MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / getPointsEdgeVert

Method getPointsEdgeVert

src/Mod/TechDraw/App/DrawViewDimension.cpp:1020–1075  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1018}
1019
1020pointPair DrawViewDimension::getPointsEdgeVert(ReferenceVector references)
1021{
1022 App::DocumentObject* refObject = references.front().getObject();
1023 int iSubelement0 = DrawUtil::getIndexFromName(references.at(0).getSubName());
1024 int iSubelement1 = DrawUtil::getIndexFromName(references.at(1).getSubName());
1025 if (refObject->isDerivedFrom<TechDraw::DrawViewPart>()
1026 && !references.at(0).getSubName().empty()) {
1027 // this is a 2d object (a DVP + subelements)
1028 TechDraw::BaseGeomPtr edge;
1029 TechDraw::VertexPtr vertex;
1030 if (DrawUtil::getGeomTypeFromName(references.at(0).getSubName()) == "Edge") {
1031 edge = getViewPart()->getGeomByIndex(iSubelement0);
1032 vertex = getViewPart()->getProjVertexByIndex(iSubelement1);
1033 }
1034 else {
1035 edge = getViewPart()->getGeomByIndex(iSubelement1);
1036 vertex = getViewPart()->getProjVertexByIndex(iSubelement0);
1037 }
1038 if (!vertex || !edge) {
1039 throw Base::RuntimeError("Missing geometry for dimension (4)");
1040 }
1041
1042 // get curve from edge
1043 double start{0.0}; // curve parameters
1044 double end{0.0}; // curve parameters
1045 const Handle(Geom_Surface) hplane = new Geom_Plane(gp_Ax3());
1046 auto const occCurve =
1047 BRep_Tool::CurveOnPlane(edge->getOCCEdge(), hplane, TopLoc_Location(), start, end);
1048 auto const occPoint = gp_Pnt2d(vertex->x(), vertex->y());
1049 // project point on curve
1050 auto projector = Geom2dAPI_ProjectPointOnCurve(occPoint, occCurve);
1051 if (projector.NbPoints() > 0) {
1052 auto p1 = Base::Vector3d(vertex->x(), vertex->y(), 0.0);
1053 auto p2 =
1054 Base::Vector3d(projector.NearestPoint().X(), projector.NearestPoint().Y(), 0.0);
1055 pointPair result = pointPair(p1, p2);
1056 result.setExtensionLine(closestPoints(edge->getOCCEdge(), vertex->getOCCVertex()));
1057 return result;
1058 }
1059 // unable to project
1060 return closestPoints(edge->getOCCEdge(), vertex->getOCCVertex());
1061 }
1062
1063 // this is a 3d object
1064 TopoDS_Shape geometry0 = references.at(0).getGeometry();
1065 TopoDS_Shape geometry1 = references.at(1).getGeometry();
1066 if (geometry0.IsNull() || geometry1.IsNull() || geometry0.ShapeType() != TopAbs_VERTEX
1067 || geometry1.ShapeType() != TopAbs_VERTEX) {
1068 throw Base::RuntimeError("Geometry for dimension reference is null.");
1069 }
1070
1071 pointPair pts = closestPoints(geometry0, geometry1);
1072 pts.move(getViewPart()->getCurrentCentroid());
1073 pts.project(getViewPart());
1074 return pts;
1075}
1076
1077arcPoints DrawViewDimension::getArcParameters(ReferenceVector references)

Callers

nothing calls this directly

Calls 15

Vector3dClass · 0.85
pointPairFunction · 0.85
atMethod · 0.80
getGeomByIndexMethod · 0.80
getProjVertexByIndexMethod · 0.80
NbPointsMethod · 0.80
setExtensionLineMethod · 0.80
getCurrentCentroidMethod · 0.80
TopLoc_LocationClass · 0.50
getObjectMethod · 0.45
frontMethod · 0.45
getSubNameMethod · 0.45

Tested by

no test coverage detected