BSA – Top-Level Architecture

This illustrate the 4 main components inside BSA. You obviously have the UI part that visualize things on the screen. This is the main and largest part, but you also have Repository, Code generator and Debugger integration that needs to be in place.

One of the reason’s I wanted to try WPF is the Repository/UI integration. In WPF I can just use standard C#, but in QML I had to use C++ and a complex binding to QML/JavaScript that basically took a lot of development time.

Debugger means that once you have generated the code and build/deployed the executable you can run it and step though logic and set breakpoints etc from BSA itself. BSA will actually be the tool you develop in unless you need to get your hands dirty with smart source code modules.

Repository is basically the project database either in JSON or XML format – I like JSON, but I need to test text etc in JSON. XML might be a safer choise as storage format. The objective of using XML/JSON is that this is basically your source code and as a last resource we need to be able to manually fix this. The UML model inside the repository will be complex as this is a complex tool to make, but I won’t dig to much into those details.

The code generator might be a command line tool that read the repository and generate code.

One part of PLAIN was that we made distributed systems rather than devices, so the code here might be several executables. For now I will repeat the session on focusing on Forms and HMI, but I will return to the more complex parts of BSA later.

BSA – WPF Property Editor – Part 3

These two examples show one of the edit controls I am considering. The challenge with a property editor is that it is an array of labels and values not well suited to edit text needed for descriptions. And just giving it more height as shown above don’t really help. So what I consider is an option to expand the edit as shown below. Even if I just stay inside the control this will be an inprovement. I just have to test as we go.

The compromize to hold the text within the control is easy and can be seen below. This might be combined with a button to pop into a larger word-pad. This was not even hard to make.

BSA – WPF Property Editor – Part 2

I have added the 6 most common object that I will need as well as got a start on the control itself. So far it has been very straight forward. I discovered that you cannot use inheritance with XAML, so these are identical, stand alone XAML objects for now – QML could use inheritance, but in WPF you need to use C# kode more – which is ok. One thing I do not like with WPF is details like the ComboBox and ScrollBar – I have a hard time controlling their colors. On QML I had different challenges with ComboBox so we will see.

Text Editor is one of the reasons I want to make this myself – Text in this case is a multi-line editor and I want to show a few lines in the property editor and have a expand button that allow me to show an extended text editor. I had this ca figured out in QML, so I will redo some research on how to do this here.

The next step is to be able to click on a symbol or the diagram and set the property list and fetch it back. I really struggled getting that done in QML, but I expect this will be far more straight forward in C#. As mentioned I am not new to C#, but I am new to XAML/WPF.

The nice thing about C# is that I have several options while in QML I only found one that I did not like. Since I am using C# I can either create a separate binding list for each object or use reflection and attributes. I think I prefer the later, meaning that you just throw an object to the property editor with close to no binding code. Reflection is feature in C# that open for some awesome API functionality.

BSA – QML version – what happened?

The QML version of BSA is almost finished on Forms design, but I froze further development until I have tested WPF. I get things working in QML, and I am happy with what I see and experience on the screen. But, I am not happy with how much work it is to get simple things done. I needed to create a QML SDK to be able to generate code for QML, but for BSA itself I want to do the same with WPF before I make a choise on how to continue.

Doing this in WPF is not straight forward either, but one issue that keep kicking me is the complexity of maintaining a repository in C++, QML and JavaScript – it does cost a lot of hours. In WPF I will maintain the repository in C# only – that alone is a huge difference. As for Qt Creator – well it is better than it was, but it is not even close to Visual Studio sadly. The two key issues is Visual Designer that crash with advanced QML and a debugger that only work on a good day. These two account for a lot of hours lost.

At the end it comes down to a long term decition on what is the best toolkit for BSA!

BSA – WPF Property Editor – Part 1

To get a feeling of the challenges with WPF I want to share the work to create a functional Property Editor in WPF. A Property Editor is a complex component, so it’s worth examining the challenges – that said – I am only exploring one path here – Both QML and WPF have multiple alternatives on getting this done.

The option that got my attention is StackPanel. In QML I just used a similar component and stacked 2 columns with label/editors. This will not work in Forms due to flicker on the screen, but it should work with WPF. To start I create a PropertyRow component consisting of 3 rows – a left, wide border, a label and a edit column. PropertyRow itself will just be a header as I extend the label to right, but I can subclass this into more specialized property rows:

  • PropertyRowString – Edit a single line text.
  • PropertyRowNumber – Edit a number.
  • PropertyRowCheckBox – Edit a bool using a checkbox.
  • PropertyRowComboBox – Select a value from a list using ComboBox.
  • aso – the list here will grow.

The 2nd thing is to make StackPanel scrollable – woops that’s just setting a flag in StackPanel and it’s done.

The 3rd thing I would like is animation on the same level as in QML – if you scroll in QML it animate the action making the UI feel so more alive. This is not critical, but it is one of the details I really liked with QML, so I will look into how to get this in WPF as well.

As I have decided to use WPF “as is” with light colors and are not digging into Dark Theme I should have a much more free ride with WPF.

The first, early version showing only 4 rows of PropertyRow can be seen above.

This last pic show how the PropertyRow look in Visual Studio – somehow I missed the border lines only. At this point I must admit that doing this excact task in QML was easier. But, that might be because I know how to do this in QML and is a bit newbie on inheritance with XAML involved yet.

Adding a header row and manually adding a Scrollbar column the Property Editor look like below. I can work with this if I have to, but I think I can avoid the manual scrollbar – lets see later.

 

BSA – Selecting WPF Components

Having a good Property Editor is important for BSA. In QML I had no choise but to start making my own, but I have ended up doing the same on every platform I tried. In WPF I could get a free one or buy one, but do I want to?

My objects will have sub-tables and properties like description that is hard to do in any property editor + StackPanel can basically create a property editor using edit objects I can create allowing for an easy adding of custom editors. Yes, this is work, but the graphical editor and the property editor is key to BSA.

I have the same issue on the graphical editor. I could use a 3rd party diagram editor, but my experience is that I will end up tweaking them because it is key functionality and is better off making my own from scratch.

So, in short – for Graphical Editor and Property Editor I will do it the hard way – from scratch myself – not because I want to, but because they are key to BSA and 3rd party components might just be in my way.

This is a hard decision you better make up front. I have far to often spent hours tweaking 3rd party components on critical functionality knowing that you have to be very selective. The question you always need to ask is If your application can adapt to the component, or if your component need to adapt to your application? In case of the later you need to be carefully.

A 3rd component I need is a DataGrid with inline edit options – in this case I have no challenge with adapting to whatever I got to work with, meaning I will use the build-in DataGrid which is actually very good.

Another recommendation learned from hard experience is that you should select 3rd party libraries with care, because you will have to live with them afterwards. Myself I often find it easier to create something I myself have control over than adapting to someone elses design and quality. But, again – I have never been afraid of putting my back into coding!

Designing my own property editor will probably also lead to another decition – I will systematically need to enable/create in-line editor options. I will use whatever WPF have and tweak it if I can or create new ones from scratch. The advantage is that I can re-use those for more advanced diagram-in-lines and I might get some 3rd party assistance. It is a lot of good developers out there that has released good solutions that can be re-used.

BSA – Custom Title Bar in WPF

One of the hardest things you do in Windows development is to change the Title bar and integrate that better in your application. What you basically need to do is to switch off the Windows Title bar and create your own.

I have done this in Forms and Qt/QML, but WPF stunned me with how easy this was! One of the advantages with WPF and C# in general is the number of developers willing to share tricks and I owe this one to this YouTube movie:

[C# WPF Tutorial] How to Make a Functional Custom Window Chrome – EASIEST METHOD! – YouTube

This will work for dark theme as well as integrating the main menu into the title bar as I want to do.

The window above shows the modified, custom title bar with Menues moved into title. I only used some text for the buttoms, but I can now add whatever I want or set colors as I want in the Title. The importance of this is that I save some space at top + it is prepared for dark theme.

BSA – WPF First Look

This is the WPF version of BSA after a few hours of work. It’s not much to look at, but I will focus on BSA itself and not the dark theme/cool look this time. Firstly I need to learn WPF so I can generate code for it anyway – but, I also expect to find a drop-in library that will change the look with a few hours work later. Lets see how fast I can catch up with 3+ months of QML work – that is the only thing that matters. So far I am impressed over how easy it is to learn WPF compared to QML.

BSA – C#/WPF .NET 5

Most of my focus is on SW for the time being, and it is sadly less interesting to write about yet. My BSA project is ambiguous specially since I keep switching development platform.

Back in the early days I did vector graphics on DOS. The challenge then was that you needed to even develop raster graphics functions yourself. My first 2D drawing was on Windows 95 using C++/MFC. That was a great success, but after that I basically stopped doing UI for a long time. I did a test using GDI+, Lazarus, Qt and even C#/Forms before I finally had a chance to work with Qt/QML.

Qt/QML is so far the best solution in terms of the result, but I am concerned that QML is so slow to develop with, so I want to try yet another solution – C#/WPF and .NET 5.

The main difference between QML and WPF in 2021 is that Visual Studio actually work as it is supposed to – it is a far better integration to XAML and C# than QML is. The debugger work properly and you only code in XAML and C#.

The second difference is 3rd party libraries. In QML they are expensive if they exist at all, while in Visual Studio you have access to ca 235,000 libraries with a single click.

Something that is not different is that you need to modify a lot of controls to have a dark theme etc, but you have the advantage that it’s a lot of 3rd parties that has done this already.

My WPF version of BSA don’t look as cool as my QML version yet, but just wait.

I have coded in C# before and was tempted to develop BSA in Forms since .NET 4.6.2, but .NET 5 and WPF seems to be much faster to work with than QML. My QML version is not lost because I will generate code for QML regardless. And I need to generate code for C#/WPF .NET 5 as well. And don’t worry, I will pick up Lazaruz as well at some point.

BSA – HMI Gauge Editor

This simple drawing illustrate how I can create a gauge with several separate layers. In this case I draw a background and a needle on top of that. The final gauge is illustrated at top. This is exacly how I plan to embed a gauge editor in BSA – by using a table with x layers where the user can draw (or code) each layer separately and watch the result. This is an easy way of creating gauges where you also can use gauges within gauges.

In this example I scale the rotation of the needle so that input value match the scale. But, I could easily rotate or change something else – meaning we create a system to scale input values to position, rotation etc so we can animate any part of the gauge. It’s a few details I need to experiment with, but gauges are important in my worlds and this system should allow you all to create your own gauges easely.

Once created the gauge should be visible in the toolbar and be available for usage – which means I need tp export properties to make a consolidated property list. For gauges build this way I plan an in-line editor where you can create local adaptions or modify the library directly from the place you use the gauge. I think this will be awesome, but it will require some experimentation and try & fail adaptions as we go.