| 1 | // Copyright: Matra-Datavision 1995 |
| 2 | // File: BRepToIGES_BRShell.cxx |
| 3 | // Created: Mon Jan 30 11:46:12 1995 |
| 4 | // Author: Marie Jose MARTZ |
| 5 | // <mjm> |
| 6 | //:n3 abv 8 Feb 99: PRO17820: BRepTools::OuterWire() -> ShapeAnalysis::OuterWire |
| 7 | //szv#4 S4163 |
| 8 | |
| 9 | #include <BRepToIGES_BRShell.ixx> |
| 10 | #include <BRepToIGES_BRWire.hxx> |
| 11 | |
| 12 | #include <BRep_Tool.hxx> |
| 13 | #include <BRepTools.hxx> |
| 14 | |
| 15 | #include <gp.hxx> |
| 16 | #include <gp_Trsf.hxx> |
| 17 | |
| 18 | #include <Geom_ConicalSurface.hxx> |
| 19 | #include <Geom_CylindricalSurface.hxx> |
| 20 | #include <Geom_RectangularTrimmedSurface.hxx> |
| 21 | #include <Geom_SphericalSurface.hxx> |
| 22 | #include <Geom_Surface.hxx> |
| 23 | #include <Geom_SurfaceOfRevolution.hxx> |
| 24 | #include <Geom_ToroidalSurface.hxx> |
| 25 | |
| 26 | #include <GeomToIGES_GeomSurface.hxx> |
| 27 | |
| 28 | #include <IGESBasic_Group.hxx> |
| 29 | #include <IGESData_HArray1OfIGESEntity.hxx> |
| 30 | #include <IGESData_IGESEntity.hxx> |
| 31 | |
| 32 | #include <IGESGeom_CurveOnSurface.hxx> |
| 33 | #include <IGESGeom_HArray1OfCurveOnSurface.hxx> |
| 34 | #include <IGESGeom_TrimmedSurface.hxx> |
| 35 | #include <IGESGeom_SurfaceOfRevolution.hxx> |
| 36 | |
| 37 | #include <Interface_Macros.hxx> |
| 38 | |
| 39 | #include <TColStd_HSequenceOfTransient.hxx> |
| 40 | |
| 41 | #include <TopLoc_Location.hxx> |
| 42 | |
| 43 | #include <TopoDS.hxx> |
| 44 | #include <TopoDS_Vertex.hxx> |
| 45 | #include <TopoDS_Edge.hxx> |
| 46 | #include <TopoDS_Face.hxx> |
| 47 | #include <TopoDS_Shell.hxx> |
| 48 | #include <TopoDS_Wire.hxx> |
| 49 | #include <TopoDS_Shape.hxx> |
| 50 | |
| 51 | #include <TopAbs_ShapeEnum.hxx> |
| 52 | #include <TopExp.hxx> |
| 53 | #include <TopExp_Explorer.hxx> |
| 54 | |
| 55 | #include <ShapeAlgo.hxx> |
| 56 | #include <ShapeAlgo_AlgoContainer.hxx> |
| 57 | |
| 58 | #include <Message_ProgressIndicator.hxx> |
| 59 | #include <Transfer_FinderProcess.hxx> |
| 60 | |
| 61 | //============================================================================= |
| 62 | // BRepToIGES_BRShell |
| 63 | //============================================================================= |
| 64 | |
| 65 | BRepToIGES_BRShell::BRepToIGES_BRShell() |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | |
| 70 | //============================================================================= |
| 71 | // BRepToIGES_BRShell |
| 72 | //============================================================================= |
| 73 | |
| 74 | BRepToIGES_BRShell::BRepToIGES_BRShell |
| 75 | (const BRepToIGES_BREntity& BR) |
| 76 | : BRepToIGES_BREntity(BR) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | |
| 81 | //============================================================================= |
| 82 | // TransferShell |
| 83 | //============================================================================= |
| 84 | |
| 85 | Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferShell(const TopoDS_Shape& start) |
| 86 | { |
| 87 | Handle(IGESData_IGESEntity) res; |
| 88 | |
| 89 | if (start.IsNull()) return res; |
| 90 | |
| 91 | if (start.ShapeType() == TopAbs_FACE) { |
| 92 | TopoDS_Face F = TopoDS::Face(start); |
| 93 | res = TransferFace(F); |
| 94 | } |
| 95 | else if (start.ShapeType() == TopAbs_SHELL) { |
| 96 | TopoDS_Shell S = TopoDS::Shell(start); |
| 97 | res = TransferShell(S); |
| 98 | } |
| 99 | else { |
| 100 | // message d`erreur |
| 101 | } |
| 102 | return res; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | //============================================================================= |
| 107 | // TransferFace |
| 108 | // |
| 109 | //============================================================================= |
| 110 | |
| 111 | Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferFace(const TopoDS_Face& start) |
| 112 | { |
| 113 | Handle(IGESData_IGESEntity) res; |
| 114 | |
| 115 | Handle(Message_ProgressIndicator) progress = GetTransferProcess()->GetProgress(); |
| 116 | if ( ! progress.IsNull() ) { |
| 117 | if ( progress->UserBreak() ) return res; |
| 118 | progress->Increment(); |
| 119 | } |
| 120 | |
| 121 | if ( start.IsNull()) { |
| 122 | return res; |
| 123 | } |
| 124 | //Standard_Integer Nb = 0; //szv#4:S4163:12Mar99 unused |
| 125 | Standard_Real Length = 1.; |
| 126 | Handle(IGESData_IGESEntity) ISurf; |
| 127 | |
| 128 | // returns the face surface |
| 129 | // ------------------------ |
| 130 | |
| 131 | Handle(Geom_Surface) Surf = BRep_Tool::Surface(start); |
| 132 | Handle(Geom_Surface) Surf1; |
| 133 | |
| 134 | if (!Surf.IsNull()) { |
| 135 | Standard_Real U1, U2, V1, V2; |
| 136 | // pour limiter les surfaces de base |
| 137 | BRepTools::UVBounds(start, U1, U2, V1, V2); |
| 138 | GeomToIGES_GeomSurface GS; |
| 139 | GS.SetModel(GetModel()); |
| 140 | ISurf = GS.TransferSurface(Surf, U1, U2, V1, V2); |
| 141 | if (ISurf.IsNull()) { |
| 142 | AddWarning (start, "the basic surface is a null entity"); |
| 143 | return res; |
| 144 | } |
| 145 | Length = GS.Length(); |
| 146 | |
| 147 | // modif mjm du 17/07/97 |
| 148 | if (Surf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { |
| 149 | DeclareAndCast(Geom_RectangularTrimmedSurface, rectang, Surf); |
| 150 | Surf1 = rectang->BasisSurface(); |
| 151 | } |
| 152 | else |
| 153 | Surf1 = Surf; |
| 154 | } |
| 155 | |
| 156 | |
| 157 | // returns the wires of the face |
| 158 | // ----------------------------- |
| 159 | |
| 160 | BRepToIGES_BRWire BW(*this); |
| 161 | Standard_Integer Imode = 0; |
| 162 | Standard_Integer Iprefer = 0; |
| 163 | Handle(IGESData_IGESEntity) ICurve2d; |
| 164 | // pour explorer la face , il faut la mettre fORWARD. |
| 165 | TopoDS_Face myface = start; |
| 166 | Standard_Boolean IsReversed = Standard_False; |
| 167 | if (start.Orientation() == TopAbs_REVERSED) { |
| 168 | myface.Reverse(); |
| 169 | IsReversed = Standard_True; |
| 170 | } |
| 171 | |
| 172 | // outer wire |
| 173 | //:n3 TopoDS_Wire Outer = BRepTools::OuterWire(myface); |
| 174 | TopoDS_Wire Outer = ShapeAlgo::AlgoContainer()->OuterWire(myface); //:n3 |
| 175 | Handle(IGESGeom_CurveOnSurface) IOuter = new IGESGeom_CurveOnSurface; |
| 176 | if (!Outer.IsNull()) { |
| 177 | Handle(IGESData_IGESEntity) ICurve3d = |
| 178 | BW.TransferWire(Outer, myface, ICurve2d, Length); |
| 179 | if ((!ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 3; |
| 180 | if ((!ICurve3d.IsNull()) && (ICurve2d.IsNull())) Iprefer = 2; |
| 181 | if ((ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 1; |
| 182 | IOuter -> Init (Imode, ISurf, ICurve2d, ICurve3d, Iprefer); |
| 183 | } |
| 184 | |
| 185 | // inners wires |
| 186 | TopExp_Explorer Ex; |
| 187 | Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); |
| 188 | |
| 189 | for (Ex.Init(myface,TopAbs_WIRE); Ex.More(); Ex.Next()) { |
| 190 | TopoDS_Wire W = TopoDS::Wire(Ex.Current()); |
| 191 | Handle(IGESGeom_CurveOnSurface) Curve = new IGESGeom_CurveOnSurface; |
| 192 | if (W.IsNull()) { |
| 193 | AddWarning(start," an Wire is a null entity"); |
| 194 | } |
| 195 | else if (!W.IsSame(Outer)) { |
| 196 | Handle(IGESData_IGESEntity) ICurve3d = |
| 197 | BW.TransferWire(W, myface, ICurve2d, Length); |
| 198 | if ((!ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 3; |
| 199 | if ((!ICurve3d.IsNull()) && (ICurve2d.IsNull())) Iprefer = 2; |
| 200 | if ((ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 1; |
| 201 | Curve-> Init (Imode, ISurf, ICurve2d, ICurve3d, Iprefer); |
| 202 | if (!Curve.IsNull()) Seq->Append(Curve); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | // all inners edges not in a wire |
| 207 | for (Ex.Init(myface,TopAbs_EDGE,TopAbs_WIRE); Ex.More(); Ex.Next()) { |
| 208 | TopoDS_Edge E = TopoDS::Edge(Ex.Current()); |
| 209 | Handle(IGESGeom_CurveOnSurface) Curve = new IGESGeom_CurveOnSurface; |
| 210 | if (E.IsNull()) { |
| 211 | AddWarning(start," an Edge is a null entity"); |
| 212 | } |
| 213 | else { |
| 214 | Handle(IGESData_IGESEntity) ICurve3d = BW.TransferEdge(E, Standard_False); |
| 215 | Handle(IGESData_IGESEntity) newICurve2d = BW.TransferEdge(E, myface, Length, Standard_False); |
| 216 | if ((!ICurve3d.IsNull()) && (!newICurve2d.IsNull())) Iprefer = 3; |
| 217 | if ((!ICurve3d.IsNull()) && (newICurve2d.IsNull())) Iprefer = 2; |
| 218 | if ((ICurve3d.IsNull()) && (!newICurve2d.IsNull())) Iprefer = 1; |
| 219 | Curve-> Init (Imode, ISurf, newICurve2d, ICurve3d, Iprefer); |
| 220 | if (!Curve.IsNull()) Seq->Append(Curve); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | |
| 225 | Standard_Integer nbent = Seq->Length(); |
| 226 | Handle(IGESGeom_HArray1OfCurveOnSurface) Tab; |
| 227 | if (nbent >=1) { |
| 228 | Tab = new IGESGeom_HArray1OfCurveOnSurface(1,nbent); |
| 229 | for (Standard_Integer itab = 1; itab <= nbent; itab++) { |
| 230 | Handle(IGESGeom_CurveOnSurface) item = GetCasted(IGESGeom_CurveOnSurface, Seq->Value(itab)); |
| 231 | Tab->SetValue(itab,item); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | // returns the TrimmedSurface |
| 236 | // -------------------------- |
| 237 | Standard_Boolean Flag = Standard_True; // pour l`instant |
| 238 | Handle(IGESGeom_TrimmedSurface) TrimmedSurf = new IGESGeom_TrimmedSurface; |
| 239 | TrimmedSurf-> Init (ISurf, Flag, IOuter, Tab); |
| 240 | |
| 241 | res = TrimmedSurf; |
| 242 | if (IsReversed) myface.Reverse(); |
| 243 | |
| 244 | SetShapeResult ( start, res ); |
| 245 | |
| 246 | return res; |
| 247 | } |
| 248 | |
| 249 | |
| 250 | //============================================================================= |
| 251 | // TransferShell |
| 252 | //============================================================================= |
| 253 | |
| 254 | Handle(IGESData_IGESEntity) BRepToIGES_BRShell::TransferShell(const TopoDS_Shell& start) |
| 255 | { |
| 256 | Handle(IGESData_IGESEntity) res; |
| 257 | if ( start.IsNull()) return res; |
| 258 | |
| 259 | TopExp_Explorer Ex; |
| 260 | Handle(IGESBasic_Group) IGroup = new IGESBasic_Group; |
| 261 | Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); |
| 262 | Handle(IGESData_IGESEntity) IFace; |
| 263 | |
| 264 | for (Ex.Init(start,TopAbs_FACE); Ex.More(); Ex.Next()) { |
| 265 | TopoDS_Face F = TopoDS::Face(Ex.Current()); |
| 266 | if (F.IsNull()) { |
| 267 | AddWarning(start," a Face is a null entity"); |
| 268 | } |
| 269 | else { |
| 270 | IFace = TransferFace(F); |
| 271 | if (!IFace.IsNull()) Seq->Append(IFace); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | |
| 276 | Standard_Integer nbfaces = Seq->Length(); |
| 277 | Handle(IGESData_HArray1OfIGESEntity) Tab; |
| 278 | if ( nbfaces >= 1) { |
| 279 | Tab = new IGESData_HArray1OfIGESEntity(1,nbfaces); |
| 280 | for (Standard_Integer itab = 1; itab <= nbfaces; itab++) { |
| 281 | Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab)); |
| 282 | Tab->SetValue(itab,item); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | if (nbfaces == 1) { |
| 287 | res = IFace; |
| 288 | } |
| 289 | else { |
| 290 | IGroup->Init(Tab); |
| 291 | res = IGroup; |
| 292 | } |
| 293 | |
| 294 | SetShapeResult ( start, res ); |
| 295 | |
| 296 | return res; |
| 297 | } |
| 298 | |
| 299 | |
| 300 | |
| 301 | |