diff --git a/PocketingNT.cpp b/PocketingNT.cpp index d6ffb68..ac6c395 100644 --- a/PocketingNT.cpp +++ b/PocketingNT.cpp @@ -122,8 +122,10 @@ const string UN_ADJUSTFEED = "AdjustFeed" ; #define DEBUG_SAFETY_LINK 0 // Debug raccordi tra percorsi di lavorazioni differenti #define DEBUG_FEED 0 // Debug per Feed #define DEBUG_START_POINT 0 // Debug per scelta del punto iniziale -#if DEBUG_OPEN_EDGE_EXTENSION || DEBUG_OPEN_EDGE_IN_RAW || DEBUG_SFR_STEPS || DEBUG_SFR_RAW || DEBUG_GLIDE || DEBUG_SAFETY_LINK || DEBUG_FEED || DEBUG_START_POINT +#define DEBUG 0 // Debug +#if DEBUG_OPEN_EDGE_EXTENSION || DEBUG_OPEN_EDGE_IN_RAW || DEBUG_SFR_STEPS || DEBUG_SFR_RAW || DEBUG_GLIDE || DEBUG_SAFETY_LINK || DEBUG_FEED || DEBUG_START_POINT || DEBUG #include "EgtDev/Include/EGkGeoPoint3d.h" + #include "EgtDev/Include/EGkGeoVector3d.h" #include "EgtDev/Include/EGkFrame3d.h" #endif @@ -1887,13 +1889,12 @@ PocketingNT::GetSfrRawProjection( const ISurfTriMesh* pStmRaw, const ISurfFlatRe Point3d PocketingNT::GetStartPointsFromSteps( const STEPINFOPOVECTOR& vStepInfo, int nCrvType) { - // se non ho step, allora errore + // se non ho step, allora non ho un punto di riferimento if ( vStepInfo.empty()) return P_INVALID ; // sull'ultimo Step ( quindi sulla geometria più simile a quella originaria) cerco il tratto aperto più lungo // ( inteso come media tra gli aperti sui Chunks) - // recupero la prima regione valida a partire dalla più profonda auto it = vStepInfo.rbegin() ; for ( ; it != vStepInfo.rend() ; ++ it) { @@ -1923,22 +1924,38 @@ PocketingNT::GetStartPointsFromSteps( const STEPINFOPOVECTOR& vStepInfo, int nCr // recupero i tratti con proprietà uniformi ICRVCOMPOPOVECTOR vpCrvs ; GetHomogeneousParts( pCrvLoop, vpCrvs) ; - // scorro i tratti con le proprietà richieste e cerco quello più lungo double dLenRef = 0. ; int nIndRef = -1 ; - for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) { - if ( vpCrvs[i]->GetTempProp() == nCrvType) { - double dLen = 0. ; vpCrvs[i]->GetLength( dLen) ; + Point3d ptMid ; + // se bordo tutto aperto, allora cerco il punto medio della curva più lunga + if ( int( vpCrvs.size()) == 1 && vpCrvs[0]->GetTempProp() == TEMP_PROP_OPEN_EDGE) { + for ( int nU = 0 ; nU < vpCrvs[0]->GetCurveCount() ; ++ nU) { + double dLen = 0. ; vpCrvs[0]->GetCurve( nU)->GetLength( dLen) ; if ( dLen > dLenRef) { dLenRef = dLen ; - nIndRef = i ; + nIndRef = nU ; } } + if ( nIndRef == -1) + continue ; + vpCrvs[0]->GetCurve( nIndRef)->GetMidPoint( ptMid) ; } - if ( nIndRef == -1) - continue ; - Point3d ptMid ; - vpCrvs[nIndRef]->GetMidPoint( ptMid) ; + else { + // scorro i tratti con le proprietà richieste e cerco quello più lungo + for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) { + if ( vpCrvs[i]->GetTempProp() == nCrvType) { + double dLen = 0. ; vpCrvs[i]->GetLength( dLen) ; + if ( dLen > dLenRef) { + dLenRef = dLen ; + nIndRef = i ; + } + } + } + if ( nIndRef == -1) + continue ; + vpCrvs[nIndRef]->GetMidPoint( ptMid) ; + } + #if DEBUG_START_POINT PtrOwner myPtMid( CreateGeoPoint3d()) ; myPtMid->Set( ptMid) ; @@ -1961,12 +1978,15 @@ PocketingNT::GetStartPointsFromSteps( const STEPINFOPOVECTOR& vStepInfo, int nCr Point3d ptStart = Point3d( dX / int( vPnts.size()), dY / int( vPnts.size()), dZ / int( vPnts.size())) ; + // proietto il punto sul primo step + ptStart.Translate( ( - ( *it).dDepth + vStepInfo.front().dDepth) * ( *it).pSfrPock->GetNormVersor()) ; #if DEBUG_START_POINT PtrOwner myPtStart( CreateGeoPoint3d()) ; myPtStart->Set( ptStart) ; int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, myPtStart->Clone()) ; m_pGeomDB->SetMaterial( nId, YELLOW) ; #endif + return ptStart ; } @@ -3359,7 +3379,7 @@ PocketingNT::GeneratePocketingPv( int nPathId, const ICurveComposite* pCompo) //---------------------------------------------------------------------------- bool -PocketingNT::CalcLeadInOutGlide( PathInfoPO& PathInfo, const StepInfoPO& StepInfo, const ICurveComposite* pCrvPath, +PocketingNT::CalcRetCurve( PathInfoPO& PathInfo, const StepInfoPO& StepInfo, const ICurveComposite* pCrvPath, const Vector3d& vtTool, bool bHolePocketing, bool bInVsOut, ICurveComposite* pCrvGlide) { /* Funzione per il calcolo della curva a sciovolo (piana) in entrata o in uscita @@ -3403,7 +3423,7 @@ PocketingNT::CalcLeadInOutGlide( PathInfoPO& PathInfo, const StepInfoPO& StepInf // calcolo la curva di ritorno PtrOwner pCrvRet( ConvertCurveToComposite( pCrvGlideTmp->CopyParamRange( dParS, dU))) ; if ( ! IsNull( pCrvRet) && pCrvRet->IsValid()) { - if ( ! PathInfo.pCrvRet.Set( Release( pCrvRet))) + if ( ! PathInfo.pCrvRet.Set( Release( pCrvRet))) return false ; } } @@ -3579,10 +3599,9 @@ PocketingNT::CalcLeadInOutGlide( PathInfoPO& PathInfo, const StepInfoPO& StepInf return true ; } - //---------------------------------------------------------------------------- bool -PocketingNT::CalcPaths( STEPINFOPOVECTOR& vStepInfo, bool& bHolePocketing) +PocketingNT::CalcPaths( STEPINFOPOVECTOR& vStepInfo) { /* funzione per calcolo dei percorsi di Pockets e delle loro proprietà @@ -3596,7 +3615,6 @@ PocketingNT::CalcPaths( STEPINFOPOVECTOR& vStepInfo, bool& bHolePocketing) if ( ! ptStartRef.IsValid()) ptStartRef = GetStartPointsFromSteps( vStepInfo, TEMP_PROP_CLOSE_EDGE) ; } - // controllo parametri per casi ottimizzati double dMaxOptSize = m_Params.m_dSideStep ; GetValInNotes( m_Params.m_sUserNotes, UN_MAXOPTSIZE, dMaxOptSize) ; @@ -3672,7 +3690,7 @@ PocketingNT::CalcPaths( STEPINFOPOVECTOR& vStepInfo, bool& bHolePocketing) } // controllo se la svuotatura è riferita ad un foro chiuso - bHolePocketing = true ; + bool bHolePocketing = true ; for ( int i = 0 ; i < int( vStepInfo.size()) && bHolePocketing ; ++ i) { bHolePocketing = ( int( vStepInfo[i].vPaths.size()) == 1 && vStepInfo[i].vPaths[0].bOptCirle && @@ -3680,14 +3698,14 @@ PocketingNT::CalcPaths( STEPINFOPOVECTOR& vStepInfo, bool& bHolePocketing) ! vStepInfo[i].vPaths[0].bOutEnd) ; } - // calcolo di LeadIn/LeadOut a guida e curva di ritorno per svuotature di fori chiusi + // calcolo la curva di ritorno ( se necessaria) for ( int i = 0 ; i < int( vStepInfo.size()) ; ++ i) { for ( int j = 0 ; j < int( vStepInfo[i].vPaths.size()) ; ++ j) { if ( GetLeadInType() == POCKET_LI_GLIDE || bHolePocketing) { PtrOwner pCrvGlideIn( CreateCurveComposite()) ; if ( IsNull( pCrvGlideIn) || - ! CalcLeadInOutGlide( vStepInfo[i].vPaths[j], vStepInfo[i], vStepInfo[i].vPaths[j].pCrvPath, - vStepInfo[i].pSfrPock->GetNormVersor(), bHolePocketing, true, pCrvGlideIn)) { + ! CalcRetCurve( vStepInfo[i].vPaths[j], vStepInfo[i], vStepInfo[i].vPaths[j].pCrvPath, + vStepInfo[i].pSfrPock->GetNormVersor(), bHolePocketing, true, pCrvGlideIn)) { m_pMchMgr->SetLastError( 2415, "Error in PocketingNT : LeadIn not computable") ; return false ; } @@ -3699,8 +3717,8 @@ PocketingNT::CalcPaths( STEPINFOPOVECTOR& vStepInfo, bool& bHolePocketing) if ( GetLeadOutType() == POCKET_LO_GLIDE || bHolePocketing) { PtrOwner pCrvGlideOut( CreateCurveComposite()) ; if ( IsNull( pCrvGlideOut) || - ! CalcLeadInOutGlide( vStepInfo[i].vPaths[j], vStepInfo[i], vStepInfo[i].vPaths[j].pCrvPath, - vStepInfo[i].pSfrPock->GetNormVersor(), bHolePocketing, false, pCrvGlideOut)) { + ! CalcRetCurve( vStepInfo[i].vPaths[j], vStepInfo[i], vStepInfo[i].vPaths[j].pCrvPath, + vStepInfo[i].pSfrPock->GetNormVersor(), bHolePocketing, false, pCrvGlideOut)) { m_pMchMgr->SetLastError( 2416, "Error in PocketingNT : LeadOut not computable") ; return false ; } @@ -3766,8 +3784,7 @@ PocketingNT::AddPocket( STEPINFOPOVECTOR& vStepInfo, const Vector3d& vtTool, dou return true ; // calcolo i percorsi di svuotatura per ogni Step/SubStep - bool bHolePocketing = false ; - if ( ! CalcPaths( vStepInfo, bHolePocketing)) + if ( ! CalcPaths( vStepInfo)) return false ; #if DEBUG_FEED int nGrp = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ; @@ -3928,10 +3945,12 @@ PocketingNT::AddPocket( STEPINFOPOVECTOR& vStepInfo, const Vector3d& vtTool, dou PtrOwner pCrvLink( CreateCurveComposite()) ; if ( IsNull( pCrvLink)) return false ; - if ( bHolePocketing && currPath.pCrvRet != nullptr && currPath.pCrvRet->IsValid()) { + // se ho una curva di ritorno, allora uso quella + if ( currPath.pCrvRet != nullptr && currPath.pCrvRet->IsValid()) { pCrvLink->CopyFrom( currPath.pCrvRet) ; bSafeLimit = true ; } + // altrimenti cerco raccordo smussato else { if ( ! bForceLinear) { if ( ! CheckSafetyLink( ptEnd, vtEnd, ptDest, vtDest, currStep.pSfrLimit, vtTool, diff --git a/PocketingNT.h b/PocketingNT.h index a0973b3..83fab07 100644 --- a/PocketingNT.h +++ b/PocketingNT.h @@ -127,8 +127,8 @@ class PocketingNT : public Machining bool VerifyPathFromBottom( const ICurveComposite* pCompo, const Vector3d& vtTool) ; bool GeneratePocketingPv( int nPathId, const ICurveComposite* pCompo) ; bool CalcLimitRegion( const ISurfFlatRegion* pSfrPock, const ISurfFlatRegion* pSfrRaw, ISurfFlatRegion* pSfrLimit) ; - bool CalcPaths( STEPINFOPOVECTOR& vStepInfo, bool& bHolePocketing) ; - bool CalcLeadInOutGlide( PathInfoPO& PathInfo, const StepInfoPO& StepInfo, const ICurveComposite* pCrvPath, + bool CalcPaths( STEPINFOPOVECTOR& vStepInfo) ; + bool CalcRetCurve( PathInfoPO& PathInfo, const StepInfoPO& StepInfo, const ICurveComposite* pCrvPath, const Vector3d& vtTool, bool bHolePocketing, bool bInVsOut, ICurveComposite* pCrvGlide) ; bool AddPocket( STEPINFOPOVECTOR& vStepInfo, const Vector3d& vtTool, double dElev, double dStep, bool bSplitArcs) ; double GetRightFeed( const Vector3d& vtMove, const Vector3d& vtTool) ; @@ -169,7 +169,7 @@ class PocketingNT : public Machining bool VerifyLeadInOutGlide( const ISurfFlatRegion* pSfr, ICurveComposite* pCrvGlide) ; bool CalcDistanceFromRawSurface( int nPhase, const Point3d& ptP, const Vector3d& vtDir, double& dDist, Vector3d& vtNorm) ; // debug - void DebugDrawSfr( const ISurfFlatRegion* pSfr, bool bUniform, int nlayer = GDB_ID_NULL) ; + void DebugDrawSfr( const ISurfFlatRegion* pSfr, bool bUniform, int nlayer = GDB_ID_ROOT) ; void DebugDrawLoop( const ICurveComposite* pCrvCompo, int nLayer, bool bUniform) ; void DebugDrawBox( const BBox3d& BBox, const Frame3d& FrBox, int nlayer) ; void DebugDrawOpenEdgesInRaw( const ICRVCOMPOPOVECTOR& vpCrvsm, int nlayer) ;