NCBI C++ ToolKit
structure_window.cpp

Search Toolkit Book for ure_window_8cpp_source

Go to the documentation of this file.
1 /* $Id: structure_window.cpp 97176 2022-06-24 15:25:52Z dzhang $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Authors: Paul Thiessen
27 *
28 * File Description:
29 * structure window object for Cn3D
30 *
31 * ===========================================================================
32 */
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbitime.hpp> // avoids some 'CurrentTime' conflict later on...
37 
39 #include <objects/cdd/Cdd.hpp>
41 
42 #include <algorithm>
43 #include <memory>
44 
46 
47 #ifdef __WXMSW__
48 #include <windows.h>
49 #include <wx/msw/winundef.h>
50 #endif
51 #include <wx/wx.h>
52 #include <wx/html/helpfrm.h>
53 #include <wx/html/helpctrl.h>
54 #include <wx/fontdlg.h>
55 #include <wx/confbase.h>
56 #include <wx/fileconf.h>
57 #include <wx/filename.h>
58 #include <wx/choicdlg.h>
59 
60 #include "asn_reader.hpp"
61 #include "cn3d_glcanvas.hpp"
62 #include "structure_window.hpp"
63 #include "structure_set.hpp"
64 #include "opengl_renderer.hpp"
65 #include "style_manager.hpp"
66 #include "messenger.hpp"
67 #include "chemical_graph.hpp"
68 #include "alignment_manager.hpp"
69 #include "show_hide_manager.hpp"
70 #include "show_hide_dialog.hpp"
71 #include "cn3d_tools.hpp"
72 #include "cdd_annot_dialog.hpp"
73 //#include "cdd_ibis_annot_dialog.hpp"
74 #include "preferences_dialog.hpp"
75 #include "cdd_ref_dialog.hpp"
76 #include "cdd_book_ref_dialog.hpp"
77 #include "cn3d_png.hpp"
80 #include "sequence_set.hpp"
81 #include "molecule_identifier.hpp"
82 #include "cdd_splash_dialog.hpp"
83 #include "command_processor.hpp"
84 #include "animation_controls.hpp"
85 #include "cn3d_cache.hpp"
86 #include "dist_select_dialog.hpp"
87 #include "data_manager.hpp"
88 
89 // the application icon (under Windows it is in resources)
90 #if defined(__WXGTK__) || defined(__WXMAC__)
91  #include "cn3d42App.xpm"
92 #endif
93 
96 
97 
98 BEGIN_SCOPE(Cn3D)
99 
100 // global strings
101 static string
102  userDir, // directory of latest user-selected file
103  currentFile; // name of current working file
105 const string& GetUserDir(void) { return userDir; }
106 const string& GetWorkingFilename(void) { return currentFile; }
107 
108 // global working title
109 static string workingTitle;
110 const string& GetWorkingTitle(void) { return workingTitle; }
111 static void SetWorkingTitle(StructureSet *sSet)
112 {
113  if (sSet->IsCDDInMime() && sSet->GetCDDName().size() > 0)
114  workingTitle = sSet->GetCDDName(); // for CDD's sent by server
115  else if (sSet->IsCDD())
116  workingTitle = GetWorkingFilename(); // for CDD's edited by curators
117  else if (sSet->objects.size() > 0) {
118  workingTitle = sSet->objects.front()->GetPDBID();
119  if (sSet->objects.size() > 1)
120  workingTitle += " neighbors";
121  } else
123 }
124 
125 // favorites stuff
126 static bool favoriteStylesChanged = false;
128 static bool LoadFavorites(void);
129 static void SaveFavorites(void);
130 
131 
132 BEGIN_EVENT_TABLE(StructureWindow, wxFrame)
133  EVT_CLOSE ( StructureWindow::OnCloseWindow)
135  EVT_MENU_RANGE(MID_OPEN, MID_NETWORK_OPEN, StructureWindow::OnOpen)
136  EVT_MENU_RANGE(MID_SAVE_SAME, MID_SAVE_AS, StructureWindow::OnSave)
138  EVT_MENU_RANGE(MID_ZOOM_IN, MID_STEREO, StructureWindow::OnAdjustView)
139  EVT_MENU_RANGE(MID_SHOW_HIDE, MID_SHOW_SELECTED_DOMAINS,StructureWindow::OnShowHide)
140  EVT_MENU_RANGE(MID_DIST_SELECT, MID_SELECT_MOLECULE, StructureWindow::OnSelect)
142  EVT_MENU_RANGE(MID_EDIT_STYLE, MID_ANNOTATE, StructureWindow::OnSetStyle)
143  EVT_MENU_RANGE(MID_ADD_FAVORITE, MID_FAVORITES_FILE, StructureWindow::OnEditFavorite)
144  EVT_MENU_RANGE(MID_FAVORITES_BEGIN, MID_FAVORITES_END, StructureWindow::OnSelectFavorite)
145  EVT_MENU_RANGE(MID_SHOW_LOG, MID_SHOW_SEQ_V, StructureWindow::OnShowWindow)
146  EVT_MENU_RANGE(MID_CDD_OVERVIEW, MID_CDD_SHOW_REJECTS, StructureWindow::OnCDD)
147  EVT_MENU (MID_PREFERENCES, StructureWindow::OnPreferences)
148  EVT_MENU_RANGE(MID_OPENGL_FONT, MID_SEQUENCE_FONT, StructureWindow::OnSetFont)
149  EVT_MENU_RANGE(MID_PLAY, MID_ANIM_CONTROLS, StructureWindow::OnAnimate)
150  EVT_MENU_RANGE(MID_HELP_COMMANDS, MID_ONLINE_HELP, StructureWindow::OnHelp)
151  EVT_MENU (MID_ABOUT, StructureWindow::OnHelp)
152  EVT_TIMER (MID_ANIMATE, StructureWindow::OnAnimationTimer)
153  EVT_TIMER (MID_MESSAGING, StructureWindow::OnFileMessagingTimer)
154  EVT_MENU (MID_SEND_SELECTION, StructureWindow::OnSendSelection)
156 
157 StructureWindow::StructureWindow(const wxString& title, const wxPoint& pos, const wxSize& size) :
158  wxFrame(NULL, wxID_HIGHEST + 1, title, pos, size, wxDEFAULT_FRAME_STYLE),
159  glCanvas(NULL), cddAnnotateDialog(NULL), /*ibisAnnotateDialog(NULL),*/ cddDescriptionDialog(NULL), cddNotesDialog(NULL),
160  cddRefDialog(NULL), cddBookRefDialog(NULL), cddOverview(NULL),
161  spinIncrement(3.0), helpController(NULL), helpConfig(NULL),
162  fileMessagingManager("Cn3D"), fileMessenger(NULL)
163 {
165  animationTimer.SetOwner(this, MID_ANIMATE);
166  SetSizeHints(150, 150); // min size
167  SetIcon(wxICON(cn3d));
168 
169  commandProcessor = new CommandProcessor(this);
170 
171  // File menu
172  menuBar = new wxMenuBar;
173  fileMenu = new wxMenu;
174  fileMenu->Append(MID_OPEN, "&Open\tCtrl+O");
175 #ifdef __WXMAC__
176  fileMenu->Append(MID_NETWORK_OPEN, "&Network Load\tCtrl+L");
177 #else
178  fileMenu->Append(MID_NETWORK_OPEN, "&Network Load\tCtrl+N");
179 #endif
180  fileMenu->Append(MID_SAVE_SAME, "&Save\tCtrl+S");
181  fileMenu->Append(MID_SAVE_AS, "Save &As...");
182  fileMenu->Append(MID_PNG, "&Export PNG");
183  fileMenu->AppendSeparator();
184  fileMenu->Append(MID_REFIT_ALL, "&Realign Structures");
185  fileMenu->AppendSeparator();
186  fileMenu->Append(MID_PREFERENCES, "&Preferences...");
187  wxMenu *subMenu = new wxMenu;
188  subMenu->Append(MID_OPENGL_FONT, "S&tructure Window");
189  subMenu->Append(MID_SEQUENCE_FONT, "Se&quence Windows");
190  fileMenu->Append(MID_FONTS, "Set &Fonts...", subMenu);
191  fileMenu->AppendSeparator();
192  fileMenu->Append(MID_EXIT, "E&xit");
193  menuBar->Append(fileMenu, "&File");
194 
195  // View menu
196  wxMenu *menu = new wxMenu;
197  menu->Append(MID_ZOOM_IN, "Zoom &In\tz");
198  menu->Append(MID_ZOOM_OUT, "Zoom &Out\tx");
199  menu->Append(MID_RESTORE, "&Restore");
200  menu->Append(MID_RESET, "Rese&t");
201  menu->AppendSeparator();
202 #ifdef __WXMSW__
203  menu->Append(MID_NEXT_FRAME, "&Next Frame\tRight");
204  menu->Append(MID_PREV_FRAME, "Pre&vious Frame\tLeft");
205  menu->Append(MID_FIRST_FRAME, "&First Frame\tDown");
206  menu->Append(MID_LAST_FRAME, "&Last Frame\tUp");
207 #else
208  // other platforms don't like to display these long accelerator names
209  menu->Append(MID_NEXT_FRAME, "&Next Frame");
210  menu->Append(MID_PREV_FRAME, "Pre&vious Frame");
211  menu->Append(MID_FIRST_FRAME, "&First Frame");
212  menu->Append(MID_LAST_FRAME, "&Last Frame");
213 #endif
214  menu->Append(MID_ALL_FRAMES, "&All Frames\ta");
215  menu->AppendSeparator();
216  subMenu = new wxMenu;
217  subMenu->Append(MID_PLAY, "&Play Frames\tp", "", true);
218  subMenu->Check(MID_PLAY, false);
219  subMenu->Append(MID_SPIN, "Spi&n\tn", "", true);
220  subMenu->Check(MID_SPIN, false);
221  subMenu->Append(MID_STOP, "&Stop\ts", "", true);
222  subMenu->Check(MID_STOP, true);
223  subMenu->AppendSeparator();
224  subMenu->Append(MID_ANIM_CONTROLS, "Set Spee&d");
225  menu->Append(MID_ANIMATE, "Ani&mation", subMenu);
226  menu->AppendSeparator();
227  menu->Append(MID_STEREO, "St&ereo", "", true);
228  menuBar->Append(menu, "&View");
229 
230  // Show-Hide menu
231  menu = new wxMenu;
232  menu->Append(MID_SHOW_HIDE, "&Pick Structures...");
233  menu->AppendSeparator();
234  menu->Append(MID_SHOW_ALL, "Show &Everything\te");
235  menu->Append(MID_SHOW_CHAINS, "Show Aligned C&hains");
236  menu->Append(MID_SHOW_DOMAINS, "Show Aligned &Domains\td");
237  menu->Append(MID_SHOW_ALIGNED, "Show &Aligned Residues");
238  subMenu = new wxMenu;
239  subMenu->Append(MID_SHOW_UNALIGNED_ALL, "Show &All");
240  subMenu->Append(MID_SHOW_UNALIGNED_ALN_DOMAIN, "Show in Aligned &Domains");
241  menu->Append(MID_SHOW_UNALIGNED, "&Unaligned Residues", subMenu);
242  menu->AppendSeparator();
243  menu->Append(MID_SHOW_SELECTED_DOMAINS, "Show Selected Do&mains");
244  menu->Append(MID_SHOW_SELECTED_RESIDUES, "Show &Selected Residues");
245  menu->AppendSeparator();
246  menu->Append(MID_DIST_SELECT, "Select by Dis&tance...");
247  menu->Append(MID_SELECT_CHAIN, "Toggle &Chain...");
248  menu->Append(MID_SELECT_MOLECULE, "Select M&olecule...\tm");
249  menuBar->Append(menu, "Se&lect");
250 
251  // Style menu
252  menu = new wxMenu;
253  menu->Append(MID_EDIT_STYLE, "Edit &Global Style");
254  // favorites
255  favoritesMenu = new wxMenu;
256  favoritesMenu->Append(MID_ADD_FAVORITE, "&Add/Replace");
257  favoritesMenu->Append(MID_REMOVE_FAVORITE, "&Remove");
258  favoritesMenu->Append(MID_FAVORITES_FILE, "&Change File");
259  favoritesMenu->AppendSeparator();
260  LoadFavorites();
261  SetupFavoritesMenu();
262  menu->Append(MID_FAVORITES, "&Favorites", favoritesMenu);
263  // rendering shortcuts
264  subMenu = new wxMenu;
265  subMenu->Append(MID_WORM, "&Worms", "", true);
266  subMenu->Append(MID_TUBE, "&Tubes", "", true);
267  subMenu->Append(MID_WIRE, "Wir&e", "", true);
268  subMenu->Append(MID_BNS, "&Ball and Stick", "", true);
269  subMenu->Append(MID_SPACE, "&Space Fill", "", true);
270  subMenu->AppendSeparator();
271  subMenu->Append(MID_SC_TOGGLE, "&Toggle Sidechains");
272  menu->Append(MID_RENDER, "&Rendering Shortcuts", subMenu);
273  // coloring shortcuts
274  subMenu = new wxMenu;
275  subMenu->Append(MID_SECSTRUC, "&Secondary Structure", "", true);
276  subMenu->Append(MID_ALIGNED, "&Aligned", "", true);
277  wxMenu *subMenu2 = new wxMenu;
278  subMenu2->Append(MID_IDENTITY, "I&dentity", "", true);
279  subMenu2->Append(MID_VARIETY, "&Variety", "", true);
280  subMenu2->Append(MID_WGHT_VAR, "&Weighted Variety", "", true);
281  subMenu2->Append(MID_INFO, "&Information Content", "", true);
282  subMenu2->Append(MID_FIT, "&Fit", "", true);
283  subMenu2->Append(MID_BLOCK_FIT, "&Block Fit", "", true);
284  subMenu2->Append(MID_BLOCK_Z_FIT, "&Normalized Block Fit", "", true);
285  subMenu2->Append(MID_BLOCK_ROW_FIT, "Block &Row Fit", "", true);
286  subMenu->Append(MID_CONS, "Sequence &Conservation", subMenu2);
287  subMenu->Append(MID_OBJECT, "&Object", "", true);
288  subMenu->Append(MID_DOMAIN, "&Domain", "", true);
289  subMenu->Append(MID_MOLECULE, "&Molecule", "", true);
290  subMenu->Append(MID_RESIDUE, "Res&idue", "", true);
291  subMenu->Append(MID_RAINBOW, "&Rainbow", "", true);
292  subMenu->Append(MID_HYDROPHOB, "&Hydrophobicity", "", true);
293  subMenu->Append(MID_CHARGE, "Char&ge", "", true);
294  subMenu->Append(MID_TEMP, "&Temperature", "", true);
295  subMenu->Append(MID_ELEMENT, "&Element", "", true);
296  menu->Append(MID_COLORS, "&Coloring Shortcuts", subMenu);
297  //annotate
298  menu->AppendSeparator();
299  menu->Append(MID_ANNOTATE, "A&nnotate");
300  menuBar->Append(menu, "&Style");
301 
302  // Window menu
303  windowMenu = new wxMenu;
304  windowMenu->Append(MID_SHOW_SEQ_V, "Show &Sequence Viewer");
305  windowMenu->Append(MID_SHOW_LOG, "Show Message &Log");
306  windowMenu->Append(MID_SHOW_LOG_START, "Show Log on Start&up", "", true);
307  bool showLog = false;
309  windowMenu->Check(MID_SHOW_LOG_START, showLog);
310 #ifdef __WXMAC__
311  // Avoid name-clash with standard 'Window' menu added to the Mac application menu bar.
312  menuBar->Append(windowMenu, "Show ...");
313 #else
314  menuBar->Append(windowMenu, "&Window");
315 #endif
316 
317  // CDD menu
318  bool readOnly;
320  menu = new wxMenu;
321  menu->Append(MID_CDD_OVERVIEW, "CDD &Overview");
322  menu->AppendSeparator();
323  menu->Append(MID_EDIT_CDD_NAME, "Edit &Name");
324  menu->Enable(MID_EDIT_CDD_NAME, !readOnly);
325  menu->Append(MID_EDIT_CDD_DESCR, "Edit &Description");
326  menu->Enable(MID_EDIT_CDD_DESCR, !readOnly);
327  menu->Append(MID_EDIT_CDD_NOTES, "Edit No&tes");
328  menu->Enable(MID_EDIT_CDD_NOTES, !readOnly);
329  menu->Append(MID_EDIT_CDD_REFERENCES, "Edit PubMed &References");
330 // menu->Enable(MID_EDIT_CDD_REFERENCES, !readOnly);
331  menu->Append(MID_EDIT_CDD_BOOK_REFERENCES, "Edit &Book References");
332 // menu->Enable(MID_EDIT_CDD_BOOK_REFERENCES, !readOnly);
333  menu->Append(MID_ANNOT_CDD, "Edit &Annotations");
334  menu->Enable(MID_ANNOT_CDD, !readOnly);
335  menu->AppendSeparator();
336 // menu->Append(MID_ANNOT_IBIS, "View Master's &Interactions");
337 // menu->Enable(MID_ANNOT_IBIS, !readOnly);
338  menu->AppendSeparator();
339  menu->Append(MID_CDD_REJECT_SEQ, "Re&ject Sequence");
340  menu->Enable(MID_CDD_REJECT_SEQ, !readOnly);
341  menu->Append(MID_CDD_SHOW_REJECTS, "&Show Rejects");
342  menuBar->Append(menu, "&CDD");
343 
344  // Help menu
345  menu = new wxMenu;
346  menu->Append(MID_HELP_COMMANDS, "&Commands");
347  menu->Append(MID_ONLINE_HELP, "Online &Help...");
348  menu->Append(MID_ABOUT, "&About");
349  menuBar->Append(menu, "&Help");
350 
351  // accelerators for special keys
352  wxAcceleratorEntry entries[12];
353  entries[0].Set(wxACCEL_NORMAL, WXK_RIGHT, MID_NEXT_FRAME);
354  entries[1].Set(wxACCEL_NORMAL, WXK_LEFT, MID_PREV_FRAME);
355  entries[2].Set(wxACCEL_NORMAL, WXK_DOWN, MID_FIRST_FRAME);
356  entries[3].Set(wxACCEL_NORMAL, WXK_UP, MID_LAST_FRAME);
357  entries[4].Set(wxACCEL_NORMAL, 'z', MID_ZOOM_IN);
358  entries[5].Set(wxACCEL_NORMAL, 'x', MID_ZOOM_OUT);
359  entries[6].Set(wxACCEL_NORMAL, 'a', MID_ALL_FRAMES);
360  entries[7].Set(wxACCEL_NORMAL, 'p', MID_PLAY);
361  entries[8].Set(wxACCEL_NORMAL, 'n', MID_SPIN);
362  entries[9].Set(wxACCEL_NORMAL, 's', MID_STOP);
363  entries[10].Set(wxACCEL_NORMAL, 'e', MID_SHOW_ALL);
364  entries[11].Set(wxACCEL_NORMAL, 'd', MID_SHOW_DOMAINS);
365  wxAcceleratorTable accel(12, entries);
366  SetAcceleratorTable(accel);
367 
368  // set menu bar and initial states
369  SetMenuBar(menuBar);
370  menuBar->EnableTop(menuBar->FindMenu("CDD"), false);
371  menuBar->Check(MID_STEREO, false);
372 
373  // Make a GLCanvas
374 #if defined(__WXMSW__)
375  int *attribList = NULL;
376 #elif defined(__WXGTK__)
377  int *attribList = NULL;
378 #elif defined(__WXMAC__)
379  int *attribList = NULL;
380 #endif
381  glCanvas = new Cn3DGLCanvas(this, attribList);
382 
383  // set initial font
384  Show(true); // on X, need to establish gl context first, which requires visible window
385  glCanvas->SetCurrent();
386  glCanvas->SetGLFontFromRegistry();
387 }
388 
390 {
391  delete commandProcessor;
392 }
393 
394 void StructureWindow::OnCloseWindow(wxCloseEvent& event)
395 {
396  animationTimer.Stop();
397  fileMessagingTimer.Stop();
398  ProcessCommand(MID_EXIT);
399 }
400 
401 void StructureWindow::OnExit(wxCommandEvent& event)
402 {
403  animationTimer.Stop();
404  fileMessagingTimer.Stop();
405 
406  GlobalMessenger()->RemoveStructureWindow(this); // don't bother with any redraws since we're exiting
407  GlobalMessenger()->SequenceWindowsSave(true); // save any edited alignment and updates first
408  SaveDialog(true, false); // give structure window a chance to save data
409  SaveFavorites();
410 
411  if (IsFileMessengerActive())
412  SendCommand(messageTargetApp, "Cn3DTerminated", "");
413 
414  // remove help window if present
415  if (helpController) {
416  if (helpController->GetFrame())
417  helpController->GetFrame()->Close(true);
418  wxConfig::Set(NULL);
419  delete helpConfig; // saves data
420  delete helpController;
421  }
422 
424  Destroy();
425 }
426 
428  const std::string& messageApp, bool readOnly)
429 {
430  if (fileMessenger) return;
431 
432  // create messenger
433  fileMessenger = fileMessagingManager.CreateNewFileMessenger(messageFilename, this, readOnly);
434  fileMessagingTimer.SetOwner(this, MID_MESSAGING);
435  fileMessagingTimer.Start(200, false);
436 
437  // add menu item for file messaging selection
438  messageTargetApp = messageApp;
439  windowMenu->AppendSeparator();
440  windowMenu->Append(MID_SEND_SELECTION, (string("Sen&d Selection to ") + messageTargetApp).c_str());
441 }
442 
443 void StructureWindow::OnFileMessagingTimer(wxTimerEvent& event)
444 {
445  // poll message files
446  fileMessagingManager.PollMessageFiles();
447 }
448 
449 void StructureWindow::ReceivedCommand(const std::string& fromApp, unsigned long id,
450  const std::string& command, const std::string& data)
451 {
452  INFOMSG("received command " << id << " from " << fromApp << ": " << command);
453 
454  // default reply - should be changed by CommandProcessor
456  string replyData = "failed to process\n";
457 
458  // actually perform the command functions
459  commandProcessor->ProcessCommand(command, data, &replyStatus, &replyData);
460 
461  // reply
462  INFOMSG("reply: " << ((replyStatus == MessageResponder::REPLY_OKAY) ? "OKAY" : "ERROR"));
463  if (replyData.size() > 0)
464  TRACEMSG("data:\n" << replyData.substr(0, replyData.size() - 1));
465  else
466  TRACEMSG("data: (none)");
467  fileMessenger->SendReply(fromApp, id, replyStatus, replyData);
468 }
469 
470 void StructureWindow::ReceivedReply(const std::string& fromApp, unsigned long id,
471  MessageResponder::ReplyStatus status, const std::string& data)
472 {
473  // just post a message for now; eventually may pass on to CommandProcessor
474  if (status == MessageResponder::REPLY_OKAY)
475  INFOMSG(fromApp << ": got OKAY from " << fromApp << " (command " << id << "), data: " << data);
476  else
477  ERRORMSG(fromApp << ": got ERROR from " << fromApp << " (command " << id << "), data: " << data);
478 }
479 
481  const std::string& command, const std::string& data)
482 {
483  if (!IsFileMessengerActive()) {
484  ERRORMSG("SendCommand: no message file active!");
485  return;
486  }
487 
488  // for now, just assign command id's in numerical order
489  static unsigned long nextCommandID = 1;
490  INFOMSG("sending command " << nextCommandID+1 << " to " << toApp << ": " << command);
491  fileMessenger->SendCommand(toApp, ++nextCommandID, command, data);
492 }
493 
494 void StructureWindow::OnSendSelection(wxCommandEvent& event)
495 {
496  if (!fileMessenger) {
497  ERRORMSG("Can't send messages when return messaging is off");
498  return;
499  }
500 
501  string data;
502  if (GlobalMessenger()->GetHighlightsForSelectionMessage(&data))
503  SendCommand(messageTargetApp, "Select", data);
504 }
505 
507 {
508  SetTitle(wxString(GetWorkingTitle().c_str()) + " - Cn3D " + CN3D_VERSION_STRING);
509 }
510 
511 void StructureWindow::OnHelp(wxCommandEvent& event)
512 {
513  if (event.GetId() == MID_HELP_COMMANDS) {
514  if (!helpController) {
515  wxString path = wxString(GetPrefsDir().c_str()) + "help_cache";
516  if (!wxDirExists(path)) {
517  INFOMSG("trying to create help cache folder " << path.c_str());
518  wxMkdir(path);
519  }
520  helpController = new wxHtmlHelpController(wxHF_DEFAULTSTYLE);
521  helpController->SetTempDir(path);
522  path = path + wxFILE_SEP_PATH + "Config";
523  INFOMSG("saving help config in " << path.c_str());
524  helpConfig = new wxFileConfig("Cn3D", "NCBI", path);
525  wxConfig::Set(helpConfig);
526  helpController->UseConfig(wxConfig::Get());
527 #ifdef __WXMAC__
528  path = wxString(GetProgramDir().c_str()) + "../Resources/cn3d_commands.htb";
529 #else
530  path = wxString(GetProgramDir().c_str()) + "cn3d_commands.htb";
531 #endif
532  if (!helpController->AddBook(path))
533  ERRORMSG("Can't load help book at " << path.c_str());
534  }
535  if (event.GetId() == MID_HELP_COMMANDS)
536  helpController->Display("Cn3D Commands");
537  }
538 
539  else if (event.GetId() == MID_ONLINE_HELP) {
540  LaunchWebPage("https://www.ncbi.nlm.nih.gov/Structure/CN3D/cn3d.shtml");
541  }
542 
543  else if (event.GetId() == MID_ABOUT) {
544  wxString message(
545  "Cn3D version "
547  "\n\n"
548  "Produced by the National Center for Biotechnology Information\n"
549  " https://www.ncbi.nlm.nih.gov\n\n"
550  "Please direct all questions and comments to:\n"
551  " info@ncbi.nlm.nih.gov"
552  );
553  wxMessageBox(message, "About Cn3D", wxOK | wxICON_INFORMATION, this);
554  }
555 }
556 
557 void StructureWindow::OnSelect(wxCommandEvent& event)
558 {
559  if (!glCanvas->structureSet) return;
560 
561  if (event.GetId() == MID_SELECT_MOLECULE) {
562  if (glCanvas->structureSet->objects.size() > 1)
563  return;
564  wxString idStr = wxGetTextFromUser("Enter an MMDB molecule ID or PDB chain:", "Select molecule");
565  if (idStr.size() == 0)
566  return;
567  unsigned long num;
568  bool isNum = idStr.ToULong(&num);
569  if (!isNum)
570  idStr.MakeUpper(); // PDB names are all caps
572  ChemicalGraph::MoleculeMap::const_iterator m, me =
573  glCanvas->structureSet->objects.front()->graph->molecules.end();
574  for (m=glCanvas->structureSet->objects.front()->graph->molecules.begin(); m!=me; ++m) {
575  if ((isNum && m->second->id == (int)num) ||
576  (!isNum && (
577  ((m->second->type == Molecule::eDNA || m->second->type == Molecule::eRNA ||
578  m->second->type == Molecule::eProtein || m->second->type == Molecule::eBiopolymer)
579  && idStr.Cmp(m->second->name.c_str()) == 0) ||
580  ((m->second->type == Molecule::eSolvent || m->second->type == Molecule::eNonpolymer ||
581  m->second->type == Molecule::eOther)
582  && m->second->residues.size() == 1
583  && (((wxString) m->second->residues.begin()->second->
584  nameGraph.c_str()).Strip(wxString::both) == idStr)))))
585  {
586  if (m->second->sequence) {
587  GlobalMessenger()->AddHighlights(m->second->sequence, 0, m->second->sequence->Length() - 1);
588  } else {
589  Molecule::ResidueMap::const_iterator r, re = m->second->residues.end();
590  for (r=m->second->residues.begin(); r!=re; ++r)
591  GlobalMessenger()->ToggleHighlight(m->second, r->second->id);
592  }
593  }
594  }
595  }
596 
597  else if (event.GetId() == MID_SELECT_CHAIN) {
598  vector < string > names;
599  vector < const Molecule * > molecules;
600  StructureSet::ObjectList::const_iterator o, oe = glCanvas->structureSet->objects.end();
601  for (o=glCanvas->structureSet->objects.begin(); o!=oe; ++o) {
602  ChemicalGraph::MoleculeMap::const_iterator m, me = (*o)->graph->molecules.end();
603  for (m=(*o)->graph->molecules.begin(); m!=me; ++m) {
604  if (m->second->residues.size() > 1) {
605  names.push_back((*o)->GetPDBID() + '_' + m->second->name);
606  molecules.push_back(m->second);
607  }
608  }
609  }
610  wxArrayString aChoices;
611  for (unsigned int i=0; i<names.size(); ++i)
612  aChoices.Add(names[i].c_str());
613  wxArrayInt selections;
614  int nSelected = wxGetSelectedChoices(selections, "Choose chain(s) to toggle:", "Select Chain", aChoices);
615  if (nSelected > 0) {
616 // GlobalMessenger()->RemoveAllHighlights(true);
617  for (size_t i=0; i<selections.GetCount(); ++i) {
618  const Molecule *molecule = molecules[selections.Item(i)];
619  Molecule::ResidueMap::const_iterator r, re = molecule->residues.end();
620  for (r=molecule->residues.begin(); r!=re; ++r)
621  GlobalMessenger()->ToggleHighlight(molecule, r->first);
622  }
623  }
624  }
625 
626  else if (event.GetId() == MID_DIST_SELECT) {
627  static double latestCutoff = 5.0;
628  static unsigned int latestOptions = (StructureSet::eSelectProtein | StructureSet::eSelectOtherMoleculesOnly);
629 
630  // setup dialog with initial values
631  DistanceSelectDialog dialog(this);
632  dialog.fpSpinCtrl->SetDouble(latestCutoff);
633  dialog.m_Protein->SetValue((latestOptions & StructureSet::eSelectProtein) > 0);
634  dialog.m_Nucleotide->SetValue((latestOptions & StructureSet::eSelectNucleotide) > 0);
635  dialog.m_Heterogen->SetValue((latestOptions & StructureSet::eSelectHeterogen) > 0);
636  dialog.m_Solvent->SetValue((latestOptions & StructureSet::eSelectSolvent) > 0);
637  dialog.m_Other->SetValue((latestOptions & StructureSet::eSelectOtherMoleculesOnly) > 0);
638 
639  // get user input
640  double cutoff;
641  if (dialog.ShowModal() == wxID_OK && dialog.fpSpinCtrl->GetDouble(&cutoff)) {
642  latestCutoff = cutoff;
643  latestOptions = 0;
644  if (dialog.m_Protein->GetValue())
645  latestOptions |= StructureSet::eSelectProtein;
646  if (dialog.m_Nucleotide->GetValue())
647  latestOptions |= StructureSet::eSelectNucleotide;
648  if (dialog.m_Heterogen->GetValue())
649  latestOptions |= StructureSet::eSelectHeterogen;
650  if (dialog.m_Solvent->GetValue())
651  latestOptions |= StructureSet::eSelectSolvent;
652  if (dialog.m_Other->GetValue())
654  glCanvas->structureSet->SelectByDistance(latestCutoff, latestOptions);
655  }
656  }
657 }
658 
659 void StructureWindow::OnPNG(wxCommandEvent& event)
660 {
662 }
663 
664 void StructureWindow::OnAnimate(wxCommandEvent& event)
665 {
666  if (event.GetId() != MID_ANIM_CONTROLS) {
667  menuBar->Check(MID_PLAY, false);
668  menuBar->Check(MID_SPIN, false);
669  menuBar->Check(MID_STOP, true);
670  }
671  if (!glCanvas->structureSet) return;
672 
673  // play frames
674  if (event.GetId() == MID_PLAY) {
675  if (glCanvas->structureSet->frameMap.size() > 1) {
676  int delay;
678  return;
679  animationTimer.Start(delay, false);
681  menuBar->Check(MID_PLAY, true);
682  menuBar->Check(MID_STOP, false);
683  }
684  }
685 
686  // spin
687  if (event.GetId() == MID_SPIN) {
688  int delay;
691  return;
692  animationTimer.Start(delay, false);
694  menuBar->Check(MID_SPIN, true);
695  menuBar->Check(MID_STOP, false);
696  }
697 
698  // stop
699  else if (event.GetId() == MID_STOP) {
700  animationTimer.Stop();
701  }
702 
703  // controls
704  else if (event.GetId() == MID_ANIM_CONTROLS) {
705  AnimationControls dialog(this);
706  dialog.ShowModal();
707  // restart timer to pick up new settings
708  if (animationTimer.IsRunning()) {
709  animationTimer.Stop();
710  ProcessCommand((animationMode == ANIM_SPIN) ? MID_SPIN : MID_PLAY);
711  }
712  }
713 }
714 
715 void StructureWindow::OnAnimationTimer(wxTimerEvent& event)
716 {
717  if (animationMode == ANIM_FRAMES) {
718  // simply pretend the user selected "next frame"
719  ProcessCommand(MID_NEXT_FRAME);
720  }
721 
722  else if (animationMode == ANIM_SPIN) {
723  // pretend the user dragged the mouse to the right
725  ((int) (spinIncrement / glCanvas->renderer->GetRotateSpeed())), 0);
726  glCanvas->Refresh(false);
727  }
728 }
729 
730 void StructureWindow::OnSetFont(wxCommandEvent& event)
731 {
732  string section, faceName;
733  if (event.GetId() == MID_OPENGL_FONT)
734  section = REG_OPENGL_FONT_SECTION;
735  else if (event.GetId() == MID_SEQUENCE_FONT)
736  section = REG_SEQUENCE_FONT_SECTION;
737  else
738  return;
739 
740  // get initial font info from registry, and create wxFont
741  string nativeFont;
742  RegistryGetString(section, REG_FONT_NATIVE_FONT_INFO, &nativeFont);
743  unique_ptr<wxFont> initialFont(wxFont::New(wxString(nativeFont.c_str())));
744  if (!initialFont.get() || !initialFont->Ok())
745  {
746  ERRORMSG("StructureWindow::OnSetFont() - error setting up initial font");
747  return;
748  }
749  wxFontData initialFontData;
750  initialFontData.SetInitialFont(*initialFont);
751 
752  // bring up font chooser dialog
753  wxFontDialog dialog(this, initialFontData);
754  int result = dialog.ShowModal();
755 
756  // if user selected a font
757  if (result == wxID_OK) {
758 
759  // set registry values appropriately
760  wxFontData& fontData = dialog.GetFontData();
761  wxFont font = fontData.GetChosenFont();
762  if (!RegistrySetString(section, REG_FONT_NATIVE_FONT_INFO, WX_TO_STD(font.GetNativeFontInfoDesc())))
763  {
764  ERRORMSG("StructureWindow::OnSetFont() - error setting registry data");
765  return;
766  }
767 
768  // call font setup
769  INFOMSG("setting new font");
770  if (event.GetId() == MID_OPENGL_FONT) {
771  glCanvas->SetCurrent();
774  } else if (event.GetId() == MID_SEQUENCE_FONT) {
776  }
777  }
778 }
779 
780 static string GetFavoritesFile(bool forRead)
781 {
782  // try to get value from registry
783  string file;
785 
786  // if not set, ask user for a folder, then set in registry
787  if (file == NO_FAVORITES_FILE) {
788  file = wxFileSelector("Select a file for favorites:",
789  GetPrefsDir().c_str(), "Favorites", "", "*.*",
790  (forRead ? wxFD_OPEN : (wxFD_SAVE | wxFD_OVERWRITE_PROMPT))).c_str();
791  if (file.size() > 0)
793  ERRORMSG("Error setting favorites file in registry");
794  }
795 
796  return file;
797 }
798 
799 static bool LoadFavorites(void)
800 {
802 
803  string favoritesFile;
805  if (favoritesFile != NO_FAVORITES_FILE) {
806  if (wxFile::Exists(favoritesFile.c_str())) {
807  INFOMSG("loading favorites from " << favoritesFile);
808  string err;
809  if (ReadASNFromFile(favoritesFile.c_str(), &favoriteStyles, false, &err)) {
810  favoriteStylesChanged = false;
811  return true;
812  }
813  ERRORMSG("Error loading from favorites file " << favoritesFile);
815  } else {
816  WARNINGMSG("Favorites file does not exist: " << favoritesFile);
818  }
819  }
820  return false;
821 }
822 
823 static void SaveFavorites(void)
824 {
825  if (favoriteStylesChanged) {
826  int choice = wxMessageBox("Do you want to save changes to your current Favorites file?",
827  "Save favorites?", wxYES_NO);
828  if (choice == wxYES) {
829  string favoritesFile = GetFavoritesFile(false);
830  if (favoritesFile != NO_FAVORITES_FILE) {
831  string err;
832  if (!WriteASNToFile(favoritesFile.c_str(), favoriteStyles, false, &err))
833  ERRORMSG("Error saving Favorites to " << favoritesFile << '\n' << err);
834  favoriteStylesChanged = false;
835  }
836  }
837  }
838 }
839 
840 void StructureWindow::OnEditFavorite(wxCommandEvent& event)
841 {
842  if (!glCanvas->structureSet) return;
843 
844  if (event.GetId() == MID_ADD_FAVORITE) {
845  // get name from user
846  wxString name = wxGetTextFromUser("Enter a name for this style:", "Input name", "", this);
847  if (name.size() == 0) return;
848 
849  // replace style of same name
850  CCn3d_style_settings *settings = NULL;
851  CCn3d_style_settings_set::Tdata::iterator f, fe = favoriteStyles.Set().end();
852  for (f=favoriteStyles.Set().begin(); f!=fe; ++f) {
853  if (NStr::CompareNocase((*f)->GetName().c_str(), name.c_str()) == 0) {
854  settings = f->GetPointer();
855  break;
856  }
857  }
858  // else add style to list
859  if (f == favoriteStyles.Set().end()) {
861  ERRORMSG("Already have max # Favorites");
862  return;
863  } else {
865  favoriteStyles.Set().push_back(ref);
866  }
867  }
868 
869  // put in data from global style
871  ERRORMSG("Error converting global style to asn");
872  settings->SetName(WX_TO_STD(name));
873  favoriteStylesChanged = true;
874  }
875 
876  else if (event.GetId() == MID_REMOVE_FAVORITE) {
877  wxString *choices = new wxString[favoriteStyles.Get().size()];
878  int i = 0;
879  CCn3d_style_settings_set::Tdata::iterator f, fe = favoriteStyles.Set().end();
880  for (f=favoriteStyles.Set().begin(); f!=fe; ++f)
881  choices[i++] = (*f)->GetName().c_str();
882  int picked = wxGetSingleChoiceIndex("Choose a style to remove from the Favorites list:",
883  "Select for removal", favoriteStyles.Set().size(), choices, this);
884  if (picked < 0 || picked >= (int)favoriteStyles.Set().size()) return;
885  for (f=favoriteStyles.Set().begin(), i=0; f!=fe; ++f, ++i) {
886  if (i == picked) {
887  favoriteStyles.Set().erase(f);
888  favoriteStylesChanged = true;
889  break;
890  }
891  }
892  }
893 
894  else if (event.GetId() == MID_FAVORITES_FILE) {
895  SaveFavorites();
898  string newFavorites = GetFavoritesFile(true);
899  if (newFavorites != NO_FAVORITES_FILE && wxFile::Exists(newFavorites.c_str())) {
900  if (!LoadFavorites())
901  ERRORMSG("Error loading Favorites from " << newFavorites.c_str());
902  }
903  }
904 
905  // update menu
907 }
908 
910 {
911  int i;
913  wxMenuItem *item = favoritesMenu->FindItem(i);
914  if (item) favoritesMenu->Delete(item);
915  }
916 
917  CCn3d_style_settings_set::Tdata::const_iterator f, fe = favoriteStyles.Get().end();
918  for (f=favoriteStyles.Get().begin(), i=0; f!=fe; ++f, ++i)
919  favoritesMenu->Append(MID_FAVORITES_BEGIN + i, (*f)->GetName().c_str());
920 }
921 
922 void StructureWindow::OnSelectFavorite(wxCommandEvent& event)
923 {
924  if (!glCanvas->structureSet) return;
925 
926  if (event.GetId() >= MID_FAVORITES_BEGIN && event.GetId() <= MID_FAVORITES_END) {
927  int index = event.GetId() - MID_FAVORITES_BEGIN;
928  CCn3d_style_settings_set::Tdata::const_iterator f, fe = favoriteStyles.Get().end();
929  int i = 0;
930  for (f=favoriteStyles.Get().begin(); f!=fe; ++f, ++i) {
931  if (i == index) {
932  INFOMSG("using favorite: " << (*f)->GetName());
936  break;
937  }
938  }
939  }
940 }
941 
942 void StructureWindow::OnShowWindow(wxCommandEvent& event)
943 {
944  switch (event.GetId()) {
945  case MID_SHOW_LOG:
946  RaiseLogWindow();
947  break;
948  case MID_SHOW_SEQ_V:
950  break;
951  case MID_SHOW_LOG_START:
953  menuBar->IsChecked(MID_SHOW_LOG_START));
954  break;
955  }
956 }
957 
959 {
960  if (!changed || !glCanvas->structureSet) return;
961 
962  if (changed == cddNotesDialog) {
964  cddNotesDialog->GetLines(&lines);
965  if (!glCanvas->structureSet->SetCDDNotes(lines))
966  ERRORMSG("Error saving CDD notes");
967  }
968  if (changed == cddDescriptionDialog) {
969  string line;
972  ERRORMSG("Error saving CDD description");
973  }
974 }
975 
977 {
978  TRACEMSG("MultiTextDialog destroyed");
979  if (destroyed == cddNotesDialog) cddNotesDialog = NULL;
980  if (destroyed == cddDescriptionDialog) cddDescriptionDialog = NULL;
981 }
982 
984 {
985  if (cddAnnotateDialog) cddAnnotateDialog->Destroy();
986 // if (ibisAnnotateDialog) ibisAnnotateDialog->Destroy();
989  if (cddRefDialog) cddRefDialog->Destroy();
990  if (cddBookRefDialog) cddBookRefDialog->Destroy();
991  if (cddOverview) cddOverview->Destroy();
992 }
993 
994 void StructureWindow::OnPreferences(wxCommandEvent& event)
995 {
996  PreferencesDialog dialog(this);
997  dialog.ShowModal();
998  glCanvas->Refresh(true); // in case stereo options changed
999 }
1000 
1001 bool StructureWindow::SaveDialog(bool prompt, bool canCancel)
1002 {
1003  // check for whether save is necessary
1005  return true;
1006 
1007  int option = wxID_YES;
1008 
1009  if (prompt) {
1010  option = wxYES_NO | wxYES_DEFAULT | wxICON_EXCLAMATION | wxCENTRE;
1011  if (canCancel) option |= wxCANCEL;
1012 
1013  wxMessageDialog dialog(NULL, "Do you want to save your work to a file?", "", option);
1014  option = dialog.ShowModal();
1015 
1016  if (option == wxID_CANCEL) return false; // user cancelled this operation
1017  }
1018 
1019  if (option == wxID_YES) {
1020  wxCommandEvent event;
1021  event.SetId(prompt ? MID_SAVE_AS : MID_SAVE_SAME);
1022  OnSave(event); // save data
1023  }
1024 
1025  return true;
1026 }
1027 
1028 // for sorting sequence list in reject dialog
1029 typedef pair < const Sequence * , wxString > SeqAndDescr;
1030 typedef vector < SeqAndDescr > SeqAndDescrList;
1032 {
1034  a.first->identifier, b.first->identifier);
1035 }
1036 
1038 {
1039  if (!cddOverview)
1042  this, -1, "CDD Descriptive Items", wxPoint(200,50));
1043  cddOverview->Raise();
1044  cddOverview->Show(true);
1045 }
1046 
1048 {
1049  if (!cddAnnotateDialog)
1051  cddAnnotateDialog->Raise();
1052  cddAnnotateDialog->Show(true);
1053 }
1054 
1055 //void StructureWindow::ShowIBISAnnotations(void)
1056 //{
1057 // if (!ibisAnnotateDialog)
1058 // ibisAnnotateDialog = new IBISAnnotateDialog(this, &ibisAnnotateDialog, glCanvas->structureSet);
1059 // ibisAnnotateDialog->Raise();
1060 // ibisAnnotateDialog->Show(true);
1061 //}
1062 
1064 {
1065  if (!cddRefDialog)
1066  cddRefDialog = new CDDRefDialog(
1067  glCanvas->structureSet, &cddRefDialog, this, -1, "CDD PubMed References");
1068  cddRefDialog->Raise();
1069  cddRefDialog->Show(true);
1070 }
1071 
1073 {
1074  if (!cddBookRefDialog)
1076  glCanvas->structureSet, &cddBookRefDialog, this, -1, "CDD Book References");
1077  cddBookRefDialog->Raise();
1078  cddBookRefDialog->Show(true);
1079 }
1080 
1081 void StructureWindow::OnCDD(wxCommandEvent& event)
1082 {
1083  if (!glCanvas->structureSet || !glCanvas->structureSet->IsCDD()) return;
1084  switch (event.GetId()) {
1085 
1086  case MID_CDD_OVERVIEW:
1087  ShowCDDOverview();
1088  break;
1089 
1090  case MID_EDIT_CDD_NAME: {
1091  wxString newName = wxGetTextFromUser("Enter or edit the CDD name:",
1092  "CDD Name", glCanvas->structureSet->GetCDDName().c_str(), this, -1, -1, false);
1093  if (newName.size() > 0) {
1094  if (!glCanvas->structureSet->SetCDDName(WX_TO_STD(newName)))
1095  ERRORMSG("Error saving CDD name");
1098  }
1099  break;
1100  }
1101 
1102  case MID_EDIT_CDD_DESCR:
1103  if (!cddDescriptionDialog) {
1104  StructureSet::TextLines line(1);
1105  line[0] = glCanvas->structureSet->GetCDDDescription().c_str();
1106  cddDescriptionDialog = new MultiTextDialog(this, line, this, -1, "CDD Description");
1107  }
1109  break;
1110 
1111  case MID_EDIT_CDD_NOTES:
1112  if (!cddNotesDialog) {
1114  if (!glCanvas->structureSet->GetCDDNotes(&lines)) break;
1115  cddNotesDialog = new MultiTextDialog(this, lines, this, -1, "CDD Notes");
1116  }
1117  cddNotesDialog->ShowDialog(true);
1118  break;
1119 
1122  break;
1123 
1126  break;
1127 
1128  case MID_ANNOT_CDD:
1130  break;
1131 
1132 // case MID_ANNOT_IBIS:
1133 // ShowIBISAnnotations();
1134 // break;
1135 
1136  case MID_CDD_SHOW_REJECTS:
1138  break;
1139 
1140  case MID_CDD_REJECT_SEQ: {
1141  // make a list of dependent sequences
1142  SeqAndDescrList seqsDescrs;
1143  const MoleculeIdentifier *master =
1145  GetCurrentMultipleAlignment()->GetSequenceOfRow(0)->identifier;
1147  SequenceSet::SequenceList::const_iterator
1148  s, se = glCanvas->structureSet->sequenceSet->sequences.end();
1149  for (s=glCanvas->structureSet->sequenceSet->sequences.begin(); s!=se; ++s) {
1150  if ((*s)->identifier != master) {
1151 
1152  // make sure this sequence isn't already rejected
1153  bool rejected = false;
1154  if (rejects) {
1155  StructureSet::RejectList::const_iterator r, re = rejects->end();
1156  for (r=rejects->begin(); r!=re; ++r) {
1157  CReject_id::TIds::const_iterator i, ie = (*r)->GetIds().end();
1158  for (i=(*r)->GetIds().begin(); i!=ie; ++i) {
1159  if ((*s)->identifier->MatchesSeqId(**i)) {
1160  rejected = true;
1161  break;
1162  }
1163  }
1164  if (rejected) break;
1165  }
1166  }
1167  if (rejected) continue;
1168 
1169  wxString description((*s)->identifier->ToString().c_str());
1170  string descr = (*s)->GetDescription();
1171  if (descr.size() > 0)
1172  description += wxString(" ") + descr.c_str();
1173  seqsDescrs.resize(seqsDescrs.size() + 1);
1174  seqsDescrs.back().first = *s;
1175  seqsDescrs.back().second = description;
1176  }
1177  }
1178  // sort by identifier
1179  stable_sort(seqsDescrs.begin(), seqsDescrs.end(), CompareSequencesByIdentifier);
1180 
1181  // user dialogs for selection and reason
1182  wxString *choices = new wxString[seqsDescrs.size()];
1183  int choice;
1184  for (choice=0; choice<(int)seqsDescrs.size(); ++choice) choices[choice] = seqsDescrs[choice].second;
1185  choice = wxGetSingleChoiceIndex("Reject which sequence?", "Reject Sequence",
1186  seqsDescrs.size(), choices, this);
1187  if (choice >= 0) {
1188  wxString message = "Are you sure you want to reject this sequence?\n\n";
1189  message += choices[choice];
1190  message += "\n\nIf so, enter a brief reason why:";
1191  wxString reason = wxGetTextFromUser(message, "Reject Sequence", "", this);
1192  if (reason.size() == 0) {
1193  wxMessageBox("Reject action cancelled!", "", wxOK | wxICON_INFORMATION, this);
1194  } else {
1195  int purge = wxMessageBox("Do you want to purge all instances of this sequence "
1196  " from the multiple alignment and update list?",
1197  "", wxYES_NO | wxICON_QUESTION, this);
1198  // finally, actually perform the rejection+purge
1200  RejectAndPurgeSequence(seqsDescrs[choice].first, WX_TO_STD(reason), purge == wxYES);
1201  }
1202  }
1203  break;
1204  }
1205  }
1206 }
1207 
1208 void StructureWindow::OnAdjustView(wxCommandEvent& event)
1209 {
1210  glCanvas->SetCurrent();
1211  switch (event.GetId()) {
1214  case MID_RESET: glCanvas->renderer->ResetCamera(); break;
1215  case MID_RESTORE: glCanvas->renderer->RestoreSavedView(); break;
1217  case MID_LAST_FRAME: glCanvas->renderer->ShowLastFrame(); break;
1218  case MID_NEXT_FRAME: glCanvas->renderer->ShowNextFrame(); break;
1220  case MID_ALL_FRAMES: glCanvas->renderer->ShowAllFrames(); break;
1221  case MID_STEREO: glCanvas->renderer->EnableStereo(menuBar->IsChecked(MID_STEREO)); break;
1222  default:
1223  break;
1224  }
1225  glCanvas->Refresh(false);
1226 }
1227 
1228 void StructureWindow::OnShowHide(wxCommandEvent& event)
1229 {
1230  if (glCanvas->structureSet) {
1231 
1232  switch (event.GetId()) {
1233 
1234  case MID_SHOW_HIDE:
1235  {
1236  vector < string > structureNames;
1237  vector < bool > structureVisibilities;
1238  glCanvas->structureSet->showHideManager->GetShowHideInfo(&structureNames, &structureVisibilities);
1239  wxString *titles = new wxString[structureNames.size()];
1240  for (unsigned int i=0; i<structureNames.size(); ++i) titles[i] = structureNames[i].c_str();
1241 
1242  ShowHideDialog dialog(
1243  titles, &structureVisibilities, glCanvas->structureSet->showHideManager, false,
1244  this, -1, "Show/Hide Structures", wxPoint(200, 50));
1245  dialog.ShowModal();
1246  //delete titles; // apparently deleted by wxWindows
1247  break;
1248  }
1249 
1250  case MID_SHOW_ALL:
1252  break;
1253  case MID_SHOW_DOMAINS:
1255  break;
1256  case MID_SHOW_ALIGNED:
1258  break;
1259  case MID_SHOW_CHAINS:
1261  break;
1264  break;
1267  ShowUnalignedResiduesInAlignedDomains(glCanvas->structureSet);
1268  break;
1271  break;
1274  break;
1275  }
1276  }
1277 }
1278 
1279 void StructureWindow::OnAlignStructures(wxCommandEvent& event)
1280 {
1282 
1283  // count aligned vs. highlighted+aligned residues (on master)
1287  BlockMultipleAlignment::UngappedAlignedBlockList::const_iterator b, be = blocks.end();
1288  int nAligned = 0, nHighlighted = 0;
1289  for (b=blocks.begin(); b!=be; ++b) {
1290  nAligned += (*b)->width;
1291  const Block::Range *range = (*b)->GetRangeOfRow(0);
1292  for (unsigned int i=0; i<(*b)->width; ++i)
1293  if (GlobalMessenger()->IsHighlighted(master, range->from + i))
1294  ++nHighlighted;
1295  }
1296 
1297  // if count is different, ask user whether to use aligned or highlighted
1298  bool highlightedOnly = false;
1299  if (nHighlighted > 0 && nHighlighted < nAligned) {
1300  wxString message;
1301  message.Printf("Do you want to do the alignment using only the %i highlighted+aligned residues (on the master)? "
1302  "Answering 'no' will use all %i aligned residues regardless of highlights.", nHighlighted, nAligned);
1303  int answer = wxMessageBox(message, "Use highlighted+aligned residues?", wxYES_NO | wxCANCEL | wxICON_QUESTION, this);
1304  if (answer == wxCANCEL)
1305  return;
1306  highlightedOnly = (answer == wxYES);
1307  }
1308 
1310  glCanvas->SetCurrent();
1311  glCanvas->Refresh(false);
1312  }
1313 }
1314 
1315 #define RENDERING_SHORTCUT(type, menu) \
1316  glCanvas->structureSet->styleManager->SetGlobalRenderingStyle(StyleSettings::type); \
1317  SetRenderingMenuFlag(menu); \
1318  break
1319 #define COLORING_SHORTCUT(type, menu) \
1320  glCanvas->structureSet->styleManager->SetGlobalColorScheme(StyleSettings::type); \
1321  SetColoringMenuFlag(menu); \
1322  break
1323 
1324 void StructureWindow::OnSetStyle(wxCommandEvent& event)
1325 {
1326  if (glCanvas->structureSet) {
1327  glCanvas->SetCurrent();
1328  switch (event.GetId()) {
1329  case MID_EDIT_STYLE:
1331  return;
1334  break;
1335  case MID_ANNOTATE:
1337  return;
1338  break;
1339  case MID_WORM: RENDERING_SHORTCUT(eWormShortcut, MID_WORM);
1340  case MID_TUBE: RENDERING_SHORTCUT(eTubeShortcut, MID_TUBE);
1341  case MID_WIRE: RENDERING_SHORTCUT(eWireframeShortcut, MID_WIRE);
1342  case MID_BNS: RENDERING_SHORTCUT(eBallAndStickShortcut, MID_BNS);
1343  case MID_SPACE: RENDERING_SHORTCUT(eSpacefillShortcut, MID_SPACE);
1344  case MID_SC_TOGGLE: RENDERING_SHORTCUT(eToggleSidechainsShortcut, 0);
1345  case MID_SECSTRUC: COLORING_SHORTCUT(eSecondaryStructureShortcut, MID_SECSTRUC);
1346  case MID_ALIGNED: COLORING_SHORTCUT(eAlignedShortcut, MID_ALIGNED);
1347  case MID_IDENTITY: COLORING_SHORTCUT(eIdentityShortcut, MID_IDENTITY);
1348  case MID_VARIETY: COLORING_SHORTCUT(eVarietyShortcut, MID_VARIETY);
1349  case MID_WGHT_VAR: COLORING_SHORTCUT(eWeightedVarietyShortcut, MID_WGHT_VAR);
1350  case MID_INFO: COLORING_SHORTCUT(eInformationContentShortcut, MID_INFO);
1351  case MID_FIT: COLORING_SHORTCUT(eFitShortcut, MID_FIT);
1352  case MID_BLOCK_FIT: COLORING_SHORTCUT(eBlockFitShortcut, MID_BLOCK_FIT);
1353  case MID_BLOCK_Z_FIT: COLORING_SHORTCUT(eBlockZFitShortcut, MID_BLOCK_Z_FIT);
1354  case MID_BLOCK_ROW_FIT: COLORING_SHORTCUT(eBlockRowFitShortcut, MID_BLOCK_ROW_FIT);
1355  case MID_OBJECT: COLORING_SHORTCUT(eObjectShortcut, MID_OBJECT);
1356  case MID_DOMAIN: COLORING_SHORTCUT(eDomainShortcut, MID_DOMAIN);
1357  case MID_MOLECULE: COLORING_SHORTCUT(eMoleculeShortcut, MID_MOLECULE);
1358  case MID_RESIDUE: COLORING_SHORTCUT(eResidueShortcut, MID_RESIDUE);
1359  case MID_RAINBOW: COLORING_SHORTCUT(eRainbowShortcut, MID_RAINBOW);
1360  case MID_HYDROPHOB: COLORING_SHORTCUT(eHydrophobicityShortcut, MID_HYDROPHOB);
1361  case MID_CHARGE: COLORING_SHORTCUT(eChargeShortcut, MID_CHARGE);
1362  case MID_TEMP: COLORING_SHORTCUT(eTemperatureShortcut, MID_TEMP);
1363  case MID_ELEMENT: COLORING_SHORTCUT(eElementShortcut, MID_ELEMENT);
1364  default:
1365  return;
1366  }
1370  }
1371 }
1372 
1374 {
1375  menuBar->Check(MID_WORM, (which == MID_WORM));
1376  menuBar->Check(MID_TUBE, (which == MID_TUBE));
1377  menuBar->Check(MID_WIRE, (which == MID_WIRE));
1378  menuBar->Check(MID_BNS, (which == MID_BNS));
1379  menuBar->Check(MID_SPACE, (which == MID_SPACE));
1380 }
1381 
1383 {
1384  menuBar->Check(MID_SECSTRUC, (which == MID_SECSTRUC));
1385  menuBar->Check(MID_ALIGNED, (which == MID_ALIGNED));
1386  menuBar->Check(MID_IDENTITY, (which == MID_IDENTITY));
1387  menuBar->Check(MID_VARIETY, (which == MID_VARIETY));
1388  menuBar->Check(MID_WGHT_VAR, (which == MID_WGHT_VAR));
1389  menuBar->Check(MID_INFO, (which == MID_INFO));
1390  menuBar->Check(MID_FIT, (which == MID_FIT));
1391  menuBar->Check(MID_BLOCK_FIT, (which == MID_BLOCK_FIT));
1392  menuBar->Check(MID_BLOCK_Z_FIT, (which == MID_BLOCK_Z_FIT));
1393  menuBar->Check(MID_BLOCK_ROW_FIT, (which == MID_BLOCK_ROW_FIT));
1394  menuBar->Check(MID_OBJECT, (which == MID_OBJECT));
1395  menuBar->Check(MID_DOMAIN, (which == MID_DOMAIN));
1396  menuBar->Check(MID_MOLECULE, (which == MID_MOLECULE));
1397  menuBar->Check(MID_RESIDUE, (which == MID_RESIDUE));
1398  menuBar->Check(MID_RAINBOW, (which == MID_RAINBOW));
1399  menuBar->Check(MID_HYDROPHOB, (which == MID_HYDROPHOB));
1400  menuBar->Check(MID_CHARGE, (which == MID_CHARGE));
1401  menuBar->Check(MID_TEMP, (which == MID_TEMP));
1402  menuBar->Check(MID_ELEMENT, (which == MID_ELEMENT));
1403 }
1404 
1405 static EModel_type GetModelTypeFromUser(wxWindow *parent)
1406 {
1407  wxString choices[3];
1408  EModel_type models[3];
1409  choices[0] = "Single model";
1410  models[0] = eModel_type_ncbi_all_atom;
1411  choices[1] = "Alpha only";
1412  models[1] = eModel_type_ncbi_backbone;
1413  choices[2] = "PDB model(s)";
1414  models[2] = eModel_type_pdb_model;
1415 
1416  wxSingleChoiceDialog dialog(parent, "Please select which type of model you'd like to load",
1417  "Select model", 3, choices, (void **) NULL, (wxCAPTION | wxSYSTEM_MENU | wxOK | wxCENTRE));
1418  if (dialog.ShowModal() != wxID_OK) {
1419  ERRORMSG("Oops, somehow dialog failed to return OK");
1421  }
1422 
1423  return models[dialog.GetSelection()];
1424 }
1425 
1426 // do data loading only, nothing involving windows (shared by both modes)
1427 bool LoadDataOnly(StructureSet **sset, OpenGLRenderer *renderer, const char *filename,
1428  CNcbi_mime_asn1 *mimeData, const string& favoriteStyle, EModel_type model, StructureWindow *window)
1429 {
1430  // set up various paths relative to given filename
1431  if (filename) {
1432  if (wxIsAbsolutePath(filename))
1433  userDir = string(wxPathOnly(filename).c_str()) + wxFILE_SEP_PATH;
1434  else if (wxPathOnly(filename) == "")
1435  userDir = GetWorkingDir();
1436  else
1437  userDir = GetWorkingDir() + WX_TO_STD(wxPathOnly(filename)) + wxFILE_SEP_PATH;
1438  INFOMSG("user dir: " << userDir.c_str());
1439  } else {
1440  userDir = GetWorkingDir();
1441  }
1442  if (mimeData)
1443  currentFileIsBinary = false; // don't know
1444 
1445  // get current structure limit
1446  int structureLimit = kMax_Int;
1448  WARNINGMSG("Can't get structure limit from registry");
1449 
1450  // use passed-in data if present, otherwise load from file
1451  if (!mimeData) {
1452 
1453  // try to decide if what ASN type this is, and if it's binary or ascii
1454  CNcbiIstream *inStream = new CNcbiIfstream(filename, IOS_BASE::in | IOS_BASE::binary);
1455  if (!(*inStream)) {
1456  ERRORMSG("Cannot open file '" << filename << "' for reading");
1457  delete inStream;
1458  return false;
1459  }
1460  currentFile = wxFileNameFromPath(filename);
1461 
1462  string firstWord;
1463  *inStream >> firstWord;
1464  delete inStream;
1465 
1466  static const string
1467  asciiMimeFirstWord = "Ncbi-mime-asn1",
1468  asciiCDDFirstWord = "Cdd",
1469  asciiBiostrucFirstWord = "Biostruc";
1470  bool isMime = false, isCDD = false, isBiostruc = false;
1471  currentFileIsBinary = true;
1472  if (firstWord == asciiMimeFirstWord) {
1473  isMime = true;
1474  currentFileIsBinary = false;
1475  } else if (firstWord == asciiCDDFirstWord) {
1476  isCDD = true;
1477  currentFileIsBinary = false;
1478  } else if (firstWord == asciiBiostrucFirstWord) {
1479  isBiostruc = true;
1480  currentFileIsBinary = false;
1481  }
1482 
1483  // try to read the file as various ASN types (if it's not clear from the first ascii word).
1484  // If read is successful, the StructureSet will own the asn data object, to keep it
1485  // around for output later on
1486  bool readOK = false;
1487  string err;
1488  if (!isCDD && !isBiostruc) {
1489  TRACEMSG("trying to read file '" << filename << "' as " <<
1490  ((currentFileIsBinary) ? "binary" : "ascii") << " mime");
1491  CNcbi_mime_asn1 *mime = new CNcbi_mime_asn1();
1492  SetDiagPostLevel(eDiag_Fatal); // ignore all but Fatal errors while reading data
1493  readOK = ReadASNFromFile(filename, mime, currentFileIsBinary, &err);
1495  if (readOK) {
1496  *sset = new StructureSet(mime, structureLimit, renderer);
1497  // if CDD is contained in a mime, then show CDD splash screen
1498  if (window && (*sset)->IsCDD())
1499  window->ShowCDDOverview();
1500  } else {
1501  TRACEMSG("error: " << err);
1502  delete mime;
1503  }
1504  }
1505  if (!readOK && !isMime && !isBiostruc) {
1506  TRACEMSG("trying to read file '" << filename << "' as " <<
1507  ((currentFileIsBinary) ? "binary" : "ascii") << " cdd");
1508  CCdd *cdd = new CCdd();
1509  SetDiagPostLevel(eDiag_Fatal); // ignore all but Fatal errors while reading data
1510  readOK = ReadASNFromFile(filename, cdd, currentFileIsBinary, &err);
1512  if (readOK) {
1513  *sset = new StructureSet(cdd, structureLimit, renderer);
1514  } else {
1515  TRACEMSG("error: " << err);
1516  delete cdd;
1517  }
1518  }
1519  if (!readOK && !isMime && !isCDD) {
1520  TRACEMSG("trying to read file '" << filename << "' as " <<
1521  ((currentFileIsBinary) ? "binary" : "ascii") << " biostruc");
1522  CRef < CBiostruc > biostruc(new CBiostruc());
1523  SetDiagPostLevel(eDiag_Fatal); // ignore all but Fatal errors while reading data
1524  readOK = ReadASNFromFile(filename, biostruc.GetPointer(), currentFileIsBinary, &err);
1526  if (readOK) {
1527  mimeData = CreateMimeFromBiostruc(biostruc, (window ? GetModelTypeFromUser(window) : model));
1528  } else {
1529  TRACEMSG("error: " << err);
1530  }
1531  }
1532  if (!readOK) {
1533  ERRORMSG("File not found, not readable, or is not a recognized data type");
1534  return false;
1535  }
1536  }
1537 
1538  // use passed-in or constructed data if present
1539  if (mimeData) {
1540  *sset = new StructureSet(mimeData, structureLimit, renderer);
1541  currentFile = ""; // don't remember file name since we have rearranged the data; make user choose a new one
1542  }
1543 
1544  // if a preferred favorite has been specified (e.g. on the command line)
1545  bool foundPreferred = false;
1546  if (favoriteStyle.size() > 0) {
1547  if (!IsWindowedMode())
1548  LoadFavorites();
1549  CCn3d_style_settings_set::Tdata::const_iterator f, fe = favoriteStyles.Get().end();
1550  for (f=favoriteStyles.Get().begin(); f!=fe; ++f) {
1551  if ((*f)->GetName() == favoriteStyle) {
1552  INFOMSG("using favorite: " << (*f)->GetName());
1553  (*sset)->styleManager->SetGlobalStyle(**f);
1554  if (window) {
1555  window->SetRenderingMenuFlag(0);
1556  window->SetColoringMenuFlag(0);
1557  }
1558  foundPreferred = true;
1559  break;
1560  }
1561  }
1562  }
1563 
1564  if (!foundPreferred) {
1565 
1566  // use style stored in asn data (already set up during StructureSet construction)
1567  if ((*sset)->hasUserStyle) {
1568  TRACEMSG("Using global style from incoming data...");
1569  if (window) {
1570  window->SetRenderingMenuFlag(0);
1571  window->SetColoringMenuFlag(0);
1572  }
1573  }
1574 
1575  // otherwise set default rendering style and view, and turn on corresponding style menu flags
1576  else {
1577  if ((*sset)->alignmentSet) {
1578  (*sset)->styleManager->SetGlobalRenderingStyle(StyleSettings::eTubeShortcut);
1579  if (window) window->SetRenderingMenuFlag(StructureWindow::MID_TUBE);
1580  if ((*sset)->IsCDD()) {
1581  (*sset)->styleManager->SetGlobalColorScheme(StyleSettings::eInformationContentShortcut);
1582  if (window) window->SetColoringMenuFlag(StructureWindow::MID_INFO);
1583  } else {
1584  (*sset)->styleManager->SetGlobalColorScheme(StyleSettings::eIdentityShortcut);
1586  }
1587  } else {
1588  (*sset)->styleManager->SetGlobalRenderingStyle(StyleSettings::eWormShortcut);
1589  if (window) window->SetRenderingMenuFlag(StructureWindow::MID_WORM);
1590  (*sset)->styleManager->SetGlobalColorScheme(StyleSettings::eSecondaryStructureShortcut);
1592  }
1593  }
1594  }
1595 
1596  renderer->AttachStructureSet(*sset);
1597  if (IsWindowedMode() && !renderer->HasASNViewSettings())
1598  renderer->ComputeBestView();
1599 
1600  return true;
1601 }
1602 
1603 bool StructureWindow::LoadData(const char *filename, bool force, bool noAlignmentWindow, CNcbi_mime_asn1 *mimeData)
1604 {
1605  SetCursor(*wxHOURGLASS_CURSOR);
1606  glCanvas->SetCurrent();
1607 
1608  if (force) {
1609  fileMenu->Enable(MID_OPEN, false);
1610  fileMenu->Enable(MID_SAVE_AS, false);
1611  }
1612 
1613  // clear old data
1614  if (glCanvas->structureSet) {
1617  GlobalMessenger()->CacheHighlights(); // copy empty highlights list, e.g. clear cache
1618  delete glCanvas->structureSet;
1621  glCanvas->Refresh(false);
1622  }
1623 
1625  filename, mimeData, preferredFavoriteStyle, eModel_type_ncbi_all_atom, this))
1626  {
1627  SetCursor(wxNullCursor);
1628  return false;
1629  }
1630 
1632  SetCursor(wxNullCursor);
1633  ERRORMSG("StructureWindow::LoadData() - MonitorAlignments() returned error");
1634  return false;
1635  }
1636 
1639  menuBar->EnableTop(menuBar->FindMenu("CDD"), glCanvas->structureSet->IsCDD());
1640 
1641  // Disable IBIS annotations when there's not a structured master.
1642 // if (glCanvas->structureSet->IsCDD() && !glCanvas->structureSet->HasStructuredMaster()) {
1643 // menuBar->FindItem(MID_ANNOT_IBIS)->Enable(false);
1644 // }
1645 
1646  glCanvas->Refresh(false);
1647  if (!noAlignmentWindow && glCanvas->structureSet->alignmentManager)
1649  SetCursor(wxNullCursor);
1650 
1651  return true;
1652 }
1653 
1654 void StructureWindow::OnOpen(wxCommandEvent& event)
1655 {
1656  if (glCanvas->structureSet) {
1657  GlobalMessenger()->SequenceWindowsSave(true); // give sequence window a chance to save
1658  SaveDialog(true, false); // give structure window a chance to save data
1659  }
1660 
1661  if (event.GetId() == MID_OPEN) {
1662  const wxString& filestr = wxFileSelector("Choose a text or binary ASN1 file to open", userDir.c_str(),
1663  "", "", "All Files|*.*|Cn3D Files (*.cn3)|*.cn3",
1664 #ifdef __WXMAC__
1665  wxFD_OPEN | wxFD_FILE_MUST_EXIST, this);
1666 #else
1667  wxFD_OPEN | wxFD_FILE_MUST_EXIST);
1668 #endif
1669  if (!filestr.IsEmpty())
1670  LoadData(filestr.c_str(), false, false);
1671  }
1672 
1673  else if (event.GetId() == MID_NETWORK_OPEN) {
1674  wxString id = wxGetTextFromUser("Please enter a PDB or MMDB id", "Input id");
1675  if (id.size() == 0)
1676  return;
1677 
1679  if (mime)
1680  LoadData(NULL, false, false, mime);
1681  }
1682 }
1683 
1684 void StructureWindow::OnSave(wxCommandEvent& event)
1685 {
1686  if (!glCanvas->structureSet) return;
1687 
1688  // determine whether to prompt user for filename
1689  bool prompt = (event.GetId() == MID_SAVE_AS);
1690  if (!prompt) {
1691  wxString dir = wxString(userDir.c_str()).MakeLower();
1692  // always prompt if this file is stored in some temp folder (e.g. browser cache)
1693  if (dir.Contains("cache") || dir.Contains("temp") || dir.Contains("tmp"))
1694  prompt = true;
1695  }
1696 
1697  // force a save of any edits to alignment and updates first
1699 
1700  wxString outputFolder = wxString(userDir.c_str(), userDir.size() - 1); // remove trailing /
1701  wxString outputFilename;
1702  bool outputBinary = currentFileIsBinary, outputCDD = glCanvas->structureSet->IsCDD();
1703 
1704  // don't ask for filename if Save As is disabled
1705  if ((prompt && fileMenu->IsEnabled(MID_SAVE_AS)) || currentFile.size() == 0) {
1706  wxFileName fn(currentFile.c_str());
1707  wxFileDialog dialog(this, "Choose a filename and type for output", outputFolder,
1708 #ifdef __WXGTK__
1709  fn.GetFullName(),
1710 #else
1711  fn.GetName(),
1712 #endif
1713  "All Files|*.*|Binary (*.cn3)|*.cn3|Text (*.cn3)|*.cn3|Text CDD (*.cn3)|*.cn3",
1714  wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
1715  dialog.SetFilterIndex(glCanvas->structureSet->IsCDD() ? 3 : (outputBinary ? 1 : 2));
1716  if (dialog.ShowModal() == wxID_OK)
1717  outputFilename = dialog.GetPath();
1718  outputBinary = (dialog.GetFilterIndex() == 1);
1719  outputCDD = (dialog.GetFilterIndex() == 3);
1720  } else {
1721  outputFilename = (userDir + currentFile).c_str();
1722  }
1723 
1724  if (!outputFilename.IsEmpty()) {
1725 
1726  TRACEMSG("binary = " << outputBinary << ", cdd = " << outputCDD);
1727  INFOMSG("save file: '" << outputFilename.c_str() << "'");
1728 
1729  // convert mime to cdd if specified
1730  if (outputCDD && (!glCanvas->structureSet->IsCDD() || glCanvas->structureSet->IsCDDInMime()))
1731  {
1732  string cddName;
1734  cddName = glCanvas->structureSet->GetCDDName();
1735  else
1736  cddName = wxGetTextFromUser("Enter a name for this CD", "Input Name");
1737  if (cddName.size() == 0 || !glCanvas->structureSet->ConvertMimeDataToCDD(cddName.c_str())) {
1738  ERRORMSG("Conversion to Cdd failed");
1739  return;
1740  }
1741  }
1742 
1743  // save and send FileSaved command
1744  unsigned int changeFlags;
1745  if (glCanvas->structureSet->SaveASNData(outputFilename.c_str(), outputBinary, &changeFlags) &&
1747  {
1748  string data(outputFilename.c_str());
1749  data += '\n';
1750  TRACEMSG("changeFlags: " << changeFlags);
1751  if ((changeFlags & StructureSet::eAnyAlignmentData) > 0)
1752  data += "AlignmentChanged\n";
1753  if ((changeFlags & StructureSet::eRowOrderData) > 0)
1754  data += "RowOrderChanged\n";
1755  if ((changeFlags & StructureSet::ePSSMData) > 0)
1756  data += "PSSMChanged\n";
1757  if ((changeFlags & StructureSet::eCDDData) > 0)
1758  data += "DescriptionChanged\n";
1759  if ((changeFlags & StructureSet::eUpdateData) > 0)
1760  data += "PendingAlignmentsChanged\n";
1761  SendCommand(messageTargetApp, "FileSaved", data);
1762  }
1763 
1764 #if defined(__WXMAC__) && !defined(__WXOSX_COCOA__)
1765  // set mac file type and creator (used under Carbon)
1766  // Note: creator codes are ignored by OSX 10.6 and later, and for the Cocoa port of wxMac [wx2.9.5 and up]
1767  wxFileName wxfn(outputFilename);
1768  if (wxfn.FileExists())
1769  if (!wxfn.MacSetTypeAndCreator('TEXT', 'Cn3D'))
1770  WARNINGMSG("Unable to set Mac file type/creator");
1771 #endif
1772 
1773  // set path/name/title
1774  if (wxIsAbsolutePath(outputFilename))
1775  userDir = string(wxPathOnly(outputFilename).c_str()) + wxFILE_SEP_PATH;
1776  else if (wxPathOnly(outputFilename) == "")
1777  userDir = GetWorkingDir();
1778  else
1779  userDir = GetWorkingDir() + WX_TO_STD(wxPathOnly(outputFilename)) + wxFILE_SEP_PATH;
1780  currentFile = wxFileNameFromPath(outputFilename);
1781  currentFileIsBinary = outputBinary;
1784  }
1785 }
1786 
1787 END_SCOPE(Cn3D)
User-defined methods of the data storage class.
User-defined methods of the data storage class.
void ShowSequenceViewer(bool showNow) const
void RealignAllDependentStructures(bool highlightedOnly) const
const BlockMultipleAlignment * GetCurrentMultipleAlignment(void) const
const Sequence * GetMaster(void) const
std::vector< const UngappedAlignedBlock * > UngappedAlignedBlockList
void GetUngappedAlignedBlocks(UngappedAlignedBlockList *blocks) const
Definition: Cdd.hpp:51
CCn3d_style_settings_set –.
CCn3d_style_settings –.
OpenGLRenderer * renderer
void SetGLFontFromRegistry(double fontScale=1.0)
void SetCurrent(void)
StructureSet * structureSet
void ProcessCommand(const std::string &command, const std::string &dataIn, ncbi::MessageResponder::ReplyStatus *status, std::string *dataOut)
ncbi::FloatingPointSpinCtrl * fpSpinCtrl
void SetAllWindowTitles(void) const
Definition: messenger.cpp:586
void NewSequenceViewerFont(void)
Definition: messenger.cpp:190
void SequenceWindowsSave(bool prompt)
Definition: messenger.cpp:183
void RemoveStructureWindow(const StructureWindow *structureWindow)
Definition: messenger.cpp:167
bool RemoveAllHighlights(bool postRedraws)
Definition: messenger.cpp:393
void ToggleHighlight(const Molecule *molecule, int residueID, bool scrollViewersTo=false)
Definition: messenger.cpp:380
void PostRedrawAllStructures(void)
Definition: messenger.cpp:79
void AddStructureWindow(StructureWindow *window)
Definition: messenger.hpp:185
void PostRedrawAllSequenceViewers(void)
Definition: messenger.cpp:90
void AddHighlights(const Sequence *sequence, unsigned int seqIndexFrom, unsigned int seqIndexTo)
Definition: messenger.cpp:248
void CacheHighlights(void)
Definition: messenger.cpp:412
static bool CompareIdentifiers(const MoleculeIdentifier *a, const MoleculeIdentifier *b)
@ eProtein
Definition: molecule.hpp:77
@ eSolvent
Definition: molecule.hpp:79
@ eBiopolymer
Definition: molecule.hpp:78
@ eNonpolymer
Definition: molecule.hpp:80
ResidueMap residues
Definition: molecule.hpp:89
bool GetLine(std::string *singleString) const
bool GetLines(TextLines *lines) const
bool DestroyDialog(void)
void ShowPreviousFrame(void)
void ResetCamera(void)
void ShowAllFrames(void)
void ShowLastFrame(void)
void AttachStructureSet(StructureSet *targetStructureSet)
void ShowFirstFrame(void)
double GetRotateSpeed(void) const
void ChangeView(eViewAdjust control, int dX=0, int dY=0, int X2=0, int Y2=0)
void RestoreSavedView(void)
void EnableStereo(bool enableStereo)
bool HasASNViewSettings(void) const
void ComputeBestView(void)
void ShowNextFrame(void)
SequenceList sequences
Definition: cav_seqset.hpp:73
void ShowDomainsWithHighlights(const StructureSet *set)
void ShowSelectedResidues(const StructureSet *set)
void ShowResidues(const StructureSet *set, bool showAligned)
void ShowAlignedDomains(const StructureSet *set)
void ShowAlignedChains(const StructureSet *set)
void GetShowHideInfo(std::vector< std::string > *names, std::vector< bool > *visibilities) const
bool IsCDDInMime(void) const
FrameMap frameMap
bool IsCDD(void) const
static const unsigned int eRowOrderData
std::vector< std::string > TextLines
const RejectList * GetRejects(void) const
void ShowRejects(void) const
void SelectByDistance(double cutoff, unsigned int options) const
ObjectList objects
static const unsigned int eAnyAlignmentData
const SequenceSet * sequenceSet
bool SetCDDDescription(const std::string &descr)
static const unsigned int eSelectProtein
static const unsigned int eSelectNucleotide
static const unsigned int eSelectHeterogen
static const unsigned int eCDDData
bool SaveASNData(const char *filename, bool doBinary, unsigned int *changeFlags)
bool SetCDDName(const std::string &name)
bool SetCDDNotes(const TextLines &lines)
bool MonitorAlignments(void) const
AlignmentManager * alignmentManager
ShowHideManager * showHideManager
bool ConvertMimeDataToCDD(const std::string &cddName)
static const unsigned int eUpdateData
const std::string & GetCDDName(void) const
bool HasDataChanged(void) const
static const unsigned int eSelectSolvent
StyleManager * styleManager
static const unsigned int eSelectOtherMoleculesOnly
const std::string & GetCDDDescription(void) const
static const unsigned int ePSSMData
std::list< ncbi::CRef< ncbi::objects::CReject_id > > RejectList
bool GetCDDNotes(TextLines *lines) const
CDDRefDialog * cddRefDialog
bool SaveDialog(bool prompt, bool canCancel)
void OnShowWindow(wxCommandEvent &event)
CDDBookRefDialog * cddBookRefDialog
std::string preferredFavoriteStyle
void ShowCDDReferences(void)
void OnPNG(wxCommandEvent &event)
void OnSetStyle(wxCommandEvent &event)
ncbi::FileMessagingManager fileMessagingManager
void OnShowHide(wxCommandEvent &event)
void OnAlignStructures(wxCommandEvent &event)
void OnAnimationTimer(wxTimerEvent &event)
void OnExit(wxCommandEvent &event)
void ReceivedReply(const std::string &fromApp, unsigned long id, ncbi::MessageResponder::ReplyStatus status, const std::string &data)
void ShowCDDOverview(void)
void SetWindowTitle(void)
void OnCloseWindow(wxCloseEvent &event)
void SetRenderingMenuFlag(int which)
void SendCommand(const std::string &toApp, const std::string &command, const std::string &data)
bool IsFileMessengerActive(void) const
void OnSelectFavorite(wxCommandEvent &event)
void OnFileMessagingTimer(wxTimerEvent &event)
void SetupFavoritesMenu(void)
void OnCDD(wxCommandEvent &event)
void OnPreferences(wxCommandEvent &event)
void DialogTextChanged(const MultiTextDialog *changed)
void ShowCDDBookReferences(void)
void OnHelp(wxCommandEvent &event)
void OnSelect(wxCommandEvent &event)
CommandProcessor * commandProcessor
void OnSave(wxCommandEvent &event)
void SetupFileMessenger(const std::string &messageFilename, const std::string &messageApp, bool readOnly)
void ReceivedCommand(const std::string &fromApp, unsigned long id, const std::string &command, const std::string &data)
MultiTextDialog * cddDescriptionDialog
void OnEditFavorite(wxCommandEvent &event)
void ShowCDDAnnotations(void)
void OnSetFont(wxCommandEvent &event)
wxFileConfig * helpConfig
ncbi::FileMessenger * fileMessenger
wxHtmlHelpController * helpController
void OnOpen(wxCommandEvent &event)
void SetColoringMenuFlag(int which)
Cn3DGLCanvas * glCanvas
void DialogDestroyed(const MultiTextDialog *destroyed)
CDDAnnotateDialog * cddAnnotateDialog
CDDSplashDialog * cddOverview
bool LoadData(const char *filename, bool force, bool noAlignmentWindow, ncbi::objects::CNcbi_mime_asn1 *mimeData=NULL)
void OnAnimate(wxCommandEvent &event)
void DestroyNonModalDialogs(void)
void OnAdjustView(wxCommandEvent &event)
void OnSendSelection(wxCommandEvent &event)
MultiTextDialog * cddNotesDialog
std::string messageTargetApp
const StyleSettings & GetGlobalStyle(void) const
bool SetGlobalStyle(const ncbi::objects::CCn3d_style_settings &styleASN)
bool EditUserAnnotations(wxWindow *parent)
bool EditGlobalStyle(wxWindow *parent)
bool CheckGlobalStyleSettings(void)
bool SaveSettingsToASN(ncbi::objects::CCn3d_style_settings *styleASN) const
void RaiseLogWindow(void)
Definition: cn3d_app.cpp:186
bool IsWindowedMode(void)
Definition: cn3d_app.cpp:92
CNcbi_mime_asn1 * LoadStructureViaCache(const std::string &uid, ncbi::objects::EModel_type modelType, int assemblyId)
Definition: cn3d_cache.cpp:255
bool ExportPNG(Cn3DGLCanvas *glCanvas, OpenGLRenderer *renderer, const string &outputFilename, int outputWidth, int outputHeight, bool interlaced)
Definition: cn3d_png.cpp:392
bool RegistryGetDouble(const string &section, const string &name, double *value)
Definition: cn3d_tools.cpp:240
const string & GetProgramDir(void)
Definition: cn3d_tools.cpp:329
bool RegistryGetInteger(const string &section, const string &name, int *value)
Definition: cn3d_tools.cpp:228
const string & GetPrefsDir(void)
Definition: cn3d_tools.cpp:331
const string & GetWorkingDir(void)
Definition: cn3d_tools.cpp:328
bool RegistrySetBoolean(const string &section, const string &name, bool value, bool useYesOrNo)
Definition: cn3d_tools.cpp:294
bool RegistryGetBoolean(const string &section, const string &name, bool *value)
Definition: cn3d_tools.cpp:250
void LaunchWebPage(const char *url)
Definition: cn3d_tools.cpp:432
bool RegistryGetString(const string &section, const string &name, string *value)
Definition: cn3d_tools.cpp:263
bool RegistrySetString(const string &section, const string &name, const string &value)
Definition: cn3d_tools.cpp:309
static const std::string REG_SPIN_DELAY
Definition: cn3d_tools.hpp:168
static const std::string REG_MAX_N_STRUCTS
Definition: cn3d_tools.hpp:196
static const std::string REG_SPIN_INCREMENT
Definition: cn3d_tools.hpp:169
static const std::string REG_CONFIG_SECTION
Definition: cn3d_tools.hpp:158
static const std::string REG_SEQUENCE_FONT_SECTION
Definition: cn3d_tools.hpp:183
#define TRACEMSG(stream)
Definition: cn3d_tools.hpp:83
#define INFOMSG(stream)
Definition: cn3d_tools.hpp:84
static const std::string REG_FAVORITES_NAME
Definition: cn3d_tools.hpp:159
static const std::string REG_OPENGL_FONT_SECTION
Definition: cn3d_tools.hpp:182
#define WARNINGMSG(stream)
Definition: cn3d_tools.hpp:85
#define CN3D_VERSION_STRING
Definition: cn3d_tools.hpp:80
static const std::string REG_ANIMATION_SECTION
Definition: cn3d_tools.hpp:167
static const std::string REG_ADVANCED_SECTION
Definition: cn3d_tools.hpp:191
static const std::string REG_CDD_ANNOT_READONLY
Definition: cn3d_tools.hpp:192
static const std::string REG_FRAME_DELAY
Definition: cn3d_tools.hpp:170
static const std::string REG_FONT_NATIVE_FONT_INFO
Definition: cn3d_tools.hpp:184
#define WX_TO_STD(wxstring)
Definition: cn3d_tools.hpp:285
#define ERRORMSG(stream)
Definition: cn3d_tools.hpp:86
static const std::string NO_FAVORITES_FILE
Definition: cn3d_tools.hpp:160
static const std::string REG_SHOW_LOG_ON_START
Definition: cn3d_tools.hpp:161
#define option
Include a standard set of the NCBI C++ Toolkit most basic headers.
static bool ReadASNFromFile(const char *filename, ASNClass *ASNobject, bool isBinary, std::string *err)
static bool WriteASNToFile(const char *filename, const ASNClass &ASNobject, bool isBinary, std::string *err, ncbi::EFixNonPrint fixNonPrint=ncbi::eFNP_Default)
CNcbi_mime_asn1 * CreateMimeFromBiostruc(const string &filename, EModel_type model)
static const struct name_t names[]
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
EDiagSev SetDiagPostLevel(EDiagSev post_sev=eDiag_Error)
Set the threshold severity for posting the messages.
Definition: ncbidiag.cpp:6129
@ eDiag_Info
Informational message.
Definition: ncbidiag.hpp:651
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
Definition: ncbidiag.hpp:655
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
#define kMax_Int
Definition: ncbi_limits.h:184
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
EModel_type
Access to EModel_type's attributes (values, names) as defined in spec.
Definition: Model_type_.hpp:63
@ eModel_type_ncbi_all_atom
Definition: Model_type_.hpp:66
@ eModel_type_ncbi_backbone
Definition: Model_type_.hpp:65
@ eModel_type_pdb_model
Definition: Model_type_.hpp:67
void SetName(const TName &value)
Assign a value to Name data member.
const Tdata & Get(void) const
Get the member data.
void Reset(void)
Reset data member.
Tdata & Set(void)
Assign a value to data member.
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
END_EVENT_TABLE()
FILE * file
int i
Messenger * GlobalMessenger(void)
Definition: messenger.cpp:73
const TYPE & Get(const CNamedParameterList *param)
range(_Ty, _Ty) -> range< _Ty >
const struct ncbi::grid::netcache::search::fields::SIZE size
unsigned int a
Definition: ncbi_localip.c:102
Defines: CTimeFormat - storage class for time format.
const char * command
std::istream & in(std::istream &in_, double &x_)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
EVT_MENU_RANGE(MID_SHOW_TITLES, MID_HIDE_TITLES, ViewerWindowBase::OnTitleView) EVT_MENU_RANGE(MID_ENABLE_EDIT
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
static DP_BlockInfo * blocks
#define RENDERING_SHORTCUT(type, menu)
static CCn3d_style_settings_set favoriteStyles
USING_SCOPE(objects)
static void SetWorkingTitle(StructureSet *sSet)
pair< const Sequence *, wxString > SeqAndDescr
static bool CompareSequencesByIdentifier(const SeqAndDescr &a, const SeqAndDescr &b)
static void SaveFavorites(void)
static string currentFile
static bool LoadFavorites(void)
#define COLORING_SHORTCUT(type, menu)
static bool currentFileIsBinary
static string GetFavoritesFile(bool forRead)
bool LoadDataOnly(StructureSet **sset, OpenGLRenderer *renderer, const char *filename, CNcbi_mime_asn1 *mimeData, const string &favoriteStyle, EModel_type model, StructureWindow *window)
const string & GetUserDir(void)
const string & GetWorkingFilename(void)
vector< SeqAndDescr > SeqAndDescrList
static string userDir
static bool favoriteStylesChanged
USING_NCBI_SCOPE
static EModel_type GetModelTypeFromUser(wxWindow *parent)
const string & GetWorkingTitle(void)
static string workingTitle
else result
Definition: token2.c:20
static void SetTitle(CRef< CSeq_entry > entry, string title)
static wxAcceleratorEntry entries[3]
#define const
Definition: zconf.h:230
Modified on Sat Dec 02 09:20:07 2023 by modify_doxy.py rev. 669887