OSDN Git Service

Attribute table was not updated correctly after revert. Fixed.
authortoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Tue, 30 Oct 2012 09:59:41 +0000 (09:59 +0000)
committertoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Tue, 30 Oct 2012 09:59:41 +0000 (09:59 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@316 a2be9bc6-48de-4e38-9406-05402d4bc13c

MolLib/MD/MDCore.c
MolLib/Molecule.c
MolLib/Ruby_bind/ruby_bind.c
Scripts/startup.rb
wxSources/ConsoleFrame.cpp
wxSources/ConsoleFrame.h
wxSources/MoleculeView.cpp
wxSources/MyApp.cpp
wxSources/MyDocument.cpp
wxSources/MyDocument.h

index 930afb3..aa6534e 100644 (file)
@@ -2332,21 +2332,33 @@ md_amend_by_symmetry(MDArena *arena)
 {
        int i, natoms;
        Atom *ap, *ap0;
-       if (arena->mol->nsyms == 0)
-               return;
        ap = ap0 = arena->mol->atoms;
        natoms = arena->mol->natoms;
+       if (arena->mol->nsyms > 0) {
+               for (i = 0; i < natoms; i++, ap++) {
+                       Symop symop;
+                       if (!ap->symop.alive)
+                               continue;
+                       symop = ap->symop;
+                       ap0 = arena->mol->atoms + ap->symbase;
+                       md_transform_vec_by_symmetry(arena, &(ap->r), &(ap0->r), symop, 0);
+                       md_transform_vec_by_symmetry(arena, &(ap->f), &(ap0->f), symop, 1);
+                       md_transform_vec_by_symmetry(arena, &(ap->v), &(ap0->v), symop, 1);
+               }
+       }
+       ap = arena->mol->atoms;
        for (i = 0; i < natoms; i++, ap++) {
-               Symop symop;
-               if (!ap->symop.alive)
+               Int *ip, j;
+               if (ap->anchor == NULL)
                        continue;
-               symop = ap->symop;
-               ap0 = arena->mol->atoms + ap->symbase;
-               md_transform_vec_by_symmetry(arena, &(ap->r), &(ap0->r), symop, 0);
-               md_transform_vec_by_symmetry(arena, &(ap->f), &(ap0->f), symop, 1);
-               md_transform_vec_by_symmetry(arena, &(ap->v), &(ap0->v), symop, 1);
+               ip = AtomConnectData(&ap->anchor->connect);
+               VecZero(ap->r);
+               for (j = 0; j < ap->anchor->connect.count; j++) {
+                       Double w = ap->anchor->coeffs[j];
+                       ap0 = arena->mol->atoms + ip[j];
+                       VecScaleInc(ap->r, ap0->r, w);
+               }
        }
-       
 }
 
 void
@@ -3428,6 +3440,8 @@ cleanup:
                MoleculeUnlock(arena->xmol); */
        }
        
+       md_amend_by_symmetry(arena);
+       
        arena->setjmp_buf = NULL;
 
        if (arena->is_running) {
index 52d3bfa..0d29d5c 100755 (executable)
@@ -1045,7 +1045,7 @@ MoleculeLoadMbsfFile(Molecule *mp, const char *fname, char **errbuf)
                                        if (iibuf[0] < 0 || iibuf[0] >= mp->natoms || iibuf[1] < 0 || iibuf[1] >= mp->natoms || iibuf[2] < 0 || iibuf[2] >= mp->natoms || iibuf[0] == iibuf[1] || iibuf[1] == iibuf[2]) {
                                                s_append_asprintf(errbuf, "line %d: warning: bad angle specification (%d-%d-%d) - skipped\n", lineNumber, iibuf[0], iibuf[1], iibuf[2]);
                                                nwarnings++;
-                                       } else if (MoleculeAreAtomsConnected(mp, iibuf[0], iibuf[1]) == 0 || MoleculeAreAtomsConnected(mp, iibuf[1], iibuf[2]) == 0) {
+                                       } else if (MoleculeAreAtomsConnected(mp, iibuf[1], iibuf[0]) == 0 || MoleculeAreAtomsConnected(mp, iibuf[1], iibuf[2]) == 0) {
                                                s_append_asprintf(errbuf, "line %d: warning: angle with non-bonded atoms (%d-%d-%d) - skipped\n", lineNumber, iibuf[0], iibuf[1], iibuf[2]);
                                                nwarnings++;                                            
                                        } else if (MoleculeLookupAngle(mp, iibuf[0], iibuf[1], iibuf[2]) >= 0) {
@@ -1077,7 +1077,7 @@ MoleculeLoadMbsfFile(Molecule *mp, const char *fname, char **errbuf)
                                        if (iibuf[0] < 0 || iibuf[0] >= mp->natoms || iibuf[1] < 0 || iibuf[1] >= mp->natoms || iibuf[2] < 0 || iibuf[2] >= mp->natoms || iibuf[3] < 0 || iibuf[3] >= mp->natoms || iibuf[0] == iibuf[1] || iibuf[1] == iibuf[2] || iibuf[2] == iibuf[3] || iibuf[0] == iibuf[2] || iibuf[1] == iibuf[3] || iibuf[0] == iibuf[3]) {
                                                s_append_asprintf(errbuf, "line %d: warning: bad dihedral specification (%d-%d-%d-%d) - skipped\n", lineNumber, iibuf[0], iibuf[1], iibuf[2], iibuf[3]);
                                                nwarnings++;
-                                       } else if (MoleculeAreAtomsConnected(mp, iibuf[0], iibuf[1]) == 0 || MoleculeAreAtomsConnected(mp, iibuf[1], iibuf[2]) == 0 || MoleculeAreAtomsConnected(mp, iibuf[2], iibuf[3]) == 0) {
+                                       } else if (MoleculeAreAtomsConnected(mp, iibuf[1], iibuf[0]) == 0 || MoleculeAreAtomsConnected(mp, iibuf[1], iibuf[2]) == 0 || MoleculeAreAtomsConnected(mp, iibuf[2], iibuf[3]) == 0) {
                                                s_append_asprintf(errbuf, "line %d: warning: dihedral with non-bonded atoms (%d-%d-%d-%d) - skipped\n", lineNumber, iibuf[0], iibuf[1], iibuf[2], iibuf[3]);
                                                nwarnings++;                                            
                                        } else if (MoleculeLookupDihedral(mp, iibuf[0], iibuf[1], iibuf[2], iibuf[3]) >= 0) {
@@ -1109,7 +1109,7 @@ MoleculeLoadMbsfFile(Molecule *mp, const char *fname, char **errbuf)
                                        if (iibuf[0] < 0 || iibuf[0] >= mp->natoms || iibuf[1] < 0 || iibuf[1] >= mp->natoms || iibuf[2] < 0 || iibuf[2] >= mp->natoms || iibuf[3] < 0 || iibuf[3] >= mp->natoms || iibuf[0] == iibuf[1] || iibuf[1] == iibuf[2] || iibuf[2] == iibuf[3] || iibuf[0] == iibuf[2] || iibuf[1] == iibuf[3] || iibuf[0] == iibuf[3]) {
                                                s_append_asprintf(errbuf, "line %d: warning: bad improper specification (%d-%d-%d-%d) - skipped\n", lineNumber, iibuf[0], iibuf[1], iibuf[2], iibuf[3]);
                                                nwarnings++;
-                                       } else if (MoleculeAreAtomsConnected(mp, iibuf[0], iibuf[2]) == 0 || MoleculeAreAtomsConnected(mp, iibuf[1], iibuf[2]) == 0 || MoleculeAreAtomsConnected(mp, iibuf[2], iibuf[3]) == 0) {
+                                       } else if (MoleculeAreAtomsConnected(mp, iibuf[2], iibuf[0]) == 0 || MoleculeAreAtomsConnected(mp, iibuf[2], iibuf[1]) == 0 || MoleculeAreAtomsConnected(mp, iibuf[2], iibuf[3]) == 0) {
                                                s_append_asprintf(errbuf, "line %d: warning: improper with non-bonded atoms (%d-%d-%d-%d) - skipped\n", lineNumber, iibuf[0], iibuf[1], iibuf[2], iibuf[3]);
                                                nwarnings++;                                            
                                        } else if (MoleculeLookupImproper(mp, iibuf[0], iibuf[1], iibuf[2], iibuf[3]) >= 0) {
@@ -6624,8 +6624,10 @@ MoleculeAmendBySymmetry(Molecule *mp, IntGroup *group, IntGroup **groupout, Vect
                        free(vp);
                }
        } else {
-               *groupout = NULL;
-               *vpout = NULL;
+               if (groupout != NULL && vpout != NULL) {
+                       *groupout = NULL;
+                       *vpout = NULL;
+               }
        }
        return count;
 }
@@ -6828,11 +6830,18 @@ MoleculeCreateAnAtom(Molecule *mp, const Atom *ap, int pos)
                for (i = 0, api = ATOM_AT_INDEX(mp->atoms, i); i < mp->natoms; i++, api = ATOM_NEXT(api)) {
                        int j;
                        Int *cp;
+                       cp = AtomConnectData(&api->connect);
                        for (j = 0; j < api->connect.count; j++) {
-                               cp = AtomConnectData(&api->connect);
                                if (cp[j] >= pos)
                                        cp[j]++;
                        }
+                       if (api->anchor != NULL) {
+                               cp = AtomConnectData(&api->anchor->connect);
+                               for (j = 0; j < api->anchor->connect.count; j++) {
+                                       if (cp[j] >= pos)
+                                               cp[j]++;
+                               }
+                       }
                }
                for (i = 0; i < mp->nbonds * 2; i++) {
                        if (mp->bonds[i] >= pos)
index 68b4043..564cf3d 100644 (file)
@@ -10087,7 +10087,7 @@ Init_Molby(void)
        rb_define_method(rb_mKernel, "call_subprocess", s_Kernel_CallSubProcess, 2);
        rb_define_method(rb_mKernel, "message_box", s_Kernel_MessageBox, -1);
        rb_define_method(rb_mKernel, "error_message_box", s_Kernel_ErrorMessageBox, 1);
-       
+
        s_ID_equal = rb_intern("==");
 }
 
@@ -10096,7 +10096,7 @@ Init_Molby(void)
 static VALUE s_ruby_top_self = Qfalse;
 
 static VALUE
-s_evalRubyScriptOnMoleculeSubSub(VALUE tagval, VALUE val)
+s_evalRubyScriptOnMoleculeSub(VALUE val)
 {
        void **ptr = (void **)val;
        Molecule *mol = (Molecule *)ptr[1];
@@ -10123,12 +10123,6 @@ s_evalRubyScriptOnMoleculeSubSub(VALUE tagval, VALUE val)
        }
 }
 
-static VALUE
-s_evalRubyScriptOnMoleculeSub(VALUE val)
-{
-       return rb_catch("molby_top", s_evalRubyScriptOnMoleculeSubSub, val);
-}
-
 RubyValue
 Molby_evalRubyScriptOnMolecule(const char *script, Molecule *mol, const char *fname, int *status)
 {
@@ -10150,6 +10144,15 @@ Molby_evalRubyScriptOnMolecule(const char *script, Molecule *mol, const char *fn
        save_ruby_sourcefile = ruby_sourcefile;
        save_ruby_sourceline = ruby_sourceline;
        retval = (RubyValue)rb_protect(s_evalRubyScriptOnMoleculeSub, (VALUE)args, status);
+       if (*status != 0) {
+               /*  Is this 'exit' exception?  */
+               VALUE last_exception = rb_gv_get("$!");
+               if (rb_obj_is_kind_of(last_exception, rb_eSystemExit)) {
+                       /*  Capture exit and return the status value  */
+                       retval = (RubyValue)rb_funcall(last_exception, rb_intern("status"), 0);
+                       *status = 0;
+               }
+       }
        s_SetInterruptFlag(Qnil, save_interrupt_flag);
        ruby_sourcefile = save_ruby_sourcefile;
        ruby_sourceline = save_ruby_sourceline;
index 6fd0607..cb153b2 100755 (executable)
@@ -39,12 +39,6 @@ def backtrace
   end
 end
 
-if Molby::HasGUI
-  def exit(val = nil)
-    throw(:molby_top, val)
-  end
-end
-
 load "transform.rb"
 load "molecule.rb"
 load "loadsave.rb"
index a8332b6..8a71c35 100755 (executable)
@@ -71,14 +71,19 @@ ConsoleFrame::OnCreate()
        //  Set the default font (fixed-pitch)
        wxTextAttr attr;
 #if defined(__WXMSW__)
-//     wxFont font = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT);
-       wxFont font(10, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
+       default_font = new wxFont(10, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
+       if (!default_font->SetFaceName(wxT("Consolas")))
+               default_font->SetFaceName(wxT("Courier"));
+#elif defined(__WXMAC__)
+       default_font = new wxFont(11, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
+       default_font->SetFaceName(wxT("Monaco"));
 #else
-       wxFont font(11, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
+       default_font = new wxFont(10, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
 #endif
-       attr.SetFont(font);
+       attr.SetFont(*default_font);
        textCtrl->SetDefaultStyle(attr);
-       
+       textCtrl->SetFont(*default_font);
+
        //  Connect "OnKeyDown" event handler
        textCtrl->Connect(-1, wxEVT_KEY_DOWN, wxKeyEventHandler(ConsoleFrame::OnKeyDown), NULL, this);
        
index e3b64e3..8ca1f0b 100755 (executable)
@@ -32,6 +32,8 @@ public:
        wxMenu *file_history_menu;
        wxMenu *edit_menu;
 
+       wxFont *default_font;
+
        ConsoleFrame(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, long type);
        virtual ~ConsoleFrame();
 
index 707eb7e..4016c9e 100755 (executable)
@@ -686,13 +686,23 @@ void
 MoleculeView::OnMoleculeReplaced()
 {
        Molecule *mol = ((MyDocument *)GetDocument())->GetMolecule();
-       if ((mol == NULL && mview == NULL) || (mol != NULL && mol->mview == mview))
+       if (mol == NULL && mview == NULL)
                return;
+       if (mol != NULL && mol->mview == mview) {
+               /*  Clear internal cache  */
+               MainView_refreshCachedInfo(mol->mview);
+               return;
+       }
        if (mview != NULL)
                MainView_setViewObject(mview, NULL);
        if (mol != NULL) {
+               int tableIndex;
                mview = mol->mview;
                MainView_setViewObject(mview, this);
+               /*  Force updating the table  */
+               tableIndex = mview->tableIndex;
+               mview->tableIndex = -1;
+               SelectTable(tableIndex);
        }
 }
 
index 0324a44..b0e3c06 100755 (executable)
@@ -362,7 +362,7 @@ MyApp::CreateMenuBar(int kind, wxMenu **out_file_history_menu, wxMenu **out_edit
        file_menu->Append(wxID_CLOSE, _T("&Close\tCtrl-W"));
        file_menu->Append(wxID_SAVE, _T("&Save\tCtrl-S"));
        file_menu->Append(wxID_SAVEAS, _T("Save &As..."));      
-       file_menu->Append(wxID_REVERT, _T("Revert..."));        
+       file_menu->Append(wxID_REVERT, _T("Revert to Saved"));  
        
        file_menu->AppendSeparator();
        file_menu->Append(myMenuID_Import, _T("Import..."));    
@@ -648,14 +648,16 @@ void
 MyApp::SetConsoleColor(int color)
 {
        wxTextCtrl *textCtrl = consoleFrame->textCtrl;
-       static wxTextAttr *col[4];
+       wxTextAttr attr(textCtrl->GetDefaultStyle());
+       static const wxColour *col[4];
        if (col[0] == NULL) {
-               col[0] = new wxTextAttr(*wxBLACK);
-               col[1] = new wxTextAttr(*wxRED);
-               col[2] = new wxTextAttr(*wxGREEN);
-               col[3] = new wxTextAttr(*wxBLUE);
+               col[0] = wxBLACK;
+               col[1] = wxRED;
+               col[2] = wxGREEN;
+               col[3] = wxBLUE;
        }
-       textCtrl->SetDefaultStyle(*(col[color % 4]));
+       attr.SetTextColour(*col[color % 4]);
+       textCtrl->SetDefaultStyle(attr);
 }
 
 void
index 11a9eec..8d05be8 100755 (executable)
@@ -262,6 +262,15 @@ MyDocument::DoOpenDocument(const wxString& file)
        return true;
 }
 
+bool
+MyDocument::Revert()
+{
+       if (wxDocument::Revert()) {
+               MainViewCallback_selectTable(mol->mview, 0);
+               return true;
+       } else return false;
+}
+
 /*  Override to intercept view creation for running script  */
 bool
 MyDocument::OnCreate(const wxString& path, long flags)
index af52278..1f23e72 100755 (executable)
@@ -134,6 +134,7 @@ public:
        virtual bool DoSaveDocument(const wxString& file);
        virtual bool DoOpenDocument(const wxString& file);
        virtual bool OnCreate(const wxString& path, long flags);
+       virtual bool Revert();
 
  private:
        DECLARE_DYNAMIC_CLASS(MyDocument)