void SCgCommandCreateBus::redo() { SCgBaseCommand::redo(); SCgBus *bus = 0; if (mObject == 0) { bus = mScene->construction()->createBus(); bus->setOwner(mOwner); mObject = bus; QPointF pt; foreach (pt, mPoints) bus->appendPoint(pt); connect(mObject, SIGNAL(destroyed()), this, SLOT(busDestroyed())); }else { mScene->construction()->appendObject(mObject); bus = qobject_cast<SCgBus*>(mObject); } bus->setOwner(mOwner); bus->updatePoints(); }
void SCgTupleArranger::startOperation() { // affect changes to bus SCgBus *bus = mTupleNode->bus(); Q_ASSERT(bus != 0); SCgBus *ghostBus = qgraphicsitem_cast<SCgBus*>(mGhosts[bus]); Q_ASSERT(ghostBus != 0); // map points into bus coordinates registerCommand(bus, ghostBus->points()); // affect pairs and objects foreach(SCgPair *pair, mBusPairs) { SCgObject *end = pair->endObject(); SCgObject *beg = pair->beginObject(); Q_ASSERT(end != 0 && beg != 0); SCgPair *ghostPair = qgraphicsitem_cast<SCgPair*>(mGhosts[pair]); Q_ASSERT(ghostPair != 0); registerCommand(pair, ghostPair->points()); if (beg->type() == SCgBus::Type) registerCommand(end, mGhosts[end]->pos()); else registerCommand(beg, mGhosts[beg]->pos()); }
void SCgCommandCreateBus::undo() { Q_ASSERT_X(mObject != 0, "void SCgCommandCreateBus::undo()", "Bus doesn't exists"); mScene->construction()->removeObject(mObject); SCgBus *bus = qobject_cast<SCgBus*>(mObject); bus->setOwner(mOwner); SCgBaseCommand::undo(); }
SCgBus* SCgScene::createSCgBus(const QVector<QPointF>& points, SCgNode *owner) { SCgBus* bus = new SCgBus; if (owner != 0) bus->setOwner(owner); bus->setPoints(points); addItem(bus); return bus; }
void SCgHorizontalArranger::startOperation() { QList<SCgObject*> objects; foreach(QGraphicsItem* it, mView->scene()->selectedItems()) if(SCgObject::isSCgObjectType(it->type()) && it->type() != SCgPair::Type) objects.append(static_cast<SCgObject*>(it)); if(objects.isEmpty() || objects.size() == 1) { QMessageBox::information(0, qAppName(), tr("Nothing to align. Did you forget to select objects for alignment?")); return; } QList<SCgObject*>::const_iterator it; double averageY = 0; // Calculate average Y coordinate for (it = objects.begin(); it != objects.end(); ++it) averageY += (*it)->y(); averageY = averageY/objects.size(); // Set objects position for (it = objects.begin(); it != objects.end(); ++it) { if((*it)->type() == SCgBus::Type) { SCgBus* b = static_cast<SCgBus*>(*it); QVector<QPointF> points = b->mapToParent(b->points()); for(int i = 0; i < points.size(); ++i) points[i].setY(averageY); registerCommand(b, b->mapFromParent(points)); }else { QPointF p = (*it)->pos(); p.setY(averageY); registerCommand(*it, p); } } }
void GwfStreamWriter::writeBus(SCgObject *obj) { writeStartElement("bus"); writeObjectAttributes(obj); SCgBus* bus = static_cast<SCgBus*>(obj); writeAttribute("owner", QString::number(bus->owner()->id())); QVector<QPointF> points = bus->scenePoints(); writeAttribute("b_x", QString::number(points.first().x())); writeAttribute("b_y", QString::number(points.first().y())); writeAttribute("e_x", QString::number(points.last().x())); writeAttribute("e_y", QString::number(points.last().y())); // do not save begin and end points points.pop_back(); points.pop_front(); writePoints(points); writeEndElement(); }
void SCgTupleArranger::startOperation() { // affect changes to bus SCgBus *bus = mTupleNode->bus(); Q_ASSERT(bus != 0); SCgBus *ghostBus = qgraphicsitem_cast<SCgBus*>(mGhosts[bus]); Q_ASSERT(ghostBus != 0); registerCommand(bus, ghostBus->points()); // affect pairs and objects foreach(SCgPair *pair, mBusPairs) { SCgObject *end = pair->getEndObject(); Q_ASSERT(end != 0); SCgObject *ghostEnd = mGhosts[end]; Q_ASSERT(ghostEnd != 0); SCgPair *ghostPair = qgraphicsitem_cast<SCgPair*>(mGhosts[pair]); Q_ASSERT(ghostPair != 0); registerCommand(pair, ghostPair->points()); registerCommand(end, ghostEnd->pos()); }
void SCgSelectSubGraph::select(SCgObject *obj) { obj->setSelected(true); // select parent //if (obj->parentItem() != 0 && SCgObject::isSCgObjectType(obj->parentItem()->type())) //select(static_cast<SCgObject*>(obj->parentItem())); switch(obj->type()) { case SCgBus::Type: { SCgBus *bus = static_cast<SCgBus*>(obj); if (bus->owner() != 0 && !bus->owner()->isSelected()) select(bus->owner()); } break; case SCgNode::Type: { SCgNode *node = static_cast<SCgNode*>(obj); if (node->bus() != 0 && !node->bus()->isSelected()) select(node->bus()); } break; case SCgPair::Type: { SCgPair *pair = static_cast<SCgPair*>(obj); if (pair->beginObject() != 0 && !pair->beginObject()->isSelected()) select(pair->beginObject()); if (pair->endObject() != 0 && !pair->endObject()->isSelected()) select(pair->endObject()); } break; case SCgContour::Type: { SCgContour *contour = static_cast<SCgContour*>(obj); QList<QGraphicsItem*> items = contour->childItems(); QGraphicsItem *item = 0; foreach(item, items) { // skip not sc.g-objects and selected objects if (!SCgObject::isSCgObjectType(item->type()) || item->isSelected()) continue; select(static_cast<SCgObject*>(item)); } } break; } SCgObject::SCgObjectList connected = obj->connectedObjects(); SCgObject *c_obj = 0; foreach(c_obj, connected) { // skip selected objects if (c_obj->isSelected()) continue; select(c_obj); } }