private List <Line> GetMappingVis(ParameterStructure.Parameter.Parameter _source, ParameterStructure.Parameter.Parameter _target, bool _input, double _connection_offset = 0.0)
        {
            List <Line> lines = new List <Line>();

            if (_source == null || _target == null)
            {
                return(lines);
            }

            TreeViewItem container_source = TreeViewQuery.ContainerFromItem(this.tv_comp_data, _source);
            TreeViewItem container_target = TreeViewQuery.ContainerFromItem(this.tv_comp_calc, _target);

            if (container_source != null && container_source.IsVisible &&
                container_target != null && container_target.IsVisible)
            {
                // draw the lines
                Point source = container_source.TransformToAncestor(this.tv_comp_data).Transform(new Point(0, 0));
                Point target = container_target.TransformToAncestor(this.tv_comp_calc).Transform(new Point(0, 0));

                Color  col       = (_input) ? COL_MAPPING_INPUT : COL_MAPPING_OUTPUT;
                double thickness = (_input) ? 1.0 : 2.0;

                lines = Utils.DrawConnection(HALF_H_TV_ROW_COMP, HALF_H_TV_ROW_COMP, this.c_pointer_midside_measure.ActualWidth, this.c_pointer_middle_measure.ActualWidth,
                                             source, target, target, (container_target == null || !container_target.IsVisible), col, thickness, _connection_offset);
            }

            return(lines);
        }
        private bool CanExecute_TogglePHighlight()
        {
            if (this.IsMapping || this.IsPickingCompData || this.IsPickingCompCalculator)
            {
                return(false);
            }
            if (this.c_data == null || this.c_calculator == null)
            {
                return(false);
            }

            if (this.tv_comp_calc.SelectedItem == null)
            {
                return(false);
            }
            ParameterStructure.Parameter.Parameter selected_p = this.tv_comp_calc.SelectedItem as ParameterStructure.Parameter.Parameter;
            if (selected_p == null)
            {
                return(false);
            }
            if (selected_p.Propagation != InfoFlow.MIXED && selected_p.Propagation != InfoFlow.OUPUT)
            {
                return(false);
            }

            return(true);
        }
        private void RemoveP2PMapping()
        {
            if (this.tv_comp_data == null)
            {
                return;
            }
            if (this.tv_comp_data.SelectedItem == null)
            {
                return;
            }

            ParameterStructure.Parameter.Parameter selP = this.tv_comp_data.SelectedItem as ParameterStructure.Parameter.Parameter;
            if (selP == null)
            {
                return;
            }

            if (this.current_input_mapping.ContainsKey(selP))
            {
                this.current_input_mapping.Remove(selP);
            }
            else if (this.current_output_mapping.ContainsKey(selP))
            {
                this.current_output_mapping.Remove(selP);
            }

            this.UpdateMappingTrackingDisplay();
        }
        protected void node_calc_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            ParameterStructure.Parameter.Parameter param = sender as ParameterStructure.Parameter.Parameter;
            if (param == null || e == null)
            {
                return;
            }

            if (e.PropertyName == "InputParams" || e.PropertyName == "ReturnParams" || e.PropertyName == "Expression")
            {
                this.UpdateContent();
            }
        }
        private void CreateP2PMapping(ParameterStructure.Parameter.Parameter _target_parameter)
        {
            if (this.MappedSourceParameter == null)
            {
                return;
            }
            if (_target_parameter == null)
            {
                return;
            }

            if (_target_parameter.Propagation == InfoFlow.INPUT)
            {
                if (this.current_input_mapping.ContainsKey(this.MappedSourceParameter) ||
                    this.current_input_mapping.ContainsValue(_target_parameter))
                {
                    MessageBox.Show("Parameter Mapping Error: Cannot map the same parameter twice!", "Parameter Mapping Error",
                                    MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else if (this.MappedSourceParameter.Propagation == InfoFlow.OUPUT || this.MappedSourceParameter.Propagation == InfoFlow.CALC_IN)
                {
                    MessageBox.Show("Parameter Mapping Error: Cannot map output to input!", "Parameter Mapping Error",
                                    MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else
                {
                    this.current_input_mapping.Add(this.MappedSourceParameter, _target_parameter);
                }
            }
            else if (_target_parameter.Propagation == InfoFlow.MIXED || _target_parameter.Propagation == InfoFlow.OUPUT)
            {
                if (this.current_output_mapping.ContainsKey(this.MappedSourceParameter) ||
                    this.current_output_mapping.ContainsValue(_target_parameter))
                {
                    MessageBox.Show("Parameter Mapping Error: Cannot map the same parameter twice!", "Parameter Mapping Error",
                                    MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else if (this.MappedSourceParameter.Propagation != InfoFlow.MIXED && this.MappedSourceParameter.Propagation != InfoFlow.OUPUT)
                {
                    MessageBox.Show("Parameter Mapping Error: Cannot map input to output!", "Parameter Mapping Error",
                                    MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else
                {
                    this.current_output_mapping.Add(this.MappedSourceParameter, _target_parameter);
                }
            }

            this.MappedSourceParameter = null;
        }
        void tv_comp_calc_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            // adapt display
            DependencyObject selObj = TreeViewQuery.GetSelectedTreeViewItem(this.tv_comp_calc);
            TreeViewItem     tvi    = selObj as TreeViewItem;

            if (tvi != null)
            {
                this.tracking_target = tvi.TransformToAncestor(this.tv_comp_calc).Transform(new Point(0, 0));
                if (this.IsMapping)
                {
                    this.UpdateMappingTrackingDisplay();
                }
            }

            // react to selection
            if (sender == null || e == null)
            {
                return;
            }
            TreeView tv = sender as TreeView;

            if (tv == null)
            {
                return;
            }

            object selection = tv.SelectedItem;

            if (selection == null)
            {
                return;
            }

            ParameterStructure.Parameter.Parameter selected_p = selection as ParameterStructure.Parameter.Parameter;
            if (selected_p == null)
            {
                return;
            }

            if (this.IsMapping && this.SelectedMappingSource)
            {
                this.CreateP2PMapping(selected_p);
                this.IsMapping             = false;
                this.SelectedMappingSource = false;
                this.UpdateMappingTrackingDisplay();
                this.UpdateButtons();
            }
        }
        void tv_comp_data_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            // adapt display
            DependencyObject selObj = TreeViewQuery.GetSelectedTreeViewItem(this.tv_comp_data);
            TreeViewItem     tvi    = selObj as TreeViewItem;

            if (tvi != null)
            {
                this.tracking_source = tvi.TransformToAncestor(this.tv_comp_data).Transform(new Point(0, 0));
                this.UpdateMappingTrackingDisplay();
            }

            // handle selection
            if (sender == null || e == null)
            {
                return;
            }
            TreeView tv = sender as TreeView;

            if (tv == null)
            {
                return;
            }

            object selection = tv.SelectedItem;

            if (selection == null)
            {
                this.UpdateButtons();
                return;
            }

            ParameterStructure.Parameter.Parameter selected_p = selection as ParameterStructure.Parameter.Parameter;
            if (selected_p != null)
            {
                if (this.IsMapping)
                {
                    this.MappedSourceParameter = selected_p;
                }
                this.UpdateButtons(selected_p);
            }
            else
            {
                this.IsMapping             = false;
                this.SelectedMappingSource = false;
                this.UpdateMappingTrackingDisplay();
                this.UpdateButtons();
            }
        }
        private void UpdateButtons(ParameterStructure.Parameter.Parameter _source_param_selected = null)
        {
            this.tbtn_get_data.IsEnabled = (!this.IsPickingCompCalculator && !this.IsMapping);
            this.tbtn_get_data.IsChecked = this.IsPickingCompData;

            this.tbtn_get_calc.IsEnabled = (!this.IsPickingCompData && !this.IsMapping);
            this.tbtn_get_calc.IsChecked = this.IsPickingCompCalculator;

            this.tbtn_map_manual.IsEnabled = (!this.IsPickingCompData && !this.IsPickingCompCalculator);
            this.tbtn_map_manual.IsChecked = this.IsMapping;

            if (_source_param_selected != null)
            {
                this.btn_P2Pmap_delete.IsEnabled = (this.current_input_mapping.ContainsKey(_source_param_selected) || this.current_output_mapping.ContainsKey(_source_param_selected));
            }
            else
            {
                this.btn_P2Pmap_delete.IsEnabled = false;
            }
        }
        private void TogglePHighlight()
        {
            ParameterStructure.Parameter.Parameter selected_p = this.tv_comp_calc.SelectedItem as ParameterStructure.Parameter.Parameter;
            if (selected_p == null)
            {
                return;
            }

            TreeViewItemForMapping container_selected = TreeViewQuery.ContainerFromItem(this.tv_comp_calc, selected_p) as TreeViewItemForMapping;

            if (container_selected != null && container_selected.IsVisible)
            {
                container_selected.IsMarkingInitiator = !container_selected.IsMarkingInitiator;

                if (container_selected.IsMarkingInitiator)
                {
                    // show all visible containers holding input parameters
                    List <ParameterStructure.Parameter.Parameter> input_involved = this.CompCalculator.GetInputParamsInvolvedInTheCalculationOf(selected_p);
                    foreach (ParameterStructure.Parameter.Parameter p in input_involved)
                    {
                        TreeViewItemForMapping container_p = TreeViewQuery.ContainerFromItem(this.tv_comp_calc, p) as TreeViewItemForMapping;
                        if (container_p != null && container_p.IsVisible)
                        {
                            container_p.IsMarked = true;
                        }
                    }
                }
                else
                {
                    // remove all markings
                    if (this.tv_comp_calc != null)
                    {
                        this.tv_comp_calc.PropagateMarkingToItems(false);
                    }
                }
            }
        }
        private void eh_MouseEnter(object sender, MouseEventArgs e)
        {
            TreeViewItemForMapping tvi = sender as TreeViewItemForMapping;

            // header highlighting preparation
            if (tvi != null)
            {
                ParameterStructure.Parameter.Parameter p  = tvi.Header as ParameterStructure.Parameter.Parameter;
                ParameterStructure.Component.Component c  = tvi.Header as ParameterStructure.Component.Component;
                WebServiceConnections.TypeNode         tn = tvi.Header as WebServiceConnections.TypeNode;
                if (p != null)
                {
                    // TODO
                }
                else if (c != null)
                {
                    // TODO
                }
                else if (tn != null)
                {
                    // TODO
                }
            }
        }