0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / QABugs / QABugs_1.cxx
CommitLineData
b311480e 1// Created on: 2002-05-21
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
1cd84fee 16#include <QABugs.hxx>
7fd59977 17
18#include <Draw_Interpretor.hxx>
19#include <DBRep.hxx>
20#include <DrawTrSurf.hxx>
21#include <AIS_InteractiveContext.hxx>
22#include <ViewerTest.hxx>
23#include <AIS_Shape.hxx>
24#include <TopoDS_Shape.hxx>
25
26#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
27#include <TColStd_ListIteratorOfListOfInteger.hxx>
28#include <TColStd_MapOfInteger.hxx>
29
30#include <TDocStd_Document.hxx>
31#include <TDocStd_Application.hxx>
32#include <DDocStd.hxx>
33#include <TDocStd_Owner.hxx>
34#include <TDF_Label.hxx>
35#include <DDF.hxx>
36#include <TPrsStd_AISViewer.hxx>
37#include <TPrsStd_AISPresentation.hxx>
38
39#include <Draw_Viewer.hxx>
40#include <Draw.hxx>
41
42#ifndef WNT
43extern Draw_Viewer dout;
44#else
45Standard_IMPORT Draw_Viewer dout;
46#endif
47
48#include <BRep_Builder.hxx>
49#include <BRepTools.hxx>
50#include <TopoDS_Wire.hxx>
51#include <BRepBuilderAPI_MakeFace.hxx>
52#include <TopoDS.hxx>
53
54#if ! defined(WNT)
55extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
56#else
57Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
58#endif
59
60static TColStd_MapOfInteger theactivatedmodes(8);
61
62#include <AIS_PlaneTrihedron.hxx>
63#include <TopoDS_Face.hxx>
64#include <TopExp_Explorer.hxx>
65#include <TopoDS_Edge.hxx>
66#include <BRepAdaptor_Curve.hxx>
67#include <GC_MakePlane.hxx>
68
69static Standard_Integer OCC328bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
70{
71 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
72 if(aContext.IsNull()) {
73 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
74 return 1;
75 }
76
77 if ( argc != 3) {
78 di << "ERROR : Usage : " << argv[0] << " shape mode" << "\n";
79 return 1;
80 }
81
82 Standard_Integer ChoosingMode = -1;
83 if ( strcmp (argv [2], "VERTEX") == 0 ) {
84 ChoosingMode = 1;
85 }
86 if ( strcmp (argv [2], "EDGE") == 0 ) {
87 ChoosingMode = 2;
88 }
89 if ( strcmp (argv [2], "WIRE") == 0 ) {
90 ChoosingMode = 3;
91 }
92 if ( strcmp (argv [2], "FACE") == 0 ) {
93 ChoosingMode = 4;
94 }
95 if ( strcmp (argv [2], "SHELL") == 0 ) {
96 ChoosingMode = 5;
97 }
98 if ( strcmp (argv [2], "SOLID") == 0 ) {
99 ChoosingMode = 6;
100 }
101 if ( strcmp (argv [2], "COMPOUND") == 0 ) {
102 ChoosingMode = 7;
103 }
104 if ( ChoosingMode == -1 ) {
105 di << "ERROR : " << argv[1] << " : vrong value of a mode" << "\n";
106 return 1;
107 }
108
eb4320f2 109 Standard_Boolean updateviewer = Standard_True;
7fd59977 110
111 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
112
113 TCollection_AsciiString aName(argv[1]);
114 Handle(AIS_InteractiveObject) AISObj;
115
116 if(!aMap.IsBound2(aName)) {
117 di << "Use 'vdisplay' before" << "\n";
118 return 1;
119 } else {
120 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
121 if(AISObj.IsNull()){
122 di << argv[1] << " : No interactive object" << "\n";
123 return 1;
124 }
125
126 if (!aContext->HasOpenedContext()) {
127 aContext->OpenLocalContext();
128 }
129
130 if(!theactivatedmodes.Contains(ChoosingMode)) {
131 aContext->ActivateStandardMode(AIS_Shape::SelectionType(ChoosingMode));
132 theactivatedmodes.Add(ChoosingMode);
133 }
eb4320f2 134 aContext->Erase(AISObj, updateviewer);
7fd59977 135 aContext->UpdateCurrentViewer();
136
137 aContext->Display(AISObj, updateviewer);
138 aContext->UpdateCurrentViewer();
139
140 const TColStd_ListOfInteger& aList = aContext->ActivatedStandardModes();
141 Standard_Integer SelectMode;
142 TCollection_AsciiString SelectModeString;
143 TColStd_ListIteratorOfListOfInteger itr(aList);
144 for (; itr.More(); itr.Next()) {
145 SelectMode = itr.Value();
146 //cout << "SelectMode = " << SelectMode << endl;
147
148 switch (SelectMode)
149 {
150 case 1:
151 SelectModeString.Copy("VERTEX");
152 break;
153 case 2:
154 SelectModeString.Copy("EDGE");
155 break;
156 case 3:
157 SelectModeString.Copy("WIRE");
158 break;
159 case 4:
160 SelectModeString.Copy("FACE");
161 break;
162 case 5:
163 SelectModeString.Copy("SHELL");
164 break;
165 case 6:
166 SelectModeString.Copy("SOLID");
167 break;
168 case 7:
169 SelectModeString.Copy("COMPOUND");
170 break;
171 default:
172 SelectModeString.Copy("UNKNOWN");
173 }
174 di << "SelectMode = " << SelectModeString.ToCString() << "\n";
175
176 }
177 }
178
179 return 0;
180}
181
182static Standard_Integer OCC159bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
183{
184 if ( argc != 2) {
185 di << "ERROR : Usage : " << argv[0] << " Doc" << "\n";
186 return 1;
187 }
188
189 Handle(TDocStd_Document) D;
190 if (!DDocStd::GetDocument(argv[1],D)) return 1;
191
192 Standard_Integer DocRefCount1 = D->GetRefCount();
193 di << "DocRefCount1 = " << DocRefCount1 << "\n";
194
195 Handle(TDocStd_Owner) Owner;
196 if (!D->Main().Root().FindAttribute(TDocStd_Owner::GetID(),Owner)) return 1;
197
198 Handle(TDocStd_Document) OwnerD1 = Owner->GetDocument();
199 if (OwnerD1.IsNull()) {
200 di << "DocOwner1 = NULL" << "\n";
201 } else {
202 di << "DocOwner1 = NOTNULL" << "\n";
203 }
204
205 Handle(TDocStd_Application) A;
206 if (!DDocStd::Find(A)) return 1;
207 A->Close(D);
208
209 Handle(Draw_Drawable3D) DD = Draw::Get(argv[1],Standard_False);
210 dout.RemoveDrawable (DD);
211
212 Handle(TDocStd_Document) OwnerD2 = Owner->GetDocument();
213 if (OwnerD2.IsNull()) {
214 di << "DocOwner2 = NULL" << "\n";
215 } else {
216 di << "DocOwner2 = NOTNULL" << "\n";
217 }
218
219 Standard_Integer DocRefCount2 = D->GetRefCount();
220 di << "DocRefCount2 = " << DocRefCount2 << "\n";
221
222 return 0;
223}
224
225static Standard_Integer OCC145bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
226{
227 if ( argc != 3) {
228 di << "ERROR : Usage : " << argv[0] << " Shape MaxNbr" << "\n";
229 return 1;
230 }
231
232 TCollection_AsciiString aFileName = argv[1];
91322f44 233 Standard_Integer aMaxNbr = Draw::Atoi(argv[2]);
7fd59977 234
235 BRep_Builder aBld;
236 TopoDS_Shape aShape;
237
238 if (!BRepTools::Read(aShape, aFileName.ToCString(), aBld)) {
239 di << "ERROR :Could not read a shape!!!" << "\n";
240 return 1;
241 }
242
243 Standard_Integer i;
244 TopoDS_Wire aWire = TopoDS::Wire(aShape);
245
246 for (i = 1; i <= aMaxNbr; i++) {
247 BRepBuilderAPI_MakeFace aMF(aWire);
248 if (!aMF.IsDone()) {
249 di << "ERROR : Could not make a face" << "\n";
250 return 1;
251 }
252 }
253
254 return 0;
255}
256
257static Standard_Integer OCC73_SelectionMode (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
258{
259 if ( argc < 3) {
260 di << "ERROR : Usage : " << argv[0] << " DOC entry [SelectionMode]" << "\n";
261 return 1;
262 }
263
264 Handle(TDocStd_Document) D;
265 //cout << "OCC73_SelectionMode 1" << endl;
266 if (!DDocStd::GetDocument(argv[1],D)) return 1;
267 TDF_Label L;
268 //cout << "OCC73_SelectionMode 2" << endl;
269 if (!DDF::FindLabel(D->GetData(),argv[2],L)) return 1;
270
271 Handle(TPrsStd_AISViewer) viewer;
272 //cout << "OCC73_SelectionMode 3" << endl;
273 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
274
275 Handle(TPrsStd_AISPresentation) prs;
276 //cout << "OCC73_SelectionMode 4" << endl;
277 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
278 if( argc == 4 ) {
91322f44 279 prs->SetSelectionMode((Standard_Integer)Draw::Atoi(argv[3]));
7fd59977 280 TPrsStd_AISViewer::Update(L);
281 }
282 else {
283 Standard_Integer SelectionMode = prs->SelectionMode();
284 //cout << "SelectionMode = " << SelectionMode << endl;
285 di<<SelectionMode;
286 }
287 }
288 //cout << "OCC73_SelectionMode 5" << endl;
289
290 return 0;
291}
292
293static Standard_Integer OCC10bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
294{
295 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
296 if(aContext.IsNull()) {
297 di << "use 'vinit' command before " << argv[0] << "\n";
298 return 1;
299 }
300
301 if(argc != 4) {
302 di << "Usage : " << argv[0] << " name plane Length" << "\n";
303 return 1;
304 }
305
306 TopoDS_Shape S = DBRep::Get( argv[2] );
307 if ( S.IsNull() ) {
308 di << "Shape is empty" << "\n";
309 return 1;
310 }
311
312 TCollection_AsciiString name(argv[1]);
91322f44 313 Standard_Real Length = Draw::Atof(argv[3]);
7fd59977 314
315 // Construction de l'AIS_PlaneTrihedron
316 Handle(AIS_PlaneTrihedron) theAISPlaneTri;
317
318 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
319 if (IsBound) {
320 // on recupere la shape dans la map des objets displayes
321 Handle(AIS_InteractiveObject) aShape =
322 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
323
324 // On verifie que l'AIS InteraciveObject est bien
325 // un AIS_PlaneTrihedron
326 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==4) {
327 // On downcast aShape de AIS_InteractiveObject a AIS_PlaneTrihedron
328 theAISPlaneTri = *(Handle(AIS_PlaneTrihedron)*) &aShape;
329
330 theAISPlaneTri->SetLength(Length);
331
332 aContext->Redisplay(theAISPlaneTri, Standard_False);
333 aContext->UpdateCurrentViewer();
334 }
335 } else {
336 TopoDS_Face FaceB=TopoDS::Face(S);
337
338 // Construction du Plane
339 // recuperation des edges des faces.
340 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
341
342 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
343 // declarations
344 gp_Pnt A,B,C;
345
346 // si il y a plusieurs edges
347 if (FaceExpB.More() ) {
348 FaceExpB.Next();
349 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
350 BRepAdaptor_Curve theCurveB(EdgeB);
351 BRepAdaptor_Curve theCurveC(EdgeC);
352 A=theCurveC.Value(0.1);
353 B=theCurveC.Value(0.9);
354 C=theCurveB.Value(0.5);
355 }
356 else {
357 // FaceB a 1 unique edge courbe
358 BRepAdaptor_Curve theCurveB(EdgeB);
359 A=theCurveB.Value(0.1);
360 B=theCurveB.Value(0.9);
361 C=theCurveB.Value(0.5);
362 }
363 // Construction du Geom_Plane
364 GC_MakePlane MkPlane(A,B,C);
365 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
366
367 // on le display & bind
368 theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
369
370 theAISPlaneTri->SetLength(Length);
371
372 GetMapOfAIS().Bind ( theAISPlaneTri, name);
373 aContext->Display(theAISPlaneTri );
374 }
375
376 Standard_Real getLength = theAISPlaneTri->GetLength();
377 di << "Length = " << Length << "\n";
378 di << "getLength = " << getLength << "\n";
379
380 if (getLength == Length) {
381 di << "OCC10: OK" << "\n";
382 } else {
383 di << "OCC10: ERROR" << "\n";
384 }
385
386 return 0;
387}
388
389static Standard_Integer OCC74bug_set (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
390{
391 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
392 if(aContext.IsNull()) {
393 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
394 return 1;
395 }
396
397 if ( argc != 3) {
398 di << "ERROR : Usage : " << argv[0] << " shape mode; set selection mode" << "\n";
399 return 1;
400 }
401
eb4320f2 402 Standard_Boolean updateviewer = Standard_True;
7fd59977 403
404 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
405
406 TCollection_AsciiString aName(argv[1]);
407 Handle(AIS_InteractiveObject) AISObj;
408
91322f44 409 Standard_Integer SelectMode = Draw::Atoi(argv[2]);
7fd59977 410
411 if(!aMap.IsBound2(aName)) {
412 di << "Use 'vdisplay' before" << "\n";
413 return 1;
414 } else {
415 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
416 if(AISObj.IsNull()){
417 di << argv[1] << " : No interactive object" << "\n";
418 return 1;
419 }
420 AISObj->SetSelectionMode(SelectMode);
421 if (!aContext->HasOpenedContext()) {
422 aContext->OpenLocalContext();
423 }
eb4320f2 424 aContext->Erase(AISObj, updateviewer);
7fd59977 425 aContext->UpdateCurrentViewer();
426 aContext->Display(AISObj, updateviewer);
427 aContext->UpdateCurrentViewer();
428 }
429 return 0;
430}
431
432static Standard_Integer OCC74bug_get (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
433{
434 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
435 if(aContext.IsNull()) {
436 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
437 return 1;
438 }
439
440 if ( argc != 2) {
441 di << "ERROR : Usage : " << argv[0] << " shape; get selection mode" << "\n";
442 return 1;
443 }
7fd59977 444
445 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
446
447 TCollection_AsciiString aName(argv[1]);
448 Handle(AIS_InteractiveObject) AISObj;
449
450 if(!aMap.IsBound2(aName)) {
451 di << "Use 'vdisplay' before" << "\n";
452 return 1;
453 } else {
454 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
455 if(AISObj.IsNull()){
456 di << argv[1] << " : No interactive object" << "\n";
457 return 1;
458 }
459 Standard_Integer SelectMode = AISObj->SelectionMode();
460 di << SelectMode << "\n";
461 }
462
463 return 0;
464}
465
466#include <BRepPrimAPI_MakeBox.hxx>
467#include <TDF_Data.hxx>
468#include <TNaming_Builder.hxx>
469#include <TNaming_NamedShape.hxx>
470
471static Standard_Integer OCC361bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
472{
473 if ( nb != 2) {
474 di << "ERROR : Usage : " << a[0] << " Doc" << "\n";
475 di << "-1" << "\n";
476 return -1;
477 }
478
479 Handle(TDocStd_Document) D;
480 if (!DDocStd::GetDocument(a[1],D)) {
481 di << "-2" << "\n";
482 return 1;
483 }
484
485 BRepPrimAPI_MakeBox aBox(gp_Pnt(0, 0, 0), 100, 100, 100);
486 TopoDS_Shape aTBox = aBox.Shape();
487 aTBox.Orientation(TopAbs_FORWARD);
488
d01cc61d 489 TDF_Label aTestLabel = D->Main();
7fd59977 490
491 TNaming_Builder aBuilder(aTestLabel);
492 aBuilder.Generated(aTBox);
493
494 TopoDS_Shape aTBox1 = aTBox;
495 aTBox1.Orientation(TopAbs_REVERSED);
496 aTestLabel.ForgetAllAttributes();
7fd59977 497
f11b9af4 498 TNaming_Builder aBuilder2(aTestLabel);
499 aBuilder2.Generated( aTBox1);
500
501 aTBox = aBuilder2.NamedShape()->Get();
7fd59977 502 if(aTBox.Orientation() != TopAbs_REVERSED) {
503 di << "1" << "\n";
504 } else {
505 di << "0" << "\n";
506 }
507 return 0;
508}
509
1cd84fee 510void QABugs::Commands_1(Draw_Interpretor& theCommands) {
511 const char *group = "QABugs";
7fd59977 512
513 theCommands.Add ("OCC328", "OCC328 shape mode", __FILE__, OCC328bug, group);
514
515 theCommands.Add ("OCC159", "OCC159 Doc", __FILE__, OCC159bug, group);
516 theCommands.Add ("OCC145", "OCC145 Shape MaxNbr", __FILE__, OCC145bug, group);
517
518 theCommands.Add ("OCC73_SelectionMode", "OCC73_SelectionMode DOC entry [SelectionMode]", __FILE__, OCC73_SelectionMode, group);
519
520 theCommands.Add ("OCC10", "OCC10 Shape MaxNbr", __FILE__, OCC10bug, group);
521
522 theCommands.Add ("OCC74_set", "OCC74_set shape mode; set selection mode", __FILE__, OCC74bug_set, group);
523 theCommands.Add ("OCC74_get", "OCC74_get shape; get selection mode", __FILE__, OCC74bug_get, group);
524
525 theCommands.Add("OCC361", "OCC361 Doc ", __FILE__, OCC361bug, group);
526
527 return;
528}