add method to activate 3d view when setting active object list
This commit is contained in:
@@ -279,15 +279,6 @@ struct PyMethodDef FreeCADGui_methods[] = {
|
||||
{NULL, NULL, 0, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
||||
Gui::MDIView* Application::activeView(void) const
|
||||
{
|
||||
if (activeDocument())
|
||||
return activeDocument()->getActiveView();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
Application::Application(bool GUIenabled)
|
||||
@@ -812,6 +803,37 @@ bool Application::sendHasMsgToActiveView(const char* pMsg)
|
||||
return pView ? pView->onHasMsg(pMsg) : false;
|
||||
}
|
||||
|
||||
Gui::MDIView* Application::activeView(void) const
|
||||
{
|
||||
if (activeDocument())
|
||||
return activeDocument()->getActiveView();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Application::activateView
|
||||
* Activates a view of the given type of the active document.
|
||||
* If a view of this type doesn't exist and \a create is true
|
||||
* a new view of this type will be created.
|
||||
* @param type
|
||||
* @param create
|
||||
*/
|
||||
void Application::activateView(const Base::Type& type, bool create)
|
||||
{
|
||||
Document* doc = activeDocument();
|
||||
if (doc) {
|
||||
MDIView* mdiView = doc->getActiveView();
|
||||
if (mdiView && mdiView->isDerivedFrom(type))
|
||||
return;
|
||||
std::list<MDIView*> mdiViews = doc->getMDIViewsOfType(type);
|
||||
if (!mdiViews.empty())
|
||||
doc->setActiveWindow(mdiViews.back());
|
||||
else if (create)
|
||||
doc->createView(type);
|
||||
}
|
||||
}
|
||||
|
||||
/// Getter for the active view
|
||||
Gui::Document* Application::activeDocument(void) const
|
||||
{
|
||||
|
||||
@@ -149,6 +149,8 @@ public:
|
||||
Gui::Document* getDocument(const App::Document* pDoc) const;
|
||||
/// Getter for the active view of the active document or null
|
||||
Gui::MDIView* activeView(void) const;
|
||||
/// Activate a view of the given type of the active document
|
||||
void activateView(const Base::Type&, bool create=false);
|
||||
/// Shows the associated view provider of the given object
|
||||
void showViewProvider(const App::DocumentObject*);
|
||||
/// Hides the associated view provider of the given object
|
||||
@@ -237,6 +239,7 @@ public:
|
||||
static PyObject* sActiveDocument (PyObject *self,PyObject *args);
|
||||
static PyObject* sSetActiveDocument (PyObject *self,PyObject *args);
|
||||
static PyObject* sActiveView (PyObject *self,PyObject *args);
|
||||
static PyObject* sActivateView (PyObject *self,PyObject *args);
|
||||
static PyObject* sGetDocument (PyObject *self,PyObject *args);
|
||||
|
||||
static PyObject* sDoCommand (PyObject *self,PyObject *args);
|
||||
|
||||
@@ -161,6 +161,9 @@ PyMethodDef Application::Methods[] = {
|
||||
{"activeView", (PyCFunction)Application::sActiveView, METH_VARARGS,
|
||||
"activeView() -> object or None\n\n"
|
||||
"Return the active view of the active document or None if no one exists"},
|
||||
{"activateView", (PyCFunction)Application::sActivateView, METH_VARARGS,
|
||||
"activateView(type)\n\n"
|
||||
"Activate a view of the given type of the active document"},
|
||||
{"getDocument", (PyCFunction) Application::sGetDocument, METH_VARARGS,
|
||||
"getDocument(string) -> object\n\n"
|
||||
"Get a document by its name"},
|
||||
@@ -208,17 +211,27 @@ PyObject* Gui::Application::sActiveView(PyObject * /*self*/, PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return NULL;
|
||||
|
||||
Document *pcDoc = Instance->activeDocument();
|
||||
if (pcDoc) {
|
||||
Gui::MDIView *pcView = pcDoc->getActiveView();
|
||||
if (pcView)
|
||||
// already incremented in getPyObject().
|
||||
return pcView->getPyObject();
|
||||
Gui::MDIView* mdiView = Instance->activeView();
|
||||
if (mdiView) {
|
||||
// already incremented in getPyObject().
|
||||
return mdiView->getPyObject();
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* Gui::Application::sActivateView(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char* typeStr;
|
||||
PyObject *create = Py_False;
|
||||
if (!PyArg_ParseTuple(args, "sO!", &typeStr, &PyBool_Type, &create))
|
||||
return NULL;
|
||||
|
||||
Base::Type type = Base::Type::fromName(typeStr);
|
||||
Instance->activateView(type, PyObject_IsTrue(create) ? true : false);
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* Gui::Application::sSetActiveDocument(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
Document *pcDoc = 0;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <algorithm>
|
||||
# include <QAbstractButton>
|
||||
# include <qapplication.h>
|
||||
# include <qdir.h>
|
||||
@@ -1389,6 +1390,36 @@ MDIView* Document::getActiveView(void) const
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Document::setActiveWindow
|
||||
* If this document is active and the view is part of it then it will be
|
||||
* activated. If the document is not active of the view is already active
|
||||
* nothing is done.
|
||||
* @param view
|
||||
*/
|
||||
void Document::setActiveWindow(Gui::MDIView* view)
|
||||
{
|
||||
// get the main window's active view
|
||||
MDIView* active = getMainWindow()->activeWindow();
|
||||
|
||||
// view is already active
|
||||
if (active == view)
|
||||
return;
|
||||
|
||||
// get all MDI views of the document
|
||||
std::list<MDIView*> mdis = getMDIViews();
|
||||
|
||||
// this document is not active
|
||||
if (std::find(mdis.begin(), mdis.end(), active) == mdis.end())
|
||||
return;
|
||||
|
||||
// the view is not part of the document
|
||||
if (std::find(mdis.begin(), mdis.end(), view) == mdis.end())
|
||||
return;
|
||||
|
||||
getMainWindow()->setActiveWindow(view);
|
||||
}
|
||||
|
||||
Gui::MDIView* Document::getViewOfNode(SoNode* node) const
|
||||
{
|
||||
std::list<MDIView*> mdis = getMDIViewsOfType(View3DInventor::getClassTypeId());
|
||||
|
||||
@@ -159,6 +159,7 @@ public:
|
||||
//@{
|
||||
/// Getter for the active view
|
||||
Gui::MDIView* getActiveView(void) const;
|
||||
void setActiveWindow(Gui::MDIView* view);
|
||||
Gui::MDIView* getEditingViewOfViewProvider(Gui::ViewProvider*) const;
|
||||
Gui::MDIView* getViewOfViewProvider(Gui::ViewProvider*) const;
|
||||
Gui::MDIView* getViewOfNode(SoNode*) const;
|
||||
|
||||
@@ -115,6 +115,7 @@ PartDesign::Body * makeBody(App::Document *doc)
|
||||
"App.activeDocument().addObject('PartDesign::Body','%s')",
|
||||
bodyName.c_str() );
|
||||
Gui::Command::doCommand( Gui::Command::Gui,
|
||||
"Gui.activateView('Gui::View3DInventor', True)\n"
|
||||
"Gui.activeView().setActiveObject('%s', App.activeDocument().%s)",
|
||||
PDBODYKEY, bodyName.c_str() );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user