0027958: Visualization, AIS_Trihedron - add shaded presentation option
[occt.git] / src / QADraw / QADraw.cxx
CommitLineData
b311480e 1// Created on: 2002-02-04
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
7fd59977 16#include <QADraw.hxx>
762b6cec 17#include <Draw.hxx>
7fd59977 18#include <Draw_Interpretor.hxx>
7fd59977 19#include <ViewerTest.hxx>
20#include <ViewerTest_EventManager.hxx>
762b6cec 21#include <TopoDS_Shape.hxx>
7fd59977 22#include <AIS_InteractiveContext.hxx>
762b6cec 23#include <DBRep.hxx>
24#include <Bnd_Box.hxx>
25#include <BRepBndLib.hxx>
26#include <BRepExtrema_DistShapeShape.hxx>
27#include <BRepBuilderAPI_MakeVertex.hxx>
28#include <TopTools_SequenceOfShape.hxx>
29#include <TColgp_SequenceOfXYZ.hxx>
30#include <OSD_Timer.hxx>
31#include <stdio.h>
7fd59977 32
7fd59977 33#include <Draw_PluginMacro.hxx>
34
7fd59977 35//=======================================================================
762b6cec 36//function : QATestExtremaSS
37//purpose :
38//=======================================================================
39static Standard_Integer QATestExtremaSS (Draw_Interpretor& theInterpretor,
40 Standard_Integer theArgNb,
41 const char** theArgs)
42{
43 if (theArgNb < 3
44 || theArgNb > 4)
45 {
46 std::cerr << "Usage: type help " << theArgs[0] << std::endl;
47 return 1;
48 }
49
50 // Get target shape
51 TopoDS_Shape aShape = DBRep::Get (theArgs[1]);
52 if (aShape.IsNull())
53 {
54 std::cerr << "Error: " << theArgs[1] << " shape is null\n";
55 return 1;
56 }
57
58 // Get step value
59 const Standard_Real aStep = Draw::Atof (theArgs[2]);
60 if (aStep <= 1e-5)
61 {
62 std::cerr << "Error: Step " << aStep << " is too small\n";
63 return 1;
64 }
65
66 Extrema_ExtFlag aFlag = Extrema_ExtFlag_MIN;
67 if (theArgNb > 3)
68 {
69 Standard_Integer aVal = Draw::Atoi (theArgs[3]);
70 if (aVal > 0)
71 {
72 aFlag = aVal == 1 ? Extrema_ExtFlag_MAX : Extrema_ExtFlag_MINMAX;
73 }
74 }
75
76 // Get bounding box of the shape
77 Bnd_Box aBounds;
78 BRepBndLib::Add (aShape, aBounds);
79
80 Standard_Real aXmin, aYmin, aZmin;
81 Standard_Real aXmax, aYmax, aZmax;
82 aBounds.Get (aXmin, aYmin, aZmin,
83 aXmax, aYmax, aZmax);
84
85 const Standard_Real aScaleFactor = 1.5;
86 aXmin *= aScaleFactor;
87 aYmin *= aScaleFactor;
88 aZmin *= aScaleFactor;
89 aXmax *= aScaleFactor;
90 aYmax *= aScaleFactor;
91 aZmax *= aScaleFactor;
92
93 TopTools_SequenceOfShape aList;
94 TColgp_SequenceOfXYZ aPoints;
95 for (Standard_Real aX = aXmin + 0.5 * aStep; aX < aXmax; aX += aStep)
96 {
97 for (Standard_Real aY = aYmin + 0.5 * aStep; aY < aYmax; aY += aStep)
98 {
99 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aY, aZmin)));
100 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aY, aZmax)));
101
102 aPoints.Append (gp_XYZ (aX, aY, aZmin));
103 aPoints.Append (gp_XYZ (aX, aY, aZmax));
104 }
105
106 for (Standard_Real aZ = aZmin + 0.5 * aStep; aZ < aZmax; aZ += aStep)
107 {
108 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aYmin, aZ)));
109 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aYmax, aZ)));
110
111 aPoints.Append (gp_XYZ (aX, aYmin, aZ));
112 aPoints.Append (gp_XYZ (aX, aYmax, aZ));
113 }
114 }
115
116 for (Standard_Real aY = aYmin + 0.5 * aStep; aY < aYmax; aY += aStep)
117 {
118 for (Standard_Real aZ = aZmin + 0.5 * aStep; aZ < aZmax; aZ += aStep)
119 {
120 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aXmin, aY, aZ)));
121 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aXmax, aY, aZ)));
122
123 aPoints.Append (gp_XYZ (aXmin, aY, aZ));
124 aPoints.Append (gp_XYZ (aXmax, aY, aZ));
125 }
126 }
127
128 const Standard_Integer aNbPoints = aList.Length();
129 theInterpretor << "Number of sampled points: " << aNbPoints << "\n";
130
131 // Perform projection of points
132 OSD_Timer aTimer;
133 aTimer.Start();
134
135 // Perform projection using standard method
136 BRepExtrema_DistShapeShape aTool;
137 aTool.SetFlag (aFlag);
138 aTool.LoadS1 (aShape);
139 for (Standard_Integer anIdx = 1; anIdx <= aNbPoints; ++anIdx)
140 {
141 aTool.LoadS2 (aList (anIdx));
142 aTool.Perform();
143 }
144
145 aTimer.Stop();
146 theInterpretor << "Test for gradient descent complete in: " << aTimer.ElapsedTime() << "\n";
147 return 0;
148}
149
150//=======================================================================
151//function : CommonCommands
152//purpose :
153//=======================================================================
154void QADraw::CommonCommands (Draw_Interpretor& theCommands)
7fd59977 155{
7fd59977 156 const char* group = "QA_Commands";
157
762b6cec 158 theCommands.Add ("QATestExtremaSS",
159 "QATestExtremaSS Shape Step [Flag { MIN = 0 | MAX = 1 | MINMAX = 2 }]",
160 __FILE__,
161 QATestExtremaSS,
162 group);
7fd59977 163
319e4241 164// adding commands "rename" leads to the fact that QA commands doesn't work properly OCC23410, use function "renamevar"
165// theCommands.Add("rename","rename name1 toname1 name2 toname2 ...",__FILE__,QArename,group);
7fd59977 166}
7fd59977 167
7fd59977 168//==============================================================================
169// QADraw::Factory
170//==============================================================================
171void QADraw::Factory(Draw_Interpretor& theCommands)
172{
7fd59977 173 // definition of QA Command
174 QADraw::CommonCommands(theCommands);
175 QADraw::AdditionalCommands(theCommands);
7fd59977 176}
177
178// Declare entry point PLUGINFACTORY
179DPLUGIN(QADraw)