Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
sceneElement.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #ifndef VSI_SCENEELEMENT_HH
51 #define VSI_SCENEELEMENT_HH
52 
53 //== INCLUDES =================================================================
54 #include <QGraphicsWidget>
55 #include <QString>
56 #include <QDomDocument>
57 #include <QDomElement>
58 #include <QXmlQuery>
59 
60 //== FORWARDDECLARATIONS ======================================================
61 class QGraphicsLinearLayout;
62 
63 //== NAMESPACES ===============================================================
64 namespace VSI {
65 
66 //== FORWARDDECLARATIONS ======================================================
67 class GraphicsScene;
68 class ElementInput;
69 class ElementOutput;
70 class ElementFunction;
71 
72 class Element;
73 class Text;
74 
75 //== CLASS DEFINITION =========================================================
76 
79 class SceneElement : public QGraphicsWidget
80 {
81  Q_OBJECT
82 
83  public:
85  SceneElement (GraphicsScene *_scene, Element *_element);
86 
88  ~SceneElement ();
89 
91  void paint (QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget = 0);
92 
94  Element *element () const { return element_; };
95 
97  QVector<ElementInput *> inputs () { return inputs_; };
98 
100  QVector<ElementOutput *> outputs () { return outputs_; };
101 
103  QVector<ElementFunction *> functions () { return functions_; };
104 
106  ElementInput *dataIn () { return dataIn_; };
107 
109  ElementOutput *dataOut () { return dataOut_; };
110 
112  void resetCodeGeneration ();
113 
115  void replaceCodeBlock (QString _name, QString _id, QString _value);
116 
118  QString variableId ();
119 
121  int id () { return id_; };
122 
124  QString code () { return code_; };
125 
127  bool isBefore (SceneElement *_e);
128 
130  bool isAfter (SceneElement *_e);
131 
133  void saveToXml (QDomDocument &_doc, QDomElement &_root);
134 
136  void loadFromXml (QXmlQuery &_xml);
137 
139  GraphicsScene *graphicsScene () { return scene_; };
140 
141  protected:
142 
143  // mouse handling for draging
144  void mousePressEvent (QGraphicsSceneMouseEvent *_event);
145  void mouseMoveEvent (QGraphicsSceneMouseEvent *_event);
146  void mouseReleaseEvent (QGraphicsSceneMouseEvent *_event);
147  void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *_event);
148 
149  // handle movement
150  void moveEvent (QGraphicsSceneMoveEvent *_event);
151 
152  private slots:
153 
154  // show input configuration dialog
155  void showInputConfig ();
156 
157  private:
158 
159  // invalidate (reset) all connections of this element
160  void invalidateConnections ();
161 
162  private:
163 
164  GraphicsScene *scene_;
165  Element *element_;
166 
167  QVector<ElementInput *> inputs_;
168  QVector<ElementOutput *> outputs_;
169 
170  ElementInput *dataIn_;
171  ElementOutput *dataOut_;
172 
173  QVector<ElementFunction *> functions_;
174 
175  QVector<ElementInput *> configInputs_;
176 
177  QString code_;
178 
179  int id_;
180 
181  Text *name_;
182  Text *elementName_;
183  QGraphicsLinearLayout *nameLayout_;
184 };
185 
186 //=============================================================================
187 }
188 //=============================================================================
189 
190 #endif
int id()
Unique id for identification.
QVector< ElementInput * > inputs()
Inputs.
Definition: sceneElement.hh:97
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *_event)
Double click occured. We can't use mouseDoubleClickEvent because we won't get one for the ConecctionP...
void saveToXml(QDomDocument &_doc, QDomElement &_root)
Save to xml.
SceneElement(GraphicsScene *_scene, Element *_element)
Constructor.
bool isBefore(SceneElement *_e)
Will this element be executed before _e bacause of its connections?
~SceneElement()
Destructor.
void paint(QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget=0)
Background painting.
void loadFromXml(QXmlQuery &_xml)
Load from xml.
GraphicsScene * graphicsScene()
Scene.
QVector< ElementFunction * > functions()
Functions.
Element * element() const
Context VSI::Element.
Definition: sceneElement.hh:94
ElementInput * dataIn()
Scene input.
ElementOutput * dataOut()
Scene output.
void replaceCodeBlock(QString _name, QString _id, QString _value)
Replace block with name _name and id _id with _value.
QString code()
Code block.
QString variableId()
Unique variable name for code generation.
QVector< ElementOutput * > outputs()
Outputs.
bool isAfter(SceneElement *_e)
Will this element be executed after _e bacause of its connections?
void resetCodeGeneration()
Reset code block for code generation.