4e5a81c493
- modifiche varie per gestire GLOB, LOC e GRID sui dati geometrici - aggiornamenti e miglirie varie - eliminate alcune funzioni lua ormai obsolete (ArcXY e CircleXY).
472 lines
16 KiB
C++
472 lines
16 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : API_GdbObjects.cpp Data : 02.09.14 Versione : 1.5i1
|
|
// Contenuto : Funzioni iterazione di DB geometrico per API.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 02.09.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "API.h"
|
|
#include "API_Macro.h"
|
|
#include "/EgtDev/Include/EInAPI.h"
|
|
#include "/EgtDev/Include/EGkStringUtils3d.h"
|
|
#include "/EgtDev/Include/EGnStringConverter.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
|
|
using namespace std ;
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtExistsObj( int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, FALSE)
|
|
// verifico se esiste l'oggetto
|
|
return ( pGeomDB->ExistsObj( nId) ? TRUE : FALSE) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetParent( int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// verifico se esiste l'oggetto
|
|
return pGeomDB->GetParentId( nId) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtGetGroupGlobFrame( int nId, double ptOrig[3], double vtX[3], double vtY[3], double vtZ[3])
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, FALSE)
|
|
// recupero il riferimento globale del gruppo
|
|
Frame3d frGlob ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nId, frGlob))
|
|
return FALSE ;
|
|
// aggiorno i parametri del frame
|
|
VEC_FROM_3D( ptOrig, frGlob.Orig())
|
|
VEC_FROM_3D( vtX, frGlob.VersX())
|
|
VEC_FROM_3D( vtY, frGlob.VersY())
|
|
VEC_FROM_3D( vtZ, frGlob.VersZ())
|
|
return TRUE ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetGroupObjs( int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il numero di oggetti nel gruppo
|
|
return pGeomDB->GetGroupObjs( nId) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetFirstInGroup( int nGroupId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il primo oggetto nel gruppo
|
|
return pGeomDB->GetFirstInGroup( nGroupId) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetNext( int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il prossimo oggetto nello stesso gruppo
|
|
return pGeomDB->GetNext( nId) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetLastInGroup( int nGroupId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero l'ultimo oggetto nel gruppo
|
|
return pGeomDB->GetLastInGroup( nGroupId) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetPrev( int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il precedente oggetto nello stesso gruppo
|
|
return pGeomDB->GetPrev( nId) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetFirstGroupInGroup( int nGroupId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il primo gruppo nel gruppo
|
|
return pGeomDB->GetFirstGroupInGroup( nGroupId) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetNextGroup( int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il prossimo gruppo nello stesso gruppo
|
|
return pGeomDB->GetNextGroup( nId) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetLastGroupInGroup( int nGroupId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero l'ultimo gruppo nel gruppo
|
|
return pGeomDB->GetLastGroupInGroup( nGroupId) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetPrevGroup( int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il precedente gruppo nello stesso gruppo
|
|
return pGeomDB->GetPrevGroup( nId) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetFirstNameInGroup( int nGroupId, const string& sName)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il primo oggetto nel gruppo
|
|
int nFirstId = pGeomDB->GetFirstInGroup( nGroupId) ;
|
|
string sObjName ;
|
|
if ( pGeomDB->GetName( nFirstId, sObjName) && sObjName == sName)
|
|
return nFirstId ;
|
|
return EgtGetNextName( nFirstId, sName) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetNextName( 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
|
|
int nNextId = nId ;
|
|
while ( ( nNextId = pGeomDB->GetNext( nNextId)) != GDB_ID_NULL) {
|
|
string sObjName ;
|
|
if ( pGeomDB->GetName( nNextId, sObjName) && sObjName == sName)
|
|
return nNextId ;
|
|
}
|
|
return GDB_ID_NULL ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtGetBBox( int nId, int nFlag, double ptMin[3], double ptMax[3])
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il bounding box locale dell'oggetto
|
|
BBox3d b3Loc ;
|
|
if ( ! pGeomDB->GetLocalBBox( nId, b3Loc, nFlag))
|
|
return FALSE ;
|
|
ptMin[0] = b3Loc.GetMin().x ;
|
|
ptMin[1] = b3Loc.GetMin().y ;
|
|
ptMin[2] = b3Loc.GetMin().z ;
|
|
ptMax[0] = b3Loc.GetMax().x ;
|
|
ptMax[1] = b3Loc.GetMax().y ;
|
|
ptMax[2] = b3Loc.GetMax().z ;
|
|
return TRUE ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtGetBBoxGlob( int nId, int nFlag, double ptMin[3], double ptMax[3])
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il bounding box globale dell'oggetto
|
|
BBox3d b3Loc ;
|
|
if ( ! pGeomDB->GetGlobalBBox( nId, b3Loc, nFlag))
|
|
return FALSE ;
|
|
ptMin[0] = b3Loc.GetMin().x ;
|
|
ptMin[1] = b3Loc.GetMin().y ;
|
|
ptMin[2] = b3Loc.GetMin().z ;
|
|
ptMax[0] = b3Loc.GetMax().x ;
|
|
ptMax[1] = b3Loc.GetMax().y ;
|
|
ptMax[2] = b3Loc.GetMax().z ;
|
|
return TRUE ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCopy( int nSouId, int nRefId, int nSonBeforeAfter)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// eseguo la copia
|
|
int nNewId = pGeomDB->Copy( nSouId, GDB_ID_NULL, nRefId, nSonBeforeAfter) ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua ;
|
|
if ( nSonBeforeAfter == GDB_SON)
|
|
sLua = "EgtCopy(" + ToString( nSouId) + "," +
|
|
ToString( nRefId) + ")" +
|
|
" -- Id=" + ToString( nNewId) ;
|
|
else
|
|
sLua = "EgtCopy(" + ToString( nSouId) + "," +
|
|
ToString( nRefId) + "," +
|
|
( nSonBeforeAfter == GDB_AFTER ? "'AFTER'" : "'BEFORE'") + ")" +
|
|
" -- Id=" + ToString( nNewId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco risultato
|
|
return nNewId ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCopyGlob( int nSouId, int nRefId, int nSonBeforeAfter)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// eseguo la copia mantenendo la posizione in globale
|
|
int nNewId = pGeomDB->CopyGlob( nSouId, GDB_ID_NULL, nRefId, nSonBeforeAfter) ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua ;
|
|
if ( nSonBeforeAfter == GDB_SON)
|
|
sLua = "EgtCopyGlob(" + ToString( nSouId) + "," +
|
|
ToString( nRefId) + ")" +
|
|
" -- Id=" + ToString( nNewId) ;
|
|
else
|
|
sLua = "EgtCopyGlob(" + ToString( nSouId) + "," +
|
|
ToString( nRefId) + "," +
|
|
( nSonBeforeAfter == GDB_AFTER ? "'AFTER'" : "'BEFORE'") + ")" +
|
|
" -- Id=" + ToString( nNewId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco risultato
|
|
return nNewId ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtRelocate( int nSouId, int nRefId, int nSonBeforeAfter)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// eseguo la rilocazione
|
|
bool bOk = pGeomDB->Relocate( nSouId, nRefId, nSonBeforeAfter) ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua ;
|
|
if ( nSonBeforeAfter == GDB_SON)
|
|
sLua = "EgtRelocate(" + ToString( nSouId) + "," +
|
|
ToString( nRefId) + ")" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
else
|
|
sLua = "EgtRelocate(" + ToString( nSouId) + "," +
|
|
ToString( nRefId) + "," +
|
|
( nSonBeforeAfter == GDB_AFTER ? "'AFTER'" : "'BEFORE'") + ")" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco risultato
|
|
return ( bOk ? TRUE : FALSE) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtRelocateGlob( int nSouId, int nRefId, int nSonBeforeAfter)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// eseguo la rilocazione mantenendo la posizione in globale
|
|
bool bOk = pGeomDB->RelocateGlob( nSouId, nRefId, nSonBeforeAfter) ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua ;
|
|
if ( nSonBeforeAfter == GDB_SON)
|
|
sLua = "EgtRelocateGlob(" + ToString( nSouId) + "," +
|
|
ToString( nRefId) + ")" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
else
|
|
sLua = "EgtRelocateGlob(" + ToString( nSouId) + "," +
|
|
ToString( nRefId) + "," +
|
|
( nSonBeforeAfter == GDB_AFTER ? "'AFTER'" : "'BEFORE'") + ")" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco risultato
|
|
return ( bOk ? TRUE : FALSE) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtChangeId( int nId, int nNewId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// eseguo cambio di Id
|
|
bool bOk = pGeomDB->ChangeId( nId, nNewId) ;
|
|
// 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 ? TRUE : FALSE) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtErase( int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
bool bOk = true ;
|
|
// eseguo cancellazione singola
|
|
if ( nId != GDB_ID_SEL) {
|
|
bOk = pGeomDB->Erase( nId) ;
|
|
}
|
|
// eseguo cancellazione dei selezionati
|
|
else {
|
|
int nI = pGeomDB->GetFirstSelectedObj() ;
|
|
while ( nI != GDB_ID_NULL && bOk) {
|
|
if ( ! pGeomDB->Erase( nI))
|
|
bOk = false ;
|
|
nI = pGeomDB->GetFirstSelectedObj() ;
|
|
}
|
|
}
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtErase(" + ( nId != GDB_ID_SEL ? ToString( nId) : "GDB_ID_SEL") + ")" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco risultato
|
|
return ( bOk ? TRUE : FALSE) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetType( 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
|
|
__stdcall EgtGetTitle( int nId, wchar_t*& wsTitle)
|
|
{
|
|
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
|
|
wsTitle = _wcsdup( stringtoW( pGeoObj->GetTitle())) ;
|
|
return (( wsTitle == nullptr) ? FALSE : TRUE) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtGroupDump( int nId, wchar_t*& wsDump)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, FALSE)
|
|
// preparo l'intestazione
|
|
string sDump = "Group " + ToString( nId) + "\r\n" ;
|
|
// preparo gli attributi
|
|
pGeomDB->DumpAttributes( nId, sDump, "\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( frGlob.Orig()) + ")\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( ptMin) + ")\r\n" ;
|
|
sDump += " M(" + ToString( ptMax) + ")\r\n" ;
|
|
}
|
|
else {
|
|
sDump += " Empty\r\n" ;
|
|
}
|
|
}
|
|
// alloco buffer di ritorno ed eseguo copia
|
|
wsDump = _wcsdup( stringtoW( sDump)) ;
|
|
return (( wsDump == nullptr) ? FALSE : TRUE) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtGeoObjDump( int nId, wchar_t*& wsDump)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, FALSE)
|
|
// recupero l'oggetto geometrico
|
|
const IGeoObj* pGeoObj = pGeomDB->GetGeoObj( nId) ;
|
|
if ( pGeoObj == nullptr)
|
|
return FALSE ;
|
|
// preparo l'intestazione
|
|
string sDump = pGeoObj->GetTitle() + " " + ToString( nId) + "\r\n" ;
|
|
// preparo gli attributi
|
|
pGeomDB->DumpAttributes( nId, sDump, "\r\n") ;
|
|
// recupero i dati geometrici
|
|
if ( ! pGeoObj->Dump( sDump, "\r\n"))
|
|
return FALSE ;
|
|
// alloco buffer di ritorno ed eseguo copia
|
|
wsDump = _wcsdup( stringtoW( sDump)) ;
|
|
return (( wsDump == nullptr) ? FALSE : TRUE) ;
|
|
}
|