프로젝트

일반

사용자정보

개정판 6af42ff0

ID6af42ff03346c4a82b314e2c20a97857d3ea8093
상위 0f26a9aa
하위 5a00ee8e

김태성이(가) 약 5년 전에 추가함

issue #0002 Search Panel 수정

Change-Id: I6b65a08862f9ec421dd81464d4e48cc14c20e0dd

차이점 보기:

KCOM/Controls/SearchPanel.xaml.cs
7 7
using System.Linq;
8 8
using System.Text;
9 9
using System.Threading;
10
using System.Threading.Tasks;
10 11
using System.Windows;
11 12
using System.Windows.Controls;
12 13
using System.Windows.Data;
......
37 38
        Bytescout.PDFExtractor.TextExtractor extractor;
38 39
        Bytescout.PDFExtractor.OCRAnalyzer ocrAnalyzer;
39 40
        private BackgroundWorker worker = new BackgroundWorker();
41
        private bool IsCancelWork = false;
42

  
40 43
        public SearchPanel()
41 44
        {
42 45
            App.splashString(ISplashMessage.SEARCHPANEL);
......
48 51
            SearchSet = new System.Collections.ObjectModel.ObservableCollection<SearchText>();
49 52

  
50 53
            tbSearch.KeyDown += tbSearch_KeyDown;
51
            this.DataContext = this;
52 54

  
53 55
            worker.DoWork += Worker_DoWork;
54 56
            worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
55 57

  
58
            this.DataContext = this;
59

  
56 60
            /*
57 61
            if (Common.ViewerDataModel.Instance.searchPDF ==null)
58 62
            {
......
66 70
            }
67 71
            */
68 72

  
69
            if (Common.ViewerDataModel.Instance.searchPDF != null)
73
            if (ViewerDataModel.Instance.IsDownloadOriginal)
70 74
            {
71
                border_Overlap.Visibility = Visibility.Collapsed;
72
                tbSearch.Focus();
75
                SetSerachPDFFile(ViewerDataModel.Instance.OriginalTempFile);
73 76
            }
74 77
        }
75 78

  
......
77 80
        {
78 81
            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
79 82
            {
80
                this.searchIndicator.IsBusy = false;
83
                btnSearch.Content = "Search";
84
                IsCancelWork = false;
85

  
86
                this.searchIndicator.IsIndeterminate = false;
81 87
                this.DataContext = this;
82
                tbSearch.Text = "";
88
                //tbSearch.Text = "";
83 89
                tbSearch.Focus();
84
                DialogMessage_Alert("검색이 완료되었습니다.");
85
            }));
86 90

  
91
                txtSearchMsg.Text = "search has completed.";
92
            }));
87 93
        }
88 94
        //private System.Collections.ObjectModel.ObservableCollection<SearchText> searchTexts = null;
89 95
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
......
121 127
            else
122 128
            {
123 129
                int pageCount = extractor.GetPageCount();
130

  
124 131
                for (int i = 0; i < pageCount; i++)
125 132
                {
126
                    Bytescout.PDFExtractor.OCRAnalysisResults analysisResults = ocrAnalyzer.AnalyzeByOCRConfidence(i);
133
                    txtSearchMsg.Dispatcher.Invoke(()=> txtSearchMsg.Text = $"Search Pages {i + 1}/{pageCount}");
134

  
135
                    //Bytescout.PDFExtractor.OCRAnalysisResults analysisResults = ocrAnalyzer.AnalyzeByOCRConfidence(i);
127 136
                    //ocrAnalyzer.ApplyResults(analysisResults, extractor);
128 137
                    if (extractor.Find(i, searchString, false))
129 138
                        do
......
132 141
                            {
133 142
                                SearchSet.Add(new SearchText { PageNo = i + 1, searchResult = extractor.FoundText });
134 143
                            }));
144

  
145
                            if(IsCancelWork)
146
                            {
147
                                break;
148
                            }
135 149
                        }
136 150
                        while (extractor.FindNext());
151

  
152
                    if (IsCancelWork)
153
                    {
154
                        break;
155
                    }
137 156
                }
138 157
            }
139 158
        }
......
154 173
                extractor.OCRMode = Bytescout.PDFExtractor.OCRMode.Auto;
155 174
                extractor.OCRLanguage = "eng";
156 175
                extractor.OCRLanguageDataFolder = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "tessdata");
157
                    
176

  
158 177
                extractor.OCRResolution = 300;
159 178

  
160 179
                ocrAnalyzer.OCRLanguage = "eng";
......
167 186
            }
168 187

  
169 188
        }
189

  
170 190
        private void SearchPanel_Loaded(object sender, RoutedEventArgs e)
171 191
        {
192
            ////
193
            /// 이벤트 안 들어옴
194

  
195

  
172 196
            //측정
173 197
            //Stopwatch sw = new Stopwatch();
174 198
            //sw.Start();
......
180 204
            SearchSet = new System.Collections.ObjectModel.ObservableCollection<SearchText>();
181 205
            extractor = new Bytescout.PDFExtractor.TextExtractor(RegistrationName, RegistrationKey);
182 206
            tbSearch.KeyDown += tbSearch_KeyDown;
207

  
183 208
            this.DataContext = this;
184 209

  
185
            if (Common.ViewerDataModel.Instance.searchPDF != null)
186
            {
187
                border_Overlap.Visibility = Visibility.Collapsed;
188
                tbSearch.Focus();
189
            }
190 210
        }
191 211

  
192 212
        private void BtnSearchPDFDownload_Click(object sender, RoutedEventArgs e)
193 213
        {
194 214
            try
195 215
            {
216
                Common.ViewerDataModel.Instance.IsDownloadCancel = true;
217

  
218

  
196 219
                using (System.Net.WebClient client = new System.Net.WebClient())
197 220
                {
198 221
                    string instnaceFile = System.IO.Path.GetTempFileName().Replace(".pdf", ".tmp");
199 222
                    client.DownloadFileCompleted += Client_DownloadFileCompleted;
200 223
                    client.DownloadProgressChanged += Client_DownloadProgressChanged;
201 224
                    string downloadurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.GetOriginalPDFURL();
202
                    client.DownloadFileAsync(new Uri(downloadurl), instnaceFile, instnaceFile);
225

  
226
                    client.DownloadFileAsync(new Uri(downloadurl), instnaceFile);
203 227
                }
204 228
            }
205 229
            catch (Exception ex)
206 230
            {
207
                Logger.sendResLog("BtnSearchPDFDownload_Click", ex.Message, 0);
231
                Logger.sendResLog("DownloadOriginalFileAsync", ex.Message, 0);
208 232
            }
209 233
        }
210 234

  
235

  
211 236
        private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
212 237
        {
238
            SetSerachPDFFile(e.UserState.ToString());
239
        }
240

  
241
        public void SetSerachPDFFile(string FileFullPath)
242
        {
213 243
            border_Overlap.Visibility = Visibility.Collapsed;
214
            Common.ViewerDataModel.Instance.searchPDF = new System.IO.FileInfo(e.UserState.ToString());
244
            Common.ViewerDataModel.Instance.searchPDF = new System.IO.FileInfo(FileFullPath);
245
            tbSearch.Focus();
215 246
        }
216 247

  
217 248
        private void Client_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
......
227 258

  
228 259
        private void SearchMethod()
229 260
        {
261
            string _strCancel = "Cancel";  // 나중에 정리 
262

  
230 263
            try
231 264
            {
265
                if (btnSearch.Content.ToString() == _strCancel)
266
                {
267
                    IsCancelWork = true;
268
                }
269

  
232 270
                if (!worker.IsBusy)
233 271
                {
234 272
                    SearchSet.Clear();
235
                    this.searchIndicator.IsBusy = true;
273

  
274
                    this.searchIndicator.IsIndeterminate = true;
275
                    btnSearch.Content = _strCancel;
276

  
236 277
                    worker.RunWorkerAsync();
237 278
                }
238 279
            }
......
302 343
                {
303 344
                    SearchText item = (e.AddedItems[0] as SearchText);
304 345

  
305
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(item.PageNo);
306
                    var width = Convert.ToDouble(Common.ViewerDataModel.Instance.Document_Info[item.PageNo - 1].PAGE_WIDTH);
307
                    var height = Convert.ToDouble(Common.ViewerDataModel.Instance.Document_Info[item.PageNo - 1].PAGE_HEIGHT);
308
                    var widthScale = width / Convert.ToDouble(extractor.GetPageRect_Width(item.PageNo - 1));
309
                    var heightScale = height / Convert.ToDouble(extractor.GetPageRect_Height(item.PageNo - 1));
310

  
311
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.zoomAndPanControl.ZoomTo(new Rect
346
                    if (Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber == item.PageNo)
347
                    {
348
                        GotoPosition(item);
349
                    }
350
                    else
312 351
                    {
313
                        X = item.searchResult.Left * widthScale,
314
                        Y = item.searchResult.Top * heightScale,
315
                        Width = item.searchResult.Width * widthScale,
316
                        Height = item.searchResult.Height * heightScale
317
                    });
352
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(item.PageNo);
318 353

  
354
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.PageChanged += (snd, evt) =>
355
                        {
356
                            GotoPosition(item);
357
                        };
358
                    }
319 359
                }
320 360
            }
321 361
            catch (Exception ex)
......
324 364
            }
325 365

  
326 366
        }
367

  
368
        private void GotoPosition(SearchText item)
369
        {
370
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Dispatcher.Invoke(() => {
371

  
372
                var width = Convert.ToDouble(Common.ViewerDataModel.Instance.Document_Info[item.PageNo - 1].PAGE_WIDTH);
373
                var height = Convert.ToDouble(Common.ViewerDataModel.Instance.Document_Info[item.PageNo - 1].PAGE_HEIGHT);
374
                var widthScale = width / Convert.ToDouble(extractor.GetPageRect_Width(item.PageNo - 1));
375
                var heightScale = height / Convert.ToDouble(extractor.GetPageRect_Height(item.PageNo - 1));
376

  
377
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.zoomAndPanControl.ZoomTo(new Rect
378
                {
379
                    X =item.searchResult.Left * widthScale,
380
                    Y = item.searchResult.Top * heightScale,
381
                    Width = ( item.searchResult.Width * widthScale *7),
382
                    Height = (item.searchResult.Height * heightScale *7)
383
                });
384
            });
385
        }
327 386
    }
328 387
}

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)