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

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sat Oct 24 09:33:23 EDT 2009


Author: uvlite
Date: 2009-10-24 09:33:23 -0400 (Sat, 24 Oct 2009)
New Revision: 4317

Modified:
   sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.cpp
Log:
RFC60 add more parser code for symbolization

Modified: sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.cpp
===================================================================
--- sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.cpp	2009-10-24 05:25:03 UTC (rev 4316)
+++ sandbox/rfc60/MgDev/Common/MdfModel/VectorScaleRange.cpp	2009-10-24 13:33:23 UTC (rev 4317)
@@ -34,6 +34,13 @@
 #include "TextSymbol.h"
 #include "W2DSymbol.h"
 
+#include "SimpleSymbol.h"
+#include "SimpleSymbolDefinition.h"
+#include "CompoundSymbolDefinition.h"
+#include "IGraphicElementVisitor.h"
+#include "LineUsage.h"
+#include "Path.h"
+
 using namespace MDFMODEL_NAMESPACE;
 
 // we must undefine the max macro so the limits max function compiles correctly
@@ -167,6 +174,75 @@
     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();
+
+
+    struct Local // local declaration of helper function
+    {
+        /// overloaded helper for SimpleSymbolDefinition
+        inline static void findColorInSymbolDefinition(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 static void findColorInSymbolDefinition(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)
+                        Local::findColorInSymbolDefinition(colorList, simsym->GetSymbolDefinition());
+                }
+            }
+
+        }
+        /// overloaded helper for SymbolDefinition
+        static void findColorInSymbolDefinition(PSTRCOLORLIST colorList, MdfModel::SymbolDefinition * symdef)
+        {
+            Local::findColorInSymbolDefinition(colorList, dynamic_cast<MdfModel::SimpleSymbolDefinition*>(symdef));
+            Local::findColorInSymbolDefinition(colorList, dynamic_cast<MdfModel::CompoundSymbolDefinition*>(symdef));
+        }
+    };
+
     // compute new color list by iterating through the featuretypecollection
     FeatureTypeStyleCollection* pftsColl = this->GetFeatureTypeStyles();
     int ftsccount = pftsColl->GetCount();
@@ -193,8 +269,8 @@
                 usedColorList->push_back(txtsym->GetBackgroundColor().substr());
             }
             // 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
+            // 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);
@@ -276,32 +352,28 @@
                 SymbolInstanceCollection* sic = pcsym->GetSymbolCollection();
                 int nInstances = sic->GetCount();
                 for (int i=0; i<nInstances; ++i)
-                {
+                {//                    bool isRef = false;
                     SymbolInstance* instance = sic->GetAt(i);
-                    bool isRef = false;
-
                     // get the symbol definition, either inlined or by reference
                     SymbolDefinition* symdef = instance->GetSymbolDefinition();
-                    if (symdef == NULL)
-                    {
-                        /// CHECK resource service
-                        const MdfString& ref = instance->GetResourceId(); // symbol reference
+                    if (symdef) // inline
+                        Local::findColorInSymbolDefinition(usedColorList, symdef);
+                    else
+                    {   // resourceId
+                        const MdfString& symref = instance->GetResourceId(); // symbol reference
 #ifdef _DEBUG
-                        printf("\n\nGetUserColorList(): found ResourceId %s\n\n", ref.c_str());
+                        // collect the symbolreference for later inspection?
+                        usedColorList->push_back(symref.substr());
+                        printf("\n\n$$$$$$$$$$$$$$$$$$$$$$$$ GetUserColorList(): found ResourceId %s\n\n", symref.c_str());
 #endif
-
+                        /// CHECK resource service
+//                        the following code is needed to use the resourceId to load a symboldefiniton into some colors but not here
 //                        symdef = m_resources->GetSymbolDefinition(ref.c_str());
 //                        if (symdef == NULL)    continue;
 //                        isRef = true;
                         // remember the current symbol resource id in case it references
                         // an attached png image resource
 //                        m_resIdStack.push_back(ref.c_str());
-                    } else
-                    {
-                        const MdfString& desc = symdef->GetDescription();
-#ifdef _DEBUG
-                        printf("\n\nGetUserColorList(): found Symbol %s\n\n", desc.c_str());
-#endif
                     }
 //                    if (isRef)  m_resIdStack.pop_back();
                 } // for sym instances



More information about the mapguide-commits mailing list