[mapguide-commits] r1304 - trunk/MgDev/Common/Stylization

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Mar 20 15:05:34 EDT 2007


Author: traianstanev
Date: 2007-03-20 15:05:34 -0400 (Tue, 20 Mar 2007)
New Revision: 1304

Modified:
   trunk/MgDev/Common/Stylization/KmlRenderer.cpp
   trunk/MgDev/Common/Stylization/KmlRenderer.h
Log:
The KML renderer will now output something (as opposed to nothing) when new SE composite styles are encountered. Basically I made KmlRenderer implement SE_Renderer and then overloaded some key virtual functions to pipe output of the new StyleEngine into the old Renderer APIs.

Modified: trunk/MgDev/Common/Stylization/KmlRenderer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/KmlRenderer.cpp	2007-03-20 19:03:47 UTC (rev 1303)
+++ trunk/MgDev/Common/Stylization/KmlRenderer.cpp	2007-03-20 19:05:34 UTC (rev 1304)
@@ -592,3 +592,132 @@
 
     return number * scale_factor;
 }
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// SE_Renderer implementation
+//
+////////////////////////////////////////////////////////////////////////////////
+
+void KmlRenderer::DrawScreenPolyline(LineBuffer* geom, const SE_Matrix* xform, unsigned int color, double weight)
+{
+}
+
+void KmlRenderer::DrawScreenPolygon(LineBuffer* geom, const SE_Matrix* xform, unsigned int fill)
+{
+}
+
+void KmlRenderer::DrawScreenRaster(unsigned char* data, int length, RS_ImageFormat format, int native_width, int native_height,
+                              double x, double y, double w, double h, double angledeg)
+{
+}
+
+void KmlRenderer::DrawScreenText(const RS_String& txt, RS_TextDef& tdef, double insx, double insy, double* path, int npts, double param_position)
+{
+}
+
+void KmlRenderer::GetWorldToScreenTransform(SE_Matrix& xform)
+{
+}
+
+void KmlRenderer::WorldToScreenPoint(double& inx, double& iny, double& ox, double& oy)
+{
+}
+
+void KmlRenderer::ScreenToWorldPoint(double& inx, double& iny, double& ox, double& oy)
+{
+}
+
+double KmlRenderer::GetPixelsPerMillimeterScreen()
+{
+    return 96.0 / 25.4; //wrong but not currently used
+}
+
+double KmlRenderer::GetPixelsPerMillimeterWorld()
+{
+    return 96.0 / 25.4 / m_mapScale; //wrong but not currently used
+}
+
+RS_FontEngine* KmlRenderer::GetFontEngine()
+{
+    return NULL;
+}
+
+void KmlRenderer::ProcessLabelGroup(SE_LabelInfo*    labels,
+                               int              nlabels,
+                               RS_OverpostType  type,
+                               bool             exclude,
+                               LineBuffer*      path)
+{
+}
+
+void KmlRenderer::AddExclusionRegion(RS_F_Point* fpts, int npts)
+{
+}
+
+void KmlRenderer::ProcessPoint(LineBuffer* geometry, SE_RenderPointStyle* style)
+{
+    RS_FillStyle fs;
+    RS_MarkerDef mdef(1.0, 1.0, 0.5, 0.5, 0.0, RS_Units_Device, L"", L"", fs);
+
+    ProcessMarker(geometry, mdef, !style->addToExclusionRegions, NULL);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// TODO: If we want true composite styles generated by the SE_Renderer
+// these 3 functions need to be removed and instead the above DrawScreen*
+// functions should be implemented. The risk of fully styling all features
+// in the kml renderer is the insanely huge resulting KML files. So the solution
+// right now is to just pipe all features that come from the SE_Renderer
+// directly into the old Renderer APIs using arbitrary styles based on
+// information obtained from cursory examination of the SE composite style.
+//
+
+void KmlRenderer::ProcessLine(LineBuffer* geometry, SE_RenderLineStyle* style)
+{
+    RS_LineStroke ls(RS_Color(0,0,0,255), 0.0, L"Solid", RS_Units_Device);
+    
+    //try to get some line style information from the SE symbol
+    if (style->symbol.size())
+    {
+        for (int i=0; i<style->symbol.size(); i++)
+        {
+            SE_RenderPrimitive* rp = style->symbol[i];
+
+            if (rp->type == SE_RenderPolylinePrimitive)
+            {
+                ls.color() = RS_Color::FromARGB(((SE_RenderPolyline*)rp)->color);
+                ls.width() = ((SE_RenderPolyline*)rp)->weight / GetPixelsPerMillimeterScreen() * 0.001; //convert from pixels to meters
+            }
+        }
+    }
+
+    //forward the feature to the regular ProcessPolyline API
+    ProcessPolyline(geometry, ls);
+        
+}
+
+void KmlRenderer::ProcessArea(LineBuffer* geometry, SE_RenderAreaStyle* style)
+{
+    //not implemented upstream yet, but let's do something anyway
+
+    RS_FillStyle fs;
+    fs.color() = RS_Color(0,0,0,255);
+
+    //try to get some fill style information from the SE symbol
+    if (style->symbol.size())
+    {
+        for (int i=0; i<style->symbol.size(); i++)
+        {
+            SE_RenderPrimitive* rp = style->symbol[i];
+
+            if (rp->type == SE_RenderPolygonPrimitive)
+            {
+                fs.color() = RS_Color::FromARGB(((SE_RenderPolygon*)rp)->fill);
+                fs.outline().color() = RS_Color::FromARGB(((SE_RenderPolygon*)rp)->color);
+            }
+        }
+    }
+
+    ProcessPolygon(geometry, fs);   
+}

Modified: trunk/MgDev/Common/Stylization/KmlRenderer.h
===================================================================
--- trunk/MgDev/Common/Stylization/KmlRenderer.h	2007-03-20 19:03:47 UTC (rev 1303)
+++ trunk/MgDev/Common/Stylization/KmlRenderer.h	2007-03-20 19:05:34 UTC (rev 1304)
@@ -30,6 +30,7 @@
 #include <map>
 
 #include "Renderer.h"
+#include "SE_Renderer.h"
 #include "KmlContent.h"
     
 typedef std::map<RS_String, KmlContent*> ThemeMap;
@@ -38,7 +39,7 @@
 
 const double METERS_PER_INCH = 0.0254; 
 
-class KmlRenderer : public Renderer
+class KmlRenderer : public Renderer, public SE_Renderer
 {
 public:
     STYLIZATION_API KmlRenderer(KmlContent* kmlContent, RS_Bounds& extents, 
@@ -116,6 +117,37 @@
 
     STYLIZATION_API virtual bool RequiresClipping();
 
+
+    ////////////////////////////////////////////////
+    // SE_Renderer
+    //
+    virtual void DrawScreenPolyline(LineBuffer* geom, const SE_Matrix* xform, unsigned int color, double weight); // px
+    virtual void DrawScreenPolygon(LineBuffer* geom, const SE_Matrix* xform, unsigned int fill);
+    virtual void DrawScreenRaster(unsigned char* data, int length, RS_ImageFormat format, int native_width, int native_height,
+                                  double x, double y, double w, double h, double angledeg);
+    virtual void DrawScreenText(const RS_String& txt, RS_TextDef& tdef, double insx, double insy, double* path, int npts, double param_position);
+
+    virtual void GetWorldToScreenTransform(SE_Matrix& xform);
+    virtual void WorldToScreenPoint(double& inx, double& iny, double& ox, double& oy);
+    virtual void ScreenToWorldPoint(double& inx, double& iny, double& ox, double& oy);
+
+    virtual double GetPixelsPerMillimeterScreen();
+    virtual double GetPixelsPerMillimeterWorld();
+
+    virtual RS_FontEngine* GetFontEngine();
+
+    virtual void ProcessLabelGroup(SE_LabelInfo*    labels,
+                                   int              nlabels,
+                                   RS_OverpostType  type,
+                                   bool             exclude,
+                                   LineBuffer*      path = NULL);
+
+    virtual void AddExclusionRegion(RS_F_Point* fpts, int npts);
+
+    virtual void ProcessPoint(LineBuffer* geometry, SE_RenderPointStyle* style);
+    virtual void ProcessLine(LineBuffer* geometry, SE_RenderLineStyle* style);
+    virtual void ProcessArea(LineBuffer* geometry, SE_RenderAreaStyle* style);
+
 private:
     // Unimplemented Constructors/Methods
     KmlRenderer(const KmlRenderer&);



More information about the mapguide-commits mailing list