Exemple #1
0
        private void SetFigChild(MpFigure_v1002 mpfig, Dictionary <uint, CadFigure> dic)
        {
            for (int i = 0; i < mpfig.ChildIdList.Count; i++)
            {
                uint id = mpfig.ChildIdList[i];

                mpfig.TempFigure.ChildList.Add(dic[id]);
                dic[id].Parent = mpfig.TempFigure;
            }
        }
Exemple #2
0
        public static List <MpFigure_v1002> FigureListToMp_v1002(List <CadFigure> figList, bool withChild = false)
        {
            List <MpFigure_v1002> ret = new List <MpFigure_v1002>();

            for (int i = 0; i < figList.Count; i++)
            {
                ret.Add(MpFigure_v1002.Create(figList[i], withChild));
            }

            return(ret);
        }
Exemple #3
0
        public static List <MpFigure_v1002> FigureMapToMp_v1002(
            Dictionary <uint, CadFigure> figMap, bool withChild = false)
        {
            List <MpFigure_v1002> ret = new List <MpFigure_v1002>();

            foreach (CadFigure fig in figMap.Values)
            {
                ret.Add(MpFigure_v1002.Create(fig, withChild));
            }

            return(ret);
        }
Exemple #4
0
        public static MpFigure_v1002 Create(CadFigure fig, bool withChild = false)
        {
            MpFigure_v1002 ret = new MpFigure_v1002();

            ret.StoreCommon(fig);

            if (withChild)
            {
                ret.StoreChildList(fig);
            }
            else
            {
                ret.StoreChildIdList(fig);
            }
            return(ret);
        }
Exemple #5
0
        public CadObjectDB Restore()
        {
            CadObjectDB ret = new CadObjectDB();

            ret.LayerIdProvider.Counter = LayerIdCount;
            ret.FigIdProvider.Counter   = FigureIdCount;

            // Figure map
            List <CadFigure> figList = MpUtil_v1002.FigureListFromMp_v1002(FigureList);

            var dic = new Dictionary <uint, CadFigure>();

            for (int i = 0; i < figList.Count; i++)
            {
                CadFigure fig = figList[i];

                dic.Add(fig.ID, fig);
                FigureList[i].TempFigure = fig;
            }

            ret.FigureMap = dic;


            // Child list
            for (int i = 0; i < figList.Count; i++)
            {
                MpFigure_v1002 mpfig = FigureList[i];
                SetFigChild(mpfig, dic);
            }


            // Layer map
            ret.LayerList = MpUtil_v1002.LayerListFromMp(LayerList, dic);

            ret.LayerMap = new Dictionary <uint, CadLayer>();

            for (int i = 0; i < ret.LayerList.Count; i++)
            {
                CadLayer layer = ret.LayerList[i];

                ret.LayerMap.Add(layer.ID, layer);
            }

            ret.CurrentLayerID = CurrentLayerID;

            return(ret);
        }
Exemple #6
0
        public virtual void ForEachFig(Action <MpFigure_v1002> d)
        {
            d(this);

            if (ChildList == null)
            {
                return;
            }

            int i;

            for (i = 0; i < ChildList.Count; i++)
            {
                MpFigure_v1002 c = ChildList[i];
                c.ForEachFig(d);
            }
        }
Exemple #7
0
        public virtual void ForEachFigID(Dictionary <uint, MpFigure_v1002> allMap, Action <uint> d)
        {
            d(ID);

            if (ChildIdList == null)
            {
                return;
            }

            int i;

            for (i = 0; i < ChildIdList.Count; i++)
            {
                uint           id       = ChildIdList[i];
                MpFigure_v1002 childFig = allMap[id];
                childFig.ForEachFigID(allMap, d);
            }
        }
Exemple #8
0
        public void GarbageCollect()
        {
            var idMap = new Dictionary <uint, MpFigure_v1002>();

            foreach (MpFigure_v1002 fig in FigureList)
            {
                idMap.Add(fig.ID, fig);
            }

            var activeSet = new HashSet <uint>();

            foreach (MpLayer_v1002 layer in LayerList)
            {
                foreach (uint id in layer.FigureIdList)
                {
                    MpFigure_v1002 fig = idMap[id];

                    fig.ForEachFigID(idMap, (a) =>
                    {
                        activeSet.Add(a);
                    });
                }
            }

            int i = FigureList.Count - 1;

            for (; i >= 0; i--)
            {
                MpFigure_v1002 fig = FigureList[i];

                if (!activeSet.Contains(fig.ID))
                {
                    FigureList.RemoveAt(i);
                }
            }
        }