//---------------------------------------------------------------------------- // EgalTech 2019-2019 //---------------------------------------------------------------------------- // File : EXE_NstAutoNesting.cpp Data : 28.11.19 Versione : 2.1k6 // Contenuto : Funzioni Automatic Nesting per EXE. // // // // Modifiche : 28.11.19 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" #include "EXE_Macro.h" #include "EXE_Const.h" #include "DllNesting.h" #include "/EgtDev/Include/EGkCurve.h" #include "/EgtDev/Include/EGkCurveComposite.h" #include "/EgtDev/Include/EGkOffsetCurve.h" #include "/EgtDev/Include/EGkSurfFlatRegion.h" #include "/EgtDev/Include/ENsAutoNester.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EgtPointerOwner.h" #include "/EgtDev/Include/SELkLockId.h" using namespace std ; //----------------------------------------------------------------------------- static PtrOwner s_pAutoNester ; static int s_nTotParts ; static double s_dTotFillRatio ; static ANIVECT s_vANestInfo ; //----------------------------------------------------------------------------- bool ExeAutoNestStart( void) { s_nTotParts = 0 ; s_dTotFillRatio = 0 ; if ( IsNull( s_pAutoNester)) { s_pAutoNester.Set( MyCreateAutoNester()) ; if ( IsNull( s_pAutoNester)) return false ; } return s_pAutoNester->Start() ; } //----------------------------------------------------------------------------- bool ExeAutoNestAddSheet( int nSheetId, int nOutlineId, double dKerf, int nPriority, int nCount) { if ( IsNull( s_pAutoNester)) return false ; IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // recupero riferimento dell'Outline Frame3d frOutl ; if ( ! pGeomDB->GetGlobFrame( nOutlineId, frOutl)) return false ; // recupero il tipo di oggetto int nType = pGeomDB->GetGeoType( nOutlineId) ; PolyArc Outline ; // recupero la curva di contorno if ( ( nType & GEO_CURVE) != 0) { const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nOutlineId)) ; if ( pCrv == nullptr || ! pCrv->ApproxWithArcs( LIN_TOL_FINE, ANG_TOL_STD_DEG, Outline)) return false ; } else if ( nType == SRF_FLATRGN) { const ISurfFlatRegion* pSfr = GetSurfFlatRegion( pGeomDB->GetGeoObj( nOutlineId)) ; if ( pSfr == nullptr) return false ; PtrOwner pCrv( pSfr->GetLoop( 0, 0)) ; if ( IsNull( pCrv) || ! pCrv->ApproxWithArcs( LIN_TOL_FINE, ANG_TOL_STD_DEG, Outline)) return false ; } // la porto in globale Outline.ToGlob( frOutl) ; // verifico direzione di estrusione Vector3d vtExtr = Outline.GetExtrusion() ; if ( vtExtr.IsZplus()) ; else if ( vtExtr.IsZminus()) Outline.Mirror( ORIG, Z_AX) ; else return false ; // se richiesto kerf ( sempre nullo o positivo) if ( dKerf > 10 * EPS_SMALL) { // curva di contorno PtrOwner pCompo( CreateCurveComposite()) ; if ( IsNull( pCompo) || ! pCompo->FromPolyArc( Outline)) return false ; // verifico sia CCW double dArea ; pCompo->GetAreaXY( dArea) ; if ( dArea < 0) pCompo->Invert() ; // eseguo offset OffsetCurve OffsCrv ; if ( ! OffsCrv.Make( pCompo, - dKerf, ICurve::OFF_FILLET)) return false ; PtrOwner pOffs( OffsCrv.GetLongerCurve()) ; // riassegno a PolyArc if ( IsNull( pOffs) || ! pOffs->ApproxWithArcs( LIN_TOL_FINE, ANG_TOL_STD_DEG, Outline)) return false ; } // aggiungo il pannello return s_pAutoNester->AddSheet( nSheetId, Outline, nPriority, nCount) ; } //----------------------------------------------------------------------------- bool ExeAutoNestAddPart( int nPartId, int nOutlineId, bool bCanFlip, bool bCanRotate, int nPriority, int nCount) { if ( IsNull( s_pAutoNester)) return false ; IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // recupero riferimento dell'Outline Frame3d frOutl ; if ( ! pGeomDB->GetGlobFrame( nOutlineId, frOutl)) return false ; // recupero il tipo di oggetto int nType = pGeomDB->GetGeoType( nOutlineId) ; PolyArc Outline ; // recupero la curva di contorno if ( ( nType & GEO_CURVE) != 0) { const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nOutlineId)) ; if ( pCrv == nullptr || ! pCrv->ApproxWithArcs( LIN_TOL_FINE, ANG_TOL_STD_DEG, Outline)) return false ; } else if ( nType == SRF_FLATRGN) { const ISurfFlatRegion* pSfr = GetSurfFlatRegion( pGeomDB->GetGeoObj( nOutlineId)) ; if ( pSfr == nullptr) return false ; PtrOwner pCrv( pSfr->GetLoop( 0, 0)) ; if ( IsNull( pCrv) || ! pCrv->ApproxWithArcs( LIN_TOL_FINE, ANG_TOL_STD_DEG, Outline)) return false ; } // la porto in globale Outline.ToGlob( frOutl) ; // verifico direzione di estrusione Vector3d vtExtr = Outline.GetExtrusion() ; if ( vtExtr.IsZplus()) ; else if ( vtExtr.IsZminus()) Outline.Mirror( ORIG, Z_AX) ; else return false ; // aggiungo il pezzo if ( ! s_pAutoNester->AddPart( nPartId, Outline, bCanFlip, bCanRotate, nPriority, nCount)) return false ; // incremento contatore pezzi s_nTotParts += nCount ; return true ; } //----------------------------------------------------------------------------- bool ExeAutoNestSetInterpartGap( double dGap) { if ( IsNull( s_pAutoNester)) return false ; return s_pAutoNester->SetInterpartGap( dGap) ; } //----------------------------------------------------------------------------- bool ExeAutoNestCompute( int nMaxTime) { if ( IsNull( s_pAutoNester)) return false ; return s_pAutoNester->Compute( nMaxTime) ; } //----------------------------------------------------------------------------- bool ExeAutoNestCancelComputation( void) { if ( IsNull( s_pAutoNester)) return false ; return s_pAutoNester->CancelComputation() ; } //----------------------------------------------------------------------------- bool ExeAutoNestGetComputationStatus( int& nStatus) { if ( IsNull( s_pAutoNester)) return false ; return s_pAutoNester->GetComputationStatus( nStatus) ; } //----------------------------------------------------------------------------- bool ExeAutoNestPrintResults( const string& sHtmlFile) { if ( IsNull( s_pAutoNester)) return false ; return s_pAutoNester->PrintResults( sHtmlFile) ; } //----------------------------------------------------------------------------- bool ExeAutoNestGetResults( int& nNestedParts, int& nParts, int& nSheets, int& nNestings, double& dTotFillRatio) { if ( IsNull( s_pAutoNester) || ! s_pAutoNester->GetResults( s_dTotFillRatio, s_vANestInfo)) return false ; nNestedParts = 0 ; nParts = s_nTotParts ; nSheets = 0 ; nNestings = 0 ; dTotFillRatio = s_dTotFillRatio ; for ( int i = 0 ; i < int( s_vANestInfo.size()) ; ++ i) { // se sheet if ( s_vANestInfo[i].nType > 0) { ++ nNestings ; nSheets += s_vANestInfo[i].nType ; nNestedParts += s_vANestInfo[i].nFlag * s_vANestInfo[i].nType ; } } return true ; } //----------------------------------------------------------------------------- bool ExeAutoNestGetOneResult( int nInd, int& nType, int& nId, int& nFlag, double& dX, double& dY, double& dAngRot) { if ( nInd < 0 || nInd >= int( s_vANestInfo.size())) return false ; nType = s_vANestInfo[nInd].nType ; nId = s_vANestInfo[nInd].nId ; nFlag = s_vANestInfo[nInd].nFlag ; dX = s_vANestInfo[nInd].dX ; dY = s_vANestInfo[nInd].dY ; dAngRot = s_vANestInfo[nInd].dAngRot ; return true ; }