Пример #1
0
        public void UpdateAutoVisgroups(IEnumerable <MapObject> nodes, bool recursive)
        {
            var autos = GetAllVisgroups().OfType <AutoVisgroup>().Where(x => x.Filter != null).ToList();
            var list  = recursive ? nodes.SelectMany(x => x.FindAll()) : nodes;

            foreach (var o in list)
            {
                var obj = o;
                obj.Visgroups.RemoveAll(x => o.AutoVisgroups.Contains(x));
                obj.AutoVisgroups.Clear();
                foreach (var vg in autos.Where(x => x.Filter(obj)))
                {
                    // Add this visgroup and all parents
                    Visgroup visgroup = vg;
                    while (visgroup != null)
                    {
                        if (o.AutoVisgroups.Contains(visgroup.ID))
                        {
                            break;                                        // Break out of infinite loop (just in case)
                        }
                        o.AutoVisgroups.Add(visgroup.ID);

                        visgroup = visgroup.Parent;
                    }
                }
                o.Visgroups.AddRange(o.AutoVisgroups);
            }
        }
Пример #2
0
 private void AddGroup(object sender, EventArgs e)
 {
     var newGroup = new Visgroup
                        {
                            ID = GetNewID(),
                            Colour = Colour.GetRandomLightColour(),
                            Name = "New Group",
                            Visible = true
                        };
     _visgroups.Add(newGroup);
     UpdateVisgroups();
     VisgroupPanel.SetSelectedVisgroup(newGroup.ID);
     GroupName.SelectAll();
     GroupName.Focus();
 }
Пример #3
0
 private static IEnumerable<Visgroup> ReadVisgroups(BinaryReader br)
 {
     var numVisgroups = br.ReadInt32();
     for (var i = 0; i < numVisgroups; i++)
     {
         var vis = new Visgroup
             {
                 Name = br.ReadFixedLengthString(Encoding.UTF8, 128),
                 Colour = br.ReadRGBAColour(),
                 ID = br.ReadInt32(),
                 Visible = br.ReadBoolean()
             };
         vis.Colour = Color.FromArgb(255, vis.Colour);
         br.ReadBytes(3);
         yield return vis;
     }
 }
Пример #4
0
        private void AddNode(TreeNode parent, Visgroup visgroup, Func<Visgroup, string> getCheckState)
        {
            if (!ShowHidden && visgroup is AutoVisgroup && ((AutoVisgroup)visgroup).IsHidden) return;
            if (HideAutomatic && visgroup.IsAutomatic) return;
            var node = new TreeNode(visgroup.Name)
            {
                StateImageKey = getCheckState(visgroup) + (DisableAutomatic && visgroup.IsAutomatic ? "Disabled" : ""),
                BackColor = visgroup.Colour,
                Tag = visgroup.ID
            };

            if (parent == null) VisgroupTree.Nodes.Add(node);
            else parent.Nodes.Add(node);

            foreach (var vg in Sort(visgroup.Children))
            {
                AddNode(node, vg, getCheckState);
            }
        }
Пример #5
0
 private static GenericStructure WriteVisgroup(Visgroup visgroup)
 {
     var ret = new GenericStructure("visgroup");
     ret["name"] = visgroup.Name;
     ret["visgroupid"] = visgroup.ID.ToString(CultureInfo.InvariantCulture);
     ret["color"] = FormatColor(visgroup.Colour);
     return ret;
 }
Пример #6
0
 private static Visgroup ReadVisgroup(GenericStructure visgroup)
 {
     var v = new Visgroup
                 {
                     Name = visgroup["name"],
                     ID = visgroup.PropertyInteger("visgroupid"),
                     Colour = visgroup.PropertyColour("color", Colour.GetRandomBrushColour()),
                     Visible = true
                 };
     return v;
 }
Пример #7
0
        public void VisgroupCreateNew()
        {
            using (var qf = new QuickForm("Create New Visgroup") {UseShortcutKeys = true}.TextBox("Name").CheckBox("Add selection to visgroup", true).OkCancel())
            {
                if (qf.ShowDialog() != DialogResult.OK) return;

                var ids = _document.Map.Visgroups.Where(x => !x.IsAutomatic).Select(x => x.ID).ToList();
                var id = Math.Max(1, ids.Any() ? ids.Max() + 1 : 1);

                var name = qf.String("Name");
                if (String.IsNullOrWhiteSpace(name)) name = "Visgroup " + id.ToString(CultureInfo.InvariantCulture);

                var vg = new Visgroup
                {
                    ID = id,
                    Colour = Colour.GetRandomLightColour(),
                    Name = name,
                    Visible = true
                };
                IAction action = new CreateEditDeleteVisgroups(new[] {vg}, new Visgroup[0], new Visgroup[0]);
                if (qf.Bool("Add selection to visgroup") && !_document.Selection.IsEmpty())
                {
                    action = new ActionCollection(action, new EditObjectVisgroups(_document.Selection.GetSelectedObjects(), new[] {id}, new int[0]));
                }
                _document.PerformAction("Create visgroup", action);
            }
        }
Пример #8
0
 private static IEnumerable<Visgroup> ReadVisgroups(BinaryReader br)
 {
     var list = new List<Visgroup>();
     var numVisgroups = br.ReadInt32();
     for (var i = 0; i < numVisgroups; i++)
     {
         var vis = new Visgroup
             {
                 Name = br.ReadFixedLengthString(Encoding.UTF8, 128),
                 Colour = br.ReadRGBAColour(),
                 ID = br.ReadInt32(),
                 Visible = br.ReadBoolean()
             };
         vis.Colour = Color.FromArgb(255, vis.Colour);
         br.ReadBytes(3);
         list.Add(vis);
     }
     // Get rid of zero groups
     foreach (var vg in list.Where(x => x.ID == 0))
     {
         vg.ID = list.Max(x => x.ID) + 1;
     }
     return list;
 }