SLCadCommand.sleela
lib/autocad/SLCadCommand.sleela · 145 line(s) · sleela
<< lib/autocad/SLCadCommand.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLCadCommand -- one recorded, reversible edit the AutoCAD
Creator(TM) applied to a document. Every creation (line/text/dim/room) and
every alteration (move/reshape/relabel/restyle/delete) is captured as a
command so the Creator can keep an audit trail and offer undo: a command
remembers its verb, the id of the entity it affected, and the "before"
values needed to reverse it (prior endpoints, prior label/layer, prior
alive flag). This keeps editing a first-class, inspectable operation rather
than an opaque mutation -- which is exactly what makes a creator (as opposed
to a one-shot renderer) possible.
Family: autocad. SLeeLa owns the edit history; a command is a plain record,
replayed/reversed against an SLCadDocument. >>
#sleela 2.5
material;
class SLCadCommand {
< ---- 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 = 11036;
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-13";
< 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; }
< Verb ordinals. >
< an entity was created (undo = delete it) >
static final int CREATE = 0;
< translated by (dx,dy) >
static final int MOVE = 1;
< endpoints changed (before stored) >
static final int RESHAPE = 2;
< text value changed (before stored) >
static final int RELABEL = 3;
< layer changed (before stored) >
static final int RESTYLE = 4;
< tombstoned (undo = restore) >
static final int DELETE = 5;
int verb;
int entityId;
< "Before" snapshot for reversal (meaning depends on the verb). >
< MOVE delta >
double dx; double dy;
< RESHAPE prior endpoints >
double px1; double py1; double px2; double py2;
< RELABEL prior text >
String priorValue;
< RESTYLE prior layer >
String priorLayer;
< Audit metadata: when the edit was applied (host-supplied) and its order in >
< the session. seq is 1-based; stampedAt is a Julian date (0 = unstamped) and >
< stampLabel its readable form. Stamped by the Creator via stamp(). >
int seq;
double stampedAt;
String stampLabel;
< Attach the audit stamp (sequence number + host time) to this command. >
void stamp(int sequence, double whenJulian, String whenText) {
seq = sequence; stampedAt = whenJulian; stampLabel = whenText;
}
int getSeq() { return seq; }
double getStampedAt() { return stampedAt; }
String getStampLabel() { return stampLabel; }
void create(int id) { verb = CREATE; entityId = id; }
void move(int id, double ddx, double ddy) { verb = MOVE; entityId = id; dx = ddx; dy = ddy; }
void reshape(int id, double ox1, double oy1, double ox2, double oy2) {
verb = RESHAPE; entityId = id; px1 = ox1; py1 = oy1; px2 = ox2; py2 = oy2;
}
void relabel(int id, String prior) { verb = RELABEL; entityId = id; priorValue = prior; }
void restyle(int id, String prior) { verb = RESTYLE; entityId = id; priorLayer = prior; }
void deleted(int id) { verb = DELETE; entityId = id; }
int getVerb() { return verb; }
int getEntityId() { return entityId; }
< Reverse this command against `doc`. Returns true when something changed. >
boolean undo(SLCadDocument doc) {
< undo create = delete >
if (verb == CREATE) { return doc.remove(entityId); }
< undo delete = restore >
if (verb == DELETE) { return doc.restore(entityId); }
if (verb == MOVE) { return doc.move(entityId, -dx, -dy); }
if (verb == RESHAPE) { return doc.reshape(entityId, px1, py1, px2, py2); }
if (verb == RELABEL) { return doc.relabel(entityId, priorValue); }
if (verb == RESTYLE) { return doc.restyle(entityId, priorLayer); }
return false;
}
< A short, human-readable description for a history/log view. >
String describe() {
if (verb == CREATE) { return "create #" + entityId; }
if (verb == MOVE) { return "move #" + entityId; }
if (verb == RESHAPE) { return "reshape #" + entityId; }
if (verb == RELABEL) { return "relabel #" + entityId; }
if (verb == RESTYLE) { return "restyle #" + entityId; }
if (verb == DELETE) { return "delete #" + entityId; }
return "noop";
}
< The same description prefixed with the audit stamp, for a timeline view: >
< "#3 @ 2026-10-13T18:00Z move #7" >
String describeAt() {
String s = "#" + seq;
if (stampLabel != "") { s = s + " @ " + stampLabel; }
return s + " " + describe();
}
}