LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_PROJECT_PROJECTLIBRARY_H
21 #define LIBREPCB_PROJECT_PROJECTLIBRARY_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
28 #include <librepcb/common/uuid.h>
29 
30 #include <QtCore>
31 
32 #include <memory>
33 
34 /*******************************************************************************
35  * Namespace / Forward Declarations
36  ******************************************************************************/
37 namespace librepcb {
38 
39 namespace library {
40 class LibraryBaseElement;
41 class Symbol;
42 class Package;
43 class Component;
44 class Device;
45 } // namespace library
46 
47 namespace project {
48 
49 class Project;
50 
51 /*******************************************************************************
52  * Class ProjectLibrary
53  ******************************************************************************/
54 
61 class ProjectLibrary final : public QObject {
62  Q_OBJECT
63 
64 public:
65  // Constructors / Destructor
66  ProjectLibrary(std::unique_ptr<TransactionalDirectory> directory);
67  ~ProjectLibrary() noexcept;
68 
69  // Getters: Library Elements
70  const QHash<Uuid, library::Symbol*>& getSymbols() const noexcept {
71  return mSymbols;
72  }
73  const QHash<Uuid, library::Package*>& getPackages() const noexcept {
74  return mPackages;
75  }
76  const QHash<Uuid, library::Component*>& getComponents() const noexcept {
77  return mComponents;
78  }
79  const QHash<Uuid, library::Device*>& getDevices() const noexcept {
80  return mDevices;
81  }
82  library::Symbol* getSymbol(const Uuid& uuid) const noexcept {
83  return mSymbols.value(uuid);
84  }
85  library::Package* getPackage(const Uuid& uuid) const noexcept {
86  return mPackages.value(uuid);
87  }
88  library::Component* getComponent(const Uuid& uuid) const noexcept {
89  return mComponents.value(uuid);
90  }
91  library::Device* getDevice(const Uuid& uuid) const noexcept {
92  return mDevices.value(uuid);
93  }
94 
95  // Getters: Special Queries
96  QHash<Uuid, library::Device*> getDevicesOfComponent(
97  const Uuid& compUuid) const noexcept;
98 
99  // Add/Remove Methods
100  void addSymbol(library::Symbol& s);
101  void addPackage(library::Package& p);
103  void addDevice(library::Device& d);
104  void removeSymbol(library::Symbol& s);
107  void removeDevice(library::Device& d);
108 
109  // General Methods
110  void save();
111 
112 private:
113  // make some methods inaccessible...
114  ProjectLibrary();
115  ProjectLibrary(const ProjectLibrary& other);
117 
118  // Private Methods
119  template <typename ElementType>
120  void loadElements(const QString& dirname, const QString& type,
121  QHash<Uuid, ElementType*>& elementList);
122  template <typename ElementType>
123  void addElement(ElementType& element, QHash<Uuid, ElementType*>& elementList);
124  template <typename ElementType>
125  void removeElement(ElementType& element,
126  QHash<Uuid, ElementType*>& elementList);
127 
128  // General
129  std::unique_ptr<TransactionalDirectory> mDirectory;
130 
131  // The currently added library elements
132  QHash<Uuid, library::Symbol*> mSymbols;
133  QHash<Uuid, library::Package*> mPackages;
134  QHash<Uuid, library::Component*> mComponents;
135  QHash<Uuid, library::Device*> mDevices;
136 
137  QSet<library::LibraryBaseElement*> mAllElements;
138  QSet<library::LibraryBaseElement*> mElementsToUpgrade;
139 };
140 
141 /*******************************************************************************
142  * End of File
143  ******************************************************************************/
144 
145 } // namespace project
146 } // namespace librepcb
147 
148 #endif // LIBREPCB_PROJECT_PROJECTLIBRARY_H
const QHash< Uuid, library::Symbol * > & getSymbols() const noexcept
Definition: projectlibrary.h:70
void addPackage(library::Package &p)
Definition: projectlibrary.cpp:100
void addSymbol(library::Symbol &s)
Definition: projectlibrary.cpp:96
const QHash< Uuid, library::Package * > & getPackages() const noexcept
Definition: projectlibrary.h:73
The ProjectLibrary class.
Definition: projectlibrary.h:61
QHash< Uuid, library::Package * > mPackages
Definition: projectlibrary.h:133
QSet< library::LibraryBaseElement * > mElementsToUpgrade
Definition: projectlibrary.h:138
The Package class represents a package of a component (including footprint and 3D model) ...
Definition: package.h:56
The Device class represents an instance of a component (a "real" component)
Definition: device.h:54
QHash< Uuid, library::Component * > mComponents
Definition: projectlibrary.h:134
void removeDevice(library::Device &d)
Definition: projectlibrary.cpp:124
void removeComponent(library::Component &c)
Definition: projectlibrary.cpp:120
The Symbol class represents the part of a component which is added to schematics. ...
Definition: symbol.h:57
const QHash< Uuid, library::Component * > & getComponents() const noexcept
Definition: projectlibrary.h:76
void addComponent(library::Component &c)
Definition: projectlibrary.cpp:104
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: projectlibrary.h:129
void addElement(ElementType &element, QHash< Uuid, ElementType * > &elementList)
Definition: projectlibrary.cpp:181
library::Device * getDevice(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:91
void save()
Definition: projectlibrary.cpp:132
QHash< Uuid, library::Device * > getDevicesOfComponent(const Uuid &compUuid) const noexcept
Definition: projectlibrary.cpp:81
void removePackage(library::Package &p)
Definition: projectlibrary.cpp:116
void removeElement(ElementType &element, QHash< Uuid, ElementType * > &elementList)
Definition: projectlibrary.cpp:196
void loadElements(const QString &dirname, const QString &type, QHash< Uuid, ElementType * > &elementList)
Definition: projectlibrary.cpp:146
void addDevice(library::Device &d)
Definition: projectlibrary.cpp:108
library::Component * getComponent(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:88
ProjectLibrary & operator=(const ProjectLibrary &rhs)
library::Package * getPackage(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:85
QSet< library::LibraryBaseElement * > mAllElements
Definition: projectlibrary.h:137
~ProjectLibrary() noexcept
Definition: projectlibrary.cpp:70
QHash< Uuid, library::Device * > mDevices
Definition: projectlibrary.h:135
const QHash< Uuid, library::Device * > & getDevices() const noexcept
Definition: projectlibrary.h:79
library::Symbol * getSymbol(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:82
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
QHash< Uuid, library::Symbol * > mSymbols
Definition: projectlibrary.h:132
The Component class represents a "generic" device in the library.
Definition: component.h:73
void removeSymbol(library::Symbol &s)
Definition: projectlibrary.cpp:112