Active object manager for the Viewer
This commit is contained in:
parent
240f2f7428
commit
16ab7f710b
46
src/Gui/ActiveObjectList.cpp
Normal file
46
src/Gui/ActiveObjectList.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/***************************************************************************
|
||||
* (c) Jürgen Riegel (juergen.riegel@web.de) 2014 *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Library General Public License (LGPL) *
|
||||
* as published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* for detail see the LICENCE text file. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with FreeCAD; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
* Juergen Riegel 2014 *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
|
||||
#endif
|
||||
|
||||
#include "ActiveObjectList.h"
|
||||
|
||||
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
|
||||
void Gui::ActiveObjectList::setObject(App::DocumentObject* obj, const char* name)
|
||||
{
|
||||
_ObjectMap[name] = obj;
|
||||
}
|
||||
|
||||
bool Gui::ActiveObjectList::hasObject(const char*name)
|
||||
{
|
||||
return _ObjectMap.find(name) != _ObjectMap.end();
|
||||
}
|
72
src/Gui/ActiveObjectList.h
Normal file
72
src/Gui/ActiveObjectList.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
/***************************************************************************
|
||||
* (c) Jürgen Riegel (juergen.riegel@web.de) 2014 *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Library General Public License (LGPL) *
|
||||
* as published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* for detail see the LICENCE text file. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with FreeCAD; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
* Juergen Riegel 2014 *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef GUI_ActiveObjectList_H
|
||||
#define GUI_ActiveObjectList_H
|
||||
|
||||
#include <map>
|
||||
namespace App {
|
||||
class DocumentObject;
|
||||
}
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
|
||||
class Document;
|
||||
|
||||
/** List of active or special objects
|
||||
* This class holds a list of objects with a special name.
|
||||
* Its mainly used to points to something like the active Body or Part in a edit session.
|
||||
* The class is used the viewer (editor) of a document.
|
||||
* @see Gui::MDIViewer
|
||||
* @author Jürgen Riegel
|
||||
*/
|
||||
class GuiExport ActiveObjectList
|
||||
{
|
||||
|
||||
public:
|
||||
template<class T> T* getObject(const char*);
|
||||
void setObject(App::DocumentObject*, const char*);
|
||||
bool hasObject(const char*);
|
||||
protected:
|
||||
std::map<std::string, App::DocumentObject*> _ObjectMap;
|
||||
|
||||
|
||||
};
|
||||
|
||||
template<class T>
|
||||
T* Gui::ActiveObjectList::getObject(const char* name)
|
||||
{
|
||||
auto pos = _ObjectMap.find(name);
|
||||
if (pos == _ObjectMap.end())
|
||||
return 0;
|
||||
else
|
||||
return dynamic_cast<T*>(pos->second);
|
||||
}
|
||||
|
||||
|
||||
} //namespace Gui
|
||||
|
||||
#endif
|
|
@ -232,6 +232,7 @@ public:
|
|||
|
||||
PYFUNCDEF_S(sActiveDocument);
|
||||
PYFUNCDEF_S(sSetActiveDocument);
|
||||
PYFUNCDEF_S(sActiveView);
|
||||
PYFUNCDEF_S(sGetDocument);
|
||||
|
||||
PYFUNCDEF_S(sDoCommand);
|
||||
|
|
|
@ -145,6 +145,9 @@ PyMethodDef Application::Methods[] = {
|
|||
{"setActiveDocument", (PyCFunction) Application::sSetActiveDocument,1,
|
||||
"setActiveDocument(string or App.Document) -> None\n\n"
|
||||
"Activate the specified document"},
|
||||
{ "activeView", (PyCFunction)Application::sActiveView, 1,
|
||||
"activeView() -> object or None\n\n"
|
||||
"Return the active view of the active document or None if no one exists" },
|
||||
{ "getDocument", (PyCFunction)Application::sGetDocument, 1,
|
||||
"getDocument(string) -> object\n\n"
|
||||
"Get a document by its name"},
|
||||
|
@ -175,11 +178,28 @@ PyObject* Gui::Application::sActiveDocument(PyObject * /*self*/, PyObject *args,
|
|||
Document *pcDoc = Instance->activeDocument();
|
||||
if (pcDoc) {
|
||||
return pcDoc->getPyObject();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Py_Return;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* Gui::Application::sActiveView(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
|
||||
Document *pcDoc = Instance->activeDocument();
|
||||
if (pcDoc) {
|
||||
Gui::MDIView *pcView = pcDoc->getActiveView();
|
||||
if (pcView)
|
||||
// already incremented in getPyObject().
|
||||
return pcView->getPyObject();
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* Gui::Application::sSetActiveDocument(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
||||
{
|
||||
Document *pcDoc = 0;
|
||||
|
|
|
@ -933,10 +933,12 @@ SOURCE_GROUP("Widget" FILES ${Widget_SRCS})
|
|||
SET(View_CPP_SRCS
|
||||
MDIView.cpp
|
||||
GraphvizView.cpp
|
||||
ActiveObjectList.cpp
|
||||
)
|
||||
SET(View_HPP_SRCS
|
||||
MDIView.h
|
||||
GraphvizView.h
|
||||
ActiveObjectList.h
|
||||
)
|
||||
SET(View_SRCS
|
||||
${View_CPP_SRCS}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "View.h"
|
||||
#include <QMainWindow>
|
||||
#include "ActiveObjectList.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QPrinter;
|
||||
|
@ -108,6 +109,8 @@ public:
|
|||
virtual void setCurrentViewMode(ViewMode mode);
|
||||
ViewMode currentViewMode() const { return currentMode; }
|
||||
|
||||
ActiveObjectList ActiveObjects;
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void setOverrideCursor(const QCursor&);
|
||||
virtual void restoreOverrideCursor();
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/DocumentObjectPy.h>
|
||||
#include <CXX/Objects.hxx>
|
||||
|
||||
using namespace Gui;
|
||||
|
@ -224,6 +225,10 @@ Py::Object View3DInventorPy::getattr(const char * attr)
|
|||
throw Py::RuntimeError(s_out.str());
|
||||
}
|
||||
else {
|
||||
App::DocumentObject *docObj = _view->ActiveObjects.getObject<App::DocumentObject>(attr);
|
||||
if (docObj){
|
||||
return Py::Object(docObj->getPyObject());
|
||||
}else{
|
||||
Py::Object obj = Py::PythonExtension<View3DInventorPy>::getattr(attr);
|
||||
if (PyCFunction_Check(obj.ptr())) {
|
||||
PyCFunctionObject* op = reinterpret_cast<PyCFunctionObject*>(obj.ptr());
|
||||
|
@ -234,6 +239,7 @@ Py::Object View3DInventorPy::getattr(const char * attr)
|
|||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int View3DInventorPy::setattr(const char * attr, const Py::Object & value)
|
||||
{
|
||||
|
@ -2160,3 +2166,15 @@ Py::Object View3DInventorPy::removeDraggerCallback(const Py::Tuple& args)
|
|||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object View3DInventorPy::setActiveObject(const Py::Tuple& args)
|
||||
{
|
||||
App::DocumentObjectPy* docObject = 0;
|
||||
char* name;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "sO!", &name, &App::DocumentObjectPy::Type, &docObject))
|
||||
throw Py::Exception();
|
||||
|
||||
if (docObject){
|
||||
_view->ActiveObjects.setObject(docObject->getDocumentObjectPtr(), name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@ public:
|
|||
Py::Object hasAxisCross(const Py::Tuple&);
|
||||
Py::Object addDraggerCallback(const Py::Tuple&);
|
||||
Py::Object removeDraggerCallback(const Py::Tuple&);
|
||||
Py::Object setActiveObject(const Py::Tuple&);
|
||||
|
||||
private:
|
||||
static void eventCallback(void * ud, SoEventCallback * n);
|
||||
|
|
Loading…
Reference in New Issue
Block a user