protected void UpdateLineLock() { BeginUpdate(); var constraint = NodeBuilderUtils.ShapeHasConstraint(Parent, Constraint2DNames.LineLengthFunction, _viewInfo.Document); if (constraint != -1) { _viewInfo.Document.Root.Remove(constraint); // remove dimension var dimensionNodeIndex = 0; foreach (var child in _viewInfo.Document.Root.Children) { if (child.Value.Get <FunctionInterpreter>().Name == FunctionNames.Dimension) { if (child.Value.Children[1].Get <ReferenceInterpreter>().Node.Index == Parent.Index) { dimensionNodeIndex = child.Value.Index; break; } } } if (dimensionNodeIndex != 0) { _viewInfo.Document.Root.Remove(dimensionNodeIndex); } } else { NodeBuilderUtils.AddLengthAndDimensionConstraint(_viewInfo.Document, Parent, true); } EndVisualUpdate("Update constraint"); }
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(); }
/// <summary> /// Receives click events. Called at mouse down and at mouse up. /// </summary> /// <param name = "mouseData"></param> protected override void OnMouseClick3DAction(Mouse3DPosition mouseData) { // At mouse down pick the selected edge if (!mouseData.MouseDown) { return; } var entities = Inputs[InputNames.SelectionContainerPipe].GetData(NotificationNames.GetEntities).Get <List <SceneSelectedEntity> >(); if (_currentSelectedEntity == null) { // Store the mouse coordinate used to calculate the extrusion height Log.Info("Dimension - started"); var selectedNodes = entities; if (selectedNodes.Count != 1) { return; } _currentSelectedEntity = selectedNodes[0]; // If no selected node if (_currentSelectedEntity == null) { return; } if (_sourceSelectedEntity == null) { _sourceSelectedEntity = _currentSelectedEntity; } else { if (_destinationSelectedEntity == null && (_currentSelectedEntity.Node.Index != _sourceSelectedEntity.Node.Index || _currentSelectedEntity.ShapeCount != _sourceSelectedEntity.ShapeCount) ) { _destinationSelectedEntity = _currentSelectedEntity; } } _currentSelectedEntity = null; } // At this moment the Dimension is finished if (_destinationSelectedEntity == null) { return; } Log.Info("Point to point constraint - finished"); InitSession(); var tempLine = new NodeBuilder(Document, FunctionNames.LineTwoPoints); tempLine[0].Reference = _sourceSelectedEntity.Node; tempLine[1].Reference = _destinationSelectedEntity.Node; tempLine.EnableSelection = false; tempLine.ExecuteFunction(); NodeBuilderUtils.AddLengthAndDimensionConstraint(Document, tempLine.Node, false); // Close all local contexts Context.CloseAllContexts(true); // Finish the transaction CommitFinal("Apply dimension"); Reset(); BackToNeutralModifier(); }