From e2172585891f3942ed2bed65ef8f589a53231b6e Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Wed, 4 Dec 2019 19:45:47 +0000 Subject: [PATCH] EgtExecutor : - a Exe e Lua AutoNestCompute aggiunto flag bMinimizeOnXvsY - aggiunta funzione ExeAutomaticPackParts. --- EXE_Const.h | 2 + EXE_NstAutoNesting.cpp | 4 +- EXE_NstPartNesting.cpp | 138 ++++++++++++++++++++++++++++++++++++----- LUA_Nesting.cpp | 8 ++- 4 files changed, 130 insertions(+), 22 deletions(-) diff --git a/EXE_Const.h b/EXE_Const.h index 2e1863f..c249b5a 100644 --- a/EXE_Const.h +++ b/EXE_Const.h @@ -31,6 +31,7 @@ const std::string NST_PARTREG_LAYER = "Region" ; const std::string NST_PARTREG_ORIG_LAYER = "Region.orig" ; const std::string NST_PARTUPREG_LAYER = "UpReg" ; const std::string NST_PARTDOWNREG_LAYER = "DwnReg" ; +const std::string NST_PART_ROT = "ROT" ; const std::string NST_OUT_LAYER = "OutLoop" ; const std::string NST_OUT_ORIG_LAYER = "OutLoop.orig" ; const std::string NST_IN_LAYER = "InLoop" ; @@ -45,6 +46,7 @@ const std::string NST_KEY_OFFSET2 = "Offset2" ; const std::string NST_KEY_DEPTH2 = "Depth2" ; // Per Sheets (Nesting) +const std::string NST_SHEET_KERF = "Kerf" ; const std::string NST_SHEET_OUTREG = "SheetOut" ; const std::string NST_REFERENCE_REG = "RefReg" ; const std::string NST_DAMAGED_REG = "DmgReg" ; diff --git a/EXE_NstAutoNesting.cpp b/EXE_NstAutoNesting.cpp index a36db09..86d1911 100644 --- a/EXE_NstAutoNesting.cpp +++ b/EXE_NstAutoNesting.cpp @@ -164,11 +164,11 @@ ExeAutoNestSetInterpartGap( double dGap) //----------------------------------------------------------------------------- bool -ExeAutoNestCompute( int nMaxTime) +ExeAutoNestCompute( bool bMinimizeOnXvsY, int nMaxTime) { if ( IsNull( s_pAutoNester)) return false ; - return s_pAutoNester->Compute( nMaxTime) ; + return s_pAutoNester->Compute( bMinimizeOnXvsY, nMaxTime) ; } //----------------------------------------------------------------------------- diff --git a/EXE_NstPartNesting.cpp b/EXE_NstPartNesting.cpp index 137f129..2d90873 100644 --- a/EXE_NstPartNesting.cpp +++ b/EXE_NstPartNesting.cpp @@ -47,6 +47,7 @@ struct SCollInfoEx : public SCollInfo //---------------------------------------------------------------------------- static const double SPESS = 100 ; +static const int BBF_PART_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; //---------------------------------------------------------------------------- static bool MyMovePartCluster( IGeomDB* pGeomDB, const INTVECTOR& vTrueIds, BBox3d b3Cluster, bool bReducedCut, Vector3d& vtMove) ; @@ -57,8 +58,6 @@ AdjustClusterObjIds( IGeomDB* pGeomDB, const INTVECTOR& vIds, INTVECTOR& vTrueId { if ( pGeomDB == nullptr) return false ; - // Flag per calcolo box - const int BBF_PART_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; // Risolvo eventuali riferimenti a oggetti selezionati vTrueIds.clear() ; vTrueIds.reserve( vIds.size()) ; @@ -536,7 +535,6 @@ TrimLine::Init( IGeomDB* pGeomDB, const INTVECTOR& vTrueIds, bool bReducedCut) nId = pGeomDB->GetNextName( nId, NST_DAMAGED_REG) ; } // Determino le regioni di tutti gli altri pezzi compresi nella regione di interesse - const int BBF_PART_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; int nId2 = ( bInRoot ? ExeGetFirstPart( true) : ExeGetFirstGroupInGroup( nGroupId)) ; while ( nId2 != GDB_ID_NULL) { if ( find( vTrueIds.begin(), vTrueIds.end(), nId2) == vTrueIds.end()) { @@ -669,9 +667,6 @@ TrimLine::TrimLineWithRegion( const ICurveLine* pLine, int nRegId, bool bOn, Int static bool MyVerifyPartCluster( IGeomDB* pGeomDB, const INTVECTOR& vTrueIds, const BBox3d& b3Cluster, bool bReducedCut) { - // Flag per calcolo box - const int BBF_PART_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; - // Determino le regioni dei pezzi INTVECTOR vReg ; INTVECTOR vUpReg ; @@ -897,8 +892,6 @@ MyPackPartCluster( const INTVECTOR& vTrueIds, bool bReducedCut, // Box della regione di interesse BBox3d b3Region( dXmin, dYmin, 0, dXmax, dYmax, 0) ; - // Flag per calcolo box - const int BBF_PART_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; // Determino tutti gli altri pezzi compresi nella regione di interesse INTVECTOR vOtherIds ; @@ -1021,9 +1014,6 @@ ExePackPartCluster( const INTVECTOR& vIds, bool bReducedCut, bool bBottomUp) if ( b3Box.IsEmpty()) return false ; - // Flag per calcolo box dei pezzi - const int BBF_PART_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; - // Calcolo il box di ingombro delle regioni dei pezzi BBox3d b3RegCluster ; for ( int nId : vTrueIds) { @@ -1230,9 +1220,6 @@ MyMovePartCluster( IGeomDB* pGeomDB, const INTVECTOR& vTrueIds, BBox3d b3Cluster if ( vtMoveXY.IsSmall()) return true ; - // Flag per calcolo box pezzi - const int BBF_PART_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; - // Verifico se pezzi sotto la radice o pezzi in altro gruppo int nGroupId = pGeomDB->GetParentId( vTrueIds[0]) ; bool bInRoot = ( nGroupId == GDB_ID_ROOT) ; @@ -1497,9 +1484,6 @@ MyRotatePartCluster( IGeomDB* pGeomDB, const INTVECTOR& vTrueIds, BBox3d& b3Clus // Rotazione nel piano XY globale - // Flag per calcolo box - const int BBF_PART_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; - // Verifico se pezzi sotto la radice o pezzi in altro gruppo int nGroupId = pGeomDB->GetParentId( vTrueIds[0]) ; bool bInRoot = ( nGroupId == GDB_ID_ROOT) ; @@ -2072,3 +2056,123 @@ ExeGetPartClusterCenterGlob( const INTVECTOR& vIds, Point3d& ptCen) return true ; } + +//---------------------------------------------------------------------------- +bool +ExeAutomaticPackParts( INTVECTOR& vIds, bool bMinimizeOnXvsY, bool bReducedCut, int nMaxTime) +{ + // Dichiaro tutti i pezzi non nestati + for ( int i = 0 ; i < int( vIds.size()) ; ++ i) + vIds[i] = - vIds[i] ; + + // Verifico gestore DB geometrico + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + + // Verifico pezzi e determino se sotto la radice o in altro gruppo + int nGroupId = pGeomDB->GetParentId( ( vIds.size() > 0 ? abs( vIds[0]) : GDB_ID_NULL)) ; + if ( nGroupId == GDB_ID_NULL) + return false ; + bool bInRoot = ( nGroupId == GDB_ID_ROOT) ; + + // Avvio nesting automatico + ExeAutoNestStart() ; + + // Definisco un solo pannello + int nSheetId = 1 ; + // Assegno il contorno del pannello ( parte utile) + int nKerfId = pGeomDB->GetFirstNameInGroup( nGroupId, NST_SHEET_KERF) ; + if ( nKerfId == GDB_ID_NULL) + return false ; + ExeAutoNestAddSheet( nSheetId, nKerfId, 0.0, 0, 1) ; + // Recupero la regione di riferimento e verifico se disabilitata + int nRefReg = pGeomDB->GetFirstNameInGroup( nGroupId, NST_REFERENCE_REG) ; + if ( ! pGeomDB->ExistsInfo( nRefReg, KEY_NST_OFF)) + ExeAutoNestAddDefectToSheet( nSheetId, nRefReg) ; + // Recupero le aree danneggiate + int nDamId = pGeomDB->GetFirstNameInGroup( nGroupId, NST_DAMAGED_REG) ; + while ( nDamId != GDB_ID_NULL) { + ExeAutoNestAddDefectToSheet( nSheetId, nDamId) ; + nDamId = pGeomDB->GetNextName( nDamId, NST_DAMAGED_REG) ; + } + + // Assegno le aree occupate dai pezzi già nestati + BBox3d b3Sheet ; + pGeomDB->GetGlobalBBox( nRefReg, b3Sheet) ; + int nId = ( bInRoot ? ExeGetFirstPart( true) : ExeGetFirstGroupInGroup( nGroupId)) ; + while ( nId != GDB_ID_NULL) { + // se pezzo non nell'elenco + if ( find( vIds.begin(), vIds.end(), -nId) == vIds.end()) { + BBox3d b3Part ; + if ( pGeomDB->GetGlobalBBox( nId, b3Part, BBF_PART_MY_FLAG) && + b3Sheet.OverlapsXY( b3Part)) { + // recupero regione del pezzo + int nRegId = GetFlatPartRegion( pGeomDB, nId) ; + ExeAutoNestAddDefectToSheet( nSheetId, nRegId) ; + // recupero regioni dei tagli del pezzo + INTVECTOR vCutReg ; + if ( GetFlatPartCutRegions( pGeomDB, nId, bReducedCut, vCutReg)) { + for ( int nRegId : vCutReg) + ExeAutoNestAddDefectToSheet( nSheetId, nRegId) ; + } + } + } + nId = ( bInRoot ? ExeGetNextPart( nId, true) : ExeGetNextGroup( nId)) ; + } + + // Assegno i pezzi da nestare + for ( int nPartId : vIds) { + nPartId = abs( nPartId) ; + // recupero regione del pezzo e flag rotazione abilitata + int nRegId = GetFlatPartRegion( pGeomDB, nPartId) ; + bool bEnableRot = ! pGeomDB->ExistsInfo( nPartId, NST_PART_ROT) ; + ExeAutoNestAddPart( nPartId, nRegId, false, bEnableRot, 0.0, 0, 1) ; + // recupero regioni dei tagli del pezzo + INTVECTOR vCutReg ; + if ( GetFlatPartCutRegions( pGeomDB, nPartId, bReducedCut, vCutReg)) { + for ( int nRegId : vCutReg) + ExeAutoNestAddToolOutlineToPart( nPartId, nRegId) ; + } + } + + // Eseguo il nesting + ExeAutoNestCompute( bMinimizeOnXvsY, nMaxTime) ; + bool bOk = true ; + int nTime = 0 ; + while ( bOk) { + int nStat ; + bOk = ExeAutoNestGetComputationStatus( nStat) ; + if ( nStat == 2 || nStat == 3) { + // eventuale raccolta dati e visualizzazione dinamica + } + if ( nStat == 3) + break ; + nTime += 1 ; + if ( ExeProcessEvents( nTime / nMaxTime * 100, 995) == 1) { + bOk = ExeAutoNestCancelComputation() ; + break ; + } + } + + // Recupero i risultati + int nNestedParts, nParts, nSheets, nNestings ; double dTotFillRatio ; + if ( ! ExeAutoNestGetResults( nNestedParts, nParts, nSheets, nNestings, dTotFillRatio)) + return false ; + for ( int j = 0 ; ; ++ j) { + int nType, nId, nFlag ; double dX, dY, dAngRot ; + if ( ! ExeAutoNestGetOneResult( j, nType, nId, nFlag, dX, dY, dAngRot)) + break ; + if ( nType == 0) { + // flip su Y escluso, si fanno rotazione e spostamento + pGeomDB->RotateGlob( nId, ORIG, Z_AX, dAngRot) ; + pGeomDB->TranslateGlob( nId, Vector3d( dX, dY, 0)) ; + // segnalo che pezzo nestato + for ( int i = 0 ; i < int( vIds.size()) ; ++ i) { + if ( vIds[i] == - nId) + vIds[i] = nId ; + } + } + } + + return true ; +} diff --git a/LUA_Nesting.cpp b/LUA_Nesting.cpp index 95b2c49..0616da7 100644 --- a/LUA_Nesting.cpp +++ b/LUA_Nesting.cpp @@ -206,12 +206,14 @@ LuaAutoNestSetInterpartGap( lua_State* L) static int LuaAutoNestCompute( lua_State* L) { - // 1 parametro : nMaxTime (ms) + // 2 parametro : bMinimizeOnXvsY nMaxTime (ms) + bool bMinimizeOnXvsY ; + LuaCheckParam( L, 1, bMinimizeOnXvsY) int nMaxTime ; - LuaCheckParam( L, 1, nMaxTime) + LuaCheckParam( L, 2, nMaxTime) LuaClearStack( L) ; // lancio calcolo del nesting - bool bOk = ExeAutoNestCompute( nMaxTime) ; + bool bOk = ExeAutoNestCompute( bMinimizeOnXvsY, nMaxTime) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ;