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 
79 class Project final : public QObject, public AttributeProvider {
80  Q_OBJECT
81 
82 public:
83  // Constructors / Destructor
84  Project() = delete;
85  Project(const Project& other) = delete;
86 
96  Project(std::unique_ptr<TransactionalDirectory> directory,
97  const QString& filename)
98  : Project(std::move(directory), filename, false) {}
99 
103  ~Project() noexcept;
104 
105  // Getters: General
106 
112  FilePath getFilepath() const noexcept {
113  return mDirectory->getAbsPath(mFilename);
114  }
115 
121  FilePath getPath() const noexcept { return mDirectory->getAbsPath(); }
122 
123  const TransactionalDirectory& getDirectory() const noexcept {
124  return *mDirectory;
125  }
126 
128 
135  StrokeFontPool& getStrokeFonts() const noexcept { return *mStrokeFontPool; }
136 
142  ProjectMetadata& getMetadata() const noexcept { return *mProjectMetadata; }
143 
149  ProjectSettings& getSettings() const noexcept { return *mProjectSettings; }
150 
157  ProjectLibrary& getLibrary() const noexcept { return *mProjectLibrary; }
158 
164  ErcMsgList& getErcMsgList() const noexcept { return *mErcMsgList; }
165 
171  Circuit& getCircuit() const noexcept { return *mCircuit; }
172 
173  // Schematic Methods
174 
176  return *mSchematicLayerProvider;
177  }
178  const SchematicLayerProvider& getLayers() const noexcept {
179  return *mSchematicLayerProvider;
180  }
181 
187  int getSchematicIndex(const Schematic& schematic) const noexcept;
188 
194  const QList<Schematic*>& getSchematics() const noexcept {
195  return mSchematics;
196  }
197 
206  Schematic* getSchematicByIndex(int index) const noexcept {
207  return mSchematics.value(index, nullptr);
208  }
209 
217  Schematic* getSchematicByUuid(const Uuid& uuid) const noexcept;
218 
226  Schematic* getSchematicByName(const QString& name) const noexcept;
227 
237  Schematic* createSchematic(const ElementName& name);
238 
249  void addSchematic(Schematic& schematic, int newIndex = -1);
250 
263  void removeSchematic(Schematic& schematic, bool deleteSchematic = false);
264 
273  void exportSchematicsAsPdf(const FilePath& filepath);
274 
284  void printSchematicPages(QPrinter& printer, QList<int>& pages);
285 
286  // Board Methods
287 
293  int getBoardIndex(const Board& board) const noexcept;
294 
300  const QList<Board*>& getBoards() const noexcept { return mBoards; }
301 
309  Board* getBoardByIndex(int index) const noexcept {
310  return mBoards.value(index, nullptr);
311  }
312 
320  Board* getBoardByUuid(const Uuid& uuid) const noexcept;
321 
329  Board* getBoardByName(const QString& name) const noexcept;
330 
340  Board* createBoard(const ElementName& name);
341 
352  Board* createBoard(const Board& other, const ElementName& name);
353 
364  void addBoard(Board& board, int newIndex = -1);
365 
378  void removeBoard(Board& board, bool deleteBoard = false);
379 
380  // General Methods
381 
387  void save();
388 
389  // Inherited from AttributeProvider
391  QString getUserDefinedAttributeValue(const QString& key) const
392  noexcept override;
394  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
395 
396  // Operator Overloadings
397  bool operator==(const Project& rhs) noexcept { return (this == &rhs); }
398  bool operator!=(const Project& rhs) noexcept { return (this != &rhs); }
399 
400  // Static Methods
401 
402  static Project* create(std::unique_ptr<TransactionalDirectory> directory,
403  const QString& filename) {
404  return new Project(std::move(directory), filename, true);
405  }
406 
407  static bool isFilePathInsideProjectDirectory(const FilePath& fp) noexcept;
408  static bool isProjectFile(const FilePath& file) noexcept;
409  static bool isProjectDirectory(const FilePath& dir) noexcept;
410  static Version getProjectFileFormatVersion(const FilePath& dir);
411 
412 signals:
413 
415  void attributesChanged() override;
416 
422  void schematicAdded(int newIndex);
423 
430  void schematicRemoved(int oldIndex);
431 
437  void boardAdded(int newIndex);
438 
444  void boardRemoved(int oldIndex);
445 
446 private:
447  // Private Methods
448 
463  explicit Project(std::unique_ptr<TransactionalDirectory> directory,
464  const QString& filename, bool create);
465 
466  std::unique_ptr<TransactionalDirectory> mDirectory;
467  QString mFilename;
468 
469  // General
470  QScopedPointer<StrokeFontPool>
472  QScopedPointer<ProjectMetadata>
474  QScopedPointer<ProjectSettings>
476  QScopedPointer<ProjectLibrary>
478  QScopedPointer<ErcMsgList>
481  QScopedPointer<Circuit>
484  QList<Schematic*> mSchematics;
486  QList<Schematic*>
488  QScopedPointer<SchematicLayerProvider>
490  QList<Board*> mBoards;
491  QList<Board*> mRemovedBoards;
492  QScopedPointer<AttributeList>
494 };
495 
496 /*******************************************************************************
497  * End of File
498  ******************************************************************************/
499 
500 } // namespace project
501 } // namespace librepcb
502 
503 #endif // LIBREPCB_PROJECT_PROJECT_H
The Circuit class represents all electrical connections in a project (drawed in the schematics) ...
Definition: circuit.h:72
Board * getBoardByUuid(const Uuid &uuid) const noexcept
Get the board with a specific UUID.
Definition: project.cpp:396
TransactionalDirectory & getDirectory() noexcept
Definition: project.h:127
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
The ProjectLibrary class.
Definition: projectlibrary.h:58
const QList< Board * > & getBoards() const noexcept
Get all boards.
Definition: project.h:300
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:471
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:485
int getBoardIndex(const Board &board) const noexcept
Get the index of a specific board.
Definition: project.cpp:392
The ProjectSettings class.
Definition: projectsettings.h:46
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:477
QList< Board * > mBoards
All boards of this project.
Definition: project.h:490
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:398
SchematicLayerProvider & getLayers() noexcept
Definition: project.h:175
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:79
Project(std::unique_ptr< TransactionalDirectory > directory, const QString &filename)
The constructor to open an existing project with all its content.
Definition: project.h:96
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:309
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:206
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:402
StrokeFontPool & getStrokeFonts() const noexcept
Get the StrokeFontPool which contains all stroke fonts of the project.
Definition: project.h:135
QScopedPointer< AttributeList > mAttributes
all attributes in a specific order
Definition: project.h:493
QString mFilename
the name of the *.lpp project file
Definition: project.h:467
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:194
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:127
const SchematicLayerProvider & getLayers() const noexcept
Definition: project.h:178
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:149
bool operator==(const Project &rhs) noexcept
Definition: project.h:397
const TransactionalDirectory & getDirectory() const noexcept
Definition: project.h:123
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:483
static bool isProjectFile(const FilePath &file) noexcept
Definition: project.cpp:630
QList< Schematic * > mRemovedSchematics
All removed schematics of this project.
Definition: project.h:487
QScopedPointer< ProjectMetadata > mProjectMetadata
e.g. project name, author, ...
Definition: project.h:473
QScopedPointer< ErcMsgList > mErcMsgList
Definition: project.h:480
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:112
QList< Board * > mRemovedBoards
All removed boards of this project.
Definition: project.h:491
Circuit & getCircuit() const noexcept
Get the Circuit object.
Definition: project.h:171
ProjectMetadata & getMetadata() const noexcept
Get the ProjectMetadata object which contains all project metadata.
Definition: project.h:142
QScopedPointer< ProjectSettings > mProjectSettings
all project specific settings
Definition: project.h:475
The StrokeFontPool class.
Definition: strokefontpool.h:46
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: project.h:466
FilePath getPath() const noexcept
Get the path to the project directory.
Definition: project.h:121
ProjectLibrary & getLibrary() const noexcept
Get the ProjectLibrary object which contains all library elements used in this project.
Definition: project.h:157
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:59
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92
ErcMsgList & getErcMsgList() const noexcept
Get the ERC messages list.
Definition: project.h:164
QScopedPointer< SchematicLayerProvider > mSchematicLayerProvider
All schematic layers of this project.
Definition: project.h:489