[mapguide-commits] r4328 - in sandbox/rfc60/MgDev: Common/MapGuideCommon/MapLayer Common/MdfModel Common/Stylization Server/src/Services/Mapping Server/src/Services/Tile

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sun Nov 1 18:24:53 EST 2009


Author: uvlite
Date: 2009-11-01 18:24:51 -0500 (Sun, 01 Nov 2009)
New Revision: 4328

Modified:
   sandbox/rfc60/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp
   sandbox/rfc60/MgDev/Common/MapGuideCommon/MapLayer/Map.h
   sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.cpp
   sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.h
   sandbox/rfc60/MgDev/Common/Stylization/DefaultStylizer.cpp
   sandbox/rfc60/MgDev/Common/Stylization/DefaultStylizer.h
   sandbox/rfc60/MgDev/Common/Stylization/FeatureTypeStyleVisitor.h
   sandbox/rfc60/MgDev/Server/src/Services/Mapping/MappingUtil.cpp
   sandbox/rfc60/MgDev/Server/src/Services/Mapping/MappingUtil.h
   sandbox/rfc60/MgDev/Server/src/Services/Tile/ServerTileService.cpp
Log:
RFC60 integrated symbol lookup

Modified: sandbox/rfc60/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp
===================================================================
--- sandbox/rfc60/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp	2009-11-01 22:36:48 UTC (rev 4327)
+++ sandbox/rfc60/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp	2009-11-01 23:24:51 UTC (rev 4328)
@@ -1121,22 +1121,30 @@
 //////////////////////////////////////////////////////////////
 // ColorPalette Accessors
 // used for the map colors collected from the stylization of the visible layers
-PSTRCOLORLIST MgMap::GetColorPalette(CREFSTRING baseMapLayerGroupName)
+PSTRCOLORLIST MgMap::GetColorPalette()
 {
 	if (m_colorPalette == NULL)
 		m_colorPalette = new STRCOLORLIST();
 	return m_colorPalette;
 }
-/// setter does sort and prune the list also
-void MgMap::SetColorPalette(PSTRCOLORLIST newColorPalette, CREFSTRING baseMapLayerGroupName)
+/// setter adds list and then sorts and prunes the map colorlist
+void MgMap::AddColors2Palette(PSTRCOLORLIST newColorPalette)
 {
+    GetColorPalette();
 	// sort and delete duplicates if any coming in
 	if (newColorPalette != NULL && !newColorPalette->empty())
 	{
-		newColorPalette->sort();
-		newColorPalette->unique();
+        STRCOLORLIST::iterator it = newColorPalette->begin();
+        for(; it != newColorPalette->end(); it++)
+        {
+            if (*it != L"")    // filter empty strings
+            {   // uppercase the colorcodes (FFABDEFF) and filter empty strings
+                std::transform( (*it).begin(), (*it).end(), (*it).begin(), towupper);
+            }
+            m_colorPalette->push_back(*it);
+        }
 	}
-	assert (m_colorPalette == newColorPalette); //make sure this is the same!
-	m_colorPalette =  newColorPalette;
+	m_colorPalette->sort();
+    m_colorPalette->unique();
 }
 

Modified: sandbox/rfc60/MgDev/Common/MapGuideCommon/MapLayer/Map.h
===================================================================
--- sandbox/rfc60/MgDev/Common/MapGuideCommon/MapLayer/Map.h	2009-11-01 22:36:48 UTC (rev 4327)
+++ sandbox/rfc60/MgDev/Common/MapGuideCommon/MapLayer/Map.h	2009-11-01 23:24:51 UTC (rev 4328)
@@ -579,8 +579,8 @@
     virtual void OnLayerParentChanged(MgLayerBase* layer, CREFSTRING parentId);
 
 	/// accessor for the colors as defined in the baseMap with given name
-	PSTRCOLORLIST GetColorPalette(CREFSTRING baseMapLayerGroupName=L"");
-	void SetColorPalette(PSTRCOLORLIST newColorPalette, CREFSTRING baseMapLayerGroupName=L"" );
+	PSTRCOLORLIST GetColorPalette();
+	void AddColors2Palette(PSTRCOLORLIST newColorPalette);
 
     //////////////////////////////////////////////////////////////////
     /// Bulk load identity properties

Modified: sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.cpp
===================================================================
--- sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.cpp	2009-11-01 22:36:48 UTC (rev 4327)
+++ sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.cpp	2009-11-01 23:24:51 UTC (rev 4328)
@@ -62,7 +62,7 @@
     this->m_dMinScale = 0.0;
     this->m_dMaxScale = MAX_MAP_SCALE;
     this->m_elevationSettings = NULL;
-    this->m_usedColorList = NULL;
+//    this->m_usedColorList = NULL;
 }
 
 //-------------------------------------------------------------------------
@@ -73,8 +73,8 @@
     // delete members which are pointers explicitely
     if (this->m_elevationSettings != NULL)
         delete this->m_elevationSettings;
-    if (this->m_usedColorList != NULL)
-        delete this->m_usedColorList;
+//    if (this->m_usedColorList != NULL)
+//        delete this->m_usedColorList;
 }
 
 //-------------------------------------------------------------------------
@@ -163,7 +163,7 @@
         this->m_elevationSettings = elevationSettings;
     }
 }
-
+/*
 //-------------------------------------------------------------------------
 /// PURPOSE: Accessor method for the base colors defined in this Layer and scaleRange.
 /// RETURNS: A pointer to the list of colors of the collected colors (maybe empty but not null)
@@ -175,7 +175,6 @@
     // this should be sufficiently thread safe as the object is created immediately
     PSTRCOLORLIST usedColorList = this->m_usedColorList = new STRCOLORLIST();
 
-
     struct Local // local declaration of helper function
     {
         /// overloaded helper for SimpleSymbolDefinition
@@ -382,3 +381,4 @@
     } // for GetFeatureTypeStyles
     return this->m_usedColorList;
 }
+*/
\ No newline at end of file

Modified: sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.h
===================================================================
--- sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.h	2009-11-01 22:36:48 UTC (rev 4327)
+++ sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.h	2009-11-01 23:24:51 UTC (rev 4328)
@@ -67,7 +67,7 @@
         void AdoptElevationSettings(ElevationSettings* elevationSettings);
 
         // Computed Property :  UsedColorList
-        PSTRCOLORLIST GetUsedColorList();
+//        PSTRCOLORLIST GetUsedColorList();
 
     private:
         // Hidden copy constructor and assignment operator.
@@ -88,7 +88,7 @@
         ElevationSettings* m_elevationSettings;
 
         // cached colorlist
-        PSTRCOLORLIST m_usedColorList;
+//        PSTRCOLORLIST m_usedColorList;
     };
 
     typedef MdfOwnerCollection<VectorScaleRange> VectorScaleRangeCollection;

Modified: sandbox/rfc60/MgDev/Common/Stylization/DefaultStylizer.cpp
===================================================================
--- sandbox/rfc60/MgDev/Common/Stylization/DefaultStylizer.cpp	2009-11-01 22:36:48 UTC (rev 4327)
+++ sandbox/rfc60/MgDev/Common/Stylization/DefaultStylizer.cpp	2009-11-01 23:24:51 UTC (rev 4328)
@@ -33,6 +33,7 @@
 DefaultStylizer::DefaultStylizer(SE_SymbolManager* sman)
 {
     m_pRasterAdapter = NULL;
+    m_symbolmanager = sman;
     m_styleEngine = new StylizationEngine(sman, &m_lbPool);
 }
 
@@ -46,7 +47,7 @@
     delete m_styleEngine;
 }
 
-
+///=======================================================================================
 void DefaultStylizer::StylizeVectorLayer(MdfModel::VectorLayerDefinition* layer,
                                          Renderer*                        renderer,
                                          RS_FeatureReader*                features,
@@ -74,150 +75,18 @@
     // check if we have any composite type styles - if we find at least
     // one then we'll use it and ignore any other non-composite type styles
     // TODO: confirm this is the behavior we want
-    bool foundComposite = false;
-    for (int i=0; i<ftsc->GetCount(); ++i)
-    {
-        MdfModel::FeatureTypeStyle* fts = ftsc->GetAt(i);
-        if (FeatureTypeStyleVisitor::DetermineFeatureTypeStyle(fts) == FeatureTypeStyleVisitor::ftsComposite)
-        {
-            foundComposite = true;
-            break;
-        }
-    }
-
     // composite type styles are handled by the new style engine
-    if (foundComposite)
-    {
+    if (FeatureTypeStyleVisitor::hasFeatureTypeStyleCollectionComposite(ftsc))
         m_styleEngine->StylizeVectorLayer(layer, scaleRange, (SE_Renderer*)renderer, features, xformer, cancel, userData);
-    }
     else
-    {
-        int nFeatures = 0;
-
-        // Here we check if the layer has a composite polyline style.  If so,
-        // we will make multiple feature queries and process the geometry
-        // once for each line style.  This makes things look much better.
-
-        // We can render polylines with composite styles using this method
-        // only if there is a single line style
-        MdfModel::FeatureTypeStyle* fts = (ftsc->GetCount() > 0)? ftsc->GetAt(0) : NULL;
-        if (NULL != fts
-            && FeatureTypeStyleVisitor::DetermineFeatureTypeStyle(fts) == FeatureTypeStyleVisitor::ftsLine
-            && renderer->RequiresCompositeLineStyleSeparation())
-        {
-            MdfModel::RuleCollection* rules = fts->GetRules();
-
-            // temporary holder for line styles
-            std::vector<MdfModel::LineSymbolizationCollection*> tmpSyms;
-
-            // For each rule transfer all line styles into a temporary collection
-            // and away from the layer definition.  Also obtain the maximum # of
-            // styles for all the rules.
-            int maxStyles = 0;
-            for (int m=0; m<rules->GetCount(); ++m)
-            {
-                MdfModel::LineRule* lr = (MdfModel::LineRule*)rules->GetAt(m);
-                MdfModel::LineSymbolizationCollection* syms = lr->GetSymbolizations();
-
-                // move composite line styles to a temporary collection away
-                // from the one in the layer definition
-                MdfModel::LineSymbolizationCollection* syms2 = new MdfModel::LineSymbolizationCollection();
-                while (syms->GetCount() > 0)
-                    syms2->Adopt(syms->OrphanAt(0));
-
-                tmpSyms.push_back(syms2);
-
-                // keep track of the maximum # of styles
-                maxStyles = rs_max(maxStyles, syms2->GetCount());
-            }
-
-            // if there are no styles, we still want to render so that labels
-            // draw even if we are not drawing the actual geometry
-            if (maxStyles == 0)
-            {
-                nFeatures = StylizeVLHelper(layer, scaleRange, renderer, features, true, xformer, cancel, userData);
-            }
-            else
-            {
-                // collection to store labels temporarily so that we add labels
-                // to each feature just once
-                std::vector<MdfModel::TextSymbol*> tmpLabels;
-
-                // now for each separate line style - run a feature query
-                // and stylization loop with that single style
-                for (int i=0; i<maxStyles; ++i)
-                {
-                    // reset reader if this is not the first time we stylize the feature
-                    if (i > 0)
-                        features->Reset();
-
-                    // for each rule, transfer a single line style from the temporary
-                    // collection to the layer definition
-                    for (int m=0; m<rules->GetCount(); ++m)
-                    {
-                        MdfModel::LineRule* lr = (MdfModel::LineRule*)rules->GetAt(m);
-                        MdfModel::LineSymbolizationCollection* syms = lr->GetSymbolizations();
-                        MdfModel::LineSymbolizationCollection* syms2 = tmpSyms[m];
-
-                        // remove label if this is not the first time we stylize
-                        // the feature
-                        if (i == 1)
-                            tmpLabels.push_back(lr->GetLabel()->OrphanSymbol());
-
-                        if (i < syms2->GetCount())
-                            syms->Adopt(syms2->GetAt(i));
-                    }
-
-                    nFeatures += StylizeVLHelper(layer, scaleRange, renderer, features, i==0, xformer, cancel, userData);
-
-                    // clear line style from each rule in the layer definition
-                    for (int m=0; m<rules->GetCount(); ++m)
-                    {
-                        MdfModel::LineRule* lr = (MdfModel::LineRule*)rules->GetAt(m);
-                        MdfModel::LineSymbolizationCollection* syms = lr->GetSymbolizations();
-
-                        // add back label if we removed it
-                        if (i > 0 && i == maxStyles-1)
-                            lr->GetLabel()->AdoptSymbol(tmpLabels[m]);
-
-                        if (syms->GetCount() > 0)
-                            syms->OrphanAt(0);
-                    }
-                }
-            }
-
-            // move composite line styles back to original layer definition
-            // collection so that it frees them up when we destroy it
-            for (int m=0; m<rules->GetCount(); ++m)
-            {
-                MdfModel::LineRule* lr = (MdfModel::LineRule*)rules->GetAt(m);
-                MdfModel::LineSymbolizationCollection* syms = lr->GetSymbolizations();
-                MdfModel::LineSymbolizationCollection* syms2 = tmpSyms[m];
-
-                while (syms2->GetCount() > 0)
-                    syms->Adopt(syms2->OrphanAt(0));
-
-                delete syms2;
-            }
-        }
-        else
-        {
-            // composite line style separation not required
-            nFeatures = StylizeVLHelper(layer, scaleRange, renderer, features, true, xformer, cancel, userData);
-        }
-
-        #ifdef _DEBUG
-        printf("  DefaultStylizer::StylizeVectorLayer() Layer: %S  Features: %d\n", layer->GetFeatureName().c_str(), nFeatures);
-        #endif
-    }
-
+        CompositeLineStyleHelper(layer, scaleRange, renderer, features, xformer, cancel, userData);
     // need to get rid of these since they cache per layer theming
     // information which may conflict with the next layer
     ClearAdapters();
     m_styleEngine->ClearCache();
 }
 
-
+///=======================================================================================
 int DefaultStylizer::StylizeVLHelper(MdfModel::VectorLayerDefinition* layer,
                                      MdfModel::VectorScaleRange*      scaleRange,
                                      Renderer*                        renderer,
@@ -343,8 +212,7 @@
 
     return nFeatures;
 }
-
-
+///=======================================================================================
 void DefaultStylizer::StylizeGridLayer(MdfModel::GridLayerDefinition* layer,
                                        Renderer*                      renderer,
                                        RS_FeatureReader*              features,
@@ -407,7 +275,7 @@
     ClearAdapters();
 }
 
-
+///=======================================================================================
 void DefaultStylizer::StylizeDrawingLayer(MdfModel::DrawingLayerDefinition* layer,
                                           Renderer*                         renderer,
                                           RS_InputStream*                   dwfin,
@@ -426,7 +294,7 @@
     }
 }
 
-
+///=======================================================================================
 // WARNING: given pointer to the new stylizer will be destroyed
 // by the stylizer (in its destructor)
 void DefaultStylizer::SetGeometryAdapter(FdoGeometryType type, GeometryAdapter* stylizer)
@@ -439,7 +307,7 @@
     m_hGeomStylizers[type] = stylizer;
 }
 
-
+///=======================================================================================
 GeometryAdapter* DefaultStylizer::FindGeomAdapter(int geomType)
 {
     GeometryAdapter* adapter = m_hGeomStylizers[geomType];
@@ -488,7 +356,7 @@
     return m_hGeomStylizers[geomType];
 }
 
-
+///=======================================================================================
 void DefaultStylizer::ClearAdapters()
 {
     std::map<int, GeometryAdapter*>::iterator sgiter = m_hGeomStylizers.begin();
@@ -507,3 +375,160 @@
         m_pRasterAdapter = NULL;
     }
 }
+
+///=======================================================================================
+/// parse the rules and move linesyms from lineRules into tmpSyms
+int DefaultStylizer::CollectLineStyles(MdfModel::RuleCollection* rules, LSCPVECTOR &tmpSyms)
+{
+    // For each rule transfer all line styles into a temporary collection
+    // and away from the layer definition.  Also obtain the maximum # of
+    // styles for all the rules.
+    int maxStyles = 0;
+    for (int m=0; m < rules->GetCount(); ++m)
+    {
+        MdfModel::LineRule* lr = (MdfModel::LineRule*)rules->GetAt(m);
+        MdfModel::LineSymbolizationCollection* syms = lr->GetSymbolizations();
+
+        // move composite line styles to a temporary collection away
+        // from the one in the layer definition
+        MdfModel::LineSymbolizationCollection* syms2 = new MdfModel::LineSymbolizationCollection();
+        while (syms->GetCount() > 0)
+            syms2->Adopt(syms->OrphanAt(0));
+
+        tmpSyms.push_back(syms2);
+
+        // keep track of the maximum # of styles
+        maxStyles = rs_max(maxStyles, syms2->GetCount());
+    }
+    return maxStyles;
+} 
+
+///=======================================================================================
+/// move composite line styles back from tmpSyms to original layer definition collection 
+/// so that it frees them up when we destroy it
+void DefaultStylizer::ReturnLineStyles(MdfModel::RuleCollection* rules, LSCPVECTOR &tmpSyms)
+{
+    for (int m=0; m<rules->GetCount(); ++m)
+    {
+        MdfModel::LineRule* lr = (MdfModel::LineRule*)rules->GetAt(m);
+        MdfModel::LineSymbolizationCollection* syms = lr->GetSymbolizations();
+        MdfModel::LineSymbolizationCollection* syms2 = tmpSyms[m];
+
+        while (syms2->GetCount() > 0)
+            syms->Adopt(syms2->OrphanAt(0));
+
+        delete syms2;
+    }
+}
+
+
+///=======================================================================================
+/// stylize multiple styles and remove labels in additional styles
+int DefaultStylizer::ProcessLineStyles(int                              maxStyles, 
+                                       MdfModel::RuleCollection*        rules,
+                                       LSCPVECTOR                       tmpSyms, 
+                                       MdfModel::VectorLayerDefinition* layer,
+                                       MdfModel::VectorScaleRange*      scaleRange,
+                                       Renderer*                        renderer,
+                                       RS_FeatureReader*                features,
+                                       CSysTransformer*                 xformer,
+                                       CancelStylization                cancel,
+                                       void*                            userData)
+{
+    int nFeatures =0;
+    // collection to store labels temporarily so that we add labels
+    // to each feature just once
+    std::vector<MdfModel::TextSymbol*> tmpLabels;
+
+    // now for each separate line style - run a feature query
+    // and stylization loop with that single style
+    for (int i=0; i < maxStyles; ++i)
+    {
+        // reset reader if this is not the first time we stylize the feature
+        if (i > 0)
+            features->Reset();
+
+        // for each rule, transfer a single line style from the temporary
+        // collection to the layer definition
+        for (int m=0; m < rules->GetCount(); ++m)
+        {
+            MdfModel::LineRule* lr = (MdfModel::LineRule*)rules->GetAt(m);
+            MdfModel::LineSymbolizationCollection* syms = lr->GetSymbolizations();
+            MdfModel::LineSymbolizationCollection* syms2 = tmpSyms[m];
+
+            // remove label if this is not the first time we stylize the feature
+            if (i == 1)
+                tmpLabels.push_back(lr->GetLabel()->OrphanSymbol());
+
+            // add 
+            if (i < syms2->GetCount())
+                syms->Adopt(syms2->GetAt(i));
+        }
+        /// call the helper
+        nFeatures += StylizeVLHelper(layer, scaleRange, renderer, features, i==0, xformer, cancel, userData);
+
+        // clear line style from each rule in the layer definition
+        for (int m=0; m<rules->GetCount(); ++m)
+        {
+            MdfModel::LineRule* lr = (MdfModel::LineRule*)rules->GetAt(m);
+            MdfModel::LineSymbolizationCollection* syms = lr->GetSymbolizations();
+
+            // add back label if we removed it
+            if (i > 0 && i == maxStyles-1)
+                lr->GetLabel()->AdoptSymbol(tmpLabels[m]);
+
+            if (syms->GetCount() > 0)
+                syms->OrphanAt(0);
+        }
+    }
+    return nFeatures;
+} 
+///=======================================================================================
+/// Here we check if the layer has a composite polyline style.  If so,
+/// we will make multiple feature queries and process the geometry
+/// once for each line style.  This makes things look much better.
+void DefaultStylizer::CompositeLineStyleHelper(MdfModel::VectorLayerDefinition* layer,
+                                               MdfModel::VectorScaleRange*      scaleRange,
+                                               Renderer*                        renderer,
+                                               RS_FeatureReader*                features,
+                                               CSysTransformer*                 xformer,
+                                               CancelStylization                cancel,
+                                               void*                            userData)
+{    
+    // we have a valid scale range... we can now go over the
+    // features and apply the feature styles in that range
+    MdfModel::FeatureTypeStyleCollection* ftsc = scaleRange->GetFeatureTypeStyles();
+
+    int nFeatures = 0;
+
+    // We can render polylines with composite styles using this method
+    // only if there is a single line style
+    MdfModel::FeatureTypeStyle* fts = (ftsc->GetCount() > 0)? ftsc->GetAt(0) : NULL;
+    if (NULL != fts
+        && FeatureTypeStyleVisitor::DetermineFeatureTypeStyle(fts) == FeatureTypeStyleVisitor::ftsLine
+        && renderer->RequiresCompositeLineStyleSeparation())
+    {
+        MdfModel::RuleCollection* rules = fts->GetRules();
+
+        // temporary holder for line styles
+        LSCPVECTOR tmpSyms;
+        int maxStyles = CollectLineStyles(rules,  tmpSyms);
+
+        // if there are no styles, we still want to render so that labels
+        // draw even if we are not drawing the actual geometry
+        if (maxStyles == 0)
+            nFeatures = StylizeVLHelper(layer, scaleRange, renderer, features, true, xformer, cancel, userData);
+        else
+            nFeatures = ProcessLineStyles(maxStyles, rules, tmpSyms, layer, scaleRange, renderer, features, xformer, cancel, userData);
+
+        ReturnLineStyles(rules, tmpSyms);
+    } 
+    else // composite line style separation not required 
+    {        
+        nFeatures = StylizeVLHelper(layer, scaleRange, renderer, features, true, xformer, cancel, userData);
+    }
+
+#ifdef _DEBUG
+printf("  DefaultStylizer::StylizeVectorLayer() Layer: %S  Features: %d\n", layer->GetFeatureName().c_str(), nFeatures);
+#endif
+}

Modified: sandbox/rfc60/MgDev/Common/Stylization/DefaultStylizer.h
===================================================================
--- sandbox/rfc60/MgDev/Common/Stylization/DefaultStylizer.h	2009-11-01 22:36:48 UTC (rev 4327)
+++ sandbox/rfc60/MgDev/Common/Stylization/DefaultStylizer.h	2009-11-01 23:24:51 UTC (rev 4328)
@@ -25,6 +25,8 @@
 class StylizationEngine;
 class SE_SymbolManager;
 
+typedef std::vector<MdfModel::LineSymbolizationCollection*> LSCPVECTOR;
+
 //-----------------------------------------------------------------------------
 // Stylizer used for all types of layers which do not have special
 // Stylizer implementation, which is currently all of them.
@@ -59,8 +61,9 @@
 
     STYLIZATION_API virtual void SetGeometryAdapter(FdoGeometryType type, GeometryAdapter* stylizer);
 
-private:
-    int StylizeVLHelper(MdfModel::VectorLayerDefinition* layer,
+    STYLIZATION_API virtual SE_SymbolManager* GetSymbolManager() { return m_symbolmanager; }
+protected:
+    virtual int StylizeVLHelper(MdfModel::VectorLayerDefinition* layer,
                         MdfModel::VectorScaleRange*      scaleRange,
                         Renderer*                        renderer,
                         RS_FeatureReader*                features,
@@ -68,6 +71,30 @@
                         CSysTransformer*                 xformer,
                         CancelStylization                cancel,
                         void*                            userData);
+
+private:
+    void CompositeLineStyleHelper(MdfModel::VectorLayerDefinition* layer,
+                                  MdfModel::VectorScaleRange*      scaleRange,
+                                  Renderer*                        renderer,
+                                  RS_FeatureReader*                features,
+                                  CSysTransformer*                 xformer,
+                                  CancelStylization                cancel,
+                                  void*                            userData);
+
+    int CollectLineStyles(MdfModel::RuleCollection* rules, LSCPVECTOR &tmpSyms);
+    void ReturnLineStyles(MdfModel::RuleCollection* rules, LSCPVECTOR &tmpSyms);
+
+    int ProcessLineStyles(int                              maxStyles, 
+                          MdfModel::RuleCollection*        rules,
+                          LSCPVECTOR                       tmpSyms, 
+                          MdfModel::VectorLayerDefinition* layer,
+                          MdfModel::VectorScaleRange*      scaleRange,
+                          Renderer*                        renderer,
+                          RS_FeatureReader*                features,
+                          CSysTransformer*                 xformer,
+                          CancelStylization                cancel,
+                          void*                            userData);
+
     GeometryAdapter* FindGeomAdapter(int geomType);
     void ClearAdapters();
 
@@ -80,6 +107,9 @@
     //composite stylizer
     StylizationEngine* m_styleEngine;
 
+    // keep a handle on the symbolmanager
+    SE_SymbolManager* m_symbolmanager;
+
     SE_BufferPool m_lbPool;
 };
 

Modified: sandbox/rfc60/MgDev/Common/Stylization/FeatureTypeStyleVisitor.h
===================================================================
--- sandbox/rfc60/MgDev/Common/Stylization/FeatureTypeStyleVisitor.h	2009-11-01 22:36:48 UTC (rev 4327)
+++ sandbox/rfc60/MgDev/Common/Stylization/FeatureTypeStyleVisitor.h	2009-11-01 23:24:51 UTC (rev 4328)
@@ -85,6 +85,20 @@
         return vis.GetFeatureTypeStyle();
     }
 
+    //static helper
+    static bool hasFeatureTypeStyleCollectionComposite(MdfModel::FeatureTypeStyleCollection* ftsc)
+    {
+        for (int i=0; i<ftsc->GetCount(); ++i)
+        {
+            MdfModel::FeatureTypeStyle* fts = ftsc->GetAt(i);
+            if (FeatureTypeStyleVisitor::DetermineFeatureTypeStyle(fts) == FeatureTypeStyleVisitor::ftsComposite)
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
 private:
     eFeatureTypeStyle m_type;
 };

Modified: sandbox/rfc60/MgDev/Server/src/Services/Mapping/MappingUtil.cpp
===================================================================
--- sandbox/rfc60/MgDev/Server/src/Services/Mapping/MappingUtil.cpp	2009-11-01 22:36:48 UTC (rev 4327)
+++ sandbox/rfc60/MgDev/Server/src/Services/Mapping/MappingUtil.cpp	2009-11-01 23:24:51 UTC (rev 4328)
@@ -22,6 +22,7 @@
 #include "Renderer.h"
 #include "AGGRenderer.h"
 #include "Stylizer.h"
+#include "DefaultStylizer.h"
 #include "SymbolVisitor.h"
 #include "SLDSymbols.h"
 #include "SE_StyleVisitor.h"
@@ -380,7 +381,7 @@
     TransformCacheMap transformCache;
 
     Ptr<MgStringCollection> layerIds = new MgStringCollection();
-    // Get the layers' resource content in a single request
+    // Get the layers' resource content in a single request by adding them to a collection
     for (int i = layers->GetCount()-1; i >= 0; i--)
     {
         Ptr<MgLayerBase> mapLayer = layers->GetItem(i);
@@ -405,6 +406,7 @@
 
         layerIds->Add(mapLayer->GetLayerDefinition()->ToString());
     }
+    // request the collection from resource service and add ResourceContent to the individual layers 
     if(layerIds->GetCount() != 0)
     {
         Ptr<MgStringCollection> layerContents = svcResource->GetResourceContents(layerIds, NULL);
@@ -421,7 +423,7 @@
             }
         }
     }
-
+    // cycle over the layers and do stylization
     for (int i = layers->GetCount()-1; i >= 0; i--)
     {
         auto_ptr<MdfModel::LayerDefinition> ldf;
@@ -438,7 +440,7 @@
 
         MG_SERVER_MAPPING_SERVICE_TRY()
 
-            //get layer definition
+            // get layer definition using SAX XML Parser
             ldf.reset(MgLayerBase::GetLayerDefinition(mapLayer->GetLayerResourceContent()));
 
             Ptr<MgLayerGroup> group = mapLayer->GetGroup();
@@ -472,7 +474,7 @@
             MdfModel::DrawingLayerDefinition* dl = dynamic_cast<MdfModel::DrawingLayerDefinition*>(ldf.get());
             MdfModel::GridLayerDefinition* gl = dynamic_cast<MdfModel::GridLayerDefinition*>(ldf.get());
 
-            if (vl)
+            if (vl) //############################################################################ VECTORLAYER
             {
                 #ifdef _DEBUG
                 long dwLayerStart = GetTickCount();
@@ -559,6 +561,7 @@
 
                     // create the reader we'll use
                     rsReader = ExecuteFeatureQuery(svcFeature, extent, vl, overrideFilter.c_str(), dstCs, layerCs, item);
+                    // create an autoPtr around the reader
                     FdoPtr<FdoIFeatureReader> fdoReader = (NULL == rsReader) ? NULL : rsReader->GetInternalReader();
 
                     #ifdef _DEBUG
@@ -571,37 +574,8 @@
                         dr->StartLayer(&layerInfo, &fcinfo);
                         ds->StylizeVectorLayer(vl, dr, rsReader, xformer, scale, NULL, NULL);
                         dr->EndLayer();
-                        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-                        // COLORPALETTE CODE from UV for Ticket #813
-                        // add the colors from this scaleRange and vectorlayer to the map colors
-                        // (overrideFilters == NULL could tells us 
-                        // that we have been called for rendering a map and not for selection)
-                        try {
-                            // the map object owns the color list so get a pointer from there
-                            PSTRCOLORLIST pStringColorPalette = map->GetColorPalette();
-                            PSTRCOLORLIST vLayerColors = scaleRange->GetUsedColorList();
-                            if (!vLayerColors->empty())
-                            {
-                                assert (pStringColorPalette);
-                                // add the vectorLayer's Colors to the map's color list
-                                STRCOLORLIST::iterator it = vLayerColors->begin();
-                                for(; it != vLayerColors->end(); it++)
-                                {	// uppercase the colorcodes (FFABDEFF) and filter empty strings
-                                    if (*it == L"") continue;
-                                    STRING upc = *it;
-                                    std::transform( upc.begin(), upc.end(), upc.begin(), towupper);
-                                    pStringColorPalette->push_back(upc);
-                                }
-                                assert (pStringColorPalette == map->GetColorPalette());
-                                // the property setter canonicalizes the palette
-                                map->SetColorPalette(pStringColorPalette);
-                            }
-                        } catch (exception e) {
-                            ACE_DEBUG((LM_DEBUG, L"(%t) %w caught in MappingUtil.ColorPaletteGeneration\n", e.what()));
-                            throw e;
-                        }
-                        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-                    }
+                        ExtractColors(map, scaleRange, ds);
+                   }
                 }
                 else  // not scaleRange
                 {
@@ -614,7 +588,7 @@
                 printf("  StylizeLayers() **LAYEREND** -Vector- Name:%S  Time:%6.4f (s)\n\n", (mapLayer->GetName()).c_str(), (GetTickCount()-dwLayerStart)/1000.0);
                 #endif
             }
-            else if (gl)
+            else if (gl)  //############################################################################ GRAPHICS layer
             {
                 // TODO: FDO RFP - Make FdoPtr's reference counter thread-safe.
                 static ACE_Recursive_Thread_Mutex sg_fdoRfpMutex;
@@ -755,7 +729,7 @@
                 printf("  StylizeLayers() **LAYEREND** -Grid- Name:%S  Time:%6.4f (s)\n\n", (mapLayer->GetName()).c_str(), (GetTickCount()-dwLayerStart)/1000.0);
                 #endif
             }
-            else if (dl) //drawing layer
+            else if (dl) //############################################################################ drawing layer
             {
                 #ifdef _DEBUG
                 long dwLayerStart = GetTickCount();
@@ -817,7 +791,7 @@
                 #ifdef _DEBUG
                 printf("  StylizeLayers() **LAYEREND** -Drawing- Name:%S  Time = %6.4f (s)\n\n", (mapLayer->GetName()).c_str(), (GetTickCount()-dwLayerStart)/1000.0);
                 #endif
-            }
+            } // end layer switch
 
         MG_SERVER_MAPPING_SERVICE_CATCH(L"MgMappingUtil.StylizeLayers");
 
@@ -1165,7 +1139,7 @@
     return NULL;
 }
 
-
+///----------------------------------------------------------------------------------------
 // transforms a given extent and returns the new extent in the new cs
 MgEnvelope* MgMappingUtil::TransformExtent(MgEnvelope* extent, MgCoordinateSystemTransform* xform)
 {
@@ -1230,3 +1204,226 @@
 {
     SetStylizerExceptionCallback(&MgMappingUtilExceptionTrap);
 }
+
+//-------------------------------------------------------------------------
+/// PURPOSE: Accessor method for the base colors defined in this Layer and scaleRange.
+/// RETURNS: A pointer to the list of colors of the collected colors (maybe empty but not null)
+//-------------------------------------------------------------------------
+PSTRCOLORLIST MgMappingUtil::GetUsedColorsFromScaleRange(MdfModel::VectorScaleRange* vsr, 
+                                                         SE_SymbolManager* sman)
+{
+    PSTRCOLORLIST usedColorList = new STRCOLORLIST();
+
+    // compute new color list by iterating through the featuretypecollection
+    FeatureTypeStyleCollection* pftsColl = vsr->GetFeatureTypeStyles();
+    int ftsccount = pftsColl->GetCount();
+    for (int j=0; j< ftsccount; j++)
+    {
+        FeatureTypeStyle* pfts = pftsColl->GetAt(j);
+
+        // iterate through the rulecollection
+        RuleCollection* ruleColl = pfts->GetRules();
+        int rccount = ruleColl->GetCount();
+        for (int k=0; k < rccount; k++)
+        {
+            Rule* rule = ruleColl->GetAt(k);
+
+            // get the label which will be the key in the color map
+            Label* label = rule->GetLabel();
+            // the legend label is just a string
+            // const MdfString& legendLabel = rule->GetLegendLabel();
+
+            // add colors of txtsymbols
+            TextSymbol* txtsym = label->GetSymbol();
+            if (txtsym) {
+                usedColorList->push_back(txtsym->GetForegroundColor().substr());
+                usedColorList->push_back(txtsym->GetBackgroundColor().substr());
+            }
+            // do the casting to access the relevant members
+            // this is bad style (instead of using the visitor pattern of the Mdfmodel)
+            // but it keeps it nice and compact and documents the structure better...
+            AreaRule* paRule = dynamic_cast<AreaRule*>(rule);
+            LineRule* plRule = dynamic_cast<LineRule*>(rule);
+            PointRule* ppRule = dynamic_cast<PointRule*>(rule);
+            CompositeRule* pcRule = dynamic_cast<CompositeRule*>(rule);  // used for new stylization
+
+            // AreaRule Symbolization.....
+            if (paRule != NULL)
+            {					
+                AreaSymbolization2D* pasym = paRule->GetSymbolization();
+                if (pasym->GetFill() != NULL) 
+                {	// create copies of all strings!!! so we can safely delete the resulting list later
+                    usedColorList->push_back(pasym->GetFill()->GetForegroundColor().substr());
+                    usedColorList->push_back(pasym->GetFill()->GetBackgroundColor().substr());
+                }
+                if (pasym->GetEdge() != NULL) 
+                    usedColorList->push_back(pasym->GetEdge()->GetColor().substr());
+            }
+
+            // LineRule Symbolization.....
+            if (plRule != NULL)
+            {
+                LineSymbolizationCollection* plsymcol = plRule->GetSymbolizations();
+                // iterate through the linesymbolizations
+                int lsccount = plsymcol->GetCount();
+                for (int l=0; l < lsccount; l++)
+                {
+                    LineSymbolization2D* plsym = plsymcol->GetAt(l);
+                    if (plsym->GetStroke() != NULL)
+                        usedColorList->push_back(plsym->GetStroke()->GetColor().substr());
+                }
+            }
+            // PointRule Symbolization.....
+            if (ppRule != NULL)
+            {
+                PointSymbolization2D* ppsym = ppRule->GetSymbolization();
+                if (ppsym)
+                {
+                    Symbol *sym   = ppsym->GetSymbol();
+                    MdfModel::BlockSymbol* blockSymbol = dynamic_cast<MdfModel::BlockSymbol*>(sym);
+                    MdfModel::FontSymbol* fontSymbol = dynamic_cast<MdfModel::FontSymbol*>(sym);
+                    MdfModel::MarkSymbol* markSymbol = dynamic_cast<MdfModel::MarkSymbol*>(sym);
+                    MdfModel::TextSymbol* textSymbol = dynamic_cast<MdfModel::TextSymbol*>(sym);
+                    MdfModel::W2DSymbol* w2dSymbol = dynamic_cast<MdfModel::W2DSymbol*>(sym);
+                    if (blockSymbol != NULL)
+                    {
+                        usedColorList->push_back(blockSymbol->GetBlockColor().substr());
+                        usedColorList->push_back(blockSymbol->GetLayerColor().substr());
+                    }
+                    if (fontSymbol != NULL)
+                    {
+                        usedColorList->push_back(fontSymbol->GetForegroundColor().substr());
+                    }
+                    if (markSymbol != NULL)
+                    {
+                        if (markSymbol->GetEdge() != NULL)
+                            usedColorList->push_back(markSymbol->GetEdge()->GetColor().substr());
+                        if (markSymbol->GetFill() != NULL) {
+                            usedColorList->push_back(markSymbol->GetFill()->GetForegroundColor().substr());
+                            usedColorList->push_back(markSymbol->GetFill()->GetBackgroundColor().substr());
+                        }
+                    }
+                    if (textSymbol != NULL)
+                    {
+                        usedColorList->push_back(textSymbol->GetForegroundColor().substr());
+                        usedColorList->push_back(textSymbol->GetBackgroundColor().substr());
+                    }
+                    if (w2dSymbol != NULL)
+                    {
+                        usedColorList->push_back(w2dSymbol->GetFillColor().substr());
+                        usedColorList->push_back(w2dSymbol->GetLineColor().substr());
+                        usedColorList->push_back(w2dSymbol->GetTextColor().substr());
+                    }
+                } // if pointSymbolization
+            } // end pointRule
+            // CompositeRule Symbolization.....
+            if (pcRule != NULL)
+            {					
+                CompositeSymbolization* pcsym = pcRule->GetSymbolization();
+                SymbolInstanceCollection* sic = pcsym->GetSymbolCollection();
+                int nInstances = sic->GetCount();
+                for (int i=0; i<nInstances; ++i)
+                {//                    bool isRef = false;
+                    SymbolInstance* instance = sic->GetAt(i);
+                    // get the symbol definition, either inlined or by reference
+                    SymbolDefinition* symdef = instance->GetSymbolDefinition();
+                    if (symdef) // inline
+                        FindColorInSymDefHelper(usedColorList, symdef);
+                    else
+                    {   // resourceId
+                        const MdfString& symref = instance->GetResourceId(); // symbol reference
+                        if (sman)
+                        {   // if we have a symbolmanager do the lookup
+                            MdfModel::SymbolDefinition* symdef = sman->GetSymbolDefinition(symref.c_str());
+                            FindColorInSymDefHelper(usedColorList, symdef);
+                        }
+                    }
+                } // for sym instances
+            } // for CompositeRule
+        } // for GetRules
+    } // for GetFeatureTypeStyles
+    return usedColorList;
+}
+
+///=======================================================================================
+/// extract colors from the scalerange, lookup the referenceIds and store them with the map
+void MgMappingUtil::ExtractColors(MgMap* map, MdfModel::VectorScaleRange* scaleRange, Stylizer* sty)
+{
+    // add the colors from this scaleRange and vectorlayer to the map colors
+    try {
+    DefaultStylizer* ds = dynamic_cast<DefaultStylizer*>(sty);
+    SE_SymbolManager* sman = ds?ds->GetSymbolManager():NULL;
+        // parse the scalerange
+        PSTRCOLORLIST vLayerColors = GetUsedColorsFromScaleRange(scaleRange, sman);
+        if (!vLayerColors->empty())
+            map->AddColors2Palette(vLayerColors); // the property setter canonicalizes the palette
+    } catch (exception e) {
+        ACE_DEBUG((LM_DEBUG, L"(%t) %w caught in MappingUtil.ExtractColors\n", e.what()));
+        throw e;
+    }
+}
+
+///=======================================================================================
+/// overloaded helper for SimpleSymbolDefinition
+inline void MgMappingUtil::FindColorInSymDefHelper(PSTRCOLORLIST colorList, MdfModel::SimpleSymbolDefinition * symdef)
+{
+    /// the visitor for the graphics
+    class GraphicElementVisitorImpl : public MdfModel::IGraphicElementVisitor
+    {
+    public:
+        PSTRCOLORLIST colorList;
+        void VisitPath (Path& path){
+            colorList->push_back(path.GetLineColor().substr());
+            colorList->push_back(path.GetFillColor().substr());                       
+        };
+        void VisitImage(Image& image){};
+        void VisitText (Text& text){};
+    } visitor;
+    if (symdef)
+    {
+        MdfModel::LineUsage* lineUsage = symdef->GetLineUsage();
+        if (lineUsage)
+        {
+            MdfModel::Path *path = lineUsage->GetDefaultPath();
+            if (path)
+            {
+                colorList->push_back(path->GetLineColor().substr());
+                colorList->push_back(path->GetFillColor().substr());                       
+            }
+        }
+
+        MdfModel::GraphicElementCollection* graphElems = symdef->GetGraphics();
+        int gInstances = graphElems->GetCount();
+        for (int i=0; i < gInstances; ++i)
+        {
+            MdfModel::GraphicElement* graphics = graphElems->GetAt(i);
+            if (graphics)
+            {
+                visitor.colorList = colorList; // use injection to pass reference to list
+                graphics->AcceptVisitor(visitor);
+            }
+        }
+    }
+}
+/// overloaded helper for CompoundSymbolDefinition
+inline void MgMappingUtil::FindColorInSymDefHelper(PSTRCOLORLIST colorList, MdfModel::CompoundSymbolDefinition * symdef)
+{
+    if (symdef)
+    {
+        MdfModel::SimpleSymbolCollection* simSymCol = symdef->GetSymbols();
+        int kInstances = simSymCol->GetCount();
+        for (int i=0; i < kInstances; ++i)
+        {
+            MdfModel::SimpleSymbol* simsym = simSymCol->GetAt(i);
+            if (simsym)
+                FindColorInSymDefHelper(colorList, simsym->GetSymbolDefinition());
+        }
+    }
+
+}
+/// overloaded helper for SymbolDefinition
+inline void MgMappingUtil::FindColorInSymDefHelper(PSTRCOLORLIST colorList, MdfModel::SymbolDefinition * symdef)
+{
+    FindColorInSymDefHelper(colorList, dynamic_cast<MdfModel::SimpleSymbolDefinition*>(symdef));
+    FindColorInSymDefHelper(colorList, dynamic_cast<MdfModel::CompoundSymbolDefinition*>(symdef));
+}

Modified: sandbox/rfc60/MgDev/Server/src/Services/Mapping/MappingUtil.h
===================================================================
--- sandbox/rfc60/MgDev/Server/src/Services/Mapping/MappingUtil.h	2009-11-01 22:36:48 UTC (rev 4327)
+++ sandbox/rfc60/MgDev/Server/src/Services/Mapping/MappingUtil.h	2009-11-01 23:24:51 UTC (rev 4328)
@@ -20,6 +20,9 @@
 
 #include "ServerMappingDllExport.h"
 #include "MapGuideCommon.h"
+#include "SE_SymbolManager.h"
+#include "SymbolDefinition.h"
+#include "CompoundSymbolDefinition.h"
 
 //fwd declare
 class MgResourceService;
@@ -80,6 +83,16 @@
 
     static void InitializeStylizerCallback();
     static MgPolygon* GetPolygonFromEnvelope(MgEnvelope* extent);
+
+    // RFC60 addition
+    static void ExtractColors(MgMap* map, MdfModel::VectorScaleRange* scaleRange, Stylizer* ds);
+    static PSTRCOLORLIST GetUsedColorsFromScaleRange(MdfModel::VectorScaleRange* vsr, SE_SymbolManager* sm);
+
+    // helper
+    static void FindColorInSymDefHelper(PSTRCOLORLIST colorList, MdfModel::SymbolDefinition * symdef);
+    static void FindColorInSymDefHelper(PSTRCOLORLIST colorList, MdfModel::CompoundSymbolDefinition * symdef);
+    static void FindColorInSymDefHelper(PSTRCOLORLIST colorList, MdfModel::SimpleSymbolDefinition * symdef);
+
 };
 
 #endif

Modified: sandbox/rfc60/MgDev/Server/src/Services/Tile/ServerTileService.cpp
===================================================================
--- sandbox/rfc60/MgDev/Server/src/Services/Tile/ServerTileService.cpp	2009-11-01 22:36:48 UTC (rev 4327)
+++ sandbox/rfc60/MgDev/Server/src/Services/Tile/ServerTileService.cpp	2009-11-01 23:24:51 UTC (rev 4328)
@@ -224,6 +224,11 @@
             if (sm_mapCache.end() != iter)
             {
                 cachedMap = SAFE_ADDREF((*iter).second);
+                /// refactored from below
+                cachedMap->Rewind();
+                Ptr<MgStream> stream = new MgStream(cachedMap);
+                map = new MgMap();
+                map->Deserialize(stream);
             }
             else
             {
@@ -241,14 +246,14 @@
                 sm_mapCache[mapString] = SAFE_ADDREF((MgMemoryStreamHelper*)cachedMap);
             }
 
+            //if (!map)     
+            //{
+            //    cachedMap->Rewind();
+            //    Ptr<MgStream> stream = new MgStream(cachedMap);
+            //    map = new MgMap();
+            //    map->Deserialize(stream);
+            //}
 
-            if (!map)
-            {
-                cachedMap->Rewind();
-                Ptr<MgStream> stream = new MgStream(cachedMap);
-                map = new MgMap();
-                map->Deserialize(stream);
-            }
         }   // end of mutex scope
 
         double scale = map->GetFiniteDisplayScaleAt(scaleIndex);
@@ -257,7 +262,7 @@
         // Render the tile and cache it.
         ret = GetTile(tilePathname, map, scaleIndex, baseMapLayerGroupName, tileColumn, tileRow);
         break;
-    }
+    } // Call ~MgMap DTOR via Ptr<>
 
     MG_CATCH(L"MgServerTileService.GetTile")
 



More information about the mapguide-commits mailing list