markus / KCOM / Events / PasteCommand.cs @ 95c73392
이력 | 보기 | 이력해설 | 다운로드 (10.9 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 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 |
|
52 |
/// <summary> |
53 |
/// paste controls |
54 |
/// </summary> |
55 |
/// <author>humkyung</author> |
56 |
/// <date>2019.06.18</date> |
57 |
/// <param name="comments"></param> |
58 |
public async void Execute() |
59 |
{ |
60 |
if (Clipboard.GetText().Contains("|OR||DZ|")) |
61 |
{ |
62 |
List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>(); |
63 |
|
64 |
SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu); |
65 |
|
66 |
Multi_Undo_data multi_Undo_Data = new Multi_Undo_data(); |
67 |
|
68 |
//강인구 Undo/Redo 보류 |
69 |
MarkupToPDF.Common.Undo_data UndoData = new Undo_data() |
70 |
{ |
71 |
IsUndo = false, |
72 |
Event = Event_Type.Create, |
73 |
EventTime = DateTime.Now, |
74 |
Markup_List = new List<Multi_Undo_data>() |
75 |
}; |
76 |
|
77 |
ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i => |
78 |
{ |
79 |
ViewerDataModel.Instance.UndoDataList.Remove(i); |
80 |
}); |
81 |
|
82 |
string[] delimiterChars = { "|OR|" }; |
83 |
string[] delimiterChars2 = { "|OR|", "|SymbolID|" }; |
84 |
string[] data = Clipboard.GetText().Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); |
85 |
foreach (string parse in data) |
86 |
{ |
87 |
if (parse != "") |
88 |
{ |
89 |
string[] data2 = new string[2]; |
90 |
data2 = parse.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
91 |
|
92 |
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); |
93 |
(item as MarkupToPDF.Common.CommentUserInfo).CommentID = Commons.shortGuid(); |
94 |
if (data2.Length >= 2) |
95 |
{ |
96 |
(item as MarkupToPDF.Common.CommentUserInfo).SymbolID = data2[1]; |
97 |
} |
98 |
ViewerDataModel.Instance.MarkupControls.Remove(item as MarkupToPDF.Common.CommentUserInfo); |
99 |
ViewerDataModel.Instance.MarkupControls_USER.Remove(item as MarkupToPDF.Common.CommentUserInfo); |
100 |
|
101 |
adornerSet.Add(item as MarkupToPDF.Common.CommentUserInfo); |
102 |
|
103 |
multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(item as MarkupToPDF.Common.CommentUserInfo); |
104 |
|
105 |
UndoData.Markup_List.Add(multi_Undo_Data); |
106 |
ViewerDataModel.Instance.UndoDataList.Add(UndoData); |
107 |
|
108 |
ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
109 |
MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null); |
110 |
} |
111 |
} |
112 |
Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet); |
113 |
|
114 |
/// place controls at current mouse position |
115 |
var diff = Point.Subtract(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, final.Centeroid); |
116 |
final.TranslateItems(diff.X, diff.Y); |
117 |
|
118 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
119 |
|
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 = App.FileUploader; |
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,FileShare.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 |
SharpVectors.Converters.SvgImageExtension svgImage = new SharpVectors.Converters.SvgImageExtension(filename); |
177 |
img.Source = (DrawingImage)svgImage.ProvideValue(null); |
178 |
} |
179 |
else |
180 |
{ |
181 |
img.Source = new BitmapImage(new Uri(filename)); |
182 |
} |
183 |
|
184 |
|
185 |
var vecSize = new Vector(clipboardImage.Width, clipboardImage.Height); |
186 |
var EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize); |
187 |
var currentControl = new MarkupToPDF.Controls.Etc.ImgControl |
188 |
{ |
189 |
PointSet = new List<Point>(), |
190 |
FilePath = filename, |
191 |
ImageData = img.Source, |
192 |
StartPoint = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, |
193 |
EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize), |
194 |
TopRightPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X + vecSize.X, |
195 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y), |
196 |
LeftBottomPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X, |
197 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y + vecSize.Y) |
198 |
}; |
199 |
|
200 |
currentControl.PointSet = new List<Point> |
201 |
{ |
202 |
currentControl.StartPoint, |
203 |
currentControl.LeftBottomPoint, |
204 |
currentControl.EndPoint, |
205 |
currentControl.TopRightPoint, |
206 |
}; |
207 |
|
208 |
multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo); |
209 |
UndoData.Markup_List.Add(multi_Undo_Data); |
210 |
ViewerDataModel.Instance.UndoDataList.Add(UndoData); |
211 |
|
212 |
ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo); |
213 |
currentControl.CommentID = Commons.shortGuid(); |
214 |
|
215 |
currentControl.ApplyTemplate(); |
216 |
currentControl.SetImage(); |
217 |
|
218 |
ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo); |
219 |
Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo); |
220 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
221 |
|
222 |
ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
223 |
MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null); |
224 |
} |
225 |
catch (Exception ex) |
226 |
{ |
227 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert"); |
228 |
} |
229 |
} |
230 |
} |
231 |
} |
232 |
} |