diff --git a/EgtExchange.rc b/EgtExchange.rc
index 74866d3..fe3b3ab 100644
Binary files a/EgtExchange.rc and b/EgtExchange.rc differ
diff --git a/EgtExchange.vcxproj b/EgtExchange.vcxproj
index 1de1a76..d63988e 100644
--- a/EgtExchange.vcxproj
+++ b/EgtExchange.vcxproj
@@ -212,6 +212,7 @@ copy $(TargetPath) \EgtProg\Dll64
+
diff --git a/EgtExchange.vcxproj.filters b/EgtExchange.vcxproj.filters
index 57137e1..f3def4d 100644
--- a/EgtExchange.vcxproj.filters
+++ b/EgtExchange.vcxproj.filters
@@ -74,6 +74,9 @@
File di origine
+
+ File di origine
+
diff --git a/ImportDxf.cpp b/ImportDxf.cpp
index 70063f7..d8620ec 100644
--- a/ImportDxf.cpp
+++ b/ImportDxf.cpp
@@ -39,6 +39,7 @@ ImportDxf::ImportDxf( void)
m_nCurrCode = CODE_NULL ;
m_nIdBlocksParent = GDB_ID_NULL ;
m_nIdCurrBlock = GDB_ID_NULL ;
+ m_nCodePage = 1252 ;
}
//----------------------------------------------------------------------------
@@ -80,6 +81,9 @@ ImportDxf::Import( const string& sFile, IGeomDB* pGDB, int nIdGroup, double dSca
if ( ! CreateBlocksParent())
return false ;
+ // imposto la codepage di default ( 1252 = ANSI Latin 1)
+ m_nCodePage = 1252 ;
+
// ciclo di lettura
bool bOk = true ;
bool bFileEnd = false ;
@@ -88,8 +92,13 @@ ImportDxf::Import( const string& sFile, IGeomDB* pGDB, int nIdGroup, double dSca
// leggo intestazione sezione, per avere il tipo
bool bOkLoc = GetSectionName( sSectName, bFileEnd) ;
if ( bOkLoc && ! bFileEnd) {
+ // se sezione header
+ if ( sSectName == "HEADER") {
+ if ( ! ReadHeader( bFileEnd))
+ bOkLoc = false ;
+ }
// se sezione tavole
- if ( sSectName == "TABLES") {
+ else if ( sSectName == "TABLES") {
if ( ! ReadTables( bFileEnd))
bOkLoc = false ;
}
diff --git a/ImportDxf.h b/ImportDxf.h
index db83472..4fc3b16 100644
--- a/ImportDxf.h
+++ b/ImportDxf.h
@@ -51,6 +51,7 @@ class ImportDxf : public IImportDxf
bool EraseEmptyLayers( void) ;
int GetGroupId( const std::string& sName) ;
bool BlockReading( void) ;
+ bool ReadHeader( bool& bFileEnd) ;
bool ReadTables( bool& bFileEnd) ;
bool GetTableName( std::string& sTabName, bool& bSectEnd, bool& bFileEnd) ;
bool SkipTable( bool& bFileEnd) ;
@@ -122,6 +123,7 @@ class ImportDxf : public IImportDxf
bool m_bUnGet ;
int m_nCurrCode ;
std::string m_sCurrItem ;
+ int m_nCodePage ;
NameMap m_nmLayer ;
StyleMap m_smStyle ;
int m_nIdBlocksParent ;
diff --git a/ImportDxfEnts.cpp b/ImportDxfEnts.cpp
index d5f652a..2b9b8d8 100644
--- a/ImportDxfEnts.cpp
+++ b/ImportDxfEnts.cpp
@@ -27,7 +27,7 @@
#include "/EgtDev/Include/EgkSurfTriMesh.h"
#include "/EgtDev/Include/EgkExtText.h"
#include "/EgtDev/Include/EGkGdbIterator.h"
-#include "/EgtDev/Include/EGnStringConverter.h"
+#include "/EgtDev/Include/EGnStringEncoder.h"
#include
using namespace std ;
@@ -2131,10 +2131,25 @@ ImportDxf::ReadText( bool& bFileEnd)
bool
ImportDxf::AdjustText( string& sText)
{
- // per gradi, più o meno e diametro con codici Unicode
- ReplaceString( sText, "\\U+00B0", LPSTR( WtoA( L"°"))) ;
- ReplaceString( sText, "\\U+00B1", LPSTR( WtoA( L"±"))) ;
- ReplaceString( sText, "\\U+2205", LPSTR( WtoA( L"Ø"))) ;
+ // se non è testo UTF-8, tento di convertirlo secondo codepage dichiarata nel DXF
+ if ( ! IsTextUtf8( sText.c_str())) {
+ sText = LPSTR( WtoA( LPWSTR( AtoW( sText.c_str(), m_nCodePage)))) ;
+ }
+
+ // converto la codifica Unicode di AutoCad ( "\\U+NNNN")
+ size_t nPos ;
+ while ( ( nPos = sText.find( "\\U+")) != string::npos) {
+ string sCode = (( sText.size() > nPos + 3) ? sText.substr( nPos+3, 4) : "") ;
+ unsigned int nCode = 127 ;
+ sscanf_s( sCode.c_str(), "%x", &nCode) ;
+ // converto diametro in O maiuscolo barrato
+ if ( nCode == 8709)
+ nCode = 216 ;
+ string sVal ;
+ if ( ! SetCodePoint( nCode, sVal))
+ sVal = "\7F" ; // carattere di errore 127
+ ReplaceString( sText, "\\U+" + sCode, sVal) ;
+ }
// se non ci sono "%%" posso uscire
if ( sText.find( "%%") == string::npos)
@@ -2325,11 +2340,11 @@ ImportDxf::AdjustMText( string& sText, double dTextMaxWidth, double dW)
return false ;
// elimino \L \k
- sText = tr1::regex_replace( sText, tr1::regex( "\\\\[LlOoKk]"), string("")) ;
+ sText = tr1::regex_replace( sText, tr1::regex( "\\\\[LlOoKk]"), string( "")) ;
// elimino \p...; \T...;
- sText = tr1::regex_replace( sText, tr1::regex( "\\\\[pQHWFfACT][^;]*;"), string("")) ;
+ sText = tr1::regex_replace( sText, tr1::regex( "\\\\[pQHWFfACT][^;]*;"), string( "")) ;
// trasformo \Sxxx; in xxx
- sText = tr1::regex_replace( sText, tr1::regex( "\\\\[S]([^;]*);"), string("$1")) ;
+ sText = tr1::regex_replace( sText, tr1::regex( "\\\\[S]([^;]*);"), string( "$1")) ;
// traformo "\~" in ' '
ReplaceString( sText, "\\~", " ") ;
// trasformo "\P" in "\n"
diff --git a/ImportDxfHeader.cpp b/ImportDxfHeader.cpp
new file mode 100644
index 0000000..3b200f4
--- /dev/null
+++ b/ImportDxfHeader.cpp
@@ -0,0 +1,72 @@
+//----------------------------------------------------------------------------
+// EgalTech 2014-2014
+//----------------------------------------------------------------------------
+// File : ImportDxfHeader.cpp Data : 08.06.14 Versione : 1.5f3
+// Contenuto : Implementazione di ImportDxf : gestione header.
+//
+//
+//
+// Modifiche : 08.06.14 DS Creazione modulo.
+//
+//
+//----------------------------------------------------------------------------
+
+//--------------------------- Include ----------------------------------------
+#include "stdafx.h"
+#include "ImportDxf.h"
+#include "DxfConst.h"
+#include "DllMain.h"
+#include "/EgtDev/Include/EGnStringUtils.h"
+
+using namespace std ;
+
+//----------------------------------------------------------------------------
+bool
+ImportDxf::ReadHeader( bool& bFileEnd)
+{
+ // ciclo di lettura
+ bool bOk = true ;
+ bool bSectEnd = false ;
+ bool bCodePage = false ;
+ bFileEnd = false ;
+ int nCode = CODE_NULL ;
+ do {
+ // leggo un Item
+ nCode = ReadNextItem() ;
+ if ( nCode == CODE_NULL) {
+ bFileEnd = true ;
+ return false ;
+ }
+ switch ( nCode) {
+ case 0 :
+ if ( m_sCurrItem == "SECTION") {
+ UngetItem() ;
+ bSectEnd = true ;
+ }
+ else if ( m_sCurrItem == "ENDSEC") {
+ bSectEnd = true ;
+ }
+ else if ( m_sCurrItem == "EOF") {
+ bSectEnd = true ;
+ bFileEnd = true ;
+ }
+ break ;
+ case 3 :
+ if ( bCodePage) {
+ string sCodePage = m_sCurrItem ;
+ ReplaceString( sCodePage, "ANSI_", "") ;
+ ReplaceString( sCodePage, "DOS", "") ;
+ int nVal ;
+ if ( FromString( sCodePage, nVal) && nVal >= 111 && nVal <= 28606)
+ m_nCodePage = nVal ;
+ }
+ break ;
+ case 9 :
+ if ( m_sCurrItem == "$DWGCODEPAGE")
+ bCodePage = true ;
+ break ;
+ }
+ } while ( ! bSectEnd) ;
+
+ return bOk ;
+}