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); }
bool SCgTranslateGWFToSc::translate(QIODevice &device, ScMemoryInterface *memory, const ScUri &set) { mScMemory = memory; Q_ASSERT(mScMemory != 0); QScopedPointer<ScHelperInterface> helper(SCgPlugin::rootInterface()->scHelper(mScMemory)); // read data from gwf GwfObjectInfoReader reader; if (!reader.read(&device)) { qDebug() << "Error while translate to sc-code: " << reader.lastError(); return false; } // iterate all objects and resolve them GwfObjectInfoReader::TypeToObjectsMap::const_iterator it; for (it = reader.objectsInfo().begin(); it != reader.objectsInfo().end(); ++it) { GwfObjectInfoReader::ObjectInfoList::const_iterator it_info; for (it_info = (*it).begin(); it_info != (*it).end(); ++it_info) resolveObject(*it_info); } // setup pair begin and end objects const GwfObjectInfoReader::ObjectInfoList &list = reader.objectsInfo()[SCgVisualObject::SCgPairType]; GwfObjectInfoReader::ObjectInfoList::const_iterator it_info; for (it_info = list.begin(); it_info != list.end(); ++it_info) { SCgPairInfo *pairInfo = static_cast<SCgPairInfo*>(*it_info); ScUri pair_uri = mIdToScUri[pairInfo->id()]; // get begin and end uri's ScUri b = mIdToScUri[pairInfo->beginObjectId()]; ScUri e = mIdToScUri[pairInfo->endObjectId()]; // setup begin and end mScMemory->set_beg(pair_uri, b); mScMemory->set_end(pair_uri, e); } // append objects into parent sets for (it = reader.objectsInfo().begin(); it != reader.objectsInfo().end(); ++it) for (it_info = (*it).begin(); it_info != (*it).end(); ++it_info) { SCgObjectInfo *info = *it_info; // check if object has a parent if (info->parentId() != "0" && !info->parentId().isEmpty()) { ScUri uri = mIdToScUri[info->id()]; ScUri parent = mIdToScUri[info->parentId()]; // generate 5 elements construction to append new arc between parent and child into output set ScUriVector res; ScTemplate templ(parent, ScElementType(ScArcMain | ScConst | ScPos), uri, ScElementType(ScArcMain | ScConst | ScPos), set); if (!helper->genElStr(templ, res)) SuiExcept(SuiExceptionInternalError, QString("Can't append '%1' into '%1'").arg(uri.value()).arg(parent.value()), "bool SCgTranslateGWFToSc::translate(QIODevice &device, ScMemoryInterface *memory, const ScUri &set)"); } } // append all translated objects into output set ScUriList::iterator it_list; ScUriVector res; for (it_list = mTranslatedObjects.begin(); it_list != mTranslatedObjects.end(); ++it_list) if (!helper->genElStr(ScTemplate() << set << ScElementType(ScArcMain | ScConst| ScPos) << *it_list, res)) SuiExcept(SuiExceptionInternalError, QString("Can't append '%1 into output set '%2").arg((*it_list).value()).arg(set.value()), "bool SCgTranslateGWFToSc::translate(QIODevice &device, ScMemoryInterface *memory, const ScUri &set)"); return true; }