Minsky
phillipsDiagram.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2023
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 PHILLIPS_DIAGRAM_H
21 #define PHILLIPS_DIAGRAM_H
22 #include "classdesc_access.h"
23 #include "renderNativeWindow.h"
24 #include "variable.h"
25 #include "wire.h"
26 
27 #include <vector>
28 #include <map>
29 
30 namespace minsky
31 {
34 
35  class PhillipsFlow: public Wire
36  {
38  public:
39  PhillipsFlow()=default;
40  PhillipsFlow(const std::weak_ptr<Port>& from, const std::weak_ptr<Port>& to):
41  Wire(from,to) {}
42  static std::map<Units, double> maxFlow;
43  classdesc::Exclude<std::vector<std::pair<double, FlowVar>>> terms;
44 
45  Units units() const {
46  if (terms.empty()) return {};
47  return terms.front().second.units();
48  }
49  void addTerm(double coef, const std::string& name) {terms.emplace_back(coef, name);}
50  double value() const {
51  double r=0;
52  for (auto& i: terms)
53  r+=i.first*i.second.value();
54  return r;
55  }
56  void draw(cairo_t*);
57  };
58 
59 
60  class PhillipsStock: public StockVar
61  {
62  public:
65  group.reset();
66  addPorts();
67  rotation(0);
69  }
70  static std::map<Units, double> maxStock;
71  std::size_t numPorts() const override {return 2;}
72  void draw(cairo_t* cairo) const override;
73  };
74 
76  {
77  bool redraw(int, int, int width, int height) override;
79  PhillipsStock* stockBeingMoved=nullptr; // weak reference
80  PhillipsStock* stockBeingRotated=nullptr; // weak reference
81  Exclude<Point> rotateOrigin;
82  PhillipsFlow* flowBeingEdited=nullptr; // weak reference
84  float x=0,y=0;
85  public:
86  std::map<std::string, PhillipsStock> stocks;
87  std::map<std::pair<std::string,std::string>, PhillipsFlow> flows;
88  void requestRedraw() {if (surface.get()) surface->requestRedraw();}
90  void init() override;
91  void clear() {
92  stocks.clear();
93  flows.clear();
94  }
95 
96  void mouseDown(float x, float y) override;
97  void mouseUp(float x, float y) override;
98  void mouseMove(float x, float y) override;
99  void moveTo(float x, float y) override {this->x=x; this->y=y; requestRedraw();}
100  std::vector<float> position() const override {return {x,y};}
101  void startRotatingItem(float x, float y);
102  bool hasScrollBars() const override {return true;}
103  };
104 }
105 
106 #include "phillipsDiagram.cd"
107 #endif
std::size_t numPorts() const override
PhillipsFlow * flowBeingEdited
virtual float x() const
Definition: item.cc:107
std::shared_ptr< Port > from() const
Definition: wire.h:63
std::shared_ptr< Port > to() const
Definition: wire.h:64
PhillipsFlow(const std::weak_ptr< Port > &from, const std::weak_ptr< Port > &to)
std::vector< float > position() const override
current centre coordinates
void draw(cairo_t *cairo) const override
draw this item into a cairo context
PhillipsStock * stockBeingRotated
static std::map< Units, double > maxFlow
void addTerm(double coef, const std::string &name)
static std::map< Units, double > maxStock
void mouseMove(float x, float y) override
CLASSDESC_ACCESS(PhillipsDiagram)
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
bool redraw(int, int, int width, int height) override
void draw(cairo_t *)
PhillipsStock(const StockVar &x)
void mouseDown(float x, float y) override
CLASSDESC_ACCESS(PhillipsFlow)
represents the units (in sense of dimensional analysis) of a variable.
Definition: units.h:34
std::map< std::pair< std::string, std::string >, PhillipsFlow > flows
std::map< std::string, PhillipsStock > stocks
double value() const
void init() override
populate phillips diagram from Godley tables in model
PhillipsStock * stockBeingMoved
bool hasScrollBars() const override
return whether this window has scrollbars (needed for MacOSX).
void startRotatingItem(float x, float y)
classdesc::Exclude< std::vector< std::pair< double, FlowVar > > > terms
Exclude< Point > rotateOrigin
void updateBoundingBox() override
Definition: item.h:201
void mouseUp(float x, float y) override
Definition: group.tcl:84
void moveTo(float x, float y) override
move this so that (x,y) is centred
double rotation() const
Definition: item.h:211
float y
position for panning