Skip to content

Commit

Permalink
Merge pull request #680 from LibrePCB/412-device-check-for-unconnecte…
Browse files Browse the repository at this point in the history
…d-pads

Device editor: Show warning if no pads are connected
  • Loading branch information
ubruhin committed Apr 4, 2020
2 parents ceef47a + f12bc9e commit c1e5911
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 0 deletions.
11 changes: 11 additions & 0 deletions libs/librepcb/library/dev/device.cpp
Expand Up @@ -22,6 +22,8 @@
******************************************************************************/
#include "device.h"

#include "devicecheck.h"

#include <librepcb/common/fileio/sexpression.h>

#include <QtCore>
Expand Down Expand Up @@ -77,6 +79,15 @@ void Device::setPackageUuid(const Uuid& uuid) noexcept {
emit packageUuidChanged(mPackageUuid);
}

/*******************************************************************************
* General Methods
******************************************************************************/

LibraryElementCheckMessageList Device::runChecks() const {
DeviceCheck check(*this);
return check.runChecks(); // can throw
}

/*******************************************************************************
* Private Methods
******************************************************************************/
Expand Down
3 changes: 3 additions & 0 deletions libs/librepcb/library/dev/device.h
Expand Up @@ -78,6 +78,9 @@ class Device final : public LibraryElement {
void setComponentUuid(const Uuid& uuid) noexcept;
void setPackageUuid(const Uuid& uuid) noexcept;

// General Methods
virtual LibraryElementCheckMessageList runChecks() const override;

// Operator Overloadings
Device& operator=(const Device& rhs) = delete;

Expand Down
78 changes: 78 additions & 0 deletions libs/librepcb/library/dev/devicecheck.cpp
@@ -0,0 +1,78 @@
/*
* LibrePCB - Professional EDA for everyone!
* Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
* https://librepcb.org/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*******************************************************************************
* Includes
******************************************************************************/
#include "devicecheck.h"

#include "device.h"
#include "msg/msgnopadsindeviceconnected.h"

#include <QtCore>

/*******************************************************************************
* Namespace
******************************************************************************/
namespace librepcb {
namespace library {

/*******************************************************************************
* Constructors / Destructor
******************************************************************************/

DeviceCheck::DeviceCheck(const Device& device) noexcept
: LibraryElementCheck(device), mDevice(device) {
}

DeviceCheck::~DeviceCheck() noexcept {
}

/*******************************************************************************
* General Methods
******************************************************************************/

LibraryElementCheckMessageList DeviceCheck::runChecks() const {
LibraryElementCheckMessageList msgs = LibraryElementCheck::runChecks();
checkNoPadsConnected(msgs);
return msgs;
}

/*******************************************************************************
* Protected Methods
******************************************************************************/

void DeviceCheck::checkNoPadsConnected(MsgList& msgs) const {
for (const DevicePadSignalMapItem& item : mDevice.getPadSignalMap()) {
if (item.getSignalUuid()) {
return; // pad is connected, don't show this message
}
}

if (!mDevice.getPadSignalMap().isEmpty()) {
msgs.append(std::make_shared<MsgNoPadsInDeviceConnected>());
}
}

/*******************************************************************************
* End of File
******************************************************************************/

} // namespace library
} // namespace librepcb
73 changes: 73 additions & 0 deletions libs/librepcb/library/dev/devicecheck.h
@@ -0,0 +1,73 @@
/*
* LibrePCB - Professional EDA for everyone!
* Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
* https://librepcb.org/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LIBREPCB_LIBRARY_DEVICECHECK_H
#define LIBREPCB_LIBRARY_DEVICECHECK_H

/*******************************************************************************
* Includes
******************************************************************************/
#include "libraryelementcheck.h"

#include <QtCore>

/*******************************************************************************
* Namespace / Forward Declarations
******************************************************************************/
namespace librepcb {
namespace library {

class Device;

/*******************************************************************************
* Class DeviceCheck
******************************************************************************/

/**
* @brief The DeviceCheck class
*/
class DeviceCheck : public LibraryElementCheck {
public:
// Constructors / Destructor
DeviceCheck() = delete;
DeviceCheck(const DeviceCheck& other) = delete;
explicit DeviceCheck(const Device& device) noexcept;
virtual ~DeviceCheck() noexcept;

// General Methods
virtual LibraryElementCheckMessageList runChecks() const override;

// Operator Overloadings
DeviceCheck& operator=(const DeviceCheck& rhs) = delete;

protected: // Methods
void checkNoPadsConnected(MsgList& msgs) const;

private: // Data
const Device& mDevice;
};

/*******************************************************************************
* End of File
******************************************************************************/

} // namespace library
} // namespace librepcb

#endif // LIBREPCB_LIBRARY_DEVICECHECK_H
56 changes: 56 additions & 0 deletions libs/librepcb/library/dev/msg/msgnopadsindeviceconnected.cpp
@@ -0,0 +1,56 @@
/*
* LibrePCB - Professional EDA for everyone!
* Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
* https://librepcb.org/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*******************************************************************************
* Includes
******************************************************************************/
#include "msgnopadsindeviceconnected.h"

/*******************************************************************************
* Namespace
******************************************************************************/
namespace librepcb {
namespace library {

/*******************************************************************************
* Constructors / Destructor
******************************************************************************/

MsgNoPadsInDeviceConnected::MsgNoPadsInDeviceConnected() noexcept
: LibraryElementCheckMessage(
Severity::Warning, // Only warning because it could be a false-positive
tr("No pads connected"),
tr("The chosen package contains pads, but none of them are connected "
"to component signals. So these pads have no electrical function "
"and when adding the device to a PCB, no traces can be connected to "
"them.\n\nTo fix this issue, connect the package pads to their "
"corresponding component signals in the table widget.\n\nIf all "
"pads have only a mechanical purpose and thus don't need to be "
"connected to component signals, this message can be ignored.")) {
}

MsgNoPadsInDeviceConnected::~MsgNoPadsInDeviceConnected() noexcept {
}

/*******************************************************************************
* End of File
******************************************************************************/

} // namespace library
} // namespace librepcb
61 changes: 61 additions & 0 deletions libs/librepcb/library/dev/msg/msgnopadsindeviceconnected.h
@@ -0,0 +1,61 @@
/*
* LibrePCB - Professional EDA for everyone!
* Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
* https://librepcb.org/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LIBREPCB_LIBRARY_MSGNOPADSINDEVICECONNECTED_H
#define LIBREPCB_LIBRARY_MSGNOPADSINDEVICECONNECTED_H

/*******************************************************************************
* Includes
******************************************************************************/
#include "../../msg/libraryelementcheckmessage.h"

#include <QtCore>

/*******************************************************************************
* Namespace / Forward Declarations
******************************************************************************/
namespace librepcb {
namespace library {

/*******************************************************************************
* Class MsgNoPadsInDeviceConnected
******************************************************************************/

/**
* @brief The MsgNoPadsInDeviceConnected class
*/
class MsgNoPadsInDeviceConnected final : public LibraryElementCheckMessage {
Q_DECLARE_TR_FUNCTIONS(MsgNoPadsInDeviceConnected)

public:
// Constructors / Destructor
MsgNoPadsInDeviceConnected() noexcept;
MsgNoPadsInDeviceConnected(const MsgNoPadsInDeviceConnected& other) noexcept
: LibraryElementCheckMessage(other) {}
virtual ~MsgNoPadsInDeviceConnected() noexcept;
};

/*******************************************************************************
* End of File
******************************************************************************/

} // namespace library
} // namespace librepcb

#endif // LIBREPCB_LIBRARY_MSGNOPADSINDEVICECONNECTED_H
4 changes: 4 additions & 0 deletions libs/librepcb/library/library.pro
Expand Up @@ -54,8 +54,10 @@ SOURCES += \
dev/cmd/cmddeviceedit.cpp \
dev/cmd/cmddevicepadsignalmapitemedit.cpp \
dev/device.cpp \
dev/devicecheck.cpp \
dev/devicepadsignalmap.cpp \
dev/devicepadsignalmapmodel.cpp \
dev/msg/msgnopadsindeviceconnected.cpp \
library.cpp \
librarybaseelement.cpp \
librarybaseelementcheck.cpp \
Expand Down Expand Up @@ -135,8 +137,10 @@ HEADERS += \
dev/cmd/cmddeviceedit.h \
dev/cmd/cmddevicepadsignalmapitemedit.h \
dev/device.h \
dev/devicecheck.h \
dev/devicepadsignalmap.h \
dev/devicepadsignalmapmodel.h \
dev/msg/msgnopadsindeviceconnected.h \
elements.h \
library.h \
librarybaseelement.h \
Expand Down

0 comments on commit c1e5911

Please sign in to comment.