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 
58 class ProjectLibrary final : public QObject {
59  Q_OBJECT
60 
61 public:
62  // Constructors / Destructor
63  ProjectLibrary(std::unique_ptr<TransactionalDirectory> directory);
64  ~ProjectLibrary() noexcept;
65 
66  // Getters: Library Elements
67  const QHash<Uuid, library::Symbol*>& getSymbols() const noexcept {
68  return mSymbols;
69  }
70  const QHash<Uuid, library::Package*>& getPackages() const noexcept {
71  return mPackages;
72  }
73  const QHash<Uuid, library::Component*>& getComponents() const noexcept {
74  return mComponents;
75  }
76  const QHash<Uuid, library::Device*>& getDevices() const noexcept {
77  return mDevices;
78  }
79  library::Symbol* getSymbol(const Uuid& uuid) const noexcept {
80  return mSymbols.value(uuid);
81  }
82  library::Package* getPackage(const Uuid& uuid) const noexcept {
83  return mPackages.value(uuid);
84  }
85  library::Component* getComponent(const Uuid& uuid) const noexcept {
86  return mComponents.value(uuid);
87  }
88  library::Device* getDevice(const Uuid& uuid) const noexcept {
89  return mDevices.value(uuid);
90  }
91 
92  // Getters: Special Queries
93  QHash<Uuid, library::Device*> getDevicesOfComponent(
94  const Uuid& compUuid) const noexcept;
95 
96  // Add/Remove Methods
97  void addSymbol(library::Symbol& s);
100  void addDevice(library::Device& d);
101  void removeSymbol(library::Symbol& s);
104  void removeDevice(library::Device& d);
105 
106  // General Methods
107  void save();
108 
109 private:
110  // make some methods inaccessible...
111  ProjectLibrary();
112  ProjectLibrary(const ProjectLibrary& other);
114 
115  // Private Methods
116  template <typename ElementType>
117  void loadElements(const QString& dirname, const QString& type,
118  QHash<Uuid, ElementType*>& elementList);
119  template <typename ElementType>
120  void addElement(ElementType& element, QHash<Uuid, ElementType*>& elementList);
121  template <typename ElementType>
122  void removeElement(ElementType& element,
123  QHash<Uuid, ElementType*>& elementList);
124 
125  // General
126  std::unique_ptr<TransactionalDirectory> mDirectory;
127 
128  // The currently added library elements
129  QHash<Uuid, library::Symbol*> mSymbols;
130  QHash<Uuid, library::Package*> mPackages;
131  QHash<Uuid, library::Component*> mComponents;
132  QHash<Uuid, library::Device*> mDevices;
133 
134  QSet<library::LibraryBaseElement*> mAllElements;
135  QSet<library::LibraryBaseElement*> mElementsToUpgrade;
136 };
137 
138 /*******************************************************************************
139  * End of File
140  ******************************************************************************/
141 
142 } // namespace project
143 } // namespace librepcb
144 
145 #endif // LIBREPCB_PROJECT_PROJECTLIBRARY_H
const QHash< Uuid, library::Symbol * > & getSymbols() const noexcept
Definition: projectlibrary.h:67
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:70
The ProjectLibrary class.
Definition: projectlibrary.h:58
QHash< Uuid, library::Package * > mPackages
Definition: projectlibrary.h:130
QSet< library::LibraryBaseElement * > mElementsToUpgrade
Definition: projectlibrary.h:135
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:131
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:73
void addComponent(library::Component &c)
Definition: projectlibrary.cpp:104
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: projectlibrary.h:126
void addElement(ElementType &element, QHash< Uuid, ElementType * > &elementList)
Definition: projectlibrary.cpp:181
library::Device * getDevice(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:88
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:85
ProjectLibrary & operator=(const ProjectLibrary &rhs)
library::Package * getPackage(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:82
QSet< library::LibraryBaseElement * > mAllElements
Definition: projectlibrary.h:134
~ProjectLibrary() noexcept
Definition: projectlibrary.cpp:70
QHash< Uuid, library::Device * > mDevices
Definition: projectlibrary.h:132
const QHash< Uuid, library::Device * > & getDevices() const noexcept
Definition: projectlibrary.h:76
library::Symbol * getSymbol(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:79
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:129
The Component class represents a "generic" device in the library.
Definition: component.h:73
void removeSymbol(library::Symbol &s)
Definition: projectlibrary.cpp:112