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