50b2d271ac
- aggiunto interprete Lua - portate in interfaccia API molte funzioni di base.
658 lines
25 KiB
C++
658 lines
25 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : API_GdbCreate.cpp Data : 30.09.14 Versione : 1.5i5
|
|
// Contenuto : Funzioni di creazione oggetti del DB geometrico per API.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 30.09.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "API.h"
|
|
#include "API_Macro.h"
|
|
#include "/EgtDev/Include/EInAPI.h"
|
|
#include "/EgtDev/Include/EgkGeoPoint3d.h"
|
|
#include "/EgtDev/Include/EgkGeoVector3d.h"
|
|
#include "/EgtDev/Include/EgkCurveLine.h"
|
|
#include "/EgtDev/Include/EgkCurveArc.h"
|
|
#include "/EgtDev/Include/EgkCurveBezier.h"
|
|
#include "/EgtDev/Include/EgkCurveComposite.h"
|
|
#include "/EgtDev/Include/EgkSurfTriMesh.h"
|
|
#include "/EgtDev/Include/EgkExtText.h"
|
|
#include "/EgtDev/Include/EGkDistPointCurve.h"
|
|
#include "/EgtDev/Include/EGnStringConverter.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
|
|
using namespace std ;
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static bool GetPolyLineFromCurve( IGeomDB* pGeomDB, int nId, const Frame3d& frDest, double dLinTol, PolyLine& PL) ;
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateGroup( int nGseCtx, int nParentId, const double ptOrig[3],
|
|
const double vX[3], const double vY[3], const double vZ[3])
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// costruisco il riferimento
|
|
Frame3d frFrame ;
|
|
if ( ! frFrame.Set( Point3d( ptOrig), Vector3d( vX), Vector3d( vY), Vector3d( vZ)))
|
|
return GDB_ID_NULL ;
|
|
// creo il gruppo
|
|
return pGeomDB->AddGroup( GDB_ID_NULL, nParentId, frFrame) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateGeoPoint( int nGseCtx, int nParentId, const double ptP[3])
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo il punto
|
|
PtrOwner<IGeoPoint3d> pGeoPnt( CreateGeoPoint3d()) ;
|
|
if ( IsNull( pGeoPnt))
|
|
return GDB_ID_NULL ;
|
|
// setto il punto
|
|
if ( ! pGeoPnt->Set( Point3d( ptP)))
|
|
return GDB_ID_NULL ;
|
|
// inserisco il punto nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pGeoPnt)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateGeoVector( int nGseCtx, int nParentId, const double vtV[3], const double ptB[3])
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo il vettore
|
|
PtrOwner<IGeoVector3d> pGeoVct( CreateGeoVector3d()) ;
|
|
if ( IsNull( pGeoVct))
|
|
return GDB_ID_NULL ;
|
|
// setto il vettore (con il punto base)
|
|
if ( ! pGeoVct->Set( Vector3d( vtV), Point3d( ptB)))
|
|
return GDB_ID_NULL ;
|
|
// inserisco il vettore nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pGeoVct)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateGeoFrame( int nGseCtx, int nParentId, const double ptOrig[3],
|
|
const double vX[3], const double vY[3], const double vZ[3])
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo il riferimento
|
|
PtrOwner<IGeoFrame3d> pGeoFrm( CreateGeoFrame3d()) ;
|
|
if ( IsNull( pGeoFrm))
|
|
return GDB_ID_NULL ;
|
|
// setto il riferimento
|
|
if ( ! pGeoFrm->Set( Point3d( ptOrig), Vector3d( vX), Vector3d( vY), Vector3d( vZ)))
|
|
return GDB_ID_NULL ;
|
|
// inserisco il vettore nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pGeoFrm)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveLine( int nGseCtx, int nParentId,
|
|
const double ptIni[3], const double ptFin[3])
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo la linea
|
|
PtrOwner<ICurveLine> pCrvLine( CreateCurveLine()) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
// setto la linea
|
|
if ( ! pCrvLine->Set( Point3d( ptIni), Point3d( ptFin)))
|
|
return GDB_ID_NULL ;
|
|
// inserisco la linea nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvLine)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveLineMinPointCurve( int nGseCtx, int nParentId,
|
|
const double ptStart[3], int nCrvId, double dNearPar)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il riferimento del gruppo destinazione
|
|
Frame3d frPoint ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frPoint))
|
|
return GDB_ID_NULL ;
|
|
// 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 ptSloc = ptStart ;
|
|
ptSloc.LocToLoc( frPoint, frCurve) ;
|
|
// calcolo il punto a minima distanza
|
|
int nFlag ;
|
|
Point3d ptEnd ;
|
|
DistPointCurve dstPtCurve( ptSloc, *pCurve) ;
|
|
if ( ! dstPtCurve.GetMinDistPoint( dNearPar, ptEnd, nFlag))
|
|
return GDB_ID_NULL ;
|
|
// porto il punto finale nel riferimento di creazione
|
|
ptEnd.LocToLoc( frCurve, frPoint) ;
|
|
// creo la linea
|
|
PtrOwner<ICurveLine> pCrvLine( CreateCurveLine()) ;
|
|
if ( IsNull( pCrvLine))
|
|
return GDB_ID_NULL ;
|
|
// setto la linea
|
|
if ( ! pCrvLine->Set( Point3d( ptStart), ptEnd))
|
|
return GDB_ID_NULL ;
|
|
// inserisco la linea nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvLine)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCircle( int nGseCtx, int nParentId,
|
|
const double ptCen[3], const double vtN[3], double dRad)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// setto la circonferenza
|
|
if ( ! pCrvArc->Set( Point3d( ptCen), Vector3d( vtN), dRad))
|
|
return GDB_ID_NULL ;
|
|
// inserisco l'arco nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCircleXY( int nGseCtx, int nParentId,
|
|
const double ptCen[3], double dRad)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// setto la circonferenza
|
|
if ( ! pCrvArc->SetXY( Point3d( ptCen), dRad))
|
|
return GDB_ID_NULL ;
|
|
// inserisco l'arco nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCircle3P( int nGseCtx, int nParentId,
|
|
const double ptP1[3], const double ptP2[3], const double ptP3[3])
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// setto l'arco
|
|
if ( ! pCrvArc->Set3P( Point3d( ptP1), Point3d( ptP2), Point3d( ptP3), true))
|
|
return GDB_ID_NULL ;
|
|
// inserisco l'arco nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveArc( int nGseCtx, int nParentId,
|
|
const double ptCen[3], const double vtN[3], double dRad,
|
|
const double vtS[3], double dAngCenDeg, double dDeltaN)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// setto l'arco
|
|
if ( ! pCrvArc->Set( Point3d( ptCen), Vector3d( vtN), dRad, Vector3d( vtS), dAngCenDeg, dDeltaN))
|
|
return GDB_ID_NULL ;
|
|
// inserisco l'arco nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveArcXY( int nGseCtx, int nParentId,
|
|
const double ptCen[3], double dRad,
|
|
double dAngStartDeg, double dAngCenDeg, double dDeltaZ)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// setto l'arco
|
|
if ( ! pCrvArc->SetXY( Point3d( ptCen), dRad, dAngStartDeg, dAngCenDeg, dDeltaZ))
|
|
return GDB_ID_NULL ;
|
|
// inserisco l'arco nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveArc3P( int nGseCtx, int nParentId,
|
|
const double ptP1[3], const double ptP2[3], const double ptP3[3])
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo l'arco
|
|
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
|
if ( IsNull( pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// setto l'arco
|
|
if ( ! pCrvArc->Set3P( Point3d( ptP1), Point3d( ptP2), Point3d( ptP3), false))
|
|
return GDB_ID_NULL ;
|
|
// inserisco l'arco nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvArc)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveBezier( int nGseCtx, int nParentId, int nDegree, const double ptCtrls[])
|
|
{
|
|
PNTVECTOR vPnt ;
|
|
vPnt.reserve( nDegree + 1) ;
|
|
for ( int i = 0 ; i <= nDegree ; ++i) {
|
|
vPnt.push_back( Point3d( ptCtrls[3*i], ptCtrls[3*i+1], ptCtrls[3*i+2])) ;
|
|
}
|
|
return EgtCreateCurveBezier( nGseCtx, nParentId, nDegree, vPnt) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveBezier( int nGseCtx, int nParentId, int nDegree, const PNTVECTOR& vPnt)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// il numero dei punti deve essere pari al grado + 1
|
|
if ( vPnt.size() != nDegree + 1)
|
|
return GDB_ID_NULL ;
|
|
// creo la curva di Bezier
|
|
PtrOwner<ICurveBezier> pCrvBez( CreateCurveBezier()) ;
|
|
if ( IsNull( pCrvBez))
|
|
return GDB_ID_NULL ;
|
|
// inizializzo la curva di Bezier
|
|
if ( ! pCrvBez->Init( nDegree, false))
|
|
return GDB_ID_NULL ;
|
|
// setto i punti di controllo
|
|
for ( int i = 0 ; i <= nDegree ; ++ i) {
|
|
if ( ! pCrvBez->SetControlPoint( i, vPnt[i]))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// se curva nulla (ovvero ridotta a punto), errore
|
|
if ( pCrvBez->IsAPoint())
|
|
return GDB_ID_NULL ;
|
|
// inserisco la curva nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvBez)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveBezierRational( int nGseCtx, int nParentId, int nDegree, const double ptCtrlWs[])
|
|
{
|
|
PNTUVECTOR vPntW ;
|
|
vPntW.reserve( nDegree + 1) ;
|
|
for ( int i = 0 ; i <= nDegree ; ++i) {
|
|
vPntW.push_back( make_pair( Point3d( ptCtrlWs[4*i], ptCtrlWs[4*i+1], ptCtrlWs[4*i+2]), ptCtrlWs[4*i+3])) ;
|
|
}
|
|
return EgtCreateCurveBezierRational( nGseCtx, nParentId, nDegree, vPntW) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveBezierRational( int nGseCtx, int nParentId, int nDegree, const PNTUVECTOR& vPntW)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// il numero dei punti deve essere pari al grado + 1
|
|
if ( vPntW.size() != nDegree + 1)
|
|
return GDB_ID_NULL ;
|
|
// creo la curva di Bezier
|
|
PtrOwner<ICurveBezier> pCrvBez( CreateCurveBezier()) ;
|
|
if ( IsNull( pCrvBez))
|
|
return GDB_ID_NULL ;
|
|
// inizializzo la curva di Bezier
|
|
if ( ! pCrvBez->Init( nDegree, true))
|
|
return GDB_ID_NULL ;
|
|
// setto i punti di controllo
|
|
for ( int i = 0 ; i <= nDegree ; ++ i) {
|
|
if ( ! pCrvBez->SetControlPoint( i, vPntW[i].first, vPntW[i].second))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// se curva nulla (ovvero ridotta a punto), errore
|
|
if ( pCrvBez->IsAPoint())
|
|
return GDB_ID_NULL ;
|
|
// inserisco la curva nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvBez)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveBezierFromArc( int nGseCtx, int nParentId, int nArcId, BOOL bErase)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo la curva di Bezier
|
|
PtrOwner<ICurveBezier> pCrvBez( CreateCurveBezier()) ;
|
|
if ( IsNull( pCrvBez))
|
|
return GDB_ID_NULL ;
|
|
// recupero l'arco
|
|
const ICurveArc* pCrvArc = GetCurveArc( pGeomDB->GetGeoObj( nArcId)) ;
|
|
if ( pCrvArc == nullptr)
|
|
return GDB_ID_NULL ;
|
|
// ne deduco la curva di Bezier
|
|
if ( ! pCrvBez->FromArc( *pCrvArc))
|
|
return GDB_ID_NULL ;
|
|
// recupero il riferimento dell'arco
|
|
Frame3d frSou ;
|
|
if ( ! pGeomDB->GetGlobFrame( nArcId, frSou))
|
|
return GDB_ID_NULL ;
|
|
// recupero il riferimento del gruppo destinazione
|
|
Frame3d frDest ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frDest))
|
|
return GDB_ID_NULL ;
|
|
// porto la curva di Bezier dal riferimento dell'arco a quello di inserimento
|
|
if ( ! AreSameFrame( frSou, frDest)) {
|
|
pCrvBez->ToGlob( frSou) ;
|
|
pCrvBez->ToLoc( frDest) ;
|
|
}
|
|
// se curva nulla (ovvero ridotta a punto), errore
|
|
if ( pCrvBez->IsAPoint())
|
|
return GDB_ID_NULL ;
|
|
// inserisco la curva nel DB
|
|
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvBez)) ;
|
|
if ( nId != GDB_ID_NULL) {
|
|
// se richiesto, cancello l'arco originale
|
|
if ( bErase) {
|
|
if ( ! pGeomDB->Erase( nArcId))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
}
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCompo( int nGseCtx, 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( nGseCtx, nParentId, vIds, ( bErase != FALSE)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCompo( int nGseCtx, int nParentId, const INTVECTOR& vIds, bool bErase)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
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 false ;
|
|
// 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 false ;
|
|
// recupero il riferimento della curva
|
|
Frame3d frSou ;
|
|
if ( ! pGeomDB->GetGlobFrame( nIdCrv, frSou))
|
|
return false ;
|
|
// se i riferimenti sono uguali
|
|
if ( AreSameFrame( frSou, frDest)) {
|
|
// aggiungo direttamente questa curva
|
|
if ( ! pCrvCompo->AddCurve( *pCrv))
|
|
return false ;
|
|
}
|
|
// altrimenti devo prima trasformare la curva
|
|
else {
|
|
// creo una copia della curva
|
|
PtrOwner<ICurve> pModCrv( pCrv->Clone()) ;
|
|
if ( IsNull( pModCrv))
|
|
return false ;
|
|
// eseguo la trasformazione
|
|
pModCrv->LocToLoc( frSou, frDest) ;
|
|
// aggiungo la curva modificata
|
|
if ( ! pCrvCompo->AddCurve( Release( pModCrv)))
|
|
return false ;
|
|
}
|
|
}
|
|
// inserisco la curva composita nel DB
|
|
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) ;
|
|
if ( nId != GDB_ID_NULL) {
|
|
// se richiesto, cancello le curve originali
|
|
if ( bErase) {
|
|
for ( Iter = vIds.begin() ; Iter != vIds.end() ; ++Iter) {
|
|
if ( ! pGeomDB->Erase( *Iter))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
}
|
|
}
|
|
return nId ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCompoFromPoints( int nGseCtx, int nParentId, int nP, const double ptPs[])
|
|
{
|
|
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( nGseCtx, nParentId, PL) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCompoFromPoints( int nGseCtx, int nParentId, const PolyLine& PL)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo la curva composita
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCrvCompo))
|
|
return GDB_ID_NULL ;
|
|
// inserisco i segmenti che uniscono i punti
|
|
if ( ! pCrvCompo->FromPolyLine( PL))
|
|
return GDB_ID_NULL ;
|
|
// inserisco la curva composita nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCompoFromPointBulges( int nGseCtx, int nParentId, int nPB, const double ptPBs[])
|
|
{
|
|
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( nGseCtx, nParentId, PA) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCompoFromPointBulges( int nGseCtx, int nParentId, const PolyArc& PA)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo la curva composita
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCrvCompo))
|
|
return GDB_ID_NULL ;
|
|
// inserisco i segmenti e gli archi che uniscono i punti
|
|
if ( ! pCrvCompo->FromPolyArc( PA))
|
|
return GDB_ID_NULL ;
|
|
// inserisco la curva composita nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateCurveCompoFromPolygonSide( int nGseCtx, int nParentId, int nNumSides,
|
|
const double ptIni[3], const double ptFin[3])
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo la curva composita
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCrvCompo))
|
|
return GDB_ID_NULL ;
|
|
// setto la curva
|
|
if ( ! pCrvCompo->PolygonSide( nNumSides, Point3d( ptIni), Point3d( ptFin)))
|
|
return GDB_ID_NULL ;
|
|
// inserisco la curva nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pCrvCompo)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateSurfTriMeshByContour( int nGseCtx, int nParentId, int nCrvId, double dLinTol)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero il riferimento del gruppo destinazione
|
|
Frame3d frDest ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nParentId, frDest))
|
|
return GDB_ID_NULL ;
|
|
// calcolo la polilinea che approssima la curva
|
|
PolyLine PL ;
|
|
if ( ! GetPolyLineFromCurve( pGeomDB, nCrvId, frDest, dLinTol, PL))
|
|
return GDB_ID_NULL ;
|
|
// creo la superficie trimesh
|
|
PtrOwner<ISurfTriMesh> pSTM( CreateSurfTriMesh()) ;
|
|
if ( IsNull( pSTM))
|
|
return GDB_ID_NULL ;
|
|
// setto la superficie
|
|
if ( ! pSTM->CreateByFlatContour( PL))
|
|
return GDB_ID_NULL ;
|
|
// inserisco la superficie nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSTM)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateText( int nGseCtx, int nParentId, const wchar_t* wsText,
|
|
const double ptP[3], double dAngRotDeg, double dH)
|
|
{
|
|
return EgtCreateText( nGseCtx, nParentId, wstrztoA( wsText), Point3d( ptP), dAngRotDeg, dH) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateText( int nGseCtx, int nParentId, const string& sText,
|
|
const Point3d& ptP, double dAngRotDeg, double dH)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo il testo
|
|
PtrOwner<IExtText> pTXT( CreateExtText()) ;
|
|
if ( IsNull( pTXT))
|
|
return GDB_ID_NULL ;
|
|
// lo riempio
|
|
if ( ! pTXT->Set( sText, ptP, dAngRotDeg, dH))
|
|
return GDB_ID_NULL ;
|
|
// inserisco il testo nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pTXT)) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateTextEx( int nGseCtx, int nParentId, const wchar_t* wsText,
|
|
const double ptP[3], double dAngRotDeg, const wchar_t* wsFont,
|
|
int nW, BOOL bItalic, double dH, double dRat, double dAddAdv, int nInsPos)
|
|
{
|
|
return EgtCreateTextEx( nGseCtx, nParentId, wstrztoA( wsText), Point3d( ptP), dAngRotDeg,
|
|
wstrztoA( wsFont), nW, ( bItalic != FALSE), dH, dRat, dAddAdv, nInsPos) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
__stdcall EgtCreateTextEx( int nGseCtx, int nParentId, const string& sText,
|
|
const Point3d& ptP, double dAngRotDeg, const string& sFont,
|
|
int nW, bool bItalic, double dH, double dRat, double dAddAdv, int nInsPos)
|
|
{
|
|
IGeomDB* pGeomDB = GetGeomDB( nGseCtx) ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// creo il testo
|
|
PtrOwner<IExtText> pTXT( CreateExtText()) ;
|
|
if ( IsNull( pTXT))
|
|
return GDB_ID_NULL ;
|
|
// lo riempio
|
|
if ( ! pTXT->Set( sText, ptP, dAngRotDeg, sFont, nW, bItalic, dH, dRat, dAddAdv, nInsPos))
|
|
return GDB_ID_NULL ;
|
|
// inserisco il testo nel DB
|
|
return pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pTXT)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------
|
|
static bool
|
|
GetPolyLineFromCurve( IGeomDB* pGeomDB, int nId, const Frame3d& frDest, double dLinTol, PolyLine& PL)
|
|
{
|
|
const double ANG_TOL_STD_DEG = 15 ;
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pCrv == nullptr)
|
|
return false ;
|
|
// recupero il riferimento della curva
|
|
Frame3d frCrv ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frCrv))
|
|
return false ;
|
|
// calcolo la polilinea che approssima la curva
|
|
// se i riferimenti sono uguali
|
|
if ( AreSameFrame( frCrv, frDest)) {
|
|
// ricavo l'approssimazione
|
|
if ( ! pCrv->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, PL))
|
|
return false ;
|
|
}
|
|
// altrimenti devo prima trasformare la curva
|
|
else {
|
|
// creo una copia della curva (da buttare alla fine)
|
|
PtrOwner<ICurve> pModCrv( pCrv->Clone()) ;
|
|
if ( IsNull( pModCrv))
|
|
return false ;
|
|
// eseguo la trasformazione
|
|
pModCrv->LocToLoc( frCrv, frDest) ;
|
|
// ricavo l'approssimazione
|
|
if ( ! pModCrv->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, PL))
|
|
return false ;
|
|
}
|
|
return true ;
|
|
}
|