/// <summary> /// Method starts drop if possible /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _TryToDrop(DragEventArgs e) { DragAndDropHelper dragAndDropHelper = new DragAndDropHelper(); Point mousePoint = e.GetPosition(ganttControl); object hoveredObject = ganttControl.HitTest(mousePoint); // Get object under mouse cursor. Object dropTarget = _GetTargetData(hoveredObject); // Get Tag from hovered object. if (dropTarget == null) // If target drop object is "null" - do nothing. { return; } // Get collection of dragging orders. ICollection <Order> draggingOrders = dragAndDropHelper.GetDraggingOrders(e.Data); // If user try to change single stop position - define additional parameters. if ((1 == draggingOrders.Count) && (dropTarget is Route) && (hoveredObject is IGanttItemElement) && ((Route)dropTarget).Stops.Count > 0) { IGanttItem parentItem = null; int index = 0; parentItem = ((IGanttItemElement)hoveredObject).ParentGanttItem; index = parentItem.GanttItemElements.IndexOf((IGanttItemElement)hoveredObject); Debug.Assert(index + 1 < parentItem.GanttItemElements.Count); if (parentItem.GanttItemElements[index + 1].Tag is Stop) { dropTarget = (Stop)parentItem.GanttItemElements[index + 1].Tag; } } // Do Drop. dragAndDropHelper.Drop(dropTarget, e.Data); }
/// <summary> /// Initializes a new instance of the <c>DriveTimeGanttItemElement</c> class. /// </summary> public DriveTimeGanttItemElement(Stop stop, IGanttItem parent) { // Creates route drive time as a gantt item element. _stop = stop; _route = stop.Route; // Cache route value. _parent = parent; // Subscribe on stop changes to notify about updates. _route.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_RoutePropertyChanged); _stop.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_StopPropertyChanged); }
/// <summary> /// Selection logic if "Shift" button was pressed in selection. /// </summary> /// <param name="pressedElement">Last clicked element.</param> /// <returns>New selection collection. If selection shouldn't be changed - returns null.</returns> private ICollection <IGanttItemElement> _SelectItemsByShift(IGanttItemElement clickedElement) { Debug.Assert(_selectedElements.Count > 0); // Collection should contain at least one element. Otherwise we use _SelectItem method. // If user clicked to element in other GanttItem - do nothing. if (_selectedElements.First().Value.ParentGanttItem != clickedElement.ParentGanttItem) { return(null); } // Else - need to select range between first selected item and clicked item. // If just clicked element has the same tag as current GanttItem - // elemet is already in selection (was added earlier by custom logic in _SelectItem() method). And we should do nothing. if (_selectedElements.First().Key.ParentGanttItem.Tag == clickedElement.Tag) { return(null); } // Check that clicked item is the same type as items in collection. Type selectedItemsType = _selectedElements.First().Value.Tag.GetType(); // If new element Tag type is nos same as Tag type of already selected elements - do nothing. if (clickedElement.Tag.GetType() != selectedItemsType) { return(null); } // Rename vars to make code more clear. IGanttItemElement firstSelectedElement = _selectedElements.First().Key; IGanttItemElement lastSelectedElement = clickedElement; IGanttItem parentItem = lastSelectedElement.ParentGanttItem; // Defines whether selection bounds are in revert order. bool doSelectionBoundsHaveInvalidOrder = (parentItem.GanttItemElements.IndexOf(lastSelectedElement) < parentItem.GanttItemElements.IndexOf(firstSelectedElement)); // If index of last selected item parent is smaller than first selected item parent - interchange items. if (doSelectionBoundsHaveInvalidOrder) { IGanttItemElement buffer = firstSelectedElement; firstSelectedElement = lastSelectedElement; lastSelectedElement = buffer; } // Collection of all element which should be selected now. ICollection <IGanttItemElement> newSelectedElements = new Collection <IGanttItemElement>(); // Select elements from selection range. newSelectedElements = _GetSelectedElementsByGanttItem(selectedItemsType, parentItem, firstSelectedElement, lastSelectedElement); return(newSelectedElements); }
/// <summary> /// Gets collection of elements which Tag is the same with Gantt item tag. /// </summary> /// <param name="ganttItem">Gantt item.</param> /// <returns>Collection of IganttItemElements with tags same to gantt item tag.</returns> private Collection <IGanttItemElement> _GetSelectedElementsWithGanttItemTag(IGanttItem ganttItem) { Collection <IGanttItemElement> selectedElements = new Collection <IGanttItemElement>(); foreach (IGanttItemElement element in ganttItem.GanttItemElements) { if (element.Tag == ganttItem.Tag) { selectedElements.Add(element); } } return(selectedElements); }
/// <summary> /// Removes all IGanttItemElements in necessary item.GanttItemElements from selection. /// </summary> /// <param name="ganttItem">Item whose elements should be removed.</param> /// <returns>True if even one element was removed.</returns> private bool _RemoveVisualsFromSelectionForGanttItem(IGanttItem ganttItem) { bool isVisualsWereRemoved = false; foreach (IGanttItemElement element in ganttItem.GanttItemElements) { if (_selectedElements.ContainsValue(element)) { _selectedElements.Remove(element); isVisualsWereRemoved = true; } } return(isVisualsWereRemoved); }
/// <summary> /// Initializes a new instance of the <c>StopGanttItem</c> class. /// </summary> public StopGanttItemElement(Stop stop, IGanttItem parent) { Debug.Assert(stop != null); Debug.Assert(parent != null); // Initialize stop. _stop = stop; _route = stop.Route; // Subscribe on stop and route changes to notify about updates. _route.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_RoutePropertyChanged); _stop.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_StopPropertyChanged); // Initialize parent. _parent = parent; }
/// <summary> /// Initializes a new instance of the <c>StopGanttItem</c> class. /// </summary> public StopGanttItemElement(Stop stop, IGanttItem parent) { Debug.Assert(stop != null); Debug.Assert(parent != null); // Initialize stop. _stop = stop; _route = stop.Route; // Subscribe on stop and route changes to notify about updates. _route.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_RoutePropertyChanged); _stop.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_StopPropertyChanged); // Initialize parent. _parent = parent; }
/// <summary> /// Method removes all visuals from child collection if visual is bound with gantt item. Also removes objects from selection. /// </summary> /// <param name="ganttItem">Gantt item.</param> private void _RemoveVisualsForGanttItem(IGanttItem ganttItem) { Collection <IGanttItemElement> itemsToRemove = new Collection <IGanttItemElement>(); foreach (GanttItemElementDrawingVisual visual in _children) //(int i = 0; i < VisualChildrenCount; i++) { IGanttItemElement element = ((GanttItemElementDrawingVisual)visual).GanttItemElement; if (element.ParentGanttItem.Equals(ganttItem)) { itemsToRemove.Add(element); } } // Remove necessary elements from collection. foreach (IGanttItemElement element in itemsToRemove) { element.RedrawRequired -= _ElementRedrawRequired; _children.Remove(_mapElementToVisual[element]); _mapElementToVisual.Remove(element); _selectedElements.Remove(element); } }
/// <summary> /// Adds one "row" of visual elements to necessary gantt item. /// </summary> /// <param name="ganttItem">Gantt item.</param> private void _AddVisualsForGanttItem(IGanttItem ganttItem) { // Define next Gantt item in collection to insert new visuals before it's visuals. int indexOfNextGanttItem = _ganttItems.IndexOf(ganttItem) + 1; if (indexOfNextGanttItem == _ganttItems.Count) // If new item was added to the end of collection. { // Add new visuals to the end of collection. foreach (IGanttItemElement element in ganttItem.GanttItemElements) { GanttItemElementDrawingVisual newVisual = new GanttItemElementDrawingVisual(element); newVisual.RedrawRequired = true; _mapElementToVisual.Add(element, newVisual); // Add pair to dictionary. _children.Add(newVisual); element.RedrawRequired += new EventHandler(_ElementRedrawRequired); } } else { Debug.Assert(false); // TODO : Add code to insert visual to necessary position later if necessary } }
/// <summary> /// Removes all IGanttItemElements in necessary item.GanttItemElements from selection. /// </summary> /// <param name="ganttItem">Item whose elements should be removed.</param> /// <returns>True if even one element was removed.</returns> private bool _RemoveVisualsFromSelectionForGanttItem(IGanttItem ganttItem) { bool isVisualsWereRemoved = false; foreach (IGanttItemElement element in ganttItem.GanttItemElements) { if (_selectedElements.ContainsValue(element)) { _selectedElements.Remove(element); isVisualsWereRemoved = true; } } return isVisualsWereRemoved; }
/// <summary> /// Method removes all visuals from child collection if visual is bound with gantt item. Also removes objects from selection. /// </summary> /// <param name="ganttItem">Gantt item.</param> private void _RemoveVisualsForGanttItem(IGanttItem ganttItem) { Collection<IGanttItemElement> itemsToRemove = new Collection<IGanttItemElement>(); foreach (GanttItemElementDrawingVisual visual in _children) //(int i = 0; i < VisualChildrenCount; i++) { IGanttItemElement element = ((GanttItemElementDrawingVisual)visual).GanttItemElement; if (element.ParentGanttItem.Equals(ganttItem)) itemsToRemove.Add(element); } // Remove necessary elements from collection. foreach (IGanttItemElement element in itemsToRemove) { element.RedrawRequired -= _ElementRedrawRequired; _children.Remove(_mapElementToVisual[element]); _mapElementToVisual.Remove(element); _selectedElements.Remove(element); } }
/// <summary> /// Gets collection of elements which Tag is the same with Gantt item tag. /// </summary> /// <param name="ganttItem">Gantt item.</param> /// <returns>Collection of IganttItemElements with tags same to gantt item tag.</returns> private Collection<IGanttItemElement> _GetSelectedElementsWithGanttItemTag(IGanttItem ganttItem) { Collection<IGanttItemElement> selectedElements = new Collection<IGanttItemElement>(); foreach (IGanttItemElement element in ganttItem.GanttItemElements) { if (element.Tag == ganttItem.Tag) selectedElements.Add(element); } return selectedElements; }
/// <summary> /// Gets collection of selected elements in necessary Gantt item. /// </summary> /// <param name="selectedType">TYpe of elements which can be added to selection.</param> /// <param name="ganttItem">Parent gantt item.</param> /// <param name="firstSelectedElement">First element in global selection.</param> /// <param name="lastSelectedElement">Last element in global selection.</param> /// <returns>Collection of selected elements.</returns> private ICollection<IGanttItemElement> _GetSelectedElementsByGanttItem(Type selectedType, IGanttItem ganttItem, IGanttItemElement firstSelectedElement, IGanttItemElement lastSelectedElement) { Collection<IGanttItemElement> selectedElements = new Collection<IGanttItemElement>(); int startIndex = 0; int endIndex = ganttItem.GanttItemElements.Count; if (ganttItem.GanttItemElements.Contains(firstSelectedElement)) startIndex = ganttItem.GanttItemElements.IndexOf(firstSelectedElement); if (ganttItem.GanttItemElements.Contains(lastSelectedElement)) endIndex = ganttItem.GanttItemElements.IndexOf(lastSelectedElement) + 1; for (int i = startIndex; i < endIndex; i++) { if (ganttItem.GanttItemElements[i].Tag.GetType() == selectedType) selectedElements.Add(ganttItem.GanttItemElements[i]); } return selectedElements; }
/// <summary> /// Gets collection of selected elements in necessary Gantt item. /// </summary> /// <param name="selectedType">TYpe of elements which can be added to selection.</param> /// <param name="ganttItem">Parent gantt item.</param> /// <param name="firstSelectedElement">First element in global selection.</param> /// <param name="lastSelectedElement">Last element in global selection.</param> /// <returns>Collection of selected elements.</returns> private ICollection <IGanttItemElement> _GetSelectedElementsByGanttItem(Type selectedType, IGanttItem ganttItem, IGanttItemElement firstSelectedElement, IGanttItemElement lastSelectedElement) { Collection <IGanttItemElement> selectedElements = new Collection <IGanttItemElement>(); int startIndex = 0; int endIndex = ganttItem.GanttItemElements.Count; if (ganttItem.GanttItemElements.Contains(firstSelectedElement)) { startIndex = ganttItem.GanttItemElements.IndexOf(firstSelectedElement); } if (ganttItem.GanttItemElements.Contains(lastSelectedElement)) { endIndex = ganttItem.GanttItemElements.IndexOf(lastSelectedElement) + 1; } for (int i = startIndex; i < endIndex; i++) { if (ganttItem.GanttItemElements[i].Tag.GetType() == selectedType) { selectedElements.Add(ganttItem.GanttItemElements[i]); } } return(selectedElements); }
public GanttItemProgressDrawingVisual(IGanttItem item) { GanttItem = item; RedrawRequired = true; }
/// <summary> /// Initializes a new instance of the <c>EmptyGanttItemElement</c> class. /// </summary> public EmptyGanttItemElement(IGanttItem parent) { _startTime = DateTime.MinValue; _endTime = DateTime.MaxValue; _parent = parent; }
/// <summary> /// Adds one "row" of visual elements to necessary gantt item. /// </summary> /// <param name="ganttItem">Gantt item.</param> private void _AddVisualsForGanttItem(IGanttItem ganttItem) { // Define next Gantt item in collection to insert new visuals before it's visuals. int indexOfNextGanttItem = _ganttItems.IndexOf(ganttItem) + 1; if (indexOfNextGanttItem == _ganttItems.Count) // If new item was added to the end of collection. { // Add new visuals to the end of collection. foreach (IGanttItemElement element in ganttItem.GanttItemElements) { GanttItemElementDrawingVisual newVisual = new GanttItemElementDrawingVisual(element); newVisual.RedrawRequired = true; _mapElementToVisual.Add(element, newVisual); // Add pair to dictionary. _children.Add(newVisual); element.RedrawRequired += new EventHandler(_ElementRedrawRequired); } } else { Debug.Assert(false); // TODO : Add code to insert visual to necessary position later if necessary } }
/// <summary> /// Initializes a new instance of the <c>DriveTimeGanttItemElement</c> class. /// </summary> public DriveTimeGanttItemElement(Stop stop, IGanttItem parent) { // Creates route drive time as a gantt item element. _stop = stop; _route = stop.Route; // Cache route value. _parent = parent; // Subscribe on stop changes to notify about updates. _route.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_RoutePropertyChanged); _stop.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_StopPropertyChanged); }
public GanttItemProgressDrawingVisual(IGanttItem item) { GanttItem = item; RedrawRequired = true; }