EgtMachKernel :
- aggiunta gestione prima disposizione in lista operazioni - migliorato controllo dati macchina al caricamento - ora macchina deve essere disegnata e definita cinematicamente con tutti gli assi a 0, si definisce la posizione home e dopo il carico viene posta in questa posizione.
This commit is contained in:
+221
-98
@@ -21,7 +21,7 @@
|
||||
#include "Exit.h"
|
||||
#include "/EgtDev/Include/EGkGeomDB.h"
|
||||
#include "/EgtDev/Include/EGkGeoVector3d.h"
|
||||
#include "/EgtDev/Include/EGnStringUtils.h"
|
||||
#include "/EgtDev/Include/EGkStringUtils3d.h"
|
||||
#include "/EgtDev/Include/EGnFileUtils.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
|
||||
@@ -31,7 +31,9 @@ using namespace std ;
|
||||
Machine::Machine( void)
|
||||
{
|
||||
m_pMchMgr = nullptr ;
|
||||
m_pGeomDB = nullptr ;
|
||||
m_nGroupId = GDB_ID_NULL ;
|
||||
m_nTempGroupId = GDB_ID_NULL ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -45,16 +47,17 @@ void
|
||||
Machine::Clear( void)
|
||||
{
|
||||
// cancellazione eventuali gruppi geometrici associati
|
||||
if ( m_pMchMgr != nullptr && m_pMchMgr->m_pGeomDB != nullptr) {
|
||||
if ( m_pGeomDB != nullptr) {
|
||||
if ( m_nGroupId != GDB_ID_NULL)
|
||||
m_pMchMgr->m_pGeomDB->Erase( m_nGroupId) ;
|
||||
m_pGeomDB->Erase( m_nGroupId) ;
|
||||
if ( m_nTempGroupId != GDB_ID_NULL)
|
||||
m_pMchMgr->m_pGeomDB->Erase( m_nTempGroupId) ;
|
||||
m_pGeomDB->Erase( m_nTempGroupId) ;
|
||||
}
|
||||
// pulizia interprete lua di macchina
|
||||
LuaExit() ;
|
||||
// reset membri
|
||||
m_pMchMgr = nullptr ;
|
||||
m_pGeomDB = nullptr ;
|
||||
m_sName.clear() ;
|
||||
m_sMachineDir.clear() ;
|
||||
m_nGroupId = GDB_ID_NULL ;
|
||||
@@ -65,27 +68,28 @@ Machine::Clear( void)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Machine::Init( const std::string& sMachineName, MachMgr* pMchMgr)
|
||||
Machine::Init( const string& sMachinesDir, const string& sMachineName, MachMgr* pMchMgr)
|
||||
{
|
||||
// pulisco
|
||||
Clear() ;
|
||||
// verifico ambiente
|
||||
if ( pMchMgr == nullptr || pMchMgr->m_nContextId == 0 || pMchMgr->m_pGeomDB == nullptr)
|
||||
if ( pMchMgr == nullptr || pMchMgr->GetContextId() == 0 || pMchMgr->GetGeomDB() == nullptr)
|
||||
return false ;
|
||||
m_pMchMgr = pMchMgr ;
|
||||
m_pGeomDB = m_pMchMgr->GetGeomDB() ;
|
||||
// verifico direttorio dati macchina
|
||||
m_sMachineDir = pMchMgr->m_sMachinesDir + "\\" + sMachineName ;
|
||||
m_sMachineDir = sMachinesDir + "\\" + sMachineName ;
|
||||
if ( ! ExistsDirectory( m_sMachineDir))
|
||||
return false ;
|
||||
// creo il gruppo per la macchina
|
||||
int nId = pMchMgr->m_pGeomDB->InsertGroup( GDB_ID_NULL, pMchMgr->m_nMachAuxId, GDB_LAST_SON, GLOB_FRM) ;
|
||||
int nId = m_pGeomDB->InsertGroup( GDB_ID_NULL, pMchMgr->GetMachAuxId(), GDB_LAST_SON, GLOB_FRM) ;
|
||||
if ( nId == GDB_ID_NULL)
|
||||
return false ;
|
||||
// imposto nome del gruppo
|
||||
pMchMgr->m_pGeomDB->SetName( nId, sMachineName) ;
|
||||
m_pGeomDB->SetName( nId, sMachineName) ;
|
||||
// carico l'interprete lua dedicato alla macchina
|
||||
if ( ! LuaInit( sMachineName)) {
|
||||
pMchMgr->m_pGeomDB->Erase( nId) ;
|
||||
m_pGeomDB->Erase( nId) ;
|
||||
return false ;
|
||||
}
|
||||
// salvo i dati
|
||||
@@ -95,17 +99,19 @@ Machine::Init( const std::string& sMachineName, MachMgr* pMchMgr)
|
||||
string sMachineMde = m_sMachineDir + "\\" + sMachineName + ".Mde" ;
|
||||
bool bOk = LuaExecFile( sMachineMde) ;
|
||||
// cancello il gruppo temporaneo
|
||||
pMchMgr->m_pGeomDB->Erase( m_nTempGroupId) ;
|
||||
m_pGeomDB->Erase( m_nTempGroupId) ;
|
||||
m_nTempGroupId = GDB_ID_NULL ;
|
||||
// in caso di errore, cancello tutta la geometria
|
||||
if ( ! bOk) {
|
||||
pMchMgr->m_pGeomDB->Erase( m_nGroupId) ;
|
||||
pMchMgr->m_pGeomDB->Erase( m_nTempGroupId) ;
|
||||
m_pGeomDB->Erase( m_nGroupId) ;
|
||||
m_pGeomDB->Erase( m_nTempGroupId) ;
|
||||
m_nGroupId = GDB_ID_NULL ;
|
||||
m_nTempGroupId = GDB_ID_NULL ;
|
||||
m_sName.clear() ;
|
||||
m_sMachineDir.clear() ;
|
||||
}
|
||||
// metto tutti gli assi in posizione home
|
||||
bOk = bOk && ResetAllAxesPos() ;
|
||||
return bOk ;
|
||||
}
|
||||
|
||||
@@ -114,15 +120,15 @@ bool
|
||||
Machine::LoadMachineGeometry( const string& sMGeoName, const Vector3d& vtOffset)
|
||||
{
|
||||
// creo un sotto gruppo temporaneo in cui caricare la macchina
|
||||
m_nTempGroupId = m_pMchMgr->m_pGeomDB->AddGroup( GDB_ID_NULL, m_pMchMgr->m_nMachAuxId, GLOB_FRM) ;
|
||||
m_nTempGroupId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_pMchMgr->GetMachAuxId(), GLOB_FRM) ;
|
||||
if ( m_nTempGroupId == GDB_ID_NULL)
|
||||
return false ;
|
||||
// carico la macchina
|
||||
string sMachineNge = m_sMachineDir + "\\" + sMGeoName ;
|
||||
if ( ! m_pMchMgr->m_pGeomDB->Load( sMachineNge, m_nTempGroupId))
|
||||
if ( ! m_pGeomDB->Load( sMachineNge, m_nTempGroupId))
|
||||
return false ;
|
||||
// applico offset
|
||||
return m_pMchMgr->m_pGeomDB->TranslateGlob( m_nTempGroupId, vtOffset) ;
|
||||
return m_pGeomDB->TranslateGlob( m_nTempGroupId, vtOffset) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -133,80 +139,127 @@ Machine::LoadMachineBase( const string& sName, const string& sGeo)
|
||||
string sPart, sLay ;
|
||||
Split( sGeo, "/", true, sPart, sLay) ;
|
||||
// cerco il gruppo nella geometria originale
|
||||
int nPart = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
|
||||
int nLay = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
|
||||
int nPart = m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
|
||||
int nLay = m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
|
||||
if ( nLay == GDB_ID_NULL)
|
||||
return false ;
|
||||
// lo sposto nella radice della macchina
|
||||
if ( ! m_pMchMgr->m_pGeomDB->RelocateGlob( nLay, m_nGroupId, GDB_FIRST_SON))
|
||||
if ( ! m_pGeomDB->RelocateGlob( nLay, m_nGroupId, GDB_FIRST_SON))
|
||||
return false ;
|
||||
// gli assegno il nome
|
||||
m_pMchMgr->m_pGeomDB->SetName( nLay, sName) ;
|
||||
m_pGeomDB->SetName( nLay, sName) ;
|
||||
// lo inserisco nel dizionario dei gruppi della macchina
|
||||
return m_mapGroups.emplace( sName, nLay).second ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Machine::LoadMachineTable( const string& sName, const string& sParent, int nType, const string& sGeo)
|
||||
Machine::LoadMachineTable( const string& sName, const string& sParent, int nType,
|
||||
const Point3d& ptRef1, const string& sGeo)
|
||||
{
|
||||
// recupero pezzo e layer della geometria originale della tavola
|
||||
string sPart, sLay ;
|
||||
Split( sGeo, "/", true, sPart, sLay) ;
|
||||
// cerco il gruppo nella geometria originale
|
||||
int nPart = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
|
||||
int nLay = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
|
||||
int nPart = m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
|
||||
int nLay = m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
|
||||
if ( nLay == GDB_ID_NULL)
|
||||
return false ;
|
||||
// cerco il gruppo padre per spostarvelo
|
||||
int nParentId = GetGroup( sParent) ;
|
||||
if ( nParentId == GDB_ID_NULL ||
|
||||
! m_pMchMgr->m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON))
|
||||
! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON))
|
||||
return false ;
|
||||
// gli assegno il nome
|
||||
m_pMchMgr->m_pGeomDB->SetName( nLay, sName) ;
|
||||
m_pGeomDB->SetName( nLay, sName) ;
|
||||
// installo e inizializzo il gestore della tavola
|
||||
Table* pTab = new(nothrow) Table ;
|
||||
if ( pTab == nullptr)
|
||||
return false ;
|
||||
pTab->Set( sName, nType) ;
|
||||
m_pMchMgr->m_pGeomDB->SetObjUser( nLay, pTab) ;
|
||||
pTab->Set( sName, nType, ptRef1) ;
|
||||
m_pGeomDB->SetObjUser( nLay, pTab) ;
|
||||
// aggiusto la posizione della tavola
|
||||
if ( ! AdjustTablePos( nLay, ptRef1))
|
||||
return false ;
|
||||
// lo inserisco nel dizionario dei gruppi della macchina
|
||||
return m_mapGroups.emplace( sName, nLay).second ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Machine::AdjustTablePos( int nLay, const Point3d& ptRef1)
|
||||
{
|
||||
// riferimento globale del gruppo tavola
|
||||
Frame3d frTable ;
|
||||
m_pGeomDB->GetGroupGlobFrame( nLay, frTable) ;
|
||||
// recupero il primo riferimento della tavola
|
||||
int nRef1 = m_pGeomDB->GetFirstNameInGroup( nLay, MCH_TREF + "1") ;
|
||||
if ( nRef1 == GDB_ID_NULL || m_pGeomDB->GetGeoType( nRef1) != GEO_FRAME3D) {
|
||||
string sOut = " Missing " + MCH_TREF + "1" ;
|
||||
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
|
||||
return false ;
|
||||
}
|
||||
// recupero frame
|
||||
const Frame3d& frFrame = GetGeoFrame3d( m_pGeomDB->GetGeoObj( nRef1))->GetFrame() ;
|
||||
// ne calcolo l'origine in globale
|
||||
Point3d ptPos = frFrame.Orig() ;
|
||||
ptPos.ToGlob( frTable) ;
|
||||
// verifico eventuale aggiustamento di posizione
|
||||
Vector3d vtMove = ptRef1 - ptPos ;
|
||||
if ( ! vtMove.IsSmall()) {
|
||||
string sOut = " Move = (" + ToString( vtMove) + ")" ;
|
||||
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
|
||||
return m_pGeomDB->TranslateGlob( nLay, vtMove) ;
|
||||
}
|
||||
else
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Machine::LoadMachineAxis( const string& sName, const string& sParent, int nType,
|
||||
const Point3d& ptPos, const Vector3d& vtDir,
|
||||
const STROKE& Stroke, const string& sGeo, double dVal)
|
||||
const STROKE& Stroke, const string& sGeo, double dHome)
|
||||
{
|
||||
// verifico sia di tipo ammesso
|
||||
if ( nType != MCH_AT_LINEAR && nType != MCH_AT_ROTARY) {
|
||||
LOG_ERROR( GetEMkLogger(), " Wrong Axis Type") ;
|
||||
return false ;
|
||||
}
|
||||
// recupero pezzo e layer della geometria originale dell'asse
|
||||
string sPart, sLay ;
|
||||
Split( sGeo, "/", true, sPart, sLay) ;
|
||||
// cerco il gruppo nella geometria originale
|
||||
int nPart = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
|
||||
int nLay = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
|
||||
if ( nLay == GDB_ID_NULL)
|
||||
int nPart = m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
|
||||
int nLay = m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
|
||||
if ( nLay == GDB_ID_NULL) {
|
||||
string sOut = " Missing Axis Part " + sPart ;
|
||||
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
|
||||
return false ;
|
||||
}
|
||||
// cerco il gruppo padre per spostarvelo
|
||||
int nParentId = GetGroup( sParent) ;
|
||||
if ( nParentId == GDB_ID_NULL ||
|
||||
! m_pMchMgr->m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON))
|
||||
! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON)) {
|
||||
string sOut = " Missing Parent Group " + sParent ;
|
||||
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
|
||||
return false ;
|
||||
// verifico che il valore sia nei limiti di corsa
|
||||
if ( dVal < Stroke.Min || dVal > Stroke.Max)
|
||||
}
|
||||
// verifico che il valore di home sia nei limiti di corsa
|
||||
if ( dHome < Stroke.Min || dHome > Stroke.Max) {
|
||||
LOG_ERROR( GetEMkLogger(), " Home Position Out of stroke") ;
|
||||
return false ;
|
||||
}
|
||||
// gli assegno il nome
|
||||
m_pMchMgr->m_pGeomDB->SetName( nLay, sName) ;
|
||||
m_pGeomDB->SetName( nLay, sName) ;
|
||||
// installo e inizializzo il gestore dell'asse
|
||||
Axis* pAxis = new(nothrow) Axis ;
|
||||
if ( pAxis == nullptr)
|
||||
return false ;
|
||||
pAxis->Set( sName, nType, ptPos, vtDir, Stroke, dVal) ;
|
||||
m_pMchMgr->m_pGeomDB->SetObjUser( nLay, pAxis) ;
|
||||
// inserisco il vettore rappresentativo dell'asse
|
||||
if ( ! AddAxisVector( nLay, ptPos, vtDir, sName))
|
||||
pAxis->Set( sName, nType, ptPos, vtDir, Stroke, dHome) ;
|
||||
m_pGeomDB->SetObjUser( nLay, pAxis) ;
|
||||
// verifico il vettore rappresentativo dell'asse
|
||||
if ( ! AdjustAxisVector( nLay, sPart, sName, nType, ptPos, vtDir))
|
||||
return false ;
|
||||
// lo inserisco nel dizionario dei gruppi della macchina
|
||||
return m_mapGroups.emplace( sName, nLay).second ;
|
||||
@@ -214,37 +267,68 @@ Machine::LoadMachineAxis( const string& sName, const string& sParent, int nType,
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Machine::AddAxisVector( int nLay, const Point3d& ptPos, const Vector3d& vtDir, const string& sName)
|
||||
Machine::AdjustAxisVector( int nLay, const string& sPart, const string& sName,
|
||||
int nType, const Point3d& ptPos, const Vector3d& vtDir)
|
||||
{
|
||||
// riferimento globale del gruppo asse
|
||||
Frame3d frFrame ;
|
||||
m_pMchMgr->m_pGeomDB->GetGroupGlobFrame( nLay, frFrame) ;
|
||||
// punto base e vettore in locale
|
||||
Point3d ptBase = ptPos ;
|
||||
ptBase.ToLoc( frFrame) ;
|
||||
Vector3d vtAxis = vtDir ;
|
||||
if ( ! vtAxis.Normalize())
|
||||
// verifico presenza vettore asse
|
||||
int nId = m_pGeomDB->GetFirstNameInGroup( nLay, sPart) ;
|
||||
if ( nId == GDB_ID_NULL || m_pGeomDB->GetGeoType( nId) != GEO_VECT3D) {
|
||||
string sOut = " Missing Axis Vector " + sPart ;
|
||||
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
|
||||
return false ;
|
||||
vtAxis *= AXIS_LEN ;
|
||||
vtAxis.ToLoc( frFrame) ;
|
||||
// vettore geometrico
|
||||
PtrOwner<IGeoVector3d> pGeoVct( CreateGeoVector3d()) ;
|
||||
if ( IsNull( pGeoVct) || ! pGeoVct->Set( vtAxis, ptBase))
|
||||
}
|
||||
// lo sposto all'inizio del suo gruppo
|
||||
if ( ! m_pGeomDB->Relocate( nId, nLay, GDB_FIRST_SON))
|
||||
return false ;
|
||||
// lo inserisco al primo posto nel gruppo
|
||||
int nId = m_pMchMgr->m_pGeomDB->InsertGeoObj( GDB_ID_NULL, nLay, GDB_FIRST_SON, Release( pGeoVct)) ;
|
||||
if ( nId == GDB_ID_NULL)
|
||||
return false ;
|
||||
// gli assegno il nome di axis
|
||||
if ( ! m_pMchMgr->m_pGeomDB->SetName( nId, sName))
|
||||
return false ;
|
||||
// gli assegno il colore blu
|
||||
if ( ! m_pMchMgr->m_pGeomDB->SetMaterial( nId, BLUE))
|
||||
// lo rinomino come l'asse
|
||||
if ( ! m_pGeomDB->SetName( nId, sName))
|
||||
return false ;
|
||||
// lo nascondo
|
||||
if ( ! m_pMchMgr->m_pGeomDB->SetStatus( nId, GDB_ST_OFF))
|
||||
if ( ! m_pGeomDB->SetStatus( nId, GDB_ST_OFF))
|
||||
return false ;
|
||||
return true ;
|
||||
|
||||
// riferimento globale del gruppo asse
|
||||
Frame3d frFrame ;
|
||||
m_pGeomDB->GetGroupGlobFrame( nLay, frFrame) ;
|
||||
// recupero punto base e vettore direzione
|
||||
IGeoVector3d* pGeoVct = GetGeoVector3d( m_pGeomDB->GetGeoObj( nId)) ;
|
||||
Point3d ptBase = pGeoVct->GetBase() ;
|
||||
Vector3d vtAxis = pGeoVct->GetVector() ;
|
||||
vtAxis.Normalize() ;
|
||||
// riassegno il vettore normalizzato
|
||||
pGeoVct->ChangeVector( vtAxis) ;
|
||||
// li porto in globale
|
||||
ptBase.ToGlob( frFrame) ;
|
||||
vtAxis.ToGlob( frFrame) ;
|
||||
|
||||
// se asse lineare devo verificarne solo la direzione
|
||||
if ( nType == MCH_AT_LINEAR) {
|
||||
Vector3d vtDirN = vtDir ;
|
||||
if ( ! vtDirN.Normalize() || ! AreSameVectorApprox( vtAxis, vtDirN)) {
|
||||
string sOut = " Wrong Axis Vector or Dir " + sPart ;
|
||||
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
// altrimenti asse rotante, devo verificarne direzione e coassialità
|
||||
else {
|
||||
Vector3d vtDirN = vtDir ;
|
||||
if ( ! vtDirN.Normalize() || ! AreSameVectorApprox( vtAxis, vtDirN)) {
|
||||
string sOut = " Wrong Axis Vector or Dir " + sPart ;
|
||||
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
|
||||
return false ;
|
||||
}
|
||||
Vector3d vtDelta = ptPos - ptBase ;
|
||||
vtDelta -= ( vtDelta * vtDirN) * vtDirN ;
|
||||
if ( ! vtDelta.IsSmall()) {
|
||||
string sOut = " Wrong Axis Base move = (" + ToString( vtDelta) + ")" ;
|
||||
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -257,26 +341,26 @@ Machine::LoadMachineStdHead( const string& sName, const string& sParent, const s
|
||||
string sPart, sLay ;
|
||||
Split( sGeo, "/", true, sPart, sLay) ;
|
||||
// cerco il gruppo nella geometria originale
|
||||
int nPart = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
|
||||
int nLay = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
|
||||
int nPart = m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
|
||||
int nLay = m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
|
||||
if ( nLay == GDB_ID_NULL)
|
||||
return false ;
|
||||
// cerco il gruppo padre per spostarvelo
|
||||
int nParentId = GetGroup( sParent) ;
|
||||
if ( nParentId == GDB_ID_NULL ||
|
||||
! m_pMchMgr->m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON))
|
||||
! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON))
|
||||
return false ;
|
||||
// sistemo lo stato di visualizzazione
|
||||
bool bShow = ( sHSet == sName) ;
|
||||
m_pMchMgr->m_pGeomDB->SetStatus( nLay, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ;
|
||||
m_pGeomDB->SetStatus( nLay, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ;
|
||||
// gli assegno il nome
|
||||
m_pMchMgr->m_pGeomDB->SetName( nLay, sName) ;
|
||||
m_pGeomDB->SetName( nLay, sName) ;
|
||||
// installo e inizializzo il gestore della testa
|
||||
Head* pHead = new(nothrow) Head ;
|
||||
if ( pHead == nullptr)
|
||||
return false ;
|
||||
pHead->Set( sName, MCH_HT_STD, sHSet, vtADir) ;
|
||||
m_pMchMgr->m_pGeomDB->SetObjUser( nLay, pHead) ;
|
||||
m_pGeomDB->SetObjUser( nLay, pHead) ;
|
||||
// aggiorno la testa capostipite
|
||||
if ( ! AddHeadToSet( sHSet, sName))
|
||||
return false ;
|
||||
@@ -299,26 +383,26 @@ Machine::LoadMachineMultiHead( const string& sName, const string& sParent, const
|
||||
string sPart, sLay ;
|
||||
Split( sGeo, "/", true, sPart, sLay) ;
|
||||
// cerco il gruppo nella geometria originale
|
||||
int nPart = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
|
||||
int nLay = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
|
||||
int nPart = m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
|
||||
int nLay = m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
|
||||
if ( nLay == GDB_ID_NULL)
|
||||
return false ;
|
||||
// cerco il gruppo padre per spostarvelo
|
||||
int nParentId = GetGroup( sParent) ;
|
||||
if ( nParentId == GDB_ID_NULL ||
|
||||
! m_pMchMgr->m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON))
|
||||
! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON))
|
||||
return false ;
|
||||
// sistemo lo stato di visualizzazione
|
||||
bool bShow = ( sHSet == sName) ;
|
||||
m_pMchMgr->m_pGeomDB->SetStatus( nLay, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ;
|
||||
m_pGeomDB->SetStatus( nLay, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ;
|
||||
// gli assegno il nome
|
||||
m_pMchMgr->m_pGeomDB->SetName( nLay, sName) ;
|
||||
m_pGeomDB->SetName( nLay, sName) ;
|
||||
// installo e inizializzo il gestore della testa
|
||||
Head* pHead = new(nothrow) Head ;
|
||||
if ( pHead == nullptr)
|
||||
return false ;
|
||||
pHead->Set( sName, MCH_HT_MULTI, sHSet, vtADir) ;
|
||||
m_pMchMgr->m_pGeomDB->SetObjUser( nLay, pHead) ;
|
||||
m_pGeomDB->SetObjUser( nLay, pHead) ;
|
||||
// aggiorno la testa capostipite
|
||||
if ( ! AddHeadToSet( sHSet, sName))
|
||||
return false ;
|
||||
@@ -331,7 +415,7 @@ Machine::LoadMachineMultiHead( const string& sName, const string& sParent, const
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
Machine::GetGroup( const string& sGroup)
|
||||
Machine::GetGroup( const string& sGroup) const
|
||||
{
|
||||
STRINT_UMAP::const_iterator Iter = m_mapGroups.find( sGroup) ;
|
||||
return (( Iter != m_mapGroups.end()) ? Iter->second : GDB_ID_NULL) ;
|
||||
@@ -339,30 +423,30 @@ Machine::GetGroup( const string& sGroup)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Axis*
|
||||
Machine::GetAxis( int nGroup)
|
||||
Machine::GetAxis( int nGroup) const
|
||||
{
|
||||
return ( dynamic_cast<Axis*>( m_pMchMgr->m_pGeomDB->GetObjUser( nGroup))) ;
|
||||
return ( dynamic_cast<Axis*>( m_pGeomDB->GetObjUser( nGroup))) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Table*
|
||||
Machine::GetTable( int nGroup)
|
||||
Machine::GetTable( int nGroup) const
|
||||
{
|
||||
return ( dynamic_cast<Table*>( m_pMchMgr->m_pGeomDB->GetObjUser( nGroup))) ;
|
||||
return ( dynamic_cast<Table*>( m_pGeomDB->GetObjUser( nGroup))) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Head*
|
||||
Machine::GetHead( int nGroup)
|
||||
Machine::GetHead( int nGroup) const
|
||||
{
|
||||
return ( dynamic_cast<Head*>( m_pMchMgr->m_pGeomDB->GetObjUser( nGroup))) ;
|
||||
return ( dynamic_cast<Head*>( m_pGeomDB->GetObjUser( nGroup))) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Exit*
|
||||
Machine::GetExit( int nGroup)
|
||||
Machine::GetExit( int nGroup) const
|
||||
{
|
||||
return ( dynamic_cast<Exit*>( m_pMchMgr->m_pGeomDB->GetObjUser( nGroup))) ;
|
||||
return ( dynamic_cast<Exit*>( m_pGeomDB->GetObjUser( nGroup))) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -382,7 +466,7 @@ Machine::AddHeadToSet( const string& sHSet, const string& sName)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const STRVECTOR&
|
||||
Machine::GetHSet( const string& sHead)
|
||||
Machine::GetHSet( const string& sHead) const
|
||||
{
|
||||
// vettore di stringhe vuoto, da restituire in caso di errore
|
||||
static const STRVECTOR vsNull ;
|
||||
@@ -413,7 +497,7 @@ Machine::EnableHeadInSet( const string& sHead)
|
||||
for ( size_t i = 0 ; i < vsHSet.size() ; ++ i) {
|
||||
int nH = GetGroup( vsHSet[i]) ;
|
||||
bool bShow = ( vsHSet[i] == sHead) ;
|
||||
m_pMchMgr->m_pGeomDB->SetStatus( nH, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ;
|
||||
m_pGeomDB->SetStatus( nH, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
@@ -422,34 +506,73 @@ Machine::EnableHeadInSet( const string& sHead)
|
||||
bool
|
||||
Machine::CreateExitGroups( int nLay, const MUEXITVECTOR& vMuExit)
|
||||
{
|
||||
// riferimento globale del gruppo testa
|
||||
Frame3d frHead ;
|
||||
m_pGeomDB->GetGroupGlobFrame( nLay, frHead) ;
|
||||
// ciclo sulle uscite
|
||||
for ( int i = 0 ; i < int( vMuExit.size()) ; ++ i) {
|
||||
string sName = MCH_EXIT + ToString( i+1) ;
|
||||
// se trovo riferimento per uscita, lo sostituisco con gruppo equivalente
|
||||
int nT = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nLay, sName) ;
|
||||
if ( nT != GDB_ID_NULL && m_pMchMgr->m_pGeomDB->GetGeoType( nT) == GEO_FRAME3D) {
|
||||
const Frame3d& frFrame = GetGeoFrame3d( m_pMchMgr->m_pGeomDB->GetGeoObj( nT))->GetFrame() ;
|
||||
int nGT = m_pMchMgr->m_pGeomDB->InsertGroup( GDB_ID_NULL, nT, GDB_AFTER, frFrame) ;
|
||||
if ( nGT == GDB_ID_NULL) {
|
||||
string sOut = "Error inserting group " + sName ;
|
||||
int nT = m_pGeomDB->GetFirstNameInGroup( nLay, sName) ;
|
||||
if ( nT != GDB_ID_NULL && m_pGeomDB->GetGeoType( nT) == GEO_FRAME3D) {
|
||||
// recupero frame
|
||||
const Frame3d& frFrame = GetGeoFrame3d( m_pGeomDB->GetGeoObj( nT))->GetFrame() ;
|
||||
// verifico dati frame rispetto ad uscita (in globale)
|
||||
Point3d ptPos = frFrame.Orig() ;
|
||||
ptPos.ToGlob( frHead) ;
|
||||
Vector3d vtTDir = frFrame.VersZ() ;
|
||||
vtTDir.ToGlob(frHead) ;
|
||||
vtTDir.Normalize() ;
|
||||
Vector3d vtDelta = vMuExit[i].ptPos - ptPos ;
|
||||
if ( ! vtDelta.IsSmall()) {
|
||||
string sOut = " Wrong Exit Position " + sName + " move = (" + ToString( vtDelta) +")" ;
|
||||
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
|
||||
return false ;
|
||||
}
|
||||
m_pMchMgr->m_pGeomDB->Erase( nT) ;
|
||||
// assegno nome
|
||||
m_pMchMgr->m_pGeomDB->SetName( nGT, sName) ;
|
||||
Vector3d vtDirN = vMuExit[i].vtTDir ;
|
||||
if ( ! vtDirN.Normalize() || ! AreSameVectorApprox( vtTDir, vtDirN)) {
|
||||
string sOut = " Wrong Exit Vector " + sName ;
|
||||
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
|
||||
return false ;
|
||||
}
|
||||
// inserisco gruppo con riferimento del frame
|
||||
int nGT = m_pGeomDB->InsertGroup( GDB_ID_NULL, nT, GDB_BEFORE, frFrame) ;
|
||||
if ( nGT == GDB_ID_NULL) {
|
||||
string sOut = " Error inserting group " + sName ;
|
||||
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
|
||||
return false ;
|
||||
}
|
||||
// cambio nome al riferimento e lo nascondo
|
||||
m_pGeomDB->SetName( nT, "_" + sName) ;
|
||||
m_pGeomDB->SetStatus( nT, GDB_ST_OFF) ;
|
||||
// assegno nome al gruppo
|
||||
m_pGeomDB->SetName( nGT, sName) ;
|
||||
// installo e inizializzo il gestore dell'uscita
|
||||
Exit* pExit = new(nothrow) Exit ;
|
||||
if ( pExit == nullptr)
|
||||
return false ;
|
||||
pExit->Set( sName, vMuExit[i].ptPos, vMuExit[i].vtTDir) ;
|
||||
m_pMchMgr->m_pGeomDB->SetObjUser( nGT, pExit) ;
|
||||
m_pGeomDB->SetObjUser( nGT, pExit) ;
|
||||
}
|
||||
else {
|
||||
string sOut = "Error finding frame " + sName ;
|
||||
string sOut = " Error finding frame " + sName ;
|
||||
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Machine::ResetAllAxesPos( void)
|
||||
{
|
||||
// ciclo sugi gruppi della macchina
|
||||
for ( auto Iter = m_mapGroups.cbegin() ; Iter != m_mapGroups.cend() ; ++ Iter) {
|
||||
if ( IsAxisGroup( Iter->second)) {
|
||||
if ( ! ResetAxisPos( Iter->first))
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
Reference in New Issue
Block a user