//only find LabwareUIElement & CarrierUIElement private BasewareUIElement FindSelectedUIElement(Point pt) { HitTestResult result = VisualTreeHelper.HitTest(_myCanvas, pt); if (result == null) { return(null); } if (otherFormNeedPickup) { return(VisualCommon.FindParent <LabwareUIElement>(result.VisualHit)); } else { //we give labwareUI element priority var labwareUIElement = VisualCommon.FindParent <LabwareUIElement>(result.VisualHit); if (labwareUIElement != null) { return(labwareUIElement); } else { return(VisualCommon.FindParent <CarrierUIElement>(result.VisualHit)); } } }
/// <summary> /// from physical to visual /// </summary> /// <param name="size"></param> /// <returns></returns> public static Size Physic2Visual(Size size) { double wPixel = VisualCommon.Convert2PixelXUnit(size.Width); double hPixel = VisualCommon.Convert2PixelYUnit(size.Height); return(new Size(wPixel, hPixel)); }
private void UpdateCarrierGrid(BasewareUIElement _selectedUIElement, Point ptCurrent) { if (!(_selectedUIElement is CarrierUIElement)) { return; } CarrierUIElement carrierUIElement = _selectedUIElement as CarrierUIElement; Carrier carrier = carrierUIElement.Carrier; int newGrid = VisualCommon.FindCorrespondingGrid(ptCurrent.X); int orgGrid = carrier.GridID; carrier.GridID = newGrid; if (carrier.Labwares.Count == 0) { return; } if (newGrid == orgGrid) { return; } foreach (Labware labware in carrier.Labwares) { labware.Refresh(); } }
public static void MountThis(BasewareUIElement baseUIElement, Point position, Grid container, Layout workingLayout) { bool bValid = IsValid(baseUIElement, position, container); if (!bValid) { if (baseUIElement is LabwareUIElement) //if labware has parent, let it go back { LabwareUIElement labwareUIElement = (LabwareUIElement)baseUIElement; if (labwareUIElement.Labware.ParentCarrier != null) { return; } } container.Children.Remove(baseUIElement); if (baseUIElement is CarrierUIElement) { RemoveUIElementsOnCarrier(container, baseUIElement as CarrierUIElement); } baseUIElement = null; return; } int grid = VisualCommon.FindCorrespondingGrid(position.X); if (baseUIElement is CarrierUIElement) { CarrierUIElement carrierUIElement = (CarrierUIElement)baseUIElement; carrierUIElement.Grid = grid; } if (baseUIElement is LabwareUIElement) { LabwareUIElement labwareUIElement = (LabwareUIElement)baseUIElement; Labware labware = labwareUIElement.Labware; CarrierUIElement carrierUIElement = null; int siteID = -1; bool bFound = FindSuitableCarrier(position, labware.TypeName, container, ref carrierUIElement, ref siteID); if (bFound) { if (labware.ParentCarrier != null) { labware.ParentCarrier.Labwares.Remove(labware); } labware.SiteID = siteID; if (labware.IsDitiBox) { var ditiInfo = workingLayout.DitiInfo.DitiBoxInfos.Find(x => x.label == labware.Label); if (ditiInfo == null) { DitiType ditiType = DitiBox.Parse(labware.TypeName); workingLayout.DitiInfo.DitiBoxInfos.Add(new DitiBoxInfo(ditiType, labware.Label, 96)); } } } carrierUIElement.Carrier.AddLabware(labware); } }
internal static int FindCorrespondingGrid(double xPixelOnCanvas) { double unitXPixels = VisualCommon.Convert2PixelXUnit(Worktable.DistanceBetweenAdjacentPins); double startXmm = Configurations.Instance.Worktable.TopLeftPinPosition.X; double xPixelsOffset = VisualCommon.Convert2PixelXUnit(startXmm); int mapGrid = (int)(Math.Ceiling((xPixelOnCanvas - GetXShift() - xPixelsOffset) / unitXPixels + 0.5)); return(mapGrid); }
/// <summary> /// from physical to visual /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="size"></param> /// <returns></returns> public static Rect Physic2Visual(double x, double y, Size size) { double xPixel = VisualCommon.Convert2PixelXUnit(x); double yPixel = VisualCommon.Convert2PixelYUnit(y); xPixel += GetXShift(); yPixel += GetYShift(); double wPixel = VisualCommon.Convert2PixelXUnit(size.Width); double hPixel = VisualCommon.Convert2PixelYUnit(size.Height); return(new Rect(new Point(xPixel, yPixel), new Size(wPixel, hPixel))); }
internal static void DrawGridNumber(int grid, int firstPinX, DrawingContext dc) { double xPixel = VisualCommon.Convert2PixelXUnit(firstPinX) + GetXShift() * 0.95; //when height is 400 use font 10 double yPixel = containerSize.Height * 0.81; dc.DrawText(new FormattedText((grid + 1).ToString(), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 10 * containerSize.Height / 400, System.Windows.Media.Brushes.DarkBlue), new System.Windows.Point(xPixel, yPixel)); }
/// <summary> /// draw circle /// </summary> /// <param name="position"></param> /// <param name="radius"></param> /// <param name="drawingContext"></param> /// <param name="color"></param> public static void DrawCircle(Point position, double radius, DrawingContext drawingContext, Color color, bool fill = false) { double xPixel = VisualCommon.Convert2PixelXUnit(position.X); double yPixel = VisualCommon.Convert2PixelYUnit(position.Y); xPixel += GetXShift(); yPixel += GetYShift(); double rXPixel = VisualCommon.Convert2PixelXUnit(radius); double rYPixel = VisualCommon.Convert2PixelYUnit(radius); Brush brush = new SolidColorBrush(color); Brush fillBrush = fill ? brush : null; drawingContext.DrawEllipse(fillBrush, new Pen(new SolidColorBrush(color), 1), new Point(xPixel, yPixel), rXPixel, rYPixel); }
internal static void DrawText(Point pt, string text, DrawingContext drawingContext) { double xPixel = VisualCommon.Convert2PixelXUnit(pt.X) + GetXShift(); double yPixel = VisualCommon.Convert2PixelYUnit(pt.Y) + GetYShift(); Point ptVisual = new Point(xPixel, yPixel); double fontSize = 10 * containerSize.Height / 400; var formattedText = new FormattedText(text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), fontSize, System.Windows.Media.Brushes.DarkBlue); drawingContext.DrawText(formattedText, ptVisual); }
private static bool IsValid(BasewareUIElement baseUIElement, Point position, Grid container) { int gridPos = VisualCommon.FindCorrespondingGrid(position.X); int totalGrid = Configurations.Instance.Worktable.GridCount; //1 moves out of worktable if (gridPos < 1 || gridPos > totalGrid) { return(false); } //2 if is Carrier, see whether there are enough grids for it if (baseUIElement is CarrierUIElement) { CarrierUIElement carrierUIElement = (CarrierUIElement)baseUIElement; bool outOfRange = IsOutofRange(gridPos, carrierUIElement); if (outOfRange) { return(false); } bool overLapped = OverlapChecker.IsOverlapped(container, carrierUIElement, gridPos); if (overLapped) { return(false); } } //3 if is labware, see whether there are suitable carrier for mounting onto if (baseUIElement is LabwareUIElement) { bool hasSuitableSite2Mount = HasSuitableSite(position, baseUIElement.Ware.TypeName, container); if (!hasSuitableSite2Mount) { return(false); } } //baseUIElement.Selected = false; return(true); }