Fixed problems with loading of FEM constraint objects

This commit is contained in:
jrheinlaender
2013-02-22 16:16:03 +04:30
parent d48542cf56
commit 517443fb59
13 changed files with 72 additions and 41 deletions

View File

@@ -78,9 +78,8 @@ App::DocumentObjectExecReturn *Constraint::execute(void)
void Constraint::onChanged(const App::Property* prop)
{
//Base::Console().Error("Constraint::onChanged()\n");
Base::Console().Error("Constraint::onChanged() %s\n", prop->getName());
if (prop == &References) {
Base::Console().Error("References\n");
// If References are changed, recalculate the normal direction. If no useful reference is found,
// use z axis or previous value. If several faces are selected, only the first one is used
std::vector<App::DocumentObject*> Objects = References.getValues();
@@ -108,28 +107,24 @@ void Constraint::onChanged(const App::Property* prop)
normal.Normalize();
NormalDirection.setValue(normal.X(), normal.Y(), normal.Z());
// One face is enough...
DocumentObject::onChanged(prop);
App::DocumentObject::onChanged(prop);
return;
}
}
}
}
DocumentObject::onChanged(prop);
App::DocumentObject::onChanged(prop);
}
void Constraint::onDocumentRestored()
{
Base::Console().Error("onDocumentRestored\n");
// This seems to be the only way to make the ViewProvider display the constraint
References.touch();
App::DocumentObject::onDocumentRestored();
}
void Constraint::onSettingDocument()
{
Base::Console().Error("onSettingDocument\n");
}
void Constraint::getPoints(std::vector<Base::Vector3f> &points, std::vector<Base::Vector3f> &normals) const
const bool Constraint::getPoints(std::vector<Base::Vector3f> &points, std::vector<Base::Vector3f> &normals) const
{
std::vector<App::DocumentObject*> Objects = References.getValues();
std::vector<std::string> SubElements = References.getSubValues();
@@ -141,6 +136,8 @@ void Constraint::getPoints(std::vector<Base::Vector3f> &points, std::vector<Base
App::DocumentObject* obj = Objects[i];
Part::Feature* feat = static_cast<Part::Feature*>(obj);
const Part::TopoShape& toposhape = feat->Shape.getShape();
if (toposhape.isNull())
return false;
sh = toposhape.getSubShape(SubElements[i].c_str());
if (sh.ShapeType() == TopAbs_VERTEX) {
@@ -219,17 +216,22 @@ void Constraint::getPoints(std::vector<Base::Vector3f> &points, std::vector<Base
}
}
}
return true;
}
void Constraint::getCylinder(float& radius, float& height, Base::Vector3f& base, Base::Vector3f& axis) const
const bool Constraint::getCylinder(float& radius, float& height, Base::Vector3f& base, Base::Vector3f& axis) const
{
std::vector<App::DocumentObject*> Objects = References.getValues();
std::vector<std::string> SubElements = References.getSubValues();
if (Objects.empty())
return;
return false;
App::DocumentObject* obj = Objects[0];
Part::Feature* feat = static_cast<Part::Feature*>(obj);
TopoDS_Shape sh = feat->Shape.getShape().getSubShape(SubElements[0].c_str());
Part::TopoShape toposhape = feat->Shape.getShape();
if (toposhape.isNull())
return false;
TopoDS_Shape sh = toposhape.getSubShape(SubElements[0].c_str());
TopoDS_Face face = TopoDS::Face(sh);
BRepAdaptor_Surface surface(face);
@@ -243,6 +245,8 @@ void Constraint::getCylinder(float& radius, float& height, Base::Vector3f& base,
base = Base::Vector3f(b.X(), b.Y(), b.Z());
gp_Dir dir = cyl.Axis().Direction();
axis = Base::Vector3f(dir.X(), dir.Y(), dir.Z());
return true;
}
Base::Vector3f Constraint::getBasePoint(const Base::Vector3f& base, const Base::Vector3f& axis,

View File

@@ -55,12 +55,11 @@ public:
protected:
virtual void onChanged(const App::Property* prop);
virtual void onDocumentRestored();
virtual void onSettingDocument();
protected:
/// Calculate the points where symbols should be drawn
void getPoints(std::vector<Base::Vector3f>& points, std::vector<Base::Vector3f>& normals) const;
void getCylinder(float& radius, float& height, Base::Vector3f& base, Base::Vector3f& axis) const;
const bool getPoints(std::vector<Base::Vector3f>& points, std::vector<Base::Vector3f>& normals) const;
const bool getCylinder(float& radius, float& height, Base::Vector3f& base, Base::Vector3f& axis) const;
Base::Vector3f getBasePoint(const Base::Vector3f& base, const Base::Vector3f& axis,
const App::PropertyLinkSub &location, const float& dist);

View File

@@ -58,11 +58,13 @@ ConstraintBearing::ConstraintBearing()
App::DocumentObjectExecReturn *ConstraintBearing::execute(void)
{
Base::Console().Error("ConstraintBearing: execute()\n");
return Constraint::execute();
}
void ConstraintBearing::onChanged(const App::Property* prop)
{
Base::Console().Error("ConstraintBearing: onChanged %s\n", prop->getName());
// Note: If we call this at the end, then the symbol ist not oriented correctly initially
// because the NormalDirection has not been calculated yet
Constraint::onChanged(prop);
@@ -71,7 +73,8 @@ void ConstraintBearing::onChanged(const App::Property* prop)
// Find data of cylinder
float radius, height;
Base::Vector3f base, axis;
getCylinder(radius, height, base, axis);
if (!getCylinder(radius, height, base, axis))
return;
Radius.setValue(radius);
Axis.setValue(axis);
Height.setValue(height);
@@ -80,7 +83,6 @@ void ConstraintBearing::onChanged(const App::Property* prop)
if (Location.getValue() != NULL) {
base = getBasePoint(base, axis, Location, Dist.getValue());
}
Base::Console().Error("Basepoint2: %f, %f, %f\n", base.x, base.y, base.z);
BasePoint.setValue(base);
BasePoint.touch(); // This triggers ViewProvider::updateData()
} else if ((prop == &Location) || (prop == &Dist)) {
@@ -107,9 +109,9 @@ void ConstraintBearing::onChanged(const App::Property* prop)
float radius, height;
Base::Vector3f base, axis;
getCylinder(radius, height, base, axis);
if (!getCylinder(radius, height, base, axis))
return;
base = getBasePoint(base + axis * height/2, axis, Location, Dist.getValue());
Base::Console().Error("Basepoint: %f, %f, %f\n", base.x, base.y, base.z);
BasePoint.setValue(base);
BasePoint.touch();
}

View File

@@ -75,9 +75,10 @@ void ConstraintFixed::onChanged(const App::Property* prop)
if (prop == &References) {
std::vector<Base::Vector3f> points;
std::vector<Base::Vector3f> normals;
getPoints(points, normals);
Points.setValues(points);
Normals.setValues(normals);
Points.touch(); // This triggers ViewProvider::updateData()
if (getPoints(points, normals)) {
Points.setValues(points);
Normals.setValues(normals);
Points.touch(); // This triggers ViewProvider::updateData()
}
}
}

View File

@@ -70,9 +70,10 @@ void ConstraintForce::onChanged(const App::Property* prop)
if (prop == &References) {
std::vector<Base::Vector3f> points;
std::vector<Base::Vector3f> normals;
getPoints(points, normals);
Points.setValues(points); // We don't use the normals because all arrows should have the same direction
Points.touch(); // This triggers ViewProvider::updateData()
if (getPoints(points, normals)) {
Points.setValues(points); // We don't use the normals because all arrows should have the same direction
Points.touch(); // This triggers ViewProvider::updateData()
}
} else if (prop == &Direction) {
App::DocumentObject* obj = Direction.getValue();
std::vector<std::string> names = Direction.getSubValues();