0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / QABugs / QABugs_9.cxx
CommitLineData
b311480e 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
1cd84fee 20#include <QABugs.hxx>
7fd59977 21
91322f44 22#include <Draw.hxx>
7fd59977 23#include <Draw_Interpretor.hxx>
24#include <DBRep.hxx>
25#include <DrawTrSurf.hxx>
26#include <AIS_InteractiveContext.hxx>
27#include <ViewerTest.hxx>
28#include <AIS_Shape.hxx>
29#include <TopoDS_Shape.hxx>
30
31#include <gp_Ax2.hxx>
32#include <gp_Pnt.hxx>
33#include <Geom_RectangularTrimmedSurface.hxx>
34#include <BRepBuilderAPI_MakeFace.hxx>
35#include <GC_MakeTrimmedCone.hxx>
36
37static Standard_Integer BUC60857 (Draw_Interpretor& di, Standard_Integer /*argc*/,const char ** argv)
38{
39 gp_Ax2 Cone_Ax;
302f96fb 40 double R1=8, R2=16, angle;
7fd59977 41 gp_Pnt P0(0,0,0), P1(0,0,20), P2(0,0,45);
c6541a0c 42 angle = 2*M_PI;
7fd59977 43
44 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
45 if(aContext.IsNull()) {
46 di << "Use vinit command before " << argv[0] << "\n";
47 return 1;
48 }
49
50 Handle(Geom_RectangularTrimmedSurface) S = GC_MakeTrimmedCone (P1, P2, R1, R2).Value();
1c72dff6 51 TopoDS_Shape myshape = BRepBuilderAPI_MakeFace(S, Precision::Confusion()).Shape();
7fd59977 52 DBRep::Set("BUC60857_BLUE",myshape);
53 Handle(AIS_Shape) ais1 = new AIS_Shape(myshape);
54 aContext->Display(ais1);
55 aContext->SetColor(ais1, Quantity_NOC_BLUE1);
56
57 Handle(Geom_RectangularTrimmedSurface) S2 = GC_MakeTrimmedCone (P1, P2, R1, 0).Value();
1c72dff6 58 TopoDS_Shape myshape2 = BRepBuilderAPI_MakeFace(S2, Precision::Confusion()).Shape();
7fd59977 59 DBRep::Set("BUC60857_RED",myshape2);
60 Handle(AIS_Shape) ais2 = new AIS_Shape(myshape2);
61 aContext->Display(ais2);
62 aContext->SetColor(ais2, Quantity_NOC_RED);
63
64 Handle(Geom_RectangularTrimmedSurface) S3 = GC_MakeTrimmedCone (P1, P2, R2, R1).Value();
1c72dff6 65 TopoDS_Shape myshape3 = BRepBuilderAPI_MakeFace(S3, Precision::Confusion()).Shape();
7fd59977 66 DBRep::Set("BUC60857_GREEN",myshape3);
67 Handle(AIS_Shape) ais3 = new AIS_Shape(myshape3);
68 aContext->Display(ais3);
69 aContext->SetColor(ais3, Quantity_NOC_GREEN);
70
71 return 0;
72}
73
74#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
75#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
76#include <SelectMgr_Selection.hxx>
77#include <StdSelect_BRepOwner.hxx>
78#include <SelectBasics_SensitiveEntity.hxx>
79#if ! defined(WNT)
80extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
81#else
82Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
83#endif
84
85static Standard_Integer OCC137 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
86{
87 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
88 if(aContext.IsNull()) {
89 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
90 return 1;
91 }
92 if ( argc < 2 || argc > 3) {
93 di << "ERROR : Usage : " << argv[0] << " highlight_mode [shape]" << "\n";
94 return 1;
95 }
96
97 ViewerTest_DoubleMapOfInteractiveAndName aMap ;
98 if(argc != 3) {
99 aMap.Assign(GetMapOfAIS());
100 } else {
101 ViewerTest_DoubleMapOfInteractiveAndName& aMap1 = GetMapOfAIS();
102 TCollection_AsciiString aName(argv[2]);
103 Handle(AIS_InteractiveObject) AISObj;
104 if(!aMap1.IsBound2(aName)) {
105 di << "Use 'vdisplay' before" << "\n";
106 return 1;
107 } else {
108 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap1.Find2(aName));
109 if(AISObj.IsNull()){
110 di << argv[2] << " : No interactive object" << "\n";
111 return 1;
112 }
113 aMap.Bind(AISObj,aName);
114 }
115 }
116 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
117 while ( it.More() ) {
118 Handle(AIS_InteractiveObject) AISObj = Handle(AIS_InteractiveObject)::DownCast(it.Key1());
91322f44 119 AISObj->SetHilightMode(Draw::Atoi(argv[1]));
7fd59977 120 if(AISObj->HasSelection(4)) {
121 //Handle(SelectMgr_Selection)& aSelection = AISObj->Selection(4);
122 const Handle(SelectMgr_Selection)& aSelection = AISObj->Selection(4);
123 if(!aSelection.IsNull()) {
124 for(aSelection->Init();aSelection->More();aSelection->Next()) {
125 Handle(StdSelect_BRepOwner) aO = Handle(StdSelect_BRepOwner)::DownCast(aSelection->Sensitive()->OwnerId());
91322f44 126 aO->SetHilightMode(Draw::Atoi(argv[1]));
7fd59977 127 }
128 }
129 }
130 it.Next();
131 }
132
133 return 0;
134}
135
136static Standard_Integer OCC137_z (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
137{
138 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
139 if(aContext.IsNull()) {
140 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
141 return 1;
142 }
143 if ( argc != 1 && argc != 2) {
144 di << "ERROR : Usage : " << argv[0] << " [ZDetection_mode]" << "\n";
145 return 1;
146 }
91322f44 147 aContext->SetZDetection(((argc == 1 || (argc == 2 && Draw::Atoi(argv[1]) == 1)) ? Standard_True : Standard_False));
7fd59977 148 return 0;
149}
150
74f5f8df 151#include <GccEnt_Position.hxx>
152#include <Geom2dGcc_QualifiedCurve.hxx>
153#include <Geom2dGcc_Circ2d2TanRad.hxx>
154#include <gp_Elips2d.hxx>
155#include <Geom2d_Ellipse.hxx>
156#include <Geom2d_Circle.hxx>
157
158static Standard_Integer OCC24303(Draw_Interpretor& di, Standard_Integer n, const char** a)
159{
160 if(n < 2)
161 return 1;
162
163 const Standard_Integer SolID = Draw::Atoi(a[1]);
164
165 //Ellipses
166 Standard_Real majorRadius = 2.0;
167 Standard_Real minorRadius = 1.0;
168 gp_Pnt2d p0(gp::Origin2d());
169 gp_Pnt2d p1(4.0,0.0);
170
171 gp_Elips2d ellipse1 = gp_Elips2d( gp_Ax2d(p0,gp::DX2d()),majorRadius, minorRadius,true);
172 gp_Elips2d ellipse2 = gp_Elips2d( gp_Ax2d(p1,gp::DX2d()),majorRadius, minorRadius,true);
173
174 Handle_Geom2d_Curve curve1 = new Geom2d_Ellipse(ellipse1);
175 Handle_Geom2d_Curve curve2 = new Geom2d_Ellipse(ellipse2);
176 DrawTrSurf::Set("c1", curve1);
177 DrawTrSurf::Set("c2", curve2);
178 //Expected tangent
179 gp_Pnt2d centre(5.0,0.0);
180 Standard_Real radius = 3.0;
181 gp_Circ2d theorical_tangent = gp_Circ2d(gp_Ax2d(centre,gp::DX2d()),radius);
182
183 //Calculate the tangent with Geom2dGcc_Circ2dTanRan
184
185 const Geom2dAdaptor_Curve AdaptedCurve1 ( curve1 );
186 const Geom2dAdaptor_Curve AdaptedCurve2 ( curve2 );
187
188 GccEnt_Position curveQualif1 = GccEnt_unqualified;
189 GccEnt_Position curveQualif2 = GccEnt_unqualified;
190
191 const Geom2dGcc_QualifiedCurve qualifiedCurve1 ( AdaptedCurve1, curveQualif1 );
192 const Geom2dGcc_QualifiedCurve qualifiedCurve2 ( AdaptedCurve2, curveQualif2 );
193
194 const Geom2dGcc_Circ2d2TanRad circCalc(qualifiedCurve1,qualifiedCurve2,radius,/*Precision::Approximation()*/ 1.0e-9);
195
196 const Standard_Integer aNbSol = circCalc.NbSolutions();
197 di << "Solutions " << aNbSol << "\n";
198
199 if((SolID < 1) || (SolID > aNbSol))
200 {
201 di << "Wrong SolID value\n";
202 return 1;
203 }
204
205 gp_Circ2d calculated_tangent = circCalc.ThisSolution(SolID);
206
207 char Buf[10];
208 for (Standard_Integer i = 1; i <= aNbSol; i++)
209 {
210 gp_Circ2d ct = circCalc.ThisSolution(i);
211 Handle (Geom2d_Circle) GSol = new Geom2d_Circle(ct);
212 Sprintf(Buf, "Sol%d",i);
213 DrawTrSurf::Set(Buf, GSol);
214 }
215
216 //This distance is different in OC 6.5.4 and OC 6.6.0
217 Standard_Real dist = theorical_tangent.Location().Distance(calculated_tangent.Location());
218 di << "Distance = " << dist << "\n";
219
220 return 0;
221}
222
1cd84fee 223void QABugs::Commands_9(Draw_Interpretor& theCommands) {
1365140b 224 const char *group = "QABugs";
7fd59977 225
226 theCommands.Add ("BUC60857", "BUC60857", __FILE__, BUC60857, group);
227 theCommands.Add("OCC137","OCC137 mode [shape]",__FILE__,OCC137,group);
228 theCommands.Add("OCC137_z","OCC137_z [ZDetection_mode]",__FILE__,OCC137_z,group);
74f5f8df 229 theCommands.Add("OCC24303", "OCC24303 SolID ", __FILE__, OCC24303,group);
7fd59977 230
231 return;
232}