GuiConsole.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # include "stdio.h"
00028 # ifdef FC_OS_WIN32
00029 # include "io.h"
00030 # endif
00031 # ifdef FC_OS_WIN32
00032 # include <windows.h>
00033 # endif
00034 # include "fcntl.h"
00035 # include <iostream>
00036 #endif
00037
00038 #include "GuiConsole.h"
00039
00040 using namespace Gui;
00041
00042 #ifdef FC_OS_WIN32
00043
00044 const unsigned int GUIConsole::s_nMaxLines = 1000;
00045 unsigned int GUIConsole::s_nRefCount = 0;
00046
00052 GUIConsole::GUIConsole (void)
00053 {
00054 if (!s_nRefCount++)
00055 {
00056 bLog = false;
00057
00058 CONSOLE_SCREEN_BUFFER_INFO csbi;
00059
00060 ::AllocConsole();
00061
00062 ::GetConsoleScreenBufferInfo(::GetStdHandle(STD_OUTPUT_HANDLE),&csbi);
00063 csbi.dwSize.Y = s_nMaxLines;
00064 ::SetConsoleScreenBufferSize(::GetStdHandle(STD_OUTPUT_HANDLE),csbi.dwSize);
00065 ::SetConsoleTitle( "FreeCAD Console");
00066
00067 *stdout = *::_fdopen(::_open_osfhandle(reinterpret_cast<LONG>(::GetStdHandle(STD_OUTPUT_HANDLE)), _O_TEXT), "w");
00068 ::setvbuf(stdout, 0, _IONBF, 0);
00069
00070 *stdin = *::_fdopen(::_open_osfhandle(reinterpret_cast<LONG>(::GetStdHandle(STD_INPUT_HANDLE)), _O_TEXT), "r");
00071 ::setvbuf(stdin, 0, _IONBF, 0);
00072
00073 *stderr = *::_fdopen(::_open_osfhandle(reinterpret_cast<LONG>(::GetStdHandle(STD_ERROR_HANDLE)), _O_TEXT), "w");
00074 ::setvbuf(stderr, 0, _IONBF, 0);
00075 }
00076 }
00077
00081 GUIConsole::~GUIConsole (void)
00082 {
00083 if (!--s_nRefCount)
00084 FreeConsole();
00085 }
00086
00087 void GUIConsole::Message(const char *sMsg)
00088 {
00089 ::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
00090 printf("%s",sMsg);
00091 ::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
00092 }
00093
00094 void GUIConsole::Warning(const char *sWarn)
00095 {
00096 ::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN);
00097 printf("%s",sWarn);
00098 ::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
00099 }
00100
00101 void GUIConsole::Error (const char *sErr)
00102 {
00103 ::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED );
00104 printf("%s",sErr);
00105 ::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
00106 }
00107
00108 void GUIConsole::Log (const char *sLog)
00109 {
00110 printf("%s",sLog);
00111 }
00112
00113 #else
00114
00115
00116 GUIConsole::GUIConsole (void) {}
00117 GUIConsole::~GUIConsole (void) {}
00118 void GUIConsole::Message(const char *sMsg) { std::cout<<sMsg; }
00119 void GUIConsole::Warning(const char *sWarn){ std::cerr<<"Warning: "<<sWarn; }
00120 void GUIConsole::Error (const char *sErr) { std::cerr<<"Error: "<<sErr;}
00121 void GUIConsole::Log (const char *sLog) { std::clog<<sLog;}
00122
00123 #endif