EgtInterface 1.6e2 :
- esecutore e lua scorporato in EgtExecutor.
This commit is contained in:
+27
-682
@@ -14,20 +14,8 @@
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "API.h"
|
||||
#include "API_Macro.h"
|
||||
#include "AuxTools.h"
|
||||
#include "GeoTools.h"
|
||||
#include "/EgtDev/Include/EInAPI.h"
|
||||
#include "/EgtDev/Include/EInConst.h"
|
||||
#include "/EgtDev/Include/EGkCurve.h"
|
||||
#include "/EgtDev/Include/EGkCurveArc.h"
|
||||
#include "/EgtDev/Include/EGkCurveBezier.h"
|
||||
#include "/EgtDev/Include/EGkCurveComposite.h"
|
||||
#include "/EgtDev/Include/EGkDistPointCurve.h"
|
||||
#include "/EgtDev/Include/EGkExtTExt.h"
|
||||
#include "/EgtDev/Include/EGkGdbIterator.h"
|
||||
#include "/EgtDev/Include/EGkStringUtils3d.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
#include "/EgtDev/Include/EXeExecutor.h"
|
||||
|
||||
using namespace std ;
|
||||
|
||||
@@ -37,196 +25,35 @@ __stdcall EgtInvertCurve( int nId)
|
||||
{
|
||||
INTVECTOR vIds ;
|
||||
vIds.push_back( nId) ;
|
||||
return ( EgtInvertCurve( vIds) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
EgtInvertCurve( const INTVECTOR& vIds)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, false)
|
||||
// eseguo inversione
|
||||
bool bOk = true ;
|
||||
for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) {
|
||||
int nId = (( vIds[i] != GDB_ID_SEL) ? vIds[i] : pGeomDB->GetFirstSelectedObj()) ;
|
||||
while ( nId != GDB_ID_NULL && bOk) {
|
||||
// recupero la curva e la inverto
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pCurve != nullptr && ! pCurve->Invert())
|
||||
bOk = false ;
|
||||
// passo alla successiva
|
||||
nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ;
|
||||
}
|
||||
}
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtInvertCurve({" + IdListToString( vIds) + "})" +
|
||||
" -- Ok=" + ToString( bOk) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco risultato
|
||||
return bOk ;
|
||||
return ( ExeInvertCurve( vIds) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtOffsetCurve( int nId, double dDist, int nType)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, FALSE)
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
// eseguo l'offset
|
||||
bool bOk = ( pCurve != nullptr) && pCurve->SimpleOffset( dDist, nType) ;
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua ;
|
||||
sLua = "EgtOffsetCurve(" + ToString( nId) + "," +
|
||||
ToString( dDist) + "," +
|
||||
OffsTypeToString( nType) + ")" +
|
||||
" -- Ok=" + ToString( bOk) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco risultato
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
return ( ExeOffsetCurve( nId, dDist, nType) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtChangeClosedCurveStartPoint( int nId, const double ptP[3], int nRefType)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, FALSE)
|
||||
bool bOk = true ;
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
bOk = bOk && ( pCurve != nullptr) ;
|
||||
// recupero il riferimento locale
|
||||
Frame3d frLoc ;
|
||||
bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ;
|
||||
// porto in locale il punto vicino ad iniziale
|
||||
Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frLoc) ;
|
||||
// recupero la posizione parametrica della proiezione di questo punto sulla curva
|
||||
DistPointCurve distPC( ptPL, *pCurve) ;
|
||||
double dPar ;
|
||||
int nFlag ;
|
||||
bOk = bOk && distPC.GetParamAtMinDistPoint( 0, dPar, nFlag) ;
|
||||
// cambio il punto iniziale
|
||||
if ( bOk && pCurve->GetType() == CRV_ARC)
|
||||
bOk = bOk && dynamic_cast<ICurveArc*>(pCurve)->ChangeStartPoint(dPar) ;
|
||||
else if ( bOk && pCurve->GetType() == CRV_COMPO)
|
||||
bOk = bOk && dynamic_cast<ICurveComposite*>(pCurve)->ChangeStartPoint(dPar) ;
|
||||
else
|
||||
bOk = false ;
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtChangeClosedCurveStartPoint(" + ToString( nId) + ",{" +
|
||||
ToString( Point3d( ptP)) + "}," +
|
||||
RefTypeToString( nRefType) + ")" +
|
||||
" -- Ok=" + ToString( bOk) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco il risultato
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
return ( ExeChangeClosedCurveStartPoint( nId, ptP, nRefType) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtModifyCurveStartPoint( int nId, const double ptP[3], int nRefType)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, FALSE)
|
||||
bool bOk = true ;
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
bOk = bOk && ( pCurve != nullptr) ;
|
||||
// recupero il riferimento locale
|
||||
Frame3d frLoc ;
|
||||
bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ;
|
||||
// porto in locale il nuovo punto iniziale
|
||||
Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frLoc) ;
|
||||
// ne modifico il punto iniziale
|
||||
bOk = bOk && pCurve->ModifyStart( ptPL) ;
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtModifyCurveStartPoint(" + ToString( nId) + ",{" +
|
||||
ToString( Point3d( ptP)) + "}," +
|
||||
RefTypeToString( nRefType) + ")" +
|
||||
" -- Ok=" + ToString( bOk) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco il risultato
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
return ( ExeModifyCurveStartPoint( nId, ptP, nRefType) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtModifyCurveEndPoint( int nId, const double ptP[3], int nRefType)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, FALSE)
|
||||
bool bOk = true ;
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
bOk = bOk && ( pCurve != nullptr) ;
|
||||
// recupero il riferimento locale
|
||||
Frame3d frLoc ;
|
||||
bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ;
|
||||
// porto in locale il nuovo punto finale
|
||||
Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frLoc) ;
|
||||
// ne modifico il punto finale
|
||||
bOk = bOk && pCurve->ModifyEnd( ptPL) ;
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtModifyCurveEndPoint(" + ToString( nId) + ",{" +
|
||||
ToString( Point3d( ptP)) + "}," +
|
||||
RefTypeToString( nRefType) + ")" +
|
||||
" -- Ok=" + ToString( bOk) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco il risultato
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static bool
|
||||
ModifyOneCurveExtrusion( IGeomDB* pGeomDB, int nId, const Vector3d& vtExtr, int nRefType)
|
||||
{
|
||||
// recupero il riferimento locale
|
||||
Frame3d frLoc ;
|
||||
if ( ! pGeomDB->GetGroupGlobFrame( nId, frLoc) &&
|
||||
! pGeomDB->GetGlobFrame( nId, frLoc))
|
||||
return false ;
|
||||
// porto in locale il versore estrusione
|
||||
Vector3d vtExtrL = GetVectorLocal( pGeomDB, vtExtr.v, nRefType, frLoc) ;
|
||||
// se gruppo, agisco sulle sole curve componenti
|
||||
if ( pGeomDB->GetGdbType( nId) == GDB_TY_GROUP) {
|
||||
PtrOwner<IGdbIterator> pIter( CreateGdbIterator( pGeomDB)) ;
|
||||
if ( IsNull( pIter))
|
||||
return false ;
|
||||
for ( bool bFound = pIter->GoToFirstInGroup( nId) ;
|
||||
bFound ;
|
||||
bFound = pIter->GoToNext()) {
|
||||
// recupero la curva e ne modifico il vettore estrusione
|
||||
ICurve* pCurve = GetCurve( pIter->GetGeoObj()) ;
|
||||
if ( pCurve != nullptr && ! pCurve->SetExtrusion( vtExtrL))
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
// se oggetto geometrico
|
||||
else {
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
// ne modifico il vettore estrusione
|
||||
return ( pCurve == nullptr || pCurve->SetExtrusion( vtExtrL)) ;
|
||||
}
|
||||
return ( ExeModifyCurveEndPoint( nId, ptP, nRefType) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -235,76 +62,7 @@ __stdcall EgtModifyCurveExtrusion( int nId, const double vtExtr[3], int nRefType
|
||||
{
|
||||
INTVECTOR vIds ;
|
||||
vIds.push_back( nId) ;
|
||||
return ( EgtModifyCurveExtrusion( vIds, vtExtr, nRefType) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
EgtModifyCurveExtrusion( const INTVECTOR& vIds, const Vector3d& vtExtr, int nRefType)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, false)
|
||||
bool bOk = true ;
|
||||
// se estrusione espressa in locale, verifico che tutte le curve siano nello stesso riferimento
|
||||
if ( nRefType == RTY_LOC)
|
||||
bOk = bOk && VerifySameFrame( pGeomDB, vIds) ;
|
||||
// ciclo sul vettore degli identificativi
|
||||
for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) {
|
||||
// impostazione estrusione singola
|
||||
if ( vIds[i] != GDB_ID_SEL) {
|
||||
bOk = bOk && ModifyOneCurveExtrusion( pGeomDB, vIds[i], vtExtr, nRefType) ;
|
||||
}
|
||||
// impostazione estrusione dei selezionati
|
||||
else {
|
||||
int nI = pGeomDB->GetFirstSelectedObj() ;
|
||||
while ( nI != GDB_ID_NULL && bOk) {
|
||||
if ( ! ModifyOneCurveExtrusion( pGeomDB, nI, vtExtr, nRefType))
|
||||
bOk = false ;
|
||||
// passo alla successiva
|
||||
nI = pGeomDB->GetNextSelectedObj() ;
|
||||
}
|
||||
}
|
||||
}
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtModifyCurveExtrusion({" + IdListToString( vIds) + "},{" +
|
||||
ToString( Vector3d( vtExtr)) + "}," +
|
||||
RefTypeToString( nRefType) + ")" +
|
||||
" -- Ok=" + ToString( bOk) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco risultato
|
||||
return bOk ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static bool
|
||||
ModifyOneCurveThickness( IGeomDB* pGeomDB, int nId, double dThick)
|
||||
{
|
||||
// se gruppo, agisco sulle sole curve componenti
|
||||
if ( pGeomDB->GetGdbType( nId) == GDB_TY_GROUP) {
|
||||
PtrOwner<IGdbIterator> pIter( CreateGdbIterator( pGeomDB)) ;
|
||||
if ( IsNull( pIter))
|
||||
return false ;
|
||||
bool bOk = true ;
|
||||
for ( bool bFound = pIter->GoToFirstInGroup( nId) ;
|
||||
bFound ;
|
||||
bFound = pIter->GoToNext()) {
|
||||
// recupero la curva e ne modifico lo spessore
|
||||
ICurve* pCurve = GetCurve( pIter->GetGeoObj()) ;
|
||||
if ( pCurve != nullptr && ! pCurve->SetThickness( dThick))
|
||||
bOk = false ;
|
||||
}
|
||||
return bOk ;
|
||||
}
|
||||
// se oggetto geometrico
|
||||
else {
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
// ne modifico lo spessore, se curva
|
||||
return ( pCurve == nullptr || pCurve->SetThickness( dThick)) ;
|
||||
}
|
||||
return ( ExeModifyCurveExtrusion( vIds, vtExtr, nRefType) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -313,537 +71,124 @@ __stdcall EgtModifyCurveThickness( int nId, double dThick)
|
||||
{
|
||||
INTVECTOR vIds ;
|
||||
vIds.push_back( nId) ;
|
||||
return ( EgtModifyCurveThickness( vIds, dThick) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
EgtModifyCurveThickness( const INTVECTOR& vIds, double dThick)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
bool bOk = true ;
|
||||
// ciclo sul vettore degli identificativi
|
||||
for ( size_t i = 0 ; i < vIds.size() && bOk ; ++ i) {
|
||||
// eseguo impostazione spessore singola
|
||||
if ( vIds[i] != GDB_ID_SEL) {
|
||||
bOk = bOk && ModifyOneCurveThickness( pGeomDB, vIds[i], dThick) ;
|
||||
}
|
||||
// eseguo impostazione spessore dei selezionati
|
||||
else {
|
||||
int nI = pGeomDB->GetFirstSelectedObj() ;
|
||||
while ( nI != GDB_ID_NULL && bOk) {
|
||||
if ( ! ModifyOneCurveThickness( pGeomDB, nI, dThick))
|
||||
bOk = false ;
|
||||
// passo alla successiva
|
||||
nI = pGeomDB->GetNextSelectedObj() ;
|
||||
}
|
||||
}
|
||||
}
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtModifyCurveThickness({" + IdListToString( vIds) + "}," +
|
||||
ToString( dThick) + ")" +
|
||||
" -- Ok=" + ToString( bOk) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco risultato
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
return ( ExeModifyCurveThickness( vIds, dThick) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtTrimCurveStartAtLen( int nId, double dLen)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pCurve == nullptr)
|
||||
return FALSE ;
|
||||
// taglio la curva all'inizio
|
||||
bool bOk = pCurve->TrimStartAtLen( dLen) ;
|
||||
EgtSetModified() ;
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
return ( ExeTrimCurveStartAtLen( nId, dLen) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtTrimCurveEndAtLen( int nId, double dLen)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pCurve == nullptr)
|
||||
return FALSE ;
|
||||
// taglio la curva alla fine
|
||||
bool bOk = pCurve->TrimEndAtLen( dLen) ;
|
||||
EgtSetModified() ;
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
return ( ExeTrimCurveEndAtLen( nId, dLen) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtTrimCurveStartAtParam( int nId, double dPar)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pCurve == nullptr)
|
||||
return FALSE ;
|
||||
// taglio la curva all'inizio
|
||||
bool bOk = pCurve->TrimStartAtParam( dPar) ;
|
||||
EgtSetModified() ;
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
return ( ExeTrimCurveStartAtParam( nId, dPar) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtTrimCurveEndAtParam( int nId, double dPar)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pCurve == nullptr)
|
||||
return FALSE ;
|
||||
// taglio la curva alla fine
|
||||
bool bOk = pCurve->TrimEndAtParam( dPar) ;
|
||||
EgtSetModified() ;
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
return ( ExeTrimCurveEndAtParam( nId, dPar) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtTrimCurveStartEndAtParam( int nId, double dParS, double dParE)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pCurve == nullptr)
|
||||
return FALSE ;
|
||||
// taglio la curva agli estremi
|
||||
bool bOk = pCurve->TrimStartEndAtParam( dParS, dParE) ;
|
||||
EgtSetModified() ;
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
return ( ExeTrimCurveStartEndAtParam( nId, dParS, dParE) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtExtendCurveStartByLen( int nId, double dLen)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pCurve == nullptr)
|
||||
return FALSE ;
|
||||
// estendo la curva all'inizio
|
||||
bool bOk = pCurve->ExtendStartByLen( dLen) ;
|
||||
EgtSetModified() ;
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
return ( ExeExtendCurveStartByLen( nId, dLen) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtExtendCurveEndByLen( int nId, double dLen)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pCurve == nullptr)
|
||||
return FALSE ;
|
||||
// estendo la curva alla fine
|
||||
bool bOk = pCurve->ExtendEndByLen( dLen) ;
|
||||
EgtSetModified() ;
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
return ( ExeExtendCurveEndByLen( nId, dLen) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtTrimExtendCurveByLen( int nId, double dLen, const double ptNear[3], int nRefType)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
bool bOk = ( pCurve != nullptr) ;
|
||||
// recupero il riferimento locale
|
||||
Frame3d frLoc ;
|
||||
bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ;
|
||||
// porto in locale il punto
|
||||
Point3d ptNearL = GetPointLocal( pGeomDB, ptNear, nRefType, frLoc) ;
|
||||
// cerco l'estremo più vicino al punto passato
|
||||
Point3d ptStart, ptEnd ;
|
||||
if ( bOk && pCurve->GetStartPoint( ptStart) && pCurve->GetEndPoint( ptEnd)) {
|
||||
if ( SqDist( ptStart, ptNearL) < SqDist( ptEnd, ptNearL)) {
|
||||
if ( dLen < - EPS_SMALL)
|
||||
bOk = pCurve->TrimStartAtLen( - dLen) ;
|
||||
else if ( dLen > EPS_SMALL)
|
||||
bOk = pCurve->ExtendStartByLen( dLen) ;
|
||||
}
|
||||
else {
|
||||
if ( dLen < - EPS_SMALL) {
|
||||
double dCrvLen ;
|
||||
bOk = pCurve->GetLength( dCrvLen) && pCurve->TrimEndAtLen( dCrvLen + dLen) ;
|
||||
}
|
||||
else if ( dLen > EPS_SMALL)
|
||||
bOk = pCurve->ExtendEndByLen( dLen) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
bOk = false ;
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtTrimExtendCurveByLen(" + ToString( nId) + "," +
|
||||
ToString( dLen) + ",{" +
|
||||
ToString( Point3d( ptNear)) + "}," +
|
||||
RefTypeToString( nRefType) + ")" +
|
||||
" -- Ok=" + ToString( bOk) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco risultato
|
||||
return ( bOk ? TRUE : FALSE) ;
|
||||
return ( ExeTrimExtendCurveByLen( nId, dLen, ptNear, nRefType) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
__stdcall EgtSplitCurve( int nId, int nParts)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
bool bOk = ( pCurve != nullptr) ;
|
||||
// il numero di parti non può essere inferiore a 1
|
||||
nParts = max( nParts, 1) ;
|
||||
// lunghezza totale della curva
|
||||
double dLenTot = 0 ;
|
||||
bOk = bOk && pCurve->GetLength( dLenTot) ;
|
||||
// lunghezza di una parte
|
||||
double dLen = dLenTot / nParts ;
|
||||
// eseguo la divisione
|
||||
int nFirstId = GDB_ID_NULL ;
|
||||
int nCurrId = nId ;
|
||||
for ( int i = 1; i < nParts ; ++ i) {
|
||||
// copio la curva
|
||||
int nCopyId = pGeomDB->Copy( nCurrId, GDB_ID_NULL, nCurrId, GDB_AFTER) ;
|
||||
ICurve* pCopyCrv = GetCurve( pGeomDB->GetGeoObj( nCopyId)) ;
|
||||
bOk = bOk && ( pCopyCrv != nullptr) ;
|
||||
// tengo la prima parte dell'originale e la seconda parte della copia
|
||||
bOk = bOk && pCurve->TrimEndAtLen( dLen) ;
|
||||
bOk = bOk && pCopyCrv->TrimStartAtLen( dLen) ;
|
||||
// la copia diventa il nuovo corrente
|
||||
nCurrId = nCopyId ;
|
||||
pCurve = pCopyCrv ;
|
||||
// salvo identificativo prima copia
|
||||
if ( nFirstId == GDB_ID_NULL)
|
||||
nFirstId = nCopyId ;
|
||||
}
|
||||
nFirstId = ( bOk ? nFirstId : GDB_ID_NULL) ;
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtSplitCurve(" + ToString( nId) + "," +
|
||||
ToString( nParts) + ")" +
|
||||
" -- Id1=" + ToString( nFirstId) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco risultato
|
||||
return nFirstId ;
|
||||
return ExeSplitCurve( nId, nParts) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
__stdcall EgtSplitCurveAtPoint( int nId, double ptOn[3], int nRefType)
|
||||
__stdcall EgtSplitCurveAtPoint( int nId, const double ptOn[3], int nRefType)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero la curva
|
||||
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
||||
bool bOk = ( pCurve != nullptr) ;
|
||||
// recupero il riferimento locale
|
||||
Frame3d frLoc ;
|
||||
bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ;
|
||||
// porto in locale il punto
|
||||
Point3d ptOnL = GetPointLocal( pGeomDB, ptOn, nRefType, frLoc) ;
|
||||
// determino la posizione parametrica del punto sulla curva (con tolleranza)
|
||||
double dU = 0 ;
|
||||
if ( bOk) {
|
||||
DistPointCurve dstPC( ptOnL, *pCurve) ;
|
||||
int nFlag ;
|
||||
if ( ! dstPC.GetParamAtMinDistPoint( 0, dU, nFlag) || nFlag != MDPCI_NORMAL)
|
||||
bOk = false ;
|
||||
}
|
||||
// verifico che il punto di taglio sia interno alla curva
|
||||
bool bIsInside = false ;
|
||||
if ( bOk) {
|
||||
Point3d ptStart ;
|
||||
Point3d ptEnd ;
|
||||
Point3d ptBreak ;
|
||||
if ( pCurve->GetStartPoint( ptStart) &&
|
||||
pCurve->GetEndPoint( ptEnd) &&
|
||||
pCurve->GetPointD1D2( dU, ICurve::FROM_MINUS, ptBreak)) {
|
||||
bIsInside = ! AreSamePointApprox( ptBreak, ptStart) &&
|
||||
! AreSamePointApprox( ptBreak, ptEnd) ;
|
||||
}
|
||||
}
|
||||
// se il punto di taglio è interno, devo realmente tagliare
|
||||
int nNewId = GDB_ID_NULL ;
|
||||
if ( bIsInside) {
|
||||
// copio la curva
|
||||
nNewId = pGeomDB->Copy( nId, GDB_ID_NULL, nId, GDB_AFTER) ;
|
||||
ICurve* pCopyCrv = GetCurve( pGeomDB->GetGeoObj( nNewId)) ;
|
||||
bOk = bOk && ( pCopyCrv != nullptr) ;
|
||||
// tengo la prima parte dell'originale e la seconda parte della copia
|
||||
bOk = bOk && pCurve->TrimEndAtParam( dU) ;
|
||||
bOk = bOk && pCopyCrv->TrimStartAtParam( dU) ;
|
||||
}
|
||||
nNewId = ( bOk ? nNewId : GDB_ID_NULL) ;
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtSplitCurveAtPoint(" + ToString( nId) + ",{" +
|
||||
ToString( Point3d( ptOn)) + "}," +
|
||||
RefTypeToString( nRefType) + ")" +
|
||||
" -- Id=" + ToString( nNewId) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco risultato
|
||||
return nNewId ;
|
||||
return ExeSplitCurveAtPoint( nId, ptOn, nRefType) ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtModifyCurveCircleCPN( int nId, const double ptOn[3], int nRefType)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, FALSE)
|
||||
// recupero l'arco e i suoi dati
|
||||
ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pArc == nullptr)
|
||||
return FALSE ;
|
||||
Point3d ptCen = pArc->GetCenter() ;
|
||||
Vector3d vtN = pArc->GetNormVersor() ;
|
||||
double dOldRad = pArc->GetRadius() ;
|
||||
// recupero il riferimento locale
|
||||
Frame3d frLoc ;
|
||||
if ( ! pGeomDB->GetGlobFrame( nId, frLoc))
|
||||
return FALSE ;
|
||||
// porto in locale il nuovo punto
|
||||
Point3d ptOnL = GetPointLocal( pGeomDB, ptOn, nRefType, frLoc) ;
|
||||
// calcolo il nuovo raggio
|
||||
double dRad = (( ptOnL - ptCen) ^ vtN).Len() ;
|
||||
// imposto il nuovo raggio
|
||||
if ( pArc->Set( ptCen, vtN, dRad))
|
||||
return TRUE ;
|
||||
// in caso di errore, ripristino i vecchi dati
|
||||
else {
|
||||
pArc->Set( ptCen, vtN, dOldRad) ;
|
||||
return FALSE ;
|
||||
}
|
||||
return ( ExeModifyCurveCircleCPN( nId, ptOn, nRefType) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtModifyCurveArcRadius( int nId, double dRad)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, FALSE)
|
||||
// recupero l'arco e i suoi dati
|
||||
ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pArc == nullptr)
|
||||
return FALSE ;
|
||||
double dOldRad = pArc->GetRadius() ;
|
||||
// imposto il nuovo raggio
|
||||
if ( pArc->ChangeRadius( dRad))
|
||||
return TRUE ;
|
||||
// in caso di errore, ripristino i vecchi dati
|
||||
else {
|
||||
pArc->ChangeRadius( dOldRad) ;
|
||||
return FALSE ;
|
||||
}
|
||||
return ( ExeModifyCurveArcRadius( nId, dRad) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtModifyCurveArcC2PN( int nId, const double ptEnd[3], int nRefType)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, FALSE)
|
||||
// recupero l'arco e i suoi dati
|
||||
ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pArc == nullptr)
|
||||
return FALSE ;
|
||||
Point3d ptCen = pArc->GetCenter() ;
|
||||
Vector3d vtN = pArc->GetNormVersor() ;
|
||||
Point3d ptStart, ptOldEnd ;
|
||||
if ( ! pArc->GetStartPoint( ptStart) || ! pArc->GetEndPoint( ptOldEnd))
|
||||
return FALSE ;
|
||||
// recupero il riferimento locale
|
||||
Frame3d frLoc ;
|
||||
if ( ! pGeomDB->GetGlobFrame( nId, frLoc))
|
||||
return FALSE ;
|
||||
// porto in locale il nuovo punto finale
|
||||
Point3d ptEndL = GetPointLocal( pGeomDB, ptEnd, nRefType, frLoc) ;
|
||||
// imposto il nuovo punto finale
|
||||
if ( pArc->SetC2PN( ptCen, ptStart, ptEndL, vtN))
|
||||
return TRUE ;
|
||||
// in caso di errore, ripristino i vecchi dati
|
||||
else {
|
||||
pArc->SetC2PN( ptCen, ptStart, ptOldEnd, vtN) ;
|
||||
return FALSE ;
|
||||
}
|
||||
return ( ExeModifyCurveArcC2PN( nId, ptEnd, nRefType) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
BOOL
|
||||
__stdcall EgtModifyCurveArc3P( int nId, const double ptMid[3], int nRefType)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, FALSE)
|
||||
// recupero l'arco e i suoi punti notevoli
|
||||
ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( pArc == nullptr)
|
||||
return FALSE ;
|
||||
Point3d ptStart, ptOldMid, ptEnd ;
|
||||
if ( ! pArc->GetStartPoint( ptStart) || ! pArc->GetMidPoint( ptOldMid) || ! pArc->GetEndPoint( ptEnd))
|
||||
return FALSE ;
|
||||
// recupero il riferimento locale
|
||||
Frame3d frLoc ;
|
||||
if ( ! pGeomDB->GetGlobFrame( nId, frLoc))
|
||||
return FALSE ;
|
||||
// porto in locale il nuovo punto medio
|
||||
Point3d ptMidL = GetPointLocal( pGeomDB, ptMid, nRefType, frLoc) ;
|
||||
// imposto il nuovo punto medio
|
||||
if ( pArc->Set3P( ptStart, ptMidL, ptEnd))
|
||||
return TRUE ;
|
||||
// in caso di errore, ripristino i vecchi dati
|
||||
else {
|
||||
pArc->Set3P( ptStart, ptOldMid, ptEnd) ;
|
||||
return FALSE ;
|
||||
}
|
||||
return ( ExeModifyCurveArc3P( nId, ptMid, nRefType) ? TRUE : FALSE) ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
int
|
||||
__stdcall EgtExplodeCurveCompo( int nId, int* pnCount)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero la curva composita
|
||||
ICurveComposite* pCompo = GetCurveComposite( pGeomDB->GetGeoObj( nId)) ;
|
||||
bool bOk = ( pCompo != nullptr) ;
|
||||
// estraggo tutte le curve
|
||||
int nFirstId = GDB_ID_NULL ;
|
||||
int nCount = 0 ;
|
||||
ICurve* pCrv ;
|
||||
while ( bOk && ( pCrv = pCompo->RemoveFirstOrLastCurve( false)) != nullptr) {
|
||||
// inserisco la curva nello stesso gruppo e nello stesso posto del GeomDB
|
||||
int nCrvId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_BEFORE, pCrv) ;
|
||||
bOk = bOk && ( nCrvId != GDB_ID_NULL) ;
|
||||
// copio gli attributi
|
||||
bOk = bOk && pGeomDB->CopyAttributes( nId, nCrvId) ;
|
||||
// aggiorno contatori
|
||||
if ( bOk) {
|
||||
if ( nFirstId == GDB_ID_NULL)
|
||||
nFirstId = nCrvId ;
|
||||
++ nCount ;
|
||||
}
|
||||
}
|
||||
nFirstId = ( bOk ? nFirstId : GDB_ID_NULL) ;
|
||||
// elimino la curva composita ormai vuota
|
||||
bOk = bOk && pGeomDB->Erase( nId) ;
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtExplodeCurveCompo(" + ToString( nId) + ")" +
|
||||
" -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco risultati
|
||||
if ( pnCount != nullptr)
|
||||
*pnCount = nCount ;
|
||||
return nFirstId ;
|
||||
return ExeExplodeCurveCompo( nId, pnCount) ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
int
|
||||
__stdcall EgtApproxCurveArc( int nId, double dLinTol)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero l'arco
|
||||
ICurveArc* pArc = GetCurveArc( pGeomDB->GetGeoObj( nId)) ;
|
||||
bool bOk = ( pArc != nullptr) ;
|
||||
// eseguo l'approssimazione con segmenti di linea
|
||||
const double ANG_TOL_STD_DEG = 15 ;
|
||||
PtrOwner<ICurveComposite> pCC( CreateCurveComposite()) ;
|
||||
bOk = bOk && ! IsNull( pCC) ;
|
||||
PolyLine PL ;
|
||||
bOk = bOk && pArc->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, PL) && pCC->FromPolyLine( PL) ;
|
||||
// inserisco la curva composita nello stesso posto del GeomDB
|
||||
int nCrvId = ( bOk ? pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_BEFORE, Release( pCC)) : GDB_ID_NULL) ;
|
||||
bOk = bOk && ( nCrvId != GDB_ID_NULL) ;
|
||||
// copio gli attributi
|
||||
bOk = bOk && pGeomDB->CopyAttributes( nId, nCrvId) ;
|
||||
// elimino l'arco
|
||||
bOk = bOk && pGeomDB->Erase( nId) ;
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtApproxCurveArc(" + ToString( nId) + "," +
|
||||
ToString( dLinTol) + ")" +
|
||||
" -- Id=" + ToString( nCrvId) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco risultato
|
||||
return nCrvId ;
|
||||
return ExeApproxCurveArc( nId, dLinTol) ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
int
|
||||
__stdcall EgtApproxCurveBezier( int nId, BOOL bArcsVsLines, double dLinTol)
|
||||
{
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
||||
// recupero la curva di Bezier
|
||||
ICurveBezier* pCBezier = GetCurveBezier( pGeomDB->GetGeoObj( nId)) ;
|
||||
bool bOk = ( pCBezier != nullptr) ;
|
||||
// eseguo l'approssimazione
|
||||
const double ANG_TOL_STD_DEG = 15 ;
|
||||
PtrOwner<ICurveComposite> pCC( CreateCurveComposite()) ;
|
||||
bOk = bOk && ! IsNull( pCC) ;
|
||||
if ( bArcsVsLines) { // con bi-archi
|
||||
PolyArc PA ;
|
||||
bOk = bOk && pCBezier->ApproxWithArcs( dLinTol, ANG_TOL_STD_DEG, PA) && pCC->FromPolyArc( PA) ;
|
||||
}
|
||||
else { // con linee
|
||||
PolyLine PL ;
|
||||
bOk = bOk && pCBezier->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, PL) && pCC->FromPolyLine( PL) ;
|
||||
}
|
||||
// inserisco la curva composita nello stesso posto del GeomDB
|
||||
int nCrvId = ( bOk ? pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_BEFORE, Release( pCC)) : GDB_ID_NULL) ;
|
||||
bOk = bOk && ( nCrvId != GDB_ID_NULL) ;
|
||||
// copio gli attributi
|
||||
bOk = bOk && pGeomDB->CopyAttributes( nId, nCrvId) ;
|
||||
// elimino la curva di Bezier
|
||||
bOk = bOk && pGeomDB->Erase( nId) ;
|
||||
EgtSetModified() ;
|
||||
// se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtApproxCurveBezier(" + ToString( nId) + "," +
|
||||
( bArcsVsLines ? "GDB_CA.ARCS" : "GDB_CA.LINES") + "," +
|
||||
ToString( dLinTol) + ")" +
|
||||
" -- Id=" + ToString( nCrvId) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
// restituisco risultato
|
||||
return nCrvId ;
|
||||
}
|
||||
return ExeApproxCurveBezier( nId, ( bArcsVsLines != FALSE), dLinTol) ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user