@@ -37,7 +37,7 @@ QTextCharFormat format(Qt::GlobalColor bg_color, Qt::GlobalColor fg_color = Qt::
3737 return fmt;
3838}
3939
40- void VisualizationInterpreter::run_script (std::string& script) {
40+ void VisualizationInterpreter::run_script (std::string& script, const InteractiveScriptSettings& settings ) {
4141 if (is_running.exchange (true )) { // avoid running scripts in parallel
4242 return ;
4343 }
@@ -47,7 +47,7 @@ void VisualizationInterpreter::run_script(std::string& script) {
4747
4848 auto exec_start = chrono::steady_clock::now ();
4949 Interpreter interpreter {parser};
50- populate_visualization_env (*interpreter.env , interpreter.parser );
50+ populate_visualization_env (*interpreter.env , interpreter.parser , settings );
5151 auto exec_ready = chrono::steady_clock::now ();
5252
5353 switch (auto [c, s] = interpreter.dostring (script, ps); c) {
@@ -84,7 +84,7 @@ void VisualizationInterpreter::run_script(std::string& script) {
8484 is_running.store (false );
8585}
8686
87- void VisualizationInterpreter::populate_visualization_env (Environment& env, LuaParser& parser) {
87+ void VisualizationInterpreter::populate_visualization_env (Environment& env, LuaParser& parser, const InteractiveScriptSettings& settings ) {
8888 env.assign (" __quad_pose" , make_shared<table>(
8989 vector<pair<val, val>> {{" x" , 0 },{" y" , 0 },{" z" , 0 },{" psi" , 0 }}), false );
9090
@@ -103,7 +103,7 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
103103 return {};
104104 }), false );
105105
106- env.assign (" moveTo" , make_shared<cfunction>([this , &env, &parser](const vallist& args) mutable -> cfunction::result {
106+ env.assign (" moveTo" , make_shared<cfunction>([this , &env, &parser, settings ](const vallist& args) mutable -> cfunction::result {
107107 if (args.size () == 4 && args[0 ].isnumber () && args[1 ].isnumber () && args[2 ].isnumber () && args[3 ].isnumber ()) {
108108 val target = env.getvar (" __quad_target" );
109109 table& tab_target = *get<table_p>(target);
@@ -116,12 +116,13 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
116116 get<double >(args[1 ]),
117117 get<double >(args[2 ]),
118118 get<double >(args[3 ]),
119- args[0 ].source .get (),
120- args[1 ].source .get (),
121- args[2 ].source .get (),
122- args[3 ].source .get (),
123- [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 {
124- if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK) {
119+ args[0 ].source .get () && settings.move_markers ,
120+ args[1 ].source .get () && settings.move_markers ,
121+ args[2 ].source .get () && settings.move_markers ,
122+ args[3 ].source .get () && settings.move_markers ,
123+ [x_source = args[0 ].source , y_source = args[1 ].source , z_source = args[2 ].source , psi_source = args[3 ].source ,
124+ this , settings, tokens = parser.tokens , original_psi = get<double >(args[3 ])](const auto & feedback) mutable {
125+ if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK && settings.click_for_dependency_trace ) {
125126 vector<LuaToken> tokens;
126127 signal.removeFormatting ();
127128
@@ -142,6 +143,10 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
142143 }
143144
144145 } else if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP) {
146+ if (feedback->control_name != " clicked" ) {
147+ signal.removeFormatting ();
148+ }
149+
145150 auto changes = make_shared<lua::rt::SourceChangeAnd>();
146151 if (x_source && feedback->control_name == " move_x" ) {
147152 if (const auto & change = x_source->forceValue (feedback->pose .position .x ))
@@ -162,7 +167,6 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
162167
163168 // apply and highlight changes
164169 if (feedback->control_name != " clicked" ) {
165- signal.removeFormatting ();
166170 QTextCharFormat fmt;
167171 fmt.setBackground (Qt::red);
168172 fmt.setForeground (Qt::white);
@@ -304,6 +308,8 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
304308 QString::fromStdString (field),
305309 QString::fromStdString (newval.to_string ()));
306310
311+ signal.highlightField (QString::fromStdString (id), QString::fromStdString (field));
312+
307313 return nullopt ;
308314 }
309315
@@ -316,6 +322,10 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
316322 }
317323
318324 vector<LuaToken> get_all_tokens () const override {
325+ // TODO: remove this hack
326+
327+ signal.highlightField (QString::fromStdString (id), QString::fromStdString (field));
328+
319329 return {};
320330 }
321331
@@ -334,15 +344,17 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
334344 auto rviz = make_shared<table>();
335345 env.assign (" rviz" , rviz, false );
336346
337- (*rviz)[" point" ] = make_shared<lua::rt::cfunction>([this , &parser](const lua::rt::vallist& args) -> cfunction::result {
347+ (*rviz)[" point" ] = make_shared<lua::rt::cfunction>([this , settings, &parser](const lua::rt::vallist& args) -> cfunction::result {
338348 if (args.size () != 3 || !args[0 ].isnumber () || !args[1 ].isnumber () || !args[2 ].isnumber ()) {
339349 signal.appendTerminal (" point requires 3 number arguments" );
340350 return {nil ()};
341351 }
342352 marker.addPoint (get<double >(args[0 ]), get<double >(args[1 ]), get<double >(args[2 ]),
343- args[0 ].source .get (), args[1 ].source .get (), args[2 ].source .get (),
344- [x_source = args[0 ].source , y_source = args[1 ].source , z_source = args[2 ].source , this , tokens = parser.tokens ](const auto & feedback) mutable {
345- if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK) {
353+ args[0 ].source .get () && settings.move_markers ,
354+ args[1 ].source .get () && settings.move_markers ,
355+ args[2 ].source .get () && settings.move_markers ,
356+ [x_source = args[0 ].source , y_source = args[1 ].source , z_source = args[2 ].source , this , settings, tokens = parser.tokens ](const auto & feedback) mutable {
357+ if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK && settings.click_for_dependency_trace ) {
346358 vector<LuaToken> tokens;
347359 signal.removeFormatting ();
348360
@@ -359,6 +371,10 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
359371 }
360372
361373 } else if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP) {
374+ if (feedback->control_name != " clicked" ) {
375+ signal.removeFormatting ();
376+ }
377+
362378 auto changes = make_shared<lua::rt::SourceChangeAnd>();
363379 if (x_source && feedback->control_name == " move_x" ) {
364380 if (const auto & change = x_source->forceValue (feedback->pose .position .x ))
@@ -375,7 +391,6 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
375391
376392 // apply and highlight changes
377393 if (feedback->control_name != " clicked" ) {
378- signal.removeFormatting ();
379394 QTextCharFormat fmt;
380395 fmt.setBackground (Qt::red);
381396 fmt.setForeground (Qt::white);
@@ -398,15 +413,18 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
398413 return {};
399414 });
400415
401- (*rviz)[" pose" ] = make_shared<lua::rt::cfunction>([this , &parser](const lua::rt::vallist& args) -> cfunction::result {
416+ (*rviz)[" pose" ] = make_shared<lua::rt::cfunction>([this , settings, &parser](const lua::rt::vallist& args) -> cfunction::result {
402417 if (args.size () != 4 || !args[0 ].isnumber () || !args[1 ].isnumber () || !args[2 ].isnumber () || !args[3 ].isnumber ()) {
403418 signal.appendTerminal (" pose requires 4 number arguments" );
404419 return {nil ()};
405420 }
406421 marker.addPose (get<double >(args[0 ]), get<double >(args[1 ]), get<double >(args[2 ]), get<double >(args[3 ]),
407- args[0 ].source .get (), args[1 ].source .get (), args[2 ].source .get (), args[3 ].source .get (),
408- [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 {
409- if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK) {
422+ args[0 ].source .get () && settings.move_markers ,
423+ args[1 ].source .get () && settings.move_markers ,
424+ args[2 ].source .get () && settings.move_markers ,
425+ args[3 ].source .get () && settings.move_markers ,
426+ [x_source = args[0 ].source , y_source = args[1 ].source , z_source = args[2 ].source , psi_source = args[3 ].source , this , settings, tokens = parser.tokens , original_psi = get<double >(args[3 ])](const auto & feedback) mutable {
427+ if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK && settings.click_for_dependency_trace ) {
410428 vector<LuaToken> tokens;
411429 signal.removeFormatting ();
412430
@@ -427,6 +445,10 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
427445 }
428446
429447 } else if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP) {
448+ if (feedback->control_name != " clicked" ) {
449+ signal.removeFormatting ();
450+ }
451+
430452 auto changes = make_shared<lua::rt::SourceChangeAnd>();
431453 if (x_source && feedback->control_name == " move_x" ) {
432454 if (const auto & change = x_source->forceValue (feedback->pose .position .x ))
@@ -447,7 +469,6 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
447469
448470 // apply and highlight changes
449471 if (feedback->control_name != " clicked" ) {
450- signal.removeFormatting ();
451472 QTextCharFormat fmt;
452473 fmt.setBackground (Qt::red);
453474 fmt.setForeground (Qt::white);
@@ -459,7 +480,7 @@ void VisualizationInterpreter::populate_visualization_env(Environment& env, LuaP
459480 });
460481}
461482
462- void LiveScriptInterpreter::run_script (const std::string& script) {
483+ void LiveScriptInterpreter::run_script (const std::string& script, const InteractiveScriptSettings& ) {
463484 async = Async ([this , script](const Async::cancel_t & cancelled){
464485 Interpreter interpreter {parser};
465486
0 commit comments