8426092c6f
- migliorato controllo gestione chiave di rete.
153 lines
4.3 KiB
C++
153 lines
4.3 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2018-2018
|
|
//----------------------------------------------------------------------------
|
|
// File : ImportPnt.cpp Data : 03.07.18 Versione : 1.9g1
|
|
// Contenuto : Implementazione della classe per l'importazione di Punti.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 03.07.18 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "ImportPnt.h"
|
|
#include "DllMain.h"
|
|
#include "/EgtDev/Include/EExDllMain.h"
|
|
#include "/EgtDev/Include/EGkGeoPoint3d.h"
|
|
#include "/EgtDEv/Include/EGnScanner.h"
|
|
#include "/EgtDev/Include/EgtKeyCodes.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
IImportPnt*
|
|
CreateImportPnt( void)
|
|
{
|
|
// verifico la chiave e le opzioni
|
|
if ( ! VerifyKey( KEYOPT_EEX_INPBASE))
|
|
return nullptr ;
|
|
// creo l'oggetto
|
|
return static_cast<IImportPnt*> ( new(nothrow) ImportPnt) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ImportPnt::Import( const string& sFile, IGeomDB* pGDB, int nIdGroup, int nFlag)
|
|
{
|
|
// verifico il DB geometrico
|
|
if ( pGDB == nullptr) {
|
|
LOG_ERROR( GetEExLogger(), "ImportPnt : Error on GeomDB")
|
|
return false ;
|
|
}
|
|
m_pGDB = pGDB ;
|
|
|
|
// verifico l'Id di gruppo
|
|
if ( ! m_pGDB->ExistsObj( nIdGroup)) {
|
|
LOG_ERROR( GetEExLogger(), "ImportPnt : Error on IdGroup")
|
|
return false ;
|
|
}
|
|
m_nIdGroup = nIdGroup ;
|
|
// ricavo il riferimento del gruppo
|
|
if ( ! m_pGDB->GetGroupGlobFrame( m_nIdGroup, m_frGroup)) {
|
|
LOG_ERROR( GetEExLogger(), "ImportPnt : Error on Group Frame3d")
|
|
return false ;
|
|
}
|
|
|
|
// imposto le opzioni di importazione
|
|
m_nFlag = nFlag ;
|
|
|
|
// inizializzo lo scanner
|
|
Scanner TheScanner ;
|
|
if ( ! TheScanner.Init( sFile, "")) {
|
|
LOG_ERROR( GetEExLogger(), "ImportPnt : Error on Init")
|
|
return false ;
|
|
}
|
|
|
|
// inizializzo lo stato
|
|
m_nLine = 0 ;
|
|
m_bLast = false ;
|
|
m_ptLast = ORIG ;
|
|
|
|
// inserisco un nuovo layer nel DB geometrico
|
|
m_nLayId = m_pGDB->AddGroup( GDB_ID_NULL, m_nIdGroup, GLOB_FRM) ;
|
|
if ( m_nLayId == GDB_ID_NULL) {
|
|
LOG_ERROR( GetEExLogger(), "ImportPnt : Error creating Layer")
|
|
return false ;
|
|
}
|
|
|
|
// ciclo di lettura delle linee
|
|
bool bOk = true ;
|
|
string sLine ;
|
|
while ( TheScanner.GetLine( sLine)) {
|
|
m_nLine = TheScanner.GetCurrLineNbr() ;
|
|
if ( ! ProcessLine( sLine)) {
|
|
bOk = false ;
|
|
string sErr = "ImportPnt : Error on line " + ToString( m_nLine) ;
|
|
LOG_ERROR( GetEExLogger(), sErr.c_str())
|
|
}
|
|
}
|
|
|
|
// se importazione riuscita eseguo elaborazione finale
|
|
if ( bOk)
|
|
bOk = PostProcess() ;
|
|
|
|
return bOk ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ImportPnt::ProcessLine( const string& sLine)
|
|
{
|
|
// Divido sugli spazi
|
|
STRVECTOR vsTokens ;
|
|
Tokenize( sLine, " ", vsTokens) ;
|
|
|
|
// Punto
|
|
Point3d ptNew = m_ptLast ;
|
|
|
|
// Almeno due parti (X e Y)
|
|
if ( vsTokens.size() < 2)
|
|
return false ;
|
|
FromString( vsTokens[0], ptNew.x) ;
|
|
FromString( vsTokens[1], ptNew.y) ;
|
|
|
|
// Eventuale terza parte Z
|
|
if ( vsTokens.size() >= 3)
|
|
FromString( vsTokens[2], ptNew.z) ;
|
|
|
|
// Se non esiste precedente o diverso, lo inserisco
|
|
if ( ! m_bLast || ! AreSamePointEpsilon( m_ptLast, ptNew, 2 * EPS_SMALL)) {
|
|
// creo il punto
|
|
PtrOwner<IGeoPoint3d> pGeoPnt( CreateGeoPoint3d()) ;
|
|
if ( IsNull( pGeoPnt))
|
|
return false ;
|
|
// setto il punto
|
|
if ( ! pGeoPnt->Set( ptNew))
|
|
return false ;
|
|
// porto il punto nel riferimento del gruppo
|
|
pGeoPnt->ToLoc( m_frGroup) ;
|
|
// inserisco il punto nel DB
|
|
int nId = m_pGDB->AddGeoObj( GDB_ID_NULL, m_nLayId, Release( pGeoPnt)) ;
|
|
if ( nId == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
// aggiorno il punto
|
|
m_ptLast = ptNew ;
|
|
m_bLast = true ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ImportPnt::PostProcess( void)
|
|
{
|
|
return true ;
|
|
}
|
|
|
|
|