42e1a696a1
- sistemazioni varie in grezzi, lavorazioni, ....
633 lines
24 KiB
C++
633 lines
24 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2015-2015
|
|
//----------------------------------------------------------------------------
|
|
// File : MachMgr.cpp Data : 16.04.15 Versione : 1.6d3
|
|
// Contenuto : Implementazione gestione grezzi e pezzi della classe MachMgr.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 16.04.15 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "DllMain.h"
|
|
#include "MachMgr.h"
|
|
#include "MachConst.h"
|
|
#include "Disposition.h"
|
|
#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"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
MachMgr::GetRawPartCount( void) const
|
|
{
|
|
// recupero il gruppo dei grezzi nella macchinata corrente
|
|
int nRawGroupId = GetCurrRawGroupId() ;
|
|
if ( nRawGroupId == GDB_ID_NULL)
|
|
return 0 ;
|
|
// ritorno numero dei grezzi della macchinata
|
|
return m_pGeomDB->GetGroupObjs( nRawGroupId) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
MachMgr::GetFirstRawPart( void) const
|
|
{
|
|
// recupero il gruppo dei grezzi nella macchinata corrente
|
|
int nRawGroupId = GetCurrRawGroupId() ;
|
|
if ( nRawGroupId == GDB_ID_NULL)
|
|
return GDB_ID_NULL ;
|
|
// recupero il primo sottogruppo
|
|
int nId = m_pGeomDB->GetFirstGroupInGroup( nRawGroupId) ;
|
|
return nId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
MachMgr::GetNextRawPart( int nId) const
|
|
{
|
|
// recupero il gruppo dei grezzi nella macchinata corrente
|
|
int nRawGroupId = GetCurrRawGroupId() ;
|
|
if ( nRawGroupId == GDB_ID_NULL)
|
|
return GDB_ID_NULL ;
|
|
// verifico che il gruppo ricevuto sia corretto
|
|
if ( m_pGeomDB->GetParentId( nId) != nRawGroupId)
|
|
return GDB_ID_NULL ;
|
|
// recupero il successivo sottogruppo
|
|
int nNextId = m_pGeomDB->GetNextGroup( nId) ;
|
|
return nNextId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
MachMgr::AddRawPart( const Point3d& ptOrig, double dLen, double dWidth, double dHeight, Color cCol)
|
|
{
|
|
// recupero il gruppo dei grezzi nella macchinata corrente
|
|
int nRawGroupId = GetCurrRawGroupId() ;
|
|
if ( nRawGroupId == GDB_ID_NULL)
|
|
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( ptMyOrig)) ;
|
|
if ( nRawId == GDB_ID_NULL)
|
|
return GDB_ID_NULL ;
|
|
// assegno il nome al gruppo
|
|
bool bOk = m_pGeomDB->SetName( nRawId, MACH_RAW_PART) ;
|
|
// 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) ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// tutto ok
|
|
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)
|
|
{
|
|
// recupero il gruppo dei grezzi nella macchinata corrente
|
|
int nRawGroupId = GetCurrRawGroupId() ;
|
|
if ( nRawGroupId == GDB_ID_NULL)
|
|
return GDB_ID_NULL ;
|
|
// recupero l'ingombro della curva in globale
|
|
BBox3d b3Crv ;
|
|
if ( ! m_pGeomDB->GetGlobalBBox( nCrvId, b3Crv))
|
|
return GDB_ID_NULL ;
|
|
// recupero il riferimento della curva
|
|
Frame3d frCrv ;
|
|
if ( ! m_pGeomDB->GetGlobFrame( nCrvId, frCrv))
|
|
return GDB_ID_NULL ;
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( m_pGeomDB->GetGeoObj( nCrvId)) ;
|
|
if ( pCrv == nullptr)
|
|
return GDB_ID_NULL ;
|
|
// copio la curva in una composita
|
|
PtrOwner<ICurveComposite> pMyCrv( CreateCurveComposite()) ;
|
|
if ( IsNull( pMyCrv) || ! pMyCrv->AddCurve( *pCrv))
|
|
return GDB_ID_NULL ;
|
|
// determino il riferimento del grezzo
|
|
Point3d ptOrig = b3Crv.GetMin() ;
|
|
ptOrig.z = dZmin ;
|
|
Frame3d frRaw( ptOrig) ;
|
|
// porto la curva in questo riferimento
|
|
pMyCrv->LocToLoc( frCrv, frRaw) ;
|
|
// la schiaccio a Z = 0
|
|
if ( ! pMyCrv->Scale( Frame3d(), 1, 1, 0))
|
|
return GDB_ID_NULL ;
|
|
// se non è chiusa, la chiudo
|
|
pMyCrv->Close() ;
|
|
// la oriento in senso CCW
|
|
double dAreaXY ;
|
|
if ( ! pMyCrv->GetAreaXY( dAreaXY))
|
|
return GDB_ID_NULL ;
|
|
if ( dAreaXY < 0)
|
|
pMyCrv->Invert() ;
|
|
// ne eseguo l'offset
|
|
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( pOffsCrv), Vector3d(0,0,dHeight), true)) ;
|
|
if ( IsNull( pStm))
|
|
return GDB_ID_NULL ;
|
|
// inserisco il gruppo del grezzo nella macchinata
|
|
int nRawId = m_pGeomDB->AddGroup( GDB_ID_NULL, nRawGroupId, frRaw) ;
|
|
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) ;
|
|
// 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) ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// tutto ok
|
|
return nRawId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
MachMgr::AddRawPart( int nSurfId, Color cCol)
|
|
{
|
|
// recupero il gruppo dei grezzi nella macchinata corrente
|
|
int nRawGroupId = GetCurrRawGroupId() ;
|
|
if ( nRawGroupId == GDB_ID_NULL)
|
|
return GDB_ID_NULL ;
|
|
// recupero l'ingombro della superficie in globale
|
|
BBox3d b3Crv ;
|
|
if ( ! m_pGeomDB->GetGlobalBBox( nSurfId, b3Crv))
|
|
return GDB_ID_NULL ;
|
|
// inserisco il gruppo del grezzo nella macchinata
|
|
Frame3d frRaw( b3Crv.GetMin()) ;
|
|
int nRawId = m_pGeomDB->AddGroup( GDB_ID_NULL, nRawGroupId, frRaw) ;
|
|
if ( nRawId == GDB_ID_NULL)
|
|
return GDB_ID_NULL ;
|
|
// assegno il nome al gruppo
|
|
bool bOk = m_pGeomDB->SetName( nRawId, MACH_RAW_PART) ;
|
|
// copio la superficie nel gruppo
|
|
int nId = m_pGeomDB->CopyGlob( nSurfId, GDB_ID_NULL, nRawId) ;
|
|
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) ;
|
|
// rendo visibile il solido
|
|
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) ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// nascondo la superficie originale
|
|
m_pGeomDB->SetStatus( nSurfId, GDB_ST_OFF) ;
|
|
// tutto ok
|
|
return nRawId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
MachMgr::AddRawPartWithPart( int nPartId, int nCrvSrfId, double dOverMat, Color cCol)
|
|
{
|
|
// verifico il gruppo dei grezzi nella macchinata corrente
|
|
if ( GetCurrRawGroupId() == GDB_ID_NULL)
|
|
return GDB_ID_NULL ;
|
|
// verifico che il pezzo non sia già usato nella macchinata corrente
|
|
if ( m_pGeomDB->GetParentId( nPartId) != GDB_ID_ROOT)
|
|
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) {
|
|
// determino l'ingombro del pezzo
|
|
BBox3d b3Part ;
|
|
if ( ! m_pGeomDB->GetGlobalBBox( nPartId, b3Part))
|
|
return GDB_ID_NULL ;
|
|
// inserisco il grezzo
|
|
double dZmin = b3Part.GetMin().z ;
|
|
double dH = ( b3Part.GetMax() - b3Part.GetMin()).z ;
|
|
if ( dH < RAW_MIN_H)
|
|
dH = RAW_MIN_H ;
|
|
nRawId = AddRawPart( nCrvSrfId, dOverMat, dZmin, dH, cCol) ;
|
|
}
|
|
// altrimenti grezzo rettangolare da ingombro pezzo
|
|
else {
|
|
// determino l'ingombro del pezzo
|
|
BBox3d b3Part ;
|
|
if ( ! m_pGeomDB->GetGlobalBBox( nPartId, b3Part))
|
|
return GDB_ID_NULL ;
|
|
// deduco i dati del grezzo
|
|
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( 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, ptRef, nRawId)) {
|
|
RemoveRawPart( nRawId) ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
|
|
return nRawId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::ModifyRawPartSize( int nRawId, double dLength, double dWidth, double dHeight)
|
|
{
|
|
// le nuove dimensioni non possono essere nulle
|
|
if ( dLength < EPS_SMALL || dWidth < EPS_SMALL || dHeight < EPS_SMALL)
|
|
return false ;
|
|
// verifica validità grezzo
|
|
if ( ! VerifyRawPart( nRawId))
|
|
return false ;
|
|
// recupero il solido del grezzo
|
|
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))
|
|
return false ;
|
|
// determino il coefficente di scalatura in X
|
|
double dOldL = b3Raw.GetMax().x - b3Raw.GetMin().x ;
|
|
if ( dOldL < EPS_SMALL)
|
|
return false ;
|
|
double dCoeffX = dLength / dOldL ;
|
|
// determino il coefficente di scalatura in Y
|
|
double dOldW = b3Raw.GetMax().y - b3Raw.GetMin().y ;
|
|
if ( dOldW < EPS_SMALL)
|
|
return false ;
|
|
double dCoeffY = dWidth / dOldW ;
|
|
// determino il coefficente di scalatura in Z
|
|
double dOldH = b3Raw.GetMax().z - b3Raw.GetMin().z ;
|
|
if ( dOldH < EPS_SMALL)
|
|
return false ;
|
|
double dCoeffZ = dHeight / dOldH ;
|
|
// 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 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::ModifyRawPartHeight( int nRawId, double dHeight)
|
|
{
|
|
// la nuova altezza non può essere nulla
|
|
if ( dHeight < EPS_SMALL)
|
|
return false ;
|
|
// verifica validità grezzo
|
|
if ( ! VerifyRawPart( nRawId))
|
|
return false ;
|
|
// recupero il solido del grezzo
|
|
int nRawSolId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ;
|
|
if ( nRawSolId == GDB_ID_NULL)
|
|
return false ;
|
|
// recupero il box del grezzo
|
|
BBox3d b3Raw ;
|
|
if ( ! m_pGeomDB->GetLocalBBox( nRawSolId, b3Raw))
|
|
return false ;
|
|
// determino il coefficente di scalatura in Z
|
|
double dOldH = b3Raw.GetMax().z - b3Raw.GetMin().z ;
|
|
if ( dOldH < EPS_SMALL)
|
|
return false ;
|
|
double dCoeff = dHeight / dOldH ;
|
|
// eseguo scalatura
|
|
bool bOk = m_pGeomDB->Scale( nRawSolId, Frame3d( b3Raw.GetMin()), 1, 1, dCoeff) ;
|
|
// dichiaro centro da ricalcolare
|
|
ResetRawPartCenter( nRawId) ;
|
|
return bOk ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::RemoveRawPart( int nRawId)
|
|
{
|
|
// verifica validità grezzo
|
|
if ( ! VerifyRawPart( nRawId))
|
|
return false ;
|
|
// devo estrarre i pezzi e riportarli in lista generale
|
|
SwapRawPartParts( nRawId, false) ;
|
|
// cancello il grezzo
|
|
m_pGeomDB->Erase( nRawId) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::VerifyRawPart( int nRawId) const
|
|
{
|
|
// recupero il gruppo dei grezzi nella macchinata corrente
|
|
int nRawGroupId = GetCurrRawGroupId() ;
|
|
if ( nRawGroupId == GDB_ID_NULL)
|
|
return false ;
|
|
// verifico che questo grezzo ne faccia parte
|
|
if ( m_pGeomDB->GetParentId( nRawId) != nRawGroupId)
|
|
return false ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::RotateRawPart( int nRawId, const Vector3d& vtAx, double dAngRotDeg)
|
|
{
|
|
// recupero la prima operazione, deve essere la disposizione
|
|
int nDispId = GetFirstOperation() ;
|
|
// recupero l'oggetto disposizione
|
|
Disposition* pDisp = dynamic_cast<Disposition*>( m_pGeomDB->GetUserObj( nDispId)) ;
|
|
if ( pDisp == nullptr)
|
|
return false ;
|
|
// eseguo l'operazione
|
|
return pDisp->RotateRawPart( nRawId, vtAx, dAngRotDeg) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::MoveToCornerRawPart( int nRawId, const Point3d& ptP, int nFlag)
|
|
{
|
|
// recupero la prima operazione, deve essere la disposizione
|
|
int nDispId = GetFirstOperation() ;
|
|
// recupero l'oggetto disposizione
|
|
Disposition* pDisp = dynamic_cast<Disposition*>( m_pGeomDB->GetUserObj( nDispId)) ;
|
|
if ( pDisp == nullptr)
|
|
return false ;
|
|
// eseguo l'operazione
|
|
return pDisp->MoveToCornerRawPart( nRawId, ptP, nFlag) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::MoveToCenterRawPart( int nRawId, const Point3d& ptP, int nFlag)
|
|
{
|
|
// recupero la prima operazione, deve essere la disposizione
|
|
int nDispId = GetFirstOperation() ;
|
|
// recupero l'oggetto disposizione
|
|
Disposition* pDisp = dynamic_cast<Disposition*>( m_pGeomDB->GetUserObj( nDispId)) ;
|
|
if ( pDisp == nullptr)
|
|
return false ;
|
|
// eseguo l'operazione
|
|
return pDisp->MoveToCenterRawPart( nRawId, ptP, nFlag) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::MoveRawPart( int nRawId, const Vector3d& vtMove)
|
|
{
|
|
// recupero la prima operazione, deve essere la disposizione
|
|
int nDispId = GetFirstOperation() ;
|
|
// recupero l'oggetto disposizione
|
|
Disposition* pDisp = dynamic_cast<Disposition*>( m_pGeomDB->GetUserObj( nDispId)) ;
|
|
if ( pDisp == nullptr)
|
|
return false ;
|
|
// eseguo l'operazione
|
|
return pDisp->MoveRawPart( nRawId, vtMove) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::SetRawPartCenter( int nRawId)
|
|
{
|
|
// recupero il solido
|
|
int nRawSolId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ;
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( m_pGeomDB->GetGeoObj( nRawSolId)) ;
|
|
if ( pStm == nullptr)
|
|
return false ;
|
|
// recupero il punto centro, se non esiste lo creo
|
|
int nGPntId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_CENTER) ;
|
|
if ( nGPntId == GDB_ID_NULL) {
|
|
PtrOwner<IGeoPoint3d> pGeoPnt( CreateGeoPoint3d()) ;
|
|
nGPntId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nRawId, Release( pGeoPnt)) ;
|
|
m_pGeomDB->SetName( nGPntId, MACH_RAW_CENTER) ;
|
|
Color cCol ;
|
|
if ( m_pGeomDB->GetCalcMaterial( nRawSolId, cCol))
|
|
m_pGeomDB->SetMaterial( nGPntId, cCol) ;
|
|
}
|
|
IGeoPoint3d* pGeoPnt = GetGeoPoint3d( m_pGeomDB->GetGeoObj( nGPntId)) ;
|
|
if ( pGeoPnt == nullptr)
|
|
return false ;
|
|
// calcolo il valore del centro
|
|
Point3d ptCen ;
|
|
if ( ! pStm->GetCentroid( ptCen))
|
|
return false ;
|
|
// aggiorno e imposto modo a standard
|
|
return ( pGeoPnt->Set( ptCen) && m_pGeomDB->SetMode( nGPntId, GDB_MD_STD)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::ResetRawPartCenter( int nRawId)
|
|
{
|
|
// recupero il punto centro
|
|
int nGPntId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_CENTER) ;
|
|
if ( nGPntId == GDB_ID_NULL)
|
|
return true ;
|
|
// imposto modo a bloccato
|
|
return m_pGeomDB->SetMode( nGPntId, GDB_MD_HIDDEN) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::GetRawPartCenter( int nRawId, Point3d& ptCen)
|
|
{
|
|
// cerco di recuperare l'oggetto
|
|
int nGPntId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_CENTER) ;
|
|
// ne verifico la validità
|
|
int nMode ;
|
|
if ( nGPntId == GDB_ID_NULL ||
|
|
! m_pGeomDB->GetMode( nGPntId, nMode) || nMode != GDB_MD_STD) {
|
|
// provo a crearlo
|
|
SetRawPartCenter( nRawId) ;
|
|
nGPntId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_CENTER) ;
|
|
// se c'è ancora errore
|
|
if ( nGPntId == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
// ne recupero il riferimento globale
|
|
Frame3d frGPnt ;
|
|
if ( ! m_pGeomDB->GetGlobFrame( nGPntId, frGPnt))
|
|
return false ;
|
|
// recupero il punto
|
|
IGeoPoint3d* pGeoPnt = GetGeoPoint3d( m_pGeomDB->GetGeoObj( nGPntId)) ;
|
|
if ( pGeoPnt == nullptr)
|
|
return false ;
|
|
ptCen = pGeoPnt->GetPoint() ;
|
|
ptCen.ToGlob( frGPnt) ;
|
|
return true ;
|
|
}
|