diff --git a/AutoNester.cpp b/AutoNester.cpp index 9fffcfa..7ca7942 100644 --- a/AutoNester.cpp +++ b/AutoNester.cpp @@ -19,6 +19,7 @@ #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_restricted_zone.h" #include "/EgtDev/Extern/Optalog/Include/cns_egaltech.h" #include "/EgtDev/Include/SELkLockId.h" @@ -82,6 +83,7 @@ AutoNester::Clear( void) m_pComp = nullptr ; } m_IdSheetInfo.clear() ; + m_IdRzCstrPtr.clear() ; m_IdPartPtr.clear() ; m_dInterpartGap = 0 ; return true ; @@ -199,6 +201,57 @@ AutoNester::AddDefectToSheet( int nSheetId, const PolyArc& Outline) return true ; } +//---------------------------------------------------------------------------- +bool +AutoNester::AddRestrictedZoneToSheet( int nRzConstrId, int nSheetId, const PolyArc& Outline) +{ + if ( m_pOrder == nullptr) + return false ; + // verifico outline + if ( Outline.GetArcNbr() == 0 || ! Outline.IsClosed()) + return false ; + // cerco lo sheet + const auto IterS = m_IdSheetInfo.find( nSheetId) ; + if ( IterS == m_IdSheetInfo.end()) + return false ; + CNS_SheetPtr pSheet = IterS->second.pSheet ; + double dOffsX = IterS->second.dOffsX ; + double dOffsY = IterS->second.dOffsY ; + // cerco il vincolo + CNS_RestrictedZoneConstraintPtr pRzCstr = nullptr ; + const auto IterC = m_IdRzCstrPtr.find( nRzConstrId) ; + if ( IterC == m_IdRzCstrPtr.end()) { + // creo vincolo per zona ristretta + pRzCstr = CNS_CreateRestrictedZoneConstraint( m_pOrder) ; + if ( pRzCstr == nullptr) + return false ; + m_IdRzCstrPtr.emplace( nRzConstrId, pRzCstr) ; + } + else + pRzCstr = IterC->second ; + // aggiungo zona ristretta tramite suo contorno + BBox3d b3Rect ; + if ( Outline.IsRectangleXY( b3Rect)) { + // imposto il rettangolo + Point3d ptMin, ptMax ; + b3Rect.GetMinMax( ptMin, ptMax) ; + CNS_Point CNSPT_Min, CNSPT_Max ; + CNSPT_Min.x = ptMin.x - dOffsX ; + CNSPT_Min.y = ptMin.y - dOffsY ; + CNSPT_Max.x = ptMax.x - dOffsX ; + CNSPT_Max.y = ptMax.y - dOffsY ; + ptMin += Vector3d( -dOffsX, -dOffsY, 0) ; + ptMax += Vector3d( -dOffsX, -dOffsY, 0) ; + CNS_SheetAddBoxRestrictedZone( pRzCstr, pSheet, CNSPT_Min, CNSPT_Max) ; + } + else { + vector vElem ; + GetCNSPath( Outline, -dOffsX, -dOffsY, vElem) ; + CNS_SheetAddRestrictedZone( pRzCstr, pSheet, int( vElem.size()), vElem.data()) ; + } + return true ; +} + //---------------------------------------------------------------------------- bool AutoNester::AddPart( int nPartId, const PolyArc& Outline, bool bCanFlip, bool bCanRotate, double dRotStep, int nPriority, int nCount) @@ -286,6 +339,27 @@ AutoNester::AddToolOutlineToPart( int nPartId, const PolyArc& ToolOutline) return true ; } +//---------------------------------------------------------------------------- +bool +AutoNester::SetRestrictedZoneToPart( int nPartId, int nRzConstrId) +{ + if ( m_pOrder == nullptr) + return false ; + // cerco il pezzo + const auto Iter = m_IdPartPtr.find( nPartId) ; + if ( Iter == m_IdPartPtr.end()) + return false ; + CNS_PartPtr pPart = Iter->second ; + // recupero il vincolo + const auto IterC = m_IdRzCstrPtr.find( nRzConstrId) ; + if ( IterC == m_IdRzCstrPtr.end()) + return false ; + CNS_RestrictedZoneConstraintPtr pRzCstr = IterC->second ; + // imposto il vincolo + CNS_SetZoneRestrictedPart( pRzCstr, pPart) ; + return true ; +} + //---------------------------------------------------------------------------- bool AutoNester::SetInterpartGap( double dGap) diff --git a/AutoNester.h b/AutoNester.h index b48eeb4..cbf0a81 100644 --- a/AutoNester.h +++ b/AutoNester.h @@ -19,6 +19,7 @@ struct CNS_LaunchingOrder ; struct CNS_Computation ; struct CNS_Sheet ; +struct CNS_RestrictedZoneConstraint ; struct CNS_Part ; //---------------------------------------------------------------------------- @@ -31,10 +32,12 @@ class AutoNester : public IAutoNester bool SetStartCorner( int nCorner) override ; bool AddSheet( int nSheetId, const PolyArc& Outline, double dKerf, int nPriority, int nCount, bool* pbIsRect = nullptr) override ; bool AddDefectToSheet( int nSheetId, const PolyArc& Outline) override ; + bool AddRestrictedZoneToSheet( int nRzConstrId, int nSheetId, const PolyArc& Outline) override ; bool AddPart( int nPartId, const PolyArc& Outline, bool bCanFlip, bool bCanRotate, double dRotStep, int nPriority, int nCount) override ; bool AddHoleToPart( int nPartId, const PolyArc& Hole) override ; bool AddAnotherOutlineToPart( int nPartId, const PolyArc& AnotherOutline) override ; bool AddToolOutlineToPart( int nPartId, const PolyArc& ToolOutline) override ; + bool SetRestrictedZoneToPart( int nPartId, int nRzConstrId) override ; bool SetInterpartGap( double dGap) override ; bool SetReportFile( const std::string& sReportFile) override ; bool Compute( bool bMinimizeOnXvsY, int nMaxTime) override ; @@ -57,13 +60,15 @@ class AutoNester : public IAutoNester SheetInfo( CNS_Sheet* pS, double dX, double dY) : pSheet( pS), dOffsX( dX), dOffsY( dY) {} } ; typedef std::unordered_map< int, SheetInfo> IDSHEETINFO_UMAP ; + typedef std::unordered_map< int, CNS_RestrictedZoneConstraint*> IDRZCSTRPTR_UMAP ; typedef std::unordered_map< int, CNS_Part*> IDPARTPTR_UMAP ; private : CNS_LaunchingOrder* m_pOrder ; // ordine di esecuzione per OptaLog CNS_Computation* m_pComp ; // calcolo di ottimizzazione IDSHEETINFO_UMAP m_IdSheetInfo ; // map dei pannelli basato su identificativi - IDPARTPTR_UMAP m_IdPartPtr ; // map dei pannelli basato su identificativi + IDRZCSTRPTR_UMAP m_IdRzCstrPtr ; // map dei vincoli di zone ristrette basato su identificativi + IDPARTPTR_UMAP m_IdPartPtr ; // map dei pezzi basato su identificativi double m_dInterpartGap ; // distanza minima tra i pezzi std::string m_sReportFile ; // file di report dei dati da inviare a Optalog in caso di problemi } ; diff --git a/EgtNesting.rc b/EgtNesting.rc index f026e84..ab6174a 100644 Binary files a/EgtNesting.rc and b/EgtNesting.rc differ