6bd14f9948
- aggiunto a assi macchina il dato Use per classificarli come generali, di disposizione o altro (solo i generali che non dipendono da una tavola possono essere usati per i movimenti di lavorazione).
341 lines
10 KiB
C++
341 lines
10 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2015-2015
|
|
//----------------------------------------------------------------------------
|
|
// File : MachineAxes.cpp Data : 11.05.15 Versione : 1.6e3
|
|
// Contenuto : Implementazione gestione macchina : funzioni per assi.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 11.05.15 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "MachMgr.h"
|
|
#include "DllMain.h"
|
|
#include "Axis.h"
|
|
#include "/EgtDev/Include/EGkGeoVector3d.h"
|
|
#include "/EgtDev/Include/EGnStringUtils.h"
|
|
#include "/EgtDev/Include/EGnFileUtils.h"
|
|
#include "/EgtDev/Include/EgtNumUtils.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::GetAllAxesIds( INTVECTOR& vIds) const
|
|
{
|
|
// reset lista identificativi
|
|
vIds.clear() ;
|
|
// ricerca degli assi
|
|
for ( const auto& snGro : m_mapGroups) {
|
|
if ( IsAxisGroup( snGro.second))
|
|
vIds.push_back( snGro.second) ;
|
|
}
|
|
// se richiesto, ordino alfabeticamente
|
|
sort( vIds.begin(), vIds.end()) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::GetAllAxesNames( STRVECTOR& vNames) const
|
|
{
|
|
// reset lista nomi
|
|
vNames.clear() ;
|
|
// ricerca degli assi
|
|
for ( const auto& snGro : m_mapGroups) {
|
|
if ( IsAxisGroup( snGro.second))
|
|
vNames.push_back( snGro.first) ;
|
|
}
|
|
// se richiesto, ordino alfabeticamente
|
|
sort( vNames.begin(), vNames.end()) ;
|
|
return true ;
|
|
}
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::GetAxisName( int nAxId, string& sName) const
|
|
{
|
|
// recupero il relativo gestore
|
|
const Axis* pAx = GetAxis( nAxId) ;
|
|
if ( pAx == nullptr)
|
|
return false ;
|
|
// recupero il token dell'asse
|
|
sName = pAx->GetName() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::GetAxisToken( const string& sAxis, string& sToken) const
|
|
{
|
|
// controllo GeomDB
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// recupero il relativo gestore
|
|
const Axis* pAx = GetAxis( GetGroup( sAxis)) ;
|
|
if ( pAx == nullptr)
|
|
return false ;
|
|
// recupero il token dell'asse
|
|
sToken = pAx->GetToken() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::GetAxisInvert( const string& sAxis, bool& bInvert) const
|
|
{
|
|
// controllo GeomDB
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// recupero il relativo gestore
|
|
const Axis* pAx = GetAxis( GetGroup( sAxis)) ;
|
|
if ( pAx == nullptr)
|
|
return false ;
|
|
// recupero il flag di inversione dell'asse in visualizzazione
|
|
bInvert = pAx->GetInvert() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::GetAxisOffset( const string& sAxis, double& dOffset) const
|
|
{
|
|
// controllo GeomDB
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// recupero il relativo gestore
|
|
const Axis* pAx = GetAxis( GetGroup( sAxis)) ;
|
|
if ( pAx == nullptr)
|
|
return false ;
|
|
// recupero il valore di offset dell'asse in visualizzazione
|
|
dOffset = pAx->GetOffset() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::GetAxisType( const string& sAxis, bool& bLinear) const
|
|
{
|
|
// controllo GeomDB
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// recupero il relativo gestore
|
|
const Axis* pAx = GetAxis( GetGroup( sAxis)) ;
|
|
if ( pAx == nullptr)
|
|
return false ;
|
|
// recupero il tipo dell'asse
|
|
bLinear = ( pAx->GetType() == MCH_AT_LINEAR) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::GetAxisDir( const string& sAxis, Vector3d& vtDir) const
|
|
{
|
|
// controllo GeomDB
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// recupero il relativo gestore
|
|
const Axis* pAx = GetAxis( GetGroup( sAxis)) ;
|
|
if ( pAx == nullptr)
|
|
return false ;
|
|
// recupero la direzione dell'asse
|
|
vtDir = pAx->GetDir() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::SetAxisPos( const string& sAxis, double dVal, bool bInStroke, double* pdNewVal)
|
|
{
|
|
// controllo GeomDB
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// recupero il gruppo dell'asse
|
|
int nAxGrp = GetGroup( sAxis) ;
|
|
// recupero il relativo gestore
|
|
Axis* pAx = GetAxis( nAxGrp) ;
|
|
if ( pAx == nullptr)
|
|
return false ;
|
|
// tipo di asse
|
|
bool bLinear = ( pAx->GetType() != MCH_AT_ROTARY) ;
|
|
// posizione attuale
|
|
double dCurrVal = pAx->GetCurrVal() ;
|
|
// limiti della corsa
|
|
STROKE Stroke = pAx->GetStroke() ;
|
|
// se rotante e corrente, verifico se ci sono limitazioni aggiuntive (dalla testa)
|
|
if ( ! bLinear) {
|
|
for ( const auto& CalcRotAx : m_vCalcRotAx) {
|
|
if ( CalcRotAx.nGrpId == nAxGrp) {
|
|
Stroke.Min = max( Stroke.Min, CalcRotAx.stroke.Min) ;
|
|
Stroke.Max = min( Stroke.Max, CalcRotAx.stroke.Max) ;
|
|
}
|
|
}
|
|
}
|
|
// recupero il vettore dell'asse
|
|
int nV = m_pGeomDB->GetFirstNameInGroup( nAxGrp, sAxis) ;
|
|
const IGeoVector3d* pGV = GetGeoVector3d( m_pGeomDB->GetGeoObj( nV)) ;
|
|
if ( pGV == nullptr)
|
|
return false ;
|
|
Point3d ptPos = pGV->GetBase() ;
|
|
Vector3d vtDir = pGV->GetVector() ;
|
|
vtDir.Normalize() ;
|
|
// se richiesto, limito il movimento alla corsa dell'asse
|
|
if ( bInStroke)
|
|
dVal = Clamp( dVal, Stroke.Min, Stroke.Max) ;
|
|
// eseguo il movimento
|
|
if ( bLinear)
|
|
m_pGeomDB->TranslateGroup( nAxGrp, vtDir * ( dVal - dCurrVal)) ;
|
|
else
|
|
m_pGeomDB->RotateGroup( nAxGrp, ptPos, vtDir, ( dVal - dCurrVal)) ;
|
|
// se richiesto, restituisco la nuova posizione
|
|
if ( pdNewVal != nullptr)
|
|
*pdNewVal = dVal ;
|
|
// salvo la nuova posizione
|
|
return pAx->SetCurrVal( dVal) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::GetAxisPos( const string& sAxis, double& dVal) const
|
|
{
|
|
// controllo GeomDB
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// recupero il relativo gestore
|
|
const Axis* pAx = GetAxis( GetGroup( sAxis)) ;
|
|
if ( pAx == nullptr)
|
|
return false ;
|
|
// recupero la posizione corrente
|
|
dVal = pAx->GetCurrVal() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::GetAxisMin( const string& sAxis, double& dMin) const
|
|
{
|
|
// controllo GeomDB
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// recupero il gestore dell'asse
|
|
const Axis* pAx = GetAxis( GetGroup( sAxis)) ;
|
|
if ( pAx == nullptr)
|
|
return false ;
|
|
// recupero il minimo
|
|
dMin = pAx->GetStroke().Min ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::GetAxisMax( const string& sAxis, double& dMax) const
|
|
{
|
|
// controllo GeomDB
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// recupero il gestore dell'asse
|
|
const Axis* pAx = GetAxis( GetGroup( sAxis)) ;
|
|
if ( pAx == nullptr)
|
|
return false ;
|
|
// recupero il massimo
|
|
dMax = pAx->GetStroke().Max ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::GetAxisHomePos( const string& sAxis, double& dHomeVal) const
|
|
{
|
|
// controllo GeomDB
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// recupero il gestore dell'asse
|
|
const Axis* pAx = GetAxis( GetGroup( sAxis)) ;
|
|
if ( pAx == nullptr)
|
|
return false ;
|
|
// recupero la posizione home
|
|
dHomeVal = pAx->GetHomeVal() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::IsDispositionAxis( int nAxisId, int nTableId) const
|
|
{
|
|
// se non dichiarato o ausiliario
|
|
const Axis* pAx = GetAxis( nAxisId) ;
|
|
if ( pAx == nullptr || pAx->GetUse() == MCH_AU_AUXILIAR)
|
|
return false ;
|
|
// se dichiarato di disposizione
|
|
if ( pAx->GetUse() == MCH_AU_DISPOSITION)
|
|
return true ;
|
|
// altrimenti è di tipo generale e va bene solo se dipende direttamente o indirettamente dalla tavola
|
|
// se direttamente dipendente dalla tavola
|
|
int nParentId = m_pGeomDB->GetParentId( nAxisId) ;
|
|
if ( ( nTableId != GDB_ID_NULL && nParentId == nTableId) || IsTableGroup( nParentId))
|
|
return true ;
|
|
// altrimenti deve dipendere da asse dipendente dalla tavola
|
|
if ( ! IsAxisGroup( nParentId))
|
|
return false ;
|
|
int nGrParId = m_pGeomDB->GetParentId( nParentId) ;
|
|
return ( ( nTableId != GDB_ID_NULL && nGrParId == nTableId) || IsTableGroup( nGrParId)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::IsDispositionAxis( const string& sAxis, const string& sTable) const
|
|
{
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// recupero Id asse
|
|
int nAxId = GetAxisId( sAxis) ;
|
|
if ( nAxId == GDB_ID_NULL)
|
|
return false ;
|
|
// recupero eventuale Id tavola
|
|
int nTabId = GDB_ID_NULL ;
|
|
if ( ! sTable.empty()) {
|
|
nTabId = GetTableId( sTable) ;
|
|
if ( nTabId == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
// eseguo
|
|
return IsDispositionAxis( nAxId, nTabId) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::ResetAxisPos( const string& sAxis)
|
|
{
|
|
// controllo GeomDB
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// recupero la posizione home
|
|
double dHomeVal ;
|
|
if ( ! GetAxisHomePos( sAxis, dHomeVal))
|
|
return false ;
|
|
// eseguo il movimento
|
|
return SetAxisPos( sAxis, dHomeVal) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::ResetAllAxesPos( bool bStdAxes, bool bDispAxes)
|
|
{
|
|
// ciclo sui gruppi della macchina
|
|
for ( auto Iter = m_mapGroups.cbegin() ; Iter != m_mapGroups.cend() ; ++ Iter) {
|
|
if ( IsAxisGroup( Iter->second)) {
|
|
if ( ( bStdAxes && bDispAxes) ||
|
|
( bStdAxes && ! IsDispositionAxis( Iter->first)) ||
|
|
( bDispAxes && IsDispositionAxis( Iter->first))) {
|
|
if ( ! ResetAxisPos( Iter->first))
|
|
return false ;
|
|
}
|
|
}
|
|
}
|
|
return true ;
|
|
}
|