EgtMachKernel :

- in PocketingNT migliorate le entrate a ZigZag.
This commit is contained in:
Riccardo Elitropi
2026-04-23 17:08:53 +02:00
parent e1ef39ad72
commit bf602419fc
2 changed files with 226 additions and 14 deletions
+220 -10
View File
@@ -125,9 +125,10 @@ static double TOOL_RAD_PTSTART = 20. ;
#define DEBUG_FEED 0 // Debug per Feed
#define DEBUG_START_POINT 0 // Debug per scelta del punto iniziale
#define DEBUG_PATH_CL 0 // Debug per valori memorizzati nel percorso del CL
#define DEBUG_ZIGZAG_LEADIN 0 // Debug per ZigZag LeadIn
#define DEBUG 0 // Debug
#if DEBUG_STM_TOPOLOGY || DEBUG_OPEN_EDGE_EXTENSION || DEBUG_OPEN_EDGE_IN_RAW || DEBUG_SFR_STEPS || DEBUG_SFR_RAW || DEBUG_SFR_GEO_EXT || \
DEBUG_GLIDE || DEBUG_SAFETY_LINK || DEBUG_FEED || DEBUG_START_POINT || DEBUG_PATH_CL || DEBUG
DEBUG_GLIDE || DEBUG_SAFETY_LINK || DEBUG_FEED || DEBUG_START_POINT || DEBUG_PATH_CL || DEBUG_ZIGZAG_LEADIN || DEBUG
#include "EgtDev/Include/EGkGeoPoint3d.h"
#include "EgtDev/Include/EGkGeoVector3d.h"
#include "EgtDev/Include/EGkFrame3d.h"
@@ -4705,6 +4706,30 @@ PocketingNT::CalcPaths( STEPINFOPOVECTOR& vStepInfo)
}
}
// calcolo il percorso a ZigZag di ritorno ( se necessario)
if ( GetLeadInType() != POCKET_LI_NONE && GetLeadInType() != POCKET_LI_GLIDE) {
for ( int i = 0 ; i < ssize( vStepInfo) ; ++ i) {
for ( int j = 0 ; j < ssize( vStepInfo[i].vPaths) ; ++ j) {
if ( IsNull( vStepInfo[i].vPaths[j].pCrvPath) || ! vStepInfo[i].vPaths[j].pCrvPath->IsValid())
continue ;
PtrOwner<ICurveComposite> pCompoZigZag( CreateCurveComposite()) ;
if ( IsNull( pCompoZigZag))
return false ;
Point3d ptStart ; vStepInfo[i].vPaths[j].pCrvPath->GetStartPoint( ptStart) ;
bool bOk = true ;
for ( int nC = 0 ; bOk && nC < vStepInfo[i].vPaths[j].pCrvPath->GetCurveCount() ; ++ nC) {
const ICurve* pCrv = vStepInfo[i].vPaths[j].pCrvPath->GetCurve( nC) ;
bOk = ( pCrv != nullptr && pCrv->IsValid() && pCompoZigZag->AddCurve( *pCrv)) ;
Point3d ptEnd ; pCrv->GetEndPoint( ptEnd) ;
if ( AreSamePointEpsilon( ptStart, ptEnd, 25. * EPS_SMALL))
break ;
}
if ( bOk)
vStepInfo[i].vPaths[j].pCrvZigZagIn.Set( Release( pCompoZigZag)) ;
}
}
}
return true ;
}
@@ -4903,7 +4928,7 @@ PocketingNT::AddPocket( STEPINFOPOVECTOR& vStepInfo, const Vector3d& vtTool, dou
bool bNoneForced = ( currPath.bOutStart || currPath.bSingleCrv ||
( m_Params.m_nSubType == POCKET_SUB_ZIGZAG && ! currPath.bIsZigZagOneWayBorder) ||
( m_Params.m_nSubType == POCKET_SUB_ONEWAY && ! currPath.bIsZigZagOneWayBorder)) ;
if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtTool, currStep.pSfrPock, Get( currPath.pCrvGlideIn),
if ( ! AddLeadIn( ptP1, ptStart, vtStart, vtTool, currStep.pSfrPock, Get( currPath.pCrvGlideIn), Get( currPath.pCrvZigZagIn),
( m_Params.m_nSubType == POCKET_SUB_SPIRALOUT ? m_Params.m_bInvert : ! m_Params.m_bInvert),
bSplitArcs, bNoneForced, false)) {
m_pMchMgr->SetLastError( 3013, "Error in PocketingNT : LeadIn not computable") ;
@@ -5119,7 +5144,7 @@ PocketingNT::CalcLastElevation( const Point3d& ptEnd, const Point3d& ptP1, const
//----------------------------------------------------------------------------
double
PocketingNT::GetRightFeed( const Vector3d& vtMove, const Vector3d& vtTool)
PocketingNT::GetRightFeed( const Vector3d& vtMove, const Vector3d& vtTool) const
{
// Determino i versori
Vector3d vtM = vtMove ;
@@ -5137,7 +5162,7 @@ PocketingNT::GetRightFeed( const Vector3d& vtMove, const Vector3d& vtTool)
//------------------------------------------------------------------
double
PocketingNT::GetRightStartFeed( const Vector3d& vtMove, const Vector3d& vtTool)
PocketingNT::GetRightStartFeed( const Vector3d& vtMove, const Vector3d& vtTool) const
{
// Determino i versori
Vector3d vtM = vtMove ;
@@ -5670,7 +5695,7 @@ PocketingNT::CalcLeadInStart( Point3d& ptStart, const Vector3d& vtTool,
//----------------------------------------------------------------------------
bool
PocketingNT::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& vtStart, const Vector3d& vtN,
const ISurfFlatRegion* pSfr, const ICurveComposite* pRCrv, bool bAtLeft, bool bSplitArcs,
const ISurfFlatRegion* pSfr, const ICurveComposite* pRCrv, const ICurveComposite* pRZigZag, bool bAtLeft, bool bSplitArcs,
bool bNoneForced, bool bSkipControl)
{
// Assegno il tipo
@@ -5742,11 +5767,16 @@ PocketingNT::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vecto
#endif
return ( AddLinearMove( ptStart, bSplitArcs, MCH_CL_LEADIN) != GDB_ID_NULL) ;
}
// altrimenti diretto ( controllo semplicemente se posso entrare di testa)
// altrimenti provo a modificare il percorso a ZigZag in maniera opportuna
else {
nType = POCKET_LI_NONE ;
if ( m_TParams.m_nType == TT_MILL_NOTIP)
return false ;
if ( AddSpecialLeadInZigZag( pRZigZag, ptStart, vtN, nStep, dStep))
return true ;
// altrimenti diretto ( controllo semplicemente se posso entrare di testa)
else {
nType = POCKET_LI_NONE ;
if ( m_TParams.m_nType == TT_MILL_NOTIP)
return false ;
}
}
}
// Se a scivolo e fattibile
@@ -6108,7 +6138,187 @@ PocketingNT::VerifyLeadInOutGlide( const ISurfFlatRegion* pSfr, ICurveComposite*
//----------------------------------------------------------------------------
bool
PocketingNT::CalcDistanceFromRawSurface( int nPhase, const Point3d& ptP, const Vector3d& vtDir,
PocketingNT::AddSpecialLeadInZigZag( const ICurveComposite* pCompoPath, const Point3d& ptCurr, const Vector3d& vtTool,
int nStep, double dStep)
{
// verifico la validità della curva
if ( pCompoPath == nullptr || ! pCompoPath->IsValid())
return false ;
// verifico che la curva sia sufficientemente lunga per permettere un'entrata a ZigZag
double dMaxLen = min( m_Params.m_dLiTang, m_TParams.m_dDiam) ;
double dLen ; pCompoPath->GetLength( dLen) ;
if ( dLen < dMaxLen)
return false ;
#if DEBUG_ZIGZAG_LEADIN
int _a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompoPath->Clone()) ;
m_pGeomDB->SetMaterial( _a, RED) ;
PtrOwner<IGeoPoint3d> _pt( CreateGeoPoint3d()) ; _pt->Set( ptCurr) ;
_a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, _pt->Clone()) ;
m_pGeomDB->SetMaterial( _a, YELLOW) ;
#endif
// verifico che il punto iniziale sia effettivamente sulla curva
const double TOL = 25. * EPS_SMALL ;
if ( ! pCompoPath->IsPointOn( ptCurr, TOL))
return false ;
Point3d ptStartZigZag = ptCurr ; // punto di inizio dello ZigZag ( potrebbe essere diverso da ptCurr)
bool bAtStart = false ; // indica se lo ZigZag è vincolato prima della partenza
bool bAtEnd = false ; // indica se lo ZigZag è vincolato dopo l'arrivo
// recupero i due tratti di curva per lo ZigZag
PtrOwner<ICurveComposite> pCrvA( nullptr) ; // dal punto corrente segue la tangenza della curva
PtrOwner<ICurveComposite> pCrvB( nullptr) ; // dal punto corrente è opposta alla tangenza della curva
if ( pCompoPath->IsClosed()) {
// --- se curva chiusa, recupero il tratto iniziale e finale ( esistono per forza per precedente controllo sulla lunghezza)
PtrOwner<ICurveComposite> pCompoPathCL( CloneCurveComposite( pCompoPath)) ;
if ( IsNull( pCompoPathCL) || ! pCompoPathCL->IsValid())
return false ;
double dUCurr ; pCompoPathCL->GetParamAtPoint( ptCurr, dUCurr, TOL) ;
pCompoPathCL->ChangeStartPoint( dUCurr) ;
double dUA ; pCompoPathCL->GetParamAtLength( dMaxLen / 2., dUA) ;
double dUB ; pCompoPathCL->GetParamAtLength( dLen - dMaxLen / 2., dUB) ;
double dUS, dUE ;
pCompoPathCL->GetDomain( dUS, dUE) ;
pCrvA.Set( ConvertCurveToComposite( pCompoPathCL->CopyParamRange( dUS, dUA))) ;
if ( pCrvB.Set( ConvertCurveToComposite( pCompoPathCL->CopyParamRange( dUB, dUE))))
pCrvB->Invert() ;
}
else {
// --- se curva aperta, verifico se mi trovo vicino ad un estrmo
double dLenCurr ; pCompoPath->GetLengthAtPoint( ptCurr, dLenCurr, TOL) ;
bAtStart = ( dLenCurr < dMaxLen / 2.) ;
bAtEnd = ( dLenCurr > dLen - dMaxLen / 2.) ;
// se lontano da entrambi gli estremi, allora posso definire le due curve per lo ZigZag
if ( ! bAtStart && ! bAtEnd) {
double dUCurr ; pCompoPath->GetParamAtPoint( ptCurr, dUCurr, TOL) ;
double dUA ; pCompoPath->GetParamAtLength( dLenCurr + dMaxLen / 2. - EPS_SMALL, dUA) ;
double dUB ; pCompoPath->GetParamAtLength( dLenCurr - dMaxLen / 2. + EPS_SMALL, dUB) ;
pCrvA.Set( ConvertCurveToComposite( pCompoPath->CopyParamRange( dUCurr, dUA))) ;
if ( pCrvB.Set( ConvertCurveToComposite( pCompoPath->CopyParamRange( dUB, dUCurr))))
pCrvB->Invert() ;
}
else {
double dUS, dUE ; pCompoPath->GetDomain( dUS, dUE) ;
// se sono all'inizio
if ( bAtStart) {
double dUA ; pCompoPath->GetParamAtLength( dMaxLen - EPS_SMALL, dUA) ;
double dUMid ; pCompoPath->GetParamAtLength( dMaxLen / 2., dUMid) ;
pCrvA.Set( ConvertCurveToComposite( pCompoPath->CopyParamRange( dUMid, dUA))) ;
if ( pCrvB.Set( ConvertCurveToComposite( pCompoPath->CopyParamRange( dUS, dUMid))))
pCrvB->Invert() ;
}
// se alla fine
else if ( bAtEnd) {
double dUB ; pCompoPath->GetParamAtLength( dLen - dMaxLen + EPS_SMALL, dUB) ;
double dUMid ; pCompoPath->GetParamAtLength( dLen - dMaxLen / 2., dUMid) ;
pCrvA.Set( ConvertCurveToComposite( pCompoPath->CopyParamRange( dUMid, dUE))) ;
if ( pCrvB.Set( ConvertCurveToComposite( pCompoPath->CopyParamRange( dUB, dUMid))))
pCrvB->Invert() ;
}
}
}
// se le curve di ZigZag non sono valide, errore
if ( IsNull( pCrvA) || IsNull( pCrvB) || ! pCrvA->IsValid() || ! pCrvB->IsValid())
return false ;
// definisco i quattro tratti dello ZigZag
ICRVCOMPOPOVECTOR vCrvZigZagStep ; vCrvZigZagStep.resize( 4) ;
if ( ! vCrvZigZagStep[0].Set( Release( pCrvA)) ||
! vCrvZigZagStep[1].Set( CloneCurveComposite( vCrvZigZagStep[0])) || ! vCrvZigZagStep[1]->Invert() ||
! vCrvZigZagStep[2].Set( Release( pCrvB)) ||
! vCrvZigZagStep[3].Set( CloneCurveComposite( vCrvZigZagStep[2])) || ! vCrvZigZagStep[3]->Invert())
return false ;
// Assegno loro l'estrusione
vCrvZigZagStep[0]->SetExtrusion( vtTool) ;
vCrvZigZagStep[1]->SetExtrusion( vtTool) ;
vCrvZigZagStep[2]->SetExtrusion( vtTool) ;
vCrvZigZagStep[3]->SetExtrusion( vtTool) ;
#if DEBUG_ZIGZAG_LEADIN
_a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvZigZagStep[0]->Clone()) ;
m_pGeomDB->SetMaterial( _a, AQUA) ;
_a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvZigZagStep[1]->Clone()) ;
m_pGeomDB->SetMaterial( _a, AQUA) ;
_a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvZigZagStep[2]->Clone()) ;
m_pGeomDB->SetMaterial( _a, ORANGE) ;
_a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvZigZagStep[3]->Clone()) ;
m_pGeomDB->SetMaterial( _a, ORANGE) ;
#endif
// uniformo la pendenza delle curve
Point3d ptIni, ptFin ;
double dNini, dNfin ;
for ( int i = 0 ; i < 4 ; ++ i) {
vCrvZigZagStep[i]->GetStartPoint( ptIni) ;
vCrvZigZagStep[i]->GetEndPoint( ptFin) ;
dNini = ( ptIni - ORIG) * vtTool ;
dNfin = ( ( ptFin - 0.25 * dStep * vtTool) - ORIG) * vtTool ;
AdjustCurveSlope( vCrvZigZagStep[i], dNini, dNfin) ;
}
#if DEBUG_ZIGZAG_LEADIN
_a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvZigZagStep[0]->Clone()) ;
m_pGeomDB->SetMaterial( _a, BLUE) ;
_a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvZigZagStep[1]->Clone()) ;
m_pGeomDB->SetMaterial( _a, BLUE) ;
_a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvZigZagStep[2]->Clone()) ;
m_pGeomDB->SetMaterial( _a, RED) ;
_a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvZigZagStep[3]->Clone()) ;
m_pGeomDB->SetMaterial( _a, RED) ;
#endif
// uniformo le posizione delle curve
if ( bAtStart)
rotate( vCrvZigZagStep.begin(), vCrvZigZagStep.begin() + 3, vCrvZigZagStep.end()) ;
else if ( bAtEnd)
rotate( vCrvZigZagStep.begin(), vCrvZigZagStep.begin() + 1, vCrvZigZagStep.end()) ;
// calcolo la Feed in base alla pendenza
double dFeed = GetEndFeed() ;
for ( int i = 0 ; i < 4 ; ++ i) {
Point3d ptS ; vCrvZigZagStep[i]->GetStartPoint( ptS) ;
Point3d ptE ; vCrvZigZagStep[i]->GetEndPoint( ptE) ;
Vector3d vtMove = ptE - ptS ;
dFeed = min( dFeed, GetRightStartFeed( vtMove, vtTool)) ;
}
// definisco il percorso a ZigZag ( lo definisco dal basso verso l'alto)
Point3d ptRef = ptCurr ;
PtrOwner<ICurveComposite> pCompoZigZag( CreateCurveComposite()) ;
if ( IsNull( pCompoZigZag) || ! pCompoZigZag->AddPoint( ptRef))
return false ;
for ( int nS = 0 ; nS < nStep ; ++ nS) {
for ( int i = 3 ; i >= 0 ; -- i) {
PtrOwner<ICurveComposite> pCompo( CloneCurveComposite( vCrvZigZagStep[i])) ;
if ( IsNull( pCompo) || ! pCompo->IsValid())
return false ;
Point3d ptEndCurr ; pCompo->GetEndPoint( ptEndCurr) ;
pCompo->Translate( ptRef - ptEndCurr) ;
pCompo->GetStartPoint( ptRef) ;
#if DEBUG_ZIGZAG_LEADIN
_a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompo->Clone()) ;
m_pGeomDB->SetMaterial( _a, GREEN) ;
#endif
if ( ! pCompoZigZag->AddCurve( Release( pCompo), false, TOL))
return false ;
}
}
// verifico che tutto sia andato a buon fine
if ( pCompoZigZag->IsValid()) {
SetFeed( dFeed) ;
return ( AddCurveMove( pCompoZigZag) != GDB_ID_NULL) ;
}
return false ;
}
//----------------------------------------------------------------------------
bool
PocketingNT::CalcDistanceFromRawSurface( int nPhase, const Point3d& ptP, const Vector3d& vtDir,
double& dDist, Vector3d& vtNorm)
{
if ( ! GetElevation( nPhase, ptP, vtDir, dDist, vtNorm))
+6 -4
View File
@@ -33,6 +33,7 @@ struct PathInfoPO {
PtrOwner<ICurveComposite> pCrvPath ; // percorso del centro utensile
PtrOwner<ICurveComposite> pCrvGlideIn ; // curva per LeadIn a guida
PtrOwner<ICurveComposite> pCrvGlideOut ; // curva per LeadOut a guida
PtrOwner<ICurveComposite> pCrvZigZagIn ; // curva per LeadIn a ZigZag ( caso speciale)
PtrOwner<ICurveComposite> pCrvRet ; // curva di ritorno ( per ora solo caso fori)
} ;
// tipo percorso
@@ -136,8 +137,8 @@ class PocketingNT : public Machining
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 dStep, bool bSplitArcs, Point3d& ptPockStart, Point3d& ptPockEnd) ;
double GetRightFeed( const Vector3d& vtMove, const Vector3d& vtTool) ;
double GetRightStartFeed( const Vector3d& vtMove, const Vector3d& vtTool) ;
double GetRightFeed( const Vector3d& vtMove, const Vector3d& vtTool) const ;
double GetRightStartFeed( const Vector3d& vtMove, const Vector3d& vtTool) const ;
bool CutCurveWithLine( ICurveComposite* pCrvA, const ICurveLine* pCrvB) ;
bool ComputePolishingPath( ICurveComposite* pMCrv, ICurveComposite* pRCrv, bool bSplitArcs) ;
bool AddEpicycles( ICurveComposite * pCompo, ICurveComposite * pCrv, ICurveComposite * pCrvBound = nullptr) ;
@@ -159,8 +160,8 @@ class PocketingNT : public Machining
double& dEscapeElev, Vector3d& vtEscape) const ;
bool CalcLeadInStart( Point3d& ptStart, const Vector3d& vtTool, const ICurveComposite* pCrvPath, Point3d& ptP1) ;
bool AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& vtStart, const Vector3d& vtN,
const ISurfFlatRegion* pSfr, const ICurveComposite* pRCrv, bool bAtLeft, bool bSplitArcs,
bool bNoneForced, bool bSkipControl) ;
const ISurfFlatRegion* pSfr, const ICurveComposite* pRCrv, const ICurveComposite* pRZigZag,
bool bAtLeft, bool bSplitArcs, bool bNoneForced, bool bSkipControl) ;
bool AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d& vtN, const ISurfFlatRegion* pSfr,
const ICurveComposite* pRCrv, bool bSplitArcs, bool bNoneForced, Point3d& ptP1) ;
double GetRadiusForStartEndElevation( void) const ;
@@ -174,6 +175,7 @@ class PocketingNT : public Machining
bool VerifyLeadInHelix( const ISurfFlatRegion* pSfr, const Point3d& ptStart, const Point3d& ptCen, double dHelixRad) ;
bool VerifyLeadInZigZag( const ISurfFlatRegion* pSfr, const Point3d& ptStart, const Point3d& ptPa, const Point3d& ptPb) ;
bool VerifyLeadInOutGlide( const ISurfFlatRegion* pSfr, ICurveComposite* pCrvGlide) ;
bool AddSpecialLeadInZigZag( const ICurveComposite* pCompoPath, const Point3d& ptStart, const Vector3d& vtTool, int nStep, double dStep) ;
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_ROOT) ;