Gui: move class SelectionObserverPython to its own source files
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
#include "MainWindow.h"
|
||||
#include "MDIView.h"
|
||||
#include "SelectionFilter.h"
|
||||
#include "SelectionObserverPython.h"
|
||||
#include "Tree.h"
|
||||
#include "ViewProviderDocumentObject.h"
|
||||
|
||||
@@ -166,195 +167,6 @@ void SelectionObserver::detachSelection()
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
std::vector<SelectionObserverPython*> SelectionObserverPython::_instances;
|
||||
|
||||
SelectionObserverPython::SelectionObserverPython(const Py::Object& obj, ResolveMode resolve)
|
||||
: SelectionObserver(true, resolve), inst(obj)
|
||||
{
|
||||
#undef FC_PY_ELEMENT
|
||||
#define FC_PY_ELEMENT(_name) FC_PY_GetCallable(obj.ptr(),#_name,py_##_name);
|
||||
FC_PY_SEL_OBSERVER
|
||||
}
|
||||
|
||||
SelectionObserverPython::~SelectionObserverPython()
|
||||
{
|
||||
}
|
||||
|
||||
void SelectionObserverPython::addObserver(const Py::Object& obj, ResolveMode resolve)
|
||||
{
|
||||
_instances.push_back(new SelectionObserverPython(obj, resolve));
|
||||
}
|
||||
|
||||
void SelectionObserverPython::removeObserver(const Py::Object& obj)
|
||||
{
|
||||
SelectionObserverPython* obs=nullptr;
|
||||
for (std::vector<SelectionObserverPython*>::iterator it =
|
||||
_instances.begin(); it != _instances.end(); ++it) {
|
||||
if ((*it)->inst == obj) {
|
||||
obs = *it;
|
||||
_instances.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete obs;
|
||||
}
|
||||
|
||||
void SelectionObserverPython::onSelectionChanged(const SelectionChanges& msg)
|
||||
{
|
||||
switch (msg.Type)
|
||||
{
|
||||
case SelectionChanges::AddSelection:
|
||||
addSelection(msg);
|
||||
break;
|
||||
case SelectionChanges::RmvSelection:
|
||||
removeSelection(msg);
|
||||
break;
|
||||
case SelectionChanges::SetSelection:
|
||||
setSelection(msg);
|
||||
break;
|
||||
case SelectionChanges::ClrSelection:
|
||||
clearSelection(msg);
|
||||
break;
|
||||
case SelectionChanges::SetPreselect:
|
||||
setPreselection(msg);
|
||||
break;
|
||||
case SelectionChanges::RmvPreselect:
|
||||
removePreselection(msg);
|
||||
break;
|
||||
case SelectionChanges::PickedListChanged:
|
||||
pickedListChanged();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SelectionObserverPython::pickedListChanged()
|
||||
{
|
||||
if(py_pickedListChanged.isNone())
|
||||
return;
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Callable(py_pickedListChanged).apply(Py::Tuple());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
void SelectionObserverPython::addSelection(const SelectionChanges& msg)
|
||||
{
|
||||
if(py_addSelection.isNone())
|
||||
return;
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(4);
|
||||
args.setItem(0, Py::String(msg.pDocName ? msg.pDocName : ""));
|
||||
args.setItem(1, Py::String(msg.pObjectName ? msg.pObjectName : ""));
|
||||
args.setItem(2, Py::String(msg.pSubName ? msg.pSubName : ""));
|
||||
Py::Tuple tuple(3);
|
||||
tuple[0] = Py::Float(msg.x);
|
||||
tuple[1] = Py::Float(msg.y);
|
||||
tuple[2] = Py::Float(msg.z);
|
||||
args.setItem(3, tuple);
|
||||
Base::pyCall(py_addSelection.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
void SelectionObserverPython::removeSelection(const SelectionChanges& msg)
|
||||
{
|
||||
if(py_removeSelection.isNone())
|
||||
return;
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(3);
|
||||
args.setItem(0, Py::String(msg.pDocName ? msg.pDocName : ""));
|
||||
args.setItem(1, Py::String(msg.pObjectName ? msg.pObjectName : ""));
|
||||
args.setItem(2, Py::String(msg.pSubName ? msg.pSubName : ""));
|
||||
Base::pyCall(py_removeSelection.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
void SelectionObserverPython::setSelection(const SelectionChanges& msg)
|
||||
{
|
||||
if(py_setSelection.isNone())
|
||||
return;
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::String(msg.pDocName ? msg.pDocName : ""));
|
||||
Base::pyCall(py_setSelection.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
void SelectionObserverPython::clearSelection(const SelectionChanges& msg)
|
||||
{
|
||||
if(py_clearSelection.isNone())
|
||||
return;
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::String(msg.pDocName ? msg.pDocName : ""));
|
||||
Base::pyCall(py_clearSelection.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
void SelectionObserverPython::setPreselection(const SelectionChanges& msg)
|
||||
{
|
||||
if(py_setPreselection.isNone())
|
||||
return;
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(3);
|
||||
args.setItem(0, Py::String(msg.pDocName ? msg.pDocName : ""));
|
||||
args.setItem(1, Py::String(msg.pObjectName ? msg.pObjectName : ""));
|
||||
args.setItem(2, Py::String(msg.pSubName ? msg.pSubName : ""));
|
||||
Base::pyCall(py_setPreselection.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
void SelectionObserverPython::removePreselection(const SelectionChanges& msg)
|
||||
{
|
||||
if(py_removePreselection.isNone())
|
||||
return;
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(3);
|
||||
args.setItem(0, Py::String(msg.pDocName ? msg.pDocName : ""));
|
||||
args.setItem(1, Py::String(msg.pObjectName ? msg.pObjectName : ""));
|
||||
args.setItem(2, Py::String(msg.pSubName ? msg.pSubName : ""));
|
||||
Base::pyCall(py_removePreselection.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
bool SelectionSingleton::hasSelection() const
|
||||
{
|
||||
return !_SelList.empty();
|
||||
|
||||
Reference in New Issue
Block a user