Need advice on how to split code for complex forms in more files

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
User avatar
Parduz
Experienced Solver
Experienced Solver
Posts: 53
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Need advice on how to split code for complex forms in more files

Post by Parduz » Tue Jan 22, 2019 9:37 am

I'm building a complex program wich will run on a BeagleBone, full of pages, subpages, controls and interaction between them.
Right my "main UI" file (the program frame) is 6k lines long, and i'm at half of the road. There's all the control events, plus the code for handling events from the underlying classes, serial and sockets communication classes, all the events from the hardware to which the Beaglebone is connected, and all the functions needed to manage and refresh the UI part of my project.

I would like to "split" this whole file in a more handly way .... a single cpp file for each wxSimpleBook would be a huge improvement, at least i'll have all the code that have a specific meaning in the same place.
Or, given that i use wxCrafter to design the form, a unique file for the control events and then separate files for the "non-control" functions etc.

I just can't think to a good way to make it in code:blocks. Did someone have some suggestions?

Thanks

Manolo
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 689
Joined: Mon Apr 30, 2012 11:07 pm

Re: Need advice on how to split code for complex forms in more files

Post by Manolo » Tue Jan 22, 2019 4:38 pm

wxWidgets code is a good example. Each goal (e.g. a special control like wxGrid, wxDVC, or event not that special, like a wxFileDialog) has its own .h and .cpp files.

If you have a dialog for setting some parameters, add new files to the IDE and write the GUI code inside them. Passing these parameters to some containers or even their serialization may well go in these same files. If it's too complex, use other dedicated files.

Moving existing code to new files is as simple as cut & paste. And be aware to #include the files where the handlers are defined and pass the right "parent" to each control.
If the existing code is automatized (wxForms, wxSmith, etc) then perhaps it's worth to recreate them in the new files, so the automatic creator is able to modify them.

Post Reply