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 <Dico_DictionaryOfInteger.hxx>
16 #include <Dico_DictionaryOfTransient.hxx>
17 #include <Geom2d_CartesianPoint.hxx>
18 #include <Geom2d_Curve.hxx>
19 #include <Geom_CartesianPoint.hxx>
20 #include <Geom_Curve.hxx>
21 #include <Geom_Surface.hxx>
24 #include <Message_Msg.hxx>
25 #include <MoniTool_CaseData.hxx>
26 #include <OSD_Timer.hxx>
27 #include <Standard_Failure.hxx>
28 #include <Standard_Transient.hxx>
29 #include <Standard_Type.hxx>
30 #include <TCollection_AsciiString.hxx>
31 #include <TCollection_HAsciiString.hxx>
33 #include <TopoDS_HShape.hxx>
34 #include <TopoDS_Shape.hxx>
36 IMPLEMENT_STANDARD_RTTIEXT(MoniTool_CaseData,MMgt_TShared)
38 //#include <GeomTools.hxx>
40 static Handle(Dico_DictionaryOfInteger)& defchecks()
42 static Handle(Dico_DictionaryOfInteger) defch;
43 if (defch.IsNull()) defch = new Dico_DictionaryOfInteger();
47 static Handle(Dico_DictionaryOfTransient)& defmess()
49 static Handle(Dico_DictionaryOfTransient) defms;
50 if (defms.IsNull()) defms = new Dico_DictionaryOfTransient();
55 static Standard_Boolean stachr = Standard_False;
57 //static OSD_Timer chrono;
58 // because merdouille link dynamique & perf, ne creer le static qu au 1er usage
59 static OSD_Timer& chrono() {
65 MoniTool_CaseData::MoniTool_CaseData
66 (const Standard_CString caseid, const Standard_CString name)
67 : thesubst (0) , thecase (caseid) , thename (name)
68 { thecheck = DefCheck(caseid); }
70 void MoniTool_CaseData::SetCaseId (const Standard_CString caseid)
71 { thecase.Clear(); thecase.AssignCat (caseid); thecheck = DefCheck(caseid); thesubst = 0; }
73 void MoniTool_CaseData::SetName (const Standard_CString name)
74 { thename.Clear(); thename.AssignCat (name); thesubst = 0; }
76 Standard_CString MoniTool_CaseData::CaseId () const
77 { return thecase.ToCString(); }
79 Standard_CString MoniTool_CaseData::Name () const
80 { return thename.ToCString(); }
83 Standard_Boolean MoniTool_CaseData::IsCheck () const
84 { return (thecheck > 0); }
86 Standard_Boolean MoniTool_CaseData::IsWarning () const
87 { return (thecheck == 1); }
89 Standard_Boolean MoniTool_CaseData::IsFail () const
90 { return (thecheck == 2); }
92 void MoniTool_CaseData::ResetCheck ()
95 void MoniTool_CaseData::SetWarning ()
98 void MoniTool_CaseData::SetFail ()
103 void MoniTool_CaseData::SetChange ()
106 void MoniTool_CaseData::SetReplace (const Standard_Integer num)
109 void MoniTool_CaseData::AddData
110 (const Handle(Standard_Transient)& val,
111 const Standard_Integer kind, const Standard_CString name)
113 TCollection_AsciiString aname(name);
114 Standard_Integer subs = thesubst;
116 // SetChange (calculer la position d apres Name)
118 if (name[0] != '\0') subs = NameNum (name);
120 // SetChange / SetReplace
121 if (subs > 0 && subs <= thedata.Length()) {
122 thedata.SetValue (subs,val);
123 thekind.SetValue (subs,kind);
124 if (aname.Length() > 0) thednam.SetValue (subs,aname);
127 thedata.Append (val);
128 thekind.Append (kind);
129 thednam.Append (aname);
134 void MoniTool_CaseData::AddRaised (const Standard_CString name)
135 { AddData ( Standard_Failure::Caught(),1,name); }
137 void MoniTool_CaseData::AddShape
138 (const TopoDS_Shape& sh, const Standard_CString name)
139 { AddData ( new TopoDS_HShape(sh), 4,name); }
141 void MoniTool_CaseData::AddXYZ
142 (const gp_XYZ& aXYZ, const Standard_CString name)
143 { AddData ( new Geom_CartesianPoint (aXYZ), 5,name); }
145 void MoniTool_CaseData::AddXY
146 (const gp_XY& aXY, const Standard_CString name)
147 { AddData ( new Geom2d_CartesianPoint (aXY), 6,name); }
149 void MoniTool_CaseData::AddReal
150 (const Standard_Real val, const Standard_CString name)
151 { AddData ( new Geom2d_CartesianPoint (val,0.), 8,name); }
153 void MoniTool_CaseData::AddReals
154 (const Standard_Real v1, const Standard_Real v2, const Standard_CString name)
155 { AddData ( new Geom2d_CartesianPoint (v1,v2), 7,name); }
157 void MoniTool_CaseData::AddCPU
158 (const Standard_Real lastCPU, const Standard_Real curCPU,
159 const Standard_CString name)
161 Standard_Real cpu = curCPU;
163 Standard_Real sec; Standard_Integer i1,i2;
164 chrono().Show (sec,i1,i2,cpu);
167 AddData ( new Geom2d_CartesianPoint (cpu,0.), 9,name);
170 Standard_Real MoniTool_CaseData::GetCPU () const
172 if (!stachr) { chrono().Start(); stachr = Standard_True; }
173 Standard_Real sec,cpu; Standard_Integer i1,i2;
174 chrono().Show (sec,i1,i2,cpu);
178 Standard_Boolean MoniTool_CaseData::LargeCPU
179 (const Standard_Real maxCPU,
180 const Standard_Real lastCPU, const Standard_Real curCPU) const
182 Standard_Real cpu = curCPU;
184 Standard_Real sec; Standard_Integer i1,i2;
185 chrono().Show (sec,i1,i2,cpu);
188 return (cpu >= maxCPU);
191 void MoniTool_CaseData::AddGeom
192 (const Handle(Standard_Transient)& val, const Standard_CString name)
193 { AddData (val,3,name); }
195 void MoniTool_CaseData::AddEntity
196 (const Handle(Standard_Transient)& val, const Standard_CString name)
197 { AddData (val,2,name); }
199 void MoniTool_CaseData::AddText
200 (const Standard_CString text, const Standard_CString name)
201 { AddData (new TCollection_HAsciiString(text),10,name); }
203 void MoniTool_CaseData::AddInteger
204 (const Standard_Integer val, const Standard_CString name)
206 Standard_Real rval = val;
207 AddData ( new Geom2d_CartesianPoint (rval,0.), 11,name);
210 void MoniTool_CaseData::AddAny
211 (const Handle(Standard_Transient)& val, const Standard_CString name)
212 { AddData (val,0,name); }
215 void MoniTool_CaseData::RemoveData (const Standard_Integer num)
217 if (num < 1 || num > thedata.Length()) return;
218 thedata.Remove(num); thekind.Remove(num); thednam.Remove(num);
221 // #### INTERROGATIONS ####
223 Standard_Integer MoniTool_CaseData::NbData () const
224 { return thedata.Length(); }
226 Handle(Standard_Transient) MoniTool_CaseData::Data
227 (const Standard_Integer nd) const
229 Handle(Standard_Transient) val;
230 if (nd < 1 || nd > thedata.Length()) return val;
234 Standard_Boolean MoniTool_CaseData::GetData
235 (const Standard_Integer nd, const Handle(Standard_Type)& type,
236 Handle(Standard_Transient)& val) const
238 if (type.IsNull()) return Standard_False;
239 if (nd < 1 || nd > thedata.Length()) return Standard_False;
240 Handle(Standard_Transient) v = thedata (nd);
241 if (v.IsNull()) return Standard_False;
242 if (!v->IsKind(type)) return Standard_False;
244 return Standard_True;
247 Standard_Integer MoniTool_CaseData::Kind
248 (const Standard_Integer nd) const
250 if (nd < 1 || nd > thekind.Length()) return 0;
255 static const TCollection_AsciiString& nulname ()
257 static TCollection_AsciiString nuln;
261 const TCollection_AsciiString& MoniTool_CaseData::Name
262 (const Standard_Integer nd) const
264 if (nd < 1 || nd > thednam.Length()) return nulname();
268 static Standard_Integer NameKind (const Standard_CString name)
271 if (n0 == 'A' && name[1] == 'N' && name[2] == 'Y' && name[3] == '\0') return 0;
273 if (name[1] == 'X' && name[2] == '\0') return 1;
274 if (name[1] == 'N' && name[2] == '\0') return 2;
277 if (n0 == 'G' && name[1] == '\0') return 3;
278 if (n0 == 'S' && name[1] == 'H' && name[2] == '\0') return 4;
279 if (n0 == 'X' && name[1] == 'Y') {
280 if (name[2] == 'Z' && name[3] == '\0') return 5;
281 if (name[2] == '\0') return 6;
283 if (n0 == 'U' && name[1] == 'V' && name[2] == '\0') return 6;
285 if (name[1] == '\0') return 8;
286 if (name[1] == 'R' && name[2] == '\0') return 7;
288 if (n0 == 'C' && name[1] == 'P' && name[2] == 'U' && name[3] == '\0') return 9;
289 if (n0 == 'T' && name[1] == '\0') return 10;
290 if (n0 == 'I' && name[1] == '\0') return 11;
295 static Standard_Integer NameRank (const Standard_CString name)
297 for (Standard_Integer i = 0; name[i] != '\0'; i ++) {
298 if (name[i] == ':' && name[i+1] != '\0') return atoi(&name[i+1]);
303 Standard_Integer MoniTool_CaseData::NameNum
304 (const Standard_CString name) const
306 if (!name || name[0] == '\0') return 0;
307 Standard_Integer nd, nn = 0, nb = NbData();
308 for (nd = 1; nd <= nb; nd ++) {
309 if (thednam(nd).IsEqual(name)) return nd;
312 Standard_Integer kind = NameKind (name);
313 if (kind < 0) return 0;
314 Standard_Integer num = NameRank (name);
316 for (nd = 1; nd <= nb; nd ++) {
317 if (thekind(nd) == kind) {
319 if (nn == num) return nd;
326 // #### RETOUR DES VALEURS ####
328 TopoDS_Shape MoniTool_CaseData::Shape
329 (const Standard_Integer nd) const
332 Handle(TopoDS_HShape) hs = Handle(TopoDS_HShape)::DownCast (Data(nd));
333 if (!hs.IsNull()) sh = hs->Shape();
337 Standard_Boolean MoniTool_CaseData::XYZ
338 (const Standard_Integer nd, gp_XYZ& val) const
340 Handle(Geom_CartesianPoint) p = Handle(Geom_CartesianPoint)::DownCast(Data(nd));
341 if (p.IsNull()) return Standard_False;
342 val = p->Pnt().XYZ();
343 return Standard_True;
346 Standard_Boolean MoniTool_CaseData::XY
347 (const Standard_Integer nd, gp_XY& val) const
349 Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd));
350 if (p.IsNull()) return Standard_False;
351 val = p->Pnt2d().XY();
352 return Standard_True;
355 Standard_Boolean MoniTool_CaseData::Reals
356 (const Standard_Integer nd,
357 Standard_Real& v1, Standard_Real& v2) const
359 Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd));
360 if (p.IsNull()) return Standard_False;
361 v1 = p->X(); v2 = p->Y();
362 return Standard_True;
366 Standard_Boolean MoniTool_CaseData::Real
367 (const Standard_Integer nd,
368 Standard_Real& val) const
370 Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd));
371 if (p.IsNull()) return Standard_False;
373 return Standard_True;
376 Standard_Boolean MoniTool_CaseData::Text
377 (const Standard_Integer nd,
378 Standard_CString& text) const
380 Handle(TCollection_HAsciiString) t = Handle(TCollection_HAsciiString)::DownCast(Data(nd));
381 if (t.IsNull()) return Standard_False;
382 text = t->ToCString();
383 return Standard_True;
386 Standard_Boolean MoniTool_CaseData::Integer
387 (const Standard_Integer nd,
388 Standard_Integer& val) const
390 Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd));
391 // if (p.IsNull()) return Standard_False;
392 if (thekind(nd) != 11) return Standard_False;
393 Standard_Real rval = p->X();
394 val = (Standard_Integer)rval;
395 return Standard_True;
399 // #### MESSAGES ET DEFINITIONS ####
401 Message_Msg MoniTool_CaseData::Msg () const
403 Standard_CString defm = DefMsg (thecase.ToCString());
405 // A REPRENDRE COMPLETEMENT ! Il faut analyser defm = mescode + variables
413 void MoniTool_CaseData::SetDefWarning (const Standard_CString acode)
414 { defchecks()->SetItem (acode,1); }
416 void MoniTool_CaseData::SetDefFail (const Standard_CString acode)
417 { defchecks()->SetItem (acode,2); }
419 Standard_Integer MoniTool_CaseData::DefCheck (const Standard_CString acode)
421 Standard_Integer val;
422 if (!defchecks()->GetItem (acode,val)) val = 0;
427 void MoniTool_CaseData::SetDefMsg
428 (const Standard_CString casecode, const Standard_CString mesdef)
430 Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString (mesdef);
431 defmess()->SetItem (casecode,str);
434 Standard_CString MoniTool_CaseData::DefMsg (const Standard_CString casecode)
436 //Standard_CString mesd;
437 Handle(TCollection_HAsciiString) str;
438 if (!defmess()->GetItem (casecode,str)) return "";
439 if (str.IsNull()) return "";
440 return str->ToCString();