Specialized viewproviders for datum features, create points from intersection of edges and faces
This commit is contained in:
committed by
Stefan Tröger
parent
9ca63b603a
commit
696bdf9a2a
@@ -27,6 +27,15 @@
|
||||
# include <QMessageBox>
|
||||
# include <QAction>
|
||||
# include <QMenu>
|
||||
# include <Inventor/nodes/SoSeparator.h>
|
||||
# include <Inventor/nodes/SoShapeHints.h>
|
||||
# include <Inventor/nodes/SoBaseColor.h>
|
||||
# include <Inventor/nodes/SoMarkerSet.h>
|
||||
# include <Inventor/nodes/SoVertexProperty.h>
|
||||
# include <TopoDS_Vertex.hxx>
|
||||
# include <TopoDS.hxx>
|
||||
# include <BRep_Tool.hxx>
|
||||
# include <gp_Pnt.hxx>
|
||||
#endif
|
||||
|
||||
#include "ViewProviderDatum.h"
|
||||
@@ -34,22 +43,26 @@
|
||||
#include "Workbench.h"
|
||||
#include <Mod/PartDesign/App/DatumFeature.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Command.h>
|
||||
|
||||
using namespace PartDesignGui;
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderDatum,PartDesignGui::ViewProvider)
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderDatum,Gui::ViewProviderGeometryObject)
|
||||
|
||||
ViewProviderDatum::ViewProviderDatum()
|
||||
{
|
||||
pShapeSep = new SoSeparator();
|
||||
pShapeSep->ref();
|
||||
}
|
||||
|
||||
ViewProviderDatum::~ViewProviderDatum()
|
||||
{
|
||||
pShapeSep->unref();
|
||||
}
|
||||
|
||||
void ViewProviderDatum::attach(App::DocumentObject *obj)
|
||||
{
|
||||
ViewProvider::attach(obj);
|
||||
ViewProviderDocumentObject::attach(obj);
|
||||
|
||||
PartDesign::Datum* pcDatum = static_cast<PartDesign::Datum*>(getObject());
|
||||
if (pcDatum->getTypeId() == PartDesign::Plane::getClassTypeId())
|
||||
@@ -58,6 +71,42 @@ void ViewProviderDatum::attach(App::DocumentObject *obj)
|
||||
datumType = QObject::tr("Line");
|
||||
else if (pcDatum->getTypeId() == PartDesign::Point::getClassTypeId())
|
||||
datumType = QObject::tr("Point");
|
||||
|
||||
SoSeparator* sep = new SoSeparator();
|
||||
SoShapeHints* hints = new SoShapeHints();
|
||||
hints->shapeType.setValue(SoShapeHints::UNKNOWN_SHAPE_TYPE);
|
||||
hints->vertexOrdering.setValue(SoShapeHints::COUNTERCLOCKWISE);
|
||||
SoBaseColor* color = new SoBaseColor();
|
||||
color->rgb.setValue(0.9, 0.9, 0.2);
|
||||
sep->addChild(hints);
|
||||
sep->addChild(color);
|
||||
sep->addChild(pShapeSep);
|
||||
addDisplayMaskMode(sep, "Base");
|
||||
}
|
||||
|
||||
std::vector<std::string> ViewProviderDatum::getDisplayModes(void) const
|
||||
{
|
||||
// add modes
|
||||
std::vector<std::string> StrList;
|
||||
StrList.push_back("Base");
|
||||
return StrList;
|
||||
}
|
||||
|
||||
void ViewProviderDatum::setDisplayMode(const char* ModeName)
|
||||
{
|
||||
if (strcmp(ModeName, "Base") == 0)
|
||||
setDisplayMaskMode("Base");
|
||||
ViewProviderDocumentObject::setDisplayMode(ModeName);
|
||||
}
|
||||
|
||||
void ViewProviderDatum::onChanged(const App::Property* prop)
|
||||
{
|
||||
/*if (prop == &Shape) {
|
||||
updateData(prop);
|
||||
}
|
||||
else {*/
|
||||
ViewProviderDocumentObject::onChanged(prop);
|
||||
//}
|
||||
}
|
||||
|
||||
void ViewProviderDatum::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
@@ -65,11 +114,14 @@ void ViewProviderDatum::setupContextMenu(QMenu* menu, QObject* receiver, const c
|
||||
QAction* act;
|
||||
act = menu->addAction(QObject::tr("Edit datum ") + datumType, receiver, member);
|
||||
act->setData(QVariant((int)ViewProvider::Default));
|
||||
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
|
||||
Gui::ViewProviderGeometryObject::setupContextMenu(menu, receiver, member);
|
||||
}
|
||||
|
||||
bool ViewProviderDatum::setEdit(int ModNum)
|
||||
{
|
||||
if (!ViewProvider::setEdit(ModNum))
|
||||
return false;
|
||||
|
||||
if (ModNum == ViewProvider::Default ) {
|
||||
// When double-clicking on the item for this datum feature the
|
||||
// object unsets and sets its edit mode without closing
|
||||
@@ -94,6 +146,9 @@ bool ViewProviderDatum::setEdit(int ModNum)
|
||||
// clear the selection (convenience)
|
||||
Gui::Selection().clearSelection();
|
||||
|
||||
// always change to PartDesign WB, remember where we come from
|
||||
oldWb = Gui::Command::assureWorkbench("PartDesignWorkbench");
|
||||
|
||||
// start the edit dialog
|
||||
if (datumDlg)
|
||||
Gui::Control().showDialog(datumDlg);
|
||||
@@ -103,19 +158,126 @@ bool ViewProviderDatum::setEdit(int ModNum)
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return ViewProviderPart::setEdit(ModNum);
|
||||
return ViewProvider::setEdit(ModNum);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderDatum::unsetEdit(int ModNum)
|
||||
{
|
||||
// return to the WB we were in before editing the PartDesign feature
|
||||
Gui::Command::assureWorkbench(oldWb.c_str());
|
||||
|
||||
if (ModNum == ViewProvider::Default) {
|
||||
// when pressing ESC make sure to close the dialog
|
||||
Gui::Control().closeDialog();
|
||||
}
|
||||
else {
|
||||
PartGui::ViewProviderPart::unsetEdit(ModNum);
|
||||
Gui::ViewProviderGeometryObject::unsetEdit(ModNum);
|
||||
}
|
||||
}
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderDatumPoint,PartDesignGui::ViewProviderDatum)
|
||||
|
||||
ViewProviderDatumPoint::ViewProviderDatumPoint()
|
||||
{
|
||||
SoMarkerSet* points = new SoMarkerSet();
|
||||
points->markerIndex = SoMarkerSet::DIAMOND_FILLED_9_9;
|
||||
points->numPoints = 1;
|
||||
pShapeSep->addChild(points);
|
||||
}
|
||||
|
||||
ViewProviderDatumPoint::~ViewProviderDatumPoint()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ViewProviderDatumPoint::updateData(const App::Property* prop)
|
||||
{
|
||||
// Gets called whenever a property of the attached object changes
|
||||
PartDesign::Point* pcDatum = static_cast<PartDesign::Point*>(this->getObject());
|
||||
|
||||
if (strcmp(prop->getName(),"_Point") == 0) {
|
||||
Base::Vector3f p = pcDatum->_Point.getValue();
|
||||
SoMFVec3f v;
|
||||
v.set1Value(0, p.x, p.y, p.z);
|
||||
SoVertexProperty* vprop = new SoVertexProperty();
|
||||
vprop->vertex = v;
|
||||
SoMarkerSet* points = static_cast<SoMarkerSet*>(pShapeSep->getChild(0));
|
||||
points->vertexProperty = vprop;
|
||||
}
|
||||
|
||||
ViewProviderDatum::updateData(prop);
|
||||
}
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderDatumLine,PartDesignGui::ViewProviderDatum)
|
||||
|
||||
ViewProviderDatumLine::ViewProviderDatumLine()
|
||||
{
|
||||
/*
|
||||
SoMarkerSet* points = new SoMarkerSet();
|
||||
points->markerIndex = SoMarkerSet::DIAMOND_FILLED_9_9;
|
||||
points->numPoints = 1;
|
||||
pShapeSep->addChild(points);
|
||||
*/
|
||||
}
|
||||
|
||||
ViewProviderDatumLine::~ViewProviderDatumLine()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ViewProviderDatumLine::updateData(const App::Property* prop)
|
||||
{
|
||||
// Gets called whenever a property of the attached object changes
|
||||
PartDesign::Line* pcDatum = static_cast<PartDesign::Line*>(this->getObject());
|
||||
|
||||
/*
|
||||
if (strcmp(prop->getName(),"_Point") == 0) {
|
||||
Base::Vector3f p = pcDatum->_Point.getValue();
|
||||
SoMFVec3f v;
|
||||
v.set1Value(0, p.x, p.y, p.z);
|
||||
SoVertexProperty* vprop = new SoVertexProperty();
|
||||
vprop->vertex = v;
|
||||
SoMarkerSet* points = static_cast<SoMarkerSet*>(pShapeSep->getChild(0));
|
||||
points->vertexProperty = vprop;
|
||||
}*/
|
||||
|
||||
ViewProviderDatum::updateData(prop);
|
||||
}
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderDatumPlane,PartDesignGui::ViewProviderDatum)
|
||||
|
||||
ViewProviderDatumPlane::ViewProviderDatumPlane()
|
||||
{
|
||||
/*
|
||||
SoMarkerSet* points = new SoMarkerSet();
|
||||
points->markerIndex = SoMarkerSet::DIAMOND_FILLED_9_9;
|
||||
points->numPoints = 1;
|
||||
pShapeSep->addChild(points);
|
||||
*/
|
||||
}
|
||||
|
||||
ViewProviderDatumPlane::~ViewProviderDatumPlane()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ViewProviderDatumPlane::updateData(const App::Property* prop)
|
||||
{
|
||||
// Gets called whenever a property of the attached object changes
|
||||
PartDesign::Plane* pcDatum = static_cast<PartDesign::Plane*>(this->getObject());
|
||||
/*
|
||||
if (strcmp(prop->getName(),"_Point") == 0) {
|
||||
Base::Vector3f p = pcDatum->_Point.getValue();
|
||||
SoMFVec3f v;
|
||||
v.set1Value(0, p.x, p.y, p.z);
|
||||
SoVertexProperty* vprop = new SoVertexProperty();
|
||||
vprop->vertex = v;
|
||||
SoMarkerSet* points = static_cast<SoMarkerSet*>(pShapeSep->getChild(0));
|
||||
points->vertexProperty = vprop;
|
||||
}*/
|
||||
|
||||
ViewProviderDatum::updateData(prop);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user