VPTissue Reference Manual
Project.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "Project.h"
21 
22 #include "common/InstallDirs.h"
24 #include "gui/ConverterWindow.h"
25 #include "ptree/PTreeUtils.h"
26 #include "workspace/Project_def.h"
27 
28 #include <QAction>
29 
30 using namespace std;
31 using namespace boost::property_tree;
32 using namespace boost::property_tree::xml_parser;
33 using namespace SimPT_Sim::Util;
34 
35 namespace SimShell {
36 namespace Ws {
37  template class Project<SimPT_Shell::Ws::StartupFileBase,
38  SimPT_Shell::Ws::WorkspaceFactory::g_project_index_file>;
39 } // Ws
40 } // SimShell
41 
42 
43 namespace SimPT_Shell {
44 namespace Ws {
45 
46 Project::Project(const string& path,
47  const string& prefs_file,
48  const shared_ptr<SimShell::Ws::IWorkspace>& w)
49  : SimPTProjectBase(path, prefs_file, w)
50 {
51  auto prefs_path = path + '/' + prefs_file;
52 
53  if (!QFile::exists(QString::fromStdString(prefs_path))) {
54  ptree default_preferences;
55  ptree new_preferences;
56 
57  WorkspaceFactory f;
58  const string default_prefs_file = f.GetWorkspaceTemplatePath() + '/' + prefs_file;
59  read_xml(default_prefs_file, default_preferences, trim_whitespace);
60  default_preferences = default_preferences.get_child("preferences");
61 
62  // Make sure this workspace's preferences contains all the keys from default-preferences.xml.
63  PTreeUtils::CopyStructure(default_preferences, new_preferences, "$WORKSPACE$", {"<xmlcomment>"});
64 
65  SetPreferences(new_preferences);
66  }
67 }
68 
70 {
71 }
72 
73 const Project::ConstructorType Project::Constructor({
74  [](const string& type, const string& path, const string& prefs_file, const shared_ptr<SimShell::Ws::IWorkspace>& w)
75  -> shared_ptr<SimShell::Ws::IProject>
76  {
77  if (type == "project") {
78  return make_shared<Project>(path, prefs_file, w);
79  } else {
80  return nullptr;
81  }
82  }
83 });
84 
85 std::vector<QAction*> Project::GetContextMenuActions() const
86 {
87  return {};
88 }
89 
90 std::vector<Project::WidgetCallback> Project::GetWidgets()
91 {
92  auto create_window = [this](vector<IConverterFormat*> formats, const string& title,
93  shared_ptr<SimShell::Ws::MergedPreferences> p, QWidget* parent) {
94  auto conv_window = make_shared<ConverterWindow>(this, formats, p, title, parent);
95  conv_window->show();
96  m_converter_window = conv_window; // keep weak_ptr to created widget
97  return conv_window;
98  };
99  return {{"Convert...", bind(create_window, FileConverterFormats::GetConverterFormats(),
100  "Convert Project", placeholders::_1, placeholders::_2)},
101  {"Postprocess...", bind(create_window, FileConverterFormats::GetExportFormats(),
102  "Postprocess Project", placeholders::_1, placeholders::_2)}};
103 }
104 
106 {
108  if (auto c = m_converter_window.lock()) {
109  c->Refresh();
110  }
111 }
112 
113 
114 } // namespace
115 } // namespace
virtual std::vector< QAction * > GetContextMenuActions() const
Definition: Project.cpp:85
STL namespace.
Namespace for miscellaneous utilities.
Definition: PTreeFile.cpp:44
Interface for SimPT projects.
Namespace for SimPT shell package.
Definition: Client.cpp:50
virtual std::vector< WidgetCallback > GetWidgets()
Definition: Project.cpp:90
PTreeUtils interface.
Interface for ConverterWindow.
virtual ~Project()
Virtual destructor.
Definition: Project.cpp:69
virtual void Refresh()
Overrides SimShell::Ws::Project::Refresh.
Definition: Project.cpp:105
Interface of file converter formats.
Implementation for Project.
Base class representing the file types used to initiate a session.
see the online Qt documentation
std::function< std::shared_ptr< IProject >(const std::string &, const std::string &, const std::string &, const std::shared_ptr< IWorkspace > &)> ConstructorType
First argument : type of project to create.
Definition: IProject.h:71
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32
virtual void Refresh()
Definition: Project_def.h:279
Interface for FileSys.