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