|
Mach Modules Documentation
Lua Module API Documentation
|
Go to the source code of this file.
Functions | |
| DrawingModule Shape | New () |
| Create a new Shape instance as the base object for all shape subclasses. | |
| DrawingModule Shape | GetPoint () |
| Return the point at the specified index from this shape's points array. | |
| DrawingModule Shape | AddToList () |
| Add a shape object to the global shape list. | |
| DrawingModule Shape | SetOutlineTool () |
| Set the pen used to draw the outline of this shape. | |
| DrawingModule Shape | SetFillTool () |
| Set the brush used to fill this shape. | |
| DrawingModule Shape | GetOutlineTool () |
| Return the outline pen tool assigned to this shape. | |
| DrawingModule Shape | GetFillTool () |
| Return the fill brush tool assigned to this shape. | |
| DrawingModule Circle | New (r, outline, fill) |
| Create a new Circle instance from a center point and radius. | |
| DrawingModule Circle | GetRadius () |
| Return the radius of this circle. | |
| DrawingModule Polygon | New (p2, p3, p4, p5,...) |
| Create a new Polygon instance from five or more vertices. | |
| DrawingModule Rectangle | New (p2, p3, p4, outline, fill) |
| Create a new Rectangle instance from four corner points. | |
| DrawingModule Triangle | New (p2, p3, outline, fill) |
| Create a new Triangle instance from three vertices. | |
| DrawingModule Cut | New (p2, outline) |
| Create a new Cut instance representing an open two-point line segment. | |
| DrawingModule Dimension_Line | New (p2, ori, offset, outline, text_color) |
| Create a new Dimension_Line instance measuring the distance between two points. | |
| DrawingModule Dimension_Line | GetDistance (p2) |
| Calculate the absolute distance between two points along a single axis. | |
| DrawingModule Dimension_Line | ApplyOffset () |
| Shift the dimension line endpoints in the configured orientation direction. | |
| DrawingModule Dimension_Line | ApplyTextOffset (off) |
| Apply an additional offset to the dimension line length label position. | |
| DrawingModule Dimension_Line | SetTextColor () |
| Set the color used to render the dimension line length label text. | |
| DrawingModule Dimension_Line | GetTextColor () |
| Return the text color used for the dimension line length label. | |
| DrawingModule Point | GetX () |
| Return the X coordinate of this point. | |
| DrawingModule Point | GetY () |
| Return the Y coordinate of this point. | |
| DrawingModule | CreateCircle (r, outline, fill) |
| Create a new Circle shape and add it to the shape list. | |
| DrawingModule | CreatePolygon (p2, p3, p4, p5,...) |
| Create a new Polygon shape and add it to the shape list. | |
| DrawingModule | CreateRectangle (p2, p3, p4, outline, fill) |
| Create a new Rectangle shape and add it to the shape list. | |
| DrawingModule | CreateTriangle (p2, p3, outline, fill) |
| Create a new Triangle shape and add it to the shape list. | |
| DrawingModule | CreateCut (p2, outline) |
| Create a new Cut shape and add it to the shape list. | |
| DrawingModule | CreateDimensionLine (p2, ori, offset, outline, text_color) |
| Create a new Dimension_Line shape and add it to the shape list. | |
| DrawingModule | GetAllShapes () |
| Return the list of all currently created shapes. | |
| DrawingModule | ClearShapes () |
| Remove all shapes from the shape list. | |
| DrawingModule | SetXScalingFunction () |
| Register an X-axis coordinate scaling function for canvas rendering. | |
| DrawingModule | SetYScalingFunction () |
| Register a Y-axis coordinate scaling function for canvas rendering. | |
| DrawingModule | SetGenericScalingFunction () |
| Register a generic scaling function for non-axis-specific coordinate scaling. | |
| DrawingModule | DrawShapes () |
| Draw all created shapes onto the given canvas. | |
| DrawingModule Shape AddToList | ( | ) |
Add a shape object to the global shape list.
Inserts the provided object into DrawingModule.shape_list using table.insert. This method is called automatically at the end of each shape subclass constructor (Circle, Rectangle, Triangle, Polygon, Cut, Dimension_Line) so that all created shapes are tracked for rendering by DrawShapes.
| obj | (table) The shape object to append to DrawingModule.shape_list |
| DrawingModule Dimension_Line ApplyOffset | ( | ) |
Shift the dimension line endpoints in the configured orientation direction.
Modifies the x_cord or y_cord of start_point and end_point by the stored offset value. The direction of the shift is determined by self.ori: LEFT shifts X negatively, RIGHT shifts X positively, UP shifts Y positively, and DOWN shifts Y negatively. This is called automatically during Dimension_Line:New() to position the line away from the measured geometry.
| DrawingModule Dimension_Line ApplyTextOffset | ( | off | ) |
Apply an additional offset to the dimension line length label position.
Adjusts the internal text_x_offset or text_y_offset accumulators based on the specified orientation direction. LEFT subtracts from text_x_offset, RIGHT adds to text_x_offset, UP adds to text_y_offset, and DOWN subtracts from text_y_offset. Offsets are cumulative, so multiple calls will continue to shift the text position.
| ori | (number) Direction constant: DrawingModule.LEFT, UP, RIGHT, or DOWN |
| off | (number|nil) The offset magnitude to apply in logical units. Defaults to 0 if nil |
| DrawingModule ClearShapes | ( | ) |
Remove all shapes from the shape list.
Resets DrawingModule.shape_list to an empty table, discarding all previously created shapes. This should be called at the beginning of each drawing loop iteration before creating new shapes, to prevent accumulation of stale shapes across redraws.
| DrawingModule CreateCircle | ( | r | , |
| outline | , | ||
| fill | ) |
Create a new Circle shape and add it to the shape list.
Shortcut constructor that delegates to DrawingModule.Circle:New(). The circle is defined by a center point and radius, with configurable outline and fill tools.
| p | (table) Center coordinate array {x, y} |
| r | (number) Radius of the circle in logical units |
| outline | (userdata|nil) wxPen for the outline. Defaults to wx.wxBLACK_PEN if nil |
| fill | (userdata|nil) wxBrush for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil |
| DrawingModule CreateCut | ( | p2 | , |
| outline | ) |
Create a new Cut shape and add it to the shape list.
Shortcut constructor that delegates to DrawingModule.Cut:New(). A Cut represents a two-point open line segment (not closed) used to depict material cuts or slots.
| p1 | (table) Start coordinate array {x, y} |
| p2 | (table) End coordinate array {x, y} |
| outline | (userdata|nil) wxPen for the line color. Defaults to wx.wxBLACK_PEN if nil |
| DrawingModule CreateDimensionLine | ( | p2 | , |
| ori | , | ||
| offset | , | ||
| outline | , | ||
| text_color | ) |
Create a new Dimension_Line shape and add it to the shape list.
Shortcut constructor that delegates to DrawingModule.Dimension_Line:New(). The dimension line measures the distance between two points and renders the measurement with bracket end-caps and a formatted length label. Orientation determines which direction the line is offset from the measured points.
| p1 | (table) Start coordinate array {x, y} |
| p2 | (table) End coordinate array {x, y} |
| ori | (number|nil) Orientation constant: DrawingModule.LEFT, UP, RIGHT, or DOWN. Defaults to LEFT if nil |
| offset | (number|nil) Distance to offset the dimension line from the measured points. Defaults to 0.8 if nil |
| outline | (userdata|nil) wxPen for the line color. Defaults to wx.wxBLACK_PEN if nil |
| text_color | (userdata|nil) wxColour for the length label. Defaults to wx.wxBLACK if nil |
| DrawingModule CreatePolygon | ( | p2 | , |
| p3 | , | ||
| p4 | , | ||
| p5 | , | ||
| ... ) |
Create a new Polygon shape and add it to the shape list.
Shortcut constructor that delegates to DrawingModule.Polygon:New(). A Polygon requires at least five points and may accept additional points via varargs. The shape is closed automatically during rendering by returning to the first point.
| p1 | (table) First vertex coordinate array {x, y} |
| p2 | (table) Second vertex coordinate array {x, y} |
| p3 | (table) Third vertex coordinate array {x, y} |
| p4 | (table) Fourth vertex coordinate array {x, y} |
| p5 | (table) Fifth vertex coordinate array {x, y} |
| ... | (table) Additional vertex coordinate arrays {x, y} for polygons with more than five sides |
| DrawingModule CreateRectangle | ( | p2 | , |
| p3 | , | ||
| p4 | , | ||
| outline | , | ||
| fill | ) |
Create a new Rectangle shape and add it to the shape list.
Shortcut constructor that delegates to DrawingModule.Rectangle:New(). A Rectangle is a closed four-point shape with configurable outline and fill.
| p1 | (table) First corner coordinate array {x, y} |
| p2 | (table) Second corner coordinate array {x, y} |
| p3 | (table) Third corner coordinate array {x, y} |
| p4 | (table) Fourth corner coordinate array {x, y} |
| outline | (userdata|nil) wxPen for the outline. Defaults to wx.wxBLACK_PEN if nil |
| fill | (userdata|nil) wxBrush for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil |
| DrawingModule CreateTriangle | ( | p2 | , |
| p3 | , | ||
| outline | , | ||
| fill | ) |
Create a new Triangle shape and add it to the shape list.
Shortcut constructor that delegates to DrawingModule.Triangle:New(). A Triangle is a closed three-point shape with configurable outline and fill.
| p1 | (table) First vertex coordinate array {x, y} |
| p2 | (table) Second vertex coordinate array {x, y} |
| p3 | (table) Third vertex coordinate array {x, y} |
| outline | (userdata|nil) wxPen for the outline. Defaults to wx.wxBLACK_PEN if nil |
| fill | (userdata|nil) wxBrush for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil |
| DrawingModule DrawShapes | ( | ) |
Draw all created shapes onto the given canvas.
Iterates over all shapes in the shape list and renders them to the provided canvas. Shape rendering is dispatched by shape ID: polygons and rectangles are drawn as connected paths, circles are drawn using AddCircle, and dimension lines are drawn with brackets and length text. Dimension line bracket orientation and text placement depend on the orientation (LEFT/RIGHT vs UP/DOWN). This function wraps the internal _DrawShapes method in a protected call via w.pcall() to catch and report any rendering errors without crashing the UI.
| canvas | (userdata) The wxGraphicsContext-compatible canvas object to draw shapes onto |
| DrawingModule GetAllShapes | ( | ) |
Return the list of all currently created shapes.
| DrawingModule Dimension_Line GetDistance | ( | p2 | ) |
Calculate the absolute distance between two points along a single axis.
Computes the distance between p1 and p2 by comparing coordinates. If the X coordinates are equal, the distance is the absolute difference in Y. If the Y coordinates are equal, the distance is the absolute difference in X. Non-axis-aligned segments (diagonal lines) are not supported and will return 0.
| p1 | (table) A Point object with GetX() and GetY() methods |
| p2 | (table) A Point object with GetX() and GetY() methods |
| DrawingModule Shape GetFillTool | ( | ) |
Return the fill brush tool assigned to this shape.
| DrawingModule Shape GetOutlineTool | ( | ) |
Return the outline pen tool assigned to this shape.
| DrawingModule Shape GetPoint | ( | ) |
Return the point at the specified index from this shape's points array.
| idx | (number) The one-based index into self.points |
| DrawingModule Circle GetRadius | ( | ) |
Return the radius of this circle.
| DrawingModule Dimension_Line GetTextColor | ( | ) |
Return the text color used for the dimension line length label.
| DrawingModule Point GetX | ( | ) |
Return the X coordinate of this point.
| DrawingModule Point GetY | ( | ) |
Return the Y coordinate of this point.
| DrawingModule Shape New | ( | ) |
Create a new Shape instance as the base object for all shape subclasses.
Create a new Point instance from a coordinate array.
Constructs a bare shape table and sets its metatable to the calling class using Lua's prototype-based inheritance pattern. This method serves as the base constructor inherited by Circle, Rectangle, Triangle, Polygon, Cut, and Dimension_Line. Subclasses call this method to obtain a properly chained metatable before populating shape-specific fields.
Constructs a Point object by extracting the first and second elements of the provided coordinate array as x_cord and y_cord respectively. Points are used by all shape classes to store vertex and center positions.
| coord | (table) A two-element array where coord[1] is the X coordinate and coord[2] is the Y coordinate |
| DrawingModule Dimension_Line New | ( | p2 | , |
| ori | , | ||
| offset | , | ||
| outline | , | ||
| text_color | ) |
Create a new Dimension_Line instance measuring the distance between two points.
Constructs a Dimension_Line object that records the start and end points, applies an orientation-based offset to position the line away from the measured geometry, computes the axis-aligned distance between the two points, initializes text offset accumulators to zero, and registers the object in DrawingModule.shape_list. If offset is nil, a default of 0.8 is used; otherwise 0.3 is added to the provided value. If ori is nil, DrawingModule.LEFT is used.
| p1 | (table) Start coordinate array {x, y} |
| p2 | (table) End coordinate array {x, y} |
| ori | (number|nil) Orientation constant: DrawingModule.LEFT, UP, RIGHT, or DOWN. Defaults to DrawingModule.LEFT if nil |
| offset | (number|nil) Distance to offset the dimension line from the measured points. Defaults to 0.8 if nil |
| outline | (userdata|nil) wxPen for the line color. Defaults to wx.wxBLACK_PEN if nil |
| text_color | (userdata|nil) wxColour for the length label. Defaults to wx.wxBLACK if nil |
| DrawingModule Cut New | ( | p2 | , |
| outline | ) |
Create a new Cut instance representing an open two-point line segment.
Constructs a Cut object with two endpoints and an outline pen. Unlike closed shapes, a Cut is not closed back to the first point during rendering, making it suitable for depicting material cuts, slots, or open line segments. The object is automatically added to DrawingModule.shape_list upon creation.
| p1 | (table) Start coordinate array {x, y} |
| p2 | (table) End coordinate array {x, y} |
| outline | (userdata|nil) wxPen for the line color. Defaults to wx.wxBLACK_PEN if nil |
| DrawingModule Triangle New | ( | p2 | , |
| p3 | , | ||
| outline | , | ||
| fill | ) |
Create a new Triangle instance from three vertices.
Constructs a Triangle object with three Point objects built from the provided coordinate arrays. Sets the outline and fill drawing tools and automatically adds the object to DrawingModule.shape_list. During rendering the shape is closed by returning to the first point.
| p1 | (table) First vertex coordinate array {x, y} |
| p2 | (table) Second vertex coordinate array {x, y} |
| p3 | (table) Third vertex coordinate array {x, y} |
| outline | (userdata|nil) wxPen for the outline. Defaults to wx.wxBLACK_PEN if nil |
| fill | (userdata|nil) wxBrush for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil |
| DrawingModule Rectangle New | ( | p2 | , |
| p3 | , | ||
| p4 | , | ||
| outline | , | ||
| fill | ) |
Create a new Rectangle instance from four corner points.
Constructs a Rectangle object with four Point objects built from the provided coordinate arrays. Sets the outline and fill drawing tools and automatically adds the object to DrawingModule.shape_list. During rendering the shape is closed by returning to the first point.
| p1 | (table) First corner coordinate array {x, y} |
| p2 | (table) Second corner coordinate array {x, y} |
| p3 | (table) Third corner coordinate array {x, y} |
| p4 | (table) Fourth corner coordinate array {x, y} |
| outline | (userdata|nil) wxPen for the outline. Defaults to wx.wxBLACK_PEN if nil |
| fill | (userdata|nil) wxBrush for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil |
| DrawingModule Polygon New | ( | p2 | , |
| p3 | , | ||
| p4 | , | ||
| p5 | , | ||
| ... ) |
Create a new Polygon instance from five or more vertices.
Constructs a Polygon object with at least five Point objects built from the required coordinate parameters, plus any additional points supplied via varargs. All points are stored in the polygon.points array in the order they are provided. The object is automatically added to DrawingModule.shape_list. During rendering the shape is closed by returning to the first point.
| p1 | (table) First vertex coordinate array {x, y} |
| p2 | (table) Second vertex coordinate array {x, y} |
| p3 | (table) Third vertex coordinate array {x, y} |
| p4 | (table) Fourth vertex coordinate array {x, y} |
| p5 | (table) Fifth vertex coordinate array {x, y} |
| ... | (table) Additional vertex coordinate arrays {x, y} for polygons with more than five sides |
| DrawingModule Circle New | ( | r | , |
| outline | , | ||
| fill | ) |
Create a new Circle instance from a center point and radius.
Constructs a Circle object with a single center Point built from the provided coordinate array and a numeric radius. Sets the outline and fill drawing tools and automatically adds the object to DrawingModule.shape_list. During rendering the circle is drawn using the canvas AddCircle method with the stored radius passed through the Scale function.
| p | (table) Center coordinate array {x, y} |
| r | (number) Radius of the circle in logical units |
| outline | (userdata|nil) wxPen for the outline. Defaults to wx.wxBLACK_PEN if nil |
| fill | (userdata|nil) wxBrush for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil |
| DrawingModule Shape SetFillTool | ( | ) |
Set the brush used to fill this shape.
| fill | (userdata|nil) A wxBrush object for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil |
| DrawingModule SetGenericScalingFunction | ( | ) |
Register a generic scaling function for non-axis-specific coordinate scaling.
Assigns a scaling function to DrawingModule.Scale, which is used in _DrawShapes to scale values such as circle radii that are not strictly X or Y coordinates. This function must be set before calling DrawShapes if any circles are present in the shape list.
| func | (function) A function that accepts a numeric value and returns a scaled numeric value |
| DrawingModule Shape SetOutlineTool | ( | ) |
Set the pen used to draw the outline of this shape.
| outline | (userdata|nil) A wxPen object for the outline. Defaults to wx.wxBLACK_PEN if nil |
| DrawingModule Dimension_Line SetTextColor | ( | ) |
Set the color used to render the dimension line length label text.
| text_color | (userdata|nil) A wxColour object for the label color. Defaults to wx.wxBLACK if nil |
| DrawingModule SetXScalingFunction | ( | ) |
Register an X-axis coordinate scaling function for canvas rendering.
Assigns a scaling function to DrawingModule.X, which is used in _DrawShapes to convert logical X coordinates to canvas pixel coordinates. This function must be set before calling DrawShapes to ensure correct horizontal positioning of all shapes.
| func | (function) A function that accepts a numeric X coordinate and returns a scaled canvas X coordinate |
| DrawingModule SetYScalingFunction | ( | ) |
Register a Y-axis coordinate scaling function for canvas rendering.
Assigns a scaling function to DrawingModule.Y, which is used in _DrawShapes to convert logical Y coordinates to canvas pixel coordinates. This function must be set before calling DrawShapes to ensure correct vertical positioning of all shapes.
| func | (function) A function that accepts a numeric Y coordinate and returns a scaled canvas Y coordinate |