Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where to we go from here with the ApsimX user interface #4381

Closed
zur003 opened this issue Nov 20, 2019 · 30 comments
Closed

Where to we go from here with the ApsimX user interface #4381

zur003 opened this issue Nov 20, 2019 · 30 comments
Labels
Software An error in the interface or structure of the software

Comments

@zur003
Copy link

zur003 commented Nov 20, 2019

Three years ago, I ported the Apsim user interface from Windows.Forms to Gtk# to allow for cross-platform usage. That has worked reasonably well, despite it not being a particularly mainstream technology (more precisely, the Gtk side is mainstream on Linux, and .Net is mainstream on Windows, but their intersection isn't that widely encountered).

Now the question arises of how (and if) we can maintain this platform as the associated technologies evolve. On the Gtk side, Linux is gradually moving away from Gtk 2 (which we are currently using as the native base layer), and towards Gtk 3, with Gtk 4 on the horizon. On the Windows side, Microsoft has introduced .NET standard (and the associated .NET Core 3 implementation), and indicated their intent to move things further in that direction. Apparently .NET Framework 5 will be base on .NET Standard.

I've spend some (too much!) time recently looking into these technologies. ApsimX's Models,exe builds and runs readily under the .NET Core 3 implementation, and gives noticeably better performance than Mono on Linux (and presumably OS X) platforms. The problems arise when we turn to the user interface. This seems like a good time to consider transitioning from Gtk 2 to Gtk 3, which is not too radically different, although Gtk 3 uses a very different CSS-based mechanism for controlling the style of user interface elements, and has a bit more support baggage associated with it. Most of the existing ApsimX user interface works under Gtk 3 with only minor modifications, but there are three areas with some difficulties:

  1. The Text Editor: we have been using Mono.TextEditor, which is based on Gtk 2 and was taken from version 5.9 of MonoDevelop. MonoDevelop is now at version 8.4 (and still using Gtk 2), but the editor code can no longer be readily abstracted from the rest of that project. I have tried porting the "old" Mono.TextEditor to Gtk 3, but haven't been fully successful, and it's not clear that we want to rely on an old, complex codebase that no-one else is working on. If we migrate to Gtk 3, I suggest that we switch to GtkSourceView as the editor. It continues to be under active development, and provides useful stuff like a code completion interface. The newer versions target Gtk 3, not Gtk 2. I have been able to successfully build a .Net wrapper for it, but have tested only its most basic features.

  2. Code completion: this is tied in with the text editor, to some extent, but another aspect is a change in C# compilers. We would likely want to transition from Mono.Cecil and ICSharpCode.NRefactory to Roslyn equivalents for parsing C# code. I haven't looked into this very closely yet. @hol430 would know far better than I what is involved. Getting the Manager to compile scripts using Roslyn turned out to be quite simple, though, so perhaps this won't be too hard.

  3. HTML rendering: this is perhaps the biggest problem. Our current use of browsers is platform-dependent. We embed an instance of Internet Explorer on Windows, WebKit on Linux and Safari on OS X. This isn't going to work, at least not easily, with .NET Core. Using IE on Windows involves using a COM interface, and calls in System.Windows.Forms which offers this support. If you do this under .NET Core, you've pulled in a platform dependency in a way that prevents the application from running on other platforms. The solution ought to be using WebKitGtk on all platforms. Unfortunately, the WebKit developers dropped official support for Windows several years ago. I've tried using an older webkitgtk dll from Cygwin, and it almost works, but can't render maps, apparently because the JavaScript interpreter has a bug in it. I've tried re-building this myself in an attempt to track down and remove the bug, but with no success to date (it's a very slow process; compiling webkitgtk can take several hours). WebKit should work readily on Linux and OS X, but Windows has me stumped. The developers of Midori appear to be working on a Windows port (for 64-bit Gtk3; their old one works well but is for 32-bit Gtk2), but there's no guarantee that will ever be released. A possible alternative to WebKitGtk is chromely.cef.gtk (which wraps the Chromium browser), but this appears to still be under development with little documentation, and I haven't been able to get it to work.

Note that for testing both GtkSourceView and WebKitGtk, I've had to build my own C# wrappers around the native binaries. This is an obscure process, but not terribly difficult if you have access to the source code for the native binaries.

So where do we go from here? Do we (1) stick with .Net Framework 4 and Gtk 2 and watch the rest of the world go by, (2) find workarounds (the browser part really has me stuck) for using .NET Core 3 and Gtk 3, (3) abandon the concept of a multi-platform GUI (making it Windows only, using either Windows Forms or WPF), or (4) use some other option like qml.net? @hol353 - can we discuss this when you are next in Canberra?

@lie112
Copy link
Contributor

lie112 commented Nov 20, 2019

Wow, appreciate all your work looking into this. I feel a pang of guild for even mentioning .Net Core.
Disclaimer: I am a windows user and may discriminate against users of other operating systems.
I have always felt that we are still a little too early in software development space for a true, professional looking, cross platform UI, but this field is advancing rapidly and we're better off waiting a bit while ensuring our direction is able to take advantage of future advancements.
Having offered the cross platform version of Next Gen now, we have users (still limited numbers I suspect) with workflow relating to the three OSs. .Net core will allow the non-UI component of APSIM (the model) to be cross platform compatible providing HPC compatibility. How many users need the UI on iOS and Linux and can't access a windows based alternative (real or virtual machine)? This is an important consideration.
In some respects the UI is relatively simple, but this may be a result of history and our restrictions enforced by GTK. I also appreciate the volume of work in developing and fixing the UI and what would be needed to rebuild using another approach, whether new or moving to Gtk3. Making decisions about new interfaces should not be taken lightly given the amount of work to bring an already working interface into a new style. There would have to be a side by side implemntation of the new approach with the current working version.
My personal view would be that we bring everything forward into .Net Core. I always though it was easier to have a windows based interface and I'd vote for WPF, but can't see this style providing multi platform compatibility in future (Point 3). This would expose us to a rich array of features that could be more easily implemented improving the look and feel and functionality of the interface tied to the development environment. The ability of Visual Studio to support WPF development is also improving rapidly for those new to these applications.
I feel HTML is a valuable approach to displaying rich information pertaining to our simulations (reports and summaries and even graphs with java add-ons when internet connection available) and may even provide a means of user interaction with client side aspects.

@hol353
Copy link
Contributor

hol353 commented Nov 20, 2019

@zur003 Great work and thanks for the analysis!

Happy to discuss this in Canberra next week. My view is that while there aren't many people using APSIM on Linux or MacOS, there are some. There were 3 people on Macs in Iowa that I was helping while I was there in July. I also know Jeremy Whish uses it quite a lot on his Mac. Forcing them to do this in a VM is somewhat painful for them. There are probably others. I would like us to retain cross platform support for APSIM, including the GUI. It is a great selling point when I give presentations!

I was looking at the code for HTMLView a couple of days ago. Terrible, but I understand why it has been implemented that way. I would love to find an alternative, even if it is just a rich text view.

Another source of frustration is the grid control (treeview in Gtk). It is only just acceptable with lots of hacks in the code to get it to function somewhat they way we want.

Two options that haven't been mentioned so far:

  1. Investigate using QT instead of GTK. Do they have a rich text and better grid control?
  2. Move to GTK3 and write our own rich text control. We may only need to implement the bare basics of MarkDown or HTML - formatting, list items etc. We could probably live without the Map control for now. How long would it take to write a rich text control?

@zur003
Copy link
Author

zur003 commented Nov 20, 2019

In response to @hol353:

Basic "rich text" would lose our mapping capability. For what it's worth, the Webkitgtk support that I've found for Windows currently displays the summary and model descriptions correctly - it fails with the mapping (and in other contexts where Javascript is used heavily so, for example, it doesn't render www.apsim.info particularly well).

The Gtk 2 treeview admittedly makes for a very clumsy grid control. I don't think Gtk 3 will help matters here. It introduces a "Grid" widget, but that's intended for use as a layout container, not as a spreadsheet. I should look into recent developments with gtksheet. It didn't used to work very well, but it appears to be under active development, and things may have improved. Using gtksheet would require writing the bindings for .Net, but that might not be terribly difficult.

Qt has a very rich set of controls, although it is designed for the C++ world rather than the C# one. It might (or might not) work well, but porting to it would require substantial effort.

There's no need to write a "rich text" control. The Gtk Textview control can already handle a lot of that.

@peter-devoil
Copy link
Contributor

Thanks for the detail, @zur003 - it's good to be so well informed.

I'd strongly advocate for a native mac solution - the majority of my colleagues and a high proportion of students (~30%) are mac users; and increasingly many have never come across VM applications like parallells, and asking them to install the VM in addition to apsim is even more burdensome. On the converse - most linux users are well conversant with VMs, perhaps because Linux GUIs have always been a sorry joke.

Many years ago, the WxWidgets people did native L&F cross platform GUIs successfully, but only succeeded due to a high abstraction level which made "nice" customisations difficult - so the resulting UI always looked bland - a lowest common denominator.

WRT textviwers - it seems we'll be forever catching up with browsers if we focus on html. If we really want to surf that wave (eg a solution like electron), we'd be up a massive cost of re-tooling our UI, yet have a better (yet non-native) L&F. The much cheaper option of a markdown processor would still be able to turn our documents into something readable.

I know we've got a map component, but has anything used it yet? I did some work on map data aggregators and soon found the bulk of the work relied on connecting a web datasource some form of customised popup - and html had been doing such async work for years. Its almost like they wrote it just for that task..

@jbrider
Copy link
Contributor

jbrider commented Nov 20, 2019 via email

@zur003
Copy link
Author

zur003 commented Nov 22, 2019

A solution may have presented itself to one problem: WebWindow has just been released on NuGet and looks like it might handle the cross-platform browser problem. The approach is similar to what we're doing currently (wrapping native browsers on each platform), but packages it more nicely.

Also I've been playing with GtkSheet, an add-on to Gtk which provides a spreadsheet-like widget. This now works under Windows. The main problem with it is that is requires a native binary for each platform.

@hol430
Copy link
Contributor

hol430 commented Nov 24, 2019

@zur003 do we really have to build a wrapper for the gtksourceview? There seems to be a .net wrapper already out there - it has its own page in the mono documentation. We don't seem to have access to this namespace currently but I'm guessing that's just because we don't have the source view binary sitting next to the other gtk binaries.

@zur003
Copy link
Author

zur003 commented Nov 24, 2019

@hol430 - I think the Mono documentation is for an early version of gtksourceview, prior to the introduction of useful stuff like code completion support. It would also have been for Gtk 2 rather than Gtk 3.
Building GtkSharp 3 wrappers isn't all that difficult - the harder part is ensuring the native binary to be wrapped actually exists.

@hol430 hol430 added the Software An error in the interface or structure of the software label Nov 26, 2019
@hol430
Copy link
Contributor

hol430 commented Dec 9, 2019

@zur003 I've checked out the netcore3 branch but it seems like .net core 3 isn't supported by vs2017? Do I need to upgrade to vs2019 to work on this branch?

@zur003
Copy link
Author

zur003 commented Dec 9, 2019

That is correct - .Net Core 3 requires VS 2019.

@lie112
Copy link
Contributor

lie112 commented Dec 9, 2019

Intelicode and other features are worth the upgrade.

@zur003
Copy link
Author

zur003 commented Dec 9, 2019

@hol430 - Just a word of warning: If you check out the netcore3 branch into the same directory tree that you normally use for building ApsimX, then switch back to a Framework based branch later, you are likely to get cryptic error messages when doing a build with Framework. The solution is to totally purge the "obj" and "bin" folders for each project. This seems to happen only when going from a netcore3 build to a framework build; going the other way doesn't seem to present any problems.

@hol430
Copy link
Contributor

hol430 commented Dec 9, 2019

Yeah in the end I just opted for a 'nuke everything' approach with git clean -xfdq and that seemed to do the trick.

@hol430
Copy link
Contributor

hol430 commented Mar 22, 2020

@zur003 did you end up looking into the webwindow component? I had a bit of a play around last week and managed to get a barebones version of our ui running on .net core/gtk3 but couldn't get the webwindow to play nicely. Also worth noting that webwindow requires the developer's version of edge to be installed in order to work at all on windows.

@zur003
Copy link
Author

zur003 commented Mar 23, 2020

@hol430 - I didn't look very deeply into WebWindow, but I kind of got the impression it was more suitable for creating and controlling a browser window from a console program rather than for proper embedding. That is, I don't think it would allow the browser to be hosted inside a Gtk window, which is what we need (if possible). But I could be wrong about that.
Chromely.CefGlue.Gtk is another options I need to investigate a bit more closely....

@hol430
Copy link
Contributor

hol430 commented Mar 23, 2020

Yeah that's what I found as well. I had a brief look into cef but couldn't find much in the way of documentation

@jbrider
Copy link
Contributor

jbrider commented Mar 23, 2020

@zur003 @hol430 Isn't the WebWindow approach just a lightweight approach to the same way Electron works?
We're starting to use Electron to do a new version of REMS - using the core3 version of Models.
We've only got to the setup phase at the moment, but should be progressing that very soon.
Like a million other people now, I use Visual Studio Code a lot - it uses Electron and works across multiple platforms. As a UI platform it seems to tick all the boxes - especially the one about rebuilding the UI unfortunately.

@hol430
Copy link
Contributor

hol430 commented Mar 23, 2020

@zur003 have you looked into the graphing side of things? It appears that the OxyPlot.GtkSharp3 package is based on the .net framework version of gtk#3.

@zur003
Copy link
Author

zur003 commented Mar 24, 2020

Well, it is open source, and I had no problems compiling a version for .Net Core 3.

@hol353
Copy link
Contributor

hol353 commented Nov 25, 2020

Time for an update:

#1: We have to move to .NET core.
#2: We must stay cross-platform. All major software is cross-platform.

The quickest way to get to .NET core is to keep using GTK# but upgrade to version 3 which supports .NET core. This is much simpler than switching to Electron or another technology. One of the hold ups to this was the use of HTMLView which isn't supported in GTK#3. To this end we have moved most (all?) our GUI code away from using HTMLView. The notable exception to this are the CLEM views.

Ways forward:

  1. All CLEM views are converted to use GTK controls like the rest of APSIM. @hol430 and I estimate this might take a couple of months work. The look and feel of CLEM would change dramatically. How do we fund this?
  2. CLEM is put onto its own git branch, effectively taken out of the APSIM release. Breaking the linkage with APSIM is a move in the wrong direction. It was always a goal to properly link CLEM to APSIMs daily timestep. That becomes much harder (impossible?) if CLEM isn't in same branch as APSIM.
  3. ??

@lie112 : thoughts?

@peter-devoil
Copy link
Contributor

If you're spending effort upgrading to a newer technology, why not upgrade to the most modern technology - electron?

@lie112
Copy link
Contributor

lie112 commented Nov 26, 2020

Hi everyone,

My hope had always been that CLEM sat in the background and never caused any problems, just adding extra functionality to others along the way and identifying areas of improvement, optimisation and generalisation.

My reason for using HTML in CLEM for the descriptive summaries was because other summary documentation approaches were not mature in APSIM Next Gen three years ago, I wanted a professional, colourful display providing a standard look and feel across the CLEM environment within APSIM Next Gen, there was a HTML viewer already being used in APSIM that fulfilled the role, I was able to leverage off the full capabilities of css including simple plots, it allowed an instant simple dark/light theme implementation, and I assumed a HTML view would always be one of the the safest and most compatible approaches into the future. WRONG ON LAST POINT

It seems the cross platform UI development from Microsoft (and others) is lagging behind the Core and Standard code and this is our dilemma. I can see we're a couple years too early in needing the linked UI to the model core across platforms.

I think there will be much more interest in running CLEM at the same time as ASPIM crops and pastures in future as many current users are using APSIM results as input into CLEM with no feedback between the models, so I suggest CLEM remains with the current build, but what with the HTML? Plus, I want access to the latest C# and Core coding conventions!

I haven't looked into future HTML view options that might be on the way. The pages being displayed are static (after clicking tree) and don't contain hyperlinks etc. I am not sure if they could be converted to RTF or something in the meantime (if there was a viewer). Was there talk that the HTML view may work on Windows machines? I am not sure how many CLEM users are on macs, but restricting CLEM to Windows might be a start (no descriptive summary on iOS, Linux). Otherwise I guess we could use an external browser to display the information outside the APSIM UI, which is not ideal but an interim approach.

I am less inclined to spend time and effort on converting the CLEM summary descriptions to GTK components as I see the UI being one of the more fluid aspects into the future and love the separation of model and UI, and never liked GTK. In future I can see web apps interacting with servers for APSIM.

They are my thoughts and only solutions I can think of.

Any choice of future UI direction can potentially have large costs and something with least change to present is desirable at present. Unless the process of building the entire VIEW component in Electron or equivalent was simple and provided vast improvement in functionality and look and feel I am not sure it's worth it at present.

@jbrider
Copy link
Contributor

jbrider commented Nov 26, 2020

I also think that html is a better choice for our future direction and if progressing to a newer version of GTK3 is going to remove that then I don't see that as a step forward. I didn't realise that we were moving away from htmlview for this reason - apologies for not understanding that earlier.

I realise that a much larger investment of time and resources will be needed to move to a different tech rather than upgrading the current one. At present that will fall heavily onto Drew and yourself, but I think it will be easier to find people who have html skill or would be willing to invest time in developing skills in html rather than GTK - I know that I'm one of them. I think the number of existing components and tutorial code out there for html has to be orders of magnitude larger than GTK which should also be a consideration.

Our front end (views) should be able to be separated from the presenter/model code - so with the release of .net5 shouldn't we be able to run the existing gtk interface on top of .netcore? I know this wasn't possible before, but it should be now?

@hol353
Copy link
Contributor

hol353 commented Nov 26, 2020

  • I'm hesitant about Electron because of the time investment to change and the fact that I've never seen a grid (spreadsheet) like control in a Electron app (please correct me if I'm wrong). We make extensive use of grids with copy / paste to/from EXCEL.
  • If we stay with GTK2 then we don't get .net core. I'm already using a special .net core build of APSIM Models.exe in the World Modellers project - not idea;. We need .net core now!
  • If we go to GTK3 we lose the HTML control but gain .net core.
  • .NET 5 doesn't give us any new capabilities for writing cross platform GUIs.
  • .NET 6 with Microsoft MAUI (evolution of Xamarin) released some time next year (preview available now) might give us a way forward. Once again I suspect there are no grid controls. It is rare that you see a grid control in an android / Ios app which was Xamarin's main focus.

We might need to rethink our use of grid controls. The problem though is I can't see a way of visualising a soil profile without using a grid control of some sort.

@hol430
Copy link
Contributor

hol430 commented Nov 27, 2020

Was there talk that the HTML view may work on Windows machines?

I haven't managed to find anything that works but I'll admit haven't really looked into a windows-specific solution.

It seems that there are four options:

  1. Do nothing, stay on gtk2 (and therefore .net framework/mono -and good luck using any newer libraries targeting .net standard)
  2. Change to another UI toolkit (maui, qt, electron, ...). This would be a huge time sink
  3. Change clem UI to use gtk components. This would be a fair bit of work, but much less than the previous option
  4. Drop clem support and move to .net core/gtk3 anyway. clem could live on its own fork, running on .net framework/gtk2 indefinitely without receiving bugfixes and other updates from the main repo (unless someone were to manually port them)

From where I'm standing, the third option seems like the least bad option. Not entirely sure why you guys don't like gtk - yes there's a learning curve (as with anything) but I've found the documentation to be pretty good. If there are specific things that you guys find difficult, maybe we should add some help pages to the website.

@lie112
Copy link
Contributor

lie112 commented Nov 27, 2020

I am having a meeting with the CLEM team on Monday.

The problematic HTML visualisation in CLEM is not model critical, but a feature used by users new to modelling (and experts like me) to understand and check the complicated setup of their farming systems tree structure and highlight potential issues before running the simulation. If I had to chose an option right now with the least cost it would be to throw the current HTML to a text or PDF file for the user to view using the GTK PDF viewer widget (if the conversion from HTML to PDF is suitable and fast) or in external application. Depending upon the widget we may drop the instant descriptive summary feedback in the summary tab, and reduce the error reporting to TEXT or mark-up and allow external viewing of the complete model setup rather than the ability to summarise each model component. This would be in the hope that a near future UI that we chose will allow us to easily resume displaying the HTML with a transition to the .Net cross platform UI as developed.

I understand the desire to remain completely open source, but it might be worth considering some third party tools if/when we head down the MAUI/xamarin path in future as these would be licenced by the software and not required by the user. It is an investment in us not having to develop the UI components to provide the most professional feature packed experience our users are accustom to in other applications. I know the Syncfusion xamarin controls have export to excel in the grid component and they also have pretty good individual free licencing and are not prohibitively expensive and locked down like Telerik but as your aware multi-developer licencing can start to get expensive.

Anyway, we'll come up with the best solution for the short term while APSIM next gen shifts to .Net Core and look forward to the latest C# and Core coding conventions.

@jbrider
Copy link
Contributor

jbrider commented Nov 29, 2020

@hol353 You're using .netcore now - is there a huge overhead in continuing to have 2 branches for Models? I agree it's not preferred. I also agree that .netcore is where we want to be and is the highest priority.

I think we should organise a zoom call to discuss the short term and long term decisions. I am more concerned with the long term and how the short term decisions will affect that. The possible options mentioned are clear, and all have their issues.

Long term - is GTK the path we want to continue to follow in the long term? Right now the largest cross platform applications that I can think of - Slack, Discord, Twitch, VS Code are all using Html inside Electron and count their users in the millions. Does GTK have the same future? Electron wasn't available when we made the choice to use GTK - it was the best solution for us at the time - is that still the case?

There are more grid and tree controls available within HTML than there are in GTK. The first page of google search is all about different grid solutions for JS - GTK barely lists 1. Note: All of the excel like grid demos I looked at were not open source.
Some of them were perfect for what we are after but would require some resource investment to create similar functionality - which we have talked about for the grid in GTK as well.

Xamarin is now a mature technology - but is aimed at phones more than the desktop - evidenced by Microsoft's own choice for cross platform development in VSCode. I'm not sure that MAUI is going to be much different. I will admit to only knowing what Drew has told me about it though.

I believe we're committed to open source, so purchasing ui components is not going to work for us.

I'm currently involved in developing 4 projects that are web based, with possibly 2 others in the next 6 months - so I don't feel that GTK is a technology that I have time to invest in - probably the reverse of the position that the GTK users are in.

@hol353
Copy link
Contributor

hol353 commented Nov 29, 2020

Yep happy to chat via Zoom - set it up for this week or next (I'm on holidays after that). Include @hol430 and @hut104.

@jbrider
Copy link
Contributor

jbrider commented Nov 29, 2020

I'll setup a zoom call - looking at this Thursday to start with.

I meant to add a couple of html grid examples as well.
The last 2 in particular work very smoothly.
https://www.infragistics.com/products/ignite-ui-angular/angular/components/grid/excel-style-filtering
https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/index.htm#demos/jqxgrid/showcase.htm
https://fancygrid.com/samples/selection/selection
https://www.ag-grid.com/

@hol430
Copy link
Contributor

hol430 commented Jan 29, 2021

Closing this one. Current plan is to migrate to .net core/gtk3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Software An error in the interface or structure of the software
Projects
Development

No branches or pull requests

6 participants