private void cb_mappings_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (this.cb_mappings.SelectedItem != null)
     {
         ParameterStructure.Mapping.Mapping2Component mapping = this.cb_mappings.SelectedItem as ParameterStructure.Mapping.Mapping2Component;
         if (mapping != null)
         {
             this.CompCalculator = mapping.Calculator;
             this.c_data.TranslateMapping(mapping, out this.current_input_mapping, out this.current_output_mapping);
             this.tb_mapping_name.Text = mapping.Name;
             this.current_mapping      = mapping;
             this.IsInMapEditingMode   = true;
         }
     }
     else
     {
         this.CompCalculator         = null;
         this.current_input_mapping  = new Dictionary <ParameterStructure.Parameter.Parameter, ParameterStructure.Parameter.Parameter>();
         this.current_output_mapping = new Dictionary <ParameterStructure.Parameter.Parameter, ParameterStructure.Parameter.Parameter>();
         this.tb_mapping_name.Text   = string.Empty;
         this.current_mapping        = null;
         this.IsInMapEditingMode     = false;
     }
     this.UpdateDisplayOnCompCalculatorLoad();
     this.UpdateMappingTrackingDisplay();
 }
        private void AddMappingToComponent()
        {
            if (this.c_data == null || this.c_calculator == null)
            {
                return;
            }
            if (this.current_input_mapping.Count == 0)
            {
                return;
            }
            if (this.current_output_mapping.Count == 0)
            {
                return;
            }

            string name             = (string.IsNullOrEmpty(this.tb_mapping_name.Text)) ? "Mapping to " + this.c_calculator.Name : this.tb_mapping_name.Text;
            Comp2CompMappingErr err = Comp2CompMappingErr.NONE;

            if (this.IsInMapEditingMode)
            {
                // save changes to mapping
                this.c_data.EditMapping(this.current_mapping, this.current_input_mapping, this.current_output_mapping, out err);
                this.IsInMapEditingMode = false;
            }
            else
            {
                // create new mapping
                this.current_mapping = this.c_data.CreateMappingTo(name, this.c_calculator, this.current_input_mapping, this.current_output_mapping, out err);
            }

            if (err != Comp2CompMappingErr.NONE)
            {
                MessageBox.Show("Mapping Error: " + err.ToString(), "Mapping Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (this.current_mapping == null)
            {
                MessageBox.Show("Mapping Error: UNKNOWN", "Mapping Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            // reset internal containers
            this.current_input_mapping.Clear();
            this.current_output_mapping.Clear();

            // update GUI
            this.cb_mappings.ItemsSource  = new List <ParameterStructure.Mapping.Mapping2Component>(this.c_data.Mappings2Comps);
            this.cb_mappings.SelectedItem = null;
        }
        private void InitControls()
        {
            // component picking
            this.IsPickingCompData       = false;
            this.IsPickingCompCalculator = false;
            this.IsMapping          = false;
            this.IsInMapEditingMode = false;

            this.tbtn_get_data.Command = new RelayCommand((x) => this.IsPickingCompData = !(this.IsPickingCompData),
                                                          (x) => !this.IsPickingCompCalculator && !this.IsMapping);
            this.tbtn_get_data.IsChecked = false;

            this.tbtn_get_calc.Command = new RelayCommand((x) => { this.cb_mappings.SelectedItem = null; this.IsPickingCompCalculator = !(this.IsPickingCompCalculator); },
                                                          (x) => !this.IsPickingCompData && !this.IsMapping && this.CompData != null);
            this.tbtn_get_calc.IsChecked = false;

            // mapping
            this.current_input_mapping  = new Dictionary <ParameterStructure.Parameter.Parameter, ParameterStructure.Parameter.Parameter>();
            this.current_output_mapping = new Dictionary <ParameterStructure.Parameter.Parameter, ParameterStructure.Parameter.Parameter>();
            this.current_mapping        = null;

            this.tbtn_map_manual.Command = new RelayCommand((x) => this.IsMapping = !(this.IsMapping),
                                                            (x) => !this.IsPickingCompData && !this.IsPickingCompCalculator);
            this.tbtn_map_manual.IsChecked = this.IsMapping;
            this.btn_P2Pmap_delete.Command = new RelayCommand((x) => RemoveP2PMapping());

            this.tv_comp_data.SelectedItemChanged += tv_comp_data_SelectedItemChanged;
            this.tv_comp_calc.SelectedItemChanged += tv_comp_calc_SelectedItemChanged;
            this.tv_comp_calc.MouseMove           += tv_comp_calc_MouseMove;
            this.tv_comp_data.ActOnTreeViewItemExpandedChangedHandler = this.UpdateMappingDisplay;
            this.tv_comp_calc.ActOnTreeViewItemExpandedChangedHandler = this.UpdateMappingDisplay;

            this.c_pointer_WS.MouseMove        += c_pointer_WS_MouseMove;
            this.c_pointer_WS.PreviewMouseMove += c_pointer_WS_MouseMove;

            this.btn_OK.Command = new RelayCommand((x) => this.AddMappingToComponent(),
                                                   (x) => !this.IsMapping && !this.IsPickingCompData && !this.IsPickingCompCalculator);
            this.btn_Del.Command = new RelayCommand((x) => this.RemoveSelectedMapping(),
                                                    (x) => CanExecute_RemoveSelectedMapping());

            this.btn_calculate.Command = new RelayCommand((x) => this.TestCalculateMapping(),
                                                          (x) => this.CanExecute_TestCalculateMapping());
            this.btn_P_highlight.Command = new RelayCommand((x) => this.TogglePHighlight(),
                                                            (x) => this.CanExecute_TogglePHighlight());

            this.cb_mappings.SelectionChanged += cb_mappings_SelectionChanged;
        }
        private void RemoveSelectedMapping()
        {
            MessageBoxResult result = MessageBox.Show("Wollen Sie das Mapping wirklich entfernen?", "Mapping Entfernen", MessageBoxButton.OKCancel, MessageBoxImage.Question);

            if (result != MessageBoxResult.OK)
            {
                return;
            }

            this.CompData.RemoveMapping(this.current_mapping);

            this.CompCalculator         = null;
            this.current_input_mapping  = new Dictionary <ParameterStructure.Parameter.Parameter, ParameterStructure.Parameter.Parameter>();
            this.current_output_mapping = new Dictionary <ParameterStructure.Parameter.Parameter, ParameterStructure.Parameter.Parameter>();
            this.tb_mapping_name.Text   = string.Empty;
            this.current_mapping        = null;

            this.UpdateDisplayOnCompDataLoad();
            this.UpdateDisplayOnCompCalculatorLoad();
            this.UpdateMappingTrackingDisplay();
        }