aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectListBox.cs
blob: 603cf07026f7357f0702b2b496566bc626602e0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace Tango.SharedUI.Controls
{
    public class MultiSelectListBox : ListBox
    {
        public IList SelectedItemsList
        {
            get { return (IList)GetValue(SelectedItemsListProperty); }
            set { SetValue(SelectedItemsListProperty, value); }
        }

        public static readonly DependencyProperty SelectedItemsListProperty =
            DependencyProperty.Register(nameof(SelectedItemsList), typeof(IList), typeof(MultiSelectListBox), new PropertyMetadata(null));

        public MultiSelectListBox() { }

        protected override void OnSelectionChanged(SelectionChangedEventArgs e)
        {
            base.OnSelectionChanged(e);

            if (SelectedItemsList != null)
            {
                SelectedItemsList.Clear();

                foreach (var item in SelectedItems)
                {
                    SelectedItemsList.Add(item);
                }
            }
        }
    }
}
} retval = {% endif -%} {%- if fun.constructor -%}{{fun.clss}} obj = {% endif -%} {%- if fun.clss and not fun.constructor -%}inst.{%- else -%} cv:: {%- endif -%} {{fun.name}}( {#- ----------- Required ------------- -#} {%- for arg in fun.req -%} {%- if arg.ref == '*' -%}&{%- endif -%} {{arg.name}} {%- if not loop.last %}, {% endif %} {% endfor %} {#- ----------- Optional ------------- -#} {% if fun.req and fun.opt %}, {% endif %} {%- for opt in fun.opt -%} {%- if opt.ref == '*' -%}&{%- endif -%} {{opt.name}} {%- if not loop.last -%}, {% endif %} {%- endfor -%} ); {%- endmacro %} /* * composeMatlab * compose a Matlab function call * This macro takes as input a Method object and composes * a Matlab function call by inspecting the types and argument names */ {% macro composeMatlab(fun) %} {# ----------- Return type ------------- #} {%- if fun|noutputs > 1 -%}[{% endif -%} {%- if not fun.rtp|void -%}LVALUE{% endif -%} {%- if not fun.rtp|void and fun|noutputs > 1 -%},{% endif -%} {# ------------- Outputs ------------- -#} {%- for arg in fun.req|outputs + fun.opt|outputs -%} {{arg.name}} {%- if arg.I -%}_out{%- endif -%} {%- if not loop.last %}, {% endif %} {% endfor %} {%- if fun|noutputs > 1 -%}]{% endif -%} {%- if fun|noutputs %} = {% endif -%} cv.{{fun.name}}( {#- ------------ Inputs -------------- -#} {%- for arg in fun.req|inputs + fun.opt|inputs -%} {{arg.name}} {%- if arg.O -%}_in{%- endif -%} {%- if not loop.last %}, {% endif -%} {% endfor -%} ); {%- endmacro %} /* * composeVariant * compose a variant call for the ArgumentParser */ {% macro composeVariant(fun) %} addVariant("{{ fun.name }}", {{ fun.req|inputs|length }}, {{ fun.opt|inputs|length }} {%- if fun.opt|inputs|length %}, {% endif -%} {%- for arg in fun.opt|inputs -%} "{{arg.name}}" {%- if not loop.last %}, {% endif -%} {% endfor -%} ) {%- endmacro %} /* * composeWithExceptionHandler * compose a function call wrapped in exception traps * This macro takes an input a Method object and composes a function * call through the compose() macro, then wraps the return in traps * for cv::Exceptions, std::exceptions, and all generic exceptions * and returns a useful error message to the Matlab interpreter */ {%- macro composeWithExceptionHandler(fun) -%} // call the opencv function // [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn); try { {{ compose(fun) }} } catch(cv::Exception& e) { error(std::string("cv::exception caught: ").append(e.what()).c_str()); } catch(std::exception& e) { error(std::string("std::exception caught: ").append(e.what()).c_str()); } catch(...) { error("Uncaught exception occurred in {{fun.name}}"); } {%- endmacro %} /* * handleInputs * unpack input arguments from the Bridge * Given an input Bridge object, this unpacks the object from the Bridge and * casts them into the correct type */ {%- macro handleInputs(fun) %} {% if fun|ninputs or (fun|noutputs and not fun.constructor) %} // unpack the arguments {# ----------- Inputs ------------- #} {% for arg in fun.req|inputs %} {{arg.tp}} {{arg.name}} = inputs[{{ loop.index0 }}].to{{arg.tp|toUpperCamelCase}}(); {% endfor %} {% for opt in fun.opt|inputs %} {{opt.tp}} {{opt.name}} = inputs[{{loop.index0 + fun.req|inputs|length}}].empty() ? ({{opt.tp}}) {% if opt.ref == '*' -%} {{opt.tp}}() {%- else -%} {{opt.default}} {%- endif %} : inputs[{{loop.index0 + fun.req|inputs|length}}].to{{opt.tp|toUpperCamelCase}}(); {% endfor %} {# ----------- Outputs ------------ #} {% for arg in fun.req|only|outputs %} {{arg.tp}} {{arg.name}}; {% endfor %} {% for opt in fun.opt|only|outputs %} {{opt.tp}} {{opt.name}}; {% endfor %} {% if not fun.rtp|void and not fun.constructor %} {{fun.rtp}} retval; {% endif %} {% endif %} {%- endmacro %} /* * handleOutputs * pack outputs into the bridge * Given a set of outputs, this methods assigns them into the bridge for * return to the calling method */ {%- macro handleOutputs(fun) %} {% if fun|noutputs %} // assign the outputs into the bridge {% if not fun.rtp|void and not fun.constructor %} outputs[0] = retval; {% endif %} {% for arg in fun.req|outputs %} outputs[{{loop.index0 + fun.rtp|void|not}}] = {{arg.name}}; {% endfor %} {% for opt in fun.opt|outputs %} outputs[{{loop.index0 + fun.rtp|void|not + fun.req|outputs|length}}] = {{opt.name}}; {% endfor %} {% endif %} {%- endmacro %}