From 0787d66b72e3fbe4e7c8c6ec918f27da17430181 Mon Sep 17 00:00:00 2001 From: Riccardo Elitropi Date: Thu, 11 Jun 2026 10:12:40 +0200 Subject: [PATCH] EgtMachKernel : - in Finiture aggiunta funzione per appiattire le curve di selezione - in Finiture Optimal migliorati controlli. --- SurfFinishing.cpp | 75 +++++++++++++++++++++++++++++++++++++---------- SurfFinishing.h | 1 + 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/SurfFinishing.cpp b/SurfFinishing.cpp index 210d259..9042df9 100644 --- a/SurfFinishing.cpp +++ b/SurfFinishing.cpp @@ -1162,11 +1162,46 @@ SurfFinishing::GetCurves( SelData Id, ICURVEPLIST& lstPC) return false ; } +//---------------------------------------------------------------------------- +bool +SurfFinishing::FlattenCurves( ICURVEPOVECTOR& vpCrv) const +{ + // se la lista è vuota, non faccio nulla + if ( vpCrv.empty()) + return true ; + + // scorro le curve + for ( int i = 0 ; i < ssize( vpCrv) ; ++ i) { + // se nulla o non valida, errore + if ( vpCrv[i] == nullptr || ! vpCrv[i]->IsValid()) + return false ; + // definisco un riferimento a partire dalla sua estrusione + Vector3d vtExtr = Z_AX ; vpCrv[i]->GetExtrusion( vtExtr) ; + Frame3d frRef ; + if ( ! frRef.Set( ORIG, vtExtr)) + return false ; + // porto la curva in tale riferimento + vpCrv[i]->ToLoc( frRef) ; + BBox3d B3Loc ; vpCrv[i]->GetLocalBBox( B3Loc) ; + Point3d ptMaxGlob = GetToGlob( B3Loc.GetMax(), frRef) ; + vpCrv[i]->ToGlob( frRef) ; + // proeitto la curva sul piano definito dalla sua estrusione e dal suo punto locale più elevato + Plane3d plRef ; + if ( ! plRef.Set( ptMaxGlob, vtExtr)) + return false ; + vpCrv[i].Set( ProjectCurveOnPlane( *vpCrv[i], plRef)) ; + vpCrv[i]->SetExtrusion( vtExtr) ; + if ( IsNull( vpCrv[i]) || ! vpCrv[i]->IsValid()) + return false ; + } + + return true ; +} + //---------------------------------------------------------------------------- bool SurfFinishing::Chain( int nGrpDestId) { - // vettore puntatori alle curve ICURVEPOVECTOR vpCrvs ; vpCrvs.reserve( m_vId.size()) ; @@ -1186,6 +1221,12 @@ SurfFinishing::Chain( int nGrpDestId) } } + // appiattisco le curve di contorno + if ( ! FlattenCurves( vpCrvs)) { + m_pMchMgr->SetLastError( 3105, "Error in SurfFinishing : Contour Not Flat") ; + return false ; + } + // se finitura a proiezione di curve if ( m_Params.m_nSubType == SURFFIN_SUB_PROJECT) { int nGroupName = -1 ; @@ -5638,17 +5679,6 @@ SurfFinishing::CalcOptimalZigZagCurves( ISURFFRPOVECTOR& vSfrZigZagProj, const F if ( pSfrZigZag == nullptr || ! pSfrZigZag->IsValid()) continue ; - // tutti i lati della superficie vengono considerati come chiusi, quindi per portare l'utensile lungo - // i bordi estendo la superficie del raggio utensile - if ( ! pSfrZigZag->Offset( m_TParams.m_dDiam / 2. - 5. * EPS_SMALL, ICurve::OFF_FILLET)) - return false ; - for ( int nC = 0 ; nC < pSfrZigZag->GetChunkCount() ; ++ nC) { - for ( int nL = 0 ; nL < pSfrZigZag->GetLoopCount( nC) ; ++ nL) { - for ( int nU = 0 ; nU < pSfrZigZag->GetLoopCurveCount( nC, nL) ; ++ nU) - pSfrZigZag->SetCurveTempProp( nC, nL, nU, 0, TEMP_PROP_CLOSE_EDGE) ; - } - } - #if ENABLE_OPTIMAL_DEBUG int nSfrProjId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLaySfrProj, pSfrZigZag->Clone()) ; m_pGeomDB->SetMaterial( nSfrProjId, Color( 1., 0., 0., .5)) ; @@ -6101,7 +6131,9 @@ SurfFinishing::CalcOptimalZConstCurves( const ISurfFlatRegion* pSfrLoc, const SU // la superficie complessiva di collisione viene limitata al bordo if ( pSfrToolColl->IsValid()) { - pSfrToolColl->Offset( - dExtraOffs, ICurve::OFF_FILLET) ; + #if 0 + pSfrToolColl->Offset( - dExtraOffs, ICurve::OFF_FILLET) ; + #endif if ( pSfrToolColl->IsValid()) pSfrToolColl->Intersect( *pSfrLoc) ; #if ENABLE_OPTIMAL_DEBUG @@ -6236,8 +6268,21 @@ SurfFinishing::CalcOptimalZigZagRegion( const ISurfFlatRegion* pSfrCntLoc, const // verifico che il Chunk non sia troppo "snello" double dMaxOffs = 0. ; pSfrZigZagChunk->GetMaxOffset( dMaxOffs) ; - if ( dMaxOffs > 10. * EPS_SMALL) - vpSfrZigZagProj.emplace_back( Release( pSfrZigZagChunk)) ; + if ( dMaxOffs < 10. * EPS_SMALL) + continue ; + // per maggior precisione, effettuo un Offset del raggio utensile per coincidere con le curve di ZLevel + pSfrZigZagChunk->Offset( m_TParams.m_dDiam / 2., ICurve::OFF_FILLET) ; + // tutti i lati della superficie vengono considerati come chiusi, quindi per portare l'utensile lungo + // i bordi estendo la superficie del raggio utensile + if ( ! pSfrZigZagChunk->Offset( m_TParams.m_dDiam / 2. - 5. * EPS_SMALL, ICurve::OFF_FILLET)) + return false ; + for ( int nC = 0 ; nC < pSfrZigZagChunk->GetChunkCount() ; ++ nC) { + for ( int nL = 0 ; nL < pSfrZigZagChunk->GetLoopCount( nC) ; ++ nL) { + for ( int nU = 0 ; nU < pSfrZigZagChunk->GetLoopCurveCount( nC, nL) ; ++ nU) + pSfrZigZagChunk->SetCurveTempProp( nC, nL, nU, 0, TEMP_PROP_CLOSE_EDGE) ; + } + } + vpSfrZigZagProj.emplace_back( Release( pSfrZigZagChunk)) ; } } } diff --git a/SurfFinishing.h b/SurfFinishing.h index 78ede9f..2e7f455 100644 --- a/SurfFinishing.h +++ b/SurfFinishing.h @@ -109,6 +109,7 @@ class SurfFinishing : public Machining bool VerifyGeometry( SelData Id, int& nSubs) ; bool GetCurves( SelData Id, ICURVEPLIST& lstPC) ; bool Chain( int nGrpDestId) ; + bool FlattenCurves( ICURVEPOVECTOR& vpCrv) const ; bool UpdateFrameAndToolDir( int nAuxId, bool& bRecalc) ; bool GetSurfacesByIds( SURFLOCALVECTOR& vSrfLoc, SURFLOCALVECTOR& vSrfSuppLoc, Frame3d& frSurf) ; bool CalcRegionElevation( const ISurfFlatRegion* pSfr, const Vector3d& vtTool, double dRad, double dLen, double& dElev) const ;