0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / samples / mfc / occtdemo / GProps / GProps_Presentation.cpp
1 // GProps_Presentation.cpp: implementation of the GProps_Presentation class.
2 // Global Properties of Shapes
3 //////////////////////////////////////////////////////////////////////
4
5 #include "stdafx.h"
6 #include "GProps_Presentation.h"
7
8 #include <BRepTools.hxx>
9 #include <TopoDS_Shape.hxx>
10 #include <BRep_Builder.hxx>
11 #include <GProp_PGProps.hxx>
12 #include <TColgp_Array1OfPnt.hxx>
13 #include <TColStd_Array1OfReal.hxx>
14 #include <Geom_TrimmedCurve.hxx>
15 #include <Geom_Circle.hxx>
16 #include <BRepGProp.hxx>
17 #include <GProp_PrincipalProps.hxx>
18 #include <Geom_BezierCurve.hxx>
19 #include <TopoDS_Edge.hxx>
20 #include <BRepBuilderAPI_MakeEdge.hxx>
21 #include <BRepBuilderAPI_MakeWire.hxx>
22 #include <TopoDS_Wire.hxx>
23 #include <TopoDS_Shell.hxx>
24 #include <TopExp_Explorer.hxx>
25 #include <BRepBuilderAPI_MakeShell.hxx>
26 #include <TopoDS.hxx>
27 #include <TopoDS_Face.hxx>
28 #include <AIS_Point.hxx>
29 #include <TopoDS_Solid.hxx>
30 #include <ElCLib.hxx>
31 #include <Geom_SurfaceOfRevolution.hxx>
32 #include <BRepBuilderAPI_MakeFace.hxx>
33 #include <BRepBuilderAPI_Transform.hxx>
34 #include <gp_Ax2d.hxx>
35 #include <gp_Trsf2d.hxx>
36 #include <gp_Trsf.hxx>
37 #include <BRepBuilderAPI_MakeSolid.hxx>
38 #include <TopoDS_Compound.hxx>
39 #include <TColgp_Array2OfPnt.hxx>
40 #include <GeomAPI_PointsToBSplineSurface.hxx>
41
42
43 // Initialization of global variable with an instance of this class
44 OCCDemo_Presentation* OCCDemo_Presentation::Current = new GProps_Presentation;
45
46 // Initialization of array of samples
47 const GProps_Presentation::PSampleFuncType GProps_Presentation::SampleFuncs[] =
48 {
49   &GProps_Presentation::samplePoints,
50   &GProps_Presentation::sampleCurves,
51   &GProps_Presentation::sampleSurfaces,
52   &GProps_Presentation::sampleVolumes,
53   &GProps_Presentation::sampleSystem
54 };
55
56 #ifdef WNT
57  #define EOL "\r\n"
58 #else
59  #define EOL "\n"
60 #endif
61
62 #define CUSTOM_INERTIAL_ELEMS_COLOR Quantity_NOC_CYAN1
63 #define MAIN_ELEMS_COLOR Quantity_NOC_RED
64 #define SEC_AXIS_COLOR Quantity_NOC_GREEN
65
66 #define SCALE_FACTOR 15
67 #define SCALE_FACTOR_FOR_VECTORS SCALE_FACTOR*5
68
69 //////////////////////////////////////////////////////////////////////
70 // Construction/Destruction
71 //////////////////////////////////////////////////////////////////////
72
73 GProps_Presentation::GProps_Presentation()
74 {
75   myNbSamples = sizeof(SampleFuncs)/sizeof(PSampleFuncType);
76   setName ("Global Properties of Points, Lines, Surfaces and Volumes");
77 }
78
79 //////////////////////////////////////////////////////////////////////
80 // Sample execution
81 //////////////////////////////////////////////////////////////////////
82
83 void GProps_Presentation::DoSample()
84 {
85   getAISContext()->EraseAll();
86   if (myIndex >=0 && myIndex < myNbSamples)
87     (this->*SampleFuncs[myIndex])();
88 }
89
90 //////////////////////////////////////////////////////////////////////
91 // Sample functions
92 //////////////////////////////////////////////////////////////////////
93
94 Standard_Boolean GProps_Presentation::GProps(GProp_GProps& aProps, 
95                                              gp_Ax1& anAxisForInertialProp,
96                                              TCollection_AsciiString& theText,
97                                              TCollection_AsciiString theMassStr)
98 {
99   theText += EOL
100     "  gp_Pnt aCenterOfMass;// center of mass of the system" EOL
101     "  Standard_Real aMass; // mass of the system" EOL
102     "  " EOL
103     "  Standard_Real aRadiusOfGyration;// radius of gyration around a given axis" EOL
104     "  Standard_Real aMomentOfInertia; // moment of inertia around a given axis" EOL
105     "  " EOL
106     "  Standard_Real aPrincipalRadiusOfGyrationXX; // radiuses of gyration around " EOL
107     "  Standard_Real aPrincipalRadiusOfGyrationYY; // the main inertial axes" EOL
108     "  Standard_Real aPrincipalRadiusOfGyrationZZ;" EOL
109     "" EOL
110     "  Standard_Real aPrincipalMomentOfInertiaXX; // moments of inertia around " EOL
111     "  Standard_Real aPrincipalMomentOfInertiaYY; // the main inertial axes" EOL
112     "  Standard_Real aPrincipalMomentOfInertiaZZ;" EOL
113     "" EOL
114     "  gp_Ax1 anAxisForInertialProp; // axis to compute inertial properties" EOL
115     "  // initializing anAxisForInertialProp" EOL
116     "  // ..." EOL
117     "" EOL
118     "  GProp_PrincipalProps aPrincipalProps;   // the object that returns inertial properties" EOL
119     "  " EOL
120     "  gp_Vec aFInertiaAxVec;  // inertial axes as they are returned by aPrincipalProps" EOL
121     "  gp_Vec aSInertiaAxVec;" EOL
122     "  gp_Vec aTInertiaAxVec;" EOL
123     "" EOL
124     "  aCenterOfMass = aProps.CentreOfMass();" EOL
125     "  aMass = aProps.Mass();" EOL
126     "" EOL
127     "  // axis for calculation gyration and inertia properties" EOL
128     "  aPrincipalProps = aProps.PrincipalProperties();" EOL
129     "" EOL
130     "  if (!aPrincipalProps.HasSymmetryPoint())" EOL
131     "  {" EOL
132     "    aFInertiaAxVec = aPrincipalProps.FirstAxisOfInertia();" EOL
133     "" EOL
134     "    // computing a radiuses of gyration and moment of inertia " EOL
135     "    // around the main axes of inertia" EOL
136     "    aPrincipalProps.RadiusOfGyration(aPrincipalRadiusOfGyrationXX, " EOL
137     "      aPrincipalRadiusOfGyrationYY, aPrincipalRadiusOfGyrationZZ);" EOL
138     "    aPrincipalProps.Moments(aPrincipalMomentOfInertiaXX, " EOL
139     "      aPrincipalMomentOfInertiaYY, aPrincipalMomentOfInertiaZZ);    " EOL
140     "    " EOL
141     "    if (!aPrincipalProps.HasSymmetryAxis())" EOL
142     "    {" EOL
143     "      aSInertiaAxVec = aPrincipalProps.SecondAxisOfInertia();" EOL
144     "      aTInertiaAxVec = aPrincipalProps.ThirdAxisOfInertia();" EOL
145     "    }" EOL
146     "  }" EOL
147     "  " EOL
148     "  // computing a radius of gyration and moment of inertia around a given axis" EOL
149     "  aRadiusOfGyration = aProps.RadiusOfGyration(anAxisForInertialProp);" EOL
150     "  aMomentOfInertia = aProps.MomentOfInertia(anAxisForInertialProp);" EOL;
151   setResultText(theText.ToCString());
152
153   gp_Pnt aCenterOfMass;// center of mass of the system
154   Standard_Real aMass; // mass of the system
155   
156   Standard_Real aRadiusOfGyration;// radius of gyration around a given axis
157   Standard_Real aMomentOfInertia; // moment of inertia around a given axis
158   
159   Standard_Real aPrincipalRadiusOfGyrationXX; // radiuses of gyration around 
160   Standard_Real aPrincipalRadiusOfGyrationYY; // the main inertial axes
161   Standard_Real aPrincipalRadiusOfGyrationZZ;
162
163   Standard_Real aPrincipalMomentOfInertiaXX; // moments of inertia around 
164   Standard_Real aPrincipalMomentOfInertiaYY; // the main inertial axes
165   Standard_Real aPrincipalMomentOfInertiaZZ;
166
167   GProp_PrincipalProps aPrincipalProps;   // the object that returns inertial properties
168   
169   gp_Vec aFInertiaAxVec;  // inertial axes as they are returned by aPrincipalProps
170   gp_Vec aSInertiaAxVec;
171   gp_Vec aTInertiaAxVec;
172
173   aCenterOfMass = aProps.CentreOfMass();
174   aMass = aProps.Mass();
175
176   theText = theText + EOL EOL
177     "  //=================================================" EOL EOL
178
179     "  Total " + theMassStr + " = " + TCollection_AsciiString(aMass) + EOL
180     "  Center of mass: ["+TCollection_AsciiString(aCenterOfMass.X())+","
181                          +TCollection_AsciiString(aCenterOfMass.Y())+","
182                          +TCollection_AsciiString(aCenterOfMass.Z())+"]";
183
184   // axis for calculation gyration and inertia properties
185   aPrincipalProps = aProps.PrincipalProperties();
186
187   if (!aPrincipalProps.HasSymmetryPoint())
188   {
189     aFInertiaAxVec = aPrincipalProps.FirstAxisOfInertia();
190
191     // computing a radiuses of gyration and moment of inertia 
192     // around the main axes of inertia
193     aPrincipalProps.RadiusOfGyration(aPrincipalRadiusOfGyrationXX, 
194       aPrincipalRadiusOfGyrationYY, aPrincipalRadiusOfGyrationZZ);
195     aPrincipalProps.Moments(aPrincipalMomentOfInertiaXX, 
196       aPrincipalMomentOfInertiaYY, aPrincipalMomentOfInertiaZZ);    
197
198     theText = theText + EOL EOL
199       "  Moment of inertia around the first axis of inertia = " + TCollection_AsciiString(aPrincipalMomentOfInertiaXX) + EOL
200       "  Moment of inertia around the second axis of inertia = " + TCollection_AsciiString(aPrincipalMomentOfInertiaYY) + EOL
201       "  Moment of inertia around the third axis of inertia = " + TCollection_AsciiString(aPrincipalMomentOfInertiaZZ) + EOL EOL
202
203       "  Radius of gyration around the first axis of inertia = " + TCollection_AsciiString(aPrincipalRadiusOfGyrationXX) + EOL      
204       "  Radius of gyration around the second axis of inertia = " + TCollection_AsciiString(aPrincipalRadiusOfGyrationYY) + EOL      
205       "  Radius of gyration around the third axis of inertia = " + TCollection_AsciiString(aPrincipalRadiusOfGyrationZZ);    
206     
207     if (!aPrincipalProps.HasSymmetryAxis())
208     {
209       aSInertiaAxVec = aPrincipalProps.SecondAxisOfInertia();
210       aTInertiaAxVec = aPrincipalProps.ThirdAxisOfInertia();
211     }
212   }
213   
214   // computing a radius of gyration and moment of inertia around a given axis
215   aRadiusOfGyration = aProps.RadiusOfGyration(anAxisForInertialProp);
216   aMomentOfInertia = aProps.MomentOfInertia(anAxisForInertialProp);
217
218   theText = theText + EOL + EOL
219       "  Radius of gyration around an axis = " + TCollection_AsciiString(aRadiusOfGyration) + EOL
220       "  Moment of inertia around an axis = " + TCollection_AsciiString(aMomentOfInertia) + EOL;      
221   setResultText(theText.ToCString());
222
223   // ========= output =======================================
224   // display the given axis
225   gp_Lin aLin(anAxisForInertialProp.Location(), anAxisForInertialProp.Direction());
226   // aParam = Parameter Of Projection Of CenterOfMass Onto AxisForInertialProp
227   Standard_Real aParam = ElCLib::Parameter(aLin, aCenterOfMass);
228   gp_Pnt aProjectedCenterOfMass = ElCLib::Value(aParam, aLin);
229   
230   gp_Ax2 anInertialCoordSys;
231   anInertialCoordSys.SetDirection(anAxisForInertialProp.Direction());
232   anInertialCoordSys.SetLocation(aProjectedCenterOfMass);
233
234   // display a point on the axis around which the properties were calculated
235   drawPoint(aProjectedCenterOfMass, CUSTOM_INERTIAL_ELEMS_COLOR);
236
237   // display the axis around which the properties were calculated
238   gp_Vec aVec(anAxisForInertialProp.Direction());
239   aVec.SetXYZ(aVec.XYZ()*SCALE_FACTOR_FOR_VECTORS);
240   drawVector(aProjectedCenterOfMass, aVec, CUSTOM_INERTIAL_ELEMS_COLOR);
241
242   if (WAIT_A_SECOND) return Standard_False;
243
244   Handle(AIS_Point) aPointIO = drawPoint(
245     aCenterOfMass, MAIN_ELEMS_COLOR, Standard_False);
246   aPointIO->UnsetMarker();
247   aPointIO->SetMarker(Aspect_TOM_O);
248   getAISContext()->Display(aPointIO);
249
250   if (WAIT_A_SECOND) return Standard_False;
251
252   // displaying inertial axes, main in red, other use default color
253   if (!aPrincipalProps.HasSymmetryPoint())
254   {
255     aFInertiaAxVec.SetXYZ(aFInertiaAxVec.XYZ()*SCALE_FACTOR_FOR_VECTORS);
256     drawVector(aCenterOfMass, aFInertiaAxVec, MAIN_ELEMS_COLOR);
257     if (!aPrincipalProps.HasSymmetryAxis())
258     {
259       aSInertiaAxVec.SetXYZ(aSInertiaAxVec.XYZ()*SCALE_FACTOR_FOR_VECTORS);
260       aTInertiaAxVec.SetXYZ(aTInertiaAxVec.XYZ()*SCALE_FACTOR_FOR_VECTORS);  
261       drawVector(aCenterOfMass, aSInertiaAxVec, SEC_AXIS_COLOR);
262       drawVector(aCenterOfMass, aTInertiaAxVec, SEC_AXIS_COLOR);
263     }
264     if (WAIT_A_SECOND) return Standard_False;
265   }
266
267   // display the cirle with radius = aRadiusOfGyration
268   Handle(Geom_Circle) aCirc = new Geom_Circle(anInertialCoordSys, aRadiusOfGyration);
269   drawCurve(aCirc, CUSTOM_INERTIAL_ELEMS_COLOR);
270
271   return Standard_True;
272 }
273
274
275 //================================================================
276 // Function : GProps_Presentation::samplePoints
277 // Purpose  : 
278 //================================================================
279 void GProps_Presentation::samplePoints()
280 {
281   ResetView();
282   SetViewCenter(63.470922672300, 35.981561054950);
283   SetViewScale(4.2572644504009); 
284
285   setResultTitle("Global Properties of Points");
286   TCollection_AsciiString aText(
287     "  TColgp_Array1OfPnt aPoints (1, nPoints); // points to analyze" EOL
288     "  TColStd_Array1OfReal aDens (1, nPoints); // dencities of points, weights" EOL
289     "  // initializing arrays of points and densities" EOL
290     "  // ..." EOL
291     "" EOL
292     "  GProp_PGProps aProps(aPoints, aDens);" EOL
293     "" EOL
294     "  gp_Pnt aBaryCentre;  // geometric centre of shape that consists all the points" EOL
295     "  aBaryCentre = GProp_PGProps::Barycentre(aPoints);" EOL);
296
297   // points to build the curves
298   Standard_Real aCoords[][3] = {
299     {0,0,0},{0,1,0},{1,1,0.2},{1,2,0.2},{2,2,0.4},{2,1,0.4},{3,1,0.6},{3,0,0.6},
300     {2,0,0.8},{2,-1,0},{3,-1,0},{3,-2,-0.5},{4,-2,1},{4,-1,1.2},{5,-1,1.2},
301     {5,0,1.4},{6,0,1.4},{6,-1,1.6},{7,-1,1.6},{7,0,1.8},{8,0,1.8},{8,1,2}
302   };
303   Standard_Integer nPoints = sizeof(aCoords)/(sizeof(Standard_Real)*3);
304   TColgp_Array1OfPnt aPoints (1, nPoints); // points to analyze
305   TColStd_Array1OfReal aDens (1, nPoints); // dencities of points, weights
306   Standard_Integer aOneColorSection = nPoints/5;
307   Standard_Integer k = SCALE_FACTOR;
308   for (Standard_Integer i=0; i < nPoints; i++)
309   {
310     aPoints(i+1) = gp_Pnt (aCoords[i][0]*k, aCoords[i][1]*k, aCoords[i][2]*k);
311     aDens(i+1) = i*10+1; 
312     
313     // displaying points in different colors according to their weight
314     Quantity_NameOfColor aColorName = Quantity_NOC_BLUE1;
315     if      (i <= 1*aOneColorSection) aColorName = Quantity_NOC_WHITESMOKE;
316     else if (i <= 2*aOneColorSection) aColorName = Quantity_NOC_ANTIQUEWHITE1;
317     else if (i <= 3*aOneColorSection) aColorName = Quantity_NOC_YELLOW;
318     else if (i <= 4*aOneColorSection) aColorName = Quantity_NOC_GREEN;
319
320     drawPoint(aPoints(i+1), Quantity_Color(aColorName));
321   }
322
323   GProp_PGProps aProps(aPoints, aDens);
324
325   gp_Pnt aBaryCentre;  // geometric centre of shape that consists all the points
326   aBaryCentre = GProp_PGProps::Barycentre(aPoints);
327
328   //if (WAIT_A_SECOND) return;
329
330   Handle(AIS_Point) aPointIO = drawPoint(
331     aBaryCentre, MAIN_ELEMS_COLOR, Standard_False);
332   aPointIO->SetMarker(Aspect_TOM_STAR);
333   getAISContext()->Display(aPointIO);
334
335   // building a CUSTOM axis for calculation of inertial properties
336   gp_Ax1 anAxisForInertialProp(gp_Pnt(5*k,5*k,5*k), gp_Dir(0.2,0.8,0));
337
338   if (!GProps(aProps, anAxisForInertialProp, aText, "Mass")) return;
339 }
340
341
342 //================================================================
343 // Function : GProps_Presentation::sampleCurves
344 // Purpose  : 
345 //================================================================
346 void GProps_Presentation::sampleCurves()
347
348   ResetView();
349   SetViewCenter(61.308121161914, 17.674575084056);
350   SetViewScale(5.3585487153415); 
351
352   setResultTitle("Global Linear Properties of Curves");
353   TCollection_AsciiString aText(
354     "  TopoDS_Wire aWire;" EOL
355     "  // initializing aWire" EOL
356     "  // ..." EOL
357     "  GProp_GProps aProps; // Global properties object" EOL
358     "" EOL
359     "  // initializing Global properties object with linear properties of aWire" EOL
360     "  BRepGProp::LinearProperties(aWire, aProps);" EOL);
361
362   // constructing a wire made of several edges
363   // initializing array of points mainly used for construction of anEdge2
364   Standard_Real aCoords[][3] = {
365     {0,0,0},{0,1,0},{1,1,0.2},{1,2,0.2},{2,2,0.4},{2,1,0.4},{3,1,0.6},{3,0,0.6},
366     {2,0,0.8},{2,-1,0},{3,-1,0},{3,-2,-0.5},{4,-2,1},{4,-1,1.2},{5,-1,1.2},
367     {5,0,1.4},{6,0,1.4},{6,-1,1.6},{7,-1,1.6},{7,0,1.8},{8,0,1.8},{8,1,2}
368   };
369   Standard_Integer nPoints = sizeof(aCoords)/(sizeof(Standard_Real)*3);
370   TColgp_Array1OfPnt aPoints (1, nPoints); 
371   Standard_Integer k = SCALE_FACTOR;
372   for (Standard_Integer i=0; i < nPoints; i++)
373     aPoints(i+1) = gp_Pnt (aCoords[i][0]*k, aCoords[i][1]*k, aCoords[i][2]*k);
374
375   // edge 2 is a bezier curve that starts in edge1's end point
376   Handle(Geom_BezierCurve) aCurve = new Geom_BezierCurve(aPoints);
377   TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(aCurve);
378
379   // edge 1 is a linear edge between 2 points
380   TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(-k, -k, 0), aCurve->StartPoint());
381
382   // edge 3 is a linear section as well
383   //TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(aCurve->EndPoint(), gp_Pnt(1000, 300, 400));
384
385   // creating a wire that consists of the edges defined above
386   TopoDS_Wire aWire = BRepBuilderAPI_MakeWire (anEdge1, anEdge2);
387
388   drawShape(aWire);
389
390   GProp_GProps aProps; // Global properties object
391
392   // initializing Global properties object with linear properties of aWire
393   BRepGProp::LinearProperties(aWire, aProps);
394
395   // building a CUSTOM axis for calculation of inertial properties
396   gp_Ax1 anAxisForInertialProp(gp_Pnt(5*k,3*k,3*k), gp_Dir(0.1,0.2,0.7));
397
398   if (!GProps(aProps, anAxisForInertialProp, aText, "Length")) return;
399 }
400
401 //================================================================
402 // Function : GProps_Presentation::sampleSurfaces
403 // Purpose  : 
404 //================================================================
405 void GProps_Presentation::sampleSurfaces()
406 {
407   ResetView();
408   SetViewCenter(7.3480331410807, 5.9413176110886);
409   SetViewScale(6.0684301060407); 
410
411   setResultTitle("Global Surface Properties of Shapes");
412   TCollection_AsciiString aText(
413     "  TopoDS_Shell aShell;" EOL
414     "  // initializing initial surface" EOL
415     "  // ..." EOL
416     "" EOL
417     "  GProp_GProps aProps; // Global properties object" EOL
418     "" EOL
419     "  // initializing Global properties object with surface properties of aShell" EOL
420     "  BRepGProp::SurfaceProperties(aShell, aProps);" EOL);
421
422   // constructing initial surface
423   Standard_Real aZCoords [] = {{-1},{0},{0},{1},{0},{-1},{-1},{0},{0},{-1.5},{-2.5},{0},{1},{-2},{-3},{0}}; 
424   
425   TColStd_Array2OfReal aZPoints(1,4,1,4);
426   TColgp_Array2OfPnt aPnt(1,4,1,4);
427    
428   Standard_Integer aColLength = aZPoints.ColLength();
429   Standard_Integer aRowLength = aZPoints.RowLength();
430   Standard_Integer aIndex = 0;
431   Standard_Integer k = SCALE_FACTOR;
432   
433   for(Standard_Integer i = 0 ; i < aRowLength ; i++)
434     for(Standard_Integer j = 0; j < aColLength ; j++)
435       aZPoints(i+1,j+1) = (aZCoords[aIndex++] * k);
436
437   Standard_Real aXStep = 1.75*k, aYStep = 1.75*k;
438   Standard_Real aXBound = -3*k, aYBound = -2*k;
439   
440   GeomAPI_PointsToBSplineSurface aPTBS(
441     aZPoints,aXBound,aXStep,aYBound,aYStep,3,8,GeomAbs_C3,k);
442
443   TopoDS_Shell aShell = BRepBuilderAPI_MakeShell(aPTBS.Surface());
444
445   drawShape(aShell);
446
447   GProp_GProps aProps; // Global properties object
448
449   // initializing Global properties object with surface properties of aShell
450   BRepGProp::SurfaceProperties(aShell, aProps);
451
452   // building a CUSTOM axis for calculation of inertial properties
453   gp_Ax1 anAxisForInertialProp(gp_Pnt(-3*k,-3*k,-3*k), gp_Dir(0.33,0.33,0.33));
454
455   if (!GProps(aProps, anAxisForInertialProp, aText, "Area")) return;
456 }
457
458 //================================================================
459 // Function : GProps_Presentation::sampleVolumes
460 // Purpose  : 
461 //================================================================
462 void GProps_Presentation::sampleVolumes()
463
464   ResetView();
465   SetViewCenter(83.572045344035, 38.188854653904);
466   SetViewScale(5.2570164985648); 
467
468   setResultTitle("Global Volume Properties of Solids");
469   TCollection_AsciiString aText(
470     "  TopoDS_Solid aSolid;" EOL
471     "  // initializing the solid" EOL
472     "  // ..." EOL
473     "" EOL
474     "  GProp_GProps aProps;   // Global properties object" EOL
475     "" EOL
476     "  // initializing Global properties object with volume properties of aSolid" EOL
477     "  BRepGProp::VolumeProperties(aSolid, aProps);" EOL);
478
479   // constructing initial surface
480   TopoDS_Shape aShape;
481   BRep_Builder aBuilder;
482   TCollection_AsciiString aFileName(GetDataDir());
483   aFileName += "\\shape1.brep";
484   Standard_Boolean Result = BRepTools::Read(aShape, aFileName.ToCString(), aBuilder);
485
486   if (!Result)
487   {
488     aFileName += " was not found.  The sample can not be shown.";
489     setResultText(aFileName.ToCString());
490     return;
491   }
492
493   TopoDS_Solid aSolid;
494   TopExp_Explorer anExp(aShape, TopAbs_SOLID);
495   if (anExp.More()) 
496     aSolid = TopoDS::Solid(anExp.Current());
497
498   drawShape(aSolid);
499
500   GProp_GProps aProps;   // Global properties object
501
502   // initializing Global properties object with volume properties of aSolid
503   BRepGProp::VolumeProperties(aSolid, aProps);
504
505   // building a CUSTOM axis for calculation of inertial properties
506   Standard_Integer k = SCALE_FACTOR;
507   gp_Ax1 anAxisForInertialProp(gp_Pnt(2.5*k,2.5*k,2.5*k), gp_Dir(0.2,0.8,0));
508
509   if (!GProps(aProps, anAxisForInertialProp, aText, "Volume")) return;
510 }
511
512
513 //================================================================
514 // Function : GProps_Presentation::sampleSystem
515 // Purpose  : 
516 //================================================================
517 void GProps_Presentation::sampleSystem()
518 {  
519   ResetView();
520   SetViewCenter(107.10015835676, 76.510352154100);
521   SetViewScale(2.3110667631188); 
522
523   setResultTitle("Global Properties of System of Shapes");
524   TCollection_AsciiString aText(
525     "  TopoDS_Compound aShape;" EOL
526     "  // initializing the shape" EOL
527     "  // ..." EOL
528     "" EOL
529     "  GProp_GProps aProps;" EOL
530     "  GProp_GProps aLinearProps;" EOL
531     "  GProp_GProps aSurfaceProps;" EOL
532     "  GProp_GProps aVolumeProps;" EOL
533     "" EOL
534     "  // creating a linear system, system that consists of all edges" EOL
535     "  TopExp_Explorer anExp(aShape, TopAbs_EDGE, TopAbs_FACE);" EOL
536     "  while (anExp.More())" EOL
537     "  {" EOL
538     "    GProp_GProps lp;" EOL
539     "    BRepGProp::LinearProperties(anExp.Current(), lp);" EOL
540     "    aLinearProps.Add(lp);" EOL
541     "    anExp.Next();" EOL
542     "  }" EOL
543     "" EOL
544     "  // creating a surface system, system that consists of all faces" EOL
545     "  anExp.Init(aShape, TopAbs_FACE, TopAbs_SHELL);" EOL
546     "  while (anExp.More())" EOL
547     "  {" EOL
548     "    GProp_GProps sp;" EOL
549     "    BRepGProp::SurfaceProperties(anExp.Current(), sp);" EOL
550     "    aSurfaceProps.Add(sp);" EOL
551     "    anExp.Next();" EOL
552     "  }" EOL
553     "" EOL
554     "  // creating a volume system, system that consists of all solids" EOL
555     "  anExp.Init(aShape, TopAbs_SOLID);" EOL
556     "  while (anExp.More())" EOL
557     "  {" EOL
558     "    GProp_GProps vp;" EOL
559     "    BRepGProp::VolumeProperties(anExp.Current(), vp);" EOL
560     "    aVolumeProps.Add(vp);" EOL
561     "    anExp.Next();" EOL
562     "  }" EOL
563     "" EOL
564     "  Standard_Real aSurfaceDensity = 2;" EOL
565     "  Standard_Real aVolumeDensity = 3;" EOL
566     "  aProps.Add (aLinearProps); // density = 1.0" EOL
567     "  aProps.Add (aSurfaceProps, aSurfaceDensity);" EOL
568     "  aProps.Add (aVolumeProps, aVolumeDensity);" EOL);
569
570   // building a shape "space ship" that consists of a solid, 2 faces, and 2 edges
571   Standard_Real aCoords[][3] = {{3,-1,0},{1,0,0},{0,1,0},{0,7,0},{1,8,0},{3,9,0}};
572   Standard_Integer nPoints = sizeof(aCoords)/(sizeof(Standard_Real)*3);
573   TColgp_Array1OfPnt aPoints (1, nPoints);
574   Standard_Integer k = 15;
575   for (Standard_Integer i=0; i < nPoints; i++)
576     aPoints(i+1) = gp_Pnt (aCoords[i][0]*k, aCoords[i][1]*k, aCoords[i][2]*k);
577
578   Handle(Geom_BezierCurve) aCurve = new Geom_BezierCurve(aPoints);
579   gp_Ax1 anAxis(aPoints(1), gp_Dir(0,1,0));
580   Handle(Geom_SurfaceOfRevolution) aSurface = new Geom_SurfaceOfRevolution(aCurve, anAxis);
581   TopoDS_Solid aSolid = BRepBuilderAPI_MakeSolid(BRepBuilderAPI_MakeShell(aSurface));
582
583   TopoDS_Edge e1 = BRepBuilderAPI_MakeEdge(gp_Pnt(5*k, 2*k, 0), gp_Pnt(12*k, 7*k, 0));
584   TopoDS_Edge e2 = BRepBuilderAPI_MakeEdge(gp_Pnt(12*k, 7*k, 0), gp_Pnt(12*k, 11*k, 0));
585   TopoDS_Edge e3 = BRepBuilderAPI_MakeEdge(gp_Pnt(12*k, 11*k, 0), gp_Pnt(5*k, 5*k, 0));
586   TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(gp_Pnt(5*k, 5*k, 0), gp_Pnt(5*k, 2*k, 0));
587   TopoDS_Face aWing1 = BRepBuilderAPI_MakeFace(BRepBuilderAPI_MakeWire(e1, e2, e3, e4));
588
589   gp_Ax2d aMirrorAx(gp_Pnt2d(3*k, 0), gp_Dir2d(0,1));
590   gp_Trsf2d aTrsf2d;
591   aTrsf2d.SetMirror(aMirrorAx);
592   gp_Trsf aTrsf(aTrsf2d);
593   BRepBuilderAPI_Transform aBuilder(aWing1, aTrsf, Standard_True);
594
595   aBuilder.Perform(aWing1, Standard_True);
596   TopoDS_Face aWing2 = TopoDS::Face(aBuilder.Shape());
597
598   Handle(Geom_Circle) aCirc = new Geom_Circle(gp_Ax2(gp_Pnt(3*k, 11*k, 0), gp_Dir(0,-0.2,0.8)), (12-3)*k);
599   Handle(Geom_TrimmedCurve) aTrimCirc = new Geom_TrimmedCurve(aCirc, -PI/2, PI/2);
600   TopoDS_Edge aSpoiler = BRepBuilderAPI_MakeEdge(aTrimCirc);
601
602   TopoDS_Edge anArrow = BRepBuilderAPI_MakeEdge(gp_Pnt(3*k, 0, 0), gp_Pnt(3*k, -5*k, 0));
603   
604   TopoDS_Compound aShape;
605   BRep_Builder aCompoundBuilder;
606   aCompoundBuilder.MakeCompound(aShape);
607   aCompoundBuilder.Add(aShape,aSolid);
608   aCompoundBuilder.Add(aShape,aWing1);
609   aCompoundBuilder.Add(aShape,aWing2);
610   aCompoundBuilder.Add(aShape,anArrow);
611   aCompoundBuilder.Add(aShape,aSpoiler);
612
613   drawShape(aSolid);
614   drawShape(aWing1);
615   drawShape(aWing2);
616   drawShape(anArrow, Quantity_NOC_GOLD);
617   drawShape(aSpoiler, Quantity_NOC_GOLD);
618
619   GProp_GProps aProps;
620   GProp_GProps aLinearProps;
621   GProp_GProps aSurfaceProps;
622   GProp_GProps aVolumeProps;
623
624   GProp_PrincipalProps aPrincipalProps;
625
626   // creating a linear system, system that consists of all edges
627   TopExp_Explorer anExp(aShape, TopAbs_EDGE, TopAbs_FACE);
628   while (anExp.More())
629   {
630     GProp_GProps lp;
631     BRepGProp::LinearProperties(anExp.Current(), lp);
632     aLinearProps.Add(lp);
633     anExp.Next();
634   }
635
636   // creating a surface system, system that consists of all faces
637   anExp.Init(aShape, TopAbs_FACE, TopAbs_SHELL);
638   while (anExp.More())
639   {
640     GProp_GProps sp;
641     BRepGProp::SurfaceProperties(anExp.Current(), sp);
642     aSurfaceProps.Add(sp);
643     anExp.Next();
644   }
645
646   // creating a volume system, system that consists of all solids
647   anExp.Init(aShape, TopAbs_SOLID);
648   while (anExp.More())
649   {
650     GProp_GProps vp;
651     BRepGProp::VolumeProperties(anExp.Current(), vp);
652     aVolumeProps.Add(vp);
653     anExp.Next();
654   }
655
656   Standard_Real aSurfaceDensity = 2;
657   Standard_Real aVolumeDensity = 3;
658   aProps.Add (aLinearProps); // density = 1.0
659   aProps.Add (aSurfaceProps, aSurfaceDensity);
660   aProps.Add (aVolumeProps, aVolumeDensity);
661
662   // Length of free edges
663   Standard_Real aEdgesLength = aLinearProps.Mass();
664   Standard_Real aFacesArea = aSurfaceProps.Mass();
665   Standard_Real aSolidsVolume = aVolumeProps.Mass();
666
667   // building a CUSTOM axis for calculation of inertial properties
668   gp_Ax1 anAxisForInertialProp(gp_Pnt(3.5*k,2*k,7*k), gp_Dir(-0.33,-0.33,-0.33));
669
670   if (!GProps(aProps, anAxisForInertialProp, aText, "Mass")) return;
671
672   aText = aText + EOL
673     "  Length of free edges = " + TCollection_AsciiString(aEdgesLength) + EOL
674     "  Area of free faces = " + TCollection_AsciiString(aFacesArea) + EOL
675     "  Volume of solids = " + TCollection_AsciiString(aSolidsVolume);
676   setResultText(aText.ToCString());
677 }