Files
EgtExchange/ImportBtl.cpp
T
DarioS 8426092c6f EgtExchange 2.5e5 :
- migliorato controllo gestione chiave di rete.
2023-05-30 10:25:16 +02:00

1273 lines
44 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : ImportBtl.cpp Data : 22.08.15 Versione : 1.6h5
// Contenuto : Implementazione della classe per l'importazione BTL.
//
//
//
// Modifiche : 22.08.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "ImportBtl.h"
#include "BtlConst.h"
#include "DllMain.h"
#include "/EgtDev/Include/EExDllMain.h"
#include "/EgtDev/Include/EGkStmStandard.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EGnFileUtils.h"
#include "/EgtDev/Include/EgtKeyCodes.h"
#include "/EgtDev/Include/EgtStringEncoder.h"
#include "/EgtDev/Include/EgtStringEncoder.h"
using namespace std ;
//----------------------------------------------------------------------------
bool
SetBtlAuxDir( const string& sBtlAuxDir)
{
BtlGeom::m_sBtlAuxDir = sBtlAuxDir ;
return ExistsDirectory( sBtlAuxDir) ;
}
//----------------------------------------------------------------------------
IImportBtl*
CreateImportBtl( void)
{
// verifico la chiave e le opzioni
if ( ! VerifyKey( KEYOPT_EEX_INPADV))
return nullptr ;
// creo l'oggetto
return static_cast<IImportBtl*> ( new(nothrow) ImportBtl) ;
}
//----------------------------------------------------------------------------
ImportBtl::ImportBtl( void)
{
m_nBuild = 10000 ;
m_dScale = 1 ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::Import( const string& sFile, IGeomDB* pGDB, int nFlag)
{
// log di informazioni
LOG_INFO( GetEExLogger(), ( "ImportBtl : " + sFile).c_str())
// inizializzo lo scanner
if ( ! m_theScanner.Init( sFile, KEY_COMMENT.c_str())) {
LOG_ERROR( GetEExLogger(), " Error on Init")
return false ;
}
// inizializzo il gestore geometria pezzi Btl
int nFlatVertPos = 0 ;
if (( nFlag & EIBFLAG_OUTL_FLAT_POS) != 0)
nFlatVertPos = 4 ;
else if (( nFlag & EIBFLAG_TS3_POS) != 0)
nFlatVertPos = 3 ;
else if (( nFlag & EIBFLAG_FLAT_POS) != 0)
nFlatVertPos = 1 ;
else if (( nFlag & EIBFLAG_VERT_POS) != 0)
nFlatVertPos = 2 ;
bool bSpecialTrim = (( nFlag & EIBFLAG_SPECIAL_TRIM) != 0) ;
bool bTrimWithOutline = (( nFlag & EIBFLAG_TRIM_WITH_OUTLINE) != 0) ;
bool bUseUAttr = (( nFlag & EIBFLAG_USEUATTR) != 0) ;
if ( ! m_BtlGeom.Init( pGDB, nFlatVertPos, bSpecialTrim, bTrimWithOutline, bUseUAttr)) {
LOG_ERROR( GetEExLogger(), " Error on BtlGeom.Init")
return false ;
}
// scrivo nel progetto path del file
m_BtlGeom.SetUserAttribute( UATD_INFO, IKEY_BTL_PATH + ":" + sFile) ;
// lettura intestazione
if ( ! ReadHeader()) {
string sOut = " Error (ReadHeader) on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
return false ;
}
// lettura generalità
bool bEnd ;
if ( ! ReadGeneral( bEnd)) {
string sOut = " Error (ReadGeneral) on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
return false ;
}
else if ( bEnd) {
string sOut = " Error No Parts in Btl file" ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
return false ;
}
// ciclo sui grezzi
bool bOk = true ;
for ( bool bEnd = false ; ! bEnd ;) {
// leggo un grezzo
if ( ! ReadObject( RAWPART, bEnd)) {
// i log di errore sono già gestiti nella funzione chiamata
bOk = false ;
}
// se aggiunto un grezzo, lo sistemo
if ( ! bEnd) {
int nNewPart = m_BtlGeom.GetCurrPartId() ;
if ( ! m_BtlGeom.AdjustRawPart( nNewPart)) {
string sOut = " Error Adjusting RawPart on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
return false ;
}
}
}
// ciclo sui pezzi
for ( bool bEnd = false ; ! bEnd ;) {
// leggo un pezzo
if ( ! ReadObject( PART, bEnd)) {
// i log di errore sono già gestiti nella funzione chiamata
bOk = false ;
}
}
// ciclo sui compositi
for ( bool bEnd = false ; ! bEnd ;) {
// leggo un composito
if ( ! ReadObject( COMPOSITE, bEnd)) {
// i log di errore sono già gestiti nella funzione chiamata
bOk = false ;
}
// se aggiunto un composito, lo sistemo
if ( ! bEnd) {
int nNewPart = m_BtlGeom.GetCurrPartId() ;
if ( ! m_BtlGeom.AdjustComposite( nNewPart)) {
string sOut = " Error Adjusting Composite on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
return false ;
}
}
}
// aggiusto riferimenti per grezzi e per compositi
m_BtlGeom.AdjustRefForRawParts() ;
m_BtlGeom.AdjustRefForComposites() ;
// verifica definizione e unicità SN ed eventuale sistemazione
m_BtlGeom.AdjustSnForParts() ;
// eventuale ordinamento degli oggetti secondo SN
bool bSort = (( nFlag & EIBFLAG_SORT) != 0) ;
if ( bSort) {
Point3d ptIns ;
m_BtlGeom.SortObjects( GDB_ID_ROOT, ptIns) ;
m_BtlGeom.SortObjects( m_BtlGeom.GetRawPartsGroup(), ptIns) ;
m_BtlGeom.SortObjects( m_BtlGeom.GetCompositesGroup(), ptIns) ;
}
return bOk ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::ReadHeader( void)
{
// conteggio campi utili letti
int nRead = 0 ;
// ciclo sulle linee
string sLine ;
while ( m_theScanner.GetLine( sLine)) {
// se cambio sezione
if ( sLine[0] == '[') {
m_theScanner.UngetLine( sLine) ;
return ( nRead > 0) ;
}
// spezzo la linea
string sKey, sVal ;
SplitFirst( sLine, ":", sKey, sVal) ;
// se numero di versione
if ( sKey == KEY_VERSION) {
Trim( sVal, " \t\r\n\"") ;
m_sVersion = sVal ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, m_sVersion) ;
}
// se numero di build
else if ( sKey == KEY_BUILD) {
Trim( sVal, " \t\r\n\"") ;
if ( FromString( sVal, m_nBuild))
++ nRead ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
}
// se edizione
else if ( sKey == KEY_EDITION) {
Trim( sVal, " \t\r\n\"") ;
if ( sVal == "PREFABRICATION")
m_nEdition = 1 ;
else
m_nEdition = 0 ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
}
}
return false ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::ReadGeneral( bool& bEnd)
{
// default file non finito
bEnd = false ;
// conteggio campi utili letti
int nRead = 0 ;
// leggo la prossima linea e verifico sia la sezione GENERAL
string sLine ;
if ( ! m_theScanner.GetLine( sLine) || sLine != SEC_GENERAL)
return false ;
// ciclo sulle linee
while ( m_theScanner.GetLine( sLine)) {
// se cambio sezione
if ( sLine[0] == '[') {
m_theScanner.UngetLine( sLine) ;
return ( nRead > 0) ;
}
// spezzo la linea
string sKey, sVal ;
SplitFirst( sLine, ":", sKey, sVal) ;
switch ( FindGeneralKey( sKey)) {
case KEY_GENE_PROJECTNUMBER : // numero di progetto
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_PROJECTNAME : // nome di progetto
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_PROJECTPART : // parte di progetto
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_PROJECTGUID : // identificativo globale unico di progetto
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_LISTNAME : // nome lista
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_CUSTOMER : // cliente
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_ARCHITECT : // architetto
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_EDITOR : // autore
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_DELIVERYDATE : // data di consegna
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_EXPORTDATE : // data di esportazione
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_EXPORTTIME : // ora di esportazione
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_EXPORTRELEASE : // programma di esportazione
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_LANGUAGE : // lingua
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_RANGE : // range dei parametri
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_SCALEUNIT : // numero di decimali
{
Trim( sVal, " \t\r\n\"") ;
int nUnit ;
if ( FromString( sVal, nUnit)) {
m_dScale = pow( 10, - nUnit) ;
++ nRead ;
}
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
}
break ;
case KEY_GENE_PROCESSINGQUALITY : // qualità di lavorazione
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_COMPUTERNAME : // nome computer
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_USER : // nome utente
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_SOURCEFILE : // file sorgente
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_EXPORTFILE : // file di esportazione
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_RECESS : // finitura angoli interni
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_INFO, sKey, sVal) ;
break ;
case KEY_GENE_USERATTRIBUTE : // attributo utente
m_BtlGeom.SetUserAttribute( UATD_INFO, sVal) ;
break ;
}
}
// fine del file
bEnd = true ;
return ( nRead > 0) ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::ReadObject( ObjType nType, bool& bEnd)
{
string sLine ;
// leggo la prossima linea
if ( ! m_theScanner.GetLine( sLine)) {
bEnd = true ;
return true ;
}
// verifico sia la sezione opportuna (PART, RAWPART o COMPOSITE)
if (( nType == PART && sLine != SEC_PART) ||
( nType == RAWPART && sLine != SEC_RAWPART) ||
( nType == COMPOSITE && sLine != SEC_COMPOSITE)) {
m_theScanner.UngetLine( sLine) ;
bEnd = true ;
return true ;
}
// creo il pezzo
if ( ! m_BtlGeom.CreatePart()) {
string sOut = " Error (CreatePart) on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
SkipCurrSection() ;
bEnd = false ;
return false ;
}
// ciclo sulle linee con i dati generali del pezzo
double dLength = 0, dHeight = 0, dWidth = 0 ;
bool bLength = false, bHeight = false, bWidth = false, bBox = false ;
int nTrasfCount = 0 ;
string sUID = "0" ;
while ( m_theScanner.GetLine( sLine)) {
// se cambio sezione
if ( sLine[0] == '[') {
m_theScanner.UngetLine( sLine) ;
bEnd = false ;
// aggiorno outline
return m_BtlGeom.UpdateOutLine() ;
}
// spezzo la linea
string sKey, sVal ;
SplitFirst( sLine, ":", sKey, sVal) ;
switch ( FindPartKey( sKey)) {
case KEY_PART_TYPE : // tipo (solo per Compositi)
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_SINGLEMEMBERNUMBER : // identificativo di produzione
{
int nProdNbr = 0 ;
if ( FromString( sVal, nProdNbr))
m_BtlGeom.SetPartProdNbr( nProdNbr) ;
}
break ;
case KEY_PART_ASSEMBLYNUMBER : // numero di lista nell'assemblato
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_ORDERNUMBER : // numero di lista nell'ordine
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_DESIGNATION : // nome
Trim( sVal, " \t\r\n\"") ;
if ( ! IsTextUtf8( sVal.c_str()))
sVal = LPSTR( WtoA( LPWSTR( AtoW( sVal.c_str(), 1252)))) ;
m_BtlGeom.SetPartName( sVal) ;
break ;
case KEY_PART_ANNOTATION : // annotazione
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_STOREY : // sottogruppo
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_GROUP : // gruppo
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_PACKAGE : // pacco di spedizione
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_MATERIAL : // materiale
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_TIMBERGRADE : // qualità legname
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_QUALITYGRADE : // qualità
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_COUNT : // quantità
{
int nCount = 0 ;
if ( FromString( sVal, nCount))
m_BtlGeom.SetPartCount( nCount) ;
}
break ;
case KEY_PART_LENGTH : // lunghezza (dimensione in X)
if ( FromString( sVal, dLength)) {
dLength *= m_dScale ;
bLength = true ;
}
if ( bLength && bHeight && bWidth) {
if ( m_BtlGeom.AddPartBox( dLength, dHeight, dWidth))
bBox = true ;
}
break ;
case KEY_PART_HEIGHT : // altezza (dimensione in Y)
if ( FromString( sVal, dHeight)) {
dHeight *= m_dScale ;
bHeight = true ;
}
if ( bLength && bHeight && bWidth) {
if ( m_BtlGeom.AddPartBox( dLength, dHeight, dWidth))
bBox = true ;
}
break ;
case KEY_PART_WIDTH : // larghezza (dimensione in Z)
if ( FromString( sVal, dWidth)) {
dWidth *= m_dScale ;
bWidth = true ;
}
if ( bLength && bHeight && bWidth) {
if ( m_BtlGeom.AddPartBox( dLength, dHeight, dWidth))
bBox = true ;
}
break ;
case KEY_PART_COLOUR : // colore
{
Trim( sVal, " \t\r\n\"") ;
Color colRes ;
if ( ReadColor( sVal, colRes))
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, ToString( colRes)) ;
}
break ;
case KEY_PART_PLANINGLENGTH : // lunghezza spianatura
{
Trim( sVal, " \t\r\n\"") ;
double dVal ;
if ( GetParam( sVal, dVal))
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, ToString( dVal, 3)) ;
}
break ;
case KEY_PART_STARTOFFSET : // offset iniziale
{
Trim( sVal, " \t\r\n\"") ;
double dVal ;
if ( GetParam( sVal, dVal))
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, ToString( dVal, 3)) ;
}
break ;
case KEY_PART_ENDOFFSET : // offset finale
{
Trim( sVal, " \t\r\n\"") ;
double dVal ;
if ( GetParam( sVal, dVal))
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, ToString( dVal, 3)) ;
}
break ;
case KEY_PART_UID : // UID istanza pezzo nella struttura
Trim( sVal, " \t\r\n\"") ;
sUID = sVal ;
break ;
case KEY_PART_TRANSFORMATION : // matrice di trasformazione istanza pezzo nella struttura
{
Frame3d frRef ;
if ( ReadTransformation( sVal, frRef)) {
++ nTrasfCount ;
if ( nType == PART)
m_BtlGeom.AddPartTransformation( sUID, frRef) ;
string sUIDKey = sPartKey[KEY_PART_UID] + ToString( nTrasfCount) ;
m_BtlGeom.SetUserAttribute( UATD_PART, sUIDKey, sUID) ;
string sTRFKey = sPartKey[KEY_PART_TRANSFORMATION] + ToString( nTrasfCount) ;
m_BtlGeom.SetUserAttribute( UATD_PART, sTRFKey, ToString( frRef)) ;
}
}
break ;
case KEY_PART_CAMBER : // incurvamento
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_PARTOFFSET : // offset pezzo
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_PROCESSINGQUALITY : // qualità di lavorazione
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_OUTLINE : // contorno
// interpreto l'outline
m_theScanner.UngetLine( sLine) ;
if ( ! ReadOutline()) {
string sOut = " Error (ReadOutline) on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
SkipCurrSection() ;
m_BtlGeom.ErasePart() ;
bEnd = false ;
return false ;
}
break ;
case KEY_PART_APERTURE : // apertura
// interpreto l'apertura
m_theScanner.UngetLine( sLine) ;
if ( ! ReadAperture()) {
string sOut = " Error (ReadAperture) on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
SkipCurrSection() ;
m_BtlGeom.ErasePart() ;
bEnd = false ;
return false ;
}
break ;
case KEY_PART_RECESS : // finitura angoli interni
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_STOREYTYPE : // tipo di piano
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_ELEMENTNUMBER : // numero elemento
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_LAYER : // layer
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_MODULENUMBER : // numero modulo
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_USERATTRIBUTE : // attributo utente
m_BtlGeom.SetUserAttribute( UATD_PART, sVal) ;
break ;
case KEY_PART_GRAINDIRECTION : // direzione venatura
{
Trim( sVal, " \t\r\n\"") ;
Vector3d vtDir ;
bool bAlign ;
if ( ReadGrainDirection( sVal, vtDir, bAlign))
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, ToString( vtDir) + ";" + ( bAlign ? "1" : "0")) ;
}
break ;
case KEY_PART_REFERENCESIDE : // lato di riferimento
{
Trim( sVal, " \t\r\n\"") ;
int nSide ;
bool bAlign ;
if ( ReadReferenceSide( sVal, nSide, bAlign))
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, ToString( nSide) + ";" + ( bAlign ? "1" : "0")) ;
}
break ;
case KEY_PART_ALIGNMENT : // allineamento
Trim( sVal, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal) ;
break ;
case KEY_PART_MATERIALTYPE : // tipo di materiale
Trim( sVal, " \t\r\n\"") ;
string sVal1, sVal2 ;
Split( sVal, ":", true, sVal1, sVal2) ;
Trim( sVal2, " \t\r\n\"") ;
m_BtlGeom.SetUserAttribute( UATD_PART, sKey, sVal1 + ": " + sVal2) ;
break ;
}
// se lavorazione, esco dal ciclo
if ( sKey == sProcKey[KEY_PROC_PROCESSKEY]) {
m_theScanner.UngetLine( sLine) ;
break ;
}
}
// verifico sia stato definito il contorno del pezzo
if ( ! bBox) {
string sOut = " Error (AddPartBox) on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
SkipCurrSection() ;
m_BtlGeom.ErasePart() ;
bEnd = false ;
return false ;
}
// interpreto le lavorazioni (processing)
bool bOk = true ;
for ( bool bProcEnd = false ; ! bProcEnd ;) {
if ( ! ReadProcess( nType != PART, bProcEnd)) {
// i log di errore sono già gestiti nella funzione chiamata
bOk = false ;
}
}
// inserisco eventuali contorni liberi
if ( ! m_BtlGeom.CreateFreeContours())
bOk = false ;
// aggiorno outline
if ( ! m_BtlGeom.UpdateOutLine()) {
string sOut = " Error (UpdateOutLine) on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
m_BtlGeom.ErasePart() ;
}
bEnd = false ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::ReadTransformation( const string& sVal, Frame3d& frRef)
{
// leggo i valori
Point3d ptO ;
GetParam( sVal, PAR_OX, ptO.x) ;
GetParam( sVal, PAR_OY, ptO.y) ;
GetParam( sVal, PAR_OZ, ptO.z) ;
Vector3d vtX ;
GetParam( sVal, PAR_XX, vtX.x) ;
GetParam( sVal, PAR_XY, vtX.y) ;
GetParam( sVal, PAR_XZ, vtX.z) ;
if ( vtX.IsSmall())
vtX = X_AX ;
Vector3d vtY ;
GetParam( sVal, PAR_YX, vtY.x) ;
GetParam( sVal, PAR_YY, vtY.y) ;
GetParam( sVal, PAR_YZ, vtY.z) ;
if ( vtY.IsSmall())
vtY = Y_AX ;
// calcolo il riferimento
return frRef.Set( ptO, ptO + vtX, ptO + vtY) ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::ReadOutline( void)
{
bool bProcFound = false ;
int nSide = BTL_SIDE_NONE ;
int nContType = 0 ;
int nContData = 0 ;
double dContPar = 0 ;
FCEDEQUE dqFce ;
STRVECTOR vsUAtt ;
// ciclo sulle linee
string sLine ;
while ( m_theScanner.GetLine( sLine)) {
// spezzo la linea
string sKey, sVal ;
SplitFirst( sLine, ":", sKey, sVal) ;
// se attributo utente
if ( sKey == sPartKey[KEY_PART_USERATTRIBUTE]) {
vsUAtt.emplace_back( sVal) ;
continue ;
}
// se cambio tipologia, concludo
else if ( sKey != sPartKey[KEY_PART_OUTLINE]) {
m_theScanner.UngetLine( sLine) ;
break ;
}
// leggo i dati
// tipo
int nFlag ;
GetParamP( sVal, 8, nFlag) ;
// se non ancora assegnato, leggo se da lavorare
if ( ! bProcFound) {
string sToDo ;
if ( GetInfo( sVal, PAR_PROCESS, sToDo)) {
if ( sToDo.find( "YES") != 0)
vsUAtt.emplace_back( "DO:0") ;
bProcFound = true ;
}
}
// se non ancora assegnata, leggo faccia di riferimento
if ( nSide == BTL_SIDE_NONE)
GetInfo( sVal, PAR_SIDE, nSide) ;
// punto principale
Point3d ptP ;
GetParamP( sVal, 1, ptP.x) ;
GetParamP( sVal, 2, ptP.y) ;
GetParamP( sVal, 3, ptP.z) ;
// se inizio leggo tipo contorno, dato e parametro
if ( nFlag == FreeContourEnt::START) {
GetParamP( sVal, 13, nContType) ;
GetParamP( sVal, 14, nContData) ;
GetParamP( sVal, 15, dContPar) ;
}
// se arco leggo il punto intermedio
Point3d ptM ;
if ( nFlag == FreeContourEnt::ARC) {
GetParamP( sVal, 10, ptM.x) ;
GetParamP( sVal, 11, ptM.y) ;
GetParamP( sVal, 12, ptM.z) ;
}
// angolo di fianco
double dAng = ( nFlag == FreeContourEnt::START ? FC_SIDEANG_DEF : FC_SIDEANG_NONE) ;
GetParamP( sVal, 6, dAng) ;
// aggiungo i dati alla deque
dqFce.emplace_back( nFlag, ptP, ptM, dAng, 0, 0) ;
}
// inserimento del contorno nel pezzo
return m_BtlGeom.AddPartOutline( nSide, dqFce, nContType, nContData, dContPar, vsUAtt) ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::ReadAperture( void)
{
bool bProcFound = false ;
int nSide = BTL_SIDE_NONE ;
int nContType = 0 ;
int nContData = 0 ;
double dContPar = 0 ;
FCEDEQUE dqFce ;
STRVECTOR vsUAtt ;
// ciclo sulle linee
string sLine ;
while ( m_theScanner.GetLine( sLine)) {
// spezzo la linea
string sKey, sVal ;
SplitFirst( sLine, ":", sKey, sVal) ;
// se attributo utente
if ( sKey == sPartKey[KEY_PART_USERATTRIBUTE]) {
vsUAtt.emplace_back( sVal) ;
continue ;
}
// se cambio tipologia, concludo
else if ( sKey != sPartKey[KEY_PART_APERTURE]) {
m_theScanner.UngetLine( sLine) ;
break ;
}
// leggo i dati
// tipo
int nFlag ;
GetParamP( sVal, 8, nFlag) ;
// se tipo start ed esistono precedenti entità, ne derivo una apertura
if ( nFlag == FreeContourEnt::START && dqFce.size() > 0) {
if ( ! m_BtlGeom.AddPartAperture( nSide, dqFce, nContType, nContData, dContPar, vsUAtt))
return false ;
nSide = BTL_SIDE_NONE ;
nContType = 0 ;
nContData = 0 ;
dContPar = 0 ;
bProcFound = false ;
dqFce.clear() ;
vsUAtt.clear() ;
}
// se non ancora assegnato, leggo se da lavorare
if ( ! bProcFound) {
string sToDo ;
if ( GetInfo( sVal, PAR_PROCESS, sToDo)) {
if ( sToDo.find( "YES") != 0)
vsUAtt.emplace_back( "DO:0") ;
bProcFound = true ;
}
}
// se non ancora assegnata, leggo faccia di riferimento
if ( nSide == BTL_SIDE_NONE)
GetInfo( sVal, PAR_SIDE, nSide) ;
// punto principale
Point3d ptP ;
GetParamP( sVal, 1, ptP.x) ;
GetParamP( sVal, 2, ptP.y) ;
GetParamP( sVal, 3, ptP.z) ;
// se inizio leggo tipo contorno, dato e parametro
if ( nFlag == FreeContourEnt::START) {
GetParamP( sVal, 13, nContType) ;
GetParamP( sVal, 14, nContData) ;
GetParamP( sVal, 15, dContPar) ;
}
// se arco leggo il punto intermedio
Point3d ptM ;
if ( nFlag == FreeContourEnt::ARC) {
GetParamP( sVal, 10, ptM.x) ;
GetParamP( sVal, 11, ptM.y) ;
GetParamP( sVal, 12, ptM.z) ;
}
// angolo di fianco
double dAng = ( nFlag == FreeContourEnt::START ? FC_SIDEANG_DEF : FC_SIDEANG_NONE) ;
GetParamP( sVal, 6, dAng) ;
// aggiungo i dati alla deque
dqFce.emplace_back( nFlag, ptP, ptM, dAng, 0, 0) ;
}
// inserimento dell'ultima apertura nel pezzo
return m_BtlGeom.AddPartAperture( nSide, dqFce, nContType, nContData, dContPar, vsUAtt) ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::ReadColor( const string& sVal, Color& colRes)
{
// leggo i valori
string sRes ;
GetParam( sVal, PAR_R, sRes) ;
int nRed ; FromString( sRes, nRed) ;
GetParam( sVal, PAR_G, sRes) ;
int nGreen ; FromString( sRes, nGreen) ;
GetParam( sVal, PAR_B, sRes) ;
int nBlue ; FromString( sRes, nBlue) ;
GetParam( sVal, PAR_A, sRes) ;
int nAlpha ; FromString( sRes, nAlpha) ; nAlpha = nAlpha * 100 / 255 ;
colRes.Set( nRed, nGreen, nBlue, nAlpha) ;
return true ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::ReadGrainDirection( const string& sVal, Vector3d& vtDir, bool& bAlign)
{
// leggo i valori (possono essere su più linee consecutive)
GetParam( sVal, PAR_X, vtDir.x) ;
if ( ! GetParam( sVal, PAR_Y, vtDir.y)) {
string sLine ;
m_theScanner.GetLine( sLine) ;
if ( ! GetParam( sLine, PAR_Y, vtDir.y)) {
m_theScanner.UngetLine( sLine) ;
return false ;
}
}
if ( ! GetParam( sVal, PAR_Z, vtDir.z)) {
string sLine ;
m_theScanner.GetLine( sLine) ;
if ( ! GetParam( sLine, PAR_Z, vtDir.z)) {
m_theScanner.UngetLine( sLine) ;
return false ;
}
}
string sRes ;
if ( ! GetParam( sVal, PAR_ALIGN, sRes)) {
string sLine ;
m_theScanner.GetLine( sLine) ;
if ( ! GetParam( sLine, PAR_ALIGN, sRes)) {
m_theScanner.UngetLine( sLine) ;
return false ;
}
}
bAlign = ( sRes == "YES") ;
// ritorno
return ( vtDir.Normalize()) ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::ReadReferenceSide( const string& sVal, int& nSide, bool& bAlign)
{
// leggo i valori (possono essere su più linee consecutive)
GetParam( sVal, PAR_SIDE, nSide) ;
string sRes ;
if ( ! GetParam( sVal, PAR_ALIGN, sRes)) {
string sLine ;
m_theScanner.GetLine( sLine) ;
if ( ! GetParam( sLine, PAR_ALIGN, sRes)) {
m_theScanner.UngetLine( sLine) ;
return false ;
}
}
bAlign = ( sRes == "YES") ;
return true ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::ReadProcess( bool bObjRef, bool& bProcEnd)
{
bProcEnd = false ;
string sLine ;
// leggo la prossima linea
if ( ! m_theScanner.GetLine( sLine)) {
bProcEnd = true ;
return true ;
}
// verifico sia l'istruzione PROCESSKEY
if ( sLine.find( sProcKey[KEY_PROC_PROCESSKEY]) == string::npos) {
m_theScanner.UngetLine( sLine) ;
bProcEnd = true ;
return true ;
}
// recupero i parametri
string sKey, sVal ;
SplitFirst( sLine, ":", sKey, sVal) ;
TrimLeft( sVal) ;
string sType, sDes ;
SplitFirst( sVal, " ", sType, sDes) ;
Trim( sDes) ;
STRVECTOR vsItem ;
Tokenize( sType, "-", vsItem) ;
if ( vsItem.size() < 3) {
string sOut = " Error in ProcessType(" + sType + ") on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
SkipCurrProcess() ;
bProcEnd = false ;
return false ;
}
int nGroup = 0 ;
FromString( vsItem[0], nGroup) ;
int nProc = 0 ;
FromString( vsItem[1], nProc) ;
int nSide = 0 ;
FromString( vsItem[2], nSide) ;
if ( nGroup != BTL_OBJECT_REF && ( nSide < BTL_SIDE_FRONT || nSide > BTL_SIDE_TOP))
nSide = BTL_SIDE_FRONT ;
bool bParams = false ;
INTVECTOR vnDPar ;
int nSPar = 0 ;
DBLVECTOR vdPar ;
string sPar ;
int nProcId = 0 ;
Frame3d frRef ;
STRVECTOR vsUAtt ;
string sUID ;
// ciclo sulle linee
while ( true) {
// se fine file, concludo
if ( ! m_theScanner.GetLine( sLine)) {
bProcEnd = true ;
break ;
}
// se cambio sezione, concludo
if ( sLine[0] == '[') {
m_theScanner.UngetLine( sLine) ;
bProcEnd = true ;
break ;
}
// se nuova lavorazione, concludo
if ( sLine.find( sProcKey[KEY_PROC_PROCESSKEY]) != string::npos) {
m_theScanner.UngetLine( sLine) ;
bProcEnd = false ;
break ;
}
// spezzo la linea
string sKey, sVal ;
SplitFirst( sLine, ":", sKey, sVal) ;
switch ( FindProcessKey( sKey)) {
case KEY_PROC_REFERENCEPLANE : // riferimento
if ( ! ReadTransformation( sVal, frRef)) {
string sOut = " Error : unable to read ReferencePlane (" + sType + ") on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
SkipCurrProcess() ;
bProcEnd = false ;
return false ;
}
break ;
case KEY_PROC_PROCESSPARAMETERS : // parametri
if ( nProc == BTL_OBJECT_REF) {
if ( ! GetParam( sVal, PAR_UID, sUID)) {
string sOut = " Error in GetProcessParams (" + sType + ") on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
SkipCurrProcess() ;
bProcEnd = false ;
return false ;
}
bParams = true ;
break ;
}
if ( ! m_BtlGeom.GetProcessParamInfos( nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar)) {
string sOut = " Error : Unknown Process (" + sType + ") on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
SkipCurrProcess() ;
bProcEnd = false ;
return true ;
}
else if ( ! GetProcessParams( sVal, sType, vnDPar, nSPar, vdPar, sPar)) {
string sOut = " Error in GetProcessParams (" + sType + ") on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
SkipCurrProcess() ;
bProcEnd = false ;
return false ;
}
bParams = true ;
break ;
case KEY_PROC_PROCESSIDENT : // identificativo
FromString( sVal, nProcId) ;
break ;
case KEY_PROC_PROCESSINGQUALITY : // qualità di lavorazione
Trim( sVal, " \t\r\n\"") ;
vsUAtt.emplace_back( sKey + ":" + sVal) ;
break ;
case KEY_PROC_USERATTRIBUTE : // attributo utente
vsUAtt.emplace_back( sVal) ;
break ;
case KEY_PROC_PRIORITY : // priorità di lavorazione
Trim( sVal, " \t\r\n\"") ;
vsUAtt.emplace_back( sKey + ":" + sVal) ;
break ;
case KEY_PROC_RECESS : // tipo angolo interno
Trim( sVal, " \t\r\n\"") ;
vsUAtt.emplace_back( sKey + ":" + sVal) ;
break ;
case KEY_PROC_PROCESS : // indicazione di produzione
Trim( sVal) ;
if ( sVal != "YES")
vsUAtt.emplace_back( "DO:0") ;
break ;
}
}
// se riferimento ad oggetto
if ( nProc == BTL_OBJECT_REF) {
// inserimento del riferimento nel pezzo
if ( ! bParams ||
! m_BtlGeom.AddObjectRef( sUID, frRef)) {
string sOut = " Error in AddObjectRef (" + sType + ") to Part " + m_BtlGeom.GetPartName() + " on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
bProcEnd = false ;
return false ;
}
}
// altrimenti lavorazione
else {
// inserimento della lavorazione nel pezzo
if ( ! bParams ||
! m_BtlGeom.AddProcess( nGroup, nProc, nSide, sDes, nProcId, frRef, vnDPar, nSPar, vdPar, sPar, vsUAtt, m_theScanner.GetCurrLineNbr())) {
string sOut = " Error in AddProcess (" + sType + ") to Part " + m_BtlGeom.GetPartName() + " on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_ERROR( GetEExLogger(), sOut.c_str())
bProcEnd = false ;
return false ;
}
}
bProcEnd = false ;
return true ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::SkipCurrSection( void)
{
// ciclo sulle linee
string sLine ;
while ( true) {
// se fine file, concludo
if ( ! m_theScanner.GetLine( sLine)) {
break ;
}
// se cambio sezione, concludo
if ( sLine[0] == '[') {
m_theScanner.UngetLine( sLine) ;
break ;
}
}
return true ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::SkipCurrProcess( void)
{
// ciclo sulle linee
string sLine ;
while ( true) {
// se fine file, concludo
if ( ! m_theScanner.GetLine( sLine)) {
break ;
}
// se cambio sezione, concludo
if ( sLine[0] == '[') {
m_theScanner.UngetLine( sLine) ;
break ;
}
// se nuova lavorazione, concludo
if ( sLine.find( sProcKey[KEY_PROC_PROCESSKEY]) != string::npos) {
m_theScanner.UngetLine( sLine) ;
break ;
}
}
return true ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::GetProcessParams( const string& sText, const string& sProcType,
const INTVECTOR& vnDPar, int nSPar,
DBLVECTOR& vdPar, string& sPar)
{
// verifico corrispondenza numero definizioni - numero parametri numerici
if ( vnDPar.size() != vdPar.size())
return false ;
// leggo i parametri numerici
for ( int i = 0 ; i < int( vnDPar.size()) ; ++ i) {
if ( ! GetParamP( sText, vnDPar[i], vdPar[i])) {
string sOut = " Info : P" + ToString( vnDPar[i], 2) + " missing in Process (" + sProcType +
") on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_DBG_INFO( GetEExLogger(), sOut.c_str())
}
}
// leggo l'eventuale parametro stringa
if ( nSPar != 0) {
if ( ! GetParamP( sText, nSPar, sPar)) {
string sOut = " Info : P" + ToString( nSPar, 2) + " missing in Process (" + sProcType +
") on line " + ToString( m_theScanner.GetCurrLineNbr()) ;
LOG_DBG_INFO( GetEExLogger(), sOut.c_str())
}
}
return true ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::GetInfo( const string& sText, const string& sPar, string& sVal)
{
// cerco l'identificativo del parametro
size_t nPos = sText.find( sPar + ":") ;
if ( nPos == string::npos)
return false ;
// recupero la stringa successiva
const int SVAL_LEN = 6 ;
sVal = sText.substr( nPos + sPar.length() + 1, SVAL_LEN) ;
Trim( sVal, " \t\r\n0") ;
return true ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::GetInfo( const string& sText, const string& sPar, int& nVal)
{
string sVal ;
if ( ! GetInfo( sText, sPar, sVal))
return false ;
nVal = 0 ;
FromString( sVal, nVal) ;
return true ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::GetParam( const string& sPar, double& dVal)
{
string sVal = sPar ;
TrimLeft( sVal, " \t\r\n0") ;
dVal = 0 ;
FromString( sVal, dVal) ;
dVal *= m_dScale ;
return true ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::GetParam( const string& sText, const string& sPar, int& nVal)
{
// leggo il parametro
double dVal ;
bool bOk = GetParam( sText, sPar, dVal) ;
nVal = lround( dVal / m_dScale) ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::GetParam( const string& sText, const string& sPar, double& dVal)
{
// cerco l'identificativo del parametro
size_t nPos = sText.find( sPar + ":") ;
if ( nPos == string::npos)
return false ;
// recupero la stringa successiva
const int SVAL_LEN = 14 ;
string sVal = sText.substr( nPos + sPar.length() + 1, SVAL_LEN) ;
TrimLeft( sVal, " \t\r\n0") ;
dVal = 0 ;
FromString( sVal, dVal) ;
dVal *= m_dScale ;
return true ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::GetParam( const string& sText, const string& sPar, string& sVal)
{
// cerco l'identificativo del parametro
size_t nPos = sText.find( sPar + ":") ;
if ( nPos == string::npos)
return false ;
// cerco i delimitatori della stringa "
size_t nPosI = sText.find( "\"", nPos + sPar.length() + 1) ;
size_t nPosF = sText.find( "\"", nPosI + 1) ;
if ( nPosI != string::npos && nPosF != string::npos) {
sVal = sText.substr( nPosI + 1, nPosF - nPosI - 1) ;
return true ;
}
else {
sVal = sText.substr( nPos + sPar.length() + 1) ;
Trim( sVal, " \t\r\n\"") ;
return true ;
}
}
//----------------------------------------------------------------------------
bool
ImportBtl::GetParamP( const string& sText, int nInd, int& nVal)
{
// verifico se dummy
if ( nInd < 0)
return true ;
// creo l'identificativo
string sPar = PAR_P + ToString( nInd, 2) ;
// leggo il parametro
double dVal = 0 ;
bool bOk = GetParam( sText, sPar, dVal) ;
nVal = lround( dVal) ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::GetParamP( const string& sText, int nInd, double& dVal)
{
// verifico se dummy
if ( nInd < 0)
return true ;
// creo l'identificativo
string sPar = PAR_P + ToString( nInd, 2) ;
// leggo il parametro
return GetParam( sText, sPar, dVal) ;
}
//----------------------------------------------------------------------------
bool
ImportBtl::GetParamP( const string& sText, int nInd, string& sVal)
{
// verifico se dummy
if ( nInd < 0)
return true ;
// creo l'identificativo
string sPar = PAR_P + ToString( nInd, 2) ;
// leggo il parametro
return GetParam( sText, sPar, sVal) ;
}