1 // Created on: 1994-02-18
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <Standard_Stream.hxx>
23 #include <BRepTest.hxx>
24 #include <Draw_Interpretor.hxx>
25 #include <Draw_Appli.hxx>
27 #include <BRepGProp.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <GProp_PrincipalProps.hxx>
33 #include <Draw_Axis3D.hxx>
34 #include <Precision.hxx>
35 #include <OSD_Chronometer.hxx>
36 #include <Geom_Surface.hxx>
37 #include <DrawTrSurf.hxx>
38 #include <Geom_Plane.hxx>
42 Standard_IMPORT Draw_Viewer dout;
46 Standard_Integer props(Draw_Interpretor& di, Standard_Integer n, const char** a)
49 di << "Use: " << a[0] << " shape [epsilon] [c[losed]] [x y z]" << "\n";
50 di << "Compute properties of the shape" << "\n";
51 di << "The epsilon, if given, defines relative precision of computation" << "\n";
52 di << "The \"closed\" flag, if present, do computation only closed shells of the shape" << "\n";
53 di << "The centroid coordinates will be put to DRAW variables x y z (if given)\n" << "\n";
57 TopoDS_Shape S = DBRep::Get(a[1]);
58 if (S.IsNull()) return 0;
62 Standard_Boolean onlyClosed = Standard_False;
63 Standard_Real eps = 1.0;
64 Standard_Boolean witheps = Standard_False;
65 if(n > 2 && *a[2]=='c' || n > 3 && *a[3]=='c') onlyClosed = Standard_True;
66 if(n > 2 && *a[2]!='c' && n != 5) {eps = Draw::Atof (a[2]); witheps = Standard_True;}
69 if (Abs(eps) < Precision::Angular()) return 2;
71 BRepGProp::LinearProperties(S,G);
72 else if (*a[0] == 's')
73 eps = BRepGProp::SurfaceProperties(S,G,eps);
75 eps = BRepGProp::VolumeProperties(S,G,eps,onlyClosed);
79 BRepGProp::LinearProperties(S,G);
80 else if (*a[0] == 's')
81 BRepGProp::SurfaceProperties(S,G);
83 BRepGProp::VolumeProperties(S,G,onlyClosed);
86 gp_Pnt P = G.CentreOfMass();
87 gp_Mat I = G.MatrixOfInertia();
90 Standard_Integer shift = n - 5;
91 Draw::Set(a[shift+2],P.X());
92 Draw::Set(a[shift+3],P.Y());
93 Draw::Set(a[shift+4],P.Z());
96 Standard_SStream aSStream1;
98 aSStream1 << "Mass : " << setw(15) << G.Mass() << "\n" << "\n";
99 if(witheps && *a[0] != 'l') aSStream1 << "Relative error of mass computation : " << setw(15) << eps << "\n" << "\n";
101 aSStream1 << "Center of gravity : \n";
102 aSStream1 << "X = " << setw(15) << P.X() << "\n";
103 aSStream1 << "Y = " << setw(15) << P.Y() << "\n";
104 aSStream1 << "Z = " << setw(15) << P.Z() << "\n";
107 aSStream1 << "Matrix of Inertia : \n";
108 aSStream1 << setw(15) << I(1,1);
109 aSStream1 << " " << setw(15) << I(1,2);
110 aSStream1 << " " << setw(15) << I(1,3) << "\n";
111 aSStream1 << setw(15) << I(2,1);
112 aSStream1 << " " << setw(15) << I(2,2);
113 aSStream1 << " " << setw(15) << I(2,3) << "\n";
114 aSStream1 << setw(15) << I(3,1);
115 aSStream1 << " " << setw(15) << I(3,2);
116 aSStream1 << " " << setw(15) << I(3,3) << "\n";
121 GProp_PrincipalProps Pr = G.PrincipalProperties();
123 Standard_Real Ix,Iy,Iz;
124 Pr.Moments(Ix,Iy,Iz);
126 Standard_SStream aSStream2;
127 aSStream2 << "Moments : \n";
128 aSStream2 << "IX = " << setw(15) << Ix << "\n";
129 aSStream2 << "IY = " << setw(15) << Iy << "\n";
130 aSStream2 << "IZ = " << setw(15) << Iz << "\n";
136 gp_Ax2 axes(P,Pr.ThirdAxisOfInertia(),Pr.FirstAxisOfInertia());
138 Handle(Draw_Axis3D) Dax = new Draw_Axis3D(axes,Draw_orange,30);
146 Standard_Integer vpropsgk(Draw_Interpretor& di, Standard_Integer n, const char** a)
149 di << "Use: " << a[0] << " shape epsilon closed span mode [x y z]" << "\n";
150 di << "Compute properties of the shape" << "\n";
151 di << "The epsilon defines relative precision of computation" << "\n";
152 di << "The \"closed\" flag, if equal 1, causes computation only closed shells of the shape" << "\n";
153 di << "The \"span\" flag, if equal 1, says that computation is performed on spans" << "\n";
154 di << " This option makes effect only for BSpline surfaces." << "\n";
155 di << "mode can be 0 - only volume calculations" << "\n";
156 di << " 1 - volume and gravity center" << "\n";
157 di << " 2 - volume, gravity center and matrix of inertia" << "\n";
158 di << "The centroid coordinates will be put to DRAW variables x y z (if given)\n" << "\n";
162 if ( n > 2 && n < 6) {
163 di << "Wrong arguments" << "\n";
167 TopoDS_Shape S = DBRep::Get(a[1]);
168 if (S.IsNull()) return 0;
172 Standard_Boolean onlyClosed = Standard_False;
173 Standard_Boolean isUseSpan = Standard_False;
174 Standard_Boolean CGFlag = Standard_False;
175 Standard_Boolean IFlag = Standard_False;
176 Standard_Real eps = 1.e-3;
177 //Standard_Real aDefaultTol = 1.e-3;
178 Standard_Integer mode = 0;
180 eps = Draw::Atof(a[2]);
181 mode = Draw::Atoi(a[3]);
182 if(mode > 0) onlyClosed = Standard_True;
183 mode = Draw::Atoi(a[4]);
184 if(mode > 0) isUseSpan = Standard_True;
186 mode = Draw::Atoi(a[5]);
187 if(mode == 1 || mode == 3) CGFlag = Standard_True;
188 if(mode == 2 || mode == 3) IFlag = Standard_True;
190 //OSD_Chronometer aChrono;
194 eps = BRepGProp::VolumePropertiesGK(S, G, eps, onlyClosed, isUseSpan, CGFlag, IFlag);
197 Standard_SStream aSStream0;
198 Standard_Integer anOutWidth = 24;
200 aSStream0.precision(15);
202 aSStream0 << "Mass : " << setw(anOutWidth) << G.Mass() << "\n" << "\n";
203 aSStream0 << "Relative error of mass computation : " << setw(anOutWidth) << eps << "\n" << "\n";
207 if(CGFlag || IFlag) {
208 Standard_SStream aSStream1;
209 gp_Pnt P = G.CentreOfMass();
211 Draw::Set(a[6],P.X());
214 Draw::Set(a[7],P.Y());
217 Draw::Set(a[8],P.Z());
220 aSStream1.precision(15);
221 aSStream1 << "Center of gravity : \n";
222 aSStream1 << "X = " << setw(anOutWidth) << P.X() << "\n";
223 aSStream1 << "Y = " << setw(anOutWidth) << P.Y() << "\n";
224 aSStream1 << "Z = " << setw(anOutWidth) << P.Z() << "\n";
228 gp_Mat I = G.MatrixOfInertia();
230 aSStream1 << "Matrix of Inertia : \n";
231 aSStream1 << setw(anOutWidth) << I(1,1);
232 aSStream1 << " " << setw(anOutWidth) << I(1,2);
233 aSStream1 << " " << setw(anOutWidth) << I(1,3) << "\n";
234 aSStream1 << setw(anOutWidth) << I(2,1);
235 aSStream1 << " " << setw(anOutWidth) << I(2,2);
236 aSStream1 << " " << setw(anOutWidth) << I(2,3) << "\n";
237 aSStream1 << setw(anOutWidth) << I(3,1);
238 aSStream1 << " " << setw(anOutWidth) << I(3,2);
239 aSStream1 << " " << setw(anOutWidth) << I(3,3) << "\n";
248 GProp_PrincipalProps Pr = G.PrincipalProperties();
250 Standard_Real Ix,Iy,Iz;
251 Pr.Moments(Ix,Iy,Iz);
252 gp_Pnt P = G.CentreOfMass();
254 Standard_SStream aSStream2;
256 aSStream2.precision(15);
257 aSStream2 << "Moments : \n";
258 aSStream2 << "IX = " << setw(anOutWidth) << Ix << "\n";
259 aSStream2 << "IY = " << setw(anOutWidth) << Iy << "\n";
260 aSStream2 << "IZ = " << setw(anOutWidth) << Iz << "\n";
266 gp_Ax2 axes(P,Pr.ThirdAxisOfInertia(),Pr.FirstAxisOfInertia());
268 Handle(Draw_Axis3D) Dax = new Draw_Axis3D(axes,Draw_orange,30);
275 //=======================================================================
276 //function : GPropCommands
278 //=======================================================================
280 void BRepTest::GPropCommands(Draw_Interpretor& theCommands)
282 static Standard_Boolean done = Standard_False;
284 done = Standard_True;
286 DBRep::BasicCommands(theCommands);
288 const char* g = "Global properties";
289 theCommands.Add("lprops",
290 "lprops name [epsilon] [x y z] : compute linear properties",
294 theCommands.Add("sprops",
295 "sprops name [epsilon] [x y z] : compute surfacic properties",
299 theCommands.Add("vprops",
300 "vprops name [epsilon] [c[losed]] [x y z] : compute volumic properties",
305 theCommands.Add("vpropsgk",
306 "vpropsgk name epsilon closed span mode [x y z] : compute volumic properties",