public void CheckPositionInRangeZeroBasedTest1() { int width = 12; int height = 8; SingleLayoutEditor target = new SingleLayoutEditor(width, height); int pos = 96; target.CheckPositionInRangeZeroBased(pos); }
public LayoutAnalysis CreateLayoutAnalysis(string xml, int width, int height, IEnumerable<int> mergedTypesSingle = null) { UserLayout userLayout = XmlHelpers.DeserializeXmlString(xml, typeof(UserLayout)) as UserLayout; SingleLayoutEditor sle = new SingleLayoutEditor(userLayout.SingleLayoutLight, width, height); Assert.AreEqual(width * height, sle.LayoutPositions.Count); return new LayoutAnalysis(sle.LayoutPositions, userLayout.SampleTypes, true, mergedTypesSingle); }
// Create from SingleLayoutEditor (used for sending back to the server) public SingleLayoutLight(SingleLayoutEditor singleLayoutEditor) { NumPositions = singleLayoutEditor.NumPositions; // Note a single layout only contains used entries foreach (LayoutPosEditor layoutPos in singleLayoutEditor.LayoutPositions) { if (layoutPos.LayoutPos.IsUsed) { LayoutPositions.Add(layoutPos.LayoutPos); } } }
public void OrderingDownTest() { SingleLayoutEditor target = new SingleLayoutEditor(2, 2); TestLayoutPosEditorEnumerable(new int[] { 1, 3, 2, 4 }, target.OrderingDown); SingleLayoutEditor target2 = new SingleLayoutEditor(3, 2); TestLayoutPosEditorEnumerable(new int[] { 1, 4, 2, 5, 3, 6 }, target2.OrderingDown); SingleLayoutEditor target3 = new SingleLayoutEditor(2, 3); TestLayoutPosEditorEnumerable(new int[] { 1, 3, 5, 2, 4, 6 }, target3.OrderingDown); }
public void OrderingAcrossTest() { SingleLayoutEditor target = new SingleLayoutEditor(12, 8); TestLayoutPosEditorEnumerable( new int[] { 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 }, target.OrderingAcross); TestLayoutPosEditorEnumerable( new int[] { 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 }, target.OrderingAcross); }
public void ItemTest() { SingleLayoutEditor target = new SingleLayoutEditor(12, 8); LayoutPosEditor l = target[96]; }
/// <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; }
private void OnUpdateCurrentState(SingleLayoutEditor obj) { CurrentState = obj; }
public string SerializeUserLayout(SingleLayoutEditor singleLayoutEditor) { UserLayout userLayout = CreateUserLayoutFromState(singleLayoutEditor); var stringBuilder = new StringBuilder(); XmlHelpers.SerializeObjectAsXmlToStringBuilder(userLayout, stringBuilder); return stringBuilder.ToString(); }
public ServiceLayoutsClient SaveUserLayoutToService(string userId, string layoutId, long associatedAssayId, SingleLayoutEditor singleLayoutEditor, EventHandler<SaveUserLayoutCompletedEventArgs> proxy_SaveLayoutToServiceCompleted) { var result = SerializeUserLayout(singleLayoutEditor); ServiceLayoutsClient proxy = CreateServiceLayoutsClientProxy(); proxy.SaveUserLayoutCompleted += new EventHandler<SaveUserLayoutCompletedEventArgs>(proxy_SaveUserLayoutCompleted); if (proxy_SaveLayoutToServiceCompleted != null) proxy.SaveUserLayoutCompleted += proxy_SaveLayoutToServiceCompleted; OnUpdateBusyStatus(true); proxy.SaveUserLayoutAsync(userId, layoutId, result, associatedAssayId); return proxy; }
public UserLayout CreateUserLayoutFromState(SingleLayoutEditor singleLayoutEditor) { //Uses a shallow copy UserLayout userLayout = this._userLayout.Clone(); userLayout.SingleLayoutLight = new SingleLayoutLight(singleLayoutEditor); return userLayout; }
private void ResetState() { CurrentState = new SingleLayoutEditor(_layoutEditorPopulation); }
// Sets all positions of the specified type/group and adjusts group numbers of type private static void EraseGroup(SingleLayoutEditor newState, int typeId, int groupNum) { // The following calls SetUnused on each position which matches the group and type newState.OrderingAcross .Where(x => (x.LayoutPos.Group == groupNum) && (x.LayoutPos.TypeId == typeId)) .ToList() .ForEach(x => x.SetUnused()); // Get all positions with a group number > this group (and equal type) and decrement newState.OrderingAcross.Select(x => x.LayoutPos) .Where(x => (x.Group > groupNum) && (x.TypeId == typeId)) .ToList() .ForEach(x => x.Group--); }
// Creates a SingleLayoutEditor from a SingleLayoutLight object // This is used when data is received from the server, it is converted to a form more suitable // for working with the PlateControl. // The main differences are that: // 1. A SingleLayoutLight only lists used wells, whereas a SingleLayoutEditor has an entry for every position public SingleLayoutEditor CreateSingleLayoutEditor(SingleLayoutLight singleLayoutLight, int width, int height, FillSettingsModel fillSettings) { SingleLayoutEditor singleLayoutEditor = new SingleLayoutEditor(width, height); foreach (LayoutPos layoutPos in singleLayoutLight.LayoutPositions) { int position = layoutPos.Id; singleLayoutEditor.CheckPositionInRangeOneBased(position); LayoutPosEditor layoutPosEditor = singleLayoutEditor[position - 1]; ModifyLayoutPosEditorForPosition(layoutPos, ref layoutPosEditor, fillSettings); } return singleLayoutEditor; }
private List<LayoutPosEditor> CreateLayout12x8Unused() { SingleLayoutEditor sle = new SingleLayoutEditor(12, 8); return sle.LayoutPositions; }
public void CloneTest() { SingleLayoutEditor original = new SingleLayoutEditor(12, 8); original[0].Colour = Colors.Green; original[0].HoverText = "Hover Text"; original[0].LayoutPos.Id = 1; original[0].LayoutPos.TypeId = 2; original[0].LayoutPos.Group = 3; original[95].Colour = Colors.Goldenrod; original[95].HoverText = "More Hover Text"; original[95].LayoutPos.Id = 3; original[95].LayoutPos.TypeId = 12; original[95].LayoutPos.Group = 23; SingleLayoutEditor copy = original.Clone(); Assert.AreEqual(original.NumPositions, copy.NumPositions); for (int i = 0; i < original.NumPositions; i++) { Assert.AreEqual(original[i].Colour, copy[i].Colour); Assert.AreEqual(original[i].HoverText, copy[i].HoverText); Assert.AreEqual(original[i].LayoutPos.Id, copy[i].LayoutPos.Id); Assert.AreEqual(original[i].LayoutPos.TypeId, copy[i].LayoutPos.TypeId); Assert.AreEqual(original[i].LayoutPos.Group, copy[i].LayoutPos.Group); } }
private void OnSaveAndClose(SingleLayoutEditor currentState) { OnShowErrorMessage("Save and Close..."); }
public void GetEnumerableDownTest() { SingleLayoutEditor target = new SingleLayoutEditor(12, 8); TestLayoutPosEditorEnumerable(new int[] { 2, 85, 73, 61, 49, 37, 25, 13, 1 }, target.GetEnumerableDown(2, 1)); TestLayoutPosEditorEnumerable(new int[] { 1, 13, 25, 37, 49, 61, 73, 85, 2 }, target.GetEnumerableDown(1, 2)); TestLayoutPosEditorEnumerable(new int[] { 1, 13 }, target.GetEnumerableDown(1, 13)); TestLayoutPosEditorEnumerable(new int[] { 13, 1 }, target.GetEnumerableDown(13, 1)); TestLayoutPosEditorEnumerable(new int[] { 1, 13, 25, 37, 49, 61, 73, 85, 2, 14, 26, 38, 50, 62, 74, 86 }, target.GetEnumerableDown(1, 86)); // N TestLayoutPosEditorEnumerable(new int[] { 14, 2 }, target.GetEnumerableDown(14, 2)); // S TestLayoutPosEditorEnumerable(new int[] { 14, 26 }, target.GetEnumerableDown(14, 26)); // E TestLayoutPosEditorEnumerable(new int[] { 14, 26, 38, 50, 62, 74, 86, 3, 15 }, target.GetEnumerableDown(14, 15)); // W TestLayoutPosEditorEnumerable(new int[] { 14, 2, 85, 73, 61, 49, 37, 25, 13 }, target.GetEnumerableDown(14, 13)); // NE TestLayoutPosEditorEnumerable(new int[] { 14, 26, 38, 50, 62, 74, 86, 3 }, target.GetEnumerableDown(14, 3)); // SE TestLayoutPosEditorEnumerable(new int[] { 14, 26, 38, 50, 62, 74, 86, 3, 15, 27 }, target.GetEnumerableDown(14, 27)); // NW TestLayoutPosEditorEnumerable(new int[] { 14, 2, 85, 73, 61, 49, 37, 25, 13, 1 }, target.GetEnumerableDown(14, 1)); // SW TestLayoutPosEditorEnumerable(new int[] { 14, 2, 85, 73, 61, 49, 37, 25 }, target.GetEnumerableDown(14, 25)); }
private LayoutAnalysis SetupLayoutAnalysisForTestRule(string xmlUserLayout, int width, int height) { UserLayout userLayout = XmlHelpers.DeserializeXmlString(xmlUserLayout, typeof(UserLayout)) as UserLayout; SingleLayoutEditor sle = new SingleLayoutEditor(userLayout.SingleLayoutLight, width, height); // Create an LPE from the LayoutEditorPopulation template string - note this has no rules // and the dimensions are not setup. However it should contain all SampleTypes used in all tests LayoutEditorPopulation lpe = CreateLayoutEditorPopulation(xmlStringsLayoutEditorPopulation.xmlAllTypesNoDimensionsOrRules); lpe.Width = width; lpe.Height = height; Debug.Assert(lpe.Rules.Count == 0); LayoutAnalysis la = new LayoutAnalysis(sle.LayoutPositions, lpe.SampleTypes, true); List<ValidationError> errors = LayoutValidation.Validate(sle, lpe); Assert.AreEqual(0, errors.Count, "The userlayout generated an InvalidLayout error"); return new LayoutAnalysis(sle.LayoutPositions, lpe.SampleTypes, true); }
public void GetEnumerableFillTest() { SingleLayoutEditor target = new SingleLayoutEditor(2, 2); TestLayoutPosEditorEnumerable(new int[] { 2, 3 }, target.GetEnumerableFill(2, 3, target.OrderingAcross)); TestLayoutPosEditorEnumerable(new int[] { 2, 3 }, target.GetEnumerableFill(3, 2, target.OrderingAcross)); TestLayoutPosEditorEnumerable(new int[] { 3, 2 }, target.GetEnumerableFill(2, 3, target.OrderingAcross.Reverse())); TestLayoutPosEditorEnumerable(new int[] { 3, 2 }, target.GetEnumerableFill(3, 2, target.OrderingAcross.Reverse())); TestLayoutPosEditorEnumerable(new int[] { 2 }, target.GetEnumerableFill(2, 2, target.OrderingAcross.Reverse())); TestLayoutPosEditorEnumerable(new int[] { 2, 1 }, target.GetEnumerableFill(2, 5, target.OrderingAcross.Reverse())); TestLayoutPosEditorEnumerable(new int[] { }, target.GetEnumerableFill(5, 6, target.OrderingAcross.Reverse())); }
public void GetRowFromPosTest() { SingleLayoutEditor target = new SingleLayoutEditor(12, 8); Assert.AreEqual(1, target.GetRowFromPos(1)); Assert.AreEqual(1, target.GetRowFromPos(12)); Assert.AreEqual(2, target.GetRowFromPos(13)); Assert.AreEqual(8, target.GetRowFromPos(96)); Assert.AreEqual(8, target.GetRowFromPos(89)); }
private void ApplyChangeToEditor(SingleLayoutEditor newState) { //Stopwatch stopWatch = DiagnosticHelpers.GetStartedStopWatch(); if (_singleLayoutEditorCachedState != null) { Debug.Assert(newState.NumPositions == _singleLayoutEditorCachedState.NumPositions); Debug.Assert(newState.LayoutPositions.Count == _singleLayoutEditorCachedState.NumPositions); Debug.Assert(newState.LayoutPositions.Count == _singleLayoutEditorCachedState.LayoutPositions.Count); } else { // Only use batch mode if there is no cached state _plateControl.BatchMode = true; _plateControl.PositionsAcross = newState.Width; _plateControl.PositionsDown = newState.Height; _plateControl.PlateColour = Colors.White; _plateControl.HeaderColour = Colors.White; } // Only make changes that are visually different (if there is a previous state cached) // This is faster and does not require a Redraw or use of Batch mode bool update; for (int pos = 0; pos < newState.NumPositions; pos++) { update = true; if (_singleLayoutEditorCachedState != null) { update = !_singleLayoutEditorCachedState[pos].IsVisuallyEqual(newState[pos]); } if (update) { UpdatePlateControlPosition(newState[pos]); } } // End batch mode and use redraw if there was no previous cached state if (_singleLayoutEditorCachedState == null) { _plateControl.BatchMode = false; _plateControl.Redraw(); } _singleLayoutEditorCachedState = newState; }