Salome HOME
bf92b3af308f70a815628ecb56e4c92ff789ec13
[modules/shaper.git] / src / Events / Events_InfoMessage.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Events_InfoMessage.hxx
4 // Created:     31 May 2016
5 // Author:      Vitaly SMETANNIKOV
6
7 #ifndef Events_InfoMessage_H_
8 #define Events_InfoMessage_H_
9
10 #include <Events.h>
11 #include <Events_Message.h>
12 #include <Events_Loop.h>
13
14 /**\class Events_InfoMessage
15  * \ingroup EventsLoop
16  * \brief An event message for sending a string message which has to be translated.
17  */
18 class Events_InfoMessage: public Events_Message
19 {
20 public:
21
22   /// Constructor
23   /// \param theSender a pointer on sender object
24   Events_InfoMessage(const void* theSender = 0):Events_Message(Events_Loop::eventByName("InfoMessage"), theSender) {}
25
26   /// Constructor
27   /// \param theSender a pointer on sender object
28   Events_InfoMessage(const std::string& theContext, 
29     const std::string& theMsg, const void* theSender = 0):
30   Events_Message(Events_Loop::eventByName("InfoMessage"), theSender),
31     myContext(theContext), myMessage(theMsg) {}
32
33   /// default destructor   
34   virtual ~Events_InfoMessage() {}
35
36   /// Identifier of this event (one for all errors)
37   static Events_ID errorID()  { return Events_Loop::loop()->eventByName("InfoMessage"); }
38
39   /// Set a context string
40   /// \param theContext a context string
41   void  setContext(const std::string& theContext) { myContext = theContext; } 
42
43
44   /// Returns context string
45   std::string context() const { return myContext; }
46
47   /// Set message string for translation
48   /// \param theMsg the string of message
49   void setMessage(const std::string& theMsg) { myMessage = theMsg; } 
50
51   /// Returns message
52   std::string message() const { return myMessage; }
53
54   /// Add parameter for message string of string type
55   /// \param theParam the parameter
56   void addParameter(const std::string& theParam) 
57   { 
58     myParameters.push_back(theParam); 
59   }
60
61   /// Add parameter for message string of double type
62   /// \param theParam the parameter
63   void addParameter(double theParam) 
64   { 
65     char aBuf[50];
66     int n = sprintf_s(aBuf, "%g", theParam);
67     std::string aStr(aBuf);
68     myParameters.push_back(aStr); 
69   }
70
71   /// Add parameter for message string of integer type
72   /// \param theParam the parameter
73   void addParameter(int theParam) 
74   { 
75     char aBuf[50];
76     int n = sprintf_s(aBuf, "%d", theParam);
77     std::string aStr(aBuf);
78     myParameters.push_back(aStr); 
79   }
80
81   /// Returns list of parameters
82   std::list<std::string> parameters() const { return myParameters; }
83
84   /// Add parameter for message string of string type
85   /// \param theParam the parameter
86   Events_InfoMessage& arg(const std::string& theParam) { addParameter(theParam); return *this; }
87
88   /// Add parameter for message string of integer type
89   /// \param theParam the parameter
90   Events_InfoMessage& arg(int theParam) { addParameter(theParam); return *this; }
91
92   /// Add parameter for message string of double type
93   /// \param theParam the parameter
94   Events_InfoMessage& arg(double theParam) { addParameter(theParam); return *this; }
95
96   void send() { 
97     std::shared_ptr<Events_Message> aMsg(new Events_InfoMessage(*this));
98     Events_Loop::loop()->send(aMsg); 
99   }
100
101 private:
102
103   /// Context of the messgae
104   std::string myContext;
105
106   /// String of the message
107   std::string myMessage;
108
109   /// Parameters of the message
110   std::list<std::string> myParameters;
111 };
112
113 #endif