0031075: Application Framework - reading STEP file into TDocStd_Document leads to...
[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
7fd59977 60#include <AIS_PlaneTrihedron.hxx>
61#include <TopoDS_Face.hxx>
62#include <TopExp_Explorer.hxx>
63#include <TopoDS_Edge.hxx>
64#include <BRepAdaptor_Curve.hxx>
65#include <GC_MakePlane.hxx>
66
7fd59977 67static Standard_Integer OCC159bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
68{
69 if ( argc != 2) {
586db386 70 di << "ERROR : Usage : " << argv[0] << " Doc\n";
7fd59977 71 return 1;
72 }
73
74 Handle(TDocStd_Document) D;
75 if (!DDocStd::GetDocument(argv[1],D)) return 1;
76
77 Standard_Integer DocRefCount1 = D->GetRefCount();
78 di << "DocRefCount1 = " << DocRefCount1 << "\n";
79
80 Handle(TDocStd_Owner) Owner;
81 if (!D->Main().Root().FindAttribute(TDocStd_Owner::GetID(),Owner)) return 1;
82
83 Handle(TDocStd_Document) OwnerD1 = Owner->GetDocument();
84 if (OwnerD1.IsNull()) {
586db386 85 di << "DocOwner1 = NULL\n";
7fd59977 86 } else {
586db386 87 di << "DocOwner1 = NOTNULL\n";
7fd59977 88 }
ef779ae0 89 OwnerD1.Nullify();
7fd59977 90
6fe96f84 91 Handle(TDocStd_Application) A = DDocStd::GetApplication();
7fd59977 92 A->Close(D);
93
1c8fc6be 94 if (Handle(Draw_Drawable3D) DD = Draw::GetExisting (argv[1]))
95 {
96 dout.RemoveDrawable (DD);
97 }
7fd59977 98
99 Handle(TDocStd_Document) OwnerD2 = Owner->GetDocument();
100 if (OwnerD2.IsNull()) {
586db386 101 di << "DocOwner2 = NULL\n";
7fd59977 102 } else {
586db386 103 di << "DocOwner2 = NOTNULL\n";
7fd59977 104 }
105
106 Standard_Integer DocRefCount2 = D->GetRefCount();
107 di << "DocRefCount2 = " << DocRefCount2 << "\n";
108
109 return 0;
110}
111
112static Standard_Integer OCC145bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
113{
114 if ( argc != 3) {
586db386 115 di << "ERROR : Usage : " << argv[0] << " Shape MaxNbr\n";
7fd59977 116 return 1;
117 }
118
119 TCollection_AsciiString aFileName = argv[1];
91322f44 120 Standard_Integer aMaxNbr = Draw::Atoi(argv[2]);
7fd59977 121
122 BRep_Builder aBld;
123 TopoDS_Shape aShape;
124
125 if (!BRepTools::Read(aShape, aFileName.ToCString(), aBld)) {
586db386 126 di << "ERROR :Could not read a shape!!!\n";
7fd59977 127 return 1;
128 }
129
130 Standard_Integer i;
131 TopoDS_Wire aWire = TopoDS::Wire(aShape);
132
133 for (i = 1; i <= aMaxNbr; i++) {
134 BRepBuilderAPI_MakeFace aMF(aWire);
135 if (!aMF.IsDone()) {
586db386 136 di << "ERROR : Could not make a face\n";
7fd59977 137 return 1;
138 }
139 }
140
141 return 0;
142}
143
144static Standard_Integer OCC73_SelectionMode (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
145{
146 if ( argc < 3) {
586db386 147 di << "ERROR : Usage : " << argv[0] << " DOC entry [SelectionMode]\n";
7fd59977 148 return 1;
149 }
150
151 Handle(TDocStd_Document) D;
04232180 152 //std::cout << "OCC73_SelectionMode 1" << std::endl;
7fd59977 153 if (!DDocStd::GetDocument(argv[1],D)) return 1;
154 TDF_Label L;
04232180 155 //std::cout << "OCC73_SelectionMode 2" << std::endl;
7fd59977 156 if (!DDF::FindLabel(D->GetData(),argv[2],L)) return 1;
157
158 Handle(TPrsStd_AISViewer) viewer;
04232180 159 //std::cout << "OCC73_SelectionMode 3" << std::endl;
7fd59977 160 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
161
162 Handle(TPrsStd_AISPresentation) prs;
04232180 163 //std::cout << "OCC73_SelectionMode 4" << std::endl;
7fd59977 164 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
165 if( argc == 4 ) {
91322f44 166 prs->SetSelectionMode((Standard_Integer)Draw::Atoi(argv[3]));
7fd59977 167 TPrsStd_AISViewer::Update(L);
168 }
169 else {
170 Standard_Integer SelectionMode = prs->SelectionMode();
04232180 171 //std::cout << "SelectionMode = " << SelectionMode << std::endl;
7fd59977 172 di<<SelectionMode;
173 }
174 }
04232180 175 //std::cout << "OCC73_SelectionMode 5" << std::endl;
7fd59977 176
177 return 0;
178}
179
180static Standard_Integer OCC10bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
181{
182 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
183 if(aContext.IsNull()) {
184 di << "use 'vinit' command before " << argv[0] << "\n";
185 return 1;
186 }
187
188 if(argc != 4) {
586db386 189 di << "Usage : " << argv[0] << " name plane Length\n";
7fd59977 190 return 1;
191 }
192
193 TopoDS_Shape S = DBRep::Get( argv[2] );
194 if ( S.IsNull() ) {
586db386 195 di << "Shape is empty\n";
7fd59977 196 return 1;
197 }
198
199 TCollection_AsciiString name(argv[1]);
91322f44 200 Standard_Real Length = Draw::Atof(argv[3]);
7fd59977 201
202 // Construction de l'AIS_PlaneTrihedron
203 Handle(AIS_PlaneTrihedron) theAISPlaneTri;
204
205 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
206 if (IsBound) {
207 // on recupere la shape dans la map des objets displayes
8f521168 208 Handle(AIS_InteractiveObject) aShape = GetMapOfAIS().Find2(name);
7fd59977 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]);
8f521168 296 if (!aMap.Find2 (aName, AISObj)
297 || AISObj.IsNull())
298 {
586db386 299 di << "Use 'vdisplay' before\n";
7fd59977 300 return 1;
7fd59977 301 }
8f521168 302
303 aContext->Erase(AISObj, updateviewer);
304 aContext->UpdateCurrentViewer();
305 aContext->SetAutoActivateSelection (Standard_False);
306 aContext->Display(AISObj, updateviewer);
307 aContext->Activate (AISObj, SelectMode);
308 aContext->UpdateCurrentViewer();
7fd59977 309 return 0;
310}
311
312static Standard_Integer OCC74bug_get (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
313{
314 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
315 if(aContext.IsNull()) {
586db386 316 di << argv[0] << "ERROR : use 'vinit' command before \n";
7fd59977 317 return 1;
318 }
319
320 if ( argc != 2) {
586db386 321 di << "ERROR : Usage : " << argv[0] << " shape; get selection mode\n";
7fd59977 322 return 1;
323 }
7fd59977 324
325 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
326
327 TCollection_AsciiString aName(argv[1]);
328 Handle(AIS_InteractiveObject) AISObj;
8f521168 329 if (!aMap.Find2(aName, AISObj)
330 || AISObj.IsNull())
331 {
586db386 332 di << "Use 'vdisplay' before\n";
7fd59977 333 return 1;
7fd59977 334 }
335
8f521168 336 TColStd_ListOfInteger anActivatedModes;
337 aContext->ActivatedModes (AISObj, anActivatedModes);
338 Standard_Integer aMode = anActivatedModes.IsEmpty() ? -1 : anActivatedModes.Last();
339 di << aMode << "\n";
7fd59977 340 return 0;
341}
342
343#include <BRepPrimAPI_MakeBox.hxx>
344#include <TDF_Data.hxx>
345#include <TNaming_Builder.hxx>
346#include <TNaming_NamedShape.hxx>
ec357c5c 347#include <AIS_InteractiveObject.hxx>
7fd59977 348
349static Standard_Integer OCC361bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
350{
351 if ( nb != 2) {
586db386 352 di << "ERROR : Usage : " << a[0] << " Doc\n";
353 di << "-1\n";
7fd59977 354 return -1;
355 }
356
357 Handle(TDocStd_Document) D;
358 if (!DDocStd::GetDocument(a[1],D)) {
586db386 359 di << "-2\n";
7fd59977 360 return 1;
361 }
362
363 BRepPrimAPI_MakeBox aBox(gp_Pnt(0, 0, 0), 100, 100, 100);
364 TopoDS_Shape aTBox = aBox.Shape();
365 aTBox.Orientation(TopAbs_FORWARD);
366
d01cc61d 367 TDF_Label aTestLabel = D->Main();
7fd59977 368
369 TNaming_Builder aBuilder(aTestLabel);
370 aBuilder.Generated(aTBox);
371
372 TopoDS_Shape aTBox1 = aTBox;
373 aTBox1.Orientation(TopAbs_REVERSED);
374 aTestLabel.ForgetAllAttributes();
7fd59977 375
f11b9af4 376 TNaming_Builder aBuilder2(aTestLabel);
377 aBuilder2.Generated( aTBox1);
378
379 aTBox = aBuilder2.NamedShape()->Get();
7fd59977 380 if(aTBox.Orientation() != TopAbs_REVERSED) {
586db386 381 di << "1\n";
7fd59977 382 } else {
586db386 383 di << "0\n";
7fd59977 384 }
385 return 0;
386}
387
88b12b7c 388#include <Graphic3d_Texture2Dmanual.hxx>
389#include <Image_AlienPixMap.hxx>
390#include <OSD_OpenFile.hxx>
391#include <Prs3d_ShadingAspect.hxx>
392#include <Standard_ArrayStreamBuffer.hxx>
393//=======================================================================
394//function : OCC30182
395//purpose : Testing different interfaces of Image_AlienPixMap::Load()
396//=======================================================================
397static Standard_Integer OCC30182 (Draw_Interpretor& , Standard_Integer theNbArgs, const char** theArgVec)
398{
399 if (ViewerTest::CurrentView().IsNull())
400 {
401 std::cout << "Error: no active view\n";
402 return 1;
403 }
404
405 TCollection_AsciiString aPrsName, anImgPath;
406 Standard_Integer anOffset = 0;
407 Standard_Integer aSrc = 0; // 0 - file name, 1 - file stream, 2 - memory buffer
408 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
409 {
410 TCollection_AsciiString anArg (theArgVec[anArgIter]);
411 anArg.LowerCase();
412 if (anArg == "-offset"
413 && anArgIter + 1 < theNbArgs)
414 {
415 anOffset = Draw::Atoi (theArgVec[++anArgIter]);
416 }
417 else if (anArg == "-filename")
418 {
419 aSrc = 0;
420 }
421 else if (anArg == "-stream")
422 {
423 aSrc = 1;
424 }
425 else if (anArg == "-mem"
426 || anArg == "-memory")
427 {
428 aSrc = 2;
429 }
430 else if (aPrsName.IsEmpty())
431 {
432 aPrsName = theArgVec[anArgIter];
433 }
434 else if (anImgPath.IsEmpty())
435 {
436 anImgPath = theArgVec[anArgIter];
437 }
438 else
439 {
440 std::cout << "Syntax error at '" << anArg << "'\n";
441 return 1;
442 }
443 }
444 if (anImgPath.IsEmpty())
445 {
446 std::cout << "Syntax error: wrong number of arguments\n";
447 return 1;
448 }
449
450 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
451 if (aSrc == 0)
452 {
453 if (!anImage->Load (anImgPath))
454 {
455 return 0;
456 }
457 }
458 else
459 {
460 std::ifstream aFile;
461 OSD_OpenStream (aFile, anImgPath.ToCString(), std::ios::in | std::ios::binary);
462 if (!aFile.is_open())
463 {
464 std::cout << "Syntax error: image file '" << anImgPath << "' cannot be found\n";
465 return 1;
466 }
467 if (anOffset != 0)
468 {
469 aFile.seekg (anOffset);
470 }
471
472 if (aSrc == 2)
473 {
474 aFile.seekg (0, std::ios::end);
475 Standard_Integer aLen = (Standard_Integer )aFile.tellg() - anOffset;
476 aFile.seekg (anOffset);
477 if (aLen <= 0)
478 {
479 std::cout << "Syntax error: wrong offset\n";
480 return 1;
481 }
482 NCollection_Array1<Standard_Byte> aBuff (1, aLen);
483 if (!aFile.read ((char* )&aBuff.ChangeFirst(), aBuff.Size()))
484 {
485 std::cout << "Error: unable to read file\n";
486 return 1;
487 }
488 aFile.close();
489 if (!anImage->Load (&aBuff.ChangeFirst(), aBuff.Size(), anImgPath))
490 {
491 return 0;
492 }
493 }
494 else
495 {
496 if (!anImage->Load (aFile, anImgPath))
497 {
498 return 0;
499 }
500 }
501 }
502
503 TopoDS_Shape aShape = BRepPrimAPI_MakeBox (100.0 * anImage->Ratio(), 100.0, 1.0).Shape();
504 Handle(AIS_Shape) aPrs = new AIS_Shape (aShape);
505 aPrs->SetDisplayMode (AIS_Shaded);
506 aPrs->Attributes()->SetupOwnShadingAspect();
507 const Handle(Graphic3d_AspectFillArea3d)& anAspect = aPrs->Attributes()->ShadingAspect()->Aspect();
508 anAspect->SetShadingModel (Graphic3d_TOSM_UNLIT);
509 anAspect->SetTextureMapOn (true);
510 anAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (anImage));
511 if (anImage->IsTopDown())
512 {
513 anAspect->TextureMap()->GetParams()->SetTranslation(Graphic3d_Vec2 (0.0f, -1.0f));
514 anAspect->TextureMap()->GetParams()->SetScale (Graphic3d_Vec2 (1.0f, -1.0f));
515 }
516
517 ViewerTest::Display (aPrsName, aPrs, true, true);
518 return 0;
519}
520
1cd84fee 521void QABugs::Commands_1(Draw_Interpretor& theCommands) {
522 const char *group = "QABugs";
7fd59977 523
7fd59977 524 theCommands.Add ("OCC159", "OCC159 Doc", __FILE__, OCC159bug, group);
525 theCommands.Add ("OCC145", "OCC145 Shape MaxNbr", __FILE__, OCC145bug, group);
526
527 theCommands.Add ("OCC73_SelectionMode", "OCC73_SelectionMode DOC entry [SelectionMode]", __FILE__, OCC73_SelectionMode, group);
528
529 theCommands.Add ("OCC10", "OCC10 Shape MaxNbr", __FILE__, OCC10bug, group);
530
531 theCommands.Add ("OCC74_set", "OCC74_set shape mode; set selection mode", __FILE__, OCC74bug_set, group);
532 theCommands.Add ("OCC74_get", "OCC74_get shape; get selection mode", __FILE__, OCC74bug_get, group);
533
88b12b7c 534 theCommands.Add ("OCC361", "OCC361 Doc ", __FILE__, OCC361bug, group);
535 theCommands.Add ("OCC30182",
536 "OCC30182 name image [-offset Start] [-fileName] [-stream] [-memory]\n"
537 "Decodes image either by passing file name, file stream or memory stream", __FILE__, OCC30182, group);
7fd59977 538 return;
539}