public EditorStateHelper(LayoutEditorPopulation layoutEditorPopulation, UserSettingsModel userSettings) { _layoutEditorPopulation = layoutEditorPopulation; _userSettings = userSettings; if (_layoutEditorPopulation.EraseOnly) { erasableTypes = layoutEditorPopulation.GetErasableTypes(); } ResetState(); }
public LayoutEditorPopulation LoadDataFromXML(string xml) { Debug.Assert(!string.IsNullOrEmpty(xml)); _layoutEditorPopulation = XmlHelpers.DeserializeXmlString(xml, typeof(LayoutEditorPopulation)) as LayoutEditorPopulation; var userSettings = ServiceLocator.Current.GetInstance<UserSettingsService>(); userSettings.UserSettings.IsMultiple = _layoutEditorPopulation.IsMultiple; userSettings.UserSettings.MultipleLayout = _layoutEditorPopulation.GetMultipleLayoutEnum(); userSettings.UserSettings.ContainerName = _layoutEditorPopulation.ContainerName; var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>(); return _layoutEditorPopulation; }
private LayoutEditorPopulation LoadFromJson(string json) { Debug.Assert(!string.IsNullOrEmpty(json)); _layoutEditorPopulation = JsonHelpers.Deserialize(json, typeof(LayoutEditorPopulation)) as LayoutEditorPopulation; var userSettings = ServiceLocator.Current.GetInstance<UserSettingsService>(); userSettings.UserSettings.IsMultiple = _layoutEditorPopulation.IsMultiple; userSettings.UserSettings.MultipleLayout = _layoutEditorPopulation.GetMultipleLayoutEnum(); userSettings.UserSettings.ContainerName = _layoutEditorPopulation.ContainerName; var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>(); return _layoutEditorPopulation; }
/// <summary> /// Validates the passed in state with the LayoutEditorPopulation, note that the SampleTypes are as specified in the LayoutEditorPopulation /// </summary> /// <param name="state"></param> /// <param name="layoutEditorPopulation"></param> /// <returns></returns> public static List<ValidationError> Validate(SingleLayoutEditor state, LayoutEditorPopulation layoutEditorPopulation) { List<ValidationError> errors = new List<ValidationError>(); // Check the state is setup correctly Debug.Assert(state.NumPositions == state.Width * state.Height); Debug.Assert(state.NumPositions == state.LayoutPositions.Count); if ((layoutEditorPopulation.Width != state.Width) || (layoutEditorPopulation.Height != state.Height)) { errors.Add(new ValidationError() { Type = ValidationError.ErrorType.InvalidLayout, Message = string.Format("The layout dimensions are not correct, they should be {0}x{1}. ", layoutEditorPopulation.Width, layoutEditorPopulation.Height) }); return errors; } try { var mergedTypesSingle = layoutEditorPopulation.GetMergedTypesSingle(); LayoutAnalysis layoutAnalysis = new LayoutAnalysis(state.LayoutPositions, layoutEditorPopulation.SampleTypes, true, // groupNumberingMustStartFromOne - for types that are NOT merged mergedTypesSingle); foreach (Rule rule in layoutEditorPopulation.Rules) { TestRule(rule, layoutAnalysis, errors); } } catch (Layout.LayoutAnalysis.InvalidLayoutException invalidLayoutException) { // Convert the InvalidLayoutException into a message. errors.Add(new ValidationError() { Type = ValidationError.ErrorType.InvalidLayout, Message = invalidLayoutException.Message }); } return errors; }
// Returns true if an empty layout is used // Returns false if a default layout has been used public bool InitEmptyUserLayout(LayoutEditorPopulation layoutEditorPopulation) { _userLayout = UserLayout.Create(layoutEditorPopulation.Width, layoutEditorPopulation.Height, layoutEditorPopulation.SampleTypes); // If there is a default section defined then setup the user layout from this if (!string.IsNullOrEmpty(layoutEditorPopulation.Default)) { _userLayout.InitFromCSVStringAllPositions(layoutEditorPopulation.Default, layoutEditorPopulation.Width, layoutEditorPopulation.Height); OnUpdateUserLayout(); return false; } OnUpdateUserLayout(); return true; }
public void InitializePlateControl(LayoutEditorPopulation layoutEditorPopulation) { if (layoutEditorPopulation == null) return; if (Equals(_userSettings, null)) throw new InvalidOperationException("Please bind the UserSettings firstly"); _layoutEditorPopulation = layoutEditorPopulation; ControlSettings = new ControlSettingsModel(); _plateControl.PosMouseCursor = Cursors.Arrow; _plateControl.SkipCheckForFontSizeRecalc = true; _plateControl.LocationMouseButtonUp += new PlateControl2DSilverlight.MouseEvents.LocationMouseButtonUpEventHandler(plateControl_LocationMouseButtonUp); _plateControl.LocationMouseButtonDown += new PlateControl2DSilverlight.MouseEvents.LocationMouseButtonDownEventHandler(plateControl_LocationMouseButtonDown); _plateControl.LocationMouseOver += new PlateControl2DSilverlight.MouseEvents.LocationMouseOverEventHandler(plateControl2D_LocationMouseOver); FillSettings = new FillSettingsModel(_userSettings) { GroupNum = 1, SelectedSampleTypeIndex = -1 }; FillSettings.PropertyChanged += _fillSettings_PropertyChanged; FillSettings.SampleTypes = _layoutEditorPopulation.SampleTypes; FillSettings.SelectedSampleTypeIndex = FillSettings.SampleTypes.Count - 1; _editorStateHelper = new EditorStateHelper(_layoutEditorPopulation, _userSettings) { }; _editorStateHelper.PropertyChanged += _editorStateHelper_PropertyChanged; // When using RackMode, force fill mode to be across (down doesn't make much sense in rack mode) if (_layoutEditorPopulation.RackMode) { FillSettings.FillDirection = Direction.Across; FillSettings.ShowNextTime = true; } // Fill mode is allowed if we are NOT in EraseOnly and we are NOT in flag mode ControlSettings.AllowFillMode = !_layoutEditorPopulation.EraseOnly && !_userSettings.IsFlagMode; ControlSettings.IsFlagMode = _userSettings.IsFlagMode; // Clear button is available unless in Erase only mode (although it is only enabled when there is something to clear). ControlSettings.AllowClearButton = !_layoutEditorPopulation.EraseOnly; // If Fill mode is not allowed then set SelectedSampleTypeIndex to -1 so ListBox has no items selected (i.e. it looks just like a legend display) if (!ControlSettings.AllowFillMode) FillSettings.SelectedSampleTypeIndex = -1; ControlSettings.SelectionCommand = ControlSettings.IsFlagMode ? SelectionCommand.Flag : SelectionCommand.Erase; if (LoadUserLayoutEvent != null) { var loadUserLayoutmodel = new LoadUserLayoutModel(); loadUserLayoutmodel.UserSettings = _userSettings; loadUserLayoutmodel.IsFlagMode = ControlSettings.IsFlagMode; LoadUserLayoutEvent(loadUserLayoutmodel); } OnUpdateControlSettings(); }