Skip to content

Commit 73fa637

Browse files
committed
- Set a call back function for plot commands. - Updated OMNotebook to use the OpenModelicaCompiler shared library. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25689 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 8a9f3b4 commit 73fa637

File tree

6 files changed

+56
-20
lines changed

6 files changed

+56
-20
lines changed

Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,7 +2513,6 @@ function plot "Launches a plot window using OMPlot."
25132513
input String footer = "" "This text will be used as the diagram footer.";
25142514
input Boolean autoScale = true "Use auto scale while plotting.";
25152515
output Boolean success "Returns true on success";
2516-
output String[:] result "Returns list i.e {\"_omc_PlotResult\",\"<fileName>\",\"<title>\",\"<legend>\",\"<grid>\",\"<PlotType>\",\"<logX>\",\"<logY>\",\"<xLabel>\",\"<yLabel>\",\"<xRange>\",\"<yRange>\",\"<curveWidth>\",\"<curveStyle>\",\"<legendPosition>\",\"<footer>\",\"<autoScale>\",\"<PlotVariables>\"}";
25172516
external "builtin";
25182517
annotation(preferredView="text",Documentation(info="<html>
25192518
<p>Launches a plot window using OMPlot. Returns true on success.</p>
@@ -2551,7 +2550,6 @@ function plotAll "Works in the same way as plot(), but does not accept any
25512550
input String footer = "" "This text will be used as the diagram footer.";
25522551
input Boolean autoScale = true "Use auto scale while plotting.";
25532552
output Boolean success "Returns true on success";
2554-
output String[:] result "Returns list i.e {\"_omc_PlotResult\",\"<fileName>\",\"<title>\",\"<legend>\",\"<grid>\",\"<PlotType>\",\"<logX>\",\"<logY>\",\"<xLabel>\",\"<yLabel>\",\"<xRange>\",\"<yRange>\",\"<curveWidth>\",\"<curveStyle>\",\"<legendPosition>\",\"<footer>\",\"<autoScale>\",\"<PlotVariables>\"}";
25552553
external "builtin";
25562554
annotation(preferredView="text");
25572555
end plotAll;
@@ -2596,7 +2594,6 @@ function plotParametric "Launches a plotParametric window using OMPlot. Returns
25962594
input String footer = "" "This text will be used as the diagram footer.";
25972595
input Boolean autoScale = true "Use auto scale while plotting.";
25982596
output Boolean success "Returns true on success";
2599-
output String[:] result "Returns list i.e {\"_omc_PlotResult\",\"<fileName>\",\"<title>\",\"<legend>\",\"<grid>\",\"<PlotType>\",\"<logX>\",\"<logY>\",\"<xLabel>\",\"<yLabel>\",\"<xRange>\",\"<yRange>\",\"<curveWidth>\",\"<curveStyle>\",\"<legendPosition>\",\"<footer>\",\"<autoScale>\",\"<PlotVariables>\"}";
26002597
external "builtin";
26012598
annotation(preferredView="text");
26022599
end plotParametric;

Compiler/Script/CevalScript.mo

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,7 +3010,7 @@ algorithm
30103010
/* in case plot is set to silent */
30113011
case (cache,env,"plotAll",
30123012
{
3013-
Values.BOOL(_),
3013+
Values.BOOL(externalWindow),
30143014
Values.STRING(filename),
30153015
Values.STRING(title),
30163016
Values.STRING(gridStr),
@@ -3046,11 +3046,9 @@ algorithm
30463046
curveWidthStr = realString(curveWidth);
30473047
curveStyleStr = intString(curveStyle);
30483048
autoScaleStr = boolString(autoScale);
3049-
args = {"_omc_PlotResult",filename,title,gridStr,"plotAll",logXStr,logYStr,xLabel,yLabel,x1Str,x2Str,y1Str,y2Str,curveWidthStr,curveStyleStr,legendPosition,footer,autoScaleStr};
3050-
vals = List.map(args, ValuesUtil.makeString);
3051-
v = ValuesUtil.makeArray(vals);
3049+
System.plotCallBack(externalWindow,filename,title,gridStr,"plotall",logXStr,logYStr,xLabel,yLabel,x1Str,x2Str,y1Str,y2Str,curveWidthStr,curveStyleStr,legendPosition,footer,autoScaleStr,"");
30523050
then
3053-
(cache,v,st);
3051+
(cache,Values.BOOL(true),st);
30543052

30553053
case (cache,_,"plotAll",_,st,_)
30563054
then (cache,Values.BOOL(false),st);
@@ -3105,7 +3103,7 @@ algorithm
31053103
case (cache,env,"plot",
31063104
{
31073105
Values.ARRAY(valueLst = cvars),
3108-
Values.BOOL(_),
3106+
Values.BOOL(externalWindow),
31093107
Values.STRING(filename),
31103108
Values.STRING(title),
31113109
Values.STRING(gridStr),
@@ -3128,7 +3126,7 @@ algorithm
31283126
// get the variables list
31293127
vars_1 = List.map(cvars, ValuesUtil.printCodeVariableName);
31303128
// seperate the variables
3131-
_ = stringDelimitList(vars_1,"\" \"");
3129+
str = stringDelimitList(vars_1,"\" \"");
31323130
// get the simulation filename
31333131
(cache,filename) = cevalCurrentSimulationResultExp(cache,env,filename,st,msg);
31343132
pd = System.pathDelimiter();
@@ -3144,12 +3142,9 @@ algorithm
31443142
curveWidthStr = realString(curveWidth);
31453143
curveStyleStr = intString(curveStyle);
31463144
autoScaleStr = boolString(autoScale);
3147-
args = {"_omc_PlotResult",filename,title,gridStr,"plot",logXStr,logYStr,xLabel,yLabel,x1Str,x2Str,y1Str,y2Str,curveWidthStr,curveStyleStr,legendPosition,footer,autoScaleStr};
3148-
args = listAppend(args, vars_1);
3149-
vals = List.map(args, ValuesUtil.makeString);
3150-
v = ValuesUtil.makeArray(vals);
3145+
System.plotCallBack(externalWindow,filename,title,gridStr,"plot",logXStr,logYStr,xLabel,yLabel,x1Str,x2Str,y1Str,y2Str,curveWidthStr,curveStyleStr,legendPosition,footer,autoScaleStr,str);
31513146
then
3152-
(cache,v,st);
3147+
(cache,Values.BOOL(true),st);
31533148

31543149
case (cache,_,"plot",_,st,_)
31553150
then
@@ -3462,7 +3457,7 @@ algorithm
34623457
{
34633458
cvar,
34643459
cvar2,
3465-
Values.BOOL(_),
3460+
Values.BOOL(externalWindow),
34663461
Values.STRING(filename),
34673462
Values.STRING(title),
34683463
Values.STRING(gridStr),
@@ -3485,6 +3480,7 @@ algorithm
34853480
// get the variables
34863481
str = ValuesUtil.printCodeVariableName(cvar);
34873482
str3 = ValuesUtil.printCodeVariableName(cvar2);
3483+
str = stringAppendList({str, " ", str3});
34883484
// get the simulation filename
34893485
(cache,filename) = cevalCurrentSimulationResultExp(cache,env,filename,st,msg);
34903486
pd = System.pathDelimiter();
@@ -3500,11 +3496,9 @@ algorithm
35003496
curveWidthStr = realString(curveWidth);
35013497
curveStyleStr = intString(curveStyle);
35023498
autoScaleStr = boolString(autoScale);
3503-
args = {"_omc_PlotResult",filename,title,gridStr,"plotParametric",logXStr,logYStr,xLabel,yLabel,x1Str,x2Str,y1Str,y2Str,curveWidthStr,curveStyleStr,legendPosition,footer,autoScaleStr,str,str3};
3504-
vals = List.map(args, ValuesUtil.makeString);
3505-
v = ValuesUtil.makeArray(vals);
3499+
System.plotCallBack(externalWindow,filename,title,gridStr,"plotparametric",logXStr,logYStr,xLabel,yLabel,x1Str,x2Str,y1Str,y2Str,curveWidthStr,curveStyleStr,legendPosition,footer,autoScaleStr,str);
35063500
then
3507-
(cache,v,st);
3501+
(cache,Values.BOOL(true),st);
35083502

35093503
case (cache,_,"plotParametric",_,st,_)
35103504
then (cache,Values.BOOL(false),st);

Compiler/Util/System.mo

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,29 @@ public function spawnCall
330330
external "C" outInteger=SystemImpl__spawnCall(path,str) annotation(Library = "omcruntime");
331331
end spawnCall;
332332

333+
public function plotCallBack
334+
input Boolean externalWindow;
335+
input String filename;
336+
input String title;
337+
input String grid;
338+
input String plotType;
339+
input String logX;
340+
input String logY;
341+
input String xLabel;
342+
input String yLabel;
343+
input String x1;
344+
input String x2;
345+
input String y1;
346+
input String y2;
347+
input String curveWidth;
348+
input String curveStyle;
349+
input String legendPosition;
350+
input String footer;
351+
input String autoScale;
352+
input String variables;
353+
external "C" SystemImpl__plotCallBack(OpenModelica.threadData(), externalWindow, filename, title, grid, plotType, logX, logY, xLabel, yLabel, x1, x2, y1, y2, curveWidth, curveStyle, legendPosition, footer, autoScale, variables) annotation(Library = "omcruntime");
354+
end plotCallBack;
355+
333356
public function cd
334357
input String inString;
335358
output Integer outInteger;

Compiler/runtime/systemimpl.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,18 @@ int SystemImpl__spawnCall(const char* path, const char* str)
815815
return ret_val;
816816
}
817817

818+
void SystemImpl__plotCallBack(threadData_t *threadData, int externalWindow, const char* filename, const char* title, const char* grid, const char* plotType,
819+
const char* logX, const char* logY, const char* xLabel, const char* yLabel, const char* x1, const char* x2, const char* y1,
820+
const char* y2, const char* curveWidth, const char* curveStyle, const char* legendPosition, const char* footer, const char* autoScale,
821+
const char* variables)
822+
{
823+
if (threadData->plotClassPointer && threadData->plotCB) {
824+
PlotCallback pcb = threadData->plotCB;
825+
pcb(threadData->plotClassPointer, externalWindow, filename, title, grid, plotType, logX, logY, xLabel, yLabel, x1, x2, y1, y2, curveWidth, curveStyle,
826+
legendPosition, footer, autoScale, variables);
827+
}
828+
}
829+
818830
extern double SystemImpl__time(void)
819831
{
820832
clock_t cl = clock();

Compiler/runtime/systemimpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ extern const char* SystemImpl__basename(const char *str);
8989
extern int SystemImpl__systemCall(const char* str, const char* outFile);
9090
extern void* SystemImpl__systemCallParallel(void *lst, int numThreads);
9191
extern int SystemImpl__spawnCall(const char* path, const char* str);
92+
extern void SystemImpl__plotCallBack(threadData_t *threadData, int externalWindow, const char* filename, const char* title, const char* grid, const char* plotType,
93+
const char* logX, const char* logY, const char* xLabel, const char* yLabel, const char* x1, const char* x2, const char* y1,
94+
const char* y2, const char* curveWidth, const char* curveStyle, const char* legendPosition, const char* footer,
95+
const char* autoScale, const char* variables);
9296
extern double SystemImpl__time(void);
9397
extern int SystemImpl__directoryExists(const char* str);
9498
extern int SystemImpl__createDirectory(const char *str);

SimulationRuntime/c/openmodelica_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ enum {
144144
MAX_LOCAL_ROOTS
145145
};
146146
#define MAX_LOCAL_ROOTS 16
147+
typedef void (*PlotCallback)(void*, int externalWindow, const char* filename, const char* title, const char* grid, const char* plotType, const char* logX,
148+
const char* logY, const char* xLabel, const char* yLabel, const char* x1, const char* x2, const char* y1, const char* y2,
149+
const char* curveWidth, const char* curveStyle, const char* legendPosition, const char* footer, const char* autoScale,
150+
const char* variables);
147151
typedef struct threadData_s {
148152
jmp_buf *mmc_jumper;
149153
jmp_buf *mmc_stack_overflow_jumper;
@@ -163,6 +167,8 @@ typedef struct threadData_s {
163167
errorStage currentErrorStage;
164168
struct threadData_s *parent;
165169
pthread_mutex_t parentMutex; /* Prevent children from all manipulating the parent at the same time */
170+
void *plotClassPointer;
171+
PlotCallback plotCB;
166172
} threadData_t;
167173

168174
#if defined(__cplusplus)

0 commit comments

Comments
 (0)