OSDN Git Service

Occasional crash during minimization is fixed.
[molby/Molby.git] / MolLib / MainView.h
1 /*
2  *  MainView.h
3  *
4  *  Created by Toshi Nagata on 06/07/30.
5  *  Copyright 2006-2008 Toshi Nagata. All rights reserved.
6  *
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation version 2 of the License.
10  
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15  */
16
17 #ifndef __mainview_h__
18 #define __mainview_h__
19
20 #include "MolLib.h"
21
22 /*  The OpenGL header location may be different for different platform  */
23 #if defined(__WXMAC__) || defined(__CMDMAC__)
24 #include <OpenGL/gl.h>
25 #include <OpenGL/glu.h>
26 #include <GLUT/vvector.h>
27 #else
28 #include <GL/gl.h>
29 #include <GL/glu.h>
30 #include <GL/glext.h>
31 #endif
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36         
37 enum {
38         kShiftKeyMask = 1,
39         kAltKeyMask = 2
40 };
41
42 struct Molecule;
43 struct Trackball;
44 struct IntGroup;
45
46 struct Label;  /*  A customized data record for drawing text in OpenGL views. Should be defined somewhere in one of the machine-dependent source files. */
47
48 typedef struct LabelRecord {
49         Int labelid;      /*  LabelID is 1-based! (0 means "no label")  */
50         struct Label *label;
51         Int idx1, idx2;
52         Vector pos;  /*  Screen position with depth  */
53 } LabelRecord;
54
55 enum MainViewDraggingMode {
56         kMainViewMovingTrackball = 1,  /* Rotate or scale by trackball */
57         kMainViewSelectingRegion = 2,  /* Selecting a region */
58         kMainViewDraggingSelectedAtoms = 3, /* Dragging selection */
59         kMainViewCreatingBond = 4,     /* Creating a bond */
60 };
61
62 enum MainViewSliderMode {
63         kSliderRotateBondMode = 1,
64         kSliderRotateXMode = 2,
65         kSliderRotateYMode = 3
66 };
67
68 enum {
69         kMainViewAtomTableIndex = 0,
70         kMainViewBondTableIndex = 1,
71         kMainViewAngleTableIndex = 2,
72         kMainViewDihedralTableIndex = 3,
73         kMainViewImproperTableIndex = 4,
74         kMainViewParameterTableIndex = 5,
75         kMainViewMOTableIndex = 6
76 };
77         
78 /*  The custom python classes for MyMolView GUI  */
79 typedef struct MainView {
80 //      PyObject_HEAD
81         struct Molecule *mol;
82         void *ref;  /*  A platform-dependent pointer to the main view object (or the main window **controller** object)  */
83         void *tableRef;  /*  The table view object  */
84
85         unsigned char isInitialized;
86         int mode;
87         struct Trackball *track;
88     GLdouble modelview_matrix[16];
89     GLdouble projection_matrix[16];
90     GLdouble perspective_vector[4];
91         
92         /*  Camera position and direction in object (Cartesian) coordinate  */
93         Vector camera;  /*  The camera position  */
94         Vector lookat;  /*  The center of the screen  */
95         Vector lookto;  /*  The direction from the camera to the screen center; this is easily derived by normalizing (lookat - camera), but provided for convenience  */
96         Vector up;      /*  The direction up in the screen  */
97
98         float atomRadius; /* Scale the vdW radius by this value */
99         float bondRadius; /* in angstrom */
100         float probabilityScale;
101         float dimension;
102         
103         Byte showUnitCell;
104         Byte showPeriodicBox;
105         Byte showExpandedAtoms;
106         Byte showEllipsoids;
107         Byte showHydrogens;
108         Byte showDummyAtoms;
109         Byte showRotationCenter;
110
111         Byte showGraphiteFlag;
112         Int  showGraphite;
113         Byte showPeriodicImageFlag;
114         Int  showPeriodicImage[6];  /* amin, amax, bmin, bmax, cmin, cmax  */
115
116         Byte *visibleFlags;     /*  This is used only as internal cache;
117                                     The attribute of "hidden" atom is set as (ap->exflags & kAtomHiddenFlag).  */
118         Int countHidden;
119         Byte freezeScreen;
120         
121         unsigned char lineMode;     /*  Draw the model with lines  */
122         unsigned char draggingMode; /*  MainViewDraggingMode  */
123         unsigned char isDragging;   /*  Becomes true if mouse moved by a certain amount  */
124         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  */
125         int modifierFlags;  /* The modifier flags during the dragging operation */
126         float dragStartPos[3];  /* If starting position is on some object, then dragStartPos[2] is the screen z-coordinates of that object. Otherwise, dragStartPos[2] = 0.5.  */
127         float dragEndPos[3];    /* dragEndPos[2] is always == dragStartpos[2]  */
128         Vector tempAtomPos[2];  /* The positions of the atoms forming the temporary bond */
129         int tempAtoms[2];       /* The atoms forming the temporary bond */
130
131         Int pasteCount;         /* Used to offset the pasted fragment when the same fragment is pasted multiple times */
132         Int pasteTimeStamp;     /* A time stamp for the last cut/copied/pasted fragment */
133
134         /*  Rotate fragment  */
135 //      int rotateBond[2];      /* The bond along which the fragment is to be rotated  */
136         struct IntGroup *rotateFragment;  /*  The fragment to rotate  */
137         Vector rotateCenter;
138         Vector rotateAxis;
139         Vector *rotateFragmentOldPos; /*  The original positions (malloc'ed pointer)  */
140         
141         /*  Labels  */
142         Int nlabels;
143         LabelRecord *labels;
144         LabelRecord **sortedLabels; /* (LabelRecord *)[nlabels], internally used in drawLabels(). Should be updated when nlabels changes  */
145
146         /*  Table view  */
147         int tableIndex;  /* kMainViewAtomTableIndex, etc.  */
148
149         /*  Caches for the table view; recalculated in MainView_refreshCachedInfo  */
150         struct IntGroup *tableCache;     /* Indices of atoms etc. that are shown in the table */
151         struct IntGroup *tableSelection; /* Selected rows in the table  */
152
153 } MainView;
154 //extern PyTypeObject MainViewType;
155
156 /*  Public functions  */
157 MainView *MainView_newMainView(void *ref);
158 void MainView_initializeOpenGLView(MainView *mview);
159 void MainView_release(MainView *mview);
160 void MainView_setMolecule(MainView *mview, struct Molecule *mol);
161 void MainView_refreshCachedInfo(MainView *mview);
162 int MainView_isAtomHidden(MainView *mview, int index);
163 void MainView_getCamera(MainView *mview, Vector *outCamera, Vector *outLookAt, Vector *outUp);
164 void MainView_resizeToFit(MainView *mview);
165 void MainView_drawModel(MainView *view);
166 void MainView_invalidateLabels(MainView *mview);
167 void MainView_mouseDown(MainView *view, const float *p, int eventMask);
168 void MainView_mouseUp(MainView *view, const float *p, int eventMask, int clickCount);
169 void MainView_mouseDragged(MainView *view, const float *p, int eventMask);
170 void MainView_mouseMoved(MainView *view, const float *p, int eventMask);
171 void MainView_setMode(MainView *mview, int mode);
172 int MainView_getMode(const MainView *mview);
173 void MainView_attachLabelToAtom(MainView *mview, int index);
174 void MainView_detachLabelFromAtom(MainView *mview, int index);
175 void MainView_purgeUnusedLabels(MainView *mview);
176 void MainView_rotateBySlider(MainView *mview, float angle, int mode, int mouseStatus, int modifierFlags);
177 void MainView_selectAll(MainView *mview);
178 void MainView_selectFragment(MainView *mview);
179 void MainView_selectReverse(MainView *mview);
180 void MainView_centerSelection(MainView *mview);
181 int MainView_copy(MainView *mview);
182 int MainView_cut(MainView *mview);
183 int MainView_delete(MainView *mview);
184 int MainView_paste(MainView *mview);
185 int MainView_pasteParameters(MainView *mview);
186 int MainView_copyOrCutParameters(MainView *mview, int flags);
187
188 /*  Table view  */
189 void MainView_tableTitleForIndex(MainView *mview, int idx, char *buf, int bufsize);
190 void MainView_createColumnsForTableAtIndex(MainView *mview, int idx);
191 void MainView_refreshTable(MainView *mview);
192 int MainView_numberOfRowsInTable(MainView *mview);
193 int MainView_indexToTableRow(MainView *mview, int idx);
194 int MainView_tableRowToIndex(MainView *mview, int row);
195 void MainView_valueForTable(MainView *mview, int column, int row, char *buf, int bufsize);
196 void MainView_setValueForTable(MainView *mview, int column, int row, const char *buf);
197 int MainView_setColorForTable(MainView *mview, int column, int row, float *fg, float *bg);
198 void MainView_setSelectionFromTable(MainView *mview);
199 int MainView_isTableItemEditable(MainView *mview, int column, int row);
200 int MainView_tableType(MainView *mview);
201 void MainView_dragTableSelectionToRow(MainView *mview, int row);
202 IntGroup *MainView_selectedMO(MainView *mview);
203
204 /*  Stubs  */
205 /*  These operations should work for the main *view* object  */
206 STUB int MainViewCallback_modifierFlags(void *eventRef);
207 STUB int MainViewCallback_clickCount(void *eventRef);
208 STUB void MainViewCallback_lockFocus(MainView *mview);
209 STUB void MainViewCallback_unlockFocus(MainView *mview);
210 STUB void MainViewCallback_frame(MainView *mview, float *rect);
211 STUB void MainViewCallback_display(MainView *mview);
212 STUB void MainViewCallback_setNeedsDisplay(MainView *mview, int flag);
213 STUB void MainViewCallback_setKeyboardFocus(MainView *mview);
214 STUB int MainViewCallback_mouseCheck(MainView *mview);
215 STUB void MainViewCallback_clearLabels(MainView *mview);
216 STUB void MainViewCallback_drawLabel(MainView *mview, const float *pos, const char *label);
217 STUB void MainViewCallback_drawInfoText(MainView *mview, const char *label);
218 STUB void MainViewCallback_selectMatrixCellForMode(MainView *mview, int mode);
219 //STUB int MainViewCallback_getTag(MainView *mview);
220 STUB MainView *MainViewCallback_viewWithTag(int tag);
221 STUB MainView *MainViewCallback_activeView(void);
222 STUB MainView *MainViewCallback_newFromFile(const char *fname);
223 STUB int MainViewCallback_importFromFile(MainView *mview, const char *fname);
224 STUB void MainViewCallback_getFilename(MainView *mview, char *buf, int bufsize);
225 STUB void MainViewCallback_moleculeReplaced(MainView *mview, struct Molecule *mol);
226
227 STUB struct Label *MainViewCallback_newLabel(MainView *mview, const char *message, float fontsize, const float *forecolor, const float *backcolor); /* colors are rgba */
228 STUB void MainViewCallback_releaseLabel(struct Label *label);
229 STUB void MainViewCallback_drawLabelAtPoint(struct Label *label, const float *pos);
230 STUB void MainViewCallback_labelSize(struct Label *label, float *outSize);
231 STUB int MainViewCallback_getTextWithPrompt(const char *prompt, char *buf, int bufsize);
232
233 /*  Table view  */
234 STUB void MainViewCallback_selectTable(MainView *mview, int idx);
235 STUB int MainViewCallback_numberOfTableColumns(MainView *mview);
236 STUB int MainViewCallback_addTableColumn(MainView *mview, const char *name, int width, int editable);
237 STUB int MainViewCallback_removeTableColumnAtIndex(MainView *mview, int idx);
238 STUB void MainViewCallback_reloadTableData(MainView *mview);
239 STUB void MainViewCallback_setTableSelection(MainView *mview, IntGroup *selection);
240 STUB IntGroup *MainViewCallback_getTableSelection(MainView *mview);
241 STUB void MainViewCallback_showTable(MainView *mview);
242 STUB void MainViewCallback_hideTable(MainView *mview);
243 STUB void MainViewCallback_ensureVisible(MainView *mview, int row);
244 STUB void MainViewCallback_startEditText(MainView *mview, int row, int column);
245
246 /*  Register the type definition  */
247 //extern void MainView_register(PyObject *module);
248
249 #ifdef __cplusplus
250 }
251 #endif
252
253 #endif /* __mainview_h__ */