1 // Created on: 2002-05-21
2 // Created by: QA Admin
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
18 #include <Draw_Interpretor.hxx>
20 #include <DrawTrSurf.hxx>
21 #include <AIS_InteractiveContext.hxx>
22 #include <ViewerTest.hxx>
23 #include <AIS_Shape.hxx>
24 #include <TopoDS_Shape.hxx>
26 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
27 #include <TColStd_ListIteratorOfListOfInteger.hxx>
28 #include <TColStd_MapOfInteger.hxx>
30 #include <TDocStd_Document.hxx>
31 #include <TDocStd_Application.hxx>
32 #include <DDocStd.hxx>
33 #include <TDocStd_Owner.hxx>
34 #include <TDF_Label.hxx>
36 #include <TPrsStd_AISViewer.hxx>
37 #include <TPrsStd_AISPresentation.hxx>
39 #include <Draw_Viewer.hxx>
43 extern Draw_Viewer dout;
45 Standard_IMPORT Draw_Viewer dout;
48 #include <BRep_Builder.hxx>
49 #include <BRepTools.hxx>
50 #include <TopoDS_Wire.hxx>
51 #include <BRepBuilderAPI_MakeFace.hxx>
55 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
57 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
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>
67 static Standard_Integer OCC159bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
70 di << "ERROR : Usage : " << argv[0] << " Doc\n";
74 Handle(TDocStd_Document) D;
75 if (!DDocStd::GetDocument(argv[1],D)) return 1;
77 Standard_Integer DocRefCount1 = D->GetRefCount();
78 di << "DocRefCount1 = " << DocRefCount1 << "\n";
80 Handle(TDocStd_Owner) Owner;
81 if (!D->Main().Root().FindAttribute(TDocStd_Owner::GetID(),Owner)) return 1;
83 Handle(TDocStd_Document) OwnerD1 = Owner->GetDocument();
84 if (OwnerD1.IsNull()) {
85 di << "DocOwner1 = NULL\n";
87 di << "DocOwner1 = NOTNULL\n";
91 Handle(TDocStd_Application) A = DDocStd::GetApplication();
94 if (Handle(Draw_Drawable3D) DD = Draw::GetExisting (argv[1]))
96 dout.RemoveDrawable (DD);
99 Handle(TDocStd_Document) OwnerD2 = Owner->GetDocument();
100 if (OwnerD2.IsNull()) {
101 di << "DocOwner2 = NULL\n";
103 di << "DocOwner2 = NOTNULL\n";
106 Standard_Integer DocRefCount2 = D->GetRefCount();
107 di << "DocRefCount2 = " << DocRefCount2 << "\n";
112 static Standard_Integer OCC145bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
115 di << "ERROR : Usage : " << argv[0] << " Shape MaxNbr\n";
119 TCollection_AsciiString aFileName = argv[1];
120 Standard_Integer aMaxNbr = Draw::Atoi(argv[2]);
125 if (!BRepTools::Read(aShape, aFileName.ToCString(), aBld)) {
126 di << "ERROR :Could not read a shape!!!\n";
131 TopoDS_Wire aWire = TopoDS::Wire(aShape);
133 for (i = 1; i <= aMaxNbr; i++) {
134 BRepBuilderAPI_MakeFace aMF(aWire);
136 di << "ERROR : Could not make a face\n";
144 static Standard_Integer OCC73_SelectionMode (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
147 di << "ERROR : Usage : " << argv[0] << " DOC entry [SelectionMode]\n";
151 Handle(TDocStd_Document) D;
152 //std::cout << "OCC73_SelectionMode 1" << std::endl;
153 if (!DDocStd::GetDocument(argv[1],D)) return 1;
155 //std::cout << "OCC73_SelectionMode 2" << std::endl;
156 if (!DDF::FindLabel(D->GetData(),argv[2],L)) return 1;
158 Handle(TPrsStd_AISViewer) viewer;
159 //std::cout << "OCC73_SelectionMode 3" << std::endl;
160 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
162 Handle(TPrsStd_AISPresentation) prs;
163 //std::cout << "OCC73_SelectionMode 4" << std::endl;
164 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
166 prs->SetSelectionMode((Standard_Integer)Draw::Atoi(argv[3]));
167 TPrsStd_AISViewer::Update(L);
170 Standard_Integer SelectionMode = prs->SelectionMode();
171 //std::cout << "SelectionMode = " << SelectionMode << std::endl;
175 //std::cout << "OCC73_SelectionMode 5" << std::endl;
180 static Standard_Integer OCC10bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
182 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
183 if(aContext.IsNull()) {
184 di << "use 'vinit' command before " << argv[0] << "\n";
189 di << "Usage : " << argv[0] << " name plane Length\n";
193 TopoDS_Shape S = DBRep::Get( argv[2] );
195 di << "Shape is empty\n";
199 TCollection_AsciiString name(argv[1]);
200 Standard_Real Length = Draw::Atof(argv[3]);
202 // Construction de l'AIS_PlaneTrihedron
203 Handle(AIS_PlaneTrihedron) theAISPlaneTri;
205 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
207 // on recupere la shape dans la map des objets displayes
208 Handle(AIS_InteractiveObject) aShape = GetMapOfAIS().Find2(name);
210 // On verifie que l'AIS InteraciveObject est bien
211 // un AIS_PlaneTrihedron
212 if (aShape->Type() == AIS_KindOfInteractive_Datum
213 && aShape->Signature() == 4)
215 // On downcast aShape de AIS_InteractiveObject a AIS_PlaneTrihedron
216 theAISPlaneTri = Handle(AIS_PlaneTrihedron)::DownCast (aShape);
218 theAISPlaneTri->SetLength(Length);
220 aContext->Redisplay(theAISPlaneTri, Standard_False);
221 aContext->UpdateCurrentViewer();
224 TopoDS_Face FaceB=TopoDS::Face(S);
226 // Construction du Plane
227 // recuperation des edges des faces.
228 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
230 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
234 // si il y a plusieurs edges
235 if (FaceExpB.More() ) {
237 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
238 BRepAdaptor_Curve theCurveB(EdgeB);
239 BRepAdaptor_Curve theCurveC(EdgeC);
240 A=theCurveC.Value(0.1);
241 B=theCurveC.Value(0.9);
242 C=theCurveB.Value(0.5);
245 // FaceB a 1 unique edge courbe
246 BRepAdaptor_Curve theCurveB(EdgeB);
247 A=theCurveB.Value(0.1);
248 B=theCurveB.Value(0.9);
249 C=theCurveB.Value(0.5);
251 // Construction du Geom_Plane
252 GC_MakePlane MkPlane(A,B,C);
253 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
255 // on le display & bind
256 theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
258 theAISPlaneTri->SetLength(Length);
260 GetMapOfAIS().Bind ( theAISPlaneTri, name);
261 aContext->Display (theAISPlaneTri, Standard_True);
264 Standard_Real getLength = theAISPlaneTri->GetLength();
265 di << "Length = " << Length << "\n";
266 di << "getLength = " << getLength << "\n";
268 if (getLength == Length) {
271 di << "OCC10: ERROR\n";
277 static Standard_Integer OCC74bug_set (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
279 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
280 if(aContext.IsNull()) {
281 di << argv[0] << "ERROR : use 'vinit' command before \n";
286 di << "ERROR : Usage : " << argv[0] << " shape mode; set selection mode\n";
290 Standard_Boolean updateviewer = Standard_True;
292 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
294 TCollection_AsciiString aName(argv[1]);
295 Handle(AIS_InteractiveObject) AISObj;
297 Standard_Integer SelectMode = Draw::Atoi(argv[2]);
298 if (!aMap.Find2 (aName, AISObj)
301 di << "Use 'vdisplay' before\n";
305 aContext->Erase(AISObj, updateviewer);
306 aContext->UpdateCurrentViewer();
307 aContext->SetAutoActivateSelection (Standard_False);
308 aContext->Display(AISObj, updateviewer);
309 aContext->Activate (AISObj, SelectMode);
310 aContext->UpdateCurrentViewer();
314 static Standard_Integer OCC74bug_get (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
316 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
317 if(aContext.IsNull()) {
318 di << argv[0] << "ERROR : use 'vinit' command before \n";
323 di << "ERROR : Usage : " << argv[0] << " shape; get selection mode\n";
327 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
329 TCollection_AsciiString aName(argv[1]);
330 Handle(AIS_InteractiveObject) AISObj;
331 if (!aMap.Find2(aName, AISObj)
334 di << "Use 'vdisplay' before\n";
338 TColStd_ListOfInteger anActivatedModes;
339 aContext->ActivatedModes (AISObj, anActivatedModes);
340 Standard_Integer aMode = anActivatedModes.IsEmpty() ? -1 : anActivatedModes.Last();
345 #include <BRepPrimAPI_MakeBox.hxx>
346 #include <TDF_Data.hxx>
347 #include <TNaming_Builder.hxx>
348 #include <TNaming_NamedShape.hxx>
349 #include <AIS_InteractiveObject.hxx>
351 static Standard_Integer OCC361bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
354 di << "ERROR : Usage : " << a[0] << " Doc\n";
359 Handle(TDocStd_Document) D;
360 if (!DDocStd::GetDocument(a[1],D)) {
365 BRepPrimAPI_MakeBox aBox(gp_Pnt(0, 0, 0), 100, 100, 100);
366 TopoDS_Shape aTBox = aBox.Shape();
367 aTBox.Orientation(TopAbs_FORWARD);
369 TDF_Label aTestLabel = D->Main();
371 TNaming_Builder aBuilder(aTestLabel);
372 aBuilder.Generated(aTBox);
374 TopoDS_Shape aTBox1 = aTBox;
375 aTBox1.Orientation(TopAbs_REVERSED);
376 aTestLabel.ForgetAllAttributes();
378 TNaming_Builder aBuilder2(aTestLabel);
379 aBuilder2.Generated( aTBox1);
381 aTBox = aBuilder2.NamedShape()->Get();
382 if(aTBox.Orientation() != TopAbs_REVERSED) {
390 #include <Graphic3d_Texture2Dmanual.hxx>
391 #include <Image_AlienPixMap.hxx>
392 #include <OSD_OpenFile.hxx>
393 #include <Prs3d_ShadingAspect.hxx>
394 #include <Standard_ArrayStreamBuffer.hxx>
395 //=======================================================================
396 //function : OCC30182
397 //purpose : Testing different interfaces of Image_AlienPixMap::Load()
398 //=======================================================================
399 static Standard_Integer OCC30182 (Draw_Interpretor& , Standard_Integer theNbArgs, const char** theArgVec)
401 if (ViewerTest::CurrentView().IsNull())
403 std::cout << "Error: no active view\n";
407 TCollection_AsciiString aPrsName, anImgPath;
408 Standard_Integer anOffset = 0;
409 Standard_Integer aSrc = 0; // 0 - file name, 1 - file stream, 2 - memory buffer
410 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
412 TCollection_AsciiString anArg (theArgVec[anArgIter]);
414 if (anArg == "-offset"
415 && anArgIter + 1 < theNbArgs)
417 anOffset = Draw::Atoi (theArgVec[++anArgIter]);
419 else if (anArg == "-filename")
423 else if (anArg == "-stream")
427 else if (anArg == "-mem"
428 || anArg == "-memory")
432 else if (aPrsName.IsEmpty())
434 aPrsName = theArgVec[anArgIter];
436 else if (anImgPath.IsEmpty())
438 anImgPath = theArgVec[anArgIter];
442 std::cout << "Syntax error at '" << anArg << "'\n";
446 if (anImgPath.IsEmpty())
448 std::cout << "Syntax error: wrong number of arguments\n";
452 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
455 if (!anImage->Load (anImgPath))
463 OSD_OpenStream (aFile, anImgPath.ToCString(), std::ios::in | std::ios::binary);
464 if (!aFile.is_open())
466 std::cout << "Syntax error: image file '" << anImgPath << "' cannot be found\n";
471 aFile.seekg (anOffset);
476 aFile.seekg (0, std::ios::end);
477 Standard_Integer aLen = (Standard_Integer )aFile.tellg() - anOffset;
478 aFile.seekg (anOffset);
481 std::cout << "Syntax error: wrong offset\n";
484 NCollection_Array1<Standard_Byte> aBuff (1, aLen);
485 if (!aFile.read ((char* )&aBuff.ChangeFirst(), aBuff.Size()))
487 std::cout << "Error: unable to read file\n";
491 if (!anImage->Load (&aBuff.ChangeFirst(), aBuff.Size(), anImgPath))
498 if (!anImage->Load (aFile, anImgPath))
505 TopoDS_Shape aShape = BRepPrimAPI_MakeBox (100.0 * anImage->Ratio(), 100.0, 1.0).Shape();
506 Handle(AIS_Shape) aPrs = new AIS_Shape (aShape);
507 aPrs->SetDisplayMode (AIS_Shaded);
508 aPrs->Attributes()->SetupOwnShadingAspect();
509 const Handle(Graphic3d_AspectFillArea3d)& anAspect = aPrs->Attributes()->ShadingAspect()->Aspect();
510 anAspect->SetShadingModel (Graphic3d_TOSM_UNLIT);
511 anAspect->SetTextureMapOn (true);
512 anAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (anImage));
513 if (anImage->IsTopDown())
515 anAspect->TextureMap()->GetParams()->SetTranslation(Graphic3d_Vec2 (0.0f, -1.0f));
516 anAspect->TextureMap()->GetParams()->SetScale (Graphic3d_Vec2 (1.0f, -1.0f));
519 ViewerTest::Display (aPrsName, aPrs, true, true);
523 void QABugs::Commands_1(Draw_Interpretor& theCommands) {
524 const char *group = "QABugs";
526 theCommands.Add ("OCC159", "OCC159 Doc", __FILE__, OCC159bug, group);
527 theCommands.Add ("OCC145", "OCC145 Shape MaxNbr", __FILE__, OCC145bug, group);
529 theCommands.Add ("OCC73_SelectionMode", "OCC73_SelectionMode DOC entry [SelectionMode]", __FILE__, OCC73_SelectionMode, group);
531 theCommands.Add ("OCC10", "OCC10 Shape MaxNbr", __FILE__, OCC10bug, group);
533 theCommands.Add ("OCC74_set", "OCC74_set shape mode; set selection mode", __FILE__, OCC74bug_set, group);
534 theCommands.Add ("OCC74_get", "OCC74_get shape; get selection mode", __FILE__, OCC74bug_get, group);
536 theCommands.Add ("OCC361", "OCC361 Doc ", __FILE__, OCC361bug, group);
537 theCommands.Add ("OCC30182",
538 "OCC30182 name image [-offset Start] [-fileName] [-stream] [-memory]\n"
539 "Decodes image either by passing file name, file stream or memory stream", __FILE__, OCC30182, group);