bool GWFFileLoader::load(QString file_name, QObject *output) { SCgScene *scene = qobject_cast<SCgScene*>(output); // read data from file QString errorStr; int errorLine; int errorColumn; QFile file(file_name); QDomDocument document; mFileName = file_name; if (!document.setContent(&file, &errorStr, &errorLine, &errorColumn)) { QMessageBox::information(0, qAppName(), QObject::tr("Error while opening file %1.\nParse error at line %2, column %3:\n%4") .arg(file_name) .arg(errorLine) .arg(errorColumn) .arg(errorStr)); return false; } ///////////////////////////////////////////// // Read document GwfObjectInfoReader reader; if (! reader.read(document)) { mLastError = reader.lastError(); showLastError(); return false; } ///////////////////////////////////////////// ///////////////////////////////////////////// //Place objects to scene DefaultSCgObjectBuilder objectBuilder(scene); objectBuilder.buildObjects(reader.objectsInfo()); if (objectBuilder.hasErrors()) { mLastError = QObject::tr("Building process has finished with following errors:\n").arg(mFileName); foreach(const QString& str, objectBuilder.errorList()) mLastError += str + '\n'; showLastError(); }
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; }