- always create KML even if FSX is not connected

git-svn-id: http://moon:8086/svn/software/trunk/projects/FsTrack@181 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2015-01-31 12:31:39 +00:00
parent 82a36d13e6
commit 4993e966a4
3 changed files with 125 additions and 129 deletions
+120 -126
View File
@@ -8,9 +8,7 @@
Kml::Kml(const char *pDocRoot) Kml::Kml(const char *pDocRoot)
: m_pKml(nullptr) : m_pKml(nullptr)
, m_pPlanePlaceMark(nullptr)
, m_pTrackPlaceMark(nullptr) , m_pTrackPlaceMark(nullptr)
, m_pCameraPlaceMark(nullptr)
, m_docRoot(pDocRoot) , m_docRoot(pDocRoot)
, m_altitudeModeString("absolute") , m_altitudeModeString("absolute")
, m_pathColorString("0xff00ffff") , m_pathColorString("0xff00ffff")
@@ -21,8 +19,13 @@ Kml::Kml(const char *pDocRoot)
, m_cameraFlyToView(false) , m_cameraFlyToView(false)
{ {
memset(m_path, 0, sizeof(m_path)); memset(m_path, 0, sizeof(m_path));
} m_pKml = new XmlElement("kml");
// Create an empty kml
m_pKml->setAttribute("xmlns", "http://www.opengis.net/kml/2.2");
m_pKml->setAttribute("xmlns:gx", "http://www.google.com/kml/ext/2.2");
}
Kml::~Kml(void) Kml::~Kml(void)
{ {
@@ -35,6 +38,11 @@ void Kml::updateFlightData(FlightData const &flightData)
m_flightData = flightData; m_flightData = flightData;
} }
const char* Kml::getPath()
{
return m_path;
}
void Kml::createNetworkLinkFile(String const &path, String const &hostIp) void Kml::createNetworkLinkFile(String const &path, String const &hostIp)
{ {
File file(path); File file(path);
@@ -77,20 +85,11 @@ void Kml::createNetworkLinkFile(String const &path, String const &hostIp)
} }
const char* Kml::getPath()
{
return m_path;
}
void Kml::create() void Kml::create()
{ {
time_t time_departure; time_t time_departure;
struct tm *time_now; struct tm *time_now;
if (m_pKml)
destroy();
m_pKml = new XmlElement("kml");
XmlElement *pDoc = m_pKml->createNewChildElement("Document"); XmlElement *pDoc = m_pKml->createNewChildElement("Document");
time(&time_departure); time(&time_departure);
@@ -112,6 +111,57 @@ void Kml::create()
} }
void Kml::destroy()
{
m_pKml->removeChildElement(m_pKml->getChildByName("Document"), true);
m_pTrackPlaceMark = nullptr;
}
XmlElement* Kml::createNetworkLinkControl()
{
XmlElement *pNetworkLinkControl = new XmlElement("NetworkLinkControl");
pNetworkLinkControl->createNewChildElement("LinkName")->addTextElement("Link");
XmlElement *pCamera = pNetworkLinkControl->createNewChildElement("Camera");
pCamera->createNewChildElement("longitude")->addTextElement(String(m_flightData.lon));
pCamera->createNewChildElement("latitude")->addTextElement(String(m_flightData.lat));
pCamera->createNewChildElement("altitude")->addTextElement(String(m_flightData.alt_meter+m_cameraAlt));
if (m_cameraAutoHeading)
pCamera->createNewChildElement("heading")->addTextElement(String(m_flightData.hdgTrue_deg));
else
pCamera->createNewChildElement("heading")->addTextElement("0");
pCamera->createNewChildElement("tilt")->addTextElement(String(m_cameraTilt));
if (m_cameraAutoRoll)
pCamera->createNewChildElement("roll")->addTextElement(String(m_flightData.bank_deg));
else
pCamera->createNewChildElement("roll")->addTextElement("0");
pCamera->createNewChildElement("altitudeMode")->addTextElement(m_altitudeModeString);
#if 0
XmlElement *pUpdate = pNetworkLinkControl->createNewChildElement("Update");
pUpdate->createNewChildElement("targetHref")->addTextElement("FsTrack.kml");
XmlElement *pChange = pUpdate->createNewChildElement("Change");
XmlElement *pNetworkLink = pChange->createNewChildElement("NetworkLink");
pNetworkLink->setAttribute("targetId", "NetworkLink_0");
XmlElement *pFlyToView = pNetworkLink->createNewChildElement("flyToView");
if (m_cameraFlyToView)
{
pFlyToView->addTextElement("0");
}
else
{
pFlyToView->addTextElement("1");
}
#endif
return pNetworkLinkControl;
}
XmlElement* Kml::createPlane() XmlElement* Kml::createPlane()
{ {
const ScopedLock sl (m_lock); const ScopedLock sl (m_lock);
@@ -194,113 +244,6 @@ XmlElement* Kml::createPlane()
return pPlacemark; return pPlacemark;
} }
XmlElement* Kml::createNetworkLinkControl()
{
XmlElement *pNetworkLinkControl = new XmlElement("NetworkLinkControl");
pNetworkLinkControl->createNewChildElement("LinkName")->addTextElement("Link");
XmlElement *pCamera = pNetworkLinkControl->createNewChildElement("Camera");
pCamera->createNewChildElement("longitude")->addTextElement(String(m_flightData.lon));
pCamera->createNewChildElement("latitude")->addTextElement(String(m_flightData.lat));
pCamera->createNewChildElement("altitude")->addTextElement(String(m_flightData.alt_meter+m_cameraAlt));
if (m_cameraAutoHeading)
pCamera->createNewChildElement("heading")->addTextElement(String(m_flightData.hdgTrue_deg));
else
pCamera->createNewChildElement("heading")->addTextElement("0");
pCamera->createNewChildElement("tilt")->addTextElement(String(m_cameraTilt));
if (m_cameraAutoRoll)
pCamera->createNewChildElement("roll")->addTextElement(String(m_flightData.bank_deg));
else
pCamera->createNewChildElement("roll")->addTextElement("0");
pCamera->createNewChildElement("altitudeMode")->addTextElement(m_altitudeModeString);
#if 0
XmlElement *pUpdate = pNetworkLinkControl->createNewChildElement("Update");
pUpdate->createNewChildElement("targetHref")->addTextElement("FsTrack.kml");
XmlElement *pChange = pUpdate->createNewChildElement("Change");
XmlElement *pNetworkLink = pChange->createNewChildElement("NetworkLink");
pNetworkLink->setAttribute("targetId", "NetworkLink_0");
XmlElement *pFlyToView = pNetworkLink->createNewChildElement("flyToView");
if (m_cameraFlyToView)
{
pFlyToView->addTextElement("0");
}
else
{
pFlyToView->addTextElement("1");
}
#endif
return pNetworkLinkControl;
}
void Kml::destroy()
{
m_pKml = nullptr;
m_pPlanePlaceMark = nullptr;
m_pTrackPlaceMark = nullptr;
m_pCameraPlaceMark = nullptr;
}
void Kml::setAltitudeMode(String const &modeString)
{
m_altitudeModeString = modeString;
if (m_pPlanePlaceMark)
{
m_pPlanePlaceMark->getChildByName("Point")->getChildByName("altitudeMode")->getFirstChildElement()->setText(modeString);
}
if (m_pTrackPlaceMark)
{
m_pTrackPlaceMark->getChildByName("LineString")->getChildByName("altitudeMode")->getFirstChildElement()->setText(modeString);
}
}
void Kml::setPathColor(String const &colorString)
{
const ScopedLock sl (m_lock);
m_pathColorString = colorString;
if (m_pTrackPlaceMark)
{
m_pTrackPlaceMark->getChildByName("Style")->getChildByName("LineStyle")->getChildByName("color")->getFirstChildElement()->setText(colorString);
}
}
void Kml::setCameraAltitude(float alt_meters)
{
m_cameraAlt = alt_meters;
}
void Kml::setCameraTilt(float tilt_deg)
{
m_cameraTilt = tilt_deg;
}
void Kml::setCameraFlyToView(bool enable)
{
m_cameraFlyToView = enable;
}
void Kml::setCameraAutoHeading(bool enable)
{
m_cameraAutoHeading = enable;
}
void Kml::setCameraAutoRoll(bool enable)
{
m_cameraAutoRoll = enable;
}
XmlElement* Kml::createTrack() XmlElement* Kml::createTrack()
{ {
const ScopedLock sl (m_lock); const ScopedLock sl (m_lock);
@@ -379,22 +322,76 @@ void Kml::updateTrack()
pCoords->addTextElement(temp_str); pCoords->addTextElement(temp_str);
} }
void Kml::setAltitudeMode(String const &modeString)
{
m_altitudeModeString = modeString;
}
void Kml::setPathColor(String const &colorString)
{
const ScopedLock sl (m_lock);
m_pathColorString = colorString;
if (m_pTrackPlaceMark)
{
m_pTrackPlaceMark->getChildByName("Style")->getChildByName("LineStyle")->getChildByName("color")->getFirstChildElement()->setText(colorString);
}
}
void Kml::setCameraAltitude(float alt_meters)
{
m_cameraAlt = alt_meters;
}
void Kml::setCameraTilt(float tilt_deg)
{
m_cameraTilt = tilt_deg;
}
void Kml::setCameraFlyToView(bool enable)
{
m_cameraFlyToView = enable;
}
void Kml::setCameraAutoHeading(bool enable)
{
m_cameraAutoHeading = enable;
}
void Kml::setCameraAutoRoll(bool enable)
{
m_cameraAutoRoll = enable;
}
void Kml::exportKml(const char *pPath) void Kml::exportKml(const char *pPath)
{ {
const ScopedLock sl (m_lock); const ScopedLock sl (m_lock);
if (pPath && m_pKml) if (pPath && m_pKml)
{ {
XmlElement *pDoc;
File file(pPath); File file(pPath);
ScopedPointer<XmlElement> pPlane = createPlane(); ScopedPointer<XmlElement> pPlane = createPlane();
ScopedPointer<XmlElement> pNetworkLinkcontrol = createNetworkLinkControl(); ScopedPointer<XmlElement> pNetworkLinkcontrol = createNetworkLinkControl();
m_pKml->addChildElement(pNetworkLinkcontrol); m_pKml->addChildElement(pNetworkLinkcontrol);
m_pKml->getChildByName("Document")->addChildElement(pPlane);
m_pKml->getChildByName("Document")->addChildElement(m_pTrackPlaceMark); pDoc = m_pKml->getChildByName("Document");
if (pDoc)
{
pDoc->addChildElement(pPlane);
pDoc->addChildElement(m_pTrackPlaceMark);
}
m_pKml->writeToFile(file, StringRef("")); m_pKml->writeToFile(file, StringRef(""));
m_pKml->removeChildElement(pNetworkLinkcontrol, false); m_pKml->removeChildElement(pNetworkLinkcontrol, false);
m_pKml->getChildByName("Document")->removeChildElement(pPlane, false);
m_pKml->getChildByName("Document")->removeChildElement(m_pTrackPlaceMark, false); if (pDoc)
{
pDoc->removeChildElement(pPlane, false);
pDoc->removeChildElement(m_pTrackPlaceMark, false);
}
} }
} }
@@ -417,9 +414,6 @@ void Kml::exportKmz(const char *pPath)
void Kml::onUpdate(const char *pPath, ViewFormat const &viewFormat) void Kml::onUpdate(const char *pPath, ViewFormat const &viewFormat)
{ {
if (m_pKml == nullptr)
return;
// LookAt // LookAt
// XmlElement *pCamera; // XmlElement *pCamera;
-2
View File
@@ -23,9 +23,7 @@ public:
private: private:
CriticalSection m_lock; CriticalSection m_lock;
ScopedPointer<XmlElement> m_pKml; ScopedPointer<XmlElement> m_pKml;
XmlElement *m_pPlanePlaceMark;
XmlElement *m_pTrackPlaceMark; XmlElement *m_pTrackPlaceMark;
XmlElement *m_pCameraPlaceMark;
char m_path[1024]; char m_path[1024];
const char *m_docRoot; const char *m_docRoot;
String m_altitudeModeString; String m_altitudeModeString;
+5 -1
View File
@@ -251,7 +251,11 @@ void MainComponent::labelTextChanged (Label* labelThatHasChanged)
{ {
//[UserLabelCode_m_labelCameraAltitude] -- add your label text handling code here.. //[UserLabelCode_m_labelCameraAltitude] -- add your label text handling code here..
m_kml->setCameraAltitude(labelThatHasChanged->getText().getFloatValue()); m_kml->setCameraAltitude(labelThatHasChanged->getText().getFloatValue());
m_cameraAltitude->setValue(std::log10(1+labelThatHasChanged->getText().getFloatValue())); if (labelThatHasChanged->getText().getFloatValue() < 1.0)
{
labelThatHasChanged->getText("1.0");
}
m_cameraAltitude->setValue(std::log10(labelThatHasChanged->getText().getFloatValue()));
//[/UserLabelCode_m_labelCameraAltitude] //[/UserLabelCode_m_labelCameraAltitude]
} }
else if (labelThatHasChanged == m_labelCameraTilt) else if (labelThatHasChanged == m_labelCameraTilt)