1 // Created on: 1992-02-03
2 // Created by: Christian CAILLET
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16 
17 #ifndef _Interface_Check_HeaderFile
18 #define _Interface_Check_HeaderFile
19 
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22 
23 #include <TColStd_HSequenceOfHAsciiString.hxx>
24 #include <Standard_Transient.hxx>
25 #include <Standard_CString.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Standard_Integer.hxx>
28 #include <Interface_CheckStatus.hxx>
29 class Message_Msg;
30 class TCollection_HAsciiString;
31 
32 // resolve name collisions with X11 headers
33 #ifdef Status
34   #undef Status
35 #endif
36 
37 class Interface_Check;
38 DEFINE_STANDARD_HANDLE(Interface_Check, Standard_Transient)
39 
40 //! Defines a Check, as a list of Fail or Warning Messages under
41 //! a literal form, which can be empty. A Check can also bring an
42 //! Entity, which is the Entity to which the messages apply
43 //! (this Entity may be any Transient Object).
44 //!
45 //! Messages can be stored in two forms : the definitive form
46 //! (the only one by default), and another form, the original
47 //! form, which can be different if it contains values to be
48 //! inserted (integers, reals, strings)
49 //! The original form can be more suitable for some operations
50 //! such as counting messages
51 class Interface_Check : public Standard_Transient
52 {
53 
54 public:
55 
56 
57   //! Allows definition of a Sequence. Used also for Global Check
58   //! of an InterfaceModel (which stores global messages for file)
59   Standard_EXPORT Interface_Check();
60 
61   //! Defines a Check on an Entity
62   Standard_EXPORT Interface_Check(const Handle(Standard_Transient)& anentity);
63 
64   //! New name for AddFail (Msg)
65   Standard_EXPORT void SendFail (const Message_Msg& amsg);
66 
67   //! Records a new Fail message
68   Standard_EXPORT void AddFail (const Handle(TCollection_HAsciiString)& amess);
69 
70   //! Records a new Fail message under two forms : final,original
71   Standard_EXPORT void AddFail (const Handle(TCollection_HAsciiString)& amess, const Handle(TCollection_HAsciiString)& orig);
72 
73   //! Records a new Fail message given as "error text" directly
74   //! If <orig> is given, a distinct original form is recorded
75   //! else (D), the original form equates <amess>
76   Standard_EXPORT void AddFail (const Standard_CString amess, const Standard_CString orig = "");
77 
78   //! Records a new Fail from the definition of a Msg (Original+Value)
79   Standard_EXPORT void AddFail (const Message_Msg& amsg);
80 
81   //! Returns True if Check brings at least one Fail Message
82   Standard_EXPORT Standard_Boolean HasFailed() const;
83 
84   //! Returns count of recorded Fails
85   Standard_EXPORT Standard_Integer NbFails() const;
86 
87   //! Returns Fail Message as a String
88   //! Final form by default, Original form if <final> is False
89   Standard_EXPORT const Handle(TCollection_HAsciiString)& Fail (const Standard_Integer num, const Standard_Boolean final = Standard_True) const;
90 
91   //! Same as above, but returns a CString (to be printed ...)
92   //! Final form by default, Original form if <final> is False
93   Standard_EXPORT Standard_CString CFail (const Standard_Integer num, const Standard_Boolean final = Standard_True) const;
94 
95   //! Returns the list of Fails, for a frontal-engine logic
96   //! Final forms by default, Original forms if <final> is False
97   //! Can be empty
98   Standard_EXPORT Handle(TColStd_HSequenceOfHAsciiString) Fails (const Standard_Boolean final = Standard_True) const;
99 
100   //! New name for AddWarning
101   Standard_EXPORT void SendWarning (const Message_Msg& amsg);
102 
103   //! Records a new Warning message
104   Standard_EXPORT void AddWarning (const Handle(TCollection_HAsciiString)& amess);
105 
106   //! Records a new Warning message under two forms : final,original
107   Standard_EXPORT void AddWarning (const Handle(TCollection_HAsciiString)& amess, const Handle(TCollection_HAsciiString)& orig);
108 
109   //! Records a Warning message given as "warning message" directly
110   //! If <orig> is given, a distinct original form is recorded
111   //! else (D), the original form equates <amess>
112   Standard_EXPORT void AddWarning (const Standard_CString amess, const Standard_CString orig = "");
113 
114   //! Records a new Warning from the definition of a Msg (Original+Value)
115   Standard_EXPORT void AddWarning (const Message_Msg& amsg);
116 
117   //! Returns True if Check brings at least one Warning Message
118   Standard_EXPORT Standard_Boolean HasWarnings() const;
119 
120   //! Returns count of recorded Warning messages
121   Standard_EXPORT Standard_Integer NbWarnings() const;
122 
123   //! Returns Warning message as a String
124   //! Final form by default, Original form if <final> is False
125   Standard_EXPORT const Handle(TCollection_HAsciiString)& Warning (const Standard_Integer num, const Standard_Boolean final = Standard_True) const;
126 
127   //! Same as above, but returns a CString (to be printed ...)
128   //! Final form by default, Original form if <final> is False
129   Standard_EXPORT Standard_CString CWarning (const Standard_Integer num, const Standard_Boolean final = Standard_True) const;
130 
131   //! Returns the list of Warnings, for a frontal-engine logic
132   //! Final forms by default, Original forms if <final> is False
133   //! Can be empty
134   Standard_EXPORT Handle(TColStd_HSequenceOfHAsciiString) Warnings (const Standard_Boolean final = Standard_True) const;
135 
136   //! Records an information message
137   //! This does not change the status of the Check
138   Standard_EXPORT void SendMsg (const Message_Msg& amsg);
139 
140   //! Returns the count of recorded information messages
141   Standard_EXPORT Standard_Integer NbInfoMsgs() const;
142 
143   //! Returns information message as a String
144   Standard_EXPORT const Handle(TCollection_HAsciiString)& InfoMsg (const Standard_Integer num, const Standard_Boolean final = Standard_True) const;
145 
146   //! Same as above, but returns a CString (to be printed ...)
147   //! Final form by default, Original form if <final> is False
148   Standard_EXPORT Standard_CString CInfoMsg (const Standard_Integer num, const Standard_Boolean final = Standard_True) const;
149 
150   //! Returns the list of Info Msg, for a frontal-engine logic
151   //! Final forms by default, Original forms if <final> is False
152   //! Can be empty
153   Standard_EXPORT Handle(TColStd_HSequenceOfHAsciiString) InfoMsgs (const Standard_Boolean final = Standard_True) const;
154 
155   //! Returns the Check Status : OK, Warning or Fail
156   Standard_EXPORT Interface_CheckStatus Status() const;
157 
158   //! Tells if Check Status complies with a given one
159   //! (i.e. also status for query)
160   Standard_EXPORT Standard_Boolean Complies (const Interface_CheckStatus status) const;
161 
162   //! Tells if a message is brought by a Check, as follows :
163   //! <incl> = 0 : <mess> exactly matches one of the messages
164   //! <incl> < 0 : <mess> is contained by one of the messages
165   //! <incl> > 0 : <mess> contains one of the messages
166   //! For <status> : for CheckWarning and CheckFail, considers only
167   //! resp. Warning or Check messages. for CheckAny, considers all
168   //! other values are ignored (answer will be false)
169   Standard_EXPORT Standard_Boolean Complies (const Handle(TCollection_HAsciiString)& mess, const Standard_Integer incl, const Interface_CheckStatus status) const;
170 
171   //! Returns True if a Check is devoted to an entity; else, it is
172   //! global (for InterfaceModel's storing of global error messages)
173   Standard_EXPORT Standard_Boolean HasEntity() const;
174 
175   //! Returns the entity on which the Check has been defined
176   Standard_EXPORT const Handle(Standard_Transient)& Entity() const;
177 
178   //! Clears a check, in order to receive information from transfer
179   //! (Messages and Entity)
180   Standard_EXPORT void Clear();
181 
182   //! Clears the Fail Messages (for instance to keep only Warnings)
183   Standard_EXPORT void ClearFails();
184 
185   //! Clears the Warning Messages (for instance to keep only Fails)
186   Standard_EXPORT void ClearWarnings();
187 
188   //! Clears the Info Messages
189   Standard_EXPORT void ClearInfoMsgs();
190 
191   //! Removes the messages which comply with <mess>, as follows :
192   //! <incl> = 0 : <mess> exactly matches one of the messages
193   //! <incl> < 0 : <mess> is contained by one of the messages
194   //! <incl> > 0 : <mess> contains one of the messages
195   //! For <status> : for CheckWarning and CheckFail, considers only
196   //! resp. Warning or Check messages. for CheckAny, considers all
197   //! other values are ignored (nothing is done)
198   //! Returns True if at least one message has been removed, False else
199   Standard_EXPORT Standard_Boolean Remove (const Handle(TCollection_HAsciiString)& mess, const Standard_Integer incl, const Interface_CheckStatus status);
200 
201   //! Mends messages, according <pref> and <num>
202   //! According to <num>, works on the whole list of Fails if = 0(D)
203   //! or only one Fail message, given its rank
204   //! If <pref> is empty, converts Fail(s) to Warning(s)
205   //! Else, does the conversion but prefixes the new Warning(s) but
206   //! <pref> followed by a semi-column
207   //! Some reserved values of <pref> are :
208   //! "FM" : standard prefix "Mended" (can be translated)
209   //! "CF" : clears Fail(s)
210   //! "CW" : clears Warning(s) : here, <num> refers to Warning list
211   //! "CA" : clears all messages : here, <num> is ignored
212   Standard_EXPORT Standard_Boolean Mend (const Standard_CString pref, const Standard_Integer num = 0);
213 
214   //! Receives an entity result of a Transfer
215   Standard_EXPORT void SetEntity (const Handle(Standard_Transient)& anentity);
216 
217   //! same as SetEntity (old form kept for compatibility)
218   //! Warning : Does nothing if Entity field is not yet clear
219   Standard_EXPORT void GetEntity (const Handle(Standard_Transient)& anentity);
220 
221   //! Copies messages stored in another Check, cumulating
222   //! Does not regard other's Entity. Used to cumulate messages
223   Standard_EXPORT void GetMessages (const Handle(Interface_Check)& other);
224 
225   //! Copies messages converted into Warning messages
226   //! If failsonly is true, only Fails are taken, and converted
227   //! else, Warnings are taken too. Does not regard Entity
228   //! Used to keep Fail messages as Warning, after a recovery
229   Standard_EXPORT void GetAsWarning (const Handle(Interface_Check)& other, const Standard_Boolean failsonly);
230 
231   //! Prints the messages of the check to an Messenger
232   //! <level> = 1 : only fails
233   //! <level> = 2 : fails and warnings
234   //! <level> = 3 : all (fails, warnings, info msg)
235   //! <final> : if positive (D) prints final values of messages
236   //! if negative, prints originals
237   //! if null, prints both forms
238   Standard_EXPORT void Print (Standard_OStream& S, const Standard_Integer level, const Standard_Integer final = 1) const;
239 
240   //! Prints the messages of the check to the default trace file
241   //! By default, according to the default standard level
242   //! Else, according level (see method Print)
243   Standard_EXPORT void Trace (const Standard_Integer level = -1, const Standard_Integer final = 1) const;
244 
245 
246 
247 
248   DEFINE_STANDARD_RTTIEXT(Interface_Check,Standard_Transient)
249 
250 protected:
251 
252 
253 
254 
255 private:
256 
257 
258   Handle(TColStd_HSequenceOfHAsciiString) thefails;
259   Handle(TColStd_HSequenceOfHAsciiString) thefailo;
260   Handle(TColStd_HSequenceOfHAsciiString) thewarns;
261   Handle(TColStd_HSequenceOfHAsciiString) thewarno;
262   Handle(TColStd_HSequenceOfHAsciiString) theinfos;
263   Handle(TColStd_HSequenceOfHAsciiString) theinfoo;
264   Handle(Standard_Transient) theent;
265 
266 
267 };
268 
269 
270 
271 
272 
273 
274 
275 #endif // _Interface_Check_HeaderFile
276