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 ******************************************************************************/
40namespace librepcb {
41
42class Board;
43class Circuit;
44class ProjectLibrary;
45class Schematic;
46class StrokeFontPool;
47
48/*******************************************************************************
49 * Class Project
50 ******************************************************************************/
51
71class Project final : public QObject {
72 Q_OBJECT
73
74public:
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 {
213 }
214
221 bool getDefaultLockComponentAssembly() const noexcept {
223 }
224
230 const OutputJobList& getOutputJobs() const 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 {
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;
514
515signals:
517
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
566private: // Methods
567 void updatePrimaryBoard();
568
569private: // 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
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
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:73
The Circuit class represents all electrical connections in a project (drawn in the schematics)
Definition: circuit.h:70
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
The Project class represents a whole (opened) project with all its content.
Definition: project.h:71
TransactionalDirectory & getDirectory() noexcept
Definition: project.h:124
QDateTime mCreated
Date/time of project creation.
Definition: project.h:592
const TransactionalDirectory & getDirectory() const noexcept
Definition: project.h:120
void addSchematic(Schematic &schematic, int newIndex=-1)
Add an existing schematic to this project.
Definition: project.cpp:218
int getSchematicIndex(const Schematic &schematic) const noexcept
Get the page index of a specific schematic.
Definition: project.cpp:200
void updateDateTime() noexcept
Update the last modified date/time.
Definition: project.cpp:148
const QDateTime & getDateTime() const noexcept
Get the date and time when the project was opened or saved.
Definition: project.h:183
bool setErcMessageApprovals(const QSet< SExpression > &approvals) noexcept
Set all ERC message approvals.
Definition: project.cpp:185
const QString & getAuthor() const noexcept
Get the author of the project.
Definition: project.h:162
QDateTime mDateTime
Date/time of opening or saving the project.
Definition: project.h:595
void setUuid(const Uuid &newUuid) noexcept
Set the project's UUID.
Definition: project.cpp:113
void boardAdded(int newIndex)
This signal is emitted after a board was added to the project.
const FileProofName & getVersion() const noexcept
Get the version of the project.
Definition: project.h:169
bool getDefaultLockComponentAssembly() const noexcept
Whether assembly options of new components are locked for the board editor or not.
Definition: project.h:221
const QStringList & getCustomBomAttributes() const noexcept
Get the configured custom BOM attributes.
Definition: project.h:211
const QList< Board * > & getBoards() const noexcept
Get all boards.
Definition: project.h:439
ProjectLibrary & getLibrary() const noexcept
Get the ProjectLibrary object which contains all library elements used in this project.
Definition: project.h:239
QPointer< Board > mPrimaryBoard
Definition: project.h:638
OutputJobList mOutputJobs
Output jobs.
Definition: project.h:613
const ElementName & getName() const noexcept
Get the name of the project.
Definition: project.h:155
Uuid mUuid
The project's UUID.
Definition: project.h:580
~Project() noexcept
The destructor will close the whole project (without saving!)
Definition: project.cpp:85
QStringList mCustomBomAttributes
Custom attributes to be included in BOM export.
Definition: project.h:607
int getBoardIndex(const Board &board) const noexcept
Get the index of a specific board.
Definition: project.cpp:288
void schematicAdded(int newIndex)
This signal is emitted after a schematic was added to the project.
static bool isFilePathInsideProjectDirectory(const FilePath &fp) noexcept
Definition: project.cpp:550
ElementName mName
The project name.
Definition: project.h:583
void addBoard(Board &board, int newIndex=-1)
Add an existing board to this project.
Definition: project.cpp:306
QSet< SExpression > mErcMessageApprovals
All approved ERC messages.
Definition: project.h:635
FileProofName mVersion
Version number.
Definition: project.h:589
FilePath getCurrentOutputDir() const noexcept
Get the output jobs base directory for the current version number.
Definition: project.h:131
FilePath getFilepath() const noexcept
Get the filepath of the project file (*.lpp)
Definition: project.h:109
static bool isProjectFile(const FilePath &file) noexcept
Definition: project.cpp:561
static Version getProjectFileFormatVersion(const FilePath &dir)
Definition: project.cpp:570
const QPointer< Board > & getPrimaryBoard() noexcept
Get the primary board (the first one)
Definition: project.h:262
void removeSchematic(Schematic &schematic, bool deleteSchematic=false)
Remove a schematic from this project.
Definition: project.cpp:257
void attributesChanged()
FilePath getPath() const noexcept
Get the path to the project directory.
Definition: project.h:118
void setDefaultLockComponentAssembly(bool newLock) noexcept
Set the default value for librepcb::ComponentInstance::mLockAssembly.
Definition: project.cpp:181
const AttributeList & getAttributes() const noexcept
Get the list of attributes.
Definition: project.h:190
QScopedPointer< Circuit > mCircuit
Definition: project.h:620
void primaryBoardChanged(const QPointer< Board > &board)
A different board has become the primary board.
QScopedPointer< ProjectLibrary > mProjectLibrary
Ehe library which contains all elements needed in this project.
Definition: project.h:616
OutputJobList & getOutputJobs() noexcept
Definition: project.h:231
QList< Schematic * > mRemovedSchematics
All removed schematics of this project.
Definition: project.h:626
Project(const Project &other)=delete
QList< Schematic * > mSchematics
All schematics of this project.
Definition: project.h:623
const QDateTime & getCreated() const noexcept
Get the date and time when the project was created.
Definition: project.h:176
Board * getBoardByName(const QString &name) const noexcept
Get the board with a specific name.
Definition: project.cpp:299
void setAttributes(const AttributeList &newAttributes) noexcept
Set all project attributes.
Definition: project.cpp:153
void setLocaleOrder(const QStringList &newLocales) noexcept
Set the locale order.
Definition: project.cpp:160
void setNormOrder(const QStringList &newNorms) noexcept
Set the norm order.
Definition: project.cpp:167
StrokeFontPool & getStrokeFonts() const noexcept
Get the StrokeFontPool which contains all stroke fonts of the project.
Definition: project.h:141
bool mDefaultLockComponentAssembly
Default value for librepcb::ComponentInstance::mLockAssembly.
Definition: project.h:610
QList< Board * > mBoards
All boards of this project.
Definition: project.h:629
static bool isProjectDirectory(const FilePath &dir) noexcept
Definition: project.cpp:566
QScopedPointer< StrokeFontPool > mStrokeFontPool
All fonts from ./resources/fontobene/.
Definition: project.h:577
AttributeList mAttributes
User-defined attributes in the specified order.
Definition: project.h:598
const OutputJobList & getOutputJobs() const noexcept
Get all output jobs.
Definition: project.h:230
void save()
Save the project to the transactional file system.
Definition: project.cpp:371
QList< Board * > mRemovedBoards
All removed boards of this project.
Definition: project.h:632
QStringList mNormOrder
Configured norms in a particular order.
Definition: project.h:604
const Uuid & getUuid() const noexcept
Get the UUID of the project.
Definition: project.h:148
Board * getBoardByIndex(int index) const noexcept
Get the board at a specific index.
Definition: project.h:448
void setVersion(const FileProofName &newVersion) noexcept
Set the version of the project.
Definition: project.cpp:134
Schematic * getSchematicByIndex(int index) const noexcept
Get the schematic page at a specific index.
Definition: project.h:381
std::unique_ptr< TransactionalDirectory > mDirectory
Project root directory.
Definition: project.h:571
void setName(const ElementName &newName) noexcept
Set the name of the project.
Definition: project.cpp:120
void updatePrimaryBoard()
Definition: project.cpp:580
Circuit & getCircuit() const noexcept
Get the Circuit object.
Definition: project.h:246
bool operator==(const Project &rhs) noexcept
Definition: project.h:502
const QList< Schematic * > & getSchematics() const noexcept
Get all schematics.
Definition: project.h:369
void boardRemoved(int oldIndex)
This signal is emitted after a board was removed from the project.
Board * getBoardByUuid(const Uuid &uuid) const noexcept
Get the board with a specific UUID.
Definition: project.cpp:292
void normOrderChanged()
The norm order has been changed.
void schematicRemoved(int oldIndex)
This signal is emitted after a schematic was removed from the project.
void setCreated(const QDateTime &newCreated) noexcept
Set the creation date/time.
Definition: project.cpp:141
Schematic * getSchematicByUuid(const Uuid &uuid) const noexcept
Get the schematic page with a specific UUID.
Definition: project.cpp:204
const QStringList & getLocaleOrder() const noexcept
Get the configured locale order.
Definition: project.h:197
const QStringList & getNormOrder() const noexcept
Get the configured norm order.
Definition: project.h:204
QStringList mLocaleOrder
Configured locales (e.g. "de_CH") in a particular order.
Definition: project.h:601
void removeBoard(Board &board, bool deleteBoard=false)
Remove a board from this project.
Definition: project.cpp:345
Schematic * getSchematicByName(const QString &name) const noexcept
Get the schematic page with a specific name.
Definition: project.cpp:211
void ercMessageApprovalsChanged(const QSet< SExpression > &approvals)
Called by setErcMessageApprovals()
bool operator!=(const Project &rhs) noexcept
Definition: project.h:503
const QSet< SExpression > & getErcMessageApprovals() const noexcept
Get all ERC message approvals.
Definition: project.h:253
void setCustomBomAttributes(const QStringList &newKeys) noexcept
Set the custom BOM attributes.
Definition: project.cpp:175
const QString & getFileName() const noexcept
Get the filename of the project file (*.lpp)
Definition: project.h:102
static std::unique_ptr< Project > create(std::unique_ptr< TransactionalDirectory > directory, const QString &filename)
Definition: project.cpp:506
QString mAuthor
Author (optional).
Definition: project.h:586
QString mFilename
Name of the *.lpp project file.
Definition: project.h:574
void setAuthor(const QString &newAuthor) noexcept
Set the author of the project.
Definition: project.cpp:127
The ProjectLibrary class.
Definition: projectlibrary.h:52
The SExpression class.
Definition: sexpression.h:69
The Schematic class represents one schematic page of a project and is always part of a circuit.
Definition: schematic.h:74
The StrokeFontPool class.
Definition: strokefontpool.h:46
Helper class to access a subdirectory of TransactionalFileSystem.
Definition: transactionaldirectory.h:51
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
Definition: occmodel.cpp:77
type_safe::constrained_type< QString, FileProofNameConstraint, FileProofNameVerifier > FileProofName
Definition: fileproofname.h:89
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:84