Work on Gui of Datum features

This commit is contained in:
jrheinlaender
2013-04-15 21:04:27 +04:30
committed by Stefan Tröger
parent d8d945a8b6
commit 4f80b72508
6 changed files with 390 additions and 36 deletions

View File

@@ -43,8 +43,11 @@
#endif
#include <App/Plane.h>
#include "DatumFeature.h"
#include <Base/Tools.h>
#include <Base/Exception.h>
#include "Mod/Part/App/PrimitiveFeature.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
@@ -52,7 +55,6 @@
using namespace PartDesign;
PROPERTY_SOURCE_ABSTRACT(PartDesign::Datum, PartDesign::Feature)
Datum::Datum(void)
@@ -77,13 +79,174 @@ short Datum::mustExecute(void) const
void Datum::onChanged(const App::Property* prop)
{
if (prop == &References) {
refTypes.clear();
std::vector<App::DocumentObject*> refs = References.getValues();
std::vector<std::string> refnames = References.getSubValues();
for (int r = 0; r < refs.size(); r++)
refTypes.insert(getRefType(refs[r], refnames[r]));
}
PartDesign::Feature::onChanged(prop);
}
// Note: We don't distinguish between e.g. datum lines and edges here
// These values are just markers so it doesn't matter that they are Part features
#define PLANE Part::Plane::getClassTypeId()
#define LINE Part::Line::getClassTypeId()
#define POINT Part::Vertex::getClassTypeId()
const Base::Type Datum::getRefType(const App::DocumentObject* obj, const std::string& subname)
{
Base::Type type = obj->getTypeId();
if ((type == App::Plane::getClassTypeId()) || (type == PartDesign::Plane::getClassTypeId()))
return PLANE;
else if (type == PartDesign::Line::getClassTypeId())
return LINE;
else if (type == PartDesign::Point::getClassTypeId())
return POINT;
else if (type.isDerivedFrom(Part::Feature::getClassTypeId())) {
// Note: For now, only planar references are possible
if (subname.size() > 4 && subname.substr(0,4) == "Face")
return PLANE;
else if (subname.size() > 4 && subname.substr(0,4) == "Edge")
return LINE;
else if (subname.size() > 6 && subname.substr(0,6) == "Vertex")
return POINT;
}
throw Base::Exception("PartDesign::Datum::getRefType(): Illegal object type");
}
// ================================ Initialize the hints =====================
std::map<std::multiset<Base::Type>, std::set<Base::Type> > Point::hints = std::map<std::multiset<Base::Type>, std::set<Base::Type> >();
void Point::initHints()
{
std::set<Base::Type> DONE;
DONE.insert(PartDesign::Point::getClassTypeId());
std::multiset<Base::Type> key;
std::set<Base::Type> value;
key.insert(POINT);
hints[key] = DONE; // POINT -> DONE. Point from another point or vertex
key.clear(); value.clear();
key.insert(LINE);
value.insert(LINE); value.insert(PLANE);
hints[key] = value; // LINE -> LINE or PLANE
key.clear(); value.clear();
key.insert(LINE); key.insert(LINE);
hints[key] = DONE; // {LINE, LINE} -> DONE. Point from two lines or edges
key.clear(); value.clear();
key.insert(LINE); key.insert(PLANE);
hints[key] = DONE; // {LINE, PLANE} -> DONE. Point from line and plane
key.clear(); value.clear();
key.insert(PLANE);
value.insert(PLANE); value.insert(LINE);
hints[key] = value; // PLANE -> PLANE or LINE
key.clear(); value.clear();
key.insert(PLANE); key.insert(PLANE);
value.insert(PLANE);
hints[key] = value; // {PLANE, PLANE} -> PLANE
key.clear(); value.clear();
key.insert(PLANE); key.insert(PLANE); key.insert(PLANE);
hints[key] = DONE; // {PLANE, PLANE, PLANE} -> DONE. Point from three planes
key.clear(); value.clear();
value.insert(POINT); value.insert(LINE); value.insert(PLANE);
hints[key] = value;
}
std::map<std::multiset<Base::Type>, std::set<Base::Type> > Line::hints = std::map<std::multiset<Base::Type>, std::set<Base::Type> >();
void Line::initHints()
{
std::set<Base::Type> DONE;
DONE.insert(PartDesign::Line::getClassTypeId());
std::multiset<Base::Type> key;
std::set<Base::Type> value;
key.insert(LINE);
hints[key] = DONE; // LINE -> DONE. Line from another line or edge
key.clear(); value.clear();
key.insert(POINT);
value.insert(POINT);
hints[key] = value; // POINT -> POINT
key.clear(); value.clear();
key.insert(POINT); key.insert(POINT);
hints[key] = DONE; // {POINT, POINT} -> DONE. Line from two points or vertices
key.clear(); value.clear();
key.insert(PLANE);
value.insert(PLANE);
hints[key] = value; // PLANE -> PLANE
key.clear(); value.clear();
key.insert(PLANE); key.insert(PLANE);
hints[key] = DONE; // {PLANE, PLANE} -> DONE. Line from two planes or faces
key.clear(); value.clear();
value.insert(POINT); value.insert(LINE); value.insert(PLANE);
hints[key] = value;
}
std::map<std::multiset<Base::Type>, std::set<Base::Type> > Plane::hints = std::map<std::multiset<Base::Type>, std::set<Base::Type> >();
void Plane::initHints()
{
std::set<Base::Type> DONE;
DONE.insert(PartDesign::Plane::getClassTypeId());
std::multiset<Base::Type> key;
std::set<Base::Type> value;
key.insert(PLANE);
hints[key] = DONE; // PLANE -> DONE. Plane from another plane or face
key.clear(); value.clear();
key.insert(POINT);
value.insert(POINT); value.insert(LINE);
hints[key] = value; // POINT -> POINT or LINE
key.clear(); value.clear();
key.insert(POINT); key.insert(LINE);
hints[key] = DONE; // {POINT, LINE} -> DONE. Plane from point/vertex and line/edge
key.clear(); value.clear();
key.insert(POINT); key.insert(POINT);
value.insert(POINT);
hints[key] = value; // {POINT, POINT} -> POINT
key.clear(); value.clear();
key.insert(POINT); key.insert(POINT); key.insert(POINT);
hints[key] = DONE; // {POINT, POINT, POINT} -> DONE. Plane from 3 points or vertices
key.clear(); value.clear();
key.insert(LINE);
value.insert(POINT);
hints[key] = value; // LINE -> POINT
key.clear(); value.clear();
value.insert(POINT); value.insert(LINE); value.insert(PLANE);
hints[key] = value;
}
// ============================================================================
PROPERTY_SOURCE(PartDesign::Point, PartDesign::Datum)
Point::Point()
{
{
}
Point::~Point()
@@ -97,8 +260,43 @@ short Point::mustExecute() const
App::DocumentObjectExecReturn *Point::execute(void)
{
std::set<Base::Type> hint = getHint();
if (!((hint.size() == 1) && (hint.find(PartDesign::Point::getClassTypeId()) != hint.end())))
return App::DocumentObject::StdReturn; // incomplete references
// Extract the shapes of the references
std::vector<TopoDS_Shape> shapes;
std::vector<App::DocumentObject*> refs = References.getValues();
std::vector<std::string> refnames = References.getSubValues();
for (int i = 0; i < refs.size(); i++) {
if (!refs[i]->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("PartDesign::Point: Invalid reference type");
Part::Feature* feature = static_cast<Part::Feature*>(refs[i]);
const TopoDS_Shape& sh = feature->Shape.getValue();
if (sh.IsNull())
return new App::DocumentObjectExecReturn("PartDesign::Point: Reference has NULL shape");
if (refnames[i].empty()) {
// Datum feature or App::Plane
shapes.push_back(sh);
} else {
// Get subshape
TopoDS_Shape subshape = feature->Shape.getShape().getSubShape(refnames[i].c_str());
if (subshape.IsNull())
return new App::DocumentObjectExecReturn("PartDesign::Point: Reference has NULL subshape");
shapes.push_back(subshape);
}
}
// Find the point
gp_Pnt point(0,0,0);
// TODO: Find the point
if (shapes.size() == 1) {
// Point from vertex or other point
if (shapes[0].ShapeType() != TopAbs_VERTEX)
return new App::DocumentObjectExecReturn("PartDesign::Point::execute(): Internal error, unexpected ShapeType");
TopoDS_Vertex v = TopoDS::Vertex(shapes[0]);
//point.X = v.
}
BRepBuilderAPI_MakeVertex MakeVertex(point);
const TopoDS_Vertex& vertex = MakeVertex.Vertex();
@@ -108,6 +306,15 @@ App::DocumentObjectExecReturn *Point::execute(void)
}
const std::set<Base::Type> Point::getHint()
{
if (hints.find(refTypes) != hints.end())
return hints[refTypes];
else
return std::set<Base::Type>();
}
PROPERTY_SOURCE(PartDesign::Line, PartDesign::Datum)
Line::Line()
@@ -139,6 +346,15 @@ App::DocumentObjectExecReturn *Line::execute(void)
}
const std::set<Base::Type> Line::getHint()
{
if (hints.find(refTypes) != hints.end())
return hints[refTypes];
else
return std::set<Base::Type>();
}
PROPERTY_SOURCE(PartDesign::Plane, PartDesign::Datum)
Plane::Plane()
@@ -172,3 +388,12 @@ App::DocumentObjectExecReturn *Plane::execute(void)
return App::DocumentObject::StdReturn;
}
const std::set<Base::Type> Plane::getHint()
{
if (hints.find(refTypes) != hints.end())
return hints[refTypes];
else
return std::set<Base::Type>();
}