diff --git a/SawFinishing.cpp b/SawFinishing.cpp index 7db2b78..b3f5a1c 100644 --- a/SawFinishing.cpp +++ b/SawFinishing.cpp @@ -1885,12 +1885,12 @@ SawFinishing::CalculateStraightSectionToolPath( int nAuxId, int nClId) // Recupero ed elaboro le sezioni per portarle ad essere la curva del centro in basso della lama ICurve* pSect, * pOrigSect ; - ISurfFlatRegion* pSfrLimit ; - if ( ! CalculateOffsetSection( nSectGrpId, frSect, pSect, pOrigSect, pSfrLimit)) + ISurfFlatRegion* pMySfrTabLimit ; + if ( ! CalculateOffsetSection( nSectGrpId, frSect, pSect, pOrigSect, pMySfrTabLimit)) return false ; PtrOwner pCrv( pSect), pCrvOrig( pOrigSect) ; - PtrOwner pSfrTabLimit( pSfrLimit) ; + PtrOwner pSfrTabLimit( pMySfrTabLimit) ; if ( IsNull( pCrv) || ! pCrv->IsValid() || IsNull( pCrvOrig) || ! pCrvOrig->IsValid() || IsNull( pSfrTabLimit) || ! pSfrTabLimit->IsValid()) return false ; @@ -1977,67 +1977,38 @@ SawFinishing::CalculateStraightSectionToolPath( int nAuxId, int nClId) return false ; } - // Se link standard, allungo inizio e fine della sezione dello spessore lama (senza scendere sotto la quota Z di sicurezza) + // Se link standard, allungo inizio e fine if ( m_Params.m_nLeadLinkType == SAWFIN_LL_STD) { - Point3d ptS, ptE ; - pCompo->GetStartPoint( ptS) ; pCompo->GetEndPoint( ptE) ; - Vector3d vtS, vtE ; - pCompo->GetStartDir( vtS) ; vtS.Invert() ; pCompo->GetEndDir( vtE) ; - PtrOwner pLineS( CreateCurveLine()), - pLineE( CreateCurveLine()) ; - if ( IsNull( pLineS) || ! pLineS->Set( ptS, ptS + vtS * m_TParams.m_dThick) || - IsNull( pLineE) || ! pLineE->Set( ptE, ptE + vtE * m_TParams.m_dThick)) - return false ; - PtrOwner pCrvLimit( pSfrTabLimit->GetLoop( 0, 0)) ; - if ( IsNull( pCrvLimit) || ! pCrvLimit->IsValid()) - return false ; - // --- aggiunta estensione iniziale (verifica con sezione e tavola) - pLineS->SetExtrusion( GetToLoc( vtTool, frSect)) ; - PtrOwner pSfrSawShape( GetSurfFlatRegionFromFatCurve( pLineS->Clone(), m_TParams.m_dDiam / 2. + GetOffsR() - 10. * EPS_SMALL, false, false)) ; - if ( IsNull( pSfrSawShape) || ! pSfrSawShape->IsValid() || - ! pSfrSawShape->Translate( GetToLoc( vtCorr, frSect) * m_TParams.m_dDiam / 2.)) - return false ; - CRVCVECTOR ccClass ; - if ( ! pSfrSawShape->GetCurveClassification( *pCrvOrig, EPS_SMALL, ccClass)) - return false ; - bool bInters = false ; - for ( int j = 0 ; ! bInters && j < ssize( ccClass) ; ++ j) - bInters = ( ccClass[j].nClass == CRVC_IN) ; - if ( ! bInters) { - IntersCurveCurve ICCS( *pLineS, *pCrvLimit) ; - if ( ICCS.GetIntersCount() == 0) - pCompo->AddLine( ptS + vtS * m_TParams.m_dThick, false) ; - else { - IntCrvCrvInfo aInfo ; - if ( ! ICCS.GetIntCrvCrvInfo( 0, aInfo)) - return false ; - pCompo->AddLine( aInfo.IciA->ptI, false) ; - } - } - // --- aggiunta estensione finale (verifica con sezione e tavola) - pLineE->SetExtrusion( GetToLoc( vtTool, frSect)) ; - pSfrSawShape.Set( GetSurfFlatRegionFromFatCurve( pLineE->Clone(), m_TParams.m_dDiam / 2. + GetOffsR() - 10. * EPS_SMALL, false, false)) ; - if ( IsNull( pSfrSawShape) || ! pSfrSawShape->IsValid() || - ! pSfrSawShape->Translate( GetToLoc( vtCorr, frSect) * m_TParams.m_dDiam / 2.)) - return false ; - ccClass.clear() ; - if ( ! pSfrSawShape->GetCurveClassification( *pCrvOrig, EPS_SMALL, ccClass)) - return false ; - bInters = false ; - for ( int j = 0 ; ! bInters && j < ssize( ccClass) ; ++ j) - bInters = ( ccClass[j].nClass == CRVC_IN) ; - if ( ! bInters) { - IntersCurveCurve ICCE( *pLineE, *pCrvLimit) ; - if ( ICCE.GetIntersCount() == 0) - pCompo->AddLine( ptE + vtE * m_TParams.m_dThick, true) ; - else { - IntCrvCrvInfo aInfo ; - if ( ! ICCE.GetIntCrvCrvInfo( 0, aInfo)) - return false ; - pCompo->AddLine( aInfo.IciA->ptI, true) ; - } + pCompo->ExtendStartByLen( m_Params.m_dStartPos) ; + pCompo->ExtendEndByLen( m_Params.m_dStartPos) ; + } + + // Verifica collisioni con tavola + PtrOwner pSfrLimit( GetSurfFlatRegionFromFatCurve( pCrvOrig->Clone(), m_TParams.m_dDiam / 2. + GetOffsR() - 10. * EPS_SMALL, false, false)) ; + if ( IsNull( pSfrLimit) || ! pSfrLimit->IsValid() || ! pSfrLimit->Translate( -Y_AX * ( m_TParams.m_dDiam / 2.))) + return false ; + if ( ! pSfrLimit->Add( *pSfrTabLimit)) + return false ; + CRVCVECTOR ccClass ; + if ( ! pSfrLimit->GetCurveClassification( *pCompo, EPS_SMALL, ccClass)) + return false ; + bool bOk = false ; + for ( int i = 0 ; i < ssize( ccClass) ; ++ i) { + if ( ccClass[i].nClass == CRVC_OUT) { + PtrOwner pCrv( pCompo->CopyParamRange( ccClass[i].dParS, ccClass[i].dParE)) ; + if ( ! pCrv->IsValid()) + return false ; + pCompo->Clear() ; + pCompo->AddCurve( ::Release( pCrv)) ; + bOk = true ; + break ; } } + if ( ! bOk) { + pCompo->Clear() ; + return true ; + } + // La porto in globale pCompo->ToGlob( frSect) ; // traslo la sezione lungo la direzione della guida per farla coicidere con il suo punto iniziale @@ -2089,10 +2060,8 @@ SawFinishing::CalculateStraightSectionToolPath( int nAuxId, int nClId) dStep = dL / nStep ; Point3d ptP ; - if ( m_Params.m_nLeadLinkType == SAWFIN_LL_OUT) { + if ( m_Params.m_nLeadLinkType == SAWFIN_LL_OUT) pCrvOrig->ToGlob( frSect) ; - pSfrTabLimit->ToGlob( frSect) ; - } for ( int i = 0 ; i <= nStep ; ++ i) { // vettore di spostamento @@ -3782,7 +3751,7 @@ SawFinishing::CalcAlong5ACuts( const SECTIONVECTOR& vSections, const Frame3d& fr } else { if ( ! CalcAlong5AZigZagCut( ptStart, ptEnd, vtGdDir, vtTool, vtToolPrev, vtCorr, vtCorrPrev, dElev, dLastElev, bExtend, false, - bFirst, bSpecialAppr)) + bFirst, bSpecialAppr, 2. * ( dStep - 10. * EPS_SMALL))) return false ; } // salvo dati correnti @@ -3918,7 +3887,7 @@ SawFinishing::CalcAlong5AOneWayCut( const Point3d& ptStart, const Point3d& ptEnd bool SawFinishing::CalcAlong5AZigZagCut( const Point3d& ptStart, const Point3d& ptEnd, const Vector3d& vtDir, const Vector3d& vtTool, const Vector3d& vtToolPrev, const Vector3d& vtCorr, const Vector3d& vtCorrPrev, double dElev, - double dLastElev, bool bExtend, bool bVert, bool bFirst, bool bAppr) + double dLastElev, bool bExtend, bool bVert, bool bFirst, bool bAppr, double dMaxDist) { // recupero distanza di sicurezza double dSafeZ = GetSafeZ() ; @@ -3959,13 +3928,19 @@ SawFinishing::CalcAlong5AZigZagCut( const Point3d& ptStart, const Point3d& ptEnd // 1 -> approccio // effettuo una retroazione se : - // - ho un approccio forzato dovuto all'inversione dell'utensile + // - ho un approccio forzato dovuto all'inversione dell'utensile o ad un collegamento diretto che rovina la sezione // - la deviazione angolare tra la passata corrente e la precedente supera la tolleranza const double ANG_DEG_MAX = 10. ; bool bPrevRetract = false ; + bool bAwayLink = false ; + if ( m_Params.m_nLeadLinkType != SAWFIN_LL_OUT) { + Point3d ptCurr ; GetCurrPos( ptCurr) ; + if ( SqDist( ptCurr, ptNewStart) > dMaxDist * dMaxDist) + bAwayLink = true ; + } if ( ! bFirst && vtToolPrev.IsValid() && vtTool.IsValid()) { - // se approccio forzato per inversione utensile - if ( bAppr) { + // se approccio forzato per inversione utensile o Link troppo distante + if ( bAppr || bAwayLink) { // recupero il punto corrente Point3d ptCurr ; GetCurrPos( ptCurr) ; // tengo l'utensile orientato come la passata precedente diff --git a/SawFinishing.h b/SawFinishing.h index d11ec58..63d0a1b 100644 --- a/SawFinishing.h +++ b/SawFinishing.h @@ -133,7 +133,7 @@ class SawFinishing : public Machining bool bExtend, bool bVert, bool bFirst, bool bAppr) ; bool CalcAlong5AZigZagCut( const Point3d& ptStart, const Point3d& ptEnd, const Vector3d& vtDir, const Vector3d& vtTool, const Vector3d& vtToolPrev, const Vector3d& vtCorr, const Vector3d& vtCorrPrev, double dElev, - double dLastElev, bool bExtend, bool bVert, bool bFirst, bool bAppr) ; + double dLastElev, bool bExtend, bool bVert, bool bFirst, bool bAppr, double dMaxDist) ; bool CalcAlongOneWayCut( const Point3d& ptStart, const Point3d& ptEnd, const Vector3d& vtDir, const Vector3d& vtTool, const Vector3d& vtCorr, double dElev, bool bExtend, bool bVert) ; bool CalcAlongZigZagCut( const Point3d& ptStart, const Point3d& ptEnd, const Vector3d& vtDir, const Vector3d& vtTool,