Fix quotes rendering and doc
This commit is contained in:
parent
350b76c867
commit
64c646c98e
177
quotes.scad
177
quotes.scad
@ -1,65 +1,164 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// LibFile: quotes.scad
|
||||||
|
// Includes:
|
||||||
|
// include <BOSL2/std.scad>;
|
||||||
|
// FileGroup: Quotes
|
||||||
|
// FileSummary: Quotes,Dimensions
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
include <BOSL2/std.scad>
|
include <BOSL2/std.scad>
|
||||||
|
|
||||||
|
|
||||||
debugging = false;
|
quotes_debugging = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
// Module: quote()
|
||||||
* Quote
|
//
|
||||||
*
|
// Synopsis: Draws a dimension line with optional text labeling the length.
|
||||||
* @param offsetFromOrigin - It specifies the distance from the object being dimensioned to the start of the extension lines
|
// Topics: Dimensioning, Annotation
|
||||||
* @param extendBeyondDimLines - How much the extension lines extend past the dimension line
|
// Description:
|
||||||
* @param textOffset - Distance between dimension text and dimension line
|
// Creates a labeled dimension line with extension lines and an optional
|
||||||
* @param direction - Direction of the dimension line (RIGHT, LEFT, UP, DOWN)
|
// length label. The dimension can be customized in terms of placement,
|
||||||
* @param placement - If BOTTOM, places the dimension below the model; if TOP, above (default is TOP)
|
// 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(
|
module quote(
|
||||||
length,
|
length,
|
||||||
offsetFromOrigin = 140,
|
textSize = 60,
|
||||||
extendBeyondDimLines = 40,
|
offsetFromOrigin = undef,
|
||||||
textOffset = 10,
|
extendBeyondDimLines = undef,
|
||||||
|
textOffset = undef,
|
||||||
direction = RIGHT,
|
direction = RIGHT,
|
||||||
color = "Red",
|
color = "Red",
|
||||||
placement = TOP
|
placement = TOP,
|
||||||
){
|
strokeWidth = 1,
|
||||||
|
font = "Saira Stencil One",
|
||||||
|
orient = TOP,
|
||||||
|
anchor = CENTER
|
||||||
|
) {
|
||||||
|
// Compute rotation angle
|
||||||
|
|
||||||
// Determine rotation angle based on direction
|
|
||||||
angle =
|
angle =
|
||||||
direction == RIGHT ? 0 :
|
direction == RIGHT ? 0 :
|
||||||
direction == LEFT ? 180 :
|
direction == LEFT ? 180 :
|
||||||
direction == UP ? 90 :
|
direction == UP ? 90 :
|
||||||
direction == DOWN ? -90 : 0;
|
direction == DOWN ? -90 : 0;
|
||||||
|
// Compute shift based on anchor point
|
||||||
|
shift =
|
||||||
|
anchor == RIGHT ? length/2 :
|
||||||
|
anchor == LEFT ? -length/2 : 0;
|
||||||
|
|
||||||
// Adjust offset based on whether the dimension is under the model
|
// Default values if undefined
|
||||||
actualOffset = placement == BOTTOM ? -offsetFromOrigin : offsetFromOrigin;
|
_textOffset = (textOffset != undef) ? textOffset : textSize / 3;
|
||||||
|
_extendBeyondDimLines = (extendBeyondDimLines != undef) ? extendBeyondDimLines : textSize / 5;
|
||||||
|
_offsetFromOrigin = (offsetFromOrigin != undef) ? offsetFromOrigin : textSize;
|
||||||
|
|
||||||
// Use color
|
// Adjust placement offset
|
||||||
|
actualOffset = (placement == BOTTOM) ? -_offsetFromOrigin : _offsetFromOrigin;
|
||||||
|
extOffset = (placement == BOTTOM) ? -_extendBeyondDimLines : _extendBeyondDimLines;
|
||||||
|
|
||||||
|
// Draw the dimension
|
||||||
color(color) {
|
color(color) {
|
||||||
// Rotate everything according to the direction
|
zrot(angle) left(shift) {
|
||||||
zrot(angle) {
|
arrowed_line([-length / 2, actualOffset, 0], [length / 2, actualOffset, 0]); // Parallel dimension line
|
||||||
path = [[ 0, actualOffset], [length-5 , actualOffset ]];
|
ext_line([-length / 2, 0, 0], [-length / 2, actualOffset + extOffset, 0]); // Left extension line
|
||||||
// Paralel line
|
ext_line([length / 2, 0, 0], [length / 2, actualOffset + extOffset, 0]); // Right extension line
|
||||||
stroke(path, width = 3,endcaps = "arrow2",endcap_width = 15);
|
back(actualOffset + _textOffset)
|
||||||
|
linear_extrude(0.1)
|
||||||
// Extension Line 1
|
text(str(length), size = textSize, font = font, halign = "center"); // Label
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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