1 // Created on: 1998-04-01
2 // Created by: Christian CAILLET
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _MoniTool_CaseData_HeaderFile
18 #define _MoniTool_CaseData_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <Standard_Integer.hxx>
24 #include <TCollection_AsciiString.hxx>
25 #include <TColStd_SequenceOfTransient.hxx>
26 #include <TColStd_SequenceOfInteger.hxx>
27 #include <TColStd_SequenceOfAsciiString.hxx>
28 #include <Standard_Transient.hxx>
29 #include <Standard_CString.hxx>
30 #include <Standard_Boolean.hxx>
31 #include <Standard_Real.hxx>
32 #include <Standard_Type.hxx>
33 class Standard_Transient;
37 class TCollection_AsciiString;
41 class MoniTool_CaseData;
42 DEFINE_STANDARD_HANDLE(MoniTool_CaseData, Standard_Transient)
44 //! This class is intended to record data attached to a case to be
47 //! * internal, i.e. for immediate debug
48 //! for instance, on an abnormal exception, fill a CaseData
49 //! in a DB (see class DB) then look at its content by XSDRAW
50 //! * to record abnormal situation, which cause a warning or fail
51 //! message, for instance during a transfer
52 //! This will allow, firstly to build a more comprehensive
53 //! message (with associated data), secondly to help seeing
55 //! * to record data in order to fix a problem
56 //! If a CASE is well defined and its fix is well known too,
57 //! recording a CaseData which identifies the CASE will allow
58 //! to furstherly call the appropriate fix routine
60 //! A CaseData is defined by
61 //! * an optional CASE identifier
62 //! If it is defined, this will allow systematic exploitation
63 //! such as calling a fix routine
64 //! * an optional Check Status, Warning or Fail, else it is Info
65 //! * a NAME : it just allows to identify where this CaseData was
66 //! created (help to debug)
69 //! Each Data has a type (integer, real etc...) and can have a name
70 //! Hence, each data may be identified by :
71 //! * its absolute rank (from 1 to NbData)
72 //! * its name if it has one (exact matching)
73 //! * else, an interpreted identifier, which gives the type and
74 //! the rank in the type (for instance, first integer; etc)
76 class MoniTool_CaseData : public Standard_Transient
82 //! Creates a CaseData with a CaseId and a Name
83 //! (by default not defined)
84 Standard_EXPORT MoniTool_CaseData(const Standard_CString caseid = "", const Standard_CString name = "");
87 Standard_EXPORT void SetCaseId (const Standard_CString caseid);
90 Standard_EXPORT void SetName (const Standard_CString name);
92 //! Returns the CaseId
93 Standard_EXPORT Standard_CString CaseId() const;
96 Standard_EXPORT Standard_CString Name() const;
98 //! Tells if <me> is Check (Warning or Fail), else it is Info
99 Standard_EXPORT Standard_Boolean IsCheck() const;
101 //! Tells if <me> is Warning
102 Standard_EXPORT Standard_Boolean IsWarning() const;
104 //! Tells if <me> is Fail
105 Standard_EXPORT Standard_Boolean IsFail() const;
107 //! Resets Check Status, i.e. sets <me> as Info
108 Standard_EXPORT void ResetCheck();
110 //! Sets <me> as Warning
111 Standard_EXPORT void SetWarning();
113 //! Sets <me> as Fail
114 Standard_EXPORT void SetFail();
116 //! Sets the next Add... not to add but to change the data item
117 //! designated by its name.
118 //! If next Add... is not called with a name, SetChange is ignored
119 //! Reset by next Add... , whatever <num> is correct or not
120 Standard_EXPORT void SetChange();
122 //! Sets the next Add... not to add but to replace the data item
123 //! <num>, if <num> is between 1 and NbData.
124 //! Reset by next Add... , whatever <num> is correct or not
125 Standard_EXPORT void SetReplace (const Standard_Integer num);
127 //! Unitary adding a data; rather internal
128 Standard_EXPORT void AddData (const Handle(Standard_Transient)& val, const Standard_Integer kind, const Standard_CString name = "");
130 //! Adds the currently caught exception
131 Standard_EXPORT void AddRaised (const Handle(Standard_Failure)& theException, const Standard_CString name = "");
133 //! Adds a Shape (recorded as a HShape)
134 Standard_EXPORT void AddShape (const TopoDS_Shape& sh, const Standard_CString name = "");
137 Standard_EXPORT void AddXYZ (const gp_XYZ& aXYZ, const Standard_CString name = "");
140 Standard_EXPORT void AddXY (const gp_XY& aXY, const Standard_CString name = "");
143 Standard_EXPORT void AddReal (const Standard_Real val, const Standard_CString name = "");
145 //! Adds two reals (for instance, two parameters)
146 Standard_EXPORT void AddReals (const Standard_Real v1, const Standard_Real v2, const Standard_CString name = "");
148 //! Adds the CPU time between lastCPU and now
149 //! if <curCPU> is given, the CPU amount is curCPU-lastCPU
150 //! else it is currently measured CPU - lastCPU
151 //! lastCPU has been read by call to GetCPU
152 //! See GetCPU to get amount, and LargeCPU to test large amount
153 Standard_EXPORT void AddCPU (const Standard_Real lastCPU, const Standard_Real curCPU = 0, const Standard_CString name = "");
155 //! Returns the current amount of CPU
156 //! This allows to laterly test and record CPU amount
157 //! Its value has to be given to LargeCPU and AddCPU
158 Standard_EXPORT Standard_Real GetCPU() const;
160 //! Tells if a CPU time amount is large
161 //! <maxCPU> gives the amount over which an amount is large
162 //! <lastCPU> gives the start CPU amount
163 //! if <curCPU> is given, the tested CPU amount is curCPU-lastCPU
164 //! else it is currently measured CPU - lastCPU
165 Standard_EXPORT Standard_Boolean LargeCPU (const Standard_Real maxCPU, const Standard_Real lastCPU, const Standard_Real curCPU = 0) const;
167 //! Adds a Geometric as a Transient (Curve, Surface ...)
168 Standard_EXPORT void AddGeom (const Handle(Standard_Transient)& geom, const Standard_CString name = "");
170 //! Adds a Transient, as an Entity from an InterfaceModel for
171 //! instance : it will then be printed with the help of a DBPE
172 Standard_EXPORT void AddEntity (const Handle(Standard_Transient)& ent, const Standard_CString name = "");
174 //! Adds a Text (as HAsciiString)
175 Standard_EXPORT void AddText (const Standard_CString text, const Standard_CString name = "");
178 Standard_EXPORT void AddInteger (const Standard_Integer val, const Standard_CString name = "");
180 //! Adds a Transient, with no more meaning
181 Standard_EXPORT void AddAny (const Handle(Standard_Transient)& val, const Standard_CString name = "");
183 //! Removes a Data from its rank. Does nothing if out of range
184 Standard_EXPORT void RemoveData (const Standard_Integer num);
186 //! Returns the count of data recorded to a set
187 Standard_EXPORT Standard_Integer NbData() const;
189 //! Returns a data item (n0 <nd> in the set <num>)
190 Standard_EXPORT Handle(Standard_Transient) Data (const Standard_Integer nd) const;
192 //! Returns a data item, under control of a Type
193 //! If the data item is kind of this type, it is returned in <val>
194 //! and the returned value is True
195 //! Else, <val> is unchanged and the returned value is False
196 Standard_EXPORT Standard_Boolean GetData (const Standard_Integer nd, const Handle(Standard_Type)& type, Handle(Standard_Transient)& val) const;
198 //! Returns the kind of a data :
199 //! KIND TYPE MEANING
200 //! 0 ANY any (not one of the following)
201 //! 1 EX raised exception
209 //! 9 CPU CPU (1 real)
213 //! For NameNum, these codes for TYPE must be given exact
214 //! i.e. SH for a Shape, not S nor SHAPE nor SOLID etc
215 Standard_EXPORT Standard_Integer Kind (const Standard_Integer nd) const;
217 //! Returns the name of a data. If it has no name, the string is
218 //! empty (length = 0)
219 Standard_EXPORT const TCollection_AsciiString& Name (const Standard_Integer nd) const;
221 //! Returns the first suitable data rank for a given name
222 //! Exact matching (exact case, no completion) is required
223 //! Firstly checks the recorded names
224 //! If not found, considers the name as follows :
225 //! Name = "TYPE" : search for the first item with this TYPE
226 //! Name = "TYPE:nn" : search for the nn.th item with this TYPE
227 //! See allowed values in method Kind
228 Standard_EXPORT Standard_Integer NameNum (const Standard_CString name) const;
230 //! Returns a data as a shape, Null if not a shape
231 Standard_EXPORT TopoDS_Shape Shape (const Standard_Integer nd) const;
233 //! Returns a data as a XYZ (i.e. Geom_CartesianPoint)
234 //! Returns False if not the good type
235 Standard_EXPORT Standard_Boolean XYZ (const Standard_Integer nd, gp_XYZ& val) const;
237 //! Returns a data as a XY (i.e. Geom2d_CartesianPoint)
238 //! Returns False if not the good type
239 Standard_EXPORT Standard_Boolean XY (const Standard_Integer nd, gp_XY& val) const;
241 //! Returns a couple of reals (stored in Geom2d_CartesianPoint)
242 Standard_EXPORT Standard_Boolean Reals (const Standard_Integer nd, Standard_Real& v1, Standard_Real& v2) const;
244 //! Returns a real or CPU amount (stored in Geom2d_CartesianPoint)
245 //! (allows an Integer converted to a Real)
246 Standard_EXPORT Standard_Boolean Real (const Standard_Integer nd, Standard_Real& val) const;
248 //! Returns a text (stored in TCollection_HAsciiString)
249 Standard_EXPORT Standard_Boolean Text (const Standard_Integer nd, Standard_CString& text) const;
251 //! Returns an Integer
252 Standard_EXPORT Standard_Boolean Integer (const Standard_Integer nd, Standard_Integer& val) const;
254 //! Returns a Msg from a CaseData : it is build from DefMsg, which
255 //! gives the message code plus the designation of items of the
256 //! CaseData to be added to the Msg
257 //! Empty if no message attached
259 //! Remains to be implemented
260 Standard_EXPORT Message_Msg Msg() const;
262 //! Sets a Code to give a Warning
263 Standard_EXPORT static void SetDefWarning (const Standard_CString acode);
265 //! Sets a Code to give a Fail
266 Standard_EXPORT static void SetDefFail (const Standard_CString acode);
268 //! Returns Check Status for a Code : 0 non/info (default),
269 //! 1 warning, 2 fail
271 //! Remark : DefCheck is used to set the check status of a
272 //! CaseData when it is attached to a case code, it can be changed
273 //! later (by SetFail, SetWarning, ResetCheck)
274 Standard_EXPORT static Standard_Integer DefCheck (const Standard_CString acode);
276 //! Attaches a message definition to a case code
277 //! This definition includes the message code plus designation of
278 //! items of the CaseData to be added to the message (this part
279 //! not yet implemented)
280 Standard_EXPORT static void SetDefMsg (const Standard_CString casecode, const Standard_CString mesdef);
282 //! Returns the message definition for a case code
283 //! Empty if no message attached
284 Standard_EXPORT static Standard_CString DefMsg (const Standard_CString casecode);
289 DEFINE_STANDARD_RTTIEXT(MoniTool_CaseData,Standard_Transient)
299 Standard_Integer thecheck;
300 Standard_Integer thesubst;
301 TCollection_AsciiString thecase;
302 TCollection_AsciiString thename;
303 TColStd_SequenceOfTransient thedata;
304 TColStd_SequenceOfInteger thekind;
305 TColStd_SequenceOfAsciiString thednam;
316 #endif // _MoniTool_CaseData_HeaderFile