Dia2Code v. 1.0.0 SUMMARY This program generates code for many languages from an UML Dia Diagram. DESCRIPTION This program is a small utility that makes code from a Dia diagram. Supported target languages are: C++(99,11), C#, Java, PHP5. Starting version 1.0.0, the program was completely rewritten in C++. Target languages still to be ported from the dia2code-0.8.x C implementation are: ActionScript3, Ada, C, Python, Ruby, shapefiles, and SQL create statement files. Its intended purpose is to ease the programmer's work by generating the structure of the classes in an Object Oriented language (like C++, Java and C#) from a graphical representation of them (a Dia Diagram). STATUS Dia2Code generates C++(99,11), C#, Java, PHP. Templates and packages are supported. In the future, it will be able to generate ActionScript, Ada, C, IDL, Python, Ruby, shape files, and SQL's CREATE TABLE statements. For the time being, if you require any of these languages, please continue to use the dia2code-0.8.x C based implementation. The generation of #include and import directives is automatically done considering the types used in each class but they may be added by dependencies. Classes are automatically searched in the types of: attributes, method's return types, method's parameters, parents, dependencies and associations. Dia2Code handles Associations, Dependencies, Realizations, Implements and Generalizations. Feel free to have a try and send me your comments. LICENSE This program is distributed under the GNU GPLv3. Read the COPYING file for details. REQUIREMENTS Works under Linux (i386 and x64) and Win32/Win64. Feedback about other platforms is welcome. - Dia (I work with 0.97.2 but older versions *may* be OK). - libxml2 headers and development libraries (I use 2.9 but it *may* be OK if you use any version greater than 2.0). - A C++ compiler which supports C++11 standard (>=gcc 4.6). - automake and autoconf (actually, optional) INSTALLATION Usually: $ ./configure --with-corba $ make $ make check # make install Read the INSTALL file for details. If that doesn't work for you, try (from the src's dia2code directory): $ g++ -std=c++11 -I/usr/include/libxml2 *.cpp -O2 -o dia2codetest -lxml2 -I.. $ strip dia2code To cross-compiling from Linux (build=x86_64-pc-linux-gnu): - To Win32, with package cross-i686-pc-mingw32/gcc: # ./configure --disable-static --enable-shared --build=x86_64-pc-linux-gnu --host=i686-pc-mingw32 - To Win64, with package cross-x86_64-w64-mingw32/gcc: # ./configure --disable-static --enable-shared --build=x86_64-pc-linux-gnu --host=x86_64-w64-mingw32 - To Linux32: # ./configure --disable-static --enable-shared -m32 - To Linux64: # ./configure --disable-static --enable-shared -m64 OPERATION $ dia2code Where can be any combination of: -h --help Print this help and exit. -d Output generated files to , default is "." --buildtree Convert package names to a directory tree. Imply -1. Off by default. -l License file to prepend to generated files. -nc Do not overwrite files that already exist. -cl Generate code only for the classes specified in the comma-separated . E.g: Base,Derived. -v Invert the class list selection. When used without -cl prevents any file from being created. --version Show version x.y.z. --tab Set number of spaces for one indentation. Default: 4. Maximum: 8. -ext Use as the file extension. Here are the defaults: ada:"ads", c:"h", cpp:"hpp", idl:"idl", java:"java", php:"php", python:"py", csharp:"cs". Not applicable to shp, sql. -bext Use as the body (implementation) file extension. Only applies to ada and c. Here are the defaults: ada:"adb", c:"c". -nl Create new line on new brace. Off by default. -1 One header contains only one header. If two classes have the same name, they will be overwritten without --buildtree. Off by default but java. -t Selects the output language. can be one of: ada,as3,c,cpp,cpp11,csharp,idl,java,php,php5,python, ruby,shp,sql. The Dia file that holds the diagram to be read. The only mandatory parameters are the diagram file name and the target. Note: Parameters can be specified in any order. EXAMPLES $ dia2code -t java test.dia Will generate the *.java files for the classes in the test.dia diagram and put them in the current directory. $ dia2code -t cpp -nc -d ~/C++ hw.dia Will generate the *.cpp and *.h files for the classes in the test.dia diagram and put them in the directory ~/C++. It won't overwrite any existant file. $ dia2code -t java -cl Base,Derived test.dia Will create the Java files only for classes "Base" and "Derived". $ dia2code -t cpp -cl B*,*Foo test.dia Will create the *.hpp files for classes that begin with "B" or end with "Foo". NOTE: You can only specify one asterisk and either at the beginning or end of the pattern. NOTE2: You may have to quote the asterisks when typing on the shell (e.g. "\*" instead of "*") $ dia2code -t cpp -cl Foo -v foobar.dia Will create C++ code for all classes but "Foo". $ dia2code -t cpp -v test.dia Will not create any files. Don't know if it may be useful, but it surely is syntactically correct. NOTES ON UML What you should put into your diagram These are mandatory: - A non-empty class or package name. - For each attribute, the name and type. - For each method, the name. - For each method's parameter, the name and type. These are optional: - The stereotype of the class. - The default value of attributes. - The default value of parameters. - The return type of a method. If no type is declared, dia2code will output no type at all for it. OUTPUT This section shows some examples of UML diagram converted to code without use of stereotype. Lines starting with double stars are comments to explain the process of the generation of the code. Common: If -1 and --buildtree are not specified, the name of each file will be the class name (if not in a package) and the name of the top package either. If -1 or --buildtree is specified, the filename will be the class name. C++ generator: ** The license if specified in command line (-l option). /* File bit-by-bit. */ ** Header guard #ifndef README__HPP #define README__HPP ** Dependencies #include "dependencies.hpp" ** Templates template ** Namespace if classes are in package. namespace package { ** Class with inheritance if necessary. class Class : public ParentClass { ** Visibility of the attribute / operation. Public, private, protected ** are supported. Implementation is not, default will be public. ** Attributes will be printed first, then operations. // Attributes ** Default values are ignored for attributes. public : ** Comments are in doxygen format. /// Comment for the first /// attribute. type1 nom1; private : /// Example of static attribute. static type2 nom2; protected : type3 nom3; // Operations public : /** * \class AbstractOperation * \brief Multiple line * comment */ ** An abstract operation must not be defined thus " = 0". virtual AbstractOperation () = 0; ** A virtual operation must be defined in the source code. virtual VirtualOperation (); NonAbstractOperation (); /** * \brief comment * \param in (in) * \param inOut (in/out) comment2 * \param undef (???) * \param out (out) */ virtual type test (type1 in, type2 inOut, type3 undef = 0, type4 out) = 0; static test2 (); test3 () const; }; } ** End of header guard #endif C++11 generator: ** The license if specified in command line (-l option). /* File bit-by-bit. */ ** Header guard #ifndef README__HPP #define README__HPP ** Dependencies #include "dependencies.hpp" ** Templates template ** Namespace if class are in package. namespace package { ** Class with inheritance if necessary. public class Class : public ParentClass { ** Visibility of the attribute / operation. Public, private, protected ** are supported. Implementation is not, default will be public. ** Attributes will be print first, then operations. // Attributes ** Default values are ignored for attributes. public : ** Comments are in doxygen format. /// Comment for the first /// attribute. type1 nom1; private : /// Exemple of static attribut. static type2 nom2; protected : type3 nom3; // Operations public : /** * \class AbstractOperation * \brief Multiple line * comment */ ** An abstract operation must not be defined thus " = 0". virtual AbstractOperation () = 0; ** A virtual operation must be defined in the source code. virtual VirtualOperation (); NonAbstractOperation (); /** * \brief comment * \param in (in) * \param inOut (in/out) comment2 * \param undef (???) * \param out (out) */ virtual type test (type1 in, type2 inOut, type3 undef = 0, type4 out) = 0; static test2 (); constexpr test3 (); }; } ** End of header guard #endif C# generator: https://msdn.microsoft.com/en-us/library/ms228500%28v=vs.90%29.aspx XML Documentation Comments https://msdn.microsoft.com/en-us/library/b2s063f7.aspx ** The license if specified in command line (-l option). /* File bit-by-bit. */ ** No header guard ** Dependencies using dependencies; ** Templates template ** Namespace if classes are in package. namespace package { ** Class with inheritance and templates if necessary. public class Class