{"id":17930905,"url":"https://github.com/lovasoa/dia2code","last_synced_at":"2025-07-16T23:32:23.195Z","repository":{"id":54447990,"uuid":"49351266","full_name":"lovasoa/dia2code","owner":"lovasoa","description":"Dia2Code is a small utility used to generate code from a Dia diagram.","archived":false,"fork":false,"pushed_at":"2021-02-17T10:45:23.000Z","size":721,"stargazers_count":16,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-06T10:08:21.746Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://dia2code.sourceforge.net/index.html","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lovasoa.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-10T03:07:12.000Z","updated_at":"2024-12-05T11:17:20.000Z","dependencies_parsed_at":"2022-08-13T16:00:35.690Z","dependency_job_id":null,"html_url":"https://github.com/lovasoa/dia2code","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/lovasoa/dia2code","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Fdia2code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Fdia2code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Fdia2code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Fdia2code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lovasoa","download_url":"https://codeload.github.com/lovasoa/dia2code/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Fdia2code/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265550338,"owners_count":23786545,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-28T21:18:31.303Z","updated_at":"2025-07-16T23:32:23.180Z","avatar_url":"https://github.com/lovasoa.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dia2Code v. 0.9.0-lovasoa\n\n## SUMMARY\n\nThis program generates code for many languages from an UML Dia Diagram.\n\n\n## DESCRIPTION\n\nThis program is a small utility that makes code from a Dia diagram. Supported\nlanguages are: Ada, C, C++, C#, IDL, Java, PHP(4,5), Python, Ruby, shapefiles,\nand SQL create statement files.\n\nIts intended purpose is to ease the programmer's work by generating\nthe structure of the classes in an Object Oriented language\n(like C++, Java and C#) from a graphical representation of them\n(a Dia Diagram).\n\n\n## STATUS\n\nDia2Code generates Ada, C, C++, IDL, Java, PHP, Python, C#, and Ruby files.\nIt can also generate a file with SQL's CREATE TABLE statements and .bat files for\ncreating shapes.  Templates and packages are supported but need testing.\n\nThe basic functionality can now be considered complete.  Minor releases\nshould fix bugs and add small improvements.\n\nThe generation of # include and import directives is done considering the\ntypes used in each class but, generally, only if those types are\ndeclared themselves in the diagram.  Classes are searched in the types of:\nattributes, parents, method's return types, method's parameters, dependencies\nand associations.\n\nDia2Code looks for Generalizations, Realizations, Implements, Dependencies and\nAssociations and adds that information to the class list.\n\nPackages are implemented considering the geometry information of the objects\n(packages and classes).\n\nFeel free to have a try and send me your comments.\n\n\n## LICENSE\n\nThis program is distributed under the GNU GPL.  Read the COPYING\nfile for details.\n\n\n## REQUIREMENTS\n\nI've only tested it under Linux/i386 and Win32.  I have notices of\nsuccessful compilation on *BSD and GNU Hurd. It should work with\nother platforms, but your mileage may vary.\n\n- Dia (I work with 0.88 but older versions *may* be OK).  Not for\n  the compilation part but to make some nice diagrams with it.\n- libxml2 headers and development libraries (I use 2.4.1 but it *may* be\n  OK if you use any version greater than 2.0.0).\n- A C compiler.\n- automake and autoconf (actually, optional)\n\n\n## INSTALLATION\n\nUsually:\n\n        $ ./configure\n\n        $ make\n\n        # make install\n\nRead the `INSTALL` file for details.\n\nIf that doesn't work for you, try (from the innermost dia2code directory):\n\n        $ cc -I/usr/include/libxml *.c -O2 -o dia2code -lxml2 -ldl\n\n        $ strip dia2code\n\nI've modified Makefile.am and configure.in so \"configure\" will hopefully\nfind everything it needs.\n\n\n## OPERATION\n\n    $ dia2code \u003cparameters\u003e\n\nWhere `\u003cparameters\u003e` can be any combination of:\n\n```\n-h|--help\n   prints help on parameters and exits inmediately\n\n-t (ada|c|cpp|idl|java|php|python|shp|sql|csharp)\n  tells dia2code to either create C++ (cpp), Java (java), C (c),\n  Ada (ada), Python (python), SQL \"create table\" files (sql) and\n  C# (csharp).\n  The default is C++.\n\n-d \u003coutdir\u003e\n  tells it to put the files in the specified directory.\n  The default is to output files in the current directory.\n\n-nc\n  asks dia2code to not overwrite existing files.\n         - Default return value for non-void methods.\n\n-cl \u003cclasslist\u003e\n  generates code only for the classes specified in the\n  comma-separated \u003cclasslist\u003e.\n\n-v\n  inverts the class list selection.  When used without -cl,\n  prevents any file from being created.\n\n-l \u003clicensefile\u003e\n  prepends the contents of the specified file to each source file\n  generated.\n\n\u003cdiagramfile\u003e\n  Name of the dia file (compressed or not) that contains the\n  UML diagram to be parsed.\n```\n\nThe only mandatory parameter is the diagram file name.\n\nNote: Parameters can be specified in any order.\n\n\n## EXAMPLES\n\n    $ dia2code -t java test.dia\n\nWill generate the *.java files for the classes in the test.dia diagram\nand put them in the current directory.\n\n    $ dia2code -nc -d ~/C++ hw.dia\n\nWill generate the *.cpp and *.h files for the classes in the test.dia\ndiagram and  put them in the directory ~/C++.  It won't overwrite any\nexistant file.\n\n    $ dia2code -t java -cl Base,Derived test.dia\n\nWill create the Java files only for classes \"Base\" and \"Derived\".\n\n    $ dia2code -cl B*,*Foo test.dia\n\nWill create the `*.cpp` and `*.h` files for classes that begin with \"B\" or\nend with \"Foo\".\nNOTE: You can only specify one asterisk and either at the beginning or end\nof the pattern.\nNOTE2: You may have to quote the asterisks when typing on the shell\n(e.g. \"\\\\*\" instead of \"*\")\n\n    $ dia2code -cl Foo -v foobar.dia\n\nWill create C++ code for all classes but \"Foo\".\n\n    $ dia2code -v test.dia\n\nWill not create any files.  Don't know if it may be useful, but it surely\nis syntactically correct.\n\n\n## HOW IT WORKS\n\n1. Parse the diagram file with xmlParseFile().\n2. Parse the tree generated in 1 for UML classes to build an\n   umlclasslist (type defined here).\n3. Parse the tree again for UML Generalizations, Realizations,\n   Implements, Dependencies, Associations and packages to add information\n   to the class list.\n4. Generate the structure of the classes (write it into files)\n   from the class list.\n\nSteps 1-3 are done in `parse_diagram()`.\nStep 4 is done in `generate_code_*()`.\nBoth functions are called from `main()`.\n\n\n## NOTES ON UML\n\nWhat you should put into your diagram\n\nThese are mandatory:\n\n- A non-empty class name.\n- For each attribute, the name and type.\n- For each method, the name.\n- For each method's parameter, the name and type.\n\nThese are optional:\n\n- The stereotype of the class.\n- The default value of attributes.\n- The default value of parameters.\n- The return type of a method. If no type is declared, dia2code\n  will output no type at all for it.\n\n\n### Stereotypes\n\nIn IDL, C++, and Ada, some stereotypes are supported that all begin with\n\"CORBA\". These are: CORBAConstant, CORBAEnum, CORBATypedef, CORBAStruct,\nCORBAUnion, CORBAValue.  When generating IDL, the corresponding IDL syntax\nis generated for the UML class.  When generating other languages, a rough\nmapping from the IDL to the other language is generated.\n\nThe following conventions are followed by the code generation for CORBA\nstereotypes:\n\nConstant   First attribute's type contains the const type; first attribute's\n           value contains the const's value. Everything else unused.\nEnum       Attribute names contain the enum literals, everything else unused.\nTypedef    First attribute's type contains the original type;\n           first attribute's value optionally contains the dimensions\n           in case of an array. Everything else unused.\nStruct     Attribute names and types contain the struct members.\n           Everything else unused.\nUnion      First attribute's type contains the switch type. Only\n           enum types are supported as the switch type.\n           Following attributes contain the union cases as follows:\n           Attribute value contains the switch value for the case\n           (only exactly one value possible per case); attribute\n           name and type contains the union member name and type\n           for that case.\n           Everything else unused.\nValue      Use much like a normal class. Staticness not supported.\n\n\nIn C++, an abstract class is not explicitly declared as it is in Java.\nTo have a class declared as \"abstract\" you have to set its \"abstract\" flag.\n\nFor generating Java, dia2code recognizes two stereotypes: \"Interface\" and\n\"JavaBean\".  The former is a standard stereotype name, the latter a convention\nwe use here.\nBoth interfaces are only meaningful when generating Java code.  If the\nstereotype is \"JavaBean\" then dia2code will output, for each attribute a of\nthe class:\n\n- A \"T getA();\" method, with return type conformant to the type of the attribute.\n  If the type of the attribute is \"boolean\" then the name will be: \"boolean isA()\".\n- A \"void setA(T value);\" method, with a paramter, \"value\", with type conformant to\n  the type of the attribute.\n\nFor generating PHP, the \"interface\" stereotype is recognized and produces an\ninterface rather than a class.\n\nNote: actually, dia2code will not output these things, but it will create the\nmethods and paste into each one the suggested implementation.  These methods will\nbe treated as the rest.  The generate_code_java outputs an implementation if\none's avaliable.  The generate_code_cpp just happens to do the same, but I feel\nit is most useful when generating Java code.\n\n\n### Visibility\n\nDia2Code does not handle the \"implementation\" visibility for methods (yet).\nSo when you have a class that implements a method that was declared\nabstract in a base class, you have to give it the same visibility of the\nparent class' method.   The visibility of the method is not printed if it is\n\"implementation\"; this may be a source of bugs.\n\n\n### Method's return type\n\nIf you leave the \"type\" entry in the method declaration empty, then no\ntype will be declared for it.  This is useful with constructors, when the\nreturn type is implicit (both in C++ and Java).  If the return type is\nvoid, you should explicitly declare it in the UML diagram.  I don't know\nif this is a good practice, I just thought it was reasonable. Everyone is\nwelcome to discuss it.\n\n\n### Packages\n\nThe UML standard states that there are (mostly) two ways of representing\npackages: a large box with all the elements inside (Large Package in Dia)\nor a small box (Small Package in Dia) to which the package's elements\nconnect with a symbol that Dia does not (yet?) include: a line with a\ncrossed out circle in the end of the container.  You can put a normal line\nwith a \"Coordiate origin\" arrow at one end, of course, and will be\naestetically correct, but of no use to Dia2Code.\n\nDia2code, currently, checks only for intersections of packages (Large or\nSmall) with other objects like classes and other packages, so it will\nbe mostly useful with diagrams that use Large Packages instead of Small\nones.\n\nAs of version 0.8.2, the Java, IDL, C++, and Ada code generators use\npackage information.  We should upgrade the other generators so they will\ngenerate better import/include directives.  The Java code generator\ncurrently outputs all the files to the specified directory, does not\ncreate one for each package. The IDL, C++, and Ada generators generate\nfiles only for the outermost packages/classes. UML elements nested inside\npackages are generated as items nested with the IDL module, C++ namespace,\nor Ada package.\n\n\n\n## INFORMATION FOR DEVELOPERS\n\nCode Generators:\n\nA code generator function is a function that takes a pointer to a\nbatch structure.  The structure looks like this:\n\n```c\nstruct batch {\n    umlclasslist classlist;\n    char *       outdir;\n    int          clobber;\n    namelist     classes;\n    int          mask;\n};\n```\n\nThe classes to generate are in classlist.\n\nThe output directory is outdir.  The files that the generate_code\nopens for writing MUST have this output directory as a prefix, UNLESS\nit is NULL, in which case, it will default to \".\".  The function\nSHOULD check the length of the directory for possible buffer overflows\ninside the function.\n\nIf the clobber flag is set, any already existing file in the output\ndirectory MUST NOT be overwritten.\n\nClasses is a list of the classes to create code for.  Mask is a\nflag that inverts this selection.\n\nSome example code:\n\n```c\n# include \"dia2code.h\"\n# include \"decls.h\"\n# include \"includes.h\"\n\ngenerate_code_foo (batch *b)\n{\n    umlclasslist tmplist;\n    declaration *d;\n\n    tmplist = b-\u003eclasslist;\n    while (tmplist != NULL) {\n        if (! (is_present (b-\u003eclasses, tmplist-\u003ekey-\u003ename) ^ b-\u003emask)) {\n            push (tmplist, b);\n            /*\n                The class is pushed onto the global `decls'.\n                We do this in order to support packages:\n                A single package may contain multiple classes\n                and these classes must be generated in the correct\n                order, i.e. declare classes that depend on other\n                classes towards the end.\n            */\n        }\n        tmplist=tmplist-\u003enext;\n    }\n    /* Generate a file for each outer declaration.  */\n    d = decls;\n    while (d != NULL) {\n        char *name;\n        char outfilename[256];\n\n        if (d-\u003edecl_kind == dk_module) {\n            name = d-\u003eu.this_module-\u003epkg-\u003ename;\n        } else {         /* dk_class */\n            name = d-\u003eu.this_class-\u003ekey-\u003ename;\n        }\n\n        sprintf (outfilename, \"%s.h\", name);\n\n        spec = open_outfile (outfilename, b);\n        if (spec == NULL) {\n            d = d-\u003enext;\n            continue;\n        }\n\n        /* Determine include files needed.  */\n        includes = NULL;\n        determine_includes (d, b);\n        if (includes) {\n            namelist incfile = includes;\n            while (incfile != NULL) {\n                if (!eq (incfile-\u003ename, name)) {\n                    emit (\"# include \\\"%s.h\\\"\\n\", incfile-\u003ename);\n                }\n                incfile = incfile-\u003enext;\n            }\n            emit (\"\\n\");\n        }\n\n        /*\n            We generate all the code here\n        */\n\n        fclose (spec);\n        d = d-\u003enext;\n    }\n}\n```\n\nGenerating import/include clauses:\n\nincludes.h contains the function determine_includes() and the global\nvariable `includes'.  Handling is as shown in the example above.\n\ndetermine_includes() assumes that a file is generated for each outer\npackage and for each class not nested inside a package.\n\nIf this does not make sense for the programming language you are targeting,\nthen there are two lower-level functions that can help the code generator\nknow which classes are used inside the current class: find_classes() and\nlist_classes().  The former is the eldest of the two.  It returns a namelist\n(a list of char*) with the names of the classes used that are also declared\nin the same diagram (are on the classlist).  The latter is a new addition\nin version 0.7.  It does basically the same search but instead of a list of\nchar* it returns a classlist with pointers to the diagram classes themselves.\nWhich to use is up to you.  For generators of C and SQL code the\nfind_classes() will suffice.  For generators of Java code, that use\nheavily the package information, the list_classes() is more suitable.\n\n\n## BUGS\n\nNote: some bugs may not be listed here.\n\n- No checking for full filesystem while writing files.\n- Does not follow the DTD of a Dia Diagram, rather parses as it sees fit.\n- Allocates memory proportionally to the size of the diagrams.  It should work\n  OK with small diagrams but may slow down with BIG ones.\n\n\n## AUTHORS\n\n### Original author\nJavier O'Hara \u003cjoh314@users.sourceforge.net\u003e\n\n### MAINTAINER\n\nRichard Torkar \u003crichard.torkar@htu.se\u003e\n\n### Contributors\n(in alphabetical order, by last name)\n- Cyrille Chepelov \u003cchepelov@calixo.net\u003e Pyhton code generation, Debian package management,\n  Hurd conformance.\n- Harald Fielker \u003chfielker@softsolutions.de\u003e PHP code generation.\n- Oliver Kellogg \u003cokellogg@users.sourceforge.net\u003e, CORBA stereotype and\n  package support\n- Ophir Lojkine (@lovasoa), bug fixes and support for database diagrams\n- Ruben Lopez \u003cryu@gpul.org\u003e, C code generation.\n- Steffen Macke \u003csdteffen@yahoo.com\u003e batch shapefile generation, win32\n  installer.\n- Chris McGee \u003csirnewton_01@yahoo.ca\u003e Dependencies, Associations, C++ Templates, SQL,\n  IDL code generation.\n- Takashi Okamoto \u003ctoraneko@kun.ne.jp\u003e License inclusion mechanism.\n- Thomas Preymesser \u003ctp@odn.de\u003e Ada code generation.\n- Dmitry V. Sabanin \u003csdmitry@lrn.ru\u003e Ruby code generation.\n- Jérôme Slangen \u003cjeromes@mail.be\u003e Wildcard class list mechanism.\n- Takaaki Tateishi \u003c\u003e Dynamic Shared Objects for dynamic code generator modules.\n- Martin Vidner \u003cmvidner@users.sourceforge.net\u003e Porting to libxml2.\n- Thomas Hansen \u003cthomas.hansen@adramatch.com\u003e C# code generation.\n\n\n### THANKS\n\nThanks to Collin Starkweather and Slush Gore for the extra help.\nAlso, thanks to all the people that have contacted me with\nsuggestions and bug reports.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovasoa%2Fdia2code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flovasoa%2Fdia2code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovasoa%2Fdia2code/lists"}