// Utility function that returns the complete path for a selection. string getSelectionName(const Selection& selection, CelestiaCore* appCore) { Universe *universe = appCore->getSimulation()->getUniverse(); switch (selection.getType()) { case Selection::Type_Body: return getBodyName(universe, selection.body()); case Selection::Type_Star: return universe->getStarCatalog()->getStarName(*selection.star()); case Selection::Type_DeepSky: return universe->getDSOCatalog()->getDSOName(selection.deepsky()); case Selection::Type_Location: { std::string name = selection.location()->getName(); Body* parentBody = selection.location()->getParentBody(); if (parentBody != NULL) name = getBodyName(universe, parentBody) + ":" + name; return name; } default: return ""; } }
void CelestiaAppWindow::slotAddBookmark() { // Set the default bookmark title to the name of the current selection Selection sel = m_appCore->getSimulation()->getSelection(); QString defaultTitle; if (sel.body() != NULL) { defaultTitle = QString::fromUtf8(sel.body()->getName(true).c_str()); } else if (sel.star() != NULL) { Universe* universe = m_appCore->getSimulation()->getUniverse(); defaultTitle = QString::fromUtf8(ReplaceGreekLetterAbbr(universe->getStarCatalog()->getStarName(*sel.star(), true)).c_str()); } else if (sel.deepsky() != NULL) { Universe* universe = m_appCore->getSimulation()->getUniverse(); defaultTitle = QString::fromUtf8(ReplaceGreekLetterAbbr(universe->getDSOCatalog()->getDSOName(sel.deepsky(), true)).c_str()); } else if (sel.location() != NULL) { defaultTitle = sel.location()->getName().c_str(); } if (defaultTitle.isEmpty()) defaultTitle = _("New bookmark"); CelestiaState appState; appState.captureState(m_appCore); // Capture the current frame buffer to use as a bookmark icon. QImage grabbedImage = glWidget->grabFrameBuffer(); int width = grabbedImage.width(); int height = grabbedImage.height(); // Crop the image to a square. QImage iconImage; if (width > height) iconImage = grabbedImage.copy((width - height) / 2, 0, height, height); else iconImage = grabbedImage.copy(0, (height - width) / 2, width, width); AddBookmarkDialog dialog(m_bookmarkManager, defaultTitle, appState, iconImage); dialog.exec(); populateBookmarkMenu(); m_bookmarkToolBar->rebuild(); }
void DeepSkyBrowser::slotMarkSelected() { QItemSelectionModel* sm = treeView->selectionModel(); bool labelMarker = labelMarkerBox->checkState() == Qt::Checked; bool convertOK = false; QVariant markerData = markerSymbolBox->itemData(markerSymbolBox->currentIndex()); MarkerRepresentation::Symbol markerSymbol = (MarkerRepresentation::Symbol) markerData.toInt(&convertOK); QVariant markerSize = markerSizeBox->itemData(markerSizeBox->currentIndex()); float size = (float) markerSize.toInt(&convertOK); QColor markerColor = colorSwatch->color(); Color color((float) markerColor.redF(), (float) markerColor.greenF(), (float) markerColor.blueF()); Universe* universe = appCore->getSimulation()->getUniverse(); string label; int nRows = dsoModel->rowCount(QModelIndex()); for (int row = 0; row < nRows; row++) { if (sm->isRowSelected(row, QModelIndex())) { DeepSkyObject* dso = dsoModel->itemAtRow((unsigned int) row); if (dso != NULL) { if (convertOK) { if (labelMarker) { label = universe->getDSOCatalog()->getDSOName(dso, true); label = ReplaceGreekLetterAbbr(label); } universe->markObject(Selection(dso), MarkerRepresentation(markerSymbol, size, color, label), 1); } else { universe->unmarkObject(Selection(dso), 1); } } } // isRowSelected } // for }
void SolarSystemBrowser::slotMarkSelected() { #if 0 QItemSelectionModel* sm = treeView->selectionModel(); QModelIndexList rows = sm->selectedRows(); bool labelMarker = labelMarkerBox->checkState() == Qt::Checked; bool convertOK = false; QVariant markerData = markerSymbolBox->itemData(markerSymbolBox->currentIndex()); Marker::Symbol markerSymbol = (Marker::Symbol) markerData.toInt(&convertOK); QColor markerColor = colorSwatch->color(); Color color((float) markerColor.redF(), (float) markerColor.greenF(), (float) markerColor.blueF()); Universe* universe = appCore->getSimulation()->getUniverse(); string label; for (QModelIndexList::const_iterator iter = rows.begin(); iter != rows.end(); iter++) { Selection sel = solarSystemModel->objectAtIndex(*iter); if (!sel.empty()) { if (convertOK) { #if 0 if (labelMarker) { label = universe->getDSOCatalog()->getDSOName(dso); label = ReplaceGreekLetterAbbr(label); } #endif universe->markObject(sel, 10.0f, color, markerSymbol, 1, label); } else { universe->unmarkObject(sel, 1); } } } #endif }
// Override QAbstractTableModel::data() QVariant DSOTableModel::data(const QModelIndex& index, int role) const { int row = index.row(); if (row < 0 || row >= (int) dsos.size()) { // Out of range return QVariant(); } const DeepSkyObject* dso = dsos[row]; if (role != Qt::DisplayRole) return QVariant(); switch (index.column()) { case NameColumn: { string dsoNameString = ReplaceGreekLetterAbbr(universe->getDSOCatalog()->getDSOName(dso, true)); return QVariant(QString::fromUtf8(dsoNameString.c_str())); } case DistanceColumn: { return QString("%L1").arg((observerPos - dso->getPosition()).norm(), 0, 'g', 4); } case AppMagColumn: { double distance = (observerPos - dso->getPosition()).norm(); return QString("%1").arg(astro::absToAppMag((double) dso->getAbsoluteMagnitude(), distance), 0, 'f', 2); } case TypeColumn: return QString(dso->getType()); default: return QVariant(); } }
void DSOTableModel::populate(const UniversalCoord& _observerPos, DSOFilterPredicate& filterPred, DSOPredicate::Criterion criterion, unsigned int nDSOs) { const DSODatabase& dsodb = *universe->getDSOCatalog(); observerPos = _observerPos.offsetFromKm(UniversalCoord::Zero()) * astro::kilometersToLightYears(1.0); typedef multiset<DeepSkyObject*, DSOPredicate> DSOSet; DSOPredicate pred(criterion, observerPos); // Apply the filter vector<DeepSkyObject*> filteredDSOs; unsigned int totalDSOs = dsodb.size(); unsigned int i = 0; filteredDSOs.reserve(totalDSOs); for (i = 0; i < totalDSOs; i++) { DeepSkyObject* dso = dsodb.getDSO(i); if (!filterPred(dso)) filteredDSOs.push_back(dso); } // Don't try and show more DSOs than remain after the filter if (filteredDSOs.size() < nDSOs) nDSOs = filteredDSOs.size(); // Clear out the results of the previous populate() call if (dsos.size() != 0) { dsos.clear(); reset(); } if (filteredDSOs.empty()) return; DSOSet firstDSOs(pred); // We'll need at least nDSOs in the set, so first fill // up the list indiscriminately. for (i = 0; i < nDSOs; i++) { firstDSOs.insert(filteredDSOs[i]); } // From here on, only add a dso to the set if it's // A better match than the worst matching dso already // in the set. const DeepSkyObject* lastDSO = *--firstDSOs.end(); for (; i < filteredDSOs.size(); i++) { DeepSkyObject* dso = filteredDSOs[i]; if (pred(dso, lastDSO)) { firstDSOs.insert(dso); firstDSOs.erase(--firstDSOs.end()); lastDSO = *--firstDSOs.end(); } } // Move the best matching DSOs into the vector dsos.reserve(nDSOs); for (DSOSet::const_iterator iter = firstDSOs.begin(); iter != firstDSOs.end(); iter++) { dsos.push_back(*iter); } beginInsertRows(QModelIndex(), 0, dsos.size()); endInsertRows(); }