0026452: Infinite loop in Edge/Edge intersection.
[occt.git] / src / QABugs / QABugs_14.cxx
CommitLineData
b311480e 1// Created on: 2002-03-19
2// Created by: QA Admin
973c2be1 3// Copyright (c) 2002-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <stdio.h>
17
1cd84fee 18#include <QABugs.hxx>
7fd59977 19
20#include <Draw_Interpretor.hxx>
21#include <DBRep.hxx>
22#include <DrawTrSurf.hxx>
23#include <AIS_InteractiveContext.hxx>
24#include <ViewerTest.hxx>
25#include <AIS_Shape.hxx>
26#include <TopoDS_Shape.hxx>
27
28#include <Geom2d_Line.hxx>
29#include <TColgp_Array1OfPnt2d.hxx>
30#include <Geom2d_BezierCurve.hxx>
31#include <Geom2dAdaptor_Curve.hxx>
32#include <Geom2dGcc_QualifiedCurve.hxx>
33#include <Geom2dGcc_Circ2d2TanRad.hxx>
34#include <Geom2d_Circle.hxx>
35#include <TopoDS_Edge.hxx>
36#include <TopoDS.hxx>
37#include <BRepAdaptor_Curve.hxx>
38#include <gp_Lin.hxx>
39#include <BRepFeat_SplitShape.hxx>
40#include <DBRep_DrawableShape.hxx>
41#include <BRep_Builder.hxx>
42#include <TopTools_ListIteratorOfListOfShape.hxx>
43#include <BRepExtrema_DistShapeShape.hxx>
44#include <Draw.hxx>
45#include <TopoDS_Vertex.hxx>
46#include <BRepLib_MakeVertex.hxx>
47#include <BRepLib_MakeEdge.hxx>
48#include <TColgp_HArray1OfPnt.hxx>
49#include <GeomAPI_Interpolate.hxx>
50#include <Precision.hxx>
51#include <Geom_BSplineCurve.hxx>
52#include <OSD_Path.hxx>
53#include <ShapeBuild_ReShape.hxx>
54#include <ShapeExtend_WireData.hxx>
55#include <TopoDS_Wire.hxx>
56#include <ShapeExtend_WireData.hxx>
57#include <ShapeFix_Wire.hxx>
58#include <ShapeAnalysis_WireOrder.hxx>
59#include <ShapeAnalysis_Wire.hxx>
60#include <TopExp.hxx>
61#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
62#include <BRep_Tool.hxx>
63#include <ShapeAnalysis_Curve.hxx>
64#include <V3d_View.hxx>
65#include <Standard_ErrorHandler.hxx>
66
67static Standard_Integer BUC60897 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
68{
69 Standard_Character abuf[16];
70
71 Handle(Geom2d_Line) aLine = new Geom2d_Line(gp_Pnt2d(100, 0), gp_Dir2d(-1, 0));
91322f44 72 Sprintf(abuf,"line");
7fd59977 73 Standard_CString st = abuf;
74 DrawTrSurf::Set (st, aLine);
75
76 TColgp_Array1OfPnt2d aPoints(1, 3);
77 aPoints.SetValue(1, gp_Pnt2d(0, 0));
78 aPoints.SetValue(2, gp_Pnt2d(50, 50));
79 aPoints.SetValue(3, gp_Pnt2d(0, 100));
80 Handle(Geom2d_BezierCurve) aCurve = new Geom2d_BezierCurve(aPoints);
91322f44 81 Sprintf(abuf,"curve");
7fd59977 82 DrawTrSurf::Set (st, aCurve);
83
84 Geom2dAdaptor_Curve aCLine(aLine);
85 Geom2dAdaptor_Curve aCCurve(aCurve);
86 Geom2dGcc_QualifiedCurve aQualifCurve1(aCLine, GccEnt_outside);
87 Geom2dGcc_QualifiedCurve aQualifCurve2(aCCurve, GccEnt_outside);
88 Geom2dGcc_Circ2d2TanRad aGccCirc2d(aQualifCurve1, aQualifCurve2, 10, 1e-7);
89 if(!aGccCirc2d.IsDone())
90 {
586db386 91 di << "Faulty: can not create a circle.\n";
7fd59977 92 return 1;
93 }
94 for(Standard_Integer i = 1; i <= aGccCirc2d.NbSolutions(); i++)
95 {
96 gp_Circ2d aCirc2d = aGccCirc2d.ThisSolution(i);
97 di << "circle : X " << aCirc2d.Location().X() << " Y " << aCirc2d.Location().Y() << " R " << aCirc2d.Radius();
98 Standard_Real aTmpR1, aTmpR2;
99 gp_Pnt2d aPnt2d1, aPnt2d2;
100 aGccCirc2d.Tangency1(i, aTmpR1, aTmpR2, aPnt2d1);
101 aGccCirc2d.Tangency2(i, aTmpR1, aTmpR2, aPnt2d2);
586db386 102 di << "\ntangency1 : X " << aPnt2d1.X() << " Y " << aPnt2d1.Y();
103 di << "\ntangency2 : X " << aPnt2d2.X() << " Y " << aPnt2d2.Y() << "\n";
7fd59977 104
91322f44 105 Sprintf(abuf,"circle_%d",i);
7fd59977 106 Handle(Geom2d_Curve) circ_res = new Geom2d_Circle(aCirc2d);
107 DrawTrSurf::Set (st, circ_res);
108 }
109
586db386 110 di << "done\n";
7fd59977 111 return 0;
112}
113
114static Standard_Integer BUC60889 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
115{
116 if(argc != 10) {
586db386 117 di << "Usage : " << argv[0] << " point_1 point_2 name_of_edge bndbox_X1 bndbox_Y1 bndbox_Z1 bndbox_X2 bndbox_Y2 bndbox_Z2\n";
7fd59977 118 return 1;
119 } else {
120 gp_Pnt p1, p2;
121 if (!(DrawTrSurf::GetPoint(argv[1], p1)) || !(DrawTrSurf::GetPoint(argv[2], p2)))
122 {
586db386 123 di << "Need two points to define a band\n";
7fd59977 124 return 1;
125 }
126 TopoDS_Edge ed = TopoDS::Edge(DBRep::Get(argv[3]));
127 if (ed.IsNull())
128 {
586db386 129 di << "Need an edge to define the band direction\n";
7fd59977 130 return 1;
131 }
132 BRepAdaptor_Curve curve(ed);
133 gp_Dir d = curve.Line().Direction();
134 Bnd_Box bnd_box;
91322f44 135 bnd_box.Update(Draw::Atof(argv[4]), Draw::Atof(argv[5]), Draw::Atof(argv[6]), Draw::Atof(argv[7]), Draw::Atof(argv[8]), Draw::Atof(argv[9]));
7fd59977 136 if(bnd_box.IsOut(p1, p2, d))
586db386 137 di << "The band lies out of the box\n";
7fd59977 138 else
586db386 139 di << "The band intersects the box\n";
7fd59977 140
141 return 0;
142 }
143}
144
145static Standard_Integer BUC60852 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
146{
147 if(argc != 8)
586db386 148 di << "Usage : " << argv[0] << " name_of_edge bndbox_X1 bndbox_Y1 bndbox_Z1 bndbox_X2 bndbox_Y2 bndbox_Z2\n";
7fd59977 149 else {
150 TopoDS_Edge shape = TopoDS::Edge(DBRep::Get(argv[1]));
151 if(shape.ShapeType() != TopAbs_EDGE)
586db386 152 di << "shape must be an edge\n";
7fd59977 153 else {
154 BRepAdaptor_Curve curve(shape);
155 gp_Lin lin = curve.Line();
156 Bnd_Box bnd_box;
91322f44 157 bnd_box.Update(Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Draw::Atof(argv[6]), Draw::Atof(argv[7]));
7fd59977 158 if(bnd_box.IsOut(lin))
586db386 159 di << "Line that lies on edge does not intersect the box\n";
7fd59977 160 else
586db386 161 di << "Line that lies on edge intersects the box\n";
7fd59977 162 }
163 }
164 return 0;
165}
166
167static Standard_Integer BUC60854 (Draw_Interpretor& /*di*/, Standard_Integer argc, const char ** argv)
168{
169 Standard_Integer newnarg;
170 if (argc < 3) return 1;
171 TopoDS_Shape S = DBRep::Get(argv[2]);
172 BRepFeat_SplitShape Spls(S);
173 Standard_Boolean pick = Standard_False;
174 TopoDS_Shape EF;
175 Standard_Real u,v;
176 Standard_Integer i = 3;
177 for ( newnarg=3; newnarg<argc; newnarg++) {
178 if (argv[newnarg][0] == '@') {
179 break;
180 }
181 }
182 if (newnarg == 3 ||
183 (newnarg !=argc && ((argc-newnarg)<=2 || (argc-newnarg)%2 != 1))) {
184 return 1;
185 }
186 if (i<newnarg) {
187 pick = (argv[i][0] == '.');
188 EF = DBRep::Get(argv[i],TopAbs_FACE);
189 if (EF.IsNull()) return 1;
190 }
191 while (i < newnarg) {
192 if (pick) {
193 DBRep_DrawableShape::LastPick(EF,u,v);
194 }
195 if (EF.ShapeType() == TopAbs_FACE) {
196 i++;
197 while (i < newnarg) {
198 TopoDS_Shape W;
199 Standard_Boolean rever = Standard_False;
200 if (argv[i][0] == '-') {
201 if (argv[i][1] == '\0')
202 return 1;
203 pick = (argv[i][1] == '.');
204 const char* Temp = argv[i]+1;
205 W = DBRep::Get(Temp,TopAbs_SHAPE,Standard_False);
206 rever = Standard_True;
207 }
208 else {
209 pick = (argv[i][0] == '.');
210 W = DBRep::Get(argv[i],TopAbs_SHAPE,Standard_False);
211 }
212 if (W.IsNull()) {
213 return 1;
214 }
215 TopAbs_ShapeEnum wtyp = W.ShapeType();
216 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE && pick) {
51740958 217 Standard_Real aTempU, aTempV;
218 DBRep_DrawableShape::LastPick(W, aTempU, aTempV);
7fd59977 219 wtyp = W.ShapeType();
220 }
221 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE) {
222 EF = DBRep::Get(argv[i]);
223 break;
224 }
225 else {
226 if (rever) {
227 W.Reverse();
228 }
229 if (wtyp == TopAbs_WIRE) {
230 Spls.Add(TopoDS::Wire(W),TopoDS::Face(EF));
231 }
232 else {
233 Spls.Add(TopoDS::Edge(W),TopoDS::Face(EF));
234 }
235 }
236 i++;
237 }
238 }
239 else
240 return 1;
241 }
68064d7b 242 i++;
243 while (argv[i][0] != '#') {
7fd59977 244 TopoDS_Shape Ew,Es;
245 TopoDS_Shape aLocalShape(DBRep::Get(argv[i],TopAbs_EDGE));
246 Es = TopoDS::Edge(aLocalShape);
247 if (Es.IsNull()) {
248 return 1;
249 }
250 aLocalShape = DBRep::Get(argv[i+1],TopAbs_EDGE);
251 Ew = TopoDS::Edge(aLocalShape);
252 if (Ew.IsNull()) {
253 return 1;
254 }
255 Spls.Add(TopoDS::Edge(Ew),TopoDS::Edge(Es));
68064d7b 256 i += 2;
7fd59977 257 }
258 Spls.Build();
259 const TopTools_ListOfShape& aLeftPart = Spls.Left();
68064d7b 260 const TopTools_ListOfShape& aRightPart = Spls.Right();
7fd59977 261 BRep_Builder BB;
262 TopoDS_Shape aShell;
263 BB.MakeShell(TopoDS::Shell(aShell));
68064d7b 264 TopTools_ListIteratorOfListOfShape anIter;
265 if (argv[argc - 1][0] == 'L') {
266 anIter.Initialize(aLeftPart);
267 }
268 else if (argv[argc - 1][0] == 'R') {
269 anIter.Initialize(aRightPart);
270 }
271 else {
272 return 1;
273 }
7fd59977 274 for(; anIter.More(); anIter.Next()) BB.Add(aShell, anIter.Value());
ab860031 275 aShell.Closed (BRep_Tool::IsClosed (aShell));
7fd59977 276 DBRep::Set(argv[1],aShell);
277 return 0;
278}
279
280static Standard_Integer BUC60870 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
281{
282 Standard_Integer i1;
283 if (argc != 5) {
586db386 284 di << "Usage : " << argv[0] << " result name_of_shape_1 name_of_shape_2 dev\n";
7fd59977 285 return 1;
286 }
287 const char *ns1 = (argv[2]), *ns2 = (argv[3]), *ns0 = (argv[1]);
288 TopoDS_Shape S1(DBRep::Get(ns1)), S2(DBRep::Get(ns2)) ;
91322f44 289 Standard_Real dev = Draw::Atof(argv[4]);
7fd59977 290 BRepExtrema_DistShapeShape dst(S1 ,S2, dev );
291 if (dst.IsDone()) {
292 char named[100];
91322f44 293 Sprintf(named, "%s%s" ,ns0,"_val");
7fd59977 294 char* tempd = named;
295 Draw::Set(tempd,dst.Value());
296 di << named << " ";
297 for (i1=1; i1<= dst.NbSolution(); i1++) {
298 gp_Pnt P1,P2;
299 P1 = (dst.PointOnShape1(i1));
300 P2 = (dst.PointOnShape2(i1));
301 if (dst.Value()<=1.e-9) {
302 TopoDS_Vertex V =BRepLib_MakeVertex(P1);
303 char namev[100];
304 if (i1==1) {
91322f44 305 Sprintf(namev, "%s" ,ns0);
7fd59977 306 } else {
91322f44 307 Sprintf(namev, "%s%d" ,ns0,i1);
7fd59977 308 }
309 char* tempv = namev;
310 DBRep::Set(tempv,V);
311 di << namev << " ";
312 } else {
313 char name[100];
314 TopoDS_Edge E = BRepLib_MakeEdge (P1, P2);
315 if (i1==1) {
91322f44 316 Sprintf(name,"%s",ns0);
7fd59977 317 } else {
91322f44 318 Sprintf(name,"%s%d",ns0,i1);
7fd59977 319 }
320 char* temp = name;
321 DBRep::Set(temp,E);
322 di << name << " " ;
323 }
324 }
325 } else {
586db386 326 di << "Faulty : found a problem\n";
7fd59977 327 }
328 return 0;
329}
330
331static Standard_Integer BUC60902 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
332{
333 Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt(1,5);
334 gp_Pnt aP(0., 0., 0.);
335 for(Standard_Integer i = 1; i <= 5; i++) {
336 aP.SetX((i-1)*1.57);
337 aP.SetY(Sin((i-1)*1.57));
338 aPnts->SetValue(i, aP);
339 }
340 GeomAPI_Interpolate anInterpolater(aPnts, Standard_False, Precision::Confusion());
341 anInterpolater.Perform();
342 if(!anInterpolater.IsDone()) {
586db386 343 di << "Faulty : error in interpolation\n";
7fd59977 344 return 1;
345 }
346 Handle(Geom_BSplineCurve) aCur = anInterpolater.Curve();
347 gp_Vec aFirstTang, aLastTang;
348 aCur->D1(aCur->FirstParameter(), aP, aFirstTang);
349 aCur->D1(aCur->LastParameter(), aP, aLastTang);
350 di << " Used Tang1 = " << aFirstTang.X() << " " << aFirstTang.Y() << " " << aFirstTang.Z() << "\n";
351 di << " Used Tang2 = " << aLastTang.X() << " " << aLastTang.Y() << " " << aLastTang.Z() << "\n";
352 GeomAPI_Interpolate anInterpolater1(aPnts, Standard_False, Precision::Confusion());
353 anInterpolater1.Load(aFirstTang, aLastTang, Standard_False);
354 anInterpolater1.Perform();
355 if(!anInterpolater1.IsDone()) {
586db386 356 di << "Faulty : error in interpolation 1\n";
7fd59977 357 return 1;
358 }
359 aCur = anInterpolater1.Curve();
360 gp_Vec aFirstTang1, aLastTang1;
361 aCur->D1(aCur->FirstParameter(), aP, aFirstTang1);
362 aCur->D1(aCur->LastParameter(), aP, aLastTang1);
363 di << " Tang1 after compute = " << aFirstTang1.X() << " " << aFirstTang1.Y() << " " << aFirstTang1.Z() << "\n";
364 di << " Tang2 after compute = " << aLastTang1.X() << " " << aLastTang1.Y() << " " << aLastTang1.Z() << "\n";
365 if(aFirstTang.IsEqual(aFirstTang1, Precision::Confusion(), Precision::Angular())) {
586db386 366 di << "First tangent is OK\n";
7fd59977 367 }
368 else {
586db386 369 di << "Faulty : first tangent is wrong\n";
7fd59977 370 }
371 if(aLastTang.IsEqual(aLastTang1, Precision::Confusion(), Precision::Angular())) {
586db386 372 di << "Last tangent is OK\n";
7fd59977 373 }
374 else {
586db386 375 di << "Faulty : last tangent is wrong\n";
7fd59977 376 }
377 return 0;
378}
379
380static Standard_Integer BUC60944 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
381{
382 if(argc != 2) {
586db386 383 di << "Usage : " << argv[0] << " path\n";
7fd59977 384 }
385
386 TCollection_AsciiString in(argv[1]);
387 OSD_Path* aPath = new OSD_Path(in);
388 TCollection_AsciiString out;
389 aPath->SystemName(out);
390 if(in == out)
586db386 391 di << "The convertion is right.\n";
7fd59977 392 else
393 di << "Faulty : The convertion is incorrect : " << out.ToCString() << "\n";
394 di << out.ToCString() << "\n";
04232180 395// std::cout << aPath->Trek() << " !" << std::endl;
7fd59977 396 return 0;
397}
398
399Standard_Boolean BuildWiresWithReshape
400 (const Handle(ShapeBuild_ReShape)& theReshape,
401 const TopTools_ListOfShape &theListOfEdges,
402 TopTools_ListOfShape &theListOfWires,
403 const Standard_Boolean isFixConnectedMode,
404 const Standard_Boolean isKeepLoopsMode,
405 const Standard_Real theTolerance)
406{
407 TopTools_ListIteratorOfListOfShape anEdgeIter;
408 Standard_Boolean isDone;
409 TopoDS_Wire aWire;
410
411 theListOfWires.Clear();
412 Handle(ShapeExtend_WireData) aWireData = new ShapeExtend_WireData;
413 Handle(ShapeFix_Wire) aShFixWire = new ShapeFix_Wire;
414 aShFixWire->SetContext (theReshape);
415
416 Handle(ShapeAnalysis_Wire) aWireAnalyzer;
417 ShapeAnalysis_WireOrder aWireOrder;
418
419 aShFixWire->Load(aWireData);
420 aShFixWire->SetPrecision(theTolerance);
421
422 for(anEdgeIter.Initialize(theListOfEdges); anEdgeIter.More(); anEdgeIter.Next())
423 aWireData->Add(TopoDS::Edge(anEdgeIter.Value()));
424
425 aWireOrder.KeepLoopsMode() = isKeepLoopsMode;
426 aWireAnalyzer = aShFixWire->Analyzer();
427 aWireAnalyzer->CheckOrder(aWireOrder, Standard_True);
428
429 aShFixWire->FixReorder(aWireOrder);
430 isDone = !aShFixWire->StatusReorder(ShapeExtend_FAIL);
431 if (!isDone)
432 return Standard_False;
433
434 if (isFixConnectedMode)
435 {
436 aShFixWire->ModifyTopologyMode() = Standard_True;
437 aShFixWire->FixConnected(theTolerance);
438 }
439
440 aWire = aWireData->Wire();
441
442// if (aWire.Closed())
443// {
444// theListOfWires.Append(aWire);
445// return Standard_True;
446// }
447
448 Standard_Integer i;
449 BRep_Builder aBuilder;
450 TopoDS_Wire aCurWire;
451 TopoDS_Vertex aVf;
452 TopoDS_Vertex aVl;
453 TopoDS_Vertex aVlast;
454 Standard_Integer aNbEdges = aWireData->NbEdges();
455
456 aBuilder.MakeWire(aCurWire);
457 if (aNbEdges >= 1)
458 {
459 TopoDS_Edge anE = aWireData->Edge(1);
460 TopExp::Vertices(anE, aVf, aVlast, Standard_True);
461 aBuilder.Add(aCurWire, anE);
462 }
463
464 for(i = 2; i <= aNbEdges; i++)
465 {
466 TopoDS_Edge anE = aWireData->Edge(i);
467 TopExp::Vertices(anE, aVf, aVl, Standard_True);
468 if (aVf.IsSame(aVlast))
469 {
470 aBuilder.Add(aCurWire, anE);
471 aVlast = aVl;
472 }
473 else
474 {
475 aVlast = aVl;
476 TopExp::Vertices(aCurWire, aVf, aVl);
477 if (aVf.IsSame(aVl))
478 aCurWire.Closed(Standard_True);
479 theListOfWires.Append(aCurWire);
480 aBuilder.MakeWire(aCurWire);
481 aBuilder.Add(aCurWire, anE);
482 }
483 }
484
485 TopExp::Vertices(aCurWire, aVf, aVl);
486 if (aVf.IsSame(aVl))
487 aCurWire.Closed(Standard_True);
488 theListOfWires.Append(aCurWire);
489
490 return Standard_True;
491}
492
493Standard_Boolean BuildWires(const TopTools_ListOfShape &theListOfEdges,
494 TopTools_ListOfShape &theListOfWires,
495 const Standard_Boolean isFixConnectedMode = Standard_False,
496 const Standard_Boolean isKeepLoopsMode = Standard_True,
497 const Standard_Real theTolerance = Precision::Confusion())
498{
499 Handle(ShapeBuild_ReShape) aReshape = new ShapeBuild_ReShape;
500 return BuildWiresWithReshape (aReshape, theListOfEdges, theListOfWires,
501 isFixConnectedMode, isKeepLoopsMode, theTolerance);
502}
503
504Standard_Boolean BuildBoundWires(const TopoDS_Shape &theShell,
505 TopTools_ListOfShape &theListOfWires)
506{
507 TopTools_IndexedDataMapOfShapeListOfShape
508 anEdgeFaceMap;
509 Standard_Integer i;
510 Standard_Boolean isBound;
511 TopTools_ListOfShape aBoundaryEdges;
512
513 TopExp::MapShapesAndAncestors(theShell, TopAbs_EDGE, TopAbs_FACE, anEdgeFaceMap);
514
515 isBound = Standard_False;
516 for (i = 1; i <= anEdgeFaceMap.Extent(); i++)
517 {
518 const TopTools_ListOfShape &anAncestFaces = anEdgeFaceMap.FindFromIndex(i);
519 if (anAncestFaces.Extent() == 1)
520 {
521 const TopoDS_Edge &anEdge = TopoDS::Edge(anEdgeFaceMap.FindKey(i));
522 if (!BRep_Tool::Degenerated(anEdge))
523 {
524 aBoundaryEdges.Append(anEdge);
525 isBound = Standard_True;
526 }
527 }
528 }
529
530 if (!isBound)
531 return Standard_True;
532
533 return BuildWires(aBoundaryEdges, theListOfWires);
534}
535
536static Standard_Integer BUC60868 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
537{
538 if (argc != 3) {
586db386 539 di << "Usage : " <<argv[0] << " Result Shell\n";
7fd59977 540 return 1;
541 }
542
543 TopoDS_Shape aShell = DBRep::Get(argv[2]);
544
545 if (aShell.IsNull()) {
586db386 546 di << "Faulty : The shape is NULL\n";
7fd59977 547 return 1;
548 }
549
550 TopTools_ListOfShape aListOfWires;
551 BuildBoundWires(aShell, aListOfWires);
552
553 TopoDS_Shape aRes;
554 if (aListOfWires.IsEmpty())
586db386 555 di << "no bound\n";
7fd59977 556 else if (aListOfWires.Extent() == 1)
557 aRes = aListOfWires.First();
558 else {
559 BRep_Builder aBld;
560 aBld.MakeCompound (TopoDS::Compound(aRes));
561 TopTools_ListIteratorOfListOfShape aWireIter (aListOfWires);
562 for(; aWireIter.More(); aWireIter.Next())
563 aBld.Add (aRes, aWireIter.Value());
564 }
565
566 DBRep::Set(argv[1], aRes);
567 return 0;
568}
569
570static Standard_Integer BUC60924 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
571{
572 if (argc != 5) {
586db386 573 di << "Usage : " <<argv[0] << " curve X Y Z\n";
7fd59977 574 return 1;
575 }
576
577 Handle(Geom_Curve) aCurve = DrawTrSurf::GetCurve(argv[1]);
578
579 if (aCurve.IsNull()) {
586db386 580 di << "Faulty : the curve is NULL.\n";
7fd59977 581 return 1;
582 }
583
91322f44 584 gp_XYZ aVec(Draw::Atof(argv[2]),Draw::Atof(argv[3]),Draw::Atof(argv[4]));
7fd59977 585
586 Standard_Boolean isPlanar=Standard_False;
587 isPlanar=ShapeAnalysis_Curve::IsPlanar(aCurve,aVec,1e-7);
588
589 if(isPlanar)
586db386 590 di << "The curve is planar !\n";
7fd59977 591 else
586db386 592 di << "Faulty : the curve is not planar!\n";
7fd59977 593
594 return 0;
595}
596
597static Standard_Integer BUC60920(Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
598{
599
600 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
601 if(myAISContext.IsNull()) {
04232180 602 std::cerr << "use 'vinit' command before " << argv[0] << "\n";
7fd59977 603 return -1;
604 }
605
606 di.Eval("box b 10 10 10");
607 di.Eval("box w 20 20 20");
608 di.Eval("explode w e");
609
610 di.Eval(" vdisplay b");
611 di.Eval("vsetdispmode 1");
612
613 const char * Shname="w_11";
614 TopoDS_Shape theShape = DBRep::Get(Shname);
615
616 Handle(AIS_Shape) anAISShape = new AIS_Shape( theShape );
617 myAISContext->Display( anAISShape, Standard_True );
618
619 Handle(V3d_View) myV3dView = ViewerTest::CurrentView();
620
621 double Xv,Yv;
622 myV3dView->Project(20,20,0,Xv,Yv);
04232180 623// std::cout<<Xv<<"\t"<<Yv<<std::endl;
7fd59977 624
625 Standard_Integer Xp,Yp;
626 myV3dView->Convert(Xv,Yv,Xp,Yp);
04232180 627// std::cout<<Xp<<"\t"<<Yp<<std::endl;
7fd59977 628
0577ae8c 629 myAISContext->MoveTo (Xp,Yp, myV3dView, Standard_True);
7fd59977 630
631// if (myAISContext->IsHilighted(anAISShape))
04232180 632// std::cout << "has hilighted shape : OK" << std::endl;
633// else std::cout << "has hilighted shape : bugged - Faulty " << std::endl;
7fd59977 634
635 return 0;
636}
637
638#include <LDOMParser.hxx>
639static Standard_Integer OCC983 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
640{
641 if (argc != 2) {
586db386 642 di << "Usage : " << argv[0] << " file\n";
7fd59977 643 return 1;
644 }
645
646 LDOMParser aParser;
647 LDOM_Document myDOM;
648
649 const char *File = (argv[1]);
650
651 if(!aParser.parse(File)) {
652 myDOM=aParser.getDocument();
586db386 653 di<<"Document parsed\n";
7fd59977 654 } else {
586db386 655 di<<"Document not parsed\n";
7fd59977 656 return 0;
657 }
658
659 LDOM_Element root = myDOM.getDocumentElement();
660
661 if ( root.isNull() ) {
586db386 662 di<<"Root element is null\n";
7fd59977 663 return 0;
664 }
665
666 TCollection_AsciiString RootName = root.getTagName();
667 di << " RootName = " << RootName.ToCString() << "\n";
668 LDOM_NodeList aChildList = root.GetAttributesList();
669 for(Standard_Integer i=0,n=aChildList.getLength();i<n;i++) {
670 LDOM_Node item = aChildList.item(i);
671 TCollection_AsciiString itemName = item.getNodeName();
672 TCollection_AsciiString itemValue = item.getNodeValue();
673 di << " AttributeName = " << itemName.ToCString() << "\n";
674 di << " AttributeValue = " << itemValue.ToCString() << "\n";
675 }
676
677// LDOM_Element element;
678// for ( element = (const LDOM_Element&) root.getFirstChild();
679// !element.isNull();
680// element = (const LDOM_Element&) element.getNextSibling() ) {
681 LDOM_Element element;
682 LDOM_Node node;
683 for ( node = root.getFirstChild(), element = (const LDOM_Element&) node;
684 !element.isNull();
685 node = element.getNextSibling(), element = (const LDOM_Element&) node) {
686 TCollection_AsciiString ElementName = element.getTagName();
687 di << " ElementName = " << ElementName.ToCString() << "\n";
688 LDOM_NodeList aChildList2 = element.GetAttributesList();
689 for(Standard_Integer i2=0,n2=aChildList2.getLength();i2<n2;i2++) {
690 LDOM_Node item2 = aChildList2.item(i2);
691 TCollection_AsciiString itemName2 = item2.getNodeName();
692 TCollection_AsciiString itemValue2 = item2.getNodeValue();
693 di << " AttributeName = " << itemName2.ToCString() << "\n";
694 di << " AttributeValue = " << itemValue2.ToCString() << "\n";
695 }
696 }
697
698 return 0;
699}
700
701static Standard_Integer OCC984 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
702{
703 if (argc != 2) {
586db386 704 di << "Usage : " << argv[0] << " file\n";
7fd59977 705 return 1;
706 }
707
708 LDOMParser aParser;
709 LDOM_Document myDOM;
710
711 //Standard_Character *File = new Standard_Character [100];
91322f44 712 //Sprintf(File,"%s",argv[1]);
7fd59977 713 const char *File = (argv[1]);
714
715 if(!aParser.parse(File)) {
716 myDOM=aParser.getDocument();
586db386 717 di<<"Document parsed\n";
7fd59977 718 } else {
586db386 719 di<<"Document not parsed\n";
7fd59977 720 }
721
722 return 0;
723}
724
7fd59977 725//#include <math.h>
726// See QAOCC.cxx OCC6143
727//static Standard_Integer OCC1723 (Draw_Interpretor& /*di*/, Standard_Integer argc, const char ** argv)
728//{
729// if( argc != 1)
730// {
04232180 731// std::cout << "Usage : " << argv[0] << std::endl;
7fd59977 732// return 1;
733// }
734//
735// Standard_Boolean isBad = Standard_False, isCaught;
736//
737// // Case 1
738// isCaught = Standard_False;
739// {
740// try {
741// OCC_CATCH_SIGNALS
742// Standard_Integer a = 1;
743// Standard_Integer b = 0;
744// Standard_Integer c = a / b;
745// }
746// catch ( Standard_Failure ) {
747// isCaught = Standard_True;
04232180 748// std::cout << "OCC1723 Case 1 : OK" << std::endl;
7fd59977 749// }
750// }
751// isBad = isBad || !isCaught;
752//
753// // Case 2
754// isCaught = Standard_False;
755// {
756// try {
757// OCC_CATCH_SIGNALS
758// Standard_Real d = -1.0;
759// Standard_Real e = sqrt(d);
760// }
761// catch ( Standard_Failure ) {
762// isCaught = Standard_True;
04232180 763// std::cout << "OCC1723 Case 2 : OK" << std::endl;
7fd59977 764// }
765// }
766// isBad = isBad || !isCaught;
767//
768// // Case 3
769// isCaught = Standard_False;
770// {
771// try {
772// OCC_CATCH_SIGNALS
773// Standard_Real f = 1.0e-200;
774// Standard_Real g = 1.0e-200;
775// Standard_Real h = f * g;
776// }
777// catch ( Standard_Failure ) {
778// isCaught = Standard_True;
04232180 779// std::cout << "OCC1723 Case 3 : OK" << std::endl;
7fd59977 780// }
781// }
782// // MSV: underflow is not caught
783// //isBad = isBad || !isCaught;
784//
785// // Case 4
786// isCaught = Standard_False;
787// {
788// try {
789// OCC_CATCH_SIGNALS
790// Standard_Real i = 1.0e+200;
791// Standard_Real j = 1.0e+200;
792// Standard_Real k = i * j;
793// }
794// catch ( Standard_Failure ) {
795// isCaught = Standard_True;
04232180 796// std::cout << "OCC1723 Case 4 : OK" << std::endl;
7fd59977 797// }
798// }
799// isBad = isBad || !isCaught;
800//
801// if (isBad) {
04232180 802// std::cout << "OCC1723 : Error" << std::endl;
7fd59977 803// } else {
04232180 804// std::cout << "OCC1723 : OK" << std::endl;
7fd59977 805// }
806//
807// return 0;
808//}
809
810#include <locale.h>
811static Standard_Integer OCC1919_get (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
812{
813 if( argc != 1)
814 {
815 di << "Usage : " << argv[0] << "\n";
816 return 1;
817 }
818 const TCollection_AsciiString anOldNumLocale =
819 (Standard_CString) setlocale (LC_NUMERIC, NULL);
820 di << "LC_NUMERIC = " << anOldNumLocale.ToCString() << "\n";
821 return 0;
822}
823static Standard_Integer OCC1919_set (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
824{
825 if( argc != 2)
826 {
586db386 827 di << "Usage : " << argv[0] << " LC_NUMERIC\n";
7fd59977 828 return 1;
829 }
830 TCollection_AsciiString aNumLocale(argv[1]);
831 setlocale(LC_ALL, "") ;
832 setlocale(LC_NUMERIC, aNumLocale.ToCString()) ;
833 return 0;
834}
835#include <DDF.hxx>
836#include <TDF_Label.hxx>
837#include <TDataStd_Real.hxx>
838#include <NCollection_BaseMap.hxx>
839static Standard_Integer OCC1919_real (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
840{
841 if (argc == 4) {
842 Handle(TDF_Data) DF;
843 if (!DDF::GetDF(argv[1],DF)) return 1;
844 TDF_Label L;
845 DDF::AddLabel(DF, argv[2], L);
846
91322f44 847 //TDataStd_Real::Set(L,Draw::Atof(arg[3]));
7fd59977 848 TCollection_AsciiString AsciiStringReal(argv[3]);
849 if (!AsciiStringReal.IsRealValue()) return 1;
850 Standard_Real aReal = AsciiStringReal.RealValue();
851 di << "aReal = " << aReal << "\n";
852
853 TDataStd_Real::Set(L,aReal);
854 return 0;
855 }
856 return 1;
857}
858
859#include <TDataStd_UAttribute.hxx>
860static Standard_Integer OCC2932_SetIDUAttribute (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
861{
862 if( argc != 5)
863 {
586db386 864 di << "Usage : " << argv[0] << " (DF, entry, oldLocalID, newLocalID)\n";
7fd59977 865 return 1;
866 }
867 Handle(TDF_Data) DF;
868 if (!DDF::GetDF(argv[1],DF)) return 1;
869 TDF_Label label;
870 if( !DDF::FindLabel(DF, argv[2], label) ) {
871 di << "No label for entry " << argv[2] << "\n";
872 return 0;
873 }
874 Standard_GUID old_guid(argv[3]); //"00000000-0000-0000-2222-000000000000");
875 Standard_GUID new_guid(argv[4]); //"00000000-0000-0000-2222-000000000001");
876
877 Handle(TDataStd_UAttribute) UA;
878 if( !label.FindAttribute(old_guid, UA) ) {
879 di << "No UAttribute Attribute on label " << argv[2] << "\n";
880 return 0;
881 }
882 Handle(TDataStd_UAttribute) anotherUA;
883 if( label.FindAttribute(new_guid, anotherUA) ) {
884 di << "There is this UAttribute Attribute on label " << argv[2] << "\n";
885 return 0;
886 }
887 UA->SetID(new_guid);
888 return 0;
889}
890
891static Standard_Integer OCC2932_SetTag (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
892{
893 if( argc != 4)
894 {
586db386 895 di << "Usage : " << argv[0] << " (DF, entry, Tag)\n";
7fd59977 896 return 1;
897 }
898 Handle(TDF_Data) DF;
899 if (!DDF::GetDF(argv[1],DF)) return 1;
900 TDF_Label L;
901 DDF::AddLabel(DF, argv[2], L);
91322f44 902 Standard_Integer Tag = Draw::Atoi(argv[3]);
7fd59977 903 Handle(TDF_TagSource) A = TDF_TagSource::Set(L);
904 A->Set(Tag);
905 return 0;
906}
907
908#include <TDataStd_Current.hxx>
909static Standard_Integer OCC2932_SetCurrent (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
910{
911 if( argc != 3)
912 {
586db386 913 di << "Usage : " << argv[0] << " (DF, entry)\n";
7fd59977 914 return 1;
915 }
916 Handle(TDF_Data) DF;
917 if (!DDF::GetDF(argv[1],DF)) return 1;
918 TDF_Label L;
919 DDF::AddLabel(DF, argv[2], L);
920 TDataStd_Current::Set(L);
921 return 0;
922}
923
924#include <TDataStd_Expression.hxx>
925static Standard_Integer OCC2932_SetExpression (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
926{
927 if( argc != 4)
928 {
586db386 929 di << "Usage : " << argv[0] << " (DF, entry, Expression)\n";
7fd59977 930 return 1;
931 }
932 Handle(TDF_Data) DF;
933 if (!DDF::GetDF(argv[1],DF)) return 1;
934 TDF_Label L;
935 DDF::AddLabel(DF, argv[2], L);
936 TCollection_ExtendedString Expression(argv[3]);
937 Handle(TDataStd_Expression) A = TDataStd_Expression::Set(L);
938 A->SetExpression(Expression);
939 return 0;
940}
941
942#include <TDataStd_Relation.hxx>
943static Standard_Integer OCC2932_SetRelation (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
944{
945 if( argc != 4)
946 {
586db386 947 di << "Usage : " << argv[0] << " (DF, entry, Relation)\n";
7fd59977 948 return 1;
949 }
950 Handle(TDF_Data) DF;
951 if (!DDF::GetDF(argv[1],DF)) return 1;
952 TDF_Label L;
953 DDF::AddLabel(DF, argv[2], L);
954 TCollection_ExtendedString Relation(argv[3]);
955 Handle(TDataStd_Relation) A = TDataStd_Relation::Set(L);
956 A->SetRelation(Relation);
957 return 0;
958}
959
960static Standard_Integer OCC3277 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
961{
962 if( argc != 2)
963 {
586db386 964 di << "Usage : " << argv[0] << " string\n";
7fd59977 965 return 1;
966 }
967 TCollection_ExtendedString ExtendedString;
968 TCollection_ExtendedString InputString(argv[1]);
969 ExtendedString.Cat(InputString);
04232180 970 //ExtendedString.Print(std::cout);
7fd59977 971 Standard_SStream aSStream;
972 ExtendedString.Print(aSStream);
973 di << aSStream;
974 return 0;
975}
976
977static Standard_Integer OCC6794 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
978{
979 if (argc > 2)
980 {
586db386 981 di << "Usage: " << argv[0] << " [nb]\n";
7fd59977 982 return 1;
983 }
984
985 char* max = ::getenv( "MMGT_THRESHOLD" );
986
987 Standard_Integer aNb = 1;
988 if ( max )
91322f44 989 aNb += Draw::Atoi( max );
7fd59977 990 else
991 aNb += 40000;
992
993 if ( argc > 1 )
91322f44 994 aNb = Draw::Atoi( argv[1] );
7fd59977 995
996 di << "Use nb = " << aNb << "\n";
997
998 const char* c = "a";
999 {
1000 TCollection_AsciiString anAscii;
1001 for ( int i = 1; i <= aNb; i++ ) {
1002 anAscii += TCollection_AsciiString( c );
1003 }
1004 Standard_Integer aLength = anAscii.Length();
1005 di << "aLength = " << aLength << "\n";
1006 }
1007 return 0;
1008}
1009
1010static Standard_Integer OCC16485 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1011{
1012 if (argc > 1)
1013 {
1014 di << "Usage: " << argv[0] << "\n";
1015 return 1;
1016 }
1017
1018 // Create points with X co-ordinate from varying from 0. to 1000.
1019 // anc compute cumulative bounding box by adding boxes for all the
1020 // points, enlarged on tolerance
1021
1022 Standard_Real tol = 1e-3;
1023 int nbstep = 1000;
1024 Bnd_Box Box;
1025 for ( int i=0; i <= nbstep; i++ )
1026 {
1027 gp_Pnt p(i, 0., 0.);
1028 Bnd_Box B;
1029 B.Add(p);
1030 B.Enlarge(tol);
1031 B.Add ( Box );
1032 Box = B; // in this case XMin of Box will grow each time
1033 }
1034
1035 Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
1036 Box.Get (xmin, ymin, zmin, xmax, ymax, zmax);
04232180 1037 //std::cout.precision(16);
1038 //std::cout << "Resulting dimensions: Xmin = " << xmin << " , Xmax = " << xmax << " , Tolerance = " << tol << std::endl;
7fd59977 1039 di << "Resulting dimensions: Xmin = " << xmin << " , Xmax = " << xmax << " , Tolerance = " << tol << "\n";
1040 if ( Abs ( xmin + tol ) > 1e-10 )
1041 di << "TEST FAILED: Xmin must be equal to -1e3!\n";
1042 else
1043 di << "TEST OK\n";
04232180 1044 //std::cout << "TEST FAILED: Xmin must be equal to -1e3!" << std::endl;
1045 //std::cout << "TEST OK" << std::endl;
7fd59977 1046 //di << "TEST FAILED: Xmin must be equal to -1e3!\n";
1047 //di << "TEST OK\n";
1048 return 0;
1049}
1050//Resulting dimensions: Xmin = -0.001 , Xmax = 1000.001 , Tolerance = 0.001
1051//TEST OK
1052
1cd84fee 1053void QABugs::Commands_14(Draw_Interpretor& theCommands) {
1054 const char *group = "QABugs";
7fd59977 1055
1056 theCommands.Add ("BUC60897", "BUC60897", __FILE__, BUC60897, group);
1057 theCommands.Add ("BUC60889", "BUC60889 point_1 point_2 name_of_edge bndbox_X1 bndbox_Y1 bndbox_Z1 bndbox_X2 bndbox_Y2 bndbox_Z2", __FILE__, BUC60889, group);
1058 theCommands.Add ("BUC60852", "BUC60852 name_of_edge bndbox_X1 bndbox_Y1 bndbox_Z1 bndbox_X2 bndbox_Y2 bndbox_Z2", __FILE__, BUC60852, group);
68064d7b 1059 theCommands.Add ("BUC60854", "BUC60854 result_shape name_of_shape name_of_face name_of_wire/name_of_edge [ name_of_wire/name_of_edge ... ] [ name_of_face name_of_wire/name_of_edge [ name_of_wire/name_of_edge ... ] ... ] [ @ edge_on_shape edge_on_wire [ edge_on_shape edge_on_wire ... ] ] [ # L/R ]", __FILE__, BUC60854, group);
7fd59977 1060 theCommands.Add ("BUC60870", "BUC60870 result name_of_shape_1 name_of_shape_2 dev", __FILE__, BUC60870, group);
1061 theCommands.Add ("BUC60902", "BUC60902", __FILE__, BUC60902, group);
1062 theCommands.Add ("BUC60944", "BUC60944 path", __FILE__, BUC60944, group);
1063 theCommands.Add ("BUC60868", "BUC60868 Result Shell", __FILE__, BUC60868, group);
1064 theCommands.Add ("BUC60924", "BUC60924 curve X Y Z", __FILE__, BUC60924, group);
1065 theCommands.Add ("BUC60920", "BUC60920", __FILE__, BUC60920, group);
1066 theCommands.Add ("OCC983", "OCC983 file", __FILE__, OCC983, group);
1067 theCommands.Add ("OCC984", "OCC984 file", __FILE__, OCC984, group);
1068
7fd59977 1069// theCommands.Add ("OCC1723", "OCC1723", __FILE__, OCC1723, group);
1070
1071 theCommands.Add ("OCC1919_get", "OCC1919_get", __FILE__, OCC1919_get, group);
1072
1073 theCommands.Add ("OCC1919_set", "OCC1919_set LC_NUMERIC", __FILE__, OCC1919_set, group);
1074
1075 theCommands.Add ("OCC1919_real", "OCC1919_real (DF, entry, value)", __FILE__, OCC1919_real, group);
1076
1077 theCommands.Add ("OCC2932_SetIDUAttribute", "OCC2932_SetIDUAttribute (DF, entry, oldLocalID, newLocalID)", __FILE__, OCC2932_SetIDUAttribute, group);
1078
1079 theCommands.Add ("OCC2932_SetTag", "OCC2932_SetTag (DF, entry, Tag)", __FILE__, OCC2932_SetTag, group);
1080
1081 theCommands.Add ("OCC2932_SetCurrent", "OCC2932_SetCurrent (DF, entry)", __FILE__, OCC2932_SetCurrent, group);
1082
1083 theCommands.Add ("OCC2932_SetExpression", "OCC2932_SetExpression (DF, entry, Expression)", __FILE__, OCC2932_SetExpression, group);
1084
1085 theCommands.Add ("OCC2932_SetRelation", "OCC2932_SetRelation (DF, entry, Relation)", __FILE__, OCC2932_SetRelation, group);
1086
1087 theCommands.Add ("OCC3277", "OCC3277 string", __FILE__, OCC3277, group);
1088
1089 theCommands.Add ("OCC6794", "OCC6794 [nb]", __FILE__, OCC6794, group);
1090
1091 theCommands.Add ("OCC16485", "OCC16485", __FILE__, OCC16485, group);
1092
1093 return;
1094}