[mapguide-commits] r5768 - in trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI: Commands ObjectModels Properties

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue May 10 08:09:27 EDT 2011


Author: jng
Date: 2011-05-10 05:09:27 -0700 (Tue, 10 May 2011)
New Revision: 5768

Modified:
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Commands/ExecuteLoadProcedure.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/DrawingSourceInterfaces.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Properties/Resources.Designer.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Properties/Resources.resx
Log:
#1503: Fix DWF load procedure not setting sheet extents. The extent information is stored in a somewhat cryptic PIA file that is usually part of each section in a DWF file. A new extension method UpdateExtents() is available to set the extents of all sheets in a IDrawingSource based on their respective PIA information


Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Commands/ExecuteLoadProcedure.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Commands/ExecuteLoadProcedure.cs	2011-05-10 11:13:12 UTC (rev 5767)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Commands/ExecuteLoadProcedure.cs	2011-05-10 12:09:27 UTC (rev 5768)
@@ -30,6 +30,7 @@
 using OSGeo.MapGuide.ObjectModels;
 using OSGeo.MapGuide.MaestroAPI.Schema;
 using System.Collections.Specialized;
+using OSGeo.MapGuide.ObjectModels.DrawingSource;
 
 namespace OSGeo.MapGuide.MaestroAPI.Commands
 {
@@ -573,7 +574,7 @@
                                 // 2. Upload dwf file as resource data for this document.
 
                                 //Step 1: Create and save drawing source document.
-                                var ds = ObjectFactory.CreateDrawingSource(this.Parent);
+                                IDrawingSource ds = ObjectFactory.CreateDrawingSource(this.Parent);
                                 ds.SourceName = dataName;
                                 ds.CoordinateSpace = proc.CoordinateSystem;
                                 ds.ResourceID = dsId;
@@ -596,7 +597,12 @@
                                         var sht = ds.CreateSheet(sect.Name, 0, 0, 0, 0);
                                         ds.AddSheet(sht);
                                     }
+
                                     this.Parent.ResourceService.SaveResource(ds);
+
+                                    ds.UpdateExtents();
+                                    
+                                    this.Parent.ResourceService.SaveResource(ds);
                                 }
                             }
                             else

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/DrawingSourceInterfaces.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/DrawingSourceInterfaces.cs	2011-05-10 11:13:12 UTC (rev 5767)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/DrawingSourceInterfaces.cs	2011-05-10 12:09:27 UTC (rev 5768)
@@ -22,6 +22,9 @@
 using System.Text;
 using OSGeo.MapGuide.MaestroAPI.Resource;
 using OSGeo.MapGuide.ObjectModels.Common;
+using OSGeo.MapGuide.MaestroAPI;
+using OSGeo.MapGuide.MaestroAPI.Services;
+using System.IO;
 
 namespace OSGeo.MapGuide.ObjectModels.DrawingSource
 {
@@ -94,4 +97,71 @@
         /// <value>The extent.</value>
         IEnvelope Extent { get; set; }
     }
+
+    public static class DrawingSourceExtensions
+    {
+        /// <summary>
+        /// Updates the extents of all sheets based on their respective AutoCAD Viewport Data in the embedded PIA resource
+        /// </summary>
+        /// <param name="source"></param>
+        public static void UpdateExtents(this IDrawingSource source)
+        {
+            Check.NotNull(source, "source");
+            Check.NotEmpty(source.ResourceID, "source.ResourceID");
+
+            //Need drawing service
+            if (Array.IndexOf(source.CurrentConnection.Capabilities.SupportedServices, (int)ServiceType.Drawing) < 0)
+                throw new NotSupportedException(string.Format(OSGeo.MapGuide.MaestroAPI.Properties.Resources.ERR_SERVICE_NOT_SUPPORTED, ServiceType.Drawing.ToString()));
+
+            var drawSvc = (IDrawingService)source.CurrentConnection.GetService((int)ServiceType.Drawing);
+
+            foreach (var sht in source.Sheet)
+            {
+                var list = drawSvc.EnumerateDrawingSectionResources(source.ResourceID, sht.Name);
+                foreach (var res in list.SectionResource)
+                {
+                    if (res.Role == "AutoCAD Viewport Data")
+                    {
+                        using (var stream = drawSvc.GetSectionResource(source.ResourceID, res.Href))
+                        {
+                            //This is text content
+                            using (var sr = new StreamReader(stream))
+                            {
+                                try
+                                {
+                                    string content = sr.ReadToEnd();
+
+                                    //Viewport parameters are:
+                                    //
+                                    // llx
+                                    // lly
+                                    // urx
+                                    // ury
+                                    //
+                                    //A the first space after each number of each parameter marks the end of that value
+
+                                    int idx = content.IndexOf("llx") + 4; // 4 - length of "llx="
+                                    string sllx = content.Substring(idx, content.IndexOf(" ", idx) - idx);
+                                    idx = content.IndexOf("lly") + 4; // 4 - length of "lly="
+                                    string slly = content.Substring(idx, content.IndexOf(" ", idx) - idx);
+                                    idx = content.IndexOf("urx") + 4; // 4 - length of "urx="
+                                    string surx = content.Substring(idx, content.IndexOf(" ", idx) - idx);
+                                    idx = content.IndexOf("ury") + 4; // 4 - length of "ury="
+                                    string sury = content.Substring(idx, content.IndexOf(" ", idx) - idx);
+
+                                    //Update extents
+                                    sht.Extent = ObjectFactory.CreateEnvelope(
+                                        Convert.ToDouble(sllx),
+                                        Convert.ToDouble(slly),
+                                        Convert.ToDouble(surx),
+                                        Convert.ToDouble(sury));
+                                }
+                                catch { }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
 }

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Properties/Resources.Designer.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Properties/Resources.Designer.cs	2011-05-10 11:13:12 UTC (rev 5767)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Properties/Resources.Designer.cs	2011-05-10 12:09:27 UTC (rev 5768)
@@ -404,6 +404,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Service Type not supported: {0}.
+        /// </summary>
+        internal static string ERR_SERVICE_NOT_SUPPORTED {
+            get {
+                return ResourceManager.GetString("ERR_SERVICE_NOT_SUPPORTED", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Factory method already registered for version: .
         /// </summary>
         internal static string FactoryMethodAlreadyRegistered {

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Properties/Resources.resx
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Properties/Resources.resx	2011-05-10 11:13:12 UTC (rev 5767)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Properties/Resources.resx	2011-05-10 12:09:27 UTC (rev 5768)
@@ -494,4 +494,7 @@
   <data name="XmlValidationIssueTemplate" xml:space="preserve">
     <value>Line {0}, Char {1}: {2}</value>
   </data>
+  <data name="ERR_SERVICE_NOT_SUPPORTED" xml:space="preserve">
+    <value>Service Type not supported: {0}</value>
+  </data>
 </root>
\ No newline at end of file



More information about the mapguide-commits mailing list