Exemple #1
0
        public bool Drop(IElementClipboardData data, bool insertAtBeginning)
        {
            if (CanDrop(data))
            {
                var elements = this.CreateElements(data);

                var index = insertAtBeginning ? 0 : Elements.Count;

                foreach (var element in elements)
                {
                    Elements.Insert(index++, element);
                }

                MarkDirty();

                SaveUndoState();

                //Make sure that the new items are selected.
                SelectionService.SelectNone();

                foreach (var selectable in elements)
                {
                    SelectionService.Select(selectable);
                }

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Selects <paramref name="selectable"/> and considers the Control/Shift buttons.
        /// </summary>
        /// <param name="selectionService"></param>
        /// <param name="selectable"></param>
        public static void SelectWithKeyboardModifiers(this ISelectionService selectionService, ISelectable selectable)
        {
            if (selectionService == null)
            {
                return;
            }

            if (selectable == null)
            {
                return;
            }

            //Determine if we're adding to the selection
            var isAddingToSelection = Keyboard.Modifiers == ModifierKeys.Control ||
                                      Keyboard.Modifiers == ModifierKeys.Shift;

            //See if this item is aready selected
            if (selectable.IsSelected)
            {
                //It is selected. Unselect it.
                selectionService.Unselect(selectable);
            }
            else
            {
                //Unless we're adding to the selection, unselect everything.
                if (!isAddingToSelection)
                {
                    selectionService.SelectNone();
                }

                //Select the current item.
                selectionService.Select(selectable);
            }
        }
Exemple #3
0
 public static void SelectRange <T>(this ISelectionService <T> service, IEnumerable <ISelectable> selectables) where T : ISelectable
 {
     foreach (var selectable in selectables)
     {
         service.Select((T)selectable);
     }
 }
Exemple #4
0
        private static void SelectBetween(this ISelectionService selectionService,
                                          ISelectable[] siblings,
                                          ISelectable start,
                                          ISelectable end)
        {
            //Select nothing
            selectionService.SelectNone();

            //Determine the start and stop
            var startIndex = siblings.IndexOf(s => s == start);
            var endIndex   = siblings.IndexOf(s => s == end);

            //If for some reason the siblings weren't found, bail
            if (startIndex == null || endIndex == null)
            {
                return;
            }

            //Always start from the "first" sibling
            var effectiveStart = Math.Min(startIndex.Value, endIndex.Value);
            var effectiveEnd   = Math.Max(startIndex.Value, endIndex.Value);

            //Mark them all as selected.
            for (int index = effectiveStart; index <= effectiveEnd; index++)
            {
                selectionService.Select(siblings[index]);
            }
        }
Exemple #5
0
 private void OnMouseDown()
 {
     if (EventSystem.current.IsPointerOverGameObject())
     {
         return;
     }
     m_SelectionService.Select(null);
 }
Exemple #6
0
        /// <summary>
        /// Selects <paramref name="selectable"/> and considers the Control/Shift buttons.
        /// </summary>
        /// <param name="selectionService"></param>
        /// <param name="selectable"></param>
        public static void SelectWithKeyboardModifiers(this ISelectionService selectionService, ISelectable selectable)
        {
            if (selectionService == null)
            {
                return;
            }

            if (selectable == null)
            {
                return;
            }

            switch (Keyboard.Modifiers)
            {
            case ModifierKeys.Control:

                if (selectable.IsSelected)
                {
                    selectionService.Unselect(selectable);
                }
                else
                {
                    selectionService.Select(selectable);
                }

                break;

            case ModifierKeys.Shift:

                selectionService.ShiftSelect(selectable);

                break;

            case ModifierKeys.None:

                selectionService.SelectNone();
                selectionService.Select(selectable);

                break;
            }
        }
 void Glass_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     //if this is already selected, we might want to move.
     if ((_selSvc.SelectionCount > 0 && _selSvc.GetSelection().Contains(this)))
     {
         StartMove(e);
     }
     else if (!_selSvc.GetSelection().Contains(this))
     {
         _selSvc.Select(new List <IDesignableControl> {
             this
         });
         StartMove(e);
     }
     e.Handled = true;
 }
        public static void RightClick(this ISelectionService selectionService, ISelectable selectable)
        {
            if (selectionService == null)
            {
                return;
            }

            if (selectable == null)
            {
                return;
            }
            if (!selectable.IsSelected)
            {
                selectionService.SelectNone();

                //Select the current item.
                selectionService.Select(selectable);
            }
        }
        static void Main(string[] args)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            PathService         pathService               = PathService.Instance;
            ISelectionService   selectionService          = RouletteService.Instance;
            ISelectionService   secondarySelectionService = TournamentService.Instance;
            PmxCrossoverService crossoverService          = PmxCrossoverService.Instance;

            Subject min = new Subject();
            int     minDitanceInIntance = 0;

            instances = pathService.RandomizeInstances(40);

            for (int i = 0; i < 100000; i++)
            {
                Random r = new Random();
                instances = (r.Next(100) > 97) ? selectionService.Select(instances) : secondarySelectionService.Select(instances);
                //instances = secondarySelectionService.Select(instances);
                //instances = selectionService.Select(instances);
                if (i < 80000)
                {
                    instances = crossoverService.CrossPopulation(instances, 80, 45);
                }
                else
                {
                    instances = crossoverService.CrossPopulation(instances, 90, 15);
                }
                minDitanceInIntance = instances.Min(x => x.Distance);
                if (min.Cities == null || min.Distance > minDitanceInIntance)
                {
                    min = instances.First(x => x.Distance == minDitanceInIntance);
                    Console.WriteLine($"Generacja: {i}, wynik: {min.Distance}");
                }
            }

            Console.WriteLine("Time elapsed: " + watch.Elapsed);

            pathService.SaveInstance(min);

            Console.ReadKey();
        }
Exemple #10
0
        public override void Initialize()
        {
            this.WhenAnyValue(vm => vm.SelectedIotHubInfo)
            .Do(selectedhub =>
            {
                deviceInfoSelectionService.Select(null);
                iotHubSelectionService.Select(selectedhub);
                if (selectedhub != null)
                {
                    settings.LastUsedIoTHub = selectedhub;
                }
            })
            .Subscribe()
            .AddDisposableTo(Disposables);


            if (settings.LastCheckedIoTHubs != null && settings.LastCheckedIoTHubs.Any())
            {
                IotHubInfo = settings.LastCheckedIoTHubs;

                if (settings.LastUsedIoTHub != null)
                {
                    SelectedIotHubInfo = settings.LastCheckedIoTHubs.Single(h => h.Name.Equals(settings.LastUsedIoTHub.Name));
                }
            }
            else
            {
                Observable.Return(Unit.Default)
                .SelectMany(_ => azureService.GetIoTHubs())
                .ObserveOnDispatcher()
                .Do(hubs => IotHubInfo = hubs)
                .LogAndRetryAfterDelay(Logger, TimeSpan.FromSeconds(1),
                                       "Error while retrieving iot hubs information")
                .Subscribe()
                .AddDisposableTo(Disposables);
            }

            ReloadCommand = ReactiveCommand.CreateFromTask(Reload)
                            .AddDisposableTo(Disposables);
        }
        public override void Initialize()
        {
            AddNewDeviceCommand = ReactiveCommand.CreateFromTask(CreateNewDevice, ioTHubInfoSelectionService.SelectedObject.Select(iotHub => iotHub != null))
                                  .AddDisposableTo(Disposables);
            DeleteSelectedDeviceCommand = ReactiveCommand.CreateFromTask(DeleteSelectedDevice, ioTDeviceSelectionService.SelectedObject.Select(ioTDeviceInfos => ioTDeviceInfos != null))
                                          .AddDisposableTo(Disposables);

            this.WhenAnyValue(vm => vm.SelectedIoTDeviceInfo)
            .Subscribe(x => ioTDeviceSelectionService.Select(x))
            .AddDisposableTo(Disposables);

            ioTHubInfoSelectionService.SelectedObject
            .Where(iotHub => iotHub != null)
            .ObserveOnDispatcher()
            .Do(_ => Loading = true)
            .Do(devices => IoTDeviceInfos = new IoTDeviceInfo[] {})
            .Do(i => this.hubName         = i.Name)
            .Subscribe()
            .AddDisposableTo(Disposables);

            ioTHubInfoSelectionService.SelectedObject
            .Where(iotHub => iotHub != null)
            .SelectMany(iothub => azureService.GetIoTDevices(iothub.Name))
            .ObserveOnDispatcher()
            .Do(devices => IoTDeviceInfos = devices)
            .Do(_ => Loading = false)
            .LogAndRetryAfterDelay(Logger, TimeSpan.FromSeconds(1), "Error while retrieving devices information")
            .Subscribe()
            .AddDisposableTo(Disposables);

            ReloadCommand = ReactiveCommand.CreateFromTask(Reload, ioTHubInfoSelectionService.SelectedObject.Select(iotHub => iotHub != null))
                            .AddDisposableTo(Disposables);

            MonitorDevice = ReactiveCommand.CreateFromTask <IoTDeviceInfo, Unit>(OpenMonitorDevice)
                            .AddDisposableTo(Disposables);
        }
Exemple #12
0
        private static void ShiftSelect(this ISelectionService selectionService, ISelectable selectable)
        {
            var siblings = selectable.GetSiblings();

            //See if there are any non sibinglings that need to be
            var nonSiblingSelected = selectionService.GetSelected()
                                     .Where(s => !siblings.Contains(s))
                                     .ToArray();

            foreach (var toUnselect in nonSiblingSelected)
            {
                selectionService.Unselect(toUnselect);
            }

            //Now, only existing siblings should be selected
            var selected = selectionService.GetSelected();

            //If there are none selected, then select all of the sibings up to this one
            if (!selected.Any())
            {
                foreach (var sibling in siblings)
                {
                    selectionService.Select(sibling);

                    if (sibling == selectable)
                    {
                        break;
                    }
                }
            }
            else
            {
                //Do a range selection
                selectionService.SelectBetween(siblings, selectable, selected.LastOrDefault());
            }
        }
Exemple #13
0
        /// <summary>
        /// Ensures that the item is selected (no changes are made if the item is already selected).
        /// </summary>
        /// <param name="selectionService"></param>
        /// <param name="selectable"></param>
        public static void EnsureSelected(this ISelectionService selectionService, ISelectable selectable)
        {
            if (selectionService == null)
            {
                return;
            }

            if (selectable == null)
            {
                return;
            }

            if (selectable.IsSelected)
            {
                return;
            }

            selectionService.SelectWithKeyboardModifiers(selectable);

            if (!selectable.IsSelected)
            {
                selectionService.Select(selectable);
            }
        }
Exemple #14
0
 public void MouseClicked(NodeViewModel nodeViewModel) =>
 selectionService.Select(nodeViewModel);
Exemple #15
0
        public override void Initialize()
        {
            this.WhenAnyValue(vm => vm.SelectedIoTModuleIdentityInfo)
            .Subscribe(x => ioTModuleIdentityInfoSelectionService.Select(x))
            .AddDisposableTo(Disposables);

            // ReSharper disable once InvokeAsExtensionMethod
            var deviceHubInfo = Observable.CombineLatest(
                ioTDeviceSelectionService.SelectedObject,
                ioTHubInfoSelectionService.SelectedObject,
                (device, iotHub) => new { DeviceInfo = device, IoTHubInfo = iotHub })
                                .Where(arg => arg.DeviceInfo != null && arg.IoTHubInfo != null);


            ioTDeviceSelectionService.SelectedObject
            .Where(deviceInfo => deviceInfo != null)
            .ObserveOnDispatcher()
            .Do(_ => Loading  = true)
            .Do(s => deviceId = s.DeviceId)
            .Subscribe()
            .AddDisposableTo(Disposables);

            ioTHubInfoSelectionService.SelectedObject
            .Where(name => name != null)
            .ObserveOnDispatcher()
            .Do(identityInfos => IoTModuleIdentityInfos = new IoTModuleIdentityInfo[] { })
            .Do(s => hubName = s.Name)
            .Subscribe()
            .AddDisposableTo(Disposables);

            deviceHubInfo
            .Do(arg => Logger.Info($"Received Hub '{arg.IoTHubInfo.Name}' and Device '{arg.DeviceInfo.DeviceId}' for retrieving Modules"))
            .SelectMany(arg => azureService.GetIoTModules(arg.IoTHubInfo.Name, arg.DeviceInfo.DeviceId))
            .ObserveOnDispatcher()
            .Do(identityInfos => IoTModuleIdentityInfos = identityInfos)
            .Do(_ => Loading = false)
            .LogAndRetryAfterDelay(Logger, TimeSpan.FromSeconds(1), "Error while retrieving device modules information")
            .Subscribe()
            .AddDisposableTo(Disposables);

            ReloadCommand = ReactiveCommand.CreateFromTask(Reload, ioTDeviceSelectionService.SelectedObject.Select(deviceInfo => deviceInfo != null))
                            .AddDisposableTo(Disposables);

            // Observable created from ModuleId
            var selectedModuleId = this.WhenAnyValue(model => model.SelectedIoTModuleIdentityInfo)
                                   .Select(model => model?.ModuleId);

            // ReSharper disable once InvokeAsExtensionMethod
            // Observable - combines Observable.Latest and selectedModuleId (Device + Hub + ModuleId)
            Observable.CombineLatest(deviceHubInfo, selectedModuleId,
                                     (deviceHub, module) =>
                                     new
            {
                ModuleId = module,
                HubName  = deviceHub.IoTHubInfo.Name,
                DeviceId = deviceHub.DeviceInfo.DeviceId
            })

            .ObserveOnDispatcher()
            .Do(_ => CurrentModuleTwin = null)
            .Where(moduleInfo => !string.IsNullOrEmpty(moduleInfo.ModuleId))
            .Do(arg => Logger.Info($"Received Hub '{arg.HubName}', Device '{arg.DeviceId}' and module id {arg.ModuleId} for retrieving module twin"))
            .SelectMany(moduleInfo => azureService.GetIoTModelTwinProperties(moduleInfo.HubName, moduleInfo.DeviceId, moduleInfo.ModuleId))
            .Do(twin => CurrentModuleTwin = twin)
            .LogAndRetryAfterDelay(Logger, TimeSpan.FromMilliseconds(100), "Error while retrieving module twin for selection")
            .Subscribe()
            .AddDisposableTo(Disposables)
            ;
        }
 public void Clicked(LineViewModel lineViewModel) => selectionService.Select(lineViewModel);