示例#1
0
        private IConfiguration NewObject(string classType, string caption, int height)
        {
            EditObject     obj;
            IConfiguration config = null;

            try
            {
                ConfigurationPanel.EditObjectButton.Text = caption;

                Assembly a = Assembly.GetAssembly(this.GetType());

                object[] args = new object[1];
                args[0] = SqlConnectionControl.ServiceBroker;
                //Create a new instance of class type stored in classType.
                config = (IConfiguration)a.CreateInstance
                             (classType, true, BindingFlags.CreateInstance, null, args,
                             System.Globalization.CultureInfo.CurrentCulture, null);

                obj = ConfigurationPanel.AddObject("(New)", config);
                obj.Expand(height);
                obj.ButtonVisible = false;
            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }

            return(config);
        }
示例#2
0
        private void ResetFormLayout()
        {
            lbPantallaPrincipal.Text = PantallaPrincipal;

            ConfigControl.BackColor = Color.White;
            TermsControl.BackColor  = Color.White;
            SurveyControl.BackColor = Color.White;
            DashControl.BackColor   = Color.White;

            ConfigControl.ForeColor = Color.DarkRed;
            TermsControl.ForeColor  = Color.DarkRed;
            SurveyControl.ForeColor = Color.DarkRed;
            DashControl.ForeColor   = Color.DarkRed;

            SecondNavBack.BackColor = Color.DarkRed;

            //Hide Panels
            ConfigurationPanel.Hide();
            TermsPanel.Hide();

            //Show Dashboard


            //Other
            label1.Text = "";
            ReportBox.Rows.Clear();
            results.Text           = "";
            ActivateFilter.Checked = false;
        }
示例#3
0
 public ParameterizedConfigWindow([NotNull] string title, [NotNull] IEnumerable <IDescriptor> descriptors,
                                  IReadonlyContext context = null, IParameterPresentAdapter adapter = null)
 {
     InitializeComponent();
     ConfigurationPanel.SetDescriptors(adapter, descriptors);
     ConfigurationPanel.Context = context ?? EmptyContext.Instance;
     Title = title;
 }
示例#4
0
        public MainForm() : base("CDI检测机系统", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString())
        {
            InitializeComponent();
            //Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            ClassCommonSetting.ProgramLog(LogFile.Level.Info, "Main", "Run version: " + Version);
            //初始化硬件
            SplashProcessInfo = "初始化硬件...";
            HardwarePool.SystemHardware.instance.Init();
            HardwarePool.SystemHardware.instance.Open();
            SerialProtocalCollection.instance.ConnectProtocol();
            SplashProcessInfo = "加载参数,打开CDIVision...";
            ClassCommonSetting.CommonInit();
            this.LogOutTime = GetLogOutTime(ClassCommonSetting.SysParam.LogOutTime);

            //初始化工作区域
            SplashProcessInfo = "初始化工作区域...";
            zones             = ClassWorkZones.Instance;
            zones.AllZoneInit();
            SplashProcessInfo = "初始化工作流程...";
            workflow          = ClassWorkFlow.Instance;
            workflow.WorkFlowInit();
            //初始化主界面
            SplashProcessInfo = "初始化界面...";
            auto        = AutoPanel.Instance;
            setting     = new ConfigurationPanel();
            manual      = new ManualOperationPanel();
            product     = new ProductPanel();
            calibration = new CalibrationPanel();
            monitor     = new MonitorPanel();
            AddInterface(PanelType.AutoFace, auto);
            AddInterface(PanelType.SettingFace, setting);
            AddInterface(PanelType.ManualFace, manual);
            AddInterface(PanelType.ProductFace, product);
            AddInterface(PanelType.DebugFace, calibration);
            AddInterface(PanelType.MonitorFace, monitor);
            ClassCommonSetting.SysParam.AddParaInterface(product);
            ClassCommonSetting.SysParam.CurrentProductParam.SetDataToInterface(product);
            ClassCommonSetting.SysParam.CurrentProductParam.AddParaInterface(calibration);

            zones.SPC.AddGUI(auto);
            zones.SPC.AddGUI(monitor);

            //事件挂钩
            CommonFunction.SysPublisher.subscribeMeToSystemEvents(zones);
            CommonFunction.SysPublisher.subscribeMeToSystemEvents(workflow);
            zones.WorkZone外框架.HookErrorEvent();
            auto.HookErrorEvent();
            workflow.TimeUsage.AddTimeUsageGUI(auto);
            zones.AddTimeUsage(auto);
            ClassCommonSetting.SocketToAOI.subscribeMeToResponseEvents(zones.WorkZone尺寸测量);
            HookErrorEvent();
            CommonFunction.SysPublisher.subscribeMeToSystemEvents(this);
            this.UserLoggedIn     += MainForm_UserLoggedIn1;
            this.UserLoggedOut    += MainForm_UserLoggedOut1;
            product.SaveParaEvent += Product_SaveParaEvent;
            //发送事件
            CommonFunction.SysPublisher.notifyProductChangeEventSubscribers(null, new StateEventArgs(ClassCommonSetting.SysParam.CurrentProduct, ""));
        }
示例#5
0
        private void NewButton_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            ConfigurationPanel.RemoveAllObjects();
            ConfigurationPanel.SetStripButtonState(ObjectsSplitPanel.operations.New);
            int height = 250;

            this.NewObject(e.ClickedItem.Tag.ToString(), e.ClickedItem.Text, height);

            this.TaskTabControl.SelectTab(ConfigurationTabPageName);
        }
示例#6
0
        private void DisplayWindow()
        {
            if (_window == null || !_window.Visible)
            {
                _window = _container.GetInstance <ConfigurationPanel>();
            }

            _window.Show();
            _window.Closed += (sender, args) => _window = null;
        }
示例#7
0
        private void DestroyDependencies()
        {
            LocaleManager.eventUIComponentLocaleChanged -= LocaleManager_eventUIComponentLocaleChanged;

            _configurationService    = null;
            _languageResourceService = null;

            _configuration    = null;
            _languageResource = null;

            _configurationPanel = null;
        }
示例#8
0
        private Panel GetConfigPanel(Type config_type, object config_instance, ConfigurationHolderAttribute class_holder)
        {
            if (m_configuration_region_dict.TryGetValue(config_instance, out var region))
            {
                return(region.Panel);
            }

            region = new ConfigurationPanel(config_type, config_instance, class_holder);
            if (region.Panel.Children.Count != 0)
            {
                m_configuration_region_dict.Add(config_instance, region);
            }
            return(region.Panel);
        }
示例#9
0
        public async Task OnTripEstimateTripCost()
        {
            Trip trip = new Trip
            {
                PassengerCount = TripConfiguration.PassengerCount,
                PaymentType    = TripConfiguration.paymentType,
                TripDistance   = TripConfiguration.TripDistance,
                VendorId       = TripConfiguration.vendor,
                RateCode       = TripConfiguration.rateCode.ToString()
            };

            totalPrice = TripCostService.PredictFare(trip).FareAmount;
            await ConfigurationPanel.HideAsync();
        }
示例#10
0
        private void OptionsButton_Click(object sender, EventArgs e)
        {
            EditObject obj;

            ConfigurationPanel.RemoveAllObjects();

            ConfigurationPanel.EditObjectButton.Text = "Application Configuration";

            obj = ConfigurationPanel.AddObject("Application Configuration",
                                               SqlConnectionControl.OptionsConfiguration);
            obj.ButtonVisible = false;

            ConfigurationPanel.ActiveEditObject = obj;

            ConfigurationPanel.SetStripButtonState(ObjectsSplitPanel.operations.New);
            this.TaskTabControl.SelectTab(ConfigurationTabPageName);
        }
示例#11
0
        public void OnSettingsUI(UIHelperBase helper)
        {
            var modFullTitle = new ModFullTitle(Name, Version);

            _configurationPanel = new ConfigurationPanel(
                helper,
                modFullTitle,
                _configuration,
                _languageResource
                );

            _configurationPanel.Initialize();
            if (_mainPanel != null)
            {
                _configurationPanel.MainPanel = _mainPanel;
            }
        }
        private void Confirm()
        {
            var invalidParams = ConfigurationPanel.GetInvalidParams().ToArray();

            if (invalidParams.Any())
            {
                var stringBuilder = new StringBuilder();
                stringBuilder.Append("The following parameters are invalid");
                foreach (var param in invalidParams)
                {
                    stringBuilder.Append("\n - ").Append(param.Name);
                }
                MessageBox.Show(stringBuilder.ToString());
                return;
            }
            DialogResult = true;
            Close();
        }
示例#13
0
        /**
         * CONFIGURAITON PANEL  ---- START
         * */
        private async void ConfigControl_Click(object sender, EventArgs e)
        {
            loadingIcon.Visible = true;

            ResetFormLayout();
            ConfigurationPanel.Show();
            //---
            ConfigControl.BackColor  = Color.DarkRed;
            ConfigControl.ForeColor  = Color.WhiteSmoke;
            lbPantallaPrincipal.Text = "Configuraciones Globales";
            label1.Text = "Configuraciones";

            await Task.Run(() => {
                //--
                List <Configurations> configs = _context.Configurations.ToList();
                GetConfigInfo(configs);
                //---
                if (!ActivateSurvey.Checked)
                {
                    SurveyLink.Enabled = false;
                    OpenStudentSurveyFullscreen.Enabled = false;
                }
                else
                {
                    SurveyLink.Enabled = true;
                    OpenStudentSurveyFullscreen.Enabled = true;
                }
                if (!ActivateSurveyTeacher.Checked)
                {
                    SurveyLinkTeacher.Enabled           = false;
                    OpenTeacherSurveyFullscreen.Enabled = false;
                }
                else
                {
                    SurveyLinkTeacher.Enabled           = true;
                    OpenTeacherSurveyFullscreen.Enabled = true;
                }
            });

            loadingIcon.Visible = false;
        }
示例#14
0
        //Show the object selected in the ObjectsTree
        private void ObjectsTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                ConfigurationPanel.RemoveAllObjects();

                //Show Objects
                if (e.Node.Tag != null)
                {
                    if (String.Equals(e.Node.Tag.ToString(),
                                      SqlConnectionControl.TreeNodeObjectType.ObjectNode.ToString()))
                    {
                        ConfigurationPanel.SetStripButtonState(ObjectsSplitPanel.operations.Show);
                        this.ShowObject(e.Node.Parent.Name, e.Node.Text, e.Node.Text);
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
        public static void Run()
        {
            // test config panel
            var bar = new Bar() { C = "sub" };
            var foo = new Foo() { C = "c", D = true, E = 2.0, F = 2, G = bar };
            var config = new ConfigurationPanel(foo);
            var copy = config.GetConfiguredObject() as Foo;
            if (!bar.HasEqualParameters(copy.G))
                throw new Exception("Sub-object comparison failed!");
            foo.G = copy.G = null;
            if (!foo.HasEqualParameters(copy))
                throw new Exception("Main object comparison failed!");
            var fprop = typeof(Foo).GetProperty("F");
            config.SetterFor(fprop)(200);
            if ((int)config.GetterFor(fprop)() != 200)
                throw new Exception("Getter or setter failed!");
            config.PropertyChanged += (args) =>
            {
                if (args.Property != fprop)
                    return;

                if ((int)args.Getter() > 150)
                    args.Setter((int)args.Getter() - 2);
            };
            config.SetterFor(fprop)(190);
            if ((int)config.GetterFor(fprop)() != 150)
                throw new Exception("PropertyChanged failed!");

            // test derived type panel
            var derivedConfig = new DerivedTypeConfigurationPanel(typeof(Interface), bar);
            if (!new Bar() { C = "sub" }.HasEqualParameters((Bar)derivedConfig.GetConfiguredObject()))
                throw new Exception("DerivedTypeConfigurationPanel failed!");
            var diffBar = new Bar() { C = "different" };
            derivedConfig.SetConfiguredObject(diffBar);
            if (!diffBar.HasEqualParameters((Bar)derivedConfig.GetConfiguredObject()))
                throw new Exception("SetConfiguredObject failed!");
        }
        private void BuildView(ClassificationScheme classificationScheme)
        {
            this.SuspendLayout();
            this.Text = classificationScheme.Settings.Name;
            var table = GUIUtils.CreateTable(new double[] { .33, .33, .33 }, Direction.Horizontal);

            // classifier
            var classifierSettings = new DerivedTypeConfigurationPanel(typeof(IClassifier), classificationScheme.Classifier);
            this.getClassifier = () => (IClassifier)classifierSettings.GetConfiguredObject();
            table.Controls.Add(classifierSettings, 0, 0);

            // general settings
            var generalSettings = new ConfigurationPanel(classificationScheme.Settings);
            table.Controls.Add(generalSettings, 1, 0);

            // bin selection
            var panel = new Panel() { Dock = DockStyle.Fill };

            var binList = new CheckedListBox() { Dock = DockStyle.Fill, CheckOnClick = true };
            binList.AddContextMenu();
            this.ToolTip.SetToolTip(binList, "Select which time bins from each trial will be used to train the classifier");
            var timeBins = GeneralClassifierSettings.MAX_BINS
                .CountTo()
                .Select(i => new TimeBin(i) { Checked = classificationScheme.Settings.SelectedBins.Contains(i) })
                .ToIArray();
            binList.ItemCheck += (sender, args) => ((TimeBin)binList.Items[args.Index]).Checked = (args.NewValue == CheckState.Checked);
            Action<int> refreshBinList = (binWidth) =>
            {
                // ensure the right number of items
                int binCount = GeneralClassifierSettings.GetBinCount(binWidth);
                if (binList.Items.Count < binCount)
                    binList.Items.AddRange(timeBins.SubView(binList.Items.Count, binCount - binList.Items.Count).ToArray());
                else
                    for (int i = binList.Items.Count - 1; i >= binCount; i--)
                        binList.Items.RemoveAt(i);

                // ensure correct width and uncheck all
                TimeBin timeBin;
                for (int i = 0; i < binCount; i++)
                {
                    timeBin = (TimeBin)binList.Items[i];
                    timeBin.BinWidth = binWidth;
                    binList.SetItemChecked(i, timeBin.Checked);
                }

                binList.Invalidate();
            };
            refreshBinList(classificationScheme.Settings.BinWidthMillis);
            var binWidthProp = typeof(GeneralClassifierSettings).GetProperty("BinWidthMillis");
            var nameProp = typeof(GeneralClassifierSettings).GetProperty("Name");
            if (binWidthProp == null || nameProp == null)
                throw new Exception("Failed to find properties!");
            generalSettings.PropertyChanged += args =>
            {
                if (args.Property.Equals(binWidthProp))
                    refreshBinList((int)args.Getter());
                else if (args.Property.Equals(nameProp))
                    this.Text = args.Getter().ToString();
            };
            this.getSettings = () =>
            {
                var settings = (GeneralClassifierSettings)generalSettings.GetConfiguredObject();
                settings.SelectedBins = binList.CheckedIndices.Cast<int>().ToIArray();

                return settings;
            };
            panel.Controls.Add(binList);
            panel.Controls.Add("Time Bins".ToLabel());
            var saveButton = GUIUtils.CreateFlatButton("Save", (b) =>
            {
                this.saveDialog.FileName = this.Text;
                if (this.saveDialog.ShowDialog() != DialogResult.OK)
                    return;

                bool saved = this.ClassificationScheme.TrySerializeToFile(this.saveDialog.FileName);
                GUIUtils.Alert((saved ? "Saved" : "Failed to save")
                    + " classifier info to " + this.saveDialog.FileName,
                    (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error));

                string directory = Path.GetDirectoryName(this.saveDialog.FileName);
                if (Directory.Exists(directory))
                    this.saveDialog.InitialDirectory = directory;
            });
            saveButton.Dock = DockStyle.Bottom;
            panel.Controls.Add(saveButton);
            table.Controls.Add(panel, 2, 0);

            this.Controls.Add(table);
            this.ResumeLayout(false);
        }
示例#17
0
 /// <summary>
 /// Constructeur de ServerClass
 /// </summary>
 /// <param name="form"></param>
 public ServerClass(ConfigurationPanel form)
 {
     this.form = form;
 }
        private void BuildView()
        {
            this.SuspendLayout();
            this.Text = this.StimulusClass.Settings.Name;
            var cols = GUIUtils.CreateTable(new double[] { .33, .33, .33 }, Direction.Horizontal);

            // settings
            var settingsConfig = new ConfigurationPanel(this.StimulusClass.Settings) { Dock = DockStyle.Fill };

            // image panel
            var imagePanel = new ImagePanel() { Dock = DockStyle.Fill };

            // dropdown
            var dropDown = new ComboBox() { DropDownStyle = ComboBoxStyle.DropDownList, Dock = DockStyle.Bottom };
            dropDown.MouseWheel += (sender, args) => ((HandledMouseEventArgs)args).Handled = true;
            dropDown.Items.Add(new DisplayPointer(() => this.StimulusClass.Settings.Answer1, true));
            dropDown.Items.Add(new DisplayPointer(() => this.StimulusClass.Settings.Answer2, false));
            dropDown.Items.Add(new DisplayPointer(GUIUtils.Strings.UNCLASSIFIED, null));

            // source folder
            var sourceFolderLink = new LinkLabel() { AutoSize = true, Text = Path.GetFileName(this.StimulusClass.SourceFolder), Dock = DockStyle.Top };
            sourceFolderLink.Click += (sender, args) =>
            {
                try { System.Diagnostics.Process.Start("explorer.exe", this.StimulusClass.SourceFolder); }
                catch (Exception) { GUIUtils.Alert("Failed to open " + this.StimulusClass.SourceFolder); }
            };
            this.ToolTip.SetToolTip(sourceFolderLink, "Open " + this.StimulusClass.SourceFolder);

            // image list
            var imageList = new CheckedListBox() { Dock = DockStyle.Fill };
            imageList.AddContextMenu();
            foreach (var stimulus in this.StimulusClass.Stimuli)
                imageList.Items.Add(new StimulusItem(this.StimulusClass, stimulus), stimulus.Used);
            EventHandler setImage = (sender, args) =>
            {
                if (imageList.Items.Count > 0)
                {
                    var stimulus = ((StimulusItem)(imageList.SelectedItem ?? imageList.Items[0])).Stimulus;
                    imagePanel.ImagePath = stimulus.PathOrText;
                    dropDown.Visible = true;
                    switch (stimulus.Subclass)
                    {
                        case true: dropDown.SelectedIndex = 0; break;
                        case false: dropDown.SelectedIndex = 1; break;
                        case null: dropDown.SelectedIndex = 2; break;
                    }
                }
                else
                {
                    imagePanel.ImagePath = null;
                    dropDown.Visible = false;
                }
            };
            setImage(imageList, EventArgs.Empty); // first set
            imageList.SelectedIndexChanged += setImage;
            settingsConfig.PropertyChanged += args =>
            {
                this.StimulusClass.Settings.SetProperty(args.Property, args.Getter());
                this.Text = this.StimulusClass.Settings.Name;
                imageList.Invalidate();

                // force a refresh
                int selectedIndex = dropDown.SelectedIndex;
                var items = dropDown.Items.Cast<DisplayPointer>().ToArray();
                dropDown.Items.Clear();
                dropDown.Items.AddRange(items);
                dropDown.SelectedIndex = selectedIndex;
            };
            imageList.ItemCheck += (sender, args) => ((StimulusItem)imageList.Items[args.Index]).Stimulus.Used = (args.NewValue == CheckState.Checked);
            dropDown.SelectedIndexChanged += (sender, args) =>
            {
                ((StimulusItem)(imageList.SelectedItem ?? imageList.Items[0])).Stimulus.Subclass =
                    (bool?)((DisplayPointer)dropDown.SelectedItem).Key;
                imageList.Invalidate();
            };
            this.getSelectedStimulus = () => imageList.SelectedItem == null ? null : ((StimulusItem)imageList.SelectedItem).Stimulus;

            // selection info label
            var selectionInfoLabel = new Label() { Dock = DockStyle.Bottom, AutoSize = true };
            PaintEventHandler updateSelectionInfoLabel = (sender, args) =>
            {
                var items = imageList.Items.Cast<StimulusItem>();
                selectionInfoLabel.Text = string.Format("{0}/{1} selected", items.Count(s => s.Stimulus.Used), imageList.Items.Count);
                if (!string.IsNullOrWhiteSpace(this.StimulusClass.Settings.Answer1)
                    || !string.IsNullOrWhiteSpace(this.StimulusClass.Settings.Answer2))
                    selectionInfoLabel.Text += string.Format(" ({0}/{1} {2}, {3}/{4} {5}, {6}/{7} {8})", items.Count(s => s.Stimulus.Subclass == true && s.Stimulus.Used),
                        items.Count(s => s.Stimulus.Subclass == true),
                        this.StimulusClass.Settings.Answer1,
                        items.Count(s => s.Stimulus.Subclass == false && s.Stimulus.Used),
                        items.Count(s => s.Stimulus.Subclass == false),
                        this.StimulusClass.Settings.Answer2,
                        items.Count(s => s.Stimulus.Subclass == null && s.Stimulus.Used),
                        items.Count(s => s.Stimulus.Subclass == null),
                        GUIUtils.Strings.UNCLASSIFIED);
            };
            imageList.Paint += updateSelectionInfoLabel;
            updateSelectionInfoLabel(null, null);

            // button table
            var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Bottom,
            GUIUtils.CreateFlatButton("Classify", b =>
            {
                MainForm.Instance.Animate(new StimulusClassSetupProvider(this.StimulusClass), this.Invalidate);
            }, this.ToolTip, "Launch a tool to quickly answer this class's question for all stimuli"),
            GUIUtils.CreateFlatButton("Refresh", b =>
            {
                this.StimulusClass.RefreshStimuli();
                this.Invalidate();
            }, this.ToolTip, "Reload the stimuli from the file system"),
            GUIUtils.CreateFlatButton("Save", b =>
            {
                bool saved = this.StimulusClass.TrySave();
                GUIUtils.Alert((saved ? "Saved" : "Failed to save")
                    + " stimulus class info to " + this.StimulusClass.SavePath,
                    (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error));
            }, this.ToolTip, "Save configuration information to " + this.StimulusClass.SavePath));

            // add all controls
            Panel panel;

            // left column
            panel = new Panel() { Dock = DockStyle.Fill };
            panel.Controls.Add(settingsConfig);
            panel.Controls.Add(sourceFolderLink);
            panel.Controls.Add("Folder".ToLabel());
            panel.Controls.Add(buttonTable);
            cols.Controls.Add(panel, 0, 0);

            // middle column
            panel = new Panel() { Dock = DockStyle.Fill };
            panel.Controls.Add(imageList);
            panel.Controls.Add(selectionInfoLabel);
            panel.Controls.Add("Stimuli".ToLabel());
            cols.Controls.Add(panel, 1, 0);

            // right column
            panel = new Panel() { Dock = DockStyle.Fill };
            panel.Controls.Add(imagePanel);
            panel.Controls.Add(dropDown);
            cols.Controls.Add(panel, 2, 0);

            this.Controls.Add(cols);
            this.ResumeLayout(false);
        }
        private void BuildView()
        {
            this.SuspendLayout();
            var tabs = new CustomTabControl() { Dock = DockStyle.Fill };
            tabs.DisplayStyleProvider = new TabStyleVisualStudioProvider(tabs) { ShowTabCloser = true };
            tabs.TabClosing += (sender, args) => ((CustomTab)args.TabPage).RaiseClosingSafe(args);

            var startTab = new CustomTab() { Text = "Classifiers " }; // the ending space is necessary for some reason
            startTab.Closing += (sender, args) =>
            {
                args.Cancel = true;
                if (GUIUtils.IsUserSure("Reset classifiers?"))
                {
                    this.classifierTabs.Clear();
                    this.Controls.Remove(tabs);
                    tabs.Dispose();
                    this.BuildView();
                    this.OnSizeChanged(EventArgs.Empty);
                }
            };

            // classifier list
            var classifierList = new CheckedListBox() { Dock = DockStyle.Fill, CheckOnClick = true };
            classifierList.AddContextMenu();
            Action<ClassificationScheme> addClassifier = (scheme) =>
            {
                // get unique name if necessary
                string baseName = string.IsNullOrWhiteSpace(scheme.Settings.Name)
                    ? "new classifier"
                    : scheme.Settings.Name;
                if (!this.classifierTabs.Select(ct => ct.Text).Contains(baseName))
                    scheme.Settings.Name = baseName;
                else
                {
                    int i = 1;
                    while (this.classifierTabs
                        .Select(ct => ct.Text.ToLower())
                        .Contains(string.Format("{0} {1}", baseName, i)))
                        i++;
                    scheme.Settings.Name = string.Format("{0} {1}", baseName, i);
                }

                // create the tab
                var classifierTab = new ClassificationSchemeTab(scheme);
                classifierTab.TextChanged += (sender, args) => classifierList.Invalidate();
                classifierTab.Closing += (sender, args) =>
                {
                    this.classifierTabs.Remove(classifierTab);
                    classifierList.Items.Remove(classifierTab);
                };

                this.classifierTabs.Add(classifierTab);
                tabs.TabPages.Add(classifierTab);
                classifierList.Items.Add(classifierTab, true);
            };
            this.getSelectedClassifiers = () => classifierList.CheckedItems.Cast<ClassificationSchemeTab>().Select(cst => cst.ClassificationScheme).ToIArray();

            // buttons
            var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Bottom,
            GUIUtils.CreateFlatButton("New", (b) =>
            {
                var classifier = classifierList.Items.Count > 0
                    ? ((ClassificationSchemeTab)(classifierList.SelectedItem ?? classifierList.Items[0])).ClassificationScheme
                    : new ClassificationScheme();

                classifier.Settings.Name = string.Empty;
                addClassifier(classifier);
            }, startTab.ToolTip, "Create a new classifier"),
            GUIUtils.CreateFlatButton("Load", (b) =>
            {
                if (this.openDialog.ShowDialog() != DialogResult.OK)
                    return;

                ClassificationScheme scheme;
                foreach (var path in this.openDialog.FileNames)
                {
                    if (Utils.TryDeserializeFile(this.openDialog.FileName, out scheme))
                        addClassifier(scheme);
                    else
                        GUIUtils.Alert("Failed to load classifier info from " + path, MessageBoxIcon.Error);
                }
            }, startTab.ToolTip, "Load a previously saved classifier settings file"));

            // artifact detection config
            var artifactDetectionPanel = new ConfigurationPanel(this.artifactDetection);
            artifactDetectionPanel.PropertyChanged += args => this.artifactDetection.SetProperty(args.Property, args.Getter());

            // artifact detection label
            var artifactDetectionLabel = new Label() { Dock = DockStyle.Bottom, TextAlign = ContentAlignment.MiddleCenter, Visible = false };
            IEnumerable<EEGDataEntry> empty = new EEGDataEntry[0], entries = empty;
            var listener = new EEGDataListener(GUIUtils.GUIInvoker,
                source => artifactDetectionLabel.Visible = true,
                data =>
                {
                    if (!this.artifactDetection.UseArtifactDetection)
                    {
                        artifactDetectionLabel.Visible = false;
                        entries = empty;
                        return;
                    }

                    artifactDetectionLabel.Visible = true;
                    entries = entries.Concat(data);
                    if (data.LastItem().TimeStamp - entries.First().TimeStamp >= 500)
                    {
                        if (this.artifactDetection.HasMotionArtifact(entries))
                        {
                            artifactDetectionLabel.Text = "Motion artifact detected!";
                            artifactDetectionLabel.BackColor = Color.Red;
                            artifactDetectionLabel.ForeColor = Color.White;
                            if (this.artifactDetection.Beep)
                                GUIUtils.GUIInvoker.BeginInvoke(SystemSounds.Beep.Play);
                        }
                        else
                        {
                            artifactDetectionLabel.Text = "No artifacts detected";
                            artifactDetectionLabel.BackColor = Color.Green;
                            artifactDetectionLabel.ForeColor = Color.Black;
                        }

                        entries = empty;
                    }
                },
                source => artifactDetectionLabel.Visible = false);
            // avoid using the gui invoker before the handle has been created
            this.HandleCreated += (sender, args) => EmotivDataSource.Instance.AddListener(listener);
            artifactDetectionLabel.Disposed += (sender, args) => { EmotivDataSource.Instance.RemoveListener(listener); listener.Dispose(); };

            // right half
            var rightPanel = new Panel() { Dock = DockStyle.Fill };
            rightPanel.Controls.Add(classifierList);
            rightPanel.Controls.Add(buttonTable);

            // left half
            var leftPanel = new Panel() { Dock = DockStyle.Fill };
            leftPanel.Controls.Add(artifactDetectionPanel);
            leftPanel.Controls.Add(artifactDetectionLabel);

            var cols = GUIUtils.CreateTable(new double[] { .5, .5 }, Direction.Horizontal);
            cols.Controls.Add(rightPanel, 0, 0);
            cols.Controls.Add(leftPanel, 1, 0);
            startTab.Controls.Add(cols);

            tabs.TabPages.Add(startTab);
            this.Controls.Add(tabs);
            this.ResumeLayout(false);
        }
示例#20
0
 public async Task ShowConfigurationPanel()
 {
     await ConfigurationPanel.ShowAsync();
 }
示例#21
0
 /// <summary>
 /// Constructeur de l'objet Client Class
 /// </summary>
 /// <param name="form"></param>
 public ClientClass(ConfigurationPanel form)
 {
     this.form       = form;
     items_bluetooth = new List <string>();
 }
示例#22
0
        public static void Run()
        {
            // test config panel
            var bar = new Bar()
            {
                C = "sub"
            };
            var foo = new Foo()
            {
                C = "c", D = true, E = 2.0, F = 2, G = bar
            };
            var config = new ConfigurationPanel(foo);
            var copy   = config.GetConfiguredObject() as Foo;

            if (!bar.HasEqualParameters(copy.G))
            {
                throw new Exception("Sub-object comparison failed!");
            }
            foo.G = copy.G = null;
            if (!foo.HasEqualParameters(copy))
            {
                throw new Exception("Main object comparison failed!");
            }
            var fprop = typeof(Foo).GetProperty("F");

            config.SetterFor(fprop)(200);
            if ((int)config.GetterFor(fprop)() != 200)
            {
                throw new Exception("Getter or setter failed!");
            }
            config.PropertyChanged += (args) =>
            {
                if (args.Property != fprop)
                {
                    return;
                }

                if ((int)args.Getter() > 150)
                {
                    args.Setter((int)args.Getter() - 2);
                }
            };
            config.SetterFor(fprop)(190);
            if ((int)config.GetterFor(fprop)() != 150)
            {
                throw new Exception("PropertyChanged failed!");
            }

            // test derived type panel
            var derivedConfig = new DerivedTypeConfigurationPanel(typeof(Interface), bar);

            if (!new Bar()
            {
                C = "sub"
            }.HasEqualParameters((Bar)derivedConfig.GetConfiguredObject()))
            {
                throw new Exception("DerivedTypeConfigurationPanel failed!");
            }
            var diffBar = new Bar()
            {
                C = "different"
            };

            derivedConfig.SetConfiguredObject(diffBar);
            if (!diffBar.HasEqualParameters((Bar)derivedConfig.GetConfiguredObject()))
            {
                throw new Exception("SetConfiguredObject failed!");
            }
        }