966885645e
- primo rilascio (esecutore e lua da EgtInterface).
959 lines
32 KiB
C++
959 lines
32 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2015
|
|
//----------------------------------------------------------------------------
|
|
// File : EXE_GeoSnap.cpp Data : 05.05.15 Versione : 1.6e1
|
|
// Contenuto : Funzioni di snap ad oggetti del DB geometrico per EXE.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 02.10.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "EXE.h"
|
|
#include "EXE_Macro.h"
|
|
#include "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EgkGeoPoint3d.h"
|
|
#include "/EgtDev/Include/EgkGeoVector3d.h"
|
|
#include "/EgtDev/Include/EgkCurve.h"
|
|
#include "/EgtDev/Include/EgkCurveArc.h"
|
|
#include "/EgtDev/Include/EgkCurveComposite.h"
|
|
#include "/EgtDev/Include/EgkSurf.h"
|
|
#include "/EgtDev/Include/EgkSurfTriMesh.h"
|
|
#include "/EgtDev/Include/EgkExtText.h"
|
|
#include "/EgtDev/Include/EgkDistPointCurve.h"
|
|
#include "/EgtDev/Include/EgkIntersCurveCurve.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
|
|
//----------------------------------------------------------------------------
|
|
static bool
|
|
TrasformPoint( IGeomDB* pGeomDB, int nId, int nRefId, Point3d& ptP)
|
|
{
|
|
// se non va trasformato, esco
|
|
if ( nRefId == nId)
|
|
return true ;
|
|
// recupero il riferimento in cui è espresso il punto (quello dell'entità da cui deriva)
|
|
Frame3d frSou ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frSou))
|
|
return false ;
|
|
// se va portato in globale, trasformo ed esco
|
|
if ( nRefId == GDB_ID_ROOT)
|
|
return ptP.ToGlob( frSou) ;
|
|
// recupero il riferimento destinazione
|
|
Frame3d frDest ;
|
|
if ( nRefId == GDB_ID_GRID)
|
|
frDest = pGeomDB->GetGridFrame() ;
|
|
else {
|
|
// nRefId può essere un gruppo o una entità
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nRefId, frDest) &&
|
|
! pGeomDB->GetGlobFrame( nRefId, frDest))
|
|
return false ;
|
|
}
|
|
// eseguo la trasformazione
|
|
return ptP.LocToLoc( frSou, frDest) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static bool
|
|
InvTrasformPoint( IGeomDB* pGeomDB, int nId, int nRefId, Point3d& ptP)
|
|
{
|
|
// se non va trasformato, esco
|
|
if ( nRefId == nId)
|
|
return true ;
|
|
// recupero il riferimento in cui va espresso il punto (quello dell'entità a cui va riferito)
|
|
Frame3d frSou ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frSou))
|
|
return false ;
|
|
// se viene da globale, trasformo ed esco
|
|
if ( nRefId == GDB_ID_ROOT)
|
|
return ptP.ToLoc( frSou) ;
|
|
// recupero il riferimento da cui proviene
|
|
Frame3d frDest ;
|
|
if ( nRefId == GDB_ID_GRID)
|
|
frDest = pGeomDB->GetGridFrame() ;
|
|
else {
|
|
// nRefId può essere un gruppo o una entità
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nRefId, frDest) &&
|
|
! pGeomDB->GetGlobFrame( nRefId, frDest))
|
|
return false ;
|
|
}
|
|
// eseguo la trasformazione inversa
|
|
return ptP.LocToLoc( frDest, frSou) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static bool
|
|
TrasformVector( IGeomDB* pGeomDB, int nId, int nRefId, Vector3d& vtV)
|
|
{
|
|
// se non va trasformato, esco
|
|
if ( nRefId == nId)
|
|
return true ;
|
|
// recupero il riferimento in cui è espresso il punto (quello dell'entità da cui deriva)
|
|
Frame3d frSou ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frSou))
|
|
return false ;
|
|
// se va portato in globale, trasformo ed esco
|
|
if ( nRefId == GDB_ID_ROOT)
|
|
return vtV.ToGlob( frSou) ;
|
|
// recupero il riferimento destinazione
|
|
Frame3d frDest ;
|
|
if ( nRefId == GDB_ID_GRID)
|
|
frDest = pGeomDB->GetGridFrame() ;
|
|
else {
|
|
// nRefId può essere un gruppo o una entità
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nRefId, frDest) &&
|
|
! pGeomDB->GetGlobFrame( nRefId, frDest))
|
|
return false ;
|
|
}
|
|
// eseguo la trasformazione
|
|
return vtV.LocToLoc( frSou, frDest) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static bool
|
|
TrasformFrame( IGeomDB* pGeomDB, int nId, int nRefId, Frame3d& frF)
|
|
{
|
|
// se non va trasformato, esco
|
|
if ( nRefId == nId)
|
|
return true ;
|
|
// recupero il riferimento in cui è espresso il punto (quello dell'entità da cui deriva)
|
|
Frame3d frSou ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frSou))
|
|
return false ;
|
|
// se va portato in globale, trasformo ed esco
|
|
if ( nRefId == GDB_ID_ROOT)
|
|
return frF.ToGlob( frSou) ;
|
|
// recupero il riferimento destinazione
|
|
Frame3d frDest ;
|
|
if ( nRefId == GDB_ID_GRID)
|
|
frDest = pGeomDB->GetGridFrame() ;
|
|
else {
|
|
// nRefId può essere un gruppo o una entità
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nRefId, frDest) &&
|
|
! pGeomDB->GetGlobFrame( nRefId, frDest))
|
|
return false ;
|
|
}
|
|
// eseguo la trasformazione
|
|
return frF.LocToLoc( frSou, frDest) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeStartPoint( int nId, int nRefId, Point3d& ptP)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se non è entità geometrica
|
|
const IGeoObj* pGObj ;
|
|
if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr)
|
|
return false ;
|
|
// se punto
|
|
if ( pGObj->GetType() == GEO_PNT3D) {
|
|
// recupero il geo-punto
|
|
const IGeoPoint3d* pGP = GetGeoPoint3d( pGObj) ;
|
|
// assegno il punto
|
|
ptP = pGP->GetPoint() ;
|
|
}
|
|
// se vettore
|
|
else if ( pGObj->GetType() == GEO_VECT3D) {
|
|
// recupero il geo-vettore
|
|
const IGeoVector3d* pGV = GetGeoVector3d( pGObj) ;
|
|
// assegno il punto
|
|
ptP = pGV->GetBase() ;
|
|
}
|
|
// se frame
|
|
else if ( pGObj->GetType() == GEO_FRAME3D) {
|
|
// recupero il frame
|
|
const IGeoFrame3d* pGF = GetGeoFrame3d( pGObj) ;
|
|
// assegno il punto
|
|
ptP = pGF->GetFrame().Orig() ;
|
|
}
|
|
// se curva
|
|
else if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
// assegno il punto
|
|
if ( pCrv == nullptr || ! pCrv->GetStartPoint( ptP))
|
|
return false ;
|
|
}
|
|
// se testo
|
|
else if ( pGObj->GetType() == EXT_TEXT) {
|
|
// recupero il testo
|
|
const IExtText* pTxt = GetExtText( pGObj) ;
|
|
// assegno il punto
|
|
if ( pTxt == nullptr || ! pTxt->GetStartPoint( ptP))
|
|
return false ;
|
|
}
|
|
else
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformPoint( pGeomDB, nId, nRefId, ptP) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeEndPoint( int nId, int nRefId, Point3d& ptP)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se non è entità geometrica
|
|
const IGeoObj* pGObj ;
|
|
if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr)
|
|
return false ;
|
|
// se curva
|
|
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
if ( pCrv == nullptr || ! pCrv->GetEndPoint( ptP))
|
|
return false ;
|
|
}
|
|
// se testo
|
|
else if ( pGObj->GetType() == EXT_TEXT) {
|
|
// recupero il testo
|
|
const IExtText* pTxt = GetExtText( pGObj) ;
|
|
if ( pTxt == nullptr || ! pTxt->GetEndPoint( ptP))
|
|
return false ;
|
|
}
|
|
else
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformPoint( pGeomDB, nId, nRefId, ptP) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeMidPoint( int nId, int nRefId, Point3d& ptP)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se non è entità geometrica
|
|
const IGeoObj* pGObj ;
|
|
if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr)
|
|
return false ;
|
|
// se curva
|
|
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
// assegno il punto
|
|
if ( pCrv == nullptr || ! pCrv->GetMidPoint( ptP))
|
|
return false ;
|
|
}
|
|
// se testo
|
|
else if ( pGObj->GetType() == EXT_TEXT) {
|
|
// recupero il testo
|
|
const IExtText* pTxt = GetExtText( pGObj) ;
|
|
// assegno il punto
|
|
if ( pTxt == nullptr || ! pTxt->GetMidPoint( ptP))
|
|
return false ;
|
|
}
|
|
else
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformPoint( pGeomDB, nId, nRefId, ptP) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCenterPoint( int nId, int nRefId, Point3d& ptP)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se non è entità geometrica
|
|
const IGeoObj* pGObj ;
|
|
if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr)
|
|
return false ;
|
|
// se curva
|
|
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
// assegno il punto
|
|
if ( pCrv == nullptr || ! pCrv->GetCenterPoint( ptP))
|
|
return false ;
|
|
}
|
|
// se testo
|
|
else if ( pGObj->GetType() == EXT_TEXT) {
|
|
// recupero il testo
|
|
const IExtText* pTxt = GetExtText( pGObj) ;
|
|
// assegno il punto
|
|
if ( pTxt == nullptr || ! pTxt->GetCenterPoint( ptP))
|
|
return false ;
|
|
}
|
|
else
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformPoint( pGeomDB, nId, nRefId, ptP) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCentroid( int nId, int nRefId, Point3d& ptP)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se non è entità geometrica
|
|
const IGeoObj* pGObj ;
|
|
if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr)
|
|
return false ;
|
|
// se curva
|
|
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
// assegno il punto
|
|
if ( pCrv == nullptr || ! pCrv->GetCentroid( ptP))
|
|
return false ;
|
|
}
|
|
// se superficie
|
|
else if ( ( pGObj->GetType() & GEO_SURF) != 0) {
|
|
// recupero la superficie
|
|
const ISurf* pSrf = GetSurf( pGObj) ;
|
|
// assegno il punto
|
|
if ( pSrf == nullptr || ! pSrf->GetCentroid( ptP))
|
|
return false ;
|
|
}
|
|
// se testo
|
|
else if ( pGObj->GetType() == EXT_TEXT) {
|
|
// recupero il testo
|
|
const IExtText* pTxt = GetExtText( pGObj) ;
|
|
// assegno il punto
|
|
if ( pTxt == nullptr || ! pTxt->GetCenterPoint( ptP))
|
|
return false ;
|
|
}
|
|
else
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformPoint( pGeomDB, nId, nRefId, ptP) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeAtParamPoint( int nId, double dU, int nRefId, Point3d& ptP)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se non è entità geometrica
|
|
const IGeoObj* pGObj ;
|
|
if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr)
|
|
return false ;
|
|
// se curva
|
|
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
if ( pCrv == nullptr || ! pCrv->GetPointD1D2( dU, ICurve::FROM_MINUS, ptP))
|
|
return false ;
|
|
}
|
|
else
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformPoint( pGeomDB, nId, nRefId, ptP) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeNearPoint( int nId, const Point3d& ptNear, int nRefId, Point3d& ptP)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se non è entità geometrica
|
|
const IGeoObj* pGObj = pGeomDB->GetGeoObj( nId) ;
|
|
if ( pGObj == nullptr)
|
|
return false ;
|
|
// porto il punto near nel riferimento dell'entità
|
|
Point3d ptNearL = ptNear ;
|
|
if ( ! InvTrasformPoint( pGeomDB, nId, nRefId, ptNearL))
|
|
return false ;
|
|
// se curva
|
|
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
// calcolo il punto della curva più vicino al punto di riferimento
|
|
DistPointCurve dstPC( ptNearL, *pCrv) ;
|
|
int nFlag ;
|
|
if ( ! dstPC.GetMinDistPoint( 0, ptP, nFlag))
|
|
return false ;
|
|
}
|
|
else
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformPoint( pGeomDB, nId, nRefId, ptP) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeIntersectionPoint( int nId1, int nId2, const Point3d& ptNear, int nRefId, Point3d& ptP)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// devono essere entità geometriche
|
|
const IGeoObj* pGObj1 ;
|
|
if ( ( pGObj1 = pGeomDB->GetGeoObj( nId1)) == nullptr)
|
|
return false ;
|
|
const IGeoObj* pGObj2 ;
|
|
if ( ( pGObj2 = pGeomDB->GetGeoObj( nId2)) == nullptr)
|
|
return false ;
|
|
// se curve
|
|
if ( ( pGObj1->GetType() & GEO_CURVE) != 0 && ( pGObj2->GetType() & GEO_CURVE) != 0) {
|
|
// recupero le curve
|
|
const ICurve* pCrv1 = GetCurve( pGObj1) ;
|
|
const ICurve* pCrv2 = GetCurve( pGObj2) ;
|
|
// recupero i riferimenti in cui sono immerse
|
|
Frame3d frEnt1 ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId1, frEnt1))
|
|
return false ;
|
|
Frame3d frEnt2 ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId2, frEnt2))
|
|
return false ;
|
|
// se il riferimento della seconda curva è diverso da quello della prima entità, devo trasformarla
|
|
PtrOwner<ICurve> crvTrans( nullptr) ;
|
|
if ( ! AreSameFrame( frEnt1, frEnt2)) {
|
|
crvTrans.Set( pCrv2->Clone()) ;
|
|
if ( IsNull( crvTrans))
|
|
return false ;
|
|
crvTrans->LocToLoc( frEnt2, frEnt1) ;
|
|
pCrv2 = ::Get( crvTrans) ;
|
|
}
|
|
// porto il punto Near nel riferimento della prima entità
|
|
Point3d ptNearL = ptNear ;
|
|
if ( ! InvTrasformPoint( pGeomDB, nId1, nRefId, ptNearL))
|
|
return false ;
|
|
// calcolo il punto di intersezione sulla prima curva più vicino al punto di riferimento
|
|
IntersCurveCurve intCC( *pCrv1, *pCrv2, true) ;
|
|
if ( ! intCC.GetIntersPointNearTo( 0, ptNearL, ptP))
|
|
return false ;
|
|
}
|
|
else
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformPoint( pGeomDB, nId1, nRefId, ptP) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeStartVector( int nId, int nRefId, Vector3d& vtV)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se non è entità geometrica
|
|
const IGeoObj* pGObj = pGeomDB->GetGeoObj( nId) ;
|
|
if ( pGObj == nullptr)
|
|
return false ;
|
|
// se vettore
|
|
if ( pGObj->GetType() == GEO_VECT3D) {
|
|
// recupero il geo-vettore
|
|
const IGeoVector3d* pGV = GetGeoVector3d( pGObj) ;
|
|
// assegno il vettore
|
|
vtV = pGV->GetVector() ;
|
|
}
|
|
// se curva
|
|
else if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
// assegno il vettore
|
|
if ( ! pCrv->GetStartDir( vtV))
|
|
return false ;
|
|
}
|
|
// se testo
|
|
else if ( pGObj->GetType() == EXT_TEXT) {
|
|
// recupero il testo
|
|
const IExtText* pTxt = GetExtText( pGObj) ;
|
|
// assegno il vettore
|
|
vtV = pTxt->GetDirVersor() ;
|
|
}
|
|
else
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformVector( pGeomDB, nId, nRefId, vtV) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeEndVector( int nId, int nRefId, Vector3d& vtV)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se non è entità geometrica
|
|
const IGeoObj* pGObj = pGeomDB->GetGeoObj( nId) ;
|
|
if ( pGObj == nullptr)
|
|
return false ;
|
|
// se curva
|
|
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
// assegno il vettore
|
|
if ( ! pCrv->GetEndDir( vtV))
|
|
return false ;
|
|
}
|
|
else
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformVector( pGeomDB, nId, nRefId, vtV) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeMidVector( int nId, int nRefId, Vector3d& vtV)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se non è entità geometrica
|
|
const IGeoObj* pGObj ;
|
|
if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr)
|
|
return false ;
|
|
// se curva
|
|
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
// assegno il vettore
|
|
if ( ! pCrv->GetMidDir( vtV))
|
|
return false ;
|
|
}
|
|
else
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformVector( pGeomDB, nId, nRefId, vtV) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeAtParamVector( int nId, double dU, int nSide, int nRefId, Vector3d& vtV)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se non è entità geometrica
|
|
const IGeoObj* pGObj ;
|
|
if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr)
|
|
return false ;
|
|
// se curva
|
|
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
// assegno il lato di approccio
|
|
ICurve::Side nSide = ICurve::FROM_MINUS ;
|
|
if ( nSide > 0)
|
|
nSide = ICurve::FROM_PLUS ;
|
|
// recupero la direzione
|
|
Point3d ptP ;
|
|
if ( ! pCrv->GetPointTang( dU, nSide, ptP, vtV))
|
|
return false ;
|
|
}
|
|
else
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformVector( pGeomDB, nId, nRefId, vtV) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeFrame( int nId, int nRefId, Frame3d& frFrame)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se gruppo
|
|
if ( pGeomDB->GetGroupFrame( nId, frFrame))
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformFrame( pGeomDB, nId, nRefId, frFrame) ;
|
|
// se geo frame
|
|
const IGeoObj* pGObj ;
|
|
if ( ( pGObj = pGeomDB->GetGeoObj( nId)) != nullptr &&
|
|
pGObj->GetType() == GEO_FRAME3D) {
|
|
frFrame = GetGeoFrame3d( pGObj)->GetFrame() ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformFrame( pGeomDB, nId, nRefId, frFrame) ;
|
|
}
|
|
// errore
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCurveLength( int nId, double* pdLen)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// verifico il parametro
|
|
if ( pdLen == nullptr)
|
|
return false ;
|
|
// recupero la curva
|
|
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pCurve == nullptr)
|
|
return false ;
|
|
// recupero la lunghezza
|
|
return pCurve->GetLength( *pdLen) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCurveLengthAtPoint( int nId, const Point3d& ptOn, double dExtend, double* pdLen)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// verifico il parametro
|
|
if ( pdLen == nullptr)
|
|
return false ;
|
|
// recupero la curva
|
|
const ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pCurve == nullptr)
|
|
return false ;
|
|
// determino la posizione parametrica del punto sulla curva (con tolleranza)
|
|
int nFlag ;
|
|
double dU ;
|
|
if ( ! DistPointCurve( ptOn, *pCurve).GetParamAtMinDistPoint( 0, dU, nFlag) || nFlag != MDPCI_NORMAL)
|
|
return false ;
|
|
// se non richiesta estensione o punto interno alla curva, recupero la lunghezza alla posizione parametrica
|
|
if ( dExtend < EPS_SMALL ||
|
|
( ! pCurve->IsStartParam( dU) && ! pCurve->IsEndParam( dU)))
|
|
return ( pCurve->GetLengthAtParam( dU, *pdLen) ? true : false) ;
|
|
// allungo la curva dalla parte del punto
|
|
PtrOwner<ICurve> pCopy( pCurve->Clone()) ;
|
|
if ( IsNull( pCopy))
|
|
return false ;
|
|
double dDeltaIni ;
|
|
if ( pCopy->IsStartParam( dU)) {
|
|
pCopy->ExtendStartByLen( dExtend) ;
|
|
dDeltaIni = dExtend ;
|
|
}
|
|
else {
|
|
pCopy->ExtendEndByLen( dExtend) ;
|
|
dDeltaIni = 0 ;
|
|
}
|
|
if ( ! DistPointCurve( ptOn, *pCopy).GetParamAtMinDistPoint( 0, dU, nFlag) || nFlag != MDPCI_NORMAL)
|
|
return false ;
|
|
if ( pCopy->GetLengthAtParam( dU, *pdLen)) {
|
|
*pdLen -= dDeltaIni ;
|
|
return true ;
|
|
}
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCurveExtrusion( int nId, int nRefId, Vector3d& vtExtr)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero la curva
|
|
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
// ne ricavo il vettore estrusione
|
|
if ( pCurve == nullptr || ! pCurve->GetExtrusion( vtExtr))
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformVector( pGeomDB, nId, nRefId, vtExtr) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCurveThickness( int nId, double* pdThick)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// verifico il parametro
|
|
if ( pdThick == nullptr)
|
|
return false ;
|
|
// recupero la curva
|
|
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
// recupero lo spessore
|
|
return ( pCurve != nullptr && pCurve->GetThickness( *pdThick)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetMinDistPointCurve( const Point3d& ptP, int nId, double* pdDist)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// verifico i parametri
|
|
if ( pdDist == nullptr)
|
|
return false ;
|
|
// recupero la curva
|
|
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pCurve == nullptr)
|
|
return false ;
|
|
// calcolo la minima distanza
|
|
DistPointCurve distPC( ptP, *pCurve) ;
|
|
return distPC.GetDist( *pdDist) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetMinDistPntSidePointCurve( const Point3d& ptP, int nId, const Vector3d& vtN,
|
|
double* pdDist, Point3d& ptMin, int* pnSide)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// verifico i parametri
|
|
if ( pdDist == nullptr || pnSide == nullptr || &ptMin == nullptr)
|
|
return false ;
|
|
// recupero la curva
|
|
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pCurve == nullptr)
|
|
return false ;
|
|
// calcolo la minima distanza
|
|
DistPointCurve distPC( ptP, *pCurve) ;
|
|
// recupero i risultati
|
|
int nFlag ;
|
|
return ( distPC.GetDist( *pdDist) &&
|
|
distPC.GetMinDistPoint( 0, ptMin, nFlag) &&
|
|
distPC.GetSideAtMinDistPoint( 0, vtN, *pnSide)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCurveArcRadius( int nId, double* pdRad)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// verifico il parametro
|
|
if ( pdRad == nullptr)
|
|
return false ;
|
|
// recupero l'arco
|
|
const ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pArc == nullptr)
|
|
return false ;
|
|
*pdRad = pArc->GetRadius() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCurveArcNormVersor( int nId, int nRefId, Vector3d& vtNorm)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero l'arco
|
|
const ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pArc == nullptr)
|
|
return false ;
|
|
// recupero la normale
|
|
vtNorm = pArc->GetNormVersor() ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformVector( pGeomDB, nId, nRefId, vtNorm) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCurveCompoCenter( int nId, int nSimpCrv, int nRefId, Point3d& ptCen)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero la curva composita
|
|
const ICurveComposite* pCompoCrv = GetCurveComposite( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pCompoCrv == nullptr)
|
|
return false ;
|
|
// recupero la curva semplice di indice richiesto
|
|
const ICurve* pSimpCrv = pCompoCrv->GetCurve( nSimpCrv) ;
|
|
if ( pSimpCrv == nullptr)
|
|
return false ;
|
|
// recupero il centro
|
|
if ( ! pSimpCrv->GetCenterPoint( ptCen))
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformPoint( pGeomDB, nId, nRefId, ptCen) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
ExeSurfTmFacetNbr( int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, 0)
|
|
// recupero la superficie trimesh
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pStm == nullptr)
|
|
return 0 ;
|
|
// recupero il numero delle facce
|
|
return pStm->GetFacetNum() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
ExeSurfTmFacetFromTria( int nId, int nT)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, SVT_NULL)
|
|
// recupero la superficie trimesh
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pStm == nullptr)
|
|
return SVT_NULL ;
|
|
// recupero il numero della faccia da quello di un suo triangolo
|
|
return pStm->GetFacetFromTria( nT) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeSurfTmFacetNearestEndPoint( int nId, int nFacet, const Point3d& ptNear, int nRefId,
|
|
Point3d& ptEnd, Vector3d& vtN)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero la superficie trimesh
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pStm == nullptr)
|
|
return false ;
|
|
// porto il punto Near nel riferimento dell'entità
|
|
Point3d ptNearL = ptNear ;
|
|
if ( ! InvTrasformPoint( pGeomDB, nId, nRefId, ptNearL))
|
|
return false ;
|
|
// recupero il punto End più vicino della faccia
|
|
if ( ! pStm->GetFacetNearestEndPoint( nFacet, ptNearL, ptEnd, vtN))
|
|
return false ;
|
|
// gestione trasformazioni ( eventuali)
|
|
return TrasformPoint( pGeomDB, nId, nRefId, ptEnd) && TrasformVector( pGeomDB, nId, nRefId, vtN) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeSurfTmFacetNearestMidPoint( int nId, int nFacet, const Point3d& ptNear, int nRefId,
|
|
Point3d& ptMid, Vector3d& vtN)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero la superficie trimesh
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pStm == nullptr)
|
|
return false ;
|
|
// porto il punto Near nel riferimento dell'entità
|
|
Point3d ptNearL = ptNear ;
|
|
if ( ! InvTrasformPoint( pGeomDB, nId, nRefId, ptNearL))
|
|
return false ;
|
|
// recupero il punto Mid più vicino della faccia
|
|
if ( ! pStm->GetFacetNearestMidPoint( nFacet, ptNearL, ptMid, vtN))
|
|
return false ;
|
|
// gestione trasformazioni ( eventuali)
|
|
return TrasformPoint( pGeomDB, nId, nRefId, ptMid) && TrasformVector( pGeomDB, nId, nRefId, vtN) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeSurfTmFacetCenter( int nId, int nFacet, int nRefId, Point3d& ptCen, Vector3d& vtN)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero la superficie trimesh
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pStm == nullptr)
|
|
return false ;
|
|
// recupero il centro della faccia
|
|
if ( ! pStm->GetFacetCenter( nFacet, ptCen, vtN))
|
|
return false ;
|
|
// gestione trasformazioni ( eventuali)
|
|
return TrasformPoint( pGeomDB, nId, nRefId, ptCen) && TrasformVector( pGeomDB, nId, nRefId, vtN) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeSurfTmFacetNormVersor( int nId, int nFacet, int nRefId, Vector3d& vtNorm)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero la superficie trimesh
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pStm == nullptr)
|
|
return false ;
|
|
// recupero il centro della faccia
|
|
if ( ! pStm->GetFacetNormal( nFacet, vtNorm))
|
|
return false ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformVector( pGeomDB, nId, nRefId, vtNorm) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeExtTextNormVersor( int nId, int nRefId, Vector3d& vtNorm)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il testo
|
|
const IExtText* pTxt = GetExtText( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pTxt == nullptr)
|
|
return false ;
|
|
// recupero la normale
|
|
vtNorm = pTxt->GetNormVersor() ;
|
|
// gestione trasformazione ( eventuale)
|
|
return TrasformVector( pGeomDB, nId, nRefId, vtNorm) ;
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
// Geo Transforms
|
|
//-------------------------------------------------------------------------------
|
|
bool
|
|
ExePointToIdGlob( Point3d& ptP, int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se griglia
|
|
if ( nId == GDB_ID_GRID)
|
|
return ptP.ToGlob( pGeomDB->GetGridFrame()) ;
|
|
// recupero il riferimento
|
|
// se gruppo -> il suo proprio espresso in globale
|
|
// se oggetto -> quello del gruppo cui appartiene in globale
|
|
Frame3d frRef ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nId, frRef) &&
|
|
! pGeomDB->GetGlobFrame( nId, frRef))
|
|
return false ;
|
|
// eseguo la trasformazione
|
|
return ptP.ToGlob( frRef) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
bool
|
|
ExePointToIdLoc( Point3d& ptP, int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se griglia
|
|
if ( nId == GDB_ID_GRID)
|
|
return ptP.ToLoc( pGeomDB->GetGridFrame()) ;
|
|
// recupero il riferimento
|
|
// se gruppo -> il suo proprio espresso in globale
|
|
// se oggetto -> quello del gruppo cui appartiene in globale
|
|
Frame3d frRef ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nId, frRef) &&
|
|
! pGeomDB->GetGlobFrame( nId, frRef))
|
|
return false ;
|
|
// eseguo la trasformazione
|
|
return ptP.ToLoc( frRef) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
bool
|
|
ExeVectorToIdGlob( Vector3d& vtV, int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se griglia
|
|
if ( nId == GDB_ID_GRID)
|
|
return vtV.ToGlob( pGeomDB->GetGridFrame()) ;
|
|
// recupero il riferimento
|
|
// se gruppo -> il suo proprio espresso in globale
|
|
// se oggetto -> quello del gruppo cui appartiene in globale
|
|
Frame3d frRef ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nId, frRef) &&
|
|
! pGeomDB->GetGlobFrame( nId, frRef))
|
|
return false ;
|
|
// eseguo la trasformazione
|
|
return vtV.ToGlob( frRef) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
bool
|
|
ExeVectorToIdLoc( Vector3d& vtV, int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// se griglia
|
|
if ( nId == GDB_ID_GRID)
|
|
return vtV.ToLoc( pGeomDB->GetGridFrame()) ;
|
|
// recupero il riferimento
|
|
// se gruppo -> il suo proprio espresso in globale
|
|
// se oggetto -> quello del gruppo cui appartiene in globale
|
|
Frame3d frRef ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nId, frRef) &&
|
|
! pGeomDB->GetGlobFrame( nId, frRef))
|
|
return false ;
|
|
// eseguo la trasformazione
|
|
return vtV.ToLoc( frRef) ;
|
|
}
|