private static NodeSignal buildHelper(string signalName, FieldDataType.DataTypeEnum dataType, object defaultValue)
        {
            var signal = BuildWith(new FieldSignalName(signalName),
                                   new FieldDataType(dataType),
                                   new FieldBool(false), new FieldConstant(dataType, defaultValue));

            return(signal);
        }
        /// <summary>
        /// Displays the Dialog as modal
        /// </summary>
        /// <returns>FieldConstant</returns>
        public FieldConstant ShowDialog(FieldDataType.DataTypeEnum dataType, FieldConstant defaultConstant)
        {
            m_dataType      = dataType;
            OriginalLiteral = defaultConstant;
            setDefaultValues();
            Window dlg = new GetConstantDialogView();

            dlg.Owner       = mainWindowExport.Value;
            dlg.DataContext = this;
            dlg.ShowDialog();
            return(Literal);
        }
Beispiel #3
0
        /// <summary>
        /// Returns a dictionary of signal names, and those signals, in a depth
        /// first search of the runtime application.  For those signals within
        /// the same page, it has no prefix, but for those in other pages or
        /// in the device configuration, it adds a directory-like prefix.
        /// </summary>
        public Dictionary <string, NodeSignal> SignalList(INodeWrapper requester, FieldDataType.DataTypeEnum dataTypeFilter)
        {
            var      dict = new Dictionary <string, NodeSignal>();
            var      tpl  = FindParentPageAndRuntimeApp(requester);
            NodePage pg   = tpl.Item1;
            NodeRuntimeApplication rta = tpl.Item2;

            if (rta != null)
            {
                if (pg != null)
                {
                    // Search the local page first
                    SignalsDepthFirst(pg, string.Empty, dict, pg, dataTypeFilter);
                }
                SignalsDepthFirst(rta, string.Empty, dict, pg, dataTypeFilter);
            }
            return(dict);
        }
        /// <summary>
        /// Displays the Dialog as modal
        /// </summary>
        /// <returns>Signal ID</returns>
        public NodeSignalIn ShowDialog(INodeWrapper requester, NodeSignalIn originalSignalIn)
        {
            m_dataTypefilter = originalSignalIn.CompatibleTypes.DataType;
            OriginalSignalIn = originalSignalIn;
            setDefaultValues();
            NodeItem = requester;
            Window dlg = new SignalChooserDialogView();

            dlg.Owner       = mainWindowExport.Value;
            dlg.DataContext = this;
            dlg.ShowDialog();
            if (SignalSelected)
            {
                return(NodeSignalIn.BuildWith(OriginalSignalIn.DataType, OriginalSignalIn.CompatibleTypes, SignalId));
            }
            else
            {
                return(NodeSignalIn.BuildWith(OriginalSignalIn.DataType, OriginalSignalIn.CompatibleTypes, Literal));
            }
        }
Beispiel #5
0
        public static bool CheckSyntax(String Field)
        {
            if (!Field.Contains(SEPARATOR))
            {
                return(false);
            }
            string[] parts = Field.Split(new string[] { SEPARATOR }, StringSplitOptions.None);
            if (Enum.IsDefined(typeof(FieldDataType.DataTypeEnum), parts[0]))
            {
                FieldDataType.DataTypeEnum dtEnum =
                    (FieldDataType.DataTypeEnum)Enum.Parse(typeof(FieldDataType.DataTypeEnum), parts[0]);

                FieldDataType dt = new FieldDataType(dtEnum);

                object o;
                return(dt.TryParse(parts[1], out o) && BaseCheckSyntax(Field));
            }
            else
            {
                return(false);
            }
        }
Beispiel #6
0
 public static bool CheckSyntax(FieldDataType.DataTypeEnum DataType, object Constant)
 {
     return(CheckSyntax(buildField(DataType, Constant)));
 }
Beispiel #7
0
 private static string buildField(FieldDataType.DataTypeEnum DataType, object Constant)
 {
     return(DataType.ToString() + SEPARATOR + Constant.ToString());
 }
Beispiel #8
0
 public FieldConstant(FieldDataType.DataTypeEnum DataType, object Constant)
     : base(buildField(DataType, Constant))
 {
 }
Beispiel #9
0
        private static void SignalsDepthFirst(NodeBase fromNode, string header, Dictionary <string, NodeSignal> dict, NodePage localRoot,
                                              FieldDataType.DataTypeEnum dataTypeFilter)
        {
            const string SEPARATOR = "/";

            string prevHeader;

            if (header.Length == 0)
            {
                prevHeader = string.Empty;
            }
            else
            {
                prevHeader = header + SEPARATOR;
            }

            var thisSig = fromNode as NodeSignal;

            if (thisSig != null)
            {
                if (thisSig.SignalName.ToString().Length > 0) // ignore unnamed signals
                {
                    var key = prevHeader + thisSig.SignalName;
                    if (thisSig.DataType.IsOfType(dataTypeFilter))
                    {
                        if (!dict.ContainsKey(key))
                        {
                            dict.Add(key, thisSig);
                        }
                    }
                }
            }
            else
            {
                foreach (var child in fromNode.ChildCollection)
                {
                    var nPageCollection      = child as NodePageCollection;
                    var nPage                = child as NodePage;
                    var nInstructionGroup    = child as NodeInstructionGroup;
                    var nInstruction         = child as NodeInstruction;
                    var nSignal              = child as NodeSignal;
                    var nDeviceConfiguration = child as NodeDeviceConfiguration;
                    var nDriver              = child as NodeDriver;
                    var nDevice              = child as NodeDevice;
                    var nDiscreteInput       = child as NodeDiscreteInput;
                    var nAnalogInput         = child as NodeAnalogInput;
                    var nStringInput         = child as NodeStringInput;


                    if (nInstructionGroup != null || nInstruction != null || nDeviceConfiguration != null ||
                        nDriver != null || nDiscreteInput != null || nAnalogInput != null ||
                        nStringInput != null || nSignal != null)
                    {
                        SignalsDepthFirst(child, header, dict, localRoot, dataTypeFilter);
                    }
                    else if (nPageCollection != null)
                    {
                        SignalsDepthFirst(child, prevHeader + nPageCollection.PageCollectionName, dict, localRoot, dataTypeFilter);
                    }
                    else if (nPage != null)
                    {
                        string newHeader = prevHeader + nPage.PageName;
                        if (nPage == localRoot)
                        {
                            newHeader = string.Empty;
                        }
                        SignalsDepthFirst(child, newHeader, dict, localRoot, dataTypeFilter);
                    }
                    else if (nDevice != null)
                    {
                        SignalsDepthFirst(child, prevHeader + nDevice.DeviceName, dict, localRoot, dataTypeFilter);
                    }
                }
            }
        }
Beispiel #10
0
 public FieldConstant GetConstant(FieldDataType.DataTypeEnum dataType, FieldConstant defaultConstant)
 {
     return(getConstantDialog.ShowDialog(dataType, defaultConstant));
 }
 /// <summary>
 /// Displays the Dialog as modal
 /// </summary>
 /// <returns>Signal ID</returns>
 public NodeSignalIn ShowDialog(INodeWrapper requester, NodeSignalIn originalSignalIn)
 {
     m_dataTypefilter = originalSignalIn.CompatibleTypes.DataType;
     OriginalSignalIn = originalSignalIn;
     setDefaultValues();
     NodeItem = requester;
     Window dlg = new SignalChooserDialogView();
     dlg.Owner = mainWindowExport.Value;
     dlg.DataContext = this;
     dlg.ShowDialog();
     if (SignalSelected)
     {
         return NodeSignalIn.BuildWith(OriginalSignalIn.DataType, OriginalSignalIn.CompatibleTypes, SignalId);
     }
     else
     {
         return NodeSignalIn.BuildWith(OriginalSignalIn.DataType, OriginalSignalIn.CompatibleTypes, Literal);
     }
 }
            private Collection <SignalTreeItem> BuildSignalTree(SignalChooserDialog dlg, NodeBase n,
                                                                NodePage pg, FieldGuid selectedSignalId, FieldDataType.DataTypeEnum dataTypeFilter)
            {
                var items = new Collection <SignalTreeItem>();

                foreach (var child in n.ChildCollection)
                {
                    var nPageCollection      = child as NodePageCollection;
                    var nPage                = child as NodePage;
                    var nInstructionGroup    = child as NodeInstructionGroup;
                    var nInstruction         = child as NodeInstruction;
                    var nSignal              = child as NodeSignal;
                    var nDeviceConfiguration = child as NodeDeviceConfiguration;
                    var nDriver              = child as NodeDriver;
                    var nDevice              = child as NodeDevice;
                    var nDiscreteInput       = child as NodeDiscreteInput;
                    var nAnalogInput         = child as NodeAnalogInput;
                    var nStringInput         = child as NodeStringInput;

                    // the following logic sets one or the other, or neither
                    SignalTreeItem item           = null;
                    NodeBase       searchChildren = null;
                    bool           sort           = false;
                    var            adjustedChild  = child;

                    if (nPageCollection != null)
                    {
                        item = new SignalTreeItem(dlg, nPageCollection.PageCollectionName.ToString(), null);
                    }
                    else if (nPage != null)
                    {
                        var pgToUse = nPage;
                        if (pg != null && nPage.PageId == pg.PageId)
                        {
                            pgToUse       = pg;
                            adjustedChild = pg;
                        }
                        item = new SignalTreeItem(dlg, pgToUse.PageName.ToString(), null);
                        sort = true;
                    }
                    else if (nInstructionGroup != null || nInstruction != null || nDiscreteInput != null || nAnalogInput != null || nStringInput != null)
                    {
                        searchChildren = adjustedChild;
                    }
                    else if (nSignal != null)
                    {
                        if (nSignal.DataType.IsOfType(dataTypeFilter))
                        {
                            item = new SignalTreeItem(dlg, nSignal.SignalName.ToString(), nSignal);
                            if (nSignal.SignalId == selectedSignalId)
                            {
                                item.IsSelected = true;
                            }
                        }
                    }
                    else if (nDeviceConfiguration != null)
                    {
                        item = new SignalTreeItem(dlg, Resources.Strings.Solution_Pad_DeviceConfigurationItem_Header, null);
                    }
                    else if (nDriver != null)
                    {
                        item = new SignalTreeItem(dlg, nDriver.DriverName.ToString(), null);
                    }
                    else if (nDevice != null)
                    {
                        item = new SignalTreeItem(dlg, nDevice.DeviceName.ToString(), null);
                    }

                    if (searchChildren != null)
                    {
                        var childItems = BuildSignalTree(dlg, searchChildren, pg, selectedSignalId, dataTypeFilter);
                        if (childItems != null)
                        {
                            foreach (var childItem in childItems)
                            {
                                items.Add(childItem);
                            }
                        }
                    }

                    if (item != null)
                    {
                        items.Add(item);
                        var childItems = BuildSignalTree(dlg, adjustedChild, pg, selectedSignalId, dataTypeFilter);
                        if (childItems != null)
                        {
                            if (sort)
                            {
                                var sorted = from c in childItems orderby c.Text select c;
                                childItems = new Collection <SignalTreeItem>();
                                foreach (var c in sorted)
                                {
                                    childItems.Add(c);
                                }
                            }
                            // make sure to have this branch of the tree expanded if the selected node is somewhere down there
                            if (childItems.Count((SignalTreeItem ti) => ti.IsSelected) > 0 ||
                                childItems.Count((SignalTreeItem ti) => ti.IsExpanded) > 0)
                            {
                                item.IsExpanded = true;
                            }

                            item.SetItems(childItems);
                        }
                    }
                }

                if (items.Count > 0)
                {
                    return(items);
                }
                else
                {
                    return(null);
                }
            }
 /// <summary>
 /// Displays the Dialog as modal
 /// </summary>
 /// <returns>FieldConstant</returns>
 public FieldConstant ShowDialog(FieldDataType.DataTypeEnum dataType, FieldConstant defaultConstant)
 {
     m_dataType = dataType;
     OriginalLiteral = defaultConstant;
     setDefaultValues();
     Window dlg = new GetConstantDialogView();
     dlg.Owner = mainWindowExport.Value;
     dlg.DataContext = this;
     dlg.ShowDialog();
     return Literal;
 }