PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/ext/OGDF/ogdf/fileformats/DinoUmlToGraphConverter.h

https://gitlab.com/cjeight/tortoisegit
C Header | 334 lines | 89 code | 40 blank | 205 comment | 0 complexity | 62db6440c08a40d14145c70ee80f4e82 MD5 | raw file
  1. /*
  2. * $Revision: 2564 $
  3. *
  4. * last checkin:
  5. * $Author: gutwenger $
  6. * $Date: 2012-07-07 00:03:48 +0200 (Sa, 07. Jul 2012) $
  7. ***************************************************************/
  8. /** \file
  9. * \brief Contains the class DinoUmlToGraphConverter...
  10. *
  11. * ...which performs all necessary steps to obtain a model graph
  12. * and a set of diagram graphs from the input file.
  13. *
  14. * \author Dino Ahr
  15. *
  16. * \par License:
  17. * This file is part of the Open Graph Drawing Framework (OGDF).
  18. *
  19. * \par
  20. * Copyright (C)<br>
  21. * See README.txt in the root directory of the OGDF installation for details.
  22. *
  23. * \par
  24. * This program is free software; you can redistribute it and/or
  25. * modify it under the terms of the GNU General Public License
  26. * Version 2 or 3 as published by the Free Software Foundation;
  27. * see the file LICENSE.txt included in the packaging of this file
  28. * for details.
  29. *
  30. * \par
  31. * This program is distributed in the hope that it will be useful,
  32. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. * GNU General Public License for more details.
  35. *
  36. * \par
  37. * You should have received a copy of the GNU General Public
  38. * License along with this program; if not, write to the Free
  39. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  40. * Boston, MA 02110-1301, USA.
  41. *
  42. * \see http://www.gnu.org/copyleft/gpl.html
  43. ***************************************************************/
  44. #ifdef _MSC_VER
  45. #pragma once
  46. #endif
  47. #ifndef OGDF_DINO_UML_TO_GRAPH_CONVERTER_H
  48. #define OGDF_DINO_UML_TO_GRAPH_CONVERTER_H
  49. #include <ogdf/fileformats/DinoXmlParser.h>
  50. #include <ogdf/fileformats/DinoUmlModelGraph.h>
  51. #include <ogdf/fileformats/DinoUmlDiagramGraph.h>
  52. #include <ogdf/basic/UMLGraph.h>
  53. namespace ogdf {
  54. //---------------------------------------------------------
  55. // D i n o U m l T o G r a p h C o n v e r t e r
  56. //---------------------------------------------------------
  57. /** This class performs all necessary steps to obtain a model
  58. * graph and diagram graphs from the input file which contains
  59. * an UML model in XML format.
  60. * In particular the following is done:
  61. * - Given the input file a class DinoXmlParser is created which
  62. * accomplishes the parsing of the XML file; as result of the
  63. * parsing procedure a parse tree representing the xml document
  64. * is accessible.
  65. * - The parse tree is used to extract the model graph of the contained
  66. * uml model as well as a set of diagram graphs which are part of the
  67. * uml model.
  68. *
  69. * The graphs can be accessed via the functions getModelGraph() and
  70. * getDiagramGraphs().
  71. *
  72. * In debug mode warnings and the content of the model graph and the diagram
  73. * graphs are written into the log file named \e umlToGraphConversionLog.txt.
  74. */
  75. class OGDF_EXPORT DinoUmlToGraphConverter {
  76. private:
  77. /** The parser used for parsing the input file. */
  78. DinoXmlParser *m_xmlParser;
  79. /** The graph which represents the complete UML model. */
  80. DinoUmlModelGraph *m_modelGraph;
  81. /** The set of graphs which represent special diagrams
  82. * contained in the model.
  83. */
  84. SList<DinoUmlDiagramGraph*> m_diagramGraphs;
  85. /** This list contains the set of graphs of the list #m_diagramGraphs
  86. * in UMLGraph format. The transformation is performed in the constructor
  87. * #DinoUmlToGraphConverter().
  88. */
  89. SList<UMLGraph*> m_diagramGraphsInUMLGraphFormat;
  90. /** Predefined info indices for known tag and attribute names. */
  91. enum PredefinedInfoIndex {
  92. xmi = 0,
  93. xmiContent,
  94. xmiId,
  95. umlModel,
  96. umlNamespaceOwnedElement,
  97. umlClass,
  98. name,
  99. umlGeneralization,
  100. child,
  101. parent,
  102. umlAssociation,
  103. umlAssociationConnection,
  104. umlAssociationEnd,
  105. type,
  106. umlDiagram,
  107. rootUmlDiagramElement,
  108. umlDiagramElement,
  109. geometry,
  110. subject,
  111. umlPackage,
  112. umlInterface,
  113. umlDependency,
  114. client,
  115. supplier,
  116. diagramType,
  117. classDiagram,
  118. moduleDiagram,
  119. nextPredefinedInfoIndex
  120. };
  121. /** Maps string info to node.
  122. * We need this hash table for fast access to nodes corresponding
  123. * to UML elements. For each UML Element in XMI format we have an
  124. * unique identifier via the xmi.id attribute. The xmi.id attribute
  125. * is saved as string in the hash table of the parser, hence we can
  126. * use the info index of it. While scanning for relations between nodes
  127. * we encounter the xmi.id attribute values of the involved elements referenced
  128. * as type attribute in the relation. Now we can use the hash table to
  129. * access the corresponding node.
  130. */
  131. Hashing<int,NodeElement*> m_idToNode;
  132. /** Maps string info to edge.
  133. * The functionality is the same as for #m_idToNode.
  134. */
  135. Hashing<int,EdgeElement*> m_idToEdge;
  136. /** The log file.
  137. * The log file is named \e umlToGraphConversionLog.txt and contains
  138. * warnings and errors ocurred during the conversion process. Furthermore
  139. * it contains the content of the model graph #m_modelGraph and of the
  140. * diagram graphs #m_diagramGraphs.
  141. */
  142. ofstream *m_logFile;
  143. public:
  144. /** Constructor.
  145. * The constructor performs the following:
  146. * - A parser object of class DinoXmlParser is created and
  147. * the parse process is started via DinoXmlParser::createParseTree().
  148. * - The variable #m_modelGraph is initialized with an empty object
  149. * of type DinoUmlModelGraph. Then the model graph is build up with
  150. * createModelGraph().
  151. * - The list of diagram graphs #m_diagramGraphs is given to
  152. * createDiagramGraphs() to build them up.
  153. *
  154. * @param fileName The file name of the xml file which contains the data
  155. * of the uml model to be converted into the graph format.
  156. */
  157. DinoUmlToGraphConverter(const char *fileName);
  158. /** Destructor.
  159. * The destructor destroys:
  160. * - the diagram graphs contained in #m_diagramGraphs,
  161. * - the model graph contained in #m_modelGraph,
  162. * - the parser contained in #m_xmlParser.
  163. */
  164. ~DinoUmlToGraphConverter();
  165. /** Access to model graph.
  166. * @return A const reference to the model graph.
  167. */
  168. const DinoUmlModelGraph &getModelGraph() const {
  169. return *m_modelGraph;
  170. }
  171. /** Access to diagram graphs.
  172. * @return A const reference to the list of diagram graphs.
  173. */
  174. const SList<DinoUmlDiagramGraph*> & getDiagramGraphs () const {
  175. return m_diagramGraphs;
  176. }
  177. /** Access to the diagrams graphs in UMLGraph format.
  178. * @return A const reference to a list of diagram graphs in UMLGraph format.
  179. */
  180. const SList<UMLGraph*> & getDiagramGraphsInUMLGraphFormat () const {
  181. return m_diagramGraphsInUMLGraphFormat;
  182. }
  183. /** Prints the content of each diagram to \a os.
  184. * @param os The output stream where to direct the output to.
  185. */
  186. void printDiagramsInUMLGraphFormat(ofstream &os);
  187. /** Print hash table which maps the ids to the NodeElements.
  188. * @param os The output stream where to direct the output to.
  189. */
  190. void printIdToNodeMappingTable(ofstream &os);
  191. private:
  192. /** Inserts known strings for tags and attributes into the hashtable
  193. * of the parser. The info elements for the hashtable are taken from
  194. * enum #PredefinedInfoIndex.
  195. */
  196. void initializePredefinedInfoIndices();
  197. /** Converts the relevant information contained in the parse tree
  198. * into the data structure of DinoUmlModelGraph. Error messages are
  199. * reported in #m_logFile.
  200. * @param modelGraph The model graph into which the nodes and edges
  201. * corresponding to uml elements and uml relations should be inserted.
  202. * @return Returns true if conversion was succesful, false otherwise.
  203. */
  204. bool createModelGraph(DinoUmlModelGraph &modelGraph);
  205. /** Traverses the package structure and identifies classifiers inside
  206. * the parse tree (starting at \a currentRootTag) and inserts a new node
  207. * for each classifier. This function will call itself recursively while
  208. * traversing nested packages.
  209. *
  210. * Valid classifiers are currently: \c class and \c interface.
  211. * @param currentRootTag The tag where to start the search for classifiers.
  212. * @param currentPackageName This string should contain the name of the package
  213. * path corresponding to \a currentRootTag.
  214. * @param modelGraph The model graph into which nodes are inserted.
  215. * @return False if something went wrong, true otherwise.
  216. */
  217. bool traversePackagesAndInsertClassifierNodes(
  218. const XmlTagObject &currentRootTag,
  219. String currentPackageName,
  220. DinoUmlModelGraph &modelGraph);
  221. /** Tries to find all classifiers of type \a desiredClassifier inside the parse
  222. * tree (starting at \a currentRootTag). Inserts a new node into \a modelGraph
  223. * for each classifier found.
  224. * @param currentRootTag The tag where to start the search for the desired
  225. * classifier.
  226. * @param currentPackageName This string should contain the name of the package
  227. * path corresponding to \a currentRootTag.
  228. * @param desiredClassifier The info index of the desired class
  229. * (see enum #PredefinedInfoIndex).
  230. * @param modelGraph The model graph into which nodes are inserted.
  231. * @return False if something went wrong, true otherwise.
  232. */
  233. bool insertSpecificClassifierNodes(
  234. const XmlTagObject &currentRootTag,
  235. String currentPackageName,
  236. int desiredClassifier,
  237. DinoUmlModelGraph &modelGraph);
  238. /** Traverses the package structure and identifies associations inside
  239. * the parse tree and inserts a new edge between the corresponding
  240. * nodes of the involved classifiers.
  241. *
  242. * Note that it is not possible to include this function into
  243. * traversePackagesAndInsertClassifierNodes(). The reason is that it
  244. * is possible that edges are specified prior to that one or both nodes
  245. * have been created.
  246. * @param currentRootTag The tag where to start the search for associations.
  247. * @param modelGraph The model graph into which edges are inserted.
  248. * @return False if something went wrong, true otherwise.
  249. */
  250. bool traversePackagesAndInsertAssociationEdges(
  251. const XmlTagObject &currentRootTag,
  252. DinoUmlModelGraph &modelGraph);
  253. /** Traverses the package structure and identifies generalization inside
  254. * the parse tree and inserts a new edge between the corresponding
  255. * nodes of the involved classifiers.
  256. *
  257. * It does not make sense to put this function and
  258. * traversePackagesAndInsertAssociationEdges() together since the generalization
  259. * tags are inside the class tags, so first the classes have to be identified
  260. * again in contrast to traversePackagesAndInsertAssociationEdges().
  261. * @param currentRootTag The tag where to start the search for generalizations.
  262. * @param modelGraph The model graph into which edges are inserted.
  263. * @return False if something went wrong, true otherwise.
  264. */
  265. bool traversePackagesAndInsertGeneralizationEdges(
  266. const XmlTagObject &currentRootTag,
  267. DinoUmlModelGraph &modelGraph);
  268. /** Identifies dependency tags inside the parse tree and inserts a
  269. * new edge between the corresponding nodes of the involved elements.
  270. * @param currentRootTag The tag where to start the search for dependencies.
  271. * @param modelGraph The model graph into which edges are inserted.
  272. * @return False if something went wrong, true otherwise.
  273. */
  274. bool insertDependencyEdges(
  275. const XmlTagObject &currentRootTag,
  276. DinoUmlModelGraph &modelGraph);
  277. /** For each diagram converts the relevant information contained in the parse tree
  278. * into the data structure of DinoUmlDiagramGraph. Error messages are
  279. * reported in #m_logFile.
  280. * @return Returns true if conversion was succesful, false otherwise.
  281. * \todo Currently only class diagrams are handled. Must be extended to handle
  282. * other kinds of uml diagrams.
  283. */
  284. bool createDiagramGraphs();
  285. /** Transforms each diagram graph contained in #m_diagramGraphs into an equivalent
  286. * Error messages are reported in #m_logFile.
  287. * @param diagramGraphsInUMLGraphFormat The list of diagram graphs in UMLGraph
  288. * format which have been obtained from the diagram graphs.
  289. * @return Returns true if conversion was successful, false otherwise.
  290. */
  291. bool createDiagramGraphsInUMLGraphFormat(SList<UMLGraph*> &diagramGraphsInUMLGraphFormat);
  292. }; // class DinoUmlToGraphConverter
  293. } // end namespace ogdf
  294. #endif