GraphMLReader.cpp 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. #include "GraphMLReader.h"
  2. #include <iostream>
  3. #include <qstring.h>
  4. #include <QTime>
  5. #include <QDebug>
  6. #include <QMap>
  7. //create graph with subgraphs - global
  8. SubGraph* gMainGraph = NULL;
  9. SubGraph* gCurrentSubGraph = NULL;
  10. GraphMLReader::GraphMLReader()
  11. {
  12. //SubGraph gMainGraph;
  13. gMainGraph = new SubGraph();
  14. // this will maintain the cluster hirarchy in the subgraph structure
  15. gCurrentSubGraph = gMainGraph;
  16. // to track the start and end of the graphml tag.
  17. m_bGraphMLTag = false;
  18. // to track node occures after graph immediately
  19. m_bGraphTag = false;
  20. // to track bend inside data which inside edge tags.
  21. m_bEdgeTag = false;
  22. m_bEdgeDataTag = false;
  23. // to perform validation of data values for nodes, graphs and edges.
  24. // for graph
  25. m_bIsGraphCoordXSet = false;
  26. m_bIsGraphCoordYSet = false;
  27. m_bIsGraphHeightSet = false;
  28. m_bIsGraphWidthSet = false;
  29. // for nodes
  30. m_bIsNodeCoordXSet = false;
  31. m_bIsNodeCoordYSet = false;
  32. m_bIsNodeHeightSet = false;
  33. m_bIsNodeWidthSet = false;
  34. // for edge
  35. m_bIsEdgeDirectionSet = false;
  36. m_iNodeStartAt = 0;
  37. }
  38. //Function Definitions
  39. SubGraph& GraphMLReader::readGraphML(QFile *file)
  40. {
  41. GraphMLReader graphMLReader; // XXX valgrind says error this is not initialized
  42. //**** Timer Start
  43. QTime t;
  44. qDebug() << t.currentTime();
  45. t.start();
  46. //**** Counter Start
  47. m_iNodeStartAt = 0;
  48. m_iNodeEndAt = 0;
  49. m_iGraphStartAt = 0;
  50. m_iNode_GraphFoundCounter = 0;
  51. try
  52. {
  53. // validation of graphml file
  54. QString sFileName = file->fileName();
  55. //cout<<"Input File Validation : File Name "<<sFileName.toStdString()<<endl;
  56. //validateGraphML(sFileName); //Commented to test Bend points reading
  57. }
  58. catch(LayoutFileIOException& eException)
  59. {
  60. throw LayoutFileIOException(__FUNCTION__,
  61. LayoutExceptionEnum::LAYOUT_INVALID_FILE_FORMAT,
  62. eException.getFileName());
  63. }
  64. try
  65. {
  66. /*
  67. This calls default handler of SAX of Qt and takes the functionality of reading the
  68. graphML
  69. */
  70. QXmlInputSource xmlInputSource(file);
  71. QXmlSimpleReader xmlSimpleReader;
  72. xmlSimpleReader.setContentHandler(&graphMLReader);
  73. xmlSimpleReader.parse(xmlInputSource);
  74. }
  75. catch(LayoutFileIOException& e)
  76. {
  77. file->close();
  78. if(e.getExceptionSubType() == LayoutExceptionEnum::UNSUPPORTED_FILE_TYPE)
  79. {
  80. }
  81. QString sFileName = e.getFileName();
  82. QString sErrorMessage = e.getErrorMessage();
  83. cout<<"Exception : "<<sErrorMessage.toStdString()<<endl;
  84. throw LayoutFileIOException(__FUNCTION__,
  85. LayoutExceptionEnum::FILE_READ_OPERATION_ERROR,
  86. sFileName);
  87. }
  88. catch(LayoutMemoryException& eException)
  89. {
  90. file->close();
  91. QString sErrorMessage = eException.getErrorMessage();
  92. QString sObjectName = eException.getObjectName();
  93. cout<<"Exception : "<<sErrorMessage.toStdString()<<" "<<sObjectName.toStdString()<<endl;
  94. throw LayoutMemoryException(__FUNCTION__, LayoutExceptionEnum::NULL_POINTER_EXCEPTION, sObjectName);
  95. }
  96. catch(LayoutException& eException)
  97. {
  98. file->close();
  99. QString sErrorMessage = eException.getErrorMessage();
  100. int iErrorCode = eException.getErrorCode();
  101. QString sEntityValue = eException.getEntityValue();
  102. QString sEntityType = eException.getEntityType();
  103. cout<<"Exception : "<<sErrorMessage.toStdString()<<" "<<iErrorCode<<" "<<sEntityType.toStdString()<<" "<<sEntityValue.toStdString()<<endl;
  104. throw LayoutException(__FUNCTION__, LayoutExceptionEnum::INVALID_PARAMETER,sEntityValue,sEntityType);
  105. }
  106. catch(boost::exception& eBoostException)
  107. {
  108. file->close();
  109. throw *boost::get_error_info<errmsg_info>(eBoostException);
  110. }
  111. catch(...)
  112. {
  113. file->close();
  114. throw;
  115. }
  116. qDebug() << "Duration : " << t.elapsed();
  117. int iTime=t.elapsed();
  118. qDebug()<<"\nTime : "<<iTime;
  119. // cleaning for maingraph will be done by the layout manager.
  120. return *gMainGraph;
  121. }
  122. bool GraphMLReader::isSupportedGraphmlFile(QString sGraphMLFileName)
  123. {
  124. bool bIsSupportedFormat = false;
  125. if(sGraphMLFileName.trimmed().isEmpty() == false)
  126. {
  127. if(sGraphMLFileName.trimmed().endsWith(GRAPHML,Qt::CaseInsensitive) == true)
  128. {
  129. bIsSupportedFormat = true;
  130. }
  131. }
  132. else
  133. {
  134. bIsSupportedFormat = false;
  135. }
  136. return bIsSupportedFormat;
  137. }
  138. void GraphMLReader::validateGraphML(QString sGraphMLInstanceFileName)
  139. {
  140. LAYOUT_ASSERT((sGraphMLInstanceFileName.trimmed().isEmpty() != true),
  141. LayoutFileIOException(__FUNCTION__,
  142. LayoutExceptionEnum::INVALID_FILE_NAME,
  143. sGraphMLInstanceFileName));
  144. // LAYOUT_ASSERT(isSupportedGraphmlFile(sGraphMLInstanceFileName) != true,
  145. // FileIOException(__FUNCTION__,
  146. // ExceptionEnum::INVALID_FILE_NAME,
  147. // sGraphMLInstanceFileName));
  148. QString sSchemaFileName = SCHEMA_FILE_PATH;
  149. if (sSchemaFileName.isEmpty())
  150. {
  151. throw LayoutFileIOException(__FUNCTION__,
  152. LayoutExceptionEnum::FILE_NOT_FOUND,
  153. sSchemaFileName);
  154. return;
  155. }
  156. qDebug() << "Selected schema = " << sSchemaFileName;
  157. qDebug() << "Selected instance = " << sGraphMLInstanceFileName;
  158. QFile qSchemaFile(sSchemaFileName);
  159. if (!qSchemaFile.open(QIODevice::ReadOnly | QIODevice::Text))
  160. {
  161. throw LayoutFileIOException(__FUNCTION__,
  162. LayoutExceptionEnum::FILE_READ_OPERATION_ERROR,
  163. sSchemaFileName,qSchemaFile.errorString());
  164. return;
  165. }
  166. QFile qInstanceFile(sGraphMLInstanceFileName);
  167. if (!qInstanceFile.open(QIODevice::ReadOnly | QIODevice::Text))
  168. {
  169. throw LayoutFileIOException(__FUNCTION__,
  170. LayoutExceptionEnum::FILE_READ_OPERATION_ERROR,
  171. sGraphMLInstanceFileName,qInstanceFile.errorString());
  172. return;
  173. }
  174. // reads the schema file into bytearray variable
  175. const QByteArray schemaData = qSchemaFile.readAll();
  176. // reads the graphml file into bytearray variable
  177. const QByteArray instanceData = qInstanceFile.readAll();
  178. // declare the messagehandler for getting the wrong instance of graphml file.
  179. MessageHandler messageHandler;
  180. // declare the xml schema object.
  181. QXmlSchema schema;
  182. schema.setMessageHandler(&messageHandler);
  183. bool bErrorOccurred = false;
  184. qDebug() << "Loading Schema";
  185. if (schema.load(schemaData) == true)
  186. {
  187. qDebug() << "Validating Schema";
  188. if (schema.isValid())
  189. {
  190. QXmlSchemaValidator validator(schema);
  191. qDebug() << "Validating Instance";
  192. if (!validator.validate(instanceData))
  193. {
  194. // set the flag of whether error present or not.
  195. bErrorOccurred = true;
  196. }
  197. }
  198. }
  199. else
  200. {
  201. bErrorOccurred = true;
  202. }
  203. if (bErrorOccurred)
  204. {
  205. qDebug() << "Validation Un - Successful";
  206. qDebug() << messageHandler.getStatusMessage()
  207. <<" "<<messageHandler.getLineNumber()
  208. <<" "<<messageHandler.getColumnNumber();
  209. std::cout<< messageHandler.getStatusMessage().toStdString()<<" "<<messageHandler.getLineNumber()<<" "<<messageHandler.getColumnNumber()<<endl;
  210. throw LayoutFileIOException(__FUNCTION__,
  211. LayoutExceptionEnum::LAYOUT_INVALID_FILE_FORMAT,
  212. sGraphMLInstanceFileName,messageHandler.getStatusMessage());
  213. }
  214. else
  215. {
  216. qDebug() << "Validation Successful";
  217. }
  218. // Close the files once task is done.
  219. qSchemaFile.close();
  220. qInstanceFile.close();
  221. }
  222. /*Handler functionality*/
  223. bool GraphMLReader::startElement( const QString &namespaceURI, const QString &sTagElement, const QString &qName,
  224. const QXmlAttributes &lstAttributes)
  225. {
  226. Q_UNUSED(namespaceURI);
  227. Q_UNUSED(qName);
  228. // Clock counter to keep ordering between the tag elements
  229. ++m_iNode_GraphFoundCounter;
  230. if (!m_bGraphMLTag && sTagElement != GRAPHML)
  231. {
  232. // if graphml file do not contain the graphml tag then set the error.
  233. m_sErrorText = NOT_GRAPHML_FILE;
  234. return false;
  235. }
  236. if(sTagElement == XML_EXTN)
  237. {
  238. // Graphml file's first tag is xml and check its version and encoding.
  239. QString sVersion = lstAttributes.value(VERSION);
  240. QString sEncoding = lstAttributes.value(ENCODING);
  241. // check graphml version and encoding suported by reader
  242. if ((!sVersion.isEmpty() || sVersion != VERSION_VALUE))
  243. {
  244. // set the the error value if version is wrong.
  245. m_sErrorText = INVALID_VERSION;
  246. throw LayoutFileIOException(__FUNCTION__,
  247. LayoutExceptionEnum::UNSUPPORTED_FILE_FORMAT,
  248. VERSION);
  249. }
  250. else if(!sEncoding.isEmpty() || sEncoding != ENCODING_VALUE)
  251. {
  252. // set the error value if encoding id wrong.
  253. m_sErrorText = INVALID_ENCODING;
  254. throw LayoutFileIOException(__FUNCTION__,
  255. LayoutExceptionEnum::UNSUPPORTED_FILE_FORMAT,
  256. VERSION);
  257. }
  258. }
  259. if (sTagElement == GRAPHML)
  260. {
  261. QString sVersion = lstAttributes.value(VERSION);
  262. if (!sVersion.isEmpty() && sVersion != VERSION_VALUE)
  263. {
  264. m_sErrorText = INVALID_VERSION;
  265. return false;
  266. }
  267. m_bGraphMLTag = true;
  268. }
  269. else if(sTagElement.compare(GRAPH,Qt::CaseInsensitive) == 0)
  270. {
  271. /*
  272. if the tag element is <graph>
  273. */
  274. // clear the current characters value.
  275. m_sCurrentText.clear();
  276. // set the value of graph start to global counter.
  277. m_iGraphStartAt = m_iNode_GraphFoundCounter;
  278. // this flag is for having bounding between node occures after graph immediately.
  279. m_bGraphTag = true;
  280. // to get the id from <graph tag> which is attribute of graph
  281. QString strId;
  282. int iAttrCount=lstAttributes.count();
  283. for( int iIndex=0; iIndex<iAttrCount; iIndex++ )
  284. {
  285. if( lstAttributes.localName( iIndex ) == GRAPH_ID )
  286. {
  287. strId = lstAttributes.value( iIndex );
  288. }
  289. }
  290. // set the graph id to current domain id in the structure
  291. m_sCurrentDomainId = strId;
  292. m_sCurrentDomain = GRAPH;
  293. // Checking if <graph> tag is found just after <node> tag
  294. if(m_iGraphStartAt - m_iNodeStartAt==1)
  295. {
  296. // Add SubGraph and Reset dirtyNode;
  297. SubGraph& gNewChildSubgraph= gCurrentSubGraph->create_subgraph();
  298. gCurrentSubGraph = &gNewChildSubgraph;
  299. // for childgraphs : Storing properties
  300. boost::ref_property_map<SubGraph*, GraphProperties>
  301. mapGraphReferenceToId(boost::get_property(*gCurrentSubGraph,graph_custom_prop));
  302. mapGraphReferenceToId[gCurrentSubGraph].sId = strId;
  303. m_dirtyNode.m_bIsDirtyNode = false;
  304. }
  305. else
  306. {
  307. // for maingraph :- Storing properties
  308. boost::ref_property_map<SubGraph*, GraphProperties>
  309. mapGraphReferenceToProperty(boost::get_property(*gCurrentSubGraph,graph_custom_prop));
  310. mapGraphReferenceToProperty[gCurrentSubGraph].sId = strId;
  311. }
  312. }
  313. if(sTagElement.compare(NODE,Qt::CaseInsensitive) == 0)
  314. {
  315. /*
  316. if the tag element is the <node> tag.
  317. */
  318. /**
  319. As node tag follows immediately to graph tag always so after reading graph tag we need to store the
  320. graph properties in the specific graph. hence store the graph properties at the start of the node tag.
  321. Actully these properties need to be stored at the start of the edge tag also but there cannot be an edge
  322. without the node hence we have decided to store these properties at the start of ned tag only.
  323. */
  324. /* set graph properties start */
  325. if(m_bGraphTag == true)
  326. {
  327. /**
  328. Actually Writer graphml file contains the x and y coordinates which are already leftX and topY
  329. coordinates of compartment.
  330. Hence while reading we have to treat those coordinates as leftX and topY coordinates.
  331. */
  332. /*
  333. Check for all madatory fields for the graph are present or not like
  334. coordinate X, coordinate Y, Height and Width.
  335. */
  336. if(m_bIsGraphCoordXSet && m_bIsGraphCoordYSet && m_bIsGraphHeightSet && m_bIsGraphWidthSet)
  337. {
  338. BoostGraphWrapper boostGraphWrapper;
  339. // retrieve properties from graph property strcuture.
  340. // Here we take X and Y as leftX and leftY.
  341. int iGraphLeftTopCoordX = structGraphProperty.iCoordX;
  342. int iGraphLeftTopCoordY = structGraphProperty.iCoordY;
  343. int iGraphHeight = structGraphProperty.iHeight;
  344. int iGraphWidth = structGraphProperty.iWidth;
  345. // center X and Y coordinates calculations
  346. int iGraphCenterCoordX = (iGraphLeftTopCoordX + (iGraphWidth/2));
  347. int iGraphCenterCoordy = (iGraphLeftTopCoordY + (iGraphHeight/2));
  348. QString sGraphId = boostGraphWrapper.getGraphId(*gCurrentSubGraph);
  349. // //cout<<"Setting The Graph Properties : "<<sGraphId.toStdString()<<" "<<iGraphLeftTopCoordX<<" "<<iGraphLeftTopCoordY
  350. // <<" "<<iGraphHeight<<" "<<iGraphWidth<<endl;
  351. // set graph properties to boost graph
  352. boostGraphWrapper.setGraphCenterCoordX(iGraphCenterCoordX, *gCurrentSubGraph);
  353. boostGraphWrapper.setGraphCenterCoordY(iGraphCenterCoordy, *gCurrentSubGraph);
  354. boostGraphWrapper.setGraphHeight(iGraphHeight, *gCurrentSubGraph);
  355. boostGraphWrapper.setGraphWidth(iGraphWidth, *gCurrentSubGraph);
  356. // set left and top properties to boost graph
  357. boostGraphWrapper.setGraphLeftTopCoordX(iGraphLeftTopCoordX, *gCurrentSubGraph);
  358. boostGraphWrapper.setGraphLeftTopCoordY(iGraphLeftTopCoordY, *gCurrentSubGraph);
  359. // set the imediate graph tag before this node tag as false.
  360. m_bGraphTag = false;
  361. // reset the flag for data values for this graph
  362. m_bIsGraphCoordXSet = false;
  363. m_bIsGraphCoordYSet = false;
  364. m_bIsGraphHeightSet = false;
  365. m_bIsGraphWidthSet = false;
  366. }
  367. else
  368. {
  369. /**
  370. This case indicates that one or more values of mandatory fields is absent for the graph entity.
  371. */
  372. throw LayoutException(__FUNCTION__, LayoutExceptionEnum::MANDATORY_FIELD_MISSING, GRAPH);
  373. }
  374. }
  375. /* set graph properties End */
  376. m_sCurrentText.clear();
  377. // set the global counter value to node counter.
  378. m_iNodeStartAt = m_iNode_GraphFoundCounter;
  379. m_dirtyNode.m_bIsDirtyNode = true;
  380. // process for the getting and setting the node id.
  381. QString sNodeId;
  382. int iAttrCount = lstAttributes.count();
  383. for( int iIndex=0; iIndex<iAttrCount; iIndex++ )
  384. {
  385. if( lstAttributes.localName( iIndex ) == NODE_ID )
  386. {
  387. sNodeId = lstAttributes.value( iIndex );
  388. // To store attributes which can be used in endElement(), set those into DirtyNode class.
  389. qDebug()<<"Set Node Ids:"<<sNodeId;
  390. try
  391. {
  392. // This will call the setter for the NODE class and set its properties.
  393. m_dirtyNode.setID(sNodeId);
  394. }
  395. catch(LayoutException& eException)
  396. {
  397. //cout<<"Exception : Empty id to the node found"<<endl;
  398. throw LayoutException(__FUNCTION__, LayoutExceptionEnum::INVALID_PARAMETER,
  399. eException.getEntityValue(), eException.getEntityType());
  400. }
  401. }
  402. }
  403. // set the value of node's id to current domain id.
  404. m_sCurrentDomainId = sNodeId;
  405. m_sCurrentDomain = NODE;
  406. }
  407. if(sTagElement.compare(EDGE,Qt::CaseInsensitive) == 0)
  408. {
  409. m_sCurrentText.clear();
  410. m_dirtyEdge.m_bIsDirtyEdge = true;
  411. // getting and setting the edge ids
  412. QString sEdgeId,sSourceVertexId,sTargetVertexId;
  413. int iAttrCount=lstAttributes.count();
  414. for( int iIndex=0; iIndex<iAttrCount; iIndex++ )
  415. {
  416. if( lstAttributes.localName( iIndex ) == SOURCE_OF_EDGE)
  417. {
  418. sSourceVertexId = lstAttributes.value( iIndex );
  419. }
  420. if(lstAttributes.localName(iIndex)==TARGET_OF_EDGE)
  421. {
  422. sTargetVertexId = lstAttributes.value( iIndex );
  423. }
  424. if(lstAttributes.localName(iIndex) == EDGE_ID)
  425. {
  426. sEdgeId = lstAttributes.value( iIndex );
  427. try
  428. {
  429. m_dirtyEdge.setId(sEdgeId);
  430. }
  431. catch(...)
  432. {
  433. /* We don't have any processing related issue if any
  434. * exception is geeting thrown here.
  435. * Hence we are ignoring this exception.
  436. */
  437. }
  438. }
  439. }
  440. // set the value of edge id to the current domain id.
  441. m_sCurrentDomainId = sEdgeId;
  442. m_sCurrentDomain = EDGE;
  443. // To store attributes which can be used in endElement(), set those into DirtyEdge class.
  444. try
  445. {
  446. m_dirtyEdge.setSourceTarget(sSourceVertexId,sTargetVertexId);
  447. }
  448. catch(LayoutException& eException)
  449. {
  450. LayoutException(__FUNCTION__,
  451. LayoutExceptionEnum::INVALID_PARAMETER,
  452. eException.getEntityValue(),
  453. eException.getEntityType());
  454. }
  455. catch(...)
  456. {}
  457. // set the flag for edge true so that we can map it in the data tag.
  458. m_bEdgeTag = true;
  459. }
  460. if(sTagElement.compare(KEY,Qt::CaseInsensitive) == 0)
  461. {
  462. // set the information retrieved from the key tag
  463. structKeyInfo.sKeyId = lstAttributes.value(KEY_ID);
  464. structKeyInfo.sKeyName = lstAttributes.value(ATTR_NAME);
  465. structKeyInfo.keyType = QSTRING_TYPE;
  466. structKeyInfo.sDomain = lstAttributes.value(FOR);
  467. // set the type of the data need to be read.
  468. if(lstAttributes.value(ATTR_TYPE) == BOOL_TYPE_STRING)
  469. {
  470. structKeyInfo.keyType = BOOLEAN_TYPE;
  471. }
  472. else if(lstAttributes.value(ATTR_TYPE) == DOUBL_TYPE_STRING)
  473. {
  474. structKeyInfo.keyType = DOUBLE_TYPE;
  475. }
  476. else if(lstAttributes.value(ATTR_TYPE) == INT_TYPE_STRING)
  477. {
  478. structKeyInfo.keyType = INTIGER_TYPE;
  479. }
  480. //Add entries to map
  481. QString sKeyId = structKeyInfo.sKeyId;
  482. m_mapKeyIdToKeyInfo.insert(sKeyId,structKeyInfo);
  483. m_vecKeyInfo.push_back(structKeyInfo);
  484. }
  485. if(sTagElement.compare(DEFAULT,Qt::CaseInsensitive) == 0)
  486. {
  487. // default values need to be considered.
  488. }
  489. if(sTagElement.compare(DATA,Qt::CaseInsensitive) == 0)
  490. {
  491. // check for the data tag and get the information for which key this data belong to.
  492. QString sKey;
  493. int iAttrCount=lstAttributes.count();
  494. for( int iIndex=0; iIndex<iAttrCount; iIndex++ )
  495. {
  496. if( lstAttributes.localName( iIndex ) == KEY )
  497. {
  498. // get attribute of data tag.
  499. sKey = lstAttributes.value( iIndex );
  500. }
  501. }
  502. // set the current key id.
  503. m_sCurrentKeyId = sKey;
  504. // set the data flag true checking only if edge tag is true.
  505. if(m_bEdgeTag == true)
  506. {
  507. m_bEdgeDataTag = true;
  508. }
  509. }
  510. if(sTagElement.compare(BEND,Qt::CaseInsensitive) == 0)
  511. {
  512. // this tag is set when data for this edge is encontered.
  513. if(m_bEdgeDataTag == true)
  514. {
  515. QString sValueX, sValueY;
  516. int iIndex = 0;
  517. // get the first attribute value.
  518. if( lstAttributes.localName( iIndex ) == XVALUE)
  519. {
  520. sValueX = lstAttributes.value( iIndex );
  521. }
  522. // get the second attribute value.
  523. if(lstAttributes.localName(iIndex + 1)== YVALUE)
  524. {
  525. sValueY = lstAttributes.value( iIndex + 1 );
  526. }
  527. // store the values into dirty edge one by one for this edge.
  528. // //cout<<"Inside Bendss : "<<m_sCurrentDomainId.toStdString()<<" "
  529. // <<sValueX.toStdString()<<" "
  530. // <<sValueY.toStdString()<<" "<<endl;
  531. int iValueX = sValueX.toInt();
  532. int iValueY = sValueY.toInt();
  533. // //cout<<"Values for bends : "<<iValueX<<" "<<iValueY<<endl;
  534. m_dirtyEdge.setEdgeBendPointsCoordinates(iValueX, iValueY);
  535. }
  536. }
  537. return true;
  538. }
  539. bool GraphMLReader::characters(const QString &sCurrentString)
  540. {
  541. // This function is default handler's function.
  542. // This function is used to retrieve the character text value betweent the tags.
  543. m_sCurrentText = sCurrentString;
  544. return true;
  545. }
  546. void GraphMLReader::convertTextToInt(QString sKeyValue)
  547. {
  548. /**
  549. as we are retriving the values in the form of string only from the graphml file,
  550. hence we need to process it to convert it into the respective type.
  551. This function converts the string value into the integer value.
  552. */
  553. int iKeyValue = sKeyValue.toInt();
  554. m_iCurrentKeyValue = iKeyValue;
  555. }
  556. void GraphMLReader::convertTextToBool(QString sKeyValue)
  557. {
  558. /**
  559. as we are retriving the values in the form of string only from the graphml file,
  560. hence we need to process it to convert it into the respective type.
  561. This function converts the string value into the boolean value.
  562. */
  563. if(sKeyValue.compare(TRUE_VALUE,Qt::CaseInsensitive) == 0)
  564. {
  565. m_bCurrentKeyValue = true;
  566. }
  567. if(sKeyValue.compare(FALSE_VALUE,Qt::CaseInsensitive) == 0)
  568. {
  569. m_bCurrentKeyValue = false;
  570. }
  571. }
  572. void GraphMLReader::convertTextToDouble(QString sKeyValue)
  573. {
  574. /**
  575. as we are retriving the values in the form of string only from the graphml file,
  576. hence we need to process it to convert it into the respective type.
  577. This function converts the string value into the double value.
  578. */
  579. double dKeyValue = sKeyValue.toDouble();
  580. m_dCurrentKeyValue = dKeyValue;
  581. }
  582. bool GraphMLReader::endElement( const QString &namespaceURI, const QString &sTagElement, const QString &qName )
  583. {
  584. Q_UNUSED(namespaceURI);
  585. Q_UNUSED(qName);
  586. // increment the global counter
  587. ++m_iNode_GraphFoundCounter;
  588. if(sTagElement.compare(GRAPHML, Qt::CaseInsensitive) == 0)
  589. {
  590. // declare the end of graphml tag.
  591. m_bGraphMLTag = false;
  592. }
  593. if(sTagElement.compare(GRAPH,Qt::CaseInsensitive) == 0)
  594. {
  595. // set the global counter value to the graph end counter value.
  596. m_iGraphEndAt = m_iNode_GraphFoundCounter;
  597. // add the properties of graph if node is not present in the graph
  598. if(m_bGraphTag == true)
  599. {
  600. /*
  601. Check for all madatory fields for the graph are present or not like
  602. coordinate X, coordinate Y, Height and Width.
  603. */
  604. if(m_bIsGraphCoordXSet && m_bIsGraphCoordYSet && m_bIsGraphHeightSet && m_bIsGraphWidthSet)
  605. {
  606. // store all propertes to graph
  607. BoostGraphWrapper boostGraphWrapper;
  608. // retrieve properties from graph property strcuture.
  609. // Here we take X and Y as leftX and leftY.
  610. int iGraphLeftTopCoordX = structGraphProperty.iCoordX;
  611. int iGraphLeftTopCoordY = structGraphProperty.iCoordY;
  612. int iGraphHeight = structGraphProperty.iHeight;
  613. int iGraphWidth = structGraphProperty.iWidth;
  614. // center X and Y coordinates calculations
  615. int iGraphCenterCoordX = (iGraphLeftTopCoordX + (iGraphWidth/2));
  616. int iGraphCenterCoordy = (iGraphLeftTopCoordY + (iGraphHeight/2));
  617. // QString sGraphId = boostGraphWrapper.getGraphId(*gCurrentSubGraph);
  618. // //cout<<"Setting The Graph Properties : "<<sGraphId.toStdString()<<" "<<iGraphLeftTopCoordX<<" "<<iGraphLeftTopCoordY
  619. // <<" "<<iGraphHeight<<" "<<iGraphWidth<<endl;
  620. // set graph properties to boost graph
  621. boostGraphWrapper.setGraphCenterCoordX(iGraphCenterCoordX, *gCurrentSubGraph);
  622. boostGraphWrapper.setGraphCenterCoordY(iGraphCenterCoordy, *gCurrentSubGraph);
  623. boostGraphWrapper.setGraphHeight(iGraphHeight, *gCurrentSubGraph);
  624. boostGraphWrapper.setGraphWidth(iGraphWidth, *gCurrentSubGraph);
  625. // set left and top properties to boost graph
  626. boostGraphWrapper.setGraphLeftTopCoordX(iGraphLeftTopCoordX, *gCurrentSubGraph);
  627. boostGraphWrapper.setGraphLeftTopCoordY(iGraphLeftTopCoordY, *gCurrentSubGraph);
  628. m_bGraphTag = false;
  629. // reset the data vales present values's flag for graph
  630. m_bIsGraphCoordXSet = false;
  631. m_bIsGraphCoordYSet = false;
  632. m_bIsGraphHeightSet = false;
  633. m_bIsGraphWidthSet = false;
  634. }
  635. else
  636. {
  637. /**
  638. This case indicates that one or more values of mandatory fields is absent for the graph entity.
  639. */
  640. throw LayoutException(__FUNCTION__, LayoutExceptionEnum::MANDATORY_FIELD_MISSING, GRAPH);
  641. }
  642. }
  643. // At the end of <graph> maintain the state of parent graph.
  644. SubGraph& gCurrentParentGraph = gCurrentSubGraph->parent();
  645. gCurrentSubGraph = &gCurrentParentGraph;
  646. }
  647. if(sTagElement.compare(NODE,Qt::CaseInsensitive) == 0)
  648. {
  649. // set the global counter value to node end counter.
  650. m_iNodeEndAt = m_iNode_GraphFoundCounter;
  651. QString strId;
  652. try
  653. {
  654. // fetch the attribute from DirtyNode.
  655. strId = m_dirtyNode.getID();
  656. }
  657. catch(LayoutException& eException)
  658. {
  659. throw LayoutException(__FUNCTION__, LayoutExceptionEnum::INVALID_ATTRIBUTE_VALUE, EMPTY_ID_FOUND, NODE);
  660. }
  661. if( (m_iNodeEndAt < m_iNodeStartAt) && (m_iNodeStartAt < m_iGraphStartAt ) )
  662. {
  663. // Ignore Dummy node end
  664. m_dirtyNode.m_bIsDirtyNode = false;
  665. }
  666. /* Condition :- (NodeStartAt < NodeEndAt) AND NOT(NodeStartAt < GraphStartAt < NodeEndAt)
  667. Means <node>
  668. <data/>
  669. ....
  670. </node>
  671. AND No <graph> tag present in between NodeStart and NodeEnd.
  672. I splitted above NOT(...) condition in c++ compiler readable way as:-
  673. (a<b<c) means ( (a<b) && (b<c) ).
  674. */
  675. else if( ( m_iNodeStartAt < m_iNodeEndAt )
  676. && !( ( m_iNodeStartAt < m_iGraphStartAt ) && ( m_iGraphStartAt < m_iNodeEndAt ) ) )
  677. {
  678. // Add vertex to graph;
  679. if( m_dirtyNode.m_bIsDirtyNode == true )
  680. {
  681. try
  682. {
  683. addVertexToSubgraph(strId);
  684. m_dirtyNode.m_bIsDirtyNode = false;
  685. }
  686. catch(LayoutException & eException)
  687. {
  688. QString sErrorMessage = eException.getErrorMessage();
  689. throw LayoutException(__FUNCTION__, LayoutExceptionEnum::INVALID_PARAMETER, EMPTY_ID_FOUND, sErrorMessage);
  690. }
  691. // obselete XXX
  692. // catch(LayoutMemoryException& eException)
  693. // {
  694. // QString sErrorMessage = eException.getErrorMessage();
  695. // //cout<<"Exception : Local_toClobal Null pointer excepton found"<<sErrorMessage.toStdString()<<endl;
  696. // throw LayoutMemoryException(__FUNCTION__, LayoutExceptionEnum::NULL_POINTER_EXCEPTION, sErrorMessage);
  697. // }
  698. catch(boost::exception& eBoostException)
  699. {
  700. throw *boost::get_error_info<errmsg_info>(eBoostException);
  701. }
  702. catch(...)
  703. {
  704. throw;
  705. }
  706. }
  707. }
  708. }
  709. if( sTagElement.compare(EDGE,Qt::CaseInsensitive) == 0 )
  710. {
  711. QString sSourceId , sTargetId , sEdgeId;
  712. // get the sourceId, targetId and EdgeId for the current edge.
  713. sSourceId = m_dirtyEdge.getSource();
  714. sTargetId = m_dirtyEdge.getTarget();
  715. sEdgeId = m_dirtyEdge.getId();
  716. // add edge to the graph
  717. if( m_dirtyEdge.m_bIsDirtyEdge == true )
  718. {
  719. try
  720. {
  721. addEdgeToMainGraph(sSourceId,sTargetId,sEdgeId);
  722. m_dirtyEdge.m_bIsDirtyEdge = false;
  723. // make it flase as edge end element occured
  724. m_bEdgeTag = false;
  725. // //cout<<"End Of Edge"<<endl;
  726. }
  727. catch(LayoutException& eException)
  728. {
  729. if(eException.getExceptionSubType() == LayoutExceptionEnum::INVALID_PARAMETER)
  730. {
  731. throw LayoutException(__FUNCTION__,
  732. LayoutExceptionEnum::INVALID_PARAMETER,
  733. eException.getEntityValue(),
  734. eException.getEntityType());
  735. }
  736. }
  737. // obselete XXX
  738. // catch(LayoutMemoryException& eException)
  739. /// {
  740. // throw LayoutMemoryException(__FUNCTION__,
  741. // LayoutExceptionEnum::NULL_POINTER_EXCEPTION,
  742. // eException.getObjectName());
  743. // }
  744. }
  745. }
  746. if(sTagElement.compare(KEY,Qt::CaseInsensitive) == 0)
  747. {
  748. // Get default value for current key
  749. structKeyInfo.sDefaultValue = m_sDefaultValue;
  750. }
  751. if(sTagElement.compare(DEFAULT,Qt::CaseInsensitive) == 0)
  752. {
  753. // Set default value
  754. // //cout<<"Default Value ~~~~~~~~~~~~~~~~~~~~~~"<<m_sCurrentText<<" "<<m_sCurrentKeyId<<endl;
  755. m_sDefaultValue = m_sCurrentText;
  756. }
  757. if( sTagElement.compare(DATA,Qt::CaseInsensitive) == 0)
  758. {
  759. // get the current data values in the structure.
  760. DataInfo structDataInfo;
  761. structDataInfo.sDomainID = m_sCurrentDomainId;
  762. structDataInfo.sDomain = m_sCurrentDomain;
  763. structDataInfo.sKeyId = m_sCurrentKeyId;
  764. size_t iNumKeyElements = m_vecKeyInfo.size();
  765. for(unsigned int iIndex = 0; iIndex < iNumKeyElements; iIndex++)
  766. {
  767. // TODO:: Use keys map instead of this vector.
  768. if(m_vecKeyInfo[iIndex].sKeyId == m_sCurrentKeyId)
  769. break;
  770. if(iIndex+1 == iNumKeyElements)
  771. {
  772. QFile file("C:/GraphmlErrorLog.txt");
  773. if (!file.open(QIODevice::Append |QIODevice::Text))
  774. {
  775. qDebug() << "error:file could not be opened";
  776. }
  777. QTextStream out(&file);
  778. out << "The key " << m_sCurrentKeyId << "is not declared before\n";
  779. file.close();
  780. }
  781. }
  782. structDataInfo.sKeyValue = m_sCurrentText.remove("\r\n");
  783. KeyInfo objKeyInfo= m_mapKeyIdToKeyInfo.value(structDataInfo.sKeyId);
  784. QString sDomainName = structDataInfo.sDomain;
  785. QString sPropertyName = objKeyInfo.sKeyName;
  786. QString sKeyValue = structDataInfo.sKeyValue;
  787. QString sKeyDefaultValue = objKeyInfo.sDefaultValue;
  788. qDebug()<<"Default value : "<<structDataInfo.sKeyId<<" "<<sKeyDefaultValue;
  789. /* Convert (Text Value) to attr.type(Specific type)*/
  790. if(objKeyInfo.keyType == INTIGER_TYPE)
  791. {
  792. convertTextToInt(sKeyValue);
  793. }
  794. if(objKeyInfo.keyType == DOUBLE_TYPE)
  795. {
  796. convertTextToDouble(sKeyValue);
  797. }
  798. if(objKeyInfo.keyType == BOOLEAN_TYPE)
  799. {
  800. convertTextToBool(sKeyValue);
  801. }
  802. if(objKeyInfo.keyType == QSTRING_TYPE)
  803. {
  804. m_sCurrentKeyValue = sKeyValue;
  805. }
  806. /****************************************************/
  807. if(sDomainName.compare(GRAPH,Qt::CaseInsensitive) == 0)
  808. {
  809. if(sPropertyName.compare(NODE_COORDINATE_X,Qt::CaseInsensitive) == 0)
  810. {
  811. // Store coord_x into GraphProperties
  812. structGraphProperty.iCoordX = m_iCurrentKeyValue;
  813. // set the value for the graph's x coordinate as preset value
  814. m_bIsGraphCoordXSet = true;
  815. }
  816. else if(sPropertyName.compare(NODE_COORDINATE_Y,Qt::CaseInsensitive) == 0)
  817. {
  818. // Store coord_y into GraphProperties
  819. structGraphProperty.iCoordY = m_iCurrentKeyValue;
  820. // set the value for the graph's y coordinate as preset value
  821. m_bIsGraphCoordYSet = true;
  822. }
  823. else if(sPropertyName.compare(NODE_HEIGHT,Qt::CaseInsensitive) == 0)
  824. {
  825. // Store height into GraphProperties
  826. // //cout<<"GraphProp Height : "<<structDataInfo.sDomainID.toStdString()<<" "<<m_iCurrentKeyValue<<endl;
  827. structGraphProperty.iHeight = m_iCurrentKeyValue;
  828. // set the value for the graph's height as preset value
  829. m_bIsGraphHeightSet = true;
  830. }
  831. else if(sPropertyName.compare(NODE_WIDTH,Qt::CaseInsensitive) == 0)
  832. {
  833. // Store width into GraphProperties
  834. // //cout<<"GraphProp Width : "<<m_iCurrentKeyValue<<endl;
  835. structGraphProperty.iWidth = m_iCurrentKeyValue;
  836. // set the value for the graph's width as preset value
  837. m_bIsGraphWidthSet = true;
  838. }
  839. else
  840. {
  841. throw LayoutException(__FUNCTION__,
  842. LayoutExceptionEnum::MANDATORY_FIELD_MISSING,
  843. "graph attributes",GRAPH);
  844. }
  845. }
  846. else if(sDomainName.compare(NODE,Qt::CaseInsensitive) == 0)
  847. {
  848. if(sPropertyName.compare(NODE_COORDINATE_X,Qt::CaseInsensitive) == 0)
  849. {
  850. // Store coord_x(int) into VertexProperty
  851. structEntityProperty.iCoordX = m_iCurrentKeyValue;
  852. // set the value for the node's x coordinate as preset value
  853. m_bIsNodeCoordXSet = true;
  854. }
  855. else if(sPropertyName.compare(NODE_COORDINATE_Y,Qt::CaseInsensitive) == 0)
  856. {
  857. // Store coord_y into VertexProperty
  858. structEntityProperty.iCoordY = m_iCurrentKeyValue;
  859. // set the value for the node's Y coordinate as preset value
  860. m_bIsNodeCoordYSet = true;
  861. }
  862. else if(sPropertyName.compare(NODE_HEIGHT,Qt::CaseInsensitive) == 0)
  863. {
  864. // Store height into VertexProperty
  865. structEntityProperty.iHeight = m_iCurrentKeyValue;
  866. // set the value for the height of node as preset value
  867. m_bIsNodeHeightSet = true;
  868. }
  869. else if(sPropertyName.compare(NODE_WIDTH,Qt::CaseInsensitive) == 0)
  870. {
  871. // Store width into VertexProperty
  872. structEntityProperty.iWidth = m_iCurrentKeyValue;
  873. // set the value for the width of node as preset value
  874. m_bIsNodeWidthSet = true;
  875. }
  876. else
  877. {
  878. throw LayoutException(__FUNCTION__,
  879. LayoutExceptionEnum::MANDATORY_FIELD_MISSING,
  880. "node attribues",NODE);
  881. }
  882. }
  883. else if(sDomainName.compare(EDGE,Qt::CaseInsensitive) == 0)
  884. {
  885. if(sPropertyName.compare(EDGE_BIDIRECTIONAL,Qt::CaseInsensitive) == 0)
  886. {
  887. // Store bidirectional(bool) into EdgeProperty
  888. // //cout<<"Edge Bidirectional : "<<m_bCurrentKeyValue<<" "<<sPropertyName.toStdString()<<" "<<m_iCurrentKeyValue<<endl;
  889. structEntityProperty.bIsBidirectional = m_bCurrentKeyValue;
  890. }
  891. else if(sPropertyName.compare(EDGE_BENDPOINTS,Qt::CaseInsensitive) == 0)
  892. {
  893. // //cout<<"Bend Points Key value : "
  894. // <<m_iCurrentKeyValue<<" "
  895. // << m_sCurrentDomain.toStdString()<<" "
  896. // <<m_sCurrentKeyId.toStdString()<<" "<<endl;
  897. }
  898. }
  899. // unset the data tag value for the edge(used for the bend points)
  900. m_bEdgeDataTag =false;
  901. }
  902. return true;
  903. }
  904. QString GraphMLReader::errorString() const
  905. {
  906. // set the error if present.
  907. return m_sErrorText;
  908. }
  909. void GraphMLReader::addVertexToSubgraph( QString sVertexId )
  910. {
  911. LAYOUT_ASSERT((sVertexId != EMPTY_STRING_VALUE) || (mapVertexIdToVertexDescriptorObj.contains(sVertexId) != true),
  912. LayoutException(__FUNCTION__,
  913. LayoutExceptionEnum::INVALID_PARAMETER,
  914. EMPTY_ID_FOUND, VERTEX));
  915. // create new vertex descriptor.
  916. VertexDescriptor *vdNode=new VertexDescriptor();
  917. //Using boost graph wrapper function for vertx ordering and own vertex list
  918. BoostGraphWrapper graphWrapper;
  919. try
  920. {
  921. // add this vertex to boost current graph.
  922. *vdNode = graphWrapper.addVertex(*gCurrentSubGraph);
  923. }
  924. catch(boost::exception& eBoostException)
  925. {
  926. DELETE_AND_SET_NULL(vdNode);
  927. throw *boost::get_error_info<errmsg_info>(eBoostException);
  928. }
  929. try
  930. {
  931. // get the global vertex descriptor of this vertex and map it with its id.
  932. VertexDescriptor vdGlobalNode = gCurrentSubGraph->local_to_global(*vdNode);
  933. mapVertexIdToVertexDescriptorObj.insert(sVertexId,vdGlobalNode);
  934. }
  935. catch(LayoutMemoryException& eException)
  936. {
  937. DELETE_AND_SET_NULL(vdNode);
  938. QString sErrorMessage = eException.getErrorMessage();
  939. throw LayoutMemoryException(__FUNCTION__, LayoutExceptionEnum::NULL_POINTER_EXCEPTION, LOCAL_TO_GLOBAL + sErrorMessage);
  940. }
  941. //Set node id into graph
  942. (*gCurrentSubGraph)[*vdNode].sId = sVertexId;
  943. // Set the node is not dummy node
  944. bool bIsDummyNode = false;
  945. (*gCurrentSubGraph)[*vdNode].bIsExpandable = bIsDummyNode;
  946. // keep map of the vertex descriptor to dummy node or not.
  947. mapVertexDescriptorToIsDummyNode.insert(*vdNode,bIsDummyNode);
  948. /**
  949. Check the data values for this nodes are set for all mandatory fields, for
  950. coordinate X, coorcinate Y, Height and Width.
  951. */
  952. if(m_bIsNodeCoordXSet && m_bIsNodeCoordYSet && m_bIsNodeHeightSet && m_bIsNodeWidthSet)
  953. {
  954. /*Adding Data Values to node*/
  955. int iLeftCoordX = structEntityProperty.iCoordX;
  956. int iLeftCoordY = structEntityProperty.iCoordY;
  957. int iHeight = structEntityProperty.iHeight;
  958. int iWidth = structEntityProperty.iWidth;
  959. // set the values to the vertex property of a graph.
  960. (*gCurrentSubGraph)[*vdNode].iLeftCoordX = iLeftCoordX;
  961. (*gCurrentSubGraph)[*vdNode].iLeftCoordY = iLeftCoordY;
  962. (*gCurrentSubGraph)[*vdNode].iHeight = iHeight;
  963. (*gCurrentSubGraph)[*vdNode].iWidth = iWidth;
  964. // calculate center coordinates of this node
  965. int iHalfWidthFactor = (iWidth / 2);
  966. int iHalfHeightFactor = (iHeight / 2);
  967. int iCenterCoordX = iLeftCoordX + iHalfWidthFactor;
  968. int iCenterCoordY = iLeftCoordY + iHalfHeightFactor;
  969. // set the center coordinates of this node.
  970. graphWrapper.setVertexCenterCoordX(*vdNode, *gCurrentSubGraph, iCenterCoordX);
  971. graphWrapper.setVertexCenterCoordY(*vdNode, *gCurrentSubGraph, iCenterCoordY);
  972. }
  973. else
  974. {
  975. /***
  976. * This case indiacets that one of the mandatory field for the node is absent in
  977. * the input geraphml file.
  978. */
  979. throw LayoutException(__FUNCTION__, LayoutExceptionEnum::MANDATORY_FIELD_MISSING, sVertexId, NODE);
  980. }
  981. }
  982. void GraphMLReader::addEdgeToMainGraph(QString sSourceVertexId,QString sTargetVertexId,QString sEdgeId)
  983. {
  984. LAYOUT_ASSERT((sSourceVertexId != EMPTY_STRING_VALUE) || (sTargetVertexId != EMPTY_STRING_VALUE),
  985. LayoutException(__FUNCTION__,
  986. LayoutExceptionEnum::INVALID_PARAMETER,
  987. EMPTY_ID_FOUND, EDGE));
  988. // create new edge for this edge id.
  989. EdgeDescriptor *edEdge = new EdgeDescriptor();
  990. bool bIsValidSourceId = mapVertexIdToVertexDescriptorObj.contains(sSourceVertexId);
  991. bool bIsValidTargetId = mapVertexIdToVertexDescriptorObj.contains(sTargetVertexId);
  992. // check forward reference for the node
  993. if((bIsValidSourceId == true) && (bIsValidTargetId == true))
  994. {
  995. // forward reference problem not present in file
  996. VertexDescriptor vdSource = mapVertexIdToVertexDescriptorObj.value(sSourceVertexId);
  997. VertexDescriptor vdTarget = mapVertexIdToVertexDescriptorObj.value(sTargetVertexId);
  998. // XXX always true because unsigned >= 0 obeslete
  999. // if((vdSource >= 0) || (vdTarget >= 0))
  1000. // {
  1001. try
  1002. {
  1003. // add edge to this boost graph.
  1004. *edEdge = (add_edge(vdSource,vdTarget,(*gMainGraph))).first;
  1005. }
  1006. catch(LayoutMemoryException& eException)
  1007. {
  1008. DELETE_AND_SET_NULL(edEdge);
  1009. throw LayoutMemoryException(__FUNCTION__, LayoutExceptionEnum::NULL_POINTER_EXCEPTION, eException.getObjectName());
  1010. }
  1011. catch(boost::exception& eBoostException)
  1012. {
  1013. DELETE_AND_SET_NULL(edEdge);
  1014. throw *boost::get_error_info<errmsg_info>(eBoostException);
  1015. }
  1016. // }
  1017. // else
  1018. // {
  1019. // DELETE_AND_SET_NULL(edEdge);
  1020. // throw LayoutException(__FUNCTION__, LayoutExceptionEnum::INVALID_PARAMETER, INVALID_EDGE_PARAMETER, EDGE);
  1021. // }
  1022. // set the edge id into graph
  1023. (*gMainGraph)[*edEdge].sId = sEdgeId;
  1024. /*Adding Data Values to Edge*/
  1025. (*gMainGraph)[*edEdge].bBidirectional = structEntityProperty.bIsBidirectional;
  1026. /* Adding bend properties into the edge structure */
  1027. (*gMainGraph)[*edEdge].vecBendPoints = m_dirtyEdge.m_vecBendPoints;
  1028. #warning "GraphMLReader/GraphMLReader.cpp:1169:9: warning: Potential leak of memory pointed to by 'edEdge' (*gMainGraph)[*edEdge].vecBendPoints = m_dirtyEdge.m_vecBendPoints;"
  1029. //Clear bend list for dirty edge just added to graph
  1030. m_dirtyEdge.m_vecBendPoints.clear();
  1031. }
  1032. else
  1033. {
  1034. // forward reference problem present in file
  1035. cout<<"Forward refrence problem while adding edge "
  1036. <<sSourceVertexId.toStdString()<<" "<<sTargetVertexId.toStdString()<<endl;
  1037. DELETE_AND_SET_NULL(edEdge);
  1038. throw LayoutException(__FUNCTION__,
  1039. LayoutExceptionEnum::INVALID_PARAMETER,
  1040. FORWARD_REFERENCE,EDGE,
  1041. sSourceVertexId,sTargetVertexId);
  1042. }
  1043. }
  1044. GraphMLReader::~GraphMLReader()
  1045. {
  1046. DELETE_AND_SET_NULL(gCurrentSubGraph);
  1047. }