Jump to content
UltiMaker Community of 3D Printing Experts

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


Tyronnosaurus

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
    • Our picks

      • UltiMaker Cura 5.3 stable released
        In this stable release, Cura 5.3 achieves yet another huge leap forward in 3D printing thanks to material interlocking! As well as introducing an expanded recommended print settings menu and lots of print quality improvements. Not to mention, a whole bunch of new printer profiles for non-UltiMaker printers!
          • Thanks
        • 21 replies
      • Here it is. The new UltiMaker S7
        The UltiMaker S7 is built on the success of the UltiMaker S5 and its design decisions were heavily based on feedback from customers.
         
         
        So what’s new?
        The obvious change is the S7’s height. It now includes an integrated Air Manager. This filters the exhaust air of every print and also improves build temperature stability. To further enclose the build chamber the S7 only has one magnetically latched door.
         
        The build stack has also been completely redesigned. A PEI-coated flexible steel build plate makes a big difference to productivity. Not only do you not need tools to pop a printed part off. But we also don’t recommend using or adhesion structures for UltiMaker materials (except PC, because...it’s PC). Along with that, 4 pins and 25 magnets make it easy to replace the flex plate perfectly – even with one hand.
         
        The re-engineered print head has an inductive sensor which reduces noise when probing the build plate. This effectively makes it much harder to not achieve a perfect first layer, improving overall print success. We also reversed the front fan direction (fewer plastic hairs, less maintenance), made the print core door magnets stronger, and add a sensor that helps avoid flooding.
         

         
        The UltiMaker S7 also includes quality of life improvements:
        Reliable bed tilt compensation (no more thumbscrews) 2.4 and 5 GHz Wi-Fi A 1080p camera (mounted higher for a better view) Compatibility with 280+ Marketplace materials Compatibility with S5 project files (no reslicing needed) And a whole lot more  
        Curious to see the S7 in action?
        We’re hosting a free tech demo on February 7.
        It will be live and you can ask any questions to our CTO, Miguel Calvo.
        Register here for the Webinar
          • Like
        • 18 replies
      • UltiMaker Cura Alpha 🎄 Tree Support Spotlight 🎄
        Are you a fan of tree support, but dislike the removal process and the amount of filament it uses? Then we would like to invite you to try this special release of UltiMaker Cura. Brought to you by our special community contributor @thomasrahm
         
        We generated a special version of Cura 5.2 called 5.3.0 Alpha + Xmas. The only changes we introduced compared to UltiMaker Cura 5.2.1 are those which are needed for the new supports. So keep in mind, this is not a sneak peek for Cura 5.3 (there are some really cool new features coming up) but a spotlight release highlighting this new version of tree supports.  
          • Like
        • 22 replies
    ×
    ×
    • Create New...