From 65ef32a368e97c6132214d49b32ab28f44f84384 Mon Sep 17 00:00:00 2001 From: Riccardo Elitropi Date: Wed, 22 Jan 2025 09:24:17 +0100 Subject: [PATCH] EgtMachKernel : - in Sgrossature aggiunto controllo sull'elevazione ed eventuale parametro MaxElev. --- SurfRoughing.cpp | 123 ++++++++++++++++++++++++++++++++++++++++++++++- SurfRoughing.h | 1 + 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/SurfRoughing.cpp b/SurfRoughing.cpp index 3c0d0c2..acce904 100644 --- a/SurfRoughing.cpp +++ b/SurfRoughing.cpp @@ -41,6 +41,8 @@ #include "/EgtDev/Include/EGkDistPointSurfTm.h" #include "/EgtDev/Include/EGkIntersPlaneSurfTm.h" #include "/EgtDev/Include/EGkStmFromCurves.h" +#include "/EgtDev/Include/EGkPolygon3d.h" +#include "/EgtDev/Include/EGkPolygonElevation.h" // per far dimenticare macro di WinUser.h #undef GetClassName @@ -80,6 +82,7 @@ using namespace std ; // 3030 = "Error in SurfRoughing : Conformal ZigZag not valid at step (xx)" // 3031 = "Error in SurfRoughing : LeadIn with Mill NoTip in material" // 3032 = "Error in SurfRoughing : Curves with different extrusion" +// 3033 = "Error in SurfRoughing : CalcRegion elevation failed" // 3051 = "Warning in SurfRoughing : Skipped entity (xx)" // 3052 = "Warning in SurfRoughing : No machinable path" // 3053 = "Warning in SurfRoughing : Tool name changed (xx)" @@ -1204,6 +1207,92 @@ SurfRoughing::Chain( int nGrpDestId) return true ; } +//---------------------------------------------------------------------------- +bool +SurfRoughing::CalcRegionElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dRad, double dLen, + double& dElev) const +{ + // inizializzo l'elevazione + dElev = 0 ; + + // approssimo la curva con una polilinea che uso per creare il poligono equivalente + PolyLine PL ; + if ( ! pCompo->ApproxWithLines( LIN_TOL_RAW, ANG_TOL_MAX_DEG, ICurve::APL_SPECIAL, PL)) + return false ; + Polygon3d pgFacet ; + if ( ! pgFacet.FromPolyLine( PL)) + return false ; + // aggiungo l'affondamento + pgFacet.Translate( -dDepth * vtTool) ; + + // inizializzo elevazioni per ogni grezzo + INTDBLVECTOR vRawElev ; + // ciclo sui grezzi della fase + int nRawId = m_pMchMgr->GetFirstRawPart() ; + while ( nRawId != GDB_ID_NULL) { + // verifico che il grezzo compaia nella fase + if ( m_pMchMgr->VerifyRawPartPhase( nRawId, m_nPhase)) { + // recupero la trimesh del grezzo + int nStmId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; + const ISurfTriMesh* pStm = GetSurfTriMesh( m_pGeomDB->GetGeoObj( nStmId)) ; + if ( pStm != nullptr) { + // recupero il riferimento della trimesh + Frame3d frStm ; + m_pGeomDB->GetGlobFrame( nStmId, frStm) ; + // porto il poligono in questo riferimento + Polygon3d pgFacetL = pgFacet ; + pgFacetL.ToLoc( frStm) ; + // calcolo l'elevazione + double dCurrElev ; + if ( ! PolygonElevationInClosedSurfTm( pgFacetL, *pStm, true, dCurrElev)) + return false ; + if ( dCurrElev > EPS_SMALL) + vRawElev.emplace_back( nStmId, dCurrElev) ; + } + } + // passo al grezzo successivo + nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; + } + // se trovate elevazioni + if ( ! vRawElev.empty()) { + // ordino il vettore secondo l'elevazione crescente + sort( vRawElev.begin(), vRawElev.end(), []( const INTDBL& a, const INTDBL& b) + { return a.second < b.second ; }) ; + // box dell'insieme delle posizioni utensile all'inizioe + const double MAX_DIST_RAW = 200.0 ; + BBox3d b3Tool ; + pgFacet.GetLocalBBox( b3Tool) ; + b3Tool.Add( b3Tool.GetMin() + dLen * vtTool) ; + b3Tool.Add( b3Tool.GetMax() + dLen * vtTool) ; + if ( vtTool.IsX()) + b3Tool.Expand( 0, dRad, dRad) ; + else if ( vtTool.IsY()) + b3Tool.Expand( dRad, 0, dRad) ; + else if ( vtTool.IsZ()) + b3Tool.Expand( dRad, dRad, 0) ; + else { + double dExpandX = dRad * sqrt( 1 - vtTool.x * vtTool.x) ; + double dExpandY = dRad * sqrt( 1 - vtTool.y * vtTool.y) ; + double dExpandZ = dRad * sqrt( 1 - vtTool.z * vtTool.z) ; + b3Tool.Expand( dExpandX, dExpandY, dExpandZ) ; + } + b3Tool.Expand( MAX_DIST_RAW) ; + // verifico la reale interferenza dell'utensile con i diversi grezzi + for ( int i = 0 ; i < int( vRawElev.size()) ; ++ i) { + // box del grezzo + BBox3d b3Raw ; + m_pGeomDB->GetGlobalBBox( vRawElev[i].first, b3Raw) ; + // confronto con il box dell'utensile nella posizione precedente + BBox3d b3CurrTool = b3Tool ; + b3CurrTool.Translate( dElev * vtTool) ; + if ( b3Raw.Overlaps( b3CurrTool)) + dElev = vRawElev[i].second ; + } + } + + return true ; +} + //---------------------------------------------------------------------------- bool SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) @@ -1255,7 +1344,6 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) return false ; } - // recupero lo spessore e valuto l'espressione dell'affondamento double dThick = 0. ; if ( m_pGeomDB->ExistsInfo( nSfrId, KEY_THICK)) @@ -1285,6 +1373,39 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) // assegno il versore fresa Vector3d vtTool = vtExtr ; + // calcolo l'elevazione al di sopra di tale regione + double dSfrMaxElev = 0. ; + for ( int nC = 0 ; nC < pSfrSgro->GetChunkCount() ; ++ nC) { + for ( int nL = 0 ; nL < pSfrSgro->GetLoopCount( nC) ; ++ nL) { + // recupero la curva + PtrOwner pCrvLoop( ConvertCurveToComposite( pSfrSgro->GetLoop( nC, nL))) ; + if ( IsNull( pCrvLoop) || ! pCrvLoop->IsValid()) + return false ; + // se isola inverto + if ( nL > 0) + pCrvLoop->Invert() ; + // determino l'elevazione + double dSfrElev = 0. ; + if ( ! CalcRegionElevation( pCrvLoop, vtTool, 0., 0.5 * m_TParams.m_dDiam, m_TParams.m_dLen, dSfrElev)) { + m_pMchMgr->SetLastError( 3033, "Error in SurfRoughing : Calc Region elevation failed") ; + return false ; + } + // l'elevazione finale รจ la massima trovata + dSfrMaxElev = max( dSfrElev, dSfrMaxElev) ; + } + } + // se la regione interseca il grezzo + if ( dSfrMaxElev > EPS_SMALL) { + // eventuale imposizione massima elevazione da note utente + double dMaxElev ; + if ( FromString( ExtractInfo( m_Params.m_sUserNotes, "MaxElev="), dMaxElev) && dSfrMaxElev > dMaxElev) + dSfrMaxElev = dMaxElev ; + // la regione viene traslata dell'elevazione trovata lungo vtTool + pSfrSgro->Translate( dSfrMaxElev * vtTool) ; + // la Depth viene incrementata del valore di traslazione + dDepth += dSfrMaxElev ; + } + // controllo se richiesto PlaneZDetection bool bPlaneZDetection = false ; m_bDetectPlaneZ = ( FromString( ExtractInfo( m_Params.m_sUserNotes, "PlaneZ="), bPlaneZDetection) && bPlaneZDetection) ; diff --git a/SurfRoughing.h b/SurfRoughing.h index 2b6e398..ba0fbff 100644 --- a/SurfRoughing.h +++ b/SurfRoughing.h @@ -110,6 +110,7 @@ class SurfRoughing : public Machining bool DetectPlaneZ( const CISURFTMPVECTOR& vpStm, const Frame3d& frCompo, const Vector3d& vtTool, PLANEZFACEVECTOR& vPlaneZ, double dMinDepth, double dMaxDepth) const ; bool CalcPaths( const INTINTVECTOR& vPocket, STEPINFOSRVECTOR& vStepInfo) const ; + bool CalcRegionElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dRad, double dLen, double& dElev) const ; bool AddPocket( const INTINTVECTOR& vPocket, const Vector3d& vtTool, double dElev, double dStep, double dSubStep, bool bSplitArcs) ; bool AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr, bool bOutStart, bool bAbsFirst) ; bool AddLinkApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr, bool bOutMove) ;