Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
vfauth committed Mar 6, 2018
2 parents 7183162 + 04312ad commit 863b4ab
Show file tree
Hide file tree
Showing 29 changed files with 894 additions and 544 deletions.
5 changes: 4 additions & 1 deletion PPcurry/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<applicationSettings>
<PPcurry.Properties.Settings>
<setting name="ResourcesFolder" serializeAs="String">
<value>Resources</value>
<value>Resources/Components</value>
</setting>
<setting name="GridThickness" serializeAs="String">
<value>1</value>
Expand All @@ -37,6 +37,9 @@
<setting name="WireThicknessSelected" serializeAs="String">
<value>6</value>
</setting>
<setting name="SaveFolder" serializeAs="String">
<value>SavedCircuits</value>
</setting>
</PPcurry.Properties.Settings>
</applicationSettings>
</configuration>
27 changes: 8 additions & 19 deletions PPcurry/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,13 @@
xmlns:local="clr-namespace:PPcurry"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style x:Key="ImageButton" TargetType="Button">
<!-- Custom style for buttons with images, so that the image stays displayed when the mouse is over the button. -->
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border" BorderThickness="0" BorderBrush="Black" Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="0.8" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Teal.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Cyan.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
249 changes: 140 additions & 109 deletions PPcurry/BoardGrid.cs

Large diffs are not rendered by default.

336 changes: 181 additions & 155 deletions PPcurry/Component.cs

Large diffs are not rendered by default.

107 changes: 46 additions & 61 deletions PPcurry/ComponentDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
using System.Diagnostics;
using System.Xml.Linq;
using System.Globalization;
using MaterialDesignThemes.Wpf;
using MaterialDesignThemes.Wpf.Transitions;

namespace PPcurry
{
public class ComponentDialog : Window
public class ComponentDialog : StackPanel
{
#region Attributes

Expand All @@ -37,14 +39,21 @@ public class ComponentDialog : Window
/// </summary>
public ComponentDialog()
{
this.Owner = Application.Current.MainWindow;

this.SizeToContent = SizeToContent.WidthAndHeight; // The dialog size is that of its children
this.WindowStyle = WindowStyle.ToolWindow; // To have only the close button
this.WindowStartupLocation = WindowStartupLocation.CenterOwner; // The dialog is positionned in the center of the main window
Orientation = Orientation.Vertical;
KeyDown += ComponentDialog_KeyUp;
}

// Event handlers
this.Closing += ComponentDialog_Closing;
private void ComponentDialog_KeyUp(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
ButtonOk_Click(sender, e);
break;
case Key.Escape:
ButtonCancel_Click(sender, e);
break;
}
}
#endregion

Expand All @@ -56,30 +65,18 @@ public ComponentDialog()
/// </summary>
public void Display(Component component)
{
this.ComponentEdited = component;
this.Content = null; // Delete all previous elements
this.Title = "Edit attributes";
this.FillDialog();
this.Show();
ComponentEdited = component;
Children.Clear(); // Delete all previous elements
FillDialog();
((MainWindow)Application.Current.MainWindow).AttributesDialogHost.IsOpen = true; // Display the dialog
}

/// <summary>
/// Create controls inside the dialog
/// </summary>
private void FillDialog()
{
this.EditableFields = new Dictionary<string, TextBox>();
DockPanel mainDockPanel = new DockPanel
{
LastChildFill = false // If set to true, the last element would not be placed right
};
this.Content = mainDockPanel;

// The StackPanel to stack all the controls
StackPanel mainStackPanel = new StackPanel();
mainDockPanel.Children.Add(mainStackPanel);
mainStackPanel.Orientation = Orientation.Vertical;
DockPanel.SetDock(mainStackPanel, Dock.Top);
EditableFields = new Dictionary<string, TextBox>();

// To edit the name
TextBlock textName = new TextBlock
Expand All @@ -90,25 +87,25 @@ private void FillDialog()

TextBox nameBox = new TextBox
{
Text = this.ComponentEdited.GetName(),
Text = ComponentEdited.Name,
MinWidth = 200,
HorizontalContentAlignment = HorizontalAlignment.Center
};
EditableFields.Add("name", nameBox);

this.EditableFields.Add("name", nameBox);
DockPanel namePanel = new DockPanel
{
Margin = new Thickness(10)
};
DockPanel.SetDock(textName, Dock.Left);
DockPanel.SetDock(nameBox, Dock.Right);
DockPanel.SetDock(textName, Dock.Right);
namePanel.Children.Add(nameBox);
namePanel.Children.Add(textName);
mainStackPanel.Children.Add(namePanel);
Children.Add(namePanel);

// To edit attributes
Dictionary<string, double?> attributes = this.ComponentEdited.Attributes; // The components attributes
Dictionary<string, Dictionary<string, double>> attributesUnits = this.ComponentEdited.AttributesUnits; // The component attributes available units
Dictionary<string, double?> attributes = ComponentEdited.Attributes; // The components attributes
Dictionary<string, Dictionary<string, double>> attributesUnits = ComponentEdited.AttributesUnits; // The component attributes available units
List<TextBox> attributesValuesControls = new List<TextBox>(); // The controls to edit the attributes

foreach (string attributeName in attributes.Keys)
Expand All @@ -129,16 +126,16 @@ private void FillDialog()
attributeValueControl.Text = ((double)attributes[attributeName]).ToString();
}

this.EditableFields.Add(attributeName, attributeValueControl);
EditableFields.Add(attributeName, attributeValueControl);
DockPanel attributeControl = new DockPanel
{
Margin = new Thickness(10)
};
DockPanel.SetDock(attributeNameControl, Dock.Left);
DockPanel.SetDock(attributeValueControl, Dock.Right);
DockPanel.SetDock(attributeNameControl, Dock.Right);
attributeControl.Children.Add(attributeValueControl);
attributeControl.Children.Add(attributeNameControl);
mainStackPanel.Children.Add(attributeControl);
Children.Add(attributeControl);
}

// For the "ok" and "cancel" buttons
Expand All @@ -147,23 +144,20 @@ private void FillDialog()
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Center
};
mainStackPanel.Children.Add(buttonsStackPanel);
DockPanel.SetDock(buttonsStackPanel, Dock.Bottom);
Children.Add(buttonsStackPanel);
Button buttonOk = new Button
{
Width = 50,
Height = 25,
Margin = new Thickness(10),
Content = "Ok"
Content = "Ok",
ToolTip = "Close the dialog and save the attributes"
};
buttonOk.Click += ButtonOk_Click;
buttonsStackPanel.Children.Add(buttonOk);
Button buttonCancel = new Button
{
Width = 50,
Height = 25,
Margin = new Thickness(10),
Content = "Annuler"
Content = "Cancel",
ToolTip = "Close the dialog but doesn't save the attributes"
};
buttonCancel.Click += ButtonCancel_Click;
buttonsStackPanel.Children.Add(buttonCancel);
Expand All @@ -175,11 +169,11 @@ private void FillDialog()
private void SaveValues()
{
// Names
this.ComponentEdited.SetName(EditableFields["name"].Text);
ComponentEdited.Name = EditableFields["name"].Text;

// Attributes
Dictionary<string, double?> attributes = new Dictionary<string, double?>(this.ComponentEdited.Attributes); // The components attributes
Dictionary<string, Dictionary<string, double>> attributesUnits = this.ComponentEdited.AttributesUnits; // The component attributes available units
Dictionary<string, double?> attributes = new Dictionary<string, double?>(ComponentEdited.Attributes); // The components attributes
Dictionary<string, Dictionary<string, double>> attributesUnits = ComponentEdited.AttributesUnits; // The component attributes available units

foreach (string attribute in EditableFields.Keys)
{
Expand All @@ -189,37 +183,28 @@ private void SaveValues()
}
else if (attribute != "name")
{
attributes[attribute] = double.Parse(EditableFields[attribute].Text, CultureInfo.InvariantCulture); // Parse the string while supporting decimal points and commas
attributes[attribute] = double.Parse(EditableFields[attribute].Text.Replace('.', ',')); // Parse the string while supporting decimal points and commas
}
}

this.ComponentEdited.Attributes = attributes;
ComponentEdited.Attributes = attributes;
}

/// <summary>
/// Handle the click on the "Ok" button
/// Handler called when the "Ok" button is clicked or the Enter key is pressed
/// </summary>
private void ButtonOk_Click(object sender, RoutedEventArgs e)
{
this.SaveValues();
this.Hide();
SaveValues();
((MainWindow)Application.Current.MainWindow).AttributesDialogHost.IsOpen = false; // Close the dialog
}

/// <summary>
/// Handle the click on the "Cancel" button
/// Handler called when the "Cancel" button is clicked or the Esc key is pressed
/// </summary>
private void ButtonCancel_Click(object sender, RoutedEventArgs e)
{
this.Hide();
}

/// <summary>
/// Handle the closing of the window to cancel it and hide the window instead
/// </summary>
private void ComponentDialog_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true; // Cancel the closing
this.Hide();
((MainWindow)Application.Current.MainWindow).AttributesDialogHost.IsOpen = false; // Close the dialog
}
#endregion
}
Expand Down
File renamed without changes.
Loading

0 comments on commit 863b4ab

Please sign in to comment.