diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 11a1c7e..6be67a2 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/Milling.cpp b/Milling.cpp index c65636d..7731182 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -50,6 +50,7 @@ const double OSC_MIN_LEN = 0.1 ; const double LIM_DOWN_APPRZ = -0.5 ; const double DELTA_ELEV_RAD = 4.0 ; const double LIM_SIN_DIFF_DIR = 0.175 ; +const Color TOOL_CORR_COLOR = Color( 0, 255, 255) ; //------------------------------ Errors -------------------------------------- // 2301 = "Error in Milling : UpdateToolData failed" @@ -839,9 +840,30 @@ Milling::Apply( bool bRecalc, bool bPostApply) // recupero flag correzione raggio fresa int nToolComp = TOOL_COMP_PROGRAM ; - bool m_bToolComp = ( GetValInNotes( m_Params.m_sUserNotes, UN_TOOL_COMPENSATION, nToolComp) && - ( nToolComp == TOOL_COMP_RADIUS || nToolComp == TOOL_COMP_LEN_AND_RAD) && - m_Params.m_nWorkSide != MILL_WS_CENTER) ; + m_bToolComp = ( GetValInNotes( m_Params.m_sUserNotes, UN_TOOL_COMPENSATION, nToolComp) && + ( nToolComp == TOOL_COMP_RADIUS || nToolComp == TOOL_COMP_LEN_AND_RAD) && + m_Params.m_nWorkSide != MILL_WS_CENTER) ; + // compensazione utensile non applicata nel caso di famiglie di lame + if ( m_bToolComp && ( m_TParams.m_nType & TF_SAWBLADE) != 0) + m_bToolComp = false ; + // compensazione utensile non applicata nel caso di attacco a None, ZigZag e Tang+Perp + if ( m_bToolComp) { + int nLeadInType = GetLeadInType() ; + if ( nLeadInType == MILL_LI_NONE || nLeadInType == MILL_LI_ZIGZAG || nLeadInType == MILL_LI_TG_PERP) + m_bToolComp = false ; + } + // compensazione utensile non applicata nel caso di Step Type Spiral + if ( m_bToolComp && m_Params.m_nStepType == MILL_ST_SPIRAL) + m_bToolComp = false ; + // se compensazione utensile, forzo la componente perpendicolare di LeadIn e LeadOut + if ( m_bToolComp) { + m_Params.m_dLiCompLen = GetToolCompPerpLen() ; + m_Params.m_dLoCompLen = GetToolCompPerpLen() ; + // l'uscita deve essere tra quelle ammesse + int nLeadOutType = GetLeadOutType() ; + if ( nLeadOutType == MILL_LO_NONE || nLeadOutType == MILL_LO_PERP_TG) + m_Params.m_nLeadOutType = MILL_LO_AS_LI ; + } if ( m_bToolComp && m_TParams.m_nCorr == 0) { m_bToolComp = false ; m_pMchMgr->SetWarning( 2365, "Warning in Milling : No compensation in tool, so no compensation in machine") ; @@ -2570,8 +2592,14 @@ Milling::AddStandardMilling( const ICurveComposite* pCompo, const Vector3d& vtTo } else { Point3d ptP3 = pLine->GetEnd() ; - if ( AddLinearMove( ptP3, bSplitArcs) == GDB_ID_NULL) - return false ; + if ( ! m_bToolComp) { + if ( AddLinearMove( ptP3, bSplitArcs) == GDB_ID_NULL) + return false ; + } + else { + if ( AddLinearMove( ptP3, bSplitArcs, GetCorrType( TOOL_CORR_PATH, false), nullptr, &TOOL_CORR_COLOR) == GDB_ID_NULL) + return false ; + } } } else if ( pCurve->GetType() == CRV_ARC) { @@ -2590,8 +2618,14 @@ Milling::AddStandardMilling( const ICurveComposite* pCompo, const Vector3d& vtTo double dAngCen = pArc->GetAngCenter() ; Vector3d vtN = pArc->GetNormVersor() ; Point3d ptP3 ; pArc->GetEndPoint( ptP3) ; - if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) - return false ; + if ( ! m_bToolComp) { + if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) + return false ; + } + else { + if ( AddArcMove( ptP3, ptCen, dAngCen, vtN, GetCorrType( TOOL_CORR_PATH, false), nullptr, &TOOL_CORR_COLOR) == GDB_ID_NULL) + return false ; + } } } // se ultima entità, uscita e retrazione @@ -2934,10 +2968,17 @@ Milling::AddZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool if ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_SAFEIN) == GDB_ID_NULL) return false ; } - // se attacco a zigzag o a spirale, non affondo + // se attacco a zigzag o a spirale o a guida, non affondo else if ( IsLeadInHelixOrZigzagOrGlide()) { - ptP1 += vtTool * ( dStElev + GetLeadInOutToler()) ; - dStElev = - GetLeadInOutToler() ; + if ( ! m_bToolComp || ( m_bToolComp && ! ( GetLeadInType() == MILL_LI_GLIDE && ! pCompo->IsClosed()))) { + ptP1 += vtTool * ( dStElev + GetLeadInOutToler()) ; + dStElev = - GetLeadInOutToler() ; + } + if ( m_bToolComp) { + Point3d ptCurr ; GetCurrPos( ptCurr) ; + if ( ! AreSamePointApprox( ptCurr, ptP1)) + AddLinearMove( ptP1, bSplitArcs, MCH_CL_SAFEIN) ; + } } // altrimenti, affondo in feed opportuna else { @@ -2970,8 +3011,20 @@ Milling::AddZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool } else { Point3d ptP3 = pLine->GetEnd() ; - if ( AddLinearMove( ptP3, bSplitArcs) == GDB_ID_NULL) - return false ; + if ( ! m_bToolComp) { + if ( AddLinearMove( ptP3, bSplitArcs) == GDB_ID_NULL) + return false ; + } + else { + int nId = AddLinearMove( ptP3, bSplitArcs) ; + if ( nId == GDB_ID_NULL) + return false ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nId)) ; + if ( pCamData == nullptr) + return false ; + pCamData->SetCorrType( GetCorrType( TOOL_CORR_PATH, bInvert)) ; + m_pGeomDB->SetMaterial( nId, AQUA) ; + } } } else if ( pCurve->GetType() == CRV_ARC) { @@ -2990,8 +3043,20 @@ Milling::AddZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool double dAngCen = pArc->GetAngCenter() ; Vector3d vtN = pArc->GetNormVersor() ; Point3d ptP3 ; pArc->GetEndPoint( ptP3) ; - if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) - return false ; + if ( ! m_bToolComp) { + if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) + return false ; + } + else { + int nId = AddArcMove( ptP3, ptCen, dAngCen, vtN) ; + if ( nId == GDB_ID_NULL) + return false ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nId)) ; + if ( pCamData == nullptr) + return false ; + pCamData->SetCorrType( GetCorrType( TOOL_CORR_PATH, bInvert)) ; + m_pGeomDB->SetMaterial( nId, AQUA) ; + } } } // se ultima entità, uscita e se ultimo step retrazione @@ -3007,9 +3072,11 @@ Milling::AddZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool // se non c'è attacco a zigzag o a spirale oppure ultimo step, aggiungo uscita Point3d ptP1 = ptEnd ; Vector3d vtDir1 ; - if ( ! IsLeadInHelixOrZigzag() || k == nStep) { + if ( ! IsLeadInHelixOrZigzag() || k == nStep || m_bToolComp) { if ( k != nStep && GetLeadInType() == MILL_LI_GLIDE) dEndElev = - GetLeadInOutToler() ; + if ( k != nStep) + dEndElev = 0. ; SetFeed( GetEndFeed()) ; if ( ! AddLeadOut( ptEnd, vtEnd, vtTool, dEndElev, bInvert, pCompo, bSplitArcs, ptP1, vtDir1)) { m_pMchMgr->SetLastError( 2311, "Error in Milling : LeadOut not computable") ; @@ -3244,7 +3311,6 @@ Milling::AddOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool Point3d ptStart ; pCurve->GetStartPoint( ptStart) ; Vector3d vtStart = m_vtStartDir ; - // pCurve->GetStartDir( vtStart) ; // imposto versore correzione e ausiliario sul punto di partenza CalcAndSetCorrAuxDir( pCompo, i, false, true) ; // punto inizio attacco @@ -3252,7 +3318,7 @@ Milling::AddOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool Vector3d vtDir1 ; double dCalcStElev = 0 ; // se speciale e step intermedio - if ( bSpecial && k > 1) { + if ( ! m_bToolComp && bSpecial && k > 1) { ptP1 = ptStart + dStep * vtTool ; } // altrimenti @@ -3303,19 +3369,25 @@ Milling::AddOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool dStElev = ( j - 1) * dStep ; } // approccio standard al punto iniziale - if ( k == 1 || bMidRetract) { - if ( ! AddApproach( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dStElev, dExtrAppr, bOutStart, - bAhAboveStartEnd || bUhBelowStartEnd, k == 1, bSplitArcs)) { - m_pMchMgr->SetLastError( 2309, "Error in Milling : Approach not computable") ; - return false ; + if ( ! ( m_bToolComp && bSpecial && k > 1)) { + if ( k == 1 || bMidRetract) { + if ( ! AddApproach( ptP1, vtTool, dSafeZ, dSafeAggrBottZ, dStElev, dExtrAppr, bOutStart, + bAhAboveStartEnd || bUhBelowStartEnd, k == 1, bSplitArcs)) { + m_pMchMgr->SetLastError( 2309, "Error in Milling : Approach not computable") ; + return false ; + } + } + // altrimenti approccio diretto al punto iniziale + else { + if ( ! AddDirectApproach( ptP1, bSplitArcs)) { + m_pMchMgr->SetLastError( 2309, "Error in Milling : Approach not computable") ; + return false ; + } } } - // altrimenti approccio diretto al punto iniziale else { - if ( ! AddDirectApproach( ptP1, bSplitArcs)) { - m_pMchMgr->SetLastError( 2309, "Error in Milling : Approach not computable") ; - return false ; - } + SetFeed( GetStartFeed()) ; + AddLinearMove( ptP1) ; } } // altrimenti, approccio per lame e frese che non lavorano di testa @@ -3402,6 +3474,7 @@ Milling::AddOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool } } } + // aggiungo attacco SetFeed( GetStartFeed()) ; if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtTool, dCalcStElev, false, pCompo, bSplitArcs)) { @@ -3425,8 +3498,14 @@ Milling::AddOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool } else { Point3d ptP3 = pLine->GetEnd() ; - if ( AddLinearMove( ptP3, bSplitArcs) == GDB_ID_NULL) - return false ; + if ( ! m_bToolComp) { + if ( AddLinearMove( ptP3, bSplitArcs) == GDB_ID_NULL) + return false ; + } + else { + if ( AddLinearMove( ptP3, bSplitArcs, GetCorrType( TOOL_CORR_PATH, false), nullptr, &TOOL_CORR_COLOR) == GDB_ID_NULL) + return false ; + } } } else if ( pCurve->GetType() == CRV_ARC) { @@ -3445,20 +3524,25 @@ Milling::AddOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool double dAngCen = pArc->GetAngCenter() ; Vector3d vtN = pArc->GetNormVersor() ; Point3d ptP3 ; pArc->GetEndPoint( ptP3) ; - if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) - return false ; + if ( ! m_bToolComp) { + if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL) + return false ; + } + else { + if ( AddArcMove( ptP3, ptCen, dAngCen, vtN, GetCorrType( TOOL_CORR_PATH, false), nullptr, &TOOL_CORR_COLOR) == GDB_ID_NULL) + return false ; + } } } // se ultima entità, uscita e retrazione if ( i == nMaxInd) { // se speciale e step intermedio salto uscita e retrazione - if ( bSpecial && k != nStep) + if ( bSpecial && k != nStep && ! m_bToolComp) continue ; // dati fine entità Point3d ptEnd ; pCurve->GetEndPoint( ptEnd) ; Vector3d vtEnd = m_vtEndDir ; - // pCurve->GetEndDir( vtEnd) ; // elevazione sul punto finale double dEndElev ; if ( ! GetElevation( m_nPhase, ptEnd, vtTool, GetRadiusForStartEndElevation(), vtTool, dEndElev)) @@ -3473,8 +3557,11 @@ Milling::AddOneWayMilling( const ICurveComposite* pCompo, const Vector3d& vtTool m_pMchMgr->SetLastError( 2311, "Error in Milling : LeadOut not computable") ; return false ; } + // se tool compensation e speciale, allora salto uscita e retroazione + if ( m_bToolComp && bSpecial && k != nStep) + continue ; // se step finale o intermedi con retrazione - if ( k == nStep || bMidRetract || ! bSafeDirLinkStartEnd) { + if ( ( k == nStep || bMidRetract || ! bSafeDirLinkStartEnd)) { // determino se la fine dell'uscita è fuori dal grezzo Vector3d vtRetr( vtTool.x, vtTool.y, 0) ; if ( ! vtRetr.Normalize()) @@ -4800,7 +4887,7 @@ Milling::GetLeadInType( void) const //---------------------------------------------------------------------------- bool Milling::CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, const Vector3d& vtTool, - double dStElev, bool bInvert, const ICurveComposite* pCompo, Point3d& ptP1, Vector3d& vtDir1) const + double dStElev, bool bInvert, const ICurveComposite* pCompo, Point3d& ptP1, Vector3d& vtDir1) { // Assegno tipo e parametri int nType = GetLeadInType() ; @@ -4836,8 +4923,18 @@ Milling::CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, const bool bCcwRot = (( ! bInvert && m_Params.m_nWorkSide == MILL_WS_LEFT) || ( bInvert && m_Params.m_nWorkSide != MILL_WS_LEFT)) ; // verifico di poter fare l'ingresso a inseguimento - if ( nType == MILL_LI_GLIDE && ! pCompo->IsClosed() && m_dAddedOverlap < EPS_SMALL) - nType = MILL_LI_NONE ; + if ( nType == MILL_LI_GLIDE && ! pCompo->IsClosed() && m_dAddedOverlap < EPS_SMALL) { + if ( ! m_bToolComp) + nType = MILL_LI_NONE ; + else { + Vector3d vtPerp = vtStart ; + Vector3d vtRot = OrthoCompo( vtTool, vtStart) ; + vtPerp.Rotate( vtRot, 0, ( bCcwRot ? 1 : - 1)) ; + ptP1 = ptStart + vtPerp * GetToolCompPerpLen() ; + vtDir1 = ptP1 - ptStart ; + return true ; + } + } // Calcolo punto iniziale switch ( nType) { case MILL_LI_NONE : @@ -4928,8 +5025,19 @@ Milling::CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, const vtDir1 = -vtStart ; return true ; case MILL_LI_HELIX : - ptP1 = ptStart ; - vtDir1 = -vtStart ; + if ( ! m_bToolComp) { + ptP1 = ptStart ; + vtDir1 = -vtStart ; + } + else { + bool bAtLeft = ( bInvert != ( m_Params.m_nWorkSide != MILL_WS_RIGHT)) ; + // vettore dal punto al centro elica + Vector3d vtCen = vtStart ; + vtCen.Rotate( vtTool, 0, ( bAtLeft ? 1 : - 1)) ; + // estensione per componente perpendicolare + ptP1 = ptStart + vtCen * m_Params.m_dLiCompLen ; + vtDir1 = -vtStart ; + } return true ; default : return false ; @@ -4975,8 +5083,12 @@ Milling::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& bool bCcwRot = (( ! bInvert && m_Params.m_nWorkSide == MILL_WS_LEFT) || ( bInvert && m_Params.m_nWorkSide != MILL_WS_LEFT)) ; // verifico di poter fare l'ingresso a inseguimento - if ( nType == MILL_LI_GLIDE && ! pCompo->IsClosed() && m_dAddedOverlap < EPS_SMALL) - nType = MILL_LI_NONE ; + if ( nType == MILL_LI_GLIDE && ! pCompo->IsClosed() && m_dAddedOverlap < EPS_SMALL) { + if ( ! m_bToolComp) + nType = MILL_LI_NONE ; + else + return ( AddLinearMove( ptStart, bSplitArcs, GetCorrType( TOOL_CORR_IN, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; + } // Eseguo a seconda del tipo switch ( nType) { case MILL_LI_NONE : @@ -4995,10 +5107,19 @@ Milling::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& Vector3d vtRot = OrthoCompo( vtTool, vtStart) ; vtPerp.Rotate( vtRot, 0, ( bCcwRot ? 1 : - 1)) ; Point3d ptMid = ptStart - vtStart * dTang + vtPerp * dPerp + vtTool * dElev ; - if ( AddLinearMove( ptMid, bSplitArcs, MCH_CL_LEADIN) == GDB_ID_NULL) - return false ; + if ( ! m_bToolComp) { + if ( AddLinearMove( ptMid, bSplitArcs, MCH_CL_LEADIN) == GDB_ID_NULL) + return false ; + } + else { + if ( AddLinearMove( ptMid, bSplitArcs, GetCorrType( TOOL_CORR_IN, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) == GDB_ID_NULL) + return false ; + } } - return ( AddLinearMove( ptStart, bSplitArcs, MCH_CL_LEADIN) != GDB_ID_NULL) ; + if ( ! m_bToolComp) + return ( AddLinearMove( ptStart, bSplitArcs, MCH_CL_LEADIN) != GDB_ID_NULL) ; + else + return ( AddLinearMove( ptStart, bSplitArcs, GetCorrType( TOOL_CORR_PATH, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; case MILL_LI_TG_PERP : { Vector3d vtPerp = vtStart ; @@ -5024,14 +5145,23 @@ Milling::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& Vector3d vtRot = OrthoCompo( vtTool, vtStart) ; vtPerp.Rotate( vtRot, 0, ( bCcwRot ? 1 : - 1)) ; ptMid = ptStart - vtStart * dTang + vtPerp * dPerp + vtTool * dElev ; - if ( AddLinearMove( ptMid, bSplitArcs, MCH_CL_LEADIN) == GDB_ID_NULL) - return false ; + if ( ! m_bToolComp) { + if ( AddLinearMove( ptMid, bSplitArcs, MCH_CL_LEADIN) == GDB_ID_NULL) + return false ; + } + else { + if ( AddLinearMove( ptMid, bSplitArcs, GetCorrType( TOOL_CORR_IN, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) == GDB_ID_NULL) + return false ; + } } PtrOwner pCrv( GetArc2PVN( ptStart, ptMid, - vtStart, vtTool)) ; if ( IsNull( pCrv)) return false ; pCrv->Invert() ; - return ( AddCurveMove( pCrv, bSplitArcs, MCH_CL_LEADIN) != GDB_ID_NULL) ; + 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) ; } case MILL_LI_GLIDE : { @@ -5082,11 +5212,20 @@ Milling::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& if ( dCompLen > 10 * EPS_SMALL) { Point3d ptMid ; pCrv->GetStartPoint( ptMid) ; - if ( AddLinearMove( ptMid, bSplitArcs, MCH_CL_LEADIN) == GDB_ID_NULL) - return false ; + if ( ! m_bToolComp) { + if ( AddLinearMove( ptMid, bSplitArcs, MCH_CL_LEADIN) == GDB_ID_NULL) + return false ; + } + else { + if ( AddLinearMove( ptMid, bSplitArcs, GetCorrType( TOOL_CORR_IN, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) == GDB_ID_NULL) + return false ; + } } // emetto (con eventuale spezzatura) - return ( AddCurveMove( pCrv, bSplitArcs, MCH_CL_LEADIN) != GDB_ID_NULL) ; + 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) ; } case MILL_LI_ZIGZAG : { @@ -5160,6 +5299,8 @@ Milling::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& // dati dell'elica double dRad = 0.5 * min( m_Params.m_dLiTang, m_TParams.m_dDiam) ; Point3d ptCen = ptP1 + vtCen * dRad ; + if ( m_bToolComp) + ptCen -= vtCen * GetToolCompPerpLen() ; double dDeltaN = ( ptStart - ptP1) * vtTool ; double dAngCen = ceil( - dDeltaN / ( m_Params.m_dLiElev + 10 * EPS_SMALL)) * ( bAtLeft ? ANG_FULL : - ANG_FULL) ; // creo l'elica @@ -5167,7 +5308,16 @@ Milling::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& if ( IsNull( pArc) || ! pArc->Set( ptCen, vtTool, dRad, - vtCen, dAngCen, dDeltaN)) return false ; // emetto l'elica (con eventuale spezzatura) - return ( AddCurveMove( pArc, bSplitArcs, MCH_CL_LEADIN) != GDB_ID_NULL) ; + if ( ! m_bToolComp) + return ( AddCurveMove( pArc, bSplitArcs, MCH_CL_LEADIN) != GDB_ID_NULL) ; + else { + Point3d ptCorrE ; pArc->GetStartPoint( ptCorrE) ; + Vector3d vtCorrDir = ptCorrE - ptCen ; vtCorrDir.Normalize() ; + 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) ; + } } default : return false ; @@ -5369,12 +5519,50 @@ Milling::AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d dElev = min( m_Params.m_dLiElev, dEndElev + GetLeadInOutToler()) ; dCompLen = m_Params.m_dLiCompLen ; } + // 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)) ; + // 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) ; + // 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) + 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 ; + if ( AddLinearMove( ptCorrE, bSplitArcs, GetCorrType( TOOL_CORR_OUT, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) == GDB_ID_NULL) + return false ; + ptP1 = ptCorrE ; + vtDir1 = vtCorrDir ; + 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) - nType = MILL_LO_NONE ; + if ( nType == MILL_LO_GLIDE && ! pCompo->IsClosed() && m_dAddedOverlap < EPS_SMALL) { + if ( ! m_bToolComp) + nType = MILL_LO_NONE ; + else { + Vector3d vtPerp = vtEnd ; + Vector3d vtRot = OrthoCompo( vtTool, vtEnd) ; + vtPerp.Rotate( vtRot, 0, ( bCcwRot ? 1 : - 1)) ; + ptP1 = ptEnd + vtPerp * GetToolCompPerpLen() ; + vtDir1 = ptP1 - ptEnd ; + return ( AddLinearMove( ptP1, bSplitArcs, GetCorrType( TOOL_CORR_IN, bInvert), &MCH_CL_LEADIN, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; + } + } // eseguo a seconda del tipo switch ( nType) { case MILL_LO_NONE : @@ -5396,14 +5584,22 @@ Milling::AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d if ( ! vtDir1.Normalize()) return false ; // inserisco movimento di uscita - bool bOk = ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; + 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)) ; ptP1 += vtDir1 * dCompLen ; - bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; + if ( ! m_bToolComp) + bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; + else + bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, GetCorrType( TOOL_CORR_OUT, bInvert), &MCH_CL_LEADOUT, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; } // eventuale movimento in elevazione per flottante if ( m_bTHoldFloating && dFloatElev > 10 * EPS_SMALL) { @@ -5444,14 +5640,21 @@ Milling::AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d Vector3d vtDirF ; if ( ! pCrv->GetEndDir( vtDirF)) return false ; - bool bOk = ( AddCurveMove( pCrv, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; + 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)) ; ptP1 += vtDir1 * dCompLen ; - bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; + if ( ! m_bToolComp) + bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; + else + bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, GetCorrType( TOOL_CORR_OUT, bInvert), &MCH_CL_LEADOUT, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; } // eventuale movimento in elevazione per flottante if ( m_bTHoldFloating && dFloatElev > 10 * EPS_SMALL) { @@ -5505,14 +5708,21 @@ Milling::AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d pCrv->GetEndPoint( ptP1) ; pCrv->GetEndDir( vtDir1) ; // emetto - bool bOk = ( AddCurveMove( pCrv, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; + 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)) ; ptP1 += vtDir1 * dCompLen ; - bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; + if ( ! m_bToolComp) + bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, MCH_CL_LEADOUT) != GDB_ID_NULL) ; + else + bOk = bOk && ( AddLinearMove( ptP1, bSplitArcs, GetCorrType( TOOL_CORR_OUT, bInvert), &MCH_CL_LEADOUT, &TOOL_CORR_COLOR) != GDB_ID_NULL) ; } return bOk ; } @@ -6694,8 +6904,18 @@ Milling::CalcOffset( ICurveComposite* pCompo, double dSignOffs) const // se curva piatta con estrusione non perpendicolare forzo offset avanzato bool bAdvOffs = ( bIsFlat && abs( vtExtr * plPlane.GetVersN()) < cos( 0.1 * DEGTORAD)) ; // eseguo offset semplice - if ( ! bAdvOffs && pCompo->SimpleOffset( dSignOffs, nFlag)) - return true ; + if ( ! m_bToolComp) { + if ( ! bAdvOffs && pCompo->SimpleOffset( dSignOffs, nFlag)) + return true ; + } + else { + if ( ! bAdvOffs && pCompo->SimpleOffset( dSignOffs, nFlag)) { + int nSign = ( dSignOffs > 0.) - ( dSignOffs < 0.) ; + pCompo->SimpleOffset( - nSign * GetToolCompMinRadOffset()) ; + pCompo->SimpleOffset( nSign * GetToolCompMinRadOffset()) ; + return true ; + } + } // eseguo offset avanzato if ( bIsFlat) { OffsetCurve OffsCrv ; @@ -6704,6 +6924,11 @@ Milling::CalcOffset( ICurveComposite* pCompo, double dSignOffs) const if ( pOffs != nullptr) { pCompo->Clear() ; pCompo->AddCurve( pOffs) ; + if ( m_bToolComp) { + int nSign = ( dSignOffs > 0.) - ( dSignOffs < 0.) ; + pCompo->SimpleOffset( - nSign * GetToolCompMinRadOffset()) ; + pCompo->SimpleOffset( nSign * GetToolCompMinRadOffset()) ; + } pCompo->ArcsBezierCurvesToArcsPerpExtr( LIN_TOL_MID, ANG_TOL_STD_DEG) ; return true ; } @@ -6811,3 +7036,31 @@ Milling::TrimExtendCurveToClosedStm( ICurveComposite* pCompo, int nCstmId, bool return true ; } + +//---------------------------------------------------------------------------- +int +Milling::GetCorrType( int nToolCompEntity, bool bInvert) const +{ + // verifica tipo di Entità + if ( nToolCompEntity != TOOL_CORR_PATH && nToolCompEntity != TOOL_CORR_IN && nToolCompEntity != TOOL_CORR_OUT) + return 0 ; + // se entità di Uscita, allora valore 140 + if ( nToolCompEntity == TOOL_CORR_OUT) + return 140 ; + // Se lavorazione lato destro + if ( m_Params.m_nWorkSide == MILL_WS_RIGHT) { + if ( ! bInvert) + return ( nToolCompEntity == TOOL_CORR_IN ? 141 : 41) ; + else + return ( nToolCompEntity == TOOL_CORR_IN ? 142 : 42) ; + } + // Se lavorazione lato sinistro + else if ( m_Params.m_nWorkSide == MILL_WS_LEFT) { + if ( ! bInvert) + return ( nToolCompEntity == TOOL_CORR_IN ? 142 : 42) ; + else + return ( nToolCompEntity == TOOL_CORR_IN ? 141 : 41) ; + } + // per gli altri casi + return 0 ; +} diff --git a/Milling.h b/Milling.h index 33dac0c..82627e2 100644 --- a/Milling.h +++ b/Milling.h @@ -81,6 +81,7 @@ class Milling : public Machining double m_dRampLen ; double m_dTopLen ; } ; + enum ToolCorrEntity { TOOL_CORR_PATH = 0, TOOL_CORR_IN = 1, TOOL_CORR_OUT = 2 } ; private : bool VerifyGeometry( SelData Id, int& nSubs, int& nType) ; @@ -115,7 +116,7 @@ class Milling : public Machining bool AddSawBladeSideRetract( const Point3d& ptP, const Vector3d& vtRetr, const Vector3d& vtTool, double dSafeZ, double dSawEndElev, double dEndElev, double dAppr, bool bAddExtract = false) ; bool CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, const Vector3d& vtTool, - double dStElev, bool bInvert, const ICurveComposite* pCompo, Point3d& ptP1, Vector3d& vtDir1) const ; + double dStElev, bool bInvert, const ICurveComposite* pCompo, Point3d& ptP1, Vector3d& vtDir1) ; bool AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& vtStart, const Vector3d& vtTool, double dStElev, bool bInvert, const ICurveComposite* pCompo, bool bSplitArcs) ; bool CalcLeadOutEnd( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d& vtTool, @@ -138,6 +139,7 @@ class Milling : public Machining Vector3d CalcCorrDir( const ICurveComposite* pCompo, double dU, bool bInvertSide = false, bool bSawSpecial = false) const ; bool CalcOffset( ICurveComposite* pCompo, double dSignOffs) const ; bool TrimExtendCurveToClosedStm( ICurveComposite* pCompo, int nCstmId, bool bInvert) ; + int GetCorrType( int nToolCompEntity, bool bInvert) const ; private : double GetSpeed() const @@ -171,6 +173,10 @@ class Milling : public Machining m_Params.m_dLiTang >= 0.9 * m_TParams.m_dDiam && m_Params.m_dLiElev <= 2) ; } double GetLeadInOutToler( void) const { return ( m_bTHoldFloating ? LIO_ELEV_FLOAT : LIO_ELEV_TOL) ; } + inline double GetToolCompMinRadOffset() const + { return 100. * EPS_SMALL ; } + inline double GetToolCompPerpLen() const + { return 2.0 ; } friend class LeadIOStatus ; private : diff --git a/Operation.h b/Operation.h index 74b803e..0b82380 100644 --- a/Operation.h +++ b/Operation.h @@ -325,12 +325,16 @@ class Operation : public IUserObj int AddLinearMove( const Point3d& ptP, const std::string& sName) ; int AddLinearMove( const Point3d& ptP, bool bSplit) ; int AddLinearMove( const Point3d& ptP, bool bSplit, const std::string& sName) ; + int AddLinearMove( const Point3d& ptP, bool bSplit, int nCorrType, const std::string* sName = nullptr, const Color* pColor = nullptr) ; int AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, const Vector3d& vtN) ; int AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, const Vector3d& vtN, const std::string& sName) ; + int AddArcMove ( const Point3d& ptP, const Point3d& ptCen, double dAngCen, const Vector3d& vtN, int nCorrType, + const std::string* psName = nullptr, const Color* pColor = nullptr) ; int AddCurveMove( const ICurve* pCrv) ; int AddCurveMove( const ICurve* pCrv, const std::string& sName) ; int AddCurveMove( const ICurve* pCrv, bool bSplit) ; int AddCurveMove( const ICurve* pCrv, bool bSplit, const std::string& sName) ; + int AddCurveMove( const ICurve* pCrv, bool bSplit, int nCorrType, const std::string* psName = nullptr, const Color* pColor = nullptr) ; bool ResetMoveData( void) ; protected : diff --git a/OperationCL.cpp b/OperationCL.cpp index 60760f9..ab471d4 100644 --- a/OperationCL.cpp +++ b/OperationCL.cpp @@ -348,6 +348,25 @@ Operation::AddLinearMove( const Point3d& ptP, bool bSplit, const string& sName) return nFirstId ; } +//---------------------------------------------------------------------------- +int +Operation::AddLinearMove( const Point3d& ptP, bool bSplit, int nCorrType, const string* psName, const Color* pColor) +{ + int nFirstId = AddLinearMove( ptP, bSplit) ; + int nId = nFirstId ; + while ( nId != GDB_ID_NULL) { + if ( psName != nullptr) + m_pGeomDB->SetName( nId, *psName) ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nId)) ; + if ( pCamData == nullptr || ! pCamData->SetCorrType( nCorrType)) + return GDB_ID_NULL ; + if ( pColor != nullptr) + m_pGeomDB->SetMaterial( nId, *pColor) ; + nId = m_pGeomDB->GetNext( nId) ; + } + return nFirstId ; +} + //---------------------------------------------------------------------------- int Operation::AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, const Vector3d& vtN) @@ -422,6 +441,24 @@ Operation::AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, return nId ; } +//---------------------------------------------------------------------------- +int +Operation::AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, const Vector3d& vtN, int nCorrType, + const string* psName, const Color* pColor) +{ + int nId = AddArcMove( ptP, ptCen, dAngCen, vtN) ; + if ( nId != GDB_ID_NULL) { + if ( psName != nullptr) + m_pGeomDB->SetName( nId, *psName) ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nId)) ; + if ( pCamData == nullptr || ! pCamData->SetCorrType( nCorrType)) + return GDB_ID_NULL ; + if ( pColor != nullptr) + m_pGeomDB->SetMaterial( nId, *pColor) ; + } + return nId ; +} + //---------------------------------------------------------------------------- int Operation::AddCurveMove( const ICurve* pCrv) @@ -530,6 +567,25 @@ Operation::AddCurveMove( const ICurve* pCrv, bool bSplit, const string& sName) return nFirstId ; } +//---------------------------------------------------------------------------- +int +Operation::AddCurveMove( const ICurve* pCrv, bool bSplit, int nCorrType, const string* psName, const Color* pColor) +{ + int nFirstId = AddCurveMove( pCrv, bSplit) ; + int nId = nFirstId ; + while ( nId != GDB_ID_NULL) { + if ( psName != nullptr) + m_pGeomDB->SetName( nId, *psName) ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nId)) ; + if ( pCamData == nullptr || ! pCamData->SetCorrType( nCorrType)) + return GDB_ID_NULL ; + if ( pColor != nullptr) + m_pGeomDB->SetMaterial( nId, *pColor) ; + nId = m_pGeomDB->GetNext( nId) ; + } + return nFirstId ; +} + //---------------------------------------------------------------------------- bool Operation::ResetMoveData( void)