1 // Created on: 2002-05-16
2 // Created by: QA Admin
3 // Copyright (c) 2002-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
24 #include <Draw_Interpretor.hxx>
26 #include <DrawTrSurf.hxx>
27 #include <AIS_InteractiveContext.hxx>
28 #include <ViewerTest.hxx>
29 #include <AIS_Shape.hxx>
30 #include <TopoDS_Shape.hxx>
35 #include <gp_Circ.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRepBuilderAPI_MakeWire.hxx>
39 #include <BRepBuilderAPI_MakeEdge.hxx>
40 #include <BRepBuilderAPI_MakeFace.hxx>
41 #include <BRepCheck_Analyzer.hxx>
42 #include <BRepGProp.hxx>
43 #include <BRepOffsetAPI_MakePipeShell.hxx>
44 #include <GC_MakeArcOfCircle.hxx>
45 #include <Geom_Curve.hxx>
46 #include <Geom_Plane.hxx>
47 #include <Law_Linear.hxx>
49 #include <TopoDS_Shell.hxx>
50 #include <TopoDS_Face.hxx>
51 #include <TopoDS_Solid.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <TopoDS_Wire.hxx>
54 #include <TopExp_Explorer.hxx>
55 #include <GProp_GProps.hxx>
56 #include <Standard_ErrorHandler.hxx>
58 //=======================================================================
61 //=======================================================================
62 static Standard_Integer OCC332bug (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
64 // Used to Display Geometry or Topolgy
67 Standard_Boolean check = Standard_True;
69 // Set default arguments
70 double wall_thickness = 10.0;
73 double length = 400.0;
74 double major_radius = 280.0;
77 if (argc>1) wall_thickness = atof(argv[1]);
78 if (argc>2) dia1 = atof(argv[2]);
79 if (argc>3) dia2 = atof(argv[3]);
80 if (argc>4) major_radius = atof(argv[4]);
81 if (argc>5) length = atof(argv[5]);
82 double bend_angle = length/major_radius;
84 //if ((bend_angle >= M_PI)) {
85 if ((bend_angle >= M_PI)) {
86 di << "The arguments are invalid." << "\n";
89 di << "creating the shape for a bent tube" << "\n";
91 double radius_l = dia1/2.0;
92 double radius_r = dia2/2.0;
95 // 1. There is no need to normalize the direction - it's done automatically
96 //gp_Ax2 origin(gp_Pnt(5000.0,-300.0, 1000.0),
97 //gp_Dir(0.0, -1.0/sqrt(2.0), -1.0/sqrt(2.0)));
98 gp_Ax2 origin(gp_Pnt(5000.0,-300.0,1000.0),gp_Dir(0.0,-1.0,-1.0));
101 TopoDS_Shape myShape, gasSolid;
102 TopoDS_Solid wallSolid;
104 // Construct a circle for the first face, on the xy-plane at the origin
105 gp_Pln circ1Plane(origin.Location(), origin.Direction());
106 gp_Circ faceCircle(origin, radius_l);
107 gp_Circ outFaceCircle(origin, radius_l+wall_thickness);
109 // Construct center for a circle to be the spine of
110 // revolution, on the xz-plane at x=major_radius
111 gp_Pnt circ_center = origin.Location().Translated(major_radius*origin.XDirection());
113 // This point will be the center of the second face.
115 // - There is no need in this point - we'll use angle instead.
116 //gp_Pnt endPoint = origin.Location();
117 //endPoint.Translate(major_radius*(1.0-cos(bend_angle))*origin.XDirection()) ;
118 //endPoint.Translate((-major_radius*sin(bend_angle))*origin.Direction());
120 // Construct the plane for the second face to sit on.
122 // - It is better to use rotation instead of explicit calculations
123 //gp_Pln circ2Plane = gce_MakePln(circ_center, endPoint,
124 // endPoint.Translated(major_radius*origin.YDirection())
126 gp_Ax1 circ_axis(circ_center,origin.YDirection());
127 gp_Pln circ2Plane = circ1Plane.Rotated(circ_axis,bend_angle);
129 // The circle used for the spine.
131 // - Use direction (-X) instead of (X) to obtain correct right-handed system.
132 // It is very important to maintain correct orientation between spine
134 //gp_Ax2 spineAxis(circ_center, origin.YDirection(), origin.XDirection());
135 gp_Ax2 spineAxis(circ_center, origin.YDirection(), -origin.XDirection());
136 gp_Circ circle(spineAxis, major_radius);
139 // - There is no need to create 2nd circles - they will be created by MakePipeShell.
140 //gp_Ax2 circ2axis(endPoint, circ2Plane.Axis().Direction(), origin.YDirection());
141 //gp_Circ faceCircle2(circ2axis,radius_r);
142 //gp_Circ outFaceCircle2(circ2axis,radius_r+wall_thickness);
144 TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(faceCircle);
145 TopoDS_Wire Wire1_ = BRepBuilderAPI_MakeWire(E1).Wire();
147 // Create the face at the near end for the wall solid, an annular ring.
148 TopoDS_Edge Eout1 = BRepBuilderAPI_MakeEdge(outFaceCircle);
149 TopoDS_Wire outerWire1_ = BRepBuilderAPI_MakeWire(Eout1).Wire();
152 // - There is no need to create 2nd circles -
153 // they will be created by MakePipeShell
154 //TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(faceCircle2);
155 //TopoDS_Wire Wire2_ = BRepBuilderAPI_MakeWire(E2).Wire();
157 // Create the face at the far end for the wall solid, an annular ring.
159 // - There is no need to create 2nd circles -
160 // they will be created by MakePipeShell
161 //TopoDS_Edge Eout2 = BRepBuilderAPI_MakeEdge(outFaceCircle2);
162 //TopoDS_Wire outerWire2_ = BRepBuilderAPI_MakeWire(Eout2).Wire();
165 // - It is better to use bend angle calculated above
166 //Handle(Geom_Curve) SpineCurve = GC_MakeArcOfCircle(circle,
168 // origin.Location(),
169 // Standard_True).Value();
170 Handle(Geom_Curve) SpineCurve = GC_MakeArcOfCircle(circle,
173 Standard_True).Value();
176 // - Use correct formula for scaling laws
177 Handle(Law_Linear) myLaw1 = new Law_Linear();
178 Handle(Law_Linear) myLaw2 = new Law_Linear();
179 //if ((radius_r - radius_l) < Precision::Confusion())
181 //myLaw1->Set(SpineCurve->FirstParameter(), 1.0,
182 //SpineCurve->LastParameter(), 1.0);
183 //myLaw2->Set(SpineCurve->FirstParameter(), 1.0,
184 //SpineCurve->LastParameter(), 1.0);
188 //myLaw1->Set(SpineCurve->FirstParameter(), radius_r/(radius_r-radius_l),
189 //SpineCurve->LastParameter(), 1.0);
190 //myLaw2->Set(SpineCurve->FirstParameter(), (radius_r+wall_thickness)/(radius_r-radius_l),
191 //SpineCurve->LastParameter(), 1.0);
193 myLaw1->Set(SpineCurve->FirstParameter(),1.0,
194 SpineCurve->LastParameter(),radius_r/radius_l);
195 myLaw2->Set(SpineCurve->FirstParameter(),1.0,
196 SpineCurve->LastParameter(),(radius_r+wall_thickness)/(radius_l+wall_thickness));
198 BRepBuilderAPI_MakeFace mkFace;
200 BRepBuilderAPI_MakeEdge mkEdge;
202 mkEdge.Init(SpineCurve);
203 if (!mkEdge.IsDone()) return 0;
204 TopoDS_Wire SpineWire = BRepBuilderAPI_MakeWire(mkEdge.Edge()).Wire();
206 sprintf (name,"SpineWire");
207 DBRep::Set(name,SpineWire);
209 sprintf (name,"Wire1_");
210 DBRep::Set(name,Wire1_);
212 sprintf (name,"outerWire1_");
213 DBRep::Set(name,outerWire1_);
216 // - There is no need to create 2nd circles
217 //sprintf (name,"Wire2_");
218 //DBRep::Set(name,Wire2_);
219 //sprintf (name,"outerWire2_");
220 //DBRep::Set(name,outerWire2_);
225 // - There is no need in these vertices
226 //TopoDS_Vertex Location1, Location2;
227 //TopExp::Vertices(SpineWire, Location1, Location2);
229 // Make inner pipe shell
230 BRepOffsetAPI_MakePipeShell mkPipe1(SpineWire);
231 mkPipe1.SetTolerance(1.0e-8,1.0e-8,1.0e-6);
232 //mkPipe1.SetTransitionMode(BRepBuilderAPI_Transformed); // Default mode !!
233 mkPipe1.SetLaw(Wire1_, myLaw1/*, Location2*/, Standard_False, Standard_False);
235 if (!mkPipe1.IsDone()) return 0;
237 // Make outer pipe shell
238 BRepOffsetAPI_MakePipeShell mkPipe2(SpineWire);
239 mkPipe2.SetTolerance(1.0e-8,1.0e-8,1.0e-6);
240 //mkPipe2.SetTransitionMode(BRepBuilderAPI_Transformed); // Default mode !!
241 mkPipe2.SetLaw(outerWire1_, myLaw2/*, Location2*/, Standard_False, Standard_False);
243 if (!mkPipe2.IsDone()) return 0;
245 // Make face for first opening
246 Handle(Geom_Plane) Plane1 = new Geom_Plane(circ1Plane);
247 mkFace.Init(Plane1,Standard_False,Precision::Confusion());
249 // - Use wires created by MakePipeShell
250 //mkFace.Add(TopoDS::Wire(outerWire1_));
251 //mkFace.Add(TopoDS::Wire(Wire1_.Reversed()));
252 mkFace.Add(TopoDS::Wire(mkPipe2.FirstShape()));
253 mkFace.Add(TopoDS::Wire(mkPipe1.FirstShape().Reversed()));
254 if (!mkFace.IsDone()) return 0;
255 TopoDS_Face Face1 = mkFace.Face();
257 // Make face for second opening
258 Handle(Geom_Plane) Plane2 = new Geom_Plane(circ2Plane);
259 mkFace.Init(Plane2,Standard_False,Precision::Confusion());
261 // - Use wires created by MakePipeShell
262 //mkFace.Add(TopoDS::Wire(outerWire2_));
263 //mkFace.Add(TopoDS::Wire(Wire2_.Reversed()));
264 mkFace.Add(TopoDS::Wire(mkPipe2.LastShape()));
265 mkFace.Add(TopoDS::Wire(mkPipe1.LastShape().Reversed()));
266 if (!mkFace.IsDone()) return 0;
267 TopoDS_Face Face2 = mkFace.Face();
270 TopoDS_Shell TubeShell;
272 B.MakeShell(TubeShell);
273 TopExp_Explorer getFaces;
274 TopoDS_Face test_face;
275 getFaces.Init(mkPipe1.Shape(), TopAbs_FACE);
277 // - In our case there should be only 1 pipe face
278 //while (getFaces.More())
280 // test_face = TopoDS::Face(getFaces.Current());
281 // Handle(Geom_Surface) S = BRep_Tool::Surface(test_face);
282 // GeomLib_IsPlanarSurface IsPl(S);
283 // if (!IsPl.IsPlanar()) {
284 // B.Add(TubeShell,getFaces.Current().Reversed());
289 B.Add(TubeShell,getFaces.Current().Reversed());
291 // Grab the gas solid now that we've extracted the faces.
293 gasSolid = mkPipe1.Shape();
295 sprintf (name,"gasSolid_");
296 DBRep::Set(name,gasSolid);
299 getFaces.Init(mkPipe2.Shape(), TopAbs_FACE);
301 // - In our case there should be only 1 pipe face
302 //while (getFaces.More())
304 // B.Add(TubeShell,getFaces.Current());
308 B.Add(TubeShell,getFaces.Current());
310 B.Add(TubeShell,Face1.Reversed());
311 B.Add(TubeShell,Face2);
313 B.MakeSolid(wallSolid);
314 B.Add(wallSolid,TubeShell);
316 sprintf (name,"wallSolid_");
317 DBRep::Set(name,wallSolid);
319 // Now calculated the volume of the outside tube.
321 BRepGProp::VolumeProperties(wallSolid, gprops);
322 di << "The wallSolid's volume is: " << gprops.Mass() << "\n";
325 if (!(BRepCheck_Analyzer(wallSolid).IsValid()))
326 di << "The TopoDS_Solid was checked, and it was invalid!" << "\n";
328 di << "The TopoDS_Solid was checked, and it was valid." << "\n";
329 if (!wallSolid.Closed())
330 di << "The TopoDS_Solid is not closed!" << "\n";
332 di << "The TopoDS_Solid is closed." << "\n";
333 if (!wallSolid.Checked())
334 di << "The TopoDS_Solid is not checked!" << "\n";
336 di << "The TopoDS_Solid has been checked." << "\n";
337 if (wallSolid.Infinite())
338 di << "The TopoDS_Solid is infinite!" << "\n";
340 di << "The TopoDS_Solid is finite." << "\n";
343 di << "The result is a ";
344 // Check to see if we have a solid
345 switch (wallSolid.ShapeType()) {
346 case (TopAbs_COMPOUND):
347 di << "TopAbs_COMPOUND" << "\n";
349 case (TopAbs_COMPSOLID):
350 di << "TopAbs_COMPSOLID" << "\n";
353 di << "TopAbs_SOLID" << "\n";
356 di << "TopAbs_SHELL" << "\n";
359 di << "TopAbs_FACE" << "\n";
362 di << "TopAbs_WIRE" << "\n";
365 di << "TopAbs_EDGE" << "\n";
367 case (TopAbs_VERTEX):
368 di << "TopAbs_VERTEX" << "\n";
371 di << "TopAbs_SHAPE" << "\n";
373 di << "Can we turn it into a solid? ";
376 di << " yes" << "\n";
378 catch (Standard_TypeMismatch) {
383 getFaces.Init(wallSolid, TopAbs_FACE);
385 while (getFaces.More())
388 sprintf(name,"Face%d",i);
389 di << "Face named " << name << "\n";
390 DBRep::Set(name,getFaces.Current());
397 #include <gce_MakePln.hxx>
398 #include <TopExp.hxx>
399 #include <BRepOffsetAPI_Sewing.hxx>
400 #include <BRepAlgoAPI_Fuse.hxx>
402 ///////#include <BRepAlgo_Fuse.hxx>
403 ///////#include <BRepAlgoAPI_Fuse.hxx>
404 #include <BRepAlgo_Fuse.hxx>
406 //=======================================================================
409 //=======================================================================
410 static Standard_Integer OCC544 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
413 di << "Usage : " << argv[0] << " [[[[[wT [[[[d1 [[[d2 [[R [length [BRepAlgoAPI/BRepAlgo = 1/0]]]]]]" << "\n";
416 Standard_Boolean IsBRepAlgoAPI = Standard_True;
418 Standard_Integer IsB = atoi(argv[6]);
420 IsBRepAlgoAPI = Standard_False;
421 #if ! defined(BRepAlgo_def01)
422 // di << "Error: There is not BRepAlgo_Fuse class" << "\n";
428 // Used to Display Geometry or Topolgy
432 Standard_Boolean check = Standard_True;
434 // Set default arguments
435 double radius_l = 20.0;
436 double radius_r = 80.0;
437 // mkv 15.07.03 double bend_angle = M_PI/2.0;
438 double bend_angle = M_PI/2.0;
440 double major_rad = 280.0;
441 double wall_thickness = 10.0;
445 if (argc>1) radius_l = atof(argv[1]);
446 if (argc>2) radius_r = atof(argv[2]);
447 if (argc>3) bend_angle = atof(argv[3]);
448 if (argc>4) major_rad = atof(argv[4]);
449 if (argc>5) wall_thickness = atof(argv[5]);
451 // mkv 15.07.03 if ((bend_angle >= 2.0*M_PI)) {
452 if ((bend_angle >= 2.0*M_PI)) {
453 di << "The arguments are invalid." << "\n";
456 di << "creating the shape for a bent tube" << "\n";
458 gp_Ax2 origin(gp_Pnt(500.0,-300.0, 100.0),
459 gp_Dir(0.0, -1.0/sqrt(2.0), -1.0/sqrt(2.0)));
461 TopoDS_Face firstFace, lastFace;
462 TopoDS_Solid wallSolid, myShape;
463 // Construct a circle for the first face, on the xy-plane at the origin
464 gp_Pln circ1Plane(origin.Location(), origin.Direction());
465 gp_Circ faceCircle(origin, radius_l);
466 gp_Circ outFaceCircle(origin, radius_l+wall_thickness);
468 // Construct center for a circle to be the spine of
469 // revolution, on the xz-plane at x=major_rad
470 gp_Pnt circ_center = origin.Location().Translated(
471 major_rad*origin.XDirection()
474 // This point will be the center of the second face.
475 gp_Pnt endPoint = origin.Location();
476 endPoint.Translate(major_rad*(1.0-cos(bend_angle))*origin.XDirection()) ;
477 endPoint.Translate((-major_rad*sin(bend_angle))*origin.Direction());
479 // Construct the plane for the second face to sit on.
480 gp_Pln circ2Plane = gce_MakePln(circ_center, endPoint,
481 endPoint.Translated(major_rad*origin.YDirection())
484 // The circle used for the spine.
485 gp_Ax2 spineAxis(circ_center, origin.YDirection(), origin.XDirection());
486 gp_Circ circle(spineAxis, major_rad);
488 gp_Ax2 circ2axis(endPoint, circ2Plane.Axis().Direction(), origin.YDirection());
489 gp_Circ faceCircle2(circ2axis,radius_r);
490 gp_Circ outFaceCircle2(circ2axis,radius_r+wall_thickness);
492 TopoDS_Edge E1_1 = BRepBuilderAPI_MakeEdge(faceCircle, 0, M_PI);
493 TopoDS_Edge E1_2 = BRepBuilderAPI_MakeEdge(faceCircle, M_PI, 2.*M_PI);
494 TopoDS_Wire Wire1_ = BRepBuilderAPI_MakeWire(E1_1, E1_2);
496 // Create the face at the near end for the wall solid, an annular ring.
497 TopoDS_Edge Eout1_1 = BRepBuilderAPI_MakeEdge(outFaceCircle, 0, M_PI);
498 TopoDS_Edge Eout1_2 = BRepBuilderAPI_MakeEdge(outFaceCircle, M_PI, 2.*M_PI);
499 TopoDS_Wire outerWire1_ = BRepBuilderAPI_MakeWire(Eout1_1, Eout1_2);
501 TopoDS_Edge E2_1 = BRepBuilderAPI_MakeEdge(faceCircle2, 0, M_PI);
502 TopoDS_Edge E2_2 = BRepBuilderAPI_MakeEdge(faceCircle2, M_PI, 2.*M_PI);
503 TopoDS_Wire Wire2_ = BRepBuilderAPI_MakeWire(E2_1, E2_2);
505 // Create the face at the far end for the wall solid, an annular ring.
506 TopoDS_Edge Eout2_1 = BRepBuilderAPI_MakeEdge(outFaceCircle2, 0, M_PI);
507 TopoDS_Edge Eout2_2 = BRepBuilderAPI_MakeEdge(outFaceCircle2, M_PI, 2.*M_PI);
508 TopoDS_Wire outerWire2_ = BRepBuilderAPI_MakeWire(Eout2_1, Eout2_2);
510 BRepBuilderAPI_MakeFace mkFace;
512 Handle(Geom_Curve) SpineCurve = GC_MakeArcOfCircle(circle,
515 Standard_True).Value();
516 Handle(Law_Linear) myLaw = new Law_Linear();
517 Handle(Law_Linear) myLaw2 = new Law_Linear();
519 myLaw->Set(SpineCurve->FirstParameter(),
521 SpineCurve->LastParameter(),
524 myLaw2->Set(SpineCurve->FirstParameter(),
525 (radius_r+wall_thickness)/(radius_l+wall_thickness),
526 SpineCurve->LastParameter(),
529 di << "SpineCurve->FirstParameter() is " << SpineCurve->FirstParameter() << "\n";
530 di << "SpineCurve->LastParameter() is " << SpineCurve->LastParameter() << "\n";
531 di << "Law1 Value at FirstParameter() is " << myLaw->Value(SpineCurve->FirstParameter()) << "\n";
532 di << "Law1 Value at LastParameter() is " << myLaw->Value(SpineCurve->LastParameter()) << "\n";
533 di << "radius_r / radius_l is " << radius_r/radius_l << "\n";
535 BRepBuilderAPI_MakeEdge mkEdge;
537 mkEdge.Init(SpineCurve);
538 if (!mkEdge.IsDone()) return TCL_ERROR;
539 TopoDS_Wire SpineWire = BRepBuilderAPI_MakeWire(mkEdge.Edge()).Wire();
541 sprintf (name,"SpineWire");
542 DBRep::Set(name,SpineWire);
544 sprintf (name,"Wire1_");
545 DBRep::Set(name,Wire1_);
547 sprintf (name,"outerWire1_");
548 DBRep::Set(name,outerWire1_);
550 sprintf (name,"Wire2_");
551 DBRep::Set(name,Wire2_);
553 sprintf (name,"outerWire2_");
554 DBRep::Set(name,outerWire2_);
558 TopoDS_Vertex Location1, Location2;
560 TopExp::Vertices(SpineWire, Location2, Location1);
562 sprintf (name,"Location1");
563 DBRep::Set(name,Location1);
565 sprintf (name,"Location2");
566 DBRep::Set(name,Location2);
568 // Make inner pipe shell
569 BRepOffsetAPI_MakePipeShell mkPipe1(SpineWire);
570 mkPipe1.SetTolerance(1.0e-8,1.0e-8,1.0e-6);
571 mkPipe1.SetTransitionMode(BRepBuilderAPI_Transformed);
572 mkPipe1.SetMode(Standard_False);
573 mkPipe1.SetLaw(Wire1_, myLaw, Location1, Standard_False, Standard_False);
575 if (!mkPipe1.IsDone()) return TCL_ERROR;
577 // Make outer pipe shell
578 BRepOffsetAPI_MakePipeShell mkPipe2(SpineWire);
579 mkPipe2.SetTolerance(1.0e-8,1.0e-8,1.0e-6);
580 mkPipe2.SetTransitionMode(BRepBuilderAPI_Transformed);
581 mkPipe2.SetMode(Standard_False);
582 mkPipe2.SetLaw(outerWire1_, myLaw2, Location1, Standard_False, Standard_False);
584 if (!mkPipe2.IsDone()) return TCL_ERROR;
586 // sprintf(name,"w1-first");
587 // DBRep::Set(name,mkPipe1.FirstShape());
589 // sprintf(name,"w1-last");
590 // DBRep::Set(name,mkPipe1.LastShape());
592 // sprintf(name,"w2-first");
593 // DBRep::Set(name,mkPipe2.FirstShape());
595 // sprintf(name,"w2-last");
596 // DBRep::Set(name,mkPipe2.LastShape());
598 BRepOffsetAPI_Sewing SewIt(1.0e-4);
601 TopExp_Explorer getFaces;
602 TopoDS_Face test_face;
603 getFaces.Init(mkPipe1.Shape(), TopAbs_FACE);
604 while (getFaces.More())
606 SewIt.Add(getFaces.Current().Reversed());
610 // Make face for first opening
611 Handle(Geom_Plane) Plane1 = new Geom_Plane(circ1Plane);
612 mkFace.Init(Plane1,Standard_False,Precision::Confusion());
613 mkFace.Add(TopoDS::Wire(outerWire1_));
614 mkFace.Add(TopoDS::Wire(Wire1_.Reversed()));
615 if (!mkFace.IsDone()) return TCL_ERROR;
616 TopoDS_Face Face1 = mkFace.Face();
618 // Make face for second opening
619 Handle(Geom_Plane) Plane2 = new Geom_Plane(circ2Plane);
620 mkFace.Init(Plane2,Standard_False,Precision::Confusion());
621 mkFace.Add(TopoDS::Wire(outerWire2_));
622 mkFace.Add(TopoDS::Wire(Wire2_.Reversed()));
623 if (!mkFace.IsDone()) return TCL_ERROR;
624 TopoDS_Face Face2 = mkFace.Face();
626 // Grab the gas solid now that we've extracted the faces.
628 myShape = TopoDS::Solid(mkPipe1.Shape());
631 getFaces.Init(mkPipe2.Shape(), TopAbs_FACE);
632 while (getFaces.More())
634 SewIt.Add(getFaces.Current());
638 SewIt.Add(Face1.Reversed());
643 di << "The result of the Sewing operation is a ";
644 // Check to see if we have a solid
645 switch (SewIt.SewedShape().ShapeType()) {
646 case (TopAbs_COMPOUND):
647 di << "TopAbs_COMPOUND" << "\n";
649 case (TopAbs_COMPSOLID):
650 di << "TopAbs_COMPSOLID" << "\n";
653 di << "TopAbs_SOLID" << "\n";
656 di << "TopAbs_SHELL" << "\n";
659 di << "TopAbs_FACE" << "\n";
662 di << "TopAbs_WIRE" << "\n";
665 di << "TopAbs_EDGE" << "\n";
667 case (TopAbs_VERTEX):
668 di << "TopAbs_VERTEX" << "\n";
671 di << "TopAbs_SHAPE" << "\n";
676 TopoDS_Shell TubeShell;
677 di << "Can we turn it into a shell? ";
680 TubeShell = TopoDS::Shell(SewIt.SewedShape());
681 B.MakeSolid(wallSolid);
682 B.Add(wallSolid,TubeShell);
683 di << " yes" << "\n";
685 catch (Standard_TypeMismatch) {
686 di << "Can't convert to shell..." << "\n";
687 TopExp_Explorer getSol;
688 getSol.Init(SewIt.SewedShape(), TopAbs_SOLID);
690 di << "First solid found in compound" << "\n";
691 wallSolid = TopoDS::Solid(getSol.Current());
692 TopoDS_Solid test_solid;
693 while (getSol.More())
695 di << "Next solid found in compound" << "\n";
697 test_solid = TopoDS::Solid(getSol.Current());
698 //////#if ! defined(BRepAlgoAPI_def01)
699 ////// BRepAlgoAPI_Fuse fuser(test_solid, wallSolid);
701 ////// BRepAlgo_Fuse fuser(test_solid, wallSolid);
703 ////// fuser.Build();
705 di << "BRepAlgoAPI_Fuse fuser(test_solid, wallSolid)" <<"\n";
706 BRepAlgoAPI_Fuse fuser(test_solid, wallSolid);
708 wallSolid = TopoDS::Solid(fuser.Shape());
710 di << "BRepAlgo_Fuse fuser(test_solid, wallSolid)" <<"\n";
711 BRepAlgo_Fuse fuser(test_solid, wallSolid);
713 wallSolid = TopoDS::Solid(fuser.Shape());
715 ////// wallSolid = TopoDS::Solid(fuser.Shape());
718 // Let's see if we can extract shells instead of solids.
719 TopExp_Explorer getShel;
720 getShel.Init(SewIt.SewedShape(), TopAbs_SHELL);
721 if (getShel.More()) {
722 di << "First shell found in compound" << "\n";
723 B.MakeSolid(wallSolid);
724 di << "B.Add(wallSolid,TopoDS::Shell(getShel.Current()));" << "\n";
726 while (getShel.More())
728 di << "Next shell found in compound" << "\n";
729 di << "B.Add(wallSolid,TopoDS::Shell(getShel.Current()));" << "\n";
730 sprintf(name,"shell%d", i++);
731 DBRep::Set(name,getShel.Current());
732 B.Add(wallSolid,TopoDS::Shell(getShel.Current()));
739 sprintf(name,"result");
740 DBRep::Set(name,wallSolid);
742 // Now calculated the volume of the outside tube.
744 BRepGProp::VolumeProperties(wallSolid, gprops);
745 di << "The wallSolid's volume is: " << gprops.Mass() << "\n";
748 if (!(BRepCheck_Analyzer(wallSolid).IsValid()))
749 di << "The TopoDS_Solid was checked, and it was invalid!" << "\n";
751 di << "The TopoDS_Solid was checked, and it was valid." << "\n";
752 if (!wallSolid.Closed())
753 di << "The TopoDS_Solid is not closed!" << "\n";
755 di << "The TopoDS_Solid is closed." << "\n";
756 if (!wallSolid.Checked())
757 di << "The TopoDS_Solid is not checked!" << "\n";
759 di << "The TopoDS_Solid has been checked." << "\n";
760 if (wallSolid.Infinite())
761 di << "The TopoDS_Solid is infinite!" << "\n";
763 di << "The TopoDS_Solid is finite." << "\n";
766 di << "The result is a ";
767 // Check to see if we have a solid
768 switch (wallSolid.ShapeType()) {
769 case (TopAbs_COMPOUND):
770 di << "TopAbs_COMPOUND" << "\n";
772 case (TopAbs_COMPSOLID):
773 di << "TopAbs_COMPSOLID" << "\n";
776 di << "TopAbs_SOLID" << "\n";
779 di << "TopAbs_SHELL" << "\n";
782 di << "TopAbs_FACE" << "\n";
785 di << "TopAbs_WIRE" << "\n";
788 di << "TopAbs_EDGE" << "\n";
790 case (TopAbs_VERTEX):
791 di << "TopAbs_VERTEX" << "\n";
794 di << "TopAbs_SHAPE" << "\n";
800 #include <BRepPrimAPI_MakeBox.hxx>
801 #include <BRepBndLib.hxx>
802 #include <TopTools_Array1OfShape.hxx>
803 #include <TColStd_Array1OfReal.hxx>
804 #include <BRepBuilderAPI_Copy.hxx>
805 #include <BRepAlgoAPI_Cut.hxx>
806 #include <BRepAlgoAPI_Common.hxx>
808 //////////#include <BRepAlgo_Cut.hxx>
809 //////////#include <BRepAlgo_Common.hxx>
810 //////////#include <BRepAlgoAPI_Cut.hxx>
811 //////////#include <BRepAlgoAPI_Common.hxx>
812 #include <BRepAlgo_Cut.hxx>
813 #include <BRepAlgo_Common.hxx>
814 #include <Precision.hxx>
816 static Standard_Integer OCC817 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
818 //////////if(argc != 3) {
819 ////////// cout << "Usage : " << argv[0] << " result mesh_delta" << endl;
822 if(argc < 3 || argc > 4) {
823 di << "Usage : " << argv[0] << " result mesh_delta [BRepAlgoAPI/BRepAlgo = 1/0]" << "\n";
826 Standard_Boolean IsBRepAlgoAPI = Standard_True;
828 Standard_Integer IsB = atoi(argv[3]);
830 IsBRepAlgoAPI = Standard_False;
831 #if ! defined(BRepAlgo_def02)
832 // di << "Error: There is not BRepAlgo_Cut class" << "\n";
835 #if ! defined(BRepAlgo_def03)
836 // di << "Error: There is not BRepAlgo_Common class" << "\n";
842 Standard_Real delt = 5.0*Precision::Confusion();
843 Standard_Real mesh_delt = atof(argv[2]);
844 if (mesh_delt <= 0.0)
846 di<<"Error: mesh_delta must be positive value"<<"\n";
850 // Create outer box solid
852 TopoDS_Solid fullSolid = BRepPrimAPI_MakeBox(P, 30.0, 30.0, 30.0).Solid();
854 // Create inner box solid
855 P.SetX(10); P.SetY(10); P.SetZ(10);
856 TopoDS_Solid internalSolid = BRepPrimAPI_MakeBox(P, 10.0, 10.0, 10.0).Solid();
858 // Cut inner from outer
859 //////////#if ! defined(BRepAlgoAPI_def01)
860 ////////// BRepAlgoAPI_Cut cut( fullSolid, internalSolid );
862 ////////// BRepAlgo_Cut cut( fullSolid, internalSolid );
864 ////////// TopoDS_Shape cut_shape = cut.Shape();
865 ////////// if ( !cut.IsDone() )
867 ////////// cout << "Error: Could not cut volumes" << endl;
868 ////////// return -1;
871 TopoDS_Shape cut_shape;
873 di << "BRepAlgoAPI_Cut cut( fullSolid, internalSolid )" <<"\n";
874 BRepAlgoAPI_Cut cut( fullSolid, internalSolid );
875 cut_shape = cut.Shape();
878 di << "Error: Could not cut volumes" << "\n";
882 di << "BRepAlgo_Cut cut( fullSolid, internalSolid )" <<"\n";
883 BRepAlgo_Cut cut( fullSolid, internalSolid );
884 cut_shape = cut.Shape();
887 di << "Error: Could not cut volumes" << "\n";
892 // see if we have a solid
893 Standard_Integer found_solid = 0;
894 TopoDS_Solid cutSolid;
896 for (Ex.Init(cut_shape, TopAbs_SOLID); Ex.More(); Ex.Next())
898 TopoDS_Solid sol = TopoDS::Solid(Ex.Current());
899 if (!sol.IsNull()) { cutSolid = sol; found_solid++; }
901 if ( found_solid != 1 )
903 di << "Error: Cut operation produced " << found_solid << " solids" << "\n";
906 DBRep::Set(argv[1],cutSolid);
908 // Calculate initial volume
909 GProp_GProps volumeVProps;
910 BRepGProp::VolumeProperties (cutSolid, volumeVProps);
911 di << "Info: Original volume = " << volumeVProps.Mass() << "\n";
914 // build bounding box and calculate bounds for initial mesh
917 BRepBndLib::Add( cutSolid, bndBox );
918 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
919 bndBox.Get( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
926 di<<"Info: Bounds\n ("<<Xmin<<","<<Ymin<<","<<Zmin<<")\n ("<<Xmax<<","<<Ymax<<","<<Zmax<<")"<<"\n";
928 // grid the bounding box
929 Standard_Integer NumXsubvolumes = (Xmax - Xmin) / mesh_delt; if (NumXsubvolumes <= 0) NumXsubvolumes = 1;
930 Standard_Integer NumYsubvolumes = (Ymax - Ymin) / mesh_delt; if (NumYsubvolumes <= 0) NumYsubvolumes = 1;
931 Standard_Integer NumZsubvolumes = (Zmax - Zmin) / mesh_delt; if (NumZsubvolumes <= 0) NumZsubvolumes = 1;
932 const Standard_Real StepX = (Xmax - Xmin) / NumXsubvolumes;
933 const Standard_Real StepY = (Ymax - Ymin) / NumYsubvolumes;
934 const Standard_Real StepZ = (Zmax - Zmin) / NumZsubvolumes;
935 const Standard_Integer NumSubvolumes = NumXsubvolumes * NumYsubvolumes * NumZsubvolumes;
936 di << "Info: NumSubvolumesX = " << NumXsubvolumes << "\n";
937 di << "Info: NumSubvolumesY = " << NumYsubvolumes << "\n";
938 di << "Info: NumSubvolumesZ = " << NumZsubvolumes << "\n";
939 di << "Info: NumSubvolumes = " << NumSubvolumes << "\n";
942 // construct initial mesh of cutSolid
944 TopTools_Array1OfShape SubvolumeSolid(0,NumSubvolumes-1);
945 TColStd_Array1OfReal SubvolumeVol(0,NumSubvolumes-1);
946 Standard_Real accumulatedVolume = 0.0;
947 Standard_Integer i, j, k, l = 0;
948 Standard_Real x = Xmin;
949 for ( i = 0; i < NumXsubvolumes; i++ )
951 Standard_Real y = Ymin;
952 for ( j = 0; j < NumYsubvolumes; j++ )
954 Standard_Real z = Zmin;
955 for ( k = 0; k < NumZsubvolumes; k++ )
960 TopoDS_Shape aSubvolume = BRepPrimAPI_MakeBox(P, StepX, StepY, StepZ).Solid();
961 di<<"Info: box b_"<<l<<" "<<P.X()<<" "<<P.Y()<<" "<<P.Z()<<" "<<StepX<<" "<<StepY<<" "<<StepZ<<"\n";
962 if ( aSubvolume.IsNull())
964 di << "Error: could not construct subvolume " << l << "\n";
967 SubvolumeSolid.SetValue(l,aSubvolume);
968 GProp_GProps subvolumeVProps;
969 BRepGProp::VolumeProperties (SubvolumeSolid(l), subvolumeVProps);
970 const Standard_Real vol = subvolumeVProps.Mass();
971 di << "Info: original subvolume " << l << " volume = " << vol << "\n";
972 SubvolumeVol.SetValue(l,vol);
973 accumulatedVolume += vol;
981 di << "Info: Accumulated mesh volume = " << accumulatedVolume << "\n";
984 // trim mesh to cutSolid
986 accumulatedVolume = 0.0;
987 for ( l = 0; l < NumSubvolumes; l++ )
989 TopoDS_Shape copySolid = BRepBuilderAPI_Copy(cutSolid).Shape();
992 //////////#if ! defined(BRepAlgoAPI_def01)
993 ////////// BRepAlgoAPI_Common common(copySolid/*cutSolid*/, SubvolumeSolid(l));
995 ////////// BRepAlgo_Common common(copySolid/*cutSolid*/, SubvolumeSolid(l));
997 ////////// if (!common.IsDone())
999 ////////// cout << "Error: could not construct a common solid " << l << endl;
1000 ////////// return 1;
1003 TopoDS_Shape aCommonShape;
1004 if (IsBRepAlgoAPI) {
1005 di << "BRepAlgoAPI_Common common(copySolid/*cutSolid*/, SubvolumeSolid(l))" <<"\n";
1006 BRepAlgoAPI_Common common(copySolid/*cutSolid*/, SubvolumeSolid(l));
1007 if (!common.IsDone())
1009 di << "Error: could not construct a common solid " << l << "\n";
1012 aCommonShape = common.Shape();
1014 di << "BRepAlgo_Common common(copySolid/*cutSolid*/, SubvolumeSolid(l))" <<"\n";
1015 BRepAlgo_Common common(copySolid/*cutSolid*/, SubvolumeSolid(l));
1016 if (!common.IsDone())
1018 di << "Error: could not construct a common solid " << l << "\n";
1021 aCommonShape = common.Shape();
1024 // see if we have a solid
1026 TopoDS_Shape commonShape;
1027 //////////for (Ex.Init(common.Shape(), TopAbs_SOLID); Ex.More(); Ex.Next())
1028 for (Ex.Init(aCommonShape, TopAbs_SOLID); Ex.More(); Ex.Next())
1030 TopoDS_Solid sol = TopoDS::Solid(Ex.Current());
1031 if (!sol.IsNull()) { commonShape = sol; found_solid++; }
1033 if ( found_solid != 1 )
1035 di << "Info: Common operation " << l << " produced " << found_solid << " solids" << "\n";
1039 SubvolumeSolid.SetValue(l,commonShape);
1040 GProp_GProps subvolumeVProps;
1041 BRepGProp::VolumeProperties (SubvolumeSolid(l), subvolumeVProps);
1042 const Standard_Real vol = subvolumeVProps.Mass();
1043 const Standard_Boolean err = (vol > SubvolumeVol(l)) || (vol <= 0.0);
1044 //cout << (err? "ERROR" : "Info") << ": final subvolume " << l << " volume = " << vol << endl;
1046 di << "ERROR" << ": final subvolume " << l << " volume = " << vol << "\n";
1048 di << "Info" << ": final subvolume " << l << " volume = " << vol << "\n";
1049 accumulatedVolume += vol;
1053 sprintf(astr,"e_%d",l);
1054 DBRep::Set(astr,commonShape);
1058 di << "Info: Accumulated meshed volume = " << accumulatedVolume << "\n";
1063 void QABugs::Commands_13(Draw_Interpretor& theCommands) {
1064 char *group = "QABugs";
1066 theCommands.Add ("OCC332", "OCC332 [wall_thickness [dia1 [dia2 [length [major_radius]]]]]", __FILE__, OCC332bug, group);
1067 //////theCommands.Add("OCC544", "OCC544 [[[[[wT [[[[d1 [[[d2 [[R [length]]]]]", __FILE__, OCC544, group);
1068 theCommands.Add("OCC544", "OCC544 [[[[[wT [[[[d1 [[[d2 [[R [length [BRepAlgoAPI/BRepAlgo = 1/0]]]]]]", __FILE__, OCC544, group);
1069 //////theCommands.Add("OCC817", "OCC817 result mesh_delta", __FILE__, OCC817, group);
1070 theCommands.Add("OCC817", "OCC817 result mesh_delta [BRepAlgoAPI/BRepAlgo = 1/0]", __FILE__, OCC817, group);