Beispiel #1
0
        private void CopyDiagrams(IEnumerable <ObservableDiagram> itemsToCopy, string destinationName)
        {
            Action <string, bool> performCopy = (name, newCollection) =>
            {
                try
                {
                    DiagramLibrary    library          = AppVM.UserConfig.DiagramLibrary;
                    DiagramCollection targetCollection = library.Get(name);

                    foreach (ObservableDiagram od in itemsToCopy)
                    {
                        Diagram clone = od.Diagram.Clone();
                        targetCollection.Add(clone);
                    }

                    Redraw(newCollection);
                }
                catch (Exception ex)
                {
                    ExceptionUtils.HandleException(ex);
                }
            };

            if (!string.IsNullOrWhiteSpace(destinationName))
            {
                // Target was specified
                performCopy(destinationName.Trim(), false);
            }
            else
            {
                // Prompt for a target
                Messenger.Default.Send(new ShowDiagramCollectionSelectorMessage(performCopy));
            }
        }
        public void ShowItem(ITabItem item)
        {
            //bool isnew = false;
            LayoutDocument ldoc = null;

            if (item is FuncBlockViewModel)
            {
                FuncBlockViewModel fbvmodel = (FuncBlockViewModel)item;
                fbvmodel.CodeTextBox.Focus();
            }
            if (item.IsFloat)
            {
                LayoutFloatingWindowControl fwctrl = item.FloatControl;
                fwctrl.Focus();
                return;
            }
            if (!TabItemCollection.Contains(item))
            {
                TabItemCollection.Add(item);
                item.FloatClosed += OnTabFloatClosed;
                ldoc              = new LayoutDocument();
                ldoc.Title        = item.TabHeader;
                if (item is LadderDiagramViewModel)
                {
                    IEnumerable <MainTabDiagramItem> fit = DiagramCollection.Where(
                        (MainTabDiagramItem _mtditem) => { return(_mtditem.LDVM_ladder == item); });
                    MainTabDiagramItem mtditem = null;
                    if (fit.Count() == 0)
                    {
                        mtditem = new MainTabDiagramItem((IProgram)item, ViewMode);
                        DiagramCollection.Add(mtditem);
                    }
                    else
                    {
                        mtditem = fit.First();
                    }
                    ldoc.Content = mtditem;
                }
                else
                {
                    ldoc.Content = item;
                }
                ldoc.IsActiveChanged += OnActiveChanged;
                Children.Add(ldoc);
                _lDocDict.Add(item, ldoc);
                //isnew = true;
            }
            else
            {
                ldoc = _lDocDict[item];
            }
            int ldocid = Children.IndexOf(ldoc);

            SelectedItem         = item;
            SelectedContentIndex = ldocid;
        }
Beispiel #3
0
        public static DiagramCollection Load(DiagramStyle parentStyle, Stream inputStream)
        {
            if (null == parentStyle)
            {
                throw new ArgumentNullException(nameof(parentStyle));
            }

            if (null == inputStream)
            {
                throw new ArgumentNullException(nameof(inputStream));
            }

            DiagramCollection collection = new DiagramCollection(parentStyle);

            using (StreamReader sr = new StreamReader(inputStream))
            {
                ChordOptions currentChordOptions = new ChordOptions();

                string line;
                while (null != (line = sr.ReadLine()))
                {
                    line = line.Trim();
                    try
                    {
                        if (line.StartsWith(CommentPrefix)) // line is a comment
                        {
                            // ignore
                        }
                        else if (line.StartsWith(OptionsPrefix)) // line modifies the options
                        {
                            currentChordOptions = new ChordOptions(line);
                        }
                        else if (!string.IsNullOrEmpty(line)) // treat line as a chord
                        {
                            Chord chord = new Chord(line);

                            Diagram diagram = GetDiagram(chord, currentChordOptions, collection.Style);
                            collection.Add(diagram);
                        }
                    }
                    catch (Exception) { }
                }
            }

            return(collection);
        }