Files
EgtMachKernel/Milling.cpp
T
Dario Sassi cc2a72d5af EgtMachKernel 1.6l3 :
- aggiunta prima gestione preview tagli con lama.
2015-12-15 14:48:11 +00:00

463 lines
14 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : Milling.cpp Data : 07.06.15 Versione : 1.6f2
// Contenuto : Implementazione gestione fresature.
//
//
//
// Modifiche : 07.06.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#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 ;
//----------------------------------------------------------------------------
USEROBJ_REGISTER( "EMkMilling", Milling) ;
//----------------------------------------------------------------------------
const string&
Milling::GetClassName( void) const
{
return USEROBJ_GETNAME( Milling) ;
}
//----------------------------------------------------------------------------
Milling*
Milling::Clone( void) const
{
// alloco oggetto
Milling* pMill = new(nothrow) Milling ;
// eseguo copia dei dati
if ( pMill != nullptr) {
try {
pMill->m_Params = m_Params ;
pMill->m_TParams = m_TParams ;
}
catch( ...) {
delete pMill ;
return nullptr ;
}
}
// ritorno l'oggetto
return pMill ;
}
//----------------------------------------------------------------------------
bool
Milling::Dump( string& sOut, bool bMM, const char* szNewLine) const
{
sOut += GetClassName() + "[mm]" + szNewLine ;
sOut += KEY_IDS + EQUAL + ToString( m_vId) + szNewLine ;
for ( int i = 0 ; i < m_Params.GetSize() ; ++ i)
sOut += m_Params.ToString( i) + szNewLine ;
for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i)
sOut += m_TParams.ToString( i) + szNewLine ;
return true ;
}
//----------------------------------------------------------------------------
bool
Milling::Save( STRVECTOR& vString) const
{
try {
int nSize = 1 + m_Params.GetSize() + m_TParams.GetSize() ;
vString.insert( vString.begin(), nSize, "") ;
int k = - 1 ;
if ( ! SetVal( KEY_IDS, m_vId, vString[++k]))
return false ;
for ( int i = 0 ; i < m_Params.GetSize() ; ++ i)
vString[++k] = m_Params.ToString( i) ;
for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i)
vString[++k] = m_TParams.ToString( i) ;
}
catch( ...) {
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
Milling::Load( const STRVECTOR& vString)
{
int nSize = 1 + m_Params.GetSize() + m_TParams.GetSize() ;
if ( int( vString.size()) < nSize)
return false ;
int k = - 1 ;
if ( ! GetVal( vString[++k], KEY_IDS, m_vId))
return false ;
for ( int i = 0 ; i < m_Params.GetSize() ; ++ i) {
int nKey ;
if ( ! m_Params.FromString( vString[++k], nKey) || nKey != i)
return false ;
}
for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i) {
int nKey ;
if ( ! m_TParams.FromString( vString[++k], nKey) || nKey != i)
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
Milling::Milling( void)
{
m_Params.m_sName = "*" ;
m_Params.m_sToolName = "*" ;
m_TParams.m_sName = "*" ;
m_TParams.m_sHead = "*" ;
}
//----------------------------------------------------------------------------
bool
Milling::Prepare( const string& sMillName)
{
// verifico il gestore lavorazioni
if ( m_pMchMgr == nullptr)
return false ;
// recupero il gestore DB utensili della macchina corrente
ToolsMgr* pTMgr = m_pMchMgr->GetCurrToolsMgr() ;
if ( pTMgr == nullptr)
return false ;
// recupero il gestore DB lavorazioni della macchina corrente
MachiningsMgr* pMMgr = m_pMchMgr->GetCurrMachiningsMgr() ;
if ( pMMgr == nullptr)
return false ;
// ricerca della lavorazione di libreria con il nome indicato
const MillingData* pDdata = GetMillingData( pMMgr->GetMachining( sMillName)) ;
if ( pDdata == nullptr)
return false ;
m_Params = *pDdata ;
// ricerca dell'utensile usato dalla lavorazione
const ToolData* pTdata = pTMgr->GetTool( m_Params.m_ToolUuid) ;
if ( pTdata == nullptr)
return false ;
m_TParams = *pTdata ;
m_Params.m_sToolName = m_TParams.m_sName ;
return true ;
}
//----------------------------------------------------------------------------
bool
Milling::SetParam( int nType, bool bVal)
{
return false ;
}
//----------------------------------------------------------------------------
bool
Milling::SetParam( int nType, int nVal)
{
return false ;
}
//----------------------------------------------------------------------------
bool
Milling::SetParam( int nType, double dVal)
{
return false ;
}
//----------------------------------------------------------------------------
bool
Milling::SetParam( int nType, const string& sVal)
{
return false ;
}
//----------------------------------------------------------------------------
bool
Milling::SetGeometry( const SELVECTOR& vIds)
{
return false ;
}
//----------------------------------------------------------------------------
bool
Milling::Preview( bool bRecalc)
{
return false ;
}
//----------------------------------------------------------------------------
bool
Milling::Apply( bool bRecalc)
{
return false ;
}
//----------------------------------------------------------------------------
bool
Milling::GetParam( int nType, bool& bVal) const
{
return false ;
}
//----------------------------------------------------------------------------
bool
Milling::GetParam( int nType, int& nVal) const
{
return false ;
}
//----------------------------------------------------------------------------
bool
Milling::GetParam( int nType, double& dVal) const
{
switch ( nType) {
case MPA_TOOLSPEED :
dVal = m_TParams.m_dSpeed ;
return true ;
case MPA_TOOLFEED :
dVal = m_TParams.m_dFeed ;
return true ;
case MPA_TOOLSTARTFEED :
dVal = m_TParams.m_dStartFeed ;
return true ;
case MPA_TOOLENDFEED :
dVal = m_TParams.m_dEndFeed ;
return true ;
case MPA_TOOLTIPFEED :
dVal = m_TParams.m_dTipFeed ;
return true ;
case MPA_TOOLOFFSR :
dVal = m_TParams.m_dOffsR ;
return true ;
case MPA_TOOLOFFSL :
dVal = m_TParams.m_dOffsL ;
return true ;
case MPA_STARTPOS :
dVal = m_Params.m_dStartPos ;
return true ;
case MPA_SIDEANGLE :
dVal = m_Params.m_dSideAngle ;
return true ;
}
return false ;
}
//----------------------------------------------------------------------------
bool
Milling::GetParam( int nType, string& sVal) const
{
switch ( nType) {
case MPA_NAME :
sVal = m_Params.m_sName ;
return true ;
case MPA_TOOL :
sVal = m_Params.m_sToolName ;
return true ;
case MPA_DEPTH_STR :
sVal = m_Params.m_sDepth ;
return true ;
case MPA_TUUID :
sVal = ToString( m_Params.m_ToolUuid) ;
return true ;
case MPA_UUID :
sVal = ToString( m_Params.m_Uuid) ;
return true ;
}
return false ;
}
//----------------------------------------------------------------------------
const ToolData&
Milling::GetToolData( void) const
{
return m_TParams ;
}
//----------------------------------------------------------------------------
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)->GetCurveCount() ;
}
// 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->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
Milling::AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP)
{
// non devo fare alcunché
return true ;
}