diff --git a/AuxTools.cpp b/AuxTools.cpp new file mode 100644 index 0000000..7220c8d --- /dev/null +++ b/AuxTools.cpp @@ -0,0 +1,141 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : AuxTools.cpp Data : 07.01.15 Versione : 1.6a1 +// Contenuto : Funzioni ausiliarie. +// +// +// +// Modifiche : 07.01.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#include "stdafx.h" +#include "AuxTools.h" +#include "/EgtDev/Include/EGkExtText.h" +#include "/EgtDev/Include/EMkMachMgr.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGnStringUtils.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +const string +IdListToString( const INTVECTOR& vIds) +{ + string sIds ; + sIds.reserve( 6 * vIds.size()) ; + for ( size_t i = 0 ; i < vIds.size() ; ++ i) + sIds += ( vIds[i] != GDB_ID_SEL ? ToString( vIds[i]) : "GDB_ID.SEL") + "," ; + if ( ! sIds.empty()) + sIds.pop_back() ; + return sIds ; +} + +//---------------------------------------------------------------------------- +const char* +NgeTypeToString( int nNgeType) +{ + switch ( nNgeType) { + case GDB_SV_TXT : return "GDB_NT.TXT" ; + case GDB_SV_BIN : return "GDB_NT.BIN" ; + default : + case GDB_SV_CMPTXT : return "GDB_NT.CMPTXT" ; + } +} + +//---------------------------------------------------------------------------- +const char* +SepToString( int nSep) +{ + switch ( nSep) { + default : + case SEP_STD : return "GDB_PT.STD" ; + case SEP_TG : return "GDB_PT.TG" ; + case SEP_PERP : return "GDB_PT.PERP" ; + case SEP_MINDIST : return "GDB_PT.MIND" ; + } +} + +//---------------------------------------------------------------------------- +const char* +InsToString( int nIns) +{ + switch ( nIns) { + case GDB_FIRST_SON : return "GDB_IN.FIRST_SON" ; + default : + case GDB_LAST_SON : return "GDB_IN.LAST_SON" ; + case GDB_BEFORE : return "GDB_IN.BEFORE" ; + case GDB_AFTER : return "GDB_IN.AFTER" ; + } +} + +//---------------------------------------------------------------------------- +const char* +RefTypeToString( int nRefType) +{ + switch ( nRefType) { + case RTY_GLOB : return "GDB_RT.GLOB" ; + default : + case RTY_LOC : return "GDB_RT.LOC" ; + case RTY_GRID : return "GDB_RT.GRID" ; + } +} + +//---------------------------------------------------------------------------- +const char* +ETxtInsPosToString( int nETxtInsPos) +{ + switch ( nETxtInsPos) { + case ETXT_IPTL : return "GDB_TI.TL" ; + case ETXT_IPTC : return "GDB_TI.TC" ; + case ETXT_IPTR : return "GDB_TI.TR" ; + case ETXT_IPML : return "GDB_TI.ML" ; + case ETXT_IPMC : return "GDB_TI.MC" ; + case ETXT_IPMR : return "GDB_TI.MR" ; + default : + case ETXT_IPBL : return "GDB_TI.BL" ; + case ETXT_IPBC : return "GDB_TI.BC" ; + case ETXT_IPBR : return "GDB_TI.BR" ; + } +} + +//---------------------------------------------------------------------------- +const char* +OffsTypeToString( int nOffsType) +{ + switch ( nOffsType) { + default : + case ICurve::OFF_FILLET : return "GDB_OT.FILLET" ; + case ICurve::OFF_CHAMFER : return "GDB_OT.CHAMFER" ; + case ICurve::OFF_EXTEND : return "GDB_OT.EXTEND" ; + } +} + +//---------------------------------------------------------------------------- +const char* +RawPartCornerPosToString( int nFlag) +{ + switch ( nFlag) { + case RPCR_TL : return "MCH_CR.TL" ; + case RPCR_TR : return "MCH_CR.TR" ; + default : + case RPCR_BL : return "MCH_CR.BL" ; + case RPCR_BR : return "MCH_CR.BR" ; + } +} + +//---------------------------------------------------------------------------- +const char* +RawPartCenterPosToString( int nFlag) +{ + switch ( nFlag) { + case RPCE_TC : return "MCH_CE.TC" ; + default : + case RPCE_ML : return "MCH_CE.ML" ; + case RPCE_MR : return "MCH_CE.MR" ; + case RPCE_BC : return "MCH_CE.BC" ; + case RPCE_MC : return "MCH_CE.MC" ; + } +} diff --git a/AuxTools.h b/AuxTools.h new file mode 100644 index 0000000..762f3d0 --- /dev/null +++ b/AuxTools.h @@ -0,0 +1,37 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : AuxTools.h Data : 07.01.15 Versione : 1.6a1 +// Contenuto : Prototipi funzioni ausiliarie. +// +// +// +// Modifiche : 07.01.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#include "/EgtDev/Include/EgtNumCollection.h" +#include + +class IGeomDB ; + +//---------------------------------------------------------------------------- +// Lista di Id completa (parametro per lua) +const std::string IdListToString( const INTVECTOR& vIds) ; +// Tipo del file Nge +const char* NgeTypeToString( int nNgeType) ; +// Tipo punto per creazione rette e archi +const char* SepToString( int nSep) ; +// Flag per posizione di inserimento nel DB geometrico +const char* InsToString( int nIns) ; +// Tipo riferimento in cui sono espressi i dati geometrici +const char* RefTypeToString( int nRefType) ; +// Posizione inserimento testo +const char* ETxtInsPosToString( int nETxtInsPos) ; +// tipo di offset di curva +const char* OffsTypeToString( int nOffsType) ; +// Flag per posizione corner rispetto a grezzo +const char* RawPartCornerPosToString( int nFlag) ; +// Flag per posizione center rispetto a grezzo +const char* RawPartCenterPosToString( int nFlag) ; diff --git a/DllExchange.cpp b/DllExchange.cpp new file mode 100644 index 0000000..f191239 --- /dev/null +++ b/DllExchange.cpp @@ -0,0 +1,213 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : DllExchange.cpp Data : 27.03.15 Versione : 1.6c9 +// Contenuto : Funzioni di gestione della libreria opzionale EgtExchange. +// +// +// +// Modifiche : 27.03.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "DllExchange.h" +#define NOMINMAX +#include + +using namespace std ; + +//----------------------------------------------------------------------------- +// Nome della libreria +#if defined( _WIN64) && defined( _DEBUG) + static const wchar_t* EEX_NAME = L"EgtExchangeD64.dll" ; +#elif defined( _WIN64) + static const wchar_t* EEX_NAME = L"EgtExchangeR64.dll" ; +#elif defined( _WIN32) && defined( _DEBUG) + static const wchar_t* EEX_NAME = L"EgtExchangeD32.dll" ; +#else + static const wchar_t* EEX_NAME = L"EgtExchangeR32.dll" ; +#endif +// Nome delle funzioni caricate +static const char* EEX_SETEEXLOGGER = "SetEExLogger" ; +static const char* EEX_GETEEXVERSION = "GetEExVersion" ; +static const char* EEX_SETEEXKEY = "SetEExKey" ; +static const char* EEX_CREATEIMPORTCNC = "CreateImportCnc" ; +static const char* EEX_CREATEIMPORTDXF = "CreateImportDxf" ; +static const char* EEX_CREATEIMPORTSTL = "CreateImportStl" ; +static const char* EEX_CREATEEXPORTDXF = "CreateExportDxf" ; +static const char* EEX_CREATEEXPORTSTL = "CreateExportStl" ; +static const char* EEX_CREATEEEXEXECUTOR = "CreateExcExecutor" ; + + +//----------------------------------------------------------------------------- +HMODULE s_hEEx = nullptr ; + +//----------------------------------------------------------------------------- +bool +LoadExchangeDll( void) +{ + // se già caricata + if ( s_hEEx != nullptr) + return true ; + // carico la libreria EgtExchange + s_hEEx = LoadLibrary( EEX_NAME) ; + return ( s_hEEx != nullptr) ; +} + +//----------------------------------------------------------------------------- +bool +FreeExchangeDll( void) +{ + // se non è già caricata + if ( s_hEEx == nullptr) + return true ; + // libero la libreria EgtExchange + FreeLibrary( s_hEEx) ; + s_hEEx = nullptr ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +IsLoadedExchangeDll( void) +{ + return ( s_hEEx != nullptr) ; +} + +//----------------------------------------------------------------------------- +void +MySetEExLogger( ILogger* pLogger) +{ + // verifico caricamento libreria EgtExchange + if ( s_hEEx == nullptr) + return ; + // recupero funzione che imposta il logger + typedef void (* PF_SetEExLogger) ( ILogger* pLogger) ; + PF_SetEExLogger pFun = (PF_SetEExLogger)GetProcAddress( s_hEEx, EEX_SETEEXLOGGER) ; + if ( pFun == nullptr) + return ; + pFun( pLogger) ; +} + +//----------------------------------------------------------------------------- +const char* +MyGetEExVersion( void) +{ + // verifico caricamento libreria EgtExchange + if ( s_hEEx == nullptr) + return "" ; + // recupero funzione che restituisce la versione della libreria + typedef const char* (* PF_GetEExVersion) ( void) ; + PF_GetEExVersion pFun = (PF_GetEExVersion)GetProcAddress( s_hEEx, EEX_GETEEXVERSION) ; + if ( pFun == nullptr) + return "" ; + return pFun() ; +} + +//----------------------------------------------------------------------------- +void +MySetEExKey( const string& sKey) +{ + // verifico caricamento libreria EgtExchange + if ( s_hEEx == nullptr) + return ; + // recupero funzione che imposta i codici di protezione + typedef void (* PF_SetEExKey) ( const string& sKey) ; + PF_SetEExKey pFun = (PF_SetEExKey)GetProcAddress( s_hEEx, EEX_SETEEXKEY) ; + if ( pFun == nullptr) + return ; + pFun( sKey) ; +} + +//----------------------------------------------------------------------------- +IImportCnc* +MyCreateImportCnc( void) +{ + // verifico caricamento libreria EgtExchange + if ( s_hEEx == nullptr) + return nullptr ; + // recupero funzione creazione oggetto + typedef IImportCnc* (* PF_CreateImportCnc) ( void) ; + PF_CreateImportCnc pFun = (PF_CreateImportCnc)GetProcAddress( s_hEEx, EEX_CREATEIMPORTCNC) ; + if ( pFun == nullptr) + return nullptr ; + return pFun() ; +} + +//----------------------------------------------------------------------------- +IImportDxf* +MyCreateImportDxf( void) +{ + // verifico caricamento libreria EgtExchange + if ( s_hEEx == nullptr) + return nullptr ; + // recupero funzione creazione oggetto + typedef IImportDxf* (* PF_CreateImportDxf) ( void) ; + PF_CreateImportDxf pFun = (PF_CreateImportDxf)GetProcAddress( s_hEEx, EEX_CREATEIMPORTDXF) ; + if ( pFun == nullptr) + return nullptr ; + return pFun() ; +} + +//----------------------------------------------------------------------------- +IImportStl* +MyCreateImportStl( void) +{ + // verifico caricamento libreria EgtExchange + if ( s_hEEx == nullptr) + return nullptr ; + // recupero funzione creazione oggetto + typedef IImportStl* (* PF_CreateImportStl) ( void) ; + PF_CreateImportStl pFun = (PF_CreateImportStl)GetProcAddress( s_hEEx, EEX_CREATEIMPORTSTL) ; + if ( pFun == nullptr) + return nullptr ; + return pFun() ; +} + +//----------------------------------------------------------------------------- +IExportDxf* +MyCreateExportDxf( void) +{ + // verifico caricamento libreria EgtExchange + if ( s_hEEx == nullptr) + return nullptr ; + // recupero funzione creazione oggetto + typedef IExportDxf* (* PF_CreateExportDxf) ( void) ; + PF_CreateExportDxf pFun = (PF_CreateExportDxf)GetProcAddress( s_hEEx, EEX_CREATEEXPORTDXF) ; + if ( pFun == nullptr) + return nullptr ; + return pFun() ; +} + +//----------------------------------------------------------------------------- +IExportStl* +MyCreateExportStl( void) +{ + // verifico caricamento libreria EgtExchange + if ( s_hEEx == nullptr) + return nullptr ; + // recupero funzione creazione oggetto + typedef IExportStl* (* PF_CreateExportStl) ( void) ; + PF_CreateExportStl pFun = (PF_CreateExportStl)GetProcAddress( s_hEEx, EEX_CREATEEXPORTSTL) ; + if ( pFun == nullptr) + return nullptr ; + return pFun() ; +} + +//----------------------------------------------------------------------------- +IExcExecutor* +MyCreateExcExecutor( void) +{ + // verifico caricamento libreria EgtExchange + if ( s_hEEx == nullptr) + return nullptr ; + // recupero funzione creazione oggetto + typedef IExcExecutor* (* PF_CreateExcExecutor) ( void) ; + PF_CreateExcExecutor pFun = (PF_CreateExcExecutor)GetProcAddress( s_hEEx, EEX_CREATEEEXEXECUTOR) ; + if ( pFun == nullptr) + return nullptr ; + return pFun() ; +} diff --git a/DllExchange.h b/DllExchange.h new file mode 100644 index 0000000..130f20f --- /dev/null +++ b/DllExchange.h @@ -0,0 +1,38 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : DllGraphics.h Data : 27.03.15 Versione : 1.6c9 +// Contenuto : Dichiarazioni funzioni per libreria opzionale EgtGraphics. +// +// +// +// Modifiche : 27.03.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include + +class ILogger ; +class IImportCnc ; +class IImportDxf ; +class IImportStl ; +class IExportDxf ; +class IExportStl ; +class IExcExecutor ; + +//---------------------------------------------------------------------------- +bool LoadExchangeDll( void) ; +bool FreeExchangeDll( void) ; +bool IsLoadedExchangeDll( void) ; +void MySetEExLogger( ILogger* pLogger) ; +void MySetEExKey( const std::string& sKey) ; +const char* MyGetEExVersion( void) ; +IImportCnc* MyCreateImportCnc( void) ; +IImportDxf* MyCreateImportDxf( void) ; +IImportStl* MyCreateImportStl( void) ; +IExportDxf* MyCreateExportDxf( void) ; +IExportStl* MyCreateExportStl( void) ; +IExcExecutor* MyCreateExcExecutor(void) ; diff --git a/DllGraphics.cpp b/DllGraphics.cpp new file mode 100644 index 0000000..9573156 --- /dev/null +++ b/DllGraphics.cpp @@ -0,0 +1,149 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : DllGraphics.cpp Data : 27.03.15 Versione : 1.6c9 +// Contenuto : Funzioni di gestione della libreria opzionale EgtGraphics. +// +// +// +// Modifiche : 27.03.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "DllGraphics.h" +#define NOMINMAX +#include + +using namespace std ; + +//----------------------------------------------------------------------------- +// Nome della libreria +#if defined( _WIN64) && defined( _DEBUG) + static const wchar_t* EGR_NAME = L"EgtGraphicsD64.dll" ; +#elif defined( _WIN64) + static const wchar_t* EGR_NAME = L"EgtGraphicsR64.dll" ; +#elif defined( _WIN32) && defined( _DEBUG) + static const wchar_t* EGR_NAME = L"EgtGraphicsD32.dll" ; +#else + static const wchar_t* EGR_NAME = L"EgtGraphicsR32.dll" ; +#endif +// Nome delle funzioni caricate +static const char* EGR_SETEGRLOGGER = "SetEGrLogger" ; +static const char* EGR_GETEGRVERSION = "GetEGrVersion" ; +static const char* EGR_SETEGRKEY = "SetEGrKey" ; +static const char* EGR_CREATEEGRSCENE = "CreateEGrScene" ; +static const char* EGR_CREATESCEEXECUTOR = "CreateSceExecutor" ; + + +//----------------------------------------------------------------------------- +HMODULE s_hEGr = nullptr ; + +//----------------------------------------------------------------------------- +bool +LoadGraphicsDll( void) +{ + // se già caricata + if ( s_hEGr != nullptr) + return true ; + // carico la libreria EgtGraphics + s_hEGr = LoadLibrary( EGR_NAME) ; + return ( s_hEGr != nullptr) ; +} + +//----------------------------------------------------------------------------- +bool +FreeGraphicsDll( void) +{ + // se non è già caricata + if ( s_hEGr == nullptr) + return true ; + // libero la libreria EgtGraphics + FreeLibrary( s_hEGr) ; + s_hEGr = nullptr ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +IsLoadedGraphicsDll( void) +{ + return ( s_hEGr != nullptr) ; +} + +//----------------------------------------------------------------------------- +void +MySetEGrLogger( ILogger* pLogger) +{ + // verifico caricamento libreria MachMgr + if ( s_hEGr == nullptr) + return ; + // recupero funzione che imposta il logger + typedef void (* PF_SetEMkLogger) ( ILogger* pLogger) ; + PF_SetEMkLogger pFun = (PF_SetEMkLogger)GetProcAddress( s_hEGr, EGR_SETEGRLOGGER) ; + if ( pFun == nullptr) + return ; + pFun( pLogger) ; +} + +//----------------------------------------------------------------------------- +const char* +MyGetEGrVersion( void) +{ + // verifico caricamento libreria MachMgr + if ( s_hEGr == nullptr) + return "" ; + // recupero funzione che restituisce la versione della libreria + typedef const char* (* PF_GetEGrVersion) ( void) ; + PF_GetEGrVersion pFun = (PF_GetEGrVersion)GetProcAddress( s_hEGr, EGR_GETEGRVERSION) ; + if ( pFun == nullptr) + return "" ; + return pFun() ; +} + +//----------------------------------------------------------------------------- +void +MySetEGrKey( const string& sKey) +{ + // verifico caricamento libreria MachMgr + if ( s_hEGr == nullptr) + return ; + // recupero funzione che imposta i codici di protezione + typedef void (* PF_SetEGrKey) ( const string& sKey) ; + PF_SetEGrKey pFun = (PF_SetEGrKey)GetProcAddress( s_hEGr, EGR_SETEGRKEY) ; + if ( pFun == nullptr) + return ; + pFun( sKey) ; +} + +//----------------------------------------------------------------------------- +IEGrScene* +MyCreateEGrScene( void) +{ + // verifico caricamento libreria MachMgr + if ( s_hEGr == nullptr) + return nullptr ; + // recupero funzione creazione oggetto + typedef IEGrScene* (* PF_CreateEGrScene) ( void) ; + PF_CreateEGrScene pFun = (PF_CreateEGrScene)GetProcAddress( s_hEGr, EGR_CREATEEGRSCENE) ; + if ( pFun == nullptr) + return nullptr ; + return pFun() ; +} + +//----------------------------------------------------------------------------- +ISceExecutor* +MyCreateSceExecutor( void) +{ + // verifico caricamento libreria MachMgr + if ( s_hEGr == nullptr) + return nullptr ; + // recupero funzione creazione oggetto + typedef ISceExecutor* (* PF_CreateSceExecutor) ( void) ; + PF_CreateSceExecutor pFun = (PF_CreateSceExecutor)GetProcAddress( s_hEGr, EGR_CREATESCEEXECUTOR) ; + if ( pFun == nullptr) + return nullptr ; + return pFun() ; +} diff --git a/DllGraphics.h b/DllGraphics.h new file mode 100644 index 0000000..237950e --- /dev/null +++ b/DllGraphics.h @@ -0,0 +1,30 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : DllGraphics.h Data : 27.03.15 Versione : 1.6c9 +// Contenuto : Dichiarazioni funzioni per libreria opzionale EgtGraphics. +// +// +// +// Modifiche : 27.03.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include + +class ILogger ; +class IEGrScene ; +class ISceExecutor ; + +//---------------------------------------------------------------------------- +bool LoadGraphicsDll( void) ; +bool FreeGraphicsDll( void) ; +bool IsLoadedGraphicsDll( void) ; +void MySetEGrLogger( ILogger* pLogger) ; +void MySetEGrKey( const std::string& sKey) ; +const char* MyGetEGrVersion( void) ; +IEGrScene* MyCreateEGrScene( void) ; +ISceExecutor* MyCreateSceExecutor(void) ; diff --git a/DllMachKernel.cpp b/DllMachKernel.cpp new file mode 100644 index 0000000..fd14329 --- /dev/null +++ b/DllMachKernel.cpp @@ -0,0 +1,133 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : DllMachKernel.cpp Data : 27.03.15 Versione : 1.6c9 +// Contenuto : Funzioni di gestione della libreria opzionale EgtMachKernel. +// +// +// +// Modifiche : 27.03.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "DllMachKernel.h" +#define NOMINMAX +#include + +using namespace std ; + +//----------------------------------------------------------------------------- +// Nome della libreria +#if defined( _WIN64) && defined( _DEBUG) + static const wchar_t* EMK_NAME = L"EgtMachKernelD64.dll" ; +#elif defined( _WIN64) + static const wchar_t* EMK_NAME = L"EgtMachKernelR64.dll" ; +#elif defined( _WIN32) && defined( _DEBUG) + static const wchar_t* EMK_NAME = L"EgtMachKernelD32.dll" ; +#else + static const wchar_t* EMK_NAME = L"EgtMachKernelR32.dll" ; +#endif +// Nome delle funzioni caricate +static const char* EMK_SETEMKLOGGER = "SetEMkLogger" ; +static const char* EMK_GETEMKVERSION = "GetEMkVersion" ; +static const char* EMK_SETEMKKEY = "SetEMkKey" ; +static const char* EMK_CREATEMACHMGR = "CreateMachMgr" ; + + +//----------------------------------------------------------------------------- +HMODULE s_hEMk = nullptr ; + +//----------------------------------------------------------------------------- +bool +LoadMachKernelDll( void) +{ + // se già caricata + if ( s_hEMk != nullptr) + return true ; + // carico la libreria EgtMachKernel + s_hEMk = LoadLibrary( EMK_NAME) ; + return ( s_hEMk != nullptr) ; +} + +//----------------------------------------------------------------------------- +bool +FreeMachKernelDll( void) +{ + // se non è già caricata + if ( s_hEMk == nullptr) + return true ; + // libero la libreria EgtMachKernel + FreeLibrary( s_hEMk) ; + s_hEMk = nullptr ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +IsLoadedMachKernelDll( void) +{ + return ( s_hEMk != nullptr) ; +} + +//----------------------------------------------------------------------------- +void +MySetEMkLogger( ILogger* pLogger) +{ + // verifico caricamento libreria MachMgr + if ( s_hEMk == nullptr) + return ; + // recupero funzione che imposta il logger + typedef void (* PF_SetEMkLogger) ( ILogger* pLogger) ; + PF_SetEMkLogger pFun = (PF_SetEMkLogger)GetProcAddress( s_hEMk, EMK_SETEMKLOGGER) ; + if ( pFun == nullptr) + return ; + pFun( pLogger) ; +} + +//----------------------------------------------------------------------------- +const char* +MyGetEMkVersion( void) +{ + // verifico caricamento libreria MachMgr + if ( s_hEMk == nullptr) + return "" ; + // recupero funzione che restituisce la versione della libreria + typedef const char* (* PF_GetEMkVersion) ( void) ; + PF_GetEMkVersion pFun = (PF_GetEMkVersion)GetProcAddress( s_hEMk, EMK_GETEMKVERSION) ; + if ( pFun == nullptr) + return "" ; + return pFun() ; +} + +//----------------------------------------------------------------------------- +void +MySetEMkKey( const string& sKey) +{ + // verifico caricamento libreria MachMgr + if ( s_hEMk == nullptr) + return ; + // recupero funzione che imposta i codici di protezione + typedef void (* PF_SetEMkKey) ( const string& sKey) ; + PF_SetEMkKey pFun = (PF_SetEMkKey)GetProcAddress( s_hEMk, EMK_SETEMKKEY) ; + if ( pFun == nullptr) + return ; + pFun( sKey) ; +} + +//----------------------------------------------------------------------------- +IMachMgr* +MyCreateMachMgr( void) +{ + // verifico caricamento libreria MachMgr + if ( s_hEMk == nullptr) + return nullptr ; + // recupero funzione creazione oggetto + typedef IMachMgr* (* PF_CreateMachMgr) ( void) ; + PF_CreateMachMgr pFun = (PF_CreateMachMgr)GetProcAddress( s_hEMk, EMK_CREATEMACHMGR) ; + if ( pFun == nullptr) + return nullptr ; + return pFun() ; +} diff --git a/DllMachKernel.h b/DllMachKernel.h new file mode 100644 index 0000000..babe4ac --- /dev/null +++ b/DllMachKernel.h @@ -0,0 +1,28 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : DllMachKernel.h Data : 27.03.15 Versione : 1.6c9 +// Contenuto : Dichiarazioni funzioni per libreria opzionale EgtMachKernel. +// +// +// +// Modifiche : 27.03.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include + +class ILogger ; +class IMachMgr ; + +//---------------------------------------------------------------------------- +bool LoadMachKernelDll( void) ; +bool FreeMachKernelDll( void) ; +bool IsLoadedMachKernelDll( void) ; +void MySetEMkLogger( ILogger* pLogger) ; +void MySetEMkKey( const std::string& sKey) ; +const char* MyGetEMkVersion( void) ; +IMachMgr* MyCreateMachMgr( void) ; diff --git a/EXE.h b/EXE.h new file mode 100644 index 0000000..895ba44 --- /dev/null +++ b/EXE.h @@ -0,0 +1,23 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : EXE.h Data : 05.05.15 Versione : 1.6e2 +// Contenuto : Dichiarazioni locali per moduli EXE. +// +// +// +// Modifiche : 01.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "GseContext.h" +#include "/EgtDev/Include/EgtILogger.h" + +//---------------------------------------------------------------------------- +ILogger* GetLogger( void) ; +ILogger* GetCmdLogger( void) ; +bool SetCmdLog( bool bVal) ; +bool IsCmdLog( void) ; diff --git a/EXE_Exchange.cpp b/EXE_Exchange.cpp new file mode 100644 index 0000000..37b17f1 --- /dev/null +++ b/EXE_Exchange.cpp @@ -0,0 +1,209 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : EXE_Exchange.cpp Data : 20.09.14 Versione : 1.6e1 +// Contenuto : Funzioni import/export per EXE. +// +// +// +// Modifiche : 20.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "DllExchange.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EExImportStl.h" +#include "/EgtDev/Include/EExImportDxf.h" +#include "/EgtDev/Include/EExImportCnc.h" +#include "/EgtDev/Include/EExExportStl.h" +#include "/EgtDev/Include/EExExportDxf.h" +#include "/EgtDev/Include/EGnStringUtils.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//----------------------------------------------------------------------------- +int +ExeGetFileType( const string& sFilePath) +{ + // divido in nome e direttorio + string sFileDir, sFileName ; + SplitLast( sFilePath, "\\", sFileDir, sFileName) ; + + // recupero l'estensione + string sFileTitle, sFileExt ; + SplitLast( sFileName, ".", sFileTitle, sFileExt) ; + ToUpper( sFileExt) ; + + if ( sFileExt == "NGE") + return 1 ; + else if ( sFileExt == "NFE") + return 2 ; + else if ( sFileExt == "DXF") + return 11 ; + else if ( sFileExt == "STL") + return 12 ; + else if ( sFileExt == "CNC") + return 13 ; + else if ( sFileExt == "TSC") + return 101 ; + else if ( sFileExt == "LUA") + return 102 ; + else { + // emetto info + string sInfo = "File type (" + sFileExt + ") not recognized" ; + LOG_INFO( GetLogger(), sInfo.c_str()) + return 0 ; + } +} + +//----------------------------------------------------------------------------- +bool +ExeImportDxf( const string& sFilePath, double dScaleFactor) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_GEOMDB( pGseCtx, false) + bool bOk = true ; + // importo il file DXF + // aggiungo un gruppo pezzo + int nPartId = pGseCtx->m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, Frame3d()) ; + // preparo l'importatore + PtrOwner pImpDxf( MyCreateImportDxf()) ; + bOk = bOk && ! IsNull( pImpDxf) ; + // eseguo l'importazione + bOk = bOk && pImpDxf->Import( sFilePath, pGseCtx->m_pGeomDB, nPartId, dScaleFactor) ; + // aggiorno stato file corrente + pGseCtx->m_sFilePath = sFilePath ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLuaPath = sFilePath ; + ReplaceString( sLuaPath, "\\", "\\\\") ; + string sLua = "EgtImportDxf('" + sLuaPath + "'," + + ToString( dScaleFactor) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeImportStl( const string& sFilePath, double dScaleFactor) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_GEOMDB( pGseCtx, false) + bool bOk = true ; + // importo il file STL + // aggiungo un gruppo pezzo e un gruppo layer + int nPartId = pGseCtx->m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, Frame3d()) ; + int nLayerId = pGseCtx->m_pGeomDB->AddGroup( GDB_ID_NULL, nPartId, Frame3d()) ; + // preparo l'importatore + PtrOwner pImpStl( MyCreateImportStl()) ; + bOk = bOk && ! IsNull( pImpStl) ; + // eseguo l'importazione + bOk = bOk && pImpStl->Import( sFilePath, pGseCtx->m_pGeomDB, nLayerId, dScaleFactor) ; + // aggiorno stato file corrente + pGseCtx->m_sFilePath = sFilePath ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLuaPath = sFilePath ; + ReplaceString( sLuaPath, "\\", "\\\\") ; + string sLua = "EgtImportStl('" + sLuaPath + "'," + + ToString( dScaleFactor) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeImportCnc( const string& sFilePath) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_GEOMDB( pGseCtx, false) + bool bOk = true ; + // importo il file CNC + // aggiungo un gruppo pezzo + int nPartId = pGseCtx->m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, Frame3d()) ; + // preparo l'importatore + PtrOwner pImpCnc( MyCreateImportCnc()) ; + bOk = bOk && ! IsNull( pImpCnc) ; + // eseguo l'importazione + bOk = bOk && pImpCnc->Import( sFilePath, pGseCtx->m_pGeomDB, nPartId) ; + // aggiorno stato file corrente + pGseCtx->m_sFilePath = sFilePath ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLuaPath = sFilePath ; + ReplaceString( sLuaPath, "\\", "\\\\") ; + string sLua = "EgtImportCnc('" + sLuaPath + "')" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeExportDxf( int nId, const string& sFilePath) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // esporto il file DXF + // preparo l'esportatore + PtrOwner pExpDxf( MyCreateExportDxf()) ; + bOk = bOk && ! IsNull( pExpDxf) ; + // eseguo l'esportazione + bOk = bOk && pExpDxf->Export( pGeomDB, nId, sFilePath) ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLuaPath = sFilePath ; + ReplaceString( sLuaPath, "\\", "\\\\") ; + string sLua = "EgtExportDxf(" + ToString( nId) + ",'" + + sLuaPath + "')" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeExportStl( int nId, const string& sFilePath) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // esporto il file STL + // preparo l'esportatore + PtrOwner pExpStl( MyCreateExportStl()) ; + bOk = bOk && ! IsNull( pExpStl) ; + // eseguo l'esportazione + bOk = bOk && pExpStl->Export( pGeomDB, nId, sFilePath) ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLuaPath = sFilePath ; + ReplaceString( sLuaPath, "\\", "\\\\") ; + string sLua = "EgtExportStl(" + ToString( nId) + ",'" + + sLuaPath + "')" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} diff --git a/EXE_GdbCreate.cpp b/EXE_GdbCreate.cpp new file mode 100644 index 0000000..e103d46 --- /dev/null +++ b/EXE_GdbCreate.cpp @@ -0,0 +1,303 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : EXE_GdbCreate.cpp Data : 04.05.15 Versione : 1.6e1 +// Contenuto : Funzioni di creazione oggetti del DB geometrico per EXE. +// +// +// +// Modifiche : 30.09.14 DS Creazione modulo. +// 07.01.15 DS Agg. scrittura comandi Lua. +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "AuxTools.h" +#include "GeoTools.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EgkGeoPoint3d.h" +#include "/EgtDev/Include/EgkGeoVector3d.h" +#include "/EgtDev/Include/EgkExtText.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +int +ExeCreateGroup( int nParentId, const Frame3d& frFrame, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale l'origine e i versori + Point3d ptOrigL = GetPointLocal( pGeomDB, frFrame.Orig(), nRefType, frLoc) ; + Vector3d vtXL = GetVectorLocal( pGeomDB, frFrame.VersX(), nRefType, frLoc) ; + Vector3d vtYL = GetVectorLocal( pGeomDB, frFrame.VersY(), nRefType, frLoc) ; + Vector3d vtZL = GetVectorLocal( pGeomDB, frFrame.VersZ(), nRefType, frLoc) ; + // costruisco il riferimento + Frame3d frFrameL ; + bOk = bOk && frFrameL.Set( ptOrigL, vtXL, vtYL, vtZL) ; + // creo il gruppo + int nId = ( bOk ? pGeomDB->AddGroup( GDB_ID_NULL, nParentId, frFrameL) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua ; + if ( AreSameFrame( frFrame, GLOB_FRM)) + sLua = "EgtGroup(" + ToString( nParentId) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + else + sLua = "EgtGroup(" + ToString( nParentId) + ",{{" + + ToString( frFrame.Orig()) + "},{" + + ToString( frFrame.VersX()) + "},{" + + ToString( frFrame.VersY()) + "},{" + + ToString( frFrame.VersZ()) + "}}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo del nuovo gruppo + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateGeoPoint( int nParentId, const Point3d& ptP, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale il punto + Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frLoc) ; ; + // creo il punto + PtrOwner pGeoPnt( CreateGeoPoint3d()) ; + bOk = bOk && ! IsNull( pGeoPnt) ; + // setto il punto + bOk = bOk && pGeoPnt->Set( ptPL) ; + // inserisco il punto nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pGeoPnt)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtPoint(" + ToString( nParentId) + ",{" + + ToString( ptP) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateGeoVector( int nParentId, const Vector3d& vtV, const Point3d& ptB, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale il vettore e il punto + Vector3d vtVL = GetVectorLocal( pGeomDB, vtV, nRefType, frLoc) ; ; + Point3d ptBL = GetPointLocal( pGeomDB, ptB, nRefType, frLoc) ; ; + // creo il vettore + PtrOwner pGeoVct( CreateGeoVector3d()) ; + bOk = bOk && ! IsNull( pGeoVct) ; + // setto il vettore (con il punto base) + bOk = bOk && pGeoVct->Set( vtVL, ptBL) ; + // inserisco il vettore nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pGeoVct)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua ; + if ( ptB.IsSmall()) + sLua = "EgtVector(" + ToString( nParentId) + ",{" + + ToString( vtV) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + else + sLua = "EgtVector(" + ToString( nParentId) + ",{" + + ToString( vtV) + "},{" + + ToString( ptB) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateGeoFrame( int nParentId, const Frame3d& frFrame, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale l'origine e i versori + Point3d ptOrigL = GetPointLocal( pGeomDB, frFrame.Orig(), nRefType, frLoc) ; ; + Vector3d vtXL = GetVectorLocal( pGeomDB, frFrame.VersX(), nRefType, frLoc) ; ; + Vector3d vtYL = GetVectorLocal( pGeomDB, frFrame.VersY(), nRefType, frLoc) ; ; + Vector3d vtZL = GetVectorLocal( pGeomDB, frFrame.VersZ(), nRefType, frLoc) ; ; + // creo e setto il riferimento + PtrOwner pGeoFrm( CreateGeoFrame3d()) ; + bOk = bOk & ! IsNull( pGeoFrm) ; + bOk = bOk & pGeoFrm->Set( ptOrigL, vtXL, vtYL, vtZL) ; + // inserisco il riferimento nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pGeoFrm)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtFrame(" + ToString( nParentId) + ",{{" + + ToString( frFrame.Orig()) + "},{" + + ToString( frFrame.VersX()) + "},{" + + ToString( frFrame.VersY()) + "},{" + + ToString( frFrame.VersZ()) + "}}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo del nuovo gruppo + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateText( int nParentId, const Point3d& ptP, double dAngRotDeg, + const string& sText, double dH, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale l'origine e i versori + Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frLoc) ; ; + Vector3d vtNL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; ; + Vector3d vtDL = GetVectorLocal( pGeomDB, X_AX, nRefType, frLoc) ; ; + // creo il testo e lo riempio + PtrOwner pTXT( CreateExtText()) ; + bOk = bOk && ! IsNull( pTXT) ; + bOk = bOk && pTXT->Set( ptPL, vtNL, vtDL, sText, "", false, dH) ; + // inserisco il testo nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pTXT)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtText(" + ToString( nParentId) + ",{" + + ToString( ptP) + "}," + + ToString( dAngRotDeg) + ",'" + + sText + "','" + + ToString( dH) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo del oggetto + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateTextEx( int nParentId, const Point3d& ptP, const Vector3d& vtN, const Vector3d& vtD, + const string& sText, const string& sFont, bool bItalic, double dH, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale l'origine e i versori + Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frLoc) ; ; + Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ; ; + Vector3d vtDL = GetVectorLocal( pGeomDB, vtD, nRefType, frLoc) ; ; + // creo il testo e lo riempio + PtrOwner pTXT( CreateExtText()) ; + bOk = bOk && ! IsNull( pTXT) ; + bOk = bOk && pTXT->Set( ptPL, vtNL, vtDL, sText, sFont, bItalic, dH) ; + // inserisco il testo nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pTXT)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTextEx(" + ToString( nParentId) + ",{" + + ToString( ptP) + "},{" + + ToString( vtN) + "},{" + + ToString( vtD) + "},'" + + sText + "','" + + sFont + "'," + + ( bItalic ? "'I'" : "'S'") + "," + + ToString( dH) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo del oggetto + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateTextAdv( int nParentId, const Point3d& ptP, const Vector3d& vtN, const Vector3d& vtD, + const string& sText, const string& sFont, + int nW, bool bItalic, double dH, double dRat, double dAddAdv, int nInsPos, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale l'origine e i versori + Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frLoc) ; ; + Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ; ; + Vector3d vtDL = GetVectorLocal( pGeomDB, vtD, nRefType, frLoc) ; ; + // creo il testo e lo imposto + PtrOwner pTXT( CreateExtText()) ; + bOk = bOk && ! IsNull( pTXT) ; + bOk = bOk && pTXT->Set( ptPL, vtNL, vtDL, sText, sFont, nW, bItalic, dH, dRat, dAddAdv, nInsPos) ; + // inserisco il testo nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pTXT)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTextAdv(" + ToString( nParentId) + ",{" + + ToString( ptP) + "},{" + + ToString( vtN) + "},{" + + ToString( vtD) + "},'" + + sText + "','" + + sFont + "'," + + ToString( nW) + "," + + ( bItalic ? "'I'" : "'S'") + "," + + ToString( dH) + "," + + ToString( dRat) + "," + + ToString( dAddAdv) + "," + + ETxtInsPosToString( nInsPos) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo del oggetto + return nId ; +} diff --git a/EXE_GdbCreateCurve.cpp b/EXE_GdbCreateCurve.cpp new file mode 100644 index 0000000..63b5a73 --- /dev/null +++ b/EXE_GdbCreateCurve.cpp @@ -0,0 +1,1917 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : API_GdbCreateCurve.cpp Data : 02.11.14 Versione : 1.5j7 +// Contenuto : Funzioni di creazione curve del DB geometrico per API. +// +// +// +// Modifiche : 02.11.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "AuxTools.h" +#include "GeoTools.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EgkCurveLine.h" +#include "/EgtDev/Include/EGkLinePntTgCurve.h" +#include "/EgtDev/Include/EGkLinePntPerpCurve.h" +#include "/EgtDev/Include/EGkLinePntMinDistCurve.h" +#include "/EgtDev/Include/EGkLineTgTwoCurves.h" +#include "/EgtDev/Include/EGkLinePerpTwoCurves.h" +#include "/EgtDev/Include/EGkLineTgCurvePerpCurve.h" +#include "/EgtDev/Include/EgkCurveArc.h" +#include "/EgtDev/Include/EgkCircleCenTgCurve.h" +#include "/EgtDev/Include/EgkArcSpecial.h" +#include "/EgtDev/Include/EgkArcPntDirTgCurve.h" +#include "/EgtDev/Include/EgkArcCenTgCurvePnt.h" +#include "/EgtDev/Include/EgkFilletChamfer.h" +#include "/EgtDev/Include/EgkCurveBezier.h" +#include "/EgtDev/Include/EgkCurveComposite.h" +#include "/EgtDev/Include/EgkChainCurves.h" +#include "/EgtDev/Include/EgkSurfTriMesh.h" +#include "/EgtDev/Include/EGkDistPointCurve.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EGkCurveLocal.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static ICurveLine* CreateLinePointTgCurve( IGeomDB* pGeomDB, int nParentId, + const Point3d& ptIni, const Point3d& ptFin, int nIdF) ; +static ICurveLine* CreateLinePointPerpCurve( IGeomDB* pGeomDB, int nParentId, + const Point3d& ptIni, const Point3d& ptFin, int nIdF) ; +static ICurveLine* CreateLinePointMinDistCurve( IGeomDB* pGeomDB, int nParentId, + const Point3d& ptIni, const Point3d& ptFin, int nIdF) ; +static ICurveLine* CreateLineTgTwoCurves( IGeomDB* pGeomDB, int nParentId, + const Point3d& ptIni, int nIdI, const Point3d& ptFin, int nIdF) ; +static ICurveLine* CreateLinePerpTwoCurves( IGeomDB* pGeomDB, int nParentId, + const Point3d& ptIni, int nIdI, const Point3d& ptFin, int nIdF) ; +static ICurveLine* CreateLineTgCurvePerpCurve( IGeomDB* pGeomDB, int nParentId, + const Point3d& ptIni, int nIdI, const Point3d& ptFin, int nIdF) ; +static Vector3d CalcExtrusion( IGeomDB* pGeomDB, int nParentId, int nRefType) ; + + +//------------------------------------------------------------------------------- +int +ExeCreateCurveLine( int nParentId, const Point3d& ptIni, const Point3d& ptFin, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo la linea + PtrOwner pCrvLine( CreateCurveLine()) ; + if ( IsNull( pCrvLine)) + return GDB_ID_NULL ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc)) + return GDB_ID_NULL ; + // porto in locale i punti e il versore estrusione + Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ; + Point3d ptFinL = GetPointLocal( pGeomDB, ptFin, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // setto la linea + if ( ! pCrvLine->Set( ptIniL, ptFinL)) + return GDB_ID_NULL ; + // assegno il versore estrusione + pCrvLine->SetExtrusion( vtExtrL) ; + // inserisco la linea nel DB + int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvLine)) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtLine(" + ToString( nParentId) + ",{" + + ToString( ptIni) + "},{" + + ToString( ptFin) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveLineEx( int nParentId, const Point3d& ptIni, int nSepI, int nIdI, + const Point3d& ptFin, int nSepF, int nIdF, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // puntatore alla linea + PtrOwner pCrvLine ; + // recupero il riferimento locale + Frame3d frLoc ; + bool bOk = pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale i punti e il versore estrusione + Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ; + Point3d ptFinL = GetPointLocal( pGeomDB, ptFin, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // 1 - se punti entrambi definiti + if ( nSepI == SEP_STD && nSepF == SEP_STD) { + pCrvLine.Set( CreateCurveLine()) ; + bOk = bOk && ! IsNull( pCrvLine) ; + bOk = bOk && pCrvLine->Set( ptIniL, ptFinL) ; + } + // 2 - se primo punto definito e secondo a minima distanza + else if ( nSepI == SEP_STD && nSepF == SEP_MINDIST) { + pCrvLine.Set( CreateLinePointMinDistCurve( pGeomDB, nParentId, ptIniL, ptFinL, nIdF)) ; + bOk = bOk && ! IsNull( pCrvLine) ; + } + // 3 - se primo punto a minima distanza e secondo definito + else if ( nSepI == SEP_MINDIST && nSepF == SEP_STD) { + pCrvLine.Set( CreateLinePointMinDistCurve( pGeomDB, nParentId, ptFinL, ptIniL, nIdI)) ; + bOk = bOk && ! IsNull( pCrvLine) ; + bOk = bOk && pCrvLine->Invert() ; + } + // 4 - se primo punto definito e secondo tangente + else if ( nSepI == SEP_STD && nSepF == SEP_TG) { + pCrvLine.Set( CreateLinePointTgCurve( pGeomDB, nParentId, ptIniL, ptFinL, nIdF)) ; + bOk = bOk && ! IsNull( pCrvLine) ; + } + // 5 - se primo punto tangente e secondo definito + else if ( nSepI == SEP_TG && nSepF == SEP_STD) { + // costruisco la curva al contrario e poi la inverto + pCrvLine.Set( CreateLinePointTgCurve( pGeomDB, nParentId, ptFinL, ptIniL, nIdI)) ; + bOk = bOk && ! IsNull( pCrvLine) ; + bOk = bOk && pCrvLine->Invert() ; + } + // 6 - se entrambi i punti tangenti + else if ( nSepI == SEP_TG && nSepF == SEP_TG) { + pCrvLine.Set( CreateLineTgTwoCurves( pGeomDB, nParentId, ptIniL, nIdI, ptFinL, nIdF)) ; + bOk = bOk && ! IsNull( pCrvLine) ; + } + // 7 - se primo punto definito e secondo perpendicolare + else if ( nSepI == SEP_STD && nSepF == SEP_PERP) { + pCrvLine.Set( CreateLinePointPerpCurve( pGeomDB, nParentId, ptIniL, ptFinL, nIdF)) ; + bOk = bOk && ! IsNull( pCrvLine) ; + } + // 8 - se primo punto perpendicolare e secondo definito + else if ( nSepI == SEP_PERP && nSepF == SEP_STD) { + // costruisco la curva al contrario e poi la inverto + pCrvLine.Set( CreateLinePointPerpCurve( pGeomDB, nParentId, ptFinL, ptIniL, nIdI)) ; + bOk = bOk && ! IsNull( pCrvLine) ; + bOk = bOk && pCrvLine->Invert() ; + } + // 9 - se entrambi i punti perpendicolari + else if ( nSepI == SEP_PERP && nSepF == SEP_PERP) { + pCrvLine.Set( CreateLinePerpTwoCurves( pGeomDB, nParentId, ptIniL, nIdI, ptFinL, nIdF)) ; + bOk = bOk && ! IsNull( pCrvLine) ; + } + // 10 - se primo punto tangente e secondo perpendicolare + else if ( nSepI == SEP_TG && nSepF == SEP_PERP) { + pCrvLine.Set( CreateLineTgCurvePerpCurve( pGeomDB, nParentId, ptIniL, nIdI, ptFinL, nIdF)) ; + bOk = bOk && ! IsNull( pCrvLine) ; + } + // 11 - se primo punto perpendicolare e secondo tangente + else if ( nSepI == SEP_PERP && nSepF == SEP_TG) { + // costruisco la curva al contrario e poi la inverto + pCrvLine.Set( CreateLineTgCurvePerpCurve( pGeomDB, nParentId, ptFinL, nIdF, ptIniL, nIdI)) ; + bOk = bOk && ! IsNull( pCrvLine) ; + bOk = bOk && pCrvLine->Invert() ; + } + // errore + else { + bOk = false ; + } + // assegno il versore estrusione + bOk = bOk && pCrvLine->SetExtrusion( vtExtrL) ; + // inserisco la linea nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvLine)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua ; + if ( nSepI == SEP_STD && nSepF == SEP_STD) + sLua = "EgtLine(" + ToString( nParentId) + ",{" + + ToString( ptIni) + "},{" + + ToString( ptFin) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + else + sLua = "EgtLineEx(" + ToString( nParentId) + ",{" + + ToString( ptIni) + "}," + + SepToString( nSepI) + "," + + ToString( nIdI) + ",{" + + ToString( ptFin) + "}," + + SepToString( nSepF) + "," + + ToString( nIdF) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +ICurveLine* +CreateLinePointTgCurve( IGeomDB* pGeomDB, int nParentId, + const Point3d& ptIni, const Point3d& ptFin, int nIdF) +{ + // verifica preliminare Id curva + if ( nIdF == GDB_ID_NULL) + return nullptr ; + // recupero il riferimento del gruppo destinazione + Frame3d frDest ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frDest)) + return nullptr ; + // recupero il riferimento della curva + Frame3d frCurve ; + if ( ! pGeomDB->GetGlobFrame( nIdF, frCurve)) + return nullptr ; + // porto il punto iniziale nel riferimento della curva + Point3d ptSloc( ptIni) ; + ptSloc.LocToLoc( frDest, frCurve) ; + // porto il punto vicino al finale nel riferimento della curva + Point3d ptNloc( ptFin) ; + ptNloc.LocToLoc( frDest, frCurve) ; + // recupero la curva + const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nIdF)) ; + if ( pCurve == nullptr) + return false ; + // calcolo la retta tangente alla curva + PtrOwner pCrvLine ; + pCrvLine.Set( GetLinePointTgCurve( ptSloc, *pCurve, ptNloc)) ; + if ( IsNull( pCrvLine)) + return nullptr ; + // porto la linea nel riferimento del gruppo destinazione + pCrvLine->LocToLoc( frCurve, frDest) ; + // restituisco la linea + return Release( pCrvLine) ; +} + +//------------------------------------------------------------------------------- +ICurveLine* +CreateLinePointPerpCurve( IGeomDB* pGeomDB, int nParentId, + const Point3d& ptIni, const Point3d& ptFin, int nIdF) +{ + // verifica preliminare Id curva + if ( nIdF == GDB_ID_NULL) + return nullptr ; + // recupero il riferimento del gruppo destinazione + Frame3d frDest ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frDest)) + return nullptr ; + // recupero il riferimento della curva + Frame3d frCurve ; + if ( ! pGeomDB->GetGlobFrame( nIdF, frCurve)) + return nullptr ; + // porto il punto iniziale nel riferimento della curva + Point3d ptSloc( ptIni) ; + ptSloc.LocToLoc( frDest, frCurve) ; + // porto il punto vicino al finale nel riferimento della curva + Point3d ptNloc( ptFin) ; + ptNloc.LocToLoc( frDest, frCurve) ; + // recupero la curva + const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nIdF)) ; + if ( pCurve == nullptr) + return nullptr ; + // calcolo la retta perpendicolare alla curva + PtrOwner pCrvLine ; + pCrvLine.Set( GetLinePointPerpCurve( ptSloc, *pCurve, ptNloc)) ; + if ( IsNull( pCrvLine)) + return nullptr ; + // porto la linea nel riferimento del gruppo destinazione + pCrvLine->LocToLoc( frCurve, frDest) ; + // restituisco la linea + return Release( pCrvLine) ; +} + +//------------------------------------------------------------------------------- +ICurveLine* +CreateLinePointMinDistCurve( IGeomDB* pGeomDB, int nParentId, + const Point3d& ptIni, const Point3d& ptFin, int nIdF) +{ + // verifica preliminare Id curva + if ( nIdF == GDB_ID_NULL) + return nullptr ; + // recupero il riferimento del gruppo destinazione + Frame3d frDest ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frDest)) + return nullptr ; + // recupero il riferimento della curva + Frame3d frCurve ; + if ( ! pGeomDB->GetGlobFrame( nIdF, frCurve)) + return nullptr ; + // porto il punto iniziale nel riferimento della curva + Point3d ptSloc( ptIni) ; + ptSloc.LocToLoc( frDest, frCurve) ; + // porto il punto vicino al finale nel riferimento della curva + Point3d ptNloc( ptFin) ; + ptNloc.LocToLoc( frDest, frCurve) ; + // recupero la curva + const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nIdF)) ; + if ( pCurve == nullptr) + return nullptr ; + // calcolo la retta perpendicolare alla curva + PtrOwner pCrvLine ; + pCrvLine.Set( GetLinePointMinDistCurve( ptSloc, *pCurve, ptNloc)) ; + if ( IsNull( pCrvLine)) + return nullptr ; + // porto la linea nel riferimento del gruppo destinazione + pCrvLine->LocToLoc( frCurve, frDest) ; + // restituisco la linea + return Release( pCrvLine) ; +} + +//------------------------------------------------------------------------------- +ICurveLine* +CreateLineTgTwoCurves( IGeomDB* pGeomDB, int nParentId, + const Point3d& ptIni, int nIdI, const Point3d& ptFin, int nIdF) +{ + // verifica preliminare Id curve + if ( nIdF == GDB_ID_NULL || nIdI == GDB_ID_NULL) + return nullptr ; + // recupero il riferimento del gruppo destinazione + Frame3d frDest ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frDest)) + return nullptr ; + // recupero il riferimento della prima curva + Frame3d frCrv1 ; + if ( ! pGeomDB->GetGlobFrame( nIdI, frCrv1)) + return nullptr ; + // recupero la prima curva + const ICurve* pCrv1 = GetCurve( pGeomDB->GetGeoObj( nIdI)) ; + if ( pCrv1 == nullptr) + return nullptr ; + // porto il punto vicino a iniziale nel riferimento della prima curva + Point3d ptN1loc( ptIni) ; + ptN1loc.LocToLoc( frDest, frCrv1) ; + // recupero il riferimento della seconda curva + Frame3d frCrv2 ; + if ( ! pGeomDB->GetGlobFrame( nIdF, frCrv2)) + return nullptr ; + // recupero la seconda curva + const ICurve* pCrv2 = GetCurve( pGeomDB->GetGeoObj( nIdF)) ; + if ( pCrv2 == nullptr) + return false ; + // porto la seconda curva nel riferimento della prima + PtrOwner pCrv2Loc( pCrv2->Clone()) ; + if ( IsNull( pCrv2Loc)) + return nullptr ; + pCrv2Loc->LocToLoc( frCrv2, frCrv1) ; + // porto il punto vicino al finale nel riferimento della prima curva + Point3d ptN2loc( ptFin) ; + ptN2loc.LocToLoc( frDest, frCrv1) ; + // calcolo la retta tangente alle due curve + PtrOwner pCrvLine ; + pCrvLine.Set( GetLineTgTwoCurves( *pCrv1, ptN1loc, *pCrv2, ptN2loc)) ; + if ( IsNull( pCrvLine)) + return nullptr ; + // porto la linea nel riferimento del gruppo destinazione + pCrvLine->LocToLoc( frCrv1, frDest) ; + // restituisco la linea + return Release( pCrvLine) ; +} + +//------------------------------------------------------------------------------- +ICurveLine* +CreateLinePerpTwoCurves( IGeomDB* pGeomDB, int nParentId, + const Point3d& ptIni, int nIdI, const Point3d& ptFin, int nIdF) +{ + // verifica preliminare Id curve + if ( nIdI == GDB_ID_NULL || nIdF == GDB_ID_NULL) + return nullptr ; + // recupero il riferimento del gruppo destinazione + Frame3d frDest ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frDest)) + return nullptr ; + // recupero il riferimento della prima curva + Frame3d frCrv1 ; + if ( ! pGeomDB->GetGlobFrame( nIdI, frCrv1)) + return nullptr ; + // recupero la prima curva + const ICurve* pCrv1 = GetCurve( pGeomDB->GetGeoObj( nIdI)) ; + if ( pCrv1 == nullptr) + return nullptr ; + // porto il punto vicino a iniziale nel riferimento della prima curva + Point3d ptN1loc( ptIni) ; + ptN1loc.LocToLoc( frDest, frCrv1) ; + // recupero il riferimento della seconda curva + Frame3d frCrv2 ; + if ( ! pGeomDB->GetGlobFrame( nIdF, frCrv2)) + return nullptr ; + // recupero la seconda curva + const ICurve* pCrv2 = GetCurve( pGeomDB->GetGeoObj( nIdF)) ; + if ( pCrv2 == nullptr) + return nullptr ; + // porto la seconda curva nel riferimento della prima + PtrOwner pCrv2Loc( pCrv2->Clone()) ; + if ( IsNull( pCrv2Loc)) + return nullptr ; + pCrv2Loc->LocToLoc( frCrv2, frCrv1) ; + // porto il punto vicino al finale nel riferimento della prima curva + Point3d ptN2loc( ptFin) ; + ptN2loc.LocToLoc( frDest, frCrv1) ; + // calcolo la retta perpendicolare alle due curve + PtrOwner pCrvLine ; + pCrvLine.Set( GetLinePerpTwoCurves( *pCrv1, ptN1loc, *pCrv2, ptN2loc)) ; + if ( IsNull( pCrvLine)) + return nullptr ; + // porto la linea nel riferimento del gruppo destinazione + pCrvLine->LocToLoc( frCrv1, frDest) ; + // restituisco la linea + return Release( pCrvLine) ; +} + +//------------------------------------------------------------------------------- +ICurveLine* +CreateLineTgCurvePerpCurve( IGeomDB* pGeomDB, int nParentId, + const Point3d& ptIni, int nIdI, const Point3d& ptFin, int nIdF) +{ + // verifica preliminare Id curve + if ( nIdI == GDB_ID_NULL || nIdF == GDB_ID_NULL) + return nullptr ; + // recupero il riferimento del gruppo destinazione + Frame3d frDest ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frDest)) + return nullptr ; + // recupero il riferimento della prima curva + Frame3d frCrv1 ; + if ( ! pGeomDB->GetGlobFrame( nIdI, frCrv1)) + return nullptr ; + // recupero la prima curva + const ICurve* pCrv1 = GetCurve( pGeomDB->GetGeoObj( nIdI)) ; + if ( pCrv1 == nullptr) + return nullptr ; + // porto il punto vicino a iniziale nel riferimento della prima curva + Point3d ptN1loc( ptIni) ; + ptN1loc.LocToLoc( frDest, frCrv1) ; + // recupero il riferimento della seconda curva + Frame3d frCrv2 ; + if ( ! pGeomDB->GetGlobFrame( nIdF, frCrv2)) + return nullptr ; + // recupero la seconda curva + const ICurve* pCrv2 = GetCurve( pGeomDB->GetGeoObj( nIdF)) ; + if ( pCrv2 == nullptr) + return nullptr ; + // porto la seconda curva nel riferimento della prima + PtrOwner pCrv2Loc( pCrv2->Clone()) ; + if ( IsNull( pCrv2Loc)) + return nullptr ; + pCrv2Loc->LocToLoc( frCrv2, frCrv1) ; + // porto il punto vicino al finale nel riferimento della prima curva + Point3d ptN2loc( ptFin) ; + ptN2loc.LocToLoc( frDest, frCrv1) ; + // calcolo la retta perpendicolare alle due curve + PtrOwner pCrvLine ; + pCrvLine.Set( GetLineTgCurvePerpCurve( *pCrv1, ptN1loc, *pCrv2, ptN2loc)) ; + if ( IsNull( pCrvLine)) + return nullptr ; + // porto la linea nel riferimento del gruppo destinazione + pCrvLine->LocToLoc( frCrv1, frDest) ; + // restituisco la linea + return Release( pCrvLine) ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveLinePVL( int nParentId, const Point3d& ptIni, + const Vector3d& vtDir, double dLen, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc)) + return GDB_ID_NULL ; + // porto in locale il punto e i versori + Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ; + Vector3d vtDirL = GetVectorLocal( pGeomDB, vtDir, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // creo la linea + PtrOwner pCrvLine( CreateCurveLine()) ; + if ( IsNull( pCrvLine)) + return GDB_ID_NULL ; + // setto la linea + if ( ! pCrvLine->SetPVL( ptIniL, vtDirL, dLen)) + return GDB_ID_NULL ; + // assegno il versore estrusione + pCrvLine->SetExtrusion( vtExtrL) ; + // inserisco la linea nel DB + int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvLine)) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtLinePVL(" + ToString( nParentId) + ",{" + + ToString( ptIni) + "},{" + + ToString( vtDir) + "}," + + ToString( dLen) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveLineMinPointCurve( int nParentId, + const Point3d& ptStart, int nCrvId, double dNearPar, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc)) + return GDB_ID_NULL ; + // porto in locale il punto e il versore estrusione + Point3d ptStartL = GetPointLocal( pGeomDB, ptStart, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // recupero il riferimento della curva + Frame3d frCurve ; + if ( ! pGeomDB->GetGlobFrame( nCrvId, frCurve)) + return GDB_ID_NULL ; + // recupero la curva + const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ; + if ( pCurve == nullptr) + return GDB_ID_NULL ; + // porto il punto nel riferimento della curva + Point3d ptStartC = ptStart ; + ptStartC.LocToLoc( frLoc, frCurve) ; + // calcolo il punto a minima distanza + int nFlag ; + Point3d ptEndL ; + DistPointCurve dstPtCurve( ptStartC, *pCurve) ; + if ( ! dstPtCurve.GetMinDistPoint( dNearPar, ptEndL, nFlag)) + return GDB_ID_NULL ; + // porto il punto finale nel riferimento di creazione + ptEndL.LocToLoc( frCurve, frLoc) ; + // creo la linea + PtrOwner pCrvLine( CreateCurveLine()) ; + if ( IsNull( pCrvLine)) + return GDB_ID_NULL ; + // setto la linea + if ( ! pCrvLine->Set( ptStartL, ptEndL)) + return GDB_ID_NULL ; + // assegno il versore estrusione + pCrvLine->SetExtrusion( vtExtrL) ; + // inserisco la linea nel DB + int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvLine)) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtLineMinPointCurve(" + ToString( nParentId) + ",{" + + ToString( ptStart) + "}," + + ToString( nCrvId) + "," + + ToString( dNearPar) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveCircle( int nParentId, const Point3d& ptCen, + const Vector3d& vtN, double dRad, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo l'arco + PtrOwner pCrvArc( CreateCurveArc()) ; + if ( IsNull( pCrvArc)) + return GDB_ID_NULL ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc)) + return GDB_ID_NULL ; + // porto in locale i punti e i versori + Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ; + Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // setto la circonferenza + if ( ! pCrvArc->Set( ptCenL, vtNL, dRad)) + return GDB_ID_NULL ; + // assegno il versore estrusione + pCrvArc->SetExtrusion( vtExtrL) ; + // inserisco l'arco nel DB + int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtCircle(" + ToString( nParentId) + ",{" + + ToString( ptCen) + "},{" + + ToString( vtN) + "}," + + ToString( dRad) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveCircleCPN( int nParentId, const Point3d& ptCen, + const Point3d& ptOn, const Vector3d& vtN, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo l'arco + PtrOwner pCrvArc( CreateCurveArc()) ; + bool bOk = ! IsNull( pCrvArc) ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale i punti e i versori + Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ; + Point3d ptOnL = GetPointLocal( pGeomDB, ptOn, nRefType, frLoc) ; + Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // calcolo il raggio + double dRad = (( ptOnL - ptCenL) ^ vtNL).Len() ; + // setto la circonferenza + bOk = bOk && pCrvArc->Set( ptCenL, vtNL, dRad) ; + // assegno il versore estrusione + bOk = bOk && pCrvArc->SetExtrusion( vtExtrL) ; + // inserisco l'arco nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtCircleCPN(" + ToString( nParentId) + ",{" + + ToString( ptCen) + "},{" + + ToString( ptOn) + "},{" + + ToString( vtN) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveCircleCPNEx( int nParentId, const Point3d& ptCen, + const Point3d& ptOn, int nSepO, int nIdO, const Vector3d& vtN, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo l'arco + PtrOwner pCrvArc ; + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale i punti e i versori + Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ; + Point3d ptOnL = GetPointLocal( pGeomDB, ptOn, nRefType, frLoc) ; + Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // se punto standard + if ( nSepO == SEP_STD) { + pCrvArc.Set( CreateCurveArc()) ; + bOk = bOk && ! IsNull( pCrvArc) ; + // calcolo il raggio + double dRad = (( ptOnL - ptCenL) ^ vtNL).Len() ; + // setto la circonferenza + bOk = bOk && pCrvArc->Set( ptCenL, vtNL, dRad) ; + } + // se punto di tangenza, determino il vero punto di passaggio + else if ( nSepO == SEP_TG) { + // recupero la curva di tangenza in locale + CurveLocal CrvTgLoc( pGeomDB, nIdO, frLoc) ; + // calcolo la circonferenza tangente a questa curva + pCrvArc.Set( GetCircleCenTgCurve( ptCenL, vtNL, *CrvTgLoc.Get(), ptOnL)) ; + bOk = bOk && ! IsNull( pCrvArc) ; + } + // altrimenti errore + else + bOk = false ; + // assegno il versore estrusione + bOk = bOk && pCrvArc->SetExtrusion( vtExtrL) ; + // inserisco l'arco nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtCircleCPNEx(" + ToString( nParentId) + ",{" + + ToString( ptCen) + "},{" + + ToString( ptOn) + "}," + + SepToString( nSepO) + "," + + ToString( nIdO) + ",{" + + ToString( vtN) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveCircle3P( int nParentId, const Point3d& ptP1, + const Point3d& ptP2, const Point3d& ptP3, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo l'arco + PtrOwner pCrvArc( CreateCurveArc()) ; + if ( IsNull( pCrvArc)) + return GDB_ID_NULL ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc)) + return GDB_ID_NULL ; + // porto in locale i punti e il versore estrusione + Point3d ptP1L = GetPointLocal( pGeomDB, ptP1, nRefType, frLoc) ; + Point3d ptP2L = GetPointLocal( pGeomDB, ptP2, nRefType, frLoc) ; + Point3d ptP3L = GetPointLocal( pGeomDB, ptP3, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // setto l'arco + if ( ! pCrvArc->Set3P( ptP1L, ptP2L, ptP3L, true)) + return GDB_ID_NULL ; + // assegno il versore estrusione + pCrvArc->SetExtrusion( vtExtrL) ; + // inserisco l'arco nel DB + int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtCircle3P(" + ToString( nParentId) + ",{" + + ToString( ptP1) + "},{" + + ToString( ptP2) + "},{" + + ToString( ptP3) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveArc( int nParentId, + const Point3d& ptCen, const Vector3d& vtN, double dRad, + const Vector3d& vtS, double dAngCenDeg, double dDeltaN, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo l'arco + PtrOwner pCrvArc( CreateCurveArc()) ; + if ( IsNull( pCrvArc)) + return GDB_ID_NULL ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc)) + return GDB_ID_NULL ; + // porto in locale i punti, i versori e il versore estrusione + Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ; + Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ; + Vector3d vtSL = GetVectorLocal( pGeomDB, vtS, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // setto l'arco + if ( ! pCrvArc->Set( ptCenL, vtNL, dRad, vtSL, dAngCenDeg, dDeltaN)) + return GDB_ID_NULL ; + // assegno il versore estrusione + pCrvArc->SetExtrusion( vtExtrL) ; + // inserisco l'arco nel DB + int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtArc(" + ToString( nParentId) + ",{" + + ToString( ptCen) + "},{" + + ToString( vtN) + "}," + + ToString( dRad) + ",{" + + ToString( vtS) + "}," + + ToString( dAngCenDeg) + "," + + ToString( dDeltaN) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveArcC2PN( int nParentId, const Point3d& ptCen, const Point3d& ptStart, + const Point3d& ptNearEnd, const Vector3d& vtNorm, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo l'arco + PtrOwner pCrvArc( CreateCurveArc()) ; + if ( IsNull( pCrvArc)) + return GDB_ID_NULL ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc)) + return GDB_ID_NULL ; + // porto in locale i punti, i versori e il versore estrusione + Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ; + Point3d ptStartL = GetPointLocal( pGeomDB, ptStart, nRefType, frLoc) ; + Point3d ptNearEndL = GetPointLocal( pGeomDB, ptNearEnd, nRefType, frLoc) ; + Vector3d vtNormL = GetVectorLocal( pGeomDB, vtNorm, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // setto l'arco + if ( ! pCrvArc->SetC2PN( ptCenL, ptStartL, ptNearEndL, vtNormL)) + return GDB_ID_NULL ; + // assegno il versore estrusione + pCrvArc->SetExtrusion( vtExtrL) ; + // inserisco l'arco nel DB + int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtArcC2PN(" + ToString( nParentId) + ",{" + + ToString( ptCen) + "},{" + + ToString( ptStart) + "},{" + + ToString( ptNearEnd) + "},{" + + ToString( vtNorm) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveArcC2PNEx( int nParentId, const Point3d& ptCen, + const Point3d& ptStart, int nSepS, int nIdS, + const Point3d& ptNearEnd, const Vector3d& vtNorm, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo l'arco + PtrOwner pCrvArc ; + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale i punti, i versori e il versore estrusione + Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ; + Point3d ptStartL = GetPointLocal( pGeomDB, ptStart, nRefType, frLoc) ; + Point3d ptNearEndL = GetPointLocal( pGeomDB, ptNearEnd, nRefType, frLoc) ; + Vector3d vtNormL = GetVectorLocal( pGeomDB, vtNorm, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // se punto standard + if ( nSepS == SEP_STD) { + pCrvArc.Set( CreateCurveArc()) ; + bOk = bOk && ! IsNull( pCrvArc) ; + // setto l'arco + if ( ! pCrvArc->SetC2PN( ptCenL, ptStartL, ptNearEndL, vtNormL)) + return GDB_ID_NULL ; + } + // se punto di tangenza, determino il vero punto di passaggio + else if ( nSepS == SEP_TG) { + // recupero la curva di tangenza in locale + CurveLocal CrvTgLoc( pGeomDB, nIdS, frLoc) ; + // calcolo l'arco tangente a questa curva + pCrvArc.Set( GetArcCenTgCurvePnt( ptCenL, *CrvTgLoc.Get(), ptStartL, ptNearEndL, vtNormL)) ; + bOk = bOk && ! IsNull( pCrvArc) ; + } + // altrimenti errore + else + bOk = false ; + // assegno il versore estrusione + bOk = bOk && pCrvArc->SetExtrusion( vtExtrL) ; + // inserisco l'arco nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtArcC2PNEx(" + ToString( nParentId) + ",{" + + ToString( ptCen) + "},{" + + ToString( ptStart) + "},{" + + SepToString( nSepS) + "," + + ToString( nIdS) + ",{" + + ToString( ptNearEnd) + "},{" + + ToString( vtNorm) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveArc3P( int nParentId, const Point3d& ptP1, + const Point3d& ptP2, const Point3d& ptP3, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo l'arco + PtrOwner pCrv ; + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale i punti e il versore estrusione + Point3d ptP1L = GetPointLocal( pGeomDB, ptP1, nRefType, frLoc) ; + Point3d ptP2L = GetPointLocal( pGeomDB, ptP2, nRefType, frLoc) ; + Point3d ptP3L = GetPointLocal( pGeomDB, ptP3, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // setto l'arco + pCrv.Set( GetArc3P( ptP1L, ptP2L, ptP3L, false)) ; + bOk = bOk && ! ( IsNull( pCrv)) ; + // assegno il versore estrusione + bOk = bOk && pCrv->SetExtrusion( vtExtrL) ; + // inserisco l'arco nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrv)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtArc3P(" + ToString( nParentId) + ",{" + + ToString( ptP1) + "},{" + + ToString( ptP2) + "},{" + + ToString( ptP3) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveArc2PVN( int nParentId, const Point3d& ptStart, const Point3d& ptEnd, + const Vector3d& vtDirS, const Vector3d& vtNorm, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo l'arco (in casi particolari retta) + PtrOwner pCrv ; + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale i punti, i versori e il versore estrusione + Point3d ptStartL = GetPointLocal( pGeomDB, ptStart, nRefType, frLoc) ; + Point3d ptEndL = GetPointLocal( pGeomDB, ptEnd, nRefType, frLoc) ; + Vector3d vtDirSL = GetVectorLocal( pGeomDB, vtDirS, nRefType, frLoc) ; + Vector3d vtNormL = GetVectorLocal( pGeomDB, vtNorm, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // setto l'arco + pCrv.Set( GetArc2PVN( ptStartL, ptEndL, vtDirSL, vtNormL)) ; + bOk = bOk && ! IsNull( pCrv) ; + // assegno il versore estrusione + bOk = bOk && pCrv->SetExtrusion( vtExtrL) ; + // inserisco l'arco nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrv)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtArc2PVN(" + ToString( nParentId) + ",{" + + ToString( ptStart) + "},{" + + ToString( ptEnd) + "},{" + + ToString( vtDirS) + "},{" + + ToString( vtNorm) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveArc2PVNEx( int nParentId, const Point3d& ptStart, + const Point3d& ptEnd, int nSep, int nId, + const Vector3d& vtDirS, const Vector3d& vtNorm, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo la curva ( in casi particolari potrebbe essere una retta) + PtrOwner pCrv ; + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale i punti, i versori e il versore estrusione + Point3d ptStartL = GetPointLocal( pGeomDB, ptStart, nRefType, frLoc) ; + Point3d ptEndL = GetPointLocal( pGeomDB, ptEnd, nRefType, frLoc) ; + Vector3d vtDirSL = GetVectorLocal( pGeomDB, vtDirS, nRefType, frLoc) ; + Vector3d vtNormL = GetVectorLocal( pGeomDB, vtNorm, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // se punto standard + if ( nSep == SEP_STD) { + // creo l'arco + pCrv.Set( CreateCurveArc()) ; + bOk = bOk && ! IsNull( pCrv) ; + if ( bOk) { + // imposto l'arco + if ( (dynamic_cast(Get(pCrv)))->Set2PVN( ptStartL, ptEndL, vtDirSL, vtNormL)) + ; + // non riuscito, provo se risulta essere una retta + else if ( ( ptEndL - ptStartL) * vtDirSL > EPS_ZERO) { + // creo e setto la retta + pCrv.Set( CreateCurveLine()) ; + bOk = bOk && ! IsNull( pCrv) ; + bOk = bOk && (dynamic_cast(Get(pCrv)))->Set( ptStartL, ptEndL) ; + } + // impossibile + else + bOk = false ; + } + } + // se punto di tangenza, determino il vero punto di passaggio + else if ( nSep == SEP_TG) { + // recupero la curva di tangenza in locale + CurveLocal CrvTgLoc( pGeomDB, nId, frLoc) ; + // calcolo l'arco tangente a questa curva + pCrv.Set( GetArcPntDirTgCurve( ptStartL, vtDirSL, *CrvTgLoc.Get(), ptEndL, vtNormL)) ; + bOk = bOk && ! IsNull( pCrv) ; + } + // altrimenti errore + else + bOk = false ; + // assegno il versore estrusione + bOk = bOk && pCrv->SetExtrusion( vtExtrL) ; + // inserisco l'arco nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrv)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtArc2PVNEx(" + ToString( nParentId) + ",{" + + ToString( ptStart) + "},{" + + ToString( ptEnd) + "}," + + SepToString( nSep) + "," + + ToString( nId) + ",{" + + ToString( vtDirS) + "},{" + + ToString( vtNorm) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveFillet( int nParentId, int nCrv1, const Point3d& ptNear1, + int nCrv2, const Point3d& ptNear2, + const Vector3d& vtNorm, double dRad, bool bTrim, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo l'arco + PtrOwner pArc ; + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale i punti, i versori e il versore estrusione + Point3d ptNear1L = GetPointLocal( pGeomDB, ptNear1, nRefType, frLoc) ; + Point3d ptNear2L = GetPointLocal( pGeomDB, ptNear2, nRefType, frLoc) ; + Vector3d vtNormL = GetVectorLocal( pGeomDB, vtNorm, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // recupero la copia locale delle curve + CurveLocal CrvLoc1( pGeomDB, nCrv1, frLoc) ; + CurveLocal CrvLoc2( pGeomDB, nCrv2, frLoc) ; + // calcolo il raccordo + double dTrim1, dTrim2 ; + pArc.Set( CreateFillet( *CrvLoc1.Get(), ptNear1L, *CrvLoc2.Get(), ptNear2L, vtNormL, dRad, dTrim1, dTrim2)) ; + bOk = bOk && ! IsNull( pArc) ; + // assegno il versore estrusione + bOk = bOk && pArc->SetExtrusion( vtExtrL) ; + // inserisco l'arco nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pArc)) : GDB_ID_NULL) ; + // se richiesto trim + if ( nNewId != GDB_ID_NULL && bTrim) { + // recupero e aggiusto la prima curva + ICurve* pCrv1 = GetCurve( pGeomDB->GetGeoObj( nCrv1)) ; + if ( dTrim1 > EPS_ZERO) + pCrv1->TrimStartAtParam( dTrim1) ; + else if ( dTrim1 < - EPS_ZERO) + pCrv1->TrimEndAtParam( fabs( dTrim1)) ; + // recupero e aggiusto la seconda curva + ICurve* pCrv2 = GetCurve( pGeomDB->GetGeoObj( nCrv2)) ; + if ( dTrim2 > EPS_ZERO) + pCrv2->TrimStartAtParam( dTrim2) ; + else if ( dTrim2 < - EPS_ZERO) + pCrv2->TrimEndAtParam( fabs( dTrim2)) ; + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtCurveFillet(" + ToString( nParentId) + "," + + ToString( nCrv1) + ",{" + + ToString( ptNear1) + "}," + + ToString( nCrv2) + ",{" + + ToString( ptNear2) + "},{" + + ToString( vtNorm) + "}," + + ToString( dRad) + "," + + ( bTrim ? "true" : "false") + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveChamfer( int nParentId, int nCrv1, const Point3d& ptNear1, + int nCrv2, const Point3d& ptNear2, + const Vector3d& vtNorm, double dDist, bool bTrim, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo la linea + PtrOwner pLine ; + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale i punti, i versori e il versore estrusione + Point3d ptNear1L = GetPointLocal( pGeomDB, ptNear1, nRefType, frLoc) ; + Point3d ptNear2L = GetPointLocal( pGeomDB, ptNear2, nRefType, frLoc) ; + Vector3d vtNormL = GetVectorLocal( pGeomDB, vtNorm, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // recupero la copia locale delle curve + CurveLocal CrvLoc1( pGeomDB, nCrv1, frLoc) ; + CurveLocal CrvLoc2( pGeomDB, nCrv2, frLoc) ; + // calcolo lo smusso + double dTrim1, dTrim2 ; + pLine.Set( CreateChamfer( *CrvLoc1.Get(), ptNear1L, *CrvLoc2.Get(), ptNear2L, vtNormL, dDist, dTrim1, dTrim2)) ; + bOk = bOk && ! IsNull( pLine) ; + // assegno il versore estrusione + bOk = bOk && pLine->SetExtrusion( vtExtrL) ; + // inserisco l'arco nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pLine)) : GDB_ID_NULL) ; + // se richiesto trim + if ( nNewId != GDB_ID_NULL && bTrim) { + // recupero e aggiusto la prima curva + ICurve* pCrv1 = GetCurve( pGeomDB->GetGeoObj( nCrv1)) ; + if ( dTrim1 > EPS_ZERO) + pCrv1->TrimStartAtParam( dTrim1) ; + else if ( dTrim1 < - EPS_ZERO) + pCrv1->TrimEndAtParam( fabs( dTrim1)) ; + // recupero e aggiusto la seconda curva + ICurve* pCrv2 = GetCurve( pGeomDB->GetGeoObj( nCrv2)) ; + if ( dTrim2 > EPS_ZERO) + pCrv2->TrimStartAtParam( dTrim2) ; + else if ( dTrim2 < - EPS_ZERO) + pCrv2->TrimEndAtParam( fabs( dTrim2)) ; + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtCurveChamfer(" + ToString( nParentId) + "," + + ToString( nCrv1) + ",{" + + ToString( ptNear1) + "}," + + ToString( nCrv2) + ",{" + + ToString( ptNear2) + "},{" + + ToString( vtNorm) + "}," + + ToString( dDist) + "," + + ( bTrim ? "true" : "false") + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveBezier( int nParentId, int nDegree, const PNTVECTOR& vPnt, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // il numero dei punti deve essere pari al grado + 1 + bOk = bOk && ( vPnt.size() == nDegree + 1) ; + // recupero il riferimento di immersione della curva + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // creo la curva di Bezier + PtrOwner pCrvBez( CreateCurveBezier()) ; + bOk = bOk && ! IsNull( pCrvBez) ; + // inizializzo la curva di Bezier + bOk = bOk && pCrvBez->Init( nDegree, false) ; + // setto i punti di controllo + for ( int i = 0 ; i <= nDegree && bOk ; ++ i) { + // eventuale trasformazione del punto nel riferimento locale + Point3d ptCtrl = GetPointLocal( pGeomDB, vPnt[i], nRefType, frLoc) ; + // inserimento del punto di controllo + if ( ! pCrvBez->SetControlPoint( i, ptCtrl)) + bOk = false ; + } + // se curva nulla (ovvero ridotta a punto), errore + bOk = bOk && ! pCrvBez->IsAPoint() ; + // assegno il versore estrusione + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + pCrvBez->SetExtrusion( vtExtrL) ; + // inserisco la curva nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvBez)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sPC ; + for ( size_t i = 0 ; i < vPnt.size() ; ++ i) { + if ( i > 0) + sPC += "," ; + sPC += "{" + ToString( vPnt[i]) + "}" ; + } + string sLua = "EgtCurveBezier(" + ToString( nParentId) + "," + + ToString( nDegree) + ",{" + + sPC + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveBezierRational( int nParentId, int nDegree, const PNTUVECTOR& vPntW, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // il numero dei punti deve essere pari al grado + 1 + bOk = bOk && ( vPntW.size() == nDegree + 1) ; + // recupero il riferimento di immersione della curva + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // creo la curva di Bezier + PtrOwner pCrvBez( CreateCurveBezier()) ; + bOk = bOk && ! IsNull( pCrvBez) ; + // inizializzo la curva di Bezier + bOk = bOk && pCrvBez->Init( nDegree, true) ; + // setto i punti di controllo + for ( int i = 0 ; i <= nDegree && bOk ; ++ i) { + // eventuale trasformazione del punto nel riferimento locale + Point3d ptCtrl = GetPointLocal( pGeomDB, vPntW[i].first, nRefType, frLoc) ; + // inserimento del punto di controllo con peso + if ( ! pCrvBez->SetControlPoint( i, ptCtrl, vPntW[i].second)) + return GDB_ID_NULL ; + } + // se curva nulla (ovvero ridotta a punto), errore + bOk = bOk && ! pCrvBez->IsAPoint() ; + // assegno il versore estrusione + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + pCrvBez->SetExtrusion( vtExtrL) ; + // inserisco la curva nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvBez)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sPC ; + for ( size_t i = 0 ; i < vPntW.size() ; ++ i) { + if ( i > 0) + sPC += "," ; + sPC += "{" + ToString( vPntW[i].first, vPntW[i].second) + "}" ; + } + string sLua = "EgtCurveBezierRat(" + ToString( nParentId) + "," + + ToString( nDegree) + ",{" + + sPC + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveBezierFromArc( int nParentId, int nArcId, bool bErase) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // creo la curva di Bezier + PtrOwner pCrvBez( CreateCurveBezier()) ; + bOk = bOk && ! IsNull( pCrvBez) ; + // recupero l'arco + const ICurveArc* pCrvArc = GetCurveArc( pGeomDB->GetGeoObj( nArcId)) ; + bOk = bOk && ( pCrvArc != nullptr) ; + // ne deduco la curva di Bezier + bOk = bOk && pCrvBez->FromArc( *pCrvArc) ; + // recupero il riferimento dell'arco + Frame3d frSou ; + bOk = bOk && pGeomDB->GetGlobFrame( nArcId, frSou) ; + // recupero il riferimento del gruppo destinazione + Frame3d frDest ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frDest) ; + // porto la curva di Bezier dal riferimento dell'arco a quello di inserimento + if ( bOk && ! AreSameFrame( frSou, frDest)) + pCrvBez->LocToLoc( frSou, frDest) ; + // se curva nulla (ovvero ridotta a punto), errore + bOk = bOk && ! pCrvBez->IsAPoint() ; + // inserisco la curva nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvBez)) : GDB_ID_NULL) ; + if ( nId != GDB_ID_NULL) { + // se richiesto, cancello l'arco originale + if ( bErase) { + if ( ! pGeomDB->Erase( nArcId)) + return GDB_ID_NULL ; + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtCurveBezierFromArc(" + ToString( nParentId) + "," + + ToString( nArcId) + "," + + ( bErase ? "true" : "false") + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +MyCreateCurveCompo( int nParentId, const INTVECTOR& vIds, bool bErase) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo la curva composita + PtrOwner pCrvCompo( CreateCurveComposite()) ; + if ( IsNull( pCrvCompo)) + return GDB_ID_NULL ; + // recupero il riferimento del gruppo destinazione + Frame3d frDest ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frDest)) + return GDB_ID_NULL ; + // estrusione e spessore + Vector3d vtExtr = CalcExtrusion( pGeomDB, nParentId, RTY_GRID) ; + double dThick = 0 ; + // esecuzione + INTVECTOR::const_iterator Iter ; + for ( Iter = vIds.begin() ; Iter != vIds.end() ; ++Iter) { + // recupero la curva + int nIdCrv = *Iter ; + const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nIdCrv)) ; + if ( pCrv == nullptr) + return GDB_ID_NULL ; + // recupero il riferimento della curva + Frame3d frSou ; + if ( ! pGeomDB->GetGlobFrame( nIdCrv, frSou)) + return GDB_ID_NULL ; + // creo una copia della curva + PtrOwner pCopCrv( pCrv->Clone()) ; + if ( IsNull( pCopCrv)) + return GDB_ID_NULL ; + // se i riferimenti sono diversi, eseguo la trasformazione + if ( ! AreSameFrame( frSou, frDest)) + pCopCrv->LocToLoc( frSou, frDest) ; + // recupero eventuali estrusione (già nel riferimento destinazione) e spessore + Vector3d vtTemp ; + if ( pCopCrv->GetExtrusion( vtTemp)) { + vtExtr = vtTemp ; + double dTemp ; + if ( pCopCrv->GetThickness( dTemp) && fabs( dTemp) > fabs( dThick)) + dThick = dTemp ; + } + // aggiungo alla composita + if ( ! pCrvCompo->AddCurve( Release( pCopCrv))) + return GDB_ID_NULL ; + } + // imposto estrusione e spessore + pCrvCompo->SetExtrusion( vtExtr) ; + pCrvCompo->SetThickness( dThick) ; + // inserisco la curva composita nel DB + int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) ; + ExeSetModified() ; + // se ok e richiesto, cancello le curve originali + if ( nId != GDB_ID_NULL && bErase) { + for ( Iter = vIds.begin() ; Iter != vIds.end() ; ++Iter) { + if ( ! pGeomDB->Erase( *Iter)) + return GDB_ID_NULL ; + } + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveCompo( int nParentId, const INTVECTOR& vIds, bool bErase) +{ + // eseguo + int nId = MyCreateCurveCompo( nParentId, vIds, bErase) ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtCurveCompo(" + ToString( nParentId) + ",{" + + IdListToString( vIds) + "}," + + ( bErase ? "true" : "false") + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +static int +MyCreateCurveCompoByChain( int nParentId, const INTVECTOR& vIds, + const Point3d& ptNear, bool bErase, int nRefType, int* pnCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // creo la curva composita + PtrOwner pCrvCompo( CreateCurveComposite()) ; + if ( IsNull( pCrvCompo)) + return GDB_ID_NULL ; + // recupero il riferimento del gruppo destinazione + Frame3d frDest ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frDest)) + return GDB_ID_NULL ; + // preparo i dati per il concatenamento + double dToler = 10 * EPS_SMALL ; + ChainCurves chainC ; + chainC.Init( true, dToler, int( vIds.size())) ; + 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) { + // recupero la curva e il suo riferimento + ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCrv == nullptr) + return GDB_ID_NULL ; + Frame3d frCrv ; + if ( ! pGeomDB->GetGlobFrame( nId, frCrv)) + return GDB_ID_NULL ; + // recupero i dati della curva necessari al concatenamento e li assegno + Point3d ptStart, ptEnd ; + Vector3d vtStart, vtEnd ; + if ( ! pCrv->GetStartPoint( ptStart) || ! pCrv->GetStartDir( vtStart) || + ! pCrv->GetEndPoint( ptEnd) || ! pCrv->GetEndDir( vtEnd)) + return GDB_ID_NULL ; + ptStart.LocToLoc( frCrv, frDest) ; + vtStart.LocToLoc( frCrv, frDest) ; + ptEnd.LocToLoc( frCrv, frDest) ; + vtEnd.LocToLoc( frCrv, frDest) ; + if ( ! chainC.AddCurve( nId, ptStart, vtStart, ptEnd, vtEnd)) + return GDB_ID_NULL ; + // passo al successivo + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + // recupero i percorsi concatenati + int nFirstId = GDB_ID_NULL ; + int nCount = 0 ; + Point3d ptNearL = GetPointLocal( pGeomDB, ptNear, nRefType, frDest) ; + INTVECTOR vId2s ; + while ( chainC.GetChainFromNear( ptNearL, false, vId2s)) { + // creo una curva composita + PtrOwner pCrvCompo( CreateCurveComposite()) ; + if ( IsNull( pCrvCompo)) + return GDB_ID_NULL ; + // estrusione e spessore + Vector3d vtExtr = CalcExtrusion( pGeomDB, nParentId, nRefType) ; + double dThick = 0 ; + // recupero le curve semplici e le inserisco nella curva composita + for ( size_t i = 0 ; i < vId2s.size() ; ++ i) { + int nId = abs( vId2s[i]) ; + bool bInvert = ( vId2s[i] < 0) ; + // recupero la curva e il suo riferimento + ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCrv == nullptr) + return GDB_ID_NULL ; + Frame3d frCrv ; + if ( ! pGeomDB->GetGlobFrame( nId, frCrv)) + return GDB_ID_NULL ; + // copio la curva + PtrOwner pCopCrv( pCrv->Clone()) ; + if ( IsNull( pCopCrv)) + return GDB_ID_NULL ; + // se necessario, la inverto + if ( bInvert) + pCopCrv->Invert() ; + // la sistemo per i riferimenti + pCopCrv->LocToLoc( frCrv, frDest) ; + // recupero eventuali estrusione (già nel riferimento destinazione) e spessore + Vector3d vtTemp ; + if ( pCopCrv->GetExtrusion( vtTemp)) { + vtExtr = vtTemp ; + double dTemp ; + if ( pCopCrv->GetThickness( dTemp) && fabs( dTemp) > fabs( dThick)) + dThick = dTemp ; + } + // la aggiungo alla curva composta + if ( ! pCrvCompo->AddCurve( ::Release( pCopCrv), true, dToler)) + return GDB_ID_NULL ; + } + // se non sono state inserite curve, vado oltre + if ( pCrvCompo->GetCurveNumber() == 0) + continue ; + // imposto estrusione e spessore + pCrvCompo->SetExtrusion( vtExtr) ; + pCrvCompo->SetThickness( dThick) ; + // aggiorno il nuovo punto vicino + pCrvCompo->GetEndPoint( ptNearL) ; + // inserisco la curva composita nel gruppo destinazione + int nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, ::Release( pCrvCompo)) ; + if ( nNewId == GDB_ID_NULL) + return GDB_ID_NULL ; + if ( nFirstId == GDB_ID_NULL) + nFirstId = nNewId ; + ++ nCount ; + } + // se richiesto e ok, cancello le curve originali + if ( bErase && nFirstId != GDB_ID_NULL) { + 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) { + pGeomDB->Erase( nId) ; + // passo al successivo + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetFirstSelectedObj()) ; + } + } + } + // restituisco l'identificativo della prima nuova entità + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveCompoByChain( int nParentId, const INTVECTOR& vIds, + const Point3d& ptNear, bool bErase, int nRefType, int* pnCount) +{ + // eseguo + int nCount = 0 ; + int nFirstId = MyCreateCurveCompoByChain( nParentId, vIds, ptNear, bErase, nRefType, &nCount) ; + if ( pnCount != nullptr) + *pnCount = nCount ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtCurveCompoByChain(" + ToString( nParentId) + ",{" + + IdListToString( vIds) + "},{" + + ToString( ptNear) + "}," + + ( bErase ? "true" : "false") + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della prima nuova entità + return nFirstId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveCompoFromPoints( int nParentId, const PolyLine& PL, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento del gruppo destinazione + Frame3d frDest ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frDest) ; + // creo la curva composita + PtrOwner pCrvCompo( CreateCurveComposite()) ; + bOk = bOk && ! IsNull( pCrvCompo) ; + // inserisco i segmenti che uniscono i punti + bOk = bOk && pCrvCompo->FromPolyLine( PL) ; + // assegno il versore estrusione + bOk = bOk && pCrvCompo->SetExtrusion( Z_AX) ; + // eventuale trasformazione per riferimento di espressione dei punti + if ( bOk && nRefType == RTY_GLOB) + pCrvCompo->ToLoc( frDest) ; + else if ( bOk && nRefType == RTY_GRID) + pCrvCompo->LocToLoc( pGeomDB->GetGridFrame(), frDest) ; + // inserisco la curva composita nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sPnt ; + Point3d ptP ; + if ( PL.GetFirstPoint( ptP)) + sPnt += "{" + ToString( ptP) + "}" ; + while ( PL.GetNextPoint( ptP)) + sPnt += ",{" + ToString( ptP) + "}" ; + string sLua = "EgtCurveCompoFromPoints(" + ToString( nParentId) + ",{" + + sPnt + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveCompoFromPointBulges( int nParentId, const PolyArc& PA, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento del gruppo destinazione + Frame3d frDest ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frDest) ; + // creo la curva composita + PtrOwner pCrvCompo( CreateCurveComposite()) ; + bOk = bOk && ! IsNull( pCrvCompo) ; + // inserisco i segmenti e gli archi che uniscono i punti + bOk = bOk && pCrvCompo->FromPolyArc( PA) ; + // assegno il versore estrusione + bOk = bOk && pCrvCompo->SetExtrusion( Z_AX) ; + // eventuale trasformazione per riferimento di espressione dei punti + if ( bOk && nRefType == RTY_GLOB) + pCrvCompo->ToLoc( frDest) ; + else if ( bOk && nRefType == RTY_GRID) + pCrvCompo->LocToLoc( pGeomDB->GetGridFrame(), frDest) ; + // inserisco la curva composita nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sPnt ; + double dB ; + Point3d ptP ; + if ( PA.GetFirstPoint( ptP, dB)) + sPnt += "{" + ToString( ptP) + "," + ToString( dB) + "}" ; + while ( PA.GetNextPoint( ptP, dB)) + sPnt += ",{" + ToString( ptP) + "," + ToString( dB) + "}" ; + string sLua = "EgtCurveCompoFromPointBulges(" + ToString( nParentId) + ",{" + + sPnt + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateCurveCompoByApprox( int nParentId, int nSouId, bool bArcsVsLines, double dLinTol) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento di inserimento + Frame3d frEnt ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frEnt) ; + // recupero la curva in locale + CurveLocal CrvLoc( pGeomDB, nSouId, frEnt) ; + bOk = bOk && ( CrvLoc.Get() != nullptr) ; + // eseguo l'approssimazione + PtrOwner pCC( CreateCurveComposite()) ; + bOk = bOk && ! IsNull( pCC) ; + const double ANG_TOL_STD_DEG = 15 ; + if ( ! bArcsVsLines) { // con linee + PolyLine PL ; + bOk = bOk && CrvLoc.Get()->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, PL) && pCC->FromPolyLine( PL) ; + } + else { // con bi-archi + PolyArc PA ; + bOk = bOk && CrvLoc.Get()->ApproxWithArcs( dLinTol, ANG_TOL_STD_DEG, PA) && pCC->FromPolyArc( PA) ; + } + // copio estrusione e spessore della curva sorgente + const ICurve* pSouCrv = GetCurve( pGeomDB->GetGeoObj( nSouId)) ; + if ( bOk && pSouCrv != nullptr) { + // recupero estrusione e spessore + Vector3d vtExtr ; + pSouCrv->GetExtrusion( vtExtr) ; + double dThick ; + pSouCrv->GetThickness( dThick) ; + // sistemo per eventuale cambio di riferimento + Frame3d frSou ; + bOk = bOk && pGeomDB->GetGlobFrame( nSouId, frSou) ; + vtExtr.LocToLoc( frSou, frEnt) ; + // assegno + pCC->SetExtrusion( vtExtr) ; + pCC->SetThickness( dThick) ; + } + // inserisco la curva composita nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCC)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtCurveCompoByApprox(" + ToString( nParentId) + "," + + ToString( nSouId) + "," + + ( bArcsVsLines ? "GDB_CA.ARCS" : "GDB_CA.LINES") + "," + + ToString( dLinTol) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateRectangle3P( int nParentId, const Point3d& ptIni, + const Point3d& ptCross, const Point3d& ptDir, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc)) + return GDB_ID_NULL ; + // porto in locale i punti, i versori e il versore estrusione + Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ; + Point3d ptCrossL = GetPointLocal( pGeomDB, ptCross, nRefType, frLoc) ; + Point3d ptDirL = GetPointLocal( pGeomDB, ptDir, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // calcolo il lato X + Vector3d vtDirX = ptDirL - ptIniL ; + bOk = bOk && vtDirX.Normalize() ; + Vector3d vtLatoX = bOk ? (( ptCrossL - ptIniL) * vtDirX) * vtDirX : V_NULL ; + // creo la polilinea con i punti + int nId = GDB_ID_NULL ; + if ( bOk) { + PolyLine PL ; + PL.AddUPoint( 0, ptIniL) ; + PL.AddUPoint( 1, Point3d( ptIniL) + vtLatoX) ; + PL.AddUPoint( 2, ptCrossL) ; + PL.AddUPoint( 3, Point3d( ptCrossL) - vtLatoX) ; + PL.AddUPoint( 4, ptIniL) ; + // disabilito log dei comandi e salvo stato precedente + bool bPrevCmdLog = SetCmdLog( false) ; + // creo la curva e la inserisco nel GDB + nId = ExeCreateCurveCompoFromPoints( nParentId, PL, RTY_LOC) ; + // ripristino precedente stato dei comandi + SetCmdLog( bPrevCmdLog) ; + // ne sistemo il vettore estrusione + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve != nullptr) + pCurve->SetExtrusion( vtExtrL) ; + } + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtRectangle3P(" + ToString( nParentId) + ",{" + + ToString( ptIni) + "},{" + + ToString( ptCross) + "},{" + + ToString( ptDir) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreatePolygonFromRadius( int nParentId, int nNumSides, const Point3d& ptCen, + const Point3d& ptCorn, const Vector3d& vtN, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc)) + return GDB_ID_NULL ; + // porto in locale i punti, la normale e il versore estrusione + Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ; + Point3d ptCornL = GetPointLocal( pGeomDB, ptCorn, nRefType, frLoc) ; + Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // creo la curva composita + PtrOwner pCrvCompo( CreateCurveComposite()) ; + bOk = bOk && ! IsNull( pCrvCompo) ; + // setto la curva + bOk = bOk && pCrvCompo->PolygonCenterCorner( nNumSides, ptCenL, ptCornL, vtNL) ; + // assegno il versore estrusione + bOk = bOk && pCrvCompo->SetExtrusion( vtExtrL) ; + // inserisco la curva nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtPolygonFromRadius(" + ToString( nParentId) + "," + + ToString( nNumSides) + ",{" + + ToString( ptCen) + "},{" + + ToString( ptCorn) + "},{" + + ToString( vtN) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreatePolygonFromApothem( int nParentId, int nNumSides, const Point3d& ptCen, + const Point3d& ptMid, const Vector3d& vtN, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc)) + return GDB_ID_NULL ; + // porto in locale i punti, la normale e il versore estrusione + Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ; + Point3d ptMidL = GetPointLocal( pGeomDB, ptMid, nRefType, frLoc) ; + Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // creo la curva composita + PtrOwner pCrvCompo( CreateCurveComposite()) ; + bOk = bOk && ! IsNull( pCrvCompo) ; + // setto la curva + bOk = bOk && pCrvCompo->PolygonCenterMidSide( nNumSides, ptCenL, ptMidL, vtNL) ; + // assegno il versore estrusione + bOk = bOk && pCrvCompo->SetExtrusion( vtExtrL) ; + // inserisco la curva nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtPolygonFromApothem(" + ToString( nParentId) + "," + + ToString( nNumSides) + ",{" + + ToString( ptCen) + "},{" + + ToString( ptMid) + "},{" + + ToString( vtN) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreatePolygonFromSide( int nParentId, int nNumSides, const Point3d& ptIni, + const Point3d& ptFin, const Vector3d& vtN, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc)) + return GDB_ID_NULL ; + // porto in locale i punti, la normale e il versore estrusione + Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ; + Point3d ptFinL = GetPointLocal( pGeomDB, ptFin, nRefType, frLoc) ; + Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ; + Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ; + // creo la curva composita + PtrOwner pCrvCompo( CreateCurveComposite()) ; + bOk = bOk && ! IsNull( pCrvCompo) ; + // setto la curva + bOk = bOk && pCrvCompo->PolygonSide( nNumSides, ptIniL, ptFinL, vtNL) ; + // assegno il versore estrusione + bOk = bOk && pCrvCompo->SetExtrusion( vtExtrL) ; + // inserisco la curva nel DB + int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtPolygonFromSide(" + ToString( nParentId) + "," + + ToString( nNumSides) + ",{" + + ToString( ptIni) + "},{" + + ToString( ptFin) + "},{" + + ToString( vtN) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nId ; +} + +//------------------------------------------------------------------------------- +Vector3d +CalcExtrusion( IGeomDB* pGeomDB, int nParentId, int nRefType) +{ + // verifica sul parametro + if ( pGeomDB == nullptr) + return Z_AX ; + // riferimento dell'entità + Frame3d frEnt ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frEnt)) + return false ; + // versore estrusione + Vector3d vtExtr = Z_AX ; + if ( nRefType == RTY_GLOB) + vtExtr.ToLoc( frEnt) ; + else if ( nRefType == RTY_GRID) + vtExtr.LocToLoc( pGeomDB->GetGridFrame(), frEnt) ; + return vtExtr ; +} diff --git a/EXE_GdbCreateSurf.cpp b/EXE_GdbCreateSurf.cpp new file mode 100644 index 0000000..addffb5 --- /dev/null +++ b/EXE_GdbCreateSurf.cpp @@ -0,0 +1,757 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : EXE_GdbCreateSurf.cpp Data : 04.05.15 Versione : 1.6e1 +// Contenuto : Funzioni di creazione superfici del DB geometrico per EXE. +// +// +// +// Modifiche : 02.11.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "AuxTools.h" +#include "GeoTools.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkStmStandard.h" +#include "/EgtDev/Include/EGkStmFromCurves.h" +#include "/EgtDev/Include/EGkStmFromTriangleSoup.h" +#include "/EgtDev/Include/EgkStringUtils3d.h" +#include "/EgtDev/Include/EgkGeoPoint3d.h" +#include "/EgtDev/Include/EgkCurveLocal.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmBBox( int nParentId, const BBox3d& b3Box, int nRefType) +{ + // bounding box orientato come gli assi del riferimento + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero il riferimento locale + Frame3d frLoc ; + bool bOk = pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // ricavo i punti standard e le dimensioni + Point3d ptIni ; + double dWidth = 0, dLen = 0, dHeight = 0 ; + bOk = bOk && b3Box.GetMinDim( ptIni, dWidth, dLen, dHeight) ; + dWidth = max( dWidth, 10 * EPS_SMALL) ; + dLen = max( dLen, 10 * EPS_SMALL) ; + dHeight = max( dHeight, 10 * EPS_SMALL) ; + Point3d ptCross = ptIni + Vector3d( dWidth, dLen) ; + Point3d ptDir = ptIni + Vector3d( dWidth, 0) ; + // porto in locale i punti + Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ; + Point3d ptCrossL = GetPointLocal( pGeomDB, ptCross, nRefType, frLoc) ; + Point3d ptDirL = GetPointLocal( pGeomDB, ptDir, nRefType, frLoc) ; + // ne ricavo un riferimento intrinseco + Frame3d frBox ; + bOk = bOk && frBox.Set( ptIniL, ptDirL, ptCrossL) ; + // creo il box nel suo riferimento intrinseco + PtrOwner pSTM( GetSurfTriMeshBox( dWidth, dLen, dHeight)) ; + bOk = bOk && ! IsNull( pSTM) ; + // porto il box nel riferimento locale + bOk = bOk && pSTM->ToGlob( frBox) ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSTM)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmBBox(" + ToString( nParentId) + ",{{" + + ToString( b3Box.GetMin()) + "},{" + + ToString( b3Box.GetMax()) + "}}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmBox( int nParentId, const Point3d& ptIni, const Point3d& ptCross, + const Point3d& ptDir, double dHeight, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero il riferimento locale + Frame3d frLoc ; + bool bOk = pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale i punti + Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ; + Point3d ptCrossL = GetPointLocal( pGeomDB, ptCross, nRefType, frLoc) ; + Point3d ptDirL = GetPointLocal( pGeomDB, ptDir, nRefType, frLoc) ; + // ne ricavo un riferimento intrinseco + Frame3d frBox ; + bOk = bOk && frBox.Set( ptIniL, ptDirL, ptCrossL) ; + // ricavo le dimensioni della base + Point3d ptCrossI = ptCrossL ; + ptCrossI.ToLoc( frBox) ; + double dWidth = ptCrossI.x ; + double dLen = ptCrossI.y ; + // creo il box nel suo riferimento intrinseco + PtrOwner pSTM( GetSurfTriMeshBox( fabs( dWidth), dLen, dHeight)) ; + bOk = bOk && ! IsNull( pSTM) ; + // eventuale traslazione per larghezza negativa + if ( dWidth < 0) + pSTM->Translate( Vector3d( dWidth, 0, 0)) ; + // porto il box nel riferimento locale + bOk = bOk && pSTM->ToGlob( frBox) ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSTM)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmBox(" + ToString( nParentId) + ",{" + + ToString( ptIni) + "},{" + + ToString( ptCross) + "},{" + + ToString( ptDir) + "}," + + ToString( dHeight) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmPyramid( int nParentId, const Point3d& ptIni, const Point3d& ptCross, + const Point3d& ptDir, double dHeight, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc)) + return GDB_ID_NULL ; + // porto in locale i punti + Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ; + Point3d ptCrossL = GetPointLocal( pGeomDB, ptCross, nRefType, frLoc) ; + Point3d ptDirL = GetPointLocal( pGeomDB, ptDir, nRefType, frLoc) ; + // ne ricavo un riferimento intrinseco + Frame3d frBox ; + bOk = bOk && frBox.Set( ptIniL, ptDirL, ptCrossL) ; + // ricavo le dimensioni della base + Point3d ptCrossI = ptCrossL ; + ptCrossI.ToLoc( frBox) ; + double dWidth = ptCrossI.x ; + double dLen = ptCrossI.y ; + // creo la piramide nel suo riferimento intrinseco + PtrOwner pSTM( GetSurfTriMeshPyramid( fabs( dWidth), dLen, dHeight)) ; + bOk = bOk && ! IsNull( pSTM) ; + // eventuale traslazione per larghezza negativa + if ( dWidth < 0) + pSTM->Translate( Vector3d( dWidth, 0, 0)) ; + // porto la piramide nel riferimento locale + bOk = bOk && pSTM->ToGlob( frBox) ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSTM)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmPyramid(" + ToString( nParentId) + ",{" + + ToString( ptIni) + "},{" + + ToString( ptCross) + "},{" + + ToString( ptDir) + "}," + + ToString( dHeight) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmCylinder( int nParentId, const Point3d& ptOrig, const Vector3d& vtN, + double dRad, double dHeight, double dLinTol, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale il punto e il versore + Point3d ptOrigL = GetPointLocal( pGeomDB, ptOrig, nRefType, frLoc) ; + Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ; + // calcolo riferimento OCS a partire da questo punto e versore + Frame3d frCyl ; + bOk = bOk && frCyl.Set( ptOrigL, vtNL) ; + // creo il cilindro nel suo riferimento intrinseco + PtrOwner pSTM( GetSurfTriMeshCylinder( dRad, dHeight, dLinTol)) ; + bOk = bOk && ! IsNull( pSTM) ; + // porto il cilindro nel riferimento locale + bOk = bOk && pSTM->ToGlob( frCyl) ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSTM)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmCylinder(" + ToString( nParentId) + ",{" + + ToString( ptOrig) + "},{" + + ToString( vtN) + "}," + + ToString( dRad) + "," + + ToString( dHeight) + "," + + ToString( dLinTol) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmCone( int nParentId, const Point3d& ptOrig, const Vector3d& vtN, + double dRad, double dHeight, double dLinTol, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale il punto e il versore + Point3d ptOrigL = GetPointLocal( pGeomDB, ptOrig, nRefType, frLoc) ; + Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ; + // calcolo riferimento OCS a partire da questo punto e versore + Frame3d frCyl ; + bOk = bOk && frCyl.Set( ptOrigL, vtNL) ; + // creo il cono nel suo riferimento intrinseco + PtrOwner pSTM( GetSurfTriMeshCone( dRad, dHeight, dLinTol)) ; + bOk = bOk && ! IsNull( pSTM) ; + // porto il cono nel riferimento locale + bOk = bOk && pSTM->ToGlob( frCyl) ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSTM)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmCone(" + ToString( nParentId) + ",{" + + ToString( ptOrig) + "},{" + + ToString( vtN) + "}," + + ToString( dRad) + "," + + ToString( dHeight) + "," + + ToString( dLinTol) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmSphere( int nParentId, const Point3d& ptOrig, + double dRad, double dLinTol, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale il punto + Point3d ptOrigL = GetPointLocal( pGeomDB, ptOrig, nRefType, frLoc) ; + // creo la sfera + PtrOwner pSTM( GetSurfTriMeshSphere( dRad, dLinTol)) ; + bOk = bOk && ! IsNull( pSTM) ; + // porto la sfera nella sua origine + bOk = bOk && pSTM->Translate( ptOrig - ORIG) ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSTM)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmSphere(" + ToString( nParentId) + ",{" + + ToString( ptOrig) + "}," + + ToString( dRad) + "," + + ToString( dLinTol) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmByFlatContour( int nParentId, int nCrvId, double dLinTol) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // recupero la curva in locale + CurveLocal CrvLoc( pGeomDB, nCrvId, frLoc) ; + bOk = bOk && ( CrvLoc.Get() != nullptr) ; + // calcolo la superficie + ISurfTriMesh* pSTM = ( bOk ? GetSurfTriMeshByFlatContour( CrvLoc.Get(), dLinTol) : nullptr) ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSTM) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmByFlatContour(" + ToString( nParentId) + "," + + ToString( nCrvId) + "," + + ToString( dLinTol) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmByRegion( int nParentId, INTVECTOR& vCrvIds, double dLinTol) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // recupero le curve in locale + CURVELOCALVECTOR vCrvLoc ; + vCrvLoc.reserve( vCrvIds.size()) ; + ICURVEPVECTOR vCrvP ; + vCrvP.reserve( vCrvIds.size()) ; + for ( size_t i = 0 ; i < vCrvIds.size() ; ++ i) { + vCrvLoc.emplace_back( pGeomDB, vCrvIds[i], frLoc) ; + vCrvP.push_back( const_cast( vCrvLoc[i].Get())) ; + bOk = bOk && ( vCrvLoc[i].Get() != nullptr) ; + } + // calcolo la superficie + ISurfTriMesh* pSTM = ( bOk ? GetSurfTriMeshByRegion( vCrvP, dLinTol) : nullptr) ; + bOk = bOk && ( pSTM != nullptr) ; + // elimino punti ripetuti + bOk = bOk && pSTM->DoCompacting() ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSTM) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sIds ; + for ( size_t i = 0 ; i < vCrvIds.size() ; ++ i) + sIds += ToString( vCrvIds[i]) + "," ; + sIds.pop_back() ; + string sLua = "EgtSurfTmByRegion(" + ToString( nParentId) + ",{" + + sIds + "}," + + ToString( dLinTol) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmByExtrusion( int nParentId, INTVECTOR& vCrvIds, const Vector3d& vtExtr, + double dLinTol, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // recupero le curve in locale + CURVELOCALVECTOR vCrvLoc ; + vCrvLoc.reserve( vCrvIds.size()) ; + ICURVEPVECTOR vCrvP ; + vCrvP.reserve( vCrvIds.size()) ; + for ( size_t i = 0 ; i < vCrvIds.size() ; ++ i) { + vCrvLoc.emplace_back( pGeomDB, vCrvIds[i], frLoc) ; + vCrvP.push_back( const_cast( vCrvLoc[i].Get())) ; + bOk = bOk && ( vCrvLoc[i].Get() != nullptr) ; + } + // porto in locale il vettore estrusione + Vector3d vtExtrL = GetVectorLocal( pGeomDB, vtExtr, nRefType, frLoc) ; + // creo le superfici e le inserisco nel DB + int nFirstId = GDB_ID_NULL ; + for ( int i = 0 ; i < int( vCrvP.size()) ; ++ i) { + // calcolo la superficie + ISurfTriMesh* pSTM = ( bOk ? GetSurfTriMeshByExtrusion( vCrvP[i], vtExtrL, false, dLinTol) : nullptr) ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSTM) : GDB_ID_NULL) ; + bOk = bOk && ( nNewId != GDB_ID_NULL) ; + if ( bOk && nFirstId == GDB_ID_NULL) + nFirstId = nNewId ; + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sIds ; + for ( size_t i = 0 ; i < vCrvIds.size() ; ++ i) + sIds += ToString( vCrvIds[i]) + "," ; + sIds.pop_back() ; + string sLua = "EgtSurfTmByExtrusion(" + ToString( nParentId) + ",{" + + sIds + "},{" + + ToString( vtExtr) + "}," + + ToString( dLinTol) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nFirstId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nFirstId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmByRegionExtrusion( int nParentId, INTVECTOR& vCrvIds, const Vector3d& vtExtr, + double dLinTol, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // recupero le curve in locale + CURVELOCALVECTOR vCrvLoc ; + vCrvLoc.reserve( vCrvIds.size()) ; + ICURVEPVECTOR vCrvP ; + vCrvP.reserve( vCrvIds.size()) ; + for ( size_t i = 0 ; i < vCrvIds.size() ; ++ i) { + vCrvLoc.emplace_back( pGeomDB, vCrvIds[i], frLoc) ; + vCrvP.push_back( const_cast( vCrvLoc[i].Get())) ; + bOk = bOk && ( vCrvLoc[i].Get() != nullptr) ; + } + // porto in locale il vettore estrusione + Vector3d vtExtrL = GetVectorLocal( pGeomDB, vtExtr, nRefType, frLoc) ; + int nNewId = GDB_ID_NULL ; + // creo la superficie + ISurfTriMesh* pSTM = ( bOk ? GetSurfTriMeshByRegionExtrusion( vCrvP, vtExtrL, dLinTol) : nullptr) ; + // inserisco la superficie nel DB + nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSTM) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sIds ; + for ( size_t i = 0 ; i < vCrvIds.size() ; ++ i) + sIds += ToString( vCrvIds[i]) + "," ; + sIds.pop_back() ; + string sLua = "EgtSurfTmByRegionExtrusion(" + ToString( nParentId) + ",{" + + sIds + "},{" + + ToString( vtExtr) + "}," + + ToString( dLinTol) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmByRevolve( int nParentId, int nCrvId, + const Point3d& ptAx, const Vector3d& vtAx, + bool bCapEnds, double dLinTol, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // recupero la curva in locale + CurveLocal CrvLoc( pGeomDB, nCrvId, frLoc) ; + bOk = bOk && ( CrvLoc.Get() != nullptr) ; + // porto in locale punto e vettore asse + Point3d ptAxL = GetPointLocal( pGeomDB, ptAx, nRefType, frLoc) ; + Vector3d vtAxL = GetVectorLocal( pGeomDB, vtAx, nRefType, frLoc) ; + // calcolo la superficie + ISurfTriMesh* pSTM = ( bOk ? GetSurfTriMeshByRevolve( CrvLoc.Get(), ptAxL, vtAxL, bCapEnds, dLinTol) : nullptr) ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSTM) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmByRevolve(" + ToString( nParentId) + "," + + ToString( nCrvId) + ",{" + + ToString( ptAx) + "},{" + + ToString( vtAx) + "}," + + ( bCapEnds ? "true" : "false") + "," + + ToString( dLinTol) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmByScrewing( int nParentId, int nCrvId, + const Point3d& ptAx, const Vector3d& vtAx, + double dAngRotDeg, double dMove, double dLinTol, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // recupero la curva in locale + CurveLocal CrvLoc( pGeomDB, nCrvId, frLoc) ; + bOk = bOk && ( CrvLoc.Get() != nullptr) ; + // porto in locale punto e vettore asse + Point3d ptAxL = GetPointLocal( pGeomDB, ptAx, nRefType, frLoc) ; + Vector3d vtAxL = GetVectorLocal( pGeomDB, vtAx, nRefType, frLoc) ; + // calcolo la superficie + ISurfTriMesh* pSTM = ( bOk ? GetSurfTriMeshByScrewing( CrvLoc.Get(), ptAxL, vtAxL, dAngRotDeg, dMove, dLinTol) : nullptr) ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSTM) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmByScrewing(" + ToString( nParentId) + "," + + ToString( nCrvId) + ",{" + + ToString( ptAx) + "},{" + + ToString( vtAx) + "}," + + ToString( dAngRotDeg) + "," + + ToString( dMove) + "," + + ToString( dLinTol) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmRuled( int nParentId, int nPtOrCrvId1, int nPtOrCrvId2, double dLinTol) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + bool bOk = true ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // creo la superficie trimesh + ISurfTriMesh* pSTM = nullptr ; + // se la prima entità è un punto e la seconda una curva + if ( pGeomDB->GetGeoType( nPtOrCrvId1) == GEO_PNT3D && + ( pGeomDB->GetGeoType( nPtOrCrvId2) & GEO_CURVE) != 0) { + // recupero il punto in locale + // recupero riferimento del punto + Frame3d frPnt ; + bOk = bOk && pGeomDB->GetGlobFrame( nPtOrCrvId1, frPnt) ; + // porto il punto in locale + Point3d ptP = GetGeoPoint3d( pGeomDB->GetGeoObj( nPtOrCrvId1))->GetPoint() ; + bOk = bOk && ptP.LocToLoc( frPnt, frLoc) ; + // recupero la curva in locale + CurveLocal CrvLoc( pGeomDB, nPtOrCrvId2, frLoc) ; + bOk = bOk && ( CrvLoc.Get() != nullptr) ; + // calcolo la superficie + pSTM = ( bOk ? GetSurfTriMeshRuled( ptP, CrvLoc.Get(), dLinTol) : nullptr) ; + } + // se la prima entità è una curva e la seconda un punto + else if ( ( pGeomDB->GetGeoType( nPtOrCrvId1) & GEO_CURVE) != 0 && + pGeomDB->GetGeoType( nPtOrCrvId2) == GEO_PNT3D) { + // recupero la curva in locale + CurveLocal CrvLoc( pGeomDB, nPtOrCrvId1, frLoc) ; + bOk = bOk && ( CrvLoc.Get() != nullptr) ; + // recupero il punto in locale + // recupero riferimento del punto + Frame3d frPnt ; + bOk = bOk && pGeomDB->GetGlobFrame( nPtOrCrvId2, frPnt) ; + // porto il punto in locale + Point3d ptP = GetGeoPoint3d( pGeomDB->GetGeoObj( nPtOrCrvId2))->GetPoint() ; + bOk = bOk && ptP.LocToLoc( frPnt, frLoc) ; + // calcolo la superficie + pSTM = ( bOk ? GetSurfTriMeshRuled( ptP, CrvLoc.Get(), dLinTol) : nullptr) ; + } + // se entrambe curve + else if ( ( pGeomDB->GetGeoType( nPtOrCrvId1) & GEO_CURVE) != 0 && + ( pGeomDB->GetGeoType( nPtOrCrvId2) & GEO_CURVE) != 0) { + // recupero la prima curva in locale + CurveLocal CrvLoc1( pGeomDB, nPtOrCrvId1, frLoc) ; + bOk = bOk && ( CrvLoc1.Get() != nullptr) ; + // recupero la seconda curva in locale + CurveLocal CrvLoc2( pGeomDB, nPtOrCrvId2, frLoc) ; + bOk = bOk && ( CrvLoc2.Get() != nullptr) ; + // calcolo la superficie + pSTM = ( bOk ? GetSurfTriMeshRuled( CrvLoc1.Get(), CrvLoc2.Get(), dLinTol) : nullptr) ; + } + // altrimenti errore + else + bOk = false ; + // inserisco la superficie trimesh nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSTM) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmRuled(" + ToString( nParentId) + "," + + ToString( nPtOrCrvId1) + "," + + ToString( nPtOrCrvId2) + "," + + ToString( dLinTol) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//---------------------------------------------------------------------------- +int +ExeCreateSurfTmByTriangles( int nParentId, const INTVECTOR& vIds, bool bErase) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // almeno un oggetto nell'elenco + bool bOk = ( vIds.size() > 0) ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // Costruttore di trimesh da insieme disordinato di triangoli + StmFromTriangleSoup StmFts ; + bOk = bOk && StmFts.Start() ; + // Recupero tutti i triangoli delle superfici sorgenti e li inserisco nella nuova + 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) { + // recupero la superficie sorgente + const ISurfTriMesh* pStmS = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + bOk = bOk && ( pStmS != nullptr) ; + // recupero il riferimento della superficie sorgente + Frame3d frSou ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frSou) ; + // recupero tutti i triangoli + Triangle3d Tria ; + int nT = ( bOk ? pStmS->GetFirstTriangle( Tria) : SVT_NULL) ; + while ( nT != SVT_NULL) { + // aggiusto per i sistemi di riferimento + Tria.LocToLoc( frSou, frLoc) ; + // inserisco il triangolo nella nuova superficie + if ( ! StmFts.AddTriangle( Tria)) + return false ; + // passo al triangolo successivo + nT = pStmS->GetNextTriangle( nT, Tria) ; + } + // passo al successivo + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + // valido la superficie e calcolo le adiacenze + bOk = bOk && StmFts.End() ; + // inserisco la superficie trimesh nel DB + PtrOwner pStm( StmFts.GetSurf()) ; + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pStm)) : GDB_ID_NULL) ; + // se richiesto, cancello le superfici originali + if ( nNewId != GDB_ID_NULL && bErase) { + 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) { + pGeomDB->Erase( nId) ; + // passo al successivo + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetFirstSelectedObj()) ; + } + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmByTriangles(" + ToString( nParentId) + ",{" + + IdListToString( vIds) + "}," + + ( bErase ? "true" : "false") + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return nNewId ; +} + +//---------------------------------------------------------------------------- +int +ExeCreateSurfTmBySewing( int nParentId, const INTVECTOR& vIds, bool bErase) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // almeno un oggetto nell'elenco + bool bOk = ( vIds.size() > 0) ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // puntatore alla nuova superficie + PtrOwner pStm( CreateSurfTriMesh()) ; + bOk = bOk && ! IsNull( pStm) ; + // esecuzione + bool bFirst = true ; + for ( size_t i = 0 ; bOk && i < vIds.size() ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // recupero la superficie da cucire + const ISurfTriMesh* pStmS = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + bOk = bOk && ( pStmS != nullptr) ; + // recupero il riferimento + Frame3d frStmS ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frStmS) ; + // lo esprimo rispetto a quello della prima superficie + frStmS.ToLoc( frLoc) ; + // se è la prima, copio + if ( bFirst) { + bOk = bOk && pStm->CopyFrom( pStmS) ; + bOk = bOk && pStm->ToGlob( frStmS) ; + bFirst = false ; + } + // altrimenti eseguo la cucitura + else + bOk = bOk && pStm->DoSewing( *pStmS, frStmS) ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + // compatto + bOk = bOk && pStm->DoCompacting() ; + // inserisco la superficie trimesh nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pStm)) : GDB_ID_NULL) ; + // se richiesto, cancello le superfici originali + if ( nNewId != GDB_ID_NULL && bErase) { + 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) { + pGeomDB->Erase( nId) ; + // passo al successivo + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetFirstSelectedObj()) ; + } + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmBySewing(" + ToString( nParentId) + ",{" + + IdListToString( vIds) + "}," + + ( bErase ? "true" : "false") + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return nNewId ; +} diff --git a/EXE_GdbModify.cpp b/EXE_GdbModify.cpp new file mode 100644 index 0000000..381add6 --- /dev/null +++ b/EXE_GdbModify.cpp @@ -0,0 +1,252 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : API_GdbModify.cpp Data : 06.10.14 Versione : 1.5i5 +// Contenuto : Funzioni di modifica geometrica per API. +// +// +// +// Modifiche : 06.10.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "AuxTools.h" +#include "GeoTools.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EgkGeoPoint3d.h" +#include "/EgtDev/Include/EgkGeoVector3d.h" +#include "/EgtDev/Include/EgkExtText.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +bool +ExeChangeGroupFrame( int nId, const Frame3d& frNewRef, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // recupero il riferimento del gruppo + Frame3d* pFrame = pGeomDB->GetGroupFrame( nId) ; + bOk = bOk && ( pFrame != nullptr) ; + // porto il nuovo riferimento in locale + Frame3d frNewL = frNewRef ; + if ( nRefType != RTY_LOC) { + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ; + if ( nRefType == RTY_GLOB) + frNewL.ToLoc( frLoc) ; + else /* RTY_GRID */ + frNewL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ; + } + // aggiorno il gruppo + if ( bOk) + *pFrame = frNewL ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtChangeGroupFrame(" + ToString( nId) + ",{{" + + ToString( frNewRef.Orig()) + "},{" + + ToString( frNewRef.VersX()) + "},{" + + ToString( frNewRef.VersY()) + "},{" + + ToString( frNewRef.VersZ()) + "}}," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//------------------------------------------------------------------------------- +bool +ExeChangeVectorBase( int nId, const Point3d& ptB, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // recupero il vettore + IGeoVector3d* pGVect = GetGeoVector3d( pGeomDB->GetGeoObj( nId)) ; + bOk = bOk && ( pGVect != nullptr) ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ; + // porto il nuovo punto base in locale + Point3d ptBL = GetPointLocal( pGeomDB, ptB, nRefType, frLoc) ; + // imposto il nuovo punto di base + bOk = bOk && pGVect->ChangeBase( ptBL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtChangeVectorBase(" + ToString( nId) + ",{" + + ToString( ptB) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//------------------------------------------------------------------------------- +bool +ExeModifyText( int nId, const string& sNewText) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero il testo + IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ; + if ( pTXT == nullptr) + return false ; + // eseguo l'operazione + ExeSetModified() ; + return pTXT->ModifyText( sNewText) ; +} + +//------------------------------------------------------------------------------- +bool +ExeChangeTextFont( int nId, const string& sNewFont) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero il testo + IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ; + if ( pTXT == nullptr) + return false ; + // eseguo l'operazione + ExeSetModified() ; + return pTXT->ChangeFont( sNewFont) ; +} + +//------------------------------------------------------------------------------- +bool +ExeFlipText( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero il testo + IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ; + if ( pTXT == nullptr) + return false ; + // eseguo l'operazione + ExeSetModified() ; + return pTXT->Flip() ; +} + +//------------------------------------------------------------------------------- +bool +ExeMirrorText( int nId, bool bOnL) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero il testo + IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ; + if ( pTXT == nullptr) + return false ; + // eseguo l'operazione + ExeSetModified() ; + return pTXT->Mir( bOnL) ; +} + +//------------------------------------------------------------------------------- +int +ExeExplodeText( int nId, int* pnCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero il testo + IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pTXT != nullptr) ; + // recupero l'outline del testo + ICURVEPLIST lstPCRV ; + bOk = bOk && pTXT->GetOutline( lstPCRV) ; + // inserisco le curve nella stessa posizione del testo + int nFirstId = GDB_ID_NULL ; + int nCount = 0 ; + for ( ICURVEPLIST::iterator iIter = lstPCRV.begin() ; iIter != lstPCRV.end() ; ++ iIter) { + // inserisco la curva nello stesso gruppo e nello stesso posto del GeomDB + int nCrvId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_BEFORE, (*iIter)) ; + bOk = bOk && ( nCrvId != GDB_ID_NULL) ; + // copio gli attributi + bOk = bOk && pGeomDB->CopyAttributes( nId, nCrvId) ; + // aggiorno contatori + if ( bOk) { + if ( nFirstId == GDB_ID_NULL) + nFirstId = nCrvId ; + ++ nCount ; + } + } + nFirstId = ( bOk ? nFirstId : GDB_ID_NULL) ; + // elimino il testo originale + bOk = bOk && pGeomDB->Erase( nId) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtExplodeText(" + ToString( nId) + ")" + + " -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultati + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; +} + +//------------------------------------------------------------------------------- +int +ExeSplitText( int nId, int* pnCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero il testo + IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pTXT != nullptr) ; + // recupero l'esplosione del testo in linee singole + IEXTTEXTPVECTOR vTxt ; + bOk = bOk && pTXT->SplitOnLineBreak( vTxt) ; + // inserisco i nuovi testi nella stessa posizione del testo + int nFirstId = GDB_ID_NULL ; + int nCount = 0 ; + for ( int i = 0 ; i < int( vTxt.size()) ; ++ i) { + // inserimento + int nCrvId = ( bOk ? pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_BEFORE, vTxt[i]) : GDB_ID_NULL) ; + if ( nCrvId != GDB_ID_NULL) { + // copio gli attributi + bOk = bOk && pGeomDB->CopyAttributes( nId, nCrvId) ; + // aggiorno contatori + if ( bOk) { + if ( nFirstId == GDB_ID_NULL) + nFirstId = nCrvId ; + ++ nCount ; + } + } + else { + bOk = false ; + delete vTxt[i] ; + } + } + nFirstId = ( bOk ? nFirstId : GDB_ID_NULL) ; + // elimino il testo originale + bOk = bOk && pGeomDB->Erase( nId) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSplitText(" + ToString( nId) + ")" + + " -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultati + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; +} diff --git a/EXE_GdbModifyCurve.cpp b/EXE_GdbModifyCurve.cpp new file mode 100644 index 0000000..42a114a --- /dev/null +++ b/EXE_GdbModifyCurve.cpp @@ -0,0 +1,822 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : API_ModifyCurve.cpp Data : 03.10.14 Versione : 1.5i5 +// Contenuto : Funzioni di modifica delle curve per API. +// +// +// +// Modifiche : 03.10.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "AuxTools.h" +#include "GeoTools.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkCurve.h" +#include "/EgtDev/Include/EGkCurveArc.h" +#include "/EgtDev/Include/EGkCurveBezier.h" +#include "/EgtDev/Include/EGkCurveComposite.h" +#include "/EgtDev/Include/EGkDistPointCurve.h" +#include "/EgtDev/Include/EGkExtTExt.h" +#include "/EgtDev/Include/EGkGdbIterator.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +bool +ExeInvertCurve( const INTVECTOR& vIds) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // eseguo inversione + bool bOk = true ; + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL && bOk) { + // recupero la curva e la inverto + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve != nullptr && ! pCurve->Invert()) + bOk = false ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtInvertCurve({" + IdListToString( vIds) + "})" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +ExeOffsetCurve( int nId, double dDist, int nType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + // eseguo l'offset + bool bOk = ( pCurve != nullptr) && pCurve->SimpleOffset( dDist, nType) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua ; + sLua = "EgtOffsetCurve(" + ToString( nId) + "," + + ToString( dDist) + "," + + OffsTypeToString( nType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +ExeChangeClosedCurveStartPoint( int nId, const Point3d& ptP, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + bOk = bOk && ( pCurve != nullptr) ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ; + // porto in locale il punto vicino ad iniziale + Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frLoc) ; + // recupero la posizione parametrica della proiezione di questo punto sulla curva + DistPointCurve distPC( ptPL, *pCurve) ; + double dPar ; + int nFlag ; + bOk = bOk && distPC.GetParamAtMinDistPoint( 0, dPar, nFlag) ; + // cambio il punto iniziale + if ( bOk && pCurve->GetType() == CRV_ARC) + bOk = bOk && dynamic_cast(pCurve)->ChangeStartPoint(dPar) ; + else if ( bOk && pCurve->GetType() == CRV_COMPO) + bOk = bOk && dynamic_cast(pCurve)->ChangeStartPoint(dPar) ; + else + bOk = false ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtChangeClosedCurveStartPoint(" + ToString( nId) + ",{" + + ToString( ptP) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +ExeModifyCurveStartPoint( int nId, const Point3d& ptP, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + bOk = bOk && ( pCurve != nullptr) ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ; + // porto in locale il nuovo punto iniziale + Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frLoc) ; + // ne modifico il punto iniziale + bOk = bOk && pCurve->ModifyStart( ptPL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtModifyCurveStartPoint(" + ToString( nId) + ",{" + + ToString( ptP) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +ExeModifyCurveEndPoint( int nId, const Point3d& ptP, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + bOk = bOk && ( pCurve != nullptr) ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ; + // porto in locale il nuovo punto finale + Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frLoc) ; + // ne modifico il punto finale + bOk = bOk && pCurve->ModifyEnd( ptPL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtModifyCurveEndPoint(" + ToString( nId) + ",{" + + ToString( ptP) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//---------------------------------------------------------------------------- +static bool +ModifyOneCurveExtrusion( IGeomDB* pGeomDB, int nId, const Vector3d& vtExtr, int nRefType) +{ + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( nId, frLoc) && + ! pGeomDB->GetGlobFrame( nId, frLoc)) + return false ; + // porto in locale il versore estrusione + Vector3d vtExtrL = GetVectorLocal( pGeomDB, vtExtr, nRefType, frLoc) ; + // se gruppo, agisco sulle sole curve componenti + if ( pGeomDB->GetGdbType( nId) == GDB_TY_GROUP) { + PtrOwner pIter( CreateGdbIterator( pGeomDB)) ; + if ( IsNull( pIter)) + return false ; + for ( bool bFound = pIter->GoToFirstInGroup( nId) ; + bFound ; + bFound = pIter->GoToNext()) { + // recupero la curva e ne modifico il vettore estrusione + ICurve* pCurve = GetCurve( pIter->GetGeoObj()) ; + if ( pCurve != nullptr && ! pCurve->SetExtrusion( vtExtrL)) + return false ; + } + return true ; + } + // se oggetto geometrico + else { + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + // ne modifico il vettore estrusione + return ( pCurve == nullptr || pCurve->SetExtrusion( vtExtrL)) ; + } +} + +//---------------------------------------------------------------------------- +bool +ExeModifyCurveExtrusion( const INTVECTOR& vIds, const Vector3d& vtExtr, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // se estrusione espressa in locale, verifico che tutte le curve siano nello stesso riferimento + if ( nRefType == RTY_LOC) + bOk = bOk && VerifySameFrame( pGeomDB, vIds) ; + // ciclo sul vettore degli identificativi + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + // impostazione estrusione singola + if ( vIds[i] != GDB_ID_SEL) { + bOk = bOk && ModifyOneCurveExtrusion( pGeomDB, vIds[i], vtExtr, nRefType) ; + } + // impostazione estrusione dei selezionati + else { + int nI = pGeomDB->GetFirstSelectedObj() ; + while ( nI != GDB_ID_NULL && bOk) { + if ( ! ModifyOneCurveExtrusion( pGeomDB, nI, vtExtr, nRefType)) + bOk = false ; + // passo alla successiva + nI = pGeomDB->GetNextSelectedObj() ; + } + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtModifyCurveExtrusion({" + IdListToString( vIds) + "},{" + + ToString( Vector3d( vtExtr)) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//---------------------------------------------------------------------------- +static bool +ModifyOneCurveThickness( IGeomDB* pGeomDB, int nId, double dThick) +{ + // se gruppo, agisco sulle sole curve componenti + if ( pGeomDB->GetGdbType( nId) == GDB_TY_GROUP) { + PtrOwner pIter( CreateGdbIterator( pGeomDB)) ; + if ( IsNull( pIter)) + return false ; + bool bOk = true ; + for ( bool bFound = pIter->GoToFirstInGroup( nId) ; + bFound ; + bFound = pIter->GoToNext()) { + // recupero la curva e ne modifico lo spessore + ICurve* pCurve = GetCurve( pIter->GetGeoObj()) ; + if ( pCurve != nullptr && ! pCurve->SetThickness( dThick)) + bOk = false ; + } + return bOk ; + } + // se oggetto geometrico + else { + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + // ne modifico lo spessore, se curva + return ( pCurve == nullptr || pCurve->SetThickness( dThick)) ; + } +} + +//---------------------------------------------------------------------------- +bool +ExeModifyCurveThickness( const INTVECTOR& vIds, double dThick) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // ciclo sul vettore degli identificativi + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + // eseguo impostazione spessore singola + if ( vIds[i] != GDB_ID_SEL) { + bOk = bOk && ModifyOneCurveThickness( pGeomDB, vIds[i], dThick) ; + } + // eseguo impostazione spessore dei selezionati + else { + int nI = pGeomDB->GetFirstSelectedObj() ; + while ( nI != GDB_ID_NULL && bOk) { + if ( ! ModifyOneCurveThickness( pGeomDB, nI, dThick)) + bOk = false ; + // passo alla successiva + nI = pGeomDB->GetNextSelectedObj() ; + } + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtModifyCurveThickness({" + IdListToString( vIds) + "}," + + ToString( dThick) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +ExeTrimCurveStartAtLen( int nId, double dLen) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve == nullptr) + return false ; + // taglio la curva all'inizio + bool bOk = pCurve->TrimStartAtLen( dLen) ; + ExeSetModified() ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +ExeTrimCurveEndAtLen( int nId, double dLen) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve == nullptr) + return false ; + // taglio la curva alla fine + bool bOk = pCurve->TrimEndAtLen( dLen) ; + ExeSetModified() ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +ExeTrimCurveStartAtParam( int nId, double dPar) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve == nullptr) + return false ; + // taglio la curva all'inizio + bool bOk = pCurve->TrimStartAtParam( dPar) ; + ExeSetModified() ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +ExeTrimCurveEndAtParam( int nId, double dPar) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve == nullptr) + return false ; + // taglio la curva alla fine + bool bOk = pCurve->TrimEndAtParam( dPar) ; + ExeSetModified() ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +ExeTrimCurveStartEndAtParam( int nId, double dParS, double dParE) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve == nullptr) + return false ; + // taglio la curva agli estremi + bool bOk = pCurve->TrimStartEndAtParam( dParS, dParE) ; + ExeSetModified() ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +ExeExtendCurveStartByLen( int nId, double dLen) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve == nullptr) + return false ; + // estendo la curva all'inizio + bool bOk = pCurve->ExtendStartByLen( dLen) ; + ExeSetModified() ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +ExeExtendCurveEndByLen( int nId, double dLen) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve == nullptr) + return false ; + // estendo la curva alla fine + bool bOk = pCurve->ExtendEndByLen( dLen) ; + ExeSetModified() ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +ExeTrimExtendCurveByLen( int nId, double dLen, const Point3d& ptNear, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pCurve != nullptr) ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ; + // porto in locale il punto + Point3d ptNearL = GetPointLocal( pGeomDB, ptNear, nRefType, frLoc) ; + // cerco l'estremo più vicino al punto passato + Point3d ptStart, ptEnd ; + if ( bOk && pCurve->GetStartPoint( ptStart) && pCurve->GetEndPoint( ptEnd)) { + if ( SqDist( ptStart, ptNearL) < SqDist( ptEnd, ptNearL)) { + if ( dLen < - EPS_SMALL) + bOk = pCurve->TrimStartAtLen( - dLen) ; + else if ( dLen > EPS_SMALL) + bOk = pCurve->ExtendStartByLen( dLen) ; + } + else { + if ( dLen < - EPS_SMALL) { + double dCrvLen ; + bOk = pCurve->GetLength( dCrvLen) && pCurve->TrimEndAtLen( dCrvLen + dLen) ; + } + else if ( dLen > EPS_SMALL) + bOk = pCurve->ExtendEndByLen( dLen) ; + } + } + else + bOk = false ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTrimExtendCurveByLen(" + ToString( nId) + "," + + ToString( dLen) + ",{" + + ToString( ptNear) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//---------------------------------------------------------------------------- +int +ExeSplitCurve( int nId, int nParts) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pCurve != nullptr) ; + // il numero di parti non può essere inferiore a 1 + nParts = max( nParts, 1) ; + // lunghezza totale della curva + double dLenTot = 0 ; + bOk = bOk && pCurve->GetLength( dLenTot) ; + // lunghezza di una parte + double dLen = dLenTot / nParts ; + // eseguo la divisione + int nFirstId = GDB_ID_NULL ; + int nCurrId = nId ; + for ( int i = 1; i < nParts ; ++ i) { + // copio la curva + int nCopyId = pGeomDB->Copy( nCurrId, GDB_ID_NULL, nCurrId, GDB_AFTER) ; + ICurve* pCopyCrv = GetCurve( pGeomDB->GetGeoObj( nCopyId)) ; + bOk = bOk && ( pCopyCrv != nullptr) ; + // tengo la prima parte dell'originale e la seconda parte della copia + bOk = bOk && pCurve->TrimEndAtLen( dLen) ; + bOk = bOk && pCopyCrv->TrimStartAtLen( dLen) ; + // la copia diventa il nuovo corrente + nCurrId = nCopyId ; + pCurve = pCopyCrv ; + // salvo identificativo prima copia + if ( nFirstId == GDB_ID_NULL) + nFirstId = nCopyId ; + } + nFirstId = ( bOk ? nFirstId : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSplitCurve(" + ToString( nId) + "," + + ToString( nParts) + ")" + + " -- Id1=" + ToString( nFirstId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return nFirstId ; +} + +//---------------------------------------------------------------------------- +int +ExeSplitCurveAtPoint( int nId, const Point3d& ptOn, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pCurve != nullptr) ; + // recupero il riferimento locale + Frame3d frLoc ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ; + // porto in locale il punto + Point3d ptOnL = GetPointLocal( pGeomDB, ptOn, nRefType, frLoc) ; + // determino la posizione parametrica del punto sulla curva (con tolleranza) + double dU = 0 ; + if ( bOk) { + DistPointCurve dstPC( ptOnL, *pCurve) ; + int nFlag ; + if ( ! dstPC.GetParamAtMinDistPoint( 0, dU, nFlag) || nFlag != MDPCI_NORMAL) + bOk = false ; + } + // verifico che il punto di taglio sia interno alla curva + bool bIsInside = false ; + if ( bOk) { + Point3d ptStart ; + Point3d ptEnd ; + Point3d ptBreak ; + if ( pCurve->GetStartPoint( ptStart) && + pCurve->GetEndPoint( ptEnd) && + pCurve->GetPointD1D2( dU, ICurve::FROM_MINUS, ptBreak)) { + bIsInside = ! AreSamePointApprox( ptBreak, ptStart) && + ! AreSamePointApprox( ptBreak, ptEnd) ; + } + } + // se il punto di taglio è interno, devo realmente tagliare + int nNewId = GDB_ID_NULL ; + if ( bIsInside) { + // copio la curva + nNewId = pGeomDB->Copy( nId, GDB_ID_NULL, nId, GDB_AFTER) ; + ICurve* pCopyCrv = GetCurve( pGeomDB->GetGeoObj( nNewId)) ; + bOk = bOk && ( pCopyCrv != nullptr) ; + // tengo la prima parte dell'originale e la seconda parte della copia + bOk = bOk && pCurve->TrimEndAtParam( dU) ; + bOk = bOk && pCopyCrv->TrimStartAtParam( dU) ; + } + nNewId = ( bOk ? nNewId : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSplitCurveAtPoint(" + ToString( nId) + ",{" + + ToString( ptOn) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return nNewId ; +} + +//------------------------------------------------------------------------------- +bool +ExeModifyCurveCircleCPN( int nId, const Point3d& ptOn, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero l'arco e i suoi dati + ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ; + if ( pArc == nullptr) + return false ; + Point3d ptCen = pArc->GetCenter() ; + Vector3d vtN = pArc->GetNormVersor() ; + double dOldRad = pArc->GetRadius() ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGlobFrame( nId, frLoc)) + return false ; + // porto in locale il nuovo punto + Point3d ptOnL = GetPointLocal( pGeomDB, ptOn, nRefType, frLoc) ; + // calcolo il nuovo raggio + double dRad = (( ptOnL - ptCen) ^ vtN).Len() ; + // imposto il nuovo raggio + if ( pArc->Set( ptCen, vtN, dRad)) + return true ; + // in caso di errore, ripristino i vecchi dati + else { + pArc->Set( ptCen, vtN, dOldRad) ; + return false ; + } +} + +//------------------------------------------------------------------------------- +bool +ExeModifyCurveArcRadius( int nId, double dRad) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero l'arco e i suoi dati + ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ; + if ( pArc == nullptr) + return false ; + double dOldRad = pArc->GetRadius() ; + // imposto il nuovo raggio + if ( pArc->ChangeRadius( dRad)) + return true ; + // in caso di errore, ripristino i vecchi dati + else { + pArc->ChangeRadius( dOldRad) ; + return false ; + } +} + +//------------------------------------------------------------------------------- +bool +ExeModifyCurveArcC2PN( int nId, const Point3d& ptEnd, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero l'arco e i suoi dati + ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ; + if ( pArc == nullptr) + return false ; + Point3d ptCen = pArc->GetCenter() ; + Vector3d vtN = pArc->GetNormVersor() ; + Point3d ptStart, ptOldEnd ; + if ( ! pArc->GetStartPoint( ptStart) || ! pArc->GetEndPoint( ptOldEnd)) + return false ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGlobFrame( nId, frLoc)) + return false ; + // porto in locale il nuovo punto finale + Point3d ptEndL = GetPointLocal( pGeomDB, ptEnd, nRefType, frLoc) ; + // imposto il nuovo punto finale + if ( pArc->SetC2PN( ptCen, ptStart, ptEndL, vtN)) + return true ; + // in caso di errore, ripristino i vecchi dati + else { + pArc->SetC2PN( ptCen, ptStart, ptOldEnd, vtN) ; + return false ; + } +} + +//------------------------------------------------------------------------------- +bool +ExeModifyCurveArc3P( int nId, const Point3d& ptMid, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero l'arco e i suoi punti notevoli + ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ; + if ( pArc == nullptr) + return false ; + Point3d ptStart, ptOldMid, ptEnd ; + if ( ! pArc->GetStartPoint( ptStart) || ! pArc->GetMidPoint( ptOldMid) || ! pArc->GetEndPoint( ptEnd)) + return false ; + // recupero il riferimento locale + Frame3d frLoc ; + if ( ! pGeomDB->GetGlobFrame( nId, frLoc)) + return false ; + // porto in locale il nuovo punto medio + Point3d ptMidL = GetPointLocal( pGeomDB, ptMid, nRefType, frLoc) ; + // imposto il nuovo punto medio + if ( pArc->Set3P( ptStart, ptMidL, ptEnd)) + return true ; + // in caso di errore, ripristino i vecchi dati + else { + pArc->Set3P( ptStart, ptOldMid, ptEnd) ; + return false ; + } +} + +//------------------------------------------------------------------------------- +int +ExeExplodeCurveCompo( int nId, int* pnCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la curva composita + ICurveComposite* pCompo = GetCurveComposite( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pCompo != nullptr) ; + // estraggo tutte le curve + int nFirstId = GDB_ID_NULL ; + int nCount = 0 ; + ICurve* pCrv ; + while ( bOk && ( pCrv = pCompo->RemoveFirstOrLastCurve( false)) != nullptr) { + // inserisco la curva nello stesso gruppo e nello stesso posto del GeomDB + int nCrvId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_BEFORE, pCrv) ; + bOk = bOk && ( nCrvId != GDB_ID_NULL) ; + // copio gli attributi + bOk = bOk && pGeomDB->CopyAttributes( nId, nCrvId) ; + // aggiorno contatori + if ( bOk) { + if ( nFirstId == GDB_ID_NULL) + nFirstId = nCrvId ; + ++ nCount ; + } + } + nFirstId = ( bOk ? nFirstId : GDB_ID_NULL) ; + // elimino la curva composita ormai vuota + bOk = bOk && pGeomDB->Erase( nId) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtExplodeCurveCompo(" + ToString( nId) + ")" + + " -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultati + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; +} + +//------------------------------------------------------------------------------- +int +ExeApproxCurveArc( int nId, double dLinTol) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero l'arco + ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pArc != nullptr) ; + // eseguo l'approssimazione con segmenti di linea + const double ANG_TOL_STD_DEG = 15 ; + PtrOwner pCC( CreateCurveComposite()) ; + bOk = bOk && ! IsNull( pCC) ; + PolyLine PL ; + bOk = bOk && pArc->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, PL) && pCC->FromPolyLine( PL) ; + // inserisco la curva composita nello stesso posto del GeomDB + int nCrvId = ( bOk ? pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_BEFORE, Release( pCC)) : GDB_ID_NULL) ; + bOk = bOk && ( nCrvId != GDB_ID_NULL) ; + // copio gli attributi + bOk = bOk && pGeomDB->CopyAttributes( nId, nCrvId) ; + // elimino l'arco + bOk = bOk && pGeomDB->Erase( nId) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtApproxCurveArc(" + ToString( nId) + "," + + ToString( dLinTol) + ")" + + " -- Id=" + ToString( nCrvId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return nCrvId ; +} + +//------------------------------------------------------------------------------- +int +ExeApproxCurveBezier( int nId, bool bArcsVsLines, double dLinTol) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la curva di Bezier + ICurveBezier* pCBezier = GetCurveBezier( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pCBezier != nullptr) ; + // eseguo l'approssimazione + const double ANG_TOL_STD_DEG = 15 ; + PtrOwner pCC( CreateCurveComposite()) ; + bOk = bOk && ! IsNull( pCC) ; + if ( bArcsVsLines) { // con bi-archi + PolyArc PA ; + bOk = bOk && pCBezier->ApproxWithArcs( dLinTol, ANG_TOL_STD_DEG, PA) && pCC->FromPolyArc( PA) ; + } + else { // con linee + PolyLine PL ; + bOk = bOk && pCBezier->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, PL) && pCC->FromPolyLine( PL) ; + } + // inserisco la curva composita nello stesso posto del GeomDB + int nCrvId = ( bOk ? pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_BEFORE, Release( pCC)) : GDB_ID_NULL) ; + bOk = bOk && ( nCrvId != GDB_ID_NULL) ; + // copio gli attributi + bOk = bOk && pGeomDB->CopyAttributes( nId, nCrvId) ; + // elimino la curva di Bezier + bOk = bOk && pGeomDB->Erase( nId) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtApproxCurveBezier(" + ToString( nId) + "," + + ( bArcsVsLines ? "GDB_CA.ARCS" : "GDB_CA.LINES") + "," + + ToString( dLinTol) + ")" + + " -- Id=" + ToString( nCrvId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return nCrvId ; +} \ No newline at end of file diff --git a/EXE_GdbModifySurf.cpp b/EXE_GdbModifySurf.cpp new file mode 100644 index 0000000..54f5823 --- /dev/null +++ b/EXE_GdbModifySurf.cpp @@ -0,0 +1,152 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : EXE_ModifySurf.cpp Data : 04.05.15 Versione : 1.6e1 +// Contenuto : Funzioni di modifica delle superfici per EXE. +// +// +// +// Modifiche : 09.03.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "AuxTools.h" +#include "GeoTools.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EgkCurveComposite.h" +#include "/EgtDev/Include/EgkSurfTriMesh.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +bool +ExeInvertSurface( const INTVECTOR& vIds) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // eseguo inversione + bool bOk = true ; + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL && bOk) { + // recupero la superficie e la inverto + ISurf* pSurf = GetSurf( pGeomDB->GetGeoObj( nId)) ; + if ( pSurf != nullptr && ! pSurf->Invert()) + bOk = false ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtInvertSurf({" + IdListToString( vIds) + "})" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//---------------------------------------------------------------------------- +int +ExeExtractSurfTmFacetLoops( int nId, int nFacet, int nDestGrpId, int* pnCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la superficie TriMesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pStm != nullptr) ; + // recupero il riferimento della superficie + Frame3d frSurf ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frSurf) ; + // recupero il riferimento di destinazione + Frame3d frDest ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest) ; + // recupero i loop come polilinee + POLYLINEVECTOR vPL ; + bOk = bOk && pStm->GetFacetLoops( nFacet, vPL) ; + // dalle polilinee creo le curve e le inserisco nel DB + int nFirstId = GDB_ID_NULL ; + int nCount = 0 ; + for ( size_t i = 0 ; i < vPL.size() ; ++ i) { + // creo la curva + PtrOwner pCrvCompo( CreateCurveComposite()) ; + bOk = bOk && pCrvCompo->FromPolyLine( vPL[i]) ; + // la porto nel riferimento destinazione + bOk = bOk && pCrvCompo->LocToLoc( frSurf, frDest) ; + // la inserisco nel DB geometrico + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( pCrvCompo)) : GDB_ID_NULL) ; + bOk = bOk && ( nNewId != GDB_ID_NULL) ; + if ( bOk && nFirstId == GDB_ID_NULL) + nFirstId = nNewId ; + if ( bOk) + ++ nCount ; + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtExtractSurfTmFacetLoops(" + ToString( nId) + ",{" + + ToString( nFacet) + "," + + ToString( nDestGrpId) + ")" + + " -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultati + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; +} + +//------------------------------------------------------------------------------- +int +ExeExplodeSurfTm( int nId, int* pnCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la superficie TriMesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pStm != nullptr) ; + // copio tutte le facce + int nFirstId = GDB_ID_NULL ; + int nCount = 0 ; + int nFacet = pStm->GetFacetNum() ; + for ( int i = 0 ; i < nFacet ; ++ i) { + ISurfTriMesh* pFac = pStm->CloneFacet( i) ; + if ( pFac == nullptr) + continue ; + // inserisco la superficie nello stesso gruppo e nello stesso posto del GeomDB + int nFacId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_BEFORE, pFac) ; + bOk = bOk && ( nFacId != GDB_ID_NULL) ; + // copio gli attributi + bOk = bOk && pGeomDB->CopyAttributes( nId, nFacId) ; + // aggiorno contatori + if ( bOk) { + if ( nFirstId == GDB_ID_NULL) + nFirstId = nFacId ; + ++ nCount ; + } + } + nFirstId = ( bOk ? nFirstId : GDB_ID_NULL) ; + // elimino la superficie + bOk = bOk && pGeomDB->Erase( nId) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtExplodeSurfTm(" + ToString( nId) + ")" + + " -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultati + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; +} diff --git a/EXE_GdbObjAttribs.cpp b/EXE_GdbObjAttribs.cpp new file mode 100644 index 0000000..ecf4b38 --- /dev/null +++ b/EXE_GdbObjAttribs.cpp @@ -0,0 +1,538 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : EXE_GdbObjAttribs.cpp Data : 04.05.15 Versione : 1.6e1 +// Contenuto : Funzioni sugli attributi degli oggetti di GeomDB per EXE. +// +// +// +// Modifiche : 03.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/EGnStringConverter.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//----------------------------------------------------------------------------- +bool +ExeSetLevel( int nId, int nLevel) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // imposto il livello + bool bOk = pGeomDB->SetLevel( nId, nLevel) ; + ExeSetModified() ; + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeRevertLevel( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // porto il livello allo stato precedente + bool bOk = pGeomDB->RevertLevel( nId) ; + ExeSetModified() ; + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetLevel( int nId, int* pnLevel) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pnLevel == nullptr) + return false ; + // recupero il livello + return pGeomDB->GetLevel( nId, *pnLevel) ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetCalcLevel( int nId, int* pnLevel) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pnLevel == nullptr) + return false ; + // recupero il modo + return pGeomDB->GetCalcLevel( nId, *pnLevel) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetMode( int nId, int nMode) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // imposto il modo + bool bOk = pGeomDB->SetMode( nId, nMode) ; + ExeSetModified() ; + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeRevertMode( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // porto il modo allo stato precedente + bool bOk = pGeomDB->RevertMode( nId) ; + ExeSetModified() ; + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetMode( int nId, int* pnMode) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pnMode == nullptr) + return false ; + // recupero il modo + return pGeomDB->GetMode( nId, *pnMode) ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetCalcMode( int nId, int* pnMode) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pnMode == nullptr) + return false ; + // recupero il modo + return pGeomDB->GetCalcMode( nId, *pnMode) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetStatus( const INTVECTOR& vIds, int nStat) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero pezzo e layer correnti + bool bCurrPartOff = false ; + bool bCurrLayerOff = false ; + int nCurrPartId = ExeGetCurrPart() ; + int nCurrLayerId = ExeGetCurrLayer() ; + // ciclo sul vettore degli identificativi + bool bOk = true ; + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + // impostazione stato + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // imposto il modo + if ( ! pGeomDB->SetStatus( nId, nStat)) + bOk = false ; + // se nascosto pezzo corrente o layer corrente + if ( nStat == GDB_ST_OFF) { + if ( nId == nCurrPartId) + bCurrPartOff = true ; + else if ( nId == nCurrLayerId) + bCurrLayerOff = true ; + } + // passo al successivo + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + // se pezzo o layer correnti da rideterminare + if ( bCurrPartOff) + ExeResetCurrPartLayer() ; + else if ( bCurrLayerOff) + ExeSetCurrPartLayer( nCurrPartId, ExeGetFirstLayer( nCurrPartId, true)) ; + // dichiaro progetto modificato + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sStat = "GDB_ST.ON" ; + if ( nStat == GDB_ST_SEL) + sStat = "GDB_ST.SEL" ; + else if ( nStat == GDB_ST_OFF) + sStat = "GDB_ST.OFF" ; + string sLua = "EgtSetStatus({" + IdListToString( vIds) + "}," + + sStat + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeRevertStatus( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // porto lo stato al valore precedente + bool bOk = pGeomDB->RevertStatus( nId) ; + ExeSetModified() ; + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetStatus( int nId, int* pnStat) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pnStat == nullptr) + return false ; + // recupero lo stato + return pGeomDB->GetStatus( nId, *pnStat) ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetCalcStatus( int nId, int* pnStat) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pnStat == nullptr) + return false ; + // recupero lo stato + return pGeomDB->GetCalcStatus( nId, *pnStat) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetMark( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // imposto l'evidenziazione + bool bOk = pGeomDB->SetMark( nId) ; + // non produce modifica perchè mark ignorato in salvataggio + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeResetMark( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // cancello l'evidenziazione + bool bOk = pGeomDB->ResetMark( nId) ; + // non produce modifica perchè mark ignorato in salvataggio + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetMark( int nId, int* pnMark) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pnMark == nullptr) + return false ; + // recupero l'evidenziazione + return pGeomDB->GetMark( nId, *pnMark) ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetCalcMark( int nId, int* pnMark) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pnMark == nullptr) + return false ; + // recupero il modo + return pGeomDB->GetCalcMark( nId, *pnMark) ; +} + +//----------------------------------------------------------------------------- +bool +ExeStdColor( const string& sName, Color& ColStd) +{ + return GetStdColor( sName, ColStd) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetColor( const INTVECTOR& vIds, const Color& cCol, bool bSetAlpha) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // assegno il colore + bool bOk = true ; + 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) { + Color cNew = cCol ; + // se richiesto, recupero alpha originale + if ( ! bSetAlpha) { + Color cOri ; + if ( pGeomDB->GetCalcMaterial( nId, cOri)) + cNew.SetAlpha( cOri.GetIntAlpha()) ; + } + // eseguo assegnazione + if ( ! pGeomDB->SetMaterial( nId, cNew)) + bOk = false ; + // passo al successivo + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sIds ; + for ( size_t i = 0 ; i < vIds.size() ; ++ i) + sIds += ( vIds[i] != GDB_ID_SEL ? ToString( vIds[i]) : "GDB_ID_SEL") + "," ; + sIds.pop_back() ; + string sLua = "EgtSetColor({" + sIds + "},{" + + ToString( cCol) + "}," + + ( bSetAlpha ? "true" : "false") + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetAlpha( const INTVECTOR& vIds, int nAlpha) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // assegno la trasparenza + 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) { + // recupero il colore originale + Color cCol ; + bOk = bOk && pGeomDB->GetCalcMaterial( nId, cCol) ; + cCol.SetAlpha( nAlpha) ; + // eseguo assegnazione + bOk = bOk && pGeomDB->SetMaterial( nId, cCol) ; + // passo al successivo + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSetAlpha({" + IdListToString( vIds) + "}," + + ToString( nAlpha) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeResetColor( const INTVECTOR& vIds) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // tolgo il colore + bool bOk = true ; + 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) { + if ( ! pGeomDB->SetMaterial( nId, GDB_MT_PARENT)) + bOk = false ; + // passo al successivo + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtResetColor({" + IdListToString( vIds) + "})" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetColor( int nId, Color& cCol) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero il colore + return pGeomDB->GetMaterial( nId, cCol) ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetCalcColor( int nId, Color& cCol) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero il colore + return pGeomDB->GetCalcMaterial( nId, cCol) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetName( int nId, const string& sName) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // assegno il nome + bool bOk = pGeomDB->SetName( nId, sName) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSetName(" + ToString( nId) + ",'" + + sName + "')" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetName( int nId, string& sName) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero il nome + return pGeomDB->GetName( nId, sName) ; +} + +//----------------------------------------------------------------------------- +bool +ExeExistsName( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico esistenza del nome + return pGeomDB->ExistsName( nId) ; +} + +//----------------------------------------------------------------------------- +bool +ExeRemoveName( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // rimuovo il nome + bool bOk = pGeomDB->RemoveName( nId) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtRemoveName(" + ToString( nId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetInfo( int nId, const string& sKey, const string& sInfo) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // assegno la info + bool bOk = pGeomDB->SetInfo( nId, sKey, sInfo) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSetInfo(" + ToString( nId) + ",'" + + sKey + "','" + + sInfo + "')" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetInfo( int nId, const string& sKey, int nInfo) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // assegno la info + bool bOk = pGeomDB->SetInfo( nId, sKey, nInfo) ; + ExeSetModified() ; + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetInfo( int nId, const string& sKey, string& sInfo) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, FALSE) + // recupero info + return pGeomDB->GetInfo( nId, sKey, sInfo) ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetInfo( int nId, const string& sKey, int& nInfo) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la info + return pGeomDB->GetInfo( nId, sKey, nInfo) ; +} + +//----------------------------------------------------------------------------- +bool +ExeExistsInfo( int nId, const string& sKey) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico esistenza info + return pGeomDB->ExistsInfo( nId, sKey) ; +} + +//----------------------------------------------------------------------------- +bool +ExeRemoveInfo( int nId, const string& sKey) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // rimuovo la info + bool bOk = pGeomDB->RemoveInfo( nId, sKey) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtRemoveInfo(" + ToString( nId) + ",'" + + sKey + "')" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} diff --git a/EXE_GdbObjSelection.cpp b/EXE_GdbObjSelection.cpp new file mode 100644 index 0000000..81a2f86 --- /dev/null +++ b/EXE_GdbObjSelection.cpp @@ -0,0 +1,217 @@ +//---------------------------------------------------------------------------- +// 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 "EXE.h" +#include "EXE_Macro.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//----------------------------------------------------------------------------- +bool +ExeSelectObj( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // seleziono l'oggetto + bool bOk = pGeomDB->SelectObj( nId) ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSelectObj(" + ToString( nId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeDeselectObj( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // deseleziono l'oggetto + bool bOk = pGeomDB->DeselectObj( nId) ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtDeselectObj(" + ToString( nId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeSelectAll( bool bOnlyIfVisible) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // seleziono tutto + int nId1 = ExeGetFirstPart( bOnlyIfVisible) ; + while ( nId1 != GDB_ID_NULL) { + // ciclo sugli oggetti del pezzo + int nId2 = pGeomDB->GetFirstInGroup( nId1) ; + while ( nId2 != GDB_ID_NULL) { + // se è gruppo seleziono i suoi componenti + if ( pGeomDB->GetGdbType( nId2) == GDB_TY_GROUP) + pGeomDB->SelectGroupObjs( nId2, 0, bOnlyIfVisible) ; + // altrimenti lo seleziono direttamente + else + pGeomDB->SelectObj( nId2, bOnlyIfVisible) ; + // passo al successivo + nId2 = pGeomDB->GetNext( nId2) ; + } + // passo al successivo + nId1 = ExeGetNextPart( nId1, bOnlyIfVisible) ; + } + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSelectAll(" + string( bOnlyIfVisible ? "true" : "false") + ")" + + " -- bOk=1" ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeDeselectAll( void) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // deseleziono tutto + bool bOk = pGeomDB->ClearSelection() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtDeselectAll()" + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeSelectGroupObjs( int nGroupId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // verifico sia un gruppo + if ( pGeomDB->GetGdbType( nGroupId) == GDB_TY_GROUP) { + bOk = pGeomDB->SelectGroupObjs( nGroupId) ; + } + else + bOk = false ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSelectGroupObjs(" + ToString( nGroupId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeDeselectGroupObjs( int nGroupId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // verifico sia un gruppo + if ( pGeomDB->GetGdbType( nGroupId) == GDB_TY_GROUP) { + bOk = pGeomDB->DeselectGroupObjs( nGroupId) ; + } + else + bOk = false ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtDeselectGroupObjs(" + ToString( nGroupId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeIsSelectedObj( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico se l'oggetto è selezionato + return pGeomDB->IsSelectedObj( nId) ; +} + +//----------------------------------------------------------------------------- +int +ExeGetSelectedObjNbr( void) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, 0) + // restituisco il numero di oggetti selezionati + return pGeomDB->GetSelectedObjNbr() ; +} + +//----------------------------------------------------------------------------- +int +ExeGetFirstSelectedObj( void) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero il primo oggetto selezionato + return pGeomDB->GetFirstSelectedObj() ; +} + +//----------------------------------------------------------------------------- +int +ExeGetNextSelectedObj( void) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero il successivo oggetto selezionato + return pGeomDB->GetNextSelectedObj() ; +} + +//----------------------------------------------------------------------------- +int +ExeGetLastSelectedObj( void) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero l'ultimo oggetto selezionato + return pGeomDB->GetLastSelectedObj() ; +} + +//----------------------------------------------------------------------------- +int +ExeGetPrevSelectedObj( void) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero il precedente oggetto selezionato + return pGeomDB->GetPrevSelectedObj() ; +} diff --git a/EXE_GdbObjects.cpp b/EXE_GdbObjects.cpp new file mode 100644 index 0000000..138191b --- /dev/null +++ b/EXE_GdbObjects.cpp @@ -0,0 +1,512 @@ +//---------------------------------------------------------------------------- +// 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 "AuxTools.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EGnStringConverter.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 +ExeGetGroupGlobFrame( int nId, Frame3d& frGlob) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero il riferimento globale del gruppo + 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) ; +} + +//----------------------------------------------------------------------------- +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) + // eseguo la copia + int nNewId = pGeomDB->Copy( nSouId, GDB_ID_NULL, nRefId, nSonBeforeAfter) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua ; + if ( nSonBeforeAfter == GDB_LAST_SON) + sLua = "EgtCopy(" + ToString( nSouId) + "," + + ToString( nRefId) + ")" + + " -- Id=" + ToString( nNewId) ; + else + sLua = "EgtCopy(" + ToString( nSouId) + "," + + ToString( 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) + // eseguo la copia mantenendo la posizione in globale + int nNewId = pGeomDB->CopyGlob( nSouId, GDB_ID_NULL, nRefId, nSonBeforeAfter) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua ; + if ( nSonBeforeAfter == GDB_LAST_SON) + sLua = "EgtCopyGlob(" + ToString( nSouId) + "," + + ToString( nRefId) + ")" + + " -- Id=" + ToString( nNewId) ; + else + sLua = "EgtCopyGlob(" + ToString( nSouId) + "," + + ToString( 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) + // 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) + "," + + ToString( nRefId) + ")" + + " -- Ok=" + ToString( bOk) ; + else + sLua = "EgtRelocate(" + ToString( nSouId) + "," + + ToString( 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) + // 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) + "," + + ToString( nRefId) + ")" + + " -- Ok=" + ToString( bOk) ; + else + sLua = "EgtRelocateGlob(" + ToString( nSouId) + "," + + ToString( nRefId) + "," + + InsToString( nSonBeforeAfter) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +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) { + // 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()) ; + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtErase({" + IdListToString( vIds) + "})" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // se cancellato pezzo corrente o layer corrente (va qui perchè salva altro comando che è successivo) + if ( bErasedCurrPart) + ExeResetCurrPartLayer() ; + else if ( bErasedCurrLayer) + ExeSetCurrPartLayer( nCurrPartId, ExeGetFirstLayer( nCurrPartId, true)) ; + // 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 + int nCurrPartId = ExeGetCurrPart() ; + int nCurrLayerId = ExeGetCurrLayer() ; + if ( ! pGeomDB->ExistsObj( nCurrPartId)) + ExeResetCurrPartLayer() ; + else if ( ! pGeomDB->ExistsObj( nCurrLayerId)) + ExeSetCurrPartLayer( nCurrPartId, ExeGetFirstLayer( nCurrPartId, true)) ; + 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) + // preparo l'intestazione + 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" ; + } + } + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeGeoObjDump( int nId, string& sDump) +{ + 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 + 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 ; + return true ; +} diff --git a/EXE_GdbPartLayers.cpp b/EXE_GdbPartLayers.cpp new file mode 100644 index 0000000..4308df6 --- /dev/null +++ b/EXE_GdbPartLayers.cpp @@ -0,0 +1,451 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : EXE_GdbPartLayers.cpp Data : 04.05.15 Versione : 1.6e1 +// Contenuto : Funzioni di gestione pezzi e layer relativi per EXE. +// +// +// +// Modifiche : 29.01.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EgkCurve.h" +#include "/EgtDev/Include/EgkChainCurves.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static bool +ExeIsUserObj( IGeomDB* pGeomDB, int nId) +{ + int nLev ; + return ( pGeomDB->GetCalcLevel( nId, nLev) && nLev == GDB_LV_USER) ; +} + +//------------------------------------------------------------------------------- +static bool +ExeIsVisibleObj( IGeomDB* pGeomDB, int nId) +{ + int nStat ; + return ( pGeomDB->GetCalcStatus( nId, nStat) && nStat != GDB_ST_OFF) ; +} + +//------------------------------------------------------------------------------- +static int +ExeVerifyOrNext( IGeomDB* pGeomDB, int nId, bool bOnlyVisible) +{ + while ( nId != GDB_ID_NULL) { + if ( ExeIsUserObj( pGeomDB, nId) && + ( ! bOnlyVisible || ExeIsVisibleObj( pGeomDB, nId))) + return nId ; + nId = pGeomDB->GetNextGroup( nId) ; + } + return GDB_ID_NULL ; +} + +//------------------------------------------------------------------------------- +bool +ExeIsPart( int nPartId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico sia un pezzo (gruppo sotto la radice con livello utente) + if ( pGeomDB->GetGdbType( nPartId) == GDB_TY_GROUP && + pGeomDB->GetParentId( nPartId) == GDB_ID_ROOT && + ExeIsUserObj( pGeomDB, nPartId)) + return true ; + else + return false ; +} + +//------------------------------------------------------------------------------- +bool +ExeIsLayer( int nLayerId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico sia un layer (gruppo sotto un pezzo con livello utente) + if ( pGeomDB->GetGdbType( nLayerId) == GDB_TY_GROUP && + ExeIsPart( pGeomDB->GetParentId( nLayerId)) && + ExeIsUserObj( pGeomDB, nLayerId)) + return true ; + else + return false ; +} + +//------------------------------------------------------------------------------- +int +ExeGetCurrPart( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_GEOMDB( pGseCtx, GDB_ID_NULL) + // recupero il pezzo corrente + return pGseCtx->m_nCurrPart ; +} + +//------------------------------------------------------------------------------- +int +ExeGetCurrLayer( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_GEOMDB( pGseCtx, GDB_ID_NULL) + // recupero il pezzo corrente + return pGseCtx->m_nCurrLayer ; +} + +//------------------------------------------------------------------------------- +bool +ExeSetCurrPartLayer( int nPartId, int nLayerId) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_GEOMDB( pGseCtx, false) + IGeomDB* pGeomDB = pGseCtx->m_pGeomDB ; + bool bOk = true ; + // verifico validità e visibilità pezzo + if ( pGeomDB->GetParentId( nPartId) == GDB_ID_ROOT && + ExeIsUserObj( pGeomDB, nPartId) && + ExeIsVisibleObj( pGeomDB, nPartId)) { + if ( nPartId != pGseCtx->m_nCurrPart) + pGseCtx->m_nCurrLayer = GDB_ID_NULL ; + pGseCtx->m_nCurrPart = nPartId ; + } + else { + if ( nPartId == pGseCtx->m_nCurrPart || nPartId == GDB_ID_NULL) { + pGseCtx->m_nCurrPart = GDB_ID_NULL ; + pGseCtx->m_nCurrLayer = GDB_ID_NULL ; + } + bOk = false ; + } + // verifico validità e visibilità layer + if ( pGeomDB->GetParentId( nLayerId) == nPartId && + ExeIsUserObj( pGeomDB, nLayerId) && + ExeIsVisibleObj( pGeomDB, nLayerId)) { + pGseCtx->m_nCurrLayer = nLayerId ; + } + else { + if ( nLayerId == pGseCtx->m_nCurrLayer || nLayerId == GDB_ID_NULL) + pGseCtx->m_nCurrLayer = GDB_ID_NULL ; + bOk = false ; + } + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSetCurrPartLayer(" + ToString( nPartId) + "," + + ToString( nLayerId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//------------------------------------------------------------------------------- +bool +ExeResetCurrPartLayer( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_GEOMDB( pGseCtx, false) + IGeomDB* pGeomDB = pGseCtx->m_pGeomDB ; + // reset + pGseCtx->m_nCurrPart = GDB_ID_NULL ; + pGseCtx->m_nCurrLayer = GDB_ID_NULL ; + // cerco il primo pezzo con un layer visibile + int nPartId = ExeGetFirstPart( true) ; + while ( nPartId != GDB_ID_NULL) { + // cerco il primo layer visibile del pezzo + int nLayerId = ExeGetFirstLayer( nPartId, true) ; + if ( nLayerId != GDB_ID_NULL) { + // assegno il pezzo corrente + pGseCtx->m_nCurrPart = nPartId ; + // assegno il layer corrente + pGseCtx->m_nCurrLayer = nLayerId ; + // esco dal ciclo di ricerca + break ; + } + nPartId = ExeGetNextPart( nPartId, true) ; + } + // se non ho trovato layer visibile mi accontento del primo pezzo visibile + if ( pGseCtx->m_nCurrPart == GDB_ID_NULL) + pGseCtx->m_nCurrPart = ExeGetFirstPart( true) ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtResetCurrPartLayer()" + " -- Ids=" + ToString( pGseCtx->m_nCurrPart) + "," + ToString( pGseCtx->m_nCurrLayer) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return true ; +} + +//------------------------------------------------------------------------------- +int +ExeGetPartNbr( bool bOnlyVisible) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, 0) + // conto i pezzi, considerando richiesta di visibilità + int nCount = 0 ; + int nPartId = ExeGetFirstPart( bOnlyVisible) ; + while ( nPartId != GDB_ID_NULL) { + ++ nCount ; + nPartId = ExeGetNextPart( nPartId, bOnlyVisible) ; + } + return nCount ; +} + +//------------------------------------------------------------------------------- +int +ExeGetFirstPart( bool bOnlyVisible) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero il primo gruppo sotto la radice + int nPartId = pGeomDB->GetFirstGroupInGroup( GDB_ID_ROOT) ; + // verifico oppure passo al primo successivo valido + return ExeVerifyOrNext( pGeomDB, nPartId, bOnlyVisible) ; +} + +//------------------------------------------------------------------------------- +int +ExeGetNextPart( int nId, bool bOnlyVisible) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero il successivo gruppo + int nPartId = pGeomDB->GetNextGroup( nId) ; + // verifico oppure passo al primo successivo valido + return ExeVerifyOrNext( pGeomDB, nPartId, bOnlyVisible) ; +} + +//------------------------------------------------------------------------------- +int +ExeGetFirstLayer( int nPartId, bool bOnlyVisible) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // verifico il pezzo (livello utente e se richiesto visibile) + if ( ! ExeIsUserObj( pGeomDB, nPartId) || + ( bOnlyVisible && ! ExeIsVisibleObj( pGeomDB, nPartId))) + return GDB_ID_NULL ; + // recupero il primo layer nel pezzo + int nLayerId = pGeomDB->GetFirstGroupInGroup( nPartId) ; + // verifico oppure passo al primo successivo valido + return ExeVerifyOrNext( pGeomDB, nLayerId, bOnlyVisible) ; +} + +//------------------------------------------------------------------------------- +int +ExeGetNextLayer( int nId, bool bOnlyVisible) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero il successivo gruppo + int nLayerId = pGeomDB->GetNextGroup( nId) ; + // verifico sia visibile oppure passo al primo successivo visibile + return ExeVerifyOrNext( pGeomDB, nLayerId, bOnlyVisible) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSelectPartObjs( int nPartId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // verifico sia veramente un pezzo + if ( ExeIsPart( nPartId)) { + // ciclo sugli oggetti del pezzo + int nId = pGeomDB->GetFirstInGroup( nPartId) ; + while ( nId != GDB_ID_NULL) { + // se è gruppo seleziono i suoi componenti + if ( pGeomDB->GetGdbType( nId) == GDB_TY_GROUP) + pGeomDB->SelectGroupObjs( nId) ; + // altrimenti lo seleziono direttamente + else + pGeomDB->SelectObj( nId) ; + // passo al successivo + nId = pGeomDB->GetNext( nId) ; + } + } + else + bOk = false ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSelectPartObjs(" + ToString( nPartId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeDeselectPartObjs( int nPartId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // verifico sia veramente un pezzo + if ( ExeIsPart( nPartId)) { + // ciclo sugli oggetti del pezzo + int nId = pGeomDB->GetFirstInGroup( nPartId) ; + while ( nId != GDB_ID_NULL) { + // se è gruppo deseleziono i suoi componenti + if ( pGeomDB->GetGdbType( nId) == GDB_TY_GROUP) + pGeomDB->DeselectGroupObjs( nId) ; + // altrimenti lo deseleziono direttamente + else + pGeomDB->DeselectObj( nId) ; + // passo al successivo + nId = pGeomDB->GetNext( nId) ; + } + } + else + bOk = false ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtDeselectPartObjs(" + ToString( nPartId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeSelectLayerObjs( int nLayerId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // verifico sia veramente un layer + if ( ExeIsLayer( nLayerId)) { + // ciclo sugli oggetti del layer + int nId = pGeomDB->GetFirstInGroup( nLayerId) ; + while ( nId != GDB_ID_NULL) { + // seleziono + pGeomDB->SelectObj( nId) ; + // passo al successivo + nId = pGeomDB->GetNext( nId) ; + } + } + else + bOk = false ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSelectLayerObjs(" + ToString( nLayerId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeDeselectLayerObjs( int nLayerId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // verifico sia veramente un layer + if ( ExeIsLayer( nLayerId)) { + // ciclo sugli oggetti del layer + int nId = pGeomDB->GetFirstInGroup( nLayerId) ; + while ( nId != GDB_ID_NULL) { + // deseleziono + pGeomDB->DeselectObj( nId) ; + // passo al successivo + nId = pGeomDB->GetNext( nId) ; + } + } + else + bOk = false ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtDeselectLayerObjs(" + ToString( nLayerId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeSelectPathObjs( int nId, bool bHaltOnFork) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico appartenga ad un layer + int nIdLayer = pGeomDB->GetParentId( nId) ; + int nIdPart = pGeomDB->GetParentId( nIdLayer) ; + bool bOk = ( nIdLayer != GDB_ID_NULL && nIdPart != GDB_ID_NULL && ExeIsLayer( nIdLayer)) ; + // seleziono percorso a partire da entità indicata usando tutte le curve del pezzo + const int CHAIN_SIZE = 1000 ; + const double CHAIN_TOLER = 10 * EPS_SMALL ; + Point3d ptNear ; + ChainCurves chainC ; + bOk = bOk && chainC.Init( true, CHAIN_TOLER, CHAIN_SIZE) ; + // ciclo sui layer del pezzo + for ( int nLayId = pGeomDB->GetFirstGroupInGroup( nIdPart) ; + nLayId != GDB_ID_NULL ; + nLayId = pGeomDB->GetNextGroup( nLayId)) { + // ciclo sulle entità del layer + for ( int nEntId = pGeomDB->GetFirstInGroup( nLayId) ; + nEntId != GDB_ID_NULL ; + nEntId = pGeomDB->GetNext( nEntId)) { + // non deve essere nascosta + int nEntStat ; + pGeomDB->GetCalcStatus( nEntId, nEntStat) ; + if ( nEntStat == GDB_ST_OFF) + continue ; + // recupero la curva e il suo riferimento + ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nEntId)) ; + if ( pCrv == nullptr) + continue ; + Frame3d frCrv ; + if ( ! pGeomDB->GetGlobFrame( nEntId, frCrv)) + continue ; + // recupero i dati della curva necessari al concatenamento e li assegno + Point3d ptStart, ptEnd ; + Vector3d vtStart, vtEnd ; + if ( ! pCrv->GetStartPoint( ptStart) || ! pCrv->GetStartDir( vtStart) || + ! pCrv->GetEndPoint( ptEnd) || ! pCrv->GetEndDir( vtEnd)) + return GDB_ID_NULL ; + ptStart.ToGlob( frCrv) ; + vtStart.ToGlob( frCrv) ; + ptEnd.ToGlob( frCrv) ; + vtEnd.ToGlob( frCrv) ; + if ( nEntId == nId) + ptNear = ptStart + vtStart ; + if ( ! chainC.AddCurve( nEntId, ptStart, vtStart, ptEnd, vtEnd)) + continue ; + } + } + // recupero il primo percorso concatenato + int nFirstId = GDB_ID_NULL ; + INTVECTOR vId2s ; + bOk = bOk && chainC.GetChainFromNear( ptNear, ( bHaltOnFork != FALSE), vId2s) ; + for ( size_t i = 0 ; i < vId2s.size() ; ++i) { + pGeomDB->SetStatus( abs( vId2s[i]), GDB_ST_SEL) ; + } + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSelectPathObjs(" + ToString( nId) + "," + + ( bHaltOnFork ? "true" : "false") + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} \ No newline at end of file diff --git a/EXE_General.cpp b/EXE_General.cpp new file mode 100644 index 0000000..03cab78 --- /dev/null +++ b/EXE_General.cpp @@ -0,0 +1,304 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : API_General.cpp Data : 01.09.14 Versione : 1.5i1 +// Contenuto : Funzioni generali per API. +// +// +// +// Modifiche : 01.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "LUA_Base.h" +#include "DllGraphics.h" +#include "DllExchange.h" +#include "DllMachKernel.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeDllMain.h" +#include "/EgtDev/Include/EGnDllMain.h" +#include "/EgtDev/Include/ENkDllMain.h" +#include "/EgtDev/Include/EGkDllMain.h" +#include "/EgtDev/Include/EGnStringUtils.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EGnPcInfo.h" +#include "/EgtDev/Include/EgtLogger.h" +#include + +using namespace std ; +using namespace egtlogger ; + +//---------------------------------------------------------------------------- +static Logger* s_pGenLog = nullptr ; +static bool s_bCmdLog = false ; +static Logger* s_pCmdLog = nullptr ; + +//----------------------------------------------------------------------------- +bool +ExeInit( int nDebug, const string& sLogFile, const string& sLogMsg) +{ + // cancello eventuali vecchi contesti + ClearAllGseContexts() ; + // cancello eventuale vecchio logger + if ( s_pGenLog != nullptr) + delete s_pGenLog ; + + // creo il logger generale + s_pGenLog = new Logger( ( nDebug > 0 ? LL_DEBUG : LL_INFO), "EgtInterface") ; + if ( s_pGenLog == nullptr) + return false ; + // assegno il file + s_pGenLog->AddOutputStream( new ofstream( stringtoW( sLogFile)), true) ; + // lo passo alle DLL + SetEGnLogger( s_pGenLog) ; + SetENkLogger( s_pGenLog) ; + SetEGkLogger( s_pGenLog) ; + + // carico librerie opzionali + LoadGraphicsDll() ; + MySetEGrLogger( s_pGenLog) ; + LoadExchangeDll() ; + MySetEExLogger( s_pGenLog) ; + LoadMachKernelDll() ; + MySetEMkLogger( s_pGenLog) ; + + // dichiaro inizio programma + LOG_DATETIME( s_pGenLog, " Init") + // eventuale messaggio dall'applicazione + if ( &sLogMsg != nullptr && ! sLogMsg.empty()) + LOG_INFO( s_pGenLog, sLogMsg.c_str()) + // versione di interfaccia e componenti + string sVer ; + ExeGetVersionInfo( sVer, "\n") ; + LOG_INFO( s_pGenLog, sVer.c_str()) + // Info sul sistema + string sTmp ; + if ( GetOsInfo( sTmp)) + LOG_INFO( s_pGenLog, sTmp.c_str()) + if ( GetCpuInfo( sTmp)) + LOG_INFO( s_pGenLog, sTmp.c_str()) + if ( GetMemoryInfo( sTmp)) + LOG_INFO( s_pGenLog, sTmp.c_str()) + + // inizializzo l'interprete LUA + LuaInit() ; + + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeExit( void) +{ + // cancello tutti i contesti + ClearAllGseContexts() ; + + // termino l'interprete LUA + LuaExit() ; + + // libero le librerie opzionali + FreeMachKernelDll() ; + FreeExchangeDll() ; + FreeGraphicsDll() ; + + // fine programma + LOG_DATETIME( s_pGenLog, " Exit") + + // cancello il logger dei comandi + if ( s_pCmdLog != nullptr) { + delete s_pCmdLog ; + s_pCmdLog = nullptr ; + } + + // cancello il logger generale + if ( s_pGenLog != nullptr) { + delete s_pGenLog ; + s_pGenLog = nullptr ; + } + + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetKey( const string& sKey) +{ + SetEGkKey( sKey) ; + MySetEGrKey( sKey) ; + MySetEExKey( sKey) ; + MySetEMkKey( sKey) ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetFont( const string& sNfeFontDir, const string& sDefaultFont) +{ + // inizializzazioni gestore font Nfe + InitFontManager( sNfeFontDir, sDefaultFont) ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetNfeFontDir( string& sNfeFontDir) +{ + if ( &sNfeFontDir == nullptr) + return false ; + // recupero il nome del font di default + sNfeFontDir = GetNfeFontDir() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetDefaultFont( string& sDefaultFont) +{ + if ( &sDefaultFont == nullptr) + return false ; + // recupero il nome del font di default + sDefaultFont = GetDefaultFont() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetLuaLibs( const string& sLuaLibsDir) +{ + return LuaSetLuaLibsDir( sLuaLibsDir) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetCommandLogger( const string& sLogFile) +{ + // cancello eventuale vecchio logger e disabilito output + if ( s_pCmdLog != nullptr) + delete s_pCmdLog ; + s_bCmdLog = false ; + // creo il logger dei comandi + s_pCmdLog = new Logger( LL_INFO, "EgtCommandLog") ; + if ( s_pCmdLog == nullptr) + return false ; + // assegno il file + ofstream* pLogFile = new ofstream( stringtoW( sLogFile)) ; + if ( pLogFile == nullptr || pLogFile->bad()) + return false ; + s_pCmdLog->AddOutputStream( pLogFile, true) ; + // scrivo intestazione + string sOut = "-- " + CurrDateTime() + " EgtCommandLog" ; + LOG_INFO( s_pCmdLog, sOut.c_str()) + return false ; +} + +//----------------------------------------------------------------------------- +void +ExeEnableCommandLogger( void) +{ + SetCmdLog( true) ; +} + +//----------------------------------------------------------------------------- +void +ExeDisableCommandLogger( void) +{ + SetCmdLog( false) ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetVersionInfo( string& sVer, const char* szNewLine) +{ + // verifico il parametro + if ( &sVer == nullptr) + return false ; + // recupero le informazioni sulle DLL sempre presenti + sVer += GetEXeVersion() ; + sVer += szNewLine ; + sVer += GetEGnVersion() ; + sVer += szNewLine ; + sVer += GetENkVersion() ; + sVer += szNewLine ; + sVer += GetEGkVersion() ; + // recupero le informazioni sulle DLL opzionali + if ( IsLoadedGraphicsDll()) { + sVer += szNewLine ; + sVer += MyGetEGrVersion() ; + } + if ( IsLoadedExchangeDll()) { + sVer += szNewLine ; + sVer += MyGetEExVersion() ; + } + if ( IsLoadedMachKernelDll()) { + sVer += szNewLine ; + sVer += MyGetEMkVersion() ; + } + + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetOsInfo( string& sOs) +{ + // recupero le informazioni sul sistema operativo + return GetOsInfo( sOs) ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetCpuInfo( string& sCpu) +{ + // recupero le informazioni sulla Cpu + return GetCpuInfo( sCpu) ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetMemoryInfo( string& sMem) +{ + // recupero le informazioni sulla memoria presente + return GetMemoryInfo( sMem) ; +} + +//----------------------------------------------------------------------------- +BOOL +__stdcall EgtOutLog( const wchar_t* sMsg) +{ + LOG_INFO( s_pGenLog, LPSTR( WtoA( sMsg))) + return ( s_pGenLog != nullptr) ; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +ILogger* +GetLogger( void) +{ + return s_pGenLog ; +} + +//----------------------------------------------------------------------------- +ILogger* +GetCmdLogger( void) +{ + return s_pCmdLog ; +} + +//----------------------------------------------------------------------------- +bool +SetCmdLog( bool bVal) +{ + swap( bVal, s_bCmdLog) ; + return bVal ; +} + +//----------------------------------------------------------------------------- +bool +IsCmdLog( void) +{ + return s_bCmdLog ; +} diff --git a/EXE_GeoSnap.cpp b/EXE_GeoSnap.cpp new file mode 100644 index 0000000..76dba0c --- /dev/null +++ b/EXE_GeoSnap.cpp @@ -0,0 +1,958 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : EXE_GeoSnap.cpp Data : 05.05.15 Versione : 1.6e1 +// Contenuto : Funzioni di snap ad oggetti del DB geometrico per EXE. +// +// +// +// Modifiche : 02.10.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EgkGeoPoint3d.h" +#include "/EgtDev/Include/EgkGeoVector3d.h" +#include "/EgtDev/Include/EgkCurve.h" +#include "/EgtDev/Include/EgkCurveArc.h" +#include "/EgtDev/Include/EgkCurveComposite.h" +#include "/EgtDev/Include/EgkSurf.h" +#include "/EgtDev/Include/EgkSurfTriMesh.h" +#include "/EgtDev/Include/EgkExtText.h" +#include "/EgtDev/Include/EgkDistPointCurve.h" +#include "/EgtDev/Include/EgkIntersCurveCurve.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +//---------------------------------------------------------------------------- +static bool +TrasformPoint( IGeomDB* pGeomDB, int nId, int nRefId, Point3d& ptP) +{ + // se non va trasformato, esco + if ( nRefId == nId) + return true ; + // recupero il riferimento in cui è espresso il punto (quello dell'entità da cui deriva) + Frame3d frSou ; + if ( ! pGeomDB->GetGlobFrame( nId, frSou)) + return false ; + // se va portato in globale, trasformo ed esco + if ( nRefId == GDB_ID_ROOT) + return ptP.ToGlob( frSou) ; + // recupero il riferimento destinazione + Frame3d frDest ; + if ( nRefId == GDB_ID_GRID) + frDest = pGeomDB->GetGridFrame() ; + else { + // nRefId può essere un gruppo o una entità + if ( ! pGeomDB->GetGroupGlobFrame( nRefId, frDest) && + ! pGeomDB->GetGlobFrame( nRefId, frDest)) + return false ; + } + // eseguo la trasformazione + return ptP.LocToLoc( frSou, frDest) ; +} + +//---------------------------------------------------------------------------- +static bool +InvTrasformPoint( IGeomDB* pGeomDB, int nId, int nRefId, Point3d& ptP) +{ + // se non va trasformato, esco + if ( nRefId == nId) + return true ; + // recupero il riferimento in cui va espresso il punto (quello dell'entità a cui va riferito) + Frame3d frSou ; + if ( ! pGeomDB->GetGlobFrame( nId, frSou)) + return false ; + // se viene da globale, trasformo ed esco + if ( nRefId == GDB_ID_ROOT) + return ptP.ToLoc( frSou) ; + // recupero il riferimento da cui proviene + Frame3d frDest ; + if ( nRefId == GDB_ID_GRID) + frDest = pGeomDB->GetGridFrame() ; + else { + // nRefId può essere un gruppo o una entità + if ( ! pGeomDB->GetGroupGlobFrame( nRefId, frDest) && + ! pGeomDB->GetGlobFrame( nRefId, frDest)) + return false ; + } + // eseguo la trasformazione inversa + return ptP.LocToLoc( frDest, frSou) ; +} + +//---------------------------------------------------------------------------- +static bool +TrasformVector( IGeomDB* pGeomDB, int nId, int nRefId, Vector3d& vtV) +{ + // se non va trasformato, esco + if ( nRefId == nId) + return true ; + // recupero il riferimento in cui è espresso il punto (quello dell'entità da cui deriva) + Frame3d frSou ; + if ( ! pGeomDB->GetGlobFrame( nId, frSou)) + return false ; + // se va portato in globale, trasformo ed esco + if ( nRefId == GDB_ID_ROOT) + return vtV.ToGlob( frSou) ; + // recupero il riferimento destinazione + Frame3d frDest ; + if ( nRefId == GDB_ID_GRID) + frDest = pGeomDB->GetGridFrame() ; + else { + // nRefId può essere un gruppo o una entità + if ( ! pGeomDB->GetGroupGlobFrame( nRefId, frDest) && + ! pGeomDB->GetGlobFrame( nRefId, frDest)) + return false ; + } + // eseguo la trasformazione + return vtV.LocToLoc( frSou, frDest) ; +} + +//---------------------------------------------------------------------------- +static bool +TrasformFrame( IGeomDB* pGeomDB, int nId, int nRefId, Frame3d& frF) +{ + // se non va trasformato, esco + if ( nRefId == nId) + return true ; + // recupero il riferimento in cui è espresso il punto (quello dell'entità da cui deriva) + Frame3d frSou ; + if ( ! pGeomDB->GetGlobFrame( nId, frSou)) + return false ; + // se va portato in globale, trasformo ed esco + if ( nRefId == GDB_ID_ROOT) + return frF.ToGlob( frSou) ; + // recupero il riferimento destinazione + Frame3d frDest ; + if ( nRefId == GDB_ID_GRID) + frDest = pGeomDB->GetGridFrame() ; + else { + // nRefId può essere un gruppo o una entità + if ( ! pGeomDB->GetGroupGlobFrame( nRefId, frDest) && + ! pGeomDB->GetGlobFrame( nRefId, frDest)) + return false ; + } + // eseguo la trasformazione + return frF.LocToLoc( frSou, frDest) ; +} + +//---------------------------------------------------------------------------- +bool +ExeStartPoint( int nId, int nRefId, Point3d& ptP) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se non è entità geometrica + const IGeoObj* pGObj ; + if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) + return false ; + // se punto + if ( pGObj->GetType() == GEO_PNT3D) { + // recupero il geo-punto + const IGeoPoint3d* pGP = GetGeoPoint3d( pGObj) ; + // assegno il punto + ptP = pGP->GetPoint() ; + } + // se vettore + else if ( pGObj->GetType() == GEO_VECT3D) { + // recupero il geo-vettore + const IGeoVector3d* pGV = GetGeoVector3d( pGObj) ; + // assegno il punto + ptP = pGV->GetBase() ; + } + // se frame + else if ( pGObj->GetType() == GEO_FRAME3D) { + // recupero il frame + const IGeoFrame3d* pGF = GetGeoFrame3d( pGObj) ; + // assegno il punto + ptP = pGF->GetFrame().Orig() ; + } + // se curva + else if ( ( pGObj->GetType() & GEO_CURVE) != 0) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGObj) ; + // assegno il punto + if ( pCrv == nullptr || ! pCrv->GetStartPoint( ptP)) + return false ; + } + // se testo + else if ( pGObj->GetType() == EXT_TEXT) { + // recupero il testo + const IExtText* pTxt = GetExtText( pGObj) ; + // assegno il punto + if ( pTxt == nullptr || ! pTxt->GetStartPoint( ptP)) + return false ; + } + else + return false ; + // gestione trasformazione ( eventuale) + return TrasformPoint( pGeomDB, nId, nRefId, ptP) ; +} + +//---------------------------------------------------------------------------- +bool +ExeEndPoint( int nId, int nRefId, Point3d& ptP) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se non è entità geometrica + const IGeoObj* pGObj ; + if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) + return false ; + // se curva + if ( ( pGObj->GetType() & GEO_CURVE) != 0) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGObj) ; + if ( pCrv == nullptr || ! pCrv->GetEndPoint( ptP)) + return false ; + } + // se testo + else if ( pGObj->GetType() == EXT_TEXT) { + // recupero il testo + const IExtText* pTxt = GetExtText( pGObj) ; + if ( pTxt == nullptr || ! pTxt->GetEndPoint( ptP)) + return false ; + } + else + return false ; + // gestione trasformazione ( eventuale) + return TrasformPoint( pGeomDB, nId, nRefId, ptP) ; +} + +//---------------------------------------------------------------------------- +bool +ExeMidPoint( int nId, int nRefId, Point3d& ptP) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se non è entità geometrica + const IGeoObj* pGObj ; + if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) + return false ; + // se curva + if ( ( pGObj->GetType() & GEO_CURVE) != 0) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGObj) ; + // assegno il punto + if ( pCrv == nullptr || ! pCrv->GetMidPoint( ptP)) + return false ; + } + // se testo + else if ( pGObj->GetType() == EXT_TEXT) { + // recupero il testo + const IExtText* pTxt = GetExtText( pGObj) ; + // assegno il punto + if ( pTxt == nullptr || ! pTxt->GetMidPoint( ptP)) + return false ; + } + else + return false ; + // gestione trasformazione ( eventuale) + return TrasformPoint( pGeomDB, nId, nRefId, ptP) ; +} + +//---------------------------------------------------------------------------- +bool +ExeCenterPoint( int nId, int nRefId, Point3d& ptP) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se non è entità geometrica + const IGeoObj* pGObj ; + if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) + return false ; + // se curva + if ( ( pGObj->GetType() & GEO_CURVE) != 0) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGObj) ; + // assegno il punto + if ( pCrv == nullptr || ! pCrv->GetCenterPoint( ptP)) + return false ; + } + // se testo + else if ( pGObj->GetType() == EXT_TEXT) { + // recupero il testo + const IExtText* pTxt = GetExtText( pGObj) ; + // assegno il punto + if ( pTxt == nullptr || ! pTxt->GetCenterPoint( ptP)) + return false ; + } + else + return false ; + // gestione trasformazione ( eventuale) + return TrasformPoint( pGeomDB, nId, nRefId, ptP) ; +} + +//---------------------------------------------------------------------------- +bool +ExeCentroid( int nId, int nRefId, Point3d& ptP) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se non è entità geometrica + const IGeoObj* pGObj ; + if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) + return false ; + // se curva + if ( ( pGObj->GetType() & GEO_CURVE) != 0) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGObj) ; + // assegno il punto + if ( pCrv == nullptr || ! pCrv->GetCentroid( ptP)) + return false ; + } + // se superficie + else if ( ( pGObj->GetType() & GEO_SURF) != 0) { + // recupero la superficie + const ISurf* pSrf = GetSurf( pGObj) ; + // assegno il punto + if ( pSrf == nullptr || ! pSrf->GetCentroid( ptP)) + return false ; + } + // se testo + else if ( pGObj->GetType() == EXT_TEXT) { + // recupero il testo + const IExtText* pTxt = GetExtText( pGObj) ; + // assegno il punto + if ( pTxt == nullptr || ! pTxt->GetCenterPoint( ptP)) + return false ; + } + else + return false ; + // gestione trasformazione ( eventuale) + return TrasformPoint( pGeomDB, nId, nRefId, ptP) ; +} + +//---------------------------------------------------------------------------- +bool +ExeAtParamPoint( int nId, double dU, int nRefId, Point3d& ptP) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se non è entità geometrica + const IGeoObj* pGObj ; + if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) + return false ; + // se curva + if ( ( pGObj->GetType() & GEO_CURVE) != 0) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGObj) ; + if ( pCrv == nullptr || ! pCrv->GetPointD1D2( dU, ICurve::FROM_MINUS, ptP)) + return false ; + } + else + return false ; + // gestione trasformazione ( eventuale) + return TrasformPoint( pGeomDB, nId, nRefId, ptP) ; +} + +//---------------------------------------------------------------------------- +bool +ExeNearPoint( int nId, const Point3d& ptNear, int nRefId, Point3d& ptP) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se non è entità geometrica + const IGeoObj* pGObj = pGeomDB->GetGeoObj( nId) ; + if ( pGObj == nullptr) + return false ; + // porto il punto near nel riferimento dell'entità + Point3d ptNearL = ptNear ; + if ( ! InvTrasformPoint( pGeomDB, nId, nRefId, ptNearL)) + return false ; + // se curva + if ( ( pGObj->GetType() & GEO_CURVE) != 0) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGObj) ; + // calcolo il punto della curva più vicino al punto di riferimento + DistPointCurve dstPC( ptNearL, *pCrv) ; + int nFlag ; + if ( ! dstPC.GetMinDistPoint( 0, ptP, nFlag)) + return false ; + } + else + return false ; + // gestione trasformazione ( eventuale) + return TrasformPoint( pGeomDB, nId, nRefId, ptP) ; +} + +//---------------------------------------------------------------------------- +bool +ExeIntersectionPoint( int nId1, int nId2, const Point3d& ptNear, int nRefId, Point3d& ptP) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // devono essere entità geometriche + const IGeoObj* pGObj1 ; + if ( ( pGObj1 = pGeomDB->GetGeoObj( nId1)) == nullptr) + return false ; + const IGeoObj* pGObj2 ; + if ( ( pGObj2 = pGeomDB->GetGeoObj( nId2)) == nullptr) + return false ; + // se curve + if ( ( pGObj1->GetType() & GEO_CURVE) != 0 && ( pGObj2->GetType() & GEO_CURVE) != 0) { + // recupero le curve + const ICurve* pCrv1 = GetCurve( pGObj1) ; + const ICurve* pCrv2 = GetCurve( pGObj2) ; + // recupero i riferimenti in cui sono immerse + Frame3d frEnt1 ; + if ( ! pGeomDB->GetGlobFrame( nId1, frEnt1)) + return false ; + Frame3d frEnt2 ; + if ( ! pGeomDB->GetGlobFrame( nId2, frEnt2)) + return false ; + // se il riferimento della seconda curva è diverso da quello della prima entità, devo trasformarla + PtrOwner crvTrans( nullptr) ; + if ( ! AreSameFrame( frEnt1, frEnt2)) { + crvTrans.Set( pCrv2->Clone()) ; + if ( IsNull( crvTrans)) + return false ; + crvTrans->LocToLoc( frEnt2, frEnt1) ; + pCrv2 = ::Get( crvTrans) ; + } + // porto il punto Near nel riferimento della prima entità + Point3d ptNearL = ptNear ; + if ( ! InvTrasformPoint( pGeomDB, nId1, nRefId, ptNearL)) + return false ; + // calcolo il punto di intersezione sulla prima curva più vicino al punto di riferimento + IntersCurveCurve intCC( *pCrv1, *pCrv2, true) ; + if ( ! intCC.GetIntersPointNearTo( 0, ptNearL, ptP)) + return false ; + } + else + return false ; + // gestione trasformazione ( eventuale) + return TrasformPoint( pGeomDB, nId1, nRefId, ptP) ; +} + +//---------------------------------------------------------------------------- +bool +ExeStartVector( int nId, int nRefId, Vector3d& vtV) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se non è entità geometrica + const IGeoObj* pGObj = pGeomDB->GetGeoObj( nId) ; + if ( pGObj == nullptr) + return false ; + // se vettore + if ( pGObj->GetType() == GEO_VECT3D) { + // recupero il geo-vettore + const IGeoVector3d* pGV = GetGeoVector3d( pGObj) ; + // assegno il vettore + vtV = pGV->GetVector() ; + } + // se curva + else if ( ( pGObj->GetType() & GEO_CURVE) != 0) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGObj) ; + // assegno il vettore + if ( ! pCrv->GetStartDir( vtV)) + return false ; + } + // se testo + else if ( pGObj->GetType() == EXT_TEXT) { + // recupero il testo + const IExtText* pTxt = GetExtText( pGObj) ; + // assegno il vettore + vtV = pTxt->GetDirVersor() ; + } + else + return false ; + // gestione trasformazione ( eventuale) + return TrasformVector( pGeomDB, nId, nRefId, vtV) ; +} + +//---------------------------------------------------------------------------- +bool +ExeEndVector( int nId, int nRefId, Vector3d& vtV) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se non è entità geometrica + const IGeoObj* pGObj = pGeomDB->GetGeoObj( nId) ; + if ( pGObj == nullptr) + return false ; + // se curva + if ( ( pGObj->GetType() & GEO_CURVE) != 0) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGObj) ; + // assegno il vettore + if ( ! pCrv->GetEndDir( vtV)) + return false ; + } + else + return false ; + // gestione trasformazione ( eventuale) + return TrasformVector( pGeomDB, nId, nRefId, vtV) ; +} + +//---------------------------------------------------------------------------- +bool +ExeMidVector( int nId, int nRefId, Vector3d& vtV) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se non è entità geometrica + const IGeoObj* pGObj ; + if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) + return false ; + // se curva + if ( ( pGObj->GetType() & GEO_CURVE) != 0) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGObj) ; + // assegno il vettore + if ( ! pCrv->GetMidDir( vtV)) + return false ; + } + else + return false ; + // gestione trasformazione ( eventuale) + return TrasformVector( pGeomDB, nId, nRefId, vtV) ; +} + +//---------------------------------------------------------------------------- +bool +ExeAtParamVector( int nId, double dU, int nSide, int nRefId, Vector3d& vtV) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se non è entità geometrica + const IGeoObj* pGObj ; + if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) + return false ; + // se curva + if ( ( pGObj->GetType() & GEO_CURVE) != 0) { + // recupero la curva + const ICurve* pCrv = GetCurve( pGObj) ; + // assegno il lato di approccio + ICurve::Side nSide = ICurve::FROM_MINUS ; + if ( nSide > 0) + nSide = ICurve::FROM_PLUS ; + // recupero la direzione + Point3d ptP ; + if ( ! pCrv->GetPointTang( dU, nSide, ptP, vtV)) + return false ; + } + else + return false ; + // gestione trasformazione ( eventuale) + return TrasformVector( pGeomDB, nId, nRefId, vtV) ; +} + +//---------------------------------------------------------------------------- +bool +ExeFrame( int nId, int nRefId, Frame3d& frFrame) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se gruppo + if ( pGeomDB->GetGroupFrame( nId, frFrame)) + // gestione trasformazione ( eventuale) + return TrasformFrame( pGeomDB, nId, nRefId, frFrame) ; + // se geo frame + const IGeoObj* pGObj ; + if ( ( pGObj = pGeomDB->GetGeoObj( nId)) != nullptr && + pGObj->GetType() == GEO_FRAME3D) { + frFrame = GetGeoFrame3d( pGObj)->GetFrame() ; + // gestione trasformazione ( eventuale) + return TrasformFrame( pGeomDB, nId, nRefId, frFrame) ; + } + // errore + return false ; +} + +//---------------------------------------------------------------------------- +bool +ExeCurveLength( int nId, double* pdLen) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pdLen == nullptr) + return false ; + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve == nullptr) + return false ; + // recupero la lunghezza + return pCurve->GetLength( *pdLen) ; +} + +//---------------------------------------------------------------------------- +bool +ExeCurveLengthAtPoint( int nId, const Point3d& ptOn, double dExtend, double* pdLen) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pdLen == nullptr) + return false ; + // recupero la curva + const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve == nullptr) + return false ; + // determino la posizione parametrica del punto sulla curva (con tolleranza) + int nFlag ; + double dU ; + if ( ! DistPointCurve( ptOn, *pCurve).GetParamAtMinDistPoint( 0, dU, nFlag) || nFlag != MDPCI_NORMAL) + return false ; + // se non richiesta estensione o punto interno alla curva, recupero la lunghezza alla posizione parametrica + if ( dExtend < EPS_SMALL || + ( ! pCurve->IsStartParam( dU) && ! pCurve->IsEndParam( dU))) + return ( pCurve->GetLengthAtParam( dU, *pdLen) ? true : false) ; + // allungo la curva dalla parte del punto + PtrOwner pCopy( pCurve->Clone()) ; + if ( IsNull( pCopy)) + return false ; + double dDeltaIni ; + if ( pCopy->IsStartParam( dU)) { + pCopy->ExtendStartByLen( dExtend) ; + dDeltaIni = dExtend ; + } + else { + pCopy->ExtendEndByLen( dExtend) ; + dDeltaIni = 0 ; + } + if ( ! DistPointCurve( ptOn, *pCopy).GetParamAtMinDistPoint( 0, dU, nFlag) || nFlag != MDPCI_NORMAL) + return false ; + if ( pCopy->GetLengthAtParam( dU, *pdLen)) { + *pdLen -= dDeltaIni ; + return true ; + } + return false ; +} + +//---------------------------------------------------------------------------- +bool +ExeCurveExtrusion( int nId, int nRefId, Vector3d& vtExtr) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + // ne ricavo il vettore estrusione + if ( pCurve == nullptr || ! pCurve->GetExtrusion( vtExtr)) + return false ; + // gestione trasformazione ( eventuale) + return TrasformVector( pGeomDB, nId, nRefId, vtExtr) ; +} + +//---------------------------------------------------------------------------- +bool +ExeCurveThickness( int nId, double* pdThick) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pdThick == nullptr) + return false ; + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + // recupero lo spessore + return ( pCurve != nullptr && pCurve->GetThickness( *pdThick)) ; +} + +//---------------------------------------------------------------------------- +bool +ExeGetMinDistPointCurve( const Point3d& ptP, int nId, double* pdDist) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico i parametri + if ( pdDist == nullptr) + return false ; + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve == nullptr) + return false ; + // calcolo la minima distanza + DistPointCurve distPC( ptP, *pCurve) ; + return distPC.GetDist( *pdDist) ; +} + +//---------------------------------------------------------------------------- +bool +ExeGetMinDistPntSidePointCurve( const Point3d& ptP, int nId, const Vector3d& vtN, + double* pdDist, Point3d& ptMin, int* pnSide) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico i parametri + if ( pdDist == nullptr || pnSide == nullptr || &ptMin == nullptr) + return false ; + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCurve == nullptr) + return false ; + // calcolo la minima distanza + DistPointCurve distPC( ptP, *pCurve) ; + // recupero i risultati + int nFlag ; + return ( distPC.GetDist( *pdDist) && + distPC.GetMinDistPoint( 0, ptMin, nFlag) && + distPC.GetSideAtMinDistPoint( 0, vtN, *pnSide)) ; +} + +//---------------------------------------------------------------------------- +bool +ExeCurveArcRadius( int nId, double* pdRad) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pdRad == nullptr) + return false ; + // recupero l'arco + const ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ; + if ( pArc == nullptr) + return false ; + *pdRad = pArc->GetRadius() ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +ExeCurveArcNormVersor( int nId, int nRefId, Vector3d& vtNorm) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero l'arco + const ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ; + if ( pArc == nullptr) + return false ; + // recupero la normale + vtNorm = pArc->GetNormVersor() ; + // gestione trasformazione ( eventuale) + return TrasformVector( pGeomDB, nId, nRefId, vtNorm) ; +} + +//---------------------------------------------------------------------------- +bool +ExeCurveCompoCenter( int nId, int nSimpCrv, int nRefId, Point3d& ptCen) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva composita + const ICurveComposite* pCompoCrv = GetCurveComposite( pGeomDB->GetGeoObj( nId)) ; + if ( pCompoCrv == nullptr) + return false ; + // recupero la curva semplice di indice richiesto + const ICurve* pSimpCrv = pCompoCrv->GetCurve( nSimpCrv) ; + if ( pSimpCrv == nullptr) + return false ; + // recupero il centro + if ( ! pSimpCrv->GetCenterPoint( ptCen)) + return false ; + // gestione trasformazione ( eventuale) + return TrasformPoint( pGeomDB, nId, nRefId, ptCen) ; +} + +//---------------------------------------------------------------------------- +int +ExeSurfTmFacetNbr( int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, 0) + // recupero la superficie trimesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + if ( pStm == nullptr) + return 0 ; + // recupero il numero delle facce + return pStm->GetFacetNum() ; +} + +//---------------------------------------------------------------------------- +int +ExeSurfTmFacetFromTria( int nId, int nT) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, SVT_NULL) + // recupero la superficie trimesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + if ( pStm == nullptr) + return SVT_NULL ; + // recupero il numero della faccia da quello di un suo triangolo + return pStm->GetFacetFromTria( nT) ; +} + +//---------------------------------------------------------------------------- +bool +ExeSurfTmFacetNearestEndPoint( int nId, int nFacet, const Point3d& ptNear, int nRefId, + Point3d& ptEnd, Vector3d& vtN) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la superficie trimesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + if ( pStm == nullptr) + return false ; + // porto il punto Near nel riferimento dell'entità + Point3d ptNearL = ptNear ; + if ( ! InvTrasformPoint( pGeomDB, nId, nRefId, ptNearL)) + return false ; + // recupero il punto End più vicino della faccia + if ( ! pStm->GetFacetNearestEndPoint( nFacet, ptNearL, ptEnd, vtN)) + return false ; + // gestione trasformazioni ( eventuali) + return TrasformPoint( pGeomDB, nId, nRefId, ptEnd) && TrasformVector( pGeomDB, nId, nRefId, vtN) ; +} + +//---------------------------------------------------------------------------- +bool +ExeSurfTmFacetNearestMidPoint( int nId, int nFacet, const Point3d& ptNear, int nRefId, + Point3d& ptMid, Vector3d& vtN) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la superficie trimesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + if ( pStm == nullptr) + return false ; + // porto il punto Near nel riferimento dell'entità + Point3d ptNearL = ptNear ; + if ( ! InvTrasformPoint( pGeomDB, nId, nRefId, ptNearL)) + return false ; + // recupero il punto Mid più vicino della faccia + if ( ! pStm->GetFacetNearestMidPoint( nFacet, ptNearL, ptMid, vtN)) + return false ; + // gestione trasformazioni ( eventuali) + return TrasformPoint( pGeomDB, nId, nRefId, ptMid) && TrasformVector( pGeomDB, nId, nRefId, vtN) ; +} + +//---------------------------------------------------------------------------- +bool +ExeSurfTmFacetCenter( int nId, int nFacet, int nRefId, Point3d& ptCen, Vector3d& vtN) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la superficie trimesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + if ( pStm == nullptr) + return false ; + // recupero il centro della faccia + if ( ! pStm->GetFacetCenter( nFacet, ptCen, vtN)) + return false ; + // gestione trasformazioni ( eventuali) + return TrasformPoint( pGeomDB, nId, nRefId, ptCen) && TrasformVector( pGeomDB, nId, nRefId, vtN) ; +} + +//---------------------------------------------------------------------------- +bool +ExeSurfTmFacetNormVersor( int nId, int nFacet, int nRefId, Vector3d& vtNorm) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la superficie trimesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + if ( pStm == nullptr) + return false ; + // recupero il centro della faccia + if ( ! pStm->GetFacetNormal( nFacet, vtNorm)) + return false ; + // gestione trasformazione ( eventuale) + return TrasformVector( pGeomDB, nId, nRefId, vtNorm) ; +} + +//---------------------------------------------------------------------------- +bool +ExeExtTextNormVersor( int nId, int nRefId, Vector3d& vtNorm) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero il testo + const IExtText* pTxt = GetExtText( pGeomDB->GetGeoObj( nId)) ; + if ( pTxt == nullptr) + return false ; + // recupero la normale + vtNorm = pTxt->GetNormVersor() ; + // gestione trasformazione ( eventuale) + return TrasformVector( pGeomDB, nId, nRefId, vtNorm) ; +} + + +//------------------------------------------------------------------------------- +// Geo Transforms +//------------------------------------------------------------------------------- +bool +ExePointToIdGlob( Point3d& ptP, int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se griglia + if ( nId == GDB_ID_GRID) + return ptP.ToGlob( pGeomDB->GetGridFrame()) ; + // recupero il riferimento + // se gruppo -> il suo proprio espresso in globale + // se oggetto -> quello del gruppo cui appartiene in globale + Frame3d frRef ; + if ( ! pGeomDB->GetGroupGlobFrame( nId, frRef) && + ! pGeomDB->GetGlobFrame( nId, frRef)) + return false ; + // eseguo la trasformazione + return ptP.ToGlob( frRef) ; +} + +//------------------------------------------------------------------------------- +bool +ExePointToIdLoc( Point3d& ptP, int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se griglia + if ( nId == GDB_ID_GRID) + return ptP.ToLoc( pGeomDB->GetGridFrame()) ; + // recupero il riferimento + // se gruppo -> il suo proprio espresso in globale + // se oggetto -> quello del gruppo cui appartiene in globale + Frame3d frRef ; + if ( ! pGeomDB->GetGroupGlobFrame( nId, frRef) && + ! pGeomDB->GetGlobFrame( nId, frRef)) + return false ; + // eseguo la trasformazione + return ptP.ToLoc( frRef) ; +} + +//------------------------------------------------------------------------------- +bool +ExeVectorToIdGlob( Vector3d& vtV, int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se griglia + if ( nId == GDB_ID_GRID) + return vtV.ToGlob( pGeomDB->GetGridFrame()) ; + // recupero il riferimento + // se gruppo -> il suo proprio espresso in globale + // se oggetto -> quello del gruppo cui appartiene in globale + Frame3d frRef ; + if ( ! pGeomDB->GetGroupGlobFrame( nId, frRef) && + ! pGeomDB->GetGlobFrame( nId, frRef)) + return false ; + // eseguo la trasformazione + return vtV.ToGlob( frRef) ; +} + +//------------------------------------------------------------------------------- +bool +ExeVectorToIdLoc( Vector3d& vtV, int nId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // se griglia + if ( nId == GDB_ID_GRID) + return vtV.ToLoc( pGeomDB->GetGridFrame()) ; + // recupero il riferimento + // se gruppo -> il suo proprio espresso in globale + // se oggetto -> quello del gruppo cui appartiene in globale + Frame3d frRef ; + if ( ! pGeomDB->GetGroupGlobFrame( nId, frRef) && + ! pGeomDB->GetGlobFrame( nId, frRef)) + return false ; + // eseguo la trasformazione + return vtV.ToLoc( frRef) ; +} diff --git a/EXE_GeoTransform.cpp b/EXE_GeoTransform.cpp new file mode 100644 index 0000000..02d5499 --- /dev/null +++ b/EXE_GeoTransform.cpp @@ -0,0 +1,384 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : EXE_GeoTransform.cpp Data : 04.05.15 Versione : 1.6e1 +// Contenuto : Funzioni di trasformazione geometrica per EXE. +// +// +// +// Modifiche : 30.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "AuxTools.h" +#include "GeoTools.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +bool +ExeMove( INTVECTOR& vIds, const Vector3d& vtMove, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // se traslazione espressa in locale + if ( nRefType == RTY_LOC) { + // verifico che tutti gli oggetti siano nello stesso riferimento + bOk = bOk && VerifySameFrame( pGeomDB, vIds) ; + // ciclo sul vettore degli identificativi + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // eseguo traslazione + if ( ! pGeomDB->Translate( nId, vtMove)) + bOk = false ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + } + // altrimenti in globale o in griglia + else { + Vector3d vtMoveG = vtMove ; + // se griglia, porto il vettore in globale + if ( nRefType == RTY_GRID) + vtMoveG.ToGlob( pGeomDB->GetGridFrame()) ; + // ciclo sul vettore degli identificativi + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // eseguo traslazione + if ( ! pGeomDB->TranslateGlob( nId, vtMoveG)) + bOk = false ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtMove({" + IdListToString( vIds) + "},{" + + ToString( vtMove) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//------------------------------------------------------------------------------- +bool +ExeRotate( INTVECTOR& vIds, const Point3d& ptAx, const Vector3d& vtAx, double dAngRotDeg, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // se rotazione espressa in locale + if ( nRefType == RTY_LOC) { + // verifico che tutti gli oggetti siano nello stesso riferimento + bOk = bOk && VerifySameFrame( pGeomDB, vIds) ; + // ciclo sul vettore degli identificativi + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // eseguo rotazione + if ( ! pGeomDB->Rotate( nId, ptAx, vtAx, dAngRotDeg)) + bOk = false ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + } + // altrimenti in globale o in griglia + else { + Point3d ptAxG = ptAx ; + Vector3d vtAxG = vtAx ; + // se griglia, porto punto e vettore in globale + if ( nRefType == RTY_GRID) { + ptAxG.ToGlob( pGeomDB->GetGridFrame()) ; + vtAxG.ToGlob( pGeomDB->GetGridFrame()) ; + } + // ciclo sul vettore degli identificativi + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // eseguo rotazione + if ( ! pGeomDB->RotateGlob( nId, ptAxG, vtAxG, dAngRotDeg)) + bOk = false ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtRotate({" + IdListToString( vIds) + "},{" + + ToString( ptAx) + "},{" + + ToString( vtAx) + "}," + + ToString( dAngRotDeg) + "," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//------------------------------------------------------------------------------- +bool +ExeScale( INTVECTOR& vIds, const Frame3d& frRef, + double dCoeffX, double dCoeffY, double dCoeffZ, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + bool bOk = true ; + // se scalatura espressa in locale + if ( nRefType == RTY_LOC) { + // verifico che tutti gli oggetti siano nello stesso riferimento + bOk = bOk && VerifySameFrame( pGeomDB, vIds) ; + // ciclo sul vettore degli identificativi + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // eseguo scalature + if ( ! pGeomDB->Scale( nId, frRef, dCoeffX, dCoeffY, dCoeffZ)) + bOk = false ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + } + // altrimenti in globale o in griglia + else { + Frame3d frRefG = frRef ; + // se griglia, porto riferimento in globale + if ( nRefType == RTY_GRID) + frRefG.ToGlob( pGeomDB->GetGridFrame()) ; + // ciclo sul vettore degli identificativi + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // eseguo scalature + if ( ! pGeomDB->ScaleGlob( nId, frRefG, dCoeffX, dCoeffY, dCoeffZ)) + bOk = false ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtScale({" + IdListToString( vIds) + "},{{" + + ToString( frRef.Orig()) + "},{" + + ToString( frRef.VersX()) + "},{" + + ToString( frRef.VersY()) + "},{" + + ToString( frRef.VersZ()) + "}}," + + ToString( dCoeffX) + "," + + ToString( dCoeffY) + "," + + ToString( dCoeffZ) + "," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//------------------------------------------------------------------------------- +bool +ExeMirror( INTVECTOR& vIds, const Point3d& ptP, const Vector3d& vtN, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, FALSE) + bool bOk = true ; + // se specularità espressa in locale + if ( nRefType == RTY_LOC) { + // verifico che tutti gli oggetti siano nello stesso riferimento + bOk = bOk && VerifySameFrame( pGeomDB, vIds) ; + // ciclo sul vettore degli identificativi + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // eseguo riflessione + if ( ! pGeomDB->Mirror( nId, ptP, vtN)) + bOk = false ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + } + // altrimenti in globale o in griglia + else { + Point3d ptPG = ptP ; + Vector3d vtNG = vtN ; + // se griglia, porto riferimento in globale + if ( nRefType == RTY_GRID) { + ptPG.ToGlob( pGeomDB->GetGridFrame()) ; + vtNG.ToGlob( pGeomDB->GetGridFrame()) ; + } + // ciclo sul vettore degli identificativi + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // eseguo riflessione + if ( ! pGeomDB->MirrorGlob( nId, ptPG, vtNG)) + bOk = false ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtMirror({" + IdListToString( vIds) + "},{" + + ToString( ptP) + "},{" + + ToString( vtN) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//------------------------------------------------------------------------------- +bool +ExeShear( INTVECTOR& vIds, const Point3d& ptP, const Vector3d& vtN, + const Vector3d& vtDir, double dCoeff, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, FALSE) + bool bOk = true ; + // se stiramento espresso in locale + if ( nRefType == RTY_LOC) { + // verifico che tutti gli oggetti siano nello stesso riferimento + bOk = bOk && VerifySameFrame( pGeomDB, vIds) ; + // ciclo sul vettore degli identificativi + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // eseguo stiramento + if ( ! pGeomDB->Shear( nId, ptP, vtN, vtDir, dCoeff)) + bOk = false ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + } + // altrimenti in globale o in griglia + else { + Point3d ptPG = ptP ; + Vector3d vtNG = vtN ; + Vector3d vtDirG = vtDir ; + // se griglia, porto riferimento in globale + if ( nRefType == RTY_GRID) { + ptPG.ToGlob( pGeomDB->GetGridFrame()) ; + vtNG.ToGlob( pGeomDB->GetGridFrame()) ; + vtDirG.ToGlob( pGeomDB->GetGridFrame()) ; + } + // ciclo sul vettore degli identificativi + for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) { + int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ; + while ( nId != GDB_ID_NULL) { + // eseguo stiramento + if ( ! pGeomDB->ShearGlob( nId, ptPG, vtNG, vtDirG, dCoeff)) + bOk = false ; + // passo alla successiva + nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ; + } + } + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtShear({" + IdListToString( vIds) + "},{" + + ToString( ptP) + "},{" + + ToString( vtN) + "},{" + + ToString( vtDir) + "}," + + ToString( dCoeff) + "," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} + +//------------------------------------------------------------------------------- +bool +ExeMoveGroup( int nId, const Vector3d& vtMove) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // eseguo traslazione ( solo singola) + bool bOk = pGeomDB->TranslateGroup( nId, vtMove) ; + ExeSetModified() ; + // restituisco risultato + return bOk ; +} + +//------------------------------------------------------------------------------- +bool +ExeRotateGroup( int nId, const Point3d& ptAx, const Vector3d& vtAx, double dAngRotDeg) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // eseguo rotazione ( solo singola) + bool bOk = pGeomDB->RotateGroup( nId, ptAx, vtAx, dAngRotDeg) ; + ExeSetModified() ; + // restituisco risultato + return bOk ; +} + +//------------------------------------------------------------------------------- +bool +ExeScaleGroup( int nId, const Frame3d& frFrame, double dCoeffX, double dCoeffY, double dCoeffZ) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // eseguo scalatura ( solo singola) + bool bOk = pGeomDB->ScaleGroup( nId, frFrame, dCoeffX, dCoeffY, dCoeffZ) ; + ExeSetModified() ; + // restituisco risultato + return bOk ; +} + +//------------------------------------------------------------------------------- +bool +ExeMirrorGroup( int nId, const Point3d& ptP, const Vector3d& vtN) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // eseguo riflessione ( solo singola) + bool bOk = pGeomDB->MirrorGroup( nId, ptP, vtN) ; + ExeSetModified() ; + // restituisco risultato + return bOk ; +} + +//------------------------------------------------------------------------------- +bool +ExeShearGroup( int nId, const Point3d& ptP, const Vector3d& vtN, const Vector3d& vtDir, double dCoeff) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // eseguo stiramento ( solo singolo) + bool bOk = pGeomDB->ShearGroup( nId, ptP, vtN, vtDir, dCoeff) ; + ExeSetModified() ; + // restituisco risultato + return bOk ; +} diff --git a/EXE_GeomDB.cpp b/EXE_GeomDB.cpp new file mode 100644 index 0000000..ba19307 --- /dev/null +++ b/EXE_GeomDB.cpp @@ -0,0 +1,379 @@ +//---------------------------------------------------------------------------- +// 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/EGnStringConverter.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 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 ; +} diff --git a/EXE_Lua.cpp b/EXE_Lua.cpp new file mode 100644 index 0000000..3b8bc3b --- /dev/null +++ b/EXE_Lua.cpp @@ -0,0 +1,113 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : EXE_LUA.cpp Data : 05.05.15 Versione : 1.6e1 +// Contenuto : Funzioni esecuzione LUA per EXE. +// +// +// +// Modifiche : 28.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "LUA_Base.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGnStringUtils.h" +#include "/EgtDev/Include/EGnStringConverter.h" + +using namespace std ; + +//----------------------------------------------------------------------------- +bool +ExeLuaEvalNumExpr( const string& sExpr, double* pdVal) +{ + // verifico parametro di ritorno + if ( pdVal == nullptr) + return false ; + // valuto l'espressione + return LuaEvalNumExpr( sExpr, *pdVal) ; +} + +//----------------------------------------------------------------------------- +bool +ExeLuaEvalStringExpr( const string& sExpr, string& sVal) +{ + // verifico parametro di ritorno + if ( &sVal == nullptr) + return false ; + // valuto l'espressione + return LuaEvalStringExpr( sExpr, sVal) ; +} + +//----------------------------------------------------------------------------- +bool +ExeLuaExecLine( const string& sLine) +{ + // disabilito log dei comandi e salvo stato precedente + bool bPrevCmdLog = SetCmdLog( false) ; + // eseguo il comando + bool bOk = LuaExecLine( sLine) ; + // ripristino lo stato originale del log dei comandi + SetCmdLog( bPrevCmdLog) ; + // se richiesto, salvo il comando Lua + if ( IsCmdLog()) { + string sLua = sLine + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeLuaExecFile( const string& sFilePath) +{ + // emetto info + string sInfo = "Exec File = " + sFilePath ; + LOG_INFO( GetLogger(), sInfo.c_str()) + // disabilito il log dei comandi + bool bPrevCmdLog = IsCmdLog() ; + ExeDisableCommandLogger() ; + // esecuzione script + bool bOk = LuaExecFile( sFilePath) ; + // ripristino lo stato originale del log dei comandi + if ( bPrevCmdLog) + ExeEnableCommandLogger() ; + // se richiesto, salvo il comando Lua + if ( IsCmdLog()) { + string sLuaPath = sFilePath ; + ReplaceString( sLuaPath, "\\", "\\\\") ; + string sLua = "dofile('" + sLuaPath + "')" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeLuaRequire( const string& sFilePath) +{ + // emetto info + string sInfo = "Require Library = " + sFilePath ; + LOG_INFO( GetLogger(), sInfo.c_str()) + // eseguo il comando + return LuaRequire( sFilePath) ; +} + +//----------------------------------------------------------------------------- +bool +ExeLuaGetLastError( string& sError) +{ + // verifico parametro di ritorno + if ( &sError == nullptr) + return false ; + sError = LuaGetLastError() ; + return true ; +} diff --git a/EXE_MachMgr.cpp b/EXE_MachMgr.cpp new file mode 100644 index 0000000..84c1672 --- /dev/null +++ b/EXE_MachMgr.cpp @@ -0,0 +1,511 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : EXE_MachMgr.cpp Data : 05.05.15 Versione : 1.6e1 +// Contenuto : Funzioni Machining Manager per EXE. +// +// +// +// Modifiche : 23.03.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "AuxTools.h" +#include "DllMachKernel.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//----------------------------------------------------------------------------- +bool +ExeInitMachMgr( const string& sMachinesDir) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX( pGseCtx, false) + // inizializzazione gestore lavorazioni + PtrOwner pMachMgr( MyCreateMachMgr()) ; + VERIFY_NULL( Get( pMachMgr), "Error in CreateMachMgr", false) + bool bOk = pMachMgr->Init( pGseCtx->m_pGeomDB, sMachinesDir) ; + // assegno il gestore al contesto + pGseCtx->m_pMachMgr = ( bOk ? Release( pMachMgr) : nullptr) ; + // log avvio Machining Manager + string sLog = "MachMgr " ; + sLog += ( bOk ? " started" : " error") ; + sLog += " (" + sMachinesDir + ")" ; + LOG_INFO( GetLogger(), sLog.c_str()) + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeUpdateMachMgr( void) +{ + IMachMgr* pMachMgr = GetCurrMachMgr() ; + VERIFY_MACHMGR( pMachMgr, false) + // aggiornamento gestore lavorazioni + return pMachMgr->Update() ; +} + +//----------------------------------------------------------------------------- +bool +ExeInsertMachMgr( int nInsGrp) +{ + IMachMgr* pMachMgr = GetCurrMachMgr() ; + VERIFY_MACHMGR( pMachMgr, false) + // sposto le macchinate dal gruppo di inserimento alla base macchinate + return pMachMgr->Insert( nInsGrp) ; +} + +//----------------------------------------------------------------------------- +int +ExeGetMachGroupNbr( void) +{ + IMachMgr* pMachMgr = GetCurrMachMgr() ; + VERIFY_MACHMGR( pMachMgr, 0) + // recupero il numero di macchinate + return pMachMgr->GetMachGroupNbr() ; +} + +//----------------------------------------------------------------------------- +int +ExeGetFirstMachGroup( void) +{ + IMachMgr* pMachMgr = GetCurrMachMgr() ; + VERIFY_MACHMGR( pMachMgr, GDB_ID_NULL) + // recupero la prima macchinata + return pMachMgr->GetFirstMachGroup() ; +} + +//----------------------------------------------------------------------------- +int +ExeGetNextMachGroup( int nId) +{ + IMachMgr* pMachMgr = GetCurrMachMgr() ; + VERIFY_MACHMGR( pMachMgr, GDB_ID_NULL) + // recupero la successiva macchinata + return pMachMgr->GetNextMachGroup( nId) ; +} + +//----------------------------------------------------------------------------- +int +ExeAddMachGroup( const string& sName, const string& sMachineName) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, GDB_ID_NULL) + // aggiungo la macchinata (gruppo di lavorazione) + int nId = pGseCtx->m_pMachMgr->AddMachGroup( sName, sMachineName) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtAddMachGroup('" + sName + "','" + + sMachineName + "')" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return nId ; +} + +//----------------------------------------------------------------------------- +bool +ExeRemoveMachGroup( int nMGroupId) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // rimuovo la macchinata (gruppo di lavorazione) + bool bOk = pGseCtx->m_pMachMgr->RemoveMachGroup( nMGroupId) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtRemoveMachGroup(" + ToString( nMGroupId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetMachGroupName( int nId, string& sName) +{ + IMachMgr* pMachMgr = GetCurrMachMgr() ; + VERIFY_MACHMGR( pMachMgr, false) + // recupero il nome della macchinata + sName = pMachMgr->GetMachGroupName( nId) ; + return ( ! sName.empty()) ; +} + +//----------------------------------------------------------------------------- +int +ExeGetMachGroupId( const string& sName) +{ + IMachMgr* pMachMgr = GetCurrMachMgr() ; + VERIFY_MACHMGR( pMachMgr, false) + // recupero l'indice della macchinata + return pMachMgr->GetMachGroupId( sName) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetCurrMachGroup( int nMGroupId) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // imposto la macchinata corrente + bool bOk = pGseCtx->m_pMachMgr->SetCurrMachGroup( nMGroupId) ; + // non cambia lo stato di modificato del progetto + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSetCurrMachGroup(" + ToString( nMGroupId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeResetCurrMachGroup( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // reset macchinata corrente + bool bOk = pGseCtx->m_pMachMgr->ResetCurrMachGroup() ; + // non cambia lo stato di modificato del progetto + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtResetCurrMachGroup()" + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +int +ExeGetCurrMachGroup( void) +{ + IMachMgr* pMachMgr = GetCurrMachMgr() ; + VERIFY_MACHMGR( pMachMgr, GDB_ID_NULL) + // restituisco identificativo macchinata corrente + return pMachMgr->GetCurrMachGroup() ; +} + +//----------------------------------------------------------------------------- +int +ExeGetRawPartNbr( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // recupero il numero di grezzi nella macchinata corrente + return pGseCtx->m_pMachMgr->GetRawPartNbr() ; +} + +//----------------------------------------------------------------------------- +int +ExeGetFirstRawPart( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // recupero identificativo primo grezzo nella macchinata corrente + return pGseCtx->m_pMachMgr->GetFirstRawPart() ; +} + +//----------------------------------------------------------------------------- +int +ExeGetNextRawPart( int nRawId) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // recupero identificativo successivo grezzo nella macchinata corrente + return pGseCtx->m_pMachMgr->GetNextRawPart( nRawId) ; +} + +//----------------------------------------------------------------------------- +int +ExeAddRawPart( Point3d ptOrig, double dWidth, double dLength, double dHeight, Color cCol) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, GDB_ID_NULL) + // inserisco grezzo nella macchinata corrente + int nId = pGseCtx->m_pMachMgr->AddRawPart( ptOrig, dWidth, dLength, dHeight, cCol) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtAddRawPart({" + ToString( ptOrig) + "}," + + ToString( dWidth) + "," + + ToString( dLength) + "," + + ToString( dHeight) + ",{" + + ToString( cCol) + "})" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return nId ; +} + +//----------------------------------------------------------------------------- +int +ExeAddRawPartWithPart( int nPartId, int nCrvId, double dOverMat, Color cCol) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, GDB_ID_NULL) + // inserisco grezzo con pezzo nella macchinata corrente + int nId = pGseCtx->m_pMachMgr->AddRawPartWithPart( nPartId, nCrvId, dOverMat, cCol) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtAddRawPartWithPart(" + ToString( nPartId) + "," + + ToString( nCrvId) + "," + + ToString( dOverMat) + ",{" + + ToString( cCol) + "})" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return nId ; +} + +//----------------------------------------------------------------------------- +bool +ExeModifyRawPartHeight( int nRawId, double dHeight) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // modifico lo spessore del grezzo + bool bOk = pGseCtx->m_pMachMgr->ModifyRawPartHeight( nRawId, dHeight) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtModifyRawPartHeight(" + ToString( nRawId) + "," + + ToString( dHeight) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeRemoveRawPart( int nRawId) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // elimino grezzo dalla macchinata corrente + bool bOk = pGseCtx->m_pMachMgr->RemoveRawPart( nRawId) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtRemoveRawPart(" + ToString( nRawId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeTranslateRawPart( int nRawId, const Vector3d& vtMove) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // traslo il grezzo + bool bOk = pGseCtx->m_pMachMgr->TranslateRawPart( nRawId, vtMove) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtMoveRawPart(" + ToString( nRawId) + ",{" + + ToString( vtMove) + "})" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeRotateRawPart( int nRawId, const Vector3d& vtAx, double dAngRotDeg) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // ruoto il grezzo + bool bOk = pGseCtx->m_pMachMgr->RotateRawPart( nRawId, vtAx, dAngRotDeg) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtRotateRawPart(" + ToString( nRawId) + ",{" + + ToString( vtAx) + "}," + + ToString( dAngRotDeg) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeMoveToCornerRawPart( int nRawId, const Point3d& ptCorner, int nFlag) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // mando il grezzo nel corner + bool bOk = pGseCtx->m_pMachMgr->MoveToCornerRawPart( nRawId, ptCorner, nFlag) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtMoveToCornerRawPart(" + ToString( nRawId) + ",{" + + ToString( ptCorner) + "}," + + RawPartCornerPosToString( nFlag) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeMoveToCenterRawPart( int nRawId, const Point3d& ptCenter, int nFlag) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // mando il grezzo nel corner + bool bOk = pGseCtx->m_pMachMgr->MoveToCenterRawPart( nRawId, ptCenter, nFlag) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtMoveToCenterRawPart(" + ToString( nRawId) + ",{" + + ToString( ptCenter) + "}," + + RawPartCenterPosToString( nFlag) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +int +ExeGetPartInRawPartNbr( int nRawId) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // recupero il numero di pezzi nel grezzo + return pGseCtx->m_pMachMgr->GetPartInRawPartNbr( nRawId) ; +} + +//----------------------------------------------------------------------------- +int +ExeGetFirstPartInRawPart( int nRawId) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // recupero identificativo primo pezzo nel grezzo + return pGseCtx->m_pMachMgr->GetFirstPartInRawPart( nRawId) ; +} + +//----------------------------------------------------------------------------- +int +ExeGetNextPartInRawPart( int nPartId) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // recupero identificativo successivo pezzo nello stesso grezzo + return pGseCtx->m_pMachMgr->GetNextPartInRawPart( nPartId) ; +} + +//----------------------------------------------------------------------------- +bool +ExeAddPartToRawPart( int nPartId, const Point3d& ptPos, int nRawId) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // inserisco pezzo in un grezzo della macchinata corrente + bool bOk = pGseCtx->m_pMachMgr->AddPartToRawPart( nPartId, ptPos, nRawId) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtAddPartToRawPart(" + ToString( nPartId) + ",{" + + ToString( ptPos) + "}," + + ToString( nRawId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeRemovePartFromRawPart( int nPartId) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // elimino pezzo da grezzo della macchinata corrente + bool bOk = pGseCtx->m_pMachMgr->RemovePartFromRawPart( nPartId) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtRemovePartFromRawPart(" + ToString( nPartId) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeTranslatePartInRawPart( int nPartId, const Vector3d& vtMove) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // traslo il pezzo nel grezzo + bool bOk = pGseCtx->m_pMachMgr->TranslatePartInRawPart( nPartId, vtMove) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtMovePartInRawPart(" + ToString( nPartId) + ",{" + + ToString( vtMove) + "})" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +ExeRotatePartInRawPart( int nPartId, const Vector3d& vtAx, double dAngRotDeg) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_MACHMGR( pGseCtx, false) + // ruoto il pezzo nel grezzo + bool bOk = pGseCtx->m_pMachMgr->RotatePartInRawPart( nPartId, vtAx, dAngRotDeg) ; + pGseCtx->m_bModified = true ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtRotatePartInRawPart(" + ToString( nPartId) + ",{" + + ToString( vtAx) + "}," + + ToString( dAngRotDeg) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco il risultato + return bOk ; +} diff --git a/EXE_Macro.h b/EXE_Macro.h new file mode 100644 index 0000000..0c1d3fc --- /dev/null +++ b/EXE_Macro.h @@ -0,0 +1,51 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : EXE_Macro Data : 05.05.15 Versione : 1.6e2 +// Contenuto : Macro locali per moduli EXE. +// +// +// +// Modifiche : 03.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + + +//----------------------------------------------------------------------------- +#define VERIFY_NULL( pO, Msg, Ret) if ( pO == nullptr) { \ + LOG_ERROR( GetLogger(), Msg " (" __FUNCTION__ ")") \ + return Ret ; \ + } + +//----------------------------------------------------------------------------- +#define VERIFY_2NULL( pO, pQ, Msg, Ret) if ( pO == nullptr || pQ == nullptr) { \ + LOG_ERROR( GetLogger(), Msg " (" __FUNCTION__ ")") \ + return Ret ; \ + } + +//----------------------------------------------------------------------------- +#define VERIFY_CTX( pC, Ret) VERIFY_NULL( pC, "Context invalid", Ret) + +//----------------------------------------------------------------------------- +#define VERIFY_GEOMDB( pG, Ret) VERIFY_NULL( pG, "GeomDB invalid", Ret) + +//----------------------------------------------------------------------------- +#define VERIFY_CTX_GEOMDB( pC, Ret) VERIFY_2NULL( pC, pC->m_pGeomDB, "Context or GeomDB invalid", Ret) + +//----------------------------------------------------------------------------- +#define VERIFY_MACHMGR( pM, Ret) VERIFY_NULL( pM, "MachMgr invalid", Ret) + +//----------------------------------------------------------------------------- +#define VERIFY_CTX_MACHMGR( pC, Ret) VERIFY_2NULL( pC, pC->m_pMachMgr, "Context or MachMgr invalid", Ret) + +//----------------------------------------------------------------------------- +#define VERIFY_SCENE( pS, Ret) VERIFY_NULL( pS, "Scene invalid", Ret) + +//----------------------------------------------------------------------------- +#define VERIFY_CTX_SCENE( pC, Ret) VERIFY_2NULL( pC, pC->m_pScene, "Context or Scene invalid", Ret) + +//----------------------------------------------------------------------------- +#define VERIFY_TSCEXEC( pT, Ret) VERIFY_NULL( pT, "TscExecutor invalid", Ret) diff --git a/EXE_Messages.cpp b/EXE_Messages.cpp new file mode 100644 index 0000000..b330602 --- /dev/null +++ b/EXE_Messages.cpp @@ -0,0 +1,94 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : EXE_Messages.cpp Data : 05.05.15 Versione : 1.6e1 +// Contenuto : Funzioni per gestione messaggi. +// +// +// +// Modifiche : 12.02.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDEv/Include/EGnScan.h" +#include "/EgtDev/Include/EGnStringUtils.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EgtLogger.h" +#include + +using namespace std ; + +//---------------------------------------------------------------------------- +typedef unordered_map< int, string> INTSTR_UMAP ; +static INTSTR_UMAP s_IdStringMap ; +static string s_sMsg ; + +//---------------------------------------------------------------------------- +bool +ExeLoadMessages( const string& sMsgFilePath) +{ + // inizializzo lo scanner + Scanner scan ; + if ( ! scan.Init( sMsgFilePath)) + return false ; + // pulisco la memoria + s_IdStringMap.clear() ; + s_sMsg.clear() ; + // riservo spazio + s_IdStringMap.rehash( 1000) ; + s_sMsg.reserve( 128) ; + // leggo le linee + string sLine ; + sLine.reserve( 128) ; + string sNum ; + sNum.reserve( 16) ; + string sMsg ; + sMsg.reserve( 128) ; + int nNum ; + int nCurrNum = - 1 ; + while ( scan.GetLine( sLine)) { + // divido la linea in due parti sul token '=' + Split( sLine, "=", true, sNum, sMsg) ; + // la prima parte deve essere numerica + if ( sNum.empty() || ! FromString( sNum, nNum)) { + string sOut ; + sOut = "Problem in " + sMsgFilePath + " at line " + ToString( scan.GetCurrLineNbr()) + " : " + sLine ; + LOG_WARN( GetLogger(), sOut.c_str()) + continue ; + } + // la numerazione deve essere crescente + if ( nNum <= nCurrNum) { + string sOut ; + sOut = "Error in " + sMsgFilePath + " at message " + sNum + " : " + sLine ; + LOG_ERROR( GetLogger(), sOut.c_str()) + return false ; + } + nCurrNum = nNum ; + // converto i caratteri speciali + ReplaceString( sMsg, "
", "\n") ; + // inserisco il messaggio in tabella + if ( ! s_IdStringMap.emplace( nNum, sMsg).second) + return false ; + } + + // termino lo scanner + return scan.Terminate() ; +} + +//---------------------------------------------------------------------------- +const string& +ExeGetMsg( int nMsg) +{ + // recupero il messaggio + INTSTR_UMAP::iterator Iter = s_IdStringMap.find( nMsg) ; + if ( Iter != s_IdStringMap.end()) + s_sMsg = Iter->second ; + else + s_sMsg = "Msg" + ToString( nMsg) ; + return s_sMsg ; +} \ No newline at end of file diff --git a/EXE_Scene.cpp b/EXE_Scene.cpp new file mode 100644 index 0000000..aa0363e --- /dev/null +++ b/EXE_Scene.cpp @@ -0,0 +1,663 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : EXE_Scene.cpp Data : 05.05.15 Versione : 1.6e1 +// Contenuto : Funzioni Scene per EXE. +// +// +// +// Modifiche : 01.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "DllGraphics.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//----------------------------------------------------------------------------- +bool +ExeInitScene( HWND hWnd, int nDriver, bool b2Buff, int nColorBits, int nDepthBits) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX( pGseCtx, false) + // inizializzazione scena OpenGL + PtrOwner pScene( MyCreateEGrScene()) ; + VERIFY_NULL( Get( pScene), "Error in CreateEGrScene", false) + HDC hdc = GetDC( hWnd) ; + if ( ! pScene->CreateContext( hdc, nDriver, b2Buff, nColorBits, nDepthBits)) + return false ; + pScene->SetBackground( WHITE, WHITE) ; + pScene->SetShowMode( SM_SHADING) ; + pScene->SetShowCurveDirection( false) ; + pScene->SetCamera( CT_TOP) ; + pScene->ZoomAll() ; + pScene->SetWinRectAttribs( true, BLACK) ; + pScene->SetMark( YELLOW) ; + pScene->Init( pGseCtx->m_pGeomDB) ; + // assegno la scena al contesto + pGseCtx->m_hWnd = hWnd ; + pGseCtx->m_pScene = Release( pScene) ; + // log con info sulla scena + string sSceneInfo = pGseCtx->m_pScene->GetOpenGLInfo() + '\n' + + pGseCtx->m_pScene->GetGLSLInfo() + '\n' + + pGseCtx->m_pScene->GetPixelFormatInfo() ; + LOG_INFO( GetLogger(), sSceneInfo.c_str()) + + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetSceneInfo( string& sInfo) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // verifico parametro di ritorno + if ( &sInfo == nullptr) + return false ; + // recupero le informazioni sulla scena + sInfo += pGseCtx->m_pScene->GetOpenGLInfo() ; + sInfo += "\r\n" ; + sInfo += pGseCtx->m_pScene->GetGLSLInfo() ; + sInfo += "\r\n" ; + sInfo += pGseCtx->m_pScene->GetPixelFormatInfo() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetBackground( Color TopCol, Color BottomCol, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto lo sfondo + pGseCtx->m_pScene->SetBackground( TopCol, BottomCol) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetMarkAttribs( Color MarkCol) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto il colore del Mark + return pGseCtx->m_pScene->SetMark( MarkCol) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetSelSurfAttribs( Color SelSurfCol) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto il colore del Mark + return pGseCtx->m_pScene->SetSelSurf( SelSurfCol) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetGeoLineAttribs( Color GlCol) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto il colore della linea geometrica gestita direttamente dalla scena + return pGseCtx->m_pScene->SetGeoLineAttribs( GlCol) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetGeoTriaAttribs( Color GtCol) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto il colore del triangolo immediato + return pGseCtx->m_pScene->SetGeoTriaAttribs( GtCol) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetWinRectAttribs( bool bOutline, Color WrCol) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto il colore della linea geometrica gestita direttamente dalla scena + return pGseCtx->m_pScene->SetWinRectAttribs( bOutline, WrCol) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetGlobFrameShow( bool bShow) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto stato visualizzazione griglia + return pGseCtx->m_pScene->SetGlobFrameShow( bShow) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetGridShow( bool bShowGrid, bool bShowFrame) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto stato visualizzazione griglia + return pGseCtx->m_pScene->SetGridShow( bShowGrid, bShowFrame) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetGridGeo( double dSnapStep, int nMinLineSstep, int nMajLineSstep, int nExtSstep) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto i parametri geometrici di griglia + return pGseCtx->m_pScene->SetGridGeo( dSnapStep, nMinLineSstep, nMajLineSstep, nExtSstep) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetGridColor( Color colMin, Color colMaj) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto i colori di griglia + return pGseCtx->m_pScene->SetGridColor( colMin, colMaj) ; +} + +//----------------------------------------------------------------------------- +bool +ExeResize( int nW, int nH) +{ + IEGrScene* pScene = GetCurrScene() ; + VERIFY_SCENE( pScene, false) + // eseguo resize + pScene->Resize( nW, nH) ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeDraw( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // eseguo disegno + pGseCtx->m_pScene->Draw() ; + // valido la finestra disegnata + ValidateRgn( pGseCtx->m_hWnd, NULL) ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeSelect( int nWinX, int nWinY, int nSelW, int nSelH, int* pnSel) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // verifico parametro di ritorno + if ( pnSel == nullptr) + return false ; + // eseguo la selezione + return pGseCtx->m_pScene->Select( Point3d( nWinX, nWinY), nSelW, nSelH, *pnSel) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetObjFilterForSelect( bool bZerodim, bool bCurve, bool bSurf, bool bVolume, bool bExtra) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto il filtro + return pGseCtx->m_pScene->SetObjFilterForSelect( bZerodim, bCurve, bSurf, bVolume, bExtra) ; +} + +//----------------------------------------------------------------------------- +bool +ExeUnselectableRemove( int nId) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // tolgo dai non selezionabili + return pGseCtx->m_pScene->UnselectableRemove( nId) ; +} + +//----------------------------------------------------------------------------- +bool +ExeUnselectableAdd( int nId) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // aggiungo ai non selezionabili + return pGseCtx->m_pScene->UnselectableAdd( nId) ; +} + +//----------------------------------------------------------------------------- +bool +ExeUnselectableClearAll( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // cancello tutti i non selezionabili + return pGseCtx->m_pScene->UnselectableClearAll() ; +} + +//----------------------------------------------------------------------------- +int +ExeGetFirstObjInSelWin( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, GDB_ID_NULL) + // restituisco il primo oggetto selezionato + return pGseCtx->m_pScene->GetFirstSelectedObj() ; +} + +//----------------------------------------------------------------------------- +int +ExeGetNextObjInSelWin( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, GDB_ID_NULL) + // restituisco il successivo oggetto selezionato + return pGseCtx->m_pScene->GetNextSelectedObj() ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetPointFromSelect( int nSelId, int nWinX, int nWinY, Point3d& ptSel, int* pnAux) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // trovo il punto usato in selezione + if ( &ptSel == nullptr || pnAux == nullptr) + return false ; + return pGseCtx->m_pScene->GetPointFromSelect( nSelId, Point3d( nWinX, nWinY), ptSel, *pnAux) ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetGraphicSnapPoint( int nSnap, int nWinX, int nWinY, int nSelW, int nSelH, Point3d& ptP) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // trovo il punto snap da selezione + if ( &ptP == nullptr) + return false ; + return pGseCtx->m_pScene->GetGraphicSnapPoint( nSnap, Point3d( nWinX, nWinY), nSelW, nSelH, ptP) ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetGridSnapPointZ( bool bSketch, int nWinX, int nWinY, const Point3d& ptGrid, Point3d& ptP) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // trovo il punto snap da griglia con elevazione in Z + if ( &ptP == nullptr) + return false ; + return pGseCtx->m_pScene->GetGridSnapPointZ( bSketch, Point3d( nWinX, nWinY), ptGrid, ptP) ; +} + +//----------------------------------------------------------------------------- +int +ExeGetLastSnapId( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, GDB_ID_NULL) + // restituisco Id di ultima entità generatrice di punto snap + return pGseCtx->m_pScene->GetLastSnapId() ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetLastSnapDir( Vector3d& vtV) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, FALSE) + // restituisco, se definita, direzione associata ad ultimo punto di snap + if ( &vtV == nullptr) + return false ; + return pGseCtx->m_pScene->GetLastSnapDir( vtV) ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetShowMode( int nShowMode, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto il modo di visualizzazione + if ( nShowMode >= SM_WIREFRAME && nShowMode <= SM_SHADING) { + pGseCtx->m_pScene->SetShowMode( nShowMode) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; + } + else + return false ; +} + +//----------------------------------------------------------------------------- +int +ExeGetShowMode( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, SM_WIREFRAME) + // recupero il modo di visualizzazione + return pGseCtx->m_pScene->GetShowMode() ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetShowCurveDirection( bool bShow, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto stato + pGseCtx->m_pScene->SetShowCurveDirection( bShow) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetShowCurveDirection( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // recupero lo stato + return pGseCtx->m_pScene->GetShowCurveDirection() ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetShowTriaAdv( bool bAdvanced, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto stato + pGseCtx->m_pScene->SetShowTriaAdvanced( bAdvanced) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return TRUE ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetShowTriaAdv( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // recupero lo stato + return pGseCtx->m_pScene->GetShowTriaAdvanced() ; +} + +//----------------------------------------------------------------------------- +bool +ExeZoom( int nZoom, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + + const double COEFF_IN = 0.9 ; + const double COEFF_OUT = 1 / COEFF_IN ; + + switch ( nZoom) { + case 1 : + pGseCtx->m_pScene->ZoomAll() ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; + break ; + case 2 : + pGseCtx->m_pScene->ZoomChange( COEFF_IN) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; + break ; + case 3 : + pGseCtx->m_pScene->ZoomChange( COEFF_OUT) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; + break ; + } + + return false ; +} + +//----------------------------------------------------------------------------- +bool +ExeZoomOnPoint( int nWinX, int nWinY, double dCoeff, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // eseguo zoom + pGseCtx->m_pScene->ZoomOnPoint( Point3d( nWinX, nWinY), dCoeff) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetGeoLine( const Point3d& ptP1, const Point3d& ptP2, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // disegno linea per distanza o similari + pGseCtx->m_pScene->SetGeoLine( ptP1, ptP2) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeResetGeoLine( bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // cancello linea per distanza o similari + pGseCtx->m_pScene->ResetGeoLine() ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetGeoTria( const Point3d& ptP1, const Point3d& ptP2, const Point3d& ptP3, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // disegno triangolo immediato + pGseCtx->m_pScene->SetGeoTria( ptP1, ptP2, ptP3) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeResetGeoTria( bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // cancello triangolo immediato + pGseCtx->m_pScene->ResetGeoTria() ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetWinRect( int nPrevX, int nPrevY, int nCurrX, int nCurrY, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // disegno finestra per zoom + pGseCtx->m_pScene->SetWinRect( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeResetWinRect( bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // cancello finestra per zoom + pGseCtx->m_pScene->ResetWinRect() ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeZoomWin( int nPrevX, int nPrevY, int nCurrX, int nCurrY, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // eseguo zoom su finestra + pGseCtx->m_pScene->ZoomWin( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetView( int nDir, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto vista + if ( nDir >= CT_TOP && nDir <= CT_CPLANE) { + pGseCtx->m_pScene->SetCamera( nDir) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; + } + else + return false ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetGenericView( double dAngVertDeg, double dAngHorizDeg, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto vista + pGseCtx->m_pScene->SetCamera( dAngVertDeg, dAngHorizDeg, 0) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeSetViewCenter( const Point3d& ptP, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // imposto vista + pGseCtx->m_pScene->SetCenter( ptP) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExePanView( int nPrevX, int nPrevY, int nCurrX, int nCurrY, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // eseguo panoramica + pGseCtx->m_pScene->PanCamera( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeRotateView( int nPrevX, int nPrevY, int nCurrX, int nCurrY, bool bRedraw) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_SCENE( pGseCtx, false) + // eseguo rotazione camera + pGseCtx->m_pScene->RotateCamera( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; + if ( bRedraw) + pGseCtx->m_pScene->RedrawWindow() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetView( int* pnDir) +{ + IEGrScene* pScene = GetCurrScene() ; + VERIFY_SCENE( pScene, false) + // recupero direzione di vista + if ( pnDir == nullptr) + return false ; + *pnDir = pScene->GetCameraDir() ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeGetGenericView( double* pdAngVertDeg, double* pdAngHorizDeg) +{ + IEGrScene* pScene = GetCurrScene() ; + VERIFY_SCENE( pScene, false) + // recupero direzione di vista + if ( pdAngVertDeg == nullptr || pdAngHorizDeg == nullptr) + return false ; + pScene->GetCamera( pdAngVertDeg, pdAngHorizDeg) ; + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeProjectPoint( const Point3d& ptP, Point3d& ptWin) +{ + IEGrScene* pScene = GetCurrScene() ; + VERIFY_SCENE( pScene, false) + // eseguo la proiezione + if ( &ptWin == nullptr) + return false ; + Point3d ptView ; + return pScene->Project( ptP, ptView) ; +} + +//----------------------------------------------------------------------------- +bool +ExeUnProjectPoint( int nWinX, int nWinY, Point3d& ptP) +{ + IEGrScene* pScene = GetCurrScene() ; + VERIFY_SCENE( pScene, false) + // eseguo l'inverso della proiezione (considero Z punto su centro) + if ( &ptP == nullptr) + return false ; + Point3d ptView( nWinX, nWinY, pScene->GetProjectedCenter().z) ; + return pScene->UnProject( ptView, ptP) ; +} diff --git a/EXE_TscExec.cpp b/EXE_TscExec.cpp new file mode 100644 index 0000000..ab52b0e --- /dev/null +++ b/EXE_TscExec.cpp @@ -0,0 +1,105 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : EXE_TscExec.cpp Data : 05.05.15 Versione : 1.6e1 +// Contenuto : Funzioni esecuzione TSC per EXE. +// +// +// +// Modifiche : 01.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "DllGraphics.h" +#include "DllExchange.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkGdbExecutor.h" +#include "/EgtDev/Include/EExExcExecutor.h" +#include "/EgtDev/Include/EGrSceExecutor.h" +#include "/EgtDev/Include/EGnStringUtils.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EgtPointerOwner.h" +#include + +using namespace std ; + +//----------------------------------------------------------------------------- +bool +ExeInitTscExec( void) +{ + GseContext* pGseCtx = GetCurrGseContext() ; + VERIFY_CTX_GEOMDB( pGseCtx, false) + + // eventuale pulizia esecutore e suoi oggetti + if ( pGseCtx->m_pTscExec != nullptr) { + delete pGseCtx->m_pTscExec ; + pGseCtx->m_pTscExec = nullptr ; + } + + // creo esecutore + PtrOwner pCmdParser( CreateCmdParser()) ; + VERIFY_NULL( Get( pCmdParser), "Error in CreateCmdParser", false) + + // creo oggetto per esecuzione funzioni di GeomKernel + PtrOwner pGdbExec( CreateGdbExecutor()) ; + VERIFY_NULL( Get( pGdbExec), "Error in CreateGdbExecutor", false) + pGdbExec->SetGeomDB( pGseCtx->m_pGeomDB) ; + pCmdParser->SetExecutor( Release( pGdbExec)) ; + + // eventuale creazione oggetto per esecuzione funzioni di Scene + if ( pGseCtx->m_pScene != nullptr && IsLoadedGraphicsDll()) { + PtrOwner pSceExec( MyCreateSceExecutor()) ; + VERIFY_NULL( Get( pSceExec), "Error in CreateSceExecutor", false) + pSceExec->SetScene( pGseCtx->m_pScene) ; + pCmdParser->AddExecutor( Release( pSceExec)) ; + } + + // eventuale creazione oggetto per esecuzione funzioni di Exchange + if ( IsLoadedExchangeDll()) { + PtrOwner pExcExec( MyCreateExcExecutor()) ; + VERIFY_NULL( Get( pExcExec), "Error in CreateExcExecutor", false) + pExcExec->SetGeomDB( pGseCtx->m_pGeomDB) ; + pCmdParser->AddExecutor( Release( pExcExec)) ; + } + + // completo inizializzazioni + pCmdParser->Init() ; + pGseCtx->m_pTscExec = Release( pCmdParser) ; + + return true ; +} + +//----------------------------------------------------------------------------- +bool +ExeTscExecFile( const string& sFilePath) +{ + ICmdParser* pTscExec = GetCurrTscExecutor() ; + VERIFY_TSCEXEC( pTscExec, false) + + // emetto info + string sInfo = "Exec File = " + sFilePath ; + LOG_INFO( GetLogger(), sInfo.c_str()) + + // imposto il direttorio dello script + string sFileDir, sFileName ; + SplitLast( sFilePath, "\\", sFileDir, sFileName) ; + pTscExec->SetDirReplace( "", sFileDir) ; + + // esecuzione script + return pTscExec->Run( sFilePath) ; +} + +//----------------------------------------------------------------------------- +bool +ExeTscExecLine( const string& sLine) +{ + ICmdParser* pTscExec = GetCurrTscExecutor() ; + VERIFY_TSCEXEC( pTscExec, false) + // eseguo il comando + return pTscExec->ExecLine( sLine) ; +} diff --git a/EXeDllMain.cpp b/EXeDllMain.cpp new file mode 100644 index 0000000..af41005 --- /dev/null +++ b/EXeDllMain.cpp @@ -0,0 +1,80 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : EXcDllMain.cpp Data : 04.05.15 Versione : 1.6e11 +// Contenuto : Inizializzazione della DLL. +// +// +// +// Modifiche : 04.05.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "/EgtDev/Include/EXeDllMain.h" +#include "/EgtDev/Include/EGnGetModuleVer.h" +#include "/EgtDev/Include/EgtTrace.h" + +//--------------------------- Costanti ---------------------------------------- +#if defined( _WIN64) + #if defined( _DEBUG) + const char* EXE_STR = "EgtExecutorD64.dll ver. " ; + #else + const char* EXE_STR = "EgtExecutorR64.dll ver. " ; + #endif +#elif defined( _WIN32) + #if defined( _DEBUG) + const char* EXE_STR = "EgtExecutorD32.dll ver. " ; + #else + const char* EXE_STR = "EgtExecutorR32.dll ver. " ; + #endif +#endif +const int STR_DIM = 50 ; + +//----------------------------------------------------------------------------- +static HINSTANCE s_hModule = NULL ; +static char s_szEXeNameVer[STR_DIM] ; + +//----------------------------------------------------------------------------- +BOOL APIENTRY +DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved) +{ + + if ( dwReason == DLL_PROCESS_ATTACH) { + // Controllo commentato per problemi con VB.NET + //#if defined( NDEBUG) + // BOOL IsDbgPresent = FALSE ; + // CheckRemoteDebuggerPresent( GetCurrentProcess(), &IsDbgPresent) ; + // if ( IsDbgPresent) + // return 0 ; + //#endif + // se debug, imposto stampe memory leaks all'uscita + #if defined ( _DEBUG) + _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF) ; + #endif + // eseguo + s_hModule = hModule ; + EGT_TRACE( "EgtExecutor.dll Initializing!\n") ; + } + else if ( dwReason == DLL_PROCESS_DETACH) { + s_hModule = NULL ; + EGT_TRACE( "EgtExecutor.dll Terminating!\n") ; + } + + return 1 ; +} + +//----------------------------------------------------------------------------- +const char* +GetEXeVersion( void) +{ + std::string sVer ; + + GetModuleVersion( s_hModule, sVer) ; + sprintf_s( s_szEXeNameVer, STR_DIM, "%s%s", EXE_STR, sVer.c_str()) ; + + return s_szEXeNameVer ; +} + diff --git a/EgtExecutor.rc b/EgtExecutor.rc new file mode 100644 index 0000000..f95ca78 Binary files /dev/null and b/EgtExecutor.rc differ diff --git a/EgtExecutor.sln b/EgtExecutor.sln new file mode 100644 index 0000000..f7f51ae --- /dev/null +++ b/EgtExecutor.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EgtExecutor", "EgtExecutor.vcxproj", "{DF654897-F85B-4108-A621-F2C4AB099A48}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DF654897-F85B-4108-A621-F2C4AB099A48}.Debug|Win32.ActiveCfg = Debug|Win32 + {DF654897-F85B-4108-A621-F2C4AB099A48}.Debug|Win32.Build.0 = Debug|Win32 + {DF654897-F85B-4108-A621-F2C4AB099A48}.Debug|x64.ActiveCfg = Debug|x64 + {DF654897-F85B-4108-A621-F2C4AB099A48}.Debug|x64.Build.0 = Debug|x64 + {DF654897-F85B-4108-A621-F2C4AB099A48}.Release|Win32.ActiveCfg = Release|Win32 + {DF654897-F85B-4108-A621-F2C4AB099A48}.Release|Win32.Build.0 = Release|Win32 + {DF654897-F85B-4108-A621-F2C4AB099A48}.Release|x64.ActiveCfg = Release|x64 + {DF654897-F85B-4108-A621-F2C4AB099A48}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/EgtExecutor.vcxproj b/EgtExecutor.vcxproj new file mode 100644 index 0000000..2f2915a --- /dev/null +++ b/EgtExecutor.vcxproj @@ -0,0 +1,284 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {DF654897-F85B-4108-A621-F2C4AB099A48} + Win32Proj + EgtExecutor + + + + DynamicLibrary + true + Unicode + v120_xp + + + DynamicLibrary + true + Unicode + v120_xp + + + DynamicLibrary + false + true + Unicode + v120_xp + + + DynamicLibrary + false + true + Unicode + v120_xp + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)$(Configuration)$(PlatformArchitecture)\ + $(Configuration)$(PlatformArchitecture)\ + $(ProjectName)D$(PlatformArchitecture) + C:\;$(IncludePath) + + + true + $(SolutionDir)$(Configuration)$(PlatformArchitecture)\ + $(Configuration)$(PlatformArchitecture)\ + $(ProjectName)D$(PlatformArchitecture) + C:\;$(IncludePath) + + + false + $(SolutionDir)$(Configuration)$(PlatformArchitecture)\ + $(Configuration)$(PlatformArchitecture)\ + $(ProjectName)R$(PlatformArchitecture) + C:\;$(IncludePath) + + + false + $(SolutionDir)$(Configuration)$(PlatformArchitecture)\ + $(Configuration)$(PlatformArchitecture)\ + $(ProjectName)R$(PlatformArchitecture) + C:\;$(IncludePath) + + + + Use + Level3 + Disabled + WIN32;I_AM_EXE;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + ProgramDatabase + true + false + + + Windows + true + $(OutDir)$(TargetName)$(TargetExt) + + + copy $(TargetDir)$(TargetName).pdb \EgtDev\Lib\ +copy $(TargetDir)$(TargetName).lib \EgtDev\Lib\ +copy $(TargetPath) \EgtProg\DllD32 + + + _UNICODE;UNICODE;_DEBUG;_DEB32;%(PreprocessorDefinitions) + + + + + Use + Level3 + Disabled + WIN32;I_AM_EXE;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + false + true + false + + + Windows + true + $(OutDir)$(TargetName)$(TargetExt) + false + + + copy $(TargetDir)$(TargetName).pdb \EgtDev\Lib\ +copy $(TargetDir)$(TargetName).lib \EgtDev\Lib\ +copy $(TargetPath) \EgtProg\DllD64 + + + _UNICODE;UNICODE;_DEBUG;_DEB64;%(PreprocessorDefinitions) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;I_AM_EXE;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + Speed + AnySuitable + true + true + true + StreamingSIMDExtensions2 + + + Windows + false + true + true + $(OutDir)$(TargetName)$(TargetExt) + + + copy $(TargetDir)$(TargetName).lib \EgtDev\Lib\ +copy $(TargetPath) \EgtProg\Dll32 + + + _UNICODE;UNICODE;NDEBUG;NDEB32;%(PreprocessorDefinitions) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;I_AM_EXE;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + Speed + AnySuitable + true + true + true + + + Windows + false + true + true + $(OutDir)$(TargetName)$(TargetExt) + + + copy $(TargetDir)$(TargetName).lib \EgtDev\Lib\ +copy $(TargetPath) \EgtProg\Dll64 + + + _UNICODE;UNICODE;NDEBUG;NDEB64;%(PreprocessorDefinitions) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/EgtExecutor.vcxproj.filters b/EgtExecutor.vcxproj.filters new file mode 100644 index 0000000..d61c721 --- /dev/null +++ b/EgtExecutor.vcxproj.filters @@ -0,0 +1,236 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {8d45f54c-e32b-4568-a8c6-6d9074ed565f} + + + {58650c7e-f303-498a-b85b-7bee0f52fa88} + + + {51194dc4-ffc1-435f-aa51-523e8d34f02a} + + + {d42d96c4-e8e4-4bcf-a6de-65b5f0492a14} + + + {85a1c0e1-b6e3-4b5c-be4a-75dc9570c4db} + + + {77e59e94-e3d5-4510-8bcb-d1360cf74848} + + + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione\Include + + + File di intestazione\Include + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione\Include + + + File di intestazione\Include + + + File di intestazione\Include + + + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\General + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\Global + + + File di origine\Global + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\Global + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\LUA + + + File di origine\Optional Dll + + + File di origine\Optional Dll + + + File di origine\Optional Dll + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\General + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + File di origine\EXE + + + + + File di risorse + + + \ No newline at end of file diff --git a/GeoTools.cpp b/GeoTools.cpp new file mode 100644 index 0000000..ebfa276 --- /dev/null +++ b/GeoTools.cpp @@ -0,0 +1,90 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : GeoTools.cpp Data : 01.02.15 Versione : 1.6b1 +// Contenuto : Funzioni geometriche ausiliarie. +// +// +// +// Modifiche : 01.02.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#include "stdafx.h" +#include "GeoTools.h" +#include "/EgtDev/Include/EGkGeomDB.h" +#include "/EgtDev/Include/EXeConst.h" + +//---------------------------------------------------------------------------- +Vector3d +GetVectorLocal( IGeomDB* pGeomDB, const Vector3d& vtV, int nRefType, const Frame3d& frLoc) +{ + Vector3d vtVL( vtV) ; + if ( nRefType == RTY_GLOB) + vtVL.ToLoc( frLoc) ; + else if ( nRefType == RTY_GRID) + vtVL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ; + return vtVL ; +} + +//---------------------------------------------------------------------------- +Point3d +GetPointLocal( IGeomDB* pGeomDB, const Point3d& ptP, int nRefType, const Frame3d& frLoc) +{ + Point3d ptPL( ptP) ; + if ( nRefType == RTY_GLOB) + ptPL.ToLoc( frLoc) ; + else if ( nRefType == RTY_GRID) + ptPL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ; + return ptPL ; +} + +//---------------------------------------------------------------------------- +bool +VerifySameFrame( IGeomDB* pGeomDB, const INTVECTOR& vIds) +{ + // verifico puntatore a GeomDB + if ( pGeomDB == nullptr) + return false ; + // ciclo sul vettore degli identificativi + bool bFirst = true ; + Frame3d frFirst ; + for ( size_t i = 0 ; i < vIds.size() ; ++ i) { + // se si deve agire su un singolo oggetto ( gruppo o entità) + if ( vIds[i] != GDB_ID_SEL) { + Frame3d frLoc ; + if ( ! pGeomDB->GetGroupGlobFrame( vIds[i], frLoc) && + ! pGeomDB->GetGlobFrame( vIds[i], frLoc)) + return false ; + if ( bFirst) { + frFirst = frLoc ; + bFirst = false ; + } + else { + if ( ! AreSameFrame( frFirst, frLoc)) + return false ; + } + } + // altrimenti si deve agire sugli oggetti selezionati + else { + int nI = pGeomDB->GetFirstSelectedObj() ; + while ( nI != GDB_ID_NULL) { + Frame3d frLoc ; + if ( ! pGeomDB->GetGlobFrame( nI, frLoc)) + return false ; + if ( bFirst) { + frFirst = frLoc ; + bFirst = false ; + } + else { + if ( ! AreSameFrame( frFirst, frLoc)) + return false ; + } + // passo alla successiva + nI = pGeomDB->GetNextSelectedObj() ; + } + } + } + return true ; +} \ No newline at end of file diff --git a/GeoTools.h b/GeoTools.h new file mode 100644 index 0000000..6e20640 --- /dev/null +++ b/GeoTools.h @@ -0,0 +1,26 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : GeoTools.h Data : 01.02.15 Versione : 1.6b1 +// Contenuto : Prototipi funzioni geometriche ausiliarie. +// +// +// +// Modifiche : 01.02.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#include "/EgtDev/Include/EGkPoint3d.h" +#include "/EgtDev/Include/EgtNumCollection.h" + +class IGeomDB ; + +//---------------------------------------------------------------------------- +// Vettore espresso nel riferimento desiderato partendo da vettore nel riferimento RefType +Vector3d GetVectorLocal( IGeomDB* pGeomDB, const Vector3d& vtV, int nRefType, const Frame3d& frLoc) ; +// Punto espresso nel riferimento desiderato partendo da punto nel riferimento RefType +Point3d GetPointLocal( IGeomDB* pGeomDB, const Point3d& ptP, int nRefType, const Frame3d& frLoc) ; +// Verifica che tutti gli oggetti dell'insieme abbiano lo stesso riferimento +bool VerifySameFrame( IGeomDB* pGeomDB, const INTVECTOR& vIds) ; + diff --git a/GseContext.cpp b/GseContext.cpp new file mode 100644 index 0000000..3392f37 --- /dev/null +++ b/GseContext.cpp @@ -0,0 +1,166 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : GseContext.cpp Data : 01.09.14 Versione : 1.5i1 +// Contenuto : Gestione contesti GSE ( Geometria, Scena, Esecuzione). +// +// +// +// Modifiche : 01.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#include "stdafx.h" +#include "GseContext.h" + +//---------------------------------------------------------------------------- +static int s_nCurrGseCtx = 0 ; +static const int MAX_CTX = 10 ; +static bool s_GseOn[MAX_CTX] = { false, false, false, false, false, false, false, false, false, false} ; +static GseContext s_GseCtx[MAX_CTX] ; + +//---------------------------------------------------------------------------- +int +CreateGseContext( void) +{ + for ( int i = 0 ; i < MAX_CTX ; ++ i) { + if ( ! s_GseOn[i]) { + s_GseCtx[i].Clear() ; + s_GseOn[i] = true ; + return ( i + 1) ; + } + } + return 0 ; +} + +//---------------------------------------------------------------------------- +bool +DeleteGseContext( int nInd) +{ + if ( nInd < 1 || nInd > MAX_CTX) + return false ; + s_GseOn[nInd-1] = false ; + s_GseCtx[nInd-1].Clear() ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +ClearAllGseContexts( void) +{ + for ( int i = 0 ; i < MAX_CTX ; ++ i) { + s_GseOn[i] = false ; + s_GseCtx[i].Clear() ; + } + return true ; +} + +//---------------------------------------------------------------------------- +GseContext* +GetGseContext( int nInd) +{ + if ( nInd < 1 || nInd > MAX_CTX || ! s_GseOn[nInd-1]) + return nullptr ; + return &(s_GseCtx[nInd-1]) ; +} + +//---------------------------------------------------------------------------- +IGeomDB* +GetGeomDB( int nInd) +{ + if ( nInd < 1 || nInd > MAX_CTX || ! s_GseOn[nInd-1]) + return nullptr ; + return ( s_GseCtx[nInd-1].m_pGeomDB) ; +} + +//---------------------------------------------------------------------------- +IEGrScene* +GetScene( int nInd) +{ + if ( nInd < 1 || nInd > MAX_CTX || ! s_GseOn[nInd-1]) + return nullptr ; + return ( s_GseCtx[nInd-1].m_pScene) ; +} + +//---------------------------------------------------------------------------- +ICmdParser* +GetTscExecutor( int nInd) +{ + if ( nInd < 1 || nInd > MAX_CTX || ! s_GseOn[nInd-1]) + return nullptr ; + return ( s_GseCtx[nInd-1].m_pTscExec) ; +} + +//---------------------------------------------------------------------------- +bool +SetCurrGseContext( int nInd) +{ + if ( nInd < 1 || nInd > MAX_CTX || ! s_GseOn[nInd-1]) { + s_nCurrGseCtx = 0 ; + return false ; + } + s_nCurrGseCtx = nInd ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +ResetCurrGseContext( void) +{ + s_nCurrGseCtx = 0 ; + return true ; +} + +//---------------------------------------------------------------------------- +int +GetIndCurrGseContext( void) +{ + return s_nCurrGseCtx ; +} + +//---------------------------------------------------------------------------- +GseContext* +GetCurrGseContext( void) +{ + if ( s_nCurrGseCtx < 1 || s_nCurrGseCtx > MAX_CTX || ! s_GseOn[s_nCurrGseCtx-1]) + return nullptr ; + return &(s_GseCtx[s_nCurrGseCtx-1]) ; +} + +//---------------------------------------------------------------------------- +IGeomDB* +GetCurrGeomDB( void) +{ + if ( s_nCurrGseCtx < 1 || s_nCurrGseCtx > MAX_CTX || ! s_GseOn[s_nCurrGseCtx-1]) + return nullptr ; + return ( s_GseCtx[s_nCurrGseCtx-1].m_pGeomDB) ; +} + +//---------------------------------------------------------------------------- +IMachMgr* +GetCurrMachMgr( void) +{ + if ( s_nCurrGseCtx < 1 || s_nCurrGseCtx > MAX_CTX || ! s_GseOn[s_nCurrGseCtx-1]) + return nullptr ; + return ( s_GseCtx[s_nCurrGseCtx-1].m_pMachMgr) ; +} + +//---------------------------------------------------------------------------- +IEGrScene* +GetCurrScene( void) +{ + if ( s_nCurrGseCtx < 1 || s_nCurrGseCtx > MAX_CTX || ! s_GseOn[s_nCurrGseCtx-1]) + return nullptr ; + return ( s_GseCtx[s_nCurrGseCtx-1].m_pScene) ; +} + +//---------------------------------------------------------------------------- +ICmdParser* +GetCurrTscExecutor( void) +{ + if ( s_nCurrGseCtx < 1 || s_nCurrGseCtx > MAX_CTX || ! s_GseOn[s_nCurrGseCtx-1]) + return nullptr ; + return ( s_GseCtx[s_nCurrGseCtx-1].m_pTscExec) ; +} + diff --git a/GseContext.h b/GseContext.h new file mode 100644 index 0000000..704d466 --- /dev/null +++ b/GseContext.h @@ -0,0 +1,90 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : GseContext.h Data : 01.09.14 Versione : 1.5i1 +// Contenuto : Dichiarazioni per contesti GSE ( Geometria, Scena, Esecuzione). +// +// +// +// Modifiche : 01.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkGeomDB.h" +#include "/EgtDev/Include/EGrScene.h" +#include "/EgtDev/Include/EGnCmdParser.h" +#include "/EgtDev/Include/EMkMachMgr.h" +#define NOMINMAX +#include + +//---------------------------------------------------------------------------- +class GseContext +{ + public : + IGeomDB* m_pGeomDB ; + Color m_colDef ; + IMachMgr* m_pMachMgr ; + HWND m_hWnd ; + IEGrScene* m_pScene ; + ICmdParser* m_pTscExec ; + std::string m_sFilePath ; + bool m_bEnableModified ; + bool m_bModified ; + int m_nCurrPart ; + int m_nCurrLayer ; + + public : + GseContext( void) + : m_pGeomDB( nullptr), m_colDef( GRAY), m_pMachMgr( nullptr), m_hWnd( nullptr), m_pScene( nullptr), + m_pTscExec( nullptr), m_sFilePath(), m_bEnableModified( true), m_bModified( false), + m_nCurrPart( GDB_ID_NULL), m_nCurrLayer( GDB_ID_NULL) + {} + ~GseContext( void) + { Clear() ; } + void Clear( void) + { + if ( m_pTscExec != nullptr) { + delete m_pTscExec ; + m_pTscExec = nullptr ; + } + if ( m_pScene != nullptr) { + m_pScene->Destroy() ; + delete m_pScene ; + m_pScene = nullptr ; + } + m_hWnd = nullptr ; + if ( m_pMachMgr != nullptr) { + delete m_pMachMgr ; + m_pMachMgr = nullptr ; + } + if ( m_pGeomDB != nullptr) { + delete m_pGeomDB ; + m_pGeomDB = nullptr ; + } + m_sFilePath.clear() ; + m_bEnableModified = true ; + m_bModified = false ; + m_nCurrPart = GDB_ID_NULL ; + m_nCurrLayer = GDB_ID_NULL ; + } +} ; + +//---------------------------------------------------------------------------- +int CreateGseContext( void) ; +bool DeleteGseContext( int nInd) ; +bool ClearAllGseContexts( void) ; +GseContext* GetGseContext( int nInd) ; +IGeomDB* GetGeomDB( int nInd) ; +IEGrScene* GetScene( int nInd) ; +ICmdParser* GetTscExecutor( int nInd) ; +bool SetCurrGseContext( int nInd) ; +bool ResetCurrGseContext( void) ; +int GetIndCurrGseContext( void) ; +GseContext* GetCurrGseContext( void) ; +IGeomDB* GetCurrGeomDB( void) ; +IMachMgr* GetCurrMachMgr( void) ; +IEGrScene* GetCurrScene( void) ; +ICmdParser* GetCurrTscExecutor( void) ; diff --git a/LUA.h b/LUA.h new file mode 100644 index 0000000..9f2ea43 --- /dev/null +++ b/LUA.h @@ -0,0 +1,70 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : LUA.h Data : 16.01.15 Versione : 1.6a3 +// Contenuto : Dichiarazioni locali per moduli LUA. +// +// +// +// Modifiche : 27.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGnLuaMgr.h" + +//-------------------------- General ----------------------------------------- +bool LuaInstallGeneral( LuaMgr& luaMgr) ; + +//-------------------------- GeoBase ----------------------------------------- +bool LuaInstallGeoBase( LuaMgr& luaMgr) ; + +//-------------------------- GeomDB ------------------------------------------ +bool LuaInstallGeomDB( LuaMgr& luaMgr) ; + +//-------------------------- GdbCreate --------------------------------------- +bool LuaInstallGdbCreate( LuaMgr& luaMgr) ; + +//-------------------------- GdbCreateCurve ---------------------------------- +bool LuaInstallGdbCreateCurve( LuaMgr& luaMgr) ; + +//-------------------------- GdbCreateSurf ----------------------------------- +bool LuaInstallGdbCreateSurf( LuaMgr& luaMgr) ; + +//-------------------------- GdbModify --------------------------------------- +bool LuaInstallGdbModify( LuaMgr& luaMgr) ; + +//-------------------------- GdbModifyCurve ---------------------------------- +bool LuaInstallGdbModifyCurve( LuaMgr& luaMgr) ; + +//-------------------------- GdbModifySurf ----------------------------------- +bool LuaInstallGdbModifySurf( LuaMgr& luaMgr) ; + +//-------------------------- GdbPartLayer ------------------------------------ +bool LuaInstallGdbPartLayer( LuaMgr& luaMgr) ; + +//-------------------------- GdbObjects -------------------------------------- +bool LuaInstallGdbObjects( LuaMgr& luaMgr) ; + +//-------------------------- GdbObjSelection --------------------------------- +bool LuaInstallGdbObjSelection( LuaMgr& luaMgr) ; + +//-------------------------- GdbObjAttribs ----------------------------------- +bool LuaInstallGdbObjAttribs( LuaMgr& luaMgr) ; + +//-------------------------- GeoSnap ----------------------------------------- +bool LuaInstallGeoSnap( LuaMgr& luaMgr) ; + +//-------------------------- GeoTransform ------------------------------------ +bool LuaInstallGeoTransform( LuaMgr& luaMgr) ; + +//-------------------------- MachMgr ----------------------------------------- +bool LuaInstallMachMgr( LuaMgr& luaMgr) ; + +//-------------------------- Scene ------------------------------------------- +bool LuaInstallScene( LuaMgr& luaMgr) ; + +//-------------------------- Exchange ---------------------------------------- +bool LuaInstallExchange( LuaMgr& luaMgr) ; diff --git a/LUA_Base.cpp b/LUA_Base.cpp new file mode 100644 index 0000000..3f1df9a --- /dev/null +++ b/LUA_Base.cpp @@ -0,0 +1,185 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_General.cpp Data : 27.09.14 Versione : 1.5i5 +// Contenuto : Funzioni generali per LUA. +// +// +// +// Modifiche : 27.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "LUA.h" +#include "LUA_Base.h" +#include "/EgtDev/Include/EGnLuaMgr.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +bool +LuaInstallAllFunctions( LuaMgr& LuaMgr) +{ + if ( ! LuaInstallGeneral( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGeneral (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGeoBase( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGeoBase (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGeomDB( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGeomDB (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGdbCreate( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGdbCreate (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGdbCreateCurve( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGdbCreateCurve (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGdbCreateSurf( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGdbCreateSurf (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGdbModify( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGdbModify (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGdbModifyCurve( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGdbModifyCurve (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGdbModifySurf( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGdbModifySurf (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGdbPartLayer( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGdbPartLayer (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGdbObjects( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGdbObjects (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGdbObjSelection( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGdbObjSelection (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGdbObjAttribs( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGdbObjAttribs (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGeoSnap( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGeoSnap (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallGeoTransform( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallGeoTransform (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallMachMgr( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallMachMgr (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallScene( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallScene (" __FUNCTION__ ")") + return false ; + } + if ( ! LuaInstallExchange( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallExchange (" __FUNCTION__ ")") + return false ; + } + return true ; +} + +//---------------------------------------------------------------------------- +// Static LuaMgr per EgtExecutor +//---------------------------------------------------------------------------- +static LuaMgr s_LuaMgr ; + +//---------------------------------------------------------------------------- +bool +LuaInit( void) +{ + // inizializzo l'interprete lua + if ( ! s_LuaMgr.Init()) + return false ; + + // carico le funzioni speciali + if ( ! LuaInstallAllFunctions( s_LuaMgr)) + return false ; + + // recupero la versione di Lua + string sLua ; + if ( s_LuaMgr.GetVersion( sLua)) + sLua += " interpreter started" ; + else + sLua = "Lua *.* interpreter started" ; + LOG_INFO( GetLogger(), sLua.c_str()) + return true ; +} + +//---------------------------------------------------------------------------- +bool +LuaExit( void) +{ + s_LuaMgr.Exit() ; + LOG_INFO( GetLogger(), "Lua interpreter closed") + return true ; +} + +//---------------------------------------------------------------------------- +bool +LuaSetLuaLibsDir( const string& sDir) +{ + return s_LuaMgr.SetLuaLibsDir( sDir) ; +} + +//---------------------------------------------------------------------------- +bool +LuaRequire( const string& sFile) +{ + return s_LuaMgr.Require( sFile) ; +} + +//---------------------------------------------------------------------------- +bool +LuaEvalNumExpr( const string& sExpr, double& dVal) +{ + return s_LuaMgr.EvalNumExpr( sExpr, dVal) ; +} + +//---------------------------------------------------------------------------- +bool +LuaEvalStringExpr( const string& sExpr, string& sVal) +{ + return s_LuaMgr.EvalStringExpr( sExpr, sVal) ; +} + +//---------------------------------------------------------------------------- +bool +LuaExecLine( const string& sLine) +{ + return s_LuaMgr.ExecLine( sLine) ; +} + +//---------------------------------------------------------------------------- +bool +LuaExecFile( const string& sFile) +{ + return s_LuaMgr.ExecFile( sFile) ; +} + +//---------------------------------------------------------------------------- +const string& +LuaGetLastError( void) +{ + return s_LuaMgr.GetLastError() ; +} diff --git a/LUA_Base.h b/LUA_Base.h new file mode 100644 index 0000000..6445af2 --- /dev/null +++ b/LUA_Base.h @@ -0,0 +1,31 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : LUA_Base.h Data : 21.03.15 Versione : 1.6c6 +// Contenuto : Dichiarazioni per funzioni di base gestione LUA. +// +// +// +// Modifiche : 21.03.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include + +//---------------------------------------------------------------------------- +struct lua_State ; +typedef int(*PFLUA) ( lua_State*) ; + +//---------------------------------------------------------------------------- +bool LuaInit( void) ; +bool LuaExit( void) ; +bool LuaSetLuaLibsDir( const std::string& sDir) ; +bool LuaRequire( const std::string& sFile) ; +bool LuaEvalNumExpr( const std::string& sExpr, double& dVal) ; +bool LuaEvalStringExpr( const std::string& sExpr, std::string& sVal) ; +bool LuaExecLine( const std::string& sLine) ; +bool LuaExecFile( const std::string& sFile) ; +const std::string& LuaGetLastError( void) ; diff --git a/LUA_Exchange.cpp b/LUA_Exchange.cpp new file mode 100644 index 0000000..e770061 --- /dev/null +++ b/LUA_Exchange.cpp @@ -0,0 +1,118 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_Exchange.cpp Data : 29.09.14 Versione : 1.5i5 +// Contenuto : Funzioni generali per LUA. +// +// +// +// Modifiche : 29.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkLuaAux.h" +#include "/EgtDev/Include/EgnStringUtils.h" + +using namespace std ; + + +//------------------------------------------------------------------------------- +static int +LuaImportDxf( lua_State* L) +{ + // 1 o 2 parametri : path del file da importare [, Fattore di scala] + string sFilePath ; + LuaCheckParam( L, 1, sFilePath) + double dScaleFactor = 1.0 ; + LuaGetParam( L, 2, dScaleFactor) ; + LuaClearStack( L) ; + // apro il file + bool bOk = ExeImportDxf( sFilePath, dScaleFactor) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaImportStl( lua_State* L) +{ + // 1 o 2 parametri : path del file da importare [, Fattore di scala] + string sFilePath ; + LuaCheckParam( L, 1, sFilePath) + double dScaleFactor = 1.0 ; + LuaGetParam( L, 2, dScaleFactor) ; + LuaClearStack( L) ; + // apro il file + bool bOk = ExeImportStl( sFilePath, dScaleFactor) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaImportCnc( lua_State* L) +{ + // 1 parametro : path del file da importare + string sFilePath ; + LuaCheckParam( L, 1, sFilePath) + LuaClearStack( L) ; + // apro il file + bool bOk = ExeImportCnc( sFilePath) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaExportDxf( lua_State* L) +{ + // 2 parametri, GroupId e path del file da esportare + int nGroupId ; + LuaCheckParam( L, 1, nGroupId) + string sFilePath ; + LuaCheckParam( L, 2, sFilePath) + LuaClearStack( L) ; + // apro il file + bool bOk = ExeExportDxf( nGroupId, sFilePath) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaExportStl( lua_State* L) +{ + // 2 parametri, GroupId e path del file da esportare + int nGroupId ; + LuaCheckParam( L, 1, nGroupId) + string sFilePath ; + LuaCheckParam( L, 2, sFilePath) + LuaClearStack( L) ; + // apro il file + bool bOk = ExeExportStl( nGroupId, sFilePath) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallExchange( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtImportDxf", LuaImportDxf) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtImportStl", LuaImportStl) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtImportCnc", LuaImportCnc) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtExportDxf", LuaExportDxf) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtExportStl", LuaExportStl) ; + return bOk ; +} diff --git a/LUA_GdbCreate.cpp b/LUA_GdbCreate.cpp new file mode 100644 index 0000000..d1ba5f5 --- /dev/null +++ b/LUA_GdbCreate.cpp @@ -0,0 +1,242 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_GdbCreate.cpp Data : 30.09.14 Versione : 1.5i5 +// Contenuto : Funzioni di creazione geometrica per LUA. +// +// +// +// Modifiche : 30.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" +#include "/EgtDev/Include/EGnStringUtils.h" + +using namespace std ; + + +//------------------------------------------------------------------------------- +static int +LuaCreateGroup( lua_State* L) +{ + // 1 o 2 o 3 parametri : ParentId [, Frame] [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Frame3d frFrame ; + int nRefType = RTY_DEFAULT ; + if ( LuaGetParam( L, 2, frFrame)) + LuaGetParam( L, 3, nRefType) ; + else + LuaGetParam( L, 2, nRefType) ; + LuaClearStack( L) ; + // creo il gruppo + int nId = ExeCreateGroup( nParentId, frFrame, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateGeoPoint( lua_State* L) +{ + // 2 o 3 parametri : ParentId, PtP [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptP ; + LuaCheckParam( L, 2, ptP) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // creo il punto + int nId = ExeCreateGeoPoint( nParentId, ptP, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateGeoVector( lua_State* L) +{ + // 2 o 3 o 4 parametri : ParentId, VtV [, PtB] [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Vector3d vtV ; + LuaCheckParam( L, 2, vtV) + Point3d ptB ; + int nRefType = RTY_DEFAULT ; + if ( LuaGetParam( L, 3, ptB)) + LuaGetParam( L, 4, nRefType) ; + else + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // creo il vettore + int nId = ExeCreateGeoVector( nParentId, vtV, ptB, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateGeoFrame( lua_State* L) +{ + // 2 o 3 parametri : ParentId, Frame [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Frame3d frFrame ; + LuaCheckParam( L, 2, frFrame) ; + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // creo il gruppo + int nId = ExeCreateGeoFrame( nParentId, frFrame, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateText( lua_State* L) +{ + // 5 o 6 parametri : ParentId, ptP, AngRotDeg, Text, H [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptP ; + LuaCheckParam( L, 2, ptP) ; + double dAngRotDeg ; + LuaCheckParam( L, 3, dAngRotDeg) ; + string sText ; + LuaCheckParam( L, 4, sText) + double dH ; + LuaCheckParam( L, 5, dH) ; + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // creo il testo + int nId = ExeCreateText( nParentId, ptP, dAngRotDeg, sText, dH, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateTextEx( lua_State* L) +{ + // 8 o 9 parametri : ParentId, ptP, vtN, vtD, Text, Font, bItalic, H [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptP ; + LuaCheckParam( L, 2, ptP) ; + Vector3d vtN ; + LuaCheckParam( L, 3, vtN) ; + Vector3d vtD ; + LuaCheckParam( L, 4, vtD) ; + string sText ; + LuaCheckParam( L, 5, sText) + string sFont ; + LuaCheckParam( L, 6, sFont) ; + string sItalic ; + LuaCheckParam( L, 7, sItalic) + ToUpper( sItalic) ; + bool bItalic = ( sItalic == "I") ; + double dH ; + LuaCheckParam( L, 8, dH) ; + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 9, nRefType) ; + LuaClearStack( L) ; + // creo il testo in modo esteso + int nId = ExeCreateTextEx( nParentId, ptP, vtN, vtD, sText, sFont, bItalic, dH, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateTextAdv( lua_State* L) +{ + // 12 o 13 parametri : ParentId, ptP, vtN, vtD, Text, Font, W, sItalic, H, Rat, AddAdv, InsPos [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptP ; + LuaCheckParam( L, 2, ptP) ; + Vector3d vtN ; + LuaCheckParam( L, 3, vtN) ; + Vector3d vtD ; + LuaCheckParam( L, 4, vtD) ; + string sText ; + LuaCheckParam( L, 5, sText) + string sFont ; + LuaCheckParam( L, 6, sFont) + int nW ; + LuaCheckParam( L, 7, nW) + string sItalic ; + LuaCheckParam( L, 8, sItalic) + ToUpper( sItalic) ; + bool bItalic = ( sItalic == "I") ; + double dH ; + LuaCheckParam( L, 9, dH) + double dRat ; + LuaCheckParam( L, 10, dRat) + double dAddAdv ; + LuaCheckParam( L, 11, dAddAdv) + int nInsPos ; + LuaCheckParam( L, 12, nInsPos) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 13, nRefType) ; + LuaClearStack( L) ; + // creo il testo in modo avanzato + int nId = ExeCreateTextAdv( nParentId, ptP, vtN, vtD, + sText, sFont, nW, bItalic, dH, dRat, dAddAdv, nInsPos, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGdbCreate( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGroup", LuaCreateGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtPoint", LuaCreateGeoPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtVector", LuaCreateGeoVector) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtFrame", LuaCreateGeoFrame) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtText", LuaCreateText) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTextEx", LuaCreateTextEx) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTextAdv", LuaCreateTextAdv) ; + return bOk ; +} diff --git a/LUA_GdbCreateCurve.cpp b/LUA_GdbCreateCurve.cpp new file mode 100644 index 0000000..fc0455e --- /dev/null +++ b/LUA_GdbCreateCurve.cpp @@ -0,0 +1,836 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_GdbCreateCurve.cpp Data : 07.01.15 Versione : 1.6a1 +// Contenuto : Funzioni di creazione curve per LUA. +// +// +// +// Modifiche : 07.01.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveLine( lua_State* L) +{ + // 3 o 4 parametri : ParentId, PtIni, PtFin [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptIni ; + LuaCheckParam( L, 2, ptIni) + Point3d ptFin ; + LuaCheckParam( L, 3, ptFin) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 4, nRefType) ; + LuaClearStack( L) ; + // creo il segmento di retta + int nId = ExeCreateCurveLine( nParentId, ptIni, ptFin, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveLineEx( lua_State* L) +{ + // 7 o 8 parametri : ParentId, PtIni, nSepI, nIdI, PtFin, nSepF, nIdF [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptIni ; + LuaCheckParam( L, 2, ptIni) + int nSepI ; + LuaCheckParam( L, 3, nSepI) + int nIdI ; + LuaCheckParam( L, 4, nIdI) + Point3d ptFin ; + LuaCheckParam( L, 5, ptFin) + int nSepF ; + LuaCheckParam( L, 6, nSepF) + int nIdF ; + LuaCheckParam( L, 7, nIdF) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 8, nRefType) ; + LuaClearStack( L) ; + // creo il segmento di retta + int nId = ExeCreateCurveLineEx( nParentId, + ptIni, nSepI, nIdI, + ptFin, nSepF, nIdF, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveLinePVL( lua_State* L) +{ + // 4 o 5 parametri : ParentId, PtIni, VtDir, dLen [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptIni ; + LuaCheckParam( L, 2, ptIni) + Vector3d vtDir ; + LuaCheckParam( L, 3, vtDir) + double dLen ; + LuaCheckParam( L, 4, dLen) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 5, nRefType) ; + LuaClearStack( L) ; + // creo il segmento di retta + int nId = ExeCreateCurveLinePVL( nParentId, ptIni, vtDir, dLen, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveLineMinPointCurve( lua_State* L) +{ + // 3 o 4 o 5 parametri : ParentId, PtIni, CrvId [, NearPar] [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptIni ; + LuaCheckParam( L, 2, ptIni) + int nCrvId ; + LuaCheckParam( L, 3, nCrvId) + double dNearPar = 0 ; + int nRefType = RTY_DEFAULT ; + if ( LuaGetParam( L, 4, dNearPar)) + LuaGetParam( L, 5, nRefType) ; + else + LuaGetParam( L, 4, nRefType) ; + LuaClearStack( L) ; + // creo il segmento di retta + int nId = ExeCreateCurveLineMinPointCurve( nParentId, ptIni, nCrvId, dNearPar, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveCircle( lua_State* L) +{ + // 4 o 5 parametri : ParentId, PtCen, VtN, Rad [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptCen ; + LuaCheckParam( L, 2, ptCen) + Vector3d vtN ; + LuaCheckParam( L, 3, vtN) + double dRad ; + LuaCheckParam( L, 4, dRad) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 5, nRefType) ; + LuaClearStack( L) ; + // creo l'arco + int nId = ExeCreateCurveCircle( nParentId, ptCen, vtN, dRad, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveCircleCPN( lua_State* L) +{ + // 4 o 5 parametri : ParentId, PtCen, PtOn, VtN [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptCen ; + LuaCheckParam( L, 2, ptCen) + Point3d ptOn ; + LuaCheckParam( L, 3, ptOn) + Vector3d vtN ; + LuaCheckParam( L, 4, vtN) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 5, nRefType) ; + LuaClearStack( L) ; + // creo l'arco + int nId = ExeCreateCurveCircleCPN( nParentId, ptCen, ptOn, vtN, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveCircleCPNEx( lua_State* L) +{ + // 6 o 7 parametri : ParentId, PtCen, PtOn, nSepO, nIdO, VtN [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptCen ; + LuaCheckParam( L, 2, ptCen) + Point3d ptOn ; + LuaCheckParam( L, 3, ptOn) + int nSepO ; + LuaCheckParam( L, 4, nSepO) + int nIdO ; + LuaCheckParam( L, 5, nIdO) + Vector3d vtN ; + LuaCheckParam( L, 6, vtN) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 7, nRefType) ; + LuaClearStack( L) ; + // creo l'arco + int nId = ExeCreateCurveCircleCPNEx( nParentId, ptCen, ptOn, nSepO, nIdO, vtN, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveCircle3P( lua_State* L) +{ + // 4 o 5 parametri : ParentId, PtP1, PtP2, PtP3 [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptP1 ; + LuaCheckParam( L, 2, ptP1) + Point3d ptP2 ; + LuaCheckParam( L, 3, ptP2) + Point3d ptP3 ; + LuaCheckParam( L, 4, ptP3) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 5, nRefType) ; + LuaClearStack( L) ; + // creo l'arco + int nId = ExeCreateCurveCircle3P( nParentId, ptP1, ptP2, ptP3, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveArc( lua_State* L) +{ + // 7 o 8 parametri : ParentId, PtCen, VtN, Rad, VtS, AngCenDeg, DeltaN [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptCen ; + LuaCheckParam( L, 2, ptCen) + Vector3d vtN ; + LuaCheckParam( L, 3, vtN) + double dRad ; + LuaCheckParam( L, 4, dRad) + Vector3d vtS ; + LuaCheckParam( L, 5, vtS) + double dAngCenDeg ; + LuaCheckParam( L, 6, dAngCenDeg) + double dDeltaN ; + LuaCheckParam( L, 7, dDeltaN) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 8, nRefType) ; + LuaClearStack( L) ; + // creo l'arco + int nId = ExeCreateCurveArc( nParentId, ptCen, vtN, dRad, vtS, dAngCenDeg, dDeltaN, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveArcC2PN( lua_State* L) +{ + // 5 o 6 parametri : ParentId, PtCen, PtStart, PtNearEnd, VtNorm [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptCen ; + LuaCheckParam( L, 2, ptCen) + Point3d ptStart ; + LuaCheckParam( L, 3, ptStart) + Point3d ptNearEnd ; + LuaCheckParam( L, 4, ptNearEnd) + Vector3d vtNorm ; + LuaCheckParam( L, 5, vtNorm) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // creo l'arco + int nId = ExeCreateCurveArcC2PN( nParentId, ptCen, ptStart, ptNearEnd, vtNorm, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveArcC2PNEx( lua_State* L) +{ + // 7 o 8 parametri : ParentId, PtCen, PtStart, nSepS, nIdS, PtNearEnd, VtNorm [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptCen ; + LuaCheckParam( L, 2, ptCen) + Point3d ptStart ; + LuaCheckParam( L, 3, ptStart) + int nSepS ; + LuaCheckParam( L, 4, nSepS) + int nIdS ; + LuaCheckParam( L, 5, nIdS) + Point3d ptNearEnd ; + LuaCheckParam( L, 6, ptNearEnd) + Vector3d vtNorm ; + LuaCheckParam( L, 7, vtNorm) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 8, nRefType) ; + LuaClearStack( L) ; + // creo l'arco + int nId = ExeCreateCurveArcC2PNEx( nParentId, ptCen, ptStart, nSepS, nIdS, ptNearEnd, vtNorm, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveArc3P( lua_State* L) +{ + // 4 o 5 parametri : ParentId, PtP1, PtP2, PtP3 [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptP1 ; + LuaCheckParam( L, 2, ptP1) + Point3d ptP2 ; + LuaCheckParam( L, 3, ptP2) + Point3d ptP3 ; + LuaCheckParam( L, 4, ptP3) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 5, nRefType) ; + LuaClearStack( L) ; + // creo l'arco + int nId = ExeCreateCurveArc3P( nParentId, ptP1, ptP2, ptP3, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveArc2PVN( lua_State* L) +{ + // 5 o 6 parametri : ParentId, PtStart, PtEnd, VtDirS, VtNorm [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptStart ; + LuaCheckParam( L, 2, ptStart) + Point3d ptEnd ; + LuaCheckParam( L, 3, ptEnd) + Vector3d vtDirS ; + LuaCheckParam( L, 4, vtDirS) + Vector3d vtNorm ; + LuaCheckParam( L, 5, vtNorm) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // creo l'arco + int nId = ExeCreateCurveArc2PVN( nParentId, ptStart, ptEnd, vtDirS, vtNorm, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveArc2PVNEx( lua_State* L) +{ + // 7 o 8 parametri : ParentId, PtStart, PtEnd, nSepE, nIdE, VtDirS, VtNorm [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptStart ; + LuaCheckParam( L, 2, ptStart) + Point3d ptEnd ; + LuaCheckParam( L, 3, ptEnd) + int nSepE ; + LuaCheckParam( L, 4, nSepE) + int nIdE ; + LuaCheckParam( L, 5, nIdE) + Vector3d vtDirS ; + LuaCheckParam( L, 6, vtDirS) + Vector3d vtNorm ; + LuaCheckParam( L, 7, vtNorm) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 8, nRefType) ; + LuaClearStack( L) ; + // creo l'arco + int nId = ExeCreateCurveArc2PVNEx( nParentId, ptStart, ptEnd, nSepE, nIdE, + vtDirS, vtNorm, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveFillet( lua_State* L) +{ + // 8 o 9 parametri : ParentId, nCrv1, PtNear1, nCrv2, PtNear2, VtNorm, dRad, bTrim [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nCrv1 ; + LuaCheckParam( L, 2, nCrv1) + Point3d ptNear1 ; + LuaCheckParam( L, 3, ptNear1) + int nCrv2 ; + LuaCheckParam( L, 4, nCrv2) + Point3d ptNear2 ; + LuaCheckParam( L, 5, ptNear2) + Vector3d vtNorm ; + LuaCheckParam( L, 6, vtNorm) + double dRad ; + LuaCheckParam( L, 7, dRad) + bool bTrim ; + LuaCheckParam( L, 8, bTrim) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 9, nRefType) ; + LuaClearStack( L) ; + // creo l'arco di fillet + int nId = ExeCreateCurveFillet( nParentId, nCrv1, ptNear1, nCrv2, ptNear2, + vtNorm, dRad, bTrim, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveChamfer( lua_State* L) +{ + // 8 o 9 parametri : ParentId, nCrv1, PtNear1, nCrv2, PtNear2, VtNorm, dDist, bTrim [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nCrv1 ; + LuaCheckParam( L, 2, nCrv1) + Point3d ptNear1 ; + LuaCheckParam( L, 3, ptNear1) + int nCrv2 ; + LuaCheckParam( L, 4, nCrv2) + Point3d ptNear2 ; + LuaCheckParam( L, 5, ptNear2) + Vector3d vtNorm ; + LuaCheckParam( L, 6, vtNorm) + double dDist ; + LuaCheckParam( L, 7, dDist) + bool bTrim ; + LuaCheckParam( L, 8, bTrim) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 9, nRefType) ; + LuaClearStack( L) ; + // creo l'arco di fillet + int nId = ExeCreateCurveChamfer( nParentId, nCrv1, ptNear1, nCrv2, ptNear2, + vtNorm, dDist, bTrim, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveBezier( lua_State* L) +{ + // 3 o 4 parametri : ParentId, Degree, CtrlPnts [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nDegree ; + LuaCheckParam( L, 2, nDegree) + PNTVECTOR vPnt ; + LuaCheckParam( L, 3, vPnt) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 4, nRefType) ; + LuaClearStack( L) ; + // creo la curva + int nId = ExeCreateCurveBezier( nParentId, nDegree, vPnt, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveBezierRational( lua_State* L) +{ + // 3 o 4 parametri : ParentId, Degree, CtrlPntWs [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nDegree ; + LuaCheckParam( L, 2, nDegree) + PNTUVECTOR vPntW ; + LuaCheckParam( L, 3, vPntW) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 4, nRefType) ; + LuaClearStack( L) ; + // creo la curva + int nId = ExeCreateCurveBezierRational( nParentId, nDegree, vPntW, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveBezierFromArc( lua_State* L) +{ + // 2 o 3 parametri : ParentId, ArcId[ , Erase] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nArcId ; + LuaCheckParam( L, 2, nArcId) + bool bErase = true ; + LuaGetParam( L, 3, bErase) ; + LuaClearStack( L) ; + // creo la curva + int nId = ExeCreateCurveBezierFromArc( nParentId, nArcId, bErase) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveCompo( lua_State* L) +{ + // 2 o 3 parametri : ParentId, nIds [, Erase] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + INTVECTOR vIds ; + LuaCheckParam( L, 2, vIds) + bool bErase = true ; + LuaGetParam( L, 3, bErase) ; + LuaClearStack( L) ; + // creo la curva composita + int nId = ExeCreateCurveCompo( nParentId, vIds, bErase) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveCompoByChain( lua_State* L) +{ + // 3 o 4 o 5 parametri : ParentId, nIds, PtNear [, Erase] [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + INTVECTOR vIds ; + LuaCheckParam( L, 2, vIds) + Point3d ptNear ; + LuaCheckParam( L, 3, ptNear) + bool bErase = true ; + int nRefType = RTY_DEFAULT ; + if ( LuaGetParam( L, 4, bErase)) + LuaGetParam( L, 5, nRefType) ; + else + LuaGetParam( L, 4, nRefType) ; + LuaClearStack( L) ; + // creo la curva composita + int nCount = 0 ; + int nId = ExeCreateCurveCompoByChain( nParentId, vIds, ptNear, bErase, nRefType, &nCount) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + LuaSetReturn( L, nCount) ; + return 2 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveCompoFromPoints( lua_State* L) +{ + // 2 o 3 parametri : ParentId, ptPs [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + PNTVECTOR vPnt ; + LuaCheckParam( L, 2, vPnt) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + PolyLine PL ; + // creo una polilinea a partire dai punti + for ( size_t i = 0 ; i < vPnt.size() ; ++ i) + PL.AddUPoint( 0, vPnt[i]) ; + // creo la curva composita + int nId = ExeCreateCurveCompoFromPoints( nParentId, PL, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveCompoFromPointBulges( lua_State* L) +{ + // 2 o 3 parametri : ParentId, ptPBs [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + PNTUVECTOR vPntB ; + LuaCheckParam( L, 2, vPntB) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // creo un poliarco a partire dai punti con bulge + PolyArc PA ; + for ( size_t i = 0 ; i < vPntB.size() ; ++ i) + PA.AddUPoint( 0, vPntB[i].first, vPntB[i].second) ; + // creo la curva composita + int nId = ExeCreateCurveCompoFromPointBulges( nParentId, PA, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateCurveCompoByApprox( lua_State* L) +{ + // 3 o 4 parametri : ParentId, nSouId, nArcsVsLines [, dLinTol] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nSouId ; + LuaCheckParam( L, 2, nSouId) + int nTemp ; + LuaCheckParam( L, 3, nTemp) + bool bArcsVsLines = ( nTemp != 0) ; + double dLinTol = 0.01 ; + LuaGetParam( L, 4, dLinTol) ; + LuaClearStack( L) ; + // creo la curva composita + int nId = ExeCreateCurveCompoByApprox( nParentId, nSouId, bArcsVsLines, dLinTol) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateRectangle3P( lua_State* L) +{ + // 4 o 5 parametri : ParentId, PtIni, PtCross, PtDir [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptIni ; + LuaCheckParam( L, 2, ptIni) + Point3d ptCross ; + LuaCheckParam( L, 3, ptCross) + Point3d ptDir ; + LuaCheckParam( L, 4, ptDir) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 5, nRefType) ; + LuaClearStack( L) ; + // creo il poligono + int nId = ExeCreateRectangle3P( nParentId, ptIni, ptCross, ptDir, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreatePolygonFromRadius( lua_State* L) +{ + // 5 o 6 parametri : ParentId, nNumSides, PtCen, PtCorn, VtN [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nNumSides ; + LuaCheckParam( L, 2, nNumSides) + Point3d PtCen ; + LuaCheckParam( L, 3, PtCen) + Point3d PtCorn ; + LuaCheckParam( L, 4, PtCorn) + Vector3d vtN ; + LuaCheckParam( L, 5, vtN) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // creo il poligono + int nId = ExeCreatePolygonFromRadius( nParentId, nNumSides, PtCen, PtCorn, vtN, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreatePolygonFromApothem( lua_State* L) +{ + // 5 o 6 parametri : ParentId, nNumSides, PtCen, PtMid, VtN [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nNumSides ; + LuaCheckParam( L, 2, nNumSides) + Point3d PtCen ; + LuaCheckParam( L, 3, PtCen) + Point3d PtMid ; + LuaCheckParam( L, 4, PtMid) + Vector3d vtN ; + LuaCheckParam( L, 5, vtN) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // creo il poligono + int nId = ExeCreatePolygonFromApothem( nParentId, nNumSides, PtCen, PtMid, vtN, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreatePolygonFromSide( lua_State* L) +{ + // 5 o 6 parametri : ParentId, nNumSides, PtIni, PtFin, VtN [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nNumSides ; + LuaCheckParam( L, 2, nNumSides) + Point3d ptIni ; + LuaCheckParam( L, 3, ptIni) + Point3d ptFin ; + LuaCheckParam( L, 4, ptFin) + Vector3d vtN ; + LuaCheckParam( L, 5, vtN) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // creo il poligono + int nId = ExeCreatePolygonFromSide( nParentId, nNumSides, ptIni, ptFin, vtN, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGdbCreateCurve( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtLine", LuaCreateCurveLine) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtLineEx", LuaCreateCurveLineEx) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtLinePVL", LuaCreateCurveLinePVL) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtLineMinPointCurve", LuaCreateCurveLineMinPointCurve) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCircle", LuaCreateCurveCircle) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCircleCPN", LuaCreateCurveCircleCPN) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCircleCPNEx", LuaCreateCurveCircleCPNEx) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCircle3P", LuaCreateCurveCircle3P) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtArc", LuaCreateCurveArc) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtArcC2PN", LuaCreateCurveArcC2PN) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtArcC2PNEx", LuaCreateCurveArcC2PNEx) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtArc3P", LuaCreateCurveArc3P) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtArc2PVN", LuaCreateCurveArc2PVN) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtArc2PVNEx", LuaCreateCurveArc2PVNEx) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveFillet", LuaCreateCurveFillet) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveChamfer", LuaCreateCurveChamfer) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveBezier", LuaCreateCurveBezier) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveBezierRat", LuaCreateCurveBezierRational) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveBezierFromArc", LuaCreateCurveBezierFromArc) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompo", LuaCreateCurveCompo) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoByChain", LuaCreateCurveCompoByChain) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoFromPoints", LuaCreateCurveCompoFromPoints) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoFromPointBulges", LuaCreateCurveCompoFromPointBulges) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoByApprox", LuaCreateCurveCompoByApprox) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRectangle3P", LuaCreateRectangle3P) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtPolygonFromRadius", LuaCreatePolygonFromRadius) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtPolygonFromApothem", LuaCreatePolygonFromApothem) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtPolygonFromSide", LuaCreatePolygonFromSide) ; + return bOk ; +} diff --git a/LUA_GdbCreateSurf.cpp b/LUA_GdbCreateSurf.cpp new file mode 100644 index 0000000..86f45f3 --- /dev/null +++ b/LUA_GdbCreateSurf.cpp @@ -0,0 +1,459 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2015 +//---------------------------------------------------------------------------- +// File : LUA_GdbCreateSurf.cpp Data : 07.01.15 Versione : 1.6a1 +// Contenuto : Funzioni di creazione superfici per LUA. +// +// +// +// Modifiche : 07.01.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" +#include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGnStringUtils.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static const double LIN_TOL_DEF = 0.05 ; + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmBBox( lua_State* L) +{ + // 2 o 3 parametri : ParentId, BBox3d [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + BBox3d b3Box ; + LuaCheckParam( L, 2, b3Box) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // creo STM bounding box + int nId = ExeCreateSurfTmBBox( nParentId, b3Box, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmBox( lua_State* L) +{ + // 5 o 6 parametri : ParentId, PtIni, PtCross, PtDir, dHeight [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptIni ; + LuaCheckParam( L, 2, ptIni) + Point3d ptCross ; + LuaCheckParam( L, 3, ptCross) + Point3d ptDir ; + LuaCheckParam( L, 4, ptDir) + double dHeight ; + LuaCheckParam( L, 5, dHeight) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // creo STM parallelepipedo + int nId = ExeCreateSurfTmBox( nParentId, ptIni, ptCross, ptDir, dHeight, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmPyramid( lua_State* L) +{ + // 5 o 6 parametri : ParentId, PtIni, PtCross, PtDir, dHeight [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptIni ; + LuaCheckParam( L, 2, ptIni) + Point3d ptCross ; + LuaCheckParam( L, 3, ptCross) + Point3d ptDir ; + LuaCheckParam( L, 4, ptDir) + double dHeight ; + LuaCheckParam( L, 5, dHeight) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // creo STM cilindro + int nId = ExeCreateSurfTmPyramid( nParentId, ptIni, ptCross, ptDir, dHeight, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmCylinder( lua_State* L) +{ + // 5 o 6 o 7 parametri : ParentId, PtOrig, vtN, dRad, dHeight [, dTol] [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptOrig ; + LuaCheckParam( L, 2, ptOrig) + Vector3d vtN ; + LuaCheckParam( L, 3, vtN) + double dRad ; + LuaCheckParam( L, 4, dRad) + double dHeight ; + LuaCheckParam( L, 5, dHeight) + double dLinTol = LIN_TOL_DEF ; + int nRefType = RTY_DEFAULT ; + if ( LuaGetParam( L, 6, dLinTol)) + LuaGetParam( L, 7, nRefType) ; + else + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // creo STM cilindro + int nId = ExeCreateSurfTmCylinder( nParentId, ptOrig, vtN, dRad, dHeight, dLinTol, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmCone( lua_State* L) +{ + // 5 o 6 o 7 parametri : ParentId, PtOrig, vtN, dRad, dHeight [, dTol] [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptOrig ; + LuaCheckParam( L, 2, ptOrig) + Vector3d vtN ; + LuaCheckParam( L, 3, vtN) + double dRad ; + LuaCheckParam( L, 4, dRad) + double dHeight ; + LuaCheckParam( L, 5, dHeight) + double dLinTol = LIN_TOL_DEF ; + int nRefType = RTY_DEFAULT ; + if ( LuaGetParam( L, 6, dLinTol)) + LuaGetParam( L, 7, nRefType) ; + else + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // creo STM cilindro + int nId = ExeCreateSurfTmCone( nParentId, ptOrig, vtN, dRad, dHeight, dLinTol, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmSphere( lua_State* L) +{ + // 3 o 4 o 5 parametri : ParentId, PtOrig, dRad [, dTol] [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptOrig ; + LuaCheckParam( L, 2, ptOrig) + double dRad ; + LuaCheckParam( L, 3, dRad) + double dLinTol = LIN_TOL_DEF ; + int nRefType = RTY_DEFAULT ; + if ( LuaGetParam( L, 4, dLinTol)) + LuaGetParam( L, 5, nRefType) ; + else + LuaGetParam( L, 4, nRefType) ; + LuaClearStack( L) ; + // creo STM cilindro + int nId = ExeCreateSurfTmSphere( nParentId, ptOrig, dRad, dLinTol, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmByFlatContour( lua_State* L) +{ + // 2 o 3 parametri : ParentId, CrvId [, dTol] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nCrvId ; + LuaCheckParam( L, 2, nCrvId) + double dLinTol = LIN_TOL_DEF ; + if ( lua_gettop( L) >= 3) + LuaCheckParam( L, 3, dLinTol) ; + LuaClearStack( L) ; + // creo STM riempiendo un contorno piano + int nId = ExeCreateSurfTmByFlatContour( nParentId, nCrvId, dLinTol) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmByRegion( lua_State* L) +{ + // 2 o 3 parametri : ParentId, CrvIds [, dTol] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + INTVECTOR vCrvIds ; + LuaCheckParam( L, 2, vCrvIds) + double dLinTol = LIN_TOL_DEF ; + if ( lua_gettop( L) >= 3) + LuaCheckParam( L, 3, dLinTol) ; + LuaClearStack( L) ; + // creo STM riempiendo una regione (piana) + int nId = ExeCreateSurfTmByRegion( nParentId, vCrvIds, dLinTol) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmByExtrusion( lua_State* L) +{ + // 3 o 4 o 5 parametri : ParentId, CrvIds, vtExtr [, dTol] [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + INTVECTOR vCrvIds ; + LuaCheckParam( L, 2, vCrvIds) + Vector3d vtExtr ; + LuaCheckParam( L, 3, vtExtr) + double dLinTol = LIN_TOL_DEF ; + int nRefType = RTY_DEFAULT ; + if ( LuaGetParam( L, 4, dLinTol)) + LuaGetParam( L, 5, nRefType) ; + else + LuaGetParam( L, 4, nRefType) ; + LuaClearStack( L) ; + // creo STM estrudendo uno o più percorsi, se piani si possono mettere i tappi + int nId = ExeCreateSurfTmByExtrusion( nParentId, vCrvIds, vtExtr, + dLinTol, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmByRegionExtrusion( lua_State* L) +{ + // 3 o 4 o 5 parametri : ParentId, CrvIds, vtExtr [, dTol] [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + INTVECTOR vCrvIds ; + LuaCheckParam( L, 2, vCrvIds) + Vector3d vtExtr ; + LuaCheckParam( L, 3, vtExtr) + double dLinTol = LIN_TOL_DEF ; + int nRefType = RTY_DEFAULT ; + if ( LuaGetParam( L, 4, dLinTol)) + LuaGetParam( L, 5, nRefType) ; + else + LuaGetParam( L, 4, nRefType) ; + LuaClearStack( L) ; + // creo STM estrudendo uno o più percorsi, con aggiunta dei tappi + int nId = ExeCreateSurfTmByRegionExtrusion( nParentId, vCrvIds, vtExtr, dLinTol, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmByRevolve( lua_State* L) +{ + // 5 o 6 o 7 parametri : ParentId, CrvId, ptAx, vtAx, bCapEnds [, dTol] [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nCrvId ; + LuaCheckParam( L, 2, nCrvId) + Point3d ptAx ; + LuaCheckParam( L, 3, ptAx) + Vector3d vtAx ; + LuaCheckParam( L, 4, vtAx) + bool bCapEnds ; + LuaCheckParam( L, 5, bCapEnds) + double dLinTol = 0.1 ; + int nRefType = RTY_DEFAULT ; + if ( LuaGetParam( L, 6, dLinTol)) + LuaGetParam( L, 7, nRefType) ; + else + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // creo STM riempiendo un contorno piano + int nId = ExeCreateSurfTmByRevolve( nParentId, nCrvId, ptAx, vtAx, bCapEnds, dLinTol, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmByScrewing( lua_State* L) +{ + // 6 o 7 o 8 parametri : ParentId, CrvId, ptAx, vtAx, dAngRotDeg, dMove [, dTol] [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nCrvId ; + LuaCheckParam( L, 2, nCrvId) + Point3d ptAx ; + LuaCheckParam( L, 3, ptAx) + Vector3d vtAx ; + LuaCheckParam( L, 4, vtAx) + double dAngRotDeg ; + LuaCheckParam( L, 5, dAngRotDeg) + double dMove ; + LuaCheckParam( L, 6, dMove) + double dLinTol = LIN_TOL_DEF ; + int nRefType = RTY_DEFAULT ; + if ( LuaGetParam( L, 7, dLinTol)) + LuaGetParam( L, 8, nRefType) ; + else + LuaGetParam( L, 7, nRefType) ; + LuaClearStack( L) ; + // creo STM riempiendo un contorno piano + int nId = ExeCreateSurfTmByScrewing( nParentId, nCrvId, ptAx, vtAx, dAngRotDeg, dMove, dLinTol, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmRuled( lua_State* L) +{ + // 3 o 4 parametri : ParentId, PtOrCrvId1, PtOrCrvId2, [, dTol] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + int nPtOrCrvId1 ; + LuaCheckParam( L, 2, nPtOrCrvId1) + int nPtOrCrvId2 ; + LuaCheckParam( L, 3, nPtOrCrvId2) + double dLinTol = LIN_TOL_DEF ; + if ( lua_gettop( L) >= 4) + LuaCheckParam( L, 4, dLinTol) ; + LuaClearStack( L) ; + // creo STM riempiendo un contorno piano + int nId = ExeCreateSurfTmRuled( nParentId, nPtOrCrvId1, nPtOrCrvId2, dLinTol) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCreateSurfTmByTriangles( lua_State* L) +{ + // 2 o 3 parametri : ParentId, Id/s [, bErase] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + INTVECTOR vId ; + LuaCheckParam( L, 2, vId) + bool bErase = true ; + if ( lua_gettop( L) >= 3) + LuaCheckParam( L, 3, bErase) ; + LuaClearStack( L) ; + // creo STM mediante cucitura di superfici + int nId = ExeCreateSurfTmByTriangles( nParentId, vId, bErase) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCreateSurfTmBySewing( lua_State* L) +{ + // 2 o 3 parametri : ParentId, Id/s [, bErase] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + INTVECTOR vId ; + LuaCheckParam( L, 2, vId) + bool bErase = true ; + if ( lua_gettop( L) >= 3) + LuaCheckParam( L, 3, bErase) ; + LuaClearStack( L) ; + // creo STM mediante cucitura di superfici + int nId = ExeCreateSurfTmBySewing( nParentId, vId, bErase) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGdbCreateSurf( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmBBox", LuaCreateSurfTmBBox) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmBox", LuaCreateSurfTmBox) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmPyramid", LuaCreateSurfTmPyramid) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmCylinder", LuaCreateSurfTmCylinder) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmCone", LuaCreateSurfTmCone) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmSphere", LuaCreateSurfTmSphere) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmByFlatContour", LuaCreateSurfTmByFlatContour) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmByRegion", LuaCreateSurfTmByRegion) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmByExtrusion", LuaCreateSurfTmByExtrusion) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmByRegionExtrusion", LuaCreateSurfTmByRegionExtrusion) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmByRevolve", LuaCreateSurfTmByRevolve) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmByScrewing", LuaCreateSurfTmByScrewing) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmRuled", LuaCreateSurfTmRuled) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmByTriangles", LuaCreateSurfTmByTriangles) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmBySewing", LuaCreateSurfTmBySewing) ; + return bOk ; +} diff --git a/LUA_GdbModify.cpp b/LUA_GdbModify.cpp new file mode 100644 index 0000000..17e8ea1 --- /dev/null +++ b/LUA_GdbModify.cpp @@ -0,0 +1,175 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_GdbModify.cpp Data : 06.10.14 Versione : 1.5i5 +// Contenuto : Funzioni di modifica geometrica per LUA. +// +// +// +// Modifiche : 06.10.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/ExeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" +#include "/EgtDev/Include/EGnStringUtils.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static int +LuaChangeGroupFrame( lua_State* L) +{ + // 2 o 3 parametri : Id, frNewRef [, nRefType] + int nId ; + LuaCheckParam( L, 1, nId) + Frame3d frNewRef ; + LuaCheckParam( L, 2, frNewRef) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // modifica del riferimento + bool bOk = ExeChangeGroupFrame( nId, frNewRef, nRefType) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaChangeVectorBase( lua_State* L) +{ + // 2 o 3 parametri : Id, ptBase [, nRefType] + int nId ; + LuaCheckParam( L, 1, nId) + Point3d ptBase ; + LuaCheckParam( L, 2, ptBase) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // modifica del punto base + bool bOk = ExeChangeVectorBase( nId, ptBase, nRefType) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaModifyText( lua_State* L) +{ + // 2 parametri : Id, sNewText + int nId ; + LuaCheckParam( L, 1, nId) + string sNewText ; + LuaCheckParam( L, 2, sNewText) + LuaClearStack( L) ; + // modifica del testo + bool bOk = ExeModifyText( nId, sNewText) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaChangeTextFont( lua_State* L) +{ + // 2 parametri : Id, sNewFont + int nId ; + LuaCheckParam( L, 1, nId) + string sNewFont ; + LuaCheckParam( L, 2, sNewFont) + LuaClearStack( L) ; + // modifica del testo + bool bOk = ExeChangeTextFont( nId, sNewFont) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaFlipText( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // flip del testo + bool bOk = ExeFlipText( nId) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaMirrorText( lua_State* L) +{ + // 1 o 2 parametri : Id [, bOnL] + int nId ; + LuaCheckParam( L, 1, nId) + bool bOnL = true ; + LuaGetParam( L, 2, bOnL) ; + LuaClearStack( L) ; + // flip del testo + bool bOk = ExeMirrorText( nId, bOnL) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaExplodeText( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // esplosione del testo in contorni + int nCount ; + int nFirstId = ExeExplodeText( nId, &nCount) ; + if ( nFirstId != GDB_ID_NULL) + LuaSetReturn( L, nFirstId) ; + else + LuaSetReturn( L) ; + LuaSetReturn( L, nCount) ; + return 2 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSplitText( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // esplosione del testo in più testi, uno per riga + int nCount ; + int nFirstId = ExeSplitText( nId, &nCount) ; + if ( nFirstId != GDB_ID_NULL) + LuaSetReturn( L, nFirstId) ; + else + LuaSetReturn( L) ; + LuaSetReturn( L, nCount) ; + return 2 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGdbModify( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtChangeGroupFrame", LuaChangeGroupFrame) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtChangeVectorBase", LuaChangeVectorBase) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtModifyText", LuaModifyText) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtChangeTextFont", LuaChangeTextFont) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtFlipText", LuaFlipText) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtMirrorText", LuaMirrorText) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtExplodeText", LuaExplodeText) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSplitText", LuaSplitText) ; + return bOk ; +} diff --git a/LUA_GdbModifyCurve.cpp b/LUA_GdbModifyCurve.cpp new file mode 100644 index 0000000..82c5e24 --- /dev/null +++ b/LUA_GdbModifyCurve.cpp @@ -0,0 +1,390 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_GdbModifyCurve.cpp Data : 28.12.14 Versione : 1.5l2 +// Contenuto : Funzioni di modifica delle curve per LUA. +// +// +// +// Modifiche : 03.10.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkCurve.h" +#include "/EgtDev/Include/EGkLuaAux.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +static int +LuaInvertCurve( lua_State* L) +{ + // 1 parametro : Id/s + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + LuaClearStack( L) ; + // eseguo inversione curve + bool bOk = ExeInvertCurve( vId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaOffsetCurve( lua_State* L) +{ + // 2 o 3 parametri : Id, dDist [, nType] + int nId ; + LuaCheckParam( L, 1, nId) + double dDist ; + LuaCheckParam( L, 2, dDist) + int nType = ICurve::OFF_FILLET ; + LuaGetParam( L, 3, nType) ; + LuaClearStack( L) ; + // offset della curva + bool bOk = ExeOffsetCurve( nId, dDist, nType) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaChangeClosedCurveStartPoint( lua_State* L) +{ + // 2 o 3 parametri : Id, NewStart [, nRefType] + int nId ; + LuaCheckParam( L, 1, nId) + Point3d ptStart ; + LuaCheckParam( L, 2, ptStart) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // modifico il punto iniziale + bool bOk = ExeChangeClosedCurveStartPoint( nId, ptStart, nRefType) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaModifyCurveStartPoint( lua_State* L) +{ + // 2 o 3 parametri : Id, NewStart [, nRefType] + int nId ; + LuaCheckParam( L, 1, nId) + Point3d ptStart ; + LuaCheckParam( L, 2, ptStart) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // modifico il punto iniziale + bool bOk = ExeModifyCurveStartPoint( nId, ptStart, nRefType) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaModifyCurveEndPoint( lua_State* L) +{ + // 2 o 3 parametri : Id, NewEnd [, nRefType] + int nId ; + LuaCheckParam( L, 1, nId) + Point3d ptEnd ; + LuaCheckParam( L, 2, ptEnd) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // modifico il punto finale + bool bOk = ExeModifyCurveEndPoint( nId, ptEnd, nRefType) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaModifyCurveExtrusion( lua_State* L) +{ + // 2 o 3 parametri : Id/s, vtExtr [, nRefType] + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + Vector3d vtExtr ; + LuaCheckParam( L, 2, vtExtr) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // modifico il vettore estrusione + bool bOk = ExeModifyCurveExtrusion( vId, vtExtr, nRefType) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaModifyCurveThickness( lua_State* L) +{ + // 2 parametri : Id/s, Thick + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + double dThick ; + LuaCheckParam( L, 2, dThick) + LuaClearStack( L) ; + // modifico lo spessore di estrusione + bool bOk = ExeModifyCurveThickness( vId, dThick) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaTrimCurveStartAtLen( lua_State* L) +{ + // 2 parametri : Id, dLen + int nId ; + LuaCheckParam( L, 1, nId) + double dLen ; + LuaCheckParam( L, 2, dLen) + LuaClearStack( L) ; + // taglio la curva all'inizio + bool bOk = ExeTrimCurveStartAtLen( nId, dLen) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaTrimCurveEndAtLen( lua_State* L) +{ + // 2 parametri : Id, dLen + int nId ; + LuaCheckParam( L, 1, nId) + double dLen ; + LuaCheckParam( L, 2, dLen) + LuaClearStack( L) ; + // taglio la curva alla fine + bool bOk = ExeTrimCurveEndAtLen( nId, dLen) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaTrimCurveStartAtParam( lua_State* L) +{ + // 2 parametri : Id, dPar + int nId ; + LuaCheckParam( L, 1, nId) + double dPar ; + LuaCheckParam( L, 2, dPar) + LuaClearStack( L) ; + // taglio la curva all' inizio + bool bOk = ExeTrimCurveStartAtParam( nId, dPar) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaTrimCurveEndAtParam( lua_State* L) +{ + // 2 parametri : Id, dPar + int nId ; + LuaCheckParam( L, 1, nId) + double dPar ; + LuaCheckParam( L, 2, dPar) + LuaClearStack( L) ; + // taglio la curva alla fine + bool bOk = ExeTrimCurveEndAtParam( nId, dPar) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaTrimCurveStartEndAtParam( lua_State* L) +{ + // 3 parametri : Id, dParS, dParE + int nId ; + LuaCheckParam( L, 1, nId) + double dParS ; + LuaCheckParam( L, 2, dParS) + double dParE ; + LuaCheckParam( L, 3, dParE) + LuaClearStack( L) ; + // taglio la curva alla fine + bool bOk = ExeTrimCurveStartEndAtParam( nId, dParS, dParE) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaTrimExtendCurveByLen( lua_State* L) +{ + // 3 o 4 parametri : Id, dLen, ptNear [, nRefType] + int nId ; + LuaCheckParam( L, 1, nId) + double dLen ; + LuaCheckParam( L, 2, dLen) + Point3d ptNear ; + LuaCheckParam( L, 3, ptNear) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 4, nRefType) ; + LuaClearStack( L) ; + // taglio o allungo la curva nell'estremo più vicino al punto + bool bOk = ExeTrimExtendCurveByLen( nId, dLen, ptNear, nRefType) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaSplitCurve( lua_State* L) +{ + // 2 parametri : Id, nParts + int nId ; + LuaCheckParam( L, 1, nId) + int nParts ; + LuaCheckParam( L, 2, nParts) + LuaClearStack( L) ; + // divido la curva nel punto + int nFirstId = ExeSplitCurve( nId, nParts) ; + if ( nFirstId != GDB_ID_NULL) + LuaSetReturn( L, nFirstId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaSplitCurveAtPoint( lua_State* L) +{ + // 2 o 3 parametri : Id, ptOn [, nRefType] + int nId ; + LuaCheckParam( L, 1, nId) + Point3d ptOn ; + LuaCheckParam( L, 2, ptOn) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // divido la curva nel punto + int nNewId = ExeSplitCurveAtPoint( nId, ptOn, nRefType) ; + if ( nNewId != GDB_ID_NULL) + LuaSetReturn( L, nNewId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaModifyCurveArcRadius( lua_State* L) +{ + // 2 parametri : Id, dNewRad + int nId ; + LuaCheckParam( L, 1, nId) + double dNewRad ; + LuaCheckParam( L, 2, dNewRad) + LuaClearStack( L) ; + // modifica del raggio + bool bOk = ExeModifyCurveArcRadius( nId, dNewRad) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaExplodeCurveCompo( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // esplosione della curva composita + int nCount ; + int nFirstId = ExeExplodeCurveCompo( nId, &nCount) ; + if ( nFirstId != GDB_ID_NULL) + LuaSetReturn( L, nFirstId) ; + else + LuaSetReturn( L) ; + LuaSetReturn( L, nCount) ; + return 2 ; +} + +//------------------------------------------------------------------------------- +static int +LuaApproxCurveArc( lua_State* L) +{ + // 1 o 2 parametri : Id [, dLinTol] + int nId ; + LuaCheckParam( L, 1, nId) + double dLinTol = 0.01 ; + LuaGetParam( L, 2, dLinTol) ; + LuaClearStack( L) ; + // approssimazione dell'arco con rette + int nNewId = ExeApproxCurveArc( nId, dLinTol) ; + if ( nNewId != GDB_ID_NULL) + LuaSetReturn( L, nNewId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaApproxCurveBezier( lua_State* L) +{ + // 2 o 3 parametri : Id, nArcsVsLines [, dLinTol] + int nId ; + LuaCheckParam( L, 1, nId) + int nTemp ; + LuaCheckParam( L, 2, nTemp) + bool bArcsVsLines = ( nTemp != 0) ; + double dLinTol = 0.01 ; + LuaGetParam( L, 3, dLinTol) ; + LuaClearStack( L) ; + // approssimazione della curva di Bezier con archi o rette + int nNewId = ExeApproxCurveBezier( nId, bArcsVsLines, dLinTol) ; + if ( nNewId != GDB_ID_NULL) + LuaSetReturn( L, nNewId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGdbModifyCurve( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtInvertCurve", LuaInvertCurve) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtOffsetCurve", LuaOffsetCurve) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtChangeClosedCurveStartPoint", LuaChangeClosedCurveStartPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtModifyCurveStartPoint", LuaModifyCurveStartPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtModifyCurveEndPoint", LuaModifyCurveEndPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtModifyCurveExtrusion", LuaModifyCurveExtrusion) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtModifyCurveThickness", LuaModifyCurveThickness) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTrimCurveStartAtLen", LuaTrimCurveStartAtLen) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTrimCurveEndAtLen", LuaTrimCurveEndAtLen) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTrimCurveStartAtParam", LuaTrimCurveStartAtParam) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTrimCurveEndAtParam", LuaTrimCurveEndAtParam) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTrimCurveStartEndAtParam", LuaTrimCurveStartEndAtParam) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTrimExtendCurveByLen", LuaTrimExtendCurveByLen) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSplitCurve", LuaSplitCurve) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSplitCurveAtPoint", LuaSplitCurveAtPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtModifyCurveArcRadius", LuaModifyCurveArcRadius) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtExplodeCurveCompo", LuaExplodeCurveCompo) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtApproxCurveArc", LuaApproxCurveArc) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtApproxCurveBezier", LuaApproxCurveBezier) ; + return bOk ; +} diff --git a/LUA_GdbModifySurf.cpp b/LUA_GdbModifySurf.cpp new file mode 100644 index 0000000..748115e --- /dev/null +++ b/LUA_GdbModifySurf.cpp @@ -0,0 +1,92 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : LUA_GdbModifySurf.cpp Data : 09.03.15 Versione : 1.6b6 +// Contenuto : Funzioni di modifica delle superfici per LUA. +// +// +// +// Modifiche : 09.03.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" + +using namespace std ; + + +//---------------------------------------------------------------------------- +static int +LuaInvertSurf( lua_State* L) +{ + // 1 parametro : Id/s + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + LuaClearStack( L) ; + // eseguo inversione superfici + bool bOk = ExeInvertSurface( vId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaExtractSurfTmFacetLoops( lua_State* L) +{ + // 3 parametri : nId, nFacet, nDestGrpId + int nId ; + LuaCheckParam( L, 1, nId) + int nFacet ; + LuaCheckParam( L, 2, nFacet) + int nDestGrpId ; + LuaCheckParam( L, 3, nDestGrpId) + LuaClearStack( L) ; + // eseguo inversione superfici + int nCount ; + int nNewId = ExeExtractSurfTmFacetLoops( nId, nFacet, nDestGrpId, &nCount) ; + // restituisco il risultato + if ( nNewId != GDB_ID_NULL) + LuaSetReturn( L, nNewId) ; + else + LuaSetReturn( L) ; + LuaSetReturn( L, nCount) ; + return 2 ; +} + +//------------------------------------------------------------------------------- +static int +LuaExplodeSurfTm( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // esplosione della superficie trimesh + int nCount ; + int nFirstId = ExeExplodeSurfTm( nId, &nCount) ; + if ( nFirstId != GDB_ID_NULL) + LuaSetReturn( L, nFirstId) ; + else + LuaSetReturn( L) ; + LuaSetReturn( L, nCount) ; + return 2 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGdbModifySurf( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtInvertSurf", LuaInvertSurf) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtExtractSurfTmFacetLoops", LuaExtractSurfTmFacetLoops) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtExplodeSurfTm", LuaExplodeSurfTm) ; + return bOk ; +} diff --git a/LUA_GdbObjAttribs.cpp b/LUA_GdbObjAttribs.cpp new file mode 100644 index 0000000..2eda847 --- /dev/null +++ b/LUA_GdbObjAttribs.cpp @@ -0,0 +1,579 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_GdbObjAttribs.cpp Data : 30.09.14 Versione : 1.5i5 +// Contenuto : Funzioni di trasformazione geometrica per LUA. +// +// +// +// Modifiche : 30.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" +#include "/EgtDev/Include/EGnStringUtils.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static int +LuaSetLevel( lua_State* L) +{ + // 2 parametri : nId, nLevel + int nId ; + LuaCheckParam( L, 1, nId) + int nLevel ; + LuaCheckParam( L, 2, nLevel) + // imposto lo stato + bool bOk = ExeSetLevel( nId, nLevel) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRevertLevel( lua_State* L) +{ + // 1 parametro : nId + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // porto il livello al valore precedente + bool bOk = ExeRevertLevel( nId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetLevel( lua_State* L) +{ + // 1 parametro : nId + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il livello + int nLevel ; + bool bOk = ExeGetLevel( nId, &nLevel) ; + // restituisco il risultato + if ( bOk) + LuaSetReturn( L, nLevel) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetCalcLevel( lua_State* L) +{ + // 1 parametro : nId + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il livello + int nLevel ; + bool bOk = ExeGetCalcLevel( nId, &nLevel) ; + // restituisco il risultato + if ( bOk) + LuaSetReturn( L, nLevel) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetMode( lua_State* L) +{ + // 2 parametri : nId, nMode + int nId ; + LuaCheckParam( L, 1, nId) + int nMode ; + LuaCheckParam( L, 2, nMode) + LuaClearStack( L) ; + // imposto il modo + bool bOk = ExeSetMode( nId, nMode) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRevertMode( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // porto il modo al valore precedente + bool bOk = ExeRevertMode( nId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetMode( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il modo + int nMode ; + if ( ExeGetMode( nId, &nMode)) + // restituisco il risultato + LuaSetReturn( L, nMode) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetCalcMode( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il modo calcolato (ovvero proprio ed ereditato) + int nMode ; + if ( ExeGetCalcMode( nId, &nMode)) + // restituisco il risultato + LuaSetReturn( L, nMode) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetStatus( lua_State* L) +{ + // 2 parametri : Id, nStatus + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + int nStatus ; + LuaCheckParam( L, 2, nStatus) + LuaClearStack( L) ; + // imposto lo stato + bool bOk = ExeSetStatus( vId, nStatus) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRevertStatus( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // porto lo stato al valore precedente + bool bOk = ExeRevertStatus( nId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetStatus( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero lo stato + int nStatus ; + if ( ExeGetStatus( nId, &nStatus)) + // restituisco il risultato + LuaSetReturn( L, nStatus) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetCalcStatus( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero lo stato + int nStatus ; + if ( ExeGetCalcStatus( nId, &nStatus)) + // restituisco il risultato + LuaSetReturn( L, nStatus) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetMark( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // imposto l'evidenziazione + bool bOk = ExeSetMark( nId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaResetMark( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // cancello l'evidenziazione + bool bOk = ExeResetMark( nId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetMark( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero lo stato di evidenziazione + BOOL nMark ; + if ( ExeGetMark( nId, &nMark)) + // restituisco il risultato + LuaSetReturn( L, ( nMark != GDB_MK_OFF)) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetCalcMark( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero lo stato calcolato di evidenziazione + BOOL nMark ; + if ( ExeGetCalcMark( nId, &nMark)) + // restituisco il risultato + LuaSetReturn( L, ( nMark != GDB_MK_OFF)) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaStdColor( lua_State* L) +{ + // 1 parametro : Nome + string sName ; + LuaCheckParam( L, 1, sName) + LuaClearStack( L) ; + // recupero il colore con il nome indicato + Color cCol ; + if ( ExeStdColor( sName, cCol)) { + // restituisco il risultato + LuaSetReturn( L, cCol) ; + } + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetColor( lua_State* L) +{ + // 2 o 3 parametri : Id/s, Colore [, bSetAlpha] + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + Color cCol ; + LuaCheckParam( L, 2, cCol) + bool bSetAlpha = true ; + LuaGetParam( L, 3, bSetAlpha) ; + LuaClearStack( L) ; + // assegno il colore + bool bOk = ExeSetColor( vId, cCol, bSetAlpha) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetAlpha( lua_State* L) +{ + // 2 : Id/s, nAlpha + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + int nAlpha ; + LuaCheckParam( L, 2, nAlpha) + LuaClearStack( L) ; + // assegno la trasparenza + bool bOk = ExeSetAlpha( vId, nAlpha) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaResetColor( lua_State* L) +{ + // 1 parametro : Id/s + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + LuaClearStack( L) ; + // tolgo il colore + bool bOk = ExeResetColor( vId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetColor( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il colore + Color cCol ; + if ( ExeGetColor( nId, cCol)) { + // restituisco il risultato + LuaSetReturn( L, cCol) ; + } + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetCalcColor( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il colore + Color cCol ; + if ( ExeGetCalcColor( nId, cCol)) { + // restituisco il risultato + LuaSetReturn( L, cCol) ; + } + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetName( lua_State* L) +{ + // 2 parametri : Id, Name + int nId ; + LuaCheckParam( L, 1, nId) + string sName ; + LuaCheckParam( L, 2, sName) + LuaClearStack( L) ; + // assegno il nome + bool bOk = ExeSetName( nId, sName) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetName( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il nome + string sName ; + bool bOk = ExeGetName( nId, sName) ; + // restituisco il risultato + if ( bOk) + LuaSetReturn( L, sName) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaExistsName( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // verifico esistenza nome + bool bOk = ExeExistsName( nId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRemoveName( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // verifico esistenza nome + bool bOk = ExeRemoveName( nId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetInfo( lua_State* L) +{ + // 3 parametri : Id, Key, Info + int nId ; + LuaCheckParam( L, 1, nId) + string sKey ; + LuaCheckParam( L, 2, sKey) + string sInfo ; + LuaCheckParam( L, 3, sInfo) + LuaClearStack( L) ; + // assegno la info + bool bOk = ExeSetInfo( nId, sKey, sInfo) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetInfo( lua_State* L) +{ + // 2 parametri : Id, Key + int nId ; + LuaCheckParam( L, 1, nId) + string sKey ; + LuaCheckParam( L, 2, sKey) + LuaClearStack( L) ; + // recupero l'info + string sInfo ; + bool bOk = ExeGetInfo( nId, sKey, sInfo) ; + // restituisco il risultato + if ( bOk) + LuaSetReturn( L, sInfo) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaExistsInfo( lua_State* L) +{ + // 2 parametri : Id, Key + int nId ; + LuaCheckParam( L, 1, nId) + string sKey ; + LuaCheckParam( L, 2, sKey) + LuaClearStack( L) ; + // verifico esistenza info + bool bOk = ExeExistsInfo( nId, sKey) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRemoveInfo( lua_State* L) +{ + // 2 parametri : Id, Key + int nId ; + LuaCheckParam( L, 1, nId) + string sKey ; + LuaCheckParam( L, 2, sKey) + LuaClearStack( L) ; + // rimuovo info + bool bOk = ExeRemoveInfo( nId, sKey) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGdbObjAttribs( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetLevel", LuaSetLevel) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRevertLevel", LuaRevertLevel) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetLevel", LuaGetLevel) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetCalcLevel", LuaGetCalcLevel) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetMode", LuaSetMode) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRevertMode", LuaRevertMode) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetMode", LuaGetMode) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetCalcMode", LuaGetCalcMode) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetStatus", LuaSetStatus) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRevertStatus", LuaRevertStatus) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetStatus", LuaGetStatus) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetCalcStatus", LuaGetCalcStatus) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetMark", LuaSetMark) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtResetMark", LuaResetMark) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetMark", LuaGetMark) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetCalcMark", LuaGetCalcMark) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtStdColor", LuaStdColor) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetColor", LuaSetColor) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetAlpha", LuaSetAlpha) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtResetColor", LuaResetColor) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetColor", LuaGetColor) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetCalcColor", LuaGetCalcColor) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetName", LuaSetName) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetName", LuaGetName) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtExistsName", LuaExistsName) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRemoveName", LuaRemoveName) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetInfo", LuaSetInfo) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetInfo", LuaGetInfo) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtExistsInfo", LuaExistsInfo) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRemoveInfo", LuaRemoveInfo) ; + return bOk ; +} diff --git a/LUA_GdbObjSelection.cpp b/LUA_GdbObjSelection.cpp new file mode 100644 index 0000000..40b452e --- /dev/null +++ b/LUA_GdbObjSelection.cpp @@ -0,0 +1,221 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : LUA_GdbObjSelection.cpp Data : 08.01.15 Versione : 1.6a1 +// Contenuto : Funzioni di selezione oggetti del DB geometrico per LUA. +// +// +// +// Modifiche : 08.01.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static int +LuaSelectObj( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // eseguo la selezione + bool bOk = ExeSelectObj( nId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaDeselectObj( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // eseguo la selezione + bool bOk = ExeDeselectObj( nId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSelectAll( lua_State* L) +{ + // 1 parametro : bOnlyIfVisible + bool bOnlyIfVisible ; + LuaCheckParam( L, 1, bOnlyIfVisible) + LuaClearStack( L) ; + // eseguo la selezione + bool bOk = ExeSelectAll( bOnlyIfVisible) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaDeselectAll( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // eseguo la selezione + bool bOk = ExeDeselectAll() ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSelectGroupObjs( lua_State* L) +{ + // 1 parametro : GroupId + int GroupId ; + LuaCheckParam( L, 1, GroupId) + LuaClearStack( L) ; + // eseguo la selezione + bool bOk = ExeSelectGroupObjs( GroupId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaDeselectGroupObjs( lua_State* L) +{ + // 1 parametro : GroupId + int GroupId ; + LuaCheckParam( L, 1, GroupId) + LuaClearStack( L) ; + // eseguo la deselezione + bool bOk = ExeDeselectGroupObjs( GroupId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaIsSelectedObj( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // eseguo la selezione + bool bOk = ExeIsSelectedObj( nId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetSelectedObjNbr( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // eseguo la selezione + int nNbr = ExeGetSelectedObjNbr() ; + // restituisco il risultato + LuaSetReturn( L, nNbr) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetFirstSelectedObj( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // recupero il primo oggetto selezionato + int nId = ExeGetFirstSelectedObj() ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetNextSelectedObj( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // recupero il successivo oggetto selezionato + int nId = ExeGetNextSelectedObj() ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetLastSelectedObj( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // recupero l'ultimo oggetto selezionato + int nId = ExeGetLastSelectedObj() ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetPrevSelectedObj( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // recupero il precedente oggetto selezionato + int nId = ExeGetPrevSelectedObj() ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGdbObjSelection( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSelectObj", LuaSelectObj) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtDeselectObj", LuaDeselectObj) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSelectAll", LuaSelectAll) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtDeselectAll", LuaDeselectAll) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSelectGroupObjs", LuaSelectGroupObjs) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtDeselectGroupObjs", LuaDeselectGroupObjs) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtIsSelectedObj", LuaIsSelectedObj) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetSelectedObjNbr", LuaGetSelectedObjNbr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstSelectedObj", LuaGetFirstSelectedObj) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetNextSelectedObj", LuaGetNextSelectedObj) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetLastSelectedObj", LuaGetLastSelectedObj) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetPrevSelectedObj", LuaGetPrevSelectedObj) ; + return bOk ; +} diff --git a/LUA_GdbObjects.cpp b/LUA_GdbObjects.cpp new file mode 100644 index 0000000..11371cd --- /dev/null +++ b/LUA_GdbObjects.cpp @@ -0,0 +1,518 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_GdbObjects.cpp Data : 30.09.14 Versione : 1.5i5 +// Contenuto : Funzioni di iterazione di DB geometrico per LUA. +// +// +// +// Modifiche : 30.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" + +using namespace std ; + + +//------------------------------------------------------------------------------- +static int +LuaExistsObj( lua_State* L) +{ + // 1 parametro : Id + int nId = GDB_ID_NULL ; + LuaGetParam( L, 1, nId) ; + LuaClearStack( L) ; + // verifico esistenza oggetto + bool bOk = ExeExistsObj( nId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetType( lua_State* L) +{ + // 1 parametro : Id + int nId = GDB_ID_NULL ; + LuaGetParam( L, 1, nId) ; + LuaClearStack( L) ; + // recupero tipo dell'oggetto + int nType = ExeGetType( nId) ; + // restituisco il risultato + LuaSetReturn( L, nType) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetGroupObjs( lua_State* L) +{ + // 1 parametro : GroupId + int nGroupId ; + LuaCheckParam( L, 1, nGroupId) + LuaClearStack( L) ; + // determino il numero di oggetti nel gruppo + int nObjs = ExeGetGroupObjs( nGroupId) ; + // restituisco il risultato + LuaSetReturn( L, nObjs) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetFirstInGroup( lua_State* L) +{ + // 1 parametro : GroupId + int nGroupId ; + LuaCheckParam( L, 1, nGroupId) + LuaClearStack( L) ; + // recupero il primo oggetto del gruppo + int nId = ExeGetFirstInGroup( nGroupId) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetNext( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il prossimo oggetto nello stesso gruppo + int nNextId = ExeGetNext( nId) ; + // restituisco il risultato + if ( nNextId != GDB_ID_NULL) + LuaSetReturn( L, nNextId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetLastInGroup( lua_State* L) +{ + // 1 parametro : GroupId + int nGroupId ; + LuaCheckParam( L, 1, nGroupId) + LuaClearStack( L) ; + // recupero l'ultimo oggetto del gruppo + int nId = ExeGetLastInGroup( nGroupId) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetPrev( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il precedente oggetto nello stesso gruppo + int nPrevId = ExeGetPrev( nId) ; + // restituisco il risultato + if ( nPrevId != GDB_ID_NULL) + LuaSetReturn( L, nPrevId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetFirstNameInGroup( lua_State* L) +{ + // 2 parametri : GroupId, sName + int nGroupId ; + LuaCheckParam( L, 1, nGroupId) + string sName ; + LuaCheckParam( L, 2, sName) + LuaClearStack( L) ; + // recupero il primo oggetto del gruppo con il nome desiderato + int nId = ExeGetFirstNameInGroup( nGroupId, sName) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetNextName( lua_State* L) +{ + // 2 parametri : Id, sName + int nId ; + LuaCheckParam( L, 1, nId) + string sName ; + LuaCheckParam( L, 2, sName) + LuaClearStack( L) ; + // recupero il prossimo oggetto nello stesso gruppo con il nome desiderato + int nNextId = ExeGetNextName( nId, sName) ; + // restituisco il risultato + if ( nNextId != GDB_ID_NULL) + LuaSetReturn( L, nNextId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetLastNameInGroup( lua_State* L) +{ + // 2 parametri : GroupId, sName + int nGroupId ; + LuaCheckParam( L, 1, nGroupId) + string sName ; + LuaCheckParam( L, 2, sName) + LuaClearStack( L) ; + // recupero l'ultimo oggetto del gruppo con il nome desiderato + int nId = ExeGetLastNameInGroup( nGroupId, sName) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetPrevName( lua_State* L) +{ + // 2 parametri : Id, sName + int nId ; + LuaCheckParam( L, 1, nId) + string sName ; + LuaCheckParam( L, 2, sName) + LuaClearStack( L) ; + // recupero il precedente oggetto nello stesso gruppo con il nome desiderato + int nPrevId = ExeGetPrevName( nId, sName) ; + // restituisco il risultato + if ( nPrevId != GDB_ID_NULL) + LuaSetReturn( L, nPrevId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetFirstGroupInGroup( lua_State* L) +{ + // 1 parametro : GroupId + int nGroupId ; + LuaCheckParam( L, 1, nGroupId) + LuaClearStack( L) ; + // recupero il primo oggetto gruppo del gruppo + int nId = ExeGetFirstGroupInGroup( nGroupId) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetNextGroup( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il prossimo oggetto gruppo dello stesso gruppo + int nNewId = ExeGetNextGroup( nId) ; + // restituisco il risultato + if ( nNewId != GDB_ID_NULL) + LuaSetReturn( L, nNewId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetLastGroupInGroup( lua_State* L) +{ + // 1 parametro : GroupId + int nGroupId ; + LuaCheckParam( L, 1, nGroupId) + LuaClearStack( L) ; + // recupero l'ultimo oggetto gruppo del gruppo + int nId = ExeGetLastGroupInGroup( nGroupId) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetPrevGroup( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il precedenteo oggetto gruppo dello stesso gruppo + int nNewId = ExeGetPrevGroup( nId) ; + // restituisco il risultato + if ( nNewId != GDB_ID_NULL) + LuaSetReturn( L, nNewId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetBBox( lua_State* L) +{ + // 2 parametri : Id, nFlag + int nId ; + LuaCheckParam( L, 1, nId) + int nFlag ; + LuaCheckParam( L, 2, nFlag) + LuaClearStack( L) ; + // recupero il bounding box dell'oggetto in locale + BBox3d b3Box ; + bool bOk = ExeGetBBox( nId, nFlag, b3Box) ; + // restituisco il risultato + if ( bOk) + LuaSetReturn( L, b3Box) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetBBoxGlob( lua_State* L) +{ + // 2 parametri : Id, nFlag + int nId ; + LuaCheckParam( L, 1, nId) + int nFlag ; + LuaCheckParam( L, 2, nFlag) + LuaClearStack( L) ; + // recupero il bounding box dell'oggetto in globale + BBox3d b3Box ; + bool bOk = ExeGetBBoxGlob( nId, nFlag, b3Box) ; + // restituisco il risultato + if ( bOk) + LuaSetReturn( L, b3Box) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetBBoxRef( lua_State* L) +{ + // 3 parametri : Id, nFlag, Ref + int nId ; + LuaCheckParam( L, 1, nId) + int nFlag ; + LuaCheckParam( L, 2, nFlag) + Frame3d frRef ; + LuaCheckParam( L, 3, frRef) + LuaClearStack( L) ; + // recupero il bounding box dell'oggetto in globale + BBox3d b3Box ; + bool bOk = ExeGetBBoxRef( nId, nFlag, frRef, b3Box) ; + // restituisco il risultato + if ( bOk) + LuaSetReturn( L, b3Box) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCopy( lua_State* L) +{ + // 2 o 3 parametri : SouId, RefId [, nSonBeforeAfter] + int nSouId ; + LuaCheckParam( L, 1, nSouId) + int nRefId ; + LuaCheckParam( L, 2, nRefId) + int nSonBeforeAfter = GDB_LAST_SON ; + LuaGetParam( L, 3, nSonBeforeAfter) ; + LuaClearStack( L) ; + // eseguo la copia + int nNewId = ExeCopy( nSouId, nRefId, nSonBeforeAfter) ; + // restituisco il risultato + if ( nNewId != GDB_ID_NULL) + LuaSetReturn( L, nNewId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCopyGlob( lua_State* L) +{ + // 2 o 3 parametri : SouId, RefId [, nSonBeforeAfter] + int nSouId ; + LuaCheckParam( L, 1, nSouId) + int nRefId ; + LuaCheckParam( L, 2, nRefId) + int nSonBeforeAfter = GDB_LAST_SON ; + LuaGetParam( L, 3, nSonBeforeAfter) ; + LuaClearStack( L) ; + // eseguo la copia + int nNewId = ExeCopyGlob( nSouId, nRefId, nSonBeforeAfter) ; + // restituisco il risultato + if ( nNewId != GDB_ID_NULL) + LuaSetReturn( L, nNewId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRelocate( lua_State* L) +{ + // 2 o 3 parametri : SouId, RefId [, nSonBeforeAfter] + int nSouId ; + LuaCheckParam( L, 1, nSouId) + int nRefId ; + LuaCheckParam( L, 2, nRefId) + int nSonBeforeAfter = GDB_LAST_SON ; + LuaGetParam( L, 3, nSonBeforeAfter) ; + LuaClearStack( L) ; + // eseguo la rilocazione + bool bOk = ( ExeRelocate( nSouId, nRefId, nSonBeforeAfter) != FALSE) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRelocateGlob( lua_State* L) +{ + // 2 o 3 parametri : SouId, RefId [, SonBeforeAfter] + int nSouId ; + LuaCheckParam( L, 1, nSouId) + int nRefId ; + LuaCheckParam( L, 2, nRefId) + int nSonBeforeAfter = GDB_LAST_SON ; + LuaGetParam( L, 3, nSonBeforeAfter) ; + LuaClearStack( L) ; + // eseguo la rilocazione + bool bOk = ExeRelocateGlob( nSouId, nRefId, nSonBeforeAfter) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaChangeId( lua_State* L) +{ + // 2 parametri : Id, nNewId + int nId ; + LuaCheckParam( L, 1, nId) + int nNewId ; + LuaCheckParam( L, 2, nNewId) + LuaClearStack( L) ; + // eseguo il cambio di identificativo + bool bOk = ExeChangeId( nId, nNewId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaErase( lua_State* L) +{ + // 1 parametro : Id/s + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + LuaClearStack( L) ; + // eseguo la cancellazione + bool bOk = ExeErase( vId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaEmptyGroup( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // eseguo la cancellazione + bool bOk = ExeEmptyGroup( nId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGdbObjects( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtExistsObj", LuaExistsObj) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetType", LuaGetType) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetGroupObjs", LuaGetGroupObjs) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstInGroup", LuaGetFirstInGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetNext", LuaGetNext) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetLastInGroup", LuaGetLastInGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetPrev", LuaGetPrev) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstNameInGroup", LuaGetFirstNameInGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetNextName", LuaGetNextName) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetLastNameInGroup", LuaGetLastNameInGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetPrevName", LuaGetPrevName) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstGroupInGroup", LuaGetFirstGroupInGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetNextGroup", LuaGetNextGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetLastGroupInGroup", LuaGetLastGroupInGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetPrevGroup", LuaGetPrevGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetBBox", LuaGetBBox) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetBBoxGlob", LuaGetBBoxGlob) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetBBoxRef", LuaGetBBoxRef) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCopy", LuaCopy) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCopyGlob", LuaCopyGlob) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRelocate", LuaRelocate) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRelocateGlob", LuaRelocateGlob) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtChangeId", LuaChangeId) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtErase", LuaErase) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtEmptyGroup", LuaEmptyGroup) ; + return bOk ; +} diff --git a/LUA_GdbPartLayers.cpp b/LUA_GdbPartLayers.cpp new file mode 100644 index 0000000..98b3772 --- /dev/null +++ b/LUA_GdbPartLayers.cpp @@ -0,0 +1,301 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : LUA_GdbPartLayers.cpp Data : 29.01.15 Versione : 1.6a7 +// Contenuto : Funzioni di gestione pezzi e layer relativi per LUA. +// +// +// +// Modifiche : 29.01.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static int +LuaIsPart( lua_State* L) +{ + // 1 parametro : nIdPart + int nIdPart ; + LuaCheckParam( L, 1, nIdPart) + LuaClearStack( L) ; + // verifico sia un pezzo + bool bOk = ExeIsPart( nIdPart) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaIsLayer( lua_State* L) +{ + // 1 parametro : nIdLayer + int nIdLayer ; + LuaCheckParam( L, 1, nIdLayer) + LuaClearStack( L) ; + // verifico sia un layer + bool bOk = ExeIsLayer( nIdLayer) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetCurrPart( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // recupero il pezzo corrente + int nId = ExeGetCurrPart() ; + // restituisco il risultato + LuaSetReturn( L, nId) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetCurrLayer( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // recupero il layer corrente + int nId = ExeGetCurrLayer() ; + // restituisco il risultato + LuaSetReturn( L, nId) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetCurrPartLayer( lua_State* L) +{ + // 2 parametri : nPartId, nLayerId + int nPartId ; + LuaCheckParam( L, 1, nPartId) + int nLayerId ; + LuaCheckParam( L, 2, nLayerId) + LuaClearStack( L) ; + // imposto pezzo e layer correnti + bool bOk = ExeSetCurrPartLayer( nPartId, nLayerId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaResetCurrPartLayer( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // cerco primo pezzo e layer validi per essere dichiarati correnti + bool bOk = ExeResetCurrPartLayer() ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetPartNbr( lua_State* L) +{ + // nessuno o 1 parametro : [bOnlyVisible] + bool bOnlyVisible = false ; + LuaGetParam( L, 1, bOnlyVisible) ; + LuaClearStack( L) ; + // recupero numero pezzi + int nNbr = ExeGetPartNbr( bOnlyVisible) ; + // restituisco il risultato + LuaSetReturn( L, nNbr) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetFirstPart( lua_State* L) +{ + // nessuno o 1 parametro : [bOnlyVisible] + bool bOnlyVisible = false ; + LuaGetParam( L, 1, bOnlyVisible) ; + LuaClearStack( L) ; + // cerco primo pezzo + int nId = ExeGetFirstPart( bOnlyVisible) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetNextPart( lua_State* L) +{ + // 1 o 2 parametri : nPartId [, bOnlyVisible] + int nPartId ; + LuaCheckParam( L, 1, nPartId) + bool bOnlyVisible = false ; + LuaGetParam( L, 2, bOnlyVisible) ; + LuaClearStack( L) ; + // cerco pezzo successivo + int nId = ExeGetNextPart( nPartId, bOnlyVisible) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetFirstLayer( lua_State* L) +{ + // 1 o 2 parametri : nPartId [, bOnlyVisible] + int nPartId ; + LuaCheckParam( L, 1, nPartId) + bool bOnlyVisible = false ; + LuaGetParam( L, 2, bOnlyVisible) ; + LuaClearStack( L) ; + // cerco il primo layer del pezzo + int nId = ExeGetFirstLayer( nPartId, bOnlyVisible) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetNextLayer( lua_State* L) +{ + // 1 o 2 parametri : nLayerId [, bOnlyVisible] + int nLayerId ; + LuaCheckParam( L, 1, nLayerId) + bool bOnlyVisible = false ; + LuaGetParam( L, 2, bOnlyVisible) ; + LuaClearStack( L) ; + // cerco il prossimo layer (ovviamente dello stesso pezzo) + int nId = ExeGetNextLayer( nLayerId, bOnlyVisible) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSelectPartObjs( lua_State* L) +{ + // 1 parametro : PartId + int nPartId ; + LuaCheckParam( L, 1, nPartId) + LuaClearStack( L) ; + // eseguo la selezione + bool bOk = ExeSelectPartObjs( nPartId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaDeselectPartObjs( lua_State* L) +{ + // 1 parametro : PartId + int nPartId ; + LuaCheckParam( L, 1, nPartId) + LuaClearStack( L) ; + // eseguo la selezione + bool bOk = ExeDeselectPartObjs( nPartId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSelectLayerObjs( lua_State* L) +{ + // 1 parametro : LayerId + int nLayerId ; + LuaCheckParam( L, 1, nLayerId) + LuaClearStack( L) ; + // eseguo la selezione + bool bOk = ExeSelectLayerObjs( nLayerId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaDeselectLayerObjs( lua_State* L) +{ + // 1 parametro : LayerId + int nLayerId ; + LuaCheckParam( L, 1, nLayerId) + LuaClearStack( L) ; + // eseguo la selezione + bool bOk = ExeDeselectLayerObjs( nLayerId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSelectPathObjs( lua_State* L) +{ + // 2 parametri : nId, bHaltOnFork + int nId ; + LuaCheckParam( L, 1, nId) + bool bHaltOnFork ; + LuaCheckParam( L, 2, bHaltOnFork) + LuaClearStack( L) ; + // eseguo la selezione + bool bOk = ExeSelectPathObjs( nId, bHaltOnFork) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGdbPartLayer( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetCurrPart", LuaGetCurrPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtIsPart", LuaIsPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtIsLayer", LuaIsLayer) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetCurrLayer", LuaGetCurrLayer) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetCurrPartLayer", LuaSetCurrPartLayer) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtResetCurrPartLayer", LuaResetCurrPartLayer) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetPartNbr", LuaGetPartNbr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstPart", LuaGetFirstPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetNextPart", LuaGetNextPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstLayer", LuaGetFirstLayer) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetNextLayer", LuaGetNextLayer) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSelectPartObjs", LuaSelectPartObjs) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtDeselectPartObjs", LuaDeselectPartObjs) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSelectLayerObjs", LuaSelectLayerObjs) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtDeselectLayerObjs", LuaDeselectLayerObjs) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSelectPathObjs", LuaSelectPathObjs) ; + return bOk ; +} diff --git a/LUA_General.cpp b/LUA_General.cpp new file mode 100644 index 0000000..1243ff2 --- /dev/null +++ b/LUA_General.cpp @@ -0,0 +1,321 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_General.cpp Data : 27.09.14 Versione : 1.5i5 +// Contenuto : Funzioni generali per LUA. +// +// +// +// Modifiche : 27.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "LUA.h" +#include "/EgtDev/Include/ExeExecutor.h" +#include "/EgtDev/Include/EGkLuaAux.h" +#include "/EgtDev/Include/EGnStringUtils.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EGnFileUtils.h" +#include "/EgtDev/Include/EGnFileCompare.h" +#include "/EgtDev/Include/EgtPerfCounter.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +static PerformanceCounter s_Counter ; + +//------------------------------------------------------------------------------- +static int +MyPrint( lua_State* L) +{ + string sOut ; + int n = lua_gettop( L) ; /* number of arguments */ + lua_getglobal( L, "tostring") ; + for ( int i = 1 ; i <= n ; ++ i) { + const char* s ; + lua_pushvalue( L, -1) ; /* function to be called */ + lua_pushvalue( L, i) ; /* value to print */ + lua_call( L, 1, 1) ; + s = lua_tostring( L, -1) ; /* get result */ + if ( s == nullptr) + return luaL_error( L, + LUA_QL("tostring") " must return a string to " LUA_QL("print")) ; + if ( i > 1) + sOut += "\t" ; + sOut += s ; + lua_pop( L, 1) ; /* pop result */ + } + if ( ! sOut.empty()) + LOG_INFO( GetLogger(), sOut.c_str()) + + return 0 ; +} + +//------------------------------------------------------------------------------- +static int +SetContext( lua_State* L) +{ + // un solo parametro intero + int nGseCtx ; + LuaCheckParam( L, 1, nGseCtx) + LuaClearStack( L) ; + // imposto il contesto + bool bOk = SetCurrGseContext( nGseCtx) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +GetContext( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // restituisco l'indice del contesto + LuaSetReturn( L, GetIndCurrGseContext()) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaPause( lua_State* L) +{ + // 1 parametro : numero di millisecondi + int nTime ; + LuaCheckParam( L, 1, nTime) + LuaClearStack( L) ; + // controllo la durata della pausa e la eseguo + const int MIN_TIME = 0 ; + const int MAX_TIME = 10000 ; + if ( nTime < MIN_TIME) + nTime = MIN_TIME ; + else if ( nTime > MAX_TIME) + nTime = MAX_TIME ; + Sleep( nTime) ; + // restituisco il risultato + LuaSetReturn( L, true) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaStartCounter( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // avvio il contatore + s_Counter.Start() ; + return 0 ; +} + +//------------------------------------------------------------------------------- +static int +LuaStopCounter( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // fermo il contatore + double dTime = s_Counter.Stop() ; + // restituisco il risultato + LuaSetReturn( L, dTime) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaNumToString( lua_State* L) +{ + // 2 parametri : dVal, nDec + double dVal ; + LuaCheckParam( L, 1, dVal) + int nDec ; + LuaCheckParam( L, 2, nDec) + LuaClearStack( L) ; + // costruisco la stringa + string sVal = ToString( dVal, nDec) ; + // ritorno il risultato + LuaSetReturn( L, sVal) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaExecTsc( lua_State* L) +{ + // 1 parametro : file + string sFile ; + LuaCheckParam( L, 1, sFile) + LuaClearStack( L) ; + // eseguo lo script TSC + bool bOk = ExeTscExecFile( sFile) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaOutLog( lua_State* L) +{ + // 1 parametro : stringa da emettere + string sOut ; + LuaCheckParam( L, 1, sOut) + LuaClearStack( L) ; + // accodo il messaggio nel file di log + LOG_INFO( GetLogger(), sOut.c_str()) + // non c'è risultato + return 0 ; +} + +//------------------------------------------------------------------------------- +static int +LuaOutBox( lua_State* L) +{ + // 3 parametri : stringa, titolo, icona + string sOut ; + LuaCheckParam( L, 1, sOut) + string sTitle ; + LuaCheckParam( L, 2, sTitle) + string sIcon ; + LuaCheckParam( L, 3, sIcon) + int nIcon = MB_ICONINFORMATION ; + ToUpper( sIcon) ; + if ( sIcon == "ERROR") + nIcon = MB_ICONERROR ; + else if ( sIcon == "WARNING") + nIcon = MB_ICONWARNING ; + LuaClearStack( L) ; + // accodo il messaggio nel file di log + int nRes = MessageBox( nullptr, stringtoW( sOut), stringtoW( sTitle), MB_OKCANCEL | nIcon | MB_TASKMODAL) ; + // risultato (Ok->true, Cancel->false) + LuaSetReturn( L, ( nRes == IDOK)) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaEraseFile( lua_State* L) +{ + // 1 parametro : file + string sFile ; + LuaCheckParam( L, 1, sFile) + LuaClearStack( L) ; + // svuoto il direttorio + bool bOk = EraseFile( sFile) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaEmptyDirectory( lua_State* L) +{ + // 1 parametro : dir + string sDir ; + LuaCheckParam( L, 1, sDir) + LuaClearStack( L) ; + // svuoto il direttorio + bool bOk = EmptyDirectory( sDir) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaTextFileCompare( lua_State* L) +{ + // 4 parametri : file1, file2, inizio commento, file diff + string sFile1 ; + LuaCheckParam( L, 1, sFile1) + string sFile2 ; + LuaCheckParam( L, 2, sFile2) + string sRemStart ; + LuaCheckParam( L, 3, sRemStart) + string sFileDiff ; + LuaCheckParam( L, 4, sFileDiff) + LuaClearStack( L) ; + // eseguo il confronto + bool bOk = TextFileCompare( sFile1, sFile2, sRemStart, sFileDiff) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaBinaryFileCompare( lua_State* L) +{ + // 3 parametri : file1, file2, file diff + string sFile1 ; + LuaCheckParam( L, 1, sFile1) + string sFile2 ; + LuaCheckParam( L, 2, sFile2) + string sFileDiff ; + LuaCheckParam( L, 3, sFileDiff) + LuaClearStack( L) ; + // eseguo il confronto + bool bOk = BinaryFileCompare( sFile1, sFile2, sFileDiff) ; + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetVersion( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // costruisco la stringa con le versioni + string sVer ; + if ( ! ExeGetVersionInfo( sVer, "\n")) + sVer = "VersionInfo error" ; + // restituisco il risultato + LuaSetReturn( L, sVer) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaIs64bit( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // restituisco il risultato +#if defined( _WIN64) + bool bRes = true ; +#elif defined( _WIN32) + bool bRes = false ; +#endif + LuaSetReturn( L, bRes) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGeneral( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "print", MyPrint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetContext", SetContext) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetContext", GetContext) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtPause", LuaPause) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtStartCounter", LuaStartCounter) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtStopCounter", LuaStopCounter) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtNumToString", LuaNumToString) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtExecTsc", LuaExecTsc) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtOutLog", LuaOutLog) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtOutBox", LuaOutBox) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtEraseFile", LuaEraseFile) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtEmptyDirectory", LuaEmptyDirectory) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTextFileCompare", LuaTextFileCompare) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtBinaryFileCompare", LuaBinaryFileCompare) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetVersion", LuaGetVersion) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtIs64bit", LuaIs64bit) ; + return bOk ; +} diff --git a/LUA_GeoBase.cpp b/LUA_GeoBase.cpp new file mode 100644 index 0000000..e547e9e --- /dev/null +++ b/LUA_GeoBase.cpp @@ -0,0 +1,467 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_GeoBasel.cpp Data : 20.12.14 Versione : 1.5l2 +// Contenuto : Funzioni generali per LUA. +// +// +// +// Modifiche : 27.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EGkLuaAux.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static int +LuaVectorRotate( lua_State* L) +{ + // 3 parametri : Vector, VtAsse, AngRot in gradi + Vector3d vtV ; + LuaCheckParam( L, 1, vtV) + Vector3d vtAx ; + LuaCheckParam( L, 2, vtAx) + double dAngRotDeg ; + LuaCheckParam( L, 3, dAngRotDeg) + LuaClearStack( L) ; + // eseguo la rotazione + if ( vtV.Rotate( vtAx, dAngRotDeg)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, vtV) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaVectorToGlob( lua_State* L) +{ + // 2 parametri : Vector, frame di trasformazione + Vector3d vtV ; + LuaCheckParam( L, 1, vtV) + Frame3d frTool ; + LuaCheckParam( L, 2, frTool) + LuaClearStack( L) ; + // eseguo la trasformazione + if ( vtV.ToGlob( frTool)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, vtV) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaVectorToLoc( lua_State* L) +{ + // 2 parametri : Vector, frame di trasformazione + Vector3d vtV ; + LuaCheckParam( L, 1, vtV) + Frame3d frTool ; + LuaCheckParam( L, 2, frTool) + LuaClearStack( L) ; + // eseguo la trasformazione + if ( vtV.ToLoc( frTool)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, vtV) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaVectorLocToLoc( lua_State* L) +{ + // 3 parametri : Vector, frame origine, frame destinazione + Vector3d vtV ; + LuaCheckParam( L, 1, vtV) + Frame3d frOri ; + LuaCheckParam( L, 2, frOri) + Frame3d frDest ; + LuaCheckParam( L, 3, frDest) + LuaClearStack( L) ; + // eseguo la trasformazione + if ( vtV.LocToLoc( frOri, frDest)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, vtV) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaPointRotate( lua_State* L) +{ + // 4 parametri : Point, PtAsse, VtAsse, AngRot in gradi + Point3d ptP ; + LuaCheckParam( L, 1, ptP) + Point3d ptAx ; + LuaCheckParam( L, 2, ptAx) + Vector3d vtAx ; + LuaCheckParam( L, 3, vtAx) + double dAngRotDeg ; + LuaCheckParam( L, 4, dAngRotDeg) + LuaClearStack( L) ; + // eseguo la rotazione + if ( ptP.Rotate( ptAx, vtAx, dAngRotDeg)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, ptP) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaPointToGlob( lua_State* L) +{ + // 2 parametri : Point, frame di trasformazione + Point3d ptP ; + LuaCheckParam( L, 1, ptP) + Frame3d frTool ; + LuaCheckParam( L, 2, frTool) + LuaClearStack( L) ; + // eseguo la trasformazione + if ( ptP.ToGlob( frTool)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, ptP) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaPointToLoc( lua_State* L) +{ + // 2 parametri : Point, frame di trasformazione + Point3d ptP ; + LuaCheckParam( L, 1, ptP) + Frame3d frTool ; + LuaCheckParam( L, 2, frTool) + LuaClearStack( L) ; + // eseguo la trasformazione + if ( ptP.ToLoc( frTool)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, ptP) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaPointLocToLoc( lua_State* L) +{ + // 3 parametri : Point, frame origine, frame destinazione + Point3d ptP ; + LuaCheckParam( L, 1, ptP) + Frame3d frOri ; + LuaCheckParam( L, 2, frOri) + Frame3d frDest ; + LuaCheckParam( L, 3, frDest) + LuaClearStack( L) ; + // eseguo la trasformazione + if ( ptP.LocToLoc( frOri, frDest)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, ptP) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaFrameFrom3Points( lua_State* L) +{ + // 3 parametri : origine, punto su X, punto vicino a Y + Point3d ptOrig ; + LuaCheckParam( L, 1, ptOrig) + Point3d ptOnX ; + LuaCheckParam( L, 2, ptOnX) + Point3d ptNearY ; + LuaCheckParam( L, 3, ptNearY) + LuaClearStack( L) ; + // calcolo il riferimento e restituisco il risultato : bOk, Frame + Frame3d frTemp ; + if ( frTemp.Set( ptOrig, ptOnX, ptNearY)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, frTemp) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaFrameOCS( lua_State* L) +{ + // 2 parametri : origine, asse Z + Point3d ptOrig ; + LuaCheckParam( L, 1, ptOrig) + Vector3d vtDirZ ; + LuaCheckParam( L, 2, vtDirZ) + LuaClearStack( L) ; + // calcolo il riferimento e restituisco il risultato : bOk, Frame + Frame3d frTemp ; + if ( frTemp.Set( ptOrig, vtDirZ)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, frTemp) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaFrameRotate( lua_State* L) +{ + // 4 parametri : Frame, PtAsse, VtAsse, AngRot in gradi + Frame3d frFrame ; + LuaCheckParam( L, 1, frFrame) + Point3d ptAx ; + LuaCheckParam( L, 2, ptAx) + Vector3d vtAx ; + LuaCheckParam( L, 3, vtAx) + double dAngRotDeg ; + LuaCheckParam( L, 4, dAngRotDeg) + LuaClearStack( L) ; + // eseguo la rotazione + if ( frFrame.Rotate( ptAx, vtAx, dAngRotDeg)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, frFrame) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaFrameToGlob( lua_State* L) +{ + // 2 parametri : frame, frame di trasformazione + Frame3d frFrame ; + LuaCheckParam( L, 1, frFrame) + Frame3d frTool ; + LuaCheckParam( L, 2, frTool) + LuaClearStack( L) ; + // eseguo la trasformazione + if ( frFrame.ToGlob( frTool)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, frFrame) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaFrameToLoc( lua_State* L) +{ + // 2 parametri : frame, frame di trasformazione + Frame3d frFrame ; + LuaCheckParam( L, 1, frFrame) + Frame3d frTool ; + LuaCheckParam( L, 2, frTool) + LuaClearStack( L) ; + // eseguo la trasformazione + if ( frFrame.ToLoc( frTool)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, frFrame) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaFrameLocToLoc( lua_State* L) +{ + // 3 parametri : frame, frame origine, frame destinazione + Frame3d frFrame ; + LuaCheckParam( L, 1, frFrame) + Frame3d frOri ; + LuaCheckParam( L, 2, frOri) + Frame3d frDest ; + LuaCheckParam( L, 3, frDest) + LuaClearStack( L) ; + // eseguo la trasformazione + if ( frFrame.LocToLoc( frOri, frDest)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, frFrame) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaBBoxRotate( lua_State* L) +{ + // 4 parametri : bbox, PtAsse, VtAsse, AngRot in gradi + BBox3d b3Box ; + LuaCheckParam( L, 1, b3Box) + Point3d ptAx ; + LuaCheckParam( L, 2, ptAx) + Vector3d vtAx ; + LuaCheckParam( L, 3, vtAx) + double dAngRotDeg ; + LuaCheckParam( L, 4, dAngRotDeg) + LuaClearStack( L) ; + // eseguo la rotazione + if ( b3Box.Rotate( ptAx, vtAx, dAngRotDeg)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, b3Box) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaBBoxToGlob( lua_State* L) +{ + // 2 parametri : bbox, frame di trasformazione + BBox3d b3Box ; + LuaCheckParam( L, 1, b3Box) + Frame3d frTool ; + LuaCheckParam( L, 2, frTool) + LuaClearStack( L) ; + // eseguo la trasformazione + if ( b3Box.ToGlob( frTool)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, b3Box) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaBBoxToLoc( lua_State* L) +{ + // 2 parametri : bbox, frame di trasformazione + BBox3d b3Box ; + LuaCheckParam( L, 1, b3Box) + Frame3d frTool ; + LuaCheckParam( L, 2, frTool) + LuaClearStack( L) ; + // eseguo la trasformazione + if ( b3Box.ToLoc( frTool)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, b3Box) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +static int +LuaBBoxLocToLoc( lua_State* L) +{ + // 3 parametri : bbox, frame origine, frame destinazione + BBox3d b3Box ; + LuaCheckParam( L, 1, b3Box) + Frame3d frOri ; + LuaCheckParam( L, 2, frOri) + Frame3d frDest ; + LuaCheckParam( L, 3, frDest) + LuaClearStack( L) ; + // eseguo la trasformazione + if ( b3Box.LocToLoc( frOri, frDest)) { + LuaSetReturn( L, true) ; + LuaSetReturn( L, b3Box) ; + return 2 ; + } + else { + LuaSetReturn( L, false) ; + return 1 ; + } +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGeoBase( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtVectorRotate", LuaVectorRotate) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtVectorToGlob", LuaVectorToGlob) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtVectorToLoc", LuaVectorToLoc) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtVectorLocToLoc", LuaVectorLocToLoc) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtPointRotate", LuaPointRotate) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtPointToGlob", LuaPointToGlob) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtPointToLoc", LuaPointToLoc) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtPointLocToLoc", LuaPointLocToLoc) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtFrameFrom3Points", LuaFrameFrom3Points) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtFrameOCS", LuaFrameOCS) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtFrameRotate", LuaFrameRotate) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtFrameToGlob", LuaFrameToGlob) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtFrameToLoc", LuaFrameToLoc) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtFrameLocToLoc", LuaFrameLocToLoc) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtBBoxRotate", LuaBBoxRotate) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtBBoxToGlob", LuaBBoxToGlob) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtBBoxToLoc", LuaBBoxToLoc) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtBBoxLocToLoc", LuaBBoxLocToLoc) ; + return bOk ; +} diff --git a/LUA_GeoSnap.cpp b/LUA_GeoSnap.cpp new file mode 100644 index 0000000..2f50144 --- /dev/null +++ b/LUA_GeoSnap.cpp @@ -0,0 +1,582 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_GeoSnap.cpp Data : 02.10.14 Versione : 1.5i5 +// Contenuto : Funzioni di snap ad oggetti del DB geometrico per LUA. +// +// +// +// Modifiche : 02.10.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkLuaAux.h" + +using namespace std ; + + +//---------------------------------------------------------------------------- +static int +LuaStartPoint( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il punto iniziale dell'entità + Point3d ptP ; + if ( ExeStartPoint( nId, nRefId, ptP)) + LuaSetReturn( L, ptP) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaEndPoint( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il punto finale dell'entità + Point3d ptP ; + if ( ExeEndPoint( nId, nRefId, ptP)) + LuaSetReturn( L, ptP) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaMidPoint( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il punto centrale dell'entità + Point3d ptP ; + if ( ExeMidPoint( nId, nRefId, ptP)) + LuaSetReturn( L, ptP) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCenterPoint( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il punto centrale dell'entità + Point3d ptP ; + if ( ExeCenterPoint( nId, nRefId, ptP)) + LuaSetReturn( L, ptP) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCentroid( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il centro geometrico dell'entità + Point3d ptP ; + if ( ExeCentroid( nId, nRefId, ptP)) + LuaSetReturn( L, ptP) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaAtParamPoint( lua_State* L) +{ + // 2 o 3 parametri : Id, U [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + double dU ; + LuaCheckParam( L, 2, dU) + int nRefId = nId ; + LuaGetParam( L, 3, nRefId) ; + LuaClearStack( L) ; + // recupero il punto in posizione parametrica U della curva + Point3d ptP ; + if ( ExeAtParamPoint( nId, dU, nRefId, ptP)) + LuaSetReturn( L, ptP) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaNearPoint( lua_State* L) +{ + // 2 o 3 parametri : Id, ptNear [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + Point3d ptNear ; + LuaCheckParam( L, 2, ptNear) + int nRefId = nId ; + LuaGetParam( L, 3, nRefId) ; + LuaClearStack( L) ; + // recupero il punto di intersezione tra le curve più vicino al punto passato + Point3d ptP ; + if ( ExeNearPoint( nId, ptNear, nRefId, ptP)) + LuaSetReturn( L, ptP) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaIntersectionPoint( lua_State* L) +{ + // 3 o 4 parametri : Id1, Id2, ptNear [, nRefId] + int nId1 ; + LuaCheckParam( L, 1, nId1) + int nId2 ; + LuaCheckParam( L, 2, nId2) + Point3d ptNear ; + LuaCheckParam( L, 3, ptNear) + int nRefId = nId1 ; + LuaGetParam( L, 4, nRefId) ; + LuaClearStack( L) ; + // recupero il punto di intersezione tra le curve più vicino al punto passato + Point3d ptP ; + if ( ExeIntersectionPoint( nId1, nId2, ptNear, nRefId, ptP)) + LuaSetReturn( L, ptP) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaStartVector( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il vettore tangente all'inizio della curva + Vector3d vtV ; + if ( ExeStartVector( nId, nRefId, vtV)) + LuaSetReturn( L, vtV) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaEndVector( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il vettore tangente alla fine della curva + Vector3d vtV ; + if ( ExeEndVector( nId, nRefId, vtV)) + LuaSetReturn( L, vtV) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaMidVector( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il vettore tangente nel punto medio della curva + Vector3d vtV ; + if ( ExeMidVector( nId, nRefId, vtV)) + LuaSetReturn( L, vtV) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaAtParamVector( lua_State* L) +{ + // 2, 3 o 4 parametri : Id, U, nSide [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + double dU ; + LuaCheckParam( L, 2, dU) + int nSide ; + LuaCheckParam( L, 3, nSide) ; + int nRefId = nId ; + LuaGetParam( L, 4, nRefId) ; + LuaClearStack( L) ; + // recupero il punto in posizione parametrica U della curva + Vector3d vtV ; + if ( ExeAtParamVector( nId, dU, nSide, nRefId, vtV)) + LuaSetReturn( L, vtV) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaFrame( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il frame + Frame3d frFrame ; + if ( ExeFrame( nId, nRefId, frFrame)) + LuaSetReturn( L, frFrame) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCurveLength( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero la lunghezza della curva + double dLen ; + if ( ExeCurveLength( nId, &dLen) != FALSE) + LuaSetReturn( L, dLen) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCurveExtrusion( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il versore + Vector3d vtExtr ; + if ( ExeCurveExtrusion( nId, nRefId, vtExtr)) + LuaSetReturn( L, vtExtr) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCurveThickness( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero lo spessore + double dThick ; + if ( ExeCurveThickness( nId, &dThick) != FALSE) + LuaSetReturn( L, dThick) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaExtrusionByThickness( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il versore e lo spessore + Vector3d vtExtr ; + double dThick ; + if ( ExeCurveExtrusion( nId, nRefId, vtExtr) && ! vtExtr.IsSmall() && + ExeCurveThickness( nId, &dThick) && fabs( dThick) > EPS_SMALL) + vtExtr *= dThick ; + else + vtExtr = V_NULL ; + LuaSetReturn( L, vtExtr) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCurveArcRadius( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il raggio + double dRad ; + if ( ExeCurveArcRadius( nId, &dRad) != FALSE) + LuaSetReturn( L, dRad) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCurveArcNormVersor( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il versore + Vector3d vtNorm ; + if ( ExeCurveArcNormVersor( nId, nRefId, vtNorm)) + LuaSetReturn( L, vtNorm) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCurveCompoCenter( lua_State* L) +{ + // 2 o 3 parametri : Id, nCrv [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nCrv ; + LuaCheckParam( L, 2, nCrv) + int nRefId = nId ; + LuaGetParam( L, 3, nRefId) ; + LuaClearStack( L) ; + // recupero il centro della curva semplice indicizzata + Point3d ptCen ; + if ( ExeCurveCompoCenter( nId, nCrv, nRefId, ptCen)) + LuaSetReturn( L, ptCen) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaSurfTmFacetNbr( lua_State* L) +{ + // 1 parametro : Id + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero il numero di facce della superficie trimesh + int nNbr = ExeSurfTmFacetNbr( nId) ; + LuaSetReturn( L, nNbr) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaSurfTmFacetNearestEndPoint( lua_State* L) +{ + // 3 o 4 parametri : Id, nFacet, ptNear [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nFacet ; + LuaCheckParam( L, 2, nFacet) + Point3d ptNear ; + LuaCheckParam( L, 3, ptNear) + int nRefId = nId ; + LuaGetParam( L, 4, nRefId) ; + LuaClearStack( L) ; + // recupero il punto End più vicino della faccia della superficie trimesh + Point3d ptEnd ; + Vector3d vtN ; + if ( ExeSurfTmFacetNearestEndPoint( nId, nFacet, ptNear, nRefId, ptEnd, vtN)) { + LuaSetReturn( L, ptEnd) ; + LuaSetReturn( L, vtN) ; + } + else { + LuaSetReturn( L) ; + LuaSetReturn( L) ; + } + return 2 ; +} + +//---------------------------------------------------------------------------- +static int +LuaSurfTmFacetNearestMidPoint( lua_State* L) +{ + // 3 o 4 parametri : Id, nFacet, ptNear [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nFacet ; + LuaCheckParam( L, 2, nFacet) + Point3d ptNear ; + LuaCheckParam( L, 3, ptNear) + int nRefId = nId ; + LuaGetParam( L, 4, nRefId) ; + LuaClearStack( L) ; + // recupero il punto Mid più vicino della faccia della superficie trimesh + Point3d ptMid ; + Vector3d vtN ; + if ( ExeSurfTmFacetNearestMidPoint( nId, nFacet, ptNear, nRefId, ptMid, vtN)) { + LuaSetReturn( L, ptMid) ; + LuaSetReturn( L, vtN) ; + } + else { + LuaSetReturn( L) ; + LuaSetReturn( L) ; + } + return 2 ; +} + +//---------------------------------------------------------------------------- +static int +LuaSurfTmFacetCenter( lua_State* L) +{ + // 2 o 3 parametri : Id, nFacet [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nFacet ; + LuaCheckParam( L, 2, nFacet) + int nRefId = nId ; + LuaGetParam( L, 3, nRefId) ; + LuaClearStack( L) ; + // recupero il centro della faccia della superficie trimesh + Point3d ptCen ; + Vector3d vtN ; + if ( ExeSurfTmFacetCenter( nId, nFacet, nRefId, ptCen, vtN)) { + LuaSetReturn( L, ptCen) ; + LuaSetReturn( L, vtN) ; + } + else { + LuaSetReturn( L) ; + LuaSetReturn( L) ; + } + return 2 ; +} + +//---------------------------------------------------------------------------- +static int +LuaSurfTmFacetNormVersor( lua_State* L) +{ + // 2 o 3 parametri : Id, nFacet [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nFacet ; + LuaCheckParam( L, 2, nFacet) + int nRefId = nId ; + LuaGetParam( L, 3, nRefId) ; + LuaClearStack( L) ; + // recupero la normale della faccia della superficie trimesh + Vector3d vtNorm ; + if ( ExeSurfTmFacetNormVersor( nId, nFacet, nRefId, vtNorm)) + LuaSetReturn( L, vtNorm) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaExtTextNormVersor( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero il versore + Vector3d vtNorm ; + if ( ExeExtTextNormVersor( nId, nRefId, vtNorm)) + LuaSetReturn( L, vtNorm) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGeoSnap( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSP", LuaStartPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtEP", LuaEndPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtMP", LuaMidPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCP", LuaCenterPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGP", LuaCentroid) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtUP", LuaAtParamPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtNP", LuaNearPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtIP", LuaIntersectionPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSV", LuaStartVector) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtEV", LuaEndVector) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtMV", LuaMidVector) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtUV", LuaAtParamVector) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtFR", LuaFrame) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtET", LuaExtrusionByThickness) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveLength", LuaCurveLength) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveExtrusion", LuaCurveExtrusion) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveThickness", LuaCurveThickness) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveArcRadius", LuaCurveArcRadius) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveArcNormVersor", LuaCurveArcNormVersor) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoCenter", LuaCurveCompoCenter) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetNbr", LuaSurfTmFacetNbr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetNearestEndPoint", LuaSurfTmFacetNearestEndPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetNearestMidPoint", LuaSurfTmFacetNearestMidPoint) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetCenter", LuaSurfTmFacetCenter) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetNormVersor", LuaSurfTmFacetNormVersor) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtExtTextNormVersor", LuaExtTextNormVersor) ; + return bOk ; +} diff --git a/LUA_GeoTransform.cpp b/LUA_GeoTransform.cpp new file mode 100644 index 0000000..c23c00b --- /dev/null +++ b/LUA_GeoTransform.cpp @@ -0,0 +1,255 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_GeoTransform.cpp Data : 29.09.14 Versione : 1.5i5 +// Contenuto : Funzioni di trasformazione geometrica per LUA. +// +// +// +// Modifiche : 29.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static int +LuaMove( lua_State* L) +{ + // 2 o 3 parametri : Id/s, VtMove [, nRefType] + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + Vector3d vtMove ; + LuaCheckParam( L, 2, vtMove) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // eseguo traslazione + bool bOk = ExeMove( vId, vtMove, nRefType) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRotate( lua_State* L) +{ + // 4 o 5 parametri : Id/s, PtAx, VtAx, dAngRotDeg [, nRefType] + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + Point3d ptAx ; + LuaCheckParam( L, 2, ptAx) + Vector3d vtAx ; + LuaCheckParam( L, 3, vtAx) + double dAngRotDeg ; + LuaCheckParam( L, 4, dAngRotDeg) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 5, nRefType) ; + LuaClearStack( L) ; + // eseguo rotazione + bool bOk = ExeRotate( vId, ptAx, vtAx, dAngRotDeg, nRefType) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaScale( lua_State* L) +{ + // 5 o 6 parametri : Id/s, Frame, CoeffX, CoeffY, CoeffZ [, nRefType] + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + Frame3d frRef ; + LuaCheckParam( L, 2, frRef) + double dCoeffX ; + LuaCheckParam( L, 3, dCoeffX) + double dCoeffY ; + LuaCheckParam( L, 4, dCoeffY) + double dCoeffZ ; + LuaCheckParam( L, 5, dCoeffZ) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // eseguo scalatura + bool bOk = ExeScale( vId, frRef, dCoeffX, dCoeffY, dCoeffZ, nRefType) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaMirror( lua_State* L) +{ + // 3 o 4 parametri : Id/s, PtOn, VtN [, nRefType] + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + Point3d ptOn ; + LuaCheckParam( L, 2, ptOn) + Vector3d vtN ; + LuaCheckParam( L, 3, vtN) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 4, nRefType) ; + LuaClearStack( L) ; + // eseguo riflessione + bool bOk = ExeMirror( vId, ptOn, vtN, nRefType) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaShear( lua_State* L) +{ + // 5 o 6 parametri : Id, PtOn, VtN, VtDir, Coeff [, nRefType] + INTVECTOR vId ; + LuaCheckParam( L, 1, vId) + Point3d ptOn ; + LuaCheckParam( L, 2, ptOn) + Vector3d vtN ; + LuaCheckParam( L, 3, vtN) + Vector3d vtDir ; + LuaCheckParam( L, 4, vtDir) + double dCoeff ; + LuaCheckParam( L, 5, dCoeff) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // eseguo stiramento + bool bOk = ExeShear( vId, ptOn, vtN, vtDir, dCoeff, nRefType) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaMoveGroup( lua_State* L) +{ + // 2 parametri : Id, VtMove + int nId ; + LuaCheckParam( L, 1, nId) + Vector3d vtMove ; + LuaCheckParam( L, 2, vtMove) + LuaClearStack( L) ; + // eseguo traslazione + bool bOk = ExeMoveGroup( nId, vtMove) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRotateGroup( lua_State* L) +{ + // 4 parametri : Id, PtAx, VtAx, dAngRotDeg + int nId ; + LuaCheckParam( L, 1, nId) + Point3d ptAx ; + LuaCheckParam( L, 2, ptAx) + Vector3d vtAx ; + LuaCheckParam( L, 3, vtAx) + double dAngRotDeg ; + LuaCheckParam( L, 4, dAngRotDeg) + LuaClearStack( L) ; + // eseguo rotazione + bool bOk = ExeRotateGroup( nId, ptAx, vtAx, dAngRotDeg) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaScaleGroup( lua_State* L) +{ + // 5 parametri : Id, Frame, CoeffX, CoeffY, CoeffZ + int nId ; + LuaCheckParam( L, 1, nId) + Frame3d frRef ; + LuaCheckParam( L, 2, frRef) + double dCoeffX ; + LuaCheckParam( L, 3, dCoeffX) + double dCoeffY ; + LuaCheckParam( L, 4, dCoeffY) + double dCoeffZ ; + LuaCheckParam( L, 5, dCoeffZ) + LuaClearStack( L) ; + // eseguo scalatura + bool bOk = ExeScaleGroup( nId, frRef, dCoeffX, dCoeffY, dCoeffZ) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaMirrorGroup( lua_State* L) +{ + // 3 parametri : Id, PtOn, VtN + int sId ; + LuaCheckParam( L, 1, sId) + Point3d ptOn ; + LuaCheckParam( L, 2, ptOn) + Vector3d vtN ; + LuaCheckParam( L, 3, vtN) + LuaClearStack( L) ; + // eseguo scalatura + bool bOk = ExeMirrorGroup( sId, ptOn, vtN) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaShearGroup( lua_State* L) +{ + // 5 parametri : Id, PtOn, VtN, VtDir, Coeff + int nId ; + LuaCheckParam( L, 1, nId) + Point3d ptOn ; + LuaCheckParam( L, 2, ptOn) + Vector3d vtN ; + LuaCheckParam( L, 3, vtN) + Vector3d vtDir ; + LuaCheckParam( L, 4, vtDir) + double dCoeff ; + LuaCheckParam( L, 5, dCoeff) + LuaClearStack( L) ; + // eseguo scalatura + bool bOk = ExeShearGroup( nId, ptOn, vtN, vtDir, dCoeff) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGeoTransform( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtMove", LuaMove) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRotate", LuaRotate) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtScale", LuaScale) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtMirror", LuaMirror) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtShear", LuaShear) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtMoveGroup", LuaMoveGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRotateGroup", LuaRotateGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtScaleGroup", LuaScaleGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtMirrorGroup", LuaMirrorGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtShearGroup", LuaShearGroup) ; + return bOk ; +} diff --git a/LUA_GeomDB.cpp b/LUA_GeomDB.cpp new file mode 100644 index 0000000..fd7212c --- /dev/null +++ b/LUA_GeomDB.cpp @@ -0,0 +1,186 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_General.cpp Data : 27.09.14 Versione : 1.5i5 +// Contenuto : Funzioni generali per LUA. +// +// +// +// Modifiche : 27.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" + +using namespace std ; + + +//------------------------------------------------------------------------------- +static int +LuaSetDefaultMaterial( lua_State* L) +{ + // un solo parametro, il colore + Color colDef ; + if ( ! LuaGetParam( L, 1, colDef)) + return luaL_error( L, "Invalide first parameter") ; + LuaClearStack( L) ; + // imposto il colore di default + int vCol[4] ; + colDef.GetInt( vCol) ; + bool bOk = ( ExeSetDefaultMaterial( vCol) != FALSE) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetGridFrame( lua_State* L) +{ + // 1 parametro : Frame + Frame3d frFrame ; + LuaCheckParam( L, 1, frFrame) ; + LuaClearStack( L) ; + // imposto il riferimento della Griglia (o CPlane) + bool bOk = ( ExeSetGridFrame( frFrame)) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetGridFrame( lua_State* L) +{ + // 1 o nessun parametro : [nRefId] + int nRefId = GDB_ID_ROOT ; + if ( lua_gettop( L) >= 1) + LuaCheckParam( L, 1, nRefId) + LuaClearStack( L) ; + // recupero il riferimento della griglia + Frame3d frFrame ; + ExeGetGridFrame( nRefId, frFrame) ; + // restituisco il risultato + LuaSetReturn( L, frFrame) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetGridVersZ( lua_State* L) +{ + // 1 o nessun parametro : [nRefId] + int nRefId = GDB_ID_ROOT ; + if ( lua_gettop( L) >= 1) + LuaCheckParam( L, 1, nRefId) + LuaClearStack( L) ; + // recupero il versore Z della griglia e lo restituisco + Vector3d vtVersZ ; + if ( ExeGetGridVersZ( nRefId, vtVersZ)) + LuaSetReturn( L, vtVersZ) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaNewFile( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // nuovo progetto + bool bOk = ExeNewFile() ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaOpenFile( lua_State* L) +{ + // 1 parametro : path del file da aprire + string sFilePath ; + LuaCheckParam( L, 1, sFilePath) + LuaClearStack( L) ; + // apro il file + bool bOk = ExeOpenFile( sFilePath) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaInsertFile( lua_State* L) +{ + // 1 parametro : path del file da importare + string sFilePath ; + LuaCheckParam( L, 1, sFilePath) + LuaClearStack( L) ; + // apro il file + bool bOk = ExeInsertFile( sFilePath) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSaveFile( lua_State* L) +{ + // 1 o 2 parametri : path del file [, flag] + string sFilePath ; + LuaCheckParam( L, 1, sFilePath) + int nFlag = GDB_SV_CMPTXT ; + LuaGetParam( L, 2, nFlag) ; + LuaClearStack( L) ; + // salvo il file + bool bOk = ExeSaveFile( sFilePath, nFlag) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSaveObjToFile( lua_State* L) +{ + // 2 o 3 parametri : nId, path del file [, flag] + int nId ; + LuaCheckParam( L, 1, nId) + string sFilePath ; + LuaCheckParam( L, 2, sFilePath) + int nFlag = GDB_SV_CMPTXT ; + LuaGetParam( L, 3, nFlag) ; + LuaClearStack( L) ; + // copio il gruppo nel file + bool bOk = ExeSaveObjToFile( nId, sFilePath, nFlag) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallGeomDB( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetDefaultMaterial", LuaSetDefaultMaterial) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetGridFrame", LuaSetGridFrame) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetGridFrame", LuaGetGridFrame) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetGridVersZ", LuaGetGridVersZ) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtNewFile", LuaNewFile) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtOpenFile", LuaOpenFile) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtInsertFile", LuaInsertFile) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSaveFile", LuaSaveFile) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSaveObjToFile", LuaSaveObjToFile) ; + return bOk ; +} diff --git a/LUA_MachMgr.cpp b/LUA_MachMgr.cpp new file mode 100644 index 0000000..8a20222 --- /dev/null +++ b/LUA_MachMgr.cpp @@ -0,0 +1,541 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : LUA_MachMgr.cpp Data : 24.03.15 Versione : 1.6c8 +// Contenuto : Funzioni Machining Manager per LUA. +// +// +// +// Modifiche : 24.03.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static int +LuaGetMachGroupNbr( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // recupero il numero di macchinate + int nTot = ExeGetMachGroupNbr() ; + // restituisco il risultato + LuaSetReturn( L, nTot) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetFirstMachGroup( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // recupero l'identificativo della prima macchinata + int nId = ExeGetFirstMachGroup() ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetNextMachGroup( lua_State* L) +{ + // 1 parametro : identificativo di una macchinata + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // recupero l'identificativo della successiva macchinata + int nNextId = ExeGetNextMachGroup( nId) ; + // restituisco il risultato + if ( nNextId != GDB_ID_NULL) + LuaSetReturn( L, nNextId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaAddMachGroup( lua_State* L) +{ + // 2 parametri : nome del gruppo, nome della macchina da utilizzare + string sName ; + LuaCheckParam( L, 1, sName) + string sMachineName ; + LuaCheckParam( L, 2, sMachineName) + LuaClearStack( L) ; + // aggiungo la macchinata + int nId = ExeAddMachGroup( sName, sMachineName) ; + // restituisco il risultato + LuaSetReturn( L, nId) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRemoveMachGroup( lua_State* L) +{ + // 1 parametro : identificativo del gruppo + int nMGroupInd ; + LuaCheckParam( L, 1, nMGroupInd) + LuaClearStack( L) ; + // rimuovo la macchinata + bool bOk = ExeRemoveMachGroup( nMGroupInd) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetMachGroupName( lua_State* L) +{ + // 1 parametro : identificativo del gruppo + int nMGroupInd ; + LuaCheckParam( L, 1, nMGroupInd) + LuaClearStack( L) ; + // recupero il nome della macchinata + string sName ; + bool bOk = ExeGetMachGroupName( nMGroupInd, sName) ; + // restituisco il risultato + if ( bOk) + LuaSetReturn( L, sName) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetMachGroupId( lua_State* L) +{ + // 1 parametro : nome del gruppo + string sGroupName ; + LuaCheckParam( L, 1, sGroupName) + LuaClearStack( L) ; + // recupero l'identificativo della macchinata + int nId = ExeGetMachGroupId( sGroupName) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetCurrMachGroup( lua_State* L) +{ + // 1 parametro : identificativo del gruppo + int nMGroupInd ; + LuaCheckParam( L, 1, nMGroupInd) + LuaClearStack( L) ; + // imposto il gruppo corrente + bool bOk = ExeSetCurrMachGroup( nMGroupInd) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaResetCurrMachGroup( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // imposto il gruppo corrente + bool bOk = ExeResetCurrMachGroup() ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetCurrMachGroup( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // recupero l'identificativo del gruppo corrente + int nId = ExeGetCurrMachGroup() ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetRawPartNbr( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // recupero il numero di grezzi nella macchinata corrente + int nCount = ExeGetRawPartNbr() ; + // restituisco il risultato + LuaSetReturn( L, nCount) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetFirstRawPart( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // recupero identificativo primo grezzo nella macchinata corrente + int nId = ExeGetFirstRawPart() ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetNextRawPart( lua_State* L) +{ + // 1 parametro : nRawId + int nRawId ; + LuaCheckParam( L, 1, nRawId) + LuaClearStack( L) ; + // recupero identificativo successivo grezzo nella macchinata corrente + int nId = ExeGetNextRawPart( nRawId) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} +//------------------------------------------------------------------------------- +static int +LuaAddRawPart( lua_State* L) +{ + // 5 parametri : Pto origine, dWidth, dLen, dH, Color + Point3d ptOrig ; + LuaCheckParam( L, 1, ptOrig) + double dWidth ; + LuaCheckParam( L, 2, dWidth) + double dLength ; + LuaCheckParam( L, 3, dLength) + double dHeight ; + LuaCheckParam( L, 4, dHeight) + Color cCol ; + LuaCheckParam( L, 5, cCol) + LuaClearStack( L) ; + // inserisco il grezzo nella macchinata corrente + int nInd = ExeAddRawPart( ptOrig, dWidth, dLength, dHeight, cCol) ; + // restituisco il risultato + if ( nInd != GDB_ID_NULL) + LuaSetReturn( L, nInd) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaAddRawPartWithPart( lua_State* L) +{ + // 4 parametri : nPartId, nCrvId, dOverMat, Color + int nPartId ; + LuaCheckParam( L, 1, nPartId) + int nCrvId = GDB_ID_NULL ; + LuaGetParam( L, 2, nCrvId) ; + double dOverMat ; + LuaCheckParam( L, 3, dOverMat) + Color cCol ; + LuaCheckParam( L, 4, cCol) + LuaClearStack( L) ; + // inserisco il grezzo nella macchinata corrente + int nInd = ExeAddRawPartWithPart( nPartId, nCrvId, dOverMat, cCol) ; + // restituisco il risultato + if ( nInd != GDB_ID_NULL) + LuaSetReturn( L, nInd) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaModifyRawPartHeight( lua_State* L) +{ + // 2 parametri : nRawId, dHeight + int nRawId ; + LuaCheckParam( L, 1, nRawId) + double dHeight ; + LuaCheckParam( L, 2, dHeight) + LuaClearStack( L) ; + // modifico lo spessore del grezzo + bool bOk = ExeModifyRawPartHeight( nRawId, dHeight) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRemoveRawPart( lua_State* L) +{ + // 1 parametro : nRawId + int nRawId ; + LuaCheckParam( L, 1, nRawId) + LuaClearStack( L) ; + // elimino il grezzo dalla macchinata corrente + bool bOk = ExeRemoveRawPart( nRawId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaTranslateRawPart( lua_State* L) +{ + // 2 parametri : nRawId, vtMove + int nRawId ; + LuaCheckParam( L, 1, nRawId) + Vector3d vtMove ; + LuaCheckParam( L, 2, vtMove) + LuaClearStack( L) ; + // traslo il grezzo + bool bOk = ExeTranslateRawPart( nRawId, vtMove) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRotateRawPart( lua_State* L) +{ + // 3 parametri : nRawId, vtAx, dAngRotDeg + int nRawId ; + LuaCheckParam( L, 1, nRawId) + Vector3d vtAx ; + LuaCheckParam( L, 2, vtAx) + double dAngRotDeg ; + LuaCheckParam( L, 3, dAngRotDeg) + LuaClearStack( L) ; + // ruoto il grezzo + bool bOk = ExeRotateRawPart( nRawId, vtAx, dAngRotDeg) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaMoveToCornerRawPart( lua_State* L) +{ + // 3 parametri : nRawId, ptCorner, nFlag + int nRawId ; + LuaCheckParam( L, 1, nRawId) + Point3d ptCorner ; + LuaCheckParam( L, 2, ptCorner) + int nFlag ; + LuaCheckParam( L, 3, nFlag) + LuaClearStack( L) ; + // sposto il grezzo nel corner + bool bOk = ExeMoveToCornerRawPart( nRawId, ptCorner, nFlag) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaMoveToCenterRawPart( lua_State* L) +{ + // 3 parametri : nRawId, ptCenter, nFlag + int nRawId ; + LuaCheckParam( L, 1, nRawId) + Point3d ptCenter ; + LuaCheckParam( L, 2, ptCenter) + int nFlag ; + LuaCheckParam( L, 3, nFlag) + LuaClearStack( L) ; + // sposto il grezzo nel corner + bool bOk = ExeMoveToCenterRawPart( nRawId, ptCenter, nFlag) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetPartInRawPartNbr( lua_State* L) +{ + // 1 parametro : nRawId + int nRawId ; + LuaCheckParam( L, 1, nRawId) + LuaClearStack( L) ; + // recupero il numero di pezzi nel grezzo + int nCount = ExeGetPartInRawPartNbr( nRawId) ; + // restituisco il risultato + LuaSetReturn( L, nCount) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetFirstPartInRawPart( lua_State* L) +{ + // 1 parametro : nRawId + int nRawId ; + LuaCheckParam( L, 1, nRawId) + LuaClearStack( L) ; + // recupero identificativo primo pezzo nel grezzo + int nId = ExeGetFirstPartInRawPart( nRawId) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetNextPartInRawPart( lua_State* L) +{ + // 1 parametro : nPartId + int nPartId ; + LuaCheckParam( L, 1, nPartId) + LuaClearStack( L) ; + // recupero identificativo successivo pezzo nello stesso grezzo + int nId = ExeGetNextPartInRawPart( nPartId) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetReturn( L, nId) ; + else + LuaSetReturn( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaAddPartToRawPart( lua_State* L) +{ + // 3 parametri : nPartId, ptPos, nRawId + int nPartId ; + LuaCheckParam( L, 1, nPartId) + Point3d ptPos ; + LuaCheckParam( L, 2, ptPos) + int nRawId ; + LuaCheckParam( L, 3, nRawId) + LuaClearStack( L) ; + // inserisco il grezzo nella macchinata corrente + bool bOk = ExeAddPartToRawPart( nPartId, ptPos, nRawId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRemovePartFromRawPart( lua_State* L) +{ + // 1 parametro : nPartId + int nPartId ; + LuaCheckParam( L, 1, nPartId) + LuaClearStack( L) ; + // elimino il grezzo dalla macchinata corrente + bool bOk = ExeRemovePartFromRawPart( nPartId) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaTranslatePartInRawPart( lua_State* L) +{ + // 2 parametri : nPartId, vtMove + int nPartId ; + LuaCheckParam( L, 1, nPartId) + Vector3d vtMove ; + LuaCheckParam( L, 2, vtMove) + LuaClearStack( L) ; + // traslo il pezzo nel grezzo + bool bOk = ExeTranslatePartInRawPart( nPartId, vtMove) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaRotatePartInRawPart( lua_State* L) +{ + // 3 parametri : nPartId, vtAx, dAngRotDeg + int nPartId ; + LuaCheckParam( L, 1, nPartId) + Vector3d vtAx ; + LuaCheckParam( L, 2, vtAx) + double dAngRotDeg ; + LuaCheckParam( L, 3, dAngRotDeg) + LuaClearStack( L) ; + // ruoto il pezzo nel grezzo + bool bOk = ExeRotatePartInRawPart( nPartId, vtAx, dAngRotDeg) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallMachMgr( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetMachGroupNbr", LuaGetMachGroupNbr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstMachGroup", LuaGetFirstMachGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetNextMachGroup", LuaGetNextMachGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtAddMachGroup", LuaAddMachGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRemoveMachGroup", LuaRemoveMachGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetMachGroupName", LuaGetMachGroupName) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetMachGroupId", LuaGetMachGroupId) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetCurrMachGroup", LuaSetCurrMachGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtResetCurrMachGroup", LuaResetCurrMachGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetCurrMachGroup", LuaGetCurrMachGroup) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetRawPartNbr", LuaGetRawPartNbr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstRawPart", LuaGetFirstRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetNextRawPart", LuaGetNextRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtAddRawPart", LuaAddRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtAddRawPartWithPart", LuaAddRawPartWithPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtModifyRawPartHeight", LuaModifyRawPartHeight) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRemoveRawPart", LuaRemoveRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtMoveRawPart", LuaTranslateRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRotateRawPart", LuaRotateRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtMoveToCornerRawPart", LuaMoveToCornerRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtMoveToCenterRawPart", LuaMoveToCenterRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetPartInRawPartNbr", LuaGetPartInRawPartNbr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstPartInRawPart", LuaGetFirstPartInRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetNextPartInRawPart", LuaGetNextPartInRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtAddPartToRawPart", LuaAddPartToRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRemovePartFromRawPart", LuaRemovePartFromRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtMovePartInRawPart", LuaTranslatePartInRawPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtRotatePartInRawPart", LuaRotatePartInRawPart) ; + + return bOk ; +} diff --git a/LUA_Scene.cpp b/LUA_Scene.cpp new file mode 100644 index 0000000..9761bac --- /dev/null +++ b/LUA_Scene.cpp @@ -0,0 +1,190 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : LUA_Scene.cpp Data : 29.09.14 Versione : 1.5i5 +// Contenuto : Funzioni di visualizzazione per LUA. +// +// +// +// Modifiche : 29.09.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkLuaAux.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static int +LuaSetBackground( lua_State* L) +{ + // 2 o 3 parametri : colore top, colore bottom [, flag ridisegna] + Color colTop ; + LuaCheckParam( L, 1, colTop) + Color colBot ; + LuaCheckParam( L, 2, colBot) + bool bRedraw ; + LuaGetParam( L, 3, bRedraw) ; + LuaClearStack( L) ; + // imposto lo sfondo + bool bOk = ExeSetBackground( colTop, colBot, bRedraw) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaDraw( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // eseguo ridisegno + bool bOk = ExeDraw() ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetShowMode( lua_State* L) +{ + // 1 o 2 parametri : nShowMode [, flag ridisegna] + int nShowMode ; + LuaCheckParam( L, 1, nShowMode) + bool bRedraw = true ; + LuaGetParam( L, 2, bRedraw) ; + LuaClearStack( L) ; + // imposto il modo di visualizzazione + bool bOk = ExeSetShowMode( nShowMode, bRedraw) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetShowCurveDirection( lua_State* L) +{ + // 1 o 2 parametri : bool bShowCrvDir [, flag ridisegna] + bool bShowCrvDir ; + LuaCheckParam( L, 1, bShowCrvDir) + bool bRedraw = true ; + LuaGetParam( L, 2, bRedraw) ; + LuaClearStack( L) ; + // imposto visualizzazione direzione curve + bool bOk = ExeSetShowCurveDirection( bShowCrvDir, bRedraw) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetShowTriaAdv( lua_State* L) +{ + // 1 o 2 parametri : flag bAdvanced [, flag ridisegna] + bool bAdvanced ; + LuaCheckParam( L, 1, bAdvanced) + bool bRedraw = true ; + LuaGetParam( L, 2, bRedraw) , + LuaClearStack( L) ; + // imposto visualizzazione direzione curve + bool bOk = ExeSetShowTriaAdv( bAdvanced, bRedraw) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaZoom( lua_State* L) +{ + // 1 o 2 parametri : nZoomType [, flag ridisegna] + int nZoomType ; + LuaCheckParam( L, 1, nZoomType) + bool bRedraw = true ; + LuaGetParam( L, 2, bRedraw) ; + LuaClearStack( L) ; + // imposto zoom + bool bOk = ExeZoom( nZoomType, bRedraw) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetView( lua_State* L) +{ + // 1 o 2 parametri : nViewDir [, flag ridisegna] + int nViewDir ; + LuaCheckParam( L, 1, nViewDir) + bool bRedraw = true ; + LuaGetParam( L, 2, bRedraw) ; + LuaClearStack( L) ; + // imposto direzione di vista + bool bOk = ExeSetView( nViewDir, bRedraw) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetGenericView( lua_State* L) +{ + // 2 o 3 parametri : dAngVertDeg, dAngHorizDeg [, flag ridisegna] + double dAngVertDeg ; + LuaCheckParam( L, 1, dAngVertDeg) + double dAngHorizDeg ; + LuaCheckParam( L, 2, dAngHorizDeg) + bool bRedraw = true ; + LuaGetParam( L, 3, bRedraw) ; + LuaClearStack( L) ; + // imposto direzione di vista + bool bOk = ExeSetGenericView( dAngVertDeg, dAngHorizDeg, bRedraw) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaSetViewCenter( lua_State* L) +{ + // 1 o 2 parametri : ptCen [, flag ridisegna] + Point3d ptCen ; + LuaCheckParam( L, 1, ptCen) + bool bRedraw = true ; + LuaGetParam( L, 2, bRedraw) ; + LuaClearStack( L) ; + // imposto centro di vista + bool bOk = ExeSetViewCenter( ptCen, bRedraw) ; + // restituisco il risultato + LuaSetReturn( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallScene( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetBackground", LuaSetBackground) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtDraw", LuaDraw) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetShowMode", LuaSetShowMode) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetShowCurveDirection", LuaSetShowCurveDirection) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetShowTriaAdv", LuaSetShowTriaAdv) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtZoom", LuaZoom) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetView", LuaSetView) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetGenericView", LuaSetGenericView) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetViewCenter", LuaSetViewCenter) ; + return bOk ; +} diff --git a/resource.h b/resource.h new file mode 100644 index 0000000..313a352 Binary files /dev/null and b/resource.h differ diff --git a/stdafx.cpp b/stdafx.cpp new file mode 100644 index 0000000..ce28b0b --- /dev/null +++ b/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : file di origine che include solo le inclusioni standard +// EgtInterface.pch sarà l'intestazione precompilata +// stdafx.obj conterrà le informazioni sui tipi precompilati + +#include "stdafx.h" + +// TODO: fare riferimento alle intestazioni aggiuntive necessarie in STDAFX.H +// e non in questo file diff --git a/stdafx.h b/stdafx.h new file mode 100644 index 0000000..d41bf0c --- /dev/null +++ b/stdafx.h @@ -0,0 +1,34 @@ +// stdafx.h : file di inclusione per file di inclusione di sistema standard +// o file di inclusione specifici del progetto utilizzati di frequente, ma +// modificati raramente +// + +#pragma once + +#include "/EgtDev/Include/EgtTargetVer.h" + +#include +#include +#include +#include + +// in Debug riconoscimento memory leakage +#if defined( _DEBUG) + #define _CRTDBG_MAP_ALLOC + #include + #include +#endif + +// in Debug controllo iteratori +#if defined( _DEBUG) + #define _SECURE_SCL 1 +#else + #define _SECURE_SCL 0 +#endif + +#include "/EgtDev/Include/EgtLibVer.h" + +#pragma comment(lib, EGTLIBDIR "EgtGeneral" EGTLIBVER ".lib") +#pragma comment(lib, EGTLIBDIR "EgtNumKernel" EGTLIBVER ".lib") +#pragma comment(lib, EGTLIBDIR "EgtGeomKernel" EGTLIBVER ".lib") +#pragma comment(lib, EGTEXTDIR "Lua/Lib/Lua52" EGTLIBVER ".lib")