markus / KCOM / Events / PasteCommand.cs @ 2184f659
이력 | 보기 | 이력해설 | 다운로드 (10.7 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 |
/// place controls at current mouse position |
113 |
var diff = Point.Subtract(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, final.Centeroid); |
114 |
final.TranslateItems(diff.X, diff.Y); |
115 |
|
116 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
117 |
} |
118 |
/// 외부 이미지 붙여넣기 |
119 |
else if (Clipboard.GetImage() != null) |
120 |
{ |
121 |
try |
122 |
{ |
123 |
Multi_Undo_data multi_Undo_Data = new Multi_Undo_data(); |
124 |
|
125 |
MarkupToPDF.Common.Undo_data UndoData = new Undo_data() |
126 |
{ |
127 |
IsUndo = false, |
128 |
Event = Event_Type.Create, |
129 |
EventTime = DateTime.Now, |
130 |
Markup_List = new List<Multi_Undo_data>() |
131 |
}; |
132 |
|
133 |
string temppath = System.IO.Path.GetTempPath(); |
134 |
string filename = Commons.shortFileKey(); |
135 |
|
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 = new kr.co.devdoftech.cloud.FileUpload(); |
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); |
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 |
byte[] imageData = null; |
174 |
DrawingImage image = null; |
175 |
using (System.Net.WebClient web = new System.Net.WebClient()) |
176 |
{ |
177 |
imageData = web.DownloadData(new Uri(filename)); |
178 |
System.IO.Stream stream = new System.IO.MemoryStream(imageData); |
179 |
image = SvgReader.Load(stream); |
180 |
} |
181 |
img.Source = image; |
182 |
} |
183 |
else |
184 |
{ |
185 |
img.Source = new BitmapImage(new Uri(filename)); |
186 |
} |
187 |
|
188 |
|
189 |
var vecSize = new Vector(clipboardImage.Width, clipboardImage.Height); |
190 |
var EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize); |
191 |
var currentControl = new MarkupToPDF.Controls.Etc.ImgControl |
192 |
{ |
193 |
PointSet = new List<Point>(), |
194 |
FilePath = filename, |
195 |
ImageData = img.Source, |
196 |
StartPoint = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, |
197 |
EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize), |
198 |
TopRightPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X + vecSize.X, |
199 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y), |
200 |
LeftBottomPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X, |
201 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y + vecSize.Y) |
202 |
}; |
203 |
|
204 |
currentControl.PointSet = new List<Point> |
205 |
{ |
206 |
currentControl.StartPoint, |
207 |
currentControl.LeftBottomPoint, |
208 |
currentControl.EndPoint, |
209 |
currentControl.TopRightPoint, |
210 |
}; |
211 |
|
212 |
multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo); |
213 |
UndoData.Markup_List.Add(multi_Undo_Data); |
214 |
ViewerDataModel.Instance.UndoDataList.Add(UndoData); |
215 |
|
216 |
ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo); |
217 |
currentControl.CommentID = Commons.shortGuid(); |
218 |
|
219 |
currentControl.ApplyTemplate(); |
220 |
currentControl.SetImage(); |
221 |
|
222 |
ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo); |
223 |
Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo); |
224 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
225 |
} |
226 |
catch (Exception ex) |
227 |
{ |
228 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert"); |
229 |
} |
230 |
} |
231 |
} |
232 |
} |
233 |
} |