Esempio n. 1
0
        public PlacingNewProcessUnit(ControlPalette sender, DrawingCanvas canvas,
                                     Type processUnitType)
        {
            m_canvas    = canvas;
            m_palette   = sender;
            m_type      = processUnitType;
            m_workspace = canvas.GetWorkspace();

            SolidColorBrush whiteBrush = new SolidColorBrush(Colors.White);

            // Create the placement icon. This will hover under the mouse pointer
            // as it moves and a mouse-down event will complete the placement.
            BitmapImage bmp = new BitmapImage();

            bmp.UriSource = new Uri(ProcessUnitControl.GetIconSource(processUnitType), UriKind.Relative);
            Image img = new Image()
            {
                Source = bmp,
                Width  = 44.0,
                Height = 44.0
            };

            m_placementIcon                 = new Border();
            m_placementIcon.Background      = whiteBrush;
            m_placementIcon.Child           = img;
            m_placementIcon.BorderThickness = new Thickness(0.0);

            // Add it to the canvas but don't show it until we get our first mouse-move event
            canvas.AddNewChild(m_placementIcon);
            m_placementIcon.Visibility = Visibility.Collapsed;

            // Deselect
            canvas.SelectedElement = null;
        }
Esempio n. 2
0
        public static StreamControl CreateOnCanvas(DrawingCanvas canvas, AbstractStream stream)
        {
            StreamControl streamControl = new StreamControl(canvas, stream);

            canvas.AddNewChild(streamControl);
            return(streamControl);
        }
Esempio n. 3
0
        public PlacingNewCommentNote(DrawingCanvas canvas, ControlPalette creator)
        {
            // Store the reference to the drawing canvas. This is where we will place the new
            // sticky note.
            m_canvas = canvas;

            // Store a reference to the control palette
            m_creator = creator;

            // Create the placement icon and add it to the canvas. This will move around under the mouse
            // until the user clicks in order to create it.
            m_placementIcon       = Core.App.CreateImageFromSource("palette_stickyNote_16x16.png");
            m_placementIcon.Width = m_placementIcon.Height = 16;
            m_canvas.AddNewChild(m_placementIcon);
        }
Esempio n. 4
0
        public PlacingNewStream(UI.ControlPalette sender, DrawingCanvas canvas, StreamType streamType)
        {
            // Quick error check on parameters
            if (null == sender || null == canvas)
            {
                throw new ArgumentNullException();
            }
            if (StreamType.Chemical != streamType && StreamType.Heat != streamType)
            {
                // To save us from problems with future changes
                throw new NotImplementedException();
            }

            m_palette = sender;
            m_canvas  = canvas;

            // Create the stream (data structure, not control). Take care to pick an ID that's not
            // already in use.
            int newID;

            do
            {
                newID = AbstractStream.GetNextUID();
            }while (canvas.GetWorkspace().StreamExists(newID));
            if (StreamType.Chemical == streamType)
            {
                m_stream = new ChemicalStream(newID);
            }
            else
            {
                m_stream = new HeatStream(newID);
            }

            // Create the table
            m_stream.PropertiesTable = new StreamPropertiesTable(m_stream);

            // Create the default row if we have a heat stream. There is no default row
            // for chemical streams
            if (StreamType.Heat == streamType)
            {
                // Add a default row if it's not already there
                if (0 == m_stream.PropertiesTable.RowCount)
                {
                    m_stream.PropertiesTable.AddNewRow();
                }

                // Choose a default label
                m_stream.PropertiesTable.Rows[0].Label = "Q" + m_stream.Id.ToString();

                // Select default units
                (m_stream.PropertiesTable.Rows[0] as HeatStreamData).SelectedUnits =
                    HeatStreamData.EnergyUnitOptions[0];

                // Flag it as not renamed by the user yet
                m_stream.PropertiesTable.Rows[0].UserHasRenamed = false;
            }

            // Create the source placement icon and add it to the canvas
            m_sourcePlacementIcon = new Image();
            Uri         uri = new Uri("/UI/Icons/pu_source.png", UriKind.Relative);
            ImageSource img = new System.Windows.Media.Imaging.BitmapImage(uri);

            m_sourcePlacementIcon.SetValue(Image.SourceProperty, img);
            m_canvas.AddNewChild(m_sourcePlacementIcon);
            m_sourcePlacementIcon.SetValue(Canvas.ZIndexProperty, 4);
        }
Esempio n. 5
0
        private StreamControl(DrawingCanvas canvas, AbstractStream stream)
        {
            m_canvas = canvas;
            m_stream = stream;

            InitializeComponent();

            if (null != canvas && null != stream)
            {
                // Create the brush for the stream line
                if (stream is HeatStream)
                {
                    m_streamLineNotSelected = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    m_streamLineNotSelected = new SolidColorBrush(Colors.Black);
                }

                // Create the drag handle for the source
                m_sourceDragIcon = new DraggableStreamEndpoint(
                    DraggableStreamEndpoint.EndpointType.StreamSource,
                    this, canvas);
                m_sourceDragIcon.Width    = m_sourceDragIcon.Height = 20.0;
                m_sourceDragIcon.Location = new Point(m_stream.SourceLocation.X, m_stream.SourceLocation.Y);
                // Add it to the canvas
                m_canvas.AddNewChild(m_sourceDragIcon);
                // Set the Z-index
                m_sourceDragIcon.SetValue(Canvas.ZIndexProperty, 2);
                // Setup mouse events
                m_sourceDragIcon.MouseLeftButtonDown += new MouseButtonEventHandler(DragIcon_MouseLeftButtonDown);

                // Create the drag handle for the destination
                m_dstDragIcon = new DraggableStreamEndpoint(
                    DraggableStreamEndpoint.EndpointType.StreamDestination,
                    this, canvas);
                // Add it to the canvas
                m_canvas.AddNewChild(m_dstDragIcon);
                // Set the Z-index
                m_dstDragIcon.SetValue(Canvas.ZIndexProperty, 2);
                // Show it if there's no destination, hide it otherwise
                m_dstDragIcon.Visibility = (null == m_stream.Destination) ?
                                           Visibility.Visible : System.Windows.Visibility.Collapsed;
                // Setup mouse events
                m_dstDragIcon.MouseLeftButtonDown += new MouseButtonEventHandler(DragIcon_MouseLeftButtonDown);

                // Create the arrow polygon control
                m_arrow = new Polygon();
                // Set the fill
                m_arrow.Fill = m_streamLineNotSelected;
                // Add it to the canvas
                m_canvas.AddNewChild(m_arrow);
                // Set the Z-index
                m_arrow.SetValue(Canvas.ZIndexProperty, 2);
                // Add 3 points/vertices
                m_arrow.Points.Add(new Point());
                m_arrow.Points.Add(new Point());
                m_arrow.Points.Add(new Point());
                // Hide it if there's no destination
                if (null == m_stream.Destination)
                {
                    m_arrow.Visibility = Visibility.Collapsed;
                }
                // Setup mouse events
                if (!(m_stream.Destination is HeatExchangerWithUtility))
                {
                    m_arrow.MouseLeftButtonDown += new MouseButtonEventHandler(DestinationArrow_MouseLeftButtonDown);
                }

                UpdateStreamLocation();

                // Create the table
                CreatePropertiesTable(m_stream.PropertiesTable);

                // Watch for when the table location changes
                m_stream.PropertiesTable.PropertyChanged += new PropertyChangedEventHandler(PropertiesTable_PropertyChanged);

                // Add it to the canvas and set it up
                m_canvas.AddNewChild(m_table as UIElement);

                UserControl tableAsUiElement = m_table as UserControl;

                //This sets the tables index to the greatest so it will be above everything
                tableAsUiElement.SetValue(System.Windows.Controls.Canvas.ZIndexProperty, 3);

                tableAsUiElement.MouseLeftButtonDown += new MouseButtonEventHandler((canvas as DrawingCanvas).MouseLeftButtonDownHandler);
                tableAsUiElement.MouseLeftButtonUp   += new MouseButtonEventHandler((canvas as DrawingCanvas).MouseLeftButtonUpHandler);

                // Hook up event listeners to the stream if non-null. We need to monitor:
                //  1. Changes in the comment collection
                //  2. Changes to the source process units properties (position)
                //  3. Changes to the destination process units properties (position)
                //  4. Changes to the source or destination references

                // 1.
                // Setup the event listener for the comment collection. It is the responsibility of this
                // control to create and manage the sticky note controls for its comments
                m_stream.Comments.CollectionChanged += Comments_CollectionChanged;
                // Invoke the callback to create sticky notes for comments
                Comments_CollectionChanged(m_stream.Comments, null);

                // 2.
                if (null != stream.Source)
                {
                    m_sourceEventItem              = stream.Source;
                    stream.Source.PropertyChanged += this.SourceOrDest_PropertyChanged;
                }

                // 3.
                if (null != stream.Destination)
                {
                    m_destEventItem = stream.Destination;
                    stream.Destination.PropertyChanged += this.SourceOrDest_PropertyChanged;
                }

                // 4.
                stream.PropertyChanged += new PropertyChangedEventHandler(Stream_PropertyChanged);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Recomputes location of all relevant controls within the stream (endpoint icons,
        /// stream lines, etc.)
        /// </summary>
        public virtual void UpdateStreamLocation()
        {
            // Error check: we shouldn't be here if the control has been removed from the canvas
            if (m_hasBeenRemoved)
            {
                throw new InvalidOperationException(
                          "Stream control that was removed from the PFD is being notified to update its location.");
            }

            if (m_updatingLocation)
            {
                return;
            }
            m_updatingLocation = true;

            MathCore.Vector sPt          = m_stream.SourceLocation;
            MathCore.Vector dPt          = m_stream.DestinationLocation;
            MathCore.Vector lineMidpoint = (sPt + dPt) / 2.0;

            // Compute the line segments for our stream lines
            MathCore.Vector        mid, sIconPt;
            MathCore.LineSegment[] lines = ComputeLineSegments(out mid, out sIconPt);
            // Get the list of UI lines to the right size
            while (m_lines.Count > lines.Length)
            {
                int index = m_lines.Count - 1;
                m_canvas.RemoveChild(m_lines[index]);
                m_lines.RemoveAt(index);
            }
            while (m_lines.Count < lines.Length)
            {
                Line line = new Line();
                m_lines.Add(line);
                m_canvas.AddNewChild(line);

                // Make sure the line has a low z-index
                line.SetValue(Canvas.ZIndexProperty, -1);

                // Remember to set the line color
                Brush b = m_isSelected ? s_streamLineSelected : m_streamLineNotSelected;
                line.Fill   = b;
                line.Stroke = b;
            }
            // Set the positions
            for (int i = 0; i < lines.Length; i++)
            {
                SetLineLocation(m_lines[i], lines[i].A, lines[i].B);
            }

            // Now do the table line if necessary
            if (null != m_table && !m_tableMinimized)
            {
                TableLine.X1 = mid.X;
                TableLine.Y1 = mid.Y;
                TableLine.X2 = m_table.Location.X;
                TableLine.Y2 = m_table.Location.Y;
            }

            // Check if we're minimized then we need to position the mini table
            if (m_tableMinimized)
            {
                m_miniTable.SetValue(Canvas.LeftProperty, mid.X);
                m_miniTable.SetValue(Canvas.TopProperty, mid.Y);
            }

            // Take care of the source drag icon
            if (null != m_stream.Source)
            {
                m_sourceDragIcon.Visibility = System.Windows.Visibility.Collapsed;
                // We need to show the square drag handle and position it
                if (null == m_square)
                {
                    m_square = new System.Windows.Shapes.Rectangle()
                    {
                        Fill   = m_streamLineNotSelected,
                        Width  = 10.0,
                        Height = 10.0
                    };
                    m_canvas.AddNewChild(m_square);
                    m_square.MouseLeftButtonDown += new MouseButtonEventHandler(SourceSquare_MouseLeftButtonDown);
                }
                m_square.Visibility = System.Windows.Visibility.Visible;
                m_square.SetValue(Canvas.LeftProperty, sIconPt.X - 5.0);
                m_square.SetValue(Canvas.TopProperty, sIconPt.Y - 5.0);
            }
            else
            {
                m_sourceDragIcon.Location = new Point(
                    m_stream.SourceLocation.X, m_stream.SourceLocation.Y);
                m_sourceDragIcon.Visibility = System.Windows.Visibility.Visible;
                if (null != m_square)
                {
                    m_square.Visibility = System.Windows.Visibility.Collapsed;
                }
            }

            // Take care of the destination drag icon as well
            if (null == m_stream.Destination)
            {
                m_dstDragIcon.Location   = new Point(dPt.X, dPt.Y);
                m_dstDragIcon.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                m_dstDragIcon.Visibility = System.Windows.Visibility.Collapsed;
            }

            // If we have a non-null destination, update the arrow
            if (null != m_stream.Destination)
            {
                // Where the last line segment intersects the destination process unit is where
                // the tip of the arrow is
                Point pt = new Point(
                    m_stream.Destination.Location.X - 20.0,
                    m_stream.Destination.Location.Y - 20.0);
                MathCore.Rectangle   destRect = MathCore.Rectangle.CreateFromCanvasRect(pt, 40.0, 40.0);
                MathCore.Vector[]    isects   = destRect.GetIntersections(lines[lines.Length - 1]);
                MathCore.LineSegment lastLine = lines[lines.Length - 1];

                if (0 == isects.Length)
                {
                    // No clue what to do here
                }

                double minDist = double.MaxValue;
                foreach (MathCore.Vector isectPt in isects)
                {
                    double tempDist = (isectPt - lastLine.A).Length;
                    if (tempDist < minDist)
                    {
                        minDist = tempDist;
                    }
                }

                MathCore.Vector dirNorm = MathCore.Vector.Normalize(lastLine.Direction);
                MathCore.Vector tip     = lastLine.A + dirNorm * minDist;
                MathCore.Vector perp1   = MathCore.Vector.Normalize(
                    MathCore.Vector.GetPerpendicular1(lastLine.Direction));
                MathCore.Vector perp2 = MathCore.Vector.Normalize(
                    MathCore.Vector.GetPerpendicular2(lastLine.Direction));
                MathCore.Vector[] pts = new MathCore.Vector[] {
                    tip,
                    tip - (dirNorm * 10.0) + (perp1 * 10.0),
                    tip - (dirNorm * 10.0) + (perp2 * 10.0)
                };

                // Set the vertices
                for (int i = 0; i < 3; i++)
                {
                    m_arrow.Points[i] = new Point(pts[i].X, pts[i].Y);
                }

                m_arrow.Visibility = System.Windows.Visibility.Visible;
            }

            // Lastly, tell the comment sticky notes to update
            foreach (StickyNoteControl sn in m_stickyNotes)
            {
                sn.UpdateLineToParent();
            }

            m_updatingLocation = false;
        }