b311480e |
1 | // Created on: 2002-07-18 |
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 | |
1cd84fee |
16 | #include <QABugs.hxx> |
7fd59977 |
17 | |
91322f44 |
18 | #include <Draw.hxx> |
7fd59977 |
19 | #include <Draw_Interpretor.hxx> |
20 | #include <DBRep.hxx> |
7fd59977 |
21 | #include <AIS_InteractiveContext.hxx> |
7fd59977 |
22 | #include <AIS_Shape.hxx> |
23 | #include <TopoDS_Shape.hxx> |
24 | #include <TopoDS_Vertex.hxx> |
25 | |
26 | #include <TopExp_Explorer.hxx> |
27 | #include <TopoDS_Face.hxx> |
28 | #include <TopoDS.hxx> |
29 | #include <BRepBndLib.hxx> |
30 | #include <gp_Pln.hxx> |
31 | #include <BRep_Tool.hxx> |
32 | #include <BRepAlgoAPI_Section.hxx> |
7fd59977 |
33 | #include <Standard_ErrorHandler.hxx> |
34 | |
35 | #include <stdio.h> |
36 | |
37 | //======================================================================= |
38 | //function : OCC527 |
39 | //purpose : |
40 | //======================================================================= |
41 | static Standard_Integer OCC527(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
42 | { |
43 | try |
44 | { |
45 | OCC_CATCH_SIGNALS |
46 | // 1. Verify amount of arguments of the command |
431d0f18 |
47 | if (argc != 2) { |
48 | di << "Usage : " << argv[0] << "OCC527 shape\n"; |
7fd59977 |
49 | return 1; |
50 | } |
431d0f18 |
51 | |
7fd59977 |
52 | // 2. Get selected shape |
53 | TopoDS_Shape aShape = DBRep::Get(argv[1]); |
54 | if(aShape.IsNull()) { di << "OCC527 FAULTY. Entry shape is NULL"; return 0;} |
55 | |
56 | // 3. Explode entry shape on faces and build sections from Zmin to Zmax with step aStep |
57 | const Standard_Real Zmin = -40.228173882121, Zmax = 96.408126285268, aStep = 1.0; |
91322f44 |
58 | char str[100]; str[0] = 0; Sprintf(str,"Test range: [%f, %f] with step %f\n",Zmin,Zmax,aStep); di << str; |
7fd59977 |
59 | int nbf = 0; |
60 | TopExp_Explorer aExp1; |
61 | for (aExp1.Init(aShape,TopAbs_FACE); aExp1.More(); aExp1.Next()) |
62 | { |
63 | // Process one face |
91322f44 |
64 | str[0] = 0; Sprintf(str,"Face #%d: \t",nbf++); di << str; |
7fd59977 |
65 | TopoDS_Face aFace = TopoDS::Face(aExp1.Current()); |
66 | |
67 | // Build BndBox in order to avoid try of building section |
68 | // if plane of the one does not intersect BndBox of the face |
69 | Bnd_Box aFaceBox; |
70 | BRepBndLib::Add(aFace,aFaceBox); |
71 | Standard_Real X1,X2,Y1,Y2,Z1,Z2; |
72 | aFaceBox.Get(X1,Y1,Z1,X2,Y2,Z2); |
73 | |
74 | // Build sections from Zmin to Zmax with step aStep |
7fd59977 |
75 | double gmaxdist = 0.0, gzmax = Zmax; |
76 | for (double zcur = Zmax; zcur > Zmin; zcur -= aStep) |
77 | { |
78 | // If plane of the section does not intersect BndBox of the face do nothing |
79 | if(zcur < Z1 || zcur > Z2 ) continue; |
80 | |
81 | // Build current section |
82 | gp_Pln pl(0,0,1,-zcur); |
431d0f18 |
83 | |
84 | // |
85 | di << "BRepAlgoAPI_Section aSection(aFace,pl,Standard_False)\n"; |
86 | BRepAlgoAPI_Section aSection(aFace, pl, Standard_False); |
87 | aSection.Approximation(Standard_True); |
88 | aSection.Build(); |
89 | Standard_Boolean IsDone = aSection.IsDone(); |
7fd59977 |
90 | |
91 | if (IsDone) |
431d0f18 |
92 | { |
93 | const TopoDS_Shape& aResult = aSection.Shape(); |
94 | if (!aResult.IsNull()) |
95 | { |
7fd59977 |
96 | double lmaxdist = 0.0; |
7fd59977 |
97 | TopExp_Explorer aExp2; |
431d0f18 |
98 | for (aExp2.Init(aResult, TopAbs_VERTEX); aExp2.More(); aExp2.Next()) |
7fd59977 |
99 | { |
100 | TopoDS_Vertex aV = TopoDS::Vertex(aExp2.Current()); |
101 | Standard_Real toler = BRep_Tool::Tolerance(aV); |
102 | double dist = pl.Distance(BRep_Tool::Pnt(aV)); |
103 | if (dist > lmaxdist) lmaxdist = dist; |
316ea293 |
104 | // If section was built check distance between vertexes and plane of the one |
431d0f18 |
105 | str[0] = 0; |
106 | if (dist > toler) |
107 | Sprintf(str, "Dist=%f, Toler=%f, Param=%f FAULTY\n", dist, toler, gzmax); |
108 | else |
109 | Sprintf(str, "Dist=%f, Toler=%f, Param=%f\n", dist, toler, gzmax); |
110 | di << str; |
7fd59977 |
111 | } |
112 | if (lmaxdist > gmaxdist) |
113 | { |
114 | gmaxdist = lmaxdist; |
115 | gzmax = zcur; |
116 | } |
117 | } |
118 | } |
119 | } |
120 | } |
121 | } |
a738b534 |
122 | catch (Standard_Failure const&) {di << "OCC527 Exception \n" ;return 0;} |
7fd59977 |
123 | |
124 | return 0; |
125 | } |
126 | |
1cd84fee |
127 | void QABugs::Commands_2(Draw_Interpretor& theCommands) { |
1365140b |
128 | const char *group = "QABugs"; |
7fd59977 |
129 | |
431d0f18 |
130 | theCommands.Add("OCC527", "OCC527 shape", __FILE__, OCC527, group); |
7fd59977 |
131 | return; |
132 | } |