sysml

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sysml reads a SysML v2 model the way the SysML v2 API serves it (requirement DS-4): element queries (Query), reads of one element's metamodel properties (Props, cached), facts built on them (names, docs, representations, specializations) and expression evaluation (Evaluate). Nothing exports the whole model. It works on a model the SysML service parsed and holds (github.com/Open-MBEE/OpenSysML's client, dialed to sysml-grpc).

Index

Constants

View Source
const UnnamedName = "Unnamed"

UnnamedName stands in for the name of an element without one, wherever this tool shows its name (requirement PG-5).

Variables

View Source
var ErrNoSuchElement = errors.New("model: no such element")

ErrNoSuchElement matches (errors.Is) the error Props returns for an id the model does not know.

Functions

This section is empty.

Types

type Model

type Model struct {
	// ElementCount is the number of elements in the model.
	ElementCount int
	// Tops are the top-level elements, in file order: the members of each
	// file's root namespace.
	Tops []Ref
	// contains filtered or unexported fields
}

Model reads one parsed model. It is not safe for concurrent use: reads are cached.

func Open

func Open(ctx context.Context, client opensysml.Client, parsed *opensysml.Model) (*Model, error)

Open reads the model parsed by client: it queries every element once, for ElementCount, Tops and the model's own ids. Open takes the client over when it succeeds: Close closes it. On error the client stays the caller's.

func (*Model) Close

func (m *Model) Close() error

Close releases the client. What was read stays cached, but nothing more can be read; the service keeps running.

func (*Model) Contains

func (m *Model) Contains(id string) bool

Contains reports whether id is an element of the model itself, not of the standard library it refers to.

func (*Model) Docs

func (m *Model) Docs(ctx context.Context, id string) ([]string, error)

Docs are the bodies of the element's doc comments, trimmed, in declaration order.

func (*Model) Evaluate

func (m *Model) Evaluate(ctx context.Context, subject, expression string) (opensysml.Value, error)

Evaluate evaluates a SysML expression with the element named subject (by qualified name) as its subject, so a feature reads that element's value: its own, a redefinition's, or one inherited from its types.

func (*Model) Generals

func (m *Model) Generals(ctx context.Context, id string) ([]string, error)

Generals are the ids of the elements the element specializes directly, through any specialization it owns (typing, subclassification, subsetting, redefinition, reference subsetting), in declaration order. A standard-library element's are not read, and are none: reading any library element makes OpenSysML build its library document's element form, seconds per document (AGENTS.md §13), and the library has no pages.

func (*Model) Members

func (m *Model) Members(ctx context.Context, id string) ([]Ref, error)

Members are the element's owned members, in declaration order.

func (*Model) Name

func (m *Model) Name(ctx context.Context, id string) (string, error)

Name is the element's name: its declared name, or the one it gets otherwise (a redefining feature borrows the redefined feature's); "" when it has none. A library element's is the last segment of its qualified name.

func (*Model) Owner

func (m *Model) Owner(ctx context.Context, id string) (Ref, error)

Owner is the element that owns the element; the zero Ref for a root namespace.

func (*Model) Props

func (m *Model) Props(ctx context.Context, id string, names ...string) (*Props, error)

Props reads the named properties of the element id names: an element form id (M__pd), a qualified name (M::pd) or a positional id (M::@2). Values are cached, so asking again costs nothing. A property the element's metaclass does not declare reads as empty. Not safe for concurrent use.

func (*Model) QualifiedName

func (m *Model) QualifiedName(ctx context.Context, id string) (string, error)

QualifiedName is how the element is identified in messages and to the evaluator: its qualified name, or for an element without one its positional name, its owner's name followed by @ and its position among the owner's members (M::@2, counted from 0), as OpenSysML writes it. A root namespace, which is no element of the model's text, has "".

func (*Model) Query

Query selects the model's elements a query matches, in declaration order. A property it selects gives one value per element (see AGENTS.md §13): read multi-valued properties with Props.

func (*Model) Redefined

func (m *Model) Redefined(ctx context.Context, id string) ([]string, error)

Redefined are the ids of the features the feature redefines, in declaration order.

func (*Model) RenderView

func (m *Model) RenderView(ctx context.Context, qualifiedName string, opts ...opensysml.RenderViewOption) (*opensysml.RenderedView, error)

RenderView renders the view with that qualified name as the view's data (nodes, edges, a table's columns and rows), shaped by the options; with opensysml.WithForm it also writes the view in that form — DOT for a diagram, CSV or text for a table (MC-21). Without a form, Columns and Rows say whether the view is tabular.

func (*Model) Representation

func (m *Model) Representation(ctx context.Context, id string) (Representation, error)

Representation reads the textual representation id names.

func (*Model) Representations

func (m *Model) Representations(ctx context.Context, id string) ([]Representation, error)

Representations are the textual representations the element owns, in any language, in declaration order.

func (*Model) ShortName

func (m *Model) ShortName(ctx context.Context, id string) (string, error)

ShortName is the element's short name, "" when it has none.

func (*Model) Specializes

func (m *Model) Specializes(ctx context.Context, specific, general string) (bool, error)

Specializes reports whether element specific is typed by, subclasses or subsets element general, directly or through a chain of such relationships (part spare : Sport with Sport :> Wheel specializes Wheel). No element specializes itself.

func (*Model) Stats

func (m *Model) Stats() Stats

Stats are the reads made so far.

func (*Model) Types

func (m *Model) Types(ctx context.Context, id string) ([]Ref, error)

Types are the element's types, in declaration order, those a usage gets through what it subsets or redefines included; none for an element that is not a feature.

type Props

type Props struct {
	Element Ref
	// contains filtered or unexported fields
}

Props are metamodel properties of one element, as Model.Props read them.

func (*Props) Bool

func (p *Props) Bool(name string) bool

Bool is a boolean property; false when absent.

func (*Props) Ref

func (p *Props) Ref(name string) Ref

Ref is the first element a property refers to, the zero Ref when none.

func (*Props) Refs

func (p *Props) Refs(name string) []Ref

Refs are the elements a property refers to, in order; none when the property is empty, absent, or holds no elements.

func (*Props) Str

func (p *Props) Str(name string) string

Str is the first value of a property as text ("" when it has none): a string as it is, a number or boolean as written.

func (*Props) Strs

func (p *Props) Strs(name string) []string

Strs are the property's non-element values as text, in order.

type Ref

type Ref struct {
	// ID is the element's id in the SysML v2 API element form ("M__pd"),
	// which Props accepts back.
	ID string
	// QualifiedName is "" for an unnamed element; a library element's is its
	// library path (ScalarValues::Real).
	QualifiedName string
	// Metaclass is the element's metaclass: "PartUsage", "Package", ...
	Metaclass string
}

Ref identifies an element: one of the model, or a standard-library element the model refers to.

func (Ref) Name

func (r Ref) Name() string

Name is the last segment of the qualified name, unquoted: Real for ScalarValues::Real, top speed for M::'top speed'; "" for an unnamed element.

type Representation

type Representation struct {
	ID       string
	Owner    string // id of the element that owns it
	Language string // as written
	Body     string // exactly as written, untrimmed
}

Representation is a textual representation, in any language.

type Stats

type Stats struct {
	Queries int // Query calls
	Reads   int // ElementProperties calls: elements, or properties, not cached yet
	Hits    int // Props calls answered from the cache
}

Stats count how the model was read: the cost of reading it through queries and element reads rather than one export (DS-4).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL