1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Geom2d_CartesianPoint.hxx>
16 #include <Geom2d_Curve.hxx>
17 #include <Geom_CartesianPoint.hxx>
20 #include <Message_Msg.hxx>
21 #include <MoniTool_CaseData.hxx>
22 #include <OSD_Timer.hxx>
23 #include <Standard_Failure.hxx>
24 #include <Standard_Transient.hxx>
25 #include <Standard_Type.hxx>
26 #include <TCollection_AsciiString.hxx>
27 #include <TCollection_HAsciiString.hxx>
28 #include <TopoDS_HShape.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <NCollection_DataMap.hxx>
32 IMPLEMENT_STANDARD_RTTIEXT(MoniTool_CaseData,Standard_Transient)
34 static NCollection_DataMap<TCollection_AsciiString, Standard_Integer> defch;
35 static NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> defms;
36 static Standard_Boolean stachr = Standard_False;
38 //static OSD_Timer chrono;
39 // because merdouille link dynamique & perf, ne creer le static qu au 1er usage
40 static OSD_Timer& chrono() {
46 MoniTool_CaseData::MoniTool_CaseData
47 (const Standard_CString caseid, const Standard_CString name)
48 : thesubst (0) , thecase (caseid) , thename (name)
49 { thecheck = DefCheck(caseid); }
51 void MoniTool_CaseData::SetCaseId (const Standard_CString caseid)
52 { thecase.Clear(); thecase.AssignCat (caseid); thecheck = DefCheck(caseid); thesubst = 0; }
54 void MoniTool_CaseData::SetName (const Standard_CString name)
55 { thename.Clear(); thename.AssignCat (name); thesubst = 0; }
57 Standard_CString MoniTool_CaseData::CaseId () const
58 { return thecase.ToCString(); }
60 Standard_CString MoniTool_CaseData::Name () const
61 { return thename.ToCString(); }
64 Standard_Boolean MoniTool_CaseData::IsCheck () const
65 { return (thecheck > 0); }
67 Standard_Boolean MoniTool_CaseData::IsWarning () const
68 { return (thecheck == 1); }
70 Standard_Boolean MoniTool_CaseData::IsFail () const
71 { return (thecheck == 2); }
73 void MoniTool_CaseData::ResetCheck ()
76 void MoniTool_CaseData::SetWarning ()
79 void MoniTool_CaseData::SetFail ()
84 void MoniTool_CaseData::SetChange ()
87 void MoniTool_CaseData::SetReplace (const Standard_Integer num)
90 void MoniTool_CaseData::AddData
91 (const Handle(Standard_Transient)& val,
92 const Standard_Integer kind, const Standard_CString name)
94 TCollection_AsciiString aname(name);
95 Standard_Integer subs = thesubst;
97 // SetChange (calculer la position d apres Name)
99 if (name[0] != '\0') subs = NameNum (name);
101 // SetChange / SetReplace
102 if (subs > 0 && subs <= thedata.Length()) {
103 thedata.SetValue (subs,val);
104 thekind.SetValue (subs,kind);
105 if (aname.Length() > 0) thednam.SetValue (subs,aname);
108 thedata.Append (val);
109 thekind.Append (kind);
110 thednam.Append (aname);
115 void MoniTool_CaseData::AddRaised (const Handle(Standard_Failure)& theException, const Standard_CString name)
116 { AddData ( theException,1,name); }
118 void MoniTool_CaseData::AddShape
119 (const TopoDS_Shape& sh, const Standard_CString name)
120 { AddData ( new TopoDS_HShape(sh), 4,name); }
122 void MoniTool_CaseData::AddXYZ
123 (const gp_XYZ& aXYZ, const Standard_CString name)
124 { AddData ( new Geom_CartesianPoint (aXYZ), 5,name); }
126 void MoniTool_CaseData::AddXY
127 (const gp_XY& aXY, const Standard_CString name)
128 { AddData ( new Geom2d_CartesianPoint (aXY), 6,name); }
130 void MoniTool_CaseData::AddReal
131 (const Standard_Real val, const Standard_CString name)
132 { AddData ( new Geom2d_CartesianPoint (val,0.), 8,name); }
134 void MoniTool_CaseData::AddReals
135 (const Standard_Real v1, const Standard_Real v2, const Standard_CString name)
136 { AddData ( new Geom2d_CartesianPoint (v1,v2), 7,name); }
138 void MoniTool_CaseData::AddCPU
139 (const Standard_Real lastCPU, const Standard_Real curCPU,
140 const Standard_CString name)
142 Standard_Real cpu = curCPU;
144 Standard_Real sec; Standard_Integer i1,i2;
145 chrono().Show (sec,i1,i2,cpu);
148 AddData ( new Geom2d_CartesianPoint (cpu,0.), 9,name);
151 Standard_Real MoniTool_CaseData::GetCPU () const
153 if (!stachr) { chrono().Start(); stachr = Standard_True; }
154 Standard_Real sec,cpu; Standard_Integer i1,i2;
155 chrono().Show (sec,i1,i2,cpu);
159 Standard_Boolean MoniTool_CaseData::LargeCPU
160 (const Standard_Real maxCPU,
161 const Standard_Real lastCPU, const Standard_Real curCPU) const
163 Standard_Real cpu = curCPU;
165 Standard_Real sec; Standard_Integer i1,i2;
166 chrono().Show (sec,i1,i2,cpu);
169 return (cpu >= maxCPU);
172 void MoniTool_CaseData::AddGeom
173 (const Handle(Standard_Transient)& val, const Standard_CString name)
174 { AddData (val,3,name); }
176 void MoniTool_CaseData::AddEntity
177 (const Handle(Standard_Transient)& val, const Standard_CString name)
178 { AddData (val,2,name); }
180 void MoniTool_CaseData::AddText
181 (const Standard_CString text, const Standard_CString name)
182 { AddData (new TCollection_HAsciiString(text),10,name); }
184 void MoniTool_CaseData::AddInteger
185 (const Standard_Integer val, const Standard_CString name)
187 Standard_Real rval = val;
188 AddData ( new Geom2d_CartesianPoint (rval,0.), 11,name);
191 void MoniTool_CaseData::AddAny
192 (const Handle(Standard_Transient)& val, const Standard_CString name)
193 { AddData (val,0,name); }
196 void MoniTool_CaseData::RemoveData (const Standard_Integer num)
198 if (num < 1 || num > thedata.Length()) return;
199 thedata.Remove(num); thekind.Remove(num); thednam.Remove(num);
202 // #### INTERROGATIONS ####
204 Standard_Integer MoniTool_CaseData::NbData () const
205 { return thedata.Length(); }
207 Handle(Standard_Transient) MoniTool_CaseData::Data
208 (const Standard_Integer nd) const
210 Handle(Standard_Transient) val;
211 if (nd < 1 || nd > thedata.Length()) return val;
215 Standard_Boolean MoniTool_CaseData::GetData
216 (const Standard_Integer nd, const Handle(Standard_Type)& type,
217 Handle(Standard_Transient)& val) const
219 if (type.IsNull()) return Standard_False;
220 if (nd < 1 || nd > thedata.Length()) return Standard_False;
221 Handle(Standard_Transient) v = thedata (nd);
222 if (v.IsNull()) return Standard_False;
223 if (!v->IsKind(type)) return Standard_False;
225 return Standard_True;
228 Standard_Integer MoniTool_CaseData::Kind
229 (const Standard_Integer nd) const
231 if (nd < 1 || nd > thekind.Length()) return 0;
236 static const TCollection_AsciiString& nulname ()
238 static TCollection_AsciiString nuln;
242 const TCollection_AsciiString& MoniTool_CaseData::Name
243 (const Standard_Integer nd) const
245 if (nd < 1 || nd > thednam.Length()) return nulname();
249 static Standard_Integer NameKind (const Standard_CString name)
252 if (n0 == 'A' && name[1] == 'N' && name[2] == 'Y' && name[3] == '\0') return 0;
254 if (name[1] == 'X' && name[2] == '\0') return 1;
255 if (name[1] == 'N' && name[2] == '\0') return 2;
258 if (n0 == 'G' && name[1] == '\0') return 3;
259 if (n0 == 'S' && name[1] == 'H' && name[2] == '\0') return 4;
260 if (n0 == 'X' && name[1] == 'Y') {
261 if (name[2] == 'Z' && name[3] == '\0') return 5;
262 if (name[2] == '\0') return 6;
264 if (n0 == 'U' && name[1] == 'V' && name[2] == '\0') return 6;
266 if (name[1] == '\0') return 8;
267 if (name[1] == 'R' && name[2] == '\0') return 7;
269 if (n0 == 'C' && name[1] == 'P' && name[2] == 'U' && name[3] == '\0') return 9;
270 if (n0 == 'T' && name[1] == '\0') return 10;
271 if (n0 == 'I' && name[1] == '\0') return 11;
276 static Standard_Integer NameRank (const Standard_CString name)
278 for (Standard_Integer i = 0; name[i] != '\0'; i ++) {
279 if (name[i] == ':' && name[i+1] != '\0') return atoi(&name[i+1]);
284 Standard_Integer MoniTool_CaseData::NameNum
285 (const Standard_CString name) const
287 if (!name || name[0] == '\0') return 0;
288 Standard_Integer nd, nn = 0, nb = NbData();
289 for (nd = 1; nd <= nb; nd ++) {
290 if (thednam(nd).IsEqual(name)) return nd;
293 Standard_Integer kind = NameKind (name);
294 if (kind < 0) return 0;
295 Standard_Integer num = NameRank (name);
297 for (nd = 1; nd <= nb; nd ++) {
298 if (thekind(nd) == kind) {
300 if (nn == num) return nd;
307 // #### RETOUR DES VALEURS ####
309 TopoDS_Shape MoniTool_CaseData::Shape
310 (const Standard_Integer nd) const
313 Handle(TopoDS_HShape) hs = Handle(TopoDS_HShape)::DownCast (Data(nd));
314 if (!hs.IsNull()) sh = hs->Shape();
318 Standard_Boolean MoniTool_CaseData::XYZ
319 (const Standard_Integer nd, gp_XYZ& val) const
321 Handle(Geom_CartesianPoint) p = Handle(Geom_CartesianPoint)::DownCast(Data(nd));
322 if (p.IsNull()) return Standard_False;
323 val = p->Pnt().XYZ();
324 return Standard_True;
327 Standard_Boolean MoniTool_CaseData::XY
328 (const Standard_Integer nd, gp_XY& val) const
330 Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd));
331 if (p.IsNull()) return Standard_False;
332 val = p->Pnt2d().XY();
333 return Standard_True;
336 Standard_Boolean MoniTool_CaseData::Reals
337 (const Standard_Integer nd,
338 Standard_Real& v1, Standard_Real& v2) const
340 Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd));
341 if (p.IsNull()) return Standard_False;
342 v1 = p->X(); v2 = p->Y();
343 return Standard_True;
347 Standard_Boolean MoniTool_CaseData::Real
348 (const Standard_Integer nd,
349 Standard_Real& val) const
351 Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd));
352 if (p.IsNull()) return Standard_False;
354 return Standard_True;
357 Standard_Boolean MoniTool_CaseData::Text
358 (const Standard_Integer nd,
359 Standard_CString& text) const
361 Handle(TCollection_HAsciiString) t = Handle(TCollection_HAsciiString)::DownCast(Data(nd));
362 if (t.IsNull()) return Standard_False;
363 text = t->ToCString();
364 return Standard_True;
367 Standard_Boolean MoniTool_CaseData::Integer
368 (const Standard_Integer nd,
369 Standard_Integer& val) const
371 Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd));
372 // if (p.IsNull()) return Standard_False;
373 if (thekind(nd) != 11) return Standard_False;
374 Standard_Real rval = p->X();
375 val = (Standard_Integer)rval;
376 return Standard_True;
380 // #### MESSAGES ET DEFINITIONS ####
382 Message_Msg MoniTool_CaseData::Msg () const
384 Standard_CString defm = DefMsg (thecase.ToCString());
386 // A REPRENDRE COMPLETEMENT ! Il faut analyser defm = mescode + variables
394 void MoniTool_CaseData::SetDefWarning (const Standard_CString acode)
395 { defch.Bind(acode,1); }
397 void MoniTool_CaseData::SetDefFail (const Standard_CString acode)
398 { defch.Bind(acode,2); }
400 Standard_Integer MoniTool_CaseData::DefCheck (const Standard_CString acode)
402 Standard_Integer val;
403 if (!defch.Find(acode, val))
409 void MoniTool_CaseData::SetDefMsg
410 (const Standard_CString casecode, const Standard_CString mesdef)
412 Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString (mesdef);
413 defms.Bind(casecode,str);
416 Standard_CString MoniTool_CaseData::DefMsg (const Standard_CString casecode)
418 Handle(Standard_Transient) aTStr;
419 if (!defms.Find(casecode, aTStr)) return "";
420 Handle(TCollection_HAsciiString) str = Handle(TCollection_HAsciiString)::DownCast(aTStr);
421 if (str.IsNull()) return "";
422 return str->ToCString();