forked from rpelorosso/pcb-tracer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponent.cpp
More file actions
78 lines (64 loc) · 2 KB
/
Component.cpp
File metadata and controls
78 lines (64 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <QGraphicsScene>
#include <QPainter>
#include "Component.h"
int Component::s_componentCount = 0;
PhantomPad::PhantomPad(const QString& name, const QPointF& position): Node(-1) {
m_name = name;
setPos(position);
setFlags(QGraphicsItem::ItemIsSelectable);
setOpacity(1);
m_showOnHover = false;
}
Pad::Pad(const QString& name, int id, const QPointF& position, int number) : Node(id), m_id(id), m_name(name), m_number(number) {
m_componentId = -1;
setPos(position);
setFlags(QGraphicsItem::ItemIsSelectable);
m_showOnHover = false;
setOpacity(1);
}
Component::Component(const QString& name, int id) : m_name(name), m_id(id) {}
int Component::numberOfPads() const {
return m_pads.size();
}
void Component::addPad(Pad* pad) {
pad->m_componentId = m_id;
m_pads.push_back(pad);
}
void Component::addToScene(QGraphicsScene* scene) {
scene->addItem(this);
for (size_t i = 0; i < m_pads.size(); ++i) {
scene->addItem(m_pads[i]);
qDebug() << "Added pad" << m_pads[i]->m_id << "to component" << m_id;
m_pads[i]->setSide(LinkSide::NODE);
}
}
QRectF Component::boundingRect() const {
// Implement bounding rect calculation based on pads' positions
// This is a placeholder implementation
return QRectF();
}
void Component::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
// Implement painting logic for the component
// This is a placeholder implementation
}
void Component::remove(QGraphicsScene* scene) {
for (auto pad : m_pads) {
scene->removeItem(pad);
//delete pad;
}
//m_pads.clear();
scene->removeItem(this);
}
int Component::genComponentId() {
return ++s_componentCount;
}
int Component::getLastComponentId() {
return s_componentCount;
}
void Component::setComponentCount(int count) {
if (count >= 0) {
s_componentCount = count;
} else {
throw std::invalid_argument("component_count must be a non-negative integer");
}
}