Search in sources :

Example 1 with PhysicalLocationReporter

use of jmri.PhysicalLocationReporter in project JMRI by JMRI.

the class VSDecoderManager method blockPropertyChange.

public void blockPropertyChange(PropertyChangeEvent event) {
    // Needs to check the ID on the event, look up the appropriate VSDecoder,
    // get the location of the event source, and update the decoder's location.
    // NOI18N
    @SuppressWarnings("cast") String eventName = (String) event.getPropertyName();
    if (event.getSource() instanceof PhysicalLocationReporter) {
        Block blk = (Block) event.getSource();
        String repVal = null;
        // "value" => Get loco address from event's newValue.
        if (eventName.equals("state")) {
            // to extract the address and the location.
            if ((Integer) event.getNewValue() == Block.OCCUPIED) {
                /// an idtag type reporter.
                if (blk.getReporter() == null) {
                    log.debug("Block " + blk.getSystemName() + " has no reporter!  Skipping state-type report.");
                    return;
                }
                if (blk.isReportingCurrent()) {
                    repVal = (String) blk.getReporter().getCurrentReport();
                } else {
                    repVal = (String) blk.getReporter().getLastReport();
                }
            } else {
                log.debug("Ignoring report. not an OCCUPIED event.");
                return;
            }
        } else if (eventName.equals("value")) {
            if (event.getNewValue() instanceof String) {
                repVal = event.getNewValue().toString();
            }
        // Else it will still be null from the declaration/assignment above.
        } else {
            log.debug("Not a supported Block event type.  Ignoring.");
            return;
        }
        // Set the decoder's position.
        if (repVal == null) {
            log.warn("Report from Block " + blk.getUserName() + " is null!");
        }
        if (blk.getDirection(repVal) == PhysicalLocationReporter.Direction.ENTER) {
            setDecoderPositionByAddr(blk.getLocoAddress(repVal), blk.getPhysicalLocation());
        }
        return;
    } else {
        log.debug("Reporter doesn't support physical location reporting.");
    }
    // Reporting object implements PhysicalLocationReporter
    return;
}
Also used : Block(jmri.Block) PhysicalLocationReporter(jmri.PhysicalLocationReporter)

Example 2 with PhysicalLocationReporter

use of jmri.PhysicalLocationReporter in project JMRI by JMRI.

the class ManageLocationsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (f == null || !f.isVisible()) {
        // Handle the Listener
        listenerLoc = VSDecoderManager.instance().getVSDecoderPreferences().getListenerPosition();
        // Handle Reporters
        ReporterManager rmgr = jmri.InstanceManager.getDefault(jmri.ReporterManager.class);
        String[] reporterNameArray = rmgr.getSystemNameArray();
        Object[][] reporterTable = new Object[reporterNameArray.length][6];
        reporterMap = new HashMap<String, PhysicalLocation>();
        int i = 0;
        for (String s : reporterNameArray) {
            Reporter r = rmgr.getByDisplayName(s);
            if (r instanceof PhysicalLocationReporter) {
                reporterMap.put(s, ((PhysicalLocationReporter) r).getPhysicalLocation());
                PhysicalLocation p = ((PhysicalLocationReporter) r).getPhysicalLocation();
                reporterTable[i][0] = s;
                reporterTable[i][1] = true;
                reporterTable[i][2] = p.getX();
                reporterTable[i][3] = p.getY();
                reporterTable[i][4] = p.getZ();
                reporterTable[i][5] = p.isTunnel();
            } else {
                reporterTable[i][0] = s;
                reporterTable[i][1] = false;
                reporterTable[i][2] = Float.valueOf(0.0f);
                reporterTable[i][3] = Float.valueOf(0.0f);
                reporterTable[i][4] = Float.valueOf(0.0f);
                reporterTable[i][5] = false;
            }
            i++;
        }
        // Handle Blocks
        BlockManager bmgr = jmri.InstanceManager.getDefault(jmri.BlockManager.class);
        String[] blockNameArray = bmgr.getSystemNameArray();
        Object[][] blockTable = new Object[blockNameArray.length][6];
        blockMap = new HashMap<String, PhysicalLocation>();
        i = 0;
        for (String s : blockNameArray) {
            Block b = bmgr.getByDisplayName(s);
            // NOTE: Unlike Reporters, all Blocks are (now) PhysicalLocationReporters, so no need to do a check here.
            // We'll keep the explicit cast for now, but it's not actually necessary.
            blockMap.put(s, ((PhysicalLocationReporter) b).getPhysicalLocation());
            PhysicalLocation p = ((PhysicalLocationReporter) b).getPhysicalLocation();
            blockTable[i][0] = s;
            blockTable[i][1] = true;
            blockTable[i][2] = p.getX();
            blockTable[i][3] = p.getY();
            blockTable[i][4] = p.getZ();
            blockTable[i][5] = p.isTunnel();
            i++;
        }
        // Handle Ops Locations
        LocationManager lmgr = LocationManager.instance();
        List<Location> locations = lmgr.getLocationsByIdList();
        opsMap = new HashMap<String, PhysicalLocation>();
        log.debug("TableSize : " + locations.size());
        Object[][] opsTable = new Object[locations.size()][6];
        i = 0;
        for (Location l : locations) {
            if (log.isDebugEnabled()) {
                log.debug("i = " + i + "MLA " + l.getId() + " Name: " + l.getName() + " table " + java.util.Arrays.toString(opsTable[i]));
            }
            PhysicalLocation p = l.getPhysicalLocation();
            Boolean use = false;
            if (p == PhysicalLocation.Origin) {
                use = false;
            } else {
                use = true;
            }
            opsTable[i][0] = l.getName();
            opsTable[i][1] = use;
            opsTable[i][2] = p.getX();
            opsTable[i][3] = p.getY();
            opsTable[i][4] = p.getZ();
            opsTable[i][5] = p.isTunnel();
            opsMap.put(l.getName(), l.getPhysicalLocation());
            i++;
        }
        f = new ManageLocationsFrame(listenerLoc, reporterTable, opsTable, blockTable);
    }
    f.setExtendedState(Frame.NORMAL);
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) ReporterManager(jmri.ReporterManager) PhysicalLocationReporter(jmri.PhysicalLocationReporter) Reporter(jmri.Reporter) BlockManager(jmri.BlockManager) Block(jmri.Block) PhysicalLocationReporter(jmri.PhysicalLocationReporter) PhysicalLocation(jmri.util.PhysicalLocation) PhysicalLocation(jmri.util.PhysicalLocation) Location(jmri.jmrit.operations.locations.Location)

Aggregations

Block (jmri.Block)2 PhysicalLocationReporter (jmri.PhysicalLocationReporter)2 BlockManager (jmri.BlockManager)1 Reporter (jmri.Reporter)1 ReporterManager (jmri.ReporterManager)1 Location (jmri.jmrit.operations.locations.Location)1 LocationManager (jmri.jmrit.operations.locations.LocationManager)1 PhysicalLocation (jmri.util.PhysicalLocation)1