EgtExecutor 2.2k6 :

- aggiunta funzione Exe e Lua SaveMachGroupToFile.
This commit is contained in:
Dario Sassi
2020-11-30 08:26:52 +00:00
parent f703ba365e
commit db726f6fd6
3 changed files with 111 additions and 3 deletions
+91 -3
View File
@@ -18,6 +18,7 @@
#include "AuxTools.h"
#include "/EgtDev/Include/EXeExecutor.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EGnFileUtils.h"
#include "/EgtDev/Include/EgtStringConverter.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
@@ -442,14 +443,101 @@ ExeSaveObjToFile( int nId, const string& sFilePath, int nFlag)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
IMachMgr* pMachMgr = GetCurrMachMgr() ;
// se l'oggetto è la base dei gruppi di lavoro, chiamo la funzione di salvataggio di tutto
if ( pMachMgr != nullptr && pMachMgr->IsMachBase( nId))
return ExeSaveFile( sFilePath, nFlag) ;
// se l'oggetto è un gruppo di lavoro o una sua parte, chiamo la appropriata funzione di salvataggio
int nParentId = pGeomDB->GetParentId( nId) ;
int nPrevParId = nId ;
while ( pMachMgr != nullptr && nParentId != GDB_ID_NULL && nParentId != GDB_ID_ROOT) {
if ( pMachMgr->IsMachBase( nParentId))
return ExeSaveMachGroupToFile( nPrevParId, sFilePath, nFlag) ;
nPrevParId = nParentId ;
nParentId = pGeomDB->GetParentId( nParentId) ;
}
// se ero in CAM, non esco <---
// copio l'oggetto nel file
bool bOk = pGeomDB->Save( nId, sFilePath, nFlag) ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSaveObjToFile('" + StringToLuaString( sFilePath) + "'," +
ToString( nId) + "," +
NgeTypeToString( nFlag) + ")" +
string sLua = "EgtSaveObjToFile(" + ToString( nId) + ",'" +
StringToLuaString( sFilePath) + "'," +
NgeTypeToString( nFlag) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco il risultato
return bOk ;
}
//-----------------------------------------------------------------------------
bool
ExeSaveMachGroupToFile( int nMGroupId, const string& sFilePath, int nFlag)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
IMachMgr* pMachMgr = GetCurrMachMgr() ;
VERIFY_MACHMGR( pMachMgr, false)
// disabilito registrazione dei comandi
bool bPrevCmdLog = SetCmdLog( false) ;
// disabilito possibilità di alterare il flag di modifica
bool bOldEnabModif = ExeGetEnableModified() ;
if ( bOldEnabModif)
ExeDisableModified() ;
// se ero in CAM, esco dopo averne salvato lo stato
CamStatus CurrCamStatus ;
ExeResetCurrMachGroup() ;
// recupero eventuali pezzi e foto del gruppo di lavoro
INTVECTOR vId ;
int nPhotoId = GDB_ID_NULL ;
string sPhotoOriPath = "" ;
if ( pMachMgr->SetCurrMachGroup( nMGroupId)) {
// aggiungo gruppo di lavoro
vId.emplace_back( nMGroupId) ;
// aggiungo pezzi
int nRawId = pMachMgr->GetFirstRawPart() ;
while ( nRawId != GDB_ID_NULL) {
int nPartId = pMachMgr->GetFirstPartInRawPart( nRawId) ;
while ( nPartId != GDB_ID_NULL) {
if ( find( vId.begin(), vId.end(), nPartId) == vId.end())
vId.emplace_back( nPartId) ;
nPartId = pMachMgr->GetNextPartInRawPart( nPartId) ;
}
nRawId = pMachMgr->GetNextRawPart( nRawId) ;
}
// aggiungo eventuale foto
static const string PHOTO_GRP = "Photos" ;
static const string PHOTO_NAME = "Raw" ;
string sMGroupName = pMachMgr->GetMachGroupName( nMGroupId) ;
nPhotoId = pGeomDB->GetFirstNameInGroup( pGeomDB->GetFirstNameInGroup( GDB_ID_ROOT, PHOTO_GRP), PHOTO_NAME + sMGroupName) ;
if ( nPhotoId != GDB_ID_NULL) {
vId.emplace_back( nPhotoId) ;
ExeGetPhotoPath( nPhotoId, sPhotoOriPath) ;
string sPhotoNewPath = ChangeFileExtension( sFilePath, GetFileExtension( sPhotoOriPath)) ;
ExeChangePhotoPath( nPhotoId, sPhotoNewPath) ;
CopyFileEgt( sPhotoOriPath, sPhotoNewPath) ;
}
// disattivo gruppo di lavoro
pMachMgr->ResetCurrMachGroup() ;
}
// salvo gli oggetti appena identificati
bool bOk = pGeomDB->Save( vId, sFilePath, nFlag) ;
// eventuale ripristino dati fotografia
if ( nPhotoId != GDB_ID_NULL)
ExeChangePhotoPath( nPhotoId, sPhotoOriPath) ;
// eventuale ripristino precedente CAM
CurrCamStatus.Restore() ;
// ripristino possibilità di alterare il flag di modifica
if ( bOldEnabModif)
ExeEnableModified() ;
// ripristino registrazione dei comandi
SetCmdLog( bPrevCmdLog) ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSaveMachGroupToFile(" + ToString( nMGroupId) + ",'" +
StringToLuaString( sFilePath) + "'," +
NgeTypeToString( nFlag) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
BIN
View File
Binary file not shown.
+20
View File
@@ -321,6 +321,25 @@ LuaSaveObjToFile( lua_State* L)
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaSaveMachGroupToFile( lua_State* L)
{
// 2 o 3 parametri : nMGroupId, path del file [, flag]
int nMGroupId ;
LuaCheckParam( L, 1, nMGroupId)
string sFilePath ;
LuaCheckParam( L, 2, sFilePath)
int nFlag = GDB_SV_CMPTXT ;
LuaGetParam( L, 3, nFlag) ;
LuaClearStack( L) ;
// copio il gruppo nel file
bool bOk = ExeSaveMachGroupToFile( nMGroupId, sFilePath, nFlag) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
bool
LuaInstallGeomDB( LuaMgr& luaMgr)
@@ -345,5 +364,6 @@ LuaInstallGeomDB( LuaMgr& luaMgr)
bOk = bOk && luaMgr.RegisterFunction( "EgtInsertFile", LuaInsertFile) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSaveFile", LuaSaveFile) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSaveObjToFile", LuaSaveObjToFile) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSaveMachGroupToFile", LuaSaveMachGroupToFile) ;
return bOk ;
}