589a58e8db
- aggiunta funzione Exe e Lua SurfTmGetEdges.
263 lines
9.5 KiB
C++
263 lines
9.5 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2020-2020
|
|
//----------------------------------------------------------------------------
|
|
// File : EXE_GeoSnap.cpp Data : 23.03.20 Versione : 2.2c3
|
|
// Contenuto : Funzioni di interrogazione di volumi del DBG per EXE.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 23.03.20 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/EGkVolZmap.h"
|
|
#include "/EgtDev/Include/EGkStringUtils3d.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeVolZmapVolume( int nId, double& dVol)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// verifico il parametro
|
|
if ( &dVol == nullptr)
|
|
return false ;
|
|
// recupero il solido Zmap
|
|
const IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nId)) ;
|
|
// ne restituisco il volume
|
|
return ( pVZM != nullptr && pVZM->GetVolume( dVol)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
ExeVolZmapResolution( int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, 0)
|
|
// recupero il solido Zmap
|
|
const IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pVZM == nullptr)
|
|
return 0 ;
|
|
// ne restituisco la risoluzione grafica
|
|
return pVZM->GetResolution() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
ExeVolZmapPartCount( int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, -1)
|
|
// recupero il solido Zmap
|
|
const IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pVZM == nullptr)
|
|
return -1 ;
|
|
// recupero il numero di parti
|
|
return pVZM->GetPartCount() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeVolZmapPartVolume( int nId, int nPart, double& dVol)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// verifico il parametro
|
|
if ( &dVol == nullptr)
|
|
return false ;
|
|
// recupero il solido Zmap
|
|
const IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nId)) ;
|
|
// restituisco il volume della eventuale parte richiesta
|
|
return ( pVZM != nullptr && pVZM->GetPartVolume( nPart, dVol)) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeVolZmapGetPartBBox( int nId, int nPart, int nFlag, BBox3d& b3Box)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero lo Zmap
|
|
IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pVZM == nullptr)
|
|
return false ;
|
|
// recupero il bounding box della parte dell'oggetto in locale
|
|
return pVZM->GetPartLocalBBox( nPart, b3Box, nFlag) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeVolZmapGetPartBBoxGlob( int nId, int nPart, int nFlag, BBox3d& b3Box)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero lo Zmap
|
|
IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pVZM == nullptr)
|
|
return false ;
|
|
// recupero il riferimento globale del gruppo cui appartiene
|
|
Frame3d frGlob ;
|
|
if ( nId != GDB_ID_ROOT && ! pGeomDB->GetGroupGlobFrame( pGeomDB->GetParentId( nId), frGlob))
|
|
return false ;
|
|
// recupero il bounding box della parte dell'oggetto in globale
|
|
return pVZM->GetPartBBox( nPart, frGlob, b3Box, nFlag) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeVolZmapGetPartMinDist( int nId, const Point3d ptNear, int nRefType, int& nPart)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// verifico il parametro
|
|
if ( &nPart == nullptr)
|
|
return false ;
|
|
// recupero il solido Zmap
|
|
const IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pVZM == nullptr)
|
|
return false ;
|
|
// recupero il riferimento del solido
|
|
Frame3d frVol ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frVol))
|
|
return false ;
|
|
// porto il punto Near nel riferimento dell'entità
|
|
Point3d ptNearL = GetPointLocal( pGeomDB, ptNear, nRefType, frVol) ;
|
|
// restituisco il volume della eventuale parte richiesta
|
|
nPart = pVZM->GetPartMinDistFromPoint( ptNearL) ;
|
|
return ( nPart >= 0) ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
int
|
|
ExeCopyVolZmapPart( int nId, int nPart, int nDestGrpId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero lo Zmap
|
|
IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pVZM == nullptr)
|
|
return GDB_ID_NULL ;
|
|
// recupero il suo riferimento globale
|
|
Frame3d frVZM ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frVZM))
|
|
return GDB_ID_NULL ;
|
|
// recupero il riferimento del gruppo di destinazione
|
|
Frame3d frDest ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest))
|
|
return GDB_ID_NULL ;
|
|
// copio la parte connessa
|
|
PtrOwner<IVolZmap> pPart( pVZM->ClonePart( nPart)) ;
|
|
if ( IsNull( pPart))
|
|
return GDB_ID_NULL ;
|
|
pPart->LocToLoc( frVZM, frDest) ;
|
|
// inserisco nel DB
|
|
int nVZMId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nDestGrpId, GDB_LAST_SON, Release( pPart)) ;
|
|
if ( nVZMId == GDB_ID_NULL)
|
|
return GDB_ID_NULL ;
|
|
// copio gli attributi
|
|
if ( ! pGeomDB->CopyAttributes( nId, nVZMId))
|
|
return GDB_ID_NULL ;
|
|
ExeSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "ExeCopyVolZmapPart(" + ToString( nId) + "," +
|
|
ToString( nPart) + "," +
|
|
ToString( nDestGrpId) + ")" +
|
|
" -- Id=" + ToString( nVZMId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
return nVZMId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeVolZmapGetDepth( int nId, const Point3d& ptP, const Vector3d& vtDir, int nRefType, bool bExact,
|
|
double& dInLen, double& dOutLen)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il riferimento locale
|
|
Frame3d frLoc ;
|
|
bool bOk = pGeomDB->GetGlobFrame( nId, frLoc) ;
|
|
// porto in locale il punto e il vettore
|
|
Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frLoc) ;
|
|
Vector3d vtVL = GetVectorLocal( pGeomDB, vtDir, nRefType, frLoc) ;
|
|
// recupero lo Zmap e calcolo profondità
|
|
IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nId)) ;
|
|
bOk = bOk && ( pVZM != nullptr && pVZM->GetDepth( ptPL, vtVL, dInLen, dOutLen, bExact)) ;
|
|
ExeSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtVolZmapGetDepth(" + IdToString( nId) + ",{" +
|
|
ToString( ptP) + "},{" +
|
|
ToString( vtDir) + "}," +
|
|
( bExact ? "true" : "false") + "," +
|
|
RefTypeToString( nRefType) + ")" +
|
|
" -- Ok=" + ToString( bOk) + "," + ToString( dInLen) + "," + ToString( dOutLen) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco risultato
|
|
return bOk ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
ExeVolZmapGetEdges( int nId, int nDestGrpId, int* pnCount)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero lo Zmap
|
|
const IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nId)) ;
|
|
bool bOk = ( pVZM != nullptr) ;
|
|
// recupero il riferimento del solido
|
|
Frame3d frSurf ;
|
|
bOk = bOk && pGeomDB->GetGlobFrame( nId, frSurf) ;
|
|
// recupero il riferimento di destinazione
|
|
Frame3d frDest ;
|
|
bOk = bOk && pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest) ;
|
|
// ne determino gli spigoli
|
|
ICURVEPOVECTOR vpCurve ;
|
|
bOk = bOk && pVZM->GetEdges( vpCurve) ;
|
|
// inserisco gli spigoli come curve nel DB
|
|
int nFirstId = GDB_ID_NULL ;
|
|
int nCount = 0 ;
|
|
for ( int i = 0 ; i < int( vpCurve.size()) ; ++ i) {
|
|
// lo porto nel riferimento destinazione
|
|
bOk = bOk && vpCurve[i]->LocToLoc( frSurf, frDest) ;
|
|
// lo inserisco nel DB geometrico
|
|
int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( vpCurve[i])) : GDB_ID_NULL) ;
|
|
bOk = bOk && ( nNewId != GDB_ID_NULL) ;
|
|
// copio il materiale
|
|
bOk = bOk && pGeomDB->CopyMaterial( nId, nNewId) ;
|
|
// aggiorno contatori
|
|
if ( bOk && nFirstId == GDB_ID_NULL)
|
|
nFirstId = nNewId ;
|
|
if ( bOk)
|
|
++ nCount ;
|
|
}
|
|
ExeSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtVolZmapGetEdges(" + ToString( nId) + ",{" +
|
|
ToString( nDestGrpId) + ")" +
|
|
" -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco risultati
|
|
if ( pnCount != nullptr)
|
|
*pnCount = nCount ;
|
|
return nFirstId ;
|
|
}
|