BSA – Dark vs Light

This first picture show the Dark Theme version made with QML, while the second show the Light Theme version made with WPF. The Light images are not all there yet, so I need to work on those. I am getting there with the light version as well. I decided to ditch TreeView and make a copy of the QML Tool Tree in WPF. Dead easy and I have far more control of what I am doing. Images are a lot of work tbh.

BSA – WPF Version 0.1

The WPF based version of BSA is getting there. It don’t look as cool as the QML version (yet). The reason I am avoiding Dark Theme is because I want to dig more into BSA functionality and avoid spending time on controls like the scrollbar’s for now. Usage with scrolling and zooming is in place, so I need to figure out the tab’s and multiple diagram bars next. Scrolling on this is not as cool as on QML (yet) – QML have a feature that it accellerate and deaccelerate so the scrolling feels more alive. Scrolling on WPF is by default the same old stepping – I probably have to add the animation from QML myself – no idea yet..

I would like a cooler looking scrollbar, but I use ScrollViewer 3 places and the scrollbar belong to this – I did not code a line to get scrolling correct. I fear I have to re-write a few controls to get back the cool QML scrollbar’s, but that’s nothing compared to all the QML controls I had to fight.

QML vs XAML is basically very much the same with different syntax. But, XAML is better integrated with C# and this is where productivity hits you hard. And to repeat myself – on WPF I can get a 3rd party library to deal with dark Theme.

Drawing performance ? I don’t know – looks pretty much the same so far. That said I did this app with good results in both Qt and C#/WinForms as well. WPF have many ways to do graphics so I am still reading up and testing to understand what is the best path. I can get away with any of them, but as I later will build more performance hungry controls I would like to understand their impact, pros and cons before I do to much of the graphics itself. It is also a 3rd party component “WritableBitmapEx” I want to try out. Fun for days to come.

Once I have my mind settled on graphics and how to draw optionally I will start on the drawing engine and draw more than just rectangles. But, this is pretty cool taking into account that this is ca 3 days work to get here so far. Keep in mind that what I am doing is one of the more complex graphics applications in terms of user interface. I struggled more than a bit with this on QML and it has so far been much easier on WPF – without dark theme that is.

The plan for the QML version was to focus on HMI first. The main reason was (and is) that HMI have become so over-complicated. You need to dig deep into technology like QML or WPF and many embedded developers simply do not have the time or skills needed to do this – neither should they need to. Making a HMI with a few gauges is hardly rocket science IMO.

BSA – Modules

One of the concepts in Plain and BSA is that you develop distributed system, not a single application or device. Meaning that state diagrams and logic can relate to a list of modules that are located either on HMI, on some server or a device distributed in a network. Both PLD and UML State Diagrams support this.

To enable this we will need to maintain a list of modules. A module is a functional module where you decide where you want this located by simply selecting platform from a list. This also means that you with a single click can move modules between platforms. Obviously we also need a definition of Nodes so we can describe the system we develop and a target platform selection – the later is static, build-in for now. It get a bit complicated, but the concept will save a big bulk of development hours by reducing complexity for the developer.

And here comes the trick called RPC (Remote Procedure Call). If PLD make a function call that call will need to adapt to wherever the module is local or on a remote node. If a function is local you simply make a standard local call, but if a function is remote it needs to convert into a message that is sent and wait for response (or timeout). The developer need to be aware of this, so function calls needs to be enabled for RPC as they are called.

Module is the key here because this also means that the repository needs to be structured around modules as the root component – something that goes hand in hand with how Plain is designed and works well for all other target languages.

Another level that is BSA specific is that we need to be able to load multiple projects. This will enable BSA to copy modules between projects or use library projects. Now this creates a new requirement as we need to keep track of dependencies between projects.

Going back to the discussion wherever I should use WPF or QML I think the discussion above tells it all. I have only worked a few days in WPF and are straight back into BSA functionality rather than HMI “How To”. Integration between XAML and C# is much easier to deal with than fighting the complexity of QML. That said I still miss some of the good things about QML so it is not a black/white discussion!

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.