Minsky
intOp.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2021
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 
20 #ifndef INTOP_H
21 #define INTOP_H
22 #include "operation.h"
23 #include "variable.h"
24 
25 namespace minsky
26 {
27  class IntOp;
28  struct IntOpAccessor: public ecolab::TCLAccessor<minsky::IntOp, std::string>
29  {IntOpAccessor();};
30 
31  class IntOp: public ItemT<IntOp, Operation<minsky::OperationType::integrate>>,
32  public IntOpAccessor
33  {
35  // integrals have named integration variables
38  friend struct SchemaHelper;
39  bool m_coupled=true;
40  void insertControlled(Selection& selection) override;
42  public:
43  // offset for coupled integration variable, tr
44  static constexpr float intVarOffset=10;
45 
46  IntOp() {
47  description("");
48  }
49  // ensure that copies create a new integral variable
50  IntOp(const IntOp& x): Super(x) {intVar.reset(); description(x.description());}
51  ~IntOp() {Item::removeControlledItems();}
52 
53  IntOp& operator=(const IntOp& x);
54 
56  std::string description(const std::string& desc);
57  std::string description() const {return intVar? intVar->name(): "";}
59 
60  std::weak_ptr<Port> ports(std::size_t i) const override {
61  // if coupled, the output port is the intVar's output
62  if (i==0 && coupled() && intVar) return intVar->ports(0);
63  return Item::ports(i);
64  }
65 
66  std::string valueId() const
67  {return intVar->valueId();}
68 
69  void draw(cairo_t*) const override;
70  void resize(const LassoBox& b) override;
71 
74 
75  bool onKeyPress(int keySym, const std::string& utf8, int state) override {
76  if (intVar) return intVar->onKeyPress(keySym, utf8, state);
77  return false;
78  }
79 
82  bool toggleCoupled();
83  bool coupled() const {return m_coupled;}
84  Units units(bool) const override;
85 
86  void pack(classdesc::pack_t& x, const std::string& d) const override;
87  void unpack(classdesc::unpack_t& x, const std::string& d) override;
88 
89  using Item::removeControlledItems;
90  };
91 
92 }
93 
94 #include "intOp.cd"
95 #include "intOp.xcd"
96 #endif
represents items that have been selected
Definition: selection.h:32
CLASSDESC_ACCESS(IntOp)
integration variable associated with this op.
IntOp & operator=(const IntOp &x)
Definition: intOp.cc:201
virtual float x() const
Definition: item.cc:107
std::string valueId() const
Definition: intOp.h:66
std::string description() const
name of the associated integral variable
Definition: intOp.h:57
represents rectangular region of a lasso operation
Definition: lasso.h:28
void insertControlled(Selection &selection) override
Definition: intOp.cc:196
void resize(const LassoBox &b) override
resize this item on the canvas
Definition: intOp.cc:184
bool coupled() const
Definition: intOp.h:83
ItemT< IntOp, Operation< minsky::OperationType::integrate > > Super
Definition: intOp.h:34
void pack(classdesc::pack_t &x, const std::string &d) const override
Definition: intOp.cc:317
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
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73
void removeControlledItems(minsky::GroupItems &) override
Definition: intOp.cc:208
void draw(cairo_t *) const override
draw this item into a cairo context
Definition: intOp.cc:40
bool toggleCoupled()
toggles coupled state of integration variable. Only valid for integrate
Definition: intOp.cc:285
IntOp(const IntOp &x)
Definition: intOp.h:50
bool m_coupled
Definition: intOp.h:39
void unpack(classdesc::unpack_t &x, const std::string &d) override
Definition: intOp.cc:320
virtual std::weak_ptr< Port > ports(std::size_t i) const
callback to be run when item deleted from group
Definition: item.h:180
std::weak_ptr< Port > ports(std::size_t i) const override
callback to be run when item deleted from group
Definition: intOp.h:60
static constexpr float intVarOffset
Definition: intOp.h:44
bool onKeyPress(int keySym, const std::string &utf8, int state) override
respond to key press events
Definition: intOp.h:75
Units units(bool) const override
compute the dimensional units
Definition: intOp.cc:32