diff --git a/src/Gui/SelectionObject.cpp b/src/Gui/SelectionObject.cpp index f055e7d8db32..c5fbedc56682 100644 --- a/src/Gui/SelectionObject.cpp +++ b/src/Gui/SelectionObject.cpp @@ -49,9 +49,9 @@ SelectionObject::~SelectionObject() const App::DocumentObject * SelectionObject::getObject(void) const { - if (DocName != "") { + if (!DocName.empty()) { App::Document *doc = App::GetApplication().getDocument(DocName.c_str()); - if (doc && FeatName != "") + if (doc && !FeatName.empty()) return doc->getObject(FeatName.c_str()); } return 0; @@ -59,9 +59,9 @@ const App::DocumentObject * SelectionObject::getObject(void) const App::DocumentObject * SelectionObject::getObject(void) { - if (DocName != "") { + if (!DocName.empty()) { App::Document *doc = App::GetApplication().getDocument(DocName.c_str()); - if (doc && FeatName != "") + if (doc && !FeatName.empty()) return doc->getObject(FeatName.c_str()); } return 0; @@ -93,9 +93,7 @@ std::string SelectionObject::getAsPropertyLinkSubString(void)const return buf; } - PyObject* SelectionObject::getPyObject() { return new SelectionObjectPy(new SelectionObject(*this)); } - diff --git a/src/Gui/SelectionObject.h b/src/Gui/SelectionObject.h index 5c871594c618..f4572533716c 100644 --- a/src/Gui/SelectionObject.h +++ b/src/Gui/SelectionObject.h @@ -58,8 +58,10 @@ class GuiExport SelectionObject : public Base::BaseClass inline const char* getDocName(void) const { return DocName.c_str(); } /// get the name of the Document Object of this SelectionObject inline const char* getFeatName(void) const { return FeatName.c_str(); } - /// get the Type of the selcted Object + /// get the Type of the selected Object inline const char* getTypeName(void) const { return TypeName.c_str(); } + /// get the selection points + inline const std::vector getSubPoints(void) const { return SelPoses; } /// returns the selected DocumentObject or NULL if the object is already deleted const App::DocumentObject *getObject(void) const; diff --git a/src/Gui/SelectionObjectPy.xml b/src/Gui/SelectionObjectPy.xml index 92f3f3581340..9014e495aaf6 100644 --- a/src/Gui/SelectionObjectPy.xml +++ b/src/Gui/SelectionObjectPy.xml @@ -19,7 +19,7 @@ Remove this selection item from the selection. This object becomes invalid. - + Test for a certain father class. @@ -34,7 +34,7 @@ Name of the selected sub-element if any - + @@ -42,7 +42,13 @@ - + + + Type name of the selected object + + + + Name of the document of the selected object @@ -64,9 +70,15 @@ Selected sub-element, if any - + - + + + Selection points + + + + Selected sub-element, if any diff --git a/src/Gui/SelectionObjectPyImp.cpp b/src/Gui/SelectionObjectPyImp.cpp index 34200b241691..f17cfc65ebab 100644 --- a/src/Gui/SelectionObjectPyImp.cpp +++ b/src/Gui/SelectionObjectPyImp.cpp @@ -22,10 +22,12 @@ #include "PreCompiled.h" -#include "Gui/SelectionObject.h" -#include "App/Document.h" -#include "App/DocumentObject.h" -#include "App/Application.h" +#include "SelectionObject.h" +#include "Selection.h" +#include +#include +#include +#include // inclusion of the generated files (generated out of SelectionObjectPy.xml) #include "SelectionObjectPy.h" @@ -39,49 +41,56 @@ std::string SelectionObjectPy::representation(void) const return ""; } - - -PyObject* SelectionObjectPy::remove(PyObject * /*args*/) +PyObject* SelectionObjectPy::remove(PyObject * args) { - PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented"); - return 0; + if (!PyArg_ParseTuple(args, "")) + return 0; + Selection().rmvSelection(getSelectionObjectPtr()->getDocName(), + getSelectionObjectPtr()->getFeatName()); + Py_Return; } -PyObject* SelectionObjectPy::isA(PyObject * /*args*/) +PyObject* SelectionObjectPy::isObjectTypeOf(PyObject * args) { - PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented"); - return 0; + char* type; + if (!PyArg_ParseTuple(args, "s", &type)) + return 0; + Base::Type id = Base::Type::fromName(type); + if (id.isBad()) { + PyErr_SetString(PyExc_TypeError, "Not a valid type"); + return 0; + } + + bool ok = getSelectionObjectPtr()->isObjectTypeOf(id); + + return Py_BuildValue("O", (ok ? Py_True : Py_False)); } - - Py::String SelectionObjectPy::getObjectName(void) const { return Py::String(getSelectionObjectPtr()->getFeatName()); } -Py::List SelectionObjectPy::getSubElementNames(void) const +Py::Tuple SelectionObjectPy::getSubElementNames(void) const { - Py::List temp; std::vector objs = getSelectionObjectPtr()->getSubNames(); + Py::Tuple temp(objs.size()); + Py::sequence_index_type index = 0; for(std::vector::const_iterator it= objs.begin();it!=objs.end();++it) - temp.append(Py::String(*it)); + temp.setItem(index++, Py::String(*it)); return temp; } Py::String SelectionObjectPy::getFullName(void) const { - std::string buf; - //buf = getSelectionObjectPtr()->getDocName(); - //buf += "."; - //buf += getSelectionObjectPtr()->getFeatName(); - //if(getSelectionObjectPtr()->getSubName()){ - // buf += "."; - // buf += getSelectionObjectPtr()->getSubName(); - //} - return Py::String(buf.c_str()); + return Py::String(getSelectionObjectPtr()->getAsPropertyLinkSubString()); +} + +Py::String SelectionObjectPy::getTypeName(void) const +{ + return Py::String(getSelectionObjectPtr()->getTypeName()); } Py::String SelectionObjectPy::getDocumentName(void) const @@ -99,12 +108,15 @@ Py::Object SelectionObjectPy::getObject(void) const return Py::Object(getSelectionObjectPtr()->getObject()->getPyObject(), true); } -Py::List SelectionObjectPy::getSubObjects(void) const +Py::Tuple SelectionObjectPy::getSubObjects(void) const { - Py::List temp; std::vector objs = getSelectionObjectPtr()->getObject()->getPySubObjects(getSelectionObjectPtr()->getSubNames()); + + Py::Tuple temp(objs.size()); + Py::sequence_index_type index = 0; for(std::vector::const_iterator it= objs.begin();it!=objs.end();++it) - temp.append(Py::Object(*it,true)); + temp.setItem(index++, Py::asObject(*it)); + return temp; } @@ -113,6 +125,18 @@ Py::Boolean SelectionObjectPy::getHasSubObjects(void) const return Py::Boolean(getSelectionObjectPtr()->hasSubNames()); } +Py::Tuple SelectionObjectPy::getSubPoints(void) const +{ + const std::vector& points = getSelectionObjectPtr()->getSubPoints(); + + Py::Tuple temp(points.size()); + Py::sequence_index_type index = 0; + for(std::vector::const_iterator it= points.begin();it!=points.end();++it) + temp.setItem(index++, Py::Vector(*it)); + + return temp; +} + PyObject *SelectionObjectPy::getCustomAttributes(const char* /*attr*/) const { return 0; @@ -122,5 +146,3 @@ int SelectionObjectPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj { return 0; } - - diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index 75fd7b24ae9d..782aaaee5047 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -48,6 +48,7 @@ #include "propertyeditor/PropertyItem.h" #include "NavigationStyle.h" #include "Flag.h" +#include "SelectionObject.h" using namespace Gui; using namespace Gui::Inventor; @@ -140,6 +141,8 @@ void Gui::SoFCDB::init() GLGraphicsItem ::init(); GLFlagWindow ::init(); + SelectionObject ::init(); + qRegisterMetaType("Base::Vector3f"); qRegisterMetaType("Base::Vector3d"); qRegisterMetaType("Base::Quantity");