Files
EgtExchange/ImportBtlx.cpp
Dario Sassi 9577795c73 EgtExchange 3.1a2 :
- per BTL aggiunta possibilità di gestione geometrica del PARTOFFSET (controllata da flag).
2026-01-23 18:53:20 +01:00

1497 lines
60 KiB
C++

//---------------------------------------------------------------------------
// EgalTech 2020-2020
//---------------------------------------------------------------------------
// File : ImportBtlx.cpp Data : 14.12.20 Versione : 2.3a6
// Contenuto : Implementazione della classe per l'importazione BTLx.
//
//
//
// Modifiche : 14.12.20 DS Creazione modulo.
//
//
//---------------------------------------------------------------------------
//-------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "pugixml.hpp"
#include "ImportBtlx.h"
#include "DllMain.h"
#include "/EgtDev/Include/EExDllMain.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EgtKeyCodes.h"
#include "/EgtDev/Include/EgtNumUtils.h"
#include "/EgtDev/Include/EgtStringConverter.h"
using namespace std ;
//---------------------------------------------------------
STRVECTOR ProjectAttributes = { "Architect", "Comment", "Customer", "DeliveryDate", "Editor", "ListName", "Name", "Number", "Section",
"SourceFile"} ;
STRVECTOR ProjectAttributes_other = { "GUID", "ProcessingQuality", "Recess"} ;
STRVECTOR PartAttributes = { "Annotation", "AssemblyNumber", "Comment", "ElementNumber", "EndOffset", "Group", "Layer", "Material",
"ModuleNumber", "OrderNumber", "Package", "PlaningLength", "QualityGrade", "StartOffset",
"Storey", "TimberGrade", "Weight"} ;
STRVECTOR PartAttributes_other = { "Count", "Designation", "Height", "Length", "ProcessingQuality", "Recess", "SingleMemberNumber",
"StoreyType", "Width"} ;
STRVECTOR svMaterials{ "batten", "cladding", "massiveTimber", "membrane", "gypsumBoard", "gypsumFibre", "insulation", "sheetComponent",
"facadePanel", "profiledPanel", "plaster"} ;
//----------------------------------------------------------------------------
IImportBtlx*
CreateImportBtlx( void)
{
// verifico la chiave e le opzioni
if ( ! VerifyKey( KEYOPT_EEX_INPADV))
return nullptr ;
// creo l'oggetto
return static_cast<IImportBtlx*> ( new(nothrow) ImportBtlx) ;
}
//----------------------------------------------------------------------------
ImportBtlx::ImportBtlx( void)
{
}
//----------------------------------------------------------------------------
bool
ImportBtlx::Import( const string& sFile, IGeomDB* pGDB, int nFlag)
{
// log di informazioni
LOG_INFO( GetEExLogger(), ( "ImportBtlx : " + sFile).c_str()) ;
// 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) ;
bool bPartOffset = (( nFlag & EIBFLAG_PARTOFFSET) != 0) ;
if ( ! m_BtlGeom.Init( pGDB, nFlatVertPos, bSpecialTrim, bTrimWithOutline, bUseUAttr, bPartOffset, true)) {
LOG_ERROR( GetEExLogger(), " Error on BtlGeom.Init") ;
return false ;
}
// scrivo nel progetto path del file
m_BtlGeom.SetUserAttribute( UATD_INFO, IKEY_BTL_PATH + ":" + sFile) ;
// inizializzo il documento
pugi::xml_document doc ;
pugi::xml_parse_result ParseResult = doc.load_file( stringtoW( sFile)) ;
if ( ! ParseResult) {
string sError = " Error parsing file : " ;
sError += ParseResult.description() ;
LOG_ERROR( GetEExLogger(), sError.c_str()) ;
return false ;
}
// ------------- Nodo BTLX ---------------------------------
pugi::xml_node rootNode = doc.first_child() ;
string sLanguage = rootNode.attribute( "Language").value() ;
if ( sLanguage != "")
m_BtlGeom.SetUserAttribute( UATD_INFO, "Language", rootNode.attribute( "Language").value()) ;
if ( rootNode.attribute( "Version") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading BTLX : unknown version of BTLX") ;
return false ;
}
m_sVersion = rootNode.attribute( "Version").value() ;
// ---------- Nodo FileHistory --------------------------------
pugi::xml_node fileHistory = rootNode.child( "FileHistory") ;
if ( fileHistory != nullptr)
if ( ! ReadFileHistory( fileHistory))
return false ;
// ----------- Nodo Project ----------------------------------------
pugi::xml_node projectNode = rootNode.child( "Project") ;
if ( projectNode == nullptr) {
LOG_ERROR( GetEExLogger(), "Error Reading BTLX: no Project") ;
return false ;
}
// Lettura attributes
if ( ! ReadProjectAttributes( projectNode.first_attribute()))
return false ;
// Analisi dei sottonodi
int nParts = 0 ; // conto i pezzi del progetto
for ( pugi::xml_node_iterator itProject = projectNode.begin() ; itProject != projectNode.end() ; ++itProject) {
string sChildName = itProject->name() ;
if ( sChildName == "Parts") {
for ( pugi::xml_node_iterator itParts = itProject->begin() ; itParts != itProject->end() ; ++itParts) {
nParts ++ ;
if ( ! ReadPart( *itParts))
return false ;
}
}
else if ( sChildName == "UserAttributes") {
if ( ! ReadUserAttributes( *itProject, 0))
return false ;
}
else if ( sChildName == "Rawparts") {
/////////
}
else if ( sChildName == "Composites") {
//////////
}
else {
LOG_ERROR( GetEExLogger(), " Error Reading Project : unknown node") ;
}
}
if ( nParts == 0) {
LOG_ERROR( GetEExLogger(), " Error Reading Project: no Parts") ;
return false ;
}
return true ;
}
//-----------------------------------------------------------------
bool
ImportBtlx::ReadFileHistory( pugi::xml_node node)
{
// Scorro tutti i sottonodi
for ( pugi::xml_node_iterator it = node.begin() ; it != node.end() ; it ++) {
string sNodeName = it->name() ;
// salvo gli attributes
for ( pugi::xml_attribute attr = it->first_attribute() ; attr ; attr = attr.next_attribute()) {
string sName = attr.name() ;
string sValue = attr.value() ;
if ( sName != "" && sValue != "") {
if ( sNodeName == "InitialExportProgram")
sName = "InitialExport - " + sName ;
else if ( sNodeName == "EditingProgram")
sName = "Editing - " + sName ;
else {
LOG_ERROR( GetEExLogger(), " Error Reading File History: unknown node") ;
return false ;
}
bool bAddOk = m_BtlGeom.SetUserAttribute( UATD_INFO, sName, sValue) ;
if ( ! bAddOk){
LOG_ERROR( GetEExLogger(), " Error Reading File History: m_BtlGeom.SetUserAttribute error") ;
return false ;
}
}
}
}
return true ;
}
//-----------------------------------------------------------------
bool
ImportBtlx::ReadProjectAttributes( pugi::xml_attribute attr)
{
// Scorro tutti gli attributes
while ( attr) {
bool bAddOk = true ;
string sName = attr.name() ;
string sValue = attr.value() ;
if ( find( ProjectAttributes.begin(), ProjectAttributes.end(), sName) != ProjectAttributes.end()) {
if ( sValue != "") // aggiungo solo se non è vuoto
bAddOk = m_BtlGeom.SetUserAttribute( UATD_INFO, attr.name(), attr.value()) ;
}
// Tratto gli attributes che necessitano di check sui valori :
else if ( find( ProjectAttributes_other.begin(), ProjectAttributes_other.end(), sName) != ProjectAttributes_other.end()) {
if ( sName == "GUID") {
if ( CheckGuid( attr.value()))
bAddOk = m_BtlGeom.SetUserAttribute( UATD_INFO, attr.name(), attr.value()) ;
else
LOG_ERROR( GetEExLogger(), " Error reading Project : GUID wrong") ;
}
else if ( sName == "ProcessingQuality") {
if ( sValue == "automatic" || sValue == "fast" || sValue == "visible")
bAddOk = m_BtlGeom.SetUserAttribute( UATD_INFO, attr.name(), attr.value()) ;
else {
LOG_ERROR( GetEExLogger(), " Error reading Project : unknown ProcessingQuality attribute value") ;
return false ;
}
}
else if ( sName == "Recess") {
if ( sValue == "automatic" || sValue == "manual")
bAddOk = m_BtlGeom.SetUserAttribute( UATD_INFO, attr.name(), attr.value()) ;
else {
LOG_ERROR( GetEExLogger(), " Error reading Project : unknown Recess attribute value") ;
return false ;
}
}
}
else {
string sError = " Warning reading Project : " + sName + " attribute is unknown" ;
LOG_ERROR( GetEExLogger(), sError.c_str()) ;
}
if ( ! bAddOk) {
LOG_ERROR( GetEExLogger(), " Error reading Project : BtlGeom.SetUserAttribute error") ;
return false ;
}
attr = attr.next_attribute() ;
}
return true ;
}
//-----------------------------------------------------------
bool
ImportBtlx::ReadUserAttributes(pugi::xml_node node, int nCaller, STRVECTOR* pvsAttr)
{
bool bAddOk = true ;
for ( pugi::xml_node_iterator it = node.begin() ; it != node.end() ; it ++) {
// verifico che abbia i due attributi richiesti
if ( it->attribute( "Name") == nullptr || it->attribute( "Value") == nullptr)
LOG_ERROR( GetEExLogger(), " Error reading UserAttribute : missing required attribute") ;
string sName = it->attribute( "Name").value() ;
string sValue = it->attribute( "Value").value() ;
if ( sName == "" || sValue == "") {
LOG_ERROR( GetEExLogger(), " Error reading UserAttribute : attribute is empty") ;
return false ;
}
if ( nCaller == 0) // chiamata dal nodo project
bAddOk = m_BtlGeom.SetUserAttribute( UATD_INFO, sName, sValue) ;
else if ( nCaller == 1) // chiamata dal nodo part
bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, sName, sValue) ;
else if ( nCaller == 2) { // chiamata da processing
if ( pvsAttr == nullptr)
LOG_ERROR( GetEExLogger(), " Error reading UserAttribute : missing UserAttribute vector")
else
pvsAttr->emplace_back( sName + ":" + sValue) ;
}
if ( ! bAddOk)
LOG_ERROR( GetEExLogger(), " Error reading UserAttribute : BtlGeom.SetUserAttribute error" ) ;
}
return true ;
}
//------------------------------------------------------------------------------------
bool
ImportBtlx::ReadPart( pugi::xml_node node)
{
// Creo la parte nel BTLGeom
if ( ! m_BtlGeom.CreatePart()) {
LOG_ERROR( GetEExLogger(), " Error reading Part : m_BtlGeom.CreatePart error") ;
return false ;
}
// Analisi Attributes
if ( ! ReadPartAttributes( node.first_attribute())){
return false ;
}
// Analisi nodi
for ( pugi::xml_node_iterator it = node.begin() ; it != node.end() ; it ++) {
string sName = it->name() ;
// Camber
if ( sName == "Camber") {
if ( ! ReadCamber( *it))
return false ;
}
// Alignment
else if ( sName == "Alignment") {
if ( ! ReadAlignment( *it))
return false ;
}
// PartOffset
else if ( sName == "PartOffset") {
if ( ! ReadPartOffset( *it))
return false ;
}
// UserAttributes
else if ( sName == "UserAttributes") {
if ( ! ReadUserAttributes( *it, 1))
return false ;
}
// Processings
else if ( sName == "Processings") {
if ( ! ReadProcessings( *it))
return false ;
}
// Colour
else if ( sName == "Colour") {
Color colRes ;
// Controllo ci siano tutti i required attributes
if ( it->attribute( "Red") == nullptr || it->attribute( "Green") == nullptr ||
it->attribute( "Blue") == nullptr || it->attribute( "Transparency") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Color: attribute missing") ;
return false ;
}
int nRed = Clamp( it->attribute( "Red").as_int(), 0, 255) ;
int nGreen = Clamp( it->attribute( "Green").as_int(), 0, 255) ;
int nBlue = Clamp( it->attribute( "Blue").as_int(), 0, 255) ;
int nAlpha = Clamp( it->attribute( "Transparency").as_int(), 0, 255) ;
nAlpha = nAlpha * 100 / 255 ; // va scalato su 100 non su 255
colRes.Set( nRed, nGreen, nBlue, nAlpha) ;
bool bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, sName, ToString( colRes)) ;
if ( ! bAddOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part Color : m_BtlGeom.SetUserAttribute error") ;
return false ;
}
}
// Transformations
else if ( sName == "Transformations") {
// Leggo tutte le trasformazioni
for ( pugi::xml_node_iterator itTransf = it->begin() ; itTransf != it->end() ; itTransf ++) {
string sNameTransf = itTransf->name() ;
if ( sNameTransf != "Transformation") {
LOG_ERROR( GetEExLogger(), " Error reading Part Transformation : unknown transformation child") ;
return false ;
}
if ( ! ReadTransformation( *itTransf))
return false ;
}
}
// Outlines
else if ( sName == "Outlines") {
int nCnt = 0 ;
// Analizzo tutti gli outlines
for ( pugi::xml_node_iterator itOutline = it->begin() ; itOutline != it->end() ; itOutline++) {
if ( nCnt > 3) { // possono essere massimo 3
LOG_ERROR( GetEExLogger(), " Error reading Part Outline: more than 3 outlines") ;
return false ;
}
string sOutlineName = itOutline->name() ;
if ( sOutlineName != "Outline") {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline: unknown child") ;
return false ;
}
if ( ! ReadOutline( *itOutline))
return false ;
nCnt ++ ;
}
}
// UserReferencePlane
else if ( sName == "UserReferencePlanes") {
for ( pugi::xml_node_iterator itURefPlanes = it->begin() ; itURefPlanes != it->end() ; itURefPlanes ++ ) {
string sNameURefPlanes = itURefPlanes->name() ;
if ( sNameURefPlanes != "UserReferencePlane") {
LOG_ERROR( GetEExLogger(), " Error reading Part : unknown UserPlane child") ;
return false ;
}
if ( ! ReadUserReferencePlane( *itURefPlanes))
return false ;
}
}
// GrainDirection
else if ( sName == "GrainDirection") {
Vector3d vtDir ;
if ( it->attribute( "X") == nullptr || it->attribute( "Y") == nullptr || it->attribute( "Z") == nullptr ||
it->attribute( "Align") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part : GrainDirection attribute missing") ;
return false ;
}
vtDir.x = it->attribute( "X").as_double() ;
vtDir.y = it->attribute( "Y").as_double() ;
vtDir.z = it->attribute( "Z").as_double() ;
string sAlign = it->attribute( "Align").value() ;
if ( sAlign == "yes")
sAlign = "1" ;
else if ( sAlign == "no")
sAlign = "0" ;
else {
LOG_ERROR( GetEExLogger(), " Error reading Part : GrainDirection align is unknown") ;
return false ;
}
bool bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, "GRAINDIRECTION", ToString( vtDir) + ";" + sAlign) ;
if ( ! bAddOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part GrainDirection : m_BtlGeom.SetUserAttribute error") ;
return false ;
}
}
// MaterialClass
else if ( sName == "MaterialClass") {
string sMaterial = it->attribute( "Group").value() ;
string sSpecification = it ->attribute( "Specification").value() ;
if ( find( svMaterials.begin(), svMaterials.end(), sMaterial) == svMaterials.end()) {
LOG_ERROR( GetEExLogger(), " Error reading Part : MaterialClass group is unknown") ;
return false ;
}
bool bAddOk = false ;
if ( sSpecification != "")
bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, "MATERIALTYPE", sMaterial + ": " + sSpecification) ;
else
bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, "MATERIALTYPE", sMaterial) ;
if ( ! bAddOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part : m_BtlGeom.SetUserAttribute error") ;
return false ;
}
}
// UserAttribute
else if ( sName == "UserAttribute") {
if ( it->attribute( "Name") == nullptr || it->attribute( "")== nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part : UserAttribute attribute missing") ;
return false ;
}
string sName = it->attribute( "Name").value() ;
string sValue = it ->attribute( "Value").value() ;
bool bAddOk = true ;
if ( sName != "" && sValue != "")
bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, sName, sValue) ;
if ( ! bAddOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part : m_BtlGeom.SetUserAttribute error") ;
return false ;
}
}
// ReferenceSide
else if ( sName == "ReferenceSide") {
// Controllo ci siano i required attributes
if ( it->attribute( "Side") == nullptr || it->attribute( "Align") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part : ReferenceSide attribute missing") ;
return false ;
}
// Controllo che i valori siano sensati
int nSide = it->attribute( "Side").as_int() ;
if ( nSide < 1 || nSide > 4) {
LOG_ERROR( GetEExLogger(), " Error reading Part : ReferenceSide Side not valid") ;
return false ;
}
string sAlign = it->attribute( "Align").value() ;
if ( sAlign == "yes" )
sAlign = "1" ;
else if ( sAlign == "no")
sAlign = "0" ;
else {
LOG_ERROR( GetEExLogger(), " Error reading Part : ReferenceSide Align not valid") ;
return false ;
}
bool bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, "REFERENCESIDE", to_string( nSide) + ";" + sAlign) ;
if ( ! bAddOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part : m_BtlGeom.SetUserAttribute error") ;
return false ;
}
}
// Shape
else if ( sName == "Shape") {
if ( ! ReadShape( *it))
return false ;
}
}
// inserisco eventuali contorni liberi
if ( ! m_BtlGeom.CreateFreeContours()) {
LOG_ERROR ( GetEExLogger(), " Error reading Part : BtlGeom.CreateFreeContours()") ;
return false ;
}
// Outline
if ( ! m_BtlGeom.UpdateOutLine()) {
LOG_ERROR( GetEExLogger(), " Error reading Part : BtlGeom.UpdateOutLine error") ;
m_BtlGeom.ErasePart() ;
return false ;
}
return true ;
}
//-----------------------------------------------------------------------------
bool
ImportBtlx::ReadPartAttributes( pugi::xml_attribute attr)
{
bool bLength = false, bWidth = false, bHeight = false ;
double dLength, dWidth, dHeight ;
// scorro tutti gli attributes
while ( attr) {
bool bAddOk = true ;
string sName = attr.name() ;
string sValue = attr.value() ;
if ( find( PartAttributes.begin(), PartAttributes.end(), sName) != PartAttributes.end()) {
if ( sValue != "") // aggiungo solo se non è vuoto
bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, attr.name(), attr.value()) ;
}
else if ( find( PartAttributes_other.begin(), PartAttributes_other.end(), sName) != PartAttributes_other.end()) {
if ( sName == "Count")
m_BtlGeom.SetPartCount( attr.as_int()) ;
else if ( sName == "Designation")
m_BtlGeom.SetPartName( sValue) ;
else if ( sName == "SingleMemberNumber")
m_BtlGeom.SetPartProdNbr( attr.as_int()) ;
else if ( sName == "Length") {
dLength = attr.as_double() ;
bLength = true ;
}
else if ( sName == "Width") {
dWidth = attr.as_double() ;
bWidth = true ;
}
else if ( sName == "Height") {
dHeight = attr.as_double() ;
bHeight = true ;
}
else if ( sName == "ProcessingQuality") {
if ( sValue == "automatic" || sValue == "fast" || sValue == "visible")
bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, attr.name(), attr.value()) ;
else {
LOG_ERROR( GetEExLogger(), " Error reading Part : unknown ProcessingQuality attribute value") ;
return false ;
}
}
else if ( sName == "Recess") {
if ( sValue == "automatic" || sValue == "manual")
bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, attr.name(), attr.value()) ;
else {
LOG_ERROR( GetEExLogger(), " Error reading Part : unknown Recess attribute value") ;
return false ;
}
}
else if ( sName == "StoreyType") {
if ( sValue == "" || sValue == "ceiling" || sValue == "roof" || sValue == "wall")
bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, attr.name(), attr.value()) ;
else {
LOG_ERROR( GetEExLogger(), " Error reading Part : unknown StoreyType attribute value") ;
return false ;
}
}
}
else {
LOG_ERROR( GetEExLogger(), " Error reading Part : unknown attribute") ;
}
if ( ! bAddOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part : BtlGeom.SetUserAttribute error") ;
return false ;
}
attr = attr.next_attribute() ;
}
// Creo il box
if ( bLength && bWidth && bHeight) {
if ( ! m_BtlGeom.AddPartBox( dLength, dHeight, dWidth)) {
LOG_ERROR( GetEExLogger(), " Error reading Part : BtlGeom.AddPartBox error") ;
return false ;
}
}
else {
LOG_ERROR( GetEExLogger(), " Error reading Part : no box") ;
m_BtlGeom.ErasePart() ;
return false ;
}
return true ;
}
//--------------------------------------------------------------------
bool
ImportBtlx::ReadCamber( pugi::xml_node node)
{
bool bAddOk = false ;
string sValue, sVal ;
sVal = node.attribute( "ReferencePlaneID").value() ;
if ( sVal == "") {
LOG_ERROR( GetEExLogger(), " Error reading Part camber : Reference Plane missing") ;
return false ;
}
sValue = "SIDE:" + sVal ;
sVal = node.attribute( "StartingPoint").value() ;
if ( sVal == "") {
LOG_ERROR( GetEExLogger(), " Error reading Part camber : StartingPoint missing") ;
return false ;
}
sValue += " P01:" + sVal ;
sVal = node.attribute( "EndPoint").value() ;
if ( sVal == "") {
LOG_ERROR( GetEExLogger(), " Error reading Part camber : EndPoint missing") ;
return false ;
}
sValue += " P02:" + sVal ;
sVal = node.attribute( "CamberPoint").value() ;
if ( sVal == "") {
LOG_ERROR( GetEExLogger(), " Error reading Part camber : CamberPoint missing") ;
return false ;
}
sValue += " P03:" + sVal ;
sVal = node.attribute( "Camber").value() ;
if ( sVal == "") {
LOG_ERROR( GetEExLogger(), " Error reading Part camber : Camber missing") ;
return false ;
}
sValue += " P04:" + sVal ;
bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, "CAMBER", sValue) ;
if ( ! bAddOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part camber : m_BtlGeom.SetUserAttribute error") ;
return false ;
}
return true ;
}
//--------------------------------------------------------------------
bool
ImportBtlx::ReadAlignment( pugi::xml_node node)
{
// Controllo che ci siano tutti gli attributes
string sValue ;
string sLocation = node.attribute( "Location").value() ;
string sEndType = node.attribute( "Endtype").value() ;
// Location Type
if ( sLocation == "") {
LOG_ERROR( GetEExLogger(), " Error reading Part Alignment: LocationType missing") ;
return false ;
}
else if ( sLocation == "bottomRail")
sValue = "BR: " ;
else if ( sLocation == "topRail")
sValue = "TR: " ;
else if ( sLocation == "bottomRailAngled")
sValue = "BA: " ;
else if ( sLocation == "topRailAngled")
sValue = "TA: " ;
else if ( sLocation == "horizontalComponent")
sValue = "HC: " ;
else if ( sLocation == "verticalComponent")
sValue = "VC: " ;
else if ( sLocation == "angledComponent")
sValue = "AC: " ;
else {
LOG_ERROR( GetEExLogger(), " Error reading Part Alignment: LocationType unknown") ;
return false ;
}
// EndType
if ( sEndType == "") {
LOG_ERROR( GetEExLogger(), " Error reading Part Alignment: EndType missing") ;
return false ;
}
else if ( sEndType == "rectangularCut")
sValue += "R" ;
else if ( sEndType == "angledCut")
sValue += "A" ;
else if ( sEndType == "doubleCut")
sValue += "D" ;
else {
LOG_ERROR( GetEExLogger(), " Error reading Part Alignment: Endtype unknown") ;
return false ;
}
bool bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, "ALIGNMENT", sValue) ;
if ( ! bAddOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part camber : m_BtlGeom.SetUserAttribute error") ;
return false ;
}
return true ;
}
//-------------------------------------------------------------------
bool
ImportBtlx::ReadPartOffset( pugi::xml_node node)
{
// controllo ci siano i required attributes:
if ( node.attribute( "FlushSide") == nullptr ) {
LOG_ERROR( GetEExLogger(), " Error reading Part PartOffset : flush side missing") ;
return false ;
}
// Controllo sui valori :
if ( node.attribute( "FlushSide").as_int() > 4 || node.attribute( "FlushSide").as_int() < 1) {
LOG_ERROR( GetEExLogger(), " Error reading Part PartOffset : flush side value is wrong") ;
return false ;
}
string sValue = "P04:" + to_string( node.attribute( "FlushSide").as_int()) ;
sValue += " P11:" + to_string( node.attribute( "OffsetSide1").as_double()) ;
sValue += " P12:" + to_string( node.attribute( "OffsetSide2").as_double()) ;
sValue += " P13:" + to_string( node.attribute( "OffsetSide3").as_double()) ;
sValue += " P14:" + to_string( node.attribute( "OffsetSide4").as_double()) ;
bool bAddOk = m_BtlGeom.SetUserAttribute( UATD_PART, "PARTOFFSET", sValue) ;
if ( ! bAddOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part Color : m_BtlGeom.SetUserAttribute error") ;
return false ;
}
return true ;
}
//--------------------------------------------------------------------
bool
ImportBtlx::ReadTransformation( pugi::xml_node node)
{
// ID
if ( node.attribute( "GUID") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Transformation : GUID missing") ;
return false ;
}
string sGuid ;
if ( CheckGuid( node.attribute( "GUID").value()))
sGuid = node.attribute( "GUID").value() ;
else {
LOG_ERROR( GetEExLogger(), " Error reading Part Transformation : GUID wrong") ;
return false ;
}
// Origine
pugi::xml_node origin = node.child( "Position").child( "ReferencePoint") ;
if ( origin == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Transformation : Origin missing") ;
return false ;
}
if ( origin.attribute( "X") == nullptr || origin.attribute( "Y") == nullptr || origin.attribute( "Z") == nullptr){
LOG_ERROR( GetEExLogger(), " Error reading Part Transformation : Origin component missing") ;
return false ;
}
Point3d ptO( origin.attribute( "X").as_double(), origin.attribute( "Y").as_double(), origin.attribute( "Z").as_double()) ;
// Asse X
pugi::xml_node axisX = node.child( "Position").child( "XVector") ;
if ( axisX == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Transformation : X axis missing") ;
return false ;
}
if ( axisX.attribute( "X") == nullptr || axisX.attribute( "Y") == nullptr || axisX.attribute( "Z") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Transformation : X axis component missing") ;
return false ;
}
Vector3d vtX( axisX.attribute( "X").as_double(), axisX.attribute( "Y").as_double(), axisX.attribute( "Z").as_double()) ;
// Asse Y
pugi::xml_node axisY = node.child( "Position").child( "YVector") ;
if ( axisY == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Transformation : Y axis missing") ;
return false ;
}
if ( axisY.attribute( "X") == nullptr || axisY.attribute( "Y") == nullptr || axisY.attribute( "Z") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Transformation : Y axis component missing") ;
return false ;
}
Vector3d vtY( axisY.attribute( "X").as_double(), axisY.attribute( "Y").as_double(), axisY.attribute( "Z").as_double()) ;
Frame3d frRef ;
frRef.Set( ptO, ptO + vtX, ptO + vtY) ;
if ( ! m_BtlGeom.AddPartTransformation( sGuid, frRef)) {
LOG_ERROR( GetEExLogger(), " Error reading Part Transformation : BtlGeom.AddPartTransformation error") ;
return false ;
}
return true ;
}
//-----------------------------------------------------------------------------
bool
ImportBtlx::CheckGuid( const string& s)
{
vector<char> range = {'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} ;
if ( s[0] != '{' || s[37] != '}')
return false ;
for ( int i = 1 ; i < 37 ; i++) {
if ( i == 9 || i == 14 || i == 19 || i == 24) {
if ( s[i] != '-')
return false ;
}
else
if ( find( range.begin(), range.end(), s[i]) == range.end())
return false ;
}
return true ;
}
//--------------------------------------------------------------------
bool
ImportBtlx::ReadOutline( pugi::xml_node node)
{
FCEDEQUE dqFce ;
STRVECTOR vsUAtt ;
if ( node.attribute( "ReferencePlaneID") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline : missing reference plane") ;
return false ;
}
int nSide = node.attribute( "ReferencePlaneID").as_int() ;
if ( node.attribute( "Process") != nullptr) {
string Process = node.attribute("Process").value() ;
if ( Process == "no")
vsUAtt.emplace_back( "DO:0") ;
}
if ( node.child( "Contour") == nullptr && node.child( "DualContour") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline : no contour is defined") ;
return false ;
}
for ( pugi::xml_node_iterator it = node.begin() ; it != node.end() ; it ++) {
string sName = it->name() ;
if ( sName == "Contour") {
dqFce.clear() ;
if ( ! ReadContour( *it, dqFce, FreeContourEnt::START))
return false ;
if ( ! m_BtlGeom.AddPartOutline( nSide, dqFce, 0, 0, 0.0, vsUAtt)) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline : BtlGeom.AddPartOutline error") ;
return false ;
}
}
else if ( sName == "DualContour") {
dqFce.clear() ;
if ( ! ReadDualContour( *it, dqFce))
return false ;
if ( ! m_BtlGeom.AddPartOutline( nSide, dqFce, 0, 0, 0.0, vsUAtt)) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline : BtlGeom.AddPartOutline error") ;
return false ;
}
}
else if ( sName == "Apertures") {
// analizzo tutti i sottonodi di tipo "Aperture"
for ( pugi::xml_node_iterator itAperture = it->begin() ; itAperture != it->end() ; itAperture++) {
string sApertureName = itAperture->name() ;
if ( sApertureName != "Aperture") {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline : Apertures unknown child") ;
return false ;
}
if ( ! ReadAperture( *itAperture, nSide))
return false ;
}
}
else {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline : unknown child") ;
return false ;
}
}
return true ;
}
//---------------------------------------------------------------------------
bool
ImportBtlx::ReadContour( pugi::xml_node node, FCEDEQUE& dqFce, FreeContourEnt::TYPE type)
{
Point3d PtP, PtM ;
double dAng = 0.0 ;
if ( node.child( "StartPoint") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline Contour: StartPoint Missing") ;
return false ;
}
for ( pugi::xml_node_iterator it = node.begin() ; it != node.end() ; it ++) {
string sName = it->name() ;
// Punto di inizio
if ( sName == "StartPoint") {
if ( it->attribute( "X") == nullptr ||
it->attribute( "Y") == nullptr ||
it->attribute( "Z") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline Contour: StartPoint component missing") ;
return false ;
}
PtP.x = node.child( "StartPoint").attribute( "X").as_double() ;
PtP.y = node.child( "StartPoint").attribute( "Y").as_double() ;
PtP.z = node.child( "StartPoint").attribute( "Z").as_double() ;
dqFce.emplace_back( type, PtP, Point3d(), 0.0, 0, 0) ;
}
// Line
else if ( sName == "Line") {
if ( it->attribute( "Inclination") == nullptr)
dAng = 0.0 ;
else
dAng = Clamp( it->attribute( "Inclination").as_double(), -89.9, 89.9) ;
if ( it->child( "EndPoint") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline Contour: Line EndPoint missing") ;
return false ;
}
if ( it->child( "EndPoint").attribute( "X") == nullptr ||
it->child( "EndPoint").attribute( "Y") == nullptr ||
it->child( "EndPoint").attribute( "Z") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline Contour: Line component missing") ;
return false ;
}
PtP.x = it->child( "EndPoint").attribute( "X").as_double() ;
PtP.y = it->child( "EndPoint").attribute( "Y").as_double() ;
PtP.z = it->child( "EndPoint").attribute( "Z").as_double() ;
dqFce.emplace_back( FreeContourEnt::LINE, PtP, Point3d(), dAng, 0, 0) ;
}
// Arc
else if ( sName == "Arc") {
if ( it->attribute( "Inclination") == nullptr)
dAng = 0.0 ;
else
dAng = Clamp( it->attribute( "Inclination").as_double(), -89.9, 89.9) ;
if ( it->child( "EndPoint") == nullptr || it->child( "PointOnArc") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline Contour: Arc Point missing") ;
return false ;
}
if ( it->child( "EndPoint").attribute( "X") == nullptr ||
it->child( "EndPoint").attribute( "Y") == nullptr ||
it->child( "EndPoint").attribute( "Z") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline Contour: Arc component missing") ;
return false ;
}
PtP.x = it->child( "EndPoint").attribute( "X").as_double() ;
PtP.y = it->child( "EndPoint").attribute( "Y").as_double() ;
PtP.z = it->child( "EndPoint").attribute( "Z").as_double() ;
if ( it->child( "PointOnArc").attribute( "X") == nullptr ||
it->child( "PointOnArc").attribute( "Y") == nullptr ||
it->child( "PointOnArc").attribute( "Z") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline Contour: Arc component missing") ;
return false ;
}
PtM.x = it->child( "PointOnArc").attribute( "X").as_double() ;
PtM.y = it->child( "PointOnArc").attribute( "Y").as_double() ;
PtM.z = it->child( "PointOnArc").attribute( "Z").as_double() ;
dqFce.emplace_back( FreeContourEnt::LINE, PtP, PtM, dAng, 0, 0) ;
}
// Altrimenti errore
else {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline Contour: unknown child") ;
return false ;
}
}
return true ;
}
//---------------------------------------------------------------------------
bool
ImportBtlx::ReadDualContour( pugi::xml_node node, FCEDEQUE& dqFce)
{
// I due contour riempiono lo stesso vettore dqFace
if ( node.child( "PrincipalContour") == nullptr || node.child( "AssociatedContour") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline : DualContour contours missing") ;
return false ;
}
// Principal Contour
if ( ! ReadContour( node.child( "PrincipalContour"), dqFce, FreeContourEnt::START_CNT0))
return false ;
// Associated Contour
if ( ! ReadContour( node.child( "AssociatedContour"), dqFce, FreeContourEnt::START_CNT1))
return false ;
return true ;
}
//---------------------------------------------------------------------------
bool
ImportBtlx::ReadAperture( pugi::xml_node node, int nSide)
{
// Attribute Aperture
STRVECTOR vsUAttAperture ;
if ( node.attribute( "Process") != nullptr) {
string Process = node.attribute( "Process").value() ;
if ( Process == "no")
vsUAttAperture.emplace_back( "DO:0") ;
}
// ChildAperture sono i contour
for ( pugi::xml_node_iterator it = node.begin() ; it != node.end() ; it++) {
string sName = it->name() ;
if ( sName == "Contour") {
FCEDEQUE dqFce ;
if ( ! ReadContour( *it, dqFce, FreeContourEnt::START))
return false ;
if ( ! m_BtlGeom.AddPartAperture( nSide, dqFce, 0, 0, 0.0, vsUAttAperture)) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline : BtlGeom.AddPartAperture error") ;
return false ;
}
}
else if ( sName == "DualContour") {
FCEDEQUE dqFce ;
if ( ! ReadDualContour( *it, dqFce))
return false ;
if ( ! m_BtlGeom.AddPartAperture( nSide, dqFce, 0, 0, 0.0, vsUAttAperture)) {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline : BtlGeom.AddPartAperture error") ;
return false ;
}
}
else {
LOG_ERROR( GetEExLogger(), " Error reading Part Outline : Aperture child unknown") ;
return false ;
}
}
return true ;
}
//-----------------------------------------------------------------------------
bool
ImportBtlx::ReadUserReferencePlane( pugi::xml_node node)
{
if ( node.attribute( "ID") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part ReferencePlane : ID missing") ;
return false ;
}
int nId = node.attribute( "ID").as_int() ;
if ( node.child( "Position") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part ReferencePlane : Position missing") ;
return false ;
}
Point3d ptOrig ;
Vector3d vX, vY ;
// Origin
if ( node.child( "Position").child( "ReferencePoint") == nullptr ||
node.child( "Position").child( "ReferencePoint").attribute( "X") == nullptr ||
node.child( "Position").child( "ReferencePoint").attribute( "Y") == nullptr ||
node.child( "Position").child( "ReferencePoint").attribute( "Z") == nullptr ) {
LOG_ERROR( GetEExLogger(), " Error reading Part ReferencePlane : ReferencePoint error") ;
return false ;
}
ptOrig.x = node.child( "Position").child( "ReferencePoint").attribute( "X").as_double() ;
ptOrig.y = node.child( "Position").child( "ReferencePoint").attribute( "Y").as_double() ;
ptOrig.z = node.child( "Position").child( "ReferencePoint").attribute( "Z").as_double() ;
// VectX
if ( node.child( "Position").child( "XVector") == nullptr ||
node.child( "Position").child( "XVector").attribute( "X") == nullptr ||
node.child( "Position").child( "XVector").attribute( "Y") == nullptr ||
node.child( "Position").child( "XVector").attribute( "Z") == nullptr ) {
LOG_ERROR( GetEExLogger(), " Error reading Part ReferencePlane : VectorX error") ;
return false ;
}
vX.x = node.child( "Position").child( "XVector").attribute( "X").as_double() ;
vX.y = node.child( "Position").child( "XVector").attribute( "Y").as_double() ;
vX.z = node.child( "Position").child( "XVector").attribute( "Z").as_double() ;
// VectY
if ( node.child( "Position").child( "YVector") == nullptr ||
node.child( "Position").child( "YVector").attribute( "X") == nullptr ||
node.child( "Position").child( "YVector").attribute( "Y") == nullptr ||
node.child( "Position").child( "YVector").attribute( "Z") == nullptr ) {
LOG_ERROR( GetEExLogger(), " Error reading Part ReferencePlane : VectorY error") ;
return false ;
}
vY.x = node.child( "Position").child( "YVector").attribute( "X").as_double() ;
vY.y = node.child( "Position").child( "YVector").attribute( "Y").as_double() ;
vY.z = node.child( "Position").child( "YVector").attribute( "Z").as_double() ;
Point3d ptOnX = ptOrig + 100 * vX ;
Point3d ptOnY = ptOrig + 100 * vY ;
Frame3d frRef ;
frRef.Set( ptOrig, ptOnX, ptOnY) ;
if ( ! frRef.IsValid()) {
LOG_ERROR( GetEExLogger(), ( " Error reading Part Process: User Reference Plane " + to_string( nId) + " is not valid").c_str()) ;
return false ;
}
m_mapRefPlanes.emplace( nId, frRef) ;
return true ;
}
//------------------------------------------------------------------------
bool
ImportBtlx::ReadProcessings( pugi::xml_node node)
{
int nProcId = 0 ; // conto le lavorazioni
// Scorro tutte le lavorazioni
for ( pugi::xml_node_iterator it = node.begin() ; it != node.end() ; it ++) {
string sProcessName = it->name() ;
int nGroup = 0 ;
int nProc = 0 ;
int nSide = 0 ;
INTVECTOR vnDPar ;
int nSPar ;
DBLVECTOR vdPar ;
string sPar ;
Frame3d frRef ;
STRVECTOR vsUAtt ;
string sDes ;
bool bProcessOk = false ;
bool bAdd = true ;
// Controllo che ci siano elementi required del tipo dei processi
if ( it->attribute( "Name") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Processing : missing name") ;
return false ;
}
sDes = it->attribute( "Name").value() ;
// Attributi comuni a tutti i processi:
for ( pugi::xml_attribute attr = it->first_attribute() ; attr ; attr = attr.next_attribute()) {
string sName = attr.name() ;
string sValue = attr.value() ;
if ( sName == "ProcessingQuality") {
if ( sValue == "automatic" || sValue == "fast" || sValue == "visible")
vsUAtt.emplace_back( sName + ":" + sValue) ;
else {
LOG_ERROR( GetEExLogger(), " Error reading Part Processing: unknown ProcessingQuality attribute value") ;
return false ;
}
}
else if ( sName == "Recess") {
if ( sValue == "automatic" || sValue == "manual")
vsUAtt.emplace_back( sName + ":" + sValue) ;
else {
LOG_ERROR( GetEExLogger(), " Error reading Part Procesing: unknown Recess attribute value") ;
return false ;
}
}
else if ( sName == "Process" && sValue != "yes")
vsUAtt.emplace_back( "DO:0") ;
else if ( sName == "Priority")
vsUAtt.emplace_back( sName + ":" + sValue) ;
}
// Analizzo i sottonodi
if ( sProcessName == "UserAttributes") {
bool bReadAttrOk = ReadUserAttributes( *it, 3, &vsUAtt) ;
if ( ! bReadAttrOk)
return false ;
}
// JackRafterCut
else if ( sProcessName == "JackRafterCut")
bProcessOk = ReadJackRafterCutParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// LongitudinalCut
else if ( sProcessName == "LongitudinalCut")
bProcessOk = ReadLongitudinalCutParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// DoubleCut
else if ( sProcessName == "DoubleCut")
bProcessOk = ReadDoubleCutParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// RidgeValleyCut
else if ( sProcessName == "RidgeValleyCut")
bProcessOk = ReadRidgeValleyCutParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// SawCut
else if ( sProcessName == "SawCut")
bProcessOk = ReadSawCutParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// Slot
else if ( sProcessName == "Slot")
bProcessOk = ReadSlotParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// BirdsMouth
else if ( sProcessName == "BirdsMouth")
bProcessOk = ReadBirdsMouthParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// HipValleyRafterNotch
else if ( sProcessName == "HipValleyRafterNotch")
bProcessOk = ReadHipValleyRafterNotchParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// Lap
else if ( sProcessName == "Lap")
bProcessOk = ReadLapParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// LogHouseHalfLap
else if ( sProcessName == "LogHouseHalfLap")
bProcessOk = ReadLogHouseHalfLapParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// FrenchRidgeLap
else if ( sProcessName == "FrenchRidgeLap")
bProcessOk = ReadFrenchRidgeLapParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// Chamfer
else if ( sProcessName == "Chamfer")
bProcessOk = ReadChamferParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// LogHouseJoint
else if ( sProcessName == "LogHouseJoint")
bProcessOk = ReadLogHouseJointParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// LogHouseFront
else if ( sProcessName == "LogHouseFront")
bProcessOk = ReadLogHouseFrontParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// Pocket
else if ( sProcessName == "Pocket")
bProcessOk = ReadPocketParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// Drilling
else if ( sProcessName == "Drilling")
bProcessOk = ReadDrillingParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// Tenon
else if ( sProcessName == "Tenon") {
bProcessOk = ReadTenonParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
if ( ! bProcessOk)
return false ;
bProcessOk = m_BtlGeom.AddTenonBTLX( nGroup, nProc, nSide, sDes, nProcId, vnDPar, vdPar, vsUAtt) ;
bAdd = false ; // non devo aggiungere il processo una volta terminati questi if
if ( ! bProcessOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part Process: BtlGeom.AddTenonBTLX error") ;
return false ;
}
}
// Mortise
else if ( sProcessName == "Mortise")
bProcessOk = ReadMortiseParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// House
else if ( sProcessName == "House") {
// I parametri sono quasi gli stessi di Tenon, quindi chiamo la stessa funzione
bProcessOk = ReadTenonParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
if ( ! bProcessOk)
return false ;
// Sovrascrivo i parametri di Tenon con le modifiche proprie di House
nProc = 52 ;
bProcessOk = m_BtlGeom.AddTenonBTLX( nGroup, nProc, nSide, sDes, nProcId, vnDPar, vdPar, vsUAtt) ;
bAdd = false ;
if ( ! bProcessOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part Process: BtlGeom.AddHouseBTLX error") ;
return false ;
}
nProcId ++ ;
// House contiene un tenon o un dovetailtenon :
pugi::xml_node housetenon = it->child( "Tenon") ;
pugi::xml_node housedtenon = it->child( "DovetailTenon") ;
if ( housetenon != nullptr) {
// Con GetProcessParamInfos viene fatto emplace_back sul vettore dei parametri quindi devono essere vuoti
vnDPar.clear() ; vdPar.clear() ; nSPar = 0 ; sPar.clear() ; vsUAtt.clear() ;
bProcessOk = ReadTenonParams( housetenon, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
if ( ! bProcessOk)
return false ;
bProcessOk = m_BtlGeom.AddTenonBTLX( nGroup, nProc, nSide, "Tenon", nProcId, vnDPar, vdPar, vsUAtt) ;
if ( ! bProcessOk ) {
LOG_ERROR( GetEExLogger(), " Error reading Part Process: BtlGeom.AddHouseBTLX error") ;
return false ;
}
}
if ( housedtenon != nullptr) {
vnDPar.clear() ; vdPar.clear() ; nSPar = 0 ; sPar.clear() ; vsUAtt.clear() ;
bProcessOk = ReadDovetailTenonParams( housedtenon, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
if ( ! bProcessOk)
return false ;
bProcessOk = m_BtlGeom.AddDovetailTenonBTLX( nGroup, nProc, nSide, "DovetailTenon", nProcId, vnDPar, vdPar, vsUAtt) ;
if ( ! bProcessOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part Process: BtlGeom.AddHouseBTLX error") ;
return false ;
}
}
}
// HouseMortise
else if ( sProcessName == "HouseMortise") {
// I parametri sono quasi gli stessi di Mortise, quindi chiamo la stessa funzione
bProcessOk = ReadMortiseParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
if ( ! bProcessOk)
return false ;
// Sovrascrivo i parametri di Mortise con le modifiche proprie di House
nProc = 53 ;
bProcessOk = m_BtlGeom.AddProcess( nGroup, nProc, nSide, sDes, nProcId, frRef, vnDPar, nSPar, vdPar, sPar, vsUAtt, 0) ;
bAdd = false ;
if ( ! bProcessOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part Process: BtlGeom.AddMortiseBTLX error") ;
return false ;
}
nProcId ++ ;
// House contiene una mortise/dovetailmortise :
pugi::xml_node housemortise = it->child( "Mortise") ;
pugi::xml_node housedtmortise = it->child( "DovetailMortise") ;
if ( housemortise != nullptr) {
vnDPar.clear() ; vdPar.clear() ; nSPar = 0 ; sPar.clear() ; vsUAtt.clear() ;
bProcessOk = ReadMortiseParams( housemortise, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
if ( ! bProcessOk)
return false ;
bProcessOk = m_BtlGeom.AddProcess( nGroup, nProc, nSide, "Mortise", nProcId, frRef, vnDPar, nSPar, vdPar, sPar, vsUAtt, 0) ;
if ( ! bProcessOk ){
LOG_ERROR( GetEExLogger(), " Error reading Part Process: BtlGeom.AddMortiseBTLX error")
return false ;
}
}
if ( housedtmortise != nullptr) {
vnDPar.clear() ; vdPar.clear() ; nSPar = 0 ; sPar.clear() ; vsUAtt.clear() ;
bProcessOk = ReadDovetailMortiseParams( housedtmortise, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
if ( ! bProcessOk)
return false ;
bProcessOk = m_BtlGeom.AddProcess( nGroup, nProc, nSide, "DovetailMortise", nProcId, frRef, vnDPar, nSPar, vdPar, sPar, vsUAtt, 0) ;
if ( ! bProcessOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part Process: BtlGeom.AddMortiseBTLX error") ;
return false ;
}
}
}
// DovetailTenon
else if ( sProcessName == "DovetailTenon") {
bProcessOk = ReadDovetailTenonParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
if ( ! bProcessOk)
return false ;
bProcessOk = m_BtlGeom.AddDovetailTenonBTLX( nGroup, nProc, nSide, sDes, nProcId, vnDPar, vdPar, vsUAtt) ;
bAdd = false ; // non devo aggiungere il processo una volta terminati questi if
if ( ! bProcessOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part Process: BtlGeom.AddDovetailTenonBTLX error") ;
return false ;
}
}
// DovetailMortise
else if ( sProcessName == "DovetailMortise")
bProcessOk = ReadDovetailMortiseParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// Marking
else if ( sProcessName == "Marking")
bProcessOk = ReadMarkingParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// Text
else if ( sProcessName == "Text")
bProcessOk = ReadTextParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// SimpleScarf
else if ( sProcessName == "SimpleScarf")
bProcessOk = ReadSimpleScarfParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// ScarfJoint
else if ( sProcessName == "ScarfJoint")
bProcessOk = ReadScarfJointParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// StepJoint
else if ( sProcessName == "StepJoint")
bProcessOk = ReadStepJointParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// StepJointNotch
else if ( sProcessName == "StepJointNotch")
bProcessOk = ReadStepJointNotchParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// Planing
else if ( sProcessName == "Planing")
bProcessOk = ReadPlaningParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// ProfileFront
else if ( sProcessName == "ProfileFront")
bProcessOk = ReadProfileFrontParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// ProfileCambered
else if ( sProcessName == "ProfileCambered")
bProcessOk = ReadProfileCamberedParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// RoundArch
else if ( sProcessName == "RoundArch")
bProcessOk = ReadRoundArchParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// ProfileHead
else if ( sProcessName == "ProfileHead")
bProcessOk = ReadProfileHeadParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// Sphere
else if ( sProcessName == "Sphere") {
LOG_ERROR( GetEExLogger(), " Warning reading Part Process: Sphere ignored") ;
// bProcessOk = ReadSphereParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
}
// TriangleCut
else if ( sProcessName == "TriangleCut")
bProcessOk = ReadTriangleCutParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// TyroleanDovetail
else if ( sProcessName == "TyroleanDovetail")
bProcessOk = ReadTyroleanDovetailParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// Dovetail
else if ( sProcessName == "Dovetail")
bProcessOk = ReadDovetailParams( *it, nGroup, nProc, nSide, vnDPar, nSPar, vdPar, sPar) ;
// FreeContour
else if ( sProcessName == "FreeContour") {
bProcessOk = ReadFreeContourParams( *it, vsUAtt) ;
bAdd = false ;
}
if ( ! bProcessOk)
return false ;
// aggiungo il processo
if ( bAdd) {
// se riferimento non è una delle facce, lo recupero da UserReferencePlanes
if ( nSide < BTL_SIDE_FRONT || nSide > BTL_SIDE_RIGHT) {
// se non esiste, errore
if ( m_mapRefPlanes.find( nSide) == m_mapRefPlanes.end()) {
LOG_ERROR( GetEExLogger(), " Error reading Part Process: Reference Plane unknown") ;
return false ;
}
frRef = m_mapRefPlanes[nSide] ;
}
bProcessOk = m_BtlGeom.AddProcess( nGroup, nProc, nSide, sDes, nProcId, frRef, vnDPar, nSPar, vdPar, sPar, vsUAtt, 0) ;
if ( ! bProcessOk) {
LOG_ERROR( GetEExLogger(), " Error reading Part Process: BtlGeom.AddProcess error") ;
return false ;
}
}
nProcId ++ ;
} // end sui sottonodi di Processings
return true ;
}
//--------------------------------------------------------------------
bool
ImportBtlx::ReadShape( pugi::xml_node node)
{
pugi::xml_node FaceSet = node.child( "IndexedFaceSet") ;
if ( FaceSet == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Shape: Indexed Face Set missing") ;
return false ;
}
string sFacesVertices = FaceSet.attribute( "coordIndex").value() ;
if ( sFacesVertices == "") {
LOG_ERROR( GetEExLogger(), " Error reading Part Shape: Indexed Face Set missing") ;
return false ;
}
if ( FaceSet.child( "Coordinate") == nullptr) {
LOG_ERROR( GetEExLogger(), " Error reading Part Shape: Coordinates missing") ;
return false ;
}
string sCoordPoints = FaceSet.child( "Coordinate").attribute( "point").value() ;
if ( sCoordPoints == "") {
LOG_ERROR( GetEExLogger(), " Error reading Part Shape: Coordinates missing") ;
return false ;
}
INTMATRIX vFacesVertices ;
PNTVECTOR vPoints ;
size_t str_start = 0 ;
size_t str_end ;
// Vertici delle facce
INTVECTOR vAux ; // vettore per salvare i vertici di una faccia
if ( sFacesVertices.back() != ' ')
sFacesVertices += " " ;
while ( ( str_end = sFacesVertices.find( " ", str_start)) != string::npos) {
int nVal = 0 ;
FromString( sFacesVertices.substr( str_start, str_end - str_start), nVal) ;
str_start = str_end + 1 ;
if ( nVal == -1) { // delimiter -1 indica che una faccia è terminata
vFacesVertices.push_back( vAux) ;
vAux.clear() ;
}
else {
vAux.push_back( nVal) ;
}
}
// Coordinate dei vertici
str_start = 0 ;
DBLVECTOR vAux2 ; // vettore per salvare le coordinate di un punto
if ( sCoordPoints.back() != ' ')
sCoordPoints += " " ;
while ( ( str_end = sCoordPoints.find( " ", str_start)) != string::npos) {
double dVal = 0 ;
FromString( sCoordPoints.substr( str_start, str_end - str_start), dVal) ;
str_start = str_end + 1 ;
vAux2.push_back( dVal) ;
if ( vAux2.size() == 3) { // hai letto 3 coordinate quindi hai un punto
vPoints.push_back( Point3d( vAux2[0], vAux2[1], vAux2[2])) ;
vAux2.clear() ;
}
}
// se termino senza aver svuotato vAux2 significa che ho un punto con coordinate incomplete
if ( vAux2.size() != 0) {
LOG_ERROR( GetEExLogger(), " Error reading Part Shape: Coordinates not defining a point") ;
return false ;
}
return m_BtlGeom.AddShapeBTLX( vFacesVertices, vPoints) ;
}