+ fix method ViewProviderDocumentObject::getActiveView()
+ fix SoAutoZoomTranslation and SoZoomTranslation to get correct scaling factor (do not rely on active view because this can be the wrong one and thus delivers wrong results)
This commit is contained in:
parent
470b9ff756
commit
6dfc395a06
|
@ -62,40 +62,32 @@ void SoAutoZoomTranslation::initClass()
|
|||
SO_NODE_INIT_CLASS(SoAutoZoomTranslation, SoTransformation, "AutoZoom");
|
||||
}
|
||||
|
||||
float SoAutoZoomTranslation::getScaleFactor()
|
||||
float SoAutoZoomTranslation::getScaleFactor(SoAction* action) const
|
||||
{
|
||||
// Dividing by 5 seems to work well
|
||||
|
||||
Gui::MDIView *mdi = Gui::Application::Instance->activeDocument()->getActiveView();
|
||||
if (mdi && mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
|
||||
Gui::View3DInventorViewer *viewer = static_cast<Gui::View3DInventor *>(mdi)->getViewer();
|
||||
float fScale = viewer->getSoRenderManager()->getCamera()->getViewVolume(viewer->getSoRenderManager()->getCamera()->aspectRatio.getValue()).getWorldToScreenScale(SbVec3f(0.f, 0.f, 0.f), 0.1f) / 5;
|
||||
if (fScale != this->scale) this->touch();
|
||||
this->scale = fScale;
|
||||
return this->scale;
|
||||
} else {
|
||||
return this->scale;
|
||||
}
|
||||
SbViewVolume vv = SoViewVolumeElement::get(action->getState());
|
||||
float aspectRatio = SoViewportRegionElement::get(action->getState()).getViewportAspectRatio();
|
||||
float scale = vv.getWorldToScreenScale(SbVec3f(0.f, 0.f, 0.f), 0.1f) / (5*aspectRatio);
|
||||
return scale;
|
||||
}
|
||||
|
||||
SoAutoZoomTranslation::SoAutoZoomTranslation()
|
||||
{
|
||||
SO_NODE_CONSTRUCTOR(SoAutoZoomTranslation);
|
||||
//SO_NODE_ADD_FIELD(abPos, (SbVec3f(0.f,0.f,0.f)));
|
||||
//this->scale = -1;
|
||||
}
|
||||
|
||||
void SoAutoZoomTranslation::GLRender(SoGLRenderAction * action)
|
||||
{
|
||||
//Base::Console().Log("Draw\n");
|
||||
SoAutoZoomTranslation::doAction((SoAction *)action);
|
||||
inherited::GLRender(action);
|
||||
{
|
||||
//Base::Console().Log("Draw\n");
|
||||
SoAutoZoomTranslation::doAction((SoAction *)action);
|
||||
inherited::GLRender(action);
|
||||
}
|
||||
|
||||
// Doc in superclass.
|
||||
void SoAutoZoomTranslation::doAction(SoAction * action)
|
||||
{
|
||||
float sf = this->getScaleFactor();
|
||||
float sf = this->getScaleFactor(action);
|
||||
SoModelMatrixElement::scaleBy(action->getState(), this,
|
||||
SbVec3f(sf,sf,sf));
|
||||
//Base::Console().Log("Scale: %f\n",sf);
|
||||
|
@ -114,8 +106,8 @@ void SoAutoZoomTranslation::doAction(SoAction * action)
|
|||
|
||||
void SoAutoZoomTranslation::getMatrix(SoGetMatrixAction * action)
|
||||
{
|
||||
//Base::Console().Log("Matrix\n");
|
||||
float sf = this->getScaleFactor();
|
||||
//Base::Console().Log("Matrix\n");
|
||||
float sf = this->getScaleFactor(action);
|
||||
|
||||
SbVec3f scalevec = SbVec3f(sf,sf,sf);
|
||||
SbMatrix m;
|
||||
|
@ -125,30 +117,29 @@ void SoAutoZoomTranslation::getMatrix(SoGetMatrixAction * action)
|
|||
|
||||
m.setScale(SbVec3f(1.0f / scalevec[0], 1.0f / scalevec[1], 1.0f / scalevec[2]));
|
||||
action->getInverse().multRight(m);
|
||||
|
||||
}
|
||||
|
||||
void SoAutoZoomTranslation::callback(SoCallbackAction * action)
|
||||
{
|
||||
// Base::Console().Log("callback\n");
|
||||
SoAutoZoomTranslation::doAction((SoAction*)action);
|
||||
// Base::Console().Log("callback\n");
|
||||
SoAutoZoomTranslation::doAction((SoAction*)action);
|
||||
}
|
||||
|
||||
void SoAutoZoomTranslation::getBoundingBox(SoGetBoundingBoxAction * action)
|
||||
{
|
||||
//Base::Console().Log("getBoundingBox\n");
|
||||
//Base::Console().Log("getBoundingBox\n");
|
||||
SoAutoZoomTranslation::doAction((SoAction*)action);
|
||||
}
|
||||
|
||||
void SoAutoZoomTranslation::pick(SoPickAction * action)
|
||||
{
|
||||
//Base::Console().Log("pick\n");
|
||||
//Base::Console().Log("pick\n");
|
||||
SoAutoZoomTranslation::doAction((SoAction*)action);
|
||||
}
|
||||
|
||||
// Doc in superclass.
|
||||
void SoAutoZoomTranslation::getPrimitiveCount(SoGetPrimitiveCountAction * action)
|
||||
{
|
||||
//Base::Console().Log("getPrimitiveCount\n");
|
||||
//Base::Console().Log("getPrimitiveCount\n");
|
||||
SoAutoZoomTranslation::doAction((SoAction*)action);
|
||||
}
|
|
@ -38,7 +38,6 @@ public:
|
|||
static void initClass();
|
||||
SoAutoZoomTranslation();
|
||||
//SoSFVec3f abPos;
|
||||
float getScaleFactor();
|
||||
|
||||
protected:
|
||||
virtual ~SoAutoZoomTranslation() {};
|
||||
|
@ -49,9 +48,9 @@ protected:
|
|||
virtual void getBoundingBox(SoGetBoundingBoxAction * action);
|
||||
virtual void callback(SoCallbackAction * action);
|
||||
virtual void pick(SoPickAction * action);
|
||||
float getScaleFactor(SoAction*) const;
|
||||
|
||||
private:
|
||||
float scale;
|
||||
//void setAutoScale(void);
|
||||
};
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "Application.h"
|
||||
#include "Document.h"
|
||||
#include "Selection.h"
|
||||
#include "MainWindow.h"
|
||||
#include "MDIView.h"
|
||||
#include "TaskView/TaskAppearance.h"
|
||||
#include "ViewProviderDocumentObject.h"
|
||||
|
@ -160,7 +161,20 @@ Gui::MDIView* ViewProviderDocumentObject::getActiveView() const
|
|||
{
|
||||
App::Document* pAppDoc = pcObject->getDocument();
|
||||
Gui::Document* pGuiDoc = Gui::Application::Instance->getDocument(pAppDoc);
|
||||
return pGuiDoc->getActiveView();
|
||||
|
||||
MDIView* active = getMainWindow()->activeWindow();
|
||||
std::list<MDIView*> views = pGuiDoc->getViewsOfViewProvider(const_cast<ViewProviderDocumentObject*>(this));
|
||||
|
||||
// is the active window a 3d view and does it contain this view provider
|
||||
std::list<MDIView*>::iterator it = std::find(views.begin(), views.end(), active);
|
||||
if (it != views.end())
|
||||
return *it;
|
||||
// if there is a 3d view containing this view provider return the first one
|
||||
else if (!views.empty())
|
||||
return views.front();
|
||||
// no 3d view found containing this view provider
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
Gui::MDIView* ViewProviderDocumentObject::getEditingView() const
|
||||
|
|
|
@ -60,25 +60,19 @@ void SoZoomTranslation::initClass()
|
|||
SO_NODE_INIT_CLASS(SoZoomTranslation, SoTranslation, "Translation");
|
||||
}
|
||||
|
||||
float SoZoomTranslation::getScaleFactor()
|
||||
float SoZoomTranslation::getScaleFactor(SoAction* action) const
|
||||
{
|
||||
// Dividing by 5 seems to work well
|
||||
|
||||
Gui::MDIView *mdi = Gui::Application::Instance->activeDocument()->getActiveView();
|
||||
if (mdi && mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
|
||||
Gui::View3DInventorViewer *viewer = static_cast<Gui::View3DInventor *>(mdi)->getViewer();
|
||||
this->scale = viewer->getSoRenderManager()->getCamera()->getViewVolume(viewer->getSoRenderManager()->getCamera()->aspectRatio.getValue()).getWorldToScreenScale(SbVec3f(0.f, 0.f, 0.f), 0.1f) / 5;
|
||||
return this->scale;
|
||||
} else {
|
||||
return this->scale;
|
||||
}
|
||||
SbViewVolume vv = SoViewVolumeElement::get(action->getState());
|
||||
float aspectRatio = SoViewportRegionElement::get(action->getState()).getViewportAspectRatio();
|
||||
float scale = vv.getWorldToScreenScale(SbVec3f(0.f, 0.f, 0.f), 0.1f) / (5*aspectRatio);
|
||||
return scale;
|
||||
}
|
||||
|
||||
SoZoomTranslation::SoZoomTranslation()
|
||||
{
|
||||
SO_NODE_CONSTRUCTOR(SoZoomTranslation);
|
||||
SO_NODE_ADD_FIELD(abPos, (SbVec3f(0.f,0.f,0.f)));
|
||||
this->scale = -1;
|
||||
}
|
||||
|
||||
void SoZoomTranslation::GLRender(SoGLRenderAction * action)
|
||||
|
@ -96,7 +90,7 @@ void SoZoomTranslation::doAction(SoAction * action)
|
|||
SbVec3f absVtr = this->abPos.getValue();
|
||||
SbVec3f relVtr = this->translation.getValue();
|
||||
|
||||
float sf = this->getScaleFactor();
|
||||
float sf = this->getScaleFactor(action);
|
||||
// For Sketcher Keep Z value the same
|
||||
relVtr[0] = (relVtr[0] != 0) ? sf * relVtr[0] : 0;
|
||||
relVtr[1] = (relVtr[1] != 0) ? sf * relVtr[1] : 0;
|
||||
|
@ -116,7 +110,7 @@ void SoZoomTranslation::getMatrix(SoGetMatrixAction * action)
|
|||
SbVec3f absVtr = this->abPos.getValue();
|
||||
SbVec3f relVtr = this->translation.getValue();
|
||||
|
||||
float sf = this->getScaleFactor();
|
||||
float sf = this->getScaleFactor(action);
|
||||
// For Sketcher Keep Z value the same
|
||||
relVtr[0] = (relVtr[0] != 0) ? sf * relVtr[0] : 0;
|
||||
relVtr[1] = (relVtr[1] != 0) ? sf * relVtr[1] : 0;
|
||||
|
|
|
@ -38,7 +38,6 @@ public:
|
|||
static void initClass();
|
||||
SoZoomTranslation();
|
||||
SoSFVec3f abPos;
|
||||
float getScaleFactor();
|
||||
|
||||
protected:
|
||||
virtual ~SoZoomTranslation() {};
|
||||
|
@ -49,9 +48,7 @@ protected:
|
|||
virtual void getBoundingBox(SoGetBoundingBoxAction * action);
|
||||
virtual void callback(SoCallbackAction * action);
|
||||
virtual void pick(SoPickAction * action);
|
||||
|
||||
private:
|
||||
float scale;
|
||||
float getScaleFactor(SoAction * action) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user