4 * Created by Toshi Nagata on 06/07/30.
5 * Copyright 2006-2008 Toshi Nagata. All rights reserved.
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.
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.
17 #ifndef __mainview_h__
18 #define __mainview_h__
20 /* The OpenGL header location may be different for different platform */
21 #if defined(__WXMAC__) || defined(__CMDMAC__)
22 #include <OpenGL/gl.h>
23 #include <OpenGL/glu.h>
24 #include <GLUT/vvector.h>
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. */
48 typedef struct LabelRecord {
49 Int labelid; /* LabelID is 1-based! (0 means "no label") */
52 Vector pos; /* Screen position with depth */
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 */
62 enum MainViewSliderMode {
63 kSliderRotateBondMode = 1,
64 kSliderRotateXMode = 2,
65 kSliderRotateYMode = 3
69 kMainViewAtomTableIndex = 0,
70 kMainViewBondTableIndex = 1,
71 kMainViewAngleTableIndex = 2,
72 kMainViewDihedralTableIndex = 3,
73 kMainViewImproperTableIndex = 4,
74 kMainViewSeparator1TableIndex = 5,
75 kMainViewParameterTableIndex = 6,
76 kMainViewSeparator2TableIndex = 7,
77 kMainViewUnitCellTableIndex = 8,
78 kMainViewXtalCoordTableIndex = 9,
79 kMainViewSeparator3TableIndex = 10,
80 kMainViewMOTableIndex = 11
84 kMainViewGraphicLine = 1,
85 kMainViewGraphicPoly = 2,
86 kMainViewGraphicCylinder = 3,
87 kMainViewGraphicCone = 4,
88 kMainViewGraphicEllipsoid = 5
91 typedef struct MainViewGraphic {
102 typedef struct MainView {
103 struct Molecule *mol;
104 struct Trackball *track;
105 float background_color[4];
107 MainViewGraphic *graphics;
109 void *ref; /* A platform-dependent pointer to the main view object
110 (or the main window **controller** object)
111 If NULL, then this is a dummy MainView object just for store parameters */
114 Byte showPeriodicBox;
115 Byte showExpandedAtoms;
119 Byte showRotationCenter;
121 Byte showGraphiteFlag;
123 Byte showPeriodicImageFlag;
124 Int showPeriodicImage[6]; /* amin, amax, bmin, bmax, cmin, cmax */
126 Byte lineMode; /* Draw the model with lines */
128 float atomRadius; /* Scale the vdW radius by this value (default: 0.2) */
129 float bondRadius; /* in angstrom (default: 0.1) */
130 int atomResolution; /* Resolution in drawing atoms (default: 12) */
131 int bondResolution; /* Resolution in drawing atoms (default: 8) */
132 float probabilityScale;
136 float offline_scale; /* If non-zero, this is the expansion factor for offline-rendering */
138 #if !defined(__CMDMAC__)
139 /* The following members are used in GUI version only */
141 void *tableRef; /* The table view object */
143 unsigned char isInitialized;
145 GLdouble modelview_matrix[16];
146 GLdouble projection_matrix[16];
147 GLdouble perspective_vector[4];
149 /* Camera position and direction in object (Cartesian) coordinate */
150 Vector camera; /* The camera position */
151 Vector lookat; /* The center of the screen */
152 Vector lookto; /* The direction from the camera to the screen center; this is easily derived by normalizing (lookat - camera), but provided for convenience */
153 Vector up; /* The direction up in the screen */
155 Byte *visibleFlags; /* This is used only as internal cache;
156 The attribute of "hidden" atom is set as (ap->exflags & kAtomHiddenFlag). */
159 unsigned char draggingMode; /* MainViewDraggingMode */
160 unsigned char isDragging; /* Becomes true if mouse moved by a certain amount */
161 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 */
162 int modifierFlags; /* The modifier flags during the dragging operation */
163 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. */
164 float dragEndPos[3]; /* dragEndPos[2] is always == dragStartpos[2] */
165 Vector tempAtomPos[2]; /* The positions of the atoms forming the temporary bond */
166 int tempAtoms[2]; /* The atoms forming the temporary bond */
167 Vector dragOffset; /* Offset during dragging; recalculated in drawModel() */
169 Int pasteCount; /* Used to offset the pasted fragment when the same fragment is pasted multiple times */
170 Int pasteTimeStamp; /* A time stamp for the last cut/copied/pasted fragment */
172 /* Rotate fragment */
173 // int rotateBond[2]; /* The bond along which the fragment is to be rotated */
174 struct IntGroup *rotateFragment; /* The fragment to rotate */
177 Vector *rotateFragmentOldPos; /* The original positions (malloc'ed pointer) */
182 LabelRecord **sortedLabels; /* (LabelRecord *)[nlabels], internally used in drawLabels(). Should be updated when nlabels changes */
185 int tableIndex; /* kMainViewAtomTableIndex, etc. */
187 /* Caches for the table view; recalculated in MainView_refreshCachedInfo */
188 struct IntGroup *tableCache; /* Indices of atoms etc. that are shown in the table */
189 struct IntGroup *tableSelection; /* Selected rows in the table */
198 /* Public functions */
200 /* "Common" functions, used both in GUI and CMD versions. Defined in MainViewCommon.c */
201 MainView *MainView_new(void);
202 void MainView_setBackgroundColor(MainView *mview, float red, float green, float blue);
203 void MainView_getBackgroundColor(const MainView *mview, float *rgb);
204 int MainView_insertGraphic(MainView *mview, int index, const MainViewGraphic *graphic);
205 int MainView_removeGraphic(MainView *mview, int index);
207 /* GUI-only functions */
208 void MainView_setViewObject(MainView *mview, void *ref);
209 void MainView_initializeOpenGL(void);
210 void MainView_release(MainView *mview);
211 void MainView_setMolecule(MainView *mview, struct Molecule *mol);
212 void MainView_refreshCachedInfo(MainView *mview);
213 int MainView_isAtomHidden(MainView *mview, int index);
214 void MainView_getCamera(MainView *mview, Vector *outCamera, Vector *outLookAt, Vector *outUp);
215 void MainView_resizeToFit(MainView *mview);
216 void MainView_drawModel(MainView *view);
217 void MainView_invalidateLabels(MainView *mview);
218 void MainView_mouseDown(MainView *view, const float *p, int eventMask);
219 void MainView_mouseUp(MainView *view, const float *p, int eventMask, int clickCount);
220 void MainView_mouseDragged(MainView *view, const float *p, int eventMask);
221 void MainView_mouseMoved(MainView *view, const float *p, int eventMask);
223 void MainView_setMode(MainView *mview, int mode);
224 int MainView_getMode(const MainView *mview);
226 void MainView_attachLabelToAtom(MainView *mview, int index);
227 void MainView_detachLabelFromAtom(MainView *mview, int index);
228 void MainView_purgeUnusedLabels(MainView *mview);
229 void MainView_rotateBySlider(MainView *mview, float angle, int mode, int mouseStatus, int modifierFlags);
230 void MainView_selectAll(MainView *mview);
231 void MainView_selectFragment(MainView *mview);
232 void MainView_selectReverse(MainView *mview);
233 void MainView_centerSelection(MainView *mview);
234 int MainView_copy(MainView *mview);
235 int MainView_cut(MainView *mview);
236 int MainView_delete(MainView *mview);
237 int MainView_paste(MainView *mview);
238 int MainView_pasteParameters(MainView *mview);
239 int MainView_copyOrCutParameters(MainView *mview, int flags);
242 void MainView_tableTitleForIndex(MainView *mview, int idx, char *buf, int bufsize);
243 int MainView_createColumnsForTableAtIndex(MainView *mview, int idx);
244 void MainView_refreshTable(MainView *mview);
245 int MainView_numberOfRowsInTable(MainView *mview);
246 int MainView_indexToTableRow(MainView *mview, int idx);
247 int MainView_tableRowToIndex(MainView *mview, int row);
248 void MainView_valueForTable(MainView *mview, int column, int row, char *buf, int bufsize);
249 void MainView_setValueForTable(MainView *mview, int column, int row, const char *buf);
250 int MainView_setColorForTable(MainView *mview, int column, int row, float *fg, float *bg);
251 void MainView_setSelectionFromTable(MainView *mview);
252 int MainView_isTableItemEditable(MainView *mview, int column, int row);
253 int MainView_tableType(MainView *mview);
254 void MainView_dragTableSelectionToRow(MainView *mview, int row);
255 IntGroup *MainView_selectedMO(MainView *mview);
258 /* These operations should work for the main *view* object */
259 STUB int MainViewCallback_modifierFlags(void *eventRef);
260 STUB int MainViewCallback_clickCount(void *eventRef);
261 STUB void MainViewCallback_lockFocus(MainView *mview);
262 STUB void MainViewCallback_unlockFocus(MainView *mview);
263 STUB void MainViewCallback_frame(MainView *mview, float *rect);
264 STUB void MainViewCallback_display(MainView *mview);
265 STUB void MainViewCallback_makeFront(MainView *mview);
266 STUB void MainViewCallback_setNeedsDisplay(MainView *mview, int flag);
267 STUB void MainViewCallback_setKeyboardFocus(MainView *mview);
268 STUB int MainViewCallback_mouseCheck(MainView *mview);
269 STUB void MainViewCallback_clearLabels(MainView *mview);
270 STUB void MainViewCallback_drawLabel(MainView *mview, const float *pos, const char *label);
271 STUB void MainViewCallback_drawInfoText(MainView *mview, const char *label);
272 STUB void MainViewCallback_selectMatrixCellForMode(MainView *mview, int mode);
273 //STUB int MainViewCallback_getTag(MainView *mview);
274 STUB MainView *MainViewCallback_viewWithTag(int tag);
275 STUB MainView *MainViewCallback_activeView(void);
276 //STUB MainView *MainViewCallback_newFromFile(const char *fname);
277 STUB int MainViewCallback_importFromFile(MainView *mview, const char *fname);
278 STUB void MainViewCallback_getFilename(MainView *mview, char *buf, int bufsize);
279 //STUB void MainViewCallback_moleculeReplaced(MainView *mview, struct Molecule *mol);
280 STUB void MainViewCallback_enableToggleButton(MainView *mview, int mode, int flag);
282 STUB struct Label *MainViewCallback_newLabel(MainView *mview, const char *message, float fontsize, const float *forecolor, const float *backcolor); /* colors are rgba */
283 STUB void MainViewCallback_releaseLabel(struct Label *label);
284 STUB void MainViewCallback_drawLabelAtPoint(struct Label *label, const float *pos);
285 STUB void MainViewCallback_labelSize(struct Label *label, float *outSize);
286 STUB int MainViewCallback_getTextWithPrompt(const char *prompt, char *buf, int bufsize);
289 STUB void MainViewCallback_selectTable(MainView *mview, int idx);
290 STUB int MainViewCallback_numberOfTableColumns(MainView *mview);
291 STUB int MainViewCallback_addTableColumn(MainView *mview, const char *name, int width, int editable);
292 STUB int MainViewCallback_removeTableColumnAtIndex(MainView *mview, int idx);
293 STUB void MainViewCallback_reloadTableData(MainView *mview);
294 STUB void MainViewCallback_setTableSelection(MainView *mview, IntGroup *selection);
295 STUB IntGroup *MainViewCallback_getTableSelection(MainView *mview);
296 STUB void MainViewCallback_showTable(MainView *mview);
297 STUB void MainViewCallback_hideTable(MainView *mview);
298 STUB void MainViewCallback_ensureVisible(MainView *mview, int row);
299 STUB void MainViewCallback_startEditText(MainView *mview, int row, int column);
301 /* Register the type definition */
302 //extern void MainView_register(PyObject *module);
308 #endif /* __mainview_h__ */