Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
elementInput.cc
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 //== INCLUDES =================================================================
51 #include "elementInput.hh"
52 #include "elementOutput.hh"
53 #include "sceneElement.hh"
54 #include "connectionPoint.hh"
55 #include "connection.hh"
56 #include "graphicsScene.hh"
57 #include "text.hh"
58 #include "../parser/element.hh"
59 #include "../parser/context.hh"
60 #include "../parser/type.hh"
61 #include "../parser/typeWidget.hh"
62
63 //== NAMESPACES ===============================================================
64 namespace VSI {
65
66 //=============================================================================
67 //
68 // CLASS VSI::ElementInput - IMPLEMENTATION
69 //
70 //=============================================================================
71
73 ElementInput::ElementInput (Input *_in, SceneElement *_parent) :
74 ElementInOut (_in, _parent),
75 in_ (_in),
76 isSet_ (false),
77 value_ (""),
78 forceAsk_ (false)
79 {
80 if (state () & Input::Optional)
81 connectionPointItem ()->setState (ConnectionPoint::Optional);
82 else if (state () & Input::NoUserInput)
83 connectionPointItem ()->setState (ConnectionPoint::NoValue);
84 else
85 connectionPointItem ()->setState (ConnectionPoint::RuntimeInput);
86
87 VSI::Type *t = inOut ()->element ()->context ()->getType (inOut ()->typeString ());
88
89 if (t)
90 {
91 TypeWidget *tW = t->widget (inOut ()->hints (), inOut ()->typeString ());
92 if (tW)
93 {
94 value_ = tW->toValue ();
95 delete tW;
96 }
97 }
98
99 typeTextItem ()->setBackground (false, true);
100 typeTextItem ()->setBackgroundBrush (Qt::gray);
101 typeTextItem ()->setBrush (Qt::black);
102 descriptionTextItem ()->setBackground (false, true);
103 descriptionTextItem ()->setBackgroundBrush (Qt::white);
104 descriptionTextItem ()->setBrush (Qt::black);
105
106 connectionPointItem ()->setWidth (qMax (typeTextItem ()->preferredHeight (),
107 descriptionTextItem ()->preferredHeight ()));
108 }
109
110 //------------------------------------------------------------------------------
111
113 ElementInput::~ElementInput ()
114 {
115 }
116
117 //------------------------------------------------------------------------------
118
120 bool ElementInput::valid()
121 {
122 if (!connections ().isEmpty ())
123 return valid_;
124
125 if (isSet () || !(state () & Input::NoRuntimeUserInput) || state () & Input::Optional)
126 return true;
127
128 return false;
129 }
130
131 //------------------------------------------------------------------------------
132
134 unsigned int VSI::ElementInput::state()
135 {
136 return in_->state ();
137 }
138
139 //------------------------------------------------------------------------------
140
142 void ElementInput::addConnection(Connection * _conn)
143 {
144 ElementInOut::addConnection (_conn);
145
146 // update state
147 connectionPointItem ()->setState (ConnectionPoint::Connected);
148 }
149
150 //------------------------------------------------------------------------------
151
153 void ElementInput::removeConnection (Connection * _conn)
154 {
155 ElementInOut::removeConnection (_conn);
156
157 // update state
158 if (connections().isEmpty())
159 {
160 if (isSet ())
161 connectionPointItem ()->setState (ConnectionPoint::UserInput);
162 else if (state () & Input::Optional && !forceAsk_)
163 {
164 connectionPointItem ()->setState (ConnectionPoint::Optional);
165 }
166 else if (state () & Input::NoUserInput)
167 {
168 connectionPointItem ()->setState (ConnectionPoint::NoValue);
169 }
170 else
171 connectionPointItem ()->setState (ConnectionPoint::RuntimeInput);
172 }
173 }
174
175 //------------------------------------------------------------------------------
176
178 void ElementInput::set(bool _set)
179 {
180 if (isSet_ != _set)
181 element ()->graphicsScene ()->contentChange ();
182 isSet_ = _set;
183
184 // update state
185 if (connections().isEmpty())
186 {
187 if (isSet ())
188 connectionPointItem ()->setState (ConnectionPoint::UserInput);
189 else if (state () & Input::Optional && !forceAsk_)
190 {
191 connectionPointItem ()->setState (ConnectionPoint::Optional);
192 }
193 else if (state () & Input::NoUserInput)
194 {
195 connectionPointItem ()->setState (ConnectionPoint::NoValue);
196 }
197 else
198 connectionPointItem ()->setState (ConnectionPoint::RuntimeInput);
199 }
200 }
201
202 //------------------------------------------------------------------------------
203
205 bool ElementInput::isSet ()
206 {
207 // Only configured input
208 if ((state () & Input::NoRuntimeUserInput) && (state () & Input::NoExternalInput))
209 return true;
210 return isSet_;
211 }
212
213 //------------------------------------------------------------------------------
214
216 void ElementInput::saveToXml(QDomDocument & _doc, QDomElement & _root)
217 {
218 QDomText t;
219
220 QDomElement main = _doc.createElement("input");
221 _root.appendChild(main);
222 main.setAttribute ("name",in_->name ());
223
224
225 QDomElement set = _doc.createElement("is_set");
226 main.appendChild(set);
227 t = _doc.createTextNode(isSet_ ? "true" : "false");
228 set.appendChild(t);
229
230 if (state () & Input::Optional && forceAsk_)
231 {
232 QDomElement fA = _doc.createElement("force_ask");
233 main.appendChild(fA);
234 t = _doc.createTextNode(isSet_ ? "true" : "false");
235 fA.appendChild(t);
236 }
237
238 if (isSet_)
239 {
240 QDomElement val = _doc.createElement("value");
241 main.appendChild(val);
242 t = _doc.createTextNode(value_);
243 val.appendChild(t);
244 }
245
246 foreach (Connection *c, connections ())
247 {
248 QDomElement conn = _doc.createElement("connection");
249 main.appendChild(conn);
250 conn.setAttribute ("element",c->output ()->element ()->element ()->name ());
251 conn.setAttribute ("element_id",QString::number (c->output ()->element ()->id ()));
252 conn.setAttribute ("output",c->output ()->inOut ()->name ());
253 }
254
255
256 }
257
258 //------------------------------------------------------------------------------
259
261 void ElementInput::loadFromXml(QXmlQuery & _xml)
262 {
263 QString val = Context::getXmlString (_xml, "is_set/string(text())");
264
265 isSet_ = Context::strToBool (val);
266
267 if (state () & Input::Optional)
268 {
269 val = Context::getXmlString (_xml, "force_ask/string(text())");
270 forceAsk_ = Context::strToBool (val);
271 }
272
273 if (isSet_)
274 {
275 value_ = Context::getXmlString (_xml, "value/string(text())");
276 }
277
278 if (isSet ())
279 connectionPointItem ()->setState (ConnectionPoint::UserInput);
280 else if (state () & Input::Optional && !forceAsk_)
281 {
282 connectionPointItem ()->setState (ConnectionPoint::Optional);
283 }
284 else if (state () & Input::NoUserInput)
285 {
286 connectionPointItem ()->setState (ConnectionPoint::NoValue);
287 }
288 else
289 connectionPointItem ()->setState (ConnectionPoint::RuntimeInput);
290
291 }
292
293 //------------------------------------------------------------------------------
294
296 void ElementInput::setValue(QString _value)
297 {
298 if (value_ != _value)
299 element ()->graphicsScene ()->contentChange ();
300 value_ = _value;
301 }
302
303 //------------------------------------------------------------------------------
304 }
305
VSI::SceneElement::id
int id()
Unique id for identification.
Definition: sceneElement.hh:121
VSI::ElementInput::addConnection
void addConnection(Connection *_conn)
Add connection.
Definition: elementInput.cc:142
VSI
Definition: baseWidget.cc:78
VSI::ElementInput::loadFromXml
void loadFromXml(QXmlQuery &_xml)
Load from xml.
Definition: elementInput.cc:261
VSI::ElementInput::saveToXml
void saveToXml(QDomDocument &_doc, QDomElement &_root)
Save to xml.
Definition: elementInput.cc:216
VSI::ElementInput::valid
bool valid()
Returns state of valid flag (needed during code generation)
Definition: elementInput.cc:120
VSI::Context::strToBool
static bool strToBool(QString _str)
Converts the given string to bool.
Definition: context.cc:555
VSI::ElementInOut::removeConnection
virtual void removeConnection(Connection *_conn)
Remove the Connection.
Definition: elementInOut.cc:170
VSI::Text::setBackground
void setBackground(bool _leftOut, bool _rightOut)
Enables background painting.
Definition: text.cc:306
VSI::Input
Definition: input.hh:66
VSI::InOut::name
const QString & name() const
Name.
Definition: inout.hh:76
VSI::ConnectionPoint::setWidth
void setWidth(int _width)
Sets the diameter.
Definition: connectionPoint.cc:234
VSI::ElementInOut::inOut
InOut * inOut() const
InOut context object.
Definition: elementInOut.hh:116
VSI::InOut::element
const Element * element() const
Element of this input/output.
Definition: inout.hh:85
VSI::ConnectionPoint::setState
void setState(State _state)
sets the state
Definition: connectionPoint.cc:159
VSI::ElementInOut::descriptionTextItem
Text * descriptionTextItem() const
Short description widget.
Definition: elementInOut.hh:101
VSI::Context::getXmlString
static QString getXmlString(QXmlQuery &_xml, QString _expr, QString _default="")
Gets the string of a xml query.
Definition: context.cc:540
VSI::ElementInput::isSet
bool isSet()
Return "set" flag.
Definition: elementInput.cc:205
VSI::Text::setBackgroundBrush
virtual void setBackgroundBrush(QBrush _brush)
Sets the background brush.
Definition: text.cc:385
VSI::Element::context
Context * context() const
Context of element.
Definition: element.hh:85
VSI::Element::name
QString name() const
Element name.
Definition: element.hh:88
VSI::ElementInput::ElementInput
ElementInput(Input *_in, SceneElement *_parent)
Constructor.
Definition: elementInput.cc:73
VSI::TypeWidget
Definition: typeWidget.hh:65
VSI::ElementInOut::connections
QList< Connection * > connections() const
Connections.
Definition: elementInOut.hh:104
VSI::ElementInOut::connectionPointItem
ConnectionPoint * connectionPointItem() const
Connection point widget.
Definition: elementInOut.hh:95
VSI::SceneElement::graphicsScene
GraphicsScene * graphicsScene()
Scene.
Definition: sceneElement.hh:139
VSI::ElementInOut::element
SceneElement * element()
Scene element.
Definition: elementInOut.hh:119
VSI::ElementInput::setValue
void setValue(QString _value)
Set to a user value.
Definition: elementInput.cc:296
VSI::SceneElement::element
Element * element() const
Context VSI::Element.
Definition: sceneElement.hh:94
VSI::ElementInOut::addConnection
virtual void addConnection(Connection *_conn)
Add the connection.
Definition: elementInOut.cc:162
VSI::GraphicsScene::contentChange
void contentChange()
handle content changes
Definition: graphicsScene.cc:1113
VSI::Type::widget
virtual TypeWidget * widget(QMap< QString, QString >, QString, QWidget *=NULL)
Returns the configuration widget.
Definition: type.hh:93
VSI::ElementInput::removeConnection
void removeConnection(Connection *_conn)
Remove connection.
Definition: elementInput.cc:153
VSI::Connection::output
ElementOutput * output()
Output of this connection.
Definition: connection.cc:254
VSI::SceneElement
Definition: sceneElement.hh:79
VSI::TypeWidget::toValue
virtual QString toValue()=0
Return the type configuration result to a string.
VSI::ElementInOut::typeTextItem
Text * typeTextItem() const
Type text widget.
Definition: elementInOut.hh:98
VSI::ElementInput::state
unsigned int state()
VSI::Input state passthrough.
Definition: elementInput.cc:134
VSI::ElementInput::set
void set(bool _set)
"Set" flag to mark input as set by user
Definition: elementInput.cc:178
VSI::ElementInOut
Definition: elementInOut.hh:75
VSI::Context::getType
Type * getType(QString _type)
Get type object for given type name.
Definition: context.cc:596
VSI::ElementInput::~ElementInput
~ElementInput()
Destructor.
Definition: elementInput.cc:113
VSI::Type
Definition: type.hh:71
VSI::Connection
Definition: connection.hh:72