markus / KCOM / Controls / Symbol.xaml.cs @ 787a4489
이력 | 보기 | 이력해설 | 다운로드 (7.55 KB)
1 | 787a4489 | KangIngu | using KCOM.Common; |
---|---|---|---|
2 | using KCOM.Events; |
||
3 | using System; |
||
4 | using System.Collections.Generic; |
||
5 | using System.Linq; |
||
6 | using System.Text; |
||
7 | using System.Windows; |
||
8 | using System.Windows.Controls; |
||
9 | using System.Windows.Data; |
||
10 | using System.Windows.Documents; |
||
11 | using System.Windows.Input; |
||
12 | using System.Windows.Media; |
||
13 | using System.Windows.Media.Imaging; |
||
14 | using System.Windows.Navigation; |
||
15 | using System.Windows.Shapes; |
||
16 | using Telerik.Windows.Controls; |
||
17 | |||
18 | namespace KCOM.Controls |
||
19 | { |
||
20 | public class Symbol_Custom |
||
21 | { |
||
22 | public string Name { get; set; } |
||
23 | public string ImageUri { get; set; } |
||
24 | } |
||
25 | |||
26 | /// <summary> |
||
27 | /// Symbol.xaml에 대한 상호 작용 논리 |
||
28 | /// </summary> |
||
29 | public partial class Symbol : UserControl |
||
30 | { |
||
31 | AdornerFinal finalItem; |
||
32 | public string filename { get; set; } |
||
33 | MarkupToPDF.Controls.Parsing.LayerControl layer = new MarkupToPDF.Controls.Parsing.LayerControl(); |
||
34 | |||
35 | public Symbol() |
||
36 | { |
||
37 | InitializeComponent(); |
||
38 | |||
39 | DataBind(); |
||
40 | } |
||
41 | |||
42 | private void DataBind() |
||
43 | { |
||
44 | lstSymbolPrivate.ItemsSource = null; |
||
45 | |||
46 | Symbol_Custom Custom = new Symbol_Custom(); |
||
47 | List<Symbol_Custom> Custom_List = new List<Symbol_Custom>(); |
||
48 | Custom.Name = "테스트"; |
||
49 | Custom.ImageUri = "http://cloud.devdoftech.co.kr:5977/UserData/000000/H2009115/JsInNjZNgC8d59543c6854eb4.png"; |
||
50 | |||
51 | Custom_List.Add(Custom); |
||
52 | Custom_List.Add(Custom); |
||
53 | |||
54 | lstSymbolPrivate.ItemsSource = Custom_List; |
||
55 | } |
||
56 | |||
57 | private void Create_Symbol(object sender, RoutedEventArgs e) |
||
58 | { |
||
59 | MarkupToPDF.Controls.Parsing.LayerControl.MarkupReturn markupReturn = new MarkupToPDF.Controls.Parsing.LayerControl.MarkupReturn(); |
||
60 | |||
61 | if (Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Count < 1) //선택된 것이 없으면 |
||
62 | { |
||
63 | DialogMessage_Alert("Please Select Controls", "Alert"); |
||
64 | } |
||
65 | else //선택된 것이 있으면 |
||
66 | { |
||
67 | string MarkupData = ""; |
||
68 | finalItem = new AdornerFinal(); |
||
69 | |||
70 | foreach (var item in Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children) |
||
71 | { |
||
72 | if (item.GetType().Name == "AdornerFinal") |
||
73 | { |
||
74 | finalItem = (item as Controls.AdornerFinal); |
||
75 | foreach (var InnerItem in (item as Controls.AdornerFinal).MemberSet.Cast<Controls.AdornerMember>()) |
||
76 | { |
||
77 | if (!ViewerDataModel.Instance.MarkupControls.Contains(InnerItem.DrawingData)) |
||
78 | { |
||
79 | markupReturn = layer.MarkupToString(InnerItem.DrawingData as MarkupToPDF.Common.CommentUserInfo, App.ViewInfo.UserID); |
||
80 | MarkupData += markupReturn.ConvertData; |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | DialogParameters parameters = new DialogParameters() |
||
86 | { |
||
87 | Closed = (obj, args) => this.MarkupNamePromptClose(MarkupData, args), |
||
88 | DefaultPromptResultValue = "Custom State", |
||
89 | Content = "Name :", |
||
90 | Header = "Insert Custom Symbol Name", |
||
91 | Theme = new VisualStudio2013Theme(), |
||
92 | ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
||
93 | }; |
||
94 | RadWindow.Prompt(parameters); |
||
95 | } |
||
96 | |||
97 | } |
||
98 | |||
99 | private void MarkupNamePromptClose(string data, WindowClosedEventArgs args) |
||
100 | { |
||
101 | Save save = new Save(); |
||
102 | |||
103 | if (args.DialogResult.Value) |
||
104 | { |
||
105 | PngBitmapEncoder _Encoder = symImage(data); |
||
106 | |||
107 | System.IO.MemoryStream fs = new System.IO.MemoryStream(); |
||
108 | _Encoder.Save(fs); |
||
109 | System.Drawing.Image ImgOut = System.Drawing.Image.FromStream(fs); |
||
110 | |||
111 | byte[] Img_byte = fs.ToArray(); |
||
112 | |||
113 | kr.co.devdoftech.cloud.FileUpload fileUploader = new kr.co.devdoftech.cloud.FileUpload(); |
||
114 | filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, Save.shortGuid() + ".png", Img_byte); |
||
115 | |||
116 | save.SymbolSave(args.PromptResult, filename, data); |
||
117 | } |
||
118 | } |
||
119 | |||
120 | public PngBitmapEncoder symImage(string data) |
||
121 | { |
||
122 | |||
123 | Canvas _canvas = new Canvas(); |
||
124 | _canvas.Background = Brushes.White; |
||
125 | _canvas.Width = finalItem.BorderSize.Width; |
||
126 | _canvas.Height = finalItem.BorderSize.Height; |
||
127 | layer.markupParse(data, _canvas, "#FFFF0000", ""); |
||
128 | |||
129 | BitmapEncoder encoder = new PngBitmapEncoder(); |
||
130 | |||
131 | |||
132 | RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)_canvas.Width + 50, (int)_canvas.Height + 50, 96d, 96d, PixelFormats.Pbgra32); |
||
133 | |||
134 | DrawingVisual dv = new DrawingVisual(); |
||
135 | |||
136 | _canvas.Measure(new System.Windows.Size(finalItem.BorderSize.Width + 50, finalItem.BorderSize.Height + 50)); |
||
137 | //_canvas.Arrange(new Rect(new System.Windows.Point { X = -finalItem.BorderSize.X - 50, Y = -finalItem.BorderSize.Y - 50 }, new Point(finalItem.BorderSize.Width + 20, finalItem.BorderSize.Height + 20))); |
||
138 | _canvas.Arrange(new Rect(new System.Windows.Point { X = -finalItem.BorderSize.X - 20, Y = -finalItem.BorderSize.Y - 20 }, new Point(finalItem.BorderSize.Width + 20, finalItem.BorderSize.Height + 20))); |
||
139 | |||
140 | using (DrawingContext ctx = dv.RenderOpen()) |
||
141 | { |
||
142 | VisualBrush vb = new VisualBrush(_canvas); |
||
143 | //ctx.DrawRectangle(vb, null, new Rect(new System.Windows.Point { X = -finalItem.BorderSize.X - 20, Y = -finalItem.BorderSize.Y - 20 }, new Point(finalItem.BorderSize.Width + 20, finalItem.BorderSize.Height + 20))); |
||
144 | ctx.DrawRectangle(vb, null, new Rect(new System.Windows.Point { X = -finalItem.BorderSize.X, Y = -finalItem.BorderSize.Y }, new Point(finalItem.BorderSize.Width + 20, finalItem.BorderSize.Height + 20))); |
||
145 | } |
||
146 | |||
147 | try |
||
148 | { |
||
149 | renderBitmap.Render(dv); |
||
150 | |||
151 | GC.Collect(); |
||
152 | GC.WaitForPendingFinalizers(); |
||
153 | GC.Collect(); |
||
154 | //bitmap.Render(controlToConvert); |
||
155 | // encode png data |
||
156 | PngBitmapEncoder pngEncoder = new PngBitmapEncoder(); |
||
157 | // puch rendered bitmap into it |
||
158 | pngEncoder.Interlace = PngInterlaceOption.Off; |
||
159 | pngEncoder.Frames.Add(BitmapFrame.Create(renderBitmap)); |
||
160 | return pngEncoder; |
||
161 | |||
162 | } |
||
163 | catch (Exception ex) |
||
164 | { |
||
165 | return null; |
||
166 | } |
||
167 | |||
168 | } |
||
169 | |||
170 | |||
171 | public void DialogMessage_Alert(string content, string header) |
||
172 | { |
||
173 | var box = new TextBlock(); |
||
174 | box.MinWidth = 400; |
||
175 | box.FontSize = 11; |
||
176 | //box.FontSize = 12; |
||
177 | box.Text = content; |
||
178 | box.TextWrapping = System.Windows.TextWrapping.Wrap; |
||
179 | |||
180 | DialogParameters parameters = new DialogParameters() |
||
181 | { |
||
182 | Content = box, |
||
183 | Header = header, |
||
184 | Theme = new VisualStudio2013Theme(), |
||
185 | ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
||
186 | }; |
||
187 | RadWindow.Alert(parameters); |
||
188 | } |
||
189 | |||
190 | private void lsySymbolPrivate_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) |
||
191 | { |
||
192 | |||
193 | } |
||
194 | } |
||
195 | } |