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
53//== FORWARDDECLARATIONS ======================================================
54class QGraphicsLinearLayout;
55
56//== NAMESPACES ===============================================================
57namespace VSI {
58
59//== FORWARDDECLARATIONS ======================================================
60class GraphicsScene;
61class ElementInput;
62class ElementOutput;
63class ElementFunction;
64
65class Element;
66class Text;
67
68//== CLASS DEFINITION =========================================================
69
72class SceneElement : public QGraphicsWidget
73{
74 Q_OBJECT
75
76 public:
78 SceneElement (GraphicsScene *_scene, Element *_element);
79
82
84 void paint (QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget = 0);
85
87 Element *element () const { return element_; };
88
90 QVector<ElementInput *> inputs () { return inputs_; };
91
93 QVector<ElementOutput *> outputs () { return outputs_; };
94
96 QVector<ElementFunction *> functions () { return functions_; };
97
99 ElementInput *dataIn () { return dataIn_; };
100
102 ElementOutput *dataOut () { return dataOut_; };
103
105 void resetCodeGeneration ();
106
108 void replaceCodeBlock (const QString& _name, const QString& _id, const QString& _value);
109
111 QString variableId ();
112
114 int id () { return id_; };
115
117 QString code () { return code_; };
118
120 bool isBefore (SceneElement *_e);
121
123 bool isAfter (SceneElement *_e);
124
126 void saveToXml (QDomDocument &_doc, QDomElement &_root);
127
135 void loadFromXml (QDomElement& _domElement,std::vector<QString>& _connections);
136
138 GraphicsScene *graphicsScene () { return scene_; };
139
140 protected:
141
142 // mouse handling for draging
143 void mousePressEvent (QGraphicsSceneMouseEvent *_event);
144 void mouseMoveEvent (QGraphicsSceneMouseEvent *_event);
145 void mouseReleaseEvent (QGraphicsSceneMouseEvent *_event);
146 void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *_event);
147
148 // handle movement
149 void moveEvent (QGraphicsSceneMoveEvent *_event);
150
151 private slots:
152
153 // show input configuration dialog
154 void showInputConfig ();
155
156 private:
157
158 // invalidate (reset) all connections of this element
159 void invalidateConnections ();
160
161 private:
162
163 GraphicsScene *scene_;
164 Element *element_;
165
166 QVector<ElementInput *> inputs_;
167 QVector<ElementOutput *> outputs_;
168
169 ElementInput *dataIn_;
170 ElementOutput *dataOut_;
171
172 QVector<ElementFunction *> functions_;
173
174 QVector<ElementInput *> configInputs_;
175
176 QString code_;
177
178 int id_;
179
180 Text *name_;
181 Text *elementName_;
182 QGraphicsLinearLayout *nameLayout_;
183};
184
185//=============================================================================
186}
187//=============================================================================
188
189#endif
QString variableId()
Unique variable name for code generation.
~SceneElement()
Destructor.
SceneElement(GraphicsScene *_scene, Element *_element)
Constructor.
Definition: sceneElement.cc:97
GraphicsScene * graphicsScene()
Scene.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *_event)
Double click occured. We can't use mouseDoubleClickEvent because we won't get one for the ConecctionP...
void paint(QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget=0)
Background painting.
QVector< ElementOutput * > outputs()
Outputs.
Definition: sceneElement.hh:93
void replaceCodeBlock(const QString &_name, const QString &_id, const QString &_value)
Replace block with name _name and id _id with _value.
void saveToXml(QDomDocument &_doc, QDomElement &_root)
Save to xml.
void loadFromXml(QDomElement &_domElement, std::vector< QString > &_connections)
Load one scene Element from xml.
ElementInput * dataIn()
Scene input.
Definition: sceneElement.hh:99
bool isBefore(SceneElement *_e)
Will this element be executed before _e bacause of its connections?
void resetCodeGeneration()
Reset code block for code generation.
Element * element() const
Context VSI::Element.
Definition: sceneElement.hh:87
ElementOutput * dataOut()
Scene output.
QString code()
Code block.
bool isAfter(SceneElement *_e)
Will this element be executed after _e bacause of its connections?
QVector< ElementFunction * > functions()
Functions.
Definition: sceneElement.hh:96
int id()
Unique id for identification.
QVector< ElementInput * > inputs()
Inputs.
Definition: sceneElement.hh:90