Minsky
switchIcon.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2015
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef SWITCHICON_H
20 #define SWITCHICON_H
21 
22 #include "item.h"
23 #include <cairo.h>
24 
25 namespace minsky
26 {
27  class SwitchIcon: public ItemT<SwitchIcon, BottomRightResizerItem>
28  {
31  friend struct SchemaHelper;
32  public:
34  SwitchIcon(const SwitchIcon& x): Super(x), flipped(x.flipped) {setNumCases(x.numCases());}
38  flipped=x.flipped;
39  setNumCases(x.numCases());
40  return *this;
41  }
44  flipped=x.flipped;
45  setNumCases(x.numCases());
46  return *this;
47  }
48 
53  unsigned numCases() const {return m_ports.size()-2;}
54  void setNumCases(unsigned);
56 
58  unsigned switchValue() const;
59  double value() const override {return m_ports[switchValue()+2]->value();}
60 
61  const SwitchIcon* switchIconCast() const override {return this;}
62  SwitchIcon* switchIconCast() override {return this;}
63 
64  Units units(bool) const override;
65 
67  void draw(cairo_t* context) const override;
68 
70  bool flipped=false;
71  void flip() override {flipped=!flipped;}
72  };
73 }
74 
75 #include "switchIcon.cd"
76 #include "switchIcon.xcd"
77 #endif
void setNumCases(unsigned)
Definition: switchIcon.cc:31
virtual float x() const
Definition: item.cc:107
unsigned switchValue() const
value of switch according to current inputs
Definition: switchIcon.cc:45
SwitchIcon(SwitchIcon &&x)
Definition: switchIcon.h:35
void flip() override
rotate icon though 180∘
Definition: switchIcon.h:71
Units units(bool) const override
compute the dimensional units
Definition: switchIcon.cc:55
void draw(cairo_t *context) const override
draw icon to context
Definition: switchIcon.cc:75
SwitchIcon * switchIconCast() override
Definition: switchIcon.h:62
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
represents the units (in sense of dimensional analysis) of a variable.
Definition: units.h:34
SwitchIcon & operator=(const SwitchIcon &x)
Definition: switchIcon.h:36
const SwitchIcon * switchIconCast() const override
Definition: switchIcon.h:61
SwitchIcon()
default to if/then
Definition: switchIcon.h:33
ItemPortVector m_ports
Definition: item.h:156
double value() const override
current value of output port
Definition: switchIcon.h:59
CLASSDESC_ACCESS(SwitchIcon)
unsigned numCases() const
Definition: switchIcon.h:53
SwitchIcon(const SwitchIcon &x)
Definition: switchIcon.h:34
bool flipped
whether icon is oriented so input ports are on the rhs, and output on the lhs
Definition: switchIcon.h:70
SwitchIcon & operator=(SwitchIcon &&x)
Definition: switchIcon.h:42