Fix attachable and remove direction
This commit is contained in:
parent
64c646c98e
commit
edf09a7cf5
42
examples.scad
Normal file
42
examples.scad
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
include <titleBlock.scad>
|
||||||
|
include <quotes.scad>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
plan(
|
||||||
|
"Title Block",
|
||||||
|
title="Sub title",
|
||||||
|
description="Description",
|
||||||
|
) {
|
||||||
|
|
||||||
|
|
||||||
|
scaling = 10;
|
||||||
|
scale ([1/scaling,1/scaling,1/scaling]) {
|
||||||
|
//translate([100,-100,0])
|
||||||
|
|
||||||
|
w = 800;
|
||||||
|
h = 600;
|
||||||
|
//projection()
|
||||||
|
color ("Gray") cube([w,h,1],anchor=CENTER+TOP) {
|
||||||
|
show_anchors();
|
||||||
|
align(BACK)
|
||||||
|
quote(w/*,anchor=LEFT*/){
|
||||||
|
show_anchors();
|
||||||
|
}
|
||||||
|
;
|
||||||
|
//right (800)
|
||||||
|
//attach(RIGHT,UP)
|
||||||
|
color("black") up(2)
|
||||||
|
align( RIGHT )
|
||||||
|
//quote(h/*,anchor=LEFT*/,color="Black")
|
||||||
|
quote(h,spin=-90) show_anchors()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
85
quotes.scad
85
quotes.scad
@ -41,46 +41,64 @@ module quote(
|
|||||||
offsetFromOrigin = undef,
|
offsetFromOrigin = undef,
|
||||||
extendBeyondDimLines = undef,
|
extendBeyondDimLines = undef,
|
||||||
textOffset = undef,
|
textOffset = undef,
|
||||||
direction = RIGHT,
|
//direction = RIGHT,
|
||||||
color = "Red",
|
color = "Red",
|
||||||
placement = TOP,
|
placement = TOP,
|
||||||
strokeWidth = 1,
|
strokeWidth = 1,
|
||||||
font = "Saira Stencil One",
|
font = "Saira Stencil One",
|
||||||
orient = TOP,
|
orient = TOP,
|
||||||
anchor = CENTER
|
anchor = CENTER,
|
||||||
|
spin = 0
|
||||||
) {
|
) {
|
||||||
// Compute rotation angle
|
|
||||||
|
|
||||||
angle =
|
|
||||||
direction == RIGHT ? 0 :
|
|
||||||
direction == LEFT ? 180 :
|
|
||||||
direction == UP ? 90 :
|
|
||||||
direction == DOWN ? -90 : 0;
|
|
||||||
// Compute shift based on anchor point
|
|
||||||
shift =
|
|
||||||
anchor == RIGHT ? length/2 :
|
|
||||||
anchor == LEFT ? -length/2 : 0;
|
|
||||||
|
|
||||||
// Default values if undefined
|
// Default values if undefined
|
||||||
_textOffset = (textOffset != undef) ? textOffset : textSize / 3;
|
_textOffset = (textOffset != undef) ? textOffset : textSize / 3;
|
||||||
_extendBeyondDimLines = (extendBeyondDimLines != undef) ? extendBeyondDimLines : textSize / 5;
|
_extendBeyondDimLines = (extendBeyondDimLines != undef) ? extendBeyondDimLines : textSize / 5;
|
||||||
_offsetFromOrigin = (offsetFromOrigin != undef) ? offsetFromOrigin : textSize;
|
_offsetFromOrigin = (offsetFromOrigin != undef) ? offsetFromOrigin : textSize;
|
||||||
|
|
||||||
// Adjust placement offset
|
// Calculate total height including text and extension lines
|
||||||
actualOffset = (placement == BOTTOM) ? -_offsetFromOrigin : _offsetFromOrigin;
|
totalHeight = _offsetFromOrigin + abs(_extendBeyondDimLines) + textSize;
|
||||||
extOffset = (placement == BOTTOM) ? -_extendBeyondDimLines : _extendBeyondDimLines;
|
|
||||||
|
// Size for attachable bounding box
|
||||||
|
size = [length, totalHeight, strokeWidth];
|
||||||
|
|
||||||
// Draw the dimension
|
|
||||||
color(color) {
|
|
||||||
zrot(angle) left(shift) {
|
attachable(anchor, spin, orient, size=size) {
|
||||||
arrowed_line([-length / 2, actualOffset, 0], [length / 2, actualOffset, 0]); // Parallel dimension line
|
// Compute rotation angle
|
||||||
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)
|
angle =
|
||||||
linear_extrude(0.1)
|
direction == RIGHT ? 0 :
|
||||||
text(str(length), size = textSize, font = font, halign = "center"); // Label
|
direction == LEFT ? 180 :
|
||||||
|
direction == FRONT ? -90 :
|
||||||
|
direction == BACK ? +90 : 0;
|
||||||
|
*/
|
||||||
|
// Compute shift based on anchor point
|
||||||
|
shift =
|
||||||
|
anchor == RIGHT ? length/2 :
|
||||||
|
anchor == LEFT ? -length/2 : 0;
|
||||||
|
|
||||||
|
|
||||||
|
// Adjust placement offset
|
||||||
|
actualOffset = (placement == BOTTOM) ? -_offsetFromOrigin : _offsetFromOrigin;
|
||||||
|
extOffset = (placement == BOTTOM) ? -_extendBeyondDimLines : _extendBeyondDimLines;
|
||||||
|
|
||||||
|
|
||||||
|
// Draw the dimension
|
||||||
|
recolor(color) {
|
||||||
|
//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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
children();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -151,14 +169,19 @@ module ext_line(p1, p2, width = 0.5) {
|
|||||||
|
|
||||||
if ( quotes_debugging ) {
|
if ( quotes_debugging ) {
|
||||||
//projection()
|
//projection()
|
||||||
quote(
|
quote(
|
||||||
1000,
|
500,
|
||||||
textSize=80,
|
textSize=80,
|
||||||
direction=RIGHT,
|
//direction=RIGHT,
|
||||||
placement=BOTTOM,
|
//placement=BOTTOM,
|
||||||
strokeWidth=2,
|
strokeWidth=2,
|
||||||
orient=FRONT,
|
orient=UP,
|
||||||
|
spin=-90,
|
||||||
anchor=CENTER
|
anchor=CENTER
|
||||||
);
|
);
|
||||||
|
left (600) quote(
|
||||||
|
500,
|
||||||
|
//direction=UP
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user