Looking for guidance on structure of application

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
georgeplusplus
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue May 11, 2021 1:49 pm

Looking for guidance on structure of application

Post by georgeplusplus »

I am writing a msPaint style application and as I am writing my application and adding features I can tell I havn't planned this out all the way since it feels hacky and has that "code smell" feeling. I would really appreciate feedback or design principles and any samples you can share that would be helpful as a basis for what I am trying to do.

Basically my GUI contains a wxFrame called MainWindow which is split into two panels as member. The left panel contains a wxTreeCtrl, the right panel is split again into top and bottom and contains an ImagePanel that is responsible for rendering objects from the treeview, and a wxDataViewCtrl for annotations made by the user on the ImagePanel.

I leverage wxTreeItem by creating objects that inherent from wxTreeItemData that act as the data container for the corresponding trees items. Each TreeItemData has associated dialogs to control the user inputs such as naming and image.

The problem I am running into is keeping consistent whats reflected in my wxTreeCtrl to what is displayed on the imagepanel. Everything is currently handled within MainWindow along with Menu/Toolbar events and TreeCtrl events which seems to be bloated from an object point of view. I find myself running into scenarios I have not accounted for and instead handling them with if statements.

I was also wondering if it is possible to have bidirectional emitted events between the left and right panel such that, a change of one can be caught by the other and vice versa.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Looking for guidance on structure of application

Post by PB »

Did you look into patterns such as model-view-controller and similar? You can read basic overview here
https://en.wikipedia.org/wiki/Model%E2% ... controller

wxWidgets has https://docs.wxwidgets.org/trunk/overview_docview.html but I am not sure if it is a good fit for your scenario.
georgeplusplus
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue May 11, 2021 1:49 pm

Re: Looking for guidance on structure of application

Post by georgeplusplus »

The first link is interesting. It sounds like what I am trying to implement but not quite. Could you give an example of how my code would fit this pattern?

I believe what I want is the TreeCtrl to just be a representation of what the user is performing to the loaded image. But since each child of the root could contain a new image with its own set of annotations and user added drawables, the TreeCtrl must accept limited input that would change the wxImagePanel. My current implementation creates a wxImagePanel for each child and Hide, Shows them .

So basically

Root
- Child1 << OnTreeSelectionActivated
- Rect1
- Triangle1
-Child2
- Circle1
- Circle2

if the user double clicks Child1, it activates that set of children onto the wximagepanel, if they select any of the children while the parent node is active they can modify or highlight it.

The built in Doc/View sounds like its too basic for what I want to do.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Looking for guidance on structure of application

Post by PB »

Sorry, I do not have a concrete code example for your model.

Basically, if I understand this correctly, those model-xxx patterns try to minimize tight coupling between classes, with roles for each part of the application clearly divided. I think the diagrams displayed showing the interaction e.g. between the M, V, and C are quite helpful.

If you are not familiar with those patters, I would try reading some more specific guide.
georgeplusplus
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue May 11, 2021 1:49 pm

Re: Looking for guidance on structure of application

Post by georgeplusplus »

Let me simplify my question. I was trying to point out that my Controller and View are coupled currently so the pattern you suggested would not work.

I can use the TreeCtrl(controller) to update whats drawn to the canvas(view) by deleting nodes and updating images. BUT I can also populate my TreeCtrl by drawing on the canvas.

Any suggestion how to decouple this?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Looking for guidance on structure of application

Post by PB »

I am just a simple guy, certainly no expert on software design.I do not want to assume how much you are familiar with design patterns, so I'd rather not give you a concrete example.

I would read more about patterns such as MVC or MVP, it is easy to find papers where they demonstrate the pattern on an example. This should answer some of your questions on which pattern is most suitable for your case and which parts of the code belong to which part of the pattern. There are still many variants of the patterns to choose from, and whichever you may choose it still does not mean that implementing it is easy. It just means that you may spend less of your time and energy on possibly reinventing the wheel or making the code suboptimal.

But perhaps someone else will recommend another and better approach to all this.
georgeplusplus
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue May 11, 2021 1:49 pm

Re: Looking for guidance on structure of application

Post by georgeplusplus »

I am familiar with the object oriented design patterns they teach in during university. Builder, Factory, Singleton etc. So anything you have wouldnt hurt.

For others who stumble upon this topic I found this topic that has helped explain a bit more.

viewtopic.php?t=30955
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Looking for guidance on structure of application

Post by PB »

georgeplusplus wrote: Wed May 12, 2021 9:09 am I am familiar with the object oriented design patterns they teach in during university. Builder, Factory, Singleton etc. So anything you have wouldnt hurt.
I have no formal education, the closest I came to the topic was probably reading the (now ancient) gang of four book, I am not sure if the book actually covers the MV* kind of patterns. Knowing that you are actually educated on the topic, me trying to help you would be futile at best, harmful at worst.
Post Reply