27a754e25fd6d1a141b77c23eee43a0647f243ef
[occt.git] / src / QABugs / QABugs_9.cxx
1 // Created on: 2002-03-18
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
20
21
22 #include <QABugs.hxx>
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 <gp_Ax2.hxx>
33 #include <gp_Pnt.hxx>
34 #include <Geom_RectangularTrimmedSurface.hxx>
35 #include <BRepBuilderAPI_MakeFace.hxx>
36 #include <GC_MakeTrimmedCone.hxx>
37
38 static Standard_Integer BUC60857 (Draw_Interpretor& di, Standard_Integer /*argc*/,const char ** argv)
39 {
40   gp_Ax2  Cone_Ax;
41   double R1=8, R2=16, H1=20, H2=40, angle;
42   gp_Pnt P0(0,0,0), P1(0,0,20), P2(0,0,45);
43   angle = 2*M_PI;
44
45   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
46   if(aContext.IsNull()) {
47     di << "Use vinit command before " << argv[0] << "\n";
48     return 1;
49   }
50
51   Handle(Geom_RectangularTrimmedSurface) S = GC_MakeTrimmedCone (P1, P2, R1, R2).Value();
52   TopoDS_Shape myshape = BRepBuilderAPI_MakeFace(S, Precision::Confusion()).Shape();
53   DBRep::Set("BUC60857_BLUE",myshape);
54   Handle(AIS_Shape) ais1 = new AIS_Shape(myshape);
55   aContext->Display(ais1);
56   aContext->SetColor(ais1, Quantity_NOC_BLUE1);
57
58   Handle(Geom_RectangularTrimmedSurface) S2 = GC_MakeTrimmedCone (P1, P2, R1, 0).Value();
59   TopoDS_Shape myshape2 = BRepBuilderAPI_MakeFace(S2, Precision::Confusion()).Shape();
60   DBRep::Set("BUC60857_RED",myshape2);
61   Handle(AIS_Shape) ais2 = new AIS_Shape(myshape2);
62   aContext->Display(ais2);
63   aContext->SetColor(ais2, Quantity_NOC_RED);
64
65   Handle(Geom_RectangularTrimmedSurface) S3 = GC_MakeTrimmedCone (P1, P2, R2, R1).Value();
66   TopoDS_Shape myshape3 = BRepBuilderAPI_MakeFace(S3, Precision::Confusion()).Shape();
67   DBRep::Set("BUC60857_GREEN",myshape3);
68   Handle(AIS_Shape) ais3 = new AIS_Shape(myshape3);
69   aContext->Display(ais3);
70   aContext->SetColor(ais3, Quantity_NOC_GREEN);
71
72   return 0;
73 }
74
75 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
76 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
77 #include <SelectMgr_Selection.hxx>
78 #include <StdSelect_BRepOwner.hxx>
79 #include <SelectBasics_SensitiveEntity.hxx>
80 #if ! defined(WNT)
81 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
82 #else
83 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
84 #endif
85
86 static Standard_Integer OCC137 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) 
87 {
88   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
89   if(aContext.IsNull()) {
90     di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
91     return 1;
92   }
93   if ( argc < 2 || argc > 3) {
94     di << "ERROR : Usage : " << argv[0] << " highlight_mode [shape]" << "\n";
95     return 1;
96   }
97   
98   ViewerTest_DoubleMapOfInteractiveAndName aMap ;
99   if(argc != 3) {
100     aMap.Assign(GetMapOfAIS());
101   } else {
102     ViewerTest_DoubleMapOfInteractiveAndName& aMap1 = GetMapOfAIS();
103     TCollection_AsciiString aName(argv[2]);
104     Handle(AIS_InteractiveObject) AISObj;
105     if(!aMap1.IsBound2(aName)) {
106       di << "Use 'vdisplay' before" << "\n";
107       return 1;
108     } else {
109       AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap1.Find2(aName));
110       if(AISObj.IsNull()){
111         di << argv[2] << " : No interactive object" << "\n";
112         return 1;
113       }
114       aMap.Bind(AISObj,aName);
115     }
116   }
117   ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
118   while ( it.More() ) {
119     Handle(AIS_InteractiveObject) AISObj = Handle(AIS_InteractiveObject)::DownCast(it.Key1());
120     AISObj->SetHilightMode(atoi(argv[1]));
121     if(AISObj->HasSelection(4)) {
122       //Handle(SelectMgr_Selection)& aSelection = AISObj->Selection(4);
123       const Handle(SelectMgr_Selection)& aSelection = AISObj->Selection(4);
124       if(!aSelection.IsNull()) {
125         for(aSelection->Init();aSelection->More();aSelection->Next()) {
126           Handle(StdSelect_BRepOwner) aO = Handle(StdSelect_BRepOwner)::DownCast(aSelection->Sensitive()->OwnerId());
127           aO->SetHilightMode(atoi(argv[1]));
128         }
129       }
130     }
131     it.Next();
132   }
133   
134   return 0;
135 }
136
137 static Standard_Integer OCC137_z (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) 
138 {
139   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
140   if(aContext.IsNull()) {
141     di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
142     return 1;
143   }
144   if ( argc != 1 && argc != 2) {
145     di << "ERROR : Usage : " << argv[0] << " [ZDetection_mode]" << "\n";
146     return 1;
147   }
148   aContext->SetZDetection(((argc == 1 || (argc == 2 && atoi(argv[1]) == 1)) ? Standard_True : Standard_False));
149   return 0;
150 }
151
152 void QABugs::Commands_9(Draw_Interpretor& theCommands) {
153   char *group = "QABugs";
154
155   theCommands.Add ("BUC60857", "BUC60857", __FILE__, BUC60857, group);
156   theCommands.Add("OCC137","OCC137 mode [shape]",__FILE__,OCC137,group);
157   theCommands.Add("OCC137_z","OCC137_z [ZDetection_mode]",__FILE__,OCC137_z,group);
158
159   return;
160 }