1 /////////////////////////////////////////////////////////////////////////////
2 // Name: energyplotdialog.cpp
3 // Purpose:
4 // Author: Brett Bode
5 // Modified by:
6 // Created: Tue 23 May 2006 01:34:03 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 "energyplotdialog.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 "Gradient.h"
34 #include <wx/clipbrd.h>
35 #include "colorArea.h"
36
37 #include "energyplotdialog.h"
38 #include <iostream>
39
40 ////@begin XPM images
41 ////@end XPM images
42
43 /*!
44 * EnergyPlotDialog type definition
45 */
46
IMPLEMENT_DYNAMIC_CLASS(EnergyPlotDialog,wxFrame)47 IMPLEMENT_DYNAMIC_CLASS( EnergyPlotDialog, wxFrame )
48
49 /*!
50 * EnergyPlotDialog event table definition
51 */
52
53 BEGIN_EVENT_TABLE( EnergyPlotDialog, wxFrame )
54 ////@begin EnergyPlotDialog event table entries
55 EVT_CLOSE( EnergyPlotDialog::OnCloseWindow )
56 EVT_MENU( wxID_CLOSE, EnergyPlotDialog::OnCloseEvent )
57 EVT_MENU( wxID_COPY, EnergyPlotDialog::OnCopyClick )
58 ////@end EnergyPlotDialog event table entries
59 // Key down should work, but I do not get any key events, so instead tackling from the other
60 // approach using the Char_hook
61 // EVT_KEY_DOWN (EnergyPlotDialog::KeyHandler)
62 EVT_CHAR_HOOK (EnergyPlotDialog::KeyHandler)
63
64 EVT_MENU( wxID_COPY, EnergyPlotDialog::OnCopyClick )
65
66 EVT_AXIS_DCLICK(ID_EPGRAPH, EnergyPlotDialog::OnEpgraphAxisDClick)
67 EVT_GRAPH_CLICK(ID_EPGRAPH, EnergyPlotDialog::OnEpgraphGraphClick)
68 END_EVENT_TABLE()
69
70 /*!
71 * EnergyPlotDialog constructors
72 */
73
74 EnergyPlotDialog::EnergyPlotDialog( )
75 {
76 }
77
EnergyPlotDialog(wxWindow * parent,wxWindowID id,const wxString & caption,const wxPoint & pos,const wxSize & size,long style)78 EnergyPlotDialog::EnergyPlotDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
79 {
80 Create(parent, id, caption, pos, size, style);
81 }
82
83 /*!
84 * EnergyPlotDialog creator
85 */
86
Create(wxWindow * parent,wxWindowID id,const wxString & caption,const wxPoint & pos,const wxSize & size,long style)87 bool EnergyPlotDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
88 {
89 ////@begin EnergyPlotDialog member initialisation
90 epGraph = NULL;
91 ////@end EnergyPlotDialog member initialisation
92
93 ////@begin EnergyPlotDialog 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 EnergyPlotDialog creation
103 UpdateWindowTitle();
104
105 // Add data to epGraph
106 RegenData();
107
108 return true;
109 }
110
111 /*!
112 * Update the Window title in the event the file is saved
113 */
UpdateWindowTitle(void)114 void EnergyPlotDialog::UpdateWindowTitle(void) {
115 MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
116 wxString foo = parent->GetTitle();
117 foo += wxString(_(" ")) + wxString(SYMBOL_ENERGYPLOTDIALOG_TITLE);
118 SetTitle(foo);
119 }
120
121 /*!
122 * Control creation for EnergyPlotDialog
123 */
124
CreateControls()125 void EnergyPlotDialog::CreateControls()
126 {
127 ////@begin EnergyPlotDialog content construction
128 EnergyPlotDialog* itemFrame1 = this;
129
130 wxMenuBar* menuBar = new wxMenuBar;
131 wxMenu* itemMenu3 = new wxMenu;
132 itemMenu3->Append(wxID_NEW, _("&New\tCtrl+N"), _T(""), wxITEM_NORMAL);
133 itemMenu3->Append(wxID_OPEN, _("&Open ...\tCtrl+O"), _T(""), wxITEM_NORMAL);
134 itemMenu3->Append(wxID_CLOSE, _("&Close Window\tCtrl+W"), wxEmptyString, wxITEM_NORMAL);
135 itemMenu3->AppendSeparator();
136 itemMenu3->Append(wxID_EXIT, _("&Quit\tCtrl+Q"), wxEmptyString, wxITEM_NORMAL);
137 menuBar->Append(itemMenu3, _("&File"));
138 wxMenu* itemMenu7 = new wxMenu;
139 itemMenu7->Append(wxID_COPY, _("&Copy\tCtrl+C"), wxEmptyString, wxITEM_NORMAL);
140 itemMenu7->AppendSeparator();
141 itemMenu7->Append(wxID_PREFERENCES, wxT("Global Pr&eferences"), wxT("Edit the default preferences for new windows"));
142 menuBar->Append(itemMenu7, _("&Edit"));
143 itemFrame1->SetMenuBar(menuBar);
144
145 wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxVERTICAL);
146 itemFrame1->SetSizer(itemBoxSizer9);
147
148 wxPanel* itemPanel10 = new wxPanel( itemFrame1, ID_PANEL5, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL );
149 itemBoxSizer9->Add(itemPanel10, 1, wxGROW, 0);
150
151 wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxVERTICAL);
152 itemPanel10->SetSizer(itemBoxSizer11);
153
154 epGraph = new wxMolGraph( itemPanel10, ID_EPGRAPH, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER );
155 itemBoxSizer11->Add(epGraph, 1, wxGROW|wxALL, 5);
156
157 ////@end EnergyPlotDialog content construction
158
159 wxMenu * menuWindow = new wxMenu;
160 menuWindow->Append(MMP_MOLECULEDISPLAYWINDOW, wxT("&Molecule Display"), _("The primary molecule display"));
161 menuWindow->Append(MMP_BONDSWINDOW, wxT("&Bonds"), _("View/edit the bonding within the molecule"));
162 menuWindow->Append(MMP_COORDSWINDOW, wxT("&Coordinates"), _("View/edit cartesian or internal coordinates"));
163 menuWindow->Append(MMP_FREQUENCIESWINDOW, wxT("&Frequencies"), _("Plot the vibrational frequencies"));
164 menuWindow->Append(MMP_INPUTBUILDERWINDOW, wxT("&Input Builder"), _T("Generate a GAMESS input file"));
165 menuWindow->Append(MMP_SURFACESWINDOW, wxT("&Surfaces"), _T("Add/Edit/Remove various surface types"));
166 menuWindow->Append(MMP_ZMATRIXCALC, wxT("&Z-Matrix Calculator"), _("Compute bond lengths/angles or dihedrals between any set of atoms"));
167 menuWindow->Append(MMP_LOCAL_PREFERENCES, wxT("Pr&eferences"), _T("Edit the preferences for this window"));
168 menuBar->Append(menuWindow, wxT("&Subwindow"));
169
170 wxMenu * menuHelp = new wxMenu;
171 menuHelp->Append(wxID_ABOUT, wxT("&About MacMolPlt..."), _T("Learn about MacMolPlt"));
172 menuHelp->Append(wxID_HELP, wxT("&MacMolPlt Manual..."), _T("Brief documentation"));
173 menuBar->Append(menuHelp, wxT("&Help"));
174 }
175
176 /*!
177 * Should we show tooltips?
178 */
179
ShowToolTips()180 bool EnergyPlotDialog::ShowToolTips()
181 {
182 return true;
183 }
184
185 /*!
186 * Get bitmap resources
187 */
188
GetBitmapResource(const wxString & name)189 wxBitmap EnergyPlotDialog::GetBitmapResource( const wxString& name )
190 {
191 // Bitmap retrieval
192 ////@begin EnergyPlotDialog bitmap retrieval
193 wxUnusedVar(name);
194 return wxNullBitmap;
195 ////@end EnergyPlotDialog bitmap retrieval
196 }
197
198 /*!
199 * Get icon resources
200 */
201
GetIconResource(const wxString & name)202 wxIcon EnergyPlotDialog::GetIconResource( const wxString& name )
203 {
204 // Icon retrieval
205 ////@begin EnergyPlotDialog icon retrieval
206 wxUnusedVar(name);
207 return wxNullIcon;
208 ////@end EnergyPlotDialog icon retrieval
209 }
210
FrameChanged(void)211 void EnergyPlotDialog::FrameChanged(void) {
212 MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
213
214 epGraph->setSelection(0, (int)(parent->GetData()->GetCurrentFrame()) - 1);
215 }
216
RegenData(void)217 void EnergyPlotDialog::RegenData(void) {
218 MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
219
220 MoleculeData *mData = parent->GetData();
221 EnergyOptions *eOpts = parent->GetPrefs()->GetEnergyOptions();
222 GraphOptions *gOpts = parent->GetPrefs()->GetGraphOptions();
223
224 vector< double > xSetData;
225 vector< pair< int, double > > totalEnergyData;
226 vector< pair< int, double > > potentialEnergyData;
227 vector< pair< int, double > > mp2EnergyData;
228 vector< pair< int, double > > kineticEnergyData;
229 vector< pair< int, double > > rmsGradData;
230 vector< pair< int, double > > maxGradData;
231 vector< pair< int, double > > bondLenData;
232 vector< pair< int, double > > bondAngleData;
233 Frame *currFrame = NULL;
234 long atom1 = gOpts->Get1stAtom();
235 long atom2 = gOpts->Get2ndAtom();
236 long atom3 = gOpts->Get3rdAtom();
237 int i = 0;
238 int size = (int)(eOpts->GetEPlotPointSize());
239
240
241 epGraph->reset();
242
243 for(currFrame = mData->Frames, i = 0; currFrame != NULL; currFrame = currFrame->NextFrame, i++) {
244 xSetData.push_back((double)(currFrame->time));
245 totalEnergyData.push_back(make_pair(i, currFrame->Energy));
246 potentialEnergyData.push_back(make_pair(i, currFrame->Energy - currFrame->GetKineticEnergy()));
247 mp2EnergyData.push_back(make_pair(i, currFrame->GetMP2Energy()));
248 kineticEnergyData.push_back(make_pair(i, currFrame->GetKineticEnergy()));
249 if(currFrame->Gradient != NULL) rmsGradData.push_back(make_pair(i, (double)(currFrame->Gradient->GetRMS())));
250 if(currFrame->Gradient != NULL) maxGradData.push_back(make_pair(i, (double)(currFrame->Gradient->GetMaximum())));
251 float length;
252 if (currFrame->GetBondLength(atom1, atom2, &length))
253 bondLenData.push_back(make_pair(i, length));
254 float angle;
255 if (currFrame->GetBondAngle(atom1, atom2, atom3, &angle))
256 bondAngleData.push_back(make_pair(i, angle));
257 }
258 epGraph->addXSet(xSetData, true);
259
260 epGraph->addYSet(totalEnergyData, 0, MG_AXIS_Y1, MG_STYLE_POINT_LINE, RGB2WX(*(eOpts->GetTEColor())), MG_SHAPE_CIRCLE, size);
261 epGraph->addYSet(potentialEnergyData, 0, MG_AXIS_Y1, MG_STYLE_POINT_LINE, RGB2WX(*(eOpts->GetPEColor())), MG_SHAPE_CIRCLE, size);
262 epGraph->addYSet(mp2EnergyData, 0, MG_AXIS_Y1, MG_STYLE_POINT_LINE, RGB2WX(*(eOpts->GetMPColor())), MG_SHAPE_CIRCLE, size);
263 epGraph->addYSet(kineticEnergyData, 0, MG_AXIS_Y1, MG_STYLE_POINT_LINE, RGB2WX(*(eOpts->GetKEColor())), MG_SHAPE_CIRCLE, size);
264 epGraph->addYSet(rmsGradData, 0, MG_AXIS_Y2, MG_STYLE_POINT_LINE, RGB2WX(*(eOpts->GetKEColor())), MG_SHAPE_CIRCLE, size);
265 epGraph->addYSet(maxGradData, 0, MG_AXIS_Y2, MG_STYLE_POINT_LINE, RGB2WX(*(eOpts->GetKEColor())), MG_SHAPE_CIRCLE, size);
266 epGraph->addYSet(bondLenData, 0, MG_AXIS_Y2, MG_STYLE_POINT_LINE, RGB2WX(*(eOpts->GetKEColor())), MG_SHAPE_CIRCLE, size);
267 epGraph->addYSet(bondAngleData, 0, MG_AXIS_Y2, MG_STYLE_POINT_LINE, RGB2WX(*(eOpts->GetKEColor())), MG_SHAPE_CIRCLE, size);
268 if(!eOpts->PlotEnergy()) {
269 epGraph->setVisible(0, 0, false);
270 }
271 if(!eOpts->PlotPEnergy()) {
272 epGraph->setVisible(0, 1, false);
273 }
274 if(!eOpts->PlotMPEnergy()) {
275 epGraph->setVisible(0, 2, false);
276 }
277 if(!eOpts->PlotKEnergy()) {
278 epGraph->setVisible(0, 3, false);
279 }
280 if(!gOpts->PlotRMSGradient()) {
281 epGraph->setVisible(0, 4, false);
282 }
283 if(!gOpts->PlotMaxGradient()) {
284 epGraph->setVisible(0, 5, false);
285 }
286
287 if(!gOpts->PlotBondLength()) {
288 epGraph->setVisible(0, 6, false);
289 }
290 if(!gOpts->PlotBondAngle()) {
291 epGraph->setVisible(0, 7, false);
292 }
293
294
295 epGraph->setOffsetY(MG_AXIS_Y1, eOpts->GetY1Zero());
296 epGraph->setOffsetY(MG_AXIS_Y2, eOpts->GetY2Zero());
297 epGraph->setPrecision(eOpts->GetNumDigits());
298 epGraph->autoScaleY(MG_AXIS_Y1);
299 epGraph->autoScaleY(MG_AXIS_Y2);
300 epGraph->setSelection(0, mData->CurrentFrame - 1);
301 }
302
303 /*!
304 * EVT_GRAPH_CLICK event handler for ID_EPGRAPH
305 */
306
OnEpgraphGraphClick(wxCommandEvent & event)307 void EnergyPlotDialog::OnEpgraphGraphClick( wxCommandEvent& event )
308 {
309 (void)event;
310 MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
311
312 parent->ChangeFrames(epGraph->getSelection(0) + 1);
313 }
314
315 /*!
316 * wxEVT_AXIS_DCLICK event handler for ID_EPGRAPH
317 */
318
OnEpgraphAxisDClick(wxCommandEvent & event)319 void EnergyPlotDialog::OnEpgraphAxisDClick( wxCommandEvent& event )
320 {
321 (void)event;
322 ////@begin wxEVT_AXIS_DCLICK event handler for ID_EPGRAPH in EnergyPlotDialog.
323 ////@end wxEVT_AXIS_DCLICK event handler for ID_EPGRAPH in EnergyPlotDialog.
324 }
325
326
327 /*!
328 * wxEVT_CLOSE_WINDOW event handler for ID_ENERGYPLOTDIALOG
329 */
330
OnCloseEvent(wxCommandEvent & event)331 void EnergyPlotDialog::OnCloseEvent( wxCommandEvent& event )
332 {
333 (void)event;
334 MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
335 parent->CloseEnergy_plotWindow();
336 }
337
338
339 /*!
340 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU
341 */
342
OnCopyClick(wxCommandEvent & event)343 void EnergyPlotDialog::OnCopyClick( wxCommandEvent& event )
344 {
345 (void)event;
346 int width = 0;
347 int height = 0;
348 epGraph->GetClientSize(&width, &height);
349 wxBitmap tempBmp(width, height);
350 wxMemoryDC tempDC;
351
352 tempDC.SelectObject(tempBmp);
353 epGraph->draw(tempDC);
354
355 if (wxTheClipboard->Open()) {
356 wxTheClipboard->SetData(new wxBitmapDataObject(tempBmp));
357 wxTheClipboard->Close();
358 }
359
360 tempDC.SelectObject(wxNullBitmap);
361 }
362
CopyToBitMap(wxBitmap ** target)363 void EnergyPlotDialog::CopyToBitMap(wxBitmap ** target) {
364 int width = 0;
365 int height = 0;
366 epGraph->GetClientSize(&width, &height);
367 *target = new wxBitmap(width, height);
368 wxMemoryDC tempDC;
369
370 tempDC.SelectObject(**target);
371 epGraph->draw(tempDC);
372
373 tempDC.SelectObject(wxNullBitmap);
374 }
375
KeyHandler(wxKeyEvent & event)376 void EnergyPlotDialog::KeyHandler(wxKeyEvent & event) {
377 MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
378 int key = event.GetKeyCode();
379 if (!event.HasModifiers()) {
380 switch (key) {
381 case WXK_LEFT:
382 case WXK_RIGHT:
383 case WXK_HOME:
384 case WXK_END:
385 parent->KeyHandler(event);
386 break;
387 }
388 } event.Skip();
389 }
390
391
392 /*!
393 * wxEVT_CLOSE_WINDOW event handler for ID_EPLOTDIALOG
394 */
395
OnCloseWindow(wxCloseEvent & event)396 void EnergyPlotDialog::OnCloseWindow( wxCloseEvent& event )
397 {
398 (void)event;
399 MolDisplayWin *parent = (MolDisplayWin *)this->GetParent();
400 parent->CloseEnergy_plotWindow();
401 }
402
403
404
405