diff --git a/AutoNester.cpp b/AutoNester.cpp index dc03626..05f6a66 100644 --- a/AutoNester.cpp +++ b/AutoNester.cpp @@ -18,6 +18,7 @@ #include "/EgtDev/Include/ENsDllMain.h" #include "/EgtDev/Include/EGkPolyArc.h" #include "/EgtDev/Extern/Optalog/Include/cns.h" +#include "/EgtDev/Extern/Optalog/Include/cns_tooling.h" #include "/EgtDev/Extern/Optalog/Include/cns_egaltech.h" #include "/EgtDev/Include/SELkLockId.h" @@ -34,6 +35,24 @@ CreateAutoNester( void) return static_cast ( new(nothrow) AutoNester) ; } +//---------------------------------------------------------------------------- +static void +GetCNSPath( const PolyArc& Outline, vector& vElem) +{ + // converto nel formato Optalog + int nElem = Outline.GetPointNbr() ; + if ( Outline.IsClosed()) + -- nElem ; + vElem.reserve( nElem) ; + Point3d ptIni, ptFin ; double dBulge ; + bool bNext = Outline.GetFirstArc( ptIni, ptFin, dBulge) ; + while ( bNext) { + double dLeftDeflection = - dBulge * DistXY( ptIni, ptFin) / 2 ; + vElem.push_back( { ptFin.x, ptFin.y, dLeftDeflection}) ; + bNext = Outline.GetNextArc( ptIni, ptFin, dBulge) ; + } +} + //---------------------------------------------------------------------------- // AutoNester //---------------------------------------------------------------------------- @@ -76,55 +95,49 @@ AutoNester::Start( void) //---------------------------------------------------------------------------- bool -AutoNester::AddSheet( int nSheetId, const PolyArc& Outline, int nPriority, int nCount) +AutoNester::AddSheet( int nSheetId, const PolyArc& Outline, double dKerf, int nPriority, int nCount) { if ( m_pOrder == nullptr) return false ; if ( ! Outline.IsClosed()) return false ; - // contorno nel formato Optalog - const int nElem = Outline.GetPointNbr() - 1 ; - vector vElem ; vElem.reserve( nElem) ; - Point3d ptIni, ptFin ; double dBulge ; - bool bNext = Outline.GetFirstArc( ptIni, ptFin, dBulge) ; - while ( bNext) { - double dLeftDeflection = - dBulge * DistXY( ptIni, ptFin) / 2 ; - vElem.push_back( { ptFin.x, ptFin.y, dLeftDeflection}) ; - bNext = Outline.GetNextArc( ptIni, ptFin, dBulge) ; - } - // aggiungo + // aggiungo contorno + vector vElem ; + GetCNSPath( Outline, vElem) ; CNS_SheetPtr pSheet = CNS_AddNonRectangularSheet( m_pOrder, nCount, int( vElem.size()), vElem.data()) ; if ( pSheet == nullptr) return false ; + // imposto altri dati CNS_SetSheetUserString( pSheet, ToString( nSheetId).c_str()) ; CNS_SetSheetPriority( pSheet, nPriority) ; + CNS_SetNonRectangularSheetGaps( pSheet, dKerf, dKerf, dKerf, dKerf, dKerf) ; return true ; } //---------------------------------------------------------------------------- bool -AutoNester::AddPart( int nPartId, const PolyArc& Outline, bool bCanFlip, bool bCanRotate, int nPriority, int nCount) +AutoNester::AddPart( int nPartId, const PolyArc& Outline, const PolyArc& ToolOutline, + bool bCanFlip, bool bCanRotate, double dRotStep, int nPriority, int nCount) { if ( m_pOrder == nullptr) return false ; - if ( ! Outline.IsClosed()) + if ( Outline.GetArcNbr() == 0 || ! Outline.IsClosed()) return false ; - // contorno nel formato Optalog - const int nElem = Outline.GetPointNbr() - 1 ; - vector vElem ; vElem.reserve( nElem) ; - Point3d ptIni, ptFin ; double dBulge ; - bool bNext = Outline.GetFirstArc( ptIni, ptFin, dBulge) ; - while ( bNext) { - double dLeftDeflection = - dBulge * DistXY( ptIni, ptFin) / 2 ; - vElem.push_back( { ptFin.x, ptFin.y, dLeftDeflection}) ; - bNext = Outline.GetNextArc( ptIni, ptFin, dBulge) ; - } - // aggiungo + // aggiungo contorno + vector vElem ; + GetCNSPath( Outline, vElem) ; CNS_PartPtr pPart = CNS_AddPart( m_pOrder, nCount, int( vElem.size()), vElem.data()) ; if ( pPart == nullptr) return false ; + // eventuale contorno esterno del percorso utensili + if ( ToolOutline.GetArcNbr() > 0 && ToolOutline.IsClosed()) { + vector vTOl ; + GetCNSPath( ToolOutline, vTOl) ; + CNS_AddToolPathToPart( pPart, int( vTOl.size()), vTOl.data()) ; + } + // altri dati CNS_SetPartUserString( pPart, ToString( nPartId).c_str()) ; - CNS_SetPartAuthorizations( pPart, ( bCanFlip ? 1 : 0), ( bCanRotate ? 1 : 0), 0) ; + CNS_SetPartAuthorizations( pPart, ( bCanFlip ? 1 : 0), ( bCanRotate ? 1 : 0), dRotStep) ; CNS_SetPartPriority( pPart, nPriority) ; return true ; } @@ -155,7 +168,7 @@ AutoNester::Compute( int nMaxTime) // passo i codici al nester CNS_UnLockLaunchingOrderOxy( m_pOrder, sKeyId.c_str(), sKeySign.c_str()) ; // lancio l'esecuzione - m_pComp = CNS_LaunchLocalComputation( m_pOrder, nMaxTime / 1000.) ; + m_pComp = CNS_LaunchLocalComputation( m_pOrder, nMaxTime) ; return ( m_pComp != nullptr) ; } diff --git a/AutoNester.h b/AutoNester.h index 55d7162..46589fa 100644 --- a/AutoNester.h +++ b/AutoNester.h @@ -24,8 +24,9 @@ class AutoNester : public IAutoNester public : ~AutoNester( void) override ; bool Start( void) override ; - bool AddSheet( int nSheetId, const PolyArc& Outline, int nPriority, int nCount) override ; - bool AddPart( int nPartId, const PolyArc& Outline, bool bCanFlip, bool bCanRotate, int nPriority, int nCount) override ; + bool AddSheet( int nSheetId, const PolyArc& Outline, double dKerf, int nPriority, int nCount) override ; + bool AddPart( int nPartId, const PolyArc& Outline, const PolyArc& ToolOutline, + bool bCanFlip, bool bCanRotate, double dRotStep, int nPriority, int nCount) override ; bool SetInterpartGap( double dGap) override ; bool Compute( int nMaxTime) override ; bool CancelComputation( void) override ;