EgtMachKernel 1.6k10 :
- sistemazioni varie in grezzi, lavorazioni, ....
This commit is contained in:
+156
-26
@@ -20,6 +20,8 @@
|
||||
#include "/EgtDev/Include/EGkCurveComposite.h"
|
||||
#include "/EgtDev/Include/EGkGdbIterator.h"
|
||||
#include "/EgtDev/Include/EGkGeoPoint3d.h"
|
||||
#include "/EgtDev/Include/EgkCurveAux.h"
|
||||
#include "/EgtDev/Include/EgkOffsetCurve.h"
|
||||
#include "/EgtDev/Include/EGkStmStandard.h"
|
||||
#include "/EgtDev/Include/EGkStmFromCurves.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
@@ -75,25 +77,19 @@ MachMgr::AddRawPart( const Point3d& ptOrig, double dLen, double dWidth, double d
|
||||
int nRawGroupId = GetCurrRawGroupId() ;
|
||||
if ( nRawGroupId == GDB_ID_NULL)
|
||||
return GDB_ID_NULL ;
|
||||
// creo il solido
|
||||
PtrOwner<ISurfTriMesh> pStm( GetSurfTriMeshBox( dLen, dWidth, dHeight)) ;
|
||||
if ( IsNull( pStm))
|
||||
return GDB_ID_NULL ;
|
||||
// se definita una tavola corrente, esprimo il punto rispetto alla sua prima origine
|
||||
Point3d ptMyOrig = ptOrig ;
|
||||
Point3d ptRef1 ;
|
||||
if ( GetTableRef( 1, ptRef1))
|
||||
ptMyOrig += ptRef1 ;
|
||||
// inserisco il gruppo del grezzo nei grezzi della macchinata
|
||||
int nRawId = m_pGeomDB->AddGroup( GDB_ID_NULL, nRawGroupId, Frame3d( ptOrig)) ;
|
||||
int nRawId = m_pGeomDB->AddGroup( GDB_ID_NULL, nRawGroupId, Frame3d( ptMyOrig)) ;
|
||||
if ( nRawId == GDB_ID_NULL)
|
||||
return GDB_ID_NULL ;
|
||||
// assegno il nome al gruppo
|
||||
bool bOk = m_pGeomDB->SetName( nRawId, MACH_RAW_PART) ;
|
||||
// inserisco il solido nel gruppo
|
||||
int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nRawId, Release( pStm)) ;
|
||||
bOk = bOk && ( nId != GDB_ID_NULL) ;
|
||||
// assegno il nome al solido
|
||||
bOk = bOk && m_pGeomDB->SetName( nId, MACH_RAW_SOLID) ;
|
||||
// assegno il colore al solido
|
||||
bOk = bOk && m_pGeomDB->SetMaterial( nId, cCol) ;
|
||||
// calcolo il punto centro del solido
|
||||
bOk = bOk && SetRawPartCenter( nRawId) ;
|
||||
// creo solido e outline
|
||||
bOk = bOk && ModifyRawPart( nRawId, ptOrig, dLen, dWidth, dHeight, cCol) ;
|
||||
// se qualcosa è andato storto, cancello tutto
|
||||
if ( ! bOk) {
|
||||
m_pGeomDB->Erase( nRawId) ;
|
||||
@@ -103,6 +99,65 @@ MachMgr::AddRawPart( const Point3d& ptOrig, double dLen, double dWidth, double d
|
||||
return nRawId ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
MachMgr::ModifyRawPart( int nRawId, const Point3d& ptOrig, double dLen, double dWidth, double dHeight, Color cCol)
|
||||
{
|
||||
// le dimensioni non possono essere nulle
|
||||
if ( dLen < EPS_SMALL || dWidth < EPS_SMALL || dHeight < EPS_SMALL)
|
||||
return false ;
|
||||
// verifica validità grezzo
|
||||
if ( ! VerifyRawPart( nRawId))
|
||||
return false ;
|
||||
// creo il solido
|
||||
PtrOwner<ISurfTriMesh> pStm( GetSurfTriMeshBox( dLen, dWidth, dHeight)) ;
|
||||
if ( IsNull( pStm))
|
||||
return false ;
|
||||
// creo il contorno esterno
|
||||
PolyLine PL ;
|
||||
PL.AddUPoint( 0, ORIG) ;
|
||||
PL.AddUPoint( 1, Point3d( dLen, 0, 0)) ;
|
||||
PL.AddUPoint( 2, Point3d( dLen, dWidth, 0)) ;
|
||||
PL.AddUPoint( 3, Point3d( 0, dWidth, 0)) ;
|
||||
PL.AddUPoint( 4, ORIG) ;
|
||||
// creo la curva
|
||||
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
||||
if ( IsNull( pCrvCompo) || ! pCrvCompo->FromPolyLine( PL) || ! pCrvCompo->SetExtrusion( Z_AX))
|
||||
return false ;
|
||||
// cancello eventuali vecchi solidi e curve di outline
|
||||
int nOldRawSolId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ;
|
||||
if ( nOldRawSolId != GDB_ID_NULL)
|
||||
m_pGeomDB->Erase( nOldRawSolId) ;
|
||||
int nOldRawOutId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_OUTLINE) ;
|
||||
if ( nOldRawOutId != GDB_ID_NULL)
|
||||
m_pGeomDB->Erase( nOldRawOutId) ;
|
||||
// se definita una tavola corrente, esprimo il punto rispetto alla sua prima origine
|
||||
Point3d ptMyOrig = ptOrig ;
|
||||
Point3d ptRef1 ;
|
||||
if ( GetTableRef( 1, ptRef1))
|
||||
ptMyOrig += ptRef1 ;
|
||||
// aggiorno l'origine del gruppo
|
||||
m_pGeomDB->GetGroupFrame( nRawId)->ChangeOrig( ptMyOrig) ;
|
||||
// inserisco il solido nel gruppo
|
||||
int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nRawId, Release( pStm)) ;
|
||||
bool bOk = ( nId != GDB_ID_NULL) ;
|
||||
// assegno il nome al solido
|
||||
bOk = bOk && m_pGeomDB->SetName( nId, MACH_RAW_SOLID) ;
|
||||
// assegno il colore al solido
|
||||
bOk = bOk && m_pGeomDB->SetMaterial( nId, cCol) ;
|
||||
// calcolo il punto centro del solido
|
||||
bOk = bOk && SetRawPartCenter( nRawId) ;
|
||||
// inserisco la curva composita nel DB
|
||||
int nCrvId = ( bOk ? m_pGeomDB->AddGeoObj( GDB_ID_NULL, nRawId, Release( pCrvCompo)) : GDB_ID_NULL) ;
|
||||
bOk = bOk && ( nCrvId != GDB_ID_NULL) ;
|
||||
// assegno il nome al contorno
|
||||
bOk = bOk && m_pGeomDB->SetName( nCrvId, MACH_RAW_OUTLINE) ;
|
||||
// assegno il colore al contorno
|
||||
bOk = bOk && m_pGeomDB->SetMaterial( nCrvId, cCol) ;
|
||||
|
||||
return bOk ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
MachMgr::AddRawPart( int nCrvId, double dOverMat, double dZmin, double dHeight, Color cCol)
|
||||
@@ -137,8 +192,7 @@ MachMgr::AddRawPart( int nCrvId, double dOverMat, double dZmin, double dHeight,
|
||||
if ( ! pMyCrv->Scale( Frame3d(), 1, 1, 0))
|
||||
return GDB_ID_NULL ;
|
||||
// se non è chiusa, la chiudo
|
||||
if ( ! pMyCrv->IsClosed())
|
||||
pMyCrv->Close() ;
|
||||
pMyCrv->Close() ;
|
||||
// la oriento in senso CCW
|
||||
double dAreaXY ;
|
||||
if ( ! pMyCrv->GetAreaXY( dAreaXY))
|
||||
@@ -146,10 +200,13 @@ MachMgr::AddRawPart( int nCrvId, double dOverMat, double dZmin, double dHeight,
|
||||
if ( dAreaXY < 0)
|
||||
pMyCrv->Invert() ;
|
||||
// ne eseguo l'offset
|
||||
if ( ! pMyCrv->SimpleOffset( dOverMat, ICurve::OFF_EXTEND))
|
||||
OffsetCurve OffsCrv ;
|
||||
OffsCrv.Make( Get( pMyCrv), dOverMat, ICurve::OFF_EXTEND) ;
|
||||
PtrOwner<ICurve> pOffsCrv( OffsCrv.GetLongerCurve()) ;
|
||||
if ( IsNull( pOffsCrv))
|
||||
return GDB_ID_NULL ;
|
||||
// creo il solido
|
||||
PtrOwner<ISurfTriMesh> pStm( GetSurfTriMeshByExtrusion( Get( pMyCrv), Vector3d(0,0,dHeight), true)) ;
|
||||
PtrOwner<ISurfTriMesh> pStm( GetSurfTriMeshByExtrusion( Get( pOffsCrv), Vector3d(0,0,dHeight), true)) ;
|
||||
if ( IsNull( pStm))
|
||||
return GDB_ID_NULL ;
|
||||
// inserisco il gruppo del grezzo nella macchinata
|
||||
@@ -167,6 +224,13 @@ MachMgr::AddRawPart( int nCrvId, double dOverMat, double dZmin, double dHeight,
|
||||
bOk = bOk && m_pGeomDB->SetMaterial( nId, cCol) ;
|
||||
// calcolo il punto centro del solido
|
||||
bOk = bOk && SetRawPartCenter( nRawId) ;
|
||||
// inserisco nel DB la curva di offset come contorno del grezzo
|
||||
int nOutCrvId = ( bOk ? m_pGeomDB->AddGeoObj( GDB_ID_NULL, nRawId, Release( pOffsCrv)) : GDB_ID_NULL) ;
|
||||
bOk = bOk && ( nOutCrvId != GDB_ID_NULL) ;
|
||||
// assegno il nome al contorno
|
||||
bOk = bOk && m_pGeomDB->SetName( nOutCrvId, MACH_RAW_OUTLINE) ;
|
||||
// assegno il colore al contorno
|
||||
bOk = bOk && m_pGeomDB->SetMaterial( nOutCrvId, cCol) ;
|
||||
// se qualcosa è andato storto, cancello tutto
|
||||
if ( ! bOk) {
|
||||
m_pGeomDB->Erase( nRawId) ;
|
||||
@@ -206,6 +270,55 @@ MachMgr::AddRawPart( int nSurfId, Color cCol)
|
||||
bOk = bOk && m_pGeomDB->SetStatus( nId, GDB_ST_ON) ;
|
||||
// calcolo il punto centro del solido
|
||||
bOk = bOk && SetRawPartCenter( nRawId) ;
|
||||
// calcolo la curva di contorno
|
||||
if ( bOk) {
|
||||
// creo la curva
|
||||
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
||||
if ( IsNull( pCrvCompo))
|
||||
return GDB_ID_NULL ;
|
||||
// recupero la superficie trimesh
|
||||
ISurfTriMesh* pStm = GetSurfTriMesh( m_pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pStm == nullptr)
|
||||
return GDB_ID_NULL ;
|
||||
// recupero l'ingombro della superficie in locale
|
||||
BBox3d b3Srf ;
|
||||
pStm->GetLocalBBox( b3Srf) ;
|
||||
// ne calcolo la silhouette secondo Z+
|
||||
POLYLINEVECTOR vPL ;
|
||||
bool bSilh = false ;
|
||||
if ( pStm->GetSilhouette( Z_AX, vPL) && vPL.size() == 1) {
|
||||
PtrOwner<ICurveComposite> pCrvSilh( CreateCurveComposite()) ;
|
||||
if ( pCrvSilh->FromPolyLine( vPL[0]) && pCrvSilh->IsClosed()) {
|
||||
pCrvSilh->SetExtrusion( Z_AX) ;
|
||||
Plane3d plProj ;
|
||||
SetPlane( b3Srf.GetMin(), Z_AX, plProj) ;
|
||||
pCrvCompo.Set( GetCurveComposite( ProjectCurveOnPlane( *pCrvSilh, plProj))) ;
|
||||
pCrvCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL) ;
|
||||
bSilh = ( ! IsNull( pCrvCompo)) ;
|
||||
}
|
||||
}
|
||||
// non riuscita, la calcolo come contorno del box
|
||||
if ( ! bSilh) {
|
||||
Point3d ptMin ;
|
||||
double dDimX, dDimY, dDimZ ;
|
||||
b3Srf.GetMinDim( ptMin, dDimX, dDimY, dDimZ) ;
|
||||
PolyLine PL ;
|
||||
PL.AddUPoint( 0, ptMin) ;
|
||||
PL.AddUPoint( 1, ptMin + Vector3d( dDimX, 0,0)) ;
|
||||
PL.AddUPoint( 2, ptMin + Vector3d( dDimX, dDimY,0)) ;
|
||||
PL.AddUPoint( 3, ptMin + Vector3d( 0, dDimY,0)) ;
|
||||
PL.AddUPoint( 4, ptMin) ;
|
||||
if ( ! pCrvCompo->FromPolyLine( PL) && ! pCrvCompo->SetExtrusion( Z_AX))
|
||||
bOk = false ;
|
||||
}
|
||||
// inserisco la curva composita nel DB
|
||||
int nCrvId = ( bOk ? m_pGeomDB->AddGeoObj( GDB_ID_NULL, nRawId, Release( pCrvCompo)) : GDB_ID_NULL) ;
|
||||
bOk = bOk && ( nCrvId != GDB_ID_NULL) ;
|
||||
// assegno il nome alla curva
|
||||
bOk = bOk && m_pGeomDB->SetName( nCrvId, MACH_RAW_SOLID) ;
|
||||
// assegno il colore alla curva
|
||||
bOk = bOk && m_pGeomDB->SetMaterial( nCrvId, cCol) ;
|
||||
}
|
||||
// se qualcosa è andato storto, cancello tutto
|
||||
if ( ! bOk) {
|
||||
m_pGeomDB->Erase( nRawId) ;
|
||||
@@ -229,12 +342,16 @@ MachMgr::AddRawPartWithPart( int nPartId, int nCrvSrfId, double dOverMat, Color
|
||||
return GDB_ID_NULL ;
|
||||
// recupero il tipo di oggetto per definire il grezzo
|
||||
int nGtype = m_pGeomDB->GetGeoType( nCrvSrfId) ;
|
||||
// punto di riferimento del pezzo nel grezzo
|
||||
Point3d ptRef ;
|
||||
// costruzione del grezzo
|
||||
int nRawId = GDB_ID_NULL ;
|
||||
// se grezzo da superficie (per ora senza possibilità di offset)
|
||||
if ( ( nGtype & GEO_SURF) != 0) {
|
||||
// inserisco il grezzo
|
||||
nRawId = AddRawPart( nCrvSrfId, cCol) ;
|
||||
// annullo il sovra-materiale
|
||||
dOverMat = 0 ;
|
||||
}
|
||||
// se altrimenti grezzo da contorno
|
||||
else if ( ( nGtype & GEO_CURVE) != 0) {
|
||||
@@ -256,22 +373,30 @@ MachMgr::AddRawPartWithPart( int nPartId, int nCrvSrfId, double dOverMat, Color
|
||||
if ( ! m_pGeomDB->GetGlobalBBox( nPartId, b3Part))
|
||||
return GDB_ID_NULL ;
|
||||
// deduco i dati del grezzo
|
||||
Point3d ptMin = b3Part.GetMin() - Vector3d( dOverMat, dOverMat, 0) ;
|
||||
Point3d ptMax = b3Part.GetMax() + Vector3d( dOverMat, dOverMat, 0) ;
|
||||
Vector3d vtDiff = ptMax - ptMin ;
|
||||
Vector3d vtDiff = b3Part.GetMax() - b3Part.GetMin() + 2 * Vector3d( dOverMat, dOverMat, 0) ;
|
||||
if ( vtDiff.z < RAW_MIN_H)
|
||||
vtDiff.z = RAW_MIN_H ;
|
||||
// inserisco il grezzo
|
||||
nRawId = AddRawPart( ptMin, vtDiff.x, vtDiff.y, vtDiff.z, cCol) ;
|
||||
nRawId = AddRawPart( ORIG, vtDiff.x, vtDiff.y, vtDiff.z, cCol) ;
|
||||
// il riferimento deve tenere conto dell'offset
|
||||
ptRef = Point3d( dOverMat, dOverMat, 0) ;
|
||||
}
|
||||
// verifico costruzione grezzo
|
||||
if ( nRawId == GDB_ID_NULL)
|
||||
return GDB_ID_NULL ;
|
||||
// se definita tavola, aggiusto posizione del grezzo
|
||||
Point3d ptTabRef ;
|
||||
if ( GetTableRef( 1, ptTabRef)) {
|
||||
BBox3d b3Raw ;
|
||||
m_pGeomDB->GetGlobalBBox( nRawId, b3Raw) ;
|
||||
m_pGeomDB->TranslateGlob( nRawId, ptTabRef - b3Raw.GetMin()) ;
|
||||
}
|
||||
// inserisco il pezzo nel grezzo
|
||||
if ( ! AddPartToRawPart( nPartId, nRawId)) {
|
||||
if ( ! AddPartToRawPart( nPartId, ptRef, nRawId)) {
|
||||
RemoveRawPart( nRawId) ;
|
||||
return GDB_ID_NULL ;
|
||||
}
|
||||
|
||||
return nRawId ;
|
||||
}
|
||||
|
||||
@@ -289,6 +414,10 @@ MachMgr::ModifyRawPartSize( int nRawId, double dLength, double dWidth, double dH
|
||||
int nRawSolId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ;
|
||||
if ( nRawSolId == GDB_ID_NULL)
|
||||
return false ;
|
||||
// recupero il contorno del grezzo
|
||||
int nRawOutId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_OUTLINE) ;
|
||||
if ( nRawOutId == GDB_ID_NULL)
|
||||
return false ;
|
||||
// recupero il box del grezzo
|
||||
BBox3d b3Raw ;
|
||||
if ( ! m_pGeomDB->GetLocalBBox( nRawSolId, b3Raw))
|
||||
@@ -308,8 +437,9 @@ MachMgr::ModifyRawPartSize( int nRawId, double dLength, double dWidth, double dH
|
||||
if ( dOldH < EPS_SMALL)
|
||||
return false ;
|
||||
double dCoeffZ = dHeight / dOldH ;
|
||||
// eseguo scalatura
|
||||
bool bOk = m_pGeomDB->Scale( nRawSolId, Frame3d( b3Raw.GetMin()), dCoeffX, dCoeffY, dCoeffZ) ;
|
||||
// eseguo scalature
|
||||
bool bOk = m_pGeomDB->Scale( nRawSolId, Frame3d( b3Raw.GetMin()), dCoeffX, dCoeffY, dCoeffZ) &&
|
||||
m_pGeomDB->Scale( nRawOutId, Frame3d( b3Raw.GetMin()), dCoeffX, dCoeffY, dCoeffZ) ;
|
||||
// dichiaro centro da ricalcolare
|
||||
ResetRawPartCenter( nRawId) ;
|
||||
return bOk ;
|
||||
@@ -426,7 +556,7 @@ MachMgr::MoveRawPart( int nRawId, const Vector3d& vtMove)
|
||||
if ( pDisp == nullptr)
|
||||
return false ;
|
||||
// eseguo l'operazione
|
||||
return pDisp->MoveRawPart( nRawId,vtMove) ;
|
||||
return pDisp->MoveRawPart( nRawId, vtMove) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user