| 1 |
// |
| 2 |
// qutemol on wxWidgets MAIN |
| 3 |
// |
| 4 |
// (on DevCpp, download and install "wxWidgets 2.6.1 unicode" DevPak) |
| 5 |
// |
| 6 |
//////////////////////////////////////////////////////////////////// |
| 7 |
|
| 8 |
#define SnapButton 1 |
| 9 |
#define OpenButton 2 |
| 10 |
#define QuitButton 3 |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#include <GL/glew.h> |
| 15 |
|
| 16 |
|
| 17 |
#ifdef __GNUG__ |
| 18 |
#pragma implementation |
| 19 |
#pragma interface |
| 20 |
#endif |
| 21 |
|
| 22 |
// For compilers that support precompilation, includes "wx.h". |
| 23 |
#include "wx/wxprec.h" |
| 24 |
|
| 25 |
#include "wx/image.h" |
| 26 |
#include "wx/stdpaths.h" |
| 27 |
|
| 28 |
//#include <iostream> |
| 29 |
#include <wx/cmdline.h> |
| 30 |
#include <wx/statline.h> |
| 31 |
|
| 32 |
#ifdef __BORLANDC__ |
| 33 |
#pragma hdrstop |
| 34 |
#endif |
| 35 |
|
| 36 |
#ifndef WX_PRECOMP |
| 37 |
#include "wx/wx.h" |
| 38 |
#endif |
| 39 |
|
| 40 |
#if !wxUSE_GLCANVAS |
| 41 |
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library" |
| 42 |
#endif |
| 43 |
|
| 44 |
#include "main.h" |
| 45 |
#ifdef __WXMAC__ |
| 46 |
# ifdef __DARWIN__ |
| 47 |
# include <OpenGL/glu.h> |
| 48 |
# else |
| 49 |
# include <glu.h> |
| 50 |
# endif |
| 51 |
#else |
| 52 |
# include <GL/glu.h> |
| 53 |
#endif |
| 54 |
|
| 55 |
//#include "sample.xpm" |
| 56 |
|
| 57 |
typedef unsigned char Byte; |
| 58 |
typedef unsigned int uint; |
| 59 |
|
| 60 |
#include "CgUtil.h" |
| 61 |
|
| 62 |
#include <math.h> |
| 63 |
|
| 64 |
#include <vector> |
| 65 |
|
| 66 |
#include <vcg/space/point3.h> |
| 67 |
#include <vcg/space/color4.h> |
| 68 |
|
| 69 |
#include "gen_normal.h" |
| 70 |
#include <wrap/gui/trackball.h> |
| 71 |
|
| 72 |
using namespace vcg; |
| 73 |
using namespace std; |
| 74 |
|
| 75 |
#include "CubeMapSamp.h" |
| 76 |
#include "OctaMapSamp.h" |
| 77 |
#include "Mol.h" |
| 78 |
//#include "AOgpu.h" |
| 79 |
|
| 80 |
#include "MyCanvas.h" |
| 81 |
|
| 82 |
#include "ShadowMap.h" |
| 83 |
#include "HardSettings.h" |
| 84 |
|
| 85 |
#include "Common.h" |
| 86 |
|
| 87 |
#include "MyTab.h" |
| 88 |
|
| 89 |
#include "saveSnapDialog.h" |
| 90 |
|
| 91 |
#include "progress.h" |
| 92 |
|
| 93 |
#include "AtomColor.h" |
| 94 |
|
| 95 |
extern vcg::Trackball track; |
| 96 |
extern vcg::Trackball lightTrack; |
| 97 |
|
| 98 |
extern Mol mol; |
| 99 |
|
| 100 |
bool mustDoHQ=false; |
| 101 |
|
| 102 |
#include <wx/dnd.h> |
| 103 |
#include <wx/notebook.h> |
| 104 |
|
| 105 |
wxStopWatch sw; |
| 106 |
|
| 107 |
|
| 108 |
#include "gifSave.h" |
| 109 |
|
| 110 |
// defined in pngSave |
| 111 |
bool PNGSaveWithAlpha( const char * filename, const Byte * data, int sx, int sy, int reverse = 0); |
| 112 |
void downsample2x2(Byte * data, int sx, int sy); |
| 113 |
void downsample2x2NoAlpha(Byte * data, int sx, int sy); |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
wxBitmap *LoadPngImage(wxString st){ |
| 118 |
#ifdef __DARWIN__ |
| 119 |
wxString basePath = wxStandardPaths::Get().GetResourcesDir(); |
| 120 |
wxBitmap* res=new wxBitmap(basePath+_T("/image/")+st+_T(".png"),wxBITMAP_TYPE_PNG); |
| 121 |
#else |
| 122 |
wxBitmap* res=new wxBitmap(_T("image/")+st+_T(".png"),wxBITMAP_TYPE_PNG); |
| 123 |
#endif |
| 124 |
//wxBitmap* res=new wxBitmap(st,wxBITMAP_TYPE_PNG_RESOURCE); |
| 125 |
|
| 126 |
// Marke all black pixels as transparent (useful for Windows NT only) |
| 127 |
//res->SetMask(new wxMask(*res, wxColor(0,0,0))); |
| 128 |
|
| 129 |
return res; |
| 130 |
} |
| 131 |
|
| 132 |
void MyTab::SceneChanged(){ |
| 133 |
((TestGLCanvas*)frame2redraw)->SceneChanged(); |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
void TestGLCanvas::SceneChanged(){ |
| 138 |
mustDoHQ=false; |
| 139 |
Refresh(false); |
| 140 |
} |
| 141 |
|
| 142 |
void StartTime(){ |
| 143 |
sw.Start(); |
| 144 |
} |
| 145 |
|
| 146 |
long int TakeTime(FILE *f , char *st){ |
| 147 |
long int delta=sw.Time(); |
| 148 |
fprintf(f,"%5ldmsec: %s\n",delta,st); |
| 149 |
//globaltime=timen; |
| 150 |
return delta; |
| 151 |
} |
| 152 |
/*long int TakeTotalTime(){ |
| 153 |
long int timen=getTicks(), delta=timen-startingtime; |
| 154 |
printf("------------------\nTotal time: %5dmsec\n",delta); |
| 155 |
globaltime=timen; |
| 156 |
return delta; |
| 157 |
}*/ |
| 158 |
|
| 159 |
|
| 160 |
long int getTicks(){ |
| 161 |
return 0; |
| 162 |
} |
| 163 |
|
| 164 |
void MyToolbar::SetTitleText(wxString s){ |
| 165 |
#ifndef __DARWIN__ |
| 166 |
titleText->SetLabel(s); |
| 167 |
titleTextSizer->Layout(); |
| 168 |
#endif |
| 169 |
} |
| 170 |
|
| 171 |
class MyDropTarget : public wxFileDropTarget |
| 172 |
{ |
| 173 |
public: |
| 174 |
MyDropTarget(MyFrame *_parent) { parent = _parent; } |
| 175 |
|
| 176 |
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames){ |
| 177 |
parent->OnReadFile(filenames[0]); |
| 178 |
}; |
| 179 |
|
| 180 |
private: |
| 181 |
MyFrame *parent; |
| 182 |
}; |
| 183 |
|
| 184 |
void MyToolbar::OnDrag(wxMouseEvent &event){ |
| 185 |
|
| 186 |
if ( event.LeftDClick()) { |
| 187 |
parent->Maximize( !(parent->IsMaximized()) ); |
| 188 |
} |
| 189 |
|
| 190 |
static int omx, omy; |
| 191 |
int mx, my; |
| 192 |
mx = event.GetX(); |
| 193 |
my = event.GetY(); |
| 194 |
|
| 195 |
if ( event.Dragging() ){ |
| 196 |
if (!(parent->IsMaximized())) { |
| 197 |
CaptureMouse(); |
| 198 |
wxPoint cur=parent->GetPosition(); |
| 199 |
int dx=mx-omx; |
| 200 |
int dy=my-omy; |
| 201 |
cur.x+=dx; |
| 202 |
cur.y+=dy; |
| 203 |
omx=mx-dx; |
| 204 |
omy=my-dy; |
| 205 |
parent->SetPosition( cur ); |
| 206 |
} |
| 207 |
} else { |
| 208 |
omx=mx; omy=my; |
| 209 |
ReleaseMouse(); |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
wxNotebook *notebook; |
| 214 |
|
| 215 |
void MyToolbar::UpdateGearsIcon(){ |
| 216 |
UpdateGearsIcon( mol.DoingAO() ); |
| 217 |
} |
| 218 |
|
| 219 |
void MyToolbar::UpdateGearsIcon(bool b){ |
| 220 |
if (gearPresent==b) return; |
| 221 |
if (!b) gearS->Detach(gear); else gearS->Add(gear); |
| 222 |
gear->Show(b); |
| 223 |
gearS->Layout(); |
| 224 |
gearPresent=b; |
| 225 |
/* |
| 226 |
if (b) |
| 227 |
gear->Raise(); |
| 228 |
else |
| 229 |
gear->Lower();*/ |
| 230 |
} |
| 231 |
|
| 232 |
MyToolbar::MyToolbar(wxTopLevelWindow *_parent, wxWindowID id, |
| 233 |
const wxPoint& pos, |
| 234 |
const wxSize& size, |
| 235 |
long style, |
| 236 |
const wxString& name): wxPanel(_parent, id, pos, size, style, name){ |
| 237 |
|
| 238 |
parent=_parent; |
| 239 |
|
| 240 |
// let's build notebook |
| 241 |
/*wxNotebook **/notebook = new wxNotebook( |
| 242 |
this, id, pos, size, |
| 243 |
0,/*style/*|wxNO_FULL_REPAINT_ON_RESIZE|wxNB_TOP,*/ |
| 244 |
name); |
| 245 |
|
| 246 |
for (int i=0; i<MyTab::Count(); i++) { |
| 247 |
//if (i==2) |
| 248 |
notebook->AddPage(new MyTab(notebook,i), MyTab::Title(i), i==0 ); |
| 249 |
parent->SetBackgroundColour(notebook->GetBackgroundColour()); |
| 250 |
} |
| 251 |
|
| 252 |
#ifndef __DARWIN__ |
| 253 |
wxBitmapButton *snapButton = new wxBitmapButton(this, SnapButton, |
| 254 |
*LoadPngImage(_T("snap_off2")), wxDefaultPosition, wxSize(48,48),0); |
| 255 |
snapButton->SetBitmapSelected(*LoadPngImage(_T("snap_on"))); |
| 256 |
|
| 257 |
wxBitmapButton *openButton = new wxBitmapButton(this, OpenButton, |
| 258 |
*LoadPngImage(_T("open_off2")),wxDefaultPosition, wxSize(48,48),0); |
| 259 |
openButton->SetBitmapSelected(*LoadPngImage(_T("open_on"))); |
| 260 |
#else |
| 261 |
wxBitmapButton *snapButton = new wxBitmapButton(this, SnapButton, |
| 262 |
*LoadPngImage(_T("snap_noborder")), wxDefaultPosition, wxSize(48,48),0); |
| 263 |
wxBitmapButton *openButton = new wxBitmapButton(this, OpenButton, |
| 264 |
*LoadPngImage(_T("open_noborder")),wxDefaultPosition, wxSize(48,48),0); |
| 265 |
|
| 266 |
#endif |
| 267 |
wxBitmapButton *quitButton = new wxBitmapButton(this, QuitButton, |
| 268 |
*LoadPngImage(_T("quitoff")), |
| 269 |
wxDefaultPosition, wxSize(15,16) , 0); |
| 270 |
quitButton->SetBitmapSelected(*LoadPngImage(_T("quiton"))); |
| 271 |
|
| 272 |
wxStaticBitmap *logo = new wxStaticBitmap(this, wxID_ANY, *LoadPngImage(_T("qutemolsm")), wxDefaultPosition ); |
| 273 |
|
| 274 |
gear = new wxStaticBitmap(this, wxID_ANY, *LoadPngImage(_T("gear2")), wxDefaultPosition ); |
| 275 |
|
| 276 |
wxSizer *sizerButtons = new wxBoxSizer( wxVERTICAL ); |
| 277 |
sizerButtons->Add(openButton, 0, wxALL, 1); |
| 278 |
sizerButtons->Add(snapButton, 0, wxALL, 1); |
| 279 |
|
| 280 |
titleText = new wxStaticText(this, wxID_ANY, wxT("")); |
| 281 |
titleText->Disable(); |
| 282 |
|
| 283 |
#ifndef __DARWIN__ |
| 284 |
wxSizer *linesizer1 = new wxBoxSizer(wxVERTICAL); |
| 285 |
|
| 286 |
linesizer1->Add(new wxStaticLine(this),0,wxALL| wxEXPAND, 1); |
| 287 |
linesizer1->Add(new wxStaticLine(this),0,wxALL| wxEXPAND, 1); |
| 288 |
linesizer1->Add(new wxStaticLine(this),0,wxALL| wxEXPAND, 1); |
| 289 |
|
| 290 |
wxSizer *linesizer2 = new wxBoxSizer(wxVERTICAL); |
| 291 |
linesizer2->Add(new wxStaticLine(this),0,wxALL| wxEXPAND, 1); |
| 292 |
linesizer2->Add(new wxStaticLine(this),0,wxALL| wxEXPAND, 1); |
| 293 |
linesizer2->Add(new wxStaticLine(this),0,wxALL| wxEXPAND, 1); |
| 294 |
|
| 295 |
titleTextSizer = new wxBoxSizer(wxHORIZONTAL); |
| 296 |
titleTextSizer->Add(3,3, 0, wxALL, 3); |
| 297 |
titleTextSizer->Add(linesizer1, 1, wxALL|wxALIGN_CENTER_VERTICAL, 0); |
| 298 |
titleTextSizer->Add(titleText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0); |
| 299 |
titleTextSizer->Add(linesizer2, 20, wxALL|wxALIGN_CENTER_VERTICAL, 0); |
| 300 |
titleTextSizer->Add(3,3, 0, wxALL, 3); // spacer |
| 301 |
titleTextSizer->Add(quitButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 2); |
| 302 |
|
| 303 |
#else |
| 304 |
quitButton->Hide(); |
| 305 |
titleText->Hide(); |
| 306 |
#endif |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
wxSizer *imgsizer = new wxBoxSizer(wxHORIZONTAL); |
| 311 |
imgsizer->Add(22,22, 0); |
| 312 |
//imgsizer->Add(1,1, 10); |
| 313 |
imgsizer->Add(logo, 1, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL, 0); // LOGO |
| 314 |
//imgsizer->Add(1,1, 9); |
| 315 |
|
| 316 |
gearS = new wxBoxSizer(wxVERTICAL); |
| 317 |
gearS->Add(22,22,1); |
| 318 |
gearS->Add(gear); |
| 319 |
gearPresent=true; |
| 320 |
|
| 321 |
imgsizer->Add(gearS, 0, wxALL|wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL, 2); // LOGO |
| 322 |
|
| 323 |
wxSizer *topRsizer = new wxBoxSizer(wxVERTICAL); |
| 324 |
#ifndef __DARWIN__ |
| 325 |
topRsizer->Add(titleTextSizer,0, wxALL| wxEXPAND, 0); |
| 326 |
#endif |
| 327 |
topRsizer->Add(imgsizer,1, wxALL| wxEXPAND, 0); |
| 328 |
|
| 329 |
topsizer = new wxBoxSizer(wxHORIZONTAL); |
| 330 |
topsizer->Add(sizerButtons, 0, wxALL, 5); |
| 331 |
topsizer->Add(topRsizer, 1, wxALIGN_TOP| wxALL| wxEXPAND, 0); |
| 332 |
|
| 333 |
|
| 334 |
wxSizer *globalsizer = new wxBoxSizer(wxVERTICAL); |
| 335 |
globalsizer->Add(topsizer, 0, wxALL| wxEXPAND, 0); |
| 336 |
//globalsizer->Add(5, 5, 0, wxALL, 0); // spacer |
| 337 |
globalsizer->Add(notebook, 1, wxALL|wxEXPAND, 0); |
| 338 |
|
| 339 |
SetSizer(globalsizer); |
| 340 |
|
| 341 |
UpdateGearsIcon(false); |
| 342 |
|
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
// `Main program' equivalent, creating windows and returning main app frame |
| 347 |
bool MyApp::OnInit() |
| 348 |
{ |
| 349 |
hardSettings.OnStart(); |
| 350 |
|
| 351 |
cgSettings.SetDefaults(); // <-- quick hack (solves wrong constructor order): |
| 352 |
|
| 353 |
//if (!wxApp::OnInit()) return false; |
| 354 |
|
| 355 |
// questo per caricare salvare PNG... |
| 356 |
wxImage::AddHandler(new wxPNGHandler); |
| 357 |
wxImage::AddHandler(new wxJPEGHandler); |
| 358 |
|
| 359 |
// Create the main frame window |
| 360 |
MyFrame *frame = new MyFrame(NULL, wxT("QuteMol"), |
| 361 |
// wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE //wxRESIZE_BORDER |
| 362 |
#ifdef __DARWIN__ |
| 363 |
wxDefaultPosition, wxDefaultSize,wxDEFAULT_FRAME_STYLE| wxRESIZE_BORDER |
| 364 |
#else |
| 365 |
wxDefaultPosition, wxDefaultSize,wxRESIZE_BORDER |
| 366 |
#endif |
| 367 |
); |
| 368 |
|
| 369 |
/* Make a menubar */ |
| 370 |
|
| 371 |
/* |
| 372 |
// ...or, maybe NOT |
| 373 |
wxMenu *fileMenu = new wxMenu; |
| 374 |
|
| 375 |
fileMenu->Append(wxID_EXIT, wxT("E&xit")); |
| 376 |
fileMenu->Append(wxID_ABOUT, wxT("A&bout")); |
| 377 |
fileMenu->Append(wxID_OPEN, wxT("O&pen")); |
| 378 |
|
| 379 |
wxMenuBar *menuBar = new wxMenuBar; |
| 380 |
menuBar->Append(fileMenu, wxT("&File")); |
| 381 |
|
| 382 |
frame->SetMenuBar(menuBar); |
| 383 |
*/ |
| 384 |
|
| 385 |
frame->SetCanvas( |
| 386 |
new TestGLCanvas( |
| 387 |
frame, wxID_ANY, wxPoint(0,0), wxSize( winx, winy ), wxNO_BORDER //wxSUNKEN_BORDER |
| 388 |
) |
| 389 |
); |
| 390 |
|
| 391 |
// onle TestGLCanvas to process idles... |
| 392 |
wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED); |
| 393 |
frame->SetExtraStyle(wxWS_EX_PROCESS_IDLE ); |
| 394 |
|
| 395 |
MyTab::frame2redraw=frame->GetCanvas(); |
| 396 |
|
| 397 |
frame->SetToolbar( |
| 398 |
new MyToolbar( |
| 399 |
frame, wxID_ANY, wxPoint(winx,0), wxDefaultSize, |
| 400 |
// wxNO_BORDER //wxSUNKEN_BORDER |
| 401 |
wxDEFAULT_FRAME_STYLE |
| 402 |
| |
| 403 |
// wxNO_FULL_REPAINT_ON_RESIZE | |
| 404 |
wxCLIP_CHILDREN | |
| 405 |
wxTAB_TRAVERSAL |
| 406 |
) |
| 407 |
); |
| 408 |
|
| 409 |
wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL); |
| 410 |
sizer->Add(frame->GetCanvas(), 1, wxGROW|wxSHAPED); |
| 411 |
sizer->Add(frame->GetToolbar(), 0, wxGROW); |
| 412 |
frame->SetSizer(sizer); |
| 413 |
|
| 414 |
int tbsize=frame->GetToolbar()->GetBestFittingSize().x; |
| 415 |
frame->GetToolbar()->SetSize(tbsize,winy); |
| 416 |
frame->GetToolbar()->Layout(); |
| 417 |
|
| 418 |
//frame->SetMinSize(wxSize(tbsize+200,200)); |
| 419 |
frame->SetClientSize(wxSize(winx+tbsize,winy)); |
| 420 |
|
| 421 |
static const wxCmdLineEntryDesc cmdLineDesc[] = |
| 422 |
{ |
| 423 |
{ |
| 424 |
wxCMD_LINE_PARAM,_T(""),_T(""),_T("filename.pdb:(molecule to be drawn)"), |
| 425 |
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL |
| 426 |
}, |
| 427 |
{ |
| 428 |
wxCMD_LINE_OPTION,_T("a"),_T(""),_T("filename.art: optional Atom Render Table"), |
| 429 |
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL |
| 430 |
}, |
| 431 |
{ |
| 432 |
wxCMD_LINE_SWITCH,_T("v"),_T(""),_T("don't start, show version name"), |
| 433 |
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL |
| 434 |
}, |
| 435 |
{ wxCMD_LINE_NONE } |
| 436 |
}; |
| 437 |
|
| 438 |
wxCmdLineParser parser(cmdLineDesc, argc, argv); |
| 439 |
|
| 440 |
parser.Parse(); |
| 441 |
|
| 442 |
InitQuteMol( NULL ); |
| 443 |
|
| 444 |
wxString artFilename; |
| 445 |
if (parser.Found(_T("v"))>0) { |
| 446 |
FILE *f=fopen("output.txt", "wt"); |
| 447 |
if (f) { |
| 448 |
fprintf(f,"ver 0.4.1"); |
| 449 |
fclose(f); |
| 450 |
} |
| 451 |
exit(0); |
| 452 |
} |
| 453 |
|
| 454 |
if (parser.Found(_T("a"),&artFilename)>0) { |
| 455 |
if (!readArtFile(artFilename.ToAscii())) { |
| 456 |
wxMessageBox( |
| 457 |
wxString(_T("Error reading art file \"") + artFilename +"\""), |
| 458 |
_T("Error reading art file"), |
| 459 |
wxOK | wxICON_EXCLAMATION, frame); |
| 460 |
exit(0); |
| 461 |
return false; |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
if (parser.GetParamCount()>0) frame->OnReadFile(parser.GetParam(0)); |
| 466 |
/* InitQuteMol( parser.GetParam(0).mb_str(wxConvUTF8) ); |
| 467 |
} else { |
| 468 |
InitQuteMol( NULL ); |
| 469 |
}*/ |
| 470 |
|
| 471 |
/* Show the frame */ |
| 472 |
|
| 473 |
frame->Center(); |
| 474 |
frame->SetDropTarget( new MyDropTarget(frame) ); |
| 475 |
frame->Show(true); |
| 476 |
|
| 477 |
return true; |
| 478 |
} |
| 479 |
void MyFrame::ResetAO(){ |
| 480 |
mol.ResetAO(); |
| 481 |
} |
| 482 |
|
| 483 |
|
| 484 |
IMPLEMENT_APP(MyApp) |
| 485 |
|
| 486 |
BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
| 487 |
//EVT_PAINT(MyFrame::OnPaint) |
| 488 |
#if defined(_WIN32) |
| 489 |
EVT_ERASE_BACKGROUND(MyFrame::OnEraseBackground) |
| 490 |
#endif |
| 491 |
EVT_SIZE(MyFrame::OnSize) |
| 492 |
EVT_BUTTON(OpenButton, MyFrame::OnOpenFile) |
| 493 |
EVT_BUTTON(SnapButton, MyFrame::OnSaveSnap) |
| 494 |
EVT_BUTTON(QuitButton, MyFrame::OnExit) |
| 495 |
EVT_KEY_DOWN(MyFrame::OnKeyDown) |
| 496 |
EVT_KEY_UP(MyFrame::OnKeyUp) |
| 497 |
EVT_IDLE(MyFrame::OnIdle) |
| 498 |
END_EVENT_TABLE() |
| 499 |
|
| 500 |
|
| 501 |
BEGIN_EVENT_TABLE(MyToolbar, wxPanel) |
| 502 |
EVT_MOUSE_EVENTS(MyToolbar::OnDrag) |
| 503 |
END_EVENT_TABLE() |
| 504 |
|
| 505 |
|
| 506 |
void MyFrame::OnKeyUp( wxKeyEvent& event ){ |
| 507 |
m_canvas->OnKeyUp(event); |
| 508 |
} |
| 509 |
|
| 510 |
void MyFrame::OnKeyDown( wxKeyEvent& event ){ |
| 511 |
m_canvas->OnKeyDown(event); |
| 512 |
} |
| 513 |
|
| 514 |
|
| 515 |
/* My frame constructor */ |
| 516 |
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, |
| 517 |
const wxSize& size, long style) |
| 518 |
: wxFrame(frame, wxID_ANY, title, pos, size, style) |
| 519 |
{ |
| 520 |
m_canvas = NULL; |
| 521 |
m_tb= NULL; |
| 522 |
#ifndef __DARWIN__ |
| 523 |
SetIcon(wxIcon(_T("sample"),wxBITMAP_TYPE_ICO_RESOURCE,32,32)); |
| 524 |
#endif |
| 525 |
resize_mode=NATURAL; |
| 526 |
} |
| 527 |
|
| 528 |
//void MyFrame::OnPaint( wxPaintEvent& event ) |
| 529 |
//{ |
| 530 |
// wxFrame::OnPaint(event); |
| 531 |
//} |
| 532 |
|
| 533 |
|
| 534 |
void MyFrame::OnSize(wxSizeEvent& event){ |
| 535 |
|
| 536 |
int w,h; |
| 537 |
GetClientSize(&w,&h); |
| 538 |
int hlogo = m_tb->topsizer->GetMinSize().y + 40; |
| 539 |
if (MyTab::Redispose(h - hlogo )) { |
| 540 |
GetToolbar()->SetSize(200,winy); |
| 541 |
} |
| 542 |
|
| 543 |
if (resize_mode==FORCED ) { |
| 544 |
// TODO: fullscreen resize |
| 545 |
//m_canvas->; |
| 546 |
//m_tb->; |
| 547 |
resize_mode=NATURAL; |
| 548 |
wxFrame::OnSize(event); |
| 549 |
//m_tb->Fit(); |
| 550 |
//m_tb->GetSizer()->RecalcSizes(); |
| 551 |
//GetSizer()->RecalcSizes(); |
| 552 |
//notebook->Layout(); |
| 553 |
//notebook->SetSize(100,100); |
| 554 |
//m_tb->SetSize(100,100); |
| 555 |
//notebook->GetSizer()->RecalcSizes();; |
| 556 |
//m_tb->Layout(); |
| 557 |
//Layout(); |
| 558 |
// Fit(); |
| 559 |
} else |
| 560 |
if (resize_mode==NATURAL ) { |
| 561 |
wxFrame::OnSize(event); |
| 562 |
/* |
| 563 |
GetClientSize(&w,&h); |
| 564 |
int tbsize=GetToolbar()->GetBestFittingSize().x; |
| 565 |
winx=w-tbsize; |
| 566 |
winy=h; |
| 567 |
|
| 568 |
GetToolbar()->SetPosition( wxPoint(winx,0) ); |
| 569 |
GetToolbar()->SetSize(tbsize,winy); |
| 570 |
GetCanvas()->SetSize(winx,winy); |
| 571 |
*/ |
| 572 |
resize_mode=CUSTOM; |
| 573 |
} |
| 574 |
else { |
| 575 |
|
| 576 |
static int oldw=0,oldh=0; |
| 577 |
|
| 578 |
|
| 579 |
int w1=m_tb->GetBestFittingSize().x; |
| 580 |
// |
| 581 |
|
| 582 |
int sx=w-w1, sy=h , s; |
| 583 |
|
| 584 |
if ((oldw==w) && (oldh!=h)) s=sy; else |
| 585 |
if ((oldh==h) && (oldw!=w)) s=sx; else |
| 586 |
s=(sx+sy)/2; |
| 587 |
|
| 588 |
wxSize size=wxSize(s+w1, s); |
| 589 |
resize_mode=NATURAL; |
| 590 |
SetClientSize(size); |
| 591 |
|
| 592 |
//wxFrame::OnSize( event ); |
| 593 |
//wxSizeEvent event2=wxSizeEvent(size); |
| 594 |
//wxFrame::OnSize(event2); |
| 595 |
|
| 596 |
//oldw=w;oldh=h; |
| 597 |
} |
| 598 |
} |
| 599 |
|
| 600 |
void MyFrame::Maximize(bool max){ |
| 601 |
|
| 602 |
//if (custom_resizing) { |
| 603 |
resize_mode=FORCED; |
| 604 |
wxFrame::Maximize(max); |
| 605 |
//} |
| 606 |
} |
| 607 |
|
| 608 |
/* Intercept menu commands */ |
| 609 |
void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) |
| 610 |
{ |
| 611 |
Close(); |
| 612 |
} |
| 613 |
|
| 614 |
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas) |
| 615 |
EVT_SIZE(TestGLCanvas::OnSize) |
| 616 |
EVT_PAINT(TestGLCanvas::OnPaint) |
| 617 |
EVT_ERASE_BACKGROUND(TestGLCanvas::OnEraseBackground) |
| 618 |
EVT_MOUSE_EVENTS(TestGLCanvas::OnMouse) |
| 619 |
EVT_KEY_DOWN(TestGLCanvas::OnKeyDown) |
| 620 |
EVT_KEY_UP(TestGLCanvas::OnKeyUp) |
| 621 |
END_EVENT_TABLE() |
| 622 |
|
| 623 |
TestGLCanvas::TestGLCanvas(wxWindow *_parent, wxWindowID id, |
| 624 |
const wxPoint& pos, const wxSize& size, long style, const wxString& name) |
| 625 |
: wxGLCanvas(_parent, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE, name) |
| 626 |
{ |
| 627 |
initdone=false; |
| 628 |
shownHQ=false; |
| 629 |
} |
| 630 |
|
| 631 |
TestGLCanvas::~TestGLCanvas() |
| 632 |
{ |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
wxString errorMSG(int errcode){ |
| 637 |
wxString res; |
| 638 |
res=_T("OpenGL problems:\n\n"); |
| 639 |
if (errcode&ERRGL_NO_GLEW) { |
| 640 |
res+=_T(" - cannot initialize GLEW:\n "); |
| 641 |
res+= wxString::FromAscii(CgUtil::lasterr); |
| 642 |
res+=_T("\n"); |
| 643 |
} |
| 644 |
if (errcode&ERRGL_NO_FS) res+=_T(" - no Programmable Fragment Shader found\n"); |
| 645 |
if (errcode&ERRGL_NO_VS) res+=_T(" - no Programmable Vertex Shader found\n"); |
| 646 |
if (errcode&ERRGL_NO_FBO_SHADOWMAP) res+=_T(" - cannot initialize FrameBufferObject for shadowmaps\n"); |
| 647 |
if (errcode&ERRGL_NO_FBO_HALO) res+=_T(" - cannot initialize FrameBufferObject for halos\n"); |
| 648 |
if (errcode&ERRGL_NO_FBO_HALO) res+=_T(" - cannot initialize FrameBufferObject for A.O. computation\n"); |
| 649 |
res+=_T("\n(Hint: update graphic card drivers)"); |
| 650 |
return res; |
| 651 |
} |
| 652 |
|
| 653 |
void TestGLCanvas::OnPaint( wxPaintEvent& event ) |
| 654 |
{ |
| 655 |
|
| 656 |
|
| 657 |
/* must always be here */ |
| 658 |
wxPaintDC dc(this); |
| 659 |
|
| 660 |
#ifndef __WXMOTIF__ |
| 661 |
if (!GetContext()) return; |
| 662 |
#endif |
| 663 |
|
| 664 |
SetCurrent(); |
| 665 |
|
| 666 |
if (!initdone) { |
| 667 |
static bool once=false; |
| 668 |
if (!once) { |
| 669 |
once=true; |
| 670 |
int errcode=initGl(); |
| 671 |
if (errcode!=ERRGL_OK){ |
| 672 |
wxMessageBox(errorMSG(errcode), _T("Unrecoverable error: Problems initializing graphics"), wxOK | wxICON_EXCLAMATION, this); |
| 673 |
exit(0); |
| 674 |
} |
| 675 |
else initdone=true; |
| 676 |
} |
| 677 |
} |
| 678 |
|
| 679 |
if (!initdone) wxGLCanvas::OnPaint(event); else |
| 680 |
if (mol.IsReady()) { |
| 681 |
if (mustDoHQ) { |
| 682 |
drawFrame( hardSettings.STILL_QUALITY ); |
| 683 |
shownHQ=true; |
| 684 |
mustDoHQ=false; |
| 685 |
} else { |
| 686 |
drawFrame( hardSettings.MOVING_QUALITY ); |
| 687 |
shownHQ=false; |
| 688 |
} |
| 689 |
SwapBuffers(); |
| 690 |
} |
| 691 |
else { |
| 692 |
clearFrame(); |
| 693 |
SwapBuffers(); |
| 694 |
} |
| 695 |
} |
| 696 |
|
| 697 |
void TestGLCanvas::OnSize(wxSizeEvent& event) |
| 698 |
{ |
| 699 |
|
| 700 |
// this is also necessary to update the context on some platforms |
| 701 |
wxGLCanvas::OnSize(event); |
| 702 |
|
| 703 |
// set GL viewport (not called by wxGLCanvas::OnSize on all platforms...) |
| 704 |
|
| 705 |
GetClientSize(&winx, &winy); |
| 706 |
mainCanvas.SetVideoSize(winx); |
| 707 |
#ifndef __WXMOTIF__ |
| 708 |
if ( GetContext() ) |
| 709 |
#endif |
| 710 |
{ |
| 711 |
SetCurrent(); |
| 712 |
glViewport(0, 0, (GLint) winx, (GLint) winy); |
| 713 |
} |
| 714 |
} |
| 715 |
|
| 716 |
|
| 717 |
void MyFrame::OnEraseBackground(wxEraseEvent& event) |
| 718 |
{ |
| 719 |
wxFrame::OnEraseBackground(event); |
| 720 |
/* Do nothing, to avoid flashing on MSW */ |
| 721 |
} |
| 722 |
|
| 723 |
void TestGLCanvas::OnEraseBackground(wxEraseEvent& event) |
| 724 |
{ |
| 725 |
if (!initdone) wxGLCanvas::OnEraseBackground(event); |
| 726 |
/* Do else do nothing, to avoid flashing on MSW */ |
| 727 |
} |
| 728 |
|
| 729 |
bool wxConsumeTrackBallEvent(wxMouseEvent& event, Trackball &track); |
| 730 |
bool wxConsumeTrackBallEvent(wxKeyEvent& event, bool down, Trackball &track); |
| 731 |
|
| 732 |
void TestGLCanvas::OnKeyUp( wxKeyEvent& event ){ |
| 733 |
wxConsumeTrackBallEvent(event,false,track); |
| 734 |
} |
| 735 |
|
| 736 |
extern int CSIZE; // number of texels for a patch of an aotm |
| 737 |
|
| 738 |
void TestGLCanvas::OnKeyDown( wxKeyEvent& event ){ |
| 739 |
wxConsumeTrackBallEvent(event,true,track); |
| 740 |
#ifdef __DARWIN__ |
| 741 |
wxString path = wxStandardPaths::Get().GetResourcesDir() + "/presets/new.preset"; |
| 742 |
#else |
| 743 |
wxString path = "presets\\new.preset"; |
| 744 |
#endif |
| 745 |
if (event.GetKeyCode() == WXK_F7 ) { |
| 746 |
cgSettings.Save(path.c_str()); |
| 747 |
} |
| 748 |
|
| 749 |
if (event.GetKeyCode() == WXK_F6 ) { |
| 750 |
if (cgSettings.Load(path.c_str())) { |
| 751 |
MyTab::UpdateAll(); |
| 752 |
|
| 753 |
cgSettings.ResetHalo(); |
| 754 |
cgSettings.UpdateShaders(); |
| 755 |
SceneChanged(); |
| 756 |
} |
| 757 |
|
| 758 |
} |
| 759 |
|
| 760 |
if (event.GetKeyCode() == WXK_F5 ) { |
| 761 |
mol.PrepareAOSingleView(); |
| 762 |
SceneChanged(); |
| 763 |
} |
| 764 |
|
| 765 |
if (event.GetKeyCode() == WXK_F2 ) { |
| 766 |
static int status=0; |
| 767 |
status=(status+1) % 5; |
| 768 |
draw_balls = (status==0) || (status==1) || (status==2) ; |
| 769 |
draw_sticks = (status==0) || (status==1) || (status==3) || (status==4) ; |
| 770 |
draw_wireframe_balls= (status==1) ; |
| 771 |
draw_wireframe_sticks= (status==1) || (status==3) ; |
| 772 |
|
| 773 |
SceneChanged(); |
| 774 |
} |
| 775 |
|
| 776 |
if (event.GetKeyCode() == WXK_F1 ) { |
| 777 |
wxString text; |
| 778 |
if (!mol.IsReady() ) text=wxT("(no molecule)"); |
| 779 |
else { |
| 780 |
|
| 781 |
text=wxString( mol.GetMolName(), wxConvUTF8 ).BeforeLast('.') + |
| 782 |
wxT("\n (file: \"")+wxString( mol.filename, wxConvUTF8 ) +wxT("\")\n\n"); |
| 783 |
|
| 784 |
text=text+wxString::Format(wxT("%d atoms\n"),mol.atom.size()); |
| 785 |
|
| 786 |
if (mol.sticks) { |
| 787 |
text=text+wxString::Format(wxT("%d bonds\n"),mol.bond.size()); |
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
text=text+wxString::Format( |
| 792 |
_T("\nUsing:\n Texture size = %dx%d\n Patch size=%dx%d"), |
| 793 |
moltextureCanvas.GetHardRes(), |
| 794 |
moltextureCanvas.GetHardRes(), |
| 795 |
CSIZE,CSIZE |
| 796 |
); |
| 797 |
|
| 798 |
|
| 799 |
} |
| 800 |
wxMessageBox(text, _T("QuteMol - file info"), wxOK | wxICON_INFORMATION, this); |
| 801 |
} |
| 802 |
|
| 803 |
if (event.GetKeyCode() == WXK_F6 ) { |
| 804 |
use_accurate_halo=!use_accurate_halo; |
| 805 |
SceneChanged(); |
| 806 |
} |
| 807 |
|
| 808 |
// temp, should e set auto depending on dist |
| 809 |
if (event.GetKeyCode() == WXK_F2 ) { |
| 810 |
|
| 811 |
cgSettings.P_capping=!cgSettings.P_capping; |
| 812 |
cgSettings.UpdateShaders(); |
| 813 |
SceneChanged(); |
| 814 |
} |
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
| 819 |
{ |
| 820 |
} |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
void MyFrame::OnSaveSnap (wxCommandEvent & event) |
| 825 |
{ |
| 826 |
|
| 827 |
int sx,sy; |
| 828 |
static const wxString FILETYPES = _T( |
| 829 |
"PNG (lossless)|*.png|" |
| 830 |
"JPEG (lossy)|*.jpg|" |
| 831 |
"GIF animation|*.gif" |
| 832 |
); |
| 833 |
wxFileDialog * saveSnapDialog = |
| 834 |
new wxFileDialog ( this, |
| 835 |
wxString (_T("Save a snapshot")), |
| 836 |
wxString(), // def path |
| 837 |
wxString(), |
| 838 |
FILETYPES, |
| 839 |
wxSAVE | /*wxCHANGE_DIR |*/ wxOVERWRITE_PROMPT |
| 840 |
); |
| 841 |
|
| 842 |
static int lastFilterIndex=-1; |
| 843 |
|
| 844 |
if (lastFilterIndex==-1) lastFilterIndex=saveSnapDialog->GetFilterIndex(); |
| 845 |
saveSnapDialog->SetFilterIndex( lastFilterIndex ); |
| 846 |
|
| 847 |
wxString ext; |
| 848 |
if (lastFilterIndex==1) ext=_T(".jpg"); |
| 849 |
else if (lastFilterIndex==2) ext=_T(".gif"); |
| 850 |
else ext=_T(".png"); |
| 851 |
saveSnapDialog->SetFilename( wxString( mol.GetFilenameSnap(), wxConvUTF8 )+ ext ); |
| 852 |
static wxString CANNOT_SAVE = _T("Could not save snap!\n\nYou might try setting\na lower resolution\nor removing AntiAliasing..."); |
| 853 |
if (saveSnapDialog->ShowModal() == wxID_OK) |
| 854 |
if ((new savesnapDialog(this,saveSnapDialog->GetFilterIndex()))->ShowModal() == wxID_OK ) |
| 855 |
{ |
| 856 |
|
| 857 |
|
| 858 |
int jj=saveSnapDialog->GetFilterIndex(); |
| 859 |
lastFilterIndex=jj; |
| 860 |
|
| 861 |
Byte* snap; |
| 862 |
int AAMult=(hardSettings.SNAP_ANTIALIAS)?2:1; |
| 863 |
bool useTransp=(hardSettings.PNG_TRANSPARENT==1) && (jj==0); |
| 864 |
if (jj!=2) { |
| 865 |
|
| 866 |
sx=sy=hardSettings.SNAP_SIZE*AAMult; |
| 867 |
|
| 868 |
if ((useTransp) && (cgSettings.UseHalo()>0)) { |
| 869 |
cgSettings.doingAlphaSnapshot=true; |
| 870 |
cgSettings.ResetHalo(); |
| 871 |
cgSettings.UpdateShaders(); |
| 872 |
} |
| 873 |
|
| 874 |
snap= GetSnapshot(sx,sy, useTransp ); |
| 875 |
|
| 876 |
if (cgSettings.doingAlphaSnapshot) { |
| 877 |
cgSettings.doingAlphaSnapshot=false; |
| 878 |
cgSettings.ResetHalo(); |
| 879 |
cgSettings.UpdateShaders(); |
| 880 |
} |
| 881 |
if (!snap) { |
| 882 |
wxMessageBox(CANNOT_SAVE, _T("OpenGL problems?"), wxOK | wxICON_EXCLAMATION, this); |
| 883 |
return; |
| 884 |
} |
| 885 |
} else sx=sy=hardSettings.GIF_SNAP_SIZE*AAMult; |
| 886 |
{ |
| 887 |
|
| 888 |
wxString fn=saveSnapDialog->GetPath(); |
| 889 |
|
| 890 |
// fix filename Extension |
| 891 |
////////////////////////// |
| 892 |
//wxString ext[3]={ _T("png"), _T("jpg") , _T("png") }; |
| 893 |
//wxString cext=fn.AfterLast('.'); |
| 894 |
//if (cext.CmpNoCase(ext[0])||cext.CmpNoCase(ext[1])) fn=fn.BeforeLast('.'); |
| 895 |
//fn=fn+_T('.')+ext[ jj ]; |
| 896 |
|
| 897 |
switch (jj) { |
| 898 |
case 0: |
| 899 |
case 1: |
| 900 |
if (!useTransp) { |
| 901 |
StartProgress("Saving snap!", 2); |
| 902 |
wxImage snapi(sx,sy,snap); |
| 903 |
if (AAMult!=1) snapi=snapi.Scale(sx/AAMult,sy/AAMult); |
| 904 |
UpdateProgress(1); |
| 905 |
wxBitmap(snapi.Mirror(false)).SaveFile( |
| 906 |
fn, |
| 907 |
(jj==0)?wxBITMAP_TYPE_PNG:wxBITMAP_TYPE_JPEG |
| 908 |
); |
| 909 |
UpdateProgress(2); |
| 910 |
EndProgress(); |
| 911 |
} |
| 912 |
else { |
| 913 |
if (AAMult!=1) downsample2x2(snap, sx, sy); |
| 914 |
PNGSaveWithAlpha((const char*)fn.mb_str(wxConvUTF8),snap,sx/AAMult,sy/AAMult,1); |
| 915 |
}; |
| 916 |
break; |
| 917 |
case 2: { |
| 918 |
GifWrapper gifw; |
| 919 |
int N; |
| 920 |
double totalTime; |
| 921 |
double subStepTime=0; |
| 922 |
double startTime;startTime=hardSettings.GIF_INITIAL_PAUSE/1000.0; |
| 923 |
if (hardSettings.GIF_ANIMATION_MODE==0) { |
| 924 |
N=hardSettings.GIF_ROT_N_FRAMES; |
| 925 |
totalTime=hardSettings.GIF_ROT_MSEC/1000.0; |
| 926 |
} |
| 927 |
if (hardSettings.GIF_ANIMATION_MODE==1) { |
| 928 |
N=hardSettings.GIF_INSP_N_FRAMES; |
| 929 |
totalTime=hardSettings.GIF_INSP_MSEC/1000.0; |
| 930 |
} |
| 931 |
if (hardSettings.GIF_ANIMATION_MODE==2) { |
| 932 |
N=hardSettings.GIF_6SIDES_N_FRAMES*6; |
| 933 |
totalTime=hardSettings.GIF_6SIDES_MSEC*6.0/1000.0; |
| 934 |
subStepTime=hardSettings.GIF_6SIDES_PAUSE/1000.0; |
| 935 |
} |
| 936 |
|
| 937 |
StartProgress("Saving GIF", N); |
| 938 |
for (int i=0; i<N; i++) { |
| 939 |
if (!UpdateProgress(i)) break; |
| 940 |
setAniStep(double(i)/N); |
| 941 |
snap = GetSnapshot(sx,sy, false); |
| 942 |
|
| 943 |
if (!snap) { |
| 944 |
wxMessageBox(CANNOT_SAVE, _T("OpenGL problems?"), wxOK | wxICON_EXCLAMATION, this); |
| 945 |
EndProgress(); |
| 946 |
return; |
| 947 |
} |
| 948 |
|
| 949 |
if (AAMult!=1) downsample2x2NoAlpha(snap, sx, sy); |
| 950 |
gifw.AddFrame(snap, sx/AAMult, sy/AAMult, |
| 951 |
totalTime/N |
| 952 |
+ ( (i==0)?startTime:0) |
| 953 |
+ ( (i%(N/6)==0)?subStepTime:0) |
| 954 |
); |
| 955 |
} |
| 956 |
stopAni(); |
| 957 |
gifw.Save( (const char*)fn.mb_str(wxConvUTF8) ); |
| 958 |
EndProgress(); |
| 959 |
} break; |
| 960 |
} |
| 961 |
|
| 962 |
} |
| 963 |
} |
| 964 |
|
| 965 |
} |
| 966 |
|
| 967 |
|
| 968 |
void MyFrame::OnReadFile (wxString filename) |
| 969 |
{ |
| 970 |
if (mol.ReadPdb((const char*)filename.mb_str(wxConvUTF8) )) { |
| 971 |
if ((mol.natm==0) && (mol.nhetatm!=0)) geoSettings.showHetatm=true; |
| 972 |
MyTab::EnableGeom(); |
| 973 |
UpdateShadowmap(); |
| 974 |
wxString name( mol.GetMolName(), wxConvUTF8 ); |
| 975 |
SetTitle( name.BeforeLast('.')+ _T(" - QuteMol") ); |
| 976 |
m_tb->SetTitleText(name); |
| 977 |
geoSettings.Apply(); |
| 978 |
|
| 979 |
// redo shaders, as texture size could have changed |
| 980 |
cgSettings.UpdateShaders(); |
| 981 |
|
| 982 |
} else { |
| 983 |
wxMessageBox(wxString::FromAscii(QAtom::lastReadError), _T(":-("), wxOK | wxICON_EXCLAMATION, this); |
| 984 |
m_tb->SetTitleText(); |
| 985 |
} |
| 986 |
|
| 987 |
// remake shaders cos texture size could have changed... |
| 988 |
|
| 989 |
|
| 990 |
//theText->LoadFile(openFileDialog->GetFilename()); |
| 991 |
//SetStatusText(GetCurrentFilename(), 0); |
| 992 |
} |
| 993 |
|
| 994 |
|
| 995 |
void MyFrame::OnOpenFile (wxCommandEvent & event) |
| 996 |
{ |
| 997 |
static const wxString FILETYPES = _T( |
| 998 |
"Protein Data Bank molecule (pdb, vdb)|*.pdb;*.vdb|" |
| 999 |
"All files|*.*" |
| 1000 |
); |
| 1001 |
wxFileDialog * openFileDialog = |
| 1002 |
new wxFileDialog ( this, |
| 1003 |
wxString(_T("Open file")), |
| 1004 |
wxString(), // def path |
| 1005 |
wxString(), |
| 1006 |
FILETYPES, |
| 1007 |
wxOPEN | wxFILE_MUST_EXIST/*| wxCHANGE_DIR*/, |
| 1008 |
wxDefaultPosition); |
| 1009 |
|
| 1010 |
if (openFileDialog->ShowModal() == wxID_OK) { |
| 1011 |
OnReadFile( openFileDialog->GetPath() ); |
| 1012 |
} |
| 1013 |
/* wxString filename=openFileDialog->GetFilename(); |
| 1014 |
wxString dir=openFileDialog->GetDirectory();*/ |
| 1015 |
} |
| 1016 |
|
| 1017 |
void MyFrame::OnIdle(wxIdleEvent& event){ |
| 1018 |
if (mol.DoingAO()) { |
| 1019 |
m_tb->UpdateGearsIcon(true); |
| 1020 |
if (mol.PrepareAOstep()) { |
| 1021 |
m_canvas->SceneChanged(); |
| 1022 |
event.RequestMore(false); |
| 1023 |
m_tb->UpdateGearsIcon(false); |
| 1024 |
return; |
| 1025 |
} |
| 1026 |
else event.RequestMore(true); |
| 1027 |
} else { |
| 1028 |
event.RequestMore(false); |
| 1029 |
if (hardSettings.STILL_QUALITY!=hardSettings.MOVING_QUALITY) |
| 1030 |
if (!m_canvas->shownHQ) { |
| 1031 |
m_canvas->shownHQ=true; |
| 1032 |
mustDoHQ=true; |
| 1033 |
m_canvas->Refresh(false); |
| 1034 |
} |
| 1035 |
m_tb->UpdateGearsIcon(false); |
| 1036 |
} |
| 1037 |
} |
| 1038 |
|
| 1039 |
void TestGLCanvas::OnMouse( wxMouseEvent& event ) |
| 1040 |
{ |
| 1041 |
|
| 1042 |
static bool useLightTrack=false; |
| 1043 |
|
| 1044 |
if ( event.m_rightDown || event.m_leftDown || event.m_middleDown ) { |
| 1045 |
if (!HasCapture()) CaptureMouse(); |
| 1046 |
} |
| 1047 |
else if (HasCapture()) ReleaseMouse(); |
| 1048 |
|
| 1049 |
useLightTrack=event.m_rightDown; |
| 1050 |
|
| 1051 |
bool consumed=false; |
| 1052 |
if (useLightTrack) { |
| 1053 |
MovingLightMode=true; |
| 1054 |
if (wxConsumeTrackBallEvent( event, lightTrack)) { |
| 1055 |
SetFocus(); |
| 1056 |
consumed=true; |
| 1057 |
} |
| 1058 |
} else { |
| 1059 |
MovingLightMode=false; |
| 1060 |
if (wxConsumeTrackBallEvent( event, track)) { |
| 1061 |
SetFocus(); |
| 1062 |
consumed=true; |
| 1063 |
} |
| 1064 |
} |
| 1065 |
|
| 1066 |
if ((consumed) && (!event.ButtonUp()) && (!event.ButtonDown())) SceneChanged(); |
| 1067 |
|
| 1068 |
/* if ( event.m_rightUp ) { |
| 1069 |
useLightTrack=false; |
| 1070 |
}*/ |
| 1071 |
|
| 1072 |
} |
| 1073 |
|
| 1074 |
void TestGLCanvas::InitGL() |
| 1075 |
{ |
| 1076 |
initGl(); |
| 1077 |
} |
| 1078 |
|