BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
scene.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_VIEW_WIDGETS_SCENE_H
6 #define BALL_VIEW_WIDGETS_SCENE_H
7 
8 #ifndef BALL_VIEW_KERNEL_MODULARWIDGET_H
10 #endif
11 
12 #ifndef BALL_VIEW_RENDERING_RENDERERSGLRENDERER_H
14 #endif
15 
16 #ifndef BALL_VIEW_KERNEL_COMMON_H
17 # include <BALL/VIEW/KERNEL/common.h>
18 #endif
19 
20 #ifndef BALL_VIEW_RENDERING_RENDERWINDOW_H
22 #endif
23 
24 #ifndef BALL_VIEW_RENDERING_GLRENDERWINDOW_H
26 #endif
27 
28 #ifndef BALL_VIEW_RENDERING_RENDERSETUP_H
30 #endif
31 
32 #ifndef BALL_VIEW_DIALOGS_EDITSETTINGS_H
34 #endif
35 
36 #ifndef BALL_VIEW_KERNEL_EDITOPERATION_H
38 #endif
39 
40 #ifndef BALL_VIEW_KERNEL_MODES_INTERACTIONMODEMANAGER_H
42 #endif
43 
44 #include <QtCore/QThread>
45 #include <QtCore/QTimer>
46 #include <QtGui/QDragEnterEvent>
47 #include <QtGui/QDropEvent>
48 #include <QtGui/QToolBar>
49 #include <QtGui/QFont>
50 #include <QtGui/QPicture>
51 
52 #include <boost/shared_ptr.hpp>
53 
54 #ifdef BALL_HAS_RTFACT
55 
56 #ifndef BALL_VIEW_RENDERING_RAYTRACINGRENDERER_H
58 #endif
59 
60 #endif // BALL_HAS_RTFACT
61 
62 class QMouseEvent;
63 class QRubberBand;
64 class QMenu;
65 class QImage;
66 class QAction;
67 class QWheelEvent;
68 class QKeyEvent;
69 
70 namespace BALL
71 {
72  class Bond;
73  class PDBAtom;
74  class AtomContainer;
75 
76  namespace VIEW
77  {
78  class ColorMap;
79  class InteractionMode;
80  class Preferences;
81  class LightSettings;
82  class StageSettings;
83  class MaterialSettings;
84  class AnimationThread;
85  class ClippingPlane;
86  class CompositeMessage;
87  class ControlSelectionMessage;
88  class RepresentationMessage;
89  class DatasetMessage;
90  class SceneMessage;
91 
92  class TransformationEvent6D;
93  class MotionTrackingEvent;
94  class ButtonEvent;
95  class RenderToBufferFinishedEvent;
96 
139  : public QWidget,
140  public ModularWidget
141  {
142  friend class AnimationThread;
143  friend class RenderSetup;
144  friend class HTMLBasedInterface;
145 
146 #ifdef BALL_HAS_RTFACT
147  typedef boost::shared_ptr<RaytracingRenderer> RaytracingRendererPtr;
148  typedef boost::shared_ptr<RenderWindow> RaytracingWindowPtr;
149 #endif
150 
151  Q_OBJECT
152 
153  public:
155 
156 
159 
166  {
168  CONTROL_WINDOW = 0,
169 
172 
174  RIGHT_EYE_WINDOW
175  };
176 
180 
191  Scene(QWidget* parent_widget = 0, const char* name = NULL, Qt::WFlags w_flags = 0);
192 
203  BALL_DEPRECATED Scene(const Scene& scene, QWidget* parent_widget = NULL, const char* name = NULL, Qt::WFlags wflags = 0);
204 
207  virtual ~Scene();
208 
217  virtual void clear();
218 
220 
224 
229  BALL_DEPRECATED void set(const Scene& scene);
230 
234  BALL_DEPRECATED const Scene& operator = (const Scene& scene);
235 
237 
240 
247  virtual void onNotify(Message *message);
248 
251  virtual bool exportScene(Renderer &er) const;
252 
253  String getBondOrderString_(Index order);
254 
256 
259 
269  virtual void initializeWidget(MainControl& main_control);
270 
272  virtual void fetchPreferences(INIFile& inifile);
273 
275  virtual void writePreferences(INIFile& inifile);
276 
287  virtual void checkMenu(MainControl& main_control);
288 
290 
293 
297  virtual bool isValid() const;
298 
305  virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
306 
307  void setInfo(const QString& info_string);
308  bool isRecording() const;
309  void captureCamera();
310  Atom* getCurrentAtom() { return current_atom_; }
311  void setCurrentAtom(Atom* atom) { current_atom_ = atom; }
312  void notify(Message* msg) { notify_(msg); }
313  Vector2 map3DToViewport(const Vector3& coords);
314  Vector3 mapViewportTo3D(const Vector2& coords);
315  Vector3 mapViewportTo3D(int x, int y);
316  void setRubberBandGeometry(const QRect& rect);
317  void setRubberBandVisible(bool show);
318  void pickObjects(const QPoint& pos, list<GeometricObject*>& objects);
319  void pickObjects(const QPoint& pos1, const QPoint& pos2, list<GeometricObject*>& objects);
320  void merge(Composite* a1, Composite* a2);
321  std::list<AtomContainer*> getContainers();
322  void enterPickingMode();
323  void exitPickingMode();
324 
325  void drawLine(const QPointF& a, const QPointF& b, QPainter* painter = 0);
326  void drawLine(const Vector2& a, const Vector2& b, QPainter* painter = 0);
327 
328  Bond* getCurrentBond() { return current_bond_; }
329  void setCurrentBond(Bond* b) { current_bond_ = b; }
330 
331  void changeBondOrder();
332  void changeBondOrder(Index delta);
333  void activatedOrderItem_(QAction* action);
334  void createMolecule_();
335  void setFormalCharge_();
336 
337  void deselect(bool update=true);
338  void getClickedItems(const QPoint& p);
339 
342  { return stage_;}
343 
345  const Stage* getStage() const
346  { return stage_;}
347 
350  { return stage_settings_; }
351 
354  { return stage_settings_; }
355 
358  { return material_settings_; }
359 
362  { return material_settings_; }
363 
365  void setCamera(const Camera& camera);
366 
368  std::list<Camera>& getAnimationPoints()
369  { return animation_points_;}
370 
372  static void setAnimationSmoothness(float value)
373  { animation_smoothness_ = value;}
374 
376  static float getAnimationSmoothness()
377  { return animation_smoothness_;}
378 
380  float getDownsamplingFactor() const
381  { return downsampling_factor_;}
382 
384  void setDownsamplingFactor(float ds_factor);
385 
387  void setDefaultLighting(bool update_GL = true);
388 
390  static void setMouseSensitivity(float sensitivity)
391  { mouse_sensitivity_ = sensitivity; }
392 
394  static float getMouseSensitivity()
395  { return mouse_sensitivity_;}
396 
398  static void setMouseWheelSensitivity(float sensitivity)
399  { mouse_wheel_sensitivity_ = sensitivity; }
400 
403  { return mouse_wheel_sensitivity_;}
404 
406  static void setShowLightSources(bool state)
407  { show_light_sources_ = state;}
408 
411  { return show_light_sources_;}
412 
415  { return *gl_renderer_;}
416 
417 #ifdef BALL_HAS_RTFACT
418  RaytracingRenderer& getRaytracingRenderer()
420  { return *rt_renderer_;}
421 #endif
422 
427  void setGLRenderer(GLRenderer& renderer);
428 
430  static bool stereoBufferSupportTest();
431 
433  bool inMoveMode() const;
434 
436  bool exportPNG(const String& filename);
437 
439  virtual void setWidgetVisible(bool state);
440 
442  void setOffScreenRendering(bool enabled, Size factor);
443 
445  virtual void paintEvent(QPaintEvent* e);
446 
448  virtual bool eventFilter(QObject* object, QEvent* event);
449 
451  virtual void projectionModeChanged();
452 
454  static void setScreenShotNumber(Position pos) { screenshot_nr_ = pos;}
455 
457  static void setPOVNumber(Position pos) { pov_nr_ = pos;}
458 
460  static void setVRMLNumber(Position pos) {vrml_nr_ = pos;}
461 
463  void rotate(float degree_right, float degree_up);
464 
466  void rotateClockwise(float degree);
467 
473  void move(Vector3 v);
474 
475  // TODO: move this and the next function somewhere else...
481  void moveComposites(const std::list<Composite*>& composites, Vector3 v);
482 
488  void rotateComposites(const std::list<Composite*>& composites, float degree_right, float degree_up, float degree_clockwise = 0);
489 
491  bool isAnimationRunning() const;
492 
494  void setTurnPoint(const Vector3& v) { system_origin_ = v;}
495 
497  const Vector3& getTurnPoint() const { return system_origin_;}
498 
500  void setFullScreen(bool state);
501 
503  void setFPSEnabled(bool state) { show_fps_ = state; }
504 
508  void showText(const String& text, Size font_size = 20);
509 
511  bool isUpdateRunning() const { return update_running_;}
512 
513  void resetTracking() {tracking_initialized_ = false;}
514 
515  // TODO: this pretty hacky!
516  void updateAllMaterials();
517 
518  void updateMaterialForRepresentation(Representation* rep, const Stage::Material& new_material);
519 
520  void lightsUpdated(bool redraw = false);
521 
523  void setupEnvironmentMap(const QImage& image);
524 
525  Position prepareGridTextures(const RegularData3D& grid, const ColorMap& map);
526 
527  void updateGL();
529  void initializePreferencesTab(Preferences &preferences);
530 
532  void finalizePreferencesTab(Preferences &preferences);
533 
535  virtual void applyPreferences();
536 
538  void showContextMenu(QPoint pos);
539 
540  // Allow to use the base class setCursor, too
541  using QWidget::setCursor;
542 
544  void setCursor(String c);
545 
547  void setElementCursor(int number);
548 
550  virtual void addToolBarEntries(QToolBar* tb);
551 
553  virtual void keyPressEvent(QKeyEvent* e);
554 
556  public slots:
558  void createCoordinateSystem();
559 
561  void createCoordinateSystemAtOrigin();
562 
564  String exportPNG();
565 
567  void exportPOVRay();
568 
570  void exportNextPOVRay();
571 
573  void exportXML3D();
574 
576  void dumpXML3D(std::ostream& xml3ddump);
577 
579  void printScene();
580 
582  void showExportPNGDialog();
583 
585  void showExportVRMLDialog();
586 
588  void setPreview(bool state) { use_preview_ = state; }
589 
591  bool usePreview() const { return use_preview_; }
592 
593  bool useVertexBuffers() const { return want_to_use_vertex_buffer_; }
594 
598  virtual void switchShowWidget();
599 
601  void switchRenderer(RenderSetup::RendererType new_type);
602 
604  void addGlWindow();
605 
606 #ifdef BALL_HAS_RTFACT
607  void addRTfactWindow();
609 #endif
610 
612  void exitStereo();
613 
615  void enterStereo();
616 
618  void enterActiveStereo();
619 
621  void enterDualStereo();
622 
624  void enterDualStereoDifferentDisplays();
625 
627  void clearRecordedAnimation();
628 
630  void startAnimation();
631 
633  void stopAnimation();
634 
636  void switchToLastMode();
637 
639  void switchShowGrid();
640 
642  void showInfos();
643 
645  void setupViewVolume();
646 
648  void storeViewPoint();
649 
651  void restoreViewPoint();
652 
654  void startContinuousLoop();
655 
657  void stopContinuousLoop();
658 
660  void toggleContinuousLoop();
661 
663  void applyStereoDefaults();
664 
665 #ifdef BALL_HAS_RTFACT
666  RaytracingWindowPtr getWindow(WindowType aWindowType);
667 #endif
668 
669  void createNewMolecule();
670  void saturateWithHydrogens();
671  void optimizeStructure();
672  void computeBondOrders();
673 
674  // slots for communication with PTEDialog
675  void setEditElementType(int element_number);
676  int getEditElementType();
677 
679  protected slots:
680 
684 
687  virtual void showViewPoint_();
689 
691  virtual void setViewPoint_();
692 
694  virtual void resetCamera_();
695 
699  virtual void resetRepresentationsForRenderer_(RenderSetup& rs);
700 
702  virtual void dropEvent(QDropEvent* e);
703 
705  virtual void dragEnterEvent(QDragEnterEvent* e);
706 
707  // dummy slot for menu entries without immediate action (saves many lines code this way)
708  void dummySlot(){}
709 
711 
713  signals:
714 
715  // signal for communication with EditOperationDialog
716  void newEditOperation(EditOperation &eo);
717 
719  protected:
720 
723  void handleRepresentationMessage_(RepresentationMessage* rm);
724 
727  void handleDatasetMessage_(DatasetMessage* dm);
728 
731  void handleSceneMessage_(SceneMessage* sm);
732 
735  void handleCompositeMessage_(CompositeMessage* cm);
736 
739  void handleControlSelectionMessage_(ControlSelectionMessage* csm);
740 
743  virtual void handleRenderToBufferFinishedEvent_(RenderToBufferFinishedEvent* evt);
744 
749  void renderText_(QPointF const& point, QString const& text, QPaintDevice* current_dev);
750 
756  void insert_(int x_, int y_, PDBAtom &atom_);
757 
762  TVector2<float> getScreenPosition_(Vector3 vec);
763 
764  void initializeMembers_();
765 
766  void renderGrid_();
767 
768  QAction *new_molecule_action_, *optimize_action_;
771 
774 
775  // pick atoms/bonds only in highlighted AtomContainer?
776  static bool only_highlighted_;
777  // element for new atoms
779 
780  //undo stack
781  vector<EditOperation> undo_;
784 
788 
791  virtual void init();
792 
799  virtual void paintGL();
800 
807  virtual void resizeEvent(QResizeEvent* event);
808 
814  virtual void customEvent(QEvent* evt);
815 
819  virtual void transformationEvent6D(TransformationEvent6D* evt);
820 
824  virtual void motionTrackingEvent(MotionTrackingEvent* evt);
825 
829  virtual void buttonPressEvent(ButtonEvent* evt);
830 
834  virtual void buttonReleaseEvent(ButtonEvent* evt);
835 
840  virtual void mouseMoveEvent(QMouseEvent* qmouse_event);
841 
846  virtual void mousePressEvent(QMouseEvent* qmouse_event);
847 
852  virtual void mouseReleaseEvent(QMouseEvent* qmouse_event);
853 
857  virtual void wheelEvent(QWheelEvent* qmouse_event);
858 
859  virtual void mouseDoubleClickEvent(QMouseEvent* e);
860 
861  //_
862  void animate_();
863 
864  void rotateSystemClockwise_();
865  void zoomSystem_();
866 
867  void selectionPressed_();
868  void selectionPressedMoved_();
869 
870  void selectObjects_();
871  void pickParent_(QPoint p);
872 
873  void writeLights_(INIFile& inifile) const;
874 
875  void readLights_(const INIFile& inifile);
876 
877  void createCoordinateSystem_(bool at_origin);
878 
879  void registerRenderers_();
880 
882  String createFPSInfo_(Renderer* renderer);
883 
884  // Menu entry IDs
885  QAction *no_stereo_action_, *enter_stereo_action_, *active_stereo_action_, *dual_stereo_action_, *dual_stereo_different_display_action_;
886  QAction *record_animation_action_, *start_animation_action_, *clear_animation_action_, *cancel_animation_action_;
887  QAction *animation_export_POV_action_, *animation_export_VRML_action_, *animation_export_PNG_action_, *animation_repeat_action_;
888 
889 #ifdef BALL_HAS_RTFACT
890  QAction *toggle_continuous_loop_action_;
891 #endif
892  QAction *switch_grid_;
894 
899 
901 
902  QRubberBand* rb_;
903 
907 
908  std::vector<boost::shared_ptr<RenderSetup> > renderers_;
910 
911 #ifdef BALL_HAS_RTFACT
912  RaytracingRenderer* rt_renderer_;
913  RaytracingWindowPtr rt_window_;
914 #endif
915 
916  static float mouse_sensitivity_;
918  static bool show_light_sources_;
919  static float animation_smoothness_;
920  static float downsampling_factor_;
921 
925 
926  // nr of last png file export
928  // nr of last pov file export
930  //nr of last vrml or stl export
932 
933  std::list<Camera> animation_points_;
936 #ifdef BALL_HAS_RTFACT
937  bool continuous_loop_;
938 #endif
941 
943  QPoint info_point_;
944  QByteArray last_state_;
945  list<float> fps_;
946  bool show_fps_;
947  static bool offscreen_rendering_;
953 
954  QString info_string_;
955 
959 
962 
964 
965  QPicture overlay_;
968  };
969 
970 
973  : public QThread
974  {
975  public:
976 
979 
981  virtual void run() {scene_->animate_();}
982 
984  void mySleep(Size msec);
985 
987  void setScene(Scene* scene) { scene_ = scene;}
988 
990  Scene* getScene() { return scene_;}
991 
992  protected:
993 
995  };
996 
997  } // namespace VIEW
998 } // namespace BALL
999 
1000 #endif // BALL_VIEW_WIDGETS_SCENE_H
bool useVertexBuffers() const
Definition: scene.h:593
QAction * no_stereo_action_
Definition: scene.h:885
QAction * optimize_action_
Definition: scene.h:768
const StageSettings * getStageSettings() const
Definition: scene.h:353
void setPreview(bool state)
Enable or disable model previews e.g. while rotating.
Definition: scene.h:588
Base class for all messages concerning a Representation.
Definition: message.h:569
bool tracking_initialized_
Definition: scene.h:897
QAction * add_hydrogens_action_
Definition: scene.h:769
QAction * switch_grid_
Definition: scene.h:892
bool has_overlay_
Definition: scene.h:966
QAction * start_animation_action_
Definition: scene.h:886
bool isUpdateRunning() const
Definition: scene.h:511
MaterialSettings * getMaterialSettings()
Definition: scene.h:357
const Stage * getStage() const
Definition: scene.h:345
static bool only_highlighted_
Definition: scene.h:776
QString info_string_
Definition: scene.h:954
static float mouse_sensitivity_
Definition: scene.h:916
static void setVRMLNumber(Position pos)
Definition: scene.h:460
QList< QAction * > toolbar_actions_view_controls_
Definition: scene.h:952
QAction * bondorders_action_
Definition: scene.h:770
const MaterialSettings * getMaterialSettings() const
Definition: scene.h:361
Camera stored_camera_
Definition: scene.h:906
static void setAnimationSmoothness(float value)
Definition: scene.h:372
GLRenderer * gl_renderer_
Definition: scene.h:909
Position main_renderer_
The index of the renderer responsible for the main display.
Definition: scene.h:958
void dummySlot()
Definition: scene.h:708
QPoint info_point_
Definition: scene.h:943
Index stereo_left_eye_
Definition: scene.h:960
static float animation_smoothness_
Definition: scene.h:919
static void setMouseSensitivity(float sensitivity)
Definition: scene.h:390
static float mouse_wheel_sensitivity_
Definition: scene.h:917
void setScene(Scene *scene)
Definition: scene.h:987
static float getAnimationSmoothness()
Definition: scene.h:376
static bool offscreen_rendering_
Definition: scene.h:947
AnimationThread * animation_thread_
Definition: scene.h:934
#define BALL_DEPRECATED
Definition: COMMON/global.h:66
QToolBar * toolbar_view_controls_
Definition: scene.h:950
Vector3 system_origin_
Definition: scene.h:895
InteractionModeManager mode_manager_
Definition: scene.h:967
LightSettings * light_settings_
Definition: scene.h:922
static void setMouseWheelSensitivity(float sensitivity)
Definition: scene.h:398
QAction * animation_repeat_action_
Definition: scene.h:887
Size font_size_
Definition: scene.h:949
vector< EditOperation > undo_
Definition: scene.h:781
BALL_EXTERN_VARIABLE const double c
Definition: constants.h:149
StageSettings * stage_settings_
Definition: scene.h:923
QList< QAction * > toolbar_actions_edit_controls_
Definition: scene.h:783
#define BALL_VIEW_EXPORT
Definition: COMMON/global.h:52
Atom * current_atom_
Definition: scene.h:772
static void setScreenShotNumber(Position pos)
Definition: scene.h:454
static bool showLightSourcesEnabled()
Definition: scene.h:410
Stage * stage_
Definition: scene.h:904
static float getMouseSensitivity()
Definition: scene.h:394
static void setPOVNumber(Position pos)
Definition: scene.h:457
Vector3 old_trackorigin_
Definition: scene.h:896
bool show_fps_
Definition: scene.h:946
bool stop_animation_
Definition: scene.h:935
void setCurrentAtom(Atom *atom)
Definition: scene.h:311
#define BALL_EMBEDDABLE(TYPE, BASE)
Definition: embeddable.h:31
GLRenderWindow * main_display_
Definition: scene.h:956
Window into which left eye should be rendered. Indicates same window as CONTROL_WINDOW if no stereo i...
Definition: scene.h:171
static Position screenshot_nr_
Definition: scene.h:927
bool update_running_
Definition: scene.h:900
virtual void run()
Definition: scene.h:981
Bond * current_bond_
Definition: scene.h:773
Size offscreen_factor_
Definition: scene.h:948
Stage * getStage()
Definition: scene.h:341
static float getMouseWheelSensitivity()
Definition: scene.h:402
void setCurrentBond(Bond *b)
Definition: scene.h:329
EditSettings * edit_settings_
Definition: scene.h:782
std::list< Camera > animation_points_
Definition: scene.h:933
Index stereo_right_eye_
Definition: scene.h:961
void notify(Message *msg)
Definition: scene.h:312
QFont default_font_
Definition: scene.h:963
std::vector< boost::shared_ptr< RenderSetup > > renderers_
Definition: scene.h:908
GLRenderer & getGLRenderer()
Definition: scene.h:414
const Vector3 & getTurnPoint() const
Definition: scene.h:497
bool use_preview_
Definition: scene.h:940
QRubberBand * rb_
Definition: scene.h:902
static Position pov_nr_
Definition: scene.h:929
static Position vrml_nr_
Definition: scene.h:931
std::list< Camera > & getAnimationPoints()
Definition: scene.h:368
QToolBar * toolbar_edit_controls_
Definition: scene.h:951
void setTurnPoint(const Vector3 &v)
Definition: scene.h:494
static bool show_light_sources_
Definition: scene.h:918
MaterialSettings * material_settings_
Definition: scene.h:924
Camera stereo_camera_
Definition: scene.h:905
QByteArray last_state_
Definition: scene.h:944
void resetTracking()
Definition: scene.h:513
Quaternion old_trackrotation_
Definition: scene.h:898
Atom * getCurrentAtom()
Definition: scene.h:310
float getDownsamplingFactor() const
Definition: scene.h:380
int atomic_number_
Definition: scene.h:778
Bond * getCurrentBond()
Definition: scene.h:328
QPicture overlay_
Definition: scene.h:965
QMenu * create_coordinate_system_
Definition: scene.h:893
list< float > fps_
Definition: scene.h:945
StageSettings * getStageSettings()
Definition: scene.h:349
bool usePreview() const
Returns the state of the preview mode.
Definition: scene.h:591
static float downsampling_factor_
Definition: scene.h:920
static void setShowLightSources(bool state)
Definition: scene.h:406
PreciseTime time_
Definition: scene.h:942
bool want_to_use_vertex_buffer_
Definition: scene.h:939
void setFPSEnabled(bool state)
Definition: scene.h:503