Addition of initialization processing when adding a model
Preview released
This function and the API used in this function have been released in advance. We do not guarantee the quality at this time, so 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 initial processing when adding a model. Not only can you set the values of primitive and enumerated fields, but you can also add models of your own child elements.
The following implementation is required to incorporate the initialization process.
- Implementation of initialization processing interface
- Implementation of registration process for initialization process
Implementation of initialization processing interface
Implement the following interface.
Interface | Method |
---|---|
IModelInitializationProvider | InitializeProvider Method InitializeFields Methods |
Please refer to the API specification for details.
note
- It is possible to implement multiple initialization processing interfaces 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 will be applied. If there is no next initialization process, the Next Design standard behavior will be applied.
Implementation of registration process for initialization process
Implement the registration process of initialization process in the public method Activate
of the main class that implements IExtention.
It is not necessary to implement the deregistration process in Deactviate
.
Activate
method: Registration of initialization process
Implementation example
Here is an example of implementing the IExtension interface in the ModelInitializationEntryPoint class.
Implementation example of IExtension
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 cancellation is required.
}
}
Sample: Automatic addition of child model
As a sample of the initialization process when adding a model, we will explain how to automatically add a child model when adding a model. In the following, we will explain from creating a new Visual Studio project to incorporating the initialization process that actually adds the child model automatically.
Overall flow
- Create a new Visual Studio project
- Implementation of initialization processing interface
- Implementation of initialization process registration 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.
- If you open the use case diagram and add a use case, the following models will be added automatically.
- Scenario (name: basic scenario)
Create a new Visual Studio project
When developing the initialization process when adding a model, select [Class Library] as the project type when creating a new project.
The following settings when creating a new project are the same as Tutorials> Batch Model Verification.
- A copy of the extension development DLL
- Added reference setting for extension development DLL
- Automation of debug execution preparation
Create and define a new manifest. The following is similar to Tutorials> Bulk Model Validation.
- Execution program entry point definition
- Extension life cycle definition
- Specify the target profile of the extension
The following definition is not required in the manifest to realize the initialization process when adding a model.
- UI extension point definition (ribbon tab group button)
- Command extension point definition
Implementation code
manifest.json
{
"name": "DensoCreate.NextDesign.Extensions.ModelInitializationSample",
"version": "1.0.0",
"publisher": "DENSO CREATE Inc.",
"license": "Conforms 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 an entry point.
"lifecycle": "project", //Specify the project lifecycle as the lifecycle.
"baseprofile": "In-vehicle system software development" //Specify the profile name as a condition of the target project.
}
Implementation of initialization processing interface
Add a class that implements the initialization process and implement the following interface.
Interface to implement | Methods that need to be implemented |
---|---|
IModelInitializationProvider | InitializeProvider method InitializeFields method |
Implementation code
Implements IModelInitializationProvider and automatically adds child models at 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>
///Set the metamodel to be the target of initialization processing
///</summary>
///<param name = "context"> </param>
public void InitializeProvider (IModelInitializationProviderInitializationContext context)
{
//Register "Use Case" as the target of initialization processing
IClass usecaseClass = context.Project.Profile.Metamodels.FindClassesByName ("UseCase"). GetItem (0);
if (usecaseClass! = null)
{
context.RegisterClass (usecaseClass);
}
}
///<summary>
///Executes the initialization process when the specified metamodel is generated.
///</summary>
///<param name = "initializeParams"> </param>
public void InitializeFields (ModelInitializationParams initializeParams)
{
//Do nothing for model duplication
if (initializeParams.IsCloned)
{
return;
}
//Automatically generate child models for design rules that always define a "basic scenario" for use cases
var model = initializeParams.Model;
var scenario = model.AddNewModel ("Scenarios", "Scenario");
scenario.SetField ("Name", "basic scenario");
}
}
}
Initialization process Implementation of registration process
Implement the registration process of initialization process in the public method Activate
of the main class that implements IExtention. There is no need to unregister with the main class public method Deactviate
.
Implementation code
Register the automatic addition of child models.
ModelInitializationEntryPoint.cs
//Declare the namespace of the API to be referenced in extension development
using NextDesign.Extension;
using NextDesign.Core;
using NextDesign.Desktop;
namespace ModelInitializationSample
{
///<summary>
///Extension entry point for initialization processing 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)
{
//There is no need to remove the constraint.
}
}
}