//-------------------------------------------------------------------------------------------------- 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(); } }
//-------------------------------------------------------------------------------------------------- List <TopoDS_Shape> IShapeOperand.FindSubshape(SubshapeReference reference, Ax3?targetFrame) { if (Body == null) { return(null); } var shape = Shape; if (shape == null) { return(null); } var shapeList = shape.FindSubshape(reference, Body.GetCoordinateSystem()); if (shapeList != null && targetFrame.HasValue) { var location = _GetCachedLocation(targetFrame.Value); for (var i = 0; i < shapeList.Count; i++) { shapeList[i] = shapeList[i].Moved(location); } } return(shapeList); }
TopLoc_Location _GetCachedLocation(Ax3 targetFrame) { if (Body == null) { return(null); } var bodyFrame = Body.GetCoordinateSystem(); if (_CachedLocation.Item1 == bodyFrame && _CachedLocation.Item2 == targetFrame) { return(_CachedLocation.Item3); } var location = new TopLoc_Location(new Trsf(Body.GetCoordinateSystem(), targetFrame)); _CachedLocation = new Tuple <Ax3, Ax3, TopLoc_Location>(bodyFrame, targetFrame, location); return(location); }
//-------------------------------------------------------------------------------------------------- bool IShapeOperand.BindToPlane(Ax3 targetFrame, Entity boundTo, Pln?plane) { if (Body == null) { return(false); } var shape = Shape; if (shape == null) { return(false); } if (plane.HasValue) { return(shape.BindToPlane(Body.GetCoordinateSystem(), boundTo, plane.Value.Transformed(new Trsf(Body.GetCoordinateSystem(), targetFrame)))); } else { return(shape.BindToPlane(Body.GetCoordinateSystem(), boundTo, null)); } }