23 #include "stringKeyMap.h" 29 #include "dimension.h" 49 #include "stringKeyMap.h" 60 #include <xml_pack_base.h> 61 #include <xml_unpack_base.h> 66 using classdesc::shared_ptr;
70 struct CallableFunction;
71 class VariableInstanceList;
82 enum StateFlags {is_edited=1, reset_needed=2, fullEqnDisplay_needed=4};
83 int flags=reset_needed;
86 static constexpr std::chrono::milliseconds resetNowThreshold{500};
89 static constexpr std::chrono::milliseconds resetPostponedThreshold{1500};
90 std::chrono::time_point<std::chrono::system_clock> resetAt=std::chrono::time_point<std::chrono::system_clock>::max();
94 int busyCursorStack=0;
126 ecolab::TCLAccessor<Minsky,bool>::Setter s):
137 std::string diagnoseNonFinite()
const;
140 void logVariables()
const;
144 bool m_multipleEquities=
false;
147 void balanceColumns(
const GodleyIcon& srcGodley,
int srcCol,
GodleyIcon& destGodley,
int destCol)
const;
160 if (canvas.item && i<publicationTabs.size())
161 publicationTabs[i].items.emplace_back(canvas.item);
166 bool multipleEquities(
const bool& m);
169 bool edited()
const {
return flags & is_edited;}
174 flags |= is_edited | fullEqnDisplay_needed;
175 if (!running) flags|=reset_needed;
177 canvas.requestRedraw();
178 canvas.model.updateTimestamp();
182 void requestRedraw();
187 if (!flagStack.empty()) {
188 flags=flagStack.back();
189 flagStack.pop_back();
207 void populateMissingDimensions();
210 void populateMissingDimensionsFromVariable(
const VariableValue&,
bool& incompatibleMessageDisplayed);
212 {
bool dummy; populateMissingDimensionsFromVariable(v,dummy);}
213 void renameDimension(
const std::string& oldName,
const std::string& newName);
233 void importDuplicateColumn(
GodleyTable& srcTable,
int srcCol);
236 void balanceDuplicateColumns(
const GodleyIcon& srcTable,
int srcCol);
238 std::vector<std::string> allGodleyFlowVars()
const;
242 ECOLAB_ACESSOR_INIT(
Minsky, multipleEquities),
243 equationDisplay(*this) {
244 lastRedraw=boost::posix_time::microsec_clock::local_time();
245 model->iHeight(std::numeric_limits<float>::max());
246 model->iWidth(std::numeric_limits<float>::max());
248 publicationTabs.emplace_back(
"Publication");
253 Exclude<std::map<std::string, std::shared_ptr<CallableFunction>>>
userFunctions;
258 void clearAllMaps(
bool clearHistory);
266 static void saveGroupAsFile(
const Group&,
const string& fileName);
268 {
if (
auto g=dynamic_cast<Group*>(canvas.item.get())) saveGroupAsFile(*g,fileName);}
283 void insertGroupFromFile(
const string& file);
285 void makeVariablesConsistent();
287 void imposeDimensions();
290 void garbageCollect();
294 bool cycleCheck()
const;
298 void openLogFile(
const string&);
308 void constructEquations();
310 void dimensionalAnalysis()
const;
312 void deleteAllUnits();
317 bool checkEquationOrder()
const;
323 std::vector<double>
step();
326 void save(
const std::string& filename);
329 void load(
const std::string& filename);
331 void exportSchema(
const std::string& filename,
int schemaLevel=1);
334 void displayErrorItem(
const Item&
op)
const;
340 if (ravel::Ravel::available())
342 int d=ravel::Ravel::daysUntilExpired();
343 return ravel::Ravel::version() +
": "+((d>=0)?(
"Expires in "+
std::to_string(d)+
" day"+(d!=1?
"s":
"")):
"Expired");
345 else return "unavailable";
348 static bool ravelExpired() {
return ravel::Ravel::available() && ravel::Ravel::daysUntilExpired()<0;}
353 unsigned maxHistory{100};
357 std::string
autoSaveFile()
const {
return autoSaver? autoSaver->fileName: std::string();}
360 void setAutoSaveFile(
const std::string& file);
374 bool commandHook(
const std::string& command,
unsigned nargs);
384 bool doPushHistory=
true;
388 long undo(
int changes=1);
399 bool inputWired(
const std::string& name)
const {
return definingVar(name).get();}
415 {canvas.renderToPNGCropped(filename,z);}
421 void renderAllPlotsAsSVG(
const string& prefix)
const;
423 void exportAllPlotsAsCSV(
const string& prefix)
const;
426 void setAllDEmode(
bool);
428 void srand(
int seed) {::srand(seed);}
431 bool displayValues=
false;
438 void importVensim(
const std::string&);
441 void redrawAllGodleyTables();
447 virtual void progress(
const std::string& title,
int) {}
467 std::size_t physicalMem()
const;
472 PangoFontFamily **families;
474 pango_font_map_list_families(pango_cairo_font_map_get_default(),
476 for (
int i=0; i<num; ++i)
477 r.push_back(pango_font_family_get_name(families[i]));
479 std::sort(r.begin(),r.end());
485 std::string defaultFont();
486 std::string defaultFont(
const std::string& x);
491 double fontScale(
double);
497 void latex(
const std::string& filename,
bool wrapLaTeXLines);
499 void matlab(
const std::string& filename) {
500 if (cycleCheck())
throw error(
"cyclic network detected");
501 ofstream
f(filename);
509 std::vector<std::string> availableOperations();
514 std::vector<std::string> variableTypes();
516 std::vector<std::string> assetClasses();
520 void openGroupInCanvas() {canvas.openGroupInCanvas(canvas.item);}
527 void listAllInstances();
535 {
return checkMemAllocation(std::numeric_limits<size_t>::max());}
540 char getc()
const {
return std::getc(stdin);}
543 void setDefinition(
const std::string&
valueId,
const std::string& definition);
562 #pragma omit pack minsky::MinskyExclude 563 #pragma omit unpack minsky::MinskyExclude 564 #pragma omit TCL_obj minsky::MinskyExclude 565 #pragma omit xml_pack minsky::MinskyExclude 566 #pragma omit xml_unpack minsky::MinskyExclude 567 #pragma omit xsd_generate minsky::MinskyExclude 569 #pragma omit xml_pack minsky::Integral 570 #pragma omit xml_unpack minsky::Integral 572 #pragma omit pack minsky::MinskyMatrix 573 #pragma omit unpack minsky::MinskyMatrix 574 #pragma omit xml_pack minsky::MinskyMatrix 575 #pragma omit xml_unpack minsky::MinskyMatrix 576 #pragma omit xsd_generate minsky::MinskyMatrix virtual void message(const std::string &)
display a message in a popup box on the GUI
static SVGRenderer svgRenderer
std::set< RenderNativeWindow * > nativeWindowsToRedraw
record nativeWindows that have requested redrawing
PannableTab< EquationDisplay > equationDisplay
void matlab(const std::string &filename)
std::string latexToPango(const char *s)
string latex2pango(const std::string &x)
void pushFlags()
push and pop state of the flags
void setGodleyIconResource(const string &s)
vector< string > listFonts() const
char getc() const
Used to implement a pause until return pressed for attaching debugger purposes.
virtual void setBusyCursor()
set/clear busy cursor in GUI
static bool ravelExpired()
std::set< string > logVarList
set of variables (valueIds) to log
Clipboard clipboard
clipboard manager
virtual void clearBusyCursor()
MinskyExclude & operator=(const MinskyExclude &)
OperationType::Group classifyOp(OperationType::Type o) const
void closeLogFile()
closes log file
bool inputWired(const std::string &name) const
returns true if any variable of name name has a wired input
VariableValues variableValues
std::string ecolabVersion() const
virtual void runItemDeletedCallback(const Item &)
run callback attached to item
std::vector< int > flagStack
std::map< Units, double > maxValue
stash the maximum absolute value obtained by a dimensioned quantity
void checkPushHistory()
called periodically to ensure history up to date
virtual MemCheckResult checkMemAllocation(size_t bytes) const
MemCheckResult
check whether to proceed or abort, given a request to allocate bytes of memory. Implemented in Minsky...
bool edited() const
reflects whether the model has been changed since last save
std::map< Units, double > maxFlowValue
void renderCanvasToEMF(const std::string &filename)
render canvas to a EMF image file (Windows only)
void setResource(const std::string &resource)
initialise object from an SVG file
void addNewPublicationTab(const std::string &name)
static SVGRenderer svgRenderer
SVG icon to display when not in editor mode.
static int daysUntilRavelExpires()
bool loggingEnabled() const
returns true if logging is in operation
void setLockIconResource(const string &locked, const string &unlocked)
void nameCurrentItem(const std::string &name)
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
void renderCanvasToSVG(const std::string &filename)
render canvas to an SVG file
bool resetIfFlagged() override
checks whether a reset is required, and resets the simulation if so
bool clipboardEmpty() const
return true if nothing available in clipboard
void markEdited()
indicate model has been changed since last saved
void renderCanvasToPS(const std::string &filename)
render canvas to a postscript file
static bool ravelAvailable()
virtual CmdData getCommandData(const std::string &command) const
return meta information on a given command
bool reset_flag() const
true if reset needs to be called prior to numerical integration
VariablePane variablePane
classdesc::StringKeyMap< std::vector< OperationType::Type > > AvailableOperationsMapping
static SVGRenderer svgRenderer
SVG icon to display when not in editor mode.
void populateMissingDimensionsFromVariable(const VariableValue &v)
std::string autoSaveFile() const
name of an auto save file
bool triggerCheckMemAllocationCallback() const
trigger checkMem callback for testing purposes
std::deque< classdesc::pack_t > history
save history of model for undo
void renderCanvasToPNG(const std::string &filename)
render canvas to a PNG image file
Exclude< ptime > lastRedraw
static SVGRenderer lockedIcon
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky's state cha...
An RAII wrapper around jtanx's libclipboard (https://github.com/jtanx/libclipboard) ...
void setRavelIconResource(const string &s)
std::vector< PubTab > publicationTabs
Mixin implementing common panning functionality in tabs.
virtual void bookmarkRefresh()
refresh the bookmark menu after changes
shared_ptr< ofstream > outputDataFile
#define CLASSDESC_ACCESS(type)
std::shared_ptr< VariableInstanceList > variableInstanceList
supports navigation to all instances of current variable
void addCanvasItemToPublicationTab(size_t i)
const Minsky & cminsky()
const version to help in const correctness
ostream & matlab(ostream &) const
render as MatLab code create equations suitable for Runge-Kutta solver
bool multipleEquities() const
SVGRenderer histogramResource
std::string ravelVersion() const
void setGroupIconResource(const string &s)
static const std::string minskyVersion
return the AEGIS assigned version number
void saveCanvasItemAsFile(const string &fileName) const
Exclude< std::map< std::string, std::shared_ptr< CallableFunction > > > userFunctions
virtual void resetScroll()
reset main window scroll bars after model has been panned
static SVGRenderer unlockedIcon
virtual void progress(const std::string &title, int)
set progress bar, out of 100, labelling the progress bar with title
std::map< std::string, std::weak_ptr< Item > > namedItems
void openModelInCanvas()
reinitialises canvas to the toplevel group
MinskyExclude(const MinskyExclude &)
std::shared_ptr< Group > GroupPtr
void itemFromNamedItem(const std::string &name)
PhillipsDiagram phillipsDiagram
RAII set the minsky object to a different one for the current scope.
string latex(double)
convert double to a LaTeX string representing that value
string to_string(CONST84 char *x)
void renderCanvasToPDF(const std::string &filename)
render canvas to a PDF file
Minsky & minsky()
global minsky object
void popFlags()
push and pop state of the flags
void srand(int seed)
set std library RNG seed
Minsky_multipleEquities(const std::string &name, ecolab::TCLAccessor< Minsky, bool >::Getter g, ecolab::TCLAccessor< Minsky, bool >::Setter s)
void saveSelectionAsFile(const string &fileName) const
std::chrono::milliseconds resetDuration
void renderCanvasToPNG(const std::string &filename, const Canvas::ZoomCrop &z)
Render canvas to a PNG file filename, scaling the canvas temporarily by zoom, shifts it to left...
static Group classify(Type t)
std::string fileVersion
Minsky version file was saved under.
unique_ptr< BackgroundSaver > autoSaver
void clearHistory()
clear history