diff --git a/EXE_GdbModifyCurve.cpp b/EXE_GdbModifyCurve.cpp index 6f64eeb..242e25f 100644 --- a/EXE_GdbModifyCurve.cpp +++ b/EXE_GdbModifyCurve.cpp @@ -1013,6 +1013,23 @@ ExeModifyCurveCompoJoint( int nId, int nU, const Point3d& ptP, int nRefType) return bOk ; } +//------------------------------------------------------------------------------- +int +ExeGetCurveCompoJointCount( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, 0) + // recupero la curva composita + ICurveComposite* pCompo = GetCurveComposite( pGeomDB->GetGeoObj( nId)) ; + if ( pCompo == nullptr) + return 0 ; + // calcolo il numero di giunzioni (se chiusa è uguale al numero delle curve altrimenti -1) + if ( pCompo->IsClosed()) + return pCompo->GetCurveCount() ; + else + return ( pCompo->GetCurveCount() - 1) ; +} + //------------------------------------------------------------------------------- bool ExeRemoveCurveCompoJoint( int nId, int nU) diff --git a/EXE_NstPartNesting.cpp b/EXE_NstPartNesting.cpp index 1097656..c9e6833 100644 --- a/EXE_NstPartNesting.cpp +++ b/EXE_NstPartNesting.cpp @@ -57,7 +57,7 @@ AdjustClusterObjIds( IGeomDB* pGeomDB, const INTVECTOR& vIds, INTVECTOR& vTrueId if ( pGeomDB == nullptr) return false ; // Flag per calcolo box - const int BBF_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; + 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()) ; @@ -66,7 +66,7 @@ AdjustClusterObjIds( IGeomDB* pGeomDB, const INTVECTOR& vIds, INTVECTOR& vTrueId int nTrueId = (( nId != GDB_ID_SEL) ? nId : pGeomDB->GetFirstSelectedObj()) ; while ( nTrueId != GDB_ID_NULL) { BBox3d b3Part ; - if ( pGeomDB->GetGlobalBBox( nTrueId, b3Part, BBF_MY_FLAG)) { + if ( pGeomDB->GetGlobalBBox( nTrueId, b3Part, BBF_PART_MY_FLAG)) { // inserisco l'identificativo nel vettore dei validi vTrueIds.push_back( nTrueId) ; // aggiorno il box del cluster @@ -277,7 +277,7 @@ static bool MyVerifyPartCluster( IGeomDB* pGeomDB, const INTVECTOR& vTrueIds, const BBox3d& b3Cluster, bool bReducedCut) { // Flag per calcolo box - const int BBF_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; + const int BBF_PART_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; // Determino le regioni dei pezzi INTVECTOR vReg ; @@ -287,7 +287,7 @@ MyVerifyPartCluster( IGeomDB* pGeomDB, const INTVECTOR& vTrueIds, const BBox3d& // recupero regione del pezzo int nRegId = GetFlatPartRegion( pGeomDB, nId) ; BBox3d b3Reg ; - if ( pGeomDB->GetGlobalBBox( nRegId, b3Reg, BBF_MY_FLAG)) { + if ( pGeomDB->GetGlobalBBox( nRegId, b3Reg, BBF_PART_MY_FLAG)) { vReg.emplace_back( nRegId) ; b3RegCluster.Add( b3Reg) ; } @@ -323,7 +323,7 @@ MyVerifyPartCluster( IGeomDB* pGeomDB, const INTVECTOR& vTrueIds, const BBox3d& while ( nId2 != GDB_ID_NULL) { if ( find( vTrueIds.begin(), vTrueIds.end(), nId2) == vTrueIds.end()) { BBox3d b3Part2 ; - if ( pGeomDB->GetGlobalBBox( nId2, b3Part2, BBF_MY_FLAG) && + if ( pGeomDB->GetGlobalBBox( nId2, b3Part2, BBF_PART_MY_FLAG) && b3Cluster.OverlapsXY( b3Part2)) { // recupero regione del pezzo int nRegId = GetFlatPartRegion( pGeomDB, nId2) ; @@ -398,7 +398,7 @@ 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_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; + 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 ; @@ -406,7 +406,7 @@ MyPackPartCluster( const INTVECTOR& vTrueIds, bool bReducedCut, while ( nId2 != GDB_ID_NULL) { if ( find( vTrueIds.begin(), vTrueIds.end(), nId2) == vTrueIds.end()) { BBox3d b3Part2 ; - if ( pGeomDB->GetGlobalBBox( nId2, b3Part2, BBF_MY_FLAG) && + if ( pGeomDB->GetGlobalBBox( nId2, b3Part2, BBF_PART_MY_FLAG) && b3Region.OverlapsXY( b3Part2)) { vOtherIds.emplace_back( nId2) ; } @@ -515,10 +515,29 @@ ExePackPartCluster( const INTVECTOR& vIds, bool bReducedCut, bool bBottomUp) return false ; b3Box.Expand( - SPESS, - SPESS, 0) ; + // Flag per calcolo box + 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) { + // recupero regione del pezzo + int nRegId = GetFlatPartRegion( pGeomDB, nId) ; + BBox3d b3Reg ; + if ( pGeomDB->GetGlobalBBox( nRegId, b3Reg, BBF_PART_MY_FLAG)) { + b3RegCluster.Add( b3Reg) ; + } + else + return false ; + } + double dRegClDimX = b3RegCluster.GetMax().x - b3RegCluster.GetMin().x ; + double dRegClDimY = b3RegCluster.GetMax().y - b3RegCluster.GetMin().y ; + // Procedo per tentativi + const double STEP = 50 ; bool bFit = false ; Point3d ptOrig = b3Cluster.GetMin() ; - Point3d ptLineStart = b3Box.GetMin() ; + Point3d ptLineStart = ( bBottomUp ? b3Box.GetMin() : b3Box.GetMax() - Vector3d(0, -dRegClDimY, 0)) ; Point3d ptIns = ptLineStart ; while ( true) { // porto nella posizione di prova @@ -533,11 +552,11 @@ ExePackPartCluster( const INTVECTOR& vIds, bool bReducedCut, bool bBottomUp) break ; } // nuova posizione di inserimento (incrementando X) - ptIns += Vector3d( 50, 0, 0) ; + ptIns += Vector3d( STEP, 0, 0) ; // se esco dal box torno all'inizio e incremento Y - if ( ! b3Box.EnclosesXY( ptIns)) { - ptLineStart += Vector3d( 0, 50, 0) ; - if ( ( ! b3Box.EnclosesXY( ptLineStart))) + if ( ! b3Box.EnclosesXY( ptIns + Vector3d( dRegClDimX, 0, 0))) { + ptLineStart += Vector3d( 0, ( bBottomUp ? STEP : - STEP), 0) ; + if ( ( ! b3Box.EnclosesXY( ptLineStart + Vector3d( 0, dRegClDimY, 0)))) break ; ptIns = ptLineStart ; } @@ -651,8 +670,8 @@ MyMovePartCluster( IGeomDB* pGeomDB, const INTVECTOR& vTrueIds, BBox3d b3Cluster if ( vtMoveXY.IsSmall()) return true ; - // Flag per calcolo box - const int BBF_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; + // 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]) ; @@ -671,7 +690,7 @@ MyMovePartCluster( IGeomDB* pGeomDB, const INTVECTOR& vTrueIds, BBox3d b3Cluster while ( nId2 != GDB_ID_NULL) { if ( find( vTrueIds.begin(), vTrueIds.end(), nId2) == vTrueIds.end()) { BBox3d b3Part2 ; - if ( pGeomDB->GetGlobalBBox( nId2, b3Part2, BBF_MY_FLAG) && + if ( pGeomDB->GetGlobalBBox( nId2, b3Part2, BBF_PART_MY_FLAG) && b3Region.OverlapsXY( b3Part2)) { // recupero regione del pezzo int nRegId = GetFlatPartRegion( pGeomDB, nId2) ; @@ -821,7 +840,7 @@ MyRotatePartCluster( IGeomDB* pGeomDB, const INTVECTOR& vTrueIds, BBox3d& b3Clus // Rotazione nel piano XY globale // Flag per calcolo box - const int BBF_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ; + 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]) ; @@ -840,7 +859,7 @@ MyRotatePartCluster( IGeomDB* pGeomDB, const INTVECTOR& vTrueIds, BBox3d& b3Clus while ( nId2 != GDB_ID_NULL) { if ( find( vTrueIds.begin(), vTrueIds.end(), nId2) == vTrueIds.end()) { BBox3d b3Part2 ; - if ( pGeomDB->GetGlobalBBox( nId2, b3Part2, BBF_MY_FLAG) && + if ( pGeomDB->GetGlobalBBox( nId2, b3Part2, BBF_PART_MY_FLAG) && b3Region.OverlapsXY( b3Part2)) { // recupero regione del pezzo int nRegId = GetFlatPartRegion( pGeomDB, nId2) ; @@ -990,6 +1009,8 @@ ExeAlignPartClusterOnCollision( const INTVECTOR& vIds, bool bReducedCut, bool& b double dU ; if ( ! pCrv->GetParamAtPoint( ptCntL, dU, 10 * EPS_SMALL)) return false ; + if ( fabs( dU - round( dU)) < 100 * EPS_PARAM) + dU = round( dU) ; Point3d ptPp ; Vector3d vtTp ; if ( ! pCrv->GetPointTang( dU, ICurve::FROM_MINUS, ptPp, vtTp))