EgtInterface 1.6a4 :

- completamento modifiche per registrazione comandi in lua e per gestione RefType e RefId.
This commit is contained in:
Dario Sassi
2015-01-26 07:53:04 +00:00
parent 4e5a81c493
commit a45c3fca8a
25 changed files with 1574 additions and 1254 deletions
+181 -129
View File
@@ -15,7 +15,9 @@
#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"
@@ -94,174 +96,169 @@ __stdcall EgtOffsetCurve( int nId, double dDist, int nType)
//----------------------------------------------------------------------------
BOOL
__stdcall EgtModifyCurveStartPoint( int nId, const double ptP[3])
__stdcall EgtModifyCurveStartPoint( int nId, const double ptP[3], int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
VERIFY_GEOMDB( pGeomDB, FALSE)
bool bOk = true ;
// recupero la curva
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
if ( pCurve == nullptr)
return FALSE ;
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
return ( pCurve->ModifyStart( ptP) ? TRUE : FALSE) ;
bOk = bOk && pCurve->ModifyStart( ptPL) ;
// 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])
__stdcall EgtModifyCurveEndPoint( int nId, const double ptP[3], int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
VERIFY_GEOMDB( pGeomDB, FALSE)
bool bOk = true ;
// recupero la curva
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
if ( pCurve == nullptr)
return FALSE ;
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
return ( pCurve->ModifyEnd( ptP) ? TRUE : FALSE) ;
bOk = bOk && pCurve->ModifyEnd( ptPL) ;
// 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
__stdcall ModifyOneCurveExtrusion( IGeomDB* pGeomDB, int nId, const Vector3d& vtExtr)
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 ;
bool bOk = true ;
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( vtExtr))
bOk = false ;
if ( pCurve != nullptr && ! pCurve->SetExtrusion( vtExtrL))
return false ;
}
return bOk ;
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( vtExtr)) ;
return ( pCurve == nullptr || pCurve->SetExtrusion( vtExtrL)) ;
}
}
//----------------------------------------------------------------------------
BOOL
__stdcall EgtModifyCurveExtrusion( int nId, const double vtExtr[3])
__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)
VERIFY_GEOMDB( pGeomDB, false)
bool bOk = true ;
// eseguo impostazione estrusione singola
if ( nId != GDB_ID_SEL) {
bOk = ModifyOneCurveExtrusion( pGeomDB, nId, vtExtr) ;
}
// eseguo impostazione estrusione dei selezionati
else {
int nI = pGeomDB->GetFirstSelectedObj() ;
while ( nI != GDB_ID_NULL && bOk) {
if ( ! ModifyOneCurveExtrusion( pGeomDB, nI, vtExtr))
bOk = false ;
// passo alla successiva
nI = pGeomDB->GetNextSelectedObj() ;
// 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() ;
}
}
}
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtModifyCurveExtrusion(" + ( nId != GDB_ID_SEL ? ToString( nId) : "GDB_ID_SEL") + ",{" +
ToString( Vector3d( vtExtr)) + "})" +
" -- Ok=" + ToString( bOk) ;
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 ? TRUE : FALSE) ;
return bOk ;
}
//----------------------------------------------------------------------------
static bool
__stdcall SetOneCurveExtrusionFromGrid( IGeomDB* pGeomDB, int nId, const Vector3d& vtExtrGlob)
{
// se gruppo, agisco sulle sole curve componenti
if ( pGeomDB->GetGdbType( nId) == GDB_TY_GROUP) {
// recupero il riferimento definito dal gruppo
Frame3d frFrame ;
if ( ! pGeomDB->GetGroupGlobFrame( nId, frFrame))
return false ;
// esprimo il versore estrusione in questo riferimento
Vector3d vtExtr = vtExtrGlob ;
vtExtr.ToLoc( frFrame) ;
// ciclo sulle curve del gruppo
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 il vettore estrusione
ICurve* pCurve = GetCurve( pIter->GetGeoObj()) ;
if ( pCurve != nullptr && ! pCurve->SetExtrusion( vtExtr))
bOk = false ;
}
return bOk ;
}
// se oggetto geometrico
else {
// recupero il riferimento definito dal gruppo
Frame3d frFrame ;
if ( ! pGeomDB->GetGlobFrame( nId, frFrame))
return false ;
// esprimo il versore estrusione in questo riferimento
Vector3d vtExtr = vtExtrGlob ;
vtExtr.ToLoc( frFrame) ;
// recupero la curva
ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ;
// ne modifico il vettore estrusione
return ( pCurve == nullptr || pCurve->SetExtrusion( vtExtr)) ;
}
}
//-------------------------------------------------------------------------------
BOOL
__stdcall EgtSetCurveExtrusionFromGrid( int nId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, FALSE)
bool bOk = true ;
// recupero il versore Z della griglia corrente (in globale)
Vector3d vtExtrGlob = pGeomDB->GetGridFrame().VersZ() ;
// eseguo impostazione estrusione singola
if ( nId != GDB_ID_SEL) {
bOk = SetOneCurveExtrusionFromGrid( pGeomDB, nId, vtExtrGlob) ;
}
// eseguo impostazione estrusione dei selezionati
else {
int nI = pGeomDB->GetFirstSelectedObj() ;
while ( nI != GDB_ID_NULL && bOk) {
if ( ! SetOneCurveExtrusionFromGrid( pGeomDB, nI, vtExtrGlob))
bOk = false ;
// passo alla successiva
nI = pGeomDB->GetNextSelectedObj() ;
}
}
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSetCurveExtrusionFromGrid(" + ( nId != GDB_ID_SEL ? ToString( nId) : "GDB_ID_SEL") + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return ( bOk ? TRUE : FALSE) ;
}
//----------------------------------------------------------------------------
static bool
__stdcall ModifyOneCurveThickness( IGeomDB* pGeomDB, int nId, double dThick)
ModifyOneCurveThickness( IGeomDB* pGeomDB, int nId, double dThick)
{
// se gruppo, agisco sulle sole curve componenti
if ( pGeomDB->GetGdbType( nId) == GDB_TY_GROUP) {
@@ -420,17 +417,27 @@ __stdcall EgtExtendCurveEndByLen( int nId, double dLen)
//----------------------------------------------------------------------------
BOOL
__stdcall EgtTrimExtendCurveByLen( int nId, double dLen, const double ptNear[3])
__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, ptNear) < SqDist( ptEnd, ptNear)) {
if ( SqDist( ptStart, ptNearL) < SqDist( ptEnd, ptNearL)) {
if ( dLen < - EPS_SMALL)
bOk = pCurve->TrimStartAtLen( - dLen) ;
else if ( dLen > EPS_SMALL)
@@ -451,7 +458,8 @@ __stdcall EgtTrimExtendCurveByLen( int nId, double dLen, const double ptNear[3])
if ( IsCmdLog()) {
string sLua = "EgtTrimExtendCurveByLen(" + ToString( nId) + "," +
ToString( dLen) + ",{" +
ToString( Point3d( ptNear)) + "})" +
ToString( Point3d( ptNear)) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
@@ -461,17 +469,27 @@ __stdcall EgtTrimExtendCurveByLen( int nId, double dLen, const double ptNear[3])
//----------------------------------------------------------------------------
BOOL
__stdcall EgtSplitCurveAtPoint( int nId, double ptOn[3])
__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( ptOn, *pCurve) ;
DistPointCurve dstPC( ptOnL, *pCurve) ;
int nFlag ;
if ( ! dstPC.GetParamAtMinDistPoint( 0, dU, nFlag) || nFlag != MDPCI_NORMAL)
bOk = false ;
@@ -502,7 +520,8 @@ __stdcall EgtSplitCurveAtPoint( int nId, double ptOn[3])
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSplitCurveAtPoint(" + ToString( nId) + ",{" +
ToString( Point3d( ptOn)) + "})" +
ToString( Point3d( ptOn)) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
@@ -512,7 +531,7 @@ __stdcall EgtSplitCurveAtPoint( int nId, double ptOn[3])
//-------------------------------------------------------------------------------
BOOL
__stdcall EgtModifyCurveCircleCPN( int nId, const double ptOn[3])
__stdcall EgtModifyCurveCircleCPN( int nId, const double ptOn[3], int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, FALSE)
@@ -523,8 +542,19 @@ __stdcall EgtModifyCurveCircleCPN( int nId, const double ptOn[3])
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( ptOn) - ptCen) ^ vtN).Len() ;
double dRad = (( Point3d( ptOnL) - ptCen) ^ vtN).Len() ;
// imposto il nuovo raggio
if ( pArc->Set( ptCen, vtN, dRad))
return TRUE ;
@@ -558,7 +588,7 @@ __stdcall EgtModifyCurveArcRadius( int nId, double dRad)
//-------------------------------------------------------------------------------
BOOL
__stdcall EgtModifyCurveArcC2PN( int nId, const double ptEnd[3])
__stdcall EgtModifyCurveArcC2PN( int nId, const double ptEnd[3], int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, FALSE)
@@ -571,8 +601,19 @@ __stdcall EgtModifyCurveArcC2PN( int nId, const double ptEnd[3])
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, ptEnd, vtN))
if ( pArc->SetC2PN( ptCen, ptStart, ptEndL, vtN))
return TRUE ;
// in caso di errore, ripristino i vecchi dati
else {
@@ -583,7 +624,7 @@ __stdcall EgtModifyCurveArcC2PN( int nId, const double ptEnd[3])
//-------------------------------------------------------------------------------
BOOL
__stdcall EgtModifyCurveArc3P( int nId, const double ptMid[3])
__stdcall EgtModifyCurveArc3P( int nId, const double ptMid[3], int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, FALSE)
@@ -593,9 +634,20 @@ __stdcall EgtModifyCurveArc3P( int nId, const double ptMid[3])
return FALSE ;
Point3d ptStart, ptOldMid, ptEnd ;
if ( ! pArc->GetStartPoint( ptStart) || ! pArc->GetMidPoint( ptOldMid) || ! pArc->GetEndPoint( ptEnd))
return false ;
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, ptMid, ptEnd))
if ( pArc->Set3P( ptStart, ptMidL, ptEnd))
return TRUE ;
// in caso di errore, ripristino i vecchi dati
else {
@@ -640,7 +692,7 @@ __stdcall EgtExplodeCurveCompo( int nId)
//-------------------------------------------------------------------------------
BOOL
__stdcall EgtExplodeCurveBezier( int nId, double dLinTol, BOOL bArcsVsLines)
__stdcall EgtExplodeCurveBezier( int nId, BOOL bArcsVsLines, double dLinTol)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, FALSE)
@@ -684,8 +736,8 @@ __stdcall EgtExplodeCurveBezier( int nId, double dLinTol, BOOL bArcsVsLines)
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtExplodeCurveBezier(" + ToString( nId) + "," +
ToString( dLinTol) + "," +
( bArcsVsLines ? "true" : "false") + ")"
( bArcsVsLines ? "true" : "false") + "," +
ToString( dLinTol) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}