0c41c8c631
- aggiunta gestione nome file di progetto e suo stato - aggiunta gestione pezzo e layer - riordino generale.
1887 lines
74 KiB
C++
1887 lines
74 KiB
C++
//----------------------------------------------------------------------------
|
|
// 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 "API.h"
|
|
#include "API_Macro.h"
|
|
#include "AuxTools.h"
|
|
#include "/EgtDev/Include/EInAPI.h"
|
|
#include "/EgtDev/Include/EInConst.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/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/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 bool SetExtrusionFromGridVersZ( IGeomDB* pGeomDB, int nParentId, ICurve* pCurve) ;
|
|
static Vector3d CalcExtrusion( IGeomDB* pGeomDB, int nParentId, int nRefType) ;
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveLine( int nParentId, const double ptIni[3], const double ptFin[3], int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo la linea
|
|
PtrOwner<ICurveLine> pCrvLine( CreateCurveLine()) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti e il versore estrusione
|
|
Point3d ptIniL( ptIni) ;
|
|
Point3d ptFinL( ptFin) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptIniL.ToLoc( frLoc) ;
|
|
ptFinL.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else /* RTY_GRID */ {
|
|
ptIniL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptFinL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), 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)) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtLine(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptIni)) + "},{" +
|
|
ToString( Point3d( ptFin)) + "}," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveLineEx( int nParentId, const double ptIni[3], int nSepI, int nIdI,
|
|
const double ptFin[3], int nSepF, int nIdF, int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// puntatore alla linea
|
|
PtrOwner<ICurveLine> pCrvLine ;
|
|
// porto in locale i punti e il versore estrusione
|
|
Point3d ptIniL( ptIni) ;
|
|
Point3d ptFinL( ptFin) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptIniL.ToLoc( frLoc) ;
|
|
ptFinL.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else /* RTY_GRID */ {
|
|
ptIniL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptFinL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
}
|
|
}
|
|
// 1 - se punti entrambi definiti
|
|
if ( nSepI == SEP_STD && nSepF == SEP_STD) {
|
|
pCrvLine.Set( CreateCurveLine()) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
if ( ! pCrvLine->Set( ptIniL, ptFinL))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// 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)) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// 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)) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
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)) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// 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)) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
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)) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// 7 - se primo punto definito e secondo perpendicolare
|
|
else if ( nSepI == SEP_STD && nSepF == SEP_PERP) {
|
|
pCrvLine.Set( CreateLinePointPerpCurve( pGeomDB, nParentId, ptIniL, ptFinL, nIdF)) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// 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)) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
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)) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// 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)) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// 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)) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
pCrvLine->Invert() ;
|
|
}
|
|
// errore
|
|
else {
|
|
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)) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua ;
|
|
if ( nSepI == SEP_STD && nSepF == SEP_STD)
|
|
sLua = "EgtLine(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptIni)) + "},{" +
|
|
ToString( Point3d( ptFin)) + "}," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
else
|
|
sLua = "EgtLineEx(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptIni)) + "}," +
|
|
SepToString( nSepI) + "," +
|
|
ToString( nIdI) + ",{" +
|
|
ToString( Point3d( 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<ICurveLine> 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<ICurveLine> 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<ICurveLine> 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<ICurve> 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<ICurveLine> 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<ICurve> 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<ICurveLine> 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<ICurve> 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<ICurveLine> 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
|
|
__stdcall EgtCreateCurveLinePVL( int nParentId, const double ptIni[3],
|
|
const double vtDir[3], double dLen, int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// porto in locale i punti e il versore estrusione
|
|
Point3d ptIniL( ptIni) ;
|
|
Vector3d vtDirL( vtDir) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptIniL.ToLoc( frLoc) ;
|
|
vtDirL.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else /* RTY_GRID */ {
|
|
ptIniL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtDirL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
}
|
|
}
|
|
// creo la linea
|
|
PtrOwner<ICurveLine> 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)) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtLinePVL(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptIni)) + "},{" +
|
|
ToString( Vector3d( vtDir)) + "}," +
|
|
ToString( dLen) + "," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveLineMinPointCurve( int nParentId,
|
|
const double ptStart[3], int nCrvId, double dNearPar, int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il riferimento del gruppo destinazione
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale il punto e il versore estrusione
|
|
Point3d ptStartL( ptStart) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptStartL.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else if ( nRefType == RTY_GRID) {
|
|
ptStartL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), 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<ICurveLine> 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)) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtLineMinPointCurve(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( 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
|
|
__stdcall EgtCreateCurveCircle( int nParentId, const double ptCen[3],
|
|
const double vtN[3], double dRad, int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale il centro, la normale e il versore estrusione
|
|
Point3d ptCenL( ptCen) ;
|
|
Vector3d vtNL( vtN) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptCenL.ToLoc( frLoc) ;
|
|
vtNL.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else /* RTY_GRID */ {
|
|
ptCenL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtNL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), 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)) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtCircle(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptCen)) + "},{" +
|
|
ToString( Vector3d( vtN)) + "}," +
|
|
ToString( dRad) + "," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCircleCPN( int nParentId, const double ptCen[3],
|
|
const double ptOn[3], const double vtN[3], int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti, i versori e il versore estrusione
|
|
Point3d ptCenL( ptCen) ;
|
|
Point3d ptOnL( ptOn) ;
|
|
Vector3d vtNL( vtN) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptCenL.ToLoc( frLoc) ;
|
|
ptOnL.ToLoc( frLoc) ;
|
|
vtNL.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else /* RTY_GRID */ {
|
|
ptCenL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptOnL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtNL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
}
|
|
}
|
|
// calcolo il raggio
|
|
double dRad = (( ptOnL - ptCenL) ^ vtNL).Len() ;
|
|
// 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)) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtCircleCPN(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptCen)) + "},{" +
|
|
ToString( Point3d( ptOn)) + "},{" +
|
|
ToString( Vector3d( vtN)) + "}," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCircle3P( int nParentId, const double ptP1[3],
|
|
const double ptP2[3], const double ptP3[3], int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti e il versore estrusione
|
|
Point3d ptP1L( ptP1) ;
|
|
Point3d ptP2L( ptP2) ;
|
|
Point3d ptP3L( ptP3) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptP1L.ToLoc( frLoc) ;
|
|
ptP2L.ToLoc( frLoc) ;
|
|
ptP3L.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else /* RTY_GRID */ {
|
|
ptP1L.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptP2L.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptP3L.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), 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)) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtCircle3P(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptP1)) + "},{" +
|
|
ToString( Point3d( ptP2)) + "},{" +
|
|
ToString( Point3d( ptP3)) + "}," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveArc( int nParentId,
|
|
const double ptCen[3], const double vtN[3], double dRad,
|
|
const double vtS[3], double dAngCenDeg, double dDeltaN, int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti, i versori e il versore estrusione
|
|
Point3d ptCenL( ptCen) ;
|
|
Vector3d vtNL( vtN) ;
|
|
Vector3d vtSL( vtS) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptCenL.ToLoc( frLoc) ;
|
|
vtNL.ToLoc( frLoc) ;
|
|
vtSL.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else /* RTY_GRID */ {
|
|
ptCenL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtNL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtSL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), 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)) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtArc(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptCen)) + "},{" +
|
|
ToString( Vector3d( vtN)) + "}," +
|
|
ToString( dRad) + ",{" +
|
|
ToString( Vector3d( 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
|
|
__stdcall EgtCreateCurveArcC2PN( int nParentId, const double ptCen[3], const double ptStart[3],
|
|
const double ptNearEnd[3], const double vtNorm[3], int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti, i versori e il versore estrusione
|
|
Point3d ptCenL( ptCen) ;
|
|
Point3d ptStartL( ptStart) ;
|
|
Point3d ptNearEndL( ptNearEnd) ;
|
|
Vector3d vtNormL( vtNorm) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptCenL.ToLoc( frLoc) ;
|
|
ptStartL.ToLoc( frLoc) ;
|
|
ptNearEndL.ToLoc( frLoc) ;
|
|
vtNormL.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else /* RTY_GRID */ {
|
|
ptCenL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptStartL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptNearEndL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtNormL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), 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)) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtArcC2PN(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptCen)) + "},{" +
|
|
ToString( Point3d( ptStart)) + "},{" +
|
|
ToString( Point3d( ptNearEnd)) + "},{" +
|
|
ToString( Vector3d( vtNorm)) + "}," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveArc3P( int nParentId, const double ptP1[3],
|
|
const double ptP2[3], const double ptP3[3], int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti e il versore estrusione
|
|
Point3d ptP1L( ptP1) ;
|
|
Point3d ptP2L( ptP2) ;
|
|
Point3d ptP3L( ptP3) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptP1L.ToLoc( frLoc) ;
|
|
ptP2L.ToLoc( frLoc) ;
|
|
ptP3L.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else /* RTY_GRID */ {
|
|
ptP1L.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptP2L.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptP3L.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
}
|
|
}
|
|
int nId = GDB_ID_NULL ;
|
|
// setto l'arco
|
|
if ( pCrvArc->Set3P( ptP1L, ptP2L, ptP3L, false)) {
|
|
// assegno il versore estrusione
|
|
pCrvArc->SetExtrusion( vtExtrL) ;
|
|
// inserisco l'arco nel DB
|
|
nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
|
|
}
|
|
// se risulta essere una retta
|
|
else if ( ( ptP2L - ptP1L) * ( ptP3L - ptP2L) > EPS_ZERO) {
|
|
// creo e setto la retta
|
|
PtrOwner<ICurveLine> pCrvLine( CreateCurveLine()) ;
|
|
if ( ! IsNull( pCrvLine) && pCrvLine->Set( ptP1L, ptP3L)) {
|
|
// assegno il versore estrusione
|
|
pCrvLine->SetExtrusion( vtExtrL) ;
|
|
// inserisco la retta nel DB
|
|
nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvLine)) ;
|
|
}
|
|
}
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtArc3P(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptP1)) + "},{" +
|
|
ToString( Point3d( ptP2)) + "},{" +
|
|
ToString( Point3d( ptP3)) + "}," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveArc2PVN( int nParentId, const double ptStart[3], const double ptEnd[3],
|
|
const double vtDirS[3], const double vtNorm[3], int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti, i versori e il versore estrusione
|
|
Point3d ptStartL( ptStart) ;
|
|
Point3d ptEndL( ptEnd) ;
|
|
Vector3d vtDirSL( vtDirS) ;
|
|
Vector3d vtNormL( vtNorm) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptStartL.ToLoc( frLoc) ;
|
|
ptEndL.ToLoc( frLoc) ;
|
|
vtDirSL.ToLoc( frLoc) ;
|
|
vtNormL.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else /* RTY_GRID */ {
|
|
ptStartL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptEndL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtDirSL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtNormL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
}
|
|
}
|
|
int nId = GDB_ID_NULL ;
|
|
// setto l'arco
|
|
if ( pCrvArc->Set2PVN( ptStartL, ptEndL, vtDirSL, vtNormL)) {
|
|
// assegno il versore estrusione
|
|
pCrvArc->SetExtrusion( vtExtrL) ;
|
|
// inserisco l'arco nel DB
|
|
nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
|
|
}
|
|
// se risulta essere una retta
|
|
else if ( ( ptEndL - ptStartL) * vtDirSL > EPS_ZERO) {
|
|
// creo e setto la retta
|
|
PtrOwner<ICurveLine> pCrvLine( CreateCurveLine()) ;
|
|
if ( ! IsNull( pCrvLine) && pCrvLine->Set( ptStartL, ptEndL)) {
|
|
// assegno il versore estrusione
|
|
pCrvLine->SetExtrusion( vtExtrL) ;
|
|
// inserisco la retta nel DB
|
|
nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvLine)) ;
|
|
}
|
|
}
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtArc2PVN(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptStart)) + "},{" +
|
|
ToString( Point3d( ptEnd)) + "},{" +
|
|
ToString( Vector3d( vtDirS)) + "},{" +
|
|
ToString( Vector3d( vtNorm)) + "}," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveBezier( int nParentId, int nDegree, const double ptCtrls[], int nRefType)
|
|
{
|
|
PNTVECTOR vPnt ;
|
|
vPnt.reserve( nDegree + 1) ;
|
|
for ( int i = 0 ; i <= nDegree ; ++i) {
|
|
vPnt.push_back( Point3d( ptCtrls[3*i], ptCtrls[3*i+1], ptCtrls[3*i+2])) ;
|
|
}
|
|
return EgtCreateCurveBezier( nParentId, nDegree, vPnt, nRefType) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
EgtCreateCurveBezier( 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<ICurveBezier> 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 = vPnt[i] ;
|
|
if ( nRefType == RTY_GLOB)
|
|
ptCtrl.ToLoc( frLoc) ;
|
|
else if ( nRefType == RTY_GRID)
|
|
ptCtrl.LocToLoc( pGeomDB->GetGridFrame(), 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 = Z_AX ;
|
|
if ( nRefType == RTY_GLOB)
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
else if ( nRefType == RTY_GRID)
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
pCrvBez->SetExtrusion( vtExtrL) ;
|
|
// inserisco la curva nel DB
|
|
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvBez)) : GDB_ID_NULL) ;
|
|
EgtSetModified() ;
|
|
// 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
|
|
__stdcall EgtCreateCurveBezierRational( int nParentId, int nDegree, const double ptCtrlWs[], int nRefType)
|
|
{
|
|
PNTUVECTOR vPntW ;
|
|
vPntW.reserve( nDegree + 1) ;
|
|
for ( int i = 0 ; i <= nDegree ; ++i) {
|
|
vPntW.push_back( make_pair( Point3d( ptCtrlWs[4*i], ptCtrlWs[4*i+1], ptCtrlWs[4*i+2]), ptCtrlWs[4*i+3])) ;
|
|
}
|
|
return EgtCreateCurveBezierRational( nParentId, nDegree, vPntW, nRefType) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
EgtCreateCurveBezierRational( 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<ICurveBezier> 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 = vPntW[i].first ;
|
|
if ( nRefType == RTY_GLOB)
|
|
ptCtrl.ToLoc( frLoc) ;
|
|
else if ( nRefType == RTY_GRID)
|
|
ptCtrl.LocToLoc( pGeomDB->GetGridFrame(), 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 = Z_AX ;
|
|
if ( nRefType == RTY_GLOB)
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
else if ( nRefType == RTY_GRID)
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
pCrvBez->SetExtrusion( vtExtrL) ;
|
|
// inserisco la curva nel DB
|
|
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvBez)) : GDB_ID_NULL) ;
|
|
EgtSetModified() ;
|
|
// 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
|
|
__stdcall EgtCreateCurveBezierFromArc( int nParentId, int nArcId, BOOL bErase)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
bool bOk = true ;
|
|
// creo la curva di Bezier
|
|
PtrOwner<ICurveBezier> 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->ToGlob( frSou) ;
|
|
pCrvBez->ToLoc( 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 ;
|
|
}
|
|
}
|
|
EgtSetModified() ;
|
|
// 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
|
|
__stdcall EgtCreateCurveCompo( int nParentId, int nNumId, const int nIds[], BOOL bErase)
|
|
{
|
|
INTVECTOR vIds ;
|
|
vIds.reserve( nNumId) ;
|
|
for ( int i = 0 ; i < nNumId ; ++i) {
|
|
vIds.push_back( nIds[i]) ;
|
|
}
|
|
return EgtCreateCurveCompo( nParentId, vIds, ( bErase != FALSE)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
MyCreateCurveCompo( int nParentId, const INTVECTOR& vIds, bool bErase)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo la curva composita
|
|
PtrOwner<ICurveComposite> 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<ICurve> 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)) ;
|
|
EgtSetModified() ;
|
|
// 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
|
|
EgtCreateCurveCompo( int nParentId, const INTVECTOR& vIds, bool bErase)
|
|
{
|
|
// eseguo
|
|
int nId = MyCreateCurveCompo( nParentId, vIds, bErase) ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sIds ;
|
|
for ( size_t i = 0 ; i < vIds.size() ; ++ i) {
|
|
if ( i > 0)
|
|
sIds += "," ;
|
|
sIds += ToString( vIds[i]) ;
|
|
}
|
|
string sLua = "EgtCurveCompo(" + ToString( nParentId) + ",{" +
|
|
sIds + "}," +
|
|
( bErase ? "true" : "false") + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCompoByChain( int nParentId, int nNumId, const int nIds[],
|
|
const double ptNear[3], BOOL bErase, int nRefType)
|
|
{
|
|
INTVECTOR vIds ;
|
|
vIds.reserve( nNumId) ;
|
|
for ( int i = 0 ; i < nNumId ; ++i) {
|
|
vIds.push_back( nIds[i]) ;
|
|
}
|
|
return EgtCreateCurveCompoByChain( nParentId, vIds, ptNear, ( bErase != FALSE), nRefType) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
MyCreateCurveCompoByChain( int nParentId, const INTVECTOR& vIds,
|
|
const Point3d& ptNear, bool bErase, int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo la curva composita
|
|
PtrOwner<ICurveComposite> 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())) ;
|
|
INTVECTOR::const_iterator Iter ;
|
|
for ( Iter = vIds.begin() ; Iter != vIds.end() ; ++Iter) {
|
|
// recupero la curva e il suo riferimento
|
|
ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( *Iter)) ;
|
|
if ( pCrv == nullptr)
|
|
return GDB_ID_NULL ;
|
|
Frame3d frCrv ;
|
|
if ( ! pGeomDB->GetGlobFrame( *Iter, 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( *Iter, ptStart, vtStart, ptEnd, vtEnd))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// recupero i percorsi concatenati
|
|
int nFirstId = GDB_ID_NULL ;
|
|
Point3d ptNearL( ptNear) ;
|
|
if ( nRefType == RTY_GLOB)
|
|
ptNearL.ToLoc( frDest) ;
|
|
else if ( nRefType == RTY_GRID)
|
|
ptNearL.LocToLoc( pGeomDB->GetGridFrame(), frDest) ;
|
|
INTVECTOR vId2s ;
|
|
while ( chainC.GetChainFromNear( ptNearL, vId2s)) {
|
|
// creo una curva composita
|
|
PtrOwner<ICurveComposite> 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
|
|
INTVECTOR::iterator Iter ;
|
|
for ( Iter = vId2s.begin() ; Iter != vId2s.end() ; ++Iter) {
|
|
int nId = abs( *Iter) ;
|
|
bool bInvert = ( *Iter < 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<ICurve> 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 ;
|
|
}
|
|
// se richiesto, cancello le curve originali
|
|
if ( bErase) {
|
|
for ( Iter = vIds.begin() ; Iter != vIds.end() ; ++Iter) {
|
|
if ( ! pGeomDB->Erase( *Iter))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
}
|
|
// restituisco l'identificativo della prima nuova entità
|
|
return nFirstId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
EgtCreateCurveCompoByChain( int nParentId, const INTVECTOR& vIds,
|
|
const Point3d& ptNear, bool bErase, int nRefType)
|
|
{
|
|
// eseguo
|
|
int nFirstId = MyCreateCurveCompoByChain( nParentId, vIds, ptNear, bErase, nRefType) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sIds ;
|
|
for ( size_t i = 0 ; i < vIds.size() ; ++ i) {
|
|
if ( i > 0)
|
|
sIds += "," ;
|
|
sIds += ToString( vIds[i]) ;
|
|
}
|
|
string sLua = "EgtCurveCompoByChain(" + ToString( nParentId) + ",{" +
|
|
sIds + "},{" +
|
|
ToString( ptNear) + "}," +
|
|
( bErase ? "true" : "false") + "," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nFirstId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della prima nuova entità
|
|
return nFirstId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCompoFromPoints( int nParentId, int nP, const double ptPs[], int nRefType)
|
|
{
|
|
PolyLine PL ;
|
|
for ( int i = 0 ; i < nP ; ++i) {
|
|
PL.AddUPoint( 0, Point3d( ptPs[3*i], ptPs[3*i+1], ptPs[3*i+2])) ;
|
|
}
|
|
return EgtCreateCurveCompoFromPoints( nParentId, PL, nRefType) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
EgtCreateCurveCompoFromPoints( 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<ICurveComposite> 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) ;
|
|
EgtSetModified() ;
|
|
// 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
|
|
__stdcall EgtCreateCurveCompoFromPointBulges( int nParentId, int nPB, const double ptPBs[], int nRefType)
|
|
{
|
|
PolyArc PA ;
|
|
for ( int i = 0 ; i < nPB ; ++i) {
|
|
PA.AddUPoint( 0, Point3d( ptPBs[4*i], ptPBs[4*i+1], ptPBs[4*i+2]), ptPBs[4*i+3]) ;
|
|
}
|
|
return EgtCreateCurveCompoFromPointBulges( nParentId, PA, nRefType) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
EgtCreateCurveCompoFromPointBulges( 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<ICurveComposite> 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) ;
|
|
EgtSetModified() ;
|
|
// 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
|
|
__stdcall EgtCreateCurveCompoByApprox( 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) ;
|
|
// eseguo l'approssimazione
|
|
PtrOwner<ICurveComposite> pCC( CreateCurveComposite()) ;
|
|
bOk = bOk && ! IsNull( pCC) ;
|
|
if ( ! bArcsVsLines) { // con linee
|
|
PolyLine PL ;
|
|
bOk = bOk && GetPolyLineFromCurve( nSouId, frEnt, dLinTol, PL) && pCC->FromPolyLine( PL) ;
|
|
}
|
|
else { // con bi-archi
|
|
PolyArc PA ;
|
|
bOk = bOk && GetPolyArcFromCurve( nSouId, frEnt, dLinTol, 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) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtCurveCompoByApprox(" + ToString( nParentId) + "," +
|
|
ToString( nSouId) + "," +
|
|
( bArcsVsLines ? "ARCS" : "LINES") +
|
|
ToString( dLinTol) + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateRectangle3P( int nParentId, const double ptIni[3],
|
|
const double ptCross[3], const double ptDir[3], int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
bool bOk = true ;
|
|
// porto in locale i punti, i versori e il versore estrusione
|
|
Point3d ptIniL( ptIni) ;
|
|
Point3d ptCrossL( ptCross) ;
|
|
Point3d ptDirL( ptDir) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
|
|
if ( bOk) {
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptIniL.ToLoc( frLoc) ;
|
|
ptCrossL.ToLoc( frLoc) ;
|
|
ptDirL.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else /* RTY_GRID */ {
|
|
ptIniL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptCrossL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptDirL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), 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) ;
|
|
// creo la curva e la inserisco nel GDB
|
|
nId = EgtCreateCurveCompoFromPoints( nParentId, PL, RTY_LOC) ;
|
|
// 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( Point3d( ptIni)) + "},{" +
|
|
ToString( Point3d( ptCross)) + "},{" +
|
|
ToString( Point3d( ptDir)) + "}," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreatePolygonFromSide( int nParentId, int nNumSides, const double ptIni[3],
|
|
const double ptFin[3], const double vtN[3], int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
bool bOk = true ;
|
|
// porto in locale i punti, la normale e il versore estrusione
|
|
Point3d ptIniL( ptIni) ;
|
|
Point3d ptFinL( ptFin) ;
|
|
Vector3d vtNL( vtN) ;
|
|
Vector3d vtExtrL = Z_AX ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
|
|
if ( bOk) {
|
|
if ( nRefType == RTY_GLOB) {
|
|
ptIniL.ToLoc( frLoc) ;
|
|
ptFinL.ToLoc( frLoc) ;
|
|
vtNL.ToLoc( frLoc) ;
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
}
|
|
else /* RTY_GRID */ {
|
|
ptIniL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
ptFinL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtNL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
}
|
|
}
|
|
}
|
|
// creo la curva composita
|
|
PtrOwner<ICurveComposite> 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) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtPolygonFromSide(" + ToString( nParentId) + "," +
|
|
ToString( nNumSides) + ",{" +
|
|
ToString( Point3d( ptIni)) + "},{" +
|
|
ToString( Point3d( ptFin)) + "},{" +
|
|
ToString( Vector3d( 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 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
bool
|
|
SetExtrusionFromGridVersZ( IGeomDB* pGeomDB, int nParentId, ICurve* pCurve)
|
|
{
|
|
// verifiche sui parametri
|
|
if ( pGeomDB == nullptr || pCurve == nullptr)
|
|
return false ;
|
|
// assegno il versore estrusione a partire dal versore Z della griglia corrente
|
|
Vector3d vtExtr = pGeomDB->GetGridFrame().VersZ() ;
|
|
Frame3d frEnt ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frEnt))
|
|
return false ;
|
|
vtExtr.ToLoc( frEnt) ;
|
|
return pCurve->SetExtrusion( vtExtr) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GetPolyLineFromCurve( int nId, const Frame3d& frDest, double dLinTol, PolyLine& PL)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pCrv == nullptr)
|
|
return false ;
|
|
// recupero il riferimento della curva
|
|
Frame3d frCrv ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frCrv))
|
|
return false ;
|
|
// calcolo la polilinea che approssima la curva
|
|
const double ANG_TOL_STD_DEG = 15 ;
|
|
// se i riferimenti sono uguali
|
|
if ( AreSameFrame( frCrv, frDest)) {
|
|
// ricavo l'approssimazione
|
|
if ( ! pCrv->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, PL))
|
|
return false ;
|
|
}
|
|
// altrimenti devo prima trasformare la curva
|
|
else {
|
|
// creo una copia della curva (da buttare alla fine)
|
|
PtrOwner<ICurve> pModCrv( pCrv->Clone()) ;
|
|
if ( IsNull( pModCrv))
|
|
return false ;
|
|
// eseguo la trasformazione
|
|
pModCrv->LocToLoc( frCrv, frDest) ;
|
|
// ricavo l'approssimazione
|
|
if ( ! pModCrv->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, PL))
|
|
return false ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GetPolyArcFromCurve( int nId, const Frame3d& frDest, double dLinTol, PolyArc& PA)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pCrv == nullptr)
|
|
return false ;
|
|
// recupero il riferimento della curva
|
|
Frame3d frCrv ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frCrv))
|
|
return false ;
|
|
// calcolo la polilinea che approssima la curva
|
|
const double ANG_TOL_STD_DEG = 15 ;
|
|
// se i riferimenti sono uguali
|
|
if ( AreSameFrame( frCrv, frDest)) {
|
|
// ricavo l'approssimazione
|
|
if ( ! pCrv->ApproxWithArcs( dLinTol, ANG_TOL_STD_DEG, PA))
|
|
return false ;
|
|
}
|
|
// altrimenti devo prima trasformare la curva
|
|
else {
|
|
// creo una copia della curva (da buttare alla fine)
|
|
PtrOwner<ICurve> pModCrv( pCrv->Clone()) ;
|
|
if ( IsNull( pModCrv))
|
|
return false ;
|
|
// eseguo la trasformazione
|
|
pModCrv->LocToLoc( frCrv, frDest) ;
|
|
// ricavo l'approssimazione
|
|
if ( ! pModCrv->ApproxWithArcs( dLinTol, ANG_TOL_STD_DEG, PA))
|
|
return false ;
|
|
}
|
|
return true ;
|
|
}
|