Fix quotes rendering and doc
This commit is contained in:
parent
350b76c867
commit
64c646c98e
195
quotes.scad
195
quotes.scad
@ -1,65 +1,164 @@
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// LibFile: quotes.scad
|
||||
// Includes:
|
||||
// include <BOSL2/std.scad>;
|
||||
// FileGroup: Quotes
|
||||
// FileSummary: Quotes,Dimensions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
include <BOSL2/std.scad>
|
||||
|
||||
|
||||
debugging = false;
|
||||
quotes_debugging = false;
|
||||
|
||||
|
||||
/**
|
||||
* Quote
|
||||
*
|
||||
* @param offsetFromOrigin - It specifies the distance from the object being dimensioned to the start of the extension lines
|
||||
* @param extendBeyondDimLines - How much the extension lines extend past the dimension line
|
||||
* @param textOffset - Distance between dimension text and dimension line
|
||||
* @param direction - Direction of the dimension line (RIGHT, LEFT, UP, DOWN)
|
||||
* @param placement - If BOTTOM, places the dimension below the model; if TOP, above (default is TOP)
|
||||
*/
|
||||
module quote(
|
||||
length,
|
||||
offsetFromOrigin = 140,
|
||||
extendBeyondDimLines = 40,
|
||||
textOffset = 10,
|
||||
direction = RIGHT,
|
||||
color = "Red",
|
||||
placement = TOP
|
||||
){
|
||||
|
||||
// Determine rotation angle based on direction
|
||||
// Module: quote()
|
||||
//
|
||||
// Synopsis: Draws a dimension line with optional text labeling the length.
|
||||
// Topics: Dimensioning, Annotation
|
||||
// Description:
|
||||
// Creates a labeled dimension line with extension lines and an optional
|
||||
// length label. The dimension can be customized in terms of placement,
|
||||
// orientation, text formatting, and appearance.
|
||||
// Arguments:
|
||||
// length = The length of the dimension line.
|
||||
// textSize = Size of the text label [default: 60].
|
||||
// offsetFromOrigin = Distance of the dimension line from the reference [default: textSize].
|
||||
// extendBeyondDimLines = Length beyond the extension lines [default: textSize / 5].
|
||||
// textOffset = Offset of the text from the dimension line [default: textSize / 3].
|
||||
// direction = Direction of the dimension (RIGHT, LEFT, UP, DOWN) [default: RIGHT].
|
||||
// color = Color of the dimension line and text [default: "Red"].
|
||||
// placement = Position relative to the model (TOP or BOTTOM) [default: TOP].
|
||||
// strokeWidth = Thickness of the lines [default: 1].
|
||||
// font = Font used for text [default: "Saira Stencil One"].
|
||||
// orient = Text orientation (TOP or BOTTOM) [default: TOP].
|
||||
// anchor = Text alignment reference (CENTER, LEFT, RIGHT) [default: CENTER].
|
||||
// Example:
|
||||
// quote(length=100, textSize=50, placement=TOP, direction=RIGHT);
|
||||
module quote(
|
||||
length,
|
||||
textSize = 60,
|
||||
offsetFromOrigin = undef,
|
||||
extendBeyondDimLines = undef,
|
||||
textOffset = undef,
|
||||
direction = RIGHT,
|
||||
color = "Red",
|
||||
placement = TOP,
|
||||
strokeWidth = 1,
|
||||
font = "Saira Stencil One",
|
||||
orient = TOP,
|
||||
anchor = CENTER
|
||||
) {
|
||||
// Compute rotation angle
|
||||
|
||||
angle =
|
||||
direction == RIGHT ? 0 :
|
||||
direction == LEFT ? 180 :
|
||||
direction == UP ? 90 :
|
||||
direction == DOWN ? -90 : 0;
|
||||
|
||||
// Adjust offset based on whether the dimension is under the model
|
||||
actualOffset = placement == BOTTOM ? -offsetFromOrigin : offsetFromOrigin;
|
||||
|
||||
// Use color
|
||||
// Compute shift based on anchor point
|
||||
shift =
|
||||
anchor == RIGHT ? length/2 :
|
||||
anchor == LEFT ? -length/2 : 0;
|
||||
|
||||
// Default values if undefined
|
||||
_textOffset = (textOffset != undef) ? textOffset : textSize / 3;
|
||||
_extendBeyondDimLines = (extendBeyondDimLines != undef) ? extendBeyondDimLines : textSize / 5;
|
||||
_offsetFromOrigin = (offsetFromOrigin != undef) ? offsetFromOrigin : textSize;
|
||||
|
||||
// Adjust placement offset
|
||||
actualOffset = (placement == BOTTOM) ? -_offsetFromOrigin : _offsetFromOrigin;
|
||||
extOffset = (placement == BOTTOM) ? -_extendBeyondDimLines : _extendBeyondDimLines;
|
||||
|
||||
// Draw the dimension
|
||||
color(color) {
|
||||
// Rotate everything according to the direction
|
||||
zrot(angle) {
|
||||
path = [[ 0, actualOffset], [length-5 , actualOffset ]];
|
||||
// Paralel line
|
||||
stroke(path, width = 3,endcaps = "arrow2",endcap_width = 15);
|
||||
|
||||
// Extension Line 1
|
||||
ext1 = [[0,0], [0,actualOffset + (placement == BOTTOM ? -extendBeyondDimLines : extendBeyondDimLines)]];
|
||||
stroke(ext1, width=3);
|
||||
|
||||
// Extension Line 2
|
||||
ext2 = [[length,0], [length,actualOffset + (placement == BOTTOM ? -extendBeyondDimLines : extendBeyondDimLines)]];
|
||||
stroke(ext2, width=3);
|
||||
|
||||
// Text
|
||||
back( actualOffset + textOffset )
|
||||
right(length/2)
|
||||
text(str(length), size=60, font="Saira Stencil One", halign="center");
|
||||
}
|
||||
zrot(angle) left(shift) {
|
||||
arrowed_line([-length / 2, actualOffset, 0], [length / 2, actualOffset, 0]); // Parallel dimension line
|
||||
ext_line([-length / 2, 0, 0], [-length / 2, actualOffset + extOffset, 0]); // Left extension line
|
||||
ext_line([length / 2, 0, 0], [length / 2, actualOffset + extOffset, 0]); // Right extension line
|
||||
back(actualOffset + _textOffset)
|
||||
linear_extrude(0.1)
|
||||
text(str(length), size = textSize, font = font, halign = "center"); // Label
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Module: arrowed_line()
|
||||
//
|
||||
// Synopsis: Draws a straight line with arrowheads at both ends.
|
||||
// Topics: Geometry, Arrows, Lines
|
||||
// Description:
|
||||
// Creates a linear extrusion representing a line with arrowheads at both ends.
|
||||
// The line thickness, length, and arrow size can be customized.
|
||||
// Arguments:
|
||||
// point1 = [x, y] start point of the line.
|
||||
// point2 = [x, y] end point of the line.
|
||||
// width = Thickness of the line [default: 0.1].
|
||||
// endcap_width = Width of the arrowhead at each end [default: 15].
|
||||
// Example:
|
||||
// arrowed_line([0,0], [50,50], width=0.5, endcap_width=5);
|
||||
module arrowed_line( p1, p2 , width=0.5, endcap_width = 15) {
|
||||
dir = p2 - p1;
|
||||
angle = atan2(dir.y, dir.x);
|
||||
length = norm(dir);
|
||||
// Draw the line
|
||||
translate(p1)
|
||||
rotate([0, 0, atan2(p2.y - p1.y, p2.x - p1.x)])
|
||||
translate([length / 2, 0])
|
||||
linear_extrude(height = width)
|
||||
square([length, width], center = true);
|
||||
// Arrowhead shape
|
||||
arrow = [
|
||||
[ 0, 0],
|
||||
[ -endcap_width, -endcap_width / 2 ],
|
||||
[ -endcap_width, +endcap_width / 2 ]
|
||||
];
|
||||
// Draw arrowheads
|
||||
for (pt = [p1, p2])
|
||||
translate(pt)
|
||||
rotate(angle + (pt == p1 ? 180 : 0))
|
||||
linear_extrude(height = width)
|
||||
polygon(arrow);
|
||||
}
|
||||
|
||||
// Module: ext_line()
|
||||
//
|
||||
// Synopsis: Draws a straight extruded line between two points.
|
||||
// Topics: Geometry, Lines
|
||||
// Description:
|
||||
// Creates a linear extrusion representing a straight line segment with a
|
||||
// specified width between two given points.
|
||||
// Arguments:
|
||||
// point1 = [x, y] start point of the line.
|
||||
// point2 = [x, y] end point of the line.
|
||||
// width = Thickness of the line [default: 0.1].
|
||||
// Example:
|
||||
// ext_line([0,0], [50,50], width=0.5);
|
||||
module ext_line(p1, p2, width = 0.5) {
|
||||
dir = p2 - p1;
|
||||
angle = atan2(dir.y, dir.x);
|
||||
length = norm(dir);
|
||||
// Draw the line
|
||||
translate(p1)
|
||||
rotate([0, 0, atan2(p2.y - p1.y, p2.x - p1.x)])
|
||||
translate([length / 2, 0])
|
||||
linear_extrude(height = width)
|
||||
square([length, width], center = true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ( quotes_debugging ) {
|
||||
//projection()
|
||||
quote(
|
||||
1000,
|
||||
textSize=80,
|
||||
direction=RIGHT,
|
||||
placement=BOTTOM,
|
||||
strokeWidth=2,
|
||||
orient=FRONT,
|
||||
anchor=CENTER
|
||||
);
|
||||
}
|
||||
|
||||
if ( debugging )
|
||||
quote(1000,direction=RIGHT,placement=BOTTOM);
|
Loading…
x
Reference in New Issue
Block a user