/* * public slot */ void CelestialBrowser::slotRefresh() { StarDatabase* stardb = appSim->getUniverse()->getStarCatalog(); sbrowser.refresh(); std::vector<const Star*> *stars = sbrowser.listStars(100); listStars->clear(); browserSel.obj = const_cast<Star*>((*stars)[0]); browserSel.type = Selection::Type_Star; SolarSystemCatalog* solarSystemCatalog = appSim->getUniverse()->getSolarSystemCatalog(); UniversalCoord ucPos = appSim->getObserver().getPosition(); Point3f obsPos( (double)ucPos.x * 1e-6, (double)ucPos.y * 1e-6, (double)ucPos.z * 1e-6); setlocale(LC_NUMERIC, ""); for (std::vector<const Star*>::iterator i = stars->begin(); i != stars->end() ; i++ ) { const Star *star=(Star *)(*i); QString starClass(star->getSpectralType()); if (starClass == "Bary") continue; float dist = ucPos.offsetFromLy(star->getPosition()).norm(); CelListViewItem *starItem = new CelListViewItem(listStars, stardb->getStarName(*star), dist, _("ly"), astro::absToAppMag(star->getAbsoluteMagnitude(), dist), star->getAbsoluteMagnitude(), starClass); SolarSystemCatalog::iterator iter = solarSystemCatalog->find(star->getCatalogNumber()); if (iter != solarSystemCatalog->end()) { addPlanetarySystem(starItem, iter->second->getPlanets()); } } setlocale(LC_NUMERIC, "C"); delete(stars); }
// Rather than directly use Celestia's solar system data structure for // the tree model, we'll build a parallel structure out of TreeItems. // The additional memory used for this structure is negligible, and // it gives us some freedom to structure the tree in a different // way than it's represented internally, e.g. to group objects by // their classification. It also simplifies the code because stars // and solar system bodies can be treated almost identically once // the new tree is built. SolarSystemTreeModel::TreeItem* SolarSystemTreeModel::createTreeItem(Selection sel, TreeItem* parent, int childIndex) { TreeItem* item = new TreeItem(); item->parent = parent; item->obj = sel; item->childIndex = childIndex; const vector<Star*>* orbitingStars = NULL; PlanetarySystem* sys = NULL; if (sel.body() != NULL) { sys = sel.body()->getSatellites(); } else if (sel.star() != NULL) { // Stars may have both a solar system and other stars orbiting // them. SolarSystemCatalog* solarSystems = universe->getSolarSystemCatalog(); SolarSystemCatalog::iterator iter = solarSystems->find(sel.star()->getCatalogNumber()); if (iter != solarSystems->end()) { sys = iter->second->getPlanets(); } orbitingStars = sel.star()->getOrbitingStars(); } if (groupByClass && sys != NULL) addTreeItemChildrenGrouped(item, sys, orbitingStars, sel); else addTreeItemChildren(item, sys, orbitingStars); return item; }