QString KStars::getObjectDataXML( const QString &objectName ) { SkyObject *target = data()->objectNamed( objectName ); if ( !target ) { return QString( "<xml></xml>" ); } QString output; QXmlStreamWriter stream( &output ); stream.setAutoFormatting( true ); stream.writeStartDocument(); stream.writeStartElement( "object" ); stream.writeTextElement( "Name", target->name() ); stream.writeTextElement( "Alt_Name", target->name2() ); stream.writeTextElement( "Long_Name", target->longname() ); stream.writeTextElement( "Constellation", KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName( target ) ); stream.writeTextElement( "RA_HMS", target->ra().toHMSString() ); stream.writeTextElement( "Dec_DMS", target->dec().toDMSString() ); stream.writeTextElement( "RA_J2000_HMS", target->ra0().toHMSString() ); stream.writeTextElement( "Dec_J2000_DMS", target->dec0().toDMSString() ); stream.writeTextElement( "RA_Degrees", QString::number( target->ra().Degrees() ) ); stream.writeTextElement( "Dec_Degrees", QString::number( target->dec().Degrees() ) ); stream.writeTextElement( "RA_J2000_Degrees", QString::number( target->ra0().Degrees() ) ); stream.writeTextElement( "Dec_J2000_Degrees", QString::number( target->dec0().Degrees() ) ); stream.writeTextElement( "Type", target->typeName() ); stream.writeTextElement( "Magnitude", QString::number( target->mag(), 'g', 2 ) ); stream.writeTextElement( "Position_Angle", QString::number( target->pa(), 'g', 3 ) ); StarObject *star = dynamic_cast< StarObject* >( target ); DeepSkyObject *dso = dynamic_cast< DeepSkyObject* >( target ); if ( star ) { stream.writeTextElement( "Spectral_Type", star->sptype() ); stream.writeTextElement( "Genetive_Name", star->gname() ); stream.writeTextElement( "Greek_Letter", star->greekLetter() ); stream.writeTextElement( "Proper_Motion", QString::number( star->pmMagnitude() ) ); stream.writeTextElement( "Proper_Motion_RA", QString::number( star->pmRA() ) ); stream.writeTextElement( "Proper_Motion_Dec", QString::number( star->pmDec() ) ); stream.writeTextElement( "Parallax_mas", QString::number( star->parallax() ) ); stream.writeTextElement( "Distance_pc", QString::number( star->distance() ) ); stream.writeTextElement( "Henry_Draper", QString::number( star->getHDIndex() ) ); stream.writeTextElement( "BV_Index", QString::number( star->getBVIndex() ) ); } else if ( dso ) { stream.writeTextElement( "Catalog", dso->catalog() ); stream.writeTextElement( "Major_Axis", QString::number( dso->a() ) ); stream.writeTextElement( "Minor_Axis", QString::number( dso->a() * dso->e() ) ); } stream.writeEndElement(); // object stream.writeEndDocument(); return output; }
QString SkyObjItem::getSurfaceBrightness() const { /** Surface Brightness is applicable only for extended light sources like * Deep-Sky Objects. Here we use the formula SB = m + log10(a*b/4) * where m is the magnitude of the sky-object. a and b are the major and minor * axis lengths of the objects respectively in arcminutes. SB is the surface * brightness obtained in mag * arcminutes^-2 */ DeepSkyObject *dso = (DeepSkyObject *)m_So; float SB = m_So->mag() + 2.5 * log10(dso->a() * dso->b() / 4); switch(getType()) { case Galaxy: case Nebula: return KGlobal::locale()->formatNumber(SB, 2) + " mag/arcmin^2"; default: return QString(" --"); // Not applicable for other sky-objects } }
void DetailsTable::createGeneralTable(SkyObject *obj) { clearContents(); QTextCursor cursor = m_Document->rootFrame()->firstCursorPosition(); //Fill in the data fields //Contents depend on type of object StarObject *s = 0; DeepSkyObject *dso = 0; KSPlanetBase *ps = 0; QString pname, oname; QString objNamesVal, objTypeVal, objDistVal, objSizeVal, objMagVal, objBvVal, objIllumVal; QString objSizeLabel, objMagLabel; switch(obj->type()) { case SkyObject::STAR: { s = (StarObject *)obj; objNamesVal = s->longname(); if(s->getHDIndex() != 0) { if(!s->longname().isEmpty()) { objNamesVal = s->longname() + QString(", HD%1").arg(QString::number(s->getHDIndex())) ; } else { objNamesVal = QString(", HD%1").arg(QString::number(s->getHDIndex())); } } objTypeVal = s->sptype() + ' ' + i18n("star"); objMagVal = i18nc("number in magnitudes", "%1 mag", KGlobal::locale()->formatNumber(s->mag(), 1)); //show to tenths place if(s->getBVIndex() < 30.0) { objBvVal = QString::number(s->getBVIndex(), 'g', 2); } //distance if(s->distance() > 2000. || s->distance() < 0.) // parallax < 0.5 mas { objDistVal = i18nc("larger than 2000 parsecs", "> 2000 pc"); } else if(s->distance() > 50.0) //show to nearest integer { objDistVal = i18nc("number in parsecs", "%1 pc", KGlobal::locale()->formatNumber(s->distance(), 0)); } else if(s->distance() > 10.0) //show to tenths place { objDistVal = i18nc("number in parsecs", "%1 pc", KGlobal::locale()->formatNumber(s->distance(), 1)); } else //show to hundredths place { objDistVal = i18nc("number in parsecs", "%1 pc", KGlobal::locale()->formatNumber(s->distance(), 2)); } //Note multiplicity/variablility in angular size label if(s->isMultiple() && s->isVariable()) { objSizeLabel = i18nc("the star is a multiple star", "multiple") + ','; objSizeVal = i18nc("the star is a variable star", "variable"); } else if(s->isMultiple()) { objSizeLabel = i18nc("the star is a multiple star", "multiple"); } else if(s->isVariable()) { objSizeLabel = i18nc("the star is a variable star", "variable"); } objIllumVal = "--"; break; //End of stars case } case SkyObject::ASTEROID: //[fall through to planets] case SkyObject::COMET: //[fall through to planets] case SkyObject::MOON: //[fall through to planets] case SkyObject::PLANET: { ps = (KSPlanetBase *)obj; objNamesVal = ps->longname(); //Type is "G5 star" for Sun if(ps->name() == "Sun") { objTypeVal = i18n("G5 star"); } else if(ps->name() == "Moon") { objTypeVal = ps->translatedName(); } else if(ps->name() == i18n("Pluto") || ps->name() == "Ceres" || ps->name() == "Eris") // TODO: Check if Ceres / Eris have translations and i18n() them { objTypeVal = i18n("Dwarf planet"); } else { objTypeVal = ps->typeName(); } //Magnitude: The moon displays illumination fraction instead if(obj->name() == "Moon") { objIllumVal = QString("%1 %").arg(KGlobal::locale()->formatNumber(((KSMoon *)obj)->illum()*100., 0)); } objMagVal = i18nc("number in magnitudes", "%1 mag", KGlobal::locale()->formatNumber(ps->mag(), 1)); //show to tenths place //Distance from Earth. The moon requires a unit conversion if(ps->name() == "Moon") { objDistVal = i18nc("distance in kilometers", "%1 km", KGlobal::locale()->formatNumber(ps->rearth() * AU_KM )); } else { objDistVal = i18nc("distance in Astronomical Units", "%1 AU", KGlobal::locale()->formatNumber(ps->rearth())); } //Angular size; moon and sun in arcmin, others in arcsec if(ps->angSize()) { if(ps->name() == "Sun" || ps->name() == "Moon") { // Needn't be a plural form because sun / moon will never contract to 1 arcminute objSizeVal = i18nc("angular size in arcminutes", "%1 arcmin", KGlobal::locale()->formatNumber(ps->angSize())); } else { objSizeVal = i18nc("angular size in arcseconds","%1 arcsec", KGlobal::locale()->formatNumber(ps->angSize() * 60.0)); } } else { objSizeVal = "--"; } break; //End of planets/comets/asteroids case } default: //Deep-sky objects { dso = (DeepSkyObject *)obj; //Show all names recorded for the object if(!dso->longname().isEmpty() && dso->longname() != dso->name()) { pname = dso->translatedLongName(); oname = dso->translatedName(); } else { pname = dso->translatedName(); } if(!dso->translatedName2().isEmpty()) { if(oname.isEmpty()) { oname = dso->translatedName2(); } else { oname += ", " + dso->translatedName2(); } } if(dso->ugc() != 0) { if(!oname.isEmpty()) { oname += ", "; } oname += "UGC " + QString::number(dso->ugc()); } if(dso->pgc() != 0) { if(!oname.isEmpty()) { oname += ", "; } oname += "PGC " + QString::number(dso->pgc()); } if(!oname.isEmpty()) { pname += ", " + oname; } objNamesVal = pname; objTypeVal = dso->typeName(); if(dso->type() == SkyObject::RADIO_SOURCE) { objMagLabel = i18nc("integrated flux at a frequency", "Flux(%1):", dso->customCatalog()->fluxFrequency()); objMagVal = i18nc("integrated flux value", "%1 %2", KGlobal::locale()->formatNumber(dso->flux(), 1), dso->customCatalog()->fluxUnit()); //show to tenths place } else if(dso->mag() > 90.0) { objMagVal = "--"; } else { objMagVal = i18nc("number in magnitudes", "%1 mag", KGlobal::locale()->formatNumber(dso->mag(), 1)); //show to tenths place } //No distances at this point... objDistVal = "--"; //Only show decimal place for small angular sizes if(dso->a() > 10.0) { objSizeVal = i18nc("angular size in arcminutes", "%1 arcmin", KGlobal::locale()->formatNumber(dso->a(), 0)); } else if(dso->a()) { objSizeVal = i18nc("angular size in arcminutes", "%1 arcmin", KGlobal::locale()->formatNumber(dso->a(), 1)); } else { objSizeVal = "--"; } break; //End of deep-space objects case } } //Common to all types: if(obj->type() == SkyObject::CONSTELLATION ) { objTypeVal = KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName(obj); } else { objTypeVal = i18nc("%1 type of sky object (planet, asteroid etc), %2 name of a constellation", "%1 in %2", objTypeVal, KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName(obj)); } QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 25) << QTextLength(QTextLength::PercentageLength, 25) << QTextLength(QTextLength::PercentageLength, 25) << QTextLength(QTextLength::PercentageLength, 25); m_TableFormat.setColumnWidthConstraints(constraints); QTextTable *table = cursor.insertTable(5, 4, m_TableFormat); table->mergeCells(0, 0, 1, 4); QTextBlockFormat centered; centered.setAlignment(Qt::AlignCenter); table->cellAt(0, 0).firstCursorPosition().setBlockFormat(centered); table->cellAt(0, 0).firstCursorPosition().insertText(i18n("General"), m_TableTitleCharFormat); table->mergeCells(1, 1, 1, 3); table->cellAt(1, 0).firstCursorPosition().insertText(i18n("Names:"), m_ItemNameCharFormat); table->cellAt(1, 0).firstCursorPosition().setBlockFormat(centered); table->cellAt(1, 1).firstCursorPosition().insertText(objNamesVal, m_ItemValueCharFormat); table->cellAt(2, 0).firstCursorPosition().insertText(i18n("Type:"), m_ItemNameCharFormat); table->cellAt(2, 0).firstCursorPosition().setBlockFormat(centered); table->cellAt(2, 1).firstCursorPosition().insertText(objTypeVal, m_ItemValueCharFormat); table->cellAt(3, 0).firstCursorPosition().insertText(i18n("Distance:"), m_ItemNameCharFormat); table->cellAt(3, 0).firstCursorPosition().setBlockFormat(centered); table->cellAt(3, 1).firstCursorPosition().insertText(objDistVal, m_ItemValueCharFormat); table->cellAt(4, 0).firstCursorPosition().insertText(i18n("Size:"), m_ItemNameCharFormat); table->cellAt(4, 0).firstCursorPosition().setBlockFormat(centered); table->cellAt(4, 1).firstCursorPosition().insertText(objSizeVal, m_ItemValueCharFormat); table->cellAt(2, 2).firstCursorPosition().insertText(i18n("Magnitude:"), m_ItemNameCharFormat); table->cellAt(2, 2).firstCursorPosition().setBlockFormat(centered); table->cellAt(2, 3).firstCursorPosition().insertText(objMagVal, m_ItemValueCharFormat); table->cellAt(3, 2).firstCursorPosition().insertText(i18n("B-V index:"), m_ItemNameCharFormat); table->cellAt(3, 2).firstCursorPosition().setBlockFormat(centered); table->cellAt(3, 3).firstCursorPosition().insertText(objBvVal, m_ItemValueCharFormat); table->cellAt(4, 2).firstCursorPosition().insertText(i18n("Illumination:"), m_ItemNameCharFormat); table->cellAt(4, 2).firstCursorPosition().setBlockFormat(centered); table->cellAt(4, 3).firstCursorPosition().insertText(objIllumVal, m_ItemValueCharFormat); }