BALL  1.5.0
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 <QtWidgets/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 
145 #ifdef BALL_HAS_RTFACT
146  typedef boost::shared_ptr<RaytracingRenderer> RaytracingRendererPtr;
147  typedef boost::shared_ptr<RenderWindow> RaytracingWindowPtr;
148 #endif
149 
150  Q_OBJECT
151 
152  public:
154 
155 
158 
165  {
167  CONTROL_WINDOW = 0,
168 
171 
173  RIGHT_EYE_WINDOW
174  };
175 
179 
190  Scene(QWidget* parent_widget = 0, const char* name = NULL, Qt::WindowFlags w_flags = 0);
191 
194  virtual ~Scene();
195 
204  virtual void clear();
205 
207 
209 
212 
219  virtual void onNotify(Message *message);
220 
223  virtual bool exportScene(Renderer &er) const;
224 
225  String getBondOrderString_(Index order);
226 
228 
231 
241  virtual void initializeWidget(MainControl& main_control);
242 
244  virtual void fetchPreferences(INIFile& inifile);
245 
247  virtual void writePreferences(INIFile& inifile);
248 
259  virtual void checkMenu(MainControl& main_control);
260 
262 
265 
269  virtual bool isValid() const;
270 
277  virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
278 
279  void setInfo(const QString& info_string);
280  bool isRecording() const;
281  void captureCamera();
282  Atom* getCurrentAtom() { return current_atom_; }
283  void setCurrentAtom(Atom* atom) { current_atom_ = atom; }
284  void notify(Message* msg) { notify_(msg); }
285  Vector2 map3DToViewport(const Vector3& coords);
286  Vector3 mapViewportTo3D(const Vector2& coords);
287  Vector3 mapViewportTo3D(int x, int y);
288  void setRubberBandGeometry(const QRect& rect);
289  void setRubberBandVisible(bool show);
290  void pickObjects(const QPoint& pos, list<GeometricObject*>& objects);
291  void pickObjects(const QPoint& pos1, const QPoint& pos2, list<GeometricObject*>& objects);
292  void merge(Composite* a1, Composite* a2);
293  std::list<AtomContainer*> getContainers();
294  void enterPickingMode();
295  void exitPickingMode();
296 
297  void drawLine(const QPointF& a, const QPointF& b, QPainter* painter = 0);
298  void drawLine(const Vector2& a, const Vector2& b, QPainter* painter = 0);
299 
300  Bond* getCurrentBond() { return current_bond_; }
301  void setCurrentBond(Bond* b) { current_bond_ = b; }
302 
303  void changeBondOrder();
304  void changeBondOrder(Index delta);
305  void activatedOrderItem_(QAction* action);
306  void createMolecule_();
307  void setFormalCharge_();
308 
309  void deselect(bool update=true);
310  void getClickedItems(const QPoint& p);
311 
314  { return stage_;}
315 
317  const Stage* getStage() const
318  { return stage_;}
319 
322  { return stage_settings_; }
323 
326  { return stage_settings_; }
327 
330  { return material_settings_; }
331 
334  { return material_settings_; }
335 
337  void setCamera(const Camera& camera);
338 
340  std::list<Camera>& getAnimationPoints()
341  { return animation_points_;}
342 
344  static void setAnimationSmoothness(float value)
345  { animation_smoothness_ = value;}
346 
348  static float getAnimationSmoothness()
349  { return animation_smoothness_;}
350 
352  float getDownsamplingFactor() const
353  { return downsampling_factor_;}
354 
356  void setDownsamplingFactor(float ds_factor);
357 
359  void setDefaultLighting(bool update_GL = true);
360 
362  BALL_DEPRECATED static void setMouseSensitivity(float /* sensitivity */) {}
363 
365  BALL_DEPRECATED static float getMouseSensitivity() { return 0; }
366 
368  BALL_DEPRECATED static void setMouseWheelSensitivity(float /* sensitivity */) {}
369 
371  BALL_DEPRECATED static float getMouseWheelSensitivity() { return 0; }
372 
374  static void setShowLightSources(bool state)
375  { show_light_sources_ = state;}
376 
379  { return show_light_sources_;}
380 
383  { return *gl_renderer_;}
384 
385 #ifdef BALL_HAS_RTFACT
386  RaytracingRenderer& getRaytracingRenderer()
388  { return *rt_renderer_;}
389 #endif
390 
395  void setGLRenderer(GLRenderer& renderer);
396 
398  static bool stereoBufferSupportTest();
399 
401  bool inMoveMode() const;
402 
404  bool exportPNG(const String& filename);
405 
407  virtual void setWidgetVisible(bool state);
408 
410  void setOffScreenRendering(bool enabled, Size factor);
411 
413  virtual void paintEvent(QPaintEvent* e);
414 
416  virtual bool eventFilter(QObject* object, QEvent* event);
417 
419  virtual void projectionModeChanged();
420 
422  static void setScreenShotNumber(Position pos) { screenshot_nr_ = pos;}
423 
425  static void setPOVNumber(Position pos) { pov_nr_ = pos;}
426 
428  static void setVRMLNumber(Position pos) {vrml_nr_ = pos;}
429 
431  void rotate(float degree_right, float degree_up);
432 
434  void rotateClockwise(float degree);
435 
441  void move(Vector3 v);
442 
443  // TODO: move this and the next function somewhere else...
449  void moveComposites(const std::list<Composite*>& composites, Vector3 v);
450 
456  void rotateComposites(const std::list<Composite*>& composites, float degree_right, float degree_up, float degree_clockwise = 0);
457 
459  bool isAnimationRunning() const;
460 
462  void setTurnPoint(const Vector3& v) { system_origin_ = v;}
463 
465  const Vector3& getTurnPoint() const { return system_origin_;}
466 
468  void setFullScreen(bool state);
469 
471  void setFPSEnabled(bool state) { show_fps_ = state; }
472 
476  void showText(const String& text, Size font_size = 20);
477 
479  bool isUpdateRunning() const { return update_running_;}
480 
481  void resetTracking() {tracking_initialized_ = false;}
482 
483  // TODO: this pretty hacky!
484  void updateAllMaterials();
485 
486  void updateMaterialForRepresentation(Representation* rep, const Stage::Material& new_material);
487 
488  void lightsUpdated(bool redraw = false);
489 
491  void setupEnvironmentMap(const QImage& image);
492 
493  Position prepareGridTextures(const RegularData3D& grid, const ColorMap& map);
494 
495  void updateGL();
497  void initializePreferencesTab(Preferences &preferences);
498 
500  void finalizePreferencesTab(Preferences &preferences);
501 
503  virtual void applyPreferences();
504 
506  void showContextMenu(QPoint pos);
507 
508  // Allow to use the base class setCursor, too
509  using QWidget::setCursor;
510 
512  void setCursor(String c);
513 
515  void setElementCursor(int number);
516 
518  virtual void addToolBarEntries(QToolBar* tb);
519 
521  virtual void keyPressEvent(QKeyEvent* e);
522 
524  public Q_SLOTS:
526  void createCoordinateSystem();
527 
529  void createCoordinateSystemAtOrigin();
530 
532  String exportPNG();
533 
535  void exportPOVRay();
536 
538  void exportNextPOVRay();
539 
541  void printScene();
542 
544  void showExportPNGDialog();
545 
547  void showExportVRMLDialog();
548 
550  void setPreview(bool state) { use_preview_ = state; }
551 
553  bool usePreview() const { return use_preview_; }
554 
555  bool useVertexBuffers() const { return want_to_use_vertex_buffer_; }
556 
560  virtual void switchShowWidget();
561 
563  void switchRenderer(RenderSetup::RendererType new_type);
564 
566  void addGlWindow();
567 
568 #ifdef BALL_HAS_RTFACT
569  void addRTfactWindow();
571 #endif
572 
574  void exitStereo();
575 
577  void enterStereo();
578 
580  void enterActiveStereo();
581 
583  void enterDualStereo();
584 
586  void enterDualStereoDifferentDisplays();
587 
589  void clearRecordedAnimation();
590 
592  void startAnimation();
593 
595  void stopAnimation();
596 
598  void switchToLastMode();
599 
601  void switchShowGrid();
602 
604  void showInfos();
605 
607  void setupViewVolume();
608 
610  void storeViewPoint();
611 
613  void restoreViewPoint();
614 
616  void startContinuousLoop();
617 
619  void stopContinuousLoop();
620 
622  void toggleContinuousLoop();
623 
625  void applyStereoDefaults();
626 
627 #ifdef BALL_HAS_RTFACT
628  RaytracingWindowPtr getWindow(WindowType aWindowType);
629 #endif
630 
631  void createNewMolecule();
632  void saturateWithHydrogens();
633  void optimizeStructure();
634  void computeBondOrders();
635 
636  // slots for communication with PTEDialog
637  void setEditElementType(int element_number);
638  int getEditElementType();
639 
642 
644  protected Q_SLOTS:
645 
649 
652  virtual void showViewPoint_();
654 
656  virtual void setViewPoint_();
657 
659  virtual void resetCamera_();
660 
664  virtual void resetRepresentationsForRenderer_(RenderSetup& rs);
665 
667  virtual void dropEvent(QDropEvent* e);
668 
670  virtual void dragEnterEvent(QDragEnterEvent* e);
671 
672  // dummy slot for menu entries without immediate action (saves many lines code this way)
673  void dummySlot(){}
674 
676 
678  Q_SIGNALS:
679 
680  // signal for communication with EditOperationDialog
681  void newEditOperation(EditOperation &eo);
682 
684  protected:
685 
688  void handleRepresentationMessage_(RepresentationMessage* rm);
689 
692  void handleDatasetMessage_(DatasetMessage* dm);
693 
696  void handleSceneMessage_(SceneMessage* sm);
697 
700  void handleCompositeMessage_(CompositeMessage* cm);
701 
704  void handleControlSelectionMessage_(ControlSelectionMessage* csm);
705 
708  virtual void handleRenderToBufferFinishedEvent_(RenderToBufferFinishedEvent* evt);
709 
714  void renderText_(QPointF const& point, QString const& text, QPaintDevice* current_dev);
715 
721  void insert_(int x_, int y_, PDBAtom &atom_);
722 
727  TVector2<float> getScreenPosition_(Vector3 vec);
728 
729  void initializeMembers_();
730 
731  void renderGrid_();
732 
733  QAction *new_molecule_action_, *optimize_action_;
736 
739 
740  // pick atoms/bonds only in highlighted AtomContainer?
741  static bool only_highlighted_;
742  // element for new atoms
744 
745  //undo stack
746  vector<EditOperation> undo_;
749 
753 
756  virtual void init();
757 
764  virtual void paintGL();
765 
772  virtual void resizeEvent(QResizeEvent* event);
773 
779  virtual void customEvent(QEvent* evt);
780 
784  virtual void transformationEvent6D(TransformationEvent6D* evt);
785 
789  virtual void motionTrackingEvent(MotionTrackingEvent* evt);
790 
794  virtual void buttonPressEvent(ButtonEvent* evt);
795 
799  virtual void buttonReleaseEvent(ButtonEvent* evt);
800 
805  virtual void mouseMoveEvent(QMouseEvent* qmouse_event);
806 
811  virtual void mousePressEvent(QMouseEvent* qmouse_event);
812 
817  virtual void mouseReleaseEvent(QMouseEvent* qmouse_event);
818 
822  virtual void wheelEvent(QWheelEvent* qmouse_event);
823 
824  virtual void mouseDoubleClickEvent(QMouseEvent* e);
825 
826  //_
827  void animate_();
828 
829  void rotateSystemClockwise_();
830  void zoomSystem_();
831 
832  void selectionPressed_();
833  void selectionPressedMoved_();
834 
835  void selectObjects_();
836  void pickParent_(QPoint p);
837 
838  void writeLights_(INIFile& inifile) const;
839 
840  void readLights_(const INIFile& inifile);
841 
842  void createCoordinateSystem_(bool at_origin);
843 
844  void registerRenderers_();
845 
847  String createFPSInfo_(Renderer* renderer);
848 
849  // Menu entry IDs
850  QAction *no_stereo_action_, *enter_stereo_action_, *active_stereo_action_, *dual_stereo_action_, *dual_stereo_different_display_action_;
851  QAction *record_animation_action_, *start_animation_action_, *clear_animation_action_, *cancel_animation_action_;
852  QAction *animation_export_POV_action_, *animation_export_VRML_action_, *animation_export_PNG_action_, *animation_repeat_action_;
853 
854 #ifdef BALL_HAS_RTFACT
855  QAction *toggle_continuous_loop_action_;
856 #endif
857  QAction *switch_grid_;
859 
864 
866 
867  QRubberBand* rb_;
868 
872 
873  std::vector<boost::shared_ptr<RenderSetup> > renderers_;
875 
876 #ifdef BALL_HAS_RTFACT
877  RaytracingRenderer* rt_renderer_;
878  RaytracingWindowPtr rt_window_;
879 #endif
880 
881  static bool show_light_sources_;
882  static float animation_smoothness_;
883  static float downsampling_factor_;
884 
888 
889  // nr of last png file export
891  // nr of last pov file export
893  //nr of last vrml or stl export
895 
896  std::list<Camera> animation_points_;
899 #ifdef BALL_HAS_RTFACT
900  bool continuous_loop_;
901 #endif
904 
906  QPoint info_point_;
907  QByteArray last_state_;
908  list<float> fps_;
909  bool show_fps_;
910  static bool offscreen_rendering_;
916 
917  QString info_string_;
918 
922 
925 
927 
928  QPicture overlay_;
931  };
932 
933 
936  : public QThread
937  {
938  public:
939 
942 
944  virtual void run() {scene_->animate_();}
945 
947  void mySleep(Size msec);
948 
950  void setScene(Scene* scene) { scene_ = scene;}
951 
953  Scene* getScene() { return scene_;}
954 
955  protected:
956 
958  };
959 
960  } // namespace VIEW
961 } // namespace BALL
962 
963 #endif // BALL_VIEW_WIDGETS_SCENE_H
static void setAnimationSmoothness(float value)
Definition: scene.h:344
void setScene(Scene *scene)
Definition: scene.h:950
static BALL_DEPRECATED float getMouseWheelSensitivity()
Definition: scene.h:371
EditSettings * edit_settings_
Definition: scene.h:747
Camera stored_camera_
Definition: scene.h:871
static BALL_DEPRECATED float getMouseSensitivity()
Definition: scene.h:365
MaterialSettings * material_settings_
Definition: scene.h:887
const StageSettings * getStageSettings() const
Definition: scene.h:325
static Position vrml_nr_
Definition: scene.h:894
std::vector< boost::shared_ptr< RenderSetup > > renderers_
Definition: scene.h:873
GLRenderer * gl_renderer_
Definition: scene.h:874
#define BALL_EMBEDDABLE(TYPE, BASE)
Definition: embeddable.h:31
Base class for all messages concerning a Representation.
Definition: message.h:569
QList< QAction * > toolbar_actions_edit_controls_
Definition: scene.h:748
Camera stereo_camera_
Definition: scene.h:870
void setPreview(bool state)
Enable or disable model previews e.g. while rotating.
Definition: scene.h:550
QToolBar * toolbar_edit_controls_
Definition: scene.h:914
Stage * getStage()
Definition: scene.h:313
static float downsampling_factor_
Definition: scene.h:883
Position main_renderer_
The index of the renderer responsible for the main display.
Definition: scene.h:921
MaterialSettings * getMaterialSettings()
Definition: scene.h:329
bool stop_animation_
Definition: scene.h:898
std::list< Camera > animation_points_
Definition: scene.h:896
bool useVertexBuffers() const
Definition: scene.h:555
QList< QAction * > toolbar_actions_view_controls_
Definition: scene.h:915
bool tracking_initialized_
Definition: scene.h:862
const Vector3 & getTurnPoint() const
Definition: scene.h:465
static bool only_highlighted_
Definition: scene.h:741
PreciseTime time_
Definition: scene.h:905
QByteArray last_state_
Definition: scene.h:907
bool update_running_
Definition: scene.h:865
static void setScreenShotNumber(Position pos)
Definition: scene.h:422
#define BALL_VIEW_EXPORT
Definition: COMMON/global.h:52
Window into which left eye should be rendered. Indicates same window as CONTROL_WINDOW if no stereo i...
Definition: scene.h:170
InteractionModeManager & getInteractionModeManager()
Returns a reference to the Scene&#39;s interaction mode manager.
Definition: scene.h:641
LightSettings * light_settings_
Definition: scene.h:885
Stage * stage_
Definition: scene.h:869
Bond * current_bond_
Definition: scene.h:738
Size offscreen_factor_
Definition: scene.h:911
BALL_EXTERN_VARIABLE const double c
Definition: constants.h:149
static void setVRMLNumber(Position pos)
Definition: scene.h:428
InteractionModeManager mode_manager_
Definition: scene.h:930
AnimationThread * animation_thread_
Definition: scene.h:897
static bool show_light_sources_
Definition: scene.h:881
static float animation_smoothness_
Definition: scene.h:882
QPoint info_point_
Definition: scene.h:906
void dummySlot()
Definition: scene.h:673
float getDownsamplingFactor() const
Definition: scene.h:352
void setFPSEnabled(bool state)
Definition: scene.h:471
vector< EditOperation > undo_
Definition: scene.h:746
bool usePreview() const
Returns the state of the preview mode.
Definition: scene.h:553
static Position pov_nr_
Definition: scene.h:892
static void setPOVNumber(Position pos)
Definition: scene.h:425
Bond * getCurrentBond()
Definition: scene.h:300
bool use_preview_
Definition: scene.h:903
Quaternion old_trackrotation_
Definition: scene.h:863
const Stage * getStage() const
Definition: scene.h:317
QString info_string_
Definition: scene.h:917
bool want_to_use_vertex_buffer_
Definition: scene.h:902
GLRenderer & getGLRenderer()
Definition: scene.h:382
Vector3 old_trackorigin_
Definition: scene.h:861
void setTurnPoint(const Vector3 &v)
Definition: scene.h:462
bool has_overlay_
Definition: scene.h:929
std::list< Camera > & getAnimationPoints()
Definition: scene.h:340
QPicture overlay_
Definition: scene.h:928
QRubberBand * rb_
Definition: scene.h:867
QAction * optimize_action_
Definition: scene.h:733
void notify(Message *msg)
Definition: scene.h:284
QMenu * create_coordinate_system_
Definition: scene.h:858
GLRenderWindow * main_display_
Definition: scene.h:919
bool show_fps_
Definition: scene.h:909
QAction * start_animation_action_
Definition: scene.h:851
QAction * switch_grid_
Definition: scene.h:857
QAction * bondorders_action_
Definition: scene.h:735
Definition: constants.h:12
StageSettings * stage_settings_
Definition: scene.h:886
Atom * current_atom_
Definition: scene.h:737
#define BALL_DEPRECATED
Definition: COMMON/global.h:64
QAction * animation_repeat_action_
Definition: scene.h:852
QAction * add_hydrogens_action_
Definition: scene.h:734
StageSettings * getStageSettings()
Definition: scene.h:321
Size font_size_
Definition: scene.h:912
list< float > fps_
Definition: scene.h:908
void setCurrentAtom(Atom *atom)
Definition: scene.h:283
static BALL_DEPRECATED void setMouseSensitivity(float)
Definition: scene.h:362
Atom * getCurrentAtom()
Definition: scene.h:282
Vector3 system_origin_
Definition: scene.h:860
const MaterialSettings * getMaterialSettings() const
Definition: scene.h:333
void resetTracking()
Definition: scene.h:481
static Position screenshot_nr_
Definition: scene.h:890
Index stereo_right_eye_
Definition: scene.h:924
QAction * no_stereo_action_
Definition: scene.h:850
static bool showLightSourcesEnabled()
Definition: scene.h:378
static void setShowLightSources(bool state)
Definition: scene.h:374
virtual void run()
Definition: scene.h:944
static float getAnimationSmoothness()
Definition: scene.h:348
static bool offscreen_rendering_
Definition: scene.h:910
static BALL_DEPRECATED void setMouseWheelSensitivity(float)
Definition: scene.h:368
QToolBar * toolbar_view_controls_
Definition: scene.h:913
QFont default_font_
Definition: scene.h:926
Index stereo_left_eye_
Definition: scene.h:923
int atomic_number_
Definition: scene.h:743
void setCurrentBond(Bond *b)
Definition: scene.h:301
bool isUpdateRunning() const
Definition: scene.h:479