Files
EgtExecutor/EXE_GdbCreateCurve.cpp
T
Dario Sassi 2e254607d5 EgtExecutor 1.6n13 :
- piccola modifica a fori lungo percorso.
2016-03-08 14:25:41 +00:00

2402 lines
102 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 "EXE.h"
#include "EXE_Const.h"
#include "EXE_Macro.h"
#include "AuxTools.h"
#include "GeoTools.h"
#include "/EgtDev/Include/EXeExecutor.h"
#include "/EgtDev/Include/EXeConst.h"
#include "/EgtDev/Include/EgkCurveLine.h"
#include "/EgtDev/Include/EGkLinePntTgCurve.h"
#include "/EgtDev/Include/EGkLinePntPerpCurve.h"
#include "/EgtDev/Include/EGkLinePntMinDistCurve.h"
#include "/EgtDev/Include/EGkLineTgTwoCurves.h"
#include "/EgtDev/Include/EGkLinePerpTwoCurves.h"
#include "/EgtDev/Include/EGkLineTgCurvePerpCurve.h"
#include "/EgtDev/Include/EgkCurveArc.h"
#include "/EgtDev/Include/EgkCircleCenTgCurve.h"
#include "/EgtDev/Include/EgkArcSpecial.h"
#include "/EgtDev/Include/EgkArcPntDirTgCurve.h"
#include "/EgtDev/Include/EgkArcCenTgCurvePnt.h"
#include "/EgtDev/Include/EGkBiArcs.h"
#include "/EgtDev/Include/EgkFilletChamfer.h"
#include "/EgtDev/Include/EgkCurveBezier.h"
#include "/EgtDev/Include/EgkCurveComposite.h"
#include "/EgtDev/Include/EgkChainCurves.h"
#include "/EgtDev/Include/EGkCurveByInterp.h"
#include "/EgtDev/Include/EGkCurveByApprox.h"
#include "/EgtDev/Include/EgkOffsetCurve.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
ExeCreateLine( int nParentId, const Point3d& ptIni, const Point3d& ptFin, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, nRefType, frLoc) ;
// setto la linea
if ( ! pCrvLine->Set( ptIniL, ptFinL))
return GDB_ID_NULL ;
// assegno il versore estrusione
pCrvLine->SetExtrusion( vtExtrL) ;
// inserisco la linea nel DB
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvLine)) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtLine(" + IdToString( nParentId) + ",{" +
ToString( ptIni) + "},{" +
ToString( ptFin) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateLineEx( int nParentId, const Point3d& ptIni, int nSepI, int nIdI,
const Point3d& ptFin, int nSepF, int nIdF, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, nRefType, frLoc) ;
// 1 - se punti entrambi definiti
if ( nSepI == SEP_STD && nSepF == SEP_STD) {
pCrvLine.Set( CreateCurveLine()) ;
bOk = bOk && ! IsNull( pCrvLine) ;
bOk = bOk && pCrvLine->Set( ptIniL, ptFinL) ;
}
// 2 - se primo punto definito e secondo a minima distanza
else if ( nSepI == SEP_STD && nSepF == SEP_MINDIST) {
pCrvLine.Set( CreateLinePointMinDistCurve( pGeomDB, nParentId, ptIniL, ptFinL, nIdF)) ;
bOk = bOk && ! IsNull( pCrvLine) ;
}
// 3 - se primo punto a minima distanza e secondo definito
else if ( nSepI == SEP_MINDIST && nSepF == SEP_STD) {
pCrvLine.Set( CreateLinePointMinDistCurve( pGeomDB, nParentId, ptFinL, ptIniL, nIdI)) ;
bOk = bOk && ! IsNull( pCrvLine) ;
bOk = bOk && pCrvLine->Invert() ;
}
// 4 - se primo punto definito e secondo tangente
else if ( nSepI == SEP_STD && nSepF == SEP_TG) {
pCrvLine.Set( CreateLinePointTgCurve( pGeomDB, nParentId, ptIniL, ptFinL, nIdF)) ;
bOk = bOk && ! IsNull( pCrvLine) ;
}
// 5 - se primo punto tangente e secondo definito
else if ( nSepI == SEP_TG && nSepF == SEP_STD) {
// costruisco la curva al contrario e poi la inverto
pCrvLine.Set( CreateLinePointTgCurve( pGeomDB, nParentId, ptFinL, ptIniL, nIdI)) ;
bOk = bOk && ! IsNull( pCrvLine) ;
bOk = bOk && pCrvLine->Invert() ;
}
// 6 - se entrambi i punti tangenti
else if ( nSepI == SEP_TG && nSepF == SEP_TG) {
pCrvLine.Set( CreateLineTgTwoCurves( pGeomDB, nParentId, ptIniL, nIdI, ptFinL, nIdF)) ;
bOk = bOk && ! IsNull( pCrvLine) ;
}
// 7 - se primo punto definito e secondo perpendicolare
else if ( nSepI == SEP_STD && nSepF == SEP_PERP) {
pCrvLine.Set( CreateLinePointPerpCurve( pGeomDB, nParentId, ptIniL, ptFinL, nIdF)) ;
bOk = bOk && ! IsNull( pCrvLine) ;
}
// 8 - se primo punto perpendicolare e secondo definito
else if ( nSepI == SEP_PERP && nSepF == SEP_STD) {
// costruisco la curva al contrario e poi la inverto
pCrvLine.Set( CreateLinePointPerpCurve( pGeomDB, nParentId, ptFinL, ptIniL, nIdI)) ;
bOk = bOk && ! IsNull( pCrvLine) ;
bOk = bOk && pCrvLine->Invert() ;
}
// 9 - se entrambi i punti perpendicolari
else if ( nSepI == SEP_PERP && nSepF == SEP_PERP) {
pCrvLine.Set( CreateLinePerpTwoCurves( pGeomDB, nParentId, ptIniL, nIdI, ptFinL, nIdF)) ;
bOk = bOk && ! IsNull( pCrvLine) ;
}
// 10 - se primo punto tangente e secondo perpendicolare
else if ( nSepI == SEP_TG && nSepF == SEP_PERP) {
pCrvLine.Set( CreateLineTgCurvePerpCurve( pGeomDB, nParentId, ptIniL, nIdI, ptFinL, nIdF)) ;
bOk = bOk && ! IsNull( pCrvLine) ;
}
// 11 - se primo punto perpendicolare e secondo tangente
else if ( nSepI == SEP_PERP && nSepF == SEP_TG) {
// costruisco la curva al contrario e poi la inverto
pCrvLine.Set( CreateLineTgCurvePerpCurve( pGeomDB, nParentId, ptFinL, nIdF, ptIniL, nIdI)) ;
bOk = bOk && ! IsNull( pCrvLine) ;
bOk = bOk && pCrvLine->Invert() ;
}
// errore
else {
bOk = false ;
}
// assegno il versore estrusione
bOk = bOk && pCrvLine->SetExtrusion( vtExtrL) ;
// inserisco la linea nel DB
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvLine)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua ;
if ( nSepI == SEP_STD && nSepF == SEP_STD)
sLua = "EgtLine(" + IdToString( nParentId) + ",{" +
ToString( ptIni) + "},{" +
ToString( ptFin) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
else
sLua = "EgtLineEx(" + IdToString( nParentId) + ",{" +
ToString( ptIni) + "}," +
SepToString( nSepI) + "," +
ToString( nIdI) + ",{" +
ToString( ptFin) + "}," +
SepToString( nSepF) + "," +
ToString( nIdF) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
ICurveLine*
CreateLinePointTgCurve( IGeomDB* pGeomDB, int nParentId,
const Point3d& ptIni, const Point3d& ptFin, int nIdF)
{
// verifica preliminare Id curva
if ( nIdF == GDB_ID_NULL)
return nullptr ;
// recupero il riferimento del gruppo destinazione
Frame3d frDest ;
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frDest))
return nullptr ;
// recupero il riferimento della curva
Frame3d frCurve ;
if ( ! pGeomDB->GetGlobFrame( nIdF, frCurve))
return nullptr ;
// porto il punto iniziale nel riferimento della curva
Point3d ptSloc( ptIni) ;
ptSloc.LocToLoc( frDest, frCurve) ;
// porto il punto vicino al finale nel riferimento della curva
Point3d ptNloc( ptFin) ;
ptNloc.LocToLoc( frDest, frCurve) ;
// recupero la curva
const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nIdF)) ;
if ( pCurve == nullptr)
return false ;
// calcolo la retta tangente alla curva
PtrOwner<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, *Get( pCrv2Loc), 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, *Get(pCrv2Loc), 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, *Get( pCrv2Loc), 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
ExeCreateLinePDL( int nParentId, const Point3d& ptIni,
double dDirDeg, double dLen, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, FromPolar( 1, dDirDeg), nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, 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)) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtLinePDL(" + IdToString( nParentId) + ",{" +
ToString( ptIni) + "}," +
ToString( dDirDeg) + "," +
ToString( dLen) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateLinePVL( int nParentId, const Point3d& ptIni,
const Vector3d& vtDir, double dLen, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// recupero il riferimento locale
Frame3d frLoc ;
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
return GDB_ID_NULL ;
// porto in locale il punto e i versori
Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ;
Vector3d vtDirL = GetVectorLocal( pGeomDB, vtDir, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// creo la linea
PtrOwner<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)) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtLinePVL(" + IdToString( nParentId) + ",{" +
ToString( ptIni) + "},{" +
ToString( vtDir) + "}," +
ToString( dLen) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateLineMinPointCurve( int nParentId,
const Point3d& ptStart, int nCrvId, double dNearPar, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// recupero il riferimento locale
Frame3d frLoc ;
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
return GDB_ID_NULL ;
// porto in locale il punto e il versore estrusione
Point3d ptStartL = GetPointLocal( pGeomDB, ptStart, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// recupero il riferimento della curva
Frame3d frCurve ;
if ( ! pGeomDB->GetGlobFrame( nCrvId, frCurve))
return GDB_ID_NULL ;
// recupero la curva
const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ;
if ( pCurve == nullptr)
return GDB_ID_NULL ;
// porto il punto nel riferimento della curva
Point3d ptStartC = ptStart ;
ptStartC.LocToLoc( frLoc, frCurve) ;
// calcolo il punto a minima distanza
int nFlag ;
Point3d ptEndL ;
DistPointCurve dstPtCurve( ptStartC, *pCurve) ;
if ( ! dstPtCurve.GetMinDistPoint( dNearPar, ptEndL, nFlag))
return GDB_ID_NULL ;
// porto il punto finale nel riferimento di creazione
ptEndL.LocToLoc( frCurve, frLoc) ;
// creo la linea
PtrOwner<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)) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtLineMinPointCurve(" + IdToString( nParentId) + ",{" +
ToString( ptStart) + "}," +
ToString( nCrvId) + "," +
ToString( dNearPar) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCircle( int nParentId, const Point3d& ptCen, double dRad, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// setto la circonferenza
if ( ! pCrvArc->Set( ptCenL, vtNL, dRad))
return GDB_ID_NULL ;
// assegno il versore estrusione
pCrvArc->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCircle(" + IdToString( nParentId) + ",{" +
ToString( ptCen) + "}," +
ToString( dRad) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCircleCP( int nParentId, const Point3d& ptCen,
const Point3d& ptOn, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// calcolo il raggio
double dRad = (( ptOnL - ptCenL) ^ vtNL).Len() ;
// setto la circonferenza
bOk = bOk && pCrvArc->Set( ptCenL, vtNL, dRad) ;
// assegno il versore estrusione
bOk = bOk && pCrvArc->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCircleCP(" + IdToString( nParentId) + ",{" +
ToString( ptCen) + "},{" +
ToString( ptOn) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCircleCPEx( int nParentId, const Point3d& ptCen,
const Point3d& ptOn, int nSepO, int nIdO, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// se punto standard
if ( nSepO == SEP_STD) {
pCrvArc.Set( CreateCurveArc()) ;
bOk = bOk && ! IsNull( pCrvArc) ;
// calcolo il raggio
double dRad = (( ptOnL - ptCenL) ^ vtNL).Len() ;
// setto la circonferenza
bOk = bOk && pCrvArc->Set( ptCenL, vtNL, dRad) ;
}
// se punto di tangenza, determino il vero punto di passaggio
else if ( nSepO == SEP_TG) {
// recupero la curva di tangenza in locale
CurveLocal CrvTgLoc( pGeomDB, nIdO, frLoc) ;
// calcolo la circonferenza tangente a questa curva
pCrvArc.Set( GetCircleCenTgCurve( ptCenL, vtNL, *CrvTgLoc.Get(), ptOnL)) ;
bOk = bOk && ! IsNull( pCrvArc) ;
}
// altrimenti errore
else
bOk = false ;
// assegno il versore estrusione
bOk = bOk && pCrvArc->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCircleCPEx(" + IdToString( nParentId) + ",{" +
ToString( ptCen) + "},{" +
ToString( ptOn) + "}," +
SepToString( nSepO) + "," +
ToString( nIdO) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nNewId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCircle3P( int nParentId, const Point3d& ptP1,
const Point3d& ptP2, const Point3d& ptP3, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, nRefType, frLoc) ;
// setto l'arco
if ( ! pCrvArc->Set3P( ptP1L, ptP2L, ptP3L, true))
return GDB_ID_NULL ;
// assegno il versore estrusione
pCrvArc->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCircle3P(" + IdToString( nParentId) + ",{" +
ToString( ptP1) + "},{" +
ToString( ptP2) + "},{" +
ToString( ptP3) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateArc( int nParentId, const Point3d& ptCen, double dRad,
double dAngIniDeg, double dAngCenDeg, double dDeltaN, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, Z_AX, nRefType, frLoc) ;
Vector3d vtSL = GetVectorLocal( pGeomDB, FromPolar( 1, dAngIniDeg), nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// setto l'arco
if ( ! pCrvArc->Set( ptCenL, vtNL, dRad, vtSL, dAngCenDeg, dDeltaN))
return GDB_ID_NULL ;
// assegno il versore estrusione
pCrvArc->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtArc(" + IdToString( nParentId) + ",{" +
ToString( ptCen) + "}," +
ToString( dRad) + "," +
ToString( dAngIniDeg) + "," +
ToString( dAngCenDeg) + "," +
ToString( dDeltaN) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateArcCPA( int nParentId, const Point3d& ptCen, const Point3d& ptStart,
double dAngCenDeg, double dDeltaN, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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) ;
Vector3d vtNL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// setto l'arco
if ( ! pCrvArc->SetCPAN( ptCenL, ptStartL, dAngCenDeg, dDeltaN, vtNL))
return GDB_ID_NULL ;
// assegno il versore estrusione
pCrvArc->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtArcCPA(" + IdToString( nParentId) + ",{" +
ToString( ptCen) + "},{" +
ToString( ptStart) + "}," +
ToString( dAngCenDeg) + "," +
ToString( dDeltaN) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateArcC2P( int nParentId, const Point3d& ptCen, const Point3d& ptStart,
const Point3d& ptNearEnd, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// setto l'arco
if ( ! pCrvArc->SetC2PN( ptCenL, ptStartL, ptNearEndL, vtNormL))
return GDB_ID_NULL ;
// assegno il versore estrusione
pCrvArc->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtArcC2P(" + IdToString( nParentId) + ",{" +
ToString( ptCen) + "},{" +
ToString( ptStart) + "},{" +
ToString( ptNearEnd) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateArcC2PEx( int nParentId, const Point3d& ptCen,
const Point3d& ptStart, int nSepS, int nIdS,
const Point3d& ptNearEnd, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// se punto standard
if ( nSepS == SEP_STD) {
pCrvArc.Set( CreateCurveArc()) ;
bOk = bOk && ! IsNull( pCrvArc) ;
// setto l'arco
if ( ! pCrvArc->SetC2PN( ptCenL, ptStartL, ptNearEndL, vtNormL))
return GDB_ID_NULL ;
}
// se punto di tangenza, determino il vero punto di passaggio
else if ( nSepS == SEP_TG) {
// recupero la curva di tangenza in locale
CurveLocal CrvTgLoc( pGeomDB, nIdS, frLoc) ;
// calcolo l'arco tangente a questa curva
pCrvArc.Set( GetArcCenTgCurvePnt( ptCenL, *CrvTgLoc.Get(), ptStartL, ptNearEndL, vtNormL)) ;
bOk = bOk && ! IsNull( pCrvArc) ;
}
// altrimenti errore
else
bOk = false ;
// assegno il versore estrusione
bOk = bOk && pCrvArc->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtArcC2PEx(" + IdToString( nParentId) + ",{" +
ToString( ptCen) + "},{" +
ToString( ptStart) + "}," +
SepToString( nSepS) + "," +
ToString( nIdS) + ",{" +
ToString( ptNearEnd) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nNewId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateArc3P( int nParentId, const Point3d& ptP1,
const Point3d& ptP2, const Point3d& ptP3, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, 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) ;
// se arco, verifico che normale al suo piano e versore estrusione non siano controversi
if ( bOk && pCrv->GetType() == CRV_ARC) {
ICurveArc* pArc = GetCurveArc( Get( pCrv)) ;
if ( ( pArc->GetNormVersor() * vtExtrL) < 0)
pArc->InvertN() ;
}
// inserisco l'arco nel DB
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrv)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtArc3P(" + IdToString( nParentId) + ",{" +
ToString( ptP1) + "},{" +
ToString( ptP2) + "},{" +
ToString( ptP3) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateArc2PD( int nParentId, const Point3d& ptStart, const Point3d& ptEnd,
double dDirSDeg, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, il versore iniziale, quello normale e il versore estrusione
Point3d ptStartL = GetPointLocal( pGeomDB, ptStart, nRefType, frLoc) ;
Point3d ptEndL = GetPointLocal( pGeomDB, ptEnd, nRefType, frLoc) ;
Vector3d vtDirSL = GetVectorLocal( pGeomDB, FromPolar( 1, dDirSDeg), nRefType, frLoc) ;
Vector3d vtNormL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// setto l'arco
pCrv.Set( GetArc2PVN( ptStartL, ptEndL, vtDirSL, vtNormL)) ;
bOk = bOk && ! IsNull( pCrv) ;
// assegno il versore estrusione
bOk = bOk && pCrv->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrv)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtArc2PD(" + IdToString( nParentId) + ",{" +
ToString( ptStart) + "},{" +
ToString( ptEnd) + "}," +
ToString( dDirSDeg) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateArc2PDEx( int nParentId, const Point3d& ptStart,
const Point3d& ptEnd, int nSep, int nId,
double dDirSDeg, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, FromPolar( 1, dDirSDeg), nRefType, frLoc) ;
Vector3d vtNormL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// se punto standard
if ( nSep == SEP_STD) {
// creo l'arco
pCrv.Set( CreateCurveArc()) ;
bOk = bOk && ! IsNull( pCrv) ;
if ( bOk) {
// imposto l'arco
if ( (dynamic_cast<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) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtArc2PDEx(" + IdToString( nParentId) + ",{" +
ToString( ptStart) + "},{" +
ToString( ptEnd) + "}," +
SepToString( nSep) + "," +
ToString( nId) + "," +
ToString( dDirSDeg) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nNewId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateArc2PV( int nParentId, const Point3d& ptStart, const Point3d& ptEnd,
const Vector3d& vtDirS, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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, il versore iniziale 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 vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// calcolo la normale locale
Vector3d vtNormL = vtDirSL ^ ( ptEndL - ptStartL) ;
if ( vtNormL.Normalize()) {
if ( vtNormL.z < 0)
vtNormL.Invert() ;
}
else
vtNormL = Z_AX ;
// setto l'arco
pCrv.Set( GetArc2PVN( ptStartL, ptEndL, vtDirSL, vtNormL)) ;
bOk = bOk && ! IsNull( pCrv) ;
// assegno il versore estrusione
bOk = bOk && pCrv->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrv)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtArc2PV(" + IdToString( nParentId) + ",{" +
ToString( ptStart) + "},{" +
ToString( ptEnd) + "},{" +
ToString( vtDirS) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateBiArc( int nParentId, const Point3d& ptStart, const Point3d& ptEnd,
double dDirSDeg, double dDirEDeg, double dPar, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// costruisco il biarco direttamente nel piano specificato
PtrOwner<ICurve> pBiArc( GetBiArc( ptStart, dDirSDeg, ptEnd, dDirEDeg, dPar)) ;
bool bOk = ! IsNull( pBiArc) ;
// recupero il riferimento locale
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
// se necessario, porto il biarco nel riferimento locale
if ( nRefType == RTY_GLOB)
bOk = bOk && pBiArc->ToLoc( frLoc) ;
else if ( nRefType == RTY_GRID)
bOk = bOk && pBiArc->LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
// assegno il versore estrusione
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
bOk = bOk && pBiArc->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pBiArc)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtBiArc(" + IdToString( nParentId) + ",{" +
ToString( ptStart) + "},{" +
ToString( ptEnd) + "}," +
ToString( dDirSDeg) + "," +
ToString( dDirEDeg) + "," +
ToString( dPar) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCurveFillet( int nParentId, int nCrv1, const Point3d& ptNear1,
int nCrv2, const Point3d& ptNear2,
double dRad, bool bTrim, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// creo l'arco
PtrOwner<ICurveArc> pArc ;
bool bOk = true ;
// recupero il riferimento locale
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
// porto in locale i punti, i versori e il versore estrusione
Point3d ptNear1L = GetPointLocal( pGeomDB, ptNear1, nRefType, frLoc) ;
Point3d ptNear2L = GetPointLocal( pGeomDB, ptNear2, nRefType, frLoc) ;
Vector3d vtNormL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// recupero la copia locale delle curve
CurveLocal CrvLoc1( pGeomDB, nCrv1, frLoc) ;
CurveLocal CrvLoc2( pGeomDB, nCrv2, frLoc) ;
// calcolo il raccordo
double dTrim1, dTrim2 ;
pArc.Set( CreateFillet( *CrvLoc1.Get(), ptNear1L, *CrvLoc2.Get(), ptNear2L, vtNormL, dRad, dTrim1, dTrim2)) ;
bOk = bOk && ! IsNull( pArc) ;
// assegno il versore estrusione
bOk = bOk && pArc->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pArc)) : GDB_ID_NULL) ;
// se richiesto trim
if ( nNewId != GDB_ID_NULL && bTrim) {
// recupero e aggiusto la prima curva
ICurve* pCrv1 = GetCurve( pGeomDB->GetGeoObj( nCrv1)) ;
if ( dTrim1 > EPS_ZERO)
pCrv1->TrimStartAtParam( dTrim1) ;
else if ( dTrim1 < - EPS_ZERO)
pCrv1->TrimEndAtParam( fabs( dTrim1)) ;
// recupero e aggiusto la seconda curva
ICurve* pCrv2 = GetCurve( pGeomDB->GetGeoObj( nCrv2)) ;
if ( dTrim2 > EPS_ZERO)
pCrv2->TrimStartAtParam( dTrim2) ;
else if ( dTrim2 < - EPS_ZERO)
pCrv2->TrimEndAtParam( fabs( dTrim2)) ;
}
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCurveFillet(" + IdToString( nParentId) + "," +
ToString( nCrv1) + ",{" +
ToString( ptNear1) + "}," +
ToString( nCrv2) + ",{" +
ToString( ptNear2) + "}," +
ToString( dRad) + "," +
( bTrim ? "true" : "false") + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
return nNewId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCurveChamfer( int nParentId, int nCrv1, const Point3d& ptNear1,
int nCrv2, const Point3d& ptNear2,
double dDist, bool bTrim, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// creo la linea
PtrOwner<ICurveLine> pLine ;
bool bOk = true ;
// recupero il riferimento locale
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ;
// porto in locale i punti, i versori e il versore estrusione
Point3d ptNear1L = GetPointLocal( pGeomDB, ptNear1, nRefType, frLoc) ;
Point3d ptNear2L = GetPointLocal( pGeomDB, ptNear2, nRefType, frLoc) ;
Vector3d vtNormL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// recupero la copia locale delle curve
CurveLocal CrvLoc1( pGeomDB, nCrv1, frLoc) ;
CurveLocal CrvLoc2( pGeomDB, nCrv2, frLoc) ;
// calcolo lo smusso
double dTrim1, dTrim2 ;
pLine.Set( CreateChamfer( *CrvLoc1.Get(), ptNear1L, *CrvLoc2.Get(), ptNear2L, vtNormL, dDist, dTrim1, dTrim2)) ;
bOk = bOk && ! IsNull( pLine) ;
// assegno il versore estrusione
bOk = bOk && pLine->SetExtrusion( vtExtrL) ;
// inserisco l'arco nel DB
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pLine)) : GDB_ID_NULL) ;
// se richiesto trim
if ( nNewId != GDB_ID_NULL && bTrim) {
// recupero e aggiusto la prima curva
ICurve* pCrv1 = GetCurve( pGeomDB->GetGeoObj( nCrv1)) ;
if ( dTrim1 > EPS_ZERO)
pCrv1->TrimStartAtParam( dTrim1) ;
else if ( dTrim1 < - EPS_ZERO)
pCrv1->TrimEndAtParam( fabs( dTrim1)) ;
// recupero e aggiusto la seconda curva
ICurve* pCrv2 = GetCurve( pGeomDB->GetGeoObj( nCrv2)) ;
if ( dTrim2 > EPS_ZERO)
pCrv2->TrimStartAtParam( dTrim2) ;
else if ( dTrim2 < - EPS_ZERO)
pCrv2->TrimEndAtParam( fabs( dTrim2)) ;
}
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCurveChamfer(" + IdToString( nParentId) + "," +
ToString( nCrv1) + ",{" +
ToString( ptNear1) + "}," +
ToString( nCrv2) + ",{" +
ToString( ptNear2) + "}," +
ToString( dDist) + "," +
( bTrim ? "true" : "false") + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nNewId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
return nNewId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCurveBezier( int nParentId, int nDegree, const PNTVECTOR& vPnt, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
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], nRefType, frLoc) ;
// inserimento del punto di controllo
if ( ! pCrvBez->SetControlPoint( i, ptCtrl))
bOk = false ;
}
// se curva nulla (ovvero ridotta a punto), errore
bOk = bOk && ! pCrvBez->IsAPoint() ;
// assegno il versore estrusione
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
pCrvBez->SetExtrusion( vtExtrL) ;
// inserisco la curva nel DB
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvBez)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sPC ;
for ( size_t i = 0 ; i < vPnt.size() ; ++ i) {
if ( i > 0)
sPC += "," ;
sPC += "{" + ToString( vPnt[i]) + "}" ;
}
string sLua = "EgtCurveBezier(" + IdToString( nParentId) + "," +
ToString( nDegree) + ",{" +
sPC + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCurveBezierRational( int nParentId, int nDegree, const PNTUVECTOR& vPntW, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
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, nRefType, frLoc) ;
// inserimento del punto di controllo con peso
if ( ! pCrvBez->SetControlPoint( i, ptCtrl, vPntW[i].second))
return GDB_ID_NULL ;
}
// se curva nulla (ovvero ridotta a punto), errore
bOk = bOk && ! pCrvBez->IsAPoint() ;
// assegno il versore estrusione
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
pCrvBez->SetExtrusion( vtExtrL) ;
// inserisco la curva nel DB
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvBez)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sPC ;
for ( size_t i = 0 ; i < vPntW.size() ; ++ i) {
if ( i > 0)
sPC += "," ;
sPC += "{" + ToString( vPntW[i].first, vPntW[i].second) + "}" ;
}
string sLua = "EgtCurveBezierRat(" + IdToString( nParentId) + "," +
ToString( nDegree) + ",{" +
sPC + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCurveBezierFromArc( int nParentId, int nArcId, bool bErase)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
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 ;
}
}
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCurveBezierFromArc(" + IdToString( nParentId) + "," +
ToString( nArcId) + "," +
( bErase ? "true" : "false") + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
MyCreateCurveCompo( int nParentId, const INTVECTOR& vIds, bool bErase)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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)) ;
ExeSetModified() ;
// se ok e richiesto, cancello le curve originali
if ( nId != GDB_ID_NULL && bErase) {
for ( Iter = vIds.begin() ; Iter != vIds.end() ; ++Iter) {
if ( ! pGeomDB->Erase( *Iter))
return GDB_ID_NULL ;
}
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCurveCompo( int nParentId, const INTVECTOR& vIds, bool bErase)
{
// eseguo
int nId = MyCreateCurveCompo( nParentId, vIds, bErase) ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCurveCompo(" + IdToString( nParentId) + ",{" +
IdListToString( vIds) + "}," +
( bErase ? "true" : "false") + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
static int
MyCreateCurveCompoByChain( int nParentId, const INTVECTOR& vIds,
const Point3d& ptNear, bool bAllowInvert, bool bErase, int nRefType, int* pnCount)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// 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( bAllowInvert, dToler, int( vIds.size())) ;
for ( size_t i = 0 ; i < vIds.size() ; ++ i) {
int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ;
while ( nId != GDB_ID_NULL) {
// recupero la curva e il suo riferimento
ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ;
if ( pCrv == nullptr)
return GDB_ID_NULL ;
Frame3d frCrv ;
if ( ! pGeomDB->GetGlobFrame( nId, frCrv))
return GDB_ID_NULL ;
// recupero i dati della curva necessari al concatenamento e li assegno
Point3d ptStart, ptEnd ;
Vector3d vtStart, vtEnd ;
if ( ! pCrv->GetStartPoint( ptStart) || ! pCrv->GetStartDir( vtStart) ||
! pCrv->GetEndPoint( ptEnd) || ! pCrv->GetEndDir( vtEnd))
return GDB_ID_NULL ;
ptStart.LocToLoc( frCrv, frDest) ;
vtStart.LocToLoc( frCrv, frDest) ;
ptEnd.LocToLoc( frCrv, frDest) ;
vtEnd.LocToLoc( frCrv, frDest) ;
if ( ! chainC.AddCurve( nId, ptStart, vtStart, ptEnd, vtEnd))
return GDB_ID_NULL ;
// passo al successivo
nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ;
}
}
// recupero i percorsi concatenati
int nFirstId = GDB_ID_NULL ;
int nCount = 0 ;
Point3d ptNearL = GetPointLocal( pGeomDB, ptNear, nRefType, frDest) ;
INTVECTOR vId2s ;
while ( chainC.GetChainFromNear( ptNearL, false, vId2s)) {
// creo una curva composita
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
if ( IsNull( pCrvCompo))
return GDB_ID_NULL ;
// estrusione e spessore
Vector3d vtExtr = CalcExtrusion( pGeomDB, nParentId, nRefType) ;
double dThick = 0 ;
// vettore con elenco Id curve originali
INTVECTOR vOrig ;
// 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) ;
vOrig.push_back( nId) ;
// 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->GetCurveCount() == 0)
continue ;
// se curva chiusa entro la tolleranza di concatenamento ma considerata aperta, la chiudo bene
Point3d ptStart, ptEnd ;
if ( pCrvCompo->GetStartPoint( ptStart) &&
pCrvCompo->GetEndPoint( ptEnd) &&
AreSamePointEpsilon( ptStart, ptEnd, dToler) &&
! AreSamePointApprox( ptStart, ptEnd)) {
// porto il punto finale a coincidere esattamente con l'inizio
pCrvCompo->ModifyEnd( ptStart) ;
}
// imposto estrusione e spessore
pCrvCompo->SetExtrusion( vtExtr) ;
pCrvCompo->SetThickness( dThick) ;
// aggiorno il nuovo punto vicino
pCrvCompo->GetEndPoint( ptNearL) ;
// inserisco la curva composita nel gruppo destinazione
int nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, ::Release( pCrvCompo)) ;
if ( nNewId == GDB_ID_NULL)
return GDB_ID_NULL ;
if ( nFirstId == GDB_ID_NULL)
nFirstId = nNewId ;
++ nCount ;
// assegno nota con curve originali
if ( ! bErase)
pGeomDB->SetInfo( nNewId, "ORIG", vOrig) ;
}
// se richiesto e ok, cancello le curve originali
if ( bErase && nFirstId != GDB_ID_NULL) {
for ( size_t i = 0 ; i < vIds.size() ; ++ i) {
int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ;
while ( nId != GDB_ID_NULL) {
pGeomDB->Erase( nId) ;
// passo al successivo
nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetFirstSelectedObj()) ;
}
}
}
// restituisco l'identificativo della prima nuova entità
if ( pnCount != nullptr)
*pnCount = nCount ;
return nFirstId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCurveCompoByChain( int nParentId, const INTVECTOR& vIds,
const Point3d& ptNear, bool bErase, int nRefType, int* pnCount)
{
// eseguo
int nCount = 0 ;
int nFirstId = MyCreateCurveCompoByChain( nParentId, vIds, ptNear, true, bErase, nRefType, &nCount) ;
if ( pnCount != nullptr)
*pnCount = nCount ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCurveCompoByChain(" + IdToString( nParentId) + ",{" +
IdListToString( vIds) + "},{" +
ToString( ptNear) + "}," +
( bErase ? "true" : "false") + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della prima nuova entità
return nFirstId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCurveCompoByReorder( int nParentId, const INTVECTOR& vIds,
const Point3d& ptNear, bool bErase, int nRefType, int* pnCount)
{
// eseguo
int nCount = 0 ;
int nFirstId = MyCreateCurveCompoByChain( nParentId, vIds, ptNear, false, bErase, nRefType, &nCount) ;
if ( pnCount != nullptr)
*pnCount = nCount ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCurveCompoByReorder(" + IdToString( nParentId) + ",{" +
IdListToString( vIds) + "},{" +
ToString( ptNear) + "}," +
( bErase ? "true" : "false") + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della prima nuova entità
return nFirstId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCurveCompoByInterpolation( int nParentId, const PolyLine& PL, int nType, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento del gruppo destinazione
Frame3d frDest ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frDest) ;
// assegno metodo di interpolazione e tipo del risultato
int nMethod = CurveByInterp::AKIMA_CORNER ;
int nCrvType = CurveByInterp::BIARCS ;
if ( nType == ITT_ARCS) {
nMethod = CurveByInterp::AKIMA ;
nCrvType = CurveByInterp::BIARCS ;
}
else if ( nType == ITT_CUBICS) {
nMethod = CurveByInterp::BESSEL ;
nCrvType = CurveByInterp::CUBIC_BEZIERS ;
}
// oggetto interpolatore
CurveByInterp crvByInterp ;
Point3d ptP ;
for ( bool bFound = PL.GetFirstPoint( ptP) ;
bFound ;
bFound = PL.GetNextPoint( ptP))
crvByInterp.AddPoint( ptP) ;
PtrOwner<ICurve> pCrvCompo( crvByInterp.GetCurve( nMethod, nType)) ;
bOk = bOk && ! IsNull( pCrvCompo) ;
// assegno il versore estrusione
bOk = bOk && pCrvCompo->SetExtrusion( Z_AX) ;
// eventuale trasformazione per riferimento di espressione dei punti
if ( bOk && nRefType == RTY_GLOB)
pCrvCompo->ToLoc( frDest) ;
else if ( bOk && nRefType == RTY_GRID)
pCrvCompo->LocToLoc( pGeomDB->GetGridFrame(), frDest) ;
// inserisco la curva composita nel DB
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sPnt ;
Point3d ptP ;
if ( PL.GetFirstPoint( ptP))
sPnt += "{" + ToString( ptP) + "}" ;
while ( PL.GetNextPoint( ptP))
sPnt += ",{" + ToString( ptP) + "}" ;
string sLua = "EgtCurveCompoByInterpolation(" + IdToString( nParentId) + ",{" +
sPnt + "}," +
InterpTypeToString( nType) +"," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCurveCompoByApproximation( int nParentId, const PolyLine& PL, int nType, double dLinTol, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento del gruppo destinazione
Frame3d frDest ;
bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frDest) ;
// eseguo approssimazione
const double ANG_TOL_STD_DEG = 15 ;
const double LIN_FEA_STD = 20 ;
CurveByApprox crvByApprox ;
Point3d ptP ;
for ( bool bFound = PL.GetFirstPoint( ptP) ;
bFound ;
bFound = PL.GetNextPoint( ptP))
crvByApprox.AddPoint( ptP) ;
PtrOwner<ICurve> pCrvCompo( crvByApprox.GetCurve( nType, dLinTol, ANG_TOL_STD_DEG, LIN_FEA_STD)) ;
bOk = bOk && ! IsNull( pCrvCompo) ;
// assegno il versore estrusione
bOk = bOk && pCrvCompo->SetExtrusion( Z_AX) ;
// eventuale trasformazione per riferimento di espressione dei punti
if ( bOk && nRefType == RTY_GLOB)
pCrvCompo->ToLoc( frDest) ;
else if ( bOk && nRefType == RTY_GRID)
pCrvCompo->LocToLoc( pGeomDB->GetGridFrame(), frDest) ;
// inserisco la curva composita nel DB
int nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) : GDB_ID_NULL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sPnt ;
Point3d ptP ;
if ( PL.GetFirstPoint( ptP))
sPnt += "{" + ToString( ptP) + "}" ;
while ( PL.GetNextPoint( ptP))
sPnt += ",{" + ToString( ptP) + "}" ;
string sLua = "EgtCurveCompoByApproximation(" + IdToString( nParentId) + ",{" +
sPnt + "}," +
InterpTypeToString( nType) + "," +
ToString( dLinTol) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCurveCompoFromPoints( int nParentId, const PolyLine& PL, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
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) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sPnt ;
Point3d ptP ;
if ( PL.GetFirstPoint( ptP))
sPnt += "{" + ToString( ptP) + "}" ;
while ( PL.GetNextPoint( ptP))
sPnt += ",{" + ToString( ptP) + "}" ;
string sLua = "EgtCurveCompoFromPoints(" + IdToString( nParentId) + ",{" +
sPnt + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCurveCompoFromPointBulges( int nParentId, const PolyArc& PA, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
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) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sPnt ;
double dB ;
Point3d ptP ;
if ( PA.GetFirstPoint( ptP, dB))
sPnt += "{" + ToString( ptP) + "," + ToString( dB) + "}" ;
while ( PA.GetNextPoint( ptP, dB))
sPnt += ",{" + ToString( ptP) + "," + ToString( dB) + "}" ;
string sLua = "EgtCurveCompoFromPointBulges(" + IdToString( nParentId) + ",{" +
sPnt + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateRectangle2P( int nParentId, const Point3d& ptIni,
const Point3d& ptCross, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento locale
Frame3d frLoc ;
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
return GDB_ID_NULL ;
// porto in locale i punti e il versore estrusione
Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ;
Point3d ptCrossL = GetPointLocal( pGeomDB, ptCross, nRefType, frLoc) ;
Vector3d vtDirXL = GetVectorLocal( pGeomDB, X_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// calcolo il lato ( XL o YL per avere senso CCW)
Vector3d vtLatoL = (( ptCrossL - ptIniL) * vtDirXL) * vtDirXL ;
if ( ( vtLatoL ^ ( ptCrossL - ptIniL)) * vtExtrL < - EPS_SMALL)
vtLatoL = ( ptCrossL - ptIniL) - vtLatoL ;
// creo la polilinea con i punti
int nId = GDB_ID_NULL ;
if ( bOk) {
PolyLine PL ;
PL.AddUPoint( 0, ptIniL) ;
PL.AddUPoint( 1, Point3d( ptIniL) + vtLatoL) ;
PL.AddUPoint( 2, ptCrossL) ;
PL.AddUPoint( 3, Point3d( ptCrossL) - vtLatoL) ;
PL.AddUPoint( 4, ptIniL) ;
// creo la curva e la inserisco nel GDB
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( vtExtrL) ;
// inserisco la curva composita nel DB
nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) : GDB_ID_NULL) ;
ExeSetModified() ;
}
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtRectangle2P(" + IdToString( nParentId) + ",{" +
ToString( ptIni) + "},{" +
ToString( ptCross) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateRectangle3P( int nParentId, const Point3d& ptIni,
const Point3d& ptCross, const Point3d& ptDir, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento locale
Frame3d frLoc ;
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
return GDB_ID_NULL ;
// porto in locale i punti, i versori e il versore estrusione
Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ;
Point3d ptCrossL = GetPointLocal( pGeomDB, ptCross, nRefType, frLoc) ;
Point3d ptDirL = GetPointLocal( pGeomDB, ptDir, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
// calcolo il lato X
Vector3d vtDirXL = ptDirL - ptIniL ;
bOk = bOk && vtDirXL.Normalize() ;
Vector3d vtLatoL = bOk ? (( ptCrossL - ptIniL) * vtDirXL) * vtDirXL : V_NULL ;
if ( ( vtLatoL ^ ( ptCrossL - ptIniL)) * vtExtrL < - EPS_SMALL)
vtLatoL = ( ptCrossL - ptIniL) - vtLatoL ;
// creo la polilinea con i punti
int nId = GDB_ID_NULL ;
if ( bOk) {
PolyLine PL ;
PL.AddUPoint( 0, ptIniL) ;
PL.AddUPoint( 1, Point3d( ptIniL) + vtLatoL) ;
PL.AddUPoint( 2, ptCrossL) ;
PL.AddUPoint( 3, Point3d( ptCrossL) - vtLatoL) ;
PL.AddUPoint( 4, ptIniL) ;
// creo la curva e la inserisco nel GDB
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( vtExtrL) ;
// inserisco la curva composita nel DB
nId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) : GDB_ID_NULL) ;
ExeSetModified() ;
}
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtRectangle3P(" + IdToString( nParentId) + ",{" +
ToString( ptIni) + "},{" +
ToString( ptCross) + "},{" +
ToString( ptDir) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreatePolygonFromRadius( int nParentId, int nNumSides, const Point3d& ptCen,
const Point3d& ptCorn, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento locale
Frame3d frLoc ;
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
return GDB_ID_NULL ;
// porto in locale i punti, la normale e il versore estrusione
Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ;
Point3d ptCornL = GetPointLocal( pGeomDB, ptCorn, nRefType, frLoc) ;
Vector3d vtNL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, 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) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtPolygonFromRadius(" + IdToString( nParentId) + "," +
ToString( nNumSides) + ",{" +
ToString( ptCen) + "},{" +
ToString( ptCorn) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreatePolygonFromApothem( int nParentId, int nNumSides, const Point3d& ptCen,
const Point3d& ptMid, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento locale
Frame3d frLoc ;
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
return GDB_ID_NULL ;
// porto in locale i punti, la normale e il versore estrusione
Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ;
Point3d ptMidL = GetPointLocal( pGeomDB, ptMid, nRefType, frLoc) ;
Vector3d vtNL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, 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) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtPolygonFromApothem(" + IdToString( nParentId) + "," +
ToString( nNumSides) + ",{" +
ToString( ptCen) + "},{" +
ToString( ptMid) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
int
ExeCreatePolygonFromSide( int nParentId, int nNumSides, const Point3d& ptIni,
const Point3d& ptFin, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
bool bOk = true ;
// recupero il riferimento locale
Frame3d frLoc ;
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
return GDB_ID_NULL ;
// porto in locale i punti, la normale e il versore estrusione
Point3d ptIniL = GetPointLocal( pGeomDB, ptIni, nRefType, frLoc) ;
Point3d ptFinL = GetPointLocal( pGeomDB, ptFin, nRefType, frLoc) ;
Vector3d vtNL = GetVectorLocal( pGeomDB, Z_AX, nRefType, frLoc) ;
Vector3d vtExtrL = GetVectorLocal( pGeomDB, Z_AX, 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) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtPolygonFromSide(" + IdToString( nParentId) + "," +
ToString( nNumSides) + ",{" +
ToString( ptIni) + "},{" +
ToString( ptFin) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Id=" + ToString( nId) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della nuova entità
return nId ;
}
//-------------------------------------------------------------------------------
static int
MyCreateCirclesAlongCurve( int nParentId, int nCrvId, double dOffset, double dOverlap,
double dStartAdd, double dEndAdd, double dDiam, int* pnCount)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
nParentId = AdjustId( nParentId) ;
// verifico i parametri
if ( dDiam <= EPS_SMALL || ( dDiam - dOverlap) <= EPS_SMALL)
return GDB_ID_NULL ;
// recupero il riferimento della curva
Frame3d frCrv ;
if ( ! pGeomDB->GetGlobFrame( nCrvId, frCrv))
return GDB_ID_NULL ;
// recupero il riferimento di destinazione
Frame3d frLoc ;
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frLoc))
return GDB_ID_NULL ;
// recupero la curva
const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ;
if ( pCurve == nullptr)
return GDB_ID_NULL ;
// recupero il vettore estrusione della curva e lo porto in locale al gruppo destinazione
Vector3d vtExtr ;
pCurve->GetExtrusion( vtExtr) ;
vtExtr.LocToLoc( frCrv, frLoc) ;
// ne faccio una copia
PtrOwner<ICurve> pCopy( pCurve->Clone()) ;
if ( IsNull( pCopy))
return GDB_ID_NULL ;
// allungo/accorcio gli estremi come indicato
if ( dStartAdd < - EPS_SMALL) {
if ( ! pCopy->TrimStartAtLen( - dStartAdd))
return GDB_ID_NULL ;
}
else if ( dStartAdd > EPS_SMALL) {
if ( ! pCopy->ExtendStartByLen( dStartAdd))
return GDB_ID_NULL ;
}
if ( dEndAdd < - EPS_SMALL) {
double dCrvLen ;
if ( ! pCopy->GetLength( dCrvLen) || ! pCopy->TrimEndAtLen( dCrvLen + dEndAdd))
return GDB_ID_NULL ;
}
else if ( dEndAdd > EPS_SMALL) {
if ( ! pCopy->ExtendEndByLen( dEndAdd))
return GDB_ID_NULL ;
}
// eseguo l'offset
OffsetCurve OffsCrv ;
if ( ! OffsCrv.Make( Get( pCopy), dOffset, ICurve::OFF_FILLET))
return GDB_ID_NULL ;
// ciclo sulle curve di offset
int nCount = 0 ;
int nFirstId = GDB_ID_NULL ;
PtrOwner<ICurve> pOffs( OffsCrv.GetCurve()) ;
while ( ! IsNull( pOffs)) {
// ne determino la lunghezza
double dTotLen = 0 ;
pOffs->GetLength( dTotLen) ;
// calcolo il numero di circonferenze
int nCirc = 0 ;
double dStep = 0 ;
if ( dTotLen - dDiam >= 0) {
nCirc = int( ( dTotLen - dDiam) / ( dDiam - dOverlap) + 0.9) ;
// determino lo step corretto
dStep = (( nCirc > 0) ? ( dTotLen - dDiam) / nCirc : 0) ;
// aggiungo le due mezze circonferenze all'estremità
++ nCirc ;
}
else if ( dTotLen - 0.5 * dDiam >= 0)
nCirc = 1 ;
// calcolo le circonferenze
double dLen = min( 0.5 * dDiam, 0.5 * dTotLen) ;
for ( int i = 0 ; i < nCirc ; ++ i) {
// determino il centro della circonferenza
double dU ;
Point3d ptCen ;
if ( ! pOffs->GetParamAtLength( dLen, dU) ||
! pOffs->GetPointD1D2( dU, ICurve::FROM_MINUS, ptCen))
return GDB_ID_NULL ;
// lo porto in locale al gruppo destinazione
ptCen.LocToLoc( frCrv, frLoc) ;
// creo e inizializzo la circonferenza
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
if ( IsNull( pCrvArc) || ! pCrvArc->Set( ptCen, vtExtr, dDiam / 2))
return GDB_ID_NULL ;
// assegno il versore estrusione
pCrvArc->SetExtrusion( vtExtr) ;
// inserisco l'arco nel DB
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
if ( nId == GDB_ID_NULL)
return GDB_ID_NULL ;
if ( nFirstId == GDB_ID_NULL)
nFirstId = nId ;
++ nCount ;
// incremento la posizione lungo la curva
dLen += dStep ;
}
// passo alla curva successiva
pOffs.Set( OffsCrv.GetCurve()) ;
}
// restituisco l'identificativo della prima nuova entità
if ( pnCount != nullptr)
*pnCount = nCount ;
return nFirstId ;
}
//-------------------------------------------------------------------------------
int
ExeCreateCirclesAlongCurve( int nParentId, int nCrvId, double dOffset, double dOverlap,
double dStartAdd, double dEndAdd, double dDiam, int* pnCount)
{
// eseguo
int nCount = 0 ;
int nFirstId = MyCreateCirclesAlongCurve( nParentId, nCrvId, dOffset, dOverlap,
dStartAdd, dEndAdd, dDiam, &nCount) ;
if ( pnCount != nullptr)
*pnCount = nCount ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCreateCirclesAlongCurve(" + IdToString( nParentId) + "," +
IdToString( nCrvId) + "," +
ToString( dOffset) + "," +
ToString( dOverlap) + "," +
ToString( dStartAdd) + "," +
ToString( dEndAdd) + "," +
ToString( dDiam) + ")" +
" -- Id=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della prima nuova entità
return nFirstId ;
}
//-------------------------------------------------------------------------------
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 ;
}