Add all base system changes from the Assembly branch

This commit is contained in:
jriegel 2013-02-10 20:01:27 +01:00
parent f609573297
commit 0215757e79
10 changed files with 1039 additions and 0 deletions

56
src/App/Plane.cpp Normal file
View File

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

63
src/App/Plane.h Normal file
View File

@ -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

View File

@ -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 <Inventor/actions/SoGLRenderAction.h>
# include <Inventor/misc/SoState.h>
# include <math.h>
# include <cfloat>
#endif
#include <Inventor/actions/SoGetMatrixAction.h>
#include <Inventor/actions/SoGLRenderAction.h>
#include <Inventor/elements/SoModelMatrixElement.h>
#include <Inventor/elements/SoProjectionMatrixElement.h>
#include <Inventor/elements/SoViewingMatrixElement.h>
#include <Inventor/elements/SoViewVolumeElement.h>
#include <Inventor/elements/SoViewportRegionElement.h>
#include <Inventor/nodes/SoCamera.h>
#include <Base/Console.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/MainWindow.h>
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
#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<Gui::View3DInventor *>(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);
}

View File

@ -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 <Inventor/nodes/SoTranslation.h>
#include <Inventor/nodes/SoSubNode.h>
#include <Inventor/nodes/SoTransformation.h>
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

75
src/Gui/ProjectView.cpp Normal file
View File

@ -0,0 +1,75 @@
/***************************************************************************
* Copyright (c) 2012 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 <boost/signals.hpp>
# include <boost/bind.hpp>
# include <QAction>
# include <QActionGroup>
# include <QApplication>
# include <qcursor.h>
# include <qlayout.h>
# include <qstatusbar.h>
# include <QContextMenuEvent>
# include <QMenu>
# include <QPixmap>
# include <QTimer>
#endif
#include <QDirModel>
#include <Base/Console.h>
#include <App/Document.h>
#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"

61
src/Gui/ProjectView.h Normal file
View File

@ -0,0 +1,61 @@
/***************************************************************************
* Copyright (c) 2012 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 <QTreeView>
#include <App/Document.h>
#include <App/Application.h>
#include <Gui/DockWindow.h>
#include <Gui/Selection.h>
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

View File

@ -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 <sstream>
# include <QApplication>
# include <Inventor/SoPickedPoint.h>
# include <Inventor/events/SoMouseButtonEvent.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoBaseColor.h>
# include <Inventor/nodes/SoFontStyle.h>
# include <Inventor/nodes/SoPickStyle.h>
# include <Inventor/nodes/SoText2.h>
# include <Inventor/nodes/SoTranslation.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoIndexedLineSet.h>
# include <Inventor/nodes/SoMarkerSet.h>
# include <Inventor/nodes/SoDrawStyle.h>
#endif
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoAnnotation.h>
#include <Inventor/details/SoLineDetail.h>
#include "ViewProviderPlacement.h"
#include "SoFCSelection.h"
#include "Application.h"
#include "Document.h"
#include "View3DInventorViewer.h"
#include "Inventor/SoAutoZoomTranslation.h"
#include "SoAxisCrossKit.h"
//#include <SoDepthBuffer.h>
#include <App/PropertyGeo.h>
#include <App/PropertyStandard.h>
#include <App/MeasureDistance.h>
#include <Base/Console.h>
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<std::string> ViewProviderPlacement::getDisplayModes(void) const
{
// add modes
std::vector<std::string> 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<const SoLineDetail*>(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;
}
// ----------------------------------------------------------------------------

View File

@ -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 <QObject>
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<std::string> 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

View File

@ -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 <sstream>
# include <QApplication>
# include <Inventor/SoPickedPoint.h>
# include <Inventor/events/SoMouseButtonEvent.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoBaseColor.h>
# include <Inventor/nodes/SoFontStyle.h>
# include <Inventor/nodes/SoPickStyle.h>
# include <Inventor/nodes/SoText2.h>
# include <Inventor/nodes/SoTranslation.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoIndexedLineSet.h>
# include <Inventor/nodes/SoMarkerSet.h>
# include <Inventor/nodes/SoDrawStyle.h>
#endif
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoAnnotation.h>
#include <Inventor/details/SoLineDetail.h>
#include "ViewProviderPlane.h"
#include "SoFCSelection.h"
#include "Application.h"
#include "Document.h"
#include "View3DInventorViewer.h"
#include "Inventor/SoAutoZoomTranslation.h"
#include "SoAxisCrossKit.h"
//#include <SoDepthBuffer.h>
#include <App/PropertyGeo.h>
#include <App/PropertyStandard.h>
#include <App/MeasureDistance.h>
#include <Base/Console.h>
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<std::string> ViewProviderPlane::getDisplayModes(void) const
{
// add modes
std::vector<std::string> 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<const SoLineDetail*>(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;
}
// ----------------------------------------------------------------------------

View File

@ -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 <QObject>
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<std::string> 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