66b56c544f
- aggiornamenti per cambio nomi include di base - corretto errore in registrazione comando EgtArcC2PNEx - corretto errore in ExeExplodeSurfTm (crash con entità non superfici) - aggiunte funzioni Exe e Lua di movimento assi e carico/scarico teste di macchina - aggiunta Exe e Lua ZoomRadius - possibilità di lua EgtOutBox non modale (solo per usi interni).
380 lines
13 KiB
C++
380 lines
13 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2015
|
|
//----------------------------------------------------------------------------
|
|
// File : EXE_GeomDB.cpp Data : 04.05.15 Versione : 1.6e1
|
|
// Contenuto : Funzioni DB geometrico per EXE.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 01.09.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "EXE.h"
|
|
#include "EXE_Macro.h"
|
|
#include "AuxTools.h"
|
|
#include "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EGkStringUtils3d.h"
|
|
#include "/EgtDev/Include/EgtStringConverter.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
|
|
using namespace std ;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
ExeInitGeomDB( void)
|
|
{
|
|
// creo e recupero un contesto libero
|
|
int nGseCtx = CreateGseContext() ;
|
|
if ( nGseCtx == 0) {
|
|
ResetCurrGseContext() ;
|
|
LOG_ERROR( GetLogger(), "Error in CreateGseContext (" __FUNCTION__ ")")
|
|
return 0 ;
|
|
}
|
|
GseContext* pGseCtx = GetGseContext( nGseCtx) ;
|
|
// inizializzazioni DB geometrico
|
|
PtrOwner<IGeomDB> pGeomDB( CreateGeomDB()) ;
|
|
VERIFY_NULL( Get( pGeomDB), "Error in CreateGeomDB", nGseCtx)
|
|
// inserisco il GeomDB nel contesto
|
|
pGseCtx->m_pGeomDB = Release( pGeomDB) ;
|
|
pGseCtx->m_pGeomDB->Init() ;
|
|
pGseCtx->m_pGeomDB->SetDefaultMaterial( pGseCtx->m_colDef) ;
|
|
// rendo corrente il contesto
|
|
SetCurrGseContext( nGseCtx) ;
|
|
// log avvio DB geometrico
|
|
string sLog = "GeomDB started " + ToString( nGseCtx) ;
|
|
LOG_INFO( GetLogger(), sLog.c_str())
|
|
|
|
return nGseCtx ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetCurrentContext( int nGseCtx)
|
|
{
|
|
return SetCurrGseContext( nGseCtx) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeResetCurrentContext( void)
|
|
{
|
|
return ResetCurrGseContext() ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
ExeGetCurrentContext( void)
|
|
{
|
|
return GetIndCurrGseContext() ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetDefaultMaterial( Color ColDef)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, false)
|
|
// imposto il materiale di default
|
|
pGseCtx->m_colDef = ColDef ;
|
|
pGseCtx->m_pGeomDB->SetDefaultMaterial( pGseCtx->m_colDef) ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetGridFrame( const Frame3d& frFrame)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// imposto il riferimento della griglia
|
|
bool bOk = pGeomDB->SetGridFrame( frFrame) ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtSetGridFrame({{" + ToString( frFrame.Orig()) + "},{" +
|
|
ToString( frFrame.VersX()) + "},{" +
|
|
ToString( frFrame.VersY()) + "},{" +
|
|
ToString( frFrame.VersZ()) + "}})" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
return bOk ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetGridFrame( int nRefId, Frame3d& frFrame)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il riferimento della griglia
|
|
frFrame = pGeomDB->GetGridFrame() ;
|
|
// se richiesto nel riferimento globale, esco subito
|
|
if ( nRefId == GDB_ID_ROOT)
|
|
return true ;
|
|
// recupero il riferimento destinazione (nRefId può essere un gruppo o una entità)
|
|
Frame3d frDest ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nRefId, frDest) &&
|
|
! pGeomDB->GetGlobFrame( nRefId, frDest))
|
|
return false ;
|
|
// eseguo la trasformazione
|
|
return frFrame.ToLoc( frDest) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetGridVersZ( int nRefId, Vector3d& vtVersZ)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il versore Z della griglia
|
|
vtVersZ = pGeomDB->GetGridFrame().VersZ() ;
|
|
// se richiesto nel riferimento globale, esco subito
|
|
if ( nRefId == GDB_ID_ROOT)
|
|
return true ;
|
|
// recupero il riferimento destinazione (nRefId può essere un gruppo o una entità)
|
|
Frame3d frDest ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nRefId, frDest) &&
|
|
! pGeomDB->GetGlobFrame( nRefId, frDest))
|
|
return false ;
|
|
// eseguo la trasformazione
|
|
return vtVersZ.ToLoc( frDest) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetCurrFilePath( const string& sFilePath)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, false)
|
|
// assegno la path
|
|
pGseCtx->m_sFilePath = sFilePath ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetCurrFilePath( string& sFilePath)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, false)
|
|
// restituisco la path
|
|
sFilePath = pGseCtx->m_sFilePath ;
|
|
return ( ! sFilePath.empty()) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeEnableModified( void)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, false)
|
|
// abilito possibilità di alterare il flag di modifica
|
|
pGseCtx->m_bEnableModified = true ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeDisableModified( void)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, false)
|
|
// disabilito possibilità di alterare il flag di modifica
|
|
pGseCtx->m_bEnableModified = false ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetModified( void)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, false)
|
|
// se consentito, imposto il flag
|
|
if ( pGseCtx->m_bEnableModified)
|
|
pGseCtx->m_bModified = true ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeResetModified( void)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, false)
|
|
// se consentito, cancello il flag
|
|
if ( pGseCtx->m_bEnableModified)
|
|
pGseCtx->m_bModified = false ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetModified( void)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, false)
|
|
// imposto il flag
|
|
return pGseCtx->m_bModified ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeNewFile( void)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, false)
|
|
bool bOk = true ;
|
|
// reinizializzazione (con pulizia) del DB geometrico
|
|
bOk = bOk && pGseCtx->m_pGeomDB->Init() ;
|
|
bOk = bOk && pGseCtx->m_pGeomDB->SetDefaultMaterial( pGseCtx->m_colDef) ;
|
|
// aggiorno stato file corrente
|
|
pGseCtx->m_sFilePath.clear() ;
|
|
pGseCtx->m_bModified = false ;
|
|
// aggiornamento gestore lavorazioni
|
|
ExeUpdateMachMgr() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtNewFile()"
|
|
" -- Ok=" + ToString( bOk) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco il risultato
|
|
return bOk ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeOpenFile( const string& sFilePath)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, false)
|
|
bool bOk = true ;
|
|
// reinizializzazione (con pulizia) del DB geometrico
|
|
bOk = bOk && pGseCtx->m_pGeomDB->Init() ;
|
|
bOk = bOk && pGseCtx->m_pGeomDB->SetDefaultMaterial( pGseCtx->m_colDef) ;
|
|
// carico il file
|
|
bOk = bOk && pGseCtx->m_pGeomDB->Load( sFilePath) ;
|
|
// aggiorno stato file corrente
|
|
pGseCtx->m_sFilePath = sFilePath ;
|
|
pGseCtx->m_bModified = false ;
|
|
// aggiornamento gestore lavorazioni
|
|
ExeUpdateMachMgr() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLuaPath = sFilePath ;
|
|
ReplaceString( sLuaPath, "\\", "\\\\") ;
|
|
string sLua = "EgtOpenFile('" + sLuaPath + "')" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco il risultato
|
|
return bOk ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeInsertFile( const string& sFilePath)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, false)
|
|
IGeomDB* pGeomDB = pGseCtx->m_pGeomDB ;
|
|
// creo gruppo temporaneo di parcheggio
|
|
int nGrp = pGeomDB->InsertGroup( GDB_ID_NULL, GDB_ID_ROOT, GDB_FIRST_SON, GLOB_FRM) ;
|
|
bool bOk = ( nGrp != GDB_ID_NULL) ;
|
|
bOk = bOk && pGeomDB->SetLevel( nGrp, GDB_LV_TEMP) ;
|
|
// carico il file
|
|
bOk = bOk && pGeomDB->Load( sFilePath, nGrp) ;
|
|
// sposto i pezzi sotto la radice
|
|
int nId = pGeomDB->GetFirstGroupInGroup( nGrp) ;
|
|
while ( bOk && nId != GDB_ID_NULL) {
|
|
// prossimo gruppo
|
|
int nNextId = pGeomDB->GetNextGroup( nId) ;
|
|
// se il gruppo corrente è un pezzo, lo sposto
|
|
int nLevel ;
|
|
if ( ! pGeomDB->GetLevel( nId, nLevel) || nLevel == GDB_LV_USER)
|
|
bOk = pGeomDB->Relocate( nId, GDB_ID_ROOT, GDB_LAST_SON) ;
|
|
// passo al prossimo
|
|
nId = nNextId ;
|
|
}
|
|
// sistemo le lavorazioni
|
|
bOk = bOk && ExeInsertMachMgr( nGrp) ;
|
|
// cancello il gruppo temporaneo
|
|
pGeomDB->Erase( nGrp) ;
|
|
// aggiorno stato file corrente
|
|
pGseCtx->m_bModified = true ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLuaPath = sFilePath ;
|
|
ReplaceString( sLuaPath, "\\", "\\\\") ;
|
|
string sLua = "EgtInsertFile('" + sLuaPath + "')" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco il risultato
|
|
return bOk ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSaveFile( const string& sFilePath, int nFlag)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, false)
|
|
// se ero in CAM, esco
|
|
int nCurrMachGroup = ExeGetCurrMachGroup() ;
|
|
ExeResetCurrMachGroup() ;
|
|
// salvo il file
|
|
bool bOk = pGseCtx->m_pGeomDB->Save( GDB_ID_ROOT, sFilePath, nFlag) ;
|
|
// eventuale ripristino precedente CAM
|
|
if ( nCurrMachGroup != GDB_ID_NULL)
|
|
ExeSetCurrMachGroup( nCurrMachGroup) ;
|
|
// aggiorno stato file corrente
|
|
pGseCtx->m_sFilePath = sFilePath ;
|
|
if ( bOk)
|
|
pGseCtx->m_bModified = false ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLuaPath = sFilePath ;
|
|
ReplaceString( sLuaPath, "\\", "\\\\") ;
|
|
string sLua = "EgtSaveFile('" + sLuaPath + "'," +
|
|
NgeTypeToString( nFlag) + ")" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco il risultato
|
|
return bOk ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSaveObjToFile( int nId, const string& sFilePath, int nFlag)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se ero in CAM, esco
|
|
int nCurrMachGroup = ExeGetCurrMachGroup() ;
|
|
ExeResetCurrMachGroup() ;
|
|
// copio l'oggetto nel file
|
|
bool bOk = pGeomDB->Save( nId, sFilePath, nFlag) ;
|
|
// ripristino eventuale precedente CAM
|
|
if ( nCurrMachGroup != GDB_ID_NULL)
|
|
ExeSetCurrMachGroup( nCurrMachGroup) ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLuaPath = sFilePath ;
|
|
ReplaceString( sLuaPath, "\\", "\\\\") ;
|
|
string sLua = "EgtSaveObjToFile('" + sLuaPath + "'," +
|
|
ToString( nId) + "," +
|
|
NgeTypeToString( nFlag) + ")" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco il risultato
|
|
return bOk ;
|
|
}
|