Пример #1
0
        /// <summary>
        /// Adds the specified node.
        /// </summary>
        /// <param name="node">The node.</param>
        public override void Add(Node node)
        {
            if (_deviceManager == null)
                _deviceManager = CoreSystem.Managers.Find(m => m.Name.Contains("DeviceManager")) as DeviceManager;
            if (_displayManager == null)
                _displayManager = CoreSystem.Managers.Find(m => m.Name.Contains("DisplayManager")) as DisplayManager;

            if (!Nodes.Contains(node)) {
                if (node is DeviceProperty) {
                    List<Node> devices = new List<Node>();
                    foreach (Plugin plugin in _deviceManager.Plugins) {
                        if (plugin is Device)
                            devices.Add(plugin as Device);
                    }

                    DeviceProperty deviceProperty = node as DeviceProperty;
                    deviceProperty.AddDeviceList(devices.DeepClone(), _deviceManager);
                }

                if (node is Property) {
                    Property property = node as Property;
                    property.PropertyChanged += PropertyPropertyChanged;
                    if (property.IsMonitored) {
                        if (_dataStorageManager == null)
                            _dataStorageManager = CoreSystem.Managers.Find(m => m.Name.Contains("DataStorageManager")) as DataStorageManager;
                        _dataStorageManager.Add(property);
                    }
                }

                _displayManager.Add(node);
                Nodes.Add(node);
                Trace.WriteLine("Property added: " + node.ToString(), LogCategory.Debug);
                OnNodeAdded(node);
            }
        }
Пример #2
0
 private StringPropertyControl AddStringProperty(Grid grid, Node property, bool isConnectable)
 {
     StringPropertyControl control = new StringPropertyControl(property as ns.Base.Plugins.Properties.Property, isConnectable);
     control.TextChanged += StringPropertyControlTextChanged;
     SetControlGridPosition(control, grid);
     return control;
 }
Пример #3
0
 /// <summary>
 /// Adds the specified node.
 /// </summary>
 /// <param name="node">The node.</param>
 public override void Add(Node node)
 {
     if (node is ImageProperty && node.Parent is Tool && ((ImageProperty)node).IsOutput) {
         node.PropertyChanged += ImageChangedEventHandle;
         base.Add(node);
     } else if (node is Operation)
         base.Add(node);
 }
Пример #4
0
 /// <summary>
 /// Remove Device.
 /// </summary>
 /// <param name="node">The Device to be removed.</param>
 public override void Remove(Node node)
 {
     base.Remove(node);
     ProjectManager projectManager = CoreSystem.Managers.Find(m => m.Name.Contains("ProjectManager")) as ProjectManager;
     if (projectManager.Configuration.Devices.Contains(node)) {
         projectManager.Configuration.Devices.Remove(node as Device);
     }
 }
Пример #5
0
 /// <summary>
 /// Removes the specified node.
 /// </summary>
 /// <param name="node">The node.</param>
 public override void Remove(Node node)
 {
     if (node is ImageProperty) {
         node.PropertyChanged -= ImageChangedEventHandle;
         base.Remove(node);
     } else if (node is Operation)
         base.Remove(node);
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NodeTreeItem"/> class.
 /// </summary>
 /// <param name="node">The node.</param>
 public NodeTreeItem(Node node)
     : base()
 {
     _textBlock = new TextBlock();
         this.Loaded += HandleLoaded;
         this.Style = new Style(GetType(), this.FindResource(typeof(TreeViewItem)) as Style);
         _node = node;
         CreateHeaderPanel(node, string.Empty);
 }
Пример #7
0
        private DevicePropertyControl AddDeviceProperty(Grid grid, Node property, bool isConnectable)
        {
            DevicePropertyControl control = new DevicePropertyControl(property as ns.Base.Plugins.Properties.Property, isConnectable);
            SetControlGridPosition(control, grid);
            DeviceProperty deviceProperty = property as DeviceProperty;

            control.SelectionBox.SelectionChanged += SelectionBoxSelectionChanged;
            return control;
        }
        /// <summary>
        /// Adds the tool.
        /// </summary>
        /// <exception cref="System.Exception">
        /// Selected tool is NULL!
        /// or
        /// Selected operation is NULL!
        /// </exception>
        private void AddTool()
        {
            ListBox view = null;
            if (this.AnyTabs.SelectedItem == this.MainToolsTab) {

                TabItem selectedTab = this.ToolTabs.SelectedItem as TabItem;
                view = selectedTab.Content as ListBox;

                if (view != null) {
                    Tool tool = view.SelectedItem as Tool;

                    if (tool == null)
                        return;

                   if(_guiManager.SelectedNode != null && _guiManager.SelectedNode is Tool) {
                        _guiManager.SelectNode(_guiManager.SelectedNode.Parent);
                    }

                    if (_guiManager.SelectedNode == null) {
                        ProjectManager manager = CoreSystem.Managers.Find(m => m.Name.Contains("ProjectManager")) as ProjectManager;
                        if (manager.Configuration.Operations.Count > 0)
                            _guiManager.SelectNode(manager.Configuration.Operations[0]);
                    }

                    if (_guiManager.SelectedNode != null &&  _guiManager.SelectedNode is Operation) {
                        _lastAddedNode = tool.Clone() as Node;
                        _projectManager.Add(_lastAddedNode, _guiManager.SelectedNode);
                    }
                }
            }
            else if (this.AnyTabs.SelectedItem == this.MainOperationsTabs) {
                view = this.ListViewAllOperations;

                Operation operation = view.SelectedItem as Operation;

                if (operation == null)
                    return;

                _lastAddedNode = operation.Clone() as Operation;
                _projectManager.Add(_lastAddedNode);
                _guiManager.SelectNode(_lastAddedNode);
            }
        }
Пример #9
0
 private void nodeManager_SelectedItemChanged(object sender, Base.Event.NodeSelectionChangedEventArgs e)
 {
     _selectedNode = e.SelectedNode;
     UpdateProperties(_selectedNode);
 }
Пример #10
0
        private void GeneratePropertyControls(Grid parentGrid, Node node)
        {
            foreach (ns.Base.Plugins.Properties.Property property in node.Childs.Where(c => c is ns.Base.Plugins.Properties.Property && !((ns.Base.Plugins.Properties.Property)c).IsOutput)) {
                if (property.IsOutput) continue;

                if (property is StringProperty
                    || property.GetType().IsAssignableFrom(typeof(StringProperty))
                    || property.GetType().IsSubclassOf(typeof(StringProperty))) {
                    AddStringProperty(parentGrid, property, true);
                } else if (CheckPropertyIsNumberType(property)) {
                    AddNumberProperty(parentGrid, property, true);
                } else if (property is DeviceProperty) {
                    AddDeviceProperty(parentGrid, property, true);
                    if (property.Childs.Count > 0) {
                        GroupBox groupBox = new GroupBox();
                        groupBox.BorderThickness = new Thickness(0.0);
                        groupBox.Header = property.GroupName;
                        parentGrid.Children.Add(groupBox);

                        RowDefinition rowDefinition = new RowDefinition();
                        rowDefinition.Height = GridLength.Auto;
                        parentGrid.RowDefinitions.Add(rowDefinition);
                        Grid.SetRow(groupBox, parentGrid.Children.Count);

                        Grid grid = new Grid();
                        groupBox.Content = grid;

                        foreach (Node child in property.Childs) {
                            GeneratePropertyControls(grid, child);
                        }
                    }
                } else if (property is ListProperty) {
                    AddComboBoxProperty(parentGrid, property, true);
                } else if (property is ImageProperty) {
                    AddComboBoxProperty(parentGrid, property, true);
                }else if (property is RectangleProperty) {
                    AddRectangleProperty(parentGrid, property, true);
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Adds the child nodes.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="parent">The parent.</param>
        private void AddChildNodes(Node node, Node parent)
        {
            List<Node> nodes = new List<Node>();
            foreach (Node child in node.Childs) {
                Node childNode = child;
                if (child is Property) {
                    Property originalProperty = child as Property;
                    Property property = originalProperty.DeepClone() as Property;
                    property.UID = Node.GenerateUID();
                    property.SetParent(parent);

                    if (property.CanAutoConnect && !property.IsOutput) {
                        List<Property> connectableProperties = _propertyManager.GetConnectableProperties(property);
                        if (connectableProperties != null && connectableProperties.Count > 0)
                            property.Connect(connectableProperties[connectableProperties.Count - 1]);
                    }
                    childNode = property;
                }
                nodes.Add(childNode);
            }

            node.Childs.Clear();
            parent.AddChild(node);
            node.SetParent(parent);

            foreach (Node child in nodes) {
                node.Childs.Add(child);
                AddChildNodes(child, node);
                _propertyManager.Add(child);
            }
        }
Пример #12
0
        /// <summary>
        /// Clones the properties.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        private void CloneProperties(Node source, Node destination)
        {
            List<object> listProperties = destination.Childs.FindAll(c => c is ListProperty);
            List<object> numberProperties = destination.Childs.DeepClone();

            destination.Childs.Clear();

            foreach (Property p in source.Childs.FindAll(c => c is Property)) {
                Property property = _propertyManager.PropertyTypes.Find(pp => pp.Fullname == p.Fullname) as Property;
                Property propertyClone = property.Clone() as Property;
                propertyClone.Value = p.Value;
                propertyClone.Name = p.Name;
                propertyClone.UID = p.UID;
                propertyClone.IsOutput = p.IsOutput;
                propertyClone.IsMonitored = p.IsMonitored;
                propertyClone.ConnectedToUID = p.ConnectedToUID;
                propertyClone.Childs = new List<object>(p.Childs);
                propertyClone.Tolerance = p.Tolerance;

                foreach (Node childNode in propertyClone.Childs)
                    childNode.SetParent(propertyClone);
                propertyClone.SetParent(destination);

                if (propertyClone is DeviceProperty) {
                    string uid = p.Value as string;
                    DeviceProperty devicePropertyClone = propertyClone as DeviceProperty;
                    ns.Base.Plugins.Device device = this.Configuration.Devices.Find(d => d.UID == uid);

                    if (device != null)
                        devicePropertyClone.SetDevice(_deviceManager, device);
                    else
                        devicePropertyClone.SetDevice(_deviceManager, uid);

                } else if (propertyClone is ImageProperty) {
                    _displayManager.Add(propertyClone);
                } else if (propertyClone is ListProperty) {
                    ListProperty originalListProperty = listProperties.Find(c => ((Property)c).Name == propertyClone.Name) as ListProperty;
                    ((ListProperty)propertyClone).List = originalListProperty.List;
                } else if (propertyClone is NumberProperty<object>) {
                    NumberProperty<object> targetPropertyClone = propertyClone as NumberProperty<object>;
                    NumberProperty<object> propertyModel = numberProperties.Find(c => ((Property)c).Name == targetPropertyClone.Name) as NumberProperty<object>;
                    targetPropertyClone.Min = propertyModel.Min;
                    targetPropertyClone.Max = propertyModel.Max;
                } else if (propertyClone is DoubleProperty) {
                    DoubleProperty targetPropertyClone = propertyClone as DoubleProperty;
                    DoubleProperty propertyModel = numberProperties.Find(c => ((Property)c).Name == targetPropertyClone.Name) as DoubleProperty;
                    targetPropertyClone.Min = propertyModel.Min;
                    targetPropertyClone.Max = targetPropertyClone.Max;
                    if(propertyClone.Tolerance != null)
                        targetPropertyClone.Tolerance = new Tolerance<double>(Convert.ToDouble(propertyClone.Tolerance.Min), Convert.ToDouble(propertyClone.Tolerance.Max));
                } else if (propertyClone is IntegerProperty) {
                    IntegerProperty targetPropertyClone = propertyClone as IntegerProperty;
                    IntegerProperty propertyModel = numberProperties.Find(c => ((Property)c).Name == targetPropertyClone.Name) as IntegerProperty;
                    targetPropertyClone.Min = propertyModel.Min;
                    targetPropertyClone.Max = targetPropertyClone.Max;
                    if (propertyClone.Tolerance != null)
                        targetPropertyClone.Tolerance = new Tolerance<int>(Convert.ToInt32(propertyClone.Tolerance.Min), Convert.ToInt32(propertyClone.Tolerance.Max));
                }

                _propertyManager.Add(propertyClone);
                destination.Childs.Add(propertyClone);
            }
        }
Пример #13
0
        /// <summary>
        /// Removes the specified node.
        /// </summary>
        /// <param name="node">The node.</param>
        public override void Remove(Node node)
        {
            if (_displayManager == null)
                _displayManager = CoreSystem.Managers.Find(m => m.Name.Contains("DisplayManager")) as DisplayManager;

            if (node is Property) {
                foreach (Property child in node.Childs.Where(p => p is Property))
                    Remove(child);

                _displayManager.Remove(node);
                base.Remove(node);
            }
        }
Пример #14
0
        /// <summary>
        /// Removes the specified node.
        /// </summary>
        /// <param name="node">The node.</param>
        public override void Remove(Node node)
        {
            if(_displayManager == null)
                _displayManager = CoreSystem.Managers.Find(m => m.Name.Contains("DisplayManager")) as DisplayManager;

            if (node is Operation) {
                Operation operation = node as Operation;

                if (_configuration.Operations.Contains(operation)) {
                    _configuration.Operations.Remove(operation);
                    OnOperationCollectionChanged(new List<Node> { node }, true);
                }
            } else if (node is Tool) {
                bool enableProcessor = false;

                if (CoreSystem.Processor.IsRunning) {
                    Trace.WriteLine("Stopping processor while removing a tool ...", LogCategory.Info);
                    CoreSystem.Processor.Stop();
                    enableProcessor = true;
                }

                foreach (Node child in node.Childs) {
                    if (child is Property)
                        _propertyManager.Remove(child);
                }

                Node parentNode = node.Parent;
                if (parentNode != null)
                    parentNode.RemoveChild(node);

                if (enableProcessor) {
                    CoreSystem.Processor.Start();
                    Trace.WriteLine("... processor started again!", LogCategory.Info);
                }
            }
            _displayManager.Remove(node);
            base.Remove(node);
        }
Пример #15
0
 private RectanglePropertyControl AddRectangleProperty(Grid grid, Node property, bool isConnectable)
 {
     RectanglePropertyControl control = new RectanglePropertyControl(property as ns.Base.Plugins.Properties.Property, isConnectable);
     SetControlGridPosition(control, grid);
     return control;
 }
Пример #16
0
        /// <summary>
        /// Creates the header panel.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="additionalFormat">The additional format.</param>
        private void CreateHeaderPanel(Node node, string additionalFormat)
        {
            string name = node.Name;
            string iconUrl = string.Empty;

            _additionFormat = additionalFormat;

            node.PropertyChanged += HandlePropertyChanged;

            if (node is StringProperty) {
                if (!string.IsNullOrEmpty(additionalFormat)) {
                    name = string.Format(additionalFormat, ((StringProperty)node).Value as string);
                } else
                    name = ((StringProperty)node).Value as string;
            } else if(node is Operation) {
                iconUrl = "/ns.GUI.WPF;component/Images/Operation.png";
            } else if (node is Tool) {
                iconUrl = "/ns.GUI.WPF;component/Images/Module.png";
                string description = ((Tool)node).Description;
                if (!string.IsNullOrEmpty(description))
                    this.ToolTip = description;
            }

            StackPanel panel = new StackPanel();
            panel.Orientation = Orientation.Horizontal;

            if (!string.IsNullOrEmpty(iconUrl)) {
                BitmapImage image = new BitmapImage();
                image.BeginInit();
                image.UriSource = new Uri(iconUrl, UriKind.Relative);
                image.EndInit();

                _imageContainer = new Image();
                _imageContainer.Source = image;
                _imageContainer.Width = 24;
                _imageContainer.Height = 23;
                _imageContainer.Margin = new Thickness(2, 0, 2, 0);

                panel.Children.Add(_imageContainer);
            }

            _textBlock.Text = name;
            panel.Children.Add(_textBlock);

            this.Header = panel;
        }
Пример #17
0
 /// <summary>
 /// Removes the child.
 /// </summary>
 /// <param name="child">The child.</param>
 public virtual void RemoveChild(Node child)
 {
     lock (Childs) {
         if (Childs.Contains(child)) {
             child.RemoveChilds();
             Childs.Remove(child);
             OnChildCollectionChanged(new List<Node> { });
         }
     }
 }
Пример #18
0
 /// <summary>
 /// Closes this instance.
 /// </summary>
 public virtual void Close()
 {
     if (_node != null) {
         _node.PropertyChanged -= HandlePropertyChanged;
         _node = null;
     }
 }
Пример #19
0
 /// <summary>
 /// Adds a new Node to the Parent.
 /// Will trigger internal the OnChildCollectionChanged Method (ChildCollectionChanged).
 /// </summary>
 /// <param name="child">The Node that should be added.</param>
 public virtual void AddChild(Node child)
 {
     lock (Childs) {
         if (Childs.Contains(child) == false) {
             if (child is Node)
                 ((Node)child).SetParent(this);
             Childs.Add(child);
             OnChildCollectionChanged(new List<Node> { child });
         }
     }
 }
Пример #20
0
        /// <summary>
        /// Removes the specified node.
        /// </summary>
        /// <param name="node">The node.</param>
        public override void Remove(Node node)
        {
            if (node is Property) {
                Property property = node as Property;
                DataStorageContainer container;

                lock (_dataStorage.Containers) {
                    try {
                        container = _dataStorage.Containers.Find(c => c.TreeName == property.TreeName);
                        if (this.ContainerRemovedEvent != null) {
                            this.ContainerRemovedEvent(this, new DataStorageContainerChangedEventArgs(property, container));
                        }
                        _dataStorage.Containers.Remove(container);
                    } catch(Exception ex) {
                        Trace.WriteLine(ex.Message, ex.StackTrace, LogCategory.Error);
                    }
                }

            }
        }
Пример #21
0
        /// <summary>
        /// Gets the target properties.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="targetTool">The target tool.</param>
        /// <param name="parent">The parent.</param>
        /// <returns></returns>
        private List<Property> GetTargetProperties(Property property, Tool targetTool, Node parent)
        {
            List<ns.Base.Plugins.Properties.Property> properties = new List<ns.Base.Plugins.Properties.Property>();

            foreach (Node node in parent.Childs) {
                if (node == targetTool) break;

                if (node is Property) {
                    ns.Base.Plugins.Properties.Property prop = node as ns.Base.Plugins.Properties.Property;
                    if (prop.IsOutput && (prop.Parent is Tool || prop.Parent is Operation) && property.GetType() == prop.GetType())
                        properties.Add(prop);
                }

                properties.AddRange(GetTargetProperties(property, targetTool, node));
            }

            return properties;
        }
Пример #22
0
        private void UpdateProperties(Node selectedNode)
        {
            this.PropertyGrid.RowDefinitions.Clear();
            this.PropertyGrid.Children.Clear();

            if (selectedNode == null) return;

            RowDefinition baseRowDefinition = new RowDefinition();
            this.PropertyGrid.RowDefinitions.Add(baseRowDefinition);

            GroupBox baseGroupBox = new GroupBox();
            baseGroupBox.Header = "Base";
            baseGroupBox.BorderThickness = new Thickness(0.0);
            this.PropertyGrid.Children.Add(baseGroupBox);

            Grid baseGrid = new Grid();
            baseGroupBox.Content = baseGrid;

            if (selectedNode is StringProperty)
                AddStringProperty(baseGrid, selectedNode, false);
            else
                AddStringProperty(baseGrid, "Name", selectedNode.Name);

            GeneratePropertyControls(baseGrid, selectedNode);
        }
Пример #23
0
        /// <summary>
        /// Adds the node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="parent">The parent.</param>
        public void Add(Node node, Node parent)
        {
            if(_propertyManager == null)
                _propertyManager = CoreSystem.Managers.Find(m => m.Name.Contains("PropertyManager")) as PropertyManager;

            bool enableProcessor = false;

            if (node is Tool && CoreSystem.Processor.IsRunning) {
                Trace.WriteLine("Stopping processor while attaching another tool ...", LogCategory.Info);
                CoreSystem.Processor.Stop();
                enableProcessor = true;
            }

            AddChildNodes(node, parent);

            if (enableProcessor) {
                CoreSystem.Processor.Start();
                Trace.WriteLine("... processor started again!", LogCategory.Info);
            }
        }
Пример #24
0
        /// <summary>
        /// Adds the specified node.
        /// </summary>
        /// <param name="node">The node.</param>
        public override void Add(Node node)
        {
            if (_displayManager == null)
                _displayManager = CoreSystem.Managers.Find(m => m.Name.Contains("DisplayManager")) as DisplayManager;
            if (node is Operation) {
                Operation operation = node as Operation;

                if (!_configuration.Operations.Contains(operation)) {
                    _configuration.Operations.Add(operation);
                    _displayManager.Add(operation);
                    OnOperationCollectionChanged(new List<Node> { node }, false);
                }
            }
        }
Пример #25
0
        /// <summary>
        /// Connects the properties by node.
        /// </summary>
        /// <param name="node">The node.</param>
        public void ConnectPropertiesByNode(Node node)
        {
            foreach (Node c in node.Childs) {
                if (c is Property) {
                    Property child = c as Property;
                    if (!string.IsNullOrEmpty(child.ConnectedToUID)) {
                        Property parent = this.Nodes.Find(p => p.UID == child.ConnectedToUID) as Property;
                        if (parent != null)
                            child.Connect(parent);
                    }
                }

                ConnectPropertiesByNode(c);
            }
        }
Пример #26
0
 /// <summary>
 /// Sets the parent.
 /// </summary>
 /// <param name="parent">The parent.</param>
 public void SetParent(Node parent)
 {
     if(_parent != null)
         _parent.PropertyChanged -= ParentPropertyChangedEvent;
     _parent = parent;
     _parent.PropertyChanged += ParentPropertyChangedEvent;
 }
Пример #27
0
 /// <summary>
 /// Adds the Node context to DataStorage.
 /// </summary>
 /// <param name="node">The Node containing the needed context.</param>
 public void AddContext(Node node)
 {
     foreach (Node child in node.Childs) {
         if (child is Property) {
             Property property = child as Property;
             if (property.IsOutput && property.IsMonitored) {
                 this.Add(property);
             }
         }
         AddContext(child);
     }
 }
Пример #28
0
 /// <summary>
 /// Selects the node.
 /// </summary>
 /// <param name="node">The node.</param>
 public void SelectNode(Node node)
 {
     _selectedNode = node;
     if(node != null)
         _selectedNode.IsSelected = true;
     if (SelectedItemChanged != null)
         SelectedItemChanged(this, new NodeSelectionChangedEventArgs(node));
 }
Пример #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Node"/> class.
 /// </summary>
 /// <param name="node">The node.</param>
 public Node(Node node)
 {
     this.UID = node.UID;
     this.Fullname = node.Fullname;
     this.Name = node.Name;
 }