Skip to content

Commit

Permalink
b133
Browse files Browse the repository at this point in the history
  • Loading branch information
dkxce authored Feb 8, 2022
1 parent ecc5b8a commit 11d5abf
Show file tree
Hide file tree
Showing 7 changed files with 298 additions and 94 deletions.
2 changes: 1 addition & 1 deletion KMZRebuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
</Compile>
<Compile Include="MapsForgeReader.cs" />
<Compile Include="MapViewerForm.cs">
<SubType>Component</SubType>
<SubType>Form</SubType>
</Compile>
<Compile Include="MapViewerForm.Designer.cs">
<DependentUpon>MapViewerForm.cs</DependentUpon>
Expand Down
244 changes: 166 additions & 78 deletions KMZRebuilederForm.Designer.cs

Large diffs are not rendered by default.

138 changes: 125 additions & 13 deletions KMZRebuilederForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public KMZRebuilederForm(string[] args)
MapIcons.InitZip(CurrentDirectory() + @"\mapicons\default.zip");
}

private void AfterLoadPrefs()
{
convertToToolStripMenuItem.Visible = Properties.GetBoolValue("gpiwriter_hide_old_menus_items");
}

public static void ConvertGPI2KMZ(string gpiFile, string kmzFile)
{
if (String.IsNullOrEmpty(gpiFile)) return;
Expand Down Expand Up @@ -764,6 +769,8 @@ private void Save2WPT(string filename, KMLayer kml)
if ((std != null) && (std.ChildNodes.Count > 0))
desc = std.ChildNodes[0].Value;

if (desc.Contains("wpt_skip=true")) continue;

bool toTop = false;
if (!String.IsNullOrEmpty(desc))
{
Expand Down Expand Up @@ -954,10 +961,15 @@ private void Save2ReportHTML(string filename, IDictionary<string, string[]> fiel

private string Save2KMZ(string filename, bool multilayers)
{
return Save2KMZ(filename, multilayers, true);
return Save2KMZ(filename, multilayers, true, null);
}

private string Save2KMZ(string filename, bool multilayers, bool createArchive)
{
return Save2KMZ(filename, multilayers, createArchive, null);
}

private string Save2KMZ(string filename, bool multilayers, bool createArchive, string desc_filter_skip)
{
log.Text = "";

Expand Down Expand Up @@ -991,20 +1003,37 @@ private string Save2KMZ(string filename, bool multilayers, bool createArchive)
int ttlpm = 0;
for (int i = 0; i < kmzLayers.CheckedItems.Count; i++)
{
bool skiplay = false;

KMLayer kml = (KMLayer)kmzLayers.CheckedItems[i];
CopySounds(kml.file, zdir);
XmlNode xn = kml.file.kmlDoc.SelectNodes("kml/Document/Folder")[kml.id];

ttlpm += kml.placemarks;

// remove names
if (!multilayers)
{
XmlNode nn = xn.SelectSingleNode("name");
if (nn != null) xn.RemoveChild(nn);
nn = xn.SelectSingleNode("description");
if (nn != null) xn.RemoveChild(nn);
};
if (nn != null)
{
if (!String.IsNullOrEmpty(desc_filter_skip))
{
try
{
string description = nn.ChildNodes[0].Value;
if (!String.IsNullOrEmpty(description))
if (description.Contains(desc_filter_skip))
skiplay = true;
}
catch { };
};
xn.RemoveChild(nn);
};
};

if (skiplay) continue;
ttlpm += kml.placemarks;

// styles
{
Expand Down Expand Up @@ -1899,6 +1928,14 @@ public int Compare(DictionaryEntry a, DictionaryEntry b)
}
}

private static string GetFolderDesc(XmlNode placemark)
{
string desc = "";
try { desc = placemark.ParentNode.SelectSingleNode("description").ChildNodes[0].Value; }
catch { return ""; };
return desc;
}

private static void Save2GPIInt(string gpifile, KMFile kmfile, string proj_name, GPIReader.Add2LogProc Add2Log, Preferences Props)
{
GPIReader.LOCALE_LANGUAGE = Props["gpi_localization"].ToUpper();
Expand Down Expand Up @@ -1953,6 +1990,9 @@ private static void Save2GPIInt(string gpifile, KMFile kmfile, string proj_name,
catch { };
string[] ll = n.ChildNodes[0].Value.Split(new string[] { "," }, StringSplitOptions.None);

if (GetFolderDesc(n.ParentNode.ParentNode).Contains("gpi_skip=true")) continue;
if (desc.Contains("gpi_skip=true")) continue;

string styleUrl = "";
if (n.ParentNode.ParentNode.SelectSingleNode("styleUrl") != null) styleUrl = n.ParentNode.ParentNode.SelectSingleNode("styleUrl").ChildNodes[0].Value;
if (styleUrl.IndexOf("#") == 0) styleUrl = styleUrl.Remove(0, 1);
Expand Down Expand Up @@ -3564,6 +3604,8 @@ private void Export2WPT(KMLayer kml)
if ((std != null) && (std.ChildNodes.Count > 0))
desc = std.ChildNodes[0].Value;

if (desc.Contains("wpt_skip=true")) continue;

bool toTop = false;
if (!String.IsNullOrEmpty(desc))
{
Expand Down Expand Up @@ -3760,7 +3802,10 @@ private void contextMenuStrip3_Opening(object sender, CancelEventArgs e)
export2DatToolStripMenuItem.Enabled = kmzLayers.CheckedIndices.Count > 0;
export2GDBToolStripMenuItem.Enabled = kmzLayers.CheckedIndices.Count > 0;
export2WPTnoIconsToolStripMenuItem.Enabled = kmzLayers.CheckedIndices.Count > 0;

convertToToolStripMenuItem.Visible = !Properties.GetBoolValue("gpiwriter_hide_old_menus_items");
convertToGarminPointsOfInterestsFileGPIToolStripMenuItem.Enabled = saveBTNG.Enabled;

c2DGPIToolStripMenuItem.Enabled = saveBTNG.Enabled;
}

Expand Down Expand Up @@ -5465,6 +5510,8 @@ private void Export2Dat(KMLayer kml)
if ((std != null) && (std.ChildNodes.Count > 0))
desc = std.ChildNodes[0].Value;

if (desc.Contains("progorod_skip=true")) continue;

ProGorodPOI.FavRecord rec = new ProGorodPOI.FavRecord();
rec.Name = name;
rec.Lat = double.Parse(llz[1].Replace("\r", "").Replace("\n", "").Replace(" ", ""), System.Globalization.CultureInfo.InvariantCulture);
Expand Down Expand Up @@ -6617,6 +6664,8 @@ private void Export2GDB(KMLayer kml)
if ((std != null) && (std.ChildNodes.Count > 0))
desc = std.ChildNodes[0].Value;

if (desc.Contains("navitel_skip=true")) continue;

bool toTop = false;
if (!String.IsNullOrEmpty(desc))
{
Expand Down Expand Up @@ -7664,7 +7713,7 @@ private void ReloadOriginalFiles()
private void exportToWPTToolStripMenuItem_Click(object sender, EventArgs e)
{
if (kmzLayers.CheckedIndices.Count == 0) return;
string zdir = Save2KMZ(null, false, false);
string zdir = Save2KMZ(null, false, false, "wpt_skip=true");
KMFile kf = KMFile.FromZDir(zdir);
Export2WPT(kf.kmLayers[0]);
ReloadOriginalFiles();
Expand All @@ -7673,7 +7722,7 @@ private void exportToWPTToolStripMenuItem_Click(object sender, EventArgs e)
private void export2DatToolStripMenuItem_Click(object sender, EventArgs e)
{
if (kmzLayers.CheckedIndices.Count == 0) return;
string zdir = Save2KMZ(null, false, false);
string zdir = Save2KMZ(null, false, false, "progorod_skip=true");
KMFile kf = KMFile.FromZDir(zdir);
Export2Dat(kf.kmLayers[0]);
ReloadOriginalFiles();
Expand All @@ -7682,7 +7731,7 @@ private void export2DatToolStripMenuItem_Click(object sender, EventArgs e)
private void export2GDBToolStripMenuItem_Click(object sender, EventArgs e)
{
if (kmzLayers.CheckedIndices.Count == 0) return;
string zdir = Save2KMZ(null, false, false);
string zdir = Save2KMZ(null, false, false, "navitel_skip=true");
KMFile kf = KMFile.FromZDir(zdir);
Export2GDB(kf.kmLayers[0]);
ReloadOriginalFiles();
Expand All @@ -7691,17 +7740,19 @@ private void export2GDBToolStripMenuItem_Click(object sender, EventArgs e)
private void export2WPTnoIconsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (kmzLayers.CheckedIndices.Count == 0) return;
string zdir = Save2KMZ(null, false, false);
string zdir = Save2KMZ(null, false, false, "wpt_skip=true");
KMFile kf = KMFile.FromZDir(zdir);
Save2WPTNoIcons(kf.kmLayers[0]);
ReloadOriginalFiles();
}

private void HelpDesc_Click(object sender, EventArgs e)
{
string help = "To Create GPI:\r\n";
help += " gpi_name_<IMAGECRC>=<FULLNAME>\r\n";
help += " gpi_subname_<IMAGECRC>=<SUBNAME>\r\n";
string help = "To Export GPI/WPT/DAT/GDB:\r\n";
help += " gpi_skip=true\r\n";
help += " wpt_skip=true\r\n";
help += " navitel_skip=true\r\n";
help += " progorod_skip=true\r\n";
help += "\r\nFor Route Planner\r\n";
help += " route_planner_skip=true\r\n";
help += " route_planner_skip=false\r\n";
Expand Down Expand Up @@ -8540,6 +8591,67 @@ private void bchelpb_Click(object sender, EventArgs e)
helptext += " MapPolygonCreator: /mpc\r\n\r\n";
MessageBox.Show(helptext, "Command Line Syntax", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void SetLayersCheckByDescIf(string condition, bool check)
{
if (kmzLayers.Items.Count == 0) return;
for (int i = 0; i < kmzLayers.Items.Count; i++)
{
KMLayer kml = (KMLayer)kmzLayers.Items[i];
XmlNode pmk = kml.file.kmlDoc.SelectNodes("kml/Document/Folder")[kml.id];
string description = "";
try
{
description = pmk.SelectSingleNode("description").ChildNodes[0].Value;
if (!String.IsNullOrEmpty(description))
if (description.Contains(condition))
kmzLayers.SetItemChecked(i, check);
}
catch { };
};
}

private void checkIfDescriptionContainsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (kmzLayers.Items.Count == 0) return;
string tc = "main=true";
if (InputBox("Check Layers", "If description contains text:", ref tc) != DialogResult.OK) return;
SetLayersCheckByDescIf(tc, true);
}

private void uncheckIfDescriptionContainsToolStripMenuItem_Click_1(object sender, EventArgs e)
{
if (kmzLayers.Items.Count == 0) return;
string tc = "main=true";
if (InputBox("Uncheck Layers", "If description contains text:", ref tc) != DialogResult.OK) return;
SetLayersCheckByDescIf(tc, false);
}

private void uncheckgpiskiptrueToolStripMenuItem_Click(object sender, EventArgs e)
{
if (kmzLayers.Items.Count == 0) return;
SetLayersCheckByDescIf("gpi_skip=true", false);
}

private void uncheckprogorodskiptrueToolStripMenuItem_Click(object sender, EventArgs e)
{
if (kmzLayers.Items.Count == 0) return;
SetLayersCheckByDescIf("progorod_skip=true", false);
}

private void unchecknavitelskiptrueToolStripMenuItem_Click(object sender, EventArgs e)
{
if (kmzLayers.Items.Count == 0) return;
SetLayersCheckByDescIf("navitel_skip=true", false);
}

private void uncheckwptskiptrueToolStripMenuItem_Click(object sender, EventArgs e)
{
if (kmzLayers.Items.Count == 0) return;
SetLayersCheckByDescIf("wpt_skip=true", false);
}


}

public class FilesListBox : CheckedListBox
Expand Down Expand Up @@ -10239,7 +10351,7 @@ public void GarminGDB2KML(string origin_name)
//List<string> types = new List<string>();
//for (int i = 0; i < 20; i++) types.Add(((ProGorodPOI.TType)i).ToString());

FileStream fs = new FileStream(this.tmp_file_dir + "doc ", FileMode.Create, FileAccess.Write);
FileStream fs = new FileStream(this.tmp_file_dir + "doc.kml", FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sw.WriteLine("<kml>");
Expand Down
3 changes: 3 additions & 0 deletions KMZRebuilederForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>674, 17</value>
</metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>674, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>52</value>
</metadata>
Expand Down
1 change: 1 addition & 0 deletions Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ private void LoadDefaults()
if (!this.Contains("gpiwriter_save_only_local_comm")) Properties.Add(new Property("gpiwriter_save_only_local_comm", "no", 1, "Save Comments only in local language"));
if (!this.Contains("gpiwriter_save_only_local_desc")) Properties.Add(new Property("gpiwriter_save_only_local_desc", "no", 1, "Save Descriptions only in local language"));
if (!this.Contains("gpiwriter_alert_datetime_maxcount")) Properties.Add(new Property("gpiwriter_alert_datetime_maxcount", "16", 2, "Max Alert DateTime Triggers Count (1..32)", 1, 32));
if (!this.Contains("gpiwriter_hide_old_menus_items")) Properties.Add(new Property("gpiwriter_hide_old_menus_items", "yes", 1, "Hide Old (Convert to) Menu items", 1, 32));
DefaultsIsLoaded = true;
}

Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("22.2.7.131")]
[assembly: AssemblyFileVersion("22.2.7.131")]
[assembly: AssemblyVersion("22.2.8.133")]
[assembly: AssemblyFileVersion("22.2.8.133")]
Binary file modified bin/Debug/KMZRebuilder.exe
Binary file not shown.

0 comments on commit 11d5abf

Please sign in to comment.