Changeset View
Changeset View
Standalone View
Standalone View
kstars/skymap.cpp
Show All 19 Lines | |||||
20 | #endif | 20 | #endif | ||
21 | 21 | | |||
22 | #include "skymap.h" | 22 | #include "skymap.h" | ||
23 | 23 | | |||
24 | #include "ksasteroid.h" | 24 | #include "ksasteroid.h" | ||
25 | #include "kstars_debug.h" | 25 | #include "kstars_debug.h" | ||
26 | #include "fov.h" | 26 | #include "fov.h" | ||
27 | #include "imageviewer.h" | 27 | #include "imageviewer.h" | ||
28 | #include "xplanetimageviewer.h" | ||||
28 | #include "ksdssdownloader.h" | 29 | #include "ksdssdownloader.h" | ||
29 | #include "kspaths.h" | 30 | #include "kspaths.h" | ||
30 | #include "kspopupmenu.h" | 31 | #include "kspopupmenu.h" | ||
31 | #include "kstars.h" | 32 | #include "kstars.h" | ||
32 | #include "ksutils.h" | 33 | #include "ksutils.h" | ||
33 | #include "Options.h" | 34 | #include "Options.h" | ||
34 | #include "skymapcomposite.h" | 35 | #include "skymapcomposite.h" | ||
35 | #ifdef HAVE_OPENGL | 36 | #ifdef HAVE_OPENGL | ||
▲ Show 20 Lines • Show All 1227 Lines • ▼ Show 20 Line(s) | 1261 | { | |||
1263 | AngularRuler.update(data); | 1264 | AngularRuler.update(data); | ||
1264 | } | 1265 | } | ||
1265 | 1266 | | |||
1266 | bool SkyMap::isSlewing() const | 1267 | bool SkyMap::isSlewing() const | ||
1267 | { | 1268 | { | ||
1268 | return (slewing || (clockSlewing && data->clock()->isActive())); | 1269 | return (slewing || (clockSlewing && data->clock()->isActive())); | ||
1269 | } | 1270 | } | ||
1270 | 1271 | | |||
1271 | void SkyMap::startXplanet(const QString &outputFile) | 1272 | void SkyMap::slotStartXplanetViewer() | ||
1272 | { | 1273 | { | ||
1273 | QString year, month, day, hour, minute, seconde, fov; | 1274 | if(clickedObject()) | ||
1274 | 1275 | new XPlanetImageViewer(clickedObject()->name(), this); | |||
1275 | QString xPlanetLocation = Options::xplanetPath(); | | |||
1276 | #ifdef Q_OS_OSX | | |||
1277 | if (Options::xplanetIsInternal()) | | |||
1278 | xPlanetLocation = QCoreApplication::applicationDirPath() + "/xplanet/bin/xplanet"; | | |||
1279 | #endif | | |||
1280 | | ||||
1281 | // If Options::xplanetPath() is empty, return | | |||
1282 | if (xPlanetLocation.isEmpty()) | | |||
1283 | { | | |||
1284 | KMessageBox::error(nullptr, i18n("Xplanet binary path is empty in config panel.")); | | |||
1285 | return; | | |||
1286 | } | | |||
1287 | | ||||
1288 | // If Options::xplanetPath() does not exist, return | | |||
1289 | const QFileInfo xPlanetLocationInfo(xPlanetLocation); | | |||
1290 | if (!xPlanetLocationInfo.exists() || !xPlanetLocationInfo.isExecutable()) | | |||
1291 | { | | |||
1292 | KMessageBox::error(nullptr, i18n("The configured Xplanet binary does not exist or is not executable.")); | | |||
1293 | return; | | |||
1294 | } | | |||
1295 | | ||||
1296 | // Format date | | |||
1297 | if (year.setNum(data->ut().date().year()).size() == 1) | | |||
1298 | year.push_front('0'); | | |||
1299 | if (month.setNum(data->ut().date().month()).size() == 1) | | |||
1300 | month.push_front('0'); | | |||
1301 | if (day.setNum(data->ut().date().day()).size() == 1) | | |||
1302 | day.push_front('0'); | | |||
1303 | if (hour.setNum(data->ut().time().hour()).size() == 1) | | |||
1304 | hour.push_front('0'); | | |||
1305 | if (minute.setNum(data->ut().time().minute()).size() == 1) | | |||
1306 | minute.push_front('0'); | | |||
1307 | if (seconde.setNum(data->ut().time().second()).size() == 1) | | |||
1308 | seconde.push_front('0'); | | |||
1309 | | ||||
1310 | // Create xplanet process | | |||
1311 | QProcess *xplanetProc = new QProcess; | | |||
1312 | | ||||
1313 | // Add some options | | |||
1314 | QStringList args; | | |||
1315 | args << "-body" << clickedObject()->name().toLower() << "-geometry" | | |||
1316 | << Options::xplanetWidth() + 'x' + Options::xplanetHeight() << "-date" | | |||
1317 | << year + month + day + '.' + hour + minute + seconde << "-glare" << Options::xplanetGlare() | | |||
1318 | << "-base_magnitude" << Options::xplanetMagnitude() << "-light_time" | | |||
1319 | << "-window"; | | |||
1320 | | ||||
1321 | // General options | | |||
1322 | if (!Options::xplanetTitle().isEmpty()) | | |||
1323 | args << "-window_title" | | |||
1324 | << "\"" + Options::xplanetTitle() + "\""; | | |||
1325 | if (Options::xplanetFOV()) | | |||
1326 | args << "-fov" << fov.setNum(this->fov()).replace('.', ','); | | |||
1327 | if (Options::xplanetConfigFile()) | | |||
1328 | args << "-config" << Options::xplanetConfigFilePath(); | | |||
1329 | if (Options::xplanetStarmap()) | | |||
1330 | args << "-starmap" << Options::xplanetStarmapPath(); | | |||
1331 | if (Options::xplanetArcFile()) | | |||
1332 | args << "-arc_file" << Options::xplanetArcFilePath(); | | |||
1333 | if (Options::xplanetWait()) | | |||
1334 | args << "-wait" << Options::xplanetWaitValue(); | | |||
1335 | if (!outputFile.isEmpty()) | | |||
1336 | args << "-output" << outputFile << "-quality" << Options::xplanetQuality(); | | |||
1337 | | ||||
1338 | // Labels | | |||
1339 | if (Options::xplanetLabel()) | | |||
1340 | { | | |||
1341 | args << "-fontsize" << Options::xplanetFontSize() << "-color" | | |||
1342 | << "0x" + Options::xplanetColor().mid(1) << "-date_format" << Options::xplanetDateFormat(); | | |||
1343 | | ||||
1344 | if (Options::xplanetLabelGMT()) | | |||
1345 | args << "-gmtlabel"; | | |||
1346 | else | | |||
1347 | args << "-label"; | | |||
1348 | if (!Options::xplanetLabelString().isEmpty()) | | |||
1349 | args << "-label_string" | | |||
1350 | << "\"" + Options::xplanetLabelString() + "\""; | | |||
1351 | if (Options::xplanetLabelTL()) | | |||
1352 | args << "-labelpos" | | |||
1353 | << "+15+15"; | | |||
1354 | else if (Options::xplanetLabelTR()) | | |||
1355 | args << "-labelpos" | | |||
1356 | << "-15+15"; | | |||
1357 | else if (Options::xplanetLabelBR()) | | |||
1358 | args << "-labelpos" | | |||
1359 | << "-15-15"; | | |||
1360 | else if (Options::xplanetLabelBL()) | | |||
1361 | args << "-labelpos" | | |||
1362 | << "+15-15"; | | |||
1363 | } | | |||
1364 | | ||||
1365 | // Markers | | |||
1366 | if (Options::xplanetMarkerFile()) | | |||
1367 | args << "-marker_file" << Options::xplanetMarkerFilePath(); | | |||
1368 | if (Options::xplanetMarkerBounds()) | | |||
1369 | args << "-markerbounds" << Options::xplanetMarkerBoundsPath(); | | |||
1370 | | ||||
1371 | // Position | | |||
1372 | if (Options::xplanetRandom()) | | |||
1373 | args << "-random"; | | |||
1374 | else | | |||
1375 | args << "-latitude" << Options::xplanetLatitude() << "-longitude" << Options::xplanetLongitude(); | | |||
1376 | | ||||
1377 | // Projection | | |||
1378 | if (Options::xplanetProjection()) | | |||
1379 | { | | |||
1380 | switch (Options::xplanetProjection()) | | |||
1381 | { | | |||
1382 | case 1: | | |||
1383 | args << "-projection" | | |||
1384 | << "ancient"; | | |||
1385 | break; | | |||
1386 | case 2: | | |||
1387 | args << "-projection" | | |||
1388 | << "azimuthal"; | | |||
1389 | break; | | |||
1390 | case 3: | | |||
1391 | args << "-projection" | | |||
1392 | << "bonne"; | | |||
1393 | break; | | |||
1394 | case 4: | | |||
1395 | args << "-projection" | | |||
1396 | << "gnomonic"; | | |||
1397 | break; | | |||
1398 | case 5: | | |||
1399 | args << "-projection" | | |||
1400 | << "hemisphere"; | | |||
1401 | break; | | |||
1402 | case 6: | | |||
1403 | args << "-projection" | | |||
1404 | << "lambert"; | | |||
1405 | break; | | |||
1406 | case 7: | | |||
1407 | args << "-projection" | | |||
1408 | << "mercator"; | | |||
1409 | break; | | |||
1410 | case 8: | | |||
1411 | args << "-projection" | | |||
1412 | << "mollweide"; | | |||
1413 | break; | | |||
1414 | case 9: | | |||
1415 | args << "-projection" | | |||
1416 | << "orthographic"; | | |||
1417 | break; | | |||
1418 | case 10: | | |||
1419 | args << "-projection" | | |||
1420 | << "peters"; | | |||
1421 | break; | | |||
1422 | case 11: | | |||
1423 | args << "-projection" | | |||
1424 | << "polyconic"; | | |||
1425 | break; | | |||
1426 | case 12: | | |||
1427 | args << "-projection" | | |||
1428 | << "rectangular"; | | |||
1429 | break; | | |||
1430 | case 13: | | |||
1431 | args << "-projection" | | |||
1432 | << "tsc"; | | |||
1433 | break; | | |||
1434 | default: | | |||
1435 | break; | | |||
1436 | } | | |||
1437 | if (Options::xplanetBackground()) | | |||
1438 | { | | |||
1439 | if (Options::xplanetBackgroundImage()) | | |||
1440 | args << "-background" << Options::xplanetBackgroundImagePath(); | | |||
1441 | else | | |||
1442 | args << "-background" | | |||
1443 | << "0x" + Options::xplanetBackgroundColorValue().mid(1); | | |||
1444 | } | | |||
1445 | } | | |||
1446 | | ||||
1447 | // We add this option at the end otherwise it does not work (???) | | |||
1448 | args << "-origin" | | |||
1449 | << "earth"; | | |||
1450 | | ||||
1451 | // Run xplanet | | |||
1452 | //qDebug() << "Run:" << xplanetProc->program().join(" "); | | |||
1453 | | ||||
1454 | #ifdef Q_OS_OSX | | |||
1455 | if (Options::xplanetIsInternal()) | | |||
1456 | { | | |||
1457 | QString searchDir = QCoreApplication::applicationDirPath() + "/xplanet/share/xplanet/"; | | |||
1458 | args << "-searchdir" << searchDir; | | |||
1459 | } | | |||
1460 | #endif | | |||
1461 | xplanetProc->start(xPlanetLocation, args); | | |||
1462 | if (xplanetProc) | | |||
1463 | { | | |||
1464 | xplanetProc->waitForFinished(1000); | | |||
1465 | new ImageViewer(QUrl::fromLocalFile(outputFile), | | |||
1466 | "XPlanet View: " + clickedObject()->name() + ", " + data->lt().date().toString() + ", " + | | |||
1467 | data->lt().time().toString(), | | |||
1468 | this); | | |||
1469 | //iv->show(); | | |||
1470 | } | | |||
1471 | else | 1276 | else | ||
1472 | { | 1277 | new XPlanetImageViewer(i18n("Saturn"), this); | ||
1473 | KMessageBox::sorry(this, i18n("XPlanet Program Error")); | | |||
1474 | } | | |||
1475 | } | 1278 | } | ||
1476 | 1279 | | |||
1477 | void SkyMap::slotXplanetToWindow() | | |||
1478 | { | | |||
1479 | QDir writableDir; | | |||
1480 | QString xPlanetDirPath = KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + "xplanet"; | | |||
1481 | writableDir.mkpath(xPlanetDirPath); | | |||
1482 | QString xPlanetPath = xPlanetDirPath + QDir::separator() + clickedObject()->name() + ".png"; | | |||
1483 | startXplanet(xPlanetPath); | | |||
1484 | } | | |||
1485 | 1280 | | |||
1486 | void SkyMap::slotXplanetToFile() | | |||
1487 | { | | |||
1488 | QString filename = QFileDialog::getSaveFileName(); | | |||
1489 | if (!filename.isEmpty()) | | |||
1490 | { | | |||
1491 | startXplanet(filename); | | |||
1492 | } | | |||
1493 | } | |