Beispiel #1
0
 private void canvas1_MouseMove(object sender, MouseEventArgs e)
 {
     if (_drawing)
     {
         _stepShape.DrawMouseMove((e.GetPosition(canvas1).X - _last_mouse_location.X), (e.GetPosition(canvas1).Y - _last_mouse_location.Y));
         _last_mouse_location = e.GetPosition(canvas1);
     }
     else if (_movingShape)
     {
         _stepShape.MoveShape(e.GetPosition(canvas1).X - _last_mouse_location.X, e.GetPosition(canvas1).Y - _last_mouse_location.Y);
         _last_mouse_location = e.GetPosition(canvas1);
     }
     else if (_movingReferencePoint)
     {
         _refPoint.Move(e.GetPosition(canvas1).X, e.GetPosition(canvas1).Y);
         _refPoint.MoveFixtureTo();
     }
     else if (_movingAttributePoint)
     {
         Point p            = e.GetPosition(canvas1);
         Shape closestShape = (Shape)GetClosestCanvasChild(p);
         Point closestPoint = GetClosestPointOnShape(closestShape, p);
         _attrPoint.Point = closestPoint;
         Canvas.SetLeft(_attrPoint.Ellipse, closestPoint.X - 450);
         Canvas.SetTop(_attrPoint.Ellipse, closestPoint.Y - 450);
         if (LivePreview)
         {
             ((RoutineFixture)lbxTimeline.SelectedItem).Fixture.MoveTo(closestPoint, 0);
         }
     }
     else if (_makingPathStep2)
     {
         _stepShape.DrawStep2MouseMove(e.GetPosition(canvas1).X - _last_mouse_location.X, e.GetPosition(canvas1).Y - _last_mouse_location.Y);
         _last_mouse_location = e.GetPosition(canvas1);
     }
 }
Beispiel #2
0
        /*
         * CANVAS/DRAWING
         */
        private void canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //Must have left the canvas while drawing and now they clicking to stop darwing?
            if (_drawing)
            {
                return;
            }

            if (_makingPathStep2)
            {
                _makingPathStep2 = false;
                _makingPath      = false;
                return;
            }

            Point p = e.GetPosition((UIElement)sender);

            HitTestResult result = VisualTreeHelper.HitTest(canvas1, p);

            //Check to make sure there is a Fixture selected in the Timeline
            if (lbxTimeline.SelectedItem == null || !(lbxTimeline.SelectedItem is RoutineFixture))
            {
                if (_activeTool == null)
                {
                    return;
                }
                if (lbxTimeline.Items.Count > 0)
                {
                    MessageBox.Show("You must select a fixture to add the step to.");
                }
                else
                {
                    MessageBox.Show("You must add a fixture first.");
                }
                return;
            }

            //Move an attribute point after it has already been placed.
            if (result.VisualHit.GetType() == typeof(Ellipse))
            {
                if (((Ellipse)result.VisualHit).Name.Contains("_attrPoint"))
                {
                    _attrPoint            = GetAttributePointEllipseParent((Ellipse)result.VisualHit);
                    _movingAttributePoint = true;
                    return;
                }
            }

            //The move tool. :) For moving a shape.
            if (_activeTool == btnToolbarMove)
            {
                Shape     closestShape = (Shape)GetClosestCanvasChild(p);
                StepShape stepShape    = GetShapeParent(closestShape);
                _movingShape = true;
                _stepShape   = stepShape;
                _stepShape.Select();
                foreach (UIElement element in canvas1.Children)
                {
                    if (element.GetType() == typeof(Shape))
                    {
                        if (((Shape)element).Name.Contains("_stepShape"))
                        {
                            StepShape parent = GetShapeParent((Shape)element);
                            parent.Deselect();
                        }
                    }
                }
            }

            if (_stepShape == null || result.VisualHit != _stepShape.Shape)
            {
                //This probably shouldn't get here. I don't know where it should go yet
                if (_stepShape != null)
                {
                    _stepShape.Deselect();
                }

                //If user has selected a shape tool.
                if (_activeTool != null && (_activeTool == btnToolbarCircle || _activeTool == btnToolbarDot || _activeTool == btnToolbarLine ||
                                            _activeTool == btnToolbarPolyline || _activeTool == btnToolbarRectangle || _activeTool == btnToolbarArc))
                {
                    _drawing = true;
                    RemoveCurrentShape();
                    if (_activeTool == btnToolbarCircle)
                    {
                        Ellipse ell = (Ellipse)StepEllipse.Draw(e.GetPosition(canvas1).X, e.GetPosition(canvas1).Y);
                        ell.Name += "_stepShape";
                        canvas1.Children.Add(ell);
                        _stepShape = new StepEllipse(ell);
                    }
                    else if (_activeTool == btnToolbarRectangle)
                    {
                        Rectangle rect = StepRectangle.Draw(e.GetPosition(canvas1).X, e.GetPosition(canvas1).Y);
                        rect.Name += "_stepShape";
                        canvas1.Children.Add(rect);
                        _stepShape = new StepRectangle(rect);
                    }
                    else if (_activeTool == btnToolbarLine)
                    {
                        Line line = StepLine.Draw(e.GetPosition(canvas1).X, e.GetPosition(canvas1).Y);
                        line.Name += "_stepShape";
                        canvas1.Children.Add(line);
                        _stepShape = new StepLine(line);
                    }
                    else if (_activeTool == btnToolbarArc)
                    {
                        _stepShape             = new StepPath(e.GetPosition(canvas1).X, e.GetPosition(canvas1).Y);
                        _stepShape.Shape.Name += "_stepShape";
                        canvas1.Children.Add(_stepShape.Shape);
                        _makingPath = true;
                    }
                    else if (_activeTool == btnToolbarPolyline)
                    {
                        _stepShape             = new StepFreeForm(e.GetPosition(canvas1).X, e.GetPosition(canvas1).Y);
                        _stepShape.Shape.Name += "_stepShape";
                        canvas1.Children.Add(_stepShape.Shape);
                    }
                    _last_mouse_location = e.GetPosition(canvas1);
                    //Create new list item for the step shape & add to list.
                    RoutineStep rs = new RoutineStep("New Step", _stepShape, _routine);
                    ((RoutineFixture)lbxTimeline.SelectedItem).RoutineSteps.Add(rs);
                    _lastSelectedStep = rs;

                    /*Horrible way to refresh the listbox.  Need to figure this out.
                     * Currently it removes the row that allows you to add more fixutres. Can't do that!
                     */
                    //lbxSteps.ItemsSource = null;
                    //lbxSteps.Items.Clear();
                    //lbxSteps.ItemsSource = ((RoutineFixture)lbxTimeline.SelectedItem).RoutineSteps;
                }
                //Not drawing something, making a reference point?
                else if (_activeTool == btnToolbarReferencePoint)
                {
                    _movingReferencePoint = true;
                    _refPoint             = new RoutineFixtureReferencePoint((RoutineFixture)lbxTimeline.SelectedItem, e.GetPosition(canvas1));
                    canvas1.Children.Add(_refPoint.Ellipse);
                    canvas1.Children.Add(_refPoint.Label);
                    _refPoint.MoveFixtureTo();
                    ((RoutineFixture)lbxTimeline.SelectedItem).Fixture.On();
                }
                //Not a referencePoint, is it an Attribute Point?
                else if (_activeTool == btnToolbarAttrPoint)
                {
                    _movingAttributePoint = true;

                    Shape closestShape = (Shape)GetClosestCanvasChild(p);
                    Point closestPoint = GetClosestPointOnShape(closestShape, p);

                    _attrPoint = new AttributePoint(closestPoint, ((RoutineFixture)lbxTimeline.SelectedItem).Fixture);
                    canvas1.Children.Add(_attrPoint.Ellipse);
                    Canvas.SetLeft(_attrPoint.Ellipse, closestPoint.X - 450);
                    Canvas.SetTop(_attrPoint.Ellipse, closestPoint.Y - 450);
                    _lastSelectedStep.AddAttributePoint(_attrPoint);

                    //Live Preview
                    if (LivePreview)
                    {
                        ((RoutineFixture)lbxTimeline.SelectedItem).Fixture.MoveTo(closestPoint, 0);
                    }
                }
            }
        }
        /*
         * CANVAS/DRAWING
         */
        private void canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //Must have left the canvas while drawing and now they clicking to stop darwing?
            if (_drawing)
                return;

            if (_makingPathStep2)
            {
                _makingPathStep2 = false;
                _makingPath = false;
                return;
            }

            Point p = e.GetPosition((UIElement)sender);

            HitTestResult result = VisualTreeHelper.HitTest(canvas1, p);

            //Check to make sure there is a Fixture selected in the Timeline
            if (lbxTimeline.SelectedItem == null || !(lbxTimeline.SelectedItem is RoutineFixture))
            {
                if (_activeTool == null) return;
                if(lbxTimeline.Items.Count > 0)
                    MessageBox.Show("You must select a fixture to add the step to.");
                else
                    MessageBox.Show("You must add a fixture first.");
                return;
            }

            //Move an attribute point after it has already been placed.
            if (result.VisualHit.GetType() == typeof(Ellipse))
            {
                if (((Ellipse)result.VisualHit).Name.Contains("_attrPoint"))
                {
                    _attrPoint = GetAttributePointEllipseParent((Ellipse)result.VisualHit);
                    _movingAttributePoint = true;
                    return;
                }
            }

            //The move tool. :) For moving a shape.
            if (_activeTool == btnToolbarMove)
            {
                Shape closestShape = (Shape)GetClosestCanvasChild(p);
                StepShape stepShape = GetShapeParent(closestShape);
                _movingShape = true;
                _stepShape = stepShape;
                _stepShape.Select();
                foreach (UIElement element in canvas1.Children)
                {
                    if (element.GetType() == typeof(Shape))
                    {
                        if (((Shape)element).Name.Contains("_stepShape"))
                        {
                            StepShape parent = GetShapeParent((Shape)element);
                            parent.Deselect();
                        }
                    }
                }
            }

            if (_stepShape == null || result.VisualHit != _stepShape.Shape)
            {
                //This probably shouldn't get here. I don't know where it should go yet
                if(_stepShape != null) _stepShape.Deselect();

                //If user has selected a shape tool.
                if (_activeTool != null && (_activeTool == btnToolbarCircle || _activeTool == btnToolbarDot || _activeTool == btnToolbarLine
                    || _activeTool == btnToolbarPolyline || _activeTool == btnToolbarRectangle || _activeTool == btnToolbarArc))
                {
                    _drawing = true;
                    RemoveCurrentShape();
                    if (_activeTool == btnToolbarCircle)
                    {
                        Ellipse ell = (Ellipse)StepEllipse.Draw(e.GetPosition(canvas1).X, e.GetPosition(canvas1).Y);
                        ell.Name += "_stepShape";
                        canvas1.Children.Add(ell);
                        _stepShape = new StepEllipse(ell);
                    }
                    else if (_activeTool == btnToolbarRectangle)
                    {
                        Rectangle rect = StepRectangle.Draw(e.GetPosition(canvas1).X, e.GetPosition(canvas1).Y);
                        rect.Name += "_stepShape";
                        canvas1.Children.Add(rect);
                        _stepShape = new StepRectangle(rect);
                    }
                    else if (_activeTool == btnToolbarLine)
                    {
                        Line line = StepLine.Draw(e.GetPosition(canvas1).X, e.GetPosition(canvas1).Y);
                        line.Name += "_stepShape";
                        canvas1.Children.Add(line);
                        _stepShape = new StepLine(line);
                    }
                    else if (_activeTool == btnToolbarArc)
                    {
                        _stepShape = new StepPath(e.GetPosition(canvas1).X, e.GetPosition(canvas1).Y);
                        _stepShape.Shape.Name += "_stepShape";
                        canvas1.Children.Add(_stepShape.Shape);
                        _makingPath = true;
                    }
                    else if (_activeTool == btnToolbarPolyline)
                    {
                        _stepShape = new StepFreeForm(e.GetPosition(canvas1).X, e.GetPosition(canvas1).Y);
                        _stepShape.Shape.Name += "_stepShape";
                        canvas1.Children.Add(_stepShape.Shape);
                    }
                    _last_mouse_location = e.GetPosition(canvas1);
                    //Create new list item for the step shape & add to list.
                    RoutineStep rs = new RoutineStep("New Step", _stepShape, _routine);
                    ((RoutineFixture)lbxTimeline.SelectedItem).RoutineSteps.Add(rs);
                    _lastSelectedStep = rs;
                    /*Horrible way to refresh the listbox.  Need to figure this out.
                     * Currently it removes the row that allows you to add more fixutres. Can't do that!
                     */
                    //lbxSteps.ItemsSource = null;
                    //lbxSteps.Items.Clear();
                    //lbxSteps.ItemsSource = ((RoutineFixture)lbxTimeline.SelectedItem).RoutineSteps;
                }
                //Not drawing something, making a reference point?
                else if(_activeTool == btnToolbarReferencePoint)
                {
                    _movingReferencePoint = true;
                    _refPoint = new RoutineFixtureReferencePoint((RoutineFixture)lbxTimeline.SelectedItem, e.GetPosition(canvas1));
                    canvas1.Children.Add(_refPoint.Ellipse);
                    canvas1.Children.Add(_refPoint.Label);
                    _refPoint.MoveFixtureTo();
                    ((RoutineFixture)lbxTimeline.SelectedItem).Fixture.On();
                }
                //Not a referencePoint, is it an Attribute Point?
                else if (_activeTool == btnToolbarAttrPoint)
                {
                    _movingAttributePoint = true;

                    Shape closestShape = (Shape)GetClosestCanvasChild(p);
                    Point closestPoint = GetClosestPointOnShape(closestShape, p);

                    _attrPoint = new AttributePoint(closestPoint, ((RoutineFixture)lbxTimeline.SelectedItem).Fixture);
                    canvas1.Children.Add(_attrPoint.Ellipse);
                    Canvas.SetLeft(_attrPoint.Ellipse, closestPoint.X -450);
                    Canvas.SetTop(_attrPoint.Ellipse, closestPoint.Y -450);
                    _lastSelectedStep.AddAttributePoint(_attrPoint);

                    //Live Preview
                    if (LivePreview)
                    {
                        ((RoutineFixture)lbxTimeline.SelectedItem).Fixture.MoveTo(closestPoint, 0);
                    }
                }
            }
        }