markus / KCOM / Events / PasteCommand.cs @ 16231f58
이력 | 보기 | 이력해설 | 다운로드 (10.6 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 System; |
||
11 | using System.Collections; |
||
12 | using System.Collections.Generic; |
||
13 | using System.ComponentModel; |
||
14 | using System.Data; |
||
15 | using System.IO; |
||
16 | using System.Linq; |
||
17 | using System.Reflection; |
||
18 | using System.Runtime.Serialization.Formatters; |
||
19 | using System.Runtime.Serialization.Formatters.Binary; |
||
20 | using System.Runtime.Serialization.Json; |
||
21 | using System.Text; |
||
22 | using System.Windows; |
||
23 | using System.Windows.Media; |
||
24 | using System.Windows.Media.Imaging; |
||
25 | using System.Xml; |
||
26 | using System.Xml.Serialization; |
||
27 | |||
28 | namespace KCOM |
||
29 | { |
||
30 | public class PasteCommand |
||
31 | { |
||
32 | private static readonly PasteCommand _instance = new PasteCommand(); |
||
33 | |||
34 | // Explicit static constructor to tell C# compiler |
||
35 | // not to mark type as beforefieldinit |
||
36 | static PasteCommand() |
||
37 | { |
||
38 | } |
||
39 | |||
40 | private PasteCommand() |
||
41 | { |
||
42 | } |
||
43 | |||
44 | public static PasteCommand Instance |
||
45 | { |
||
46 | get |
||
47 | { |
||
48 | return _instance; |
||
49 | } |
||
50 | } |
||
51 | /// <summary> |
||
52 | /// paste controls |
||
53 | /// </summary> |
||
54 | /// <author>humkyung</author> |
||
55 | /// <date>2019.06.18</date> |
||
56 | /// <param name="comments"></param> |
||
57 | ac4f1e13 | taeseongkim | public async void Execute() |
58 | b37ef4b3 | humkyung | { |
59 | 5b48dae7 | taeseongkim | var markupData = Clipboard.GetData(DataFormats.StringFormat); |
60 | |||
61 | if (markupData?.ToString().Contains("|OR||DZ|") == true) |
||
62 | b37ef4b3 | humkyung | { |
63 | 26ec6226 | taeseongkim | string[] delimiterChars = { "|OR|" }; |
64 | string[] delimiterChars2 = { "|OR|", "|SymbolID|" }; |
||
65 | 5b48dae7 | taeseongkim | string[] data = markupData.ToString().Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); |
66 | 26ec6226 | taeseongkim | |
67 | 02a9f323 | humkyung | if (data.Any()) |
68 | 26ec6226 | taeseongkim | { |
69 | List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>(); |
||
70 | |||
71 | //강인구 Undo/Redo 보류 |
||
72 | 02a9f323 | humkyung | MarkupToPDF.Common.UndoDataGroup UndoDataGrp = new UndoDataGroup() |
73 | 26ec6226 | taeseongkim | { |
74 | IsUndo = false, |
||
75 | 02a9f323 | humkyung | Event = EventType.Create |
76 | 26ec6226 | taeseongkim | }; |
77 | |||
78 | foreach (string parse in data) |
||
79 | { |
||
80 | if (parse != "") |
||
81 | { |
||
82 | string[] data2 = new string[2]; |
||
83 | data2 = parse.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
84 | |||
85 | 58dd9e89 | humkyung | System.Windows.Controls.Control item = await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, data2[0], ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, "#FFFF0000", string.Empty, |
86 | STAMP_Contents: App.SystemInfo.STAMP_CONTENTS); |
||
87 | 26ec6226 | taeseongkim | |
88 | var control = (item as MarkupToPDF.Common.CommentUserInfo); |
||
89 | |||
90 | 5a223b60 | humkyung | control.CommentID = Commons.ShortGuid(); |
91 | 26ec6226 | taeseongkim | control.MarkupInfoID = App.Custom_ViewInfoId; |
92 | control.IsNew = true; |
||
93 | |||
94 | if (data2.Length >= 2) |
||
95 | { |
||
96 | control.SymbolID = data2[1]; |
||
97 | } |
||
98 | |||
99 | //CreateCommand.Instance.Execute(control); |
||
100 | adornerSet.Add(control); |
||
101 | 19d602e0 | humkyung | var UndoData = new UndoData(control); |
102 | UndoDataGrp.MarkupDataColl.Add(UndoData); |
||
103 | 02a9f323 | humkyung | ViewerDataModel.Instance.UndoDataList.Add(UndoDataGrp); |
104 | 26ec6226 | taeseongkim | |
105 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.UpdateMyMarkupList(); |
||
106 | //ViewerDataModel.Instance.MarkupControls_USER.Remove(control); |
||
107 | |||
108 | ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
||
109 | 19d602e0 | humkyung | MarkupParser.MarkupToString(UndoData.Markup, App.ViewInfo.UserID), EventType.Create, null, null); |
110 | 26ec6226 | taeseongkim | } |
111 | } |
||
112 | |||
113 | Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet); |
||
114 | |||
115 | /// 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 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
||
120 | } |
||
121 | } |
||
122 | /// 외부 이미지 붙여넣기 |
||
123 | else if (Clipboard.GetImage() != null) |
||
124 | { |
||
125 | try |
||
126 | { |
||
127 | 02a9f323 | humkyung | MarkupToPDF.Common.UndoDataGroup UndoDataGrp = new UndoDataGroup() |
128 | 26ec6226 | taeseongkim | { |
129 | IsUndo = false, |
||
130 | 02a9f323 | humkyung | Event = EventType.Create |
131 | 26ec6226 | taeseongkim | }; |
132 | |||
133 | string temppath = System.IO.Path.GetTempPath(); |
||
134 | 5a223b60 | humkyung | string filename = Commons.ShortFileKey(); |
135 | 26ec6226 | taeseongkim | |
136 | System.Drawing.Image clipboardImage = System.Windows.Forms.Clipboard.GetImage(); |
||
137 | clipboardImage.Save(Path.Combine(temppath, filename)); |
||
138 | |||
139 | /// upload image file to server |
||
140 | System.IO.FileInfo fileInfo = new System.IO.FileInfo(Path.Combine(temppath, filename)); |
||
141 | String strFile = System.IO.Path.GetFileName(fileInfo.FullName); |
||
142 | long numByte = fileInfo.Length; |
||
143 | double dLen = Convert.ToDouble(fileInfo.Length / 1000000); |
||
144 | kr.co.devdoftech.cloud.FileUpload fileUploader = App.FileUploader; |
||
145 | if (dLen < 4) |
||
146 | { |
||
147 | System.IO.FileStream fStream = new System.IO.FileStream(fileInfo.FullName, |
||
148 | System.IO.FileMode.Open, System.IO.FileAccess.Read, FileShare.Read); |
||
149 | System.IO.BinaryReader br = new System.IO.BinaryReader(fStream); |
||
150 | byte[] data = br.ReadBytes((int)numByte); |
||
151 | |||
152 | filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, strFile + ".png", data); |
||
153 | Check_Uri.UriCheck(filename); |
||
154 | |||
155 | br.Close(); |
||
156 | fStream.Close(); |
||
157 | fStream.Dispose(); |
||
158 | } |
||
159 | else |
||
160 | { |
||
161 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("Available Memory less than 4 mega byte", "Alert"); |
||
162 | return; |
||
163 | } |
||
164 | |||
165 | fileInfo.Delete(); |
||
166 | |||
167 | System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(clipboardImage); |
||
168 | IntPtr hBitmap = bmp.GetHbitmap(); |
||
169 | System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); |
||
170 | System.Windows.Controls.Image img = new System.Windows.Controls.Image(); |
||
171 | if (filename.Contains(".svg")) |
||
172 | { |
||
173 | SharpVectors.Converters.SvgImageExtension svgImage = new SharpVectors.Converters.SvgImageExtension(filename); |
||
174 | img.Source = (DrawingImage)svgImage.ProvideValue(null); |
||
175 | } |
||
176 | else |
||
177 | { |
||
178 | img.Source = new BitmapImage(new Uri(filename)); |
||
179 | } |
||
180 | |||
181 | |||
182 | var vecSize = new Vector(clipboardImage.Width, clipboardImage.Height); |
||
183 | var EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize); |
||
184 | var currentControl = new MarkupToPDF.Controls.Etc.ImgControl |
||
185 | { |
||
186 | PointSet = new List<Point>(), |
||
187 | FilePath = filename, |
||
188 | ImageData = img.Source, |
||
189 | StartPoint = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, |
||
190 | EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize), |
||
191 | TopRightPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X + vecSize.X, |
||
192 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y), |
||
193 | LeftBottomPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X, |
||
194 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y + vecSize.Y) |
||
195 | }; |
||
196 | |||
197 | currentControl.PointSet = new List<Point> |
||
198 | { |
||
199 | currentControl.StartPoint, |
||
200 | currentControl.LeftBottomPoint, |
||
201 | currentControl.EndPoint, |
||
202 | currentControl.TopRightPoint, |
||
203 | }; |
||
204 | |||
205 | 19d602e0 | humkyung | var UndoData = new UndoData(currentControl as MarkupToPDF.Common.CommentUserInfo); |
206 | UndoDataGrp.MarkupDataColl.Add(UndoData); |
||
207 | 02a9f323 | humkyung | ViewerDataModel.Instance.UndoDataList.Add(UndoDataGrp); |
208 | b37ef4b3 | humkyung | |
209 | ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo); |
||
210 | 5a223b60 | humkyung | currentControl.CommentID = Commons.ShortGuid(); |
211 | b37ef4b3 | humkyung | |
212 | currentControl.ApplyTemplate(); |
||
213 | currentControl.SetImage(); |
||
214 | |||
215 | ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo); |
||
216 | Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo); |
||
217 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
||
218 | 4eb052e4 | ljiyeon | |
219 | 39f0624f | ljiyeon | ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
220 | 19d602e0 | humkyung | MarkupParser.MarkupToString(UndoData.Markup, App.ViewInfo.UserID), EventType.Create, null, null); |
221 | b37ef4b3 | humkyung | } |
222 | catch (Exception ex) |
||
223 | { |
||
224 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert"); |
||
225 | } |
||
226 | } |
||
227 | } |
||
228 | } |
||
229 | } |