Frapper  1.0a
SceneModel.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of FRAPPER
4 research.animationsinstitut.de
5 sourceforge.net/projects/frapper
6 
7 Copyright (c) 2008-2009 Filmakademie Baden-Wuerttemberg, Institute of Animation
8 
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; version 2.1 of the License.
12 
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
21 -----------------------------------------------------------------------------
22 */
23 
33 
34 #ifndef SCENEMODEL_H
35 #define SCENEMODEL_H
36 
37 #include "NodeModel.h"
38 #include "NodeGraphicsItem.h"
39 #include "ViewNode.h"
40 #include "NumberParameter.h"
41 #include "ViewingParameters.h"
42 #include <QtCore/QObject>
43 #include <QtCore/QTime>
44 #include <QtGui/QStandardItemModel>
45 #include <QtGui/QItemSelectionModel>
46 #include <QtGui/QGraphicsScene>
47 
48 // OGRE
49 #include <Ogre.h>
50 #if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32)
51 #include <windows.h>
52 #endif
53 
54 // COLLADA
55 #define NO_BOOST
56 #include <dae.h>
57 #include <dom/domCOLLADA.h>
58 
59 namespace Frapper {
60 
79 class FRAPPER_CORE_EXPORT SceneModel : public QObject
80 {
81 
82  Q_OBJECT
83 
84 public: // constructors and destructors
85 
89  SceneModel ();
90 
94  ~SceneModel ();
95 
96 public: // functions
97 
103  QString getName () const;
104 
110  void setName (const QString &name);
111 
118  NodeModel * getNodeModel () const;
119 
126  QItemSelectionModel * getSelectionModel () const;
127 
133  NodeGraphicsItem * getGraphicsItem ( const QString &name ) const;
134 
140  QGraphicsScene * getGraphicsScene () const;
141 
147  QList<QAction *> getControlActions () const;
148 
154  QStringList getSelectedObjects ( bool onlyConnections = false ) const;
155 
161  int getFrameStep () const;
162 
168  int getFrameRate () const;
169 
177  void getFrameRange ( int& firstFrame, int& lastFrame ) const;
178 
184  int getCurrentFrame () const;
185 
191  int getStartFrame () const;
192 
198  int getEndFrame () const;
199 
205  int getInFrame () const;
206 
212  int getOutFrame () const;
213 
217  void createSceneRoot ();
218 
225  void createScene ( daeElement *rootElement );
226 
238  QString createObject ( const QString &typeName, const QString &name = "", const QPointF &position = QPointF(-1, -1), bool select = false, bool visible = true );
239 
251  void connectParameters ( Node *sourceNode, const QString &sourceParameterName, Node *targetNode, const QString &targetParameterName );
252 
261  void connectParametersByName ( Node *sourceNode, Node *targetNode );
262 
269  void createDaeElements ( daeElement *parentElement );
270 
276  void createSceneDAEProperties ( daeElement *parentElement ) const;
277 
281  void clear ();
282 
283  public slots: //
284 
293  void connectParameters ( Parameter *sourceParameter, Parameter *targetParameter );
294 
301  void connectParameters ( Node *sourceNode, Node *targetNode );
302 
309  void createCamera ( ViewingParameters *viewingParameters );
310 
316  void deleteCamera ( const QString &cameraName );
317 
324  void updateCamera ( const QString &cameraName, ViewingParameters *viewingParameters );
325 
329  void cameraListRequested ();
330 
338  void applyCamera ( const QString &cameraName, ViewingParameters *viewingParameters );
339 
343  void deleteObject ( const QString &name );
344 
348  void selectDeselectObject ( const QString &name );
349 
353  void deleteSelected ();
354 
358  void selectAll ();
359 
363  void evaluateSelectedObjects ();
364 
368  void ignoreSelectedObjects ();
369 
376  void graphicsSceneSelectionChanged ();
377 
381  void changeNodeName(const QString &name);
382 
390  void selectObject ( const QString &name, bool toggle = false );
391 
397  void deselectObject ( const QString &name = "" );
398 
404  inline void setCurrentFrame ( int index, bool realtime = false );
405 
409  void updateFrame ();
410 
416  void setStartFrame ( int index );
417 
423  void setEndFrame ( int index );
424 
430  void setInFrame ( int index );
431 
437  void setOutFrame ( int index );
438 
444  void setFrameStep ( int frameStep );
445 
451  void setFrameRate ( int frameRate );
452 
461  void frameSelectedObjects ( ViewingParameters *viewingParameters );
462 
469  void setViewNode ( unsigned int stageIndex, ViewNode *viewNode );
470 
475  void rebuildScene ();
476 
480  void redrawTriggered ();
481 
487  void setNewNodePosition ( const QPointF &scenePosition );
488 
495  void addKey ( NumberParameter *numberParameter );
496 
497 signals: //
498 
504  void sceneNameChanged ( const QString &name );
505 
511  void realtimeModeToggled ( bool realtime );
512 
518  void selectionChanged ( bool objectsSelected );
519 
526  void currentFrameSet ( int index );
527 
534  void startFrameSet ( int index );
535 
542  void endFrameSet ( int index );
543 
550  void inFrameSet ( int index );
551 
558  void outFrameSet ( int index );
559 
566  void frameStepSet ( int frameStep );
567 
574  void frameRateSet ( int frameRate );
575 
580  void modified ();
581 
586  void triggerRedraw ();
587 
591  void renderingTriggered ();
592 
599  void imageSet ( unsigned int stageIndex, Ogre::TexturePtr image );
600 
606  void objectCreated ( const QString &objectName );
607 
613  //void cameraCreated ( const QString &cameraName );
614 
620  //void cameraDeleted ( const QString &cameraName );
621 
628  void camerasUpdated ( const QList<Node *> &cameraNodes, const QString &cameraName );
629 
633  void loadSceneElementsReady ();
634 
638  void loadReady ();
639 
643  void saveStart ();
644 
645 protected: // events
646 
652  virtual void timerEvent ( QTimerEvent *event );
653 
654  private slots: //
655 
664  void selectionModelSelectionChanged ( const QItemSelection &selected, const QItemSelection &deselected );
665 
672  void connectionDestroyed ( Connection *connection);
673 
680  void on_m_inFrameAction_triggered ( bool checked = false );
681 
688  void on_m_previousKeyAction_triggered ( bool checked = false );
689 
696  void on_m_previousFrameAction_triggered ( bool checked = false );
697 
703  void on_m_playAction_toggled ( bool checked );
704 
710  void on_m_realtimeAction_toggled ( bool checked );
711 
718  void on_m_nextFrameAction_triggered ( bool checked = false );
719 
726  void on_m_nextKeyAction_triggered ( bool checked = false );
727 
734  void on_m_outFrameAction_triggered ( bool checked = false );
735 
736 private: // functions
737 
741  void initializeActions ();
742 
747  void updateActions ();
748 
749  void deleteConnection (const QString &name, bool deleteGraphicItem = false );
750 
759  QPointF decodePosition ( std::string position, const QString &nodeName );
760 
768  void createDaeElements ( ParameterGroup *parameterGroup, daeElement *parentElement ) const;
769 
770  void createParameters(Node *node, ParameterGroup *parameterGroup, daeElement *parametersElement);
771 
772 private: // data
773 
778  QString m_name;
779 
785 
789  QItemSelectionModel *m_selectionModel;
790 
794  QGraphicsScene *m_graphicsScene;
795 
799  QHash<QString, QGraphicsItem *> m_graphicsItemMap;
800 
804  QHash<QString, QGraphicsItem *> m_connectionGraphicsItemMap;
805 
809  QHash<unsigned int, Connection *> m_connectionMap;
810 
814  QList<Node *> m_cameraNodes;
815 
820 
826 
831 
836 
841 
846 
851 
855  unsigned int m_averageCounter;
856 
857 
863  //ViewNode *m_viewNode;
864  QList<ViewNode *> m_viewNodeList;
865 
870 
878 
883 
884 private: // actions
885 
889  QAction *m_inFrameAction;
890 
895 
900 
904  QAction *m_playAction;
905 
910 
915 
919  QAction *m_nextKeyAction;
920 
925 
930 
935 
940 
945 
946 };
947 
948 } // end namespace Frapper
949 
950 #endif