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.
20 #include <QADNaming.hxx>
21 #include <QANCollection.hxx>
23 #include <AIS_InteractiveContext.hxx>
24 #include <Bnd_Box.hxx>
25 #include <BRepBndLib.hxx>
26 #include <BRepExtrema_DistShapeShape.hxx>
27 #include <BRepBuilderAPI_MakeVertex.hxx>
30 #include <Draw_Interpretor.hxx>
31 #include <Draw_PluginMacro.hxx>
32 #include <OSD_Timer.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopTools_SequenceOfShape.hxx>
35 #include <TColgp_SequenceOfXYZ.hxx>
39 //=======================================================================
40 //function : QATestExtremaSS
42 //=======================================================================
43 static Standard_Integer QATestExtremaSS (Draw_Interpretor& theInterpretor,
44 Standard_Integer theArgNb,
50 std::cerr << "Usage: type help " << theArgs[0] << std::endl;
55 TopoDS_Shape aShape = DBRep::Get (theArgs[1]);
58 std::cerr << "Error: " << theArgs[1] << " shape is null\n";
63 const Standard_Real aStep = Draw::Atof (theArgs[2]);
66 std::cerr << "Error: Step " << aStep << " is too small\n";
70 Extrema_ExtFlag aFlag = Extrema_ExtFlag_MIN;
73 Standard_Integer aVal = Draw::Atoi (theArgs[3]);
76 aFlag = aVal == 1 ? Extrema_ExtFlag_MAX : Extrema_ExtFlag_MINMAX;
80 // Get bounding box of the shape
82 BRepBndLib::Add (aShape, aBounds);
84 Standard_Real aXmin, aYmin, aZmin;
85 Standard_Real aXmax, aYmax, aZmax;
86 aBounds.Get (aXmin, aYmin, aZmin,
89 const Standard_Real aScaleFactor = 1.5;
90 aXmin *= aScaleFactor;
91 aYmin *= aScaleFactor;
92 aZmin *= aScaleFactor;
93 aXmax *= aScaleFactor;
94 aYmax *= aScaleFactor;
95 aZmax *= aScaleFactor;
97 TopTools_SequenceOfShape aList;
98 TColgp_SequenceOfXYZ aPoints;
99 for (Standard_Real aX = aXmin + 0.5 * aStep; aX < aXmax; aX += aStep)
101 for (Standard_Real aY = aYmin + 0.5 * aStep; aY < aYmax; aY += aStep)
103 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aY, aZmin)));
104 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aY, aZmax)));
106 aPoints.Append (gp_XYZ (aX, aY, aZmin));
107 aPoints.Append (gp_XYZ (aX, aY, aZmax));
110 for (Standard_Real aZ = aZmin + 0.5 * aStep; aZ < aZmax; aZ += aStep)
112 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aYmin, aZ)));
113 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aX, aYmax, aZ)));
115 aPoints.Append (gp_XYZ (aX, aYmin, aZ));
116 aPoints.Append (gp_XYZ (aX, aYmax, aZ));
120 for (Standard_Real aY = aYmin + 0.5 * aStep; aY < aYmax; aY += aStep)
122 for (Standard_Real aZ = aZmin + 0.5 * aStep; aZ < aZmax; aZ += aStep)
124 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aXmin, aY, aZ)));
125 aList.Append (BRepBuilderAPI_MakeVertex (gp_Pnt (aXmax, aY, aZ)));
127 aPoints.Append (gp_XYZ (aXmin, aY, aZ));
128 aPoints.Append (gp_XYZ (aXmax, aY, aZ));
132 const Standard_Integer aNbPoints = aList.Length();
133 theInterpretor << "Number of sampled points: " << aNbPoints << "\n";
135 // Perform projection of points
139 // Perform projection using standard method
140 BRepExtrema_DistShapeShape aTool;
141 aTool.SetFlag (aFlag);
142 aTool.LoadS1 (aShape);
143 for (Standard_Integer anIdx = 1; anIdx <= aNbPoints; ++anIdx)
145 aTool.LoadS2 (aList (anIdx));
150 theInterpretor << "Test for gradient descent complete in: " << aTimer.ElapsedTime() << "\n";
154 //=======================================================================
155 //function : CommonCommands
157 //=======================================================================
158 void QADraw::CommonCommands (Draw_Interpretor& theCommands)
160 const char* group = "QA_Commands";
162 theCommands.Add ("QATestExtremaSS",
163 "QATestExtremaSS Shape Step [Flag { MIN = 0 | MAX = 1 | MINMAX = 2 }]",
168 // adding commands "rename" leads to the fact that QA commands doesn't work properly OCC23410, use function "renamevar"
169 // theCommands.Add("rename","rename name1 toname1 name2 toname2 ...",__FILE__,QArename,group);
172 //==============================================================================
174 //==============================================================================
175 void QADraw::Factory(Draw_Interpretor& theCommands)
177 // definition of QA Command
178 QADraw::CommonCommands(theCommands);
179 QADraw::TutorialCommands(theCommands);
181 QABugs::Commands(theCommands);
182 QADNaming::AllCommands(theCommands);
183 QANCollection::Commands(theCommands);
186 // Declare entry point PLUGINFACTORY