[mapguide-commits] r6804 - in trunk/Tools/Maestro: ExtendedModels/LayerDefinition-2.3.0 ExtendedModels/LayerDefinition-2.4.0 ExtendedModels/MapDefinition-2.3.0 ExtendedModels/MapDefinition-2.4.0 ExtendedModels/WatermarkDefinition-2.3.0 Maestro.AddIn.Local/Services Maestro.Base/Editor Maestro.Editors/WatermarkDefinition OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI/ObjectModels

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Jun 25 06:26:33 PDT 2012


Author: jng
Date: 2012-06-25 06:26:33 -0700 (Mon, 25 Jun 2012)
New Revision: 6804

Added:
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/WatermarkCollectionUtil.cs
Modified:
   trunk/Tools/Maestro/ExtendedModels/LayerDefinition-2.3.0/OSGeo.MapGuide.ObjectModels.LayerDefinition-2.3.0.csproj
   trunk/Tools/Maestro/ExtendedModels/LayerDefinition-2.4.0/OSGeo.MapGuide.ObjectModels.LayerDefinition-2.4.0.csproj
   trunk/Tools/Maestro/ExtendedModels/MapDefinition-2.3.0/OSGeo.MapGuide.ObjectModels.MapDefinition-2.3.0.csproj
   trunk/Tools/Maestro/ExtendedModels/MapDefinition-2.4.0/OSGeo.MapGuide.ObjectModels.MapDefinition-2.4.0.csproj
   trunk/Tools/Maestro/ExtendedModels/WatermarkDefinition-2.3.0/WatermarkImpl.cs
   trunk/Tools/Maestro/Maestro.AddIn.Local/Services/LocalPreviewer.cs
   trunk/Tools/Maestro/Maestro.Base/Editor/ResourcePreviewEngine.cs
   trunk/Tools/Maestro/Maestro.Editors/WatermarkDefinition/WatermarkCollectionEditorCtrl.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/MapDefinition.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/VectorLayerDefinitionImpl.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/WatermarkInterfaces.cs
Log:
#2036: Fix inability to add watermark instances to a Map Definition if originating from a different resource version (eg. A 2.3 watermark to a 2.4 Map Definition or vice versa). To fix this we removed the CreateInstance() API from IWatermarkDefinition. Instead we delegate watermark instance creation to a new internal WatermarkCollectionUtil utility class. This allows watermark instances to be detached from the WatermarkDefinition version allowing watermarks to be added from *any* Watermark Definition regardless of schema version. The existing Watermark Collection editor has been re-worked to work against this change of APIs

Modified: trunk/Tools/Maestro/ExtendedModels/LayerDefinition-2.3.0/OSGeo.MapGuide.ObjectModels.LayerDefinition-2.3.0.csproj
===================================================================
--- trunk/Tools/Maestro/ExtendedModels/LayerDefinition-2.3.0/OSGeo.MapGuide.ObjectModels.LayerDefinition-2.3.0.csproj	2012-06-22 17:50:14 UTC (rev 6803)
+++ trunk/Tools/Maestro/ExtendedModels/LayerDefinition-2.3.0/OSGeo.MapGuide.ObjectModels.LayerDefinition-2.3.0.csproj	2012-06-25 13:26:33 UTC (rev 6804)
@@ -73,6 +73,9 @@
     <Compile Include="..\..\OSGeo.MapGuide.MaestroAPI\ObjectModels\VectorLayerDefinitionImpl.cs">
       <Link>VectorLayerDefinitionImpl.cs</Link>
     </Compile>
+    <Compile Include="..\..\OSGeo.MapGuide.MaestroAPI\ObjectModels\WatermarkCollectionUtil.cs">
+      <Link>WatermarkCollectionUtil.cs</Link>
+    </Compile>
     <Compile Include="..\..\Properties\GlobalAssemblyInfo.cs">
       <Link>GlobalAssemblyInfo.cs</Link>
     </Compile>

Modified: trunk/Tools/Maestro/ExtendedModels/LayerDefinition-2.4.0/OSGeo.MapGuide.ObjectModels.LayerDefinition-2.4.0.csproj
===================================================================
--- trunk/Tools/Maestro/ExtendedModels/LayerDefinition-2.4.0/OSGeo.MapGuide.ObjectModels.LayerDefinition-2.4.0.csproj	2012-06-22 17:50:14 UTC (rev 6803)
+++ trunk/Tools/Maestro/ExtendedModels/LayerDefinition-2.4.0/OSGeo.MapGuide.ObjectModels.LayerDefinition-2.4.0.csproj	2012-06-25 13:26:33 UTC (rev 6804)
@@ -73,6 +73,9 @@
     <Compile Include="..\..\OSGeo.MapGuide.MaestroAPI\ObjectModels\VectorLayerDefinitionImpl.cs">
       <Link>VectorLayerDefinitionImpl.cs</Link>
     </Compile>
+    <Compile Include="..\..\OSGeo.MapGuide.MaestroAPI\ObjectModels\WatermarkCollectionUtil.cs">
+      <Link>WatermarkCollectionUtil.cs</Link>
+    </Compile>
     <Compile Include="..\..\Properties\GlobalAssemblyInfo.cs">
       <Link>GlobalAssemblyInfo.cs</Link>
     </Compile>

Modified: trunk/Tools/Maestro/ExtendedModels/MapDefinition-2.3.0/OSGeo.MapGuide.ObjectModels.MapDefinition-2.3.0.csproj
===================================================================
--- trunk/Tools/Maestro/ExtendedModels/MapDefinition-2.3.0/OSGeo.MapGuide.ObjectModels.MapDefinition-2.3.0.csproj	2012-06-22 17:50:14 UTC (rev 6803)
+++ trunk/Tools/Maestro/ExtendedModels/MapDefinition-2.3.0/OSGeo.MapGuide.ObjectModels.MapDefinition-2.3.0.csproj	2012-06-25 13:26:33 UTC (rev 6804)
@@ -67,6 +67,9 @@
     <Compile Include="..\..\OSGeo.MapGuide.MaestroAPI\ObjectModels\MapDefinition.cs">
       <Link>MapDefinition.cs</Link>
     </Compile>
+    <Compile Include="..\..\OSGeo.MapGuide.MaestroAPI\ObjectModels\WatermarkCollectionUtil.cs">
+      <Link>WatermarkCollectionUtil.cs</Link>
+    </Compile>
     <Compile Include="..\..\Properties\GlobalAssemblyInfo.cs">
       <Link>GlobalAssemblyInfo.cs</Link>
     </Compile>

Modified: trunk/Tools/Maestro/ExtendedModels/MapDefinition-2.4.0/OSGeo.MapGuide.ObjectModels.MapDefinition-2.4.0.csproj
===================================================================
--- trunk/Tools/Maestro/ExtendedModels/MapDefinition-2.4.0/OSGeo.MapGuide.ObjectModels.MapDefinition-2.4.0.csproj	2012-06-22 17:50:14 UTC (rev 6803)
+++ trunk/Tools/Maestro/ExtendedModels/MapDefinition-2.4.0/OSGeo.MapGuide.ObjectModels.MapDefinition-2.4.0.csproj	2012-06-25 13:26:33 UTC (rev 6804)
@@ -67,6 +67,9 @@
     <Compile Include="..\..\OSGeo.MapGuide.MaestroAPI\ObjectModels\MapDefinition.cs">
       <Link>MapDefinition.cs</Link>
     </Compile>
+    <Compile Include="..\..\OSGeo.MapGuide.MaestroAPI\ObjectModels\WatermarkCollectionUtil.cs">
+      <Link>WatermarkCollectionUtil.cs</Link>
+    </Compile>
     <Compile Include="..\..\Properties\GlobalAssemblyInfo.cs">
       <Link>GlobalAssemblyInfo.cs</Link>
     </Compile>

Modified: trunk/Tools/Maestro/ExtendedModels/WatermarkDefinition-2.3.0/WatermarkImpl.cs
===================================================================
--- trunk/Tools/Maestro/ExtendedModels/WatermarkDefinition-2.3.0/WatermarkImpl.cs	2012-06-22 17:50:14 UTC (rev 6803)
+++ trunk/Tools/Maestro/ExtendedModels/WatermarkDefinition-2.3.0/WatermarkImpl.cs	2012-06-25 13:26:33 UTC (rev 6804)
@@ -210,17 +210,6 @@
             return this.Clone();
         }
 
-        public IWatermark CreateInstance()
-        {
-            return new WatermarkType() 
-            {
-                ResourceId = this.ResourceID,
-                Name = ResourceIdentifier.GetName(this.ResourceID),
-                Usage = UsageType.All
-            };
-        }
-
-
         public IXYPosition CreateXYPosition()
         {
             return new XYPositionType()

Modified: trunk/Tools/Maestro/Maestro.AddIn.Local/Services/LocalPreviewer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.AddIn.Local/Services/LocalPreviewer.cs	2012-06-22 17:50:14 UTC (rev 6803)
+++ trunk/Tools/Maestro/Maestro.AddIn.Local/Services/LocalPreviewer.cs	2012-06-25 13:26:33 UTC (rev 6804)
@@ -67,14 +67,13 @@
                 string resId = "Session:" + edSvc.SessionID + "//" + Guid.NewGuid() + "." + res.ResourceType.ToString();
                 edSvc.ResourceService.SetResourceXmlData(resId, ResourceTypeRegistry.Serialize(res));
 
-                var wm = ((IWatermarkDefinition)res).CreateInstance();
-                wm.ResourceId = resId;
                 var csFact = new MgCoordinateSystemFactory();
                 var arbXY = csFact.ConvertCoordinateSystemCodeToWkt("XY-M");
                 mapDef = ObjectFactory.CreateMapDefinition(conn, new Version(2, 3, 0), "Preview");
                 mapDef.CoordinateSystem = arbXY;
                 mapDef.SetExtents(-100000, -100000, 100000, 100000);
-                ((IMapDefinition2)mapDef).AddWatermark(wm);
+                var wm = ((IMapDefinition2)mapDef).AddWatermark(((IWatermarkDefinition)res));
+                wm.ResourceId = resId;
             }
 
             var mapResId = new MgResourceIdentifier("Session:" + edSvc.SessionID + "//" + Guid.NewGuid() + "." + res.ResourceType.ToString());

Modified: trunk/Tools/Maestro/Maestro.Base/Editor/ResourcePreviewEngine.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Editor/ResourcePreviewEngine.cs	2012-06-22 17:50:14 UTC (rev 6803)
+++ trunk/Tools/Maestro/Maestro.Base/Editor/ResourcePreviewEngine.cs	2012-06-25 13:26:33 UTC (rev 6804)
@@ -183,7 +183,7 @@
             IMapDefinition2 map = (IMapDefinition2)ObjectFactory.CreateMapDefinition(wmd.CurrentConnection, wmd.SupportedMapDefinitionVersion, "Watermark Definition Preview");
             map.CoordinateSystem = @"LOCAL_CS[""*XY-M*"", LOCAL_DATUM[""*X-Y*"", 10000], UNIT[""Meter"", 1], AXIS[""X"", EAST], AXIS[""Y"", NORTH]]";
             map.Extents = ObjectFactory.CreateEnvelope(-1000000, -1000000, 1000000, 1000000);
-            map.AddWatermark(wmd.CreateInstance());
+            map.AddWatermark(wmd);
             return GenerateMapPreviewUrl(map);
         }
 

Modified: trunk/Tools/Maestro/Maestro.Editors/WatermarkDefinition/WatermarkCollectionEditorCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/WatermarkDefinition/WatermarkCollectionEditorCtrl.cs	2012-06-22 17:50:14 UTC (rev 6803)
+++ trunk/Tools/Maestro/Maestro.Editors/WatermarkDefinition/WatermarkCollectionEditorCtrl.cs	2012-06-25 13:26:33 UTC (rev 6804)
@@ -64,13 +64,17 @@
                 {
                     LastSelectedFolder.FolderId = picker.SelectedFolder;
                     var wdf = (IWatermarkDefinition)_resSvc.GetResource(picker.ResourceID);
-                    var wm = wdf.CreateInstance();
+                    //var wm = wdf.CreateInstance();
+                    var wm = _watermarks.AddWatermark(wdf);
                     var diag = new WatermarkInstanceEditorDialog(_resSvc, wm);
                     if (diag.ShowDialog() == DialogResult.OK)
                     {
                         _list.Add(wm);
-                        _watermarks.AddWatermark(wm);
                     }
+                    else //Undo
+                    {
+                        _watermarks.RemoveWatermark(wm);
+                    }
                 }
             }
         }

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj	2012-06-22 17:50:14 UTC (rev 6803)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj	2012-06-25 13:26:33 UTC (rev 6804)
@@ -251,6 +251,7 @@
     <Compile Include="ObjectModels\IFdoSpatialContext.cs" />
     <Compile Include="ObjectModels\NsDoc.cs" />
     <Compile Include="ObjectModels\SymbolDefFactory.cs" />
+    <Compile Include="ObjectModels\WatermarkCollectionUtil.cs" />
     <Compile Include="ObjectModels\WatermarkInterfaces.cs" />
     <Compile Include="Resource\Comparison\BinaryData.cs" />
     <Compile Include="Resource\Comparison\CharData.cs" />

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/MapDefinition.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/MapDefinition.cs	2012-06-22 17:50:14 UTC (rev 6803)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/MapDefinition.cs	2012-06-25 13:26:33 UTC (rev 6804)
@@ -663,26 +663,14 @@
             }
         }
 
-        void IWatermarkCollection.AddWatermark(OSGeo.MapGuide.ObjectModels.WatermarkDefinition.IWatermark watermark)
+        IWatermark IWatermarkCollection.AddWatermark(OSGeo.MapGuide.ObjectModels.WatermarkDefinition.IWatermarkDefinition watermark)
         {
-#if MDF_240
-            var wm = watermark as OSGeo.MapGuide.ObjectModels.WatermarkDefinition_2_4_0.WatermarkType;
-#else
-            var wm = watermark as OSGeo.MapGuide.ObjectModels.WatermarkDefinition_2_3_0.WatermarkType;
-#endif
-            if (wm != null)
-                this.Watermarks.Add(wm);
+            return WatermarkCollectionUtil.AddWatermark(this.Watermarks, watermark);
         }
 
         void IWatermarkCollection.RemoveWatermark(OSGeo.MapGuide.ObjectModels.WatermarkDefinition.IWatermark watermark)
         {
-#if MDF_240
-            var wm = watermark as OSGeo.MapGuide.ObjectModels.WatermarkDefinition_2_4_0.WatermarkType;
-#else
-            var wm = watermark as OSGeo.MapGuide.ObjectModels.WatermarkDefinition_2_3_0.WatermarkType;
-#endif
-            if (wm != null)
-                this.Watermarks.Remove(wm);
+            WatermarkCollectionUtil.RemoveWatermark(this.Watermarks, watermark);
         }
 
         int IWatermarkCollection.WatermarkCount

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/VectorLayerDefinitionImpl.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/VectorLayerDefinitionImpl.cs	2012-06-22 17:50:14 UTC (rev 6803)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/VectorLayerDefinitionImpl.cs	2012-06-25 13:26:33 UTC (rev 6804)
@@ -68,26 +68,14 @@
             }
         }
 
-        void IWatermarkCollection.AddWatermark(OSGeo.MapGuide.ObjectModels.WatermarkDefinition.IWatermark watermark)
+        IWatermark IWatermarkCollection.AddWatermark(OSGeo.MapGuide.ObjectModels.WatermarkDefinition.IWatermarkDefinition watermark)
         {
-#if LDF_240
-            var wm = watermark as OSGeo.MapGuide.ObjectModels.WatermarkDefinition_2_4_0.WatermarkType;
-#else
-            var wm = watermark as OSGeo.MapGuide.ObjectModels.WatermarkDefinition_2_3_0.WatermarkType;
-#endif
-            if (wm != null)
-                this.Watermarks.Add(wm);
+            return WatermarkCollectionUtil.AddWatermark(this.Watermarks, watermark);
         }
 
         void IWatermarkCollection.RemoveWatermark(OSGeo.MapGuide.ObjectModels.WatermarkDefinition.IWatermark watermark)
         {
-#if LDF_240
-            var wm = watermark as OSGeo.MapGuide.ObjectModels.WatermarkDefinition_2_4_0.WatermarkType;
-#else
-            var wm = watermark as OSGeo.MapGuide.ObjectModels.WatermarkDefinition_2_3_0.WatermarkType;
-#endif
-            if (wm != null)
-                this.Watermarks.Remove(wm);
+            WatermarkCollectionUtil.RemoveWatermark(this.Watermarks, watermark);
         }
 
         [XmlIgnore]

Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/WatermarkCollectionUtil.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/WatermarkCollectionUtil.cs	                        (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/WatermarkCollectionUtil.cs	2012-06-25 13:26:33 UTC (rev 6804)
@@ -0,0 +1,52 @@
+#region Disclaimer / License
+// Copyright (C) 2012, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using OSGeo.MapGuide.MaestroAPI;
+using System.IO;
+using System.Xml.Serialization;
+using OSGeo.MapGuide.MaestroAPI.Resource;
+
+namespace OSGeo.MapGuide.ObjectModels.WatermarkDefinition
+{
+    internal class WatermarkCollectionUtil
+    {
+        public static IWatermark AddWatermark<T>(IList<T> collection, IWatermarkDefinition watermark) where T : class, IWatermark, new()
+        {
+            Check.NotNull(watermark, "watermark");
+            T impl = new T();
+            impl.ResourceId = watermark.ResourceID;
+            impl.Name = ResourceIdentifier.GetName(impl.ResourceId);
+            impl.Usage = UsageType.All;
+            collection.Add(impl);
+            return impl;
+        }
+
+        public static void RemoveWatermark<T>(IList<T> collection, IWatermark watermark) where T : class, IWatermark
+        {
+            Check.NotNull(watermark, "watermark");
+            T impl = watermark as T;
+            if (impl != null)
+                collection.Remove(impl);
+        }
+    }
+}

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/WatermarkInterfaces.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/WatermarkInterfaces.cs	2012-06-22 17:50:14 UTC (rev 6803)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/WatermarkInterfaces.cs	2012-06-25 13:26:33 UTC (rev 6804)
@@ -23,6 +23,7 @@
 using OSGeo.MapGuide.MaestroAPI.Resource;
 using System.ComponentModel;
 using OSGeo.MapGuide.ObjectModels.SymbolDefinition;
+using OSGeo.MapGuide.ObjectModels.Common;
 
 namespace OSGeo.MapGuide.ObjectModels.WatermarkDefinition
 {
@@ -121,12 +122,6 @@
         IPosition Position { get; set; }
 
         /// <summary>
-        /// Creates an new watermark instance from this definition
-        /// </summary>
-        /// <returns></returns>
-        IWatermark CreateInstance();
-
-        /// <summary>
         /// Creates the XY position.
         /// </summary>
         /// <returns></returns>
@@ -288,8 +283,9 @@
         /// <summary>
         /// Adds a watermark
         /// </summary>
-        /// <param name="watermark"></param>
-        void AddWatermark(IWatermark watermark);
+        /// <param name="watermarkDef">The watermark definition to add</param>
+        /// <returns>The added watermark instance.</returns>
+        IWatermark AddWatermark(IWatermarkDefinition watermarkDef);
 
         /// <summary>
         /// Removes the specified watermark



More information about the mapguide-commits mailing list