1 // PROJECT.H : base classes for all graphical user interfaces.
2 
3 // Copyright (C) 1998 Tommi Hassinen.
4 
5 // This package is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 
10 // This package is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 
15 // You should have received a copy of the GNU General Public License
16 // along with this package; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 /*################################################################################################*/
20 
21 #ifndef PROJECT_H
22 #define PROJECT_H
23 
24 #include "ghemicalconfig2.h"
25 
26 class project;
27 class dummy_project;
28 
29 class color_mode;
30 class color_mode_element;		// atom *
31 class color_mode_secstruct;		// atom *
32 class color_mode_hydphob;		// atom *
33 
34 class transparent_primitive;
35 class transparent_primitive_data;
36 
37 class tpd_tri_3c;
38 class tpd_quad_4c;
39 
40 class ogl_dummy_object;		// oglappth/ogl_objects.h
41 class ogl_smart_object;		// oglappth/ogl_objects.h
42 
43 class custom_camera;		// custom_camera.h
44 class ogl_light;		// oglappth/ogl_camera.h
45 
46 #include <ghemical/model.h>
47 #include <ghemical/geomopt.h>
48 #include <ghemical/moldyn.h>
49 
50 #include "oglview_wcl.h"
51 
52 #include "p1dview_wcl.h"
53 #include "p2dview_wcl.h"
54 #include "eldview_wcl.h"
55 #include "rcpview_wcl.h"
56 #include "gpcview_wcl.h"
57 
58 #include <map>
59 #include <vector>
60 using namespace std;
61 
62 #define FILENAME_FILTER	"*.gpr"
63 
64 /*################################################################################################*/
65 
66 class jobinfo_GeomOpt
67 {
68 	public:
69 
70 	project * prj;
71 	geomopt_param go;	// this is a class...
72 	bool show_dialog;
73 
jobinfo_GeomOpt(void)74 	jobinfo_GeomOpt(void) : go(NULL)
75 	{
76 		prj = NULL;
77 		show_dialog = false;
78 	}
79 };
80 
81 class jobinfo_MolDyn
82 {
83 	public:
84 
85 	project * prj;
86 	moldyn_param md;	// this is a class...
87 	bool show_dialog;
88 
jobinfo_MolDyn(void)89 	jobinfo_MolDyn(void) : md(NULL)
90 	{
91 		prj = NULL;
92 		show_dialog = false;
93 	}
94 };
95 
96 struct jobinfo_RandomSearch
97 {
98 	project * prj;
99 
100 	int cycles;
101 	int optsteps;
102 };
103 
104 /*################################################################################################*/
105 
106 class custom_transformer_client :
107 	public ogl_transformer_client
108 {
109 	public:
110 
111 	bool tc_local_object;	// is the object affected by transformation?
112 
113 	public:
114 
115 	custom_transformer_client(void);
116 	~custom_transformer_client(void);
117 };
118 
119 /*################################################################################################*/
120 
121 /**	The "##project" class is an enhanced version of "##model" class, containing
122 	graphical user interface.
123 */
124 
125 class project;
126 
127 bool ReadGPR_OLD(project &, istream &, bool, bool = false);		///< this is for the very old version.
128 bool ReadGPR_v100(project &, istream &, bool, bool = false);		///< this is for the version 1.00.
129 bool ReadGPR_v110(project &, istream &, bool, bool = false);		///< this is for the version 1.10.
130 /// This is an input function for the v1.11 ghemical file format.
131 bool ReadGPR(project &, istream &, bool, bool = false);
132 
133 class project :
134 	public custom_transformer_client,
135 	public model
136 {
137 	protected:
138 
139 	char * project_path;		// may or may not exist...
140 	char * project_filename;	// should always exist...
141 
142 // call oglview-type views graphics views (by tradition)...
143 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144 	vector<oglview_wcl *> graphics_view_vector;
145 
146 // call all other types of views (except project-view) plotting views.
147 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
148 	vector<base_wcl *> plotting_view_vector;
149 
150 	i32s camera_counter;
151 	i32s object_counter;
152 
153 /**	A static counter of display list IDs.
154 	In some targets there can be several GUI's running simultaneously,
155 	so we must make sure that the display list ID's are unique -> static.
156 */
157 	static iGLu list_counter;
158 
159 	atom * mt_a1;	// measure_tool
160 	atom * mt_a2;	// measure_tool
161 	atom * mt_a3;	// measure_tool
162 
163 	readpdb_mdata * importpdb_mdata;	// temporary?!?!?!
164 
165 	friend class gtk_importpdb_dialog;	// importpdb_mdata
166 
167 	public:
168 
169 	vector<ogl_smart_object *> object_vector;
170 	static ogl_dummy_object * selected_object;
171 
172 	static const char appversion[16];
173 	static char appdata_path[256];		// also see libghemical_init()...
174 
175 /**	If background_job_running is "true" it means that a geometry optimization,
176 	molecular dynamics etc. job is running on the background, and the user possibly
177 	can access any of the GUI elements. What we want is to block user out from any
178 	GUI elements that might be able directly or indirectly modify any internal state
179 	or information of the model object (for example addition or removal of atoms or
180 	bonds will instantly mess up everything ; sorting atoms/bonds does the same ;
181 	etc...). However it is good if user can update graphics using zoom/turning tools
182 	and so on...
183 */
184 	static bool background_job_running;
185 
186 	static color_mode_element cm_element;
187 	static color_mode_secstruct cm_secstruct;
188 	static color_mode_hydphob cm_hydphob;
189 
190 	atom * draw_data[2];
191 
192 	public:
193 
194 	project(void);
195 	virtual ~project(void);
196 
197 	void ClearAll(void);
198 
199 	virtual bool Question(const char *) = 0;
200 
201 	// some file name methods...
202 	// ^^^^^^^^^^^^^^^^^^^^^^^^^
203 
204 	const char * GetProjectFileNameExtension(void);
205 
206 	void SetProjectPath(const char *);
207 	void SetProjectFileName(const char *);
208 
209 	void SetDefaultProjectFileName(void);
210 
211 	void ParseProjectFileNameAndPath(const char *);
212 
213 	void GetProjectFileName(char *, int, bool);
214 	void GetFullProjectFileName(char *, int);
215 
216 // methods for file I/O : ReadGPR and WriteGPR are friend functions so that it would be easier to "borrow" them elsewhere...
217 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
218 	friend bool ReadGPR_OLD(project &, istream &, bool, bool);		///< this is for the very old version.
219 	friend bool ReadGPR_v100(project &, istream &, bool, bool);		///< this is for the version 1.00.
220 	friend bool ReadGPR_v110(project &, istream &, bool, bool);		///< this is for the version 1.10.
221 /// This is an input function for the v1.11 ghemical file format.
222 	friend bool ReadGPR(project &, istream &, bool, bool);
223 
224 	friend void WriteGPR_v100(project &, ostream &);	///< this is for the version 1.00.
225 /// This is an output function for the v1.11 ghemical file format.
226 	friend void WriteGPR(project &, ostream &);
227 
228 #ifdef ENABLE_OPENBABEL
229 
230 	bool ImportFile(const char * filename, int index = 0);
231 	bool ExportFile(const char * filename, int index = 0);
232 
233 #endif	// ENABLE_OPENBABEL
234 
235 	// add or remove hydrogen atoms...
236 	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
237 
238 	void AddH(void);
239 	void RemoveH(void);
240 
241 	// some utility functions.
242 	// ^^^^^^^^^^^^^^^^^^^^^^^
243 
244 	const char * GetType(void);
245 	color_mode * GetDefaultColorMode(void);
246 
247 	void SelectAll(void);
248 	void InvertSelection(void);
249 
250 	void HideSelected(void);
251 	void ShowSelected(void);
252 	void LockSelected(void);
253 	void UnlockSelected(void);
254 	void DeleteSelected(void);
255 
256 	iGLu GetDisplayListIDs(iGLu);
257 	void DeleteDisplayLists(iGLu, iGLu);
258 
259 // we need to intercept these atom/bond events from the
260 // model class in order to keep "project view" up-to-date!
261 
262 	void AddAtom_lg(atom &);	// virtual
263 	void RemoveAtom(iter_al);	// virtual
264 
265 	void AddBond(bond &);		// virtual
266 	void RemoveBond(iter_bl);	// virtual
267 
268 	void InvalidateGroups(void);	// virtual
269 	void UpdateChains(void);	// virtual
270 
271 	// some ogl_object-related methods:
272 	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
273 
274 	i32s IsObject(const ogl_dummy_object *);
275 	bool SelectObject(const ogl_dummy_object *);
276 
277 	void AddObject(ogl_smart_object *);
278 	bool RemoveObject(ogl_dummy_object *);
279 
280 	// some camera/window methods:
281 	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
282 
283 	fGL GetDefaultFocus(void);
284 
285 	virtual base_wnd * CreateGraphicsWnd(bool) = 0;
286 	virtual void DestroyGraphicsWnd(base_wnd *) = 0;
287 
288 	virtual base_wnd * CreatePlot1DWnd(bool) = 0;
289 	virtual base_wnd * CreatePlot2DWnd(bool) = 0;
290 	virtual base_wnd * CreateEnergyLevelDiagramWnd(bool) = 0;
291 	virtual base_wnd * CreateReactionCoordinatePlotWnd(bool) = 0;
292 	virtual base_wnd * CreateGenericProteinChainWnd(bool) = 0;
293 	virtual void DestroyPlottingWnd(base_wnd *) = 0;
294 
295 // if custom_camera is NULL, a new one is created ; this is the add cam/new logic.
296 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
297 	oglview_wcl * AddGraphicsClient(custom_camera *, bool);
298 	bool RemoveGraphicsClient(oglview_wcl *, bool);
299 	bool IsThisLastGraphicsClient(oglview_wcl *);
300 
301 // each "plotting" client will create an ogl_camera object of it's own ; none is given.
302 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
303 	p1dview_wcl * AddPlot1DClient(const char *, const char *, bool);
304 	p2dview_wcl * AddPlot2DClient(const char *, const char *, const char *, bool);
305 	eldview_wcl * AddEnergyLevelDiagramClient(bool);
306 	rcpview_wcl * AddReactionCoordinatePlotClient(const char *, const char *, bool);
307 	gpcview_wcl * AddGenericProteinChainClient(bool);
308 	bool RemovePlottingClient(base_wcl *);
309 
310 	void UpdateAllViews(void);
311 
312 	void UpdateAllGraphicsViews(bool = false);	// virtual
313 	void UpdateAllPlottingViews(bool = false);
314 
315 	void UpdateGraphicsViews(ogl_camera *, bool = false);
316 	void UpdateGraphicsView(oglview_wcl *, bool = false);
317 
318 /**	Contains some OpenGL initialization commands
319 	(color, material, light settings).
320 	The OGL selection buffer should also be assigned here!!!
321 */
322 	void InitGL(void);
323 
324 /**	Contains the OpenGL rendering commands that draw the 3D-view.
325 
326 	Selection is done in a rather crude way by dumping the atom pointers directly to
327 	the OGL selection buffer and reading them later there... Works fine as long as
328 	both datatypes have the same size (currently it's 32 bits). If we some day need
329 	64-bit pointers and have only 32-bit sel-buffer we have to use two names...
330 */
331 	void Render(oglview_wcl *, rmode);
332 
333 /**	This is just quickly cut into a different function for clarity... We will call this
334 	multiple times with translation applied if we render some periodic systems...
335 */
336 	void RenderOnce(oglview_wcl *, rmode, bool);
337 	void RenderObjects(oglview_wcl *);
338 
339 	void BeginClientTransformation(ogl_transformer *);	// virtual
340 	void EndClientTransformation(ogl_transformer *);	// virtual
341 
342 void DrawEvent(oglview_wcl *, vector<iGLu> &);
343 void EraseEvent(oglview_wcl *, vector<iGLu> &);
344 
345 void SelectEvent(oglview_wcl *, vector<iGLu> &);
346 void MeasureEvent(oglview_wcl *, vector<iGLu> &);
347 
348 	// some common operations are implemented here:
349 	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
350 
351 	virtual void CreateProgressDialog(const char *, bool, int, int) = 0;
352 	virtual void DestroyProgressDialog(void) = 0;
353 
354 	void ProcessCommandString(oglview_wcl *, const char *);
355 
356 	virtual void start_job_GeomOpt(jobinfo_GeomOpt *) = 0;
357 	virtual void start_job_MolDyn(jobinfo_MolDyn *) = 0;
358 	virtual void start_job_RandomSearch(jobinfo_RandomSearch *) = 0;
359 
360 	void DoDeleteCurrentObject(void);
361 
362 	void DoSwitchLocalLights(ogl_camera *, bool);
363 	void DoSwitchGlobalLights(ogl_camera *, bool);
364 
365 	bool TestAtom(atom *, rmode);
366 	bool TestBond(bond *, rmode);
367 
368 	inline void SetColor(color_mode *, atom *, bool);
369 
370 	void DrawCylinder1(const fGL **, const fGL **, const fGL *);
371 
372 // here are some Do???() functions similar to those in the model class.
373 // however, the classes here are "interactive" and are directly dependent on graphics.
374 // so you don't want to use any of these classes in the console version...
375 
376 	void DoFormula(void);
377 
378 	void DoEnergyPlot1D(i32s, i32s, i32s, i32s, i32s, fGL, fGL, i32s);
379 	void DoEnergyPlot2D(i32s, i32s, i32s, i32s, i32s, fGL, fGL, i32s, i32s, i32s, i32s, i32s, fGL, fGL, i32s);
380 
381 	void DoTransitionStateSearch(f64, f64);
382 	void DoStationaryStateSearch(i32s);
383 };
384 
385 float measure_len(float *, float *);
386 float measure_ang(float *, float *, float *);
387 float measure_tor(float *, float *, float *, float *);
388 
389 /*################################################################################################*/
390 
391 /// the purpose of this class is just to make file operations available (ReadGPR() wants project object).
392 
393 class dummy_project : public project
394 {
395 	public:
396 
397 	dummy_project(void);
398 	~dummy_project(void);
399 
CreateProgressDialog(const char *,bool,int,int)400 	void CreateProgressDialog(const char *, bool, int, int) { }
DestroyProgressDialog(void)401 	void DestroyProgressDialog(void) { }
402 
start_job_GeomOpt(jobinfo_GeomOpt *)403 	void start_job_GeomOpt(jobinfo_GeomOpt *) { }
start_job_MolDyn(jobinfo_MolDyn *)404 	void start_job_MolDyn(jobinfo_MolDyn *) { }
start_job_RandomSearch(jobinfo_RandomSearch *)405 	void start_job_RandomSearch(jobinfo_RandomSearch *) { }
406 
Question(const char *)407 	bool Question(const char *) { return false; }
408 
CreateGraphicsWnd(bool)409 	base_wnd * CreateGraphicsWnd(bool) { return NULL; }
DestroyGraphicsWnd(base_wnd *)410 	void DestroyGraphicsWnd(base_wnd *) { }
411 
CreatePlot1DWnd(bool)412 	base_wnd * CreatePlot1DWnd(bool) { return NULL; }
CreatePlot2DWnd(bool)413 	base_wnd * CreatePlot2DWnd(bool) { return NULL; }
CreateEnergyLevelDiagramWnd(bool)414 	base_wnd * CreateEnergyLevelDiagramWnd(bool) { return NULL; }
CreateReactionCoordinatePlotWnd(bool)415 	base_wnd * CreateReactionCoordinatePlotWnd(bool) { return NULL; }
CreateGenericProteinChainWnd(bool)416 	base_wnd * CreateGenericProteinChainWnd(bool) { return NULL; }
DestroyPlottingWnd(base_wnd *)417 	void DestroyPlottingWnd(base_wnd *) { }
418 };
419 
420 /*################################################################################################*/
421 
422 /// The "##color_mode" class is used to handle the color detemination details.
423 
424 class color_mode
425 {
426 	protected:
427 
428 // this is just an interface definition -> there is no relevant common data?!?!?
429 // this is just an interface definition -> there is no relevant common data?!?!?
430 // this is just an interface definition -> there is no relevant common data?!?!?
431 
432 	public:
433 
color_mode(void)434 	color_mode(void) { }
~color_mode(void)435 	virtual ~color_mode(void) { }
436 
437 // is this (void *)-method really the only possibility to give a virtual function different
438 // parameters without the "hiding problem"???????????????????
439 
440 // should be [void *, i32s CRD_SET, fGL_a4] -> crd-set can be included in coloring??? ALSO NEED TO FIND A BETTER WAY TO INCLUDE PREFS!!!
441 // should be [void *, i32s CRD_SET, fGL_a4] -> crd-set can be included in coloring??? ALSO NEED TO FIND A BETTER WAY TO INCLUDE PREFS!!!
442 // should be [void *, i32s CRD_SET, fGL_a4] -> crd-set can be included in coloring??? ALSO NEED TO FIND A BETTER WAY TO INCLUDE PREFS!!!
443 
444 	virtual void GetColor4(const void *, i32s, fGL *) = 0;
445 };
446 
447 class color_mode_element : public color_mode
448 {
449 	protected:
450 
451 	public:
452 
color_mode_element(void)453 	color_mode_element(void) : color_mode() { }
~color_mode_element(void)454 	~color_mode_element(void) { }
455 
456 	void GetColor4(const void *, i32s, fGL *);
457 };
458 
459 class color_mode_secstruct : public color_mode
460 {
461 	protected:
462 
463 	public:
464 
color_mode_secstruct(void)465 	color_mode_secstruct(void) : color_mode() { }
~color_mode_secstruct(void)466 	~color_mode_secstruct(void) { }
467 
468 	void GetColor4(const void *, i32s, fGL *);
469 };
470 
471 class color_mode_hydphob : public color_mode
472 {
473 	protected:
474 
475 	public:
476 
color_mode_hydphob(void)477 	color_mode_hydphob(void) : color_mode() { }
~color_mode_hydphob(void)478 	~color_mode_hydphob(void) { }
479 
480 	void GetColor4(const void *, i32s, fGL *);
481 };
482 
483 /*################################################################################################*/
484 
485 #endif	// PROJECT_H
486 
487 // eof
488