public NodeControl CreateNode(ViewModel.Node viewModelNode, SuperGraphControl parentSurface) { NodeControl nodeControl = null; /// TODO: We will need to consider being able to have the same viewModelNode present here twice. if (!Nodes.ContainsKey(viewModelNode.Id)) { nodeControl = new NodeControl(); Canvas.SetZIndex(nodeControl, 50); nodeControl.ParentSurface = parentSurface; nodeControl.DataContext = viewModelNode; nodeControl.VideoRemoteControl.DataContext = viewModelNode.VideoInfo; //nodeControl.NodeCornerControl.DataContext = viewModelNode; NodeControlFactorySet set = new NodeControlFactorySet(); set.Node = viewModelNode; set.Control = nodeControl; Nodes.Add(viewModelNode.Id, set); } else { nodeControl = Nodes[viewModelNode.Id].Control; } return(nodeControl); }
public void SaveToImage(SuperGraphControl mapCanvas) { var saveDlg = new SaveFileDialog { Filter = "JPEG Files (*.jpg)|*.jpg", DefaultExt = ".jpg" }; var showDialog = saveDlg.ShowDialog(); if (showDialog != null && (bool)showDialog) { WriteableBitmap bitmap; try { double left, right, top, bottom; mapCanvas.GetMapBounds(out left, out right, out top, out bottom); left -= 70; right += 70; top -= 170; bottom += 170; double mapHeight = bottom - top; double mapWidth = right - left; var transform = new TransformGroup(); ScaleTransform st; TranslateTransform tt; var moved = mapCanvas.MoveGraphTransform; double xMove, yMove; const ScreenCaptureType type = ScreenCaptureType.ZoomedFullScale; Canvas canvas; switch (type) { case ScreenCaptureType.FullScale: xMove = moved.X + left; yMove = moved.Y + top; st = new ScaleTransform { ScaleX = 1 / mapCanvas.Zoom, ScaleY = 1 / mapCanvas.Zoom, CenterX = 0, CenterY = 0 }; transform.Children.Add(st); tt = new TranslateTransform { X = -xMove, Y = -yMove, }; transform.Children.Add(tt); canvas = new Canvas { Background = new SolidColorBrush(Colors.White), Width = (int)mapWidth, Height = (int)mapHeight }; bitmap = new WriteableBitmap(canvas, null); break; case ScreenCaptureType.ZoomedFullScale: xMove = moved.X + left; yMove = moved.Y + top; tt = new TranslateTransform { X = -xMove * mapCanvas.Zoom, Y = -yMove * mapCanvas.Zoom, }; transform.Children.Add(tt); canvas = new Canvas { Background = new SolidColorBrush(Colors.White), Width = (int)(mapWidth * mapCanvas.Zoom), Height = (int)(mapHeight * mapCanvas.Zoom) }; bitmap = new WriteableBitmap(canvas, null); break; case ScreenCaptureType.CurrentScreenOnly: canvas = new Canvas { Background = new SolidColorBrush(Colors.White), Width = (int)mapCanvas.ActualWidth, Height = (int)mapCanvas.ActualHeight }; bitmap = new WriteableBitmap(canvas, null); break; default: canvas = new Canvas { Background = new SolidColorBrush(Colors.White), Width = (int)mapCanvas.ActualWidth, Height = (int)mapCanvas.ActualHeight }; bitmap = new WriteableBitmap(canvas, null); break; } bitmap.Render(mapCanvas, transform); bitmap.Invalidate(); using (var fs = saveDlg.OpenFile()) { var stream = GetImageStream(bitmap); //Get Bytes from memory stream and write into IO stream var binaryData = new Byte[stream.Length]; var bytesRead = stream.Read(binaryData, 0, (int)stream.Length); fs.Write(binaryData, 0, binaryData.Length); } } catch (Exception e) { SuperMessageBoxService.ShowError("Export Failed", "We are unable to export your map.\r\nPlease zoom out and try again."); } GC.Collect(); GC.WaitForPendingFinalizers(); } }
public JavaScriptBridge(SuperGraphControl superGraphControl) { _superGraphControl = superGraphControl; }