Example #1
0
        private static InputSimulator inputSimulator = new InputSimulator(); // Init input simulator

        #endregion Fields

        #region Methods

        public static void HitKey(Gesture g)
        {
            if (g.Hold)
            foreach (Key k in g.Command) inputSimulator.Keyboard.KeyDown((VirtualKeyCode)KeyInterop.VirtualKeyFromKey(k));
              else
              {
            foreach (Key k in g.Command) inputSimulator.Keyboard.KeyDown((VirtualKeyCode)KeyInterop.VirtualKeyFromKey(k));
            foreach (Key k in g.Command) inputSimulator.Keyboard.KeyUp((VirtualKeyCode)KeyInterop.VirtualKeyFromKey(k));
              }
        }
Example #2
0
        private Gesture DeepCopyGesture(Gesture source)
        {
            Gesture target = new Gesture();

              target.Name = source.Name;
              target.Command = new ObservableCollection<Key>(source.Command);
              target.Hold = source.Hold; // System.Boolean's value type is bool
              target.Joint = source.Joint; // Enums are also value type

              target.Frames = new ObservableCollection<GestureFrame>();
              foreach (GestureFrame sourceFrame in source.Frames)
            target.Frames.Add(DeepCopyGestureFrame(sourceFrame));

              return target;
        }
 private void DeHighlightGestureOnList(Gesture g)
 {
     g.IsHit = false;
 }
 /// <summary>
 /// De-highlight frames on visualizer grids
 /// </summary>
 /// <param name="g">Gesture</param>
 private void DeHighlightFrames_Visualizer(Gesture g)
 {
     //Model3DGroup modelGroup_3D = (Model3DGroup)HotspotCellsModelVisual3D_Hit_Visualizer.Content; //this seems to be unused
       CollisionHighlights_3D.Children[GestureCollection.IndexOf(g)] = new Model3DGroup(); //TODO: maybe there is a bug here and wanted to use modelGroup_3D instead?
       CollisionHighlights_Front.Children[GestureCollection.IndexOf(g)] = new Model3DGroup(); //TODO: maybe reuse the "new Model3DGroup()" instead of creating 3 of those?
       CollisionHighlights_Side.Children[GestureCollection.IndexOf(g)] = new Model3DGroup();
 }
 private void HighlightGestureOnList(Gesture g)
 {
     g.IsHit = true;
 }
 /// <summary>
 /// Highlight frames on visualizer grids
 /// </summary>
 /// <param name="g">Gesture</param>
 /// <param name="fs">Gesture Frames</param>
 private void HighlightFrames_Visualizer(Gesture g, List<GestureFrame> fs)
 {
     Model3DGroup modelGroup = GetHighlightModel3D(g, fs);
       CollisionHighlights_3D.Children[GestureCollection.IndexOf(g)] = modelGroup;
       CollisionHighlights_Front.Children[GestureCollection.IndexOf(g)] = modelGroup;
       CollisionHighlights_Side.Children[GestureCollection.IndexOf(g)] = modelGroup;
 }
        private Model3DGroup GetHighlightModel3D(Gesture g, List<GestureFrame> fs)
        {
            // Create material
              EmissiveMaterial material = new EmissiveMaterial(new SolidColorBrush() { Color = Colors.White, Opacity = 0.3 });

              Model3DGroup modelGroup = new Model3DGroup();
              foreach (GestureFrame f in fs)
              {
            foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true))
            {
              int fcIndex = Array.IndexOf(f.FrontCells, fc);
              foreach (GestureFrameCell sc in f.SideCells.Where(
              sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20)))
              {
            // Init mesh
            MeshBuilder meshBuilder = new MeshBuilder(false, false);
            // Make cube and add to mesh
            double y = (fc.LeftCM + fc.RightCM) / 2;
            double z = (fc.TopCM + fc.BottomCM) / 2;
            double x = (sc.LeftCM + sc.RightCM) / 2;
            Point3D cubeCenter = new Point3D(x, y, z);
            meshBuilder.AddBox(cubeCenter, 15, 15, 15);
            // Create and freeze mesh
            var mesh = meshBuilder.ToMesh(true);
            // Create models
            modelGroup.Children.Add(new GeometryModel3D(mesh, material));
              }
            }
              }
              return modelGroup;
        }
 private void ExecuteGesture(Gesture g, bool keyboardEmulation = true)
 {
     if (keyboardEmulation)
     KeyboardUtils.HitKey(g);
       HighlightGestureOnList(g);
 }
    /// <summary>
    /// Sync 3D Viewport with grids
    /// </summary>
    private void SyncEditorGrids_3D(Gesture g) //TODO: split into smaller methods
    {
      // Init 3D stuff
      Model3DGroup modelGroup = new Model3DGroup();
      foreach (GestureFrame f in g.Frames)
      {
        // Create material
        SolidColorBrush materialBrush = new SolidColorBrush()
        {
          Color = Colors.DarkSlateBlue,
          Opacity = 0.1 + ((double)(g.Frames.IndexOf(f) + 1) / (double)g.Frames.Count) * 0.8
        };
        DiffuseMaterial material = new DiffuseMaterial(materialBrush);

        foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true))
        {
          int fcIndex = Array.IndexOf(f.FrontCells, fc);
          foreach (GestureFrameCell sc in f.SideCells.Where(
                   sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20)))
          {
            // Init mesh
            MeshBuilder meshBuilder = new MeshBuilder(false, false);
            // Make cube and add to mesh
            double y = (fc.LeftCM + fc.RightCM) / 2;
            double z = (fc.TopCM + fc.BottomCM) / 2;
            double x = (sc.LeftCM + sc.RightCM) / 2;
            Point3D cubeCenter = new Point3D(x, y, z);
            meshBuilder.AddBox(cubeCenter, 15, 15, 15);

            // Create and freeze mesh
            var mesh = meshBuilder.ToMesh(true);

            // Create model
            modelGroup.Children.Add(new GeometryModel3D(mesh, material));
          }
        }
      }

      // Suggest other gestures too
      foreach (Gesture gg in GestureCollection)
      {
        foreach (GestureFrame f in gg.Frames)
        {
          // Create material
          SolidColorBrush materialBrush = new SolidColorBrush()
          {
            Color = Visualizer_GestureColors[GestureCollection.IndexOf(gg) % Visualizer_GestureColors.Length].Color,
            Opacity = ((double)(gg.Frames.IndexOf(f) + 1) / (double)gg.Frames.Count) * 0.09
          };
          DiffuseMaterial material = new DiffuseMaterial(materialBrush);

          foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true))
          {
            int fcIndex = Array.IndexOf(f.FrontCells, fc);
            foreach (GestureFrameCell sc in f.SideCells.Where(
                sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20)))
            {
              // Init mesh
              MeshBuilder meshBuilder = new MeshBuilder(false, false);

              // Make cube and add to mesh
              double y = (fc.LeftCM + fc.RightCM) / 2;
              double z = (fc.TopCM + fc.BottomCM) / 2;
              double x = (sc.LeftCM + sc.RightCM) / 2;
              Point3D cubeCenter = new Point3D(x, y, z);
              meshBuilder.AddBox(cubeCenter, 15, 15, 15);

              // Create and freeze mesh
              var mesh = meshBuilder.ToMesh(true);

              // Create model
              modelGroup.Children.Add(new GeometryModel3D(mesh, material));
            }
          }
        }
      }

      HotspotCellsModelVisual3D_Editor.Content = modelGroup;
    }
    /// <summary>
    /// Put hints for the current gesture's existing hotspots below both 2D grids
    /// </summary>
    private void SyncEditorGrids_2D_Hints(Gesture g)
    {
      FVHints.Children.Clear();
      SVHints.Children.Clear();
      for (int i = 0; i < 400; i++)
      {
        FVHints.Children.Add(new Border() { Background = Brushes.Transparent, BorderBrush = Brushes.Transparent });
        SVHints.Children.Add(new Border() { Background = Brushes.Transparent, BorderBrush = Brushes.Transparent });
      }
      foreach (GestureFrame f in g.Frames)
      {
        foreach (GestureFrameCell c in f.FrontCells.Where(c => c.IsHotspot))
        {
          Border b = (Border)FVHints.Children[c.IndexInFrame];
          b.Background = new SolidColorBrush() { Color = Colors.SlateBlue, Opacity = 0.2 };
        }

        foreach (GestureFrameCell c in f.SideCells.Where(c => c.IsHotspot))
        {
          Border b = (Border)SVHints.Children[c.IndexInFrame];
          b.Background = new SolidColorBrush() { Color = Colors.SlateBlue, Opacity = 0.2 };
        }
      }
    }
    public bool SaveGesture()
    {
      if (!CanSaveGesture) return false;

      ExGesture = null;
      CloseEditor();

      LoadSpeechRecognitionGrammarForGestureCollection(); //reload the speech recognition grammar for the current gesture collection, since the gesture may have been renamed before saving
      return true;
    }
Example #12
0
 public static void ReleaseKey(Gesture g)
 {
     foreach (Key k in g.Command) inputSimulator.Keyboard.KeyUp((VirtualKeyCode)KeyInterop.VirtualKeyFromKey(k));
 }
 public void DeleteGesture(Gesture g)
 {
     if (MessageBox.Show(string.Format(GlblRes.DeleteGestureFromCollectionConfirmation, g.Name),
             GlblRes.DeleteGestureFromCollection, MessageBoxButton.YesNo)
       == MessageBoxResult.Yes)
     GestureCollection.Remove(g);
 }
        public void LoadGestureCollection(string filename)
        {
            string json = File.ReadAllText(filename);
              // DeserializeObject() does not appear to correctly deserialize Gesture objects
              // Below is a kinda-dirty solution around that
              List<Gesture> sourceList = JsonConvert.DeserializeObject<List<Gesture>>(json);
              GestureCollection.Clear();

              foreach (Gesture sourceGesture in sourceList)
              {
            RemoveNoneKeys(sourceGesture.Command); //Seems somewhere at the serialization or deserialization Key.None creeps in, so remove it

            //copy sourceGesture to targetGesture //TODO: check why this copying is needed
            Gesture targetGesture = new Gesture()
            {
              Name = sourceGesture.Name,
              Command = new ObservableCollection<Key>(sourceGesture.Command),
              Hold = sourceGesture.Hold,
              Joint = sourceGesture.Joint
            };
            //copy the frames too (note: this is not the same as DeepCopyGestureFrame)
            foreach (GestureFrame sourceFrame in sourceGesture.Frames)
            {
              GestureFrame targetFrame = new GestureFrame();
              for (int i = 0; i < 400; i++)
              {
            targetFrame.FrontCells[i] = sourceFrame.FrontCells[i];
            targetFrame.SideCells[i] = sourceFrame.SideCells[i];
              }
              targetGesture.Frames.Add(targetFrame);
            }

            GestureCollection.Add(targetGesture);

            if (GestureCollectionLoaded != null)
              GestureCollectionLoaded(this, EventArgs.Empty);
              }
        }
 public void EditGesture(Gesture g)
 {
     // Store the initial state of the gesture being edited
       ExGesture = DeepCopyGesture(g);
       // Go
       TheWorkspace.DataContext = g;
       ShowEditor();
 }