diff --git a/CamData.cpp b/CamData.cpp index ebcf8a4..6abbe6a 100644 --- a/CamData.cpp +++ b/CamData.cpp @@ -83,7 +83,7 @@ CamData::Dump( string& sOut, bool bMM, const char* szNewLine) const 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 ; + sOut += CAM_AXVAL + "=" + ToString( m_vMachAxes) + szNewLine ; return true ; } @@ -126,7 +126,7 @@ CamData::Save( STRVECTOR& vString) const 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) ; + vString[++k] = CAM_AXVAL + "=" + ToString( m_vMachAxes) ; } catch( ...) { return false ; @@ -149,7 +149,7 @@ CamData::Load( const STRVECTOR& vString) ! 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_dMachAxes)) + ! GetVal( vString[++k], CAM_AXVAL, m_vMachAxes)) return false ; return true ; } @@ -388,8 +388,7 @@ CamData::CamData( void) m_dFeed = 0 ; m_nFlag = 0 ; m_nAxesStatus = AS_NONE ; - for ( auto& dAxVal : m_dMachAxes) - dAxVal = 0 ; + m_vMachAxes.reserve( 8) ; } //---------------------------------------------------------------------------- @@ -446,12 +445,12 @@ CamData::SetFlag( int nFlag) //---------------------------------------------------------------------------- bool -CamData::SetAxes( int nStatus, const MachAxesVal& adAxVal) +CamData::SetAxes( int nStatus, const DBLVECTOR& vAxVal) { if ( nStatus != AS_OK && nStatus != AS_ERR && nStatus != AS_OUTSTROKE) return false ; m_nAxesStatus = nStatus ; - m_dMachAxes = adAxVal ; + m_vMachAxes = vAxVal ; return true ; } diff --git a/CamData.h b/CamData.h index 2091f42..253386d 100644 --- a/CamData.h +++ b/CamData.h @@ -16,10 +16,6 @@ #include "/EgtDev/Include/EGkVector3d.h" #include "/EgtDev/Include/EGkUserObj.h" #include "/EgtDev/Include/EGkSelection.h" -#include - -//---------------------------------------------------------------------------- -typedef std::array MachAxesVal ; //---------------------------------------------------------------------------- class CamData : public IUserObj @@ -55,25 +51,25 @@ 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 SetAxes( int nStatus, const DBLVECTOR& vAxVal) ; bool ResetAxes( void) { m_nAxesStatus = AS_NONE ; return true ; } - const Vector3d& GetToolDir( void) + const Vector3d& GetToolDir( void) const { return m_vtTool ; } - const Vector3d& GetCorrDir( void) + const Vector3d& GetCorrDir( void) const { return m_vtCorr ; } - const Vector3d& GetAuxDir( void) + const Vector3d& GetAuxDir( void) const { return m_vtAux ; } - const Point3d& GetBasePoint( void) + const Point3d& GetBasePoint( void) const { return m_ptBase ; } - double GetFeed( void) + double GetFeed( void) const { return m_dFeed ; } - int GetFlag( void) + int GetFlag( void) const { return m_nFlag ; } - int GetAxesStatus( void) + int GetAxesStatus( void) const { return m_nAxesStatus ; } - const MachAxesVal& GetAxisVal( void) - { return m_dMachAxes ; } + const DBLVECTOR& GetAxisVal( void) const + { return m_vMachAxes ; } public : enum { AS_NONE = 0, @@ -95,5 +91,5 @@ class CamData : public IUserObj 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 + DBLVECTOR m_vMachAxes ; // valori degli assi macchina } ; \ No newline at end of file diff --git a/Drilling.cpp b/Drilling.cpp index 4d7bfff..8893a07 100644 --- a/Drilling.cpp +++ b/Drilling.cpp @@ -339,10 +339,9 @@ Drilling::Apply( void) } } } + // calcolo gli assi macchina - - - return true ; + return CalculateAxesValues() ; } //---------------------------------------------------------------------------- @@ -359,6 +358,13 @@ Drilling::GetParam( int nType, string& sVal) return true ; } +//---------------------------------------------------------------------------- +const ToolData& +Drilling::GetToolData( void) +{ + return m_TParams ; +} + //---------------------------------------------------------------------------- bool Drilling::GetHoleData( SelData Id, Hole& hole) @@ -625,3 +631,11 @@ Drilling::DoPeckDrilling( const Hole& hole, SelData Id, int nPathId) return true ; } + +//---------------------------------------------------------------------------- +bool +Drilling::AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP) +{ + // non devo fare alcunché + return true ; +} diff --git a/Drilling.h b/Drilling.h index 2f8c382..89a0fd5 100644 --- a/Drilling.h +++ b/Drilling.h @@ -39,6 +39,8 @@ class Drilling : public Machining virtual bool SetGeometry( const SELVECTOR& vIds) ; virtual bool Apply( void) ; virtual bool GetParam( int nType, std::string& sVal) ; + virtual const ToolData& GetToolData( void) ; + virtual bool AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP) ; public : Drilling( void) ; diff --git a/DrillingData.cpp b/DrillingData.cpp index 889976d..c23ae7f 100644 --- a/DrillingData.cpp +++ b/DrillingData.cpp @@ -15,6 +15,7 @@ #include "stdafx.h" #include "DrillingData.h" #include "MachiningDataFactory.h" +#include "/EgtDev/Include/EmkToolConst.h" #include "/EgtDev/Include/EGnStringUtils.h" #include #include diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 4298ff6..4dca250 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/Head.cpp b/Head.cpp index af710f8..ad9fa58 100644 --- a/Head.cpp +++ b/Head.cpp @@ -95,19 +95,20 @@ Head::GetGeomDB( void) const //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- Head::Head( void) - : m_nOwnerId( GDB_ID_NULL), m_pGeomDB( nullptr), m_nType( MCH_HT_NONE) + : m_nOwnerId( GDB_ID_NULL), m_pGeomDB( nullptr), m_nType( MCH_HT_NONE), m_dRot1W( 1) { } //---------------------------------------------------------------------------- bool -Head::Set( const string& sName, int nType, const string& sHSet, const Vector3d& vtADir) +Head::Set( const string& sName, int nType, const string& sHSet, const Vector3d& vtADir, double dRot1W) { m_sName = sName ; m_nType = nType ; m_vsHSet.clear() ; m_vsHSet.push_back( sHSet) ; m_vtADir = vtADir ; + m_dRot1W = dRot1W ; return true ; } diff --git a/Head.h b/Head.h index 5433380..6b12bdf 100644 --- a/Head.h +++ b/Head.h @@ -30,12 +30,13 @@ class Head : public IUserObj public : Head( void) ; - bool Set( const std::string& sName, int nType, const std::string& sHSet, const Vector3d& vtADir) ; + bool Set( const std::string& sName, int nType, const std::string& sHSet, const Vector3d& vtADir, double dRot1W) ; bool AddHeadToHSet( const std::string& sHead) ; const std::string& GetName( void) { return m_sName ; } int GetType( void) { return m_nType ; } const STRVECTOR& GetHSet(void) { return m_vsHSet ; } const Vector3d& GetADir( void) { return m_vtADir ; } + double GetRot1W( void) { return m_dRot1W ; } private : int m_nOwnerId ; @@ -44,4 +45,5 @@ class Head : public IUserObj int m_nType ; STRVECTOR m_vsHSet ; Vector3d m_vtADir ; + double m_dRot1W ; } ; \ No newline at end of file diff --git a/MachMgr.h b/MachMgr.h index 7666af6..67b49f9 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -57,6 +57,8 @@ class MachMgr : public IMachMgr int nContextId, const std::string& sLuaLibsDir, const std::string& sLuaLastRequire) ; virtual bool Update( void) ; virtual bool Insert( int nInsGrp) ; + // Machines + virtual bool SetCurrMachine( const std::string& sMachineName) ; // MachGroups virtual int GetMachGroupCount( void) const ; virtual int GetFirstMachGroup( void) const ; @@ -96,7 +98,7 @@ class MachMgr : public IMachMgr virtual bool GetTableArea1( int& nAreaId) ; virtual int AddSubPiece( const std::string& sName, const Point3d& ptPos, double dAngRotDeg) ; virtual bool ShowOnlyTable( bool bVal) ; - // Machine + // Machine Calc virtual bool SetAxisPos( const std::string& sAxis, double dVal) ; virtual bool GetAxisPos( const std::string& sAxis, double& dVal) ; virtual bool GetAxisHomePos( const std::string& sAxis, double& dHomeVal) ; @@ -112,10 +114,19 @@ class MachMgr : public IMachMgr virtual bool GetCalcPositions( const Point3d& ptP, double dAngA, double dAngB, int& nStat, double& dX, double& dY, double& dZ) ; virtual bool VerifyOutOfStroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) ; - // Tools - virtual bool GetToolParam( const std::string& sName, int nType, int& nVal) const ; - virtual bool GetToolParam( const std::string& sName, int nType, double& dVal) const ; - virtual bool GetToolParam( const std::string& sName, int nType, std::string& sVal) const ; + // Tool DataBase + virtual bool TdbAddTool( const std::string& sName, int nType) ; + virtual bool TdbCopyTool( const std::string& sSource, const std::string& sName) ; + virtual bool TdbRemoveTool( const std::string& sName) ; + virtual bool TdbGetFirstTool( int nFamily, std::string& sName, int& nType) ; + virtual bool TdbGetNextTool( int nFamily, std::string& sName, int& nType) ; + virtual bool TdbSetToolParam( const std::string& sName, int nType, int nVal) ; + virtual bool TdbSetToolParam( const std::string& sName, int nType, double dVal) ; + virtual bool TdbSetToolParam( const std::string& sName, int nType, const std::string& sVal) ; + virtual bool TdbGetToolParam( const std::string& sName, int nType, int& nVal) const ; + virtual bool TdbGetToolParam( const std::string& sName, int nType, double& dVal) const ; + virtual bool TdbGetToolParam( const std::string& sName, int nType, std::string& sVal) const ; + virtual bool TdbSave( void) const ; // Operations virtual int AddMachining( const std::string& sName, const std::string& sMachining) ; virtual bool SetMachiningParam( int nType, bool bVal) ; @@ -128,6 +139,8 @@ class MachMgr : public IMachMgr virtual int GetOperationCount( void) const ; virtual int GetFirstOperation( void) const ; virtual int GetNextOperation( int nId) const ; + virtual int GetLastOperation( void) const ; + virtual int GetPrevOperation( int nId) const ; virtual int GetOperationType( int nId) const ; virtual bool GetOperationNewName( std::string& sName) const ; virtual std::string GetOperationName( int nId) const ; @@ -176,8 +189,15 @@ class MachMgr : public IMachMgr Machine* GetCurrMachine( void) const ; ToolsMgr* GetCurrToolsMgr( void) const ; MachiningsMgr* GetCurrMachiningsMgr( void) const ; - // Tools - const ToolData* GetToolData( const std::string& sName) const ; + // MachineCalc + int GetCurrLinAxes( void) ; + int GetCurrRotAxes( void) ; + bool GetAllCurrAxesName( STRVECTOR& vAxName) ; + bool GetAllCalcAxesHomePos( DBLVECTOR& vAxHomeVal) ; + double GetCalcRot1W( void) ; + // Tool DataBase + ToolData* TdbGetToolData( const std::string& sName) ; + const ToolData* TdbGetToolData( const std::string& sName) const ; private : // Basic diff --git a/MachMgrMachGroups.cpp b/MachMgrMachGroups.cpp index f83e716..006a23b 100644 --- a/MachMgrMachGroups.cpp +++ b/MachMgrMachGroups.cpp @@ -97,9 +97,19 @@ MachMgr::AddMachGroup( const string& sName, const string& sMachineName) // verifico nome non vuoto e non esista già un gruppo con lo stesso nome if ( sName.empty() || GetMachGroupId( sName) != GDB_ID_NULL) return GDB_ID_NULL ; - // verifica ed eventuale caricamento della macchina - if ( ! LoadMachine( sMachineName)) - return GDB_ID_NULL ; + // se nome macchina vuoto, verifico esista una macchina corrente + string sMachName ; + if ( sMachineName.empty()) { + if ( GetCurrMachine() == nullptr) + return GDB_ID_NULL ; + sMachName = GetCurrMachine()->GetMachineName() ; + } + // altrimenti, verifica ed eventuale caricamento della macchina + else { + if ( ! LoadMachine( sMachineName)) + return GDB_ID_NULL ; + sMachName = sMachineName ; + } // inserisco il gruppo in coda int nNewId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nMachBaseId, GLOB_FRM) ; if ( nNewId == GDB_ID_NULL) @@ -107,7 +117,7 @@ MachMgr::AddMachGroup( const string& sName, const string& sMachineName) // assegno il nome m_pGeomDB->SetName( nNewId, sName) ; // assegno la macchina - m_pGeomDB->SetInfo( nNewId, MACH_MACHINE_KEY, sMachineName) ; + m_pGeomDB->SetInfo( nNewId, MACH_MACHINE_KEY, sMachName) ; // creo il sottogruppo per l'attrezzaggio int nSetupId = m_pGeomDB->AddGroup( GDB_ID_NULL, nNewId, GLOB_FRM) ; m_pGeomDB->SetName( nSetupId, MACH_SETUP_GROUP) ; @@ -289,7 +299,7 @@ MachMgr::SetCurrMachGroup( int nId) m_nCurrMch = GetMachine( m_cCurrMGrp.MGeoName) ; // porto i pezzi dalla loro posizione standard nei grezzi nuovi SwapParts( true) ; - // nascondo pezzi rimasti sotto la radice + // nascondo i pezzi rimasti sotto la radice ShowRootParts( false) ; // rendo visibile il nuovo gruppo corrente e la relativa macchina m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_ON) ; @@ -322,9 +332,8 @@ MachMgr::ResetCurrMachGroup( void) // nascondo gruppo corrente e la relativa macchina m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_OFF) ; m_pGeomDB->SetStatus( GetCurrMGeoId(), GDB_ST_OFF) ; - // dichiaro nessun gruppo corrente, la relativa macchina e la lavorazione corrente + // dichiaro nessun gruppo e lavorazione correnti, lascio corrente la macchina m_nCurrMGrpId = GDB_ID_NULL ; - m_nCurrMch = - 1 ; m_nCurrMachiningId = GDB_ID_NULL ; return true ; } diff --git a/MachMgrMachines.cpp b/MachMgrMachines.cpp index 9a3272c..fa8dcc5 100644 --- a/MachMgrMachines.cpp +++ b/MachMgrMachines.cpp @@ -70,6 +70,26 @@ MachMgr::GetMachine( const string& sMachineName) const return - 1 ; } +//---------------------------------------------------------------------------- +bool +MachMgr::SetCurrMachine( const string& sMachineName) +{ + // se è già la macchina corrente, tutto bene + if ( m_nCurrMch >= 0 && m_nCurrMch < int( m_vMachines.size()) && + m_vMachines[m_nCurrMch].pMachine != nullptr && + EqualNoCase( m_vMachines[m_nCurrMch].pMachine->GetMachineName(), sMachineName)) + return true ; + // se c'è macchinata corrente, non posso cambiare la macchina + if ( m_nCurrMGrpId != GDB_ID_NULL) + return false ; + // verifica ed eventuale caricamento della macchina + if ( ! LoadMachine( sMachineName)) + return GDB_ID_NULL ; + // imposto i dati della macchina corrente + m_nCurrMch = GetMachine( sMachineName) ; + return true ; +} + //---------------------------------------------------------------------------- int MachMgr::GetCurrMGeoId( void) const @@ -207,6 +227,56 @@ MachMgr::GetCalcTool( string& sTool) return m_vMachines[m_nCurrMch].pMachine->GetCurrTool( sTool) ; } +//---------------------------------------------------------------------------- +double +MachMgr::GetCalcRot1W( void) +{ + if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || + m_vMachines[m_nCurrMch].pMachine == nullptr) + return 1 ; + return m_vMachines[m_nCurrMch].pMachine->GetCurrRot1W() ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetCurrLinAxes( void) +{ + if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || + m_vMachines[m_nCurrMch].pMachine == nullptr) + return 0 ; + return m_vMachines[m_nCurrMch].pMachine->GetCurrLinAxes() ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetCurrRotAxes( void) +{ + if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || + m_vMachines[m_nCurrMch].pMachine == nullptr) + return 0 ; + return m_vMachines[m_nCurrMch].pMachine->GetCurrRotAxes() ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::GetAllCurrAxesName( STRVECTOR& vAxName) +{ + if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || + m_vMachines[m_nCurrMch].pMachine == nullptr) + return false ; + return m_vMachines[m_nCurrMch].pMachine->GetAllCurrAxesName( vAxName) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::GetAllCalcAxesHomePos( DBLVECTOR& vAxHomeVal) +{ + if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || + m_vMachines[m_nCurrMch].pMachine == nullptr) + return false ; + return m_vMachines[m_nCurrMch].pMachine->GetAllCurrAxesHomePos( vAxHomeVal) ; +} + //---------------------------------------------------------------------------- bool MachMgr::GetCalcAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, diff --git a/MachMgrOperations.cpp b/MachMgrOperations.cpp index 61ca9b4..19cf066 100644 --- a/MachMgrOperations.cpp +++ b/MachMgrOperations.cpp @@ -70,6 +70,35 @@ MachMgr::GetNextOperation( int nId) const return nNextId ; } +//---------------------------------------------------------------------------- +int +MachMgr::GetLastOperation( void) const +{ + // recupero il gruppo delle operazioni nella macchinata corrente + int nOperGrpId = GetCurrOperId() ; + if ( nOperGrpId == GDB_ID_NULL) + return GDB_ID_NULL ; + // recupero l'ultimo sottogruppo + int nId = m_pGeomDB->GetLastGroupInGroup( nOperGrpId) ; + return nId ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetPrevOperation( int nId) const +{ + // recupero il gruppo delle operazioni nella macchinata corrente + int nOperGrpId = GetCurrOperId() ; + if ( nOperGrpId == GDB_ID_NULL) + return GDB_ID_NULL ; + // verifico che il gruppo ricevuto sia corretto + if ( m_pGeomDB->GetParentId( nId) != nOperGrpId) + return GDB_ID_NULL ; + // recupero il precedente sottogruppo + int nNextId = m_pGeomDB->GetPrevGroup( nId) ; + return nNextId ; +} + //---------------------------------------------------------------------------- int MachMgr::GetOperationType( int nId) const diff --git a/MachMgrTools.cpp b/MachMgrTools.cpp index 4a2aade..378cd04 100644 --- a/MachMgrTools.cpp +++ b/MachMgrTools.cpp @@ -18,9 +18,153 @@ using namespace std ; +//---------------------------------------------------------------------------- +bool +MachMgr::TdbAddTool( const string& sName, int nType) +{ + // recupero il gestore di utensili della macchina corrente + ToolsMgr* pTsMgr = GetCurrToolsMgr() ; + if ( pTsMgr == nullptr) + return false ; + // aggiungo l'utensile al DB utensili + return pTsMgr->AddTool( sName, nType) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::TdbCopyTool( const string& sSource, const string& sName) +{ + // recupero il gestore di utensili della macchina corrente + ToolsMgr* pTsMgr = GetCurrToolsMgr() ; + if ( pTsMgr == nullptr) + return false ; + // copio l'utensile nel DB utensili + return pTsMgr->CopyTool( sSource, sName) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::TdbRemoveTool( const string& sName) +{ + // recupero il gestore di utensili della macchina corrente + ToolsMgr* pTsMgr = GetCurrToolsMgr() ; + if ( pTsMgr == nullptr) + return false ; + // rimuovo l'utensile dal DB utensili + return pTsMgr->RemoveTool( sName) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::TdbGetFirstTool( int nFamily, string& sName, int& nType) +{ + // recupero il gestore di utensili della macchina corrente + ToolsMgr* pTsMgr = GetCurrToolsMgr() ; + if ( pTsMgr == nullptr) + return false ; + // cerco il primo utensile della famiglia nel DB utensili + return pTsMgr->GetFirstTool( nFamily, sName, nType) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::TdbGetNextTool( int nFamily, string& sName, int& nType) +{ + // recupero il gestore di utensili della macchina corrente + ToolsMgr* pTsMgr = GetCurrToolsMgr() ; + if ( pTsMgr == nullptr) + return false ; + // cerco il successivo utensile della famiglia nel DB utensili + return pTsMgr->GetNextTool( nFamily, sName, nType) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::TdbSetToolParam( const string& sName, int nType, int nVal) +{ + // recupero l'utensile + ToolData* pTdata = TdbGetToolData( sName) ; + if ( pTdata == nullptr) + return false ; + // assegno il parametro + return pTdata->SetParam( nType, nVal) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::TdbSetToolParam( const string& sName, int nType, double dVal) +{ + // recupero l'utensile + ToolData* pTdata = TdbGetToolData( sName) ; + if ( pTdata == nullptr) + return false ; + // assegno il parametro + return pTdata->SetParam( nType, dVal) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::TdbSetToolParam( const string& sName, int nType, const string& sVal) +{ + // recupero l'utensile + ToolData* pTdata = TdbGetToolData( sName) ; + if ( pTdata == nullptr) + return false ; + // assegno il parametro + return pTdata->SetParam( nType, sVal) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::TdbGetToolParam( const string& sName, int nType, int& nVal) const +{ + // recupero l'utensile + const ToolData* pTdata = TdbGetToolData( sName) ; + if ( pTdata == nullptr) + return false ; + // recupero il parametro + return pTdata->GetParam( nType, nVal) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::TdbGetToolParam( const string& sName, int nType, double& dVal) const +{ + // recupero l'utensile + const ToolData* pTdata = TdbGetToolData( sName) ; + if ( pTdata == nullptr) + return false ; + // recupero il parametro + return pTdata->GetParam( nType, dVal) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::TdbGetToolParam( const string& sName, int nType, string& sVal) const +{ + // recupero l'utensile + const ToolData* pTdata = TdbGetToolData( sName) ; + if ( pTdata == nullptr) + return false ; + // recupero il parametro + return pTdata->GetParam( nType, sVal) ; +} + +//---------------------------------------------------------------------------- +ToolData* +MachMgr::TdbGetToolData( const string& sName) +{ + // recupero il gestore di utensili della macchina corrente + ToolsMgr* pTsMgr = GetCurrToolsMgr() ; + if ( pTsMgr == nullptr) + return nullptr ; + // recupero l'utensile + return pTsMgr->GetTool( sName) ; +} + //---------------------------------------------------------------------------- const ToolData* -MachMgr::GetToolData( const string& sName) const +MachMgr::TdbGetToolData( const string& sName) const { // recupero il gestore di utensili della macchina corrente ToolsMgr* pTsMgr = GetCurrToolsMgr() ; @@ -32,36 +176,12 @@ MachMgr::GetToolData( const string& sName) const //---------------------------------------------------------------------------- bool -MachMgr::GetToolParam( const string& sName, int nType, int& nVal) const +MachMgr::TdbSave( void) const { + // recupero il gestore di utensili della macchina corrente + ToolsMgr* pTsMgr = GetCurrToolsMgr() ; + if ( pTsMgr == nullptr) + return nullptr ; // recupero l'utensile - const ToolData* pTdata = GetToolData( sName) ; - if ( pTdata == nullptr) - return false ; - // recupero il parametro - return pTdata->GetParam( nType, nVal) ; -} - -//---------------------------------------------------------------------------- -bool -MachMgr::GetToolParam( const string& sName, int nType, double& dVal) const -{ - // recupero l'utensile - const ToolData* pTdata = GetToolData( sName) ; - if ( pTdata == nullptr) - return false ; - // recupero il parametro - return pTdata->GetParam( nType, dVal) ; -} - -//---------------------------------------------------------------------------- -bool -MachMgr::GetToolParam( const string& sName, int nType, string& sVal) const -{ - // recupero l'utensile - const ToolData* pTdata = GetToolData( sName) ; - if ( pTdata == nullptr) - return false ; - // recupero il parametro - return pTdata->GetParam( nType, sVal) ; + return pTsMgr->Save() ; } diff --git a/Machine.cpp b/Machine.cpp index 5e97091..44b0e8e 100644 --- a/Machine.cpp +++ b/Machine.cpp @@ -335,7 +335,7 @@ Machine::AdjustAxisVector( int nLay, const string& sPart, const string& sName, bool Machine::LoadMachineStdHead( const string& sName, const string& sParent, const std::string& sHSet, const Point3d& ptPos, const Vector3d& vtTDir, - const Vector3d& vtADir, const string& sGeo) + const Vector3d& vtADir, double dRot1W, const string& sGeo) { // recupero pezzo e layer della geometria originale dell'asse string sPart, sLay ; @@ -359,7 +359,7 @@ Machine::LoadMachineStdHead( const string& sName, const string& sParent, const s Head* pHead = new(nothrow) Head ; if ( pHead == nullptr) return false ; - pHead->Set( sName, MCH_HT_STD, sHSet, vtADir) ; + pHead->Set( sName, MCH_HT_STD, sHSet, vtADir, dRot1W) ; m_pGeomDB->SetUserObj( nLay, pHead) ; // aggiorno la testa capostipite if ( ! AddHeadToSet( sHSet, sName)) @@ -377,7 +377,7 @@ Machine::LoadMachineStdHead( const string& sName, const string& sParent, const s bool Machine::LoadMachineMultiHead( const string& sName, const string& sParent, const std::string& sHSet, const MUEXITVECTOR& vMuExit, - const Vector3d& vtADir, const string& sGeo) + const Vector3d& vtADir, double dRot1W, const string& sGeo) { // recupero pezzo e layer della geometria originale dell'asse string sPart, sLay ; @@ -401,7 +401,7 @@ Machine::LoadMachineMultiHead( const string& sName, const string& sParent, const Head* pHead = new(nothrow) Head ; if ( pHead == nullptr) return false ; - pHead->Set( sName, MCH_HT_MULTI, sHSet, vtADir) ; + pHead->Set( sName, MCH_HT_MULTI, sHSet, vtADir, dRot1W) ; m_pGeomDB->SetUserObj( nLay, pHead) ; // aggiorno la testa capostipite if ( ! AddHeadToSet( sHSet, sName)) @@ -562,17 +562,3 @@ Machine::CreateExitGroups( int nLay, const MUEXITVECTOR& vMuExit) } return true ; } - -//---------------------------------------------------------------------------- -bool -Machine::ResetAllAxesPos( void) -{ - // ciclo sugi gruppi della macchina - for ( auto Iter = m_mapGroups.cbegin() ; Iter != m_mapGroups.cend() ; ++ Iter) { - if ( IsAxisGroup( Iter->second)) { - if ( ! ResetAxisPos( Iter->first)) - return false ; - } - } - return true ; -} \ No newline at end of file diff --git a/Machine.h b/Machine.h index d17b65c..c39cb0b 100644 --- a/Machine.h +++ b/Machine.h @@ -51,7 +51,12 @@ class Machine 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, @@ -72,10 +77,10 @@ class Machine 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, const std::string& sGeo) ; + 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, const std::string& sGeo) ; + 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) ; } @@ -113,6 +118,7 @@ class Machine 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 diff --git a/MachineAxes.cpp b/MachineAxes.cpp index a01efa7..9f1453a 100644 --- a/MachineAxes.cpp +++ b/MachineAxes.cpp @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- -// File : MachineAXes.cpp Data : 11.05.15 Versione : 1.6e3 +// File : MachineAxes.cpp Data : 11.05.15 Versione : 1.6e3 // Contenuto : Implementazione gestione macchina : funzioni per assi. // // @@ -108,4 +108,18 @@ Machine::ResetAxisPos( const string& sAxis) return false ; // eseguo il movimento return SetAxisPos( sAxis, dHomeVal) ; -} \ No newline at end of file +} + +//---------------------------------------------------------------------------- +bool +Machine::ResetAllAxesPos( void) +{ + // ciclo sugi gruppi della macchina + for ( auto Iter = m_mapGroups.cbegin() ; Iter != m_mapGroups.cend() ; ++ Iter) { + if ( IsAxisGroup( Iter->second)) { + if ( ! ResetAxisPos( Iter->first)) + return false ; + } + } + return true ; +} diff --git a/MachineCalc.cpp b/MachineCalc.cpp index 693fa20..ed9b45b 100644 --- a/MachineCalc.cpp +++ b/MachineCalc.cpp @@ -96,12 +96,13 @@ Machine::SetCurrTool( const string& sTool, const string& sHead, int nExit) if ( nToolId == GDB_ID_NULL || m_pGeomDB->GetGdbType( nToolId) != GDB_TY_GROUP) return false ; double dTLen = 0 ; - if ( ! m_pMchMgr->GetToolParam( sTool, TPA_LEN, dTLen)) + if ( ! m_pMchMgr->TdbGetToolParam( sTool, TPA_LEN, dTLen)) return false ; // assegno tutti i dati m_nCalcHeadId = nHeadId ; m_nCalcExitId = nExitId ; m_nCalcToolId = nToolId ; + m_dCalcRot1W = pHead->GetRot1W() ; m_ptCalcPos = pExit->GetPos() ; m_vtCalcDir = pExit->GetTDir() ; m_vtCalcADir = pHead->GetADir() ; @@ -132,6 +133,14 @@ Machine::GetCurrTool( string& sTool) return m_pGeomDB->GetName( m_nCalcToolId, sTool) ; } +//---------------------------------------------------------------------------- +double +Machine::GetCurrRot1W( void) +{ + // restituisco il peso del primo asse rotante nei confronti di movimento + return m_dCalcRot1W ; +} + //---------------------------------------------------------------------------- bool Machine::CalculateKinematicChain( void) @@ -502,4 +511,68 @@ Machine::VerifyOutOfStroke( double dX, double dY, double dZ, double dAngA, doubl nStat += 512 ; } return true ; -} \ No newline at end of file +} + +//---------------------------------------------------------------------------- +int +Machine::GetCurrLinAxes( void) +{ + return int( m_vCalcLinAx.size()) ; +} + +//---------------------------------------------------------------------------- +int +Machine::GetCurrRotAxes( void) +{ + return int( m_vCalcRotAx.size()) ; +} + +//---------------------------------------------------------------------------- +bool +Machine::GetAllCurrAxesName( STRVECTOR& vAxName) +{ + vAxName.clear() ; + bool bOk = true ; + // ciclo sugi assi lineari correnti + for ( auto& CalcLinAx : m_vCalcLinAx) { + Axis* pAx = GetAxis( CalcLinAx.nGrpId) ; + if ( pAx != nullptr) + vAxName.emplace_back( pAx->GetName()) ; + else + bOk = false ; + } + // ciclo sugi assi rotanti correnti + for ( auto& CalcRotAx : m_vCalcRotAx) { + Axis* pAx = GetAxis( CalcRotAx.nGrpId) ; + if ( pAx != nullptr) + vAxName.emplace_back( pAx->GetName()) ; + else + bOk = false ; + } + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Machine::GetAllCurrAxesHomePos( DBLVECTOR& vAxHomeVal) +{ + vAxHomeVal.clear() ; + bool bOk = true ; + // ciclo sugi assi lineari correnti + for ( auto& CalcLinAx : m_vCalcLinAx) { + Axis* pAx = GetAxis( CalcLinAx.nGrpId) ; + if ( pAx != nullptr) + vAxHomeVal.emplace_back( pAx->GetHomeVal()) ; + else + bOk = false ; + } + // ciclo sugi assi rotanti correnti + for ( auto& CalcRotAx : m_vCalcRotAx) { + Axis* pAx = GetAxis( CalcRotAx.nGrpId) ; + if ( pAx != nullptr) + vAxHomeVal.emplace_back( pAx->GetHomeVal()) ; + else + bOk = false ; + } + return bOk ; +} diff --git a/MachineHeads.cpp b/MachineHeads.cpp index b66458e..29faed9 100644 --- a/MachineHeads.cpp +++ b/MachineHeads.cpp @@ -44,7 +44,7 @@ Machine::LoadTool( const string& sHead, int nExit, const string& sTool) return EnableHeadInSet( sHead) ; // verifico esistenza file utensile string sDraw ; - if ( ! m_pMchMgr->GetToolParam( sTool, TPA_DRAW, sDraw)) + if ( ! m_pMchMgr->TdbGetToolParam( sTool, TPA_DRAW, sDraw)) return false ; string sToolFile = m_sMachineDir + "\\" + TOOLS_DIR + "\\" + sDraw ; if ( ! ExistsFile( sToolFile)) diff --git a/MachineLua.cpp b/MachineLua.cpp index 349fac8..c21f81f 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -283,6 +283,9 @@ Machine::LuaEmtStdHead( lua_State* L) // lettura campo 'ADir' dalla tabella Vector3d vtADir ; LuaCheckTabFieldParam( L, 1, "ADir", vtADir) + // lettura eventuale campo 'Rot1W' dalla tabella (default 1) + double dRot1W = 1 ; + LuaGetTabFieldParam( L, 1, "Rot1W", dRot1W) ; // lettura campo 'Geo' dalla tabella string sGeo ; LuaCheckTabFieldParam( L, 1, "Geo", sGeo) @@ -297,7 +300,7 @@ Machine::LuaEmtStdHead( lua_State* L) return luaL_error( L, " Unknown Machine") ; // carico i dati della testa standard - if ( ! m_pMchLua->LoadMachineStdHead( sName, sParent, sHSet, ptPos, vtTDir, vtADir, sGeo)) + if ( ! m_pMchLua->LoadMachineStdHead( sName, sParent, sHSet, ptPos, vtTDir, vtADir, dRot1W, sGeo)) return luaL_error( L, " Load Machine Standard Head failed") ; return 0 ; @@ -339,6 +342,9 @@ Machine::LuaEmtMultiHead( lua_State* L) // lettura campo 'ADir' dalla tabella Vector3d vtADir ; LuaCheckTabFieldParam( L, 1, "ADir", vtADir) + // lettura eventuale campo 'Rot1W' dalla tabella (default 1) + double dRot1W = 1 ; + LuaGetTabFieldParam( L, 1, "Rot1W", dRot1W) ; // lettura campo 'Geo' dalla tabella string sGeo ; LuaCheckTabFieldParam( L, 1, "Geo", sGeo) @@ -353,7 +359,7 @@ Machine::LuaEmtMultiHead( lua_State* L) return luaL_error( L, " Unknown Machine") ; // carico i dati della testa multipla - if ( ! m_pMchLua->LoadMachineMultiHead( sName, sParent, sHSet, vMuExit, vtADir, sGeo)) + if ( ! m_pMchLua->LoadMachineMultiHead( sName, sParent, sHSet, vMuExit, vtADir, dRot1W, sGeo)) return luaL_error( L, " Load Machine Standard Head failed") ; return 0 ; diff --git a/Machining.cpp b/Machining.cpp index 3bd2016..e871340 100644 --- a/Machining.cpp +++ b/Machining.cpp @@ -15,6 +15,7 @@ #include "stdafx.h" #include "MachMgr.h" #include "Machining.h" +#include "MachiningConst.h" #include "CamData.h" #include "/EgtDev/Include/EGkGeoPoint3d.h" #include "/EgtDev/Include/EGkCurveLine.h" @@ -328,3 +329,161 @@ Machining::ResetMoveData( void) m_nFlag = 0 ; return true ; } + +//---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +bool +Machining::GetFinalAxesValues( DBLVECTOR& vAxVal) +{ + // recupero gruppo per geometria di lavorazione (Cutter Location) + int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ; + if ( nClId == GDB_ID_NULL) + return false ; + // recupero l'ultimo percorso CL + int nClPathId = m_pGeomDB->GetLastGroupInGroup( nClId) ; + // recupero l'ultima entità di questo percorso + int nEntId = m_pGeomDB->GetLastInGroup( nClPathId) ; + // recupero i dati Cam dell'entità + CamData* pCamData = dynamic_cast( m_pGeomDB->GetUserObj( nEntId)) ; + if ( pCamData == nullptr) + return false ; + // assegno i valori degli assi + vAxVal = pCamData->GetAxisVal() ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Machining::CalculateAxesValues( void) +{ + // recupero la lavorazione precedente + int nPrevOpId = m_pMchMgr->GetPrevOperation( GetOwner()) ; + Machining* pPrevMch = dynamic_cast( m_pGeomDB->GetUserObj( nPrevOpId)) ; + // recupero l'utensile precedente + string sPrevTool ; + if ( pPrevMch != nullptr) + pPrevMch->GetParam( MPA_TOOL, sPrevTool) ; + + // imposto l'utensile per i calcoli macchina + if ( ! m_pMchMgr->SetCalcTool( GetToolData().m_sName, GetToolData().m_sHead, GetToolData().m_nExit)) + return false ; + + // recupero il numero di assi lineari e rotanti attivi + int nLinAxes = m_pMchMgr->GetCurrLinAxes() ; + int nRotAxes = m_pMchMgr->GetCurrRotAxes() ; + + // assegno gli angoli iniziali + double dAngAprec = 0 ; + double dAngBprec = 0 ; + // se utensile non cambiato, uso gli angoli finali della lavorazione precedente + if ( ! sPrevTool.empty() && GetToolData().m_sName == sPrevTool) { + DBLVECTOR vAxVal ; + pPrevMch->GetFinalAxesValues( vAxVal) ; + if ( nRotAxes >= 1) + dAngAprec = vAxVal[nLinAxes - 1 + 1] ; + if ( nRotAxes >= 2) + dAngBprec = vAxVal[nLinAxes - 1 + 2] ; + } + // altrimenti uso gli angoli home + else { + DBLVECTOR vAxVal ; + m_pMchMgr->GetAllCalcAxesHomePos( vAxVal) ; + if ( nRotAxes >= 1) + dAngAprec = vAxVal[nLinAxes - 1 + 1] ; + if ( nRotAxes >= 2) + dAngBprec = vAxVal[nLinAxes - 1 + 2] ; + } + + // recupero peso primo asse rotante di testa + double dRot1W = m_pMchMgr->GetCalcRot1W() ; + + // recupero gruppo della geometria di lavorazione (Cutter Location) + int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ; + if ( nClId == GDB_ID_NULL) + return false ; + + // calcolo il valore degli assi macchina di tutti i movimenti + bool bOk = true ; + int nClPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; + while ( nClPathId != GDB_ID_NULL) { + if ( ! CalculateClPathAxesValues( nClPathId, nLinAxes, nRotAxes, dRot1W, dAngAprec, dAngBprec)) + bOk = false ; + nClPathId = m_pGeomDB->GetNextGroup( nClPathId) ; + } + + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Machining::CalculateClPathAxesValues( int nClPathId, int nLinAxes, int nRotAxes, double dRot1W, + double& dAngAprec, double& dAngBprec) +{ + // recupero il numero degli assi lineari e rotanti + // predispongo variabile per valori assi + DBLVECTOR vAxVal ; + vAxVal.reserve( 8) ; + // ciclo su tutte le entità del percorso CL + 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)) ; + if ( pCamData == nullptr) + continue ; + // 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, vAxVal) ; + continue ; + } + if ( nRStat == 2) { + double dDeltaA1 = dRot1W * fabs( dAngA1 - dAngAprec) ; + double dDeltaB1 = fabs( dAngB1 - dAngBprec) ; + double dDeltaA2 = dRot1W * fabs( dAngA2 - dAngAprec) ; + double dDeltaB2 = fabs( dAngB2 - dAngBprec) ; + if ( dDeltaA2 + dDeltaB2 < dDeltaA1 + dDeltaB1 - 1.) { + dAngA1 = dAngA2 ; + dAngB1 = dAngB2 ; + } + } + // ricavo posizione con eventuali modifiche dipendenti dalla lavorazione + Point3d ptP = pCamData->GetBasePoint() ; + AdjustPositionForAxesCalc( pCamData, ptP) ; + // 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, vAxVal) ; + continue ; + } + // assegno valori assi + vAxVal.clear() ; + vAxVal.emplace_back( dX) ; + vAxVal.emplace_back( dY) ; + vAxVal.emplace_back( dZ) ; + vAxVal.emplace_back( dAngA1) ; + vAxVal.emplace_back( 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, vAxVal) ; + continue ; + } + // salvo i valori degli assi + pCamData->SetAxes( CamData::AS_OK, vAxVal) ; + // memorizzo i valori degli angoli come nuovi precedenti + dAngAprec = dAngA1 ; + dAngBprec = dAngB1 ; + } + + return bOk ; +} diff --git a/Machining.h b/Machining.h index 848375f..706b7c6 100644 --- a/Machining.h +++ b/Machining.h @@ -31,6 +31,8 @@ class Machining : public IUserObj public : virtual bool Init( MachMgr* pMchMgr) ; + + public : virtual bool Prepare( const std::string& sMchName) = 0 ; virtual bool SetParam( int nType, bool bVal) = 0 ; virtual bool SetParam( int nType, int nVal) = 0 ; @@ -40,6 +42,8 @@ class Machining : public IUserObj //virtual bool ResetGeometry( void) = 0 ; virtual bool Apply( void) = 0 ; virtual bool GetParam( int nType, std::string& sVal) = 0 ; + virtual const ToolData& GetToolData( void) = 0 ; + virtual bool AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP) = 0 ; protected : Machining( void) ; @@ -48,6 +52,10 @@ class Machining : public IUserObj double GetApproachDist( void) { return 30.0 ; } bool GetElevation( const Point3d& ptP, const Vector3d& vtDir, double& dElev) ; bool GetElevation( const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtDir, double& dElev) ; + bool GetFinalAxesValues( DBLVECTOR& vAxVal) ; + bool CalculateAxesValues( void) ; + bool CalculateClPathAxesValues( int nClPathId, int nLinAxes, int nRotAxes, double dRot1W, + double& dAngAprec, double& dAngBprec) ; protected : bool SetPathId( int nPathId) ; diff --git a/Milling.cpp b/Milling.cpp index 69f0b28..e1d6f0e 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -207,6 +207,13 @@ Milling::GetParam( int nType, string& sVal) return false ; } +//---------------------------------------------------------------------------- +const ToolData& +Milling::GetToolData( void) +{ + return m_TParams ; +} + //---------------------------------------------------------------------------- bool Milling::VerifyGeometry( SelData Id, int& nSubs) @@ -375,3 +382,11 @@ Milling::Chain( int nGrpDestId) } return true ; } + +//---------------------------------------------------------------------------- +bool +Milling::AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP) +{ + // non devo fare alcunché + return true ; +} diff --git a/Milling.h b/Milling.h index 4050579..cc1e374 100644 --- a/Milling.h +++ b/Milling.h @@ -39,6 +39,8 @@ class Milling : public Machining virtual bool SetGeometry( const SELVECTOR& vIds) ; virtual bool Apply( void) ; virtual bool GetParam( int nType, std::string& sVal) ; + virtual const ToolData& GetToolData( void) ; + virtual bool AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP) ; public : Milling( void) ; diff --git a/Sawing.cpp b/Sawing.cpp index ec159ce..81ae82f 100644 --- a/Sawing.cpp +++ b/Sawing.cpp @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- -// File : Sawing.cpp Data : 07.06.15 Versione : 1.6f2 +// File : Sawing.cpp Data : 24.10.15 Versione : 1.6j3 // Contenuto : Implementazione gestione tagli con lama. // // Note : Questa lavorazione è sempre espressa nel riferimento globale. @@ -361,23 +361,8 @@ 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 ; + // calcolo gli assi macchina + return CalculateAxesValues() ; } //---------------------------------------------------------------------------- @@ -397,6 +382,13 @@ Sawing::GetParam( int nType, string& sVal) return true ; } +//---------------------------------------------------------------------------- +const ToolData& +Sawing::GetToolData( void) +{ + return m_TParams ; +} + //---------------------------------------------------------------------------- bool Sawing::VerifyGeometry( SelData Id, int& nSubs) @@ -878,66 +870,10 @@ Sawing::AdjustForEdges( ICurveLine* pLine, double dElev, bool bIsFirst, bool bIs //---------------------------------------------------------------------------- bool -Sawing::ClPathApply( int nClPathId, double& dAngAprec, double& dAngBprec) +Sawing::AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP) { - // 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 ; - } + // compenso il raggio dell'utensile + ptP += pCamData->GetCorrDir() * ( m_TParams.m_dDiam / 2) ; - return bOk ; + return true ; } diff --git a/Sawing.h b/Sawing.h index 2baed4f..d978e0b 100644 --- a/Sawing.h +++ b/Sawing.h @@ -39,7 +39,10 @@ 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 CalculateAxesValues( void) ; virtual bool GetParam( int nType, std::string& sVal) ; + virtual const ToolData& GetToolData( void) ; + virtual bool AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP) ; public : Sawing( void) ; @@ -54,7 +57,6 @@ 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/SawingData.cpp b/SawingData.cpp index 24c272a..dbab0be 100644 --- a/SawingData.cpp +++ b/SawingData.cpp @@ -16,6 +16,7 @@ #include "SawingData.h" #include "MachiningDataFactory.h" #include "/EgtDev/Include/EMkMachiningConst.h" +#include "/EgtDev/Include/EmkToolConst.h" #include "/EgtDev/Include/EGkGeoConst.h" #include "/EgtDev/Include/EGnStringUtils.h" #include diff --git a/Simulator.cpp b/Simulator.cpp index 8f65739..698e93a 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -31,6 +31,8 @@ Simulator::Simulator( void) m_nCLPathId = GDB_ID_NULL ; m_nEntId = GDB_ID_NULL ; m_dCoeff = 0 ; + m_AxesName.reserve( 8) ; + m_AxesVal.reserve( 8) ; } //---------------------------------------------------------------------------- @@ -72,40 +74,15 @@ Simulator::Start( void) 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()) + + // aggiornamenti legati al cambio di lavorazione (utensile e assi conseguenti) + if ( ! UpdateTool() || ! UpdateAxes()) 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 ; - } + if ( ! GoHome()) + return false ; + // determino il primo percorso di lavoro int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOpId, MCH_CL) ; m_nCLPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; @@ -141,13 +118,16 @@ Simulator::Move( void) m_nCLPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ; m_dCoeff = 0 ; + // aggiorno utensile e assi conseguenti + if ( ! UpdateTool() || ! UpdateAxes()) + return false ; } // 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() ; + const DBLVECTOR& AxesEnd = pCamData->GetAxisVal() ; // Verifico se movimento in rapido bool bRapid = ( pCamData->GetFeed() < EPS_SMALL) ; // Calcolo distanza di movimento @@ -196,3 +176,46 @@ Simulator::Stop( void) m_dCoeff = 0 ; return true ; } + +//---------------------------------------------------------------------------- +bool +Simulator::UpdateTool( void) +{ + // Recupero l'utensile della lavorazione corrente + 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->TdbGetToolData( sTool) ; + if ( pTdata == nullptr) + return false ; + // se cambiato, attivo l'utensile della lavorazione + if ( sTool != m_sTool) { + if ( ! m_pMchMgr->SetCalcTool( sTool, pTdata->m_sHead, pTdata->m_nExit)) + return false ; + m_sTool = sTool ; + } + return true ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::UpdateAxes( void) +{ + // Macchina corrente + Machine* pMachine = m_pMchMgr->GetCurrMachine() ; + if ( pMachine == nullptr) + return false ; + // Carico i nomi degli assi macchina attivi + return pMachine->GetAllCurrAxesName( m_AxesName) ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::GoHome( void) +{ + // porto la macchina in home + m_pMchMgr->ResetAllAxesPos() ; + // assegno valori home degli assi macchina attivi + return m_pMchMgr->GetAllCalcAxesHomePos( m_AxesVal) ; +} diff --git a/Simulator.h b/Simulator.h index c65457e..8ba9d94 100644 --- a/Simulator.h +++ b/Simulator.h @@ -30,6 +30,11 @@ class Simulator bool SetStep( double dStep) ; bool Stop( void) ; + private : + bool UpdateTool( void) ; + bool UpdateAxes( void) ; + bool GoHome( void) ; + private : MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni IGeomDB* m_pGeomDB ; // puntatore al DB geometrico @@ -38,6 +43,7 @@ class Simulator int m_nCLPathId ; // identificativo del percorso di lavoro corrente int m_nEntId ; // identificativo dell'entità corrente double m_dCoeff ; // coefficiente di movimento corrente + std::string m_sTool ; // nome dell'utensile corrente STRVECTOR m_AxesName ; // nomi degli assi macchina attivi - MachAxesVal m_AxesVal ; // valori degli assi macchina all'inizio del movimento corrente + DBLVECTOR m_AxesVal ; // valori degli assi macchina all'inizio del movimento corrente } ; diff --git a/ToolData.cpp b/ToolData.cpp index 4d466b5..80c76cb 100644 --- a/ToolData.cpp +++ b/ToolData.cpp @@ -240,6 +240,110 @@ ToolData::VerifySpeed( double dVal) const return ( dVal < m_dMaxSpeed + EPS_SMALL) ; } +//---------------------------------------------------------------------------- +bool +ToolData::SetParam( int nType, int nVal) +{ + switch ( nType) { + case TPA_CORR : + m_nCorr = nVal ; + return true ; + case TPA_EXIT : + m_nExit = nVal ; + return true ; + case TPA_TYPE : + m_nType = nVal ; + return true ; + } + return false ; +} + +//---------------------------------------------------------------------------- +bool +ToolData::SetParam( int nType, double dVal) +{ + switch ( nType) { + case TPA_CORNRAD : + m_dCornRad = dVal ; + return true ; + case TPA_DIAM : + m_dDiam = dVal ; + return true ; + case TPA_TOTDIAM : + m_dTDiam = dVal ; + return true ; + case TPA_FEED : + m_dFeed = dVal ; + return true ; + case TPA_ENDFEED : + m_dEndFeed = dVal ; + return true ; + case TPA_STARTFEED : + m_dStartFeed = dVal ; + return true ; + case TPA_TIPFEED : + m_dTipFeed = dVal ; + return true ; + case TPA_LEN : + m_dLen = dVal ; + return true ; + case TPA_TOTLEN : + m_dTLen = dVal ; + return true ; + case TPA_MAXMAT : + m_dMaxMat = dVal ; + return true ; + case TPA_LONOFFSET : + m_dOffsL = dVal ; + return true ; + case TPA_RADOFFSET : + m_dOffsR = dVal ; + return true ; + case TPA_SPEED : + m_dSpeed = dVal ; + return true ; + case TPA_SIDEANG : + m_dSideAng = dVal ; + return true ; + case TPA_MAXSPEED : + m_dMaxSpeed = dVal ; + return true ; + case TPA_THICK : + m_dThick = dVal ; + return true ; + } + return false ; +} + +//---------------------------------------------------------------------------- +bool +ToolData::SetParam( int nType, const string& sVal) +{ + switch ( nType) { + case TPA_DRAW : + m_sDraw = sVal ; + return true ; + case TPA_HEAD : + m_sHead = sVal ; + return true ; + case TPA_NAME : + m_sName = sVal ; + return true ; + case TPA_SYSNOTES : + m_sSysNotes = sVal ; + return true ; + case TPA_USERNOTES : + m_sUserNotes = sVal ; + return true ; + case TPA_TCPOS : + m_sTcPos = sVal ; + return true ; + case TPA_UUID : + return ::FromString( sVal, m_Uuid) ; + } + return false ; +} + //---------------------------------------------------------------------------- bool ToolData::GetParam( int nType, int& nVal) const @@ -343,4 +447,4 @@ ToolData::GetParam( int nType, string& sVal) const return true ; } return false ; -} \ No newline at end of file +} diff --git a/ToolData.h b/ToolData.h index 5c27bf2..17580d8 100644 --- a/ToolData.h +++ b/ToolData.h @@ -47,7 +47,7 @@ struct ToolData std::string m_sUserNotes ; // note dell'utente ToolData( void) - : m_Uuid(), m_nExit( 0), m_nCorr(0), m_nType(0), m_dMaxSpeed(0), m_dMaxMat(0), + : m_Uuid(), m_sHead( "H1"), m_nExit( 1), m_nCorr(0), m_nType(0), m_dMaxSpeed(0), m_dMaxMat(0), m_dDiam( 0), m_dTDiam( 0), m_dLen( 0), m_dTLen( 0), m_dThick( 0), m_dCornRad( 0), m_dSideAng( 0), m_dSpeed( 0), m_dFeed(0), m_dStartFeed( 0), m_dEndFeed( 0), m_dTipFeed( 0), m_dOffsR( 0), m_dOffsL( 0) {} @@ -57,29 +57,10 @@ struct ToolData std::string ToString( int nInd) const ; bool VerifySpeed( double dVal) const ; + bool SetParam( int nType, int nVal) ; + bool SetParam( int nType, double dVal) ; + bool SetParam( int nType, const std::string& sVal) ; bool GetParam( int nType, int& nVal) const ; bool GetParam( int nType, double& dVal) const ; bool GetParam( int nType, std::string& sVal) const ; } ; - -//---------------------------------------------------------------------------- -// Costanti per famiglie di utensili -const int TF_DRILLBIT = 0x0100 ; // 256 -const int TF_SAWBLADE = 0x0200 ; // 512 -const int TF_MILL = 0x0400 ; // 1024 -const int TF_MORTISE = 0x0800 ; // 2048 -const int TF_COMPO = 0x1000 ; // 4096 - -//---------------------------------------------------------------------------- -// Tipologie di utensili -enum ToolType { - TT_NONE = 0, - TT_DRILL_STD = TF_DRILLBIT + 0, // 256 - TT_DRILL_LONG = TF_DRILLBIT + 1, // 257 - TT_SAW_STD = TF_SAWBLADE + 0, // 512 - TT_SAW_FLAT = TF_SAWBLADE + 1, // 513 - TT_MILL_STD = TF_MILL + 0, // 1024 - TT_MILL_NOTIP = TF_MILL + 1, // 1025 - TT_MORTISE_STD = TF_MORTISE + 0, // 2048 - TT_COMPO = TF_COMPO + 0 // 4096 -} ; diff --git a/ToolsMgr.cpp b/ToolsMgr.cpp index 8648135..ffc666e 100644 --- a/ToolsMgr.cpp +++ b/ToolsMgr.cpp @@ -15,6 +15,7 @@ #include "stdafx.h" #include "ToolsMgr.h" #include "DllMain.h" +#include "/EgtDEv/Include/EmkToolConst.h" #include "/EgtDEv/Include/EGnStringUtils.h" #include "/EgtDEv/Include/EGnFileUtils.h" #include "/EgtDEv/Include/EGnScanner.h" @@ -260,6 +261,82 @@ ToolsMgr::SaveOneTool( const EgtUUID& Uuid, Writer& TheWriter) const return bOk ; } +//---------------------------------------------------------------------------- +bool +ToolsMgr::AddTool( const string& sName, int nType) +{ + // verifico unicità del nome + if ( m_suData.find( sName) != m_suData.end()) + return false ; + // verifico validità del tipo + if ( ! IsValidToolType( nType)) + return false ; + // definisco un utensile con valori di default + ToolData tData ; + tData.m_sName = sName ; + tData.m_nType = nType ; + CreateEgtUUID( tData.m_Uuid) ; + // salvo i dati dell'utensile + return ( m_utData.emplace( tData.m_Uuid, tData).second && + m_suData.emplace( tData.m_sName, tData.m_Uuid).second) ; +} + +//---------------------------------------------------------------------------- +bool +ToolsMgr::CopyTool( const std::string& sSource, const std::string& sName) +{ + // verifico unicità del nome + if ( m_suData.find( sName) != m_suData.end()) + return false ; + // recupero l'utensile sorgente + const ToolData* pTdata = GetTool( sSource) ; + if ( pTdata == nullptr) + return false ; + // ne faccio una copia + ToolData tData = *pTdata ; + // modifico nome e UUID + tData.m_sName = sName ; + CreateEgtUUID( tData.m_Uuid) ; + // salvo i dati del nuovo utensile + return ( m_utData.emplace( tData.m_Uuid, tData).second && + m_suData.emplace( tData.m_sName, tData.m_Uuid).second) ; +} + +//---------------------------------------------------------------------------- +bool +ToolsMgr::RemoveTool( const string& sName) +{ + // cerco l'utensile nell'elenco dei nomi + auto iNameIter = m_suData.find( sName) ; + if ( iNameIter == m_suData.end()) + return true ; + // rimuovo l'utensile dal dizionario degli UUID + m_utData.erase( iNameIter->second) ; + // rimuovo l'utensile dall'elenco dei nomi + m_suData.erase( iNameIter) ; + return true ; +} + +//---------------------------------------------------------------------------- +ToolData* +ToolsMgr::GetTool( const EgtUUID& Uuid) +{ + auto iIter = m_utData.find( Uuid) ; + if ( iIter == m_utData.end()) + return nullptr ; + return &( iIter->second) ; +} + +//---------------------------------------------------------------------------- +ToolData* +ToolsMgr::GetTool( const string& sName) +{ + auto iIter = m_suData.find( sName) ; + if ( iIter == m_suData.end()) + return nullptr ; + return GetTool( iIter->second) ; +} + //---------------------------------------------------------------------------- const ToolData* ToolsMgr::GetTool( const EgtUUID& Uuid) const diff --git a/ToolsMgr.h b/ToolsMgr.h index 50392d8..0efbbee 100644 --- a/ToolsMgr.h +++ b/ToolsMgr.h @@ -28,6 +28,11 @@ class ToolsMgr bool Init( const std::string& sToolsFile) ; bool Load( void) ; bool Save( bool bCompressed = true) const ; + bool AddTool( const std::string& sName, int nType) ; + bool CopyTool( const std::string& sSource, const std::string& sName) ; + bool RemoveTool( const std::string& sName) ; + ToolData* GetTool( const EgtUUID& Uuid) ; + ToolData* GetTool( const std::string& sName) ; const ToolData* GetTool( const EgtUUID& Uuid) const ; const ToolData* GetTool( const std::string& sName) const ; bool GetFirstTool( int nFamily, std::string& sName, int& nType) const ;