improve ordinate dimension renderer
from typing import TYPE_CHECKING, List
import logging
-from ezdxf.math import Vec2, UCS, NULLVEC
+from ezdxf.math import Vec2, UCS, NULLVEC, sign
from ezdxf.lldxf import const
from ezdxf.entities import DimStyleOverride, Dimension
from .dim_base import (
BaseDimensionRenderer,
get_required_defpoint,
compile_mtext,
- TextBox,
)
if TYPE_CHECKING:
@@ -38,11 +37,23 @@ class OrdinateDimension(BaseDimensionRenderer):
dimension, "defpoint2"
)
self.end_of_leader: Vec2 = get_required_defpoint(dimension, "defpoint3")
+ self.leader_offset = self.end_of_leader - self.feature_location
# x_type = not(y_type)
self.y_type = bool(
dimension.dxf.get("dimtype", 0) & const.DIM_ORDINATE_TYPE
)
super().__init__(dimension, ucs, override)
+
+ # Main direction vectors for x-type:
+ self.direction: Vec2 = Vec2(
+ -1.0 if self.leader_offset.x < 0.0 else 1.0, 0
+ )
+ self.dir_ortho: Vec2 = Vec2(
+ 0, -1.0 if self.leader_offset.y < 0.0 else 1.0
+ )
+ if self.y_type:
+ self.direction, self.dir_ortho = self.dir_ortho, self.direction
+
# Class specific setup:
self.update_measurement()
if self.tol.has_limits:
@@ -62,10 +73,18 @@ class OrdinateDimension(BaseDimensionRenderer):
self.dimension.dxf.text_midpoint = self.measurement.text_location
def setup_text_location(self) -> None:
- """Setup geometric text properties (location, rotation) and the TextBox
- object.
- """
- pass
+ """Setup geometric text properties location and rotation."""
+ self.measurement.text_location = (
+ self.end_of_leader
+ + self.direction * self.text_box.width / 2.0
+ + self.dir_ortho * self.measurement.text_vertical_distance()
+ )
+ if self.measurement.text_rotation is None:
+ # if no user text rotation is set:
+ if self.y_type:
+ self.measurement.text_rotation = 90.0
+ else:
+ self.measurement.text_rotation = 0.0
def update_measurement(self) -> None:
distance: Vec2 = self.feature_location - self.origin
