//---------------------------------------------------------------------------- // 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/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, 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 return s_pAutoNester->AddSheet( nSheetId, Outline, nPriority, nCount) ; } //----------------------------------------------------------------------------- bool ExeAutoNestAddPart( int nPartId, int nOutlineId, 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, 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 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& nTotParts, int& nTotSheets, int& nDiffSheets, double& dTotFillRatio) { if ( IsNull( s_pAutoNester) || ! s_pAutoNester->GetResults( s_dTotFillRatio, s_vANestInfo)) return false ; nNestedParts = 0 ; nTotParts = s_nTotParts ; nTotSheets = 0 ; nDiffSheets = 0 ; dTotFillRatio = s_dTotFillRatio ; for ( int i = 0 ; i < int( s_vANestInfo.size()) ; ++ i) { // se sheet if ( s_vANestInfo[i].nType > 0) { ++ nDiffSheets ; nTotSheets += 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 ; }