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

Method getProjectedDimValue

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

retrieve the dimension value for "projected" (2d) dimensions. The returned value is in internal units (mm).

Source from the content-addressed store, hash-verified

734
735//! retrieve the dimension value for "projected" (2d) dimensions. The returned value is in internal units (mm).
736double DrawViewDimension::getProjectedDimValue() const
737{
738 double result = 0.0;
739 double scale = getViewPart()->getScale();
740
741 if (Type.isValue("Distance") || Type.isValue("DistanceX") || Type.isValue("DistanceY")) {
742 pointPair pts = getLinearPoints();
743 auto dbv = freecad_cast<DrawBrokenView*>(getViewPart());
744 if (dbv) {
745 // raw pts from view are inverted Y, so we need to un-invert them before mapping
746 // raw pts are scaled, so we need to unscale them for mapPoint2dFromView
747 // then rescale them for the distance calculation below
748 // centers are right side up
749 // if both points are on the expanded side of the last (rightmost/upmost) break
750 // then we should not move the points.
751 //
752 pts.invertY();
753 // unscale the points, map them to the broken view then rescale them to draw.
754 pts.scale(1 / scale);
755 pts.first(dbv->mapPoint2dFromView(pts.first()));
756 pts.second(dbv->mapPoint2dFromView(pts.second()));
757 pts.invertY();
758 pts.scale(scale);
759 }
760 Base::Vector3d dimVec = pts.first() - pts.second();
761 if (Type.isValue("Distance")) {
762 result = dimVec.Length() / scale;
763 }
764 else if (Type.isValue("DistanceX")) {
765 result = fabs(dimVec.x) / scale;
766 }
767 else {
768 result = fabs(dimVec.y) / scale;
769 }
770 }
771 else if (Type.isValue("Radius")) {
772 // Projected BaseGeom is scaled for drawing
773 result = m_arcPoints.radius / scale;
774 }
775 else if (Type.isValue("Diameter")) {
776 arcPoints pts = m_arcPoints;
777 result = (pts.radius * 2) / scale; // Projected BaseGeom is scaled for drawing
778 }
779 else if (Type.isValue("Angle") || Type.isValue("Angle3Pt")) { // same as case "Angle"?
780 anglePoints pts = m_anglePoints;
781 Base::Vector3d vertex = pts.vertex();
782 Base::Vector3d leg0 = pts.first() - vertex;
783 Base::Vector3d leg1 = pts.second() - vertex;
784 double legAngle = Base::toDegrees(leg0.GetAngle(leg1));
785 result = legAngle;
786 }
787 else if (Type.isValue("Area")) {
788 // 2d reference makes scaled values in areaPoint
789 // 3d reference makes actual values in areaPoint :p
790 double divisor{scale / scale};
791 if (has3DReferences()) {
792 divisor = 1.0;
793 }

Callers

nothing calls this directly

Calls 11

toDegreesFunction · 0.85
firstMethod · 0.80
vertexMethod · 0.80
getScaleMethod · 0.45
isValueMethod · 0.45
invertYMethod · 0.45
scaleMethod · 0.45
mapPoint2dFromViewMethod · 0.45
LengthMethod · 0.45
GetAngleMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected