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