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 /*******************************************************************************
21 * Includes
22 ******************************************************************************/
23 #include "deviceconverter.h"
24
25 #include "converterdb.h"
26
27 #include <librepcb/library/dev/device.h>
28 #include <parseagle/deviceset/deviceset.h>
29
30 #include <QtCore>
31
32 /*******************************************************************************
33 * Namespace
34 ******************************************************************************/
35 namespace librepcb {
36 namespace eagleimport {
37
38 /*******************************************************************************
39 * Constructors / Destructor
40 ******************************************************************************/
41
DeviceConverter(const parseagle::DeviceSet & deviceSet,const parseagle::Device & device,ConverterDb & db)42 DeviceConverter::DeviceConverter(const parseagle::DeviceSet& deviceSet,
43 const parseagle::Device& device,
44 ConverterDb& db) noexcept
45 : mDeviceSet(deviceSet), mDevice(device), mDb(db) {
46 }
47
~DeviceConverter()48 DeviceConverter::~DeviceConverter() noexcept {
49 }
50
51 /*******************************************************************************
52 * General Methods
53 ******************************************************************************/
54
generate() const55 std::unique_ptr<library::Device> DeviceConverter::generate() const {
56 // create device
57 QString deviceName = mDeviceSet.getName();
58 if (!mDevice.getName().isEmpty()) {
59 deviceName += "_" % mDevice.getName();
60 }
61 Uuid compUuid = mDb.getComponentUuid(mDeviceSet.getName());
62 Uuid pkgUuid = mDb.getPackageUuid(mDevice.getPackage());
63 std::unique_ptr<library::Device> device(new library::Device(
64 mDb.getDeviceUuid(mDeviceSet.getName(), mDevice.getName()),
65 Version::fromString("0.1"), "LibrePCB", ElementName(deviceName),
66 createDescription(), "", compUuid, pkgUuid)); // can throw
67
68 // connect pads
69 Uuid fptUuid = mDb.getFootprintUuid(mDevice.getPackage());
70 foreach (const parseagle::Connection& connection, mDevice.getConnections()) {
71 QString gateName = connection.getGate();
72 QString pinName = connection.getPin();
73 QString padNames = connection.getPad();
74 if (pinName.contains("@")) pinName.truncate(pinName.indexOf("@"));
75 if (pinName.contains("#")) pinName.truncate(pinName.indexOf("#"));
76 foreach (const QString& padName,
77 padNames.split(" ", QString::SkipEmptyParts)) {
78 device->getPadSignalMap().append(
79 std::make_shared<library::DevicePadSignalMapItem>(
80 mDb.getPackagePadUuid(fptUuid, padName),
81 mDb.getComponentSignalUuid(compUuid, gateName, pinName)));
82 }
83 }
84
85 return device;
86 }
87
88 /*******************************************************************************
89 * Private Methods
90 ******************************************************************************/
91
createDescription() const92 QString DeviceConverter::createDescription() const noexcept {
93 QString desc = mDeviceSet.getDescription() + "\n\n";
94 desc += "This device was automatically imported from Eagle.\n";
95 desc += "Library: " % mDb.getCurrentLibraryFilePath().getFilename() % "\n";
96 desc += "DeviceSet: " % mDeviceSet.getName() % "\n";
97 desc += "Device: " % mDevice.getName() % "\n";
98 desc += "NOTE: Please remove this text after manual rework!";
99 return desc.trimmed();
100 }
101
102 /*******************************************************************************
103 * End of File
104 ******************************************************************************/
105
106 } // namespace eagleimport
107 } // namespace librepcb
108