Next Previous Contents

4. In Depth

This section gives you a more in depth view of what's going on. It's probably not necessary to read, but maybe if you don't get a quirk or two you might figure out what's going on here.

4.1 Inheritence and Relations

Inheritence is pretty key to the whole model. There are really two sorts of inheritence going on in the KlassModeler. The first is inheritence within your model. Like if you make a CAnimal class and a CDog class. To do the inheritence it's easiest to right click on the CDog class and choose "Inherit from" in the menu. Next left click on the CAnimal class and you will see the inheritence line drawn. You can move the horizontal bar up and down by left clicking on it and dragging (it can be a little hard as it's only a pixel wide). The other kind of inheritence is outside of the model. Like if this CAnimal actually inherits from some other library, perhaps wxCarbonBasedLifeForm. Since this outside class isn't in your model you will need to open the Class Information dialog by double clicking on the class. The Relations tab show you the list of things you inherit from. Simply click on Add and type in the parent and press okay. If you make a mistake delete the parent class and re-add it. All inheritence is public in the KlassModeler since I've never seen anyone use any other type. Let me know if you actually need other inheritences and I'll add them.

Relations aren't really key to anything, but my friend Anatoli REALLY seems to like them. They don't affect the generated code at all, they're just visual things to help you with your design. The two types of relations are Has-a and Uses-a. According to Anatoli a Has-a relation is when a class owns a variable. It created it, it's responsible for destroying it. A Uses-a relationship is when a class uses a variable. Maybe a pointer is passed in or something, but when the class is done with the variable it is not responsible for deleting it. Really there are just 2 new kinds of lines in the model that you can use. Feel free to do whatever you want with them. You can create these lines pretty much the same way you create inheritence lines, with the right mouse button or by using the Relations tab in the class dialog.

4.2 Code Generation

First off, make sure that you have set the header file name in the Misc tab in the Class Information dialog. Remember that this file and path is relative to the path that your KlassModeler file is saved. If that is all set then you're ready to generate the header. If you want to generate for just the one class, right click and choose Generate Code from the menu. If you want to generate code for the entire project, choose Headers from the Generate menu in either the tree view or the model view. If you have a model that includes some classes you DON'T want generated when you generate the complete model you can check the "Exclude from full model generation" box in the class Misc tab. KlassModeler is smart enough to parse existing headers and it will only erase and rebuild the information between the class ClassName line and the end }; So you can put #include and #define and even other classes inside your header and KlassModeler will leave those alone. It is often helpful to understand just a little bit about how KlassModeler writes the code. Basically it does the simplest thing possible, it writes the Return Type, then the Method name, then the arguments, etc etc. There is no parsing. So if you want a complex return type like const struct MyType *, then simple fill that in for your return type. Heck, you could fill in const struct as your type and put the MyType * in your class name (though that would make the model look sort of stupied). If you want a constructor with no return type then just don't include a return type.

4.3 HTML Doc Generation

This is similar to code generation except you can only do it for the whole model all at once. If you have a model that includes some classes you DON'T want generated when you generate the complete model you can check the "Exclude from full model generation" box in the class Misc tab. Again, make sure your HTML file field is filled in in the Class Dialog Misc tab. To Generate the docs choose HTML Docs from the generate menu. This will dump all the html files and a few extra files. Specifically you will get an index.html, KlassModelerImage.html and .png, and a KlassModelerMenu.html. The extra files create the frame and image for the docs. You can open your docs by using the index.html file. I apologize for the shameless plug of putting my name and a link to my web page in the docs, but I am trying to promote KlassModeler and I think it would be cool if people knew where your docs where coming from. No hard feelings at all if you decide to edit the source to remove those lines.

4.4 Reading external header files

This is an option I really avoided for a long time. There are just so many darned inputs, and I slept through most of my compiler design class, so I really don't know anything about good parsing. But eventually someone asked for it (Thanks Norbert ;) so I decided to give it a try. To do it, simply right click on the blank part of the screen, and choose "New Class from header" from the context menu. It will ask you for a header file.

You can also read new headers from the clipboard. This is a great option if you want to just copy a few classes from a header file and only import those. To do this just select the class or classes you want to import and copy them. Then in the model view right click and choose "New Class from clipboard."

I managed to get it to work for all my headers, but even within my own stuff there were a ton of permutations. I don't expect it to work for all headers. When it gets confused it tends to go into an infinite loop, so SAVE YOUR WORK BEFORE YOU TRY IT! If it does manage to read the header if will remember the header file as KlassModelerAttempt.OriginalName.h. Please try generating this header and make sure you like what it does before you have KlassModeler overwrite any of your headers.

Anyway, warnings aside, when it does work it's pretty cool. Give it a shot, and if it does something stupid, or hangs, please send along the header that broke it and I'll try to fix it. If enough people do that then maybe it will start getting robust.

4.5 Printing

I've recently added printing and still consider it somewhat experimental. I've only tested it on a borrowed HP LaserJet 6P using CUPS under KDE. And it doesn't really work all that great for me. If you know anything about printing and would like to pass on some pointers, I'd appreciate it.

Under the "View" menu you'll notice an option to show printer grids. This will draw grid lines for where the printer has its page breaks. If printing is important to you then you should lay out your design such that objects stay away from those page break lines. Margins and other craziness make it so objects that get to close to the lines often get parts of themselves dissapeared.


Next Previous Contents