Skip to content

Commit

Permalink
console/plugins/planning/MissionTreePanel: Adding property to avoid a…
Browse files Browse the repository at this point in the history
…sking for plan override for certain plan names.
  • Loading branch information
paulosousadias committed Jan 14, 2025
1 parent 52e7af4 commit 3b68ef2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.swing.ImageIcon;
Expand Down Expand Up @@ -104,7 +105,6 @@
import pt.lsts.neptus.types.mission.plan.PlanType;
import pt.lsts.neptus.util.ByteUtil;


/**
* Panel that holds mission objects namely plans and acoustic transponders.
*
Expand All @@ -127,13 +127,18 @@ public class MissionTreePanel extends ConsolePanel
private boolean debugOn = false;
@NeptusProperty(name = "Acceptable Elapsed Time", description = "Maximum acceptable interval between transponder ranges, in seconds.")
private int maxAcceptableElapsedTime = 600;
@NeptusProperty(name = "Plan Names to Automatically Accept Updates", description = "Comma separated values. This upon reception of a plan " +
"with the same name as the ones listed here, it will be automatically accepted the changes and replace it.")
private String planNamesToAutoAcceptUpdates = "teleoperation-mode, service_loiter";

private MissionTreeMouse mouseAdapter;
private boolean running = false;
boolean inited = false;
protected MissionBrowser browser = new MissionBrowser();
protected PlanDBControl pdbControl;

protected final List<String> planNamesToAutoAcceptUpdatesList = new ArrayList<>();

/**
* This adapter is called by a class monitoring PlanDB messages. It is only called if a PlanDB message with field
* type set to success is received.
Expand Down Expand Up @@ -318,11 +323,13 @@ public void on(PlanSpecification msg) {
}

// Non matching plans
int option = JOptionPane.showConfirmDialog(getConsole(),
I18n.text("Replace plan '" + plan.getId() + "' with version disseminated by "
+ msg.getSourceName()+"?"));
if (option != JOptionPane.YES_OPTION) {
return;
if (!planNamesToAutoAcceptUpdatesList.contains(plan.getId())) {
int option = JOptionPane.showConfirmDialog(getConsole(),
I18n.text("Replace plan '" + plan.getId() + "' with version disseminated by "
+ msg.getSourceName()+"?"));
if (option != JOptionPane.YES_OPTION) {
return;
}
}
}

Expand Down Expand Up @@ -385,6 +392,12 @@ public void propertiesChanged() {
planDBListener.setDebugOn(debugOn);
browser.setMaxAcceptableElapsedTime(maxAcceptableElapsedTime);
browser.setHideTransponder(!useTransponderFeatures);

planNamesToAutoAcceptUpdatesList.clear();
String[] pList = planNamesToAutoAcceptUpdates.split(",");
for (String p : pList) {
planNamesToAutoAcceptUpdatesList.add(p.trim());
}
}

class MissionTreeMouse extends MouseAdapter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

import javax.swing.JOptionPane;
Expand Down Expand Up @@ -61,12 +63,18 @@ public class MissionTreePlanDbAdapter extends PlanDBAdapter {
private ConsoleLayout console;
private MissionTreePanel missionTree;
private boolean debugOn = true;
private final List<String> planNamesToAutoAcceptUpdatesList = new ArrayList<>();

public MissionTreePlanDbAdapter(ConsoleLayout console, MissionTreePanel missionTree) {
this.console = console;
this.missionTree = missionTree;
}


public void updatePlanNamesToAutoAcceptUpdatesList(List<String> planNamesToAutoAcceptUpdatesList) {
this.planNamesToAutoAcceptUpdatesList.clear();
this.planNamesToAutoAcceptUpdatesList.addAll(planNamesToAutoAcceptUpdatesList);
}

// Called only if Type == SUCCESS in received PlanDB message
@Override
public void dbCleared() {
Expand Down Expand Up @@ -114,10 +122,12 @@ public void dbPlanReceived(PlanType spec) {
PlanSpecification local = (PlanSpecification) console.getMission().getIndividualPlansList()
.get(spec.getId()).asIMCPlan();
if (!ByteUtil.equal(local.payloadMD5(), remote.payloadMD5())) {
int option = JOptionPane.showConfirmDialog(console,
I18n.text("Replace plan '" + spec.getId() + "' with received version?"));
if (option != JOptionPane.YES_OPTION)
return;
if (!planNamesToAutoAcceptUpdatesList.contains(spec.getId())) {
int option = JOptionPane.showConfirmDialog(console,
I18n.text("Replace plan '" + spec.getId() + "' with received version?"));
if (option != JOptionPane.YES_OPTION)
return;
}
}
}

Expand Down

0 comments on commit 3b68ef2

Please sign in to comment.