LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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
364 bool setErcMessageApproved(const SExpression& approval,
365 bool approved) noexcept;
366
367 // Schematic Methods
368
374 int getSchematicIndex(const Schematic& schematic) const noexcept;
375
381 const QList<Schematic*>& getSchematics() const noexcept {
382 return mSchematics;
383 }
384
393 Schematic* getSchematicByIndex(int index) const noexcept {
394 return mSchematics.value(index, nullptr);
395 }
396
404 Schematic* getSchematicByUuid(const Uuid& uuid) const noexcept;
405
413 Schematic* getSchematicByName(const QString& name) const noexcept;
414
423 void addSchematic(Schematic& schematic, int newIndex = -1);
424
435 void removeSchematic(Schematic& schematic, bool deleteSchematic = false);
436
437 // Board Methods
438
444 int getBoardIndex(const Board& board) const noexcept;
445
451 const QList<Board*>& getBoards() const noexcept { return mBoards; }
452
460 Board* getBoardByIndex(int index) const noexcept {
461 return mBoards.value(index, nullptr);
462 }
463
471 Board* getBoardByUuid(const Uuid& uuid) const noexcept;
472
480 Board* getBoardByName(const QString& name) const noexcept;
481
490 void addBoard(Board& board, int newIndex = -1);
491
502 void removeBoard(Board& board, bool deleteBoard = false);
503
504 // General Methods
505
511 void save();
512
513 // Operator Overloadings
514 bool operator==(const Project& rhs) noexcept { return (this == &rhs); }
515 bool operator!=(const Project& rhs) noexcept { return (this != &rhs); }
516
517 // Static Methods
518
519 static std::unique_ptr<Project> create(
520 std::unique_ptr<TransactionalDirectory> directory,
521 const QString& filename);
522 static bool isFilePathInsideProjectDirectory(const FilePath& fp) noexcept;
523 static bool isProjectFile(const FilePath& file) noexcept;
524 static bool isProjectDirectory(const FilePath& dir) noexcept;
526
527signals:
529
534
540 void ercMessageApprovalsChanged(const QSet<SExpression>& approvals);
541
547 void schematicAdded(int newIndex);
548
555 void schematicRemoved(int oldIndex);
556
562 void boardAdded(int newIndex);
563
569 void boardRemoved(int oldIndex);
570
576 void primaryBoardChanged(const QPointer<Board>& board);
577
578private: // Methods
579 void updatePrimaryBoard();
580
581private: // Data
583 std::unique_ptr<TransactionalDirectory> mDirectory;
584
586 QString mFilename;
587
589 QScopedPointer<StrokeFontPool> mStrokeFontPool;
590
593
596
598 QString mAuthor;
599
602
604 QDateTime mCreated;
605
607 QDateTime mDateTime;
608
611
613 QStringList mLocaleOrder;
614
616 QStringList mNormOrder;
617
620
623
626
628 QScopedPointer<ProjectLibrary> mProjectLibrary;
629
632 QScopedPointer<Circuit> mCircuit;
633
635 QList<Schematic*> mSchematics;
636
638 QList<Schematic*> mRemovedSchematics;
639
641 QList<Board*> mBoards;
642
644 QList<Board*> mRemovedBoards;
645
647 QSet<SExpression> mErcMessageApprovals;
648
649 // Cached properties
650 QPointer<Board> mPrimaryBoard;
651};
652
653/*******************************************************************************
654 * End of File
655 ******************************************************************************/
656
657} // namespace librepcb
658
659#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:127
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:604
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:232
int getSchematicIndex(const Schematic &schematic) const noexcept
Get the page index of a specific schematic.
Definition project.cpp:214
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:607
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:451
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:650
OutputJobList mOutputJobs
Output jobs.
Definition project.h:625
const ElementName & getName() const noexcept
Get the name of the project.
Definition project.h:155
Uuid mUuid
The project's UUID.
Definition project.h:592
~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:619
int getBoardIndex(const Board &board) const noexcept
Get the index of a specific board.
Definition project.cpp:302
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:564
ElementName mName
The project name.
Definition project.h:595
void addBoard(Board &board, int newIndex=-1)
Add an existing board to this project.
Definition project.cpp:320
QSet< SExpression > mErcMessageApprovals
All approved ERC messages.
Definition project.h:647
FileProofName mVersion
Version number.
Definition project.h:601
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:575
static Version getProjectFileFormatVersion(const FilePath &dir)
Definition project.cpp:584
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:271
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:632
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:628
OutputJobList & getOutputJobs() noexcept
Definition project.h:231
QList< Schematic * > mRemovedSchematics
All removed schematics of this project.
Definition project.h:638
Project(const Project &other)=delete
QList< Schematic * > mSchematics
All schematics of this project.
Definition project.h:635
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:313
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:622
QList< Board * > mBoards
All boards of this project.
Definition project.h:641
static bool isProjectDirectory(const FilePath &dir) noexcept
Definition project.cpp:580
QScopedPointer< StrokeFontPool > mStrokeFontPool
All fonts from ./resources/fontobene/.
Definition project.h:589
AttributeList mAttributes
User-defined attributes in the specified order.
Definition project.h:610
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:385
QList< Board * > mRemovedBoards
All removed boards of this project.
Definition project.h:644
QStringList mNormOrder
Configured norms in a particular order.
Definition project.h:616
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:460
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:393
std::unique_ptr< TransactionalDirectory > mDirectory
Project root directory.
Definition project.h:583
void setName(const ElementName &newName) noexcept
Set the name of the project.
Definition project.cpp:120
void updatePrimaryBoard()
Definition project.cpp:594
Circuit & getCircuit() const noexcept
Get the Circuit object.
Definition project.h:246
bool operator==(const Project &rhs) noexcept
Definition project.h:514
const QList< Schematic * > & getSchematics() const noexcept
Get all schematics.
Definition project.h:381
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:306
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:218
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:613
bool setErcMessageApproved(const SExpression &approval, bool approved) noexcept
Set a single ERC message as approved or not.
Definition project.cpp:196
void removeBoard(Board &board, bool deleteBoard=false)
Remove a board from this project.
Definition project.cpp:359
Schematic * getSchematicByName(const QString &name) const noexcept
Get the schematic page with a specific name.
Definition project.cpp:225
void ercMessageApprovalsChanged(const QSet< SExpression > &approvals)
Called by setErcMessageApprovals()
bool operator!=(const Project &rhs) noexcept
Definition project.h:515
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:520
QString mAuthor
Author (optional).
Definition project.h:598
QString mFilename
Name of the *.lpp project file.
Definition project.h:586
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:56
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:84
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition elementname.h:84