1 // Created on: 2002-02-04
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>
19 #include <ViewerTest.hxx>
20 #include <ViewerTest_EventManager.hxx>
21 #include <TopoDS_Shape.hxx>
22 #include <AIS_InteractiveContext.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>
33 #if defined(_WIN32) || defined(__WIN32__)
40 #include <Draw_PluginMacro.hxx>
42 //=======================================================================
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>
50 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
51 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext();
53 //==============================================================================
54 // function : VTrihedronOrigins
56 // purpose : draws triheron axis origin lines.
57 // Draw arg : vtri_orig trihedron_name
58 //==============================================================================
59 static int VTrihedronOrigins(Draw_Interpretor& di,
60 Standard_Integer argc,
64 di <<"Usage : vtri_orig tri_name\n";
68 if(TheAISContext().IsNull()){
69 di<<"Make 'vinit' before this method call\n";
73 //get trihedron from AIS map.
74 TCollection_AsciiString aName(argv[1]);
75 if(!GetMapOfAIS().IsBound2(aName)){
76 di<<"No object named '"<<argv[1]<<"'\n";
80 Handle(AIS_Trihedron) aTrih =
81 Handle(AIS_Trihedron)::DownCast(GetMapOfAIS().Find2(aName));
83 di<<"Trihedron is not found, try another name\n";
88 Handle(AIS_Axis) XAxis = aTrih->XAxis();
89 Handle(AIS_Axis) YAxis = aTrih->YAxis();
90 Handle(AIS_Axis) ZAxis = aTrih->Axis();
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();
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);
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:
107 di<<argv[1]<<"_X "<<argv[1]<<"_Y "<<argv[1]<<"_Z\n";
110 TheAISContext()->Display (XLine, Standard_False);
111 TheAISContext()->Display (YLine, Standard_False);
112 TheAISContext()->Display (ZLine, Standard_True);
117 //=======================================================================
118 //function : QATestExtremaSS
120 //=======================================================================
121 static Standard_Integer QATestExtremaSS (Draw_Interpretor& theInterpretor,
122 Standard_Integer theArgNb,
123 const char** theArgs)
128 std::cerr << "Usage: type help " << theArgs[0] << std::endl;
133 TopoDS_Shape aShape = DBRep::Get (theArgs[1]);
136 std::cerr << "Error: " << theArgs[1] << " shape is null\n";
141 const Standard_Real aStep = Draw::Atof (theArgs[2]);
144 std::cerr << "Error: Step " << aStep << " is too small\n";
148 Extrema_ExtFlag aFlag = Extrema_ExtFlag_MIN;
151 Standard_Integer aVal = Draw::Atoi (theArgs[3]);
154 aFlag = aVal == 1 ? Extrema_ExtFlag_MAX : Extrema_ExtFlag_MINMAX;
158 // Get bounding box of the shape
160 BRepBndLib::Add (aShape, aBounds);
162 Standard_Real aXmin, aYmin, aZmin;
163 Standard_Real aXmax, aYmax, aZmax;
164 aBounds.Get (aXmin, aYmin, aZmin,
165 aXmax, aYmax, aZmax);
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;
175 TopTools_SequenceOfShape aList;
176 TColgp_SequenceOfXYZ aPoints;
177 for (Standard_Real aX = aXmin + 0.5 * aStep; aX < aXmax; aX += aStep)
179 for (Standard_Real aY = aYmin + 0.5 * aStep; aY < aYmax; aY += aStep)
181 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aY, aZmin)));
182 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aY, aZmax)));
184 aPoints.Append (gp_XYZ (aX, aY, aZmin));
185 aPoints.Append (gp_XYZ (aX, aY, aZmax));
188 for (Standard_Real aZ = aZmin + 0.5 * aStep; aZ < aZmax; aZ += aStep)
190 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aYmin, aZ)));
191 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aYmax, aZ)));
193 aPoints.Append (gp_XYZ (aX, aYmin, aZ));
194 aPoints.Append (gp_XYZ (aX, aYmax, aZ));
198 for (Standard_Real aY = aYmin + 0.5 * aStep; aY < aYmax; aY += aStep)
200 for (Standard_Real aZ = aZmin + 0.5 * aStep; aZ < aZmax; aZ += aStep)
202 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aXmin, aY, aZ)));
203 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aXmax, aY, aZ)));
205 aPoints.Append (gp_XYZ (aXmin, aY, aZ));
206 aPoints.Append (gp_XYZ (aXmax, aY, aZ));
210 const Standard_Integer aNbPoints = aList.Length();
211 theInterpretor << "Number of sampled points: " << aNbPoints << "\n";
213 // Perform projection of points
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)
223 aTool.LoadS2 (aList (anIdx));
228 theInterpretor << "Test for gradient descent complete in: " << aTimer.ElapsedTime() << "\n";
232 //=======================================================================
233 //function : CommonCommands
235 //=======================================================================
236 void QADraw::CommonCommands (Draw_Interpretor& theCommands)
238 const char* group = "QA_Commands";
240 theCommands.Add ("vtri_orig",
241 "vtri_orig : vtri_orig trihedron_name - draws axis origin lines",
246 theCommands.Add ("QATestExtremaSS",
247 "QATestExtremaSS Shape Step [Flag { MIN = 0 | MAX = 1 | MINMAX = 2 }]",
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);
256 //==============================================================================
258 //==============================================================================
259 void QADraw::Factory(Draw_Interpretor& theCommands)
261 // definition of QA Command
262 QADraw::CommonCommands(theCommands);
263 QADraw::AdditionalCommands(theCommands);
266 // Declare entry point PLUGINFACTORY