#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);
}
}
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
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;
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 */
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);
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);
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);
--- /dev/null
+/*
+ * 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;
+}
+
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
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;
}
*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;
}
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;
}
MoleculeReleaseExternalObj(mp);
if (ObjectDecrRefCount((Object *)mp) == 0) {
MoleculeClear(mp);
+ mp->mview->mol = NULL;
+ MainView_release(mp->mview);
ObjectDealloc((Object *)mp, (Object **)&sMoleculeRoot);
}
}
} 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);
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");
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);
sAlignSymbol, sRightSymbol, sCenterSymbol,
sVerticalAlignSymbol, sBottomSymbol,
sMarginSymbol, sPaddingSymbol, sSubItemsSymbol,
- sHFillSymbol, sVFillSymbol;
+ sHFillSymbol, sVFillSymbol,
+ sIsProcessingActionSymbol;
VALUE rb_cDialog = Qfalse;
VALUE rb_cDialogItem = Qfalse;
/* 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)
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;
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);
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;
}
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]));
{
}
+/*
+void
+MainViewCallback_moleculeReplaced(MainView *mview, struct Molecule *mol)
+{
+}
+*/
+
void
MyAppCallback_beginUndoGrouping(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)
-{
- return 0;
-}
-
-int
-MainView_removeGraphic(MainView *mview, int index)
-{
- return 0;
-}
-
int
main(int argc, const char **argv)
{
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
// 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)
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);
// 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;
}
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
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;
}
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
}
}
+/*
void
MainViewCallback_moleculeReplaced(MainView *mview, struct Molecule *mol)
{
listctrl->SetDataSource((MoleculeView *)(mview->ref));
}
}
+*/
typedef struct Label {
// StringTexture *tex;
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;
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);
+ }
}
/*
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
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;
};