1 // -*- c-basic-offset: 4 -*-
2
3 /** @file OptimizePanel.cpp
4 *
5 * @brief implementation of OptimizePanel
6 *
7 * @author Pablo d'Angelo <pablo.dangelo@web.de>
8 *
9 * $Id$
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This software is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public
22 * License along with this software. If not, see
23 * <http://www.gnu.org/licenses/>.
24 *
25 */
26
27 #include "hugin_config.h"
28 #include "panoinc_WX.h"
29 #include "panoinc.h"
30 #include "PTWXDlg.h"
31 #include <wx/app.h>
32
33 extern "C" {
34 #include <pano13/filter.h>
35 #include <pano13/queryfeature.h>
36 }
37
38 // Error reporting
39
PTPrintErrorWX(char * fmt,va_list ap)40 static void PTPrintErrorWX(char* fmt, va_list ap)
41 {
42 char message[257];
43
44 vsprintf(message, fmt, ap);
45
46 // MessageBox(GetFocus(), (LPSTR)message, (LPSTR)"", MB_OK | MB_ICONHAND) ;
47 wxMessageBox(wxString(message,wxConvLocal), _("Panorama Tools"), wxOK | wxICON_HAND);
48 }
49
50
51 // Progress report; return false if canceled
52
53
PTProgressWX(int command,char * argument)54 static int PTProgressWX( int command, char* argument ){
55
56 static wxProgressDialog * dlg = 0;
57 // MSG msg;
58 long percent;
59 switch( command ){
60 case _initProgress:
61 if (dlg) {
62 dlg->Destroy();
63 wxTheApp->Yield();
64 dlg = 0;
65 } else {
66 dlg = new wxProgressDialog(_("Panorama Tools"),
67 wxT("\n\n\n"), 100, NULL,
68 wxPD_APP_MODAL | wxPD_CAN_ABORT);
69 if (dlg == 0) {
70 return FALSE;
71 }
72 dlg->Update(0, wxString(argument, wxConvLocal));
73 }
74 return TRUE;
75 case _setProgress:
76 if (dlg) {
77 sscanf(argument,"%ld", &percent);
78 if(percent>100) percent = 100;
79 if(percent<0 ) percent = 0;
80 if (! dlg->Update(percent)) {
81 return FALSE;
82 }
83 }
84 return TRUE;
85 break;
86 case _disposeProgress:
87 if( dlg != 0 )
88 {
89 dlg->Destroy();
90 wxTheApp->Yield();
91 dlg=0;
92 }
93
94 return TRUE;
95
96 case _idleProgress:
97 return TRUE;
98
99 }
100 return TRUE;
101 }
102
103
PTInfoDlgWX(int command,char * argument)104 static int PTInfoDlgWX ( int command, char* argument ) // Display info: same argumenmts as progress
105 {
106 char text[256];
107 static char mainMessage[256];
108
109 static wxProgressDialog * dlg = 0;
110 // MSG msg;
111 switch( command ){
112 case _initProgress:
113 if (dlg) {
114 dlg->Destroy();
115 wxTheApp->Yield();
116 dlg = 0;
117 } else {
118 // we need to ensure that there is are enough lines in the dialog..
119 // create progress dialog
120 dlg = new wxProgressDialog(_("Panorama Tools"),
121 #ifdef __WXMAC__
122 wxT("0123456789012345678901234567890123456789012345\n\n\n\n\n"),
123 #else
124 wxT("0123456789012345678901234567890123456789012345\n\n\n"),
125 #endif
126 100, NULL,
127 wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME);
128 if (dlg == 0) {
129 return FALSE;
130 }
131 dlg->Pulse(wxString(argument, wxConvLocal));
132 }
133 return TRUE;
134 case _setProgress:
135 if (dlg) {
136 if( *argument != 0 )
137 {
138 bool cont;
139
140 if( *argument != '+' )
141 {
142 strcpy( mainMessage, argument );
143 strcpy( text, argument );
144 }
145 else
146 {
147 sprintf( text,"%s%s", mainMessage, &(argument[1]) );
148 }
149 cont = dlg->Pulse(wxString(argument, wxConvLocal));
150 if (! cont) {
151 return FALSE;
152 }
153 }
154 }
155 return TRUE;
156 break;
157 case _disposeProgress:
158 if( dlg != 0 )
159 {
160 dlg->Destroy();
161 wxTheApp->Yield();
162 dlg=0;
163 }
164
165 return TRUE;
166
167 case _idleProgress:
168 return TRUE;
169 }
170 return TRUE;
171 }
172
registerPTWXDlgFcn()173 void registerPTWXDlgFcn()
174 {
175 PT_setProgressFcn(&PTProgressWX);
176 PT_setErrorFcn(&PTPrintErrorWX);
177 PT_setInfoDlgFcn(&PTInfoDlgWX);
178 };
179
deregisterPTWXDlgFcn()180 void deregisterPTWXDlgFcn()
181 {
182 PT_setProgressFcn(NULL);
183 PT_setErrorFcn(NULL);
184 PT_setInfoDlgFcn(NULL);
185 }
186
187