Gui: Provide ViewProviderFeaturePython selection callbacks

Adds support for Python-based selection callbacks to
`ViewProviderFeaturePython` objects.

It follows the same conventions as `SelectionObserverPython`, follows an
example:

```python
    def setPreselection(self, document, object, element):
        print("setPreselection: %s.%s.%s"%(document, object, element))

    def removePreselection(self, document, object, element):
print("removePreselection: %s.%s.%s"%(document, object,
element))

    def addSelection(self, document, object, element, position):
print("addSelection: %s.%s.%s at %s"%(document, object, element,
str(position)))

    def removeSelection(self,document, object, element):
        print("removeSelection: %s.%s.%s"%(document, object, element))

    def setSelection(self,doc):
        sel = FreeCADGui.Selection.getSelection(doc)
        print("setSelection: %s"%sel)

    def clearSelection(self,doc):
        print("clearSelection\n")
```
This commit is contained in:
tritao
2025-01-15 21:05:07 +00:00
parent 10ad4b7e15
commit ea80310642
6 changed files with 84 additions and 8 deletions

View File

@@ -26,17 +26,19 @@
#include <App/AutoTransaction.h>
#include <App/PropertyPythonObject.h>
#include <App/FeaturePython.h>
#include <Gui/Selection/SelectionObserverPython.h>
#include "ViewProviderGeometryObject.h"
#include "Document.h"
class SoSensor;
class SoDragger;
class SoNode;
namespace Gui {
class SelectionChanges;
class GuiExport ViewProviderFeaturePythonImp
{
public:
@@ -55,6 +57,7 @@ public:
QIcon getIcon() const;
bool claimChildren(std::vector<App::DocumentObject*>&) const;
ValueT useNewSelectionModel() const;
void onSelectionChanged(const SelectionChanges&);
ValueT getElementPicked(const SoPickedPoint *pp, std::string &subname) const;
bool getElement(const SoDetail *det, std::string &) const;
bool getDetail(const char*, SoDetail *&det) const;
@@ -130,6 +133,7 @@ public:
private:
ViewProviderDocumentObject* object;
App::PropertyPythonObject &Proxy;
SelectionObserverPythonHandler selectionObserver;
bool has__object__{false};
#define FC_PY_VIEW_OBJECT \
@@ -253,6 +257,10 @@ public:
return ViewProviderT::useNewSelectionModel();
}
}
/// called when the selection changes for the view provider
void onSelectionChanged(const SelectionChanges& changes) override {
return imp->onSelectionChanged(changes);
}
bool getElementPicked(const SoPickedPoint *pp, std::string &subname) const override {
auto ret = imp->getElementPicked(pp,subname);
if(ret == ViewProviderFeaturePythonImp::NotImplemented)