1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        exportoptionsdialog.cpp
3 // Purpose:
4 // Author:      Brett Bode
5 // Modified by:
6 // Created:     Thu 11 May 2006 02:46:50 PM CDT
7 // Copyright:   (c) 2006 Iowa State University
8 // Licence:
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
12 #pragma implementation "exportoptionsdialog.h"
13 #endif
14 #include "Globals.h"
15 
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18 
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22 
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26 
27 ////@begin includes
28 ////@end includes
29 #include "MolDisplayWin.h"
30 
31 #include "exportoptionsdialog.h"
32 
33 ////@begin XPM images
34 ////@end XPM images
35 
36 /*!
37  * ExportOptionsDialog type definition
38  */
39 
IMPLEMENT_DYNAMIC_CLASS(ExportOptionsDialog,wxDialog)40 IMPLEMENT_DYNAMIC_CLASS( ExportOptionsDialog, wxDialog )
41 
42 /*!
43  * ExportOptionsDialog event table definition
44  */
45 
46 BEGIN_EVENT_TABLE( ExportOptionsDialog, wxDialog )
47 
48 ////@begin ExportOptionsDialog event table entries
49 	EVT_CHOICE( ID_RES_CHOICE, ExportOptionsDialog::OnResChoiceSelected )
50 	EVT_SPINCTRL( ID_RESWIDTHSPIN, ExportOptionsDialog::OnReswidthspinUpdated )
51 	EVT_SPINCTRL( ID_RESHEIGHTSPIN, ExportOptionsDialog::OnResheightspinUpdated )
52 	EVT_CHECKBOX( ID_CHECKBOX3, ExportOptionsDialog::OnCheckbox3Click )
53 	EVT_RADIOBOX( ID_ANIMATIONRADIO, ExportOptionsDialog::OnAnimationradioSelected )
54 	EVT_BUTTON( wxID_OK, ExportOptionsDialog::OnOkClick )
55 ////@end ExportOptionsDialog event table entries
56 
57 END_EVENT_TABLE()
58 
59 /*!
60  * ExportOptionsDialog constructors
61  */
62 
63 ExportOptionsDialog::ExportOptionsDialog( )
64 {
65 }
66 
ExportOptionsDialog(wxWindow * parent,wxWindowID id,const wxString & caption,const wxPoint & pos,const wxSize & size,long style)67 ExportOptionsDialog::ExportOptionsDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
68 {
69     Create(parent, id, caption, pos, size, style);
70 }
71 
72 /*!
73  * ExportOptionsDialog creator
74  */
75 
Create(wxWindow * parent,wxWindowID id,const wxString & caption,const wxPoint & pos,const wxSize & size,long style)76 bool ExportOptionsDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
77 {
78 ////@begin ExportOptionsDialog member initialisation
79 	panelRes = NULL;
80 	resChoice = NULL;
81 	txt0 = NULL;
82 	resWidthSpin = NULL;
83 	txt1 = NULL;
84 	txt2 = NULL;
85 	resHeightSpin = NULL;
86 	txt3 = NULL;
87 	resTBGCheck = NULL;
88 	mMovieType = NULL;
89 	mEPlotCheck = NULL;
90 ////@end ExportOptionsDialog member initialisation
91     width = 0;
92     height = 0;
93     H2Wratio = 1.0;
94     filetype = 0;
95 
96     ((MolDisplayWin *)parent)->getCanvasSize(&screenWidth, &screenHeight);
97     width = screenWidth;
98     height = screenHeight;
99     H2Wratio = (double)height / (double)width;
100 
101 ////@begin ExportOptionsDialog creation
102     SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
103     wxDialog::Create( parent, id, caption, pos, size, style );
104 
105     CreateControls();
106     GetSizer()->Fit(this);
107     GetSizer()->SetSizeHints(this);
108     Centre();
109 ////@end ExporresWidthTexttOptionsDialog creation
110     resWidthSpin->SetValue(width);
111     resHeightSpin->SetValue(height);
112     return true;
113 }
114 
115 /*!
116  * Control creation for ExportOptionsDialog
117  */
118 
CreateControls()119 void ExportOptionsDialog::CreateControls()
120 {
121 ////@begin ExportOptionsDialog content construction
122 	ExportOptionsDialog* itemDialog1 = this;
123 
124 	wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
125 	itemDialog1->SetSizer(itemBoxSizer2);
126 
127 	panelRes = new wxPanel( itemDialog1, ID_RES_PANEL, wxDefaultPosition, wxDefaultSize, wxNO_BORDER );
128 	itemBoxSizer2->Add(panelRes, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
129 
130 	wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
131 	panelRes->SetSizer(itemBoxSizer4);
132 
133 	wxArrayString resChoiceStrings;
134 	resChoiceStrings.Add(_("72dpi (Screen)"));
135 	resChoiceStrings.Add(_("300dpi (Print)"));
136 	resChoiceStrings.Add(_("Custom"));
137 	resChoice = new wxChoice( panelRes, ID_RES_CHOICE, wxDefaultPosition, wxDefaultSize, resChoiceStrings, 0 );
138 	resChoice->SetStringSelection(_("72dpi (Screen)"));
139 	itemBoxSizer4->Add(resChoice, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
140 
141 	wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
142 	itemBoxSizer4->Add(itemBoxSizer6, 0, wxALIGN_RIGHT, 5);
143 
144 	txt0 = new wxStaticText( panelRes, wxID_STATIC, _("Width:"), wxDefaultPosition, wxDefaultSize, 0 );
145 	itemBoxSizer6->Add(txt0, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5);
146 
147 	resWidthSpin = new wxSpinCtrl( panelRes, ID_RESWIDTHSPIN, wxT("300"), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 999999999, 300 );
148 	itemBoxSizer6->Add(resWidthSpin, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxBOTTOM, 5);
149 
150 	txt1 = new wxStaticText( panelRes, wxID_STATIC, _("pixels"), wxDefaultPosition, wxDefaultSize, 0 );
151 	itemBoxSizer6->Add(txt1, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxBOTTOM, 5);
152 
153 	wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxHORIZONTAL);
154 	itemBoxSizer4->Add(itemBoxSizer10, 0, wxALIGN_RIGHT, 5);
155 
156 	txt2 = new wxStaticText( panelRes, wxID_STATIC, _("Height:"), wxDefaultPosition, wxDefaultSize, 0 );
157 	itemBoxSizer10->Add(txt2, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5);
158 
159 	resHeightSpin = new wxSpinCtrl( panelRes, ID_RESHEIGHTSPIN, wxT("300"), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 999999999, 300 );
160 	itemBoxSizer10->Add(resHeightSpin, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxBOTTOM, 5);
161 
162 	txt3 = new wxStaticText( panelRes, wxID_STATIC, _("pixels"), wxDefaultPosition, wxDefaultSize, 0 );
163 	itemBoxSizer10->Add(txt3, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxBOTTOM, 5);
164 
165 	resTBGCheck = new wxCheckBox( panelRes, ID_CHECKBOX3, _("Enable background transparency"), wxDefaultPosition, wxDefaultSize, 0 );
166 	resTBGCheck->SetValue(false);
167 	resTBGCheck->Enable(false);
168 	itemBoxSizer4->Add(resTBGCheck, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
169 
170 	wxBoxSizer* itemBoxSizer15 = new wxBoxSizer(wxVERTICAL);
171 	itemBoxSizer2->Add(itemBoxSizer15, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
172 
173 	wxArrayString mMovieTypeStrings;
174 	mMovieTypeStrings.Add(_("&Frame Animation"));
175 	mMovieTypeStrings.Add(_("&Normal Mode Animation"));
176 	mMovieType = new wxRadioBox( itemDialog1, ID_ANIMATIONRADIO, _("Animation Type"), wxDefaultPosition, wxDefaultSize, mMovieTypeStrings, 1, wxRA_SPECIFY_ROWS );
177 	mMovieType->SetSelection(0);
178 	itemBoxSizer15->Add(mMovieType, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
179 
180 	mEPlotCheck = new wxCheckBox( itemDialog1, ID_ENERGYPLOTCHECK, _("Include Energy Plot"), wxDefaultPosition, wxDefaultSize, 0 );
181 	mEPlotCheck->SetValue(false);
182 	itemBoxSizer15->Add(mEPlotCheck, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
183 
184 	wxStdDialogButtonSizer* itemStdDialogButtonSizer18 = new wxStdDialogButtonSizer;
185 
186 	itemBoxSizer2->Add(itemStdDialogButtonSizer18, 0, wxALIGN_RIGHT|wxRIGHT|wxTOP|wxBOTTOM, 5);
187 	wxButton* itemButton19 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
188 	itemButton19->SetDefault();
189 	itemStdDialogButtonSizer18->AddButton(itemButton19);
190 
191 	wxButton* itemButton20 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
192 	itemStdDialogButtonSizer18->AddButton(itemButton20);
193 
194 	itemStdDialogButtonSizer18->Realize();
195 
196 ////@end ExportOptionsDialog content construction
197 }
198 
setFileType(int ft)199 void ExportOptionsDialog::setFileType(int ft) {
200     filetype = ft;
201     if((filetype == wxBITMAP_TYPE_PNG)
202 #if wxCHECK_VERSION(2,9,0)
203 	   || (filetype == wxBITMAP_TYPE_GIF) || (filetype == wxBITMAP_TYPE_TIFF)
204 #endif
205 	   ) {
206         resTBGCheck->Enable(true);
207     }
208     else {
209         resTBGCheck->Enable(false);
210     }
211 }
212 
213 /*!
214  * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
215  */
216 
OnOkClick(wxCommandEvent & event)217 void ExportOptionsDialog::OnOkClick( wxCommandEvent& event )
218 {
219 ////@begin wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK in ExportOptionsDialog.
220 	// Before editing this code, remove the block markers.
221 	event.Skip();
222 ////@end wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK in ExportOptionsDialog.
223 }
224 
225 
226 /*!
227  * Should we show tooltips?
228  */
229 
ShowToolTips()230 bool ExportOptionsDialog::ShowToolTips()
231 {
232     return true;
233 }
234 
235 /*!
236  * Get bitmap resources
237  */
238 
GetBitmapResource(const wxString & name)239 wxBitmap ExportOptionsDialog::GetBitmapResource( const wxString& name )
240 {
241     // Bitmap retrieval
242 ////@begin ExportOptionsDialog bitmap retrieval
243 	wxUnusedVar(name);
244 	return wxNullBitmap;
245 ////@end ExportOptionsDialog bitmap retrieval
246 }
247 
248 /*!
249  * Get icon resources
250  */
251 
GetIconResource(const wxString & name)252 wxIcon ExportOptionsDialog::GetIconResource( const wxString& name )
253 {
254     // Icon retrieval
255 ////@begin ExportOptionsDialog icon retrieval
256 	wxUnusedVar(name);
257 	return wxNullIcon;
258 ////@end ExportOptionsDialog icon retrieval
259 }
260 
261 
262 
263 /*!
264  * wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_RES_CHOICE
265  */
266 
OnResChoiceSelected(wxCommandEvent & event)267 void ExportOptionsDialog::OnResChoiceSelected( wxCommandEvent& event )
268 {
269 	(void)event;
270     switch(resChoice->GetSelection()) {
271         case 0:
272             width = screenWidth;
273             height = screenHeight;
274             resWidthSpin->SetValue(width);
275             resHeightSpin->SetValue(height);
276             break;
277         case 1:
278             width = screenWidth * 300 / 72;
279             height = screenHeight * 300 / 72;
280             resWidthSpin->SetValue(width);
281             resHeightSpin->SetValue(height);
282             break;
283         case 2:
284             // TODO:  Nothing?
285             break;
286     }
287 }
288 
289 /*!
290  * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for ID_RESWIDTHSPIN
291  */
292 
OnReswidthspinUpdated(wxSpinEvent & event)293 void ExportOptionsDialog::OnReswidthspinUpdated( wxSpinEvent& event )
294 {
295     long tempWidth = 0;
296 	(void)event;
297 
298     resChoice->SetSelection(2);
299     tempWidth = resWidthSpin->GetValue();
300     if(height != -1) {
301         width = -1;
302         height = (long)(tempWidth * H2Wratio);
303         resHeightSpin->SetValue(height);
304     }
305     width = tempWidth;
306 }
307 
308 /*!
309  * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for ID_RESHEIGHTSPIN
310  */
311 
OnResheightspinUpdated(wxSpinEvent & event)312 void ExportOptionsDialog::OnResheightspinUpdated( wxSpinEvent& event )
313 {
314     long tempHeight = 0;
315 	(void)event;
316 
317     resChoice->SetSelection(2);
318     tempHeight = resHeightSpin->GetValue();
319     if(width != -1) {
320         height = -1;
321         width = (long)(tempHeight / H2Wratio);
322         resWidthSpin->SetValue(width);
323     }
324     height = tempHeight;
325 }
326 
327 
328 
329 /*!
330  * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_CHECKBOX3
331  */
332 
OnCheckbox3Click(wxCommandEvent & event)333 void ExportOptionsDialog::OnCheckbox3Click( wxCommandEvent& event )
334 {
335 	(void)event;
336     transparency = resTBGCheck->GetValue();
337 }
338 
339 /*!
340  * Compute and return the ratio in size between the target output image and the screen image
341  */
342 
getImageRatio() const343 int ExportOptionsDialog::getImageRatio() const
344 {
345     int result;
346 	result = width/screenWidth;
347 	if (result*screenWidth < width) result++;
348 	if (result < 1) result = 1;
349 	return result;
350 }
351 
352 
353 /*!
354  * wxEVT_COMMAND_RADIOBOX_SELECTED event handler for ID_ANIMATIONRADIO
355  */
356 
OnAnimationradioSelected(wxCommandEvent & event)357 void ExportOptionsDialog::OnAnimationradioSelected( wxCommandEvent& event )
358 {
359 	if(event.GetInt() == 0) {
360 		mEPlotCheck->Enable(true);
361 	}
362 	else {
363 		mEPlotCheck->SetValue(false);
364 		mEPlotCheck->Enable(false);
365 	}
366 }
367 
SetMovieChoice(int v)368 void ExportOptionsDialog::SetMovieChoice(int v) {
369 	mMovieType->SetSelection(v);
370 }
371 
EnableFrameMovie(bool v)372 void ExportOptionsDialog::EnableFrameMovie(bool v) {
373 	if(v) {
374 		mMovieType->SetSelection(0);
375 		mMovieType->Enable(0, true);
376 		mEPlotCheck->Enable(true);
377 	}
378 	else {
379 		mMovieType->SetSelection(1);
380 		mMovieType->Enable(0, false);
381 		mEPlotCheck->Enable(false);
382 	}
383 }
384 
EnableModeMovie(bool b)385 void ExportOptionsDialog::EnableModeMovie(bool b) {
386 	mMovieType->SetSelection(0);
387 	mMovieType->Enable(1, b);
388 }
389 
GetMovieChoice(void) const390 int ExportOptionsDialog::GetMovieChoice(void) const {
391 	return mMovieType->GetSelection();
392 }
393 
AddEnergyPlot(void) const394 bool ExportOptionsDialog::AddEnergyPlot(void) const {
395 	return mEPlotCheck->IsChecked();
396 }
397 
398 
399