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 Standard_DISABLE_DEPRECATION_WARNINGS
70 static Standard_Integer OCC328bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
72 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
73 if(aContext.IsNull()) {
74 di << argv[0] << "ERROR : use 'vinit' command before \n";
79 di << "ERROR : Usage : " << argv[0] << " shape mode\n";
83 Standard_Integer ChoosingMode = -1;
84 if ( strcmp (argv [2], "VERTEX") == 0 ) {
87 if ( strcmp (argv [2], "EDGE") == 0 ) {
90 if ( strcmp (argv [2], "WIRE") == 0 ) {
93 if ( strcmp (argv [2], "FACE") == 0 ) {
96 if ( strcmp (argv [2], "SHELL") == 0 ) {
99 if ( strcmp (argv [2], "SOLID") == 0 ) {
102 if ( strcmp (argv [2], "COMPOUND") == 0 ) {
105 if ( ChoosingMode == -1 ) {
106 di << "ERROR : " << argv[1] << " : vrong value of a mode\n";
110 Standard_Boolean updateviewer = Standard_True;
112 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
114 TCollection_AsciiString aName(argv[1]);
115 Handle(AIS_InteractiveObject) AISObj;
117 if(!aMap.IsBound2(aName)) {
118 di << "Use 'vdisplay' before\n";
121 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
123 di << argv[1] << " : No interactive object\n";
127 if (!aContext->HasOpenedContext()) {
128 aContext->OpenLocalContext();
131 if(!theactivatedmodes.Contains(ChoosingMode)) {
132 aContext->ActivateStandardMode(AIS_Shape::SelectionType(ChoosingMode));
133 theactivatedmodes.Add(ChoosingMode);
135 aContext->Erase(AISObj, updateviewer);
136 aContext->UpdateCurrentViewer();
138 aContext->Display(AISObj, updateviewer);
139 aContext->UpdateCurrentViewer();
141 const TColStd_ListOfInteger& aList = aContext->ActivatedStandardModes();
142 Standard_Integer SelectMode;
143 TCollection_AsciiString SelectModeString;
144 TColStd_ListIteratorOfListOfInteger itr(aList);
145 for (; itr.More(); itr.Next()) {
146 SelectMode = itr.Value();
147 //cout << "SelectMode = " << SelectMode << endl;
152 SelectModeString.Copy("VERTEX");
155 SelectModeString.Copy("EDGE");
158 SelectModeString.Copy("WIRE");
161 SelectModeString.Copy("FACE");
164 SelectModeString.Copy("SHELL");
167 SelectModeString.Copy("SOLID");
170 SelectModeString.Copy("COMPOUND");
173 SelectModeString.Copy("UNKNOWN");
175 di << "SelectMode = " << SelectModeString.ToCString() << "\n";
182 Standard_ENABLE_DEPRECATION_WARNINGS
184 static Standard_Integer OCC159bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
187 di << "ERROR : Usage : " << argv[0] << " Doc\n";
191 Handle(TDocStd_Document) D;
192 if (!DDocStd::GetDocument(argv[1],D)) return 1;
194 Standard_Integer DocRefCount1 = D->GetRefCount();
195 di << "DocRefCount1 = " << DocRefCount1 << "\n";
197 Handle(TDocStd_Owner) Owner;
198 if (!D->Main().Root().FindAttribute(TDocStd_Owner::GetID(),Owner)) return 1;
200 Handle(TDocStd_Document) OwnerD1 = Owner->GetDocument();
201 if (OwnerD1.IsNull()) {
202 di << "DocOwner1 = NULL\n";
204 di << "DocOwner1 = NOTNULL\n";
207 Handle(TDocStd_Application) A = DDocStd::GetApplication();
210 Handle(Draw_Drawable3D) DD = Draw::Get(argv[1],Standard_False);
211 dout.RemoveDrawable (DD);
213 Handle(TDocStd_Document) OwnerD2 = Owner->GetDocument();
214 if (OwnerD2.IsNull()) {
215 di << "DocOwner2 = NULL\n";
217 di << "DocOwner2 = NOTNULL\n";
220 Standard_Integer DocRefCount2 = D->GetRefCount();
221 di << "DocRefCount2 = " << DocRefCount2 << "\n";
226 static Standard_Integer OCC145bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
229 di << "ERROR : Usage : " << argv[0] << " Shape MaxNbr\n";
233 TCollection_AsciiString aFileName = argv[1];
234 Standard_Integer aMaxNbr = Draw::Atoi(argv[2]);
239 if (!BRepTools::Read(aShape, aFileName.ToCString(), aBld)) {
240 di << "ERROR :Could not read a shape!!!\n";
245 TopoDS_Wire aWire = TopoDS::Wire(aShape);
247 for (i = 1; i <= aMaxNbr; i++) {
248 BRepBuilderAPI_MakeFace aMF(aWire);
250 di << "ERROR : Could not make a face\n";
258 static Standard_Integer OCC73_SelectionMode (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
261 di << "ERROR : Usage : " << argv[0] << " DOC entry [SelectionMode]\n";
265 Handle(TDocStd_Document) D;
266 //cout << "OCC73_SelectionMode 1" << endl;
267 if (!DDocStd::GetDocument(argv[1],D)) return 1;
269 //cout << "OCC73_SelectionMode 2" << endl;
270 if (!DDF::FindLabel(D->GetData(),argv[2],L)) return 1;
272 Handle(TPrsStd_AISViewer) viewer;
273 //cout << "OCC73_SelectionMode 3" << endl;
274 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
276 Handle(TPrsStd_AISPresentation) prs;
277 //cout << "OCC73_SelectionMode 4" << endl;
278 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
280 prs->SetSelectionMode((Standard_Integer)Draw::Atoi(argv[3]));
281 TPrsStd_AISViewer::Update(L);
284 Standard_Integer SelectionMode = prs->SelectionMode();
285 //cout << "SelectionMode = " << SelectionMode << endl;
289 //cout << "OCC73_SelectionMode 5" << endl;
294 static Standard_Integer OCC10bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
296 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
297 if(aContext.IsNull()) {
298 di << "use 'vinit' command before " << argv[0] << "\n";
303 di << "Usage : " << argv[0] << " name plane Length\n";
307 TopoDS_Shape S = DBRep::Get( argv[2] );
309 di << "Shape is empty\n";
313 TCollection_AsciiString name(argv[1]);
314 Standard_Real Length = Draw::Atof(argv[3]);
316 // Construction de l'AIS_PlaneTrihedron
317 Handle(AIS_PlaneTrihedron) theAISPlaneTri;
319 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
321 // on recupere la shape dans la map des objets displayes
322 Handle(AIS_InteractiveObject) aShape =
323 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
325 // On verifie que l'AIS InteraciveObject est bien
326 // un AIS_PlaneTrihedron
327 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==4) {
328 // On downcast aShape de AIS_InteractiveObject a AIS_PlaneTrihedron
329 theAISPlaneTri = Handle(AIS_PlaneTrihedron)::DownCast (aShape);
331 theAISPlaneTri->SetLength(Length);
333 aContext->Redisplay(theAISPlaneTri, Standard_False);
334 aContext->UpdateCurrentViewer();
337 TopoDS_Face FaceB=TopoDS::Face(S);
339 // Construction du Plane
340 // recuperation des edges des faces.
341 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
343 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
347 // si il y a plusieurs edges
348 if (FaceExpB.More() ) {
350 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
351 BRepAdaptor_Curve theCurveB(EdgeB);
352 BRepAdaptor_Curve theCurveC(EdgeC);
353 A=theCurveC.Value(0.1);
354 B=theCurveC.Value(0.9);
355 C=theCurveB.Value(0.5);
358 // FaceB a 1 unique edge courbe
359 BRepAdaptor_Curve theCurveB(EdgeB);
360 A=theCurveB.Value(0.1);
361 B=theCurveB.Value(0.9);
362 C=theCurveB.Value(0.5);
364 // Construction du Geom_Plane
365 GC_MakePlane MkPlane(A,B,C);
366 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
368 // on le display & bind
369 theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
371 theAISPlaneTri->SetLength(Length);
373 GetMapOfAIS().Bind ( theAISPlaneTri, name);
374 aContext->Display(theAISPlaneTri );
377 Standard_Real getLength = theAISPlaneTri->GetLength();
378 di << "Length = " << Length << "\n";
379 di << "getLength = " << getLength << "\n";
381 if (getLength == Length) {
384 di << "OCC10: ERROR\n";
390 static Standard_Integer OCC74bug_set (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
392 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
393 if(aContext.IsNull()) {
394 di << argv[0] << "ERROR : use 'vinit' command before \n";
399 di << "ERROR : Usage : " << argv[0] << " shape mode; set selection mode\n";
403 Standard_Boolean updateviewer = Standard_True;
405 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
407 TCollection_AsciiString aName(argv[1]);
408 Handle(AIS_InteractiveObject) AISObj;
410 Standard_Integer SelectMode = Draw::Atoi(argv[2]);
412 if(!aMap.IsBound2(aName)) {
413 di << "Use 'vdisplay' before\n";
416 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
418 di << argv[1] << " : No interactive object\n";
421 aContext->Erase(AISObj, updateviewer);
422 aContext->UpdateCurrentViewer();
423 aContext->SetAutoActivateSelection (Standard_False);
424 aContext->Display(AISObj, updateviewer);
425 aContext->Activate (AISObj, SelectMode);
426 aContext->UpdateCurrentViewer();
431 static Standard_Integer OCC74bug_get (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
433 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
434 if(aContext.IsNull()) {
435 di << argv[0] << "ERROR : use 'vinit' command before \n";
440 di << "ERROR : Usage : " << argv[0] << " shape; get selection mode\n";
444 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
446 TCollection_AsciiString aName(argv[1]);
447 Handle(AIS_InteractiveObject) AISObj;
449 if(!aMap.IsBound2(aName)) {
450 di << "Use 'vdisplay' before\n";
453 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
455 di << argv[1] << " : No interactive object\n";
458 TColStd_ListOfInteger anActivatedModes;
459 aContext->ActivatedModes (AISObj, anActivatedModes);
460 Standard_Integer aMode = anActivatedModes.IsEmpty() ? -1 : anActivatedModes.Last();
467 #include <BRepPrimAPI_MakeBox.hxx>
468 #include <TDF_Data.hxx>
469 #include <TNaming_Builder.hxx>
470 #include <TNaming_NamedShape.hxx>
471 #include <AIS_InteractiveObject.hxx>
473 static Standard_Integer OCC361bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
476 di << "ERROR : Usage : " << a[0] << " Doc\n";
481 Handle(TDocStd_Document) D;
482 if (!DDocStd::GetDocument(a[1],D)) {
487 BRepPrimAPI_MakeBox aBox(gp_Pnt(0, 0, 0), 100, 100, 100);
488 TopoDS_Shape aTBox = aBox.Shape();
489 aTBox.Orientation(TopAbs_FORWARD);
491 TDF_Label aTestLabel = D->Main();
493 TNaming_Builder aBuilder(aTestLabel);
494 aBuilder.Generated(aTBox);
496 TopoDS_Shape aTBox1 = aTBox;
497 aTBox1.Orientation(TopAbs_REVERSED);
498 aTestLabel.ForgetAllAttributes();
500 TNaming_Builder aBuilder2(aTestLabel);
501 aBuilder2.Generated( aTBox1);
503 aTBox = aBuilder2.NamedShape()->Get();
504 if(aTBox.Orientation() != TopAbs_REVERSED) {
512 void QABugs::Commands_1(Draw_Interpretor& theCommands) {
513 const char *group = "QABugs";
515 theCommands.Add ("OCC328", "OCC328 shape mode", __FILE__, OCC328bug, group);
517 theCommands.Add ("OCC159", "OCC159 Doc", __FILE__, OCC159bug, group);
518 theCommands.Add ("OCC145", "OCC145 Shape MaxNbr", __FILE__, OCC145bug, group);
520 theCommands.Add ("OCC73_SelectionMode", "OCC73_SelectionMode DOC entry [SelectionMode]", __FILE__, OCC73_SelectionMode, group);
522 theCommands.Add ("OCC10", "OCC10 Shape MaxNbr", __FILE__, OCC10bug, group);
524 theCommands.Add ("OCC74_set", "OCC74_set shape mode; set selection mode", __FILE__, OCC74bug_set, group);
525 theCommands.Add ("OCC74_get", "OCC74_get shape; get selection mode", __FILE__, OCC74bug_get, group);
527 theCommands.Add("OCC361", "OCC361 Doc ", __FILE__, OCC361bug, group);