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;
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations