프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / Controls / Symbol.xaml.cs @ 6b6e937c

이력 | 보기 | 이력해설 | 다운로드 (44 KB)

1
using IKCOM;
2
using KCOM.Common;
3
using KCOM.Events;
4
using KCOMDataModel.Common;
5
using KCOMDataModel.DataModel;
6
using MarkupToPDF.Common;
7
using MarkupToPDF.Controls.Parsing;
8
using Svg2Xaml;
9
using System;
10
using System.Collections.Generic;
11
using System.ComponentModel;
12
using System.Linq;
13
using System.Text;
14
using System.Windows;
15
using System.Windows.Controls;
16
using System.Windows.Data;
17
using System.Windows.Documents;
18
using System.Windows.Input;
19
using System.Windows.Media;
20
using System.Windows.Media.Imaging;
21
using System.Windows.Navigation;
22
using System.Windows.Shapes;
23
using Telerik.Windows.Controls;
24
using Telerik.Windows.Controls.DragDrop;
25

    
26
namespace KCOM.Controls
27
{
28
    public class Symbol_Custom
29
    {
30
        public string ID { get; set; }
31
        public string Name { get; set; }
32
        public string ImageUri { get; set; }
33
    }
34

    
35
    /// <summary>
36
    /// Symbol.xaml에 대한 상호 작용 논리
37
    /// </summary>
38
    public partial class Symbol : UserControl
39
    {
40
        AdornerFinal finalItem;
41
        bool IsMouseDown = false;
42
        string moveItem_id = "";
43
        public string filename { get; set; }
44

    
45
        public Symbol()
46
        {
47
            App.splashString(ISplashMessage.SYMBOL);
48
            InitializeComponent();
49

    
50
            //RadDragAndDropManager.AddDragInfoHandler(lstSymbolPrivate, OnDragPrivateInfo);
51
            //RadDragAndDropManager.AddDragQueryHandler(lstSymbolPrivate, OnDragPrivateQuery);
52
            //RadDragAndDropManager.SetAllowDrag(lstSymbolPrivate, true);
53

    
54
            DataBind();
55
        }
56

    
57
        private void OnDragPrivateInfo(object sender, DragDropEventArgs e)
58
        {
59
        }
60

    
61
        private void OnDragPrivateQuery(object sender, DragDropQueryEventArgs e)
62
        {
63
            if (e.Options.Status == DragStatus.DragQuery)
64
            {
65
                //var draggedListBoxItem = (e.Options.Source as System.Windows.Controls.ListBox).SelectedItem;
66
                //BitmapImage im = new BitmapImage(new Uri((draggedListBoxItem as DeepView.ServiceDeepView_Symbol.SymbolPrivate).ImageUri));
67
                //ImageSource _source = im;
68
                //Image img = new Image();
69
                //img.Source = _source;
70

    
71
                //e.Options.Payload = im;
72
                //var dragCue = new Image();
73
                //dragCue.Source = img.Source;
74
                //dragCue.Width = 0;
75
                //dragCue.Height = 0;
76
                //e.Options.DragCue = dragCue;
77

    
78

    
79
                //PayLoadAdorner = new AdornerFinal();
80
                //DeepView.ServiceDeepView_Symbol.SymbolPrivate tempDragableControl = (e.Options.Source as System.Windows.Controls.ListBox).SelectedItem as DeepView.ServiceDeepView_Symbol.SymbolPrivate;
81
                //var xamldata = tempDragableControl.Data;
82
                ////this.DeepLayer.markupParse(xamldata, this.DeepLayer._TempLayer, "복사된 데이터_이름으로 수정해야함");
83
                //PayLoadAdorner = this.DeepLayer.markupParseToAdorner(xamldata, this.DeepLayer._SelectLayer, "");
84
                //this.DeepLayer._SelectLayer.Children.Add(PayLoadAdorner);
85
            }
86

    
87
            e.QueryResult = true;
88
            e.Handled = true;
89
        }
90

    
91
        private void DataBind()
92
        {
93
            //lstSymbolPrivate.ItemsSource = null;
94
            //lstSymbolPublic.ItemsSource = null;
95

    
96
            Symbol_Custom Custom = new Symbol_Custom();
97
            List<Symbol_Custom> Custom_List = new List<Symbol_Custom>();
98

    
99
            try
100
            {
101

    
102
                var symbol_Private = ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetSymbolList(App.ViewInfo.UserID);
103

    
104

    
105
                foreach (var item in symbol_Private)
106
                {
107
                    Custom.Name = item.NAME;
108
                    Custom.ImageUri = CommonLib.Common.IPReplace(item.IMAGE_URL, App.isExternal);
109
                    Custom.ID = item.ID;
110
                    Custom_List.Add(Custom);
111
                    Custom = new Symbol_Custom();
112
                }
113
                lstSymbolPrivate.ItemsSource = Custom_List;
114
            }
115
            catch (Exception ex)
116
            {
117
                System.Diagnostics.Debug.WriteLine(ex.ToString());
118
            }
119

    
120
            Custom = new Symbol_Custom();
121
            Custom_List = new List<Symbol_Custom>();
122

    
123
            deptlist.ItemsSource = ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetPublicSymbolDeptList();
124

    
125
            List<SYMBOL_PUBLIC> symbol_Public;
126

    
127

    
128
            if (deptlist.SelectedValue != null)
129
            {
130
                symbol_Public = ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetPublicSymbolList(deptlist.SelectedValue.ToString());
131
            }
132
            else
133
            {
134
                symbol_Public = ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetPublicSymbolList(null);
135
            }
136
        
137
            foreach (var item in symbol_Public)
138
            {
139
                Custom.Name = item.NAME;
140
                Custom.ImageUri = CommonLib.Common.IPReplace(item.IMAGE_URL, App.isExternal);
141
                Custom.ID = item.ID;
142
                Custom_List.Add(Custom);
143
                Custom = new Symbol_Custom();
144
            }
145
            lstSymbolPublic.ItemsSource = Custom_List;
146
        }
147

    
148
        public PngBitmapEncoder symImage(string data)
149
        {
150

    
151
            Canvas _canvas = new Canvas();
152
            _canvas.Background = Brushes.White;
153
            _canvas.Width = finalItem.BorderSize.Width;
154
            _canvas.Height = finalItem.BorderSize.Height;
155
            MarkupParser.Parse(App.ViewInfo.ProjectNO, data, _canvas, "#FFFF0000", "");
156

    
157
            BitmapEncoder encoder = new PngBitmapEncoder();
158

    
159

    
160
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)_canvas.Width + 50, (int)_canvas.Height + 50, 96d, 96d, PixelFormats.Pbgra32);
161

    
162
            DrawingVisual dv = new DrawingVisual();
163

    
164
            _canvas.Measure(new System.Windows.Size(finalItem.BorderSize.Width + 50, finalItem.BorderSize.Height + 50));
165
            //_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)));
166
            _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)));
167

    
168
            using (DrawingContext ctx = dv.RenderOpen())
169
            {
170
                VisualBrush vb = new VisualBrush(_canvas);
171
                //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)));
172
                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)));
173
            }
174

    
175
            try
176
            {
177
                renderBitmap.Render(dv);
178

    
179
                GC.Collect();
180
                GC.WaitForPendingFinalizers();
181
                GC.Collect();
182
                //bitmap.Render(controlToConvert);
183
                // encode png data
184
                PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
185
                // puch rendered bitmap into it
186
                pngEncoder.Interlace = PngInterlaceOption.Off;
187
                pngEncoder.Frames.Add(BitmapFrame.Create(renderBitmap));
188
                return pngEncoder;
189

    
190
            }
191
            catch //(Exception ex)
192
            {
193
                return null;
194
            }
195

    
196
        }
197

    
198
        public void DialogMessage_Alert(string content, string header)
199
        {
200
            DialogParameters parameters = new DialogParameters()
201
            {
202
                Owner = Application.Current.MainWindow,
203
                Content = new TextBlock()
204
                {
205
                    MinWidth = 400,
206
                    FontSize = 11,
207
                    Text = content,
208
                    TextWrapping = System.Windows.TextWrapping.Wrap
209
                },
210
                Header = header,
211
                Theme = new VisualStudio2013Theme(),
212
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
213
            };
214
            RadWindow.Alert(parameters);
215
        }
216

    
217
        #region Event
218

    
219
        #region Private Symbol Add Event
220
        private void Create_Symbol(object sender, RoutedEventArgs e)
221
        {
222
            MarkupToPDF.Controls.Parsing.MarkupParser.MarkupReturn markupReturn = new MarkupToPDF.Controls.Parsing.MarkupParser.MarkupReturn();
223

    
224
            if (Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Count < 1) //선택된 것이 없으면
225
            {
226
                DialogMessage_Alert("Please Select Controls", "Alert");
227
            }
228
            else //선택된 것이 있으면
229
            {
230
                string MarkupData = "";
231
                finalItem = new AdornerFinal();
232

    
233
                foreach (var item in Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children)
234
                {
235
                    if (item.GetType().Name == "AdornerFinal")
236
                    {
237
                        finalItem = (item as Controls.AdornerFinal);
238
                        foreach (var InnerItem in (item as Controls.AdornerFinal).Members.Cast<Controls.AdornerMember>())
239
                        {
240
                            if (!ViewerDataModel.Instance.MarkupControls.Contains(InnerItem.DrawingData))
241
                            {
242
                                markupReturn = MarkupParser.MarkupToString(InnerItem.DrawingData as MarkupToPDF.Common.CommentUserInfo, App.ViewInfo.UserID);
243
                                MarkupData += markupReturn.ConvertData;
244
                            }
245
                        }
246
                    }
247
                }
248
                DialogParameters parameters = new DialogParameters()
249
                {
250
                    Owner = Application.Current.MainWindow,
251
                    Closed = (obj, args) => this.MarkupNamePromptClose(MarkupData, args),
252
                    DefaultPromptResultValue = "Custom State",
253
                    Content = "Name :",
254
                    Header = "Insert Custom Symbol Name",
255
                    Theme = new VisualStudio2013Theme(),
256
                    ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
257
                };
258
                RadWindow.Prompt(parameters);
259
            }
260

    
261
        }
262
        #endregion
263

    
264
        #region Symbol Add Close Event 
265
        private void MarkupNamePromptClose(string data, WindowClosedEventArgs args)
266
        {
267
            try
268
            {
269
                if (args.PromptResult != null)
270
                {
271
                    if (args.DialogResult.Value)
272
                    {
273
                        PngBitmapEncoder _Encoder = symImage(data);
274

    
275
                        System.IO.MemoryStream fs = new System.IO.MemoryStream();
276
                        _Encoder.Save(fs);
277
                        System.Drawing.Image ImgOut = System.Drawing.Image.FromStream(fs);
278

    
279
                        byte[] Img_byte = fs.ToArray();
280

    
281
                        kr.co.devdoftech.cloud.FileUpload fileUploader = new kr.co.devdoftech.cloud.FileUpload();
282
                        filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, Commons.shortGuid() + ".png", Img_byte);
283
                        Check_Uri.UriCheck(filename);
284
                        if (RadTab.SelectedIndex == 0)
285
                        {
286
                            SymbolSave(args.PromptResult, filename, data);
287
                        }
288
                        else
289
                        {
290
                            SymbolSave_Public(args.PromptResult, filename, data, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.userData.DEPARTMENT);
291
                        }
292

    
293
                        DataBind();
294
                    }
295
                }
296
            }
297
            catch(Exception ex)
298
            {
299
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert");
300
            }
301
        }
302
        #endregion
303

    
304
        public void SymbolSave(string Name, string Url, string Data)
305
        {
306
            try
307
            {
308
                SYMBOL_PRIVATE symbol_private = new SYMBOL_PRIVATE
309
                {
310
                    ID = Commons.shortGuid(),
311
                    MEMBER_USER_ID = App.ViewInfo.UserID,
312
                    NAME = Name,
313
                    IMAGE_URL = Url,
314
                    DATA = Data
315
                };
316

    
317
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveSymbolCompleted += BaseClient_SaveSymbolCompleted;
318
                Logger.sendReqLog("SaveSymbolAsync: ", symbol_private.ID + "," + symbol_private.MEMBER_USER_ID + "," + symbol_private.NAME + "," + symbol_private.IMAGE_URL + "," + symbol_private.DATA, 1);
319
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveSymbolAsync(symbol_private);
320
            }
321
            catch (Exception)
322
            {
323
                throw;
324
            }
325
        }
326

    
327
        public void SymbolSave_Public(string Name, string Url, string Data, string Department)
328
        {
329
            try
330
            {
331
                SYMBOL_PUBLIC symbol_public = new SYMBOL_PUBLIC
332
                {
333
                    ID = Commons.shortGuid(),
334
                    DEPARTMENT = Department,
335
                    NAME = Name,
336
                    IMAGE_URL = Url,
337
                    DATA = Data
338
                };
339
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddPublicSymbolCompleted += BaseClient_AddPublicSymbolCompleted;
340
                Logger.sendReqLog("AddPublicSymbol: ", symbol_public.ID + "," + symbol_public.DEPARTMENT + "," + symbol_public.NAME + "," + symbol_public.IMAGE_URL + "," + symbol_public.DATA, 1);
341
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddPublicSymbol(symbol_public);
342
            }
343
            catch (Exception)
344
            {
345
                throw;
346
            }
347
        }
348

    
349
        private void BaseClient_AddPublicSymbolCompleted(object sender, ServiceDeepView.AddPublicSymbolCompletedEventArgs e)
350
        {
351
            Logger.sendResLog("AddPublicSymbolCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
352
            DataBind();
353
        }
354

    
355
        private void BaseClient_SaveSymbolCompleted(object sender, ServiceDeepView.SaveSymbolCompletedEventArgs e)
356
        {
357
            Logger.sendResLog("RenameSymbolCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
358
            DataBind();
359
        }
360

    
361
        #region Private Symbol Delete Event
362
        private void Remove_Symbol(object sender, RoutedEventArgs e)
363
        {
364
            if (lstSymbolPrivate.SelectedItem == null)
365
            {
366
                DialogMessage_Alert("Please Select Symbol", "Alert");
367
                return;
368
            }
369
            string delItem_ID = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
370

    
371
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolCompleted += BaseClient_DeleteSymbolCompleted;
372
            Logger.sendReqLog("DeleteSymbolAsync: ", delItem_ID, 1);
373
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolAsync(delItem_ID, RadTab.SelectedIndex);
374
        }
375
        #endregion
376
        #region Public Symbol Delete Event
377
        private void Remove_Symbol_Public(object sender, RoutedEventArgs e)
378
        {
379
            if (lstSymbolPublic.SelectedItem == null)
380
            {
381
                DialogMessage_Alert("Please Select Symbol", "Alert");
382
                return;
383
            }
384
            string delItem_ID = (lstSymbolPublic.SelectedItem as Symbol_Custom).ID;
385

    
386
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolCompleted += BaseClient_DeleteSymbolCompleted;
387
            Logger.sendReqLog("DeleteSymbolAsync: ", delItem_ID, 1);
388
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolAsync(delItem_ID, RadTab.SelectedIndex);
389
        }
390

    
391
        private void BaseClient_DeleteSymbolCompleted(object sender, ServiceDeepView.DeleteSymbolCompletedEventArgs e)
392
        {
393
            Logger.sendResLog("DeleteSymbolCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
394
            DataBind();
395
        }
396
        #endregion
397

    
398
        public Undo_data UndoData { get; set; }
399
        /// <summary>
400
        /// place symbol which has given id to original position which is created
401
        /// </summary>
402
        /// <date>2018.06.14</date>
403
        /// <param name="id"></param>
404
        private void PlaceSymbol(string id,Point CurrentMousePoint)
405
        {
406
            string Data_ = "";
407

    
408
            var systemMain = Common.ViewerDataModel.Instance.SystemMain;
409
            var mainMenu = systemMain.dzMainMenu;
410
            
411
            SelectionSet.Instance.UnSelect(mainMenu);  /// unselect alreay selected items
412

    
413
            try
414
            {
415
                Logger.sendReqLog("GetSymbolData: ", id + "," + RadTab.SelectedIndex, 1);
416
                Data_ = mainMenu.BaseClient.GetSymbolData(id, RadTab.SelectedIndex);
417

    
418
                if (Data_ != null || Data_ != "")
419
                {
420
                    Logger.sendResLog("GetSymbolData", "TRUE", 1);
421
                }
422
                else
423
                {
424
                    Logger.sendResLog("GetSymbolData", "FALSE", 1);
425
                }
426

    
427
                //MARKUP_DATA_GROUP INSERT
428
                //MARKUP_DATA_GROUP mARKUP_DATA_GROUP = new MARKUP_DATA_GROUP
429
                //{
430
                //    SYMBOL_ID = id,//InnerItem.Symbol_ID
431
                //    STATE = 0,
432
                //};
433
                //long group_id = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddMarkupDataGroup(mARKUP_DATA_GROUP, App.ViewInfo.ProjectNO);
434
                //Logger.sendReqLog("AddMarkupDataGroup: ", "", 1);
435

    
436
                if (Data_.Contains("|DZ|"))
437
                {
438
                    List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
439

    
440
                    string[] delimiterChars = { "|DZ|" };
441
                    string[] data = Data_.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
442

    
443
                    Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
444
                    UndoData = new Undo_data()
445
                    {
446
                        IsUndo = false,
447
                        Event = Event_Type.Create,
448
                        EventTime = DateTime.Now,
449
                        Markup_List = new List<Multi_Undo_data>()
450
                    };
451
                    ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i =>
452
                    {
453
                        ViewerDataModel.Instance.UndoDataList.Remove(i);
454
                    });
455

    
456
                    foreach (string parse in data)
457
                    {
458
                        if (parse != "")
459
                        {
460
                            System.Windows.Controls.Control item = MarkupParser.ParseEx(App.ViewInfo.ProjectNO, parse, ViewerDataModel.Instance.MarkupControls_USER, string.Empty, string.Empty);
461
                            (item as MarkupToPDF.Common.CommentUserInfo).CommentID = Commons.shortGuid();
462
                            (item as MarkupToPDF.Common.CommentUserInfo).SymbolID = id;
463
                            //(item as MarkupToPDF.Common.CommentUserInfo).GroupID = group_id;
464

    
465
                            ViewerDataModel.Instance.MarkupControls.Remove(item as MarkupToPDF.Common.CommentUserInfo);
466
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item as MarkupToPDF.Common.CommentUserInfo);
467

    
468
                            adornerSet.Add(item as MarkupToPDF.Common.CommentUserInfo);
469

    
470
                            multi_Undo_Data = this.ParentOfType<MainWindow>().dzMainMenu.Control_Style(item as MarkupToPDF.Common.CommentUserInfo);
471

    
472
                            UndoData.Markup_List.Add(multi_Undo_Data);
473
                            ViewerDataModel.Instance.UndoDataList.Add(UndoData);
474
                        }
475
                    }
476

    
477
                    Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
478

    
479
                    // 마우스 클릭된 페이지 위치
480

    
481
                    var pageWidth = mainMenu.pageNavigator.CurrentPage.Width;
482
                    var pageHeight = mainMenu.pageNavigator.CurrentPage.Height;
483
                    var angle = Common.ViewerDataModel.Instance.Angle;
484

    
485
                    Point pagePoint = new Point(pageWidth/2, pageHeight/2);
486

    
487
                    var rotatePoint = Rotate(mainMenu.CanvasDrawingMouseDownPoint,pagePoint,angle);
488

    
489
                    var diff = Point.Subtract(rotatePoint, final.Centeroid);
490
                    final.TranslateItems(diff.X, diff.Y);
491

    
492
                    mainMenu.SelectLayer.Children.Add(final);
493
                    //var finalPosition = new Point(Canvas.GetLeft(final), Canvas.GetTop(final));
494
                    //Rect rect = new Rect(finalPosition, Point.Add(finalPosition,new Vector(final.Width,final.Height)));
495

    
496
                    //SelectionSet.Instance.SelectItemByRect(final.getAdornerSize(), mainMenu);
497

    
498
                }
499
                else
500
                {
501
                    PlaceImageSymbol(id, 0);
502
                }
503
            }
504
            catch (Exception ex)
505
            {
506
                this.ParentOfType<MainWindow>().dzMainMenu.DialogMessage_Alert(ex.Message, "Error");
507
            }
508
        }
509

    
510

    
511
        //출처: https://icodebroker.tistory.com/3189 [ICODEBROKER]
512
        public Point Rotate(Point sourcePoint, Point centerPoint, double rotateAngle)
513
        {
514
            Point targetPoint = new Point();
515

    
516
            double radian = rotateAngle / 180 * Math.PI;
517

    
518
            targetPoint.X = Math.Cos(radian) * (sourcePoint.X - centerPoint.X) - Math.Sin(radian) * (sourcePoint.Y - centerPoint.Y) + centerPoint.X;
519
            targetPoint.Y = Math.Sin(radian) * (sourcePoint.X - centerPoint.X) + Math.Cos(radian) * (sourcePoint.Y - centerPoint.Y) + centerPoint.Y;
520

    
521
            return targetPoint;
522
        }
523

    
524

    
525

    
526
        private void PlaceImageSymbol(string id, long group_id)
527
        {
528
           
529
            //canvasZoommovingMouseDownPoint
530
            string Data_ = "";
531

    
532
            try
533
            {
534
                Logger.sendReqLog("GetSymbolImageURL: ", id + "," + RadTab.SelectedIndex, 1);
535
                Data_ = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetSymbolImageURL(id, RadTab.SelectedIndex);
536
                if (Data_ != null || Data_ != "")
537
                {
538
                    Logger.sendResLog("GetSymbolImageURL", "TRUE", 1);
539
                }
540
                else
541
                {
542
                    Logger.sendResLog("GetSymbolImageURL", "FALSE", 1);
543
                }
544

    
545
                //MARKUP_DATA_GROUP INSERT
546
                //MARKUP_DATA_GROUP mARKUP_DATA_GROUP = new MARKUP_DATA_GROUP
547
                //{
548
                //    SYMBOL_ID = id,//InnerItem.Symbol_ID
549
                //    STATE = 0,
550
                //};
551
                //long group_id = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddMarkupDataGroup(mARKUP_DATA_GROUP, App.ViewInfo.ProjectNO);
552
                //Logger.sendReqLog("AddMarkupDataGroup: ", "", 1);
553

    
554
                if (Data_ != null)
555
                {
556
                    Image img = new Image();
557
                    //img.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(Data_));
558
                    if (Data_.Contains(".svg"))
559
                    {
560
                        byte[] imageData = null;
561
                        DrawingImage image = null;
562
                        using (System.Net.WebClient web = new System.Net.WebClient())
563
                        {
564
                            imageData = web.DownloadData(new Uri(Data_));
565
                            System.IO.Stream stream = new System.IO.MemoryStream(imageData);
566
                            image = SvgReader.Load(stream);
567
                        }
568
                        img.Source = image;
569
                    }
570
                    else
571
                    {
572
                        img.Source = new BitmapImage(new Uri(Data_));
573
                    }
574

    
575
                    var currentControl = new MarkupToPDF.Controls.Etc.ImgControl
576
                    {
577
                        PointSet = new List<Point>(),
578
                        FilePath = Data_,
579
                        ImageData = img.Source,
580
                        StartPoint = new Point(0, 0),
581
                        EndPoint = new Point(img.Source.Width, img.Source.Height),
582
                        TopRightPoint = new Point(img.Source.Width, 0),
583
                        LeftBottomPoint = new Point(0, img.Source.Height)
584
                    };
585

    
586
                    currentControl.PointSet = new List<Point>
587
                                        {
588
                                            currentControl.StartPoint,
589
                                            currentControl.LeftBottomPoint,
590
                                            currentControl.EndPoint,
591
                                            currentControl.TopRightPoint,
592
                                        };
593
                    Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
594
                    UndoData = new Undo_data()
595
                    {
596
                        IsUndo = false,
597
                        Event = Event_Type.Create,
598
                        EventTime = DateTime.Now,
599
                        Markup_List = new List<Multi_Undo_data>()
600
                    };
601
                    ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i =>
602
                    {
603
                        ViewerDataModel.Instance.UndoDataList.Remove(i);
604
                    });
605

    
606
                    //multi_Undo_Data = dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo);
607
                    multi_Undo_Data = this.ParentOfType<MainWindow>().dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo);
608
                    UndoData.Markup_List.Add(multi_Undo_Data);
609
                    ViewerDataModel.Instance.UndoDataList.Add(UndoData);
610

    
611
                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo);
612
                    currentControl.CommentID = Commons.shortGuid();
613
                    currentControl.SymbolID = id;
614
                    currentControl.GroupID = group_id;
615
                    currentControl.ApplyTemplate();
616
                    currentControl.SetImage();
617

    
618
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo);
619
                    Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo);
620
                    this.ParentOfType<MainWindow>().dzMainMenu.SelectLayer.Children.Add(final);
621

    
622
                    /*
623
                    // this.ParentOfType<MainWindow>().dzMainMenu.isLeftMouseButtonDownOnWindow = true;
624
                    // final.MoveAdorner(new System.Windows.Controls.Primitives.DragDeltaEventArgs(realPointX, realPointY));
625
                    double realPointX = this.ParentOfType<MainWindow>().dzMainMenu.getCurrentPoint.X - final.BorderSize.X - (final.BorderSize.Width / 2);
626
                    double realPointY = this.ParentOfType<MainWindow>().dzMainMenu.getCurrentPoint.Y - final.BorderSize.Y - (final.BorderSize.Height / 2);
627
                      final.TranslateItems(realPointX, realPointY);
628
                    // move.control_Select(item, dragRect);
629
                    ApplyDragSelectionRect();
630
                    //this.ParentOfType<MainWindow>().dzMainMenu.mouseHandlingMode = MouseHandlingMode.DragSymbol;
631
                    ///this.ParentOfType<MainWindow>().dzMainMenu.mouseButtonDown = MouseButton.Left;
632
                    //this.ParentOfType<MainWindow>().dzMainMenu.symboldata(id, group_id, RadTab.SelectedIndex, Data_, img.Source);*/
633
                    
634
                }
635
            }
636
            catch(Exception ex)
637
            {
638
                this.ParentOfType<MainWindow>().dzMainMenu.DialogMessage_Alert(ex.Message, "Error");
639
            }
640
        }
641

    
642
        public Multi_Undo_data multi_Undo_Data;
643
        private void ApplyDragSelectionRect()
644
        {
645
            multi_Undo_Data = new Multi_Undo_data();
646

    
647
            UndoData = new Undo_data()
648
            {
649
                IsUndo = false,
650
                Event = Event_Type.Select,
651
                EventTime = DateTime.Now,
652
                Markup_List = new List<Multi_Undo_data>()
653
            };
654

    
655
            this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder.Visibility = Visibility.Collapsed;
656

    
657
            double x = Canvas.GetLeft(this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder);
658
            double y = Canvas.GetTop(this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder);
659
            double width = this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder.Width;
660
            double height = this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder.Height;
661
            Rect dragRect = new Rect(x, y, width, height);
662
            Boolean Flag = false;
663
            dragRect.Inflate(width / 10, height / 10);
664
            List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
665
            var Items = ViewerDataModel.Instance.MarkupControls_USER.ToList();
666

    
667
            dragRect = new Rect(x, y, width, height);
668
            dragRect.Inflate(width / 10, height / 10);
669

    
670
            //move.mousemode = MarkupToPDF.Controls.Common.MouseMode.Selecting;
671
            //move.
672
            foreach (var item in Items)
673
            {
674
                Flag = SelectionSet.Instance.SelectControl(item, dragRect);
675

    
676
                if (Flag)
677
                {
678
                    adornerSet.Add(item);
679
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(item);
680

    
681
                    this.ParentOfType<MainWindow>().dzMainMenu.Control_Style(item);
682
                    UndoData.Markup_List.Add(multi_Undo_Data);
683
                    multi_Undo_Data = new Multi_Undo_data();
684
                    if (item.GroupID > 0)
685
                    {
686

    
687
                    }
688
                }
689
            }
690
            if (adornerSet.Count > 0)
691
            {
692
                ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == true).ToList().ForEach(i =>
693
                {
694
                    ViewerDataModel.Instance.UndoDataList.Remove(i);
695
                });
696
                ViewerDataModel.Instance.UndoDataList.Add(UndoData);
697

    
698
                Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
699
                this.ParentOfType<MainWindow>().dzMainMenu.SelectLayer.Children.Add(final);
700
            }
701
        }
702

    
703
        ///private Move move;
704
        #region Symbol DoubleClick Event
705
        private void Move_Symbol(object sender, MouseButtonEventArgs e)
706
        {
707
            try
708
            {
709
                Type type = e.OriginalSource.GetType();
710
                string id = string.Empty;
711
                Logger.sendResLog("Move_Symbol", type.Name, 0);
712
                if (type.Name == "Image")
713
                {
714
                    id = ((e.OriginalSource as Image).DataContext as Symbol_Custom).ID;
715
                }
716
                else if (type.Name == "Border")
717
                {
718
                    id = ((e.OriginalSource as Border).DataContext as Symbol_Custom).ID;
719
                }
720
                else if (type.Name == "TextBox")
721
                {
722
                    id = ((e.OriginalSource as TextBox).DataContext as Symbol_Custom).ID;
723
                }
724

    
725
                IsMouseDown = true;
726

    
727
                if (e.ClickCount > 1)
728
                {
729
                    this.PlaceSymbol(id,ViewerDataModel.Instance.SystemMain.dzMainMenu.CanvasDrawingMouseDownPoint);
730
                }
731
            }
732
            catch(Exception ex)
733
            {
734
                Logger.sendResLog("Move_Symbol", ex.Message, 0);
735
            }
736
        }
737
        #endregion
738

    
739
        #region Private Symbol Rename Event
740
        private void Rename_Symbol(object sender, RoutedEventArgs e)
741
        {
742
            if (lstSymbolPrivate.SelectedItem == null)
743
            {
744
                DialogMessage_Alert("Please Select Symbol", "Alert");
745
                return;
746
            }
747

    
748
            DialogParameters parameters = new DialogParameters()
749
            {
750
                Owner = Application.Current.MainWindow,
751
                Closed = (obj, args) => this.MarkupReNamePromptClose("", args),
752
                //DefaultPromptResultValue = "Custom State",
753
                DefaultPromptResultValue = (lstSymbolPrivate.SelectedItem as Symbol_Custom).Name,
754
                Content = "Name :",
755
                Header = "Update Custom Symbol Name",
756
                Theme = new VisualStudio2013Theme(),
757
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
758
            };
759
            RadWindow.Prompt(parameters);
760

    
761
        }
762
        #endregion
763

    
764
        #region Public Symbol Rename Event
765
        private void Rename_Symbol_Public(object sender, RoutedEventArgs e)
766
        {
767
            if (lstSymbolPublic.SelectedItem == null)
768
            {
769
                DialogMessage_Alert("Please Select Symbol", "Alert");
770
                return;
771
            }
772

    
773
            DialogParameters parameters = new DialogParameters()
774
            {
775
                Owner = Application.Current.MainWindow,
776
                Closed = (obj, args) => this.MarkupReNamePromptClose("", args),
777
                //DefaultPromptResultValue = "Custom State",
778
                DefaultPromptResultValue = (lstSymbolPublic.SelectedItem as Symbol_Custom).Name,
779
                Content = "Name :",
780
                Header = "Update Custom Symbol Name",
781
                Theme = new VisualStudio2013Theme(),
782
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
783
            };
784
            RadWindow.Prompt(parameters);
785

    
786
        }
787
        #endregion
788
        #region Symbol Rename Close Event
789
        private void MarkupReNamePromptClose(string data, WindowClosedEventArgs args)
790
        {
791
            if (args.DialogResult != null && args.DialogResult.Value)
792
            {
793
                if(RadTab.SelectedIndex == 0)
794
                {
795
                    string _id = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
796
                    string _name = args.PromptResult;
797
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
798
                    Logger.sendReqLog("RenameSymbolAsync: ", _id + "," + _name, 1);
799
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(_id, _name, RadTab.SelectedIndex);
800
                }
801
                else
802
                {
803
                    string _id = (lstSymbolPublic.SelectedItem as Symbol_Custom).ID;
804
                    string _name = args.PromptResult;
805
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
806
                    Logger.sendReqLog("RenameSymbolAsync: ", _id + "," + _name, 1);
807
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(_id, _name, RadTab.SelectedIndex);
808
                }
809
            }
810
        }
811

    
812
        private void BaseClient_RenameSymbolCompleted(object sender, ServiceDeepView.RenameSymbolCompletedEventArgs e)
813
        {
814
            Logger.sendResLog("RenameSymbolCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
815
            DataBind();
816
        }
817
        #endregion
818

    
819
        #region Wheel Event
820
        private void lstSymbolPrivate_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
821
        {
822
            ScView.ScrollToVerticalOffset(ScView.ContentVerticalOffset - (e.Delta / 2));
823
        }
824
        private void lstSymbolPublic_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
825
        {
826
            ScView_Public.ScrollToVerticalOffset(ScView_Public.ContentVerticalOffset - (e.Delta / 2));
827
        }
828
        #endregion
829

    
830
        #region Tab Selection Event
831
        private void RadTabControl_PreviewSelectionChanged(object sender, RadSelectionChangedEventArgs e)
832
        {
833
            foreach (var item in (e.OriginalSource as RadTabControl).Items)
834
            {
835
                (item as RadTabItem).FontWeight = FontWeights.Normal;
836
            }
837
            ((e.OriginalSource as RadTabControl).SelectedItem as RadTabItem).FontWeight = FontWeights.Bold;
838
        }
839
        #endregion
840

    
841
        #region Department Selection Event
842
        private void deptlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
843
        {
844
            DataBind();
845
        }
846
        #endregion
847

    
848
        #endregion
849

    
850
        private void lstSymbolPrivate_PreviewMouseUp(object sender, MouseButtonEventArgs e)
851
        {
852

    
853
        }
854

    
855
        private void lstSymbolPrivate_MouseLeave(object sender, MouseEventArgs e)
856
        {
857

    
858
        }
859

    
860
        private void lstSymbolPrivate_MouseDown(object sender, MouseButtonEventArgs e)
861
        {
862

    
863
        }
864

    
865
        private void StackPanel_MouseLeave(object sender, MouseEventArgs e)
866
        {
867
            if(IsMouseDown && e.LeftButton == MouseButtonState.Pressed)
868
            {
869
                ViewerDataModel.Instance.SystemMain.dzMainMenu.Symbol_ID = moveItem_id;
870
            }
871
            else
872
            {
873
                IsMouseDown = false;
874
            }
875
        }
876

    
877
        private void StackPanel_MouseUp(object sender, MouseButtonEventArgs e)
878
        {
879
            IsMouseDown = false;
880
        }
881

    
882
        /// <summary>
883
        /// place symbol which user select
884
        /// </summary>
885
        /// <author>humkyung</author>
886
        /// <date>2018.06.14</date>
887
        /// <param name="sender"></param>
888
        /// <param name="e"></param>
889
        private void Place_Symbol(object sender, RoutedEventArgs e)
890
        {
891
            if (lstSymbolPrivate.SelectedItem == null)
892
            {
893
                DialogMessage_Alert("Please Select Symbol",  "Alert");
894
                return;
895
            }
896

    
897
            string id = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
898
            this.PlaceSymbol(id, ViewerDataModel.Instance.SystemMain.dzMainMenu.CanvasDrawingMouseDownPoint);
899
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.None;
900
        }
901

    
902
        private void Place_Symbol_Public(object sender, RoutedEventArgs e)
903
        {
904
            if (lstSymbolPublic.SelectedItem == null)
905
            {
906
                DialogMessage_Alert("Please Select Symbol", "Alert");
907
                return;
908
            }
909

    
910
            string id = (lstSymbolPublic.SelectedItem as Symbol_Custom).ID;
911
            this.PlaceSymbol(id, ViewerDataModel.Instance.SystemMain.dzMainMenu.CanvasDrawingMouseDownPoint);
912
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.None;
913
        }
914

    
915
        private void Image_Place_Register(object sender, RoutedEventArgs e)
916
        {
917
            SyncInit();
918
            ViewerDataModel.Instance.SystemMain.dzMainMenu.controlType = MarkupToPDF.Controls.Common.ControlType.ImgControl;
919
            //캡쳐 하기 전에 코멘트 저장
920
            if (Common.ViewerDataModel.Instance.MarkupControls_USER.Count > 0 || (Application.Current.MainWindow as MainWindow).dzMainMenu.SelectLayer.Children.Count > 0)
921
            {
922
                var menu = (Application.Current.MainWindow as MainWindow).dzMainMenu;
923
                SelectionSet.Instance.UnSelect(menu);
924
                if (menu.PreviewUserMarkupInfoItem != null && menu.PreviewUserMarkupInfoItem.IsPreviewUser == true)
925
                {
926
                    (Application.Current.MainWindow as MainWindow).dzTopMenu.SaveEventCallback(null, null);
927
                }
928
                else if (menu.gridViewMarkup.SelectedItems.Count == 0 || (menu.gridViewMarkup.SelectedItems.FirstOrDefault() as IKCOM.MarkupInfoItem).UserID != App.ViewInfo.UserID)
929
                {
930

    
931
                }
932
                else
933
                {
934
                    (Application.Current.MainWindow as MainWindow).dzTopMenu.SaveEventCallback(null, null);
935
                }
936
            }
937
            Application.Current.MainWindow.Focus();
938
            Common.ViewerDataModel.Instance.Capture_Opacity = 0.49;
939
            (Application.Current.MainWindow as MainWindow).dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.Capture;
940
        }
941

    
942

    
943
        private void SyncInit()
944
        {
945
            try
946
            {
947
                if (!ViewerDataModel.Instance.SystemMain.dzMainMenu.testPanel2.IsHidden)
948
                {
949
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.testPanel2.IsHidden = true;
950
                    ViewerDataModel.Instance.PageBalanceMode = false;
951
                    ViewerDataModel.Instance.PageBalanceNumber = 0;
952
                    ViewerDataModel.Instance.PageNumber = 0;
953
                    ViewerDataModel.Instance.MarkupControls_Sync.Clear();
954
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.gridViewRevMarkup.Visibility = Visibility.Collapsed;
955
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.UserList.IsChecked = false;
956
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.BalanceMode.IsChecked = false;
957
                }
958
            }
959
            catch (Exception ex)
960
            {
961
                Logger.sendResLog("SyncInit", ex.Message, 0);
962
            }
963
        }
964

    
965
        private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
966
        {
967
            var block = sender as TextBox;
968
            block.Focusable = true;
969
               
970
        }
971

    
972
        private void TextBlock_MouseEnter(object sender, MouseEventArgs e)
973
        {
974
            var block = sender as TextBox;
975
            if (block != null)
976
            {
977
                //block.Text = "Enter";
978

    
979
            }
980
        }
981

    
982
        private void OnKeyDownHandler(object sender, KeyEventArgs e)
983
        {
984
            if (e.Key == Key.Return)
985
            {
986
                Type type = e.OriginalSource.GetType();
987
                string id = string.Empty;
988
                Logger.sendResLog("Move_Symbol", type.Name, 0);
989
                if (type.Name == "Image")
990
                {
991
                    id = ((e.OriginalSource as Image).DataContext as Symbol_Custom).ID;
992
                }
993
                else if (type.Name == "Border")
994
                {
995
                    id = ((e.OriginalSource as Border).DataContext as Symbol_Custom).ID;
996
                }
997
                else if (type.Name == "TextBox")
998
                {
999
                    id = ((e.OriginalSource as TextBox).DataContext as Symbol_Custom).ID;
1000
                }
1001

    
1002
                //((System.Windows.Controls.TextBox)sender).Text;
1003

    
1004
                if (RadTab.SelectedIndex == 0)
1005
                {
1006
                    //string _id = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
1007
                    string _name = ((System.Windows.Controls.TextBox)sender).Text;
1008
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
1009
                    Logger.sendReqLog("RenameSymbolAsync: ", id + "," + _name, 1);
1010
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(id, _name, RadTab.SelectedIndex);
1011
                }
1012
                else
1013
                {
1014
                    //string _id = (lstSymbolPublic.SelectedItem as Symbol_Custom).ID;
1015
                    string _name = ((System.Windows.Controls.TextBox)sender).Text;
1016
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
1017
                    Logger.sendReqLog("RenameSymbolAsync: ", id + "," + _name, 1);
1018
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(id, _name, RadTab.SelectedIndex);
1019
                }
1020
                
1021
            }
1022
        }
1023
        
1024
    }
1025
}
클립보드 이미지 추가 (최대 크기: 500 MB)