예제 #1
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);
                    }
                }
            }
        }
예제 #2
0
        public List <AttributePoint> GetAttributePoints(List <Point> movementPoints, Fixture fixture)
        {
            // Make a new list of attribute points, one per movement point
            List <AttributePoint> attrPoints = new List <AttributePoint>();

            foreach (Point pt in movementPoints)
            {
                attrPoints.Add(new AttributePoint(new Point(pt.X, pt.Y), fixture));
            }

            // Assign each attribute point to its closest movement point
            foreach (AttributePoint attrPt in _attributePoints)
            {
                int closestMovementPointIndex = Utilities.GetClosestPointIndexInList(attrPt.Point, movementPoints);
                attrPoints[closestMovementPointIndex] = attrPt;
            }

            // If there isn't a key attribute point assigned to the first movement point, we don't
            // know what value each fixture attribute should start at. So, we ask each fixture
            // attribute what its current DMX value is
            foreach (AttributePointSetting setting in attrPoints[0].AttributePointSettings)
            {
                if (!setting.Active)
                {
                    // If the setting isn't active, get the fixture attribute's current value
                    setting.Value = setting.Attribute.GetLevel();
                }
            }

            // Now fill in the intermediate values for the movement points that
            // don't have a corresponding attribute point.
            // First, we keep track of the last key point for each attribute, currently 0
            Dictionary <string, int> lastKeyPointForAttribute = new Dictionary <string, int>();

            foreach (FixtureAttribute attr in fixture.Attributes)
            {
                lastKeyPointForAttribute[attr.Name] = 0;
            }
            // Next, step through the attribute points; whenever we hit a "key" point
            // (that is, a point that has an active setting), if we were supposed to
            // fade to that value, go back and fill in the intermediate values
            for (int i = 0; i < attrPoints.Count; i++)
            {
                AttributePoint attrPoint = attrPoints[i];

                foreach (AttributePointSetting setting in attrPoint.AttributePointSettings)
                {
                    if (setting.Active)
                    {
                        if (!setting.Snap)
                        {
                            // If we aren't supposed to snap to this value, that means
                            // we were supposed to have been fading to it. So we have
                            // to go back and fill in the intermediate values between
                            // this AttributePoint and this attribute's last key point.
                            int lastKeyPointIndex             = lastKeyPointForAttribute[setting.AttributeName];
                            int startVal                      = attrPoints[lastKeyPointIndex].GetSettingForAttributeName(setting.AttributeName).Value;
                            int endVal                        = setting.Value;
                            int incrementPerIntermediatePoint = (endVal - startVal) / (i - lastKeyPointIndex);

                            for (int j = lastKeyPointIndex + 1; j < i; j++)
                            {
                                AttributePointSetting intermediateSetting = attrPoints[j].GetSettingForAttributeName(setting.AttributeName);
                                intermediateSetting.Value  = startVal + incrementPerIntermediatePoint * (j - lastKeyPointIndex);
                                intermediateSetting.Active = true;
                            }
                        }

                        // Since the setting is active, this is this attribute's
                        // most recent "key" attributePoint
                        lastKeyPointForAttribute[setting.AttributeName] = i;
                    }
                    else
                    {
                        // Since this is not a "key" point for this attribute, copy
                        // in the value from the last key point. It might turn out that
                        // we're supposed to be fading to the next key point here, but
                        // if this turns out to be the case, we'll come back and
                        // correct this point when we get the next key point

                        AttributePoint lastKeyPoint = attrPoints[lastKeyPointForAttribute[setting.AttributeName]];
                        setting.Value = lastKeyPoint.GetSettingForAttributeName(setting.AttributeName).Value;
                    }
                }
            }

            return(attrPoints);
        }
        /*
         * 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);
                    }
                }
            }
        }
예제 #4
0
 // I made this method instead of making the list of attribute
 // points accessible through a Property because at some point
 // we might care about carefully maintaining the list in a
 // particular order, and we don't want to let other people change
 // that order.   --David
 public void AddAttributePoint(AttributePoint attrPoint)
 {
     _attributePoints.Add(attrPoint);
 }
예제 #5
0
 // I made this method instead of making the list of attribute
 // points accessible through a Property because at some point
 // we might care about carefully maintaining the list in a
 // particular order, and we don't want to let other people change
 // that order.   --David
 public void AddAttributePoint(AttributePoint attrPoint)
 {
     _attributePoints.Add(attrPoint);
 }