Search in sources :

Example 1 with FadeNode

use of gaiasky.scenegraph.FadeNode in project gaiasky by langurmonkey.

the class SAMPClient method initialize.

public void initialize(final Skin skin) {
    // Disable logging
    java.util.logging.Logger.getLogger("org.astrogrid.samp").setLevel(Level.OFF);
    // Init map
    idToNode = new TwoWayHashmap<>();
    idToUrl = new HashMap<>();
    ClientProfile cp = DefaultClientProfile.getProfile();
    conn = new GaiaSkyHubConnector(cp);
    // Configure it with metadata about this application
    Metadata meta = new Metadata();
    meta.setName(Settings.APPLICATION_NAME);
    meta.setDescriptionText("3D Universe application focused on ESA's Gaia satellite");
    meta.setDocumentationUrl(Settings.DOCUMENTATION);
    meta.setIconUrl(Settings.ICON_URL.replaceAll("[^\\x00-\\x7F]", "?"));
    meta.put("author.name", Settings.AUTHOR_NAME_PLAIN);
    meta.put("author.email", Settings.AUTHOR_EMAIL);
    meta.put("author.affiliation", Settings.AUTHOR_AFFILIATION_PLAIN);
    meta.put("home.page", Settings.WEBPAGE);
    meta.put("gaiasky.version", Settings.settings.version.version);
    conn.declareMetadata(meta);
    // Load table
    conn.addMessageHandler(new AbstractMessageHandler("table.load.votable") {

        public Map<Object, Object> processCall(HubConnection c, String senderId, Message msg) {
            // do stuff
            String name = (String) msg.getParam("name");
            String id = (String) msg.getParam("table-id");
            String url = (String) msg.getParam("url");
            boolean loaded = loadVOTable(url, id, name, skin);
            if (!loaded) {
                logger.info(I18n.txt("samp.error.votable", name));
            }
            return null;
        }
    });
    // Select one row
    conn.addMessageHandler(new AbstractMessageHandler("table.highlight.row") {

        public Map<Object, Object> processCall(HubConnection c, String senderId, Message msg) {
            // do stuff
            long row = Parser.parseLong((String) msg.getParam("row"));
            String id = (String) msg.getParam("table-id");
            // First, fetch table if not here
            boolean loaded = idToNode.containsKey(id);
            // If table here, select
            if (loaded) {
                logger.info("Select row " + row + " of " + id);
                if (idToNode.containsKey(id)) {
                    if (idToNode.getForward(id) instanceof ParticleGroup) {
                        // Stars or particles
                        ParticleGroup pg = (ParticleGroup) idToNode.getForward(id);
                        pg.setFocusIndex((int) row);
                        preventProgrammaticEvents = true;
                        EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE);
                        EventManager.publish(Event.FOCUS_CHANGE_CMD, this, pg);
                        preventProgrammaticEvents = false;
                    } else if (idToNode.getForward(id) != null) {
                        // Star cluster
                        FadeNode fn = idToNode.getForward(id);
                        if (fn.children != null && fn.children.size > (int) row) {
                            SceneGraphNode sgn = fn.children.get((int) row);
                            preventProgrammaticEvents = true;
                            EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE);
                            EventManager.publish(Event.FOCUS_CHANGE_CMD, this, sgn);
                            preventProgrammaticEvents = false;
                        } else {
                            logger.info("Star cluster to select not found: " + row);
                        }
                    }
                }
            }
            return null;
        }
    });
    // Select multiple rows
    conn.addMessageHandler(new AbstractMessageHandler("table.select.rowList") {

        public Map<Object, Object> processCall(HubConnection c, String senderId, Message msg) {
            // do stuff
            ArrayList<String> rows = (ArrayList<String>) msg.getParam("row-list");
            String id = (String) msg.getParam("table-id");
            // First, fetch table if not here
            boolean loaded = idToNode.containsKey(id);
            // If table here, select
            if (loaded && rows != null && !rows.isEmpty()) {
                logger.info("Select " + rows.size() + " rows of " + id + ". Gaia Sky does not support multiple selection, so only the first entry is selected.");
                // We use the first one, as multiple selections are not supported in Gaia Sky
                int row = Integer.parseInt(rows.get(0));
                if (idToNode.containsKey(id)) {
                    FadeNode fn = idToNode.getForward(id);
                    if (fn instanceof ParticleGroup) {
                        ParticleGroup pg = (ParticleGroup) fn;
                        pg.setFocusIndex(row);
                        preventProgrammaticEvents = true;
                        EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraManager.CameraMode.FOCUS_MODE);
                        EventManager.publish(Event.FOCUS_CHANGE_CMD, this, pg);
                        preventProgrammaticEvents = false;
                    }
                }
            }
            return null;
        }
    });
    // Point in sky
    conn.addMessageHandler(new AbstractMessageHandler("coord.pointAt.sky") {

        public Map<Object, Object> processCall(HubConnection c, String senderId, Message msg) {
            // do stuff
            double ra = Parser.parseDouble((String) msg.getParam("ra"));
            double dec = Parser.parseDouble((String) msg.getParam("dec"));
            logger.info("Point to coordinate (ra,dec): (" + ra + ", " + dec + ")");
            EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FREE_MODE);
            EventManager.publish(Event.FREE_MODE_COORD_CMD, this, ra, dec);
            return null;
        }
    });
    // This step required even if no custom message handlers added.
    conn.declareSubscriptions(conn.computeSubscriptions());
    // Keep a look out for hubs if initial one shuts down
    conn.setAutoconnect(10);
}
Also used : Message(org.astrogrid.samp.Message) ParticleGroup(gaiasky.scenegraph.ParticleGroup) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) Metadata(org.astrogrid.samp.Metadata) ArrayList(java.util.ArrayList) FadeNode(gaiasky.scenegraph.FadeNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with FadeNode

use of gaiasky.scenegraph.FadeNode in project gaiasky by langurmonkey.

the class ConstellationsLoader method loadData.

@Override
public Array<? extends SceneGraphNode> loadData() {
    Array<SceneGraphNode> constellations = new Array<>();
    for (String f : files) {
        try {
            // Add fade node
            FadeNode constellationsFadeNode = new FadeNode();
            constellationsFadeNode.setPosition(new double[] { 0, 0, 0 });
            constellationsFadeNode.setCt(new String[] { "Constellations" });
            constellationsFadeNode.setFadeout(new double[] { 1.0e2, 2.0e4 });
            constellationsFadeNode.setParent(SceneGraphNode.ROOT_NAME);
            constellationsFadeNode.setName("Constellations");
            constellations.add(constellationsFadeNode);
            // load constellations
            FileHandle file = Settings.settings.data.dataFileHandle(f);
            BufferedReader br = new BufferedReader(new InputStreamReader(file.read()));
            try {
                // Skip first line
                String lastName = "";
                Array<int[]> partial = null;
                int lastid = -1;
                String line;
                String name = null;
                ComponentTypes ct = new ComponentTypes(ComponentType.Constellations);
                while ((line = br.readLine()) != null) {
                    if (!line.startsWith("#")) {
                        String[] tokens = line.split(separator);
                        name = tokens[0].trim();
                        if (!lastName.isEmpty() && !name.equals("JUMP") && !name.equals(lastName)) {
                            // We finished a constellation object
                            Constellation cons = new Constellation(lastName, "Constellations");
                            cons.ct = ct;
                            cons.ids = partial;
                            constellations.add(cons);
                            partial = null;
                            lastid = -1;
                        }
                        if (partial == null) {
                            partial = new Array<>();
                        }
                        // Break point sequence
                        if (name.equals("JUMP") && tokens[1].trim().equals("JUMP")) {
                            lastid = -1;
                        } else {
                            int newid = Parser.parseInt(tokens[1].trim());
                            if (lastid > 0) {
                                partial.add(new int[] { lastid, newid });
                            }
                            lastid = newid;
                            lastName = name;
                        }
                    }
                }
                // Add last
                if (!lastName.isEmpty() && !name.equals("JUMP")) {
                    // We finished a constellation object
                    Constellation cons = new Constellation(lastName, "Constellations");
                    cons.ct = ct;
                    cons.ids = partial;
                    constellations.add(cons);
                }
            } catch (IOException e) {
                Logger.getLogger(this.getClass()).error(e);
            }
        } catch (Exception e) {
            Logger.getLogger(this.getClass()).error(e);
        }
    }
    Logger.getLogger(this.getClass()).info(I18n.txt("notif.constellations.init", constellations.size));
    return constellations;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileHandle(com.badlogic.gdx.files.FileHandle) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) ComponentTypes(gaiasky.render.ComponentTypes) IOException(java.io.IOException) IOException(java.io.IOException) Array(com.badlogic.gdx.utils.Array) Constellation(gaiasky.scenegraph.Constellation) BufferedReader(java.io.BufferedReader) FadeNode(gaiasky.scenegraph.FadeNode)

Example 3 with FadeNode

use of gaiasky.scenegraph.FadeNode in project gaiasky by langurmonkey.

the class UpdaterTask method call.

@Override
public Void call() throws Exception {
    int size = nodes.size;
    for (int i = start; i < size; i += step) {
        SceneGraphNode node = nodes.get(i);
        float opacity = node instanceof Particle && node.octant != null ? node.octant.opacity : (node instanceof FadeNode ? 1f : node.opacity);
        node.update(time, node.parent.translation, camera, opacity);
    }
    return null;
}
Also used : Particle(gaiasky.scenegraph.Particle) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) FadeNode(gaiasky.scenegraph.FadeNode)

Example 4 with FadeNode

use of gaiasky.scenegraph.FadeNode in project gaiasky by langurmonkey.

the class SAMPClient method notify.

@Override
public void notify(final Event event, Object source, final Object... data) {
    switch(event) {
        case FOCUS_CHANGED:
            if (!preventProgrammaticEvents) {
                if (conn != null && conn.isConnected()) {
                    if (data[0] instanceof ParticleGroup) {
                        ParticleGroup pg = (ParticleGroup) data[0];
                        if (idToNode.containsValue(pg)) {
                            String id = idToNode.getBackward(pg);
                            String url = idToUrl.get(id);
                            int row = pg.getCandidateIndex();
                            Message msg = new Message("table.highlight.row");
                            msg.addParam("row", Integer.toString(row));
                            msg.addParam("table-id", id);
                            msg.addParam("url", url);
                            try {
                                conn.getConnection().notifyAll(msg);
                            } catch (SampException e) {
                                logger.error(e);
                            }
                        }
                    } else if (data[0] instanceof StarCluster) {
                        StarCluster sc = (StarCluster) data[0];
                        if (sc.parent instanceof FadeNode) {
                            // Comes from a catalog
                            FadeNode parent = (FadeNode) sc.parent;
                            if (idToNode.containsValue(parent)) {
                                String id = idToNode.getBackward(parent);
                                String url = idToUrl.get(id);
                                int row = parent.children.indexOf(sc, true);
                                Message msg = new Message("table.highlight.row");
                                msg.addParam("row", Integer.toString(row));
                                msg.addParam("table-id", id);
                                msg.addParam("url", url);
                                try {
                                    conn.getConnection().notifyAll(msg);
                                } catch (SampException e) {
                                    logger.error(e);
                                }
                            }
                        }
                    }
                }
            }
            break;
        case CATALOG_REMOVE:
            String dsName = (String) data[0];
            if (idToNode.containsKey(dsName)) {
                idToNode.removeKey(dsName);
            }
            idToUrl.remove(dsName);
            break;
        case DISPOSE:
            if (conn != null) {
                conn.setActive(false);
            }
            break;
    }
}
Also used : Message(org.astrogrid.samp.Message) ParticleGroup(gaiasky.scenegraph.ParticleGroup) FadeNode(gaiasky.scenegraph.FadeNode) StarCluster(gaiasky.scenegraph.StarCluster)

Aggregations

FadeNode (gaiasky.scenegraph.FadeNode)4 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)3 ParticleGroup (gaiasky.scenegraph.ParticleGroup)2 Message (org.astrogrid.samp.Message)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 Array (com.badlogic.gdx.utils.Array)1 ComponentTypes (gaiasky.render.ComponentTypes)1 Constellation (gaiasky.scenegraph.Constellation)1 Particle (gaiasky.scenegraph.Particle)1 StarCluster (gaiasky.scenegraph.StarCluster)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Metadata (org.astrogrid.samp.Metadata)1