+ add Document::sendMsgToFirstView, fix memory leak

This commit is contained in:
wmayer 2015-04-12 18:39:01 +02:00
parent 52db9a6cff
commit 8991b9e04b
3 changed files with 30 additions and 22 deletions

View File

@ -1163,6 +1163,26 @@ bool Document::sendMsgToViews(const char* pMsg)
return false;
}
bool Document::sendMsgToFirstView(const Base::Type& typeId, const char* pMsg, const char** ppReturn)
{
// first try the active view
Gui::MDIView* view = getActiveView();
if (view && view->isDerivedFrom(typeId)) {
if (view->onMsg(pMsg, ppReturn))
return true;
}
// now try the other views
std::list<Gui::MDIView*> views = getMDIViewsOfType(typeId);
for (std::list<Gui::MDIView*>::iterator it = views.begin(); it != views.end(); ++it) {
if ((*it != view) && (*it)->onMsg(pMsg, ppReturn)) {
return true;
}
}
return false;
}
/// Getter for the active view
MDIView* Document::getActiveView(void) const
{

View File

@ -150,6 +150,12 @@ public:
*/
/// send Messages to all views
bool sendMsgToViews(const char* pMsg);
/** Sends the message \a pMsg to the views of type \a typeid and stops with
* the first view that supports the message and returns \a ppReturn. The very
* first checked view is the current active view.
* If a view supports the message true is returned and false otherwise.
*/
bool sendMsgToFirstView(const Base::Type& typeId, const char* pMsg, const char** ppReturn);
/// Attach a view (get called by the MDIView constructor)
void attachView(Gui::BaseView* pcView, bool bPassiv=false);
/// Detach a view (get called by the MDIView destructor)

View File

@ -98,17 +98,7 @@ povViewCamera(PyObject *self, PyObject *args)
Gui::Document* doc = Gui::Application::Instance->activeDocument();
if (doc) {
// try active view first
Gui::MDIView* view = doc->getActiveView();
if (!(view && view->onMsg("GetCamera",&ppReturn))) {
// now try all views
std::list<Gui::MDIView*> views = doc->getMDIViews();
for (std::list<Gui::MDIView*>::iterator it = views.begin(); it != views.end(); ++it) {
if ((*it)->onMsg("GetCamera",&ppReturn)) {
break;
}
}
}
doc->sendMsgToFirstView(Gui::MDIView::getClassTypeId(), "GetCamera", &ppReturn);
}
else {
PyErr_SetString(PyExc_RuntimeError, "No active document found");
@ -146,6 +136,7 @@ povViewCamera(PyObject *self, PyObject *args)
SbVec3f pos = Cam->position.getValue();
float Dist = Cam->focalDistance.getValue();
Cam->unref(); // free memory
// making gp out of the Coin stuff
gp_Vec gpPos(pos.getValue()[0],pos.getValue()[1],pos.getValue()[2]);
@ -180,17 +171,7 @@ luxViewCamera(PyObject *self, PyObject *args)
Gui::Document* doc = Gui::Application::Instance->activeDocument();
if (doc) {
// try active view first
Gui::MDIView* view = doc->getActiveView();
if (!(view && view->onMsg("GetCamera",&ppReturn))) {
// now try all views
std::list<Gui::MDIView*> views = doc->getMDIViews();
for (std::list<Gui::MDIView*>::iterator it = views.begin(); it != views.end(); ++it) {
if ((*it)->onMsg("GetCamera",&ppReturn)) {
break;
}
}
}
doc->sendMsgToFirstView(Gui::MDIView::getClassTypeId(), "GetCamera", &ppReturn);
}
else {
PyErr_SetString(PyExc_RuntimeError, "No active document found");
@ -228,6 +209,7 @@ luxViewCamera(PyObject *self, PyObject *args)
SbVec3f pos = Cam->position.getValue();
float Dist = Cam->focalDistance.getValue();
Cam->unref(); // free memory
// making gp out of the Coin stuff
gp_Vec gpPos(pos.getValue()[0],pos.getValue()[1],pos.getValue()[2]);