bebcf1ecfe
- migliorie e modifiche in generale, specie su Lua.
203 lines
6.3 KiB
C++
203 lines
6.3 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : API_GeomDB.cpp Data : 01.09.14 Versione : 1.5i1
|
|
// Contenuto : Funzioni DB geometrico per API.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 01.09.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "API.h"
|
|
#include "API_Macro.h"
|
|
#include "/EgtDev/Include/EInAPI.h"
|
|
#include "/EgtDev/Include/EGnStringUtils.h"
|
|
#include "/EgtDev/Include/EGnStringConverter.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
|
|
using namespace std ;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtInitGeomDB( 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
|
|
__stdcall EgtSetCurrentContext( int nGseCtx)
|
|
{
|
|
return ( SetCurrGseContext( nGseCtx) ? TRUE : FALSE) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtResetCurrentContext( void)
|
|
{
|
|
return ( ResetCurrGseContext() ? TRUE : FALSE) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtGetCurrentContext( void)
|
|
{
|
|
return GetIndCurrGseContext() ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtSetDefaultMaterial( const int vCol[4])
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, FALSE)
|
|
// imposto il materiale di default
|
|
pGseCtx->m_colDef.Set( vCol) ;
|
|
pGseCtx->m_pGeomDB->SetDefaultMaterial( pGseCtx->m_colDef) ;
|
|
return TRUE ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtSetGridFrame( const double ptOrig[3], const double vX[3], const double vY[3], const double vZ[3])
|
|
{
|
|
// costruisco il riferimento
|
|
Frame3d frFrame ;
|
|
if ( ! frFrame.Set( ptOrig, vX, vY, vZ))
|
|
return FALSE ;
|
|
// imposto il riferimento della griglia
|
|
return ( EgtSetGridFrame( frFrame) ? TRUE : FALSE) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
__stdcall EgtSetGridFrame( const Frame3d& frFrame)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// imposto il riferimento della griglia
|
|
return pGeomDB->SetGridFrame( frFrame) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtGetGridFrame( double ptOrig[3], double vX[3], double vY[3], double vZ[3])
|
|
{
|
|
// recupero il riferimento della griglia
|
|
Frame3d frGrid ;
|
|
if ( EgtGetGridFrame( frGrid)) {
|
|
// assegno i valori di ritorno
|
|
VEC_FROM_3D( ptOrig, frGrid.Orig())
|
|
VEC_FROM_3D( vX, frGrid.VersX())
|
|
VEC_FROM_3D( vY, frGrid.VersY())
|
|
VEC_FROM_3D( vZ, frGrid.VersZ())
|
|
return TRUE ;
|
|
}
|
|
else
|
|
return FALSE ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
__stdcall EgtGetGridFrame( Frame3d& frFrame)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il riferimento della griglia
|
|
frFrame = pGeomDB->GetGridFrame() ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
__stdcall EgtGetGridVersZ( 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
|
|
__stdcall EgtNewFile( void)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_GEOMDB( pGseCtx, FALSE)
|
|
// reinizializzazione (con pulizia) del DB geometrico
|
|
pGseCtx->m_pGeomDB->Init() ;
|
|
pGseCtx->m_pGeomDB->SetDefaultMaterial( pGseCtx->m_colDef) ;
|
|
return TRUE ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtOpenFile( const wchar_t* wsFilePath)
|
|
{
|
|
return ( EgtOpenFile( wstrztoA( wsFilePath)) ? TRUE : FALSE) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
__stdcall EgtOpenFile( const string& sFilePath)
|
|
{
|
|
// reinizializzazione (con pulizia) del DB geometrico
|
|
if ( ! EgtNewFile())
|
|
return false ;
|
|
// carico il file
|
|
return GetCurrGeomDB()->Load( sFilePath) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtSaveFile( const wchar_t* wsFilePath, int nFlag)
|
|
{
|
|
return ( EgtSaveFile( wstrztoA( wsFilePath), nFlag) ? TRUE : FALSE) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
__stdcall EgtSaveFile( const string& sFilePath, int nFlag)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// salvo il file
|
|
return pGeomDB->Save( sFilePath, nFlag) ;
|
|
}
|