| 1 | // Created on: 1996-09-03 |
| 2 | // Created by: Jacques GOUSSARD |
| 3 | // Copyright (c) 1996-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 | |
| 18 | #include <Bnd_Box.hxx> |
| 19 | #include <BRep_Tool.hxx> |
| 20 | #include <BRepAlgoAPI_Cut.hxx> |
| 21 | #include <BRepAlgoAPI_Fuse.hxx> |
| 22 | #include <BRepBndLib.hxx> |
| 23 | #include <BRepFeat.hxx> |
| 24 | #include <BRepFeat_MakePipe.hxx> |
| 25 | #include <Geom_Curve.hxx> |
| 26 | #include <Geom_Line.hxx> |
| 27 | #include <gp_Pnt.hxx> |
| 28 | #include <gp_Pnt2d.hxx> |
| 29 | #include <gp_Vec.hxx> |
| 30 | #include <LocOpe.hxx> |
| 31 | #include <LocOpe_Pipe.hxx> |
| 32 | #include <Standard_ConstructionError.hxx> |
| 33 | #include <TColgp_SequenceOfPnt.hxx> |
| 34 | #include <TopExp.hxx> |
| 35 | #include <TopExp_Explorer.hxx> |
| 36 | #include <TopoDS.hxx> |
| 37 | #include <TopoDS_Edge.hxx> |
| 38 | #include <TopoDS_Face.hxx> |
| 39 | #include <TopoDS_Shape.hxx> |
| 40 | #include <TopoDS_Wire.hxx> |
| 41 | #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx> |
| 42 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
| 43 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
| 44 | #include <TopTools_MapIteratorOfMapOfShape.hxx> |
| 45 | #include <TopTools_MapOfShape.hxx> |
| 46 | |
| 47 | #ifdef OCCT_DEBUG |
| 48 | extern Standard_Boolean BRepFeat_GettraceFEAT(); |
| 49 | #endif |
| 50 | |
| 51 | static void MajMap(const TopoDS_Shape&, // base |
| 52 | LocOpe_Pipe&, |
| 53 | TopTools_DataMapOfShapeListOfShape&, // myMap |
| 54 | TopoDS_Shape&, // myFShape |
| 55 | TopoDS_Shape&); // myLShape |
| 56 | |
| 57 | //======================================================================= |
| 58 | //function : Init |
| 59 | //purpose : |
| 60 | //======================================================================= |
| 61 | |
| 62 | void BRepFeat_MakePipe::Init(const TopoDS_Shape& Sbase, |
| 63 | const TopoDS_Shape& Pbase, |
| 64 | const TopoDS_Face& Skface, |
| 65 | const TopoDS_Wire& Spine, |
| 66 | const Standard_Integer Mode, |
| 67 | const Standard_Boolean Modify) |
| 68 | { |
| 69 | #ifdef OCCT_DEBUG |
| 70 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
| 71 | if (trc) std::cout << "BRepFeat_MakePipe::Init" << std::endl; |
| 72 | #endif |
| 73 | mySbase = Sbase; |
| 74 | BasisShapeValid(); |
| 75 | mySkface = Skface; |
| 76 | SketchFaceValid(); |
| 77 | myPbase = Pbase; |
| 78 | mySlface.Clear(); |
| 79 | mySpine = Spine; |
| 80 | if(Mode == 0) { |
| 81 | myFuse = Standard_False; |
| 82 | myJustFeat = Standard_False; |
| 83 | } |
| 84 | else if(Mode == 1) { |
| 85 | myFuse = Standard_True; |
| 86 | myJustFeat = Standard_False; |
| 87 | } |
| 88 | else if(Mode == 2) { |
| 89 | myFuse = Standard_True; |
| 90 | myJustFeat = Standard_True; |
| 91 | } |
| 92 | else { |
| 93 | } |
| 94 | myModify = Modify; |
| 95 | myJustGluer = Standard_False; |
| 96 | |
| 97 | |
| 98 | //-------------- ifv |
| 99 | //mySkface.Nullify(); |
| 100 | //-------------- ifv |
| 101 | |
| 102 | myShape.Nullify(); |
| 103 | myMap.Clear(); |
| 104 | myFShape.Nullify(); |
| 105 | myLShape.Nullify(); |
| 106 | TopExp_Explorer exp; |
| 107 | for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) { |
| 108 | TopTools_ListOfShape thelist; |
| 109 | myMap.Bind(exp.Current(), thelist); |
| 110 | myMap(exp.Current()).Append(exp.Current()); |
| 111 | } |
| 112 | #ifdef OCCT_DEBUG |
| 113 | if (trc) { |
| 114 | if (myJustFeat) std::cout << " Just Feature" << std::endl; |
| 115 | if (myFuse) std::cout << " Fuse" << std::endl; |
| 116 | if (!myFuse) std::cout << " Cut" << std::endl; |
| 117 | if (!myModify) std::cout << " Modify = 0" << std::endl; |
| 118 | } |
| 119 | #endif |
| 120 | } |
| 121 | |
| 122 | |
| 123 | //======================================================================= |
| 124 | //function : Add |
| 125 | //purpose : add faces of gluing |
| 126 | //======================================================================= |
| 127 | |
| 128 | void BRepFeat_MakePipe::Add(const TopoDS_Edge& E, |
| 129 | const TopoDS_Face& F) |
| 130 | { |
| 131 | #ifdef OCCT_DEBUG |
| 132 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
| 133 | if (trc) std::cout << "BRepFeat_MakePipe::Add(Edge,face)" << std::endl; |
| 134 | #endif |
| 135 | TopExp_Explorer exp; |
| 136 | for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) { |
| 137 | if (exp.Current().IsSame(F)) { |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | if (!exp.More()) { |
| 142 | throw Standard_ConstructionError(); |
| 143 | } |
| 144 | |
| 145 | for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) { |
| 146 | if (exp.Current().IsSame(E)) { |
| 147 | break; |
| 148 | } |
| 149 | } |
| 150 | if (!exp.More()) { |
| 151 | throw Standard_ConstructionError(); |
| 152 | } |
| 153 | |
| 154 | if (!mySlface.IsBound(F)) { |
| 155 | TopTools_ListOfShape thelist1; |
| 156 | mySlface.Bind(F,thelist1); |
| 157 | } |
| 158 | TopTools_ListIteratorOfListOfShape itl(mySlface(F)); |
| 159 | for (; itl.More();itl.Next()) { |
| 160 | if (itl.Value().IsSame(E)) { |
| 161 | break; |
| 162 | } |
| 163 | } |
| 164 | if (!itl.More()) { |
| 165 | mySlface(F).Append(E); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | |
| 170 | //======================================================================= |
| 171 | //function : Perform |
| 172 | //purpose : |
| 173 | //======================================================================= |
| 174 | |
| 175 | void BRepFeat_MakePipe::Perform() |
| 176 | { |
| 177 | #ifdef OCCT_DEBUG |
| 178 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
| 179 | if (trc) std::cout << "BRepFeat_MakePipe::Perform()" << std::endl; |
| 180 | #endif |
| 181 | mySFrom.Nullify(); |
| 182 | ShapeFromValid(); |
| 183 | mySUntil.Nullify(); |
| 184 | ShapeUntilValid(); |
| 185 | myGluedF.Clear(); |
| 186 | myPerfSelection = BRepFeat_NoSelection; |
| 187 | PerfSelectionValid(); |
| 188 | TopoDS_Shape theBase = myPbase; |
| 189 | LocOpe_Pipe thePipe(mySpine,theBase); |
| 190 | TopoDS_Shape VraiPipe = thePipe.Shape(); |
| 191 | MajMap(myPbase,thePipe,myMap,myFShape,myLShape); |
| 192 | myGShape = VraiPipe; |
| 193 | GeneratedShapeValid(); |
| 194 | |
| 195 | GluedFacesValid(); |
| 196 | |
| 197 | if(myGluedF.IsEmpty()) { |
| 198 | if(myFuse == 1) { |
| 199 | BRepAlgoAPI_Fuse f(mySbase, myGShape); |
| 200 | myShape = f.Shape(); |
| 201 | UpdateDescendants(f, myShape, Standard_False); |
| 202 | Done(); |
| 203 | } |
| 204 | else if(myFuse == 0) { |
| 205 | BRepAlgoAPI_Cut c(mySbase, myGShape); |
| 206 | myShape = c.Shape(); |
| 207 | UpdateDescendants(c, myShape, Standard_False); |
| 208 | Done(); |
| 209 | } |
| 210 | else { |
| 211 | myShape = myGShape; |
| 212 | Done(); |
| 213 | } |
| 214 | } |
| 215 | else { |
| 216 | myFShape = thePipe.FirstShape(); |
| 217 | TColgp_SequenceOfPnt spt; |
| 218 | LocOpe::SampleEdges(myFShape,spt); |
| 219 | myCurves = thePipe.Curves(spt); |
| 220 | myBCurve = thePipe.BarycCurve(); |
| 221 | GlobalPerform(); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | |
| 226 | //======================================================================= |
| 227 | //function : Perform |
| 228 | //purpose : till shape Until |
| 229 | //======================================================================= |
| 230 | |
| 231 | void BRepFeat_MakePipe::Perform(const TopoDS_Shape& Until) |
| 232 | { |
| 233 | #ifdef OCCT_DEBUG |
| 234 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
| 235 | if (trc) std::cout << "BRepFeat_MakePipe::Perform(Until)" << std::endl; |
| 236 | #endif |
| 237 | if (Until.IsNull()) { |
| 238 | throw Standard_ConstructionError(); |
| 239 | } |
| 240 | TopExp_Explorer exp(Until, TopAbs_FACE); |
| 241 | if (!exp.More()) { |
| 242 | throw Standard_ConstructionError(); |
| 243 | } |
| 244 | myGluedF.Clear(); |
| 245 | myPerfSelection = BRepFeat_SelectionU; |
| 246 | PerfSelectionValid(); |
| 247 | mySFrom.Nullify(); |
| 248 | ShapeFromValid(); |
| 249 | mySUntil = Until; |
| 250 | TransformShapeFU(1); |
| 251 | ShapeUntilValid(); |
| 252 | LocOpe_Pipe thePipe(mySpine,myPbase); |
| 253 | TopoDS_Shape VraiTuyau = thePipe.Shape(); |
| 254 | MajMap(myPbase,thePipe,myMap,myFShape,myLShape); |
| 255 | myGShape = VraiTuyau; |
| 256 | GeneratedShapeValid(); |
| 257 | |
| 258 | GluedFacesValid(); |
| 259 | |
| 260 | myFShape = thePipe.FirstShape(); |
| 261 | TColgp_SequenceOfPnt spt; |
| 262 | LocOpe::SampleEdges(myFShape,spt); |
| 263 | myCurves = thePipe.Curves(spt); |
| 264 | myBCurve = thePipe.BarycCurve(); |
| 265 | GlobalPerform(); |
| 266 | } |
| 267 | |
| 268 | |
| 269 | //======================================================================= |
| 270 | //function : Perform |
| 271 | //purpose : between From and Until |
| 272 | //======================================================================= |
| 273 | |
| 274 | void BRepFeat_MakePipe::Perform(const TopoDS_Shape& From, |
| 275 | const TopoDS_Shape& Until) |
| 276 | { |
| 277 | #ifdef OCCT_DEBUG |
| 278 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
| 279 | if (trc) std::cout << "BRepFeat_MakePipe::Perform(From,Until)" << std::endl; |
| 280 | #endif |
| 281 | if (From.IsNull() || Until.IsNull()) { |
| 282 | throw Standard_ConstructionError(); |
| 283 | } |
| 284 | if (!mySkface.IsNull()) { |
| 285 | if (From.IsSame(mySkface)) { |
| 286 | Perform(Until); |
| 287 | return; |
| 288 | } |
| 289 | else if (Until.IsSame(mySkface)) { |
| 290 | Perform(From); |
| 291 | return; |
| 292 | } |
| 293 | } |
| 294 | myGluedF.Clear(); |
| 295 | myPerfSelection = BRepFeat_SelectionFU; |
| 296 | PerfSelectionValid(); |
| 297 | TopExp_Explorer exp(From, TopAbs_FACE); |
| 298 | if (!exp.More()) { |
| 299 | throw Standard_ConstructionError(); |
| 300 | } |
| 301 | exp.Init(Until, TopAbs_FACE); |
| 302 | if (!exp.More()) { |
| 303 | throw Standard_ConstructionError(); |
| 304 | } |
| 305 | mySFrom = From; |
| 306 | TransformShapeFU(0); |
| 307 | ShapeFromValid(); |
| 308 | mySUntil = Until; |
| 309 | TransformShapeFU(1); |
| 310 | ShapeUntilValid(); |
| 311 | LocOpe_Pipe thePipe(mySpine,myPbase); |
| 312 | TopoDS_Shape VraiTuyau = thePipe.Shape(); |
| 313 | MajMap(myPbase,thePipe,myMap,myFShape,myLShape); |
| 314 | myGShape = VraiTuyau; |
| 315 | GeneratedShapeValid(); |
| 316 | |
| 317 | // mySbase, myPbase, mySlface, thePipe, myGluedF); |
| 318 | GluedFacesValid(); |
| 319 | |
| 320 | myFShape = thePipe.FirstShape(); |
| 321 | TColgp_SequenceOfPnt spt; |
| 322 | LocOpe::SampleEdges(myFShape,spt); |
| 323 | myCurves = thePipe.Curves(spt); |
| 324 | myBCurve = thePipe.BarycCurve(); |
| 325 | GlobalPerform(); |
| 326 | } |
| 327 | |
| 328 | |
| 329 | //======================================================================= |
| 330 | //function : Curves |
| 331 | //purpose : curves parallel to the generating wire of the pipe |
| 332 | //======================================================================= |
| 333 | |
| 334 | void BRepFeat_MakePipe::Curves(TColGeom_SequenceOfCurve& scur) |
| 335 | { |
| 336 | scur = myCurves; |
| 337 | } |
| 338 | |
| 339 | //======================================================================= |
| 340 | //function : BarycCurve |
| 341 | //purpose : pass through the center of mass |
| 342 | //======================================================================= |
| 343 | |
| 344 | Handle(Geom_Curve) BRepFeat_MakePipe::BarycCurve() |
| 345 | { |
| 346 | return myBCurve; |
| 347 | } |
| 348 | |
| 349 | //======================================================================= |
| 350 | //function : MajMap |
| 351 | //purpose : management of descendants |
| 352 | //======================================================================= |
| 353 | |
| 354 | static void MajMap(const TopoDS_Shape& theB, |
| 355 | LocOpe_Pipe& theP, |
| 356 | TopTools_DataMapOfShapeListOfShape& theMap, // myMap |
| 357 | TopoDS_Shape& theFShape, // myFShape |
| 358 | TopoDS_Shape& theLShape) // myLShape |
| 359 | { |
| 360 | TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE); |
| 361 | if (exp.More()) { |
| 362 | theFShape = exp.Current(); |
| 363 | TopTools_ListOfShape thelist2; |
| 364 | theMap.Bind(theFShape, thelist2); |
| 365 | for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) { |
| 366 | theMap(theFShape).Append(exp.Current()); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | exp.Init(theP.LastShape(),TopAbs_WIRE); |
| 371 | if (exp.More()) { |
| 372 | theLShape = exp.Current(); |
| 373 | TopTools_ListOfShape thelist3; |
| 374 | theMap.Bind(theLShape, thelist3); |
| 375 | for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) { |
| 376 | theMap(theLShape).Append(exp.Current()); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) { |
| 381 | if (!theMap.IsBound(exp.Current())) { |
| 382 | TopTools_ListOfShape thelist4; |
| 383 | theMap.Bind(exp.Current(), thelist4); |
| 384 | theMap(exp.Current()) = theP.Shapes(exp.Current()); |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |