Skip to content

Commit f963e59

Browse files
committed
display error messages in UI, fix #16 clear old node data, browse parent folder if current target folder is not available, automatically set output file extension based on output format dropdown selection, #BUILD
1 parent 965b59d commit f963e59

File tree

5 files changed

+57
-14
lines changed

5 files changed

+57
-14
lines changed

MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<Button x:Name="btnBrowseOutput" Content="..." HorizontalAlignment="Left" Margin="636,114,0,0" VerticalAlignment="Top" Width="32" Height="23" Click="btnBrowseOutput_Click" ToolTip="Browse for output file"/>
1515
<TextBox x:Name="txtOutput" HorizontalAlignment="Left" Height="23" Margin="20,114,0,0" VerticalAlignment="Top" Width="611"/>
1616
<Label x:Name="label_Copy" Content="Output:" HorizontalAlignment="Left" Margin="20,88,0,0" VerticalAlignment="Top" Foreground="{DynamicResource MainText}"/>
17-
<ComboBox x:Name="cmbExportFormat" HorizontalAlignment="Left" Margin="719,114,0,0" VerticalAlignment="Top" Width="163" IsReadOnly="True"/>
17+
<ComboBox x:Name="cmbExportFormat" HorizontalAlignment="Left" Margin="719,114,0,0" VerticalAlignment="Top" Width="163" IsReadOnly="True" SelectionChanged="cmbExportFormat_SelectionChanged"/>
1818
<Label x:Name="label_Copy1" Content="Export format:&#xD;&#xA;" HorizontalAlignment="Left" Margin="719,88,0,0" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" Height="26"/>
1919
<ComboBox x:Name="cmbImportFormat" HorizontalAlignment="Left" Margin="719,48,0,0" VerticalAlignment="Top" Width="163" IsReadOnly="True"/>
2020
<Label x:Name="label_Copy2" Content="Import format:&#xA;" HorizontalAlignment="Left" Margin="719,22,0,0" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" Height="26"/>

MainWindow.xaml.cs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
using System.Runtime.InteropServices;
1010
using System.Threading;
1111
using System.Windows;
12+
using System.Windows.Controls;
1213

1314
namespace PointCloudConverter
1415
{
1516
public partial class MainWindow : Window
1617
{
17-
static string appname = "PointCloud Converter v1.74";
18+
static string appname = "PointCloud Converter v1.75";
1819
static readonly string rootFolder = AppDomain.CurrentDomain.BaseDirectory;
1920

2021
// allow console output from WPF application https://stackoverflow.com/a/7559336/5452781
@@ -281,10 +282,9 @@ void StartProcess(bool doProcess = true)
281282

282283
// check input files
283284
var importSettings = ArgParser.Parse(args.ToArray(), rootFolder);
284-
// TODO get error messages into log textbox (return in settings?)
285285

286286
// if have files, process them
287-
if (importSettings != null)
287+
if (importSettings.errors.Count == 0)
288288
{
289289
// show output settings for commandline
290290
var cl = string.Join(" ", args);
@@ -303,7 +303,7 @@ void StartProcess(bool doProcess = true)
303303
else
304304
{
305305
HideProcessingPanel();
306-
txtConsole.Text = "Operation failed! Errors in arguments.";
306+
txtConsole.Text = "Operation failed! " + string.Join(Environment.NewLine, importSettings.errors);
307307
}
308308
}
309309

@@ -342,7 +342,40 @@ private void btnBrowseOutput_Click(object sender, RoutedEventArgs e)
342342
var dialog = new SaveFileDialog();
343343
dialog.Title = "Set output folder and filename";
344344
dialog.Filter = "UCPC (V2)|*.ucpc|PCROOT (V3)|*.pcroot";
345-
dialog.InitialDirectory = Properties.Settings.Default.lastExportFolder;
345+
346+
// take folder from field
347+
if (string.IsNullOrEmpty(txtOutput.Text) == false)
348+
{
349+
// check if folder exists, if not take parent folder
350+
if (Directory.Exists(Path.GetDirectoryName(txtOutput.Text)) == true)
351+
{
352+
dialog.InitialDirectory = txtOutput.Text;
353+
}
354+
else
355+
{
356+
var folder = Path.GetDirectoryName(txtOutput.Text);
357+
// fix slashes
358+
folder = folder.Replace("\\", "/");
359+
for (int i = folder.Length - 1; i > -1; i--)
360+
{
361+
if (folder[i] == '/')
362+
{
363+
if (Directory.Exists(folder.Substring(0, i)))
364+
{
365+
dialog.InitialDirectory = folder.Substring(0, i).Replace("/", "\\");
366+
break;
367+
}
368+
}
369+
}
370+
}
371+
}
372+
else // no path
373+
{
374+
dialog.InitialDirectory = Properties.Settings.Default.lastExportFolder;
375+
}
376+
377+
Console.WriteLine(dialog.InitialDirectory);
378+
346379
if (dialog.ShowDialog() == true)
347380
{
348381
txtOutput.Text = dialog.FileName;
@@ -438,5 +471,11 @@ private void BtnCancel_Click(object sender, RoutedEventArgs e)
438471
Environment.Exit(Environment.ExitCode);
439472
}
440473
}
474+
475+
private void cmbExportFormat_SelectionChanged(object sender, SelectionChangedEventArgs e)
476+
{
477+
// updatae file extension, if set
478+
txtOutput.Text = Path.ChangeExtension(txtOutput.Text, "." + cmbExportFormat.SelectedValue.ToString().ToLower());
479+
}
441480
} // class
442481
} // namespace

Structs/ImportSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ImportSettings
1313
public IWriter writer = new UCPC();
1414

1515
public bool haveError = false; // if errors during parsing args
16-
public string[] errorMessages = null; // last error message(s)
16+
//public string[] errorMessages = null; // last error message(s)
1717

1818
public bool useScale = false;
1919
public float scale = 1f;
@@ -24,6 +24,8 @@ public class ImportSettings
2424
public List<string> inputFiles = new List<string>();
2525
public string outputFile = null;
2626

27+
public List<string> errors = new List<string>(); // return errors to UI
28+
2729
// FIXME default values will be used unless otherwise specified.. randomize = true
2830
// TODO these should be export settings..
2931

Tools/ArgParser.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,11 @@ public static ImportSettings Parse(string[] args, string rootFolder)
620620
Console.WriteLine(i + "> " + errors[i]);
621621
}
622622
Console.ForegroundColor = ConsoleColor.White;
623-
624-
return null;
625-
}
626-
else
627-
{
628-
return importSettings;
623+
importSettings.errors = errors;
629624
}
625+
626+
// return always, but note that we might have errors
627+
return importSettings;
630628
}
631629
}
632630
}

Writers/PCROOT.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ bool IWriter.InitWriter(ImportSettings _importSettings, int _pointCount)
3838
var res = true;
3939

4040
// clear old nodes
41+
nodeBounds.Clear();
4142
nodeX.Clear();
4243
nodeY.Clear();
4344
nodeZ.Clear();
4445
nodeR.Clear();
4546
nodeG.Clear();
4647
nodeB.Clear();
4748

49+
bsPoints = null;
50+
writerPoints = null;
51+
4852
cloudMinX = float.PositiveInfinity;
4953
cloudMinY = float.PositiveInfinity;
5054
cloudMinZ = float.PositiveInfinity;
@@ -317,7 +321,7 @@ void IWriter.Save(int fileIndex)
317321
var tilerootdata = new List<string>();
318322
var outputFileRoot = Path.Combine(baseFolder, fileOnly) + ".pcroot";
319323

320-
// add to tileroot list
324+
// add to tileroot listS
321325
long totalPointCount = 0;
322326
for (int i = 0, len = nodeBounds.Count; i < len; i++)
323327
{

0 commit comments

Comments
 (0)