예제 #1
0
        public HitTestResultBehavior MyHitTestResultCallback(HitTestResult result)
        {
            // Retrieve the results of the hit test.
            IntersectionDetail intersectionDetail = ((GeometryHitTestResult)result).IntersectionDetail;

            ControlOnCanvas controlAdd = null;

            if (result.VisualHit is Image)
            {
                if (((Image)result.VisualHit).TemplatedParent is ControlOnCanvas)
                {
                    controlAdd = ((Image)result.VisualHit).TemplatedParent as ControlOnCanvas;
                }
            }

            switch (intersectionDetail)
            {
            case IntersectionDetail.FullyContains:

                // Add the hit test result to the list that will be processed after the enumeration.

                if (controlAdd != null)
                {
                    hitResultsList.Add(controlAdd);
                }

                return(HitTestResultBehavior.Continue);

            case IntersectionDetail.Intersects:

                // Set the behavior to return visuals at all z-order levels.
                if (controlAdd != null)
                {
                    hitResultsList.Add(controlAdd);
                }

                return(HitTestResultBehavior.Continue);

            case IntersectionDetail.FullyInside:

                // Set the behavior to return visuals at all z-order levels.
                if (controlAdd != null)
                {
                    hitResultsList.Add(controlAdd);
                }

                return(HitTestResultBehavior.Continue);

            default:
                return(HitTestResultBehavior.Stop);
            }
        }
예제 #2
0
        public int CompareTo(object obj)
        {
            ControlOnCanvas otherControlOnCanvas = obj as ControlOnCanvas;

            if (otherControlOnCanvas != null)
            {
                return(this.ZIndex.CompareTo(otherControlOnCanvas.controlOnCanvasSer.ZIndex));
            }
            else
            {
                throw new ArgumentException("Пустой объект для сортировки");
            }
        }
예제 #3
0
        public override void DeleteItem(ControlOnCanvas objectOnCanvas)
        {
            Page page = ((AppWPF)Application.Current).CollectionPage[objectOnCanvas.IS.Path];

            if (objectOnCanvas is Pipe)
            {
                Pipe pipe = objectOnCanvas as Pipe;
                page.CollectionPipe.Remove(pipe.PipeSer);
            }
            else if (objectOnCanvas is Pipe90)
            {
                Pipe90 pipe90 = objectOnCanvas as Pipe90;
                page.CollectionPipe90.Remove(pipe90.Pipe90Ser);
            }
            else if (objectOnCanvas is Text)
            {
                Text text = objectOnCanvas as Text;
                page.CollectionText.Remove(text.TextSer);
            }
            else if (objectOnCanvas is Display)
            {
                Display display = objectOnCanvas as Display;
                page.CollectionDisplay.Remove(display.DisplaySer);
            }
            else if (objectOnCanvas is ImageControl)
            {
                ImageControl imageControl = objectOnCanvas as ImageControl;
                page.CollectionImage.Remove(imageControl.ImageSer);
            }
            else if (objectOnCanvas is EthernetControl)
            {
                EthernetControl ethernetControl = objectOnCanvas as EthernetControl;
                page.CollectionEthernet.Remove(ethernetControl.EthernetSer);
                ((AppWPF)Application.Current).CollectionEthernetSers.Remove(((EthernetControl)objectOnCanvas).EthernetSer);
            }
            else if (objectOnCanvas is ComControl)
            {
                ComControl comControl = objectOnCanvas as ComControl;
                page.CollectionCom.Remove(comControl.ComSer);
                ((AppWPF)Application.Current).CollectionComSers.Remove(((ComControl)objectOnCanvas).ComSer);
            }
            else if (objectOnCanvas is ModbusControl)
            {
                ModbusControl modbusControl = objectOnCanvas as ModbusControl;
                page.CollectionModbus.Remove(modbusControl.ModbusSer);
                ((AppWPF)Application.Current).CollectionModbusSers.Remove(modbusControl.ModbusSer);
            }

            objectOnCanvas.CanvasTab.Children.Remove(objectOnCanvas);
        }
예제 #4
0
 public virtual void DeleteItem(ControlOnCanvas objectOnCanvas)
 {
 }
예제 #5
0
        public override void SelectOne()
        {
            if (this.CanvasPage.CountSelect == 1 && !this.IsSelected && Keyboard.Modifiers != ModifierKeys.Control)
            {
                ControlOnCanvas controlOnCanvas = CanvasPage.SelectedControlOnCanvas[0];
                controlOnCanvas.IsSelected = false;
                controlOnCanvas.border.Pen.Brush.Opacity = 0;

                this.IsSelected = true;
                this.border.Pen.Brush.Opacity = 100;
                this.CanvasPage.CountSelect   = 1;

                CanvasPage.SelectedControlOnCanvas[0] = this;

                if (this is PipeOnCanvas)
                {
                    PipeOnCanvas pipeOnCanvas = this as PipeOnCanvas;
                    pipeOnCanvas.TextBoxDiameter.IsReadOnly        = false;
                    pipeOnCanvas.ComboBoxEnvironment.IsEnabled     = true;
                    pipeOnCanvas.TextBoxDiameter.Text              = string.Format("{0:F2}", pipeOnCanvas.Diameter);
                    pipeOnCanvas.ComboBoxEnvironment.SelectedIndex = pipeOnCanvas.IntEnvironment;
                }

                CoordinateX.IsReadOnly = false;
                CoordinateY.IsReadOnly = false;

                if (controlOnCanvasSer.Transform == 0)
                {
                    CoordinateX.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.LeftProperty));
                    CoordinateY.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.TopProperty));
                }
                else if (controlOnCanvasSer.Transform == -90 || controlOnCanvasSer.Transform == 270)
                {
                    CoordinateY.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.TopProperty) - this.ActualWidth);
                    CoordinateX.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.LeftProperty));
                }
                else if (controlOnCanvasSer.Transform == -180 || controlOnCanvasSer.Transform == 180)
                {
                    CoordinateY.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.TopProperty) - this.ActualHeight);
                    CoordinateX.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.LeftProperty) - this.ActualWidth);
                }
                else if (controlOnCanvasSer.Transform == -270 || controlOnCanvasSer.Transform == 90)
                {
                    CoordinateY.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.TopProperty));
                    CoordinateX.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.LeftProperty) - this.ActualHeight);
                }
            }
            else if (this.CanvasPage.CountSelect == 1 && !this.IsSelected && Keyboard.Modifiers == ModifierKeys.Control)
            {
                MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;

                this.IsSelected = true;
                this.border.Pen.Brush.Opacity = 100;
                this.CanvasPage.CountSelect  += 1;

                CanvasPage.SelectedControlOnCanvas.Add(this);

                PipeOnCanvas pipeOld       = null;
                PipeOnCanvas pipe          = null;
                bool         falseComparer = false;
                int          countPipe     = 0;

                foreach (ControlOnCanvasPage controlOnCanvas in CanvasPage.SelectedControlOnCanvas)
                {
                    if (controlOnCanvas is PipeOnCanvas)
                    {
                        countPipe += 1;

                        if (!falseComparer)
                        {
                            if (countPipe > 1)
                            {
                                pipe = controlOnCanvas as PipeOnCanvas;

                                if (Math.Round(pipeOld.Diameter, 2, MidpointRounding.AwayFromZero) != Math.Round(pipe.Diameter, 2, MidpointRounding.AwayFromZero))
                                {
                                    pipe.TextBoxDiameter.Text = "-";
                                }
                                else
                                {
                                    pipe.TextBoxDiameter.Text = string.Format("{0:F2}", pipe.Diameter);
                                }
                                if (pipeOld.IntEnvironment != pipe.IntEnvironment)
                                {
                                    pipe.ComboBoxEnvironment.SelectedIndex = -1;
                                }
                                else
                                {
                                    pipe.ComboBoxEnvironment.SelectedIndex = pipe.IntEnvironment;
                                }

                                if (Math.Round(pipeOld.Diameter, 2, MidpointRounding.AwayFromZero) != Math.Round(pipe.Diameter, 2, MidpointRounding.AwayFromZero))
                                {
                                    falseComparer = true;
                                }
                                else if (pipeOld.IntEnvironment != pipe.IntEnvironment)
                                {
                                    falseComparer = true;
                                }
                            }
                        }

                        pipeOld = (PipeOnCanvas)controlOnCanvas;
                    }
                }

                if (countPipe == 1)
                {
                    mainWindow.TextBoxDiameter.IsReadOnly        = false;
                    mainWindow.ComboBoxEnvironment.IsEnabled     = true;
                    mainWindow.TextBoxDiameter.Text              = string.Format("{0:F2}", pipeOld.Diameter);
                    mainWindow.ComboBoxEnvironment.SelectedIndex = pipeOld.IntEnvironment;
                }

                CoordinateX.IsReadOnly = true;
                CoordinateY.IsReadOnly = true;
                CoordinateX.Text       = null;
                CoordinateY.Text       = null;
            }
            else if (Keyboard.Modifiers != ModifierKeys.Control && this.IsSelected)
            {
                return;
            }
            else if (Keyboard.Modifiers == ModifierKeys.Control && this.IsSelected)
            {
                this.IsSelected = false;
                this.border.Pen.Brush.Opacity = 0;
                this.CanvasPage.CountSelect   = 0;

                CanvasPage.SelectedControlOnCanvas.Remove(this);

                MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;

                if (this is PipeOnCanvas)
                {
                    mainWindow.TextBoxDiameter.IsReadOnly        = true;
                    mainWindow.ComboBoxEnvironment.IsEnabled     = false;
                    mainWindow.ComboBoxEnvironment.SelectedIndex = -1;
                    mainWindow.TextBoxDiameter.Text = null;
                }

                CoordinateX.IsReadOnly = true;
                CoordinateY.IsReadOnly = true;
                CoordinateX.Text       = null;
                CoordinateY.Text       = null;
            }
            else
            {
                this.IsSelected = true;
                this.border.Pen.Brush.Opacity = 100;
                this.CanvasPage.CountSelect   = 1;

                CanvasPage.SelectedControlOnCanvas.Add(this);

                if (this is PipeOnCanvas)
                {
                    PipeOnCanvas pipeOnCanvas = this as PipeOnCanvas;
                    pipeOnCanvas.TextBoxDiameter.IsReadOnly        = false;
                    pipeOnCanvas.ComboBoxEnvironment.IsEnabled     = true;
                    pipeOnCanvas.TextBoxDiameter.Text              = string.Format("{0:F2}", pipeOnCanvas.Diameter);
                    pipeOnCanvas.ComboBoxEnvironment.SelectedIndex = pipeOnCanvas.IntEnvironment;
                }

                CoordinateX.IsReadOnly = false;
                CoordinateY.IsReadOnly = false;

                if (controlOnCanvasSer.Transform == 0)
                {
                    CoordinateX.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.LeftProperty));
                    CoordinateY.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.TopProperty));
                }
                else if (controlOnCanvasSer.Transform == -90 || controlOnCanvasSer.Transform == 270)
                {
                    CoordinateY.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.TopProperty) - this.ActualWidth);
                    CoordinateX.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.LeftProperty));
                }
                else if (controlOnCanvasSer.Transform == -180 || controlOnCanvasSer.Transform == 180)
                {
                    CoordinateY.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.TopProperty) - this.ActualHeight);
                    CoordinateX.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.LeftProperty) - this.ActualWidth);
                }
                else if (controlOnCanvasSer.Transform == -270 || controlOnCanvasSer.Transform == 90)
                {
                    CoordinateY.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.TopProperty));
                    CoordinateX.Text = string.Format("{0:F2}", (double)this.GetValue(Canvas.LeftProperty) - this.ActualHeight);
                }
            }

            LabelSelected.Content = "Выделенно объектов: " + this.CanvasPage.CountSelect;
        }