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

Last change on this file since 1620 was 1620, checked in by kopal, 12 years ago
  • connectors now may only connect from output to InputConnection
  • view is disabled when editor is executing now
  • connector now has "lastData" which stores last used data
  • minwidth, minheight of an VisualElementModel can only be >=50 now
File size: 6.2 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 bool hasData = false;
36
37        [NonSerialized]
38        private bool hasLastData = false;
39
40        [NonSerialized]
41        private object data;
42
43        [NonSerialized]
44        private object lastData;
45       
46        /// <summary>
47        /// The PluginModel this Connector belongs to
48        /// </summary>
49        public PluginModel PluginModel { get; set; }
50
51        /// <summary>
52        /// The data type of this ConnectorModel
53        /// </summary>
54        public Type ConnectorType { get; set; }
55
56        /// <summary>
57        /// Is this Connector Outgoing?
58        /// </summary>
59        public bool Outgoing { get; set; }
60       
61        /// <summary>
62        /// The InputConnection of this ConnectorModel
63        /// </summary>
64        public ConnectionModel InputConnection { get; set; }
65
66        /// <summary>
67        /// The OutputConnections of this ConnectorModel
68        /// </summary>
69        public List<ConnectionModel> OutputConnections;
70
71        /// <summary>
72        /// Creates a new ConnectorModel
73        /// </summary>
74        public ConnectorModel()
75        {
76            this.OutputConnections = new List<ConnectionModel>();
77        }
78
79        /// <summary>
80        /// The WorkspaceModel of this PluginModel
81        /// </summary>
82        public WorkspaceModel WorkspaceModel { get; set; }
83
84        /// <summary>
85        /// Is this Connectors Data mandatory?
86        /// </summary>
87        /// <returns></returns>
88        public bool IsMandatory
89        {
90            get;
91            set;
92        }
93
94        /// <summary>
95        /// Does this Connector currently provides Data?
96        /// </summary>
97        /// <returns></returns>
98        public bool HasData
99        {
100            get { 
101                    return hasData; 
102            }
103
104            set 
105            {   
106                hasData = value; 
107            }
108        }
109
110        /// <summary>
111        /// Data of this Connector
112        /// </summary>
113        public object Data
114        {
115            get
116            {
117                return data;
118            }
119
120            set
121            {
122                data = value;
123            }
124        }
125
126        /// <summary>
127        /// Does this Connector currently provides last Data?
128        /// </summary>
129        /// <returns></returns>
130        public bool HasLastData
131        {
132            get
133            {
134                return hasLastData;
135            }
136
137            set
138            {
139                hasLastData = value;
140            }
141        }
142
143        /// <summary>
144        /// LastData of this Connector
145        /// </summary>
146        public object LastData
147        {
148            get
149            {
150                return lastData;
151            }
152
153            set
154            {
155                lastData = value;
156            }
157        }
158
159        /// <summary>
160        /// Name of the represented Property of the IPlugin of this ConnectorModel
161        /// </summary>
162        public string PropertyName{get;set;}
163
164        /// <summary>
165        /// ToolTip of this Connector
166        /// </summary>
167        public string ToolTip { get; set; }
168
169        /// <summary>
170        /// Plugin informs the Connector that a PropertyChanged
171        /// </summary>
172        /// <param name="sender"></param>
173        /// <param name="propertyChangedEventArgs"></param>
174        public void PropertyChangedOnPlugin(Object sender, PropertyChangedEventArgs propertyChangedEventArgs)
175        {
176            if(sender == this.PluginModel.Plugin && 
177                propertyChangedEventArgs.PropertyName.Equals(PropertyName) && 
178                Outgoing){
179               
180                foreach (ConnectionModel connectionModel in this.OutputConnections)
181                {                   
182                    connectionModel.To.Data = sender.GetType().GetProperty(propertyChangedEventArgs.PropertyName).GetValue(sender, null);
183                    connectionModel.To.HasData = true;
184                    connectionModel.Active = true;
185                    //this.WorkspaceModel.WorkspaceManagerEditor.GuiLogMessage("PropertyChanged for  \"" + this.PluginModel.Name + "\" Property \"" + PropertyName + "\"", Cryptool.PluginBase.NotificationLevel.Debug);
186
187                    //We changed an input on the PluginModel where "To" is belonging to so
188                    //we have to check if this is executable now
189                    connectionModel.To.PluginModel.checkExecutable(connectionModel.To.PluginModel.PluginProtocol);
190                }
191            }                       
192        }
193
194        /// <summary>
195        /// Orientation of this Connecor
196        /// </summary>
197        public ConnectorOrientation ConnectorOrientation { get; set; }
198
199    }
200
201    /// <summary>
202    /// Enumeration for connector orientation:
203    ///
204    ///        North
205    ///       --------
206    ///       |      |
207    /// West  |      |  East
208    ///       |      |
209    ///       --------
210    ///        South
211    /// </summary>
212    public enum ConnectorOrientation
213    {
214        North,
215        East,
216        South,
217        West
218    }
219}
Note: See TracBrowser for help on using the repository browser.