Ejemplo n.º 1
0
 private void mnuEditResizeDocument(object sender, RoutedEventArgs e)
 {
     winDocumentSize docSizeWindow = new winDocumentSize();
     docSizeWindow.Owner = this;
     docSizeWindow.DocumentWidth = circuitDisplay.Document.Size.Width;
     docSizeWindow.DocumentHeight = circuitDisplay.Document.Size.Height;
     if (docSizeWindow.ShowDialog() == true)
     {
         Size newSize = new Size(docSizeWindow.DocumentWidth, docSizeWindow.DocumentHeight);
         if (newSize != circuitDisplay.Document.Size)
         {
             UndoAction resizeAction = new UndoAction(UndoCommand.ResizeDocument, "Resize document");
             resizeAction.AddData("before", circuitDisplay.Document.Size);
             circuitDisplay.Document.Size = newSize;
             circuitDisplay.DocumentSizeChanged();
             resizeAction.AddData("after", newSize);
             UndoManager.AddAction(resizeAction);
         }
     }
 }
Ejemplo n.º 2
0
        private void mnuFileDocument_Click(object sender, RoutedEventArgs e)
        {
            string previousTitle = circuitDisplay.Document.Metadata.Title;
            string previousDescription = circuitDisplay.Document.Metadata.Description;

            winDocumentProperties documentInfoWindow = new winDocumentProperties();
            documentInfoWindow.Owner = this;
            documentInfoWindow.SetDocument(circuitDisplay.Document);
            documentInfoWindow.ShowDialog();

            if (circuitDisplay.Document.Metadata.Title != previousTitle || circuitDisplay.Document.Metadata.Description != previousDescription)
            {
                UndoAction editMetadataAction = new UndoAction(UndoCommand.ModifyMetadata, "Modify metadata");
                editMetadataAction.AddData("before", new string[2] { previousTitle, previousDescription});
                editMetadataAction.AddData("after", new string[2] { circuitDisplay.Document.Metadata.Title, circuitDisplay.Document.Metadata.Description });
                UndoManager.AddAction(editMetadataAction);
            }
        }
Ejemplo n.º 3
0
        void Editor_ComponentUpdated(object sender, ComponentUpdatedEventArgs e)
        {
            UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "edit", new Component[] { e.Component });
            Dictionary<Component, string> previousData = new Dictionary<Component, string>(1);
            previousData.Add(e.Component, e.PreviousData);
            undoAction.AddData("before", previousData);
            Dictionary<Component, string> newData = new Dictionary<Component, string>(1);
            newData.Add(e.Component, e.Component.SerializeToString());
            undoAction.AddData("after", newData);
            UndoManager.AddAction(undoAction);

            // Update connections
            e.Component.ResetConnections();
            e.Component.ApplyConnections(circuitDisplay.Document);
            circuitDisplay.DrawConnections();
        }
Ejemplo n.º 4
0
        protected override void OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e)
        {
            base.OnMouseUp(e);

            m_movingMouse = false;
            if (m_resizing != ComponentResizeMode.None)
            {
                m_resizingComponent.ResetConnections();
                m_resizingComponent.ApplyConnections(Document);
                DrawConnections();

                UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "Move component", new Component[] { m_resizingComponent });
                undoAction.AddData("before", m_undoManagerBeforeData);
                Dictionary<Component, string> afterDictionary = new Dictionary<Component, string>(1);
                afterDictionary.Add(m_resizingComponent, m_resizingComponent.SerializeToString());
                undoAction.AddData("after", afterDictionary);
                UndoManager.AddAction(undoAction);
                m_undoManagerBeforeData = new Dictionary<Component, string>();
            }
            m_resizing = ComponentResizeMode.None;
            this.Cursor = System.Windows.Input.Cursors.Arrow;
            m_resizingComponent = null;

            if (m_placingComponent)
            {
                Component newComponent = Component.Create(NewComponentData);
                ComponentHelper.SizeComponent(newComponent, m_mouseDownPos, e.GetPosition(this));

                // Flip if necessary
                if (newComponent.Orientation == Orientation.Horizontal && newComponent.Description.CanFlip)
                {
                    if (m_mouseDownPos.X > e.GetPosition(this).X)
                        newComponent.IsFlipped = true;
                    else
                        newComponent.IsFlipped = false;
                }
                else if (newComponent.Description.CanFlip)
                {
                    if (m_mouseDownPos.Y > e.GetPosition(this).Y)
                        newComponent.IsFlipped = true;
                    else
                        newComponent.IsFlipped = false;
                }

                Document.Elements.Add(newComponent);
                newComponent.ApplyConnections(Document);
                DrawConnections();
                m_placingComponent = false;

                UndoAction undoAction = new UndoAction(UndoCommand.AddComponents, "Add component", new Component[] { newComponent });
                UndoManager.AddAction(undoAction);

                RemoveVisualChild(m_elementVisuals[m_tempComponent]);
                RemoveLogicalChild(m_elementVisuals[m_tempComponent]);
                m_elementVisuals.Remove(m_tempComponent);
                m_tempComponent = null;
            }
            else if (m_selectedComponents.Count > 0)
            {
                Dictionary<Component, string> afterData = new Dictionary<Component, string>();

                foreach (Component component in m_selectedComponents)
                {
                    string afterDataString = component.SerializeToString();
                    if (afterDataString == m_undoManagerBeforeData[component])
                        break;

                    afterData.Add(component, afterDataString);
                }

                if (afterData.Count > 0)
                {
                    UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "move", m_selectedComponents.ToArray());
                    undoAction.AddData("before", m_undoManagerBeforeData);
                    undoAction.AddData("after", afterData);
                    UndoManager.AddAction(undoAction);
                    m_undoManagerBeforeData = new Dictionary<Component, string>();
                }
            }
            else if (m_selectionBox)
            {
                using (DrawingContext dc = m_selectedVisual.RenderOpen())
                {
                    enclosingRect = Rect.Empty;

                    VisualTreeHelper.HitTest(this, new HitTestFilterCallback(delegate(DependencyObject testObject)
                    {
                        if (testObject is CircuitElementDrawingVisual)
                            return HitTestFilterBehavior.ContinueSkipChildren;
                        else
                            return HitTestFilterBehavior.ContinueSkipSelf;
                    }),
                    new HitTestResultCallback(delegate(HitTestResult result)
                    {
                        m_selectedComponents.Add((result.VisualHit as CircuitElementDrawingVisual).CircuitElement as Component);

                        if (result.VisualHit is CircuitElementDrawingVisual)
                        {
                            Rect rect = VisualTreeHelper.GetContentBounds(result.VisualHit as Visual);
                            dc.PushTransform(new TranslateTransform((result.VisualHit as CircuitElementDrawingVisual).Offset.X, (result.VisualHit as CircuitElementDrawingVisual).Offset.Y));
                            dc.DrawRectangle(new SolidColorBrush(Color.FromArgb(100, 0, 0, 100)), null, rect);
                            dc.Pop();

                            if (enclosingRect.IsEmpty)
                            {
                                rect.Offset((result.VisualHit as CircuitElementDrawingVisual).Offset.X, (result.VisualHit as CircuitElementDrawingVisual).Offset.Y);
                                enclosingRect = rect;
                            }
                            else
                            {
                                rect.Offset((result.VisualHit as CircuitElementDrawingVisual).Offset.X, (result.VisualHit as CircuitElementDrawingVisual).Offset.Y);
                                enclosingRect.Union(rect);
                            }
                        }

                        return HitTestResultBehavior.Continue;
                    }), new GeometryHitTestParameters(new RectangleGeometry(new Rect(m_mouseDownPos, e.GetPosition(this)))));

                    dc.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Black, 1d), enclosingRect);
                }

                m_selectionBox = false;
            }
        }
Ejemplo n.º 5
0
        protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
        {
            base.OnMouseLeave(e);

            if (m_resizing != ComponentResizeMode.None)
            {
                m_resizingComponent.ResetConnections();
                m_resizingComponent.ApplyConnections(Document);
                DrawConnections();

                UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "Move component", new Component[] { m_resizingComponent });
                undoAction.AddData("before", m_undoManagerBeforeData);
                Dictionary<Component, string> afterDictionary = new Dictionary<Component, string>(1);
                afterDictionary.Add(m_resizingComponent, m_resizingComponent.SerializeToString());
                undoAction.AddData("after", afterDictionary);
                UndoManager.AddAction(undoAction);
                m_undoManagerBeforeData = new Dictionary<Component, string>();

                m_resizing = ComponentResizeMode.None;
                this.Cursor = System.Windows.Input.Cursors.Arrow;
            }

            m_selectionBox = false;
            m_placingComponent = false;
        }
Ejemplo n.º 6
0
        public void RotateComponentCommand_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            if (m_selectedComponents.Count == 1)
            {
                m_selectedComponents[0].Orientation = m_selectedComponents[0].Orientation.Reverse();
                m_selectedComponents[0].ResetConnections();
                RedrawComponent(m_selectedComponents[0]);
                foreach (Component component in Document.Components)
                    component.DisconnectConnections();
                foreach (Component component in Document.Components)
                    component.ApplyConnections(Document);
                DrawConnections();

                UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "Rotate component", new Component[] { m_selectedComponents[0] });
                undoAction.AddData("before", m_undoManagerBeforeData);
                Dictionary<Component, string> afterDictionary = new Dictionary<Component, string>(1);
                afterDictionary.Add(m_selectedComponents[0], m_selectedComponents[0].SerializeToString());
                undoAction.AddData("after", afterDictionary);
                UndoManager.AddAction(undoAction);
                m_undoManagerBeforeData = new Dictionary<Component, string>();
            }
            else if (m_resizingComponent != null)
            {
                Dictionary<Component, string> beforeData = new Dictionary<Component, string>();
                beforeData.Add(m_resizingComponent, m_resizingComponent.SerializeToString());

                m_resizingComponent.Orientation = m_resizingComponent.Orientation.Reverse();
                m_resizingComponent.ResetConnections();
                RedrawComponent(m_resizingComponent);
                foreach (Component component in Document.Components)
                    component.DisconnectConnections();
                foreach (Component component in Document.Components)
                    component.ApplyConnections(Document);
                DrawConnections();

                UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "Rotate component", new Component[] { m_resizingComponent });
                undoAction.AddData("before", beforeData);
                Dictionary<Component, string> afterDictionary = new Dictionary<Component, string>(1);
                afterDictionary.Add(m_resizingComponent, m_resizingComponent.SerializeToString());
                undoAction.AddData("after", afterDictionary);
                UndoManager.AddAction(undoAction);
                m_undoManagerBeforeData = new Dictionary<Component, string>();
            }
        }
Ejemplo n.º 7
0
        public void FlipComponentCommand(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            if (m_selectedComponents.Count == 1 && m_selectedComponents[0].Description.CanFlip)
            {
                m_selectedComponents[0].IsFlipped = !m_selectedComponents[0].IsFlipped;
                m_elementVisuals[m_selectedComponents[0]].UpdateVisual();
                m_selectedComponents[0].ResetConnections();
                m_selectedComponents[0].ApplyConnections(Document);

                UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "Flip component", new Component[] { m_selectedComponents[0] });
                undoAction.AddData("before", m_undoManagerBeforeData);
                Dictionary<Component, string> afterDictionary = new Dictionary<Component, string>(1);
                afterDictionary.Add(m_selectedComponents[0], m_selectedComponents[0].SerializeToString());
                undoAction.AddData("after", afterDictionary);
                UndoManager.AddAction(undoAction);
                m_undoManagerBeforeData = new Dictionary<Component, string>();
            }
            else if (m_resizingComponent != null && m_resizingComponent.Description.CanFlip)
            {
                Dictionary<Component, string> beforeData = new Dictionary<Component, string>();
                beforeData.Add(m_resizingComponent, m_resizingComponent.SerializeToString());

                m_resizingComponent.IsFlipped = !m_resizingComponent.IsFlipped;
                m_elementVisuals[m_resizingComponent].UpdateVisual();
                m_resizingComponent.ResetConnections();
                m_resizingComponent.ApplyConnections(Document);

                UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "Flip component", new Component[] { m_resizingComponent });
                undoAction.AddData("before", beforeData);
                Dictionary<Component, string> afterDictionary = new Dictionary<Component, string>(1);
                afterDictionary.Add(m_resizingComponent, m_resizingComponent.SerializeToString());
                undoAction.AddData("after", afterDictionary);
                UndoManager.AddAction(undoAction);
                m_undoManagerBeforeData = new Dictionary<Component, string>();
            }
        }