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

Last change on this file since 1570 was 1570, checked in by kopal, 12 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: 5.5 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        /// Plugin informs the Connector that a PropertyChanged
134        /// </summary>
135        /// <param name="sender"></param>
136        /// <param name="propertyChangedEventArgs"></param>
137        public void PropertyChangedOnPlugin(Object sender, PropertyChangedEventArgs propertyChangedEventArgs)
138        {
139            if(propertyChangedEventArgs.PropertyName.Equals(PropertyName) && Outgoing){
140                foreach (ConnectionModel connectionModel in this.OutputConnections)
141                {
142                    while (connectionModel.To.HasData && WorkspaceModel.WorkspaceManagerEditor.isExecuting())
143                    {
144                        Thread.Sleep(5); 
145                    }
146                    connectionModel.To.Data = sender.GetType().GetProperty(propertyChangedEventArgs.PropertyName).GetValue(sender, null);
147                    connectionModel.To.HasData = true;
148                    connectionModel.Active = true;
149                    this.WorkspaceModel.WorkspaceManagerEditor.GuiLogMessage("PropertyChanged: " + sender.GetType().GetProperty(propertyChangedEventArgs.PropertyName),Cryptool.PluginBase.NotificationLevel.Debug);
150
151                    //We changed an input on the PluginModel where "To" is belonging to so
152                    //we have to check if this is executable now
153                    connectionModel.To.PluginModel.checkExecutable();
154                }
155            }                       
156        }
157
158        /// <summary>
159        /// Orientation of this Connecor
160        /// </summary>
161        public ConnectorOrientation ConnectorOrientation { get; set; }
162
163    }
164
165    /// <summary>
166    /// Enumeration for connector orientation:
167    ///
168    ///        North
169    ///       --------
170    ///       |      |
171    /// West  |      |  East
172    ///       |      |
173    ///       --------
174    ///        South
175    /// </summary>
176    public enum ConnectorOrientation
177    {
178        North,
179        East,
180        South,
181        West
182    }
183}
Note: See TracBrowser for help on using the repository browser.