public override bool Execute() { var originalShape = Dependency[0].ReferedShape; if (originalShape == null) { return(false); } var facePosition = Dependency[1].Integer; TopAbsShapeEnum shapeType; var shapeTypeId = Dependency[2].Integer; if (_subShapeTypes.ContainsKey(shapeTypeId)) { shapeType = _subShapeTypes[shapeTypeId]; } else { return(false); } var shape = ShapeUtils.ExtractSubShape(originalShape, facePosition, shapeType); if (shape == null) { return(false); } Shape = shape; return(true); }
public static Point3D ComputeMiddlePointPosition(TopoDSShape wire) { var firstPoint = new Point3D( ShapeUtils.ConvertShapeToPoint(ShapeUtils.ExtractSubShape(wire, 1, TopAbsShapeEnum.TopAbs_VERTEX))); var secondPoint = new Point3D( ShapeUtils.ConvertShapeToPoint(ShapeUtils.ExtractSubShape(wire, 2, TopAbsShapeEnum.TopAbs_VERTEX))); return(ComputeMiddlePoint(firstPoint, secondPoint)); }
private void GetLength(ref object resultvalue) { if (Builder[0].ReferenceBuilder.FunctionName == FunctionNames.Circle) { var radius = Builder[0].ReferenceBuilder.Dependency[1].Real; resultvalue = radius * 2; return; } var referenceShape = ShapeUtils.ExtractSubShape(Builder[0].ReferenceData); var edge = TopoDS.Edge(referenceShape); var curve = new BRepAdaptorCurve(edge); var firstPoint = curve.Value(curve.FirstParameter); var lastPoint = curve.Value(curve.LastParameter); var length = firstPoint.Distance(lastPoint); resultvalue = length; }
private bool DrawConstraint(Node circleNode, NodeBuilder circleBuilder) { var textLocation = circleBuilder[0].Axis3D.GpAxis.Location.Transformed(circleBuilder.Transformation); const int translate = 10; textLocation.X = (textLocation.X + circleBuilder[1].Real + translate); textLocation.Y = (textLocation.Y + circleBuilder[1].Real + translate); var shape = ShapeUtils.ExtractSubShape(circleNode, 1, TopAbsShapeEnum.TopAbs_EDGE); var interactive = DimensionUtils.CreateDependency(shape, textLocation, DsgPrsArrowSide.DsgPrs_AS_BOTHAR); if (interactive == null) { return(false); } Parent.Set <TreeViewVisibilityInterpreter>(); Interactive = interactive; return(true); }
private bool BuildDimensionInteractive(Node rectangleNode) { var textLocation = DimensionUtils.ComputeMiddlePointPosition(rectangleNode, 2).GpPnt; const int translate = 10; textLocation.X = (textLocation.X + translate); textLocation.Y = (textLocation.Y + translate); textLocation.Z = (textLocation.Z + translate); var shape = ShapeUtils.ExtractSubShape(rectangleNode, 2, TopAbsShapeEnum.TopAbs_EDGE); var interactive = DimensionUtils.CreateDependency(shape, textLocation, DsgPrsArrowSide.DsgPrs_AS_BOTHAR); if (interactive == null) { return(false); } Parent.Set <TreeViewVisibilityInterpreter>(); Interactive = interactive; return(true); }
public override bool Execute() { var edgeNode = Dependency[0].Reference; var edgeIndexNode = Dependency[0].ReferenceData.ShapeCount; if (ShapeUtils.ExtractShape(edgeNode) == null) { return(false); } var edge = TopoDS.Edge(ShapeUtils.ExtractSubShape(edgeNode, edgeIndexNode, TopAbsShapeEnum.TopAbs_EDGE)); var distance = Dependency[1].Real; var referenceShape = Dependency[2].Reference; var referebceShapePointIndex = Dependency[3].Integer; if (referenceShape == null) { return(false); } var point = NodeBuilderUtils.GetNodePoint(referenceShape[referebceShapePointIndex]); if (point != null) { var projectionPoint = GeomUtils.ProjectPointOnEdge(edge, ((Point3D)point).GpPnt); var newPoint = new Point3D(projectionPoint); var currentDistance = projectionPoint.Distance(((Point3D)point).GpPnt); if (Math.Abs(currentDistance - distance) > 0.01) { var scale = currentDistance / distance; if (Math.Abs(scale - 1) > Precision.Confusion) { newPoint = TreeUtils.ScaleSegment(newPoint, ((Point3D)point), scale); } } NodeBuilderUtils.SetupNodePoint(referenceShape[referebceShapePointIndex], newPoint); } return(true); }
public override bool Execute() { var referenceShape = ShapeUtils.ExtractSubShape(Dependency[0].ReferenceData); var refBuilder = new NodeBuilder(Dependency[0].Reference); var builder = Builder; builder.Visibility = refBuilder.Visibility; var textLocation = Dependency[1].TransformedPoint3D.GpPnt; var arrowType = Dependency[2].Integer == 1 ? DsgPrsArrowSide.DsgPrs_AS_NONE : DsgPrsArrowSide.DsgPrs_AS_BOTHAR; Point3D offset = new Point3D(textLocation); bool isOffset = false; if (Dependency[3].Integer == 1) { isOffset = true; Dependency[3].Integer = 0; var edge = TopoDS.Edge(referenceShape); var calculatedMidpoint = GeomUtils.CalculateEdgeMidPoint(edge); if (calculatedMidpoint != null) { offset = new Point3D(textLocation.X - calculatedMidpoint.Value.X, textLocation.Y - calculatedMidpoint.Value.Y, textLocation.Z - calculatedMidpoint.Value.Z); Dependency[4].Node.Set <Point3DInterpreter>().Value = offset; } } var interactive = DimensionUtils.CreateDependency(referenceShape, offset.GpPnt, arrowType, isOffset, Dependency[4].TransformedPoint3D.GpPnt); if (interactive == null) { return(false); } Interactive = interactive; return(true); }
private void BuildConstraint() { InitSession(); var firstShape = new NodeBuilder(_sourceSelectedEntity.Node); var secondShape = new NodeBuilder(_destinationSelectedEntity.Node); SceneSelectedEntity shapeEdge; Node point; if (firstShape.FunctionName == FunctionNames.Point) { point = _sourceSelectedEntity.Node; shapeEdge = _destinationSelectedEntity; } else { if (secondShape.FunctionName == FunctionNames.Point) { point = _destinationSelectedEntity.Node; shapeEdge = _sourceSelectedEntity; } else { Document.Revert(); BackToNeutralModifier(); return; } } if (shapeEdge.Node.Get <FunctionInterpreter>().Name == FunctionNames.Dimension) { var line = shapeEdge.Node.Children[1].Get <ReferenceInterpreter>().Node; var canSelect = new NodeBuilder(line).EnableSelection; if (canSelect) { shapeEdge = new SceneSelectedEntity(line) { ShapeType = TopAbsShapeEnum.TopAbs_WIRE, ShapeCount = 1 }; } } var shape = ShapeUtils.ExtractSubShape(shapeEdge); if (shape == null) { return; } var edge = GeomUtils.ExtractEdge(shape); if (edge == null) { return; } var projectedPoint = GeomUtils.ProjectPointOnEdge(edge, (new NodeBuilder(point))[1].TransformedPoint3D.GpPnt); var projectedPointNode = new NodeBuilder(Document, FunctionNames.Point); projectedPointNode[0].Reference = Document.Root.Children[0]; projectedPointNode[1].TransformedPoint3D = new Point3D(projectedPoint); projectedPointNode.EnableSelection = false; projectedPointNode.ExecuteFunction(); var tempLine1 = new NodeBuilder(Document, FunctionNames.LineTwoPoints); tempLine1[0].Reference = point; //sketchCreator.GetPoint((new NodeBuilder(point))[1].TransformedPoint3D).Node; tempLine1[1].Reference = projectedPointNode.Node; tempLine1.EnableSelection = false; tempLine1.ExecuteFunction(); var perpendicularConstraint = new NodeBuilder(Document, Constraint2DNames.PerpendicularFunction); perpendicularConstraint[0].Reference = tempLine1.Node; perpendicularConstraint[1].Reference = shapeEdge.Node; perpendicularConstraint.ExecuteFunction(); var pointOnLineConstraint = new NodeBuilder(Document, Constraint2DNames.PointOnSegmentFunction); pointOnLineConstraint[0].Reference = projectedPointNode.Node; pointOnLineConstraint[1].Reference = shapeEdge.Node; pointOnLineConstraint.ExecuteFunction(); NodeBuilderUtils.AddLengthAndDimensionConstraint(Document, tempLine1.Node, true); // Finish the transaction CommitFinal("Apply Constraint"); UpdateView(); RebuildTreeView(); BackToNeutralModifier(); }
public static Point3D ComputeMiddlePointPosition(Node rectangleNode, int wireIndex) { return (ComputeMiddlePointPosition(ShapeUtils.ExtractSubShape(rectangleNode, wireIndex, TopAbsShapeEnum.TopAbs_EDGE))); }