[mapguide-commits] r4250 - sandbox/rfc60/MgDev/Common/MdfModel

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Sep 22 19:01:56 EDT 2009


Author: uvlite
Date: 2009-09-22 19:01:56 -0400 (Tue, 22 Sep 2009)
New Revision: 4250

Modified:
   sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.cpp
   sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.h
Log:
rfc60 add a string based color list to the VectorScaleRange

Modified: sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.cpp
===================================================================
--- sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.cpp	2009-09-22 22:53:50 UTC (rev 4249)
+++ sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.cpp	2009-09-22 23:01:56 UTC (rev 4250)
@@ -22,7 +22,18 @@
 
 #include "stdafx.h"
 #include "VectorScaleRange.h"
+#include "AreaRule.h"
+#include "LineRule.h"
+#include "PointRule.h"
+#include "CompositeRule.h"
 
+#include "BlockSymbol.h"
+#include "FontSymbol.h"
+#include "ImageSymbol.h"
+#include "MarkSymbol.h"
+#include "TextSymbol.h"
+#include "W2DSymbol.h"
+
 using namespace MDFMODEL_NAMESPACE;
 
 // we must undefine the max macro so the limits max function compiles correctly
@@ -44,6 +55,7 @@
     this->m_dMinScale = 0.0;
     this->m_dMaxScale = MAX_MAP_SCALE;
     this->m_elevationSettings = NULL;
+    this->m_usedColorList = NULL;
 }
 
 //-------------------------------------------------------------------------
@@ -51,8 +63,11 @@
 //-------------------------------------------------------------------------
 VectorScaleRange::~VectorScaleRange()
 {
+    // delete members which are pointers explicitely
     if (this->m_elevationSettings != NULL)
         delete this->m_elevationSettings;
+    if (this->m_usedColorList != NULL)
+        delete this->m_usedColorList;
 }
 
 //-------------------------------------------------------------------------
@@ -141,3 +156,112 @@
         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)
+//-------------------------------------------------------------------------
+PSTRCOLORLIST VectorScaleRange::GetUsedColorList()
+{
+    // lazy instantiation
+    if (this->m_usedColorList)	return this->m_usedColorList;
+    // this should be sufficiently thread safe as the object is created immediately
+    PSTRCOLORLIST usedColorList = this->m_usedColorList = new STRCOLORLIST();
+    // compute new color list by iterating through the featuretypecollection
+    FeatureTypeStyleCollection* pftsColl = this->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
+            const MdfString& label = rule->GetLegendLabel();
+
+            // do the casting to access the relevant members
+            // this is bad style (instead of virtual functions GetColors() in each subclass)
+            // but we save touching too many different files
+            AreaRule* paRule = dynamic_cast<AreaRule*>(rule);
+            LineRule* plRule = dynamic_cast<LineRule*>(rule);
+            PointRule* ppRule = dynamic_cast<PointRule*>(rule);
+            //CompositeRule* pcRule = dynamic_cast<CompositeRule*>(rule);  // no colors in there
+
+            // 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
+
+        } // for GetRules
+    } // for GetFeatureTypeStyles
+    return this->m_usedColorList;
+}

Modified: sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.h
===================================================================
--- sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.h	2009-09-22 22:53:50 UTC (rev 4249)
+++ sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.h	2009-09-22 23:01:56 UTC (rev 4250)
@@ -23,7 +23,11 @@
 #include "FeatureTypeStyle.h"
 #include "ElevationSettings.h"
 #include "MdfRootObject.h"
+#include <list>
 
+typedef std::list<const MdfModel::MdfString> STRCOLORLIST;
+typedef STRCOLORLIST* PSTRCOLORLIST;
+
 BEGIN_NAMESPACE_MDFMODEL
 
     //-------------------------------------------------------------------------
@@ -62,6 +66,9 @@
         ElevationSettings* GetElevationSettings();
         void AdoptElevationSettings(ElevationSettings* elevationSettings);
 
+        // Computed Property :  UsedColorList
+        PSTRCOLORLIST GetUsedColorList();
+
     private:
         // Hidden copy constructor and assignment operator.
         VectorScaleRange(const VectorScaleRange&);
@@ -79,6 +86,9 @@
 
         // Extended data
         ElevationSettings* m_elevationSettings;
+
+        // cached colorlist
+        PSTRCOLORLIST m_usedColorList;
     };
 
     typedef MdfOwnerCollection<VectorScaleRange> VectorScaleRangeCollection;



More information about the mapguide-commits mailing list