//---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- // File : Machine.h Data : 06.05.15 Versione : 1.6e3 // Contenuto : Dichiarazione della classe Machine. // // // // Modifiche : 06.05.15 DS Creazione modulo. // // //---------------------------------------------------------------------------- #pragma once #include "MachineStruConst.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EGkGeomDB.h" #include "/EgtDev/Include/EGkLuaAux.h" #include "/EgtDev/Include/EGnLuaMgr.h" #include "/EgtDev/Include/EGnWriter.h" #include class MachMgr ; class Axis ; class Table ; class Head ; class Exit ; //---------------------------------------------------------------------------- class Machine { public : Machine( void) ; ~Machine( void) ; bool Init( const std::string& sMachinesDir, const std::string& sMachineName, MachMgr* pMchMgr) ; int GetMGeoId( void) const { return m_nGroupId ; } const std::string& GetMachineName( void) const { return m_sName ; } Table* GetTable( const std::string& sTable) const { return GetTable( GetGroup( sTable)) ; } 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) ; double GetCurrRot1W( void) ; std::string GetKinematicAxis( int nInd) ; int GetCurrLinAxes( void) ; int GetCurrRotAxes( void) ; bool GetAllCurrAxesName( STRVECTOR& vAxName) ; bool GetAllCurrAxesHomePos( DBLVECTOR& vAxHomeVal) ; 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, int& nStat, double& dX, double& dY, double& dZ) ; bool GetNearestAngleInStroke( int nId, double dAngRef, double& dAng) ; bool VerifyOutOfStroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) ; bool LuaCallFunction( const std::string& sFun) ; bool LuaCreateGlobTable( const std::string& sName) ; bool LuaResetGlobVar( const std::string& sName) ; template bool LuaSetGlobVar( const std::string& sVar, const T& Val) ; template bool LuaGetGlobVar( const std::string& sVar, T& Val) ; bool WriterOpen( const std::string& sOutFile) ; bool WriterClose( void) ; bool WriterEmit( const std::string& sLine) ; private : void Clear( void) ; bool LoadMachineGeometry( const std::string& sMGeoName, const Vector3d& vtOffset) ; bool LoadMachineBase( const std::string& sName, const std::string& sGeo) ; bool LoadMachineTable( const std::string& sName, const std::string& sParent, int nType, const Point3d& ptRef1, const std::string& sGeo) ; bool AdjustTablePos( int nLay, const Point3d& ptRef1) ; bool LoadMachineAxis( const std::string& sName, const std::string& sParent, int nType, const Point3d& ptPos, const Vector3d& vtDir, const STROKE& Stroke, const std::string& sGeo, double dHome) ; bool AdjustAxisVector( int nLay, const std::string& sPart, const std::string& sName, int nType, const Point3d& ptPos, const Vector3d& vtDir) ; bool LoadMachineStdHead( const std::string& sName, const std::string& sParent, const std::string& sHSet, const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, double dRot1W, const std::string& sGeo) ; bool LoadMachineMultiHead( const std::string& sName, const std::string& sParent, const std::string& sHSet, const MUEXITVECTOR& vMuExit, const Vector3d& vtADir, double dRot1W, const std::string& sGeo) ; int GetGroup( const std::string& sGroup) const ; Axis* GetAxis( int nGroup) const ; bool IsAxisGroup( int nGroup) const { return ( GetAxis( nGroup) != nullptr) ; } Table* GetTable( int nGroup) const ; bool IsTableGroup( int nGroup) const { return ( GetTable( nGroup) != nullptr) ; } Head* GetHead( int nGroup) const ; bool IsHeadGroup( int nGroup) const { return ( GetHead( nGroup) != nullptr) ; } Exit* GetExit( int nGroup) const ; bool IsExitGroup( int nGroup) const { return ( GetExit( nGroup) != nullptr) ; } bool AddHeadToSet( const std::string& sHSet, const std::string& sName) ; const STRVECTOR& GetHSet( const std::string& sHead) const ; bool EnableHeadInSet( const std::string& sHead) ; bool CreateExitGroups( int nLay, const MUEXITVECTOR& vMuExit) ; bool CalculateKinematicChain( void) ; bool AddKinematicAxis( bool bOnHead, int nId) ; bool AdjustAngleInStroke( int nId, double& dAng) ; bool LuaInit( const std::string& sMachineName) ; bool LuaExit( void) ; bool LuaLoadMachine( const std::string& sFile) ; private : typedef std::unordered_map< std::string, int> STRINT_UMAP ; private : MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni IGeomDB* m_pGeomDB ; // puntatore al DB geometrico LuaMgr m_LuaMgr ; // interprete lua della macchina Writer m_Writer ; // scrittore di file di testo std::string m_sName ; // nome della macchina std::string m_sMachineDir ; // direttorio della macchina int m_nGroupId ; // Id del gruppo della macchina int m_nTempGroupId ; // Id del gruppo temporaneo macchina per carico STRINT_UMAP m_mapGroups ; // dizionario dei gruppi della macchina int m_nCalcTabId ; // tavola corrente per calcoli int m_nCalcHeadId ; // testa corrente per calcoli int m_nCalcExitId ; // uscita corrente per calcoli int m_nCalcToolId ; // utensile corrente per calcoli double m_dCalcRot1W ; // peso del primo asse rotante per i confronti Point3d m_ptCalcPos ; // posizione utensile a riposo per calcoli Vector3d m_vtCalcDir ; // direzione utensile a riposo per calcoli Vector3d m_vtCalcADir ; // direzione ausiliaria a riposo per calcoli double m_dCalcTLen ; // lunghezza utensile corrente per calcoli KINAXISVECTOR m_vCalcLinAx ; // vettore assi lineari attivi per calcoli KINAXISVECTOR m_vCalcRotAx ; // vettore assi rotanti attivi per calcoli // Static per interprete Lua di macchina private : static Machine* m_pMchLua ; private : static int LuaEmtGeneral( lua_State* L) ; static int LuaEmtBase( lua_State* L) ; static int LuaEmtTable( lua_State* L) ; static int LuaEmtAxis( lua_State* L) ; static int LuaEmtHead( lua_State* L) ; static int LuaEmtStdHead( lua_State* L) ; static int LuaEmtMultiHead( lua_State* L) ; static int LuaEmtWrite( lua_State* L) ; } ; //---------------------------------------------------------------------------- template bool Machine::LuaSetGlobVar( const std::string& sVar, const T& Val) { // imposto contesto corretto int nOldCtx = ExeGetCurrentContext() ; if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( m_pMchMgr->GetContextId()) ; // imposto l'oggetto corrente per Lua m_pMchLua = this ; // eseguo l'assegnamento bool bOk = ::LuaSetGlobVar( m_LuaMgr.GetLuaState(), sVar, Val) ; // ripristino contesto originale if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( nOldCtx) ; return bOk ; } //---------------------------------------------------------------------------- template bool Machine::LuaGetGlobVar( const std::string& sVar, T& Val) { // imposto contesto corretto int nOldCtx = ExeGetCurrentContext() ; if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( m_pMchMgr->GetContextId()) ; // imposto l'oggetto corrente per Lua m_pMchLua = this ; // eseguo la lettura bool bOk = ::LuaGetGlobVar( m_LuaMgr.GetLuaState(), sVar, Val) ; // ripristino contesto originale if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( nOldCtx) ; return bOk ; }