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  ******************************************************************************/
31 #include <librepcb/common/uuid.h>
33 
34 #include <QtCore>
35 
36 /*******************************************************************************
37  * Namespace / Forward Declarations
38  ******************************************************************************/
39 class QPrinter;
40 
41 namespace librepcb {
42 
43 class SmartTextFile;
44 class SmartSExprFile;
45 class SmartVersionFile;
46 class StrokeFontPool;
47 
48 namespace project {
49 
50 class ProjectMetadata;
51 class ProjectSettings;
52 class ProjectLibrary;
53 class Circuit;
54 class Schematic;
55 class SchematicLayerProvider;
56 class ErcMsgList;
57 class Board;
58 
59 /*******************************************************************************
60  * Class Project
61  ******************************************************************************/
62 
84 class Project final : public QObject, public AttributeProvider {
85  Q_OBJECT
86 
87 public:
88  // Constructors / Destructor
89  Project() = delete;
90  Project(const Project& other) = delete;
91 
101  Project(const FilePath& filepath, bool readOnly, bool interactve)
102  : Project(filepath, false, readOnly, interactve) {}
103 
107  ~Project() noexcept;
108 
109  // Getters: General
110 
116  const FilePath& getFilepath() const noexcept { return mFilepath; }
117 
123  const FilePath& getPath() const noexcept { return mPath; }
124 
130  bool isReadOnly() const noexcept { return mIsReadOnly; }
131 
137  bool isRestored() const noexcept { return mIsRestored; }
138 
145  StrokeFontPool& getStrokeFonts() const noexcept { return *mStrokeFontPool; }
146 
152  ProjectMetadata& getMetadata() const noexcept { return *mProjectMetadata; }
153 
159  ProjectSettings& getSettings() const noexcept { return *mProjectSettings; }
160 
167  ProjectLibrary& getLibrary() const noexcept { return *mProjectLibrary; }
168 
174  ErcMsgList& getErcMsgList() const noexcept { return *mErcMsgList; }
175 
181  Circuit& getCircuit() const noexcept { return *mCircuit; }
182 
183  // Schematic Methods
184 
186  return *mSchematicLayerProvider;
187  }
188  const SchematicLayerProvider& getLayers() const noexcept {
189  return *mSchematicLayerProvider;
190  }
191 
197  int getSchematicIndex(const Schematic& schematic) const noexcept;
198 
204  const QList<Schematic*>& getSchematics() const noexcept {
205  return mSchematics;
206  }
207 
216  Schematic* getSchematicByIndex(int index) const noexcept {
217  return mSchematics.value(index, nullptr);
218  }
219 
227  Schematic* getSchematicByUuid(const Uuid& uuid) const noexcept;
228 
236  Schematic* getSchematicByName(const QString& name) const noexcept;
237 
247  Schematic* createSchematic(const ElementName& name);
248 
259  void addSchematic(Schematic& schematic, int newIndex = -1);
260 
273  void removeSchematic(Schematic& schematic, bool deleteSchematic = false);
274 
285  void exportSchematicsAsPdf(const FilePath& filepath);
286 
296  void printSchematicPages(QPrinter& printer, QList<int>& pages);
297 
298  // Board Methods
299 
305  int getBoardIndex(const Board& board) const noexcept;
306 
312  const QList<Board*>& getBoards() const noexcept { return mBoards; }
313 
321  Board* getBoardByIndex(int index) const noexcept {
322  return mBoards.value(index, nullptr);
323  }
324 
332  Board* getBoardByUuid(const Uuid& uuid) const noexcept;
333 
341  Board* getBoardByName(const QString& name) const noexcept;
342 
352  Board* createBoard(const ElementName& name);
353 
364  Board* createBoard(const Board& other, const ElementName& name);
365 
376  void addBoard(Board& board, int newIndex = -1);
377 
390  void removeBoard(Board& board, bool deleteBoard = false);
391 
392  // General Methods
393 
403  void save(bool toOriginal);
404 
405  // Inherited from AttributeProvider
407  QString getUserDefinedAttributeValue(const QString& key) const
408  noexcept override;
410  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
411 
412  // Operator Overloadings
413  bool operator==(const Project& rhs) noexcept { return (this == &rhs); }
414  bool operator!=(const Project& rhs) noexcept { return (this != &rhs); }
415 
416  // Static Methods
417 
418  static Project* create(const FilePath& filepath) {
419  return new Project(filepath, true, false, false);
420  }
421 
422  static bool isFilePathInsideProjectDirectory(const FilePath& fp) noexcept;
423  static bool isProjectFile(const FilePath& file) noexcept;
424  static bool isProjectDirectory(const FilePath& dir) noexcept;
425  static Version getProjectFileFormatVersion(const FilePath& dir);
426 
427 signals:
428 
430  void attributesChanged() override;
431 
437  void schematicAdded(int newIndex);
438 
445  void schematicRemoved(int oldIndex);
446 
452  void boardAdded(int newIndex);
453 
459  void boardRemoved(int oldIndex);
460 
461 private:
462  // Private Methods
463 
478  explicit Project(const FilePath& filepath, bool create, bool readOnly,
479  bool interactve);
480 
492  bool save(bool toOriginal, QStringList& errors) noexcept;
493 
494  // Project File (*.lpp)
497  QScopedPointer<SmartVersionFile>
499  QScopedPointer<SmartTextFile> mProjectFile;
501  bool mIsRestored;
503  bool mIsReadOnly;
505 
507  // schematic and board list files
508  QScopedPointer<SmartSExprFile> mSchematicsFile;
509  QScopedPointer<SmartSExprFile> mBoardsFile;
510 
511  // General
512  QScopedPointer<StrokeFontPool>
514  QScopedPointer<ProjectMetadata>
516  QScopedPointer<ProjectSettings>
518  QScopedPointer<ProjectLibrary>
520  QScopedPointer<ErcMsgList>
523  QScopedPointer<Circuit>
526  QList<Schematic*> mSchematics;
528  QList<Schematic*>
530  QScopedPointer<SchematicLayerProvider>
532  QList<Board*> mBoards;
533  QList<Board*> mRemovedBoards;
534  QScopedPointer<AttributeList>
536 };
537 
538 /*******************************************************************************
539  * End of File
540  ******************************************************************************/
541 
542 } // namespace project
543 } // namespace librepcb
544 
545 #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:587
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
QScopedPointer< SmartTextFile > mProjectFile
the *.lpp project file
Definition: project.h:499
QScopedPointer< SmartSExprFile > mBoardsFile
core/boards.lp
Definition: project.h:509
The ProjectLibrary class.
Definition: projectlibrary.h:59
const QList< Board * > & getBoards() const noexcept
Get all boards.
Definition: project.h:312
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:513
Project(const FilePath &filepath, bool readOnly, bool interactve)
The constructor to open an existing project with all its content.
Definition: project.h:101
Schematic * getSchematicByUuid(const Uuid &uuid) const noexcept
Get the schematic page with a specific UUID.
Definition: project.cpp:443
static bool isFilePathInsideProjectDirectory(const FilePath &fp) noexcept
Definition: project.cpp:753
~Project() noexcept
The destructor will close the whole project (without saving!)
Definition: project.cpp:411
bool mIsReadOnly
Definition: project.h:504
Schematic * getSchematicByName(const QString &name) const noexcept
Get the schematic page with a specific name.
Definition: project.cpp:450
The ErcMsgList class contains a list of ERC messages which are visible for the user.
Definition: ercmsglist.h:52
QList< Schematic * > mSchematics
All schematics of this project.
Definition: project.h:527
int getBoardIndex(const Board &board) const noexcept
Get the index of a specific board.
Definition: project.cpp:583
The ProjectSettings class.
Definition: projectsettings.h:52
QString getBuiltInAttributeValue(const QString &key) const noexceptoverride
Get the value of a built-in attribute (if available)
Definition: project.cpp:716
FilePath mFilepath
the filepath of the *.lpp project file
Definition: project.h:496
QScopedPointer< ProjectLibrary > mProjectLibrary
Definition: project.h:519
QList< Board * > mBoards
All boards of this project.
Definition: project.h:532
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:665
bool operator!=(const Project &rhs) noexcept
Definition: project.h:414
SchematicLayerProvider & getLayers() noexcept
Definition: project.h:185
void addSchematic(Schematic &schematic, int newIndex=-1)
Add an existing schematic to this project.
Definition: project.cpp:475
The Project class represents a whole (opened) project with all its content.
Definition: project.h:84
Board * getBoardByIndex(int index) const noexcept
Get the board at a specific index.
Definition: project.h:321
void exportSchematicsAsPdf(const FilePath &filepath)
Export the schematic pages as a PDF.
Definition: project.cpp:535
The ProjectMetadata class.
Definition: projectmetadata.h:54
Schematic * getSchematicByIndex(int index) const noexcept
Get the schematic page at a specific index.
Definition: project.h:216
void printSchematicPages(QPrinter &printer, QList< int > &pages)
Print some schematics to a QPrinter (printer or file)
Definition: project.cpp:553
void addBoard(Board &board, int newIndex=-1)
Add an existing board to this project.
Definition: project.cpp:633
int getSchematicIndex(const Schematic &schematic) const noexcept
Get the page index of a specific schematic.
Definition: project.cpp:439
static bool isProjectDirectory(const FilePath &dir) noexcept
Definition: project.cpp:769
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:773
StrokeFontPool & getStrokeFonts() const noexcept
Get the StrokeFontPool which contains all stroke fonts of the project.
Definition: project.h:145
QScopedPointer< AttributeList > mAttributes
all attributes in a specific order
Definition: project.h:535
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.
DirectoryLock mLock
Definition: project.h:500
Schematic * createSchematic(const ElementName &name)
Create a new schematic (page)
Definition: project.cpp:457
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:204
bool isRestored() const noexcept
Check whether this project restored from temporary files or not.
Definition: project.h:137
const FilePath & getFilepath() const noexcept
Get the filepath of the project file (*.lpp)
Definition: project.h:116
static Project * create(const FilePath &filepath)
Definition: project.h:418
Board * createBoard(const ElementName &name)
Create a new board.
Definition: project.cpp:601
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
const SchematicLayerProvider & getLayers() const noexcept
Definition: project.h:188
The SchematicLayerProvider class provides and manages all available schematic layers which are used i...
Definition: schematiclayerprovider.h:47
const FilePath & getPath() const noexcept
Get the path to the project directory.
Definition: project.h:123
FilePath mPath
the path to the project directory
Definition: project.h:495
ProjectSettings & getSettings() const noexcept
Get the ProjectSettings object which contains all project settings.
Definition: project.h:159
bool operator==(const Project &rhs) noexcept
Definition: project.h:413
QString getUserDefinedAttributeValue(const QString &key) const noexceptoverride
Get the value of a user defined attribute (if available)
Definition: project.cpp:707
void removeSchematic(Schematic &schematic, bool deleteSchematic=false)
Remove a schematic from this project.
Definition: project.cpp:507
QScopedPointer< Circuit > mCircuit
Definition: project.h:525
static bool isProjectFile(const FilePath &file) noexcept
Definition: project.cpp:764
bool mIsRestored
Definition: project.h:502
QList< Schematic * > mRemovedSchematics
All removed schematics of this project.
Definition: project.h:529
QScopedPointer< ProjectMetadata > mProjectMetadata
e.g. project name, author, ...
Definition: project.h:515
void save(bool toOriginal)
Save the whole project to the harddisc.
Definition: project.cpp:690
QScopedPointer< ErcMsgList > mErcMsgList
Definition: project.h:522
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:594
QList< Board * > mRemovedBoards
All removed boards of this project.
Definition: project.h:533
QScopedPointer< SmartSExprFile > mSchematicsFile
core/schematics.lp
Definition: project.h:508
Circuit & getCircuit() const noexcept
Get the Circuit object.
Definition: project.h:181
ProjectMetadata & getMetadata() const noexcept
Get the ProjectMetadata object which contains all project metadata.
Definition: project.h:152
QScopedPointer< ProjectSettings > mProjectSettings
all project specific settings
Definition: project.h:517
The StrokeFontPool class.
Definition: strokefontpool.h:44
bool isReadOnly() const noexcept
Check whether this project was opened in read-only mode or not.
Definition: project.h:130
This class can be used to implement file-based directory locks.
Definition: directorylock.h:162
QScopedPointer< SmartVersionFile > mVersionFile
the ".librepcb-project" file
Definition: project.h:498
ProjectLibrary & getLibrary() const noexcept
Get the ProjectLibrary object which contains all library elements used in this project.
Definition: project.h:167
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:174
QScopedPointer< SchematicLayerProvider > mSchematicLayerProvider
All schematic layers of this project.
Definition: project.h:531