//---------------------------------------------------------------------------- // EgalTech 2015-2023 //---------------------------------------------------------------------------- // File : Machine.h Data : 16.01.23 Versione : 2.5a2 // 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 TcPos ; class Exit ; //---------------------------------------------------------------------------- class Machine { public : Machine( void) ; ~Machine( void) ; bool Init( const std::string& sMachineName, const std::string& sMachineDir, MachMgr* pMchMgr) ; const std::string& GetMachineName( void) const { return m_sName ; } const std::string& GetMachineDir( void) const { return m_sMachineDir ; } int GetMachineId( void) const { return m_nGroupId ; } int GetBaseId( const std::string& sBase) const { int nId = GetGroup( sBase) ; return ( IsBaseGroup( nId) ? nId : GDB_ID_NULL) ; } int GetTableId( const std::string& sTable) const { int nId = GetGroup( sTable) ; return ( IsTableGroup( nId) ? nId : GDB_ID_NULL) ; } int GetAxisId( const std::string& sAxis) const { int nId = GetGroup( sAxis) ; return ( IsAxisGroup( nId) ? nId : GDB_ID_NULL) ; } int GetHeadId( const std::string& sHead) const { int nId = GetGroup( sHead) ; return ( IsHeadGroup( nId) ? nId : GDB_ID_NULL) ; } int GetExitId( const std::string& sHead, int nExit) const { int nHeadId = GetHeadId( sHead) ; int nId = ( m_pGeomDB != nullptr ? m_pGeomDB->GetFirstNameInGroup( nHeadId, MCH_EXIT + ToString( nExit)) : GDB_ID_NULL) ; return ( IsExitGroup( nId) ? nId : GDB_ID_NULL) ; } int GetTcPosId( const std::string& sTcPos) const { int nId = GetGroup( sTcPos) ; return ( IsTcPosGroup( nId) ? nId : GDB_ID_NULL) ; } bool GetAllTablesNames( STRVECTOR& vNames) const ; bool GetAllHeadsNames( STRVECTOR& vNames) const ; bool GetAllTcPosNames( STRVECTOR& vNames) const ; int GetFirstTable( void) const ; int GetHeadExitCount( const std::string& sHead) const ; int GetHeadExitPosDirAux( const std::string& sHead, int nExit, Point3d& ptPos, Vector3d& vtDir, Vector3d& vtAux) const ; int GetHeadSolCh( const std::string& sHead) const ; double GetAngDeltaMinForHome( void) const { return m_dAngDeltaMinForHome ; } bool LoadTool( const std::string& sHead, int nExit, const std::string& sTool) ; bool GetLoadedTool( const std::string& sHead, int nExit, std::string& sTool) const ; bool UnloadTool( const std::string& sHead, int nExit) ; bool LoadTools( const std::string& sHead, int nNoExit, int* pnCount = nullptr) ; bool UnloadTools( const std::string& sHead) ; bool LoadAllTools( void) ; bool UnloadAllTools( void) ; bool ResetHeadSet( const std::string& sHead) ; bool GetAxisToken( const std::string& sAxis, std::string& sToken) const ; bool GetAxisInvert( const std::string& sAxis, bool& bInvert) const ; bool GetAxisOffset( const std::string& sAxis, double& dOffset) const ; bool GetAxisType( const std::string& sAxis, bool& bLinear) const ; bool SetAxisPos( const std::string& sAxis, double dVal, double* pdNewVal = nullptr) ; bool GetAxisPos( const std::string& sAxis, double& dVal) const ; bool GetAxisMin( const std::string& sAxis, double& dMin) const ; bool GetAxisMax( const std::string& sAxis, double& dMax) const ; bool GetAxisHomePos( const std::string& sAxis, double& dHomeVal) const ; bool ResetAxisPos( const std::string& sAxis) ; bool ResetAllAxesPos( void) ; bool SetCurrTable( const std::string& sTable) ; bool ResetCurrTable( void) ; int GetCurrTable( void) const ; bool GetCurrTable( std::string& sTable) const ; bool GetCurrTableRef1( Point3d& ptRef1) const ; bool GetCurrTableArea1( BBox3d& b3Area1) const ; bool GetCurrTableDeltaRef1( Vector3d& vtDelta1) const ; bool GetCurrTableIsTilting( bool& bTilting) const ; bool SetCurrTool( const std::string& sTool, const std::string& sHead, int nExit) ; bool ResetCurrTool( void) ; int GetCurrTool( void) const ; bool GetCurrTool( std::string& sTool) const ; int GetCurrHead( void) const ; bool GetCurrHead( std::string& sHead) const ; int GetCurrExit( void) const ; bool GetCurrExit( int& nExit) const ; bool GetCurrHeadCollGroups( INTVECTOR& vIds) const ; double GetCurrRot1W( void) const { return m_dCalcRot1W ; } bool GetCurrMaxDeltaR2OnFirst( void) const { return m_bCalcMaxDeltaR2On1 ; } std::string GetKinematicAxis( int nInd) const ; bool BlockKinematicRotAxis( const std::string& sName, double dVal) ; bool BlockKinematicRotAxis( int nId, double dVal) ; bool FreeKinematicRotAxis( const std::string& sName) ; bool FreeKinematicRotAxis( int nId) ; bool IsKinematicRotAxisBlocked( int nInd) const ; bool GetKinematicRotAxisBlocked( int nInd, std::string& sName, double& dVal) const ; bool SetSolCh( int nScc, bool bExact) ; int GetCurrLinAxes( void) const ; int GetCurrRotAxes( void) const ; bool GetCurrAxisName( int nInd, std::string& sAxName) const ; bool GetAllCurrAxesName( STRVECTOR& vAxName) const ; bool GetCurrAxisToken( int nInd, std::string& sAxToken) const ; bool GetAllCurrAxesToken( STRVECTOR& vAxToken) const ; bool GetCurrAxisMin( int nInd, double& dMin) const ; bool GetCurrAxisMax( int nInd, double& dMax) const ; bool GetCurrAxisHomePos( int nInd, double& dHome) const ; bool GetAllCurrAxesHomePos( DBLVECTOR& vAxHomeVal) const ; const Frame3d& GetCurrLinAxesFrame( void) const { return m_frLinAx ; } bool GetAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, int& nStat, double& dAngA1, double& dAngB1, double& dAngA2, double& dAngB2) const ; bool GetAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, int& nStat, DBLVECTOR& vAng1, DBLVECTOR& vAng2) const ; bool GetPositions( const Point3d& ptP, const DBLVECTOR& vAng, int& nStat, double& dX, double& dY, double& dZ) const ; bool GetNoseFromPositions( double dX, double dY, double dZ, const DBLVECTOR& vAng, Point3d& ptNose) const ; bool GetTipFromPositions( double dX, double dY, double dZ, const DBLVECTOR& vAng, bool bBottom, bool bOverall, Point3d& ptTip) const ; bool GetToolDirFromAngles( const DBLVECTOR& vAng, Vector3d& vtDir) const ; bool GetAuxDirFromAngles( const DBLVECTOR& vAng, Vector3d& vtDir) const ; bool GetPartDirFromAngles( const Vector3d& vtPart, const DBLVECTOR& vAng, Vector3d& vtDir) const ; bool GetBackToolDirFromAngles( const DBLVECTOR& vAng, Vector3d& vtDir) const ; bool GetBackAuxDirFromAngles( const DBLVECTOR& vAng, Vector3d& vtDir) const ; bool GetNearestAngleInStroke( int nInd, double dAngRef, double& dAng) const ; bool LimitAngleToStroke( int nInd, double& dAng) const ; bool VerifyAngleOutstroke( int nInd, double dAng) const ; bool VerifyOutstroke( double dX, double dY, double dZ, const DBLVECTOR& vAng, bool bClear, int& nStat) const ; bool ExistProtectedAreas( void) const ; bool VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& vAng, int& nStat) ; bool VerifyOutstroke( const std::string& sAxName, double dVal) const ; std::string GetOutstrokeInfo( bool bMM = true) const ; void ResetOutstrokeInfo( void) const { m_OutstrokeInfo.Clear() ; } bool SetLook( int nFlag) ; int GetLook( void) const { return m_nMachineLook ; } bool LinkRawPartToGroup( int nRawPartId, const std::string& sGroupName) ; bool IsLinkedRawPart( int nRawId) const ; const INTVECTOR& GetAllLinkedRawParts( void) const ; bool UnlinkRawPartFromGroup( int nRawPartId) ; bool UnlinkAllRawPartsFromGroups( void) ; bool LinkFixtureToGroup( int nFxtId, const std::string& sGroupName) ; bool IsLinkedFixture( int nFxtId) const ; bool UnlinkFixtureFromGroup( int nFxtId) ; bool UnlinkAllFixturesFromGroups( void) ; bool LinkPartToGroup( int nPartId, const std::string& sGroupName) ; bool IsLinkedPart( int nPartId) const ; bool UnlinkPartFromGroup( int nPartId) ; bool UnlinkAllPartsFromGroups( void) ; bool LuaExistsFunction( const std::string& sFun) const ; bool LuaCallFunction( const std::string& sFun, bool bSetModifiedOff = true) ; bool LuaCreateGlobTable( const std::string& sName) ; bool LuaResetGlobVar( const std::string& sName) ; bool LuaChangeNameGlobVar( const std::string& sOldName, const std::string& sNewName) ; 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, const STRVECTOR& vsAux) ; bool AdjustAuxGeometry( const STRVECTOR& vsAux, int nLay) ; bool LoadMachineTable( const std::string& sName, const std::string& sParent, int nType, const Point3d& ptRef1, double dCoeffX, double dCoeffY, double dCoeffZ, const std::string& sGeo, const STRVECTOR& vsAux) ; bool AdjustTable( int nLay, const Point3d& ptRef1) ; bool LoadMachineAxis( const std::string& sName, const std::string& sParent, const std::string& sToken, bool bInvert, double dOffset, int nType, const Point3d& ptPos, const Vector3d& vtDir, const STROKE& Stroke, double dHome, bool bAdjustAux, const std::string& sGeo, const STRVECTOR& vsAux) ; bool AdjustAxis( int nLay, const std::string& sPart, const std::string& sName, int nType, const Point3d& ptPos, const Vector3d& vtDir, bool bAdjustAux) ; bool ModifyMachineAxisPosition( const std::string& sName, const Point3d& ptPos) ; bool ModifyMachineAxisDirection( const std::string& sName, const Vector3d& vtDir) ; bool ModifyMachineAxisStroke( const std::string& sName, const STROKE& Stroke) ; bool ModifyMachineAxisHome( const std::string& sName, double dHome) ; 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, bool bMaxDeltaR2On1, const STROKE& Rot2Stroke, int nSolCh, const STRVECTOR& vsOthColl, const std::string& sGeo, const STRVECTOR& vsAux) ; bool LoadMachineMultiHead( const std::string& sName, const std::string& sParent, const std::string& sHSet, const MUEXITVECTOR& vMuExit, const Vector3d& vtADir, double dRot1W, bool bMaxDeltaR2On1, const STROKE& Rot2Stroke, int nSolCh, const STRVECTOR& vsOthColl, const std::string& sGeo, const STRVECTOR& vsAux) ; bool LoadMachineSpecialHead( const std::string& sName, const std::string& sParent, const std::string& sHSet, const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, double dRot1W, bool bMaxDeltaR2On1, const STROKE& Rot2Stroke, int nSolCh, const STRVECTOR& vsOthColl, const std::string& sGeo, const STRVECTOR& vsAux) ; bool LoadMachineTcPos( const std::string& sName, const std::string& sParent, const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, const std::string& sGeo, const STRVECTOR& vsAux) ; int GetGroup( const std::string& sGroup) const ; bool IsBaseGroup( int nGroup) const ; Axis* GetAxis( int nGroup) const ; bool IsAxisGroup( int nGroup) const { return ( GetAxis( nGroup) != nullptr) ; } bool IsLinearAxisGroup( int nGroup) const ; bool IsRotaryAxisGroup( int nGroup) const ; 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) ; } TcPos* GetTcPos( int nGroup) const ; bool IsTcPosGroup( int nGroup) const { return ( GetTcPos( 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 LoadTool( Exit* pExit, const std::string& sTool) ; bool ModifyMachineHeadAuxDirection( const std::string& sHead, const Vector3d& vtADir) ; bool AdjustExitFrames( int nLay, const MUEXITVECTOR& vMuExit, const Vector3d& vtADir) ; bool CreateExitGroups( int nLay, const MUEXITVECTOR& vMuExit) ; bool ModifyMachineExitPosition( const std::string& sHead, int nExit, const Point3d& ptPos) ; bool CalculateKinematicChain( void) ; bool AddKinematicAxis( bool bOnHead, int nId) ; bool GetMyAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, const Vector3d& vtDirH, const Vector3d& vtDirI, int nNumRotAx, const KinAxis& RotAx1, const KinAxis& RotAx2, int& nStat, double& dAngA1, double& dAngB1, double& dAngA2, double& dAngB2) const ; bool GetDirection( const Vector3d& vtDir, const DBLVECTOR& vAng, Vector3d& vtNew) const ; bool GetBackDirection( const Vector3d& vtDir, const DBLVECTOR& vAng, Vector3d& vtNew) const ; bool GetSccDir( int nSolCh, const Vector3d& vtDirA, Vector3d& vtDirScc) const ; bool VerifyScc( const Vector3d& vtDirI, const Vector3d& vtDirA, int nSolCh, bool bExact) const ; bool AdjustAngleInStroke( const STROKE& Stroke, double& dAng) const ; 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 : // generali 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 // dati macchina 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 double m_dAxisMaxAdjust ; // massimo aggiustamento asse da geometria a descrizione cinematica double m_dAxisMaxRotAdj ; // massima rotazione di aggiustamento asse da geometria a descrizione cinematica double m_dExitMaxAdjust ; // massimo aggiustamento uscita da geometria a descrizione cinematica double m_dExitMaxRotAdj ; // massima rotazione di aggiustamento uscita da geometria a descrizione cinematica double m_dAngDeltaMinForHome ; // minima differenza angolare da valore precedente per scegliere di stare vicino a home INTVECTOR m_vLinkedRawParts ; // elenco dei grezzi agganciati a gruppi della macchina INTVECTOR m_vLinkedFixtures ; // elenco dei bloccaggi agganciati a gruppi della macchina INTVECTOR m_vLinkedParts ; // elenco dei pezzi agganciati a gruppi della macchina // dati di calcolo 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 bool m_bCalcMaxDeltaR2On1 ; // flag utilizzo controllo massimo delta secondo asse rotante su inizio lavorazione int m_nCalcSolCh ; // criterio di scelta della soluzione bool m_bSolChExact ; // flag per scelta soluzione da soddisfare esattamente 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 double m_dCalcTRad ; // raggio utensile corrente per calcoli double m_dCalcTOvLen ; // lunghezza di ingombro utensile corrente per calcoli double m_dCalcTOvRad ; // raggio di ingombro utensile corrente per calcoli int m_nTabLinAxes ; // numero assi lineari attivi di tavola per calcoli int m_nTabRotAxes ; // numero assi rotanti attivi di tavola per calcoli int m_nHeadLinAxes ; // numero assi lineari attivi di testa per calcoli int m_nHeadRotAxes ; // numero assi rotanti attivi di testa per calcoli int m_nHeadSpecRotAxis ; // indice eventuale asse rotante speciale di testa prima dei lineari di testa (-1 non esiste) KINAXISVECTOR m_vCalcLinAx ; // vettore assi lineari attivi per calcoli KINAXISVECTOR m_vCalcRotAx ; // vettore assi rotanti attivi per calcoli Frame3d m_frLinAx ; // sistema di riferimento definito dagli assi lineari mutable OutStroke m_OutstrokeInfo ; // informazioni su ultima extra corsa // stato di visualizzazione int m_nMachineLook ; // stato di visualizzazione della macchina // 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 LuaEmtSpecialHead( lua_State* L) ; static int LuaEmtTcPos( lua_State* L) ; static int LuaEmtModifyAxisPosition( lua_State* L) ; static int LuaEmtModifyAxisDirection( lua_State* L) ; static int LuaEmtModifyAxisStroke( lua_State* L) ; static int LuaEmtModifyAxisHome( lua_State* L) ; static int LuaEmtModifyHeadAuxDirection( lua_State* L) ; static int LuaEmtModifyExitPosition( lua_State* L) ; static int LuaEmtAddRapidStart( lua_State* L) ; static int LuaEmtAddRapidMove( lua_State* L) ; static int LuaEmtAddLinearMove( lua_State* L) ; static int LuaEmtAddArcMove( lua_State* L) ; static int LuaEmtGetMoveType( lua_State* L) ; static int LuaEmtGetAxesPos( lua_State* L) ; static int LuaEmtGetBackAuxDir( lua_State* L) ; static int LuaEmtLinkRawPartToGroup( lua_State* L) ; static int LuaEmtGetAllLinkedRawParts( lua_State* L) ; static int LuaEmtUnlinkRawPartFromGroup( lua_State* L) ; static int LuaEmtUnlinkAllRawPartsFromGroups( lua_State* L) ; static int LuaEmtLinkFixtureToGroup( lua_State* L) ; static int LuaEmtUnlinkFixtureFromGroup( lua_State* L) ; static int LuaEmtUnlinkAllFixturesFromGroups( lua_State* L) ; static int LuaEmtLinkPartToGroup( lua_State* L) ; static int LuaEmtUnlinkPartFromGroup( lua_State* L) ; static int LuaEmtUnlinkAllPartsFromGroups( lua_State* L) ; static int LuaEmtWrite( lua_State* L) ; static int LuaEmtSetOutstrokeInfo( lua_State* L) ; static int LuaEmtSetLastError( lua_State* L) ; static int LuaEmtSetWarning( lua_State* L) ; static int LuaEmtAddCollisionObj( lua_State* L) ; static int LuaEmtAddCollisionObjEx( lua_State* L) ; static int LuaEmtExecCollisionCheck( lua_State* L) ; static int LuaEmtOnCollision( lua_State* L) ; static int LuaEmtSetToolForVmill( lua_State* L) ; static int LuaEmtAddToolForVmill( lua_State* L) ; static int LuaEmtMoveAxes( 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 Machine* pOldMchLua = m_pMchLua ; m_pMchLua = this ; // eseguo l'assegnamento bool bOk = ::LuaSetGlobVar( m_LuaMgr.GetLuaState(), sVar, Val) ; // ripristino contesto originale if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( nOldCtx) ; // ripristino dell'oggetto corrente per Lua m_pMchLua = pOldMchLua ; 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 Machine* pOldMchLua = m_pMchLua ; m_pMchLua = this ; // eseguo la lettura bool bOk = ::LuaGetGlobVar( m_LuaMgr.GetLuaState(), sVar, Val) ; // ripristino contesto originale if ( nOldCtx != m_pMchMgr->GetContextId()) ExeSetCurrentContext( nOldCtx) ; // ripristino dell'oggetto corrente per Lua m_pMchLua = pOldMchLua ; return bOk ; }