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_KOI_Datum && aShape->Signature()==4) {
213 // On downcast aShape de AIS_InteractiveObject a AIS_PlaneTrihedron
214 theAISPlaneTri = Handle(AIS_PlaneTrihedron)::DownCast (aShape);
216 theAISPlaneTri->SetLength(Length);
218 aContext->Redisplay(theAISPlaneTri, Standard_False);
219 aContext->UpdateCurrentViewer();
222 TopoDS_Face FaceB=TopoDS::Face(S);
224 // Construction du Plane
225 // recuperation des edges des faces.
226 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
228 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
232 // si il y a plusieurs edges
233 if (FaceExpB.More() ) {
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);
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);
249 // Construction du Geom_Plane
250 GC_MakePlane MkPlane(A,B,C);
251 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
253 // on le display & bind
254 theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
256 theAISPlaneTri->SetLength(Length);
258 GetMapOfAIS().Bind ( theAISPlaneTri, name);
259 aContext->Display (theAISPlaneTri, Standard_True);
262 Standard_Real getLength = theAISPlaneTri->GetLength();
263 di << "Length = " << Length << "\n";
264 di << "getLength = " << getLength << "\n";
266 if (getLength == Length) {
269 di << "OCC10: ERROR\n";
275 static Standard_Integer OCC74bug_set (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
277 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
278 if(aContext.IsNull()) {
279 di << argv[0] << "ERROR : use 'vinit' command before \n";
284 di << "ERROR : Usage : " << argv[0] << " shape mode; set selection mode\n";
288 Standard_Boolean updateviewer = Standard_True;
290 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
292 TCollection_AsciiString aName(argv[1]);
293 Handle(AIS_InteractiveObject) AISObj;
295 Standard_Integer SelectMode = Draw::Atoi(argv[2]);
296 if (!aMap.Find2 (aName, AISObj)
299 di << "Use 'vdisplay' before\n";
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();
312 static Standard_Integer OCC74bug_get (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
314 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
315 if(aContext.IsNull()) {
316 di << argv[0] << "ERROR : use 'vinit' command before \n";
321 di << "ERROR : Usage : " << argv[0] << " shape; get selection mode\n";
325 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
327 TCollection_AsciiString aName(argv[1]);
328 Handle(AIS_InteractiveObject) AISObj;
329 if (!aMap.Find2(aName, AISObj)
332 di << "Use 'vdisplay' before\n";
336 TColStd_ListOfInteger anActivatedModes;
337 aContext->ActivatedModes (AISObj, anActivatedModes);
338 Standard_Integer aMode = anActivatedModes.IsEmpty() ? -1 : anActivatedModes.Last();
343 #include <BRepPrimAPI_MakeBox.hxx>
344 #include <TDF_Data.hxx>
345 #include <TNaming_Builder.hxx>
346 #include <TNaming_NamedShape.hxx>
347 #include <AIS_InteractiveObject.hxx>
349 static Standard_Integer OCC361bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
352 di << "ERROR : Usage : " << a[0] << " Doc\n";
357 Handle(TDocStd_Document) D;
358 if (!DDocStd::GetDocument(a[1],D)) {
363 BRepPrimAPI_MakeBox aBox(gp_Pnt(0, 0, 0), 100, 100, 100);
364 TopoDS_Shape aTBox = aBox.Shape();
365 aTBox.Orientation(TopAbs_FORWARD);
367 TDF_Label aTestLabel = D->Main();
369 TNaming_Builder aBuilder(aTestLabel);
370 aBuilder.Generated(aTBox);
372 TopoDS_Shape aTBox1 = aTBox;
373 aTBox1.Orientation(TopAbs_REVERSED);
374 aTestLabel.ForgetAllAttributes();
376 TNaming_Builder aBuilder2(aTestLabel);
377 aBuilder2.Generated( aTBox1);
379 aTBox = aBuilder2.NamedShape()->Get();
380 if(aTBox.Orientation() != TopAbs_REVERSED) {
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 //=======================================================================
397 static Standard_Integer OCC30182 (Draw_Interpretor& , Standard_Integer theNbArgs, const char** theArgVec)
399 if (ViewerTest::CurrentView().IsNull())
401 std::cout << "Error: no active view\n";
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)
410 TCollection_AsciiString anArg (theArgVec[anArgIter]);
412 if (anArg == "-offset"
413 && anArgIter + 1 < theNbArgs)
415 anOffset = Draw::Atoi (theArgVec[++anArgIter]);
417 else if (anArg == "-filename")
421 else if (anArg == "-stream")
425 else if (anArg == "-mem"
426 || anArg == "-memory")
430 else if (aPrsName.IsEmpty())
432 aPrsName = theArgVec[anArgIter];
434 else if (anImgPath.IsEmpty())
436 anImgPath = theArgVec[anArgIter];
440 std::cout << "Syntax error at '" << anArg << "'\n";
444 if (anImgPath.IsEmpty())
446 std::cout << "Syntax error: wrong number of arguments\n";
450 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
453 if (!anImage->Load (anImgPath))
461 OSD_OpenStream (aFile, anImgPath.ToCString(), std::ios::in | std::ios::binary);
462 if (!aFile.is_open())
464 std::cout << "Syntax error: image file '" << anImgPath << "' cannot be found\n";
469 aFile.seekg (anOffset);
474 aFile.seekg (0, std::ios::end);
475 Standard_Integer aLen = (Standard_Integer )aFile.tellg() - anOffset;
476 aFile.seekg (anOffset);
479 std::cout << "Syntax error: wrong offset\n";
482 NCollection_Array1<Standard_Byte> aBuff (1, aLen);
483 if (!aFile.read ((char* )&aBuff.ChangeFirst(), aBuff.Size()))
485 std::cout << "Error: unable to read file\n";
489 if (!anImage->Load (&aBuff.ChangeFirst(), aBuff.Size(), anImgPath))
496 if (!anImage->Load (aFile, anImgPath))
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())
513 anAspect->TextureMap()->GetParams()->SetTranslation(Graphic3d_Vec2 (0.0f, -1.0f));
514 anAspect->TextureMap()->GetParams()->SetScale (Graphic3d_Vec2 (1.0f, -1.0f));
517 ViewerTest::Display (aPrsName, aPrs, true, true);
521 void QABugs::Commands_1(Draw_Interpretor& theCommands) {
522 const char *group = "QABugs";
524 theCommands.Add ("OCC159", "OCC159 Doc", __FILE__, OCC159bug, group);
525 theCommands.Add ("OCC145", "OCC145 Shape MaxNbr", __FILE__, OCC145bug, group);
527 theCommands.Add ("OCC73_SelectionMode", "OCC73_SelectionMode DOC entry [SelectionMode]", __FILE__, OCC73_SelectionMode, group);
529 theCommands.Add ("OCC10", "OCC10 Shape MaxNbr", __FILE__, OCC10bug, group);
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);
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);