0029974: Visualization - OpenGl_Layer::Render() produces inconsistent state of Polygo...
[occt.git] / src / QABugs / QABugs_1.cxx
CommitLineData
b311480e 1// Created on: 2002-05-21
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.
7fd59977 15
1cd84fee 16#include <QABugs.hxx>
7fd59977 17
18#include <Draw_Interpretor.hxx>
19#include <DBRep.hxx>
20#include <DrawTrSurf.hxx>
21#include <AIS_InteractiveContext.hxx>
22#include <ViewerTest.hxx>
23#include <AIS_Shape.hxx>
24#include <TopoDS_Shape.hxx>
25
26#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
27#include <TColStd_ListIteratorOfListOfInteger.hxx>
28#include <TColStd_MapOfInteger.hxx>
29
30#include <TDocStd_Document.hxx>
31#include <TDocStd_Application.hxx>
32#include <DDocStd.hxx>
33#include <TDocStd_Owner.hxx>
34#include <TDF_Label.hxx>
35#include <DDF.hxx>
36#include <TPrsStd_AISViewer.hxx>
37#include <TPrsStd_AISPresentation.hxx>
38
39#include <Draw_Viewer.hxx>
40#include <Draw.hxx>
41
57c28b61 42#ifndef _WIN32
7fd59977 43extern Draw_Viewer dout;
44#else
45Standard_IMPORT Draw_Viewer dout;
46#endif
47
48#include <BRep_Builder.hxx>
49#include <BRepTools.hxx>
50#include <TopoDS_Wire.hxx>
51#include <BRepBuilderAPI_MakeFace.hxx>
52#include <TopoDS.hxx>
53
57c28b61 54#if ! defined(_WIN32)
7fd59977 55extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
56#else
57Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
58#endif
59
60static TColStd_MapOfInteger theactivatedmodes(8);
61
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>
68
7fd59977 69static Standard_Integer OCC159bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
70{
71 if ( argc != 2) {
586db386 72 di << "ERROR : Usage : " << argv[0] << " Doc\n";
7fd59977 73 return 1;
74 }
75
76 Handle(TDocStd_Document) D;
77 if (!DDocStd::GetDocument(argv[1],D)) return 1;
78
79 Standard_Integer DocRefCount1 = D->GetRefCount();
80 di << "DocRefCount1 = " << DocRefCount1 << "\n";
81
82 Handle(TDocStd_Owner) Owner;
83 if (!D->Main().Root().FindAttribute(TDocStd_Owner::GetID(),Owner)) return 1;
84
85 Handle(TDocStd_Document) OwnerD1 = Owner->GetDocument();
86 if (OwnerD1.IsNull()) {
586db386 87 di << "DocOwner1 = NULL\n";
7fd59977 88 } else {
586db386 89 di << "DocOwner1 = NOTNULL\n";
7fd59977 90 }
91
6fe96f84 92 Handle(TDocStd_Application) A = DDocStd::GetApplication();
7fd59977 93 A->Close(D);
94
95 Handle(Draw_Drawable3D) DD = Draw::Get(argv[1],Standard_False);
96 dout.RemoveDrawable (DD);
97
98 Handle(TDocStd_Document) OwnerD2 = Owner->GetDocument();
99 if (OwnerD2.IsNull()) {
586db386 100 di << "DocOwner2 = NULL\n";
7fd59977 101 } else {
586db386 102 di << "DocOwner2 = NOTNULL\n";
7fd59977 103 }
104
105 Standard_Integer DocRefCount2 = D->GetRefCount();
106 di << "DocRefCount2 = " << DocRefCount2 << "\n";
107
108 return 0;
109}
110
111static Standard_Integer OCC145bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
112{
113 if ( argc != 3) {
586db386 114 di << "ERROR : Usage : " << argv[0] << " Shape MaxNbr\n";
7fd59977 115 return 1;
116 }
117
118 TCollection_AsciiString aFileName = argv[1];
91322f44 119 Standard_Integer aMaxNbr = Draw::Atoi(argv[2]);
7fd59977 120
121 BRep_Builder aBld;
122 TopoDS_Shape aShape;
123
124 if (!BRepTools::Read(aShape, aFileName.ToCString(), aBld)) {
586db386 125 di << "ERROR :Could not read a shape!!!\n";
7fd59977 126 return 1;
127 }
128
129 Standard_Integer i;
130 TopoDS_Wire aWire = TopoDS::Wire(aShape);
131
132 for (i = 1; i <= aMaxNbr; i++) {
133 BRepBuilderAPI_MakeFace aMF(aWire);
134 if (!aMF.IsDone()) {
586db386 135 di << "ERROR : Could not make a face\n";
7fd59977 136 return 1;
137 }
138 }
139
140 return 0;
141}
142
143static Standard_Integer OCC73_SelectionMode (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
144{
145 if ( argc < 3) {
586db386 146 di << "ERROR : Usage : " << argv[0] << " DOC entry [SelectionMode]\n";
7fd59977 147 return 1;
148 }
149
150 Handle(TDocStd_Document) D;
151 //cout << "OCC73_SelectionMode 1" << endl;
152 if (!DDocStd::GetDocument(argv[1],D)) return 1;
153 TDF_Label L;
154 //cout << "OCC73_SelectionMode 2" << endl;
155 if (!DDF::FindLabel(D->GetData(),argv[2],L)) return 1;
156
157 Handle(TPrsStd_AISViewer) viewer;
158 //cout << "OCC73_SelectionMode 3" << endl;
159 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
160
161 Handle(TPrsStd_AISPresentation) prs;
162 //cout << "OCC73_SelectionMode 4" << endl;
163 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
164 if( argc == 4 ) {
91322f44 165 prs->SetSelectionMode((Standard_Integer)Draw::Atoi(argv[3]));
7fd59977 166 TPrsStd_AISViewer::Update(L);
167 }
168 else {
169 Standard_Integer SelectionMode = prs->SelectionMode();
170 //cout << "SelectionMode = " << SelectionMode << endl;
171 di<<SelectionMode;
172 }
173 }
174 //cout << "OCC73_SelectionMode 5" << endl;
175
176 return 0;
177}
178
179static Standard_Integer OCC10bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
180{
181 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
182 if(aContext.IsNull()) {
183 di << "use 'vinit' command before " << argv[0] << "\n";
184 return 1;
185 }
186
187 if(argc != 4) {
586db386 188 di << "Usage : " << argv[0] << " name plane Length\n";
7fd59977 189 return 1;
190 }
191
192 TopoDS_Shape S = DBRep::Get( argv[2] );
193 if ( S.IsNull() ) {
586db386 194 di << "Shape is empty\n";
7fd59977 195 return 1;
196 }
197
198 TCollection_AsciiString name(argv[1]);
91322f44 199 Standard_Real Length = Draw::Atof(argv[3]);
7fd59977 200
201 // Construction de l'AIS_PlaneTrihedron
202 Handle(AIS_PlaneTrihedron) theAISPlaneTri;
203
204 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
205 if (IsBound) {
206 // on recupere la shape dans la map des objets displayes
207 Handle(AIS_InteractiveObject) aShape =
208 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
209
210 // On verifie que l'AIS InteraciveObject est bien
211 // un AIS_PlaneTrihedron
212 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==4) {
213 // On downcast aShape de AIS_InteractiveObject a AIS_PlaneTrihedron
c5f3a425 214 theAISPlaneTri = Handle(AIS_PlaneTrihedron)::DownCast (aShape);
7fd59977 215
216 theAISPlaneTri->SetLength(Length);
217
218 aContext->Redisplay(theAISPlaneTri, Standard_False);
219 aContext->UpdateCurrentViewer();
220 }
221 } else {
222 TopoDS_Face FaceB=TopoDS::Face(S);
223
224 // Construction du Plane
225 // recuperation des edges des faces.
226 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
227
228 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
229 // declarations
230 gp_Pnt A,B,C;
231
232 // si il y a plusieurs edges
233 if (FaceExpB.More() ) {
234 FaceExpB.Next();
235 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
236 BRepAdaptor_Curve theCurveB(EdgeB);
237 BRepAdaptor_Curve theCurveC(EdgeC);
238 A=theCurveC.Value(0.1);
239 B=theCurveC.Value(0.9);
240 C=theCurveB.Value(0.5);
241 }
242 else {
243 // FaceB a 1 unique edge courbe
244 BRepAdaptor_Curve theCurveB(EdgeB);
245 A=theCurveB.Value(0.1);
246 B=theCurveB.Value(0.9);
247 C=theCurveB.Value(0.5);
248 }
249 // Construction du Geom_Plane
250 GC_MakePlane MkPlane(A,B,C);
251 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
252
253 // on le display & bind
254 theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
255
256 theAISPlaneTri->SetLength(Length);
257
258 GetMapOfAIS().Bind ( theAISPlaneTri, name);
0577ae8c 259 aContext->Display (theAISPlaneTri, Standard_True);
7fd59977 260 }
261
262 Standard_Real getLength = theAISPlaneTri->GetLength();
263 di << "Length = " << Length << "\n";
264 di << "getLength = " << getLength << "\n";
265
266 if (getLength == Length) {
586db386 267 di << "OCC10: OK\n";
7fd59977 268 } else {
586db386 269 di << "OCC10: ERROR\n";
7fd59977 270 }
271
272 return 0;
273}
274
275static Standard_Integer OCC74bug_set (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
276{
277 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
278 if(aContext.IsNull()) {
586db386 279 di << argv[0] << "ERROR : use 'vinit' command before \n";
7fd59977 280 return 1;
281 }
282
283 if ( argc != 3) {
586db386 284 di << "ERROR : Usage : " << argv[0] << " shape mode; set selection mode\n";
7fd59977 285 return 1;
286 }
287
eb4320f2 288 Standard_Boolean updateviewer = Standard_True;
7fd59977 289
290 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
291
292 TCollection_AsciiString aName(argv[1]);
293 Handle(AIS_InteractiveObject) AISObj;
294
91322f44 295 Standard_Integer SelectMode = Draw::Atoi(argv[2]);
7fd59977 296
297 if(!aMap.IsBound2(aName)) {
586db386 298 di << "Use 'vdisplay' before\n";
7fd59977 299 return 1;
300 } else {
301 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
302 if(AISObj.IsNull()){
586db386 303 di << argv[1] << " : No interactive object\n";
7fd59977 304 return 1;
7fd59977 305 }
eb4320f2 306 aContext->Erase(AISObj, updateviewer);
7fd59977 307 aContext->UpdateCurrentViewer();
c3282ec1 308 aContext->SetAutoActivateSelection (Standard_False);
7fd59977 309 aContext->Display(AISObj, updateviewer);
c3282ec1 310 aContext->Activate (AISObj, SelectMode);
7fd59977 311 aContext->UpdateCurrentViewer();
312 }
313 return 0;
314}
315
316static Standard_Integer OCC74bug_get (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
317{
318 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
319 if(aContext.IsNull()) {
586db386 320 di << argv[0] << "ERROR : use 'vinit' command before \n";
7fd59977 321 return 1;
322 }
323
324 if ( argc != 2) {
586db386 325 di << "ERROR : Usage : " << argv[0] << " shape; get selection mode\n";
7fd59977 326 return 1;
327 }
7fd59977 328
329 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
330
331 TCollection_AsciiString aName(argv[1]);
332 Handle(AIS_InteractiveObject) AISObj;
333
334 if(!aMap.IsBound2(aName)) {
586db386 335 di << "Use 'vdisplay' before\n";
7fd59977 336 return 1;
337 } else {
338 AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
339 if(AISObj.IsNull()){
586db386 340 di << argv[1] << " : No interactive object\n";
7fd59977 341 return 1;
342 }
c3282ec1 343 TColStd_ListOfInteger anActivatedModes;
344 aContext->ActivatedModes (AISObj, anActivatedModes);
345 Standard_Integer aMode = anActivatedModes.IsEmpty() ? -1 : anActivatedModes.Last();
346 di << aMode << "\n";
7fd59977 347 }
348
349 return 0;
350}
351
352#include <BRepPrimAPI_MakeBox.hxx>
353#include <TDF_Data.hxx>
354#include <TNaming_Builder.hxx>
355#include <TNaming_NamedShape.hxx>
ec357c5c 356#include <AIS_InteractiveObject.hxx>
7fd59977 357
358static Standard_Integer OCC361bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
359{
360 if ( nb != 2) {
586db386 361 di << "ERROR : Usage : " << a[0] << " Doc\n";
362 di << "-1\n";
7fd59977 363 return -1;
364 }
365
366 Handle(TDocStd_Document) D;
367 if (!DDocStd::GetDocument(a[1],D)) {
586db386 368 di << "-2\n";
7fd59977 369 return 1;
370 }
371
372 BRepPrimAPI_MakeBox aBox(gp_Pnt(0, 0, 0), 100, 100, 100);
373 TopoDS_Shape aTBox = aBox.Shape();
374 aTBox.Orientation(TopAbs_FORWARD);
375
d01cc61d 376 TDF_Label aTestLabel = D->Main();
7fd59977 377
378 TNaming_Builder aBuilder(aTestLabel);
379 aBuilder.Generated(aTBox);
380
381 TopoDS_Shape aTBox1 = aTBox;
382 aTBox1.Orientation(TopAbs_REVERSED);
383 aTestLabel.ForgetAllAttributes();
7fd59977 384
f11b9af4 385 TNaming_Builder aBuilder2(aTestLabel);
386 aBuilder2.Generated( aTBox1);
387
388 aTBox = aBuilder2.NamedShape()->Get();
7fd59977 389 if(aTBox.Orientation() != TopAbs_REVERSED) {
586db386 390 di << "1\n";
7fd59977 391 } else {
586db386 392 di << "0\n";
7fd59977 393 }
394 return 0;
395}
396
1cd84fee 397void QABugs::Commands_1(Draw_Interpretor& theCommands) {
398 const char *group = "QABugs";
7fd59977 399
7fd59977 400 theCommands.Add ("OCC159", "OCC159 Doc", __FILE__, OCC159bug, group);
401 theCommands.Add ("OCC145", "OCC145 Shape MaxNbr", __FILE__, OCC145bug, group);
402
403 theCommands.Add ("OCC73_SelectionMode", "OCC73_SelectionMode DOC entry [SelectionMode]", __FILE__, OCC73_SelectionMode, group);
404
405 theCommands.Add ("OCC10", "OCC10 Shape MaxNbr", __FILE__, OCC10bug, group);
406
407 theCommands.Add ("OCC74_set", "OCC74_set shape mode; set selection mode", __FILE__, OCC74bug_set, group);
408 theCommands.Add ("OCC74_get", "OCC74_get shape; get selection mode", __FILE__, OCC74bug_get, group);
409
410 theCommands.Add("OCC361", "OCC361 Doc ", __FILE__, OCC361bug, group);
411
412 return;
413}