OSDN Git Service

Support load/save of NBO info
[molby/Molby.git] / wxSources / MyDocument.cpp
index f2b100d..b4ad7b2 100755 (executable)
@@ -230,7 +230,10 @@ MyDocument::DoOpenDocument(const wxString& file)
                return false;
        }
        
-       /*  Does this document have multiple representation of molecules?  */
+  if (gLoadSaveErrorMessage != NULL)
+    MyAppCallback_showScriptMessage("On loading %s:\n%s\n", p, gLoadSaveErrorMessage);
+
+  /*  Does this document have multiple representation of molecules?  */
        if (MolActionCreateAndPerform(newmol, SCRIPT_ACTION(";i"), "lambda { @aux_mols ? @aux_mols.count : 0 }", &len) == 0 && len > 0) {
                wxCommandEvent myEvent(MyDocumentEvent, MyDocumentEvent_openAuxiliaryDocuments);
                wxPostEvent(this, myEvent);
@@ -338,8 +341,7 @@ MyDocument::OnExport(wxCommandEvent& event)
 {
        wxString wildcard;
        wxFileName fname(GetFilename());
-       wxString fnstr;
-       GetPrintableName(fnstr);
+    wxString fnstr = GetUserReadableName();
        {
                /*  File filter is built from MyDocManager information  */
                wxString desc, filter, ext;
@@ -394,7 +396,7 @@ MyDocument::OnExportGraphic(wxCommandEvent& event)
        i = MyAppCallback_getGlobalSettingsWithType("global.export_background_color", 'i', &bg_color);
        if (i != 0)
                bg_color = 0;
-       GetPrintableName(fnstr);
+       fnstr = GetUserReadableName();
        if ((i = fnstr.Find('.', true)) != wxNOT_FOUND) {
                fnstr = fnstr.Mid(0, i);
        }
@@ -1091,6 +1093,7 @@ MyDocument::OnInsertFrameFromMD(wxCommandEvent &event)
                }
                ring->count = 0;
                mol->needsMDCopyCoordinates = 0;  /*  This flag needs to be negated because the coordinates come from the MD run  */
+        MainViewCallback_updateCanvas(GetMainView());
        }
        MoleculeUnlock(mol);
 }
@@ -1131,7 +1134,7 @@ MyDocument::OnSubThreadTerminated(wxCommandEvent &event)
 
 /*  Run a subprocess asynchronically  */
 long
-MyDocument::RunSubProcess(const char *cmd, int (*callback)(Molecule *, int), int (*timerCallback)(Molecule *, int), FILE *output, FILE *errout)
+MyDocument::RunSubProcess(const char **argv, int (*callback)(Molecule *, int), int (*timerCallback)(Molecule *, int), FILE *output, FILE *errout)
 {
        if (sCheckIsSubThreadRunning(mol, subThreadKind))
                return -1;  /*  subProcess (or MM/MD subThread) is already running  */
@@ -1139,13 +1142,20 @@ MyDocument::RunSubProcess(const char *cmd, int (*callback)(Molecule *, int), int
        mol->mutex = new wxMutex;
        mol->requestAbortThread = 0;
        
-       wxString cmdstr(cmd, WX_DEFAULT_CONV);
        subProcess = new wxProcess(this, -1);
        subProcess->Redirect();
        subProcessStdout = output;
        subProcessStderr = errout;
 
-       subProcessPID = ::wxExecute(cmdstr, wxEXEC_ASYNC | wxEXEC_MAKE_GROUP_LEADER, subProcess);
+  if (argv[1] != NULL && argv[1][0] == 0) {
+    //  If the second argument is an empty string, then we handle the first string
+    //  as a single argument. (On the other hand, if the second argument is NULL,
+    //  then argv is given to wxExecute as an array containing a single string.)
+    subProcessPID = ::wxExecute(argv[0], wxEXEC_ASYNC | wxEXEC_MAKE_GROUP_LEADER, subProcess);
+  } else {
+    // Array of arguments
+    subProcessPID = ::wxExecuteArgv(argv, wxEXEC_ASYNC | wxEXEC_MAKE_GROUP_LEADER, subProcess);
+  }
        if (subProcessPID == 0) {
                subProcess->Detach();
                subProcess = NULL;
@@ -1520,6 +1530,8 @@ MyDocumentFromMolecule(Molecule *mp)
 Molecule *
 MoleculeCallback_openNewMolecule(const char *fname)
 {
+  if (!gUseGUI)
+    return NULL;
        wxDocument *doc;
        MyDocManager *manager = wxGetApp().DocManager();
        if (fname == NULL || *fname == 0) {
@@ -1536,6 +1548,8 @@ MoleculeCallback_openNewMolecule(const char *fname)
 void
 MoleculeCallback_notifyModification(Molecule *mp, int now_flag)
 {
+  if (!gUseGUI)
+    return;
        MyDocument *doc = MyDocumentFromMolecule(mp);
        if (doc && !doc->isModifyNotificationSent) {
                doc->isModifyNotificationSent = true;
@@ -1646,6 +1660,8 @@ MoleculeCallback_isDataInPasteboard(const char *type)
 Molecule *
 MoleculeCallback_currentMolecule(void)
 {
+  if (!gUseGUI)
+    return NULL;
   MainView *mview = MainViewCallback_activeView();
   if (mview != NULL)
     return mview->mol;
@@ -1655,6 +1671,8 @@ MoleculeCallback_currentMolecule(void)
 Molecule *
 MoleculeCallback_moleculeAtIndex(int idx)
 {
+  if (!gUseGUI)
+    return NULL;
   MainView *mview = MainViewCallback_viewWithTag(idx);
   if (mview != NULL)
     return mview->mol;
@@ -1670,10 +1688,14 @@ MoleculeCallback_moleculeAtOrderedIndex(int idx)
 void
 MoleculeCallback_displayName(Molecule *mol, char *buf, int bufsize)
 {
+  if (!gUseGUI) {
+    buf[0] = 0;
+    return;
+  }
   MyDocument *doc = MyDocumentFromMolecule(mol);
   if (doc != NULL) {
     wxString fname;
-    doc->GetPrintableName(fname);
+    fname = doc->GetUserReadableName();
     strncpy(buf, (const char*)fname.mb_str(wxConvFile), bufsize - 1);
     buf[bufsize - 1] = 0;
   } else {
@@ -1684,6 +1706,13 @@ MoleculeCallback_displayName(Molecule *mol, char *buf, int bufsize)
 void
 MoleculeCallback_pathName(Molecule *mol, char *buf, int bufsize)
 {
+  if (!gUseGUI) {
+    if (mol != NULL && mol->path != NULL) {
+      strncpy(buf, mol->path, bufsize - 1);
+      buf[bufsize - 1] = 0;
+    } else buf[0] = 0;
+    return;
+  }
        MyDocument *doc = MyDocumentFromMolecule(mol);
        if (doc != NULL && doc->hasFile)
                MainViewCallback_getFilename(mol->mview, buf, bufsize);
@@ -1693,6 +1722,9 @@ MoleculeCallback_pathName(Molecule *mol, char *buf, int bufsize)
 int
 MoleculeCallback_setDisplayName(Molecule *mol, const char *name)
 {
+  if (!gUseGUI) {
+    return 0;
+  }
        MyDocument *doc = MyDocumentFromMolecule(mol);
        if (doc == NULL || doc->hasFile)
                return 1; /*  Cannot change file-associated window title  */
@@ -1705,13 +1737,15 @@ MoleculeCallback_setDisplayName(Molecule *mol, const char *name)
 void
 MoleculeCallback_lockMutex(void *mutex)
 {
-       ((wxMutex *)mutex)->Lock();
+  if (gUseGUI)
+    ((wxMutex *)mutex)->Lock();
 }
 
 void
 MoleculeCallback_unlockMutex(void *mutex)
 {
-       ((wxMutex *)mutex)->Unlock();
+  if (gUseGUI)
+    ((wxMutex *)mutex)->Unlock();
 }
 
 void
@@ -1745,17 +1779,21 @@ MoleculeCallback_cannotModifyMoleculeDuringMDError(Molecule *mol)
 }
 
 int
-MoleculeCallback_callSubProcessAsync(Molecule *mol, const char *cmd, int (*callback)(Molecule *, int), int (*timerCallback)(Molecule *, int), FILE *output, FILE *errout)
+MoleculeCallback_callSubProcessAsync(Molecule *mol, const char **argv, int (*callback)(Molecule *, int), int (*timerCallback)(Molecule *, int), FILE *output, FILE *errout)
 {
+  if (!gUseGUI)
+    return -1;
        MyDocument *doc = MyDocumentFromMolecule(mol);
        if (doc != NULL)
-               return doc->RunSubProcess(cmd, callback, timerCallback, output, errout);
+               return doc->RunSubProcess(argv, callback, timerCallback, output, errout);
        else return -1;
 }
 
 void
 MolActionCallback_registerUndo(Molecule *mol, MolAction *action)
 {
+  if (!gUseGUI)
+    return;
        MyDocument *doc = MyDocumentFromMolecule(mol);
        if (doc != NULL && doc->IsUndoEnabled())
                doc->PushUndoAction(action);
@@ -1764,6 +1802,8 @@ MolActionCallback_registerUndo(Molecule *mol, MolAction *action)
 int
 MolActionCallback_setUndoRegistrationEnabled(Molecule *mol, int flag)
 {
+  if (!gUseGUI)
+    return 0;
        MyDocument *doc = MyDocumentFromMolecule(mol);
        if (doc != NULL) {
                doc->SetUndoEnabled(flag);
@@ -1774,6 +1814,8 @@ MolActionCallback_setUndoRegistrationEnabled(Molecule *mol, int flag)
 int
 MolActionCallback_isUndoRegistrationEnabled(Molecule *mol)
 {
+  if (!gUseGUI)
+    return 0;
        MyDocument *doc = MyDocumentFromMolecule(mol);
        if (doc != NULL && doc->IsUndoEnabled())
                return 1;