SLCadModel.sleela
lib/autocad/SLCadModel.sleela · 133 line(s) · sleela
<< lib/autocad/SLCadModel.sleela
SLeeLa Standard Library Definition.
Definition: Defines the SLeeLa standard-library type SLCadModel used within the autocad library family. >>
#sleela 2.5
material;
import math;
< Unified SLeeLa standard-library front-end object. >
< Family: autocad. The geometry model the AutoCAD renderer builds from a plan. >
< The SLeeLa surface has no array storage, so the model accumulates the DXF >
< entity text directly as geometry is added (walls, dimensions, notes), and >
< tracks the drawing extents in scalar fields. The emitter wraps these entity >
< strings in the DXF sections. SLeeLa owns the geometry. >
< >
< Only existing opcodes are used: arithmetic, the native math `hypot` for the >
< dimension distance, and String concatenation on OP_ADD (buffer sized from >
< SL_MAX_STRTEXT so large drawings are not truncated). No new VM opcode needed. >
class SLCadModel {
< ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
<< Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
or catalog can read and (where appropriate) override this record.
Values are faithful to the subject's real origin where publicly known. >>
String metaVersion = "1.0.0";
int metaId = 10053;
String metaAuthor = "Kiro Agent";
String metaDate = "2026-10-16";
String metaCopyright = "SLeeLa project";
String metaTrademark = "none";
String metaCorporation = "none";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-10-03";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 9;
< metaNationalSchedule: a real, citable instrument or "none" >
String metaNationalSchedule = "none";
String getMetaVersion() { return metaVersion; }
void setMetaVersion(String v) { metaVersion = v; }
int getMetaId() { return metaId; }
void setMetaId(int v) { metaId = v; }
String getAuthor() { return metaAuthor; }
void setAuthor(String v) { metaAuthor = v; }
String getDate() { return metaDate; }
void setDate(String v) { metaDate = v; }
String getCopyright() { return metaCopyright; }
void setCopyright(String v) { metaCopyright = v; }
String getTrademark() { return metaTrademark; }
void setTrademark(String v) { metaTrademark = v; }
String getCorporation() { return metaCorporation; }
void setCorporation(String v) { metaCorporation = v; }
String getOrigin() { return metaOrigin; }
void setOrigin(String v) { metaOrigin = v; }
String getBirthDate() { return metaBirthDate; }
void setBirthDate(String v) { metaBirthDate = v; }
int getScienceRating() { return metaScienceRating; }
void setScienceRating(int v) { metaScienceRating = v; }
String getNationalSchedule() { return metaNationalSchedule; }
void setNationalSchedule(String v) { metaNationalSchedule = v; }
String title; String units;
< insertion point for next room >
double curX; double curY;
< extents >
double minX; double minY; double maxX; double maxY;
< accumulated DXF entity text >
String walls; String dims; String notes;
int noteCount;
void begin(String t, String u) {
title = t; units = u;
curX = 0.0; curY = 0.0;
minX = 0.0; minY = 0.0; maxX = 0.0; maxY = 0.0;
walls = ""; dims = ""; notes = ""; noteCount = 0;
}
void setAt(double x, double y) { curX = x; curY = y; }
void grow(double x, double y) {
if (x < minX) { minX = x; }
if (y < minY) { minY = y; }
if (x > maxX) { maxX = x; }
if (y > maxY) { maxY = y; }
}
String num(double v) { return "" + v; }
String lineEntity(String lyr, double x1, double y1, double x2, double y2) {
String s = "0\nLINE\n8\n" + lyr + "\n";
s = s + "10\n" + num(x1) + "\n20\n" + num(y1) + "\n30\n0.0\n";
s = s + "11\n" + num(x2) + "\n21\n" + num(y2) + "\n31\n0.0\n";
return s;
}
String textEntity(String lyr, double x, double y, double height, String value) {
String s = "0\nTEXT\n8\n" + lyr + "\n";
s = s + "10\n" + num(x) + "\n20\n" + num(y) + "\n30\n0.0\n";
s = s + "40\n" + num(height) + "\n1\n" + value + "\n";
return s;
}
void addWall(double x1, double y1, double x2, double y2) {
walls = walls + lineEntity("walls", x1, y1, x2, y2);
grow(x1, y1); grow(x2, y2);
}
< Expand a room into its four wall segments at the current insertion point. >
void addRoom(double w, double h) {
double ox = curX; double oy = curY;
< south >
addWall(ox, oy, ox + w, oy);
< east >
addWall(ox + w, oy, ox + w, oy + h);
< north >
addWall(ox + w, oy + h, ox, oy + h);
< west >
addWall(ox, oy + h, ox, oy);
}
void addDim(double x1, double y1, double x2, double y2) {
dims = dims + lineEntity("dims", x1, y1, x2, y2);
dims = dims + textEntity("dims", (x1 + x2) / 2.0, (y1 + y2) / 2.0, 120.0, num(distance(x1, y1, x2, y2)));
}
void addNote(double x, double y, String text) {
notes = notes + textEntity("notes", x, y, 150.0, text);
noteCount = noteCount + 1;
}
< Straight-line distance -- used to compute dimension labels. >
double distance(double x1, double y1, double x2, double y2) {
return math.hypot(x2 - x1, y2 - y1);
}
}