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

Last change on this file since 1581 was 1581, checked in by kopal, 12 years ago
  • added ToolTip to ConnectorModel
  • added Icon to PluginModel
File size: 5.6 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.Collections.Generic;
19using System.Linq;
20using System.Text;
21using System.ComponentModel;
22using System.Threading;
23
24namespace WorkspaceManager.Model
25{
26   
27
28    /// <summary>
29    /// Class to represent the Connection between two Connector Models
30    /// </summary>
31    [Serializable]
32    public class ConnectorModel : VisualElementModel
33    {
34        [NonSerialized]
35        private Mutex mutex = new Mutex();
36
37        [NonSerialized]
38        private bool hasData = false;
39
40        [NonSerialized]
41        private object data;
42
43        /// <summary>
44        /// The PluginModel this Connector belongs to
45        /// </summary>
46        public PluginModel PluginModel { get; set; }
47
48        /// <summary>
49        /// The data type of this ConnectorModel
50        /// </summary>
51        public Type ConnectorType { get; set; }
52
53        /// <summary>
54        /// Is this Connector Outgoing?
55        /// </summary>
56        public bool Outgoing { get; set; }
57       
58        /// <summary>
59        /// The InputConnection of this ConnectorModel
60        /// </summary>
61        public ConnectionModel InputConnection { get; set; }
62
63        /// <summary>
64        /// The OutputConnections of this ConnectorModel
65        /// </summary>
66        public List<ConnectionModel> OutputConnections;
67
68        /// <summary>
69        /// Creates a new ConnectorModel
70        /// </summary>
71        public ConnectorModel()
72        {
73            this.OutputConnections = new List<ConnectionModel>();
74        }
75
76        /// <summary>
77        /// The WorkspaceModel of this PluginModel
78        /// </summary>
79        public WorkspaceModel WorkspaceModel { get; set; }
80
81        /// <summary>
82        /// Is this Connectors Data mandatory?
83        /// </summary>
84        /// <returns></returns>
85        public bool IsMandatory
86        {
87            get;
88            set;
89        }
90
91        /// <summary>
92        /// Does this Connector currently provides Data?
93        /// </summary>
94        /// <returns></returns>
95        public bool HasData
96        {
97            get { 
98                    return hasData; 
99            }
100
101            set 
102            {   
103                mutex.WaitOne(); 
104                hasData = value; 
105                mutex.ReleaseMutex(); 
106            }
107        }
108
109        /// <summary>
110        /// Data of this Connector
111        /// </summary>
112        public object Data
113        {
114            get
115            {
116                return data;
117            }
118
119            set
120            {
121                mutex.WaitOne();
122                data = value;
123                mutex.ReleaseMutex();
124            }
125        }
126
127        /// <summary>
128        /// Name of the represented Property of the IPlugin of this ConnectorModel
129        /// </summary>
130        public string PropertyName{get;set;}
131
132        /// <summary>
133        /// ToolTip of this Connector
134        /// </summary>
135        public string ToolTip { get; set; }
136
137        /// <summary>
138        /// Plugin informs the Connector that a PropertyChanged
139        /// </summary>
140        /// <param name="sender"></param>
141        /// <param name="propertyChangedEventArgs"></param>
142        public void PropertyChangedOnPlugin(Object sender, PropertyChangedEventArgs propertyChangedEventArgs)
143        {
144            if(propertyChangedEventArgs.PropertyName.Equals(PropertyName) && Outgoing){
145                foreach (ConnectionModel connectionModel in this.OutputConnections)
146                {
147                    while (connectionModel.To.HasData && WorkspaceModel.WorkspaceManagerEditor.isExecuting())
148                    {
149                        Thread.Sleep(5); 
150                    }
151                    connectionModel.To.Data = sender.GetType().GetProperty(propertyChangedEventArgs.PropertyName).GetValue(sender, null);
152                    connectionModel.To.HasData = true;
153                    connectionModel.Active = true;
154                    this.WorkspaceModel.WorkspaceManagerEditor.GuiLogMessage("PropertyChanged: " + sender.GetType().GetProperty(propertyChangedEventArgs.PropertyName),Cryptool.PluginBase.NotificationLevel.Debug);
155
156                    //We changed an input on the PluginModel where "To" is belonging to so
157                    //we have to check if this is executable now
158                    connectionModel.To.PluginModel.checkExecutable();
159                }
160            }                       
161        }
162
163        /// <summary>
164        /// Orientation of this Connecor
165        /// </summary>
166        public ConnectorOrientation ConnectorOrientation { get; set; }
167
168    }
169
170    /// <summary>
171    /// Enumeration for connector orientation:
172    ///
173    ///        North
174    ///       --------
175    ///       |      |
176    /// West  |      |  East
177    ///       |      |
178    ///       --------
179    ///        South
180    /// </summary>
181    public enum ConnectorOrientation
182    {
183        North,
184        East,
185        South,
186        West
187    }
188}
Note: See TracBrowser for help on using the repository browser.