0027960: Configuration - fix compilation of OSD_Directory with MinGW-w64
[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
87225ffd 33#if defined(_WIN32) || defined(__WIN32__)
34# include <windows.h>
35# include <io.h>
7fd59977 36#else
87225ffd 37# include <unistd.h>
7fd59977 38#endif
39
7fd59977 40#include <Draw_PluginMacro.hxx>
41
7fd59977 42//=======================================================================
b7c077b9 43
7fd59977 44#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
45#include <AIS_Trihedron.hxx>
46#include <AIS_Axis.hxx>
47#include <Geom_Line.hxx>
48#include <AIS_Line.hxx>
49
b7c077b9 50Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
51Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext();
52
7fd59977 53//==============================================================================
54// function : VTrihedronOrigins
55// author : ota
56// purpose : draws triheron axis origin lines.
57// Draw arg : vtri_orig trihedron_name
58//==============================================================================
59static int VTrihedronOrigins(Draw_Interpretor& di,
60 Standard_Integer argc,
61 const char ** argv)
62{
63 if(argc != 2){
586db386 64 di <<"Usage : vtri_orig tri_name\n";
7fd59977 65 return 1;
66 }
67
68 if(TheAISContext().IsNull()){
586db386 69 di<<"Make 'vinit' before this method call\n";
7fd59977 70 return 1;
71 }
72
73 //get trihedron from AIS map.
74 TCollection_AsciiString aName(argv[1]);
75 if(!GetMapOfAIS().IsBound2(aName)){
586db386 76 di<<"No object named '"<<argv[1]<<"'\n";
7fd59977 77 return 1;
78 }
79
80 Handle(AIS_Trihedron) aTrih =
81 Handle(AIS_Trihedron)::DownCast(GetMapOfAIS().Find2(aName));
82 if(aTrih.IsNull()){
586db386 83 di<<"Trihedron is not found, try another name\n";
7fd59977 84 return 1;
85 }
86
87 //get axis
88 Handle(AIS_Axis) XAxis = aTrih->XAxis();
89 Handle(AIS_Axis) YAxis = aTrih->YAxis();
90 Handle(AIS_Axis) ZAxis = aTrih->Axis();
91
92 //get geometrical lines
93 Handle(Geom_Line) XGLine = XAxis->Component();
94 Handle(Geom_Line) YGLine = YAxis->Component();
95 Handle(Geom_Line) ZGLine = ZAxis->Component();
96
97 //make AIS_Lines
98 Handle(AIS_Line) XLine = new AIS_Line(XGLine);
99 Handle(AIS_Line) YLine = new AIS_Line(YGLine);
100 Handle(AIS_Line) ZLine = new AIS_Line(ZGLine);
101
102 //put them into AIS map:
103 GetMapOfAIS().Bind(XLine,aName+"_X");
104 GetMapOfAIS().Bind(YLine,aName+"_Y");
105 GetMapOfAIS().Bind(ZLine,aName+"_Z");
106 //print names of created objects:
586db386 107 di<<argv[1]<<"_X "<<argv[1]<<"_Y "<<argv[1]<<"_Z\n";
7fd59977 108
109 //try to draw them:
110 TheAISContext()->Display(XLine);
111 TheAISContext()->Display(YLine);
112 TheAISContext()->Display(ZLine);
113
114 return 0;
115}
116
762b6cec 117//=======================================================================
118//function : QATestExtremaSS
119//purpose :
120//=======================================================================
121static Standard_Integer QATestExtremaSS (Draw_Interpretor& theInterpretor,
122 Standard_Integer theArgNb,
123 const char** theArgs)
124{
125 if (theArgNb < 3
126 || theArgNb > 4)
127 {
128 std::cerr << "Usage: type help " << theArgs[0] << std::endl;
129 return 1;
130 }
131
132 // Get target shape
133 TopoDS_Shape aShape = DBRep::Get (theArgs[1]);
134 if (aShape.IsNull())
135 {
136 std::cerr << "Error: " << theArgs[1] << " shape is null\n";
137 return 1;
138 }
139
140 // Get step value
141 const Standard_Real aStep = Draw::Atof (theArgs[2]);
142 if (aStep <= 1e-5)
143 {
144 std::cerr << "Error: Step " << aStep << " is too small\n";
145 return 1;
146 }
147
148 Extrema_ExtFlag aFlag = Extrema_ExtFlag_MIN;
149 if (theArgNb > 3)
150 {
151 Standard_Integer aVal = Draw::Atoi (theArgs[3]);
152 if (aVal > 0)
153 {
154 aFlag = aVal == 1 ? Extrema_ExtFlag_MAX : Extrema_ExtFlag_MINMAX;
155 }
156 }
157
158 // Get bounding box of the shape
159 Bnd_Box aBounds;
160 BRepBndLib::Add (aShape, aBounds);
161
162 Standard_Real aXmin, aYmin, aZmin;
163 Standard_Real aXmax, aYmax, aZmax;
164 aBounds.Get (aXmin, aYmin, aZmin,
165 aXmax, aYmax, aZmax);
166
167 const Standard_Real aScaleFactor = 1.5;
168 aXmin *= aScaleFactor;
169 aYmin *= aScaleFactor;
170 aZmin *= aScaleFactor;
171 aXmax *= aScaleFactor;
172 aYmax *= aScaleFactor;
173 aZmax *= aScaleFactor;
174
175 TopTools_SequenceOfShape aList;
176 TColgp_SequenceOfXYZ aPoints;
177 for (Standard_Real aX = aXmin + 0.5 * aStep; aX < aXmax; aX += aStep)
178 {
179 for (Standard_Real aY = aYmin + 0.5 * aStep; aY < aYmax; aY += aStep)
180 {
181 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aY, aZmin)));
182 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aY, aZmax)));
183
184 aPoints.Append (gp_XYZ (aX, aY, aZmin));
185 aPoints.Append (gp_XYZ (aX, aY, aZmax));
186 }
187
188 for (Standard_Real aZ = aZmin + 0.5 * aStep; aZ < aZmax; aZ += aStep)
189 {
190 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aYmin, aZ)));
191 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aYmax, aZ)));
192
193 aPoints.Append (gp_XYZ (aX, aYmin, aZ));
194 aPoints.Append (gp_XYZ (aX, aYmax, aZ));
195 }
196 }
197
198 for (Standard_Real aY = aYmin + 0.5 * aStep; aY < aYmax; aY += aStep)
199 {
200 for (Standard_Real aZ = aZmin + 0.5 * aStep; aZ < aZmax; aZ += aStep)
201 {
202 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aXmin, aY, aZ)));
203 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aXmax, aY, aZ)));
204
205 aPoints.Append (gp_XYZ (aXmin, aY, aZ));
206 aPoints.Append (gp_XYZ (aXmax, aY, aZ));
207 }
208 }
209
210 const Standard_Integer aNbPoints = aList.Length();
211 theInterpretor << "Number of sampled points: " << aNbPoints << "\n";
212
213 // Perform projection of points
214 OSD_Timer aTimer;
215 aTimer.Start();
216
217 // Perform projection using standard method
218 BRepExtrema_DistShapeShape aTool;
219 aTool.SetFlag (aFlag);
220 aTool.LoadS1 (aShape);
221 for (Standard_Integer anIdx = 1; anIdx <= aNbPoints; ++anIdx)
222 {
223 aTool.LoadS2 (aList (anIdx));
224 aTool.Perform();
225 }
226
227 aTimer.Stop();
228 theInterpretor << "Test for gradient descent complete in: " << aTimer.ElapsedTime() << "\n";
229 return 0;
230}
231
232//=======================================================================
233//function : CommonCommands
234//purpose :
235//=======================================================================
236void QADraw::CommonCommands (Draw_Interpretor& theCommands)
7fd59977 237{
7fd59977 238 const char* group = "QA_Commands";
239
762b6cec 240 theCommands.Add ("vtri_orig",
241 "vtri_orig : vtri_orig trihedron_name - draws axis origin lines",
242 __FILE__,
243 VTrihedronOrigins,
244 group);
245
246 theCommands.Add ("QATestExtremaSS",
247 "QATestExtremaSS Shape Step [Flag { MIN = 0 | MAX = 1 | MINMAX = 2 }]",
248 __FILE__,
249 QATestExtremaSS,
250 group);
7fd59977 251
319e4241 252// adding commands "rename" leads to the fact that QA commands doesn't work properly OCC23410, use function "renamevar"
253// theCommands.Add("rename","rename name1 toname1 name2 toname2 ...",__FILE__,QArename,group);
7fd59977 254}
7fd59977 255
7fd59977 256//==============================================================================
257// QADraw::Factory
258//==============================================================================
259void QADraw::Factory(Draw_Interpretor& theCommands)
260{
7fd59977 261 // definition of QA Command
262 QADraw::CommonCommands(theCommands);
263 QADraw::AdditionalCommands(theCommands);
7fd59977 264}
265
266// Declare entry point PLUGINFACTORY
267DPLUGIN(QADraw)