Developer Documentation
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 #ifndef VSI_SCENEELEMENT_HH
45 #define VSI_SCENEELEMENT_HH
46 
47 //== INCLUDES =================================================================
48 #include <QGraphicsWidget>
49 #include <QString>
50 #include <QDomDocument>
51 #include <QDomElement>
52 #include <QXmlQuery>
53 
54 //== FORWARDDECLARATIONS ======================================================
55 class QGraphicsLinearLayout;
56 
57 //== NAMESPACES ===============================================================
58 namespace VSI {
59 
60 //== FORWARDDECLARATIONS ======================================================
61 class GraphicsScene;
62 class ElementInput;
63 class ElementOutput;
64 class ElementFunction;
65 
66 class Element;
67 class Text;
68 
69 //== CLASS DEFINITION =========================================================
70 
73 class SceneElement : public QGraphicsWidget
74 {
75  Q_OBJECT
76 
77  public:
79  SceneElement (GraphicsScene *_scene, Element *_element);
80 
82  ~SceneElement ();
83 
85  void paint (QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget = 0);
86 
88  Element *element () const { return element_; };
89 
91  QVector<ElementInput *> inputs () { return inputs_; };
92 
94  QVector<ElementOutput *> outputs () { return outputs_; };
95 
97  QVector<ElementFunction *> functions () { return functions_; };
98 
100  ElementInput *dataIn () { return dataIn_; };
101 
103  ElementOutput *dataOut () { return dataOut_; };
104 
106  void resetCodeGeneration ();
107 
109  void replaceCodeBlock (QString _name, QString _id, QString _value);
110 
112  QString variableId ();
113 
115  int id () { return id_; };
116 
118  QString code () { return code_; };
119 
121  bool isBefore (SceneElement *_e);
122 
124  bool isAfter (SceneElement *_e);
125 
127  void saveToXml (QDomDocument &_doc, QDomElement &_root);
128 
130  void loadFromXml (QXmlQuery &_xml);
131 
133  GraphicsScene *graphicsScene () { return scene_; };
134 
135  protected:
136 
137  // mouse handling for draging
138  void mousePressEvent (QGraphicsSceneMouseEvent *_event);
139  void mouseMoveEvent (QGraphicsSceneMouseEvent *_event);
140  void mouseReleaseEvent (QGraphicsSceneMouseEvent *_event);
141  void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *_event);
142 
143  // handle movement
144  void moveEvent (QGraphicsSceneMoveEvent *_event);
145 
146  private slots:
147 
148  // show input configuration dialog
149  void showInputConfig ();
150 
151  private:
152 
153  // invalidate (reset) all connections of this element
154  void invalidateConnections ();
155 
156  private:
157 
158  GraphicsScene *scene_;
159  Element *element_;
160 
161  QVector<ElementInput *> inputs_;
162  QVector<ElementOutput *> outputs_;
163 
164  ElementInput *dataIn_;
165  ElementOutput *dataOut_;
166 
167  QVector<ElementFunction *> functions_;
168 
169  QVector<ElementInput *> configInputs_;
170 
171  QString code_;
172 
173  int id_;
174 
175  Text *name_;
176  Text *elementName_;
177  QGraphicsLinearLayout *nameLayout_;
178 };
179 
180 //=============================================================================
181 }
182 //=============================================================================
183 
184 #endif
void paint(QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget=0)
Background painting.
QString variableId()
Unique variable name for code generation.
ElementInput * dataIn()
Scene input.
int id()
Unique id for identification.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *_event)
Double click occured. We can&#39;t use mouseDoubleClickEvent because we won&#39;t get one for the ConecctionP...
QString code()
Code block.
QVector< ElementOutput * > outputs()
Outputs.
Definition: sceneElement.hh:94
void loadFromXml(QXmlQuery &_xml)
Load from xml.
ElementOutput * dataOut()
Scene output.
SceneElement(GraphicsScene *_scene, Element *_element)
Constructor.
Definition: sceneElement.cc:98
~SceneElement()
Destructor.
void saveToXml(QDomDocument &_doc, QDomElement &_root)
Save to xml.
bool isBefore(SceneElement *_e)
Will this element be executed before _e bacause of its connections?
QVector< ElementFunction * > functions()
Functions.
Definition: sceneElement.hh:97
Element * element() const
Context VSI::Element.
Definition: sceneElement.hh:88
void resetCodeGeneration()
Reset code block for code generation.
bool isAfter(SceneElement *_e)
Will this element be executed after _e bacause of its connections?
GraphicsScene * graphicsScene()
Scene.
void replaceCodeBlock(QString _name, QString _id, QString _value)
Replace block with name _name and id _id with _value.
QVector< ElementInput * > inputs()
Inputs.
Definition: sceneElement.hh:91