diff --git a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp index 2862b4695..77460f74e 100644 --- a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp @@ -25,8 +25,89 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "pathcompiler.h" +#include "uavobjectmanager.h" +#include "waypoint.h" +#include "homelocation.h" PathCompiler::PathCompiler(QObject *parent) : QObject(parent) { + Waypoint *waypoint = NULL; + HomeLocation *homeLocation = NULL; + + /* Connect the object updates */ + waypoint = Waypoint::GetInstance(getObjectManger()); + Q_ASSERT(waypoint); + if(waypoint) + connect(waypoint, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(doUpdateFromUAV())); + + homeLocation = HomeLocation::GetInstance(getObjectManager()); + Q_ASSERT(homeLocation); + if(homeLocation) + connect(homeLocation, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(doUpdateFromUAV())); +} + +/** + * Helper method to get the uavobjectamanger + */ +UAVObjectManager * PathCompiler::getObjectManager() +{ + ExtensionSystem::PluginManager *pm = NULL; + UAVObjectUtilManager *objMngr = NULL; + + pm = ExtensionSystem::PluginManager::instance(); + Q_ASSERT(pm); + if(pm) + objMngr = pm->getObject(); + Q_ASSERT(objMngr); + + return objMngr; +} + +/** + * This method opens a dialog (if filename is null) and saves the path + * @param filename The file to save the path to + * @returns -1 for failure, 0 for success + */ +int PathCompiler::savePath(QString filename = null) +{ + return -1; +} + +/** + * This method opens a dialog (if filename is null) and loads the path + * @param filename The file to load from + * @returns -1 for failure, 0 for success + */ +int PathCompiler::loadPath(QString filename = null) +{ + return -1; +} + +/** + * add a waypoint + * @param waypoint the new waypoint to add + * @param position which position to insert it to, defaults to end + */ +void PathCompiler::doAddWaypoint(struct PathCompiler::waypoint, int position = -1) +{ + emit visualizationChanged(waypoints); +} + +/** + * Delete a waypoint + * @param index which waypoint to delete + */ +void PathCompiler::doDelWaypoint(int index) +{ + emit visualizationChanged(waypoints); +} + +/** + * When the UAV waypoints change trigger the pathcompiler to + * get the latest version and then update the visualization + */ +void PathCompiler::doUpdateFromUAV() +{ + emit visualizationChanged(waypoints); } diff --git a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h index 565986fa3..f0e71aae4 100644 --- a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h +++ b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h @@ -29,6 +29,10 @@ #include #include +#include + +// TODO: Make this a singleton class and separate from map library. Not sure of the proper design pattern in Qt. +// factory? static variables? /** * This class is a two way adapter between a visualization of a path and the @@ -54,6 +58,13 @@ public: float longitude; }; +private: + //! Helper method to get uavobject manager + UAVObjectManager * getObjectManager(); + + //! The internal list of waypoints + QList waypoints; + signals: /** * Indicates something changed the waypoints and the map should