diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index ed21170..aa6a3ee 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/EgtMachKernel.vcxproj b/EgtMachKernel.vcxproj index 81f414d..a5c776e 100644 --- a/EgtMachKernel.vcxproj +++ b/EgtMachKernel.vcxproj @@ -205,6 +205,7 @@ copy $(TargetPath) \EgtProg\Dll64 + diff --git a/EgtMachKernel.vcxproj.filters b/EgtMachKernel.vcxproj.filters index 0d8429d..6775123 100644 --- a/EgtMachKernel.vcxproj.filters +++ b/EgtMachKernel.vcxproj.filters @@ -42,6 +42,9 @@ Source Files + + Source Files + diff --git a/MachMgr.h b/MachMgr.h index c848870..f5f6b11 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -14,6 +14,7 @@ #pragma once #include "MachConst.h" +#include "Machine.h" #include "/EgtDev/Include/EMkMachMgr.h" #include "/EgtDev/Include/EgtNumCollection.h" @@ -37,7 +38,8 @@ class MachMgr : public IMachMgr { public : // Basic - virtual bool Init( IGeomDB* pGeomDB, const std::string& sMachinesDir) ; + virtual ~MachMgr( void) ; + virtual bool Init( int nContextId, IGeomDB* pGeomDB, const std::string& sMachinesDir) ; virtual bool Update( void) ; virtual bool Insert( int nInsGrp) ; // MachGroups @@ -78,6 +80,7 @@ class MachMgr : public IMachMgr private : // Basic + void Clear( void) ; bool IsMachBase( int nId) const ; int FindMachBase( int nGroupId) const ; bool VerifyMachBase( void) const ; @@ -101,7 +104,8 @@ class MachMgr : public IMachMgr (( m_nCurrMGrpId == GDB_ID_NULL) ? GDB_ID_NULL : m_cCurrMGrp.OperGroupId) ; } // Machines bool LoadMachine( const std::string& sMachineName) ; - int GetMachineId( const std::string& sMachineName) const ; + int GetMachine( const std::string& sMachineName) const ; + int GetCurrMGeoId( void) const ; // RawParts int AddRawPart( int nCrvId, double dOverMat, double dZmin, double dHeight, Color cCol) ; int AddRawPart( int nSurfId, Color cCol) ; @@ -116,11 +120,16 @@ class MachMgr : public IMachMgr bool ShowRootParts( bool bShow) ; private : + typedef std::vector MCHPVECTOR ; + + private : + int m_nContextId ; // 1-based IGeomDB* m_pGeomDB ; std::string m_sMachinesDir ; int m_nMachBaseId ; int m_nMachAuxId ; int m_nCurrMGrpId ; MachGrp m_cCurrMGrp ; - int m_nCurrMGeoId ; + int m_nCurrMch ; // 0-based + MCHPVECTOR m_vMachines ; } ; diff --git a/MachMgrBasic.cpp b/MachMgrBasic.cpp index c6d68b6..b863b6c 100644 --- a/MachMgrBasic.cpp +++ b/MachMgrBasic.cpp @@ -52,30 +52,52 @@ CreateMachMgr( void) //---------------------------------------------------------------------------- MachMgr::MachMgr( void) { + m_nContextId = 0 ; m_pGeomDB = nullptr ; m_nMachBaseId = GDB_ID_NULL ; m_nMachAuxId = GDB_ID_NULL ; m_nCurrMGrpId = GDB_ID_NULL ; - m_nCurrMGeoId = GDB_ID_NULL ; + m_nCurrMch = 0 ; +} + +//---------------------------------------------------------------------------- +MachMgr::~MachMgr( void) +{ + Clear() ; +} + +//---------------------------------------------------------------------------- +void +MachMgr::Clear( void) +{ + // pulisco le macchine + while ( ! m_vMachines.empty()) { + if ( m_vMachines.back() != nullptr) + delete m_vMachines.back() ; + m_vMachines.pop_back() ; + } } //---------------------------------------------------------------------------- bool -MachMgr::Init( IGeomDB* pGeomDB, const string& sMachinesDir) +MachMgr::Init( int nContextId, IGeomDB* pGeomDB, const string& sMachinesDir) { + m_nContextId = nContextId ; m_pGeomDB = pGeomDB ; m_sMachinesDir = sMachinesDir ; m_nMachBaseId = GDB_ID_NULL ; m_nMachAuxId = GDB_ID_NULL ; m_nCurrMGrpId = GDB_ID_NULL ; - m_nCurrMGeoId = GDB_ID_NULL ; - return ( m_pGeomDB != nullptr && ExistsDirectory( m_sMachinesDir)) ; + m_nCurrMch = - 1 ; + return ( m_nContextId > 0 && m_pGeomDB != nullptr && ExistsDirectory( m_sMachinesDir)) ; } //---------------------------------------------------------------------------- bool MachMgr::Update( void) { + // pulizia + Clear() ; // ricerca del gruppo base per le lavorazioni m_nMachBaseId = FindMachBase( GDB_ID_ROOT) ; // imposto gruppo di lavorazione corrente a nessuno diff --git a/MachMgrMachGroups.cpp b/MachMgrMachGroups.cpp index dfc5531..2fef45c 100644 --- a/MachMgrMachGroups.cpp +++ b/MachMgrMachGroups.cpp @@ -258,19 +258,19 @@ MachMgr::SetCurrMachGroup( int nId) SwapParts( false) ; // nascondo precedente gruppo corrente e la relativa macchina m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_OFF) ; - m_pGeomDB->SetStatus( m_nCurrMGeoId, GDB_ST_OFF) ; + m_pGeomDB->SetStatus( GetCurrMGeoId(),GDB_ST_OFF) ; } // imposto i dati del nuovo gruppo corrente m_nCurrMGrpId = nId ; m_cCurrMGrp = mgData ; - m_nCurrMGeoId = GetMachineId( m_cCurrMGrp.MGeoName) ; + m_nCurrMch = GetMachine( m_cCurrMGrp.MGeoName) ; // porto i pezzi dalla loro posizione standard nei grezzi nuovi SwapParts( true) ; // nascondo 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) ; - m_pGeomDB->SetStatus( m_nCurrMGeoId, GDB_ST_ON) ; + m_pGeomDB->SetStatus( GetCurrMGeoId(), GDB_ST_ON) ; return true ; } @@ -290,10 +290,10 @@ MachMgr::ResetCurrMachGroup( void) ShowRootParts( true) ; // nascondo gruppo corrente e la relativa macchina m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_OFF) ; - m_pGeomDB->SetStatus( m_nCurrMGeoId, GDB_ST_OFF) ; + m_pGeomDB->SetStatus( GetCurrMGeoId(), GDB_ST_OFF) ; // dichiaro nessun gruppo corrente e la relativa macchina m_nCurrMGrpId = GDB_ID_NULL ; - m_nCurrMGeoId = GDB_ID_NULL ; + m_nCurrMch = - 1 ; return true ; } diff --git a/MachMgrMachines.cpp b/MachMgrMachines.cpp index bda41da..619e713 100644 --- a/MachMgrMachines.cpp +++ b/MachMgrMachines.cpp @@ -30,8 +30,24 @@ MachMgr::LoadMachine( const string& sMachineName) if ( ! IsValidName( sMachineName)) return false ; // se macchina gią caricata, non devo fare alcunchč - if ( GetMachineId( sMachineName) != GDB_ID_NULL) + if ( GetMachine( sMachineName) != - 1) return true ; + // creo gruppo ausiliario di base per le macchine + if ( ! CreateMachAux()) + return false ; + // creo una nuova macchina + PtrOwner pMch( new( nothrow) Machine) ; + if ( IsNull( pMch)) + return false ; + // tento di caricarla + string sMachineDir = m_sMachinesDir + "\\" + sMachineName ; + if ( pMch->Init( m_nContextId, m_pGeomDB, m_nMachAuxId, sMachineDir, sMachineName)) { + m_vMachines.push_back( Release( pMch)) ; + return true ; + } + return false ; + +#if 0 // verifico esistenza macchina string sMachineDir = m_sMachinesDir + "\\" + sMachineName ; string sMachineMde = sMachineDir + "\\" + sMachineName + ".Mde" ; @@ -49,12 +65,22 @@ MachMgr::LoadMachine( const string& sMachineName) // inserisco la geometria della macchina !!! PROVVISORIO !!! string sMachineNge = sMachineDir + "\\" + sMachineName + ".Nge" ; return m_pGeomDB->Load( sMachineNge, nId) ; +#endif } //---------------------------------------------------------------------------- int -MachMgr::GetMachineId( const string& sMachineName) const +MachMgr::GetMachine( const string& sMachineName) const { + // ciclo sulle macchine + for ( size_t i = 0 ; i < m_vMachines.size() ; ++ i) { + if ( m_vMachines[i] != nullptr && + CompareNoCase( m_vMachines[i]->GetMachineName(), sMachineName)) + return int( i) ; + } + return - 1 ; + +#if 0 // verifico validitą del nome if ( ! IsValidName( sMachineName)) return GDB_ID_NULL ; @@ -75,4 +101,15 @@ MachMgr::GetMachineId( const string& sMachineName) const bIter = pIter->GoToNextGroup() ; } return GDB_ID_NULL ; +#endif +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetCurrMGeoId( void) const +{ + if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || + m_vMachines[m_nCurrMch] == nullptr) + return GDB_ID_NULL ; + return ( m_vMachines[m_nCurrMch]->GetMGeoId()) ; } diff --git a/Machine.cpp b/Machine.cpp new file mode 100644 index 0000000..39d4000 --- /dev/null +++ b/Machine.cpp @@ -0,0 +1,84 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : Machine.cpp Data : 06.05.15 Versione : 1.6e3 +// Contenuto : Implementazione gestione macchina. +// +// +// +// Modifiche : 06.05.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "Machine.h" +#include "/EgtDev/Include/EGkGeomDB.h" +#include "/EgtDev/Include/EGnStringUtils.h" +#include "/EgtDev/Include/EGnFileUtils.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +Machine::Machine( void) +{ + m_nContextId = 0 ; + m_pGeomDB = nullptr ; + m_nGroupId = GDB_ID_NULL ; +} + +//---------------------------------------------------------------------------- +Machine::~Machine( void) +{ + Clear() ; +} + +//---------------------------------------------------------------------------- +void +Machine::Clear( void) +{ + // cancellazione eventuale gruppo geometrico associato + if ( m_pGeomDB != nullptr && m_nGroupId != GDB_ID_NULL) + m_pGeomDB->Erase( m_nGroupId) ; + // reset membri + m_nContextId = 0 ; + m_pGeomDB = nullptr ; + m_nGroupId = GDB_ID_NULL ; + m_sName.clear() ; +} + +//---------------------------------------------------------------------------- +bool +Machine::Init( int nContextId, IGeomDB* pGeomDB, int nMachAuxId, + const string& sMachineDir, const string& sMachineName) +{ + // pulisco + Clear() ; + // verifico ambiente geometrico + if ( nContextId == 0 || pGeomDB == nullptr) + return false ; + // verifico esistenza macchina + string sMachineMde = sMachineDir + "\\" + sMachineName + ".Mde" ; + if ( ! ExistsFile( sMachineMde)) + return false ; + // creo il gruppo per la macchina + int nId = pGeomDB->InsertGroup( GDB_ID_NULL, nMachAuxId, GDB_LAST_SON, GLOB_FRM) ; + if ( nId == GDB_ID_NULL) + return false ; + // imposto nome del gruppo + pGeomDB->SetName( nId, sMachineName) ; + // inserisco la geometria della macchina !!! PROVVISORIO !!! + string sMachineNge = sMachineDir + "\\" + sMachineName + ".Nge" ; + if ( ! pGeomDB->Load( sMachineNge, nId)) { + pGeomDB->Erase( nId) ; + return false ; + } + // salvo i dati + m_nContextId = nContextId ; + m_pGeomDB = pGeomDB ; + m_nGroupId = nId ; + m_sMachineDir = sMachineDir ; + m_sName = sMachineName ; + return true ; +} \ No newline at end of file diff --git a/Machine.h b/Machine.h new file mode 100644 index 0000000..06b8367 --- /dev/null +++ b/Machine.h @@ -0,0 +1,42 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : Machine.h Data : 06.05.15 Versione : 1.6e3 +// Contenuto : Dichiarazione della classe Machine. +// +// +// +// Modifiche : 06.05.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkGeomDB.h" +#include + +//---------------------------------------------------------------------------- +class Machine +{ + public : + Machine( void) ; + ~Machine( void) ; + bool Init( int nContextId, IGeomDB* pGeomDB, int nMachAuxId, + const std::string& sMachineDir, const std::string& sMachineName) ; + int GetMGeoId( void) + { return m_nGroupId ; } + const std::string& GetMachineName( void) + { return m_sName ; } + + private : + void Clear( void) ; + + private : + int m_nContextId ; // 1-based + IGeomDB* m_pGeomDB ; + std::string m_sMachineDir ; + std::string m_sName ; + int m_nGroupId ; + +} ; diff --git a/stdafx.h b/stdafx.h index 993c811..f07152c 100644 --- a/stdafx.h +++ b/stdafx.h @@ -31,4 +31,5 @@ #pragma comment(lib, EGTLIBDIR "EgtGeneral" EGTLIBVER ".lib") #pragma comment(lib, EGTLIBDIR "EgtNumKernel" EGTLIBVER ".lib") #pragma comment(lib, EGTLIBDIR "EgtGeomKernel" EGTLIBVER ".lib") +#pragma comment(lib, EGTLIBDIR "EgtExecutor" EGTLIBVER ".lib") #pragma comment(lib, EGTLIBDIR "SEgtLock" EGTLIBVER ".lib")