77e74ccf4e
- aggiunta IsFlat a tutte le Curve - aggiunta ApproxWithArcs a tutte le Curve - aggiunto oggetto PolyArc (raccolta ordinata di linee e archi con bulge) - aggiunto oggetto PointsPCA per stima componenti principali di un insieme di punti - FromSpheriical e FromPolar di Vector3d sono diventati funzioni e aggiunto FromUprightOrtho - aggiunte Invert e a Vector3d.
852 lines
26 KiB
C++
852 lines
26 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : ExtText.cpp Data : 27.05.14 Versione : 1.5e10
|
|
// Contenuto : Implementazione della classe Testo.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 27.05.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "ExtText.h"
|
|
#include "GeoObjFactory.h"
|
|
#include "NgeWriter.h"
|
|
#include "NgeReader.h"
|
|
#include "FontManager.h"
|
|
#include "\EgtDev\Include\EGkStringUtils3d.h"
|
|
#include <new>
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
GEOOBJ_REGISTER( EXT_TEXT, NGE_E_TXT, ExtText) ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
ExtText::ExtText( void)
|
|
: m_ptP(), m_vtN( 0, 0, 1), m_vtD( 1, 0, 0), m_sFont(),
|
|
m_nWeight( 400), m_bItalic( false), m_dHeight( 10), m_dRatio( 1), m_dAddAdvance( 0)
|
|
{
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
ExtText::~ExtText( void)
|
|
{
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Set( const string& sText, const Point3d& ptP, double dAngDeg, double dH)
|
|
{
|
|
// controllo testo non vuoto
|
|
if ( sText.empty())
|
|
return false ;
|
|
// assegno i dati
|
|
m_ptP = ptP ;
|
|
m_vtN = Z_AX ;
|
|
m_vtD = FromPolar( 1, dAngDeg) ;
|
|
m_sText = sText ;
|
|
m_sFont.clear() ;
|
|
m_nWeight = 400 ;
|
|
m_bItalic = false ;
|
|
m_dHeight = dH ;
|
|
m_dRatio = 1 ;
|
|
m_dAddAdvance = 0 ;
|
|
m_nInsPos = ETXT_IPBL ;
|
|
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Set( const string& sText, const Point3d& ptP, double dAngDeg,
|
|
const string& sFont, int nW, bool bItl, double dH, double dRat, double dAddAdv,
|
|
int nInsPos)
|
|
{
|
|
// controllo testo non vuoto
|
|
if ( sText.empty())
|
|
return false ;
|
|
// controllo lunghezza nome font
|
|
if ( sFont.size() > MAX_FONT_LEN)
|
|
return false ;
|
|
// assegno i dati
|
|
m_ptP = ptP ;
|
|
m_vtN = Z_AX ;
|
|
m_vtD = FromPolar( 1, dAngDeg) ;
|
|
m_sText = sText ;
|
|
m_sFont = sFont ;
|
|
m_nWeight = nW ;
|
|
m_bItalic = bItl ;
|
|
m_dHeight = dH ;
|
|
m_dRatio = dRat ;
|
|
m_dAddAdvance = dAddAdv ;
|
|
m_nInsPos = (( nInsPos >= ETXT_IPTL && nInsPos <= ETXT_IPBR) ? nInsPos : ETXT_IPBL) ;
|
|
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Set( const string& sText, const Point3d& ptP, const Vector3d& vtN, const Vector3d& vtD,
|
|
const string& sFont, int nW, bool bItl, double dH, double dRat, double dAddAdv,
|
|
int nInsPos)
|
|
{
|
|
// controllo testo non vuoto
|
|
if ( sText.empty())
|
|
return false ;
|
|
// controllo lunghezza nome font
|
|
if ( sFont.size() > MAX_FONT_LEN)
|
|
return false ;
|
|
// assegno i dati
|
|
m_ptP = ptP ;
|
|
m_vtN = vtN ;
|
|
if ( ! m_vtN.Normalize())
|
|
return false ;
|
|
m_vtD = vtD - m_vtN * ( vtD * m_vtN) ;
|
|
if ( ! m_vtD.Normalize())
|
|
return false ;
|
|
m_sText = sText ;
|
|
m_sFont = sFont ;
|
|
m_nWeight = nW ;
|
|
m_bItalic = bItl ;
|
|
m_dHeight = dH ;
|
|
m_dRatio = dRat ;
|
|
m_dAddAdvance = dAddAdv ;
|
|
m_nInsPos = (( nInsPos >= ETXT_IPTL && nInsPos <= ETXT_IPBR) ? nInsPos : ETXT_IPBL) ;
|
|
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
ExtText*
|
|
ExtText::Clone( void) const
|
|
{
|
|
// alloco oggetto
|
|
ExtText* pGPt = new(nothrow) ExtText ;
|
|
if ( pGPt != nullptr) {
|
|
if ( ! pGPt->CopyFrom( *this)) {
|
|
delete pGPt ;
|
|
return nullptr ;
|
|
}
|
|
}
|
|
|
|
return pGPt ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::CopyFrom( const IGeoObj* pGObjSrc)
|
|
{
|
|
const ExtText* pTxt = dynamic_cast<const ExtText*>( pGObjSrc) ;
|
|
if ( pTxt == nullptr)
|
|
return false ;
|
|
return CopyFrom( *pTxt) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::CopyFrom( const ExtText& clSrc)
|
|
{
|
|
if ( &clSrc == this)
|
|
return true ;
|
|
m_OGrMgr.Reset() ;
|
|
m_ptP = clSrc.m_ptP ;
|
|
m_vtN = clSrc.m_vtN ;
|
|
m_vtD = clSrc.m_vtD ;
|
|
m_sText = clSrc.m_sText ;
|
|
m_sFont = clSrc.m_sFont ;
|
|
m_nWeight = clSrc.m_nWeight ;
|
|
m_bItalic = clSrc.m_bItalic ;
|
|
m_dHeight = clSrc.m_dHeight ;
|
|
m_dRatio = clSrc.m_dRatio ;
|
|
m_dAddAdvance = clSrc.m_dAddAdvance ;
|
|
m_nInsPos = clSrc.m_nInsPos ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
GeoObjType
|
|
ExtText::GetType( void) const
|
|
{
|
|
return static_cast<GeoObjType>( GEOOBJ_GETTYPE( ExtText)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
const string&
|
|
ExtText::GetTitle( void) const
|
|
{
|
|
static const string sTitle = "Text" ;
|
|
return sTitle ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Dump( string& sOut, const char* szNewLine) const
|
|
{
|
|
// parametri
|
|
sOut += "P(" + ToString( m_ptP, 3) + ") " ;
|
|
sOut += " IP=" + ToString( m_nInsPos) + szNewLine ;
|
|
sOut += "VN(" + ToString( m_vtN, 6) + ") " + szNewLine ;
|
|
sOut += "VS(" + ToString( m_vtD, 6) + ") " + szNewLine ;
|
|
sOut += "Txt=" + m_sText + szNewLine ;
|
|
sOut += "Fnt=" + m_sFont + szNewLine ;
|
|
sOut += "W=" + ToString( m_nWeight) ;
|
|
sOut += " I=" + ToString( m_bItalic) ;
|
|
sOut += " H=" + ToString( m_dHeight, 1) ;
|
|
sOut += " R=" + ToString( m_dRatio, 3) ;
|
|
sOut += " A=" + ToString( m_dAddAdvance, 1) + szNewLine ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
ExtText::GetNgeId( void) const
|
|
{
|
|
return GEOOBJ_GETNGEID( ExtText) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Save( NgeWriter& ngeOut) const
|
|
{
|
|
// punto di inserimento
|
|
if ( ! ngeOut.WritePoint( m_ptP, ";"))
|
|
return false ;
|
|
// flag posizione inserimento
|
|
if ( ! ngeOut.WriteInt( m_nInsPos, ";"))
|
|
return false ;
|
|
// versore normale
|
|
if ( ! ngeOut.WriteVector( m_vtN, ";"))
|
|
return false ;
|
|
// versore di direzione
|
|
if ( ! ngeOut.WriteVector( m_vtD, ";", true))
|
|
return false ;
|
|
// testo
|
|
int nTextLines = int( m_sText.size()) / MAX_TXT_LINE +
|
|
( ( int( m_sText.size()) % MAX_TXT_LINE) > 0 ? 1 : 0) ;
|
|
if ( ! ngeOut.WriteInt( nTextLines, ";", true))
|
|
return false ;
|
|
string sBuff ;
|
|
for ( int i = 0 ; i < nTextLines ; ++ i) {
|
|
// copio i caratteri nel buffer
|
|
sBuff = m_sText.substr( i * MAX_TXT_LINE, MAX_TXT_LINE) ;
|
|
// sostituisco eventuale primo o ultimo spazio con carattere speciale
|
|
if ( sBuff.front() == ' ')
|
|
sBuff.front() = CHR_SPECIAL ;
|
|
if ( sBuff.back() == ' ')
|
|
sBuff.back() = CHR_SPECIAL ;
|
|
// scrivo il testo
|
|
if ( ! ngeOut.WriteString( sBuff, nullptr, true))
|
|
return false ;
|
|
}
|
|
// font
|
|
if ( ! ngeOut.WriteString( m_sFont, ";"))
|
|
return false ;
|
|
// spessore del font
|
|
if ( ! ngeOut.WriteInt( m_nWeight, ","))
|
|
return false ;
|
|
// flag di italico
|
|
if ( ! ngeOut.WriteBool( m_bItalic, ","))
|
|
return false ;
|
|
// altezza del font
|
|
if ( ! ngeOut.WriteDouble( m_dHeight, ","))
|
|
return false ;
|
|
// rapporto larghezza su altezza del font
|
|
if ( ! ngeOut.WriteDouble( m_dRatio, ","))
|
|
return false ;
|
|
// avanzamento addizionale tra caratteri
|
|
if ( ! ngeOut.WriteDouble( m_dAddAdvance, ";", true))
|
|
return false ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Load( NgeReader& ngeIn)
|
|
{
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// leggo la prossima linea : punto, posiz. inserimento, normale, direzione
|
|
if ( ! ngeIn.ReadPoint( m_ptP, ";"))
|
|
return false ;
|
|
if ( ! ngeIn.ReadInt( m_nInsPos, ";"))
|
|
return false ;
|
|
if ( ! ngeIn.ReadVector( m_vtN, ";"))
|
|
return false ;
|
|
if ( ! ngeIn.ReadVector( m_vtD, ";", true))
|
|
return false ;
|
|
// leggo la prossima linea : numero di righe di testo
|
|
int nTextLines ;
|
|
if ( ! ngeIn.ReadInt( nTextLines, ";", true))
|
|
return false ;
|
|
// leggo le stringhe che costituisco il testo
|
|
string sBuff ;
|
|
for ( int i = 0 ; i < nTextLines ; ++i) {
|
|
// leggo la linea
|
|
if ( ! ngeIn.ReadString( sBuff, nullptr, true))
|
|
return false ;
|
|
// sostituisco eventuale primo o ultimo carattere speciale con spazio
|
|
if ( sBuff.front() == CHR_SPECIAL)
|
|
sBuff.front() = ' ' ;
|
|
if ( sBuff.back() == CHR_SPECIAL)
|
|
sBuff.back() = ' ' ;
|
|
// la accodo
|
|
m_sText += sBuff ;
|
|
}
|
|
// leggo la prossima linea : font, spessore, italico, altezza, ratio, addAdvance
|
|
if ( ! ngeIn.ReadString( m_sFont, ";"))
|
|
return false ;
|
|
if ( ! ngeIn.ReadInt( m_nWeight, ","))
|
|
return false ;
|
|
if ( ! ngeIn.ReadBool( m_bItalic, ","))
|
|
return false ;
|
|
if ( ! ngeIn.ReadDouble( m_dHeight, ","))
|
|
return false ;
|
|
if ( ! ngeIn.ReadDouble( m_dRatio, ","))
|
|
return false ;
|
|
if ( ! ngeIn.ReadDouble( m_dAddAdvance, ";", true))
|
|
return false ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::GetLocalBBox( BBox3d& b3Loc) const
|
|
{
|
|
// recupero il font manager
|
|
FontManager& fntMgr = FontManager::GetFontManager() ;
|
|
|
|
// imposto il font corrente e i suoi dati
|
|
if ( ! fntMgr.SetCurrFont( m_sFont, m_nWeight, m_bItalic, m_dHeight, m_dRatio, m_dAddAdvance))
|
|
return false ;
|
|
|
|
// richiedo il box
|
|
if ( ! fntMgr.GetBBox( m_sText, m_nInsPos, b3Loc))
|
|
return false ;
|
|
|
|
// calcolo ed eseguo la trasformazione
|
|
Frame3d frRef ;
|
|
if ( ! frRef.Set( m_ptP, m_vtN, m_vtD))
|
|
return false ;
|
|
b3Loc.ToGlob( frRef) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::GetBBox( const Frame3d& frRef, BBox3d& b3Ref) const
|
|
{
|
|
// verifico validità del frame
|
|
if ( frRef.GetType() == Frame3d::ERR)
|
|
return false ;
|
|
|
|
// recupero il font manager
|
|
FontManager& fntMgr = FontManager::GetFontManager() ;
|
|
|
|
// imposto il font corrente e i suoi dati
|
|
if ( ! fntMgr.SetCurrFont( m_sFont, m_nWeight, m_bItalic, m_dHeight, m_dRatio, m_dAddAdvance))
|
|
return false ;
|
|
|
|
// richiedo il box
|
|
if ( ! fntMgr.GetBBox( m_sText, m_nInsPos, b3Ref))
|
|
return false ;
|
|
|
|
// calcolo ed eseguo la prima trasformazione (per tener conto dell'orientamento del testo)
|
|
Frame3d frTxt ;
|
|
if ( ! frTxt.Set( m_ptP, m_vtN, m_vtD))
|
|
return false ;
|
|
b3Ref.ToGlob( frTxt) ;
|
|
|
|
// porto il box nel riferimento passato
|
|
b3Ref.ToGlob( frRef) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Translate( const Vector3d& vtMove)
|
|
{
|
|
m_OGrMgr.Reset() ;
|
|
m_ptP.Translate( vtMove) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
|
|
{
|
|
m_OGrMgr.Reset() ;
|
|
return ( m_ptP.Rotate( ptAx, vtAx, dCosAng, dSinAng) &&
|
|
m_vtN.Rotate( vtAx, dCosAng, dSinAng) &&
|
|
m_vtD.Rotate( vtAx, dCosAng, dSinAng)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ)
|
|
{
|
|
// verifico non sia nulla
|
|
if ( fabs( dCoeffX) < EPS_ZERO && fabs( dCoeffY) < EPS_ZERO && fabs( dCoeffZ) < EPS_ZERO)
|
|
return false ;
|
|
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
|
|
// scalo il punto di inserimento
|
|
if ( ! m_ptP.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ))
|
|
return false ;
|
|
|
|
// calcolo il versore altezza testo
|
|
Vector3d vtH = m_vtN ^ m_vtD ;
|
|
vtH.Normalize() ;
|
|
// scalo il versore direzione
|
|
if ( ! m_vtD.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ))
|
|
return false ;
|
|
double dScaleD = m_vtD.Len() ;
|
|
m_vtD /= dScaleD ;
|
|
// scalo il versore altezza testo
|
|
if ( ! vtH.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ))
|
|
return false ;
|
|
// per il coeff di scalatura considero solo la parte perpendicolare alla nuova direzione start
|
|
double dScaleH = sqrt( vtH.SqLen() - ( vtH * m_vtD) *( vtH * m_vtD)) ;
|
|
// aggiorno il vettore normale
|
|
m_vtN = m_vtD ^ vtH ;
|
|
m_vtN.Normalize() ;
|
|
// aggiorno i parametri altezza testo e ratio
|
|
m_dHeight *= dScaleH ;
|
|
if ( dScaleH > EPS_ZERO)
|
|
m_dRatio *= dScaleD / dScaleH ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Mirror( const Point3d& ptOn, const Vector3d& vtNorm)
|
|
{
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
|
|
// eseguo il mirror del punto di inserimento
|
|
if ( ! m_ptP.Mirror( ptOn, vtNorm))
|
|
return false ;
|
|
|
|
// calcolo il versore altezza testo
|
|
Vector3d vtH = m_vtN ^ m_vtD ;
|
|
vtH.Normalize() ;
|
|
// eseguo il mirror del versore direzione
|
|
if ( ! m_vtD.Mirror( vtNorm))
|
|
return false ;
|
|
// eseguo il mirror del versore altezza testo
|
|
if ( ! vtH.Mirror( vtNorm))
|
|
return false ;
|
|
// aggiorno il vettore normale
|
|
m_vtN = m_vtD ^ vtH ;
|
|
m_vtN.Normalize() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff)
|
|
{
|
|
// verifico validità dei parametri
|
|
if ( vtNorm.IsSmall() || vtDir.IsSmall())
|
|
return false ;
|
|
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
|
|
// eseguo scorrimento del punto di inserimento
|
|
if ( ! m_ptP.Shear( ptOn, vtNorm, vtDir, dCoeff))
|
|
return false ;
|
|
|
|
// calcolo il versore altezza testo
|
|
Vector3d vtH = m_vtN ^ m_vtD ;
|
|
vtH.Normalize() ;
|
|
// eseguo scorrimento del versore direzione
|
|
if ( ! m_vtD.Shear( vtNorm, vtDir, dCoeff))
|
|
return false ;
|
|
double dScaleD = m_vtD.Len() ;
|
|
m_vtD /= dScaleD ;
|
|
// eseguo scorrimento del versore altezza testo
|
|
if ( ! vtH.Shear( vtNorm, vtDir, dCoeff))
|
|
return false ;
|
|
// per il coeff di scalatura considero solo la parte perpendicolare alla nuova direzione start
|
|
double dScaleH = sqrt( vtH.SqLen() - ( vtH * m_vtD) *( vtH * m_vtD)) ;
|
|
// aggiorno il vettore normale
|
|
m_vtN = m_vtD ^ vtH ;
|
|
m_vtN.Normalize() ;
|
|
// aggiorno i parametri altezza testo e ratio
|
|
m_dHeight *= dScaleH ;
|
|
if ( dScaleH > EPS_ZERO)
|
|
m_dRatio *= dScaleD / dScaleH ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::ToGlob( const Frame3d& frRef)
|
|
{
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// trasformo punto e versori
|
|
return ( m_ptP.ToGlob( frRef) &&
|
|
m_vtN.ToGlob( frRef) &&
|
|
m_vtD.ToGlob( frRef)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::ToLoc( const Frame3d& frRef)
|
|
{
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// trasformo punto e versori
|
|
return ( m_ptP.ToLoc( frRef) &&
|
|
m_vtN.ToLoc( frRef) &&
|
|
m_vtD.ToLoc( frRef)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::LocToLoc( const Frame3d& frOri, const Frame3d& frDest)
|
|
{
|
|
// verifico validità dei frame
|
|
if ( frOri.GetType() == Frame3d::ERR || frDest.GetType() == Frame3d::ERR)
|
|
return false ;
|
|
// se i due riferimenti coincidono, non devo fare alcunché
|
|
if ( AreSameFrame( frOri, frDest))
|
|
return true ;
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// trasformo punto e versori
|
|
return ( m_ptP.ToGlob( frOri) && m_ptP.ToLoc( frDest) &&
|
|
m_vtN.ToGlob( frOri) && m_vtN.ToLoc( frDest) &&
|
|
m_vtD.ToGlob( frOri) && m_vtD.ToLoc( frDest)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::GetHeightVersor( Vector3d& vtH) const
|
|
{
|
|
vtH = m_vtN ^ m_vtD ;
|
|
return ( vtH.Normalize()) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::GetStartPoint( Point3d& ptStart) const
|
|
{
|
|
// imposto il font corrente e i suoi dati
|
|
FontManager& fntMgr = FontManager::GetFontManager() ;
|
|
if ( ! fntMgr.SetCurrFont( m_sFont, m_nWeight, m_bItalic, m_dHeight, m_dRatio, m_dAddAdvance))
|
|
return false ;
|
|
|
|
// richiedo il box delle maiuscole
|
|
BBox3d b3Loc ;
|
|
if ( ! fntMgr.GetCapBox( m_sText, m_nInsPos, b3Loc))
|
|
return false ;
|
|
|
|
// ricavo il punto di inizio
|
|
ptStart = b3Loc.GetMin() ;
|
|
|
|
// calcolo ed eseguo la trasformazione (da riferimento canonico font alla entità)
|
|
Frame3d frRef ;
|
|
if ( ! frRef.Set( m_ptP, m_vtN, m_vtD))
|
|
return false ;
|
|
ptStart.ToGlob( frRef) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::GetOverStartPoint( Point3d& ptStart) const
|
|
{
|
|
// imposto il font corrente e i suoi dati
|
|
FontManager& fntMgr = FontManager::GetFontManager() ;
|
|
if ( ! fntMgr.SetCurrFont( m_sFont, m_nWeight, m_bItalic, m_dHeight, m_dRatio, m_dAddAdvance))
|
|
return false ;
|
|
|
|
// richiedo il box delle maiuscole
|
|
BBox3d b3Loc ;
|
|
if ( ! fntMgr.GetCapBox( m_sText, m_nInsPos, b3Loc))
|
|
return false ;
|
|
|
|
// ricavo il punto sopra l'inizio
|
|
ptStart.Set( b3Loc.GetMin().x, b3Loc.GetMax().y, 0) ;
|
|
|
|
// calcolo ed eseguo la trasformazione (da riferimento canonico font alla entità)
|
|
Frame3d frRef ;
|
|
if ( ! frRef.Set( m_ptP, m_vtN, m_vtD))
|
|
return false ;
|
|
ptStart.ToGlob( frRef) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::GetEndPoint( Point3d& ptEnd) const
|
|
{
|
|
// imposto il font corrente e i suoi dati
|
|
FontManager& fntMgr = FontManager::GetFontManager() ;
|
|
if ( ! fntMgr.SetCurrFont( m_sFont, m_nWeight, m_bItalic, m_dHeight, m_dRatio, m_dAddAdvance))
|
|
return false ;
|
|
|
|
// richiedo il box delle maiuscole
|
|
BBox3d b3Loc ;
|
|
if ( ! fntMgr.GetCapBox( m_sText, m_nInsPos, b3Loc))
|
|
return false ;
|
|
|
|
// ricavo il punto di fine
|
|
ptEnd.Set( b3Loc.GetMax().x, b3Loc.GetMin().y, 0) ;
|
|
|
|
// calcolo ed eseguo la trasformazione (da riferimento canonico font alla entità)
|
|
Frame3d frRef ;
|
|
if ( ! frRef.Set( m_ptP, m_vtN, m_vtD))
|
|
return false ;
|
|
ptEnd.ToGlob( frRef) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::GetOverEndPoint( Point3d& ptEnd) const
|
|
{
|
|
// imposto il font corrente e i suoi dati
|
|
FontManager& fntMgr = FontManager::GetFontManager() ;
|
|
if ( ! fntMgr.SetCurrFont( m_sFont, m_nWeight, m_bItalic, m_dHeight, m_dRatio, m_dAddAdvance))
|
|
return false ;
|
|
|
|
// richiedo il box delle maiuscole
|
|
BBox3d b3Loc ;
|
|
if ( ! fntMgr.GetCapBox( m_sText, m_nInsPos, b3Loc))
|
|
return false ;
|
|
|
|
// ricavo il punto sopra la fine
|
|
ptEnd = b3Loc.GetMax() ;
|
|
|
|
// calcolo ed eseguo la trasformazione (da riferimento canonico font alla entità)
|
|
Frame3d frRef ;
|
|
if ( ! frRef.Set( m_ptP, m_vtN, m_vtD))
|
|
return false ;
|
|
ptEnd.ToGlob( frRef) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::GetMidPoint( Point3d& ptMid) const
|
|
{
|
|
// imposto il font corrente e i suoi dati
|
|
FontManager& fntMgr = FontManager::GetFontManager() ;
|
|
if ( ! fntMgr.SetCurrFont( m_sFont, m_nWeight, m_bItalic, m_dHeight, m_dRatio, m_dAddAdvance))
|
|
return false ;
|
|
|
|
// richiedo il box delle maiuscole
|
|
BBox3d b3Loc ;
|
|
if ( ! fntMgr.GetCapBox( m_sText, m_nInsPos, b3Loc))
|
|
return false ;
|
|
|
|
// assegno il medio
|
|
ptMid.Set( 0.5 * ( b3Loc.GetMin().x + b3Loc.GetMax().x), b3Loc.GetMin().y, 0) ;
|
|
|
|
// calcolo ed eseguo la trasformazione (da riferimento canonico font alla entità)
|
|
Frame3d frRef ;
|
|
if ( ! frRef.Set( m_ptP, m_vtN, m_vtD))
|
|
return false ;
|
|
ptMid.ToGlob( frRef) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::GetCenterPoint( Point3d& ptCen) const
|
|
{
|
|
// imposto il font corrente e i suoi dati
|
|
FontManager& fntMgr = FontManager::GetFontManager() ;
|
|
if ( ! fntMgr.SetCurrFont( m_sFont, m_nWeight, m_bItalic, m_dHeight, m_dRatio, m_dAddAdvance))
|
|
return false ;
|
|
|
|
// richiedo il box delle maiuscole
|
|
BBox3d b3Loc ;
|
|
if ( ! fntMgr.GetCapBox( m_sText, m_nInsPos, b3Loc))
|
|
return false ;
|
|
|
|
// ricavo il centro
|
|
ptCen = Media( b3Loc.GetMin(), b3Loc.GetMax(), 0.5) ;
|
|
|
|
// calcolo ed eseguo la trasformazione (da riferimento canonico font alla entità)
|
|
Frame3d frRef ;
|
|
if ( ! frRef.Set( m_ptP, m_vtN, m_vtD))
|
|
return false ;
|
|
ptCen.ToGlob( frRef) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::GetOutline( ICURVEPLIST& lstPC) const
|
|
{
|
|
// imposto il font corrente e i suoi dati
|
|
FontManager& fntMgr = FontManager::GetFontManager() ;
|
|
if ( ! fntMgr.SetCurrFont( m_sFont, m_nWeight, m_bItalic, m_dHeight, m_dRatio, m_dAddAdvance))
|
|
return false ;
|
|
|
|
// richiedo l'outline
|
|
if ( ! fntMgr.GetOutline( m_sText, m_nInsPos, lstPC))
|
|
return false ;
|
|
|
|
// calcolo la trasformazione
|
|
Frame3d frRef ;
|
|
if ( ! frRef.Set( m_ptP, m_vtN, m_vtD))
|
|
return false ;
|
|
|
|
// eseguo la trasformazione
|
|
ICURVEPLIST::iterator Iter ;
|
|
for ( Iter = lstPC.begin() ; Iter != lstPC.end() ; ++ Iter)
|
|
(*Iter)->ToGlob( frRef) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::ApproxWithLines( double dLinTol, double dAngTolDeg, POLYLINELIST& lstPL) const
|
|
{
|
|
// imposto il font corrente e i suoi dati
|
|
FontManager& fntMgr = FontManager::GetFontManager() ;
|
|
if ( ! fntMgr.SetCurrFont( m_sFont, m_nWeight, m_bItalic, m_dHeight, m_dRatio, m_dAddAdvance))
|
|
return false ;
|
|
|
|
// richiedo l'outline
|
|
if ( ! fntMgr.ApproxWithLines( m_sText, m_nInsPos, dLinTol, dAngTolDeg, lstPL))
|
|
return false ;
|
|
|
|
// calcolo la trasformazione
|
|
Frame3d frRef ;
|
|
if ( ! frRef.Set( m_ptP, m_vtN, m_vtD))
|
|
return false ;
|
|
|
|
// eseguo la trasformazione
|
|
POLYLINELIST::iterator Iter ;
|
|
for ( Iter = lstPL.begin() ; Iter != lstPL.end() ; ++ Iter)
|
|
Iter->ToGlob( frRef) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Flip( void)
|
|
{
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// recupero il centro
|
|
Point3d ptCen ;
|
|
if ( ! GetCenterPoint( ptCen))
|
|
return false ;
|
|
// calcolo il nuovo punto di inserimento
|
|
m_ptP += 2 * ( ptCen - m_ptP) ;
|
|
// inverto la direzione di riferimento
|
|
m_vtD *= -1 ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::Mir( bool bOnLen)
|
|
{
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// imposto il font corrente e i suoi dati
|
|
FontManager& fntMgr = FontManager::GetFontManager() ;
|
|
if ( ! fntMgr.SetCurrFont( m_sFont, m_nWeight, m_bItalic, m_dHeight, m_dRatio, m_dAddAdvance))
|
|
return false ;
|
|
|
|
// se auto-mirror sulla lunghezza del testo
|
|
if ( bOnLen) {
|
|
// faccio mirror sulla lunghezza della posizione di inserimento
|
|
switch ( m_nInsPos) {
|
|
case ETXT_IPTL : m_nInsPos = ETXT_IPTR ; break ;
|
|
case ETXT_IPTR : m_nInsPos = ETXT_IPTL ; break ;
|
|
case ETXT_IPML : m_nInsPos = ETXT_IPMR ; break ;
|
|
case ETXT_IPMR : m_nInsPos = ETXT_IPML ; break ;
|
|
case ETXT_IPBL : m_nInsPos = ETXT_IPBR ; break ;
|
|
case ETXT_IPBR : m_nInsPos = ETXT_IPBL ; break ;
|
|
}
|
|
// inverto i versori
|
|
m_vtN.Invert() ;
|
|
m_vtD.Invert() ;
|
|
}
|
|
// altrimenti auto-mirror su altezza del testo
|
|
else {
|
|
// faccio mirror sulla altezza della posizione di inserimento
|
|
switch ( m_nInsPos) {
|
|
case ETXT_IPTL : m_nInsPos = ETXT_IPBL ; break ;
|
|
case ETXT_IPTC : m_nInsPos = ETXT_IPBC ; break ;
|
|
case ETXT_IPTR : m_nInsPos = ETXT_IPBR ; break ;
|
|
case ETXT_IPBL : m_nInsPos = ETXT_IPTL ; break ;
|
|
case ETXT_IPBC : m_nInsPos = ETXT_IPTC ; break ;
|
|
case ETXT_IPBR : m_nInsPos = ETXT_IPTR ; break ;
|
|
}
|
|
// inverto il versore normale
|
|
m_vtN.Invert() ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::ModifyText( const string& sText)
|
|
{
|
|
// verifico che il testo sia valido
|
|
if ( sText.empty())
|
|
return false ;
|
|
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// assegno nuovo test
|
|
m_sText = sText ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExtText::ChangeFont( const string& sFont)
|
|
{
|
|
// imposto ricalcolo della grafica
|
|
m_OGrMgr.Reset() ;
|
|
// assegno nuovo font
|
|
m_sFont = sFont ;
|
|
|
|
return true ;
|
|
} |