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 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 
37 namespace library {
38 class LibraryBaseElement;
39 class Symbol;
40 class Package;
41 class Component;
42 class Device;
43 } // namespace library
44 
45 namespace project {
46 
47 class Project;
48 
49 /*******************************************************************************
50  * Class ProjectLibrary
51  ******************************************************************************/
52 
59 class ProjectLibrary final : public QObject {
60  Q_OBJECT
61 
62 public:
63  // Constructors / Destructor
64  explicit ProjectLibrary(const FilePath& libDir, bool restore, bool readOnly);
65  ~ProjectLibrary() noexcept;
66 
67  // Getters: Library Elements
68  const QHash<Uuid, library::Symbol*>& getSymbols() const noexcept {
69  return mSymbols;
70  }
71  const QHash<Uuid, library::Package*>& getPackages() const noexcept {
72  return mPackages;
73  }
74  const QHash<Uuid, library::Component*>& getComponents() const noexcept {
75  return mComponents;
76  }
77  const QHash<Uuid, library::Device*>& getDevices() const noexcept {
78  return mDevices;
79  }
80  library::Symbol* getSymbol(const Uuid& uuid) const noexcept {
81  return mSymbols.value(uuid);
82  }
83  library::Package* getPackage(const Uuid& uuid) const noexcept {
84  return mPackages.value(uuid);
85  }
86  library::Component* getComponent(const Uuid& uuid) const noexcept {
87  return mComponents.value(uuid);
88  }
89  library::Device* getDevice(const Uuid& uuid) const noexcept {
90  return mDevices.value(uuid);
91  }
92 
93  // Getters: Special Queries
94  QHash<Uuid, library::Device*> getDevicesOfComponent(
95  const Uuid& compUuid) const noexcept;
96 
97  // Add/Remove Methods
98  void addSymbol(library::Symbol& s);
101  void addDevice(library::Device& d);
102  void removeSymbol(library::Symbol& s);
105  void removeDevice(library::Device& d);
106 
107  // General Methods
108  bool save(bool toOriginal, QStringList& errors) noexcept;
109 
110 private:
111  // make some methods inaccessible...
112  ProjectLibrary();
113  ProjectLibrary(const ProjectLibrary& other);
115 
116  // Private Methods
117  QSet<library::LibraryBaseElement*> getCurrentElements() const noexcept;
118  template <typename ElementType>
119  void loadElements(const FilePath& directory, const QString& type,
120  QHash<Uuid, ElementType*>& elementList);
121  template <typename ElementType>
122  void addElement(ElementType& element, QHash<Uuid, ElementType*>& elementList);
123  template <typename ElementType>
124  void removeElement(ElementType& element,
125  QHash<Uuid, ElementType*>& elementList);
126 
127  // General
131 
132  // The currently added library elements
133  QHash<Uuid, library::Symbol*> mSymbols;
134  QHash<Uuid, library::Package*> mPackages;
135  QHash<Uuid, library::Component*> mComponents;
136  QHash<Uuid, library::Device*> mDevices;
137 
142 };
143 
144 /*******************************************************************************
145  * End of File
146  ******************************************************************************/
147 
148 } // namespace project
149 } // namespace librepcb
150 
151 #endif // LIBREPCB_PROJECT_PROJECTLIBRARY_H
const QHash< Uuid, library::Symbol * > & getSymbols() const noexcept
Definition: projectlibrary.h:68
FilePath mLibraryPath
the "library" directory of the project
Definition: projectlibrary.h:128
void addPackage(library::Package &p)
Definition: projectlibrary.cpp:118
void addSymbol(library::Symbol &s)
Definition: projectlibrary.cpp:114
const QHash< Uuid, library::Package * > & getPackages() const noexcept
Definition: projectlibrary.h:71
The ProjectLibrary class.
Definition: projectlibrary.h:59
QHash< Uuid, library::Package * > mPackages
Definition: projectlibrary.h:134
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
QSet< library::LibraryBaseElement * > mLoadedElements
Definition: projectlibrary.h:139
QHash< Uuid, library::Component * > mComponents
Definition: projectlibrary.h:135
bool save(bool toOriginal, QStringList &errors) noexcept
Definition: projectlibrary.cpp:150
void removeDevice(library::Device &d)
Definition: projectlibrary.cpp:142
void removeComponent(library::Component &c)
Definition: projectlibrary.cpp:138
QSet< library::LibraryBaseElement * > mSavedToTemporary
Definition: projectlibrary.h:140
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:74
The LibraryBaseElement class.
Definition: librarybaseelement.h:52
void addComponent(library::Component &c)
Definition: projectlibrary.cpp:122
void addElement(ElementType &element, QHash< Uuid, ElementType * > &elementList)
Definition: projectlibrary.cpp:263
void loadElements(const FilePath &directory, const QString &type, QHash< Uuid, ElementType * > &elementList)
Definition: projectlibrary.cpp:211
QSet< library::LibraryBaseElement * > mSavedToOriginal
Definition: projectlibrary.h:141
library::Device * getDevice(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:89
QSet< library::LibraryBaseElement * > getCurrentElements() const noexcept
Definition: projectlibrary.cpp:201
QHash< Uuid, library::Device * > getDevicesOfComponent(const Uuid &compUuid) const noexcept
Definition: projectlibrary.cpp:99
FilePath mTmpDir
path to a temporary directory
Definition: projectlibrary.h:130
void removePackage(library::Package &p)
Definition: projectlibrary.cpp:134
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
void removeElement(ElementType &element, QHash< Uuid, ElementType * > &elementList)
Definition: projectlibrary.cpp:281
void addDevice(library::Device &d)
Definition: projectlibrary.cpp:126
library::Component * getComponent(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:86
ProjectLibrary & operator=(const ProjectLibrary &rhs)
library::Package * getPackage(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:83
QSet< library::LibraryBaseElement * > mAllElements
Definition: projectlibrary.h:138
~ProjectLibrary() noexcept
Definition: projectlibrary.cpp:79
QHash< Uuid, library::Device * > mDevices
Definition: projectlibrary.h:136
const QHash< Uuid, library::Device * > & getDevices() const noexcept
Definition: projectlibrary.h:77
library::Symbol * getSymbol(const Uuid &uuid) const noexcept
Definition: projectlibrary.h:80
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:133
The Component class represents a "generic" device in the library.
Definition: component.h:73
void removeSymbol(library::Symbol &s)
Definition: projectlibrary.cpp:130
FilePath mBackupPath
same as mLibraryPath, but with trailing "~"
Definition: projectlibrary.h:129