Search in sources :

Example 1 with PhysicalLocation

use of jmri.util.PhysicalLocation 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)

Example 2 with PhysicalLocation

use of jmri.util.PhysicalLocation in project JMRI by JMRI.

the class VSDecoder method propertyChange.

/**
     * Respond to property change events from this VSDecoder's GUI
     *
     * @param evt (PropertyChangeEvent) event to respond to
     */
@SuppressWarnings("cast")
@Override
public void propertyChange(PropertyChangeEvent evt) {
    String property = evt.getPropertyName();
    // Respond to events from the new GUI.
    if (evt.getSource() instanceof VSDControl) {
        if (property.equals(VSDControl.PCIDMap.get(VSDControl.PropertyChangeID.OPTION_CHANGE))) {
            Train selected_train = TrainManager.instance().getTrainByName((String) evt.getNewValue());
            if (selected_train != null) {
                selected_train.addPropertyChangeListener(this);
            }
        }
        return;
    }
    // Respond to events from the old GUI.
    if ((property.equals(VSDManagerFrame.PCIDMap.get(VSDManagerFrame.PropertyChangeID.MUTE))) || (property.equals(VSDecoderPane.PCIDMap.get(VSDecoderPane.PropertyChangeID.MUTE)))) {
        // Either GUI Mute button
        log.debug("VSD: Mute change. value = " + evt.getNewValue());
        Boolean b = (Boolean) evt.getNewValue();
        this.mute(b.booleanValue());
    } else if ((property.equals(VSDManagerFrame.PCIDMap.get(VSDManagerFrame.PropertyChangeID.VOLUME_CHANGE))) || (property.equals(VSDecoderPane.PCIDMap.get(VSDecoderPane.PropertyChangeID.VOLUME_CHANGE)))) {
        // Either GUI Volume slider
        log.debug("VSD: Volume change. value = " + evt.getNewValue());
        // Slider gives integer 0-100. Need to change that to a float 0.0-1.0
        this.setMasterVolume((1.0f * (Integer) evt.getNewValue()) / 100.0f);
    } else if (property.equals(VSDecoderPane.PCIDMap.get(VSDecoderPane.PropertyChangeID.ADDRESS_CHANGE))) {
        // OLD GUI Address Change
        log.debug("Decoder set address = " + (LocoAddress) evt.getNewValue());
        this.setAddress((LocoAddress) evt.getNewValue());
        this.enable();
    } else if (property.equals(Train.TRAIN_LOCATION_CHANGED_PROPERTY)) {
        // Train Location Move (either GUI)
        PhysicalLocation p = getTrainPosition((Train) evt.getSource());
        if (p != null) {
            this.setPosition(getTrainPosition((Train) evt.getSource()));
        } else {
            log.debug("Train has null position");
            this.setPosition(new PhysicalLocation());
        }
    } else if (property.equals(Train.STATUS_CHANGED_PROPERTY)) {
        // Train Status change (either GUI)
        String status = (String) evt.getNewValue();
        log.debug("Train status changed: " + status);
        log.debug("New Location: " + getTrainPosition((Train) evt.getSource()));
        if ((status.startsWith(Train.BUILT)) || (status.startsWith(Train.PARTIAL_BUILT))) {
            log.debug("Train built. status = " + status);
            PhysicalLocation p = getTrainPosition((Train) evt.getSource());
            if (p != null) {
                this.setPosition(getTrainPosition((Train) evt.getSource()));
            } else {
                log.debug("Train has null position");
                this.setPosition(new PhysicalLocation());
            }
        }
    }
}
Also used : DccLocoAddress(jmri.DccLocoAddress) LocoAddress(jmri.LocoAddress) VSDControl(jmri.jmrit.vsdecoder.swing.VSDControl) Train(jmri.jmrit.operations.trains.Train) PhysicalLocation(jmri.util.PhysicalLocation)

Example 3 with PhysicalLocation

use of jmri.util.PhysicalLocation in project JMRI by JMRI.

the class VSDecoder method getTrainPosition.

// Methods for handling location tracking based on JMRI Operations
/**
     * Get the physical location of the given Operations Train
     *
     * @param t (Train) the Train to interrogate
     * @return PhysicalLocation location of the train
     */
protected PhysicalLocation getTrainPosition(Train t) {
    if (t == null) {
        log.debug("Train is null.");
        return (null);
    }
    RouteLocation rloc = t.getCurrentLocation();
    if (rloc == null) {
        log.debug("RouteLocation is null.");
        return (null);
    }
    Location loc = rloc.getLocation();
    if (loc == null) {
        log.debug("Location is null.");
        return (null);
    }
    return (loc.getPhysicalLocation());
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) PhysicalLocation(jmri.util.PhysicalLocation) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 4 with PhysicalLocation

use of jmri.util.PhysicalLocation in project JMRI by JMRI.

the class ManageLocationsFrame method saveTableValues.

@SuppressFBWarnings(value = "WMI_WRONG_MAP_ITERATOR", justification = "only in slow debug")
private void saveTableValues() {
    if ((Boolean) locModel.getValueAt(0, 1)) {
        listenerLoc.setLocation((Double) locModel.getValueAt(0, 2), (Double) locModel.getValueAt(0, 3), (Double) locModel.getValueAt(0, 4));
        listenerLoc.setOrientation((Double) locModel.getValueAt(0, 5), (Double) locModel.getValueAt(0, 6));
        VSDecoderManager.instance().getVSDecoderPreferences().setListenerPosition(listenerLoc);
    }
    HashMap<String, PhysicalLocation> data = reporterModel.getDataMap();
    ReporterManager mgr = jmri.InstanceManager.getDefault(jmri.ReporterManager.class);
    for (String s : data.keySet()) {
        log.debug("Reporter: " + s + " Location: " + data.get(s));
        Reporter r = mgr.getByDisplayName(s);
        PhysicalLocation.setBeanPhysicalLocation(data.get(s), r);
    }
    data = blockModel.getDataMap();
    BlockManager bmgr = jmri.InstanceManager.getDefault(jmri.BlockManager.class);
    for (String s : data.keySet()) {
        log.debug("Block: " + s + " Location: " + data.get(s));
        Block b = bmgr.getByDisplayName(s);
        PhysicalLocation.setBeanPhysicalLocation(data.get(s), b);
    }
    data = opsModel.getDataMap();
    LocationManager lmgr = LocationManager.instance();
    for (String s : data.keySet()) {
        log.debug("OpsLocation: " + s + " Location: " + data.get(s));
        Location l = lmgr.getLocationByName(s);
        l.setPhysicalLocation(data.get(s));
    }
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) ReporterManager(jmri.ReporterManager) BlockManager(jmri.BlockManager) Reporter(jmri.Reporter) Block(jmri.Block) PhysicalLocation(jmri.util.PhysicalLocation) Location(jmri.jmrit.operations.locations.Location) PhysicalLocation(jmri.util.PhysicalLocation) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 5 with PhysicalLocation

use of jmri.util.PhysicalLocation in project JMRI by JMRI.

the class RpsReporter method getPhysicalLocation.

/**
     * getPhysicalLocation(String s)
     *
     * Returns the PhysicalLocation of the Transmitter with the given ID
     *
     * Given an ID (in String form), looks up the Transmitter and gets its
     * current PhysicalLocation (translated from the RPS Measurement).
     */
public PhysicalLocation getPhysicalLocation(String s) {
    if (s.length() > 0) {
        try {
            int id = Integer.parseInt(s);
            Vector3d v = Engine.instance().getTransmitter(id).getLastMeasurement().getVector();
            return (new PhysicalLocation(new Vector3f(v)));
        } catch (NumberFormatException e) {
            return (null);
        } catch (NullPointerException e) {
            return (null);
        }
    } else {
        return (null);
    }
}
Also used : Vector3d(javax.vecmath.Vector3d) Vector3f(javax.vecmath.Vector3f) PhysicalLocation(jmri.util.PhysicalLocation)

Aggregations

PhysicalLocation (jmri.util.PhysicalLocation)5 Location (jmri.jmrit.operations.locations.Location)3 Block (jmri.Block)2 BlockManager (jmri.BlockManager)2 Reporter (jmri.Reporter)2 ReporterManager (jmri.ReporterManager)2 LocationManager (jmri.jmrit.operations.locations.LocationManager)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Vector3d (javax.vecmath.Vector3d)1 Vector3f (javax.vecmath.Vector3f)1 DccLocoAddress (jmri.DccLocoAddress)1 LocoAddress (jmri.LocoAddress)1 PhysicalLocationReporter (jmri.PhysicalLocationReporter)1 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)1 Train (jmri.jmrit.operations.trains.Train)1 VSDControl (jmri.jmrit.vsdecoder.swing.VSDControl)1