From 37d0b8f552853c15303994b598f1d0092e0de5fb Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Thu, 22 Feb 2024 16:59:14 +0100 Subject: [PATCH 1/2] EgtMachKernel : - in Milling corretto calcolo punto inizio attacco nel caso percorso invertito per ZigZag o similare. --- Milling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Milling.cpp b/Milling.cpp index 1c07b62..6f84fe8 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -4311,7 +4311,7 @@ Milling::CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, const if ( bInvert) { // va aggiustato se non zigzag o spirale if ( nType != MILL_LI_ZIGZAG && nType != MILL_LI_HELIX) { - switch ( m_Params.m_nLeadOutType) { + switch ( GetLeadOutType()) { case MILL_LO_LINEAR : nType = MILL_LI_LINEAR ; break ; case MILL_LO_PERP_TG : nType = MILL_LI_TG_PERP ; break ; case MILL_LO_TANGENT : nType = MILL_LI_TANGENT ; break ; From d3b281a858c34a3f760c5afd925417b421b1a6d6 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 26 Feb 2024 15:15:07 +0100 Subject: [PATCH 2/2] =?UTF-8?q?EgtMachKernel=20:=20-=20migliorata=20fresat?= =?UTF-8?q?ura=20di=20lato=20con=20lama=20con=20pi=C3=B9=20passaggi=20(Zig?= =?UTF-8?q?Zag=20e=20OneWay)=20con=20note=20utente=20=20=20=20=20=20=20Sid?= =?UTF-8?q?eElev=20anche=20negativa=20per=20avere=20controllo=20MaxMat=20c?= =?UTF-8?q?on=20Step=20=20=20=20=20=20=20TrimExt=3DnClosedStmId=20per=20de?= =?UTF-8?q?finire=20superficie=20chiusa=20con=20cui=20estendere/trimmare?= =?UTF-8?q?=20il=20percorso=20di=20lavoro.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Milling.cpp | 377 +++++++++++++++++++++++++++++++++++++++++++----- Milling.h | 7 +- Operation.cpp | 4 +- Operation.h | 14 +- OperationCL.cpp | 24 +-- 5 files changed, 371 insertions(+), 55 deletions(-) diff --git a/Milling.cpp b/Milling.cpp index 6f84fe8..072cc7e 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -33,6 +33,7 @@ #include "/EgtDev/Include/EGkSurfTriMesh.h" #include "/EgtDev/Include/EGkExtText.h" #include "/EgtDev/Include/EGkDistPointCurve.h" +#include "/EgtDev/Include/EGkIntersCurveSurfTm.h" #include "/EgtDev/Include/EGkIntervals.h" #include "/EgtDev/Include/EGkUserObjFactory.h" #include "/EgtDev/Include/EGnStringKeyVal.h" @@ -53,7 +54,7 @@ const double DELTA_ELEV_RAD = 4.0 ; // 2303 = "Error in Milling : Empty RawBox" // 2304 = "Error in Milling : Depth not computable" // 2305 = "Error in Milling : machining depth (xx) bigger than MaxMaterial (yy)" -// 2306 = "Error in Milling : Entity GetElevation" +// 2306 = "Error in Milling : machining step (xx) bigger than MaxMaterial (yy)" // 2307 = "Error in Milling : missing aggregate from bottom" // 2308 = "Error in Milling : path too far from part sides" // 2309 = "Error in Milling : Approach not computable" @@ -1831,7 +1832,7 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) dOkStep = m_Params.m_dStep + EPS_ZERO ; else if ( m_Params.m_dStep < -EPS_SMALL && ( m_TParams.m_nType == TT_MILL_NOTIP || - ( ( m_TParams.m_nType & TF_SAWBLADE) != 0 && dSideElev < 10 * EPS_SMALL))) { + ( ( m_TParams.m_nType & TF_SAWBLADE) != 0 && abs( dSideElev) < 10 * EPS_SMALL))) { dOkStep = abs( m_Params.m_dStep) + EPS_ZERO ; bStepUp = true ; } @@ -1902,12 +1903,27 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) } } // per lame e con elevazione di lato definita - else if ( dSideElev > EPS_SMALL) { - if ( dSideElev > m_TParams.m_dMaxMat) { - string sInfo = "Error in Milling : machining depth (" + ToString( dSideElev, 1) + - ") bigger than MaxMaterial (" + ToString( m_TParams.m_dMaxMat, 1) + ")" ; - m_pMchMgr->SetLastError( 2305, sInfo) ; - return false ; + else if ( abs( dSideElev) > EPS_SMALL) { + // caso standard + if ( dSideElev > 0) { + // se l'elevazione di lato supera la capacità dell'utensile + if ( dSideElev > m_TParams.m_dMaxMat + EPS_SMALL) { + string sInfo = "Error in Milling : machining depth (" + ToString( dSideElev, 1) + + ") bigger than MaxMaterial (" + ToString( m_TParams.m_dMaxMat, 1) + ")" ; + m_pMchMgr->SetLastError( 2305, sInfo) ; + return false ; + } + } + // per tagli a cubetti (ciascuno step di taglio cade) + else { + // se lo step supera la capacità dell'utensile + if ( m_Params.m_dStep > m_TParams.m_dMaxMat + EPS_SMALL) { + string sInfo = "Error in Milling : machining step (" + ToString( m_Params.m_dStep, 1) + + ") bigger than MaxMaterial (" + ToString( m_TParams.m_dMaxMat, 1) + ")" ; + m_pMchMgr->SetLastError( 2306, sInfo) ; + return false ; + } + dSideElev = abs( dSideElev) ; } } @@ -1986,7 +2002,10 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) // Se lama con elevazione e step di fianco if ( ( m_TParams.m_nType & TF_SAWBLADE) != 0 && dSideElev > 10 * EPS_SMALL && dOkStep > EPS_SMALL) { m_bStepOn = true ; - bOk = AddSawZigZagMilling( pCompo, vtTool, dDepth, dSideElev, dOkStep, bSplitArcs) ; + if ( m_Params.m_nStepType != MILL_ST_ONEWAY) + bOk = AddSawZigZagMilling( pCompo, vtTool, dDepth, dSideElev, dOkStep, bSplitArcs) ; + else + bOk = AddSawOneWayMilling( pCompo, vtTool, dDepth, dSideElev, dOkStep, bSplitArcs) ; } // se altrimenti una sola passata else if ( dOkStep < EPS_SMALL || dOkStep > dElev) { @@ -3810,20 +3829,26 @@ class LeadIOStatus LeadIOStatus( Milling* pMill) { m_pMill = pMill ; m_dLiPerp = m_pMill->m_Params.m_dLiPerp ; + m_dLiTang = m_pMill->m_Params.m_dLiTang ; m_dLoPerp = m_pMill->m_Params.m_dLoPerp ; + m_dLoTang = m_pMill->m_Params.m_dLoTang ; } ~LeadIOStatus( void) { Restore() ; } void Restore( void) { m_pMill->m_Params.m_dLiPerp = m_dLiPerp ; + m_pMill->m_Params.m_dLiTang = m_dLiTang ; m_pMill->m_Params.m_dLoPerp = m_dLoPerp ; + m_pMill->m_Params.m_dLoTang = m_dLoTang ; } private : Milling* m_pMill ; double m_dLiPerp ; + double m_dLiTang ; double m_dLoPerp ; + double m_dLoTang ; } ; //---------------------------------------------------------------------------- @@ -3839,44 +3864,64 @@ Milling::AddSawZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtT // flag di percorso chiuso bool bClosed = pCompo->IsClosed() ; + // recupero eventuale superficie trimesh chiusa per trim/extend + int nTriExtCstm = GDB_ID_NULL ; + int nTesId ; + if ( FromString( ExtractInfo( m_Params.m_sUserNotes, "TrimExt="), nTesId)) { + const ISurfTriMesh* pTes = GetSurfTriMesh( m_pGeomDB->GetGeoObj( nTesId)) ; + if ( pTes != nullptr && pTes->IsClosed()) + nTriExtCstm = nTesId ; + } + // determino numero e affondamento degli step int nStep = max( 1, static_cast( ceil( dElev / dOkStep))) ; double dStep = dElev / nStep ; // gestione parametri di attacco/uscita (con backup per ripristino all'uscita) LeadIOStatus LioStatus( this) ; - bool bAdjustLiPerp = ( m_Params.m_dLiPerp > EPS_SMALL) ; - if ( bAdjustLiPerp) - m_Params.m_dLiPerp = max( 0., m_Params.m_dLiPerp - ( nStep - 1) * dStep) ; - bool bAdjustLoPerp = ( m_Params.m_dLoPerp > EPS_SMALL) ; - m_Params.m_dLoPerp = 0. ; + bool bAdjustLiPerp = ( m_Params.m_dLiPerp > 10 * EPS_SMALL) ; + if ( bAdjustLiPerp) { + double dNewLiPerp = max( 0., m_Params.m_dLiPerp - ( nStep - 1) * dStep) ; + m_Params.m_dLiTang *= dNewLiPerp / m_Params.m_dLiPerp ; + m_Params.m_dLiPerp = dNewLiPerp ; + } + bool bAdjustLoPerp = ( m_Params.m_dLoPerp > 10 * EPS_SMALL) ; + if ( bAdjustLoPerp) { + m_Params.m_dLoTang = 0 ; + m_Params.m_dLoPerp = 0. ; + } // ciclo sugli step for ( int j = 1 ; j <= nStep ; ++ j) { - // flag direzione (prima passata indice 1) - bool bInvert = ( ( j % 2) == 0) ; + // flag direzione + bool bInvert = ( (( nStep - j) % 2) == 1) ; // copio la curva PtrOwner pMyCompo( pCompo->Clone()) ; if ( IsNull( pMyCompo)) return false ; - // eseguo offset + // eseguo offset ed eventuale inversione double dSignOffs = ( dElev - j * dStep) * ( m_Params.m_nWorkSide == MILL_WS_LEFT ? - 1 : 1) ; if ( ! CalcOffset( pMyCompo, dSignOffs)) return false ; - // dopo primo step annullo parametro di attacco - if ( j > 1) + if ( bInvert) + pMyCompo->Invert() ; + // eventuale trim/extend con la superficie indicata + if ( nTriExtCstm != GDB_ID_NULL) { + // trim con ripristino dell'originale in caso di errore + PtrOwner pMyCopy( pMyCompo->Clone()) ; + if ( ! TrimExtendCurveToClosedStm( pMyCompo, nTriExtCstm, bInvert)) + pMyCompo.Set( pMyCopy) ; + } + // dopo primo step annullo parametri di attacco + if ( j > 1 && bAdjustLiPerp) { m_Params.m_dLiPerp = 0. ; + m_Params.m_dLiTang = 0. ; + } // ciclo sulle curve elementari - int nMaxInd = pCompo->GetCurveCount() - 1 ; + int nMaxInd = pMyCompo->GetCurveCount() - 1 ; for ( int i = 0 ; i <= nMaxInd ; ++ i) { // curva corrente - const ICurve* pCrvC = pMyCompo->GetCurve( ( bInvert ? nMaxInd - i : i)) ; - // copio la curva - PtrOwner pCurve( pCrvC->Clone()) ; - if ( IsNull( pCurve)) - return false ; - if ( bInvert) - pCurve->Invert() ; + const ICurve* pCurve = pMyCompo->GetCurve( i) ; // se prima entità, se primo step approccio e sempre affondo if ( i == 0) { // dati inizio entità @@ -3896,15 +3941,15 @@ Milling::AddSawZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtT Point3d ptP1 ; Vector3d vtDir1 ; double dCalcStElev = dStElev ; - if ( ! CalcLeadInStart( ptStart, vtStart, vtTool, dCalcStElev, bInvert, pCompo, ptP1, vtDir1)) + if ( ! CalcLeadInStart( ptStart, vtStart, vtTool, dCalcStElev, bInvert, pMyCompo, ptP1, vtDir1)) return false ; // determino se l'inizio dell'attacco è fuori dal grezzo - Vector3d vtCorr = CalcCorrDir( pCompo, ( bInvert ? nMaxInd - i + 1 : i)) ; + Vector3d vtCorr = CalcCorrDir( pMyCompo, i, bInvert) ; bool bOutStart = GetPointOutOfRaw( ptP1, vtTool, vtCorr, dElev, dSafeZ) ; // determino se l'inizio dell'attacco è sopra il grezzo bool bAboveStart = m_bAboveHead && GetPointAboveRaw( ptP1, vtTool) ; // imposto versore correzione e ausiliario sul punto di partenza - CalcAndSetCorrAuxDir( pCompo, ( bInvert ? nMaxInd - i + 1 : i)) ; + CalcAndSetCorrAuxDir( pMyCompo, i, bInvert) ; // se primo step if ( j == 1) { // verifico di entrare in aria @@ -3927,23 +3972,23 @@ Milling::AddSawZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtT // aggiungo attacco bool bTang = (( ! bInvert && m_Params.m_dLiTang > EPS_SMALL) || ( bInvert && m_Params.m_dLoTang > EPS_SMALL)) ; SetFeed( bTang ? GetStartFeed() : GetTipFeed()) ; - if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtTool, dCalcStElev, bInvert, pCompo, bSplitArcs)) { + if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtTool, dCalcStElev, bInvert, pMyCompo, bSplitArcs)) { m_pMchMgr->SetLastError( 2310, "Error in Milling : LeadIn not computable") ; return false ; } } // imposto versore correzione e ausiliario sul punto di arrivo - CalcAndSetCorrAuxDir( pCompo, ( bInvert ? nMaxInd - i : i + 1)) ; + CalcAndSetCorrAuxDir( pMyCompo, i + 1, bInvert) ; // elaborazioni sulla curva corrente if ( pCurve->GetType() == CRV_LINE) { - ICurveLine* pLine = GetCurveLine( pCurve) ; + const 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) ; + const ICurveArc* pArc = GetCurveArc( pCurve) ; Point3d ptCen = pArc->GetCenter() ; double dAngCen = pArc->GetAngCenter() ; Vector3d vtN = pArc->GetNormVersor() ; @@ -3974,8 +4019,202 @@ Milling::AddSawZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtT // aggiungo uscita Point3d ptP1 ; Vector3d vtDir1 ; + SetFlag( 301, false) ; SetFeed( GetEndFeed()) ; - if ( ! AddLeadOut( ptEnd, vtEnd, vtTool, dEndElev, bInvert, pCompo, bSplitArcs, ptP1, vtDir1)) { + if ( ! AddLeadOut( ptEnd, vtEnd, vtTool, dEndElev, bInvert, pMyCompo, bSplitArcs, ptP1, vtDir1)) { + m_pMchMgr->SetLastError( 2311, "Error in Milling : LeadOut not computable") ; + return false ; + } + // per lame retrazione non è necessaria + } + } + } + return true ; +} + +//---------------------------------------------------------------------------- +bool +Milling::AddSawOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool, + double dDepth, double dElev, double dOkStep, bool bSplitArcs) +{ + // recupero distanze di sicurezza + double dSafeZ = m_pMchMgr->GetCurrMachiningsMgr()->GetSafeZ() ; + double dSafeAggrBottZ = m_pMchMgr->GetCurrMachiningsMgr()->GetSafeAggrBottZ() ; + // lunghezza di approccio/retrazione + double dAppr = m_Params.m_dStartPos ; + // flag di percorso chiuso + bool bClosed = pCompo->IsClosed() ; + + // recupero eventuale superficie trimesh chiusa per trim/extend + int nTriExtCstm = GDB_ID_NULL ; + int nTesId ; + if ( FromString( ExtractInfo( m_Params.m_sUserNotes, "TrimExt="), nTesId)) { + const ISurfTriMesh* pTes = GetSurfTriMesh( m_pGeomDB->GetGeoObj( nTesId)) ; + if ( pTes != nullptr && pTes->IsClosed()) + nTriExtCstm = nTesId ; + } + + // determino numero e affondamento degli step + int nStep = max( 1, static_cast( ceil( dElev / dOkStep))) ; + double dStep = dElev / nStep ; + + // gestione parametri di attacco/uscita (con backup per ripristino all'uscita) + LeadIOStatus LioStatus( this) ; + bool bAdjustLiPerp = ( m_Params.m_dLiPerp > 10 * EPS_SMALL) ; + if ( bAdjustLiPerp) { + double dNewLiPerp = max( 0., m_Params.m_dLiPerp - ( nStep - 1) * dStep) ; + m_Params.m_dLiTang *= dNewLiPerp / m_Params.m_dLiPerp ; + m_Params.m_dLiPerp = dNewLiPerp ; + } + bool bAdjustLoPerp = ( m_Params.m_dLoPerp > 10 * EPS_SMALL) ; + if ( bAdjustLoPerp) { + m_Params.m_dLoTang = 0 ; + m_Params.m_dLoPerp = 0. ; + } + + // ciclo su step più ritorni (quelli pari sono i ritorni) + for ( int k = 1 ; k <= 2 * nStep - 1 ; ++ k) { + // indice step + int j = ( k + 1) / 2 ; + // flag ritorno + bool bReturn = ( ( k % 2) == 0) ; + // copio la curva + PtrOwner pMyCompo( pCompo->Clone()) ; + if ( IsNull( pMyCompo)) + return false ; + // eseguo offset ed eventuale inversione per ritorno + double dDelta = ( bReturn ? min( dStep, 5.) : 0) ; + double dSignOffs = ( dElev - j * dStep + dDelta) * ( m_Params.m_nWorkSide == MILL_WS_LEFT ? - 1 : 1) ; + if ( ! CalcOffset( pMyCompo, dSignOffs)) + return false ; + if ( bReturn) + pMyCompo->Invert() ; + // eventuale trim/extend con la superficie indicata + if ( nTriExtCstm != GDB_ID_NULL) { + // trim con ripristino dell'originale in caso di errore + PtrOwner pMyCopy( pMyCompo->Clone()) ; + if ( ! TrimExtendCurveToClosedStm( pMyCompo, nTriExtCstm, bReturn)) + pMyCompo.Set( pMyCopy) ; + } + // dopo primo step annullo parametro di attacco + if ( k > 1 && bAdjustLiPerp) { + m_Params.m_dLiPerp = 0. ; + m_Params.m_dLiTang = 0. ; + } + // ciclo sulle curve elementari + int nMaxInd = pMyCompo->GetCurveCount() - 1 ; + for ( int i = 0 ; i <= nMaxInd ; ++ i) { + // curva corrente + const ICurve* pCurve = pMyCompo->GetCurve( i) ; + // se prima entità, se primo step approccio e sempre affondo + if ( i == 0) { + // dati inizio entità + Point3d ptStart ; + pCurve->GetStartPoint( ptStart) ; + Vector3d vtStart ; + pCurve->GetStartDir( vtStart) ; + // determino elevazione su inizio attacco + double dStElev ; + if ( k == 1) { + if ( ! GetElevation( m_nPhase, ptStart, vtTool, GetRadiusForStartEndElevation(), vtTool, dStElev)) + dStElev = dElev ; + } + else + dStElev = dStep - LIO_ELEV_TOL - 10 * EPS_SMALL ; + // determino inizio attacco + Point3d ptP1 ; + Vector3d vtDir1 ; + double dCalcStElev = dStElev ; + if ( ! CalcLeadInStart( ptStart, vtStart, vtTool, dCalcStElev, bReturn, pMyCompo, ptP1, vtDir1)) + return false ; + // determino se l'inizio dell'attacco è fuori dal grezzo + Vector3d vtCorr = CalcCorrDir( pMyCompo, i, bReturn) ; + bool bOutStart = GetPointOutOfRaw( ptP1, vtTool, vtCorr, dElev, dSafeZ) ; + // determino se l'inizio dell'attacco è sopra il grezzo + bool bAboveStart = m_bAboveHead && GetPointAboveRaw( ptP1, vtTool) ; + // imposto versore correzione e ausiliario sul punto di partenza + CalcAndSetCorrAuxDir( pMyCompo, i, bReturn) ; + // se primo step + if ( k == 1) { + // verifico di entrare in aria + if ( ! bOutStart) { + m_pMchMgr->SetLastError( 2314, "Error in Milling : LeadIn must be out of rawpart") ; + return false ; + } + // eseguo affondo + SetFlag( 0) ; + if ( AddRapidStart( ptP1) == GDB_ID_NULL) + return false ; + } + // altrimenti, affondo ( o retrazione se Return) in feed opportuna + else { + bool bStartFeed = ( bOutStart || m_TParams.m_nType == TT_MILL_NOTIP || m_TParams.m_nType == TT_MILL_POLISHING) ; + SetFeed( bReturn ? GetEndFeed() : ( bStartFeed ? GetStartFeed() : GetTipFeed())) ; + if ( AddLinearMove( ptP1) == GDB_ID_NULL) + return false ; + } + // aggiungo attacco + bool bTang = (( ! bReturn && m_Params.m_dLiTang > EPS_SMALL) || ( bReturn && m_Params.m_dLoTang > EPS_SMALL)) ; + SetFeed( bReturn ? GetEndFeed() : ( bTang ? GetStartFeed() : GetTipFeed())) ; + if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtTool, dCalcStElev, bReturn, pMyCompo, bSplitArcs)) { + m_pMchMgr->SetLastError( 2310, "Error in Milling : LeadIn not computable") ; + return false ; + } + } + // imposto versore correzione e ausiliario sul punto di arrivo + CalcAndSetCorrAuxDir( pMyCompo, i + 1, bReturn) ; + // se Retrazione e ultima entità, dichiaro fine passata + if ( bReturn && i == nMaxInd) + SetFlag( 301) ; + // elaborazioni sulla curva corrente + if ( pCurve->GetType() == CRV_LINE) { + const ICurveLine* pLine = GetCurveLine( pCurve) ; + Point3d ptP3 = pLine->GetEnd() ; + SetFeed( bReturn ? GetEndFeed() : GetFeed()) ; + if ( AddLinearMove( ptP3) == GDB_ID_NULL) { + SetFlag( 0) ; + return false ; + } + } + else if ( pCurve->GetType() == CRV_ARC) { + const ICurveArc* pArc = GetCurveArc( pCurve) ; + Point3d ptCen = pArc->GetCenter() ; + double dAngCen = pArc->GetAngCenter() ; + Vector3d vtN = pArc->GetNormVersor() ; + Point3d ptP3 ; + pArc->GetEndPoint( ptP3) ; + SetFeed( bReturn ? GetEndFeed() : GetFeed()) ; + if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) { + SetFlag( 0) ; + return false ; + } + } + SetFlag( 0) ; + // se ultima entità, uscita e se ultimo step retrazione + if ( i == nMaxInd) { + // se ultima passata, ripristino parametri originali di attacco/uscita + if ( j == nStep) + LioStatus.Restore() ; + // dati fine entità + Point3d ptEnd ; + pCurve->GetEndPoint( ptEnd) ; + Vector3d vtEnd ; + pCurve->GetEndDir( vtEnd) ; + // elevazione sul punto finale + double dEndElev ; + if ( j == nStep) { + if ( ! GetElevation( m_nPhase, ptEnd, vtTool, GetRadiusForStartEndElevation(), vtTool, dEndElev)) + dEndElev = dElev ; + } + else + dEndElev = - LIO_ELEV_TOL ; + // aggiungo uscita + Point3d ptP1 ; + Vector3d vtDir1 ; + SetFeed( GetEndFeed()) ; + if ( ! bReturn) + SetFlag( 301, false) ; + if ( ! AddLeadOut( ptEnd, vtEnd, vtTool, dEndElev, bReturn, pMyCompo, bSplitArcs, ptP1, vtDir1)) { m_pMchMgr->SetLastError( 2311, "Error in Milling : LeadOut not computable") ; return false ; } @@ -5952,7 +6191,7 @@ Milling::GetPointAboveRaw( const Point3d& ptP, const Vector3d& vtTool) const //---------------------------------------------------------------------------- bool -Milling::CalcAndSetCorrAuxDir( const ICurveComposite* pCompo, double dU) +Milling::CalcAndSetCorrAuxDir( const ICurveComposite* pCompo, double dU, bool bInvertSide) { // verifico curva if ( pCompo == nullptr) @@ -5961,7 +6200,7 @@ Milling::CalcAndSetCorrAuxDir( const ICurveComposite* pCompo, double dU) if ( m_Params.m_nWorkSide == MILL_WS_CENTER) return true ; // calcolo del versore correzione - Vector3d vtCorr = CalcCorrDir( pCompo, dU) ; + Vector3d vtCorr = CalcCorrDir( pCompo, dU, bInvertSide) ; // imposto versore correzione SetCorrDir( vtCorr) ; // se rinvio da sotto in uso, non devo impostare direzione aux da correzione @@ -5981,7 +6220,7 @@ Milling::CalcAndSetCorrAuxDir( const ICurveComposite* pCompo, double dU) //---------------------------------------------------------------------------- Vector3d -Milling::CalcCorrDir( const ICurveComposite* pCompo, double dU) +Milling::CalcCorrDir( const ICurveComposite* pCompo, double dU, bool bInvertSide) { // verifico curva if ( pCompo == nullptr) @@ -5990,7 +6229,7 @@ Milling::CalcCorrDir( const ICurveComposite* pCompo, double dU) if ( m_Params.m_nWorkSide == MILL_WS_CENTER) return V_NULL ; // angolo di rotazione da tg a versore corr/aux - bool bCcwRot = (m_Params.m_nWorkSide == MILL_WS_LEFT) ; + bool bCcwRot = (( m_Params.m_nWorkSide == MILL_WS_LEFT) != bInvertSide) ; double dCaRot = ( bCcwRot ? ANG_RIGHT : -ANG_RIGHT) ; // dominio parametrico della curva double dUs, dUe ; @@ -6078,3 +6317,63 @@ Milling::CalcOffset( ICurveComposite* pCompo, double dSignOffs) } return false ; } + +//---------------------------------------------------------------------------- +bool +Milling::TrimExtendCurveToClosedStm( ICurveComposite* pCompo, int nCstmId, bool bInvert) +{ + // dati preparatori + const ISurfTriMesh* pCstm = GetSurfTriMesh( m_pGeomDB->GetGeoObj( nCstmId)) ; + if ( pCstm == nullptr || ! pCstm->IsClosed()) + return false ; + Frame3d frCstm ; + if ( ! m_pGeomDB->GetGlobFrame( nCstmId, frCstm)) + return false ; + BBox3d b3Tes = pCstm->GetAllTriaBox() ; + if ( b3Tes.IsEmpty()) + return false ; + double dTriExtLen ; + b3Tes.GetDiameter( dTriExtLen) ; + + // inverto offset su centro utensile + double dCompOffs = 0.5 * m_TParams.m_dDiam * ( ( m_Params.m_nWorkSide == MILL_WS_RIGHT) != bInvert ? 1 : -1) ; + if ( ! CalcOffset( pCompo, -dCompOffs)) + return false ; + // porto la curva nel riferimento della superficie + pCompo->ToLoc( frCstm) ; + + // allungo la curva in testa e coda per essere sicuro che gli estremi siano esterni + if ( ! pCompo->AddLineTg( dTriExtLen, false) || ! pCompo->AddLineTg( dTriExtLen, true)) + return false ; + // calcolo intersezioni con superficie chiusa + INTDBLVECTOR vInters ; + if ( ! IntersCurveSurfTmExt( *pCompo, *pCstm, 10 * EPS_SMALL, vInters)) + return false ; + // prendo prima intersezione entrante e ultima uscente + double dParStart = -1 ; + for ( int i = 0 ; i < int( vInters.size()) ; ++ i) { + if ( vInters[i].first == CSIT_OUT_IN || vInters[i].first == CSIT_ON_IN) { + dParStart = vInters[i].second ; + break ; + } + } + double dParEnd = -1 ; + for ( int i = int( vInters.size()) - 1 ; i >= 0 ; -- i) { + if ( vInters[i].first == CSIT_IN_OUT || vInters[i].first == CSIT_IN_ON) { + dParEnd = vInters[i].second ; + break ; + } + } + // eseguo trim ed unisco le eventuali parti allineate + if ( ! pCompo->TrimStartEndAtParam( dParStart, dParEnd) || + ! pCompo->MergeCurves(10 * EPS_SMALL, 10 * EPS_ANG_SMALL)) + return false ; + + // riporto la curva in globale + pCompo->ToGlob( frCstm) ; + // ritorno in centro utensile + if ( ! CalcOffset(pCompo, dCompOffs)) + return false ; + + return true ; +} diff --git a/Milling.h b/Milling.h index 38fe988..71217d6 100644 --- a/Milling.h +++ b/Milling.h @@ -96,6 +96,8 @@ class Milling : public Machining double dDepth, double dElev, double dOkStep, bool bSplitArcs, bool bPathTabsEnable, bool bPathOscEnable) ; bool AddSawZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dElev, double dOkStep, bool bSplitArcs) ; + bool AddSawOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool, + double dDepth, double dElev, double dOkStep, bool bSplitArcs) ; bool AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dSafeAggrBottZ, double dElev, double dAppr, bool bOutStart, bool bAboveStart) ; bool AddSawBladeSideApproach( const Point3d& ptP, const Vector3d& vtAppr, const Vector3d& vtTool, @@ -123,9 +125,10 @@ class Milling : public Machining double GetRadiusForStartEndElevation( bool bExtra = true) const ; bool GetPointOutOfRaw( const Point3d& ptP, const Vector3d& vtTool, const Vector3d& vtCorr, double dElev, double dSafeZ) const ; bool GetPointAboveRaw( const Point3d& ptP, const Vector3d& vtTool) const ; - bool CalcAndSetCorrAuxDir( const ICurveComposite* pCompo, double dU) ; - Vector3d CalcCorrDir( const ICurveComposite* pCompo, double dU) ; + bool CalcAndSetCorrAuxDir( const ICurveComposite* pCompo, double dU, bool bInvertSide = false) ; + Vector3d CalcCorrDir( const ICurveComposite* pCompo, double dU, bool bInvertSide = false) ; bool CalcOffset( ICurveComposite* pCompo, double dSignOffs) ; + bool TrimExtendCurveToClosedStm( ICurveComposite* pCompo, int nCstmId, bool bInvert) ; private : double GetSpeed() const diff --git a/Operation.cpp b/Operation.cpp index df53403..ee880ef 100644 --- a/Operation.cpp +++ b/Operation.cpp @@ -133,8 +133,8 @@ Operation::Init( MachMgr* pMchMgr) //---------------------------------------------------------------------------- Operation::Operation( void) : m_nOwnerId( GDB_ID_NULL), m_pGeomDB( nullptr), m_pMchMgr( nullptr), m_nPhase( 1), - m_nPathId( GDB_ID_NULL), m_bCurr( false), m_ptCurr(), - m_vtTool(), m_vtCorr(), m_vtAux(), m_dFeed( 0), m_nFlag( 0), m_nFlag2( 0), m_nIndex( 0) + m_nPathId( GDB_ID_NULL), m_bCurr( false), m_ptCurr(), m_vtTool(), m_vtCorr(), m_vtAux(), + m_dFeed( 0), m_nFlag( 0), m_bFlagModal( true), m_nFlag2( 0), m_bFlag2Modal( true), m_nIndex( 0) { } diff --git a/Operation.h b/Operation.h index 9af8cfe..3c8a940 100644 --- a/Operation.h +++ b/Operation.h @@ -182,8 +182,8 @@ class Operation : public IUserObj bool SetAuxDir( const Vector3d& vtDir) ; bool SetCorrAuxDir( const Vector3d& vtDir) ; bool SetFeed( double dFeed) ; - bool SetFlag( int nFlag) ; - bool SetFlag2( int nFlag2) ; + bool SetFlag( int nFlag, bool bModal = true) ; + bool SetFlag2( int nFlag2, bool bModal = true) ; bool SetIndex( int nIndex) ; bool GetCurrPos( Point3d& ptCurr) const { if ( ! m_bCurr) return false ; ptCurr = m_ptCurr ; return true ; } @@ -214,8 +214,18 @@ class Operation : public IUserObj Vector3d m_vtAux ; // direzione ausiliaria corrente double m_dFeed ; // feed corrente int m_nFlag ; // flag corrente + bool m_bFlagModal ; // valore persistente del flag int m_nFlag2 ; // secondo flag corrente + bool m_bFlag2Modal ; // valore persistente del flag2 int m_nIndex ; // indice corrente + + private : + int UseFlag( void) + { if ( m_bFlagModal) return m_nFlag ; + int nTemp = m_nFlag ; m_nFlag = 0 ; m_bFlagModal = true ; return nTemp ; } + int UseFlag2( void) + { if ( m_bFlag2Modal) return m_nFlag2 ; + int nTemp = m_nFlag2 ; m_nFlag2 = 0 ; m_bFlag2Modal = true ; return nTemp ; } } ; //---------------------------------------------------------------------------- diff --git a/OperationCL.cpp b/OperationCL.cpp index 35cee28..d56f78b 100644 --- a/OperationCL.cpp +++ b/OperationCL.cpp @@ -76,17 +76,19 @@ Operation::SetFeed( double dFeed) //---------------------------------------------------------------------------- bool -Operation::SetFlag( int nFlag) +Operation::SetFlag( int nFlag, bool bModal) { m_nFlag = nFlag ; + m_bFlagModal = bModal ; return true ; } //---------------------------------------------------------------------------- bool -Operation::SetFlag2( int nFlag2) +Operation::SetFlag2( int nFlag2, bool bModal) { m_nFlag2 = nFlag2 ; + m_bFlag2Modal = bModal ; return true ; } @@ -128,8 +130,8 @@ Operation::AddRapidStart( const Point3d& ptP) pCam->SetAuxDir( m_vtAux) ; pCam->SetEndPoint( ptP) ; pCam->SetFeed( 0) ; - pCam->SetFlag( m_nFlag) ; - pCam->SetFlag2( m_nFlag2) ; + pCam->SetFlag( UseFlag()) ; + pCam->SetFlag2( UseFlag2()) ; pCam->SetIndex( m_nIndex) ; // associo questo oggetto a quello geometrico m_pGeomDB->SetUserObj( nId, Release( pCam)) ; @@ -180,8 +182,8 @@ Operation::AddRapidMove( const Point3d& ptP) pCam->SetAuxDir( m_vtAux) ; pCam->SetEndPoint( ptP) ; pCam->SetFeed( 0) ; - pCam->SetFlag( m_nFlag) ; - pCam->SetFlag2( m_nFlag2) ; + pCam->SetFlag( UseFlag()) ; + pCam->SetFlag2( UseFlag2()) ; pCam->SetIndex( m_nIndex) ; // associo questo oggetto a quello geometrico m_pGeomDB->SetUserObj( nId, Release( pCam)) ; @@ -238,8 +240,8 @@ Operation::AddLinearMove( const Point3d& ptP) pCam->SetAuxDir( m_vtAux) ; pCam->SetEndPoint( ptP) ; pCam->SetFeed( m_dFeed) ; - pCam->SetFlag( m_nFlag) ; - pCam->SetFlag2( m_nFlag2) ; + pCam->SetFlag( UseFlag()) ; + pCam->SetFlag2( UseFlag2()) ; pCam->SetIndex( m_nIndex) ; // associo questo oggetto a quello geometrico m_pGeomDB->SetUserObj( nId, Release( pCam)) ; @@ -312,8 +314,8 @@ Operation::AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, pCam->SetDeltaN( dDeltaZ) ; pCam->SetNormDir( vtMyN) ; pCam->SetFeed( m_dFeed) ; - pCam->SetFlag( m_nFlag) ; - pCam->SetFlag2( m_nFlag2) ; + pCam->SetFlag( UseFlag()) ; + pCam->SetFlag2( UseFlag2()) ; pCam->SetIndex( m_nIndex) ; // associo questo oggetto a quello geometrico m_pGeomDB->SetUserObj( nId, Release( pCam)) ; @@ -424,7 +426,9 @@ Operation::ResetMoveData( void) m_vtAux = V_NULL ; m_dFeed = 0 ; m_nFlag = 0 ; + m_bFlagModal = true ; m_nFlag2 = 0 ; + m_bFlag2Modal = true ; m_nIndex = 0 ; return true ; }