Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2002-05-21 |
2 | // Created by: QA Admin | |
3 | // Copyright (c) 2002-2012 OPEN CASCADE SAS | |
4 | // | |
5 | // The content of this file is subject to the Open CASCADE Technology Public | |
6 | // License Version 6.5 (the "License"). You may not use the content of this file | |
7 | // except in compliance with the License. Please obtain a copy of the License | |
8 | // at http://www.opencascade.org and read it completely before using this file. | |
9 | // | |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
12 | // | |
13 | // The Original Code and all software distributed under the License is | |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
15 | // Initial Developer hereby disclaims all such warranties, including without | |
16 | // limitation, any warranties of merchantability, fitness for a particular | |
17 | // purpose or non-infringement. Please see the License for the specific terms | |
18 | // and conditions governing the rights and limitations under the License. | |
19 | ||
7fd59977 | 20 | |
1cd84fee | 21 | #include <QABugs.hxx> |
7fd59977 | 22 | |
23 | #include <Draw_Interpretor.hxx> | |
24 | #include <DBRep.hxx> | |
25 | #include <DrawTrSurf.hxx> | |
26 | #include <AIS_InteractiveContext.hxx> | |
27 | #include <ViewerTest.hxx> | |
28 | #include <AIS_Shape.hxx> | |
29 | #include <TopoDS_Shape.hxx> | |
30 | ||
31 | #include <gp_Pnt2d.hxx> | |
f6f03db9 | 32 | #include <gp_Ax1.hxx> |
7fd59977 | 33 | #include <GCE2d_MakeSegment.hxx> |
34 | #include <Geom2d_TrimmedCurve.hxx> | |
35 | #include <DrawTrSurf.hxx> | |
36 | ||
f6f03db9 | 37 | #include <Precision.hxx> |
38 | ||
7fd59977 | 39 | #include <PCollection_HAsciiString.hxx> |
40 | ||
c2ae831c | 41 | #include <cstdio> |
42 | #include <cmath> | |
43 | #include <iostream> | |
44 | #include <OSD_PerfMeter.hxx> | |
45 | #include <OSD_Timer.hxx> | |
46 | #include <BRepPrimAPI_MakeBox.hxx> | |
47 | #include <BRepPrimAPI_MakeSphere.hxx> | |
48 | #include <BRepAlgo_Cut.hxx> | |
49 | ||
7fd59977 | 50 | static Standard_Integer OCC230 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
51 | { | |
52 | if ( argc != 4) { | |
53 | di << "ERROR OCC230: Usage : " << argv[0] << " TrimmedCurve Pnt2d Pnt2d" << "\n"; | |
54 | return 1; | |
55 | } | |
56 | ||
57 | gp_Pnt2d P1, P2; | |
58 | if ( !DrawTrSurf::GetPoint2d(argv[2],P1)) { | |
59 | di << "ERROR OCC230: " << argv[2] << " is not Pnt2d" << "\n"; | |
60 | return 1; | |
61 | } | |
62 | if ( !DrawTrSurf::GetPoint2d(argv[3],P2)) { | |
63 | di << "ERROR OCC230: " << argv[3] << " is not Pnt2d" << "\n"; | |
64 | return 1; | |
65 | } | |
66 | ||
67 | GCE2d_MakeSegment MakeSegment(P1,P2); | |
68 | Handle(Geom2d_TrimmedCurve) TrimmedCurve = MakeSegment.Value(); | |
69 | DrawTrSurf::Set(argv[1], TrimmedCurve); | |
70 | return 0; | |
71 | } | |
72 | ||
73 | static Standard_Integer OCC142 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/) | |
74 | { | |
75 | for(Standard_Integer i= 0;i <= 20;i++){ | |
76 | Handle(PCollection_HAsciiString) pstr = new PCollection_HAsciiString("TEST"); | |
77 | pstr->Clear(); | |
78 | } | |
79 | di << "OCC142: OK" << "\n"; | |
80 | return 0; | |
81 | } | |
82 | ||
f6f03db9 | 83 | static Standard_Integer OCC23361 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/) |
84 | { | |
85 | gp_Pnt p(0, 0, 2); | |
86 | ||
87 | gp_Trsf t1, t2; | |
88 | t1.SetRotation(gp_Ax1(p, gp_Dir(0, 1, 0)), -0.49328285294022267); | |
89 | t2.SetRotation(gp_Ax1(p, gp_Dir(0, 0, 1)), 0.87538474718473880); | |
90 | ||
91 | gp_Trsf tComp = t2 * t1; | |
92 | ||
93 | gp_Pnt p1(10, 3, 4); | |
94 | gp_Pnt p2 = p1.Transformed(tComp); | |
95 | gp_Pnt p3 = p1.Transformed(t1); | |
96 | p3.Transform(t2); | |
97 | ||
98 | // points must be equal | |
99 | if ( ! p2.IsEqual(p3, Precision::Confusion()) ) | |
100 | di << "ERROR OCC23361: equivalent transformations does not produce equal points" << "\n"; | |
101 | else | |
102 | di << "OCC23361: OK" << "\n"; | |
103 | ||
104 | return 0; | |
105 | } | |
106 | ||
c2ae831c | 107 | static Standard_Integer OCC23237 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/) |
108 | { | |
109 | OSD_PerfMeter aPM("TestMeter",0); | |
110 | OSD_Timer aTM; | |
111 | ||
112 | // run some operation in cycle for about 2 seconds to have good values of times to compare | |
113 | int count = 0; | |
114 | printf("OSD_PerfMeter test.\nRunning Boolean operation on solids in loop.\n"); | |
115 | for (; aTM.ElapsedTime() < 2.; count++) | |
116 | { | |
117 | aPM.Start(); | |
118 | aTM.Start(); | |
119 | ||
120 | // do some operation that will take considerable time compared with time or starting / stopping timers | |
121 | BRepPrimAPI_MakeBox aBox (10., 10., 10.); | |
122 | BRepPrimAPI_MakeSphere aSphere (10.); | |
123 | BRepAlgo_Cut (aBox.Shape(), aSphere.Shape()); | |
124 | ||
125 | aTM.Stop(); | |
126 | aPM.Stop(); | |
127 | } | |
128 | ||
129 | int aNbEnters = 0; | |
130 | Standard_Real aPerfMeter_CPUtime = 0., aTimer_ElapsedTime = aTM.ElapsedTime(); | |
131 | ||
132 | perf_get_meter("TestMeter", &aNbEnters, &aPerfMeter_CPUtime); | |
133 | ||
134 | Standard_Real aTimeDiff = (fabs(aTimer_ElapsedTime - aPerfMeter_CPUtime) / aTimer_ElapsedTime); | |
135 | ||
136 | printf("\nMeasurement results (%d cycles):\n", count); | |
137 | printf("\nOSD_PerfMeter CPU time: %lf\nOSD_Timer elapsed time: %lf\n", aPerfMeter_CPUtime, aTimer_ElapsedTime); | |
138 | printf("Time delta is: %.3lf %%\n", aTimeDiff * 100); | |
139 | ||
140 | if (aTimeDiff > 0.2) | |
141 | di << "OCC23237: Error: too much difference between CPU and elapsed times"; | |
142 | else if (aNbEnters != count) | |
143 | di << "OCC23237: Error: counter reported by PerfMeter (" << aNbEnters << ") does not correspond to actual number of cycles"; | |
144 | else | |
145 | di << "OCC23237: OK"; | |
146 | ||
147 | return 0; | |
148 | } | |
149 | ||
1365140b RL |
150 | #ifdef HAVE_TBB |
151 | ||
152 | #include <Standard_Atomic.hxx> | |
153 | #include <tbb/blocked_range.h> | |
154 | #include <tbb/parallel_for.h> | |
155 | ||
156 | class IncrementerDecrementer | |
157 | { | |
158 | public: | |
159 | IncrementerDecrementer (Standard_Integer* theVal, Standard_Boolean thePositive) : myVal (theVal), myPositive (thePositive) | |
160 | {} | |
161 | void operator() (const tbb::blocked_range<size_t>& r) const | |
162 | { | |
163 | if (myPositive) | |
164 | for (size_t i = r.begin(); i != r.end(); ++i) | |
165 | Standard_Atomic_Increment (myVal); | |
166 | else | |
167 | for (size_t i = r.begin(); i != r.end(); ++i) | |
168 | Standard_Atomic_Decrement (myVal); | |
169 | } | |
170 | private: | |
171 | Standard_Integer* myVal; | |
172 | Standard_Boolean myPositive; | |
173 | }; | |
174 | #endif | |
175 | ||
176 | #define QCOMPARE(val1, val2) \ | |
177 | di << "Checking " #val1 " == " #val2 << \ | |
178 | ((val1) == (val2) ? ": OK\n" : ": Error\n") | |
179 | ||
180 | #ifdef HAVE_TBB | |
181 | static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/) | |
182 | { | |
183 | int aSum = 0; | |
184 | ||
185 | //check returned value | |
186 | QCOMPARE (Standard_Atomic_Decrement (&aSum), -1); | |
187 | QCOMPARE (Standard_Atomic_Increment (&aSum), 0); | |
188 | QCOMPARE (Standard_Atomic_Increment (&aSum), 1); | |
189 | QCOMPARE (Standard_Atomic_Increment (&aSum), 2); | |
190 | // QCOMPARE (Standard_Atomic_DecrementTest (&aSum), 0); | |
191 | // QCOMPARE (Standard_Atomic_DecrementTest (&aSum), 1); | |
192 | ||
193 | //check atomicity | |
194 | aSum = 0; | |
195 | const int N = 1 << 24; //big enough to ensure concurrency | |
196 | ||
197 | //increment | |
198 | tbb::parallel_for (tbb::blocked_range<size_t> (0, N), IncrementerDecrementer (&aSum, true)); | |
199 | QCOMPARE (aSum, N); | |
200 | ||
201 | //decrement | |
202 | tbb::parallel_for (tbb::blocked_range<size_t> (0, N), IncrementerDecrementer (&aSum, false)); | |
203 | QCOMPARE (aSum, 0); | |
204 | ||
205 | return 0; | |
206 | } | |
207 | ||
208 | #else /* HAVE_TBB */ | |
209 | ||
210 | static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char **argv) | |
211 | { | |
212 | di << "Test skipped: command " << argv[0] << " requires TBB library\n"; | |
213 | return 0; | |
214 | } | |
215 | ||
216 | #endif /* HAVE_TBB */ | |
217 | ||
e6aad0ee RL |
218 | #include <TDocStd_Application.hxx> |
219 | #include <XCAFApp_Application.hxx> | |
220 | #include <TDocStd_Document.hxx> | |
221 | #include <XCAFDoc_ShapeTool.hxx> | |
222 | #include <XCAFDoc_DocumentTool.hxx> | |
223 | #include <TDF_Label.hxx> | |
224 | #include <TDataStd_Name.hxx> | |
225 | ||
226 | static Standard_Integer OCC23595 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char **argv) | |
227 | { | |
228 | const Handle(TDocStd_Application)& anApp = XCAFApp_Application::GetApplication(); | |
229 | Handle(TDocStd_Document) aDoc; | |
230 | anApp->NewDocument ("XmlXCAF", aDoc); | |
231 | QCOMPARE (!aDoc.IsNull(), Standard_True); | |
232 | ||
233 | Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main()); | |
234 | ||
235 | //check default value | |
236 | Standard_Boolean aValue = XCAFDoc_ShapeTool::AutoNaming(); | |
237 | QCOMPARE (aValue, Standard_True); | |
238 | ||
239 | //true | |
240 | XCAFDoc_ShapeTool::SetAutoNaming (Standard_True); | |
241 | TopoDS_Shape aShape = BRepPrimAPI_MakeBox (100., 200., 300.).Shape(); | |
242 | TDF_Label aLabel = aShTool->AddShape (aShape); | |
243 | Handle(TDataStd_Name) anAttr; | |
244 | QCOMPARE (aLabel.FindAttribute (TDataStd_Name::GetID(), anAttr), Standard_True); | |
245 | ||
246 | //false | |
247 | XCAFDoc_ShapeTool::SetAutoNaming (Standard_False); | |
248 | aShape = BRepPrimAPI_MakeBox (300., 200., 100.).Shape(); | |
249 | aLabel = aShTool->AddShape (aShape); | |
250 | QCOMPARE (!aLabel.FindAttribute (TDataStd_Name::GetID(), anAttr), Standard_True); | |
251 | ||
252 | //restore | |
253 | XCAFDoc_ShapeTool::SetAutoNaming (aValue); | |
254 | ||
255 | return 0; | |
256 | } | |
257 | ||
5d1833ef | 258 | #include <ExprIntrp_GenExp.hxx> |
259 | Standard_Integer OCC22611 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) | |
260 | { | |
261 | ||
262 | if (argc != 3) { | |
263 | di << "Usage : " << argv[0] << " string nb\n"; | |
264 | return 1; | |
265 | } | |
266 | ||
267 | TCollection_AsciiString aToken = argv[1]; | |
268 | Standard_Integer aNb = atoi(argv[2]); | |
269 | ||
270 | Handle(ExprIntrp_GenExp) aGen = ExprIntrp_GenExp::Create(); | |
271 | for (Standard_Integer i=0; i < aNb; i++) | |
272 | { | |
273 | aGen->Process(aToken); | |
274 | Handle(Expr_GeneralExpression) aExpr = aGen->Expression(); | |
275 | } | |
276 | ||
277 | return 0; | |
278 | } | |
279 | ||
e187cc0a | 280 | Standard_Integer OCC22595 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
281 | { | |
282 | gp_Mat M0; | |
283 | di << "M0 = " | |
284 | << " {" << M0(1,1) << "} {" << M0(1,2) << "} {" << M0(1,3) <<"}" | |
285 | << " {" << M0(2,1) << "} {" << M0(2,2) << "} {" << M0(2,3) <<"}" | |
286 | << " {" << M0(1,1) << "} {" << M0(1,2) << "} {" << M0(1,3) <<"}"; | |
287 | return 0; | |
288 | } | |
289 | ||
bead40f2 | 290 | #include <TopoDS_Face.hxx> |
291 | #include <TopoDS_Face.hxx> | |
292 | #include <TopoDS.hxx> | |
293 | #include <BRepBuilderAPI_Transform.hxx> | |
294 | #include <BRepExtrema_DistShapeShape.hxx> | |
295 | #include <BRepTools.hxx> | |
296 | ||
297 | Standard_Boolean static OCC23774Test(const TopoDS_Face& grossPlateFace, const TopoDS_Shape& originalWire, Draw_Interpretor& di) | |
298 | { | |
299 | BRepExtrema_DistShapeShape distShapeShape(grossPlateFace,originalWire,Extrema_ExtFlag_MIN); | |
300 | if(!distShapeShape.IsDone()) { | |
301 | di <<"Distance ShapeShape is Not Done\n"; | |
302 | return Standard_False; | |
303 | } | |
304 | ||
305 | if(distShapeShape.Value() > 0.01) { | |
306 | di << "Wrong Dist = " <<distShapeShape.Value() << "\n"; | |
307 | return Standard_False; | |
308 | } else | |
309 | di << "Dist0 = " <<distShapeShape.Value() <<"\n"; | |
310 | ||
311 | ////////////////////////////////////////////////////////////////////////// | |
312 | /// First Flip Y | |
313 | const gp_Pnt2d axis1P1(1474.8199035519228,1249.9995745636970); | |
314 | const gp_Pnt2d axis1P2(1474.8199035519228,1250.9995745636970); | |
315 | ||
316 | gp_Vec2d mirrorVector1(axis1P1,axis1P2); | |
317 | ||
318 | gp_Trsf2d mirror1; | |
319 | mirror1.SetMirror(gp_Ax2d(axis1P1,mirrorVector1)); | |
320 | ||
321 | BRepBuilderAPI_Transform transformer1(mirror1); | |
322 | transformer1.Perform(originalWire); | |
323 | if(!transformer1.IsDone()) { | |
324 | di << "Not Done1 " << "\n"; | |
325 | return Standard_False; | |
326 | } | |
327 | const TopoDS_Shape& step1ModifiedShape = transformer1.ModifiedShape(originalWire); | |
328 | ||
329 | BRepExtrema_DistShapeShape distShapeShape1(grossPlateFace,step1ModifiedShape,Extrema_ExtFlag_MIN); | |
330 | if(!distShapeShape1.IsDone()) | |
331 | return Standard_False; | |
332 | if(distShapeShape1.Value() > 0.01) { | |
333 | di << "Dist = " <<distShapeShape1.Value() <<"\n"; | |
334 | return Standard_False; | |
335 | } else | |
336 | di << "Dist1 = " <<distShapeShape1.Value() <<"\n"; | |
337 | ||
338 | ////////////////////////////////////////////////////////////////////////// | |
339 | /// Second flip Y | |
340 | transformer1.Perform(step1ModifiedShape); | |
341 | if(!transformer1.IsDone()) { | |
342 | di << "Not Done1 \n"; | |
343 | return Standard_False; | |
344 | } | |
345 | const TopoDS_Shape& step2ModifiedShape = transformer1.ModifiedShape(step1ModifiedShape); | |
346 | BRepTools::Write(step2ModifiedShape, Standard_CString ("SecondMirrorWire.brep")); | |
347 | ||
348 | //This is identity matrix for values but for type is gp_Rotation ?! | |
349 | gp_Trsf2d mirror11 = mirror1; | |
350 | mirror11.PreMultiply(mirror1); | |
351 | ||
352 | BRepExtrema_DistShapeShape distShapeShape2(grossPlateFace,step2ModifiedShape);//,Extrema_ExtFlag_MIN); | |
353 | if(!distShapeShape2.IsDone()) | |
354 | return Standard_False; | |
355 | ||
356 | //This last test case give error (the value is 1008.8822038689706) | |
357 | if(distShapeShape2.Value() > 0.01) { | |
358 | di << "Wrong Dist2 = " <<distShapeShape2.Value() <<"\n"; | |
359 | Standard_Integer N = distShapeShape2.NbSolution(); | |
360 | di << "Nb = " <<N <<"\n"; | |
361 | for (Standard_Integer i=1;i <= N;i++) | |
362 | di <<"Sol(" <<i<<") = " <<distShapeShape2.PointOnShape1(i).Distance(distShapeShape2.PointOnShape2(i)) <<"\n"; | |
363 | return Standard_False; | |
364 | } | |
365 | di << "Distance2 = " <<distShapeShape2.Value() <<"\n"; | |
366 | ||
367 | return Standard_True; | |
368 | } | |
369 | static Standard_Integer OCC23774(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
370 | { | |
371 | ||
372 | if (n != 3) { | |
373 | di <<"OCC23774: invalid number of input parameters\n"; | |
374 | return 1; | |
375 | } | |
376 | ||
377 | const char *ns1 = (a[1]), *ns2 = (a[2]); | |
378 | TopoDS_Shape S1(DBRep::Get(ns1)), S2(DBRep::Get(ns2)); | |
379 | if (S1.IsNull() || S2.IsNull()) { | |
380 | di <<"OCC23774: Null input shapes\n"; | |
381 | return 1; | |
382 | } | |
383 | const TopoDS_Face& aFace = TopoDS::Face(S1); | |
384 | if(!OCC23774Test(aFace, S2, di)) | |
385 | di << "Something is wrong\n"; | |
386 | ||
387 | return 0; | |
388 | } | |
389 | ||
06be28a4 RL |
390 | static Standard_Integer OCC23683 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv) |
391 | { | |
392 | if (argc < 2) { | |
393 | di<<"Usage: " << argv[0] << " invalid number of arguments"<<"\n"; | |
394 | return 1; | |
395 | } | |
396 | ||
397 | Standard_Integer ucontinuity = 1; | |
398 | Standard_Integer vcontinuity = 1; | |
399 | Standard_Boolean iscnu = false; | |
400 | Standard_Boolean iscnv = false; | |
401 | ||
402 | Handle(Geom_Surface) aSurf = DrawTrSurf::GetSurface(argv[1]); | |
403 | ||
404 | QCOMPARE (aSurf->IsCNu (ucontinuity), iscnu); | |
405 | QCOMPARE (aSurf->IsCNv (vcontinuity), iscnv); | |
406 | ||
407 | return 0; | |
408 | } | |
409 | ||
1cd84fee | 410 | void QABugs::Commands_19(Draw_Interpretor& theCommands) { |
1365140b | 411 | const char *group = "QABugs"; |
7fd59977 | 412 | |
413 | theCommands.Add ("OCC230", "OCC230 TrimmedCurve Pnt2d Pnt2d", __FILE__, OCC230, group); | |
414 | theCommands.Add ("OCC142", "OCC142", __FILE__, OCC142, group); | |
f6f03db9 | 415 | theCommands.Add ("OCC23361", "OCC23361", __FILE__, OCC23361, group); |
1365140b RL |
416 | theCommands.Add ("OCC23237", "OCC23237", __FILE__, OCC23237, group); |
417 | theCommands.Add ("OCC22980", "OCC22980", __FILE__, OCC22980, group); | |
e6aad0ee | 418 | theCommands.Add ("OCC23595", "OCC23595", __FILE__, OCC23595, group); |
5d1833ef | 419 | theCommands.Add ("OCC22611", "OCC22611 string nb", __FILE__, OCC22611, group); |
e187cc0a | 420 | theCommands.Add ("OCC22595", "OCC22595", __FILE__, OCC22595, group); |
bead40f2 | 421 | theCommands.Add ("OCC23774", "OCC23774 shape1 shape2", __FILE__, OCC23774, group); |
06be28a4 | 422 | theCommands.Add ("OCC23683", "OCC23683 shape", __FILE__, OCC23683, group); |
7fd59977 | 423 | |
424 | return; | |
425 | } |