Skip to content

Commit

Permalink
Merge pull request #13182 from danielb987/NoDecoder
Browse files Browse the repository at this point in the history
Disable read and write for roster entries without a decoder
  • Loading branch information
bobjacobsen committed Jun 19, 2024
2 parents 99e5227 + 627b0af commit c8b56e8
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
12 changes: 12 additions & 0 deletions java/src/jmri/jmrit/symbolicprog/CvTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ public CvTableModel(JLabel status, Programmer pProgrammer) {
//addCV("1", false, false, false);
}

public void setNoDecoder() {
for (var b : _readButtons) {
b.setEnabled(false);
}
for (var b : _writeButtons) {
b.setEnabled(false);
}
for (var b : _compareButtons) {
b.setEnabled(false);
}
}

/**
* Gives access to the programmer used to reach these CVs, so you can check
* on mode, capabilities, etc.
Expand Down
30 changes: 27 additions & 3 deletions java/src/jmri/jmrit/symbolicprog/tabbedframe/PaneProgFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ abstract public class PaneProgFrame extends JmriJFrame
ArrayList<JMenu> extraMenuList = new ArrayList<>();

Programmer mProgrammer;
boolean noDecoder = false;

JMenuBar menuBar = new JMenuBar();

Expand Down Expand Up @@ -306,7 +307,10 @@ public boolean doPrompt() {

void setProgrammingGui(JPanel bottom) {
// see if programming mode is available
var tempModePane = getModePane();
JPanel tempModePane = null;
if (!noDecoder) {
tempModePane = getModePane();
}
if (tempModePane != null) {
// if so, configure programming part of GUI
// add buttons
Expand Down Expand Up @@ -548,7 +552,8 @@ void enableReadButtons() {
readAllButton.setToolTipText(Bundle.getMessage("TipReadAll"));
// check with CVTable programmer to see if read is possible
if (cvModel != null && cvModel.getProgrammer() != null
&& !cvModel.getProgrammer().getCanRead()) {
&& !cvModel.getProgrammer().getCanRead()
|| noDecoder) {
// can't read, disable the button
readChangesButton.setEnabled(false);
readAllButton.setEnabled(false);
Expand Down Expand Up @@ -681,6 +686,10 @@ public PaneProgFrame(DecoderFile pDecoderFile, @Nonnull RosterEntry pRosterEntry
pickProgrammerMode(programming);
// reset the read buttons if the mode changes
enableReadButtons();
if (noDecoder) {
writeChangesButton.setEnabled(false);
writeAllButton.setEnabled(false);
}
} else {
log.debug("Skipping programmer setup because found no programmer element");
}
Expand Down Expand Up @@ -786,6 +795,11 @@ protected void pickProgrammerMode(@Nonnull Element programming) {
Attribute a;

// set the programming attributes for DCC
if ((a = programming.getAttribute("nodecoder")) != null) {
if (a.getValue().equals("yes")) {
noDecoder = true; // No decoder in the loco
}
}
if ((a = programming.getAttribute("paged")) != null) {
if (a.getValue().equals("no")) {
paged = false;
Expand Down Expand Up @@ -855,6 +869,8 @@ protected void pickProgrammerMode(@Nonnull Element programming) {
} else if (modes.contains(ProgrammingMode.REGISTERMODE) && register) {
mProgrammer.setMode(ProgrammingMode.REGISTERMODE);
log.debug("Set to REGISTERMODE");
} else if (noDecoder) {
log.debug("No decoder");
} else {
JmriJOptionPane.showMessageDialog(
this,
Expand Down Expand Up @@ -1081,7 +1097,7 @@ public void windowClosing(java.awt.event.WindowEvent e) {
if (log.isDebugEnabled()) {
log.debug("Checking decoder dirty status. CV: {} variables:{}", cvModel.decoderDirty(), variableModel.decoderDirty());
}
if (checkDirtyDecoder()) {
if (!noDecoder && checkDirtyDecoder()) {
if (JmriJOptionPane.showConfirmDialog(this,
Bundle.getMessage("PromptCloseWindowNotWrittenDecoder"),
Bundle.getMessage("PromptChooseOne"),
Expand Down Expand Up @@ -1442,6 +1458,10 @@ public void newPane(String name, Element pane, Element modelElem, boolean enable
// create a panel to hold columns
PaneProgPane p = new PaneProgPane(this, name, pane, cvModel, variableModel, modelElem, _rosterEntry, programmerPane);
p.setOpaque(true);
if (noDecoder) {
p.setNoDecoder();
cvModel.setNoDecoder();
}
// how to handle the tab depends on whether it has contents and option setting
int index;
if (enableEmpty || !p.cvList.isEmpty() || !p.varList.isEmpty()) {
Expand Down Expand Up @@ -1571,6 +1591,10 @@ public void paneFinished() {
@Override
public void enableButtons(boolean stat) {
log.debug("enableButtons({})", stat);
if (noDecoder) {
// If we don't have a decoder, no read or write is possible
stat = false;
}
if (stat) {
enableReadButtons();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,15 @@ public PaneProgPane(PaneContainer parent, String name, Element pane, CvTableMode
}
}

public void setNoDecoder() {
readChangesButton.setEnabled(false);
readAllButton.setEnabled(false);
writeChangesButton.setEnabled(false);
writeAllButton.setEnabled(false);
confirmChangesButton.setEnabled(false);
confirmAllButton.setEnabled(false);
}

@Override
public String getName() {
return mName;
Expand Down
20 changes: 18 additions & 2 deletions xml/decoders/0NoDecoder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,25 @@
<family name="No Decoder" mfg="No Decoder">
<model model="No Decoder"/>
</family>
<programming direct="no" paged="no" register="no" ops="no"/>
<programming nodecoder="yes" direct="no" paged="no" register="no" ops="no"/>
<variables>
<xi:include href="http://jmri.org/xml/decoders/nmra/shortAddressOnly.xml"/>
<variable CV="1" comment="Short address" item="Short Address" default="0">
<shortAddressVal/>
<label>Primary Address</label>
<label xml:lang="cs">Základní adresa</label>
<label xml:lang="it">Indirizzo Primario</label>
<label xml:lang="fr">Adresse décodeur</label>
<label xml:lang="de">Basisadresse</label>
<label xml:lang="nl">Basisadres</label>
<label xml:lang="es">Dirección primaria</label>
<tooltip xml:lang="cs">Krátká adresa</tooltip>
<tooltip xml:lang="it">Indirizzo Corto</tooltip>
<tooltip xml:lang="fr">Adresse courte</tooltip>
<tooltip xml:lang="de">Kurze Adresse</tooltip>
<tooltip xml:lang="nl">Kort Adres</tooltip>
<tooltip xml:lang="es">Dirección corta</tooltip>
<tooltip xml:lang="de">Kurze Adresse</tooltip>
</variable>
</variables>
</decoder>
</decoder-config>
6 changes: 6 additions & 0 deletions xml/schema/decoder-4-15-2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="nodecoder" type="yesNoType" default="no">
<xs:annotation><xs:documentation>
Yes indicates no decoder in loco. If so, it's
recommended that the other modes are all "no".
</xs:documentation></xs:annotation>
</xs:attribute>
<xs:attribute name="paged" type="yesNoType" default="yes">
<xs:annotation><xs:documentation>
Yes indicates programmer supports Paged mode,
Expand Down

0 comments on commit c8b56e8

Please sign in to comment.