Files
EgtInterface/API_GdbCreateSurf.cpp
T
Dario Sassi 1e24540dc1 EgtInterface 1.6b2 :
- razionalizzazione
- modificati comandi per creazione superfici per gestione piani di regioni con buchi
- aggiunta SplitCurve.
2015-02-11 11:46:14 +00:00

353 lines
15 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : API_GdbCreateSurf.cpp Data : 02.11.14 Versione : 1.5j7
// Contenuto : Funzioni di creazione superfici del DB geometrico per API.
//
//
//
// Modifiche : 02.11.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "API.h"
#include "API_Macro.h"
#include "AuxTools.h"
#include "GeoTools.h"
#include "/EgtDev/Include/EInAPI.h"
#include "/EgtDev/Include/EInConst.h"
#include "/EgtDev/Include/EGkStmFromCurves.h"
#include "/EgtDev/Include/EgkStringUtils3d.h"
#include "/EgtDev/Include/EgkCurveLocal.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
using namespace std ;
//-------------------------------------------------------------------------------
int
__stdcall EgtCreateSurfTriMeshByFlatContour( 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) ;
EgtSetModified() ;
// 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
__stdcall EgtCreateSurfTriMeshByRegion( int nParentId, int nNumId, const int nCrvIds[], double dLinTol)
{
INTVECTOR vCrvIds ;
vCrvIds.reserve( nNumId) ;
for ( int i = 0 ; i < nNumId ; ++i) {
vCrvIds.push_back( nCrvIds[i]) ;
}
return EgtCreateSurfTriMeshByRegion( nParentId, vCrvIds, dLinTol) ;
}
//-------------------------------------------------------------------------------
int
EgtCreateSurfTriMeshByRegion( 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<ICurve*>( 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) ;
EgtSetModified() ;
// 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
__stdcall EgtCreateSurfTriMeshByExtrusion( int nParentId, int nNumId, const int nCrvIds[],
const double vtExtr[3], double dLinTol, int nRefType)
{
INTVECTOR vCrvIds ;
vCrvIds.reserve( nNumId) ;
for ( int i = 0 ; i < nNumId ; ++i) {
vCrvIds.push_back( nCrvIds[i]) ;
}
return EgtCreateSurfTriMeshByExtrusion( nParentId, vCrvIds, vtExtr, dLinTol, nRefType) ;
}
//-------------------------------------------------------------------------------
int
EgtCreateSurfTriMeshByExtrusion( 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<ICurve*>( vCrvLoc[i].Get())) ;
bOk = bOk && ( vCrvLoc[i].Get() != nullptr) ;
}
// porto in locale il vettore estrusione
Vector3d vtExtrL = GetVectorLocal( pGeomDB, vtExtr.v, 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 ;
}
EgtSetModified() ;
// 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( Vector3d( vtExtr)) + "}," +
ToString( dLinTol) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nFirstId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nFirstId ;
}
//-------------------------------------------------------------------------------
int
__stdcall EgtCreateSurfTriMeshByRegionExtrusion( int nParentId, int nNumId, const int nCrvIds[],
const double vtExtr[3], double dLinTol, int nRefType)
{
INTVECTOR vCrvIds ;
vCrvIds.reserve( nNumId) ;
for ( int i = 0 ; i < nNumId ; ++i) {
vCrvIds.push_back( nCrvIds[i]) ;
}
return EgtCreateSurfTriMeshByRegionExtrusion( nParentId, vCrvIds, vtExtr, dLinTol, nRefType) ;
}
//-------------------------------------------------------------------------------
int
EgtCreateSurfTriMeshByRegionExtrusion( 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<ICurve*>( vCrvLoc[i].Get())) ;
bOk = bOk && ( vCrvLoc[i].Get() != nullptr) ;
}
// porto in locale il vettore estrusione
Vector3d vtExtrL = GetVectorLocal( pGeomDB, vtExtr.v, 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) ;
EgtSetModified() ;
// 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( Vector3d( vtExtr)) + "}," +
ToString( dLinTol) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nNewId ;
}
//-------------------------------------------------------------------------------
int
__stdcall EgtCreateSurfTriMeshByRevolve( int nParentId, int nCrvId,
const double ptAx[3], const double vtAx[3],
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 != FALSE), dLinTol) : nullptr) ;
// inserisco la superficie nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSTM) : GDB_ID_NULL) ;
EgtSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfTmByRevolve(" + ToString( nParentId) + "," +
ToString( nCrvId) + ",{" +
ToString( Point3d( ptAx)) + "},{" +
ToString( Vector3d( 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
__stdcall EgtCreateSurfTriMeshByScrewing( int nParentId, int nCrvId,
const double ptAx[3], const double vtAx[3],
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) ;
EgtSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfTmByScrewing(" + ToString( nParentId) + "," +
ToString( nCrvId) + ",{" +
ToString( Point3d( ptAx)) + "},{" +
ToString( Vector3d( 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
__stdcall EgtCreateSurfTriMeshRuled( int nParentId, int nCrvId1, int nCrvId2, 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 prima curva in locale
CurveLocal CrvLoc1( pGeomDB, nCrvId1, frLoc) ;
bOk = bOk && ( CrvLoc1.Get() != nullptr) ;
// recupero la seconda curva in locale
CurveLocal CrvLoc2( pGeomDB, nCrvId2, frLoc) ;
bOk = bOk && ( CrvLoc2.Get() != nullptr) ;
// calcolo la superficie
ISurfTriMesh* pSTM = ( bOk ? GetSurfTriMeshRuled( CrvLoc1.Get(), CrvLoc2.Get(), dLinTol) : nullptr) ;
// inserisco la superficie trimesh nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, pSTM) : GDB_ID_NULL) ;
EgtSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSurfTmRuled(" + ToString( nParentId) + "," +
ToString( nCrvId1) + "," +
ToString( nCrvId2) + "," +
ToString( dLinTol) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nNewId ;
}