Minsky: 3.17.0
minsky::anonymous_namespace{addon.cc}::AddOnMinsky Struct Reference
Inheritance diagram for minsky::anonymous_namespace{addon.cc}::AddOnMinsky:
Inheritance graph
Collaboration diagram for minsky::anonymous_namespace{addon.cc}::AddOnMinsky:
Collaboration graph

Public Member Functions

 AddOnMinsky ()
 
 ~AddOnMinsky ()
 
Value queueCommand (Env env, string command, const json_pack_t &arguments)
 
string doCommand (const string &command, const json_pack_t &arguments)
 
void drawNativeWindows ()
 
void macOSXDrawNativeWindows ()
 
void macOSXLaunchDrawNativeWindows ()
 
void run ()
 
Value setMessageCallback (const Napi::CallbackInfo &info)
 
void message (const std::string &msg) override
 display a message in a popup box on the GUI More...
 
MemCheckResult checkMemAllocation (std::size_t bytes) const override
 
Value setBusyCursorCallback (const Napi::CallbackInfo &info)
 
void doBusyCursor (bool bc)
 
void setBusyCursor () override
 set/clear busy cursor in GUI More...
 
void clearBusyCursor () override
 
void progress (const string &title, int x) override
 set progress bar, out of 100, labelling the progress bar with title More...
 
Value setProgressCallback (const Napi::CallbackInfo &info)
 
void bookmarkRefresh () override
 refresh the bookmark menu after changes More...
 
Value setBookmarkRefreshCallback (const Napi::CallbackInfo &info)
 
void resetScroll () override
 reset main window scroll bars after model has been panned More...
 
Value setResetScrollCallback (const Napi::CallbackInfo &info)
 
void outOfMemoryHandler ()
 
- Public Member Functions inherited from minsky::RESTMinsky
CmdData getCommandData (const std::string &) const override
 return meta information on a given command More...
 
template<class RP >
void commandHook (const std::string &command, const RP &args)
 
 RESTMinsky ()
 
- Public Member Functions inherited from minsky::Minsky
void addNewPublicationTab (const std::string &name)
 
void addCanvasItemToPublicationTab (size_t i)
 
bool multipleEquities () const
 
bool multipleEquities (const bool &m)
 
bool edited () const
 reflects whether the model has been changed since last save More...
 
bool reset_flag () const
 true if reset needs to be called prior to numerical integration More...
 
void markEdited ()
 indicate model has been changed since last saved More...
 
void requestReset ()
 
void requestRedraw ()
 requests a redraw of the curren active tab More...
 
bool resetIfFlagged () override
 checks whether a reset is required, and resets the simulation if so More...
 
void populateMissingDimensions ()
 fills in dimensions table with all loaded ravel axes More...
 
void populateMissingDimensionsFromVariable (const VariableValue &, bool &incompatibleMessageDisplayed)
 populate missing dimensions from a variableValue More...
 
void populateMissingDimensionsFromVariable (const VariableValue &v)
 
void renameDimension (const std::string &oldName, const std::string &newName)
 
void setGodleyIconResource (const string &s)
 
void setGroupIconResource (const string &s)
 
void setLockIconResource (const string &locked, const string &unlocked)
 
void setRavelIconResource (const string &s)
 
std::set< string > matchingTableColumns (const GodleyIcon &currTable, GodleyAssetClass::AssetClass ac)
 
void importDuplicateColumn (GodleyTable &srcTable, int srcCol)
 find any duplicate column, and use it as a source column for balanceDuplicateColumns More...
 
void balanceDuplicateColumns (const GodleyIcon &srcTable, int srcCol)
 makes all duplicated columns consistent with srcTable, srcCol More...
 
std::vector< std::string > allGodleyFlowVars () const
 
 Minsky ()
 
 ~Minsky ()
 
void clearAllMaps (bool clearHistory)
 
void clearAllMaps ()
 
void clearAllMapsTCL ()
 
VariablePtr definingVar (const std::string &valueId) const
 returns reference to variable defining (ie input wired) for valueId More...
 
void saveCanvasItemAsFile (const string &fileName) const
 
void initGodleys ()
 
void cut ()
 erase items in current selection, put copy into clipboard More...
 
void copy () const
 copy items in current selection into clipboard More...
 
void paste ()
 paste clipboard as a new group or ungrouped items on the canvas. canvas.itemFocus is set to refer to the new group or items. More...
 
bool clipboardEmpty () const
 return true if nothing available in clipboard More...
 
void saveSelectionAsFile (const string &fileName) const
 
void insertGroupFromFile (const string &file)
 
void makeVariablesConsistent ()
 
void imposeDimensions ()
 
void garbageCollect ()
 
bool cycleCheck () const
 checks for presence of illegal cycles in network. Returns true if there are some More...
 
void openLogFile (const string &)
 opens the log file, and writes out a header line describing names of all variables More...
 
void closeLogFile ()
 closes log file More...
 
bool loggingEnabled () const
 returns true if logging is in operation More...
 
void constructEquations ()
 construct the equations based on input data More...
 
void dimensionalAnalysis () const
 performs dimension analysis, throws if there is a problem More...
 
void deleteAllUnits ()
 removes units markup from all variables in model More...
 
bool checkEquationOrder () const
 consistency check of the equation order. Should return true. Outputs the operation number of the invalidly ordered operation. More...
 
double deltaT () const
 
void reset ()
 resets the variables back to their initial values More...
 
std::vector< double > step ()
 step the equations (by n steps, default 1) More...
 
void save (const std::string &filename)
 
void load (const std::string &filename)
 load from a file More...
 
void displayErrorItem (const Item &op) const
 indicate operation item has error, if visible, otherwise contining group More...
 
std::string autoSaveFile () const
 name of an auto save file More...
 
void setAutoSaveFile (const std::string &file)
 initialises auto saving empty file to turn off autosave More...
 
void clearHistory ()
 clear history More...
 
void checkPushHistory ()
 called periodically to ensure history up to date More...
 
bool pushHistory ()
 push current model state onto history if it differs from previous More...
 
bool commandHook (const std::string &command, unsigned nargs)
 Executed after each interpreter command to maintain undo/redo stack, edited flag, autosaving etc. More...
 
long undo (int changes=1)
 restore model to state changes ago More...
 
void convertVarType (const std::string &name, VariableType::Type type)
 Converts variable(s) named by name into a variable of type type. More...
 
void addIntegral ()
 add integral to current canvas item (which must be variable convertible to an integral variable More...
 
bool inputWired (const std::string &name) const
 returns true if any variable of name name has a wired input More...
 
void renderCanvasToPS (const std::string &filename)
 render canvas to a postscript file More...
 
void renderCanvasToPDF (const std::string &filename)
 render canvas to a PDF file More...
 
void renderCanvasToSVG (const std::string &filename)
 render canvas to an SVG file More...
 
void renderCanvasToPNG (const std::string &filename)
 render canvas to a PNG image file More...
 
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, top, and crops to width, height (in ZoomCrop struct). More...
 
void renderCanvasToEMF (const std::string &filename)
 render canvas to a EMF image file (Windows only) More...
 
void renderAllPlotsAsSVG (const string &prefix) const
 render all plots More...
 
void exportAllPlotsAsCSV (const string &prefix) const
 export all plots More...
 
void setAllDEmode (bool)
 set DE mode on all godley tables More...
 
void srand (int seed)
 set std library RNG seed More...
 
void setGodleyDisplayValue (bool displayValues, GodleyTable::DisplayStyle displayStyle)
 set display value mode on all godley table editor modes More...
 
void importVensim (const std::string &)
 import a Vensim file More...
 
void redrawAllGodleyTables ()
 request all Godley table windows to redraw More...
 
virtual void runItemDeletedCallback (const Item &)
 run callback attached to item More...
 
virtual MemCheckResult checkMemAllocation (size_t bytes) const
 
vector< string > listFonts () const
 
void latex (const std::string &filename, bool wrapLaTeXLines)
 
void matlab (const std::string &filename)
 
string latex2pango (const std::string &x)
 
void autoLayout ()
 auto layout current open group and recentre More...
 
void randomLayout ()
 randomly layout current open group and recentre reinitialises canvas to the group located in item More...
 
void openGroupInCanvas ()
 
void openModelInCanvas ()
 reinitialises canvas to the toplevel group More...
 
void listAllInstances ()
 
void nameCurrentItem (const std::string &name)
 
void itemFromNamedItem (const std::string &name)
 
bool triggerCheckMemAllocationCallback () const
 trigger checkMem callback for testing purposes More...
 
char getc () const
 Used to implement a pause until return pressed for attaching debugger purposes. More...
 
void setDefinition (const std::string &valueId, const std::string &definition)
 add/replace a definition for a flow variable given by valueId More...
 
void reloadAllCSVParameters ()
 reload all CSV parameters from latest values in files. More...
 
void pushFlags ()
 push and pop state of the flags More...
 
void popFlags ()
 push and pop state of the flags More...
 
- Public Member Functions inherited from minsky::RungeKutta
virtual ~RungeKutta ()=default
 
void rkreset ()
 reset the simulation More...
 
void rkstep ()
 step the equations (by n steps, default 1) evaluate the flow equations without stepping. More...
 
void evalEquations ()
 

Static Public Member Functions

static void tsDrawNativeWindows (Napi::Env env, Napi::Function, AddOnMinsky *minsky, void *)
 
static void messageCallback (Napi::Env env, Napi::Function fn, void *, AddOnMinsky *addonMinsky)
 
static void busyCursorCallback (Napi::Env env, Napi::Function fn, void *, bool *busy)
 
static void progressCallback (Napi::Env env, Napi::Function fn, void *, AddOnMinsky *addon)
 
static void bookmarkRefreshCallback (Napi::Env env, Napi::Function fn, void *, AddOnMinsky *addon)
 
static void resetScrollCallback (Napi::Env env, Napi::Function fn, void *, AddOnMinsky *addon)
 
- Static Public Member Functions inherited from minsky::Minsky
static void saveGroupAsFile (const Group &, const string &fileName)
 
static void exportSchema (const std::string &filename, int schemaLevel=1)
 
static std::string ecolabVersion ()
 
static std::string ravelVersion ()
 
static bool ravelAvailable ()
 
static bool ravelExpired ()
 
static int daysUntilRavelExpires ()
 
static std::size_t physicalMem ()
 returns amount of memory installed on system More...
 
static int numOpArgs (OperationType::Type o)
 
static OperationType::Group classifyOp (OperationType::Type o)
 
static std::vector< std::string > availableOperations ()
 list of available operations More...
 
static Minsky::AvailableOperationsMapping availableOperationsMapping ()
 
static std::vector< std::string > variableTypes ()
 list of available variable types More...
 
static std::vector< std::string > assetClasses ()
 return list of available asset classes More...
 
static std::string defaultFont ()
 the default used by Pango More...
 
static std::string defaultFont (const std::string &x)
 the default used by Pango More...
 
static double fontScale ()
 an extra scaling factor of Pango fonts More...
 
static double fontScale (double)
 an extra scaling factor of Pango fonts More...
 

Public Attributes

Timers timers
 
deque< unique_ptr< Command > > minskyCommands
 
mutex cmdMutex
 
atomic< bool > running {true}
 
std::thread thread
 
bool inputBufferExceeded =false
 
atomic< bool > drawLaunched {false}
 
TypedThreadSafeFunction< AddOnMinsky, void, tsDrawNativeWindowstsDrawNativeWindows_
 
string theMessage
 
vector< string > messageButtons
 
promise< unsigned > userResponse
 
bool messageCallbackSet =false
 
TypedThreadSafeFunction< void, AddOnMinsky, messageCallbacktsMessageCallback
 
bool busyCursorCallbackSet =false
 
TypedThreadSafeFunction< void, bool, busyCursorCallbacktsBusyCursorCallback
 
bool busyCursor =false
 
int progressValue =0
 
string progressTitle
 
bool progressCallbackSet =false
 
TypedThreadSafeFunction< void, AddOnMinsky, progressCallbacktsProgressCallback
 
bool bookmarkRefreshSet =false
 
TypedThreadSafeFunction< void, AddOnMinsky, bookmarkRefreshCallbacktsBookmarkRefreshCallback
 
bool resetScrollSet =false
 
TypedThreadSafeFunction< void, AddOnMinsky, resetScrollCallbacktsResetScrollCallback
 
- Public Attributes inherited from minsky::RESTMinsky
RESTProcess_t registry
 
- Public Attributes inherited from minsky::Minsky
PannableTab< EquationDisplayequationDisplay
 
FontDisplay fontSampler
 
PhillipsDiagram phillipsDiagram
 
std::vector< PubTabpublicationTabs
 
VariableValues variableValues
 
Dimensions dimensions
 
Conversions conversions
 
std::map< Units, double > maxValue
 stash the maximum absolute value obtained by a dimensioned quantity More...
 
std::map< Units, double > maxFlowValue
 
SVGRenderer histogramResource
 
Exclude< std::map< std::string, std::shared_ptr< CallableFunction > > > userFunctions
 
GroupPtr model {new Group}
 
Canvas canvas {model}
 
std::set< string > logVarList
 set of variables (valueIds) to log More...
 
double lastT {0}
 previous timestep More...
 
int numBackups =1
 number of previous versions of saved files to keep save to a file More...
 
std::string fileVersion
 Minsky version file was saved under. More...
 
unsigned maxHistory {100}
 maximum no. of history states to save More...
 
int maxWaitMS =100
 maximum wait in millisecond between redrawing canvas during simulation More...
 
bool doPushHistory =true
 flag to indicate whether a TCL should be pushed onto the history stack, or logged in a recording. This is used to avoid movements being added to recordings and undo history More...
 
bool displayValues =false
 
GodleyTable::DisplayStyle displayStyle =GodleyTable::sign
 
std::shared_ptr< VariableInstanceListvariableInstanceList
 supports navigation to all instances of current variable More...
 
std::map< std::string, std::weak_ptr< Item > > namedItems
 
VariablePane variablePane
 
- Public Attributes inherited from minsky::RungeKutta
double t {0}
 time More...
 
bool running =false
 controls whether simulation is running More...
 
bool reverse =false
 reverse direction of simulation More...
 
EvalGodley evalGodley
 
- Public Attributes inherited from minsky::Simulation
double stepMin {0}
 
double stepMax {0.01}
 
int nSteps {1}
 
double epsRel {1e-2}
 
double epsAbs {1e-3}
 
int order {4}
 
bool implicit {false}
 
int simulationDelay {0}
 
std::string timeUnit
 
double tmax {INFINITY}
 
double t0 {0}
 

Additional Inherited Members

- Public Types inherited from minsky::Minsky
enum  CmdData { no_command, is_const, is_setterGetter, generic }
 
enum  MemCheckResult { OK, proceed, abort }
 check whether to proceed or abort, given a request to allocate bytes of memory. Implemented in MinskyTCL More...
 
using AvailableOperationsMapping = classdesc::StringKeyMap< std::vector< OperationType::Type > >
 
- Static Public Attributes inherited from minsky::Minsky
static const std::string minskyVersion =MINSKY_VERSION
 
- Static Public Attributes inherited from minsky::ValueVector
static std::vector< double, CIVITA_ALLOCATOR< double > > stockVars
 vector of variables that are integrated via Runge-Kutta. These variables label the columns of the Godley table More...
 
static std::vector< double, CIVITA_ALLOCATOR< double > > flowVars
 variables defined as a simple function of the stock variables, also known as lhs variables. These variables appear in the body of the Godley table More...
 
- Protected Member Functions inherited from minsky::RungeKutta
void evalEquations (double result[], double, const double vars[])
 
void evalJacobian (Matrix &, double, const double vars[])
 
- Static Protected Member Functions inherited from minsky::RungeKutta
static int RKfunction (double, const double y[], double f[], void *)
 function to be integrated (internal use) More...
 
static int jacobian (double, const double y[], double *, double dfdt[], void *)
 compute jacobian (internal use) More...
 

Detailed Description

Definition at line 191 of file addon.cc.

Constructor & Destructor Documentation

◆ AddOnMinsky()

minsky::anonymous_namespace{addon.cc}::AddOnMinsky::AddOnMinsky ( )
inline

Definition at line 200 of file addon.cc.

200  : thread([this](){run();}) {
201  flags=0;
202  }

◆ ~AddOnMinsky()

minsky::anonymous_namespace{addon.cc}::AddOnMinsky::~AddOnMinsky ( )
inline

Definition at line 204 of file addon.cc.

204  {
205  running=false;
206  if (thread.joinable()) thread.join();
207  }

Member Function Documentation

◆ bookmarkRefresh()

void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::bookmarkRefresh ( )
inlineoverridevirtual

refresh the bookmark menu after changes

Reimplemented from minsky::Minsky.

Definition at line 480 of file addon.cc.

481  {
482  if (!bookmarkRefreshSet) return;
483  tsBookmarkRefreshCallback.BlockingCall(this);
484  }
TypedThreadSafeFunction< void, AddOnMinsky, bookmarkRefreshCallback > tsBookmarkRefreshCallback
Definition: addon.cc:486

◆ bookmarkRefreshCallback()

static void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::bookmarkRefreshCallback ( Napi::Env  env,
Napi::Function  fn,
void *  ,
AddOnMinsky addon 
)
inlinestatic

Definition at line 475 of file addon.cc.

476  {
477  fn({});
478  }

◆ busyCursorCallback()

static void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::busyCursorCallback ( Napi::Env  env,
Napi::Function  fn,
void *  ,
bool *  busy 
)
inlinestatic

Definition at line 414 of file addon.cc.

415  {
416  fn({Boolean::New(env,*busy)});
417  }

◆ checkMemAllocation()

MemCheckResult minsky::anonymous_namespace{addon.cc}::AddOnMinsky::checkMemAllocation ( std::size_t  bytes) const
inlineoverride

Definition at line 400 of file addon.cc.

400  {
401  // Electron restricts heap size to 4GiB, regardless of how much physical memory is present
402  if (messageCallbackSet && bytes>/*physicalMem()*/4ULL*1024*1024*1024)
403  {
404  theMessage="Allocation will use more than 50% of available memory. Do you want to proceed?";
405  messageButtons={"No","Yes"};
406  userResponse={}; //reset the promise
407  tsMessageCallback.BlockingCall(const_cast<AddOnMinsky*>(this));
408  return userResponse.get_future().get()? proceed: abort;
409  }
410  return OK;
411  }
TypedThreadSafeFunction< void, AddOnMinsky, messageCallback > tsMessageCallback
Definition: addon.cc:375

◆ clearBusyCursor()

void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::clearBusyCursor ( )
inlineoverridevirtual

Reimplemented from minsky::Minsky.

Definition at line 443 of file addon.cc.

◆ doBusyCursor()

void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::doBusyCursor ( bool  bc)
inline

Definition at line 435 of file addon.cc.

436  {
437  if (!busyCursorCallbackSet) return;
438  busyCursor=bc;
439  tsBusyCursorCallback.BlockingCall(&busyCursor);
440  }
TypedThreadSafeFunction< void, bool, busyCursorCallback > tsBusyCursorCallback
Definition: addon.cc:420

◆ doCommand()

string minsky::anonymous_namespace{addon.cc}::AddOnMinsky::doCommand ( const string &  command,
const json_pack_t &  arguments 
)
inline

Definition at line 236 of file addon.cc.

References minsky::anonymous_namespace{addon.cc}::minskyCmdMutex.

237  {
238  const lock_guard<mutex> lock(minskyCmdMutex);
239  const Timer timer(timers[command]);
240 
241  // if reset requested, postpone it
242  if (reset_flag()) requestReset();
243 
244  civita::ITensor::cancel(false);
245  // disable quoting wide characters in UTF-8 strings
246  auto result=write(registry.process(command, arguments)->asBuffer(),json5_parser::raw_utf8);
247  commandHook(command,arguments);
248  return result;
249  }
void commandHook(const std::string &command, const RP &args)
Definition: RESTMinsky.h:32
void requestReset()
Definition: minsky.cc:466
RESTProcess_t registry
Definition: RESTMinsky.h:29
bool reset_flag() const
true if reset needs to be called prior to numerical integration
Definition: minsky.h:159

◆ drawNativeWindows()

void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::drawNativeWindows ( )
inline

Definition at line 251 of file addon.cc.

References minsky::anonymous_namespace{addon.cc}::minskyCmdMutex.

252  {
253  const lock_guard<mutex> lock(minskyCmdMutex);
254  const Timer timer(timers["draw"]);
255  for (auto i: nativeWindowsToRedraw)
256  try
257  {
258  i->draw();
259  }
260  catch (const std::exception& ex)
261  {
262  /* absorb and log any exceptions, cannot do anything anyway */
263  cerr << ex.what() << endl;
264  break;
265  }
266  catch (...) {break;}
267  nativeWindowsToRedraw.clear();
268  }

◆ macOSXDrawNativeWindows()

void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::macOSXDrawNativeWindows ( )
inline

Definition at line 277 of file addon.cc.

References minsky::macOSXRedraw(), and minsky::anonymous_namespace{addon.cc}::minskyCmdMutex.

278  {
279  // share the lock with all window redraw routines - when all windows redrawn, lock is released
280  auto lock=make_shared<lock_guard<mutex>>(minskyCmdMutex);
281  const Timer timer(timers["draw"]);
282  for (auto i: nativeWindowsToRedraw)
283  macOSXRedraw(*i,lock);
284  nativeWindowsToRedraw.clear();
285  drawLaunched=false;
286  }
void macOSXRedraw(RenderNativeWindow &window, const std::shared_ptr< std::lock_guard< std::mutex >> &lock)
Here is the call graph for this function:

◆ macOSXLaunchDrawNativeWindows()

void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::macOSXLaunchDrawNativeWindows ( )
inline

Definition at line 288 of file addon.cc.

289  {
290  drawLaunched=true;
291  tsDrawNativeWindows_.BlockingCall(this);
292  }
TypedThreadSafeFunction< AddOnMinsky, void, tsDrawNativeWindows > tsDrawNativeWindows_
Definition: addon.cc:275

◆ message()

void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::message ( const std::string &  )
inlineoverridevirtual

display a message in a popup box on the GUI

Reimplemented from minsky::Minsky.

Definition at line 391 of file addon.cc.

392  {
393  if (!messageCallbackSet) return;
394  theMessage=msg;
395  messageButtons.clear(); // empty buttons imply a single OK button
396  userResponse={}; //reset the promise
397  tsMessageCallback.BlockingCall(const_cast<AddOnMinsky*>(this));
398  }
TypedThreadSafeFunction< void, AddOnMinsky, messageCallback > tsMessageCallback
Definition: addon.cc:375

◆ messageCallback()

static void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::messageCallback ( Napi::Env  env,
Napi::Function  fn,
void *  ,
AddOnMinsky addonMinsky 
)
inlinestatic

Definition at line 364 of file addon.cc.

References messageButtons, theMessage, and userResponse.

365  {
366  auto buttons=Array::New(env);
367  for (unsigned i=0; i< addonMinsky->messageButtons.size(); ++i)
368  buttons[i]=String::New(env,addonMinsky->messageButtons[i]);
369  try {
370  addonMinsky->userResponse.set_value(fn({String::New(env,addonMinsky->theMessage), buttons}).As<Number>().Int32Value());
371  } catch (...) {/* may fail if multiple messages posted in rapid succession */}
372  }

◆ outOfMemoryHandler()

void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::outOfMemoryHandler ( )
inline

Definition at line 524 of file addon.cc.

525  {
526  string file=(std::filesystem::current_path()/"savedRavelSession.rvl").string();
527  if (autoSaver) {
528  autoSaver->killThread();
529  file=autoSaver->fileName;
530  }
531  save(file);
532 
533  theMessage="Out of memory, saving to autosave file: "+file;
534  messageButtons={"OK"};
535  userResponse={}; //reset the promise
536  tsMessageCallback.BlockingCall(const_cast<AddOnMinsky*>(this));
537  userResponse.get_future().get();
538  }
void save(const std::string &filename)
Definition: minsky.cc:1013
TypedThreadSafeFunction< void, AddOnMinsky, messageCallback > tsMessageCallback
Definition: addon.cc:375

◆ progress()

void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::progress ( const string &  title,
int   
)
inlineoverridevirtual

set progress bar, out of 100, labelling the progress bar with title

Reimplemented from minsky::Minsky.

Definition at line 453 of file addon.cc.

454  {
455  if (!progressCallbackSet) return;
456  progressValue=x;
457  progressTitle=title;
458  tsProgressCallback.BlockingCall(this);
459  }
TypedThreadSafeFunction< void, AddOnMinsky, progressCallback > tsProgressCallback
Definition: addon.cc:461

◆ progressCallback()

static void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::progressCallback ( Napi::Env  env,
Napi::Function  fn,
void *  ,
AddOnMinsky addon 
)
inlinestatic

Definition at line 446 of file addon.cc.

References progressTitle, and progressValue.

447  {
448  fn({String::New(env,addon->progressTitle), Number::New(env,addon->progressValue)});
449  }

◆ queueCommand()

Value minsky::anonymous_namespace{addon.cc}::AddOnMinsky::queueCommand ( Env  env,
string  command,
const json_pack_t &  arguments 
)
inline

Definition at line 209 of file addon.cc.

210  {
211  static const std::string sync=".$sync";
212  if (command.ends_with(sync))
213  {
214  command.erase(command.size()-sync.length());
215  // Javascript needs the result returned as UTF-16.
216  return String::New(env, utf_to_utf<char16_t>(doCommand(command, arguments)));
217  }
218 #if defined(_WIN32) || defined(MAC_OSX_TK)
219  // renderFrame needs to be called synchronously, otherwise inexplicable hangs occur on Windows.
220  if (command.ends_with(".renderFrame"))
221  return String::New(env, utf_to_utf<char16_t>(doCommand(command, arguments)));
222 #endif
223  if (minskyCommands.size()>20)
224  {
226  inputBufferExceeded=true;
227  return env.Null();
228  }
229  if (inputBufferExceeded) clearBusyCursor(); // single shot clear of busy curser
230  inputBufferExceeded=false;
231  const lock_guard<mutex> lock(cmdMutex);
232  minskyCommands.emplace_back(new Command{env,command,arguments});
233  return minskyCommands.back()->promiseResolver->promise.Promise();
234  }
string doCommand(const string &command, const json_pack_t &arguments)
Definition: addon.cc:236
deque< unique_ptr< Command > > minskyCommands
Definition: addon.cc:194
void setBusyCursor() override
set/clear busy cursor in GUI
Definition: addon.cc:441

◆ resetScroll()

void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::resetScroll ( )
inlineoverridevirtual

reset main window scroll bars after model has been panned

Reimplemented from minsky::Minsky.

Definition at line 505 of file addon.cc.

506  {
507  if (!resetScrollSet) return;
508  tsResetScrollCallback.BlockingCall(this);
509  }
TypedThreadSafeFunction< void, AddOnMinsky, resetScrollCallback > tsResetScrollCallback
Definition: addon.cc:511

◆ resetScrollCallback()

static void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::resetScrollCallback ( Napi::Env  env,
Napi::Function  fn,
void *  ,
AddOnMinsky addon 
)
inlinestatic

Definition at line 500 of file addon.cc.

501  {
502  fn({});
503  }

◆ run()

void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::run ( )
inline

Definition at line 294 of file addon.cc.

References minsky::anonymous_namespace{addon.cc}::minskyCmdMutex.

295  {
296 #if defined(_PTHREAD_H) && defined(__USE_GNU) && !defined(NDEBUG)
297  pthread_setname_np(pthread_self(),"minsky thread");
298 #endif
299  while (running)
300  {
301  unique_ptr<Command> command;
302  {
303  const lock_guard<mutex> lock(cmdMutex);
304  if (!minskyCommands.empty())
305  {
306  command=std::move(minskyCommands.front());
307  minskyCommands.pop_front();
308  }
309  }
310 
311  if (!command) // perform housekeeping
312  {
313  if (reset_flag() && resetDuration<resetPostponedThreshold && resetAt<std::chrono::system_clock::now())
314  try
315  {
316  const lock_guard<mutex> lock(minskyCmdMutex);
317  if (reset_flag()) // check again, in case another thread got there first
318  {
319  const Timer timer(timers["minsky.reset"]);
320  reset();
321  }
322  }
323  catch (...)
324  {flags&=~reset_needed;}
325 #ifdef MAC_OSX_TK
326  if (!drawLaunched && nativeWindowsToRedraw.size())
328 #else
330 #endif
331  if (inputBufferExceeded && minskyCommands.empty())
332  {
333  // clears busy cursor when no commands are being received or processed
334  clearBusyCursor();
335  inputBufferExceeded=false;
336  }
337  this_thread::sleep_for(chrono::milliseconds(10));
338  continue;
339  }
340 
341  if (!running) return;
342  try
343  {
344  auto result=doCommand(command->command, command->arguments);
345  if (!running) return; // prevent crashes on shutdown
346  command->promiseResolver->resolve(result);
347  }
348  catch (const std::exception& ex)
349  {
350  if (!running) return; // prevent crashes on shutdown
351  command->promiseResolver->reject(ex.what());
352  }
353  catch (...)
354  {
355  if (!running) return; // prevent crashes on shutdown
356  command->promiseResolver->reject("Unknown exception");
357  }
358  }
359  }
void reset()
resets the variables back to their initial values
Definition: minsky.cc:865
bool reset_flag() const
true if reset needs to be called prior to numerical integration
Definition: minsky.h:159
string doCommand(const string &command, const json_pack_t &arguments)
Definition: addon.cc:236
deque< unique_ptr< Command > > minskyCommands
Definition: addon.cc:194

◆ setBookmarkRefreshCallback()

Value minsky::anonymous_namespace{addon.cc}::AddOnMinsky::setBookmarkRefreshCallback ( const Napi::CallbackInfo &  info)
inline

Definition at line 487 of file addon.cc.

488  {
489  const Env env = info.Env();
490  if (info.Length()<1 || !info[0].IsFunction())
491  {
492  Napi::Error::New(env, "Callback not provided").ThrowAsJavaScriptException();
493  }
494  bookmarkRefreshSet=true;
495  tsBookmarkRefreshCallback=TypedThreadSafeFunction<void,AddOnMinsky,bookmarkRefreshCallback>::New
496  (env,info[0].As<Function>(), "refreshBookmark",0,2,nullptr);
497  return env.Null();
498  }
TypedThreadSafeFunction< void, AddOnMinsky, bookmarkRefreshCallback > tsBookmarkRefreshCallback
Definition: addon.cc:486

◆ setBusyCursor()

void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::setBusyCursor ( )
inlineoverridevirtual

set/clear busy cursor in GUI

Reimplemented from minsky::Minsky.

Definition at line 441 of file addon.cc.

◆ setBusyCursorCallback()

Value minsky::anonymous_namespace{addon.cc}::AddOnMinsky::setBusyCursorCallback ( const Napi::CallbackInfo &  info)
inline

Definition at line 421 of file addon.cc.

422  {
423  const Env env = info.Env();
424  if (info.Length()<1 || !info[0].IsFunction())
425  {
426  Napi::Error::New(env, "Callback not provided").ThrowAsJavaScriptException();
427  }
429  tsBusyCursorCallback=TypedThreadSafeFunction<void,bool,busyCursorCallback>::New
430  (env,info[0].As<Function>(), "setBusyCursor",0,2,nullptr);
431  return env.Null();
432  }
TypedThreadSafeFunction< void, bool, busyCursorCallback > tsBusyCursorCallback
Definition: addon.cc:420

◆ setMessageCallback()

Value minsky::anonymous_namespace{addon.cc}::AddOnMinsky::setMessageCallback ( const Napi::CallbackInfo &  info)
inline

Definition at line 376 of file addon.cc.

377  {
378  const Env env = info.Env();
379  if (info.Length()<1 || !info[0].IsFunction())
380  {
381  Napi::Error::New(env, "Callback not provided").ThrowAsJavaScriptException();
382  }
383  messageCallbackSet=true;
384  tsMessageCallback=TypedThreadSafeFunction<void,AddOnMinsky,messageCallback>::New
385  (env,info[0].As<Function>(), "message",0,2,nullptr);
386 
387  return env.Null();
388  }
TypedThreadSafeFunction< void, AddOnMinsky, messageCallback > tsMessageCallback
Definition: addon.cc:375

◆ setProgressCallback()

Value minsky::anonymous_namespace{addon.cc}::AddOnMinsky::setProgressCallback ( const Napi::CallbackInfo &  info)
inline

Definition at line 462 of file addon.cc.

463  {
464  const Env env = info.Env();
465  if (info.Length()<1 || !info[0].IsFunction())
466  {
467  Napi::Error::New(env, "Callback not provided").ThrowAsJavaScriptException();
468  }
469  progressCallbackSet=true;
470  tsProgressCallback=TypedThreadSafeFunction<void,AddOnMinsky,progressCallback>::New
471  (env,info[0].As<Function>(), "progress",0,2,nullptr);
472  return env.Null();
473  }
TypedThreadSafeFunction< void, AddOnMinsky, progressCallback > tsProgressCallback
Definition: addon.cc:461

◆ setResetScrollCallback()

Value minsky::anonymous_namespace{addon.cc}::AddOnMinsky::setResetScrollCallback ( const Napi::CallbackInfo &  info)
inline

Definition at line 512 of file addon.cc.

513  {
514  const Env env = info.Env();
515  if (info.Length()<1 || !info[0].IsFunction())
516  {
517  Napi::Error::New(env, "Callback not provided").ThrowAsJavaScriptException();
518  }
519  resetScrollSet=true;
520  tsResetScrollCallback=TypedThreadSafeFunction<void,AddOnMinsky,resetScrollCallback>::New
521  (env,info[0].As<Function>(), "resetScroll",0,2,nullptr);
522  return env.Null();
523  }
TypedThreadSafeFunction< void, AddOnMinsky, resetScrollCallback > tsResetScrollCallback
Definition: addon.cc:511

◆ tsDrawNativeWindows()

static void minsky::anonymous_namespace{addon.cc}::AddOnMinsky::tsDrawNativeWindows ( Napi::Env  env,
Napi::Function  ,
AddOnMinsky minsky,
void *   
)
inlinestatic

Definition at line 272 of file addon.cc.

273  {minsky->macOSXDrawNativeWindows();}

Member Data Documentation

◆ bookmarkRefreshSet

bool minsky::anonymous_namespace{addon.cc}::AddOnMinsky::bookmarkRefreshSet =false

Definition at line 485 of file addon.cc.

◆ busyCursor

bool minsky::anonymous_namespace{addon.cc}::AddOnMinsky::busyCursor =false

Definition at line 434 of file addon.cc.

◆ busyCursorCallbackSet

bool minsky::anonymous_namespace{addon.cc}::AddOnMinsky::busyCursorCallbackSet =false

Definition at line 419 of file addon.cc.

◆ cmdMutex

mutex minsky::anonymous_namespace{addon.cc}::AddOnMinsky::cmdMutex

Definition at line 195 of file addon.cc.

◆ drawLaunched

atomic<bool> minsky::anonymous_namespace{addon.cc}::AddOnMinsky::drawLaunched {false}

Definition at line 271 of file addon.cc.

◆ inputBufferExceeded

bool minsky::anonymous_namespace{addon.cc}::AddOnMinsky::inputBufferExceeded =false

Definition at line 198 of file addon.cc.

◆ messageButtons

vector<string> minsky::anonymous_namespace{addon.cc}::AddOnMinsky::messageButtons
mutable

Definition at line 362 of file addon.cc.

Referenced by messageCallback().

◆ messageCallbackSet

bool minsky::anonymous_namespace{addon.cc}::AddOnMinsky::messageCallbackSet =false

Definition at line 374 of file addon.cc.

◆ minskyCommands

deque<unique_ptr<Command> > minsky::anonymous_namespace{addon.cc}::AddOnMinsky::minskyCommands

Definition at line 194 of file addon.cc.

◆ progressCallbackSet

bool minsky::anonymous_namespace{addon.cc}::AddOnMinsky::progressCallbackSet =false

Definition at line 460 of file addon.cc.

◆ progressTitle

string minsky::anonymous_namespace{addon.cc}::AddOnMinsky::progressTitle

Definition at line 452 of file addon.cc.

Referenced by progressCallback().

◆ progressValue

int minsky::anonymous_namespace{addon.cc}::AddOnMinsky::progressValue =0

Definition at line 451 of file addon.cc.

Referenced by progressCallback().

◆ resetScrollSet

bool minsky::anonymous_namespace{addon.cc}::AddOnMinsky::resetScrollSet =false

Definition at line 510 of file addon.cc.

◆ running

atomic<bool> minsky::anonymous_namespace{addon.cc}::AddOnMinsky::running {true}

Definition at line 196 of file addon.cc.

◆ theMessage

string minsky::anonymous_namespace{addon.cc}::AddOnMinsky::theMessage
mutable

Definition at line 361 of file addon.cc.

Referenced by messageCallback().

◆ thread

std::thread minsky::anonymous_namespace{addon.cc}::AddOnMinsky::thread

Definition at line 197 of file addon.cc.

◆ timers

Timers minsky::anonymous_namespace{addon.cc}::AddOnMinsky::timers

Definition at line 193 of file addon.cc.

◆ tsBookmarkRefreshCallback

TypedThreadSafeFunction<void,AddOnMinsky,bookmarkRefreshCallback> minsky::anonymous_namespace{addon.cc}::AddOnMinsky::tsBookmarkRefreshCallback

Definition at line 486 of file addon.cc.

◆ tsBusyCursorCallback

TypedThreadSafeFunction<void,bool,busyCursorCallback> minsky::anonymous_namespace{addon.cc}::AddOnMinsky::tsBusyCursorCallback

Definition at line 420 of file addon.cc.

◆ tsDrawNativeWindows_

TypedThreadSafeFunction<AddOnMinsky,void,tsDrawNativeWindows> minsky::anonymous_namespace{addon.cc}::AddOnMinsky::tsDrawNativeWindows_

Definition at line 275 of file addon.cc.

◆ tsMessageCallback

TypedThreadSafeFunction<void,AddOnMinsky,messageCallback> minsky::anonymous_namespace{addon.cc}::AddOnMinsky::tsMessageCallback

Definition at line 375 of file addon.cc.

◆ tsProgressCallback

TypedThreadSafeFunction<void,AddOnMinsky,progressCallback> minsky::anonymous_namespace{addon.cc}::AddOnMinsky::tsProgressCallback

Definition at line 461 of file addon.cc.

◆ tsResetScrollCallback

TypedThreadSafeFunction<void,AddOnMinsky,resetScrollCallback> minsky::anonymous_namespace{addon.cc}::AddOnMinsky::tsResetScrollCallback

Definition at line 511 of file addon.cc.

◆ userResponse

promise<unsigned> minsky::anonymous_namespace{addon.cc}::AddOnMinsky::userResponse
mutable

Definition at line 363 of file addon.cc.

Referenced by messageCallback().


The documentation for this struct was generated from the following file: