Files
EgtInterface/API_GdbModifyCurve.cpp
T
Dario Sassi b0389f3fda EgtInterface 1.6b6 :
- aggiornamenti vari
- introdotto comando per merge (cucitura) di superfici
- migliorata gestione oggetti selezionati in comandi.
2015-03-11 09:06:35 +00:00

789 lines
28 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : API_ModifyCurve.cpp Data : 03.10.14 Versione : 1.5i5
// Contenuto : Funzioni di modifica delle curve per API.
//
//
//
// Modifiche : 03.10.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- 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"
using namespace std ;
//----------------------------------------------------------------------------
BOOL
__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 sIds ;
for ( size_t i = 0 ; i < vIds.size() ; ++ i)
sIds += ( vIds[i] != GDB_ID_SEL ? ToString( vIds[i]) : "GDB_ID_SEL") + "," ;
sIds.pop_back() ;
string sLua = "EgtInvertCurve({" + sIds + "})" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return bOk ;
}
//----------------------------------------------------------------------------
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 ;
if ( nType == ICurve::OFF_FILLET)
sLua = "EgtOffsetCurve(" + ToString( nId) + "," +
ToString( dDist) + ")" +
" -- Ok=" + ToString( bOk) ;
else
sLua = "EgtOffsetCurve(" + ToString( nId) + "," +
ToString( dDist) + "," +
( nType == ICurve::OFF_CHAMFER ? "'CHAMFER'" : "'EXTEND'") + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return ( bOk ? 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) ;
}
//----------------------------------------------------------------------------
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)) ;
}
}
//----------------------------------------------------------------------------
BOOL
__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 sIds ;
for ( size_t i = 0 ; i < vIds.size() ; ++ i)
sIds += ( vIds[i] != GDB_ID_SEL ? ToString( vIds[i]) : "GDB_ID_SEL") + "," ;
sIds.pop_back() ;
string sLua = "EgtModifyCurveExtrusion({" + sIds + "},{" +
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)) ;
}
}
//----------------------------------------------------------------------------
BOOL
__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 sIds ;
for ( size_t i = 0 ; i < vIds.size() ; ++ i)
sIds += ( vIds[i] != GDB_ID_SEL ? ToString( vIds[i]) : "GDB_ID_SEL") + "," ;
sIds.pop_back() ;
string sLua = "EgtModifyCurveThickness({" + sIds + "}," +
ToString( dThick) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return ( bOk ? 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) ;
}
//----------------------------------------------------------------------------
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) ;
}
//----------------------------------------------------------------------------
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) ;
}
//----------------------------------------------------------------------------
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) ;
}
//----------------------------------------------------------------------------
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) ;
}
//----------------------------------------------------------------------------
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) ;
}
//----------------------------------------------------------------------------
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) ;
}
//----------------------------------------------------------------------------
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) ;
}
//----------------------------------------------------------------------------
BOOL
__stdcall EgtSplitCurve( int nId, int nParts)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, FALSE)
// 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
for ( int i = 1; i < nParts ; ++ i) {
// copio la curva
int nCopyId = pGeomDB->Copy( nId, GDB_ID_NULL, nId, GDB_BEFORE) ;
ICurve* pCopyCrv = GetCurve( pGeomDB->GetGeoObj( nCopyId)) ;
bOk = bOk && ( pCopyCrv != nullptr) ;
// tengo la prima parte della copia e la seconda parte dell'originale
bOk = bOk && pCopyCrv->TrimEndAtLen( dLen) ;
bOk = bOk && pCurve->TrimStartAtLen( dLen) ;
}
EgtSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSplitCurve(" + ToString( nId) + "," +
ToString( nParts) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return ( bOk ? TRUE : FALSE) ;
}
//----------------------------------------------------------------------------
BOOL
__stdcall EgtSplitCurveAtPoint( int nId, double ptOn[3], int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, FALSE)
// 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
if ( bIsInside) {
// copio la curva
int nCopyId = pGeomDB->Copy( nId, GDB_ID_NULL, nId, 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->TrimEndAtParam( dU) ;
bOk = bOk && pCopyCrv->TrimStartAtParam( dU) ;
}
EgtSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSplitCurveAtPoint(" + ToString( nId) + ",{" +
ToString( Point3d( ptOn)) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return ( bOk ? TRUE : FALSE) ;
}
//-------------------------------------------------------------------------------
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 ;
}
}
//-------------------------------------------------------------------------------
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 ;
}
}
//-------------------------------------------------------------------------------
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 ;
}
}
//-------------------------------------------------------------------------------
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 ;
}
}
//-------------------------------------------------------------------------------
BOOL
__stdcall EgtExplodeCurveCompo( int nId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, FALSE)
bool bOk = true ;
// recupero la curva composita
ICurveComposite* pCompo = GetCurveComposite( pGeomDB->GetGeoObj( nId)) ;
if ( pCompo == nullptr)
bOk = false ;
// estraggo tutte le curve
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) ;
if ( nCrvId == GDB_ID_NULL)
bOk = false ;
// copio gli attributi
if ( ! pGeomDB->CopyAttributes( nId, nCrvId))
bOk = false ;
}
// 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) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return ( bOk ? TRUE : FALSE) ;
}
//-------------------------------------------------------------------------------
BOOL
__stdcall EgtExplodeCurveBezier( int nId, BOOL bArcsVsLines, double dLinTol)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, FALSE)
bool bOk = true ;
// recupero la curva di Bezier
ICurveBezier* pCBezier = GetCurveBezier( pGeomDB->GetGeoObj( nId)) ;
if ( pCBezier == nullptr)
bOk = false ;
// eseguo l'approssimazione
const double ANG_TOL_STD_DEG = 15 ;
PtrOwner<ICurveComposite> pCC( CreateCurveComposite()) ;
if ( ! IsNull( pCC)) {
if ( bArcsVsLines) { // con bi-archi
PolyArc PA ;
if ( ! pCBezier->ApproxWithArcs( dLinTol, ANG_TOL_STD_DEG, PA) ||
! pCC->FromPolyArc( PA))
bOk = false ;
}
else { // con linee
PolyLine PL ;
if ( ! pCBezier->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, PL) ||
! pCC->FromPolyLine( PL))
bOk = false ;
}
}
else
bOk = false ;
// inserisco le curve elementari nel DB
ICurve* pCrv ;
while ( bOk && ( pCrv = pCC->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) ;
if ( nCrvId == GDB_ID_NULL)
bOk = false ;
// copio gli attributi
if ( ! pGeomDB->CopyAttributes( nId, nCrvId))
bOk = false ;
}
// elimino la curva di Bezier
bOk = bOk && pGeomDB->Erase( nId) ;
EgtSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtExplodeCurveBezier(" + ToString( nId) + ",'" +
( bArcsVsLines ? "ARCS" : "LINES") + "'," +
ToString( dLinTol) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return ( bOk ? TRUE : FALSE) ;
}