// https://www.thingiverse.com/thing:3346069
//upper text line
textstring1="PLA+ 2.0";
textsize_upper=5; 

textstring2="0.4 0.2  200°C";
textstring3="SUNLU";

textsize_lower=5; 

//Top text (on the top edge, to quickly find the material type). 
texttop_predefined=" P L A P l u s";//[-,P L A, A B S, P E T G, N y l o n, P V B, H I P S, P E E K, T P U, P O M, P V A, P P, A S A, P C, U L T E M, R e s i n, P A, n G E N, H T, P H A, A M 1 8 0 0,A M 3 3 0 0,N G E N _ F L E X,P U R,F L 6 0 0 0]

//Own top text: Use text here if you want to override the drop-down right above. Note that you can increase readability by using all capital letters and by spacing the letters out with a space each: "P L A" 
texttop_configurable="SUNLU PLA+ 2.0";

//Font name, e.g. "Pathway Gothic One,", "Voltaire", "Oswald", depends on what is available on the platform. In the customizer,choose from about 700 Google Fonts. For an overview please refer: http://www.google.com/fonts. I like the Aldo font and use it with OpenSCAD on my PC.
fontname="Noto Sans";//[Pathway Gothic One,Voltaire,Oswald,"Oswald:style=Bold","PT Sans Narrow:style=Bold",Archivo,ABeeZee,Abel,Abril Fatface,Aclonica,Acme,Actor,Adamina,Advent Pro,Aguafina Script,Akronim,Aladin,Aldrich,Alef,Alegreya,Alegreya Sans,Alegreya Sans SC,Alegreya SC,Alex Brush,Alfa Slab One,Alice,Alike,Alike Angular,Allan,Allerta,Allerta Stencil,Allura,Almendra,Almendra Display,Almendra SC,Amarante,Amaranth,Amatic SC,Amethysta,Amiri,Anaheim,Andada,Andika,Angkor,Annie Use Your Telescope,Anonymous Pro,Antic,Antic Didone,Antic Slab,Anton,Arapey,Arbutus,Arbutus Slab,Architects Daughter,Archivo Black,Archivo Narrow,Arimo,Arizonia,Armata,Artifika,Arvo,Asap,Asset,Astloch,Asul,Atomic Age,Aubrey,Audiowide,Autour One,Average,Average Sans,Averia Gruesa Libre,Averia Libre,Averia Sans Libre,Averia Serif Libre,Bad Script,Balthazar,Bangers,Basic,Battambang,Baumans,Bayon,Belgrano,Belleza,BenchNine,Bentham,Berkshire Swash,Bevan,Bigelow Rules,Bigshot One,Bilbo,Bilbo Swash Caps,Bitter,Black Ops One,Bokor,Bonbon,Boogaloo,Bowlby One,Bowlby One SC,Brawler,Bree Serif,Bubblegum Sans,Bubbler One,Buda,Buenard,Butcherman,Butterfly Kids,Cabin,Cabin Condensed,Cabin Sketch,Caesar Dressing,Cagliostro,Calligraffitti,Cambay,Cambo,Candal,Cantarell,Cantata One,Cantora One,Capriola,Cardo,Carme,Carrois Gothic,Carrois Gothic SC,Carter One,Caudex,Cedarville Cursive,Ceviche One,Changa One,Chango,Chau Philomene One,Chela One,Chelsea Market,Chenla,Cherry Cream Soda,Cherry Swash,Chewy,Chicle,Chivo,Cinzel,Cinzel Decorative,Clicker Script,Coda,Coda Caption,Codystar,Combo,Comfortaa,Coming Soon,Concert One,Condiment,Content,Contrail One,Convergence,Cookie,Copse,Corben,Courgette,Cousine,Coustard,Covered By Your Grace,Crafty Girls,Creepster,Crete Round,Crimson Text,Croissant One,Crushed,Cuprum,Cutive,Cutive Mono,Damion,Dancing Script,Dangrek,Dawning of a New Day,Days One,Dekko,Delius,Delius Swash Caps,Delius Unicase,Della Respira,Denk One,Devonshire,Dhurjati,Didact Gothic,Diplomata,Diplomata SC,Domine,Donegal One,Doppio One,Dorsa,Dosis,Dr Sugiyama,Droid Sans,Droid Sans Mono,Droid Serif,Duru Sans,Dynalight,Eagle Lake,Eater,EB Garamond,Economica,Ek Mukta,Electrolize,Elsie,Elsie Swash Caps,Emblema One,Emilys Candy,Engagement,Englebert,Enriqueta,Erica One,Esteban,Euphoria Script,Ewert,Exo,Exo 2,Expletus Sans,Fanwood Text,Fascinate,Fascinate Inline,Faster One,Fasthand,Fauna One,Federant,Federo,Felipa,Fenix,Finger Paint,Fira Mono,Fira Sans,Fjalla One,Fjord One,Flamenco,Flavors,Fondamento,Fontdiner Swanky,Forum,Francois One,Freckle Face,Fredericka the Great,Fredoka One,Freehand,Fresca,Frijole,Fruktur,Fugaz One,Gabriela,Gafata,Galdeano,Galindo,Gentium Basic,Gentium Book Basic,Geo,Geostar,Geostar Fill,Germania One,GFS Didot,GFS Neohellenic,Gidugu,Gilda Display,Give You Glory,Glass Antiqua,Glegoo,Gloria Hallelujah,Goblin One,Gochi Hand,Gorditas,Goudy Bookletter 1911,Graduate,Grand Hotel,Gravitas One,Great Vibes,Griffy,Gruppo,Gudea,Gurajada,Habibi,Halant,Hammersmith One,Hanalei,Hanalei Fill,Handlee,Hanuman,Happy Monkey,Headland One,Henny Penny,Herr Von Muellerhoff,Hind,Holtwood One SC,Homemade Apple,Homenaje,Iceberg,Iceland,IM Fell Double Pica,IM Fell Double Pica SC,IM Fell DW Pica,IM Fell DW Pica SC,IM Fell English,IM Fell English SC,IM Fell French Canon,IM Fell French Canon SC,IM Fell Great Primer,IM Fell Great Primer SC,Imprima,Inconsolata,Inder,Indie Flower,Inika,Irish Grover,Istok Web,Italiana,Italianno,Jacques Francois,Jacques Francois Shadow,Jim Nightshade,Jockey One,Jolly Lodger,Josefin Sans,Josefin Slab,Joti One,Judson,Julee,Julius Sans One,Junge,Jura,Just Another Hand,Just Me Again Down Here,Kalam,Kameron,Kantumruy,Karla,Karma,Kaushan Script,Kavoon,Kdam Thmor,Keania One,Kelly Slab,Kenia,Khand,Khmer,Khula,Kite One,Knewave,Kotta One,Koulen,Kranky,Kreon,Kristi,Krona One,La Belle Aurore,Laila,Lakki Reddy,Lancelot,Lateef,Lato,League Script,Leckerli One,Ledger,Lekton,Lemon,Liberation Sans,Libre Baskerville,Life Savers,Lilita One,Lily Script One,Limelight,Linden Hill,Lobster,Lobster Two,Londrina Outline,Londrina Shadow,Londrina Sketch,Londrina Solid,Lora,Love Ya Like A Sister,Loved by the King,Lovers Quarrel,Luckiest Guy,Lusitana,Lustria,Macondo,Macondo Swash Caps,Magra,Maiden Orange,Mako,Mallanna,Mandali,Marcellus,Marcellus SC,Marck Script,Margarine,Marko One,Marmelad,Martel Sans,Marvel,Mate,Mate SC,Maven Pro,McLaren,Meddon,MedievalSharp,Medula One,Megrim,Meie Script,Merienda,Merienda One,Merriweather,Merriweather Sans,Metal,Metal Mania,Metamorphous,Metrophobic,Michroma,Milonga,Miltonian,Miltonian Tattoo,Miniver,Miss Fajardose,Modak,Modern Antiqua,Molengo,Molle,Monda,Monofett,Monoton,Monsieur La Doulaise,Montaga,Montez,Montserrat,Montserrat Alternates,Montserrat Subrayada,Moul,Moulpali,Mountains of Christmas,Mouse Memoirs,Mr Bedfort,Mr Dafoe,Mr De Haviland,Mrs Saint Delafield,Mrs Sheppards,Muli,Mystery Quest,Neucha,Neuton,New Rocker,News Cycle,Niconne,Nixie One,Nobile,Nokora,Norican,Nosifer,Nothing You Could Do,Noticia Text,Noto Sans,Noto Serif,Nova Cut,Nova Flat,Nova Mono,Nova Oval,Nova Round,Nova Script,Nova Slim,Nova Square,NTR,Numans,Nunito,Odor Mean Chey,Offside,Old Standard TT,Oldenburg,Oleo Script,Oleo Script Swash Caps,Open Sans,Open Sans Condensed,Oranienbaum,Orbitron,Oregano,Orienta,Original Surfer,Over the Rainbow,Overlock,Overlock SC,Ovo,Oxygen,Oxygen Mono,Pacifico,Paprika,Parisienne,Passero One,Passion One,Patrick Hand,Patrick Hand SC,Patua One,Paytone One,Peddana,Peralta,Permanent Marker,Petit Formal Script,Petrona,Philosopher,Piedra,Pinyon Script,Pirata One,Plaster,Play,Playball,Playfair Display,Playfair Display SC,Podkova,Poiret One,Poller One,Poly,Pompiere,Pontano Sans,Port Lligat Sans,Port Lligat Slab,Prata,Preahvihear,Press Start 2P,Princess Sofia,Prociono,Prosto One,PT Mono,PT Sans,PT Sans Caption,PT Sans Narrow,PT Serif,PT Serif Caption,Puritan,Purple Purse,Quando,Quantico,Quattrocento,Quattrocento Sans,Questrial,Quicksand,Quintessential,Qwigley,Racing Sans One,Radley,Rajdhani,Raleway,Raleway Dots,Ramabhadra,Ramaraja,Rambla,Rammetto One,Ranchers,Rancho,Ranga,Rationale,Ravi Prakash,Redressed,Reenie Beanie,Revalia,Ribeye,Ribeye Marrow,Righteous,Risque,Roboto,Roboto Condensed,Roboto Slab,Rochester,Rock Salt,Rokkitt,Romanesco,Ropa Sans,Rosario,Rosarivo,Rouge Script,Rozha One,Rubik Mono One,Rubik One,Ruda,Rufina,Ruge Boogie,Ruluko,Rum Raisin,Ruslan Display,Russo One,Ruthie,Rye,Sacramento,Sail,Salsa,Sanchez,Sancreek,Sansita One,Sarina,Sarpanch,Satisfy,Scada,Scheherazade,Schoolbell,Seaweed Script,Sevillana,Seymour One,Shadows Into Light,Shadows Into Light Two,Shanti,Share,Share Tech,Share Tech Mono,Shojumaru,Short Stack,Siemreap,Sigmar One,Signika,Signika Negative,Simonetta,Sintony,Sirin Stencil,Six Caps,Skranji,Slabo 13px,Slabo 27px,Slackey,Smokum,Smythe,Sniglet,Snippet,Snowburst One,Sofadi One,Sofia,Sonsie One,Sorts Mill Goudy,Source Code Pro,Source Sans Pro,Source Serif Pro,Special Elite,Spicy Rice,Spinnaker,Spirax,Squada One,Sree Krushnadevaraya,Stalemate,Stalinist One,Stardos Stencil,Stint Ultra Condensed,Stint Ultra Expanded,Stoke,Strait,Sue Ellen Francisco,Sunshiney,Supermercado One,Suranna,Suravaram,Suwannaphum,Swanky and Moo Moo,Syncopate,Tangerine,Taprom,Tauri,Teko,Telex,Tenali Ramakrishna,Tenor Sans,Text Me One,The Girl Next Door,Tienne,Timmana,Tinos,Titan One,Titillium Web,Trade Winds,Trocchi,Trochut,Trykker,Tulpen One,Ubuntu,Ubuntu Condensed,Ubuntu Mono,Ultra,Uncial Antiqua,Underdog,Unica One,UnifrakturCook,UnifrakturMaguntia,Unkempt,Unlock,Unna,Vampiro One,Varela,Varela Round,Vast Shadow,Vesper Libre,Vibur,Vidaloka,Viga,Voces,Volkhov,Vollkorn,VT323,Waiting for the Sunrise,Wallpoet,Walter Turncoat,Warnes,Wellfleet,Wendy One,Wire One,Yanone Kaffeesatz,Yellowtail,Yeseva One,Yesteryear,Zeyada]


//Text raised or embossed
text_type="embossed";//[embossed,raised]

//Different top edges for testing enabled? If you want a simple rounded swatch, set this to disabled
edge_tests="enabled";//[enabled,disabled]

//Number of advanced test circles?
test_circles=6;//[0:6]

// Thickness progression of the 'layers' is taken from https://www.thingiverse.com/thing:3067940 : 0.2, 0.4, 0.6, 0.8, 1.0, 1.6, without the 2.25 mm. If you put a negative number here, it will generate a "bridge" structure of the respective thickness.
steps_thickness=[-.6, 0.2, 0.4, 0.6, 0.8, 1.0, 1.5]; 
// steps_thickness=[-.9, 0.3, 0.6, 0.9, 1.2, 1.5, 2]; 

//Switch on or off the text to indicate the thickness on the steps
steps_text="enabled";//[enabled,disabled]

//Set font size on the thickness steps in mm. These show the step size below (0.2, 0.4, ...). 
steps_textsize=4;

//textheight on thickness steps
steps_textheight=.4;

//Set wether the leading zeroes should be visible on the thickness steps.
steps_text_format="enforce leading and trailing zero 0.0";//[enforce leading zero 0._,enforce leading and trailing zero 0.0,no enforcing _._]

//rotate the text on the steps by 90 degree?
steps_text_rotate="no";//[yes,no]

//Swatch size. This is compatible to Jaxels box. Other sizes are e.g. 75,40,3. First is swatch Width
w=79.5; 

//Swatch Height, should be >=26mm. If you go below 26mm, you will have to reduce the values wall=1 and round=2
h=30; 

//Swatch Thickness, should be >=.18mm. 
th=2.2;
 
//Swatch roundness radius
round=5;

//Border size around the text
wall=2;

//Text line separation
linesep=1.4;

//hole radius. Set to 0 to have no hole
r_hole=2.5;

//side indents to take out the swatch from the box. set to 0 to have no indents
r_indent=2.5;
 

/* [Hidden] */
//-------------------------------------------------------------------------------

/*
Configurable Filament Swatch 
Version ZA, January 2022
Written by MC Geisler (mcgenki at gmail dot com)

This is a swatch with configurable text.

Have fun!

License: Attribution 4.0 International (CC BY 4.0)

You are free to:
    Share - copy and redistribute the material in any medium or format
    Adapt - remix, transform, and build upon the material
    for any purpose, even commercially.
*/

texttop=(texttop_configurable==""?texttop_predefined:texttop_configurable);

$fn=48;

font_recessed=0.8;

//***USE THIS ONLY IF YOU KNOW WHAT YOU ARE DOING***: In case your steps are not in the right heigt, add here some little bit of thickness to your step height. This might help e.g. if you use cura to slice. Its not needed for Simplify3D or Slic3r.
step_thickness_correction=0;

module rounded_square(x,y,z,r)
{
    delta=r;
    
    hull()
    {
        translate([r,r,0]) cylinder(h=z,r=r);
        translate([-r+x,r,0]) cylinder(h=z,r=r);
        translate([r,-r+y,0]) cylinder(h=z,r=r);
        translate([-r+x,-r+y,0])cylinder(h=z,r=r);
    }
}

module rounded_biteoff_square(x,y,z,r)
{  
    delta=r;
    
    difference()
    {
        translate([-delta,0,0])
            cube([x+2*r,y,z]);
        
        translate([-2*r,0,0])
        hull()
        {
            translate([r,r,-.1]) cylinder(h=z+1,r=r);
            translate([r,-r+y,-.1]) cylinder(h=z+1,r=r);
        }
        
        translate([2*r,0,0])
        hull()
        {
            translate([-r+x,-r+y,-.1])cylinder(h=z+1,r=r);
            translate([-r+x,r,-.1]) cylinder(h=z+1,r=r);
        }
    }
}

module write_text_on_top(x,y,z,dist)
{
            //text on top
        fontdepth=.6;
        translate([x-dist,y-fontdepth,z-.2+.1*0]) 
        //translate([ w-2*wall,h-wall-textsize*(1+linesep),height ])
            rotate([-90,0,0])
                linear_extrude(height=fontdepth*2,convexity = 10)
                    text(texttop,size=z-.6,font="Open Sans:style=Bold",halign="right",valign="bottom");   
}

module rounded_square_test_pattern(x,y,z,r)
{
    delta=r;
    r3=z/2;
    r2=r;

    difference()
    {
        hull()
        {
            //bottom left cylindrical/round
            translate([r,r,0]) cylinder(h=z,r=r);
            
            //bottom right test flattened/round
//            translate([-r2+x-delta,r2,0]) cylinder(h=z,r=r2);
//            translate([-r2+x,r2+delta,0]) cylinder(h=z,r=r2);
//            translate([-r2+x,r2,z/2]) 
//                scale([r2,r2,z/2])
//                    sphere(r=1);
            translate([-r+x,r,0]) cylinder(h=z,r=r);
            
            //upper left ball/rounded
            /// translate([r,-r+y,0]) cylinder(h=z,r=r);
            translate([r3,-r3+y,r3]) scale([r3,r3,z/2]) sphere(r=1);
            
            //upper right corner
            r_corner=.1;
            translate([-r_corner+x,-r_corner+y,0]) cylinder(h=z,r=r_corner);
        }
        
        for (i = [0:test_circles])
        {
            //circle top left with round test pattern
            translate([wall+r_hole+r_hole*2.5*i,h-wall-r_hole,th/2-.1])
                cylinder(r=r_hole, h=th+.2, center=true);
            
            if (i==6) //filament holder
            {
                //filament container
                filament_r=1.8/2;
                translate([wall+r_hole+r_hole*2.5*i, h+.1, th/2])
                    rotate([90,0,0])
                        cylinder(r=filament_r,h=r_hole*2+wall+2,center=false);
            }
        }          
        
        //cuts
        cutin=wall*1.2;
        cutwide=1;
        wallwide_from=.5;
        wallwide_step=.1;
        wallwide_number=5;
        for(i=[0:wallwide_number-1])
        {
            wallwide=wallwide_from+wallwide_step*i;
            translate([x-r-r2-(cutwide+wallwide)*i,-.1,-.1]) 
                cube([cutwide,cutin+.1,z+.2]);
        }
        
        //overhang
        i=wallwide_number-1;
        short_x=(x-r-r2-(cutwide+wallwide_from+wallwide_step*i)*i);
        translate([0,-.01,-z])
            rotate([0,-asin(2*z/short_x),0])
                cube([short_x,wall*1.2,z]);
        
        //write_text_on_top(x,y,z);
    }
}


module rounded_square_test_pattern_raised(x,y,z,r,text_type, edge_tests)
{ 
    //sphere test
    if(test_circles>=1)
        translate([wall+r_hole+r_hole*2.5,h-wall-r_hole,th/2])
            intersection()
            {
                cylinder(r=r_hole, h=th, center=true);
                translate([0,0,-r_hole+th/2])
                    sphere(r=r_hole);
            }
        
    //cylinder/hole test
    r_testhole=.5;
    r_testcylinder=r_testhole+.5;
    if(test_circles>=2)
    translate([wall+r_hole+r_hole*5,h-wall-r_hole,th/2])
        difference()
        {
            union()
            {
                cylinder(r=r_testcylinder, h=th, center=true);
                translate([-r_testhole,-r_hole,-th/2])
                    cube([r_testhole*2,r_hole*2,.2],center=false);
                if (text_type=="embossed")
                    translate([-r_hole,-r_testhole,th/2-.2])
                        cube([r_hole*2,r_testhole*2,.2],center=false);
            }
            cylinder(r=r_testhole, h=th+.2, center=true);
        }
    
    //overhang test
    bridge_h=.2;
    bridge_pos=(text_type=="raised"?th-font_recessed-bridge_h:th/2) ;
    if(test_circles>=3)
        translate([wall+r_hole+r_hole*7.5,h-wall-r_hole,bridge_pos])
            translate([-r_hole/2,-r_hole,0])
                cube([r_hole,r_hole*2,bridge_h],center=false);
        
    //hanging cylinder test
    testradius=(z-.3)/2;
    if(test_circles>=4)
        translate([wall+r_hole+r_hole*10, h-wall-r_hole*.5, th-testradius])
                rotate([90,0,0])
                    cylinder(r=testradius,h=r_hole*1.7,center=false);
 
     //pyramid test
    testpyramid=z-.3;
    biggerpyramid=1;
    if(test_circles>=5)
    {
        translate([wall+r_hole+r_hole*12.5, h-wall-r_hole*2, th-z/2])
            rotate([-90,45,0])
                cylinder(d1=z*sqrt(2), d2=0, h=testpyramid, $fn=4);
        translate([wall+r_hole+r_hole*12.5, h-wall, th-z/2])
            intersection()
            {
                rotate([90,0,0])
                    cylinder(d1=z*sqrt(2), d2=0, h=testpyramid*1, $fn=4);
                cube([3*z,3*z,z],center=true);
            }
    }
    //6
//    testwidth=z-.5;
//    translate([wall+r_hole+r_hole*15, h-wall-r_hole*1.4, th-testwidth/2])
//        cube([testwidth,r_hole*2,testwidth],center=true);

}

module textlines(height)
{
    translate([ w-wall,h-wall-textsize_upper,height ])
        linear_extrude(height=th,convexity = 10)
            text(textstring1,size=textsize_upper,font=fontname,halign="right",valign="baseline");  
    
    translate([ wall,h-wall-(textsize_upper+textsize_lower*linesep),height ])
        linear_extrude(height=th,convexity = 10)
                text(textstring2,size=textsize_lower,font=fontname,halign="left",valign="baseline");  
    
    translate([ w-wall,h-wall-(textsize_upper+textsize_lower*linesep),height ])
        linear_extrude(height=th,convexity = 10)
                text(textstring3,size=textsize_lower,font=fontname,halign="right",valign="baseline");      
}



/**** substr ****

[str] substr(`str`, `[pos]`, `[len]`)
Returns a substring of a string.

Arguments:
- [str] `str`: The original string.
- [int] `pos` (optional): The substring position (0 by default).
- [int] `len` (optional): The substring length (string length by default).

Usage:
str = "OpenScad is a free CAD software.";
echo(substr(str, 12)); // "a free CAD software."
echo(substr(str, 12, 10)); // "a free CAD"
echo(substr(str, len=8)); // or substr(str, 0, 8); // "OpenScad"
*/

function substr(str, pos=0, len=-1, substr="") =
	len == 0 ? substr :
	len == -1 ? substr(str, pos, len(str)-pos, substr) :
	substr(str, pos+1, len-1, str(substr, str[pos]));

function no_leading_zero(strng) =
	strng == undef?
		undef
	: strng == ""?
		""
	: strng[0] == "0"?
        substr(strng, pos=1, len=-1, substr="")
    : strng;




function str_configurable_zero(number) =
	steps_text_format=="enforce leading zero 0._"?
		str(abs(number))
	: steps_text_format=="enforce leading and trailing zero 0.0"?
		 (round(number)==number? substr(str(abs(number+.01)), pos=0, len=len(str(abs(number+.01)))-1, substr=""):str(abs(number)))
	: no_leading_zero(str(abs(number)));
module swatch(text_type, edge_tests)
{            
    //wall thickness around step area 
    stepareadistance=(edge_tests=="enabled"?1.5:1);
    //height of the text field -> needs more space if raised text
    font_h= (text_type=="raised"?textsize_lower*.2 : 1)+textsize_upper + linesep*textsize_lower;
    //step area height
    steparea_h=h-(stepareadistance+1)*wall-font_h-wall;
    //if raised text, what is the area to recess so the raised text goes on top
    fontarea_h=font_h+wall;
        
    difference()
    {
        if(edge_tests=="enabled")
            rounded_square_test_pattern(w,h,th,round);
        else
            rounded_square(w,h,th,round);

        write_text_on_top(w,h,th,(edge_tests=="enabled"?wall:round));
        
        //hole to hang
        translate([wall+r_hole,h-wall-r_hole,th/2])
            cylinder(r=r_hole, h=th*2, center=true);
                            
        for (i = [0:len(steps_thickness)-1])
        {
            steparea_w=(w-(2*stepareadistance)*wall)/len(steps_thickness)*(i+1);
            
            translate([ wall*stepareadistance,wall*stepareadistance,(steps_thickness[i]<0?-.1:steps_thickness[i]+step_thickness_correction) ])
            {
                rounded_square(steparea_w,steparea_h,th*2,round-wall);
            }
        }
        
        //handles
        handle_groove_out=r_indent/2;
        translate([-handle_groove_out,h-wall-r_indent,th/2])
            cylinder(r=r_indent, h=th*2, center=true);
        translate([w+handle_groove_out,h-wall-r_indent,th/2])
            cylinder(r=r_indent, h=th*2, center=true);
        
        if (text_type=="embossed")
        {
            //text
            textlines(th-font_recessed);
        }
        else
        {//xxx     if(text_type!="embossed")
            translate([ wall/2,h-wall/2-fontarea_h,th-font_recessed ])
                rounded_square(w-wall,fontarea_h,th,round-wall/2);
        }
    }

    //thickness numbers & bridges
    textheight=steps_textheight;//th-steps_thickness[len(steps_thickness)-1];
    textheight_bridge=steps_textheight;
    
    one_steparea_w=(w-2*stepareadistance*wall)/len(steps_thickness);
    for (i = [0:len(steps_thickness)-1])
    {
        steparea_w=one_steparea_w*(i+1);
        translate([ wall*stepareadistance+ steparea_w,0,0 ])
        {    
            if (steps_text=="enabled")
            {
                rotate([0,0,(steps_text_rotate=="yes"?90:0)])
                translate([ (steps_text_rotate=="yes"?one_steparea_w/3:-one_steparea_w/10)
                            ,(steps_text_rotate=="yes"?wall*.5:wall*2)
                            ,(steps_thickness[i]<0?th-textheight_bridge:steps_thickness[i]+step_thickness_correction)])
                    linear_extrude(height=(steps_thickness[i]<0?textheight_bridge+step_thickness_correction:textheight),convexity = 10)
                            text(str_configurable_zero(steps_thickness[i]),size=steps_textsize,font=fontname,
                                halign=(steps_text_rotate=="yes"?"left":"right"),valign="baseline");
            }
            
            if (steps_thickness[i]<0) // bridge
            {
                gap=round/3;
                translate([ -one_steparea_w+gap,wall*stepareadistance,th-(-steps_thickness[i])-textheight_bridge ])
                    cube([one_steparea_w-gap, steparea_h, -steps_thickness[i]+step_thickness_correction]);
                    //rounded_biteoff_square(one_steparea_w-gap, steparea_h, -steps_thickness[i],round-wall);
            }
        }  
    }
    
    if(text_type!="embossed")
    {    
        textlines(0);
    }

    if(edge_tests=="enabled")
    {    
        rounded_square_test_pattern_raised(w,h,th,round,text_type, edge_tests);
    }

}
 

Debug="false";
if (Debug!="true")
{
    swatch(text_type, edge_tests);
}
else
{
    swatch("raised", "disabled");
    translate([w+3,0,0]) swatch("raised", "enabled");
    translate([0,h+3,0]) swatch("embossed", "disabled");
    translate([w+3,h+3,0]) swatch("embossed", "enabled");
}
