From ed5a055444b9e260add11ea44c8308205cf873e2 Mon Sep 17 00:00:00 2001 From: jriegel Date: Sat, 28 Jan 2012 17:59:45 +0100 Subject: [PATCH] implementing PlacementObject --- src/Gui/Application.cpp | 2 +- src/Gui/Inventor/SoAutoZoomTranslation.cpp | 16 +-- src/Gui/Inventor/SoZoomTranslation.cpp | 154 --------------------- src/Gui/Inventor/SoZoomTranslation.h | 58 -------- src/Gui/ViewProviderPlacement.cpp | 62 +++++++++ src/Gui/ViewProviderPlacement.h | 2 + 6 files changed, 73 insertions(+), 221 deletions(-) delete mode 100644 src/Gui/Inventor/SoZoomTranslation.cpp delete mode 100644 src/Gui/Inventor/SoZoomTranslation.h diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 1be3a9d48..5fbca951d 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2004 Juergen Riegel * * * * This file is part of the FreeCAD CAx development system. * * * diff --git a/src/Gui/Inventor/SoAutoZoomTranslation.cpp b/src/Gui/Inventor/SoAutoZoomTranslation.cpp index 5137d7f74..896e35dd6 100644 --- a/src/Gui/Inventor/SoAutoZoomTranslation.cpp +++ b/src/Gui/Inventor/SoAutoZoomTranslation.cpp @@ -25,7 +25,7 @@ #ifndef _PreComp_ # include # include -# include +# include # include #endif @@ -96,7 +96,7 @@ SoAutoZoomTranslation::SoAutoZoomTranslation() void SoAutoZoomTranslation::GLRender(SoGLRenderAction * action) { - //Base::Console().Log("Draw\n"); + Base::Console().Log("Draw\n"); SoAutoZoomTranslation::doAction((SoAction *)action); inherited::GLRender(action); } @@ -107,7 +107,7 @@ void SoAutoZoomTranslation::doAction(SoAction * action) float sf = this->getScaleFactor(action); SoModelMatrixElement::scaleBy(action->getState(), this, SbVec3f(sf,sf,sf)); - //Base::Console().Log("Scale: %f\n",sf); + Base::Console().Log("Scale: %f\n",sf); } // set the auto scale factor. @@ -123,7 +123,7 @@ void SoAutoZoomTranslation::doAction(SoAction * action) void SoAutoZoomTranslation::getMatrix(SoGetMatrixAction * action) { - //Base::Console().Log("Matrix\n"); + Base::Console().Log("Matrix\n"); float sf = this->getScaleFactor(action); SbVec3f scalevec = SbVec3f(sf,sf,sf); @@ -138,25 +138,25 @@ void SoAutoZoomTranslation::getMatrix(SoGetMatrixAction * action) void SoAutoZoomTranslation::callback(SoCallbackAction * action) { - // Base::Console().Log("callback\n"); + 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); } diff --git a/src/Gui/Inventor/SoZoomTranslation.cpp b/src/Gui/Inventor/SoZoomTranslation.cpp deleted file mode 100644 index 30e3d2197..000000000 --- a/src/Gui/Inventor/SoZoomTranslation.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/*************************************************************************** - * Copyright (c)2011 Luke Parry * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - -#include "PreCompiled.h" - -#ifndef _PreComp_ -# include -# include -# include -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - - -#include "SoZoomTranslation.h" - -// ************************************************************************* - -using namespace Gui; - -// ------------------------------------------------------ - -SO_NODE_SOURCE(SoZoomTranslation); - -void SoZoomTranslation::initClass() -{ - SO_NODE_INIT_CLASS(SoZoomTranslation, SoTranslation, "Translation"); -} - -float SoZoomTranslation::getScaleFactor() -{ - // 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(mdi)->getViewer(); - this->scale = viewer->getCamera()->getViewVolume(viewer->getCamera()->aspectRatio.getValue()).getWorldToScreenScale(SbVec3f(0.f, 0.f, 0.f), 0.1f) / 5; - return this->scale; - } else { - return this->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) -{ - SoZoomTranslation::doAction((SoAction *)action); -} - -// Doc in superclass. -void SoZoomTranslation::doAction(SoAction * action) -{ - SbVec3f v; - if(this->translation.getValue() == SbVec3f(0.0f, 0.0f, 0.0f) && this->abPos.getValue() == SbVec3f(0.0f, 0.0f, 0.0f)) { - return; - } else { - SbVec3f absVtr = this->abPos.getValue(); - SbVec3f relVtr = this->translation.getValue(); - - float sf = this->getScaleFactor(); - // 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; - - v = absVtr + relVtr; - } - - SoModelMatrixElement::translateBy(action->getState(), this, v); -} - -void SoZoomTranslation::getMatrix(SoGetMatrixAction * action) -{ - SbVec3f v; - if(this->translation.getValue() == SbVec3f(0.0f, 0.0f, 0.0f) && this->abPos.getValue() == SbVec3f(0.0f, 0.0f, 0.0f)) { - return; - } else { - SbVec3f absVtr = this->abPos.getValue(); - SbVec3f relVtr = this->translation.getValue(); - - float sf = this->getScaleFactor(); - // 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; - - v = absVtr + relVtr; - } - - SbMatrix m; - m.setTranslate(v); - action->getMatrix().multLeft(m); - m.setTranslate(-v); - action->getInverse().multRight(m); - -} - -void SoZoomTranslation::callback(SoCallbackAction * action) -{ - SoZoomTranslation::doAction((SoAction *)action); -} - -void SoZoomTranslation::getBoundingBox(SoGetBoundingBoxAction * action) -{ - SoZoomTranslation::doAction((SoAction *)action); -} - -void SoZoomTranslation::pick(SoPickAction * action) -{ - SoZoomTranslation::doAction((SoAction *)action); -} - -// Doc in superclass. -void SoZoomTranslation::getPrimitiveCount(SoGetPrimitiveCountAction * action) -{ - SoZoomTranslation::doAction((SoAction *)action); -} \ No newline at end of file diff --git a/src/Gui/Inventor/SoZoomTranslation.h b/src/Gui/Inventor/SoZoomTranslation.h deleted file mode 100644 index 08050a89e..000000000 --- a/src/Gui/Inventor/SoZoomTranslation.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * (c) 2011 Luke Parry * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - -#ifndef GUI_SOZOOMTRANSLATION_H -#define GUI_SOZOOMTRANSLATION_H - -#include -#include -#include - -namespace Gui { - -class GuiExport SoZoomTranslation : public SoTranslation { - typedef SoTranslation inherited; - - SO_NODE_HEADER(SoZoomTranslation); - -public: - static void initClass(); - SoZoomTranslation(); - SoSFVec3f abPos; - float getScaleFactor(); - -protected: - virtual ~SoZoomTranslation() {}; - virtual void doAction(SoAction * action); - virtual void getPrimitiveCount(SoGetPrimitiveCountAction * action); - virtual void getMatrix(SoGetMatrixAction * action); - virtual void GLRender(SoGLRenderAction *action); - virtual void getBoundingBox(SoGetBoundingBoxAction * action); - virtual void callback(SoCallbackAction * action); - virtual void pick(SoPickAction * action); - -private: - float scale; -}; - -} -#endif // SKETCHERGUI_SOZOOMTRANSLATION_H diff --git a/src/Gui/ViewProviderPlacement.cpp b/src/Gui/ViewProviderPlacement.cpp index 2d94c730b..d475e96ef 100644 --- a/src/Gui/ViewProviderPlacement.cpp +++ b/src/Gui/ViewProviderPlacement.cpp @@ -44,6 +44,7 @@ #include #include #include "ViewProviderPlacement.h" +#include "SoFCSelection.h" #include "Application.h" #include "Document.h" #include "View3DInventorViewer.h" @@ -161,11 +162,72 @@ void ViewProviderPlacement::attach(App::DocumentObject* pcObject) lineSep->addChild(pCoords); lineSep->addChild(pLines); + // Making the whole measurement object selectable by 3d view can + // become cumbersome since it has influence to any raypick action. + // Thus, it's only selectable by its text label + //SoFCSelection* textsep = new SoFCSelection(); + //textsep->objectName = pcObject->getNameInDocument(); + //textsep->documentName = pcObject->getDocument()->getName(); + //textsep->subElementName = "Main"; + ////SoSeparator* textsep = new SoSeparator(); + //textsep->addChild(pTranslation); + //textsep->addChild(pTextColor); + //textsep->addChild(pFont); + //textsep->addChild(pLabel); + + //SoSeparator* sep = new SoSeparator(); + //sep->addChild(lineSep); + //sep->addChild(textsep); addDisplayMaskMode(lineSep, "Base"); } void ViewProviderPlacement::updateData(const App::Property* prop) { + //if (prop->getTypeId() == App::PropertyVector::getClassTypeId() || + // prop == &Mirror || prop == &DistFactor) { + // if (strcmp(prop->getName(),"P1") == 0) { + // Base::Vector3f v = static_cast(prop)->getValue(); + // pCoords->point.set1Value(0, SbVec3f(v.x,v.y,v.z)); + // } + // else if (strcmp(prop->getName(),"P2") == 0) { + // Base::Vector3f v = static_cast(prop)->getValue(); + // pCoords->point.set1Value(1, SbVec3f(v.x,v.y,v.z)); + // } + + // SbVec3f pt1 = pCoords->point[0]; + // SbVec3f pt2 = pCoords->point[1]; + // SbVec3f dif = pt1-pt2; + + // float length = fabs(dif.length())*DistFactor.getValue(); + // if (Mirror.getValue()) + // length = -length; + + // if (dif.sqrLength() < 10.0e-6f) { + // pCoords->point.set1Value(2, pt1+SbVec3f(0.0f,0.0f,length)); + // pCoords->point.set1Value(3, pt2+SbVec3f(0.0f,0.0f,length)); + // } + // else { + // SbVec3f dir = dif.cross(SbVec3f(1.0f,0.0f,0.0f)); + // if (dir.sqrLength() < 10.0e-6f) + // dir = dif.cross(SbVec3f(0.0f,1.0f,0.0f)); + // if (dir.sqrLength() < 10.0e-6f) + // dir = dif.cross(SbVec3f(0.0f,0.0f,1.0f)); + // dir.normalize(); + // if (dir.dot(SbVec3f(0.0f,0.0f,1.0f)) < 0.0f) + // length = -length; + // pCoords->point.set1Value(2, pt1 + length*dir); + // pCoords->point.set1Value(3, pt2 + length*dir); + // } + + // SbVec3f pos = (pCoords->point[2]+pCoords->point[3])/2.0f; + // pTranslation->translation.setValue(pos); + + // std::stringstream s; + // s.precision(3); + // s.setf(std::ios::fixed | std::ios::showpoint); + // s << dif.length(); + // pLabel->string.setValue(s.str().c_str()); + //} ViewProviderGeometryObject::updateData(prop); } diff --git a/src/Gui/ViewProviderPlacement.h b/src/Gui/ViewProviderPlacement.h index d4a44f625..5bcc887e9 100644 --- a/src/Gui/ViewProviderPlacement.h +++ b/src/Gui/ViewProviderPlacement.h @@ -62,6 +62,8 @@ public: virtual std::string getElement(const SoDetail *) const; virtual SoDetail* getDetail(const char*) const; + static void measureDistanceCallback(void * ud, SoEventCallback * n); + protected: void onChanged(const App::Property* prop);