All: Reformat according to new standard
This commit is contained in:
committed by
Kacper Donat
parent
eafd18dac0
commit
25c3ba7338
@@ -24,7 +24,6 @@
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
|
||||
#include <Mod/Part/PartGlobal.h>
|
||||
|
||||
#include <string>
|
||||
@@ -68,22 +67,26 @@ using namespace Part;
|
||||
using Attacher::AttachEnginePlane;
|
||||
|
||||
|
||||
// From: https://github.com/Celemation/FreeCAD/blob/joel_selection_summary_demo/src/Gui/Selection/SelectionSummary.cpp
|
||||
// From:
|
||||
// https://github.com/Celemation/FreeCAD/blob/joel_selection_summary_demo/src/Gui/Selection/SelectionSummary.cpp
|
||||
|
||||
// Should work with edges and wires
|
||||
static float getLength(TopoDS_Shape& wire){
|
||||
static float getLength(TopoDS_Shape& wire)
|
||||
{
|
||||
GProp_GProps gprops;
|
||||
BRepGProp::LinearProperties(wire, gprops);
|
||||
return gprops.Mass();
|
||||
}
|
||||
|
||||
static float getFaceArea(TopoDS_Shape& face){
|
||||
static float getFaceArea(TopoDS_Shape& face)
|
||||
{
|
||||
GProp_GProps gprops;
|
||||
BRepGProp::SurfaceProperties(face, gprops);
|
||||
return gprops.Mass();
|
||||
}
|
||||
|
||||
static float getRadius(TopoDS_Shape& edge){
|
||||
static float getRadius(TopoDS_Shape& edge)
|
||||
{
|
||||
// gprops.Mass() would be the circumference (length) of the circle (arc)
|
||||
if (edge.ShapeType() == TopAbs_EDGE) {
|
||||
BRepAdaptor_Curve adapt(TopoDS::Edge(edge));
|
||||
@@ -106,17 +109,22 @@ TopoDS_Shape getLocatedShape(const App::SubObjectT& subject, Base::Matrix4D* mat
|
||||
|
||||
Part::TopoShape shape = Part::Feature::getTopoShape(
|
||||
obj,
|
||||
Part::ShapeOption::ResolveLink
|
||||
| Part::ShapeOption::Transform,
|
||||
Part::ShapeOption::ResolveLink | Part::ShapeOption::Transform,
|
||||
subject.getElementName(),
|
||||
mat);
|
||||
mat
|
||||
);
|
||||
|
||||
if (shape.isNull()) {
|
||||
Base::Console().log("Part::MeasureClient::getLocatedShape: Did not retrieve shape for %s, %s\n", obj->getNameInDocument(), subject.getElementName());
|
||||
Base::Console().log(
|
||||
"Part::MeasureClient::getLocatedShape: Did not retrieve shape for %s, %s\n",
|
||||
obj->getNameInDocument(),
|
||||
subject.getElementName()
|
||||
);
|
||||
return {};
|
||||
}
|
||||
|
||||
auto placement = App::GeoFeature::getGlobalPlacement(obj, subject.getObject(), subject.getSubName());
|
||||
auto placement
|
||||
= App::GeoFeature::getGlobalPlacement(obj, subject.getObject(), subject.getSubName());
|
||||
shape.setPlacement(placement);
|
||||
|
||||
// Don't get the subShape from datum elements
|
||||
@@ -140,15 +148,20 @@ App::MeasureElementType PartMeasureTypeCb(App::DocumentObject* ob, const char* s
|
||||
return curve->NbPoles() == 2;
|
||||
};
|
||||
|
||||
TopoDS_Shape shape = Part::Feature::getShape(ob,
|
||||
Part::ShapeOption::NeedSubElement
|
||||
| Part::ShapeOption::ResolveLink
|
||||
| Part::ShapeOption::Transform,
|
||||
subName);
|
||||
TopoDS_Shape shape = Part::Feature::getShape(
|
||||
ob,
|
||||
Part::ShapeOption::NeedSubElement | Part::ShapeOption::ResolveLink
|
||||
| Part::ShapeOption::Transform,
|
||||
subName
|
||||
);
|
||||
|
||||
if (shape.IsNull()) {
|
||||
// failure here on loading document with existing measurement.
|
||||
Base::Console().message("Part::PartMeasureTypeCb did not retrieve shape for %s, %s\n", ob->getNameInDocument(), subName);
|
||||
Base::Console().message(
|
||||
"Part::PartMeasureTypeCb did not retrieve shape for %s, %s\n",
|
||||
ob->getNameInDocument(),
|
||||
subName
|
||||
);
|
||||
return App::MeasureElementType();
|
||||
}
|
||||
TopAbs_ShapeEnum shapeType = shape.ShapeType();
|
||||
@@ -171,20 +184,22 @@ App::MeasureElementType PartMeasureTypeCb(App::DocumentObject* ob, const char* s
|
||||
}
|
||||
case GeomAbs_BezierCurve: {
|
||||
return isStraightBezierCurve(curve.Bezier())
|
||||
? App::MeasureElementType::LINESEGMENT
|
||||
: App::MeasureElementType::CURVE;
|
||||
? App::MeasureElementType::LINESEGMENT
|
||||
: App::MeasureElementType::CURVE;
|
||||
}
|
||||
case GeomAbs_BSplineCurve: {
|
||||
return isStraightBSplineCurve(curve.BSpline())
|
||||
? App::MeasureElementType::LINESEGMENT
|
||||
: App::MeasureElementType::CURVE;
|
||||
? App::MeasureElementType::LINESEGMENT
|
||||
: App::MeasureElementType::CURVE;
|
||||
}
|
||||
case GeomAbs_Ellipse:
|
||||
case GeomAbs_Hyperbola:
|
||||
case GeomAbs_Parabola: {
|
||||
return App::MeasureElementType::CURVE;
|
||||
}
|
||||
default: { return App::MeasureElementType::INVALID; }
|
||||
default: {
|
||||
return App::MeasureElementType::INVALID;
|
||||
}
|
||||
}
|
||||
}
|
||||
case TopAbs_FACE: {
|
||||
@@ -220,19 +235,20 @@ App::MeasureElementType PartMeasureTypeCb(App::DocumentObject* ob, const char* s
|
||||
}
|
||||
|
||||
|
||||
bool getShapeFromStrings(TopoDS_Shape &shapeOut, const App::SubObjectT& subject, Base::Matrix4D *mat)
|
||||
bool getShapeFromStrings(TopoDS_Shape& shapeOut, const App::SubObjectT& subject, Base::Matrix4D* mat)
|
||||
{
|
||||
App::DocumentObject *obj = subject.getObject();
|
||||
App::DocumentObject* obj = subject.getObject();
|
||||
if (!obj) {
|
||||
return {};
|
||||
}
|
||||
shapeOut = Part::Feature::getShape(obj,
|
||||
Part::ShapeOption::NeedSubElement
|
||||
| Part::ShapeOption::ResolveLink
|
||||
| Part::ShapeOption::Transform,
|
||||
subject.getElementName(),
|
||||
mat);
|
||||
return !shapeOut.IsNull();
|
||||
}
|
||||
shapeOut = Part::Feature::getShape(
|
||||
obj,
|
||||
Part::ShapeOption::NeedSubElement | Part::ShapeOption::ResolveLink
|
||||
| Part::ShapeOption::Transform,
|
||||
subject.getElementName(),
|
||||
mat
|
||||
);
|
||||
return !shapeOut.IsNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -243,46 +259,46 @@ Part::VectorAdapter buildAdapter(const App::SubObjectT& subject)
|
||||
|
||||
if (shape.IsNull()) {
|
||||
// failure here on loading document with existing measurement.
|
||||
Base::Console().message("Part::buildAdapter did not retrieve shape for %s, %s\n",
|
||||
subject.getObjectName(), subject.getElementName());
|
||||
Base::Console().message(
|
||||
"Part::buildAdapter did not retrieve shape for %s, %s\n",
|
||||
subject.getObjectName(),
|
||||
subject.getElementName()
|
||||
);
|
||||
return Part::VectorAdapter();
|
||||
}
|
||||
TopAbs_ShapeEnum shapeType = shape.ShapeType();
|
||||
|
||||
if (shapeType == TopAbs_EDGE)
|
||||
{
|
||||
TopoDS_Edge edge = TopoDS::Edge(shape);
|
||||
// make edge orientation so that end of edge closest to pick is head of vector.
|
||||
TopoDS_Vertex firstVertex = TopExp::FirstVertex(edge, Standard_True);
|
||||
TopoDS_Vertex lastVertex = TopExp::LastVertex(edge, Standard_True);
|
||||
if (firstVertex.IsNull() || lastVertex.IsNull()) {
|
||||
return {};
|
||||
}
|
||||
gp_Vec firstPoint = Part::VectorAdapter::convert(firstVertex);
|
||||
gp_Vec lastPoint = Part::VectorAdapter::convert(lastVertex);
|
||||
Base::Vector3d v(0.0, 0.0, 0.0); //v(current.x,current.y,current.z);
|
||||
v = mat*v;
|
||||
gp_Vec pickPoint(v.x, v.y, v.z);
|
||||
double firstDistance = (firstPoint - pickPoint).Magnitude();
|
||||
double lastDistance = (lastPoint - pickPoint).Magnitude();
|
||||
if (lastDistance > firstDistance)
|
||||
{
|
||||
if (edge.Orientation() == TopAbs_FORWARD) {
|
||||
edge.Orientation(TopAbs_REVERSED);
|
||||
if (shapeType == TopAbs_EDGE) {
|
||||
TopoDS_Edge edge = TopoDS::Edge(shape);
|
||||
// make edge orientation so that end of edge closest to pick is head of vector.
|
||||
TopoDS_Vertex firstVertex = TopExp::FirstVertex(edge, Standard_True);
|
||||
TopoDS_Vertex lastVertex = TopExp::LastVertex(edge, Standard_True);
|
||||
if (firstVertex.IsNull() || lastVertex.IsNull()) {
|
||||
return {};
|
||||
}
|
||||
else {
|
||||
edge.Orientation(TopAbs_FORWARD);
|
||||
gp_Vec firstPoint = Part::VectorAdapter::convert(firstVertex);
|
||||
gp_Vec lastPoint = Part::VectorAdapter::convert(lastVertex);
|
||||
Base::Vector3d v(0.0, 0.0, 0.0); // v(current.x,current.y,current.z);
|
||||
v = mat * v;
|
||||
gp_Vec pickPoint(v.x, v.y, v.z);
|
||||
double firstDistance = (firstPoint - pickPoint).Magnitude();
|
||||
double lastDistance = (lastPoint - pickPoint).Magnitude();
|
||||
if (lastDistance > firstDistance) {
|
||||
if (edge.Orientation() == TopAbs_FORWARD) {
|
||||
edge.Orientation(TopAbs_REVERSED);
|
||||
}
|
||||
else {
|
||||
edge.Orientation(TopAbs_FORWARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
return {edge, pickPoint};
|
||||
return {edge, pickPoint};
|
||||
}
|
||||
if (shapeType == TopAbs_FACE)
|
||||
{
|
||||
TopoDS_Face face = TopoDS::Face(shape);
|
||||
Base::Vector3d vTemp(0.0, 0.0, 0.0); //v(current.x, current.y, current.z);
|
||||
vTemp = mat*vTemp;
|
||||
gp_Vec pickPoint(vTemp.x, vTemp.y, vTemp.z);
|
||||
return {face, pickPoint};
|
||||
if (shapeType == TopAbs_FACE) {
|
||||
TopoDS_Face face = TopoDS::Face(shape);
|
||||
Base::Vector3d vTemp(0.0, 0.0, 0.0); // v(current.x, current.y, current.z);
|
||||
vTemp = mat * vTemp;
|
||||
gp_Vec pickPoint(vTemp.x, vTemp.y, vTemp.z);
|
||||
return {face, pickPoint};
|
||||
}
|
||||
|
||||
return {};
|
||||
@@ -295,8 +311,11 @@ MeasureLengthInfoPtr MeasureLengthHandler(const App::SubObjectT& subject)
|
||||
|
||||
if (shape.IsNull()) {
|
||||
// failure here on loading document with existing measurement.
|
||||
Base::Console().message("MeasureLengthHandler did not retrieve shape for %s, %s\n",
|
||||
subject.getObjectName(), subject.getElementName());
|
||||
Base::Console().message(
|
||||
"MeasureLengthHandler did not retrieve shape for %s, %s\n",
|
||||
subject.getObjectName(),
|
||||
subject.getElementName()
|
||||
);
|
||||
return std::make_shared<MeasureLengthInfo>(false, 0.0, Base::Matrix4D());
|
||||
}
|
||||
TopAbs_ShapeEnum sType = shape.ShapeType();
|
||||
@@ -316,18 +335,18 @@ MeasureLengthInfoPtr MeasureLengthHandler(const App::SubObjectT& subject)
|
||||
|
||||
MeasureRadiusInfoPtr MeasureRadiusHandler(const App::SubObjectT& subject)
|
||||
{
|
||||
Base::Placement placement; // curve center + orientation
|
||||
Base::Placement placement; // curve center + orientation
|
||||
Base::Vector3d pointOnCurve;
|
||||
|
||||
TopoDS_Shape shape = getLocatedShape(subject);
|
||||
|
||||
if (shape.IsNull()) {
|
||||
return std::make_shared<MeasureRadiusInfo>( false, 0.0, pointOnCurve, placement);
|
||||
return std::make_shared<MeasureRadiusInfo>(false, 0.0, pointOnCurve, placement);
|
||||
}
|
||||
TopAbs_ShapeEnum sType = shape.ShapeType();
|
||||
TopAbs_ShapeEnum sType = shape.ShapeType();
|
||||
|
||||
if (sType != TopAbs_EDGE) {
|
||||
return std::make_shared<MeasureRadiusInfo>( false, 0.0, pointOnCurve, placement);
|
||||
return std::make_shared<MeasureRadiusInfo>(false, 0.0, pointOnCurve, placement);
|
||||
}
|
||||
|
||||
// Get Center of mass as the attachment point of the label
|
||||
@@ -346,7 +365,7 @@ MeasureRadiusInfoPtr MeasureRadiusHandler(const App::SubObjectT& subject)
|
||||
|
||||
placement = Base::Placement(Base::Vector3d(origin.X(), origin.Y(), origin.Z()), rot);
|
||||
|
||||
return std::make_shared<MeasureRadiusInfo>( true, getRadius(shape), pointOnCurve, placement);
|
||||
return std::make_shared<MeasureRadiusInfo>(true, getRadius(shape), pointOnCurve, placement);
|
||||
}
|
||||
|
||||
|
||||
@@ -356,8 +375,11 @@ MeasureAreaInfoPtr MeasureAreaHandler(const App::SubObjectT& subject)
|
||||
|
||||
if (shape.IsNull()) {
|
||||
// failure here on loading document with existing measurement.
|
||||
Base::Console().message("MeasureAreaHandler did not retrieve shape for %s, %s\n",
|
||||
subject.getObjectName(), subject.getElementName());
|
||||
Base::Console().message(
|
||||
"MeasureAreaHandler did not retrieve shape for %s, %s\n",
|
||||
subject.getObjectName(),
|
||||
subject.getElementName()
|
||||
);
|
||||
return std::make_shared<MeasureAreaInfo>(false, 0.0, Base::Matrix4D());
|
||||
}
|
||||
TopAbs_ShapeEnum sType = shape.ShapeType();
|
||||
@@ -371,7 +393,8 @@ MeasureAreaInfoPtr MeasureAreaHandler(const App::SubObjectT& subject)
|
||||
BRepGProp::SurfaceProperties(shape, gprops);
|
||||
auto origin = gprops.CentreOfMass();
|
||||
|
||||
// TODO: Center of Mass might not lie on the surface, somehow snap to the closest point on the surface?
|
||||
// TODO: Center of Mass might not lie on the surface, somehow snap to the closest point on the
|
||||
// surface?
|
||||
|
||||
Base::Placement placement(Base::Vector3d(origin.X(), origin.Y(), origin.Z()), Base::Rotation());
|
||||
return std::make_shared<MeasureAreaInfo>(true, getFaceArea(shape), placement);
|
||||
@@ -383,8 +406,11 @@ MeasurePositionInfoPtr MeasurePositionHandler(const App::SubObjectT& subject)
|
||||
TopoDS_Shape shape = getLocatedShape(subject);
|
||||
|
||||
if (shape.IsNull()) {
|
||||
Base::Console().message("MeasurePositionHandler did not retrieve shape for %s, %s\n",
|
||||
subject.getObjectName(), subject.getElementName());
|
||||
Base::Console().message(
|
||||
"MeasurePositionHandler did not retrieve shape for %s, %s\n",
|
||||
subject.getObjectName(),
|
||||
subject.getElementName()
|
||||
);
|
||||
return std::make_shared<MeasurePositionInfo>(false, Base::Vector3d());
|
||||
}
|
||||
TopAbs_ShapeEnum sType = shape.ShapeType();
|
||||
@@ -395,7 +421,7 @@ MeasurePositionInfoPtr MeasurePositionHandler(const App::SubObjectT& subject)
|
||||
|
||||
TopoDS_Vertex vertex = TopoDS::Vertex(shape);
|
||||
auto point = BRep_Tool::Pnt(vertex);
|
||||
return std::make_shared<MeasurePositionInfo>( true, Base::Vector3d(point.X(), point.Y(), point.Z()));
|
||||
return std::make_shared<MeasurePositionInfo>(true, Base::Vector3d(point.X(), point.Y(), point.Z()));
|
||||
}
|
||||
|
||||
|
||||
@@ -405,8 +431,11 @@ MeasureAngleInfoPtr MeasureAngleHandler(const App::SubObjectT& subject)
|
||||
|
||||
if (shape.IsNull()) {
|
||||
// failure here on loading document with existing measurement.
|
||||
Base::Console().message("MeasureAngleHandler did not retrieve shape for %s, %s\n",
|
||||
subject.getObjectName(), subject.getElementName());
|
||||
Base::Console().message(
|
||||
"MeasureAngleHandler did not retrieve shape for %s, %s\n",
|
||||
subject.getObjectName(),
|
||||
subject.getElementName()
|
||||
);
|
||||
return std::make_shared<MeasureAngleInfo>();
|
||||
}
|
||||
|
||||
@@ -422,8 +451,8 @@ MeasureAngleInfoPtr MeasureAngleHandler(const App::SubObjectT& subject)
|
||||
GProp_GProps gprops;
|
||||
BRepGProp::SurfaceProperties(face, gprops);
|
||||
vec = gprops.CentreOfMass();
|
||||
|
||||
} else if (sType == TopAbs_EDGE) {
|
||||
}
|
||||
else if (sType == TopAbs_EDGE) {
|
||||
TopoDS_Edge edge = TopoDS::Edge(shape);
|
||||
|
||||
GProp_GProps gprops;
|
||||
@@ -444,8 +473,11 @@ MeasureDistanceInfoPtr MeasureDistanceHandler(const App::SubObjectT& subject)
|
||||
|
||||
if (shape.IsNull()) {
|
||||
// failure here on loading document with existing measurement.
|
||||
Base::Console().message("MeasureDistanceHandler did not retrieve shape for %s, %s\n",
|
||||
subject.getObjectName(), subject.getElementName());
|
||||
Base::Console().message(
|
||||
"MeasureDistanceHandler did not retrieve shape for %s, %s\n",
|
||||
subject.getObjectName(),
|
||||
subject.getElementName()
|
||||
);
|
||||
return std::make_shared<MeasureDistanceInfo>();
|
||||
}
|
||||
|
||||
@@ -455,9 +487,9 @@ MeasureDistanceInfoPtr MeasureDistanceHandler(const App::SubObjectT& subject)
|
||||
}
|
||||
|
||||
|
||||
void Part::MeasureClient::initialize() {
|
||||
void Part::MeasureClient::initialize()
|
||||
{
|
||||
App::MeasureManager::addMeasureHandler("Part", PartMeasureTypeCb);
|
||||
|
||||
}
|
||||
|
||||
Part::CallbackRegistrationList Part::MeasureClient::reportLengthCB()
|
||||
|
||||
Reference in New Issue
Block a user