diff --git a/src/App/Application.cpp b/src/App/Application.cpp
index 71517fc674..40a621bd09 100644
--- a/src/App/Application.cpp
+++ b/src/App/Application.cpp
@@ -58,7 +58,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include
diff --git a/src/App/Document.cpp b/src/App/Document.cpp
index 09a3e58497..8e6cf23313 100644
--- a/src/App/Document.cpp
+++ b/src/App/Document.cpp
@@ -91,6 +91,7 @@ recompute path. Also, it enables more complicated dependencies beyond trees.
#include
#include
#include
+#include
#include "Document.h"
#include "Application.h"
diff --git a/src/App/DocumentPyImp.cpp b/src/App/DocumentPyImp.cpp
index 4f7bc1a6f9..3b4c3e96de 100644
--- a/src/App/DocumentPyImp.cpp
+++ b/src/App/DocumentPyImp.cpp
@@ -25,6 +25,7 @@
#include
#include
+#include
#include "Document.h"
#include "DocumentObject.h"
diff --git a/src/App/PropertyFile.cpp b/src/App/PropertyFile.cpp
index 8dc8cfe3e7..5c14e43bae 100644
--- a/src/App/PropertyFile.cpp
+++ b/src/App/PropertyFile.cpp
@@ -26,6 +26,7 @@
#include
#include
#include
+#include
#include
#include
diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp
index cf84b57421..0fc1cf9821 100644
--- a/src/App/PropertyStandard.cpp
+++ b/src/App/PropertyStandard.cpp
@@ -32,6 +32,7 @@
#include
#include
#include
+#include
#include
#include "PropertyStandard.h"
diff --git a/src/Base/Builder3D.cpp b/src/Base/Builder3D.cpp
index a090485985..073413244c 100644
--- a/src/Base/Builder3D.cpp
+++ b/src/Base/Builder3D.cpp
@@ -26,6 +26,7 @@
#ifndef _PreComp_
# include
# include
+# include
#endif
#include "Builder3D.h"
diff --git a/src/Base/CMakeLists.txt b/src/Base/CMakeLists.txt
index bbe8c09b9f..f5a711055d 100644
--- a/src/Base/CMakeLists.txt
+++ b/src/Base/CMakeLists.txt
@@ -222,6 +222,7 @@ SET(FreeCADBase_CPP_SRCS
BoundBoxPyImp.cpp
Builder3D.cpp
Console.cpp
+ ConsoleObserver.cpp
CoordinateSystem.cpp
CoordinateSystemPyImp.cpp
Debugger.cpp
@@ -285,6 +286,7 @@ SET(FreeCADBase_HPP_SRCS
BoundBox.h
Builder3D.h
Console.h
+ ConsoleObserver.h
Converter.h
CoordinateSystem.h
Debugger.h
diff --git a/src/Base/Console.cpp b/src/Base/Console.cpp
index e03a4acc36..e68f1cb353 100644
--- a/src/Base/Console.cpp
+++ b/src/Base/Console.cpp
@@ -35,7 +35,6 @@
#include "Console.h"
#include "Exception.h"
#include "PyObjectBase.h"
-#include "frameobject.h"
#include
@@ -70,7 +69,7 @@ public:
}
static void destruct() {
delete instance;
- instance = 0;
+ instance = nullptr;
}
void customEvent(QEvent* ev) {
@@ -104,7 +103,7 @@ private:
static ConsoleOutput* instance;
};
-ConsoleOutput* ConsoleOutput::instance = 0;
+ConsoleOutput* ConsoleOutput::instance = nullptr;
}
@@ -112,7 +111,7 @@ ConsoleOutput* ConsoleOutput::instance = 0;
// Construction destruction
-ConsoleSingleton::ConsoleSingleton(void)
+ConsoleSingleton::ConsoleSingleton()
: _bVerbose(true)
, _bCanRefresh(true)
, connectionMode(Direct)
@@ -404,14 +403,14 @@ ILogger *ConsoleSingleton::Get(const char *Name) const
if (OName && strcmp(OName,Name) == 0)
return *Iter;
}
- return 0;
+ return nullptr;
}
int *ConsoleSingleton::GetLogLevel(const char *tag, bool create) {
if (!tag) tag = "";
if (_logLevels.find(tag) != _logLevels.end())
return &_logLevels[tag];
- if (!create) return 0;
+ if (!create) return nullptr;
int &ret = _logLevels[tag];
ret = -1;
return &ret;
@@ -429,17 +428,17 @@ void ConsoleSingleton::EnableRefresh(bool enable) {
//**************************************************************************
// Singleton stuff
-ConsoleSingleton * ConsoleSingleton::_pcSingleton = 0;
+ConsoleSingleton * ConsoleSingleton::_pcSingleton = nullptr;
-void ConsoleSingleton::Destruct(void)
+void ConsoleSingleton::Destruct()
{
// not initialized or double destructed!
assert(_pcSingleton);
delete _pcSingleton;
- _pcSingleton=0;
+ _pcSingleton=nullptr;
}
-ConsoleSingleton & ConsoleSingleton::Instance(void)
+ConsoleSingleton & ConsoleSingleton::Instance()
{
// not initialized?
if (!_pcSingleton)
@@ -454,19 +453,19 @@ ConsoleSingleton & ConsoleSingleton::Instance(void)
// ConsoleSingleton Methods // Methods structure
PyMethodDef ConsoleSingleton::Methods[] = {
- {"PrintMessage", (PyCFunction) ConsoleSingleton::sPyMessage, METH_VARARGS,
+ {"PrintMessage", ConsoleSingleton::sPyMessage, METH_VARARGS,
"PrintMessage(string) -- Print a message to the output"},
- {"PrintLog", (PyCFunction) ConsoleSingleton::sPyLog, METH_VARARGS,
+ {"PrintLog", ConsoleSingleton::sPyLog, METH_VARARGS,
"PrintLog(string) -- Print a log message to the output"},
- {"PrintError" , (PyCFunction) ConsoleSingleton::sPyError, METH_VARARGS,
+ {"PrintError" , ConsoleSingleton::sPyError, METH_VARARGS,
"PrintError(string) -- Print an error message to the output"},
- {"PrintWarning", (PyCFunction) ConsoleSingleton::sPyWarning, METH_VARARGS,
+ {"PrintWarning", ConsoleSingleton::sPyWarning, METH_VARARGS,
"PrintWarning -- Print a warning to the output"},
- {"SetStatus", (PyCFunction) ConsoleSingleton::sPySetStatus, METH_VARARGS,
+ {"SetStatus", ConsoleSingleton::sPySetStatus, METH_VARARGS,
"Set the status for either Log, Msg, Wrn or Error for an observer"},
- {"GetStatus", (PyCFunction) ConsoleSingleton::sPyGetStatus, METH_VARARGS,
+ {"GetStatus", ConsoleSingleton::sPyGetStatus, METH_VARARGS,
"Get the status for either Log, Msg, Wrn or Error for an observer"},
- {NULL, NULL, 0, NULL} /* Sentinel */
+ {nullptr, nullptr, 0, nullptr} /* Sentinel */
};
@@ -474,10 +473,10 @@ PyObject *ConsoleSingleton::sPyMessage(PyObject * /*self*/, PyObject *args)
{
PyObject *output;
if (!PyArg_ParseTuple(args, "O", &output))
- return NULL;
+ return nullptr;
- const char* string=0;
- PyObject* unicode=0;
+ const char* string=nullptr;
+ PyObject* unicode=nullptr;
if (PyUnicode_Check(output)) {
string = PyUnicode_AsUTF8(output);
}
@@ -502,10 +501,10 @@ PyObject *ConsoleSingleton::sPyWarning(PyObject * /*self*/, PyObject *args)
{
PyObject *output;
if (!PyArg_ParseTuple(args, "O", &output))
- return NULL;
+ return nullptr;
- const char* string=0;
- PyObject* unicode=0;
+ const char* string=nullptr;
+ PyObject* unicode=nullptr;
if (PyUnicode_Check(output)) {
string = PyUnicode_AsUTF8(output);
}
@@ -530,10 +529,10 @@ PyObject *ConsoleSingleton::sPyError(PyObject * /*self*/, PyObject *args)
{
PyObject *output;
if (!PyArg_ParseTuple(args, "O", &output))
- return NULL;
+ return nullptr;
- const char* string=0;
- PyObject* unicode=0;
+ const char* string=nullptr;
+ PyObject* unicode=nullptr;
if (PyUnicode_Check(output)) {
string = PyUnicode_AsUTF8(output);
}
@@ -558,10 +557,10 @@ PyObject *ConsoleSingleton::sPyLog(PyObject * /*self*/, PyObject *args)
{
PyObject *output;
if (!PyArg_ParseTuple(args, "O", &output))
- return NULL;
+ return nullptr;
- const char* string=0;
- PyObject* unicode=0;
+ const char* string=nullptr;
+ PyObject* unicode=nullptr;
if (PyUnicode_Check(output)) {
string = PyUnicode_AsUTF8(output);
}
@@ -587,7 +586,7 @@ PyObject *ConsoleSingleton::sPyGetStatus(PyObject * /*self*/, PyObject *args)
char *pstr1;
char *pstr2;
if (!PyArg_ParseTuple(args, "ss", &pstr1, &pstr2)) // convert args: Python->C
- return NULL; // NULL triggers exception
+ return nullptr; // NULL triggers exception
PY_TRY{
bool b=false;
@@ -616,8 +615,8 @@ PyObject *ConsoleSingleton::sPySetStatus(PyObject * /*self*/, PyObject *args)
char *pstr1;
char *pstr2;
int Bool;
- if (!PyArg_ParseTuple(args, "ssi", &pstr1, &pstr2,&Bool)) // convert args: Python->C
- return NULL; // NULL triggers exception
+ if (!PyArg_ParseTuple(args, "ssi", &pstr1, &pstr2,&Bool))
+ return nullptr;
PY_TRY{
ILogger *pObs = Instance().Get(pstr1);
@@ -637,253 +636,12 @@ PyObject *ConsoleSingleton::sPySetStatus(PyObject * /*self*/, PyObject *args)
Py_INCREF(Py_None);
return Py_None;
}
- else {
+ else {
Py_Error(Base::BaseExceptionFreeCADError,"Unknown Console Type");
- }
+ }
} PY_CATCH;
}
-//=========================================================================
-// some special observers
-
Base::ILogger::~ILogger()
{}
-
-ConsoleObserverFile::ConsoleObserverFile(const char *sFileName)
- : cFileStream(Base::FileInfo(sFileName)) // can be in UTF8
-{
- if (!cFileStream.is_open())
- Console().Warning("Cannot open log file '%s'.\n", sFileName);
- // mark the file as a UTF-8 encoded file
- unsigned char bom[3] = {0xef, 0xbb, 0xbf};
- cFileStream.write((const char*)bom,3*sizeof(char));
-}
-
-ConsoleObserverFile::~ConsoleObserverFile()
-{
- cFileStream.close();
-}
-
-void ConsoleObserverFile::SendLog(const std::string& msg, LogStyle level)
-{
- std::string prefix;
- switch(level){
- case LogStyle::Warning:
- prefix = "Wrn: ";
- break;
- case LogStyle::Message:
- prefix = "Msg: ";
- break;
- case LogStyle::Error:
- prefix = "Err: ";
- break;
- case LogStyle::Log:
- prefix = "Log: ";
- break;
- }
-
- cFileStream << prefix << msg;
- cFileStream.flush();
-}
-
-ConsoleObserverStd::ConsoleObserverStd() :
-# if defined(FC_OS_WIN32)
- useColorStderr(true)
-# elif defined(FC_OS_LINUX) || defined(FC_OS_MACOSX) || defined(FC_OS_BSD)
- useColorStderr( isatty(STDERR_FILENO) )
-# else
- useColorStderr(false)
-# endif
-{
- bLog = false;
-}
-
-ConsoleObserverStd::~ConsoleObserverStd()
-{
-}
-
-void ConsoleObserverStd::SendLog(const std::string& msg, LogStyle level)
-{
- switch(level){
- case LogStyle::Warning:
- this->Warning(msg.c_str());
- break;
- case LogStyle::Message:
- this->Message(msg.c_str());
- break;
- case LogStyle::Error:
- this->Error(msg.c_str());
- break;
- case LogStyle::Log:
- this->Log(msg.c_str());
- break;
- }
-}
-
-void ConsoleObserverStd::Message(const char *sMsg)
-{
- printf("%s",sMsg);
-}
-
-void ConsoleObserverStd::Warning(const char *sWarn)
-{
- if (useColorStderr) {
-# if defined(FC_OS_WIN32)
- ::SetConsoleTextAttribute(::GetStdHandle(STD_ERROR_HANDLE), FOREGROUND_GREEN| FOREGROUND_BLUE);
-# elif defined(FC_OS_LINUX) || defined(FC_OS_MACOSX) || defined(FC_OS_BSD)
- fprintf(stderr, "\033[1;33m");
-# endif
- }
-
- fprintf(stderr, "%s", sWarn);
-
- if (useColorStderr) {
-# if defined(FC_OS_WIN32)
- ::SetConsoleTextAttribute(::GetStdHandle(STD_ERROR_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
-# elif defined(FC_OS_LINUX) || defined(FC_OS_MACOSX) || defined(FC_OS_BSD)
- fprintf(stderr, "\033[0m");
-# endif
- }
-}
-
-void ConsoleObserverStd::Error (const char *sErr)
-{
- if (useColorStderr) {
-# if defined(FC_OS_WIN32)
- ::SetConsoleTextAttribute(::GetStdHandle(STD_ERROR_HANDLE), FOREGROUND_RED|FOREGROUND_INTENSITY );
-# elif defined(FC_OS_LINUX) || defined(FC_OS_MACOSX) || defined(FC_OS_BSD)
- fprintf(stderr, "\033[1;31m");
-# endif
- }
-
- fprintf(stderr, "%s", sErr);
-
- if (useColorStderr) {
-# if defined(FC_OS_WIN32)
- ::SetConsoleTextAttribute(::GetStdHandle(STD_ERROR_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
-# elif defined(FC_OS_LINUX) || defined(FC_OS_MACOSX) || defined(FC_OS_BSD)
- fprintf(stderr, "\033[0m");
-# endif
- }
-}
-
-void ConsoleObserverStd::Log (const char *sErr)
-{
- if (useColorStderr) {
-# if defined(FC_OS_WIN32)
- ::SetConsoleTextAttribute(::GetStdHandle(STD_ERROR_HANDLE), FOREGROUND_RED |FOREGROUND_GREEN);
-# elif defined(FC_OS_LINUX) || defined(FC_OS_MACOSX) || defined(FC_OS_BSD)
- fprintf(stderr, "\033[1;36m");
-# endif
- }
-
- fprintf(stderr, "%s", sErr);
-
- if (useColorStderr) {
-# if defined(FC_OS_WIN32)
- ::SetConsoleTextAttribute(::GetStdHandle(STD_ERROR_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
-# elif defined(FC_OS_LINUX) || defined(FC_OS_MACOSX) || defined(FC_OS_BSD)
- fprintf(stderr, "\033[0m");
-# endif
- }
-}
-
-RedirectStdOutput::RedirectStdOutput()
-{
- buffer.reserve(80);
-}
-
-int RedirectStdOutput::overflow(int c)
-{
- if (c != EOF)
- buffer.push_back((char)c);
- return c;
-}
-
-int RedirectStdOutput::sync()
-{
- // Print as log as this might be verbose
- if (!buffer.empty() && buffer.back() == '\n') {
- Base::Console().Log("%s", buffer.c_str());
- buffer.clear();
- }
- return 0;
-}
-
-RedirectStdLog::RedirectStdLog()
-{
- buffer.reserve(80);
-}
-
-int RedirectStdLog::overflow(int c)
-{
- if (c != EOF)
- buffer.push_back((char)c);
- return c;
-}
-
-int RedirectStdLog::sync()
-{
- // Print as log as this might be verbose
- if (!buffer.empty() && buffer.back() == '\n') {
- Base::Console().Log("%s", buffer.c_str());
- buffer.clear();
- }
- return 0;
-}
-
-RedirectStdError::RedirectStdError()
-{
- buffer.reserve(80);
-}
-
-int RedirectStdError::overflow(int c)
-{
- if (c != EOF)
- buffer.push_back((char)c);
- return c;
-}
-
-int RedirectStdError::sync()
-{
- if (!buffer.empty() && buffer.back() == '\n') {
- Base::Console().Error("%s", buffer.c_str());
- buffer.clear();
- }
- return 0;
-}
-
-//---------------------------------------------------------
-
-std::stringstream &LogLevel::prefix(std::stringstream &str, const char *src, int line)
-{
- static FC_TIME_POINT s_tstart;
- static bool s_timing = false;
- if (print_time) {
- if (!s_timing) {
- s_timing = true;
- _FC_TIME_INIT(s_tstart);
- }
- auto tnow = std::chrono::FC_TIME_CLOCK::now();
- auto d = std::chrono::duration_cast(tnow-s_tstart);
- str << d.count() << ' ';
- }
- if (print_tag) str << '<' << tag << "> ";
- if (print_src==2) {
- PyFrameObject* frame = PyEval_GetFrame();
- if (frame) {
- line = PyFrame_GetLineNumber(frame);
- src = PyUnicode_AsUTF8(frame->f_code->co_filename);
- }
- }
- if (print_src && src && src[0]) {
-#ifdef FC_OS_WIN32
- const char *_f = std::strrchr(src, '\\');
-#else
- const char *_f = std::strrchr(src, '/');
-#endif
- str << (_f?_f+1:src)<<"("<
#include
#include