LibrePCB Developers Documentation
eaglelibraryimport.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_EAGLEIMPORT_EAGLELIBRARYIMPORT_H
21 #define LIBREPCB_EAGLEIMPORT_EAGLELIBRARYIMPORT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
28 
29 #include <QtCore>
30 
31 #include <memory>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace parseagle {
37 class Device;
38 class DeviceSet;
39 class Package;
40 class Symbol;
41 class Wire;
42 } // namespace parseagle
43 
44 namespace librepcb {
45 
46 class MessageLogger;
47 
48 namespace eagleimport {
49 
50 struct EagleLibraryConverterSettings;
51 
52 /*******************************************************************************
53  * Class EagleLibraryImport
54  ******************************************************************************/
55 
59 class EagleLibraryImport final : public QThread {
60  Q_OBJECT
61 
62 public:
63  struct Symbol {
64  QString displayName; // Same as symbol->getName()
65  QString description; // Same as symbol->getDescription()
66  Qt::CheckState checkState;
67  std::shared_ptr<parseagle::Symbol> symbol;
68  };
69 
70  struct Package {
71  QString displayName; // Same as package->getName()
72  QString description; // Same as package->getDescription()
73  Qt::CheckState checkState;
74  std::shared_ptr<parseagle::Package> package;
75  };
76 
77  struct Component {
78  QString displayName; // Like deviceSet->getName() but without trailing [-_]
79  QString description; // Same as deviceSet->getDescription()
80  Qt::CheckState checkState;
81  QSet<QString> symbolDisplayNames;
82  std::shared_ptr<parseagle::DeviceSet> deviceSet;
83  };
84 
85  struct Device {
86  QString displayName; // Built from names of deviceSet and device
87  QString description; // Same as deviceSet->getDescription()
88  Qt::CheckState checkState;
91  std::shared_ptr<parseagle::Device> device;
92  std::shared_ptr<parseagle::DeviceSet> deviceSet;
93  };
94 
95  // Constructors / Destructor
96  EagleLibraryImport(const EagleLibraryImport& other) = delete;
97  EagleLibraryImport(const FilePath& dstLibFp,
98  QObject* parent = nullptr) noexcept;
99  ~EagleLibraryImport() noexcept;
100 
101  // Getters
102  std::shared_ptr<MessageLogger> getLogger() const noexcept { return mLogger; }
103  const FilePath& getLoadedFilePath() const noexcept { return mLoadedFilePath; }
104  int getTotalElementsCount() const noexcept;
105  int getCheckedElementsCount() const noexcept;
106  int getCheckedSymbolsCount() const noexcept;
107  int getCheckedPackagesCount() const noexcept;
108  int getCheckedComponentsCount() const noexcept;
109  int getCheckedDevicesCount() const noexcept;
110  const QVector<Symbol>& getSymbols() const noexcept { return mSymbols; }
111  const QVector<Package>& getPackages() const noexcept { return mPackages; }
112  const QVector<Component>& getComponents() const noexcept {
113  return mComponents;
114  }
115  const QVector<Device>& getDevices() const noexcept { return mDevices; }
116 
117  // Setters
118  void setNamePrefix(const QString& prefix) noexcept;
119  void setSymbolCategories(const QSet<Uuid>& uuids) noexcept;
120  void setPackageCategories(const QSet<Uuid>& uuids) noexcept;
121  void setComponentCategories(const QSet<Uuid>& uuids) noexcept;
122  void setDeviceCategories(const QSet<Uuid>& uuids) noexcept;
123  void setSymbolChecked(const QString& name, bool checked) noexcept;
124  void setPackageChecked(const QString& name, bool checked) noexcept;
125  void setComponentChecked(const QString& name, bool checked) noexcept;
126  void setDeviceChecked(const QString& name, bool checked) noexcept;
127 
128  // General Methods
129  void reset() noexcept;
130  QStringList open(const FilePath& lbr);
131 
132  // Operator Overloadings
133  EagleLibraryImport& operator=(const EagleLibraryImport& rhs) = delete;
134 
135 signals:
136  void symbolCheckStateChanged(const QString& name, Qt::CheckState state);
137  void packageCheckStateChanged(const QString& name, Qt::CheckState state);
138  void componentCheckStateChanged(const QString& name, Qt::CheckState state);
139  void progressStatus(const QString& status);
140  void progressPercent(int percent);
141  void finished();
142 
143 private: // Methods
144  template <typename T>
145  int getCheckedElementsCount(const QVector<T>& elements) const noexcept;
146  template <typename T>
147  void setElementChecked(QVector<T>& elements, const QString& name,
148  bool checked) noexcept;
149  void updateDependencies() noexcept;
150  template <typename T>
151  bool setElementDependent(T& element, bool dependent) noexcept;
152  void run() noexcept override;
153 
154 private: // Data
156  QScopedPointer<EagleLibraryConverterSettings> mSettings;
157  std::shared_ptr<MessageLogger> mLogger;
158 
159  // State
160  bool mAbort;
162 
163  // Library elements
164  QVector<Symbol> mSymbols;
165  QVector<Package> mPackages;
166  QVector<Component> mComponents;
167  QVector<Device> mDevices;
168 };
169 
170 /*******************************************************************************
171  * End of File
172  ******************************************************************************/
173 
174 } // namespace eagleimport
175 } // namespace librepcb
176 
177 #endif
const QVector< Component > & getComponents() const noexcept
Definition: eaglelibraryimport.h:112
Definition: eaglelibraryimport.h:85
QVector< Symbol > mSymbols
Definition: eaglelibraryimport.h:164
std::shared_ptr< parseagle::DeviceSet > deviceSet
Definition: eaglelibraryimport.h:82
QString componentDisplayName
Definition: eaglelibraryimport.h:89
Qt::CheckState checkState
Definition: eaglelibraryimport.h:73
Definition: occmodel.cpp:77
Definition: eaglelibraryimport.h:63
QString description
Definition: eaglelibraryimport.h:87
QVector< Device > mDevices
Definition: eaglelibraryimport.h:167
QSet< QString > symbolDisplayNames
Definition: eaglelibraryimport.h:81
QString displayName
Definition: eaglelibraryimport.h:71
Qt::CheckState checkState
Definition: eaglelibraryimport.h:80
QString description
Definition: eaglelibraryimport.h:79
std::shared_ptr< parseagle::Device > device
Definition: eaglelibraryimport.h:91
std::shared_ptr< parseagle::Package > package
Definition: eaglelibraryimport.h:74
QScopedPointer< EagleLibraryConverterSettings > mSettings
Definition: eaglelibraryimport.h:156
QString displayName
Definition: eaglelibraryimport.h:64
Qt::CheckState checkState
Definition: eaglelibraryimport.h:88
FilePath mLoadedFilePath
Definition: eaglelibraryimport.h:161
QVector< Package > mPackages
Definition: eaglelibraryimport.h:165
bool mAbort
Definition: eaglelibraryimport.h:160
const QVector< Package > & getPackages() const noexcept
Definition: eaglelibraryimport.h:111
Generic logger class to pass messages between objects.
Definition: messagelogger.h:43
Definition: eaglelibraryimport.h:77
const FilePath & getLoadedFilePath() const noexcept
Definition: eaglelibraryimport.h:103
std::shared_ptr< parseagle::DeviceSet > deviceSet
Definition: eaglelibraryimport.h:92
std::shared_ptr< parseagle::Symbol > symbol
Definition: eaglelibraryimport.h:67
Definition: eaglelibraryimport.h:70
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
Qt::CheckState checkState
Definition: eaglelibraryimport.h:66
const QVector< Symbol > & getSymbols() const noexcept
Definition: eaglelibraryimport.h:110
QString packageDisplayName
Definition: eaglelibraryimport.h:90
QString displayName
Definition: eaglelibraryimport.h:86
Definition: eaglelibraryconverter.h:38
QString displayName
Definition: eaglelibraryimport.h:78
QString description
Definition: eaglelibraryimport.h:65
QString description
Definition: eaglelibraryimport.h:72
const FilePath mDestinationLibraryFp
Definition: eaglelibraryimport.h:155
EAGLE library (*.lbr) import.
Definition: eaglelibraryimport.h:59
QVector< Component > mComponents
Definition: eaglelibraryimport.h:166
std::shared_ptr< MessageLogger > mLogger
Definition: eaglelibraryimport.h:157
const QVector< Device > & getDevices() const noexcept
Definition: eaglelibraryimport.h:115