0c41c8c631
- aggiunta gestione nome file di progetto e suo stato - aggiunta gestione pezzo e layer - riordino generale.
770 lines
27 KiB
C++
770 lines
27 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 "/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)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
bool bOk = true ;
|
|
// eseguo inversione singola
|
|
if ( nId != GDB_ID_SEL) {
|
|
// recupero la curva e la inverto
|
|
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
|
|
if ( pCurve != nullptr && ! pCurve->Invert())
|
|
bOk = false ;
|
|
}
|
|
// eseguo inversione dei selezionati
|
|
else {
|
|
int nI = pGeomDB->GetFirstSelectedObj() ;
|
|
while ( nI != GDB_ID_NULL && bOk) {
|
|
// recupero la curva e la inverto
|
|
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nI)) ;
|
|
if ( pCurve != nullptr && ! pCurve->Invert())
|
|
bOk = false ;
|
|
// passo alla successiva
|
|
nI = pGeomDB->GetNextSelectedObj() ;
|
|
}
|
|
}
|
|
EgtSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtInvertCurve(" + ( nId != GDB_ID_SEL ? ToString( nId): "GDB_ID_SEL") + ")" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco risultato
|
|
return ( bOk ? 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 ;
|
|
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) ;
|
|
// porto in locale il nuovo punto iniziale
|
|
Point3d ptPL( ptP) ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ;
|
|
if ( nRefType == RTY_GLOB)
|
|
ptPL.ToLoc( frLoc) ;
|
|
else /* RTY_GRID */
|
|
ptPL.LocToLoc( pGeomDB->GetGridFrame(), 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) ;
|
|
// porto in locale il nuovo punto iniziale
|
|
Point3d ptPL( ptP) ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ;
|
|
if ( nRefType == RTY_GLOB)
|
|
ptPL.ToLoc( frLoc) ;
|
|
else /* RTY_GRID */
|
|
ptPL.LocToLoc( pGeomDB->GetGridFrame(), 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)
|
|
{
|
|
// porto in locale il versore estrusione
|
|
Vector3d vtExtrL( vtExtr) ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGroupGlobFrame( nId, frLoc) &&
|
|
! pGeomDB->GetGlobFrame( nId, frLoc))
|
|
return false ;
|
|
if ( nRefType == RTY_GLOB)
|
|
vtExtrL.ToLoc( frLoc) ;
|
|
else /* RTY_GRID */
|
|
vtExtrL.LocToLoc( pGeomDB->GetGridFrame(), 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( 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) {
|
|
if ( i > 0)
|
|
sIds += "," ;
|
|
sIds += ( vIds[i] != GDB_ID_SEL ? ToString( vIds[i]) : "GDB_ID_SEL") ;
|
|
}
|
|
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)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
bool bOk = true ;
|
|
// eseguo impostazione spessore singola
|
|
if ( nId != GDB_ID_SEL) {
|
|
bOk = ModifyOneCurveThickness( pGeomDB, nId, 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(" + ( nId != GDB_ID_SEL ? ToString( nId) : "GDB_ID_SEL") + "," +
|
|
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) ;
|
|
// porto in locale il punto
|
|
Point3d ptNearL( ptNear) ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ;
|
|
if ( nRefType == RTY_GLOB)
|
|
ptNearL.ToLoc( frLoc) ;
|
|
else /* RTY_GRID */
|
|
ptNearL.LocToLoc( pGeomDB->GetGridFrame(), 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 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) ;
|
|
// porto in locale il punto
|
|
Point3d ptOnL( ptOn) ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ;
|
|
if ( nRefType == RTY_GLOB)
|
|
ptOnL.ToLoc( frLoc) ;
|
|
else /* RTY_GRID */
|
|
ptOnL.LocToLoc( pGeomDB->GetGridFrame(), 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 = GDB_ID_NULL ;
|
|
if ( bOk && ( nCopyId = pGeomDB->Copy( nId, GDB_ID_NULL, nId, GDB_AFTER)) == GDB_ID_NULL)
|
|
bOk = false ;
|
|
// tengo la prima parte dell'originale e la seconda parte della copia
|
|
bOk = bOk && pCurve->TrimEndAtParam( dU) ;
|
|
bOk = bOk && ( EgtTrimCurveStartAtParam( nCopyId, dU) != FALSE) ;
|
|
}
|
|
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() ;
|
|
// porto in locale il nuovo punto
|
|
Point3d ptOnL( ptOn) ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frLoc))
|
|
return FALSE ;
|
|
if ( nRefType == RTY_GLOB)
|
|
ptOnL.ToLoc( frLoc) ;
|
|
else /* RTY_GRID */
|
|
ptOnL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
|
|
}
|
|
// calcolo il nuovo raggio
|
|
double dRad = (( Point3d( 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 ;
|
|
// porto in locale il nuovo punto finale
|
|
Point3d ptEndL( ptEnd) ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frLoc))
|
|
return FALSE ;
|
|
if ( nRefType == RTY_GLOB)
|
|
ptEndL.ToLoc( frLoc) ;
|
|
else /* RTY_GRID */
|
|
ptEndL.LocToLoc( pGeomDB->GetGridFrame(), 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 ;
|
|
// porto in locale il nuovo punto medio
|
|
Point3d ptMidL( ptMid) ;
|
|
if ( nRefType != RTY_LOC) {
|
|
Frame3d frLoc ;
|
|
if ( ! pGeomDB->GetGlobFrame( nId, frLoc))
|
|
return FALSE ;
|
|
if ( nRefType == RTY_GLOB)
|
|
ptMidL.ToLoc( frLoc) ;
|
|
else /* RTY_GRID */
|
|
ptMidL.LocToLoc( pGeomDB->GetGridFrame(), 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 ? "true" : "false") + "," +
|
|
ToString( dLinTol) + ")" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco risultato
|
|
return ( bOk ? TRUE : FALSE) ;
|
|
} |