private void UnbindFromDiagram(Diagram diagram) { if (diagram == null) { return; } DiagramPanel dpanel = diagram.Panel; if (dpanel == null) { return; } dpanel.ViewportBoundsChanged -= this.ObservedPanel_ViewportBoundsChanged; dpanel.DiagramBoundsChanged -= this.ObservedPanel_DiagramBoundsChanged; dpanel.PartBoundsChanged -= this.ObservedPanel_PartBoundsChanged; dpanel.PartVisibleChanged -= this.ObservedPanel_PartVisibleChanged; diagram.TemplatesChanged -= this.ObservedDiagram_TemplatesChanged; diagram.ModelReplaced -= this.ObservedDiagram_ModelReplaced; if (this.Panel != null) { this.Panel.ViewportBoundsChanged += this.OverviewPanel_ViewportBoundsChanged; } this.BoundEventHandlers = false; }
/// <summary> /// Double click or Single click at node /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Node node = Part.FindAncestor <Node>(sender as UIElement); if (node == null) { return; } NodeData nodeData = node.Data as NodeData; if (nodeData == null) { return; } if (nodeData.obj is Bus) { Bus bus = nodeData.obj as Bus; if (bus == null) { return; } if (DiagramPanel.IsDoubleClick(e)) { e.Handled = true; MessageBoxResult rs = MessageBox.Show(string.Format("Go to bus:\nID: {0}\nName: '{1}'?", bus.Key, bus.Name), "Confirm", MessageBoxButton.YesNo); if (rs != MessageBoxResult.Yes) { return; } selectedBusID = bus.Key; Update(); } else { TxtInfo.Text = string.Format("Bus:\nID: {0} Name: '{1}'", bus.Key, bus.Name); } } else if (nodeData.obj is Generator) { Generator generator = nodeData.obj as Generator; if (generator == null) { return; } TxtInfo.Text = string.Format("Generator:\nKey: {0} Name: '{1}'", generator.Key, generator.Name); } else if (nodeData.obj is Load) { Load load = nodeData.obj as Load; if (load == null) { return; } TxtInfo.Text = string.Format("PSSE Load:\nBusID: {0} LoadID: '{1}'", load.BusID, load.LoadID); } }
private void UpdateBox() { Node box = this.Box; if (box == null) { return; } Diagram observed = this.Observed; if (observed == null) { return; } DiagramPanel dpanel = observed.Panel; if (dpanel == null) { return; } FrameworkElement orect = box.VisualElement; if (orect == null) { return; } Rect viewportbounds = dpanel.ViewportBounds; orect.Width = viewportbounds.Width; orect.Height = viewportbounds.Height; box.Position = new Point(viewportbounds.X, viewportbounds.Y); // try to keep the box visible in the overview this.Panel.MakeVisible(box, Rect.Empty); }
private void QueueBackgroundGridUpdate(DiagramPanel panel) { this.UpdateBackgroundGridNeeded = false; if (ShouldCacheBitmap(panel)) { // stop any current timer if (this.Timer != null) { this.Timer.Stop(); } // start a new timer this.Timer = new System.Windows.Threading.DispatcherTimer(); this.Timer.Tick += (s, e) => { var tim = s as System.Windows.Threading.DispatcherTimer; if (tim != null) { tim.Stop(); // don't repeat } this.Timer = null; Rect viewrect = panel.ViewportBounds; double scale = panel.Scale; DoUpdateBackgroundGrid(panel, viewrect, scale, true); }; // wait half second before calling DoUpdateBackgroundGrid this.Timer.Interval = new TimeSpan(0, 0, 0, 0, 500); this.Timer.Start(); } else // just call DoUpdateBackgroundGrid right now { Rect viewrect = panel.ViewportBounds; double scale = panel.Scale; DoUpdateBackgroundGrid(panel, viewrect, scale, true); } }
/// <summary> /// Show a print dialog and start printing. /// </summary> public void Print() { Diagram diagram = this.Diagram; if (diagram == null) { return; } DiagramPanel panel = diagram.Panel; if (panel == null) { return; } IDiagramModel model = diagram.Model; if (model == null) { return; } this._wasVirtualizing = panel.IsVirtualizing; panel.UpdateAllVisuals(); panel.IsVirtualizing = false; PrintDocument pdoc = new PrintDocument(); pdoc.BeginPrint += pdoc_BeginPrint; pdoc.EndPrint += pdoc_EndPrint; pdoc.PrintPage += pdoc_PrintPage; String modelname = (model.Name != null ? model.Name : "Diagram"); pdoc.Print(modelname); }
private void FinishedLayout() // no animation { this.SkipsInvalidate = false; Diagram diagram = this.Diagram; if (diagram == null) { return; } //Diagram.Debug(diagram.Name + ".IsEnabled finished " + diagram.IsEnabled.ToString() + " no animation"); Diagram.InvokeLater(this, ClearSizeChangedByLayoutFlags); diagram.Cursor = null; IDiagramModel model = diagram.Model; if (model != null) { model.SkipsUndoManager = this.WasSkippingUndoManager; } DiagramPanel panel = diagram.Panel; if (panel != null) { panel.InvokeUpdateDiagramBounds("Layout"); } }
private void Node_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // Only executes logic if you have double-clicked. if (DiagramPanel.IsDoubleClick(e)) { e.Handled = true; Node clicked = Part.FindAncestor <Node>(sender as UIElement); if (clicked != null) { Employee thisemp = (Employee)clicked.Data; myDiagram.StartTransaction("New Employee"); Employee newemp = new Employee() { Key = 1, // can't use zero, because zero means "no boss" Name = "(new person)", ParentKey = thisemp.Key, // the clicked employee is the new boss Location = Spot.BottomLeft.PointInRect(clicked.Bounds) // start underneath }; myDiagram.Model.AddNode(newemp); myDiagram.CommitTransaction("New Employee"); } } }
private void Node_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // Only creates a new employee if you have double-clicked a non-assistant. if (DiagramPanel.IsDoubleClick(e)) { e.Handled = true; Node clicked = Part.FindAncestor <Node>(sender as UIElement); if (clicked != null && clicked.Category != "Comment") { Employee thisemp = (Employee)clicked.Data; myDiagram.StartTransaction("New Employee"); Employee newemp = new Employee() { Key = 1, // can't use zero, because zero means "no boss" Name = "(new person)", ParentKey = thisemp.Key, // the clicked employee is the new boss }; if (Keyboard.Modifiers != ModifierKeys.Shift) // if shift is not held, add an Employee { newemp.Category = ""; newemp.Location = Spot.BottomLeft.PointInRect(clicked.Bounds); // start underneath } else // if shift is held, add an Assistant { newemp.Category = "Comment"; newemp.Location = Spot.TopRight.PointInRect(clicked.Bounds); // start on right side } myDiagram.Model.AddNode(newemp); myDiagram.CommitTransaction("New Employee"); } } }
private void pdoc_EndPrint(object sender, EndPrintEventArgs e) { this.PartsToPrint = null; Diagram diagram = this.Diagram; if (diagram == null) { return; } DiagramPanel panel = diagram.Panel; if (panel == null) { return; } panel.ReleasePrintingPanel(); panel.IsVirtualizing = this._wasVirtualizing; // Silverlight adornments might have wrong offsets afterwards -- fix up: foreach (Part p in diagram.SelectedParts) { p.RefreshAdornments(); } panel.UpdateScrollTransform(); diagram.Cursor = null; }
/// <summary> /// Show a print dialog and start printing. /// </summary> public void Print() { Diagram diagram = this.Diagram; if (diagram == null) { return; } DiagramPanel panel = diagram.Panel; if (panel == null) { return; } IDiagramModel model = diagram.Model; if (model == null) { return; } String modelname = (model.Name != null ? model.Name : "Diagram"); this.EffectivePageCount = 0; // uninitialized this.PageIndex = 0; PrintDocument pdoc = new PrintDocument(); pdoc.BeginPrint += pdoc_BeginPrint; pdoc.EndPrint += pdoc_EndPrint; pdoc.PrintPage += pdoc_PrintPage; pdoc.Print(modelname); }
internal void DoUpdateBackgroundGrid(DiagramPanel panel, Rect bounds, double scale, bool delayed) { Diagram diagram = panel.Diagram; if (diagram == null) { return; } if (!diagram.GridVisible || diagram.GridPattern != this) { return; } if (this.RenderedViewport == bounds && this.RenderedScale == scale) { return; } // pretend to scroll the grid appropriately Point origin = diagram.GridSnapOrigin; this.Origin = new Point(origin.X - bounds.X, origin.Y - bounds.Y); // remember to avoid duplicate renderings this.RenderedViewport = bounds; this.RenderedScale = scale; // also used by GetDefiningGeometry // size it to fill the viewport Size gridsize = new Size(bounds.Width, bounds.Height); this.Width = gridsize.Width; this.Height = gridsize.Height; //Diagram.Debug("Grid: " + Diagram.Str(bounds) + scale.ToString() + " " + Diagram.Str(gridsize)); // scale this GridPattern this.RenderTransformOrigin = new Point(0, 0); this.RenderTransform = new ScaleTransform() { CenterX = 0, CenterY = 0, ScaleX = scale, ScaleY = scale }; // get it to update InvalidateMeasure(); //panel.InvalidateMeasure(); if (!delayed || !panel.CachesBitmap) { panel.ClearBackground(); // before rendering, make sure the grid lines have been updated Measure(gridsize); Arrange(new Rect(0, 0, gridsize.Width, gridsize.Height)); //Diagram.Debug("Grid arranged: " + Diagram.Str(bounds) + scale.ToString() + " " + Diagram.Str(gridsize) + "actual: " + Diagram.Str(this.ActualWidth) + "x" + Diagram.Str(this.ActualHeight)); } else { //Diagram.Debug("Grid invalidated measure"); } }
private void BindToDiagram(Diagram diagram) { if (diagram == null) { this.Model = null; return; } if (diagram.Model is PartsModel) { Diagram.Error("cannot show an Overview of a Diagram with a PartsModel"); return; } // Overview's Template not yet applied? // Wait for OnApplyTemplate to call BindToDiagram. DiagramPanel vpanel = this.Panel; if (vpanel == null) { return; } //vpanel.IsVirtualizing = false; // Observed diagram's Template not yet applied? // When its template has been applied, call DelayBindingForObserved. DiagramPanel dpanel = diagram.Panel; if (dpanel == null) { diagram.TemplateApplied += DelayBindingForObserved; return; } if (!this.BoundEventHandlers) { // try to avoid executing this twice this.BoundEventHandlers = true; dpanel.ViewportBoundsChanged += this.ObservedPanel_ViewportBoundsChanged; dpanel.DiagramBoundsChanged += this.ObservedPanel_DiagramBoundsChanged; dpanel.PartBoundsChanged += this.ObservedPanel_PartBoundsChanged; dpanel.PartVisibleChanged += this.ObservedPanel_PartVisibleChanged; dpanel.AnimatingChanged += this.ObservedPanel_AnimatingChanged; diagram.TemplatesChanged += this.ObservedDiagram_TemplatesChanged; diagram.ModelReplaced += this.ObservedDiagram_ModelReplaced; } UpdateModel(); UpdateTemplates(); UpdateNodesAndLinks(); BindBox(); }
public override void DoMouseWheel() { Diagram diagram = this.Diagram; if (diagram == null) { return; } DiagramPanel panel = diagram.Panel; if (panel == null) { return; } int delta = GetWheelDelta(); if (delta == 0) { return; } bool shift = IsShiftKeyDown(); bool control = IsControlKeyDown(); var pm = diagram.PrintManager as PreviewingPrintManager; if (pm != null && pm.IsPreviewEnabled && shift && control) { double scale = pm.Scale; if (Double.IsNaN(scale) || scale <= 0 || Double.IsInfinity(scale)) { scale = 1; } else if (delta > 0) { scale *= 1.05; } else { scale /= 1.05; } pm.Scale = scale; pm.UpdatePrintGrid(); MouseWheelEventArgs e = diagram.LastMouseEventArgs as MouseWheelEventArgs; if (e != null) { e.Handled = true; } } else { base.DoMouseWheel(); } }
// when used as the Diagram's GridPattern background internal void InvokeBackgroundGridUpdate(DiagramPanel panel) { if (this.Timer != null) { this.Timer.Stop(); this.Timer = null; } if (!this.UpdateBackgroundGridNeeded) { this.UpdateBackgroundGridNeeded = true; Diagram.InvokeLater(this, () => QueueBackgroundGridUpdate(panel)); } }
private void FinishedLayoutAnimation() { this.SkipsInvalidate = false; if (!this.IsAnimating) { return; } this.IsAnimating = false; Diagram diagram = this.Diagram; if (diagram == null) { return; } //Diagram.Debug("Finished animation: " + diagram.Name); if (this.WasEnabled) { this.WasEnabled = false; diagram.ClearValue(System.Windows.Controls.Control.IsEnabledProperty); } if (this.HadFocus) { diagram.Focus(); } diagram.Cursor = null; IDiagramModel model = diagram.Model; if (model != null) { model.SkipsUndoManager = false; } // combine layout edits into previous transaction if (model != null) { UndoManager undomgr = model.UndoManager; if (undomgr != null) { undomgr.CoalesceLastTransaction("Layout"); } } DiagramPanel panel = diagram.Panel; if (panel == null) { return; } panel.InvokeUpdateDiagramBounds("Layout"); }
private void BindToDiagram(Diagram diagram) { if (diagram == null) { this.Model = null; return; } if (diagram.Model is PartsModel) { Diagram.Error("cannot show an Overview of a Diagram with a PartsModel"); return; } ApplyTemplate(); DiagramPanel vpanel = this.Panel; if (vpanel == null) { return; } //vpanel.IsVirtualizing = false; diagram.ApplyTemplate(); DiagramPanel dpanel = diagram.Panel; if (dpanel == null) { return; } if (!this.BoundEventHandlers) { // try to avoid executing this twice this.BoundEventHandlers = true; dpanel.ViewportBoundsChanged += this.ObservedPanel_ViewportBoundsChanged; dpanel.DiagramBoundsChanged += this.ObservedPanel_DiagramBoundsChanged; dpanel.PartBoundsChanged += this.ObservedPanel_PartBoundsChanged; dpanel.PartVisibleChanged += this.ObservedPanel_PartVisibleChanged; diagram.TemplatesChanged += this.ObservedDiagram_TemplatesChanged; diagram.ModelReplaced += this.ObservedDiagram_ModelReplaced; vpanel.ViewportBoundsChanged += this.OverviewPanel_ViewportBoundsChanged; } UpdateModel(); UpdateTemplates(); BindBox(); }
/// <summary> /// This calls <c>UIElement.ReleaseMouseCapture</c> on the <see cref="Diagram"/>'s <see cref="Northwoods.GoXam.Diagram.Panel"/>. /// </summary> protected virtual void ReleaseMouse() { Diagram diagram = this.Diagram; if (diagram == null) { return; } DiagramPanel panel = diagram.Panel; if (panel == null) { return; } panel.ReleaseMouse(); }
/// <summary> /// This override establishes an event handler that notices when the <see cref="Palette"/>'s /// <see cref="DiagramPanel"/>'s <see cref="DiagramPanel.ViewportBounds"/> changes, /// which then causes the layout to be performed again. /// </summary> public override void OnApplyTemplate() { // use a different default Layout than what Diagram.OnApplyTemplate might set if (this.Layout == null) { this.Layout = new Northwoods.GoXam.Layout.GridLayout(); } base.OnApplyTemplate(); DiagramPanel panel = this.Panel; if (panel != null && !this.EventHandlerEstablished) { panel.ViewportBoundsChanged += Panel_ViewportBoundsChanged; this.EventHandlerEstablished = true; } }
/// <summary> /// Return true when the last mouse down event occurred very close to and very soon after the previous mouse down event. /// </summary> /// <returns></returns> protected virtual bool IsDoubleClick() { Diagram diagram = this.Diagram; if (diagram == null) { return(false); } DiagramPanel panel = diagram.Panel; if (panel == null) { return(false); } return(panel.IsDoubleClick()); }
/// <summary> /// Return true when the alt key modifier is pressed. /// </summary> /// <returns></returns> protected virtual bool IsAltKeyDown() { Diagram diagram = this.Diagram; if (diagram == null) { return(false); } DiagramPanel panel = diagram.Panel; if (panel == null) { return(false); } return(panel.IsAltKeyDown()); }
/// <summary> /// Return how much the wheel has turned. /// </summary> /// <returns> /// If the last mouse event was the mouse wheel turning forward, this returns a positive integer. /// If the last mouse event was the mouse wheel turning backward, this returns a negative integer. /// Otherwise this returns zero. /// </returns> protected virtual int GetWheelDelta() { Diagram diagram = this.Diagram; if (diagram == null) { return(0); } DiagramPanel panel = diagram.Panel; if (panel == null) { return(0); } return(panel.GetWheelDelta()); }
private IStudioControl OpenControl(StrategyInfo info) { IStudioControl ctrl = null; switch (StrategyInfo.Type) { case StrategyInfoTypes.SourceCode: case StrategyInfoTypes.Analytics: ctrl = OpenControl(info.Id.To <string>(), typeof(StrategyInfoCodeContent), info, () => { var c = new StrategyInfoCodeContent { StrategyInfo = info }; ConfigManager .GetService <IStudioCommandService>() .Bind(info.GetKey(), c); return(c); }); break; case StrategyInfoTypes.Diagram: ctrl = OpenControl(info.Id.To <string>(), typeof(DiagramPanel), info, () => { var c = new DiagramPanel { StrategyInfo = info }; ConfigManager .GetService <IStudioCommandService>() .Bind(info.GetKey(), c); return(c); }); break; case StrategyInfoTypes.Assembly: case StrategyInfoTypes.Terminal: break; default: throw new ArgumentOutOfRangeException(); } return(ctrl); }
private void pdoc_EndPrint(object sender, EndPrintEventArgs e) { Diagram diagram = this.Diagram; if (diagram == null) { return; } DiagramPanel panel = diagram.Panel; if (panel == null) { return; } panel.ReleasePrintingPanel(); panel.UpdateScrollTransform(); diagram.Cursor = null; }
public override void DoMouseMove() { if (this.Active) { Overview ov = this.Diagram as Overview; if (ov != null && ov.Observed != null) { Diagram diag = ov.Observed; DiagramPanel obpanel = diag.Panel; if (obpanel != null) { Rect viewport = obpanel.ViewportBounds; Point pt = ov.LastMousePointInModel; obpanel.Position = new Point(pt.X - viewport.Width / 2, pt.Y - viewport.Height / 2); } } } }
// handle a mouse-down on an input node: toggle its Value if it's a double-click private void StartNodeDoubleClick(object sender, MouseButtonEventArgs e) { // Only executes logic if you have double-clicked. if (DiagramPanel.IsDoubleClick(e)) { myDiagram.StartTransaction("Toggle"); // When you double-click, toggles value of Input node Node input = Part.FindAncestor <Node>(sender as UIElement); if (input != null) { GateData d = input.Data as GateData; if (d != null && d.GateType == "Input") { d.Value = !d.Value; } } myDiagram.CommitTransaction("Toggle"); } }
/// <summary> /// Return true when the last mouse point is far enough away from the first mouse down point /// to constitute a drag operation instead of just a potential click. /// </summary> /// <returns>true if the first and last mouse points are more than two pixels apart in either axis</returns> protected virtual bool IsBeyondDragSize() { Diagram diagram = this.Diagram; if (diagram == null) { return(false); } DiagramPanel panel = diagram.Panel; if (panel == null) { return(false); } // Get all of the points in screen/view coordinates Point first = panel.TransformModelToView(diagram.FirstMousePointInModel); Point last = panel.TransformModelToView(diagram.LastMousePointInModel); return(DiagramPanel.IsBeyondDragSize(last, first)); }
public BitmapSource MakeBitmap(DiagramPanel diagramPanel) { Rect bounds = diagramPanel.DiagramBounds; double width = bounds.Width; double height = bounds.Height; double scale = 1.0; if (width > 2000) { scale = 2000 / width; } if (height > 2000) { scale = Math.Min(scale, 2000 / height); } width = Math.Ceiling(width * scale); height = Math.Ceiling(height * scale); return(diagramPanel.MakeBitmap(new Size(width, height), 96, new Point(bounds.X, bounds.Y), scale)); }
private void ObservedPanel_DiagramBoundsChanged(object sender, EventArgs e) { Diagram observed = this.Observed; if (observed == null) { return; } DiagramPanel dpanel = observed.Panel; if (dpanel == null) { return; } Rect r = dpanel.DiagramBounds; if (this.Box != null) { Rect b = this.Box.Bounds; Geo.Inflate(ref b, 10, 10); r.Union(b); } this.Panel.FixedBounds = r; }
internal void TransformBrush(DiagramPanel panel) { }
internal void FinishedPrinting(DiagramPanel panel) { this.Visibility = Visibility.Collapsed; }
internal void PrepareForPrinting(DiagramPanel panel, Rect viewb, double scale) { this.Visibility = Visibility.Visible; DoUpdateBackgroundGrid(panel, viewb, scale, false); // false: no bitmap cache update needed }
private void QueueBackgroundGridUpdate(DiagramPanel panel) { this.UpdateBackgroundGridNeeded = false; if (ShouldCacheBitmap(panel)) { // stop any current timer if (this.Timer != null) this.Timer.Stop(); // start a new timer this.Timer = new System.Windows.Threading.DispatcherTimer(); this.Timer.Tick += (s, e) => { var tim = s as System.Windows.Threading.DispatcherTimer; if (tim != null) tim.Stop(); // don't repeat this.Timer = null; Rect viewrect = panel.ViewportBounds; double scale = panel.Scale; DoUpdateBackgroundGrid(panel, viewrect, scale, true); }; // wait half second before calling DoUpdateBackgroundGrid this.Timer.Interval = new TimeSpan(0, 0, 0, 0, 500); this.Timer.Start(); } else { // just call DoUpdateBackgroundGrid right now Rect viewrect = panel.ViewportBounds; double scale = panel.Scale; DoUpdateBackgroundGrid(panel, viewrect, scale, true); } }
/// <summary> /// Recreates the line. /// </summary> /// <param name="panel">The panel.</param> /// <param name="left">The left.</param> /// <param name="top">The top.</param> private void RecreateLine(DiagramPanel panel, double left, double top) { lock (panel) { panel.Children.Remove(_line); _line = CreateRubberBandLine(); _line.X1 = _lineStartPosition.X; _line.Y1 = _lineStartPosition.Y; _line.X2 = left; _line.Y2 = top; panel.Children.Add(_line); } }
internal void DoUpdateBackgroundGrid(DiagramPanel panel, Rect bounds, double scale, bool delayed) { Diagram diagram = panel.Diagram; if (diagram == null) return; if (!diagram.GridVisible || diagram.GridPattern != this) return; if (this.RenderedViewport == bounds && this.RenderedScale == scale) return; // pretend to scroll the grid appropriately Point origin = diagram.GridSnapOrigin; this.Origin = new Point(origin.X-bounds.X, origin.Y-bounds.Y); // remember to avoid duplicate renderings this.RenderedViewport = bounds; this.RenderedScale = scale; // also used by GetDefiningGeometry // size it to fill the viewport Size gridsize = new Size(bounds.Width, bounds.Height); this.Width = gridsize.Width; this.Height = gridsize.Height; //Diagram.Debug("Grid: " + Diagram.Str(bounds) + scale.ToString() + " " + Diagram.Str(gridsize)); // scale this GridPattern this.RenderTransformOrigin = new Point(0, 0); this.RenderTransform = new ScaleTransform() { CenterX=0, CenterY=0, ScaleX=scale, ScaleY=scale }; // get it to update InvalidateMeasure(); //panel.InvalidateMeasure(); if (!delayed || !panel.CachesBitmap) { panel.ClearBackground(); // before rendering, make sure the grid lines have been updated Measure(gridsize); Arrange(new Rect(0, 0, gridsize.Width, gridsize.Height)); } }
//?? ought to decide based on complexity of drawing the grid, not the size // currently just checks for > 1 megapixel private bool ShouldCacheBitmap(DiagramPanel panel) { return panel.CachesBitmap && panel.ViewportWidth*panel.ViewportHeight > 1000*1000; }
/// <summary> /// Removes temporary line object from the design canvas /// </summary> /// <param name="mapPanel">The map panel.</param> private void CancelLink(DiagramPanel mapPanel) { if (_line == null) { return; } mapPanel.Children.Remove(_line); _line = null; }