EgtMachKernel :

- gestione rinvio da sotto con gestione normale e con rotazione alla MDC.
This commit is contained in:
Dario Sassi
2017-06-10 15:44:40 +00:00
parent 948a9b2251
commit 88d87de77e
11 changed files with 373 additions and 1001 deletions
+74 -774
View File
@@ -21,7 +21,6 @@
#include "/EgtDev/Include/EGkCurveArc.h"
#include "/EgtDev/Include/EGkCurveComposite.h"
#include "/EgtDev/Include/EgkArcSpecial.h"
#include "/EgtDev/Include/EgkChainCurves.h"
#include "/EgtDev/Include/EGkSfrCreate.h"
#include "/EgtDev/Include/EGkSurfTriMesh.h"
#include "/EgtDev/Include/EGkUserObjFactory.h"
@@ -39,6 +38,28 @@ using namespace std ;
// 2805 = "Error in GenMachining : link movements not calculable"
// 2806 = "Error in GenMachining : post apply not calculable"
//------------------------------ Constants -----------------------------------
static const string EMC_VAR = "EMC" ; // tabella variabili locali per calcolo
static const string EVAR_MACHID = ".MACHID" ; // IN (int) identificativo della lavorazione
static const string EVAR_GEOM = ".GEOM" ; // IN (table) tabella delle entità da lavorare
static const string EVAR_DEPTH = ".DEPTH" ; // IN (string) affondamento (espressione numerica)
static const string EVAR_TINVERT = ".TOOLINVERT" ; // IN (bool) flag di inversione direzione utensile
static const string EVAR_INVERT = ".INVERT" ; // IN (bool) flag di inversione direzione lavorazione
static const string EVAR_STARTPOS = ".STARTPOS" ; // IN (num) quota di inizio lavorazione (sempre >= 0)
static const string EVAR_OFFSR = ".OFFSR" ; // IN (num) offset radiale
static const string EVAR_OFFSL = ".OFFSL" ; // IN (num) offset longitudinale
static const string EVAR_TOOL = ".TOOL" ; // IN (string) nome dell'utensile
static const string EVAR_FEED = ".FEED" ; // IN (num) feed dell'utensile
static const string EVAR_STARTFEED = ".STARTFEED" ;// IN (num) feed di inizio dell'utensile
static const string EVAR_ENDFEED = ".ENDFEED" ; // IN (num) feed di fine dell'utensile
static const string EVAR_TIPFEED = ".TIPFEED" ; // IN (num) feed di punta dell'utensile
static const string EVAR_SYSNOTES = ".SYSNOTES" ; // IN (string) note interne
static const string EVAR_USERNOTES = ".USERNOTES" ;// IN (string) note dell'utente
static const string EVAR_ERROR = ".ERR" ; // OUT (int) codice di errore ( 0 = ok)
static const string EVAR_MILLS = ".MILLS" ; // OUT (int) numero di percorsi di lavoro
static const string ON_PREVIEW = "OnPreview_" ;
static const string ON_APPLY = "OnApply_" ;
//----------------------------------------------------------------------------
USEROBJ_REGISTER( "EMkGenMachining", GenMachining) ;
@@ -357,34 +378,12 @@ GenMachining::Preview( bool bRecalc)
if ( m_pGeomDB == nullptr || ! m_pGeomDB->ExistsObj( m_nOwnerId))
return false ;
// recupero gruppo per geometria ausiliaria
int nAuxId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_AUX) ;
bool bChain = false ;
// se non c'è, lo aggiungo
if ( nAuxId == GDB_ID_NULL) {
nAuxId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nOwnerId, Frame3d()) ;
if ( nAuxId == GDB_ID_NULL)
return false ;
m_pGeomDB->SetName( nAuxId, MCH_AUX) ;
m_pGeomDB->SetStatus( nAuxId, GDB_ST_OFF) ;
bChain = true ;
}
// altrimenti, se chiesto ricalcolo, lo svuoto
else if ( bRecalc) {
m_pGeomDB->EmptyGroup( nAuxId) ;
bChain = true ;
}
// aggiorno dati geometrici dell'utensile
if ( ! UpdateToolData()) {
LOG_INFO( GetEMkLogger(), "Error in GenMachining : UpdateToolData failed") ;
m_pMchMgr->SetLastError( 2801, "Error in GenMachining : UpdateToolData failed") ;
return false ;
}
// se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria
if ( bChain && ! Chain( nAuxId))
return false ;
// recupero gruppo per geometria di Preview
int nPvId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_PV) ;
// se non c'è, lo aggiungo
@@ -398,12 +397,57 @@ GenMachining::Preview( bool bRecalc)
else
m_pGeomDB->EmptyGroup( nPvId) ;
// lavoro ogni singola catena
int nPathId = m_pGeomDB->GetFirstGroupInGroup( nAuxId) ;
while ( nPathId != GDB_ID_NULL) {
if ( ! ProcessPath( nPathId, nPvId, GDB_ID_NULL))
return false ;
nPathId = m_pGeomDB->GetNextGroup( nPathId) ;
// recupero la macchina corrente
Machine* pMch = m_pMchMgr->GetCurrMachine() ;
if ( pMch == nullptr)
return false ;
// nome della funzione lua da Ini della macchina
string sMachIni = pMch->GetMachineDir() + "\\" + pMch->GetMachineName() + ".ini" ;
string sKey = GENMACHINING_SCRIPT_KEY + ToString( m_Params.m_nSubType) ;
string sName = GetPrivateProfileStringUtf8( GENMACHINING_SEC.c_str(), sKey.c_str(), "", sMachIni.c_str()) ;
string sPreview = ON_PREVIEW + sName ;
// verifico esistenza funzione
if ( ! pMch->LuaExistsFunction( sPreview)) {
string sErr = "Error in GenMachining : missing Script " + sPreview ;
m_pMchMgr->SetLastError( 2802, sErr) ;
return false ;
}
// imposto stato
bool bOk = true ;
int nErr = 99 ;
// imposto valori parametri
bOk = bOk && pMch->LuaCreateGlobTable( EMC_VAR) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_MACHID, m_nOwnerId) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_GEOM, m_vId) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_DEPTH, m_Params.m_sDepth) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_TINVERT, m_Params.m_bToolInvert) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_INVERT, m_Params.m_bInvert) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_STARTPOS, m_Params.m_dStartPos) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_OFFSR, GetOffsR()) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_OFFSL, GetOffsL()) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_TOOL, m_TParams.m_sName) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_FEED, GetFeed()) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_STARTFEED, GetStartFeed()) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_ENDFEED, GetEndFeed()) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_TIPFEED, GetTipFeed()) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_SYSNOTES, m_Params.m_sSysNotes) ;
bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_USERNOTES, m_Params.m_sUserNotes) ;
// eseguo
bOk = bOk && pMch->LuaCallFunction( sPreview, false) ;
// recupero valori parametri obbligatori
bOk = bOk && pMch->LuaGetGlobVar( EMC_VAR + EVAR_ERROR, nErr) ;
bOk = bOk && pMch->LuaGetGlobVar( EMC_VAR + EVAR_MILLS, m_nMills) ;
// reset
bOk = bOk && pMch->LuaResetGlobVar( EMC_VAR) ;
// segnalo errori
if ( ! bOk || nErr != 0) {
m_nMills = 0 ;
string sErr = "Error in GenMachining : Error in " + sPreview + " (" + ToString( nErr) + ")" ;
m_pMchMgr->SetLastError( 2803, sErr) ;
return false ;
}
return true ;
@@ -439,27 +483,6 @@ GenMachining::Apply( bool bRecalc)
else
m_pGeomDB->EmptyGroup( nClId) ;
// costanti
static const string EMC_VAR = "EMC" ; // tabella variabili locali per calcolo
static const string EVAR_MACHID = ".MACHID" ; // IN (int) identificativo della lavorazione
static const string EVAR_GEOM = ".GEOM" ; // IN (table) tabella delle entità da lavorare
static const string EVAR_DEPTH = ".DEPTH" ; // IN (string) affondamento (espressione numerica)
static const string EVAR_TINVERT = ".TOOLINVERT" ; // IN (bool) flag di inversione direzione utensile
static const string EVAR_INVERT = ".INVERT" ; // IN (bool) flag di inversione direzione lavorazione
static const string EVAR_STARTPOS = ".STARTPOS" ; // IN (num) quota di inizio lavorazione (sempre >= 0)
static const string EVAR_OFFSR = ".OFFSR" ; // IN (num) offset radiale
static const string EVAR_OFFSL = ".OFFSL" ; // IN (num) offset longitudinale
static const string EVAR_TOOL = ".TOOL" ; // IN (string) nome dell'utensile
static const string EVAR_FEED = ".FEED" ; // IN (num) feed dell'utensile
static const string EVAR_STARTFEED = ".STARTFEED" ;// IN (num) feed di inizio dell'utensile
static const string EVAR_ENDFEED = ".ENDFEED" ; // IN (num) feed di fine dell'utensile
static const string EVAR_TIPFEED = ".TIPFEED" ; // IN (num) feed di punta dell'utensile
static const string EVAR_SYSNOTES = ".SYSNOTES" ; // IN (string) note interne
static const string EVAR_USERNOTES = ".USERNOTES" ;// IN (string) note dell'utente
static const string EVAR_ERROR = ".ERR" ; // OUT (int) codice di errore ( 0 = ok)
static const string EVAR_MILLS = ".MILLS" ; // OUT (int) numero di percorsi di lavoro
static const string ON_APPLY = "OnApply_" ;
// recupero la macchina corrente
Machine* pMch = m_pMchMgr->GetCurrMachine() ;
if ( pMch == nullptr)
@@ -750,261 +773,6 @@ GenMachining::VerifyGeometry( SelData Id, int& nSubs, int& nType)
return false ;
}
//----------------------------------------------------------------------------
ICurve*
GenMachining::GetCurve( SelData Id)
{
// ammessi : curve o facce di polymesh
const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( Id.nId) ;
if ( pGObj == nullptr)
return nullptr ;
// ne recupero il riferimento globale
Frame3d frGlob ;
if ( ! m_pGeomDB->GetGlobFrame( Id.nId, frGlob))
return nullptr ;
// se curva
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
PtrOwner<ICurve> pCurve ;
// se direttamente curva
if ( Id.nSub == SEL_SUB_ALL) {
// recupero e duplico la curva
const ICurve* pOriCurve = ::GetCurve( pGObj) ;
if ( pOriCurve != nullptr)
pCurve.Set( pOriCurve->Clone()) ;
// se estrusione mancante, imposto default
Vector3d vtExtr ;
if ( ! pCurve->GetExtrusion( vtExtr) || vtExtr.IsSmall())
pCurve->SetExtrusion( Z_AX) ;
}
// altrimenti sottocurva di composita
else {
// recupero la composita
const ICurveComposite* pCompo = GetCurveComposite( pGObj) ;
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) || vtExtr.IsSmall())
vtExtr = Z_AX ;
pCurve->SetExtrusion( vtExtr) ;
double dThick ;
if ( pCompo->GetThickness( dThick))
pCurve->SetThickness( dThick) ;
}
}
}
if ( IsNull( pCurve))
return nullptr ;
// la porto in globale
pCurve->ToGlob( frGlob) ;
// la restituisco
return Release( pCurve) ;
}
// se altrimenti superficie
else if ( ( pGObj->GetType() & GEO_SURF) != 0) {
// recupero la trimesh
const ISurfTriMesh* pSurf = ::GetSurfTriMesh( pGObj) ;
if ( pSurf == nullptr)
return nullptr ;
// recupero l'indice della faccia
int nFacet = ( ( Id.nSub == SEL_SUB_ALL) ? 0 : Id.nSub) ;
// recupero i contorni della faccia
POLYLINEVECTOR vPL ;
pSurf->GetFacetLoops( nFacet, vPL) ;
if ( vPL.empty())
return nullptr ;
// recupero la normale esterna della faccia
Vector3d vtN ;
if ( ! pSurf->GetFacetNormal( nFacet, vtN))
return nullptr ;
// creo la curva a partire da quello esterno
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
pCrvCompo->FromPolyLine( vPL[0]) ;
if ( ! pCrvCompo->IsValid())
return nullptr ;
// assegno l'estrusione dalla normale alla faccia
pCrvCompo->SetExtrusion( vtN) ;
// la porto in globale
pCrvCompo->ToGlob( frGlob) ;
// sistemazioni varie
AdjustCurveFromSurf( pCrvCompo) ;
// la restituisco
return Release( pCrvCompo) ;
}
// altrimenti errore
else
return nullptr ;
}
//----------------------------------------------------------------------------
bool
GenMachining::AdjustCurveFromSurf( ICurveComposite* pCrvCompo)
{
// con utensile fresa fa il contorno
if ( ( m_TParams.m_nType & TF_SAWBLADE) == 0) {
// cerco l'estremo più alto e lo imposto come inizio
double dU = 0 ;
double dUmax = 0 ;
double dZmax = - INFINITO ;
Point3d ptP ;
while ( pCrvCompo->GetPointD1D2( dU, ICurve::FROM_MINUS, ptP)) {
if ( ptP.z > dZmax + EPS_SMALL) {
dZmax = ptP.z ;
dUmax = dU ;
}
dU += 1 ;
}
if ( dU != 0)
pCrvCompo->ChangeStartPoint( dUmax) ;
}
// con utensile lama tiene solo la parte sotto
else {
// ingombro
BBox3d b3Box ;
pCrvCompo->GetLocalBBox( b3Box) ;
double dZmin = b3Box.GetMin().z ;
double dZtol = min( ( b3Box.GetMax().z - b3Box.GetMin().z) / 2., 20.) ;
// elimino le linee troppo sopra il minimo dall'inizio e poi dalla fine
const ICurve* pCrv = pCrvCompo->GetFirstCurve() ;
while ( pCrv != nullptr) {
Point3d ptMid ; pCrv->GetMidPoint( ptMid) ;
Vector3d vtDir ; pCrv->GetMidDir( vtDir) ;
if ( ptMid.z > dZmin + dZtol) {
ICurve* pErase = pCrvCompo->RemoveFirstOrLastCurve( false) ;
delete( pErase) ;
pCrv = pCrvCompo->GetFirstCurve() ;
}
else
break ;
}
pCrv = pCrvCompo->GetLastCurve() ;
while ( pCrv != nullptr) {
Point3d ptMid ; pCrv->GetMidPoint( ptMid) ;
Vector3d vtDir ; pCrv->GetMidDir( vtDir) ;
if ( ptMid.z > dZmin + dZtol) {
ICurve* pErase = pCrvCompo->RemoveFirstOrLastCurve( true) ;
delete( pErase) ;
pCrv = pCrvCompo->GetLastCurve() ;
}
else
break ;
}
// verifico il versore estrusione
Vector3d vtN ;
pCrvCompo->GetExtrusion( vtN) ;
if ( vtN.z < - sin( 2 * DEGTORAD)) {
pCrvCompo->Invert() ;
pCrvCompo->Translate( vtN * m_TParams.m_dThick) ;
pCrvCompo->SetExtrusion( - vtN) ;
}
}
return true ;
}
//----------------------------------------------------------------------------
bool
GenMachining::Chain( int nGrpDestId)
{
// vettore puntatori alle curve
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 GenMachining" ;
LOG_INFO( GetEMkLogger(), sOut.c_str()) ;
vpCrvs.back().Reset() ;
}
}
// preparo i dati per il concatenamento
bool bFirst = true ;
Point3d ptNear = ORIG ;
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 = 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 ;
// se prima curva, assegno inizio della ricerca
if ( bFirst) {
ptNear = ptStart + 10 * EPS_SMALL * vtStart ;
bFirst = false ;
}
}
// recupero i percorsi concatenati
int nCount = 0 ;
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 = 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->GetCurveCount() == 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 ;
}
//----------------------------------------------------------------------------
bool
GenMachining::AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) const
@@ -1012,471 +780,3 @@ GenMachining::AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP)
// non devo fare alcunché
return true ;
}
//----------------------------------------------------------------------------
bool
GenMachining::ProcessPath( int nPathId, int nPvId, int nClId)
{
// recupero gruppo per geometria temporanea
const string GRP_TEMP = "Temp" ;
int nTempId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, GRP_TEMP) ;
// se non c'è, lo aggiungo
if ( nTempId == GDB_ID_NULL) {
nTempId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nOwnerId, Frame3d()) ;
if ( nTempId == GDB_ID_NULL)
return false ;
m_pGeomDB->SetName( nTempId, GRP_TEMP) ;
}
// altrimenti lo svuoto
else
m_pGeomDB->EmptyGroup( nTempId) ;
// in ogni caso lo dichiaro temporaneo e non visibile
m_pGeomDB->SetLevel( nTempId, GDB_LV_TEMP) ;
m_pGeomDB->SetStatus( nTempId, GDB_ST_OFF) ;
// copio la curva composita da elaborare
int nCrvId = m_pGeomDB->GetFirstInGroup( nPathId) ;
if ( m_pGeomDB->GetGeoType( nCrvId) != CRV_COMPO)
return false ;
int nCopyId = m_pGeomDB->CopyGlob( nCrvId, GDB_ID_NULL, nTempId) ;
if ( nCopyId == GDB_ID_NULL)
return false ;
ICurveComposite* pCompo = GetCurveComposite( m_pGeomDB->GetGeoObj( nCopyId)) ;
// eventuale inversione percorso
if ( m_Params.m_bInvert)
pCompo->Invert() ;
// recupero estrusione e spessore
Vector3d vtExtr ;
pCompo->GetExtrusion( vtExtr) ;
double dThick ;
pCompo->GetThickness( dThick) ;
// unisco le parti allineate (tranne inizio-fine se chiusa)
if ( ! pCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL, false))
return false ;
// recupero il punto di inizio (per poi salvarlo nelle info di CL path)
Point3d ptStart ;
pCompo->GetStartPoint( ptStart) ;
// recupero il box del grezzo in globale
BBox3d b3Raw ;
if ( ! GetRawGlobBox( m_nPhase, nPathId, 0.5 * m_TParams.m_dDiam, b3Raw) || b3Raw.IsEmpty()) {
LOG_INFO( GetEMkLogger(), "Error in GenMachining : Empty RawBox") ;
return false ;
}
// recupero distanza da fondo dei grezzi interessati dal percorso
double dRbDist = 0 ;
if ( AreSameVectorApprox( vtExtr, Z_AX)) {
if ( ! GetDistanceFromRawBottom( m_nPhase, nCopyId, m_TParams.m_dDiam, dRbDist))
return false ;
}
// valuto l'espressione dell'affondamento
ExeLuaSetGlobNumVar( "TH", abs( dThick)) ;
ExeLuaSetGlobNumVar( "RB", dRbDist) ;
double dDepth ;
string sMyDepth = m_Params.m_sDepth ;
if ( ! ExeLuaEvalNumExpr( ToUpper( sMyDepth), &dDepth)) {
LOG_INFO( GetEMkLogger(), "Error in GenMachining : Depth not computable") ;
return false ;
}
// se spessore positivo, lo sottraggo dal risultato
if ( dThick > 0)
dDepth -= dThick ;
// sottraggo eventuale offset longitudinale
dDepth -= GetOffsL() ;
// recupero nome del path
string sPathName ;
m_pGeomDB->GetName( nPathId, sPathName) ;
// eventuale approssimazione con segmenti di retta
int nSplitArcs = m_pMchMgr->GetCurrMachiningsMgr()->GetSplitArcs() ;
bool bSplitArcs = ( nSplitArcs == SPLAR_ALWAYS ||
( nSplitArcs == SPLAR_NO_XY_PLANE && ! vtExtr.IsZplus()) ||
( nSplitArcs == SPLAR_GEN_PLANE && vtExtr.IsGeneric())) ;
if ( bSplitArcs) {
const double ANG_TOL_MAX_DEG = 90 ;
PolyLine PL ;
if ( pCompo->ApproxWithLines( 50 * EPS_SMALL, ANG_TOL_MAX_DEG, ICurve::APL_SPECIAL, PL)) {
// sostituisco le linee alle curve originali
pCompo->Clear() ;
pCompo->FromPolyLine( PL) ;
// riassegno estrusione e spessore
pCompo->SetExtrusion( vtExtr) ;
pCompo->SetThickness( dThick) ;
}
}
// verifiche sull'ampiezza dell'angolo al centro degli eventuali archi
VerifyArcs( pCompo) ;
// calcolo il versore fresa
Vector3d vtTool = Z_AX ;
if ( ! vtExtr.IsSmall())
vtTool = vtExtr ;
// calcolo l'elevazione massima
double dElev ;
if ( CalcPathElevation( pCompo, vtTool, dDepth, 0.5 * m_TParams.m_dDiam, dElev)) {
if ( dElev < EPS_SMALL && AreSameVectorApprox( vtExtr, Z_AX)) {
BBox3d b3Crv ;
pCompo->GetLocalBBox( b3Crv) ;
dElev = max( 0., b3Raw.GetMax().z - b3Crv.GetMin().z + min( 0., dThick) + dDepth) ;
}
}
else
return false ;
// se richiesta anteprima
if ( nPvId != GDB_ID_NULL) {
// creo gruppo per geometria di lavorazione del percorso
int nPxId = m_pGeomDB->AddGroup( GDB_ID_NULL, nPvId, Frame3d()) ;
if ( nPxId == GDB_ID_NULL)
return false ;
m_pGeomDB->SetName( nPxId, sPathName) ;
m_pGeomDB->SetMaterial( nPxId, GREEN) ;
// creo l'anteprima del percorso
if ( ! GenerateMillingPv( nPxId, pCompo))
return false ;
}
// se richiesta lavorazione
if ( nClId != GDB_ID_NULL) {
// creo gruppo per geometria di lavorazione del percorso
int nPxId = m_pGeomDB->AddGroup( GDB_ID_NULL, nClId, Frame3d()) ;
if ( nPxId == GDB_ID_NULL)
return false ;
m_pGeomDB->SetName( nPxId, sPathName) ;
m_pGeomDB->SetMaterial( nPxId, BLUE) ;
// assegno il vettore estrazione al gruppo del percorso
m_pGeomDB->SetInfo( nPxId, KEY_EXTR, vtTool) ;
// assegno il punto di inizio al gruppo del percorso
m_pGeomDB->SetInfo( nPxId, KEY_START, ptStart) ;
// assegno l'elevazione massima
m_pGeomDB->SetInfo( nPxId, KEY_ELEV, dElev) ;
// Imposto dati comuni
SetPathId( nPxId) ;
SetToolDir( vtTool) ;
// Calcolo la lavorazione
if ( ! AddStandardMilling( pCompo, vtTool, vtExtr, dDepth, dElev, bSplitArcs))
return false ;
// assegno al gruppo l'ingombro del percorso di lavoro
BBox3d b3Grp ;
m_pGeomDB->GetGlobalBBox( nPxId, b3Grp) ;
m_pGeomDB->SetInfo( nPxId, KEY_PMIN, b3Grp.GetMin()) ;
m_pGeomDB->SetInfo( nPxId, KEY_PMAX, b3Grp.GetMax()) ;
}
// incremento numero di fresate
++ m_nMills ;
return true ;
}
//----------------------------------------------------------------------------
bool
GenMachining::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dRad,
double& dElev)
{
dElev = 0 ;
int nMaxInd = pCompo->GetCurveCount() - 1 ;
for ( int i = 0 ; i <= nMaxInd ; ++ i) {
// curva corrente
const ICurve* pCrvC = pCompo->GetCurve( i) ;
// calcolo elevazione
double dCurrElev ;
Point3d ptStart, ptMid, ptEnd ;
pCrvC->GetStartPoint( ptStart) ;
pCrvC->GetMidPoint( ptMid) ;
pCrvC->GetEndPoint( ptEnd) ;
Vector3d vtStartPerp, vtMidPerp, vtEndPerp, vtTg ;
pCrvC->GetStartDir( vtTg) ;
vtStartPerp = vtTg ^ vtTool ;
vtStartPerp.Normalize() ;
vtStartPerp *= dRad ;
pCrvC->GetMidDir( vtTg) ;
vtMidPerp = vtTg ^ vtTool ;
vtMidPerp.Normalize() ;
vtMidPerp *= dRad ;
pCrvC->GetEndDir( vtTg) ;
vtEndPerp = vtTg ^ vtTool ;
vtEndPerp.Normalize() ;
vtEndPerp *= dRad ;
Vector3d vtDepth = vtTool * dDepth ;
// linea centro utensile
if ( GetElevation( m_nPhase, ptStart - vtDepth, ptMid - vtDepth, ptEnd - vtDepth, vtTool, dCurrElev)) {
if ( dCurrElev > dElev)
dElev = dCurrElev ;
}
else {
LOG_INFO( GetEMkLogger(), "Error in GenMachining : Entity GetElevation") ;
return false ;
}
// da una parte
if ( GetElevation( m_nPhase, ptStart + vtStartPerp - vtDepth, ptMid + vtMidPerp - vtDepth,
ptEnd + vtEndPerp - vtDepth, vtTool, dCurrElev)) {
if ( dCurrElev > dElev)
dElev = dCurrElev ;
}
else {
LOG_INFO( GetEMkLogger(), "Error in GenMachining : Entity GetElevation") ;
return false ;
}
// dall'altra parte
if ( GetElevation( m_nPhase, ptStart - vtStartPerp - vtDepth, ptMid - vtMidPerp - vtDepth,
ptEnd - vtEndPerp - vtDepth, vtTool, dCurrElev)) {
if ( dCurrElev > dElev)
dElev = dCurrElev ;
}
else {
LOG_INFO( GetEMkLogger(), "Error in GenMachining : Entity GetElevation") ;
return false ;
}
}
return true ;
}
//----------------------------------------------------------------------------
bool
GenMachining::GenerateMillingPv( int nPathId, const ICurveComposite* pCompo)
{
// creo copia della curva composita
PtrOwner< ICurve> pCrv( pCompo->Clone()) ;
if ( IsNull( pCrv))
return false ;
// calcolo la regione
PtrOwner<ISurfFlatRegion> pSfr ;
pSfr.Set( GetSurfFlatRegionFromFatCurve( Release( pCrv), 0.5 * m_TParams.m_dDiam, false, false)) ;
if ( IsNull( pSfr))
return false ;
// ne recupero il contorno
PtrOwner< ICurve> pCrv2 ;
pCrv2.Set( pSfr->GetLoop( 0, 0)) ;
if ( IsNull( pCrv2))
return false ;
// inserisco la curva nel DB
int nC2Id = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, Release( pCrv2)) ;
if ( nC2Id == GDB_ID_NULL)
return false ;
// assegno nome e colore
m_pGeomDB->SetName( nC2Id, MCH_PV_CUT) ;
m_pGeomDB->SetMaterial( nC2Id, LIME) ;
// eventuali altri contorni ( interni di contornatura chiusa)
const int MAX_INT_LOOP = 1000 ;
for ( int i = 1 ; i <= MAX_INT_LOOP ; ++i) {
PtrOwner< ICurve> pCrv3 ;
pCrv3.Set( pSfr->GetLoop( 0, i)) ;
if ( IsNull( pCrv3))
break ;
// inserisco la curva nel DB
int nC3Id = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, Release( pCrv3)) ;
if ( nC3Id == GDB_ID_NULL)
return false ;
// assegno nome e colore
m_pGeomDB->SetName( nC3Id, MCH_PV_CUT) ;
m_pGeomDB->SetMaterial( nC3Id, LIME) ;
}
// inserisco la regione nel DB
int nRId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, Release( pSfr)) ;
if ( nRId == GDB_ID_NULL)
return false ;
m_pGeomDB->SetName( nRId, MCH_PV_RCUT) ;
m_pGeomDB->SetMaterial( nRId, INVISIBLE) ;
// la copio anche come regione ridotta
int nRrId = m_pGeomDB->Copy( nRId, GDB_ID_NULL, nPathId) ;
if ( nRrId == GDB_ID_NULL)
return false ;
m_pGeomDB->SetName( nRrId, MCH_PV_RRCUT) ;
m_pGeomDB->SetMaterial( nRrId, INVISIBLE) ;
return true ;
}
//----------------------------------------------------------------------------
bool
GenMachining::AddStandardMilling( const ICurveComposite* pCompo, const Vector3d& vtTool, const Vector3d& vtExtr,
double dDepth, double dElev, bool bSplitArcs)
{
// recupero distanza di sicurezza
double dSafeZ = m_pMchMgr->GetCurrMachiningsMgr()->GetSafeZ() ;
// lunghezza di approccio/retrazione
double dAppr = m_Params.m_dStartPos ;
// ciclo sulle curve elementari
bool bClosed = pCompo->IsClosed() ;
int nMaxInd = pCompo->GetCurveCount() - 1 ;
for ( int i = 0 ; i <= nMaxInd ; ++ i) {
// curva corrente
const ICurve* pCrvC = pCompo->GetCurve( i) ;
// copio la curva
PtrOwner<ICurve> pCurve( pCrvC->Clone()) ;
if ( IsNull( pCurve))
return false ;
// aggiungo affondamento
pCurve->Translate( - vtTool * dDepth) ;
// se prima entità, approccio e affondo
if ( i == 0) {
// dati inizio entità
Point3d ptStart ;
pCurve->GetStartPoint( ptStart) ;
Vector3d vtStart ;
pCurve->GetStartDir( vtStart) ;
// determino inizio attacco
Point3d ptP1 = ptStart ;
// aggiungo approccio per frese normali con spazio sopra attacco
if ( ( m_TParams.m_nType & TF_SAWBLADE) == 0) {
// determino elevazione su inizio attacco
double dStElev ;
if ( ! GetElevation( m_nPhase, ptStart - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), dStElev))
dStElev = dElev ;
dStElev -= ( ptP1 - ptStart) * vtExtr ;
// approccio al punto iniziale
if ( ! AddApproach( ptP1, vtTool, dSafeZ, dStElev, dAppr))
return false ;
}
// altrimenti, approccio per lame o diretto
else {
// affondo al punto iniziale
SetFlag( 0) ;
if ( AddRapidStart( ptP1) == GDB_ID_NULL)
return false ;
}
// aggiungo attacco
SetFeed( GetStartFeed()) ;
// ...
}
// elaborazioni sulla curva corrente
if ( pCurve->GetType() == CRV_LINE) {
ICurveLine* pLine = GetCurveLine( pCurve) ;
Point3d ptP3 = pLine->GetEnd() ;
SetFeed( GetFeed()) ;
if ( AddLinearMove( ptP3) == GDB_ID_NULL)
return false ;
}
else if ( pCurve->GetType() == CRV_ARC) {
ICurveArc* pArc = GetCurveArc( pCurve) ;
Point3d ptCen = pArc->GetCenter() ;
double dAngCen = pArc->GetAngCenter() ;
Vector3d vtN = pArc->GetNormVersor() ;
Point3d ptP3 ;
pArc->GetEndPoint( ptP3) ;
SetFeed( GetFeed()) ;
if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL)
return false ;
}
// se ultima entità, uscita e retrazione
if ( i == nMaxInd) {
// dati fine entità
Point3d ptEnd ;
pCurve->GetEndPoint( ptEnd) ;
Vector3d vtEnd ;
pCurve->GetEndDir( vtEnd) ;
// aggiungo uscita
Point3d ptP1 ;
SetFeed( GetStartFeed()) ;
// ...
// aggiungo retrazione per frese normali
if ( ( m_TParams.m_nType & TF_SAWBLADE) == 0) {
double dEndElev ;
if ( ! GetElevation( m_nPhase, ptEnd - 10 * EPS_SMALL * vtTool, vtTool, GetRadiusForStartEndElevation(), dEndElev))
dEndElev = dElev ;
dEndElev -= ( ptP1 - ptEnd) * vtExtr ;
// aggiungo retrazione
if ( ! AddRetract( ptP1, vtTool, dSafeZ, dEndElev, dAppr))
return false ;
}
// per lame non è necessario
}
}
return true ;
}
//----------------------------------------------------------------------------
bool
GenMachining::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr)
{
// se sopra attacco c'è spazio per sicurezza o approccio
if ( dElev + max( dSafeZ, dAppr) > 10 * EPS_SMALL) {
// se distanza di sicurezza minore di distanza di inizio
if ( dSafeZ < dAppr + 10 * EPS_SMALL) {
// 1 -> punto sopra inizio
SetFlag( 1) ;
Point3d ptP1 = ptP + vtTool * ( dElev + dAppr) ;
if ( AddRapidStart( ptP1) == GDB_ID_NULL)
return false ;
}
else {
// 1a -> punto sopra inizio
SetFlag( 1) ;
Point3d ptP1b = ptP + vtTool * ( dElev + dAppr) ;
Point3d ptP1a = ptP1b + vtTool * ( dSafeZ - dAppr) ;
if ( AddRapidStart( ptP1a) == GDB_ID_NULL)
return false ;
// 1b -> punto appena sopra inizio
if ( ( dElev + dAppr) > EPS_SMALL) {
SetFlag( 0) ;
if ( AddRapidMove( ptP1b) == GDB_ID_NULL)
return false ;
}
}
// affondo al punto iniziale
SetFlag( 0) ;
SetFeed( GetTipFeed()) ;
if ( AddLinearMove( ptP) == GDB_ID_NULL)
return false ;
}
else {
// affondo diretto al punto iniziale
SetFlag( 0) ;
if ( AddRapidStart( ptP) == GDB_ID_NULL)
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
GenMachining::AddRetract( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr)
{
// se sopra uscita c'è spazio per sicurezza o approccio
if ( dElev + max( dSafeZ, dAppr) > 10 * EPS_SMALL) {
if ( dSafeZ < dAppr + 10 * EPS_SMALL) {
// 4 -> movimento di risalita sopra il punto finale
SetFeed( GetEndFeed()) ;
Point3d ptP4 = ptP + vtTool * ( dElev + dAppr) ;
if ( AddLinearMove( ptP4) == GDB_ID_NULL)
return false ;
}
else {
// 4a -> movimento di risalita appena sopra il punto finale
Point3d ptP4a = ptP + vtTool * ( dElev + dAppr) ;
if ( dElev + dAppr > EPS_SMALL) {
SetFeed( GetEndFeed()) ;
if ( AddLinearMove( ptP4a) == GDB_ID_NULL)
return false ;
}
// 4b -> movimento di risalita sopra il punto finale
Point3d ptP4b = ptP4a + vtTool * ( dSafeZ - dAppr) ;
if ( AddRapidMove( ptP4b) == GDB_ID_NULL)
return false ;
}
}
return true ;
}
//----------------------------------------------------------------------------
double
GenMachining::GetRadiusForStartEndElevation( void)
{
const double DELTA_ELEV_RAD = 20.0 ;
return ( 0.5 * m_TParams.m_dTDiam + DELTA_ELEV_RAD) ;
}