Ejemplo n.º 1
0
        public int syncObjects(IEnumerable <DGObject> objs)
        {
            if (objs == null)
            {
                return(0);
            }

            // Build (graphic name)-(graphics) index.
            // Graphics may share a same name if they belong to a object.
            //
            Dictionary <string, IGraphicCollection> graphicIndex =
                new Dictionary <string, IGraphicCollection>();

            foreach (IGraphic g in graphics)
            {
                if (g.Attributes.ContainsKey("Name"))
                {
                    string name = g.Attributes["Name"] as string;
                    if (name == null)
                    {
                        continue;
                    }
                    IGraphicCollection gc = null;
                    if (graphicIndex.ContainsKey(name))
                    {
                        gc = graphicIndex[name];
                    }
                    else
                    {
                        gc = new IS3GraphicCollection();
                        graphicIndex[name] = gc;
                    }
                    gc.Add(g);
                }
            }

            // Sync objects with graphics
            //
            _obj2Graphics     = new Dictionary <DGObject, IGraphicCollection>();
            _graphicName2Objs = new Dictionary <string, DGObject>();
            int count = 0;

            foreach (DGObject obj in objs)
            {
                string name = obj.Name;
                if (graphicIndex.ContainsKey(name))
                {
                    IGraphicCollection gc = graphicIndex[name];
                    _obj2Graphics[obj]      = gc;
                    _graphicName2Objs[name] = obj;
                    count++;
                }
            }
            _graphic2Objs = new Dictionary <IGraphic, DGObject>();
            foreach (IGraphic g in graphics)
            {
                if (g.Attributes.ContainsKey("Name"))
                {
                    string name = g.Attributes["Name"] as string;
                    if (name == null)
                    {
                        continue;
                    }
                    if (_graphicName2Objs.ContainsKey(name))
                    {
                        _graphic2Objs[g] = _graphicName2Objs[name];
                    }
                }
            }

            return(count);
        }
Ejemplo n.º 2
0
        public int syncObjects(IEnumerable <DGObject> objs)
        {
            if (objs == null)
            {
                return(0);
            }

            // Build (graphic name)-(graphics) index.
            // Graphics may share a same name if they belong to a object.
            //
            Dictionary <int, IGraphicCollection> graphicIndex =
                new Dictionary <int, IGraphicCollection>();

            foreach (IGraphic g in graphics)
            {
                if (g.Attributes.ContainsKey("ID"))
                {
                    int id = int.Parse(g.Attributes["ID"].ToString());
                    if (id == null)
                    {
                        continue;
                    }
                    IGraphicCollection gc = null;
                    if (graphicIndex.ContainsKey(id))
                    {
                        gc = graphicIndex[id];
                    }
                    else
                    {
                        gc = new IS3GraphicCollection();
                        graphicIndex[id] = gc;
                    }
                    gc.Add(g);
                }
            }

            // Sync objects with graphics
            //
            _obj2Graphics   = new Dictionary <DGObject, IGraphicCollection>();
            _graphicID2Objs = new Dictionary <int, DGObject>();
            int count = 0;

            foreach (DGObject obj in objs)
            {
                int id = obj.ID;
                if (graphicIndex.ContainsKey(id))
                {
                    IGraphicCollection gc = graphicIndex[id];
                    _obj2Graphics[obj]  = gc;
                    _graphicID2Objs[id] = obj;
                    count++;
                }
            }
            _graphic2Objs = new Dictionary <IGraphic, DGObject>();
            foreach (IGraphic g in graphics)
            {
                if (g.Attributes.ContainsKey("ID"))
                {
                    int id = int.Parse(g.Attributes["ID"].ToString());
                    if (_graphicID2Objs.ContainsKey(id))
                    {
                        _graphic2Objs[g] = _graphicID2Objs[id];
                    }
                }
            }

            return(count);
        }