4a618e287b
- aggiunta gestione selezione per percorso.
1865 lines
80 KiB
C++
1865 lines
80 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 "GeoTools.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/EgkCircleCenTgCurve.h"
|
|
#include "/EgtDev/Include/EgkArcSpecial.h"
|
|
#include "/EgtDev/Include/EgkArcPntDirTgCurve.h"
|
|
#include "/EgtDev/Include/EgkArcCenTgCurvePnt.h"
|
|
#include "/EgtDev/Include/EgkCurveBezier.h"
|
|
#include "/EgtDev/Include/EgkCurveComposite.h"
|
|
#include "/EgtDev/Include/EgkChainCurves.h"
|
|
#include "/EgtDev/Include/EgkSurfTriMesh.h"
|
|
#include "/EgtDev/Include/EGkDistPointCurve.h"
|
|
#include "/EgtDev/Include/EGkStringUtils3d.h"
|
|
#include "/EgtDev/Include/EGkCurveLocal.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
|
|
using namespace std ;
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static ICurveLine* CreateLinePointTgCurve( IGeomDB* pGeomDB, int nParentId,
|
|
const Point3d& ptIni, const Point3d& ptFin, int nIdF) ;
|
|
static ICurveLine* CreateLinePointPerpCurve( IGeomDB* pGeomDB, int nParentId,
|
|
const Point3d& ptIni, const Point3d& ptFin, int nIdF) ;
|
|
static ICurveLine* CreateLinePointMinDistCurve( IGeomDB* pGeomDB, int nParentId,
|
|
const Point3d& ptIni, const Point3d& ptFin, int nIdF) ;
|
|
static ICurveLine* CreateLineTgTwoCurves( IGeomDB* pGeomDB, int nParentId,
|
|
const Point3d& ptIni, int nIdI, const Point3d& ptFin, int nIdF) ;
|
|
static ICurveLine* CreateLinePerpTwoCurves( IGeomDB* pGeomDB, int nParentId,
|
|
const Point3d& ptIni, int nIdI, const Point3d& ptFin, int nIdF) ;
|
|
static ICurveLine* CreateLineTgCurvePerpCurve( IGeomDB* pGeomDB, int nParentId,
|
|
const Point3d& ptIni, int nIdI, const Point3d& ptFin, int nIdF) ;
|
|
static Vector3d CalcExtrusion( IGeomDB* pGeomDB, int nParentId, int nRefType) ;
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__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 ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti e il versore estrusione
|
|
Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ;
|
|
Point3d ptFinL = GetPointLocal( pGeomDB, ptFin, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// setto la linea
|
|
if ( ! pCrvLine->Set( ptIniL, ptFinL))
|
|
return GDB_ID_NULL ;
|
|
// assegno il versore estrusione
|
|
pCrvLine->SetExtrusion( vtExtrL) ;
|
|
// inserisco la linea nel DB
|
|
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvLine)) ;
|
|
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 ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
bool bOk = pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
|
|
// porto in locale i punti e il versore estrusione
|
|
Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ;
|
|
Point3d ptFinL = GetPointLocal( pGeomDB, ptFin, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// 1 - se punti entrambi definiti
|
|
if ( nSepI == SEP_STD && nSepF == SEP_STD) {
|
|
pCrvLine.Set( CreateCurveLine()) ;
|
|
bOk = bOk && ! IsNull( pCrvLine) ;
|
|
bOk = bOk && pCrvLine->Set( ptIniL, ptFinL) ;
|
|
}
|
|
// 2 - se primo punto definito e secondo a minima distanza
|
|
else if ( nSepI == SEP_STD && nSepF == SEP_MINDIST) {
|
|
pCrvLine.Set( CreateLinePointMinDistCurve( pGeomDB, nParentId, ptIniL, ptFinL, nIdF)) ;
|
|
bOk = bOk && ! IsNull( pCrvLine) ;
|
|
}
|
|
// 3 - se primo punto a minima distanza e secondo definito
|
|
else if ( nSepI == SEP_MINDIST && nSepF == SEP_STD) {
|
|
pCrvLine.Set( CreateLinePointMinDistCurve( pGeomDB, nParentId, ptFinL, ptIniL, nIdI)) ;
|
|
bOk = bOk && ! IsNull( pCrvLine) ;
|
|
bOk = bOk && pCrvLine->Invert() ;
|
|
}
|
|
// 4 - se primo punto definito e secondo tangente
|
|
else if ( nSepI == SEP_STD && nSepF == SEP_TG) {
|
|
pCrvLine.Set( CreateLinePointTgCurve( pGeomDB, nParentId, ptIniL, ptFinL, nIdF)) ;
|
|
bOk = bOk && ! IsNull( pCrvLine) ;
|
|
}
|
|
// 5 - se primo punto tangente e secondo definito
|
|
else if ( nSepI == SEP_TG && nSepF == SEP_STD) {
|
|
// costruisco la curva al contrario e poi la inverto
|
|
pCrvLine.Set( CreateLinePointTgCurve( pGeomDB, nParentId, ptFinL, ptIniL, nIdI)) ;
|
|
bOk = bOk && ! IsNull( pCrvLine) ;
|
|
bOk = bOk && pCrvLine->Invert() ;
|
|
}
|
|
// 6 - se entrambi i punti tangenti
|
|
else if ( nSepI == SEP_TG && nSepF == SEP_TG) {
|
|
pCrvLine.Set( CreateLineTgTwoCurves( pGeomDB, nParentId, ptIniL, nIdI, ptFinL, nIdF)) ;
|
|
bOk = bOk && ! IsNull( pCrvLine) ;
|
|
}
|
|
// 7 - se primo punto definito e secondo perpendicolare
|
|
else if ( nSepI == SEP_STD && nSepF == SEP_PERP) {
|
|
pCrvLine.Set( CreateLinePointPerpCurve( pGeomDB, nParentId, ptIniL, ptFinL, nIdF)) ;
|
|
bOk = bOk && ! IsNull( pCrvLine) ;
|
|
}
|
|
// 8 - se primo punto perpendicolare e secondo definito
|
|
else if ( nSepI == SEP_PERP && nSepF == SEP_STD) {
|
|
// costruisco la curva al contrario e poi la inverto
|
|
pCrvLine.Set( CreateLinePointPerpCurve( pGeomDB, nParentId, ptFinL, ptIniL, nIdI)) ;
|
|
bOk = bOk && ! IsNull( pCrvLine) ;
|
|
bOk = bOk && pCrvLine->Invert() ;
|
|
}
|
|
// 9 - se entrambi i punti perpendicolari
|
|
else if ( nSepI == SEP_PERP && nSepF == SEP_PERP) {
|
|
pCrvLine.Set( CreateLinePerpTwoCurves( pGeomDB, nParentId, ptIniL, nIdI, ptFinL, nIdF)) ;
|
|
bOk = bOk && ! IsNull( pCrvLine) ;
|
|
}
|
|
// 10 - se primo punto tangente e secondo perpendicolare
|
|
else if ( nSepI == SEP_TG && nSepF == SEP_PERP) {
|
|
pCrvLine.Set( CreateLineTgCurvePerpCurve( pGeomDB, nParentId, ptIniL, nIdI, ptFinL, nIdF)) ;
|
|
bOk = bOk && ! IsNull( pCrvLine) ;
|
|
}
|
|
// 11 - se primo punto perpendicolare e secondo tangente
|
|
else if ( nSepI == SEP_PERP && nSepF == SEP_TG) {
|
|
// costruisco la curva al contrario e poi la inverto
|
|
pCrvLine.Set( CreateLineTgCurvePerpCurve( pGeomDB, nParentId, ptFinL, nIdF, ptIniL, nIdI)) ;
|
|
bOk = bOk && ! IsNull( pCrvLine) ;
|
|
bOk = bOk && pCrvLine->Invert() ;
|
|
}
|
|
// errore
|
|
else {
|
|
bOk = false ;
|
|
}
|
|
// assegno il versore estrusione
|
|
bOk = bOk && pCrvLine->SetExtrusion( vtExtrL) ;
|
|
// inserisco la linea nel DB
|
|
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvLine)) : GDB_ID_NULL) ;
|
|
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)
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale il punto e i versori
|
|
Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ;
|
|
Vector3d vtDirL = GetVectorLocal( pGeomDB, vtDir, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, 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 locale
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale il punto e il versore estrusione
|
|
Point3d ptStartL = GetPointLocal( pGeomDB, ptStart, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// recupero il riferimento della curva
|
|
Frame3d frCurve ;
|
|
if ( ! pGeomDB->GetGlobFrame( nCrvId, frCurve))
|
|
return GDB_ID_NULL ;
|
|
// recupero la curva
|
|
const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ;
|
|
if ( pCurve == nullptr)
|
|
return GDB_ID_NULL ;
|
|
// porto il punto nel riferimento della curva
|
|
Point3d ptStartC = ptStart ;
|
|
ptStartC.LocToLoc( frLoc, frCurve) ;
|
|
// calcolo il punto a minima distanza
|
|
int nFlag ;
|
|
Point3d ptEndL ;
|
|
DistPointCurve dstPtCurve( ptStartC, *pCurve) ;
|
|
if ( ! dstPtCurve.GetMinDistPoint( dNearPar, ptEndL, nFlag))
|
|
return GDB_ID_NULL ;
|
|
// porto il punto finale nel riferimento di creazione
|
|
ptEndL.LocToLoc( frCurve, frLoc) ;
|
|
// creo la linea
|
|
PtrOwner<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 ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti e i versori
|
|
Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ;
|
|
Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// setto la circonferenza
|
|
if ( ! pCrvArc->Set( ptCenL, vtNL, dRad))
|
|
return GDB_ID_NULL ;
|
|
// assegno il versore estrusione
|
|
pCrvArc->SetExtrusion( vtExtrL) ;
|
|
// inserisco l'arco nel DB
|
|
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
|
|
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()) ;
|
|
bool bOk = ! IsNull( pCrvArc) ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
|
|
// porto in locale i punti e i versori
|
|
Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ;
|
|
Point3d ptOnL = GetPointLocal( pGeomDB, ptOn, nRefType, frLoc) ;
|
|
Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// calcolo il raggio
|
|
double dRad = (( ptOnL - ptCenL) ^ vtNL).Len() ;
|
|
// setto la circonferenza
|
|
bOk = bOk && pCrvArc->Set( ptCenL, vtNL, dRad) ;
|
|
// assegno il versore estrusione
|
|
bOk = bOk && pCrvArc->SetExtrusion( vtExtrL) ;
|
|
// inserisco l'arco nel DB
|
|
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) : GDB_ID_NULL) ;
|
|
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 EgtCreateCurveCircleCPNEx( int nParentId, const double ptCen[3],
|
|
const double ptOn[3], int nSepO, int nIdO, const double vtN[3], int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc ;
|
|
bool bOk = true ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
|
|
// porto in locale i punti e i versori
|
|
Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ;
|
|
Point3d ptOnL = GetPointLocal( pGeomDB, ptOn, nRefType, frLoc) ;
|
|
Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// se punto standard
|
|
if ( nSepO == SEP_STD) {
|
|
pCrvArc.Set( CreateCurveArc()) ;
|
|
bOk = bOk && ! IsNull( pCrvArc) ;
|
|
// calcolo il raggio
|
|
double dRad = (( ptOnL - ptCenL) ^ vtNL).Len() ;
|
|
// setto la circonferenza
|
|
bOk = bOk && pCrvArc->Set( ptCenL, vtNL, dRad) ;
|
|
}
|
|
// se punto di tangenza, determino il vero punto di passaggio
|
|
else if ( nSepO == SEP_TG) {
|
|
// recupero la curva di tangenza in locale
|
|
CurveLocal CrvTgLoc( pGeomDB, nIdO, frLoc) ;
|
|
// calcolo la circonferenza tangente a questa curva
|
|
pCrvArc.Set( GetCircleCenTgCurve( ptCenL, vtNL, *CrvTgLoc.Get(), ptOnL)) ;
|
|
bOk = bOk && ! IsNull( pCrvArc) ;
|
|
}
|
|
// altrimenti errore
|
|
else
|
|
bOk = false ;
|
|
// assegno il versore estrusione
|
|
bOk = bOk && pCrvArc->SetExtrusion( vtExtrL) ;
|
|
// inserisco l'arco nel DB
|
|
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) : GDB_ID_NULL) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtCircleCPNEx(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptCen)) + "},{" +
|
|
ToString( Point3d( ptOn)) + "}," +
|
|
SepToString( nSepO) + "," +
|
|
ToString( nIdO) + ",{" +
|
|
ToString( Vector3d( vtN)) + "}," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nNewId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nNewId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
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 ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti e il versore estrusione
|
|
Point3d ptP1L = GetPointLocal( pGeomDB, ptP1, nRefType, frLoc) ;
|
|
Point3d ptP2L = GetPointLocal( pGeomDB, ptP2, nRefType, frLoc) ;
|
|
Point3d ptP3L = GetPointLocal( pGeomDB, ptP3, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// setto l'arco
|
|
if ( ! pCrvArc->Set3P( ptP1L, ptP2L, ptP3L, true))
|
|
return GDB_ID_NULL ;
|
|
// assegno il versore estrusione
|
|
pCrvArc->SetExtrusion( vtExtrL) ;
|
|
// inserisco l'arco nel DB
|
|
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
|
|
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 ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti, i versori e il versore estrusione
|
|
Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ;
|
|
Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ;
|
|
Vector3d vtSL = GetVectorLocal( pGeomDB, vtS, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// setto l'arco
|
|
if ( ! pCrvArc->Set( ptCenL, vtNL, dRad, vtSL, dAngCenDeg, dDeltaN))
|
|
return GDB_ID_NULL ;
|
|
// assegno il versore estrusione
|
|
pCrvArc->SetExtrusion( vtExtrL) ;
|
|
// inserisco l'arco nel DB
|
|
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
|
|
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 ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti, i versori e il versore estrusione
|
|
Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ;
|
|
Point3d ptStartL = GetPointLocal( pGeomDB, ptStart, nRefType, frLoc) ;
|
|
Point3d ptNearEndL = GetPointLocal( pGeomDB, ptNearEnd, nRefType, frLoc) ;
|
|
Vector3d vtNormL = GetVectorLocal( pGeomDB, vtNorm, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// setto l'arco
|
|
if ( ! pCrvArc->SetC2PN( ptCenL, ptStartL, ptNearEndL, vtNormL))
|
|
return GDB_ID_NULL ;
|
|
// assegno il versore estrusione
|
|
pCrvArc->SetExtrusion( vtExtrL) ;
|
|
// inserisco l'arco nel DB
|
|
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
|
|
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 EgtCreateCurveArcC2PNEx( int nParentId, const double ptCen[3],
|
|
const double ptStart[3], int nSepS, int nIdS,
|
|
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 ;
|
|
bool bOk = true ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
|
|
// porto in locale i punti, i versori e il versore estrusione
|
|
Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ;
|
|
Point3d ptStartL = GetPointLocal( pGeomDB, ptStart, nRefType, frLoc) ;
|
|
Point3d ptNearEndL = GetPointLocal( pGeomDB, ptNearEnd, nRefType, frLoc) ;
|
|
Vector3d vtNormL = GetVectorLocal( pGeomDB, vtNorm, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// se punto standard
|
|
if ( nSepS == SEP_STD) {
|
|
pCrvArc.Set( CreateCurveArc()) ;
|
|
bOk = bOk && ! IsNull( pCrvArc) ;
|
|
// setto l'arco
|
|
if ( ! pCrvArc->SetC2PN( ptCenL, ptStartL, ptNearEndL, vtNormL))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// se punto di tangenza, determino il vero punto di passaggio
|
|
else if ( nSepS == SEP_TG) {
|
|
// recupero la curva di tangenza in locale
|
|
CurveLocal CrvTgLoc( pGeomDB, nIdS, frLoc) ;
|
|
// calcolo l'arco tangente a questa curva
|
|
pCrvArc.Set( GetArcCenTgCurvePnt( ptCenL, *CrvTgLoc.Get(), ptStartL, ptNearEndL, vtNormL)) ;
|
|
bOk = bOk && ! IsNull( pCrvArc) ;
|
|
}
|
|
// altrimenti errore
|
|
else
|
|
bOk = false ;
|
|
// assegno il versore estrusione
|
|
bOk = bOk && pCrvArc->SetExtrusion( vtExtrL) ;
|
|
// inserisco l'arco nel DB
|
|
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) : GDB_ID_NULL) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtArcC2PNEx(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptCen)) + "},{" +
|
|
ToString( Point3d( ptStart)) + "},{" +
|
|
SepToString( nSepS) + "," +
|
|
ToString( nIdS) + ",{" +
|
|
ToString( Point3d( ptNearEnd)) + "},{" +
|
|
ToString( Vector3d( vtNorm)) + "}," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nNewId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nNewId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
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<ICurve> pCrv ;
|
|
bool bOk = true ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
|
|
// porto in locale i punti e il versore estrusione
|
|
Point3d ptP1L = GetPointLocal( pGeomDB, ptP1, nRefType, frLoc) ;
|
|
Point3d ptP2L = GetPointLocal( pGeomDB, ptP2, nRefType, frLoc) ;
|
|
Point3d ptP3L = GetPointLocal( pGeomDB, ptP3, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// setto l'arco
|
|
pCrv.Set( GetArc3P( ptP1L, ptP2L, ptP3L, false)) ;
|
|
bOk = bOk && ! ( IsNull( pCrv)) ;
|
|
// assegno il versore estrusione
|
|
bOk = bOk && pCrv->SetExtrusion( vtExtrL) ;
|
|
// inserisco l'arco nel DB
|
|
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrv)) : GDB_ID_NULL) ;
|
|
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 (in casi particolari retta)
|
|
PtrOwner<ICurve> pCrv ;
|
|
bool bOk = true ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
|
|
// porto in locale i punti, i versori e il versore estrusione
|
|
Point3d ptStartL = GetPointLocal( pGeomDB, ptStart, nRefType, frLoc) ;
|
|
Point3d ptEndL = GetPointLocal( pGeomDB, ptEnd, nRefType, frLoc) ;
|
|
Vector3d vtDirSL = GetVectorLocal( pGeomDB, vtDirS, nRefType, frLoc) ;
|
|
Vector3d vtNormL = GetVectorLocal( pGeomDB, vtNorm, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// setto l'arco
|
|
pCrv.Set( GetArc2PVN( ptStartL, ptEndL, vtDirSL, vtNormL)) ;
|
|
bOk = bOk && ! IsNull( pCrv) ;
|
|
// assegno il versore estrusione
|
|
bOk = bOk && pCrv->SetExtrusion( vtExtrL) ;
|
|
// inserisco l'arco nel DB
|
|
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrv)) : GDB_ID_NULL) ;
|
|
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 EgtCreateCurveArc2PVNEx( int nParentId, const double ptStart[3],
|
|
const double ptEnd[3], int nSep, int nId,
|
|
const double vtDirS[3], const double vtNorm[3], int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo la curva ( in casi particolari potrebbe essere una retta)
|
|
PtrOwner<ICurve> pCrv ;
|
|
bool bOk = true ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
|
|
// porto in locale i punti, i versori e il versore estrusione
|
|
Point3d ptStartL = GetPointLocal( pGeomDB, ptStart, nRefType, frLoc) ;
|
|
Point3d ptEndL = GetPointLocal( pGeomDB, ptEnd, nRefType, frLoc) ;
|
|
Vector3d vtDirSL = GetVectorLocal( pGeomDB, vtDirS, nRefType, frLoc) ;
|
|
Vector3d vtNormL = GetVectorLocal( pGeomDB, vtNorm, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// se punto standard
|
|
if ( nSep == SEP_STD) {
|
|
// creo l'arco
|
|
pCrv.Set( CreateCurveArc()) ;
|
|
bOk = bOk && ! IsNull( pCrv) ;
|
|
if ( bOk) {
|
|
// imposto l'arco
|
|
if ( (dynamic_cast<ICurveArc*>(Get(pCrv)))->Set2PVN( ptStartL, ptEndL, vtDirSL, vtNormL))
|
|
;
|
|
// non riuscito, provo se risulta essere una retta
|
|
else if ( ( ptEndL - ptStartL) * vtDirSL > EPS_ZERO) {
|
|
// creo e setto la retta
|
|
pCrv.Set( CreateCurveLine()) ;
|
|
bOk = bOk && ! IsNull( pCrv) ;
|
|
bOk = bOk && (dynamic_cast<ICurveLine*>(Get(pCrv)))->Set( ptStartL, ptEndL) ;
|
|
}
|
|
// impossibile
|
|
else
|
|
bOk = false ;
|
|
}
|
|
}
|
|
// se punto di tangenza, determino il vero punto di passaggio
|
|
else if ( nSep == SEP_TG) {
|
|
// recupero la curva di tangenza in locale
|
|
CurveLocal CrvTgLoc( pGeomDB, nId, frLoc) ;
|
|
// calcolo l'arco tangente a questa curva
|
|
pCrv.Set( GetArcPntDirTgCurve( ptStartL, vtDirSL, *CrvTgLoc.Get(), ptEndL, vtNormL)) ;
|
|
bOk = bOk && ! IsNull( pCrv) ;
|
|
}
|
|
// altrimenti errore
|
|
else
|
|
bOk = false ;
|
|
// assegno il versore estrusione
|
|
bOk = bOk && pCrv->SetExtrusion( vtExtrL) ;
|
|
// inserisco l'arco nel DB
|
|
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrv)) : GDB_ID_NULL) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtArc2PVNEx(" + ToString( nParentId) + ",{" +
|
|
ToString( Point3d( ptStart)) + "},{" +
|
|
ToString( Point3d( ptEnd)) + "}," +
|
|
SepToString( nSep) + "," +
|
|
ToString( nId) + ",{" +
|
|
ToString( Vector3d( vtDirS)) + "},{" +
|
|
ToString( Vector3d( vtNorm)) + "}," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nNewId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nNewId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
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.emplace_back( 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 = GetPointLocal( pGeomDB, vPnt[i].v, nRefType, frLoc) ;
|
|
// inserimento del punto di controllo
|
|
if ( ! pCrvBez->SetControlPoint( i, ptCtrl))
|
|
bOk = false ;
|
|
}
|
|
// se curva nulla (ovvero ridotta a punto), errore
|
|
bOk = bOk && ! pCrvBez->IsAPoint() ;
|
|
// assegno il versore estrusione
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, 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.emplace_back( 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 = GetPointLocal( pGeomDB, vPntW[i].first.v, nRefType, frLoc) ;
|
|
// inserimento del punto di controllo con peso
|
|
if ( ! pCrvBez->SetControlPoint( i, ptCtrl, vPntW[i].second))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// se curva nulla (ovvero ridotta a punto), errore
|
|
bOk = bOk && ! pCrvBez->IsAPoint() ;
|
|
// assegno il versore estrusione
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, 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->LocToLoc( frSou, frDest) ;
|
|
// se curva nulla (ovvero ridotta a punto), errore
|
|
bOk = bOk && ! pCrvBez->IsAPoint() ;
|
|
// inserisco la curva nel DB
|
|
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvBez)) : GDB_ID_NULL) ;
|
|
if ( nId != GDB_ID_NULL) {
|
|
// se richiesto, cancello l'arco originale
|
|
if ( bErase) {
|
|
if ( ! pGeomDB->Erase( nArcId))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
}
|
|
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())) ;
|
|
for ( size_t i = 0 ; i < vIds.size() ; ++ i) {
|
|
int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ;
|
|
while ( nId != GDB_ID_NULL) {
|
|
// recupero la curva e il suo riferimento
|
|
ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pCrv == nullptr)
|
|
return GDB_ID_NULL ;
|
|
Frame3d frCrv ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frCrv))
|
|
return GDB_ID_NULL ;
|
|
// recupero i dati della curva necessari al concatenamento e li assegno
|
|
Point3d ptStart, ptEnd ;
|
|
Vector3d vtStart, vtEnd ;
|
|
if ( ! pCrv->GetStartPoint( ptStart) || ! pCrv->GetStartDir( vtStart) ||
|
|
! pCrv->GetEndPoint( ptEnd) || ! pCrv->GetEndDir( vtEnd))
|
|
return GDB_ID_NULL ;
|
|
ptStart.LocToLoc( frCrv, frDest) ;
|
|
vtStart.LocToLoc( frCrv, frDest) ;
|
|
ptEnd.LocToLoc( frCrv, frDest) ;
|
|
vtEnd.LocToLoc( frCrv, frDest) ;
|
|
if ( ! chainC.AddCurve( nId, ptStart, vtStart, ptEnd, vtEnd))
|
|
return GDB_ID_NULL ;
|
|
// passo al successivo
|
|
nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ;
|
|
}
|
|
}
|
|
// recupero i percorsi concatenati
|
|
int nFirstId = GDB_ID_NULL ;
|
|
Point3d ptNearL = GetPointLocal( pGeomDB, ptNear.v, nRefType, frDest) ;
|
|
INTVECTOR vId2s ;
|
|
while ( chainC.GetChainFromNear( ptNearL, false, 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
|
|
for ( size_t i = 0 ; i < vId2s.size() ; ++ i) {
|
|
int nId = abs( vId2s[i]) ;
|
|
bool bInvert = ( vId2s[i] < 0) ;
|
|
// recupero la curva e il suo riferimento
|
|
ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pCrv == nullptr)
|
|
return GDB_ID_NULL ;
|
|
Frame3d frCrv ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frCrv))
|
|
return GDB_ID_NULL ;
|
|
// copio la curva
|
|
PtrOwner<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 e ok, cancello le curve originali
|
|
if ( bErase && nFirstId != GDB_ID_NULL) {
|
|
for ( size_t i = 0 ; i < vIds.size() ; ++ i) {
|
|
int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ;
|
|
while ( nId != GDB_ID_NULL) {
|
|
pGeomDB->Erase( nId) ;
|
|
// passo al successivo
|
|
nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetFirstSelectedObj()) ;
|
|
}
|
|
}
|
|
}
|
|
// restituisco l'identificativo della prima nuova entità
|
|
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)
|
|
sIds += ( vIds[i] != GDB_ID_SEL ? ToString( vIds[i]) : "GDB_ID_SEL") + "," ;
|
|
sIds.pop_back() ;
|
|
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) ;
|
|
// recupero la curva in locale
|
|
CurveLocal CrvLoc( pGeomDB, nSouId, frEnt) ;
|
|
bOk = bOk && ( CrvLoc.Get() != nullptr) ;
|
|
// eseguo l'approssimazione
|
|
PtrOwner<ICurveComposite> pCC( CreateCurveComposite()) ;
|
|
bOk = bOk && ! IsNull( pCC) ;
|
|
const double ANG_TOL_STD_DEG = 15 ;
|
|
if ( ! bArcsVsLines) { // con linee
|
|
PolyLine PL ;
|
|
bOk = bOk && CrvLoc.Get()->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, PL) && pCC->FromPolyLine( PL) ;
|
|
}
|
|
else { // con bi-archi
|
|
PolyArc PA ;
|
|
bOk = bOk && CrvLoc.Get()->ApproxWithArcs( dLinTol, ANG_TOL_STD_DEG, PA) && pCC->FromPolyArc( PA) ;
|
|
}
|
|
// copio estrusione e spessore della curva sorgente
|
|
const ICurve* pSouCrv = GetCurve( pGeomDB->GetGeoObj( nSouId)) ;
|
|
if ( bOk && pSouCrv != nullptr) {
|
|
// recupero estrusione e spessore
|
|
Vector3d vtExtr ;
|
|
pSouCrv->GetExtrusion( vtExtr) ;
|
|
double dThick ;
|
|
pSouCrv->GetThickness( dThick) ;
|
|
// sistemo per eventuale cambio di riferimento
|
|
Frame3d frSou ;
|
|
bOk = bOk && pGeomDB->GetGlobFrame( nSouId, frSou) ;
|
|
vtExtr.LocToLoc( frSou, frEnt) ;
|
|
// assegno
|
|
pCC->SetExtrusion( vtExtr) ;
|
|
pCC->SetThickness( dThick) ;
|
|
}
|
|
// inserisco la curva composita nel DB
|
|
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCC)) : GDB_ID_NULL) ;
|
|
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 ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti, i versori e il versore estrusione
|
|
Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ;
|
|
Point3d ptCrossL = GetPointLocal( pGeomDB, ptCross, nRefType, frLoc) ;
|
|
Point3d ptDirL = GetPointLocal( pGeomDB, ptDir, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// calcolo il lato X
|
|
Vector3d vtDirX = ptDirL - ptIniL ;
|
|
bOk = bOk && vtDirX.Normalize() ;
|
|
Vector3d vtLatoX = bOk ? (( ptCrossL - ptIniL) * vtDirX) * vtDirX : V_NULL ;
|
|
// creo la polilinea con i punti
|
|
int nId = GDB_ID_NULL ;
|
|
if ( bOk) {
|
|
PolyLine PL ;
|
|
PL.AddUPoint( 0, ptIniL) ;
|
|
PL.AddUPoint( 1, Point3d( ptIniL) + vtLatoX) ;
|
|
PL.AddUPoint( 2, ptCrossL) ;
|
|
PL.AddUPoint( 3, Point3d( ptCrossL) - vtLatoX) ;
|
|
PL.AddUPoint( 4, ptIniL) ;
|
|
// disabilito log dei comandi e salvo stato precedente
|
|
bool bPrevCmdLog = SetCmdLog( false) ;
|
|
// creo la curva e la inserisco nel GDB
|
|
nId = EgtCreateCurveCompoFromPoints( nParentId, PL, RTY_LOC) ;
|
|
// ripristino precedente stato dei comandi
|
|
SetCmdLog( bPrevCmdLog) ;
|
|
// ne sistemo il vettore estrusione
|
|
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pCurve != nullptr)
|
|
pCurve->SetExtrusion( vtExtrL) ;
|
|
}
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtRectangle3P(" + ToString( nParentId) + ",{" +
|
|
ToString( 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 EgtCreatePolygonFromRadius( int nParentId, int nNumSides, const double ptCen[3],
|
|
const double ptCorn[3], const double vtN[3], int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
bool bOk = true ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti, la normale e il versore estrusione
|
|
Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ;
|
|
Point3d ptCornL = GetPointLocal( pGeomDB, ptCorn, nRefType, frLoc) ;
|
|
Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// creo la curva composita
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
bOk = bOk && ! IsNull( pCrvCompo) ;
|
|
// setto la curva
|
|
bOk = bOk && pCrvCompo->PolygonCenterCorner( nNumSides, ptCenL, ptCornL, vtNL) ;
|
|
// assegno il versore estrusione
|
|
bOk = bOk && pCrvCompo->SetExtrusion( vtExtrL) ;
|
|
// inserisco la curva nel DB
|
|
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) : GDB_ID_NULL) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtPolygonFromRadius(" + ToString( nParentId) + "," +
|
|
ToString( nNumSides) + ",{" +
|
|
ToString( Point3d( ptCen)) + "},{" +
|
|
ToString( Point3d( ptCorn)) + "},{" +
|
|
ToString( Vector3d( vtN)) + "}," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco l'identificativo della nuova entità
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreatePolygonFromApothem( int nParentId, int nNumSides, const double ptCen[3],
|
|
const double ptMid[3], const double vtN[3], int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
bool bOk = true ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti, la normale e il versore estrusione
|
|
Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ;
|
|
Point3d ptMidL = GetPointLocal( pGeomDB, ptMid, nRefType, frLoc) ;
|
|
Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, frLoc) ;
|
|
// creo la curva composita
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
bOk = bOk && ! IsNull( pCrvCompo) ;
|
|
// setto la curva
|
|
bOk = bOk && pCrvCompo->PolygonCenterMidSide( nNumSides, ptCenL, ptMidL, vtNL) ;
|
|
// assegno il versore estrusione
|
|
bOk = bOk && pCrvCompo->SetExtrusion( vtExtrL) ;
|
|
// inserisco la curva nel DB
|
|
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) : GDB_ID_NULL) ;
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtPolygonFromApothem(" + ToString( nParentId) + "," +
|
|
ToString( nNumSides) + ",{" +
|
|
ToString( Point3d( ptCen)) + "},{" +
|
|
ToString( Point3d( ptMid)) + "},{" +
|
|
ToString( Vector3d( vtN)) + "}," +
|
|
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 ;
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
|
|
return GDB_ID_NULL ;
|
|
// porto in locale i punti, la normale e il versore estrusione
|
|
Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ;
|
|
Point3d ptFinL = GetPointLocal( pGeomDB, ptFin, nRefType, frLoc) ;
|
|
Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frLoc) ;
|
|
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX.v, nRefType, 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 ;
|
|
}
|