EgtMachKernel :
- modifiche a Sawing.
This commit is contained in:
+174
-3
@@ -16,14 +16,16 @@
|
||||
#include "MachMgr.h"
|
||||
#include "DllMain.h"
|
||||
#include "Milling.h"
|
||||
#include "MachiningConst.h"
|
||||
#include "/EgtDev/Include/EGkCurveLine.h"
|
||||
#include "/EgtDev/Include/EGkCurveComposite.h"
|
||||
#include "/EgtDev/Include/EgkChainCurves.h"
|
||||
#include "/EgtDev/Include/EGkUserObjFactory.h"
|
||||
#include "/EgtDev/Include/EGnStringKeyVal.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
|
||||
using namespace std ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static std::string KEY_IDS = "IDS" ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
USEROBJ_REGISTER( "EMkMilling", Milling) ;
|
||||
|
||||
@@ -169,3 +171,172 @@ Milling::Apply( void)
|
||||
{
|
||||
return false ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Milling::VerifyGeometry( SelData Id, int& nSubs)
|
||||
{
|
||||
// ammessi : curve o facce di polymesh
|
||||
|
||||
// per ora accetto solo curve
|
||||
const ICurve* pCurve = nullptr ;
|
||||
const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( Id.nId) ;
|
||||
// se direttamente la curva
|
||||
if ( Id.nSub == SEL_SUB_ALL) {
|
||||
pCurve = ::GetCurve( m_pGeomDB->GetGeoObj( Id.nId)) ;
|
||||
if ( pCurve != nullptr && pCurve->GetType() == CRV_COMPO)
|
||||
nSubs = ::GetCurveComposite( pCurve)->GetCurveNumber() ;
|
||||
}
|
||||
// altrimenti sottocurva di composita
|
||||
else {
|
||||
const ICurveComposite* pCompo = GetCurveComposite( m_pGeomDB->GetGeoObj( Id.nId)) ;
|
||||
if ( pCompo != nullptr)
|
||||
pCurve = pCompo->GetCurve( Id.nSub) ;
|
||||
nSubs = 0 ;
|
||||
}
|
||||
return ( pCurve != nullptr) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
ICurve*
|
||||
Milling::GetCurve( SelData Id)
|
||||
{
|
||||
// ammessi : curve o facce di polymesh
|
||||
// nel caso di facce si deve recuperare la linea di base
|
||||
|
||||
// per ora accetto solo curve
|
||||
PtrOwner<ICurve> pCurve ;
|
||||
// se direttamente curva
|
||||
if ( Id.nSub == SEL_SUB_ALL) {
|
||||
// recupero e duplico la curva
|
||||
const ICurve* pOriCurve = ::GetCurve( m_pGeomDB->GetGeoObj( Id.nId)) ;
|
||||
if ( pOriCurve != nullptr)
|
||||
pCurve.Set( pOriCurve->Clone()) ;
|
||||
}
|
||||
// altrimenti sottocurva di composita
|
||||
else {
|
||||
// recupero la composita
|
||||
const ICurveComposite* pCompo = GetCurveComposite( m_pGeomDB->GetGeoObj( Id.nId)) ;
|
||||
if ( pCompo != nullptr) {
|
||||
// duplico la curva semplice
|
||||
const ICurve* pOriCurve = ::GetCurve( pCompo->GetCurve( Id.nSub)) ;
|
||||
if ( pOriCurve != nullptr) {
|
||||
pCurve.Set( pOriCurve->Clone()) ;
|
||||
// recupero estrusione e spessore
|
||||
Vector3d vtExtr ;
|
||||
if ( pCompo->GetExtrusion( vtExtr))
|
||||
pCurve->SetExtrusion( vtExtr) ;
|
||||
double dThick ;
|
||||
if ( pCompo->GetThickness( dThick))
|
||||
pCurve->SetThickness( dThick) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( IsNull( pCurve))
|
||||
return nullptr ;
|
||||
// ne recupero il riferimento globale
|
||||
Frame3d frGlob ;
|
||||
if ( ! m_pGeomDB->GetGlobFrame( Id.nId, frGlob))
|
||||
return nullptr ;
|
||||
// la porto in globale
|
||||
pCurve->ToGlob( frGlob) ;
|
||||
// la restituisco
|
||||
return Release( pCurve) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Milling::Chain( int nGrpDestId)
|
||||
{
|
||||
// vettore puntatori alle curve
|
||||
typedef PtrOwner<ICurve> POWNCURVE ;
|
||||
typedef std::vector<POWNCURVE> POCRVVECTOR ;
|
||||
POCRVVECTOR vpCrvs ;
|
||||
vpCrvs.reserve( m_vId.size()) ;
|
||||
// recupero tutte le curve e le porto in globale
|
||||
for ( const auto& Id : m_vId) {
|
||||
// prendo curva
|
||||
vpCrvs.emplace_back( GetCurve( Id)) ;
|
||||
// ne verifico la validità
|
||||
if ( IsNull( vpCrvs.back())) {
|
||||
string sOut = "Entity " + ToString( Id) + " skipped by Milling" ;
|
||||
LOG_INFO( GetEMkLogger(), sOut.c_str()) ;
|
||||
vpCrvs.back().Reset() ;
|
||||
}
|
||||
}
|
||||
// preparo i dati per il concatenamento
|
||||
double dToler = 10 * EPS_SMALL ;
|
||||
ChainCurves chainC ;
|
||||
chainC.Init( true, dToler, int( vpCrvs.size())) ;
|
||||
for ( size_t i = 0 ; i < vpCrvs.size() ; ++ i) {
|
||||
// recupero la curva e il suo riferimento
|
||||
ICurve* pCrv = Get( vpCrvs[i]) ;
|
||||
if ( pCrv == nullptr)
|
||||
continue ;
|
||||
// recupero i dati della curva necessari al concatenamento e li assegno
|
||||
Point3d ptStart, ptEnd ;
|
||||
Vector3d vtStart, vtEnd ;
|
||||
if ( ! pCrv->GetStartPoint( ptStart) || ! pCrv->GetStartDir( vtStart) ||
|
||||
! pCrv->GetEndPoint( ptEnd) || ! pCrv->GetEndDir( vtEnd))
|
||||
return false ;
|
||||
if ( ! chainC.AddCurve( int( i + 1), ptStart, vtStart, ptEnd, vtEnd))
|
||||
return false ;
|
||||
}
|
||||
// recupero i percorsi concatenati
|
||||
int nCount = 0 ;
|
||||
Point3d ptNear = ORIG ;
|
||||
INTVECTOR vnId2 ;
|
||||
while ( chainC.GetChainFromNear( ptNear, false, vnId2)) {
|
||||
// creo una curva composita
|
||||
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
||||
if ( IsNull( pCrvCompo))
|
||||
return false ;
|
||||
// estrusione e spessore
|
||||
Vector3d vtExtr = Z_AX ;
|
||||
double dThick = 0 ;
|
||||
// vettore Id originali
|
||||
SELVECTOR vId2 ;
|
||||
vId2.reserve( vnId2.size()) ;
|
||||
// recupero le curve semplici e le inserisco nella curva composita
|
||||
for ( size_t i = 0 ; i < vnId2.size() ; ++ i) {
|
||||
int nId = abs( vnId2[i]) - 1 ;
|
||||
bool bInvert = ( vnId2[i] < 0) ;
|
||||
vId2.emplace_back( m_vId[nId]) ;
|
||||
// recupero la curva
|
||||
ICurve* pCrv = Get( vpCrvs[nId]) ;
|
||||
// se necessario, la inverto
|
||||
if ( bInvert)
|
||||
pCrv->Invert() ;
|
||||
// recupero eventuali estrusione e spessore
|
||||
Vector3d vtTemp ;
|
||||
if ( pCrv->GetExtrusion( vtTemp)) {
|
||||
vtExtr = vtTemp ;
|
||||
double dTemp ;
|
||||
if ( pCrv->GetThickness( dTemp) && fabs( dTemp) > fabs( dThick))
|
||||
dThick = dTemp ;
|
||||
}
|
||||
// la aggiungo alla curva composta
|
||||
if ( ! pCrvCompo->AddCurve( ::Release( vpCrvs[nId]), true, dToler))
|
||||
return false ;
|
||||
}
|
||||
// se non sono state inserite curve, vado oltre
|
||||
if ( pCrvCompo->GetCurveNumber() == 0)
|
||||
continue ;
|
||||
// imposto estrusione e spessore
|
||||
pCrvCompo->SetExtrusion( vtExtr) ;
|
||||
pCrvCompo->SetThickness( dThick) ;
|
||||
// aggiorno il nuovo punto vicino
|
||||
pCrvCompo->GetEndPoint( ptNear) ;
|
||||
// creo nuovo gruppo
|
||||
int nPathId = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrpDestId, Frame3d()) ;
|
||||
if ( nPathId == GDB_ID_NULL)
|
||||
return false ;
|
||||
m_pGeomDB->SetName( nPathId, MCH_PATH + ToString( ++ nCount)) ;
|
||||
m_pGeomDB->SetInfo( nPathId, KEY_IDS, ToString( vId2)) ;
|
||||
// inserisco la curva composita nel gruppo destinazione
|
||||
int nNewId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, ::Release( pCrvCompo)) ;
|
||||
if ( nNewId == GDB_ID_NULL)
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user