프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / Events / UndoCommand.cs @ 19d602e0

이력 | 보기 | 이력해설 | 다운로드 (5.84 KB)

1
using MarkupToPDF.Common;
2
using MarkupToPDF.Controls.Common;
3
using MarkupToPDF.Controls.Line;
4
using MarkupToPDF.Controls.Polygon;
5
using MarkupToPDF.Controls.Shape;
6
using MarkupToPDF.Controls.Text;
7
using MarkupToPDF.Controls.Etc;
8
using System;
9
using System.Collections.Generic;
10
using System.Linq;
11
using System.Text;
12
using System.Windows;
13
using System.Windows.Controls;
14
using System.Windows.Media;
15
using MarkupToPDF.Controls.Cad;
16
using KCOM.Common;
17
using KCOM.Controls;
18
using MarkupToPDF.Controls.Parsing;
19

    
20
namespace KCOM.Events
21
{
22
    public class UndoCommand
23
    {
24
        private static readonly UndoCommand _instance = new UndoCommand();
25

    
26
        // Explicit static constructor to tell C# compiler
27
        // not to mark type as beforefieldinit
28
        static UndoCommand()
29
        {
30
        }
31

    
32
        private UndoCommand()
33
        {
34
        }
35

    
36
        public static UndoCommand Instance
37
        {
38
            get
39
            {
40
                return _instance;
41
            }
42
        }
43

    
44
        /// <summary>
45
        /// push undo data
46
        /// </summary>
47
        /// <author>humkyung</author>
48
        /// <date>2019.06.14, 2024.04.26</date>
49
        /// <param name="comments"></param>
50
        public void Push(EventType _EventType, ICollection<CommentUserInfo> comments)
51
        {
52
            UndoDataGroup UndoDataGrp = new UndoDataGroup()
53
            {
54
                IsUndo = false,
55
                Event = _EventType
56
            };
57

    
58
            foreach (var comment in comments)
59
            {
60
                UndoData _UndoData = new UndoData(comment);
61
                _UndoData.Clone = comment.Clone();
62
                UndoDataGrp.MarkupDataColl.Add(_UndoData);
63

    
64
                if (_EventType == EventType.Delete)
65
                {
66
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(comment);
67
                    ViewerDataModel.Instance.MarkupControls.Remove(comment);
68

    
69
                    var Item_ = ViewerDataModel.Instance.MyMarkupList.Find(d => d.ID == comment.CommentID);
70
                    ViewerDataModel.Instance.MyMarkupList.Remove(Item_);
71

    
72
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
73
                        null, EventType.Delete, MarkupParser.MarkupToString(_UndoData.Markup, App.ViewInfo.UserID).CommentID, null);
74
                }
75
                else
76
                {
77
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
78
                        MarkupParser.MarkupToString(_UndoData.Markup, App.ViewInfo.UserID), EventType.Operation, null, null);
79
                }
80
            }
81

    
82
            ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo).ToList().ForEach(i =>
83
            {
84
                ViewerDataModel.Instance.UndoDataList.Remove(i);
85
            });
86
            ViewerDataModel.Instance.UndoDataList.Add(UndoDataGrp);
87
        }
88

    
89
        /// <summary>
90
        /// undo 실행
91
        /// </summary>
92
        public void Execute()
93
        {
94
            AdornerFinal final;
95
            SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
96

    
97
            UndoDataGroup undo = ViewerDataModel.Instance.UndoDataList.Where(data => !data.IsUndo).ToList()
98
                .OrderByDescending(order => order.EventTime).FirstOrDefault();
99
            if (undo == null) return;
100

    
101
            switch (undo.Event)
102
            {
103
                case (EventType.Create):
104
                    {
105
                        foreach (var item in undo.MarkupDataColl)
106
                        {
107
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
108

    
109
                            ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
110
                            null, EventType.Delete, item.Markup.CommentID, null);
111
                        }
112
                    }
113
                    break;
114
                case (EventType.Delete):
115
                    {
116
                        List<CommentUserInfo> comments = new List<CommentUserInfo>();
117
                        foreach (var item in undo.MarkupDataColl)
118
                        {
119
                            item.Markup.Load();
120
                            item.Markup.UpdateControl();
121
                            comments.Add(item.Markup);
122
                        }
123

    
124
                        var adorner = new AdornerFinal(comments);
125
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(adorner);
126
                        ///SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
127
                    }
128
                    break;
129
                case (EventType.Operation):
130
                    {
131
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
132

    
133
                        foreach (var item in undo.MarkupDataColl)
134
                        {
135
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item.Markup);
136

    
137
                            var tmp = item.Markup.Clone();
138
                            item.Markup.Copy(item.Clone);
139
                            item.Clone.Copy(tmp);
140
                            item.Markup.UpdateControl();
141

    
142
                            comment.Add(item.Markup);
143
                        }
144
                        var adoner = new AdornerFinal(comment);
145
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(adoner);
146
                        ///SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
147
                    }
148
                    break;
149
            }
150

    
151
            ViewerDataModel.Instance.UndoDataList.Where(data => data.EventTime == undo.EventTime).ToList()
152
                .OrderByDescending(order => order.EventTime).ToList().ForEach(i =>
153
            {
154
                i.IsUndo = true;
155
            });
156
        }
157
    }
158
}
클립보드 이미지 추가 (최대 크기: 500 MB)