Namespace OpenCAD2D.Plugins
Classes
- CadCommandAttribute
Marks a method of a plugin as a command, as AutoCAD's
[CommandMethod]does:[CadCommand("NUMCIRCLES", Alias = "NC")]onpublic IEnumerable<CadPrompt> NumberCircles(CadCommandContext c). The method is an iterator, as the presenter's own commands are: it yields each prompt and reads the answer from Input when it is resumed, so that it runs inside the command line with no thread of its own. It may be static, or an instance method of a public class with a public constructor that takes nothing, of which the plugin makes one when it is loaded.
- CadCustomSnap
An object snap a plugin adds, as AutoCAD's
CustomObjectSnapMode: a name, a keyword typed as an override, a glyph, the entity types it applies to and the points the plugin works out for an entity under the cursor. Beyond AutoCAD, the window lists it in the Object Snap tab of Drafting Settings, the OSNAP status menu and the Shift+right-click menu, and turns it on and off as it does the built-in snaps, keeping the choice in the settings by keyword.
- CadDrawingsRequest
What a DRAWINGS menu provider is given when the right-click menu of a row opens.
- CadLoadedPlugin
A plugin CadPluginManager knows in this session: where it was loaded from, whether it is loaded now, whether it lies in the plugin folder or is on the startup list, and the plugin itself while it is loaded.
- CadPlugin
A command plugin made from its assemblies: the methods marked CadCommandAttribute as commands, the properties marked CadSettingAttribute as settings, found by reflection, and added to the command lines of the open drawings with AddTo(CadCommandRegistry).
- CadPluginApiAttribute
Says which version of the plugin API an assembly needs at least, as
[assembly: CadPluginApi("1.0")]. The presenter refuses to load it, saying why, when its own ApiVersion is older. An assembly without one is taken as needing 1.0.
- CadPluginBuild
What compiling a plugin given as a folder with a .csproj gave (Compile(string, string)): the assembly and its PDB, or the errors that kept it from being built. A plugin folder Stairs that compiles gives
Stairs.dllandStairs.pdbin the cache; one with an unknown name on line 12 of Stairs.cs gives one error,Stairs.cs(12,9): error CS0103: The name 'x' does not exist in the current context; one whose Stairs.csproj holds a condition, which is not evaluated, gives the build and the warningStairs.csproj: <PropertyGroup Condition="'$(Configuration)' == 'Debug'"> was not read (conditions are not evaluated).
- CadPluginButton
A button a plugin puts in the header of the DRAWINGS list, left of the presenter's Refresh and Open: an icon with a tooltip that runs a callback.
- CadPluginCommand
One command of a plugin: its name, alias and description as its attribute gives them, and the command the registry runs.
- CadPluginCommandEntry
One command a
plugin.jsondeclares, written as a name ("RING") or as an object that says more:{ "name": "RING", "alias": "RG", "description": "Draws a ring", "usesSelection": true }. A Python tool declares its commands here so that the app shows them, and starts the tool's process only when one is used.
- CadPluginContext
What a callback of a plugin is given when the window runs it: a ribbon button's, a DRAWINGS button's, a menu item's, a button's
CanRunor a contextual tab'sShowWhen. A callback edits the drawing through ApplyEdit(string, IReadOnlyList<CadEditRecord>, Action<CadEditScope>) (one undo step each), or the editors commands use, as a command does.
- CadPluginException
A plugin refused, or one of its commands failed: the message names the plugin, and the exception it threw is the inner one.
- CadPluginHost
What a plugin adds to the window in Initialize(CadPluginHost): ribbon tabs and panels, Properties rows, DRAWINGS buttons and menu items, canvas menu items and object snaps. It is a registrar and not a window: it keeps the descriptions, and the window reads them from Host when a plugin is loaded or unloaded and draws them, so a test reads the same lists headless. The
Addmethods take additions only whileInitializeruns.
- CadPluginIcon
The picture of a ribbon button or a DRAWINGS button, described without WPF: path data, or the bytes of an image. The bytes are copied in when the icon is made, so that it keeps no stream, no file lock and no reference to the plugin's assembly, which unloading the plugin needs. The window draws it fitted into 32 pixels on a large button and 16 on a standard one; a raster icon of 16 by 16 is drawn as it is on a standard button.
- CadPluginLoader
Loads the assemblies of a plugin for CadPluginManager, and unloads them, as the runtime allows: on .NET 8 each plugin into a collectible load context of its own, which unloading frees; on .NET Framework into the one AppDomain, from which nothing is ever unloaded. The presenter's controls give the loader of the runtime they run on (
OpenCAD2D.Wpf.Plugins.CadPluginAssemblyLoader); this library, built for netstandard2.0, has no load contexts to give one of its own.
- CadPluginLogEntry
One line of the load log the Plugin manager shows: when, which plugin, what, from where, whether trusted, and what came of it.
- CadPluginManager
The command plugins of the presenter, as AutoCAD's NETLOAD and APPLOAD keep them (A14 of the plan): loaded from a .dll, the folder of one, or the plugin folder, unloaded and loaded again while the presenter runs, their commands added to the command line of every drawing open (Attach(CadCommandRegistry)), every load written in the load log (Log) and logged with its full path.
- CadPluginManifest
What a plugin says of itself in its
plugin.json, read without loading its code (D18 of the plan):{ "id": "number-circles", "name": "Number circles", "version": "1.0.0", "author": "Nguyen Thang", "kind": "command", "minimumApiVersion": "1.0", "commands": [ "NUMCIRCLES" ], "icon": "icon.png" }Only the name is needed; the id is the name where not given, the kind "command", the API version 1.0. A command is a name or an object,
{ "name": "NUMCIRCLES", "alias": "NC", "description": "Numbers the circles", "usesSelection": true }(CommandEntries); a Python tool, whose process the app starts only when a command is used, also declares what it adds to the ribbon:"ribbon": [ { "id": "tools", "title": "Tools", "panels": [ { "title": "Draw", "buttons": [ { "text": "Number", "command": "NUMCIRCLES", "icon": "number.png", "size": "large", "tooltip": "Numbers the circles" } ] } ] } ](Ribbon), the object snaps it adds,"snaps": [ { "keyword": "CTOP", "name": "Circle top", "entityTypes": [ "CIRCLE" ], "glyph": "quadrant", "onByDefault": true } ](Snaps), and the settings the user may change,"settings": [ { "name": "textHeight", "label": "Text height", "kind": "number", "default": 2.5, "minimum": 0.1, "maximum": 1000 } ](Settings).
- CadPluginMenuItem
An item of a menu a plugin adds to, as the presenter's
CadExtensionMenuItemis for an extension: a line that runs a callback, a submenu, or a separator, ticked or not, on or off.
- CadPluginResult
What came of a load, unload or reload: whether it was done, the sentence the command line writes, and what was left out.
- CadPluginRibbonButtonEntry
One button of a panel of the
"ribbon"of aplugin.json:{ "text": "Ring", "command": "RING", "icon": "ring.png", "size": "large", "tooltip": "Draws a ring" }. A button starts a command and does nothing else.
- CadPluginRibbonPanelEntry
One panel of a tab of the
"ribbon"of aplugin.json:{ "title": "Draw", "buttons": [ ... ] }.
- CadPluginRibbonTabEntry
One tab of the
"ribbon"of aplugin.json:{ "id": "tools", "title": "Tools", "panels": [ ... ] }.
- CadPluginSetting
One setting a plugin declares with CadSettingAttribute: its label, kind, default and range, as the presenter draws them, and its value, read from and written to the plugin's property. A text height declared with
Minimum = 0.1and set to 0.05 is refused, and the plugin keeps the height it had.
- CadPluginSettingEntry
One setting a Python tool declares in the
"settings"of itsplugin.json, as a C# plugin declares one with CadSettingAttribute:{ "name": "textHeight", "label": "Text height", "kind": "number", "default": 2.5, "minimum": 0.1, "maximum": 1000, "description": "How high the numbers are written." }. The kinds arenumber,integer,boolean,textandchoice(with"choices": ["Left", "Right"]); the name is an identifier,[A-Za-z_][A-Za-z0-9_]*, once in the file; the label is the name where not given; the default is needed and must be of the kind, in range and, for a choice, one of the choices.
- CadPluginSnapEntry
One object snap a Python tool declares in the
"snaps"of itsplugin.json:{ "keyword": "CTOP", "name": "Circle top", "entityTypes": ["CIRCLE"], "glyph": "quadrant", "onByDefault": true }. The glyph is the name of a built-in marker (one of CadSnapKind, in any case) or strokes in pixels about the point, Y down:[ { "points": [[-4.5, 4.5], [4.5, 4.5], [0, -4.5]], "closed": true, "dotted": false, "filled": false } ]. The tool's code is bound to the keyword when the tool starts; the app lists the snap before that.
- CadPropertyRequest
What a Properties provider is given when the panel is read: the drawing, the objects shown and what the panel shows so far, the presenter's groups and those of the extensions.
- CadRibbonButton
A button that starts a command, as a button of the presenter's own ribbon does, or runs a callback of the plugin at once on the window's thread.
- CadRibbonItem
What a panel holds: a CadRibbonButton or a CadRibbonSplitButton.
- CadRibbonPanel
A panel of a ribbon tab: a titled row of items, as AutoCAD's
RibbonPanel.
- CadRibbonSplitButton
A button with a drop-down of others, as AutoCAD's Circle button is: the part on top runs one button, the arrow lists them all. With RemembersLast the top shows and runs the one used last.
- CadRibbonTab
A tab of the ribbon a plugin adds, as AutoCAD's
RibbonTab: panels of buttons. It comes after the Plugins tab and before Settings, in the order the plugins were loaded; with ShowWhen set it is a contextual tab instead, green and shown only while the answer is true.
- CadSettingAttribute
Marks a public property of a plugin's class as a setting the presenter shows and the user changes, as
[CadSetting("Text height", Minimum = 0.1)] public double TextHeight { get; set; } = 2.5;. The property is read for its default once the plugin is loaded, and its value is set through Value; its type isdouble,int,bool,stringor an enumeration, and the presenter draws a box for it of its own (D17 of the plan), so a plugin never touches the window.
- CadSnapRequest
What a CadSnapFinder is given: the entity under the aperture and where the cursor is.
Interfaces
- ICadPluginApplication
The entry point of a plugin that adds to the window, as AutoCAD's
IExtensionApplicationis: a public class with a public constructor that takes nothing, which the presenter makes once when the plugin is loaded and Initialize(CadPluginHost)s, so that the plugin adds its ribbon tabs and panels, Properties rows, DRAWINGS buttons and menu items, canvas menu items and object snaps to the CadPluginHost. Terminate() runs when the plugin is unloaded or reloaded, or the presenter closes.
Enums
- CadPluginAction
What was done to a plugin, as the load log says it.
- CadRibbonItemSize
How big an item of a panel is drawn.
- CadSettingKind
What kind of value a plugin's setting holds, and so which box the presenter draws for it.
Delegates
- CadCanvasMenuProvider
What a plugin adds to the right-click menu of the canvas, as AutoCAD's object context menu extension does: items after those of the extensions and before the presenter's own, asked with objects selected and no command running; the objects are Selected.
- CadDrawingsMenuProvider
What a plugin adds to the right-click menu of a row of DRAWINGS: items at its end, after a separator, asked each time the menu opens, for the rows that are files and not for folder headers.
- CadPropertyProvider
What a plugin gives the Properties panel, as the extension's
DescribeSelectiondoes: it gets the request and returns what the panel shows, typically the groups it was given and its own besides. Null shows the panel as it was. Providers run after the extensions, in the order the plugins were loaded; one that throws is passed over for that call, with a Warn. A row with a setter is committed by the window as an extension's row is.
- CadSnapFinder
Works out the points of a custom snap for the entity under the cursor, in the world coordinates of the space shown; those farther from the cursor than the aperture are dropped. It is called once per entity per mouse move, so it should be quick; one that throws is switched off for the session, with a Warn and a line on the command line. It is asked also for the model space seen through a viewport (in model coordinates), for the entities inside blocks (a placed copy), and for a point typed after the snap's keyword (the typed point as the cursor, the point nearest it taken however far; a finder that throws there says nothing was found, with a Warn, and is not switched off).