diff --git a/src/App/Plane.cpp b/src/App/Plane.cpp new file mode 100644 index 0000000000..0e01419f14 --- /dev/null +++ b/src/App/Plane.cpp @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2012 * + * * + * 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_ +#endif + + +#include "Plane.h" + +using namespace App; + + +PROPERTY_SOURCE(App::Plane, App::GeoFeature) + + +//=========================================================================== +// Feature +//=========================================================================== + +Plane::Plane(void) +{ + +} + +Plane::~Plane(void) +{ +} + + + + + + + diff --git a/src/App/Plane.h b/src/App/Plane.h new file mode 100644 index 0000000000..f5bbd5b23b --- /dev/null +++ b/src/App/Plane.h @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2012 * + * * + * 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 _AppPlane_h_ +#define _AppPlane_h_ + + +#include "GeoFeature.h" +#include "PropertyGeo.h" + + + +namespace App +{ + + +/** Plane Object + * Used to define planar support for all kind of operations in the document space + */ +class AppExport Plane: public App::GeoFeature +{ + PROPERTY_HEADER(App::Plane); + +public: + + /// Constructor + Plane(void); + virtual ~Plane(); + + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName(void) const { + return "Gui::ViewProviderPlane"; + } +}; + + +} //namespace App + + + +#endif diff --git a/src/Gui/Inventor/SoAutoZoomTranslation.cpp b/src/Gui/Inventor/SoAutoZoomTranslation.cpp new file mode 100644 index 0000000000..7b5738c68e --- /dev/null +++ b/src/Gui/Inventor/SoAutoZoomTranslation.cpp @@ -0,0 +1,154 @@ +/*************************************************************************** + * 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 + + +#include "SoAutoZoomTranslation.h" + +// ************************************************************************* + +using namespace Gui; + +// ------------------------------------------------------ + +SO_NODE_SOURCE(SoAutoZoomTranslation); + +void SoAutoZoomTranslation::initClass() +{ + SO_NODE_INIT_CLASS(SoAutoZoomTranslation, SoTransformation, "AutoZoom"); +} + +float SoAutoZoomTranslation::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(); + float fScale = viewer->getCamera()->getViewVolume(viewer->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; + } +} + +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); +} + +// Doc in superclass. +void SoAutoZoomTranslation::doAction(SoAction * action) +{ + float sf = this->getScaleFactor(); + SoModelMatrixElement::scaleBy(action->getState(), this, + SbVec3f(sf,sf,sf)); + //Base::Console().Log("Scale: %f\n",sf); +} + +// set the auto scale factor. +//void SoAutoZoomTranslation::setAutoScale(void) +//{ +// float sf = this->getScaleFactor(); +// //this->enableNotify ( false ); +// scaleFactor.setValue(SbVec3f(sf,sf,sf)); +// //this->enableNotify ( true ); +// //scaleFactor.setDirty (true); +// +//} + +void SoAutoZoomTranslation::getMatrix(SoGetMatrixAction * action) +{ + //Base::Console().Log("Matrix\n"); + float sf = this->getScaleFactor(); + + SbVec3f scalevec = SbVec3f(sf,sf,sf); + SbMatrix m; + + m.setScale(scalevec); + action->getMatrix().multLeft(m); + + 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); +} + +void SoAutoZoomTranslation::getBoundingBox(SoGetBoundingBoxAction * action) +{ + //Base::Console().Log("getBoundingBox\n"); + SoAutoZoomTranslation::doAction((SoAction*)action); +} + +void SoAutoZoomTranslation::pick(SoPickAction * action) +{ + //Base::Console().Log("pick\n"); + SoAutoZoomTranslation::doAction((SoAction*)action); +} + +// Doc in superclass. +void SoAutoZoomTranslation::getPrimitiveCount(SoGetPrimitiveCountAction * action) +{ + //Base::Console().Log("getPrimitiveCount\n"); + SoAutoZoomTranslation::doAction((SoAction*)action); +} \ No newline at end of file diff --git a/src/Gui/Inventor/SoAutoZoomTranslation.h b/src/Gui/Inventor/SoAutoZoomTranslation.h new file mode 100644 index 0000000000..19201018d8 --- /dev/null +++ b/src/Gui/Inventor/SoAutoZoomTranslation.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * (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_SOAUTOZOOMTRANSLATION_H +#define GUI_SOAUTOZOOMTRANSLATION_H + +#include +#include +#include + +namespace Gui { + +class GuiExport SoAutoZoomTranslation : public SoTransformation { + typedef SoTransformation inherited; + + SO_NODE_HEADER(SoAutoZoomTranslation); + +public: + static void initClass(); + SoAutoZoomTranslation(); + //SoSFVec3f abPos; + float getScaleFactor(); + +protected: + virtual ~SoAutoZoomTranslation() {}; + 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; + //void setAutoScale(void); +}; + +} +#endif // GUI_SOAUTOZOOMTRANSLATION_H diff --git a/src/Gui/ProjectView.cpp b/src/Gui/ProjectView.cpp new file mode 100644 index 0000000000..0a67e2bc9c --- /dev/null +++ b/src/Gui/ProjectView.cpp @@ -0,0 +1,75 @@ +/*************************************************************************** + * Copyright (c) 2012 Jürgen Riegel * + * * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include +#include +#include + +#include "ProjectView.h" +#include "Document.h" +#include "BitmapFactory.h" +#include "ViewProviderDocumentObject.h" +#include "MenuManager.h" +#include "Application.h" +#include "MainWindow.h" + +using namespace Gui; + + + +/* TRANSLATOR Gui::ProjectWidget */ +ProjectWidget::ProjectWidget(QWidget* parent) + : QTreeView(parent) +{ + fileModel = new QDirModel(this); + fileModel->setSorting(QDir::DirsFirst | QDir::Type); + setModel(fileModel); +} + +ProjectWidget::~ProjectWidget() +{ +} + + + + + +#include "moc_ProjectView.cpp" + diff --git a/src/Gui/ProjectView.h b/src/Gui/ProjectView.h new file mode 100644 index 0000000000..fb584e2561 --- /dev/null +++ b/src/Gui/ProjectView.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (c) 2012 Jürgen Riegel * + * * + * 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_ProjectView_H +#define GUI_ProjectView_H + +#include + +#include +#include + +#include +#include +class QDirModel; + +namespace Gui { + + +/** Tree view that allows drag & drop of document objects. + * @author Werner Mayer + */ +class ProjectWidget : public QTreeView +{ + Q_OBJECT + +public: + ProjectWidget(QWidget* parent=0); + ~ProjectWidget(); + +private: + QDirModel *fileModel; + +}; + + + +} + + +#endif // GUI_ProjectView_H + diff --git a/src/Gui/ViewProviderPlacement.cpp b/src/Gui/ViewProviderPlacement.cpp new file mode 100644 index 0000000000..ef6389de44 --- /dev/null +++ b/src/Gui/ViewProviderPlacement.cpp @@ -0,0 +1,222 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2012 * + * * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include +#include +#include +#include "ViewProviderPlacement.h" +#include "SoFCSelection.h" +#include "Application.h" +#include "Document.h" +#include "View3DInventorViewer.h" +#include "Inventor/SoAutoZoomTranslation.h" +#include "SoAxisCrossKit.h" +//#include + +#include +#include +#include +#include + +using namespace Gui; + +PROPERTY_SOURCE(Gui::ViewProviderPlacement, Gui::ViewProviderGeometryObject) + + +ViewProviderPlacement::ViewProviderPlacement() +{ + + pMat = new SoMaterial(); + pMat->ref(); + + const float dist = 2; + const float size = 6; + const float pSize = 4; + + static const SbVec3f verts[13] = + { + SbVec3f(0,0,0), SbVec3f(size,0,0), + SbVec3f(0,size,0), SbVec3f(0,0,size), + SbVec3f(dist,dist,0), SbVec3f(dist,pSize,0), SbVec3f(pSize,dist,0), // XY Plane + SbVec3f(dist,0,dist), SbVec3f(dist,0,pSize), SbVec3f(pSize,0,dist), // XY Plane + SbVec3f(0,dist,dist), SbVec3f(0,pSize,dist), SbVec3f(0,dist,pSize) // XY Plane + }; + + // indexes used to create the edges + static const int32_t lines[21] = + { + 0,1,-1, + 0,2,-1, + 0,3,-1, + 5,4,6,-1, + 8,7,9,-1, + 11,10,12,-1 + }; + + pMat->diffuseColor.setNum(6); + pMat->diffuseColor.set1Value(0, SbColor(1.0f, 0.2f, 0.2f)); + pMat->diffuseColor.set1Value(1, SbColor(0.2f, 1.0f, 0.2f)); + pMat->diffuseColor.set1Value(2, SbColor(0.2f, 0.2f, 1.0f)); + + pMat->diffuseColor.set1Value(3, SbColor(1.0f, 1.0f, 0.8f)); + pMat->diffuseColor.set1Value(4, SbColor(1.0f, 0.8f, 1.0f)); + pMat->diffuseColor.set1Value(5, SbColor(0.8f, 1.0f, 1.0f)); + + pCoords = new SoCoordinate3(); + pCoords->ref(); + pCoords->point.setNum(13); + pCoords->point.setValues(0, 13, verts); + + pLines = new SoIndexedLineSet(); + pLines->ref(); + pLines->coordIndex.setNum(21); + pLines->coordIndex.setValues(0, 21, lines); + sPixmap = "view-measurement"; +} + +ViewProviderPlacement::~ViewProviderPlacement() +{ + pCoords->unref(); + pLines->unref(); + pMat->unref(); +} + +void ViewProviderPlacement::onChanged(const App::Property* prop) +{ + ViewProviderGeometryObject::onChanged(prop); +} + +std::vector ViewProviderPlacement::getDisplayModes(void) const +{ + // add modes + std::vector StrList; + StrList.push_back("Base"); + return StrList; +} + +void ViewProviderPlacement::setDisplayMode(const char* ModeName) +{ + if (strcmp(ModeName, "Base") == 0) + setDisplayMaskMode("Base"); + ViewProviderGeometryObject::setDisplayMode(ModeName); +} + +void ViewProviderPlacement::attach(App::DocumentObject* pcObject) +{ + ViewProviderGeometryObject::attach(pcObject); + + SoAnnotation *lineSep = new SoAnnotation(); + + + SoAutoZoomTranslation *zoom = new SoAutoZoomTranslation; + + SoDrawStyle* style = new SoDrawStyle(); + style->lineWidth = 2.0f; + + SoMaterialBinding* matBinding = new SoMaterialBinding; + matBinding->value = SoMaterialBinding::PER_FACE; + + lineSep->addChild(zoom); + lineSep->addChild(style); + lineSep->addChild(matBinding); + lineSep->addChild(pMat); + lineSep->addChild(pCoords); + lineSep->addChild(pLines); + + addDisplayMaskMode(lineSep, "Base"); +} + +void ViewProviderPlacement::updateData(const App::Property* prop) +{ + ViewProviderGeometryObject::updateData(prop); +} + +std::string ViewProviderPlacement::getElement(const SoDetail* detail) const +{ + if (detail) { + if (detail->getTypeId() == SoLineDetail::getClassTypeId()) { + const SoLineDetail* line_detail = static_cast(detail); + int edge = line_detail->getLineIndex(); + switch (edge) + { + case 0: return std::string("X-Axis"); + case 1: return std::string("Y-Axis"); + case 2: return std::string("Z-Axis"); + case 3: return std::string("XY-Plane"); + case 4: return std::string("XZ-Plane"); + case 5: return std::string("YZ-Plane"); + } + } + } + + return std::string(""); +} + +SoDetail* ViewProviderPlacement::getDetail(const char* subelement) const +{ + SoLineDetail* detail = 0; + std::string subelem(subelement); + int edge = -1; + + if(subelem == "X-Axis") edge = 0; + else if(subelem == "Y-Axis") edge = 1; + else if(subelem == "Z-Axis") edge = 2; + else if(subelem == "XY-Plane") edge = 3; + else if(subelem == "XZ-Plane") edge = 4; + else if(subelem == "YZ-Plane") edge = 5; + + if(edge >= 0) { + detail = new SoLineDetail(); + detail->setPartIndex(edge); + } + + + return detail; +} + +bool ViewProviderPlacement::isSelectable(void) const +{ + return true; +} +// ---------------------------------------------------------------------------- + + diff --git a/src/Gui/ViewProviderPlacement.h b/src/Gui/ViewProviderPlacement.h new file mode 100644 index 0000000000..02ff9fd43e --- /dev/null +++ b/src/Gui/ViewProviderPlacement.h @@ -0,0 +1,77 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2012 * + * * + * 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_ViewProviderPlacement_H +#define GUI_ViewProviderPlacement_H + +#include "ViewProviderGeometryObject.h" +#include + +class SoFontStyle; +class SoText2; +class SoBaseColor; +class SoTranslation; +class SoCoordinate3; +class SoIndexedLineSet; +class SoEventCallback; +class SoMaterial; + +namespace Gui +{ + + +class GuiExport ViewProviderPlacement : public ViewProviderGeometryObject +{ + PROPERTY_HEADER(Gui::ViewProviderPlacement); + +public: + /// Constructor + ViewProviderPlacement(void); + virtual ~ViewProviderPlacement(); + + void attach(App::DocumentObject *); + void updateData(const App::Property*); + std::vector getDisplayModes(void) const; + void setDisplayMode(const char* ModeName); + + /// indicates if the ViewProvider use the new Selection model + virtual bool useNewSelectionModel(void) const {return true;} + /// indicates if the ViewProvider can be selected + virtual bool isSelectable(void) const ; + /// return a hit element to the selection path or 0 + virtual std::string getElement(const SoDetail *) const; + virtual SoDetail* getDetail(const char*) const; + +protected: + void onChanged(const App::Property* prop); + +private: + SoCoordinate3 * pCoords; + SoMaterial * pMat; + SoIndexedLineSet * pLines; +}; + +} //namespace Gui + + +#endif // GUI_ViewProviderPlacement_H diff --git a/src/Gui/ViewProviderPlane.cpp b/src/Gui/ViewProviderPlane.cpp new file mode 100644 index 0000000000..397b7e0b9a --- /dev/null +++ b/src/Gui/ViewProviderPlane.cpp @@ -0,0 +1,195 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2012 * + * * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include +#include +#include +#include "ViewProviderPlane.h" +#include "SoFCSelection.h" +#include "Application.h" +#include "Document.h" +#include "View3DInventorViewer.h" +#include "Inventor/SoAutoZoomTranslation.h" +#include "SoAxisCrossKit.h" +//#include + +#include +#include +#include +#include + +using namespace Gui; + +PROPERTY_SOURCE(Gui::ViewProviderPlane, Gui::ViewProviderGeometryObject) + + +ViewProviderPlane::ViewProviderPlane() +{ + + pMat = new SoMaterial(); + pMat->ref(); + + const float size = 2; + + static const SbVec3f verts[4] = + { + SbVec3f(size,size,0), SbVec3f(size,-size,0), + SbVec3f(-size,-size,0), SbVec3f(-size,size,0), + }; + + // indexes used to create the edges + static const int32_t lines[6] = + { + 0,1,2,3,0,-1 + }; + + pMat->diffuseColor.setNum(1); + pMat->diffuseColor.set1Value(0, SbColor(1.0f, 1.0f, 1.0f)); + + pCoords = new SoCoordinate3(); + pCoords->ref(); + pCoords->point.setNum(4); + pCoords->point.setValues(0, 4, verts); + + pLines = new SoIndexedLineSet(); + pLines->ref(); + pLines->coordIndex.setNum(6); + pLines->coordIndex.setValues(0, 6, lines); + sPixmap = "view-measurement"; +} + +ViewProviderPlane::~ViewProviderPlane() +{ + pCoords->unref(); + pLines->unref(); + pMat->unref(); +} + +void ViewProviderPlane::onChanged(const App::Property* prop) +{ + ViewProviderGeometryObject::onChanged(prop); +} + +std::vector ViewProviderPlane::getDisplayModes(void) const +{ + // add modes + std::vector StrList; + StrList.push_back("Base"); + return StrList; +} + +void ViewProviderPlane::setDisplayMode(const char* ModeName) +{ + if (strcmp(ModeName, "Base") == 0) + setDisplayMaskMode("Base"); + ViewProviderGeometryObject::setDisplayMode(ModeName); +} + +void ViewProviderPlane::attach(App::DocumentObject* pcObject) +{ + ViewProviderGeometryObject::attach(pcObject); + + SoAnnotation *lineSep = new SoAnnotation(); + + + SoAutoZoomTranslation *zoom = new SoAutoZoomTranslation; + + SoDrawStyle* style = new SoDrawStyle(); + style->lineWidth = 1.0f; + + SoMaterialBinding* matBinding = new SoMaterialBinding; + matBinding->value = SoMaterialBinding::PER_FACE; + + lineSep->addChild(zoom); + lineSep->addChild(style); + lineSep->addChild(matBinding); + lineSep->addChild(pMat); + lineSep->addChild(pCoords); + lineSep->addChild(pLines); + + addDisplayMaskMode(lineSep, "Base"); +} + +void ViewProviderPlane::updateData(const App::Property* prop) +{ + ViewProviderGeometryObject::updateData(prop); +} + +std::string ViewProviderPlane::getElement(const SoDetail* detail) const +{ + if (detail) { + if (detail->getTypeId() == SoLineDetail::getClassTypeId()) { + const SoLineDetail* line_detail = static_cast(detail); + int edge = line_detail->getLineIndex(); + if (edge == 0) + { + return std::string("Main"); + } + } + } + + return std::string(""); +} + +SoDetail* ViewProviderPlane::getDetail(const char* subelement) const +{ + SoLineDetail* detail = 0; + std::string subelem(subelement); + int edge = -1; + + if(subelem == "Main") edge = 0; + + if(edge >= 0) { + detail = new SoLineDetail(); + detail->setPartIndex(edge); + } + + return detail; +} + +bool ViewProviderPlane::isSelectable(void) const +{ + return true; +} +// ---------------------------------------------------------------------------- + + diff --git a/src/Gui/ViewProviderPlane.h b/src/Gui/ViewProviderPlane.h new file mode 100644 index 0000000000..9cef63ac4c --- /dev/null +++ b/src/Gui/ViewProviderPlane.h @@ -0,0 +1,77 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2012 * + * * + * 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_ViewProviderPlane_H +#define GUI_ViewProviderPlane_H + +#include "ViewProviderGeometryObject.h" +#include + +class SoFontStyle; +class SoText2; +class SoBaseColor; +class SoTranslation; +class SoCoordinate3; +class SoIndexedLineSet; +class SoEventCallback; +class SoMaterial; + +namespace Gui +{ + + +class GuiExport ViewProviderPlane : public ViewProviderGeometryObject +{ + PROPERTY_HEADER(Gui::ViewProviderPlane); + +public: + /// Constructor + ViewProviderPlane(void); + virtual ~ViewProviderPlane(); + + void attach(App::DocumentObject *); + void updateData(const App::Property*); + std::vector getDisplayModes(void) const; + void setDisplayMode(const char* ModeName); + + /// indicates if the ViewProvider use the new Selection model + virtual bool useNewSelectionModel(void) const {return true;} + /// indicates if the ViewProvider can be selected + virtual bool isSelectable(void) const ; + /// return a hit element to the selection path or 0 + virtual std::string getElement(const SoDetail *) const; + virtual SoDetail* getDetail(const char*) const; + +protected: + void onChanged(const App::Property* prop); + +private: + SoCoordinate3 * pCoords; + SoMaterial * pMat; + SoIndexedLineSet * pLines; +}; + +} //namespace Gui + + +#endif // GUI_ViewProviderPlane_H