2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup OPMapPlugin OpenPilot Map Plugin
10 * @brief The OpenPilot Map plugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #ifndef PATHCOMPILER_H
28 #define PATHCOMPILER_H
31 #include <uavobject.h>
32 #include <uavobjectmanager.h>
35 // TODO: Make this a singleton class and separate from map library. Not sure of the proper design pattern in Qt.
36 // factory? static variables?
39 * This class is a two way adapter between a visualization of a path and the
40 * UAVObject representation on the flight controller. It also can support multiple
41 * ways of converting a path from what the user clicked to the underlying representation
42 * to achieve the desired end flight trajectory
44 * So the chain of data for the map lib is:
45 * FC <-> PathCompiler <-> OPMapGadget <-> OPMapLib
47 * The goal is that PathCompiler be as state free as is possible. Eventually for more
48 * complicated path compilation this will probably not be achievable. That means it
49 * should not cache a copy of waypoints locally if that can be avoided (i.e. it should
50 * refer directly to what is stored on the FC).
52 * For the visualization to have the ability to manipulate the path though it needs to
53 * be able to map unambiguously from the graphical items to the internal waypoints. It
54 * must cache a lookup from the graphical item to the index from this tool.
56 class PathCompiler
: public QObject
{
59 explicit PathCompiler(QObject
*parent
= 0);
61 // ! This method opens a dialog (if filename is null) and saves the path
62 int savePath(QString filename
= NULL
);
64 // ! This method opens a dialog (if filename is null) and loads the path
65 int loadPath(QString filename
= NULL
);
67 // ! Waypoint representation that is exchanged between visualization
72 const bool operator==(const waypoint other
)
74 return (other
.latitude
== latitude
) && (other
.longitude
== longitude
);
83 // ! Helper method to get uavobject manager
84 UAVObjectManager
*getObjectManager();
86 // ! Convert a UAVO waypoint to the local structure
87 struct PathCompiler::waypoint
UavoToInternal(Waypoint::DataFields
);
89 // ! Convert a UAVO waypoint to the local structure
90 Waypoint::DataFields
InternalToUavo(waypoint
);
92 QList
<waypoint
> previousWaypoints
;
95 * Indicates something changed the waypoints and the map should
98 void visualizationChanged(QList
<PathCompiler::waypoint
>);
102 * These are slots that the visualization can call to manipulate the path.
103 * It is an important design detail that the visualiation _not_ attempt to maintain
104 * the list of waypoints itself. This starts the slippery of moving the path logic
109 * Called when new instances are registered
111 void doNewInstance(UAVObject
*);
115 * @param waypoint the new waypoint to add
116 * @param position which position to insert it to, defaults to end
118 void doAddWaypoint(waypoint
, int position
= -1);
123 void doUpdateWaypoints(PathCompiler::waypoint
, int position
);
127 * @param index which waypoint to delete
129 void doDelWaypoint(int index
);
132 * Delete all the waypoints
134 void doDelAllWaypoints();
138 * These are slots that the UAV can call to update the path.
142 * When the UAV waypoints change trigger the pathcompiler to
143 * get the latest version and then update the visualization
145 void doUpdateFromUAV(UAVObject
*);
148 #endif // PATHCOMPILER_H