diff --git a/CMakeLists.txt b/CMakeLists.txt index 42d57a882ecc4..24a291784d783 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -589,6 +589,7 @@ IF (STELLARIUM_GUI_MODE STREQUAL "Standard") ADD_PLUGIN(SkyCultureMaker 1) ADD_PLUGIN(SolarSystemEditor 1) ADD_PLUGIN(TimeNavigator 1) + ADD_PLUGIN(ObjectVisibility 1) ENDIF() ADD_PLUGIN(Vts 0) diff --git a/plugins/ObjectVisibility/CMakeLists.txt b/plugins/ObjectVisibility/CMakeLists.txt new file mode 100644 index 0000000000000..c9d784b65566e --- /dev/null +++ b/plugins/ObjectVisibility/CMakeLists.txt @@ -0,0 +1,6 @@ +# This is the cmake config file for the Object Visibility plugin +SET(OBJECTVISIBILITY_VERSION "${VERSION}") +ADD_DEFINITIONS(-DOBJECTVISIBILITY_PLUGIN_VERSION="${OBJECTVISIBILITY_VERSION}") +ADD_DEFINITIONS(-DOBJECTVISIBILITY_PLUGIN_LICENSE="GNU GPLv2 or later") + +ADD_SUBDIRECTORY( src ) diff --git a/plugins/ObjectVisibility/COPYING b/plugins/ObjectVisibility/COPYING new file mode 100644 index 0000000000000..b35f35c99338e --- /dev/null +++ b/plugins/ObjectVisibility/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/plugins/ObjectVisibility/ObjectVisibility.qrc b/plugins/ObjectVisibility/ObjectVisibility.qrc new file mode 100644 index 0000000000000..2cf00bb6e7559 --- /dev/null +++ b/plugins/ObjectVisibility/ObjectVisibility.qrc @@ -0,0 +1,6 @@ + + + bt_object_visibility_on.png + bt_object_visibility_off.png + + diff --git a/plugins/ObjectVisibility/bt_object_visibility_off.png b/plugins/ObjectVisibility/bt_object_visibility_off.png new file mode 100644 index 0000000000000..168bf3c9761b2 Binary files /dev/null and b/plugins/ObjectVisibility/bt_object_visibility_off.png differ diff --git a/plugins/ObjectVisibility/bt_object_visibility_on.png b/plugins/ObjectVisibility/bt_object_visibility_on.png new file mode 100644 index 0000000000000..ef6883cf6bc8d Binary files /dev/null and b/plugins/ObjectVisibility/bt_object_visibility_on.png differ diff --git a/plugins/ObjectVisibility/icons.svg b/plugins/ObjectVisibility/icons.svg new file mode 100644 index 0000000000000..8edb6017ad822 --- /dev/null +++ b/plugins/ObjectVisibility/icons.svg @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Object Visibility icon — follows EquationOfTime convention. + + + "off" layer: flat medium grey (#6d6d6d), no halo. + + + "on" layer: crisp white icon over a soft white halo (Inkscape's + + + "Drop Shadow with zero offset" recipe). + + + Both layers stamp the <g id="iconShape"/> defined in <defs>. + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/ObjectVisibility/src/CMakeLists.txt b/plugins/ObjectVisibility/src/CMakeLists.txt new file mode 100644 index 0000000000000..7f9d1ac0b62e3 --- /dev/null +++ b/plugins/ObjectVisibility/src/CMakeLists.txt @@ -0,0 +1,52 @@ +INCLUDE_DIRECTORIES(. gui) +LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src) + +SET(ObjectVisibility_SRCS + ObjectVisibility.hpp + ObjectVisibility.cpp +) +IF (STELLARIUM_GUI_MODE STREQUAL "Standard") +LIST(APPEND ObjectVisibility_SRCS + gui/ObjectVisibilityDialog.hpp + gui/ObjectVisibilityDialog.cpp + gui/ObjectVisibilityMapWidget.hpp + gui/ObjectVisibilityMapWidget.cpp +) + +SET(ObjectVisibility_UIS + gui/objectVisibilityDialog.ui +) +ENDIF (STELLARIUM_GUI_MODE STREQUAL "Standard") + +################# compiles resources files ############ +SET(ObjectVisibility_RES ../ObjectVisibility.qrc) +IF (${QT_VERSION_MAJOR} EQUAL "5") + IF (STELLARIUM_GUI_MODE STREQUAL "Standard") + QT5_WRAP_UI(ObjectVisibility_UIS_H ${ObjectVisibility_UIS}) + ENDIF() + QT5_ADD_RESOURCES(ObjectVisibility_RES_CXX ${ObjectVisibility_RES}) +ELSE() + IF (STELLARIUM_GUI_MODE STREQUAL "Standard") + QT_WRAP_UI(ObjectVisibility_UIS_H ${ObjectVisibility_UIS}) + ENDIF() + QT_ADD_RESOURCES(ObjectVisibility_RES_CXX ${ObjectVisibility_RES}) +ENDIF() + +ADD_LIBRARY(ObjectVisibility-static STATIC + ${ObjectVisibility_SRCS} + ${ObjectVisibility_RES_CXX} + ${ObjectVisibility_UIS_H}) + +TARGET_LINK_LIBRARIES(ObjectVisibility-static + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::OpenGL) + +SET_TARGET_PROPERTIES(ObjectVisibility-static PROPERTIES + OUTPUT_NAME "ObjectVisibility") +SET_TARGET_PROPERTIES(ObjectVisibility-static PROPERTIES + COMPILE_FLAGS "-DQT_STATICPLUGIN") +ADD_DEPENDENCIES(AllStaticPlugins ObjectVisibility-static) + +SET_TARGET_PROPERTIES(ObjectVisibility-static PROPERTIES + FOLDER "plugins/ObjectVisibility") diff --git a/plugins/ObjectVisibility/src/ObjectVisibility.cpp b/plugins/ObjectVisibility/src/ObjectVisibility.cpp new file mode 100644 index 0000000000000..1e8176e1882ba --- /dev/null +++ b/plugins/ObjectVisibility/src/ObjectVisibility.cpp @@ -0,0 +1,204 @@ +/* + * Object Visibility plug-in for Stellarium + * + * Copyright (C) 2026 Atque + * + * Concept inspired by: + * Astro-Geo-GIS, "The 49 brightest stars in the night sky – when and + * where can we see them?", https://astro-geo-gis.com/ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. + */ + +#include "ObjectVisibility.hpp" +#include "gui/ObjectVisibilityDialog.hpp" + +#include "StelApp.hpp" +#include "StelCore.hpp" +#include "StelGui.hpp" +#include "StelGuiItems.hpp" +#include "StelModuleMgr.hpp" +#include "StelTranslator.hpp" + +#include +#include +#include +#include +#include + +// +// =================== Plug-in interface (Qt plug-in system) =================== +// + +StelModule* ObjectVisibilityStelPluginInterface::getStelModule() const +{ + return new ObjectVisibility(); +} + +StelPluginInfo ObjectVisibilityStelPluginInterface::getPluginInfo() const +{ + // Required when used as a static plug-in. + Q_INIT_RESOURCE(ObjectVisibility); + + StelPluginInfo info; + info.id = "ObjectVisibility"; + info.displayedName = N_("Object Visibility"); + info.authors = "Atque"; + info.contact = "https://github.com/Atque"; + info.description = N_("Shows on a planet map where a selected star or " + "deep-sky object is visible. Supports observation " + "from Earth, the Moon, the eight planets, Pluto, " + "and the four Galilean moons. Based on the " + "geometric criteria of the Astro-Geo-GIS article " + "\"The 49 brightest stars in the night sky – when " + "and where can we see them?\""); + info.version = OBJECTVISIBILITY_PLUGIN_VERSION; + info.license = OBJECTVISIBILITY_PLUGIN_LICENSE; + return info; +} + +// +// =================== ObjectVisibility ==================== +// + +ObjectVisibility::ObjectVisibility() + : goodVisibilityLimit(5) + , conf(nullptr) +#ifndef NO_GUI + , configDialog(nullptr) + , toolbarButton(nullptr) +#endif +{ + setObjectName("ObjectVisibility"); + +#ifndef NO_GUI + configDialog = new ObjectVisibilityDialog(); +#endif + conf = StelApp::getInstance().getSettings(); +} + +ObjectVisibility::~ObjectVisibility() +{ +#ifndef NO_GUI + delete configDialog; + configDialog = nullptr; +#endif +} + +double ObjectVisibility::getCallOrder(StelModuleActionName actionName) const +{ + Q_UNUSED(actionName); + // We don't draw on the sky, so the order doesn't really matter. + return 0.0; +} + +bool ObjectVisibility::configureGui(bool show) +{ +#ifdef NO_GUI + Q_UNUSED(show); + return false; +#else + if (show) + configDialog->setVisible(true); + return true; +#endif +} + +void ObjectVisibility::init() +{ + loadSettings(); + + // Defensive: ensure our qrc is registered. Q_INIT_RESOURCE is + // idempotent — calling it twice is safe. We do this here in + // addition to in getPluginInfo() so that even if some unusual + // loading order happens, our pixmaps are guaranteed to be + // accessible when the toolbar button is built below. +#ifndef NO_GUI + Q_INIT_RESOURCE(ObjectVisibility); +#endif + + const QString section = N_("Object Visibility"); + // A StelAction that toggles the dialog's visibility. Note that + // the dialog itself is a StelDialog with a `visible` property, so + // we hook the action directly to it. +#ifndef NO_GUI + addAction("actionShow_ObjectVisibility_dialog", + section, + N_("Object Visibility plug-in dialog"), + configDialog, + "visible", + ""); // no default shortcut + + // Toolbar button (only if we have the standard GUI). + try + { + StelGui* gui = dynamic_cast(StelApp::getInstance().getGui()); + if (gui != nullptr) + { + // Icon PNGs are supplied at 5x scale (160x160) because + // Stellarium's GUI uses GUI_INPUT_PIXMAPS_SCALE = 5 to + // downscale into the actual ~32px logical button size. + // Supplying smaller PNGs makes the button appear tiny. + toolbarButton = new StelButton( + nullptr, + QPixmap(":/ObjectVisibility/bt_object_visibility_on.png"), + QPixmap(":/ObjectVisibility/bt_object_visibility_off.png"), + QPixmap(":/graphicGui/miscGlow32x32.png"), + "actionShow_ObjectVisibility_dialog"); + gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGroup"); + } + } + catch (std::runtime_error& e) + { + qWarning() << "[ObjectVisibility] Unable to create toolbar button:" + << e.what(); + } +#endif +} + +void ObjectVisibility::loadSettings() +{ + Q_ASSERT(conf); + conf->beginGroup("ObjectVisibility"); + const int v = conf->value("good_visibility_limit", 5).toInt(); + conf->endGroup(); + setGoodVisibilityLimit(std::clamp(v, 1, 89)); +} + +void ObjectVisibility::restoreDefaultSettings() +{ + Q_ASSERT(conf); + conf->beginGroup("ObjectVisibility"); + conf->remove(""); // wipe section + conf->setValue("good_visibility_limit", 5); + conf->endGroup(); + loadSettings(); +} + +void ObjectVisibility::setGoodVisibilityLimit(int degrees) +{ + degrees = std::clamp(degrees, 1, 89); + if (degrees == goodVisibilityLimit) + return; + goodVisibilityLimit = degrees; + + if (conf) + { + conf->beginGroup("ObjectVisibility"); + conf->setValue("good_visibility_limit", goodVisibilityLimit); + conf->endGroup(); + } + emit goodVisibilityLimitChanged(goodVisibilityLimit); +} diff --git a/plugins/ObjectVisibility/src/ObjectVisibility.hpp b/plugins/ObjectVisibility/src/ObjectVisibility.hpp new file mode 100644 index 0000000000000..0e5486432f49d --- /dev/null +++ b/plugins/ObjectVisibility/src/ObjectVisibility.hpp @@ -0,0 +1,129 @@ +/* + * Object Visibility plug-in for Stellarium + * + * Copyright (C) 2026 Atque + * + * Concept inspired by: + * Astro-Geo-GIS, "The 49 brightest stars in the night sky – when and + * where can we see them?", https://astro-geo-gis.com/ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. + */ + +#ifndef OBJECTVISIBILITY_HPP +#define OBJECTVISIBILITY_HPP + +#include +#include "StelModule.hpp" +#include "StelFader.hpp" + +class QSettings; +class StelButton; +class ObjectVisibilityDialog; + +/*! @defgroup objectVisibility Object Visibility Plug-in +@{ +A plugin to visualise where on Earth a given star (or DSO) can be seen, +based on the simple geometric criteria described in the Astro-Geo-GIS +article "The 49 brightest stars in the night sky – when and where can +we see them?". + +Given a star with declination @f$\delta@f$ at the current epoch +(precession + proper motion taken into account): + + - **Limit of visibility:** latitudes outside [@f$\delta-90°@f$, + @f$\delta+90°@f$] never see the star above the horizon. + - **"Good visibility" limit (default +5°):** latitudes within + [@f$\delta-(90°-h)@f$, @f$\delta+(90°-h)@f$] see the star reach at + least altitude @f$h@f$ at upper culmination. + - **Passes zenith:** at latitude @f$\delta@f$ the star passes through + the zenith. + - **Circumpolar limit, north / south hemisphere:** at latitudes + @f$\geq 90°-\delta@f$ (resp. @f$\leq -90°-\delta@f$) the star never + sets. + +The plugin does **not** handle planets, the Sun, the Moon, asteroids, +comets or artificial satellites: their motion across the sky is too +fast for a single static snapshot to be useful. +@} +*/ + +//! Main class for the Object Visibility plug-in. +//! @ingroup objectVisibility +class ObjectVisibility : public StelModule +{ + Q_OBJECT + // Configurable "good visibility" altitude limit, in degrees. + // Stored in config.ini; default 5°. + Q_PROPERTY(int goodVisibilityLimit + READ getGoodVisibilityLimit + WRITE setGoodVisibilityLimit + NOTIFY goodVisibilityLimitChanged) + +public: + ObjectVisibility(); + ~ObjectVisibility() override; + + /////////////////////////////////////////////////////////////////////////// + // Methods defined in the StelModule class + void init() override; + void update(double deltaTime) override { Q_UNUSED(deltaTime); } + // We do not draw anything on the sky. All drawing happens inside our + // own widget. Keeping draw() empty is the cheapest possible + // implementation, which is important for keeping FPS high. + void draw(class StelCore* core) override { Q_UNUSED(core); } + double getCallOrder(StelModuleActionName actionName) const override; + bool configureGui(bool show=true) override; + /////////////////////////////////////////////////////////////////////////// + + //! Restore default settings to config.ini and reload them. + void restoreDefaultSettings(); + //! Load settings from config.ini ("ObjectVisibility/..." section). + void loadSettings(); + + int getGoodVisibilityLimit() const { return goodVisibilityLimit; } + +signals: + void goodVisibilityLimitChanged(int degrees); + +public slots: + void setGoodVisibilityLimit(int degrees); + +private: + int goodVisibilityLimit; //!< degrees, range [1, 89] + QSettings* conf; + +#ifndef NO_GUI + ObjectVisibilityDialog* configDialog; + StelButton* toolbarButton; +#endif +}; + + + +#include "StelPluginInterface.hpp" + +//! Plug-in interface used by Qt's plug-in system. +class ObjectVisibilityStelPluginInterface : public QObject, public StelPluginInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID StelPluginInterface_iid) + Q_INTERFACES(StelPluginInterface) +public: + StelModule* getStelModule() const override; + StelPluginInfo getPluginInfo() const override; +}; + +#endif // OBJECTVISIBILITY_HPP diff --git a/plugins/ObjectVisibility/src/gui/ObjectVisibilityDialog.cpp b/plugins/ObjectVisibility/src/gui/ObjectVisibilityDialog.cpp new file mode 100644 index 0000000000000..90b44d8beb3eb --- /dev/null +++ b/plugins/ObjectVisibility/src/gui/ObjectVisibilityDialog.cpp @@ -0,0 +1,572 @@ +/* + * Object Visibility plug-in for Stellarium + * + * Copyright (C) 2026 Atque + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. + */ + +#include "ObjectVisibilityDialog.hpp" +#include "ObjectVisibility.hpp" +#include "ObjectVisibilityMapWidget.hpp" +#include "ui_objectVisibilityDialog.h" + +#include "StelApp.hpp" +#include "StelCore.hpp" +#include "StelFileMgr.hpp" +#include "StelGui.hpp" +#include "StelLocation.hpp" +#include "StelModuleMgr.hpp" +#include "StelObjectMgr.hpp" +#include "StelTranslator.hpp" +#include "StelUtils.hpp" +#include "modules/Planet.hpp" +#include "modules/SolarSystem.hpp" + +#include +#include +#include +#include +#include +#include + +ObjectVisibilityDialog::ObjectVisibilityDialog() + : StelDialog("ObjectVisibility") + , ui(new Ui_objectVisibilityDialog()) + , plugin(nullptr) +{ +} + +ObjectVisibilityDialog::~ObjectVisibilityDialog() +{ + delete ui; + ui = nullptr; +} + +void ObjectVisibilityDialog::retranslate() +{ + if (dialog) + { + ui->retranslateUi(dialog); + setAboutHtml(); + refreshTitleLabel(); + } +} + +// +// =================== Construction ==================== +// + +void ObjectVisibilityDialog::createDialogContent() +{ + plugin = GETSTELMODULE(ObjectVisibility); + Q_ASSERT(plugin); + ui->setupUi(dialog); + + // Standard kinetic scrolling for the About browser. + kineticScrollingList << ui->aboutTextBrowser; + StelGui* gui = static_cast(StelApp::getInstance().getGui()); + if (gui) + { + enableKineticScrolling(gui->getFlagUseKineticScrolling()); + // enableKineticScrolling is protected in StelDialog, so we + // can't take its address from outside the class hierarchy. + // Calling it from inside a lambda works because the lambda + // is a member-function context with access to inherited + // protected members. + connect(gui, &StelGui::flagUseKineticScrollingChanged, + this, [this](bool b){ enableKineticScrolling(b); }); + } + + // Localisation + close button. + connect(&StelApp::getInstance(), &StelApp::languageChanged, + this, &ObjectVisibilityDialog::retranslate); + connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close); + connect(ui->titleBar, &TitleBar::movedTo, + this, &StelDialog::handleMovedTo); + + // "Good visibility" spinbox. + ui->goodVisibilityLimitSpinBox->setRange(1, 89); + ui->goodVisibilityLimitSpinBox->setSingleStep(1); + ui->goodVisibilityLimitSpinBox->setValue(plugin->getGoodVisibilityLimit()); + connect(ui->goodVisibilityLimitSpinBox, + QOverload::of(&QSpinBox::valueChanged), + this, &ObjectVisibilityDialog::onGoodVisibilityLimitChanged); + // Push the same value back into the map widget at startup so the + // dashed line uses the correct altitude limit straight away. + ui->mapWidget->setGoodVisibilityAltitude(plugin->getGoodVisibilityLimit()); + + // Buttons. + connect(ui->calculatePushButton, &QPushButton::clicked, + this, &ObjectVisibilityDialog::calculate); + connect(ui->setLocationByClickCheckBox, &QCheckBox::toggled, + this, &ObjectVisibilityDialog::onSetLocationByClickToggled); + connect(ui->resetSettingsPushButton, &QPushButton::clicked, + this, &ObjectVisibilityDialog::onResetSettings); + + // Map clicks while in "set location" mode. + connect(ui->mapWidget, &ObjectVisibilityMapWidget::locationPicked, + this, &ObjectVisibilityDialog::onLocationPicked); + + // Track Stellarium's selection so we can enable/disable Calculate + // and update the prompt label. The signal carries a + // StelModuleSelectAction enum we don't care about — drop it with + // a lambda so the slot can stay parameter-free. + StelObjectMgr* objMgr = GETSTELMODULE(StelObjectMgr); + if (objMgr) + { + connect(objMgr, &StelObjectMgr::selectedObjectChanged, + this, [this](StelModule::StelModuleSelectAction) + { onSelectedObjectChanged(); }); + } + + // Keep the marker on the map in sync with the observer's current + // position — whether the user moved it from our dialog, from the + // Location dialog, or from any other source. + StelCore* core = StelApp::getInstance().getCore(); + connect(core, &StelCore::locationChanged, + this, &ObjectVisibilityDialog::syncMarkerToObserver); + syncMarkerToObserver(); + + setAboutHtml(); + refreshTitleLabel(); + updateCalculateButtonEnabled(); +} + +// +// =================== Actions ==================== +// + +bool ObjectVisibilityDialog::isAcceptableType(const QString& type) +{ + // "Star" covers normal stars (StarWrapper) and "Nebula" covers all + // DSOs in Stellarium's nomenclature. We deliberately exclude + // planets, moons, comets, asteroids, satellites, etc. + return (type == QStringLiteral("Star")) || + (type == QStringLiteral("Nebula")); +} + +void ObjectVisibilityDialog::onSelectedObjectChanged() +{ + updateCalculateButtonEnabled(); + // In the pre-Calculate state, the label depends on what's + // selected — refresh it so the user gets immediate feedback + // about whether the new selection is acceptable. Once + // Calculate has been pressed, the label shows the result + // and is unaffected by subsequent selection changes. + refreshTitleLabel(); +} + +void ObjectVisibilityDialog::updateCalculateButtonEnabled() +{ + StelObjectMgr* objMgr = GETSTELMODULE(StelObjectMgr); + bool typeOk = false; + if (objMgr && !objMgr->getSelectedObject().isEmpty()) + { + const StelObjectP sel = objMgr->getSelectedObject().first(); + typeOk = isAcceptableType(sel->getType()); + } + + StelCore* core = StelApp::getInstance().getCore(); + const QString planet = core->getCurrentLocation().planetName; + const bool planetOk = isSupportedPlanet(planet); + + const bool acceptable = typeOk && planetOk; + ui->calculatePushButton->setEnabled(acceptable); + + QString tip; + if (!typeOk) + tip = q_("Only stars and DSOs may be used in this plugin!"); + else if (!planetOk) + tip = q_("This plug-in supports observation from Earth, the " + "Moon, the eight planets, Pluto and the four Galilean " + "moons. The current observing body (%1) is not " + "supported.").arg(planet); + else + tip = q_("Compute visibility for the selected object."); + ui->calculatePushButton->setToolTip(tip); +} + +void ObjectVisibilityDialog::calculate() +{ + StelObjectMgr* objMgr = GETSTELMODULE(StelObjectMgr); + if (!objMgr || objMgr->getSelectedObject().isEmpty()) + return; + + const StelObjectP sel = objMgr->getSelectedObject().first(); + if (!isAcceptableType(sel->getType())) + return; + + // Remember which object we computed for, so the title label can + // be refreshed on retranslate without re-running the geometry. + // We use getID() because it is the only identifier guaranteed to + // be unique within a type (e.g. "HIP 32349" for Sirius). + lockedObjectId = sel->getID(); + lockedObjectType = sel->getType(); + lockedObjectNameI18n = sel->getNameI18n(); + if (lockedObjectNameI18n.isEmpty()) + lockedObjectNameI18n = sel->getEnglishName(); + if (lockedObjectNameI18n.isEmpty()) + lockedObjectNameI18n = lockedObjectId; + + StelCore* core = StelApp::getInstance().getCore(); + // getEquinoxEquatorialPos() returns the equatorial coordinates at + // the *current* equinox (date), which is exactly what the spec requires: + // precession and (where applicable) proper motion are folded in, + // so plotting Sirius at 10000 BCE uses Sirius's position at that + // time, not its J2000 position. + double ra, dec; + StelUtils::rectToSphe(&ra, &dec, sel->getEquinoxEquatorialPos(core)); + const double decDeg = dec * 180.0 / M_PI; + + ui->mapWidget->setDeclination(decDeg); + refreshTitleLabel(); +} + +void ObjectVisibilityDialog::onGoodVisibilityLimitChanged(int degrees) +{ + plugin->setGoodVisibilityLimit(degrees); + ui->mapWidget->setGoodVisibilityAltitude(degrees); +} + +void ObjectVisibilityDialog::onSetLocationByClickToggled(bool on) +{ + ui->mapWidget->setClickSetsLocationMode(on); +} + +void ObjectVisibilityDialog::onLocationPicked(double longitude, + double latitude, + const QColor &color) +{ + Q_UNUSED(color); + // Note: we deliberately do NOT exit click-to-set mode here. + // The user explicitly enabled the checkbox so they can pick as + // many locations as they like; they uncheck when they're done. + + // Move the observer to the picked spot. We keep the rest of the + // current location (planet, altitude, name) untouched. + StelCore* core = StelApp::getInstance().getCore(); + StelLocation loc = core->getCurrentLocation(); + loc.setLatitude(static_cast(latitude)); + loc.setLongitude(static_cast(longitude)); + loc.name = QString("%1, %2") + .arg(loc.getLatitude()) + .arg(loc.getLongitude()); + // Quick move (no animation) so it feels responsive. + core->moveObserverTo(loc, 0.0, 0.0); + + // Move the on-map marker immediately, without waiting for + // StelCore::locationChanged to arrive — that signal is emitted + // after the (async) move completes, which would feel laggy. + ui->mapWidget->setMarkerPos(longitude, latitude); +} + +void ObjectVisibilityDialog::onResetSettings() +{ + if (!askConfirmation()) + return; + plugin->restoreDefaultSettings(); + // Refresh the visible controls so they match what we just wrote. + const int g = plugin->getGoodVisibilityLimit(); + ui->goodVisibilityLimitSpinBox->setValue(g); + ui->mapWidget->setGoodVisibilityAltitude(g); +} + +void ObjectVisibilityDialog::syncMarkerToObserver() +{ + if (!ui || !ui->mapWidget) return; + const StelLocation& loc = + StelApp::getInstance().getCore()->getCurrentLocation(); + + // (1) If the user has moved to a different planet since we last + // loaded a texture, swap the map texture. We mirror LocationDialog's + // approach: Earth uses miscWorldMap.jpg (no clouds); other bodies + // use Stellarium's stored planet texture identified by their + // englishName. + if (loc.planetName != cachedPlanetName) + { + QPixmap pixmap; + if (loc.planetName == QStringLiteral("Earth")) + { + pixmap = QPixmap(":/graphicGui/miscWorldMap.jpg"); + } + else + { + SolarSystem* ssm = GETSTELMODULE(SolarSystem); + PlanetP p = ssm ? ssm->searchByEnglishName(loc.planetName) : PlanetP(); + if (p) + { + QString path = StelFileMgr::findFile( + "textures/" + p->getTextMapName()); + if (!path.isEmpty()) + pixmap = QPixmap(path); + else + qWarning() << "[ObjectVisibility] " + "no texture for planet" + << loc.planetName; + } + } + if (!pixmap.isNull()) + ui->mapWidget->setMap(pixmap); + cachedPlanetName = loc.planetName; + } + + // (2) Update the location marker. getLatitude(true)/ + // getLongitude(true) returns the *configured* position even when + // the observer is on a planet other than Earth, which is exactly + // what we want here. + const float lat = loc.getLatitude(true); + const float lon = loc.getLongitude(true); + ui->mapWidget->setMarkerPos(static_cast(lon), + static_cast(lat)); + + // (3) Refresh the Calculate-enabled state and title label, since + // both depend on whether the current planet is supported. + updateCalculateButtonEnabled(); + refreshTitleLabel(); +} + +bool ObjectVisibilityDialog::isSupportedPlanet(const QString& englishName) +{ + // Bodies whose rotation-pole orientation is reliably known in + // Stellarium. Limiting to these guarantees the visibility lines + // reflect the body's real geometry. Other bodies may have + // approximate or default-equatorial poles which would give + // misleading lines. + static const QStringList supported = { + QStringLiteral("Earth"), + QStringLiteral("Moon"), + QStringLiteral("Mercury"), + QStringLiteral("Venus"), + QStringLiteral("Mars"), + QStringLiteral("Jupiter"), + QStringLiteral("Saturn"), + QStringLiteral("Uranus"), + QStringLiteral("Neptune"), + QStringLiteral("Pluto"), + // Galilean moons + QStringLiteral("Io"), + QStringLiteral("Europa"), + QStringLiteral("Ganymede"), + QStringLiteral("Callisto") + }; + return supported.contains(englishName); +} + +// +// =================== Helpers ==================== +// + +int ObjectVisibilityDialog::currentYear(StelCore* core) +{ + int y = 2000, m = 1, d = 1; + StelUtils::getDateFromJulianDay(core->getJD(), &y, &m, &d); + Q_UNUSED(m); + Q_UNUSED(d); + return y; +} + +void ObjectVisibilityDialog::refreshTitleLabel() +{ + if (!ui) return; + + // Pre-Calculate state: the label reflects what's currently selected + // in Stellarium so the user knows why Calculate is enabled or not. + // Three cases: + // 1. nothing selected → generic prompt + // 2. acceptable object selected → confirm with name + // 3. wrong-type object selected → say so explicitly, including + // the localised type name, so the user understands why + // Calculate is disabled. Tooltips on disabled buttons are + // not always discoverable; the label is. + if (lockedObjectId.isEmpty()) + { + StelObjectMgr* objMgr = GETSTELMODULE(StelObjectMgr); + if (!objMgr || objMgr->getSelectedObject().isEmpty()) + { + ui->titleLabel->setText( + q_("Select a star or DSO, then click Calculate.")); + return; + } + const StelObjectP sel = objMgr->getSelectedObject().first(); + if (isAcceptableType(sel->getType())) + { + QString name = sel->getNameI18n(); + if (name.isEmpty()) name = sel->getEnglishName(); + if (name.isEmpty()) name = sel->getID(); + ui->titleLabel->setText( + QString(q_("%1 is selected. Click Calculate.")) + .arg(name)); + } + else + { + // Map Stellarium's internal type string to a user-friendly + // localised description. We could ask the object itself + // via getObjectType() but that returns finer-grained + // English text ("star", "open cluster", ...) that may not + // be the most useful thing to surface in a "wrong type" + // message; a class-level descriptor reads more naturally. + const QString type = sel->getType(); + QString typeName; + if (type == QStringLiteral("Planet")) + typeName = q_("a planet, moon or the Sun"); + else if (type == QStringLiteral("Comet")) + typeName = q_("a comet"); + else if (type == QStringLiteral("MinorPlanet")) + typeName = q_("a minor planet"); + else if (type == QStringLiteral("Satellite")) + typeName = q_("an artificial satellite"); + else if (type == QStringLiteral("NomenclatureItem")) + typeName = q_("a surface feature"); + else if (type == QStringLiteral("Meteor")) + typeName = q_("a meteor"); + else + typeName = q_("not a star or deep-sky object"); + + QString name = sel->getNameI18n(); + if (name.isEmpty()) name = sel->getEnglishName(); + if (name.isEmpty()) name = sel->getID(); + ui->titleLabel->setText( + QString(q_("%1 is %2. This plug-in only supports stars " + "and deep-sky objects.")) + .arg(name) + .arg(typeName)); + } + return; + } + + // Post-Calculate state: show what we computed. + StelCore* core = StelApp::getInstance().getCore(); + const int year = currentYear(core); + const QString planet = core->getCurrentLocation().planetName; + + // Two translatable templates: the Earth case keeps the original + // phrasing; the non-Earth case adds the planet name. Splitting + // them lets translators adapt word order independently for each + // language. %1 = object name, %2 = year, %3 = planet name. + QString text; + if (planet == QStringLiteral("Earth")) + { + text = QString(q_("Visibility of %1 in %2")) + .arg(lockedObjectNameI18n) + .arg(year); + } + else + { + text = QString(q_("Visibility of %1 from %3 in %2")) + .arg(lockedObjectNameI18n) + .arg(year) + .arg(q_(planet.toUtf8().constData())); + } + ui->titleLabel->setText(text); +} + +void ObjectVisibilityDialog::setAboutHtml() +{ + QString html = ""; + html += "

" + q_("Object Visibility Plug-in") + "

"; + html += ""; + html += ""; + html += ""; + html += ""; + html += "
" + q_("Version") + ":" + + QString(OBJECTVISIBILITY_PLUGIN_VERSION) + "
" + q_("License") + ":" + + QString(OBJECTVISIBILITY_PLUGIN_LICENSE) + "
" + q_("Author") + ":Atque
"; + + html += "

" + q_("This plug-in shows on a planet map where on the " + "observer's planet a selected star or deep-sky " + "object is visible. Given an object with declination " + "δ at the current epoch (precession and proper " + "motion taken into account), five lines are drawn at " + "fixed geographic latitudes:") + "

"; + html += "
    "; + html += "
  • " + q_("Limit of visibility") + ": " + + q_("φ = δ ± 90°. The object never rises " + "above the horizon at latitudes outside this band.") + + "
  • "; + html += "
  • " + q_("Extinction free / good visibility") + ": " + + q_("φ = δ ± (90° − h). At latitudes " + "inside this band the object reaches at least altitude h " + "at upper culmination. The default h is 5°; you may " + "increase it if you observe from a mountainous site or " + "want a larger safety margin.") + + "
  • "; + html += "
  • " + q_("Passes zenith") + ": " + + q_("φ = δ. At this latitude the object passes " + "through the zenith.") + + "
  • "; + html += "
  • " + q_("Circumpolar limit, northern hemisphere") + ": " + + q_("φ = 90° − δ. North of this latitude " + "the object never sets.") + + "
  • "; + html += "
  • " + q_("Circumpolar limit, southern hemisphere") + ": " + + q_("φ = −90° − δ. South of this " + "latitude the object never sets.") + + "
  • "; + html += "
"; + + html += "

" + q_("Planets, moons, asteroids, comets and artificial " + "satellites are intentionally not supported as the " + "selected target: their rapid daily motion " + "(and, for some, parallax) would make a single " + "snapshot misleading.") + + "

"; + + html += "

" + q_("The plug-in does support observation from any of " + "the following bodies: Earth, the Moon, the eight " + "planets (Mercury through Neptune), Pluto, and the " + "four Galilean moons of Jupiter (Io, Europa, " + "Ganymede, Callisto). Change observer body via " + "Stellarium's Location dialog; the map updates " + "automatically.") + + "

"; + + html += "

" + q_("Because stellar positions change over time through " + "precession and proper motion, the lines are always " + "computed for the date currently shown in the " + "planetarium. To see Sirius's visibility in " + "10 000 BCE, set the planetarium's date " + "first, then press Calculate.") + + "

"; + + html += "

" + q_("Credits") + "

"; + html += "

" + q_("The whole concept of these visibility lines on a " + "world map – and in particular the choice of the " + "five line types and their visual style – comes " + "from Astro-Geo-GIS, in the article " + "The 49 brightest stars in the night sky – when " + "and where can we see them?") + + "

"; + html += "

" + + q_("Read the original article") + + "
" + + "" + + q_("Astro-Geo-GIS website") + + "

"; + + html += StelApp::getInstance().getModuleMgr() + .getStandardSupportLinksInfo("Object Visibility plug-in"); + + html += ""; + + StelGui* gui = dynamic_cast(StelApp::getInstance().getGui()); + if (gui) + { + QString stylesheet(gui->getStelStyle().htmlStyleSheet); + ui->aboutTextBrowser->document()->setDefaultStyleSheet(stylesheet); + } + ui->aboutTextBrowser->setHtml(html); +} diff --git a/plugins/ObjectVisibility/src/gui/ObjectVisibilityDialog.hpp b/plugins/ObjectVisibility/src/gui/ObjectVisibilityDialog.hpp new file mode 100644 index 0000000000000..7b2eb70c5a427 --- /dev/null +++ b/plugins/ObjectVisibility/src/gui/ObjectVisibilityDialog.hpp @@ -0,0 +1,113 @@ +/* + * Object Visibility plug-in for Stellarium + * + * Copyright (C) 2026 Atque + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. + */ + +#ifndef OBJECTVISIBILITYDIALOG_HPP +#define OBJECTVISIBILITYDIALOG_HPP + +#include "StelDialog.hpp" +#include + +class Ui_objectVisibilityDialog; +class ObjectVisibility; +class StelCore; + +//! Main window of the Object Visibility plug-in. +//! @ingroup objectVisibility +class ObjectVisibilityDialog : public StelDialog +{ + Q_OBJECT + +public: + ObjectVisibilityDialog(); + ~ObjectVisibilityDialog() override; + +public slots: + void retranslate() override; + +protected: + void createDialogContent() override; + +private slots: + //! User pressed "Calculate". Reads the current selection from + //! StelObjectMgr, computes the declination at the current epoch + //! and feeds it to the map widget. + void calculate(); + + //! Called whenever the user's selection in Stellarium changes; we + //! use it only to enable/disable the Calculate button so the user + //! gets immediate feedback that planets etc. are not supported. + void onSelectedObjectChanged(); + + //! Toggle "click on map to set location" mode on the map widget. + void onSetLocationByClickToggled(bool on); + + //! The user clicked the map while in click-to-set mode. + void onLocationPicked(double longitude, double latitude, + const QColor &color); + + //! Spinbox value changed. + void onGoodVisibilityLimitChanged(int degrees); + + //! Reset settings button. + void onResetSettings(); + + //! Re-sync the location marker AND the planet texture from + //! StelCore's current observer. Called on startup and whenever + //! StelCore reports a location change. + void syncMarkerToObserver(); + +private: + Ui_objectVisibilityDialog* ui; + ObjectVisibility* plugin; + + //! The object that was selected when Calculate was clicked. We + //! keep a reference so the title label can be refreshed (e.g. on + //! retranslate) without re-running the geometry. We hold it as + //! a type + ID (which is more stable than the English name + //! across releases). + QString lockedObjectId; + QString lockedObjectType; // "Star" or "Nebula" + QString lockedObjectNameI18n; // for label + + //! Cached english name of the planet whose texture is currently + //! displayed in the map widget. We compare against this to avoid + //! reloading the same texture when the observer just changes + //! geographic position on the same planet. + QString cachedPlanetName; + + void setAboutHtml(); + void refreshTitleLabel(); + void updateCalculateButtonEnabled(); + + //! Compute the year label in astronomical convention from the + //! StelCore's current JD. E.g. 2026, or -10000 for 10001 BCE. + static int currentYear(StelCore* core); + + //! True iff the given StelObject type is a star or a DSO (nebula). + static bool isAcceptableType(const QString& type); + + //! True iff the given (English) planet name is in our supported + //! list. We restrict to bodies whose rotation-pole orientation is + //! reliably known in Stellarium: Earth, Moon, the eight planets, + //! Pluto, and the four Galilean moons. + static bool isSupportedPlanet(const QString& englishName); +}; + +#endif // OBJECTVISIBILITYDIALOG_HPP diff --git a/plugins/ObjectVisibility/src/gui/ObjectVisibilityMapWidget.cpp b/plugins/ObjectVisibility/src/gui/ObjectVisibilityMapWidget.cpp new file mode 100644 index 0000000000000..624ceee047094 --- /dev/null +++ b/plugins/ObjectVisibility/src/gui/ObjectVisibilityMapWidget.cpp @@ -0,0 +1,247 @@ +/* + * Object Visibility plug-in for Stellarium + * + * Copyright (C) 2026 Atque + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. + */ + +#include "ObjectVisibilityMapWidget.hpp" + +#include +#include +#include +#include +#include +#include +#include + +ObjectVisibilityMapWidget::ObjectVisibilityMapWidget(QWidget* parent) + : MapWidget(parent) +{ + // We show the observer-location marker so the user can always + // tell where they currently are on Earth. The dialog updates + // its position whenever the observer moves. + setMarkerVisible(true); + + // Listen to the base class's clicks so we can decide whether to + // re-emit them upwards. + connect(this, &MapWidget::positionChanged, + this, &ObjectVisibilityMapWidget::onPositionChanged); +} + +void ObjectVisibilityMapWidget::setClickSetsLocationMode(bool on) +{ + if (clickToSetMode == on) return; + clickToSetMode = on; + setCursor(on ? Qt::CrossCursor : Qt::ArrowCursor); +} + +void ObjectVisibilityMapWidget::setDeclination(double declinationDeg_) +{ + if (declinationDeg_ < -90.0 || declinationDeg_ > 90.0) + { + clearVisibility(); + return; + } + hasDeclination = true; + declinationDeg = declinationDeg_; + update(); +} + +void ObjectVisibilityMapWidget::setGoodVisibilityAltitude(int degrees) +{ + if (degrees < 1) degrees = 1; + if (degrees > 89) degrees = 89; + if (goodVisibilityDeg == degrees) return; + goodVisibilityDeg = degrees; + if (hasDeclination) + update(); +} + +void ObjectVisibilityMapWidget::clearVisibility() +{ + if (!hasDeclination) return; + hasDeclination = false; + update(); +} + +void ObjectVisibilityMapWidget::onPositionChanged(double longitude, + double latitude, + const QColor& color) +{ + if (!clickToSetMode) return; + emit locationPicked(longitude, latitude, color); + // We deliberately stay in click-to-set mode so the user can pick + // multiple locations in a row. The dialog's checkbox is the + // canonical control; we only react to its state. +} + +// +// =================== Drawing ==================== +// + +namespace +{ +// Colour matching the screenshots in the article: solid blue line, a +// slightly lighter dashed line, blue plus marks and triangle markers. +const QColor LINE_COLOR = QColor(0, 60, 220, 255); +const QColor DASHED_COLOR = QColor(0, 60, 220, 220); +const QColor ZENITH_COLOR = QColor(0, 60, 220, 240); +const QColor TRIANGLE_COLOR = QColor(0, 60, 220, 255); +} // namespace + +void ObjectVisibilityMapWidget::drawLatitudeLine(QPainter& painter, + double latitudeDeg, + const QPen& pen) const +{ + if (latitudeDeg < -90.0 || latitudeDeg > 90.0) return; + + // Use the inherited helper from MapWidget to convert lat/lon to + // pixel space. The helper returns coordinates in DEVICE pixels. + const auto p = lonLatToMapPoint(0.0, latitudeDeg); + const double ratio = devicePixelRatioF(); + // MapWidget::paintEvent applies painter.scale(1/ratio, 1/ratio) + // and then works in device pixels. We do the same so our + // coordinate space matches the base class exactly. + const double y = p.y; + + painter.setPen(pen); + // Draw across the entire widget width (in device pixels) so the + // line still appears continuous over map wrap-arounds. + painter.drawLine(QPointF(0.0, y), + QPointF(width() * ratio, y)); +} + +void ObjectVisibilityMapWidget::drawLatitudeMarkers(QPainter& painter, + double latitudeDeg, + const QChar& marker, + const QColor& color) const +{ + if (latitudeDeg < -90.0 || latitudeDeg > 90.0) return; + + const auto p = lonLatToMapPoint(0.0, latitudeDeg); + const double ratio = devicePixelRatioF(); + const double y = p.y; + + // Pick a font size that scales with the widget height (and HiDPI). + // 12-14 pt at standard DPI looks good; we target ~14 logical pixels. + QFont font = painter.font(); + const int pixelSize = static_cast(std::round(14.0 * ratio)); + font.setPixelSize(std::max(8, pixelSize)); + font.setBold(true); + painter.setFont(font); + painter.setPen(color); + + const QFontMetrics fm(font); + const QString s(marker); + const int advance = +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + fm.horizontalAdvance(s); +#else + fm.width(s); +#endif + // Spacing between marks: roughly 1.6x the advance so they "kiss" + // without overlapping. Matches the article's screenshot pretty + // well across a wide range of zoom levels. + const double step = std::max(advance * 1.6, + 12.0 * ratio); + const double totalWidth = width() * ratio; + + // We draw the marker glyph centred on the latitude line. Qt's + // text baseline is offset from the y coordinate by the font + // ascent, so we add ascent/2 to roughly centre the glyph. + const double yText = y + fm.ascent() * 0.35; + + for (double x = step * 0.5; x < totalWidth; x += step) + { + painter.drawText(QPointF(x - advance * 0.5, yText), s); + } +} + +void ObjectVisibilityMapWidget::paintEvent(QPaintEvent* event) +{ + // Step 1: let MapWidget render the world map, the (hidden) marker, + // and any location filter. This is the cheapest way to keep + // pan/zoom/HiDPI behaviour identical to LocationDialog's map. + MapWidget::paintEvent(event); + + if (!hasDeclination) return; + + // Step 2: overlay our visibility lines. Like the base class, we + // work in device-pixel space. + QPainter painter(this); + const double ratio = devicePixelRatioF(); + painter.scale(1.0 / ratio, 1.0 / ratio); + painter.setRenderHint(QPainter::Antialiasing, true); + + const double dec = declinationDeg; + const double h = static_cast(goodVisibilityDeg); + + // Pen widths scale with HiDPI so lines look the same physical + // thickness on any monitor. + const double penW = std::max(1.0, 1.5 * ratio); + + // + // (1) Limit of visibility (solid). phi = dec +/- 90. + // + { + QPen pen(LINE_COLOR); + pen.setWidthF(penW); + pen.setCapStyle(Qt::FlatCap); + // One of phi_north / phi_south will be off-map; we just try + // both and the helper silently does nothing for the invalid + // one. + drawLatitudeLine(painter, dec + 90.0, pen); + drawLatitudeLine(painter, dec - 90.0, pen); + } + + // + // (2) Good-visibility (extinction-free) limit (dashed). + // phi = dec +/- (90 - h). + // + { + QPen pen(DASHED_COLOR); + pen.setWidthF(penW); + // A pattern that scales with line width so the dashes look + // right at any DPI. Numbers are in units of pen widths. + pen.setStyle(Qt::CustomDashLine); + pen.setDashPattern({6.0, 4.0}); + pen.setCapStyle(Qt::FlatCap); + drawLatitudeLine(painter, dec + (90.0 - h), pen); + drawLatitudeLine(painter, dec - (90.0 - h), pen); + } + + // + // (3) Passes zenith (+ marks). phi = dec. + // + drawLatitudeMarkers(painter, dec, QChar('+'), ZENITH_COLOR); + + // + // (4) Circumpolar limit, northern hemisphere (filled up-triangle). + // phi = 90 - dec. Only meaningful when 0 <= phi <= 90. + // + drawLatitudeMarkers(painter, 90.0 - dec, + QChar(0x25B2), // BLACK UP-POINTING TRIANGLE + TRIANGLE_COLOR); + + // + // (5) Circumpolar limit, southern hemisphere (filled down-triangle). + // phi = -90 - dec. Only meaningful when -90 <= phi <= 0. + // + drawLatitudeMarkers(painter, -90.0 - dec, + QChar(0x25BC), // BLACK DOWN-POINTING TRIANGLE + TRIANGLE_COLOR); +} diff --git a/plugins/ObjectVisibility/src/gui/ObjectVisibilityMapWidget.hpp b/plugins/ObjectVisibility/src/gui/ObjectVisibilityMapWidget.hpp new file mode 100644 index 0000000000000..4b663cc474ae2 --- /dev/null +++ b/plugins/ObjectVisibility/src/gui/ObjectVisibilityMapWidget.hpp @@ -0,0 +1,92 @@ +/* + * Object Visibility plug-in for Stellarium + * + * Copyright (C) 2026 Atque + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. + */ + +#ifndef OBJECTVISIBILITYMAPWIDGET_HPP +#define OBJECTVISIBILITYMAPWIDGET_HPP + +#include "MapWidget.hpp" + +//! A MapWidget subclass that: +//! 1. Optionally gates emission of positionChanged() through a "click +//! to set location" mode. Outside of that mode, the user can pan +//! and zoom freely without ever moving the observer. +//! 2. Overlays "visibility lines" on top of the map, computed from +//! the declination of a star/DSO. +//! +//! All five line types are simply parallels of geographic latitude: +//! - limit-of-visibility: phi = dec +/- 90 +//! - good-visibility: phi = dec +/- (90 - h_good) +//! - passes zenith: phi = dec +//! - circumpolar (N): phi = 90 - dec +//! - circumpolar (S): phi = -90 - dec +//! +//! A latitude that falls outside [-90, +90] is simply not drawn. +//! +//! @ingroup objectVisibility +class ObjectVisibilityMapWidget : public MapWidget +{ + Q_OBJECT + +public: + explicit ObjectVisibilityMapWidget(QWidget *parent = nullptr); + + //! Enable/disable "click on map to set observer location" mode. + //! In normal mode, clicks on the map do nothing (panning/zooming + //! still work). + void setClickSetsLocationMode(bool on); + bool clickSetsLocationMode() const { return clickToSetMode; } + + //! Set the declination (degrees, current epoch) of the object to + //! be plotted. Pass any value outside [-90, 90] to clear and stop + //! drawing visibility lines. + void setDeclination(double declinationDeg); + + //! Configure the "good visibility" altitude limit (degrees). + //! 1..89. Default is 5. + void setGoodVisibilityAltitude(int degrees); + + //! Hide all visibility lines (e.g. when no object is selected). + void clearVisibility(); + +signals: + //! Forwarded to the dialog when the user clicked on the map and we + //! were in click-to-set mode. Mirrors MapWidget::positionChanged. + void locationPicked(double longitude, double latitude, const QColor &color); + +protected: + void paintEvent(QPaintEvent* event) override; + +private slots: + void onPositionChanged(double longitude, double latitude, const QColor &color); + +private: + void drawLatitudeLine(QPainter& painter, double latitudeDeg, + const QPen& pen) const; + void drawLatitudeMarkers(QPainter& painter, double latitudeDeg, + const QChar& marker, const QColor& color) const; + + bool clickToSetMode = false; + + bool hasDeclination = false; + double declinationDeg = 0.0; + int goodVisibilityDeg = 5; +}; + +#endif // OBJECTVISIBILITYMAPWIDGET_HPP diff --git a/plugins/ObjectVisibility/src/gui/objectVisibilityDialog.ui b/plugins/ObjectVisibility/src/gui/objectVisibilityDialog.ui new file mode 100644 index 0000000000000..9d3b02d7d9ae6 --- /dev/null +++ b/plugins/ObjectVisibility/src/gui/objectVisibilityDialog.ui @@ -0,0 +1,359 @@ + + + objectVisibilityDialog + + + + 0 + 0 + 820 + 620 + + + + Object Visibility Configuration + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Object Visibility plug-in + + + + + + + 0 + + + + Visibility + + + + 6 + + + 8 + + + 8 + + + 8 + + + 8 + + + + + Select a star or DSO, then click Calculate. + + + Qt::AlignCenter + + + font-weight: bold; font-size: 14px; + + + + + + + + 1 + 1 + + + + + 400 + 200 + + + + + + + + + + Key of stars visibility + + + QGroupBox#legendGroupBox { background-color: white; color: black; } QGroupBox#legendGroupBox QLabel { background-color: transparent; color: black; } + + + + 8 + + + 6 + + + 8 + + + 6 + + + 12 + + + 4 + + + + + + Qt::AlignLeft|Qt::AlignVCenter + + + color: rgb(0,60,220); font-weight: bold; font-family: monospace; background-color: transparent; + + + ──── + + + + + + + Limit of visibility + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + + Qt::AlignLeft|Qt::AlignVCenter + + + color: rgb(0,60,220); font-weight: bold; font-family: monospace; background-color: transparent; + + + - - - + + + + + + + Good visibility (default 5° above the horizon) + + + + + + + + Qt::AlignLeft|Qt::AlignVCenter + + + color: rgb(0,60,220); font-weight: bold; font-family: monospace; background-color: transparent; + + + +++++ + + + + + + + Passes zenith + + + + + + + + Qt::AlignLeft|Qt::AlignVCenter + + + color: rgb(0,60,220); font-weight: bold; background-color: transparent; + + + ▲▲▲▲▲ + + + + + + + Circumpolar limit (northern hemisphere) + + + + + + + + Qt::AlignLeft|Qt::AlignVCenter + + + color: rgb(0,60,220); font-weight: bold; background-color: transparent; + + + ▼▼▼▼▼ + + + + + + + Circumpolar limit (southern hemisphere) + + + + + + + + + + + + + 8 + + + + + Calculate + + + Compute visibility for the selected object. + + + + + + + Qt::Vertical + + + + + + + Good visibility above the horizon: + + + + + + + ° + + + 1 + + + 89 + + + 5 + + + + + + + Qt::Horizontal + + + + 10 + 10 + + + + + + + + Set location by clicking on the map + + + Enable to move the observer by clicking on the map. Stays active until you uncheck it — you can pick as many locations as you like. + + + + + + + Reset settings + + + + + + + + + + About + + + + + + true + + + + + + + + + + + + TitleBar + QWidget +
Dialog.hpp
+ 0 +
+ + ObjectVisibilityMapWidget + QWidget +
ObjectVisibilityMapWidget.hpp
+ 0 +
+
+ + +
diff --git a/po/stellarium/POTFILES.in b/po/stellarium/POTFILES.in index 8550bd7c72c05..9741bc758fe21 100644 --- a/po/stellarium/POTFILES.in +++ b/po/stellarium/POTFILES.in @@ -282,4 +282,6 @@ plugins/NebulaTextures/src/ui_nebulaTexturesDialog.h plugins/TimeNavigator/src/TimeNavigator.cpp plugins/TimeNavigator/src/ui_timeNavigatorDialog.h plugins/TimeNavigator/src/gui/TimeNavigatorDialog.cpp +plugins/ObjectVisibility/src/gui/ui_objectVisibilityDialog.h +plugins/ObjectVisibility/src/gui/ObjectVisibilityDialog.cpp diff --git a/src/core/StelApp.cpp b/src/core/StelApp.cpp index 02bca06730b21..8ed298487c3e9 100644 --- a/src/core/StelApp.cpp +++ b/src/core/StelApp.cpp @@ -240,6 +240,10 @@ Q_IMPORT_PLUGIN(MosaicCameraStelPluginInterface) Q_IMPORT_PLUGIN(TimeNavigatorStelPluginInterface) #endif +#ifdef USE_STATIC_PLUGIN_OBJECTVISIBILITY +Q_IMPORT_PLUGIN(ObjectVisibilityStelPluginInterface) +#endif + // Initialize static variables StelApp* StelApp::singleton = nullptr; qint64 StelApp::startMSecs = 0;