Developer Documentation
elementInOut.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//== INCLUDES =================================================================
45#include <QFont>
46
47#include "sceneElement.hh"
48#include "elementInOut.hh"
49#include "text.hh"
50#include "connection.hh"
51#include "connectionPoint.hh"
52#include "../parser/inout.hh"
53#include "../parser/element.hh"
54#include "../parser/context.hh"
55
56#include <iostream>
57
58//== NAMESPACES ===============================================================
59namespace VSI {
60
61//=============================================================================
62//
63// CLASS VSI::ElementInOut - IMPLEMENTATION
64//
65//=============================================================================
66
69 io_ (_io),
70 element_ (_parent)
71{
72 conn_ = new ConnectionPoint (this, _parent);
73 typeText_ = new Text (_io->typeString (), _parent);
74 QFont font = typeText_->font ();
75 font.setItalic (true);
76 font.setPointSize (8);
77 typeText_->setFont (font);
78 descText_ = new Text (_io->shortDescription (), _parent);
79 font = descText_->font ();
80 if (_io->name() == "data")
81 font.setPointSize (10);
82 else
83 font.setPointSize (8);
84 descText_->setFont (font);
85
86 conn_->setToolTip (_io->typeString () + " : " + _io->longDescription ());
87 typeText_->setToolTip (_io->typeString () + " : " + _io->longDescription ());
88 descText_->setToolTip (_io->typeString () + " : " + _io->longDescription ());
89
90 typeText_->setHorizontalStretch (true);
91 descText_->setHorizontalStretch (true);
92}
93
94
96 io_(NULL),
97 element_(NULL),
98 conn_(NULL),
99 typeText_(NULL),
100 descText_(NULL)
101{
102 std::cerr << "Illegal use of copy constructor in class ElementInOut, which is not implemented yet!" << std::endl;
103};
104
105//------------------------------------------------------------------------------
106
109{
110 foreach (Connection *c, connections_)
111 delete c;
112
113 delete conn_;
114 delete typeText_;
115 delete descText_;
116}
117
118//------------------------------------------------------------------------------
119
122{
123 // Can't be connected to itself
124 if (_e == this)
125 return false;
126 // Can't be connected to another input/output of the same element
127 if (element_ == _e->element_)
128 return false;
129
130 // Can't be connected if types are different and can't be converted
131 if (io_->typeString () != _e->io_->typeString () &&
132 !io_->element ()->context ()->canConvert (io_->typeString (), _e->io_->typeString ()))
133 return false;
134
135 // An input can only have one connection
136 if (type () == TypeInput && !connections ().isEmpty ())
137 return false;
138 if (_e->type () == TypeInput && !_e->connections().isEmpty ())
139 return false;
140
141 // Circular dependency check
142 if ((type () == TypeInput && _e->element ()->isAfter (element ())) ||
143 (type () == TypeOutput && _e->element ()->isBefore (element ())))
144 return false;
145
146 // inputs can only be connected to outputs and vice versa
147 if (type () == _e->type ())
148 return false;
149
150 return true;
151}
152
153//------------------------------------------------------------------------------
154
157{
158 connections_.append (_conn);
159}
160
161//------------------------------------------------------------------------------
162
165{
166 connections_.removeAll (_conn);
167}
168
169//------------------------------------------------------------------------------
170}
bool canConvert(const QString &_type1, const QString &_type2)
Can the given types be converted to each other.
Definition: context.cc:560
virtual ~ElementInOut()
Destructor.
ElementInOut(InOut *_io, SceneElement *_parent)
Constructor.
Definition: elementInOut.cc:68
QList< Connection * > connections() const
Connections.
Definition: elementInOut.hh:98
virtual Type type() const =0
Type.
SceneElement * element()
Scene element.
virtual void removeConnection(Connection *_conn)
Remove the Connection.
bool validConnection(ElementInOut *_e)
Can this input/output be connected to _e.
virtual void addConnection(Connection *_conn)
Add the connection.
Context * context() const
Context of element.
Definition: element.hh:79
QString typeString() const
Type.
Definition: inout.cc:65
const QString & longDescription() const
Long description.
Definition: inout.hh:76
const Element * element() const
Element of this input/output.
Definition: inout.hh:79
const QString & shortDescription() const
Short description.
Definition: inout.hh:73
const QString & name() const
Name.
Definition: inout.hh:70
bool isBefore(SceneElement *_e)
Will this element be executed before _e bacause of its connections?
bool isAfter(SceneElement *_e)
Will this element be executed after _e bacause of its connections?
void setHorizontalStretch(bool _stretch)
Should this widget be stretchable in horizontal direction.
Definition: text.cc:324