[mapguide-commits] r1185 - in trunk/MgDev: Common/MdfModel Common/MdfParser Common/Schema Common/Stylization Server/src/Services/Kml

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Mar 8 17:58:20 EST 2007


Author: chrisclaydon
Date: 2007-03-08 17:58:19 -0500 (Thu, 08 Mar 2007)
New Revision: 1185

Modified:
   trunk/MgDev/Common/MdfModel/Stroke.cpp
   trunk/MgDev/Common/MdfModel/Stroke.h
   trunk/MgDev/Common/MdfParser/IOStroke.cpp
   trunk/MgDev/Common/Schema/LayerDefinition-1.1.0.xsd
   trunk/MgDev/Common/Stylization/DWFRenderer.cpp
   trunk/MgDev/Common/Stylization/GDRenderer.cpp
   trunk/MgDev/Common/Stylization/GeometryAdapter.cpp
   trunk/MgDev/Common/Stylization/KmlRenderer.cpp
   trunk/MgDev/Common/Stylization/KmlRenderer.h
   trunk/MgDev/Common/Stylization/RendererStyles.h
   trunk/MgDev/Server/src/Services/Kml/ServerKmlService.cpp
Log:
RFC17 - Map Space Line Widths

Modified: trunk/MgDev/Common/MdfModel/Stroke.cpp
===================================================================
--- trunk/MgDev/Common/MdfModel/Stroke.cpp	2007-03-08 21:12:48 UTC (rev 1184)
+++ trunk/MgDev/Common/MdfModel/Stroke.cpp	2007-03-08 22:58:19 UTC (rev 1185)
@@ -34,6 +34,7 @@
     this->SetLineStyle(L"Solid"); // NOXLATE
     this->SetThickness(L"0.0"); // NOXLATE
     this->SetColor(L"ff000000"); // NOXLATE
+    this->SetSizeContext(MdfModel::DeviceUnits);
 }
 
 //-------------------------------------------------------------------------
@@ -146,3 +147,21 @@
 {
     this->m_strColor = strColor;
 }
+
+//-------------------------------------------------------------------------
+// PURPOSE:
+// PARAMETERS:
+//-------------------------------------------------------------------------
+SizeContext Stroke::GetSizeContext() const
+{
+    return this->m_eSizeContext;
+}
+
+//-------------------------------------------------------------------------
+// PURPOSE:
+// PARAMETERS:
+//-------------------------------------------------------------------------
+void Stroke::SetSizeContext(SizeContext sizeContext)
+{
+    this->m_eSizeContext = sizeContext;
+}
\ No newline at end of file

Modified: trunk/MgDev/Common/MdfModel/Stroke.h
===================================================================
--- trunk/MgDev/Common/MdfModel/Stroke.h	2007-03-08 21:12:48 UTC (rev 1184)
+++ trunk/MgDev/Common/MdfModel/Stroke.h	2007-03-08 22:58:19 UTC (rev 1185)
@@ -55,6 +55,10 @@
         const MdfString& GetColor()const;
         void SetColor(const MdfString& strColor);
 
+        // Property : SizeContext
+        SizeContext GetSizeContext() const;
+        void SetSizeContext(SizeContext sizeContext);
+
     private:
         // Data members
 

Modified: trunk/MgDev/Common/MdfParser/IOStroke.cpp
===================================================================
--- trunk/MgDev/Common/MdfParser/IOStroke.cpp	2007-03-08 21:12:48 UTC (rev 1184)
+++ trunk/MgDev/Common/MdfParser/IOStroke.cpp	2007-03-08 22:58:19 UTC (rev 1185)
@@ -30,6 +30,7 @@
 ELEM_MAP_ENTRY(3, Thickness);
 ELEM_MAP_ENTRY(4, Color);
 ELEM_MAP_ENTRY(5, Unit);
+ELEM_MAP_ENTRY(6, SizeContext);
 
 IOStroke::IOStroke(std::wstring elementName)
 {
@@ -72,17 +73,28 @@
 
 void IOStroke::ElementChars(const wchar_t *ch)
 {
-    if (m_currElemName == L"LineStyle") // NOXLATE
+    if (m_currElemName == swLineStyle) 
         (this->_stroke)->SetLineStyle(ch);
-    else if (m_currElemName == L"Thickness") // NOXLATE
+    else if (m_currElemName == swThickness) 
         (this->_stroke)->SetThickness(ch);
-    else if (m_currElemName == L"Color") // NOXLATE
+    else if (m_currElemName == swColor) 
         (this->_stroke)->SetColor(ch);
-    else if (m_currElemName == L"Unit") // NOXLATE
+    else if (m_currElemName == swUnit) 
     {
         LengthUnit unit = LengthConverter::EnglishToUnit(ch);
         this->_stroke->SetUnit(unit);
     }
+    else if (this->m_currElemName == swSizeContext) // NOXLATE
+    {
+        if (::wcscmp(ch, L"MappingUnits") == 0) // NOXLATE
+        {
+            this->_stroke->SetSizeContext(MdfModel::MappingUnits);
+        }
+        else // "DeviceUnits" & default
+        {
+            this->_stroke->SetSizeContext(MdfModel::DeviceUnits);
+        }
+    }
 }
 
 void IOStroke::EndElement(const wchar_t *name, HandlerStack *handlerStack)
@@ -125,7 +137,19 @@
     fd << EncodeString(*str);
     fd << "</Unit>" << std::endl; // NOXLATE
 
-        // Write any previously found unknown XML
+    //Property: SizeContext
+    fd << tab() << "<SizeContext>"; // NOXLATE
+    if(stroke->GetSizeContext() == MdfModel::MappingUnits)
+    {
+        fd << "MappingUnits"; // NOXLATE
+    }
+    else
+    {
+        fd << "DeviceUnits"; // NOXLATE
+    }
+    fd << "</SizeContext>" << std::endl; // NOXLATE
+        
+    // Write any previously found unknown XML
     if (!stroke->GetUnknownXml().empty())
     {
         fd << toCString(stroke->GetUnknownXml()); 

Modified: trunk/MgDev/Common/Schema/LayerDefinition-1.1.0.xsd
===================================================================
--- trunk/MgDev/Common/Schema/LayerDefinition-1.1.0.xsd	2007-03-08 21:12:48 UTC (rev 1184)
+++ trunk/MgDev/Common/Schema/LayerDefinition-1.1.0.xsd	2007-03-08 22:58:19 UTC (rev 1185)
@@ -430,6 +430,11 @@
           <xs:documentation>Unit of measurement that the thickness is specified in</xs:documentation>
         </xs:annotation>
       </xs:element>
+      <xs:element name="SizeContext" type="SizeContextType">
+        <xs:annotation>
+          <xs:documentation>Whether the sizes are with respect to the earth or the user's display device.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
       <xs:element name="ExtendedData1" type="ExtendedDataType" minOccurs="0"/>
     </xs:sequence>
   </xs:complexType>

Modified: trunk/MgDev/Common/Stylization/DWFRenderer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/DWFRenderer.cpp	2007-03-08 21:12:48 UTC (rev 1184)
+++ trunk/MgDev/Common/Stylization/DWFRenderer.cpp	2007-03-08 22:58:19 UTC (rev 1185)
@@ -1586,13 +1586,10 @@
 {
     m_w2dFile->desired_rendition().color() = Util_ConvertColor(stroke.color());
 
-    int line_weight = 0;
-
     double thickness = stroke.width();
 
-    //line width is always device space.
-    //so convert to equivalent mapping space width
-    line_weight = (int)(fabs(thickness) / m_metersPerUnit * m_mapScale * m_scale);
+    //convert thickness to equivalent mapping space width
+    int line_weight = (int)(_MeterToMapSize(stroke.units(), fabs(thickness)) * m_scale);
 
     m_w2dFile->desired_rendition().line_weight() = WT_Line_Weight(line_weight);
 }

Modified: trunk/MgDev/Common/Stylization/GDRenderer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/GDRenderer.cpp	2007-03-08 21:12:48 UTC (rev 1184)
+++ trunk/MgDev/Common/Stylization/GDRenderer.cpp	2007-03-08 22:58:19 UTC (rev 1185)
@@ -1148,9 +1148,8 @@
 
     double thickness = stroke.width();
 
-    //line width is always device space and units are meters.
-    //so convert to equivalent pixel width
-    int line_weight = (int)(fabs(thickness) / m_metersPerUnit * m_mapScale * m_scale);
+    //convert thickness to equivalent mapping space width
+    int line_weight = (int)(_MeterToMapSize(stroke.units(), fabs(thickness)) * m_scale);
 
     gdImagePtr brush1 = NULL;
 
@@ -1500,7 +1499,7 @@
         RS_Color selLineColor = RS_Color(0, 0, 255, 200);
         RS_Color selFillColor = RS_Color(0, 0, 255, 160);
         RS_Color selBgColor(0, 0, 0, 0);
-        RS_LineStroke selStroke = RS_LineStroke(selLineColor, 0.001, L"Solid");
+        RS_LineStroke selStroke = RS_LineStroke(selLineColor, 0.001, L"Solid", RS_Units_Device);
         m_selFill = RS_FillStyle(selStroke, selFillColor, selBgColor, L"Solid");
     }
 }

Modified: trunk/MgDev/Common/Stylization/GeometryAdapter.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/GeometryAdapter.cpp	2007-03-08 21:12:48 UTC (rev 1184)
+++ trunk/MgDev/Common/Stylization/GeometryAdapter.cpp	2007-03-08 22:58:19 UTC (rev 1185)
@@ -310,6 +310,7 @@
         bool const1 = ConvertLineThickness(stroke->GetThickness(), val);
         rsstroke.width()= MdfModel::LengthConverter::UnitToMeters(stroke->GetUnit(), val);
         rsstroke.style() = stroke->GetLineStyle();
+        rsstroke.units() = (stroke->GetSizeContext() == MdfModel::MappingUnits) ? RS_Units_Model : RS_Units_Device;
         bool const2 = EvalColor(stroke->GetColor(), rsstroke.color());
 
         return const1 && const2; //if all members are constant, the stroke is constant

Modified: trunk/MgDev/Common/Stylization/KmlRenderer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/KmlRenderer.cpp	2007-03-08 21:12:48 UTC (rev 1184)
+++ trunk/MgDev/Common/Stylization/KmlRenderer.cpp	2007-03-08 22:58:19 UTC (rev 1185)
@@ -30,20 +30,21 @@
 
 //default constructor
 KmlRenderer::KmlRenderer(KmlContent* kmlContent, RS_Bounds& extents, 
-        double scale, double dpi, int drawOrder) :
+        double scale, double dpi, double metersPerUnit, int drawOrder) :
     m_mainContent(kmlContent),
     m_kmlContent(kmlContent),
     m_styleContent(NULL),
     m_featureCount(0),
     m_layerInfo(NULL),
     m_featureClassInfo(NULL),
-    m_scale(scale),
+    m_mapScale(scale),
     m_styleId(0),
     m_extents(extents),
     m_drawOrder(drawOrder),
     m_elevation(0),
     m_extrude(false),
-    m_elevType(RS_ElevationType_RelativeToGround)
+    m_elevType(RS_ElevationType_RelativeToGround),
+    m_metersPerUnit(metersPerUnit)
 {
     m_kmlContent = m_mainContent;
     m_pixelSize = METERS_PER_INCH / dpi;
@@ -400,7 +401,7 @@
 
 double KmlRenderer::GetMapScale()
 {
-    return m_scale;
+    return m_mapScale;
 }
 
 
@@ -418,7 +419,7 @@
 
 double KmlRenderer::GetMetersPerUnit()
 {
-    return 0;
+    return m_metersPerUnit;
 }
 
 
@@ -479,7 +480,7 @@
     char buffer[256];
 
     int thisStyleId;
-    KmlPolyStyle key(fill.outline().color().abgr(), fill.outline().width() / m_pixelSize, fill.color().abgr());
+    KmlPolyStyle key(fill.outline().color().abgr(), _MeterToPixels(fill.outline().units(), fill.outline().width()), fill.color().abgr());
     KmlPolyStyleIdMap::iterator iter = m_polyStyleMap.find(key);
     if(iter != m_polyStyleMap.end())
     {
@@ -540,7 +541,7 @@
 
     char buffer[256];
     int thisStyleId = 0;
-    KmlLineStyle key(lsym.color().abgr(), lsym.width() / m_pixelSize );
+    KmlLineStyle key(lsym.color().abgr(), _MeterToPixels(lsym.units(), lsym.width()));
     KmlLineStyleIdMap::iterator iter = m_lineStyleMap.find(key);
     if(iter != m_lineStyleMap.end())
     {
@@ -575,7 +576,23 @@
     m_kmlContent->WriteString(buffer);
 }
 
+double KmlRenderer::_MeterToPixels(RS_Units unit, double number)
+{
+    double scale_factor;
 
+    if (unit == RS_Units_Device) // in meters, fixed size
+    {
+        scale_factor = 1.0 / m_pixelSize;
+    }
+    else
+    {
+        scale_factor = 1.0 / m_mapScale / m_pixelSize;
+    }
 
+    return number * scale_factor;
+}
 
 
+
+
+

Modified: trunk/MgDev/Common/Stylization/KmlRenderer.h
===================================================================
--- trunk/MgDev/Common/Stylization/KmlRenderer.h	2007-03-08 21:12:48 UTC (rev 1184)
+++ trunk/MgDev/Common/Stylization/KmlRenderer.h	2007-03-08 22:58:19 UTC (rev 1185)
@@ -43,7 +43,7 @@
 public:
 
     STYLIZATION_API KmlRenderer(KmlContent* kmlContent, RS_Bounds& extents, 
-        double scale, double dpi, int drawOrder);
+        double scale, double dpi, double metersPerUnit, int drawOrder);
     STYLIZATION_API ~KmlRenderer();
 
     ///////////////////////////////////
@@ -135,6 +135,7 @@
     void WriteElevationSettings();
     void ClearThemes();
     void ClearStyles();
+    double _MeterToPixels(RS_Units unit, double number);
 
     RS_Bounds& m_extents;
     KmlContent* m_kmlContent;
@@ -143,7 +144,7 @@
     int m_featureCount;
     RS_LayerUIInfo* m_layerInfo;
     RS_FeatureClassInfo* m_featureClassInfo;
-    double m_scale;
+    double m_mapScale;
     ThemeMap m_themeMap;
     int m_styleId;
     KmlLineStyleIdMap m_lineStyleMap;
@@ -152,6 +153,7 @@
     int m_drawOrder;
     double m_elevation;
     bool m_extrude;
+    double m_metersPerUnit;
     RS_ElevationType m_elevType;
 };
 

Modified: trunk/MgDev/Common/Stylization/RendererStyles.h
===================================================================
--- trunk/MgDev/Common/Stylization/RendererStyles.h	2007-03-08 21:12:48 UTC (rev 1184)
+++ trunk/MgDev/Common/Stylization/RendererStyles.h	2007-03-08 22:58:19 UTC (rev 1185)
@@ -184,27 +184,32 @@
     RS_LineStroke() :
         m_color(),
         m_width(0.0),
-        m_style(L"Solid")
+        m_style(L"Solid"),
+        m_units(RS_Units_Device)
     {
     }
 
     RS_LineStroke(RS_Color&        lineColor,
                   double           lineWidth,
-                  const RS_String& lineStyle)
+                  const RS_String& lineStyle,
+                  RS_Units         units)
     {
         m_color = lineColor;
         m_width = lineWidth;
         m_style = lineStyle;
+        m_units = units;
     }
 
     inline RS_Color &      color() { return m_color; }
     inline double &        width() { return m_width; }
     inline RS_String &     style() { return m_style; }
+    inline RS_Units &      units() { return m_units; }
 
 private:
     RS_Color m_color;
     double m_width;
     RS_String m_style;
+    RS_Units m_units;
 };
 
 

Modified: trunk/MgDev/Server/src/Services/Kml/ServerKmlService.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Kml/ServerKmlService.cpp	2007-03-08 21:12:48 UTC (rev 1184)
+++ trunk/MgDev/Server/src/Services/Kml/ServerKmlService.cpp	2007-03-08 22:58:19 UTC (rev 1185)
@@ -432,6 +432,7 @@
                                        -layer->GetDisplayOrder(),
                                        uig);
     Ptr<MgCoordinateSystem> destCs = m_csFactory->Create(GOOGLE_EARTH_WKT);
+    double metersPerUnit = (destCs.p != NULL) ? destCs->ConvertCoordinateSystemUnitsToMeters(1.0) : 1.0;
     
     RS_Bounds bounds(extents->GetLowerLeftCoordinate()->GetX(),
         extents->GetLowerLeftCoordinate()->GetY(),
@@ -442,7 +443,7 @@
     MdfModel::VectorLayerDefinition* vl = dynamic_cast<MdfModel::VectorLayerDefinition*>(layerDef);
     if(vl != NULL)
     {
-        KmlRenderer renderer(&kmlContent, bounds, scale, dpi, drawOrder);
+        KmlRenderer renderer(&kmlContent, bounds, scale, dpi, metersPerUnit, drawOrder);
         DefaultStylizer stylizer;
         stylizer.Initialize(&renderer);
         if(m_svcFeature == NULL)



More information about the mapguide-commits mailing list