diff --git a/PocketingNT.cpp b/PocketingNT.cpp index 1f86740..22992e3 100644 --- a/PocketingNT.cpp +++ b/PocketingNT.cpp @@ -4787,7 +4787,10 @@ PocketingNT::CalcPaths( STEPINFOPOVECTOR& vStepInfo) for ( int j = 0 ; j < ssize( vStepInfo[i].vPaths) ; ++ j) { if ( vStepInfo[i].vPaths[j].bToolCompensation && ! IsNull( vStepInfo[i].vPaths[j].pCrvPath) && vStepInfo[i].vPaths[j].pCrvPath->IsValid()) { - if ( ! AddTangentLinesForToolCompensation( vStepInfo[i].vPaths[j].pCrvPath, m_vtTool, vStepInfo[i].pSfrLimit)) + // stabilisco se aggiungere il tratto a scivolo alla fine + bool bWithEndGlide = ( GetLeadOutType() == POCKET_LO_GLIDE && ! vStepInfo[i].vPaths[j].bOutEnd && + ! vStepInfo[i].vPaths[j].bOptTrap && i == ssize( vStepInfo) - 1 && j == ssize( vStepInfo[i].vPaths) - 1) ; + if ( ! AddTangentLinesForToolCompensation( vStepInfo[i].vPaths[j].pCrvPath, m_vtTool, vStepInfo[i].pSfrLimit, bWithEndGlide)) return false ; } } @@ -4815,7 +4818,6 @@ PocketingNT::CalcPaths( STEPINFOPOVECTOR& vStepInfo) if ( ! IsNull( pCrvGlideIn) && pCrvGlideIn->IsValid()) { if ( ! vStepInfo[i].vPaths[j].pCrvGlideIn.Set( Release( pCrvGlideIn))) return false ; - m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vStepInfo[i].vPaths[j].pCrvGlideIn->Clone()) ; } } // se uscita a scivolo @@ -4823,13 +4825,14 @@ PocketingNT::CalcPaths( STEPINFOPOVECTOR& vStepInfo) PtrOwner pCrvGlideOut( CreateCurveComposite()) ; if ( IsNull( pCrvGlideOut) || ! CalcRetCurve( vStepInfo[i].vPaths[j], vStepInfo[i], vStepInfo[i].vPaths[j].pCrvPath, - vStepInfo[i].pSfrPock->GetNormVersor(), bHolePocketing, P_INVALID, false, bToolComp, pCrvGlideOut)) { + vStepInfo[i].pSfrPock->GetNormVersor(), ( ! bToolComp && bHolePocketing), P_INVALID, bToolComp, false, pCrvGlideOut)) { m_pMchMgr->SetLastError( 2416, "Error in PocketingNT : LeadOut not computable") ; return false ; } - if ( ! IsNull( pCrvGlideOut) && pCrvGlideOut->IsValid()) + if ( ! IsNull( pCrvGlideOut) && pCrvGlideOut->IsValid()) { if ( ! vStepInfo[i].vPaths[j].pCrvGlideOut.Set( Release( pCrvGlideOut))) return false ; + } } } } @@ -6787,7 +6790,8 @@ PocketingNT::CalcDistanceFromRawSurface( int nPhase, const Point3d& ptP, const V //---------------------------------------------------------------------------- bool -PocketingNT::AddTangentLinesForToolCompensation( ICurveComposite* pCompoPath, const Vector3d& vtTool, const ISurfFlatRegion* pSfrLimit) const +PocketingNT::AddTangentLinesForToolCompensation( ICurveComposite* pCompoPath, const Vector3d& vtTool, const ISurfFlatRegion* pSfrLimit, + bool bWithEndGlide) const { // Verifico che la curva sia valida if ( pCompoPath == nullptr || ! pCompoPath->IsValid()) @@ -6801,6 +6805,8 @@ PocketingNT::AddTangentLinesForToolCompensation( ICurveComposite* pCompoPath, co PtrOwner pCompoPathLoc( CloneCurveComposite( pCompoPath)) ; if ( IsNull( pCompoPathLoc) || ! pCompoPathLoc->IsValid() || ! pCompoPathLoc->ToLoc( frLoc)) return false ; + + // definisco la regione limite, quella che l'utensile non deve intersecare PtrOwner pSfrLimitLocUB( nullptr) ; // Upper Bound if ( pSfrLimit != nullptr && pSfrLimit->IsValid()) { if ( ! pSfrLimitLocUB.Set( CloneSurfFlatRegion( pSfrLimit)) || ! pSfrLimitLocUB->IsValid() || ! pSfrLimitLocUB->ToLoc( frLoc)) @@ -6810,7 +6816,7 @@ PocketingNT::AddTangentLinesForToolCompensation( ICurveComposite* pCompoPath, co return false ; } - #if DEBUG_TOOL_COMPENSATION + #if DEBUG_TOOL_COMPENSATION int nGrpLocId = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ; m_pGeomDB->SetName( nGrpLocId, "LOCAL_COMPENSATION") ; int nLayId = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrpLocId, GLOB_FRM) ; @@ -6823,7 +6829,43 @@ PocketingNT::AddTangentLinesForToolCompensation( ICurveComposite* pCompoPath, co } #endif - // Calcolo tratto lineare Iniziale e Finale + // se la curva รจ chiusa, aggiungo un piccolo raccordo iniziale + if ( pCompoPathLoc->IsClosed()) { + const double EXTRA_TANG_LEN = 2.0 ; + const double EXTRA_PERP_LEN = 0.5 ; + double dLen ; pCompoPathLoc->GetLength( dLen) ; + if ( dLen > EXTRA_TANG_LEN + EPS_SMALL) { + double dUS, dUE ; pCompoPathLoc->GetDomain( dUS, dUE) ; + double dUCurr ; + Point3d ptCurr ; + Vector3d vtCurr ; + if ( pCompoPathLoc->GetParamAtLength( dLen - EXTRA_TANG_LEN, dUCurr) && + pCompoPathLoc->GetPointD1D2( dUCurr, ICurve::FROM_MINUS, ptCurr, &vtCurr)) { + double dArea ; pCompoPathLoc->GetAreaXY( dArea) ; + double dAng = ( dArea > 0. ? ANG_RIGHT : - ANG_RIGHT) ; + vtCurr.Normalize() ; + Vector3d vtPerp = vtCurr ; vtPerp.Rotate( Z_AX, dAng) ; + Point3d ptArcStart = ptCurr + EXTRA_PERP_LEN * vtPerp ; + Point3d ptArcEnd ; pCompoPathLoc->GetStartPoint( ptArcEnd) ; + Vector3d vtArcEnd ; pCompoPathLoc->GetStartDir( vtArcEnd) ; + PtrOwner pCrvArc( CreateCurveArc()) ; + if ( ! IsNull( pCrvArc) && pCrvArc->Set2PVN( ptArcEnd, ptArcStart, -vtArcEnd, Z_AX) && pCrvArc->Invert()) { + #if DEBUG_TOOL_COMPENSATION + nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayId, pCrvArc->Clone()) ; + m_pGeomDB->SetMaterial( nId, LIME) ; + #endif + if ( ! IsNull( pSfrLimitLocUB) && pSfrLimitLocUB->IsValid()) { + CRVCVECTOR ccClass ; + if ( pSfrLimitLocUB->GetCurveClassification( *pCrvArc, EPS_SMALL, ccClass) && + ( ssize( ccClass) == 1 && ccClass[0].nClass == CRVC_OUT)) + pCompoPathLoc->AddCurve( Release( pCrvArc), false) ; + } + } + } + } + } + + // Calcolo tratto lineare Iniziale e ( se richiesto ) Finale const double EXTRA_LEN = 2. ; const double LEN_LINE = EXTRA_LEN ; @@ -6838,6 +6880,7 @@ PocketingNT::AddTangentLinesForToolCompensation( ICurveComposite* pCompoPath, co else dRotAngle = ( m_Params.m_bInvert ? - ANG_RIGHT : ANG_RIGHT) ; + // aggiungo il tratto inziale pCompoPathLoc->GetStartPoint( ptStart) ; Vector3d vtStart ; pCompoPathLoc->GetStartDir( vtStart) ; Vector3d vtOut = vtStart ; vtOut.Rotate( Z_AX, dRotAngle) ; @@ -6857,6 +6900,46 @@ PocketingNT::AddTangentLinesForToolCompensation( ICurveComposite* pCompoPath, co } } + // se necessario calcolo il tratto a scivolo (precedentemente all'uscita finale) + // (calcolato solo per i bordi chiusi) + if ( bWithEndGlide && pCompoPath->IsClosed()) { + // inizializzo e recupero il percorso : + PtrOwner pCrvGlideOut( CreateCurveComposite()) ; + if ( IsNull( pCrvGlideOut)) + return false ; + // controllo che la lunghezza del percorso sia compatibile + double dLen = 0. ; + if ( pCompoPath->GetLength( dLen) && dLen > m_Params.m_dLoTang + 10. * EPS_SMALL) { + // recupero il tratto di curva alla fine + double dU = 0. ; + if ( ! pCompoPath->GetParamAtLength( m_Params.m_dLoTang, dU)) + return false ; + pCrvGlideOut->AddCurve( pCompoPath->CopyParamRange( 0., dU)) ; + } + // se non sufficientemente lunga, la guida diventa la curva stessa + else + pCrvGlideOut->AddCurve( Release( pCrvGlideOut)) ; + + // se curva a scivolo valida + if ( pCrvGlideOut->IsValid()) { + // porto la curva in locale al riferimento corrente + pCrvGlideOut->ToLoc( frLoc) ; + pCrvGlideOut->SetExtrusion( Z_AX) ; + // recupero le quote della curva + Point3d ptIni ; pCrvGlideOut->GetStartPoint( ptIni) ; + Point3d ptFin ; pCrvGlideOut->GetEndPoint( ptFin) ; + double dExtraElev = 1.0 ; + if ( m_TParams.m_nType == TT_MILL_POLISHING) // ??? + dExtraElev = max( m_Params.m_dLiElev, 1.0) ; + ptFin += Z_AX * dExtraElev ; + double dNini = ( ptIni - ORIG) * Z_AX ; + double dNfin = ( ptFin - ORIG) * Z_AX ; + AdjustCurveSlope( pCrvGlideOut, dNini, dNfin) ; + pCompoPathLoc->AddCurve( Release( pCrvGlideOut)) ; + } + } + + // aggiungo il tratto alla fine Point3d ptEnd ; pCompoPathLoc->GetEndPoint( ptEnd) ; Vector3d vtEnd ; pCompoPathLoc->GetEndDir( vtEnd) ; vtOut = vtEnd ; vtOut.Rotate( Z_AX, dRotAngle) ; @@ -6864,8 +6947,8 @@ PocketingNT::AddTangentLinesForToolCompensation( ICurveComposite* pCompoPath, co if ( IsNull( pLineE) || ! pLineE->Set( ptEnd, ptEnd + vtOut * LEN_LINE)) return false ; #if DEBUG_TOOL_COMPENSATION - nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayId, pLineE->Clone()) ; - m_pGeomDB->SetMaterial( nId, AQUA) ; + nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLayId, pLineE->Clone()) ; + m_pGeomDB->SetMaterial( nId, AQUA) ; #endif if ( ! IsNull( pSfrLimitLocUB) && pSfrLimitLocUB->IsValid()) { CRVCVECTOR ccClass ; @@ -6876,13 +6959,13 @@ PocketingNT::AddTangentLinesForToolCompensation( ICurveComposite* pCompoPath, co } } - // Aggiungo il tratto lineare all'inizio e alla fine + // restituisco in globale i risultati ottenuti Point3d ptSLoc ; pLineS->GetStartPoint( ptSLoc) ; Point3d ptELoc ; pLineE->GetEndPoint( ptELoc) ; - Point3d ptSGlob = GetToGlob( ptSLoc, frLoc) ; - Point3d ptEGlob = GetToGlob( ptELoc, frLoc) ; - if ( ! pCompoPath->AddLine( ptSGlob, false) || ! pCompoPath->AddLine( ptEGlob, true)) + if ( ! pCompoPathLoc->AddLine( ptSLoc, false) || ! pCompoPathLoc->AddLine( ptELoc, true)) return false ; + pCompoPathLoc->ToGlob( frLoc) ; + pCompoPath->CopyFrom( pCompoPathLoc) ; return true ; } diff --git a/PocketingNT.h b/PocketingNT.h index 1519880..f846f65 100644 --- a/PocketingNT.h +++ b/PocketingNT.h @@ -183,7 +183,8 @@ class PocketingNT : public Machining const INTVECTOR& vLeadOutId, const ISurfFlatRegion* pSfrLimit, const Vector3d& vtTool, bool bSplitArcs, double dMinFeed) ; double GetDoubleLastStep( void) ; - bool AddTangentLinesForToolCompensation( ICurveComposite* pCompoPath, const Vector3d& vtTool, const ISurfFlatRegion* pSfrLimit) const ; + bool AddTangentLinesForToolCompensation( ICurveComposite* pCompoPath, const Vector3d& vtTool, const ISurfFlatRegion* pSfrLimit, + bool bWithEndGuide) const ; bool AssignPropsToCamDataForToolCompensation( int nId, bool bLineIn, bool bLineOut, bool bToolAtLeft) ; // debug void DebugDrawSfr( const ISurfFlatRegion* pSfr, bool bUniform, int nlayer = GDB_ID_ROOT) ;