diff --git a/src/ifcgeom/IfcGeomIterator.h b/src/ifcgeom/IfcGeomIterator.h index 22a59dafdb..803ca21226 100644 --- a/src/ifcgeom/IfcGeomIterator.h +++ b/src/ifcgeom/IfcGeomIterator.h @@ -522,6 +522,8 @@ namespace IfcGeom { } IfcSchema::IfcProduct* product = *ifcproduct_iterator; + + Logger::SetProduct(product); BRepElement

* element; if (ifcproduct_iterator == ifcproducts->begin() || !settings.get(IteratorSettings::USE_WORLD_COORDS)) { diff --git a/src/ifcparse/IfcLogger.cpp b/src/ifcparse/IfcLogger.cpp new file mode 100644 index 0000000000..aaf731fd45 --- /dev/null +++ b/src/ifcparse/IfcLogger.cpp @@ -0,0 +1,73 @@ +/******************************************************************************** + * * + * This file is part of IfcOpenShell. * + * * + * IfcOpenShell is free software: you can redistribute it and/or modify * + * it under the terms of the Lesser GNU General Public License as published by * + * the Free Software Foundation, either version 3.0 of the License, or * + * (at your option) any later version. * + * * + * IfcOpenShell is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Lesser GNU General Public License for more details. * + * * + * You should have received a copy of the Lesser GNU General Public License * + * along with this program. If not, see . * + * * + ********************************************************************************/ + +#include "IfcLogger.h" +#include "../ifcparse/IfcException.h" + +#include +#include + +#include +#include + + +void Logger::SetProduct(boost::optional product) { + current_product = product; +} +void Logger::SetOutput(std::ostream* l1, std::ostream* l2) { + log1 = l1; + log2 = l2; + if ( ! log2 ) { + log2 = &log_stream; + } +} +void Logger::Message(Logger::Severity type, const std::string& message, IfcAbstractEntity* entity) { + if ( log2 && type >= verbosity ) { + (*log2) << "[" << severity_strings[type] << "] "; + if ( current_product ) { + (*log2) << "{" << (*current_product)->GlobalId() << "} "; + } + (*log2) << message << std::endl; + if ( entity ) (*log2) << entity->toString() << std::endl; + } +} +void Logger::Status(const std::string& message, bool new_line) { + if ( log1 ) { + (*log1) << message; + if ( new_line ) (*log1) << std::endl; + else (*log1) << std::flush; + } +} +void Logger::ProgressBar(int progress) { + if ( log1 ) { + Status("\r[" + std::string(progress,'#') + std::string(50 - progress,' ') + "]", false); + } +} +std::string Logger::GetLog() { + return log_stream.str(); +} +void Logger::Verbosity(Logger::Severity v) { verbosity = v; } +Logger::Severity Logger::Verbosity() { return verbosity; } + +std::ostream* Logger::log1 = 0; +std::ostream* Logger::log2 = 0; +std::stringstream Logger::log_stream; +Logger::Severity Logger::verbosity = Logger::LOG_NOTICE; +const char* Logger::severity_strings[] = { "Notice","Warning","Error" }; +boost::optional Logger::current_product; \ No newline at end of file diff --git a/src/ifcparse/IfcLogger.h b/src/ifcparse/IfcLogger.h new file mode 100644 index 0000000000..acd5801e04 --- /dev/null +++ b/src/ifcparse/IfcLogger.h @@ -0,0 +1,62 @@ +/******************************************************************************** + * * + * This file is part of IfcOpenShell. * + * * + * IfcOpenShell is free software: you can redistribute it and/or modify * + * it under the terms of the Lesser GNU General Public License as published by * + * the Free Software Foundation, either version 3.0 of the License, or * + * (at your option) any later version. * + * * + * IfcOpenShell is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Lesser GNU General Public License for more details. * + * * + * You should have received a copy of the Lesser GNU General Public License * + * along with this program. If not, see . * + * * + ********************************************************************************/ + +#ifndef IFCLOGGER_H +#define IFCLOGGER_H + +#include +#include +#include +#include +#include + +#ifdef USE_IFC4 +#include "../ifcparse/Ifc4.h" +#else +#include "../ifcparse/Ifc2x3.h" +#endif + +#include + + +class Logger { +public: + typedef enum { LOG_NOTICE, LOG_WARNING, LOG_ERROR } Severity; +private: + static std::ostream* log1; + static std::ostream* log2; + static std::stringstream log_stream; + static Severity verbosity; + static const char* severity_strings[]; + static boost::optional current_product; +public: + static void SetProduct(boost::optional product); + /// Determines to what stream respectively progress and errors are logged + static void SetOutput(std::ostream* l1, std::ostream* l2); + /// Determines the types of log messages to get logged + static void Verbosity(Severity v); + static Severity Verbosity(); + /// Log a message to the output stream + static void Message(Severity type, const std::string& message, IfcAbstractEntity* entity=0); + static void Status(const std::string& message, bool new_line=true); + static void ProgressBar(int progress); + static std::string GetLog(); +}; + +#endif \ No newline at end of file diff --git a/src/ifcparse/IfcParse.h b/src/ifcparse/IfcParse.h index 16907cf786..03d53d89d0 100644 --- a/src/ifcparse/IfcParse.h +++ b/src/ifcparse/IfcParse.h @@ -42,6 +42,7 @@ #include "../ifcparse/IfcCharacterDecoder.h" #include "../ifcparse/IfcUtil.h" +#include "../ifcparse/IfcLogger.h" #ifdef USE_IFC4 #include "../ifcparse/Ifc4.h" diff --git a/src/ifcparse/IfcUtil.cpp b/src/ifcparse/IfcUtil.cpp index 80bd257b14..4fa8fd6d60 100644 --- a/src/ifcparse/IfcUtil.cpp +++ b/src/ifcparse/IfcUtil.cpp @@ -21,6 +21,7 @@ #include "../ifcparse/IfcException.h" #include +#include #include #include @@ -75,43 +76,6 @@ unsigned int IfcUtil::IfcBaseType::getArgumentCount() const { return 1; } Argument* IfcUtil::IfcBaseType::getArgument(unsigned int i) const { return entity->getArgument(i); } const char* IfcUtil::IfcBaseType::getArgumentName(unsigned int i) const { if (i == 0) { return "wrappedValue"; } else { throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); } } -void Logger::SetOutput(std::ostream* l1, std::ostream* l2) { - log1 = l1; - log2 = l2; - if ( ! log2 ) { - log2 = &log_stream; - } -} -void Logger::Message(Logger::Severity type, const std::string& message, IfcAbstractEntity* entity) { - if ( log2 && type >= verbosity ) { - (*log2) << "[" << severity_strings[type] << "] " << message << std::endl; - if ( entity ) (*log2) << entity->toString() << std::endl; - } -} -void Logger::Status(const std::string& message, bool new_line) { - if ( log1 ) { - (*log1) << message; - if ( new_line ) (*log1) << std::endl; - else (*log1) << std::flush; - } -} -void Logger::ProgressBar(int progress) { - if ( log1 ) { - Status("\r[" + std::string(progress,'#') + std::string(50 - progress,' ') + "]", false); - } -} -std::string Logger::GetLog() { - return log_stream.str(); -} -void Logger::Verbosity(Logger::Severity v) { verbosity = v; } -Logger::Severity Logger::Verbosity() { return verbosity; } - -std::ostream* Logger::log1 = 0; -std::ostream* Logger::log2 = 0; -std::stringstream Logger::log_stream; -Logger::Severity Logger::verbosity = Logger::LOG_NOTICE; -const char* Logger::severity_strings[] = { "Notice","Warning","Error" }; - static const char* const argument_type_string[] = { "NULL", "DERIVED", diff --git a/src/ifcparse/IfcUtil.h b/src/ifcparse/IfcUtil.h index 5e51d8232a..9580d27038 100644 --- a/src/ifcparse/IfcUtil.h +++ b/src/ifcparse/IfcUtil.h @@ -327,26 +327,4 @@ public: virtual IfcWrite::IfcWritableEntity* isWritable() = 0; }; -class Logger { -public: - typedef enum { LOG_NOTICE, LOG_WARNING, LOG_ERROR } Severity; -private: - static std::ostream* log1; - static std::ostream* log2; - static std::stringstream log_stream; - static Severity verbosity; - static const char* severity_strings[]; -public: - /// Determines to what stream respectively progress and errors are logged - static void SetOutput(std::ostream* l1, std::ostream* l2); - /// Determines the types of log messages to get logged - static void Verbosity(Severity v); - static Severity Verbosity(); - /// Log a message to the output stream - static void Message(Severity type, const std::string& message, IfcAbstractEntity* entity=0); - static void Status(const std::string& message, bool new_line=true); - static void ProgressBar(int progress); - static std::string GetLog(); -}; - #endif