diff --git a/Machine.h b/Machine.h index b33655a..dccf2c2 100644 --- a/Machine.h +++ b/Machine.h @@ -178,7 +178,7 @@ class Machine bool VerifyAngleOutstroke( int nInd, double dAng) const ; bool VerifyOutstroke( double dX, double dY, double dZ, const DBLVECTOR& vAng, bool bClear, int& nStat) const ; bool ExistProtectedAreas( void) const ; - bool VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& vAng, bool bIsLink, int& nStat) ; + bool VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& vAng, int nLinkType, int& nStat) ; bool VerifyOutstroke( const std::string& sAxName, double dVal) const ; std::string GetOutstrokeInfo( bool bMM = true) const ; void ResetOutstrokeInfo( void) const diff --git a/MachineCalc.cpp b/MachineCalc.cpp index b2682a6..8a79d89 100644 --- a/MachineCalc.cpp +++ b/MachineCalc.cpp @@ -48,7 +48,7 @@ static const string EVAR_R1 = ".R1" ; // (num) valore del pri static const string EVAR_R2 = ".R2" ; // (num) valore del secondo asse rotante static const string EVAR_R3 = ".R3" ; // (num) valore del terzo asse rotante static const string EVAR_R4 = ".R4" ; // (num) valore del quarto asse rotante -static const string EVAR_ISLINK = ".ISLINK" ; // (bool) flag per indicare controllo posizioni in un link +static const string EVAR_LINKTYPE = ".LINKTYPE" ; // (int) tipo collegamento (0=No, 1=Inizio, 2=Fine, 3=Link)) static const string EVAR_ERROR = ".ERR" ; // OUT (int) codice di errore ( 0 = ok) static const string EVAR_STAT = ".STAT" ; // OUT (int) codice di stato ( 0 = ok) static const string EVAR_AUXINFO = ".AUXINFO" ; // OUT (string) stringa con info ausiliarie @@ -1728,7 +1728,7 @@ Machine::VerifyOutstroke( double dX, double dY, double dZ, const DBLVECTOR& vAng } // verifica delle aree protette if ( nStat == 0) - return const_cast( this)->VerifyProtectedAreas( dX, dY, dZ, vAng, false, nStat) ; + return const_cast( this)->VerifyProtectedAreas( dX, dY, dZ, vAng, 0, nStat) ; return true ; } @@ -1742,7 +1742,7 @@ Machine::VerifyOutstroke( double dX, double dY, double dZ, const DBLVECTOR& vAng //---------------------------------------------------------------------------- bool -Machine::VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& vAng, bool bIsLink, int& nStat) +Machine::VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& vAng, int nLinkType, int& nStat) { // se non esiste funzione gestione aree protette, non devo fare alcunchè if ( ! LuaExistsFunction( ON_VERIFY_PROTECTEDAREAS)) @@ -1770,7 +1770,7 @@ Machine::VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_R3, vAng[2]) ; if ( vAng.size() >= 4) bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_R4, vAng[3]) ; - bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_ISLINK, bIsLink) ; + bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_LINKTYPE, nLinkType) ; // chiamo funzione bOk = bOk && LuaCallFunction( ON_VERIFY_PROTECTEDAREAS) ; // recupero il risultato diff --git a/Operation.cpp b/Operation.cpp index caf0f60..6e7f7b5 100644 --- a/Operation.cpp +++ b/Operation.cpp @@ -2959,6 +2959,9 @@ Operation::ManageProtectedAreas( const DBLVECTOR& vAxStart, const DBLVECTOR& vAx // recupero flag nuova gestione collegamenti tra lavorazioni bool bNewLink = m_pMchMgr->GetCurrMachine()->GetNewLinkMgr() ; + // codifica tipo di collegamento + int nLinkType = 0 + ( pPrevOp == nullptr ? 0 : 2) + ( pNextOp == nullptr ? 0 : 1) ; + // Verifico se il collegamento le attraversa Point3d ptSta( vAxStart[0], vAxStart[1], vAxStart[2]) ; Point3d ptEnd( vAxEnd[0], vAxEnd[1], vAxEnd[2]) ; @@ -2971,10 +2974,10 @@ Operation::ManageProtectedAreas( const DBLVECTOR& vAxStart, const DBLVECTOR& vAx // verifico inizio e fine int nOutstroke = 0 ; int nStSta = 0 ; - if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptSta.x, ptSta.y, ptSta.z, vAngSta, true, nStSta) || nStSta != 0) + if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptSta.x, ptSta.y, ptSta.z, vAngSta, nLinkType, nStSta) || nStSta != 0) nOutstroke |= 2 ; int nStEnd = 0 ; - if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptEnd.x, ptEnd.y, ptEnd.z, vAngEnd, true, nStEnd) || nStEnd != 0) + if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptEnd.x, ptEnd.y, ptEnd.z, vAngEnd, nLinkType, nStEnd) || nStEnd != 0) nOutstroke |= 1 ; // verifico i punti intermedi const double PA_VERIF_LEN = 10 ; @@ -2987,7 +2990,7 @@ Operation::ManageProtectedAreas( const DBLVECTOR& vAxStart, const DBLVECTOR& vAx for ( int j = 0 ; j < int( vAngSta.size()) ; ++ j) vAng.emplace_back( ( 1 - dCoeff) * vAngSta[j] + dCoeff * vAngEnd[j]) ; int nStat = 0 ; - if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptCurr.x, ptCurr.y, ptCurr.z, vAng, true, nStat) || nStat != 0) + if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptCurr.x, ptCurr.y, ptCurr.z, vAng, nLinkType, nStat) || nStat != 0) nOutstroke |= 4 ; } if ( nOutstroke == 0) @@ -3008,7 +3011,6 @@ Operation::ManageProtectedAreas( const DBLVECTOR& vAxStart, const DBLVECTOR& vAx return false ; // chiamo funzione script OnSpecialRapidMove per avere posizioni di movimento - int nLinkType = 0 + ( pPrevOp == nullptr ? 0 : 2) + ( pNextOp == nullptr ? 0 : 1) ; POSVECTOR vPosNew ; bool bOk = SpecialMoveRapid( vNeatAxSta, vNeatAxEnd, nOutstroke, nLinkType, vPosNew) ; // se tutto bene, eseguo cancellazioni e inserimenti come richiesto diff --git a/SurfRoughing.cpp b/SurfRoughing.cpp index 4cbb994..0a24b59 100644 --- a/SurfRoughing.cpp +++ b/SurfRoughing.cpp @@ -78,7 +78,8 @@ using namespace std ; // 3029 = "Error in SurfRoughing : Error in Classifying border" // 3029 = "Error in SurfRoughing : Simplify Chunks for SubSteps failed" // 3030 = "Error in SurfRoughing : Conformal ZigZag not valid at step (xx)" -// 3131 = "Error in SurfRoughing : LeadIn with Mill NoTip in material" +// 3031 = "Error in SurfRoughing : LeadIn with Mill NoTip in material" +// 3032 = "Error in SurfRoughing : Curves with different extrusion" // 3051 = "Warning in SurfRoughing : Skipped entity (xx)" // 3052 = "Warning in SurfRoughing : No machinable path" // 3053 = "Warning in SurfRoughing : Tool name changed (xx)" @@ -1053,6 +1054,7 @@ SurfRoughing::Chain( int nGrpDestId) } } // preparo i dati per il concatenamento + Vector3d vtExtr = Z_AX ; bool bFirst = true ; Point3d ptNear = ORIG ; double dToler = 10 * EPS_SMALL ; @@ -1073,9 +1075,18 @@ SurfRoughing::Chain( int nGrpDestId) return false ; // se prima curva, assegno inizio della ricerca if ( bFirst) { + pCrv->GetExtrusion( vtExtr) ; ptNear = ptStart + 10 * EPS_SMALL * vtStart ; bFirst = false ; } + // altrimenti + else { + Vector3d vtTmpExtr ; pCrv->GetExtrusion( vtTmpExtr) ; + if ( ! AreSameVectorApprox( vtTmpExtr, vtExtr)) { + m_pMchMgr->SetLastError( 3032, "Error in SurfRoughing : Curves with different extrusion") ; + return false ; + } + } } // recupero i percorsi concatenati e definisco la regione piana di sgrossatura SurfFlatRegionByContours SfrByC ; @@ -1086,7 +1097,6 @@ SurfRoughing::Chain( int nGrpDestId) if ( IsNull( pCrvCompo)) return false ; // estrusione e spessore - Vector3d vtExtr = Z_AX ; double dThick = 0 ; // vettore Id originali SELVECTOR vId2 ; @@ -1102,13 +1112,9 @@ SurfRoughing::Chain( int nGrpDestId) if ( bInvert) pCrv->Invert() ; // recupero eventuali estrusione e spessore - Vector3d vtTemp ; - if ( pCrv->GetExtrusion( vtTemp)) { - vtExtr = vtTemp ; - double dTemp ; - if ( pCrv->GetThickness( dTemp) && abs( dTemp) > abs( dThick)) - dThick = dTemp ; - } + double dTemp ; + if ( pCrv->GetThickness( dTemp) && abs( dTemp) > abs( dThick)) + dThick = dTemp ; // la aggiungo alla curva composta if ( ! pCrvCompo->AddCurve( ::Release( vpCrvs[nId]), true, dToler)) return false ; @@ -1134,7 +1140,6 @@ SurfRoughing::Chain( int nGrpDestId) m_pMchMgr->SetLastError( 3006, "Error in SurfRoughing : Tool Dir not perpendicular to Flat Area") ; return false ; } - pFlatCrv->GetExtrusion( vtExtr) ; pCrvCompo->Clear() ; pCrvCompo->AddCurve( Release( pFlatCrv)) ; // salvo vettore estrusione @@ -1154,6 +1159,9 @@ SurfRoughing::Chain( int nGrpDestId) int nGroupName = -1 ; PtrOwner pSfrCurr( SfrByC.GetSurf()) ; while ( ! IsNull( pSfrCurr) && pSfrCurr->IsValid()) { + // la normale del Chunk deve essere coerente con l'estrusione ricavata + if ( AreOppositeVectorApprox( pSfrCurr->GetNormVersor(), vtExtr)) + pSfrCurr->Invert() ; // per ogni Chunk for ( int nC = 0 ; nC < pSfrCurr->GetChunkCount() ; ++ nC) { // creo nuovo gruppo @@ -1169,7 +1177,7 @@ SurfRoughing::Chain( int nGrpDestId) int nNewId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, ::CloneSurfFlatRegion( pSfrChunk)) ; if ( nNewId == GDB_ID_NULL) return false ; - // salvo eventuali lati aperti per il Chunk corrente + // scorro i loop della regione for ( int nL = 0 ; nL < pSfrChunk->GetLoopCount( 0) ; ++ nL) { // recupero il Loop PtrOwner pCrvLoop( ConvertCurveToComposite( pSfrChunk->GetLoop( 0, nL))) ; @@ -1179,8 +1187,6 @@ SurfRoughing::Chain( int nGrpDestId) if ( nL == 0) { double dThick = pCrvLoop->GetTempParam( 1) ; m_pGeomDB->SetInfo( nNewId, KEY_THICK, dThick) ; - Vector3d vtExtr ; - pCrvLoop->GetExtrusion( vtExtr) ; m_pGeomDB->SetInfo( nNewId, KEY_EXTR, vtExtr) ; } } @@ -1225,19 +1231,29 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) int nCopyId = m_pGeomDB->CopyGlob( nSfrId, GDB_ID_NULL, nTempId) ; if ( nCopyId == GDB_ID_NULL) return false ; - PtrOwner pSfrGDB( CloneSurfFlatRegion( m_pGeomDB->GetGeoObj( nCopyId))) ; - if ( IsNull( pSfrGDB) || ! pSfrGDB->IsValid()) + PtrOwner pSfrSgro( CloneSurfFlatRegion( m_pGeomDB->GetGeoObj( nCopyId))) ; + if ( IsNull( pSfrSgro) || ! pSfrSgro->IsValid()) return false ; - // recupero estrusione e spessore + // recupero estrusione Vector3d vtExtr = Z_AX ; if ( m_pGeomDB->ExistsInfo( nSfrId, KEY_EXTR)) m_pGeomDB->GetInfo( nSfrId, KEY_EXTR, vtExtr) ; + // controllo che l'estrusione sia coerente con la normale della superficie + if ( AreSameOrOppositeVectorApprox( pSfrSgro->GetNormVersor(), vtExtr)) { + if ( AreOppositeVectorApprox( pSfrSgro->GetNormVersor(), vtExtr)) + pSfrSgro->Invert() ; + } + else { + m_pMchMgr->SetLastError( 3006, "Error in SurfRoughing : Tool Dir not perpendicular to Flat Area") ; + return false ; + } + + + // recupero lo spessore e valuto l'espressione dell'affondamento double dThick = 0. ; if ( m_pGeomDB->ExistsInfo( nSfrId, KEY_THICK)) m_pGeomDB->GetInfo( nSfrId, KEY_THICK, dThick) ; - - // valuto l'espressione dell'affondamento ExeLuaSetGlobNumVar( "TH", abs( dThick)) ; double dDepth ; string sMyDepth = m_Params.m_sDepth ; @@ -1249,35 +1265,6 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) if ( dThick > 0) dDepth -= dThick ; - // recupero il Loop esterno della regione da svuotatare - PtrOwner pCompo( ConvertCurveToComposite( pSfrGDB->GetLoop( 0, 0))) ; - if ( IsNull( pCompo) || ! pCompo->IsValid()) - return false ; - - // verifico sia piana e sistemo senso antiorario visto dalla direzione di estrusione - Plane3d plPlane ; double dArea ; - if ( ! pCompo->GetArea( plPlane, dArea)) { - m_pMchMgr->SetLastError( 3005, "Error in SurfRoughing : Contour Not Flat") ; - return false ; - } - if ( abs( plPlane.GetVersN() * vtExtr) < cos( 10 * EPS_ANG_SMALL)) { - m_pMchMgr->SetLastError( 3006, "Error in SurfRoughing : Tool Dir not perpendicular to Flat Area") ; - return false ; - } - if ( plPlane.GetVersN() * vtExtr * dArea < 0) - pCompo->Invert() ; - if ( plPlane.GetVersN() * vtExtr < 0) - plPlane.Invert() ; - - // creo un frame centrato sulla curva - Frame3d fr_pCompo ; - if ( ! fr_pCompo.Set( plPlane.GetPoint(), plPlane.GetVersN())) - return false ; - - // unisco le parti allineate - if ( ! pCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL, true)) - return false ; - // recupero il box del grezzo in globale BBox3d b3Raw ; if ( ! GetRawGlobBox( m_nPhase, nPathId, 0.5 * m_TParams.m_dTDiam, b3Raw) || b3Raw.IsEmpty()) { @@ -1296,6 +1283,12 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) bool bPlaneZDetection = false ; m_bDetectPlaneZ = ( FromString( ExtractInfo( m_Params.m_sUserNotes, "PlaneZ="), bPlaneZDetection) && bPlaneZDetection) ; + // creo un frame centrato sulla superficie + Frame3d frSfr ; + Point3d ptCenter ; pSfrSgro->GetCentroid( ptCenter) ; + if ( ! frSfr.Set( ptCenter, vtTool)) + return false ; + // non prevista gestione anteprima di lavorazione // se richiesta lavorazione @@ -1328,16 +1321,16 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) // inizializzo la classe di intersezione tra grezzo e piani paralleli ( quelli di lavoro) // traslo leggermente il grezzo per gestire il primo e l'ultimo Step pStmRaw->Translate( - vtTool * 5 * EPS_SMALL) ; - IntersParPlanesSurfTm IPPStm( fr_pCompo, *pStmRaw) ; + IntersParPlanesSurfTm IPPStm( frSfr, *pStmRaw) ; // costruisco una superficie di estrusione della curva (devo determinare parte della regione limite) Vector3d vtLimitExtr = - vtTool * 1.5 * max( b3Raw.GetDimX(), max( b3Raw.GetDimY(), b3Raw.GetDimZ())) ; - PtrOwner pStmLimit( GetStmOutSideSfr( pSfrGDB, pStmRaw, vtLimitExtr)) ; + PtrOwner pStmLimit( GetStmOutSideSfr( pSfrSgro, pStmRaw, vtLimitExtr)) ; if ( IsNull( pStmLimit)) return false ; // inizializzo la classe di intersezione tra la superficie trimesh limite e piani paralleli ( quelli di lavoro) - IntersParPlanesSurfTm IPPStm1( fr_pCompo, *pStmLimit) ; + IntersParPlanesSurfTm IPPStm1( frSfr, *pStmLimit) ; // inizializzo la classe di calcolo delle silhouette nei piani come sopra SURFLOCALVECTOR vSurfL ; vSurfL.reserve( vSurfId.size()) ; @@ -1350,11 +1343,9 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0) vpStm.emplace_back( pStm) ; } - Frame3d frPlanes ; - frPlanes.Set( plPlane.GetPoint(), vtTool) ; const double SILH_TOL = 1.0 ; PtrOwner pCavParSilh( CreateCAvParSilhouettesSurfTm()) ; - if ( IsNull( pCavParSilh) || ! pCavParSilh->SetData( vpStm, frPlanes, SILH_TOL)) + if ( IsNull( pCavParSilh) || ! pCavParSilh->SetData( vpStm, frSfr, SILH_TOL)) return false ; // vettore Id salvati nel gruppo Temp @@ -1379,7 +1370,7 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) // se richiesto PlaneZ detection, aggiungo altri step intermedi ( planeZSteps ) PLANEZFACEVECTOR vPlaneZ ; if ( m_bDetectPlaneZ) { - if ( ! DetectPlaneZ( vpStm, fr_pCompo, vtTool, vPlaneZ, - GetOffsL(), dDepth - GetOffsL())) + if ( ! DetectPlaneZ( vpStm, frSfr, vtTool, vPlaneZ, - GetOffsL(), dDepth - GetOffsL())) return false ; #if ENABLE_DEBUG_ZPLANE for ( int nP = 0 ; nP < int( vPlaneZ.size()) ; ++ nP) { @@ -1470,18 +1461,11 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) /* ******************** Regione estesa di lavoro ******************** */ // regione di lavoro allo step corrente ( definita dalla curva di lavoro ) - PtrOwner pSfr( CreateSurfFlatRegion()) ; - if ( IsNull( pSfr) || ! pSfr->AddExtLoop( *pCompo)) { + PtrOwner pSfr( CloneSurfFlatRegion( pSfrSgro)) ; + if ( IsNull( pSfr) || ! pSfr->IsValid()) { m_pMchMgr->SetLastError( 3024, "Error in SurfRoughing : region not computable") ; return false ; } - for ( int nL = 1 ; nL < pSfrGDB->GetLoopCount( 0) ; ++ nL) { - // recupero l'isola - PtrOwner pCrvIsl( pSfrGDB->GetLoop( 0, nL)) ; - if ( IsNull( pCrvIsl) || ! pCrvIsl->IsValid() || - ! pSfr->AddIntLoop( *pCrvIsl)) - return false ; - } pSfr->Translate( ( it->dDepth + GetOffsL()) * vtTool) ; /* ******************** Regione adattata al grezzo ******************** */ @@ -1548,6 +1532,7 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) ( vStepInfo[nIndRef].pSfrRemoved == nullptr || ! vStepInfo[nIndRef].pSfrRemoved->IsValid())) { nIndRef = vStepInfo[nIndRef].nIndRef ; } + // recupero la superficie progressiva dello step di riferimento PtrOwner pSfrRef( CloneSurfFlatRegion( vStepInfo[nIndRef].pSfrRemoved)) ; if ( ! IsNull( pSfrRef) && pSfrRef->IsValid()) { // se valida @@ -1850,41 +1835,51 @@ SurfRoughing::GetStmOutSideSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pStmRaw == nullptr || ! pStmRaw->IsValid()) return nullptr ; + // creo una copia della pSfr mediante un piccolo offset correttivo (per problemi con archi) + PtrOwner pSfrOffs( pSfr->CreateOffsetSurf( 100 * EPS_SMALL, ICurve::OFF_FILLET)) ; + if ( IsNull( pSfrOffs) || ! pSfrOffs->IsValid()) + return nullptr ; + // definisco il vettore delle curve dei i bordi della regione CICURVEPVECTOR vpCrv ; + bool bOk = true ; // per ogni Chunk - for ( int nC = 0 ; nC < pSfr->GetChunkCount() ; ++ nC) { + for ( int nC = 0 ; nC < pSfrOffs->GetChunkCount() && bOk ; ++ nC) { // per ogni Loop - for ( int nL = 0 ; nL < pSfr->GetLoopCount( nC) ; ++ nL) { + for ( int nL = 0 ; nL < pSfrOffs->GetLoopCount( nC) && bOk ; ++ nL) { // recupero il Loop come curva composita - PtrOwner pCompoLoop( ConvertCurveToComposite( pSfr->GetLoop( nC, nL))) ; - if ( IsNull( pCompoLoop) || ! pCompoLoop->IsValid()) - return nullptr ; - // recupero la PolyLine associata a tale Loop e la inserisco nel vettore - vpCrv.emplace_back( Release( pCompoLoop)) ; + PtrOwner pLoop( pSfrOffs->GetLoop( nC, nL)) ; + bOk = ( ! IsNull( pLoop) && pLoop->IsValid()) ; + if ( bOk) + vpCrv.emplace_back( Release( pLoop)) ; } } - // definisco la superficie di estrusione - PtrOwner pStmExtr( GetSurfTriMeshByRegionExtrusion( vpCrv, vtExtr)) ; - if ( IsNull( pStmExtr) || ! pStmExtr->IsValid()) - return nullptr ; - - // la superficie deeve definire un volume - double dVol = 0. ; pStmExtr->GetVolume( dVol) ; - if ( dVol < EPS_ZERO) - pStmExtr->Invert() ; - - // sottraggo al grezzo la regione di estrusione + // definisco la TrimMesh limite (inizialmente vuota) PtrOwner pStmLimit( CloneSurfTriMesh( pStmRaw)) ; - bool bOk = ! IsNull( pStmLimit) ; - bOk = bOk && pStmLimit->IsValid() ; - bOk = bOk && pStmLimit->Subtract( *pStmExtr) ; - if ( ! bOk) - return nullptr ; + bOk = bOk && ( ! IsNull( pStmLimit) && pStmLimit->IsValid()) ; - return Release( pStmLimit) ; + // definisco la superficie di estrusione + if ( bOk) { + PtrOwner pStmExtr( GetSurfTriMeshByRegionExtrusion( vpCrv, vtExtr)) ; + bOk = ( ! IsNull( pStmExtr) && pStmExtr->IsValid()) ; + // la superficie deve definire un volume + double dVol = 0. ; + bOk = bOk && pStmExtr->GetVolume( dVol) ; + if ( dVol < EPS_ZERO) + bOk = bOk && pStmExtr->Invert() ; + // sottraggo al grezzo la regione di estrusione + bOk = bOk && pStmLimit->Subtract( *pStmExtr) ; + } + + // rimozione del vettore di curve costanti + for ( int i = 0 ; i < int( vpCrv.size()) ; ++ i) { + delete( vpCrv[i]) ; + vpCrv[i] = nullptr ; + } + + return ( bOk ? Release( pStmLimit) : nullptr) ; } //---------------------------------------------------------------------------- @@ -2166,7 +2161,7 @@ SurfRoughing::CalcPaths( const INTINTVECTOR& vPocket, STEPINFOSRVECTOR& vStepInf // se utensile che non lavora di testa e ingresso non fuori dal pezzo, errore if ( m_TParams.m_nType == TT_MILL_NOTIP && ! vStepInfo[nInd].vPaths[i].bOutStart) { if ( ! LeadInRawIsOk()) { - m_pMchMgr->SetLastError( 2431, "Error in SurfRoughing : LeadIn with Mill NoTip in material") ; + m_pMchMgr->SetLastError( 3031, "Error in SurfRoughing : LeadIn with Mill NoTip in material") ; return false ; } } @@ -2248,11 +2243,13 @@ SurfRoughing::AddPocket( const INTINTVECTOR& vPocket, const Vector3d& vtTool, do // riferimento alle informazioni relative allo step i-esimo StepInfoSR& currStep = vStepInfo[i] ; + // scorro i percorsi calcolati per il piano di pocketing i-esimo for ( int j = 0 ; j < int( currStep.vPaths.size()) ; ++ j) { // riferimento alle informazioni relative al percorso j-esimo del piano di pocketing i-esimo PathInfoSR& currPath = currStep.vPaths[j] ; + // ciclo sulle curve elementari del percorso attuale int nMaxInd = currPath.pCrvPath->GetCurveCount() - 1 ; for ( int k = 0 ; k <= nMaxInd ; ++ k) { @@ -2303,7 +2300,7 @@ SurfRoughing::AddPocket( const INTINTVECTOR& vPocket, const Vector3d& vtTool, do Point3d ptMyPos ; GetCurrPos( ptMyPos) ; double dMyElev = ( bAbsFirst ? dCurrElev : ( ptMyPos - ptP1) * vtTool) ; double dMyAppr = ( bAbsFirst ? dAppr : 0.) ; - if ( ! AddApproach( ptP1, vtTool, dMySafeZ, dMyElev, dMyAppr, currPath.bOutStart)) { + if ( ! AddApproach( ptP1, vtTool, dMySafeZ, dMyElev, dMyAppr, currPath.bOutStart, bAbsFirst)) { m_pMchMgr->SetLastError( 3011, "Error in SurfRoughing : Approach not computable") ; return false ; } @@ -2438,9 +2435,10 @@ SurfRoughing::AddPocket( const INTINTVECTOR& vPocket, const Vector3d& vtTool, do //---------------------------------------------------------------------------- bool SurfRoughing::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, - double dAppr, bool bOutStart) + double dAppr, bool bOutStart, bool bAbsFirst) { - SetFlag( 1) ; + if ( bAbsFirst) + SetFlag( 1) ; // se sopra attacco c'è spazio per sicurezza o approccio double dSafeDist = dSafeZ ; if ( dElev + max( dSafeDist, dAppr) > 10 * EPS_SMALL) { @@ -2448,14 +2446,14 @@ SurfRoughing::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dS if ( dSafeDist < dAppr + 10 * EPS_SMALL) { // 1 -> punto sopra inizio Point3d ptP1 = ptP + vtTool * ( dElev + dAppr) ; - if ( AddRapidStart( ptP1) == GDB_ID_NULL) + if ( bAbsFirst && AddRapidStart( ptP1) == GDB_ID_NULL) return false ; } else { // 1a -> punto sopra inizio Point3d ptP1b = ptP + vtTool * ( dElev + dAppr) ; Point3d ptP1a = ptP1b + vtTool * ( dSafeDist - dAppr) ; - if ( ( AddRapidStart( ptP1a) == GDB_ID_NULL)) + if ( bAbsFirst && AddRapidStart( ptP1a) == GDB_ID_NULL) return false ; // 1b -> punto appena sopra inizio if ( ( dElev + dAppr) > EPS_SMALL) { @@ -2474,7 +2472,7 @@ SurfRoughing::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dS else { // affondo diretto al punto iniziale SetFlag( 0) ; - if ( AddRapidStart( ptP) == GDB_ID_NULL) + if ( bAbsFirst && AddRapidStart( ptP) == GDB_ID_NULL) return false ; } return true ; @@ -3005,6 +3003,7 @@ SurfRoughing::CloseOpenEdgesUnderTolerance( ISurfFlatRegion* pSfr, double dToler PtrOwner pCrvNewLoop( CreateCurveComposite()) ; if ( IsNull( pCrvNewLoop)) return false ; + for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) { // se tratto aperto e non coincidente con tutta la curva if ( vpCrvs[i]->GetTempProp( 0) == TEMP_PROP_OPEN_EDGE && int( vpCrvs.size()) != 1) { @@ -3035,7 +3034,7 @@ SurfRoughing::CloseOpenEdgesUnderTolerance( ISurfFlatRegion* pSfr, double dToler // se il chunk è stato creato correttamente, allora lo aggiungo if ( bOk) { if ( pSfrRegular->IsValid() && pSfrRegular->GetChunkCount() > 0) { - if ( ! pSfrRegular->Add( *Release( pSfrTest))) + if ( ! pSfrRegular->Add( *pSfrTest)) return false ; } else { @@ -3049,7 +3048,7 @@ SurfRoughing::CloseOpenEdgesUnderTolerance( ISurfFlatRegion* pSfr, double dToler if ( IsNull( pSfrChunkCL) || ! pSfrChunkCL->IsValid()) return false ; if ( pSfrRegular->IsValid() && pSfrRegular->GetChunkCount() > 0) { - if ( ! pSfrRegular->Add( *Release( pSfrTest))) + if ( ! pSfrRegular->Add( *pSfrTest)) return false ; } else { diff --git a/SurfRoughing.h b/SurfRoughing.h index b51efcf..d862403 100644 --- a/SurfRoughing.h +++ b/SurfRoughing.h @@ -111,7 +111,7 @@ class SurfRoughing : public Machining double dMinDepth, double dMaxDepth) const ; bool CalcPaths( const INTINTVECTOR& vPocket, STEPINFOSRVECTOR& vStepInfo) 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 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) ; bool AddLinkRetract( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr) ; bool AddRetract( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr) ;