Search in sources :

Example 6 with SceneGraphNode

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

the class SearchDialog method checkString.

private boolean checkString(String text, ISceneGraph sg) {
    try {
        if (sg.containsNode(text)) {
            SceneGraphNode node = sg.getNode(text);
            if (node instanceof IFocus) {
                IFocus focus = ((IFocus) node).getFocus(text);
                boolean timeOverflow = focus.isCoordinatesTimeOverflow();
                boolean canSelect = !(focus instanceof ParticleGroup) || ((ParticleGroup) focus).canSelect();
                boolean ctOn = GaiaSky.instance.isOn(focus.getCt());
                Optional<CatalogInfo> ci = GaiaSky.instance.getCatalogInfoFromObject(node);
                boolean datasetVisible = ci.isEmpty() || ci.get().isVisible(true);
                if (!timeOverflow && canSelect && ctOn && datasetVisible) {
                    GaiaSky.postRunnable(() -> {
                        EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE, true);
                        EventManager.publish(Event.FOCUS_CHANGE_CMD, this, focus, true);
                    });
                    info(null);
                } else if (timeOverflow) {
                    info(I18n.txt("gui.objects.search.timerange", text));
                } else if (!canSelect) {
                    info(I18n.txt("gui.objects.search.filter", text));
                } else if (!datasetVisible) {
                    info(I18n.txt("gui.objects.search.dataset.invisible", text, ci.get().name));
                } else {
                    info(I18n.txt("gui.objects.search.invisible", text, focus.getCt().toString()));
                }
                return true;
            }
        } else {
            info(null);
        }
    } catch (Exception e) {
        logger.error(e);
    }
    return false;
}
Also used : SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) ParticleGroup(gaiasky.scenegraph.ParticleGroup) CatalogInfo(gaiasky.util.CatalogInfo) IFocus(gaiasky.scenegraph.IFocus)

Example 7 with SceneGraphNode

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

the class TopInfoInterface method notify.

@Override
public void notify(final Event event, Object source, final Object... data) {
    switch(event) {
        case TIME_CHANGE_INFO:
        case TIME_CHANGE_CMD:
            // Update input time
            Instant datetime = (Instant) data[0];
            GaiaSky.postRunnable(() -> {
                date.setText(dfDate.format(datetime));
                time.setText(dfTime.format(datetime) + " UTC");
                pack();
            });
            break;
        case TIME_WARP_CHANGED_INFO:
            if (data.length == 1)
                pace.setText("(" + TextUtils.getFormattedTimeWarp((double) data[0]) + ")");
            break;
        case TIME_STATE_CMD:
            Boolean t = (Boolean) data[0];
            if (!t) {
                pace.setText("(" + I18n.txt("gui.top.time.off") + ")");
            } else {
                pace.setText("(" + TextUtils.getFormattedTimeWarp() + ")");
            }
            break;
        case CAMERA_CLOSEST_INFO:
            IFocus closestObject = (IFocus) data[0];
            if (closestObject != null) {
                closest.setText(TextUtils.capString(closestObject.getClosestName(), maxNameLen));
                closest.setText(I18n.txt("gui.top.closest", closest.getText()));
            } else {
                closest.setText("");
            }
            break;
        case CAMERA_MODE_CMD:
            CameraMode mode = (CameraMode) data[0];
            if (!mode.isFocus()) {
                focus.setText("");
                s1.setText("");
            } else {
                focus.setText(I18n.txt("gui.top.focus", lastFocusName));
                s1.setText("|");
            }
            break;
        case FOCUS_CHANGE_CMD:
            IFocus f = null;
            if (data[0] instanceof String) {
                SceneGraphNode sgn = GaiaSky.instance.sceneGraph.getNode((String) data[0]);
                if (sgn instanceof IFocus)
                    f = (IFocus) sgn;
            } else {
                f = (IFocus) data[0];
            }
            if (f != null) {
                String candidate = f.getCandidateName();
                lastFocusName = TextUtils.capString(candidate, maxNameLen);
                focus.setText(I18n.txt("gui.top.focus", lastFocusName));
                s1.setText("|");
            }
            break;
        default:
            break;
    }
}
Also used : Instant(java.time.Instant) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) CameraMode(gaiasky.scenegraph.camera.CameraManager.CameraMode) IFocus(gaiasky.scenegraph.IFocus)

Example 8 with SceneGraphNode

use of gaiasky.scenegraph.SceneGraphNode 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 9 with SceneGraphNode

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

the class SceneGraphJsonLoader method loadSceneGraph.

public static synchronized ISceneGraph loadSceneGraph(FileHandle[] jsonFiles, ITimeFrameProvider time, boolean multithreading, int maxThreads) throws FileNotFoundException, ReflectionException {
    ISceneGraph sg;
    logger.info(I18n.txt("notif.loading", "JSON data descriptor files:"));
    for (FileHandle fh : jsonFiles) {
        logger.info("\t" + fh.path() + " - exists: " + fh.exists());
        if (!fh.exists()) {
            logger.error(I18n.txt("error.loading.notexistent", fh.path()));
        }
    }
    Array<SceneGraphNode> nodes = new Array<>(false, 20600);
    for (FileHandle jsonFile : jsonFiles) {
        nodes.addAll(loadJsonFile(jsonFile));
    }
    // Initialize nodes and look for octrees
    boolean hasOctree = false;
    boolean hasStarGroup = false;
    for (SceneGraphNode node : nodes) {
        node.initialize();
        if (node instanceof AbstractOctreeWrapper) {
            hasOctree = true;
            AbstractOctreeWrapper aow = (AbstractOctreeWrapper) node;
            if (aow.children != null)
                for (SceneGraphNode n : aow.children) {
                    if (n instanceof StarGroup) {
                        hasStarGroup = true;
                        break;
                    }
                }
        }
        if (node instanceof StarGroup)
            hasStarGroup = true;
    }
    sg = SceneGraphImplementationProvider.provider.getImplementation(multithreading, hasOctree, hasStarGroup, maxThreads, nodes.size);
    sg.initialize(nodes, time, hasOctree, hasStarGroup);
    return sg;
}
Also used : Array(com.badlogic.gdx.utils.Array) ISceneGraph(gaiasky.scenegraph.ISceneGraph) FileHandle(com.badlogic.gdx.files.FileHandle) StarGroup(gaiasky.scenegraph.StarGroup) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) AbstractOctreeWrapper(gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)

Example 10 with SceneGraphNode

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

the class ControllerGui method checkString.

public boolean checkString(String text, ISceneGraph sg) {
    try {
        if (sg.containsNode(text)) {
            SceneGraphNode node = sg.getNode(text);
            if (node instanceof IFocus) {
                IFocus focus = ((IFocus) node).getFocus(text);
                boolean timeOverflow = focus.isCoordinatesTimeOverflow();
                boolean canSelect = !(focus instanceof ParticleGroup) || ((ParticleGroup) focus).canSelect();
                boolean ctOn = GaiaSky.instance.isOn(focus.getCt());
                if (!timeOverflow && canSelect && ctOn) {
                    GaiaSky.postRunnable(() -> {
                        EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE, true);
                        EventManager.publish(Event.FOCUS_CHANGE_CMD, this, focus, true);
                    });
                    info(null);
                } else if (timeOverflow) {
                    info(I18n.txt("gui.objects.search.timerange", text));
                } else if (!canSelect) {
                    info(I18n.txt("gui.objects.search.filter", text));
                } else {
                    info(I18n.txt("gui.objects.search.invisible", text, focus.getCt().toString()));
                }
                return true;
            }
        } else {
            info(null);
        }
    } catch (Exception e) {
        logger.error(e);
    }
    return false;
}
Also used : SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) ParticleGroup(gaiasky.scenegraph.ParticleGroup) IFocus(gaiasky.scenegraph.IFocus)

Aggregations

SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)25 Array (com.badlogic.gdx.utils.Array)7 IFocus (gaiasky.scenegraph.IFocus)6 StarGroup (gaiasky.scenegraph.StarGroup)5 ParticleGroup (gaiasky.scenegraph.ParticleGroup)4 ArrayList (java.util.ArrayList)4 Actor (com.badlogic.gdx.scenes.scene2d.Actor)3 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)3 FadeNode (gaiasky.scenegraph.FadeNode)3 ISceneGraph (gaiasky.scenegraph.ISceneGraph)3 IOException (java.io.IOException)3 FileHandle (com.badlogic.gdx.files.FileHandle)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 NaturalCamera (gaiasky.scenegraph.camera.NaturalCamera)2 AbstractOctreeWrapper (gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)2 IParticleRecord (gaiasky.scenegraph.particle.IParticleRecord)2 CatalogInfo (gaiasky.util.CatalogInfo)2 OwnLabel (gaiasky.util.scene2d.OwnLabel)2 Lwjgl3Graphics (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1