Saturday 28 July 2018

TrafficControl: Adding a Help Menu to Web Pages

I added a help section on the program, and that was quite easy!

In the user interface form (trafficcontrol.ui), I added an action (actionHelpOverview) in the help menu. That action was connected (SIGNAL/SLOT) to a slot that opens a web page in the default browser in the system.


The existing help pages are quite small - I don't want to have too much text and I want the program to be easy to use without reading too much documentation.

In the next blog post, I'll simplify the Python script that converts KML file to TrafficNetworkMap.

Saturday 21 July 2018

TrafficControl: Minor Fixes for Network Designer and User Interface

As mentioned earlier, the default path to the network files were hardcoded. This made TrafficControl dependent on having that particular folder on the particular computer, which is bad design. Instead, I used QStandardPaths to make the program look for the files in the user's home directory.


Further, I've modified the code for generating the TNM file. It is possible to select either a KML file, or a Traffic Network Map/File. In the latter case, the file is opened and parsed directly to the text field.

TrafficControl is setting up the UI and has many signal/slot definitions. I moved those to a separate function.

Finally, I deleted some objects in the trafficControl destructor in order to prevent memory leaks.

In the future, I'll need to add tet cases and error handling.

Saturday 14 July 2018

TrafficControl: NetworkDesigner Class for Designing Networks

Before proceeding with the network designer, I need to plan where to add the new functionality,

One use case will be:
  1. User selects a complex but valid KML file.
  2. The python script trackStationConnector.py converts the file and displays the output on trafficNetworkDescriptionEdit.
  3. If there are issues seen, the program should inform the user
  4. If there are no blocking issues, the user can save the file and/or continue with using the train network that is now loaded.
Initially, I'll assume that the input from the user is correct. I'll add error checks later.



How it's done:
The button for selecting the KML file is associated with the action actionImportKmlFile. That action activates a slot in trafficControl that allows the user to select the KML file to import.


I have separated the code for selecting a file and the code that is opening the file for testability reasons. This way, I'll be able to open files in automated testing.
Here, the file path is hard coded. I need to have a generic default directory, such as the user's home folder.

Once the file is selected, it is opened from networkDesigner:
The program calls the python interpreter on the system, and parses the path to the python script as the first argument and the KML file as the second argument. This approach is very system-dependent and anyone that fetches my GIT repo must adapt this part. I need to fix tis issue in a later blog post.

All output from the python script is saved and parsed to trafficControl::updateTnmTextBox that is setting the text. It also parses the commands to networkControl so that the corresponding elements appears on the map. For testability, this needs to change so that the networkDesigner can communicate directly to networkControl using signals/slots.

Finally, the program saves the contents of the two text fields to one file.

This solution is hardcoded for my system. I need to make it more generic in future versions. Now, the program works only if puthon is installed on the computer, and the python path must be "c:/users/gusbra...".



Saturday 7 July 2018

Trains: Volunteers Bringing History to Life

One sunny day in June, me and my family went to a heritage railway in the eastern parts of  Skåne.

Skånska Järnvägar is a non-profit organisation that operates four stations, 13 km of railway, half a dozen of locomotives and some passenger cars. All this is possible thanks to dedicated and hard-working volunteers.





The railroad was constructed in 1901, but it was transferred to SJ fourty years later. There has been no line traffic for more than fourty years.



Thanks to Skånska Järnvägar for keeping the traffic running!