Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2002-05-16 |
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> | |
21 | #include <DrawTrSurf.hxx> | |
22 | #include <AIS_InteractiveContext.hxx> | |
23 | #include <ViewerTest.hxx> | |
24 | #include <AIS_Shape.hxx> | |
25 | #include <TopoDS_Shape.hxx> | |
26 | ||
7fd59977 | 27 | #include <gp_Ax2.hxx> |
28 | #include <gp_Circ.hxx> | |
29 | #include <gp_Pln.hxx> | |
30 | #include <BRep_Builder.hxx> | |
31 | #include <BRepBuilderAPI_MakeWire.hxx> | |
32 | #include <BRepBuilderAPI_MakeEdge.hxx> | |
33 | #include <BRepBuilderAPI_MakeFace.hxx> | |
34 | #include <BRepCheck_Analyzer.hxx> | |
35 | #include <BRepGProp.hxx> | |
36 | #include <BRepOffsetAPI_MakePipeShell.hxx> | |
37 | #include <GC_MakeArcOfCircle.hxx> | |
543a9964 | 38 | #include <Geom_TrimmedCurve.hxx> |
7fd59977 | 39 | #include <Geom_Plane.hxx> |
40 | #include <Law_Linear.hxx> | |
41 | #include <TopoDS.hxx> | |
42 | #include <TopoDS_Shell.hxx> | |
43 | #include <TopoDS_Face.hxx> | |
44 | #include <TopoDS_Solid.hxx> | |
45 | #include <TopoDS_Edge.hxx> | |
46 | #include <TopoDS_Wire.hxx> | |
47 | #include <TopExp_Explorer.hxx> | |
48 | #include <GProp_GProps.hxx> | |
49 | #include <Standard_ErrorHandler.hxx> | |
50 | ||
51 | //======================================================================= | |
52 | //function : OCC332 | |
53 | //purpose : | |
54 | //======================================================================= | |
55 | static Standard_Integer OCC332bug (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
56 | { | |
57 | // Used to Display Geometry or Topolgy | |
58 | char name[255]; | |
7fd59977 | 59 | Standard_Boolean check = Standard_True; |
60 | ||
61 | // Set default arguments | |
62 | double wall_thickness = 10.0; | |
63 | double dia1 = 80.0; | |
64 | double dia2 = 100.0; | |
65 | double length = 400.0; | |
66 | double major_radius = 280.0; | |
67 | ||
68 | // Convert arguments | |
91322f44 | 69 | if (argc>1) wall_thickness = Draw::Atof(argv[1]); |
70 | if (argc>2) dia1 = Draw::Atof(argv[2]); | |
71 | if (argc>3) dia2 = Draw::Atof(argv[3]); | |
72 | if (argc>4) major_radius = Draw::Atof(argv[4]); | |
73 | if (argc>5) length = Draw::Atof(argv[5]); | |
7fd59977 | 74 | double bend_angle = length/major_radius; |
7fd59977 | 75 | |
76 | //if ((bend_angle >= M_PI)) { | |
c6541a0c | 77 | if ((bend_angle >= M_PI)) { |
586db386 | 78 | di << "The arguments are invalid.\n"; |
6a0964c2 | 79 | return 1; |
7fd59977 | 80 | } |
586db386 | 81 | di << "creating the shape for a bent tube\n"; |
7fd59977 | 82 | |
83 | double radius_l = dia1/2.0; | |
84 | double radius_r = dia2/2.0; | |
85 | ||
86 | // SUPPORT: | |
87 | // 1. There is no need to normalize the direction - it's done automatically | |
88 | //gp_Ax2 origin(gp_Pnt(5000.0,-300.0, 1000.0), | |
89 | //gp_Dir(0.0, -1.0/sqrt(2.0), -1.0/sqrt(2.0))); | |
90 | gp_Ax2 origin(gp_Pnt(5000.0,-300.0,1000.0),gp_Dir(0.0,-1.0,-1.0)); | |
91 | ||
92 | TopoDS_Face myFace; | |
93 | TopoDS_Shape myShape, gasSolid; | |
94 | TopoDS_Solid wallSolid; | |
95 | ||
96 | // Construct a circle for the first face, on the xy-plane at the origin | |
97 | gp_Pln circ1Plane(origin.Location(), origin.Direction()); | |
98 | gp_Circ faceCircle(origin, radius_l); | |
99 | gp_Circ outFaceCircle(origin, radius_l+wall_thickness); | |
100 | ||
101 | // Construct center for a circle to be the spine of | |
102 | // revolution, on the xz-plane at x=major_radius | |
103 | gp_Pnt circ_center = origin.Location().Translated(major_radius*origin.XDirection()); | |
104 | ||
105 | // This point will be the center of the second face. | |
106 | // SUPPORT: | |
107 | // - There is no need in this point - we'll use angle instead. | |
108 | //gp_Pnt endPoint = origin.Location(); | |
109 | //endPoint.Translate(major_radius*(1.0-cos(bend_angle))*origin.XDirection()) ; | |
110 | //endPoint.Translate((-major_radius*sin(bend_angle))*origin.Direction()); | |
111 | ||
112 | // Construct the plane for the second face to sit on. | |
113 | // SUPPORT: | |
114 | // - It is better to use rotation instead of explicit calculations | |
115 | //gp_Pln circ2Plane = gce_MakePln(circ_center, endPoint, | |
116 | // endPoint.Translated(major_radius*origin.YDirection()) | |
117 | // ).Value(); | |
118 | gp_Ax1 circ_axis(circ_center,origin.YDirection()); | |
119 | gp_Pln circ2Plane = circ1Plane.Rotated(circ_axis,bend_angle); | |
120 | ||
121 | // The circle used for the spine. | |
122 | // SUPPORT: | |
123 | // - Use direction (-X) instead of (X) to obtain correct right-handed system. | |
124 | // It is very important to maintain correct orientation between spine | |
125 | // and circles axes. | |
126 | //gp_Ax2 spineAxis(circ_center, origin.YDirection(), origin.XDirection()); | |
127 | gp_Ax2 spineAxis(circ_center, origin.YDirection(), -origin.XDirection()); | |
128 | gp_Circ circle(spineAxis, major_radius); | |
129 | ||
130 | // SUPPORT: | |
131 | // - There is no need to create 2nd circles - they will be created by MakePipeShell. | |
132 | //gp_Ax2 circ2axis(endPoint, circ2Plane.Axis().Direction(), origin.YDirection()); | |
133 | //gp_Circ faceCircle2(circ2axis,radius_r); | |
134 | //gp_Circ outFaceCircle2(circ2axis,radius_r+wall_thickness); | |
135 | ||
136 | TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(faceCircle); | |
137 | TopoDS_Wire Wire1_ = BRepBuilderAPI_MakeWire(E1).Wire(); | |
138 | ||
139 | // Create the face at the near end for the wall solid, an annular ring. | |
140 | TopoDS_Edge Eout1 = BRepBuilderAPI_MakeEdge(outFaceCircle); | |
141 | TopoDS_Wire outerWire1_ = BRepBuilderAPI_MakeWire(Eout1).Wire(); | |
142 | ||
143 | // SUPPORT: | |
144 | // - There is no need to create 2nd circles - | |
145 | // they will be created by MakePipeShell | |
146 | //TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(faceCircle2); | |
147 | //TopoDS_Wire Wire2_ = BRepBuilderAPI_MakeWire(E2).Wire(); | |
148 | ||
149 | // Create the face at the far end for the wall solid, an annular ring. | |
150 | // SUPPORT: | |
151 | // - There is no need to create 2nd circles - | |
152 | // they will be created by MakePipeShell | |
153 | //TopoDS_Edge Eout2 = BRepBuilderAPI_MakeEdge(outFaceCircle2); | |
154 | //TopoDS_Wire outerWire2_ = BRepBuilderAPI_MakeWire(Eout2).Wire(); | |
155 | ||
156 | // SUPPORT: | |
157 | // - It is better to use bend angle calculated above | |
158 | //Handle(Geom_Curve) SpineCurve = GC_MakeArcOfCircle(circle, | |
159 | // endPoint, | |
160 | // origin.Location(), | |
161 | // Standard_True).Value(); | |
5b111128 | 162 | Handle(Geom_Curve) SpineCurve (GC_MakeArcOfCircle (circle, 0.0, bend_angle, Standard_True).Value()); |
7fd59977 | 163 | |
164 | // SUPPORT: | |
165 | // - Use correct formula for scaling laws | |
166 | Handle(Law_Linear) myLaw1 = new Law_Linear(); | |
167 | Handle(Law_Linear) myLaw2 = new Law_Linear(); | |
168 | //if ((radius_r - radius_l) < Precision::Confusion()) | |
169 | //{ | |
170 | //myLaw1->Set(SpineCurve->FirstParameter(), 1.0, | |
171 | //SpineCurve->LastParameter(), 1.0); | |
172 | //myLaw2->Set(SpineCurve->FirstParameter(), 1.0, | |
173 | //SpineCurve->LastParameter(), 1.0); | |
174 | //} | |
175 | //else | |
176 | //{ | |
177 | //myLaw1->Set(SpineCurve->FirstParameter(), radius_r/(radius_r-radius_l), | |
178 | //SpineCurve->LastParameter(), 1.0); | |
179 | //myLaw2->Set(SpineCurve->FirstParameter(), (radius_r+wall_thickness)/(radius_r-radius_l), | |
180 | //SpineCurve->LastParameter(), 1.0); | |
181 | //} | |
182 | myLaw1->Set(SpineCurve->FirstParameter(),1.0, | |
183 | SpineCurve->LastParameter(),radius_r/radius_l); | |
184 | myLaw2->Set(SpineCurve->FirstParameter(),1.0, | |
185 | SpineCurve->LastParameter(),(radius_r+wall_thickness)/(radius_l+wall_thickness)); | |
186 | ||
187 | BRepBuilderAPI_MakeFace mkFace; | |
188 | ||
189 | BRepBuilderAPI_MakeEdge mkEdge; | |
190 | ||
191 | mkEdge.Init(SpineCurve); | |
192 | if (!mkEdge.IsDone()) return 0; | |
193 | TopoDS_Wire SpineWire = BRepBuilderAPI_MakeWire(mkEdge.Edge()).Wire(); | |
194 | ||
91322f44 | 195 | Sprintf (name,"SpineWire"); |
7fd59977 | 196 | DBRep::Set(name,SpineWire); |
197 | ||
91322f44 | 198 | Sprintf (name,"Wire1_"); |
7fd59977 | 199 | DBRep::Set(name,Wire1_); |
200 | ||
91322f44 | 201 | Sprintf (name,"outerWire1_"); |
7fd59977 | 202 | DBRep::Set(name,outerWire1_); |
203 | ||
204 | // SUPPORT: | |
205 | // - There is no need to create 2nd circles | |
91322f44 | 206 | //Sprintf (name,"Wire2_"); |
7fd59977 | 207 | //DBRep::Set(name,Wire2_); |
91322f44 | 208 | //Sprintf (name,"outerWire2_"); |
7fd59977 | 209 | //DBRep::Set(name,outerWire2_); |
210 | ||
211 | di.Eval("fit"); | |
212 | ||
213 | // SUPPORT: | |
214 | // - There is no need in these vertices | |
215 | //TopoDS_Vertex Location1, Location2; | |
216 | //TopExp::Vertices(SpineWire, Location1, Location2); | |
217 | ||
218 | // Make inner pipe shell | |
219 | BRepOffsetAPI_MakePipeShell mkPipe1(SpineWire); | |
220 | mkPipe1.SetTolerance(1.0e-8,1.0e-8,1.0e-6); | |
221 | //mkPipe1.SetTransitionMode(BRepBuilderAPI_Transformed); // Default mode !! | |
222 | mkPipe1.SetLaw(Wire1_, myLaw1/*, Location2*/, Standard_False, Standard_False); | |
223 | mkPipe1.Build(); | |
224 | if (!mkPipe1.IsDone()) return 0; | |
225 | ||
226 | // Make outer pipe shell | |
227 | BRepOffsetAPI_MakePipeShell mkPipe2(SpineWire); | |
228 | mkPipe2.SetTolerance(1.0e-8,1.0e-8,1.0e-6); | |
229 | //mkPipe2.SetTransitionMode(BRepBuilderAPI_Transformed); // Default mode !! | |
230 | mkPipe2.SetLaw(outerWire1_, myLaw2/*, Location2*/, Standard_False, Standard_False); | |
231 | mkPipe2.Build(); | |
232 | if (!mkPipe2.IsDone()) return 0; | |
233 | ||
234 | // Make face for first opening | |
235 | Handle(Geom_Plane) Plane1 = new Geom_Plane(circ1Plane); | |
1c72dff6 | 236 | mkFace.Init(Plane1,Standard_False,Precision::Confusion()); |
7fd59977 | 237 | // SUPPORT: |
238 | // - Use wires created by MakePipeShell | |
239 | //mkFace.Add(TopoDS::Wire(outerWire1_)); | |
240 | //mkFace.Add(TopoDS::Wire(Wire1_.Reversed())); | |
241 | mkFace.Add(TopoDS::Wire(mkPipe2.FirstShape())); | |
242 | mkFace.Add(TopoDS::Wire(mkPipe1.FirstShape().Reversed())); | |
243 | if (!mkFace.IsDone()) return 0; | |
244 | TopoDS_Face Face1 = mkFace.Face(); | |
245 | ||
246 | // Make face for second opening | |
247 | Handle(Geom_Plane) Plane2 = new Geom_Plane(circ2Plane); | |
1c72dff6 | 248 | mkFace.Init(Plane2,Standard_False,Precision::Confusion()); |
7fd59977 | 249 | // SUPPORT: |
250 | // - Use wires created by MakePipeShell | |
251 | //mkFace.Add(TopoDS::Wire(outerWire2_)); | |
252 | //mkFace.Add(TopoDS::Wire(Wire2_.Reversed())); | |
253 | mkFace.Add(TopoDS::Wire(mkPipe2.LastShape())); | |
254 | mkFace.Add(TopoDS::Wire(mkPipe1.LastShape().Reversed())); | |
255 | if (!mkFace.IsDone()) return 0; | |
256 | TopoDS_Face Face2 = mkFace.Face(); | |
257 | ||
258 | // Make tube | |
259 | TopoDS_Shell TubeShell; | |
260 | BRep_Builder B; | |
261 | B.MakeShell(TubeShell); | |
262 | TopExp_Explorer getFaces; | |
263 | TopoDS_Face test_face; | |
264 | getFaces.Init(mkPipe1.Shape(), TopAbs_FACE); | |
265 | // SUPPORT: | |
266 | // - In our case there should be only 1 pipe face | |
267 | //while (getFaces.More()) | |
268 | // { | |
269 | // test_face = TopoDS::Face(getFaces.Current()); | |
270 | // Handle(Geom_Surface) S = BRep_Tool::Surface(test_face); | |
271 | // GeomLib_IsPlanarSurface IsPl(S); | |
272 | // if (!IsPl.IsPlanar()) { | |
273 | // B.Add(TubeShell,getFaces.Current().Reversed()); | |
274 | // } | |
275 | // getFaces.Next(); | |
276 | // } | |
277 | if (getFaces.More()) | |
278 | B.Add(TubeShell,getFaces.Current().Reversed()); | |
279 | ||
280 | // Grab the gas solid now that we've extracted the faces. | |
281 | mkPipe1.MakeSolid(); | |
282 | gasSolid = mkPipe1.Shape(); | |
283 | ||
91322f44 | 284 | Sprintf (name,"gasSolid_"); |
7fd59977 | 285 | DBRep::Set(name,gasSolid); |
286 | ||
287 | //getFaces.Clear(); | |
288 | getFaces.Init(mkPipe2.Shape(), TopAbs_FACE); | |
289 | // SUPPORT: | |
290 | // - In our case there should be only 1 pipe face | |
291 | //while (getFaces.More()) | |
292 | // { | |
293 | // B.Add(TubeShell,getFaces.Current()); | |
294 | // getFaces.Next(); | |
295 | // } | |
296 | if (getFaces.More()) | |
297 | B.Add(TubeShell,getFaces.Current()); | |
298 | ||
299 | B.Add(TubeShell,Face1.Reversed()); | |
300 | B.Add(TubeShell,Face2); | |
ab860031 | 301 | TubeShell.Closed (BRep_Tool::IsClosed (TubeShell)); |
7fd59977 | 302 | |
303 | B.MakeSolid(wallSolid); | |
304 | B.Add(wallSolid,TubeShell); | |
305 | ||
91322f44 | 306 | Sprintf (name,"wallSolid_"); |
7fd59977 | 307 | DBRep::Set(name,wallSolid); |
308 | ||
309 | // Now calculated the volume of the outside tube. | |
310 | GProp_GProps gprops; | |
311 | BRepGProp::VolumeProperties(wallSolid, gprops); | |
312 | di << "The wallSolid's volume is: " << gprops.Mass() << "\n"; | |
313 | ||
314 | if (check) { | |
315 | if (!(BRepCheck_Analyzer(wallSolid).IsValid())) | |
586db386 | 316 | di << "The TopoDS_Solid was checked, and it was invalid!\n"; |
7fd59977 | 317 | else |
586db386 | 318 | di << "The TopoDS_Solid was checked, and it was valid.\n"; |
7fd59977 | 319 | if (!wallSolid.Closed()) |
586db386 | 320 | di << "The TopoDS_Solid is not closed!\n"; |
7fd59977 | 321 | else |
586db386 | 322 | di << "The TopoDS_Solid is closed.\n"; |
7fd59977 | 323 | if (!wallSolid.Checked()) |
586db386 | 324 | di << "The TopoDS_Solid is not checked!\n"; |
7fd59977 | 325 | else |
586db386 | 326 | di << "The TopoDS_Solid has been checked.\n"; |
7fd59977 | 327 | if (wallSolid.Infinite()) |
586db386 | 328 | di << "The TopoDS_Solid is infinite!\n"; |
7fd59977 | 329 | else |
586db386 | 330 | di << "The TopoDS_Solid is finite.\n"; |
7fd59977 | 331 | } |
332 | ||
333 | di << "The result is a "; | |
334 | // Check to see if we have a solid | |
335 | switch (wallSolid.ShapeType()) { | |
336 | case (TopAbs_COMPOUND): | |
586db386 | 337 | di << "TopAbs_COMPOUND\n"; |
7fd59977 | 338 | break; |
339 | case (TopAbs_COMPSOLID): | |
586db386 | 340 | di << "TopAbs_COMPSOLID\n"; |
7fd59977 | 341 | break; |
342 | case (TopAbs_SOLID): | |
586db386 | 343 | di << "TopAbs_SOLID\n"; |
7fd59977 | 344 | break; |
345 | case (TopAbs_SHELL): | |
586db386 | 346 | di << "TopAbs_SHELL\n"; |
7fd59977 | 347 | break; |
348 | case (TopAbs_FACE): | |
586db386 | 349 | di << "TopAbs_FACE\n"; |
7fd59977 | 350 | break; |
351 | case (TopAbs_WIRE): | |
586db386 | 352 | di << "TopAbs_WIRE\n"; |
7fd59977 | 353 | break; |
354 | case (TopAbs_EDGE): | |
586db386 | 355 | di << "TopAbs_EDGE\n"; |
7fd59977 | 356 | break; |
357 | case (TopAbs_VERTEX): | |
586db386 | 358 | di << "TopAbs_VERTEX\n"; |
7fd59977 | 359 | break; |
360 | case (TopAbs_SHAPE): | |
586db386 | 361 | di << "TopAbs_SHAPE\n"; |
7fd59977 | 362 | } |
363 | di << "Can we turn it into a solid? "; | |
364 | try { | |
365 | OCC_CATCH_SIGNALS | |
586db386 | 366 | di << " yes\n"; |
7fd59977 | 367 | } |
368 | catch (Standard_TypeMismatch) { | |
586db386 | 369 | di << " no\n"; |
7fd59977 | 370 | } |
371 | ||
372 | getFaces.Clear(); | |
373 | getFaces.Init(wallSolid, TopAbs_FACE); | |
374 | int i =0; | |
375 | while (getFaces.More()) | |
376 | { | |
377 | i++; | |
91322f44 | 378 | Sprintf(name,"Face%d",i); |
7fd59977 | 379 | di << "Face named " << name << "\n"; |
380 | DBRep::Set(name,getFaces.Current()); | |
381 | getFaces.Next(); | |
382 | } | |
383 | ||
384 | return 0; | |
385 | } | |
386 | ||
387 | #include <gce_MakePln.hxx> | |
388 | #include <TopExp.hxx> | |
389 | #include <BRepOffsetAPI_Sewing.hxx> | |
390 | #include <BRepAlgoAPI_Fuse.hxx> | |
391 | ///////#else | |
392 | ///////#include <BRepAlgo_Fuse.hxx> | |
393 | ///////#include <BRepAlgoAPI_Fuse.hxx> | |
394 | #include <BRepAlgo_Fuse.hxx> | |
395 | ||
396 | //======================================================================= | |
397 | //function : OCC544 | |
398 | //purpose : | |
399 | //======================================================================= | |
400 | static Standard_Integer OCC544 (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
401 | { | |
402 | if(argc > 7) { | |
586db386 | 403 | di << "Usage : " << argv[0] << " [[[[[wT [[[[d1 [[[d2 [[R [length [BRepAlgoAPI/BRepAlgo = 1/0]]]]]]\n"; |
7fd59977 | 404 | return 1; |
405 | } | |
406 | Standard_Boolean IsBRepAlgoAPI = Standard_True; | |
407 | if (argc == 7) { | |
91322f44 | 408 | Standard_Integer IsB = Draw::Atoi(argv[6]); |
7fd59977 | 409 | if (IsB != 1) { |
410 | IsBRepAlgoAPI = Standard_False; | |
411 | #if ! defined(BRepAlgo_def01) | |
586db386 | 412 | // di << "Error: There is not BRepAlgo_Fuse class\n"; |
7fd59977 | 413 | // return 1; |
414 | #endif | |
415 | } | |
416 | } | |
417 | ||
418 | // Used to Display Geometry or Topolgy | |
419 | char name[255]; | |
7fd59977 | 420 | Standard_Boolean check = Standard_True; |
421 | ||
422 | // Set default arguments | |
423 | double radius_l = 20.0; | |
424 | double radius_r = 80.0; | |
425 | // mkv 15.07.03 double bend_angle = M_PI/2.0; | |
c6541a0c | 426 | double bend_angle = M_PI/2.0; |
7fd59977 | 427 | |
428 | double major_rad = 280.0; | |
429 | double wall_thickness = 10.0; | |
430 | ||
431 | ||
432 | // Convert arguments | |
91322f44 | 433 | if (argc>1) radius_l = Draw::Atof(argv[1]); |
434 | if (argc>2) radius_r = Draw::Atof(argv[2]); | |
435 | if (argc>3) bend_angle = Draw::Atof(argv[3]); | |
436 | if (argc>4) major_rad = Draw::Atof(argv[4]); | |
437 | if (argc>5) wall_thickness = Draw::Atof(argv[5]); | |
7fd59977 | 438 | |
439 | // mkv 15.07.03 if ((bend_angle >= 2.0*M_PI)) { | |
c6541a0c | 440 | if ((bend_angle >= 2.0*M_PI)) { |
586db386 | 441 | di << "The arguments are invalid.\n"; |
6a0964c2 | 442 | return 1; |
7fd59977 | 443 | } |
586db386 | 444 | di << "creating the shape for a bent tube\n"; |
7fd59977 | 445 | |
446 | gp_Ax2 origin(gp_Pnt(500.0,-300.0, 100.0), | |
447 | gp_Dir(0.0, -1.0/sqrt(2.0), -1.0/sqrt(2.0))); | |
448 | ||
449 | TopoDS_Face firstFace, lastFace; | |
450 | TopoDS_Solid wallSolid, myShape; | |
451 | // Construct a circle for the first face, on the xy-plane at the origin | |
452 | gp_Pln circ1Plane(origin.Location(), origin.Direction()); | |
453 | gp_Circ faceCircle(origin, radius_l); | |
454 | gp_Circ outFaceCircle(origin, radius_l+wall_thickness); | |
455 | ||
456 | // Construct center for a circle to be the spine of | |
457 | // revolution, on the xz-plane at x=major_rad | |
458 | gp_Pnt circ_center = origin.Location().Translated( | |
459 | major_rad*origin.XDirection() | |
460 | ); | |
461 | ||
462 | // This point will be the center of the second face. | |
463 | gp_Pnt endPoint = origin.Location(); | |
464 | endPoint.Translate(major_rad*(1.0-cos(bend_angle))*origin.XDirection()) ; | |
465 | endPoint.Translate((-major_rad*sin(bend_angle))*origin.Direction()); | |
466 | ||
467 | // Construct the plane for the second face to sit on. | |
468 | gp_Pln circ2Plane = gce_MakePln(circ_center, endPoint, | |
469 | endPoint.Translated(major_rad*origin.YDirection()) | |
470 | ).Value(); | |
471 | ||
472 | // The circle used for the spine. | |
473 | gp_Ax2 spineAxis(circ_center, origin.YDirection(), origin.XDirection()); | |
474 | gp_Circ circle(spineAxis, major_rad); | |
475 | ||
476 | gp_Ax2 circ2axis(endPoint, circ2Plane.Axis().Direction(), origin.YDirection()); | |
477 | gp_Circ faceCircle2(circ2axis,radius_r); | |
478 | gp_Circ outFaceCircle2(circ2axis,radius_r+wall_thickness); | |
479 | ||
c6541a0c D |
480 | TopoDS_Edge E1_1 = BRepBuilderAPI_MakeEdge(faceCircle, 0, M_PI); |
481 | TopoDS_Edge E1_2 = BRepBuilderAPI_MakeEdge(faceCircle, M_PI, 2.*M_PI); | |
7fd59977 | 482 | TopoDS_Wire Wire1_ = BRepBuilderAPI_MakeWire(E1_1, E1_2); |
483 | ||
484 | // Create the face at the near end for the wall solid, an annular ring. | |
c6541a0c D |
485 | TopoDS_Edge Eout1_1 = BRepBuilderAPI_MakeEdge(outFaceCircle, 0, M_PI); |
486 | TopoDS_Edge Eout1_2 = BRepBuilderAPI_MakeEdge(outFaceCircle, M_PI, 2.*M_PI); | |
7fd59977 | 487 | TopoDS_Wire outerWire1_ = BRepBuilderAPI_MakeWire(Eout1_1, Eout1_2); |
488 | ||
c6541a0c D |
489 | TopoDS_Edge E2_1 = BRepBuilderAPI_MakeEdge(faceCircle2, 0, M_PI); |
490 | TopoDS_Edge E2_2 = BRepBuilderAPI_MakeEdge(faceCircle2, M_PI, 2.*M_PI); | |
7fd59977 | 491 | TopoDS_Wire Wire2_ = BRepBuilderAPI_MakeWire(E2_1, E2_2); |
492 | ||
493 | // Create the face at the far end for the wall solid, an annular ring. | |
c6541a0c D |
494 | TopoDS_Edge Eout2_1 = BRepBuilderAPI_MakeEdge(outFaceCircle2, 0, M_PI); |
495 | TopoDS_Edge Eout2_2 = BRepBuilderAPI_MakeEdge(outFaceCircle2, M_PI, 2.*M_PI); | |
7fd59977 | 496 | TopoDS_Wire outerWire2_ = BRepBuilderAPI_MakeWire(Eout2_1, Eout2_2); |
497 | ||
498 | BRepBuilderAPI_MakeFace mkFace; | |
499 | ||
5b111128 | 500 | Handle(Geom_Curve) SpineCurve (GC_MakeArcOfCircle (circle, endPoint, origin.Location(), Standard_True).Value()); |
7fd59977 | 501 | Handle(Law_Linear) myLaw = new Law_Linear(); |
502 | Handle(Law_Linear) myLaw2 = new Law_Linear(); | |
503 | ||
504 | myLaw->Set(SpineCurve->FirstParameter(), | |
505 | radius_r/radius_l, | |
506 | SpineCurve->LastParameter(), | |
507 | 1.0); | |
508 | ||
509 | myLaw2->Set(SpineCurve->FirstParameter(), | |
510 | (radius_r+wall_thickness)/(radius_l+wall_thickness), | |
511 | SpineCurve->LastParameter(), | |
512 | 1.0); | |
513 | ||
514 | di << "SpineCurve->FirstParameter() is " << SpineCurve->FirstParameter() << "\n"; | |
515 | di << "SpineCurve->LastParameter() is " << SpineCurve->LastParameter() << "\n"; | |
516 | di << "Law1 Value at FirstParameter() is " << myLaw->Value(SpineCurve->FirstParameter()) << "\n"; | |
517 | di << "Law1 Value at LastParameter() is " << myLaw->Value(SpineCurve->LastParameter()) << "\n"; | |
518 | di << "radius_r / radius_l is " << radius_r/radius_l << "\n"; | |
519 | ||
520 | BRepBuilderAPI_MakeEdge mkEdge; | |
521 | ||
522 | mkEdge.Init(SpineCurve); | |
6a0964c2 | 523 | if (!mkEdge.IsDone()) |
524 | return 1; | |
7fd59977 | 525 | TopoDS_Wire SpineWire = BRepBuilderAPI_MakeWire(mkEdge.Edge()).Wire(); |
526 | ||
91322f44 | 527 | Sprintf (name,"SpineWire"); |
7fd59977 | 528 | DBRep::Set(name,SpineWire); |
529 | ||
91322f44 | 530 | Sprintf (name,"Wire1_"); |
7fd59977 | 531 | DBRep::Set(name,Wire1_); |
532 | ||
91322f44 | 533 | Sprintf (name,"outerWire1_"); |
7fd59977 | 534 | DBRep::Set(name,outerWire1_); |
535 | ||
91322f44 | 536 | Sprintf (name,"Wire2_"); |
7fd59977 | 537 | DBRep::Set(name,Wire2_); |
538 | ||
91322f44 | 539 | Sprintf (name,"outerWire2_"); |
7fd59977 | 540 | DBRep::Set(name,outerWire2_); |
541 | ||
542 | di.Eval("fit"); | |
543 | ||
544 | TopoDS_Vertex Location1, Location2; | |
545 | ||
546 | TopExp::Vertices(SpineWire, Location2, Location1); | |
547 | ||
91322f44 | 548 | Sprintf (name,"Location1"); |
7fd59977 | 549 | DBRep::Set(name,Location1); |
550 | ||
91322f44 | 551 | Sprintf (name,"Location2"); |
7fd59977 | 552 | DBRep::Set(name,Location2); |
553 | ||
554 | // Make inner pipe shell | |
555 | BRepOffsetAPI_MakePipeShell mkPipe1(SpineWire); | |
556 | mkPipe1.SetTolerance(1.0e-8,1.0e-8,1.0e-6); | |
557 | mkPipe1.SetTransitionMode(BRepBuilderAPI_Transformed); | |
558 | mkPipe1.SetMode(Standard_False); | |
559 | mkPipe1.SetLaw(Wire1_, myLaw, Location1, Standard_False, Standard_False); | |
560 | mkPipe1.Build(); | |
6a0964c2 | 561 | if (!mkPipe1.IsDone()) |
562 | return 1; | |
7fd59977 | 563 | |
564 | // Make outer pipe shell | |
565 | BRepOffsetAPI_MakePipeShell mkPipe2(SpineWire); | |
566 | mkPipe2.SetTolerance(1.0e-8,1.0e-8,1.0e-6); | |
567 | mkPipe2.SetTransitionMode(BRepBuilderAPI_Transformed); | |
568 | mkPipe2.SetMode(Standard_False); | |
569 | mkPipe2.SetLaw(outerWire1_, myLaw2, Location1, Standard_False, Standard_False); | |
570 | mkPipe2.Build(); | |
6a0964c2 | 571 | if (!mkPipe2.IsDone()) |
572 | return 1; | |
7fd59977 | 573 | |
91322f44 | 574 | // Sprintf(name,"w1-first"); |
7fd59977 | 575 | // DBRep::Set(name,mkPipe1.FirstShape()); |
576 | ||
91322f44 | 577 | // Sprintf(name,"w1-last"); |
7fd59977 | 578 | // DBRep::Set(name,mkPipe1.LastShape()); |
579 | ||
91322f44 | 580 | // Sprintf(name,"w2-first"); |
7fd59977 | 581 | // DBRep::Set(name,mkPipe2.FirstShape()); |
582 | ||
91322f44 | 583 | // Sprintf(name,"w2-last"); |
7fd59977 | 584 | // DBRep::Set(name,mkPipe2.LastShape()); |
585 | ||
586 | BRepOffsetAPI_Sewing SewIt(1.0e-4); | |
587 | ||
588 | // Make tube | |
589 | TopExp_Explorer getFaces; | |
590 | TopoDS_Face test_face; | |
591 | getFaces.Init(mkPipe1.Shape(), TopAbs_FACE); | |
592 | while (getFaces.More()) | |
593 | { | |
594 | SewIt.Add(getFaces.Current().Reversed()); | |
595 | getFaces.Next(); | |
596 | } | |
597 | ||
598 | // Make face for first opening | |
599 | Handle(Geom_Plane) Plane1 = new Geom_Plane(circ1Plane); | |
1c72dff6 | 600 | mkFace.Init(Plane1,Standard_False,Precision::Confusion()); |
7fd59977 | 601 | mkFace.Add(TopoDS::Wire(outerWire1_)); |
602 | mkFace.Add(TopoDS::Wire(Wire1_.Reversed())); | |
6a0964c2 | 603 | if (!mkFace.IsDone()) |
604 | return 1; | |
7fd59977 | 605 | TopoDS_Face Face1 = mkFace.Face(); |
606 | ||
607 | // Make face for second opening | |
608 | Handle(Geom_Plane) Plane2 = new Geom_Plane(circ2Plane); | |
1c72dff6 | 609 | mkFace.Init(Plane2,Standard_False,Precision::Confusion()); |
7fd59977 | 610 | mkFace.Add(TopoDS::Wire(outerWire2_)); |
611 | mkFace.Add(TopoDS::Wire(Wire2_.Reversed())); | |
6a0964c2 | 612 | if (!mkFace.IsDone()) |
613 | return 1; | |
7fd59977 | 614 | TopoDS_Face Face2 = mkFace.Face(); |
615 | ||
616 | // Grab the gas solid now that we've extracted the faces. | |
617 | mkPipe1.MakeSolid(); | |
618 | myShape = TopoDS::Solid(mkPipe1.Shape()); | |
619 | ||
620 | getFaces.Clear(); | |
621 | getFaces.Init(mkPipe2.Shape(), TopAbs_FACE); | |
622 | while (getFaces.More()) | |
623 | { | |
624 | SewIt.Add(getFaces.Current()); | |
625 | getFaces.Next(); | |
626 | } | |
627 | ||
628 | SewIt.Add(Face1.Reversed()); | |
629 | SewIt.Add(Face2); | |
630 | ||
631 | SewIt.Perform(); | |
632 | ||
633 | di << "The result of the Sewing operation is a "; | |
634 | // Check to see if we have a solid | |
635 | switch (SewIt.SewedShape().ShapeType()) { | |
636 | case (TopAbs_COMPOUND): | |
586db386 | 637 | di << "TopAbs_COMPOUND\n"; |
7fd59977 | 638 | break; |
639 | case (TopAbs_COMPSOLID): | |
586db386 | 640 | di << "TopAbs_COMPSOLID\n"; |
7fd59977 | 641 | break; |
642 | case (TopAbs_SOLID): | |
586db386 | 643 | di << "TopAbs_SOLID\n"; |
7fd59977 | 644 | break; |
645 | case (TopAbs_SHELL): | |
586db386 | 646 | di << "TopAbs_SHELL\n"; |
7fd59977 | 647 | break; |
648 | case (TopAbs_FACE): | |
586db386 | 649 | di << "TopAbs_FACE\n"; |
7fd59977 | 650 | break; |
651 | case (TopAbs_WIRE): | |
586db386 | 652 | di << "TopAbs_WIRE\n"; |
7fd59977 | 653 | break; |
654 | case (TopAbs_EDGE): | |
586db386 | 655 | di << "TopAbs_EDGE\n"; |
7fd59977 | 656 | break; |
657 | case (TopAbs_VERTEX): | |
586db386 | 658 | di << "TopAbs_VERTEX\n"; |
7fd59977 | 659 | break; |
660 | case (TopAbs_SHAPE): | |
586db386 | 661 | di << "TopAbs_SHAPE\n"; |
7fd59977 | 662 | } |
663 | ||
664 | BRep_Builder B; | |
665 | ||
666 | TopoDS_Shell TubeShell; | |
667 | di << "Can we turn it into a shell? "; | |
668 | try { | |
669 | OCC_CATCH_SIGNALS | |
670 | TubeShell = TopoDS::Shell(SewIt.SewedShape()); | |
671 | B.MakeSolid(wallSolid); | |
672 | B.Add(wallSolid,TubeShell); | |
586db386 | 673 | di << " yes\n"; |
7fd59977 | 674 | } |
675 | catch (Standard_TypeMismatch) { | |
586db386 | 676 | di << "Can't convert to shell...\n"; |
7fd59977 | 677 | TopExp_Explorer getSol; |
678 | getSol.Init(SewIt.SewedShape(), TopAbs_SOLID); | |
679 | if (getSol.More()) { | |
586db386 | 680 | di << "First solid found in compound\n"; |
7fd59977 | 681 | wallSolid = TopoDS::Solid(getSol.Current()); |
682 | TopoDS_Solid test_solid; | |
683 | while (getSol.More()) | |
684 | { | |
586db386 | 685 | di << "Next solid found in compound\n"; |
7fd59977 | 686 | getSol.Next(); |
687 | test_solid = TopoDS::Solid(getSol.Current()); | |
688 | //////#if ! defined(BRepAlgoAPI_def01) | |
689 | ////// BRepAlgoAPI_Fuse fuser(test_solid, wallSolid); | |
690 | //////#else | |
691 | ////// BRepAlgo_Fuse fuser(test_solid, wallSolid); | |
692 | //////#endif | |
693 | ////// fuser.Build(); | |
694 | if (IsBRepAlgoAPI) { | |
586db386 | 695 | di << "BRepAlgoAPI_Fuse fuser(test_solid, wallSolid)\n"; |
7fd59977 | 696 | BRepAlgoAPI_Fuse fuser(test_solid, wallSolid); |
697 | fuser.Build(); | |
698 | wallSolid = TopoDS::Solid(fuser.Shape()); | |
699 | } else { | |
586db386 | 700 | di << "BRepAlgo_Fuse fuser(test_solid, wallSolid)\n"; |
7fd59977 | 701 | BRepAlgo_Fuse fuser(test_solid, wallSolid); |
702 | fuser.Build(); | |
703 | wallSolid = TopoDS::Solid(fuser.Shape()); | |
704 | } | |
705 | ////// wallSolid = TopoDS::Solid(fuser.Shape()); | |
706 | } | |
707 | } else { | |
708 | // Let's see if we can extract shells instead of solids. | |
709 | TopExp_Explorer getShel; | |
710 | getShel.Init(SewIt.SewedShape(), TopAbs_SHELL); | |
711 | if (getShel.More()) { | |
586db386 | 712 | di << "First shell found in compound\n"; |
7fd59977 | 713 | B.MakeSolid(wallSolid); |
586db386 | 714 | di << "B.Add(wallSolid,TopoDS::Shell(getShel.Current()));\n"; |
7fd59977 | 715 | int i = 1; |
716 | while (getShel.More()) | |
717 | { | |
586db386 | 718 | di << "Next shell found in compound\n"; |
719 | di << "B.Add(wallSolid,TopoDS::Shell(getShel.Current()));\n"; | |
91322f44 | 720 | Sprintf(name,"shell%d", i++); |
7fd59977 | 721 | DBRep::Set(name,getShel.Current()); |
722 | B.Add(wallSolid,TopoDS::Shell(getShel.Current())); | |
723 | getShel.Next(); | |
724 | } | |
725 | } | |
726 | } | |
727 | } | |
728 | ||
91322f44 | 729 | Sprintf(name,"result"); |
7fd59977 | 730 | DBRep::Set(name,wallSolid); |
731 | ||
732 | // Now calculated the volume of the outside tube. | |
733 | GProp_GProps gprops; | |
734 | BRepGProp::VolumeProperties(wallSolid, gprops); | |
735 | di << "The wallSolid's volume is: " << gprops.Mass() << "\n"; | |
736 | ||
737 | if (check) { | |
738 | if (!(BRepCheck_Analyzer(wallSolid).IsValid())) | |
586db386 | 739 | di << "The TopoDS_Solid was checked, and it was invalid!\n"; |
7fd59977 | 740 | else |
586db386 | 741 | di << "The TopoDS_Solid was checked, and it was valid.\n"; |
7fd59977 | 742 | if (!wallSolid.Closed()) |
586db386 | 743 | di << "The TopoDS_Solid is not closed!\n"; |
7fd59977 | 744 | else |
586db386 | 745 | di << "The TopoDS_Solid is closed.\n"; |
7fd59977 | 746 | if (!wallSolid.Checked()) |
586db386 | 747 | di << "The TopoDS_Solid is not checked!\n"; |
7fd59977 | 748 | else |
586db386 | 749 | di << "The TopoDS_Solid has been checked.\n"; |
7fd59977 | 750 | if (wallSolid.Infinite()) |
586db386 | 751 | di << "The TopoDS_Solid is infinite!\n"; |
7fd59977 | 752 | else |
586db386 | 753 | di << "The TopoDS_Solid is finite.\n"; |
7fd59977 | 754 | } |
755 | ||
756 | di << "The result is a "; | |
757 | // Check to see if we have a solid | |
758 | switch (wallSolid.ShapeType()) { | |
759 | case (TopAbs_COMPOUND): | |
586db386 | 760 | di << "TopAbs_COMPOUND\n"; |
7fd59977 | 761 | break; |
762 | case (TopAbs_COMPSOLID): | |
586db386 | 763 | di << "TopAbs_COMPSOLID\n"; |
7fd59977 | 764 | break; |
765 | case (TopAbs_SOLID): | |
586db386 | 766 | di << "TopAbs_SOLID\n"; |
7fd59977 | 767 | break; |
768 | case (TopAbs_SHELL): | |
586db386 | 769 | di << "TopAbs_SHELL\n"; |
7fd59977 | 770 | break; |
771 | case (TopAbs_FACE): | |
586db386 | 772 | di << "TopAbs_FACE\n"; |
7fd59977 | 773 | break; |
774 | case (TopAbs_WIRE): | |
586db386 | 775 | di << "TopAbs_WIRE\n"; |
7fd59977 | 776 | break; |
777 | case (TopAbs_EDGE): | |
586db386 | 778 | di << "TopAbs_EDGE\n"; |
7fd59977 | 779 | break; |
780 | case (TopAbs_VERTEX): | |
586db386 | 781 | di << "TopAbs_VERTEX\n"; |
7fd59977 | 782 | break; |
783 | case (TopAbs_SHAPE): | |
586db386 | 784 | di << "TopAbs_SHAPE\n"; |
7fd59977 | 785 | } |
786 | ||
787 | return 0; | |
788 | } | |
789 | ||
790 | #include <BRepPrimAPI_MakeBox.hxx> | |
791 | #include <BRepBndLib.hxx> | |
792 | #include <TopTools_Array1OfShape.hxx> | |
793 | #include <TColStd_Array1OfReal.hxx> | |
794 | #include <BRepBuilderAPI_Copy.hxx> | |
795 | #include <BRepAlgoAPI_Cut.hxx> | |
796 | #include <BRepAlgoAPI_Common.hxx> | |
797 | //////////#else | |
798 | //////////#include <BRepAlgo_Cut.hxx> | |
799 | //////////#include <BRepAlgo_Common.hxx> | |
800 | //////////#include <BRepAlgoAPI_Cut.hxx> | |
801 | //////////#include <BRepAlgoAPI_Common.hxx> | |
802 | #include <BRepAlgo_Cut.hxx> | |
803 | #include <BRepAlgo_Common.hxx> | |
804 | #include <Precision.hxx> | |
805 | ||
806 | static Standard_Integer OCC817 (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
807 | { | |
808 | //////////if(argc != 3) { | |
809 | ////////// cout << "Usage : " << argv[0] << " result mesh_delta" << endl; | |
810 | ////////// return 1; | |
811 | //////////} | |
812 | if(argc < 3 || argc > 4) { | |
586db386 | 813 | di << "Usage : " << argv[0] << " result mesh_delta [BRepAlgoAPI/BRepAlgo = 1/0]\n"; |
7fd59977 | 814 | return 1; |
815 | } | |
816 | Standard_Boolean IsBRepAlgoAPI = Standard_True; | |
817 | if (argc == 4) { | |
91322f44 | 818 | Standard_Integer IsB = Draw::Atoi(argv[3]); |
7fd59977 | 819 | if (IsB != 1) { |
820 | IsBRepAlgoAPI = Standard_False; | |
821 | #if ! defined(BRepAlgo_def02) | |
586db386 | 822 | // di << "Error: There is not BRepAlgo_Cut class\n"; |
7fd59977 | 823 | // return 1; |
824 | #endif | |
825 | #if ! defined(BRepAlgo_def03) | |
586db386 | 826 | // di << "Error: There is not BRepAlgo_Common class\n"; |
7fd59977 | 827 | // return 1; |
828 | #endif | |
829 | } | |
830 | } | |
831 | ||
832 | Standard_Real delt = 5.0*Precision::Confusion(); | |
91322f44 | 833 | Standard_Real mesh_delt = Draw::Atof(argv[2]); |
7fd59977 | 834 | if (mesh_delt <= 0.0) |
835 | { | |
586db386 | 836 | di<<"Error: mesh_delta must be positive value\n"; |
7fd59977 | 837 | return -1; |
838 | } | |
839 | ||
840 | // Create outer box solid | |
841 | gp_Pnt P(0,0,0); | |
842 | TopoDS_Solid fullSolid = BRepPrimAPI_MakeBox(P, 30.0, 30.0, 30.0).Solid(); | |
843 | ||
844 | // Create inner box solid | |
845 | P.SetX(10); P.SetY(10); P.SetZ(10); | |
846 | TopoDS_Solid internalSolid = BRepPrimAPI_MakeBox(P, 10.0, 10.0, 10.0).Solid(); | |
847 | ||
848 | // Cut inner from outer | |
849 | //////////#if ! defined(BRepAlgoAPI_def01) | |
850 | ////////// BRepAlgoAPI_Cut cut( fullSolid, internalSolid ); | |
851 | //////////#else | |
852 | ////////// BRepAlgo_Cut cut( fullSolid, internalSolid ); | |
853 | //////////#endif | |
854 | ////////// TopoDS_Shape cut_shape = cut.Shape(); | |
855 | ////////// if ( !cut.IsDone() ) | |
856 | ////////// { | |
857 | ////////// cout << "Error: Could not cut volumes" << endl; | |
858 | ////////// return -1; | |
859 | ////////// } | |
860 | ||
861 | TopoDS_Shape cut_shape; | |
862 | if (IsBRepAlgoAPI) { | |
586db386 | 863 | di << "BRepAlgoAPI_Cut cut( fullSolid, internalSolid )\n"; |
7fd59977 | 864 | BRepAlgoAPI_Cut cut( fullSolid, internalSolid ); |
865 | cut_shape = cut.Shape(); | |
866 | if ( !cut.IsDone() ) | |
867 | { | |
586db386 | 868 | di << "Error: Could not cut volumes\n"; |
7fd59977 | 869 | return -1; |
870 | } | |
871 | } else { | |
586db386 | 872 | di << "BRepAlgo_Cut cut( fullSolid, internalSolid )\n"; |
7fd59977 | 873 | BRepAlgo_Cut cut( fullSolid, internalSolid ); |
874 | cut_shape = cut.Shape(); | |
875 | if ( !cut.IsDone() ) | |
876 | { | |
586db386 | 877 | di << "Error: Could not cut volumes\n"; |
7fd59977 | 878 | return -1; |
879 | } | |
880 | } | |
881 | ||
882 | // see if we have a solid | |
883 | Standard_Integer found_solid = 0; | |
884 | TopoDS_Solid cutSolid; | |
885 | TopExp_Explorer Ex; | |
886 | for (Ex.Init(cut_shape, TopAbs_SOLID); Ex.More(); Ex.Next()) | |
887 | { | |
888 | TopoDS_Solid sol = TopoDS::Solid(Ex.Current()); | |
889 | if (!sol.IsNull()) { cutSolid = sol; found_solid++; } | |
890 | } | |
891 | if ( found_solid != 1 ) | |
892 | { | |
586db386 | 893 | di << "Error: Cut operation produced " << found_solid << " solids\n"; |
7fd59977 | 894 | return -1; |
895 | } | |
896 | DBRep::Set(argv[1],cutSolid); | |
897 | ||
898 | // Calculate initial volume | |
899 | GProp_GProps volumeVProps; | |
900 | BRepGProp::VolumeProperties (cutSolid, volumeVProps); | |
901 | di << "Info: Original volume = " << volumeVProps.Mass() << "\n"; | |
902 | ||
903 | // | |
904 | // build bounding box and calculate bounds for initial mesh | |
905 | // | |
906 | Bnd_Box bndBox; | |
907 | BRepBndLib::Add( cutSolid, bndBox ); | |
908 | Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax; | |
909 | bndBox.Get( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax ); | |
910 | Xmin -= delt; | |
911 | Ymin -= delt; | |
912 | Zmin -= delt; | |
913 | Xmax += delt; | |
914 | Ymax += delt; | |
915 | Zmax += delt; | |
586db386 | 916 | di<<"Info: Bounds\n ("<<Xmin<<","<<Ymin<<","<<Zmin<<")\n ("<<Xmax<<","<<Ymax<<","<<Zmax<<")\n"; |
7fd59977 | 917 | |
918 | // grid the bounding box | |
f1e162f2 | 919 | Standard_Integer NumXsubvolumes = (Standard_Integer)((Xmax - Xmin) / mesh_delt); if (NumXsubvolumes <= 0) NumXsubvolumes = 1; |
920 | Standard_Integer NumYsubvolumes = (Standard_Integer)((Ymax - Ymin) / mesh_delt); if (NumYsubvolumes <= 0) NumYsubvolumes = 1; | |
921 | Standard_Integer NumZsubvolumes = (Standard_Integer)((Zmax - Zmin) / mesh_delt); if (NumZsubvolumes <= 0) NumZsubvolumes = 1; | |
7fd59977 | 922 | const Standard_Real StepX = (Xmax - Xmin) / NumXsubvolumes; |
923 | const Standard_Real StepY = (Ymax - Ymin) / NumYsubvolumes; | |
924 | const Standard_Real StepZ = (Zmax - Zmin) / NumZsubvolumes; | |
925 | const Standard_Integer NumSubvolumes = NumXsubvolumes * NumYsubvolumes * NumZsubvolumes; | |
926 | di << "Info: NumSubvolumesX = " << NumXsubvolumes << "\n"; | |
927 | di << "Info: NumSubvolumesY = " << NumYsubvolumes << "\n"; | |
928 | di << "Info: NumSubvolumesZ = " << NumZsubvolumes << "\n"; | |
929 | di << "Info: NumSubvolumes = " << NumSubvolumes << "\n"; | |
930 | ||
931 | // | |
932 | // construct initial mesh of cutSolid | |
933 | // | |
934 | TopTools_Array1OfShape SubvolumeSolid(0,NumSubvolumes-1); | |
935 | TColStd_Array1OfReal SubvolumeVol(0,NumSubvolumes-1); | |
936 | Standard_Real accumulatedVolume = 0.0; | |
937 | Standard_Integer i, j, k, l = 0; | |
938 | Standard_Real x = Xmin; | |
939 | for ( i = 0; i < NumXsubvolumes; i++ ) | |
940 | { | |
941 | Standard_Real y = Ymin; | |
942 | for ( j = 0; j < NumYsubvolumes; j++ ) | |
943 | { | |
944 | Standard_Real z = Zmin; | |
945 | for ( k = 0; k < NumZsubvolumes; k++ ) | |
946 | { | |
947 | P.SetX(x); | |
948 | P.SetY(y); | |
949 | P.SetZ(z); | |
950 | TopoDS_Shape aSubvolume = BRepPrimAPI_MakeBox(P, StepX, StepY, StepZ).Solid(); | |
951 | di<<"Info: box b_"<<l<<" "<<P.X()<<" "<<P.Y()<<" "<<P.Z()<<" "<<StepX<<" "<<StepY<<" "<<StepZ<<"\n"; | |
952 | if ( aSubvolume.IsNull()) | |
953 | { | |
954 | di << "Error: could not construct subvolume " << l << "\n"; | |
955 | return 1; | |
956 | } | |
957 | SubvolumeSolid.SetValue(l,aSubvolume); | |
958 | GProp_GProps subvolumeVProps; | |
959 | BRepGProp::VolumeProperties (SubvolumeSolid(l), subvolumeVProps); | |
960 | const Standard_Real vol = subvolumeVProps.Mass(); | |
961 | di << "Info: original subvolume " << l << " volume = " << vol << "\n"; | |
962 | SubvolumeVol.SetValue(l,vol); | |
963 | accumulatedVolume += vol; | |
964 | l++; | |
965 | z += StepZ; | |
966 | } | |
967 | y += StepY; | |
968 | } | |
969 | x += StepX; | |
970 | } | |
971 | di << "Info: Accumulated mesh volume = " << accumulatedVolume << "\n"; | |
972 | ||
973 | // | |
974 | // trim mesh to cutSolid | |
975 | // | |
976 | accumulatedVolume = 0.0; | |
977 | for ( l = 0; l < NumSubvolumes; l++ ) | |
978 | { | |
979 | TopoDS_Shape copySolid = BRepBuilderAPI_Copy(cutSolid).Shape(); | |
980 | ||
981 | // perform common | |
982 | //////////#if ! defined(BRepAlgoAPI_def01) | |
983 | ////////// BRepAlgoAPI_Common common(copySolid/*cutSolid*/, SubvolumeSolid(l)); | |
984 | //////////#else | |
985 | ////////// BRepAlgo_Common common(copySolid/*cutSolid*/, SubvolumeSolid(l)); | |
986 | //////////#endif | |
987 | ////////// if (!common.IsDone()) | |
988 | ////////// { | |
989 | ////////// cout << "Error: could not construct a common solid " << l << endl; | |
990 | ////////// return 1; | |
991 | ////////// } | |
992 | ||
993 | TopoDS_Shape aCommonShape; | |
994 | if (IsBRepAlgoAPI) { | |
586db386 | 995 | di << "BRepAlgoAPI_Common common(copySolid/*cutSolid*/, SubvolumeSolid(l))\n"; |
7fd59977 | 996 | BRepAlgoAPI_Common common(copySolid/*cutSolid*/, SubvolumeSolid(l)); |
997 | if (!common.IsDone()) | |
998 | { | |
999 | di << "Error: could not construct a common solid " << l << "\n"; | |
1000 | return 1; | |
1001 | } | |
1002 | aCommonShape = common.Shape(); | |
1003 | } else { | |
586db386 | 1004 | di << "BRepAlgo_Common common(copySolid/*cutSolid*/, SubvolumeSolid(l))\n"; |
7fd59977 | 1005 | BRepAlgo_Common common(copySolid/*cutSolid*/, SubvolumeSolid(l)); |
1006 | if (!common.IsDone()) | |
1007 | { | |
1008 | di << "Error: could not construct a common solid " << l << "\n"; | |
1009 | return 1; | |
1010 | } | |
1011 | aCommonShape = common.Shape(); | |
1012 | } | |
1013 | ||
1014 | // see if we have a solid | |
1015 | found_solid = 0; | |
1016 | TopoDS_Shape commonShape; | |
1017 | //////////for (Ex.Init(common.Shape(), TopAbs_SOLID); Ex.More(); Ex.Next()) | |
1018 | for (Ex.Init(aCommonShape, TopAbs_SOLID); Ex.More(); Ex.Next()) | |
1019 | { | |
1020 | TopoDS_Solid sol = TopoDS::Solid(Ex.Current()); | |
1021 | if (!sol.IsNull()) { commonShape = sol; found_solid++; } | |
1022 | } | |
1023 | if ( found_solid != 1 ) | |
1024 | { | |
586db386 | 1025 | di << "Info: Common operation " << l << " produced " << found_solid << " solids\n"; |
7fd59977 | 1026 | } |
1027 | else | |
1028 | { | |
1029 | SubvolumeSolid.SetValue(l,commonShape); | |
1030 | GProp_GProps subvolumeVProps; | |
1031 | BRepGProp::VolumeProperties (SubvolumeSolid(l), subvolumeVProps); | |
1032 | const Standard_Real vol = subvolumeVProps.Mass(); | |
1033 | const Standard_Boolean err = (vol > SubvolumeVol(l)) || (vol <= 0.0); | |
1034 | //cout << (err? "ERROR" : "Info") << ": final subvolume " << l << " volume = " << vol << endl; | |
1035 | if (err) | |
586db386 | 1036 | di << "ERROR: final subvolume " << l << " volume = " << vol << "\n"; |
7fd59977 | 1037 | else |
586db386 | 1038 | di << "Info: final subvolume " << l << " volume = " << vol << "\n"; |
7fd59977 | 1039 | accumulatedVolume += vol; |
1040 | if (err) | |
1041 | { | |
1042 | char astr[80]; | |
91322f44 | 1043 | Sprintf(astr,"e_%d",l); |
7fd59977 | 1044 | DBRep::Set(astr,commonShape); |
1045 | } | |
1046 | } | |
1047 | } | |
1048 | di << "Info: Accumulated meshed volume = " << accumulatedVolume << "\n"; | |
1049 | ||
1050 | return 0; | |
1051 | } | |
1052 | ||
1cd84fee | 1053 | void QABugs::Commands_13(Draw_Interpretor& theCommands) { |
1365140b | 1054 | const char *group = "QABugs"; |
7fd59977 | 1055 | |
1056 | theCommands.Add ("OCC332", "OCC332 [wall_thickness [dia1 [dia2 [length [major_radius]]]]]", __FILE__, OCC332bug, group); | |
1057 | //////theCommands.Add("OCC544", "OCC544 [[[[[wT [[[[d1 [[[d2 [[R [length]]]]]", __FILE__, OCC544, group); | |
1058 | theCommands.Add("OCC544", "OCC544 [[[[[wT [[[[d1 [[[d2 [[R [length [BRepAlgoAPI/BRepAlgo = 1/0]]]]]]", __FILE__, OCC544, group); | |
1059 | //////theCommands.Add("OCC817", "OCC817 result mesh_delta", __FILE__, OCC817, group); | |
1060 | theCommands.Add("OCC817", "OCC817 result mesh_delta [BRepAlgoAPI/BRepAlgo = 1/0]", __FILE__, OCC817, group); | |
1061 | ||
1062 | return; | |
1063 | } |