Files
Dario Sassi dbd7a96277 EgtExecutor 1.9j3 :
- aggiunta funzione Exe e Lua CreateSurfTmConvexHullInBBox.
2018-10-12 07:34:13 +00:00

321 lines
10 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : GeoTools.cpp Data : 01.02.15 Versione : 1.6b1
// Contenuto : Funzioni geometriche ausiliarie.
//
//
//
// Modifiche : 01.02.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "EXE.h"
#include "EXE_Macro.h"
#include "GeoTools.h"
#include "/EgtDev/Include/EGkGeomDB.h"
#include "/EgtDev/Include/EXeConst.h"
//----------------------------------------------------------------------------
int
AdjustId( int nId)
{
GseContext* pCtx = GetCurrGseContext() ;
VERIFY_CTX( pCtx, GDB_ID_NULL)
if ( nId == GDB_ID_CURRPART)
return pCtx->m_nCurrPart ;
else if ( nId == GDB_ID_CURRLAYER)
return pCtx->m_nCurrLayer ;
else if ( nId <= GDB_ID_NULL)
return GDB_ID_NULL ;
else
return nId ;
}
//----------------------------------------------------------------------------
Vector3d
GetVectorLocal( IGeomDB* pGeomDB, const Vector3d& vtV, int nRefType, const Frame3d& frLoc)
{
Vector3d vtVL( vtV) ;
if ( nRefType == RTY_GLOB)
vtVL.ToLoc( frLoc) ;
else if ( nRefType == RTY_GRID)
vtVL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
return vtVL ;
}
//----------------------------------------------------------------------------
Vector3d
GetVectorInRef( IGeomDB* pGeomDB, const Vector3d& vtV, const Frame3d& frLoc, int nRefType)
{
Vector3d vtVL( vtV) ;
if ( nRefType == RTY_GLOB)
vtVL.ToGlob( frLoc) ;
else if ( nRefType == RTY_GRID)
vtVL.LocToLoc( frLoc, pGeomDB->GetGridFrame()) ;
return vtVL ;
}
//----------------------------------------------------------------------------
Point3d
GetPointLocal( IGeomDB* pGeomDB, const Point3d& ptP, int nRefType, const Frame3d& frLoc)
{
Point3d ptPL( ptP) ;
if ( nRefType == RTY_GLOB)
ptPL.ToLoc( frLoc) ;
else if ( nRefType == RTY_GRID)
ptPL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
return ptPL ;
}
//----------------------------------------------------------------------------
Point3d
GetPointInRef( IGeomDB* pGeomDB, const Point3d& ptP, const Frame3d& frLoc, int nRefType)
{
Point3d ptPL( ptP) ;
if ( nRefType == RTY_GLOB)
ptPL.ToGlob( frLoc) ;
else if ( nRefType == RTY_GRID)
ptPL.LocToLoc( frLoc, pGeomDB->GetGridFrame()) ;
return ptPL ;
}
//----------------------------------------------------------------------------
Plane3d
GetPlaneLocal( IGeomDB* pGeomDB, const Plane3d& plPlane, int nRefType, const Frame3d& frLoc)
{
Plane3d plPlaneL( plPlane) ;
if ( nRefType == RTY_GLOB)
plPlaneL.ToLoc( frLoc) ;
else if ( nRefType == RTY_GRID)
plPlaneL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
return plPlaneL ;
}
//----------------------------------------------------------------------------
Plane3d
GetPlaneInRef( IGeomDB* pGeomDB, const Plane3d& plPlane, const Frame3d& frLoc, int nRefType)
{
Plane3d plPlaneL( plPlane) ;
if ( nRefType == RTY_GLOB)
plPlaneL.ToGlob( frLoc) ;
else if ( nRefType == RTY_GRID)
plPlaneL.LocToLoc( frLoc, pGeomDB->GetGridFrame()) ;
return plPlaneL ;
}
//----------------------------------------------------------------------------
Frame3d
GetFrameLocal( IGeomDB* pGeomDB, const Frame3d& frRef, int nRefType, const Frame3d& frLoc)
{
Frame3d frRefL( frRef) ;
if ( nRefType == RTY_GLOB)
frRefL.ToLoc( frLoc) ;
else if ( nRefType == RTY_GRID)
frRefL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
return frRefL ;
}
//----------------------------------------------------------------------------
Frame3d
GetFrameInRef( IGeomDB* pGeomDB, const Frame3d& frRef, const Frame3d& frLoc, int nRefType)
{
Frame3d frRefL( frRef) ;
if ( nRefType == RTY_GLOB)
frRefL.ToGlob( frLoc) ;
else if ( nRefType == RTY_GRID)
frRefL.LocToLoc( frLoc, pGeomDB->GetGridFrame()) ;
return frRefL ;
}
//----------------------------------------------------------------------------
bool
TransformPoint( 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) ;
}
//----------------------------------------------------------------------------
bool
InvTransformPoint( 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) ;
}
//----------------------------------------------------------------------------
bool
TransformVector( 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) ;
}
//----------------------------------------------------------------------------
bool
InvTransformVector( IGeomDB* pGeomDB, int nId, int nRefId, Vector3d& vtV)
{
// 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 vtV.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 vtV.LocToLoc( frDest, frSou) ;
}
//----------------------------------------------------------------------------
bool
TransformFrame( 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
VerifySameFrame( IGeomDB* pGeomDB, const INTVECTOR& vIds)
{
// verifico puntatore a GeomDB
if ( pGeomDB == nullptr)
return false ;
// ciclo sul vettore degli identificativi
bool bFirst = true ;
Frame3d frFirst ;
for ( size_t i = 0 ; i < vIds.size() ; ++ i) {
// se si deve agire su un singolo oggetto ( gruppo o entità)
if ( vIds[i] != GDB_ID_SEL) {
Frame3d frLoc ;
if ( ! pGeomDB->GetGroupGlobFrame( vIds[i], frLoc) &&
! pGeomDB->GetGlobFrame( vIds[i], frLoc))
return false ;
if ( bFirst) {
frFirst = frLoc ;
bFirst = false ;
}
else {
if ( ! AreSameFrame( frFirst, frLoc))
return false ;
}
}
// altrimenti si deve agire sugli oggetti selezionati
else {
int nI = pGeomDB->GetFirstSelectedObj() ;
while ( nI != GDB_ID_NULL) {
Frame3d frLoc ;
if ( ! pGeomDB->GetGlobFrame( nI, frLoc))
return false ;
if ( bFirst) {
frFirst = frLoc ;
bFirst = false ;
}
else {
if ( ! AreSameFrame( frFirst, frLoc))
return false ;
}
// passo alla successiva
nI = pGeomDB->GetNextSelectedObj() ;
}
}
}
return true ;
}