void CatalogComponent::update( KSNumbers * ) { if ( selected() ) { KStarsData *data = KStarsData::Instance(); foreach ( SkyObject *obj, m_ObjectList ) { DeepSkyObject *dso = dynamic_cast< DeepSkyObject * >( obj ); StarObject *so = dynamic_cast< StarObject *>( obj ); Q_ASSERT( dso || so ); // We either have stars, or deep sky objects if( dso ) { // Update the deep sky object if need be if ( dso->updateID != data->updateID() ) { dso->updateID = data->updateID(); if ( dso->updateNumID != data->updateNumID() ) { dso->updateCoords( data->updateNum() ); } dso->EquatorialToHorizontal( data->lst(), data->geo()->lat() ); } } else { // Do exactly the same thing for stars if ( so->updateID != data->updateID() ) { so->updateID = data->updateID(); if ( so->updateNumID != data->updateNumID() ) { so->updateCoords( data->updateNum() ); } so->EquatorialToHorizontal( data->lst(), data->geo()->lat() ); } } } this->updateID = data->updateID(); }
void DeepSkyComponent::loadData() { KStarsData* data = KStarsData::Instance(); //Check whether we need to concatenate a split NGC/IC catalog //(i.e., if user has downloaded the Steinicke catalog) mergeSplitFiles(); QList< QPair<QString,KSParser::DataTypes> > sequence; QList<int> widths; sequence.append(qMakePair(QString("Flag"), KSParser::D_QSTRING)); widths.append(1); sequence.append(qMakePair(QString("ID"), KSParser::D_INT)); widths.append(4); sequence.append(qMakePair(QString("suffix"), KSParser::D_QSTRING)); widths.append(1); sequence.append(qMakePair(QString("RA_H"), KSParser::D_INT)); widths.append(2); sequence.append(qMakePair(QString("RA_M"),KSParser::D_INT)); widths.append(2); sequence.append(qMakePair(QString("RA_S"),KSParser::D_FLOAT)); widths.append(4); sequence.append(qMakePair(QString("D_Sign"),KSParser::D_QSTRING)); widths.append(2); sequence.append(qMakePair(QString("Dec_d"),KSParser::D_INT)); widths.append(2); sequence.append(qMakePair(QString("Dec_m"),KSParser::D_INT)); widths.append(2); sequence.append(qMakePair(QString("Dec_s"),KSParser::D_INT)); widths.append(2); sequence.append(qMakePair(QString("BMag"),KSParser::D_QSTRING)); widths.append(6); sequence.append(qMakePair(QString("type"),KSParser::D_INT)); widths.append(2); sequence.append(qMakePair(QString("a"),KSParser::D_FLOAT)); widths.append(6); sequence.append(qMakePair(QString("b"),KSParser::D_FLOAT)); widths.append(6); sequence.append(qMakePair(QString("pa"),KSParser::D_QSTRING)); widths.append(4); sequence.append(qMakePair(QString("PGC"),KSParser::D_INT)); widths.append(7); sequence.append(qMakePair(QString("other cat"),KSParser::D_QSTRING)); widths.append(4); sequence.append(qMakePair(QString("other1"),KSParser::D_QSTRING)); widths.append(6); sequence.append(qMakePair(QString("other2"),KSParser::D_QSTRING)); widths.append(6); sequence.append(qMakePair(QString("Messr"),KSParser::D_QSTRING)); widths.append(2); sequence.append(qMakePair(QString("MessrNum"),KSParser::D_INT)); widths.append(4); sequence.append(qMakePair(QString("Longname"),KSParser::D_QSTRING)); //No width to be appended for last sequence object QString file_name = KSPaths::locate(QStandardPaths::GenericDataLocation, QString("ngcic.dat") ); KSParser deep_sky_parser(file_name, '#', sequence, widths); deep_sky_parser.SetProgress( i18n("Loading NGC/IC objects"), 13444, 10 ); qDebug() << "Loading NGC/IC objects"; QHash<QString,QVariant> row_content; while (deep_sky_parser.HasNextRow()) { row_content = deep_sky_parser.ReadNextRow(); QString iflag; QString cat; iflag = row_content["Flag"].toString().mid( 0, 1 ); //check for NGC/IC catalog flag /* Q_ASSERT(iflag == "I" || iflag == "N" || iflag == " "); // (spacetime): ^ Why an assert? Change in implementation of ksparser // might result in crash for no reason. // n.b. We also allow non-NGC/IC objects which have a blank iflag */ float mag(1000.0); int type, ingc, imess(-1), pa; int pgc, ugc; QString ss, name, name2, longname; QString cat2; // Designation if ( iflag == "I" ) cat = "IC"; else if ( iflag == "N" ) cat = "NGC"; ingc = row_content["ID"].toInt(); // NGC/IC catalog number if ( ingc==0 ) cat.clear(); //object is not in NGC or IC catalogs QString suffix = row_content["suffix"].toString(); // multipliticity suffixes, eg: the 'A' in NGC 4945A Q_ASSERT( suffix.isEmpty() || ( suffix.at( 0 ) >= QChar( 'A' ) && suffix.at( 0 ) <= QChar( 'Z' ) ) || (suffix.at( 0 ) >= QChar( 'a' ) && suffix.at( 0 ) <= QChar( 'z' ) ) ); //coordinates int rah = row_content["RA_H"].toInt(); int ram = row_content["RA_M"].toInt(); float ras = row_content["RA_S"].toFloat(); QString sgn = row_content["D_Sign"].toString(); int dd = row_content["Dec_d"].toInt(); int dm = row_content["Dec_m"].toInt(); int ds = row_content["Dec_s"].toInt(); if ( !( (0.0 <= rah && rah < 24.0) || (0.0 <= ram && ram < 60.0) || (0.0 <= ras && ras < 60.0) || (0.0 <= dd && dd <= 90.0) || (0.0 <= dm && dm < 60.0) || (0.0 <= ds && ds < 60.0) ) ) { qDebug() << "Bad coordinates while processing NGC/IC object: " << cat << ingc; qDebug() << "RA H:M:S = " << rah << ":" << ram << ":" << ras << "; Dec D:M:S = " << dd << ":" << dm << ":" << ds; Q_ASSERT( false ); } //Ignore lines with no coordinate values if not debugging if (rah==0 && ram==0 && ras==0) continue; //B magnitude ss = row_content["BMag"].toString(); if (ss == "") { mag = 99.9f; } else { mag = ss.toFloat(); } //object type type = row_content["type"].toInt(); //major and minor axes float a = row_content["a"].toFloat(); float b = row_content["b"].toFloat(); //position angle. The catalog PA is zero when the Major axis //is horizontal. But we want the angle measured from North, so //we set PA = 90 - pa. ss = row_content["pa"].toString(); if (ss == "" ) { pa = 90; } else { pa = 90 - ss.toInt(); } //PGC number pgc = row_content["PGC"].toInt(); //UGC number if (row_content["other cat"].toString().trimmed() == "UGC") { ugc = row_content["other1"].toString().toInt(); } else { ugc = 0; } //Messier number if ( row_content["Messr"].toString().trimmed() == "M" ) { cat2 = cat; if ( ingc == 0 ) cat2.clear(); cat = 'M'; imess = row_content["MessrNum"].toInt(); } longname = row_content["Longname"].toString(); dms r; r.setH( rah, ram, int(ras) ); dms d( dd, dm, ds ); if ( sgn == "-" ) { d.setD( -1.0*d.Degrees() ); } bool hasName = true; QString snum; if (cat=="IC" || cat=="NGC") { snum.setNum(ingc); name = cat + ' ' + ( ( suffix.isEmpty() ) ? snum : ( snum + suffix ) ); } else if (cat == "M") { snum.setNum( imess ); name = cat + ' ' + snum; // Note: Messier has no suffixes if (cat2 == "NGC" || cat2 == "IC") { snum.setNum( ingc ); name2 = cat2 + ' ' + ( ( suffix.isEmpty() ) ? snum : ( snum + suffix ) ); } else { name2.clear(); } } else { if (!longname.isEmpty()) name = longname; else { hasName = false; name = i18n( "Unnamed Object" ); } } name = i18nc("object name (optional)", name.toLatin1().constData()); if (!longname.isEmpty()) longname = i18nc("object name (optional)", longname.toLatin1().constData()); // create new deepskyobject DeepSkyObject *o = 0; if ( type==0 ) type = 1; //Make sure we use CATALOG_STAR, not STAR o = new DeepSkyObject( type, r, d, mag, name, name2, longname, cat, a, b, pa, pgc, ugc ); o->EquatorialToHorizontal( data->lst(), data->geo()->lat() ); // Add the name(s) to the nameHash for fast lookup -jbb if ( hasName) { nameHash[ name.toLower() ] = o; if ( ! longname.isEmpty() ) nameHash[ longname.toLower() ] = o; if ( ! name2.isEmpty() ) nameHash[ name2.toLower() ] = o; } Trixel trixel = m_skyMesh->index(o); //Assign object to general DeepSkyObjects list, //and a secondary list based on its catalog. m_DeepSkyList.append( o ); appendIndex( o, &m_DeepSkyIndex, trixel ); if ( o->isCatalogM()) { m_MessierList.append( o ); appendIndex( o, &m_MessierIndex, trixel ); } else if (o->isCatalogNGC() ) { m_NGCList.append( o ); appendIndex( o, &m_NGCIndex, trixel ); } else if ( o->isCatalogIC() ) { m_ICList.append( o ); appendIndex( o, &m_ICIndex, trixel ); } else { m_OtherList.append( o ); appendIndex( o, &m_OtherIndex, trixel ); } // JM: VERY INEFFICIENT. Disabling for now until we figure out how to deal with dups. QSet? //if ( ! name.isEmpty() && !objectNames(type).contains(name)) if ( ! name.isEmpty() ) objectNames(type).append( name ); //Add long name to the list of object names //if ( ! longname.isEmpty() && longname != name && !objectNames(type).contains(longname)) if ( ! longname.isEmpty() && longname != name) objectNames(type).append( longname ); deep_sky_parser.ShowProgress(); } foreach(QStringList list, objectNames()) list.removeDuplicates(); }