1 // Created on: 2002-05-21
2 // Created by: QA Admin
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
18 #include <Draw_Interpretor.hxx>
20 #include <DrawTrSurf.hxx>
21 #include <AIS_InteractiveContext.hxx>
22 #include <ViewerTest.hxx>
23 #include <AIS_Shape.hxx>
24 #include <TopoDS_Shape.hxx>
26 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
27 #include <TColStd_ListIteratorOfListOfInteger.hxx>
28 #include <TColStd_MapOfInteger.hxx>
30 #include <TDocStd_Document.hxx>
31 #include <TDocStd_Application.hxx>
32 #include <DDocStd.hxx>
33 #include <TDocStd_Owner.hxx>
34 #include <TDF_Label.hxx>
36 #include <TPrsStd_AISViewer.hxx>
37 #include <TPrsStd_AISPresentation.hxx>
39 #include <Draw_Viewer.hxx>
43 extern Draw_Viewer dout;
45 Standard_IMPORT Draw_Viewer dout;
48 #include <BRep_Builder.hxx>
49 #include <BRepTools.hxx>
50 #include <TopoDS_Wire.hxx>
51 #include <BRepBuilderAPI_MakeFace.hxx>
55 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
57 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
60 static TColStd_MapOfInteger theactivatedmodes(8);
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>
69 static Standard_Integer OCC328bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
71 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
72 if(aContext.IsNull()) {
73 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
78 di << "ERROR : Usage : " << argv[0] << " shape mode" << "\n";
82 Standard_Integer ChoosingMode = -1;
83 if ( strcmp (argv [2], "VERTEX") == 0 ) {
86 if ( strcmp (argv [2], "EDGE") == 0 ) {
89 if ( strcmp (argv [2], "WIRE") == 0 ) {
92 if ( strcmp (argv [2], "FACE") == 0 ) {
95 if ( strcmp (argv [2], "SHELL") == 0 ) {
98 if ( strcmp (argv [2], "SOLID") == 0 ) {
101 if ( strcmp (argv [2], "COMPOUND") == 0 ) {
104 if ( ChoosingMode == -1 ) {
105 di << "ERROR : " << argv[1] << " : vrong value of a mode" << "\n";
109 Standard_Boolean updateviewer = Standard_True;
111 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
113 TCollection_AsciiString aName(argv[1]);
114 Handle(AIS_InteractiveObject) AISObj;
116 if(!aMap.IsBound2(aName)) {
117 di << "Use 'vdisplay' before" << "\n";
120 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
122 di << argv[1] << " : No interactive object" << "\n";
126 if (!aContext->HasOpenedContext()) {
127 aContext->OpenLocalContext();
130 if(!theactivatedmodes.Contains(ChoosingMode)) {
131 aContext->ActivateStandardMode(AIS_Shape::SelectionType(ChoosingMode));
132 theactivatedmodes.Add(ChoosingMode);
134 aContext->Erase(AISObj, updateviewer);
135 aContext->UpdateCurrentViewer();
137 aContext->Display(AISObj, updateviewer);
138 aContext->UpdateCurrentViewer();
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;
151 SelectModeString.Copy("VERTEX");
154 SelectModeString.Copy("EDGE");
157 SelectModeString.Copy("WIRE");
160 SelectModeString.Copy("FACE");
163 SelectModeString.Copy("SHELL");
166 SelectModeString.Copy("SOLID");
169 SelectModeString.Copy("COMPOUND");
172 SelectModeString.Copy("UNKNOWN");
174 di << "SelectMode = " << SelectModeString.ToCString() << "\n";
182 static Standard_Integer OCC159bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
185 di << "ERROR : Usage : " << argv[0] << " Doc" << "\n";
189 Handle(TDocStd_Document) D;
190 if (!DDocStd::GetDocument(argv[1],D)) return 1;
192 Standard_Integer DocRefCount1 = D->GetRefCount();
193 di << "DocRefCount1 = " << DocRefCount1 << "\n";
195 Handle(TDocStd_Owner) Owner;
196 if (!D->Main().Root().FindAttribute(TDocStd_Owner::GetID(),Owner)) return 1;
198 Handle(TDocStd_Document) OwnerD1 = Owner->GetDocument();
199 if (OwnerD1.IsNull()) {
200 di << "DocOwner1 = NULL" << "\n";
202 di << "DocOwner1 = NOTNULL" << "\n";
205 Handle(TDocStd_Application) A;
206 if (!DDocStd::Find(A)) return 1;
209 Handle(Draw_Drawable3D) DD = Draw::Get(argv[1],Standard_False);
210 dout.RemoveDrawable (DD);
212 Handle(TDocStd_Document) OwnerD2 = Owner->GetDocument();
213 if (OwnerD2.IsNull()) {
214 di << "DocOwner2 = NULL" << "\n";
216 di << "DocOwner2 = NOTNULL" << "\n";
219 Standard_Integer DocRefCount2 = D->GetRefCount();
220 di << "DocRefCount2 = " << DocRefCount2 << "\n";
225 static Standard_Integer OCC145bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
228 di << "ERROR : Usage : " << argv[0] << " Shape MaxNbr" << "\n";
232 TCollection_AsciiString aFileName = argv[1];
233 Standard_Integer aMaxNbr = Draw::Atoi(argv[2]);
238 if (!BRepTools::Read(aShape, aFileName.ToCString(), aBld)) {
239 di << "ERROR :Could not read a shape!!!" << "\n";
244 TopoDS_Wire aWire = TopoDS::Wire(aShape);
246 for (i = 1; i <= aMaxNbr; i++) {
247 BRepBuilderAPI_MakeFace aMF(aWire);
249 di << "ERROR : Could not make a face" << "\n";
257 static Standard_Integer OCC73_SelectionMode (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
260 di << "ERROR : Usage : " << argv[0] << " DOC entry [SelectionMode]" << "\n";
264 Handle(TDocStd_Document) D;
265 //cout << "OCC73_SelectionMode 1" << endl;
266 if (!DDocStd::GetDocument(argv[1],D)) return 1;
268 //cout << "OCC73_SelectionMode 2" << endl;
269 if (!DDF::FindLabel(D->GetData(),argv[2],L)) return 1;
271 Handle(TPrsStd_AISViewer) viewer;
272 //cout << "OCC73_SelectionMode 3" << endl;
273 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
275 Handle(TPrsStd_AISPresentation) prs;
276 //cout << "OCC73_SelectionMode 4" << endl;
277 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
279 prs->SetSelectionMode((Standard_Integer)Draw::Atoi(argv[3]));
280 TPrsStd_AISViewer::Update(L);
283 Standard_Integer SelectionMode = prs->SelectionMode();
284 //cout << "SelectionMode = " << SelectionMode << endl;
288 //cout << "OCC73_SelectionMode 5" << endl;
293 static Standard_Integer OCC10bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
295 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
296 if(aContext.IsNull()) {
297 di << "use 'vinit' command before " << argv[0] << "\n";
302 di << "Usage : " << argv[0] << " name plane Length" << "\n";
306 TopoDS_Shape S = DBRep::Get( argv[2] );
308 di << "Shape is empty" << "\n";
312 TCollection_AsciiString name(argv[1]);
313 Standard_Real Length = Draw::Atof(argv[3]);
315 // Construction de l'AIS_PlaneTrihedron
316 Handle(AIS_PlaneTrihedron) theAISPlaneTri;
318 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
320 // on recupere la shape dans la map des objets displayes
321 Handle(AIS_InteractiveObject) aShape =
322 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
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;
330 theAISPlaneTri->SetLength(Length);
332 aContext->Redisplay(theAISPlaneTri, Standard_False);
333 aContext->UpdateCurrentViewer();
336 TopoDS_Face FaceB=TopoDS::Face(S);
338 // Construction du Plane
339 // recuperation des edges des faces.
340 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
342 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
346 // si il y a plusieurs edges
347 if (FaceExpB.More() ) {
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);
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);
363 // Construction du Geom_Plane
364 GC_MakePlane MkPlane(A,B,C);
365 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
367 // on le display & bind
368 theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
370 theAISPlaneTri->SetLength(Length);
372 GetMapOfAIS().Bind ( theAISPlaneTri, name);
373 aContext->Display(theAISPlaneTri );
376 Standard_Real getLength = theAISPlaneTri->GetLength();
377 di << "Length = " << Length << "\n";
378 di << "getLength = " << getLength << "\n";
380 if (getLength == Length) {
381 di << "OCC10: OK" << "\n";
383 di << "OCC10: ERROR" << "\n";
389 static Standard_Integer OCC74bug_set (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
391 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
392 if(aContext.IsNull()) {
393 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
398 di << "ERROR : Usage : " << argv[0] << " shape mode; set selection mode" << "\n";
402 Standard_Boolean updateviewer = Standard_True;
404 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
406 TCollection_AsciiString aName(argv[1]);
407 Handle(AIS_InteractiveObject) AISObj;
409 Standard_Integer SelectMode = Draw::Atoi(argv[2]);
411 if(!aMap.IsBound2(aName)) {
412 di << "Use 'vdisplay' before" << "\n";
415 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
417 di << argv[1] << " : No interactive object" << "\n";
420 AISObj->SetSelectionMode(SelectMode);
421 if (!aContext->HasOpenedContext()) {
422 aContext->OpenLocalContext();
424 aContext->Erase(AISObj, updateviewer);
425 aContext->UpdateCurrentViewer();
426 aContext->Display(AISObj, updateviewer);
427 aContext->UpdateCurrentViewer();
432 static Standard_Integer OCC74bug_get (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
434 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
435 if(aContext.IsNull()) {
436 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
441 di << "ERROR : Usage : " << argv[0] << " shape; get selection mode" << "\n";
445 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
447 TCollection_AsciiString aName(argv[1]);
448 Handle(AIS_InteractiveObject) AISObj;
450 if(!aMap.IsBound2(aName)) {
451 di << "Use 'vdisplay' before" << "\n";
454 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
456 di << argv[1] << " : No interactive object" << "\n";
459 Standard_Integer SelectMode = AISObj->SelectionMode();
460 di << SelectMode << "\n";
466 #include <BRepPrimAPI_MakeBox.hxx>
467 #include <TDF_Data.hxx>
468 #include <TNaming_Builder.hxx>
469 #include <TNaming_NamedShape.hxx>
470 #include <AIS_InteractiveObject.hxx>
472 static Standard_Integer OCC361bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
475 di << "ERROR : Usage : " << a[0] << " Doc" << "\n";
480 Handle(TDocStd_Document) D;
481 if (!DDocStd::GetDocument(a[1],D)) {
486 BRepPrimAPI_MakeBox aBox(gp_Pnt(0, 0, 0), 100, 100, 100);
487 TopoDS_Shape aTBox = aBox.Shape();
488 aTBox.Orientation(TopAbs_FORWARD);
490 TDF_Label aTestLabel = D->Main();
492 TNaming_Builder aBuilder(aTestLabel);
493 aBuilder.Generated(aTBox);
495 TopoDS_Shape aTBox1 = aTBox;
496 aTBox1.Orientation(TopAbs_REVERSED);
497 aTestLabel.ForgetAllAttributes();
499 TNaming_Builder aBuilder2(aTestLabel);
500 aBuilder2.Generated( aTBox1);
502 aTBox = aBuilder2.NamedShape()->Get();
503 if(aTBox.Orientation() != TopAbs_REVERSED) {
511 void QABugs::Commands_1(Draw_Interpretor& theCommands) {
512 const char *group = "QABugs";
514 theCommands.Add ("OCC328", "OCC328 shape mode", __FILE__, OCC328bug, group);
516 theCommands.Add ("OCC159", "OCC159 Doc", __FILE__, OCC159bug, group);
517 theCommands.Add ("OCC145", "OCC145 Shape MaxNbr", __FILE__, OCC145bug, group);
519 theCommands.Add ("OCC73_SelectionMode", "OCC73_SelectionMode DOC entry [SelectionMode]", __FILE__, OCC73_SelectionMode, group);
521 theCommands.Add ("OCC10", "OCC10 Shape MaxNbr", __FILE__, OCC10bug, group);
523 theCommands.Add ("OCC74_set", "OCC74_set shape mode; set selection mode", __FILE__, OCC74bug_set, group);
524 theCommands.Add ("OCC74_get", "OCC74_get shape; get selection mode", __FILE__, OCC74bug_get, group);
526 theCommands.Add("OCC361", "OCC361 Doc ", __FILE__, OCC361bug, group);