cherish
UserScene.h
1 #ifndef USERSCENE_H
2 #define USERSCENE_H
3 
4 #include <string>
5 
6 #include <QUndoStack>
7 #include <QObject>
8 #include <QModelIndex>
9 #include <QTreeWidgetItem>
10 
11 #include <osg/Group>
12 #include <osg/ref_ptr>
13 #include <osg/observer_ptr>
14 #include <osgDB/ObjectWrapper>
15 #include <osg/Camera>
16 
17 #include "ProtectedGroup.h"
18 #include "Canvas.h"
19 #include "Stroke.h"
20 #include "Polygon.h"
21 #include "Photo.h"
22 #include "LineSegment.h"
23 #include "Bookmarks.h"
24 #include "../libGUI/ListWidget.h"
25 #include "../libGUI/TreeWidget.h"
26 #include "../libSGControls/AddEntityCommand.h"
27 #include "../libSGControls/EditEntityCommand.h"
28 
29 namespace entity {
30 class Bookmarks;
31 }
32 
33 class BookmarkWidget;
34 namespace fur {
35 class AddCanvasCommand;
36 class AddPhotoCommand;
37 class EditCanvasDeleteCommand;
38 class AddCanvasSeparationCommand;
39 class EditPhotoDeleteCommand;
40 class EditEntityDeleteCommand;
41 class AddStrokeCommand;
42 class AddPolygonCommand;
43 class AddEntityCommand;
44 class AddLineSegmentCommand;
45 class EditStrokesPushCommand;
46 class EditStrokeDeleteCommand;
47 class EditPasteCommand;
48 class EditCutCommand;
49 class EditPhotoPushCommand;
50 class EditSelectedEntitiesDeleteCommand;
51 }
52 
56 namespace entity {
57 
86 class UserScene : public QObject, public osg::ProtectedGroup
87 {
88  Q_OBJECT
89 public:
91  UserScene();
92 
97  UserScene(const UserScene& scene, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
98 
99  META_Node(entity, UserScene)
100 
101 
103  void initializeSG();
104 
105 #ifndef DOXYGEN_SHOULD_SKIP_THIS
106  void setGroupCanvases(osg::Group* group);
107  const osg::Group* getGroupCanvases() const;
108 
109  void setBookmarks(entity::Bookmarks* group);
110  const entity::Bookmarks* getBookmarks() const;
111  entity::Bookmarks* getBookmarksModel() const;
112 
113  void setIdCanvas(unsigned int id);
114  unsigned int getIdCanvas() const;
115 
116  void setIdPhoto(unsigned int id);
117  unsigned int getIdPhoto() const;
118 
119  void setIdBookmark(unsigned int id);
120  unsigned int getIdBookmark() const;
121 
122  void setFilePath(const std::string& name);
123  const std::string& getFilePath() const;
124 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
125 
128  bool isSetFilePath() const;
129 
130 
136  void addCanvas(QUndoStack* stack, const osg::Matrix& R, const osg::Matrix& T);
137 
143  void addCanvas(QUndoStack* stack, const osg::Vec3f& normal, const osg::Vec3f& center);
144 
152  void addCanvas(QUndoStack* stack, const osg::Matrix& R, const osg::Matrix& T, const std::string& name);
153 
154 
162  void addStroke(QUndoStack* stack, float u, float v, cher::EVENT event);
163 
170  void addPolygon(QUndoStack* stack, float u, float v, cher::EVENT event);
171 
178  void addLineSegment(QUndoStack* stack, float u, float v, cher::EVENT event);
179 
184  void addPhoto(QUndoStack* stack, const std::string& fname);
185 
186 
194  void addBookmark(BookmarkWidget *widget, const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up, const double& fov);
195 
199  void updateBookmark(BookmarkWidget *widget, int row);
200 
204  void deleteBookmark(BookmarkWidget *widget, const QModelIndex& index);
205 
206 
214  void eraseStroke(QUndoStack* stack, entity::Stroke* stroke, int first, int last, cher::EVENT event);
215 
216 
227  entity::Canvas* getCanvas(unsigned int id);
228 
235  entity::Canvas* getCanvas(const std::string& name);
236 
237 
249  int getStrokeLevel() const;
250 
261  int getCanvasLevel() const;
262 
274  int getPhotoLevel() const;
275 
276 
287  bool setCanvasCurrent(entity::Canvas* cnv);
288 
300  bool setCanvasPrevious(entity::Canvas* cnv);
301 
314  void setCanvasesButCurrent(bool enabled);
315 
318  void setAllCanvases(bool enabled);
319 
324  bool getCanvasesButCurrent() const;
325 
327  entity::Canvas* getCanvasCurrent() const;
328 
330  entity::Canvas* getCanvasPrevious() const;
331 
332 
341  int getCanvasIndex(entity::Canvas* canvas) const;
342 
351  int getPhotoIndex(entity::Photo* photo, entity::Canvas* canvas) const;
352 
359  entity::Canvas* getCanvasFromIndex(int row);
360 
367  entity::Photo* getPhoto(entity::Canvas* canvas, int row);
368 
370  int getNumCanvases() const;
371 
373  int getNumPhotos(entity::Canvas* canvas) const;
374 
376  int getNumPhotos();
377 
379  int getNumPhotosTill(entity::Canvas* canvas);
380 
388  void editCanvasOffset(QUndoStack* stack, const osg::Vec3f& translate, cher::EVENT event);
389 
398  void editCanvasRotate(QUndoStack* stack, const osg::Quat& rotation, const osg::Vec3f& center3d, cher::EVENT event);
399 
413  void editCanvasClone(QUndoStack* stack, const osg::Vec3f& translate, cher::EVENT event);
414 
427  void editCanvasSeparate(QUndoStack* stack, const osg::Vec3f& translate, cher::EVENT event);
428 
431  void editCanvasDelete(QUndoStack* stack, entity::Canvas* canvas);
432 
436  void editPhotoDelete(QUndoStack* stack, entity::Photo* photo, entity::Canvas* canvas);
437 
444  void editPhotoPush(QUndoStack* stack, entity::Photo* photo, entity::Canvas* source,
445  entity::Canvas* destination);
446 
451  void editPhotoTransparency(entity::Photo* photo, entity::Canvas* canvas, float t);
452 
454  void editPolygonDelete(QUndoStack* stack, entity::Polygon* poly, entity::Canvas* canvas);
455 
461  void editStrokesPush(QUndoStack* stack, osg::Camera* camera);
462 
463 
470  void editStrokesMove(QUndoStack* stack, double u, double v, cher::EVENT event);
471 
478  void editStrokesScale(QUndoStack* stack, double u, double v, cher::EVENT event);
479 
487  void editStrokesRotate(QUndoStack* stack, double u, double v, cher::EVENT event);
488 
492  void editStrokeDelete(QUndoStack* stack, entity::Stroke* stroke);
493 
494  void editEntity2DDelete(QUndoStack* stack, entity::Entity2D* entity);
495 
497  void editSelectedEntitiesDelete(QUndoStack* stack);
498 
500  bool isEntityCurrent() const;
501 
502 
504  bool isEmptyScene() const;
505 
508  bool clearUserData();
509 
512  void updateWidgets();
513 
518  void resetModel(CanvasPhotoWidget* widget);
519 
520 signals:
522  void sendRequestUpdate();
523 
525  void canvasAdded(const std::string& name);
526 
528  void photoAdded(const std::string& name, int idxCanvas);
529 
531  void canvasRemoved(int row);
532 
534  void photoRemoved(int rowCanvas, int rowPhoto);
535 
538  void canvasSelectedColor(int row, int color);
539 
546  void canvasVisibilitySet(int row, bool visibility);
547 
551  void requestSceneToolStatus(bool& visibility);
552 
554  void requestCanvasCreate(const osg::Vec3f& eye, const osg::Vec3f& center, const osg::Vec3f& up);
555 
556 public slots:
559  void onItemChanged(QTreeWidgetItem* item, int column);
560 
563  void onClicked(const QModelIndex& index);
564 
567  void onRightClicked(const QModelIndex& index);
568 
569 protected:
570  std::string getCanvasName();
571  std::string getPhotoName();
572  std::string getBookmarkName();
573  std::string getEntityName(const std::string& name, unsigned int id) const;
574 
575  void strokeStart();
576  void strokeAppend(float u, float v);
577  void strokeFinish(QUndoStack* stack);
578  bool strokeValid() const;
579 
580  void polygonStart();
581  void polygonAppend(float u, float v, QUndoStack *stack);
582  void polygonEdit(float u, float v);
583  void polygonFinish(QUndoStack* stack);
584  bool polygonValid() const;
585 
586  void linesegmentStart();
587  void linesegmentAppend(float u, float v, QUndoStack* stack);
588  void linesegmentEdit(float u, float v);
589  void linesegmentFinish(QUndoStack* stack);
590  bool linesegmentValid() const;
591 
592  void entitiesMoveStart(double u, double v);
593  void entitiesMoveAppend(double u, double v);
594  void entitiesMoveFinish(QUndoStack* stack);
595  bool entitiesSelectedValid() const;
596 
597  void entitiesScaleStart(double u, double v);
598  void entitiesScaleAppend(double u, double v);
599  void entitiesScaleFinish(QUndoStack* stack);
600 
601  void entitiesRotateStart(double u, double v);
602  void entitiesRotateAppend(double u, double v);
603  void entitiesRotateFinish(QUndoStack* stack);
604 
605  void eraseStart(entity::Stroke* stroke, osg::Vec3d& hit);
606  void eraseAppend(entity::Stroke* stroke, osg::Vec3d& hit);
607  void eraseFinish(QUndoStack* stack, entity::Stroke* stroke);
608  bool eraseValid(entity::Stroke* stroke) const;
609 
610  void canvasOffsetStart();
611  void canvasOffsetAppend(const osg::Vec3f& t);
612  void canvasOffsetFinish(QUndoStack* stack);
613  bool canvasEditValid() const;
614 
615  void canvasCloneStart();
616  void canvasCloneAppend(const osg::Vec3f& t);
617  void canvasCloneFinish(QUndoStack* stack);
618  bool canvasCloneValid() const;
619 
620  void canvasSeparateStart();
621  void canvasSeparateAppend(const osg::Vec3f& t);
622  void canvasSeparateFinish(QUndoStack* stack);
623 
624  void canvasRotateStart();
625  void canvasRotateAppend(const osg::Quat& r, const osg::Vec3f& center3d);
626  void canvasRotateFinish(QUndoStack* stack);
627 
628  friend class ::fur::AddCanvasCommand;
629  friend class ::fur::AddPhotoCommand;
630  friend class ::fur::EditCanvasDeleteCommand;
631  friend class ::fur::AddCanvasSeparationCommand;
632  friend class ::fur::EditPhotoDeleteCommand;
633  friend class ::fur::EditEntityDeleteCommand;
634  friend class ::fur::AddStrokeCommand;
635  friend class ::fur::AddPolygonCommand;
636  friend class ::fur::AddEntityCommand;
637  friend class ::fur::AddLineSegmentCommand;
638  friend class ::fur::EditStrokesPushCommand;
639  friend class ::fur::EditStrokeDeleteCommand;
640  friend class ::fur::EditPasteCommand;
641  friend class ::fur::EditCutCommand;
642  friend class ::fur::EditPhotoPushCommand;
643  friend class ::fur::EditSelectedEntitiesDeleteCommand;
644 
645  bool addCanvas(entity::Canvas* canvas);
646  bool removeCanvas(entity::Canvas* canvas);
647 
648  bool addEntity(entity::Canvas* canvas, entity::Entity2D* entity);
649  bool removeEntity(entity::Canvas* canvas, entity::Entity2D* entity);
650 
651 private:
652  osg::ref_ptr<osg::Group> m_groupCanvases;
653  osg::ref_ptr<entity::Bookmarks> m_groupBookmarks;
654  osg::observer_ptr<entity::Canvas> m_canvasCurrent;
655  osg::observer_ptr<entity::Canvas> m_canvasPrevious;
656  osg::ref_ptr<entity::Canvas> m_canvasClone;
658  osg::Vec3f m_deltaT;
659  osg::Quat m_deltaR;
660  double m_u
661  , m_v;
662  bool m_inits;
663  double m_du
664  , m_dv;
665  double m_scaleX
666  , m_scaleY;
667  double m_rotate;
668  unsigned int m_idCanvas;
669  unsigned int m_idPhoto;
670  unsigned int m_idBookmark;
671  std::string m_filePath;
672 };
673 
674 }
675 
676 #endif // USERSCENE_H
A proxy class that helps to connect scene graph camera positions (in format eye, center, up and name) with the corresponding BookmarkWidget.
Definition: Bookmarks.h:48
Definition: Canvas.h:31
Scene graph entities.
Definition: AddEntityCommand.h:17
EVENT
Definition: Settings.h:160
Geometry class that defined strokes entered by a user. The creation and usage of this class must be f...
Definition: Stroke.h:62
Geometry class that defines opacity polygons drawn by a user. The creation and usage of this class mu...
Definition: Polygon.h:47
The UserScene class contains scene graph that was created by user, including the construction tools...
Definition: UserScene.h:86
Definition: Entity2D.h:13
Quad that uses texture to represent a 2D photo in 3D space.
Definition: Photo.h:22
A convinience class that inherits full functionality of osg::Group except the methods that allow dire...
Definition: ProtectedGroup.h:17
Re-defined QTreeWidget that contains info on canvases and their photos. Contains method to obtain cor...
Definition: TreeWidget.h:12
Contains QUndoCommand - based classes that are defined within undo/redo framework. All these classes are made friend classes for entity::UserScene (protected) so that to access add and remove entity functionality.
Re-defined QListWidget that contains a method to obtain the corresponding delegate.
Definition: ListWidget.h:18