Minsky: 3.17.0
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 
29  class IntOp: public ItemT<IntOp, Operation<minsky::OperationType::integrate>>
30  {
32  // integrals have named integration variables
35  friend struct SchemaHelper;
36  bool m_coupled=true;
37  void insertControlled(Selection& selection) override;
39  public:
40  // offset for coupled integration variable, tr
41  static constexpr float intVarOffset=10;
42 
43  IntOp() {
44  description("");
45  }
46  // ensure that copies create a new integral variable
47  IntOp(const IntOp& x): Super(x) {intVar.reset(); description(x.description());}
48  ~IntOp() {Item::removeControlledItems();}
49 
50  IntOp& operator=(const IntOp& x);
51 
53  std::string description(const std::string& desc);
54  std::string description() const {return intVar? intVar->name(): "";}
56 
57  std::weak_ptr<Port> ports(std::size_t i) const override {
58  // if coupled, the output port is the intVar's output
59  if (i==0 && coupled() && intVar) return intVar->ports(0);
60  return Item::ports(i);
61  }
62 
63  std::string valueId() const
64  {return intVar->valueId();}
65 
66  void draw(cairo_t*) const override;
67  void resize(const LassoBox& b) override;
68 
71 
72  bool onKeyPress(int keySym, const std::string& utf8, int state) override {
73  if (intVar) return intVar->onKeyPress(keySym, utf8, state);
74  return false;
75  }
76 
79  bool toggleCoupled();
80  bool coupled() const {return m_coupled;}
81  Units units(bool) const override;
82 
83  void pack(classdesc::pack_t& x, const std::string& d) const override;
84  void unpack(classdesc::unpack_t& x, const std::string& d) override;
85 
86  using Item::removeControlledItems;
87  };
88 
89 }
90 
91 #include "intOp.cd"
92 #include "intOp.xcd"
93 #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:198
virtual float x() const
Definition: item.cc:107
std::string valueId() const
Definition: intOp.h:63
std::string description() const
name of the associated integral variable
Definition: intOp.h:54
represents rectangular region of a lasso operation
Definition: lasso.h:28
void insertControlled(Selection &selection) override
Definition: intOp.cc:193
void resize(const LassoBox &b) override
resize this item on the canvas
Definition: intOp.cc:181
bool coupled() const
Definition: intOp.h:80
ItemT< IntOp, Operation< minsky::OperationType::integrate > > Super
Definition: intOp.h:31
void pack(classdesc::pack_t &x, const std::string &d) const override
Definition: intOp.cc:314
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:70
void removeControlledItems(minsky::GroupItems &) override
Definition: intOp.cc:205
void draw(cairo_t *) const override
draw this item into a cairo context
Definition: intOp.cc:37
bool toggleCoupled()
toggles coupled state of integration variable. Only valid for integrate
Definition: intOp.cc:282
IntOp(const IntOp &x)
Definition: intOp.h:47
bool m_coupled
Definition: intOp.h:36
void unpack(classdesc::unpack_t &x, const std::string &d) override
Definition: intOp.cc:317
virtual std::weak_ptr< Port > ports(std::size_t i) const
callback to be run when item deleted from group
Definition: item.h:177
std::weak_ptr< Port > ports(std::size_t i) const override
callback to be run when item deleted from group
Definition: intOp.h:57
static constexpr float intVarOffset
Definition: intOp.h:41
bool onKeyPress(int keySym, const std::string &utf8, int state) override
respond to key press events
Definition: intOp.h:72
Units units(bool) const override
compute the dimensional units
Definition: intOp.cc:29