1 // Created on: 2002-07-18
2 // Created by: QA Admin
3 // Copyright (c) 2002-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
22 #include <QAAMINO.hxx>
24 #include <Draw_Interpretor.hxx>
26 #include <DrawTrSurf.hxx>
27 #include <AIS_InteractiveContext.hxx>
28 #include <ViewerTest.hxx>
29 #include <AIS_Shape.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Vertex.hxx>
33 #include <TopExp_Explorer.hxx>
34 #include <TopoDS_Face.hxx>
36 #include <BRepBndLib.hxx>
38 #include <BRep_Tool.hxx>
39 #include <BRepAlgoAPI_Section.hxx>
40 #include <BRepAlgo_Section.hxx>
41 #include <Precision.hxx>
42 #include <Standard_ErrorHandler.hxx>
46 //=======================================================================
49 //=======================================================================
50 static Standard_Integer OCC527(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
55 // 1. Verify amount of arguments of the command
56 //if (argc < 2) { di << "OCC527 FAULTY. Use : OCC527 shape "; return 0;}
57 if (argc < 2 || argc > 3) {
58 di << "Usage : " << argv[0] << " shape [BRepAlgoAPI/BRepAlgo = 1/0]" << "\n";
61 Standard_Boolean IsBRepAlgoAPI = Standard_True;
63 Standard_Integer IsB = atoi(argv[2]);
65 IsBRepAlgoAPI = Standard_False;
66 //#if ! defined(BRepAlgo_def04)
67 // di << "Error: There is not BRepAlgo_Section class" << "\n";
73 // 2. Get selected shape
74 TopoDS_Shape aShape = DBRep::Get(argv[1]);
75 if(aShape.IsNull()) { di << "OCC527 FAULTY. Entry shape is NULL"; return 0;}
77 // 3. Explode entry shape on faces and build sections from Zmin to Zmax with step aStep
78 const Standard_Real Zmin = -40.228173882121, Zmax = 96.408126285268, aStep = 1.0;
79 char str[100]; str[0] = 0; sprintf(str,"Test range: [%f, %f] with step %f\n",Zmin,Zmax,aStep); di << str;
81 TopExp_Explorer aExp1;
82 for (aExp1.Init(aShape,TopAbs_FACE); aExp1.More(); aExp1.Next())
85 str[0] = 0; sprintf(str,"Face #%d: \t",nbf++); di << str;
86 TopoDS_Face aFace = TopoDS::Face(aExp1.Current());
88 // Build BndBox in order to avoid try of building section
89 // if plane of the one does not intersect BndBox of the face
91 BRepBndLib::Add(aFace,aFaceBox);
92 Standard_Real X1,X2,Y1,Y2,Z1,Z2;
93 aFaceBox.Get(X1,Y1,Z1,X2,Y2,Z2);
95 // Build sections from Zmin to Zmax with step aStep
96 Standard_Boolean wasBuilt = Standard_False;
97 double gmaxdist = 0.0, gzmax = Zmax;
98 for (double zcur = Zmax; zcur > Zmin; zcur -= aStep)
100 // If plane of the section does not intersect BndBox of the face do nothing
101 if(zcur < Z1 || zcur > Z2 ) continue;
103 // Build current section
104 gp_Pln pl(0,0,1,-zcur);
105 //#if ! defined(BRepAlgoAPI_def01)
106 // BRepAlgoAPI_Section aSection(aFace,pl,Standard_False);
108 // BRepAlgo_Section aSection(aFace,pl,Standard_False);
110 // aSection.Approximation(Standard_True);
112 // // If section was built meassure distance between vertexes and plane of the one. Max distance is stored.
113 // if (aSection.IsDone())
115 Standard_Boolean IsDone;
116 TopoDS_Shape aResult;
118 di << "BRepAlgoAPI_Section aSection(aFace,pl,Standard_False)" <<"\n";
119 BRepAlgoAPI_Section aSection(aFace,pl,Standard_False);
120 aSection.Approximation(Standard_True);
122 IsDone = aSection.IsDone();
123 aResult = aSection.Shape();
125 di << "BRepAlgo_Section aSection(aFace,pl,Standard_False)" <<"\n";
126 BRepAlgo_Section aSection(aFace,pl,Standard_False);
127 aSection.Approximation(Standard_True);
129 IsDone = aSection.IsDone();
130 aResult = aSection.Shape();
135 // TopoDS_Shape aResult = aSection.Shape();
136 if (!aResult.IsNull())
138 double lmaxdist = 0.0;
139 double lmaxtoler = 0.0;
140 TopExp_Explorer aExp2;
141 for (aExp2.Init(aResult,TopAbs_VERTEX); aExp2.More(); aExp2.Next())
143 TopoDS_Vertex aV = TopoDS::Vertex(aExp2.Current());
144 Standard_Real toler = BRep_Tool::Tolerance(aV);
145 double dist = pl.Distance(BRep_Tool::Pnt(aV));
146 if (dist > lmaxdist) lmaxdist = dist;
147 wasBuilt = Standard_True;
148 // If section was built check distance beetwen vertexes and plane of the one
152 // if(gmaxdist > Precision::Confusion())
153 // sprintf(str,"Dist=%f, Param=%f FAULTY\n",gmaxdist,gzmax);
155 // sprintf(str,"Dist=%f, Param=%f\n",gmaxdist,gzmax);
157 sprintf(str,"Dist=%f, Toler=%f, Param=%f FAULTY\n",dist,toler,gzmax);
159 sprintf(str,"Dist=%f, Toler=%f, Param=%f\n",dist,toler,gzmax);
161 // else sprintf(str,"No result\n");
164 if (lmaxdist > gmaxdist)
174 catch (Standard_Failure) {di << "OCC527 Exception \n" ;return 0;}
179 #include <StlMesh_Mesh.hxx>
180 #include <StlTransfer.hxx>
181 //=======================================================================
184 //=======================================================================
185 static Standard_Integer OCC1048 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
187 // Verify amount of arguments of the command
188 if (argc < 2) { di << "Usage : " << argv[0] <<" shape"; return 1;}
190 TopoDS_Shape aShape = DBRep::Get(argv[1]);
192 Standard_Real theDeflection = 0.006;
193 Handle(StlMesh_Mesh) theStlMesh = new StlMesh_Mesh;
194 StlTransfer::BuildIncrementalMesh(aShape, theDeflection, Standard_False, theStlMesh);
196 Standard_Integer NBTRIANGLES = theStlMesh->NbTriangles();
197 di<<"Info: Number of triangles = "<<NBTRIANGLES<<"\n";
202 void QAAMINO::Commands(Draw_Interpretor& theCommands) {
203 char *group = "QAAMINO";
205 //theCommands.Add("OCC527", "OCC527 shape", __FILE__, OCC527, group);
206 theCommands.Add("OCC527", "OCC527 shape [BRepAlgoAPI/BRepAlgo = 1/0]", __FILE__, OCC527, group);
207 theCommands.Add("OCC1048", "OCC1048 shape", __FILE__, OCC1048, group);