LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
project.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_PROJECT_PROJECT_H
21 #define LIBREPCB_PROJECT_PROJECT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
32 #include <librepcb/common/uuid.h>
34 
35 #include <QtCore>
36 
37 /*******************************************************************************
38  * Namespace / Forward Declarations
39  ******************************************************************************/
40 class QPrinter;
41 
42 namespace librepcb {
43 
44 class StrokeFontPool;
45 
46 namespace project {
47 
48 class ProjectMetadata;
49 class ProjectSettings;
50 class ProjectLibrary;
51 class Circuit;
52 class Schematic;
53 class SchematicLayerProvider;
54 class ErcMsgList;
55 class Board;
56 
57 /*******************************************************************************
58  * Class Project
59  ******************************************************************************/
60 
82 class Project final : public QObject, public AttributeProvider {
83  Q_OBJECT
84 
85 public:
86  // Constructors / Destructor
87  Project() = delete;
88  Project(const Project& other) = delete;
89 
99  Project(std::unique_ptr<TransactionalDirectory> directory,
100  const QString& filename)
101  : Project(std::move(directory), filename, false) {}
102 
106  ~Project() noexcept;
107 
108  // Getters: General
109 
115  FilePath getFilepath() const noexcept {
116  return mDirectory->getAbsPath(mFilename);
117  }
118 
124  FilePath getPath() const noexcept { return mDirectory->getAbsPath(); }
125 
126  const TransactionalDirectory& getDirectory() const noexcept {
127  return *mDirectory;
128  }
129 
131 
138  StrokeFontPool& getStrokeFonts() const noexcept { return *mStrokeFontPool; }
139 
145  ProjectMetadata& getMetadata() const noexcept { return *mProjectMetadata; }
146 
152  ProjectSettings& getSettings() const noexcept { return *mProjectSettings; }
153 
160  ProjectLibrary& getLibrary() const noexcept { return *mProjectLibrary; }
161 
167  ErcMsgList& getErcMsgList() const noexcept { return *mErcMsgList; }
168 
174  Circuit& getCircuit() const noexcept { return *mCircuit; }
175 
176  // Schematic Methods
177 
179  return *mSchematicLayerProvider;
180  }
181  const SchematicLayerProvider& getLayers() const noexcept {
182  return *mSchematicLayerProvider;
183  }
184 
190  int getSchematicIndex(const Schematic& schematic) const noexcept;
191 
197  const QList<Schematic*>& getSchematics() const noexcept {
198  return mSchematics;
199  }
200 
209  Schematic* getSchematicByIndex(int index) const noexcept {
210  return mSchematics.value(index, nullptr);
211  }
212 
220  Schematic* getSchematicByUuid(const Uuid& uuid) const noexcept;
221 
229  Schematic* getSchematicByName(const QString& name) const noexcept;
230 
240  Schematic* createSchematic(const ElementName& name);
241 
252  void addSchematic(Schematic& schematic, int newIndex = -1);
253 
266  void removeSchematic(Schematic& schematic, bool deleteSchematic = false);
267 
278  void exportSchematicsAsPdf(const FilePath& filepath);
279 
289  void printSchematicPages(QPrinter& printer, QList<int>& pages);
290 
291  // Board Methods
292 
298  int getBoardIndex(const Board& board) const noexcept;
299 
305  const QList<Board*>& getBoards() const noexcept { return mBoards; }
306 
314  Board* getBoardByIndex(int index) const noexcept {
315  return mBoards.value(index, nullptr);
316  }
317 
325  Board* getBoardByUuid(const Uuid& uuid) const noexcept;
326 
334  Board* getBoardByName(const QString& name) const noexcept;
335 
345  Board* createBoard(const ElementName& name);
346 
357  Board* createBoard(const Board& other, const ElementName& name);
358 
369  void addBoard(Board& board, int newIndex = -1);
370 
383  void removeBoard(Board& board, bool deleteBoard = false);
384 
385  // General Methods
386 
392  void save();
393 
394  // Inherited from AttributeProvider
396  QString getUserDefinedAttributeValue(const QString& key) const
397  noexcept override;
399  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
400 
401  // Operator Overloadings
402  bool operator==(const Project& rhs) noexcept { return (this == &rhs); }
403  bool operator!=(const Project& rhs) noexcept { return (this != &rhs); }
404 
405  // Static Methods
406 
407  static Project* create(std::unique_ptr<TransactionalDirectory> directory,
408  const QString& filename) {
409  return new Project(std::move(directory), filename, true);
410  }
411 
412  static bool isFilePathInsideProjectDirectory(const FilePath& fp) noexcept;
413  static bool isProjectFile(const FilePath& file) noexcept;
414  static bool isProjectDirectory(const FilePath& dir) noexcept;
415  static Version getProjectFileFormatVersion(const FilePath& dir);
416 
417 signals:
418 
420  void attributesChanged() override;
421 
427  void schematicAdded(int newIndex);
428 
435  void schematicRemoved(int oldIndex);
436 
442  void boardAdded(int newIndex);
443 
449  void boardRemoved(int oldIndex);
450 
451 private:
452  // Private Methods
453 
468  explicit Project(std::unique_ptr<TransactionalDirectory> directory,
469  const QString& filename, bool create);
470 
471  std::unique_ptr<TransactionalDirectory> mDirectory;
472  QString mFilename;
473 
474  // General
475  QScopedPointer<StrokeFontPool>
477  QScopedPointer<ProjectMetadata>
479  QScopedPointer<ProjectSettings>
481  QScopedPointer<ProjectLibrary>
483  QScopedPointer<ErcMsgList>
486  QScopedPointer<Circuit>
489  QList<Schematic*> mSchematics;
491  QList<Schematic*>
493  QScopedPointer<SchematicLayerProvider>
495  QList<Board*> mBoards;
496  QList<Board*> mRemovedBoards;
497  QScopedPointer<AttributeList>
499 };
500 
501 /*******************************************************************************
502  * End of File
503  ******************************************************************************/
504 
505 } // namespace project
506 } // namespace librepcb
507 
508 #endif // LIBREPCB_PROJECT_PROJECT_H
The Circuit class represents all electrical connections in a project (drawed in the schematics) ...
Definition: circuit.h:75
Board * getBoardByUuid(const Uuid &uuid) const noexcept
Get the board with a specific UUID.
Definition: project.cpp:396
TransactionalDirectory & getDirectory() noexcept
Definition: project.h:130
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
The ProjectLibrary class.
Definition: projectlibrary.h:61
const QList< Board * > & getBoards() const noexcept
Get all boards.
Definition: project.h:305
void schematicAdded(int newIndex)
This signal is emitted after a schematic was added to the project.
QScopedPointer< StrokeFontPool > mStrokeFontPool
all fonts from ./resources/fontobene/
Definition: project.h:476
Schematic * getSchematicByUuid(const Uuid &uuid) const noexcept
Get the schematic page with a specific UUID.
Definition: project.cpp:252
static bool isFilePathInsideProjectDirectory(const FilePath &fp) noexcept
Definition: project.cpp:619
~Project() noexcept
The destructor will close the whole project (without saving!)
Definition: project.cpp:220
Schematic * getSchematicByName(const QString &name) const noexcept
Get the schematic page with a specific name.
Definition: project.cpp:259
The ErcMsgList class contains a list of ERC messages which are visible for the user.
Definition: ercmsglist.h:49
QList< Schematic * > mSchematics
All schematics of this project.
Definition: project.h:490
int getBoardIndex(const Board &board) const noexcept
Get the index of a specific board.
Definition: project.cpp:392
The ProjectSettings class.
Definition: projectsettings.h:49
QString getBuiltInAttributeValue(const QString &key) const noexceptoverride
Get the value of a built-in attribute (if available)
Definition: project.cpp:582
QScopedPointer< ProjectLibrary > mProjectLibrary
Definition: project.h:482
QList< Board * > mBoards
All boards of this project.
Definition: project.h:495
The Schematic class represents one schematic page of a project and is always part of a circuit...
Definition: schematic.h:83
void removeBoard(Board &board, bool deleteBoard=false)
Remove a board from this project.
Definition: project.cpp:476
bool operator!=(const Project &rhs) noexcept
Definition: project.h:403
SchematicLayerProvider & getLayers() noexcept
Definition: project.h:178
void save()
Save the project to the transactional file system.
Definition: project.cpp:501
void addSchematic(Schematic &schematic, int newIndex=-1)
Add an existing schematic to this project.
Definition: project.cpp:284
The Project class represents a whole (opened) project with all its content.
Definition: project.h:82
Project(std::unique_ptr< TransactionalDirectory > directory, const QString &filename)
The constructor to open an existing project with all its content.
Definition: project.h:99
Helper class to access a subdirectory of TransactionalFileSystem.
Definition: transactionaldirectory.h:52
Board * getBoardByIndex(int index) const noexcept
Get the board at a specific index.
Definition: project.h:314
void exportSchematicsAsPdf(const FilePath &filepath)
Export the schematic pages as a PDF.
Definition: project.cpp:344
The ProjectMetadata class.
Definition: projectmetadata.h:45
Schematic * getSchematicByIndex(int index) const noexcept
Get the schematic page at a specific index.
Definition: project.h:209
void printSchematicPages(QPrinter &printer, QList< int > &pages)
Print some schematics to a QPrinter (printer or file)
Definition: project.cpp:362
void addBoard(Board &board, int newIndex=-1)
Add an existing board to this project.
Definition: project.cpp:444
int getSchematicIndex(const Schematic &schematic) const noexcept
Get the page index of a specific schematic.
Definition: project.cpp:248
static bool isProjectDirectory(const FilePath &dir) noexcept
Definition: project.cpp:635
void boardRemoved(int oldIndex)
This signal is emitted after a board was removed from the project.
static Version getProjectFileFormatVersion(const FilePath &dir)
Definition: project.cpp:639
static Project * create(std::unique_ptr< TransactionalDirectory > directory, const QString &filename)
Definition: project.h:407
StrokeFontPool & getStrokeFonts() const noexcept
Get the StrokeFontPool which contains all stroke fonts of the project.
Definition: project.h:138
QScopedPointer< AttributeList > mAttributes
all attributes in a specific order
Definition: project.h:498
QString mFilename
the name of the *.lpp project file
Definition: project.h:472
void schematicRemoved(int oldIndex)
This signal is emitted after a schematic was removed from the project.
void boardAdded(int newIndex)
This signal is emitted after a board was added to the project.
Schematic * createSchematic(const ElementName &name)
Create a new schematic (page)
Definition: project.cpp:266
void attributesChanged() override
This signal is emited when the value of attributes has changed.
const QList< Schematic * > & getSchematics() const noexcept
Get all schematics.
Definition: project.h:197
Board * createBoard(const ElementName &name)
Create a new board.
Definition: project.cpp:410
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
const SchematicLayerProvider & getLayers() const noexcept
Definition: project.h:181
The SchematicLayerProvider class provides and manages all available schematic layers which are used i...
Definition: schematiclayerprovider.h:47
ProjectSettings & getSettings() const noexcept
Get the ProjectSettings object which contains all project settings.
Definition: project.h:152
bool operator==(const Project &rhs) noexcept
Definition: project.h:402
const TransactionalDirectory & getDirectory() const noexcept
Definition: project.h:126
QString getUserDefinedAttributeValue(const QString &key) const noexceptoverride
Get the value of a user defined attribute (if available)
Definition: project.cpp:573
void removeSchematic(Schematic &schematic, bool deleteSchematic=false)
Remove a schematic from this project.
Definition: project.cpp:316
QScopedPointer< Circuit > mCircuit
Definition: project.h:488
static bool isProjectFile(const FilePath &file) noexcept
Definition: project.cpp:630
QList< Schematic * > mRemovedSchematics
All removed schematics of this project.
Definition: project.h:492
QScopedPointer< ProjectMetadata > mProjectMetadata
e.g. project name, author, ...
Definition: project.h:478
QScopedPointer< ErcMsgList > mErcMsgList
Definition: project.h:485
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:82
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Board * getBoardByName(const QString &name) const noexcept
Get the board with a specific name.
Definition: project.cpp:403
FilePath getFilepath() const noexcept
Get the filepath of the project file (*.lpp)
Definition: project.h:115
QList< Board * > mRemovedBoards
All removed boards of this project.
Definition: project.h:496
Circuit & getCircuit() const noexcept
Get the Circuit object.
Definition: project.h:174
ProjectMetadata & getMetadata() const noexcept
Get the ProjectMetadata object which contains all project metadata.
Definition: project.h:145
QScopedPointer< ProjectSettings > mProjectSettings
all project specific settings
Definition: project.h:480
The StrokeFontPool class.
Definition: strokefontpool.h:46
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: project.h:471
FilePath getPath() const noexcept
Get the path to the project directory.
Definition: project.h:124
ProjectLibrary & getLibrary() const noexcept
Get the ProjectLibrary object which contains all library elements used in this project.
Definition: project.h:160
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:62
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92
ErcMsgList & getErcMsgList() const noexcept
Get the ERC messages list.
Definition: project.h:167
QScopedPointer< SchematicLayerProvider > mSchematicLayerProvider
All schematic layers of this project.
Definition: project.h:494