diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 8100120..0d30e26 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/MachMgr.h b/MachMgr.h index 8b68bed..b01a360 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -120,6 +120,8 @@ class MachMgr : public IMachMgr bool GetTableRef( int nInd, Point3d& ptPos) override ; bool GetTableArea( int nInd, BBox3d& b3Area) override ; int AddFixture( const std::string& sName, const Point3d& ptPos, double dAngRotDeg) override ; + int GetFirstFixture( void) override ; + int GetNextFixture( int nFxtId) override ; bool ShowOnlyTable( bool bVal) override ; // Tools DataBase bool TdbGetToolNewName( std::string& sName) const override ; diff --git a/MachMgrFixtures.cpp b/MachMgrFixtures.cpp index 8d36a64..00ac2ea 100644 --- a/MachMgrFixtures.cpp +++ b/MachMgrFixtures.cpp @@ -74,6 +74,33 @@ MachMgr::AddFixture( const string& sName, const Point3d& ptPos, double dAngRotDe return pDisp->AddFixture( sName, ptPos, dAngRotDeg) ; } +//---------------------------------------------------------------------------- +int +MachMgr::GetFirstFixture( void) +{ + // recupero il gruppo delle fixtures nella macchinata corrente + int nFixtGrpId = GetCurrFixtGroupId() ; + if ( nFixtGrpId == GDB_ID_NULL) + return GDB_ID_NULL ; + // restituisco identificativo del primo oggetto nel gruppo + return m_pGeomDB->GetFirstInGroup( nFixtGrpId) ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetNextFixture( int nFxtId) +{ + // recupero il gruppo delle fixtures nella macchinata corrente + int nFixtGrpId = GetCurrFixtGroupId() ; + if ( nFixtGrpId == GDB_ID_NULL) + return GDB_ID_NULL ; + // verifico che l'oggetto ricevuto appartenga al gruppo delle fixtures + if ( m_pGeomDB->GetParentId( nFxtId) != nFixtGrpId) + return GDB_ID_NULL ; + // restituisco identificativo del primo oggetto nel gruppo + return m_pGeomDB->GetNext( nFxtId) ; +} + //---------------------------------------------------------------------------- bool MachMgr::ShowOnlyTable( bool bVal) diff --git a/Machine.cpp b/Machine.cpp index 490a781..cd7ed9c 100644 --- a/Machine.cpp +++ b/Machine.cpp @@ -936,3 +936,71 @@ Machine::UnlinkAllRawPartsFromGroups( void) } return true ; } + +//---------------------------------------------------------------------------- +bool +Machine::LinkFixtureToGroup( int nFxtId, const std::string& sGroupName) +{ + // verifico DB geometrico e gestore lavorazioni + if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr) + return false ; + // recupero il gruppo delle fixtures nella macchinata corrente + int nFixtGrpId = m_pMchMgr->GetCurrFixtGroupId() ; + if ( nFixtGrpId == GDB_ID_NULL) + return GDB_ID_NULL ; + // verifico che il bloccaggio appartenga a questo gruppo + if ( m_pGeomDB->GetParentId( nFxtId) != nFixtGrpId) + return false ; + // recupero il gruppo di macchina indicato + int nGrpId = GetGroup( sGroupName) ; + if ( nGrpId == GDB_ID_NULL) + return false ; + // aggancio il bloccaggio al gruppo + if ( ! m_pGeomDB->RelocateGlob( nFxtId, nGrpId)) + return false ; + // inserisco il bloccaggio nell'elenco dei linkati + m_vLinkedFixtures.push_back( nFxtId) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Machine::IsLinkedFixture( int nFxtId) const +{ + return ( find( m_vLinkedFixtures.begin(), m_vLinkedFixtures.end(), nFxtId) != m_vLinkedFixtures.end()) ; +} + +//---------------------------------------------------------------------------- +bool +Machine::UnlinkFixtureFromGroup( int nFxtId) +{ + // verifico DB geometrico e gestore lavorazioni + if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr) + return false ; + // recupero il gruppo delle fixtures nella macchinata corrente + int nFixtGrpId = m_pMchMgr->GetCurrFixtGroupId() ; + if ( nFixtGrpId == GDB_ID_NULL) + return GDB_ID_NULL ; + // verifico che il bloccaggio indicato sia nell'elenco dei linkati + auto iIter = find( m_vLinkedFixtures.begin(), m_vLinkedFixtures.end(), nFxtId) ; + if ( iIter == m_vLinkedFixtures.end()) + return false ; + // riporto il bloccaggio nel gruppo delle fixtures + if ( ! m_pGeomDB->RelocateGlob( nFxtId, nFixtGrpId)) + return false ; + // tolgo il bloccaggio dall'elenco dei linkati + m_vLinkedFixtures.erase( iIter) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Machine::UnlinkAllFixturesFromGroups( void) +{ + while ( m_vLinkedFixtures.size() > 0) { + int nFxtId = m_vLinkedFixtures.back() ; + if ( ! UnlinkFixtureFromGroup( nFxtId)) + return false ; + } + return true ; +} diff --git a/Machine.h b/Machine.h index 1e62047..3da2aef 100644 --- a/Machine.h +++ b/Machine.h @@ -98,6 +98,10 @@ class Machine bool IsLinkedRawPart( int nRawId) 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 LuaExistsFunction( const std::string& sFun) ; bool LuaCallFunction( const std::string& sFun) ; bool LuaCreateGlobTable( const std::string& sName) ; @@ -189,6 +193,7 @@ class Machine double m_dAxisMaxAdjust ; // massimo aggiustamento asse da geometria a descrizione cinematica double m_dExitMaxAdjust ; // massimo aggiustamento uscita da geometria a descrizione cinematica INTVECTOR m_vLinkedRawParts ; // elenco dei grezzi agganciati a gruppi della macchina + INTVECTOR m_vLinkedFixtures ; // elenco dei bloccaggi agganciati a gruppi della macchina // dati di calcolo int m_nCalcTabId ; // tavola corrente per calcoli int m_nCalcHeadId ; // testa corrente per calcoli @@ -226,6 +231,9 @@ class Machine static int LuaEmtLinkRawPartToGroup( 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 LuaEmtWrite( lua_State* L) ; } ; diff --git a/MachineCalc.cpp b/MachineCalc.cpp index bb96812..c2d9472 100644 --- a/MachineCalc.cpp +++ b/MachineCalc.cpp @@ -30,7 +30,11 @@ using namespace std ; //---------------------------------------------------------------------------- static const string EMC_VAR = "EMC" ; // tabella variabili locali per calcolo static const string EVAR_TABNAME = ".TABNAME" ; // (string) nome della tavola macchina +static const string EVAR_HEAD = ".HEAD" ; // (string) nome della testa +static const string EVAR_EXIT = ".EXIT" ; // (int) numero dell'uscita +static const string EVAR_TOOL = ".TOOL" ; // (string) nome dell'utensile static const string ON_SET_TABLE = "OnSetTable" ; +static const string ON_SET_HEAD = "OnSetHead" ; //---------------------------------------------------------------------------- @@ -173,6 +177,17 @@ Machine::SetCurrTool( const string& sTool, const string& sHead, int nExit) m_vtCalcADir = pHead->GetADir() ; m_dCalcTLen = dTLen ; m_dCalcTRad = dTDiam / 2 ; + // lancio eventuale funzione lua di personalizzazione + if ( LuaExistsFunction( ON_SET_HEAD)) { + bool bOk = LuaCreateGlobTable( EMC_VAR) ; + bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_HEAD, sHead) ; + bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_EXIT, nExit) ; + bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_TOOL, sTool) ; + bOk = bOk && LuaCallFunction( ON_SET_HEAD) ; + bOk = bOk && LuaResetGlobVar( EMC_VAR) ; + if ( ! bOk) + return false ; + } // determino la catena cinematica return CalculateKinematicChain() ; } @@ -557,7 +572,7 @@ Machine::GetMyAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, } // direzione primo asse rotante - Vector3d vtAx1 = m_vCalcRotAx[0].vtDir ; + Vector3d vtAx1 = RotAx1.vtDir ; // se asse di tavola, ne inverto la direzione if ( ! RotAx1.bHead) vtAx1.Invert() ; diff --git a/MachineLua.cpp b/MachineLua.cpp index 23553e8..dd7bd85 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -85,6 +85,9 @@ Machine::LuaInit( const string& sMachineName) m_LuaMgr.RegisterFunction( "EmtLinkRawPartToGroup", Machine::LuaEmtLinkRawPartToGroup) ; m_LuaMgr.RegisterFunction( "EmtUnlinkRawPartFromGroup", Machine::LuaEmtUnlinkRawPartFromGroup) ; m_LuaMgr.RegisterFunction( "EmtUnlinkAllRawPartsFromGroups", Machine::LuaEmtUnlinkAllRawPartsFromGroups) ; + m_LuaMgr.RegisterFunction( "EmtLinkFixtureToGroup", Machine::LuaEmtLinkFixtureToGroup) ; + m_LuaMgr.RegisterFunction( "EmtUnlinkFixtureFromGroup", Machine::LuaEmtUnlinkFixtureFromGroup) ; + m_LuaMgr.RegisterFunction( "EmtUnlinkAllFixturesFromGroups", Machine::LuaEmtUnlinkAllFixturesFromGroups) ; // registro le funzioni di definizione entità CL per lua m_LuaMgr.RegisterFunction( "EmtAddRapidStart", Machine::LuaEmtAddRapidStart) ; m_LuaMgr.RegisterFunction( "EmtAddRapidMove", Machine::LuaEmtAddRapidMove) ; @@ -715,6 +718,60 @@ Machine::LuaEmtUnlinkAllRawPartsFromGroups( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +int +Machine::LuaEmtLinkFixtureToGroup( lua_State* L) +{ + // 2 parametri : nFxtId, sGroupName + int nFxtId ; + LuaCheckParam( L, 1, nFxtId) + string sGroupName ; + LuaCheckParam( L, 2, sGroupName) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // aggancio il bloccaggio al gruppo + bool bOk = m_pMchLua->LinkFixtureToGroup( nFxtId, sGroupName) ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtUnlinkFixtureFromGroup( lua_State* L) +{ + // 1 parametro : nFxtId + int nFxtId ; + LuaCheckParam( L, 1, nFxtId) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // riporto il bloccaggio nel gruppo delle fixtures + bool bOk = m_pMchLua->UnlinkFixtureFromGroup( nFxtId) ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtUnlinkAllFixturesFromGroups( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // riporto tutti i bloccaggi linkati nel gruppo delle fixtures + bool bOk = m_pMchLua->UnlinkAllFixturesFromGroups() ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + //---------------------------------------------------------------------------- int Machine::LuaEmtWrite( lua_State* L) diff --git a/OutputConst.h b/OutputConst.h index a5d17c8..5aceae5 100644 --- a/OutputConst.h +++ b/OutputConst.h @@ -116,6 +116,8 @@ static const std::string ON_ARC = "OnArc" ; // Funzioni simulazione static const std::string ON_SIMUL_DISPOSITION_START = "OnSimulDispositionStart" ; static const std::string ON_SIMUL_DISPOSITION_END = "OnSimulDispositionEnd" ; +static const std::string ON_SIMUL_TOOL_SELECT = "OnSimulToolSelect" ; +static const std::string ON_SIMUL_TOOL_DESELECT = "OnSimulToolDeselect" ; static const std::string ON_SIMUL_MACHINING_START = "OnSimulMachiningStart" ; static const std::string ON_SIMUL_MACHINING_END = "OnSimulMachiningEnd" ; static const std::string ON_SIMUL_PATH_START = "OnSimulPathStart" ; diff --git a/Simulator.cpp b/Simulator.cpp index cff2510..2e810b3 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -431,6 +431,9 @@ Simulator::SetStep( double dStep) bool Simulator::GoHome( void) { + // controllo validità stato + if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr || m_pMachine == nullptr) + return false ; // reset stato macchina OnResetMachine() ; // porto la macchina in home @@ -443,6 +446,9 @@ Simulator::GoHome( void) bool Simulator::Stop( void) { + // controllo validità stato + if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr || m_pMachine == nullptr) + return false ; // reset stato macchina OnResetMachine() ; // porto la macchina in home @@ -464,9 +470,16 @@ Simulator::UpdateTool( bool bForced) // Recupero l'utensile della lavorazione corrente Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; if ( pMch != nullptr) { + // recupero nome nuovo utensile string sTool ; if ( ! pMch->GetParam( MPA_TOOL, sTool)) return false ; + // se cambierà e non forzato (inizio), scarico l'utensile corrente + if ( sTool != m_sTool && ! bForced) { + // eventuale lancio script per scarico utensile + if ( ! OnToolDeselect()) + return false ; + } if ( ! m_pMchMgr->TdbSetCurrTool( sTool)) return false ; // se cambiato oppure forzato, attivo l'utensile della lavorazione @@ -480,10 +493,8 @@ Simulator::UpdateTool( bool bForced) if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) return false ; m_sTool = sTool ; - // imposto variabili per script - if ( ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_TOOL, m_sTool) || - ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_HEAD, sHead) || - ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_EXIT, nExit)) + // eventuale lancio script + if ( ! OnToolSelect( m_sTool, sHead, nExit)) return false ; } return true ; @@ -491,6 +502,9 @@ Simulator::UpdateTool( bool bForced) // Provo con una disposizione Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ; if ( pDisp != nullptr) { + // eventuale lancio script per scarico utensile + if ( ! OnToolDeselect()) + return false ; // recupero i dati string sTool ; string sHead ; int nExit ; pDisp->GetToolData( sTool, sHead, nExit) ; @@ -498,10 +512,8 @@ Simulator::UpdateTool( bool bForced) if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) return false ; m_sTool = sTool ; - // imposto variabili per script - if ( ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_TOOL, m_sTool) || - ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_HEAD, sHead) || - ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_EXIT, nExit)) + // eventuale lancio script + if ( ! OnToolSelect( m_sTool, sHead, nExit)) return false ; return true ; } @@ -529,6 +541,24 @@ Simulator::UpdateAxes( void) return true ; } +//---------------------------------------------------------------------------- +bool +Simulator::UpdateAxesPos( void) +{ + // Macchina corrente + Machine* pMachine = m_pMchMgr->GetCurrMachine() ; + if ( pMachine == nullptr) + return false ; + // Aggiorno la posizione corrente degli assi macchina attivi + m_AxesVal.clear() ; + for ( size_t i = 0 ; i < m_AxesName.size() ; ++ i) { + double dVal ; + m_pMachine->GetAxisPos( m_AxesName[i], dVal) ; + m_AxesVal.emplace_back( dVal) ; + } + return true ; +} + //---------------------------------------------------------------------------- bool Simulator::OnOperationEnd( void) @@ -580,6 +610,33 @@ Simulator::OnDispositionEnd( void) return bOk ; } +//---------------------------------------------------------------------------- +bool +Simulator::OnToolSelect( const string& sTool, const string& sHead, int nExit) +{ + // assegno dati + if ( ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_TOOL, sTool) || + ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_HEAD, sHead) || + ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_EXIT, nExit)) + return false ; + // verifico esistenza funzione + if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_TOOL_SELECT)) + return true ; + // chiamo la funzione di selezione utensile + return m_pMachine->LuaCallFunction( ON_SIMUL_TOOL_SELECT) ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::OnToolDeselect( void) +{ + // verifico esistenza funzione + if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_TOOL_DESELECT)) + return true ; + // chiamo la funzione di deselezione utensile + return m_pMachine->LuaCallFunction( ON_SIMUL_TOOL_DESELECT) ; +} + //---------------------------------------------------------------------------- bool Simulator::OnMachiningStart( int nOpId, int nOpInd) @@ -588,11 +645,11 @@ Simulator::OnMachiningStart( int nOpId, int nOpInd) if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MACHINING_START)) return true ; // assegno identificativo e indice lavorazione - bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MCHID, nOpId) ; - bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MCHIND, nOpInd) ; + if ( ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MCHID, nOpId) || + ! m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MCHIND, nOpInd)) + return false ; // chiamo la funzione di inizio disposizione - bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_MACHINING_START) ; - return bOk ; + return m_pMachine->LuaCallFunction( ON_SIMUL_MACHINING_START) ; } //---------------------------------------------------------------------------- @@ -667,12 +724,15 @@ Simulator::OnMoveStart( const CamData* pCamData) // verifico esistenza funzione if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MOVE_START)) - return true ; + return bOk ; // chiamo la funzione bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_MOVE_START) ; if ( ! bOk) return false ; + // forzo aggiornamento posizione assi (possono essere stati mssi nello script) + UpdateAxesPos() ; + // recupero i dati di ritorno int nNumAuxAxes = 0 ; if ( ! m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_AUXAXES, nNumAuxAxes) || nNumAuxAxes == 0) @@ -718,6 +778,5 @@ Simulator::OnResetMachine( void) if ( ! m_pMachine->LuaExistsFunction( ON_RESET_MACHINE)) return true ; // eseguo reset macchina - bool bOk = m_pMachine->LuaCallFunction( ON_RESET_MACHINE) ; - return bOk ; + return m_pMachine->LuaCallFunction( ON_RESET_MACHINE) ; } diff --git a/Simulator.h b/Simulator.h index f6d2b8b..4cb1a20 100644 --- a/Simulator.h +++ b/Simulator.h @@ -39,11 +39,14 @@ class Simulator private : bool UpdateTool( bool bForced = false) ; bool UpdateAxes( void) ; + bool UpdateAxesPos( void) ; private : bool OnOperationEnd( void) ; bool OnDispositionStart( int nOpId, int nOpInd, int nPhase, bool bEmpty) ; bool OnDispositionEnd( void) ; + bool OnToolSelect( const std::string& sTool, const std::string& sHead, int nExit) ; + bool OnToolDeselect( void) ; bool OnMachiningStart( int nOpId, int nOpInd) ; bool OnMachiningEnd( void) ; bool OnPathStart( int nClPathId, int nClPathInd) ;