Files
EgtMachKernel/CamData.cpp
T
Dario Sassi 2f016585bb EgtMachKernel :
- in calcolo angoli macchina aggiunta segnalazione di direzione utensile irraggiungibile
- in disposizione aggiunti controlli di sottopezzo e grezzo in tavola
- in simulazione la Move ora restituisce uno stato
- migliorato calcolo elevazione per lavorazioni con lama
- la tavola macchina conserva l'area utile.
2015-11-23 09:06:44 +00:00

471 lines
14 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : CamData.cpp Data : 10.06.15 Versione : 1.6f2
// Contenuto : Implementazione informazioni Cam di ogni movimento.
//
//
//
// Modifiche : 10.06.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "CamData.h"
#include "/EgtDev/Include/EGkGeomDB.h"
#include "/EgtDev/Include/EGkUserObjFactory.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EGnStringKeyVal.h"
using namespace std ;
//----------------------------------------------------------------------------
static int CAM_TOTPARAM = 9 ;
static std::string CAM_CORR = "Corr" ;
static std::string CAM_TDIR = "TDir" ;
static std::string CAM_CDIR = "CDir" ;
static std::string CAM_ADIR = "ADir" ;
static std::string CAM_PBAS = "PBas" ;
static std::string CAM_FEED = "Feed" ;
static std::string CAM_FLAG = "Flg" ;
static std::string CAM_AXSTS = "AxS" ;
static std::string CAM_AXVAL = "AxV" ;
//----------------------------------------------------------------------------
USEROBJ_REGISTER( "EMkCamData", CamData) ;
//----------------------------------------------------------------------------
const string&
CamData::GetClassName( void) const
{
return USEROBJ_GETNAME( CamData) ;
}
//----------------------------------------------------------------------------
CamData*
CamData::Clone( void) const
{
// alloco oggetto
CamData* pCam = new(nothrow) CamData ;
// eseguo copia dei dati
if ( pCam != nullptr) {
try {
pCam->m_nOwnerId = GDB_ID_NULL ;
pCam->m_pGeomDB = nullptr ;
pCam->m_nCorre = m_nCorre ;
pCam->m_vtTool = m_vtTool ;
pCam->m_vtCorr = m_vtCorr ;
pCam->m_vtAux = m_vtAux ;
pCam->m_dFeed = m_dFeed ;
pCam->m_nFlag = m_nFlag ;
}
catch( ...) {
delete pCam ;
return nullptr ;
}
}
// ritorno l'oggetto
return pCam ;
}
//----------------------------------------------------------------------------
bool
CamData::Dump( string& sOut, bool bMM, const char* szNewLine) const
{
sOut += GetClassName() + "[mm]" + szNewLine ;
sOut += CAM_CORR + "=" + ToString( m_nCorre) + szNewLine ;
sOut += CAM_TDIR + "=" + ToString( m_vtTool) + szNewLine ;
sOut += CAM_CDIR + "=" + ToString( m_vtCorr) + szNewLine ;
sOut += CAM_ADIR + "=" + ToString( m_vtAux) + szNewLine ;
sOut += CAM_PBAS + "=" + ToString( m_ptBase) + szNewLine ;
sOut += CAM_FEED + "=" + ToString( m_dFeed) + szNewLine ;
sOut += CAM_FLAG + "=" + ToString( m_nFlag) + szNewLine ;
sOut += CAM_AXSTS + "=" + ToString( m_nAxesStatus) + szNewLine ;
sOut += CAM_AXVAL + "=" + ToString( m_vMachAxes) + szNewLine ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::SetOwner( int nId, IGeomDB* pGDB)
{
m_nOwnerId = nId ;
m_pGeomDB = pGDB ;
return ( m_nOwnerId != GDB_ID_NULL && m_pGeomDB != nullptr) ;
}
//----------------------------------------------------------------------------
int
CamData::GetOwner( void) const
{
return m_nOwnerId ;
}
//----------------------------------------------------------------------------
IGeomDB*
CamData::GetGeomDB( void) const
{
return m_pGeomDB ;
}
//----------------------------------------------------------------------------
bool
CamData::Save( STRVECTOR& vString) const
{
try {
vString.insert( vString.begin(), CAM_TOTPARAM, "") ;
int k = - 1 ;
vString[++k] = CAM_CORR + "=" + ToString( m_nCorre) ;
vString[++k] = CAM_TDIR + "=" + ToString( m_vtTool) ;
vString[++k] = CAM_CDIR + "=" + ToString( m_vtCorr) ;
vString[++k] = CAM_ADIR + "=" + ToString( m_vtAux) ;
vString[++k] = CAM_PBAS + "=" + ToString( m_ptBase) ;
vString[++k] = CAM_FEED + "=" + ToString( m_dFeed) ;
vString[++k] = CAM_FLAG + "=" + ToString( m_nFlag) ;
vString[++k] = CAM_AXSTS + "=" + ToString( m_nAxesStatus) ;
vString[++k] = CAM_AXVAL + "=" + ToString( m_vMachAxes) ;
}
catch( ...) {
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::Load( const STRVECTOR& vString)
{
if ( int( vString.size()) < CAM_TOTPARAM)
return false ;
int k = - 1 ;
if ( ! GetVal( vString[++k], CAM_CORR, m_nCorre) ||
! GetVal( vString[++k], CAM_TDIR, m_vtTool) ||
! GetVal( vString[++k], CAM_CDIR, m_vtCorr) ||
! GetVal( vString[++k], CAM_ADIR, m_vtAux) ||
! GetVal( vString[++k], CAM_PBAS, m_ptBase) ||
! GetVal( vString[++k], CAM_FEED, m_dFeed) ||
! GetVal( vString[++k], CAM_FLAG, m_nFlag) ||
! GetVal( vString[++k], CAM_AXSTS, m_nAxesStatus) ||
! GetVal( vString[++k], CAM_AXVAL, m_vMachAxes))
return false ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::GetDrawPolyLines( POLYLINELIST& lstPL) const
{
bool bToDraw = false ;
// se vettore fresa non nullo
if ( ! m_vtTool.IsSmall()) {
bToDraw = true ;
// aggiungo polilinea alla lista
lstPL.emplace_back() ;
PolyLine& PL = lstPL.back() ;
// dimensioni
const double TLEN = 40 ;
const double ALEN = 4 ;
// inserisco disegno nella polilinea
PL.AddUPoint( 0, m_ptBase) ;
Point3d ptTip = m_ptBase + m_vtTool * TLEN ;
PL.AddUPoint( 1, ptTip) ;
// aggiungo simil-freccia
Frame3d frF ;
frF.Set( ptTip, m_vtTool) ;
Point3d ptP2 = ORIG + Vector3d( ALEN, 0, -ALEN) ;
ptP2.ToGlob( frF) ;
PL.AddUPoint( 2, ptP2) ;
Point3d ptP3 = ORIG + Vector3d( -ALEN, 0, -ALEN) ;
ptP3.ToGlob( frF) ;
PL.AddUPoint( 3, ptP3) ;
PL.AddUPoint( 4, ptTip) ;
Point3d ptP5 = ORIG + Vector3d( 0, ALEN, -ALEN) ;
ptP5.ToGlob( frF) ;
PL.AddUPoint( 5, ptP5) ;
Point3d ptP6 = ORIG + Vector3d( 0, -ALEN, -ALEN) ;
ptP6.ToGlob( frF) ;
PL.AddUPoint( 6, ptP6) ;
PL.AddUPoint( 6, ptTip) ;
}
// se vettore correzione non nullo
if ( ! m_vtCorr.IsSmall()) {
bToDraw = true ;
// aggiungo polilinea alla lista
lstPL.emplace_back() ;
PolyLine& PL = lstPL.back() ;
// dimensioni
const double CLEN = 20 ;
const double ALEN = 2 ;
// inserisco disegno nella polilinea
PL.AddUPoint( 0, m_ptBase) ;
Point3d ptTip = m_ptBase + m_vtCorr * CLEN ;
PL.AddUPoint( 1, ptTip) ;
// aggiungo simil-freccia
Frame3d frF ;
if ( m_vtTool. IsSmall())
frF.Set( ptTip, m_vtCorr) ;
else
frF.Set( ptTip, m_vtCorr, m_vtTool) ;
Point3d ptP2 = ORIG + Vector3d( 0, ALEN, 0) ;
ptP2.ToGlob( frF) ;
PL.AddUPoint( 2, ptP2) ;
Point3d ptP3 = ORIG + Vector3d( 0, ALEN, - ALEN) ;
ptP3.ToGlob( frF) ;
PL.AddUPoint( 3, ptP3) ;
Point3d ptP4 = ORIG + Vector3d( 0, 0, - ALEN) ;
ptP4.ToGlob( frF) ;
PL.AddUPoint( 4, ptP4) ;
}
// se vettore ausiliario non nullo
if ( ! m_vtAux.IsSmall()) {
bToDraw = true ;
// aggiungo polilinea alla lista
lstPL.emplace_back() ;
PolyLine& PL = lstPL.back() ;
// dimensioni
const double CLEN = 20 ;
const double ALEN = 2 ;
// inserisco disegno nella polilinea
PL.AddUPoint( 0, m_ptBase) ;
Point3d ptTip = m_ptBase + m_vtAux * CLEN ;
PL.AddUPoint( 1, ptTip) ;
// aggiungo simil-freccia
Frame3d frF ;
if ( m_vtTool. IsSmall())
frF.Set( ptTip, m_vtAux) ;
else
frF.Set( ptTip, m_vtAux, m_vtTool) ;
Point3d ptP2 = ORIG + Vector3d( 0, ALEN, - 0.5 * ALEN) ;
ptP2.ToGlob( frF) ;
PL.AddUPoint( 2, ptP2) ;
Point3d ptP3 = ORIG + Vector3d( 0, 0, - ALEN) ;
ptP3.ToGlob( frF) ;
PL.AddUPoint( 3, ptP3) ;
}
return bToDraw ;
}
//----------------------------------------------------------------------------
bool
CamData::Translate( const Vector3d& vtMove)
{
m_ptBase.Translate( vtMove) ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
{
if ( ! m_ptBase.Rotate( ptAx, vtAx, dCosAng, dSinAng))
return false ;
if ( ! m_vtTool.Rotate( vtAx, dCosAng, dSinAng))
return false ;
if ( ! m_vtCorr.Rotate( vtAx, dCosAng, dSinAng))
return false ;
if ( ! m_vtAux.Rotate( vtAx, dCosAng, dSinAng))
return false ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ)
{
if ( ! m_ptBase.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ))
return false ;
if ( ! m_vtTool.IsSmall()) {
if ( ! m_vtTool.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) || ! m_vtTool.Normalize())
return false ;
}
if ( ! m_vtCorr.IsSmall()) {
double dLen = m_vtCorr.Len() ;
if ( ! m_vtCorr.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) || ! m_vtCorr.Normalize())
return false ;
m_vtCorr *= dLen ;
}
if ( ! m_vtAux.IsSmall()) {
if ( ! m_vtAux.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) || ! m_vtAux.Normalize())
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::Mirror( const Point3d& ptOn, const Vector3d& vtNorm)
{
if ( ! m_ptBase.Mirror( ptOn, vtNorm))
return false ;
if ( ! m_vtTool.Mirror( vtNorm))
return false ;
if ( ! m_vtCorr.Mirror( vtNorm))
return false ;
if ( ! m_vtAux.Mirror( vtNorm))
return false ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff)
{
if ( ! m_ptBase.Shear( ptOn, vtNorm, vtDir, dCoeff))
return false ;
if ( ! m_vtTool.IsSmall()) {
if ( ! m_vtTool.Shear( vtNorm, vtDir, dCoeff) || ! m_vtTool.Normalize())
return false ;
}
if ( ! m_vtCorr.IsSmall()) {
double dLen = m_vtCorr.Len() ;
if ( ! m_vtCorr.Shear( vtNorm, vtDir, dCoeff) || ! m_vtCorr.Normalize())
return false ;
m_vtCorr *= dLen ;
}
if ( ! m_vtAux.IsSmall()) {
if ( ! m_vtAux.Shear( vtNorm, vtDir, dCoeff) || ! m_vtAux.Normalize())
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::ToGlob( const Frame3d& frRef)
{
if ( ! m_ptBase.ToGlob( frRef))
return false ;
if ( ! m_vtTool.ToGlob( frRef))
return false ;
if ( ! m_vtCorr.ToGlob( frRef))
return false ;
if ( ! m_vtAux.ToGlob( frRef))
return false ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::ToLoc( const Frame3d& frRef)
{
if ( ! m_ptBase.ToLoc( frRef))
return false ;
if ( ! m_vtTool.ToLoc( frRef))
return false ;
if ( ! m_vtCorr.ToLoc( frRef))
return false ;
if ( ! m_vtAux.ToLoc( frRef))
return false ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::LocToLoc( const Frame3d& frOri, const Frame3d& frDest)
{
if ( ! m_ptBase.LocToLoc( frOri, frDest))
return false ;
if ( ! m_vtTool.LocToLoc( frOri, frDest))
return false ;
if ( ! m_vtCorr.LocToLoc( frOri, frDest))
return false ;
if ( ! m_vtAux.LocToLoc( frOri, frDest))
return false ;
return true ;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
CamData::CamData( void)
{
m_nOwnerId = GDB_ID_NULL ;
m_pGeomDB = nullptr ;
m_nCorre = 0 ;
m_dFeed = 0 ;
m_nFlag = 0 ;
m_nAxesStatus = AS_NONE ;
m_vMachAxes.reserve( 8) ;
}
//----------------------------------------------------------------------------
bool
CamData::SetToolDir( const Vector3d& vtDir)
{
m_vtTool = vtDir ;
ResetObjGraphics() ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::SetCorrDir( const Vector3d& vtDir)
{
m_vtCorr = vtDir ;
ResetObjGraphics() ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::SetAuxDir( const Vector3d& vtDir)
{
m_vtAux = vtDir ;
ResetObjGraphics() ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::SetBasePoint( const Point3d& ptBase)
{
m_ptBase = ptBase ;
ResetObjGraphics() ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::SetFeed( double dFeed)
{
m_dFeed = dFeed ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::SetFlag( int nFlag)
{
m_nFlag = nFlag ;
return true ;
}
//----------------------------------------------------------------------------
bool
CamData::SetAxes( int nStatus, const DBLVECTOR& vAxVal)
{
if ( nStatus != AS_OK && nStatus != AS_OUTSTROKE && nStatus != AS_DIR_ERR && nStatus != AS_ERR)
return false ;
m_nAxesStatus = nStatus ;
m_vMachAxes = vAxVal ;
return true ;
}
//----------------------------------------------------------------------------
void
CamData::ResetObjGraphics( void)
{
if ( m_pGeomDB == nullptr)
return ;
IGeoObj* pGeo = m_pGeomDB->GetGeoObj( m_nOwnerId) ;
if ( pGeo == nullptr)
return ;
IObjGraphics* pGraph = pGeo->GetObjGraphics() ;
if ( pGraph == nullptr)
return ;
pGraph->Reset() ;
}