1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        frequenciesdialog.cpp
3 // Purpose:
4 // Author:      Brett Bode
5 // Modified by:
6 // Created:     Wed 31 May 2006 12:01:12 PM CDT
7 // RCS-ID:
8 // Copyright:   (c) 2006 Iowa State University
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11 
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "frequenciesdialog.h"
14 #endif
15 #include "Globals.h"
16 
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
19 
20 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23 
24 #ifndef WX_PRECOMP
25 #include "wx/wx.h"
26 #endif
27 
28 ////@begin includes
29 ////@end includes
30 
31 #include "MolDisplayWin.h"
32 #include "Frame.h"
33 #include <wx/clipbrd.h>
34 
35 #include "frequenciesdialog.h"
36 
37 ////@begin XPM images
38 ////@end XPM images
39 
40 /*!
41  * FrequenciesDialog type definition
42  */
43 
IMPLEMENT_CLASS(FrequenciesDialog,wxFrame)44 IMPLEMENT_CLASS( FrequenciesDialog, wxFrame )
45 
46 /*!
47  * FrequenciesDialog event table definition
48  */
49 
50 BEGIN_EVENT_TABLE( FrequenciesDialog, wxFrame )
51 ////@begin FrequenciesDialog event table entries
52 	EVT_CLOSE( FrequenciesDialog::OnCloseWindow )
53 	EVT_MENU( wxID_CLOSE, FrequenciesDialog::OnCloseEvent )
54 	EVT_MENU( ID_FREQCOPY, FrequenciesDialog::OnFreqcopyClick )
55 	EVT_MENU( ID_PREVMODE, FrequenciesDialog::OnPrevmodeClick )
56 	EVT_UPDATE_UI( ID_PREVMODE, FrequenciesDialog::OnPrevmodeUpdate )
57 	EVT_MENU( ID_NEXTMODE, FrequenciesDialog::OnNextmodeClick )
58 	EVT_UPDATE_UI( ID_NEXTMODE, FrequenciesDialog::OnNextmodeUpdate )
59 	EVT_MENU( ID_MENUIRINTEN, FrequenciesDialog::OnMenuirintenClick )
60 	EVT_MENU( ID_MENURAMANINTEN, FrequenciesDialog::OnMenuramanintenClick )
61 	EVT_MENU( ID_MENUZOOMIN, FrequenciesDialog::OnMenuzoominClick )
62 	EVT_MENU( ID_MENUZOOMOUT, FrequenciesDialog::OnMenuzoomoutClick )
63 	EVT_LISTBOX( ID_FREQLISTBOX, FrequenciesDialog::OnFreqlistboxSelected )
64 ////@end FrequenciesDialog event table entries
65 	EVT_GRAPH_CLICK(ID_CUSTOM, FrequenciesDialog::OnCustomGraphClick)
66 END_EVENT_TABLE()
67 
68 /*!
69  * FrequenciesDialog constructors
70  */
71 
72 FrequenciesDialog::FrequenciesDialog( )
73 {
74 }
75 
FrequenciesDialog(wxWindow * parent,wxWindowID id,const wxString & caption,const wxPoint & pos,const wxSize & size,long style)76 FrequenciesDialog::FrequenciesDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
77 {
78     Create( parent, id, caption, pos, size, style );
79 }
80 
81 /*!
82  * FrequenciesDialog creator
83  */
84 
Create(wxWindow * parent,wxWindowID id,const wxString & caption,const wxPoint & pos,const wxSize & size,long style)85 bool FrequenciesDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
86 {
87 ////@begin FrequenciesDialog member initialisation
88 	editMenu = NULL;
89 	mFreqListBox = NULL;
90 	fGraph = NULL;
91 ////@end FrequenciesDialog member initialisation
92 
93 ////@begin FrequenciesDialog creation
94 	wxFrame::Create( parent, id, caption, pos, size, style );
95 
96 	CreateControls();
97 	if (GetSizer())
98 	{
99 		GetSizer()->SetSizeHints(this);
100 	}
101 	Centre();
102 ////@end FrequenciesDialog creation
103 	UpdateWindowTitle();
104 
105     RegenData();
106 
107     return true;
108 }
109 
110 /*!
111  * Update the Window title in the event the file is saved
112  */
UpdateWindowTitle(void)113 void FrequenciesDialog::UpdateWindowTitle(void) {
114 	MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
115 	wxString foo = parent->GetTitle();
116 	foo += wxString(_(" ")) + wxString(SYMBOL_FREQUENCIESDIALOG_TITLE);
117 	SetTitle(foo);
118 }
119 
120 /*!
121  * Control creation for FrequenciesDialog
122  */
123 
CreateControls()124 void FrequenciesDialog::CreateControls()
125 {
126 ////@begin FrequenciesDialog content construction
127 	FrequenciesDialog* itemFrame1 = this;
128 
129 	wxMenuBar* menuBar = new wxMenuBar;
130 	wxMenu* itemMenu3 = new wxMenu;
131 	itemMenu3->Append(wxID_NEW, _("&New\tCtrl+N"), _T(""), wxITEM_NORMAL);
132 	itemMenu3->Append(wxID_OPEN, _("&Open ...\tCtrl+O"), _T(""), wxITEM_NORMAL);
133 	itemMenu3->Append(wxID_CLOSE, _("&Close Window\tCtrl+W"), wxEmptyString, wxITEM_NORMAL);
134 	itemMenu3->AppendSeparator();
135 	itemMenu3->Append(wxID_EXIT, _("&Quit\tCtrl+Q"), wxEmptyString, wxITEM_NORMAL);
136 	menuBar->Append(itemMenu3, _("&File"));
137 	editMenu = new wxMenu;
138 	editMenu->Append(ID_FREQCOPY, _("&Copy\tCtrl+C"), wxEmptyString, wxITEM_NORMAL);
139 	editMenu->AppendSeparator();
140 	editMenu->Append(wxID_PREFERENCES, wxT("Global Pr&eferences"), wxT("Edit the default preferences for new windows"));
141 	menuBar->Append(editMenu, _("&Edit"));
142 	wxMenu* itemMenu9 = new wxMenu;
143 	itemMenu9->Append(ID_PREVMODE, _("&Previous Normal Mode\tCtrl+["), wxEmptyString, wxITEM_NORMAL);
144 	itemMenu9->Append(ID_NEXTMODE, _("Ne&xt Normal Mode\tCtrl+]"), wxEmptyString, wxITEM_NORMAL);
145 	itemMenu9->AppendSeparator();
146 	itemMenu9->Append(ID_MENUIRINTEN, _("Show &IR Intensity"), wxEmptyString, wxITEM_RADIO);
147 	itemMenu9->Append(ID_MENURAMANINTEN, _("Show &Raman Intensity"), wxEmptyString, wxITEM_RADIO);
148 	itemMenu9->AppendSeparator();
149 	itemMenu9->Append(ID_MENUZOOMIN, _("Zoom In\tCtrl++"), wxEmptyString, wxITEM_NORMAL);
150 	itemMenu9->Append(ID_MENUZOOMOUT, _("Zoom Out\tCtrl+-"), wxEmptyString, wxITEM_NORMAL);
151 	menuBar->Append(itemMenu9, _("&View"));
152 	itemFrame1->SetMenuBar(menuBar);
153 
154 	wxBoxSizer* itemBoxSizer18 = new wxBoxSizer(wxVERTICAL);
155 	itemFrame1->SetSizer(itemBoxSizer18);
156 
157 	wxPanel* itemPanel19 = new wxPanel( itemFrame1, ID_PANEL4, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL );
158 	itemBoxSizer18->Add(itemPanel19, 1, wxGROW, 0);
159 
160 	wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL);
161 	itemPanel19->SetSizer(itemBoxSizer20);
162 
163 	wxBoxSizer* itemBoxSizer21 = new wxBoxSizer(wxHORIZONTAL);
164 	itemBoxSizer20->Add(itemBoxSizer21, 1, wxGROW|wxALL, 5);
165 
166 	wxArrayString mFreqListBoxStrings;
167 	mFreqListBox = new wxListBox( itemPanel19, ID_FREQLISTBOX, wxDefaultPosition, wxDefaultSize, mFreqListBoxStrings, wxLB_SINGLE );
168 	if (FrequenciesDialog::ShowToolTips())
169 		mFreqListBox->SetToolTip(_("Click the frequency to display the desired mode."));
170 	itemBoxSizer21->Add(mFreqListBox, 0, wxGROW|wxALL, 5);
171 
172 	fGraph = new wxMolGraph( itemPanel19, ID_CUSTOM, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER );
173 	itemBoxSizer21->Add(fGraph, 1, wxGROW|wxALL, 5);
174 
175 ////@end FrequenciesDialog content construction
176     editMenu->Append(wxID_PREFERENCES, wxT("Global Pr&eferences"));
177 
178 	wxMenu * menuWindow = new wxMenu;
179 	menuWindow->Append(MMP_MOLECULEDISPLAYWINDOW, wxT("&Molecule Display"), _("The primary molecule display"));
180 	menuWindow->Append(MMP_BONDSWINDOW, wxT("&Bonds"), _("View/edit the bonding within the molecule"));
181 	menuWindow->Append(MMP_COORDSWINDOW, wxT("&Coordinates"), _("View/edit cartesian or internal coordinates"));
182 	menuWindow->Append(MMP_ENERGYPLOTWINDOW, wxT("&Energy Plot"), _("A plot of the energy for each geometry"));
183 	menuWindow->Append(MMP_INPUTBUILDERWINDOW, wxT("&Input Builder"), _T("Generate a GAMESS input file"));
184 	menuWindow->Append(MMP_SURFACESWINDOW, wxT("&Surfaces"), _T("Add/Edit/Remove various surface types"));
185 	menuWindow->Append(MMP_ZMATRIXCALC, wxT("&Z-Matrix Calculator"), _("Compute bond lengths/angles or dihedrals between any set of atoms"));
186 	menuWindow->Append(MMP_LOCAL_PREFERENCES, wxT("Pr&eferences"), _T("Edit the preferences for this window"));
187 	menuBar->Append(menuWindow, wxT("&Subwindow"));
188 
189 	wxMenu * menuHelp = new wxMenu;
190 	menuHelp->Append(wxID_ABOUT, wxT("&About MacMolPlt..."), _T("Learn about MacMolPlt"));
191 	menuHelp->Append(wxID_HELP, wxT("&MacMolPlt Manual..."), _T("Brief documentation"));
192     menuBar->Append(menuHelp, wxT("&Help"));
193 }
194 
195 /*!
196  * Should we show tooltips?
197  */
198 
ShowToolTips()199 bool FrequenciesDialog::ShowToolTips()
200 {
201     return true;
202 }
203 
204 /*!
205  * Get bitmap resources
206  */
207 
GetBitmapResource(const wxString & name)208 wxBitmap FrequenciesDialog::GetBitmapResource( const wxString& name )
209 {
210     // Bitmap retrieval
211 ////@begin FrequenciesDialog bitmap retrieval
212 	wxUnusedVar(name);
213 	return wxNullBitmap;
214 ////@end FrequenciesDialog bitmap retrieval
215 }
216 
217 /*!
218  * Get icon resources
219  */
220 
GetIconResource(const wxString & name)221 wxIcon FrequenciesDialog::GetIconResource( const wxString& name )
222 {
223     // Icon retrieval
224 ////@begin FrequenciesDialog icon retrieval
225 	wxUnusedVar(name);
226 	return wxNullIcon;
227 ////@end FrequenciesDialog icon retrieval
228 }
229 /*!
230  * wxEVT_CLOSE_WINDOW event handler for ID_FRAME
231  */
232 
FrameChanged(void)233 void FrequenciesDialog::FrameChanged(void) {
234     RegenData();
235     Refresh();
236 }
237 
ModeChanged(void)238 void FrequenciesDialog::ModeChanged(void) {
239     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
240     fGraph->setSelection(0, parent->GetData()->cFrame->Vibs->GetCurrentMode());
241 	mFreqListBox->SetSelection(parent->GetData()->cFrame->Vibs->GetCurrentMode());
242     Refresh();
243 }
244 
RegenData(void)245 void FrequenciesDialog::RegenData(void) {
246     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
247 	WinPrefs * Prefs = parent->GetPrefs();
248 	FrequencyWindowOptions * fprefs = Prefs->GetFrequencyWindowOptions();
249 
250 	bool UseRaman = fprefs->ShowRamanIntensity();
251 
252     VibRec *Vibs = parent->GetData()->cFrame->Vibs;
253 
254 	std::vector< double > xSetData;
255 	std::vector< pair< int, double > > freqData;
256     int i = 0;
257 
258 	mFreqListBox->Clear();
259     fGraph->reset();
260 
261     if(Vibs == NULL) return;
262 	wxString freq;
263 
264     for(i = 0; i < Vibs->GetNumModes(); i++) {
265         xSetData.push_back((double)(Vibs->GetFrequency(i)));
266 		if (UseRaman)
267 			freqData.push_back(make_pair(i, Vibs->GetRamanIntensity(i)));
268 		else
269 			freqData.push_back(make_pair(i, Vibs->GetIntensity(i)));
270 
271 		freq.Printf(wxT("%f"), Vibs->GetFrequency(i));
272 		mFreqListBox->InsertItems(1, &freq, i);
273     }
274     fGraph->addXSet(xSetData, true);
275 
276     fGraph->addYSet(freqData, 0, MG_AXIS_Y1, MG_STYLE_BAR, *wxBLACK);
277 
278     //fGraph->setPrecision(eOpts->GetNumDigits());
279     fGraph->autoScaleY(MG_AXIS_Y1);
280     fGraph->setYAxisMin(MG_AXIS_Y1, 0.0);
281 	fGraph->setYAxisMax(MG_AXIS_Y1, fGraph->getYAxisMax(MG_AXIS_Y1)*fprefs->GetYScaleFactor());
282     fGraph->setXAxisMin(0.0);
283 	if (UseRaman)
284 		fGraph->setAxisLabel(MG_AXIS_Y1, _("Raman Intensity"));
285 	else
286 		fGraph->setAxisLabel(MG_AXIS_Y1, _("IR Intensity"));
287 	fGraph->setAxisLabel(MG_AXIS_X, _("Frequency"));
288     fGraph->setSelection(0, Vibs->GetCurrentMode());
289 	mFreqListBox->SetSelection(Vibs->GetCurrentMode());
290 }
291 
OnCloseWindow(wxCloseEvent & event)292 void FrequenciesDialog::OnCloseWindow( wxCloseEvent& event )
293 {
294 	(void)event;
295     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
296     parent->CloseFrequenciesWindow();
297 }
298 
299 /*!
300  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_COPY
301  */
302 
OnFreqcopyClick(wxCommandEvent & event)303 void FrequenciesDialog::OnFreqcopyClick( wxCommandEvent& event )
304 {
305     int width = 0;
306     int height = 0;
307 	(void)event;
308     fGraph->GetClientSize(&width, &height);
309     wxBitmap tempBmp(width, height);
310     wxMemoryDC tempDC;
311 
312     tempDC.SelectObject(tempBmp);
313     fGraph->draw(tempDC);
314 
315     if (wxTheClipboard->Open()) {
316         wxTheClipboard->SetData(new wxBitmapDataObject(tempBmp));
317         wxTheClipboard->Close();
318     }
319 
320     tempDC.SelectObject(wxNullBitmap);
321 }
322 
323 /*!
324  * wxEVT_GRAPH_CLICK event handler for ID_CUSTOM
325  */
326 
OnCustomGraphClick(wxCommandEvent & event)327 void FrequenciesDialog::OnCustomGraphClick( wxCommandEvent& event )
328 {
329 	(void)event;
330     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
331     MoleculeData *MainData = parent->GetData();
332 
333     if(MainData->cFrame->Vibs) {
334         parent->ChangeModes(fGraph->getSelection(0));
335     }
336 }
337 
338 /*!
339  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_PREVMODE
340  */
341 
OnPrevmodeClick(wxCommandEvent & event)342 void FrequenciesDialog::OnPrevmodeClick( wxCommandEvent& event )
343 {
344 	(void)event;
345     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
346     MoleculeData *MainData = parent->GetData();
347 	if (MainData->cFrame->Vibs) {
348 		if(MainData->cFrame->Vibs->CurrentMode > 0) {
349 			parent->ChangeModes(MainData->cFrame->Vibs->CurrentMode - 1);
350 		}
351 	}
352 }
353 
354 /*!
355  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_NEXTMODE
356  */
357 
OnNextmodeClick(wxCommandEvent & event)358 void FrequenciesDialog::OnNextmodeClick( wxCommandEvent& event )
359 {
360 	(void)event;
361     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
362 	MoleculeData *MainData = parent->GetData();
363 	if (MainData->cFrame->Vibs) {
364 		if(MainData->cFrame->Vibs->CurrentMode < MainData->cFrame->Vibs->NumModes - 1) {
365 			parent->ChangeModes(MainData->cFrame->Vibs->CurrentMode + 1);
366 		}
367 	}
368 }
369 
370 
371 /*!
372  * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_FREQLISTBOX
373  */
374 
OnFreqlistboxSelected(wxCommandEvent & event)375 void FrequenciesDialog::OnFreqlistboxSelected( wxCommandEvent& event )
376 {
377 	int newSelection = mFreqListBox->GetSelection();
378     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
379 
380     VibRec *Vibs = parent->GetData()->cFrame->Vibs;
381 
382     if(Vibs != NULL) {
383 		if (newSelection != Vibs->GetCurrentMode()) {
384 			parent->ChangeModes(newSelection);
385 		}
386 	}
387     event.Skip();
388 }
389 
390 /*!
391  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENUIRINTEN
392  */
393 
OnMenuirintenClick(wxCommandEvent & event)394 void FrequenciesDialog::OnMenuirintenClick( wxCommandEvent& event )
395 {
396 	(void)event;
397     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
398 	WinPrefs * Prefs = parent->GetPrefs();
399 	FrequencyWindowOptions * fprefs = Prefs->GetFrequencyWindowOptions();
400 
401 	fprefs->ShowRamanIntensity(false);
402 	fprefs->ShowIRIntensity(true);
403 
404 	RegenData();	//regenerate the graph with the new intensity
405 }
406 
407 /*!
408  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENURAMANINTEN
409  */
410 
OnMenuramanintenClick(wxCommandEvent & event)411 void FrequenciesDialog::OnMenuramanintenClick( wxCommandEvent& event )
412 {
413 	(void)event;
414 	MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
415 	WinPrefs * Prefs = parent->GetPrefs();
416 	FrequencyWindowOptions * fprefs = Prefs->GetFrequencyWindowOptions();
417 
418 	fprefs->ShowRamanIntensity(true);
419 	fprefs->ShowIRIntensity(false);
420 
421 	RegenData();	//regenerate the graph with the new intensity
422 }
423 
424 /*!
425  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENUITEM1
426  */
OnMenuzoominClick(wxCommandEvent & event)427 void FrequenciesDialog::OnMenuzoominClick( wxCommandEvent& event )
428 {
429 	(void)event;
430     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
431 	WinPrefs * Prefs = parent->GetPrefs();
432 	FrequencyWindowOptions * fprefs = Prefs->GetFrequencyWindowOptions();
433 
434 	fprefs->SetYScaleFactor(0.9*fprefs->GetYScaleFactor());
435 
436 	fGraph->setYAxisMax(MG_AXIS_Y1, fGraph->getYAxisMax(MG_AXIS_Y1)*0.9);
437 
438 	Refresh();
439 }
440 
441 /*!
442  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENUITEM2
443  */
444 
OnMenuzoomoutClick(wxCommandEvent & event)445 void FrequenciesDialog::OnMenuzoomoutClick( wxCommandEvent& event )
446 {
447 	(void)event;
448     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
449 	WinPrefs * Prefs = parent->GetPrefs();
450 	FrequencyWindowOptions * fprefs = Prefs->GetFrequencyWindowOptions();
451 
452 	fprefs->SetYScaleFactor(1.1*fprefs->GetYScaleFactor());
453 
454 	fGraph->setYAxisMax(MG_AXIS_Y1, fGraph->getYAxisMax(MG_AXIS_Y1)*1.1);
455 
456 	Refresh();
457 }
458 
459 
460 /*!
461  * wxEVT_UPDATE_UI event handler for ID_PREVMODE
462  */
463 
OnPrevmodeUpdate(wxUpdateUIEvent & event)464 void FrequenciesDialog::OnPrevmodeUpdate( wxUpdateUIEvent& event )
465 {
466     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
467 	MoleculeData *MainData = parent->GetData();
468 	if (MainData->cFrame->Vibs) {
469 		event.Enable((MainData->cFrame->Vibs->NumModes > 0)&&(MainData->cFrame->Vibs->GetCurrentMode() > 0));
470 	} else event.Enable(false);
471 }
472 
473 
474 /*!
475  * wxEVT_UPDATE_UI event handler for ID_NEXTMODE
476  */
477 
OnNextmodeUpdate(wxUpdateUIEvent & event)478 void FrequenciesDialog::OnNextmodeUpdate( wxUpdateUIEvent& event )
479 {
480     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
481 	MoleculeData *MainData = parent->GetData();
482 	if (MainData->cFrame->Vibs) {
483 		event.Enable((MainData->cFrame->Vibs->NumModes > 0)&&(MainData->cFrame->Vibs->GetCurrentMode() < MainData->cFrame->Vibs->GetNumModes()-1));
484 	} else event.Enable(false);
485 }
486 
487 
488 /*!
489  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_CLOSE
490  */
491 
OnCloseEvent(wxCommandEvent & event)492 void FrequenciesDialog::OnCloseEvent( wxCommandEvent& event )
493 {
494 	(void)event;
495     MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
496     parent->CloseFrequenciesWindow();
497 }
498 
499