Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
martin2250 committed Jan 14, 2018
2 parents 5d131c6 + 92c63c5 commit 9ef8c88
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
4 changes: 4 additions & 0 deletions OpenCNCPilot/GCode/GCodeFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class GCodeFile
public bool ContainsMotion { get; private set; } = false;

public double TravelDistance { get; private set; } = 0;
public TimeSpan TotalTime { get; private set; } = TimeSpan.Zero;

private GCodeFile(List<Command> toolpath)
{
Expand All @@ -40,6 +41,9 @@ private GCodeFile(List<Command> toolpath)
{
TravelDistance += m.Length;

if(m is Line && !((Line)m).Rapid && ((Line)m).Feed > 0.0)
TotalTime += TimeSpan.FromMinutes(m.Length/m.Feed);

ContainsMotion = true;

for (int i = 0; i < 3; i++)
Expand Down
19 changes: 13 additions & 6 deletions OpenCNCPilot/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<StackPanel Orientation="Vertical" HorizontalAlignment="Left">
<Border Style="{StaticResource stylePanelOut}">
<Expander Header="File" Width="Auto">
<Grid Width="210" Height="240">
<Grid Width="210" Height="260">
<Button Name="ButtonFileOpen" Click="ButtonOpen_Click" Content="Open" Style="{StaticResource styleButton}" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top"/>
<Button Name="ButtonFileSave" Click="ButtonSave_Click" Content="Save" Style="{StaticResource styleButton}" HorizontalAlignment="Left" Margin="48,5,0,0" VerticalAlignment="Top"/>
<Button Name="ButtonFileClear" Click="ButtonClear_Click" Content="Clear" Style="{StaticResource styleButton}" HorizontalAlignment="Left" Margin="87,5,0,0" VerticalAlignment="Top"/>
Expand All @@ -62,12 +62,19 @@
<Label Name="LabelFileLength" Content="0" Margin="-8,0,0,0"/>
</StackPanel>

<ListView Name="ListViewFile" Margin="0,33" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Background="Transparent"/>
<ListView Name="ListViewFile" Margin="0,53" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Background="Transparent"/>

<Button Name="ButtonFileStart" Click="ButtonFileStart_Click" Content="Start" Style="{StaticResource styleButton}" HorizontalAlignment="Left" Margin="5,0,0,5" Height="23" VerticalAlignment="Bottom"/>
<Button Name="ButtonFilePause" Click="ButtonFilePause_Click" Content="Pause" Style="{StaticResource styleButton}" HorizontalAlignment="Left" Margin="48,0,0,5" Height="23" VerticalAlignment="Bottom"/>
<Button Name="ButtonFileGoto" Click="ButtonFileGoto_Click" Content="Go To" Style="{StaticResource styleButton}" HorizontalAlignment="Left" Margin="93,0,0,5" Height="23" VerticalAlignment="Bottom"/>
<CheckBox Name="CheckBoxPauseOnM0" Content="Pause" ToolTip="Pause the Program on M0/M1/M30" IsChecked="{util:SettingBinding PauseFileOnHold}" HorizontalAlignment="Left" Margin="138,0,-24,0" Height="23" VerticalAlignment="Bottom"/>
<Button Name="ButtonFileStart" Click="ButtonFileStart_Click" Content="Start" Style="{StaticResource styleButton}" HorizontalAlignment="Left" Margin="5,0,0,25" Height="23" VerticalAlignment="Bottom"/>
<Button Name="ButtonFilePause" Click="ButtonFilePause_Click" Content="Pause" Style="{StaticResource styleButton}" HorizontalAlignment="Left" Margin="48,0,0,25" Height="23" VerticalAlignment="Bottom"/>
<Button Name="ButtonFileGoto" Click="ButtonFileGoto_Click" Content="Go To" Style="{StaticResource styleButton}" HorizontalAlignment="Left" Margin="93,0,0,25" Height="23" VerticalAlignment="Bottom"/>
<CheckBox Name="CheckBoxPauseOnM0" Content="Pause" ToolTip="Pause the Program on M0/M1/M30" IsChecked="{util:SettingBinding PauseFileOnHold}" HorizontalAlignment="Left" Margin="138,0,-24,20" Height="23" VerticalAlignment="Bottom"/>

<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" Margin="5,5,0,0" HorizontalAlignment="Left">
<Label Content="Runtime:"/>
<Label Name="LabelFileRuntime" Content="00:00:00" Margin="0,0,-8,0"/>
<Label Content="/"/>
<Label Name="LabelFileDuration" Content="00:00:00" Margin="-8,0,0,0"/>
</StackPanel>
</Grid>
</Expander>
</Border>
Expand Down
30 changes: 23 additions & 7 deletions OpenCNCPilot/MainWindow.xaml.MachineStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
using System.Windows.Threading;

namespace OpenCNCPilot
{
partial class MainWindow
{
// Used for displaying runtime of job
Machine.OperatingMode lastMode = Machine.OperatingMode.Disconnected;
DateTime lastFileStart = DateTime.Now;
bool ShowRuntimeOnIdle = false;
TimeSpan FileRunTime = TimeSpan.Zero;
DateTime LastFileStart = DateTime.Now;
DispatcherTimer FileRuntimeTimer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(1) };

bool StopRuntimeOnIdle = false;

private void Machine_PlaneChanged()
{
Expand Down Expand Up @@ -45,10 +49,12 @@ private void Machine_StatusChanged()
else
ButtonStatus.Foreground = Brushes.Black;

if (ShowRuntimeOnIdle && machine.Status == "Idle")
if (StopRuntimeOnIdle && machine.Status == "Idle")
{
Machine_Info($"File took {(DateTime.Now - lastFileStart).ToString(@"hh\:mm\:ss")}");
ShowRuntimeOnIdle = false;
FileRuntimeTimer.Stop();
FileRuntimeTimer_Tick(null, null);
FileRunTime += DateTime.Now - LastFileStart;
StopRuntimeOnIdle = false;
}
}

Expand Down Expand Up @@ -225,6 +231,8 @@ private void Machine_FileChanged()
ToolPath.GetModel(ModelLine, ModelRapid, ModelArc);

LabelFileLength.Content = machine.File.Count;
LabelFileDuration.Content = ToolPath.TotalTime.ToString(@"hh\:mm\:ss");
FileRunTime = TimeSpan.Zero;

int digits = (int)Math.Ceiling(Math.Log10(machine.File.Count));

Expand Down Expand Up @@ -335,14 +343,22 @@ private void Machine_OperatingMode_Changed()
UpdateProbeTabButtons();

if (lastMode == Machine.OperatingMode.Manual && machine.Mode == Machine.OperatingMode.SendFile)
lastFileStart = DateTime.Now;
{
LastFileStart = DateTime.Now;
FileRuntimeTimer.Start();
}

if (lastMode == Machine.OperatingMode.SendFile && machine.Mode == Machine.OperatingMode.Manual)
ShowRuntimeOnIdle = true;
StopRuntimeOnIdle = true;

lastMode = machine.Mode;
}

private void FileRuntimeTimer_Tick(object sender, EventArgs e)
{
LabelFileRuntime.Content = ((DateTime.Now - LastFileStart) + FileRunTime).ToString(@"hh\:mm\:ss");
}

private void Machine_ConnectionStateChanged()
{
ButtonConnect.Visibility = machine.Connected ? Visibility.Collapsed : Visibility.Visible;
Expand Down
1 change: 1 addition & 0 deletions OpenCNCPilot/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public MainWindow()
Machine_OperatingMode_Changed();

Properties.Settings.Default.SettingChanging += Default_SettingChanging;
FileRuntimeTimer.Tick += FileRuntimeTimer_Tick;

LoadMacros();

Expand Down

0 comments on commit 9ef8c88

Please sign in to comment.