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 DefaultSCgObjectBuilder::buildObjects(const AbstractSCgObjectBuilder::TypeToObjectsMap& objects) { SCgObjectInfo* info; // parse nodes foreach(info, objects[SCgNode::Type]) buildNode(static_cast<SCgNodeInfo*>(info)); // parse pairs foreach(info, objects[SCgPair::Type]) buildPair(static_cast<SCgPairInfo*>(info)); // parse buses foreach(info, objects[SCgBus::Type]) buildBus(static_cast<SCgBusInfo*>(info)); // parse contours foreach(info, objects[SCgContour::Type]) buildContour(static_cast<SCgContourInfo*>(info)); // set parents relation ParentChildMap::iterator parentIt; for (parentIt = mParentChild.begin(); parentIt != mParentChild.end(); parentIt++) { if (!mId2SCgObj.contains(parentIt.value())) continue; SCgObject *parent = mId2SCgObj[parentIt.value()]; SCgObject *child = mId2SCgObj[parentIt.key()]; child->setParentItem(parent); } // holds true, if there are errors while setting begin and end objects. bool isConnectedDuty = false; // set begin and end objects for pairs foreach(SCgObjectInfo* info, objects[SCgPair::Type]) { SCgPairInfo* pairInfo = static_cast<SCgPairInfo*>(info); SCgPair *pair = static_cast<SCgPair*>(mId2SCgObj[pairInfo->id()]); // we can't build pair without begin or end objects if (!mId2SCgObj.contains(pairInfo->beginObjectId()) || !mId2SCgObj.contains(pairInfo->endObjectId())) { mErrors.append(QObject::tr("Can't find begin or end object for pair id=\"%1\"") .arg(pairInfo->id())); mId2SCgObj.remove(pairInfo->id()); isConnectedDuty = true; delete pair; continue; } SCgObject *begObject = mId2SCgObj[pairInfo->beginObjectId()]; SCgObject *endObject = mId2SCgObj[pairInfo->endObjectId()]; pair->setBeginObject(begObject); pair->setEndObject(endObject); }
void SCgCommandChangePairBeginEndDots::undo() { SCgBaseCommand::undo(); ChangeDotsInfo::const_iterator it = mChangeDotsInfo.constBegin(); for(;it != mChangeDotsInfo.constEnd(); ++it) { SCgPair* pair = it.key(); const QPair<BeginEndPairDots, BeginEndPairDots>& dotPositions = it.value(); pair->setBeginDotPosition(dotPositions.first.first); pair->setEndDotPosition(dotPositions.first.second); } }
SCgPair* SCgScene::createSCgPair(SCgObject *begObj, SCgObject *endObj, const QVector<QPointF> &points) { Q_ASSERT_X(begObj && endObj, "SCgPair* SCgScene::createSCgPair(SCgObject *begObj, SCgObject *endObj, const QVector<QPointF> &points)", "Begin or end object is null"); SCgPair *pair = new SCgPair; pair->setTypeAlias("pair/const/pos/perm/orient/accessory"); pair->setBeginObject(begObj); pair->setEndObject(endObj); pair->setPoints(points); addItem(pair); return pair; }
void GwfStreamWriter::writePair(SCgObject *obj) { QString type = mTypeAlias2GWFType[obj->typeAlias()].mid(0,3); if(type=="arc") writeStartElement(type); else writeStartElement("pair"); writeObjectAttributes(obj); SCgPair* pair = static_cast<SCgPair*>(obj); SCgObject* b = pair->getBeginObject(); SCgObject* e = pair->getEndObject(); writeAttribute("id_b", QString::number(b->id())); writeAttribute("id_e", QString::number(e->id())); writePosition(b,"b_x","b_y"); writePosition(e,"e_x","e_y"); writeAttribute("dotBBalance", QString::number(pair->getBeginDot())); writeAttribute("dotEBalance", QString::number(pair->getEndDot())); QVector<QPointF> points = pair->scenePoints(); 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()); }
QIcon SCgAlphabet::createPairIcon(const QSize &size, QString type) { QIcon icon; SCgPair *pair = new SCgPair; pair->setTypeAlias(type); QVector<QPointF> points; points.push_back(QPointF(-size.width() / 2.f, 0.f)); points.push_back(QPointF(size.width() / 2.f, 0.f)); pair->setPoints(points); QPixmap pixmap(size); QPainter painter; pixmap.fill(Qt::transparent); painter.begin(&pixmap); painter.setRenderHint(QPainter::Antialiasing, true); pair->setColor(QColor(0, 0, 0, 255));//(state == QIcon::On) ? 255 : 128)); painter.translate(size.width() / 2.f, size.height() / 2.f); painter.scale(0.9f, 0.9f); paintPair(&painter, pair); painter.end(); for (int mode = QIcon::Normal; mode <= QIcon::Selected; mode++) for (int state = QIcon::On; state <= QIcon::Off; state++) icon.addPixmap(pixmap, (QIcon::Mode)mode, (QIcon::State)state); delete pair; return icon; }
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); } }