HAL
project_manager.cpp
Go to the documentation of this file.
2 
3 namespace hal
4 {
6  {
7  py::class_<ProjectManager, RawPtrWrapper<ProjectManager>> py_project_manager(m, "ProjectManager", R"(
8  Project manager class that handles opening, closing, and saving of projects.
9  )");
10 
11  py::enum_<ProjectManager::ProjectStatus> py_project_status(py_project_manager, "ProjectStatus", R"(
12  Represents the logic value that a Boolean function operates on.
13  )");
14 
15  py_project_status.value("NONE", ProjectManager::ProjectStatus::NONE, R"(Represents the default state.)")
16  .value("OPENED", ProjectManager::ProjectStatus::OPENED, R"(Represents an open project state.)")
17  .value("SAVED", ProjectManager::ProjectStatus::SAVED, R"(Represents a saved project state.)")
18  .export_values();
19 
20  py::class_<ProjectDirectory, RawPtrWrapper<ProjectDirectory>> py_project_directory(m, "ProjectDirectory", R"(
21  Represents a project directory.
22  )");
23 
24  py_project_directory.def(py::init<const std::string&>(), py::arg("path") = std::string(), R"(
25  Constructs a ProjectDirectory object.
26 
27  :param str path: Path to the project directory. If empty, an empty path is used.
28  )");
29 
30  py_project_directory.def("get_default_filename", &ProjectDirectory::get_default_filename, py::arg("extension") = std::string(), R"(
31  Returns the default file name for the project directory.
32 
33  :param str extension: Extension of the default file name. If empty, '.hal' is assumed.
34  :returns: The absolute path to the default file.
35  :rtype: str
36  )");
37 
38  py_project_directory.def("get_filename", &ProjectDirectory::get_filename, py::arg("relative_filename"), R"(
39  Returns the absolute path to a file within the project directory.
40 
41  :param str relative_filename: The relative file name within the project directory.
42  :returns: The absolute path to the file.
43  :rtype: str
44  )");
45 
46  py_project_directory.def("get_shadow_filename", &ProjectDirectory::get_shadow_filename, py::arg("extension") = std::string(), R"(
47  Returns the file name within the autosave (shadow) directory.
48 
49  :param str extension: Extension of the shadow file name. If empty, '.hal' is assumed.
50  :returns: The absolute path to the shadow file.
51  :rtype: str
52  )");
53 
54  py_project_directory.def("get_shadow_dir", &ProjectDirectory::get_shadow_dir, R"(
55  Returns the path to the autosave (shadow) directory.
56 
57  :returns: The absolute path to the autosave directory.
58  :rtype: str
59  )");
60 
61  py_project_directory.def("get_canonical_path", &ProjectDirectory::get_canonical_path, R"(
62  Returns the canonical path to the project directory.
63 
64  :returns: The absolute canonical path to the project directory. If no project path is given, an empty path is returned.
65  :rtype: str
66  )");
67 
68  py_project_directory.def("get_relative_file_path", &ProjectDirectory::get_relative_file_path, py::arg("filename"), R"(
69  Returns the relative file path if the file is within the project directory.
70 
71  :param str filename: The absolute path to the file.
72  :returns: The relative file path if the file is within the project directory; otherwise, the original filename.
73  :rtype: str
74  )");
75 
76  py_project_directory.def_static("generate_random", &ProjectDirectory::generate_random, R"(
77  Generates a random directory name in the current working directory.
78 
79  :returns: The absolute path to the generated directory.
80  :rtype: str
81  )");
82 
83  py_project_directory.attr("s_shadow_dir") = ProjectDirectory::s_shadow_dir;
84 
85 
86  py_project_manager.def_static("instance", &ProjectManager::instance, R"(
87  Returns the singleton instance which gets constructed upon first call.
88 
89  :returns: The singleton instance.
90  :rtype: hal_py.ProjectManager
91  )");
92 
93  // TODO register_serializer
94 
95  // TODO unregister_serializer
96 
97  py_project_manager.def("get_project_status", &ProjectManager::get_project_status, R"(
98  Returns the current project status.
99 
100  :returns: The project status value.
101  :rtype: hal_py.ProjectManager.ProjectStatus
102  )");
103 
104  py_project_manager.def("set_project_status", &ProjectManager::set_project_status, py::arg("status"), R"(
105  Set the current project status to a new value.
106  Must be called when a project is closed.
107 
108  :param hal_py.ProjectManager.ProjectStatus status: The new project status value.
109  )");
110 
111  py_project_manager.def("get_filename", &ProjectManager::get_filename, py::arg("serializer_name"), R"(
112  Returns the relative path of the file to be parsed by an external serializer.
113 
114  :param str serializer_name: The unique name of the serializer.
115  :returns: The relative file path.
116  :rtype: str
117  )");
118 
119  py_project_manager.def("set_gate_library_path", &ProjectManager::set_gate_library_path, py::arg("gl_path"), R"(
120  Set the path to the gate library file.
121 
122  :param str gl_path: The path to the gate library file.
123  )");
124 
125  py_project_manager.def("serialize_project", &ProjectManager::serialize_project, py::arg("netlist"), py::arg("shadow") = false, R"(
126  Serialize the netlist and all dependent data to the project directory.
127 
128  :param hal_py.Netlist netlist: The netlist.
129  :param bool shadow: Set to True if function is called from autosave procedure, False otherwise. Defaults to False.
130  :returns: True if serialization of the netlist was successful, False otherwise.
131  :rtype: bool
132  )");
133 
134  py_project_manager.def("open_project", &ProjectManager::open_project, py::arg("path") = std::string(), R"(
135  Open the project specified by the provided directory path.
136 
137  :param str path: The path to the project directory. Can be omitted if the path was previously set using `ProjectManager::set_project_directory`.
138  :returns: True on success, False otherwise.
139  :rtype: bool
140  )");
141 
142  py_project_manager.def("get_project_directory", &ProjectManager::get_project_directory, R"(
143  Returns project directory.
144 
145  :returns: project directory
146  :rtype: hal_py.ProjectDirectory
147  )");
148 
149  py_project_manager.def("set_project_directory", &ProjectManager::set_project_directory, py::arg("path"), R"(
150  Set path to the project directory.
151 
152  :param str path: The path to the project directory.
153  )");
154 
155  // TODO restore_project_file_from_autosave
156 
157  py_project_manager.def("create_project_directory", &ProjectManager::create_project_directory, py::arg("path"), R"(
158  Create an empty project directory at the specified location.
159  The project directory must not exist.
160 
161  :param str path: The path to the new project directory.
162  :returns: True on success, False otherwise.
163  :rtype: bool
164  )");
165 
166  py_project_manager.def("remove_project_directory", &ProjectManager::remove_project_directory, R"(
167  Remove the existing project directory and clear the path member variable.
168 
169  :returns: True on success, False otherwise.
170  :rtype: bool
171  )");
172 
173  py_project_manager.def("get_netlist_filename", &ProjectManager::get_netlist_filename, R"(
174  Returns the path to the netlist file.
175 
176  :returns: The netlist file path.
177  :rtype: str
178  )");
179  }
180 } // namespace hal
std::filesystem::path get_filename(const std::string &relative_filename) const
std::filesystem::path get_relative_file_path(const std::string &filename) const
std::filesystem::path get_canonical_path() const
static const std::string s_shadow_dir
static ProjectDirectory generate_random()
std::filesystem::path get_shadow_filename(const std::string &extension=std::string()) const
std::filesystem::path get_default_filename(const std::string &extension=std::string()) const
std::filesystem::path get_shadow_dir() const
static ProjectManager * instance()
void set_project_status(ProjectStatus status)
bool create_project_directory(const std::string &path)
bool serialize_project(Netlist *netlist, bool shadow=false)
void set_gate_library_path(const std::string &gl_path)
std::string get_filename(const std::string &serializer_name)
ProjectStatus get_project_status() const
std::string get_netlist_filename() const
bool open_project(const std::string &path="")
const ProjectDirectory & get_project_directory() const
void set_project_directory(const std::string &path)
void project_manager_init(py::module &m)
const Module * module(const Gate *g, const NodeBoxes &boxes)