Skip to main content

Change conditional formatting in diagram view

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 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 dynamically change the format of shapes, labels, etc. displayed in the diagram view based on conditions such as model field values.

The following implementation is required to achieve conditional formatting changes:

  • Implementation of callback function
  • Implementation of callback function registration process

Implementation of callback function

Implement a conditional formatting callback function. There are the following types of callback functions:

  • shape formatting callback function
  • label/text formatting callback function
  • Compartment item format callback function

The implementation of each callback function is described below.

Shape Formatting Callback Function

The signature of the shape formatting callback function and the styles that can be set in the callback function are as follows:
For details of the callback function, please refer to the argument getter description of IViewDefinitions.RegisterGetStyleCallback method.

Callback function signature

object get_styleFunction(IEditorElement element, IModel model, IStyleProperty target)

Configurable Styles

  • Letter color
  • Background color
  • line color
  • line thickness
  • Line Style (Solid Line | Dot | Dashed Line | Dashed Dot Line | Dashed Double Dot Line | None)
  • Shapes (*node shapes only)
  • Image (*node shape only)
  • Line type (Straight line | Polygonal line | Single Bezier curve | Binary Bezier curve | Tree) (*connector shape only)
  • Start point shape (*connector shape only)
  • End point shape (*connector shape only)

label/text formatting callback function

The signature of the label/text formatting callback function and the styles that can be set in the callback function are as follows:
For details, please refer to the argument getter description of IViewDefinitions.RegisterGetTextStyleCallback method.

Callback function signature

object get_TextStyleFunction(IShape shape, TextTypes type, string textPath, IModel model, IStyleProperty target)

Configurable Styles

  • Letter color
  • Font
  • font size
  • underline
  • Italic
  • bold
  • Strikethrough

Compartment item formatting callback function

The signature of the compartment item formatting callback function and the styles that can be set in the callback function are as follows:
For details, please refer to the argument getter description of IViewDefinitions.RegisterGetCompartmentItemTextStyleCallback method.

Callback function signature

object object get_ItemTextStyleFunction(INode node, int areaIndex, string areaPath, IModel itemModel, IStyleProperty target)

Configurable Styles

  • Letter color
  • Font
  • font size
  • underline
  • Italic
  • bold
  • Strikethrough
  • icon
  • Show icon

Implementation of callback function registration process

Implement the callback function registration process in the Activate method, which is a public method of the main class that implements IExtention.
For details, please refer to each method of IViewDefinitions interface.


Sample: highlighting shapes in diagrams

As a sample of conditional formatting changes in Diagram View, we will show you how to highlight shapes that have a specific keyword in their model name. Below, we'll walk you through creating a new Visual Studio project and actually incorporating conditional formatting.

Overall flow

  • Create a new Visual Studio project
  • Implementing a conditional formatting callback function
  • Implementation of conditional formatting callback function registration process

Public Sample

  • A set of sample source code created by the following procedure is available on GitHub.

    External link: ShapeHighlightingSample

Goal Image

Screen capture or GIF animation

  • Open the [Advanced driving system software development] project from the Next Design sample project.
  • Open [Functional Structure Diagram] from [System Functional Structure] in [System Logical Design].
  • Subsystems with the specific keyword "TBD" in their name are highlighted as follows:
    • Font Color: Red
    • Border color: red
    • bold
    • underline

Create a new Visual Studio project

Create a new Visual Studio project by referring to the following page.

Tutorials > Model Batch Verification

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.ShapeHighlightingSample",
"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": "ShapeHighlightingSample.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.
}

Conditional formatting callback function implementation

Implement a callback function that provides conditional formatting.

  • GetShapeStyle: font color, border color
  • GetTextStyle: bold, underline

Implementation example

Implement a callback function that does the highlighting.

ShapeHighlightingEntryPoint.cs

using System.Linq;
using System.Collections.Generic;
using NextDesign.Core;
using NextDesign.Core.EditingCapabilities;
using NextDesign.Desktop;
using NextDesign.Extension;

namespace ShapeHighlightingSample
{
public class ShapeHighlightingEntryPoint : IExtension
{
//formatting to highlight the text you are working with
private Dictionary<StyleAttributes, object> workingTextAttribute
= new Dictionary<StyleAttributes, object>()
{
{StyleAttributes.IsBold, true},
{StyleAttributes.IsUnderline, true}
};

//formatting to highlight the shape you're working on
private Dictionary<StyleAttributes, object> workingShapeAttribute
= new Dictionary<StyleAttributes, object>()
{
{ StyleAttributes.ForeColor, "Red"},
{StyleAttributes.BorderColor, "Red"}
};

///<summary>
///A callback function to get the style value of the text
///</summary>
private object GetTextStyle(IShape shape, TextTypes textType, string textPath, IModel model, IStyleProperty styleProperty)
{
object outValue;
if (workingTextAttribute.TryGetValue(styleProperty.Attribute, out outValue))
{
//If "TBD" is included in the name, it will be bold and underlined.
if (model.Name.Contains("TBD"))
{
return outValue;
}
}
//Returns styleProperty.CurrentValue, since formatting other than bold and underline does not change.
return styleProperty.CurrentValue;
}

///<summary>
///A callback function to get the shape's style value
///</summary>
private object GetShapeStyle(IEditorElement element, IModel model, IStyleProperty styleProperty)
{
object outValue;
if (workingShapeAttribute.TryGetValue(styleProperty.Attribute, out outValue))
{
//If "TBD" is included in the name, set the font color and border color to red.
if (model.Name.Contains("TBD"))
{
return outValue;
}
}

//Returns styleProperty.CurrentValue, since we are not changing any formatting other than the font color and border color.
return styleProperty.CurrentValue;
}

}
}

Implementation of registration process and unregistration process of conditional formatting callback function

Implement the callback function registration process in the public method Activate of the main class that implements IExtention. And implement the deregistration process of the callback function in the public method Deactviate of the main class.

Implementation example

Following implementation of the conditional formatting callback function, implement the registration process and unregistration process of the conditional formatting callback function.

ShapeHighlightingEntryPoint.cs

using System.Linq;
using System.Collections.Generic;
using NextDesign.Core;
using NextDesign.Core.EditingCapabilities;
using NextDesign.Desktop;
using NextDesign.Extension;

namespace ShapeHighlightingSample
{
public class ShapeHighlightingEntryPoint : IExtension
{

///<summary>
///activate the extension
///</summary>
///<param name="context">execution context</param>
public void Activate(IContext context)
{
//Get the element definition to apply conditional formatting to
//target is
//"Subsystem" in the diagram "Functional Structure Diagram"
IElementDef targetDefinition = GetTargetDefinition(context, "SystemStructureModel", "Functional Structure Diagram", "SubSystem");

//register a callback function
//Change the text color of the title with the style of the shape, not the text.
var viewDefinitions = context.App.Workspace.CurrentProject.Profile.ViewDefinitions;
viewDefinitions.RegisterGetStyleCallback(targetDefinition, GetShapeStyle);
viewDefinitions.RegisterGetTextStyleCallback(targetDefinition, TextTypes.Title, GetTextStyle);
}

///<summary>
///deactivate the extension
///</summary>
///<param name="context">execution context</param>
public void Deactivate(IContext context)
{
//unregister the callback function
IElementDef targetDefinition = GetTargetDefinition(context, "SystemStructureModel", "Functional Structure Diagram", "SubSystem");
var viewDefinitions = context.App.Workspace.CurrentProject.Profile.ViewDefinitions;
viewDefinitions.UnregisterStyleCallback(targetDefinition);
}

///<summary>
///get the format change target
///</summary>
private IElementDef GetTargetDefinition(IContext context, string diagramClassName, string diagramName, string targetClassName)
{
var profile = context.App.Workspace.CurrentProject.Profile;

//Get the target element definition by name from the current project.
var diagramClass = profile.Metamodels.GetClass(diagramClassName);
var diagramDefinition = profile.ViewDefinitions.FindEditorDefByClass(diagramClass, diagramName).GetItem(0);
var targetClass = profile.Metamodels.GetClass(targetClassName);
var targetDefinition = profile.ViewDefinitions.FindElementDefByClass(diagramDefinition, targetClass).GetItem(0);
return targetDefinition;
}
}
}