aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExEllipseScroll.cs
blob: cfd9d54c50bc67cda307c0cba44fac1d6b47a7e9 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using RealTimeGraphEx.Models;
using RealTimeGraphEx.Enums;

namespace RealTimeGraphEx.FastGraphs
{
    public class RealTimeGraphExEllipseScroll : RealTimeGraphExLineScroll
    {
        #region Cross Thread Fields

        protected OpacityTypeEnum _opacityAnimationType;
        protected int _ellipseXRadius;
        protected int _ellipseYRadius;

        #endregion

        #region Constructors

        public RealTimeGraphExEllipseScroll()
            : base()
        {

        }

        #endregion

        #region Properties

        public OpacityTypeEnum OpacityAnimationType
        {
            get { return (OpacityTypeEnum)GetValue(OpacityAnimationTypeProperty); }
            set { SetValue(OpacityAnimationTypeProperty, value); }
        }
        public static readonly DependencyProperty OpacityAnimationTypeProperty =
            DependencyProperty.Register("OpacityAnimationType", typeof(OpacityTypeEnum), typeof(RealTimeGraphExEllipseScroll), new PropertyMetadata(OpacityTypeEnum.None, new PropertyChangedCallback(CrossModelChanged)));



        public int EllipseXRadius
        {
            get { return (int)GetValue(EllipseXRadiusProperty); }
            set { SetValue(EllipseXRadiusProperty, value); }
        }
        public static readonly DependencyProperty EllipseXRadiusProperty =
            DependencyProperty.Register("EllipseXRadius", typeof(int), typeof(RealTimeGraphExEllipseScroll), new PropertyMetadata(5));



        public int EllipseYRadius
        {
            get { return (int)GetValue(EllipseYRadiusProperty); }
            set { SetValue(EllipseYRadiusProperty, value); }
        }
        public static readonly DependencyProperty EllipseYRadiusProperty =
            DependencyProperty.Register("EllipseYRadius", typeof(int), typeof(RealTimeGraphExEllipseScroll), new PropertyMetadata(5));




        #endregion

        #region Override Methods

        protected override void OnSetCrossThreadFields()
        {
            base.OnSetCrossThreadFields();

            this.Dispatcher.Invoke(() =>
            {

                _opacityAnimationType = OpacityAnimationType;
                _ellipseXRadius = EllipseXRadius;
                _ellipseYRadius = EllipseYRadius;

            }, System.Windows.Threading.DispatcherPriority.Send);
        }

        /// <summary>
        /// Draw the actual polygon on the image.
        /// </summary>
        /// <param name="bmp"></param>
        protected override void OnDrawVisuals(WriteableBitmap bmp)
        {
            Color stroke = _graphController.dataSeries.GetStrokeColor() != null ? _graphController.dataSeries.GetStrokeColor().Value : _stroke;
            Color fill = _graphController.dataSeries.GetFillColor() != null ? _graphController.dataSeries.GetFillColor().Value : _fill;

            double scale = GetPolygonScaleFactor();

            for (int i = 0; i < graphPolygon.Count; i++)
            {
                var point = graphPolygon[i];

                Color processedLineColor = stroke;
                Color processedFillColor = fill;

                if (_opacityAnimationType == OpacityTypeEnum.FadeOut)
                {
                    byte opacity = (byte)((((i) * 100 / _maxPoints) * 255) / 100);

                    processedLineColor.A = opacity;
                    processedFillColor.A = opacity;
                }

                if (_fillGraph)
                {
                    bmp.FillEllipseCentered((int)(i * scale), (int)ConvertYToImageYFliped(point), _ellipseXRadius, _ellipseYRadius, processedFillColor);
                }

                bmp.DrawEllipseCentered((int)(i * scale), (int)ConvertYToImageYFliped(point), _ellipseXRadius, _ellipseYRadius, processedLineColor);
            }
        }

        #endregion
    }
}
pan>} private User _managedUser; public User ManagedUser { get { return _managedUser; } set { _managedUser = value; RaisePropertyChangedAuto(); } } private Place _selectedUserPlace; public Place SelectedUserPlace { get { return _selectedUserPlace; } set { _selectedUserPlace = value; if (_selectedUserPlace != null && _selectedUserPlace.Address != null) { SetUserPlace(value); } } } private Place _selectedOrganizationPlace; public Place SelectedOrganizationPlace { get { return _selectedOrganizationPlace; } set { _selectedOrganizationPlace = value; if (_selectedOrganizationPlace != null && _selectedOrganizationPlace.Address != null) { SetOrganizationPlace(value); } } } public RelayCommand ManageOrganizationCommand { get; set; } public RelayCommand BackToOrganizationsCommand { get; set; } public RelayCommand ManageUserCommand { get; set; } public RelayCommand SaveOrganizationCommand { get; set; } public RelayCommand AddOrganizationCommand { get; set; } public RelayCommand RemoveOrganizationCommand { get; set; } public RelayCommand BackToManagedOrganizationCommand { get; set; } public RelayCommand<Role> RemoveRoleCommand { get; set; } public RelayCommand SaveManagedUserCommand { get; set; } public RelayCommand AddUserCommand { get; set; } public RelayCommand RemoveUserCommand { get; set; } public MainViewVM(UsersAndRolesNavigationManager navigation, INotificationProvider notification) { _navigation = navigation; _notification = notification; ManageOrganizationCommand = new RelayCommand(LoadSelectedOrganization, () => SelectedOrganization != null); BackToOrganizationsCommand = new RelayCommand(BackToOrganizations); ManageUserCommand = new RelayCommand(LoadSelectedUser, () => SelectedUser != null); SaveOrganizationCommand = new RelayCommand(SaveOrganization); AddOrganizationCommand = new RelayCommand(AddOrganization); RemoveOrganizationCommand = new RelayCommand(RemoveOrganization, () => SelectedOrganization != null); BackToManagedOrganizationCommand = new RelayCommand(BackToManagedOrganization); RemoveRoleCommand = new RelayCommand<Role>(RemoveUserRole); SaveManagedUserCommand = new RelayCommand(SaveManagedUser); AddUserCommand = new RelayCommand(AddNewUser); RemoveUserCommand = new RelayCommand(RemoveSelectedUser, () => SelectedUser != null); } public override void OnApplicationReady() { LoadOrganizations(); } private async void AddOrganization() { String name = _notification.ShowTextInput("Enter organization name", "Name"); if (!String.IsNullOrWhiteSpace(name)) { using (_notification.PushTaskItem("Adding new organization...")) { Organization org = new Organization(); org.Name = name; org.Address = new Address(); org.Contact = new Contact(); _organizationsContext.Organizations.Add(org); await org.SaveAsync(_organizationsContext); Organizations = _organizationsContext.Organizations.ToObservableCollection(); SelectedOrganization = org; LoadSelectedOrganization(); } } } private async void RemoveOrganization() { if (_notification.ShowQuestion("Are you sure you want to remove " + SelectedOrganization.Name + " organization?")) { using (_notification.PushTaskItem("Removing organization...")) { await SelectedOrganization.DeleteCascadeAsync(_organizationsContext); await LoadOrganizations(); } } } private async void SaveOrganization() { using (_notification.PushTaskItem("Saving organization address and contact...")) { await ManagedOrganization.SaveAsync(_manageContext); await LoadOrganizations(); SelectedOrganization = Organizations.SingleOrDefault(x => x.Guid == ManagedOrganization.Guid); } } private async void LoadSelectedUser() { using (_notification.PushTaskItem("Loading user details...")) { await Task.Factory.StartNew(() => { _userContext = ObservablesContext.CreateDefault(); Roles = new RolesCollectionBuilder(_userContext).SetAll().WithPermission().Build(); ManagedUser = new UserBuilder(_userContext).Set(SelectedUser.Guid).WithRolesAndPermissions().Build(); ManagedUserRoles = ManagedUser.Roles.ToObservableCollection(); }); _navigation.NavigateTo(UsersAndRolesNavigationView.UserManagementView); } } private void BackToOrganizations() { _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationSelectionView); } private void BackToManagedOrganization() { _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationManagementView); } private void RemoveUserRole(Role role) { ManagedUserRoles.Remove(role); foreach (var userRole in ManagedUser.UsersRoles.Where(x => x.Role == role).ToList()) { _userContext.UsersRoles.Remove(userRole); } } private async void SaveManagedUser() { try { ManagedUser.Validate(_userContext); } catch (Exception ex) { _notification.ShowError(ex.Message); return; } using (_notification.PushTaskItem("Saving user details...")) { await ManagedUser.SaveAsync(_userContext); LoadSelectedOrganization(); } } private async void LoadSelectedOrganization() { using (_notification.PushTaskItem("Loading organization...")) { await Task.Factory.StartNew(() => { _manageContext = ObservablesContext.CreateDefault(); ManagedOrganization = new OrganizationBuilder(_manageContext).Set(SelectedOrganization.Guid).WithUsers().Build(); }); _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationManagementView); } } private Task LoadOrganizations() { return Task.Factory.StartNew(() => { _organizationsContext = ObservablesContext.CreateDefault(); Organizations = new OrganizationsCollectionBuilder(_organizationsContext).SetAll().WithUsers().WithMachines().Build(); }); } public void OnDropRole(Role role) { ManagedUser.UsersRoles.Add(new UsersRole() { Role = role, RoleGuid = role.Guid, User = ManagedUser, UserGuid = ManagedUser.Guid, }); ManagedUserRoles.Add(role); } private async void RemoveSelectedUser() { if (_notification.ShowQuestion("Are you sure you want to remove the selected user?")) { using (_notification.PushTaskItem("Removing user...")) { await SelectedUser.DeleteCascadeAsync(_manageContext); LoadSelectedOrganization(); } } } private async void AddNewUser() { String email = _notification.ShowTextInput("Enter user email", "email"); if (!String.IsNullOrWhiteSpace(email)) { User user = new User(); user.Email = email; user.Password = "1111"; user.Contact = new Contact() { FirstName = "Twine", LastName = "User", Email = email, }; user.Address = new Address(); user.UsersRoles.Add(new UsersRole() { User = user, Role = _manageContext.Roles.SingleOrDefault(x => x.Code == (int)BL.Enumerations.Roles.User) }); try { user.Validate(_manageContext); } catch (Exception ex) { _notification.ShowError(ex.Message); return; } ManagedOrganization.Users.Add(user); using (_notification.PushTaskItem("Adding new user...")) { await ManagedOrganization.SaveAsync(_manageContext); await LoadOrganizations(); SelectedOrganization = Organizations.SingleOrDefault(x => x.Guid == ManagedOrganization.Guid); } } } private void SetUserPlace(Place place) { ManagedUser.Address.AddressString = place.Address.Road; ManagedUser.Address.City = place.Address.City; ManagedUser.Address.Country = place.Address.Country; ManagedUser.Address.CountryCode = place.Address.CountryCode; ManagedUser.Address.Locality = place.Address.CountryCode; ManagedUser.Address.PostalCode = place.Address.PostalCode; ManagedUser.Address.State = place.Address.State; } private void SetOrganizationPlace(Place place) { ManagedOrganization.Address.AddressString = place.Address.Road; ManagedOrganization.Address.City = place.Address.City; ManagedOrganization.Address.Country = place.Address.Country; ManagedOrganization.Address.CountryCode = place.Address.CountryCode; ManagedOrganization.Address.Locality = place.Address.CountryCode; ManagedOrganization.Address.PostalCode = place.Address.PostalCode; ManagedOrganization.Address.State = place.Address.State; } protected override void RaisePropertyChangedAuto([CallerMemberName] string caller = null) { base.RaisePropertyChangedAuto(caller); InvalidateRelayCommands(); } } }