EgtExecutor :

- a Exe e Lua AutoNestCompute aggiunto flag bMinimizeOnXvsY
- aggiunta funzione ExeAutomaticPackParts.
This commit is contained in:
Dario Sassi
2019-12-04 19:45:47 +00:00
parent bcfa87b700
commit e217258589
4 changed files with 130 additions and 22 deletions
+121 -17
View File
@@ -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 ;
}