프로젝트

일반

사용자정보

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

markus / KCOM / Events / PasteCommand.cs @ b37ef4b3

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

1
using KCOM.Common;
2
using KCOM.Controls;
3
using KCOM.Views;
4
using MarkupToPDF.Common;
5
using MarkupToPDF.Controls.Parsing;
6
using Newtonsoft.Json;
7
using Newtonsoft.Json.Converters;
8
using Newtonsoft.Json.Linq;
9
using Newtonsoft.Json.Serialization;
10
using Svg2Xaml;
11
using System;
12
using System.Collections;
13
using System.Collections.Generic;
14
using System.ComponentModel;
15
using System.Data;
16
using System.IO;
17
using System.Linq;
18
using System.Reflection;
19
using System.Runtime.Serialization.Formatters;
20
using System.Runtime.Serialization.Formatters.Binary;
21
using System.Runtime.Serialization.Json;
22
using System.Text;
23
using System.Windows;
24
using System.Windows.Media;
25
using System.Windows.Media.Imaging;
26
using System.Xml;
27
using System.Xml.Serialization;
28

    
29
namespace KCOM
30
{
31
    public class PasteCommand
32
    {
33
        private static readonly PasteCommand _instance = new PasteCommand();
34

    
35
        // Explicit static constructor to tell C# compiler
36
        // not to mark type as beforefieldinit
37
        static PasteCommand()
38
        {
39
        }
40

    
41
        private PasteCommand()
42
        {
43
        }
44

    
45
        public static PasteCommand Instance
46
        {
47
            get
48
            {
49
                return _instance;
50
            }
51
        }
52

    
53
        /// <summary>
54
        /// paste controls
55
        /// </summary>
56
        /// <author>humkyung</author>
57
        /// <date>2019.06.18</date>
58
        /// <param name="comments"></param>
59
        public void Execute()
60
        {
61
            if (Clipboard.GetText().Contains("|OR||DZ|"))
62
            {
63
                List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
64

    
65
                SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
66

    
67
                Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
68

    
69
                //강인구 Undo/Redo 보류
70
                MarkupToPDF.Common.Undo_data UndoData = new Undo_data()
71
                {
72
                    IsUndo = false,
73
                    Event = Event_Type.Create,
74
                    EventTime = DateTime.Now,
75
                    Markup_List = new List<Multi_Undo_data>()
76
                };
77

    
78
                ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i =>
79
                {
80
                    ViewerDataModel.Instance.UndoDataList.Remove(i);
81
                });
82

    
83
                string[] delimiterChars = { "|OR|" };
84
                string[] delimiterChars2 = { "|OR|", "|SymbolID|" };
85
                string[] data = Clipboard.GetText().Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
86
                foreach (string parse in data)
87
                {
88
                    if (parse != "")
89
                    {
90
                        string[] data2 = new string[2];
91
                        data2 = parse.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
92

    
93
                        System.Windows.Controls.Control item = MarkupParser.ParseEx(App.ViewInfo.ProjectNO, data2[0], ViewerDataModel.Instance.MarkupControls_USER, string.Empty, string.Empty);
94
                        (item as MarkupToPDF.Common.CommentUserInfo).CommentID = Commons.shortGuid();
95
                        if (data2.Length >= 2)
96
                        {
97
                            (item as MarkupToPDF.Common.CommentUserInfo).SymbolID = data2[1];
98
                        }
99
                        ViewerDataModel.Instance.MarkupControls.Remove(item as MarkupToPDF.Common.CommentUserInfo);
100
                        ViewerDataModel.Instance.MarkupControls_USER.Remove(item as MarkupToPDF.Common.CommentUserInfo);
101

    
102
                        adornerSet.Add(item as MarkupToPDF.Common.CommentUserInfo);
103

    
104
                        multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(item as MarkupToPDF.Common.CommentUserInfo);
105

    
106
                        UndoData.Markup_List.Add(multi_Undo_Data);
107
                        ViewerDataModel.Instance.UndoDataList.Add(UndoData);
108
                    }
109
                }
110
                Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
111

    
112
                double realPointX = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X - final.BorderSize.X - (final.BorderSize.Width / 2);
113
                double realPointY = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y - final.BorderSize.Y - (final.BorderSize.Height / 2);
114
                final.MoveAdorner(new System.Windows.Controls.Primitives.DragDeltaEventArgs(realPointX, realPointY));
115

    
116
                if (final.Members.Where(type => type.Drawingtype == MarkupToPDF.Controls.Common.ControlType.TextControl).FirstOrDefault() != null)
117
                {
118
                    final.MoveAdorner(new System.Windows.Controls.Primitives.DragDeltaEventArgs(0.001, 0.001)); //dummy
119
                }
120

    
121
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
122
            }
123
            /// 외부 이미지 붙여넣기
124
            else if (Clipboard.GetImage() != null)
125
            {
126
                try
127
                {
128
                    Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
129

    
130
                    MarkupToPDF.Common.Undo_data UndoData = new Undo_data()
131
                    {
132
                        IsUndo = false,
133
                        Event = Event_Type.Create,
134
                        EventTime = DateTime.Now,
135
                        Markup_List = new List<Multi_Undo_data>()
136
                    };
137

    
138
                    string temppath = System.IO.Path.GetTempPath();
139
                    string filename = Commons.shortFileKey();
140

    
141
                    System.Drawing.Image clipboardImage = System.Windows.Forms.Clipboard.GetImage();
142
                    clipboardImage.Save(Path.Combine(temppath , filename));
143

    
144
                    /// upload image file to server
145
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(Path.Combine(temppath , filename));
146
                    String strFile = System.IO.Path.GetFileName(fileInfo.FullName);
147
                    long numByte = fileInfo.Length;
148
                    double dLen = Convert.ToDouble(fileInfo.Length / 1000000);
149
                    kr.co.devdoftech.cloud.FileUpload fileUploader = new kr.co.devdoftech.cloud.FileUpload();
150
                    if (dLen < 4)
151
                    {
152
                        System.IO.FileStream fStream = new System.IO.FileStream(fileInfo.FullName,
153
                        System.IO.FileMode.Open, System.IO.FileAccess.Read);
154
                        System.IO.BinaryReader br = new System.IO.BinaryReader(fStream);
155
                        byte[] data = br.ReadBytes((int)numByte);
156

    
157
                        filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, strFile + ".png", data);
158

    
159
                        Check_Uri.UriCheck(filename);
160

    
161
                        br.Close();
162
                        fStream.Close();
163
                        fStream.Dispose();
164
                    }
165
                    else
166
                    {
167
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("Available Memory less than 4 mega byte", "Alert");
168
                        return;
169
                    }
170

    
171
                    fileInfo.Delete();
172

    
173
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(clipboardImage);
174
                    IntPtr hBitmap = bmp.GetHbitmap();
175
                    System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
176
                    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
177
                    if (filename.Contains(".svg"))
178
                    {
179
                        byte[] imageData = null;
180
                        DrawingImage image = null;
181
                        using (System.Net.WebClient web = new System.Net.WebClient())
182
                        {
183
                            imageData = web.DownloadData(new Uri(filename));
184
                            System.IO.Stream stream = new System.IO.MemoryStream(imageData);
185
                            image = SvgReader.Load(stream);
186
                        }
187
                        img.Source = image;
188
                    }
189
                    else
190
                    {
191
                        img.Source = new BitmapImage(new Uri(filename));
192
                    }
193
                    var currentControl = new MarkupToPDF.Controls.Etc.ImgControl
194
                    {
195
                        PointSet = new List<Point>(),
196
                        FilePath = filename,
197
                        ImageData = img.Source,
198
                        StartPoint = new Point(100, 100),
199
                        EndPoint = new Point(200, 200),
200
                        TopRightPoint = new Point(100, 200),
201
                        LeftBottomPoint = new Point(200, 100)
202
                    };
203

    
204
                    currentControl.TopRightPoint = new Point(currentControl.StartPoint.X + clipboardImage.Width, currentControl.StartPoint.Y);
205
                    currentControl.LeftBottomPoint = new Point(currentControl.StartPoint.X, currentControl.StartPoint.Y + clipboardImage.Height);
206
                    currentControl.EndPoint = new Point(currentControl.StartPoint.X + clipboardImage.Width, currentControl.StartPoint.Y + clipboardImage.Height);
207

    
208
                    currentControl.PointSet = new List<Point>
209
                                        {
210
                                            currentControl.StartPoint,
211
                                            currentControl.LeftBottomPoint,
212
                                            currentControl.EndPoint,
213
                                            currentControl.TopRightPoint,
214
                                        };
215

    
216
                    multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo);
217
                    UndoData.Markup_List.Add(multi_Undo_Data);
218
                    ViewerDataModel.Instance.UndoDataList.Add(UndoData);
219

    
220
                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo);
221
                    currentControl.CommentID = Commons.shortGuid();
222

    
223
                    currentControl.ApplyTemplate();
224
                    currentControl.SetImage();
225

    
226
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo);
227
                    Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo);
228
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
229

    
230
                    double realPointX = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X - final.BorderSize.X - (final.BorderSize.Width / 2);
231
                    double realPointY = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y - final.BorderSize.Y - (final.BorderSize.Height / 2);
232
                    final.MoveAdorner(new System.Windows.Controls.Primitives.DragDeltaEventArgs(realPointX, realPointY));
233
                }
234
                catch (Exception ex)
235
                {
236
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert");
237
                }
238
            }
239
        }
240
    }
241
}
클립보드 이미지 추가 (최대 크기: 500 MB)