Skip to content

Commit dc110b6

Browse files
authored
Add support for NXT code generation in the 2D model (#1918)
1. Add support for NXT code generation in the 2D model 2. Add generation tests for NXT to CI 3. Use `JavaScript` as the default mode for executing files. 4. Add an option to generate the source code without further execution. Closes #1877
1 parent 1d77234 commit dc110b6

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

.github/workflows/installer.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ jobs:
140140
- name: Run minimal Python interpeter tests in direct script mode
141141
run: |
142142
PATH="" $SHELL -c 'for i in "$GITHUB_WORKSPACE"/tests/*.qrs; do "$TWOD_EXEC_NAME" --generate-path "$i".py \
143-
--close -s 5 --script-path "$i".py -m script "$i"; done'
143+
--generate-mode python --close -s 5 --script-path "$i".py -m script "$i"; done'
144144
timeout-minutes: 15
145145

146146
- name: Run minimal Javascript interpeter tests as fields in .qrs (For backward compatibility)
@@ -154,3 +154,16 @@ jobs:
154154
PATH="" $SHELL -c 'for i in "$GITHUB_WORKSPACE"/tests/*.qrs; do "$PATCHER_NAME" -s "$i".py "$i" \
155155
&& "$TWOD_EXEC_NAME" --close -s 5 -m script "$i"; done'
156156
timeout-minutes: 5
157+
158+
- name: Run nxt generation tests
159+
run: |
160+
curl --output nxt_tests.7z "https://dl.trikset.com/edu/.solutions20200701/nxt_generation.7z"
161+
7z x nxt_tests.7z || 7za x nxt_tests.7z
162+
set -x
163+
for i in "$GITHUB_WORKSPACE"/nxt/*.qrs;
164+
do
165+
"$TWOD_EXEC_NAME" --generate-mode nxt --generate-path "$i".c --only-generate "$i"
166+
ls "$GITHUB_WORKSPACE"/nxt/
167+
cat "$i".c
168+
done
169+
timeout-minutes: 5

plugins/robots/checker/twoDModelRunner/main.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,13 @@ int main(int argc, char *argv[])
129129
", to save the generated JavaScript or Python code.")
130130
, "path-to-save-code", QString());
131131
QCommandLineOption generateModeOption("generate-mode", QObject::tr("Select \"python\" or \"javascript\".")
132-
, "generate-mode", "python");
132+
, "generate-mode", "javascript");
133133
QCommandLineOption directScriptExecutionPathOption("script-path"
134134
, QObject::tr("The path to the Python or JavaScript file that will be used for interpretation.")
135135
, "script-path", QString());
136+
QCommandLineOption onlyGenerateOption("only-generate"
137+
, QObject::tr("Do not run the interpretation in any mode, "\
138+
"this is a parameter that is only used to generate a file."));
136139
parser.addOption(backgroundOption);
137140
parser.addOption(reportOption);
138141
parser.addOption(trajectoryOption);
@@ -145,6 +148,7 @@ int main(int argc, char *argv[])
145148
parser.addOption(generatePathOption);
146149
parser.addOption(generateModeOption);
147150
parser.addOption(directScriptExecutionPathOption);
151+
parser.addOption(onlyGenerateOption);
148152
parser.process(*app);
149153
const QStringList positionalArgs = parser.positionalArguments();
150154
if (positionalArgs.size() != 1) {
@@ -162,12 +166,14 @@ int main(int argc, char *argv[])
162166
const QString generatePath = parser.value(generatePathOption);
163167
const QString generateMode = parser.value(generateModeOption);
164168
const QString scriptFilePath = parser.value(directScriptExecutionPathOption);
169+
const bool onlyGenerate = parser.isSet(onlyGenerateOption);
165170

166171
QScopedPointer<twoDModel::Runner> runner(new twoDModel::Runner(report, trajectory, input, mode, qrsFile));
167172
auto speedFactor = parser.value(speedOption).toInt();
168173

169174
if (!generatePath.isEmpty()) {
170-
if (generateMode != "python" and generateMode != "javascript") {
175+
if (generateMode != "python" and generateMode != "javascript"
176+
and generateMode != "nxt") {
171177
parser.showHelp();
172178
QLOG_ERROR() << "Problem with generate code to " << generatePath;
173179
return TWO_D_MODEL_RUNNER_GENERATE_MODE_NOT_EXIST;
@@ -178,6 +184,10 @@ int main(int argc, char *argv[])
178184
}
179185
}
180186

187+
if (onlyGenerate || mode == "nxt") {
188+
return 0;
189+
}
190+
181191
if (!runner->interpret(backgroundMode, speedFactor, closeOnFinishMode,
182192
closeOnSuccessMode, showConsoleMode, scriptFilePath)) {
183193
return TWO_D_MODEL_RUNNER_INTERPRET_ERROR;

plugins/robots/checker/twoDModelRunner/runner.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ bool Runner::generate(const QString &generatePath, const QString &generateMode)
107107
emit action.action()->triggered();
108108
}
109109
}
110+
if (generateMode == "nxt") {
111+
if (action.action()->objectName() == "generateCode") {
112+
emit action.action()->triggered();
113+
}
114+
}
110115
}
111116

112117
auto codes = mTextManager->code(mMainWindow->activeDiagram());

qrtranslations/fr/plugins/robots/twoDModelRunner_fr.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ In background mode the session will be terminated just after the execution ended
5151
<translation type="unfinished"></translation>
5252
</message>
5353
<message>
54-
<location line="-3"/>
54+
<location line="+3"/>
55+
<source>Do not run the interpretation in any mode, this is a parameter that is only used to generate a file.</source>
56+
<translation type="unfinished"></translation>
57+
</message>
58+
<message>
59+
<location line="-6"/>
5560
<source>Select &quot;python&quot; or &quot;javascript&quot;.</source>
5661
<translation type="unfinished"></translation>
5762
</message>
@@ -87,7 +92,7 @@ In background mode the session will be terminated just after the execution ended
8792
<context>
8893
<name>twoDModel::Runner</name>
8994
<message>
90-
<location filename="../../../../plugins/robots/checker/twoDModelRunner/runner.cpp" line="+234"/>
95+
<location filename="../../../../plugins/robots/checker/twoDModelRunner/runner.cpp" line="+239"/>
9196
<source>Robot console</source>
9297
<translation type="unfinished"></translation>
9398
</message>

qrtranslations/ru/plugins/robots/twoDModelRunner_ru.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,16 @@ In background mode the session will be terminated just after the execution ended
5757
<translation>Путь к Python или Javascript файлу, который будет использоваться для интерпретации.</translation>
5858
</message>
5959
<message>
60-
<location line="-3"/>
60+
<location line="+3"/>
61+
<source>Do not run the interpretation in any mode, this is a parameter that is only used to generate a file.</source>
62+
<translation type="unfinished"></translation>
63+
</message>
64+
<message>
65+
<source>Do not run the interpretation in any mode, this is a parameter used only to generate a file.</source>
66+
<translation type="vanished">Не запускайте интерпретацию ни в каком режиме, этот параметр используется только для генерации файла.</translation>
67+
</message>
68+
<message>
69+
<location line="-6"/>
6170
<source>Select &quot;python&quot; or &quot;javascript&quot;.</source>
6271
<translation>Выберите &quot;python&quot; или &quot;javascript&quot;.</translation>
6372
</message>
@@ -89,7 +98,7 @@ In background mode the session will be terminated just after the execution ended
8998
<context>
9099
<name>twoDModel::Runner</name>
91100
<message>
92-
<location filename="../../../../plugins/robots/checker/twoDModelRunner/runner.cpp" line="+234"/>
101+
<location filename="../../../../plugins/robots/checker/twoDModelRunner/runner.cpp" line="+239"/>
93102
<source>Robot console</source>
94103
<translation>Консоль робота</translation>
95104
</message>

0 commit comments

Comments
 (0)