2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkMessageManager.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.17 $
34 =========================================================================*/
40 * \brief class MessageManager : Manages the messages displayed by bbtk (code)
42 #include "bbtkMessageManager.h"
47 MessageManager::MessageManager()
48 : mMaxMessageLength(8)//, mAllLevel(0), mMaxLevel(9)
53 mMessageLevel[key] = 0;
54 mMessageHelp[key] = "Minimum level for all kind of messages";
55 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
57 mMessageLevel[key] = 9;
58 mMessageHelp[key] = "Maximum level for all kind of messages";
59 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
61 mMessageLevel[key] = 0;
62 mMessageHelp[key] = "Messages generated by the core classes of the lib";
63 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
65 mMessageLevel[key] = 0;
66 mMessageHelp[key] = "Messages related to box processing";
67 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
69 mMessageLevel[key] = 1;
70 mMessageHelp[key] = "Help messages";
71 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
73 mMessageLevel[key] = 0;
74 mMessageHelp[key] = "Error messages";
75 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
77 mMessageLevel[key] = 1;
78 mMessageHelp[key] = "Warning messages";
79 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
81 mMessageLevel[key] = 1;
82 mMessageHelp[key] = "Output messages";
83 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
85 mMessageLevel[key] = 0;
86 mMessageHelp[key] = "Debug messages";
87 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
89 mMessageLevel[key] = 0;
90 mMessageHelp[key] = "Configuration related messages";
91 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
93 mMessageLevel[key] = 0;
94 mMessageHelp[key] = "Data related messages";
95 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
97 mMessageLevel[key] = 0;
98 mMessageHelp[key] = "Widgets related messages";
99 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
101 mMessageLevel[key] = 0;
102 mMessageHelp[key] = "wxWidgets related messages";
103 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
105 mMessageLevel[key] = 0;
106 mMessageHelp[key] = "Qt related messages";
107 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
109 mMessageLevel[key] = 0;
110 mMessageHelp[key] = "Graphical user interface related messages";
111 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
113 mMessageLevel[key] = 0;
114 mMessageHelp[key] = "object memory related messages";
115 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
117 mMessageLevel[key] = 0;
118 mMessageHelp[key] = "Packages related messages";
119 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
121 mMessageLevel[key] = 0;
122 mMessageHelp[key] = "Connections related messages";
123 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
125 mMessageLevel[key] = 0;
126 mMessageHelp[key] = "Box i/o changes related messages";
127 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
129 mMessageLevel[key] = 0;
130 mMessageHelp[key] = "If positive then codes of the messages are displayed";
131 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
137 MessageManager::~MessageManager()
139 // std::cout << "~MessageManager"<<std::endl;
144 MessageManager* MessageManager::GetInstance()
146 static MessageManager* m = 0;
147 if (!m) m = new MessageManager();
151 bool MessageManager::RegisterMessageType(std::string key,
153 unsigned char default_level)
155 GetInstance()->mMessageLevel[key] = default_level;
156 GetInstance()->mMessageHelp[key] = help;
157 if (GetInstance()->mMaxMessageLength<key.length())
158 GetInstance()->mMaxMessageLength = key.length();
165 void MessageManager::SetMessageLevel(std::string key,
168 std::map<std::string,int>::iterator i;
169 i = GetInstance()->mMessageLevel.find(key);
170 if (i!=GetInstance()->mMessageLevel.end())
176 bbtkWarning("MessageManager::SetMessageLevel : message type=<"
177 <<key<<"> unregistered");
184 int MessageManager::GetMessageLevel(std::string key)
186 int l = GetInstance()->mMessageLevel["all"];
187 std::map<std::string,int>::iterator i =
188 GetInstance()->mMessageLevel.find(key);
189 if (i!=GetInstance()->mMessageLevel.end()) {
190 if ( (*i).second > l ) l = (*i).second;
192 int m = GetInstance()->mMessageLevel["max"];
199 void MessageManager::PrintInfo()
201 bbtkMessage("help",1,"================ Messages ================="
203 bbtkMessage("help",1, "Kind");
205 k<(int)(GetInstance()->mMaxMessageLength-2);
208 bbtkMessageCont("help",1," ");
210 bbtkMessageCont("help",1,"Level Nature" << bbtkendl);
211 std::map<std::string,int>::iterator i;
212 std::map<std::string,std::string>::iterator j;
213 for (i=GetInstance()->mMessageLevel.begin(),
214 j=GetInstance()->mMessageHelp.begin();
215 i!=GetInstance()->mMessageLevel.end();++i,++j) {
216 bbtkMessage("help",1, (*i).first);
218 k<(int)(GetInstance()->mMaxMessageLength+2-(*i).first.length());
220 bbtkMessageCont("help",1," ");
222 bbtkMessageCont("help",1, (*i).second << "\t"
223 << (*j).second << bbtkendl);
225 bbtkMessage("help",1,"==========================================="
229 std::string MessageManager::FormatKey(const std::string& key,
233 if ( GetInstance()->mMessageLevel["code"] != 0 )
236 std::stringstream ss;