973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | |
42cf5bc1 |
15 | #include <Geom2d_CartesianPoint.hxx> |
7fd59977 |
16 | #include <Geom2d_Curve.hxx> |
42cf5bc1 |
17 | #include <Geom_CartesianPoint.hxx> |
7fd59977 |
18 | #include <Geom_Curve.hxx> |
19 | #include <Geom_Surface.hxx> |
42cf5bc1 |
20 | #include <gp_XY.hxx> |
21 | #include <gp_XYZ.hxx> |
22 | #include <Message_Msg.hxx> |
23 | #include <MoniTool_CaseData.hxx> |
7fd59977 |
24 | #include <OSD_Timer.hxx> |
42cf5bc1 |
25 | #include <Standard_Failure.hxx> |
26 | #include <Standard_Transient.hxx> |
27 | #include <Standard_Type.hxx> |
28 | #include <TCollection_AsciiString.hxx> |
29 | #include <TCollection_HAsciiString.hxx> |
30 | #include <TopAbs.hxx> |
31 | #include <TopoDS_HShape.hxx> |
32 | #include <TopoDS_Shape.hxx> |
997e128f |
33 | #include <NCollection_DataMap.hxx> |
7fd59977 |
34 | |
92efcf78 |
35 | IMPLEMENT_STANDARD_RTTIEXT(MoniTool_CaseData,MMgt_TShared) |
36 | |
997e128f |
37 | static NCollection_DataMap<TCollection_AsciiString, Standard_Integer> defch; |
38 | static NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> defms; |
7fd59977 |
39 | static Standard_Boolean stachr = Standard_False; |
40 | |
41 | //static OSD_Timer chrono; |
42 | // because merdouille link dynamique & perf, ne creer le static qu au 1er usage |
43 | static OSD_Timer& chrono() { |
44 | static OSD_Timer chr; |
45 | return chr; |
46 | } |
47 | |
48 | |
49 | MoniTool_CaseData::MoniTool_CaseData |
50 | (const Standard_CString caseid, const Standard_CString name) |
51 | : thesubst (0) , thecase (caseid) , thename (name) |
52 | { thecheck = DefCheck(caseid); } |
53 | |
54 | void MoniTool_CaseData::SetCaseId (const Standard_CString caseid) |
55 | { thecase.Clear(); thecase.AssignCat (caseid); thecheck = DefCheck(caseid); thesubst = 0; } |
56 | |
57 | void MoniTool_CaseData::SetName (const Standard_CString name) |
58 | { thename.Clear(); thename.AssignCat (name); thesubst = 0; } |
59 | |
60 | Standard_CString MoniTool_CaseData::CaseId () const |
61 | { return thecase.ToCString(); } |
62 | |
63 | Standard_CString MoniTool_CaseData::Name () const |
64 | { return thename.ToCString(); } |
65 | |
66 | |
67 | Standard_Boolean MoniTool_CaseData::IsCheck () const |
68 | { return (thecheck > 0); } |
69 | |
70 | Standard_Boolean MoniTool_CaseData::IsWarning () const |
71 | { return (thecheck == 1); } |
72 | |
73 | Standard_Boolean MoniTool_CaseData::IsFail () const |
74 | { return (thecheck == 2); } |
75 | |
76 | void MoniTool_CaseData::ResetCheck () |
77 | { thecheck = 0; } |
78 | |
79 | void MoniTool_CaseData::SetWarning () |
80 | { thecheck = 1; } |
81 | |
82 | void MoniTool_CaseData::SetFail () |
83 | { thecheck = 2; } |
84 | |
85 | // #### DATA #### |
86 | |
87 | void MoniTool_CaseData::SetChange () |
88 | { thesubst = -1; } |
89 | |
90 | void MoniTool_CaseData::SetReplace (const Standard_Integer num) |
91 | { thesubst = num; } |
92 | |
93 | void MoniTool_CaseData::AddData |
94 | (const Handle(Standard_Transient)& val, |
95 | const Standard_Integer kind, const Standard_CString name) |
96 | { |
97 | TCollection_AsciiString aname(name); |
98 | Standard_Integer subs = thesubst; |
99 | |
100 | // SetChange (calculer la position d apres Name) |
101 | if (thesubst < 0) { |
102 | if (name[0] != '\0') subs = NameNum (name); |
103 | } |
104 | // SetChange / SetReplace |
105 | if (subs > 0 && subs <= thedata.Length()) { |
106 | thedata.SetValue (subs,val); |
107 | thekind.SetValue (subs,kind); |
108 | if (aname.Length() > 0) thednam.SetValue (subs,aname); |
109 | // Ajout Normal |
110 | } else { |
111 | thedata.Append (val); |
112 | thekind.Append (kind); |
113 | thednam.Append (aname); |
114 | } |
115 | thesubst = 0; |
116 | } |
117 | |
9775fa61 |
118 | void MoniTool_CaseData::AddRaised (const Handle(Standard_Failure)& theException, const Standard_CString name) |
119 | { AddData ( theException,1,name); } |
7fd59977 |
120 | |
121 | void MoniTool_CaseData::AddShape |
122 | (const TopoDS_Shape& sh, const Standard_CString name) |
123 | { AddData ( new TopoDS_HShape(sh), 4,name); } |
124 | |
125 | void MoniTool_CaseData::AddXYZ |
126 | (const gp_XYZ& aXYZ, const Standard_CString name) |
127 | { AddData ( new Geom_CartesianPoint (aXYZ), 5,name); } |
128 | |
129 | void MoniTool_CaseData::AddXY |
130 | (const gp_XY& aXY, const Standard_CString name) |
131 | { AddData ( new Geom2d_CartesianPoint (aXY), 6,name); } |
132 | |
133 | void MoniTool_CaseData::AddReal |
134 | (const Standard_Real val, const Standard_CString name) |
135 | { AddData ( new Geom2d_CartesianPoint (val,0.), 8,name); } |
136 | |
137 | void MoniTool_CaseData::AddReals |
138 | (const Standard_Real v1, const Standard_Real v2, const Standard_CString name) |
139 | { AddData ( new Geom2d_CartesianPoint (v1,v2), 7,name); } |
140 | |
141 | void MoniTool_CaseData::AddCPU |
142 | (const Standard_Real lastCPU, const Standard_Real curCPU, |
143 | const Standard_CString name) |
144 | { |
145 | Standard_Real cpu = curCPU; |
146 | if (cpu == 0.) { |
147 | Standard_Real sec; Standard_Integer i1,i2; |
148 | chrono().Show (sec,i1,i2,cpu); |
149 | } |
150 | cpu = cpu - lastCPU; |
151 | AddData ( new Geom2d_CartesianPoint (cpu,0.), 9,name); |
152 | } |
153 | |
154 | Standard_Real MoniTool_CaseData::GetCPU () const |
155 | { |
156 | if (!stachr) { chrono().Start(); stachr = Standard_True; } |
157 | Standard_Real sec,cpu; Standard_Integer i1,i2; |
158 | chrono().Show (sec,i1,i2,cpu); |
159 | return cpu; |
160 | } |
161 | |
162 | Standard_Boolean MoniTool_CaseData::LargeCPU |
163 | (const Standard_Real maxCPU, |
164 | const Standard_Real lastCPU, const Standard_Real curCPU) const |
165 | { |
166 | Standard_Real cpu = curCPU; |
167 | if (cpu == 0.) { |
168 | Standard_Real sec; Standard_Integer i1,i2; |
169 | chrono().Show (sec,i1,i2,cpu); |
170 | } |
171 | cpu = cpu - lastCPU; |
172 | return (cpu >= maxCPU); |
173 | } |
174 | |
175 | void MoniTool_CaseData::AddGeom |
176 | (const Handle(Standard_Transient)& val, const Standard_CString name) |
177 | { AddData (val,3,name); } |
178 | |
179 | void MoniTool_CaseData::AddEntity |
180 | (const Handle(Standard_Transient)& val, const Standard_CString name) |
181 | { AddData (val,2,name); } |
182 | |
183 | void MoniTool_CaseData::AddText |
184 | (const Standard_CString text, const Standard_CString name) |
185 | { AddData (new TCollection_HAsciiString(text),10,name); } |
186 | |
187 | void MoniTool_CaseData::AddInteger |
188 | (const Standard_Integer val, const Standard_CString name) |
189 | { |
190 | Standard_Real rval = val; |
191 | AddData ( new Geom2d_CartesianPoint (rval,0.), 11,name); |
192 | } |
193 | |
194 | void MoniTool_CaseData::AddAny |
195 | (const Handle(Standard_Transient)& val, const Standard_CString name) |
196 | { AddData (val,0,name); } |
197 | |
198 | |
199 | void MoniTool_CaseData::RemoveData (const Standard_Integer num) |
200 | { |
201 | if (num < 1 || num > thedata.Length()) return; |
202 | thedata.Remove(num); thekind.Remove(num); thednam.Remove(num); |
203 | } |
204 | |
205 | // #### INTERROGATIONS #### |
206 | |
207 | Standard_Integer MoniTool_CaseData::NbData () const |
208 | { return thedata.Length(); } |
209 | |
210 | Handle(Standard_Transient) MoniTool_CaseData::Data |
211 | (const Standard_Integer nd) const |
212 | { |
213 | Handle(Standard_Transient) val; |
214 | if (nd < 1 || nd > thedata.Length()) return val; |
215 | return thedata (nd); |
216 | } |
217 | |
218 | Standard_Boolean MoniTool_CaseData::GetData |
219 | (const Standard_Integer nd, const Handle(Standard_Type)& type, |
220 | Handle(Standard_Transient)& val) const |
221 | { |
222 | if (type.IsNull()) return Standard_False; |
223 | if (nd < 1 || nd > thedata.Length()) return Standard_False; |
224 | Handle(Standard_Transient) v = thedata (nd); |
225 | if (v.IsNull()) return Standard_False; |
226 | if (!v->IsKind(type)) return Standard_False; |
227 | val = v; |
228 | return Standard_True; |
229 | } |
230 | |
231 | Standard_Integer MoniTool_CaseData::Kind |
232 | (const Standard_Integer nd) const |
233 | { |
234 | if (nd < 1 || nd > thekind.Length()) return 0; |
235 | return thekind (nd); |
236 | } |
237 | |
238 | |
239 | static const TCollection_AsciiString& nulname () |
240 | { |
241 | static TCollection_AsciiString nuln; |
242 | return nuln; |
243 | } |
244 | |
245 | const TCollection_AsciiString& MoniTool_CaseData::Name |
246 | (const Standard_Integer nd) const |
247 | { |
248 | if (nd < 1 || nd > thednam.Length()) return nulname(); |
249 | return thednam(nd); |
250 | } |
251 | |
252 | static Standard_Integer NameKind (const Standard_CString name) |
253 | { |
254 | char n0 = name[0]; |
255 | if (n0 == 'A' && name[1] == 'N' && name[2] == 'Y' && name[3] == '\0') return 0; |
256 | if (n0 == 'E') { |
257 | if (name[1] == 'X' && name[2] == '\0') return 1; |
258 | if (name[1] == 'N' && name[2] == '\0') return 2; |
259 | return 0; |
260 | } |
261 | if (n0 == 'G' && name[1] == '\0') return 3; |
262 | if (n0 == 'S' && name[1] == 'H' && name[2] == '\0') return 4; |
263 | if (n0 == 'X' && name[1] == 'Y') { |
264 | if (name[2] == 'Z' && name[3] == '\0') return 5; |
265 | if (name[2] == '\0') return 6; |
266 | } |
267 | if (n0 == 'U' && name[1] == 'V' && name[2] == '\0') return 6; |
268 | if (n0 == 'R') { |
269 | if (name[1] == '\0') return 8; |
270 | if (name[1] == 'R' && name[2] == '\0') return 7; |
271 | } |
272 | if (n0 == 'C' && name[1] == 'P' && name[2] == 'U' && name[3] == '\0') return 9; |
273 | if (n0 == 'T' && name[1] == '\0') return 10; |
274 | if (n0 == 'I' && name[1] == '\0') return 11; |
275 | |
276 | return 0; |
277 | } |
278 | |
279 | static Standard_Integer NameRank (const Standard_CString name) |
280 | { |
281 | for (Standard_Integer i = 0; name[i] != '\0'; i ++) { |
282 | if (name[i] == ':' && name[i+1] != '\0') return atoi(&name[i+1]); |
283 | } |
284 | return 1; |
285 | } |
286 | |
287 | Standard_Integer MoniTool_CaseData::NameNum |
288 | (const Standard_CString name) const |
289 | { |
290 | if (!name || name[0] == '\0') return 0; |
291 | Standard_Integer nd, nn = 0, nb = NbData(); |
292 | for (nd = 1; nd <= nb; nd ++) { |
293 | if (thednam(nd).IsEqual(name)) return nd; |
294 | } |
295 | |
296 | Standard_Integer kind = NameKind (name); |
297 | if (kind < 0) return 0; |
298 | Standard_Integer num = NameRank (name); |
299 | |
300 | for (nd = 1; nd <= nb; nd ++) { |
301 | if (thekind(nd) == kind) { |
302 | nn ++; |
303 | if (nn == num) return nd; |
304 | } |
305 | } |
306 | return 0; |
307 | } |
308 | |
309 | |
310 | // #### RETOUR DES VALEURS #### |
311 | |
312 | TopoDS_Shape MoniTool_CaseData::Shape |
313 | (const Standard_Integer nd) const |
314 | { |
315 | TopoDS_Shape sh; |
316 | Handle(TopoDS_HShape) hs = Handle(TopoDS_HShape)::DownCast (Data(nd)); |
317 | if (!hs.IsNull()) sh = hs->Shape(); |
318 | return sh; |
319 | } |
320 | |
321 | Standard_Boolean MoniTool_CaseData::XYZ |
322 | (const Standard_Integer nd, gp_XYZ& val) const |
323 | { |
324 | Handle(Geom_CartesianPoint) p = Handle(Geom_CartesianPoint)::DownCast(Data(nd)); |
325 | if (p.IsNull()) return Standard_False; |
326 | val = p->Pnt().XYZ(); |
327 | return Standard_True; |
328 | } |
329 | |
330 | Standard_Boolean MoniTool_CaseData::XY |
331 | (const Standard_Integer nd, gp_XY& val) const |
332 | { |
333 | Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd)); |
334 | if (p.IsNull()) return Standard_False; |
335 | val = p->Pnt2d().XY(); |
336 | return Standard_True; |
337 | } |
338 | |
339 | Standard_Boolean MoniTool_CaseData::Reals |
340 | (const Standard_Integer nd, |
341 | Standard_Real& v1, Standard_Real& v2) const |
342 | { |
343 | Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd)); |
344 | if (p.IsNull()) return Standard_False; |
345 | v1 = p->X(); v2 = p->Y(); |
346 | return Standard_True; |
347 | } |
348 | |
349 | |
350 | Standard_Boolean MoniTool_CaseData::Real |
351 | (const Standard_Integer nd, |
352 | Standard_Real& val) const |
353 | { |
354 | Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd)); |
355 | if (p.IsNull()) return Standard_False; |
356 | val = p->X(); |
357 | return Standard_True; |
358 | } |
359 | |
360 | Standard_Boolean MoniTool_CaseData::Text |
361 | (const Standard_Integer nd, |
362 | Standard_CString& text) const |
363 | { |
364 | Handle(TCollection_HAsciiString) t = Handle(TCollection_HAsciiString)::DownCast(Data(nd)); |
365 | if (t.IsNull()) return Standard_False; |
366 | text = t->ToCString(); |
367 | return Standard_True; |
368 | } |
369 | |
370 | Standard_Boolean MoniTool_CaseData::Integer |
371 | (const Standard_Integer nd, |
372 | Standard_Integer& val) const |
373 | { |
374 | Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd)); |
375 | // if (p.IsNull()) return Standard_False; |
376 | if (thekind(nd) != 11) return Standard_False; |
377 | Standard_Real rval = p->X(); |
378 | val = (Standard_Integer)rval; |
379 | return Standard_True; |
380 | } |
381 | |
382 | |
383 | // #### MESSAGES ET DEFINITIONS #### |
384 | |
385 | Message_Msg MoniTool_CaseData::Msg () const |
386 | { |
387 | Standard_CString defm = DefMsg (thecase.ToCString()); |
388 | |
389 | // A REPRENDRE COMPLETEMENT ! Il faut analyser defm = mescode + variables |
390 | Message_Msg mess; |
391 | mess.Set (defm); |
392 | |
393 | return mess; |
394 | } |
395 | |
396 | |
397 | void MoniTool_CaseData::SetDefWarning (const Standard_CString acode) |
997e128f |
398 | { defch.Bind(acode,1); } |
7fd59977 |
399 | |
400 | void MoniTool_CaseData::SetDefFail (const Standard_CString acode) |
997e128f |
401 | { defch.Bind(acode,2); } |
7fd59977 |
402 | |
403 | Standard_Integer MoniTool_CaseData::DefCheck (const Standard_CString acode) |
404 | { |
405 | Standard_Integer val; |
997e128f |
406 | if (!defch.Find(acode, val)) |
407 | val = 0; |
7fd59977 |
408 | return val; |
409 | } |
410 | |
411 | |
412 | void MoniTool_CaseData::SetDefMsg |
413 | (const Standard_CString casecode, const Standard_CString mesdef) |
414 | { |
415 | Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString (mesdef); |
997e128f |
416 | defms.Bind(casecode,str); |
7fd59977 |
417 | } |
418 | |
419 | Standard_CString MoniTool_CaseData::DefMsg (const Standard_CString casecode) |
420 | { |
997e128f |
421 | Handle(Standard_Transient) aTStr; |
422 | if (!defms.Find(casecode, aTStr)) return ""; |
423 | Handle(TCollection_HAsciiString) str = Handle(TCollection_HAsciiString)::DownCast(aTStr); |
7fd59977 |
424 | if (str.IsNull()) return ""; |
425 | return str->ToCString(); |
426 | } |