46c5fce044
- ora si imposta un context corrente anche per le API come per LUA - il context corrente di LUA coincide con quello delle API.
406 lines
12 KiB
C++
406 lines
12 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : API_GeoSnap.cpp Data : 02.10.14 Versione : 1.5i5
|
|
// Contenuto : Funzioni di snap ad oggetti del DB geometrico per API.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 02.10.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/EgkCurve.h"
|
|
#include "/EgtDev/Include/EgkExtText.h"
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtStartPoint( int nId, double ptP[3])
|
|
{
|
|
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) ;
|
|
Point3d ptStart = pGP->GetPoint() ;
|
|
// assegno il punto
|
|
ptP[0] = ptStart.x ;
|
|
ptP[1] = ptStart.y ;
|
|
ptP[2] = ptStart.z ;
|
|
return TRUE ;
|
|
}
|
|
// se vettore
|
|
else if ( pGObj->GetType() == GEO_VECT3D) {
|
|
// recupero il geo-vettore
|
|
const IGeoVector3d* pGV = GetGeoVector3d( pGObj) ;
|
|
Point3d ptStart = pGV->GetBase() ;
|
|
// assegno il punto
|
|
ptP[0] = ptStart.x ;
|
|
ptP[1] = ptStart.y ;
|
|
ptP[2] = ptStart.z ;
|
|
return TRUE ;
|
|
}
|
|
// se frame
|
|
else if ( pGObj->GetType() == GEO_FRAME3D) {
|
|
// recupero il frame
|
|
const IGeoFrame3d* pGF = GetGeoFrame3d( pGObj) ;
|
|
Point3d ptStart = pGF->GetFrame().Orig() ;
|
|
// assegno il punto
|
|
ptP[0] = ptStart.x ;
|
|
ptP[1] = ptStart.y ;
|
|
ptP[2] = ptStart.z ;
|
|
return TRUE ;
|
|
}
|
|
// se curva
|
|
else if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
Point3d ptStart ;
|
|
if ( ! pCrv->GetStartPoint( ptStart))
|
|
return FALSE ;
|
|
// assegno il punto
|
|
ptP[0] = ptStart.x ;
|
|
ptP[1] = ptStart.y ;
|
|
ptP[2] = ptStart.z ;
|
|
return TRUE ;
|
|
}
|
|
// se testo
|
|
else if ( pGObj->GetType() == EXT_TEXT) {
|
|
// recupero il testo
|
|
const IExtText* pTxt = GetExtText( pGObj) ;
|
|
Point3d ptStart ;
|
|
if ( ! pTxt->GetStartPoint( ptStart))
|
|
return false ;
|
|
// assegno il punto
|
|
ptP[0] = ptStart.x ;
|
|
ptP[1] = ptStart.y ;
|
|
ptP[2] = ptStart.z ;
|
|
return TRUE ;
|
|
}
|
|
return FALSE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtEndPoint( int nId, double ptP[3])
|
|
{
|
|
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) ;
|
|
Point3d ptEnd ;
|
|
if ( ! pCrv->GetEndPoint( ptEnd))
|
|
return FALSE ;
|
|
// assegno il punto
|
|
ptP[0] = ptEnd.x ;
|
|
ptP[1] = ptEnd.y ;
|
|
ptP[2] = ptEnd.z ;
|
|
return TRUE ;
|
|
}
|
|
// se testo
|
|
else if ( pGObj->GetType() == EXT_TEXT) {
|
|
// recupero il testo
|
|
const IExtText* pTxt = GetExtText( pGObj) ;
|
|
Point3d ptEnd ;
|
|
if ( ! pTxt->GetEndPoint( ptEnd))
|
|
return false ;
|
|
// assegno il punto
|
|
ptP[0] = ptEnd.x ;
|
|
ptP[1] = ptEnd.y ;
|
|
ptP[2] = ptEnd.z ;
|
|
return TRUE ;
|
|
}
|
|
return FALSE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtMidPoint( int nId, double ptP[3])
|
|
{
|
|
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) ;
|
|
Point3d ptEnd ;
|
|
if ( ! pCrv->GetMidPoint( ptEnd))
|
|
return FALSE ;
|
|
// assegno il punto
|
|
ptP[0] = ptEnd.x ;
|
|
ptP[1] = ptEnd.y ;
|
|
ptP[2] = ptEnd.z ;
|
|
return TRUE ;
|
|
}
|
|
// se testo
|
|
else if ( pGObj->GetType() == EXT_TEXT) {
|
|
// recupero il testo
|
|
const IExtText* pTxt = GetExtText( pGObj) ;
|
|
Point3d ptEnd ;
|
|
if ( ! pTxt->GetMidPoint( ptEnd))
|
|
return false ;
|
|
// assegno il punto
|
|
ptP[0] = ptEnd.x ;
|
|
ptP[1] = ptEnd.y ;
|
|
ptP[2] = ptEnd.z ;
|
|
return TRUE ;
|
|
}
|
|
return FALSE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtCenterPoint( int nId, double ptP[3])
|
|
{
|
|
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) ;
|
|
Point3d ptEnd ;
|
|
if ( ! pCrv->GetCenterPoint( ptEnd))
|
|
return FALSE ;
|
|
// assegno il punto
|
|
ptP[0] = ptEnd.x ;
|
|
ptP[1] = ptEnd.y ;
|
|
ptP[2] = ptEnd.z ;
|
|
return TRUE ;
|
|
}
|
|
// se testo
|
|
else if ( pGObj->GetType() == EXT_TEXT) {
|
|
// recupero il testo
|
|
const IExtText* pTxt = GetExtText( pGObj) ;
|
|
Point3d ptEnd ;
|
|
if ( ! pTxt->GetCenterPoint( ptEnd))
|
|
return false ;
|
|
// assegno il punto
|
|
ptP[0] = ptEnd.x ;
|
|
ptP[1] = ptEnd.y ;
|
|
ptP[2] = ptEnd.z ;
|
|
return TRUE ;
|
|
}
|
|
return FALSE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtAtParamPoint( int nId, double dU, double ptP[3])
|
|
{
|
|
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) ;
|
|
Point3d ptStart ;
|
|
if ( ! pCrv->GetPointD1D2( dU, ICurve::FROM_MINUS, ptStart))
|
|
return FALSE ;
|
|
// assegno il punto
|
|
ptP[0] = ptStart.x ;
|
|
ptP[1] = ptStart.y ;
|
|
ptP[2] = ptStart.z ;
|
|
return TRUE ;
|
|
}
|
|
return FALSE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtStartVector( int nId, double vtV[3])
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, FALSE)
|
|
// se non è entità geometrica
|
|
const IGeoObj* pGObj ;
|
|
if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr)
|
|
return FALSE ;
|
|
// se vettore
|
|
if ( pGObj->GetType() == GEO_VECT3D) {
|
|
// recupero il geo-vettore
|
|
const IGeoVector3d* pGV = GetGeoVector3d( pGObj) ;
|
|
Vector3d vtDir = pGV->GetVector() ;
|
|
// assegno il vettore
|
|
vtV[0] = vtDir.x ;
|
|
vtV[1] = vtDir.y ;
|
|
vtV[2] = vtDir.z ;
|
|
return TRUE ;
|
|
}
|
|
// se curva
|
|
else if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGObj) ;
|
|
Vector3d vtDir ;
|
|
if ( ! pCrv->GetStartDir( vtDir))
|
|
return FALSE ;
|
|
// assegno il vettore
|
|
vtV[0] = vtDir.x ;
|
|
vtV[1] = vtDir.y ;
|
|
vtV[2] = vtDir.z ;
|
|
return TRUE ;
|
|
}
|
|
return FALSE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtEndVector( int nId, double vtV[3])
|
|
{
|
|
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) ;
|
|
Vector3d vtDir ;
|
|
if ( ! pCrv->GetEndDir( vtDir))
|
|
return FALSE ;
|
|
// assegno il vettore
|
|
vtV[0] = vtDir.x ;
|
|
vtV[1] = vtDir.y ;
|
|
vtV[2] = vtDir.z ;
|
|
return TRUE ;
|
|
}
|
|
return FALSE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtMidVector( int nId, double vtV[3])
|
|
{
|
|
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) ;
|
|
Vector3d vtDir ;
|
|
if ( ! pCrv->GetMidDir( vtDir))
|
|
return FALSE ;
|
|
// assegno il vettore
|
|
vtV[0] = vtDir.x ;
|
|
vtV[1] = vtDir.y ;
|
|
vtV[2] = vtDir.z ;
|
|
return TRUE ;
|
|
}
|
|
return FALSE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtAtParamVector( int nId, double dU, int nSide, double vtV[3])
|
|
{
|
|
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
|
|
Vector3d vtDir ;
|
|
Point3d ptP ;
|
|
if ( ! pCrv->GetPointTang( dU, nSide, ptP, vtDir))
|
|
return false ;
|
|
// assegno il vettore
|
|
vtV[0] = vtDir.x ;
|
|
vtV[1] = vtDir.y ;
|
|
vtV[2] = vtDir.z ;
|
|
return TRUE ;
|
|
}
|
|
return FALSE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtFrame( int nId, double ptOrig[3], double vtX[3], double vtY[3], double vtZ[3])
|
|
{
|
|
// recupero il frame
|
|
Frame3d frFrame ;
|
|
if ( ! EgtFrame( nId, frFrame))
|
|
return FALSE ;
|
|
// assegno l'origine
|
|
ptOrig[0] = frFrame.Orig().x ;
|
|
ptOrig[1] = frFrame.Orig().y ;
|
|
ptOrig[2] = frFrame.Orig().z ;
|
|
// assegno il versore X
|
|
vtX[0] = frFrame.VersX().x ;
|
|
vtX[1] = frFrame.VersX().y ;
|
|
vtX[2] = frFrame.VersX().z ;
|
|
// assegno il versore Y
|
|
vtY[0] = frFrame.VersY().x ;
|
|
vtY[1] = frFrame.VersY().y ;
|
|
vtY[2] = frFrame.VersY().z ;
|
|
// assegno il versore Z
|
|
vtZ[0] = frFrame.VersZ().x ;
|
|
vtZ[1] = frFrame.VersZ().y ;
|
|
vtZ[2] = frFrame.VersZ().z ;
|
|
return TRUE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtFrame( int nId, Frame3d& frFrame)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, FALSE)
|
|
// se gruppo
|
|
if ( pGeomDB->GetGroupFrame( nId, frFrame))
|
|
return TRUE ;
|
|
// se geo frame
|
|
const IGeoObj* pGObj ;
|
|
if ( ( pGObj = pGeomDB->GetGeoObj( nId)) != nullptr &&
|
|
pGObj->GetType() == GEO_FRAME3D) {
|
|
frFrame = GetGeoFrame3d( pGObj)->GetFrame() ;
|
|
return TRUE ;
|
|
}
|
|
// altrimenti errore
|
|
return FALSE ;
|
|
} |