diff --git a/Pocketing.cpp b/Pocketing.cpp index 37c674c..affa858 100644 --- a/Pocketing.cpp +++ b/Pocketing.cpp @@ -1519,7 +1519,7 @@ Pocketing::AddZigZag( const ICurveComposite* pCompo, const Vector3d& vtTool, con nStep = max( 1, static_cast( ceil( dElev / dOkStep))) ; double dStep = dElev / nStep ; - // calcolo curva offsettata del raggio utensile + sovramateriale + // calcolo curva offsettata del raggio utensile + sovramateriale + extra double dTRad = 0.5 * m_TParams.m_dDiam ; double dOffs = dTRad + GetOffsR() ; double dExtra = min( 0.1 * m_TParams.m_dDiam, 2.0) ; @@ -1528,41 +1528,166 @@ Pocketing::AddZigZag( const ICurveComposite* pCompo, const Vector3d& vtTool, con m_pMchMgr->SetLastError( 2412, "Error in Pocketing : Offset not computable") ; return false ; } - // recupero la prima curva di offset - PtrOwner pOffs( CreateCurveComposite()) ; - if ( IsNull( pOffs) || ! pOffs->AddCurve( OffsCrv.GetLongerCurve())) { - m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; + + // ciclo sulle curve risultanti + bool bStart = true ; + while ( OffsCrv.GetCurveCount() > 0) { + + // recupero la prima curva di offset + PtrOwner pOffs( CreateCurveComposite()) ; + if ( IsNull( pOffs) || ! pOffs->AddCurve( OffsCrv.GetLongerCurve())) { + m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; + return false ; + } + + // determino il riferimento di base e il box della svuotatura + Frame3d frPocket ; + Point3d ptCen ; pCompo->GetCentroid( ptCen) ; + frPocket.Set( ptCen, vtExtr) ; + frPocket.Rotate( ptCen, vtExtr, m_Params.m_dSideAngle) ; + pOffs->ToLoc( frPocket) ; + + // calcolo i percorsi di svuotatura + ICRVCOMPOPOVECTOR vpCrvs ; + if ( ! CalcZigZag( pOffs, vpCrvs)) + return false ; + + // inserisco i movimenti di svuotatura + for ( int j = 1 ; j <= nStep ; ++ j) { + // ciclo sui percorsi + for ( int k = 0 ; k < int( vpCrvs.size()) ; ++ k) { + // ciclo sulle curve elementari + int nMaxInd = vpCrvs[k]->GetCurveCount() - 1 ; + for ( int i = 0 ; i <= nMaxInd ; ++ i) { + // curva corrente + const ICurve* pCrvC = vpCrvs[k]->GetCurve( i) ; + // copio la curva + PtrOwner pCurve( pCrvC->Clone()) ; + if ( IsNull( pCurve)) + return false ; + pCurve->ToGlob( frPocket) ; + // aggiungo affondamento + pCurve->Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; + // se prima entità + if ( i == 0 ) { + // dati inizio entità + Point3d ptStart ; + pCurve->GetStartPoint( ptStart) ; + Vector3d vtStart ; + pCurve->GetStartDir( vtStart) ; + // determino inizio attacco + Point3d ptP1 ; + if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, nullptr, ptP1)) + return false ; + // determino elevazione su inizio attacco + double dStElev ; + if ( ! GetElevation( m_nPhase, ptStart - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), vtTool, dStElev)) + dStElev = dElev ; + dStElev -= ( ptP1 - ptStart) * vtExtr ; + // se inizio, approccio globale al punto iniziale + if ( bStart) { + if ( ! AddApproach( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dStElev, dAppr)) { + m_pMchMgr->SetLastError( 2414, "Error in Pocketing : Approach not computable") ; + return false ; + } + bStart = false ; + } + // altrimenti, approccio di collegamento + else { + if ( ! AddLinkApproach( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dStElev, dAppr)) { + m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; + return false ; + } + } + // aggiungo attacco + SetFeed( GetStartFeed()) ; + if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, nullptr, ! m_Params.m_bInvert, bSplitArcs, true)) { + m_pMchMgr->SetLastError( 2415, "Error in Pocketing : LeadIn not computable") ; + return false ; + } + } + // elaborazioni sulla curva corrente + if ( pCurve->GetType() == CRV_LINE) { + ICurveLine* pLine = GetCurveLine( pCurve) ; + Point3d ptP3 = pLine->GetEnd() ; + SetFeed( GetFeed()) ; + if ( AddLinearMove( ptP3) == GDB_ID_NULL) + return false ; + } + else if ( pCurve->GetType() == CRV_ARC) { + ICurveArc* pArc = GetCurveArc( pCurve) ; + Point3d ptCen = pArc->GetCenter() ; + double dAngCen = pArc->GetAngCenter() ; + Vector3d vtN = pArc->GetNormVersor() ; + Point3d ptP3 ; + pArc->GetEndPoint( ptP3) ; + SetFeed( GetFeed()) ; + if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) + return false ; + } + // se ultima entità + if ( i == nMaxInd) { + // dati fine entità + Point3d ptEnd ; + pCurve->GetEndPoint( ptEnd) ; + Vector3d vtEnd ; + pCurve->GetEndDir( vtEnd) ; + // aggiungo uscita + double dEndElev = dElev ; + Point3d ptP1 ; + SetFeed( GetEndFeed()) ; + if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, nullptr, bSplitArcs, ptP1, dEndElev, true)) { + m_pMchMgr->SetLastError( 2416, "Error in Pocketing : LeadOut not computable") ; + return false ; + } + // aggiungo retrazione di collegamento + if ( ! AddLinkRetract( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dEndElev, dAppr)) { + m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; + return false ; + } + } + } + } + } + } + + // calcolo seconda curva offsettata del raggio utensile + sovramateriale + OffsetCurve OffsCrv2 ; + if ( ! OffsCrv2.Make( pCompo, - dOffs, ICurve::OFF_FILLET)) { + m_pMchMgr->SetLastError( 2412, "Error in Pocketing : Offset not computable") ; return false ; } - // determino il riferimento di base e il box della svuotatura - Frame3d frPocket ; - Point3d ptCen ; pCompo->GetCentroid( ptCen) ; - frPocket.Set( ptCen, vtExtr) ; - frPocket.Rotate( ptCen, vtExtr, m_Params.m_dSideAngle) ; - pOffs->ToLoc( frPocket) ; - // calcolo i percorsi di svuotatura - ICRVCOMPOPOVECTOR vpCrvs ; - if ( ! CalcZigZag( pOffs, vpCrvs)) - return false ; + // ciclo sulle curve risultanti + while ( OffsCrv2.GetCurveCount() > 0) { - // inserisco i movimenti di svuotatura - bool bStart = true ; - Point3d ptP1 ; - for ( int j = 1 ; j <= nStep ; ++ j) { - // ciclo sui percorsi - for ( int k = 0 ; k < int( vpCrvs.size()) ; ++ k) { + // recupero la prima curva di offset + PtrOwner pOffs2( CreateCurveComposite()) ; + if ( IsNull( pOffs2) || ! pOffs2->AddCurve( OffsCrv2.GetLongerCurve())) { + m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; + return false ; + } + + // se richiesto, la inverto + if ( m_Params.m_bInvert) + pOffs2->Invert() ; + + // sposto l'inizio a metà del tratto più lungo + AdjustContourStart( pOffs2) ; + + // aggiungo la lavorazione di questa curva + Point3d ptP1 ; + for ( int j = 1 ; j <= nStep ; ++ j) { // ciclo sulle curve elementari - int nMaxInd = vpCrvs[k]->GetCurveCount() - 1 ; + int nMaxInd = pOffs2->GetCurveCount() - 1 ; for ( int i = 0 ; i <= nMaxInd ; ++ i) { // curva corrente - const ICurve* pCrvC = vpCrvs[k]->GetCurve( i) ; + const ICurve* pCrvC = pOffs2->GetCurve( i) ; // copio la curva PtrOwner pCurve( pCrvC->Clone()) ; if ( IsNull( pCurve)) return false ; - pCurve->ToGlob( frPocket) ; // aggiungo affondamento pCurve->Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; // se prima entità @@ -1572,34 +1697,43 @@ Pocketing::AddZigZag( const ICurveComposite* pCompo, const Vector3d& vtTool, con pCurve->GetStartPoint( ptStart) ; Vector3d vtStart ; pCurve->GetStartDir( vtStart) ; - // determino inizio attacco - if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, nullptr, ptP1)) - return false ; - // determino elevazione su inizio attacco - double dStElev ; - if ( ! GetElevation( m_nPhase, ptStart - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), vtTool, dStElev)) - dStElev = dElev ; - dStElev -= ( ptP1 - ptStart) * vtExtr ; - // se inizio, approccio globale al punto iniziale - if ( bStart) { - if ( ! AddApproach( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dStElev, dAppr)) { - m_pMchMgr->SetLastError( 2414, "Error in Pocketing : Approach not computable") ; + // se primo step, approccio e affondo + if ( j == 1) { + // determino inizio attacco + if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, nullptr, ptP1)) return false ; + // determino elevazione su inizio attacco + double dStElev ; + if ( ! GetElevation( m_nPhase, ptStart - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), vtTool, dStElev)) + dStElev = dElev ; + dStElev -= ( ptP1 - ptStart) * vtExtr ; + // se attacco a zigzag o a spirale o a scivolo, l'elevazione va nell'attacco + if ( GetLeadInType() == POCKET_LI_ZIGZAG || + GetLeadInType() == POCKET_LI_HELIX || + GetLeadInType() == POCKET_LI_GLIDE) { + ptP1 += vtExtr * dStElev ; + dStElev = 0 ; } - bStart = false ; - } - // altrimenti, approccio di collegamento - else { + // approccio al punto iniziale if ( ! AddLinkApproach( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dStElev, dAppr)) { m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; return false ; } + // aggiungo attacco + SetFeed( GetStartFeed()) ; + if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, nullptr, ! m_Params.m_bInvert, bSplitArcs)) { + m_pMchMgr->SetLastError( 2415, "Error in Pocketing : LeadIn not computable") ; + return false ; + } } - // aggiungo attacco - SetFeed( GetStartFeed()) ; - if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, nullptr, ! m_Params.m_bInvert, bSplitArcs, true)) { - m_pMchMgr->SetLastError( 2415, "Error in Pocketing : LeadIn not computable") ; - return false ; + // altrimenti solo collegamento + else { + SetFeed( GetStartFeed()) ; + ptP1 -= vtExtr * dStep ; + if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, nullptr, ! m_Params.m_bInvert, bSplitArcs)) { + m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; + return false ; + } } } // elaborazioni sulla curva corrente @@ -1623,145 +1757,34 @@ Pocketing::AddZigZag( const ICurveComposite* pCompo, const Vector3d& vtTool, con } // se ultima entità if ( i == nMaxInd) { - // dati fine entità - Point3d ptEnd ; - pCurve->GetEndPoint( ptEnd) ; - Vector3d vtEnd ; - pCurve->GetEndDir( vtEnd) ; - // aggiungo uscita - Point3d ptP1 ; - double dEndElev = dElev ; - SetFeed( GetEndFeed()) ; - if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, nullptr, bSplitArcs, ptP1, dEndElev, true)) { - m_pMchMgr->SetLastError( 2416, "Error in Pocketing : LeadOut not computable") ; - return false ; - } - // aggiungo retrazione di collegamento - if ( ! AddLinkRetract( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dEndElev, dAppr)) { - m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; - return false ; - } - } - } - } - } - - // calcolo curva offsettata del raggio utensile + sovramateriale - OffsetCurve OffsCrv2 ; - if ( ! OffsCrv2.Make( pCompo, - dOffs, ICurve::OFF_FILLET)) { - m_pMchMgr->SetLastError( 2412, "Error in Pocketing : Offset not computable") ; - return false ; - } - // recupero la prima curva di offset - PtrOwner pOffs2( CreateCurveComposite()) ; - if ( IsNull( pOffs2) || ! pOffs2->AddCurve( OffsCrv2.GetLongerCurve())) { - m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; - return false ; - } - - // se richiesto, la inverto - if ( m_Params.m_bInvert) - pOffs->Invert() ; - - // aggiungo la lavorazione di questa curva - for ( int j = 1 ; j <= nStep ; ++ j) { - // ciclo sulle curve elementari - int nMaxInd = pOffs2->GetCurveCount() - 1 ; - for ( int i = 0 ; i <= nMaxInd ; ++ i) { - // curva corrente - const ICurve* pCrvC = pOffs2->GetCurve( i) ; - // copio la curva - PtrOwner pCurve( pCrvC->Clone()) ; - if ( IsNull( pCurve)) - return false ; - // aggiungo affondamento - pCurve->Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; - // se prima entità - if ( i == 0 ) { - // dati inizio entità - Point3d ptStart ; - pCurve->GetStartPoint( ptStart) ; - Vector3d vtStart ; - pCurve->GetStartDir( vtStart) ; - // se primo step, approccio e affondo - if ( j == 1) { - // determino inizio attacco - if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, nullptr, ptP1)) - return false ; - // determino elevazione su inizio attacco - double dStElev ; - if ( ! GetElevation( m_nPhase, ptStart - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), vtTool, dStElev)) - dStElev = dElev ; - dStElev -= ( ptP1 - ptStart) * vtExtr ; - // se attacco a zigzag o a spirale o a scivolo, l'elevazione va nell'attacco - if ( GetLeadInType() == POCKET_LI_ZIGZAG || - GetLeadInType() == POCKET_LI_HELIX || - GetLeadInType() == POCKET_LI_GLIDE) { - ptP1 += vtExtr * dStElev ; - dStElev = 0 ; - } - // approccio al punto iniziale - if ( ! AddLinkApproach( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dStElev, dAppr)) { - m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; - return false ; - } - // aggiungo attacco - SetFeed( GetStartFeed()) ; - if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, nullptr, ! m_Params.m_bInvert, bSplitArcs)) { - m_pMchMgr->SetLastError( 2415, "Error in Pocketing : LeadIn not computable") ; - return false ; - } - } - // altrimenti solo collegamento - else { - SetFeed( GetStartFeed()) ; - ptP1 -= vtExtr * dStep ; - if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, nullptr, ! m_Params.m_bInvert, bSplitArcs)) { - m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; - return false ; - } - } - } - // elaborazioni sulla curva corrente - if ( pCurve->GetType() == CRV_LINE) { - ICurveLine* pLine = GetCurveLine( pCurve) ; - Point3d ptP3 = pLine->GetEnd() ; - SetFeed( GetFeed()) ; - if ( AddLinearMove( ptP3) == GDB_ID_NULL) - return false ; - } - else if ( pCurve->GetType() == CRV_ARC) { - ICurveArc* pArc = GetCurveArc( pCurve) ; - Point3d ptCen = pArc->GetCenter() ; - double dAngCen = pArc->GetAngCenter() ; - Vector3d vtN = pArc->GetNormVersor() ; - Point3d ptP3 ; - pArc->GetEndPoint( ptP3) ; - SetFeed( GetFeed()) ; - if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) - return false ; - } - // se ultima entità - if ( i == nMaxInd) { - // se ultimo step, uscita e retrazione di collegamento - if ( j == nStep) { - // dati fine entità - Point3d ptEnd ; - pCurve->GetEndPoint( ptEnd) ; - Vector3d vtEnd ; - pCurve->GetEndDir( vtEnd) ; - // aggiungo uscita - Point3d ptP1 ; - double dEndElev = dElev ; - SetFeed( GetEndFeed()) ; - if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, nullptr, bSplitArcs, ptP1, dEndElev)) { - m_pMchMgr->SetLastError( 2416, "Error in Pocketing : LeadOut not computable") ; - return false ; - } - // aggiungo retrazione - if ( ! AddRetract( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dEndElev, dAppr)) { - m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Retract not computable") ; - return false ; + // se ultimo step, uscita e retrazione di collegamento + if ( j == nStep) { + // dati fine entità + Point3d ptEnd ; + pCurve->GetEndPoint( ptEnd) ; + Vector3d vtEnd ; + pCurve->GetEndDir( vtEnd) ; + // aggiungo uscita + double dEndElev = dElev ; + SetFeed( GetEndFeed()) ; + if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, nullptr, bSplitArcs, ptP1, dEndElev)) { + m_pMchMgr->SetLastError( 2416, "Error in Pocketing : LeadOut not computable") ; + return false ; + } + // se ci sono ancora curve, aggiungo retrazione di collegamento + if ( OffsCrv2.GetCurveCount() > 0) { + if ( ! AddLinkRetract( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dEndElev, dAppr)) { + m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; + return false ; + } + } + // altrimenti retrazione finale + else { + if ( ! AddRetract( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dEndElev, dAppr)) { + m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Retract not computable") ; + return false ; + } + } } } } @@ -1989,120 +2012,128 @@ Pocketing::AddOneWay( const ICurveComposite* pCompo, const Vector3d& vtTool, con m_pMchMgr->SetLastError( 2412, "Error in Pocketing : Offset not computable") ; return false ; } - // recupero la prima curva di offset - PtrOwner pOffs( CreateCurveComposite()) ; - if ( IsNull( pOffs) || ! pOffs->AddCurve( OffsCrv.GetLongerCurve())) { - m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; - return false ; - } - // se richiesto, la inverto - if ( m_Params.m_bInvert) - pOffs->Invert() ; + // ciclo sulle curve risultanti + while ( OffsCrv.GetCurveCount() > 0) { - // coefficiente di riduzione feed di lavorazione di questa curva - double dFeedRid = min( GetSideStep() / m_TParams.m_dDiam, 1.0) ; + // recupero la prima curva di offset + PtrOwner pOffs( CreateCurveComposite()) ; + if ( IsNull( pOffs) || ! pOffs->AddCurve( OffsCrv.GetLongerCurve())) { + m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; + return false ; + } - // aggiungo la lavorazione di questa curva - Point3d ptP1 ; - for ( int j = 1 ; j <= nStep ; ++ j) { - // ciclo sulle curve elementari - int nMaxInd = pOffs->GetCurveCount() - 1 ; - for ( int i = 0 ; i <= nMaxInd ; ++ i) { - // curva corrente - const ICurve* pCrvC = pOffs->GetCurve( i) ; - // copio la curva - PtrOwner pCurve( pCrvC->Clone()) ; - if ( IsNull( pCurve)) - return false ; - // aggiungo affondamento - pCurve->Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; - // se prima entità - if ( i == 0 ) { - // dati inizio entità - Point3d ptStart ; - pCurve->GetStartPoint( ptStart) ; - Vector3d vtStart ; - pCurve->GetStartDir( vtStart) ; - // se primo step, approccio e affondo - if ( j == 1) { - // determino inizio attacco - if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, nullptr, ptP1)) - return false ; - // determino elevazione su inizio attacco - double dStElev ; - if ( ! GetElevation( m_nPhase, ptStart - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), vtTool, dStElev)) - dStElev = dElev ; - dStElev -= ( ptP1 - ptStart) * vtExtr ; - // se attacco a zigzag o a spirale o a scivolo, l'elevazione va nell'attacco - if ( GetLeadInType() == POCKET_LI_ZIGZAG || - GetLeadInType() == POCKET_LI_HELIX || - GetLeadInType() == POCKET_LI_GLIDE) { - ptP1 += vtExtr * dStElev ; - dStElev = 0 ; + // se richiesto, la inverto + if ( m_Params.m_bInvert) + pOffs->Invert() ; + + // sposto l'inizio a metà del tratto più lungo + AdjustContourStart( pOffs) ; + + // coefficiente di riduzione feed di lavorazione di questa curva + double dFeedRid = min( GetSideStep() / m_TParams.m_dDiam, 1.0) ; + + // aggiungo la lavorazione di questa curva + Point3d ptP1 ; + for ( int j = 1 ; j <= nStep ; ++ j) { + // ciclo sulle curve elementari + int nMaxInd = pOffs->GetCurveCount() - 1 ; + for ( int i = 0 ; i <= nMaxInd ; ++ i) { + // curva corrente + const ICurve* pCrvC = pOffs->GetCurve( i) ; + // copio la curva + PtrOwner pCurve( pCrvC->Clone()) ; + if ( IsNull( pCurve)) + return false ; + // aggiungo affondamento + pCurve->Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; + // se prima entità + if ( i == 0 ) { + // dati inizio entità + Point3d ptStart ; + pCurve->GetStartPoint( ptStart) ; + Vector3d vtStart ; + pCurve->GetStartDir( vtStart) ; + // se primo step, approccio e affondo + if ( j == 1) { + // determino inizio attacco + if ( ! CalcLeadInStart( ptStart, vtStart, vtExtr, nullptr, ptP1)) + return false ; + // determino elevazione su inizio attacco + double dStElev ; + if ( ! GetElevation( m_nPhase, ptStart - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), vtTool, dStElev)) + dStElev = dElev ; + dStElev -= ( ptP1 - ptStart) * vtExtr ; + // se attacco a zigzag o a spirale o a scivolo, l'elevazione va nell'attacco + if ( GetLeadInType() == POCKET_LI_ZIGZAG || + GetLeadInType() == POCKET_LI_HELIX || + GetLeadInType() == POCKET_LI_GLIDE) { + ptP1 += vtExtr * dStElev ; + dStElev = 0 ; + } + // approccio al punto iniziale + if ( ! AddApproach( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dStElev, dAppr)) { + m_pMchMgr->SetLastError( 2414, "Error in Pocketing : Approach not computable") ; + return false ; + } + // aggiungo attacco + SetFeed( GetStartFeed()) ; + if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, nullptr, ! m_Params.m_bInvert, bSplitArcs)) { + m_pMchMgr->SetLastError( 2415, "Error in Pocketing : LeadIn not computable") ; + return false ; + } } - // approccio al punto iniziale - if ( ! AddApproach( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dStElev, dAppr)) { - m_pMchMgr->SetLastError( 2414, "Error in Pocketing : Approach not computable") ; - return false ; - } - // aggiungo attacco - SetFeed( GetStartFeed()) ; - if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, nullptr, ! m_Params.m_bInvert, bSplitArcs)) { - m_pMchMgr->SetLastError( 2415, "Error in Pocketing : LeadIn not computable") ; - return false ; + // altrimenti solo collegamento + else { + SetFeed( GetStartFeed()) ; + ptP1 -= vtExtr * dStep ; + if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, nullptr, ! m_Params.m_bInvert, bSplitArcs)) { + m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; + return false ; + } } } - // altrimenti solo collegamento - else { - SetFeed( GetStartFeed()) ; - ptP1 -= vtExtr * dStep ; - if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtExtr, nullptr, ! m_Params.m_bInvert, bSplitArcs)) { - m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; + // elaborazioni sulla curva corrente + if ( pCurve->GetType() == CRV_LINE) { + ICurveLine* pLine = GetCurveLine( pCurve) ; + Point3d ptP3 = pLine->GetEnd() ; + SetFeed( dFeedRid * GetFeed()) ; + if ( AddLinearMove( ptP3) == GDB_ID_NULL) return false ; - } } - } - // elaborazioni sulla curva corrente - if ( pCurve->GetType() == CRV_LINE) { - ICurveLine* pLine = GetCurveLine( pCurve) ; - Point3d ptP3 = pLine->GetEnd() ; - SetFeed( dFeedRid * GetFeed()) ; - if ( AddLinearMove( ptP3) == GDB_ID_NULL) - return false ; - } - else if ( pCurve->GetType() == CRV_ARC) { - ICurveArc* pArc = GetCurveArc( pCurve) ; - Point3d ptCen = pArc->GetCenter() ; - double dAngCen = pArc->GetAngCenter() ; - Vector3d vtN = pArc->GetNormVersor() ; - Point3d ptP3 ; - pArc->GetEndPoint( ptP3) ; - SetFeed( dFeedRid * GetFeed()) ; - if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) - return false ; - } - // se ultima entità - if ( i == nMaxInd) { - // se ultimo step, uscita e retrazione di collegamento - if ( j == nStep) { - // dati fine entità - Point3d ptEnd ; - pCurve->GetEndPoint( ptEnd) ; - Vector3d vtEnd ; - pCurve->GetEndDir( vtEnd) ; - // aggiungo uscita - Point3d ptP1 ; - double dEndElev = dElev ; - SetFeed( GetEndFeed()) ; - if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, nullptr, bSplitArcs, ptP1, dEndElev)) { - m_pMchMgr->SetLastError( 2416, "Error in Pocketing : LeadOut not computable") ; - return false ; - } - // aggiungo retrazione - if ( ! AddLinkRetract( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dEndElev, dAppr)) { - m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; + else if ( pCurve->GetType() == CRV_ARC) { + ICurveArc* pArc = GetCurveArc( pCurve) ; + Point3d ptCen = pArc->GetCenter() ; + double dAngCen = pArc->GetAngCenter() ; + Vector3d vtN = pArc->GetNormVersor() ; + Point3d ptP3 ; + pArc->GetEndPoint( ptP3) ; + SetFeed( dFeedRid * GetFeed()) ; + if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) return false ; + } + // se ultima entità + if ( i == nMaxInd) { + // se ultimo step, uscita e retrazione di collegamento + if ( j == nStep) { + // dati fine entità + Point3d ptEnd ; + pCurve->GetEndPoint( ptEnd) ; + Vector3d vtEnd ; + pCurve->GetEndDir( vtEnd) ; + // aggiungo uscita + Point3d ptP1 ; + double dEndElev = dElev ; + SetFeed( GetEndFeed()) ; + if ( ! AddLeadOut( ptEnd, vtEnd, vtExtr, nullptr, bSplitArcs, ptP1, dEndElev)) { + m_pMchMgr->SetLastError( 2416, "Error in Pocketing : LeadOut not computable") ; + return false ; + } + // aggiungo retrazione + if ( ! AddLinkRetract( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dEndElev, dAppr)) { + m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; + return false ; + } } } } @@ -2116,112 +2147,116 @@ Pocketing::AddOneWay( const ICurveComposite* pCompo, const Vector3d& vtTool, con m_pMchMgr->SetLastError( 2412, "Error in Pocketing : Offset not computable") ; return false ; } - PtrOwner pOffs2( CreateCurveComposite()) ; - if ( IsNull( pOffs2) || ! pOffs2->AddCurve( OffsCrv2.GetLongerCurve())) { - m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; - return false ; - } - // determino il riferimento di base e il box della svuotatura - Frame3d frPocket ; - Point3d ptCen ; pCompo->GetCentroid( ptCen) ; - frPocket.Set( ptCen, vtExtr) ; - frPocket.Rotate( ptCen, vtExtr, m_Params.m_dSideAngle) ; - pOffs2->ToLoc( frPocket) ; - BBox3d b3Pocket ; - pOffs2->GetLocalBBox( b3Pocket) ; - Point3d ptMin ; double dDimX, dDimY, dDimZ ; - b3Pocket.GetMinDim( ptMin, dDimX, dDimY, dDimZ) ; + // ciclo sulle curve risultanti + while ( OffsCrv2.GetCurveCount() > 0) { - // passi in Y - int nYStep = static_cast( ceil( ( dDimY + 2 * dExtra) / GetSideStep())) ; - double dYStep = ( nYStep > 0 ? ( dDimY + 2 * dExtra) / nYStep : 0) ; - -- nYStep ; + PtrOwner pOffs2( CreateCurveComposite()) ; + if ( IsNull( pOffs2) || ! pOffs2->AddCurve( OffsCrv2.GetLongerCurve())) { + m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; + return false ; + } - // calcolo le linee di svuotatura - bool bStart = true ; - const double EXP_LEN = 1.0 ; - for ( int j = 1 ; j <= nStep ; ++ j) { - for ( int i = 1 ; i <= nYStep ; ++ i) { - // definisco la linea - PtrOwner pLine( CreateCurveLine()) ; - Point3d ptStart( ptMin.x - EXP_LEN, ptMin.y + ( - dExtra + i * dYStep), ptMin.z + dDimZ) ; - if ( IsNull( pLine) || ! pLine->SetPVL( ptStart, X_AX, dDimX + 2 * EXP_LEN)) { - m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; - return false ; - } - // calcolo la classificazione della curva rispetto al contorno esterno offsettato - IntersCurveCurve intCC( *pLine, *pOffs2) ; - CRVCVECTOR ccClass ; - if ( ! intCC.GetCurveClassification( 0, ccClass)) { - m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; - return false ; - } - // determino gli intervalli di curva da conservare - Intervals inOk ; - for ( auto& ccOne : ccClass) { - if ( ccOne.nClass == CRVC_IN || ccOne.nClass == CRVC_ON_P || ccOne.nClass == CRVC_ON_M) - inOk.Add( ccOne.dParS, ccOne.dParE) ; - } - // inserisco i tratti validi - double dParS, dParE ; - bool bFound = inOk.GetFirst( dParS, dParE) ; - while ( bFound) { - // calcolo inizio con affondamento - Point3d ptS ; pLine->GetPointD1D2( dParS, ICurve::FROM_PLUS, ptS) ; - ptS.ToGlob( frPocket) ; - ptS.Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; - // determino inizio attacco - Point3d ptP ; - if ( ! CalcLeadInStart( ptS, frPocket.VersX(), vtExtr, nullptr, ptP)) - return false ; - // determino elevazione su inizio attacco - double dStElev ; - if ( ! GetElevation( m_nPhase, ptS - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), vtTool, dStElev)) - dStElev = dElev ; - dStElev -= ( ptP - ptS) * vtExtr ; - // sempre approccio di collegamento - if ( ! AddLinkApproach( ptP, vtTool, dSafeZ, dSafeAggrBottZ, dStElev, dAppr)) { - m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; + // determino il riferimento di base e il box della svuotatura + Frame3d frPocket ; + Point3d ptCen ; pCompo->GetCentroid( ptCen) ; + frPocket.Set( ptCen, vtExtr) ; + frPocket.Rotate( ptCen, vtExtr, m_Params.m_dSideAngle) ; + pOffs2->ToLoc( frPocket) ; + BBox3d b3Pocket ; + pOffs2->GetLocalBBox( b3Pocket) ; + Point3d ptMin ; double dDimX, dDimY, dDimZ ; + b3Pocket.GetMinDim( ptMin, dDimX, dDimY, dDimZ) ; + + // passi in Y + int nYStep = static_cast( ceil( ( dDimY + 2 * dExtra) / GetSideStep())) ; + double dYStep = ( nYStep > 0 ? ( dDimY + 2 * dExtra) / nYStep : 0) ; + -- nYStep ; + + // calcolo le linee di svuotatura + const double EXP_LEN = 1.0 ; + for ( int j = 1 ; j <= nStep ; ++ j) { + for ( int i = 1 ; i <= nYStep ; ++ i) { + // definisco la linea + PtrOwner pLine( CreateCurveLine()) ; + Point3d ptStart( ptMin.x - EXP_LEN, ptMin.y + ( - dExtra + i * dYStep), ptMin.z + dDimZ) ; + if ( IsNull( pLine) || ! pLine->SetPVL( ptStart, X_AX, dDimX + 2 * EXP_LEN)) { + m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; return false ; } - // aggiungo attacco - SetFeed( GetStartFeed()) ; - if ( ! AddLeadIn( ptP, ptS, frPocket.VersX(), vtExtr, nullptr, ! m_Params.m_bInvert, bSplitArcs, true)) { - m_pMchMgr->SetLastError( 2415, "Error in Pocketing : LeadIn not computable") ; + // calcolo la classificazione della curva rispetto al contorno esterno offsettato + IntersCurveCurve intCC( *pLine, *pOffs2) ; + CRVCVECTOR ccClass ; + if ( ! intCC.GetCurveClassification( 0, ccClass)) { + m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ; return false ; } - // calcolo fine con affondamento - Point3d ptE ; pLine->GetPointD1D2( dParE, ICurve::FROM_MINUS, ptE) ; - ptE.ToGlob( frPocket) ; - ptE.Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; - // movimento al punto finale - SetFeed( GetFeed()) ; - if ( AddLinearMove( ptE) == GDB_ID_NULL) - return false ; - // risalita - Point3d ptQ ; - double dEndElev = dElev ; - SetFeed( GetEndFeed()) ; - if ( ! AddLeadOut( ptE, frPocket.VersX(), vtExtr, nullptr, bSplitArcs, ptQ, dEndElev, true)) { - m_pMchMgr->SetLastError( 2416, "Error in Pocketing : LeadOut not computable") ; - return false ; + // determino gli intervalli di curva da conservare + Intervals inOk ; + for ( auto& ccOne : ccClass) { + if ( ccOne.nClass == CRVC_IN || ccOne.nClass == CRVC_ON_P || ccOne.nClass == CRVC_ON_M) + inOk.Add( ccOne.dParS, ccOne.dParE) ; } - // recupero successivo intervallo - bFound = inOk.GetNext( dParS, dParE) ; - // se ultimo movimento, aggiungo retrazione globale - if ( j == nStep && i == nYStep && ! bFound) { - if ( ! AddRetract( ptQ, vtTool, dSafeZ, dSafeAggrBottZ, dEndElev, dAppr)) { - m_pMchMgr->SetLastError( 2417, "Error in Pocketing : Retract not computable") ; + // inserisco i tratti validi + double dParS, dParE ; + bool bFound = inOk.GetFirst( dParS, dParE) ; + while ( bFound) { + // calcolo inizio con affondamento + Point3d ptS ; pLine->GetPointD1D2( dParS, ICurve::FROM_PLUS, ptS) ; + ptS.ToGlob( frPocket) ; + ptS.Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; + // determino inizio attacco + Point3d ptP ; + if ( ! CalcLeadInStart( ptS, frPocket.VersX(), vtExtr, nullptr, ptP)) return false ; - } - } - // altrimenti aggiungo retrazione di collegamento - else { - if ( ! AddLinkRetract( ptQ, vtTool, dSafeZ, dSafeAggrBottZ, dEndElev, dAppr)) { + // determino elevazione su inizio attacco + double dStElev ; + if ( ! GetElevation( m_nPhase, ptS - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), vtTool, dStElev)) + dStElev = dElev ; + dStElev -= ( ptP - ptS) * vtExtr ; + // sempre approccio di collegamento + if ( ! AddLinkApproach( ptP, vtTool, dSafeZ, dSafeAggrBottZ, dStElev, dAppr)) { m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; return false ; } + // aggiungo attacco + SetFeed( GetStartFeed()) ; + if ( ! AddLeadIn( ptP, ptS, frPocket.VersX(), vtExtr, nullptr, ! m_Params.m_bInvert, bSplitArcs, true)) { + m_pMchMgr->SetLastError( 2415, "Error in Pocketing : LeadIn not computable") ; + return false ; + } + // calcolo fine con affondamento + Point3d ptE ; pLine->GetPointD1D2( dParE, ICurve::FROM_MINUS, ptE) ; + ptE.ToGlob( frPocket) ; + ptE.Translate( - vtTool * ( dDepth - dElev + j * dStep)) ; + // movimento al punto finale + SetFeed( GetFeed()) ; + if ( AddLinearMove( ptE) == GDB_ID_NULL) + return false ; + // risalita + Point3d ptQ ; + double dEndElev = dElev ; + SetFeed( GetEndFeed()) ; + if ( ! AddLeadOut( ptE, frPocket.VersX(), vtExtr, nullptr, bSplitArcs, ptQ, dEndElev, true)) { + m_pMchMgr->SetLastError( 2416, "Error in Pocketing : LeadOut not computable") ; + return false ; + } + // recupero successivo intervallo + bFound = inOk.GetNext( dParS, dParE) ; + // se ultimo movimento di ultima area, aggiungo retrazione globale + if ( j == nStep && i == nYStep && ! bFound && OffsCrv2.GetCurveCount() == 0) { + if ( ! AddRetract( ptQ, vtTool, dSafeZ, dSafeAggrBottZ, dEndElev, dAppr)) { + m_pMchMgr->SetLastError( 2417, "Error in Pocketing : Retract not computable") ; + return false ; + } + } + // altrimenti aggiungo retrazione di collegamento + else { + if ( ! AddLinkRetract( ptQ, vtTool, dSafeZ, dSafeAggrBottZ, dEndElev, dAppr)) { + m_pMchMgr->SetLastError( 2418, "Error in Pocketing : Link not computable") ; + return false ; + } + } } } }