markus / KCOM / Events / PasteCommand.cs @ e0f00e26
이력 | 보기 | 이력해설 | 다운로드 (11.1 KB)
1 | b37ef4b3 | humkyung | 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 | 4eb052e4 | ljiyeon | |
109 | ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.markupListUpdate( |
||
110 | MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null); |
||
111 | b37ef4b3 | humkyung | } |
112 | } |
||
113 | Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet); |
||
114 | |||
115 | 025ebf74 | humkyung | /// place controls at current mouse position |
116 | var diff = Point.Subtract(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, final.Centeroid); |
||
117 | final.TranslateItems(diff.X, diff.Y); |
||
118 | |||
119 | b37ef4b3 | humkyung | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
120 | } |
||
121 | /// 외부 이미지 붙여넣기 |
||
122 | else if (Clipboard.GetImage() != null) |
||
123 | { |
||
124 | try |
||
125 | { |
||
126 | Multi_Undo_data multi_Undo_Data = new Multi_Undo_data(); |
||
127 | |||
128 | MarkupToPDF.Common.Undo_data UndoData = new Undo_data() |
||
129 | { |
||
130 | IsUndo = false, |
||
131 | Event = Event_Type.Create, |
||
132 | EventTime = DateTime.Now, |
||
133 | Markup_List = new List<Multi_Undo_data>() |
||
134 | }; |
||
135 | |||
136 | string temppath = System.IO.Path.GetTempPath(); |
||
137 | string filename = Commons.shortFileKey(); |
||
138 | |||
139 | System.Drawing.Image clipboardImage = System.Windows.Forms.Clipboard.GetImage(); |
||
140 | clipboardImage.Save(Path.Combine(temppath , filename)); |
||
141 | |||
142 | /// upload image file to server |
||
143 | System.IO.FileInfo fileInfo = new System.IO.FileInfo(Path.Combine(temppath , filename)); |
||
144 | String strFile = System.IO.Path.GetFileName(fileInfo.FullName); |
||
145 | long numByte = fileInfo.Length; |
||
146 | double dLen = Convert.ToDouble(fileInfo.Length / 1000000); |
||
147 | kr.co.devdoftech.cloud.FileUpload fileUploader = new kr.co.devdoftech.cloud.FileUpload(); |
||
148 | if (dLen < 4) |
||
149 | { |
||
150 | System.IO.FileStream fStream = new System.IO.FileStream(fileInfo.FullName, |
||
151 | System.IO.FileMode.Open, System.IO.FileAccess.Read); |
||
152 | System.IO.BinaryReader br = new System.IO.BinaryReader(fStream); |
||
153 | byte[] data = br.ReadBytes((int)numByte); |
||
154 | |||
155 | filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, strFile + ".png", data); |
||
156 | Check_Uri.UriCheck(filename); |
||
157 | |||
158 | br.Close(); |
||
159 | fStream.Close(); |
||
160 | fStream.Dispose(); |
||
161 | } |
||
162 | else |
||
163 | { |
||
164 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("Available Memory less than 4 mega byte", "Alert"); |
||
165 | return; |
||
166 | } |
||
167 | |||
168 | fileInfo.Delete(); |
||
169 | |||
170 | System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(clipboardImage); |
||
171 | IntPtr hBitmap = bmp.GetHbitmap(); |
||
172 | System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); |
||
173 | System.Windows.Controls.Image img = new System.Windows.Controls.Image(); |
||
174 | if (filename.Contains(".svg")) |
||
175 | { |
||
176 | byte[] imageData = null; |
||
177 | DrawingImage image = null; |
||
178 | using (System.Net.WebClient web = new System.Net.WebClient()) |
||
179 | { |
||
180 | imageData = web.DownloadData(new Uri(filename)); |
||
181 | System.IO.Stream stream = new System.IO.MemoryStream(imageData); |
||
182 | image = SvgReader.Load(stream); |
||
183 | } |
||
184 | img.Source = image; |
||
185 | } |
||
186 | else |
||
187 | { |
||
188 | img.Source = new BitmapImage(new Uri(filename)); |
||
189 | } |
||
190 | 2184f659 | humkyung | |
191 | |||
192 | var vecSize = new Vector(clipboardImage.Width, clipboardImage.Height); |
||
193 | var EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize); |
||
194 | b37ef4b3 | humkyung | var currentControl = new MarkupToPDF.Controls.Etc.ImgControl |
195 | { |
||
196 | PointSet = new List<Point>(), |
||
197 | FilePath = filename, |
||
198 | ImageData = img.Source, |
||
199 | 2184f659 | humkyung | StartPoint = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, |
200 | EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize), |
||
201 | TopRightPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X + vecSize.X, |
||
202 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y), |
||
203 | LeftBottomPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X, |
||
204 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y + vecSize.Y) |
||
205 | b37ef4b3 | humkyung | }; |
206 | |||
207 | currentControl.PointSet = new List<Point> |
||
208 | 2184f659 | humkyung | { |
209 | currentControl.StartPoint, |
||
210 | currentControl.LeftBottomPoint, |
||
211 | currentControl.EndPoint, |
||
212 | currentControl.TopRightPoint, |
||
213 | }; |
||
214 | b37ef4b3 | humkyung | |
215 | multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo); |
||
216 | UndoData.Markup_List.Add(multi_Undo_Data); |
||
217 | ViewerDataModel.Instance.UndoDataList.Add(UndoData); |
||
218 | |||
219 | ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo); |
||
220 | currentControl.CommentID = Commons.shortGuid(); |
||
221 | |||
222 | currentControl.ApplyTemplate(); |
||
223 | currentControl.SetImage(); |
||
224 | |||
225 | ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo); |
||
226 | Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo); |
||
227 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
||
228 | 4eb052e4 | ljiyeon | |
229 | ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.markupListUpdate( |
||
230 | MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null); |
||
231 | b37ef4b3 | humkyung | } |
232 | catch (Exception ex) |
||
233 | { |
||
234 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert"); |
||
235 | } |
||
236 | } |
||
237 | } |
||
238 | } |
||
239 | } |