1 /*=========================================================================
3 Module: $RCSfile: bbtkMessageManager.cxx,v $
5 Date: $Date: 2009/05/19 10:19:23 $
6 Version: $Revision: 1.15 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief class MessageManager : Manages the messages displayed by bbtk (code)
35 #include "bbtkMessageManager.h"
40 MessageManager::MessageManager()
41 : mMaxMessageLength(8)//, mAllLevel(0), mMaxLevel(9)
46 mMessageLevel[key] = 0;
47 mMessageHelp[key] = "Minimum level for all kind of messages";
48 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
50 mMessageLevel[key] = 9;
51 mMessageHelp[key] = "Maximum level for all kind of messages";
52 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
54 mMessageLevel[key] = 0;
55 mMessageHelp[key] = "Messages generated by the core classes of the lib";
56 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
58 mMessageLevel[key] = 0;
59 mMessageHelp[key] = "Messages related to box processing";
60 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
62 mMessageLevel[key] = 1;
63 mMessageHelp[key] = "Help messages";
64 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
66 mMessageLevel[key] = 0;
67 mMessageHelp[key] = "Error messages";
68 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
70 mMessageLevel[key] = 1;
71 mMessageHelp[key] = "Warning messages";
72 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
74 mMessageLevel[key] = 1;
75 mMessageHelp[key] = "Output messages";
76 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
78 mMessageLevel[key] = 0;
79 mMessageHelp[key] = "Debug messages";
80 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
82 mMessageLevel[key] = 0;
83 mMessageHelp[key] = "Configuration related messages";
84 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
86 mMessageLevel[key] = 0;
87 mMessageHelp[key] = "Data related messages";
88 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
90 mMessageLevel[key] = 0;
91 mMessageHelp[key] = "Widgets related messages";
92 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
94 mMessageLevel[key] = 0;
95 mMessageHelp[key] = "wxWidgets related messages";
96 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
98 mMessageLevel[key] = 0;
99 mMessageHelp[key] = "Qt related messages";
100 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
102 mMessageLevel[key] = 0;
103 mMessageHelp[key] = "Graphical user interface related messages";
104 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
106 mMessageLevel[key] = 0;
107 mMessageHelp[key] = "object memory related messages";
108 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
110 mMessageLevel[key] = 0;
111 mMessageHelp[key] = "Packages related messages";
112 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
114 mMessageLevel[key] = 0;
115 mMessageHelp[key] = "Connections related messages";
116 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
118 mMessageLevel[key] = 0;
119 mMessageHelp[key] = "Box i/o changes related messages";
120 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
126 MessageManager::~MessageManager()
128 // std::cout << "~MessageManager"<<std::endl;
133 MessageManager* MessageManager::GetInstance()
135 static MessageManager* m = 0;
136 if (!m) m = new MessageManager();
140 bool MessageManager::RegisterMessageType(std::string key,
142 unsigned char default_level)
144 GetInstance()->mMessageLevel[key] = default_level;
145 GetInstance()->mMessageHelp[key] = help;
146 if (GetInstance()->mMaxMessageLength<key.length())
147 GetInstance()->mMaxMessageLength = key.length();
154 void MessageManager::SetMessageLevel(std::string key,
157 std::map<std::string,int>::iterator i;
158 i = GetInstance()->mMessageLevel.find(key);
159 if (i!=GetInstance()->mMessageLevel.end())
165 bbtkWarning("MessageManager::SetMessageLevel : message type=<"
166 <<key<<"> unregistered");
173 int MessageManager::GetMessageLevel(std::string key)
175 int l = GetInstance()->mMessageLevel["all"];
176 std::map<std::string,int>::iterator i =
177 GetInstance()->mMessageLevel.find(key);
178 if (i!=GetInstance()->mMessageLevel.end()) {
179 if ( (*i).second > l ) l = (*i).second;
181 int m = GetInstance()->mMessageLevel["max"];
188 void MessageManager::PrintInfo()
190 bbtkMessage("Help",1,"================ Messages ================="
192 bbtkMessage("Help",1, "Kind");
194 k<(int)(GetInstance()->mMaxMessageLength-2);
197 bbtkMessageCont("Help",1," ");
199 bbtkMessageCont("Help",1,"Level Nature" << bbtkendl);
200 std::map<std::string,int>::iterator i;
201 std::map<std::string,std::string>::iterator j;
202 for (i=GetInstance()->mMessageLevel.begin(),
203 j=GetInstance()->mMessageHelp.begin();
204 i!=GetInstance()->mMessageLevel.end();++i,++j) {
205 bbtkMessage("Help",1, (*i).first);
207 k<(int)(GetInstance()->mMaxMessageLength+2-(*i).first.length());
209 bbtkMessageCont("Help",1," ");
211 bbtkMessageCont("Help",1, (*i).second << "\t"
212 << (*j).second << bbtkendl);
214 bbtkMessage("Help",1,"==========================================="