Intgrate Jans FEM PullRequest
This commit is contained in:
@@ -41,6 +41,11 @@
|
||||
#include "FemSetNodesObject.h"
|
||||
|
||||
#include "HypothesisPy.h"
|
||||
#include "FemConstraintBearing.h"
|
||||
#include "FemConstraintFixed.h"
|
||||
#include "FemConstraintForce.h"
|
||||
#include "FemConstraintGear.h"
|
||||
#include "FemConstraintPulley.h"
|
||||
|
||||
extern struct PyMethodDef Fem_methods[];
|
||||
|
||||
@@ -115,6 +120,12 @@ void AppFemExport initFem()
|
||||
Fem::FemSetGeometryObject ::init();
|
||||
Fem::FemSetNodesObject ::init();
|
||||
|
||||
Fem::Constraint ::init();
|
||||
Fem::ConstraintBearing ::init();
|
||||
Fem::ConstraintFixed ::init();
|
||||
Fem::ConstraintForce ::init();
|
||||
Fem::ConstraintGear ::init();
|
||||
Fem::ConstraintPulley ::init();
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -24,10 +24,10 @@ set(Fem_LIBS
|
||||
Mesh
|
||||
FreeCADApp
|
||||
)
|
||||
|
||||
if(SMESH_FOUND)
|
||||
include_directories( ${SMESH_INCLUDE_DIR} )
|
||||
list( APPEND Fem_LIBS ${SMESH_LIBRARIES} )
|
||||
|
||||
if(SMESH_FOUND)
|
||||
include_directories( ${SMESH_INCLUDE_DIR} )
|
||||
list( APPEND Fem_LIBS ${SMESH_LIBRARIES} )
|
||||
endif(SMESH_FOUND)
|
||||
|
||||
generate_from_xml(FemMeshPy)
|
||||
@@ -64,6 +64,18 @@ SET(Fem_SRCS
|
||||
FemMesh.h
|
||||
FemMeshProperty.cpp
|
||||
FemMeshProperty.h
|
||||
FemConstraint.cpp
|
||||
FemConstraint.h
|
||||
FemConstraintBearing.h
|
||||
FemConstraintBearing.cpp
|
||||
FemConstraintFixed.cpp
|
||||
FemConstraintFixed.h
|
||||
FemConstraintForce.cpp
|
||||
FemConstraintForce.h
|
||||
FemConstraintGear.cpp
|
||||
FemConstraintGear.h
|
||||
FemConstraintPulley.cpp
|
||||
FemConstraintPulley.h
|
||||
${Mod_SRCS}
|
||||
${Python_SRCS}
|
||||
)
|
||||
|
||||
329
src/Mod/Fem/App/FemConstraint.cpp
Normal file
329
src/Mod/Fem/App/FemConstraint.cpp
Normal file
@@ -0,0 +1,329 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 <TopoDS.hxx>
|
||||
# include <BRepGProp_Face.hxx>
|
||||
# include <gp_Vec.hxx>
|
||||
# include <gp_Pnt.hxx>
|
||||
# include <gp_Pln.hxx>
|
||||
# include <gp_Cylinder.hxx>
|
||||
# include <gp_Ax3.hxx>
|
||||
# include <BRepAdaptor_Curve.hxx>
|
||||
# include <GCPnts_AbscissaPoint.hxx>
|
||||
# include <Adaptor3d_IsoCurve.hxx>
|
||||
# include <Adaptor3d_HSurface.hxx>
|
||||
# include <BRepAdaptor_HSurface.hxx>
|
||||
# include <BRepAdaptor_Surface.hxx>
|
||||
# include <GProp_GProps.hxx>
|
||||
# include <BRepGProp.hxx>
|
||||
# include <TopoDS_Vertex.hxx>
|
||||
# include <BRepClass_FaceClassifier.hxx>
|
||||
# include <BRep_Tool.hxx>
|
||||
# include <BRepGProp_Face.hxx>
|
||||
# include <ShapeAnalysis.hxx>
|
||||
# include <GeomAPI_ProjectPointOnSurf.hxx>
|
||||
# include <GeomAPI_IntCS.hxx>
|
||||
# include <Geom_Plane.hxx>
|
||||
# include <Geom_Line.hxx>
|
||||
# include <Precision.hxx>
|
||||
#endif
|
||||
|
||||
#include "FemConstraint.h"
|
||||
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
using namespace Fem;
|
||||
|
||||
PROPERTY_SOURCE(Fem::Constraint, App::DocumentObject);
|
||||
|
||||
Constraint::Constraint()
|
||||
{
|
||||
ADD_PROPERTY_TYPE(References,(0,0),"Constraint",(App::PropertyType)(App::Prop_None),"Elements where the constraint is applied");
|
||||
ADD_PROPERTY_TYPE(NormalDirection,(Base::Vector3f(0,0,1)),"Constraint",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),"Normal direction pointing outside of solid");
|
||||
}
|
||||
|
||||
Constraint::~Constraint()
|
||||
{
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *Constraint::execute(void)
|
||||
{
|
||||
References.touch();
|
||||
return StdReturn;
|
||||
}
|
||||
|
||||
void Constraint::onChanged(const App::Property* prop)
|
||||
{
|
||||
//Base::Console().Error("Constraint::onChanged() %s\n", prop->getName());
|
||||
if (prop == &References) {
|
||||
// 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();
|
||||
std::vector<std::string> SubElements = References.getSubValues();
|
||||
|
||||
// Extract geometry from References
|
||||
TopoDS_Shape sh;
|
||||
|
||||
for (int i = 0; i < Objects.size(); i++) {
|
||||
App::DocumentObject* obj = Objects[i];
|
||||
Part::Feature* feat = static_cast<Part::Feature*>(obj);
|
||||
const Part::TopoShape& toposhape = feat->Shape.getShape();
|
||||
if (!toposhape._Shape.IsNull()) {
|
||||
sh = toposhape.getSubShape(SubElements[i].c_str());
|
||||
|
||||
if (sh.ShapeType() == TopAbs_FACE) {
|
||||
// Get face normal in center point
|
||||
TopoDS_Face face = TopoDS::Face(sh);
|
||||
BRepGProp_Face props(face);
|
||||
gp_Vec normal;
|
||||
gp_Pnt center;
|
||||
double u1,u2,v1,v2;
|
||||
props.Bounds(u1,u2,v1,v2);
|
||||
props.Normal((u1+u2)/2.0,(v1+v2)/2.0,center,normal);
|
||||
normal.Normalize();
|
||||
NormalDirection.setValue(normal.X(), normal.Y(), normal.Z());
|
||||
// One face is enough...
|
||||
App::DocumentObject::onChanged(prop);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
App::DocumentObject::onChanged(prop);
|
||||
}
|
||||
|
||||
void Constraint::onDocumentRestored()
|
||||
{
|
||||
// This seems to be the only way to make the ViewProvider display the constraint
|
||||
References.touch();
|
||||
App::DocumentObject::onDocumentRestored();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// Extract geometry from References
|
||||
TopoDS_Shape sh;
|
||||
|
||||
for (int i = 0; i < Objects.size(); i++) {
|
||||
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) {
|
||||
const TopoDS_Vertex& vertex = TopoDS::Vertex(sh);
|
||||
gp_Pnt p = BRep_Tool::Pnt(vertex);
|
||||
points.push_back(Base::Vector3f(p.X(), p.Y(), p.Z()));
|
||||
normals.push_back(NormalDirection.getValue());
|
||||
} else if (sh.ShapeType() == TopAbs_EDGE) {
|
||||
BRepAdaptor_Curve curve(TopoDS::Edge(sh));
|
||||
double fp = curve.FirstParameter();
|
||||
double lp = curve.LastParameter();
|
||||
GProp_GProps props;
|
||||
BRepGProp::LinearProperties(TopoDS::Edge(sh), props);
|
||||
double l = props.Mass();
|
||||
// Create points with 10 units distance, but at least one at the beginning and end of the edge
|
||||
int steps;
|
||||
if (l >= 20)
|
||||
steps = round(l / 10);
|
||||
else
|
||||
steps = 1;
|
||||
double step = (lp - fp) / steps;
|
||||
for (int i = 0; i < steps + 1; i++) {
|
||||
gp_Pnt p = curve.Value(i * step);
|
||||
points.push_back(Base::Vector3f(p.X(), p.Y(), p.Z()));
|
||||
normals.push_back(NormalDirection.getValue());
|
||||
}
|
||||
} else if (sh.ShapeType() == TopAbs_FACE) {
|
||||
TopoDS_Face face = TopoDS::Face(sh);
|
||||
// Surface boundaries
|
||||
BRepAdaptor_Surface surface(face);
|
||||
double ufp = surface.FirstUParameter();
|
||||
double ulp = surface.LastUParameter();
|
||||
double vfp = surface.FirstVParameter();
|
||||
double vlp = surface.LastVParameter();
|
||||
// Surface normals
|
||||
BRepGProp_Face props(face);
|
||||
gp_Vec normal;
|
||||
gp_Pnt center;
|
||||
// Get an estimate for the number of arrows by finding the average length of curves
|
||||
Handle(Adaptor3d_HSurface) hsurf;
|
||||
hsurf = new BRepAdaptor_HSurface(surface);
|
||||
Adaptor3d_IsoCurve isoc(hsurf, GeomAbs_IsoU, vfp);
|
||||
double l = GCPnts_AbscissaPoint::Length(isoc, Precision::Confusion());
|
||||
isoc.Load(GeomAbs_IsoU, vlp);
|
||||
double lv = (l + GCPnts_AbscissaPoint::Length(isoc, Precision::Confusion()))/2.0;
|
||||
isoc.Load(GeomAbs_IsoV, ufp);
|
||||
l = GCPnts_AbscissaPoint::Length(isoc, Precision::Confusion());
|
||||
isoc.Load(GeomAbs_IsoV, ulp);
|
||||
double lu = (l + GCPnts_AbscissaPoint::Length(isoc, Precision::Confusion()))/2.0;
|
||||
int stepsv;
|
||||
if (lv >= 20.0)
|
||||
stepsv = round(lv / 10);
|
||||
else
|
||||
stepsv = 2; // Minimum of three arrows to ensure (as much as possible) that at least one is displayed
|
||||
int stepsu;
|
||||
if (lu >= 20.0)
|
||||
stepsu = round(lu / 10);
|
||||
else
|
||||
stepsu = 2;
|
||||
double stepv = (vlp - vfp) / stepsv;
|
||||
double stepu = (ulp - ufp) / stepsu;
|
||||
// Create points and normals
|
||||
for (int i = 0; i < stepsv + 1; i++) {
|
||||
for (int j = 0; j < stepsu + 1; j++) {
|
||||
double v = vfp + i * stepv;
|
||||
double u = ufp + j * stepu;
|
||||
gp_Pnt p = surface.Value(u, v);
|
||||
BRepClass_FaceClassifier classifier(face, p, Precision::Confusion());
|
||||
if (classifier.State() != TopAbs_OUT) {
|
||||
points.push_back(Base::Vector3f(p.X(), p.Y(), p.Z()));
|
||||
props.Normal(u, v,center,normal);
|
||||
normal.Normalize();
|
||||
normals.push_back(Base::Vector3f(normal.X(), normal.Y(), normal.Z()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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 false;
|
||||
App::DocumentObject* obj = Objects[0];
|
||||
Part::Feature* feat = static_cast<Part::Feature*>(obj);
|
||||
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);
|
||||
gp_Cylinder cyl = surface.Cylinder();
|
||||
gp_Pnt start = surface.Value(surface.FirstUParameter(), surface.FirstVParameter());
|
||||
gp_Pnt end = surface.Value(surface.FirstUParameter(), surface.LastVParameter());
|
||||
height = start.Distance(end);
|
||||
radius = cyl.Radius();
|
||||
|
||||
gp_Pnt b = cyl.Location();
|
||||
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,
|
||||
const App::PropertyLinkSub& location, const float& dist)
|
||||
{
|
||||
// Get the point specified by Location and Distance
|
||||
App::DocumentObject* objLoc = location.getValue();
|
||||
std::vector<std::string> names = location.getSubValues();
|
||||
if (names.size() == 0)
|
||||
return Base::Vector3f(0,0,0);
|
||||
std::string subName = names.front();
|
||||
Part::Feature* featLoc = static_cast<Part::Feature*>(objLoc);
|
||||
TopoDS_Shape shloc = featLoc->Shape.getShape().getSubShape(subName.c_str());
|
||||
|
||||
// Get a plane from the Location reference
|
||||
gp_Pln plane;
|
||||
gp_Dir cylaxis(axis.x, axis.y, axis.z);
|
||||
if (shloc.ShapeType() == TopAbs_FACE) {
|
||||
BRepAdaptor_Surface surface(TopoDS::Face(shloc));
|
||||
plane = surface.Plane();
|
||||
} else {
|
||||
BRepAdaptor_Curve curve(TopoDS::Edge(shloc));
|
||||
gp_Lin line = curve.Line();
|
||||
gp_Dir tang = line.Direction().Crossed(cylaxis);
|
||||
gp_Dir norm = line.Direction().Crossed(tang);
|
||||
plane = gp_Pln(line.Location(), norm);
|
||||
}
|
||||
|
||||
// Translate the plane in direction of the cylinder (for positive values of Distance)
|
||||
Handle_Geom_Plane pln = new Geom_Plane(plane);
|
||||
gp_Pnt cylbase(base.x, base.y, base.z);
|
||||
GeomAPI_ProjectPointOnSurf proj(cylbase, pln);
|
||||
if (!proj.IsDone())
|
||||
return Base::Vector3f(0,0,0);
|
||||
|
||||
gp_Pnt projPnt = proj.NearestPoint();
|
||||
if ((fabs(dist) > Precision::Confusion()) && (projPnt.IsEqual(cylbase, Precision::Confusion()) == Standard_False))
|
||||
plane.Translate(gp_Vec(projPnt, cylbase).Normalized().Multiplied(dist));
|
||||
Handle_Geom_Plane plnt = new Geom_Plane(plane);
|
||||
|
||||
// Intersect translated plane with cylinder axis
|
||||
Handle_Geom_Curve crv = new Geom_Line(cylbase, cylaxis);
|
||||
GeomAPI_IntCS intersector(crv, plnt);
|
||||
if (!intersector.IsDone())
|
||||
return Base::Vector3f(0,0,0);
|
||||
gp_Pnt inter = intersector.Point(1);
|
||||
return Base::Vector3f(inter.X(), inter.Y(), inter.Z());
|
||||
}
|
||||
|
||||
const Base::Vector3f Constraint::getDirection(const App::PropertyLinkSub &direction)
|
||||
{
|
||||
App::DocumentObject* obj = direction.getValue();
|
||||
std::vector<std::string> names = direction.getSubValues();
|
||||
if (names.size() == 0)
|
||||
return Base::Vector3f(0,0,0);
|
||||
std::string subName = names.front();
|
||||
Part::Feature* feat = static_cast<Part::Feature*>(obj);
|
||||
TopoDS_Shape sh = feat->Shape.getShape().getSubShape(subName.c_str());
|
||||
gp_Dir dir;
|
||||
|
||||
if (sh.ShapeType() == TopAbs_FACE) {
|
||||
BRepAdaptor_Surface surface(TopoDS::Face(sh));
|
||||
if (surface.GetType() == GeomAbs_Plane) {
|
||||
dir = surface.Plane().Axis().Direction();
|
||||
} else {
|
||||
return Base::Vector3f(0,0,0); // "Direction must be a planar face or linear edge"
|
||||
}
|
||||
} else if (sh.ShapeType() == TopAbs_EDGE) {
|
||||
BRepAdaptor_Curve line(TopoDS::Edge(sh));
|
||||
if (line.GetType() == GeomAbs_Line) {
|
||||
dir = line.Line().Direction();
|
||||
} else {
|
||||
return Base::Vector3f(0,0,0); // "Direction must be a planar face or linear edge"
|
||||
}
|
||||
}
|
||||
|
||||
Base::Vector3f the_direction(dir.X(), dir.Y(), dir.Z());
|
||||
the_direction.Normalize();
|
||||
return the_direction;
|
||||
}
|
||||
73
src/Mod/Fem/App/FemConstraint.h
Normal file
73
src/Mod/Fem/App/FemConstraint.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 FEM_CONSTRAINT_H
|
||||
#define FEM_CONSTRAINT_H
|
||||
|
||||
#include <Base/Vector3D.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/PropertyLinks.h>
|
||||
#include <App/PropertyGeo.h>
|
||||
|
||||
namespace Fem
|
||||
{
|
||||
|
||||
class AppFemExport Constraint : public App::DocumentObject
|
||||
{
|
||||
PROPERTY_HEADER(Fem::Constraint);
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
Constraint(void);
|
||||
virtual ~Constraint();
|
||||
|
||||
App::PropertyLinkSubList References;
|
||||
// Read-only (calculated values). These trigger changes in the ViewProvider
|
||||
App::PropertyVector NormalDirection;
|
||||
|
||||
/// recalculate the object
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
return "FemGui::ViewProviderFemConstraint";
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void onChanged(const App::Property* prop);
|
||||
virtual void onDocumentRestored();
|
||||
|
||||
protected:
|
||||
/// Calculate the points where symbols should be drawn
|
||||
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);
|
||||
const Base::Vector3f getDirection(const App::PropertyLinkSub &direction);
|
||||
|
||||
};
|
||||
|
||||
} //namespace Fem
|
||||
|
||||
|
||||
#endif // FEM_CONSTRAINT_H
|
||||
117
src/Mod/Fem/App/FemConstraintBearing.cpp
Normal file
117
src/Mod/Fem/App/FemConstraintBearing.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 <gp_Pnt.hxx>
|
||||
#include <gp_Pln.hxx>
|
||||
#include <gp_Lin.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <Precision.hxx>
|
||||
#endif
|
||||
|
||||
#include "FemConstraintBearing.h"
|
||||
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
using namespace Fem;
|
||||
|
||||
PROPERTY_SOURCE(Fem::ConstraintBearing, Fem::Constraint);
|
||||
|
||||
ConstraintBearing::ConstraintBearing()
|
||||
{
|
||||
ADD_PROPERTY_TYPE(Location,(0),"ConstraintBearing",(App::PropertyType)(App::Prop_None),
|
||||
"Element giving axial location of constraint");
|
||||
ADD_PROPERTY(Dist,(0.0));
|
||||
ADD_PROPERTY(AxialFree,(0));
|
||||
ADD_PROPERTY(Radius,(0.0));
|
||||
ADD_PROPERTY(Height,(0.0));
|
||||
ADD_PROPERTY_TYPE(BasePoint,(Base::Vector3f(0,0,0)),"ConstraintBearing",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"Base point of cylindrical bearing seat");
|
||||
ADD_PROPERTY_TYPE(Axis,(Base::Vector3f(0,1,0)),"ConstraintBearing",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"Axis of bearing seat");
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *ConstraintBearing::execute(void)
|
||||
{
|
||||
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);
|
||||
|
||||
if (prop == &References) {
|
||||
// Find data of cylinder
|
||||
float radius, height;
|
||||
Base::Vector3f base, axis;
|
||||
if (!getCylinder(radius, height, base, axis))
|
||||
return;
|
||||
Radius.setValue(radius);
|
||||
Axis.setValue(axis);
|
||||
Height.setValue(height);
|
||||
// Update base point
|
||||
base = base + axis * height/2;
|
||||
if (Location.getValue() != NULL) {
|
||||
base = getBasePoint(base, axis, Location, Dist.getValue());
|
||||
}
|
||||
BasePoint.setValue(base);
|
||||
BasePoint.touch(); // This triggers ViewProvider::updateData()
|
||||
} else if ((prop == &Location) || (prop == &Dist)) {
|
||||
App::DocumentObject* obj = Location.getValue();
|
||||
std::vector<std::string> names = Location.getSubValues();
|
||||
if (names.size() == 0) {
|
||||
return;
|
||||
}
|
||||
std::string subName = names.front();
|
||||
Part::Feature* feat = static_cast<Part::Feature*>(obj);
|
||||
TopoDS_Shape sh = feat->Shape.getShape().getSubShape(subName.c_str());
|
||||
|
||||
if (sh.ShapeType() == TopAbs_FACE) {
|
||||
BRepAdaptor_Surface surface(TopoDS::Face(sh));
|
||||
if (surface.GetType() != GeomAbs_Plane) {
|
||||
return; // "Location must be a planar face or linear edge"
|
||||
}
|
||||
} else if (sh.ShapeType() == TopAbs_EDGE) {
|
||||
BRepAdaptor_Curve line(TopoDS::Edge(sh));
|
||||
if (line.GetType() != GeomAbs_Line) {
|
||||
return; // "Location must be a planar face or linear edge"
|
||||
}
|
||||
}
|
||||
|
||||
float radius, height;
|
||||
Base::Vector3f base, axis;
|
||||
if (!getCylinder(radius, height, base, axis))
|
||||
return;
|
||||
base = getBasePoint(base + axis * height/2, axis, Location, Dist.getValue());
|
||||
BasePoint.setValue(base);
|
||||
BasePoint.touch();
|
||||
}
|
||||
}
|
||||
71
src/Mod/Fem/App/FemConstraintBearing.h
Normal file
71
src/Mod/Fem/App/FemConstraintBearing.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 FEM_CONSTRAINTBEARING_H
|
||||
#define FEM_CONSTRAINTBEARING_H
|
||||
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/PropertyLinks.h>
|
||||
#include <App/PropertyGeo.h>
|
||||
|
||||
#include "FemConstraint.h"
|
||||
|
||||
namespace Fem
|
||||
{
|
||||
|
||||
class AppFemExport ConstraintBearing : public Fem::Constraint
|
||||
{
|
||||
PROPERTY_HEADER(Fem::ConstraintBearing);
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
ConstraintBearing(void);
|
||||
|
||||
/// Location reference
|
||||
App::PropertyLinkSub Location;
|
||||
/// Distance from location reference
|
||||
App::PropertyFloat Dist;
|
||||
/// Is the bearing free to move in axial direction?
|
||||
App::PropertyBool AxialFree;
|
||||
// Read-only (calculated values). These trigger changes in the ViewProvider
|
||||
App::PropertyFloat Radius;
|
||||
App::PropertyFloat Height;
|
||||
App::PropertyVector BasePoint;
|
||||
App::PropertyVector Axis;
|
||||
|
||||
/// recalculate the object
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
const char* getViewProviderName(void) const {
|
||||
return "FemGui::ViewProviderFemConstraintBearing";
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void onChanged(const App::Property* prop);
|
||||
};
|
||||
|
||||
} //namespace Fem
|
||||
|
||||
|
||||
#endif // FEM_CONSTRAINTBEARING_H
|
||||
84
src/Mod/Fem/App/FemConstraintFixed.cpp
Normal file
84
src/Mod/Fem/App/FemConstraintFixed.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 <gp_Pnt.hxx>
|
||||
#include <gp_Pln.hxx>
|
||||
#include <gp_Lin.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
#include <GCPnts_AbscissaPoint.hxx>
|
||||
#include <Adaptor3d_IsoCurve.hxx>
|
||||
#include <Adaptor3d_HSurface.hxx>
|
||||
#include <BRepAdaptor_HSurface.hxx>
|
||||
#include <GProp_GProps.hxx>
|
||||
#include <BRepGProp.hxx>
|
||||
#include <TopoDS_Vertex.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <BRepClass_FaceClassifier.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <Precision.hxx>
|
||||
#endif
|
||||
|
||||
#include "FemConstraintFixed.h"
|
||||
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
using namespace Fem;
|
||||
|
||||
PROPERTY_SOURCE(Fem::ConstraintFixed, Fem::Constraint);
|
||||
|
||||
ConstraintFixed::ConstraintFixed()
|
||||
{
|
||||
ADD_PROPERTY_TYPE(Points,(Base::Vector3f()),"ConstraintFixed",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"Points where symbols are drawn");
|
||||
ADD_PROPERTY_TYPE(Normals,(Base::Vector3f()),"ConstraintFixed",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"Normals where symbols are drawn");
|
||||
Points.setValues(std::vector<Base::Vector3f>());
|
||||
Normals.setValues(std::vector<Base::Vector3f>());
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *ConstraintFixed::execute(void)
|
||||
{
|
||||
return Constraint::execute();
|
||||
}
|
||||
|
||||
void ConstraintFixed::onChanged(const App::Property* prop)
|
||||
{
|
||||
// Note: If we call this at the end, then the symbols are not oriented correctly initially
|
||||
// because the NormalDirection has not been calculated yet
|
||||
Constraint::onChanged(prop);
|
||||
|
||||
if (prop == &References) {
|
||||
std::vector<Base::Vector3f> points;
|
||||
std::vector<Base::Vector3f> normals;
|
||||
if (getPoints(points, normals)) {
|
||||
Points.setValues(points);
|
||||
Normals.setValues(normals);
|
||||
Points.touch(); // This triggers ViewProvider::updateData()
|
||||
}
|
||||
}
|
||||
}
|
||||
63
src/Mod/Fem/App/FemConstraintFixed.h
Normal file
63
src/Mod/Fem/App/FemConstraintFixed.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 FEM_CONSTRAINTFIXED_H
|
||||
#define FEM_CONSTRAINTFIXED_H
|
||||
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/PropertyLinks.h>
|
||||
#include <App/PropertyGeo.h>
|
||||
|
||||
#include "FemConstraint.h"
|
||||
|
||||
namespace Fem
|
||||
{
|
||||
|
||||
class AppFemExport ConstraintFixed : public Fem::Constraint
|
||||
{
|
||||
PROPERTY_HEADER(Fem::ConstraintFixed);
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
ConstraintFixed(void);
|
||||
|
||||
// Read-only (calculated values). These trigger changes in the ViewProvider
|
||||
App::PropertyVectorList Points;
|
||||
App::PropertyVectorList Normals;
|
||||
|
||||
/// recalculate the object
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
const char* getViewProviderName(void) const {
|
||||
return "FemGui::ViewProviderFemConstraintFixed";
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void onChanged(const App::Property* prop);
|
||||
};
|
||||
|
||||
} //namespace Fem
|
||||
|
||||
|
||||
#endif // FEM_CONSTRAINTFIXED_H
|
||||
101
src/Mod/Fem/App/FemConstraintForce.cpp
Normal file
101
src/Mod/Fem/App/FemConstraintForce.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 <gp_Pnt.hxx>
|
||||
#include <gp_Pln.hxx>
|
||||
#include <gp_Lin.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <Precision.hxx>
|
||||
#endif
|
||||
|
||||
#include "FemConstraintForce.h"
|
||||
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
using namespace Fem;
|
||||
|
||||
PROPERTY_SOURCE(Fem::ConstraintForce, Fem::Constraint);
|
||||
|
||||
ConstraintForce::ConstraintForce()
|
||||
{
|
||||
ADD_PROPERTY(Force,(0.0));
|
||||
ADD_PROPERTY_TYPE(Direction,(0),"ConstraintForce",(App::PropertyType)(App::Prop_None),
|
||||
"Element giving direction of constraint");
|
||||
ADD_PROPERTY(Reversed,(0));
|
||||
ADD_PROPERTY_TYPE(Points,(Base::Vector3f()),"ConstraintForce",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"Points where arrows are drawn");
|
||||
ADD_PROPERTY_TYPE(DirectionVector,(Base::Vector3f(0,0,1)),"ConstraintForce",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"Direction of arrows");
|
||||
naturalDirectionVector = Base::Vector3f(0,0,1);
|
||||
Points.setValues(std::vector<Base::Vector3f>());
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *ConstraintForce::execute(void)
|
||||
{
|
||||
return Constraint::execute();
|
||||
}
|
||||
|
||||
void ConstraintForce::onChanged(const App::Property* prop)
|
||||
{
|
||||
// Note: If we call this at the end, then the arrows are not oriented correctly initially
|
||||
// because the NormalDirection has not been calculated yet
|
||||
Constraint::onChanged(prop);
|
||||
|
||||
if (prop == &References) {
|
||||
std::vector<Base::Vector3f> points;
|
||||
std::vector<Base::Vector3f> normals;
|
||||
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) {
|
||||
Base::Vector3f direction = getDirection(Direction);
|
||||
if (direction.Length() < Precision::Confusion())
|
||||
return;
|
||||
naturalDirectionVector = direction;
|
||||
if (Reversed.getValue())
|
||||
direction = -direction;
|
||||
DirectionVector.setValue(direction);
|
||||
DirectionVector.touch();
|
||||
} else if (prop == &Reversed) {
|
||||
if (Reversed.getValue() && (DirectionVector.getValue() == naturalDirectionVector)) {
|
||||
DirectionVector.setValue(-naturalDirectionVector);
|
||||
DirectionVector.touch();
|
||||
} else if (!Reversed.getValue() && (DirectionVector.getValue() != naturalDirectionVector)) {
|
||||
DirectionVector.setValue(naturalDirectionVector);
|
||||
DirectionVector.touch();
|
||||
}
|
||||
} else if (prop == &NormalDirection) {
|
||||
// Set a default direction if no direction reference has been given
|
||||
if (Direction.getValue() == NULL) {
|
||||
DirectionVector.setValue(NormalDirection.getValue());
|
||||
naturalDirectionVector = NormalDirection.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
69
src/Mod/Fem/App/FemConstraintForce.h
Normal file
69
src/Mod/Fem/App/FemConstraintForce.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 FEM_CONSTRAINTFORCE_H
|
||||
#define FEM_CONSTRAINTFORCE_H
|
||||
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/PropertyLinks.h>
|
||||
#include <App/PropertyGeo.h>
|
||||
|
||||
#include "FemConstraint.h"
|
||||
|
||||
namespace Fem
|
||||
{
|
||||
|
||||
class AppFemExport ConstraintForce : public Fem::Constraint
|
||||
{
|
||||
PROPERTY_HEADER(Fem::ConstraintForce);
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
ConstraintForce(void);
|
||||
|
||||
App::PropertyFloat Force;
|
||||
App::PropertyLinkSub Direction;
|
||||
App::PropertyBool Reversed;
|
||||
// Read-only (calculated values). These trigger changes in the ViewProvider
|
||||
App::PropertyVectorList Points;
|
||||
App::PropertyVector DirectionVector;
|
||||
|
||||
/// recalculate the object
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
const char* getViewProviderName(void) const {
|
||||
return "FemGui::ViewProviderFemConstraintForce";
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void onChanged(const App::Property* prop);
|
||||
|
||||
private:
|
||||
Base::Vector3f naturalDirectionVector;
|
||||
};
|
||||
|
||||
} //namespace Fem
|
||||
|
||||
|
||||
#endif // FEM_CONSTRAINTFORCE_H
|
||||
86
src/Mod/Fem/App/FemConstraintGear.cpp
Normal file
86
src/Mod/Fem/App/FemConstraintGear.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 <gp_Pnt.hxx>
|
||||
#include <gp_Pln.hxx>
|
||||
#include <gp_Lin.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <Precision.hxx>
|
||||
#endif
|
||||
|
||||
#include "FemConstraintGear.h"
|
||||
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
using namespace Fem;
|
||||
|
||||
PROPERTY_SOURCE(Fem::ConstraintGear, Fem::ConstraintBearing);
|
||||
|
||||
ConstraintGear::ConstraintGear()
|
||||
{
|
||||
ADD_PROPERTY(Diameter,(100.0));
|
||||
ADD_PROPERTY(Force,(1000.0));
|
||||
ADD_PROPERTY(ForceAngle,(0.0));
|
||||
ADD_PROPERTY_TYPE(Direction,(0),"ConstraintGear",(App::PropertyType)(App::Prop_None),
|
||||
"Element giving direction of gear force");
|
||||
ADD_PROPERTY(Reversed,(0));
|
||||
ADD_PROPERTY_TYPE(DirectionVector,(Base::Vector3f(1,1,1).Normalize()),"ConstraintGear",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"Direction of gear force");
|
||||
naturalDirectionVector = Base::Vector3f(1,1,1).Normalize();
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *ConstraintGear::execute(void)
|
||||
{
|
||||
return ConstraintBearing::execute();
|
||||
}
|
||||
|
||||
void ConstraintGear::onChanged(const App::Property* prop)
|
||||
{
|
||||
ConstraintBearing::onChanged(prop);
|
||||
|
||||
if (prop == &Direction) {
|
||||
Base::Vector3f direction = getDirection(Direction);
|
||||
if (direction.Length() < Precision::Confusion())
|
||||
return;
|
||||
naturalDirectionVector = direction;
|
||||
if (Reversed.getValue())
|
||||
direction = -direction;
|
||||
DirectionVector.setValue(direction);
|
||||
DirectionVector.touch();
|
||||
} else if (prop == &Reversed) {
|
||||
if (Reversed.getValue() && (DirectionVector.getValue() == naturalDirectionVector)) {
|
||||
DirectionVector.setValue(-naturalDirectionVector);
|
||||
DirectionVector.touch();
|
||||
} else if (!Reversed.getValue() && (DirectionVector.getValue() != naturalDirectionVector)) {
|
||||
DirectionVector.setValue(naturalDirectionVector);
|
||||
DirectionVector.touch();
|
||||
}
|
||||
}
|
||||
// The computation for the force angle is simpler in the ViewProvider directly
|
||||
}
|
||||
70
src/Mod/Fem/App/FemConstraintGear.h
Normal file
70
src/Mod/Fem/App/FemConstraintGear.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 FEM_CONSTRAINTGear_H
|
||||
#define FEM_CONSTRAINTGear_H
|
||||
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/PropertyLinks.h>
|
||||
#include <App/PropertyGeo.h>
|
||||
|
||||
#include "FemConstraintBearing.h"
|
||||
|
||||
namespace Fem
|
||||
{
|
||||
|
||||
class AppFemExport ConstraintGear : public Fem::ConstraintBearing
|
||||
{
|
||||
PROPERTY_HEADER(Fem::ConstraintGear);
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
ConstraintGear(void);
|
||||
|
||||
App::PropertyFloat Diameter;
|
||||
App::PropertyFloat Force;
|
||||
App::PropertyFloat ForceAngle;
|
||||
App::PropertyLinkSub Direction;
|
||||
App::PropertyBool Reversed;
|
||||
// Read-only (calculated values). These trigger changes in the ViewProvider
|
||||
App::PropertyVector DirectionVector;
|
||||
|
||||
/// recalculate the object
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
const char* getViewProviderName(void) const {
|
||||
return "FemGui::ViewProviderFemConstraintGear";
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void onChanged(const App::Property* prop);
|
||||
|
||||
private:
|
||||
Base::Vector3f naturalDirectionVector;
|
||||
};
|
||||
|
||||
} //namespace Fem
|
||||
|
||||
|
||||
#endif // FEM_CONSTRAINTGear_H
|
||||
98
src/Mod/Fem/App/FemConstraintPulley.cpp
Normal file
98
src/Mod/Fem/App/FemConstraintPulley.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 <gp_Pnt.hxx>
|
||||
#include <gp_Pln.hxx>
|
||||
#include <gp_Lin.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <Precision.hxx>
|
||||
#endif
|
||||
|
||||
#include "FemConstraintPulley.h"
|
||||
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
using namespace Fem;
|
||||
|
||||
PROPERTY_SOURCE(Fem::ConstraintPulley, Fem::ConstraintGear);
|
||||
|
||||
ConstraintPulley::ConstraintPulley()
|
||||
{
|
||||
ADD_PROPERTY(OtherDiameter,(100.0));
|
||||
ADD_PROPERTY(CenterDistance,(500.0));
|
||||
ADD_PROPERTY(IsDriven,(0));
|
||||
ADD_PROPERTY(TensionForce,(0.0));
|
||||
|
||||
ADD_PROPERTY_TYPE(BeltAngle,(0),"ConstraintPulley",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"Angle of belt forces");
|
||||
ADD_PROPERTY_TYPE(BeltForce1,(0.0),"ConstraintPulley",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"First belt force");
|
||||
ADD_PROPERTY_TYPE(BeltForce2,(0.0),"ConstraintPulley",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"Second belt force");
|
||||
ForceAngle.setValue(00.0);
|
||||
Diameter.setValue(300.0);
|
||||
// calculate initial values of read-only properties
|
||||
onChanged(&Force);
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *ConstraintPulley::execute(void)
|
||||
{
|
||||
return ConstraintBearing::execute();
|
||||
}
|
||||
|
||||
void ConstraintPulley::onChanged(const App::Property* prop)
|
||||
{
|
||||
ConstraintGear::onChanged(prop);
|
||||
|
||||
if ((prop == &Diameter) || (prop == &OtherDiameter) || (prop == &CenterDistance)) {
|
||||
if (CenterDistance.getValue() > Precision::Confusion()) {
|
||||
BeltAngle.setValue(asin((Diameter.getValue() - OtherDiameter.getValue())/2/CenterDistance.getValue()));
|
||||
BeltAngle.touch();
|
||||
}
|
||||
} else if ((prop == &Force) || (prop == &TensionForce) || (prop == &IsDriven)) {
|
||||
double radius = Diameter.getValue() / 2.0;
|
||||
if (radius < Precision::Confusion())
|
||||
return;
|
||||
double force = Force.getValue() / (radius/1000);
|
||||
if (fabs(force) < Precision::Confusion())
|
||||
return;
|
||||
bool neg = (force < 0.0);
|
||||
if (neg)
|
||||
force *= -1.0;
|
||||
|
||||
if ((IsDriven.getValue() && neg) || (!IsDriven.getValue() && !neg)) {
|
||||
BeltForce1.setValue(force + TensionForce.getValue());
|
||||
BeltForce2.setValue(TensionForce.getValue());
|
||||
} else {
|
||||
BeltForce2.setValue(force + TensionForce.getValue());
|
||||
BeltForce1.setValue(TensionForce.getValue());
|
||||
}
|
||||
BeltForce1.touch();
|
||||
}
|
||||
}
|
||||
73
src/Mod/Fem/App/FemConstraintPulley.h
Normal file
73
src/Mod/Fem/App/FemConstraintPulley.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 FEM_CONSTRAINTPulley_H
|
||||
#define FEM_CONSTRAINTPulley_H
|
||||
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/PropertyLinks.h>
|
||||
#include <App/PropertyGeo.h>
|
||||
|
||||
#include "FemConstraintGear.h"
|
||||
|
||||
namespace Fem
|
||||
{
|
||||
|
||||
class AppFemExport ConstraintPulley : public Fem::ConstraintGear
|
||||
{
|
||||
PROPERTY_HEADER(Fem::ConstraintPulley);
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
ConstraintPulley(void);
|
||||
|
||||
/// Other pulley diameter
|
||||
App::PropertyFloat OtherDiameter;
|
||||
/// Center distance between the pulleys
|
||||
App::PropertyFloat CenterDistance;
|
||||
/// Driven pulley or driving pulley?
|
||||
App::PropertyBool IsDriven;
|
||||
/// Belt tension force
|
||||
App::PropertyFloat TensionForce;
|
||||
// Read-only (calculated values). These trigger changes in the ViewProvider
|
||||
App::PropertyFloat BeltAngle;
|
||||
App::PropertyFloat BeltForce1;
|
||||
App::PropertyFloat BeltForce2;
|
||||
|
||||
/// recalculate the object
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
const char* getViewProviderName(void) const {
|
||||
return "FemGui::ViewProviderFemConstraintPulley";
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void onChanged(const App::Property* prop);
|
||||
|
||||
};
|
||||
|
||||
} //namespace Fem
|
||||
|
||||
|
||||
#endif // FEM_CONSTRAINTPulley_H
|
||||
Reference in New Issue
Block a user