b14c634bc3
- in creazione curve eliminata la normale (si deduce dal riferimento indicato) - in creazione gruppo di inserimento è layer corrente da costante - gestino carattere ' nelle stringhe per lua.
773 lines
34 KiB
C++
773 lines
34 KiB
C++
//----------------------------------------------------------------------------
|
|
// 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
// 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<ISurfTriMesh> 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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
// 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<ISurfTriMesh> 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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
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<ISurfTriMesh> 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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
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<ISurfTriMesh> 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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
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<ISurfTriMesh> 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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
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<ISurfTriMesh> 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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
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) ;
|
|
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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
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, 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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
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, 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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
// 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<ISurfTriMesh> 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(" + IdToString( 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)
|
|
nParentId = AdjustId( nParentId) ;
|
|
// 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<ISurfTriMesh> 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(" + IdToString( nParentId) + ",{" +
|
|
IdListToString( vIds) + "}," +
|
|
( bErase ? "true" : "false") + ")" +
|
|
" -- Id=" + ToString( nNewId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco il risultato
|
|
return nNewId ;
|
|
}
|