Exemple #1
0
        public ViewModel(MainWindow window)
        {
            _refreshing = true;

            _cutTree         = window.cutTree;
            _cutPropertyGrid = window.cutPropertyGrid;
            _cutResultGrid   = window.cutResultGrid;
            _cutNameGrid     = window.cutNameGrid;
            _graph           = window.linegraph;

            _inputFields    = new Dictionary <string, InputProperty>();
            _computedFields = new Dictionary <string, ComputedProperty>();

            // The cut name textbox
            Label cutNameLabel = new Label();

            cutNameLabel.Content             = "Name";
            cutNameLabel.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            _cutNameGrid.Children.Add(cutNameLabel);

            _cutNameText              = new TextBox();
            _cutNameText.Text         = "";
            _cutNameText.Margin       = new System.Windows.Thickness(5);
            _cutNameText.TextChanged += (b, c) => CutNameChanged();
            _cutNameText.Background   = new SolidColorBrush(k_enabledColor);
            _cutNameText.IsReadOnly   = true;
            Grid.SetColumn(_cutNameText, 2);
            _cutNameGrid.Children.Add(_cutNameText);

            // build the input fields
            int row = 0;

            foreach (CutProperty property in Cut.GetCutPropertyDefinitions())
            {
                string name = property.name;

                RowDefinition rowDefinition = new RowDefinition();
                rowDefinition.Height = new GridLength(30);
                _cutPropertyGrid.RowDefinitions.Add(rowDefinition);

                InputProperty field = new InputProperty();
                _inputFields.Add(name, field);

                field.label                     = new Label();
                field.label.Content             = name;
                field.label.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                Grid.SetRow(field.label, row);
                _cutPropertyGrid.Children.Add(field.label);

                field.text              = new TextBox();
                field.text.Text         = "";
                field.text.Margin       = new System.Windows.Thickness(5);
                field.text.TextChanged += (b, c) => FieldTextChanged(name, field);
                field.text.Background   = new SolidColorBrush(k_disabledColor);
                field.text.IsReadOnly   = true;
                Grid.SetRow(field.text, row);
                Grid.SetColumn(field.text, 2);
                _cutPropertyGrid.Children.Add(field.text);

                field.checkbox            = new CheckBox();
                field.checkbox.IsChecked  = false;
                field.checkbox.Checked   += (b, c) => FieldTextChecked(name, field);
                field.checkbox.Unchecked += (b, c) => FieldTextUnChecked(name, field);
                field.checkbox.Margin     = new System.Windows.Thickness(5);
                Grid.SetRow(field.checkbox, row);
                Grid.SetColumn(field.checkbox, 1);
                _cutPropertyGrid.Children.Add(field.checkbox);

                field.units         = new Label();
                field.units.Content = property.units;
                Grid.SetRow(field.units, row);
                Grid.SetColumn(field.units, 3);
                _cutPropertyGrid.Children.Add(field.units);

                row++;
            }

            // build the computed fields
            row = 0;
            foreach (CutProperty property in Cut.GetComputedPropertyDefinitions())
            {
                string           name  = property.name;
                ComputedProperty field = new ComputedProperty();
                _computedFields.Add(name, field);

                RowDefinition rowDefinition = new RowDefinition();
                rowDefinition.Height = new GridLength(30);
                _cutResultGrid.RowDefinitions.Add(rowDefinition);

                field.label                     = new Label();
                field.label.Content             = name;
                field.label.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                Grid.SetRow(field.label, row);
                _cutResultGrid.Children.Add(field.label);

                field.text            = new TextBox();
                field.text.Text       = "";
                field.text.IsReadOnly = true;
                field.text.Margin     = new System.Windows.Thickness(5);
                field.text.Background = new SolidColorBrush(k_computedColor);
                Grid.SetRow(field.text, row);
                Grid.SetColumn(field.text, 1);
                _cutResultGrid.Children.Add(field.text);

                field.units         = new Label();
                field.units.Content = property.units;
                Grid.SetRow(field.units, row);
                Grid.SetColumn(field.units, 2);
                _cutResultGrid.Children.Add(field.units);

                field.model = property;

                row++;
            }

            _cutDB = ReadFromJsonFile <CutDB>("cutsdb.json");
            if (_cutDB == null)
            {
                NewDB();
            }
            else
            {
                _cutDB.AfterLoad();
                PushCutDBToTree();
            }

            _refreshing = false;
        }
Exemple #2
0
 public void NewDB()
 {
     _cutDB = new CutDB();
     //_cutDB.Cuts.Add(new Cut());
     PushCutDBToTree();
 }