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