Project Calculation Modes

Overview

Project calculation modes are used to set how the project should calculate project dates, cost and other necessary fields. Aspose.Tasks for C++ API provides three project calculation modes where each mode’s output is different based on the selection. These calculation modes are:

The code examples given below demonstrates the usage of each of the calculation modes.

Project Calculation Mode - None

 1// Create empty project and set calculation mode to None
 2System::SharedPtr<Project> project = System::MakeObject<Project>();
 3project->set_CalculationMode(Aspose::Tasks::CalculationMode::None);
 4    
 5// Add a new task
 6System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->Add(u"Task");
 7    
 8// Note that even ids were not calculated            
 9System::Console::WriteLine(u"Task.Id Equals 0 : {0} ", System::ObjectExt::Box<bool>(System::Equals(task->Get<int32_t>(Tsk::Id()), 0)));
10System::Console::WriteLine(u"Task.OutlineLevel Equals 0 : {0} ", System::ObjectExt::Box<bool>(System::Equals(task->Get<int32_t>(Tsk::OutlineLevel()), 0)));
11System::Console::WriteLine(u"Task Start Equals DateTime.MinValue : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task->Get<System::DateTime>(Tsk::Start()), System::DateTime::MinValue)));
12System::Console::WriteLine(u"Task Finish Equals DateTime.MinValue : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task->Get<System::DateTime>(Tsk::Finish()), System::DateTime::MinValue)));
13System::Console::WriteLine(u"Task Duration Equals 0 mins : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(System::ObjectExt::ToString(task->Get<Duration>(Tsk::Duration())), u"0 mins")));
14    
15// Set duration property
16task->Set<Duration>(Tsk::Duration(), project->GetDuration(2, Aspose::Tasks::TimeUnitType::Day));
17System::Console::WriteLine(u"Task Duration Equals 2 days : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(System::ObjectExt::ToString(task->Get<Duration>(Tsk::Duration())), u"2 days")));
18System::Console::WriteLine(u"Task Start Equals DateTime.MinValue  : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task->Get<System::DateTime>(Tsk::Start()), System::DateTime::MinValue)));
19System::Console::WriteLine(u"Task Finish Equals DateTime.MinValue  : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task->Get<System::DateTime>(Tsk::Finish()), System::DateTime::MinValue)));

Project Calculation Mode - Manual

 1// Create empty project and set calculation mode to Manual
 2System::SharedPtr<Project> project = System::MakeObject<Project>();
 3project->set_CalculationMode(Aspose::Tasks::CalculationMode::Manual);
 4    
 5// Set project start date and add new tasks
 6project->Set(Prj::StartDate(), System::DateTime(2015, 4, 15));
 7System::SharedPtr<Task> task1 = project->get_RootTask()->get_Children()->Add(u"Task 1");
 8System::SharedPtr<Task> task2 = project->get_RootTask()->get_Children()->Add(u"Task 2");
 9    
10// The necessary properties are set in manual mode
11System::Console::WriteLine(u"Task1.Id Equals 1 : {0} ", System::ObjectExt::Box<bool>(System::Equals(task1->Get<int32_t>(Tsk::Id()), 1)));
12System::Console::WriteLine(u"Task1 OutlineLevel Equals 1 : {0} ", System::ObjectExt::Box<bool>(System::Equals(task1->Get<int32_t>(Tsk::OutlineLevel()), 1)));
13System::Console::WriteLine(u"Task1 Start Equals 15/04/2015 08:00 AM : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task1->Get<System::DateTime>(Tsk::Start()), System::DateTime(2015, 4, 15, 8, 0, 0))));
14System::Console::WriteLine(u"Task1 Finish Equals 15/04/2015 05:00 PM : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task1->Get<System::DateTime>(Tsk::Finish()), System::DateTime(2015, 4, 15, 17, 0, 0))));
15System::Console::WriteLine(u"Task1 Duration Equals 1 day : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(System::ObjectExt::ToString(task1->Get<Duration>(Tsk::Duration())), u"1 day")));
16System::Console::WriteLine(u"Task2 Start Equals 15/04/2015 08:00 AM : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task2->Get<System::DateTime>(Tsk::Start()), System::DateTime(2015, 4, 15, 8, 0, 0))));
17System::Console::WriteLine(u"Task2 Finish Equals 15/04/2015 05:00 PM : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task2->Get<System::DateTime>(Tsk::Finish()), System::DateTime(2015, 4, 15, 17, 0, 0))));
18System::Console::WriteLine(u"Task2 Duration Equals 1 day : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(System::ObjectExt::ToString(task2->Get<Duration>(Tsk::Duration())), u"1 day")));
19    
20// When we link two tasks together their dates are not recalculated in manual mode
21System::SharedPtr<TaskLink> link = project->get_TaskLinks()->Add(task1, task2, Aspose::Tasks::TaskLinkType::FinishToStart);
22    
23// Task 2 Start has not been changed
24System::Console::WriteLine(u"Task1 Start Equals Task2 Start : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task1->Get<System::DateTime>(Tsk::Start()), task2->Get<System::DateTime>(Tsk::Start()))));
25System::Console::WriteLine(u"Task1 Finish Equals Task2 Finish : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task1->Get<System::DateTime>(Tsk::Finish()), task2->Get<System::DateTime>(Tsk::Finish()))));

Project Calculation Mode - Automatic

 1// Create empty project and set calculation mode to Automatic
 2System::SharedPtr<Project> project = System::MakeObject<Project>();
 3project->set_CalculationMode(Aspose::Tasks::CalculationMode::Automatic);
 4    
 5// Set project start date and add new tasks
 6project->Set(Prj::StartDate(), System::DateTime(2015, 4, 15));
 7System::SharedPtr<Task> task1 = project->get_RootTask()->get_Children()->Add(u"Task 1");
 8System::SharedPtr<Task> task2 = project->get_RootTask()->get_Children()->Add(u"Task 2");
 9    
10// Link tasks
11System::SharedPtr<TaskLink> link = project->get_TaskLinks()->Add(task1, task2, Aspose::Tasks::TaskLinkType::FinishToStart);
12    
13// Verify dates have been recalculated
14System::Console::WriteLine(u"Task1 Start + 1 Equals Task2 Start : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task1->Get<System::DateTime>(Tsk::Start()).AddDays(1), task2->Get<System::DateTime>(Tsk::Start()))));
15System::Console::WriteLine(u"Task1 Finish + 1 Equals Task2 Finish : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task1->Get<System::DateTime>(Tsk::Finish()).AddDays(1), task2->Get<System::DateTime>(Tsk::Finish()))));
16System::Console::WriteLine(u"RootTask Finish Equals Task2 Finish : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task2->Get<System::DateTime>(Tsk::Finish()), project->get_RootTask()->Get<System::DateTime>(Tsk::Finish()))));
17System::Console::WriteLine(u"Project Finish Date Equals Task2 Finish : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(task2->Get<System::DateTime>(Tsk::Finish()), project->Get<System::DateTime>(Prj::FinishDate()))));
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.