Standard editing modes in python setEdit

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
adrianinsaval
Veteran
Posts: 5553
Joined: Thu Apr 05, 2018 5:15 pm

Standard editing modes in python setEdit

Post by adrianinsaval »

Hi guys! I didn't want to necrobump these threads since the mods say its better to create a new one
https://forum.freecadweb.org/viewtopic.php?t=31254
https://forum.freecadweb.org/viewtopic.php?t=21330

What is the current state of this? What is the correct way of doing it if it can be done at all. I couldn't find it in the documentation either, any hints would be appreciated.
wmayer wrote:
yorik wrote:
DeepSOIC wrote:
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Standard editing modes in python setEdit

Post by DeepSOIC »

raise NotImplementedError() is the official way of doing it, as far as I know.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Standard editing modes in python setEdit

Post by vocx »

adrianinsaval wrote: Thu May 07, 2020 7:27 pm ...What is the correct way of doing it if it can be done at all. ...
What is the correct way of doing what?

I thank you for linking to past threads, but exactly what do you want to do? Implement a new edit method, call the C++ parent's method?
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
adrianinsaval
Veteran
Posts: 5553
Joined: Thu Apr 05, 2018 5:15 pm

Re: Standard editing modes in python setEdit

Post by adrianinsaval »

vocx wrote: Fri May 08, 2020 4:59 am What is the correct way of doing what?

...call the C++ parent's method?
That's what I'm asking, sorry for not making it clear.
DeepSOIC wrote: Fri May 08, 2020 12:31 am raise NotImplementedError() is the official way of doing it, as far as I know.
Thanks. Is there documentation on what number corresponds to what mode? Do you know any example of doing it that I can look at?
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Standard editing modes in python setEdit

Post by wmayer »

The whole mechanism still isn't well designed because there too many different use cases that makes it difficult to cover everything with an easy and extendible design.
Thanks. Is there documentation on what number corresponds to what mode?
Inside ViewProvider.h you will find some basic edit modes:

Code: Select all

    enum EditMode {Default = 0,
                   Transform,
                   Cutting,
                   Color,
    };
The bad thing about this is that each view provider type that defines its own edit modes would extend this list. The downside is that each time you add a new mode the whole GUI part must be completely rebuilt which is a very time-consuming and annoying because it breaks the design rule that the core shouldn't know about implementation details of extension modules. And for the core system it's anyway not needed to know all possible edit modes.

Currently the vast majority of view providers either completely ignore the passed mode number or handle ViewProvider::Default (which is 0) and for all other cases delegate it to the sub-class.
Do you know any example of doing it that I can look at?
Search for the string "::setEdit(" in the code base to see how the different view providers handle it.
User avatar
adrianinsaval
Veteran
Posts: 5553
Joined: Thu Apr 05, 2018 5:15 pm

Re: Standard editing modes in python setEdit

Post by adrianinsaval »

DeepSOIC wrote: Fri May 08, 2020 12:31 am raise NotImplementedError() is the official way of doing it, as far as I know.
should this be added to the wiki? if so, were do you think is the best place?

Also: what value should setEdit return and in which case?
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Standard editing modes in python setEdit

Post by DeepSOIC »

adrianinsaval wrote: Mon May 11, 2020 2:43 am Also: what value should setEdit return and in which case?
True if editing mode is entered, False if editing mode is refused/canceled.
Post Reply