From 66e64e26c4e0464021d788db18269f63a54f9f57 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Thu, 21 Nov 2013 13:31:49 +0000 Subject: [PATCH] Include : modifiche per interfacce. --- EGkGeoObj.h | 51 +++++++++ EGkGeoObjType.h | 39 +++++++ EGkGeoPoint3d.h | 34 ++++++ EGnScan.h | 41 ++++++++ EGnStringConverter.h | 244 +++++++++++++++++++++++++++++++++++++++++++ EGnStringUtils.h | 124 ++++++++++++++++++++++ EgtLibVer.h | 25 +++++ EgtTargetVer.h | 20 ++++ 8 files changed, 578 insertions(+) create mode 100644 EGkGeoObj.h create mode 100644 EGkGeoObjType.h create mode 100644 EGkGeoPoint3d.h create mode 100644 EGnScan.h create mode 100644 EGnStringConverter.h create mode 100644 EGnStringUtils.h create mode 100644 EgtLibVer.h create mode 100644 EgtTargetVer.h diff --git a/EGkGeoObj.h b/EGkGeoObj.h new file mode 100644 index 0000000..be5983b --- /dev/null +++ b/EGkGeoObj.h @@ -0,0 +1,51 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : EGkGeoObj.h Data : 20.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione della interfaccia IGeoObj. +// +// +// +// Modifiche : 20.11.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include +#include "/EgtDev/Include/EGkPoint3d.h" +#include "/EgtDev/Include/EGkFrame3d.h" +#include "/EgtDev/Include/EGkGeoObjType.h" +#include "/EgtDev/Include/EGnScan.h" + +//----------------------- Macro per import/export ---------------------------- +#undef EGK_EXPORT +#ifdef I_AM_EGK // da definirsi solo nei moduli della DLL + #define EGK_EXPORT __declspec( dllexport) +#else + #define EGK_EXPORT __declspec( dllimport) +#endif + +//----------------------------------------------------------------------------- +class _declspec( novtable) IGeoObj +{ + public : + virtual ~IGeoObj( void) {} + virtual IGeoObj* Clone( void) const = 0 ; + virtual GeoObjType GetType( void) const = 0 ; + virtual std::string GetKey( void) const = 0 ; + virtual bool IsValid( void) const = 0 ; + virtual bool Save( std::ostream& osOut) const = 0 ; + virtual bool Load( CScan& TheScanner) = 0 ; + virtual bool Translate( const Vector3d& vtMove) = 0 ; + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) = 0 ; + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngRad) = 0 ; + virtual bool Scale( const Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) = 0 ; + virtual bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) = 0 ; + virtual bool ToGlob( const Frame3d& frRef) = 0 ; + virtual bool ToLoc( const Frame3d& frRef) = 0 ; +} ; + +//----------------------------------------------------------------------------- +EGK_EXPORT IGeoObj* CreateGeoObj( std::string sKey) ; \ No newline at end of file diff --git a/EGkGeoObjType.h b/EGkGeoObjType.h new file mode 100644 index 0000000..b1c7da9 --- /dev/null +++ b/EGkGeoObjType.h @@ -0,0 +1,39 @@ +//---------------------------------------------------------------------------- +// EgalS +//---------------------------------------------------------------------------- +// File : GeoObjType.h Data : 30.04.13 Versione : 1.1d3 +// Contenuto : Definizione Tipo degli Oggetti Geometrici. +// +// +// +// Modifiche : 30.04.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + + +//----------------- Costanti famiglie oggetto geometrico ---------------------- +#define GEO_ZERODIM 0x100 +#define GEO_CURVE 0x200 +#define GEO_SURF 0x400 + +//----------------- Costanti tipo oggetto geometrico -------------------------- +enum GeoObjType { GEO_NONE = 0, + GEO_VECT3D = ( GEO_ZERODIM + 0), + GEO_PNT3D = ( GEO_ZERODIM + 1), + CRV_LINE = ( GEO_CURVE + 0), + CRV_ARC = ( GEO_CURVE + 1), + CRV_BEZ = ( GEO_CURVE + 2), + CRV_COMPO = ( GEO_CURVE + 3), + SRF_TRIMESH = ( GEO_SURF + 0)} ; + +//----------------- Costanti chiavi oggetto geometrico ------------------------ +#define KEY_GEO_VECT3D "G_VEC" +#define KEY_GEO_PNT3D "G_PNT" +#define KEY_CRV_LINE "C_LIN" +#define KEY_CRV_ARC "C_ARC" +#define KEY_CRV_BEZ "C_BEZ" +#define KEY_CRV_COMPO "C_CMP" +#define KEY_SRF_TRIMESH "S_TRM" diff --git a/EGkGeoPoint3d.h b/EGkGeoPoint3d.h new file mode 100644 index 0000000..d969eb6 --- /dev/null +++ b/EGkGeoPoint3d.h @@ -0,0 +1,34 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : EGkGeoPoint3d.h Data : 21.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione della interfaccia IGeoPoint3d. +// +// +// +// Modifiche : 21.11.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkGeoObj.h" + +//----------------------------------------------------------------------------- +class _declspec( novtable) IGeoPoint3d : public IGeoObj +{ + public : + virtual bool Set( const Point3d& ptP) = 0 ; + virtual const Point3d* GetPoint( void) const = 0 ; +} ; + +//----------------------------------------------------------------------------- +inline const IGeoPoint3d* GetGeoPoint3d( const IGeoObj* pGObj) + { if ( pGObj == nullptr || pGObj->GetType() != GEO_PNT3D) + return nullptr ; + return (static_cast(pGObj)) ; } +inline IGeoPoint3d* GetGeoPoint3d( IGeoObj* pGObj) + { if ( pGObj == nullptr || pGObj->GetType() != GEO_PNT3D) + return nullptr ; + return (static_cast(pGObj)) ; } diff --git a/EGnScan.h b/EGnScan.h new file mode 100644 index 0000000..daafe01 --- /dev/null +++ b/EGnScan.h @@ -0,0 +1,41 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : EgnScan.h Data : 20.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione della classe CScan. +// +// +// +// Modifiche : 20.11.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include +#include + +//----------------------- Macro per import/export ----------------------------- +#undef EGN_EXPORT +#ifdef I_AM_EGN // da definirsi solo nei moduli della DLL + #define EGN_EXPORT __declspec( dllexport) +#else + #define EGN_EXPORT __declspec( dllimport) +#endif + +//---------------------------------------------------------------------------- +class EGN_EXPORT CScan +{ + public : + CScan( void) ; + ~CScan( void) ; + bool Initialize( std::ifstream& InFile) ; + bool Terminate( void) ; + bool GetLine( std::string& sLine) ; + int GetCurrLineNbr( void) { return m_nLineNbr ; } + + private : + std::ifstream* m_pInFile ; + int m_nLineNbr ; +} ; diff --git a/EGnStringConverter.h b/EGnStringConverter.h new file mode 100644 index 0000000..47dfcdd --- /dev/null +++ b/EGnStringConverter.h @@ -0,0 +1,244 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : EgnStringConverter.h Data : 10.02.13 Versione : 1.3a1 +// Contenuto : Insieme di classi per convertire stringhe tra vari formati. +// +// +// +// Modifiche : 10.02.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +#include + +//----------------------------------------------------------------------------- +template +inline void SmartAllocMemory( _CharType** ppBuff, int nLength, _CharType* pszFixedBuffer, int nFixedBufferLength) +{ + // controlli + if ( ppBuff == nullptr) + return ; + if ( nLength < 0 || pszFixedBuffer == nullptr) { + *ppBuff = nullptr ; + return ; + } + + // se buffer già allocato, lo rialloco + if ( *ppBuff != pszFixedBuffer) { + if ( nLength > nFixedBufferLength) { + *ppBuff = static_cast<_CharType*>( _recalloc( *ppBuff, nLength,sizeof( _CharType))) ; + } + else { + free( *ppBuff) ; + *ppBuff = pszFixedBuffer ; + } + } + // altrimenti buffer non già allocato + else { + if ( nLength > nFixedBufferLength) { + *ppBuff = static_cast<_CharType*>( calloc( nLength, sizeof( _CharType))) ; + } + else { + *ppBuff = pszFixedBuffer ; + } + } +} + +//----------------------------------------------------------------------------- +template +inline void SmartFreeMemory( _CharType* pBuff, _CharType* pszFixedBuffer, int nFixedBufferLength) +{ + if ( pBuff != pszFixedBuffer) + free( pBuff) ; +#ifdef _DEBUG + else + memset( pszFixedBuffer, 0xFE, nFixedBufferLength * sizeof(_CharType)) ; +#endif +} + +//----------------------------------------------------------------------------- +inline bool IsTextUtf8( const char* psz) +{ + const unsigned char* p ; + + + // validità parametro + if ( psz == nullptr) + return false ; + + // ciclo sulla stringa + p = ( const unsigned char*) psz ; + while ( *p != '\0') { + // caratteri ASCII + if ( 0x00 <= p[0] && p[0] <= 0x7F) + p += 1 ; + // 2 byte + else if ( (0xC2 <= p[0] && p[0] <= 0xDF) && + (0x80 <= p[1] && p[1] <= 0xBF) ) + p += 2 ; + // 3byte + else if ( ( // escludo extralunghi + p[0] == 0xE0 && + ( 0xA0 <= p[1] && p[1] <= 0xBF) && + ( 0x80 <= p[2] && p[2] <= 0xBF) ) || + ( // normali + (( 0xE1 <= p[0] && p[0] <= 0xEC) || p[0] == 0xEE || p[0] == 0xEF) && + ( 0x80 <= p[1] && p[1] <= 0xBF) && + ( 0x80 <= p[2] && p[2] <= 0xBF) ) || + ( // escludo surrogati + p[0] == 0xED && + ( 0x80 <= p[1] && p[1] <= 0x9F) && + ( 0x80 <= p[2] && p[2] <= 0xBF) ) ) + p += 3 ; + // 4byte + else if ( ( // piani 1-3 + p[0] == 0xF0 && + ( 0x90 <= p[1] && p[1] <= 0xBF) && + ( 0x80 <= p[2] && p[2] <= 0xBF) && + ( 0x80 <= p[3] && p[3] <= 0xBF) ) || + ( // piani 4-15 + ( 0xF1 <= p[0] && p[0] <= 0xF3) && + ( 0x80 <= p[1] && p[1] <= 0xBF) && + ( 0x80 <= p[2] && p[2] <= 0xBF) && + ( 0x80 <= p[3] && p[3] <= 0xBF) ) || + ( // piano 16 + p[0] == 0xF4 && + ( 0x80 <= p[1] && p[1] <= 0x8F) && + ( 0x80 <= p[2] && p[2] <= 0xBF) && + ( 0x80 <= p[3] && p[3] <= 0xBF) ) ) + p += 4 ; + // non validi + else + return false ; + } + + return true ; +} + +//----------------------------------------------------------------------------- +template< int t_nBufferLength = 128 > +class CAtoWEX +{ + public : + CAtoWEX( const char* psz) : + m_psz( m_szBuffer) + { + if ( IsTextUtf8( psz)) + Init( psz, CP_UTF8) ; + else + Init( psz, CP_ACP) ; + } + CAtoWEX( const char* psz, unsigned int nCodePage) : + m_psz( m_szBuffer) + { + Init( psz, nCodePage) ; + } + + ~CAtoWEX( void) + { + SmartFreeMemory( m_psz, m_szBuffer, t_nBufferLength) ; + } + + operator LPWSTR( void) + { + return ( m_psz) ; + } + + private : + void Init( const char* psz, unsigned int nCodePage) + { + if ( psz == nullptr) { + m_psz = nullptr ; + return ; + } + int nLengthA = lstrlenA( psz) + 1 ; + int nLengthW = nLengthA ; + + SmartAllocMemory( &m_psz, nLengthW, m_szBuffer, t_nBufferLength) ; + + BOOL bFailed = ( MultiByteToWideChar( nCodePage, 0, psz, nLengthA, m_psz, nLengthW) == 0) ; + if ( bFailed) { + if ( GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + nLengthW = ::MultiByteToWideChar( nCodePage, 0, psz, nLengthA, nullptr, 0) ; + SmartAllocMemory( &m_psz, nLengthW, m_szBuffer, t_nBufferLength) ; + bFailed =( MultiByteToWideChar( nCodePage, 0, psz, nLengthA, m_psz, nLengthW) == 0) ; + } + } + if ( bFailed) + m_psz = nullptr ; + } + + public : + wchar_t* m_psz ; + wchar_t m_szBuffer[t_nBufferLength] ; +} ; + +typedef CAtoWEX<> CAtoW ; +#define stringtoW(s) LPWSTR( CAtoW( s.c_str())) + +//----------------------------------------------------------------------------- +template < int t_nBufferLength = 128 > +class CWtoAEX +{ + public : + CWtoAEX( const wchar_t* psz) : + m_psz( m_szBuffer) + { + Init( psz, CP_UTF8) ; + } + + CWtoAEX( const wchar_t* psz, unsigned int nCodePage) : + m_psz( m_szBuffer) + { + Init( psz, nCodePage) ; + } + + ~CWtoAEX( void) + { + SmartFreeMemory( m_psz, m_szBuffer, t_nBufferLength) ; + } + + operator LPSTR( void) + { + return ( m_psz) ; + } + + int GetLength( void) + { + return strlen( m_psz) ; + } + + private : + void Init( const wchar_t* psz, unsigned int nCodePage) + { + if ( psz == nullptr) { + m_psz = nullptr ; + return ; + } + int nLengthW = lstrlenW( psz) + 1 ; + int nLengthA = max( 2 * nLengthW, t_nBufferLength) ; + + SmartAllocMemory( &m_psz, nLengthA, m_szBuffer, t_nBufferLength) ; + + BOOL bFailed = ( WideCharToMultiByte( nCodePage, 0, psz, nLengthW, m_psz, nLengthA, nullptr, nullptr) == 0) ; + if ( bFailed) { + if ( GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + nLengthA = ::WideCharToMultiByte( nCodePage, 0, psz, nLengthW, nullptr, 0, nullptr, nullptr) ; + SmartAllocMemory( &m_psz, nLengthA, m_szBuffer, t_nBufferLength) ; + bFailed = ( WideCharToMultiByte( nCodePage, 0, psz, nLengthW, m_psz, nLengthA, nullptr, nullptr) == 0) ; + } + } + if ( bFailed) + m_psz = nullptr ; + } + + public : + char* m_psz ; + char m_szBuffer[t_nBufferLength] ; +} ; + +typedef CWtoAEX<> CWtoA ; +#define wstringtoA(ws) LPSTR( CWtoA( ws.c_str())) diff --git a/EGnStringUtils.h b/EGnStringUtils.h new file mode 100644 index 0000000..b23eab6 --- /dev/null +++ b/EGnStringUtils.h @@ -0,0 +1,124 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : EgnStringUtils.h Data : 20.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione delle funzioni di utilità per le stringhe. +// +// +// +// Modifiche : 20.11.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include +#include +#include +#include "/EgtDEv/Include/EGkPoint3d.h" + +//----------------------- Macro per import/export ----------------------------- +#undef EGN_EXPORT +#ifdef I_AM_EGN // da definirsi solo nei moduli della DLL + #define EGN_EXPORT __declspec( dllexport) +#else + #define EGN_EXPORT __declspec( dllimport) +#endif + +//---------------------------------------------------------------------------- +typedef std::vector STRVECTOR ; + +//---------------------------------------------------------------------------- +inline std::string& +TrimLeft( std::string& sString, const char* szTarget = " \t\r\n") + { size_t iStartPos = sString.find_first_not_of( szTarget) ; + if ( iStartPos != std::string::npos) + sString.erase( 0, iStartPos) ; + else + sString.clear() ; + return sString ; } +inline std::string& +TrimRight( std::string& sString, const char* szTarget = " \t\r\n") + { size_t iEndPos = sString.find_last_not_of( szTarget) ; + if ( iEndPos != std::string::npos) + sString.erase( iEndPos + 1) ; + else + sString.clear() ; + return sString ; } +inline std::string& +Trim( std::string& sString, const char* szTarget = " \t\r\n") + { return TrimLeft( TrimRight( sString, szTarget), szTarget) ; } +inline std::string& +TrimUtf8Bom( std::string& sString) + { if ( sString[0] == '\xef' && sString[1] == '\xbb' && sString[2] == '\xbf') + sString.erase( 0, 3) ; + return sString ; } + +//---------------------------------------------------------------------------- +inline std::string& +ToUpper( std::string& sString) + { std::transform( sString.begin(), sString.end(), sString.begin(), ::toupper) ; + return sString ; } +inline std::string& +ToLower( std::string& sString) + { std::transform( sString.begin(), sString.end(), sString.begin(), ::tolower) ; + return sString ; } + +//---------------------------------------------------------------------------- +inline bool +FromString( const std::string& sVal, int& nVal) + { const char* pStart ; + char* pStop ; + pStart = sVal.c_str() ; + nVal = strtol( pStart, &pStop, 10) ; + return ( pStop != pStart && *pStop == '\0' && errno == 0) ; } +inline bool +FromString( const std::string& sVal, bool& bVal) + { int nTmp ; + if ( ! FromString( sVal, nTmp)) + return false ; + bVal = ( nTmp != 0) ; + return true ; } +inline bool +FromString( const std::string& sVal, double& dVal) + { const char* pStart ; + char* pStop ; + pStart = sVal.c_str() ; + dVal = strtod( pStart, &pStop) ; + return ( pStop != pStart && *pStop == '\0' && errno == 0) ; } +const std::string EGN_EXPORT ToString( int nVal, int nPrec = 1) ; +inline const std::string +ToString( bool bVal) + { return std::string( ( bVal ? "1" : "0")) ; } +EGN_EXPORT const std::string ToString( double dVal, int nPrec = 6) ; +inline const std::string +ToString( Vector3d vtVal, int nPrec = 9) + { std::string sBuff ; + sBuff.reserve( 3 * 32 + 2) ; + sBuff = ToString( vtVal.x, nPrec) + ',' + ToString( vtVal.y, nPrec) + ',' + ToString( vtVal.z, nPrec) ; + return sBuff ; } +inline const std::string +ToString( Point3d ptVal, int nPrec = 6) + { std::string sBuff ; + sBuff.reserve( 3 * 32 + 2) ; + sBuff = ToString( ptVal.x, nPrec) + ',' + ToString( ptVal.y, nPrec) + ',' + ToString( ptVal.z, nPrec) ; + return sBuff ; } + +//---------------------------------------------------------------------------- +EGN_EXPORT void Split( const std::string& sString, const std::string& sSeparator, bool bFirstVsLast, + std::string& sFirst, std::string& sLast) ; +inline void +SplitFirst( const std::string& sString, const std::string& sSeparator, std::string& sFirst, std::string& sLast) + { Split( sString, sSeparator, true, sFirst, sLast) ; } +inline void +SplitLast( const std::string& sString, const std::string& sSeparator, std::string& sFirst, std::string& sLast) + { Split( sString, sSeparator, false, sFirst, sLast) ; } + +//---------------------------------------------------------------------------- +EGN_EXPORT bool Tokenize( const std::string& sString, const std::string& sSeparators, STRVECTOR& vsTokens) ; +EGN_EXPORT bool Tokenize( const std::string& sString, const std::string& sSeparators, + const std::string& sAtomStarts, const std::string& sAtomEnds, STRVECTOR& vsTokens) ; + +//---------------------------------------------------------------------------- +EGN_EXPORT int ReplaceString( std::string& sString, const std::string& sOld, const std::string& sNew) ; diff --git a/EgtLibVer.h b/EgtLibVer.h new file mode 100644 index 0000000..c3ff954 --- /dev/null +++ b/EgtLibVer.h @@ -0,0 +1,25 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : EgtLibVer.h Data : 20.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione macro per versioni librerie Egt*. +// +// +// +// Modifiche : 20.11.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +// Direttorio librerie +#define EGTLIBDIR "/EgtDev/Lib/" + +// Dichiarazione suffisso librerie +#if _DEBUG + #define EGTLIBVER "D32" +#else + #define EGTLIBVER "R32" +#endif + diff --git a/EgtTargetVer.h b/EgtTargetVer.h new file mode 100644 index 0000000..4f6d30a --- /dev/null +++ b/EgtTargetVer.h @@ -0,0 +1,20 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : EgtTargetVer.h Data : 20.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione macro per versione Windows target. +// +// +// +// Modifiche : 20.11.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + + +#define WINVER 0x0601 +#define _WIN32_WINNT 0x0601 +#define _WIN32_IE 0x0800 +