NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
winlayout.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2021 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#include "winlayout.hpp"
20#include "../utils/tinyxml2.h"
21#include "../io/styledtextfile.hpp"
22#include "../../kernel.hpp"
23#include "../procedure/includer.hpp"
24
25#include <stack>
26#include <memory>
27
28std::string removeQuotationMarks(const std::string& sString);
29
30
40static std::string parseNumOpt(const std::string& sCmd, size_t pos)
41{
43}
44
45
55static std::string parseStringOpt(const std::string& sCmd, size_t pos)
56{
57 std::string arg = getArgAtPos(sCmd, pos, ARGEXTRACT_PARSED);
58 StripSpaces(arg);
59
60 if (arg.find(",") != std::string::npos && arg.find("\"") != std::string::npos)
61 return arg;
62 else if (arg.front() == '"' && arg.back() == '"')
63 return arg.substr(1, arg.length()-2);
64
65 return arg;
66}
67
68
79static std::string parseEventOpt(const std::string& sCmd, size_t pos, const std::string& sFolderName)
80{
81 std::string option = getArgAtPos(sCmd, pos);
82 std::string sProcBase = NumeReKernel::getInstance()->getSettings().getProcPath();
83
84 if (sFolderName.substr(0, sProcBase.length()) == sProcBase)
85 {
86 sProcBase = sFolderName.substr(sProcBase.length());
87 replaceAll(sProcBase, "/", "~");
88
89 while (sProcBase.front() == '~')
90 sProcBase.erase(0, 1);
91
92 if (sProcBase.length() && sProcBase.back() != '~')
93 sProcBase += "~";
94 }
95 else
96 sProcBase.clear();
97
98 if (option.front() == '$' && option.substr(option.length()-2) == "()")
99 option.erase(option.length()-2);
100
101 if (option.substr(0, 6) == "$this~")
102 option = "$" + sProcBase + option.substr(6);
103
104 return option;
105}
106
107
117static void evaluateExpression(std::string& sExpr)
118{
120
121 if (sExpr.find_first_not_of(' ') == std::string::npos)
122 return;
123
124 // Call functions
125 if (!instance->getDefinitions().call(sExpr))
127
128 // Evaluate strings
129 if (instance->getStringParser().isStringExpression(sExpr))
130 {
131 std::string dummy;
132 NumeRe::StringParser::StringParserRetVal _ret = instance->getStringParser().evalAndFormat(sExpr, dummy, true);
133
135 return;
136 }
137
138 if (instance->getMemoryManager().containsTablesOrClusters(sExpr))
139 getDataElements(sExpr, instance->getParser(), instance->getMemoryManager(), instance->getSettings());
140
141 // Numerical evaluation
142 instance->getParser().SetExpr(sExpr);
143
144 int results;
145 mu::value_type* v = instance->getParser().Eval(results);
146
147 sExpr.clear();
148
149 for (int i = 0; i < results; i++)
150 {
151 if (sExpr.length())
152 sExpr += ",";
153
154 sExpr += toString(v[i], 7);
155 }
156}
157
158
169static void parseLayoutCommand(const std::string& sLayoutCommand, tinyxml2::XMLElement* layoutElement, const std::string& sFolderName)
170{
171 std::string sExpr = sLayoutCommand.substr(0, std::min(sLayoutCommand.find("-set"), sLayoutCommand.find("--")));
172
173 replaceAll(sExpr, "<this>", sFolderName.c_str());
174
175 evaluateExpression(sExpr);
176
177 StripSpaces(sExpr);
178
179 layoutElement->SetText(sExpr.c_str());
180
181 if (findParameter(sLayoutCommand, "id", '='))
182 layoutElement->SetAttribute("id", parseNumOpt(sLayoutCommand, findParameter(sLayoutCommand, "id", '=')+2).c_str());
183
184 if (findParameter(sLayoutCommand, "color", '='))
185 layoutElement->SetAttribute("color", parseNumOpt(sLayoutCommand, findParameter(sLayoutCommand, "color", '=')+5).c_str());
186
187 if (findParameter(sLayoutCommand, "min", '='))
188 layoutElement->SetAttribute("min", parseNumOpt(sLayoutCommand, findParameter(sLayoutCommand, "min", '=')+3).c_str());
189
190 if (findParameter(sLayoutCommand, "max", '='))
191 layoutElement->SetAttribute("max", parseNumOpt(sLayoutCommand, findParameter(sLayoutCommand, "max", '=')+3).c_str());
192
193 if (findParameter(sLayoutCommand, "value", '='))
194 layoutElement->SetAttribute("value", parseStringOpt(sLayoutCommand, findParameter(sLayoutCommand, "value", '=')+5).c_str());
195
196 if (findParameter(sLayoutCommand, "label", '='))
197 layoutElement->SetAttribute("label", parseStringOpt(sLayoutCommand, findParameter(sLayoutCommand, "label", '=')+5).c_str());
198
199 if (findParameter(sLayoutCommand, "font", '='))
200 layoutElement->SetAttribute("font", parseStringOpt(sLayoutCommand, findParameter(sLayoutCommand, "font", '=')+4).c_str());
201
202 if (findParameter(sLayoutCommand, "align", '='))
203 layoutElement->SetAttribute("align", parseStringOpt(sLayoutCommand, findParameter(sLayoutCommand, "align", '=')+5).c_str());
204
205 if (findParameter(sLayoutCommand, "type", '='))
206 layoutElement->SetAttribute("type", getArgAtPos(sLayoutCommand, findParameter(sLayoutCommand, "type", '=')+4).c_str());
207
208 if (findParameter(sLayoutCommand, "size", '='))
209 layoutElement->SetAttribute("size", parseNumOpt(sLayoutCommand, findParameter(sLayoutCommand, "size", '=')+4).c_str());
210
211 if (findParameter(sLayoutCommand, "state", '='))
212 layoutElement->SetAttribute("state", getArgAtPos(sLayoutCommand, findParameter(sLayoutCommand, "state", '=')+5).c_str());
213
214 if (findParameter(sLayoutCommand, "onchange", '='))
215 layoutElement->SetAttribute("onchange", parseEventOpt(sLayoutCommand, findParameter(sLayoutCommand, "onchange", '=')+8, sFolderName).c_str());
216
217 if (findParameter(sLayoutCommand, "onclick", '='))
218 layoutElement->SetAttribute("onclick", parseEventOpt(sLayoutCommand, findParameter(sLayoutCommand, "onclick", '=')+7, sFolderName).c_str());
219}
220
221
233static std::string parseLayoutScript(std::string& sLayoutScript, tinyxml2::XMLDocument* layout)
234{
235 // Ensure that the file name of the layout
236 // script is valid
237 sLayoutScript = NumeReKernel::getInstance()->getScript().ValidFileName(sLayoutScript, ".nlyt");
238
239 // Load the layoutscript as a StyledTextFile
240 StyledTextFile layoutScript(sLayoutScript);
241 SymDefManager _symDefs;
242 std::unique_ptr<Includer> _includer; // Pointer-based, because it might not be available each time
243
244 std::string sFolderName = sLayoutScript.substr(0, sLayoutScript.rfind('/'));
245 std::string sOnOpenEvent;
246
247 // Nothing read?
248 if (!layoutScript.getLinesCount())
250
251 std::stack<tinyxml2::XMLElement*> currentGroup;
252 tinyxml2::XMLElement* currentChild = nullptr;
253 int i = 0;
254
255 // Go through the layout script
256 while (i < layoutScript.getLinesCount())
257 {
258 std::string line;
259
260 // If the includer is open, get the line from
261 // here
262 if (_includer && _includer->is_open())
263 {
264 line = _includer->getNextLine();
265
266 // Remove not necessary global statements
267 if (findCommand(line).sString == "global")
268 line.erase(0, findCommand(line).nPos+7);
269 }
270 else
271 {
272 // Free up the includer, if it is not necessary any more
273 if (_includer)
274 _includer.reset();
275
276 // Get the current line without comments
277 line = layoutScript.getStrippedLine(i);
278 i++;
279
280 // If this line contains an including syntax, create
281 // a new includer to resolve that
282 if (Includer::is_including_syntax(line) && !_includer)
283 {
284 _includer.reset(new Includer(line, sLayoutScript.substr(0, sLayoutScript.rfind('/'))));
285 continue;
286 }
287 }
288
289 // Resolve symbol declarations
290 _symDefs.resolveSymbols(line);
291
292 StripSpaces(line);
293
294 if (line.length())
295 {
296 Match _mMatch = findCommand(line);
297
298 // Create new symbol declarations
299 if (_mMatch.sString == "declare")
300 {
301 _symDefs.createSymbol(line.substr(_mMatch.nPos+8));
302 continue;
303 }
304
305 // Decode the commands
306 if (_mMatch.sString == "layout")
307 {
308 // Start of the layout block
309 currentGroup.push(layout->NewElement("layout"));
310 layout->InsertFirstChild(currentGroup.top());
311 replaceAll(line, "<this>", sFolderName.c_str());
312
313 if (findParameter(line, "size", '='))
314 currentGroup.top()->SetAttribute("size", parseNumOpt(line, findParameter(line, "size", '=')+4).c_str());
315
316 if (findParameter(line, "title", '='))
317 currentGroup.top()->SetAttribute("title", parseStringOpt(line, findParameter(line, "title", '=')+5).c_str());
318
319 if (findParameter(line, "icon", '='))
320 currentGroup.top()->SetAttribute("icon", parseStringOpt(line, findParameter(line, "icon", '=')+4).c_str());
321
322 if (findParameter(line, "color", '='))
323 currentGroup.top()->SetAttribute("color", parseNumOpt(line, findParameter(line, "color", '=')+5).c_str());
324
325 if (findParameter(line, "onopen", '='))
326 sOnOpenEvent = parseEventOpt(line, findParameter(line, "onopen", '=')+6, sFolderName);
327 }
328 else if (_mMatch.sString == "endlayout")
329 break;
330 else if (_mMatch.sString == "group")
331 {
332 // Start a new group
333 tinyxml2::XMLElement* newgroup = layout->NewElement("group");
334 currentGroup.top()->InsertEndChild(newgroup);
335 currentGroup.push(newgroup);
336
337 if (findParameter(line, "label", '='))
338 newgroup->SetAttribute("label", parseStringOpt(line, findParameter(line, "label", '=')+5).c_str());
339
340 if (findParameter(line, "type", '='))
341 newgroup->SetAttribute("type", getArgAtPos(line, findParameter(line, "type", '=')+4).c_str());
342
343 if (findParameter(line, "style", '='))
344 newgroup->SetAttribute("style", getArgAtPos(line, findParameter(line, "style", '=')+5).c_str());
345
346 if (findParameter(line, "expand"))
347 newgroup->SetAttribute("expand", "true");
348
349 }
350 else if (_mMatch.sString == "endgroup")
351 {
352 currentGroup.pop();
353
354 if (currentGroup.empty())
356 }
357 else if (_mMatch.sString == "prop" || _mMatch.sString == "var" || _mMatch.sString == "str")
358 {
359 if (currentGroup.empty())
360 throw SyntaxError(SyntaxError::CANNOT_READ_FILE, sLayoutScript, "");
361
362 // Create a the var element
363 currentChild = layout->NewElement("prop");
364 currentGroup.top()->InsertEndChild(currentChild);
365 std::string sLayoutCommand = line.substr(_mMatch.nPos+_mMatch.sString.length());
366 std::string sExpr = sLayoutCommand.substr(0, std::min(sLayoutCommand.find("-set"), sLayoutCommand.find("--")));
367 replaceAll(sExpr, "<this>", sFolderName.c_str());
368 StripSpaces(sExpr);
369 currentChild->SetText(sExpr.c_str());
370 }
371 else
372 {
373 // All other commands
374 if (currentGroup.empty())
375 throw SyntaxError(SyntaxError::CANNOT_READ_FILE, sLayoutScript, "");
376
377 // Create a new element
378 currentChild = layout->NewElement(_mMatch.sString.c_str());
379 currentGroup.top()->InsertEndChild(currentChild);
380
381 // Parse the parameters and the
382 // command expression and insert
383 // it
384 parseLayoutCommand(line.substr(_mMatch.nPos+_mMatch.sString.length()), currentChild, sFolderName);
385 }
386 }
387 }
388
389 // Nothing usable?
390 if (!layout->FirstChild())
392
393 return sOnOpenEvent;
394}
395
396
407static int getItemId(const std::string& sCmd)
408{
409 if (findParameter(sCmd, "item", '='))
411 else if (findParameter(sCmd, "id", '='))
413
414 return -1;
415}
416
417
427static NumeRe::WindowInformation getWindow(const std::string& sExpr)
428{
429 std::string sCurExpr = sExpr;
430
431 if (NumeReKernel::getInstance()->getMemoryManager().containsTablesOrClusters(sCurExpr))
432 getDataElements(sCurExpr, NumeReKernel::getInstance()->getParser(), NumeReKernel::getInstance()->getMemoryManager(), NumeReKernel::getInstance()->getSettings());
433
435 int windowID = intCast(NumeReKernel::getInstance()->getParser().Eval());
436
438}
439
440
450static void getParametersFromWindow(CommandLineParser& cmdParser, const std::string& sExpr)
451{
452 const std::string& sParList = cmdParser.getParameterList();
453
454 // Get value of window item
455 int itemID = getItemId(sParList);
456 NumeRe::WindowInformation winInfo = getWindow(sExpr);
457
458 // If the window does not exist, the pointer
459 // is a nullptr type
460 if (!winInfo.window || winInfo.nStatus != NumeRe::STATUS_RUNNING)
462
463 if (findParameter(sParList, "value"))
464 {
465 if (findParameter(sParList, "prop", '='))
466 {
467 std::string varname = getArgAtPos(sParList, findParameter(sParList, "prop", '=')+4);
468 cmdParser.setReturnValue(winInfo.window->getPropValue(varname));
469 }
470 else
471 {
472 NumeRe::WinItemValue val = winInfo.window->getItemValue(itemID);
473
474 if (val.type != "tablegrid")
475 cmdParser.setReturnValue(val.stringValue);
476 else
477 {
479 Indices _idx;
480 std::string sTarget = cmdParser.getTargetTable(_idx, "valtable");
481
482 cmdParser.setReturnValue("\"" + sTarget + "()\"");
483 _memManager.importTable(val.tableValue, sTarget, _idx.row, _idx.col);
484 }
485 }
486 }
487 else if (findParameter(sParList, "label"))
488 cmdParser.setReturnValue(winInfo.window->getItemLabel(itemID));
489 else if (findParameter(sParList, "state"))
490 cmdParser.setReturnValue("\"" + winInfo.window->getItemState(itemID) + "\"");
491 else if (findParameter(sParList, "color"))
492 cmdParser.setReturnValue(winInfo.window->getItemColor(itemID));
493}
494
495
505static void setParametersInWindow(CommandLineParser& cmdParser, const std::string& sExpr)
506{
507 const std::string& sParList = cmdParser.getParameterList();
508
509 // Change value of window item
510 int itemID = getItemId(sParList);
511 NumeRe::WindowInformation winInfo = getWindow(sExpr);
512
513 // If the window does not exist, the pointer
514 // is a nullptr type
515 if (!winInfo.window || winInfo.nStatus != NumeRe::STATUS_RUNNING)
517
518 // Get the new value
519 if (findParameter(sParList, "value", '='))
520 {
521 if (findParameter(sParList, "prop", '='))
522 {
523 std::string varname = getArgAtPos(sParList, findParameter(sParList, "prop", '=')+4);
524 cmdParser.setReturnValue(toString(winInfo.window->setPropValue(getArgAtPos(sParList, findParameter(sParList, "value", '=')+5, ARGEXTRACT_PARSED), varname)));
525 }
526 else
527 {
528 std::string sValue = getArgAtPos(sParList, findParameter(sParList, "value", '=')+5);
531
532 if (_memManager.containsTables(sValue))
533 {
534 DataAccessParser _access(sValue);
535 value.tableValue = _memManager.extractTable(_access.getDataObject(), _access.getIndices().row, _access.getIndices().col);
536 value.stringValue = _access.getDataObject() + "()";
537 }
538 else
539 value.stringValue = cmdParser.getParameterValueAsString("value", "");
540
541 cmdParser.setReturnValue(toString(winInfo.window->setItemValue(value, itemID)));
542 }
543 }
544 else if (findParameter(sParList, "label", '='))
545 {
546 std::string sLabel = cmdParser.getParameterValueAsString("label", "");
547 cmdParser.setReturnValue(toString(winInfo.window->setItemLabel(sLabel, itemID)));
548 }
549 else if (findParameter(sParList, "state", '='))
550 {
551 std::string sState = getArgAtPos(sParList, findParameter(sParList, "state", '=')+5);
552 cmdParser.setReturnValue(toString(winInfo.window->setItemState(sState, itemID)));
553 }
554 else if (findParameter(sParList, "color", '='))
555 {
556 std::string sColor = parseNumOpt(sParList, findParameter(sParList, "color", '=')+5);
557 cmdParser.setReturnValue(toString(winInfo.window->setItemColor(sColor, itemID)));
558 }
559
560
561}
562
563
573{
575
576 // Find the expression part
577 std::string sExpr = cmdParser.getExpr();
578 std::string sParList = cmdParser.getParameterList();
579
580 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sExpr))
581 {
582 std::string dummy;
584 }
585
586 StripSpaces(sExpr);
587 sExpr = removeQuotationMarks(sExpr);
588
589 // Determine, what the user wants to do
590 if (findParameter(sParList, "getitems", '='))
591 {
592 // get IDs of all selected items
593 std::string sItemType = getArgAtPos(sParList, findParameter(sParList, "getitems", '=')+8);
594 NumeRe::WindowInformation winInfo = getWindow(sExpr);
596
597 // If the window does not exist, the pointer
598 // is a nullptr type
599 if (winInfo.window && winInfo.nStatus == NumeRe::STATUS_RUNNING)
600 {
601 if (sItemType == "prop")
602 {
603 cmdParser.setReturnValue("{" + winInfo.window->getProperties() + "}");
604 }
605 else
606 {
607 std::vector<int> vItems = winInfo.window->getWindowItems(sItemType);
608
609 if (!vItems.size())
610 cmdParser.setReturnValue("nan");
611 else
612 {
613 std::vector<mu::value_type> vRes;
614
615 // Convert the ints to doubles
616 for (auto items : vItems)
617 vRes.push_back(items);
618
619 cmdParser.setReturnValue(_parser.CreateTempVectorVar(vRes));
620 }
621 }
622 }
623 else
624 throw SyntaxError(SyntaxError::INVALID_WINDOW_ID, cmdParser.getCommandLine(), cmdParser.getExpr());
625 }
626 else if (findParameter(sParList, "get"))
627 getParametersFromWindow(cmdParser, sExpr);
628 else if (findParameter(sParList, "set"))
629 setParametersInWindow(cmdParser, sExpr);
630 else if (findParameter(sParList, "close"))
631 {
632 // Close window
633 NumeRe::WindowInformation winInfo = getWindow(sExpr);
634
635 // If the window does not exist, the pointer
636 // is a nullptr type
637 if (winInfo.window && winInfo.nStatus == NumeRe::STATUS_RUNNING)
638 cmdParser.setReturnValue(toString(winInfo.window->closeWindow()));
639 else
640 cmdParser.setReturnValue("false");
641 }
642 else
643 {
644 // Create new window
646 std::string sOnOpenEvent;
647
648 // parse layout
649 try
650 {
651 sOnOpenEvent = parseLayoutScript(sExpr, layout);
652 }
653 catch (...)
654 {
655 delete layout;
656 throw;
657 }
658
659 // Create the window and return the ID
660 int id = winManager.createWindow(layout);
661
662 size_t millisecs = 0;
663
664 while (millisecs < 3000)
665 {
666 Sleep(100);
667 millisecs += 100;
668
669 if (winManager.getWindowInformation(id).window->creationFinished())
670 break;
671 }
672
673 cmdParser.setReturnValue(toString(id));
674
675 // Create the string for the onopen event
676 if (sOnOpenEvent.length())
677 cmdParser.setReturnValue(" " + sOnOpenEvent + "(" + toString(id) + ", -1, {\"event\",\"onopen\",\"object\",\"window\",\"value\",nan,\"state\",\"enabled\"})");
678 }
679}
680
681
690static std::string getProcedureFileName(std::string sProc)
691{
692 // Replace all tilde characters in the current path
693 // string. Consider the special namespace "main", which
694 // is a reference to the toplevel procedure folder
695 for (size_t i = 0; i < sProc.length(); i++)
696 {
697 if (sProc[i] == '~')
698 {
699 if (sProc.length() > 5 && i >= 4 && sProc.substr(i - 4, 5) == "main~")
700 sProc = sProc.substr(0, i - 4) + sProc.substr(i + 1);
701 else
702 sProc[i] = '/';
703 }
704 }
705
706 // Create a valid file name from the procedure name
708
709 return sProc;
710}
711
712
723std::vector<std::string> getEventProcedures(const std::string& sLayoutFile)
724{
725 StyledTextFile layoutFile(sLayoutFile);
726 std::string sFolderName = sLayoutFile.substr(0, sLayoutFile.rfind('/'));
727 std::vector<std::string> vProcedures;
728
729 for (size_t i = 0; i < (size_t)layoutFile.getLinesCount(); i++)
730 {
731 std::string sLine = layoutFile.getStrippedLine(i);
732
733 if (findParameter(sLine, "onopen", '='))
734 {
735 std::string sEvent = parseEventOpt(sLine, findParameter(sLine, "onopen", '=')+6, sFolderName);
736
737 if (sEvent.front() == '$')
738 vProcedures.push_back(getProcedureFileName(sEvent.substr(1)));
739 }
740
741 if (findParameter(sLine, "onclick", '='))
742 {
743 std::string sEvent = parseEventOpt(sLine, findParameter(sLine, "onclick", '=')+7, sFolderName);
744
745 if (sEvent.front() == '$')
746 vProcedures.push_back(getProcedureFileName(sEvent.substr(1)));
747 }
748
749 if (findParameter(sLine, "onchange", '='))
750 {
751 std::string sEvent = parseEventOpt(sLine, findParameter(sLine, "onchange", '=')+8, sFolderName);
752
753 if (sEvent.front() == '$')
754 vProcedures.push_back(getProcedureFileName(sEvent.substr(1)));
755 }
756 }
757
758 return vProcedures;
759}
760
761
771{
772 const std::string& sParList = cmdParser.getParameterList();
773 std::string sMessage;
774 std::string sTitle = "NumeRe: Window";
775 std::string sExpression;
776 int nControls = NumeRe::CTRL_NONE;
778
779 // Extract the message for the user
780 if (findParameter(sParList, "msg", '='))
781 sMessage = cmdParser.getParameterValueAsString("msg", "");
782
783 // Extract the window title
784 if (findParameter(sParList, "title", '='))
785 sTitle = cmdParser.getParameterValueAsString("title", sTitle);
786
787 // Extract the selected dialog type if available, otherwise
788 // use the message box as default value
789 if (findParameter(sParList, "type", '='))
790 {
791 std::string sType = getArgAtPos(sParList, findParameter(sParList, "type", '=')+4);
792
793 if (sType == "filedialog")
794 nControls = NumeRe::CTRL_FILEDIALOG;
795 else if (sType == "dirdialog")
796 nControls = NumeRe::CTRL_FOLDERDIALOG;
797 else if (sType == "listdialog")
798 nControls = NumeRe::CTRL_LISTDIALOG;
799 else if (sType == "selectiondialog")
801 else if (sType == "messagebox")
802 nControls = NumeRe::CTRL_MESSAGEBOX;
803 else if (sType == "textentry")
804 nControls = NumeRe::CTRL_TEXTENTRY;
805 }
806 else
807 nControls = NumeRe::CTRL_MESSAGEBOX;
808
809 // Extract the button information. The default values are
810 // created by wxWidgets. We don't have to do that here
811 if (findParameter(sParList, "buttons", '='))
812 {
813 std::string sButtons = getArgAtPos(sParList, findParameter(sParList, "buttons", '=')+7);
814
815 if (sButtons == "ok")
816 nControls |= NumeRe::CTRL_OKBUTTON;
817 else if (sButtons == "okcancel")
819 else if (sButtons == "yesno")
820 nControls |= NumeRe::CTRL_YESNOBUTTON;
821 }
822
823 // Extract the icon information. The default values are
824 // created by wxWidgets. We don't have to do that here
825 if (findParameter(sParList, "icon", '='))
826 {
827 std::string sIcon = getArgAtPos(sParList, findParameter(sParList, "icon", '=')+4);
828
829 if (sIcon == "erroricon")
830 nControls |= NumeRe::CTRL_ICONERROR;
831 else if (sIcon == "warnicon")
832 nControls |= NumeRe::CTRL_ICONWARNING;
833 else if (sIcon == "infoicon")
834 nControls |= NumeRe::CTRL_ICONINFORMATION;
835 else if (sIcon == "questionicon")
836 nControls |= NumeRe::CTRL_ICONQUESTION;
837 }
838
839 // Strip spaces and assign the value
840 sExpression = cmdParser.getExpr();
841
842 // Handle strings in the default value
843 // expression. This will include also possible path
844 // tokens
845 if (kernel->getStringParser().isStringExpression(sExpression))
846 {
847 std::string sDummy;
848 kernel->getStringParser().evalAndFormat(sExpression, sDummy, true);
849 }
850
851 // Ensure that default values are available, if the user
852 // selected either a list or a selection dialog
853 if ((nControls & NumeRe::CTRL_LISTDIALOG || nControls & NumeRe::CTRL_SELECTIONDIALOG) && (!sExpression.length() || sExpression == "\"\""))
854 {
856 }
857
858 // Use the default expression as message for the message
859 // box as a fallback solution
860 if (nControls & NumeRe::CTRL_MESSAGEBOX && (!sMessage.length() || sMessage == "\"\""))
861 sMessage = getNextArgument(sExpression, false);
862
863 // Ensure that the message box has at least a message,
864 // because the message box is the default value
865 if (nControls & NumeRe::CTRL_MESSAGEBOX && (!sMessage.length() || sMessage == "\"\""))
866 {
868 }
869
870 // Ensure that the path for the file and the directory
871 // dialog is a valid path and replace all placeholders
872 if ((nControls & NumeRe::CTRL_FILEDIALOG || nControls & NumeRe::CTRL_FOLDERDIALOG) && sExpression.length() && sExpression != "\"\"")
873 {
874 std::string sTemp = sExpression;
875
876 sExpression = "\"" + kernel->getMemoryManager().ValidFolderName(removeQuotationMarks(getNextArgument(sTemp, true))) + "\"";
877
878 if (sTemp.length())
879 sExpression += "," + sTemp;
880 }
881
882 // Get the window manager, create the modal window and
883 // wait until the user interacted with the dialog
884 NumeRe::WindowManager& manager = kernel->getWindowManager();
885 size_t winid = manager.createWindow(NumeRe::WINDOW_MODAL, NumeRe::WindowSettings(nControls, true, sMessage, sTitle, sExpression));
887
888 // Insert the return value as a string into the command
889 // line and inform the command handler, that a value
890 // has to be evaluated
891 cmdParser.setReturnValue("\"" + replacePathSeparator(wininfo.sReturn) + "\"");
892}
893
894
895
896
897
This class provides the functionality to extract the different components of a command line into the ...
const std::string & getCommandLine() const
Returns the command line used for constructing this instance (e.g. for errors).
std::string getParameterValueAsString(const std::string &sParameter, const std::string &sDefaultValue, bool stripAlways=false, bool onlyStringEvaluation=false) const
Parses the selected parameter value as a string and returns it. If the parameter is not found,...
const std::string & getExpr() const
Returns the expression as plain value.
const std::string & getParameterList() const
Returns the parameter list.
std::string getTargetTable(Indices &_targetIndices, const std::string &sDefaultTableName)
Evaluates any target=TABLE() statements in the parameter list and returns the needed information....
void setReturnValue(const std::string &sRetVal)
Sets the return value of the current command by simply appending it to the return value statement.
This class is defined to abstrahize the determination of the correct data object and the calculation ...
Definition: dataaccess.hpp:38
Indices & getIndices()
Returns a reference to the stored indices.
Definition: dataaccess.cpp:196
std::string & getDataObject()
Returns a reference to the data object identifier.
Definition: dataaccess.cpp:170
std::string ValidFolderName(std::string _sFileName, bool doCleanPath=true, bool appendTrailingSeparator=true) const
This member function evaluates, whether the passed foldername is a valid foldername.
Definition: filesystem.cpp:369
std::string ValidFileName(std::string _sFileName, const std::string sExtension=".dat", bool checkExtension=true, bool doCleanPath=true) const
This member function evaluates, whether the passed filename is a valid filename. One may supply a pre...
Definition: filesystem.cpp:280
bool call(std::string &sExpr, int nRecursion=0)
This function searches for known custom definitions in the passed expression and replaces them with t...
Definition: define.cpp:801
This class represents a file, which can be included into other files using the @ syntax.
Definition: includer.hpp:32
static bool is_including_syntax(const std::string &sLine)
Static member function which determines, whether the passed line is actually a including syntax.
Definition: includer.cpp:318
This class represents the central memory managing instance. It will handle all tables and clusters,...
NumeRe::Table extractTable(const std::string &_sTable, const VectorIndex &lines=VectorIndex(0, VectorIndex::OPEN_END), const VectorIndex &cols=VectorIndex(0, VectorIndex::OPEN_END))
void importTable(NumeRe::Table _table, const std::string &_sTable, const VectorIndex &lines=VectorIndex(0, VectorIndex::OPEN_END), const VectorIndex &cols=VectorIndex(0, VectorIndex::OPEN_END))
bool containsTables(const std::string &sExpression)
This member function detects, whether a table is used in the current expression.
bool containsTablesOrClusters(const std::string &sCmdLine)
This member function evaluates, whether the passed command line contains tables or clusters.
virtual bool isStringExpression(const std::string &sExpression) override
Returns true, if the passed expression is an expression containing strings, string variables or strin...
StringParserRetVal evalAndFormat(std::string &sLine, std::string &sCache, bool bSilent=false, bool bCheckAssertions=false)
This public member function evaluates the passed string expression and formats the results for the co...
std::string getItemColor(int windowItemID) const
Returns the color of the selected window item as a string.
bool setItemState(const std::string &_state, int windowItemID)
Enables changing the state of the selected window item to the passed state.
WinItemValue getItemValue(int windowItemID) const
Returns the value of the selected window item as a string.
std::vector< int > getWindowItems(const std::string &_selection) const
Returns a vector of item ids corresponding to the available window items of this window.
std::string getItemLabel(int windowItemID) const
Returns the label of the selected window item as a string.
bool setItemColor(const std::string &_color, int windowItemID)
Enables changing the color of the selected window item to the passed color.
std::string getItemState(int windowItemID) const
Returns the state of the selected window item as a string.
std::string getProperties() const
Returns a list of all available window properties (comp. prop) in this window.
bool setItemValue(const WinItemValue &_value, int windowItemID)
Enables changing the value of the selected window item to the passed value.
bool setPropValue(const std::string &_value, const std::string &varName)
This function sets the value of the selected window property.
bool closeWindow()
Closes the current window.
std::string getPropValue(const std::string &varName) const
Returns the value of the selected property as a string.
bool setItemLabel(const std::string &_label, int windowItemID)
Enables changing the label of the selected window item to the passed label.
This is the window manager of the kernel. All windows opened by the kernel will be registered here.
WindowInformation getWindowInformationModal(size_t windowId)
This public member function will return the window information stored in the internal map....
WindowInformation getWindowInformation(size_t windowId)
This public member function will return the window information stored in the internal map....
size_t createWindow(GraphHelper *graph)
This public member function will create a window object containing the passed graph.
This class provides the interface to the core of NumeRe. It provides all functionalities,...
Definition: kernel.hpp:97
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
Definition: kernel.hpp:221
NumeRe::StringParser & getStringParser()
Definition: kernel.hpp:286
Script & getScript()
Definition: kernel.hpp:311
NumeRe::WindowManager & getWindowManager()
Definition: kernel.hpp:331
mu::Parser & getParser()
Definition: kernel.hpp:281
MemoryManager & getMemoryManager()
Definition: kernel.hpp:263
FunctionDefinitionManager & getDefinitions()
Definition: kernel.hpp:291
Procedure & getProcedureInterpreter()
Definition: kernel.hpp:316
Settings & getSettings()
Definition: kernel.hpp:296
std::string getProcPath() const
Returns the current procedure root import path.
Definition: settings.hpp:1068
This class represents a text file in memory (e.g. a code file). This class will try to lex the loaded...
std::string getStrippedLine(size_t line) const
Returns the selected line (without the line termination characters and without any comments).
int getLinesCount() const
Returns the number of lines in the current loaded file.
This class handles the file-static constants, which are more or less macros similar to #define in C/C...
Definition: symdef.hpp:32
void resolveSymbols(std::string &sCommandLine) const
Resolve all file-static constant declarations in the current line.
Definition: symdef.cpp:47
void createSymbol(const std::string &sCommandLine)
Create one or more new file-static constant declarations for the current file.
Definition: symdef.cpp:72
Common exception class for all exceptions thrown in NumeRe.
Definition: error.hpp:32
@ INVALID_WINDOW_ID
Definition: error.hpp:140
@ CANNOT_READ_FILE
Definition: error.hpp:75
@ FUNCTION_ERROR
Definition: error.hpp:110
@ NO_DEFAULTVALUE_FOR_DIALOG
Definition: error.hpp:184
static size_t invalid_position
Definition: error.hpp:235
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
string_type CreateTempVectorVar(const std::vector< mu::value_type > &vVar)
This member function copies the passed vector into the internal storage referencing it with a auto-ge...
Mathematical expressions parser.
Definition: muParser.h:51
XMLElement * NewElement(const char *name)
Definition: tinyxml2.cpp:2239
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
Definition: tinyxml2.h:1465
void SetText(const char *inText)
Definition: tinyxml2.cpp:1675
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:769
XMLNode * InsertFirstChild(XMLNode *addThis)
Definition: tinyxml2.cpp:925
XMLNode * InsertEndChild(XMLNode *addThis)
Definition: tinyxml2.cpp:895
string getDataElements(string &sLine, Parser &_parser, MemoryManager &_data, const Settings &_option, int options)
Searches the passed string for calls to any table or cluster and replaces them with internal vectors ...
Definition: dataaccess.cpp:276
std::string replacePathSeparator(const std::string &)
This function replaces the Windows style path sparators to UNIX style.
@ STATUS_RUNNING
@ CTRL_MESSAGEBOX
@ CTRL_SELECTIONDIALOG
@ CTRL_ICONERROR
@ CTRL_YESNOBUTTON
@ CTRL_FOLDERDIALOG
@ CTRL_TEXTENTRY
@ CTRL_FILEDIALOG
@ CTRL_LISTDIALOG
@ CTRL_ICONQUESTION
@ CTRL_ICONWARNING
@ CTRL_ICONINFORMATION
@ CTRL_CANCELBUTTON
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
#define min(a, b)
Definition: resampler.cpp:34
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
int StrToInt(const std::string &)
Converts a string into an integer.
int findParameter(const std::string &sCmd, const std::string &sParam, const char cFollowing)
This function searches the passed parameter in the passed command string. If something is found,...
Definition: tools.cpp:113
std::string getNextArgument(std::string &sArgList, bool bCut)
Definition: tools.cpp:2294
void replaceAll(std::string &sToModify, const char *sToRep, const char *sNewValue, size_t nStart, size_t nEnd)
This function replaces all occurences of the string sToRep in the string sToModify with the new value...
This structure is central for managing the indices of a table or cluster read or write data access....
VectorIndex col
VectorIndex row
Structure for the findCommand function.
unsigned int nPos
std::string sString
Kernel representation of the WindowItemValue structure of the CustomWindow class.
This class is used by the window manager to handle the information of an opened window and to store i...
This class contains the window information to create the dialog in the GUI.
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
Definition: tools.cpp:1824
std::string toString(int)
Converts an integer to a string without the Settings bloat.
Match findCommand(StringView sCmd, const std::string &sCommand)
This function is very important for the command handler.
Definition: tools.cpp:1275
string getArgAtPos(const string &sCmd, unsigned int nPos, int extraction)
Extracts a options value at the selected position and applies automatic parsing, if necessary.
Definition: tools.cpp:1598
@ ARGEXTRACT_ASINT
Definition: tools.hpp:58
@ ARGEXTRACT_STRIPPED
Definition: tools.hpp:56
@ ARGEXTRACT_PARSED
Definition: tools.hpp:57
static void getParametersFromWindow(CommandLineParser &cmdParser, const std::string &sExpr)
This static function handles property reads from windows.
Definition: winlayout.cpp:450
static void evaluateExpression(std::string &sExpr)
This static function evaluates the expression part of each window layout command.
Definition: winlayout.cpp:117
static int getItemId(const std::string &sCmd)
This static function returns the item id from the user command string. It is also handled if the user...
Definition: winlayout.cpp:407
static std::string parseEventOpt(const std::string &sCmd, size_t pos, const std::string &sFolderName)
This static function parses a event argument.
Definition: winlayout.cpp:79
static std::string parseStringOpt(const std::string &sCmd, size_t pos)
This static function parses a string option.
Definition: winlayout.cpp:55
std::vector< std::string > getEventProcedures(const std::string &sLayoutFile)
Examines a window layout file and searches for all event handler procedures. Returns their correspond...
Definition: winlayout.cpp:723
static NumeRe::WindowInformation getWindow(const std::string &sExpr)
This static function returns the window information describing the window with the selected ID.
Definition: winlayout.cpp:427
std::string removeQuotationMarks(const std::string &sString)
This function simply removes the surrounding quotation marks.
static std::string parseLayoutScript(std::string &sLayoutScript, tinyxml2::XMLDocument *layout)
This static function parses a layout script into a xml data container usable by the GUI....
Definition: winlayout.cpp:233
static void parseLayoutCommand(const std::string &sLayoutCommand, tinyxml2::XMLElement *layoutElement, const std::string &sFolderName)
This static function parses a single layout command into a usable XML element.
Definition: winlayout.cpp:169
static std::string getProcedureFileName(std::string sProc)
Converts a full-qualified procedure name into the corresponding file name.
Definition: winlayout.cpp:690
static std::string parseNumOpt(const std::string &sCmd, size_t pos)
This static function parses a numerical argument.
Definition: winlayout.cpp:40
void dialogCommand(CommandLineParser &cmdParser)
This function is the actual implementation of the dialog command.
Definition: winlayout.cpp:770
void windowCommand(CommandLineParser &cmdParser)
This function is the actual implementation of the window command.
Definition: winlayout.cpp:572
static void setParametersInWindow(CommandLineParser &cmdParser, const std::string &sExpr)
This static function handles property writes in windows.
Definition: winlayout.cpp:505