//-------------------------------------------------------------------------------------------------- public TransformBodyTool(IEnumerable <Entity> targetList, PivotPoint pivotPoint, Options options) { Debug.Assert(targetList != null); foreach (var target in targetList) { Body body = null; if (target is Body) { body = (Body)target; } else if (target is Shape) { body = ((Shape)target).Body; } if (body != null && !_TargetBodies.Contains(body)) { _TargetBodies.Add(body); } } Debug.Assert(_TargetBodies.Any()); _PivotPoint = pivotPoint; _Options = options; _TargetAndLinkedBodies.Clear(); _TargetAndLinkedBodies.AddRange(_TargetBodies); foreach (var targetBody in _TargetBodies) { targetBody.PropertyChanged += _TargetBody_PropertyChanged; _TargetAndLinkedBodies.AddRange(targetBody.GetReferencedBodies()); } _TargetAndLinkedBodies = _TargetAndLinkedBodies.Distinct().ToList(); }
//-------------------------------------------------------------------------------------------------- void _ComputeCoordinateSystem() { TopoDS_Shape ocShape; if ((_TargetBodies.Count == 1) || _Options.HasFlag(Options.MultiBodyUseFirst)) { // Single body, or Multishape using pivot of first shape Body targetBody = _TargetBodies[0]; ocShape = targetBody.Shape?.GetTransformedBRep(); switch (_PivotPoint) { case PivotPoint.BodyPivot: _CoordinateSystem = targetBody.GetCoordinateSystem(); break; case PivotPoint.BoundingCenter: _CoordinateSystem = targetBody.GetCoordinateSystem(); if (ocShape != null) { _CoordinateSystem.Location = ocShape.BoundingBox().Center(); } break; case PivotPoint.MassCenter: _CoordinateSystem = targetBody.GetCoordinateSystem(); if (ocShape != null) { _CoordinateSystem.Location = ocShape.CenterOfMass(); } break; } if (_Options.HasFlag(Options.WorldSpaceOrientation)) { _CoordinateSystem = new Ax3(_CoordinateSystem.Location, Dir.DZ); } } else { // Multiple shapes, use BBox center for all as pivot, and world space axis Bnd_Box bndBox = new Bnd_Box(); foreach (var targetBody in _TargetBodies) { ocShape = targetBody.Shape?.GetTransformedBRep(); if (ocShape != null) { bndBox.Add(ocShape.BoundingBox()); } } _CoordinateSystem = Ax3.XOY; _CoordinateSystem.Location = bndBox.Center(); } }