123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194 |
- #include "GraphMLReader.h"
- #include <iostream>
- #include <qstring.h>
- #include <QTime>
- #include <QDebug>
- #include <QMap>
- SubGraph* gMainGraph = NULL;
- SubGraph* gCurrentSubGraph = NULL;
- GraphMLReader::GraphMLReader()
- {
-
- gMainGraph = new SubGraph();
-
- gCurrentSubGraph = gMainGraph;
-
- m_bGraphMLTag = false;
-
- m_bGraphTag = false;
-
- m_bEdgeTag = false;
- m_bEdgeDataTag = false;
-
-
- m_bIsGraphCoordXSet = false;
- m_bIsGraphCoordYSet = false;
- m_bIsGraphHeightSet = false;
- m_bIsGraphWidthSet = false;
-
- m_bIsNodeCoordXSet = false;
- m_bIsNodeCoordYSet = false;
- m_bIsNodeHeightSet = false;
- m_bIsNodeWidthSet = false;
-
- m_bIsEdgeDirectionSet = false;
- m_iNodeStartAt = 0;
- }
- SubGraph& GraphMLReader::readGraphML(QFile *file)
- {
- GraphMLReader graphMLReader;
-
- QTime t;
- qDebug() << t.currentTime();
- t.start();
-
- m_iNodeStartAt = 0;
- m_iNodeEndAt = 0;
- m_iGraphStartAt = 0;
- m_iNode_GraphFoundCounter = 0;
- try
- {
-
- QString sFileName = file->fileName();
-
-
- }
- catch(LayoutFileIOException& eException)
- {
- throw LayoutFileIOException(__FUNCTION__,
- LayoutExceptionEnum::LAYOUT_INVALID_FILE_FORMAT,
- eException.getFileName());
- }
- try
- {
-
- QXmlInputSource xmlInputSource(file);
- QXmlSimpleReader xmlSimpleReader;
- xmlSimpleReader.setContentHandler(&graphMLReader);
- xmlSimpleReader.parse(xmlInputSource);
- }
- catch(LayoutFileIOException& e)
- {
- file->close();
- if(e.getExceptionSubType() == LayoutExceptionEnum::UNSUPPORTED_FILE_TYPE)
- {
- }
- QString sFileName = e.getFileName();
- QString sErrorMessage = e.getErrorMessage();
- cout<<"Exception : "<<sErrorMessage.toStdString()<<endl;
- throw LayoutFileIOException(__FUNCTION__,
- LayoutExceptionEnum::FILE_READ_OPERATION_ERROR,
- sFileName);
- }
- catch(LayoutMemoryException& eException)
- {
- file->close();
- QString sErrorMessage = eException.getErrorMessage();
- QString sObjectName = eException.getObjectName();
- cout<<"Exception : "<<sErrorMessage.toStdString()<<" "<<sObjectName.toStdString()<<endl;
- throw LayoutMemoryException(__FUNCTION__, LayoutExceptionEnum::NULL_POINTER_EXCEPTION, sObjectName);
- }
- catch(LayoutException& eException)
- {
- file->close();
- QString sErrorMessage = eException.getErrorMessage();
- int iErrorCode = eException.getErrorCode();
- QString sEntityValue = eException.getEntityValue();
- QString sEntityType = eException.getEntityType();
- cout<<"Exception : "<<sErrorMessage.toStdString()<<" "<<iErrorCode<<" "<<sEntityType.toStdString()<<" "<<sEntityValue.toStdString()<<endl;
- throw LayoutException(__FUNCTION__, LayoutExceptionEnum::INVALID_PARAMETER,sEntityValue,sEntityType);
- }
- catch(boost::exception& eBoostException)
- {
- file->close();
- throw *boost::get_error_info<errmsg_info>(eBoostException);
- }
- catch(...)
- {
- file->close();
- throw;
- }
- qDebug() << "Duration : " << t.elapsed();
- int iTime=t.elapsed();
- qDebug()<<"\nTime : "<<iTime;
-
- return *gMainGraph;
- }
- bool GraphMLReader::isSupportedGraphmlFile(QString sGraphMLFileName)
- {
- bool bIsSupportedFormat = false;
- if(sGraphMLFileName.trimmed().isEmpty() == false)
- {
- if(sGraphMLFileName.trimmed().endsWith(GRAPHML,Qt::CaseInsensitive) == true)
- {
- bIsSupportedFormat = true;
- }
- }
- else
- {
- bIsSupportedFormat = false;
- }
- return bIsSupportedFormat;
- }
- void GraphMLReader::validateGraphML(QString sGraphMLInstanceFileName)
- {
- LAYOUT_ASSERT((sGraphMLInstanceFileName.trimmed().isEmpty() != true),
- LayoutFileIOException(__FUNCTION__,
- LayoutExceptionEnum::INVALID_FILE_NAME,
- sGraphMLInstanceFileName));
- QString sSchemaFileName = SCHEMA_FILE_PATH;
- if (sSchemaFileName.isEmpty())
- {
- throw LayoutFileIOException(__FUNCTION__,
- LayoutExceptionEnum::FILE_NOT_FOUND,
- sSchemaFileName);
- return;
- }
- qDebug() << "Selected schema = " << sSchemaFileName;
- qDebug() << "Selected instance = " << sGraphMLInstanceFileName;
- QFile qSchemaFile(sSchemaFileName);
- if (!qSchemaFile.open(QIODevice::ReadOnly | QIODevice::Text))
- {
- throw LayoutFileIOException(__FUNCTION__,
- LayoutExceptionEnum::FILE_READ_OPERATION_ERROR,
- sSchemaFileName,qSchemaFile.errorString());
- return;
- }
- QFile qInstanceFile(sGraphMLInstanceFileName);
- if (!qInstanceFile.open(QIODevice::ReadOnly | QIODevice::Text))
- {
- throw LayoutFileIOException(__FUNCTION__,
- LayoutExceptionEnum::FILE_READ_OPERATION_ERROR,
- sGraphMLInstanceFileName,qInstanceFile.errorString());
- return;
- }
-
- const QByteArray schemaData = qSchemaFile.readAll();
-
- const QByteArray instanceData = qInstanceFile.readAll();
-
- MessageHandler messageHandler;
-
- QXmlSchema schema;
- schema.setMessageHandler(&messageHandler);
- bool bErrorOccurred = false;
- qDebug() << "Loading Schema";
- if (schema.load(schemaData) == true)
- {
- qDebug() << "Validating Schema";
- if (schema.isValid())
- {
- QXmlSchemaValidator validator(schema);
- qDebug() << "Validating Instance";
- if (!validator.validate(instanceData))
- {
-
- bErrorOccurred = true;
- }
- }
- }
- else
- {
- bErrorOccurred = true;
- }
- if (bErrorOccurred)
- {
- qDebug() << "Validation Un - Successful";
- qDebug() << messageHandler.getStatusMessage()
- <<" "<<messageHandler.getLineNumber()
- <<" "<<messageHandler.getColumnNumber();
- std::cout<< messageHandler.getStatusMessage().toStdString()<<" "<<messageHandler.getLineNumber()<<" "<<messageHandler.getColumnNumber()<<endl;
- throw LayoutFileIOException(__FUNCTION__,
- LayoutExceptionEnum::LAYOUT_INVALID_FILE_FORMAT,
- sGraphMLInstanceFileName,messageHandler.getStatusMessage());
- }
- else
- {
- qDebug() << "Validation Successful";
- }
-
- qSchemaFile.close();
- qInstanceFile.close();
- }
- bool GraphMLReader::startElement( const QString &namespaceURI, const QString &sTagElement, const QString &qName,
- const QXmlAttributes &lstAttributes)
- {
- Q_UNUSED(namespaceURI);
- Q_UNUSED(qName);
-
- ++m_iNode_GraphFoundCounter;
- if (!m_bGraphMLTag && sTagElement != GRAPHML)
- {
-
- m_sErrorText = NOT_GRAPHML_FILE;
- return false;
- }
- if(sTagElement == XML_EXTN)
- {
-
- QString sVersion = lstAttributes.value(VERSION);
- QString sEncoding = lstAttributes.value(ENCODING);
-
- if ((!sVersion.isEmpty() || sVersion != VERSION_VALUE))
- {
-
- m_sErrorText = INVALID_VERSION;
- throw LayoutFileIOException(__FUNCTION__,
- LayoutExceptionEnum::UNSUPPORTED_FILE_FORMAT,
- VERSION);
- }
- else if(!sEncoding.isEmpty() || sEncoding != ENCODING_VALUE)
- {
-
- m_sErrorText = INVALID_ENCODING;
- throw LayoutFileIOException(__FUNCTION__,
- LayoutExceptionEnum::UNSUPPORTED_FILE_FORMAT,
- VERSION);
- }
- }
- if (sTagElement == GRAPHML)
- {
- QString sVersion = lstAttributes.value(VERSION);
- if (!sVersion.isEmpty() && sVersion != VERSION_VALUE)
- {
- m_sErrorText = INVALID_VERSION;
- return false;
- }
- m_bGraphMLTag = true;
- }
- else if(sTagElement.compare(GRAPH,Qt::CaseInsensitive) == 0)
- {
-
-
- m_sCurrentText.clear();
-
- m_iGraphStartAt = m_iNode_GraphFoundCounter;
-
- m_bGraphTag = true;
-
- QString strId;
- int iAttrCount=lstAttributes.count();
- for( int iIndex=0; iIndex<iAttrCount; iIndex++ )
- {
- if( lstAttributes.localName( iIndex ) == GRAPH_ID )
- {
- strId = lstAttributes.value( iIndex );
- }
- }
-
- m_sCurrentDomainId = strId;
- m_sCurrentDomain = GRAPH;
-
- if(m_iGraphStartAt - m_iNodeStartAt==1)
- {
-
- SubGraph& gNewChildSubgraph= gCurrentSubGraph->create_subgraph();
- gCurrentSubGraph = &gNewChildSubgraph;
-
- boost::ref_property_map<SubGraph*, GraphProperties>
- mapGraphReferenceToId(boost::get_property(*gCurrentSubGraph,graph_custom_prop));
- mapGraphReferenceToId[gCurrentSubGraph].sId = strId;
- m_dirtyNode.m_bIsDirtyNode = false;
- }
- else
- {
-
- boost::ref_property_map<SubGraph*, GraphProperties>
- mapGraphReferenceToProperty(boost::get_property(*gCurrentSubGraph,graph_custom_prop));
- mapGraphReferenceToProperty[gCurrentSubGraph].sId = strId;
- }
- }
- if(sTagElement.compare(NODE,Qt::CaseInsensitive) == 0)
- {
-
-
-
- if(m_bGraphTag == true)
- {
-
-
- if(m_bIsGraphCoordXSet && m_bIsGraphCoordYSet && m_bIsGraphHeightSet && m_bIsGraphWidthSet)
- {
- BoostGraphWrapper boostGraphWrapper;
-
-
- int iGraphLeftTopCoordX = structGraphProperty.iCoordX;
- int iGraphLeftTopCoordY = structGraphProperty.iCoordY;
- int iGraphHeight = structGraphProperty.iHeight;
- int iGraphWidth = structGraphProperty.iWidth;
-
- int iGraphCenterCoordX = (iGraphLeftTopCoordX + (iGraphWidth/2));
- int iGraphCenterCoordy = (iGraphLeftTopCoordY + (iGraphHeight/2));
- QString sGraphId = boostGraphWrapper.getGraphId(*gCurrentSubGraph);
-
- boostGraphWrapper.setGraphCenterCoordX(iGraphCenterCoordX, *gCurrentSubGraph);
- boostGraphWrapper.setGraphCenterCoordY(iGraphCenterCoordy, *gCurrentSubGraph);
- boostGraphWrapper.setGraphHeight(iGraphHeight, *gCurrentSubGraph);
- boostGraphWrapper.setGraphWidth(iGraphWidth, *gCurrentSubGraph);
-
- boostGraphWrapper.setGraphLeftTopCoordX(iGraphLeftTopCoordX, *gCurrentSubGraph);
- boostGraphWrapper.setGraphLeftTopCoordY(iGraphLeftTopCoordY, *gCurrentSubGraph);
-
- m_bGraphTag = false;
-
- m_bIsGraphCoordXSet = false;
- m_bIsGraphCoordYSet = false;
- m_bIsGraphHeightSet = false;
- m_bIsGraphWidthSet = false;
- }
- else
- {
-
- throw LayoutException(__FUNCTION__, LayoutExceptionEnum::MANDATORY_FIELD_MISSING, GRAPH);
- }
- }
-
- m_sCurrentText.clear();
-
- m_iNodeStartAt = m_iNode_GraphFoundCounter;
- m_dirtyNode.m_bIsDirtyNode = true;
-
- QString sNodeId;
- int iAttrCount = lstAttributes.count();
- for( int iIndex=0; iIndex<iAttrCount; iIndex++ )
- {
- if( lstAttributes.localName( iIndex ) == NODE_ID )
- {
- sNodeId = lstAttributes.value( iIndex );
-
- qDebug()<<"Set Node Ids:"<<sNodeId;
- try
- {
-
- m_dirtyNode.setID(sNodeId);
- }
- catch(LayoutException& eException)
- {
-
- throw LayoutException(__FUNCTION__, LayoutExceptionEnum::INVALID_PARAMETER,
- eException.getEntityValue(), eException.getEntityType());
- }
- }
- }
-
- m_sCurrentDomainId = sNodeId;
- m_sCurrentDomain = NODE;
- }
- if(sTagElement.compare(EDGE,Qt::CaseInsensitive) == 0)
- {
- m_sCurrentText.clear();
- m_dirtyEdge.m_bIsDirtyEdge = true;
-
- QString sEdgeId,sSourceVertexId,sTargetVertexId;
- int iAttrCount=lstAttributes.count();
- for( int iIndex=0; iIndex<iAttrCount; iIndex++ )
- {
- if( lstAttributes.localName( iIndex ) == SOURCE_OF_EDGE)
- {
- sSourceVertexId = lstAttributes.value( iIndex );
- }
- if(lstAttributes.localName(iIndex)==TARGET_OF_EDGE)
- {
- sTargetVertexId = lstAttributes.value( iIndex );
- }
- if(lstAttributes.localName(iIndex) == EDGE_ID)
- {
- sEdgeId = lstAttributes.value( iIndex );
- try
- {
- m_dirtyEdge.setId(sEdgeId);
- }
- catch(...)
- {
-
- }
- }
- }
-
- m_sCurrentDomainId = sEdgeId;
- m_sCurrentDomain = EDGE;
-
- try
- {
- m_dirtyEdge.setSourceTarget(sSourceVertexId,sTargetVertexId);
- }
- catch(LayoutException& eException)
- {
- LayoutException(__FUNCTION__,
- LayoutExceptionEnum::INVALID_PARAMETER,
- eException.getEntityValue(),
- eException.getEntityType());
- }
- catch(...)
- {}
-
- m_bEdgeTag = true;
- }
- if(sTagElement.compare(KEY,Qt::CaseInsensitive) == 0)
- {
-
- structKeyInfo.sKeyId = lstAttributes.value(KEY_ID);
- structKeyInfo.sKeyName = lstAttributes.value(ATTR_NAME);
- structKeyInfo.keyType = QSTRING_TYPE;
- structKeyInfo.sDomain = lstAttributes.value(FOR);
-
- if(lstAttributes.value(ATTR_TYPE) == BOOL_TYPE_STRING)
- {
- structKeyInfo.keyType = BOOLEAN_TYPE;
- }
- else if(lstAttributes.value(ATTR_TYPE) == DOUBL_TYPE_STRING)
- {
- structKeyInfo.keyType = DOUBLE_TYPE;
- }
- else if(lstAttributes.value(ATTR_TYPE) == INT_TYPE_STRING)
- {
- structKeyInfo.keyType = INTIGER_TYPE;
- }
-
- QString sKeyId = structKeyInfo.sKeyId;
- m_mapKeyIdToKeyInfo.insert(sKeyId,structKeyInfo);
- m_vecKeyInfo.push_back(structKeyInfo);
- }
- if(sTagElement.compare(DEFAULT,Qt::CaseInsensitive) == 0)
- {
-
- }
- if(sTagElement.compare(DATA,Qt::CaseInsensitive) == 0)
- {
-
- QString sKey;
- int iAttrCount=lstAttributes.count();
- for( int iIndex=0; iIndex<iAttrCount; iIndex++ )
- {
- if( lstAttributes.localName( iIndex ) == KEY )
- {
-
- sKey = lstAttributes.value( iIndex );
- }
- }
-
- m_sCurrentKeyId = sKey;
-
- if(m_bEdgeTag == true)
- {
- m_bEdgeDataTag = true;
- }
- }
- if(sTagElement.compare(BEND,Qt::CaseInsensitive) == 0)
- {
-
- if(m_bEdgeDataTag == true)
- {
- QString sValueX, sValueY;
- int iIndex = 0;
-
- if( lstAttributes.localName( iIndex ) == XVALUE)
- {
- sValueX = lstAttributes.value( iIndex );
- }
-
- if(lstAttributes.localName(iIndex + 1)== YVALUE)
- {
- sValueY = lstAttributes.value( iIndex + 1 );
- }
-
- int iValueX = sValueX.toInt();
- int iValueY = sValueY.toInt();
- m_dirtyEdge.setEdgeBendPointsCoordinates(iValueX, iValueY);
- }
- }
- return true;
- }
- bool GraphMLReader::characters(const QString &sCurrentString)
- {
-
-
- m_sCurrentText = sCurrentString;
- return true;
- }
- void GraphMLReader::convertTextToInt(QString sKeyValue)
- {
-
- int iKeyValue = sKeyValue.toInt();
- m_iCurrentKeyValue = iKeyValue;
- }
- void GraphMLReader::convertTextToBool(QString sKeyValue)
- {
-
- if(sKeyValue.compare(TRUE_VALUE,Qt::CaseInsensitive) == 0)
- {
- m_bCurrentKeyValue = true;
- }
- if(sKeyValue.compare(FALSE_VALUE,Qt::CaseInsensitive) == 0)
- {
- m_bCurrentKeyValue = false;
- }
- }
- void GraphMLReader::convertTextToDouble(QString sKeyValue)
- {
-
- double dKeyValue = sKeyValue.toDouble();
- m_dCurrentKeyValue = dKeyValue;
- }
- bool GraphMLReader::endElement( const QString &namespaceURI, const QString &sTagElement, const QString &qName )
- {
- Q_UNUSED(namespaceURI);
- Q_UNUSED(qName);
-
- ++m_iNode_GraphFoundCounter;
- if(sTagElement.compare(GRAPHML, Qt::CaseInsensitive) == 0)
- {
-
- m_bGraphMLTag = false;
- }
- if(sTagElement.compare(GRAPH,Qt::CaseInsensitive) == 0)
- {
-
- m_iGraphEndAt = m_iNode_GraphFoundCounter;
-
- if(m_bGraphTag == true)
- {
-
- if(m_bIsGraphCoordXSet && m_bIsGraphCoordYSet && m_bIsGraphHeightSet && m_bIsGraphWidthSet)
- {
-
- BoostGraphWrapper boostGraphWrapper;
-
-
- int iGraphLeftTopCoordX = structGraphProperty.iCoordX;
- int iGraphLeftTopCoordY = structGraphProperty.iCoordY;
- int iGraphHeight = structGraphProperty.iHeight;
- int iGraphWidth = structGraphProperty.iWidth;
-
- int iGraphCenterCoordX = (iGraphLeftTopCoordX + (iGraphWidth/2));
- int iGraphCenterCoordy = (iGraphLeftTopCoordY + (iGraphHeight/2));
-
- boostGraphWrapper.setGraphCenterCoordX(iGraphCenterCoordX, *gCurrentSubGraph);
- boostGraphWrapper.setGraphCenterCoordY(iGraphCenterCoordy, *gCurrentSubGraph);
- boostGraphWrapper.setGraphHeight(iGraphHeight, *gCurrentSubGraph);
- boostGraphWrapper.setGraphWidth(iGraphWidth, *gCurrentSubGraph);
-
- boostGraphWrapper.setGraphLeftTopCoordX(iGraphLeftTopCoordX, *gCurrentSubGraph);
- boostGraphWrapper.setGraphLeftTopCoordY(iGraphLeftTopCoordY, *gCurrentSubGraph);
- m_bGraphTag = false;
-
- m_bIsGraphCoordXSet = false;
- m_bIsGraphCoordYSet = false;
- m_bIsGraphHeightSet = false;
- m_bIsGraphWidthSet = false;
- }
- else
- {
-
- throw LayoutException(__FUNCTION__, LayoutExceptionEnum::MANDATORY_FIELD_MISSING, GRAPH);
- }
- }
-
- SubGraph& gCurrentParentGraph = gCurrentSubGraph->parent();
- gCurrentSubGraph = &gCurrentParentGraph;
- }
- if(sTagElement.compare(NODE,Qt::CaseInsensitive) == 0)
- {
-
- m_iNodeEndAt = m_iNode_GraphFoundCounter;
- QString strId;
- try
- {
-
- strId = m_dirtyNode.getID();
- }
- catch(LayoutException& eException)
- {
- throw LayoutException(__FUNCTION__, LayoutExceptionEnum::INVALID_ATTRIBUTE_VALUE, EMPTY_ID_FOUND, NODE);
- }
- if( (m_iNodeEndAt < m_iNodeStartAt) && (m_iNodeStartAt < m_iGraphStartAt ) )
- {
-
- m_dirtyNode.m_bIsDirtyNode = false;
- }
-
- else if( ( m_iNodeStartAt < m_iNodeEndAt )
- && !( ( m_iNodeStartAt < m_iGraphStartAt ) && ( m_iGraphStartAt < m_iNodeEndAt ) ) )
- {
-
- if( m_dirtyNode.m_bIsDirtyNode == true )
- {
- try
- {
- addVertexToSubgraph(strId);
- m_dirtyNode.m_bIsDirtyNode = false;
- }
- catch(LayoutException & eException)
- {
- QString sErrorMessage = eException.getErrorMessage();
- throw LayoutException(__FUNCTION__, LayoutExceptionEnum::INVALID_PARAMETER, EMPTY_ID_FOUND, sErrorMessage);
- }
- catch(boost::exception& eBoostException)
- {
- throw *boost::get_error_info<errmsg_info>(eBoostException);
- }
- catch(...)
- {
- throw;
- }
- }
- }
- }
- if( sTagElement.compare(EDGE,Qt::CaseInsensitive) == 0 )
- {
- QString sSourceId , sTargetId , sEdgeId;
-
- sSourceId = m_dirtyEdge.getSource();
- sTargetId = m_dirtyEdge.getTarget();
- sEdgeId = m_dirtyEdge.getId();
-
- if( m_dirtyEdge.m_bIsDirtyEdge == true )
- {
- try
- {
- addEdgeToMainGraph(sSourceId,sTargetId,sEdgeId);
- m_dirtyEdge.m_bIsDirtyEdge = false;
-
- m_bEdgeTag = false;
- }
- catch(LayoutException& eException)
- {
- if(eException.getExceptionSubType() == LayoutExceptionEnum::INVALID_PARAMETER)
- {
- throw LayoutException(__FUNCTION__,
- LayoutExceptionEnum::INVALID_PARAMETER,
- eException.getEntityValue(),
- eException.getEntityType());
- }
- }
- }
- }
- if(sTagElement.compare(KEY,Qt::CaseInsensitive) == 0)
- {
-
- structKeyInfo.sDefaultValue = m_sDefaultValue;
- }
- if(sTagElement.compare(DEFAULT,Qt::CaseInsensitive) == 0)
- {
-
- m_sDefaultValue = m_sCurrentText;
- }
- if( sTagElement.compare(DATA,Qt::CaseInsensitive) == 0)
- {
-
- DataInfo structDataInfo;
- structDataInfo.sDomainID = m_sCurrentDomainId;
- structDataInfo.sDomain = m_sCurrentDomain;
- structDataInfo.sKeyId = m_sCurrentKeyId;
- size_t iNumKeyElements = m_vecKeyInfo.size();
- for(unsigned int iIndex = 0; iIndex < iNumKeyElements; iIndex++)
- {
-
- if(m_vecKeyInfo[iIndex].sKeyId == m_sCurrentKeyId)
- break;
- if(iIndex+1 == iNumKeyElements)
- {
- QFile file("C:/GraphmlErrorLog.txt");
- if (!file.open(QIODevice::Append |QIODevice::Text))
- {
- qDebug() << "error:file could not be opened";
- }
- QTextStream out(&file);
- out << "The key " << m_sCurrentKeyId << "is not declared before\n";
- file.close();
- }
- }
- structDataInfo.sKeyValue = m_sCurrentText.remove("\r\n");
- KeyInfo objKeyInfo= m_mapKeyIdToKeyInfo.value(structDataInfo.sKeyId);
- QString sDomainName = structDataInfo.sDomain;
- QString sPropertyName = objKeyInfo.sKeyName;
- QString sKeyValue = structDataInfo.sKeyValue;
- QString sKeyDefaultValue = objKeyInfo.sDefaultValue;
- qDebug()<<"Default value : "<<structDataInfo.sKeyId<<" "<<sKeyDefaultValue;
-
- if(objKeyInfo.keyType == INTIGER_TYPE)
- {
- convertTextToInt(sKeyValue);
- }
- if(objKeyInfo.keyType == DOUBLE_TYPE)
- {
- convertTextToDouble(sKeyValue);
- }
- if(objKeyInfo.keyType == BOOLEAN_TYPE)
- {
- convertTextToBool(sKeyValue);
- }
- if(objKeyInfo.keyType == QSTRING_TYPE)
- {
- m_sCurrentKeyValue = sKeyValue;
- }
-
- if(sDomainName.compare(GRAPH,Qt::CaseInsensitive) == 0)
- {
- if(sPropertyName.compare(NODE_COORDINATE_X,Qt::CaseInsensitive) == 0)
- {
-
- structGraphProperty.iCoordX = m_iCurrentKeyValue;
-
- m_bIsGraphCoordXSet = true;
- }
- else if(sPropertyName.compare(NODE_COORDINATE_Y,Qt::CaseInsensitive) == 0)
- {
-
- structGraphProperty.iCoordY = m_iCurrentKeyValue;
-
- m_bIsGraphCoordYSet = true;
- }
- else if(sPropertyName.compare(NODE_HEIGHT,Qt::CaseInsensitive) == 0)
- {
-
- structGraphProperty.iHeight = m_iCurrentKeyValue;
-
- m_bIsGraphHeightSet = true;
- }
- else if(sPropertyName.compare(NODE_WIDTH,Qt::CaseInsensitive) == 0)
- {
-
- structGraphProperty.iWidth = m_iCurrentKeyValue;
-
- m_bIsGraphWidthSet = true;
- }
- else
- {
- throw LayoutException(__FUNCTION__,
- LayoutExceptionEnum::MANDATORY_FIELD_MISSING,
- "graph attributes",GRAPH);
- }
- }
- else if(sDomainName.compare(NODE,Qt::CaseInsensitive) == 0)
- {
- if(sPropertyName.compare(NODE_COORDINATE_X,Qt::CaseInsensitive) == 0)
- {
-
- structEntityProperty.iCoordX = m_iCurrentKeyValue;
-
- m_bIsNodeCoordXSet = true;
- }
- else if(sPropertyName.compare(NODE_COORDINATE_Y,Qt::CaseInsensitive) == 0)
- {
-
- structEntityProperty.iCoordY = m_iCurrentKeyValue;
-
- m_bIsNodeCoordYSet = true;
- }
- else if(sPropertyName.compare(NODE_HEIGHT,Qt::CaseInsensitive) == 0)
- {
-
- structEntityProperty.iHeight = m_iCurrentKeyValue;
-
- m_bIsNodeHeightSet = true;
- }
- else if(sPropertyName.compare(NODE_WIDTH,Qt::CaseInsensitive) == 0)
- {
-
- structEntityProperty.iWidth = m_iCurrentKeyValue;
-
- m_bIsNodeWidthSet = true;
- }
- else
- {
- throw LayoutException(__FUNCTION__,
- LayoutExceptionEnum::MANDATORY_FIELD_MISSING,
- "node attribues",NODE);
- }
- }
- else if(sDomainName.compare(EDGE,Qt::CaseInsensitive) == 0)
- {
- if(sPropertyName.compare(EDGE_BIDIRECTIONAL,Qt::CaseInsensitive) == 0)
- {
-
- structEntityProperty.bIsBidirectional = m_bCurrentKeyValue;
- }
- else if(sPropertyName.compare(EDGE_BENDPOINTS,Qt::CaseInsensitive) == 0)
- {
- }
- }
-
- m_bEdgeDataTag =false;
- }
- return true;
- }
- QString GraphMLReader::errorString() const
- {
-
- return m_sErrorText;
- }
- void GraphMLReader::addVertexToSubgraph( QString sVertexId )
- {
- LAYOUT_ASSERT((sVertexId != EMPTY_STRING_VALUE) || (mapVertexIdToVertexDescriptorObj.contains(sVertexId) != true),
- LayoutException(__FUNCTION__,
- LayoutExceptionEnum::INVALID_PARAMETER,
- EMPTY_ID_FOUND, VERTEX));
-
- VertexDescriptor *vdNode=new VertexDescriptor();
-
- BoostGraphWrapper graphWrapper;
- try
- {
-
- *vdNode = graphWrapper.addVertex(*gCurrentSubGraph);
- }
- catch(boost::exception& eBoostException)
- {
- DELETE_AND_SET_NULL(vdNode);
- throw *boost::get_error_info<errmsg_info>(eBoostException);
- }
- try
- {
-
- VertexDescriptor vdGlobalNode = gCurrentSubGraph->local_to_global(*vdNode);
- mapVertexIdToVertexDescriptorObj.insert(sVertexId,vdGlobalNode);
- }
- catch(LayoutMemoryException& eException)
- {
- DELETE_AND_SET_NULL(vdNode);
- QString sErrorMessage = eException.getErrorMessage();
- throw LayoutMemoryException(__FUNCTION__, LayoutExceptionEnum::NULL_POINTER_EXCEPTION, LOCAL_TO_GLOBAL + sErrorMessage);
- }
-
- (*gCurrentSubGraph)[*vdNode].sId = sVertexId;
-
- bool bIsDummyNode = false;
- (*gCurrentSubGraph)[*vdNode].bIsExpandable = bIsDummyNode;
-
- mapVertexDescriptorToIsDummyNode.insert(*vdNode,bIsDummyNode);
-
- if(m_bIsNodeCoordXSet && m_bIsNodeCoordYSet && m_bIsNodeHeightSet && m_bIsNodeWidthSet)
- {
-
- int iLeftCoordX = structEntityProperty.iCoordX;
- int iLeftCoordY = structEntityProperty.iCoordY;
- int iHeight = structEntityProperty.iHeight;
- int iWidth = structEntityProperty.iWidth;
-
- (*gCurrentSubGraph)[*vdNode].iLeftCoordX = iLeftCoordX;
- (*gCurrentSubGraph)[*vdNode].iLeftCoordY = iLeftCoordY;
- (*gCurrentSubGraph)[*vdNode].iHeight = iHeight;
- (*gCurrentSubGraph)[*vdNode].iWidth = iWidth;
-
- int iHalfWidthFactor = (iWidth / 2);
- int iHalfHeightFactor = (iHeight / 2);
- int iCenterCoordX = iLeftCoordX + iHalfWidthFactor;
- int iCenterCoordY = iLeftCoordY + iHalfHeightFactor;
-
- graphWrapper.setVertexCenterCoordX(*vdNode, *gCurrentSubGraph, iCenterCoordX);
- graphWrapper.setVertexCenterCoordY(*vdNode, *gCurrentSubGraph, iCenterCoordY);
- }
- else
- {
-
- throw LayoutException(__FUNCTION__, LayoutExceptionEnum::MANDATORY_FIELD_MISSING, sVertexId, NODE);
- }
- }
- void GraphMLReader::addEdgeToMainGraph(QString sSourceVertexId,QString sTargetVertexId,QString sEdgeId)
- {
- LAYOUT_ASSERT((sSourceVertexId != EMPTY_STRING_VALUE) || (sTargetVertexId != EMPTY_STRING_VALUE),
- LayoutException(__FUNCTION__,
- LayoutExceptionEnum::INVALID_PARAMETER,
- EMPTY_ID_FOUND, EDGE));
-
- EdgeDescriptor *edEdge = new EdgeDescriptor();
- bool bIsValidSourceId = mapVertexIdToVertexDescriptorObj.contains(sSourceVertexId);
- bool bIsValidTargetId = mapVertexIdToVertexDescriptorObj.contains(sTargetVertexId);
-
- if((bIsValidSourceId == true) && (bIsValidTargetId == true))
- {
-
- VertexDescriptor vdSource = mapVertexIdToVertexDescriptorObj.value(sSourceVertexId);
- VertexDescriptor vdTarget = mapVertexIdToVertexDescriptorObj.value(sTargetVertexId);
- try
- {
-
- *edEdge = (add_edge(vdSource,vdTarget,(*gMainGraph))).first;
- }
- catch(LayoutMemoryException& eException)
- {
- DELETE_AND_SET_NULL(edEdge);
- throw LayoutMemoryException(__FUNCTION__, LayoutExceptionEnum::NULL_POINTER_EXCEPTION, eException.getObjectName());
- }
- catch(boost::exception& eBoostException)
- {
- DELETE_AND_SET_NULL(edEdge);
- throw *boost::get_error_info<errmsg_info>(eBoostException);
- }
-
- (*gMainGraph)[*edEdge].sId = sEdgeId;
-
- (*gMainGraph)[*edEdge].bBidirectional = structEntityProperty.bIsBidirectional;
-
- (*gMainGraph)[*edEdge].vecBendPoints = m_dirtyEdge.m_vecBendPoints;
- #warning "GraphMLReader/GraphMLReader.cpp:1169:9: warning: Potential leak of memory pointed to by 'edEdge' (*gMainGraph)[*edEdge].vecBendPoints = m_dirtyEdge.m_vecBendPoints;"
-
- m_dirtyEdge.m_vecBendPoints.clear();
- }
- else
- {
-
- cout<<"Forward refrence problem while adding edge "
- <<sSourceVertexId.toStdString()<<" "<<sTargetVertexId.toStdString()<<endl;
- DELETE_AND_SET_NULL(edEdge);
- throw LayoutException(__FUNCTION__,
- LayoutExceptionEnum::INVALID_PARAMETER,
- FORWARD_REFERENCE,EDGE,
- sSourceVertexId,sTargetVertexId);
- }
- }
- GraphMLReader::~GraphMLReader()
- {
- DELETE_AND_SET_NULL(gCurrentSubGraph);
- }
|