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,
|
||||
extendBeyondDimLines = undef,
|
||||
textOffset = undef,
|
||||
direction = RIGHT,
|
||||
//direction = RIGHT,
|
||||
color = "Red",
|
||||
placement = TOP,
|
||||
strokeWidth = 1,
|
||||
font = "Saira Stencil One",
|
||||
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
|
||||
_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;
|
||||
// Calculate total height including text and extension lines
|
||||
totalHeight = _offsetFromOrigin + abs(_extendBeyondDimLines) + textSize;
|
||||
|
||||
// Size for attachable bounding box
|
||||
size = [length, totalHeight, strokeWidth];
|
||||
|
||||
// Draw the dimension
|
||||
color(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
|
||||
|
||||
|
||||
attachable(anchor, spin, orient, size=size) {
|
||||
// Compute rotation angle
|
||||
|
||||
/*
|
||||
angle =
|
||||
direction == RIGHT ? 0 :
|
||||
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 ) {
|
||||
//projection()
|
||||
quote(
|
||||
1000,
|
||||
quote(
|
||||
500,
|
||||
textSize=80,
|
||||
direction=RIGHT,
|
||||
placement=BOTTOM,
|
||||
//direction=RIGHT,
|
||||
//placement=BOTTOM,
|
||||
strokeWidth=2,
|
||||
orient=FRONT,
|
||||
orient=UP,
|
||||
spin=-90,
|
||||
anchor=CENTER
|
||||
);
|
||||
left (600) quote(
|
||||
500,
|
||||
//direction=UP
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user