source: trunk/CrypPlugins/WorkspaceManager/Model/ConnectorModel.cs @ 1700

Last change on this file since 1700 was 1700, checked in by kopal, 12 years ago
  • WorkspaceManager now allows multiple Connections on InputConnectors
  • Created own Gears4Net Scheduler which implements flow control in WorkspaceManagers ExecutionEngine to support loops
  • some small bugfixes
File size: 7.4 KB
Line 
1/*                             
2   Copyright 2010 Nils Kopal, Viktor M.
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15*/
16
17using System;
18using System.Linq;
19using System.Text;
20using System.ComponentModel;
21using System.Threading;
22using Cryptool.PluginBase;
23using WorkspaceManager.View.Container;
24using System.Windows.Media;
25using System.Collections.Generic;
26
27namespace WorkspaceManager.Model
28{
29   
30    /// <summary>
31    /// Class to represent the Connection between two Connector Models
32    /// </summary>
33    [Serializable]
34    public class ConnectorModel : VisualElementModel
35    {       
36        [NonSerialized]
37        private bool hasData = false;
38       
39        /// <summary>
40        /// The PluginModel this Connector belongs to
41        /// </summary>
42        public PluginModel PluginModel { get; set; }
43
44        /// <summary>
45        /// The data type of this ConnectorModel
46        /// </summary>
47        public Type ConnectorType { get; set; }
48
49        /// <summary>
50        /// Is this Connector Outgoing?
51        /// </summary>
52        public bool Outgoing { get; set; }
53       
54        /// <summary>
55        /// The InputConnections of this ConnectorModel
56        /// </summary>
57        public List<ConnectionModel> InputConnections;
58
59        /// <summary>
60        /// The OutputConnections of this ConnectorModel
61        /// </summary>
62        public List<ConnectionModel> OutputConnections;
63
64        /// <summary>
65        /// Creates a new ConnectorModel
66        /// </summary>
67        public ConnectorModel()
68        {
69            this.InputConnections = new List<ConnectionModel>();
70            this.OutputConnections = new List<ConnectionModel>();           
71        }
72
73        /// <summary>
74        /// The WorkspaceModel of this PluginModel
75        /// </summary>
76        public WorkspaceModel WorkspaceModel { get; set; }
77
78        /// <summary>
79        /// Is this Connectors Data mandatory?
80        /// </summary>
81        /// <returns></returns>
82        public bool IsMandatory
83        {
84            get;
85            set;
86        }
87
88        /// <summary>
89        /// Is this a dynamic connector?
90        /// </summary>
91        public bool IsDynamic
92        {
93            get;
94            set;
95        }
96
97        /// <summary>
98        /// DynamicGetterName
99        /// </summary>
100        public string DynamicGetterName
101        {
102            get;
103            set;
104        }
105
106        /// <summary>
107        /// DynamicSetterName
108        /// </summary>
109        public string DynamicSetterName
110        {
111            get;
112            set;
113        }
114
115        /// <summary>
116        /// Does this Connector currently provides Data?
117        /// </summary>
118        /// <returns></returns>
119        public bool HasData
120        {
121            get { 
122                    return hasData; 
123            }
124
125            set 
126            {   
127                hasData = value; 
128            }
129        }
130
131        /// <summary>
132        /// Data of this Connector
133        /// </summary>
134        [NonSerialized]
135        public object Data = null;
136       
137        /// <summary>
138        /// Name of the represented Property of the IPlugin of this ConnectorModel
139        /// </summary>
140        public string PropertyName{get;set;}
141
142        /// <summary>
143        /// ToolTip of this Connector
144        /// </summary>
145        public string ToolTip { get; set; }
146
147        /// <summary>
148        /// Plugin informs the Connector that a PropertyChanged
149        /// </summary>
150        /// <param name="sender"></param>
151        /// <param name="propertyChangedEventArgs"></param>
152        public void PropertyChangedOnPlugin(Object sender, PropertyChangedEventArgs propertyChangedEventArgs)
153        {
154            if(sender == this.PluginModel.Plugin && 
155                propertyChangedEventArgs.PropertyName.Equals(PropertyName) && 
156                Outgoing){
157               
158                foreach (ConnectionModel connectionModel in this.OutputConnections)
159                {
160                    if (IsDynamic)
161                    {
162                        connectionModel.To.Data = sender.GetType().GetMethod(DynamicGetterName).Invoke(sender, new object[] { this.PropertyName });
163                    }
164                    else
165                    {
166                        connectionModel.To.Data = sender.GetType().GetProperty(propertyChangedEventArgs.PropertyName).GetValue(sender, null);
167                    }
168                    connectionModel.To.HasData = true;
169                    connectionModel.Active = true;
170                }
171
172               //We changed an input on the PluginModels where "To"s are belonging to so
173                //we have to check if there are executable now
174                foreach (ConnectionModel connectionModel in this.OutputConnections)
175                {
176                    connectionModel.To.PluginModel.checkExecutable(connectionModel.To.PluginModel.PluginProtocol);
177                }
178            }                       
179        }
180
181        /// <summary>
182        /// Orientation of this Connecor
183        /// </summary>
184        public ConnectorOrientation ConnectorOrientation { get; set; }
185
186        /// <summary>
187        ///
188        /// </summary>
189        public void PropertyTypeChangedOnPlugin(IPlugin plugin)
190        {
191            Dictionary<string, DynamicProperty> dictionary = plugin.GetDynamicPropertyList();
192            DynamicPropertyInfoAttribute dynamicPropertyInfoAttribute = plugin.GetDynamicPropertyInfo();
193            foreach (DynamicProperty dynamicProperty in dictionary.Values)
194            {
195               
196                if (this.PropertyName == dynamicProperty.Name)
197                {
198                    foreach(ConnectionModel connectionModel in new List<ConnectionModel>(InputConnections)){
199                        this.WorkspaceModel.deleteConnectionModel(connectionModel);
200                    }
201                    foreach(ConnectionModel connectionModel in new List<ConnectionModel>(this.OutputConnections))
202                    {
203                        this.WorkspaceModel.deleteConnectionModel(connectionModel);
204                    }
205                    this.ConnectorType = dynamicProperty.Type;
206                    if (this.UpdateableView != null)
207                    {
208                        ((ConnectorView)this.UpdateableView).Ellipse.Fill = new SolidColorBrush(ColorHelper.GetColor(this.ConnectorType));
209                    }
210                }
211            }
212        }
213    }
214
215    /// <summary>
216    /// Enumeration for connector orientation:
217    ///
218    ///        North
219    ///       --------
220    ///       |      |
221    /// West  |      |  East
222    ///       |      |
223    ///       --------
224    ///        South
225    /// </summary>
226    public enum ConnectorOrientation
227    {
228        North,
229        East,
230        South,
231        West
232    }
233}
Note: See TracBrowser for help on using the repository browser.