From 2de785c6cef92b2e76c6a3f9c40371342add8008 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Fri, 23 Oct 2015 07:59:43 +0000 Subject: [PATCH] EgtMachKernel 1.6j2 : - aggiunta prima versione del Simulator. --- CamData.cpp | 26 ++++- CamData.h | 49 +++++++-- Drilling.cpp | 14 +++ Drilling.h | 1 + EgtMachKernel.rc | Bin 11782 -> 11782 bytes EgtMachKernel.vcxproj | 3 + EgtMachKernel.vcxproj.filters | 12 +++ MachMgr.h | 12 ++- MachMgrBasic.cpp | 6 ++ MachMgrMachines.cpp | 10 ++ MachMgrOperations.cpp | 31 ++++++ MachMgrSimulation.cpp | 74 +++++++++++++ Machine.h | 4 +- MachineCalc.cpp | 24 ++++- Machining.h | 3 +- Milling.cpp | 7 ++ Milling.h | 1 + Sawing.cpp | 108 ++++++++++++++++++- Sawing.h | 2 + Simulator.cpp | 198 ++++++++++++++++++++++++++++++++++ Simulator.h | 43 ++++++++ 21 files changed, 609 insertions(+), 19 deletions(-) create mode 100644 MachMgrSimulation.cpp create mode 100644 Simulator.cpp create mode 100644 Simulator.h diff --git a/CamData.cpp b/CamData.cpp index 6a31a51..ebcf8a4 100644 --- a/CamData.cpp +++ b/CamData.cpp @@ -22,7 +22,7 @@ using namespace std ; //---------------------------------------------------------------------------- -static int CAM_TOTPARAM = 7 ; +static int CAM_TOTPARAM = 9 ; static std::string CAM_CORR = "Corr" ; static std::string CAM_TDIR = "TDir" ; static std::string CAM_CDIR = "CDir" ; @@ -30,6 +30,8 @@ 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) ; @@ -80,6 +82,8 @@ CamData::Dump( string& sOut, bool bMM, const char* szNewLine) const 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_dMachAxes) + szNewLine ; return true ; } @@ -121,6 +125,8 @@ CamData::Save( STRVECTOR& vString) const 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_dMachAxes) ; } catch( ...) { return false ; @@ -141,7 +147,9 @@ CamData::Load( const STRVECTOR& vString) ! 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_FLAG, m_nFlag) || + ! GetVal( vString[++k], CAM_AXSTS, m_nAxesStatus) || + ! GetVal( vString[++k], CAM_AXVAL, m_dMachAxes)) return false ; return true ; } @@ -379,6 +387,9 @@ CamData::CamData( void) m_nCorre = 0 ; m_dFeed = 0 ; m_nFlag = 0 ; + m_nAxesStatus = AS_NONE ; + for ( auto& dAxVal : m_dMachAxes) + dAxVal = 0 ; } //---------------------------------------------------------------------------- @@ -433,6 +444,17 @@ CamData::SetFlag( int nFlag) return true ; } +//---------------------------------------------------------------------------- +bool +CamData::SetAxes( int nStatus, const MachAxesVal& adAxVal) +{ + if ( nStatus != AS_OK && nStatus != AS_ERR && nStatus != AS_OUTSTROKE) + return false ; + m_nAxesStatus = nStatus ; + m_dMachAxes = adAxVal ; + return true ; +} + //---------------------------------------------------------------------------- void CamData::ResetObjGraphics( void) diff --git a/CamData.h b/CamData.h index 84a0035..2091f42 100644 --- a/CamData.h +++ b/CamData.h @@ -16,6 +16,10 @@ #include "/EgtDev/Include/EGkVector3d.h" #include "/EgtDev/Include/EGkUserObj.h" #include "/EgtDev/Include/EGkSelection.h" +#include + +//---------------------------------------------------------------------------- +typedef std::array MachAxesVal ; //---------------------------------------------------------------------------- class CamData : public IUserObj @@ -51,18 +55,45 @@ class CamData : public IUserObj bool SetBasePoint( const Point3d& ptBase) ; bool SetFeed( double dFeed) ; bool SetFlag( int nFlag) ; + bool SetAxes( int nStatus, const MachAxesVal& adAxVal) ; + bool ResetAxes( void) + { m_nAxesStatus = AS_NONE ; return true ; } + const Vector3d& GetToolDir( void) + { return m_vtTool ; } + const Vector3d& GetCorrDir( void) + { return m_vtCorr ; } + const Vector3d& GetAuxDir( void) + { return m_vtAux ; } + const Point3d& GetBasePoint( void) + { return m_ptBase ; } + double GetFeed( void) + { return m_dFeed ; } + int GetFlag( void) + { return m_nFlag ; } + int GetAxesStatus( void) + { return m_nAxesStatus ; } + const MachAxesVal& GetAxisVal( void) + { return m_dMachAxes ; } + + public : + enum { AS_NONE = 0, + AS_OK = 1, + AS_ERR = 2, + AS_OUTSTROKE = 3} ; private : void ResetObjGraphics( void) ; private : - int m_nOwnerId ; - IGeomDB* m_pGeomDB ; - int m_nCorre ; // tipo correzione (0, 41, 42, 141, 142, 40) - Vector3d m_vtTool ; // versore fresa - Vector3d m_vtCorr ; // versore correzione - Vector3d m_vtAux ; // versore ausiliario - Point3d m_ptBase ; // punto base per il disegno dei vettori - double m_dFeed ; // velocità di avanzamento in lavorazione - int m_nFlag ; // flag per usi vari + int m_nOwnerId ; + IGeomDB* m_pGeomDB ; + int m_nCorre ; // tipo correzione (0, 41, 42, 141, 142, 40) + Vector3d m_vtTool ; // versore fresa + Vector3d m_vtCorr ; // versore correzione + Vector3d m_vtAux ; // versore ausiliario + Point3d m_ptBase ; // punto base per il disegno dei vettori + double m_dFeed ; // velocità di avanzamento in lavorazione + int m_nFlag ; // flag per usi vari + int m_nAxesStatus ; // stato dei valori assi + MachAxesVal m_dMachAxes ; // valori degli assi macchina } ; \ No newline at end of file diff --git a/Drilling.cpp b/Drilling.cpp index 210a9a6..4d7bfff 100644 --- a/Drilling.cpp +++ b/Drilling.cpp @@ -345,6 +345,20 @@ Drilling::Apply( void) return true ; } +//---------------------------------------------------------------------------- +bool +Drilling::GetParam( int nType, string& sVal) +{ + switch ( nType) { + case MPA_TOOL : + sVal = m_Params.m_sToolName ; + break ; + default : + return false ; + } + return true ; +} + //---------------------------------------------------------------------------- bool Drilling::GetHoleData( SelData Id, Hole& hole) diff --git a/Drilling.h b/Drilling.h index 9a205d3..2f8c382 100644 --- a/Drilling.h +++ b/Drilling.h @@ -38,6 +38,7 @@ class Drilling : public Machining virtual bool SetParam( int nType, const std::string& sVal) ; virtual bool SetGeometry( const SELVECTOR& vIds) ; virtual bool Apply( void) ; + virtual bool GetParam( int nType, std::string& sVal) ; public : Drilling( void) ; diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 5d10d0a03219e56e05d6c683c594499e5d39a7bf..4298ff64df57c93442fba0d354a4434a65bcbf63 100644 GIT binary patch delta 97 zcmZpRX^YwLhmFx_^ItYwW=5mQj>5W|vxM9jH?QON0rG*u7nvrX5iEd9O=7{OSQ@Kh Hr8(RHP01iS delta 97 zcmZpRX^YwLhmFy2^ItYwW=6xwj>5W|vxM9jH?QON0rG*u7nvrX5iEd9O=7{OSQ@Kh Hr8(RHOf?`f diff --git a/EgtMachKernel.vcxproj b/EgtMachKernel.vcxproj index b922f0e..9297c88 100644 --- a/EgtMachKernel.vcxproj +++ b/EgtMachKernel.vcxproj @@ -235,11 +235,13 @@ copy $(TargetPath) \EgtProg\Dll64 + + Create Create @@ -279,6 +281,7 @@ copy $(TargetPath) \EgtProg\Dll64 + diff --git a/EgtMachKernel.vcxproj.filters b/EgtMachKernel.vcxproj.filters index 8278d0a..c213c5c 100644 --- a/EgtMachKernel.vcxproj.filters +++ b/EgtMachKernel.vcxproj.filters @@ -34,6 +34,9 @@ {9ebd88f4-45ef-477d-b613-d142baef86fb} + + {fbbebf38-66cd-4db8-863b-bc1a1cbf95d9} + @@ -132,6 +135,12 @@ Source Files\MachMgr + + Source Files\Simulation + + + Source Files\MachMgr + @@ -230,6 +239,9 @@ Header Files\Include + + Header Files + diff --git a/MachMgr.h b/MachMgr.h index 4832cd3..7666af6 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -17,10 +17,10 @@ #include "Machine.h" #include "ToolsMgr.h" #include "MachiningsMgr.h" +#include "Simulator.h" #include "/EgtDev/Include/EMkMachMgr.h" #include "/EgtDev/Include/EgtNumCollection.h" - //---------------------------------------------------------------------------- struct MachGrp { std::string MGeoName ; @@ -101,6 +101,7 @@ class MachMgr : public IMachMgr virtual bool GetAxisPos( const std::string& sAxis, double& dVal) ; virtual bool GetAxisHomePos( const std::string& sAxis, double& dHomeVal) ; virtual bool ResetAxisPos( const std::string& sAxis) ; + virtual bool ResetAllAxesPos( void) ; virtual bool LoadTool( const std::string& sHead, int nExit, const std::string& sTool) ; virtual bool ResetHeadSet( const std::string& sHead) ; virtual bool SetCalcTable( const std::string& sTable) ; @@ -127,6 +128,7 @@ class MachMgr : public IMachMgr virtual int GetOperationCount( void) const ; virtual int GetFirstOperation( void) const ; virtual int GetNextOperation( int nId) const ; + virtual int GetOperationType( int nId) const ; virtual bool GetOperationNewName( std::string& sName) const ; virtual std::string GetOperationName( int nId) const ; virtual int GetOperationId( const std::string& sName) const ; @@ -134,6 +136,11 @@ class MachMgr : public IMachMgr virtual bool ResetCurrMachining( void) ; virtual int GetCurrMachining( void) const ; virtual int AddDisposition( const std::string& sName) ; + // Simulation + virtual bool SimStart( void) ; + virtual bool SimMove( void) ; + virtual bool SimSetStep( double dStep) ; + virtual bool SimStop( void) ; public : MachMgr( void) ; @@ -217,5 +224,6 @@ class MachMgr : public IMachMgr MachGrp m_cCurrMGrp ; // dati principali macchinata corrente int m_nCurrMch ; // indice macchina corrente (0-based) MCHDATAVECTOR m_vMachines ; // elenco macchine caricate - int m_nCurrMachiningId ; // identificativo della lavorazione corrente + int m_nCurrMachiningId ; // identificativo della lavorazione corrente + Simulator* m_pSimul ; // puntatore al simulatore attivo } ; diff --git a/MachMgrBasic.cpp b/MachMgrBasic.cpp index 11ecbf6..2192ba7 100644 --- a/MachMgrBasic.cpp +++ b/MachMgrBasic.cpp @@ -48,6 +48,7 @@ MachMgr::MachMgr( void) m_nCurrMGrpId = GDB_ID_NULL ; m_nCurrMch = 0 ; m_nCurrMachiningId = GDB_ID_NULL ; + m_pSimul = nullptr ; } //---------------------------------------------------------------------------- @@ -70,6 +71,11 @@ MachMgr::Clear( void) delete m_vMachines.back().pMsMgr ; m_vMachines.pop_back() ; } + // cancello simulatore, se necessario + if ( m_pSimul != nullptr) { + delete m_pSimul ; + m_pSimul = nullptr ; + } } //---------------------------------------------------------------------------- diff --git a/MachMgrMachines.cpp b/MachMgrMachines.cpp index 68f975d..9a3272c 100644 --- a/MachMgrMachines.cpp +++ b/MachMgrMachines.cpp @@ -147,6 +147,16 @@ MachMgr::ResetAxisPos( const string& sAxis) return m_vMachines[m_nCurrMch].pMachine->ResetAxisPos( sAxis) ; } +//---------------------------------------------------------------------------- +bool +MachMgr::ResetAllAxesPos( void) +{ + if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || + m_vMachines[m_nCurrMch].pMachine == nullptr) + return GDB_ID_NULL ; + return m_vMachines[m_nCurrMch].pMachine->ResetAllAxesPos() ; +} + //---------------------------------------------------------------------------- bool MachMgr::LoadTool( const string& sHead, int nExit, const string& sTool) diff --git a/MachMgrOperations.cpp b/MachMgrOperations.cpp index 0dc66be..61ca9b4 100644 --- a/MachMgrOperations.cpp +++ b/MachMgrOperations.cpp @@ -20,6 +20,8 @@ #include "Drilling.h" #include "Sawing.h" #include "Milling.h" +#include "/EgtDev/Include/EMkOperationConst.h" +#include "/EgtDev/Include/EGkUserObjFactory.h" #include "/EgtDev/Include/EGkGdbIterator.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EGnFileUtils.h" @@ -68,6 +70,35 @@ MachMgr::GetNextOperation( int nId) const return nNextId ; } +//---------------------------------------------------------------------------- +int +MachMgr::GetOperationType( int nId) const +{ + // recupero il gruppo delle operazioni nella macchinata corrente + int nOperGrpId = GetCurrOperId() ; + if ( nOperGrpId == GDB_ID_NULL) + return OPER_NULL ; + // verifico che il gruppo ricevuto sia corretto + if ( m_pGeomDB->GetParentId( nId) != nOperGrpId) + return OPER_NULL ; + // recupero user object + IUserObj* pUserObj = m_pGeomDB->GetUserObj( nId) ; + if ( pUserObj == nullptr) + return OPER_NULL ; + // recupero il tipo di UserObj + string sUserObj = pUserObj->GetClassName() ; + if ( sUserObj == USEROBJ_GETNAME( Disposition)) + return OPER_DISP ; + else if ( sUserObj == USEROBJ_GETNAME( Drilling)) + return OPER_DRILLING ; + else if ( sUserObj == USEROBJ_GETNAME( Sawing)) + return OPER_SAWING ; + else if ( sUserObj == USEROBJ_GETNAME( Milling)) + return OPER_MILLING ; + else + return OPER_NULL ; +} + //---------------------------------------------------------------------------- bool MachMgr::GetOperationNewName( string& sName) const diff --git a/MachMgrSimulation.cpp b/MachMgrSimulation.cpp new file mode 100644 index 0000000..ac113e6 --- /dev/null +++ b/MachMgrSimulation.cpp @@ -0,0 +1,74 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : MachMgrSimulation.cpp Data : 20.10.15 Versione : 1.6j2 +// Contenuto : Implementazione gestione simulazione della classe MachMgr. +// +// +// +// Modifiche : 20.10.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "DllMain.h" +#include "MachMgr.h" +#include "MachConst.h" +#include "Simulator.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +bool +MachMgr::SimStart( void) +{ + // alloco simulatore + if ( m_pSimul != nullptr) + delete m_pSimul ; + m_pSimul = new( std::nothrow) Simulator ; + if ( m_pSimul == nullptr) + return false ; + // lo inizializzo + if ( ! m_pSimul->Init( this)) + return false ; + // lo avvio + return m_pSimul->Start() ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::SimMove( void) +{ + // verifico simulatore + if ( m_pSimul == nullptr) + return false ; + // eseguo movimento + return m_pSimul->Move() ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::SimSetStep( double dStep) +{ + // verifico simulatore + if ( m_pSimul == nullptr) + return false ; + // imposto lo step di riferimento + return m_pSimul->SetStep( dStep) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::SimStop( void) +{ + // verifico simulatore + if ( m_pSimul == nullptr) + return true ; + // lo fermo e cancello + m_pSimul->Stop() ; + delete m_pSimul ; + m_pSimul = nullptr ; + return true ; +} diff --git a/Machine.h b/Machine.h index c0dcb60..d17b65c 100644 --- a/Machine.h +++ b/Machine.h @@ -40,15 +40,18 @@ class Machine bool LoadTool( const std::string& sHead, int nExit, const std::string& sTool) ; bool ResetHeadSet( const std::string& sHead) ; bool SetAxisPos( const std::string& sAxis, double dVal) ; + bool SetAxisPos( int nAxGrp, double dVal) ; bool GetAxisPos( const std::string& sAxis, double& dVal) ; bool GetAxisHomePos( const std::string& sAxis, double& dHomeVal) ; bool ResetAxisPos( const std::string& sAxis) ; + bool ResetAllAxesPos( void) ; bool SetCurrTable( const std::string& sTable) ; int GetCurrTable( void) ; bool GetCurrTable( std::string& sTable) ; bool SetCurrTool( const std::string& sTool, const std::string& sHead, int nExit) ; int GetCurrTool( void) ; bool GetCurrTool( std::string& sTool) ; + std::string GetKinematicAxis( int nInd) ; bool GetAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, int& nStat, double& dAngA1, double& dAngB1, double& dAngA2, double& dAngB2) ; bool GetPositions( const Point3d& ptP, double dA, double dB, @@ -86,7 +89,6 @@ class Machine const STRVECTOR& GetHSet( const std::string& sHead) const ; bool EnableHeadInSet( const std::string& sHead) ; bool CreateExitGroups( int nLay, const MUEXITVECTOR& vMuExit) ; - bool ResetAllAxesPos( void) ; bool CalculateKinematicChain( void) ; bool AddKinematicAxis( bool bOnHead, int nId) ; bool AdjustAngleInStroke( int nId, double& dAng) ; diff --git a/MachineCalc.cpp b/MachineCalc.cpp index 01948c9..693fa20 100644 --- a/MachineCalc.cpp +++ b/MachineCalc.cpp @@ -228,6 +228,27 @@ Machine::AddKinematicAxis( bool bOnHead, int nId) return true ; } +//---------------------------------------------------------------------------- +string +Machine::GetKinematicAxis( int nInd) +{ + // controllo GeomDB + if ( m_pGeomDB == nullptr) + return "" ; + // controllo indice + int nLinAxTot = int( m_vCalcLinAx.size()) ; + int nRotAxTot = int( m_vCalcRotAx.size()) ; + if ( nInd < 0 || nInd >= nLinAxTot + nRotAxTot) + return "" ; + // recupero nome + string sName ; + if ( nInd < nLinAxTot) + m_pGeomDB->GetName( m_vCalcLinAx[nInd].nGrpId, sName) ; + else + m_pGeomDB->GetName( m_vCalcRotAx[nInd-nLinAxTot].nGrpId, sName) ; + return sName ; +} + //---------------------------------------------------------------------------- bool Machine::GetAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, @@ -392,7 +413,7 @@ Machine::GetPositions( const Point3d& ptP, double dAngA, double dAngB, vtDirH.Rotate( vtAx1, dAngA) ; } - // assegno l'offset tesat + // assegno l'offset testa Vector3d vtDtHe = ORIG - m_ptCalcPos ; // calcolo il recupero degli assi : è l'opposto dello spostamento della posizione @@ -406,6 +427,7 @@ Machine::GetPositions( const Point3d& ptP, double dAngA, double dAngB, dY = ptP.y + vtDtHe.y + vtDtAx.y + vtDtTL.y ; dZ = ptP.z + vtDtHe.z + vtDtAx.z + vtDtTL.z ; + nStat = 0 ; return true ; } diff --git a/Machining.h b/Machining.h index 3ce0085..848375f 100644 --- a/Machining.h +++ b/Machining.h @@ -39,8 +39,7 @@ class Machining : public IUserObj virtual bool SetGeometry( const SELVECTOR& vIds) = 0 ; //virtual bool ResetGeometry( void) = 0 ; virtual bool Apply( void) = 0 ; - //virtual bool Simulate( void) = 0 ; - //virtual bool Generate( void) = 0 ; + virtual bool GetParam( int nType, std::string& sVal) = 0 ; protected : Machining( void) ; diff --git a/Milling.cpp b/Milling.cpp index 18357f3..69f0b28 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -200,6 +200,13 @@ Milling::Apply( void) return false ; } +//---------------------------------------------------------------------------- +bool +Milling::GetParam( int nType, string& sVal) +{ + return false ; +} + //---------------------------------------------------------------------------- bool Milling::VerifyGeometry( SelData Id, int& nSubs) diff --git a/Milling.h b/Milling.h index 46e7e14..4050579 100644 --- a/Milling.h +++ b/Milling.h @@ -38,6 +38,7 @@ class Milling : public Machining virtual bool SetParam( int nType, const std::string& sVal) ; virtual bool SetGeometry( const SELVECTOR& vIds) ; virtual bool Apply( void) ; + virtual bool GetParam( int nType, std::string& sVal) ; public : Milling( void) ; diff --git a/Sawing.cpp b/Sawing.cpp index 176ec29..ec159ce 100644 --- a/Sawing.cpp +++ b/Sawing.cpp @@ -17,6 +17,7 @@ #include "DllMain.h" #include "Sawing.h" #include "MachiningConst.h" +#include "CamData.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EGkCurveLine.h" #include "/EgtDev/Include/EGkCurveComposite.h" @@ -360,6 +361,39 @@ Sawing::Apply( void) nPathId = m_pGeomDB->GetNextGroup( nPathId) ; } + // imposto l'utensile per i calcoli macchina + m_pMchMgr->SetCalcTool( m_TParams.m_sName, m_TParams.m_sHead, m_TParams.m_nExit) ; + + // assegno gli angoli iniziali + double dAngAprec = 0 ; + double dAngBprec = 0 ; + + // calcolo il valore degli assi macchina di ogni movimento + bool bOk = true ; + int nClPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; + while ( nClPathId != GDB_ID_NULL) { + if ( ! ClPathApply( nClPathId, dAngAprec, dAngBprec)) + bOk = false ; + nClPathId = m_pGeomDB->GetNextGroup( nClPathId) ; + } + + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Sawing::GetParam( int nType, string& sVal) +{ + switch ( nType) { + case MPA_TOOL : + sVal = m_Params.m_sToolName ; + break ; + case MPA_DEPTH_STR : + sVal = m_Params.m_sDepth ; + break ; + default : + return false ; + } return true ; } @@ -375,8 +409,12 @@ Sawing::VerifyGeometry( SelData Id, int& nSubs) // 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() ; + if ( pCurve != nullptr) { + if ( pCurve->GetType() == CRV_COMPO) + nSubs = ::GetCurveComposite( pCurve)->GetCurveCount() ; + else + nSubs = 0 ; + } } // altrimenti sottocurva di composita else { @@ -837,3 +875,69 @@ Sawing::AdjustForEdges( ICurveLine* pLine, double dElev, bool bIsFirst, bool bIs return true ; } + +//---------------------------------------------------------------------------- +bool +Sawing::ClPathApply( int nClPathId, double& dAngAprec, double& dAngBprec) +{ + // ciclo su tutte le entità del percorso CL + MachAxesVal adAxVal = {} ; + bool bOk = true ; + for ( int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; + nEntId != GDB_ID_NULL ; + nEntId = m_pGeomDB->GetNext( nEntId)) { + // recupero i dati Cam dell'entità + CamData* pCamData = dynamic_cast( m_pGeomDB->GetUserObj( nEntId)) ; + // calcolo degli assi rotanti della macchina + int nRStat ; + double dAngA1, dAngB1, dAngA2, dAngB2 ; + bool bROk = m_pMchMgr->GetCalcAngles( pCamData->GetToolDir(), pCamData->GetCorrDir(), nRStat, dAngA1, dAngB1, dAngA2, dAngB2) ; + if ( ! bROk || nRStat == 0) { + bOk = false ; + pCamData->SetAxes( CamData::AS_ERR, adAxVal) ; + continue ; + } + if ( nRStat == 2) { + double dDeltaA1 = fabs( dAngA1 - dAngAprec) ; + double dDeltaB1 = fabs( dAngB1 - dAngBprec) ; + double dDeltaA2 = fabs( dAngA2 - dAngAprec) ; + double dDeltaB2 = fabs( dAngB2 - dAngBprec) ; + if ( dDeltaA2 + dDeltaB2 < dDeltaA1 + dDeltaB1 - 1.) { + dAngA1 = dAngA2 ; + dAngB1 = dAngB2 ; + } + } + // compenso il raggio dell'utensile + Point3d ptP = pCamData->GetBasePoint() + pCamData->GetCorrDir() * ( m_TParams.m_dDiam / 2) ; + // calcolo gli assi lineari della macchina + int nLStat ; + double dX, dY, dZ ; + bool bLOk = m_pMchMgr->GetCalcPositions( ptP, dAngA1, dAngB1, nLStat, dX, dY, dZ) ; + if ( ! bLOk || nLStat != 0) { + bOk = false ; + pCamData->SetAxes( CamData::AS_ERR, adAxVal) ; + continue ; + } + // assegno valori assi + adAxVal[0] = dX ; + adAxVal[1] = dY ; + adAxVal[2] = dZ ; + adAxVal[3] = dAngA1 ; + adAxVal[4] = dAngB1 ; + // verifico i limiti di corsa degli assi + int nStat ; + bool bOsOk = m_pMchMgr->VerifyOutOfStroke( dX, dY, dZ, dAngA1, dAngB1, nStat) ; + if ( ! bOsOk || nStat != 0) { + bOk = false ; + pCamData->SetAxes( CamData::AS_OUTSTROKE, adAxVal) ; + continue ; + } + // salvo i valori degli assi + pCamData->SetAxes( CamData::AS_OK, adAxVal) ; + // memorizzo i valori degli angoli + dAngAprec = dAngA1 ; + dAngBprec = dAngB1 ; + } + + return bOk ; +} diff --git a/Sawing.h b/Sawing.h index b653472..2baed4f 100644 --- a/Sawing.h +++ b/Sawing.h @@ -39,6 +39,7 @@ class Sawing : public Machining virtual bool SetParam( int nType, const std::string& sVal) ; virtual bool SetGeometry( const SELVECTOR& vIds) ; virtual bool Apply( void) ; + virtual bool GetParam( int nType, std::string& sVal) ; public : Sawing( void) ; @@ -53,6 +54,7 @@ class Sawing : public Machining bool CalculateToolAndCorrVersors( const ICurve* pCurve, Vector3d& vtTool, Vector3d& vtCorr) ; bool AdjustForSide( ICurve* pCurve) ; bool AdjustForEdges( ICurveLine* pLine, double dElev, bool bIsFirst, bool bIsLast, bool bExtAngPC, bool bExtAngCN) ; + bool ClPathApply( int nClPathId, double& dAngAprec, double& dAngBprec) ; private : SELVECTOR m_vId ; // identificativi entità geometriche da lavorare diff --git a/Simulator.cpp b/Simulator.cpp new file mode 100644 index 0000000..8f65739 --- /dev/null +++ b/Simulator.cpp @@ -0,0 +1,198 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : Simulation.cpp Data : 19.10.15 Versione : 1.6j2 +// Contenuto : Implementazione della classe Simulation. +// +// +// +// Modifiche : 19.10.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "Simulator.h" +#include "MachMgr.h" +#include "Machining.h" +#include "MachiningConst.h" +#include "/EgtDev/Include/EMkOperationConst.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +Simulator::Simulator( void) +{ + m_pMchMgr = nullptr ; + m_pGeomDB = nullptr ; + m_dStep = 5.0 ; + m_nOpId = GDB_ID_NULL ; + m_nCLPathId = GDB_ID_NULL ; + m_nEntId = GDB_ID_NULL ; + m_dCoeff = 0 ; +} + +//---------------------------------------------------------------------------- +Simulator::~Simulator( void) +{ + +} + +//---------------------------------------------------------------------------- +bool +Simulator::Init( MachMgr* pMchMgr) +{ + // verifico ambiente + if ( pMchMgr == nullptr || pMchMgr->GetContextId() == 0 || pMchMgr->GetGeomDB() == nullptr) + return false ; + m_pMchMgr = pMchMgr ; + m_pGeomDB = m_pMchMgr->GetGeomDB() ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::Start( void) +{ + // verifico ci sia una macchinata corrente + if ( m_pMchMgr == nullptr) + return false ; + int nMachGrp = m_pMchMgr->GetCurrMachGroup() ; + if ( nMachGrp == GDB_ID_NULL) + return false ; + // verifico la disposizione iniziale della macchinata + int nOpId = m_pMchMgr->GetFirstOperation() ; + if ( m_pMchMgr->GetOperationType( nOpId) != OPER_DISP) + return false ; + // cerco la prima lavorazione + nOpId = m_pMchMgr->GetNextOperation( nOpId) ; + while ( nOpId != GDB_ID_NULL && ( m_pMchMgr->GetOperationType( nOpId) & OPER_MACH) == 0) + nOpId = m_pMchMgr->GetNextOperation( nOpId) ; + if ( nOpId == GDB_ID_NULL) + return false ; + m_nOpId = nOpId ; + // recupero l'utensile della lavorazione + string sTool ; + Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( m_nOpId)) ; + if ( pMch == nullptr || ! pMch->GetParam( MPA_TOOL, sTool)) + return false ; + const ToolData* pTdata = m_pMchMgr->GetToolData( sTool) ; + if ( pTdata == nullptr) + return false ; + // attivo l'utensile della lavorazione + if ( ! m_pMchMgr->SetCalcTool( sTool, pTdata->m_sHead, pTdata->m_nExit)) + return false ; + // macchina corrente + Machine* pMachine = m_pMchMgr->GetCurrMachine() ; + if ( pMachine == nullptr) + return false ; + // carico i nomi degli assi macchina attivi + m_AxesName.clear() ; + int nInd = 0 ; + string sAxis = pMachine->GetKinematicAxis( nInd) ; + while ( ! sAxis.empty()) { + m_AxesName.emplace_back( sAxis) ; + sAxis = pMachine->GetKinematicAxis( ++ nInd) ; + } + if ( m_AxesName.size() > m_AxesVal.size()) + return false ; + // porto la macchina in home + m_pMchMgr->ResetAllAxesPos() ; + // assegno valori home degli assi come precedenti + m_AxesVal.fill( 0) ; + for ( size_t i = 0 ; i < m_AxesName.size() ; ++ i) { + double dHVal ; + if ( pMachine->GetAxisHomePos( m_AxesName[i], dHVal)) + m_AxesVal[i] = dHVal ; + } + // determino il primo percorso di lavoro + int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOpId, MCH_CL) ; + m_nCLPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; + m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ; + m_dCoeff = 0 ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::Move( void) +{ + // Se arrivato alla fine dell'interpolazione, recupero una nuova entità + if ( m_dCoeff > 0.999) { + m_nEntId = m_pGeomDB->GetNext( m_nEntId) ; + m_dCoeff = 0 ; + } + // Se arrivato alla fine di un percorso di lavoro, recupero un nuovo CLpath + if ( m_nEntId == GDB_ID_NULL) { + m_nCLPathId = m_pGeomDB->GetNextGroup( m_nCLPathId) ; + m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ; + m_dCoeff = 0 ; + } + // Se arrivato alla fine di una lavorazione, recupero la successiva + if ( m_nCLPathId == GDB_ID_NULL) { + m_nOpId = m_pMchMgr->GetNextOperation( m_nOpId) ; + // se non ce ne sono altre, sono alla fine + if ( m_nOpId == GDB_ID_NULL) + return false ; + // aggiorno gli altri dati + int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOpId, MCH_CL) ; + m_nCLPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; + m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ; + m_dCoeff = 0 ; + } + + // Cerco prossima posizione su interpolazione corrente + CamData* pCamData = dynamic_cast( m_pGeomDB->GetUserObj( m_nEntId)) ; + if ( pCamData == nullptr || pCamData->GetAxesStatus() != CamData::AS_OK) + return false ; + MachAxesVal AxesEnd = pCamData->GetAxisVal() ; + // Verifico se movimento in rapido + bool bRapid = ( pCamData->GetFeed() < EPS_SMALL) ; + // Calcolo distanza di movimento + double dDist = 0 ; + for ( size_t i = 0 ; i < m_AxesName.size() ; ++ i) + dDist += ( AxesEnd[i] - m_AxesVal[i]) * ( AxesEnd[i] - m_AxesVal[i]) ; + dDist = sqrt( dDist) ; + m_dCoeff += ( bRapid ? 4 : 1) * m_dStep / dDist ; + if ( m_dCoeff > 1) + m_dCoeff = 1 ; + // Eseguo movimento + for ( size_t i = 0 ; i < m_AxesName.size() ; ++ i) { + double dVal = m_AxesVal[i] * ( 1 - m_dCoeff) + AxesEnd[i] * m_dCoeff ; + m_pMchMgr->SetAxisPos( m_AxesName[i], dVal) ; + } + + // Se arrivato a fine interpolazione movimento, salvo posizioni + if ( m_dCoeff > 0.999) + m_AxesVal = AxesEnd ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::SetStep( double dStep) +{ + const double MIN_STEP = 0.1 ; + const double MAX_STEP = 100.0 ; + if ( dStep < MIN_STEP) + m_dStep = MIN_STEP ; + else if ( dStep > MAX_STEP) + m_dStep = MAX_STEP ; + else + m_dStep = dStep ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::Stop( void) +{ + m_nOpId = GDB_ID_NULL ; + m_nCLPathId = GDB_ID_NULL ; + m_nEntId = GDB_ID_NULL ; + m_dCoeff = 0 ; + return true ; +} diff --git a/Simulator.h b/Simulator.h new file mode 100644 index 0000000..c65457e --- /dev/null +++ b/Simulator.h @@ -0,0 +1,43 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : Simulator.h Data : 19.10.15 Versione : 1.6j2 +// Contenuto : Dichiarazione della classe Simulator. +// +// +// +// Modifiche : 19.10.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "CamData.h" + +class MachMgr ; +class IGeomDB ; + +//---------------------------------------------------------------------------- +class Simulator +{ + public : + Simulator( void) ; + ~Simulator( void) ; + bool Init( MachMgr* pMchMgr) ; + bool Start( void) ; + bool Move( void) ; + bool SetStep( double dStep) ; + bool Stop( void) ; + + private : + MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni + IGeomDB* m_pGeomDB ; // puntatore al DB geometrico + double m_dStep ; // lunghezza di riferimento per la velocità di simulazione + int m_nOpId ; // identificativo della operazione (lavoraz.) corrente + int m_nCLPathId ; // identificativo del percorso di lavoro corrente + int m_nEntId ; // identificativo dell'entità corrente + double m_dCoeff ; // coefficiente di movimento corrente + STRVECTOR m_AxesName ; // nomi degli assi macchina attivi + MachAxesVal m_AxesVal ; // valori degli assi macchina all'inizio del movimento corrente +} ;