diff --git a/Operation.cpp b/Operation.cpp index 45fb817..15797fa 100644 --- a/Operation.cpp +++ b/Operation.cpp @@ -589,7 +589,7 @@ Operation::GetSignedDistFromStmRaw( int nPhase, const Point3d ptP, const Vector3 // Trimesh della parte p-esima PtrOwner pStmRawPart( CloneSurfTriMesh( GetSurfTriMesh( pGObj))) ; - if( IsNull( pStmRawPart)) + if ( IsNull( pStmRawPart)) return false ; // porto la trimesh in globale @@ -625,7 +625,7 @@ Operation::GetSignedDistFromStmRaw( int nPhase, const Point3d ptP, const Vector3 pCrvEdge->FromPolyLine( vP[j]) ; if ( !pCrvEdge->IsValid() || pCrvEdge->GetCurveCount() == 0) return false ; - if( pCrvEdge->IsPointOn( ptP)) + if ( pCrvEdge->IsPointOn( ptP)) bIsCurrOnLoop = true ; } } diff --git a/Pocketing.cpp b/Pocketing.cpp index 97fdd3d..b258add 100644 --- a/Pocketing.cpp +++ b/Pocketing.cpp @@ -3337,6 +3337,11 @@ Pocketing::OptimizedZigZag( ISurfFlatRegion* pSrf, const Vector3d& vtTool, doubl } int nClosedSides = vnInfoClosed.size() ; + PtrOwner pCrvDraw1( CloneCurveComposite( pCrvPocket)) ; + pCrvDraw1->ToGlob( frPocket) ; + m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvDraw1->Clone()) ; + + // modifico pCrvPocket per poterla passare a CalcZigZag bool bTwoOpposite ; Vector3d vtDir ; // direzione principale del segmento più lungo (linea) @@ -3358,6 +3363,10 @@ Pocketing::OptimizedZigZag( ISurfFlatRegion* pSrf, const Vector3d& vtTool, doubl break ; } + PtrOwner pCrvDraw( CloneCurveComposite( pCrvPocket)) ; + pCrvDraw->ToGlob( frPocket) ; + m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvDraw->Clone()) ; + if ( ! bOptimizedZigZag) return true ; @@ -3717,39 +3726,77 @@ Pocketing::ZigZagOptimizedThreeClosedEdges( ICurveComposite* pCrvPocket, const I } //------------------------------------------------------------------ - bool - Pocketing::ZigZagOptimizedComputeOffset( ICurveComposite* pCrvPocket, const Vector3d& vtMainDir, int nOffsettedEdgesOnY, +bool +Pocketing::ZigZagOptimizedComputeOffset( ICurveComposite* pCrvPocket, const Vector3d& vtMainDir, int nOffsettedEdgesOnY, const INTVECTOR& vnClosedIds, double& dOffs) - { - // ricavo l'estrusione - Vector3d vtExtr ; pCrvPocket->GetExtrusion( vtExtr) ; - // ricavo la Thickness - double dThick ; pCrvPocket->GetThickness( dThick) ; +{ + // ricavo l'estrusione + Vector3d vtExtr ; pCrvPocket->GetExtrusion( vtExtr) ; + // ricavo la Thickness + double dThick ; pCrvPocket->GetThickness( dThick) ; - // aggiusto offset - dOffs = m_TParams.m_dDiam / 2 + 5 * EPS_SMALL ; - double dMinOffs = max( 0., 0.5 * m_TParams.m_dDiam - m_Params.m_dSideStep) ; - dOffs = max( dOffs, dMinOffs) ; + // aggiusto offset + dOffs = m_TParams.m_dDiam / 2 + 5 * EPS_SMALL ; + double dMinOffs = max( 0., 0.5 * m_TParams.m_dDiam - m_Params.m_dSideStep) ; + dOffs = max( dOffs, dMinOffs) ; - if ( dOffs > EPS_SMALL) { - // calcolo offset - OffsetCurve OffsCrv ; - if ( ! OffsCrv.Make( pCrvPocket, dOffs, ICurve::OFF_EXTEND)) { - m_pMchMgr->SetLastError( 2412, "Error in Pocketing : Offset not computable") ; - return false ; - } - if ( OffsCrv.GetCurveCount() > 1) - return false ; - - // aggiorno pCrvPocket - pCrvPocket->Clear() ; - pCrvPocket->AddCurve( OffsCrv.GetCurve()) ; - pCrvPocket->SetExtrusion( vtExtr) ; - pCrvPocket->SetThickness( dThick) ; - } + if ( nOffsettedEdgesOnY == 0) { + // calcolo il side step che verr� utilizzato in CalcZigZag + Frame3d frLoc ; + if ( ! frLoc.Set( ORIG, Z_AX, vtMainDir)) + return true ; + BBox3d b3Loc ; + pCrvPocket->ToLoc( frLoc) ; + pCrvPocket->GetLocalBBox( b3Loc) ; + pCrvPocket->ToGlob( frLoc) ; + Point3d pt ; + double dDimX, dDimY, dDimZ ; + b3Loc.GetMinDim( pt, dDimX, dDimY, dDimZ) ; + // riduco la DimY della svuotatura in base al numero di lati chiusi che saranno offsettati lungo quella direzione + dDimY -= nOffsettedEdgesOnY * ( 0.5 * m_TParams.m_dDiam + GetOffsR()) ; + int nYStep = static_cast( ceil( ( dDimY - 30 * EPS_SMALL) / GetSideStep())) ; + double dYSideStep = ( nYStep > 0 ? ( dDimY - 30 * EPS_SMALL) / nYStep : 0) ; + // verifico se resteranno aree residue e calcolo eventuale offset per pCrvPocket + double dOffs_ = 0 ; + for ( int i = 0 ; i < pCrvPocket->GetCurveCount() ; i ++) { + double dOffsTmp = 0 ; + double dVal = 0 ; + if ( pCrvPocket->GetCurve(i)->GetType() == CRV_LINE) { + Vector3d vtDir ; + if ( ! pCrvPocket->GetCurve( i)->GetStartDir( vtDir)) + return false ; + double dSinAlpha = ( vtMainDir ^ vtDir).Len() ; + if ( abs( dSinAlpha) > EPS_SMALL) + dVal = ( dYSideStep - 0.5 * m_TParams.m_dDiam) / dSinAlpha - 0.5 * m_TParams.m_dDiam ; + if ( dVal > EPS_SMALL) { + double dCosAlpha = vtMainDir * vtDir ; + dOffsTmp = abs( ( dYSideStep - 0.5 * m_TParams.m_dDiam) * dCosAlpha) ; + } + } + if ( dOffsTmp > dOffs_) + dOffs_ = dOffsTmp ; + } + dOffs = dOffs_ ; + } + if ( dOffs > EPS_SMALL) { + // calcolo offset + OffsetCurve OffsCrv ; + if ( ! OffsCrv.Make( pCrvPocket, dOffs, ICurve::OFF_EXTEND)) { + m_pMchMgr->SetLastError( 2412, "Error in Pocketing : Offset not computable") ; + return false ; + } + if ( OffsCrv.GetCurveCount() > 1) + return false ; - return true ; - } + // aggiorno pCrvPocket + pCrvPocket->Clear() ; + pCrvPocket->AddCurve( OffsCrv.GetCurve()) ; + pCrvPocket->SetExtrusion( vtExtr) ; + pCrvPocket->SetThickness( dThick) ; + } + + return true ; +} //------------------------------------------------------------------ bool @@ -7658,7 +7705,7 @@ bool Pocketing::AdjustTrapezoidSpiralForLeadInLeadOut( ICurveComposite* pCompo, ICurveComposite* pRCrv, const Vector3d& vtTool, double dDepth, int& nOutsideRaw) { - // recupero la direzione principale della svuotatura + // recupero la direzione principale della svuotatura Vector3d vtMainDir ; for ( int i = 0 ; i < pCompo->GetCurveCount() ; i++) { int nProp ; @@ -7745,30 +7792,24 @@ Pocketing::ComputeTrapezoidSpiralLeadInLeadOut( ICurveComposite* pCompo, const V // recupero la distanza dal bordo del grezzo lungo la direzione di allungamento double dDist ; Vector3d vtNorm ; - //if ( ! CalcDistanceFromRawSurface( m_nPhase, ptP, vtDirP, dDist, vtNorm)) - // return false ; - if ( ! GetSignedDistFromStmRaw( m_nPhase, ptP, vtDirP, dDist, vtNorm)) - return false ; - if ( abs( dDist) < EPS_SMALL) { - ptP -= vtDirP ; - if ( ! CalcDistanceFromRawSurface( m_nPhase, ptP, vtDirP, dDist, vtNorm)) - return false ; - } + + if ( ! GetSignedDistFromRealDirection( ptP, vtDirP, dDist, vtNorm)) + return false ; // calcolo eventuali fattori correttivi (se uscita approx. con fianco utensile) double dCorr = 1 ; double dDistRef = dDist ; double dDistMin ; Vector3d vtNormMin ; - if ( abs( vtTool * vtNorm) < 0.5 && GetSignedDistFromStmRaw( m_nPhase, ptP, vtDir, dDistMin, vtNorm)) { + if ( abs( vtTool * vtNorm) < 0.5 && GetSignedDistFromRealDirection( ptP, vtNorm, dDistMin, vtNormMin)) { if ( abs( dDistMin) < abs( dDist) && abs( dDistMin) > EPS_SMALL) { dDistRef = dDistMin ; dCorr = dDist / dDistMin ; } } - // se vicino al bordo del grezzo - if ( abs( dDistRef) < m_TParams.m_dDiam / 2 + EPS_SMALL) { + // ( se sono dentro al grezzo e se sono vicino al bordo del grezzo) oppure sono fuori ( circa sul bordo) + if (( dDistRef < EPS_SMALL && abs( dDistRef) < m_TParams.m_dDiam / 2 + EPS_SMALL ) || dDistRef > - EPS_SMALL) { Point3d ptTest = ptP + vtDirP * ( - dDist + ( m_TParams.m_dDiam / 2 + max( dSafeZ, m_dOpenMinSafe)) * dCorr) ; ptTest += - vtTool * dDepth ; double dTestElev ; @@ -7789,9 +7830,7 @@ Pocketing::ComputeTrapezoidSpiralLeadInLeadOut( ICurveComposite* pCompo, const V // calcolo distanza dal bordo del grezzo lungo vtDirO double dDist ; Vector3d vtNorm ; - //if ( ! CalcDistanceFromRawSurface( m_nPhase, ptP, vtDirO, dDist, vtNorm)) - // return false ; - if ( ! GetSignedDistFromStmRaw( m_nPhase, ptP, vtDirO, dDist, vtNorm)) + if ( ! GetSignedDistFromRealDirection( ptP, vtDirO, dDist, vtNorm)) return false ; // se vicino al bordo del grezzo @@ -7810,6 +7849,25 @@ Pocketing::ComputeTrapezoidSpiralLeadInLeadOut( ICurveComposite* pCompo, const V return true ; } +//---------------------------------------------------------------------------- +bool +Pocketing::GetSignedDistFromRealDirection( const Point3d ptP, const Vector3d vtDir, double& dDist, Vector3d& vtNorm) +{ + // calcolo la distanza lungo vtDir... + if ( ! GetSignedDistFromStmRaw( m_nPhase, ptP, vtDir, dDist, vtNorm)) + return false ; + // se risulta infinita, allora sono fuori dal grezzo, quindi inverto vtDir e ricalcolo la distanza + if ( dDist > INFINITO - 1) { + if ( ! GetSignedDistFromStmRaw( m_nPhase, ptP, -vtDir, dDist, vtNorm)) + return false ; + // se ancora infinita, errore + else if ( dDist > INFINITO - 1) + return false ; + } + + return true ; +} + //---------------------------------------------------------------------------- bool Pocketing::ComputePolishingPath( ICurveComposite* pMCrv, ICurveComposite* pRCrv, bool bSplitArcs) @@ -8766,6 +8824,8 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, ICRVCOMPOPOVECTO else { pCompo->AddLine( ptStart) ; pCompo->SetCurveTempProp( pCompo->GetCurveCount() - 1, bInVsOut ? 0 : 1, 0) ; // segmento aggiunto + if ( bInVsOut) + pCompo->SetCurveTempProp( pCompo->GetCurveCount() - 1, -99 , 1) ; // linea da controllare } } // se passo da aperto a chiuso @@ -8820,11 +8880,15 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, ICRVCOMPOPOVECTO else { pCompo->AddLine( ptStart) ; pCompo->SetCurveTempProp( pCompo->GetCurveCount() - 1, bInVsOut ? 0 : 1, 0) ; // segmento come curva aperta + if ( bInVsOut) + pCompo->SetCurveTempProp( pCompo->GetCurveCount() - 1, -99 , 1) ; // linea da controllare } } else { pCompo->AddLine( ptStart) ; pCompo->SetCurveTempProp( pCompo->GetCurveCount() - 1, 1, 0) ; // segmento come curva aperta + if ( bInVsOut) + pCompo->SetCurveTempProp( pCompo->GetCurveCount() - 1, -99 , 1) ; // linea da controllare } } } @@ -8839,11 +8903,36 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, ICRVCOMPOPOVECTO pCompo->Close() ; //int LI = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompo->Clone()) ; //m_pGeomDB->SetMaterial( LI, LIME) ; - + return true ; } +//--------------------------------------------------------------------------- +bool +Pocketing::AdustTmpPropLinesForProjection( ICurveComposite* pCompo) +{ + // controllo dei parametri + if ( pCompo == nullptr || ! pCompo->IsValid() || ! pCompo->IsClosed()) + return false ; + + // scorro la curva cercando tutti i tratti lineare con tmpProp 1 impostata a -99 + for ( int u = 0 ; u < pCompo->GetCurveCount() ; ++ u) { + const ICurve* pCrv_u = pCompo->GetCurve( u) ; + if ( pCrv_u == nullptr) + return false ; + if ( pCrv_u->GetType() == CRV_LINE && pCrv_u->GetTempProp( 1) == -99) { + const ICurve* pCrv_prec = pCompo->GetCurve( u == 0 ? pCompo->GetCurveCount() - 1 : u) ; + if ( pCrv_prec == nullptr) + return false ; + pCompo->SetCurveTempProp( u, pCrv_prec->GetTempProp( 0), 0) ; + } + } + + return pCompo->IsValid() && pCompo->IsClosed() ; +} + + //--------------------------------------------------------------------------- bool Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, const ICRVCOMPOPOVECTOR& vCrvIsland, @@ -9316,30 +9405,6 @@ Pocketing::VerifyLeadInZigZag( ISurfFlatRegion* pSrfChunk, const Point3d& ptPa, } -//---------------------------------------------------------------------------- -bool -Pocketing::CalcDistanceFromRawSurface( int nPhase, const Point3d& ptP, const Vector3d& vtDir, double& dDist, Vector3d& vtNorm) -{ - //if ( ! GetElevation( nPhase, ptP, vtDir, dDist, vtNorm)) - // return false ; - - // se punto esterno al grezzo - //if ( abs( dDist) < EPS_SMALL) { - // double dDist1, dDist2 ; - // if ( ! GetElevation( nPhase, ptP, -vtDir, dDist1)) - // return false ; - // if ( ! GetElevation( nPhase, ptP - vtDir * ( dDist1), vtDir, dDist2, vtNorm)) - // return false ; - // if ( abs( dDist2) > EPS_SMALL && abs( dDist1) > EPS_SMALL) - // dDist = dDist2 - dDist1 ; - //} - //if ( ! GetElevation( nPhase, ptP, vtDir, dDist, vtNorm) - // || ! GetSignedDistFromStmRaw( nPhase, ptP, vtDir, dDist, vtNorm)) - // return false ; - - return true ; -} - //---------------------------------------------------------------------------- bool Pocketing::GetParamsAtEachStep( ISURFFRPOVECTOR& vSrfSliced, vector& vCrvOEWithFlags, @@ -9405,6 +9470,7 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, const doubl // ricavo il grezzo attuale della lavorazione PtrOwner pStmRaw( CreateSurfTriMesh()) ; + pStmRaw->AdjustTopology() ; if ( ! GetStmRawPart( nProp0 , pStmRaw, GLOB_FRM)) return false ; @@ -9477,10 +9543,10 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, const doubl if ( ! ModifySurfByOpenEdge( pSrf, vCrvOEFlags, vtTrasl, pStmRaw)) return false ; - //PtrOwner pSrf_toDraw( CloneSurfFlatRegion( pSrf)) ; - //pSrf_toDraw->Translate( vtTrasl) ; - //m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_toDraw->Clone()) ; - /*for ( int c = 0 ; c < pSrf->GetChunkCount() ; ++ c) { + /*PtrOwner pSrf_toDraw( CloneSurfFlatRegion( pSrf)) ; + pSrf_toDraw->Translate( vtTrasl) ; + m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_toDraw->Clone()) ; + for ( int c = 0 ; c < pSrf->GetChunkCount() ; ++ c) { for ( int l = 0 ; l < pSrf->GetLoopCount( c) ; ++ l) { const ICurveComposite* pCrvCompo( GetCurveComposite( pSrf->GetLoop( c, l))) ; for ( int u = 0 ; u < pCrvCompo->GetCurveCount() ; ++ u) { @@ -9490,9 +9556,9 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, const doubl } } }*/ - //PtrOwner pSrf_toDraw( CloneSurfFlatRegion( pSrf)) ; - //pSrf_toDraw->Translate( vtTrasl) ; - //int p = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_toDraw->Clone()) ; + //PtrOwner pSrf_toDrawtt( CloneSurfFlatRegion( pSrf)) ; + //pSrf_toDrawtt->Translate( vtTrasl) ; + //int p = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_toDrawtt->Clone()) ; //m_pGeomDB->SetMaterial( p, PURPLE) ; // 4) SE SUPERIFICIE PRECEDENTEMENTE GIA' LAVORATA... @@ -9582,10 +9648,10 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio } } - //if ( bFromProj) { - //for ( int i = 0 ; i < vCrvExtProj.size() ; ++ i) - //m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvExtProj[i]->Clone()) ; - //} + /*if ( bFromProj) { + for ( int i = 0 ; i < vCrvExtProj.size() ; ++ i) + m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvExtProj[i]->Clone()) ; + }*/ //------------------------------------------------------------------------------------------------------------- // ---------------- CREAZIONE DELLA VERA A PROPRIA REGIONE DI INCIDENZA, COME SOMMA DELLE @@ -9619,10 +9685,10 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio pSrf_ind0->Invert() ; pSrf_Proj->Add( *pSrf_ind0) ; - //if ( bFromProj) { - //int ooo = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_Proj->Clone()) ; - //m_pGeomDB->SetMaterial( ooo, Color( 0.0, 1.0, 0.0, 0.3)) ; - //} + /*if ( bFromProj) { + int ooo = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_Proj->Clone()) ; + m_pGeomDB->SetMaterial( ooo, Color( 0.0, 1.0, 0.0, 0.3)) ; + }*/ // =============================================================================================================== // Clono la superificie originaria, portandola allo step corrente @@ -9631,10 +9697,10 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio return false ; pSrfOrig_clone->Translate( vtTrasl) ; - //if ( bFromProj) { - //int oooo = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfOrig_clone->Clone()) ; - //m_pGeomDB->SetMaterial( oooo, Color( 0.0, 0.0, 0.0, 0.3)) ; - //} + /*if ( bFromProj) { + int oooo = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfOrig_clone->Clone()) ; + m_pGeomDB->SetMaterial( oooo, Color( 0.0, 0.0, 0.0, 0.3)) ; + }*/ // ho cambiato un lato aperto in chiuso ? bool bLoopL_isChanged = false ; @@ -9645,10 +9711,10 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio PtrOwner pSrf_critica( CloneSurfFlatRegion( pSrf_Proj)) ; pSrf_critica->Subtract( *pSrfOrig_clone) ; - if ( bFromProj) { - //int ooooy = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_critica->Clone()) ; - //m_pGeomDB->SetMaterial( ooooy, ORANGE) ; - } + /*if ( bFromProj) { + int ooooy = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_critica->Clone()) ; + m_pGeomDB->SetMaterial( ooooy, ORANGE) ; + }*/ do { ++nCont ; @@ -9685,7 +9751,7 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio PtrOwner pCrvlonger( OffsCrv.GetLongerCurve()) ; // -> per ogni curva di Offset while ( ! IsNull( pCrvlonger) && ! bLoopL_isChanged) { - if ( ! pCrvlonger->IsClosed()) { // salto le curve "chiuse" + if ( ! pCrvlonger->IsClosed() || nCrv_offs == 1) { // salto le curve "chiuse" ( a meno che non sia l'unica) // 4) classifico la curva di offset ricavata con la supericie originale // NB. Tutti tratti di curva che sono esterni alla superificie originale e che si trovano all'interno della // superificie di proeizione del grezzo lo rovineranno al di fuori della superficie originale, quindi @@ -9693,10 +9759,10 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio PtrOwner pCrv_tOpen_Offs( CloneCurveComposite( pCrvlonger)) ; if ( IsNull( pCrv_tOpen_Offs) || ! pCrv_tOpen_Offs->IsValid()) return false ; - if ( bFromProj) { - //int YE = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrv_tOpen_Offs->Clone()) ; - //m_pGeomDB->SetMaterial( YE, YELLOW) ; - } + //if ( bFromProj) { + // int YE = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrv_tOpen_Offs->Clone()) ; + // m_pGeomDB->SetMaterial( YE, YELLOW) ; + //} CRVCVECTOR ccClass ; if ( pSrf_critica->GetCurveClassification( *pCrv_tOpen_Offs, 10 * EPS_SMALL, ccClass)) { for ( int j = 0 ; j < ( int)ccClass.size() && ! bLoopL_isChanged ; ++ j) { @@ -9726,8 +9792,8 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio PtrOwner CIAO( pCrv_tOpen_Offs->CopyParamRange( ccClass[j].dParS, ccClass[j].dParE)) ; //if ( bFromProj) { - //int YEs = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, CIAO->Clone()) ; - //m_pGeomDB->SetMaterial( YEs, Color( 0.95, 0.0, 0.63, 1.0)) ; + // int YEs = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, CIAO->Clone()) ; + // m_pGeomDB->SetMaterial( YEs, Color( 0.95, 0.0, 0.63, 1.0)) ; //} // ------------------------------ PARAMETRO FINALE ----------------------------------- @@ -10096,7 +10162,7 @@ Pocketing::IntersSurfWithRaw( ISurfFlatRegion* pSfrPock, const ISurfTriMesh* pSt return false ; // traslo la superificie da svuotare a seconda dello step e la taglio con il grezzo if ( ! pStm->Translate( vtTrasl) || - ! m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStm->Clone()) || ! m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStmRaw->Clone()) || + //! m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStm->Clone()) || ! m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStmRaw->Clone()) || ! pStm->CutWithOtherSurf( *pStmRaw, bInVsOut, true)) { pStm.Set( pStmCopy) ; // nel caso il taglio non sia riuscito, allungo leggermente il vettore di traslazione e riprovo @@ -10528,6 +10594,35 @@ Pocketing::GetStmRawPart( int nId, ISurfTriMesh* pSrfTMRaw, Frame3d frPocket) } } + //int nRawId = m_pMchMgr->GetFirstRawPart() ; + + //while ( nRawId != GDB_ID_NULL) { + // // verifico che il grezzo compaia nella fase + // if ( m_pMchMgr->VerifyRawPartPhase( nRawId, m_nPhase)) { + // // recupero l'oggetto dal database con tale Id + // int nRawSolidId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; + // const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( nRawSolidId) ; + // // recupero il frame in cui si trova + // Frame3d frRaw ; + // m_pGeomDB->GetGlobFrame( nRawSolidId, frRaw) ; + // if ( pGObj == nullptr) + // return false ; + // // controllo che sia una Trimesh + // if ( pGObj->GetType() == SRF_TRIMESH) { + // // Trimesh della parte p-esima + // PtrOwner pStmRawPart( CloneSurfTriMesh( GetSurfTriMesh( pGObj))) ; + // if ( IsNull( pStmRawPart)) + // return false ; + // // porto la trimesh in globale + // pStmRawPart->LocToLoc( frRaw, frPocket) ; + // // lo aggiungo alla Trimesh complessiva + // pSrfTMRaw->Add( *Release( pStmRawPart)) ; + // } + // } + // // passo al grezzo successivo + // nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; + //} + return true ; } @@ -10868,7 +10963,7 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt // copio la superficie in globale PtrOwner pSfrPock( CloneSurfFlatRegion( pSfr)) ; - if( IsNull( pSfrPock)) + if ( IsNull( pSfrPock)) return false ; // costante di estrusione per creazione delle regioni @@ -11036,6 +11131,7 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt // creo la curva composita associata PtrOwner pCrvBorderProj_f( CreateCurveComposite()) ; pCrvBorderProj_f->AddCurve( Release( pCrvProjFacef)) ; + //m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvBorderProj_f->Clone()) ; // 1) controllo se una sottocurva della curva composita del bordo è sufficientemente vicina ad una curva aperta // della curva originale di bordo della superificie esterna bool bNeedProj = false ; @@ -11068,6 +11164,47 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt } } } + if ( ! bNeedProj) { + // 3) controllo se la questa curva contiene o interseca un lato aperto + // 3.1) creo una flat region ausiliaria per determinare il verso corretto della curva proeittata + PtrOwner pSrf_HelpProjPart( CreateSurfFlatRegion()) ; + if ( IsNull( pSrf_HelpProjPart)) + return false ; + pSrf_HelpProjPart->AddExtLoop( pCrvBorderProj_f->Clone()) ; + if ( AreOppositeVectorApprox( pSrf_HelpProjPart->GetNormVersor(), pSrfOrig->GetNormVersor())) + pSrf_HelpProjPart->Invert() ; + // 3.2) ricavo la curva di bordo della regione ( lascio le isole invariate) <- possibile miglioria (?) + PtrOwner pCrvBorder_Check( ConvertCurveToComposite( pSfrPock->GetLoop( 0, 0))) ; + if ( IsNull( pCrvBorder_Check) || ! pCrvBorder_Check->IsValid()) + return false ; + // 3.3) classificazione + CRVCVECTOR ccClass_H ; + + //int G = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_HelpProjPart->Clone()) ; + //m_pGeomDB->SetMaterial( G, YELLOW) ; + //int GG = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvBorder_Check->Clone()) ; + //m_pGeomDB->SetMaterial( GG, YELLOW) ; + + + + if ( pSrf_HelpProjPart->GetCurveClassification( *pCrvBorder_Check, EPS_SMALL, ccClass_H)) { + for ( int j = 0 ; j < ( int)ccClass_H.size() && !bNeedProj ; ++ j) { + if ( ccClass_H[j].nClass == CRVC_IN) { + // se tratto j di curva interno, controllo se c'è un sotto-tratto jj aperto + PtrOwner pCrvCompo_forOpens( + ConvertCurveToComposite( pCrvBorder_Check->CopyParamRange( ccClass_H[j].dParS, ccClass_H[j].dParE))) ; + if ( ! IsNull( pCrvCompo_forOpens) && pCrvCompo_forOpens->IsValid()) { + // scorro le sottocurve del tratto j + for ( int u = 0 ; u < pCrvCompo_forOpens->GetCurveCount() && !bNeedProj ; ++ u) { + int nTmpProp0 = 0 ; + if ( pCrvCompo_forOpens->GetCurveTempProp( u, nTmpProp0, 0) && nTmpProp0 == 1) + bNeedProj = true ; + } + } + } + } + } + } if ( ! bNeedProj) // se non devo proiettare passo alla prossima continue ; @@ -11173,6 +11310,7 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt PtrOwner pSrfWithOEModified( CreateSurfFlatRegion()) ; if ( IsNull( pSrfWithOEModified)) return false ; + // sistemo le rette ottenute per allargare la superificie presso i lati aperti pSrfWithOEModified->AddExtLoop( Release( pCrvExt)) ; // la modifico con la curva appena restituita // ( allargata dai lati aperti) if ( pSrfWithOEModified->IsValid()) { // se la superificie ottenuta è valida... @@ -11204,7 +11342,7 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt return false ; //int ghh = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrProj_Clone->Clone()) ; //m_pGeomDB->SetMaterial( ghh, ORANGE) ; - // Recupero le TmpProp e creo la nuova superificie mediante questo loop esterno + // Recupero le TmpProp e creo la nuova superificie mediante questo loop esterno PtrOwner pCrv_NewExt( pSfrProj_Clone->GetLoop( 0, 0)) ; if ( IsNull( pCrv_NewExt) || ! pCrv_NewExt->IsValid()) return false ; @@ -11214,13 +11352,6 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt pCrvCompo_NewExt->AddCurve( Release( pCrv_NewExt)) ; // Imposto le temp prop if ( pCrvCompo_NewExt->IsValid()) { - /*if( nStep == 2) { - m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvCompo_NewExt->Clone()) ; - for ( int ii = 0 ; ii < vCrvExtProj.size() ; ++ii) { - int jjj = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvExtProj[ii]->Clone()) ; - m_pGeomDB->SetMaterial( jjj, RED) ; - } - }*/ if ( ! SetTmpPropWithRawProjectedFaces( pCrvCompo_NewExt, vCrvExtProj, pSfr->GetNormVersor()) || ! CheckSmallPartsForOpenEdge( pCrvCompo)) return false ; @@ -11705,6 +11836,10 @@ Pocketing::GetParamForPtStartOnEdge( const ICurve* pCrvCheck, const ICurveCompos // lavorare, i quali Offset non hanno generato alcuna curva di pCrvCheck ) // ========================================================================================== + //for ( int u = 0 ; u < pCrvCompo->GetCurveCount() ; ++ u) { + // int c = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvCompo->GetCurve( u)->Clone()) ; + // m_pGeomDB->SetMaterial( c, pCrvCompo->GetCurve( u)->GetTempProp( 0) == 0 ? BLUE : RED) ; + //} // controllo dei parametri if ( pCrvCheck == nullptr || ! pCrvCheck->IsValid() || @@ -11752,10 +11887,10 @@ Pocketing::GetParamForPtStartOnEdge( const ICurve* pCrvCheck, const ICurveCompos if ( IsNull( pCrvArc) || ! GetCoeffLinArc( pCrvArc, dDiam, dSubArc)) return false ; } - double dDiv = dSubArc < 0 ? dDiam : dSubArc; + double dDiv = dSubArc < 0 ? dDiam : dSubArc ; double dMaxInt = floor( dLen / dDiv) ; - if ( dMaxInt < EPS_SMALL) - return false ; + //if ( dMaxInt < EPS_SMALL) + // return false ; int nDen = 2 ; // intervalli in cui suddivido la curva dMaxInt = max( 2.0, dMaxInt) ; // così se entra una volta controllo sempre dParT = 0.5 @@ -11935,7 +12070,7 @@ Pocketing::SetBetterPtStartForSubChunks( ICurveComposite* pCrvOffsAct, const ISu pCrv->SetCurveTempProp( i, 0, 0) ; } else - pCrv->SetCurveTempProp( i, 0, 0) ; + pCrv->SetCurveTempProp( i, 1, 0) ; // <- tmp prop = 0 } @@ -12042,6 +12177,9 @@ Pocketing::SetTmpPropByOverlap( ICurveComposite* pCrv_, int nInd, const ICurveCo if ( dUE - floor( dUE) < EPS_SMALL) nRealDUE = ( int)floor( dUE) ; + if ( nRealDUS == pCrvOri->GetCurveCount()) + nRealDUS = 0 ; + // controllo subito se tocco più curve sulla originale con stesse temp prop bool bHasAllSameProp = true ; int nProp_prec ; pCrvOri->GetCurveTempProp( nRealDUS, nProp_prec, 0) ; @@ -12184,17 +12322,17 @@ Pocketing::SetTmpPropWithRawProjectedFaces( ICurveComposite* pCrvCompo_NewExt, I if ( ! frLoc.IsValid()) return false ; + //int PU = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvCompo_NewExt->Clone()) ; + //m_pGeomDB->SetMaterial( PU, PURPLE) ; + //for ( int i = 0 ; i < (int)vCrvExtProj.size() ; ++ i) { + // int rr = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvExtProj[i]->Clone()) ; + // m_pGeomDB->SetMaterial( rr, i == 0 ? LIME : GRAY) ; + //} + // inizialmente imposto tutte le curve come chiuse for ( int u = 0 ; u < pCrvCompo_NewExt->GetCurveCount() ; ++ u) pCrvCompo_NewExt->SetCurveTempProp( u, 0, 0) ; - //int ww = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvCompo_NewExt->Clone()) ; - //m_pGeomDB->SetMaterial( ww, WHITE) ; - //for ( int i = 0 ; i < ( int)vCrvExtProj.size() ; ++ i) { - // int ww2 = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvExtProj[i]->Clone()) ; - // m_pGeomDB->SetMaterial( ww2, BLACK) ; - //} - // imposto le proprietà temporanee delle curve for ( int u = 0 ; u < pCrvCompo_NewExt->GetCurveCount() ; ++ u) { bool bFound = false ; @@ -12253,7 +12391,7 @@ Pocketing::SetTmpPropWithRawProjectedFaces( ICurveComposite* pCrvCompo_NewExt, I int nStat1 = -1 ; // richiamo la SetTmpPropByOverlap in quanto potrebbe fare overlap con l'indice 0 di vCrvExtProj. // L'indice 0 contiene il bordo con i lati aperti/chiusi settati della intersezione con il grezzo - if ( SetTmpPropByOverlap( pCrvCompo_Step, 0, vCrvExtProj[i], nStat1, dToll) && nStat1 != -1) + if ( SetTmpPropByOverlap( pCrvCompo_Step, 0, vCrvExtProj[i], nStat1, dToll) && nStat1 != 1) pCrvCompo_Step->SetCurveTempProp( 0, 0, 0) ; // chiusa se non c'è Overlap pCrvCompoH->AddCurve( Release( pCrvCompo_Step)) ; } @@ -12266,6 +12404,9 @@ Pocketing::SetTmpPropWithRawProjectedFaces( ICurveComposite* pCrvCompo_NewExt, I // overlap ha fatto con le curve esterne delle proiezioni if ( pCrvCompoH->GetCurveCount() > 1) pCrvCompoCurr.Set( Release( pCrvCompoH)) ; + else { + + } } // sostituisco la CURVA COMPOSITA creata con alla CURVA SEMPLICE originaria PtrOwner pCrv_Bef( CloneCurveComposite( pCrvCompo_NewExt)) ; // tratto precente diff --git a/Pocketing.h b/Pocketing.h index 7a15e1d..77b487f 100644 --- a/Pocketing.h +++ b/Pocketing.h @@ -137,6 +137,7 @@ class Pocketing : public Machining bool AdjustContourWithOpenEdges( ICurveComposite* pCompo, ICRVCOMPOPOVECTOR& vCrvIsl, double dDiam, double dOffR, double dStepPrec, const Vector3d& vtTrasl, ISurfTriMesh* pStmRaw = nullptr, bool bInVsOut = false) ; + bool AdustTmpPropLinesForProjection( ICurveComposite* pCompo) ; bool AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, const ICRVCOMPOPOVECTOR& vCrvIsland, ICurveComposite* pCrvOpenOffs, const Point3d& ptCrvOpenS, const Point3d& ptCrvOpenE, const double dRad, const double dDiam, @@ -230,6 +231,7 @@ class Pocketing : public Machining double dDepth, int& nOutsideRaw) ; bool ComputeTrapezoidSpiralLeadInLeadOut( ICurveComposite * pCompo, const Vector3d& vtMainDir, bool bLeadIn, const Vector3d& vtTool, double dDepth, bool& bIsOutsideRaw) ; + bool GetSignedDistFromRealDirection( const Point3d ptP, const Vector3d vtDir, double& dDist, Vector3d& vtNorm) ; // ========================================================================= // ============================ FEED ======================================= @@ -259,7 +261,6 @@ class Pocketing : public Machining // ============================ IN/OUT ===================================== bool VerifyLeadInHelix( ISurfFlatRegion* pSrfChunk, const Point3d& ptCen, double dRad) const ; bool VerifyLeadInZigZag( ISurfFlatRegion* pSrfChunk, const Point3d& ptPa, const Point3d& ptPb) const ; - bool CalcDistanceFromRawSurface( int nPhase, const Point3d& ptP, const Vector3d& vtDir, double& dDist, Vector3d& vtNorm) ; bool ComputePolishingPath( ICurveComposite* pMCrv, ICurveComposite* pRCrv, bool bSplitArcs) ; bool AddEpicycles( ICurveComposite * pCompo, ICurveComposite * pCrv, ICurveComposite * pCrvBound = nullptr) ; bool AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dSafeAggrBottZ, @@ -340,7 +341,7 @@ class Pocketing : public Machining double m_dMaxLenRawProj = 100 ; // lunghezza massima per contatto di proiezione bool m_bOptOffset = true ; // flag per ottimizzazione numero di Offset necessari bool m_bOptOffsetCM = false ; // flag per ottimizzazione numero di Offset necessari con centroidi e medial Axis - bool m_bAssignFeed = true ; // flag per controllo della Feed + bool m_bAssignFeed = false ; // flag per controllo della Feed double m_dDiam_Prec = 0.0 ; // diametro utensile per precedente svuotatura double m_dOffsetR_Prec = 0.0 ; // offset radiale della svuotatura precedente double m_dSideStep_Prec = 0.0 ; // side Step della svuotatura precedente