@@ -30,6 +30,13 @@ std::pair<Interpreter::ExecResult, eval_result_t> Interpreter::dostring(const st
3030 }
3131}
3232
33+ QTextCharFormat format (Qt::GlobalColor bg_color, Qt::GlobalColor fg_color = Qt::white) {
34+ QTextCharFormat fmt;
35+ fmt.setBackground (bg_color);
36+ fmt.setForeground (fg_color);
37+ return fmt;
38+ }
39+
3340void VisualizationInterpreter::run_script (std::string& script) {
3441 if (is_running.exchange (true )) { // avoid running scripts in parallel
3542 return ;
@@ -114,7 +121,27 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
114121 args[2 ].source .get (),
115122 args[3 ].source .get (),
116123 [x_source = args[0 ].source , y_source = args[1 ].source , z_source = args[2 ].source , psi_source = args[3 ].source , this , tokens = parser.tokens , original_psi = get<double >(args[3 ])](const auto & feedback) mutable {
117- if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP) {
124+ if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK) {
125+ vector<LuaToken> tokens;
126+ signal.removeFormatting ();
127+
128+ if (x_source) {
129+ signal.highlightTokens (x_source->get_all_tokens (), format (Qt::red));
130+ }
131+
132+ if (y_source) {
133+ signal.highlightTokens (y_source->get_all_tokens (), format (Qt::darkGreen));
134+ }
135+
136+ if (z_source) {
137+ signal.highlightTokens (z_source->get_all_tokens (), format (Qt::blue));
138+ }
139+
140+ if (psi_source) {
141+ signal.highlightTokens (psi_source->get_all_tokens (), format (Qt::darkCyan));
142+ }
143+
144+ } else if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP) {
118145 auto changes = make_shared<lua::rt::SourceChangeAnd>();
119146 if (x_source && feedback->control_name == " move_x" ) {
120147 if (const auto & change = x_source->forceValue (feedback->pose .position .x ))
@@ -134,11 +161,13 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
134161 }
135162
136163 // apply and highlight changes
137- signal.removeFormatting ();
138- QTextCharFormat fmt;
139- fmt.setBackground (Qt::red);
140- fmt.setForeground (Qt::white);
141- signal.applySourceChanges (changes, fmt);
164+ if (feedback->control_name != " clicked" ) {
165+ signal.removeFormatting ();
166+ QTextCharFormat fmt;
167+ fmt.setBackground (Qt::red);
168+ fmt.setForeground (Qt::white);
169+ signal.applySourceChanges (changes, fmt);
170+ }
142171 }
143172 });
144173
@@ -286,6 +315,10 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
286315 return false ;
287316 }
288317
318+ vector<LuaToken> get_all_tokens () const override {
319+ return {};
320+ }
321+
289322 SignalObject& signal;
290323 string id;
291324 string field;
@@ -309,7 +342,23 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
309342 marker.addPoint (get<double >(args[0 ]), get<double >(args[1 ]), get<double >(args[2 ]),
310343 args[0 ].source .get (), args[1 ].source .get (), args[2 ].source .get (),
311344 [x_source = args[0 ].source , y_source = args[1 ].source , z_source = args[2 ].source , this , tokens = parser.tokens ](const auto & feedback) mutable {
312- if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP) {
345+ if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK) {
346+ vector<LuaToken> tokens;
347+ signal.removeFormatting ();
348+
349+ if (x_source) {
350+ signal.highlightTokens (x_source->get_all_tokens (), format (Qt::red));
351+ }
352+
353+ if (y_source) {
354+ signal.highlightTokens (y_source->get_all_tokens (), format (Qt::darkGreen));
355+ }
356+
357+ if (z_source) {
358+ signal.highlightTokens (z_source->get_all_tokens (), format (Qt::blue));
359+ }
360+
361+ } else if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP) {
313362 auto changes = make_shared<lua::rt::SourceChangeAnd>();
314363 if (x_source && feedback->control_name == " move_x" ) {
315364 if (const auto & change = x_source->forceValue (feedback->pose .position .x ))
@@ -325,11 +374,13 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
325374 }
326375
327376 // apply and highlight changes
328- signal.removeFormatting ();
329- QTextCharFormat fmt;
330- fmt.setBackground (Qt::red);
331- fmt.setForeground (Qt::white);
332- signal.applySourceChanges (changes, fmt);
377+ if (feedback->control_name != " clicked" ) {
378+ signal.removeFormatting ();
379+ QTextCharFormat fmt;
380+ fmt.setBackground (Qt::red);
381+ fmt.setForeground (Qt::white);
382+ signal.applySourceChanges (changes, fmt);
383+ }
333384 }
334385 });
335386 return {};
@@ -355,7 +406,27 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
355406 marker.addPose (get<double >(args[0 ]), get<double >(args[1 ]), get<double >(args[2 ]), get<double >(args[3 ]),
356407 args[0 ].source .get (), args[1 ].source .get (), args[2 ].source .get (), args[3 ].source .get (),
357408 [x_source = args[0 ].source , y_source = args[1 ].source , z_source = args[2 ].source , psi_source = args[3 ].source , this , tokens = parser.tokens , original_psi = get<double >(args[3 ])](const auto & feedback) mutable {
358- if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP) {
409+ if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK) {
410+ vector<LuaToken> tokens;
411+ signal.removeFormatting ();
412+
413+ if (x_source) {
414+ signal.highlightTokens (x_source->get_all_tokens (), format (Qt::red));
415+ }
416+
417+ if (y_source) {
418+ signal.highlightTokens (y_source->get_all_tokens (), format (Qt::darkGreen));
419+ }
420+
421+ if (z_source) {
422+ signal.highlightTokens (z_source->get_all_tokens (), format (Qt::blue));
423+ }
424+
425+ if (psi_source) {
426+ signal.highlightTokens (psi_source->get_all_tokens (), format (Qt::darkCyan));
427+ }
428+
429+ } else if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP) {
359430 auto changes = make_shared<lua::rt::SourceChangeAnd>();
360431 if (x_source && feedback->control_name == " move_x" ) {
361432 if (const auto & change = x_source->forceValue (feedback->pose .position .x ))
@@ -375,11 +446,13 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
375446 }
376447
377448 // apply and highlight changes
378- signal.removeFormatting ();
379- QTextCharFormat fmt;
380- fmt.setBackground (Qt::red);
381- fmt.setForeground (Qt::white);
382- signal.applySourceChanges (changes, fmt);
449+ if (feedback->control_name != " clicked" ) {
450+ signal.removeFormatting ();
451+ QTextCharFormat fmt;
452+ fmt.setBackground (Qt::red);
453+ fmt.setForeground (Qt::white);
454+ signal.applySourceChanges (changes, fmt);
455+ }
383456 }
384457 });
385458 return {};
@@ -432,7 +505,7 @@ void LiveScriptInterpreter::populate_live_env(lua::rt::Environment &env, const A
432505 return {nil ()};
433506 }
434507
435- signal.highlightTokens (stmt.tokens );
508+ signal.highlightTokens (stmt.tokens , format (Qt::magenta) );
436509
437510 std::this_thread::sleep_for (chrono::milliseconds (static_cast <long >(get<double >(args[0 ])*1000 )));
438511
@@ -448,7 +521,7 @@ void LiveScriptInterpreter::populate_live_env(lua::rt::Environment &env, const A
448521 return {nil ()};
449522 }
450523
451- signal.highlightTokens (stmt.tokens );
524+ signal.highlightTokens (stmt.tokens , format (Qt::magenta) );
452525
453526 while (!quad.is_at_target ()) {
454527 if (*cancelled)
0 commit comments