Hello again,

Here is what I could come up with so far (see attached patches).

'nautical_units.patch' addresses A by modifying the existing "CUnitNautic".

'waypoints_route.patch' addresses B and C by adding a separate
"CRoute::addWaypoint" method and preserving the former route points
behavior as much as possible (to prevent unforeseen side-effects).

What do you think?

Cheers,

Cédric


On 20/03/12 11:57, Cédric wrote:
> Hello QLandKarte Team!
>
> I just discovered QLandKarte and I'm more than happy to eventually ditch
> the poor Windows equivalent I have been using so far!
>
> I (will) actually use QLandKarte for aero-nautical route planning.
> Unfortunately, I'm missing two "features" to do so:
>  - "AeroNautic" units (distance always in "nm" and elevations always in
> "ft")
>  - elevation (altitude) data in routes (and GPX exported routes)
>
> After quickly going through the source code of the 1.4.0 release, I
> found out that adding those two features should not be too difficult.
> I'm thus more than willing to contribute to your project and send you
> the corresponding patches once I'm done (well, if you deem those
> modifications are interesting, of course ;-) ).
>
> Before I set on modifying the source code, I have a few questions though:
>
> A. Should I add a new "CUnitAeroNautic" class or should I modify the
> "CUnitNautic" one?
> PS: I'm not aware of any use of "Nautical" units out of the sea-faring
> and sky-faring realms. Sea-faring users don't use elevation data (and
> should not care about which unit is being used). Sky-faring users always
> use elevation in feet (ICAO standard).
>
> B. Should I modify the "CRoute::addPosition" method to handle a new
> "altitude" field (and modify all call to this method accordingly) or
> would you rather have me create a new "CRoute::setAltitude" method (to
> be called after "CRoute::addPosition" when relevant, e.g. in
> "CDlgWpt2Rte::accept") ?
>
> C. When exporting a route to GPX, each route point "<RtePt>" is named
> numerically (sequentially) and the original waypoints' name is lost. Can
> we imagine keeping the original (waypoint) name, knowing that the order
> of route points is implicit, in the containing vector (in CRoute) or in
> the GPX file ?
>
> D. When exporting to GPX, it might be safer to use '<![CDATA[...]]>'
> constructs (to encapsulate name, comment and description data). Do you
> thing this could/should be changed as well ?
>
> Thank you very much for your help and comments.
>
> Cheers,
>
> Cédric
>
> ------------------------------------------------------------------------------
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here 
> http://p.sf.net/sfu/sfd2d-msazure
> _______________________________________________
> Qlandkartegt-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qlandkartegt-users
>
Description: Fix nautical units
Author: Cedric Dufour <[email protected]>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- qlandkartegt-1.4.0.orig/src/CUnitNautic.cpp
+++ qlandkartegt-1.4.0/src/CUnitNautic.cpp
@@ -19,8 +19,10 @@
 
 #include "CUnitNautic.h"
 
+// 1 nm = 1852 meters (exactly!)
+// 1 ft = 0.3048 meter (exactly!)
 CUnitNautic::CUnitNautic(QObject * parent)
-: IUnit("nautic", "nm", 0.00053989f, "nm/h", 1.94361780f, parent)
+: IUnit("nautic", "nm", 0.00053996f, "kt", 1.94384449f, parent)
 {
 
 }
@@ -34,8 +36,8 @@ CUnitNautic::~CUnitNautic()
 
 void CUnitNautic::meter2elevation(float meter, QString& val, QString& unit)
 {
-    val.sprintf("%1.0f", meter);
-    unit = "m";
+    val.sprintf("%1.0f", meter / 0.3048);
+    unit = "ft";
 }
 
 
@@ -55,17 +57,25 @@ void CUnitNautic::meter2speed(float mete
 
 float CUnitNautic::elevation2meter(const QString& val)
 {
-    return val.toDouble();
+    return val.toDouble() * 0.3048;
 }
 
 
 float CUnitNautic::str2speed(QString& str)
 {
-    return (str.remove(" nm/h").toDouble() / 0.53989f);
+    return (str.remove(" kt").toDouble() / speedfactor);
 }
 
 
 float CUnitNautic::str2distance(QString& str)
 {
-    return (str.remove(" nm").toDouble() / 0.00053989f);
+    if (str.contains(" nm"))
+    {
+        return (str.remove(" nm").toDouble() / basefactor);
+    }
+    else if (str.contains(" ft"))
+    {
+        return (str.remove(" ft").toDouble() * 0.3048);
+    }
+    return 0;
 }
Description: Include all waypoints data in routes
Author: Cedric Dufour <[email protected]>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- qlandkartegt-1.4.0.orig/src/CDlgWpt2Rte.cpp
+++ qlandkartegt-1.4.0/src/CDlgWpt2Rte.cpp
@@ -103,36 +103,7 @@ void CDlgWpt2Rte::accept()
     foreach(item,items)
     {
         CWpt * wpt = CWptDB::self().getWptByKey(item->data(Qt::UserRole).toString());
-        if(wpt)
-        {
-            QString description = wpt->getDescription();
-            QString comment     = wpt->getComment();
-            QString action;
-
-            description.remove(QRegExp("<head.*[^>]*><\\/head>"));
-            description.remove(QRegExp("<[^>]*>"));
-            description = description.simplified();
-
-            comment.remove(QRegExp("<head.*[^>]*><\\/head>"));
-            comment.remove(QRegExp("<[^>]*>"));
-            comment = description.simplified();
-
-            if(!description.isEmpty())
-            {
-                action = description;
-            }
-            else if(!comment.isEmpty())
-            {
-                action = comment;
-            }
-            else if(!wpt->getName().isEmpty())
-            {
-                action = wpt->getName();
-            }
-
-
-            route->addPosition(wpt->lon, wpt->lat, action);
-        }
+        if(wpt) route->addWaypoint(wpt);
     }
 
     route->setName(lineRouteName->text());
--- qlandkartegt-1.4.0.orig/src/CRouteDB.cpp
+++ qlandkartegt-1.4.0/src/CRouteDB.cpp
@@ -328,32 +328,81 @@ void CRouteDB::saveGPX(CGpx& gpx, const
             gpxRtept.setAttribute("lat",QString::number(rtept->lat,'f',6));
             gpxRtept.setAttribute("lon",QString::number(rtept->lon,'f',6));
 
-            QString str     = QString("%1").arg(++cnt,3,10,QChar('0'));
-
-            QDomElement name = gpx.createElement("name");
-            gpxRtept.appendChild(name);
-            QDomText _name_ = gpx.createTextNode(str);
-            name.appendChild(_name_);
-
-            QString action = rtept->action;
-//            action.remove(QRegExp("<head.*[^>]*><\\/head>"));
-//            action.remove(QRegExp("<[^>]*>"));
-//            action = action.simplified();
-
-            QDomElement cmt = gpx.createElement("cmt");
-            gpxRtept.appendChild(cmt);
-            QDomText _cmt_ = gpx.createTextNode(action);
-            cmt.appendChild(_cmt_);
-
-            QDomElement desc = gpx.createElement("desc");
-            gpxRtept.appendChild(desc);
-            QDomText _desc_ = gpx.createTextNode(action);
-            desc.appendChild(_desc_);
-
-            QDomElement sym = gpx.createElement("sym");
-            gpxRtept.appendChild(sym);
-            QDomText _sym_ = gpx.createTextNode((*route)->getIconString());
-            sym.appendChild(_sym_);
+            if(rtept->isWpt)
+            { // we have an "imported" waypoint (cf. CRoute::addWaypoint)
+                if(rtept->ele != 1e25f)
+                {
+                    QDomElement ele = gpx.createElement("ele");
+                    gpxRtept.appendChild(ele);
+                    QDomText _ele_ = gpx.createTextNode(QString::number(rtept->ele));
+                    ele.appendChild(_ele_);
+                }
+
+                QDomElement name = gpx.createElement("name");
+                gpxRtept.appendChild(name);
+                QDomText _name_ = gpx.createTextNode(rtept->name);
+                name.appendChild(_name_);
+
+                if(!rtept->comment.isEmpty())
+                {
+                    QString comment = rtept->comment;
+                    comment.remove(QRegExp("<head.*[^>]*><\\/head>"));
+                    comment.remove(QRegExp("<[^>]*>"));
+                    comment = comment.simplified();
+
+                    QDomElement cmt = gpx.createElement("cmt");
+                    gpxRtept.appendChild(cmt);
+                    QDomText _cmt_ = gpx.createTextNode(comment);
+                    cmt.appendChild(_cmt_);
+                }
+
+                if(!rtept->description.isEmpty())
+                {
+                    QString description = rtept->description;
+                    description.remove(QRegExp("<head.*[^>]*><\\/head>"));
+                    description.remove(QRegExp("<[^>]*>"));
+                    description = description.simplified();
+
+                    QDomElement desc = gpx.createElement("desc");
+                    gpxRtept.appendChild(desc);
+                    QDomText _desc_ = gpx.createTextNode(description);
+                    desc.appendChild(_desc_);
+                }
+
+                QDomElement sym = gpx.createElement("sym");
+                gpxRtept.appendChild(sym);
+                QDomText _sym_ = gpx.createTextNode(rtept->iconString);
+                sym.appendChild(_sym_);
+            }
+            else
+            { // legacy route point
+                QString str     = QString("%1").arg(++cnt,3,10,QChar('0'));
+
+                QDomElement name = gpx.createElement("name");
+                gpxRtept.appendChild(name);
+                QDomText _name_ = gpx.createTextNode(str);
+                name.appendChild(_name_);
+
+                QString action = rtept->action;
+//                action.remove(QRegExp("<head.*[^>]*><\\/head>"));
+//                action.remove(QRegExp("<[^>]*>"));
+//                action = action.simplified();
+
+                QDomElement cmt = gpx.createElement("cmt");
+                gpxRtept.appendChild(cmt);
+                QDomText _cmt_ = gpx.createTextNode(action);
+                cmt.appendChild(_cmt_);
+
+                QDomElement desc = gpx.createElement("desc");
+                gpxRtept.appendChild(desc);
+                QDomText _desc_ = gpx.createTextNode(action);
+                desc.appendChild(_desc_);
+
+                QDomElement sym = gpx.createElement("sym");
+                gpxRtept.appendChild(sym);
+                QDomText _sym_ = gpx.createTextNode((*route)->getIconString());
+                sym.appendChild(_sym_);
+            }
 
             ++rtept;
         }
--- qlandkartegt-1.4.0.orig/src/CRoute.h
+++ qlandkartegt-1.4.0/src/CRoute.h
@@ -20,6 +20,7 @@
 #define CROUTE_H
 
 #include "IItem.h"
+#include "CWpt.h"
 
 #include <QObject>
 #include <QPixmap>
@@ -53,6 +54,14 @@ class CRoute : public IItem
 
             QString action;
 
+            // additional fields for full waypoint support
+            bool isWpt;
+            QString name;
+            QString comment;
+            QString description;
+            QString iconString;
+            float ele;
+
             operator const XY ()
             {
                 XY p;
@@ -74,6 +83,9 @@ class CRoute : public IItem
         */
         void addPosition(const double lon, const double lat, const QString& action);
 
+        /// add a new position point based on given waypoint
+        void addWaypoint(const CWpt * wpt);
+
         QPolygon& getPolyline(){return polyline;}
         QPolygon& getPoints(){return points;}
 
--- qlandkartegt-1.4.0.orig/src/CRoute.cpp
+++ qlandkartegt-1.4.0/src/CRoute.cpp
@@ -311,6 +311,7 @@ void CRoute::addPosition(const double lo
     pt.lon = lon;
     pt.lat = lat;
     pt.action = action;
+    pt.isWpt = false;
     priRoute << pt;
 
     secRoute.clear();
@@ -320,6 +321,24 @@ void CRoute::addPosition(const double lo
     emit sigChanged();
 }
 
+void CRoute::addWaypoint(const CWpt * wpt)
+{
+    pt_t pt;
+    pt.lon = wpt->lon;
+    pt.lat = wpt->lat;
+    pt.action = wpt->getName();
+    pt.ele = wpt->ele;
+    pt.name = wpt->getName();
+    pt.comment = wpt->getComment();
+    pt.description = wpt->getDescription();
+    pt.iconString = wpt->getIconString();
+    pt.isWpt = true;
+
+    priRoute << pt;
+    secRoute.clear();
+    calcDistance();
+    emit sigChanged();
+}
 
 void CRoute::calcDistance()
 {
--- qlandkartegt-1.4.0.orig/src/IItem.h
+++ qlandkartegt-1.4.0/src/IItem.h
@@ -34,17 +34,17 @@ class IItem : public QObject
         /// set the item's short name
         virtual void setName(const QString& str){name = str;}
         /// get the item's short name
-        virtual QString getName(){return name;}
+        virtual QString getName() const {return name;}
 
         /// set the item's long comment
         virtual void setComment(const QString& str){comment = str;}
         /// get the item's long comment
-        virtual QString getComment(){return comment;}
+        virtual QString getComment() const {return comment;}
 
         /// set the item's description
         virtual void setDescription(const QString& str){description = str;}
         /// get the item's description
-        virtual QString getDescription(){return description;}
+        virtual QString getDescription() const {return description;}
 
         /// get a summary of item's data to display on screen or in the toolview
         virtual QString getInfo()= 0;
@@ -52,9 +52,9 @@ class IItem : public QObject
         /// set the icon defined by a string
         virtual void setIcon(const QString& str) = 0;
         /// get the icon as pixmap
-        virtual QPixmap getIcon(){return iconPixmap;}
+        virtual QPixmap getIcon() const {return iconPixmap;}
         /// get the icon as string definition
-        virtual QString getIconString(){return iconString;}
+        virtual QString getIconString() const {return iconString;}
 
         /// set the name of the parent waypoint
         virtual void setParentWpt(const QString& name){parentWpt = name;}
@@ -69,7 +69,7 @@ class IItem : public QObject
         /// get the unique key
         virtual QString getKey();
 
-        virtual quint32 getTimestamp(){return timestamp;}
+        virtual quint32 getTimestamp() const {return timestamp;}
 
         static void resetKeyCnt(){keycnt = 0;}
 
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Qlandkartegt-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qlandkartegt-users

Reply via email to