0028987: Visualization, SelectMgr_SelectableObject - move out iterator from object
[occt.git] / src / QABugs / QABugs_9.cxx
CommitLineData
b311480e 1// Created on: 2002-03-18
2// Created by: QA Admin
973c2be1 3// Copyright (c) 2002-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
1cd84fee 16#include <QABugs.hxx>
7fd59977 17
91322f44 18#include <Draw.hxx>
7fd59977 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 <gp_Ax2.hxx>
28#include <gp_Pnt.hxx>
29#include <Geom_RectangularTrimmedSurface.hxx>
30#include <BRepBuilderAPI_MakeFace.hxx>
31#include <GC_MakeTrimmedCone.hxx>
32
33static Standard_Integer BUC60857 (Draw_Interpretor& di, Standard_Integer /*argc*/,const char ** argv)
34{
35 gp_Ax2 Cone_Ax;
96a95605 36 double R1=8, R2=16;
7fd59977 37 gp_Pnt P0(0,0,0), P1(0,0,20), P2(0,0,45);
7fd59977 38
39 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
40 if(aContext.IsNull()) {
41 di << "Use vinit command before " << argv[0] << "\n";
42 return 1;
43 }
44
45 Handle(Geom_RectangularTrimmedSurface) S = GC_MakeTrimmedCone (P1, P2, R1, R2).Value();
1c72dff6 46 TopoDS_Shape myshape = BRepBuilderAPI_MakeFace(S, Precision::Confusion()).Shape();
7fd59977 47 DBRep::Set("BUC60857_BLUE",myshape);
48 Handle(AIS_Shape) ais1 = new AIS_Shape(myshape);
0577ae8c 49 aContext->Display (ais1, Standard_False);
50 aContext->SetColor (ais1, Quantity_NOC_BLUE1, Standard_False);
7fd59977 51
52 Handle(Geom_RectangularTrimmedSurface) S2 = GC_MakeTrimmedCone (P1, P2, R1, 0).Value();
1c72dff6 53 TopoDS_Shape myshape2 = BRepBuilderAPI_MakeFace(S2, Precision::Confusion()).Shape();
7fd59977 54 DBRep::Set("BUC60857_RED",myshape2);
55 Handle(AIS_Shape) ais2 = new AIS_Shape(myshape2);
0577ae8c 56 aContext->Display (ais2, Standard_False);
57 aContext->SetColor (ais2, Quantity_NOC_RED, Standard_False);
7fd59977 58
59 Handle(Geom_RectangularTrimmedSurface) S3 = GC_MakeTrimmedCone (P1, P2, R2, R1).Value();
1c72dff6 60 TopoDS_Shape myshape3 = BRepBuilderAPI_MakeFace(S3, Precision::Confusion()).Shape();
7fd59977 61 DBRep::Set("BUC60857_GREEN",myshape3);
62 Handle(AIS_Shape) ais3 = new AIS_Shape(myshape3);
0577ae8c 63 aContext->Display (ais3, Standard_False);
64 aContext->SetColor (ais3, Quantity_NOC_GREEN, Standard_True);
7fd59977 65
66 return 0;
67}
68
69#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
70#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
71#include <SelectMgr_Selection.hxx>
72#include <StdSelect_BRepOwner.hxx>
73#include <SelectBasics_SensitiveEntity.hxx>
57c28b61 74#if ! defined(_WIN32)
7fd59977 75extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
76#else
77Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
78#endif
79
80static Standard_Integer OCC137 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
81{
82 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
83 if(aContext.IsNull()) {
586db386 84 di << argv[0] << "ERROR : use 'vinit' command before \n";
7fd59977 85 return 1;
86 }
87 if ( argc < 2 || argc > 3) {
586db386 88 di << "ERROR : Usage : " << argv[0] << " highlight_mode [shape]\n";
7fd59977 89 return 1;
90 }
91
92 ViewerTest_DoubleMapOfInteractiveAndName aMap ;
93 if(argc != 3) {
94 aMap.Assign(GetMapOfAIS());
95 } else {
96 ViewerTest_DoubleMapOfInteractiveAndName& aMap1 = GetMapOfAIS();
97 TCollection_AsciiString aName(argv[2]);
98 Handle(AIS_InteractiveObject) AISObj;
99 if(!aMap1.IsBound2(aName)) {
586db386 100 di << "Use 'vdisplay' before\n";
7fd59977 101 return 1;
102 } else {
103 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap1.Find2(aName));
104 if(AISObj.IsNull()){
586db386 105 di << argv[2] << " : No interactive object\n";
7fd59977 106 return 1;
107 }
108 aMap.Bind(AISObj,aName);
109 }
110 }
111 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
112 while ( it.More() ) {
113 Handle(AIS_InteractiveObject) AISObj = Handle(AIS_InteractiveObject)::DownCast(it.Key1());
91322f44 114 AISObj->SetHilightMode(Draw::Atoi(argv[1]));
7fd59977 115 if(AISObj->HasSelection(4)) {
116 //Handle(SelectMgr_Selection)& aSelection = AISObj->Selection(4);
117 const Handle(SelectMgr_Selection)& aSelection = AISObj->Selection(4);
b5cce1ab 118 if(!aSelection.IsNull())
119 {
120 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSelection->Entities()); aSelEntIter.More(); aSelEntIter.Next())
121 {
122 Handle(StdSelect_BRepOwner) aO = Handle(StdSelect_BRepOwner)::DownCast(aSelEntIter.Value()->BaseSensitive()->OwnerId());
91322f44 123 aO->SetHilightMode(Draw::Atoi(argv[1]));
7fd59977 124 }
125 }
126 }
127 it.Next();
128 }
129
130 return 0;
131}
132
74f5f8df 133#include <GccEnt_Position.hxx>
134#include <Geom2dGcc_QualifiedCurve.hxx>
135#include <Geom2dGcc_Circ2d2TanRad.hxx>
136#include <gp_Elips2d.hxx>
137#include <Geom2d_Ellipse.hxx>
138#include <Geom2d_Circle.hxx>
ec357c5c 139#include <AIS_InteractiveObject.hxx>
74f5f8df 140
141static Standard_Integer OCC24303(Draw_Interpretor& di, Standard_Integer n, const char** a)
142{
143 if(n < 2)
144 return 1;
145
146 const Standard_Integer SolID = Draw::Atoi(a[1]);
147
148 //Ellipses
149 Standard_Real majorRadius = 2.0;
150 Standard_Real minorRadius = 1.0;
151 gp_Pnt2d p0(gp::Origin2d());
152 gp_Pnt2d p1(4.0,0.0);
153
154 gp_Elips2d ellipse1 = gp_Elips2d( gp_Ax2d(p0,gp::DX2d()),majorRadius, minorRadius,true);
155 gp_Elips2d ellipse2 = gp_Elips2d( gp_Ax2d(p1,gp::DX2d()),majorRadius, minorRadius,true);
156
857ffd5e 157 Handle(Geom2d_Curve) curve1 = new Geom2d_Ellipse(ellipse1);
158 Handle(Geom2d_Curve) curve2 = new Geom2d_Ellipse(ellipse2);
74f5f8df 159 DrawTrSurf::Set("c1", curve1);
160 DrawTrSurf::Set("c2", curve2);
161 //Expected tangent
162 gp_Pnt2d centre(5.0,0.0);
163 Standard_Real radius = 3.0;
164 gp_Circ2d theorical_tangent = gp_Circ2d(gp_Ax2d(centre,gp::DX2d()),radius);
165
166 //Calculate the tangent with Geom2dGcc_Circ2dTanRan
167
168 const Geom2dAdaptor_Curve AdaptedCurve1 ( curve1 );
169 const Geom2dAdaptor_Curve AdaptedCurve2 ( curve2 );
170
171 GccEnt_Position curveQualif1 = GccEnt_unqualified;
172 GccEnt_Position curveQualif2 = GccEnt_unqualified;
173
174 const Geom2dGcc_QualifiedCurve qualifiedCurve1 ( AdaptedCurve1, curveQualif1 );
175 const Geom2dGcc_QualifiedCurve qualifiedCurve2 ( AdaptedCurve2, curveQualif2 );
176
177 const Geom2dGcc_Circ2d2TanRad circCalc(qualifiedCurve1,qualifiedCurve2,radius,/*Precision::Approximation()*/ 1.0e-9);
178
179 const Standard_Integer aNbSol = circCalc.NbSolutions();
180 di << "Solutions " << aNbSol << "\n";
181
182 if((SolID < 1) || (SolID > aNbSol))
183 {
184 di << "Wrong SolID value\n";
185 return 1;
186 }
187
188 gp_Circ2d calculated_tangent = circCalc.ThisSolution(SolID);
189
190 char Buf[10];
191 for (Standard_Integer i = 1; i <= aNbSol; i++)
192 {
193 gp_Circ2d ct = circCalc.ThisSolution(i);
194 Handle (Geom2d_Circle) GSol = new Geom2d_Circle(ct);
195 Sprintf(Buf, "Sol%d",i);
196 DrawTrSurf::Set(Buf, GSol);
197 }
198
199 //This distance is different in OC 6.5.4 and OC 6.6.0
200 Standard_Real dist = theorical_tangent.Location().Distance(calculated_tangent.Location());
201 di << "Distance = " << dist << "\n";
202
203 return 0;
204}
205
1cd84fee 206void QABugs::Commands_9(Draw_Interpretor& theCommands) {
1365140b 207 const char *group = "QABugs";
7fd59977 208
209 theCommands.Add ("BUC60857", "BUC60857", __FILE__, BUC60857, group);
210 theCommands.Add("OCC137","OCC137 mode [shape]",__FILE__,OCC137,group);
74f5f8df 211 theCommands.Add("OCC24303", "OCC24303 SolID ", __FILE__, OCC24303,group);
7fd59977 212
213 return;
214}