From c848b82235de494c4a12d20de08b22fb269c6c16 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Thu, 28 May 2026 22:52:57 +0200 Subject: [PATCH] EgtMachKereel : - ulteriori migliorie per correzione raggio fresa in macchina/CNC. --- Milling.cpp | 165 +++++++++++++++++++++++++++++++++++++++------------- Milling.h | 4 ++ 2 files changed, 129 insertions(+), 40 deletions(-) diff --git a/Milling.cpp b/Milling.cpp index 9f88196..21fe432 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -2457,6 +2457,10 @@ Milling::AddStandardMilling( const ICurveComposite* pCompo, const Vector3d& vtTo } // imposto versore correzione e ausiliario sul punto di partenza CalcAndSetCorrAuxDir( pCompo, i, false, true) ; + m_vtLieCorr = m_vtCorr ; + m_vtLieAux = m_vtAux ; + if ( m_bToolComp) + CalcAndSetCorrAuxDir( vtDir1) ; // se richiesto rapido quando fuori e sono giĆ  in aria if ( bRapidOnOut && bOutStart) { // affondo al punto iniziale @@ -2854,6 +2858,10 @@ Milling::AddZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool } // imposto versore correzione e ausiliario sul punto di partenza CalcAndSetCorrAuxDir( pCompo, ( bInvert ? nMaxInd - i + 1 : i), false, true) ; + m_vtLieCorr = m_vtCorr ; + m_vtLieAux = m_vtAux ; + if ( m_bToolComp) + CalcAndSetCorrAuxDir( vtDir1) ; // se primo step if ( k == 1) { // aggiungo approccio per frese normali e frese che non lavorano di testa con attacco opportuno oppure fuori @@ -3311,6 +3319,10 @@ Milling::AddOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool Vector3d vtStart = m_vtStartDir ; // imposto versore correzione e ausiliario sul punto di partenza CalcAndSetCorrAuxDir( pCompo, i, false, true) ; + m_vtLieCorr = m_vtCorr ; + m_vtLieAux = m_vtAux ; + if ( m_bToolComp) + CalcAndSetCorrAuxDir( vtDirs) ; // punto inizio attacco Point3d ptP1 ; Vector3d vtDir1 ; @@ -3748,6 +3760,10 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool bool bAboveStart = m_bAboveHead && GetPointAboveRaw( ptP1, vtTool) ; // imposto versore correzione e ausiliario sul punto di partenza CalcAndSetCorrAuxDir( pCompo, i) ; + m_vtLieCorr = m_vtCorr ; + m_vtLieAux = m_vtAux ; + if ( m_bToolComp) + CalcAndSetCorrAuxDir( vtDir1) ; // aggiungo approccio per frese normali if ( ( m_TParams.m_nType & TF_SAWBLADE) == 0) { // correggo elevazione iniziale per punto inizio attacco (se testa da sopra senza aggregato approccio mai Z-) @@ -3947,6 +3963,10 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool bool bAboveStart = m_bAboveHead && GetPointAboveRaw( ptP1, vtTool) ; // imposto versore correzione e ausiliario sul punto di partenza CalcAndSetCorrAuxDir( pCompo, ( bInvert ? nMaxInd - i + 1 : i)) ; + m_vtLieCorr = m_vtCorr ; + m_vtLieAux = m_vtAux ; + if ( m_bToolComp) + CalcAndSetCorrAuxDir( vtDir1) ; // aggiungo approccio per frese normali if ( ( m_TParams.m_nType & TF_SAWBLADE) == 0) { // correggo elevazione iniziale per punto inizio attacco (se testa da sopra senza aggregato approccio mai Z-) @@ -4969,7 +4989,7 @@ Milling::CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, const vtPerp.Rotate( vtRot, 0, ( bCcwRot ? 1 : - 1)) ; ptP1 = ptStart + vtPerp * GetToolCompPerpLen() ; vtDir1 = ptP1 - ptStart ; - return true ; + return vtDir1.Normalize() ; } } // Calcolo punto iniziale @@ -5030,21 +5050,21 @@ Milling::CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, const if ( ! bInvert) { double dLen, dU ; if ( ! pCompo->GetLength( dLen) || ! pCompo->GetParamAtLength( dLen - m_dAddedOverlap - dTang, dU) || - ! pCompo->GetPointD1D2( dU, ICurve::FROM_MINUS, ptP1)) { - if ( ! pCompo->GetStartPoint( ptP1)) + ! pCompo->GetPointD1D2( dU, ICurve::FROM_MINUS, ptP1, &vtDir1)) { + if ( ! pCompo->GetStartPoint( ptP1) || ! pCompo->GetStartDir( vtDir1)) return false ; } + vtDir1 = -vtDir1 ; } else { double dU ; if ( ! pCompo->GetParamAtLength( m_dAddedOverlap + dTang, dU) || - ! pCompo->GetPointD1D2( dU, ICurve::FROM_MINUS, ptP1)) { - if ( ! pCompo->GetEndPoint( ptP1)) + ! pCompo->GetPointD1D2( dU, ICurve::FROM_MINUS, ptP1, &vtDir1)) { + if ( ! pCompo->GetEndPoint( ptP1) || ! pCompo->GetEndDir( vtDir1)) return false ; } } ptP1 += vtTool * ( vtTool * ( ptStart - ptP1)) + vtTool * dElev ; - vtDir1 = ptP1 - ptStart ; if ( ! vtDir1.Normalize()) return false ; // eventuale movimento ortogonale (estensione di inserimento compensazione raggio utensile) @@ -5073,7 +5093,7 @@ Milling::CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, const vtCen.Rotate( vtTool, 0, ( bAtLeft ? 1 : - 1)) ; // estensione per componente perpendicolare ptP1 = ptStart + vtCen * m_Params.m_dLiCompLen ; - vtDir1 = -vtStart ; + vtDir1 = vtCen ; } return true ; default : @@ -5151,6 +5171,8 @@ Milling::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& else { if ( AddLinearMove( ptMid, bSplitArcs, GetCorrType( TOOL_CORR_IN, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) == GDB_ID_NULL) return false ; + SetCorrDir( m_vtLieCorr) ; + SetAuxDir( m_vtLieAux) ; } } if ( ! m_bToolComp) @@ -5189,6 +5211,8 @@ Milling::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& else { if ( AddLinearMove( ptMid, bSplitArcs, GetCorrType( TOOL_CORR_IN, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) == GDB_ID_NULL) return false ; + SetCorrDir( m_vtLieCorr) ; + SetAuxDir( m_vtLieAux) ; } } PtrOwner pCrv( GetArc2PVN( ptStart, ptMid, - vtStart, vtTool)) ; @@ -5197,8 +5221,10 @@ Milling::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& pCrv->Invert() ; if ( ! m_bToolComp) return ( AddCurveMove( pCrv, bSplitArcs, MCH_CL_LEADIN) != GDB_ID_NULL) ; - else - return ( AddCurveMove( pCrv, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; + else { + int nId = AddCurveMove( pCrv, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) ; + return AdjustAllCorrAuxDirToSide( nId, bCcwRot) ; + } } case MILL_LI_GLIDE : { @@ -5256,13 +5282,17 @@ Milling::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& else { if ( AddLinearMove( ptMid, bSplitArcs, GetCorrType( TOOL_CORR_IN, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) == GDB_ID_NULL) return false ; + SetCorrDir( m_vtLieCorr) ; + SetAuxDir( m_vtLieAux) ; } } // emetto (con eventuale spezzatura) if ( ! m_bToolComp) return ( AddCurveMove( pCrv, bSplitArcs, MCH_CL_LEADIN) != GDB_ID_NULL) ; - else - return ( AddCurveMove( pCrv, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; + else { + int nId = AddCurveMove( pCrv, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) ; + return AdjustAllCorrAuxDirToSide( nId, bCcwRot) ; + } } case MILL_LI_ZIGZAG : { @@ -5353,7 +5383,10 @@ Milling::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& Point3d ptCorrS = ptCorrE - m_Params.m_dLiCompLen * vtCorrDir ; if ( AddLinearMove( ptCorrE, bSplitArcs, GetCorrType( TOOL_CORR_IN, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) == GDB_ID_NULL) return false ; - return ( AddCurveMove( pArc, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; + SetCorrDir( m_vtLieCorr) ; + SetAuxDir( m_vtLieAux) ; + int nId = AddCurveMove( pArc, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) ; + return AdjustAllCorrAuxDirToSide( nId, bCcwRot) ; } } default : @@ -5556,37 +5589,38 @@ Milling::AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d dElev = min( m_Params.m_dLiElev, dEndElev + GetLeadInOutToler()) ; dCompLen = m_Params.m_dLiCompLen ; } + // senso di rotazione da dir tg a dir esterna + bool bCcwRot = (( ! bInvert && m_Params.m_nWorkSide == MILL_WS_LEFT) || + ( bInvert && m_Params.m_nWorkSide != MILL_WS_LEFT)) ; // verifico in caso di tool compensation se richiesta uscita con 1/4 di elica if ( m_bToolComp && GetLeadInType() == MILL_LI_HELIX && GetLeadOutType() == MILL_LO_AS_LI) { - bool bAtLeft = ( bInvert != ( m_Params.m_nWorkSide != MILL_WS_RIGHT)) ; // vettore dal punto al centro dell'elica - Vector3d vtCen = vtEnd ; - vtCen.Rotate( vtTool, 0, ( bAtLeft ? 1 : -1)) ; + Vector3d vtCen = OrthoCompo( vtEnd, vtTool) ; + vtCen.Rotate( vtTool, 0, ( bCcwRot ? 1 : -1)) ; // dati dell'elica double dRad = 0.5 * min( m_Params.m_dLiTang, m_TParams.m_dDiam) ; Point3d ptCen = ptEnd + vtCen * dRad ; double dDeltaN = ( ptEnd - ptP1) * vtTool ; - double dAngCen = ( bAtLeft ? ANG_RIGHT : - ANG_RIGHT) ; + double dAngCen = ( bCcwRot ? ANG_RIGHT : - ANG_RIGHT) ; // creo l'elica PtrOwner pArc( CreateCurveArc()) ; if ( IsNull( pArc) || ! pArc->Set( ptCen, vtTool, dRad, - vtCen, dAngCen, 0.)) return false ; // emetto l'elica (con eventuale spezzatura) + Vector3d vtCorr = vtCen ; + vtCorr.Rotate( vtTool, 0, ( bCcwRot ? 1 : -1)) ; + CalcAndSetCorrAuxDir( vtCorr) ; if ( AddCurveMove( pArc, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) == GDB_ID_NULL) return false ; // emetto il tratto perpendicolare Point3d ptCorrS ; pArc->GetEndPoint( ptCorrS) ; - Vector3d vtCorrDir = ptCen - ptCorrS ; vtCorrDir.Normalize() ; - Point3d ptCorrE = ptCorrS + m_Params.m_dLiCompLen * vtCorrDir ; + Point3d ptCorrE = ptCorrS + m_Params.m_dLiCompLen * vtCorr ; if ( AddLinearMove( ptCorrE, bSplitArcs, GetCorrType( TOOL_CORR_OUT, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) == GDB_ID_NULL) return false ; ptP1 = ptCorrE ; - vtDir1 = vtCorrDir ; + vtDir1 = vtCorr ; return true ; } - // senso di rotazione da dir tg a dir esterna - bool bCcwRot = (( ! bInvert && m_Params.m_nWorkSide == MILL_WS_LEFT) || - ( bInvert && m_Params.m_nWorkSide != MILL_WS_LEFT)) ; // verifico di poter fare l'uscita a inseguimento if ( nType == MILL_LO_GLIDE && ! pCompo->IsClosed() && m_dAddedOverlap < EPS_SMALL) { if ( ! m_bToolComp) @@ -5620,18 +5654,21 @@ Milling::AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d vtDir1 = ptP1 - ptEnd ; if ( ! vtDir1.Normalize()) return false ; - // inserisco movimento di uscita bool bOk = true ; - if ( ! m_bToolComp) - bOk = ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; - else { - bOk = ( AddLinearMove( ptP1, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADOUT, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; - } - // eventuale movimento ortogonale (estensione di inserimento compensazione raggio utensile) if ( dCompLen > 10 * EPS_SMALL) { vtDir1 = OrthoCompo( vtDir1, vtTool) ; bOk = bOk && vtDir1.Normalize() ; vtDir1.Rotate( vtTool, 0, ( bCcwRot ? 1 : - 1)) ; + } + // inserisco movimento di uscita + if ( ! m_bToolComp) + bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; + else { + CalcAndSetCorrAuxDir( vtDir1) ; + bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADOUT, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; + } + // eventuale movimento ortogonale (estensione di inserimento compensazione raggio utensile) + if ( dCompLen > 10 * EPS_SMALL) { ptP1 += vtDir1 * dCompLen ; if ( ! m_bToolComp) bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; @@ -5678,15 +5715,20 @@ Milling::AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d if ( ! pCrv->GetEndDir( vtDirF)) return false ; bool bOk = true ; - if ( ! m_bToolComp) - bOk = ( AddCurveMove( pCrv, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; - else - bOk = ( AddCurveMove( pCrv, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADOUT, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; - // eventuale movimento ortogonale (estensione di inserimento compensazione raggio utensile) if ( dCompLen > 10 * EPS_SMALL) { vtDir1 = OrthoCompo( vtDirF, vtTool) ; bOk = bOk && vtDir1.Normalize() ; vtDir1.Rotate( vtTool, 0, ( bCcwRot ? 1 : - 1)) ; + } + if ( ! m_bToolComp) + bOk = bOk && ( AddCurveMove( pCrv, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; + else { + CalcAndSetCorrAuxDir( vtDir1) ; + int nId = ( bOk ? AddCurveMove( pCrv, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADOUT, &TOOL_CORR_COLOR) : GDB_ID_NULL) ; + bOk = bOk && AdjustAllCorrAuxDirToSide( nId, bCcwRot) ; + } + // eventuale movimento ortogonale (estensione di inserimento compensazione raggio utensile) + if ( dCompLen > 10 * EPS_SMALL) { ptP1 += vtDir1 * dCompLen ; if ( ! m_bToolComp) bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; @@ -5744,17 +5786,22 @@ Milling::AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d // assegno punto e direzione finale dell'uscita pCrv->GetEndPoint( ptP1) ; pCrv->GetEndDir( vtDir1) ; - // emetto bool bOk = true ; - if ( ! m_bToolComp) - bOk = ( AddCurveMove( pCrv, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; - else - bOk = ( AddCurveMove( pCrv, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADOUT, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; - // eventuale movimento ortogonale (estensione di inserimento compensazione raggio utensile) if ( dCompLen > 10 * EPS_SMALL) { vtDir1 = OrthoCompo( vtDir1, vtTool) ; bOk = bOk && vtDir1.Normalize() ; vtDir1.Rotate( vtTool, 0, ( bCcwRot ? 1 : - 1)) ; + } + // emetto + if ( ! m_bToolComp) + bOk = bOk && ( AddCurveMove( pCrv, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; + else { + CalcAndSetCorrAuxDir( vtDir1) ; + int nId = ( bOk ? AddCurveMove( pCrv, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADOUT, &TOOL_CORR_COLOR) : GDB_ID_NULL) ; + bOk = bOk && AdjustAllCorrAuxDirToSide( nId, bCcwRot) ; + } + // eventuale movimento ortogonale (estensione di inserimento compensazione raggio utensile) + if ( dCompLen > 10 * EPS_SMALL) { ptP1 += vtDir1 * dCompLen ; if ( ! m_bToolComp) bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; @@ -7111,6 +7158,14 @@ Milling::CalcAndSetCorrAuxDir( const ICurveComposite* pCompo, double dU, bool bI // se utensile non centrato, calcolo del versore correzione if ( m_Params.m_nWorkSide != MILL_WS_CENTER) vtCorr = CalcCorrDir( pCompo, dU, bInvertSide, bSawSpecial) ; + // impostazione + return CalcAndSetCorrAuxDir( vtCorr) ; +} + +//---------------------------------------------------------------------------- +bool +Milling::CalcAndSetCorrAuxDir( const Vector3d& vtCorr) +{ // imposto versore correzione SetCorrDir( vtCorr) ; // se rinvio da sotto in uso, non devo impostare direzione aux da correzione @@ -7209,6 +7264,36 @@ Milling::CalcCorrDir( const ICurveComposite* pCompo, double dU, bool bInvertSide } } +//---------------------------------------------------------------------------- +bool +Milling::AdjustAllCorrAuxDirToSide( int nId, bool bCcwRot) +{ + if ( nId == GDB_ID_NULL) + return false ; + while ( nId != GDB_ID_NULL) { + const ICurve* pCrv = GetCurve( m_pGeomDB->GetGeoObj( nId)) ; + if ( pCrv == nullptr) + return false ; + Vector3d vtEnd ; + if ( ! pCrv->GetEndDir( vtEnd)) + return false ; + Vector3d vtCorr = OrthoCompo( vtEnd, m_vtTool) ; + if ( ! vtCorr.Normalize()) + return false ; + vtCorr.Rotate( m_vtTool, 0, ( bCcwRot ? 1 : -1)) ; + CalcAndSetCorrAuxDir( vtCorr) ; + CamData* pCam = GetCamData( m_pGeomDB->GetUserObj( nId)) ; + if ( pCam == nullptr) + return false ; + pCam->SetCorrDir( m_vtCorr) ; + pCam->SetAuxDir( m_vtAux) ; + nId = m_pGeomDB->GetNext( nId) ; + } + + + return true ; +} + //---------------------------------------------------------------------------- bool Milling::CalcOffset( ICurveComposite* pCompo, double dSignOffs, double dExtraOffs) const diff --git a/Milling.h b/Milling.h index 45ef360..2b87da2 100644 --- a/Milling.h +++ b/Milling.h @@ -137,6 +137,8 @@ class Milling : public Machining bool GetPointBelowRaw( const Point3d& ptP, const Vector3d& vtTool) const ; bool CalcAndSetCorrAuxDir( const ICurveComposite* pCompo, double dU, bool bInvertSide = false, bool bSawSpecial = false) ; Vector3d CalcCorrDir( const ICurveComposite* pCompo, double dU, bool bInvertSide = false, bool bSawSpecial = false) const ; + bool CalcAndSetCorrAuxDir( const Vector3d& vtCorr) ; + bool AdjustAllCorrAuxDirToSide( int nId, bool bCcwRot) ; bool CalcOffset( ICurveComposite* pCompo, double dSignOffs, double dExtraOffs = 0) const ; bool TrimExtendCurveToClosedStm( ICurveComposite* pCompo, int nCstmId, bool bInvert) ; int GetCorrType( int nToolCompEntity, bool bInvert) const ; @@ -201,6 +203,8 @@ class Milling : public Machining double m_dCurrOscillLen ; // lunghezza corrente lungo il percorso per l'oscillazione double m_dCurrTabsLen ; // lunghezza corrente lungo il percorso per tabs bool m_bToolComp ; // correzione raggio utensile abilitata dai dati + Vector3d m_vtLieCorr ; // versore correzione da applicare a fine attacco + Vector3d m_vtLieAux ; // versore ausiliario da applicare a fine attacco bool m_bStartOutRaw ; // flag forzatura inizio fuori dal grezzo bool m_bEndOutRaw ; // flag forzatura fine fuori dal grezzo Vector3d m_vtStartDir ; // direzione iniziale del percorso in elaborazione