Static Plugin Development
Writing plugins
General information about plugins development you can found on page Plugin Development.
On these page I describe building static plugin.
Example code
Examples for static plug-ins are the "official" plug-ins and the HelloStelModule example plug-in. All can be found in the "plugins" subdirectory of Stellarium's trunk branch.
For further information and links to those places, see the "Plug-ins" section in How to get Stellarium's source code.
I will consider the creation of a static plugin based on the current development trunk branch.
Steps of create a static plugin
Let's say that your plugin will be called the "Mars Explorer" based on HelloStelModule plugin.
Step 1
You need create yourself branch for new plugin, example as:
mkdir ~/stellarium cd ~/stellarium bzr branch lp:stellarium marsexplorer-plugin cd marsexplorer-plugin
Step 2
You need create a directory for plugin and create a minimal source code for this plugin.
mkdir -p plugins/MarsExplorer/src cd plugins/MarsExplorer/src touch MarsExplorer.cpp touch MarsExplorer.hpp touch CMakeLists.txt touch ../CMakeLists.txt
After created files you need a edit their. Their example source look bottom.
Source of ~/stellarium/marsexplorer-plugin/plugins/MarsExplorer/src/MarsExplorer.cpp
/*
* Copyright (C) YEAR Your Name
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "StelProjector.hpp"
#include "StelPainter.hpp"
#include "StelApp.hpp"
#include "StelCore.hpp"
#include "StelLocaleMgr.hpp"
#include "StelModuleMgr.hpp"
#include "MarsExplorer.hpp"
#include <QDebug>
StelModule* MarsExplorerStelPluginInterface::getStelModule() const
{
return new MarsExplorer();
}
StelPluginInfo MarsExplorerStelPluginInterface::getPluginInfo() const
{
StelPluginInfo info;
info.id = "MarsExplorer";
info.displayedName = q_("Mars Explorer");
info.authors = "Your Name";
info.contact = "your email or website";
info.description = q_("Example plugin named Mars Explorer.");
return info;
}
Q_EXPORT_PLUGIN2(MarsExplorer, MarsExplorerStelPluginInterface)
MarsExplorer::MarsExplorer()
{
setObjectName("MarsExplorer");
font.setPixelSize(25);
}
MarsExplorer::~MarsExplorer()
{
}
double MarsExplorer::getCallOrder(StelModuleActionName actionName) const
{
if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("NebulaMgr")->getCallOrder(actionName)+10.;
return 0;
}
void MarsExplorer::init()
{
qDebug() << "init called for MarsExplorer";
}
void MarsExplorer::draw(StelCore* core)
{
StelPainter painter(core->getProjection2d());
painter.setColor(1,1,1,1);
painter.setFont(font);
painter.drawText(300, 300, "I'm Mars Explorer plugin!");
}
Source of ~/stellarium/marsexplorer-plugin/plugins/MarsExplorer/src/MarsExplorer.hpp
/*
* Copyright (C) YEAR Your Name
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef MARSEXPLORER_HPP_
#define MARSEXPLORER_HPP_
#include "StelModule.hpp"
#include <QFont>
class MarsExplorer : public StelModule
{
public:
MarsExplorer();
virtual ~MarsExplorer();
virtual void init();
virtual void update(double) {;}
virtual void draw(StelCore* core);
virtual double getCallOrder(StelModuleActionName actionName) const;
private:
QFont font;
};
#include "fixx11h.h"
#include <QObject>
#include "StelPluginInterface.hpp"
class MarsExplorerStelPluginInterface : public QObject, public StelPluginInterface
{
Q_OBJECT
Q_INTERFACES(StelPluginInterface)
public:
virtual StelModule* getStelModule() const;
virtual StelPluginInfo getPluginInfo() const;
};
#endif /*MARSEXPLORER_HPP_*/
Source of ~/stellarium/marsexplorer-plugin/plugins/MarsExplorer/src/CMakeLists.txt
INCLUDE_DIRECTORIES(.)
LINK_DIRECTORIES(${BUILD_DIR}/src)
SET(MarsExplorer_SRCS
MarsExplorer.hpp
MarsExplorer.cpp)
SET(MarsExplorer_MOC_HDRS
MarsExplorer.hpp)
QT4_WRAP_CPP(MarsExplorer_MOC_SRCS ${MarsExplorer_MOC_HDRS})
SET(extLinkerOption ${QT_LIBRARIES} ${JPEG_LIBRARIES} ${PNG_LIBRARIES} ${OPENGL_LIBRARIES} ${ICONV_LIBRARIES} ${INTL_LIBRARIES})
IF(BUILD_DYNAMIC_PLUGINS)
ADD_LIBRARY(MarsExplorer MODULE ${MarsExplorer_SRCS} ${MarsExplorer_MOC_SRCS})
IF(APPLE)
FIND_LIBRARY(OPENGL_LIBRARY OpenGL)
MARK_AS_ADVANCED(OPENGL_LIBRARY)
SET_TARGET_PROPERTIES(MarsExplorer PROPERTIES LINK_FLAGS "-undefined dynamic_lookup" SUFFIX ".dylib")
ENDIF()
IF(WIN32)
SET_TARGET_PROPERTIES(MarsExplorer PROPERTIES LINK_FLAGS "-enable-runtime-pseudo-reloc -Wl,--allow-multiple-definition" )
SET(StelMain stelMain)
ELSE(WIN32)
SET(StelMain )
ENDIF(WIN32)
TARGET_LINK_LIBRARIES(MarsExplorer ${StelMain} ${extLinkerOption})
INSTALL(TARGETS MarsExplorer DESTINATION "modules/MarsExplorer")
ENDIF()
IF(BUILD_STATIC_PLUGINS)
ADD_LIBRARY(MarsExplorer-static STATIC ${MarsExplorer_SRCS} ${MarsExplorer_MOC_SRCS})
SET_TARGET_PROPERTIES(MarsExplorer-static PROPERTIES OUTPUT_NAME "MarsExplorer")
TARGET_LINK_LIBRARIES(MarsExplorer-static ${extLinkerOption})
SET_TARGET_PROPERTIES(MarsExplorer-static PROPERTIES COMPILE_FLAGS "-DQT_STATICPLUGIN")
ADD_DEPENDENCIES(AllStaticPlugins MarsExplorer-static)
ENDIF()
Source of ~/stellarium/marsexplorer-plugin/plugins/MarsExplorer/CMakeLists.txt
SET(MARSEXPLORER_VERSION "0.1.0")
ADD_SUBDIRECTORY( src )
IF(APPLE)
SET(CMAKE_INSTALL_PREFIX $ENV{HOME}/Library/Application\ Support/Stellarium)
ELSE(APPLE)
SET(CMAKE_INSTALL_PREFIX $ENV{HOME}/.stellarium)
ENDIF(APPLE)
INSTALL(FILES DESTINATION "modules/MarsExplorer")
Step 3
Update source of Stellarium's files.
In file ~/stellarium/marsexplorer-plugin/CMakeLists.txt find lines contain string "SET(USE_PLUGIN" and add this string:
SET(USE_PLUGIN_MARSEXPLORER 1 CACHE BOOL "Define whether the Mars Explorer plugin should be created.")
In file ~/stellarium/marsexplorer-plugin/plugins/CMakeLists.txt find lines contain string "IF (USE_PLUGIN" and add this strings:
IF (USE_PLUGIN_MARSEXPLORER)
ADD_SUBDIRECTORY( MarsExplorer )
ENDIF()
In file ~/stellarium/marsexplorer-plugin/src/CMakeLists.txt find lines contain string "IF (USE_PLUGIN" and add this strings:
IF (USE_PLUGIN_MARSEXPLORER)
SET(STELLARIUM_STATIC_PLUGINS_LIBRARIES ${STELLARIUM_STATIC_PLUGINS_LIBRARIES} "${CMAKE_BINARY_DIR}/plugins/MarsExplorer/src/${CMAKE_CFG_INTDIR}/libMarsExplorer.a")
ADD_DEFINITIONS(-DUSE_STATIC_PLUGIN_MARSEXPLORER)
ENDIF()
In file ~/stellarium/marsexplorer-plugin/src/StelMainGraphicsView.cpp find lines contain string "#ifdef USE_STATIC_PLUGIN" and add this strings:
#ifdef USE_STATIC_PLUGIN_MARSEXPLORER Q_IMPORT_PLUGIN(MarsExplorer) #endif
Step 4
Add your code into branch and publish it.
cd ~/stellarium/marsexplorer-plugin bzr add plugins/MarsExplorer bzr commit -m "Init Mars Explorer plugin" bzr push lp:~yourlaunchpadlogin/stellarium/marsexplorer-plugin
Building and installing
Building and installing this plugin is together with Stellarium and instruction for building and installing of Stellarium you can found on this pages: