0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / QABugs / QABugs_8.cxx
1 // Created on: 2002-03-19
2 // Created by: QA Admin
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <QABugs.hxx>
17
18 #include <Draw.hxx>
19 #include <Draw_Interpretor.hxx>
20 #include <DBRep.hxx>
21 #include <DrawTrSurf.hxx>
22 #include <AIS_InteractiveContext.hxx>
23 #include <ViewerTest.hxx>
24 #include <AIS_Shape.hxx>
25 #include <TopoDS_Shape.hxx>
26
27 #include <TColStd_Array2OfReal.hxx>
28 #include <V3d_View.hxx>
29
30 #include <BRepOffsetAPI_Sewing.hxx>
31
32 #include <AIS_ListOfInteractive.hxx>
33 #include <AIS_ListIteratorOfListOfInteractive.hxx>
34
35 #include <BRepPrimAPI_MakeBox.hxx>
36
37 static Standard_Integer  OCC162 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
38 {
39   if ( argc != 2 ) {
40     di << "Usage : " << argv[0] << " name\n";
41     return 1;
42   }
43
44   TopoDS_Shape aShape = DBRep::Get(argv[1]);
45   if (aShape.IsNull()) return 0;
46
47   Standard_Real tolValue = 0.0001;
48   BRepOffsetAPI_Sewing sew(tolValue);
49   sew.Add(aShape);
50   sew.Perform();
51   TopoDS_Shape aSewed = sew.SewedShape();
52   
53   return 0;     
54 }
55
56 static Standard_Integer  OCC172 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
57 {
58   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
59   if(aContext.IsNull()) { 
60     di << "use 'vinit' command before " << argv[0] << "\n";
61     return 1;
62   }
63   
64   AIS_ListOfInteractive aListOfIO;
65   aContext->DisplayedObjects(aListOfIO);
66   AIS_ListIteratorOfListOfInteractive It;
67   for (It.Initialize(aListOfIO);It.More();It.Next())
68     {
69       aContext->AddOrRemoveSelected (It.Value(), Standard_False);
70     }
71   aContext->UpdateCurrentViewer();
72   return 0;     
73 }
74
75 static Standard_Integer  OCC204 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
76 {
77   if ( argc != 2 ) {
78     di << "Usage : " << argv[0] << " updateviewer=0/1\n";
79     return 1;
80   }
81
82   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
83   if (aContext.IsNull()) { 
84     di << "use 'vinit' command before " << argv[0] << "\n";
85     return 1;
86   }
87   Standard_Boolean UpdateViewer = Standard_True;
88   Standard_Integer IntegerUpdateViewer = Draw::Atoi(argv[1]);
89   if (IntegerUpdateViewer == 0) {
90     UpdateViewer = Standard_False;
91   }
92
93   Standard_Integer deltaY = -500;
94   BRepPrimAPI_MakeBox box1(gp_Pnt(0, 0 + deltaY, 0),  gp_Pnt(100, 100 + deltaY, 100));
95   BRepPrimAPI_MakeBox box2(gp_Pnt(120, 120 + deltaY, 120),  gp_Pnt(300, 300 + deltaY,300));
96   BRepPrimAPI_MakeBox box3(gp_Pnt(320, 320 + deltaY, 320),  gp_Pnt(500, 500 + deltaY,500));
97
98   Handle(AIS_InteractiveObject) ais1 = new AIS_Shape(box1.Shape());
99   Handle(AIS_InteractiveObject) ais2 = new AIS_Shape(box2.Shape());
100   Handle(AIS_InteractiveObject) ais3 = new AIS_Shape(box3.Shape());
101
102   aContext->Display (ais1, Standard_False);
103   aContext->Display (ais2, Standard_False);
104   aContext->Display (ais3, Standard_False);
105
106   aContext->AddOrRemoveSelected (ais1, Standard_False);
107   aContext->AddOrRemoveSelected (ais2, Standard_False);
108   aContext->AddOrRemoveSelected (ais3, Standard_False);
109
110   aContext->UpdateCurrentViewer();
111
112   //printf("\n No of currents = %d", aContext->NbCurrents());
113
114   aContext->InitSelected();
115   
116   //int count = 1;
117   while(aContext->MoreSelected())
118   {
119     //printf("\n count is = %d",  count++);
120     Handle(AIS_InteractiveObject) ais = aContext->SelectedInteractive();
121     aContext->Remove(ais, UpdateViewer);
122     aContext->InitSelected();
123   }
124   
125   return 0;     
126 }
127
128 #include <gp_Lin.hxx>
129 #include <BRepClass3d_Intersector3d.hxx>
130 #include <TopoDS.hxx>
131 static Standard_Integer OCC1651 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
132 {
133   if ( argc != 8 ) {
134     di << "Usage : " << argv[0] << " Shape PntX PntY PntZ DirX DirY DirZ\n";
135     return 1;
136   }
137
138   TopoDS_Shape aShape = DBRep::Get(argv[1]);
139   if (aShape.IsNull()) return 0;
140
141   gp_Pnt aP1(Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]));
142   gp_Dir aD1(Draw::Atof(argv[5]), Draw::Atof(argv[6]), Draw::Atof(argv[7]));
143   gp_Lin aL1(aP1,aD1);
144   BRepClass3d_Intersector3d aI1;
145   aI1.Perform(aL1, -250, 1e-7, TopoDS::Face(aShape));
146   if(aI1.IsDone() && aI1.HasAPoint()) {
147     gp_Pnt aR1 = aI1.Pnt();
148     di << aR1.X() << " " << aR1.Y() << " " << aR1.Z() << "\n";
149   }
150
151   return 0;
152 }
153
154 void QABugs::Commands_8(Draw_Interpretor& theCommands) {
155   const char *group = "QABugs";
156
157   theCommands.Add("OCC162", "OCC162 name", __FILE__, OCC162, group);
158   theCommands.Add("OCC172", "OCC172", __FILE__, OCC172, group);
159   theCommands.Add("OCC204", "OCC204 updateviewer=0/1", __FILE__, OCC204, group);
160   theCommands.Add("OCC1651", "OCC1651 Shape PntX PntY PntZ DirX DirY DirZ", __FILE__, OCC1651, group);
161
162   return;
163 }