Jump to content
Ultimaker Community of 3D Printing Experts

Plugin development: hide a new View from the View Selector in Preview Stage


Tyronnosaurus
 Share

Recommended Posts

Posted (edited) · Plugin development: hide a new View from the View Selector in Preview Stage

Hello there.

 

In default Cura, there are (at least) 3 Views: Solid, Simulation and X-Ray.

In the Preview Stage, there is a View Selector (a dropdown menu) that lets you choose between Simulation (AKA Layer) and X-Ray views. The Solid View does not appear on the list. I would like to know how Cura selects which views appear/don't appear in this list.

 

The only relevant difference I've found is that SolidView inherits from UM.View.View, while SimulationView and XRayView inherit from cura.CuraView.

 

The reason I need this is that in the plugin I'm developing, I use 2 new views and I don't want them appearing here:

 

PreviewStageViewSelector.png.79075aa2f4d3f48b3cd507d1c9ed32f8.png

 

If hiding my new Views is not possible, I'd like to at least make them appear last. When registering a View, there is a 'Weight' parameter which I guess dictates the load order, but I haven't managed to reorder them with it.

 

Thanks.

 

Edited by Tyronnosaurus
  • Like 1
Link to post
Share on other sites

Posted · Plugin development: hide a new View from the View Selector in Preview Stage

You can hide them. This is what my plugin does for a view that needs to be hidden from the users.

This is part of the getMetadata() of the root init of the plugin

"view":
{
    "name": "Chop",
    "view_panel": "",
    "visible": False
}
  • Like 1
Link to post
Share on other sites

  • 2 weeks later...
Posted · Plugin development: hide a new View from the View Selector in Preview Stage

Hello nallath. Thanks for answering. I've tried to do as you say, but I think my case is a little more complicated because I use 2 views in my plugin (as per your recommendation in another thread) or because of some previous undetected mistake I did.

 

In your ModelCutter plugin, the only View (ChopperView) has no self.name assigned in its __init__(). Therefore, Cura automatically names the View as "ModelCutter" (the name of the plugin).

 

In my plugin, I have 2 views with individual self.name values assigned (i.e. "SetupView" & "ResultsView"). Note that when I do this, they still get automatically appended the plugin's name (i.e. "FemPlugin_SetupView" & "FemPlugin_ResultsView").

 

The moment I open the Preview stage, I get a few errors stating that metadata (such as "view_panel" or "visible") could not be loaded:

DEBUG - [MainThread] UM.Controller.setActiveStage [180]: Setting active stage to PreviewStage
WARNING - [MainThread] UM.PluginRegistry._populateMetaData [778]: Could not find plugin FemPlugin_SetupView
WARNING - [MainThread] UM.PluginRegistry._populateMetaData [778]: Could not find plugin FemPlugin_ResultsView
DEBUG - [MainThread] UM.Controller.setActiveView [108]: Setting active view to SimulationView
INFO - [MainThread] STLReader.STLReader.load_file [53]: Using NumPy-STL to load STL data.
DEBUG - [MainThread] UM.Mesh.MeshData.calculateNormalsFromVertices [558]: Calculating normals took 0.00099945068359375 seconds
DEBUG - [MainThread] STLReader.STLReader._read [105]: Loaded a mesh with 12612 vertices
DEBUG - [MainThread] UM.View.GL.ShaderProgram.load [60]: Loading [C:\Program Files\Ultimaker Cura 4.11.0\plugins\SimulationView\simulationview_composite.shader]...
WARNING - [MainThread] UM.PluginRegistry._populateMetaData [778]: Could not find plugin FemPlugin_SetupView
WARNING - [MainThread] UM.PluginRegistry._populateMetaData [778]: Could not find plugin FemPlugin_ResultsView

 

  • I've tried to pinpoint how is _populateMetaData() being called in Cura and Uranium's source code, with no success.
  • I also do not understand why it says "Could not find plugin" yet uses the View's name rather than the plugin's name.
  • Changing to Prepare or Monitor stages works fine and does not trigger these errors.
  • Since it fails to load the metadata, it doesn't load the "visible" values you told me about in your post above and therefore the dropdown still shows the unwanted views.

Many thanks for any help.

 

  • Link to post
    Share on other sites

    Posted · Plugin development: hide a new View from the View Selector in Preview Stage

     

    18 hours ago, Tyronnosaurus said:

    I've tried to pinpoint how is _populateMetaData() being called in Cura and Uranium's source code, with no success

    _populateMetadata is being called in the pluginRegistry. It's used in "getMetaData" and in "loadPlugin"
     

    19 hours ago, Tyronnosaurus said:

    I also do not understand why it says "Could not find plugin" yet uses the View's name rather than the plugin's name


    I don't know what you did in your code, so i can't really help out entirely with what is going on. If you have a public repo somewhere, I could have a look.

    You could have a look at the https://github.com/tetonsim/is-cura-ui/blob/master/SmartSlicePlugin/ if i recall correctly, they also use multiple views.

     

    • Like 1
    Link to post
    Share on other sites

    Posted (edited) · Plugin development: hide a new View from the View Selector in Preview Stage
    Quote

    You could have a look at the https://github.com/tetonsim/is-cura-ui/blob/master/SmartSlicePlugin/ if i recall correctly, they also use multiple views.

    I can only find one view. Maybe they had 2 in the past but I haven't found anything in past versions.

     

     

    Quote

    _populateMetadata is being called in the pluginRegistry. It's used in "getMetaData" and in "loadPlugin"

    I saw this in Uranium's source code, but still wasn't sure if it was getMetadata() or loadPlugin() that was doing the calling, and how was plugin_id generated in _populateMetaData(self, plugin_id: str).

     

    In any case, I've found something that may be a possible bug:

    I managed to run Cura from source, and added some code in Uranium to see all the stack of function calls when _populateMetaData() is called, from deepest to highest:

    'C:\dev\Uranium\UM\PluginRegistry.py',              L776, _populateMetaData()
    'C:\dev\Uranium\UM\PluginRegistry.py',              L273, getMetaData()
    'C:\dev\Uranium\UM\Qt\Bindings\ViewModel.py',       L41,  _update()
    'C:\dev\Uranium\UM\Signal.py',                      L332, __performEmit()
    'C:\dev\Uranium\UM\Signal.py',                      L219, emit()
    'C:\dev\Uranium\UM\Controller.py',                  L118, setActiveView()
    'C:\dev\Uranium\UM\Qt\Bindings\ControllerProxy.py', L41,  setActiveView()
    'C:\dev\Uranium\UM\Qt\Bindings\ControllerProxy.py', L116, _onActiveStageChanged()
    etc

     

    The 3rd deepest function is ViewModel.update().

    Note how it only accounts for Views that have been automatically assigned the same name as the plugin. If a view is named as PluginName_ViewName, it will not be found because there's no such plugin by that name:

    views = self._controller.getAllViews()
    ...
    for view_id in views:
      view_meta_data = PluginRegistry.getInstance().getMetaData(view_id).get("view", {})

     

    Edit: if I change it like this, everything works:

    views = self._controller.getAllViews()
    ...
    for view_id in views:
      plugin_name = view_id.split('_')[0]
      view_meta_data = PluginRegistry.getInstance().getMetaData(plugin_name).get("view", {})
      if isinstance(view_meta_data,list):
        continue  #Skip unsupported case where View comes from a plugin with multiple views

     

    nallath, do you think I should report the issue on Github? Nvm, posted it.

     

    In the meantime, do you think there's any way to bypass this problem with code in the plugin, rather than modifying Uranium?

     

    Edited by Tyronnosaurus
    Posted issue on Github
  • Link to post
    Share on other sites

    • 2 weeks later...
    Posted · Plugin development: hide a new View from the View Selector in Preview Stage

    To anyone also trying to develop a plugin with 2 views:

     

    nallath and I discovered and fixed a small bug in Uranium that caused the previous problems.

    Since Cura 4.12 beta is already out, I guess the solution is to wait for Cura 4.13 (unless the fix is included in the release version of 4.12).

     

    With this fix, Views can be hidden from the dropdown in Preview Stage with the 'visible' metadata as nallath said in the 1st answer.

    • Thanks 1
    Link to post
    Share on other sites

    Posted · Plugin development: hide a new View from the View Selector in Preview Stage
    17 hours ago, Tyronnosaurus said:

    To anyone also trying to develop a plugin with 2 views:

     

    nallath and I discovered and fixed a small bug in Uranium that caused the previous problems.

    Since Cura 4.12 beta is already out, I guess the solution is to wait for Cura 4.13 (unless the fix is included in the release version of 4.12).

     

    With this fix, Views can be hidden from the dropdown in Preview Stage with the 'visible' metadata as nallath said in the 1st answer.

    It's not in 4.12. And again thanks for making the PR 🙂

  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    • Our picks

      • Ultimaker showcase | April 2022 | 4pm CEST | 10am EDT
        I'm excited because I've personally produced this showcase event, so if you are curious what else I'm up to nowadays, come check it out and say hi in the chat! It would mean a lot! 
          • Thanks
          • Like
        • 4 replies
      • New here? Get ahead with a free onboarding course
        Hi,
         
        Often getting started is the most difficult part of any process. A good start sets you up for success and saves you time and energy that could be spent elsewhere. That is why we have a onboarding course ready for
        Ultimaker S5 Pro Bundle, Ultimaker S5, Ultimaker S3 Ultimaker 2+ Connect.   
        They're ready for you on the Ultimaker Academy platform. All you need to do to gain access is to register your product to gain free access. 
        Ready? Register your product here in just 60 seconds.
          • Like
        • 11 replies
    ×
    ×
    • Create New...