diff --git a/EGkDllMain.cpp b/EGkDllMain.cpp index fe279e2..9af4caf 100644 --- a/EGkDllMain.cpp +++ b/EGkDllMain.cpp @@ -70,7 +70,7 @@ DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved) const char* GetEGkVersion( void) { - std::string sVer ; + string sVer ; GetModuleVersion( s_hModule, sVer) ; sprintf_s( s_szEGkNameVer, STR_DIM, "%s%s", EGK_STR, sVer.c_str()) ; @@ -96,12 +96,12 @@ GetEGkLogger( void) } //----------------------------------------------------------------------------- -static std::string s_sKey ; +static string s_sKey ; static int s_nKeyType = KEY_LOCK_TYPE_ANY ; //----------------------------------------------------------------------------- void -SetEGkKey( const std::string& sKey) +SetEGkKey( const string& sKey) { s_sKey = sKey ; } diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index 1ce66cd..7495a22 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/EgtGeomKernel.vcxproj b/EgtGeomKernel.vcxproj index 530478d..d5e8537 100644 --- a/EgtGeomKernel.vcxproj +++ b/EgtGeomKernel.vcxproj @@ -281,6 +281,7 @@ copy $(TargetPath) \EgtProg\Dll64 + @@ -514,6 +515,7 @@ copy $(TargetPath) \EgtProg\Dll64 + diff --git a/EgtGeomKernel.vcxproj.filters b/EgtGeomKernel.vcxproj.filters index 18b6aa7..2b8bb21 100644 --- a/EgtGeomKernel.vcxproj.filters +++ b/EgtGeomKernel.vcxproj.filters @@ -396,6 +396,9 @@ File di origine\Geo + + File di origine\Geo + @@ -950,6 +953,9 @@ File di intestazione\Include + + File di intestazione + diff --git a/ExtDimension.cpp b/ExtDimension.cpp new file mode 100644 index 0000000..92b528f --- /dev/null +++ b/ExtDimension.cpp @@ -0,0 +1,765 @@ +//---------------------------------------------------------------------------- +// EgalTech 2019-2019 +//---------------------------------------------------------------------------- +// File : ExtDimension.cpp Data : 27.12.19 Versione : 2.2a1 +// Contenuto : Implementazione della classe Dimension (quota). +// +// +// +// Modifiche : 27.12.19 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "ExtDimension.h" +#include "GeoObjFactory.h" +#include "NgeWriter.h" +#include "NgeReader.h" +#include "FontManager.h" +#include "FontAux.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EGkExtText.h" +#include "/EgtDev/Include/EGkUiUnits.h" +#include + +using namespace std ; + +//---------------------------------------------------------------------------- +static const string IS_MEASURE = "<>" ; +static const string STD_FONT = "ModernPropS.Nfe" ; +static const int FONT_WEIGHT = 400 ; +static const bool FONT_ITALIC = false ; +static const double FONT_RATIO = 0.75 ; +static const double FONT_ADDADVANCE = 0 ; + +//---------------------------------------------------------------------------- +GEOOBJ_REGISTER( EXT_DIMENSION, NGE_E_DIM, ExtDimension) ; + +//---------------------------------------------------------------------------- +ExtDimension::ExtDimension( void) + : m_dExtLineLen( 5), m_dArrowLen( 5), m_dTextDist( 2), m_bLenIsMM( true), m_nLenDec( -2), m_sFont( STD_FONT), m_dTextHeight( 10) +{ +} + +//---------------------------------------------------------------------------- +ExtDimension::~ExtDimension( void) +{ +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::SetLinear( const Point3d& ptP1, const Point3d& ptP2, const Point3d& ptPos, + const Vector3d& vtN, const Vector3d& vtDir, const string& sText) +{ + // dichiaro quota non ancora determinata + m_nType = DT_NONE ; + // verifico la definizione del versore normale + m_vtN = vtN ; + if ( ! m_vtN.Normalize()) + return false ; + // porto i punti nel piano definito da P1 e N + m_ptP1 = ptP1 ; + m_ptP2 = ptP2 - ( ptP2 - m_ptP1) * m_vtN * m_vtN ; + m_ptPos = ptPos - ( ptPos - m_ptP1) * m_vtN * m_vtN ; + // verifico che i punti di misura non siano coincidenti + if ( AreSamePointApprox( m_ptP1, m_ptP2)) + return false ; + // direzione di riferimento (nel piano perpendicolare a vtN) + m_vtDir = vtDir ; + if ( m_vtDir.IsSmall()) + m_vtDir = m_ptP2 - m_ptP1 ; + else { + m_vtDir -= m_vtDir * m_vtN * m_vtN ; + if ( m_vtDir * ( m_ptP2 - m_ptP1) < 0) + m_vtDir.Invert() ; + } + if ( ! m_vtDir.Normalize()) + return false ; + // punti estremi della linea di misura ed esterni delle linee di estremità + Vector3d vtLine = m_vtDir ; + vtLine.Rotate( m_vtN, 0, 1) ; + if ( vtLine * ( m_ptPos - m_ptP1) < 0) + vtLine.Invert() ; + m_ptP5 = m_ptP1 + vtLine * ( m_ptPos - m_ptP1) * vtLine ; + m_ptP6 = m_ptP2 + vtLine * ( m_ptPos - m_ptP2) * vtLine ; + m_ptP3 = m_ptP5 + vtLine * m_dExtLineLen ; + m_ptP4 = m_ptP6 + vtLine * m_dExtLineLen ; + // assegnazione del testo + m_sText = sText ; + // assegno il tipo + m_nType = DT_LINEAR ; + // imposto da calcolare + m_bToCalc = true ; + m_OGrMgr.Reset() ; + + return true ; +} + +//---------------------------------------------------------------------------- +ExtDimension* +ExtDimension::Clone( void) const +{ + // alloco oggetto + ExtDimension* pDim = new( nothrow) ExtDimension ; + if ( pDim != nullptr) { + if ( ! pDim->CopyFrom( *this)) { + delete pDim ; + return nullptr ; + } + } + + return pDim ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::CopyFrom( const IGeoObj* pGObjSrc) +{ + const ExtDimension* pDim = dynamic_cast( pGObjSrc) ; + if ( pDim == nullptr) + return false ; + return CopyFrom( *pDim) ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::CopyFrom( const ExtDimension& clSrc) +{ + if ( &clSrc == this) + return true ; + m_OGrMgr.Reset() ; + m_nType = clSrc.m_nType ; + m_vtN = clSrc.m_vtN ; + m_vtDir = clSrc.m_vtDir ; + m_ptP1 = clSrc.m_ptP1 ; + m_ptP2 = clSrc.m_ptP2 ; + m_ptP3 = clSrc.m_ptP3 ; + m_ptP4 = clSrc.m_ptP4 ; + m_ptP5 = clSrc.m_ptP5 ; + m_ptP6 = clSrc.m_ptP6 ; + m_ptPos = clSrc.m_ptPos ; + m_sText = clSrc.m_sText ; + m_bToCalc = clSrc.m_bToCalc ; + m_ptOutPos = clSrc.m_ptOutPos ; + m_sOutText = clSrc.m_sOutText ; + m_dExtLineLen = clSrc.m_dExtLineLen ; + m_dArrowLen = clSrc.m_dArrowLen ; + m_dTextDist = clSrc.m_dTextDist ; + m_bLenIsMM = clSrc.m_bLenIsMM ; + m_nLenDec = clSrc.m_nLenDec ; + m_sFont = clSrc.m_sFont ; + m_dTextHeight = clSrc.m_dTextHeight ; + m_nTempProp = clSrc.m_nTempProp ; + return true ; +} + +//---------------------------------------------------------------------------- +GeoObjType +ExtDimension::GetType( void) const +{ + return static_cast( GEOOBJ_GETTYPE( ExtDimension)) ; +} + +//---------------------------------------------------------------------------- +const string& +ExtDimension::GetTitle( void) const +{ + static const string sTitle = "Dimension" ; + return sTitle ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::Dump( string& sOut, bool bMM, const char* szNewLine) const +{ + // parametri + sOut += "VN(" + ToString( m_vtN, 6) + ") " + szNewLine ; + + return true ; +} + +//---------------------------------------------------------------------------- +int +ExtDimension::GetNgeId( void) const +{ + return GEOOBJ_GETNGEID( ExtDimension) ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::Save( NgeWriter& ngeOut) const +{ + // tipo + if ( ! ngeOut.WriteInt( m_nType, ";", true)) + return false ; + // versori normale e direzione + if ( ! ngeOut.WriteVector( m_vtN, ";")) + return false ; + if ( ! ngeOut.WriteVector( m_vtDir, ";", true)) + return false ; + // punti di quotatura + if ( ! ngeOut.WritePoint( m_ptP1, ";")) + return false ; + if ( ! ngeOut.WritePoint( m_ptP2, ";")) + return false ; + if ( ! ngeOut.WritePoint( m_ptP3, ";")) + return false ; + if ( ! ngeOut.WritePoint( m_ptP4, ";", true)) + return false ; + if ( ! ngeOut.WritePoint( m_ptP5, ";")) + return false ; + if ( ! ngeOut.WritePoint( m_ptP6, ";")) + return false ; + if ( ! ngeOut.WritePoint( m_ptPos, ";", true)) + return false ; + // testo + if ( ! ngeOut.WriteString( m_sText, ";", true)) + return false ; + // attributi + if ( ! ngeOut.WriteDouble( m_dExtLineLen, ",")) + return false ; + if ( ! ngeOut.WriteDouble( m_dArrowLen, ",")) + return false ; + if ( ! ngeOut.WriteDouble( m_dTextDist, ",")) + return false ; + if ( ! ngeOut.WriteBool( m_bLenIsMM, ",")) + return false ; + if ( ! ngeOut.WriteInt( m_nLenDec, ",")) + return false ; + if ( ! ngeOut.WriteString( m_sFont, ",")) + return false ; + if ( ! ngeOut.WriteDouble( m_dTextHeight, ";", true)) + return false ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::Load( NgeReader& ngeIn) +{ + // imposto ricalcolo + m_bToCalc = true ; + m_OGrMgr.Reset() ; + // leggo la prossima linea : tipo + if ( ! ngeIn.ReadInt( m_nType, ";", true)) + return false ; + // leggo la prossima linea : versori normale e direzione + if ( ! ngeIn.ReadVector( m_vtN, ";")) + return false ; + if ( ! ngeIn.ReadVector( m_vtDir, ";", true)) + return false ; + // leggo la prossima linea : punti di quotatura + if ( ! ngeIn.ReadPoint( m_ptP1, ";")) + return false ; + if ( ! ngeIn.ReadPoint( m_ptP2, ";")) + return false ; + if ( ! ngeIn.ReadPoint( m_ptP3, ";")) + return false ; + if ( ! ngeIn.ReadPoint( m_ptP4, ";", true)) + return false ; + if ( ! ngeIn.ReadPoint( m_ptP5, ";")) + return false ; + if ( ! ngeIn.ReadPoint( m_ptP6, ";")) + return false ; + if ( ! ngeIn.ReadPoint( m_ptPos, ";", true)) + return false ; + // leggo la prossima linea : testo + if ( ! ngeIn.ReadString( m_sText, ";", true)) + return false ; + // leggo la prossima linea : attributi + if ( ! ngeIn.ReadDouble( m_dExtLineLen, ",")) + return false ; + if ( ! ngeIn.ReadDouble( m_dArrowLen, ",")) + return false ; + if ( ! ngeIn.ReadDouble( m_dTextDist, ",")) + return false ; + if ( ! ngeIn.ReadBool( m_bLenIsMM, ",")) + return false ; + if ( ! ngeIn.ReadInt( m_nLenDec, ",")) + return false ; + if ( ! ngeIn.ReadString( m_sFont, ",")) + return false ; + if ( ! ngeIn.ReadDouble( m_dTextHeight, ";", true)) + return false ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::GetLocalBBox( BBox3d& b3Loc, int nFlag) const +{ + // se lineare + if ( m_nType == DT_LINEAR) { + b3Loc.Set( m_ptP1) ; + b3Loc.Add( m_ptP2) ; + b3Loc.Set( m_ptP3) ; + b3Loc.Add( m_ptP4) ; + // ingombro del testo + BBox3d b3Text ; + if ( GetTextLocalBBox( b3Text)) + b3Loc.Add( b3Text) ; + return true ; + } + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag) const +{ + // verifico validità del frame + if ( frRef.GetType() == Frame3d::ERR) + return false ; + // se lineare + if ( m_nType == DT_LINEAR) { + // porto i punti nel riferimento passato + Point3d ptFrP1 = m_ptP1 ; + ptFrP1.ToGlob( frRef) ; + Point3d ptFrP2 = m_ptP2 ; + ptFrP2.ToGlob( frRef) ; + Point3d ptFrP3 = m_ptP3 ; + ptFrP3.ToGlob( frRef) ; + Point3d ptFrP4 = m_ptP4 ; + ptFrP4.ToGlob( frRef) ; + // assegno il box nel riferimento + b3Ref.Set( ptFrP1) ; + b3Ref.Add( ptFrP2) ; + b3Ref.Add( ptFrP3) ; + b3Ref.Add( ptFrP4) ; + // ingombro del testo + BBox3d b3Text ; + if ( GetTextBBox( frRef, b3Text)) + b3Ref.Add( b3Text) ; + return true ; + } + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::Translate( const Vector3d& vtMove) +{ + // imposto ricalcolo + m_bToCalc = true ; + m_OGrMgr.Reset() ; + // se lineare + if ( m_nType == DT_LINEAR) { + m_ptP1.Translate( vtMove) ; + m_ptP2.Translate( vtMove) ; + m_ptP3.Translate( vtMove) ; + m_ptP4.Translate( vtMove) ; + m_ptP5.Translate( vtMove) ; + m_ptP6.Translate( vtMove) ; + m_ptPos.Translate( vtMove) ; + return true ; + } + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) +{ + // imposto ricalcolo + m_bToCalc = true ; + m_OGrMgr.Reset() ; + // se lineare + if ( m_nType == DT_LINEAR) { + return ( m_vtN.Rotate( vtAx, dCosAng, dSinAng) && + m_vtDir.Rotate( vtAx, dCosAng, dSinAng) && + m_ptP1.Rotate( ptAx, vtAx, dCosAng, dSinAng) && + m_ptP2.Rotate( ptAx, vtAx, dCosAng, dSinAng) && + m_ptP3.Rotate( ptAx, vtAx, dCosAng, dSinAng) && + m_ptP4.Rotate( ptAx, vtAx, dCosAng, dSinAng) && + m_ptP5.Rotate( ptAx, vtAx, dCosAng, dSinAng) && + m_ptP6.Rotate( ptAx, vtAx, dCosAng, dSinAng) && + m_ptPos.Rotate( ptAx, vtAx, dCosAng, dSinAng)) ; + } + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) +{ + // verifico non sia nulla + if ( abs( dCoeffX) < EPS_ZERO && abs( dCoeffY) < EPS_ZERO && abs( dCoeffZ) < EPS_ZERO) + return false ; + // imposto ricalcolo + m_bToCalc = true ; + m_OGrMgr.Reset() ; + // se lineare + if ( m_nType == DT_LINEAR) { + // sistemo i vettori + Vector3d vtTmp = m_vtN ^ m_vtDir ; + if ( ! vtTmp.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) || ! vtTmp.Normalize()) + return false ; + if ( ! m_vtDir.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) || ! m_vtDir.Normalize()) + return false ; + m_vtN = m_vtDir ^ vtTmp ; + if ( ! m_vtN.Normalize()) + return false ; + // scalo i punti di base + if ( ! m_ptP1.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ)) + return false ; + if ( ! m_ptP2.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ)) + return false ; + if ( ! m_ptPos.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ)) + return false ; + // ricalcolo completamente la quota + return SetLinear( m_ptP1, m_ptP2, m_ptPos, m_vtN, m_vtDir, m_sText) ; + } + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::Mirror( const Point3d& ptOn, const Vector3d& vtNorm) +{ + // verifico validità del piano di specchiatura + if ( vtNorm.IsSmall()) + return false ; + // imposto ricalcolo + m_bToCalc = true ; + m_OGrMgr.Reset() ; + // se lineare + if ( m_nType == DT_LINEAR) { + // eseguo il mirror dei versori + if ( ! m_vtN.Mirror( vtNorm)) + return false ; + if ( ! m_vtDir.Mirror( vtNorm)) + return false ; + // eseguo il mirror dei punti + if ( ! m_ptP1.Mirror( ptOn, vtNorm)) + return false ; + if ( ! m_ptP2.Mirror( ptOn, vtNorm)) + return false ; + if ( ! m_ptP3.Mirror( ptOn, vtNorm)) + return false ; + if ( ! m_ptP4.Mirror( ptOn, vtNorm)) + return false ; + if ( ! m_ptP5.Mirror( ptOn, vtNorm)) + return false ; + if ( ! m_ptP6.Mirror( ptOn, vtNorm)) + return false ; + if ( ! m_ptPos.Mirror( ptOn, vtNorm)) + return false ; + return true ; + } + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::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 + m_bToCalc = true ; + m_OGrMgr.Reset() ; + // se lineare + if ( m_nType == DT_LINEAR) { + // sistemo i vettori + Vector3d vtTmp = m_vtN ^ m_vtDir ; + if ( ! vtTmp.Shear( vtNorm, vtDir, dCoeff) || ! vtTmp.Normalize()) + return false ; + if ( ! m_vtDir.Shear( vtNorm, vtDir, dCoeff) || ! m_vtDir.Normalize()) + return false ; + m_vtN = m_vtDir ^ vtTmp ; + if ( ! m_vtN.Normalize()) + return false ; + // eseguo scorrimento dei punti di base + if ( ! m_ptP1.Shear( ptOn, vtNorm, vtDir, dCoeff)) + return false ; + if ( ! m_ptP2.Shear( ptOn, vtNorm, vtDir, dCoeff)) + return false ; + if ( ! m_ptPos.Shear( ptOn, vtNorm, vtDir, dCoeff)) + return false ; + // ricalcolo completamente la quota + return SetLinear( m_ptP1, m_ptP2, m_ptPos, m_vtN, m_vtDir, m_sText) ; + } + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::ToGlob( const Frame3d& frRef) +{ + // verifico validità del frame + if ( frRef.GetType() == Frame3d::ERR) + return false ; + // imposto ricalcolo + m_bToCalc = true ; + m_OGrMgr.Reset() ; + // se lineare + if ( m_nType == DT_LINEAR) { + // trasformo punto e versori + return ( m_vtN.ToGlob( frRef) && + m_vtDir.ToGlob( frRef) && + m_ptP1.ToGlob( frRef) && + m_ptP2.ToGlob( frRef) && + m_ptP3.ToGlob( frRef) && + m_ptP4.ToGlob( frRef) && + m_ptP5.ToGlob( frRef) && + m_ptP6.ToGlob( frRef) && + m_ptPos.ToGlob( frRef)) ; + } + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::ToLoc( const Frame3d& frRef) +{ + // verifico validità del frame + if ( frRef.GetType() == Frame3d::ERR) + return false ; + // imposto ricalcolo + m_bToCalc = true ; + m_OGrMgr.Reset() ; + // se lineare + if ( m_nType == DT_LINEAR) { + // trasformo punto e versori + return ( m_vtN.ToLoc( frRef) && + m_vtDir.ToLoc( frRef) && + m_ptP1.ToLoc( frRef) && + m_ptP2.ToLoc( frRef) && + m_ptP3.ToLoc( frRef) && + m_ptP4.ToLoc( frRef) && + m_ptP5.ToLoc( frRef) && + m_ptP6.ToLoc( frRef) && + m_ptPos.ToLoc( frRef)) ; + } + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::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 + m_bToCalc = true ; + m_OGrMgr.Reset() ; + // trasformo punto e versori + return ( m_vtN.ToGlob( frOri) && m_vtN.ToLoc( frDest) && + m_vtDir.ToGlob( frOri) && m_vtDir.ToLoc( frDest) && + m_ptP1.ToGlob( frOri) && m_ptP1.ToLoc( frDest) && + m_ptP2.ToGlob( frOri) && m_ptP2.ToLoc( frDest) && + m_ptP3.ToGlob( frOri) && m_ptP3.ToLoc( frDest) && + m_ptP4.ToGlob( frOri) && m_ptP4.ToLoc( frDest) && + m_ptP5.ToGlob( frOri) && m_ptP5.ToLoc( frDest) && + m_ptP6.ToGlob( frOri) && m_ptP6.ToLoc( frDest) && + m_ptPos.ToGlob( frOri) && m_ptPos.ToLoc( frDest)) ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::Update( void) const +{ + // se ricalcolo non richiesto, esco + if ( ! m_bToCalc) + return true ; + // se quota lineare + if ( m_nType == DT_LINEAR) { + // testo + m_sOutText = m_sText ; + if ( m_sOutText.find( IS_MEASURE) != string::npos) { + double dVal = ( m_ptP2 - m_ptP1) * m_vtDir * ( m_bLenIsMM ? 1 : 1. / ONEINCH) ; + string sVal = ToString( dVal, m_nLenDec) ; + ReplaceString( m_sOutText, IS_MEASURE, sVal) ; + } + // punto di inserimento del testo + m_ptOutPos = ( m_ptP5 + m_ptP6) / 2 ; + // dichiaro ricalcolo eseguito + m_bToCalc = false ; + return true ; + } + else + return false ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::ApproxWithLines( double dLinTol, double dAngTolDeg, POLYLINELIST& lstPL) const +{ + // eventuale ricalcolo + if ( m_bToCalc) + Update() ; + // se quota lineare + if ( m_nType == DT_LINEAR) { + // prima linea di riferimento + lstPL.emplace_back() ; + lstPL.back().AddUPoint( 0, m_ptP1) ; + lstPL.back().AddUPoint( 1, m_ptP3) ; + // seconda linea di riferimento + lstPL.emplace_back() ; + lstPL.back().AddUPoint( 0, m_ptP2) ; + lstPL.back().AddUPoint( 1, m_ptP4) ; + // se non c'è testo, linea di misura intera + if ( IsEmptyOrSpaces( m_sOutText)) { + lstPL.emplace_back() ; + lstPL.back().AddUPoint( 0, m_ptP5) ; + lstPL.back().AddUPoint( 1, m_ptP6) ; + } + // altrimenti, linea di misura divisa in due parti + else { + // semi distanza di interruzione + double dHalfDist = m_dTextHeight / 2 + m_dTextDist ; + // recupero il box di ingombro del testo + BBox3d b3Text ; + if ( GetTextLocalBBox( b3Text)) { + double dHalfL = ( b3Text.GetMax().x - b3Text.GetMin().x) / 2 ; + double dHalfH = ( b3Text.GetMax().y - b3Text.GetMin().y) / 2 ; + dHalfDist = sqrt( dHalfL * dHalfL + dHalfH * dHalfH) ; + if ( abs( m_vtDir.x) > EPS_ZERO) + dHalfDist = min( dHalfDist, dHalfL / abs( m_vtDir.x)) ; + if ( abs( m_vtDir.y) > EPS_ZERO) + dHalfDist = min( dHalfDist, dHalfH / abs( m_vtDir.y)) ; + dHalfDist += m_dTextDist ; + } + // prima parte + lstPL.emplace_back() ; + lstPL.back().AddUPoint( 0, m_ptP5) ; + lstPL.back().AddUPoint( 1, m_ptOutPos - m_vtDir * dHalfDist) ; + // seconda parte + lstPL.emplace_back() ; + lstPL.back().AddUPoint( 0, m_ptOutPos + m_vtDir * dHalfDist) ; + lstPL.back().AddUPoint( 1, m_ptP6) ; + } + // frecce + lstPL.emplace_back() ; + GetArrowHead( m_ptP5, -m_vtDir, lstPL.back()) ; + lstPL.emplace_back() ; + GetArrowHead( m_ptP6, m_vtDir, lstPL.back()) ; + // testo + POLYLINELIST lstTxt ; + if ( ApproxTextWithLines( dLinTol, dAngTolDeg, lstTxt)) + lstPL.splice( lstPL.end(), lstTxt) ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::GetArrowHead( const Point3d& ptTip, const Vector3d& vtDir, PolyLine& PL) const +{ + Vector3d vtPerp = vtDir ^ m_vtN ; + if ( ! vtPerp.Normalize()) + return false ; + const double A_WIDTH_COEFF = 0.1666 ; + PL.AddUPoint( 0, ptTip) ; + PL.AddUPoint( 1, ptTip - ( vtDir + vtPerp * A_WIDTH_COEFF) * m_dArrowLen) ; + PL.AddUPoint( 2, ptTip - ( vtDir - vtPerp * A_WIDTH_COEFF) * m_dArrowLen) ; + PL.AddUPoint( 4, ptTip) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::ApproxTextWithLines( double dLinTol, double dAngTolDeg, POLYLINELIST& lstPL) const +{ + // eventuale ricalcolo + if ( m_bToCalc) + Update() ; + + // imposto il font corrente e i suoi dati + FontManager& fntMgr = FontManager::GetFontManager() ; + if ( ! fntMgr.SetCurrFont( m_sFont, FONT_WEIGHT, FONT_ITALIC, m_dTextHeight, FONT_RATIO, FONT_ADDADVANCE)) + return false ; + + // richiedo l'outline + if ( ! fntMgr.ApproxWithLines( m_sOutText, ETXT_IPMC, dLinTol, dAngTolDeg, lstPL)) + return false ; + + // calcolo la trasformazione + Frame3d frRef ; + if ( ! frRef.Set( m_ptOutPos, m_vtN)) + return false ; + + // eseguo la trasformazione + for ( auto& PL : lstPL) + PL.ToGlob( frRef) ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::GetTextMyBBox( const Point3d& ptPos, BBox3d& b3Loc) const +{ + // imposto box vuoto + b3Loc.Reset() ; + + // se testo vuoto, box vuoto + if ( IsEmptyOrSpaces( m_sOutText)) + return true ; + + // imposto il font corrente e i suoi dati + FontManager& fntMgr = FontManager::GetFontManager() ; + if ( ! fntMgr.SetCurrFont( m_sFont, FONT_WEIGHT, FONT_ITALIC, m_dTextHeight, FONT_RATIO, FONT_ADDADVANCE)) + return false ; + + // richiedo il box + if ( ! fntMgr.GetBBox( m_sOutText, ETXT_IPMC, b3Loc)) + return false ; + + // calcolo ed eseguo la trasformazione + Frame3d frRef ; + if ( ! frRef.Set( ptPos, m_vtN)) + return false ; + b3Loc.ToGlob( frRef) ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::GetTextLocalBBox( BBox3d& b3Loc) const +{ + // eventuale ricalcolo + if ( m_bToCalc) + Update() ; + + // calcolo il box + return GetTextMyBBox( m_ptOutPos, b3Loc) ; +} + +//---------------------------------------------------------------------------- +bool +ExtDimension::GetTextBBox( const Frame3d& frRef, BBox3d& b3Ref) const +{ + // eventuale ricalcolo + if ( m_bToCalc) + Update() ; + + // calcolo il box + if ( ! GetTextMyBBox( m_ptOutPos, b3Ref)) + return false ; + + // porto il box nel riferimento passato + b3Ref.ToGlob( frRef) ; + + return true ; +} diff --git a/ExtDimension.h b/ExtDimension.h new file mode 100644 index 0000000..ac1fb40 --- /dev/null +++ b/ExtDimension.h @@ -0,0 +1,112 @@ +//---------------------------------------------------------------------------- +// EgalTech 2019-2019 +//---------------------------------------------------------------------------- +// File : ExtDimension.h Data : 27.12.19 Versione : 2.2a1 +// Contenuto : Dichiarazione della classe Dimension (quota). +// +// +// +// Modifiche : 27.12.19 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "ObjGraphicsMgr.h" +#include "DllMain.h" +#include "GeoObjRW.h" +#include "/EgtDev/Include/EGkExtDimension.h" + +//---------------------------------------------------------------------------- +class ExtDimension : public IExtDimension, public IGeoObjRW +{ + public : // IGeoObj + ~ExtDimension( void) override ; + ExtDimension* Clone( void) const override ; + GeoObjType GetType( void) const override ; + bool IsValid( void) const override + { return true ; } + const std::string& GetTitle( void) const override ; + bool Dump( std::string& sOut, bool bMM = true, const char* szNewLine = "\n") const override ; + bool GetLocalBBox( BBox3d& b3Loc, int nFlag = BBF_STANDARD) const override ; + bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag = BBF_STANDARD) const override ; + bool Translate( const Vector3d& vtMove) override ; + bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) override + { double dAngRad = dAngDeg * DEGTORAD ; + return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; } + bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) override ; + bool Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) override ; + bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) override ; + bool Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff) override ; + bool ToGlob( const Frame3d& frRef) override ; + bool ToLoc( const Frame3d& frRef) override ; + bool LocToLoc( const Frame3d& frOri, const Frame3d& frDest) override ; + void SetObjGraphics( IObjGraphics* pOGr) override + { m_OGrMgr.SetObjGraphics( pOGr) ; } + IObjGraphics* GetObjGraphics( void) override + { return m_OGrMgr.GetObjGraphics() ; } + const IObjGraphics* GetObjGraphics( void) const override + { return m_OGrMgr.GetObjGraphics() ; } + void SetTempProp( int nProp) override + { m_nTempProp = nProp ; } + int GetTempProp( void) const override + { return m_nTempProp ; } + + public : // IExtDimension + bool CopyFrom( const IGeoObj* pGObjSrc) override ; + bool SetLinear( const Point3d& ptP1, const Point3d& ptP2, const Point3d& ptPos, + const Vector3d& vtN, const Vector3d& vtDir, const std::string& sText) override ; + const Vector3d& GetNormVersor( void) const override + { return m_vtN ; } + bool ApproxWithLines( double dLinTol, double dAngTolDeg, POLYLINELIST& lstPL) const override ; + + public : // IGeoObjRW + int GetNgeId( void) const override ; + bool Save( NgeWriter& ngeOut) const override ; + bool Load( NgeReader& ngeIn) override ; + + public : + ExtDimension( void) ; + ExtDimension( const ExtDimension& gpSrc) + { if ( ! CopyFrom( gpSrc)) + LOG_ERROR( GetEGkLogger(), "ExtDimension : copy constructor error") } + ExtDimension& operator =( const ExtDimension& gpSrc) + { if ( ! CopyFrom( gpSrc)) + LOG_ERROR( GetEGkLogger(), "ExtDimension : copy error") + return *this ; } + + private : + bool CopyFrom( const ExtDimension& gpSrc) ; + bool Update( void) const ; + bool GetArrowHead( const Point3d& ptTip, const Vector3d& vtDir, PolyLine& PL) const ; + bool ApproxTextWithLines( double dLinTol, double dAngTolDeg, POLYLINELIST& lstPL) const ; + bool GetTextMyBBox( const Point3d& ptPos, BBox3d& b3Loc) const ; + bool GetTextLocalBBox( BBox3d& b3Loc) const ; + bool GetTextBBox( const Frame3d& frRef, BBox3d& b3Ref) const ; + + private : + ObjGraphicsMgr m_OGrMgr ; // gestore grafica dell'oggetto + int m_nType ; // tipo di quota + Vector3d m_vtN ; // versore normale + Vector3d m_vtDir ; // versore direzione + Point3d m_ptP1 ; // primo punto + Point3d m_ptP2 ; // secondo punto + Point3d m_ptP3 ; // terzo punto + Point3d m_ptP4 ; // quarto punto + Point3d m_ptP5 ; // quinto punto + Point3d m_ptP6 ; // sesto punto + Point3d m_ptPos ; // posizione ricevuta della quota + std::string m_sText ; // testo della quota + mutable bool m_bToCalc ; // flag dati effettivi da ricalcolare + mutable Point3d m_ptOutPos ; // posizione effettiva della quota + mutable std::string m_sOutText ; // testo effettivo della quota + double m_dExtLineLen ; // lunghezza di estensione della linea + double m_dArrowLen ; // lunghezza delle frecce + double m_dTextDist ; // distanza della linea di quotatura dal testo + bool m_bLenIsMM ; // flag per mm/pollici se lunghezza + int m_nLenDec ; // numero di cifre decimali + std::string m_sFont ; // font del testo + double m_dTextHeight ; // altezza del testo + int m_nTempProp ; // proprietà temporanea +} ; diff --git a/ExtText.cpp b/ExtText.cpp index 40a3fc2..d0031a7 100644 --- a/ExtText.cpp +++ b/ExtText.cpp @@ -444,6 +444,10 @@ ExtText::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCo bool ExtText::Mirror( const Point3d& ptOn, const Vector3d& vtNorm) { + // verifico validità del piano di specchiatura + if ( vtNorm.IsSmall()) + return false ; + // imposto ricalcolo della grafica m_OGrMgr.Reset() ; diff --git a/FontManager.h b/FontManager.h index 2965e2b..5eb50cd 100644 --- a/FontManager.h +++ b/FontManager.h @@ -54,6 +54,6 @@ class FontManager private : FontManager( void) {} - FontManager( FontManager const& copy) ; // Not Implemented - FontManager& operator=( FontManager const& copy) ; // Not Implemented + FontManager( FontManager const& copy) = delete ; + FontManager& operator=( FontManager const& copy) = delete ; } ; diff --git a/GdbIterator.cpp b/GdbIterator.cpp index 07b7e9d..ca1a397 100644 --- a/GdbIterator.cpp +++ b/GdbIterator.cpp @@ -960,6 +960,9 @@ GdbIterator::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double if ( m_pGDB == nullptr || m_pCurrObj == nullptr || m_pCurrObj->m_nId == GDB_ID_ROOT) return false ; + // non sono ammessi coefficienti negativi + if ( dCoeffX < 0 || dCoeffY < 0 || dCoeffZ < 0) + return false ; // eseguo la scalatura return m_pCurrObj->Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) ; } @@ -971,6 +974,9 @@ GdbIterator::ScaleGlob( const Frame3d& frRef, double dCoeffX, double dCoeffY, do if ( m_pGDB == nullptr || m_pCurrObj == nullptr || m_pCurrObj->m_nId == GDB_ID_ROOT) return false ; + // non sono ammessi coefficienti negativi + if ( dCoeffX < 0 || dCoeffY < 0 || dCoeffZ < 0) + return false ; // recupero il riferimento in cui è immerso l'oggetto Frame3d frObj ; if ( ! GetGlobFrame( frObj)) @@ -990,6 +996,9 @@ GdbIterator::ScaleGroup( const Frame3d& frRef, double dCoeffX, double dCoeffY, d if ( m_pGDB == nullptr || m_pCurrObj == nullptr || m_pCurrObj->m_nId == GDB_ID_ROOT) return false ; + // non sono ammessi coefficienti negativi + if ( dCoeffX < 0 || dCoeffY < 0 || dCoeffZ < 0) + return false ; // deve essere un gruppo di cui utilizzo il riferimento proprio GdbGroup* pGdbGroup = GetGdbGroup( m_pCurrObj) ; if ( pGdbGroup == nullptr) diff --git a/GeoFrame3d.cpp b/GeoFrame3d.cpp index 363074b..58a3373 100644 --- a/GeoFrame3d.cpp +++ b/GeoFrame3d.cpp @@ -199,7 +199,7 @@ bool GeoFrame3d::GetDrawWithArrowHeads( double dLenA, double dFrazLenAH, PolyLine& plX, PolyLine& plY, PolyLine& plZ) const { - const double A_WIDTH_COEFF = 0.3 ; + const double A_WIDTH_COEFF = 0.258819 ; double dLenAH = dFrazLenAH * dLenA ; // vettore X (con freccia) plX.AddUPoint( 0, m_frF.Orig()) ; diff --git a/GeoVector3d.cpp b/GeoVector3d.cpp index c4f812d..c6b2fab 100644 --- a/GeoVector3d.cpp +++ b/GeoVector3d.cpp @@ -230,7 +230,7 @@ GeoVector3d::GetDrawWithArrowHead( double dFrazLenAH, double dMaxDimA, PolyLine& Point3d ptTip = m_ptBase + m_vtV ; PL.AddUPoint( 1, ptTip) ; // doppia freccia - const double A_WIDTH_COEFF = 0.3 ; + const double A_WIDTH_COEFF = 0.258819 ; double dLenAH = min( dMaxDimA, dFrazLenAH * m_vtV.Len()) ; Frame3d frF ; frF.Set( ptTip, m_vtV) ; diff --git a/GeomDB.cpp b/GeomDB.cpp index bd83b27..3969ee2 100644 --- a/GeomDB.cpp +++ b/GeomDB.cpp @@ -1502,6 +1502,9 @@ GeomDB::Scale( int nId, const Frame3d& frRef, double dCoeffX, double dCoeffY, do // non si può modificare il gruppo radice (escludo anche Id non validi) if ( nId <= GDB_ID_ROOT) return false ; + // non sono ammessi coefficienti negativi + if ( dCoeffX < 0 || dCoeffY < 0 || dCoeffZ < 0) + return false ; // recupero l'oggetto GdbObj* pGdbObj = GetGdbObj( nId) ; if ( pGdbObj == nullptr) @@ -1517,6 +1520,9 @@ GeomDB::ScaleGlob( int nId, const Frame3d& frRef, double dCoeffX, double dCoeffY // non si può modificare il gruppo radice (escludo anche Id non validi) if ( nId <= GDB_ID_ROOT) return false ; + // non sono ammessi coefficienti negativi + if ( dCoeffX < 0 || dCoeffY < 0 || dCoeffZ < 0) + return false ; // recupero l'oggetto GdbObj* pGdbObj = GetGdbObj( nId) ; if ( pGdbObj == nullptr) @@ -1542,6 +1548,9 @@ GeomDB::ScaleGroup( int nId, const Frame3d& frRef, double dCoeffX, double dCoeff // non si può modificare il gruppo radice (escludo anche Id non validi) if ( nId <= GDB_ID_ROOT) return false ; + // non sono ammessi coefficienti negativi + if ( dCoeffX < 0 || dCoeffY < 0 || dCoeffZ < 0) + return false ; // recupero il gruppo Gdb GdbGroup* pGdbGroup ; if ( ( pGdbGroup = GetGdbGroup( nId)) == nullptr) diff --git a/NgeConst.h b/NgeConst.h index 70f3d4c..8d65494 100644 --- a/NgeConst.h +++ b/NgeConst.h @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- -// EgalTech 2014-2018 +// EgalTech 2014-2019 //---------------------------------------------------------------------------- -// File : NgeConst.h Data : 18.09.18 Versione : 1.9i3 +// File : NgeConst.h Data : 27.12.19 Versione : 2.2a1 // Contenuto : Costanti per file Nge. // // @@ -14,7 +14,8 @@ // 22.05.15 DS 1011 -> Aggiunta possibilità estensione oggetti con IUserObj. // 05.08.15 DS 1012 -> Aggiunta FlatRegion. // 04.10.15 DS 1013 -> Aggiunto TextureData. -// 18.09.18 DS 1014 -> Aggiunto falg Shape a Zmap. +// 18.09.18 DS 1014 -> Aggiunto flag Shape a Zmap. +// 27.12.19 DS 1015 -> Aggiunto DIMENSION. // //---------------------------------------------------------------------------- @@ -28,23 +29,16 @@ // Nome GDB const std::string NGE_GEOMDB = "EgtGeomDB" ; // Versione -const int NGE_VER_1007 = 1007 ; -// 1007 : nuovo versioning con unico valore -const int NGE_VER_1008 = 1008 ; -// 1008 : aggiunge vtExtr e dThick a tutte le curve -const int NGE_VER_1009 = 1009 ; -// 1009 : aggiunto solido ZMAP e cambiato Id di TEXT -const int NGE_VER_1010 = 1010 ; -// 1010 : aggiunto flag orientata e elenco facce a SurfTm -const int NGE_VER_1011 = 1011 ; -// 1011 : aggiunta possibilità estensione oggetti con IUserObj (Keyword U) -const int NGE_VER_1012 = 1012 ; -// 1012 : aggiunta superficie FlatRegion -const int NGE_VER_1013 = 1013 ; -// 1013 : aggiunto TextureData (Keyword T) -const int NGE_VER_1014 = 1014 ; -// 1014 : aggiunto Shape a Zmap -const int NGE_VER_LAST = NGE_VER_1014 ; +const int NGE_VER_1007 = 1007 ; // nuovo versioning con unico valore +const int NGE_VER_1008 = 1008 ; // aggiunge vtExtr e dThick a tutte le curve +const int NGE_VER_1009 = 1009 ; // aggiunto solido ZMAP e cambiato Id di TEXT +const int NGE_VER_1010 = 1010 ; // aggiunto flag orientata e elenco facce a SurfTm +const int NGE_VER_1011 = 1011 ; // aggiunta possibilità estensione oggetti con IUserObj (Keyword U) +const int NGE_VER_1012 = 1012 ; // aggiunta superficie FlatRegion +const int NGE_VER_1013 = 1013 ; // aggiunto TextureData (Keyword T) +const int NGE_VER_1014 = 1014 ; // aggiunto Shape a Zmap +const int NGE_VER_1015 = 1015 ; // aggiunto Dimension +const int NGE_VER_LAST = NGE_VER_1015 ; // Indici KeyWord const int NGE_START = 0 ; const int NGE_END = 1 ; @@ -68,4 +62,5 @@ const int NGE_S_TRM = 18 ; const int NGE_S_FRG = 19 ; const int NGE_V_ZMP = 20 ; const int NGE_E_TXT = 21 ; -const int NGE_LAST_ID = 21 ; // ultimo valore +const int NGE_E_DIM = 22 ; +const int NGE_LAST_ID = 22 ; // ultimo valore diff --git a/NgeKeyW.h b/NgeKeyW.h index d7e4efe..6b2d999 100644 --- a/NgeKeyW.h +++ b/NgeKeyW.h @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- -// EgalTech 2014-2014 +// EgalTech 2014-2019 //---------------------------------------------------------------------------- -// File : NgeKeyW.h Data : 28.05.14 Versione : 1.5e10 +// File : NgeKeyW.h Data : 27.12.19 Versione : 2.2a1 // Contenuto : Parole chiave per file Nge. // // @@ -41,7 +41,8 @@ const std::string NgeAscKeyW[] = { "START", // NGE_START "S_TRM", // NGE_S_TRM "S_FRG", // NGE_S_FRG "V_ZMP", // NGE_V_ZMP - "E_TXT"} ; // NGE_E_TXT + "E_TXT", // NGE_E_TXT + "E_DIM"} ; // NGE_E_DIM //---------------------------------------------------------------------------- // KeyWord per file NGE BINARY @@ -72,4 +73,5 @@ const int NgeBinKeyW[] = { NGEB_GEN_BASE + 0x0F0F, // NGE_START NGEB_GEO_BASE + SRF_TRIMESH, // NGE_S_TRM NGEB_GEO_BASE + SRF_FLATRGN, // NGE_S_FRG NGEB_GEO_BASE + VOL_ZMAP, // NGE_V_ZMP - NGEB_GEO_BASE + EXT_TEXT} ; // NGE_E_TXT \ No newline at end of file + NGEB_GEO_BASE + EXT_TEXT, // NGE_E_TXT + NGEB_GEO_BASE + EXT_DIMENSION} ; // NGE_E_DIM