| 1 | // Created on: 1994-10-04 |
| 2 | // Created by: Yves FRICAUD |
| 3 | // Copyright (c) 1994-1999 Matra Datavision |
| 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 5 | // |
| 6 | // This file is part of Open CASCADE Technology software library. |
| 7 | // |
| 8 | // This library is free software; you can redistribute it and/or modify it under |
| 9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
| 10 | // by the Free Software Foundation, with special exception defined in the file |
| 11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
| 12 | // distribution for complete text of the license and disclaimer of any warranty. |
| 13 | // |
| 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 15 | // commercial license or contractual agreement. |
| 16 | |
| 17 | #include <BRepTest.hxx> |
| 18 | #include <Draw_Interpretor.hxx> |
| 19 | #include <Draw_Appli.hxx> |
| 20 | #include <DrawTrSurf.hxx> |
| 21 | #include <DrawTrSurf_Curve2d.hxx> |
| 22 | |
| 23 | #include <Geom2d_Line.hxx> |
| 24 | #include <Geom2d_Circle.hxx> |
| 25 | #include <Geom2d_Curve.hxx> |
| 26 | #include <Geom2d_TrimmedCurve.hxx> |
| 27 | #include <Geom2d_Parabola.hxx> |
| 28 | #include <Geom2d_Hyperbola.hxx> |
| 29 | |
| 30 | #include <MAT_Bisector.hxx> |
| 31 | #include <MAT_Zone.hxx> |
| 32 | #include <MAT_Graph.hxx> |
| 33 | #include <MAT_Arc.hxx> |
| 34 | #include <MAT_BasicElt.hxx> |
| 35 | #include <MAT_Node.hxx> |
| 36 | #include <MAT_Side.hxx> |
| 37 | |
| 38 | #include <Bisector_Bisec.hxx> |
| 39 | #include <Bisector_BisecAna.hxx> |
| 40 | #include <Bisector_Curve.hxx> |
| 41 | #include <Precision.hxx> |
| 42 | |
| 43 | #include <BRepMAT2d_Explorer.hxx> |
| 44 | #include <BRepMAT2d_BisectingLocus.hxx> |
| 45 | #include <BRepMAT2d_LinkTopoBilo.hxx> |
| 46 | |
| 47 | #include <gp_Parab2d.hxx> |
| 48 | #include <gp_Hypr2d.hxx> |
| 49 | |
| 50 | #include <DBRep.hxx> |
| 51 | #include <TopoDS.hxx> |
| 52 | |
| 53 | #ifdef _WIN32 |
| 54 | Standard_IMPORT Draw_Viewer dout; |
| 55 | #endif |
| 56 | |
| 57 | static BRepMAT2d_BisectingLocus MapBiLo; |
| 58 | static BRepMAT2d_Explorer anExplo; |
| 59 | static BRepMAT2d_LinkTopoBilo TopoBilo; |
| 60 | static MAT_Side SideOfMat = MAT_Left; |
| 61 | static Standard_Boolean LinkComputed; |
| 62 | |
| 63 | static void DrawCurve(const Handle(Geom2d_Curve)& aCurve, |
| 64 | const Standard_Integer Indice); |
| 65 | |
| 66 | //========================================================================== |
| 67 | //function : topoLoad |
| 68 | // loading of a face in the explorer. |
| 69 | //========================================================================== |
| 70 | static Standard_Integer topoload (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
| 71 | { |
| 72 | if (argc < 2) return 1; |
| 73 | |
| 74 | TopoDS_Shape C1 = DBRep::Get (argv[1],TopAbs_FACE); |
| 75 | |
| 76 | if (C1.IsNull()) return 1; |
| 77 | |
| 78 | anExplo.Perform (TopoDS::Face(C1)); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | //========================================================================== |
| 83 | //function : drawcont |
| 84 | // visualization of the contour defined by the explorer. |
| 85 | //========================================================================== |
| 86 | static Standard_Integer drawcont(Draw_Interpretor& , Standard_Integer , const char**) |
| 87 | { |
| 88 | Handle(Geom2d_TrimmedCurve) C; |
| 89 | |
| 90 | for (Standard_Integer j = 1; j <= anExplo.NumberOfContours(); j ++) { |
| 91 | for (anExplo.Init(j);anExplo.More();anExplo.Next()) { |
| 92 | DrawCurve(anExplo.Value(),1); |
| 93 | } |
| 94 | } |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | //========================================================================== |
| 99 | //function : mat |
| 100 | // calculate the map of locations bisector on the contour defined by |
| 101 | // the explorer. |
| 102 | //========================================================================== |
| 103 | static Standard_Integer mat(Draw_Interpretor&, Standard_Integer n, const char** a) |
| 104 | { |
| 105 | GeomAbs_JoinType theJoinType = GeomAbs_Arc; |
| 106 | if (n >= 2 && strcmp(a[1], "i") == 0) |
| 107 | theJoinType = GeomAbs_Intersection; |
| 108 | |
| 109 | Standard_Boolean IsOpenResult = Standard_False; |
| 110 | if (n == 3 && strcmp(a[2], "o") == 0) |
| 111 | IsOpenResult = Standard_True; |
| 112 | |
| 113 | MapBiLo.Compute(anExplo, 1, SideOfMat, theJoinType, IsOpenResult); |
| 114 | LinkComputed = Standard_False; |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | //============================================================================ |
| 120 | //function : zone |
| 121 | // construction and display of the proximity zone associated to the |
| 122 | // base elements defined by the edge or the vertex. |
| 123 | //============================================================================ |
| 124 | static Standard_Integer zone(Draw_Interpretor& , Standard_Integer argc , const char** argv) |
| 125 | { |
| 126 | if (argc < 2) return 1; |
| 127 | |
| 128 | TopoDS_Shape S = DBRep::Get (argv[1],TopAbs_EDGE); |
| 129 | if (S.IsNull()) { |
| 130 | S = DBRep::Get (argv[1],TopAbs_VERTEX); |
| 131 | } |
| 132 | |
| 133 | if (!LinkComputed) { |
| 134 | TopoBilo.Perform(anExplo,MapBiLo); |
| 135 | LinkComputed = Standard_True; |
| 136 | } |
| 137 | |
| 138 | Standard_Boolean Reverse; |
| 139 | Handle(MAT_Zone) TheZone = new MAT_Zone(); |
| 140 | |
| 141 | for (TopoBilo.Init(S); TopoBilo.More(); TopoBilo.Next()) { |
| 142 | const Handle(MAT_BasicElt)& BE = TopoBilo.Value(); |
| 143 | TheZone->Perform(BE); |
| 144 | for (Standard_Integer i=1; i <= TheZone->NumberOfArcs(); i++) { |
| 145 | DrawCurve(MapBiLo.GeomBis(TheZone->ArcOnFrontier(i),Reverse).Value(),2); |
| 146 | } |
| 147 | } |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | //========================================================================== |
| 153 | //function : side |
| 154 | // side = left => calculation to the left of the contour. |
| 155 | // side = right => calculation to the right of the contour. |
| 156 | //========================================================================== |
| 157 | |
| 158 | static Standard_Integer side(Draw_Interpretor& , Standard_Integer, const char** argv) |
| 159 | { |
| 160 | if(!strcmp(argv[1],"right")) |
| 161 | SideOfMat = MAT_Right; |
| 162 | else |
| 163 | SideOfMat = MAT_Left; |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | //========================================================================== |
| 169 | //function : result |
| 170 | // Complete display of the calculated map. |
| 171 | //========================================================================== |
| 172 | static Standard_Integer result(Draw_Interpretor& , Standard_Integer, const char**) |
| 173 | { |
| 174 | Standard_Integer i,NbArcs=0; |
| 175 | Standard_Boolean Rev; |
| 176 | |
| 177 | NbArcs = MapBiLo.Graph()->NumberOfArcs(); |
| 178 | |
| 179 | for (i=1; i <= NbArcs;i++) { |
| 180 | DrawCurve(MapBiLo.GeomBis(MapBiLo.Graph()->Arc(i),Rev).Value(),3); |
| 181 | } |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | //========================================================================== |
| 186 | //function : DrawCurve |
| 187 | // Display of curve <aCurve> of Geom2d in a color defined by <Indice>. |
| 188 | // Indice = 1 yellow, |
| 189 | // Indice = 2 blue, |
| 190 | // Indice = 3 red, |
| 191 | // Indice = 4 green. |
| 192 | //========================================================================== |
| 193 | void DrawCurve(const Handle(Geom2d_Curve)& aCurve, |
| 194 | const Standard_Integer Indice) |
| 195 | { |
| 196 | Handle(Standard_Type) type = aCurve->DynamicType(); |
| 197 | Handle(Geom2d_Curve) curve,CurveDraw; |
| 198 | Handle(DrawTrSurf_Curve2d) dr; |
| 199 | Draw_Color Couleur; |
| 200 | |
| 201 | if (type == STANDARD_TYPE(Geom2d_TrimmedCurve)) { |
| 202 | curve = Handle(Geom2d_TrimmedCurve)::DownCast (aCurve)->BasisCurve(); |
| 203 | type = curve->DynamicType(); |
| 204 | if (type == STANDARD_TYPE(Bisector_BisecAna)) { |
| 205 | curve =Handle(Bisector_BisecAna)::DownCast (curve)->Geom2dCurve(); |
| 206 | type = curve->DynamicType(); |
| 207 | } |
| 208 | // PB of representation of semi_infinite curves. |
| 209 | gp_Parab2d gpParabola; |
| 210 | gp_Hypr2d gpHyperbola; |
| 211 | Standard_Real Focus; |
| 212 | Standard_Real Limit = 50000.; |
| 213 | Standard_Real delta = 400; |
| 214 | |
| 215 | // PB of representation of semi_infinite curves. |
| 216 | if (aCurve->LastParameter() == Precision::Infinite()) { |
| 217 | |
| 218 | if (type == STANDARD_TYPE(Geom2d_Parabola)) { |
| 219 | gpParabola = Handle(Geom2d_Parabola)::DownCast(curve)->Parab2d(); |
| 220 | Focus = gpParabola.Focal(); |
| 221 | Standard_Real Val1 = Sqrt(Limit*Focus); |
| 222 | Standard_Real Val2 = Sqrt(Limit*Limit); |
| 223 | delta= (Val1 <= Val2 ? Val1:Val2); |
| 224 | } |
| 225 | else if (type == STANDARD_TYPE(Geom2d_Hyperbola)) { |
| 226 | gpHyperbola = Handle(Geom2d_Hyperbola)::DownCast(curve)->Hypr2d(); |
| 227 | Standard_Real Majr = gpHyperbola.MajorRadius(); |
| 228 | Standard_Real Minr = gpHyperbola.MinorRadius(); |
| 229 | Standard_Real Valu1 = Limit/Majr; |
| 230 | Standard_Real Valu2 = Limit/Minr; |
| 231 | Standard_Real Val1 = Log(Valu1+Sqrt(Valu1*Valu1-1)); |
| 232 | Standard_Real Val2 = Log(Valu2+Sqrt(Valu2*Valu2+1)); |
| 233 | delta = (Val1 <= Val2 ? Val1:Val2); |
| 234 | } |
| 235 | if (aCurve->FirstParameter() == -Precision::Infinite()) |
| 236 | CurveDraw = new Geom2d_TrimmedCurve(aCurve, -delta, delta); |
| 237 | else |
| 238 | CurveDraw = new Geom2d_TrimmedCurve(aCurve, |
| 239 | aCurve->FirstParameter(), |
| 240 | aCurve->FirstParameter() + delta); |
| 241 | } |
| 242 | else { |
| 243 | CurveDraw = aCurve; |
| 244 | } |
| 245 | // end PB. |
| 246 | } |
| 247 | else { |
| 248 | CurveDraw = aCurve; |
| 249 | } |
| 250 | |
| 251 | if (Indice == 1) Couleur = Draw_jaune; |
| 252 | else if (Indice == 2) Couleur = Draw_bleu; |
| 253 | else if (Indice == 3) Couleur = Draw_rouge; |
| 254 | else if (Indice == 4) Couleur = Draw_vert; |
| 255 | |
| 256 | Standard_Integer Discret = 50; |
| 257 | |
| 258 | if (type == STANDARD_TYPE(Geom2d_Circle)) |
| 259 | dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,30,Standard_False); |
| 260 | else if (type == STANDARD_TYPE(Geom2d_Line)) |
| 261 | dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,2,Standard_False); |
| 262 | else |
| 263 | dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,Discret,Standard_False); |
| 264 | |
| 265 | dout << dr; |
| 266 | dout.Flush(); |
| 267 | } |
| 268 | |
| 269 | //========================================================================== |
| 270 | //function BRepTest:: MatCommands |
| 271 | //========================================================================== |
| 272 | |
| 273 | void BRepTest::MatCommands (Draw_Interpretor& theCommands) |
| 274 | { |
| 275 | theCommands.Add("topoload","load face",__FILE__,topoload); |
| 276 | theCommands.Add("drawcont","display current contour",__FILE__,drawcont); |
| 277 | theCommands.Add("mat","computes the mat: mat [a/i [o]]",__FILE__,mat); |
| 278 | theCommands.Add("side","side left/right",__FILE__,side); |
| 279 | theCommands.Add("result","result",__FILE__,result); |
| 280 | theCommands.Add("zone","zone edge or vertex",__FILE__,zone); |
| 281 | } |