src/FingersDance.Control.UserPanel/UserControlUserPanel.xaml.cs
changeset 188 e642ad0c366b
parent 186 83615722dbab
child 190 619ca3ae13c7
equal deleted inserted replaced
187:b266af50744c 188:e642ad0c366b
    19 	public partial class UserControlUserPanel
    19 	public partial class UserControlUserPanel
    20 	{
    20 	{
    21         #region Variables
    21         #region Variables
    22 
    22 
    23         //public ContactEventHandler ContactDown;
    23         //public ContactEventHandler ContactDown;
    24         public event EventHandler OnSuccessAnnotation;  //Event to display ColorAnnotation from different Users        
    24         public event EventHandler OnSuccessAnnotation;  //Event to display ColorAnnotation from different Users   
       
    25         public event EventHandler OnTagVisualisation; //Event to Mute all Players
    25         public int id = 0;
    26         public int id = 0;
    26         public uint idcolor = 0;    //The color of the Pivot Button
    27         public uint idcolor = 0;    //The color of the Pivot Button
    27         //Project _Project = new Project();
    28         //Project _Project = new Project();
    28         private CuttingViewModel cutVM;
    29         private CuttingViewModel cutVM;
    29 
    30 
       
    31         //variables for TagSound Control
       
    32         double baseOrientation = 0;
       
    33         double deltaOrientation = 0;
       
    34         double lastdeltaOrientation = 0;
       
    35         int lastSoundlevel = 0;
       
    36         bool rise = true; //rise is true if the curse of the volume is positive
    30         #endregion
    37         #endregion
    31 
    38 
    32         #region Properties
    39         #region Properties
    33         public CuttingViewModel CuttingVM
    40         public CuttingViewModel CuttingVM
    34         {
    41         {
    59             id = idPar;
    66             id = idPar;
    60             //_Project = p;
    67             //_Project = p;
    61             cutVM = cutVMPar;
    68             cutVM = cutVMPar;
    62             this.UserControlSyncSource.Load(path, col, cutVM);
    69             this.UserControlSyncSource.Load(path, col, cutVM);
    63             UserControlSyncSource.OnSuccessAnnotation+=new EventHandler(UserControlSyncSource_OnSuccessAnnotation);
    70             UserControlSyncSource.OnSuccessAnnotation+=new EventHandler(UserControlSyncSource_OnSuccessAnnotation);
    64             //SAR -Contact Down event for TAG Control
    71             //SAR -Initialize Tag Values
    65             InitializeDefinitions();
    72             InitializeDefinitions();
    66         }
    73         }
    67 
    74         #endregion
    68         private void InitializeDefinitions() 
    75 
    69         { 
    76         #region Tag Management
       
    77 
       
    78         private void InitializeDefinitions()
       
    79         {
    70             for (byte k = 1; k <= 5; k++)
    80             for (byte k = 1; k <= 5; k++)
    71             { 
    81             {
    72                 ByteTagVisualizationDefinition tagDef = new ByteTagVisualizationDefinition(); 
    82                 ByteTagVisualizationDefinition tagDef = new ByteTagVisualizationDefinition();
    73                 // The tag value that this definition will respond to. 
    83                 // The tag value that this definition will respond to. 
    74                 tagDef.Value = k; 
    84                 tagDef.Value = k;
    75                 // The .xaml file for the UI. 
    85                 // The .xaml file for the UI. 
    76                 tagDef.Source = new Uri("FingersDance.Control.UserPanel;Component/TagVisuSoundControl.xaml", UriKind.Relative);
    86                 tagDef.Source = new Uri("FingersDance.Control.UserPanel;Component/TagVisuSoundControl.xaml", UriKind.Relative);
    77 
    87 
    78                 // The maximum number for this tag value. tagDef.MaxCount = 2; 
    88                 // The maximum number for this tag value. tagDef.MaxCount = 2; 
    79                 // The visualization stays for 2 seconds after the tag is lifted. 
    89                 // The visualization stays for 2 seconds after the tag is lifted. 
    80                 tagDef.LostTagTimeout = 2000.0; 
    90                 tagDef.LostTagTimeout = 2000.0;
    81                 // The orientation offset (default). 
    91                 // The orientation offset (default). 
    82                 tagDef.OrientationOffsetFromTag = 0.0; 
    92                 tagDef.OrientationOffsetFromTag = 0.0;
    83                 // The physical offset (horizontal inches, vertical inches). 
    93                 // The physical offset (horizontal inches, vertical inches). 
    84                 tagDef.PhysicalCenterOffsetFromTag = new Vector(0.5, 0.25); 
    94                 tagDef.PhysicalCenterOffsetFromTag = new Vector(0.5, 0.25);
    85                 // The tag removal behavior (default). 
    95                 // The tag removal behavior (default). 
    86                 tagDef.TagRemovedBehavior = TagRemovedBehavior.Fade; 
    96                 tagDef.TagRemovedBehavior = TagRemovedBehavior.Fade;
    87                 // Orient UI to tag? (default). 
    97                 // Orient UI to tag? (default). 
    88                 tagDef.UsesTagOrientation = true; 
    98                 tagDef.UsesTagOrientation = true;
    89                 // Add the definition to the collection. 
    99                 // Add the definition to the collection. 
    90                 this.tagVisualizer.Definitions.Add(tagDef); 
   100                 this.tagVisualizer.Definitions.Add(tagDef);
    91             } 
   101             }
    92         }
   102         }
    93 
   103 
    94         private void OnVisualizationAdded(object sender, TagVisualizerEventArgs e) 
   104         //SAR - Event Rised when Tag Control is moved or rotated
    95         { 
   105         private void tagVisualizer_VisualizationMoved(object sender, TagVisualizerEventArgs e)
    96             TagVisuSoundControl tagsoundcontrol = (TagVisuSoundControl)e.TagVisualization; 
   106         {
    97             switch (tagsoundcontrol.VisualizedTag.Byte.Value) 
   107             /*TagVisuSoundControl tagsoundcontrol = (TagVisuSoundControl)e.TagVisualization;
    98             {
   108             BindingExpression be = tagsoundcontrol.volumeModel.GetBindingExpression(Label.ContentProperty);
    99                 case 1: tagsoundcontrol.volumeModel.Content = "Tag Value 1"; 
   109             be.UpdateSource();*/
   100                 break;
   110 
   101                 case 2: tagsoundcontrol.volumeModel.Content = "Tag Value 2"; 
   111             TagVisuSoundControl tagsoundcontrol = (TagVisuSoundControl)e.TagVisualization;
   102                 break;
   112 
   103                 case 3: tagsoundcontrol.volumeModel.Content = "Tag Value 3"; 
   113             deltaOrientation = (tagsoundcontrol.Orientation - baseOrientation) % 360;
   104                 break;
   114             if (deltaOrientation < 0)
   105                 case 4: tagsoundcontrol.volumeModel.Content = "Tag Value 4"; 
   115                 deltaOrientation = 360 + deltaOrientation;
   106                 break;
   116             int niveau = (int)(deltaOrientation / 36);
   107                 case 5: tagsoundcontrol.volumeModel.Content = "Tag Value 5"; 
   117 
   108                 break;
   118             //if (((niveau == 9) || (niveau == 8) || (niveau == 7)) && lastSoundlevel == 0)
   109                 default: tagsoundcontrol.volumeModel.Content = "UNKNOWN MODEL"; 
   119             if (((niveau == 9) || (niveau == 8)) && lastSoundlevel == 0)
   110                 break; 
   120                 rise = false;
   111             } 
   121             //else if (((niveau == 1) || (niveau == 2) || (niveau == 3)) && lastSoundlevel == 0)
   112         }
   122             else if (((niveau == 1) || (niveau == 2)) && lastSoundlevel == 0)
       
   123                 rise = true;
       
   124 
       
   125             
       
   126             if (!rise)
       
   127             {
       
   128                 niveau = (niveau - 10) % 10;
       
   129             }
       
   130             //ToDo
       
   131             //--1 Mute all other Players
       
   132 
       
   133             //--2 Elipse visibility
       
   134             tagsoundcontrol.TagVisuSoundLevelUpdate(niveau);
       
   135             //Set the Sound of the Player.
       
   136             if (Math.Abs(lastSoundlevel - niveau) == 1)
       
   137             {
       
   138                 UserControlSyncSource.setUserPlayerVolume((double)niveau / 10.0);
       
   139             }
       
   140             lastSoundlevel = niveau;
       
   141             tagsoundcontrol.volumeModel.Content = niveau;//deltaOrientation.ToString();
       
   142 
       
   143         }
       
   144         private void OnVisualizationAdded(object sender, TagVisualizerEventArgs e)
       
   145         {
       
   146             TagVisuSoundControl tagsoundcontrol = (TagVisuSoundControl)e.TagVisualization;
       
   147 
       
   148             switch (tagsoundcontrol.VisualizedTag.Byte.Value)
       
   149             {
       
   150                 case 1:
       
   151                     try
       
   152                     {
       
   153                         /*
       
   154                         Binding mybinding = new Binding("Orientation");
       
   155                         mybinding.Source = tagsoundcontrol;
       
   156                         mybinding.UpdateSourceTrigger= UpdateSourceTrigger.PropertyChanged ;
       
   157                         tagsoundcontrol.volumeModel.SetBinding(Label.ContentProperty,mybinding);
       
   158                         */
       
   159 
       
   160                         baseOrientation = tagsoundcontrol.Orientation % 360;
       
   161                         deltaOrientation = ((tagsoundcontrol.Orientation % 360) - baseOrientation) % 360;
       
   162                         tagsoundcontrol.volumeModel.Content = deltaOrientation;
       
   163 
       
   164                         //RiseEvent To Mute all other Players
       
   165                         OnTagVisualisation(this, new EventArgs());
       
   166                         PlayerMute(false);
       
   167                     }
       
   168                     catch (Exception ex)
       
   169                     {
       
   170                     }
       
   171                     break;
       
   172                 case 2: tagsoundcontrol.volumeModel.Content = "Tag Value 2";
       
   173                     break;
       
   174                 case 3: tagsoundcontrol.volumeModel.Content = "Tag Value 3";
       
   175                     break;
       
   176                 case 4: tagsoundcontrol.volumeModel.Content = "Tag Value 4";
       
   177                     break;
       
   178                 case 5: tagsoundcontrol.volumeModel.Content = "Tag Value 5";
       
   179                     break;
       
   180                 default: tagsoundcontrol.volumeModel.Content = "UNKNOWN MODEL";
       
   181                     break;
       
   182             }
       
   183         }
       
   184 
   113         #endregion
   185         #endregion
   114 
   186 
   115         public void PlayerPause()
   187         public void PlayerPause()
   116         {
   188         {
   117             UserControlSyncSource.PlayerPause();
   189             UserControlSyncSource.PlayerPause();
   118         }
   190         }
   119 
   191         public void PlayerMute(bool b)
       
   192         {
       
   193             UserControlSyncSource.setUserPlayerMute(b);
       
   194         }
   120 
   195 
   121         private void UserControlSyncSource_OnSuccessAnnotation(object sender, EventArgs e)
   196         private void UserControlSyncSource_OnSuccessAnnotation(object sender, EventArgs e)
   122         {
   197         {
   123             OnSuccessAnnotation(this, new EventArgs());
   198             OnSuccessAnnotation(this, new EventArgs());
   124         }
   199         }
   125 
   200 
   126         public void UserControlSyncSource_DisplayAnnotation(int id, Brush b)
   201         public void UserControlSyncSource_DisplayAnnotation(int id, Brush b)
   127         {
   202         {
   128             UserControlSyncSource.UserControlPlayer_DisplayAnnotation(id, b);
   203             UserControlSyncSource.UserControlPlayer_DisplayAnnotation(id, b);
   129         }
   204         }  
   130 
       
   131         //SAR
       
   132         public void UserControlUserPanel_ContactDown(object sender, ContactEventArgs e)
       
   133         {
       
   134             Contact c = e.Contact;
       
   135             string type = "";
       
   136             if (c.Tag.Type == TagType.Byte)
       
   137             {
       
   138                 type = "Byte Tag";
       
   139                 type += (" Value: " + c.Tag.Byte.Value.ToString("X", CultureInfo.InvariantCulture));
       
   140             }
       
   141             else if (c.Tag.Type == TagType.Identity)
       
   142             {
       
   143                 type = "Identity Tag";
       
   144                 type += (" Value: " + c.Tag.Byte.Value.ToString("X", CultureInfo.InvariantCulture));
       
   145             }
       
   146         }
       
   147 
       
   148         private void tagVisualizer_VisualizationAdded(object sender, Microsoft.Surface.Presentation.Controls.TagVisualizerEventArgs e)
       
   149         {
       
   150 
       
   151         }
       
   152 
       
   153         private void v(object sender, Microsoft.Surface.Presentation.Controls.TagVisualizerEventArgs e)
       
   154         {
       
   155 
       
   156         }
       
   157 
       
   158         
       
   159     }
   205     }
   160 }
   206 }