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