Connection *ConnectionManager::addConnection(ScreenObject *from, int fpin, ScreenObject *to, int tpin, const std::vector<QPoint> &points) { if (points.size() < 2) { return 0; } Connection *c = new Connection; c->from = from; c->fpin = fpin; c->to = to; c->tpin = tpin; c->points = points; c->points[0] = c->from->getPins()[c->fpin].rect.center(); c->points[c->points.size() - 1] = c->to->getPins()[c->tpin].rect.center(); removeDuplicatePoints(c); if (dynamic_cast<ConnectionNode *>(c->to)) { dynamic_cast<ConnectionNode *>(c->to)->setConnection(c->tpin, c); } if (dynamic_cast<ConnectionNode *>(c->from)) { dynamic_cast<ConnectionNode *>(c->from)->setConnection(c->fpin, c); } m_conns.push_back(c); return c; }
void ConnectionManager::objectMoved(ScreenObject *object) { for (ConnectionList::iterator it = m_conns.begin(); it != m_conns.end(); ++it) { Connection *c = *it; if (c->from == object || c->to == object) { removeDuplicatePoints(c); } } }
void PolygonLine :: cropPolygon(const double &iArcPosStart, const double &iArcPosEnd) { std::vector<FloatArray> points; giveSubPolygon(points, iArcPosStart, iArcPosEnd); setVertices(points); const double tol2 = 1.0e-18; removeDuplicatePoints(tol2); }
bool ConnectionManager::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { if (m_moving && m_fromObject && m_movingConn) { ScreenObject *object = m_screen->getObject(NORM(event->x()), NORM(event->y())); if (object) { int pin = m_screen->getPin(object, NORM(event->x()), NORM(event->y())); if (pin != -1) { if (m_fromObject == m_movingConn->to) { ConnectionNode *node = dynamic_cast<ConnectionNode *>(m_movingConn->to); if (node) { node->removeConnection(m_movingConn->tpin); } m_movingConn->tpin = pin; m_movingConn->to = object; node = dynamic_cast<ConnectionNode *>(m_movingConn->to); if (node) { node->setConnection(m_movingConn->tpin, m_movingConn); } } else { ConnectionNode *node = dynamic_cast<ConnectionNode *>(m_movingConn->from); if (node) { node->removeConnection(m_movingConn->fpin); } m_movingConn->fpin = pin; m_movingConn->from = object; node = dynamic_cast<ConnectionNode *>(m_movingConn->from); if (node) { node->setConnection(m_movingConn->fpin, m_movingConn); } } m_moving->setX(object->getPins()[pin].rect.center().x()); m_moving->setY(object->getPins()[pin].rect.center().y()); } else { if (m_fromObject == m_movingConn->from) { m_moving->setX(m_fromObject->getPins()[m_movingConn->fpin].rect.center().x()); m_moving->setY(m_fromObject->getPins()[m_movingConn->fpin].rect.center().y()); } else { m_moving->setX(m_fromObject->getPins()[m_movingConn->tpin].rect.center().x()); m_moving->setY(m_fromObject->getPins()[m_movingConn->tpin].rect.center().y()); } } } else { if (m_fromObject == m_movingConn->from) { m_moving->setX(m_fromObject->getPins()[m_movingConn->fpin].rect.center().x()); m_moving->setY(m_fromObject->getPins()[m_movingConn->fpin].rect.center().y()); } else { m_moving->setX(m_fromObject->getPins()[m_movingConn->tpin].rect.center().x()); m_moving->setY(m_fromObject->getPins()[m_movingConn->tpin].rect.center().y()); } } m_fromObject = 0; } else if (m_moving && m_movingConn) { removeDuplicatePoints(m_movingConn); m_moving = 0; m_movingConn = 0; } } return true; }
void ConnectionManager::removeUselessNode(ConnectionNode *node) { if (node->isUseless()) { Connection *c1 = 0; Connection *c2 = 0; int c1pin = 0; int c2pin = 0; for (int i = 0; i < 4; ++i) { Connection *c = node->getConnection(i); if (!c) { continue; } if (!c1) { c1 = c; c1pin = i;} else if (!c2) { c2 = c; c2pin = i; } } if (c1->to == node) { if (c1pin == 0) { c1->points[c1->points.size() - 1].setX(c1->points[c1->points.size() - 1].x() + 12); } else if (c1pin == 1) { c1->points[c1->points.size() - 1].setY(c1->points[c1->points.size() - 1].y() - 12); } else if (c1pin == 2) { c1->points[c1->points.size() - 1].setX(c1->points[c1->points.size() - 1].x() - 12); } else if (c1pin == 3) { c1->points[c1->points.size() - 1].setY(c1->points[c1->points.size() - 1].y() + 12); } if (c2->to == node) { qDebug() << "1x"; c1->to = c2->from; c1->tpin = c2->fpin; c2->to = 0; for (int i = c2->points.size() - 1; i != -1; i--) { qDebug() << "push" << c2->points[i]; c1->points.push_back(c2->points[i]); } for (int i = 0; i != c1->points.size(); i++) { qDebug() << "got" << c1->points[i]; } } else { qDebug() << "2x"; c1->to = c2->to; c1->tpin = c2->tpin; c2->from = 0; for (int i = 0; i != c2->points.size(); i++) { qDebug() << "push" << c2->points[i]; c1->points.push_back(c2->points[i]); } for (int i = 0; i != c1->points.size(); i++) { qDebug() << "got" << c1->points[i]; } } } else { if (c1pin == 0) { c1->points[0].setX(c1->points[0].x() + 12); } else if (c1pin == 1) { c1->points[0].setY(c1->points[0].y() - 12); } else if (c1pin == 2) { c1->points[0].setX(c1->points[0].x() - 12); } else if (c1pin == 3) { c1->points[0].setY(c1->points[0].y() + 12); } if (c2->to == node) { qDebug() << "3x"; c1->from = c2->from; c1->fpin = c2->fpin; c2->to = 0; for (int i = 0; i != c1->points.size(); i++) { qDebug() << "push" << c1->points[i]; c2->points.push_back(c1->points[i]); } c1->points = c2->points; for (int i = 0; i != c1->points.size(); i++) { qDebug() << "got" << c1->points[i]; } } else { qDebug() << "4x"; c1->from = c2->to; c1->fpin = c2->tpin; c2->from = 0; std::reverse(c2->points.begin(), c2->points.end()); for (int i = 0; i != c1->points.size(); i++) { qDebug() << "push" << c1->points[i]; c2->points.push_back(c1->points[i]); } c1->points = c2->points; for (int i = 0; i != c1->points.size(); i++) { qDebug() << "got" << c1->points[i]; } } } removeConnection(c2); removeDuplicatePoints(c1); if (!m_removingUselessNode) { m_removingUselessNode = true; m_screen->removeObject(node); m_removingUselessNode = false; } } }