source: trunk/CrypPlugins/WorkspaceManager/View/Container/WorkSpaceEditorView.xaml.cs @ 1570

Last change on this file since 1570 was 1570, checked in by kopal, 11 years ago
  • renamed "ConntectorView" to "ConnectorView"
  • bug fix - newConnectionModel now puts the new ConnectionModel into the internal list
  • PluginModels are now executable if
    • all Mandatory Inputs are set + all Outputs are "free"
    • there are no Mandatory Inputs but at least one input is set + all Outputs are "free"
    • there are no Inputs + all Outputs are "free"
  • some small fixes
File size: 8.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows;
6using System.Windows.Controls;
7using System.Windows.Data;
8using System.Windows.Documents;
9using System.Windows.Input;
10using System.Windows.Media;
11using System.Windows.Media.Imaging;
12using System.Windows.Navigation;
13using System.Windows.Shapes;
14using WorkspaceManager.View.Converter;
15using WorkspaceManager.View.Interface;
16using WorkspaceManager.View.VisualComponents;
17using WorkspaceManager.Model;
18using Cryptool.PluginBase.Editor;
19using Cryptool.Core;
20using Cryptool.PluginBase;
21
22namespace WorkspaceManager.View.Container
23{
24    /// <summary>
25    /// Interaction logic for WorkSpaceEditorView.xaml
26    /// </summary>
27    public partial class WorkSpaceEditorView : UserControl
28    {
29        public enum EditorState
30        {
31            READY,
32            BUSY
33        };
34
35        private Point previousDragPoint = new Point();
36        private ConnectorView selectedConnector;
37        private PluginContainerView selectedPluginContainer;
38        private CryptoLineView dummyLine = new CryptoLineView();
39        private Point p;
40
41        public EditorState State;
42        public EditorState ConnectorState;
43        public List<CryptoLineView> LineList = new List<CryptoLineView>();
44        public List<PluginContainerView> PluginContainerList = new List<PluginContainerView>();
45        private WorkspaceModel WorkspaceModel;
46
47        public WorkSpaceEditorView()
48        {
49            InitializeComponent();
50        }
51
52        public WorkSpaceEditorView(WorkspaceModel WorkspaceModel)
53        {
54            this.Loaded += new RoutedEventHandler(WorkSpaceEditorView_Loaded);
55            this.DragEnter += new DragEventHandler(WorkSpaceEditorView_DragEnter);
56            this.Drop += new DragEventHandler(WorkSpaceEditorView_Drop);
57            this.MouseMove += new MouseEventHandler(WorkSpaceEditorView_MouseMove);
58            this.PreviewMouseRightButtonDown += new MouseButtonEventHandler(WorkSpaceEditorView_PreviewMouseRightButtonDown);
59            this.WorkspaceModel = WorkspaceModel;
60            this.State = EditorState.READY;
61            InitializeComponent();
62        }
63
64        void WorkSpaceEditorView_Loaded(object sender, RoutedEventArgs e)
65        {
66
67        }
68
69        public void AddPluginContainerView(Point position, PluginModel model)
70        {
71            PluginContainerView shape = new PluginContainerView(model);
72            shape.MouseLeave += new MouseEventHandler(shape_MouseLeave);
73            shape.OnConnectorMouseLeftButtonDown += new EventHandler<ConnectorViewEventArgs>(shape_OnConnectorMouseLeftButtonDown);
74            shape.MouseLeftButtonDown += new MouseButtonEventHandler(shape_MouseLeftButtonDown);
75            shape.MouseLeftButtonUp += new MouseButtonEventHandler(shape_MouseLeftButtonUp);
76            shape.SetPosition(position);
77            this.root.Children.Add(shape);
78            Canvas.SetZIndex(shape, 100);
79        }
80
81        public void AddConnection(IConnectable source, IConnectable target)
82        {
83            ConnectionModel connectionModel = this.WorkspaceModel.newConnectionModel(((ConnectorView)source).cModel, ((ConnectorView)target).cModel, ((ConnectorView)source).cModel.ConnectorType);
84            CryptoLineView conn = new CryptoLineView(connectionModel);
85            conn.SetBinding(CryptoLineView.StartPointProperty, CreateConnectorBinding(source));
86            conn.SetBinding(CryptoLineView.EndPointProperty, CreateConnectorBinding(target));
87            root.Children.Add(conn);
88            Canvas.SetZIndex(conn, 0);           
89        }
90
91        private void AddConnectionSource(IConnectable source, CryptoLineView conn)
92        {
93            conn.SetBinding(CryptoLineView.StartPointProperty, CreateConnectorBinding(source));
94            conn.EndPoint = Mouse.GetPosition(this);
95        }
96
97        private MultiBinding CreateConnectorBinding(IConnectable connectable)
98        {
99            MultiBinding multiBinding = new MultiBinding();
100            multiBinding.Converter = new ConnectorBindingConverter();
101
102            Binding binding = new Binding();
103            binding.Source = connectable;
104            binding.Path = new PropertyPath(ConnectorView.PositionOnWorkSpaceXProperty);
105            multiBinding.Bindings.Add(binding);
106
107            binding = new Binding();
108            binding.Source = connectable;
109            binding.Path = new PropertyPath(ConnectorView.PositionOnWorkSpaceYProperty);
110            multiBinding.Bindings.Add(binding);
111
112            binding = new Binding();
113            binding.Source = connectable;
114            binding.Path = new PropertyPath(FrameworkElement.ActualHeightProperty);
115            multiBinding.Bindings.Add(binding);
116
117            binding = new Binding();
118            binding.Source = connectable;
119            binding.Path = new PropertyPath(FrameworkElement.ActualWidthProperty);
120            multiBinding.Bindings.Add(binding);
121
122            return multiBinding;
123        }
124
125        #region Controls
126
127        void shape_OnConnectorMouseLeftButtonDown(object sender, ConnectorViewEventArgs e)
128        {
129            if (selectedConnector != null)
130            {
131                this.root.Children.Remove(dummyLine);
132                this.AddConnection(selectedConnector, e.connector);
133                this.selectedConnector = null;
134                this.State = EditorState.READY;
135                return;
136            }
137
138            if (selectedConnector == null)
139            {
140                this.root.Children.Add(dummyLine);
141                this.selectedConnector = e.connector;
142                this.AddConnectionSource(e.connector, dummyLine);
143                this.State = EditorState.BUSY;
144                return;
145            }
146           
147        }
148
149        void WorkSpaceEditorView_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
150        {
151            this.selectedConnector = null;
152            this.root.Children.Remove(dummyLine);
153        }
154
155        void WorkSpaceEditorView_MouseMove(object sender, MouseEventArgs e)
156        {
157            if (e.LeftButton == MouseButtonState.Pressed && selectedPluginContainer != null)
158            {
159                p = selectedPluginContainer.GetPosition();
160                this.selectedPluginContainer.SetPosition(new Point(p.X + (Mouse.GetPosition(sender as WorkSpaceEditorView).X - previousDragPoint.X), p.Y + (Mouse.GetPosition(sender as WorkSpaceEditorView).Y - previousDragPoint.Y)));
161            }
162
163            if (selectedConnector != null && root.Children.Contains(dummyLine))
164            {
165                this.dummyLine.EndPoint = Mouse.GetPosition(sender as WorkSpaceEditorView);
166            }
167            this.previousDragPoint = Mouse.GetPosition(sender as WorkSpaceEditorView);
168        }
169
170        void shape_MouseLeave(object sender, MouseEventArgs e)
171        {
172            this.selectedPluginContainer = null;
173            this.State = EditorState.READY;
174        }
175
176        void shape_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
177        {
178            Canvas.SetZIndex(sender as PluginContainerView, 100);
179            this.selectedPluginContainer = null;
180            this.State = EditorState.BUSY;
181        }
182
183        void shape_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
184        {
185            Canvas.SetZIndex(sender as PluginContainerView, 101);
186            this.selectedPluginContainer = sender as PluginContainerView;
187            this.State = EditorState.BUSY;
188        }
189
190        void WorkSpaceEditorView_Drop(object sender, DragEventArgs e)
191        {
192            DragDropDataObject obj = e.Data.GetData("Cryptool.PluginBase.Editor.DragDropDataObject") as DragDropDataObject;
193            if(obj != null)
194                this.AddPluginContainerView(e.GetPosition(this), WorkspaceModel.newPluginModel(DragDropDataObjectToPluginConverter.CreatePluginInstance(obj.AssemblyFullName, obj.TypeFullName)));
195        }
196
197        void WorkSpaceEditorView_DragEnter(object sender, DragEventArgs e)
198        {
199            e.Effects = DragDropEffects.Copy;
200        }
201
202        #endregion
203    }
204}
Note: See TracBrowser for help on using the repository browser.