28
28
#include < BRepAdaptor_CompCurve.hxx>
29
29
#include < BRepAdaptor_Curve.hxx>
30
30
#include < BRepAdaptor_Surface.hxx>
31
+ #include < BRepBndLib.hxx>
31
32
#include < BRepClass_FaceClassifier.hxx>
32
33
#include < BRepGProp.hxx>
33
34
#include < BRepGProp_Face.hxx>
@@ -131,22 +132,14 @@ App::DocumentObjectExecReturn* Constraint::execute()
131
132
}
132
133
}
133
134
134
- // OvG: Provide the ability to determine how big to draw constraint arrows etc.
135
- unsigned int Constraint::calcSizeFactor (double lparam) const
135
+ // Provide the ability to determine how big to draw constraint arrows etc.
136
+ // Try to get symbol size equal to 1/5 of the characteristic length of
137
+ // the object. Typical symbol size is 5, so use 1/25 of the characteristic length.
138
+ double Constraint::calcSizeFactor (double characLen) const
136
139
{
137
- return (static_cast <int >(round (log (lparam) * log (lparam) * log (lparam) / 10 )) > 1 )
138
- ? (static_cast <int >(round (log (lparam) * log (lparam) * log (lparam) / 10 )))
139
- : 1 ;
140
- }
141
-
142
- unsigned int Constraint::calcSizeFactor (double lvparam, double luparam) const
143
- {
144
- return calcSizeFactor ((lvparam + luparam) / 2.0 );
145
- }
146
-
147
- unsigned int Constraint::calcSizeFactor () const
148
- {
149
- return 1 ;
140
+ double l = characLen / 25.0 ;
141
+ l = ((round (l)) > 1 ) ? round (l) : l;
142
+ return (l > Precision::Confusion () ? l : 1 );
150
143
}
151
144
152
145
float Constraint::getScaleFactor () const
@@ -272,7 +265,7 @@ void Constraint::handleChangedPropertyType(Base::XMLReader& reader,
272
265
273
266
bool Constraint::getPoints (std::vector<Base::Vector3d>& points,
274
267
std::vector<Base::Vector3d>& normals,
275
- int * scale) const
268
+ double * scale) const
276
269
{
277
270
std::vector<App::DocumentObject*> Objects = References.getValues ();
278
271
std::vector<std::string> SubElements = References.getSubValues ();
@@ -294,42 +287,35 @@ bool Constraint::getPoints(std::vector<Base::Vector3d>& points,
294
287
}
295
288
296
289
setSubShapeLocation (feat, sh);
290
+ // Scale by bounding box of the object
291
+ Bnd_Box box;
292
+ BRepBndLib::Add (toposhape.getShape (), box);
293
+ double l = sqrt (box.SquareExtent () / 3.0 );
294
+ *scale = this ->calcSizeFactor (l);
297
295
298
296
if (sh.ShapeType () == TopAbs_VERTEX) {
299
297
const TopoDS_Vertex& vertex = TopoDS::Vertex (sh);
300
298
gp_Pnt p = BRep_Tool::Pnt (vertex);
301
299
points.emplace_back (p.X (), p.Y (), p.Z ());
302
300
normals.push_back (NormalDirection.getValue ());
303
- // OvG: Scale by whole object mass in case of a vertex
304
- GProp_GProps props;
305
- BRepGProp::VolumeProperties (toposhape.getShape (), props);
306
- double lx = props.Mass ();
307
- // OvG: setup draw scale for constraint
308
- *scale = this ->calcSizeFactor (sqrt (lx) * 0.5 );
309
301
}
310
302
else if (sh.ShapeType () == TopAbs_EDGE) {
311
303
BRepAdaptor_Curve curve (TopoDS::Edge (sh));
312
304
double fp = curve.FirstParameter ();
313
305
double lp = curve.LastParameter ();
314
- GProp_GProps props;
315
- BRepGProp::LinearProperties (TopoDS::Edge (sh), props);
316
- double l = props.Mass ();
317
306
// Create points with 10 units distance, but at least one at the beginning and end of
318
307
// the edge
319
308
int steps;
320
309
// OvG: Increase 10 units distance proportionately to l for larger objects.
321
310
if (l >= 30 ) {
322
- *scale = this ->calcSizeFactor (l); // OvG: setup draw scale for constraint
323
311
steps = static_cast <int >(round (l / (10 * (*scale))));
324
312
steps = steps < 3 ? 3 : steps;
325
313
}
326
314
else if (l >= 20 ) {
327
315
steps = static_cast <int >(round (l / 10 ));
328
- *scale = this ->calcSizeFactor (); // OvG: setup draw scale for constraint
329
316
}
330
317
else {
331
318
steps = 1 ;
332
- *scale = this ->calcSizeFactor (); // OvG: setup draw scale for constraint
333
319
}
334
320
335
321
// OvG: Place upper limit on number of steps
@@ -407,37 +393,31 @@ bool Constraint::getPoints(std::vector<Base::Vector3d>& points,
407
393
// OvG: Increase 10 units distance proportionately to lv for larger objects.
408
394
int stepsv;
409
395
if (lv >= 30 ) {
410
- *scale = this ->calcSizeFactor (lv, lu); // OvG: setup draw scale for constraint
411
396
stepsv = static_cast <int >(round (lv / (10 * (*scale))));
412
397
stepsv = stepsv < 3 ? 3 : stepsv;
413
398
}
414
399
else if (lv >= 20.0 ) {
415
400
stepsv = static_cast <int >(round (lv / 10 ));
416
- *scale = this ->calcSizeFactor (); // OvG: setup draw scale for constraint
417
401
}
418
402
else {
419
403
// Minimum of three arrows to ensure (as much as possible) that at
420
404
// least one is displayed
421
405
stepsv = 2 ;
422
- *scale = this ->calcSizeFactor (); // OvG: setup draw scale for constraint
423
406
}
424
407
425
408
// OvG: Place upper limit on number of steps
426
409
stepsv = stepsv > CONSTRAINTSTEPLIMIT ? CONSTRAINTSTEPLIMIT : stepsv;
427
410
int stepsu;
428
411
// OvG: Increase 10 units distance proportionately to lu for larger objects.
429
412
if (lu >= 30 ) {
430
- *scale = this ->calcSizeFactor (lv, lu); // OvG: setup draw scale for constraint
431
413
stepsu = static_cast <int >(round (lu / (10 * (*scale))));
432
414
stepsu = stepsu < 3 ? 3 : stepsu;
433
415
}
434
416
else if (lu >= 20.0 ) {
435
417
stepsu = static_cast <int >(round (lu / 10 ));
436
- *scale = this ->calcSizeFactor (); // OvG: setup draw scale for constraint
437
418
}
438
419
else {
439
420
stepsu = 2 ;
440
- *scale = this ->calcSizeFactor (); // OvG: setup draw scale for constraint
441
421
}
442
422
443
423
// OvG: Place upper limit on number of steps
0 commit comments