Rozdziały kursu
Szkolenia · Ścieżka 9. Podstawy SysML v2 · Rozdział 9.1 z 8
9.1 Definicje i atrybuty 4:33
Zapisywanie typów wartości i komponentów w tekście SysML v2, z wartościami w jednostkach.
Pokazuje Holarch 2.22.
Czego się nauczysz
- Zapisywanie wyliczenia, typu wartości i abstrakcyjnej definicji części w Edytorze
- Specjalizowanie definicji za pomocą `:>` i nadawanie odziedziczonym atrybutom wartości z jednostkami za pomocą `redefines`
- Znajdowanie i poprawianie błędu jednostki podkreślonego przez kontroler
- Pisanie definicji za pomocą Wstaw ▾ i uzupełniania oraz wyszukiwanie typu w Bibliotece standardowej
- Zmienianie nazwy elementu wszędzie klawiszem F2 w jednym kroku cofania
Zapisuj definicje i atrybuty SysML v2 w Edytorze Holarch zgodnie z samouczkiem SysML v2 Definicje i atrybuty na małym projekcie Hybrid Car: wyliczenie, typ wartości specjalizujący ScalarValue, abstrakcyjny komponent i jego specjalizacje z wartościami w jednostkach, błąd jednostki wykryty przez kontroler, uzupełnianie i Biblioteka standardowa, Wstaw oraz zmiana nazwy klawiszem F2. SysML jest zastrzeżonym znakiem towarowym Object Management Group, Inc.
Pliki projektu
- Projekt ukończony (.holarch.json; Zarządzaj projektami → Pliki projektu ▾ → Importuj projekt (.json)…)
Film jest odtwarzany z holarch.app; zobacz Politykę prywatności.
Ćwiczenie
Wykonaj to samodzielnie w Holarch na projekcie demonstracyjnym Hybrid Car (SysML v2).
- Utwórz demo Hybrid Car: Zarządzaj projektami → Pliki projektu ▾ → Nowy projekt demonstracyjny → Hybrid Car (SysML v2). Otwórz Model → Edytor i pakiet
Vehicles. - Pod
enum def FuelKinddodajenum def CoolingMode { enum passive; enum active; }. - Pod
part def Bodywybierz Wstaw ▾ → Definicja części i uzupełnijpart def Radiator :> Componentoattribute redefines mass = 8 [kg];,attribute coolantVolume : VolumeValue;(wpiszVolui zaakceptujVolumeValuez listy uzupełniania klawiszem Enter) orazattribute mode : CoolingMode;. - Zmień masę na
8 [W], wskaż podkreślenie, aby przeczytać komunikat, a następnie zmień ją z powrotem na8 [kg]. - W
part def Powertraindodajpart radiator : Radiator;. Następnie umieść kursor nacoolantVolume, naciśnij F2 i zmień nazwę nacoolantCapacity. - Aby przejść całość ze sprawdzaniem, uruchom samouczek SysML v2 Definicje i atrybuty (Pomoc → Samouczki).
Gotowe, gdy stan pod edytorem nie zgłasza problemów, a Przeglądarka pokazuje Radiator pod Vehicles z coolantCapacity i mode.
Sprawdź się
- Co robią odpowiednio
:>iredefineswpart def Battery :> Component { attribute redefines mass = 45 [kg]; }? - Dlaczego Component jest zadeklarowany jako
abstract part def? - Dlaczego
attribute redefines power = 60 [kg];powoduje błąd? - Czym różni się
doc /* … */od wiersza//?
Pokaż odpowiedzi
Co robią odpowiednio
:>iredefineswpart def Battery :> Component { attribute redefines mass = 45 [kg]; }?:>czyni Battery specjalizacją Component, więc dziedziczy ona mass, partNumber i power.redefineszastępuje odziedziczonemassw Battery własną cechą, tutaj powiązaną z 45 kg.Dlaczego Component jest zadeklarowany jako
abstract part def?Nic nie jest komponentem jako takim, istnieją tylko rodzaje komponentów. Definicja abstrakcyjna zbiera to, co wspólne dla wszystkich komponentów, a rzeczywiste części opisują tylko jej specjalizacje, np. Battery lub Engine.
Dlaczego
attribute redefines power = 60 [kg];powoduje błąd?powerma typPowerValue, a kilogramy są jednostką masy. Kontroler ocenia jednostki, więc podkreśla wartość, dopóki jednostka nie jest jednostką mocy, np.[W].Czym różni się
doc /* … */od wiersza//?Komentarz
docto dokumentacja należąca do elementu i jest częścią modelu. Notatka//pozostaje tylko w tekście i nie jest częścią modelu.
Więcej informacji
- Samouczek: Definicje i atrybuty (Samouczki SysML v2)
- Docs: Notacja tekstowa SysML v2, Typowanie, specjalizacja i redefinicja
- Docs: Notacja tekstowa SysML v2, Wartości i jednostki
- Docs: Edytor tekstu SysML v2, Wstawianie konstrukcji
- Docs: Edytor tekstu SysML v2, Przejście do definicji i zmiana nazwy
- Pomoc: Biblioteka standardowa
Transkrypcja
Pokaż transkrypcję (narracja i to, co widać na ekranie)
Introduction
Welcome to SysML v2 Fundamentals. This track teaches the SysML v2 textual notation and views in Holarch, one task per chapter, on the starter projects of Holarch's SysML v2 tutorials, so you can follow along step by step.
In this chapter you write definitions and attributes: an enumeration, a value type, an abstract component and the components that specialize it, with values in units.
Start the tutorial
In Manage Projects, open Project Files and choose Start a Tutorial. Under the tutorials for SysML v2 projects, click Start on Definitions and Attributes. Holarch creates a small Hybrid Car project and opens the step panel, which checks each step as you go.
On screen: Project Files ▾ → Start a Tutorial… → SysML v2: Definitions and Attributes → Start; the step panel opens.
Enumerations and value types
Open Model, then Editor. The package Vehicles holds one part definition, Car, with two attributes. Every declaration is a keyword and a name, then a body in braces, or a semicolon when there is no body.
On screen: Model → Editor: Vehicles; outline part def Car.
An enumeration is a value type with a fixed set of values. Above the car, write the drive mode: economy, normal or sport.
On screen: Caret after the imports; type enum def DriveMode.
Next, a value type of your own. Tire pressure specializes Scalar Value from the standard library. The short symbol after the name means specializes.
On screen: Below DriveMode; type attribute def TirePressure :> ScalarValue;
Specialization and units
Now an abstract component. There is no component as such, only kinds of components, and every one has a mass, a part number and a power. The doc comment is part of the model. Two slashes start a note that stays in the text only.
On screen: Below TirePressure; type abstract part def Component.
The battery is a component, so it has a mass, a part number and a power of its own. Write it with a mistake on purpose: a power in kilograms.
On screen: Below Component; type part def Battery :> Component with power = 60 [kg].
The checker underlines the value, and the status under the editor counts the error. Point at the underline to read the message.
On screen: Problems count; the information card on 60 [kg].
Change kilograms to watts, and the error clears. Redefines gives each inherited attribute the battery's own value, with its unit in square brackets.
On screen: kg → W; No problems, Applied.
Completion and the Standard Library
Completion knows the model and the library. Inside the battery, type attribute capacity, a colon, and the start of Energy Value. Press Enter to take it from the list, and end the line with a semicolon.
On screen: Inside Battery: attribute capacity : Ener → completion → Enter → ;
Point at Energy Value. The card shows that it comes from the I S Q package of the standard library.
On screen: The information card on EnergyValue.
The Standard Library page lists every package and definition of that library. Open Settings, then Standard Library, and search for Energy Value.
On screen: Settings → Standard Library; Find EnergyValue.
Insert
Back in the Editor, Insert writes a construct for you. Place the cursor below the battery, open Insert, and choose Part Definition. Type Engine, and press Tab to move into its body.
On screen: Model → Editor; caret below Battery; Insert ▾ (open on camera) → Part Definition; Engine; Tab.
The engine is a component too. Give it its mass and a number of cylinders, and make it specialize Component.
On screen: Body: mass 110 kg, cylinders : Integer; then :> Component after the name.
Usages and rename
Now use the definitions. Inside the car, add a drive mode, a battery and an engine. Each usage is typed by a definition after the colon, the drive mode by the enumeration you wrote first.
On screen: In Car after curbMass: attribute mode : DriveMode; part battery : Battery; part engine : Engine;
To rename a name everywhere it is used, place the cursor on cylinders and press F2. Enter cylinder count and confirm. Every reference to it changes, in one undo step.
On screen: Caret in cylinders; F2; New name cylinderCount; OK.
Every step is ticked off. Click Mark as Done to finish the tutorial.
On screen: Step panel → Mark as Done.
Recap
Let's recap. You started a SysML v2 tutorial, wrote an enumeration and a value type, an abstract component with specializations and values in units, let the checker find a wrong unit, and used completion, the Standard Library, Insert and rename.
Next, ports and interfaces connect these components.