Guest User

Untitled

a guest
Apr 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.59 KB | None | 0 0
  1. <Window x:Class="Hipot_Sequence_Editor.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:local="clr-namespace:Hipot_Sequence_Editor"
  7. xmlns:viewModels="clr-namespace:Hipot_Sequence_Editor"
  8. xmlns:views="clr-namespace:Hipot_Sequence_Editor.Views"
  9. mc:Ignorable="d"
  10. Title="MainWindow" Height="677.538" Width="896.456" Name="mainWindow" Loaded="mainWindow_Loaded">
  11.  
  12. <Window.DataContext>
  13. <local:VM_Main></local:VM_Main>
  14. </Window.DataContext>
  15.  
  16. <Grid>
  17. <Grid.RowDefinitions>
  18. <RowDefinition Height="25*"/>
  19. <RowDefinition Height="299*"/>
  20. </Grid.RowDefinitions>
  21. <Grid.ColumnDefinitions>
  22. <ColumnDefinition Width="211*"/>
  23. <ColumnDefinition Width="86*"/>
  24. </Grid.ColumnDefinitions>
  25. <TreeView x:Name="treeView" Grid.Column="1" HorizontalAlignment="Left" Height="628" Margin="10.2,10,0,0" VerticalAlignment="Top" Width="237" Grid.RowSpan="2" ItemsSource="{Binding Parts}" SelectedItemChanged="TreeView_OnSelectedItemChanged">
  26. <TreeView.Resources>
  27.  
  28. <HierarchicalDataTemplate x:Name="PartLevel" DataType="{x:Type viewModels:VM_Part}" ItemsSource="{Binding VM_Steps}">
  29. <StackPanel Orientation="Horizontal">
  30.  
  31. <TextBlock Text="{Binding SequenceNumber}" />
  32. <TextBlock Text=" - "></TextBlock>
  33. <TextBlock Text="{Binding Name}" />
  34. </StackPanel>
  35. </HierarchicalDataTemplate>
  36. <DataTemplate DataType="{x:Type viewModels:VM_Step}">
  37. <StackPanel Orientation="Horizontal">
  38. <CheckBox Visibility="{Binding Path=DataContext.CheckMarksVisible, ElementName=PartLevel}"></CheckBox>
  39. <TextBlock Text="{Binding Name}" />
  40. </StackPanel>
  41. </DataTemplate>
  42. </TreeView.Resources>
  43. </TreeView>
  44.  
  45. <ContentControl Grid.Row="1" Grid.Column="0" x:Name="ContentPanel" Content="{Binding TreeViewSelectedItem}">
  46. <ContentControl.Resources>
  47. <DataTemplate DataType="{x:Type local:VM_Part}">
  48. <Label Content="{Binding Name}"></Label>
  49. </DataTemplate>
  50. <DataTemplate DataType="{x:Type local:VM_Step}">
  51. <views:StepEditorView/>
  52. </DataTemplate>
  53. </ContentControl.Resources>
  54. </ContentControl>
  55.  
  56. </Grid>
  57. </Window>
  58.  
  59. using System.Collections.ObjectModel;
  60. using System.Windows;
  61.  
  62.  
  63. namespace Hipot_Sequence_Editor
  64. {
  65. /// <summary>
  66. /// Interaction logic for MainWindow.xaml
  67. /// </summary>
  68. public partial class MainWindow : Window
  69. {
  70.  
  71. private VM_Main _viewModel;
  72.  
  73. public MainWindow()
  74. {
  75. InitializeComponent();
  76.  
  77. _viewModel = (VM_Main)DataContext;
  78.  
  79. }
  80.  
  81. private void TreeView_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  82. {
  83. _viewModel.TreeViewSelectedItem = e.NewValue;
  84. }
  85.  
  86. private void mainWindow_Loaded(object sender, RoutedEventArgs e)
  87. {
  88. _viewModel.Parts = new ObservableCollection<VM_Part>
  89. {
  90. new VM_Part()
  91. {
  92. Name = "Sequence 1",
  93. SequenceNumber = 1,
  94. VM_Steps = new ObservableCollection<VM_Step>()
  95. {
  96. new VM_Step() {
  97. Name = "Step 1",
  98. TestType = TestType.DCW,
  99. VM_Step_Test = new VM_Step_Test()
  100. {
  101. Voltage = 50,
  102. RampTime = 33,
  103. DwellTime = 20,
  104. TestTimeResistance = 30,
  105. }
  106. },
  107. new VM_Step() {
  108. Name = "Step 2",
  109. TestType = TestType.DCW,
  110. VM_Step_Test = new VM_Step_Test()
  111. {
  112. Voltage = 55,
  113. RampTime = 34,
  114. DwellTime = 23,
  115. TestTimeResistance = 23,
  116. }
  117. },
  118. new VM_Step() {
  119. Name = "Step 3",
  120. TestType = TestType.LOWOHM,
  121. VM_Step_Test = new VM_Step_Test()
  122. {
  123. TestTimeResistance = 30,
  124. MaxResistance = 100
  125. }
  126. }
  127. }
  128. },
  129. new VM_Part()
  130. {
  131. Name = "Sequence 2",
  132. SequenceNumber = 2,
  133. VM_Steps = new ObservableCollection<VM_Step>()
  134. {
  135. new VM_Step() {
  136. Name = "Step 1",
  137. TestType = TestType.DCW,
  138. VM_Step_Test = new VM_Step_Test()
  139. {
  140. Voltage = 23,
  141. RampTime = 21,
  142. DwellTime = 10,
  143. TestTimeResistance = 05,
  144. }
  145. },
  146. new VM_Step() {
  147. Name = "Step 2",
  148. TestType = TestType.DCW,
  149. VM_Step_Test = new VM_Step_Test()
  150. {
  151. Voltage = 55,
  152. RampTime = 56,
  153. DwellTime = 53,
  154. TestTimeResistance = 46,
  155. }
  156. },
  157. new VM_Step() {
  158. Name = "Step 3",
  159. TestType = TestType.LOWOHM,
  160. VM_Step_Test = new VM_Step_Test()
  161. {
  162. TestTimeResistance = 989,
  163. MaxResistance = 75
  164. }
  165. }
  166. }
  167. }
  168. };
  169. }
  170. }
  171. }
  172.  
  173. <UserControl x:Class="Hipot_Sequence_Editor.Views.StepEditorView"
  174. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  175. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  176. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  177. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  178. xmlns:dataModel="clr-namespace:Hardware.DataModel;assembly=Vitrek-Library"
  179. xmlns:uiConverters="clr-namespace:Hipot_Sequence_Editor.UI_Converters"
  180. mc:Ignorable="d"
  181. d:DesignHeight="300" d:DesignWidth="300">
  182. <UserControl.Resources>
  183. <uiConverters:DoubleStringConverter x:Key="DoubleStringConverter" />
  184. <uiConverters:EnumSelectedConverter x:Key="EnumSelectedConverter" />
  185. </UserControl.Resources>
  186. <Grid>
  187. <Grid.RowDefinitions>
  188. <RowDefinition Height="25"/>
  189. <RowDefinition Height="100"/>
  190.  
  191. </Grid.RowDefinitions>
  192. <Grid.ColumnDefinitions>
  193. <ColumnDefinition Width="*" />
  194. </Grid.ColumnDefinitions>
  195. <WrapPanel Grid.Row="0">
  196. <Label>Step: </Label>
  197. <Label Content="{Binding Name}"></Label>
  198. </WrapPanel>
  199. <TabControl Grid.Row="1">
  200. <TabItem Header="Resistance" IsSelected="{Binding VM_Step_Test.vTestType, Converter={StaticResource EnumSelectedConverter}, ConverterParameter={x:Static dataModel:TestType.LOWOHM}}">
  201. <WrapPanel>
  202. <WrapPanel>
  203. <Label Content="Resistance"></Label>
  204. <TextBox Width="50" Text="{Binding VM_Step_Test.MaxResistance, Converter={StaticResource DoubleStringConverter}}"></TextBox>
  205. <Label Content="Ω"></Label>
  206. </WrapPanel>
  207. <WrapPanel>
  208. <Label Content="Dwell Time"></Label>
  209. <TextBox Width="50" Text="{Binding VM_Step_Test.TestTimeResistance, Converter={StaticResource DoubleStringConverter}}"></TextBox>
  210. <Label Content="mSec"></Label>
  211. </WrapPanel>
  212. </WrapPanel>
  213. </TabItem>
  214. <TabItem Header="DC Hipot" IsSelected="{Binding VM_Step_Test.vTestType, Converter={StaticResource EnumSelectedConverter}, ConverterParameter={x:Static dataModel:TestType.DCW}}" Height="22" VerticalAlignment="Top">
  215. <WrapPanel>
  216. <WrapPanel>
  217. <Label Content="Voltage"></Label>
  218. <TextBox Width="50" Text="{Binding VM_Step_Test.Voltage, Converter={StaticResource DoubleStringConverter}}"></TextBox>
  219. <Label Content="kV"></Label>
  220. </WrapPanel>
  221. <WrapPanel>
  222. <Label Content="Ramp Time"></Label>
  223. <TextBox Width="50" Text="{Binding VM_Step_Test.RampTime, Converter={StaticResource DoubleStringConverter}}"></TextBox>
  224. <Label Content="mSec"></Label>
  225. </WrapPanel>
  226. <WrapPanel>
  227. <Label Content="Dwell Time"></Label>
  228. <TextBox Width="50" Text="{Binding VM_Step_Test.DwellTime, Converter={StaticResource DoubleStringConverter}}"></TextBox>
  229. <Label Content="mSec"></Label>
  230. </WrapPanel>
  231. </WrapPanel>
  232. </TabItem>
  233.  
  234. </TabControl>
  235. </Grid>
  236. </UserControl>
  237.  
  238. using System;
  239. using System.Collections.ObjectModel;
  240. using System.ComponentModel;
  241. using PropertyChanged;
  242.  
  243. namespace Hipot_Sequence_Editor
  244. {
  245. [AddINotifyPropertyChangedInterface]
  246. public class VM_Main
  247. {
  248.  
  249. private object _treeViewSelectedItem;
  250.  
  251. public ObservableCollection<VM_Part> Parts { get; set; }
  252.  
  253. public object TreeViewSelectedItem
  254. {
  255. get => _treeViewSelectedItem;
  256. set { _treeViewSelectedItem = value; OnSelectedNodeChanged(value); }
  257. }
  258.  
  259. public VM_Part SelectedPartForUI { get; set; }
  260.  
  261. public VM_Step SelectedStepForUI { get; set; }
  262.  
  263. public VM_Step_Test SelectedTestStepForUI { get; set; }
  264.  
  265. private void OnSelectedNodeChanged(object node)
  266. {
  267. switch (node)
  268. {
  269. case VM_Part vmpart:
  270. SelectedPartForUI = vmpart;
  271. break;
  272. case VM_Step vmstep:
  273. SelectedStepForUI = vmstep;
  274. break;
  275. default:
  276. throw new NotImplementedException();
  277.  
  278. }
  279.  
  280. }
  281. }
  282.  
  283. public enum TestType
  284. {
  285. [Description("AC Hipot")]
  286. ACW,
  287. [Description("DC Hipot")]
  288. DCW,
  289. [Description("Resistance")]
  290. LOWOHM
  291. }
  292.  
  293. [AddINotifyPropertyChangedInterface]
  294. public class VM_Part
  295. {
  296. public int SequenceNumber { get; set; }
  297. public string Name { get; set; }
  298. public ObservableCollection<VM_Step> VM_Steps { get; set; }
  299. public bool IsSelected { get; set; }
  300. public bool CheckMarksVisible { get; set; }
  301. }
  302.  
  303. [AddINotifyPropertyChangedInterface]
  304. public class VM_Step
  305. {
  306. public string Name { get; set; }
  307. public TestType TestType { get; set; }
  308. public VM_Step_Test VM_Step_Test { get; set; }
  309. public bool IsSelected { get; set; }
  310.  
  311. }
  312.  
  313. [AddINotifyPropertyChangedInterface]
  314. public class VM_Step_Test
  315. {
  316. public TestType vTestType { get; set; }
  317. public double RampTime { get; set; }
  318.  
  319. public double DwellTime { get; set; }
  320.  
  321. public double Voltage { get; set; }
  322.  
  323. public double TestTimeResistance { get; set; }
  324. public double MaxResistance { get; set; }
  325. }
  326.  
  327. }
  328.  
  329. using System.Windows.Data;
  330.  
  331. namespace Hipot_Sequence_Editor.UI_Converters
  332. {
  333.  
  334. public class EnumSelectedConverter : IValueConverter
  335. {
  336. public object Convert(object value, Type targetType,
  337. object parameter, System.Globalization.CultureInfo culture)
  338. {
  339. if (value == null || parameter == null) return false;
  340. TestType vmType = (TestType) value;
  341. TestType viewType = (TestType) parameter;
  342.  
  343. return vmType == viewType;
  344. }
  345.  
  346. public object ConvertBack(object value, Type targetType,
  347. object parameter, System.Globalization.CultureInfo culture)
  348. {
  349. if (value == null || parameter == null) return false;
  350.  
  351. bool isSelected = (bool) value;
  352. if (!isSelected) return false;
  353.  
  354. TestType vTestType = (TestType) parameter;
  355.  
  356. return vTestType;
  357. }
  358. }
  359. }
  360.  
  361. using System;
  362. using System.Windows.Data;
  363.  
  364. namespace Hipot_Sequence_Editor.UI_Converters
  365. {
  366.  
  367. public class DoubleStringConverter : IValueConverter
  368. {
  369. private string user_string = null;
  370.  
  371. public object Convert(object value, Type targetType,
  372. object parameter, System.Globalization.CultureInfo culture)
  373. {
  374. if (user_string != null)
  375. {
  376. return user_string;
  377. }
  378.  
  379. double number = (double)value;
  380. return string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}", number);
  381. }
  382.  
  383. public object ConvertBack(object value, Type targetType,
  384. object parameter, System.Globalization.CultureInfo culture)
  385. {
  386. string s_value = value.ToString();
  387. double result = 0;
  388.  
  389. System.Text.RegularExpressions.Regex nonNumericCharacters = new System.Text.RegularExpressions.Regex(@"[^0-9.]");
  390. string numericOnlyString = nonNumericCharacters.Replace(s_value, String.Empty);
  391.  
  392. if (!double.TryParse(numericOnlyString, System.Globalization.NumberStyles.Number,
  393. System.Globalization.CultureInfo.CurrentCulture, out result))
  394. return null;
  395.  
  396. user_string = s_value;
  397.  
  398. return result;
  399. }
  400. }
  401. }
Add Comment
Please, Sign In to add comment