private void ScrollViewer_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { System.Diagnostics.Debug.WriteLine("DrawingArea_MouseLeftButtonUp" + new Random().Next()); PageManager pageManager = (App.Current.MainWindow.FindName("MainGrid") as Grid).DataContext as PageManager; if ((pageManager.CurrentPage.Item as Project).WorkOrders[0].SelectedItem == null) { ToolbarManager toolbarManager = (App.Current.MainWindow.FindName("Toolbox") as ToolBar).DataContext as ToolbarManager; if (toolbarManager.SelectedToolbar != null) { Project project = (pageManager.CurrentPage.Item as Project); Stock stock = project.WorkOrders[0].Items[0].Material; //todo: handle more WorkItem selection if (toolbarManager.SelectedToolbar.Name.Contains("LShapeItem")) { LShapeItem wo = new LShapeItem(toolbarManager.SelectedToolbar.Name, stock, 0, 0); project.WorkOrders[0].Items.Add(wo); } else if (toolbarManager.SelectedToolbar.Name.Contains("RectItem")) { RectItem wo = new RectItem(toolbarManager.SelectedToolbar.Name, stock, 0, 0); project.WorkOrders[0].Items.Add(wo); } } } else { Canvas canvas = (sender as Control).FindName("DrawingArea") as Canvas; Point newPosition = e.GetPosition(canvas); (pageManager.CurrentPage.Item as Project).WorkOrders[0].SelectedItem.Left += newPosition.X - originalPoint.X; (pageManager.CurrentPage.Item as Project).WorkOrders[0].SelectedItem.Top += newPosition.Y - originalPoint.Y; (pageManager.CurrentPage.Item as Project).WorkOrders[0].SelectedItem = null;//reset } }
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values.Length > 1) { string number = string.Empty; if (!(values[0] is RectItem)) { return(number); } if (!(values[1] is WorkOrder)) { return(number); } RectItem rect = values[0] as RectItem; WorkOrder wo = values[1] as WorkOrder; int i = 0; MatchItemInCollection(wo.Items, rect, ref i); number = i.ToString() + ".";//todo: to desire format based on setting return(number); } throw new NotImplementedException(); }
private void _DrawDots() { Random rand = new Random(); mre = new ManualResetEvent(false); ThreadColorPair = new ConcurrentDictionary <int, int>(); _lock = new object(); _rectLock = new object(); IsSettingsEnabled = false; IsButtonStartEnabled = false; void callbackAction() { if (mre.WaitOne(0)) { return; } Debug.WriteLine($"{Thread.CurrentThread.ManagedThreadId} - current thread id"); var x = rand.NextDouble() * WidthOfCanvas; var y = rand.NextDouble() * HeightOfCanvas; var color = Colors[_FindColorForGivenThread()]; var item = new RectItem { X = x, Y = y, Width = 1, Height = 1, Color = color }; if (App.Current == null) { return; } App.Current.Dispatcher.Invoke((Action) delegate { RectItems.Add(item); }); }; MyPool = new PoolManager(NumberOfThreads); Task runner = Task.Run(() => { while (!MyPool.IsDisposed) { var _speed = 1000 / SpeedOfDrawing; MyPool.QueueTask(callbackAction); Thread.Sleep(_speed); } }).ContinueWith((o) => { Debug.WriteLine("Drawing has stopped and threads are disposed."); }); }
public void AddRect(RectItem rect) { rectList.Add(rect); if (MaxHeight < rect.Height) { MaxHeight = rect.Height; } EqualizeHeight(); }
public void AddRect(RectItem rect) { rectList.Add(rect); if (MaxWidth < rect.Width) { MaxWidth = rect.Width; } EqualizeWidth(); }
public static RectItem Frame(Color color) { var r = new RectItem( ) { Key = "FRAME", Rectangle = MfdGeo.MfdArea, FillBrush = null, Pen = new Pen(color) }; return(r); }
private void ArrangeItems(int columnCount, Size finalSize) { rowList.RemoveAll(x => true); columnList.RemoveAll(x => true); int column = 0; int row = 0; for (int desiredIndex = 0; desiredIndex < desiredList.Count; desiredIndex++) { if (column == 0) { rowList.Add(new FieldGridWrapRow()); } if (columnList.Count < columnCount) { columnList.Add(new FieldGridWrapColumn()); } double margin = 0; if (column > 1 && column % 2 == 0 && Stretch == true) { margin = ColumnMargin; } RectItem rect = new RectItem(0, 0, desiredList[desiredIndex].Height, desiredList[desiredIndex].Width + margin); rowList[row].AddRect(rect); columnList[column].AddRect(rect); if (rowList.First().TotalWidth > finalSize.Width && columnCount != 2) { column = 0; row = 0; desiredIndex = -1; columnCount -= 2; rowList.RemoveAll(x => true); columnList.RemoveAll(x => true); continue; } column++; if (column == columnCount) { column = 0; margin = 0; row++; } } }
public void WorkOrderUniqueGuidTest() { Stock stock = new Stock { Name1 = "Blue Pearl" }; LShapeItem w1 = new LShapeItem("LShapeItem04", stock, 48, 108); w1.Lengths[1].Type = new Bullnose("dep2"); w1.Lengths[2].Type = new Bullnose("dep2"); w1.Lengths[3].Type = new Bullnose("dep2"); w1.Lengths[4].Type = new Bullnose("dep2"); RectItem w2 = new RectItem("RectItem00", stock, 24, 6); w2.Top = 400; w2.Left = 200; w2.AddElement(); RectItem w3 = new RectItem("RectItem00", stock, 28, 13); w3.Top = 100; w3.AddElement(); w3.AddElement(); RectItem w4 = new RectItem("RectItem00", stock, 36, 4); w4.Top = 100; w4.AddElement(); w4.AddElement(); w4.AddElement(); WorkOrder target = new WorkOrder(); target.Items.Add(w1); target.Items.Add(w2); target.Items.Add(w3); target.Items.Add(w4); //using dictionary to insert unique key for all ShapeItem and the children collection. Dictionary <string, ShapeItem> actual = new Dictionary <string, ShapeItem>(); RetrieveShapeItem(target.Items, ref actual); //if cause exception means fail System.Diagnostics.Debug.WriteLine(actual.Count); }
protected override Size ArrangeOverride(Size finalSize) { int columnCount = CalculateColumnCount(finalSize.Width); ArrangeItems(columnCount, finalSize); List <double> restWidth = null; if (rowList.Count > 0 && Stretch == true) { restWidth = CalculateRestWidth(finalSize.Width); } for (int i = 0; i < columnList.Count; i++) { columnList[i].Arrange(restWidth?[i] ?? 0); } int counter = 0; foreach (var item in rowList) { double margin = 0; if (!rowList.First().Equals(item)) { margin = RowMargin * counter; } item.Arrange(margin); counter++; } for (int i = 0; i < Children.Count; i++) { int row = i / columnList.Count; int column = i % columnList.Count; RectItem rectitem = rowList[row].Get(column); Rect rect = new Rect(rectitem.X, rectitem.Y, rectitem.Width, rectitem.Height); Children[i].Arrange(rect); } return(finalSize); }
private void ArrangeItems(int columnCount, Size finalSize) { rowList.RemoveAll(x => true); columnList.RemoveAll(x => true); int column = 0; int row = 0; for (int desiredIndex = 0; desiredIndex < desiredList.Count; desiredIndex++) { if (column == 0) { rowList.Add(new GridWrapRow()); } if (columnList.Count < columnCount) { columnList.Add(new GridWrapColumn()); } RectItem rect = new RectItem(0, 0, desiredList[desiredIndex]); rowList[row].AddRect(rect); columnList[column].AddRect(rect); if (rowList.First().TotalWidth > finalSize.Width && columnCount != 1) { column = 0; row = 0; desiredIndex = -1; columnCount--; rowList.RemoveAll(x => true); columnList.RemoveAll(x => true); continue; } column++; if (column == columnCount) { column = 0; row++; } } }
protected override Size ArrangeOverride(Size finalSize) { int columnCount = CalculateColumnCount(finalSize.Width); ArrangeItems(columnCount, finalSize); double restWidth = 0; if (rowList.Count > 0 && Stretch == true) { restWidth = (finalSize.Width - rowList.First().TotalWidth) / columnList.Count; } foreach (var item in columnList) { item.Arrange(restWidth); } foreach (var item in rowList) { item.Arrange(); } for (int i = 0; i < Children.Count; i++) { int row = i / columnList.Count; int column = i % columnList.Count; RectItem rectitem = rowList[row].Get(column); Rect rect = new Rect(rectitem.X, rectitem.Y, rectitem.Width, rectitem.Height); Children[i].Arrange(rect); } return(finalSize); }
private Project CreateProject() { Employee creator = new Employee(); creator.EmailAddresses.Add(new vCardEmailAddress { Address = "*****@*****.**" }); Customer agent = new Customer { GivenName = "One Kitchen" + new Random().Next(20) }; Customer customer = new Customer { GivenName = "Ah Shing" }; customer.Phones.Add(new vCardPhone { FullNumber = "012-4711134" }); vCardDeliveryAddress deliver = new vCardDeliveryAddress(); deliver.Street = "963 Jalan 6\nMachang Bubok"; deliver.City = "Bukit Mertajam"; deliver.Region = "Penang"; deliver.PostalCode = "14020"; deliver.Country = "Malaysia"; customer.DeliveryAddresses.Add(deliver); customer.Latitude = 5.33398f; customer.Longitude = 100.50754f; Project target = new Project(); target.CreatedBy = creator; target.DeliverTo = customer;//customer.DeliveryAddresses[0]; target.OrderBy = agent; target.Stage = ProjectStage.Draft; int size = DatabaseObject.Stocks.Stock.Count; Stock stock = DatabaseObject.Stocks.Stock[new Random().Next(size)]; LShapeItem w1 = new LShapeItem("LShapeItem04", stock, 48, 108); w1.Lengths[1].Type = new Bullnose("dep2"); w1.Lengths[2].Type = new Bullnose("dep2"); w1.Lengths[3].Type = new Bullnose("dep2"); w1.Lengths[4].Type = new Bullnose("dep2"); //w1.Elements.Add(new VerticalLine(string.Empty, 150)); RectItem w2 = new RectItem("RectItem00", stock, 24, 6); w2.Top = 400; w2.Left = 200; w2.AddElement(); RectItem w3 = new RectItem("RectItem00", stock, 28, 13); w3.Top = 100; w3.AddElement(); w3.AddElement(); RectItem w4 = new RectItem("RectItem00", stock, 36, 4); w4.Top = 100; w4.AddElement(); w4.AddElement(); w4.AddElement(); WorkOrder wo = new WorkOrder(); wo.Items.Add(w1); wo.Items.Add(w2); wo.Items.Add(w3); wo.Items.Add(w4); target.WorkOrders.Add(wo); return(target); }
private Project CreateProject() { Employee creator = new Employee(); creator.EmailAddresses.Add(new vCardEmailAddress { Address = "*****@*****.**" }); Customer agent = new Customer { GivenName = "John" + new Random().Next(20) }; Customer customer = new Customer { GivenName = "Ah Hock" }; customer.Phones.Add(new vCardPhone { FullNumber = "012-4711134" }); vCardDeliveryAddress deliver = new vCardDeliveryAddress(); deliver.Street = "963 Jalan 6"; deliver.Region = "Machang Bubok"; deliver.City = "Bukit Mertajam"; deliver.PostalCode = "05400"; deliver.Country = "Malaysia"; customer.DeliveryAddresses.Add(deliver); customer.Latitude = 6.09105f; customer.Longitude = 100.44629f; Project target = new Project(); target.CreatedBy = creator; target.DeliverTo = customer;//customer.DeliveryAddresses[0]; target.OrderBy = agent; target.Stage = ProjectStage.Draft; int size = DatabaseObject.Stocks.Stock.Count; Stock stock = DatabaseObject.Stocks.Stock[new Random().Next(size)]; LShapeItem w1 = new LShapeItem();//WorkItem w1 = new WorkItem(); w1.Tags.Add("LShapeItem04"); w1.Material = stock; w1.Lengths.Add(new LengthItem { Length = 108 }); w1.Lengths.Add(new LengthItem { Length = 24 }); w1.Lengths.Add(new LengthItem { Length = 84 }); w1.Lengths.Add(new LengthItem { Length = 24 }); w1.Lengths.Add(new LengthItem { Length = 24 }); w1.Lengths.Add(new LengthItem { Length = 48 }); w1.MaxHeight = 108; w1.MaxWidth = 48; RectItem w2 = new RectItem(); w2.Tags.Add("RectItem00"); w2.Material = stock; w2.Height = 6; w2.Width = 24; w2.Top = 400; w2.Left = 200; RectItem w3 = new RectItem(); w3.Tags.Add("RectItem00"); w3.Material = stock; w3.Height = 6; w3.Width = 24; //w3.Top = 100; //w3.Left = 200; WorkOrder wo = new WorkOrder(); wo.Items.Add(w1); wo.Items.Add(w2); wo.Items.Add(w3); target.WorkOrders.Add(wo); return(target); }