LibrePCB Developers Documentation
projectlibrary.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_PROJECTLIBRARY_H
21#define LIBREPCB_CORE_PROJECTLIBRARY_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../fileio/transactionaldirectory.h"
27#include "../types/uuid.h"
28
29#include <QtCore>
30
31#include <memory>
32
33/*******************************************************************************
34 * Namespace / Forward Declarations
35 ******************************************************************************/
36namespace librepcb {
37
38class Component;
39class Device;
40class LibraryBaseElement;
41class Package;
42class Project;
43class Symbol;
44
45/*******************************************************************************
46 * Class ProjectLibrary
47 ******************************************************************************/
48
52class ProjectLibrary final : public QObject {
53 Q_OBJECT
54
55public:
56 // Constructors / Destructor
57 ProjectLibrary() = delete;
58 ProjectLibrary(const ProjectLibrary& other) = delete;
59 ProjectLibrary(std::unique_ptr<TransactionalDirectory> directory);
60 ~ProjectLibrary() noexcept;
61
62 // Getters: General
64
65 // Getters: Library Elements
66 const QHash<Uuid, Symbol*>& getSymbols() const noexcept { return mSymbols; }
67 const QHash<Uuid, Package*>& getPackages() const noexcept {
68 return mPackages;
69 }
70 const QHash<Uuid, Component*>& getComponents() const noexcept {
71 return mComponents;
72 }
73 const QHash<Uuid, Device*>& getDevices() const noexcept { return mDevices; }
74 Symbol* getSymbol(const Uuid& uuid) const noexcept {
75 return mSymbols.value(uuid);
76 }
77 Package* getPackage(const Uuid& uuid) const noexcept {
78 return mPackages.value(uuid);
79 }
80 Component* getComponent(const Uuid& uuid) const noexcept {
81 return mComponents.value(uuid);
82 }
83 Device* getDevice(const Uuid& uuid) const noexcept {
84 return mDevices.value(uuid);
85 }
86
87 // Getters: Special Queries
88 QHash<Uuid, Device*> getDevicesOfComponent(
89 const Uuid& compUuid) const noexcept;
90
91 // Add/Remove Methods
92 void addSymbol(Symbol& s);
93 void addPackage(Package& p);
94 void addComponent(Component& c);
95 void addDevice(Device& d);
96 void removeSymbol(Symbol& s);
97 void removePackage(Package& p);
99 void removeDevice(Device& d);
100
101 // Operator Overloadings
103
104private:
105 // Private Methods
106 template <typename ElementType>
107 void addElement(ElementType& element, QHash<Uuid, ElementType*>& elementList);
108 template <typename ElementType>
109 void removeElement(ElementType& element,
110 QHash<Uuid, ElementType*>& elementList);
111
112 // General
113 std::unique_ptr<TransactionalDirectory> mDirectory;
114
115 // The currently added library elements
116 QHash<Uuid, Symbol*> mSymbols;
117 QHash<Uuid, Package*> mPackages;
118 QHash<Uuid, Component*> mComponents;
119 QHash<Uuid, Device*> mDevices;
120
121 QSet<LibraryBaseElement*> mAllElements;
122};
123
124/*******************************************************************************
125 * End of File
126 ******************************************************************************/
127
128} // namespace librepcb
129
130#endif
The Component class represents a "generic" device in the library.
Definition: component.h:73
The Device class represents an instance of a component (a "real" component)
Definition: device.h:55
The Package class represents a package of a component (including footprint and 3D model)
Definition: package.h:59
The ProjectLibrary class.
Definition: projectlibrary.h:52
void addComponent(Component &c)
Definition: projectlibrary.cpp:79
Package * getPackage(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:77
QSet< LibraryBaseElement * > mAllElements
Definition: projectlibrary.h:121
const QHash< Uuid, Device * > & getDevices() const noexcept
Definition: projectlibrary.h:73
Symbol * getSymbol(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:74
void removeSymbol(Symbol &s)
Definition: projectlibrary.cpp:87
const QHash< Uuid, Package * > & getPackages() const noexcept
Definition: projectlibrary.h:67
ProjectLibrary(const ProjectLibrary &other)=delete
void removeDevice(Device &d)
Definition: projectlibrary.cpp:99
QHash< Uuid, Device * > mDevices
Definition: projectlibrary.h:119
QHash< Uuid, Package * > mPackages
Definition: projectlibrary.h:117
void addPackage(Package &p)
Definition: projectlibrary.cpp:75
TransactionalDirectory & getDirectory() const
Definition: projectlibrary.h:63
Component * getComponent(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:80
void addElement(ElementType &element, QHash< Uuid, ElementType * > &elementList)
Definition: projectlibrary.cpp:108
void addSymbol(Symbol &s)
Definition: projectlibrary.cpp:71
QHash< Uuid, Device * > getDevicesOfComponent(const Uuid &compUuid) const noexcept
Definition: projectlibrary.cpp:56
Device * getDevice(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:83
void removeComponent(Component &c)
Definition: projectlibrary.cpp:95
void removePackage(Package &p)
Definition: projectlibrary.cpp:91
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: projectlibrary.h:113
QHash< Uuid, Component * > mComponents
Definition: projectlibrary.h:118
ProjectLibrary & operator=(const ProjectLibrary &rhs)=delete
void addDevice(Device &d)
Definition: projectlibrary.cpp:83
void removeElement(ElementType &element, QHash< Uuid, ElementType * > &elementList)
Definition: projectlibrary.cpp:131
const QHash< Uuid, Component * > & getComponents() const noexcept
Definition: projectlibrary.h:70
QHash< Uuid, Symbol * > mSymbols
Definition: projectlibrary.h:116
const QHash< Uuid, Symbol * > & getSymbols() const noexcept
Definition: projectlibrary.h:66
~ProjectLibrary() noexcept
Definition: projectlibrary.cpp:47
The Symbol class represents the part of a component which is added to schematics.
Definition: symbol.h:55
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
Definition: occmodel.cpp:77