Files
EgtExecutor/EXE_GdbModify.cpp
T
Dario Sassi dc0396f6af EgtExecutor :
- aggiunte Exe e lua ChangeTextHeight e ChangeTextItalic
- aggiunte Exe TextGetHeight e TextGetItalic.
2019-08-02 17:33:44 +00:00

348 lines
12 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : API_GdbModify.cpp Data : 06.10.14 Versione : 1.5i5
// Contenuto : Funzioni di modifica geometrica per API.
//
//
//
// Modifiche : 06.10.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "EXE.h"
#include "EXE_Macro.h"
#include "AuxTools.h"
#include "GeoTools.h"
#include "/EgtDev/Include/EXeExecutor.h"
#include "/EgtDev/Include/EXeConst.h"
#include "/EgtDev/Include/EGkGeoPoint3d.h"
#include "/EgtDev/Include/EGkGeoVector3d.h"
#include "/EgtDev/Include/EGkExtText.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EgtStringConverter.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
using namespace std ;
//-------------------------------------------------------------------------------
bool
ExeChangeGroupFrame( int nId, const Frame3d& frNewRef, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
bool bOk = true ;
// recupero il riferimento del gruppo
Frame3d* pFrame = pGeomDB->GetGroupFrame( nId) ;
bOk = bOk && ( pFrame != nullptr) ;
// porto il nuovo riferimento in locale
Frame3d frNewL = frNewRef ;
if ( nRefType != RTY_LOC) {
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ;
if ( nRefType == RTY_GLOB)
frNewL.ToLoc( frLoc) ;
else /* RTY_GRID */
frNewL.LocToLoc( pGeomDB->GetGridFrame(), frLoc) ;
}
// aggiorno il gruppo
if ( bOk)
*pFrame = frNewL ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtChangeGroupFrame(" + ToString( nId) + ",{{" +
ToString( frNewRef.Orig()) + "},{" +
ToString( frNewRef.VersX()) + "},{" +
ToString( frNewRef.VersY()) + "},{" +
ToString( frNewRef.VersZ()) + "}}," +
RefTypeToString( nRefType) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return bOk ;
}
//-------------------------------------------------------------------------------
bool
ExeChangeVectorBase( int nId, const Point3d& ptB, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
bool bOk = true ;
// recupero il vettore
IGeoVector3d* pGVect = GetGeoVector3d( pGeomDB->GetGeoObj( nId)) ;
bOk = bOk && ( pGVect != nullptr) ;
// recupero il riferimento locale
Frame3d frLoc ;
bOk = bOk && pGeomDB->GetGlobFrame( nId, frLoc) ;
// porto il nuovo punto base in locale
Point3d ptBL = GetPointLocal( pGeomDB, ptB, nRefType, frLoc) ;
// imposto il nuovo punto di base
bOk = bOk && pGVect->ChangeBase( ptBL) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtChangeVectorBase(" + ToString( nId) + ",{" +
ToString( ptB) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return bOk ;
}
//----------------------------------------------------------------------------
bool
ExeInvertVector( 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 il vettore e lo inverto
IGeoVector3d* pGVect = GetGeoVector3d( pGeomDB->GetGeoObj( nId)) ;
bOk = ( pGVect != nullptr && pGVect->ChangeVector( - pGVect->GetVector())) ;
// passo alla successiva
nId = (( vIds[i] != GDB_ID_SEL) ? GDB_ID_NULL : pGeomDB->GetNextSelectedObj()) ;
}
}
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtInvertVector({" + IdListToString( vIds) + "})" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return bOk ;
}
//-------------------------------------------------------------------------------
bool
ExeModifyText( int nId, const string& sNewText)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il testo
IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ;
if ( pTXT == nullptr)
return false ;
// eseguo l'operazione
bool bOk = pTXT->ModifyText( sNewText) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtModifyText(" + ToString( nId) + ",'"
+ StringToLuaString( sNewText) + "')" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return bOk ;
}
//-------------------------------------------------------------------------------
bool
ExeChangeTextFont( int nId, const string& sNewFont)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il testo
IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ;
if ( pTXT == nullptr)
return false ;
// eseguo l'operazione
bool bOk = pTXT->ChangeFont( sNewFont) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtChangeTextFont(" + ToString( nId) + ",'"
+ StringToLuaString( sNewFont) + "')" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return bOk ;
}
//-------------------------------------------------------------------------------
bool
ExeChangeTextHeight( int nId, double dH)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il testo
IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ;
if ( pTXT == nullptr)
return false ;
// eseguo l'operazione
bool bOk = pTXT->ChangeHeight( dH) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtChangeTextHeight(" + ToString( nId) + ","
+ ToString( dH) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return bOk ;
}
//-------------------------------------------------------------------------------
bool
ExeChangeTextItalic( int nId, bool bItl)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il testo
IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ;
if ( pTXT == nullptr)
return false ;
// eseguo l'operazione
bool bOk = pTXT->ChangeItalic( bItl) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtChangeTextItalic(" + ToString( nId) + ","
+ ( bItl ? "true" : "false") + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultato
return bOk ;
}
//-------------------------------------------------------------------------------
bool
ExeFlipText( int nId)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il testo
IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ;
if ( pTXT == nullptr)
return false ;
// eseguo l'operazione
ExeSetModified() ;
return pTXT->Flip() ;
}
//-------------------------------------------------------------------------------
bool
ExeMirrorText( int nId, bool bOnL)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il testo
IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ;
if ( pTXT == nullptr)
return false ;
// eseguo l'operazione
ExeSetModified() ;
return pTXT->Mir( bOnL) ;
}
//-------------------------------------------------------------------------------
int
ExeExplodeText( int nId, int* pnCount)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero il testo
IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ;
bool bOk = ( pTXT != nullptr) ;
// recupero l'outline del testo
ICURVEPLIST lstPCRV ;
bOk = bOk && pTXT->GetOutline( lstPCRV) ;
// inserisco le curve nella stessa posizione del testo
int nFirstId = GDB_ID_NULL ;
int nCount = 0 ;
for ( ICURVEPLIST::iterator iIter = lstPCRV.begin() ; iIter != lstPCRV.end() ; ++ iIter) {
// inserisco la curva nello stesso gruppo e nello stesso posto del GeomDB
int nCrvId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_BEFORE, (*iIter)) ;
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 il testo originale
bOk = bOk && pGeomDB->Erase( nId) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtExplodeText(" + ToString( nId) + ")" +
" -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultati
if ( pnCount != nullptr)
*pnCount = nCount ;
return nFirstId ;
}
//-------------------------------------------------------------------------------
int
ExeSplitText( int nId, int* pnCount)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero il testo
IExtText* pTXT = GetExtText( pGeomDB->GetGeoObj( nId)) ;
bool bOk = ( pTXT != nullptr) ;
// recupero l'esplosione del testo in linee singole
IEXTTEXTPVECTOR vTxt ;
bOk = bOk && pTXT->SplitOnLineBreak( vTxt) ;
// inserisco i nuovi testi nella stessa posizione del testo
int nFirstId = GDB_ID_NULL ;
int nCount = 0 ;
for ( int i = 0 ; i < int( vTxt.size()) ; ++ i) {
// inserimento
int nCrvId = ( bOk ? pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_BEFORE, vTxt[i]) : GDB_ID_NULL) ;
if ( 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 ;
}
}
else {
bOk = false ;
delete vTxt[i] ;
}
}
nFirstId = ( bOk ? nFirstId : GDB_ID_NULL) ;
// elimino il testo originale
bOk = bOk && pGeomDB->Erase( nId) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtSplitText(" + ToString( nId) + ")" +
" -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultati
if ( pnCount != nullptr)
*pnCount = nCount ;
return nFirstId ;
}