예제 #1
0
        private void SetupEquationControlEvents(EquationRowControl control)
        {
            // Set the deletion callback function
            control.SetDeleteRequestDelegate(this.DeleteEquationRow);

            // TODO: Perhaps fix at a later date (the commented-out line)
            //control.Model.RelatedElements = PfdElements;
            control.Model.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(EquationModelPropertyChanged);

            // Link up events for move up/move down buttons
            control.MoveDownButton.Click += new RoutedEventHandler(MoveDownButton_Click);
            control.MoveUpButton.Click   += new RoutedEventHandler(MoveUpButton_Click);

            // Set comment button border
            control.CommentIconBorder.BorderBrush          = new SolidColorBrush(Colors.Gray);
            control.CommentIconBorder.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
            {
                // Toggle the comment visibility. All relevant UI elements that need to know about this
                // will have attached event listeners and will update themselves appropriately
                control.Model.CommentsVisible = !control.Model.CommentsVisible;

                UpdateRowProperties();

                // If we have any rows with visible comments then ensure the comments pane is visible
                if (CountRowsWithCommentsVisible() > 0)
                {
                    Core.App.Workspace.CommentsPaneVisible = true;
                }
            };
        }
예제 #2
0
        public void UpdateRowProperties()
        {
            int count = EquationRowCount;

            for (int i = 0; i < count; i++)
            {
                EquationRowControl ec = GetRow(i);

                // Row number label
                Brush clrBrush = new SolidColorBrush(Color.FromArgb(255, 42, 176, 240));
                ec.NumberLabel.Content    = (i + 1).ToString() + ".";
                ec.NumberLabel.Foreground = clrBrush;

                // The "button" to show or hide comments for an equation can be in one of 4 states:
                // 1. There are comments for the equation and CommentsVisible is false
                // 2. There are comments for the equation and CommentsVisible is true
                // 3. There are no comments for the equation and CommentsVisible is false
                // 4. There are no comments for the equation and CommentsVisible is true

                // If the comments are visible, then we have a colored border and background
                if (ec.Model.CommentsVisible)
                {
                    ec.CommentIconBorder.BorderBrush = ec.CommentIconBorder.Background = clrBrush;
                    ToolTipService.SetToolTip(ec.CommentIconBorder,
                                              "Click to hide comments for this equation in the side pane");
                }
                else
                {
                    // Otherwise, if the comments are hidden, then we want some sort of visual cue to indicate whether
                    // or not there are any comments for that equation. We will do this by setting the border brush to gray
                    // if there are no comments and setting it to colored otherwise. The background will be gray in either
                    // case.
                    ec.CommentIconBorder.BorderBrush = (ec.Model.Comments.Count > 0) ?
                                                       clrBrush : s_grayBrush;
                    ec.CommentIconBorder.Background = s_lightGrayBrush;

                    // Also set a tooltip
                    if (ec.Model.Comments.Count > 0)
                    {
                        ToolTipService.SetToolTip(ec.CommentIconBorder,
                                                  "There are comments for this equation, click to show them");
                    }
                    else
                    {
                        ToolTipService.SetToolTip(ec.CommentIconBorder,
                                                  "There are no comments for this equation, click to show the comment editor");
                    }
                }

                // Up/down buttons
                ec.MoveUpButton.IsEnabled   = (i != 0);
                ec.MoveDownButton.IsEnabled = (i < count - 1);

                // Ensure that the font size is correct
                ec.EquationTextBox.FontSize = m_workspace.EquationEditorFontSize;
            }
        }
예제 #3
0
        /// <summary>
        /// Updates the list of scopes that an equation can reference
        /// </summary>
        private void updateScopes()
        {
            // Can't do anything without a workspace
            if (null == m_workspace)
            {
                return;
            }

            EquationScopes = new ObservableCollection <EquationScope>();

            //add "overall" scope
            EquationScopes.Add(new EquationScope(EquationScopeClassification.Overall, Name = "Overall"));

            //add "Unknown" scope
            EquationScopes.Add(new EquationScope(EquationScopeClassification.Unknown, Name = "Unknown"));

            // Add any process units and subprocesses to the list of possible scopes
            foreach (AbstractProcessUnit apu in m_workspace.ProcessUnits)
            {
                EquationScopes.Add(new EquationScope(EquationScopeClassification.SingleUnit, Name = apu.Label));

                // If there's a non-default subprocess for this process unit, then add it
                if (!apu.Subprocess.ToLower().Equals("#ffffffff"))
                {
                    // Find the name of this color
                    string name = null;
                    foreach (Core.NamedColor nc in Core.NamedColors.All)
                    {
                        if (nc.Color.ToString().Equals(apu.Subprocess))
                        {
                            name = nc.Name + " subprocess";
                            break;
                        }
                    }

                    if (!string.IsNullOrEmpty(name))
                    {
                        EquationScopes.Add(new EquationScope(EquationScopeClassification.SubProcess, name));
                    }
                }
            }

            //add streams as well
            foreach (AbstractStream stream in m_workspace.Streams)
            {
                EquationScopes.Add(new EquationScope(EquationScopeClassification.Unknown, string.Format("Stream #{0}", stream.Id)));
            }

            // Update all of the equation controls
            for (int i = 0; i < EquationRowCount; i++)
            {
                EquationRowControl ec = GetRow(i);
                ec.SetScopeOptions(EquationScopes);
                UpdateEquationModelElements(ec.Model);
            }
        }
예제 #4
0
        /// <summary>
        /// Updates the UI and the set of equation controls based on data from the workspace object
        /// </summary>
        private void UpdateFromWorkspace()
        {
            // Tests show that creating the equation row controls is somewhat slow, so here we want
            // to minimize the number of controls we create. Thus instead of clearing out all
            // controls and creating new ones, which would certainly work, we'll take a more efficient
            // approach. We start by creating the exact number of row controls that are needed. This
            // may require deleting or adding rows.

            // If there are too many equation row controls, then we have to delete
            while (EquationsStackPanel.Children.Count > m_workspace.Equations.Count)
            {
                // Remove the last one
                EquationRowControl ec =
                    EquationsStackPanel.Children[EquationsStackPanel.Children.Count - 1] as EquationRowControl;
                ec.SetModel(null);
                EquationsStackPanel.Children.Remove(ec);
            }

            // If there are too few equation row controls then add additional ones
            while (EquationsStackPanel.Children.Count < m_workspace.Equations.Count)
            {
                EquationRowControl ec = new EquationRowControl(m_workspace,
                                                               this, m_workspace.Equations[EquationsStackPanel.Children.Count]);
                SetupEquationControlEvents(ec);
                EquationsStackPanel.Children.Add(ec);
            }

            // Now we have the correct number of controls to match the number of equations in the workspace. Go
            // through each one and set the data.
            for (int i = 0; i < m_workspace.Equations.Count; i++)
            {
                // If the control doesn't already have the correct model then update it
                if (!object.ReferenceEquals(m_workspace.Equations[i],
                                            (EquationsStackPanel.Children[i] as EquationRowControl).Model))
                {
                    (EquationsStackPanel.Children[i] as EquationRowControl).SetModel(m_workspace.Equations[i]);
                }
            }

            // Fix the move up/move down buttons on all rows
            UpdateRowProperties();
        }
예제 #5
0
        private void MoveUpButton_Click(object sender, RoutedEventArgs e)
        {
            EquationRowControl row = null;

            // Start by finding the row index in the stack panel
            int indexOfThis = -1;

            for (int i = 0; i < EquationsStackPanel.Children.Count; i++)
            {
                // Will throw an exception if it the object is not an EquationControl, but that's
                // what we want since the design contract is that all objects in the stack panel
                // must be EquationControl objects.
                EquationRowControl ec = (EquationRowControl)EquationsStackPanel.Children[i];

                if (object.ReferenceEquals(sender, ec.MoveUpButton))
                {
                    indexOfThis = i;
                    row         = ec;
                    break;
                }
            }


            // If it's the first row then disable the button to move up and return
            if (0 == indexOfThis)
            {
                row.MoveUpButton.IsEnabled = false;
                return;
            }

            // Move the row up by removing it and then inserting it at a lower index. Event
            // handlers are subscribed to changes in the equation collection, so the UI will
            // be updated automatically.
            EquationModel toMoveUp = m_workspace.Equations[indexOfThis];

            m_workspace.Equations.Remove(toMoveUp);
            m_workspace.Equations.Insert(indexOfThis - 1, toMoveUp);

            // Add an undo that will move it back down
            m_workspace.AddUndo(new UndoRedoCollection("Undo moving equation up",
                                                       new Logic.Undos.MoveEquationDown(indexOfThis - 1)));
        }
예제 #6
0
        /// <summary>
        /// This is called from an equation control when it wants to delete itself. We must remove
        /// it from the stack panel.
        /// </summary>
        private void DeleteEquationRow(EquationRowControl thisOne)
        {
            int index = m_workspace.Equations.IndexOf(thisOne.Model);

#if DEBUG
            if (index < 0)
            {
                throw new ArgumentException(
                          "Request was made to delete an equation that was not found in the collection");
            }
#endif

            // Create an undo that will add it back
            m_workspace.AddUndo(new UndoRedoCollection(
                                    "Undo deleting equation row",
                                    new InsertEquation(m_workspace, thisOne.Model, index)));

            // Remove it from the workspace. There are event listeners that will update the UI
            // when doing this
            m_workspace.Equations.Remove(thisOne.Model);

            // Fix row numbers and buttons
            UpdateRowProperties();
        }