コード例 #1
0
ファイル: StackPanelTest.cs プロジェクト: dfr0/moon
		public void ArrangeTest ()
		{
			Border b1 = new Border ();
			b1.Background = new SolidColorBrush (Colors.Red);
			b1.Width = 50;
			b1.Height = 25;
			
			Border b2 = new Border ();
			b2.Background = new SolidColorBrush (Colors.Blue);
			b2.Width = 25;
			b2.Height = 30;
			
			var stack = new StackPanel ();
			stack.Children.Add (b1);
			stack.Children.Add (b2);
			
			stack.Measure (new Size (Double.PositiveInfinity,Double.PositiveInfinity));
			
			Assert.AreEqual (new Size (50,55), stack.DesiredSize, "stack desired");
			Assert.AreEqual (new Size (0,0), new Size (stack.ActualWidth, stack.ActualHeight), "stack actual");
			
			stack.Arrange (new Rect (10, 10, stack.DesiredSize.Width, stack.DesiredSize.Height));
			
			Assert.AreEqual (new Size (50,55), stack.DesiredSize, "stack desired1");
			Assert.AreEqual (new Size (50,55), stack.RenderSize, "stack render1");
			Assert.AreEqual (new Rect (10,10,50,55), LayoutInformation.GetLayoutSlot (stack), "stack slot");
		}
コード例 #2
0
ファイル: StackPanelTest.cs プロジェクト: highzion/Granular
        public void StackPanelLayoutTest()
        {
            StackPanel panel = new StackPanel();

            FrameworkElement child1 = new FrameworkElement { Height = 100 };
            FrameworkElement child2 = new FrameworkElement { Height = 100 };
            FrameworkElement child3 = new FrameworkElement { Height = 100 };

            panel.Children.Add(child1);
            panel.Children.Add(child2);
            panel.Children.Add(child3);

            panel.Measure(new Size(1000, 1000));

            Assert.AreEqual(new Size(0, 300), panel.DesiredSize);

            panel.Arrange(new Rect(1000, 300));

            Assert.AreEqual(new Size(1000, 300), panel.VisualSize);

            Assert.AreEqual(new Size(1000, 100), child1.VisualSize);
            Assert.AreEqual(new Size(1000, 100), child2.VisualSize);
            Assert.AreEqual(new Size(1000, 100), child3.VisualSize);

            Assert.AreEqual(new Point(0, 0), child1.VisualOffset);
            Assert.AreEqual(new Point(0, 100), child2.VisualOffset);
            Assert.AreEqual(new Point(0, 200), child3.VisualOffset);
        }
コード例 #3
0
ファイル: StackPanelTest.cs プロジェクト: dfr0/moon
		public void LayoutSlotTest ()
		{
			var stack = new StackPanel ();
			stack.Children.Add (CreateSlotItem ());
			stack.Children.Add (CreateSlotItem ());
			stack.Children.Add (CreateSlotItem ());
			
			stack.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			stack.Arrange (new Rect (0,0,stack.DesiredSize.Width,stack.DesiredSize.Height));
			
			Assert.AreEqual (new Rect (0,0,25,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]));
			Assert.AreEqual (new Rect (0,33,25,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]));
			Assert.AreEqual (new Rect (0,66,25,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]));
		}
コード例 #4
0
ファイル: MouseDeviceTest.cs プロジェクト: highzion/Granular
        public void MouseDeviceCaptureTest()
        {
            Border child1 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 };
            Border child2 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 };
            Border child3 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 };

            StackPanel panel = new StackPanel { IsRootElement = true };
            panel.Children.Add(child1);
            panel.Children.Add(child2);

            MouseEventArgs lastArgs = null;
            panel.MouseMove += (sender, e) => lastArgs = e;

            TestPresentationSource presentationSource = new TestPresentationSource();
            presentationSource.RootElement = panel;

            panel.Measure(Size.Infinity);
            panel.Arrange(new Rect(panel.DesiredSize));

            MouseDevice mouseDevice = new MouseDevice(presentationSource);

            mouseDevice.Activate();
            mouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 50), 0));
            Assert.AreEqual(child1, lastArgs.Source);
            Assert.AreEqual(child1, mouseDevice.HitTarget);
            Assert.AreEqual(null, mouseDevice.CaptureTarget);
            Assert.AreEqual(child1, mouseDevice.Target);

            mouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 150), 0));
            Assert.AreEqual(child2, lastArgs.Source);
            Assert.AreEqual(child2, mouseDevice.HitTarget);
            Assert.AreEqual(null, mouseDevice.CaptureTarget);
            Assert.AreEqual(child2, mouseDevice.Target);

            mouseDevice.Capture(child2);
            mouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 50), 0));
            Assert.AreEqual(child2, lastArgs.Source);
            Assert.AreEqual(child1, mouseDevice.HitTarget);
            Assert.AreEqual(child2, mouseDevice.CaptureTarget);
            Assert.AreEqual(child2, mouseDevice.Target);

            mouseDevice.ReleaseCapture();
            mouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 50), 0));
            Assert.AreEqual(child1, lastArgs.Source);
            Assert.AreEqual(child1, mouseDevice.HitTarget);
            Assert.AreEqual(null, mouseDevice.CaptureTarget);
            Assert.AreEqual(child1, mouseDevice.Target);
        }
コード例 #5
0
ファイル: StackPanelTest.cs プロジェクト: dfr0/moon
		public void MeasureTest ()
		{
			Border b1 = new Border ();
			b1.Background = new SolidColorBrush (Colors.Red);
			b1.Width = 50;
			b1.Height = 25;
			
			Border b2 = new Border ();
			b2.Background = new SolidColorBrush (Colors.Blue);
			b2.Width = 25;
			b2.Height = 30;
			
			var stack = new StackPanel ();
			stack.Children.Add (b1);
			stack.Children.Add (b2);
			
			stack.Measure (new Size (Double.PositiveInfinity,Double.PositiveInfinity));
			
			Assert.AreEqual (new Size (50,55), stack.DesiredSize, "stack desired");
		}
コード例 #6
0
        private void Print_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog printDlg = new PrintDialog();

              if (printDlg.ShowDialog() == true)
              {
            printDlg.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.NorthAmerica4x6);
            //printDlg.PrintQueue.DefaultPrintTicket.PageOrientation = PageOrientation.Landscape;
            printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape;
            Console.WriteLine("wwwwwwwwwwwwww->" + printDlg.PrintableAreaWidth);
            Console.WriteLine("hhhhhhhhhhhhhhh->" + printDlg.PrintableAreaHeight);
            Console.WriteLine("W-> "+printDlg.PrintTicket.PageMediaSize.Width);
            Console.WriteLine("H-> "+printDlg.PrintTicket.PageMediaSize.Height);
            //printDlg.PrintQueue.DefaultPrintTicket.PageOrientation = PageOrientation.Portrait;
            /*
            XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(printDlg.PrintQueue);
            PrintTicket ticket = new PrintTicket();
            if (printDlg.PrintTicket.PageOrientation == PageOrientation.Landscape)
            {
              ticket.PageMediaSize =
            new PageMediaSize(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);
            }
            docWriter.Write(visual, ticket);
            */
            Size size = new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight);
            StackPanel stackPanel = new StackPanel { Orientation = Orientation.Vertical, RenderSize = size };

            //TextBlock title = new TextBlock { Text = @"Form", FontSize = 20 };
            //stackPanel.Children.Add(title);

            Image image = new Image { Source = this.theImage.Source, Stretch = Stretch.Uniform };
            image.RenderTransform = new ScaleTransform(1, 1);
            stackPanel.Children.Add(image);

            stackPanel.Measure(size);
            stackPanel.Arrange(new Rect(new Point(0, 0), stackPanel.DesiredSize));

            printDlg.PrintVisual(stackPanel, @"Form image");
            //printDlg.PrintVisual(theImage, "My First Print Job");
              }
        }
コード例 #7
0
ファイル: PrintImage.cs プロジェクト: hxshandle/PrintCat
        internal void Print(System.Windows.Controls.Image ImageCtrl)
        {
            PrintDialog printDlg = new PrintDialog();

              if (printDlg.ShowDialog() == true)
              {
            printDlg.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.NorthAmerica4x6);
            printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape;

            System.Windows.Size size = new System.Windows.Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight);
            StackPanel stackPanel = new StackPanel { Orientation = Orientation.Vertical, RenderSize = size };

            //TextBlock title = new TextBlock { Text = @"Form", FontSize = 20 };
            //stackPanel.Children.Add(title);

            TransformGroup transformGroup = new TransformGroup();
            ScaleTransform scaleTransform = new ScaleTransform(1,1);
            transformGroup.Children.Add(scaleTransform);

            Image image = new Image { Source = ImageCtrl.Source, Stretch = Stretch.Uniform };

            //image.RenderTransform = new ScaleTransform(1, 1);

            BitmapSource imgSrouce = ImageCtrl.Source as BitmapSource;
            if (imgSrouce.PixelWidth < imgSrouce.PixelHeight)
            {

              image.LayoutTransform = new RotateTransform(90);
            }

            image.RenderTransform = transformGroup;

            stackPanel.Children.Add(image);

            stackPanel.Measure(size);
            stackPanel.Arrange(new Rect(new Point(0, 0), stackPanel.DesiredSize));

            printDlg.PrintVisual(stackPanel, @"Form image");
            //printDlg.PrintVisual(ImageCtrl, "My First Print Job");
              }
        }
コード例 #8
0
ファイル: HitTestTest.cs プロジェクト: highzion/Granular
        public void HitTestBasicTest()
        {
            StackPanel stackPanel1 = new StackPanel { Name = "stackPanel1", Background = Brushes.Transparent, IsRootElement = true };
            StackPanel stackPanel2 = new StackPanel { Name = "stackPanel2", Background = Brushes.Transparent, Height = 100, Orientation = Orientation.Horizontal };

            Border child1 = new Border { Name = "child1", Background = Brushes.Transparent, Height = 100, Width = 100 };
            Border child2 = new Border { Name = "child2", Background = Brushes.Transparent, Height = 100 };
            Border child3 = new Border { Name = "child3", Background = Brushes.Transparent, Width = 100 };
            Border child4 = new Border { Name = "child4", Background = Brushes.Transparent, Width = 100 };

            stackPanel1.Children.Add(child1);
            stackPanel1.Children.Add(stackPanel2);
            stackPanel1.Children.Add(child2);
            stackPanel2.Children.Add(child3);
            stackPanel2.Children.Add(child4);

            // [child1]       ]
            // [child3][child4]
            // [child2        ]

            stackPanel1.Measure(Size.Infinity);
            stackPanel1.Arrange(new Rect(stackPanel1.DesiredSize));

            Assert.AreEqual(child1, stackPanel1.HitTest(new Point(50, 50)));
            Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(150, 50)));
            Assert.AreEqual(child3, stackPanel1.HitTest(new Point(50, 150)));
            Assert.AreEqual(child4, stackPanel1.HitTest(new Point(150, 150)));
            Assert.AreEqual(child2, stackPanel1.HitTest(new Point(50, 250)));
            Assert.AreEqual(child2, stackPanel1.HitTest(new Point(150, 250)));

            stackPanel2.IsEnabled = false;
            Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(50, 150)));
            Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(150, 150)));

            child2.IsHitTestVisible = false;
            Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(50, 250)));
            Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(150, 250)));
        }
コード例 #9
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            System.Windows.Size size = new System.Windows.Size(600, 400);
              StackPanel stackPanel = new StackPanel { Orientation = Orientation.Vertical, RenderSize = size };

              System.Windows.Controls.Image ImageCtrl = new System.Windows.Controls.Image();
              BitmapImage bitImg = new BitmapImage(new Uri("C:\\temp\\32367-78aNJdO.jpg"));
              ImageCtrl.Source = bitImg;
              TransformGroup transformGroup = new TransformGroup();
              ScaleTransform scaleTransform = new ScaleTransform(1, 1);
              transformGroup.Children.Add(scaleTransform);

              System.Windows.Controls.Image image = new System.Windows.Controls.Image { Source = ImageCtrl.Source, Stretch = Stretch.Uniform };

              //image.RenderTransform = new ScaleTransform(1, 1);

              BitmapSource imgSrouce = ImageCtrl.Source as BitmapSource;
              if (imgSrouce.PixelWidth < imgSrouce.PixelHeight)
              {
            /*
            double argle = 90 * 180 / 3.142;
            RotateTransform rotateTransform = new RotateTransform();
            rotateTransform.Angle = argle;
            transformGroup.Children.Add(rotateTransform);
             * */
            image.LayoutTransform = new RotateTransform(90);
              }

              image.RenderTransform = transformGroup;

              stackPanel.Children.Add(image);

              stackPanel.Measure(size);
              stackPanel.Arrange(new Rect(new System.Windows.Point(0, 0), stackPanel.DesiredSize));
              this.AddChild(stackPanel);
        }
コード例 #10
0
ファイル: StackPanelTest.cs プロジェクト: dfr0/moon
		public void LayoutSlotTest_Flow ()
		{
			var stack = new StackPanel ();
			var border = new Border () { Width = 100, Height = 200 };
			border.Child = stack;

			stack.FlowDirection = FlowDirection.RightToLeft;
			stack.Orientation = Orientation.Horizontal;
			
			var child0 = CreateSlotItem ();
			var child1 = CreateSlotItem ();
			child1.FlowDirection = FlowDirection.LeftToRight;

			stack.Children.Add (child0);
			stack.Children.Add (child1);
			stack.Children.Add (CreateSlotItem ());
			stack.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			stack.Arrange (new Rect (0,0,stack.DesiredSize.Width,stack.DesiredSize.Height));
			
			Assert.AreEqual (new Rect (0,0,25,33), LayoutInformation.GetLayoutSlot (child0));
			Assert.AreEqual (new Rect (25,0,25,33), LayoutInformation.GetLayoutSlot (child1));
			Assert.AreEqual (new Rect (50,0,25,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]));
			CreateAsyncTest (border, () => {

					MatrixTransform xform0 = child0.TransformToVisual (border) as MatrixTransform;
					Assert.AreEqual ("-1,0,0,1,100,84", xform0.Matrix.ToString(), "transform0 string");

					MatrixTransform xform1 = child1.TransformToVisual (border) as MatrixTransform;
					Assert.AreEqual ("1,0,0,1,50,84", xform1.Matrix.ToString(), "transform1 string");

					MatrixTransform xform0_st = child0.TransformToVisual (stack) as MatrixTransform;
					Assert.AreEqual ("1,0,0,1,0,84", xform0_st.Matrix.ToString(), "transform0_st string");

					MatrixTransform xform1_st = child1.TransformToVisual (stack) as MatrixTransform;
					Assert.AreEqual ("-1,0,0,1,50,84", xform1_st.Matrix.ToString(), "transform1_st string");

				});
 		}
コード例 #11
0
        private void BuildOverlay2D(SOMNode node, ISOMInput[] images, bool showCount, bool showNodeHash, bool showImageHash, bool showSpread, bool showPerImageDistance)
        {
            const int IMAGESIZE = 80;
            const int NODEHASHSIZE = 100;

            const double SMALLFONT1 = 17;
            const double LARGEFONT1 = 21;
            const double SMALLFONT2 = 15;
            const double LARGEFONT2 = 18;
            const double SMALLFONT3 = 12;
            const double LARGEFONT3 = 14;

            const double SMALLLINE1 = .8;
            const double LARGELINE1 = 1;
            const double SMALLLINE2 = .5;
            const double LARGELINE2 = .85;
            const double SMALLLINE3 = .3;
            const double LARGELINE3 = .7;

            Canvas canvas = new Canvas();
            List<Rect> rectangles = new List<Rect>();

            #region cursor rectangle

            var cursorRect = SelfOrganizingMapsWPF.GetMouseCursorRect(0);
            rectangles.Add(cursorRect.Item1);

            // This is just for debugging
            //Rectangle cursorVisual = new Rectangle()
            //{
            //    Width = cursorRect.Item1.Width,
            //    Height = cursorRect.Item1.Height,
            //    Fill = new SolidColorBrush(UtilityWPF.GetRandomColor(64, 192, 255)),
            //};

            //Canvas.SetLeft(cursorVisual, cursorRect.Item1.Left);
            //Canvas.SetTop(cursorVisual, cursorRect.Item1.Top);

            //canvas.Children.Add(cursorVisual);

            #endregion

            #region count text

            if (showCount)
            {
                StackPanel textPanel = new StackPanel()
                {
                    Orientation = Orientation.Horizontal,
                };

                // "images "
                OutlinedTextBlock text = SelfOrganizingMapsWPF.GetOutlineText("images ", SMALLFONT1, SMALLLINE1);
                text.Margin = new Thickness(0, 0, 4, 0);
                textPanel.Children.Add(text);

                // count
                text = SelfOrganizingMapsWPF.GetOutlineText(images.Length.ToString("N0"), LARGEFONT1, LARGELINE1);
                textPanel.Children.Add(text);

                // Place on canvas
                textPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));       // aparently, the infinity is important to get an accurate desired size
                Size textSize = textPanel.DesiredSize;

                Rect textRect = SelfOrganizingMapsWPF.GetFreeSpot(textSize, new Point(0, 0), new Vector(0, 1), rectangles);
                rectangles.Add(textRect);

                Canvas.SetLeft(textPanel, textRect.Left);
                Canvas.SetTop(textPanel, textRect.Top);

                canvas.Children.Add(textPanel);
            }

            #endregion
            #region spread

            var nodeImages = images.Select(o => o.Weights);
            var allImages = _imagesByNode.SelectMany(o => o).Select(o => o.Weights);

            double nodeSpread = images.Length == 0 ? 0d : SelfOrganizingMaps.GetTotalSpread(nodeImages);
            double totalSpread = SelfOrganizingMaps.GetTotalSpread(allImages);

            if (showSpread && images.Length > 0)
            {
                double nodeStandDev = MathND.GetStandardDeviation(nodeImages);
                double totalStandDev = MathND.GetStandardDeviation(allImages);

                double percentSpread = nodeSpread / totalSpread;
                double pecentStandDev = nodeStandDev / totalSpread;

                Grid spreadPanel = new Grid()
                {
                    Margin = new Thickness(2),
                };
                spreadPanel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });
                spreadPanel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(4) });
                spreadPanel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });

                spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
                spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2) });
                spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
                spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2) });
                spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
                spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2) });
                spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
                spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2) });
                spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
                spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2) });
                spreadPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });

                AddTextRow(spreadPanel, 0, "node stand dev", (pecentStandDev * 100).ToStringSignificantDigits(2) + "%", SMALLFONT2, LARGEFONT2, SMALLLINE2, LARGELINE2, true);
                AddTextRow(spreadPanel, 2, "node spread", (percentSpread * 100).ToStringSignificantDigits(2) + "%", SMALLFONT2, LARGEFONT2, SMALLLINE2, LARGELINE2, false);

                AddTextRow(spreadPanel, 4, "node stand dev", nodeStandDev.ToStringSignificantDigits(2), SMALLFONT3, LARGEFONT3, SMALLLINE3, LARGELINE3, true);
                AddTextRow(spreadPanel, 6, "node spread", nodeSpread.ToStringSignificantDigits(2), SMALLFONT3, LARGEFONT3, SMALLLINE3, LARGELINE3, false);

                AddTextRow(spreadPanel, 8, "total stand dev", totalStandDev.ToStringSignificantDigits(2), SMALLFONT3, LARGEFONT3, SMALLLINE3, LARGELINE3, true);
                AddTextRow(spreadPanel, 10, "total spread", totalSpread.ToStringSignificantDigits(2), SMALLFONT3, LARGEFONT3, SMALLLINE3, LARGELINE3, false);

                // Place on canvas
                spreadPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));       // aparently, the infinity is important to get an accurate desired size
                Size spreadSize = spreadPanel.DesiredSize;

                Rect spreadRect = SelfOrganizingMapsWPF.GetFreeSpot(spreadSize, new Point(0, 0), new Vector(0, 1), rectangles);
                rectangles.Add(spreadRect);

                Canvas.SetLeft(spreadPanel, spreadRect.Left);
                Canvas.SetTop(spreadPanel, spreadRect.Top);

                canvas.Children.Add(spreadPanel);
            }

            #endregion

            double[] nodeCenter = images.Length == 0 ? node.Weights : MathND.GetCenter(nodeImages);

            #region node hash

            if (showNodeHash)
            {
                ImageInput nodeImage = new ImageInput(null, node.Weights, node.Weights);

                double nodeDist = MathND.GetDistance(nodeImage.Weights, nodeCenter);
                double nodeDistPercent = nodeSpread.IsNearZero() ? 1d : (nodeDist / nodeSpread);     // if zero or one node, then spread will be zero

                Tuple<UIElement, VectorInt> nodeCtrl = GetPreviewImage(nodeImage, true, NODEHASHSIZE, showPerImageDistance, nodeDistPercent);

                // Place on canvas
                Rect nodeRect = SelfOrganizingMapsWPF.GetFreeSpot(new Size(nodeCtrl.Item2.X, nodeCtrl.Item2.Y), new Point(0, 0), new Vector(0, -1), rectangles);
                rectangles.Add(nodeRect);

                Canvas.SetLeft(nodeCtrl.Item1, nodeRect.Left);
                Canvas.SetTop(nodeCtrl.Item1, nodeRect.Top);

                canvas.Children.Add(nodeCtrl.Item1);
            }

            #endregion

            #region images

            foreach (ImageInput image in images)
            {
                double imageDistPercent;
                if (images.Length == 1)
                {
                    imageDistPercent = 1;
                }
                else
                {
                    imageDistPercent = MathND.GetDistance(image.Weights, nodeCenter) / nodeSpread;
                }

                // Create the image (and any other graphics for that image)
                Tuple<UIElement, VectorInt> imageCtrl = GetPreviewImage(image, showImageHash, IMAGESIZE, showPerImageDistance, imageDistPercent);

                // Find a spot for it
                var imageRect = Enumerable.Range(0, 10).
                    Select(o =>
                    {
                        Vector direction = Math3D.GetRandomVector_Circular_Shell(1).ToVector2D();

                        Rect imageRect2 = SelfOrganizingMapsWPF.GetFreeSpot(new Size(imageCtrl.Item2.X, imageCtrl.Item2.Y), new Point(0, 0), direction, rectangles);

                        return new { Rect = imageRect2, Distance = new Vector(imageRect2.CenterX(), imageRect2.CenterY()).LengthSquared };
                    }).
                    OrderBy(o => o.Distance).
                    First().
                    Rect;

                Canvas.SetLeft(imageCtrl.Item1, imageRect.Left);
                Canvas.SetTop(imageCtrl.Item1, imageRect.Top);

                // Add it
                rectangles.Add(imageRect);
                canvas.Children.Add(imageCtrl.Item1);
            }

            #endregion

            Rect canvasAABB = Math2D.GetAABB(rectangles);

            //NOTE: All the items are placed around zero zero, but that may not be half width and height (items may not be centered)
            canvas.RenderTransform = new TranslateTransform(-canvasAABB.Left, -canvasAABB.Top);

            panelOverlay.Children.Clear();
            panelOverlay.Children.Add(canvas);

            _overlayPolyStats = new OverlayPolygonStats(node, images, canvasAABB, cursorRect.Item2, canvas);
        }
コード例 #12
0
        private void BuildOverlay2D(SOMNode node, ISOMInput[] inputs, bool showCount = false, bool showNodeHash = false)
        {
            const double SMALLFONT1 = 17;
            const double LARGEFONT1 = 21;
            const double SMALLFONT2 = 15;
            const double LARGEFONT2 = 18;
            const double SMALLFONT3 = 12;
            const double LARGEFONT3 = 14;

            const double SMALLLINE1 = .8;
            const double LARGELINE1 = 1;
            const double SMALLLINE2 = .5;
            const double LARGELINE2 = .85;
            const double SMALLLINE3 = .3;
            const double LARGELINE3 = .7;

            Canvas canvas = new Canvas();
            List<Rect> rectangles = new List<Rect>();

            #region cursor rectangle

            var cursorRect = SelfOrganizingMapsWPF.GetMouseCursorRect();
            rectangles.Add(cursorRect.Item1);

            // This is just for debugging
            //Rectangle cursorVisual = new Rectangle()
            //{
            //    Width = cursorRect.Item1.Width,
            //    Height = cursorRect.Item1.Height,
            //    Fill = new SolidColorBrush(UtilityWPF.GetRandomColor(64, 192, 255)),
            //};

            //Canvas.SetLeft(cursorVisual, cursorRect.Item1.Left);
            //Canvas.SetTop(cursorVisual, cursorRect.Item1.Top);

            //canvas.Children.Add(cursorVisual);

            #endregion

            #region count text

            if (showCount && _result != null && _result.InputsByNode != null)       // it's possible that they are changing things while old graphics are still showing
            {
                StackPanel textPanel = new StackPanel()
                {
                    Orientation = Orientation.Horizontal,
                };

                // "rows "
                OutlinedTextBlock text = SelfOrganizingMapsWPF.GetOutlineText("rows ", SMALLFONT1, SMALLLINE1);
                text.Margin = new Thickness(0, 0, 4, 0);
                textPanel.Children.Add(text);

                // percent
                double percent = -1;
                if (_result.InputsByNode.Length == 0)
                {
                    if (inputs.Length == 0)
                    {
                        percent = 0;
                    }
                    else
                    {
                        percent = -1;
                    }
                }
                else
                {
                    percent = inputs.Length.ToDouble() / _result.InputsByNode.SelectMany(o => o).Count().ToDouble();
                    percent *= 100d;
                }
                text = SelfOrganizingMapsWPF.GetOutlineText(percent.ToStringSignificantDigits(2) + "%", LARGEFONT1, LARGELINE1);
                textPanel.Children.Add(text);

                // Place on canvas
                textPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));       // aparently, the infinity is important to get an accurate desired size
                Size textSize = textPanel.DesiredSize;

                Rect textRect = SelfOrganizingMapsWPF.GetFreeSpot(textSize, new Point(0, 0), new Vector(0, -1), rectangles);
                rectangles.Add(textRect);

                Canvas.SetLeft(textPanel, textRect.Left);
                Canvas.SetTop(textPanel, textRect.Top);

                canvas.Children.Add(textPanel);
            }

            #endregion

            double[] nodeCenter = inputs.Length == 0 ? node.Weights : MathND.GetCenter(inputs.Select(o => o.Weights));

            #region node hash

            if (showNodeHash)
            {
                var nodeCtrl = GetVectorVisual(node.Weights);

                // Place on canvas
                Rect nodeRect = SelfOrganizingMapsWPF.GetFreeSpot(new Size(nodeCtrl.Item2.X, nodeCtrl.Item2.Y), new Point(0, 0), new Vector(0, -1), rectangles);
                rectangles.Add(nodeRect);

                Canvas.SetLeft(nodeCtrl.Item1, nodeRect.Left);
                Canvas.SetTop(nodeCtrl.Item1, nodeRect.Top);

                canvas.Children.Add(nodeCtrl.Item1);
            }

            #endregion

            //TODO: For the first attempt, put all row descriptions under
            #region rows

            if (_queryResults != null && _queryResults.Results != null)
            {
                var rowsCtrl = GetRowsVisual(_queryResults.ColumnNames, inputs, _detailsHeaderStyle, _detailsBodyStyle);

                // Place on canvas
                Rect rowsRect = SelfOrganizingMapsWPF.GetFreeSpot(new Size(rowsCtrl.Item2.X, rowsCtrl.Item2.Y), new Point(0, 0), new Vector(0, 1), rectangles);
                rectangles.Add(rowsRect);

                Canvas.SetLeft(rowsCtrl.Item1, rowsRect.Left);
                Canvas.SetTop(rowsCtrl.Item1, rowsRect.Top);

                canvas.Children.Add(rowsCtrl.Item1);
            }

            #endregion

            Rect canvasAABB = Math2D.GetAABB(rectangles);

            //NOTE: All the items are placed around zero zero, but that may not be half width and height (items may not be centered)
            canvas.RenderTransform = new TranslateTransform(-canvasAABB.Left, -canvasAABB.Top);

            panelOverlay.Children.Clear();
            panelOverlay.Children.Add(canvas);

            _overlayPolyStats = new OverlayPolygonStats(node, inputs, canvasAABB, cursorRect.Item2, canvas);
        }
コード例 #13
0
ファイル: MainWindow.cs プロジェクト: wcatykid/GeoShader
        private void Print_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog dialog = new PrintDialog();
            if (dialog.ShowDialog() == true)
            {
                StackPanel panel = new StackPanel();
                panel.Margin = new Thickness(15);
                panel.Children.Add((Canvas)XamlReader.Parse(XamlWriter.Save(this.DrawingHost.DrawingControl)));
                TextBlock myBlock = new TextBlock();
                myBlock.Text = "Drawing";
                myBlock.TextAlignment = TextAlignment.Center;
                panel.Children.Add(myBlock);

                panel.Measure(new Size(dialog.PrintableAreaWidth,
                  dialog.PrintableAreaHeight));
                panel.Arrange(new Rect(new System.Windows.Point(0, 0), panel.DesiredSize));
                dialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
                dialog.PrintVisual(panel, "Drawing");
            }
        }
コード例 #14
0
    Composite
    (
        Double compositeWidth,
        Double compositeHeight,
        String headerText,
        String footerText,
        System.Drawing.Font headerFooterFont,
        IEnumerable<LegendControlBase> legendControls
    )
    {
        Debug.Assert(compositeWidth > 0);
        Debug.Assert(compositeHeight > 0);
        Debug.Assert(headerFooterFont != null);
        Debug.Assert(legendControls != null);
        AssertValid();

        // Note:
        //
        // Don't try taking a shortcut by using
        // NodeXLControl.CopyGraphToBitmap() to get an image of the graph and
        // then compositing the image with the other elements.  That would work
        // if the caller were creating an image, but if it were creating an XPS
        // document, the graph would no longer be scalable.

        Double dScreenDpi =
            WpfGraphicsUtil.GetScreenDpi(m_oNodeXLControl).Width;

        // The NodeXLControl can't be a child of two logical trees, so
        // disconnect it from its parent after saving the current vertex
        // locations.

        m_oLayoutSaver = new LayoutSaver(m_oNodeXLControl.Graph);

        Debug.Assert(m_oNodeXLControl.Parent is Panel);
        m_oParentPanel = (Panel)m_oNodeXLControl.Parent;
        UIElementCollection oParentChildren = m_oParentPanel.Children;
        m_iChildIndex = oParentChildren.IndexOf(m_oNodeXLControl);
        oParentChildren.Remove(m_oNodeXLControl);

        m_oGraphImageScaler = new GraphImageScaler(m_oNodeXLControl);

        m_oGraphImageCenterer = new NodeXLControl.GraphImageCenterer(
            m_oNodeXLControl);

        // The header and footer are rendered as Label controls.  The legend is
        // rendered as a set of Image controls.

        Label oHeaderLabel, oFooterLabel;
        IEnumerable<Image> oLegendImages;
        Double dHeaderHeight, dTotalLegendHeight, dFooterHeight;

        CreateHeaderOrFooterLabel(headerText, compositeWidth, headerFooterFont,
            out oHeaderLabel, out dHeaderHeight);

        CreateLegendImages(legendControls, compositeWidth, out oLegendImages,
            out dTotalLegendHeight);

        CreateHeaderOrFooterLabel(footerText, compositeWidth, headerFooterFont,
            out oFooterLabel, out dFooterHeight);

        m_oNodeXLControl.Width = compositeWidth;

        m_oNodeXLControl.Height = Math.Max(10,
            compositeHeight - dHeaderHeight - dTotalLegendHeight
            - dFooterHeight);

        // Adjust the control's graph scale so that the graph's vertices and
        // edges will be the same relative size in the composite that they are
        // in the control.

        m_oGraphImageScaler.SetGraphScale(
            (Int32)WpfGraphicsUtil.WpfToPx(compositeWidth, dScreenDpi),
            (Int32)WpfGraphicsUtil.WpfToPx(m_oNodeXLControl.Height, dScreenDpi),
            dScreenDpi);

        // Adjust the NodeXLControl's translate transforms so that the
        // composite will be centered on the same point on the graph that the
        // NodeXLControl is centered on.

        m_oGraphImageCenterer.CenterGraphImage( new Size(compositeWidth,
            m_oNodeXLControl.Height) );

        StackPanel oStackPanel = new StackPanel();
        UIElementCollection oStackPanelChildren = oStackPanel.Children;

        // To avoid a solid black line at the bottom of the header or the top
        // of the footer, which is caused by rounding errors, make the
        // StackPanel background color the same as the header and footer.

        oStackPanel.Background = HeaderFooterBackgroundBrush;

        if (oHeaderLabel != null)
        {
            oStackPanelChildren.Add(oHeaderLabel);
        }

        // Wrap the NodeXLControl in a Grid to clip it.

        m_oGrid = new Grid();
        m_oGrid.Width = m_oNodeXLControl.Width;
        m_oGrid.Height = m_oNodeXLControl.Height;
        m_oGrid.ClipToBounds = true;
        m_oGrid.Children.Add(m_oNodeXLControl);

        oStackPanelChildren.Add(m_oGrid);

        foreach (Image oLegendImage in oLegendImages)
        {
            oStackPanelChildren.Add(oLegendImage);
        }

        if (oFooterLabel != null)
        {
            oStackPanelChildren.Add(oFooterLabel);
        }

        Size oCompositeSize = new Size(compositeWidth, compositeHeight);
        Rect oCompositeRectangle = new Rect(new Point(), oCompositeSize);

        oStackPanel.Measure(oCompositeSize);
        oStackPanel.Arrange(oCompositeRectangle);
        oStackPanel.UpdateLayout();

        return (oStackPanel);
    }
コード例 #15
0
ファイル: MouseDeviceTest.cs プロジェクト: highzion/Granular
        public void MouseDeviceQueryCursorTest()
        {
            Border child1 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 };
            Border child2 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 };

            StackPanel panel = new StackPanel { IsRootElement = true };
            panel.Children.Add(child1);
            panel.Children.Add(child2);

            TestPresentationSource presentationSource = new TestPresentationSource();
            presentationSource.RootElement = panel;

            ((TestApplicationHost)ApplicationHost.Current).PresentationSourceFactory = new TestPresentationSourceFactory(presentationSource);

            panel.Measure(Size.Infinity);
            panel.Arrange(new Rect(panel.DesiredSize));

            child1.Cursor = Cursors.Help;
            child2.Cursor = Cursors.Pen;

            presentationSource.MouseDevice.Activate();
            Assert.AreEqual(Cursors.Arrow, presentationSource.MouseDevice.Cursor);

            presentationSource.MouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 50), 0));
            Assert.AreEqual(Cursors.Help, presentationSource.MouseDevice.Cursor);

            presentationSource.MouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 150), 0));
            Assert.AreEqual(Cursors.Pen, presentationSource.MouseDevice.Cursor);

            child2.Cursor = Cursors.Hand;
            Assert.AreEqual(Cursors.Hand, presentationSource.MouseDevice.Cursor);

            panel.Cursor = Cursors.Arrow;
            Assert.AreEqual(Cursors.Hand, presentationSource.MouseDevice.Cursor);

            panel.ForceCursor = true;
            Assert.AreEqual(Cursors.Arrow, presentationSource.MouseDevice.Cursor);

            ((TestApplicationHost)ApplicationHost.Current).PresentationSourceFactory = null;
        }
コード例 #16
0
ファイル: StackPanelTest.cs プロジェクト: highzion/Granular
        public void StackPanelMarginTest()
        {
            StackPanel panel = new StackPanel { Orientation = Orientation.Horizontal };

            FrameworkElement child1 = new FrameworkElement { Width = 80, Margin = new Thickness(10) };
            FrameworkElement child2 = new FrameworkElement { Width = 60, Margin = new Thickness(20) };
            FrameworkElement child3 = new FrameworkElement { Width = 40, Margin = new Thickness(30) };

            panel.Children.Add(child1);
            panel.Children.Add(child2);
            panel.Children.Add(child3);

            panel.Measure(new Size(1000, 1000));

            Assert.AreEqual(new Size(300, 60), panel.DesiredSize);

            panel.Arrange(new Rect(300, 1000));

            Assert.AreEqual(new Size(300, 1000), panel.VisualSize);

            Assert.AreEqual(new Size(80, 980), child1.VisualSize);
            Assert.AreEqual(new Size(60, 960), child2.VisualSize);
            Assert.AreEqual(new Size(40, 940), child3.VisualSize);

            Assert.AreEqual(new Point(10, 10), child1.VisualOffset);
            Assert.AreEqual(new Point(120, 20), child2.VisualOffset);
            Assert.AreEqual(new Point(230, 30), child3.VisualOffset);
        }
コード例 #17
0
ファイル: PanelTest.cs プロジェクト: dfr0/moon
		public void MinWidthOnParentTest ()
		{
			StackPanel sp = new StackPanel { MinWidth = 200 };
			LayoutPoker c = new LayoutPoker { Height = 25 };

			sp.Children.Add (c);

			sp.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (200,25), c.MeasureArg, "c.Measure");

			Assert.AreEqual (new Size (0,25), c.DesiredSize);

			sp.Arrange (new Rect (0, 0, 100, 100));

			Assert.AreEqual (new Size (200,25), c.ArrangeArg, "c.Arrange");

			// now check desired/render sizes

			// the child is oblivious to the parent's maxheight
			Assert.AreEqual (new Size (0,0), c.RenderSize, "c.RenderedSize");
			Assert.AreEqual (new Size (0,25), c.DesiredSize, "c.DesiredSize");
			Assert.IsNull (LayoutInformation.GetLayoutClip (c), "c.LayoutClip == null");

			// the parent's maxheight clips
			Assert.AreEqual (new Size (200,100), sp.RenderSize, "sp.RenderSize");
			Assert.AreEqual (new Size (100,25), sp.DesiredSize, "sp.DesiredSize");
			Assert.IsNotNull (LayoutInformation.GetLayoutClip (sp), "sp.LayoutClip != null");
		}
コード例 #18
0
 private void MeasureView(UIElement view)
 {
     if (this.panel.Children.Contains(view))
     {
         this.panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
     }
     else if (VisualTreeHelper.GetParent(view) == null)
     {
         StackPanel stackPanel = new StackPanel();
         stackPanel.Children.Add(view);
         if (view is VirtualizedContainerService.VirtualizingContainer)
         {
             ((VirtualizedContainerService.VirtualizingContainer)view).Populate();
         }
         stackPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
         stackPanel.UpdateLayout();
         stackPanel.Children.Remove(view);
         FreeFormPanel.SetChildSize(view, view.DesiredSize);
     }
     else
     {
         Fx.Assert(false, "The view should either be un-rooted or contained in the FreeFormPanel");
     }
 }
コード例 #19
0
ファイル: Home.xaml.cs プロジェクト: rj128x/VotGESOrders
        private List<StackPanel> getPrintPages(double width, double height)
        {
            List<StackPanel> pages=new List<StackPanel>();
            bool finish=false;
            int index=0;
            while (!finish) {
                StackPanel host = new StackPanel();
                bool isFirst=true;
                while (index < OrdersContext.Current.View.Count) {
                    OrderPrintBriefLandscapeControl cntrl = new OrderPrintBriefLandscapeControl();
                    cntrl.DataContext = OrdersContext.Current.View.GetItemAt(index); ;
                    //cntrl.UpdateLayout();
                    if (isFirst) {
                        cntrl.showHeader();
                    }
                    isFirst = false;
                    host.Children.Add(cntrl);

                    host.Measure(new Size(width, double.PositiveInfinity));

                    //Logger.logMessage(cntrl.DesiredSize.Height+" "+ host.DesiredSize.Height + " " + height);
                    if (host.DesiredSize.Height > height && host.Children.Count > 1) {
                        host.Children.Remove(cntrl);
                        break;
                    }
                    index++;
                    finish = OrdersContext.Current.View.Count == index;
                }
                pages.Add(host);
            }
            return pages;
        }
コード例 #20
0
        private void AddMeasures()
        {
            foreach (var measurement in _measurements)
            {
                var line = new Line
                {
                    Stroke = new SolidColorBrush(Colors.Yellow),
                    StrokeThickness = 2,
                    X1 = measurement.StartPoint.X - (4 * ScrollPosition),
                    Y1 = measurement.StartPoint.Y,
                    X2 = measurement.EndPoint.X - (4 * ScrollPosition),
                    Y2 = measurement.EndPoint.Y
                };

                Panel.SetZIndex(line, 2);
                ControlCanvas.Children.Add(line);

                var startPoint = new Point(line.X1, line.Y1);
                var endPoint = new Point(line.X2, line.Y2);
                var v = startPoint - endPoint;
                var midpoint = endPoint + (v / 2);
                var theta = Math.Atan2(v.Y, v.X);
                var offset = Math.PI / 2;
                if (v.Y > 0)
                    offset = -Math.PI / 2;

                var theta2 = theta + offset;
                var x4 = 10 * Math.Cos(theta2) + midpoint.X;
                var y4 = 10 * Math.Sin(theta2) + midpoint.Y;

                var x3 = 30 * Math.Cos(theta2) + midpoint.X;
                var y3 = 30 * Math.Sin(theta2) + midpoint.Y;

                var redline = new Line
                {
                    Stroke = new SolidColorBrush(Colors.Yellow),
                    X1 = x4,
                    Y1 = y4,
                    X2 = x3,
                    Y2 = y3,
                    StrokeThickness = 2
                };

                // anchor points
                AddAnchor(startPoint);
                AddAnchor(endPoint);

                var panel = new StackPanel();
                var outerBorder = new Border
                {
                    Background = new SolidColorBrush(Color.FromArgb(0xa2, 0xaf, 0x2a, 0x2a)),
                    CornerRadius = new CornerRadius(4),
                };

                var innerBorder = new Border
                {
                    Margin = new Thickness(4),
                    Background = new SolidColorBrush(Color.FromArgb(0xa2, 0xf2, 0xda, 0xc7)),
                    CornerRadius = new CornerRadius(4)
                };

                panel.Children.Add(outerBorder);
                outerBorder.Child = innerBorder;

                var grid = new Grid { Margin = new Thickness(5) };
                grid.ColumnDefinitions.Add(new ColumnDefinition());
                grid.ColumnDefinitions.Add(new ColumnDefinition());

                var rowDefinition = new RowDefinition();
                rowDefinition.Height = new GridLength(1, GridUnitType.Auto);

                grid.RowDefinitions.Add(rowDefinition);
                grid.RowDefinitions.Add(new RowDefinition());
                grid.RowDefinitions.Add(new RowDefinition());

                var voltageLabel = new Label { Foreground = new SolidColorBrush(Colors.Brown), Margin = new Thickness(0, 0, 2, 0), Content = "Voltage:", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Right, FontSize = 10.0 };
                var voltageValueLabel = new Label { FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(Colors.White), Content = measurement.VoltageMeasure, VerticalAlignment = VerticalAlignment.Center, FontSize = 10.0 };
                var timeLabel = new Label { Foreground = new SolidColorBrush(Colors.Brown), Margin = new Thickness(0, 0, 2, 0), Content = "Time:", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Right, FontSize = 10.0 };
                var timeValueLabel = new Label { FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(Colors.White), Content = measurement.TimeMeasure, VerticalAlignment = VerticalAlignment.Center, FontSize = 10.0 };

                var button = new ButtonChrome();
                button.Content = "X";
                button.HorizontalAlignment = HorizontalAlignment.Right;
                button.FontSize = 10.0;
                button.Padding = new Thickness(4);
                button.CornerRadius = new CornerRadius(4);

                button.Cursor = Cursors.Hand;

                button.MouseDown += ButtonOnMouseDown;

                Grid.SetColumn(voltageValueLabel, 1);
                Grid.SetColumn(timeValueLabel, 1);

                Grid.SetRow(voltageLabel, 1);
                Grid.SetRow(voltageValueLabel, 1);

                Grid.SetRow(timeLabel, 2);
                Grid.SetRow(timeValueLabel, 2);

                Grid.SetColumn(button, 1);

                var title = new Label();
                title.Content = "Measurement";
                title.FontSize = 10;
                title.HorizontalAlignment = HorizontalAlignment.Right;
                title.Foreground = new SolidColorBrush(Colors.White);
                title.FontWeight = FontWeights.Bold;

                grid.Children.Add(title);
                grid.Children.Add(voltageLabel);
                grid.Children.Add(voltageValueLabel);
                grid.Children.Add(timeLabel);
                grid.Children.Add(timeValueLabel);
                grid.Children.Add(button);

                innerBorder.Child = grid;

                panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                var top = y3;
                if ((endPoint.X <= startPoint.X && endPoint.Y <= startPoint.Y) || (endPoint.X >= startPoint.X && endPoint.Y >= startPoint.Y))
                {
                    top -= panel.DesiredSize.Height;
                }

                Panel.SetZIndex(panel, 1);
                Canvas.SetLeft(panel, x3);
                Canvas.SetTop(panel, top);

                var polyLineArrowHead = AddArrowHead(midpoint, theta2);

                ControlCanvas.Children.Add(redline);
                ControlCanvas.Children.Add(polyLineArrowHead);
                ControlCanvas.Children.Add(panel);
            }
        }
コード例 #21
-1
        private void Print(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                PrintDialog dlg = new PrintDialog();
                configData.IsRedy = false;
                configData.IsError = false;
                var conf = new PrintPluginViewModel(configData);
                var outfile = Path.Combine(Path.GetTempPath(), Path.GetFileName(item.FileName));

                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                System.Printing.PrintCapabilities capabilities = dlg.PrintQueue.GetPrintCapabilities(dlg.PrintTicket);
                var PageWidth = (int)capabilities.PageImageableArea.ExtentWidth;
                var PageHeight = (int)capabilities.PageImageableArea.ExtentHeight;

                var panel = new StackPanel
                {
                    Margin = new Thickness(conf.Margin),
                };

                var image = new Image
                {
                    Source = BitmapLoader.Instance.LoadImage(outfile, PageWidth > PageHeight ? PageWidth : PageHeight, conf.Rotate ? 90 : 0),
                    Width = PageWidth ,
                    Height = PageHeight,
                    Stretch = Stretch.Uniform,
                };

               
                panel.Children.Add(image);
                panel.UpdateLayout();
                panel.Measure(new Size(PageWidth, PageHeight));
                panel.Arrange(new Rect(new Point(0, 0), panel.DesiredSize));
                panel.UpdateLayout();
                dlg.PrintVisual(panel, item.Name);
                image.Source = null;
                panel.Children.Clear();
                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error print file", exception);
                configData.IsError = true;
                configData.Error = exception.Message;
            }

            configData.IsRedy = true;            
        }