Add initialization process when adding model
This function and the API used in this function have been released in advance. We do not guarantee the quality at this time, so if you use it, please use it at your own risk. Also, please note that these specifications are subject to change without notice.
Overview
You can add your own initialization process when adding a model. In addition to setting values for fields of primitive and enum types, it is also possible to model the owning child elements.
The following implementation is required to incorporate initialization processing.
- Implementation of interface for initialization process
- Implementation of registration process of initialization process
Implementation of interface for initialization process
Implement the following interfaces.
interfaces | methods |
---|---|
IModelInitializationProvider | InitializeProvider method< br/>InitializeFields method |
Please refer to the API specification for details.
- It is possible to implement multiple interfaces for initialization processing for the same model.
- All initialization processes for the same model are applied in the order in which they were registered.
- If an implementation of an initialization process returns null, the following initialization process is applied. If there is no next initialization processing, Next Design standard behavior is applied.
Implementation of registration process of initialization process
Implement the registration process for the initialization process in the Activate
method, which is a public method of the main class that implements IExtention.
There is no need to implement the deregistration process in Deactviate
.
-
API used for registration process
Target Callback function registration API Initialization process IEditingCapabilityProviderRegistry.Register method
Sample: Automatic addition of child models
As a sample of initialization processing when adding a model, we will explain how to automatically add a child model when adding a model. Below, I will explain from creating a new Visual Studio project to incorporating the initialization process that actually automatically adds a child model.
Overall flow
- Create a new Visual Studio project
- Implementation of interface for initialization process
- Implementation of registration process of initialization process
Public Sample
-
A set of sample source code created by the following procedure is available on GitHub.
External link: ModelInitializationSample
Goal Image
- Open the [Advanced driving system software development] project from the Next Design sample project.
- When you open a use case diagram and add a use case, the following models are also added automatically.
- Scenario (Name: Base Scenario)
Create a new Visual Studio project
Create a new Visual Studio project by referring to the following page.
In addition, when adding the initialization process when adding a model, the following definitions are not required in the manifest.
- UI extension point definitions (ribbon tabs, groups, buttons)
- command extension point definition
Implementation example
manifest.json
{
"name": "DensoCreate.NextDesign.Extensions.ModelInitializationSample",
"version": "1.0.0",
"publisher": "DENSO CREATE Inc.",
"license": "According to the Next Design License Agreement. Copyright (C) 2021 DENSO CREATE INC. All rights reserved.",
"main": "ModelInitializationSample.dll", //Specify the build result DLL file name as the entry point.
"lifecycle": "project", //Specify the project lifecycle as the lifecycle.
"baseprofile": "In-vehicle system software development" //Specify the profile name as a condition for the target project.
}
Implementation of interface for initialization process
Add a class that implements the initialization process and implement the following interface.
Interfaces to implement | Methods that must be implemented |
---|---|
IModelInitializationProvider | InitializeProvider method< br/>InitializeFields method |
Implementation example
Implement IModelInitializationProvider to auto-add child models on initialization.
ModelInitializationProvider.cs
using System;
using System.Collections.Generic;
using System.Text;
using NextDesign.Core;
using NextDesign.Core.EditingCapabilities;
using NextDesign.Desktop;
namespace ModelInitializationSample
{
class ModelInitializationProvider : IModelInitializationProvider
{
///<summary>
///Sets the metamodel to be initialized
///</summary>
///<param name="context"></param>
public void InitializeProvider(IModelInitializationProviderInitializationContext context)
{
//Register "UseCase" as a target for initialization processing
IClass usecaseClass = context.Project.Profile.Metamodels.FindClassesByName("UseCase").GetItem(0);
if (usecaseClass != null)
{
context.RegisterClass(usecaseClass);
}
}
///<summary>
///Perform initialization when generating the specified metamodel
///</summary>
///<param name="initializeParams"></param>
public void InitializeFields(ModelInitializationParams initializeParams)
{
//do nothing if the model is cloned
if (initializeParams.IsCloned)
{
return;
}
//A child model is automatically generated for the design rule that always defines the "basic scenario" for the use case
var model = initializeParams.Model;
var scenario = model.AddNewModel("Scenarios", "Scenario");
scenario.SetField("Name", "Base Scenario");
}
}
}
Implementation of registration process of initialization process
Implement the initialization process registration process in the Activate
method, which is a public method of the main class that implements IExtention. No unregistration is required in the public method Deactviate
of the main class.
Implementation example
Register for automatic addition of child models.
ModelInitializationEntryPoint.cs
//Declaration of namespace of API to be referenced in extension development
using NextDesign.Extension;
using NextDesign.Core;
using NextDesign.Desktop;
namespace ModelInitializationSample
{
///<summary>
///Extension entry point for initialization when adding a model.
///</summary>
public class ModelInitializationEntryPoint : IExtension
{
///<summary>
///Activate the extension.
///</summary>
///<param name="context">execution context</param>
public void Activate(IContext context)
{
//Register the initialization process.
var registry = context.App.Workspace.CurrentProject.EditingCapabilityProviderRegistry;
registry.Register(new ModelInitializationProvider());
}
///<summary>
///Deactivate the extension.
///</summary>
///<param name="context">execution context</param>
public void Deactivate(IContext context)
{
//No need to unlock.
}
}
}