Search in sources :

Example 6 with IFocus

use of gaiasky.scenegraph.IFocus 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 IFocus

use of gaiasky.scenegraph.IFocus 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 IFocus

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

the class NaturalMouseKbdListener method getHits.

private Array<IFocus> getHits(int screenX, int screenY) {
    Array<IFocus> l = GaiaSky.instance.getFocusableEntities();
    Array<IFocus> hits = new Array<>();
    // Add all hits
    for (IFocus s : l) {
        s.addHit(screenX, screenY, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), MIN_PIX_DIST, camera, hits);
    }
    return hits;
}
Also used : Array(com.badlogic.gdx.utils.Array) IFocus(gaiasky.scenegraph.IFocus)

Example 9 with IFocus

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

the class NotificationsInterface method notify.

@Override
public void notify(final Event event, Object source, final Object... data) {
    synchronized (lock) {
        switch(event) {
            case POST_NOTIFICATION:
                LoggerLevel level = (LoggerLevel) data[0];
                Object[] dat = (Object[]) data[1];
                String message = "";
                boolean perm = false;
                for (int i = 0; i < dat.length; i++) {
                    if (i == dat.length - 1 && dat[i] instanceof Boolean) {
                        perm = (Boolean) dat[i];
                    } else {
                        message += dat[i].toString();
                        if (i < dat.length - 1 && !(i == dat.length - 2 && dat[dat.length - 1] instanceof Boolean)) {
                            message += TAG_SEPARATOR;
                        }
                    }
                }
                addMessage(message, perm, level);
                break;
            case FOCUS_CHANGED:
                if (data[0] != null) {
                    IFocus sgn = null;
                    if (data[0] instanceof String) {
                        sgn = GaiaSky.instance.sceneGraph.findFocus((String) data[0]);
                    } else {
                        sgn = (IFocus) data[0];
                    }
                    addMessage(I18n.txt("notif.camerafocus", sgn.getName()));
                }
                break;
            case TIME_STATE_CMD:
                Boolean bool = (Boolean) data[0];
                if (bool == null) {
                    addMessage(I18n.txt("notif.toggle", I18n.txt("gui.time")));
                } else {
                    addMessage(I18n.txt("notif.simulation." + (bool ? "resume" : "pause")));
                }
                break;
            case TOGGLE_VISIBILITY_CMD:
                if (data.length == 2)
                    addMessage(I18n.txt("notif.visibility." + (((Boolean) data[1]) ? "on" : "off"), I18n.txt((String) data[0])));
                else
                    addMessage(I18n.txt("notif.visibility.toggle", I18n.txt((String) data[0])));
                break;
            case FOCUS_LOCK_CMD:
            case ORIENTATION_LOCK_CMD:
            case TOGGLE_AMBIENT_LIGHT:
            case OCTREE_PARTICLE_FADE_CMD:
                addMessage(data[0] + (((Boolean) data[1]) ? " on" : " off"));
                break;
            case CAMERA_MODE_CMD:
                CameraMode cm = (CameraMode) data[0];
                if (cm != CameraMode.FOCUS_MODE)
                    addMessage(I18n.txt("notif.cameramode.change", data[0]));
                break;
            case TIME_WARP_CHANGED_INFO:
                addMessage(I18n.txt("notif.timepace.change", data[0]));
                break;
            case FOV_CHANGE_NOTIFICATION:
                // addMessage("Field of view changed to " + (float) data[0]);
                break;
            case JAVA_EXCEPTION:
                Throwable t = (Throwable) data[0];
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                t.printStackTrace(pw);
                String stackTrace = sw.toString();
                if (data.length == 1) {
                    if (I18n.bundle != null)
                        addMessage(I18n.txt("notif.error", stackTrace));
                    else
                        addMessage("Error: " + stackTrace);
                } else {
                    if (I18n.bundle != null)
                        addMessage(I18n.txt("notif.error", data[1] + TAG_SEPARATOR + stackTrace));
                    else
                        addMessage("Error: " + data[1] + TAG_SEPARATOR + stackTrace);
                }
                break;
            case ORBIT_DATA_LOADED:
                addMessage(I18n.txt("notif.orbitdata.loaded", data[1], ((PointCloudData) data[0]).getNumPoints()), false, LoggerLevel.DEBUG);
                break;
            case SCREENSHOT_INFO:
                addMessage(I18n.txt("notif.screenshot", data[0]));
                break;
            case STEREOSCOPIC_CMD:
                addMessage(I18n.txt("notif.toggle", I18n.txt("notif.stereoscopic")));
                break;
            case DISPLAY_GUI_CMD:
                boolean displayGui = (Boolean) data[0];
                addMessage(I18n.txt("notif." + (!displayGui ? "activated" : "deactivated"), data[1]));
                break;
            case STEREO_PROFILE_CMD:
                addMessage(I18n.txt("notif.stereoscopic.profile", StereoProfile.values()[(Integer) data[0]].toString()));
                break;
            case FRAME_OUTPUT_CMD:
                boolean activated = (Boolean) data[0];
                if (activated) {
                    addMessage(I18n.txt("notif.activated", I18n.txt("element.frameoutput")));
                } else {
                    addMessage(I18n.txt("notif.deactivated", I18n.txt("element.frameoutput")));
                }
                break;
            case SCREEN_NOTIFICATION_CMD:
                String title = (String) data[0];
                String[] msgs = (String[]) data[1];
                float time = (Float) data[2];
                // Log to output
                addMessage(title);
                for (String msg : msgs) addMessage(msg);
                break;
            case MODE_POPUP_CMD:
                ModePopupInfo mpi = (ModePopupInfo) data[0];
                if (mpi != null) {
                    addMessage(mpi.title);
                    addMessage(mpi.header);
                    for (Pair<String[], String> p : mpi.mappings) {
                        String[] keys = p.getFirst();
                        String action = p.getSecond();
                        StringBuilder msg = new StringBuilder();
                        msg.append("<");
                        for (int i = 0; i < keys.length; i++) {
                            msg.append(keys[i].toUpperCase());
                            if (i < keys.length - 1) {
                                msg.append("+");
                            }
                        }
                        msg.append("> " + action);
                        addMessage(msg.toString());
                    }
                }
                break;
            default:
                break;
        }
    }
}
Also used : PointCloudData(gaiasky.data.util.PointCloudData) StringBuilder(com.badlogic.gdx.utils.StringBuilder) CameraMode(gaiasky.scenegraph.camera.CameraManager.CameraMode) LoggerLevel(gaiasky.util.Logger.LoggerLevel) IFocus(gaiasky.scenegraph.IFocus) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 10 with IFocus

use of gaiasky.scenegraph.IFocus 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

IFocus (gaiasky.scenegraph.IFocus)16 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)6 Array (com.badlogic.gdx.utils.Array)3 CameraMode (gaiasky.scenegraph.camera.CameraManager.CameraMode)3 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)2 PointCloudData (gaiasky.data.util.PointCloudData)2 ParticleGroup (gaiasky.scenegraph.ParticleGroup)2 NaturalCamera (gaiasky.scenegraph.camera.NaturalCamera)2 LoggerLevel (gaiasky.util.Logger.LoggerLevel)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 com.badlogic.gdx.scenes.scene2d.ui (com.badlogic.gdx.scenes.scene2d.ui)1 StringBuilder (com.badlogic.gdx.utils.StringBuilder)1 BookmarkNode (gaiasky.interafce.BookmarksManager.BookmarkNode)1 NewBookmarkFolderDialog (gaiasky.interafce.NewBookmarkFolderDialog)1 Invisible (gaiasky.scenegraph.Invisible)1 StubModel (gaiasky.scenegraph.StubModel)1 CatalogInfo (gaiasky.util.CatalogInfo)1