// Handles any change in FigureBox by changing SelectedNode.Data.NodeFigure private void FigureChanged(object sender, EventArgs e) { if (myDiagram.SelectedNode == null) { return; } MyNodeData mnd = myDiagram.SelectedNode.Data as MyNodeData; if (mnd != null) { myDiagram.StartTransaction("Modify Node Figure"); mnd.Figure = (NodeFigure)FigureBox.SelectedItem; myDiagram.CommitTransaction("Modify Node Figure"); } }
// Handles all RadioButton clicks for FromSpot and ToSpot. private void NodeRadioButton_Click(object sender, EventArgs e) { if (myDiagram.SelectedNode == null) { return; } RadioButton tempRB = sender as RadioButton; if (tempRB == null) { return; } MyNodeData mnd = myDiagram.SelectedNode.Data as MyNodeData; if (mnd != null) { myDiagram.StartTransaction("Modify Port Spots"); // "From" Side CheckBoxes are all unchecked when a "From" RadioButton is selected. if (ToFromSpotTabControl.SelectedItem == FromPortTab) { this.IgnoreCheckBoxChanges = true; FromLeftCB.IsChecked = false; FromTopCB.IsChecked = false; FromRightCB.IsChecked = false; FromBottomCB.IsChecked = false; this.IgnoreCheckBoxChanges = false; // The names of FromPort RadioButtons are formatted in the pattern ("From"+NameOfSpot). // Spot.Parse() converts the button name to a Spot value. mnd.FromSpot = Spot.Parse(tempRB.Name.Substring(4)); } // "To" Side CheckBoxes are all unchecked when a "To" RadioButton is selected. if (ToFromSpotTabControl.SelectedItem == ToPortTab) { this.IgnoreCheckBoxChanges = true; ToLeftCB.IsChecked = false; ToTopCB.IsChecked = false; ToRightCB.IsChecked = false; ToBottomCB.IsChecked = false; this.IgnoreCheckBoxChanges = false; // The names of ToPort RadioButtons are formatted in the pattern ("To"+NameOfSpot). // Spot.Parse() converts the button name to a Spot value. mnd.ToSpot = Spot.Parse(tempRB.Name.Substring(2)); } myDiagram.CommitTransaction("Modify Port Spots"); } }
// Handles the changes made in the CheckBoxes in the TabControl for ports. private void CheckBox_Changed(object sender, EventArgs e) { if (this.IgnoreCheckBoxChanges) { return; } if (myDiagram.SelectedNode == null) { return; } MyNodeData mnd = myDiagram.SelectedNode.Data as MyNodeData; if (mnd != null) { myDiagram.StartTransaction("Modify Port Spots"); if (ToFromSpotTabControl.SelectedItem == FromPortTab) { FromNone.IsChecked = true; mnd.FromSpot = Spot.GetSide((bool)FromLeftCB.IsChecked, (bool)FromTopCB.IsChecked, (bool)FromRightCB.IsChecked, (bool)FromBottomCB.IsChecked); if (mnd.FromSpot != Spot.None) { FromNone.IsChecked = false; } } if (ToFromSpotTabControl.SelectedItem == ToPortTab) { ToNone.IsChecked = true; mnd.ToSpot = Spot.GetSide((bool)ToLeftCB.IsChecked, (bool)ToTopCB.IsChecked, (bool)ToRightCB.IsChecked, (bool)ToBottomCB.IsChecked); if (mnd.ToSpot != Spot.None) { ToNone.IsChecked = false; } } myDiagram.CommitTransaction("Modify Port Spots"); } }
// Updates all controls when the primary selected part, SelectedPart, changes private void SelectedPartsChanged(object sender, EventArgs e) { if (myDiagram.SelectedPart == null) { return; } MyNodeData mnd = myDiagram.SelectedPart.Data as MyNodeData; if (mnd != null) // if SelectedPart is a Node { FigureBox.SelectedItem = mnd.Figure; this.IgnoreCheckBoxChanges = true; Spot from = mnd.FromSpot; if (from.IsSide) { FromLeftCB.IsChecked = from.IncludesSide(Spot.LeftSide); FromTopCB.IsChecked = from.IncludesSide(Spot.TopSide); FromRightCB.IsChecked = from.IncludesSide(Spot.RightSide); FromBottomCB.IsChecked = from.IncludesSide(Spot.BottomSide); //Deselect all FromSpot RadioButtons FromNone.IsChecked = false; } else // FromSpot is a specific Spot or Spot.None // Sets the IsChecked Property of the corresponding RadioButton { SetRadioButton("From", from); FromLeftCB.IsChecked = false; FromTopCB.IsChecked = false; FromRightCB.IsChecked = false; FromBottomCB.IsChecked = false; } Spot to = mnd.ToSpot; if (to.IsSide) { ToLeftCB.IsChecked = to.IncludesSide(Spot.LeftSide); ToTopCB.IsChecked = to.IncludesSide(Spot.TopSide); ToRightCB.IsChecked = to.IncludesSide(Spot.RightSide); ToBottomCB.IsChecked = to.IncludesSide(Spot.BottomSide); //Deselect all ToSpot RadioButtons ToNone.IsChecked = false; } else // ToSpot is a specific Spot or Spot.None // Sets the IsChecked Property of the corresponding RadioButton { SetRadioButton("To", to); ToLeftCB.IsChecked = false; ToTopCB.IsChecked = false; ToRightCB.IsChecked = false; ToBottomCB.IsChecked = false; } this.IgnoreCheckBoxChanges = false; } MyLinkData mld = myDiagram.SelectedPart.Data as MyLinkData; if (mld != null) // or SelectedPart is a Link { CurvinessSlider.Value = mld.Curviness; CornerSlider.Value = mld.Corner; ToArrowBox.SelectedItem = mld.ToArrow; FromArrowBox.SelectedItem = mld.FromArrow; ToArrowScaleBox.Text = mld.ToArrowScale.ToString(); FromArrowScaleBox.Text = mld.FromArrowScale.ToString(); ToEndSegmentLengthBox.Text = mld.ToEndSegmentLength.ToString(); FromEndSegmentLengthBox.Text = mld.FromEndSegmentLength.ToString(); ToShortLengthBox.Text = mld.ToShortLength.ToString(); FromShortLengthBox.Text = mld.FromShortLength.ToString(); switch (mld.Routing) { case LinkRouting.Normal: NormalRoutingRB.IsChecked = true; break; case LinkRouting.Orthogonal: OrthogonalRoutingRB.IsChecked = true; break; case LinkRouting.AvoidsNodes: AvoidsNodesRoutingRB.IsChecked = true; break; } switch (mld.Curve) { case LinkCurve.None: NoneCurveRB.IsChecked = true; break; case LinkCurve.JumpOver: JumpOverCurveRB.IsChecked = true; break; case LinkCurve.JumpGap: JumpGapCurveRB.IsChecked = true; break; case LinkCurve.Bezier: BezierCurveRB.IsChecked = true; break; } } }