using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
namespace Braincase.GanttChart
{
///
/// Passive data class holding schedule information
///
[Serializable]
public class Task
{
///
/// Initialize a new task to hold schedule information
///
public Task()
{
Complete = 0.0f;
Start = 0;
End = 1;
Duration = 1;
Slack = 0;
TagValue = "1";
BackFill = Brushes.MediumSlateBlue;
}
///
/// Get or set Task background color
///
public Brush BackFill { get; set; }
///
/// Get or set the Name of this Task
///
public string Name { get; set; }
///
/// Indicate whether this task is collapsed such that sub tasks are hidden from view. Only groups can be collasped.
///
public bool IsCollapsed { get; set; }
///
/// Get or set the pecentage complete of this task, expressed in float between 0.0 and 1.0f.
///
public float Complete { get; internal set; }
public string ID { get; internal set; }
///
/// Task类型 1:工艺路径规划;2:零件是否可见;3:机器人;4:信号点
///
public int Type { get; internal set; }
///
/// 变量代码
///
public string TagID { get; internal set; }
///
/// 变量值
///
public string TagValue { get; internal set; }
///
/// 变量值
///
public int TagFrom { get; internal set; }
///
/// 变量值
///
public string OpName { get; internal set; }
///
/// 拷贝变量值
///
public string TagIDCopyFrom { get; internal set; }
///
/// 模型代码
///
public int ModelCode { get; internal set; }
///
/// 模型是否可见
///
public int Visible { get; internal set; }
///
/// 机器人脚本
///
public string ScriptText { get; internal set; }
///
/// Get the start time of this Task relative to the project start
///
public float Start { get; internal set; }
///
/// Get the end time of this Task relative to the project start
///
public float End { get; internal set; }
///
/// Get the duration of this Task
///
public float Duration { get; internal set; }
///
/// Get the amount of slack (free float)
///
public float Slack { get; internal set; }
///
/// Convert this Task to a descriptive string
///
///
public override string ToString()
{
// return string.Format("[Name = {0}, Start = {1}, End = {2}, Duration = {3}, Complete = {4}, TagID = {5}, TagValue = {6}, ModelCode = {7}]", Name, Start, End, Duration, Complete, TagID, TagValue, ModelCode);
return string.Format("[ID = {0}, TagID = {1},Name = {2}, TagValue = {3},StartTime = {4}, KeepTime = {5},EndTime = {6}]", ID, TagID, Name, TagValue, Start, Duration, End);
}
}
///
/// Time scale in which the time units represent
///
public enum TimeScale
{
///
/// Unit time in Days
///
Day,
///
/// Unit time in Weeks
///
Week,
///
/// Unit time in Others
///
Other
}
///
/// ProjectManager interface
///
/// Task class type
/// Resource class type
public interface IProjectManager
where T : Task
where R : class
{
///
/// Add task to project manager
///
///
void Add(T task);
///
/// Delete task from project manager
///
///
void Delete(T task);
///
/// Group the member task under the group task. Group task cannot have relations.
///
///
///
void Group(T group, T member);
///
/// Ungroup member task from group task. If there are no more task under group, group will become a normal task.
///
///
///
void Ungroup(T group, T member);
///
/// Split the specified task into consecutive parts part1 and part2.
///
/// The regular task to split which has duration of at least 2 to make two parts of 1 time unit duration each.
/// New Task part (1) of the split task, with the start time of the original task and the specified duration value.
/// New Task part (2) of the split task, starting 1 time unit after part (1) ends and having the remaining of the duration of the origina task.
/// The duration of part (1) will be set to the specified duration value but will also be adjusted to approperiate value if necessary.
void Split(T task, T part1, T part2, float duration);
///
/// Split the specified part and obtain another part from it.
///
/// The task part to split which has duration of at least 2 to make two parts of 1 time unit duration each. Its duration will be set to the specified duration value.
/// New Task part of the original part, starting 1 time unit after it ends and having the remaining of the duration of the original part.
/// The duration of part (1) will be set to the specified duration value but will also be adjusted to approperiate value if necessary.
void Split(T part, T another, float duration);
///
/// Join part1 and part2 in a split task into a single part represented by part1, and part2 will be deleted from the ProjectManager.
/// The resulting part will have a duration total of the two parts. Schedule of other parts will be packed according to direction of join.
/// If the join will result in only one part remaining, the split task will merge instead.
///
/// The part to keep in the ProjectManager after the join completes successfully.
/// The part to join into part1 and be deleted afterwards from the ProjectManager.
void Join(T part1, T part2);
///
/// Merge all the parts of the splitted task back into one task, having duration equal to sum of total duration of individual task parts, and aggregating the resources onto the resulting task.
///
/// The split Task to merge
void Merge(T split);
///
/// Get the parts of the split task
///
///
///
IEnumerable PartsOf(T split);
///
/// Get the split task that the specified part belogs to.
///
///
///
T SplitTaskOf(T part);
///
/// Get whether the specified task is a split task
///
///
///
bool IsSplit(T task);
///
/// Get whether the specified task is a part of a split task
///
///
///
bool IsPart(T task);
///
/// Ungroup all member task under the specfied group task. The specified group task will become a normal task.
///
///
void Ungroup(T group);
///
/// Move the specified task by offset positions in the task enumeration
///
///
///
void Move(T task, int offset);
///
/// Set a relation between the precedent and dependant task
///
///
///
void Relate(T precedent, T dependant);
///
/// Unset the relation between the precedent and dependant task, if any.
///
///
///
void Unrelate(T precedent, T dependant);
///
/// Remove all dependant task from specified precedent task
///
///
void Unrelate(T precedent);
///
/// Enumerate through all tasks that is a precedent, having dependants.
///
IEnumerable Precedents { get; }
///
/// Enumerate through all the tasks in the ProjectManager.
/// If there are no change to groups and no add/delete tasks, the order between consecutive calls is preserved.
///
IEnumerable Tasks { get; }
///
/// Set the start time of the specified task.
///
///
/// Number of timescale units after ProjectManager.Start
void SetStart(T task, float start);
///
/// Set the end time of the specified task. Duration is automatically adjusted to satisfy.
///
///
/// Number of timescale units after ProjectManager.Start
void SetEnd(T task, float end);
///
/// Set the duration of the specified task from start to end.
///
///
/// Number of timescale units between ProjectManager.Start
void SetDuration(T task, float duration);
///
/// Set the percentage complete of the specified task from 0.0f to 1.0f.
/// No effect on group tasks as they will get the aggregated percentage complete of all child tasks
///
///
///
void SetComplete(T task, float complete);
///
/// Set whether to collapse the specified group task. No effect on regular tasks.
///
///
///
void SetCollapse(T group, bool collasped);
///
/// Set the "now" time. Its value is the number of timescale units after the start time.
///
int Now { get; }
///
/// Set the start date of the project.
///
DateTime Start { get; set; }
///
/// Get the zero-based index of the specified task
///
///
///
int IndexOf(T task);
///
/// Enumerate through parent group and grandparent groups of the specified task
///
///
///
IEnumerable AncestorsOf(T task);
///
/// Enumerate through all the children and grandchildren of the specified group
///
///
///
IEnumerable DecendantsOf(T group);
///
/// Enumerate through all the direct children of the specified group
///
///
///
IEnumerable ChildrenOf(T group);
///
/// Enumerate through all the direct precedents and indirect precedents of the specified task
///
///
///
IEnumerable PrecedentsOf(T task);
///
/// Enumerate through all the direct dependants and indirect dependants of the specified task
///
///
///
IEnumerable DependantsOf(T task);
///
/// Enumerate through all the direct precedents of the specified task
///
///
///
IEnumerable DirectPrecedentsOf(T task);
///
/// Enumerate through all the direct dependants of the specified task
///
///
///
IEnumerable DirectDependantsOf(T task);
///
/// Enumerate through all the critical paths. Each path is an enumerable of tasks, starting from the final task of each path.
///
IEnumerable> CriticalPaths { get; }
///
/// Get the parent group of the specified task
///
///
///
T ParentOf(T task);
///
/// Get whether the specified task is a group
///
///
///
bool IsGroup(T task);
///
/// Get whether the specified task is a member
///
///
///
bool IsMember(T task);
///
/// Get whether the specified task has relations, either has dependants or has precedents connecting to it.
///
///
///
bool HasRelations(T task);
///
/// Assign the specified resource to the specified task
///
///
///
void Assign(T task, R resource);
///
/// Unassign the specified resource from the specfied task
///
///
///
void Unassign(T task, R resource);
///
/// Unassign all resources from the specified task
///
///
void Unassign(T task);
///
/// Unassign the specified resource from all tasks that has this resource assigned
///
///
void Unassign(R resource);
///
/// Enumerate through all the resources that has been assigned to some task.
///
IEnumerable Resources { get; }
///
/// Enumerate through all the resources that has been assigned to the specified task.
///
///
///
IEnumerable ResourcesOf(T task);
///
/// Enumerate through all the tasks that has the specified resource assigned to it.
///
///
///
IEnumerable TasksOf(R resource);
}
}