[mapguide-commits] r7681 - in branches/maestro-4.0.x/MgCooker: . Properties

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Jul 9 07:43:59 PDT 2013


Author: jng
Date: 2013-07-09 07:43:59 -0700 (Tue, 09 Jul 2013)
New Revision: 7681

Modified:
   branches/maestro-4.0.x/MgCooker/BatchSettings.cs
   branches/maestro-4.0.x/MgCooker/Program.cs
   branches/maestro-4.0.x/MgCooker/Properties/Resources.Designer.cs
   branches/maestro-4.0.x/MgCooker/Properties/Resources.resx
   branches/maestro-4.0.x/MgCooker/SetupRun.cs
Log:
#2291, #2289: Port r7649 to 4.0.x

Modified: branches/maestro-4.0.x/MgCooker/BatchSettings.cs
===================================================================
--- branches/maestro-4.0.x/MgCooker/BatchSettings.cs	2013-07-09 13:51:12 UTC (rev 7680)
+++ branches/maestro-4.0.x/MgCooker/BatchSettings.cs	2013-07-09 14:43:59 UTC (rev 7681)
@@ -394,26 +394,6 @@
         /// </summary>
         public string[] Groups { get { return m_groups; } }
 
-        /// <summary>
-        /// The number of tiles to offset the row counter with
-        /// </summary>
-        private int m_rowTileOffset = 0;
-
-        /// <summary>
-        /// The number of tiles to offset the col counter with
-        /// </summary>
-        private int m_colTileOffset = 0;
-
-        /// <summary>
-        /// The tile offset for row indexes for tiles
-        /// </summary>
-        public int RowTileOffset { get { return m_rowTileOffset; } }
-
-        /// <summary>
-        /// The tile offset for col indexes for tiles
-        /// </summary>
-        public int ColTileOffset { get { return m_colTileOffset; } }
-
         //The map's scales may have been modified, this array is a map of the new values
         public int[] ScaleIndexMap { get { return m_scaleindexmap; } }
 
@@ -470,7 +450,7 @@
             m_dimensions = new long[this.Resolutions][];
             for (int i = this.Resolutions - 1; i >= 0; i--)
             {
-                long rows, cols;
+                long rows, cols, rowTileOffset = 0, colTileOffset = 0;
                 double scale = m_mapdefinition.BaseMap.GetScaleAt(i);
 
                 if (m_parent.Config.UseOfficialMethod)
@@ -490,9 +470,17 @@
                     {
                         //The extent is overridden, so we need to adjust the start offsets
                         double offsetX = MaxExtent.MinX - m_mapdefinition.Extents.MinX;
-                        double offsetY = MaxExtent.MinY - m_mapdefinition.Extents.MinY;
-                        m_rowTileOffset = (int)Math.Ceiling(offsetY / tileHeight);
-                        m_colTileOffset = (int)Math.Ceiling(offsetX / tileWidth);
+                        double offsetY = m_mapdefinition.Extents.MaxY - MaxExtent.MaxY;
+                        rowTileOffset = (int)Math.Floor(offsetY / tileHeight);
+                        colTileOffset = (int)Math.Floor(offsetX / tileWidth);
+
+                        double offsetMaxX = MaxExtent.MaxX - m_mapdefinition.Extents.MinX;
+                        double offsetMinY = m_mapdefinition.Extents.MaxY - MaxExtent.MinY;
+                        int rowMinTileOffset = (int)Math.Floor(offsetMinY / tileHeight);
+                        int colMaxTileOffset = (int)Math.Floor(offsetMaxX / tileWidth);
+
+                        cols += (colMaxTileOffset - colTileOffset);
+                        rows += (rowMinTileOffset - rowTileOffset);
                     }
                 }
                 else
@@ -516,7 +504,7 @@
                 }
 
 
-                m_dimensions[i] = new long[] {rows, cols};
+                m_dimensions[i] = new long[] { rows, cols, rowTileOffset, colTileOffset };
             }
         }
 
@@ -530,6 +518,12 @@
             m_groups = g.ToArray();
         }
 
+        internal void SetScalesAndExtend(int[] scales, IEnvelope envelope)
+        {
+            this.m_maxExtent = envelope;
+            SetScales(scales);
+        }
+
         public void SetScales(int[] scaleindexes)
         {
             //TODO: Re-read scales from mapdef?
@@ -606,11 +600,13 @@
             {
                 int rows = (int)m_dimensions[scaleindex][0];
                 int cols = (int)m_dimensions[scaleindex][1];
+                int rowTileOffset = (int)m_dimensions[scaleindex][2];
+                int colTileOffset = (int)m_dimensions[scaleindex][3];
 
                 //If the MaxExtents are different from the actual bounds, we need a start offset offset
 
-                RenderThreads settings = new RenderThreads(this, m_parent, m_scaleindexmap[scaleindex], group, m_mapdefinition.ResourceID, rows, cols, m_rowTileOffset, m_colTileOffset, m_parent.Config.RandomizeTileSequence);
-                
+                RenderThreads settings = new RenderThreads(this, m_parent, m_scaleindexmap[scaleindex], group, m_mapdefinition.ResourceID, rows, cols, rowTileOffset, colTileOffset, m_parent.Config.RandomizeTileSequence);
+
                 settings.RunAndWait();
 
                 if (settings.TileSet.Count != 0 && !m_parent.Cancel)

Modified: branches/maestro-4.0.x/MgCooker/Program.cs
===================================================================
--- branches/maestro-4.0.x/MgCooker/Program.cs	2013-07-09 13:51:12 UTC (rev 7680)
+++ branches/maestro-4.0.x/MgCooker/Program.cs	2013-07-09 14:43:59 UTC (rev 7681)
@@ -68,6 +68,8 @@
             //basegroups="x","y"
             //extentoverride=minx,miny,maxx,maxy
 
+            Boolean batchMode = false;
+            
             string mapagent = "http://localhost/mapguide";
             string username = "Anonymous";
             string password = "";
@@ -137,13 +139,20 @@
             }
 
 
+            if (largs.IndexOf("batch") >= 0 || largs.IndexOf("/batch") >= 0 || largs.IndexOf("commandline") >= 0 || largs.IndexOf("/commandline") >= 0)
+            {
+                batchMode = true;
+            }
+
             try
             {
                 Console.Clear();
+                m_logableProgress = true;
             }
             catch
             {
                 hasConsole = false;
+                m_logableProgress = false;
             }
 
 
@@ -154,7 +163,7 @@
             SetupRun sr = null;
             if (!opts.ContainsKey("username") || (!opts.ContainsKey("mapagent")))
             {
-                if (largs.IndexOf("/commandline") < 0 && largs.IndexOf("commandline") < 0)
+                if (!batchMode)
                 {
                     var frm = new LoginDialog();
                     if (frm.ShowDialog() != System.Windows.Forms.DialogResult.OK)
@@ -197,9 +206,9 @@
                 }
             }
 
-            
 
-            if (largs.IndexOf("batch") < 0 && largs.IndexOf("/batch") < 0)
+
+            if (!batchMode)
             {
                 if (sr == null)
                     sr = new SetupRun(connection, maps, opts);
@@ -257,21 +266,29 @@
                 bx.SetGroups(groups.ToArray());
             }
 
-            if (!string.IsNullOrEmpty(scaleindex))
+            if (overrideExtents != null)
             {
                 List<int> scales = new List<int>();
                 int tmp;
                 foreach (string s in scaleindex.Split(','))
                     if (int.TryParse(s, out tmp))
                         scales.Add(tmp);
+                foreach (BatchMap bm in bx.Maps)
+                    bm.SetScalesAndExtend(scales.ToArray(), overrideExtents);
+            } 
+            else if (!string.IsNullOrEmpty(scaleindex))
+            {
+                List<int> scales = new List<int>();
+                int tmp;
+                foreach (string s in scaleindex.Split(','))
+                    if (int.TryParse(s, out tmp))
+                        scales.Add(tmp);
                 bx.SetScales(scales.ToArray());
             }
 
-            if (overrideExtents != null)
-                foreach (BatchMap bm in bx.Maps)
-                    bm.MaxExtent = overrideExtents;
+            
 
-            if (largs.IndexOf("/commandline") < 0 && largs.IndexOf("commandline") < 0)
+            if (!batchMode)
             {
                 Progress pg = new Progress(bx);
                 pg.ShowDialog();

Modified: branches/maestro-4.0.x/MgCooker/Properties/Resources.Designer.cs
===================================================================
--- branches/maestro-4.0.x/MgCooker/Properties/Resources.Designer.cs	2013-07-09 13:51:12 UTC (rev 7680)
+++ branches/maestro-4.0.x/MgCooker/Properties/Resources.Designer.cs	2013-07-09 14:43:59 UTC (rev 7681)
@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:2.0.50727.4961
+//     Runtime Version:2.0.50727.5466
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
@@ -143,7 +143,7 @@
         }
         
         /// <summary>
-        ///   Looks up a localized string similar to {0}: Rendering group {1} ({3} of {4}).
+        ///   Looks up a localized string similar to {0}: Rendering group {1} ({2} of {3}).
         /// </summary>
         internal static string ConsoleOperationBeginGroup {
             get {

Modified: branches/maestro-4.0.x/MgCooker/Properties/Resources.resx
===================================================================
--- branches/maestro-4.0.x/MgCooker/Properties/Resources.resx	2013-07-09 13:51:12 UTC (rev 7680)
+++ branches/maestro-4.0.x/MgCooker/Properties/Resources.resx	2013-07-09 14:43:59 UTC (rev 7681)
@@ -155,7 +155,7 @@
     <comment>Text displayed in the console to report progress</comment>
   </data>
   <data name="ConsoleOperationBeginGroup" xml:space="preserve">
-    <value>{0}: Rendering group {1} ({3} of {4})</value>
+    <value>{0}: Rendering group {1} ({2} of {3})</value>
     <comment>Text displayed in the console to report progress</comment>
   </data>
   <data name="ConsoleOperationBeginMap" xml:space="preserve">

Modified: branches/maestro-4.0.x/MgCooker/SetupRun.cs
===================================================================
--- branches/maestro-4.0.x/MgCooker/SetupRun.cs	2013-07-09 13:51:12 UTC (rev 7680)
+++ branches/maestro-4.0.x/MgCooker/SetupRun.cs	2013-07-09 14:43:59 UTC (rev 7681)
@@ -29,6 +29,7 @@
 using OSGeo.MapGuide.ObjectModels.MapDefinition;
 using OSGeo.MapGuide.MaestroAPI.Exceptions;
 using System.Collections.Specialized;
+using OSGeo.MapGuide.ObjectModels;
 
 namespace MgCooker
 {
@@ -60,6 +61,7 @@
             grpDifferentConnection.Enabled = chkUseDifferentConnection.Enabled = !m_connection.ProviderName.ToUpper().Equals("MAESTRO.LOCAL");
             m_commandlineargs = args;
             m_coordinateOverrides = new Dictionary<string, IEnvelope>();
+            IEnvelope overrideExtents = null;
 
             //HttpServerConnection hc = connection as HttpServerConnection;
             try
@@ -70,13 +72,8 @@
             }
             catch { }
 
-            if (m_commandlineargs.ContainsKey("mapdefinitions"))
-                m_commandlineargs.Remove("mapdefinitions");
-            if (m_commandlineargs.ContainsKey("scaleindex"))
-                m_commandlineargs.Remove("scaleindex");
-            if (m_commandlineargs.ContainsKey("basegroups"))
-                m_commandlineargs.Remove("basegroups");
-
+            if (m_commandlineargs.ContainsKey("mapdefinitions")) //NOXLATE
+                m_commandlineargs.Remove("mapdefinitions"); //NOXLATE
             if (m_commandlineargs.ContainsKey("mapagent"))
                 MapAgent.Text = m_commandlineargs["mapagent"];
             if (m_commandlineargs.ContainsKey("username"))
@@ -107,8 +104,30 @@
                 }
             }
 
-            if (m_commandlineargs.ContainsKey("metersperunit"))
+            if (m_commandlineargs.ContainsKey("extentoverride")) //NOXLATE
             {
+                 string[] parts = m_commandlineargs["extentoverride"].Split(',');
+                if (parts.Length == 4)
+                {
+                    double minx;
+                    double miny;
+                    double maxx;
+                    double maxy;
+                    if (
+                        double.TryParse(parts[0], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out minx) &&
+                        double.TryParse(parts[1], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out miny) &&
+                        double.TryParse(parts[2], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out maxx) &&
+                        double.TryParse(parts[3], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out maxy)
+                        )
+                    {
+                        overrideExtents = ObjectFactory.CreateEnvelope(minx, miny, maxx, maxy);
+                    }
+                }
+
+            }
+
+            if (m_commandlineargs.ContainsKey("metersperunit")) //NOXLATE
+            {
                 double d;
                 if (
                     double.TryParse(m_commandlineargs["metersperunit"], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.CurrentUICulture, out d)
@@ -129,6 +148,24 @@
                 maps = tmp.ToArray();
             }
 
+            
+            var basegroupsSelected = new List<string>();
+            if (m_commandlineargs.ContainsKey("basegroups"))//NOXLATE
+            {
+                basegroupsSelected = new List<string>(m_commandlineargs["basegroups"].Split(','));//NOXLATE
+                m_commandlineargs.Remove("basegroups"); //NOXLATE
+            }
+
+            var scalesSelected = new List<int>();
+            if (m_commandlineargs.ContainsKey("scaleindex")) //NOXLATE
+            {
+                foreach (string scaleIndex in m_commandlineargs["scaleindex"].Split(','))//NOXLATE
+                {
+                    scalesSelected.Add(int.Parse(scaleIndex));
+                }
+                m_commandlineargs.Remove("scaleindex"); //NOXLATE
+            }
+
             MapTree.Nodes.Clear();
             foreach (string m in maps)
             {
@@ -142,27 +179,43 @@
                     baseMap.HasGroups())
                 {
                     TreeNode mn = MapTree.Nodes.Add(m);
-                    //mn.Checked = true;
+                    
                     mn.ImageIndex = mn.SelectedImageIndex = 0;
                     mn.Tag = mdef;
                     foreach (var g in baseMap.BaseMapLayerGroup)
                     {
                         TreeNode gn = mn.Nodes.Add(g.Name);
                         gn.Tag = g;
-                        //gn.Checked = true;
+                        if (basegroupsSelected.Contains(g.Name))
+                        {
+                            mn.Checked = true;
+                            gn.Checked = true;
+                            if (overrideExtents != null && !m_coordinateOverrides.ContainsKey(m))
+                            {
+                                m_coordinateOverrides.Add(m, overrideExtents);
+                            }
+                        }
+                        
                         gn.ImageIndex = gn.SelectedImageIndex = 1;
 
+                        int counter = 0;
                         foreach (double d in baseMap.FiniteDisplayScale)
                         {
                             TreeNode sn = gn.Nodes.Add(d.ToString(System.Globalization.CultureInfo.CurrentUICulture));
-                            //sn.Checked = true;
+                            if (gn.Checked && scalesSelected.Contains(counter))
+                            {
+                                sn.Checked = true;
+                                
+                            }
                             sn.ImageIndex = sn.SelectedImageIndex = 3;
+                            counter++;
                         }
                     }
 
                     mn.Expand();
                 }
             }
+            MapTree_AfterSelect(null, null);
         }
 
         private void panel1_Paint(object sender, PaintEventArgs e)
@@ -252,9 +305,8 @@
                 {
                     BatchMap bm = new BatchMap(bx, c.MapDefinition);
                     bm.SetGroups(new string[] { c.Group });
-                    bm.SetScales(c.ScaleIndexes);
-                    if (c.ExtentOverride != null)
-                        bm.MaxExtent = c.ExtentOverride;
+                    bm.SetScalesAndExtend(c.ScaleIndexes,c.ExtentOverride);
+                   
                     bx.Maps.Add(bm);
                 }
 
@@ -319,34 +371,36 @@
 
             if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
             {
-                StringBuilder args = new StringBuilder();
-                args.Append("--mapagent=\"" + MapAgent.Text + "\" ");
-                args.Append("--username=\"" + Username.Text + "\" ");
-                args.Append("--password=\"" + Password.Text + "\" ");
+                //Common args for all map defintions to be tiled
+                List<string> args = new List<string>();
+                args.Add("--mapagent=\"" + MapAgent.Text + "\""); //NOXLATE
+                args.Add("--username=\"" + Username.Text + "\""); //NOXLATE
+                args.Add("--password=\"" + Password.Text + "\""); //NOXLATE
 
                 if (LimitTileset.Checked)
                 {
                     if (MaxRowLimit.Value > 0)
-                        args.Append("--limitrows=\"" + ((int)MaxRowLimit.Value).ToString() + "\" ");
+                        args.Add("--limitrows=\"" + ((int)MaxRowLimit.Value).ToString() + "\""); //NOXLATE
                     if (MaxColLimit.Value > 0)
-                        args.Append("--limitcols=\"" + ((int)MaxColLimit.Value).ToString() + "\" ");
+                        args.Add("--limitcols=\"" + ((int)MaxColLimit.Value).ToString() + "\""); //NOXLATE
                 }
 
                 if (UseNativeAPI.Checked)
-                    args.Append("--native-connection ");
+                    args.Add("--native-connection"); //NOXLATE
                 if (UseOfficialMethod.Checked)
-                    args.Append("--metersperunit=" + ((double)MetersPerUnit.Value).ToString(System.Globalization.CultureInfo.InvariantCulture) + " ");
+                    args.Add("--metersperunit=" + ((double)MetersPerUnit.Value).ToString(System.Globalization.CultureInfo.InvariantCulture)); //NOXLATE
 
-                args.Append("--threadcount=" + ((int)ThreadCount.Value).ToString() + " ");
+                args.Add("--threadcount=" + ((int)ThreadCount.Value).ToString()); //NOXLATE
                 if (RandomTileOrder.Checked)
-                    args.Append("--random-tile-order ");
+                    args.Add("--random-tile-order"); //NOXLATE
 
 
                 string executable = System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);
+                string cmdExecutable = "MgCookerCmd.exe"; //NOXLATE
 
                 //Windows has problems with console output from GUI applications...
-                if (System.Environment.OSVersion.Platform != PlatformID.Unix && executable == "MgCooker.exe" && System.IO.File.Exists(System.IO.Path.Combine(Application.StartupPath, "MgCookerCommandline.exe")))
-                    executable = System.IO.Path.Combine(Application.StartupPath, "MgCookerCommandline.exe");
+                if (System.Environment.OSVersion.Platform != PlatformID.Unix && executable == "MgCooker.exe" && System.IO.File.Exists(System.IO.Path.Combine(Application.StartupPath, cmdExecutable))) //NOXLATE
+                    executable = System.IO.Path.Combine(Application.StartupPath, cmdExecutable); //NOXLATE
                 else
                     executable = System.IO.Path.Combine(Application.StartupPath, executable);
 
@@ -378,41 +432,59 @@
 
                     foreach (Config c in ReadTree())
                     {
+                        //Map-specific args
+                        List<string> argsMap = new List<string>();
                         if (System.Environment.OSVersion.Platform != PlatformID.MacOSX ||
                             System.Environment.OSVersion.Platform != PlatformID.Unix)
                         {
-                            sw.Write(exeName);
+                            argsMap.Add(exeName);
                         }
                         else
                         {
-                            sw.Write(executable);
+                            argsMap.Add(executable);
                         }
-                        sw.Write(" batch");
-                        sw.Write(" --mapdefinitions=\"");
-                        sw.Write(c.MapDefinition);
-                        sw.Write("\" --basegroups=\"");
-                        sw.Write(c.Group);
-                        sw.Write("\" --scaleindex=");
+
+                        argsMap.Add("batch"); //NOXLATE
+                        argsMap.Add("--mapdefinitions=\"" + c.MapDefinition + "\"");
+                        argsMap.Add("--basegroups=\"" + c.Group + "\"");
+                        StringBuilder si = new StringBuilder("--scaleindex="); //NOXLATE
                         for (int i = 0; i < c.ScaleIndexes.Length; i++)
                         {
                             if (i != 0)
-                                sw.Write(",");
-                            sw.Write(c.ScaleIndexes[i].ToString());
+                                si.Append(","); //NOXLATE
+                            si.Append(c.ScaleIndexes[i].ToString());
                         }
-                        sw.Write(" "); // dont forget the space after the list of scaleindexes ticket #1316
+                        argsMap.Add(si.ToString());
+
                         if (c.ExtentOverride != null)
                         {
-                            sw.Write(" --extentoverride=");
-                            sw.Write(c.ExtentOverride.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture));
-                            sw.Write(",");
-                            sw.Write(c.ExtentOverride.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture));
-                            sw.Write(",");
-                            sw.Write(c.ExtentOverride.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture));
-                            sw.Write(",");
-                            sw.Write(c.ExtentOverride.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture));
+                            StringBuilder ov = new StringBuilder("--extentoverride="); //NOXLATE
+                            ov.Append(c.ExtentOverride.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture));
+                            ov.Append(","); //NOXLATE
+                            ov.Append(c.ExtentOverride.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture));
+                            ov.Append(","); //NOXLATE
+                            ov.Append(c.ExtentOverride.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture));
+                            ov.Append(","); //NOXLATE
+                            ov.Append(c.ExtentOverride.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture));
+                            argsMap.Add(ov.ToString());
                         }
 
-                        sw.Write(args.ToString());
+                        string[] argsFinal = new string[args.Count + argsMap.Count];
+                        int a = 0;
+                        //Map-specific args first (as this contains the executable name)
+                        foreach (string arg in argsMap)
+                        {
+                            argsFinal[a] = arg;
+                            a++;
+                        }
+                        //Then the common args
+                        foreach (string arg in args)
+                        {
+                            argsFinal[a] = arg;
+                            a++;
+                        }
+
+                        sw.Write(string.Join(" ", argsFinal));
                         sw.WriteLine();
                     }
 
@@ -486,7 +558,7 @@
             if (m_isUpdating)
                 return;
 
-            if (MapTree.SelectedNode == null || !UseOfficialMethod.Checked)
+            if (MapTree.SelectedNode == null)
             {
                 BoundsOverride.Enabled = false;
                 BoundsOverride.Tag = null;



More information about the mapguide-commits mailing list