| 1 | // Created on: 2002-07-18 |
| 2 | // Created by: QA Admin |
| 3 | // Copyright (c) 2002-2012 OPEN CASCADE SAS |
| 4 | // |
| 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. |
| 9 | // |
| 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. |
| 12 | // |
| 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. |
| 19 | |
| 20 | #include <QABugs.hxx> |
| 21 | |
| 22 | #include <Draw.hxx> |
| 23 | #include <Draw_Interpretor.hxx> |
| 24 | #include <DBRep.hxx> |
| 25 | #include <DrawTrSurf.hxx> |
| 26 | #include <AIS_InteractiveContext.hxx> |
| 27 | #include <ViewerTest.hxx> |
| 28 | #include <AIS_Shape.hxx> |
| 29 | #include <TopoDS_Shape.hxx> |
| 30 | #include <TopoDS_Vertex.hxx> |
| 31 | |
| 32 | #include <TopExp_Explorer.hxx> |
| 33 | #include <TopoDS_Face.hxx> |
| 34 | #include <TopoDS.hxx> |
| 35 | #include <BRepBndLib.hxx> |
| 36 | #include <gp_Pln.hxx> |
| 37 | #include <BRep_Tool.hxx> |
| 38 | #include <BRepAlgoAPI_Section.hxx> |
| 39 | #include <BRepAlgo_Section.hxx> |
| 40 | #include <Precision.hxx> |
| 41 | #include <Standard_ErrorHandler.hxx> |
| 42 | |
| 43 | #include <stdio.h> |
| 44 | |
| 45 | //======================================================================= |
| 46 | //function : OCC527 |
| 47 | //purpose : |
| 48 | //======================================================================= |
| 49 | static Standard_Integer OCC527(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
| 50 | { |
| 51 | try |
| 52 | { |
| 53 | OCC_CATCH_SIGNALS |
| 54 | // 1. Verify amount of arguments of the command |
| 55 | //if (argc < 2) { di << "OCC527 FAULTY. Use : OCC527 shape "; return 0;} |
| 56 | if (argc < 2 || argc > 3) { |
| 57 | di << "Usage : " << argv[0] << " shape [BRepAlgoAPI/BRepAlgo = 1/0]" << "\n"; |
| 58 | return 1; |
| 59 | } |
| 60 | Standard_Boolean IsBRepAlgoAPI = Standard_True; |
| 61 | if (argc == 3) { |
| 62 | Standard_Integer IsB = Draw::Atoi(argv[2]); |
| 63 | if (IsB != 1) { |
| 64 | IsBRepAlgoAPI = Standard_False; |
| 65 | //#if ! defined(BRepAlgo_def04) |
| 66 | // di << "Error: There is not BRepAlgo_Section class" << "\n"; |
| 67 | // return 1; |
| 68 | //#endif |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // 2. Get selected shape |
| 73 | TopoDS_Shape aShape = DBRep::Get(argv[1]); |
| 74 | if(aShape.IsNull()) { di << "OCC527 FAULTY. Entry shape is NULL"; return 0;} |
| 75 | |
| 76 | // 3. Explode entry shape on faces and build sections from Zmin to Zmax with step aStep |
| 77 | const Standard_Real Zmin = -40.228173882121, Zmax = 96.408126285268, aStep = 1.0; |
| 78 | char str[100]; str[0] = 0; Sprintf(str,"Test range: [%f, %f] with step %f\n",Zmin,Zmax,aStep); di << str; |
| 79 | int nbf = 0; |
| 80 | TopExp_Explorer aExp1; |
| 81 | for (aExp1.Init(aShape,TopAbs_FACE); aExp1.More(); aExp1.Next()) |
| 82 | { |
| 83 | // Process one face |
| 84 | str[0] = 0; Sprintf(str,"Face #%d: \t",nbf++); di << str; |
| 85 | TopoDS_Face aFace = TopoDS::Face(aExp1.Current()); |
| 86 | |
| 87 | // Build BndBox in order to avoid try of building section |
| 88 | // if plane of the one does not intersect BndBox of the face |
| 89 | Bnd_Box aFaceBox; |
| 90 | BRepBndLib::Add(aFace,aFaceBox); |
| 91 | Standard_Real X1,X2,Y1,Y2,Z1,Z2; |
| 92 | aFaceBox.Get(X1,Y1,Z1,X2,Y2,Z2); |
| 93 | |
| 94 | // Build sections from Zmin to Zmax with step aStep |
| 95 | Standard_Boolean wasBuilt = Standard_False; |
| 96 | double gmaxdist = 0.0, gzmax = Zmax; |
| 97 | for (double zcur = Zmax; zcur > Zmin; zcur -= aStep) |
| 98 | { |
| 99 | // If plane of the section does not intersect BndBox of the face do nothing |
| 100 | if(zcur < Z1 || zcur > Z2 ) continue; |
| 101 | |
| 102 | // Build current section |
| 103 | gp_Pln pl(0,0,1,-zcur); |
| 104 | //#if ! defined(BRepAlgoAPI_def01) |
| 105 | // BRepAlgoAPI_Section aSection(aFace,pl,Standard_False); |
| 106 | //#else |
| 107 | // BRepAlgo_Section aSection(aFace,pl,Standard_False); |
| 108 | //#endif |
| 109 | // aSection.Approximation(Standard_True); |
| 110 | // aSection.Build(); |
| 111 | // // If section was built meassure distance between vertexes and plane of the one. Max distance is stored. |
| 112 | // if (aSection.IsDone()) |
| 113 | |
| 114 | Standard_Boolean IsDone; |
| 115 | TopoDS_Shape aResult; |
| 116 | if (IsBRepAlgoAPI) { |
| 117 | di << "BRepAlgoAPI_Section aSection(aFace,pl,Standard_False)" <<"\n"; |
| 118 | BRepAlgoAPI_Section aSection(aFace,pl,Standard_False); |
| 119 | aSection.Approximation(Standard_True); |
| 120 | aSection.Build(); |
| 121 | IsDone = aSection.IsDone(); |
| 122 | aResult = aSection.Shape(); |
| 123 | } else { |
| 124 | di << "BRepAlgo_Section aSection(aFace,pl,Standard_False)" <<"\n"; |
| 125 | BRepAlgo_Section aSection(aFace,pl,Standard_False); |
| 126 | aSection.Approximation(Standard_True); |
| 127 | aSection.Build(); |
| 128 | IsDone = aSection.IsDone(); |
| 129 | aResult = aSection.Shape(); |
| 130 | } |
| 131 | |
| 132 | if (IsDone) |
| 133 | { |
| 134 | // TopoDS_Shape aResult = aSection.Shape(); |
| 135 | if (!aResult.IsNull()) |
| 136 | { |
| 137 | double lmaxdist = 0.0; |
| 138 | double lmaxtoler = 0.0; |
| 139 | TopExp_Explorer aExp2; |
| 140 | for (aExp2.Init(aResult,TopAbs_VERTEX); aExp2.More(); aExp2.Next()) |
| 141 | { |
| 142 | TopoDS_Vertex aV = TopoDS::Vertex(aExp2.Current()); |
| 143 | Standard_Real toler = BRep_Tool::Tolerance(aV); |
| 144 | double dist = pl.Distance(BRep_Tool::Pnt(aV)); |
| 145 | if (dist > lmaxdist) lmaxdist = dist; |
| 146 | wasBuilt = Standard_True; |
| 147 | // If section was built check distance beetwen vertexes and plane of the one |
| 148 | str[0] =0; |
| 149 | // if (wasBuilt) |
| 150 | // { |
| 151 | // if(gmaxdist > Precision::Confusion()) |
| 152 | // Sprintf(str,"Dist=%f, Param=%f FAULTY\n",gmaxdist,gzmax); |
| 153 | // else |
| 154 | // Sprintf(str,"Dist=%f, Param=%f\n",gmaxdist,gzmax); |
| 155 | if(dist > toler) |
| 156 | Sprintf(str,"Dist=%f, Toler=%f, Param=%f FAULTY\n",dist,toler,gzmax); |
| 157 | else |
| 158 | Sprintf(str,"Dist=%f, Toler=%f, Param=%f\n",dist,toler,gzmax); |
| 159 | // } |
| 160 | // else Sprintf(str,"No result\n"); |
| 161 | di << str; |
| 162 | } |
| 163 | if (lmaxdist > gmaxdist) |
| 164 | { |
| 165 | gmaxdist = lmaxdist; |
| 166 | gzmax = zcur; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | catch (Standard_Failure) {di << "OCC527 Exception \n" ;return 0;} |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | #include <StlMesh_Mesh.hxx> |
| 179 | #include <StlTransfer.hxx> |
| 180 | //======================================================================= |
| 181 | //function : OCC1048 |
| 182 | //purpose : |
| 183 | //======================================================================= |
| 184 | static Standard_Integer OCC1048 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
| 185 | { |
| 186 | // Verify amount of arguments of the command |
| 187 | if (argc < 2) { di << "Usage : " << argv[0] <<" shape"; return 1;} |
| 188 | |
| 189 | TopoDS_Shape aShape = DBRep::Get(argv[1]); |
| 190 | |
| 191 | Standard_Real theDeflection = 0.006; |
| 192 | Handle(StlMesh_Mesh) theStlMesh = new StlMesh_Mesh; |
| 193 | StlTransfer::BuildIncrementalMesh(aShape, theDeflection, Standard_False, theStlMesh); |
| 194 | |
| 195 | Standard_Integer NBTRIANGLES = theStlMesh->NbTriangles(); |
| 196 | di<<"Info: Number of triangles = "<<NBTRIANGLES<<"\n"; |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | void QABugs::Commands_2(Draw_Interpretor& theCommands) { |
| 202 | const char *group = "QABugs"; |
| 203 | |
| 204 | //theCommands.Add("OCC527", "OCC527 shape", __FILE__, OCC527, group); |
| 205 | theCommands.Add("OCC527", "OCC527 shape [BRepAlgoAPI/BRepAlgo = 1/0]", __FILE__, OCC527, group); |
| 206 | theCommands.Add("OCC1048", "OCC1048 shape", __FILE__, OCC1048, group); |
| 207 | return; |
| 208 | } |