root/FalconView/trunk/public/fvw_core/WMSMapSetup/WMSDescriptor.cpp @ 2220

Revision 2220, 6.7 KB (checked in by cb194, 6 months ago)

See #411. WMS Map Setup OCX was updated because it was hanging when inserted into an MFC DLL. Also Fixed the version information to reflect the build number and cleaned up some string comparisons so proper XML is generated.

Line 
1#include "StdAfx.h"
2#include "WMSDescriptor.h"
3#include "..\Common\ComErrorObject.h"
4
5WMSDescriptor::WMSDescriptor(void)
6{
7}
8
9WMSDescriptor::~WMSDescriptor(void)
10{
11}
12
13bool WMSDescriptor::WriteVariant(std::string Path, VARIANT v)
14{
15
16
17   std::istringstream iss(Path);
18   std::string token;
19
20   getline(iss, token, '/');
21   MSXML6::IXMLDOMNodePtr pNode = spElement->selectSingleNode(_bstr_t(token.c_str()));
22   if (!pNode)
23   {
24      MSXML6::IXMLDOMElementPtr pNextNode = spXMLDOMDocument->createElement(_bstr_t(token.c_str())); //Create first child element
25      pNode = spElement->appendChild(pNextNode);
26   }
27
28
29   while(getline(iss, token, '/'))
30   {
31      MSXML6::IXMLDOMNodePtr pNextNode = pNode->selectSingleNode(_bstr_t(token.c_str()));
32      if (!pNextNode)
33      {
34         MSXML6::IXMLDOMElementPtr pNextNode = spXMLDOMDocument->createElement(_bstr_t(token.c_str())); //Create first child element
35         pNode = pNode->appendChild(pNextNode);
36      }
37      else
38      {
39         pNode = pNextNode;
40      }
41   }
42   HRESULT hr = pNode->put_nodeTypedValue(v);
43   return (S_OK == hr);
44
45}
46
47
48// Read the GDAL XML description of a WMS Server
49int WMSDescriptor::ReadXML(std::string FileName)
50{
51
52   CO_CREATE(spXMLDOMDocument, __uuidof(MSXML6::DOMDocument60));
53
54    try
55    {
56        spXMLDOMDocument->async = VARIANT_FALSE;
57        //pXMLDom->validateOnParse = VARIANT_FALSE;
58        spXMLDOMDocument->resolveExternals = VARIANT_FALSE;
59        if(spXMLDOMDocument->load(FileName.c_str()) == VARIANT_TRUE)
60        {
61           spElement = spXMLDOMDocument->GetdocumentElement();
62           if (!spElement)
63           {
64              return -1;
65           }
66            m_UpperLeftX   = ReadDoubleValue(L"DataWindow/UpperLeftX",-180.0);
67            m_UpperLeftY   = ReadDoubleValue(L"DataWindow/UpperLeftY",90.0);
68            m_LowerRightX  = ReadDoubleValue(L"DataWindow/LowerRightX",180.0);
69            m_LowerRightY  = ReadDoubleValue(L"DataWindow/LowerRightY",-90.0);
70            m_TileLevel    = ReadIntValue(L"DataWindow/TileLevel",0);
71            m_TileCountX   = ReadIntValue(L"DataWindow/TileCountX",0);
72            m_TileCountY   = ReadIntValue(L"DataWindow/TileCountY",0);
73            m_TileSizeX    = ReadIntValue(L"BlockSizeX",1024);
74            m_TileSizeY    = ReadIntValue(L"BlockSizeY",1024);
75            m_OverviewCount= ReadIntValue(L"OverViewCount");
76            m_lImageSizeX  = ReadIntValue(L"DataWindow/SizeX");
77            m_lImageSizeY  = ReadIntValue(L"DataWindow/SizeY");
78 
79            m_ServerType   = ReadAttribute(L"Service",L"name");           
80            m_ServerURL    = ReadStringValue(L"Service/ServerUrl");           
81            m_CachePath    = ReadStringValue(L"Cache/Path",L"");
82
83            if (0==m_ServerType.compare("TMS"))
84            {
85               m_ImageFormat  = ReadStringValue(L"Service/Format",L"jpg");
86               m_Version      = ReadStringValue(L"Service/Version",L"1.0.0");
87               m_Layers    = ReadStringValue(L"Service/Layer");
88            }
89            else
90            {
91               m_ImageFormat  = ReadStringValue(L"Service/ImageFormat",L"image/jpeg");
92               m_Version      = ReadStringValue(L"Service/Version",L"1.1.1");
93               if (0==m_ServerType.compare("WMS"))
94               {
95                  m_Layers    = ReadStringValue(L"Service/Layers");
96                  if (0==m_Version.compare("1.1.1"))
97                  {
98                     m_SRS          = ReadStringValue(L"Service/SRS",L"EPSG:4326");
99                  }
100                  else
101                  {
102                     m_SRS          = ReadStringValue(L"Service/CRS",L"CRS:83");
103                  }
104               }
105            }
106            m_Projection   = ReadStringValue(L"Projection",L"EPSG:4326");
107
108
109        }
110        else
111        {
112            // Failed to load xml
113           std::string msg;
114           msg = std::string("Failed to load ") + FileName;
115           msg +=std::string(spXMLDOMDocument->parseError->Getreason());
116           THROW_ERROR_MSG2(E_FAIL,msg.c_str());
117           return -1;
118        }
119    }
120    catch(_com_error errorObject)
121    {
122        ATLTRACE("Exception thrown, HRESULT: 0x%08x", errorObject.Error());
123        return -1;
124    }
125   return 0;
126}
127
128
129
130// Write the DOM to the specified XML file
131HRESULT WMSDescriptor::WriteXML(std::string FileName)
132{
133   if (!spElement)
134   {
135      return E_FAIL;
136   }
137   WriteDoubleValue(std::string("DataWindow/UpperLeftX"),m_UpperLeftX);
138   WriteDoubleValue(std::string("DataWindow/UpperLeftY"),m_UpperLeftY);
139   WriteDoubleValue(std::string("DataWindow/LowerRightX"),m_LowerRightX);
140   WriteDoubleValue(std::string("DataWindow/LowerRightY"),m_LowerRightY);
141   if (m_TileLevel)WriteIntValue(std::string("DataWindow/TileLevel"),m_TileLevel);
142   if (m_TileCountX) WriteIntValue(std::string("DataWindow/TileCountX"),m_TileCountX);
143   if (m_TileCountY) WriteIntValue(std::string("DataWindow/TileCountY"),m_TileCountY);
144   WriteIntValue(std::string("BlockSizeX"),m_TileSizeX);
145   WriteIntValue(std::string("BlockSizeY"),m_TileSizeY);
146   if (m_OverviewCount) WriteIntValue(std::string("OverViewCount"),m_OverviewCount);
147   if(m_lImageSizeX) WriteIntValue(std::string("DataWindow/SizeX"),m_lImageSizeX);
148   if(m_lImageSizeY) WriteIntValue(std::string("DataWindow/SizeY"),m_lImageSizeY);
149   WriteAttribute(std::string("Service"),std::string("name"),m_ServerType);           
150   WriteStringValue(std::string("Service/ServerUrl"),m_ServerURL);
151
152   if(0!=m_CachePath.compare(std::string(""))) WriteStringValue(std::string("Cache/Path"),m_CachePath);
153
154   WriteStringValue(std::string("Projection"),m_Projection);
155   if (0==m_ServerType.compare(std::string("TMS")))
156   {
157      if (0!=m_Layers.compare(std::string("")))
158      {
159         WriteStringValue(std::string("Service/Layer"),m_Layers);
160      }
161      WriteStringValue(std::string("Service/Format"),m_ImageFormat);
162      WriteStringValue(std::string("Service/Version"),m_Version);   
163   }
164   else
165   {
166      WriteStringValue(std::string("Service/ImageFormat"),m_ImageFormat);
167      WriteStringValue(std::string("Service/Version"),m_Version);
168      if (0==m_ServerType.compare(std::string("WMS")))
169      {
170         if (0!=m_Layers.compare(std::string("")))
171         {
172            WriteStringValue(std::string("Service/Layers"),m_Layers);
173         }
174         if (0==m_Version.compare(std::string("1.1.1")))
175         {
176            WriteStringValue(std::string("Service/SRS"),m_SRS);     
177         }
178         else
179         {
180            WriteStringValue(std::string("Service/CRS"),m_SRS);
181         }
182      }
183   }
184
185   return spXMLDOMDocument->save(FileName.c_str());
186
187}
Note: See TracBrowser for help on using the browser.