LibrePCB Developers Documentation
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_CORE_PROJECT_H
21 #define LIBREPCB_CORE_PROJECT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../attribute/attribute.h"
27 #include "../fileio/directorylock.h"
28 #include "../fileio/transactionaldirectory.h"
29 #include "../job/outputjob.h"
30 #include "../types/elementname.h"
31 #include "../types/fileproofname.h"
32 #include "../types/uuid.h"
33 #include "../types/version.h"
34 
35 #include <QtCore>
36 
37 /*******************************************************************************
38  * Namespace / Forward Declarations
39  ******************************************************************************/
40 namespace librepcb {
41 
42 class Board;
43 class Circuit;
44 class ProjectLibrary;
45 class Schematic;
46 class StrokeFontPool;
47 
48 /*******************************************************************************
49  * Class Project
50  ******************************************************************************/
51 
71 class Project final : public QObject {
72  Q_OBJECT
73 
74 public:
75  // Constructors / Destructor
76  Project() = delete;
77  Project(const Project& other) = delete;
78 
87  Project(std::unique_ptr<TransactionalDirectory> directory,
88  const QString& filename);
89 
93  ~Project() noexcept;
94 
95  // Getters
96 
102  const QString& getFileName() const noexcept { return mFilename; }
103 
109  FilePath getFilepath() const noexcept {
110  return mDirectory->getAbsPath(mFilename);
111  }
112 
118  FilePath getPath() const noexcept { return mDirectory->getAbsPath(); }
119 
120  const TransactionalDirectory& getDirectory() const noexcept {
121  return *mDirectory;
122  }
123 
125 
131  FilePath getCurrentOutputDir() const noexcept {
132  return mDirectory->getAbsPath("output/" % *mVersion);
133  }
134 
141  StrokeFontPool& getStrokeFonts() const noexcept { return *mStrokeFontPool; }
142 
148  const Uuid& getUuid() const noexcept { return mUuid; }
149 
155  const ElementName& getName() const noexcept { return mName; }
156 
162  const QString& getAuthor() const noexcept { return mAuthor; }
163 
169  const FileProofName& getVersion() const noexcept { return mVersion; }
170 
176  const QDateTime& getCreated() const noexcept { return mCreated; }
177 
183  const QDateTime& getDateTime() const noexcept { return mDateTime; }
184 
190  const AttributeList& getAttributes() const noexcept { return mAttributes; }
191 
197  const QStringList& getLocaleOrder() const noexcept { return mLocaleOrder; }
198 
204  const QStringList& getNormOrder() const noexcept { return mNormOrder; }
205 
211  const QStringList& getCustomBomAttributes() const noexcept {
212  return mCustomBomAttributes;
213  }
214 
221  bool getDefaultLockComponentAssembly() const noexcept {
223  }
224 
230  const OutputJobList& getOutputJobs() const noexcept { return mOutputJobs; }
231  OutputJobList& getOutputJobs() noexcept { return mOutputJobs; }
232 
239  ProjectLibrary& getLibrary() const noexcept { return *mProjectLibrary; }
240 
246  Circuit& getCircuit() const noexcept { return *mCircuit; }
247 
253  const QSet<SExpression>& getErcMessageApprovals() const noexcept {
254  return mErcMessageApprovals;
255  }
256 
262  const QPointer<Board>& getPrimaryBoard() noexcept { return mPrimaryBoard; }
263 
264  // Setters
265 
274  void setUuid(const Uuid& newUuid) noexcept;
275 
281  void setName(const ElementName& newName) noexcept;
282 
288  void setAuthor(const QString& newAuthor) noexcept;
289 
295  void setVersion(const FileProofName& newVersion) noexcept;
296 
302  void setCreated(const QDateTime& newCreated) noexcept;
303 
307  void updateDateTime() noexcept;
308 
314  void setAttributes(const AttributeList& newAttributes) noexcept;
315 
321  void setLocaleOrder(const QStringList& newLocales) noexcept;
322 
328  void setNormOrder(const QStringList& newNorms) noexcept;
329 
335  void setCustomBomAttributes(const QStringList& newKeys) noexcept;
336 
343  void setDefaultLockComponentAssembly(bool newLock) noexcept;
344 
353  bool setErcMessageApprovals(const QSet<SExpression>& approvals) noexcept;
354 
355  // Schematic Methods
356 
362  int getSchematicIndex(const Schematic& schematic) const noexcept;
363 
369  const QList<Schematic*>& getSchematics() const noexcept {
370  return mSchematics;
371  }
372 
381  Schematic* getSchematicByIndex(int index) const noexcept {
382  return mSchematics.value(index, nullptr);
383  }
384 
392  Schematic* getSchematicByUuid(const Uuid& uuid) const noexcept;
393 
401  Schematic* getSchematicByName(const QString& name) const noexcept;
402 
411  void addSchematic(Schematic& schematic, int newIndex = -1);
412 
423  void removeSchematic(Schematic& schematic, bool deleteSchematic = false);
424 
425  // Board Methods
426 
432  int getBoardIndex(const Board& board) const noexcept;
433 
439  const QList<Board*>& getBoards() const noexcept { return mBoards; }
440 
448  Board* getBoardByIndex(int index) const noexcept {
449  return mBoards.value(index, nullptr);
450  }
451 
459  Board* getBoardByUuid(const Uuid& uuid) const noexcept;
460 
468  Board* getBoardByName(const QString& name) const noexcept;
469 
478  void addBoard(Board& board, int newIndex = -1);
479 
490  void removeBoard(Board& board, bool deleteBoard = false);
491 
492  // General Methods
493 
499  void save();
500 
501  // Operator Overloadings
502  bool operator==(const Project& rhs) noexcept { return (this == &rhs); }
503  bool operator!=(const Project& rhs) noexcept { return (this != &rhs); }
504 
505  // Static Methods
506 
507  static std::unique_ptr<Project> create(
508  std::unique_ptr<TransactionalDirectory> directory,
509  const QString& filename);
510  static bool isFilePathInsideProjectDirectory(const FilePath& fp) noexcept;
511  static bool isProjectFile(const FilePath& file) noexcept;
512  static bool isProjectDirectory(const FilePath& dir) noexcept;
513  static Version getProjectFileFormatVersion(const FilePath& dir);
514 
515 signals:
516  void attributesChanged();
517 
521  void normOrderChanged();
522 
528  void ercMessageApprovalsChanged(const QSet<SExpression>& approvals);
529 
535  void schematicAdded(int newIndex);
536 
543  void schematicRemoved(int oldIndex);
544 
550  void boardAdded(int newIndex);
551 
557  void boardRemoved(int oldIndex);
558 
564  void primaryBoardChanged(const QPointer<Board>& board);
565 
566 private: // Methods
567  void updatePrimaryBoard();
568 
569 private: // Data
571  std::unique_ptr<TransactionalDirectory> mDirectory;
572 
574  QString mFilename;
575 
577  QScopedPointer<StrokeFontPool> mStrokeFontPool;
578 
581 
584 
586  QString mAuthor;
587 
590 
592  QDateTime mCreated;
593 
595  QDateTime mDateTime;
596 
599 
601  QStringList mLocaleOrder;
602 
604  QStringList mNormOrder;
605 
607  QStringList mCustomBomAttributes;
608 
611 
614 
616  QScopedPointer<ProjectLibrary> mProjectLibrary;
617 
620  QScopedPointer<Circuit> mCircuit;
621 
623  QList<Schematic*> mSchematics;
624 
626  QList<Schematic*> mRemovedSchematics;
627 
629  QList<Board*> mBoards;
630 
632  QList<Board*> mRemovedBoards;
633 
635  QSet<SExpression> mErcMessageApprovals;
636 
637  // Cached properties
638  QPointer<Board> mPrimaryBoard;
639 };
640 
641 /*******************************************************************************
642  * End of File
643  ******************************************************************************/
644 
645 } // namespace librepcb
646 
647 #endif
int getSchematicIndex(const Schematic &schematic) const noexcept
Get the page index of a specific schematic.
Definition: project.cpp:200
const QPointer< Board > & getPrimaryBoard() noexcept
Get the primary board (the first one)
Definition: project.h:262
void primaryBoardChanged(const QPointer< Board > &board)
A different board has become the primary board.
const QDateTime & getDateTime() const noexcept
Get the date and time when the project was opened or saved.
Definition: project.h:183
void setUuid(const Uuid &newUuid) noexcept
Set the project&#39;s UUID.
Definition: project.cpp:113
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
QList< Schematic * > mRemovedSchematics
All removed schematics of this project.
Definition: project.h:626
Schematic * getSchematicByIndex(int index) const noexcept
Get the schematic page at a specific index.
Definition: project.h:381
const FileProofName & getVersion() const noexcept
Get the version of the project.
Definition: project.h:169
void updateDateTime() noexcept
Update the last modified date/time.
Definition: project.cpp:148
bool mDefaultLockComponentAssembly
Default value for librepcb::ComponentInstance::mLockAssembly.
Definition: project.h:610
type_safe::constrained_type< QString, FileProofNameConstraint, FileProofNameVerifier > FileProofName
Definition: fileproofname.h:88
std::unique_ptr< TransactionalDirectory > mDirectory
Project root directory.
Definition: project.h:571
int getBoardIndex(const Board &board) const noexcept
Get the index of a specific board.
Definition: project.cpp:288
bool operator!=(const Project &rhs) noexcept
Definition: project.h:503
QSet< SExpression > mErcMessageApprovals
All approved ERC messages.
Definition: project.h:635
Definition: occmodel.cpp:76
const AttributeList & getAttributes() const noexcept
Get the list of attributes.
Definition: project.h:190
Board * getBoardByIndex(int index) const noexcept
Get the board at a specific index.
Definition: project.h:448
static bool isProjectDirectory(const FilePath &dir) noexcept
Definition: project.cpp:560
QScopedPointer< StrokeFontPool > mStrokeFontPool
All fonts from ./resources/fontobene/.
Definition: project.h:577
const QList< Schematic * > & getSchematics() const noexcept
Get all schematics.
Definition: project.h:369
static Version getProjectFileFormatVersion(const FilePath &dir)
Definition: project.cpp:564
bool setErcMessageApprovals(const QSet< SExpression > &approvals) noexcept
Set all ERC message approvals.
Definition: project.cpp:185
void schematicAdded(int newIndex)
This signal is emitted after a schematic was added to the project.
Schematic * getSchematicByUuid(const Uuid &uuid) const noexcept
Get the schematic page with a specific UUID.
Definition: project.cpp:204
void normOrderChanged()
The norm order has been changed.
const QStringList & getNormOrder() const noexcept
Get the configured norm order.
Definition: project.h:204
Helper class to access a subdirectory of TransactionalFileSystem.
Definition: transactionaldirectory.h:51
const QList< Board * > & getBoards() const noexcept
Get all boards.
Definition: project.h:439
static std::unique_ptr< Project > create(std::unique_ptr< TransactionalDirectory > directory, const QString &filename)
Definition: project.cpp:500
The ProjectLibrary class.
Definition: projectlibrary.h:52
void schematicRemoved(int oldIndex)
This signal is emitted after a schematic was removed from the project.
FilePath getPath() const noexcept
Get the path to the project directory.
Definition: project.h:118
QDateTime mDateTime
Date/time of opening or saving the project.
Definition: project.h:595
void setVersion(const FileProofName &newVersion) noexcept
Set the version of the project.
Definition: project.cpp:134
void addBoard(Board &board, int newIndex=-1)
Add an existing board to this project.
Definition: project.cpp:306
QList< Board * > mBoards
All boards of this project.
Definition: project.h:629
StrokeFontPool & getStrokeFonts() const noexcept
Get the StrokeFontPool which contains all stroke fonts of the project.
Definition: project.h:141
const QStringList & getCustomBomAttributes() const noexcept
Get the configured custom BOM attributes.
Definition: project.h:211
Schematic * getSchematicByName(const QString &name) const noexcept
Get the schematic page with a specific name.
Definition: project.cpp:211
void setCreated(const QDateTime &newCreated) noexcept
Set the creation date/time.
Definition: project.cpp:141
void setLocaleOrder(const QStringList &newLocales) noexcept
Set the locale order.
Definition: project.cpp:160
void removeBoard(Board &board, bool deleteBoard=false)
Remove a board from this project.
Definition: project.cpp:345
The Schematic class represents one schematic page of a project and is always part of a circuit...
Definition: schematic.h:74
const QDateTime & getCreated() const noexcept
Get the date and time when the project was created.
Definition: project.h:176
bool operator==(const Project &rhs) noexcept
Definition: project.h:502
The Circuit class represents all electrical connections in a project (drawn in the schematics) ...
Definition: circuit.h:70
QString mAuthor
Author (optional).
Definition: project.h:586
QStringList mCustomBomAttributes
Custom attributes to be included in BOM export.
Definition: project.h:607
static bool isFilePathInsideProjectDirectory(const FilePath &fp) noexcept
Definition: project.cpp:544
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:73
const OutputJobList & getOutputJobs() const noexcept
Get all output jobs.
Definition: project.h:230
QScopedPointer< ProjectLibrary > mProjectLibrary
Ehe library which contains all elements needed in this project.
Definition: project.h:616
static bool isProjectFile(const FilePath &file) noexcept
Definition: project.cpp:555
OutputJobList mOutputJobs
Output jobs.
Definition: project.h:613
QString mFilename
Name of the *.lpp project file.
Definition: project.h:574
void setAttributes(const AttributeList &newAttributes) noexcept
Set all project attributes.
Definition: project.cpp:153
QStringList mLocaleOrder
Configured locales (e.g. "de_CH") in a particular order.
Definition: project.h:601
TransactionalDirectory & getDirectory() noexcept
Definition: project.h:124
const QString & getAuthor() const noexcept
Get the author of the project.
Definition: project.h:162
void addSchematic(Schematic &schematic, int newIndex=-1)
Add an existing schematic to this project.
Definition: project.cpp:218
AttributeList mAttributes
User-defined attributes in the specified order.
Definition: project.h:598
const TransactionalDirectory & getDirectory() const noexcept
Definition: project.h:120
void setCustomBomAttributes(const QStringList &newKeys) noexcept
Set the custom BOM attributes.
Definition: project.cpp:175
const QSet< SExpression > & getErcMessageApprovals() const noexcept
Get all ERC message approvals.
Definition: project.h:253
void setName(const ElementName &newName) noexcept
Set the name of the project.
Definition: project.cpp:120
OutputJobList & getOutputJobs() noexcept
Definition: project.h:231
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
QStringList mNormOrder
Configured norms in a particular order.
Definition: project.h:604
void setDefaultLockComponentAssembly(bool newLock) noexcept
Set the default value for librepcb::ComponentInstance::mLockAssembly.
Definition: project.cpp:181
The Project class represents a whole (opened) project with all its content.
Definition: project.h:71
Circuit & getCircuit() const noexcept
Get the Circuit object.
Definition: project.h:246
void save()
Save the project to the transactional file system.
Definition: project.cpp:371
const QString & getFileName() const noexcept
Get the filename of the project file (*.lpp)
Definition: project.h:102
const Uuid & getUuid() const noexcept
Get the UUID of the project.
Definition: project.h:148
void attributesChanged()
void ercMessageApprovalsChanged(const QSet< SExpression > &approvals)
Called by setErcMessageApprovals()
QList< Board * > mRemovedBoards
All removed boards of this project.
Definition: project.h:632
ElementName mName
The project name.
Definition: project.h:583
FilePath getFilepath() const noexcept
Get the filepath of the project file (*.lpp)
Definition: project.h:109
Board * getBoardByName(const QString &name) const noexcept
Get the board with a specific name.
Definition: project.cpp:299
Uuid mUuid
The project&#39;s UUID.
Definition: project.h:580
Board * getBoardByUuid(const Uuid &uuid) const noexcept
Get the board with a specific UUID.
Definition: project.cpp:292
FilePath getCurrentOutputDir() const noexcept
Get the output jobs base directory for the current version number.
Definition: project.h:131
bool getDefaultLockComponentAssembly() const noexcept
Whether assembly options of new components are locked for the board editor or not.
Definition: project.h:221
void setNormOrder(const QStringList &newNorms) noexcept
Set the norm order.
Definition: project.cpp:167
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:56
QDateTime mCreated
Date/time of project creation.
Definition: project.h:592
QScopedPointer< Circuit > mCircuit
Definition: project.h:620
FileProofName mVersion
Version number.
Definition: project.h:589
~Project() noexcept
The destructor will close the whole project (without saving!)
Definition: project.cpp:85
QList< Schematic * > mSchematics
All schematics of this project.
Definition: project.h:623
void setAuthor(const QString &newAuthor) noexcept
Set the author of the project.
Definition: project.cpp:127
void updatePrimaryBoard()
Definition: project.cpp:574
QPointer< Board > mPrimaryBoard
Definition: project.h:638
The StrokeFontPool class.
Definition: strokefontpool.h:46
void removeSchematic(Schematic &schematic, bool deleteSchematic=false)
Remove a schematic from this project.
Definition: project.cpp:257
const ElementName & getName() const noexcept
Get the name of the project.
Definition: project.h:155
void boardRemoved(int oldIndex)
This signal is emitted after a board was removed from the project.
const QStringList & getLocaleOrder() const noexcept
Get the configured locale order.
Definition: project.h:197
ProjectLibrary & getLibrary() const noexcept
Get the ProjectLibrary object which contains all library elements used in this project.
Definition: project.h:239
void boardAdded(int newIndex)
This signal is emitted after a board was added to the project.
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:83