// NOTE: A new EditGestureViewModel is instantiated on every call to EditGesture()
        public EditStaticGestureViewModel(MainViewModel mvm, SGClassWrapper gesture = null, bool newGesture = false)
        {
            _mvm        = mvm;
            _newGesture = newGesture;
            _provider   = _mvm.SQLiteProvider;
            _recorder   = new SGRecorder(this, _mvm);

            _recorder.RecordingSessionFinished += OnRecordingSessionFinished;

            var featureWeightsDict = new Dictionary <string, int>();

            if (newGesture)
            {
                Name               = "New Static Gesture";
                Instances          = new ObservableCollection <SGInstanceWrapper>();
                featureWeightsDict = SGClass.GetDefaultFeatureWeights();
            }
            else
            {
                Name               = gesture.Name;
                Id                 = gesture.Id;
                Instances          = _provider.GetStaticGestureInstances(gesture.Id);
                featureWeightsDict = gesture.Gesture.FeatureWeights;
            }

            setFeatureWeights(featureWeightsDict);

            Changeset = new EditStaticGestureChangeset();
        }
        public void SaveGesture()
        {
            Dictionary <string, int> featureWeightsDict = null;

            if (_newGesture)
            {
                Id = _provider.SaveNewStaticGestureClass(Name, null);                 // Need to get id
            }
            else
            {
                // Fill featureWeightsDict
                featureWeightsDict = new Dictionary <string, int>();
                foreach (var fw in FeatureWeights)
                {
                    featureWeightsDict.Add(fw.Name, fw.Weight);
                }
            }

            var editedGesture  = new SGClass(Instances, featureWeightsDict);
            var sampleInstance = (Instances.Any()) ? Instances.FirstOrDefault().Gesture : null;

            var gestureWrapper = new SGClassWrapper()
            {
                Id             = this.Id,
                Name           = this.Name,
                Gesture        = editedGesture,
                SampleInstance = sampleInstance
            };

            _provider.SaveStaticGestureClass(gestureWrapper);

            if (Changeset.ChangesExist())
            {
                // Update the StaticGestureInstances table
                foreach (int instanceId in Changeset.DeletedGestureInstances)
                {
                    _provider.DeleteStaticGestureInstance(instanceId);
                }
                foreach (var instance in Changeset.NewGestureInstances)
                {
                    _provider.SaveNewStaticGestureInstance(Id, instance.Gesture);
                }
            }

            _mvm.UpdateStaticGestureLibrary();
        }
Пример #3
0
 public void EditStaticGesture(SGClassWrapper gesture, bool newGesture = false)
 {
     _editStaticGestureControl.VM = new EditStaticGestureViewModel(this, gesture, newGesture);
     Mode = LGR_Mode.EditStatic;
 }