OSDN Git Service

Handling of view-related attributes of Molecule is improved (specifically, methods...
authortoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Sat, 1 Sep 2012 09:19:45 +0000 (09:19 +0000)
committertoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Sat, 1 Sep 2012 09:19:45 +0000 (09:19 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@284 a2be9bc6-48de-4e38-9406-05402d4bc13c

13 files changed:
MolLib/MainView.c
MolLib/MainView.h
MolLib/MainViewCommon.c [new file with mode: 0755]
MolLib/Makefile
MolLib/MolAction.c
MolLib/Molecule.c
MolLib/Ruby_bind/ruby_bind.c
MolLib/Ruby_bind/ruby_dialog.c
MolLib/cmdtool_stubs.c
wxSources/MoleculeView.cpp
wxSources/MoleculeView.h
wxSources/MyDocument.cpp
xcode-build/Molby.xcodeproj/project.pbxproj

index 0c0884e..ce925eb 100755 (executable)
@@ -30,78 +30,26 @@ const Double kInvalidValue = -10000000.0;
 
 #pragma mark ==== MainView public methods ====
 
-MainView *
-MainView_newMainView(void *ref)
+void
+MainView_setViewObject(MainView *mview, void *ref)
 {
        static GLdouble sIdentity[16] = {
                1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1
        };
-       MainView *mview = (MainView *)malloc(sizeof(MainView));
-       if (mview != NULL) {
-               memset(mview, 0, sizeof(MainView));
-               mview->ref = ref;
-               mview->track = TrackballNew();
-               mview->mode = kTrackballRotateMode;
-               mview->tempAtoms[0] = mview->tempAtoms[1] = -1;
-               memmove(mview->modelview_matrix, sIdentity, sizeof(sIdentity));
-               memmove(mview->projection_matrix, sIdentity, sizeof(sIdentity));
-               mview->atomRadius = 0.4;
-               mview->bondRadius = 0.1;
-               mview->probabilityScale = 1.5382;
-               mview->dimension = 10.0;
-       /*      MainView_resizeToFit(mview); */
-               mview->showHydrogens = mview->showDummyAtoms = mview->showExpandedAtoms = 1;
-               mview->showPeriodicBox = 1;
-               mview->showGraphite = 5;
-               mview->tableCache = IntGroupNew();
-               mview->tableSelection = IntGroupNew();
-       }
-       return mview;
-}
-
-void
-MainView_release(MainView *mview)
-{
-       int i;
        if (mview != NULL) {
-               MainView_setMolecule(mview, NULL);
-               TrackballRelease(mview->track);
-               IntGroupRelease(mview->tableCache);
-               IntGroupRelease(mview->tableSelection);
-               if (mview->nlabels > 0) {
-                       for (i = 0; i < mview->nlabels; i++) {
-                               MainViewCallback_releaseLabel(mview->labels[i].label);
-                       }
-                       free(mview->labels);
-                       free(mview->sortedLabels);
-               }
-               if (mview->rotateFragment != NULL)
-                       IntGroupRelease(mview->rotateFragment);
-               if (mview->rotateFragmentOldPos != NULL)
-                       free(mview->rotateFragmentOldPos);
-               if (mview->visibleFlags != NULL)
-                       free(mview->visibleFlags);
-       }
-       free(mview);
-}
-
-void
-MainView_setMolecule(MainView *mview, struct Molecule *mol)
-{
-       if (mview == NULL || mview->mol == mol)
-               return;
-       if (mview->mol != NULL) {
-               mview->mol->mview = NULL;  /*  No need to release  */
-               MoleculeRelease(mview->mol);
-       }
-       mview->mol = mol;
-       if (mol != NULL) {
-               MoleculeRetain(mol);
-               mol->mview = mview;  /*  No retain  */
-               MainViewCallback_moleculeReplaced(mview, mol);
-       /*      MainView_resizeToFit(mview); */
-               MoleculeCallback_notifyModification(mol, 0);
-       /*      MainViewCallback_setNeedsDisplay(mview, 1); */
+               if (mview->ref == NULL) {
+                       /*  Initialize GUI-only members  */
+                       mview->mode = kTrackballRotateMode;
+                       mview->tempAtoms[0] = mview->tempAtoms[1] = -1;
+                       memmove(mview->modelview_matrix, sIdentity, sizeof(sIdentity));
+                       memmove(mview->projection_matrix, sIdentity, sizeof(sIdentity));
+                       mview->tableCache = IntGroupNew();
+                       mview->tableSelection = IntGroupNew();
+               }
+               mview->ref = ref;  /*  No retain  */
+               IntGroupClear(mview->tableCache);
+               IntGroupClear(mview->tableSelection);
+               MoleculeCallback_notifyModification(mview->mol, 0);
        }
 }
 
@@ -2152,57 +2100,6 @@ MainView_getMode(const MainView *mview)
        else return 0;
 }
 
-#pragma mark ====== Drawing Settings ======
-
-void
-MainView_setBackgroundColor(MainView *mview, float red, float green, float blue)
-{
-       if (mview != NULL) {
-               mview->background_color[0] = red;
-               mview->background_color[1] = green;
-               mview->background_color[2] = blue;
-               MoleculeCallback_notifyModification(mview->mol, 0);
-       }
-}
-
-void
-MainView_getBackgroundColor(const MainView *mview, float *rgb)
-{
-       if (mview != NULL) {
-               rgb[0] = mview->background_color[0];
-               rgb[1] = mview->background_color[1];
-               rgb[2] = mview->background_color[2];
-       }
-}
-
-#pragma mark ====== Graphics ======
-
-int
-MainView_insertGraphic(MainView *mview, int index, const MainViewGraphic *graphic)
-{
-       if (index < 0 || index >= mview->ngraphics)
-               index = mview->ngraphics;
-       InsertArray(&mview->graphics, &mview->ngraphics, sizeof(MainViewGraphic), index, 1, graphic);
-       MoleculeCallback_notifyModification(mview->mol, 0);
-       return index;
-}
-
-int
-MainView_removeGraphic(MainView *mview, int index)
-{
-       MainViewGraphic *g;
-       if (index < 0 || index >= mview->ngraphics)
-               return -1;
-       g = &mview->graphics[index];
-       if (g->points != NULL)
-               free(g->points);
-       if (g->normals != NULL)
-               free(g->normals);
-       DeleteArray(&mview->graphics, &mview->ngraphics, sizeof(MainViewGraphic), index, 1, NULL);
-       MoleculeCallback_notifyModification(mview->mol, 0);
-       return index;
-}
-
 #pragma mark ====== Mouse operations ======
 
 static void
index ca44e7a..93b61cc 100755 (executable)
@@ -97,31 +97,15 @@ typedef struct MainViewGraphic {
 
 typedef struct MainView {
        struct Molecule *mol;
-       void *ref;  /*  A platform-dependent pointer to the main view object (or the main window **controller** object)  */
-       void *tableRef;  /*  The table view object  */
-
-       unsigned char isInitialized;
-       int mode;
        struct Trackball *track;
-    GLdouble modelview_matrix[16];
-    GLdouble projection_matrix[16];
-    GLdouble perspective_vector[4];
-       
-       /*  Camera position and direction in object (Cartesian) coordinate  */
-       Vector camera;  /*  The camera position  */
-       Vector lookat;  /*  The center of the screen  */
-       Vector lookto;  /*  The direction from the camera to the screen center; this is easily derived by normalizing (lookat - camera), but provided for convenience  */
-       Vector up;      /*  The direction up in the screen  */
-
-       float atomRadius; /* Scale the vdW radius by this value */
-       float bondRadius; /* in angstrom */
-       float probabilityScale;
-       float dimension;
-       
        float background_color[4];
        Int ngraphics;
        MainViewGraphic *graphics;
        
+       void *ref;  /*  A platform-dependent pointer to the main view object 
+                                  (or the main window **controller** object)
+                                   If NULL, then this is a dummy MainView object just for store parameters  */
+
        Byte showUnitCell;
        Byte showPeriodicBox;
        Byte showExpandedAtoms;
@@ -129,18 +113,41 @@ typedef struct MainView {
        Byte showHydrogens;
        Byte showDummyAtoms;
        Byte showRotationCenter;
-
+       
        Byte showGraphiteFlag;
        Int  showGraphite;
        Byte showPeriodicImageFlag;
        Int  showPeriodicImage[6];  /* amin, amax, bmin, bmax, cmin, cmax  */
+       
+       Byte lineMode;     /*  Draw the model with lines  */
+       
+       float atomRadius; /* Scale the vdW radius by this value */
+       float bondRadius; /* in angstrom */
+       float probabilityScale;
+       Byte  freezeScreen;
+       float dimension;
+       
+#if !defined(__CMDMAC__)
+       /*  The following members are used in GUI version only  */
+       
+       void *tableRef;  /*  The table view object  */
+
+       unsigned char isInitialized;
+       int mode;
+    GLdouble modelview_matrix[16];
+    GLdouble projection_matrix[16];
+    GLdouble perspective_vector[4];
+       
+       /*  Camera position and direction in object (Cartesian) coordinate  */
+       Vector camera;  /*  The camera position  */
+       Vector lookat;  /*  The center of the screen  */
+       Vector lookto;  /*  The direction from the camera to the screen center; this is easily derived by normalizing (lookat - camera), but provided for convenience  */
+       Vector up;      /*  The direction up in the screen  */
 
        Byte *visibleFlags;     /*  This is used only as internal cache;
                                    The attribute of "hidden" atom is set as (ap->exflags & kAtomHiddenFlag).  */
        Int countHidden;
-       Byte freezeScreen;
        
-       unsigned char lineMode;     /*  Draw the model with lines  */
        unsigned char draggingMode; /*  MainViewDraggingMode  */
        unsigned char isDragging;   /*  Becomes true if mouse moved by a certain amount  */
        int clickedAtoms[2]; /*  The object under the mouse on mouseDown event. [-1,-1]: nothing, [n,-1]: atom n, [n,m]: bond between atoms n and m  */
@@ -173,10 +180,21 @@ typedef struct MainView {
        struct IntGroup *tableCache;     /* Indices of atoms etc. that are shown in the table */
        struct IntGroup *tableSelection; /* Selected rows in the table  */
 
+#endif
+
 } MainView;
 
 /*  Public functions  */
-MainView *MainView_newMainView(void *ref);
+
+/*  "Common" functions, used both in GUI and CMD versions. Defined in MainViewCommon.c  */
+MainView *MainView_new(void);
+void MainView_setBackgroundColor(MainView *mview, float red, float green, float blue);
+void MainView_getBackgroundColor(const MainView *mview, float *rgb);
+int MainView_insertGraphic(MainView *mview, int index, const MainViewGraphic *graphic);
+int MainView_removeGraphic(MainView *mview, int index);
+
+/*  GUI-only functions  */
+void MainView_setViewObject(MainView *mview, void *ref);
 void MainView_initializeOpenGLView(MainView *mview);
 void MainView_release(MainView *mview);
 void MainView_setMolecule(MainView *mview, struct Molecule *mol);
@@ -194,11 +212,6 @@ void MainView_mouseMoved(MainView *view, const float *p, int eventMask);
 void MainView_setMode(MainView *mview, int mode);
 int MainView_getMode(const MainView *mview);
 
-void MainView_setBackgroundColor(MainView *mview, float red, float green, float blue);
-void MainView_getBackgroundColor(const MainView *mview, float *rgb);
-int MainView_insertGraphic(MainView *mview, int index, const MainViewGraphic *graphic);
-int MainView_removeGraphic(MainView *mview, int index);
-
 void MainView_attachLabelToAtom(MainView *mview, int index);
 void MainView_detachLabelFromAtom(MainView *mview, int index);
 void MainView_purgeUnusedLabels(MainView *mview);
@@ -252,7 +265,7 @@ STUB MainView *MainViewCallback_activeView(void);
 STUB MainView *MainViewCallback_newFromFile(const char *fname);
 STUB int MainViewCallback_importFromFile(MainView *mview, const char *fname);
 STUB void MainViewCallback_getFilename(MainView *mview, char *buf, int bufsize);
-STUB void MainViewCallback_moleculeReplaced(MainView *mview, struct Molecule *mol);
+//STUB void MainViewCallback_moleculeReplaced(MainView *mview, struct Molecule *mol);
 
 STUB struct Label *MainViewCallback_newLabel(MainView *mview, const char *message, float fontsize, const float *forecolor, const float *backcolor); /* colors are rgba */
 STUB void MainViewCallback_releaseLabel(struct Label *label);
diff --git a/MolLib/MainViewCommon.c b/MolLib/MainViewCommon.c
new file mode 100755 (executable)
index 0000000..ced823b
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ *  MainViewCommon.c
+ *
+ *  Created by Toshi Nagata on 12/09/01.
+ *  Copyright 2012 Toshi Nagata. All rights reserved.
+ *
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation version 2 of the License.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ */
+
+#include "MolLib.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#pragma mark ====== Drawing Settings ======
+
+MainView *
+MainView_new(void)
+{
+       MainView *mview = (MainView *)malloc(sizeof(MainView));
+       if (mview != NULL) {
+               /*  Initialize common members (that are used both in GUI and CMD versions  */
+               memset(mview, 0, sizeof(MainView));
+               mview->track = TrackballNew();
+               mview->atomRadius = 0.4;
+               mview->bondRadius = 0.1;
+               mview->probabilityScale = 1.5382;
+               mview->dimension = 10.0;
+               mview->showHydrogens = mview->showDummyAtoms = mview->showExpandedAtoms = 1;
+               mview->showPeriodicBox = 1;
+               mview->showGraphite = 5;
+       }
+       return mview;
+}
+
+void
+MainView_release(MainView *mview)
+{
+       if (mview != NULL) {
+               if (mview->ref != NULL) {
+                       fprintf(stderr, "%s:%d:Memory leak warning: mview->ref is not NULL\n", __FILE__, __LINE__);
+                       return;
+               }
+       //      MainView_setMolecule(mview, NULL);
+               TrackballRelease(mview->track);
+#if !defined(__CMDMAC__)
+               IntGroupRelease(mview->tableCache);
+               IntGroupRelease(mview->tableSelection);
+               if (mview->nlabels > 0) {
+                       int i;
+                       for (i = 0; i < mview->nlabels; i++) {
+                               MainViewCallback_releaseLabel(mview->labels[i].label);
+                       }
+                       free(mview->labels);
+                       free(mview->sortedLabels);
+               }
+               if (mview->rotateFragment != NULL)
+                       IntGroupRelease(mview->rotateFragment);
+               if (mview->rotateFragmentOldPos != NULL)
+                       free(mview->rotateFragmentOldPos);
+               if (mview->visibleFlags != NULL)
+                       free(mview->visibleFlags);
+#endif
+       }
+       free(mview);
+}
+
+/*
+void
+MainView_setMolecule(MainView *mview, struct Molecule *mol)
+{
+       if (mview == NULL || mview->mol == mol)
+               return;
+       if (mview->mol != NULL) {
+               mview->mol->mview = NULL;  //  No need to release
+               MoleculeRelease(mview->mol);
+       }
+       mview->mol = mol;
+       if (mol != NULL) {
+               MoleculeRetain(mol);
+               mol->mview = mview;  //  No retain
+               MainViewCallback_moleculeReplaced(mview, mol);
+               MoleculeCallback_notifyModification(mol, 0);
+       }
+}
+*/
+
+void
+MainView_setBackgroundColor(MainView *mview, float red, float green, float blue)
+{
+       if (mview != NULL) {
+               mview->background_color[0] = red;
+               mview->background_color[1] = green;
+               mview->background_color[2] = blue;
+               MoleculeCallback_notifyModification(mview->mol, 0);
+       }
+}
+
+void
+MainView_getBackgroundColor(const MainView *mview, float *rgb)
+{
+       if (mview != NULL) {
+               rgb[0] = mview->background_color[0];
+               rgb[1] = mview->background_color[1];
+               rgb[2] = mview->background_color[2];
+       }
+}
+
+#pragma mark ====== Graphics ======
+
+int
+MainView_insertGraphic(MainView *mview, int index, const MainViewGraphic *graphic)
+{
+       if (index < 0 || index >= mview->ngraphics)
+               index = mview->ngraphics;
+       InsertArray(&mview->graphics, &mview->ngraphics, sizeof(MainViewGraphic), index, 1, graphic);
+       MoleculeCallback_notifyModification(mview->mol, 0);
+       return index;
+}
+
+int
+MainView_removeGraphic(MainView *mview, int index)
+{
+       MainViewGraphic *g;
+       if (index < 0 || index >= mview->ngraphics)
+               return -1;
+       g = &mview->graphics[index];
+       if (g->points != NULL)
+               free(g->points);
+       if (g->normals != NULL)
+               free(g->normals);
+       DeleteArray(&mview->graphics, &mview->ngraphics, sizeof(MainViewGraphic), index, 1, NULL);
+       MoleculeCallback_notifyModification(mview->mol, 0);
+       return index;
+}
+
index 5e9994c..2c4607b 100755 (executable)
@@ -5,7 +5,7 @@ DESTDIR = .
 OBJDIR = .
 endif
 
-OBJECTS = IntGroup.o MainView.o MolAction.o Molecule.o \
+OBJECTS = IntGroup.o MainView.o MainViewCommon.o MolAction.o Molecule.o \
   Object.o Dcd.o Parameter.o Trackball.o Types.o Missing.o
 MD_OBJECTS = MDCore.o MDForce.o MDGraphite.o MDPressure.o MDSurface.o
 
index 35b1734..923eb56 100644 (file)
@@ -1586,9 +1586,11 @@ s_MolActionInsertOnePiAtom(Molecule *mol, MolAction *action, MolAction **actp, i
        memmove(AtomConnectData(&pp->connect), connects, sizeof(Int) * nconnects);
        NewArray(&pp->coeffs, &pp->ncoeffs, sizeof(Double), nconnects);
        memmove(pp->coeffs, coeffs, sizeof(Double) * nconnects);
-       for (i = 0; i < mol->npibonds * 4; i++) {
-               if (mol->pibonds[i] >= ATOMS_MAX_NUMBER + idx)
-                       mol->pibonds[i]++;
+       if (!willReplace) {
+               for (i = 0; i < mol->npibonds * 4; i++) {
+                       if (mol->pibonds[i] >= ATOMS_MAX_NUMBER + idx)
+                               mol->pibonds[i]++;
+               }
        }
        return 0;
 }
@@ -1620,6 +1622,10 @@ s_MolActionRemoveOnePiAtom(Molecule *mol, MolAction *action, MolAction **actp)
        *actp = MolActionNew(gMolActionInsertOnePiAtom, idx, 4, pp->aname, pp->type, nconnects, ip, pp->ncoeffs, pp->coeffs);
        PiAtomClean(pp);
        DeleteArray(&mol->piatoms, &mol->npiatoms, sizeof(PiAtom), idx, 1, NULL);
+       for (i = 0; i < mol->npibonds * 4; i++) {
+               if (mol->pibonds[i] > ATOMS_MAX_NUMBER + idx)
+                       mol->pibonds[i]--;
+       }       
        return 0;
 }
 
index e037176..7921718 100755 (executable)
@@ -299,6 +299,8 @@ MoleculeNew(void)
                Panic("Cannot allocate new molecule record");
        snprintf(name, sizeof name, "Untitled %d", sMoleculeUntitledCount++);
        ObjectInit((Object *)mp, (Object **)&sMoleculeRoot, name);
+       mp->mview = MainView_new();
+       mp->mview->mol = mp;
        return mp;
 }
 
@@ -568,6 +570,8 @@ MoleculeRelease(Molecule *mp)
        MoleculeReleaseExternalObj(mp);
        if (ObjectDecrRefCount((Object *)mp) == 0) {
                MoleculeClear(mp);
+               mp->mview->mol = NULL;
+               MainView_release(mp->mview);
                ObjectDealloc((Object *)mp, (Object **)&sMoleculeRoot);
        }
 }
index 93bf12e..9fbaa9a 100644 (file)
@@ -9373,7 +9373,9 @@ s_Molecule_CreateOrReplacePiAnchor(int func, int argc, VALUE *argv, VALUE self)
        } else {
                rb_scan_args(argc, argv, "41", &ival, &nval, &tval, &gval, &wval);
                idx = NUM2INT(rb_Integer(ival));
-               if (idx < 0 || idx > mol->npiatoms || (func == 2 && idx == mol->npiatoms))
+               if (idx < 0)
+                       idx = mol->npiatoms;
+               if (idx > mol->npiatoms || (func == 2 && idx == mol->npiatoms))
                        rb_raise(rb_eMolbyError, "pi anchor index out of range");
        }
        np = StringValuePtr(nval);
@@ -9885,6 +9887,8 @@ Init_Molby(void)
        rb_define_method(rb_cMolecule, "show_periodic_image=", s_Molecule_ShowPeriodicImage, -1);
        rb_define_method(rb_cMolecule, "show_periodic_image?", s_Molecule_ShowPeriodicImageFlag, 0);
        rb_define_alias(rb_cMolecule, "show_unitcell=", "show_unitcell");
+       rb_define_alias(rb_cMolecule, "show_unit_cell", "show_unitcell");
+       rb_define_alias(rb_cMolecule, "show_unit_cell=", "show_unitcell");
        rb_define_alias(rb_cMolecule, "show_hydrogens=", "show_hydrogens");
        rb_define_alias(rb_cMolecule, "show_dummy_atoms=", "show_dummy_atoms");
        rb_define_alias(rb_cMolecule, "show_expanded=", "show_expanded");
@@ -9894,7 +9898,7 @@ Init_Molby(void)
        rb_define_method(rb_cMolecule, "line_mode", s_Molecule_LineMode, -1);
        rb_define_alias(rb_cMolecule, "line_mode=", "line_mode");
        rb_define_method(rb_cMolecule, "resize_to_fit", s_Molecule_ResizeToFit, 0);
-#if !defined(__CMDMAC__)
+#if 1 || !defined(__CMDMAC__)
        rb_define_method(rb_cMolecule, "get_view_rotation", s_Molecule_GetViewRotation, 0);
        rb_define_method(rb_cMolecule, "get_view_scale", s_Molecule_GetViewScale, 0);
        rb_define_method(rb_cMolecule, "get_view_center", s_Molecule_GetViewCenter, 0);
index 6b77c75..adb72ee 100644 (file)
@@ -30,7 +30,8 @@ static VALUE
        sAlignSymbol, sRightSymbol, sCenterSymbol,
        sVerticalAlignSymbol, sBottomSymbol, 
        sMarginSymbol, sPaddingSymbol, sSubItemsSymbol,
-       sHFillSymbol, sVFillSymbol;
+       sHFillSymbol, sVFillSymbol,
+       sIsProcessingActionSymbol;
 
 VALUE rb_cDialog = Qfalse;
 VALUE rb_cDialogItem = Qfalse;
@@ -919,6 +920,9 @@ s_RubyDialog_Item(int argc, VALUE *argv, VALUE self)
        /*  Set attributes  */
        s_RubyDialog_SetAttr(self, val, hash);
        
+       /*  Set internal attributes  */
+       rb_ivar_set(new_item, SYM2ID(sIsProcessingActionSymbol), Qfalse);
+       
        /*  Type-specific attributes  */
        if (type == sLineSymbol) {
                if (rect.size.width > rect.size.height && rect.size.width == 2)
@@ -1287,6 +1291,7 @@ s_RubyDialog_doItemAction(VALUE val)
        int i, j, n;
        void **vp = (void **)val;
        VALUE self = (VALUE)vp[0];
+       VALUE flag;
        RDItem *ip = (RDItem *)vp[1];
        RDItem *ip2;
        VALUE ival, itval, actval;
@@ -1298,7 +1303,12 @@ s_RubyDialog_doItemAction(VALUE val)
                return Qnil;
        ival = INT2NUM(idx);
        itval = s_RubyDialog_ItemAtIndex(self, ival);
-       
+       flag = rb_ivar_get(itval, SYM2ID(sIsProcessingActionSymbol));
+       if (flag == Qtrue)
+               return Qnil;  /*  Avoid recursive calling action proc for the same item  */
+
+       rb_ivar_set(itval, SYM2ID(sIsProcessingActionSymbol), Qtrue);
+
        /*  Handle radio group  */
        if (s_RubyDialogItem_Attr(itval, sTypeSymbol) == sRadioSymbol) {
                VALUE gval = s_RubyDialogItem_Attr(itval, sRadioGroupSymbol);
@@ -1339,9 +1349,14 @@ s_RubyDialog_doItemAction(VALUE val)
                rb_funcall(itval, SYM2ID(sActionSymbol), 0);
        } else {
                /*  Default action (only for default buttons)  */
-               if (idx == 0 || idx == 1)
+               if (idx == 0 || idx == 1) {
+                       rb_ivar_set(itval, SYM2ID(sIsProcessingActionSymbol), Qfalse);
                        s_RubyDialog_EndModal(1, &itval, self);
+               }
        }
+
+       rb_ivar_set(itval, SYM2ID(sIsProcessingActionSymbol), Qfalse);
+       
        return Qnil;
 }
 
@@ -1423,8 +1438,8 @@ RubyDialogInitClass(void)
        rb_define_alias(rb_cDialogItem, "set_attr", "[]=");
        rb_define_alias(rb_cDialogItem, "attr", "[]");
        {
-               static VALUE *sTable1[] = { &sTextSymbol, &sTextFieldSymbol, &sRadioSymbol, &sButtonSymbol, &sCheckBoxSymbol, &sPopUpSymbol, &sTextViewSymbol, &sViewSymbol, &sDialogSymbol, &sIndexSymbol, &sLineSymbol, &sTagSymbol, &sTypeSymbol, &sTitleSymbol, &sXSymbol, &sYSymbol, &sWidthSymbol, &sHeightSymbol, &sOriginSymbol, &sSizeSymbol, &sFrameSymbol, &sEnabledSymbol, &sEditableSymbol, &sHiddenSymbol, &sValueSymbol, &sRadioGroupSymbol, &sBlockSymbol, &sRangeSymbol, &sActionSymbol, &sAlignSymbol, &sRightSymbol, &sCenterSymbol, &sVerticalAlignSymbol, &sBottomSymbol, &sMarginSymbol, &sPaddingSymbol, &sSubItemsSymbol, &sHFillSymbol, &sVFillSymbol };
-               static const char *sTable2[] = { "text", "textfield", "radio", "button", "checkbox", "popup", "textview", "view", "dialog", "index", "line", "tag", "type", "title", "x", "y", "width", "height", "origin", "size", "frame", "enabled", "editable", "hidden", "value", "radio_group", "block", "range", "action", "align", "right", "center", "vertical_align", "bottom", "margin", "padding", "subitems", "hfill", "vfill" };
+               static VALUE *sTable1[] = { &sTextSymbol, &sTextFieldSymbol, &sRadioSymbol, &sButtonSymbol, &sCheckBoxSymbol, &sPopUpSymbol, &sTextViewSymbol, &sViewSymbol, &sDialogSymbol, &sIndexSymbol, &sLineSymbol, &sTagSymbol, &sTypeSymbol, &sTitleSymbol, &sXSymbol, &sYSymbol, &sWidthSymbol, &sHeightSymbol, &sOriginSymbol, &sSizeSymbol, &sFrameSymbol, &sEnabledSymbol, &sEditableSymbol, &sHiddenSymbol, &sValueSymbol, &sRadioGroupSymbol, &sBlockSymbol, &sRangeSymbol, &sActionSymbol, &sAlignSymbol, &sRightSymbol, &sCenterSymbol, &sVerticalAlignSymbol, &sBottomSymbol, &sMarginSymbol, &sPaddingSymbol, &sSubItemsSymbol, &sHFillSymbol, &sVFillSymbol, &sIsProcessingActionSymbol };
+               static const char *sTable2[] = { "text", "textfield", "radio", "button", "checkbox", "popup", "textview", "view", "dialog", "index", "line", "tag", "type", "title", "x", "y", "width", "height", "origin", "size", "frame", "enabled", "editable", "hidden", "value", "radio_group", "block", "range", "action", "align", "right", "center", "vertical_align", "bottom", "margin", "padding", "subitems", "hfill", "vfill", "is_processing_action" };
                int i;
                for (i = 0; i < sizeof(sTable1) / sizeof(sTable1[0]); i++)
                        *(sTable1[i]) = ID2SYM(rb_intern(sTable2[i]));
index 7b490bb..1f431f7 100644 (file)
@@ -37,6 +37,13 @@ MainViewCallback_setNeedsDisplay(MainView *mview, int flag)
 {
 }
 
+/*
+void
+MainViewCallback_moleculeReplaced(MainView *mview, struct Molecule *mol)
+{
+}
+*/
+
 void
 MyAppCallback_beginUndoGrouping(void)
 {
@@ -262,28 +269,6 @@ MolActionCallback_registerUndo(Molecule *mol, MolAction *action)
 {
 }
 
-void
-MainView_setBackgroundColor(MainView *mview, float red, float green, float blue)
-{
-}
-
-void
-MainView_getBackgroundColor(const MainView *mview, float *rgb)
-{
-}
-
-int
-MainView_insertGraphic(MainView *mview, int index, const MainViewGraphic *graphic)
-{
-       return 0;
-}
-
-int
-MainView_removeGraphic(MainView *mview, int index)
-{
-       return 0;
-}
-
 int
 main(int argc, const char **argv)
 {
index 37eec3a..3db3dad 100755 (executable)
@@ -114,6 +114,12 @@ MoleculeView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
        frameText = NULL;
        isRebuildingTable = false;
        
+       Molecule *mol = ((MyDocument *)doc)->GetMolecule();
+       if (mol != NULL) {
+               mview = mol->mview;
+               MainView_setViewObject(mview, this);
+       }
+
        wxMenuBar *menu_bar = wxGetApp().CreateMenuBar(1, &file_history_menu, &edit_menu);
        
        // Associate the menu bar with the frame
@@ -122,8 +128,6 @@ MoleculeView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
        // Associate the edit menu with the command processor
        doc->GetCommandProcessor()->SetEditMenu(edit_menu);
        
-    mview = MainView_newMainView(this);
-       
        // Create the window content
        
        //  A splitter window embraces a grid (left) and main screen (right)
@@ -314,10 +318,7 @@ MoleculeView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
 
        mainsizer->Layout();
        splitter->SetSashPosition(240, true);
-       
-       //  Associate the molecule with the main view
-       MainView_setMolecule(mview, ((MyDocument *)doc)->GetMolecule());
-       
+
        //  Initialize table view
        MainView_createColumnsForTableAtIndex(mview, 0);
 
@@ -343,6 +344,9 @@ MoleculeView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
 
        //  Intercept the double-click handler of MyListCtrl
        listctrl->Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(MoleculeView::OnLeftDClickInListCtrl), NULL, this);
+
+       //  Set data source for the list control
+       listctrl->SetDataSource(this);
                                        
     return true;
 }
@@ -379,10 +383,8 @@ MoleculeView::OnClose(bool deleteWindow)
        if (!GetDocument()->Close())
                return false;
 
-       //  Dispose relationship between MainView and Molecule
-       MainView_setMolecule(mview, NULL);
-       //  Release the MainView object
-       MainView_release(mview);
+       //  Dispose relationship between this and Molecule (MainView)
+       MainView_setViewObject(mview, NULL);
        mview = NULL;
 
        //  Dispose Connection between DocManager and file history menu
@@ -390,25 +392,9 @@ MoleculeView::OnClose(bool deleteWindow)
 
        wxGetApp().Disconnect(MyDocumentEvent_scriptMenuModified, MyDocumentEvent, wxCommandEventHandler(MoleculeView::OnScriptMenuModified), NULL, this);
 
-       // Clear the canvas in case we're in single-window mode,
-       // and the canvas stays.
-/*     canvas->ClearBackground();
-       canvas->view = NULL;
-       canvas = NULL;
-
-       wxString s(wxTheApp->GetAppName());
-       if (frame)
-               frame->SetTitle(s);
-
-       SetFrame(NULL);
-
-       Activate(false); */
-
-       if (deleteWindow) {
+       if (deleteWindow)
                frame->Destroy();
-       //      delete frame;
-               return true;
-       }
+
        return true;
 }
 
@@ -689,6 +675,20 @@ MoleculeView::OnActivate(wxActivateEvent &event)
        event.Skip();
 }
 
+void
+MoleculeView::OnMoleculeReplaced()
+{
+       Molecule *mol = ((MyDocument *)GetDocument())->GetMolecule();
+       if ((mol == NULL && mview == NULL) || mol->mview == mview)
+               return;
+       if (mview != NULL)
+               MainView_setViewObject(mview, NULL);
+       if (mol != NULL) {
+               mview = mol->mview;
+               MainView_setViewObject(mview, this);
+       }
+}
+
 #pragma mark ====== MyListCtrl data source ======
 
 int
@@ -1006,6 +1006,7 @@ MainViewCallback_getFilename(MainView *mview, char *buf, int bufsize)
   }
 }
 
+/*
 void
 MainViewCallback_moleculeReplaced(MainView *mview, struct Molecule *mol)
 {
@@ -1018,6 +1019,7 @@ MainViewCallback_moleculeReplaced(MainView *mview, struct Molecule *mol)
                        listctrl->SetDataSource((MoleculeView *)(mview->ref));
        }
 }
+*/
 
 typedef struct Label {
   //   StringTexture *tex;
index 4e2f56f..1ec515e 100755 (executable)
@@ -80,6 +80,8 @@ public:
 
        void OnActivate(wxActivateEvent &event);
        
+       void OnMoleculeReplaced();  /*  Called when Molecule is replaced within MyDocument  */
+       
        /*  MyListCtrlDataSource functions  */
        virtual int GetItemCount(MyListCtrl *ctrl);
        virtual wxString GetItemText(MyListCtrl *ctrl, long row, long column) const;
index ac35477..32ddd60 100755 (executable)
@@ -129,14 +129,23 @@ MyDocument::MyDocument()
 
 MyDocument::~MyDocument()
 {
-  int i;
-  if (mol != NULL)
-    MoleculeRelease(mol);
-  if (undoStack != NULL) {
-       for (i = 0; i < countUndoStack; i++)
-         MolActionRelease(undoStack[i]);
-       free(undoStack);
-  }
+       int i;
+       Molecule *mol2 = mol;
+       mol = NULL;
+
+       /*  May be unnecessary?  */
+       MoleculeView *view = (MoleculeView *)GetFirstView();
+       if (view != NULL) {
+               view->OnMoleculeReplaced();
+       }
+
+       if (mol2 != NULL)
+               MoleculeRelease(mol2);
+       if (undoStack != NULL) {
+               for (i = 0; i < countUndoStack; i++)
+                       MolActionRelease(undoStack[i]);
+               free(undoStack);
+       }
 }
 
 /*
@@ -153,20 +162,19 @@ MyDocument::GetMainView()
 void
 MyDocument::SetMolecule(Molecule *aMolecule)
 {
+       Molecule *mol2 = mol;
        if (mol == aMolecule)
                return;
-       if (mol != NULL)
-               MoleculeRelease(mol);
        mol = aMolecule;
        if (aMolecule != NULL)
                MoleculeRetain(aMolecule);
 
        MoleculeView *view = (MoleculeView *)GetFirstView();
        if (view != NULL) {
-               MainView_setMolecule(view->mview, aMolecule);
-       /*      if (aMolecule->natoms >= 1000)
-                       view->mview->lineMode = 1; */
+               view->OnMoleculeReplaced();
        }
+       if (mol2 != NULL)
+               MoleculeRelease(mol2);
 }
 
 bool
index 2ff4f62..3c57324 100755 (executable)
@@ -43,6 +43,8 @@
                E43CCDE10EB20F0F00108D2D /* QuickTime.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E43CCDD80EB20F0F00108D2D /* QuickTime.framework */; };
                E43CCDE20EB20F0F00108D2D /* System.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E43CCDD90EB20F0F00108D2D /* System.framework */; };
                E441806315BEA63000289B87 /* revisionInfo.txt in Resources */ = {isa = PBXBuildFile; fileRef = E441806215BEA63000289B87 /* revisionInfo.txt */; };
+               E445145315F1DA5B0050171E /* MainViewCommon.c in Sources */ = {isa = PBXBuildFile; fileRef = E445145215F1DA5B0050171E /* MainViewCommon.c */; };
+               E445145415F1DA5B0050171E /* MainViewCommon.c in Sources */ = {isa = PBXBuildFile; fileRef = E445145215F1DA5B0050171E /* MainViewCommon.c */; };
                E44CEED6100E1E9C0040BD51 /* ProgressFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E44CEED4100E1E9C0040BD51 /* ProgressFrame.cpp */; };
                E4513F550EED72C0009DF1F7 /* MyListCtrl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4513F540EED72C0009DF1F7 /* MyListCtrl.cpp */; };
                E46C904A108F491E000E984D /* MyThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46C9049108F491E000E984D /* MyThread.cpp */; };
                E43CCDD80EB20F0F00108D2D /* QuickTime.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuickTime.framework; path = /System/Library/Frameworks/QuickTime.framework; sourceTree = "<absolute>"; };
                E43CCDD90EB20F0F00108D2D /* System.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = System.framework; path = /System/Library/Frameworks/System.framework; sourceTree = "<absolute>"; };
                E441806215BEA63000289B87 /* revisionInfo.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = revisionInfo.txt; path = ../revisionInfo.txt; sourceTree = SOURCE_ROOT; };
+               E445145215F1DA5B0050171E /* MainViewCommon.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = MainViewCommon.c; sourceTree = "<group>"; };
                E44CEED4100E1E9C0040BD51 /* ProgressFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ProgressFrame.cpp; path = ../wxSources/ProgressFrame.cpp; sourceTree = SOURCE_ROOT; };
                E44CEED5100E1E9C0040BD51 /* ProgressFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProgressFrame.h; path = ../wxSources/ProgressFrame.h; sourceTree = SOURCE_ROOT; };
                E4513F530EED72C0009DF1F7 /* MyListCtrl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MyListCtrl.h; path = ../wxSources/MyListCtrl.h; sourceTree = SOURCE_ROOT; };
                                E433CE7C0EC709BD00675985 /* IntGroup.c */,
                                E433CE7F0EC709BD00675985 /* MainView.h */,
                                E433CE7E0EC709BD00675985 /* MainView.c */,
+                               E445145215F1DA5B0050171E /* MainViewCommon.c */,
                                E433CE810EC709BD00675985 /* Missing.h */,
                                E433CE800EC709BD00675985 /* Missing.c */,
                                E433CE830EC709BD00675985 /* MolAction.h */,
                                E4A4667610C15B4300E40A9D /* listctrl.cpp in Sources */,
                                E4A1802811897F8600B394E7 /* wxKillAddition.cpp in Sources */,
                                9E12580F119EC42E00E95DC3 /* docview.cpp in Sources */,
+                               E445145415F1DA5B0050171E /* MainViewCommon.c in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                E4D5AD9C1180890A00B1D8A4 /* Dcd.c in Sources */,
                                E4D5ADA611808A2C00B1D8A4 /* cmdtool_stubs.c in Sources */,
                                9ECE828311A191A2001B435E /* Trackball.c in Sources */,
+                               E445145315F1DA5B0050171E /* MainViewCommon.c in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };