+ 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:
wmayer
2015-09-16 11:32:35 +02:00
parent a2d8a5b0aa
commit 4accb68bb1
5 changed files with 41 additions and 46 deletions

View File

@@ -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);
}