37 namespace Controller {
39 ProjectController::ProjectController(AppController* m)
41 HasUnsavedChangesPrompt(
"Project"),
43 m_running_controller(m)
50 QAction* ProjectController::GetActionClose()
const
52 return m_a_close_project;
55 QMenu* ProjectController::GetExportMenu()
const
60 const std::string& ProjectController::GetOpenedFileName()
const
65 const std::string& ProjectController::GetOpenedProjectName()
const
67 return m_project_name;
70 QDockWidget* ProjectController::GetParametersDock()
const
72 return m_container_parameters->GetDock();
75 QMenu* ProjectController::GetParametersMenu()
const
77 return m_container_parameters->GetMenu();
80 QDockWidget* ProjectController::GetPreferencesDock()
const
82 return m_container_preferences->GetDock();
85 QMenu* ProjectController::GetPreferencesMenu()
const
87 return m_container_preferences->GetMenu();
90 ptree ProjectController::GetPTreeState()
const
93 state.put_child(
"container_parameters", m_container_parameters->GetPTreeState());
94 state.put_child(
"container_preferences", m_container_preferences->GetPTreeState());
98 QMenu* ProjectController::GetSimulationMenu()
const
100 return m_m_simulation;
103 ProjectController::Timings ProjectController::GetTimings()
const
108 QMenu* ProjectController::GetViewersMenu()
const
113 void ProjectController::InitActions()
115 m_a_close_project =
new QAction(
"&Close",
this);
116 m_a_close_project->setShortcut(QKeySequence(
"Ctrl+W"));
117 m_a_close_project->setEnabled(
false);
118 connect(m_a_close_project, SIGNAL(triggered()),
this, SLOT(SLOT_Close()));
119 m_enabled_actions.Add(m_a_close_project);
122 void ProjectController::InitBaseClasses()
125 m_container_parameters.get(),
126 m_container_preferences.get()
130 void ProjectController::InitWidgets()
132 m_container_parameters = make_shared<PTreeContainer>(
"Parameters");
133 connect(m_container_parameters.get(), SIGNAL(Applied(
const boost::property_tree::ptree&)),
134 this, SLOT(SLOT_ApplyParameters(
const boost::property_tree::ptree&)));
136 m_container_preferences = make_shared<PTreeContainerPreferencesObserver>(
"Project Preferences");
137 m_container_preferences->SetOnlyEditData(
true);
138 connect(m_container_preferences.get(), SIGNAL(Applied(
const boost::property_tree::ptree&)),
139 this, SLOT(SLOT_ApplyPreferences(
const boost::property_tree::ptree&)));
141 m_m_export =
new QMenu(
"&Export",
this);
142 m_m_export->setEnabled(
false);
143 m_enabled_actions.Add(m_m_export);
145 m_m_viewers =
new QMenu(
"Viewers",
this);
146 m_m_viewers->setEnabled(
false);
147 m_enabled_actions.Add(m_m_viewers);
149 m_m_simulation =
new QMenu(
"&Simulation",
this);
150 m_m_simulation->addAction(m_running_controller.GetActionSingleStep());
151 m_m_simulation->addAction(m_running_controller.GetActionRun());
152 m_m_simulation->addSeparator();
155 void ProjectController::InternalForceClose()
157 m_timings.Merge(m_project->Session().GetTimings());
158 m_enabled_actions.Disable();
159 m_running_controller.Disable();
162 weak_ptr<const void>>::Unregister(m_container_preferences);
166 m_export_actions.reset();
167 m_viewer_actions.reset();
168 m_root_viewer.reset();
174 m_project_name.clear();
177 bool ProjectController::InternalIsClean()
const
182 void ProjectController::InternalPreForceClose()
184 m_project->SetUserData(
"project_controller", GetPTreeState());
187 bool ProjectController::InternalSave()
192 bool ProjectController::IsOpened()
const
194 return (
bool) m_project;
197 bool ProjectController::IsRunning()
const
199 return m_running_controller.IsRunning();
202 bool ProjectController::Set(
const string& project_name,
const shared_ptr<Ws::IProject>& project)
209 m_project_name = project_name;
210 m_file_name = project->GetSessionFileName();
213 m_container_parameters->Open(m_project->Session().GetParameters());
214 m_container_preferences->Open(m_project->GetPreferences());
217 m_root_viewer = m_project->Session().CreateRootViewer(m_main_controller);
220 m_export_actions = make_shared<ProjectActions::ExportActions>(m_project,
221 m_project->Session().GetExporters(), m_main_controller);
222 m_viewer_actions = ProjectActions::ViewerActions::Create(m_root_viewer);
225 for (
auto action : m_export_actions->GetActions())
226 m_m_export->addAction(action);
228 m_m_viewers->clear();
230 for (
auto action : m_viewer_actions->GetMenu()->actions())
231 m_m_viewers->addAction(action);
233 if (m_m_viewers->actions().size() == 0) {
234 auto action = m_m_viewers->addAction(
"No viewers");
235 action->setEnabled(
false);
239 auto handler = bind(&PTreeContainerPreferencesObserver::Update,
240 m_container_preferences.get(), std::placeholders::_1);
242 weak_ptr<const void>>::Register(m_container_preferences, handler);
245 m_running_controller.Enable(m_project);
247 m_enabled_actions.Enable();
249 SetPTreeState(m_project->GetUserData(
"project_controller"));
258 void ProjectController::SetPTreeState(
const ptree& state)
260 auto container_parameters_state = state.get_child_optional(
"container_parameters");
261 if (container_parameters_state) {
262 m_container_parameters->SetPTreeState(container_parameters_state.get());
265 auto container_preferences_state = state.get_child_optional(
"container_preferences");
266 if (container_preferences_state) {
267 m_container_preferences->SetPTreeState(container_preferences_state.get());
271 void ProjectController::SetRunning(
bool b)
273 m_running_controller.SetRunning(b);
276 ProjectController::operator bool()
const
281 void ProjectController::SLOT_ApplyParameters(
const ptree& p)
283 m_project->Session().SetParameters(p);
286 void ProjectController::SLOT_ApplyPreferences(
const ptree& p)
288 m_project->SetPreferences(p);
291 void ProjectController::SLOT_Close()
Event used to inform some observer that preferences have changed.
Namespace for miscellaneous utilities.
Interface for PTreeQtState.
Interface for PTreeContainerPreferencesObserver.
Extremely simple Exception root class.
see the online Qt documentation
see the online Qt documentation
ProjectController header.
see the online Qt documentation
Header file for Exception class.
Namespace for generic graphical shell for simulators.
Interface for PTreeContainer.