Files
DarioS ff6aae071a EgtMachKernel 2.4i :
- aggiunta gestione offset assi per visualizzazione
- correzioni in Milling e Pocketing per approcci e retrazioni con TiltingTab (comprende asse rotante tipo ralla).
2022-09-24 18:53:47 +02:00

195 lines
6.2 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2015-2016
//----------------------------------------------------------------------------
// File : Axis.cpp Data : 09.06.16 Versione : 1.6r9
// Contenuto : Oggetto asse per gruppo asse di macchina.
//
//
//
// Modifiche : 24.05.15 DS Creazione modulo.
// 09.06.16 DS Aggiunto token.
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "DllMain.h"
#include "Axis.h"
#include "MachConst.h"
#include "/EgtDev/Include/EGkGdbConst.h"
#include "/EgtDev/Include/EGkUserObjFactory.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EGkUiUnits.h"
using namespace std ;
//----------------------------------------------------------------------------
USEROBJ_REGISTER( "EMkAxis", Axis) ;
//----------------------------------------------------------------------------
const string&
Axis::GetClassName( void) const
{
return USEROBJ_GETNAME( Axis) ;
}
//----------------------------------------------------------------------------
Axis*
Axis::Clone( void) const
{
// alloco oggetto
Axis* pAx = new(nothrow) Axis ;
// eseguo copia dei dati
if ( pAx != nullptr) {
try { pAx->m_nOwnerId = GDB_ID_NULL ;
pAx->m_pGeomDB = nullptr ;
pAx->m_sName = m_sName ;
pAx->m_sToken = m_sToken ;
pAx->m_bInvert = m_bInvert ;
pAx->m_dOffset = m_dOffset ;
pAx->m_nType = m_nType ;
pAx->m_ptPos = m_ptPos ;
pAx->m_vtDir = m_vtDir ;
pAx->m_Stroke = m_Stroke ;
pAx->m_dHomeVal = m_dHomeVal ;
pAx->m_dCurrVal = m_dCurrVal ;
}
catch( ...) {
delete pAx ;
return nullptr ;
}
}
// ritorno l'oggetto
return pAx ;
}
//----------------------------------------------------------------------------
bool
Axis::Dump( string& sOut, bool bMM, const char* szNewLine) const
{
sOut += GetClassName() + szNewLine ;
sOut += "Id=" + ToString( m_nOwnerId) + szNewLine ;
sOut += "Name=" + m_sName + szNewLine ;
sOut += "Token=" + m_sToken + szNewLine ;
sOut += "Type=" + ToString( m_nType) + szNewLine ;
sOut += "Pos=" + ToString( GetInUiUnits( m_ptPos, bMM), 4) + szNewLine ;
sOut += "Dir=" + ToString( m_vtDir) + szNewLine ;
if ( m_nType == MCH_AT_LINEAR)
sOut += "Stroke=" + ToString( GetInUiUnits( m_Stroke.Min, bMM), 4) + "," +
ToString( GetInUiUnits( m_Stroke.Max, bMM), 4) + szNewLine ;
else
sOut += "Stroke=" + ToString( m_Stroke.v, 4) + szNewLine ;
sOut += "HVal=" + ToString( GetInUiUnits( m_dHomeVal, bMM), 4) + szNewLine ;
sOut += "Val=" + ToString( GetInUiUnits( m_dCurrVal, bMM), 4) + szNewLine ;
return true ;
}
//----------------------------------------------------------------------------
bool
Axis::SetOwner( int nId, IGeomDB* pGDB)
{
m_nOwnerId = nId ;
m_pGeomDB = pGDB ;
return ( m_nOwnerId != GDB_ID_NULL && m_pGeomDB != nullptr) ;
}
//----------------------------------------------------------------------------
int
Axis::GetOwner( void) const
{
return m_nOwnerId ;
}
//----------------------------------------------------------------------------
IGeomDB*
Axis::GetGeomDB( void) const
{
return m_pGeomDB ;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
Axis::Axis( void)
: m_nOwnerId( GDB_ID_NULL), m_pGeomDB( nullptr), m_bInvert( false), m_dOffset( 0),
m_nType( MCH_AT_NONE), m_Stroke( {{0,0}}), m_dHomeVal( 0), m_dCurrVal( 0)
{
}
//----------------------------------------------------------------------------
bool
Axis::Set( const string& sName, const string& sToken, bool bInvert, double dOffset,
int nType, const Point3d& ptPos, const Vector3d& vtDir, const STROKE& Stroke, double dHome)
{
m_sName = sName ;
m_sToken = sToken ;
m_bInvert = bInvert ;
m_dOffset = dOffset ;
m_nType = nType ;
m_ptPos = ptPos ;
m_vtDir = vtDir ;
m_Stroke = Stroke ;
m_dHomeVal = dHome ;
m_dCurrVal = 0.0 ;
return m_vtDir.Normalize() ;
}
//----------------------------------------------------------------------------
bool
Axis::Modify( const Point3d& ptPos, double dAxisMaxAdjust)
{
// Verifico che lo spostamento non superi il massimo ammesso
Vector3d vtDelta = ptPos - m_ptPos ;
Vector3d vtDeltaPerp = vtDelta - ( vtDelta * m_vtDir) * m_vtDir ;
if ( vtDeltaPerp.Len() > dAxisMaxAdjust) {
string sOut = " Modify Axis " + m_sName + " Position (" + ToString( ptPos) + ") failed" ;
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
return false ;
}
// Assegno la nuova posizione
m_ptPos = ptPos ;
return true ;
}
//----------------------------------------------------------------------------
bool
Axis::Modify( const Vector3d& vtDir, double dAxisMaxRotAdj)
{
// Verifico che la rotazione non superi il massimo ammesso
Vector3d vtDirN = vtDir ;
double dAngRot ;
if ( ! vtDirN.Normalize() || ! m_vtDir.GetAngle( vtDirN, dAngRot) || abs( dAngRot) > dAxisMaxRotAdj) {
string sOut = " Modify Axis " + m_sName + " Direction (" + ToString( vtDir) + ") failed" ;
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
return false ;
}
// Assegno la nuova direzione
m_vtDir = vtDirN ;
return true ;
}
//----------------------------------------------------------------------------
bool
Axis::Modify( const STROKE& Stroke)
{
m_Stroke = Stroke ;
if ( m_dHomeVal < m_Stroke.Min)
m_dHomeVal = m_Stroke.Min ;
else if ( m_dHomeVal > m_Stroke.Max)
m_dHomeVal = m_Stroke.Max ;
return true ;
}
//----------------------------------------------------------------------------
bool
Axis::Modify( double dHome)
{
if ( dHome < m_Stroke.Min)
m_dHomeVal = m_Stroke.Min ;
else if ( dHome > m_Stroke.Max)
m_dHomeVal = m_Stroke.Max ;
else
m_dHomeVal = dHome ;
return true ;
}