EgtExecutor 1.6o1 :

- in nesting aggiunta verifica interferenza con atgli inclinati.
This commit is contained in:
Dario Sassi
2016-03-12 18:21:54 +00:00
parent 2e254607d5
commit 4dfc24345f
6 changed files with 486 additions and 16 deletions
+247
View File
@@ -735,6 +735,210 @@ ExeAdjustFlatPartLayer( int nLayerId)
return bOk ;
}
//----------------------------------------------------------------------------
static bool
AdjustCurves( ICurve* pCrv1, ICurve* pCrv2)
{
// se fine della prima coincide con inizio della seconda non devo fare alcunchè
Point3d ptEnd1 ;
pCrv1->GetEndPoint( ptEnd1) ;
Point3d ptStart2 ;
pCrv2->GetStartPoint( ptStart2) ;
if ( AreSamePointApprox( ptEnd1, ptStart2))
return true ;
// allungo le due curve
if ( ! pCrv1->ExtendEndByLen( 200) ||
! pCrv2->ExtendStartByLen( 200))
return false ;
// cerco intersezioni
IntersCurveCurve intCC( *pCrv1, *pCrv2) ;
if ( intCC.GetIntersCount() == 0)
return false ;
// prendo l'intersezione più vicina al punto medio tra gli estremi originali delle curve
Point3d ptMid = 0.5 * ( ptEnd1 + ptStart2) ;
Point3d ptNew1, ptNew2 ;
if ( ! intCC.GetIntersPointNearTo( 0, ptMid, ptNew1) ||
! intCC.GetIntersPointNearTo( 1, ptMid, ptNew2))
return false ;
// modifico le due curve sul punto medio
Point3d ptNew = 0.5 * ( ptNew1 + ptNew2) ;
return ( pCrv1->ModifyEnd( ptNew) && pCrv2->ModifyStart( ptNew)) ;
}
//----------------------------------------------------------------------------
bool
ExeCalcFlatPartDownRegion( int nPartId, double dH)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// ripristino lo stato originale
pGeomDB->Erase( pGeomDB->GetFirstNameInGroup( nPartId, NST_PARTDOWNREG_LAYER)) ;
int nOlOrigId = pGeomDB->GetFirstNameInGroup( nPartId, NST_EXT_ORIG_LAYER) ;
if ( nOlOrigId != GDB_ID_NULL) {
pGeomDB->Erase( pGeomDB->GetFirstNameInGroup( nPartId, NST_EXT_LAYER)) ;
pGeomDB->SetName( nOlOrigId, NST_EXT_LAYER) ;
pGeomDB->SetStatus( nOlOrigId, GDB_ST_ON) ;
}
// se spessore nullo, non devo fare alcunché
if ( dH < EPS_SMALL)
return true ;
// recupero il layer esterno
int nOlId = pGeomDB->GetFirstNameInGroup( nPartId, NST_EXT_LAYER) ;
if ( nOlId == GDB_ID_NULL)
return false ;
// se il pezzo non ha lati esterni inclinati non devo fare alcunchè
bool bAllVertSides = true ;
int nCrvId = pGeomDB->GetFirstInGroup( nOlId) ;
while ( nCrvId != GDB_ID_NULL) {
double dSideAng ;
if ( pGeomDB->GetInfo( nCrvId, NST_KEY_SIDEANG, dSideAng) && abs( dSideAng) > EPS_ANG_SMALL) {
bAllVertSides = false ;
break ;
}
nCrvId = pGeomDB->GetNext( nCrvId) ;
}
if ( bAllVertSides)
return true ;
// creo una copia del layer esterno
nOlOrigId = pGeomDB->Copy( nOlId, GDB_ID_NULL, nOlId, GDB_AFTER) ;
if ( nOlOrigId == GDB_ID_NULL)
return false ;
pGeomDB->SetName( nOlOrigId, NST_EXT_ORIG_LAYER) ;
pGeomDB->SetStatus( nOlOrigId, GDB_ST_OFF) ;
// creo il layer per la regione sotto (con il medesimo riferimento del layer esterno)
Frame3d frOl ;
pGeomDB->GetGroupFrame( nOlId, frOl) ;
int nDwnRegId = pGeomDB->AddGroup( GDB_ID_NULL, nPartId, frOl) ;
if ( nDwnRegId == GDB_ID_NULL)
return false ;
pGeomDB->SetName( nDwnRegId, NST_PARTDOWNREG_LAYER) ;
// copio le entità del contorno esterno e le offsetto opportunamente
nCrvId = pGeomDB->GetFirstInGroup( nOlId) ;
while ( nCrvId != GDB_ID_NULL) {
// copio la curva nel gruppo downregion
int nNewId = pGeomDB->CopyGlob( nCrvId, GDB_ID_NULL, nDwnRegId) ;
if ( nNewId == GDB_ID_NULL)
return false ;
// determino ed eseguo offset
double dSideAng ;
if ( pGeomDB->GetInfo( nCrvId, NST_KEY_SIDEANG, dSideAng) && abs( dSideAng) > EPS_ANG_SMALL) {
double dOffset = dH * tan( dSideAng * DEGTORAD) ;
ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nNewId)) ;
if ( pCrv == nullptr)
return false ;
pCrv->SimpleOffset( dOffset) ;
}
// passo alla successiva
nCrvId = pGeomDB->GetNext( nCrvId) ;
}
// aggiusto tra loro le entità offsettate
int nFirstCrvId = pGeomDB->GetFirstInGroup( nDwnRegId) ;
ICurve* pCrv1 = GetCurve( pGeomDB->GetGeoObj( nFirstCrvId)) ;
int nNextCrvId = pGeomDB->GetNext( nFirstCrvId) ;
ICurve* pCrv2 = GetCurve( pGeomDB->GetGeoObj( nNextCrvId)) ;
while ( nNextCrvId != GDB_ID_NULL) {
// sistemo le curve
pCrv2 = GetCurve( pGeomDB->GetGeoObj( nNextCrvId)) ;
if ( pCrv1 == nullptr || pCrv2 == nullptr || ! AdjustCurves( pCrv1, pCrv2))
return false ;
// passo alla successiva
pCrv1 = pCrv2 ;
nNextCrvId = pGeomDB->GetNext( nNextCrvId) ;
}
// anche prima e ultima
pCrv2 = GetCurve( pGeomDB->GetGeoObj( nFirstCrvId)) ;
if ( pCrv1 == nullptr || pCrv2 == nullptr || ! AdjustCurves( pCrv1, pCrv2))
return false ;
// eventuali allungamenti per le curve del loop esterno
for ( int nCrvId = pGeomDB->GetFirstInGroup( nOlId) ;
nCrvId != GDB_ID_NULL ;
nCrvId = pGeomDB->GetNext( nCrvId)) {
// recupero il nome
string sName ;
if ( ! pGeomDB->GetName( nCrvId, sName))
continue ;
// recupero curva con lo stesso nome nel gruppo della regione sotto
int nCrvDrId = pGeomDB->GetFirstNameInGroup( nDwnRegId, sName) ;
if ( nCrvDrId == GDB_ID_NULL)
continue ;
// verifico siano curve
ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ;
ICurve* pCrvDr = GetCurve( pGeomDB->GetGeoObj( nCrvDrId)) ;
if ( pCrv == nullptr || pCrvDr == nullptr)
continue ;
// verifico se devo allungare o accorciare la curva all'inizio
double dPrevAng = 0 ;
pGeomDB->GetInfo( nCrvId, MCH_PV_KEY_PREVANG, dPrevAng) ;
Point3d ptStart ;
pCrv->GetStartPoint( ptStart) ;
Vector3d vtStartDir ;
pCrv->GetStartDir( vtStartDir) ;
Point3d ptStartDr ;
pCrvDr->GetStartPoint( ptStartDr) ;
double dStartPro = - ( ( ptStartDr - ptStart) * vtStartDir) ;
if ( dPrevAng > - EPS_ANG_SMALL) {
if ( dStartPro > EPS_SMALL)
pCrv->ExtendStartByLen( dStartPro) ;
}
else {
if ( dStartPro < - EPS_SMALL)
pCrv->TrimStartAtLen( - dStartPro) ;
}
// verifico se devo allungare la curva alla fine
double dNextAng = 0 ;
pGeomDB->GetInfo( nCrvId, MCH_PV_KEY_NEXTANG, dNextAng) ;
Point3d ptEnd ;
pCrv->GetEndPoint( ptEnd) ;
Vector3d vtEndDir ;
pCrv->GetStartDir( vtEndDir) ;
Point3d ptEndDr ;
pCrvDr->GetEndPoint( ptEndDr) ;
double dEndPro = ( ptEndDr - ptEnd) * vtEndDir ;
if ( dNextAng > - EPS_ANG_SMALL) {
if ( dEndPro > EPS_SMALL)
pCrv->ExtendEndByLen( dEndPro) ;
}
else {
if ( dEndPro < - EPS_SMALL) {
double dLen ;
pCrv->GetLength( dLen) ;
pCrv->TrimEndAtLen( dLen + dEndPro) ;
}
}
}
// creo la regione
PtrOwner<ICurveComposite> pCompo( CreateCurveComposite()) ;
if ( IsNull( pCompo))
return false ;
for ( int nCrvId = pGeomDB->GetFirstInGroup( nDwnRegId) ;
nCrvId != GDB_ID_NULL ;
nCrvId = pGeomDB->GetFirstInGroup( nDwnRegId)) {
ICurve* pCrv = GetCurve( pGeomDB->RemoveGeoObjAndErase( nCrvId)) ;
if ( pCrv != nullptr) {
pCompo->AddCurve( pCrv) ;
pGeomDB->RemoveGeoObjAndErase( nCrvId) ;
}
else
pGeomDB->Erase( nCrvId) ;
}
SurfFlatRegionByContours SfrCntr( false) ;
SfrCntr.AddCurve( Release( pCompo)) ;
int nSfrId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDwnRegId, SfrCntr.GetSurf()) ;
if ( nSfrId == GDB_ID_NULL)
return false ;
// assegno il colore
Color cCol = AQUA ;
cCol.SetAlpha( 0.3) ;
pGeomDB->SetMaterial( nSfrId, cCol) ;
return true ;
}
//----------------------------------------------------------------------------
int
GetFlatPartRegion( IGeomDB* pGeomDB, int nId)
@@ -750,6 +954,21 @@ GetFlatPartRegion( IGeomDB* pGeomDB, int nId)
return nRegId ;
}
//----------------------------------------------------------------------------
int
GetFlatPartDownRegion( IGeomDB* pGeomDB, int nId)
{
// recupero regione del pezzo (è la prima del sottogruppo di nome DwnReg)
int nRegGrp = pGeomDB->GetFirstNameInGroup( nId, NST_PARTDOWNREG_LAYER) ;
int nRegId = pGeomDB->GetFirstInGroup( nRegGrp) ;
while ( nRegId != GDB_ID_NULL) {
if ( pGeomDB->GetGeoType( nRegId) == SRF_FLATRGN)
break ;
nRegId = pGeomDB->GetNext( nRegId) ;
}
return nRegId ;
}
//----------------------------------------------------------------------------
bool
GetFlatPartCutRegions( IGeomDB* pGeomDB, int nId, bool bReduced, INTVECTOR& vCrId)
@@ -775,6 +994,34 @@ GetFlatPartCutRegions( IGeomDB* pGeomDB, int nId, bool bReduced, INTVECTOR& vCrI
return true ;
}
//----------------------------------------------------------------------------
bool
GetFlatPartDownCutRegions( IGeomDB* pGeomDB, int nId, bool bReduced, INTVECTOR& vDwnCrId)
{
// recupero gruppo preview lavorazioni del pezzo
int nPVGrp = pGeomDB->GetFirstNameInGroup( nId, MCH_PV) ;
if ( nPVGrp == GDB_ID_NULL)
return true ;
// ciclo sulle lavorazioni
int nMchId = pGeomDB->GetFirstGroupInGroup( nPVGrp) ;
while ( nMchId != GDB_ID_NULL) {
int nClId = pGeomDB->GetFirstGroupInGroup( nMchId) ;
while ( nClId != GDB_ID_NULL) {
// ciclo sui sopra e salvo gli eventuali sotto (per tenerli sincronizzati)
int nCrId = pGeomDB->GetFirstNameInGroup( nClId, ( bReduced ? MCH_PV_RRCUT : MCH_PV_RCUT)) ;
int nDwnCrId = pGeomDB->GetFirstNameInGroup( nClId, ( bReduced ? MCH_PV_DOWN_RRCUT : MCH_PV_DOWN_RCUT)) ;
while ( nCrId != GDB_ID_NULL) {
vDwnCrId.emplace_back( nDwnCrId) ;
nCrId = pGeomDB->GetNextName( nCrId, ( bReduced ? MCH_PV_RRCUT : MCH_PV_RCUT)) ;
nDwnCrId = pGeomDB->GetNextName( nDwnCrId, ( bReduced ? MCH_PV_DOWN_RRCUT : MCH_PV_DOWN_RCUT)) ;
}
nClId = pGeomDB->GetNextGroup( nClId) ;
}
nMchId = pGeomDB->GetNextGroup( nMchId) ;
}
return true ;
}
//----------------------------------------------------------------------------
int
GetFlatPartFromRegion( IGeomDB* pGeomDB, int nId)