Files
EgtExchange/ImportDxf.cpp
T
Dario Sassi 1ec34dc4e1 EgtExchange 1.5d4 :
- aggiunta importazione DXF.
2014-04-21 21:58:16 +00:00

201 lines
5.5 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : ImportDxf.cpp Data : 16.04.14 Versione : 1.5d4
// Contenuto : Implementazione della classe per l'importazione di DXF.
//
//
//
// Modifiche : 16.04.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 ;
//----------------------------------------------------------------------------
IImportDxf*
CreateImportDxf( void)
{
return static_cast<IImportDxf*> ( new(nothrow) ImportDxf) ;
}
//----------------------------------------------------------------------------
ImportDxf::ImportDxf( void)
{
m_pGDB = nullptr ;
m_nIdGroup = GDB_ID_NULL ;
m_bUnGet = false ;
m_nCurrCode = CODE_NULL ;
}
//----------------------------------------------------------------------------
bool
ImportDxf::Import( const string& sFile, IGeomDB* pGDB, int nIdGroup)
{
// inizializzo lo scanner
if ( ! m_theScanner.Init( sFile, nullptr, false)) {
LOG_ERROR( GetEExLogger(), "ImportDxf : Error on Init")
return false ;
}
// verifico il DB geometrico
if ( pGDB == nullptr) {
LOG_ERROR( GetEExLogger(), "ImportDxf : Error on GeomDB")
return false ;
}
m_pGDB = pGDB ;
// verifico l'Id di gruppo
if ( ! m_pGDB->ExistsObj( nIdGroup)) {
LOG_ERROR( GetEExLogger(), "ImportDxf : Error on IdGroup")
return false ;
}
m_nIdGroup = nIdGroup ;
// ricavo il riferimento del gruppo
if ( ! m_pGDB->GetGroupGlobFrame( m_nIdGroup, m_frGroup)) {
LOG_ERROR( GetEExLogger(), "ImportDxf : Error on Group Frame3d")
return false ;
}
// ciclo di lettura
bool bOk = true ;
bool bFileEnd = false ;
string sSectName ;
do {
// leggo intestazione sezione, per avere il tipo
bool bOkLoc = GetSectionName( sSectName, bFileEnd) ;
if ( bOkLoc && ! bFileEnd) {
// se sezione tavole
if ( sSectName == "TABLES") {
if ( ! ReadTables( bFileEnd))
bOkLoc = false ;
}
// se sezione blocchi
else if ( sSectName == "BLOCKS") {
if ( ! ReadBlocks( bFileEnd))
bOkLoc = false ;
}
// se sezione entità
else if ( sSectName == "ENTITIES") {
if ( ! ReadEntities( bFileEnd))
bOkLoc = false ;
}
// altrimenti
else {
if ( ! SkipSection( bFileEnd))
bOkLoc = false ;
}
}
// gestisco eventuale errore
if ( ! bOkLoc) {
bOk = false ;
string sOut = "ImportDxf : Error on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
}
} while ( ! bFileEnd) ;
// pulisco map dei layer
m_lmLayer.clear() ;
return bOk ;
}
//----------------------------------------------------------------------------
int
ImportDxf::ReadNextItem( void)
{
// se unget attivo
if ( m_bUnGet) {
m_bUnGet = false ;
return m_nCurrCode ;
}
// pulisco Item corrente
m_nCurrCode = CODE_NULL ;
m_sCurrItem.clear() ;
// recupero la prima linea
string sCode ;
if ( ! m_theScanner.GetLine( sCode))
return m_nCurrCode ;
// recupero la seconda linea
if ( ! m_theScanner.GetLine( m_sCurrItem))
return m_nCurrCode ;
// interpreto il codice
if ( ! FromString( sCode, m_nCurrCode))
m_nCurrCode = CODE_NULL ;
// se linea di commento, la ignoro e rilancio lettura item
if ( m_nCurrCode == 999)
ReadNextItem() ;
return m_nCurrCode ;
}
//----------------------------------------------------------------------------
void
ImportDxf::UngetItem( void)
{
m_bUnGet = true ;
}
//----------------------------------------------------------------------------
bool
ImportDxf::GetSectionName( string& sSectName, bool& bFileEnd)
{
// inizializzo
sSectName.clear() ;
bFileEnd = false ;
// leggo il primo Item (mi aspetto 0 -> SECTION)
int nCode = ReadNextItem() ;
if ( nCode == CODE_NULL) {
bFileEnd = true ;
return false ;
}
if ( nCode == 0 && m_sCurrItem == "EOF") {
bFileEnd = true ;
return true ;
}
if ( nCode != 0 || m_sCurrItem != "SECTION")
return false ;
// leggo il secondo Item (mi aspetto 0 -> NomeSezione)
nCode = ReadNextItem() ;
if ( nCode == CODE_NULL) {
bFileEnd = true ;
return false ;
}
if ( nCode != 2)
return false ;
sSectName = m_sCurrItem ;
return true ;
}
//----------------------------------------------------------------------------
bool
ImportDxf::SkipSection( bool& bFileEnd)
{
bFileEnd = false ;
int nCode = CODE_NULL ;
do {
// leggo un Item ( cerco 0 -> ENDSEC)
nCode = ReadNextItem() ;
if ( nCode == CODE_NULL) {
bFileEnd = true ;
return false ;
}
} while ( nCode != 0 || m_sCurrItem != "ENDSEC") ;
return true ;
}
//----------------------------------------------------------------------------
bool
ImportDxf::ReadBlocks( bool& bFileEnd)
{
return SkipSection( bFileEnd) ;
}