Files
EgtExecutor/EXE_GdbObjects.cpp
T
Dario Sassi 2794f35805 EgtExecutor :
- aggiunte funzioni Exe e Lua CreateSurfTmTriangle e CreateSurfTmRectangle
- in Copy, CopyGlob, Relocate e RelocateGlob RefId ora accetta anche valori simbolici (layer corrente, ..).
2023-09-18 08:14:36 +02:00

613 lines
21 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2015
//----------------------------------------------------------------------------
// File : EXE_GdbObjects.cpp Data : 04.05.15 Versione : 1.6e1
// Contenuto : Funzioni iterazione di DB geometrico per EXE.
//
//
//
// Modifiche : 02.09.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "EXE.h"
#include "EXE_Macro.h"
#include "GeoTools.h"
#include "AuxTools.h"
#include "/EgtDev/Include/EXeExecutor.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EGkUiUnits.h"
#include "/EgtDev/Include/EgtStringConverter.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
using namespace std ;
//-----------------------------------------------------------------------------
bool
ExeExistsObj( int nId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// verifico se esiste l'oggetto
return pGeomDB->ExistsObj( nId) ;
}
//-----------------------------------------------------------------------------
int
ExeGetParent( int nId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// verifico se esiste l'oggetto
return pGeomDB->GetParentId( nId) ;
}
//-----------------------------------------------------------------------------
bool
ExeGetGlobFrame( int nId, Frame3d& frGlob)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il riferimento globale in cui è immerso l'oggetto
return pGeomDB->GetGlobFrame( nId, frGlob) ;
}
//-----------------------------------------------------------------------------
bool
ExeGetGroupGlobFrame( int nId, Frame3d& frGlob)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il riferimento globale del gruppo (in cui sono immersi i suoi oggetti figli)
return pGeomDB->GetGroupGlobFrame( nId, frGlob) ;
}
//-----------------------------------------------------------------------------
int
ExeGetGroupObjs( int nId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, 0)
// recupero il numero di oggetti nel gruppo
return pGeomDB->GetGroupObjs( nId) ;
}
//-----------------------------------------------------------------------------
bool
ExeGetAllInGroup( int nGroupId, INTVECTOR& vIds)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il numero di oggetti nel gruppo
if ( ! pGeomDB->ExistsObj( nGroupId))
return false ;
// preparo il riempimento del vettore
vIds.clear() ;
int nCount = pGeomDB->GetGroupObjs( nGroupId) ;
if ( nCount == 0)
return true ;
vIds.reserve( nCount) ;
// eseguo il riempimento
int nEntId = pGeomDB->GetFirstInGroup( nGroupId) ;
while ( nEntId != GDB_ID_NULL) {
vIds.emplace_back( nEntId) ;
nEntId = pGeomDB->GetNext( nEntId) ;
}
return true ;
}
//-----------------------------------------------------------------------------
int
ExeGetFirstInGroup( int nGroupId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero il primo oggetto nel gruppo
return pGeomDB->GetFirstInGroup( nGroupId) ;
}
//-----------------------------------------------------------------------------
int
ExeGetNext( int nId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero il prossimo oggetto nello stesso gruppo
return pGeomDB->GetNext( nId) ;
}
//-----------------------------------------------------------------------------
int
ExeGetLastInGroup( int nGroupId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero l'ultimo oggetto nel gruppo
return pGeomDB->GetLastInGroup( nGroupId) ;
}
//-----------------------------------------------------------------------------
int
ExeGetPrev( int nId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero il precedente oggetto nello stesso gruppo
return pGeomDB->GetPrev( nId) ;
}
//-----------------------------------------------------------------------------
int
ExeGetFirstGroupInGroup( int nGroupId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero il primo gruppo nel gruppo
return pGeomDB->GetFirstGroupInGroup( nGroupId) ;
}
//-----------------------------------------------------------------------------
int
ExeGetNextGroup( int nId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero il prossimo gruppo nello stesso gruppo
return pGeomDB->GetNextGroup( nId) ;
}
//-----------------------------------------------------------------------------
int
ExeGetLastGroupInGroup( int nGroupId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero l'ultimo gruppo nel gruppo
return pGeomDB->GetLastGroupInGroup( nGroupId) ;
}
//-----------------------------------------------------------------------------
int
ExeGetPrevGroup( int nId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero il precedente gruppo nello stesso gruppo
return pGeomDB->GetPrevGroup( nId) ;
}
//-----------------------------------------------------------------------------
int
ExeGetFirstNameInGroup( int nGroupId, const string& sName)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero il primo oggetto con il nome desiderato nel gruppo
return pGeomDB->GetFirstNameInGroup( nGroupId, sName) ;
}
//-----------------------------------------------------------------------------
int
ExeGetNextName( int nId, const string& sName)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero il prossimo oggetto nello stesso gruppo con il nome voluto
return pGeomDB->GetNextName( nId, sName) ;
}
//-----------------------------------------------------------------------------
int
ExeGetLastNameInGroup( int nGroupId, const string& sName)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero l'ultimo oggetto con il nome desiderato nel gruppo
return pGeomDB->GetLastNameInGroup( nGroupId, sName) ;
}
//-----------------------------------------------------------------------------
int
ExeGetPrevName( int nId, const string& sName)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero il precedente oggetto nello stesso gruppo con il nome voluto
return pGeomDB->GetPrevName( nId, sName) ;
}
//-----------------------------------------------------------------------------
bool
ExeGetBBox( int nId, int nFlag, BBox3d& b3Box)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il bounding box dell'oggetto in locale
return pGeomDB->GetLocalBBox( nId, b3Box, nFlag) ;
}
//-----------------------------------------------------------------------------
bool
ExeGetBBoxGlob( int nId, int nFlag, BBox3d& b3Box)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il bounding box dell'oggetto in globale
return pGeomDB->GetGlobalBBox( nId, b3Box, nFlag) ;
}
//-----------------------------------------------------------------------------
bool
ExeGetBBoxRef( int nId, int nFlag, const Frame3d& frRef, BBox3d& b3Box)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il bounding box dell'oggetto nel riferimento
return pGeomDB->GetRefBBox( nId, frRef, b3Box, nFlag) ;
}
//-----------------------------------------------------------------------------
int
ExeCopy( int nSouId, int nRefId, int nSonBeforeAfter)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nRefId = AdjustId( nRefId) ;
// eseguo la copia
int nNewId = pGeomDB->Copy( nSouId, GDB_ID_NULL, nRefId, nSonBeforeAfter) ;
pGeomDB->RemoveInfo( nNewId, GDB_SI_LIST) ;
pGeomDB->RemoveInfo( nNewId, GDB_SI_DUPLIST) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua ;
if ( nSonBeforeAfter == GDB_LAST_SON)
sLua = "EgtCopy(" + ToString( nSouId) + "," +
IdToString( nRefId) + ")" +
" -- Id=" + ToString( nNewId) ;
else
sLua = "EgtCopy(" + ToString( nSouId) + "," +
IdToString( nRefId) + "," +
InsToString( nSonBeforeAfter) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return nNewId ;
}
//-----------------------------------------------------------------------------
int
ExeCopyGlob( int nSouId, int nRefId, int nSonBeforeAfter)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nRefId = AdjustId( nRefId) ;
// eseguo la copia mantenendo la posizione in globale
int nNewId = pGeomDB->CopyGlob( nSouId, GDB_ID_NULL, nRefId, nSonBeforeAfter) ;
pGeomDB->RemoveInfo( nNewId, GDB_SI_LIST) ;
pGeomDB->RemoveInfo( nNewId, GDB_SI_DUPLIST) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua ;
if ( nSonBeforeAfter == GDB_LAST_SON)
sLua = "EgtCopyGlob(" + ToString( nSouId) + "," +
IdToString( nRefId) + ")" +
" -- Id=" + ToString( nNewId) ;
else
sLua = "EgtCopyGlob(" + ToString( nSouId) + "," +
IdToString( nRefId) + "," +
InsToString( nSonBeforeAfter) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return nNewId ;
}
//-----------------------------------------------------------------------------
bool
ExeRelocate( int nSouId, int nRefId, int nSonBeforeAfter)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
nRefId = AdjustId( nRefId) ;
// eseguo la rilocazione
bool bOk = pGeomDB->Relocate( nSouId, nRefId, nSonBeforeAfter) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua ;
if ( nSonBeforeAfter == GDB_LAST_SON)
sLua = "EgtRelocate(" + ToString( nSouId) + "," +
IdToString( nRefId) + ")" +
" -- Ok=" + ToString( bOk) ;
else
sLua = "EgtRelocate(" + ToString( nSouId) + "," +
IdToString( nRefId) + "," +
InsToString( nSonBeforeAfter) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return bOk ;
}
//-----------------------------------------------------------------------------
bool
ExeRelocateGlob( int nSouId, int nRefId, int nSonBeforeAfter)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
nRefId = AdjustId( nRefId) ;
// eseguo la rilocazione mantenendo la posizione in globale
bool bOk = pGeomDB->RelocateGlob( nSouId, nRefId, nSonBeforeAfter) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua ;
if ( nSonBeforeAfter == GDB_LAST_SON)
sLua = "EgtRelocateGlob(" + ToString( nSouId) + "," +
IdToString( nRefId) + ")" +
" -- Ok=" + ToString( bOk) ;
else
sLua = "EgtRelocateGlob(" + ToString( nSouId) + "," +
IdToString( nRefId) + "," +
InsToString( nSonBeforeAfter) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return bOk ;
}
//-----------------------------------------------------------------------------
bool
ExeGroupSwap( int nId1, int nId2, bool bSwapRef, bool bMark)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// eseguo swap
return pGeomDB->GroupSwap( nId1, nId2, bSwapRef, bMark) ;
}
//-----------------------------------------------------------------------------
int
ExeGetNewId( void)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// richiedo valore nuovo Id
return pGeomDB->GetNewId() ;
}
//-----------------------------------------------------------------------------
bool
ExeChangeId( int nId, int nNewId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// eseguo cambio di Id
bool bOk = pGeomDB->ChangeId( nId, nNewId) ;
// se pezzo corrente o layer corrente
if ( bOk) {
if ( nId == ExeGetCurrPart())
ExeSetCurrPartLayer( nNewId, ExeGetCurrLayer()) ;
else if ( nId == ExeGetCurrLayer())
ExeSetCurrPartLayer( ExeGetCurrPart(), nNewId) ;
}
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtChangeId(" + ToString( nId) + "," +
ToString( nNewId) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
return bOk ;
}
//-----------------------------------------------------------------------------
bool
ExeErase( const INTVECTOR& vIds)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// eseguo cancellazione
bool bOk = true ;
bool bErasedCurrPart = false ;
bool bErasedCurrLayer = false ;
int nCurrPartId = ExeGetCurrPart() ;
int nCurrLayerId = ExeGetCurrLayer() ;
for ( size_t i = 0 ; i < vIds.size() ; ++ i) {
int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ;
while ( nId != GDB_ID_NULL) {
// se pezzo con duplicati, cancello anche questi
if ( ExeIsPart( nId)) {
INTVECTOR vnRef ;
pGeomDB->GetInfo( nId, GDB_SI_DUPLIST, vnRef) ;
for ( int nDupId : vnRef)
pGeomDB->Erase( nDupId) ;
}
// se altrimenti duplicato di pezzo, lo tolgo da lista duplicati nell'originale
else if ( ExeIsDuplo( nId)) {
int nOrigId ;
pGeomDB->GetInfo( nId, GDB_SI_DUPSOU, nOrigId) ;
INTVECTOR vnRef ;
pGeomDB->GetInfo( nOrigId, GDB_SI_DUPLIST, vnRef) ;
vnRef.erase( remove( vnRef.begin(), vnRef.end(), nId), vnRef.end()) ;
pGeomDB->SetInfo( nOrigId, GDB_SI_DUPLIST, vnRef) ;
}
// cancello
if ( ! pGeomDB->Erase( nId))
bOk = false ;
// verifico se cancellato pezzo corrente o layer corrente
if ( nId == nCurrPartId)
bErasedCurrPart = true ;
else if ( nId == nCurrLayerId)
bErasedCurrLayer = true ;
// passo al successivo
nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetFirstSelectedObj()) ;
}
}
// se cancellato pezzo corrente o layer corrente
bool bPrevCmdLog = SetCmdLog( false) ;
if ( bErasedCurrPart)
ExeResetCurrPartLayer() ;
else if ( bErasedCurrLayer)
ExeSetCurrPartLayer( nCurrPartId, ExeGetFirstLayer( nCurrPartId, true)) ;
SetCmdLog( bPrevCmdLog) ;
// dichiaro progetto modificato
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtErase({" + IdListToString( vIds) + "})" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return bOk ;
}
//-----------------------------------------------------------------------------
bool
ExeEmptyGroup( int nId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// svuoto il gruppo
bool bOk = pGeomDB->EmptyGroup( nId) ;
// se cancellato pezzo corrente o layer corrente
bool bPrevCmdLog = SetCmdLog( false) ;
int nCurrPartId = ExeGetCurrPart() ;
int nCurrLayerId = ExeGetCurrLayer() ;
if ( ! pGeomDB->ExistsObj( nCurrPartId))
ExeResetCurrPartLayer() ;
else if ( ! pGeomDB->ExistsObj( nCurrLayerId))
ExeSetCurrPartLayer( nCurrPartId, ExeGetFirstLayer( nCurrPartId, true)) ;
SetCmdLog( bPrevCmdLog) ;
// dichiaro progetto modificato
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtEmptyGroup(" + ToString( nId) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return bOk ;
}
//-----------------------------------------------------------------------------
int
ExeGetType( int nId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_TY_NONE)
// recupero il tipo GDB
int nType = pGeomDB->GetGdbType( nId) ;
if ( nType == GDB_TY_GEO) {
// recupero il tipo Geo
const IGeoObj* pGeoObj = pGeomDB->GetGeoObj( nId) ;
if ( pGeoObj == nullptr)
return GDB_TY_NONE ;
else
return pGeoObj->GetType() ;
}
else if ( nType == GDB_TY_GROUP)
return GDB_TY_GROUP ;
else
return GDB_TY_NONE ;
}
//-----------------------------------------------------------------------------
bool
ExeGetTitle( int nId, string& sTitle)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero l'oggetto geometrico
const IGeoObj* pGeoObj = pGeomDB->GetGeoObj( nId) ;
if ( pGeoObj == nullptr)
return false ;
// recupero la stringa del titolo
sTitle = pGeoObj->GetTitle() ;
return true ;
}
//-----------------------------------------------------------------------------
bool
ExeGroupDump( int nId, string& sDump)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// flag per unità di misura di uscita
bool bMM = ExeUiUnitsAreMM() ;
// preparo l'intestazione
sDump = "Group " + ToString( nId) + "\r\n" ;
// preparo gli attributi
pGeomDB->DumpAttributes( nId, sDump, bMM, "\r\n") ;
// preparo TextureData
pGeomDB->DumpTextureData( nId, sDump, bMM, "\r\n") ;
// preparo UserObj
pGeomDB->DumpUserObj( nId, sDump, bMM, "\r\n") ;
// numero di nodi (figli)
int nNodes = pGeomDB->GetGroupObjs( nId) ;
sDump += "Nodes : " + ToString( nNodes) + "\r\n" ;
// riferimento in globale
Frame3d frGlob ;
if ( pGeomDB->GetGroupGlobFrame( nId, frGlob)) {
sDump += "GlobFrame :\r\n" ;
sDump += " O(" + ToString( GetInUiUnits( frGlob.Orig(), bMM)) + ")\r\n" ;
sDump += " X(" + ToString( frGlob.VersX()) + ")\r\n" ;
sDump += " Y(" + ToString( frGlob.VersY()) + ")\r\n" ;
sDump += " Z(" + ToString( frGlob.VersZ()) + ")\r\n" ;
}
// ingombro in globale
BBox3d b3Glob ;
if ( pGeomDB->GetGlobalBBox( nId, b3Glob, BBF_EXACT)) {
sDump += "GlobBBox :\r\n" ;
Point3d ptMin, ptMax ;
if ( b3Glob.GetMinMax( ptMin, ptMax)) {
sDump += " m(" + ToString( GetInUiUnits( ptMin, bMM)) + ")\r\n" ;
sDump += " M(" + ToString( GetInUiUnits( ptMax, bMM)) + ")\r\n" ;
}
else {
sDump += " Empty\r\n" ;
}
}
return true ;
}
//-----------------------------------------------------------------------------
bool
ExeGeoObjDump( int nId, string& sDump)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// flag per unità di misura di uscita
bool bMM = ExeUiUnitsAreMM() ;
// recupero l'oggetto geometrico
const IGeoObj* pGeoObj = pGeomDB->GetGeoObj( nId) ;
if ( pGeoObj == nullptr)
return false ;
// preparo l'intestazione
sDump = pGeoObj->GetTitle() + " " + ToString( nId) + "\r\n" ;
// preparo gli attributi
pGeomDB->DumpAttributes( nId, sDump, bMM, "\r\n") ;
// preparo stipple
pGeomDB->DumpStipple( nId, sDump, bMM, "\r\n") ;
// preparo TextureData
pGeomDB->DumpTextureData( nId, sDump, bMM, "\r\n") ;
// preparo UserObj
pGeomDB->DumpUserObj( nId, sDump, bMM, "\r\n") ;
// recupero i dati geometrici
if ( ! pGeoObj->Dump( sDump, bMM, "\r\n"))
return false ;
return true ;
}