279 - context menu entry "back to the star" (qt and gtk)
279 - cleanup as requestedpull/3/head
parent
85fa5ddade
commit
3bc970c780
|
@ -9,6 +9,8 @@ set(CELESTIA_SOURCES
|
|||
eclipsefinder.h
|
||||
favorites.cpp
|
||||
favorites.h
|
||||
helper.cpp
|
||||
helper.h
|
||||
imagecapture.cpp
|
||||
imagecapture.h
|
||||
moviecapture.h
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include <celengine/simulation.h>
|
||||
#include <celestia/celestiacore.h>
|
||||
#include <celestia/helper.h>
|
||||
#include <celutil/utf8.h>
|
||||
|
||||
#include "menu-context.h"
|
||||
|
@ -26,6 +27,7 @@
|
|||
static void wrapAction(GtkAction* action);
|
||||
static void menuMark();
|
||||
static void menuUnMark();
|
||||
static void handleContextPrimary();
|
||||
static void handleContextPlanet(gpointer data);
|
||||
static void handleContextSurface(gpointer data);
|
||||
|
||||
|
@ -66,6 +68,10 @@ void menuContext(float, float, Selection sel)
|
|||
AppendMenu(popup, NULL, "S_ync Orbit", gtk_action_group_get_action(app->agMain, "SyncSelection"));
|
||||
/* Add info eventually:
|
||||
* AppendMenu(popup, NULL, "_Info", 0); */
|
||||
if (Helper::hasPrimary(sel.body()))
|
||||
{
|
||||
AppendMenu(popup, GTK_SIGNAL_FUNC(handleContextPrimary), "Select Primary Body", NULL);
|
||||
}
|
||||
|
||||
const PlanetarySystem* satellites = sel.body()->getSatellites();
|
||||
if (satellites != NULL && satellites->getSystemSize() != 0)
|
||||
|
@ -204,6 +210,17 @@ static void handleContextPlanet(gpointer data)
|
|||
}
|
||||
|
||||
|
||||
/* CALLBACK: Handle an object's primary selection */
|
||||
static void handleContextPrimary()
|
||||
{
|
||||
Selection sel = app->simulation->getSelection();
|
||||
if (sel.body() != NULL)
|
||||
{
|
||||
app->simulation->setSelection(Helper::getPrimary(sel.body()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* CALLBACK: Handle an alternate surface from the context menu. */
|
||||
static void handleContextSurface(gpointer data)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
#include <celengine/body.h>
|
||||
#include <celengine/selection.h>
|
||||
#include "helper.h"
|
||||
|
||||
|
||||
constexpr const int SpacecraftPrimaryBody = Body::Planet | Body::DwarfPlanet | Body::Moon |
|
||||
Body::MinorMoon | Body::Asteroid | Body::Comet;
|
||||
|
||||
|
||||
bool Helper::hasPrimaryStar(const Body* body)
|
||||
{
|
||||
return body->getSystem() != nullptr && body->getSystem()->getStar() != nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool Helper::hasPrimaryBody(const Body* body, int classification)
|
||||
{
|
||||
return body->getSystem() != nullptr && body->getSystem()->getPrimaryBody() != nullptr &&
|
||||
(body->getSystem()->getPrimaryBody()->getClassification() & classification);
|
||||
}
|
||||
|
||||
|
||||
bool Helper::hasBarycenter(const Body* body)
|
||||
{
|
||||
PlanetarySystem *system = body->getSystem();
|
||||
if (system == nullptr || system->getPrimaryBody() == nullptr ||
|
||||
!(system->getPrimaryBody()->getClassification() & Body::Invisible))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int bodyIdx = 0; bodyIdx < system->getSystemSize(); bodyIdx++)
|
||||
{
|
||||
if (system->getBody(bodyIdx)->getClassification() & (Body::Planet | Body::DwarfPlanet))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Helper::hasPrimary(const Body* body)
|
||||
{
|
||||
switch (body->getClassification())
|
||||
{
|
||||
case Body::Planet:
|
||||
case Body::DwarfPlanet:
|
||||
case Body::Asteroid:
|
||||
case Body::Comet:
|
||||
return hasPrimaryStar(body);
|
||||
case Body::Moon:
|
||||
case Body::MinorMoon:
|
||||
return hasPrimaryBody(body, Body::Planet | Body::DwarfPlanet) ||
|
||||
hasBarycenter(body);
|
||||
case Body::Spacecraft:
|
||||
return hasPrimaryBody(body, SpacecraftPrimaryBody) || hasPrimaryStar(body);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Selection Helper::getPrimary(const Body* body)
|
||||
{
|
||||
PlanetarySystem* system = body->getSystem();
|
||||
if (system == nullptr)
|
||||
return Selection();
|
||||
|
||||
Body* primaryBody = system->getPrimaryBody();
|
||||
if (primaryBody != nullptr)
|
||||
{
|
||||
int primaryClass = primaryBody->getClassification();
|
||||
if (primaryClass & SpacecraftPrimaryBody)
|
||||
return Selection(primaryBody);
|
||||
|
||||
if ((primaryClass & Body::Invisible) &&
|
||||
(body->getClassification() & (Body::Moon | Body::MinorMoon)))
|
||||
{
|
||||
for (int bodyIdx = 0; bodyIdx < system->getSystemSize(); bodyIdx++)
|
||||
{
|
||||
Body *barycenterBody = system->getBody(bodyIdx);
|
||||
if (barycenterBody->getClassification() & (Body::Planet | Body::DwarfPlanet))
|
||||
return Selection(barycenterBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Star* primaryStar = system->getStar();
|
||||
if (primaryStar != nullptr)
|
||||
return Selection(primaryStar);
|
||||
|
||||
return Selection();
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef _HELPER_H_
|
||||
#define _HELPER_H_
|
||||
|
||||
class Body;
|
||||
class Selection;
|
||||
|
||||
class Helper
|
||||
{
|
||||
public:
|
||||
static bool hasPrimary(const Body* body);
|
||||
static Selection getPrimary(const Body* body);
|
||||
|
||||
private:
|
||||
static bool hasPrimaryStar(const Body* body);
|
||||
static bool hasPrimaryBody(const Body* body, int classification);
|
||||
static bool hasBarycenter(const Body* body);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -13,6 +13,7 @@
|
|||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <celestia/celestiacore.h>
|
||||
#include <celestia/helper.h>
|
||||
#include <celengine/axisarrow.h>
|
||||
#include <celengine/planetgrid.h>
|
||||
#include <fmt/printf.h>
|
||||
|
@ -180,20 +181,24 @@ SelectionPopup::SelectionPopup(const Selection& sel,
|
|||
addAction(action);
|
||||
}
|
||||
|
||||
// Reference vector submenu
|
||||
if (selection.body() != nullptr)
|
||||
{
|
||||
// Reference vector submenu
|
||||
QMenu* refVecMenu = createReferenceVectorMenu();
|
||||
addMenu(refVecMenu);
|
||||
}
|
||||
|
||||
if (selection.body() != nullptr)
|
||||
{
|
||||
// Alternate surface submenu
|
||||
QMenu* surfacesMenu = createAlternateSurfacesMenu();
|
||||
if (surfacesMenu != nullptr)
|
||||
addMenu(surfacesMenu);
|
||||
|
||||
if (Helper::hasPrimary(selection.body()))
|
||||
{
|
||||
QAction *action = new QAction(_("Select Primary Body"), this);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(slotSelectPrimary()));
|
||||
addAction(action);
|
||||
}
|
||||
|
||||
// Child object menus
|
||||
PlanetarySystem* sys = selection.body()->getSatellites();
|
||||
if (sys != nullptr)
|
||||
|
@ -498,6 +503,17 @@ void SelectionPopup::slotSelectAlternateSurface()
|
|||
}
|
||||
|
||||
|
||||
void SelectionPopup::slotSelectPrimary()
|
||||
{
|
||||
Body *selectedBody = selection.body();
|
||||
if (selectedBody != nullptr)
|
||||
{
|
||||
Simulation* sim = appCore->getSimulation();
|
||||
sim->setSelection(Helper::getPrimary(selectedBody));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SelectionPopup::slotSelectChildObject()
|
||||
{
|
||||
QAction* action = qobject_cast<QAction*>(sender());
|
||||
|
|
|
@ -36,6 +36,7 @@ Q_OBJECT
|
|||
void slotFollowSelection();
|
||||
void slotSyncOrbitSelection();
|
||||
void slotSelectAlternateSurface();
|
||||
void slotSelectPrimary();
|
||||
void slotSelectChildObject();
|
||||
void slotMark();
|
||||
void slotUnmark();
|
||||
|
|
Loading…
Reference in New Issue