PreBuild and PostBuild Variance

The variance access API is the entry point for convenient access to variant AUTOSAR model content. It provides means to filter variant model content and access variant specific data.

The DaVinci Configurator supports two types of variance:

  • PostBuild variance (Post-build selectable)
  • PreBuild variance

Investigate Project Variance

The projects variance can be analyzed using the variance keyword. These methods can be called then:

  • The method getCurrentlyActiveView() returns the currently active model view.
  • The method variantView(String) returns the IPostBuildPredefinedVariantView with the given name. This may be a PreBuild of PostBuild view.

Retrieve and use a variant view by name
scriptTask("TaskName", DV_PROJECT){
    code{
        // Activates the DoorLeftFront variant
        variance.variantView("DoorLeftFront").activeWith{
            // Now all MDF model accesses are executed in the variant "DoorLeftFront"
        }
    }
}

The default view is the IPostBuildInvariantValuesView
scriptTask("TaskName", DV_PROJECT){
    code{
        def activeView1 = variance.currentlyActiveView
        assert activeView1 instanceof IPostBuildInvariantValuesView

        // ... or with a closure
        variance {
                def activeView2 = currentlyActiveView
                assert activeView1 == activeView2
                assert activeView1 == postBuildInvariantValuesView

                // Get number of variants
                int num = allPostBuildVariantViews.size()
                assert num == 4
        }
    }
}

Investigate Project Variance - PostBuild

  • The method hasPostBuildVariance() returns true if the active project contains post-build variants.

  • The method getPostBuildInvariantValuesView() returns the PostBuild invariant values view. This view contains objects which are not variant (Object or parent have no VariationPoint) or the values in all variants are equal.

  • The method getPostBuildInvariantEcucDefView() returns the PostBuild invariant Ecuc definition view. This view contains the same objects as the invariant values view but excludes all objects which, by (EcuC / BSWMD) definition, support variance. Using this view you can avoid dealing with objects which are accidentally equal by value (in your test configurations) but potentially can be different because they support variance.

  • The method getAllPostBuildVariantViews() returns the model views of all PostBuild predefined variants defined in the evaluated variant set. It never returns null. If the project contains no PostBuild variants, the result will be an empty list.

    The order of variant views returned is deterministic. It is the natural order of the names of the variants defined in the evaluated variant set.

  • The method getAllPostBuildVariantViewsOrInvariant() returns the same as the method getAllPostBuildVariantViews() if the project contains PostBuild variants. If the project contains no PostBuld variants (see hasPostBuildVariance()) the method returns a list containing only the IPostBuildInvariantValuesView.

    This helps to create code working with both variant and non-variant projects.

Variant Model Objects

The following model object extensions provide convenient means to investigate model object variance in detail.

  • The method IModelView.activeWith(Supplier) executes code under visibility of the specified model view.

  • The method MIObject.isModelInvariant() returns true if the object and all its parents has no variation point conditions. If this is true, this model object instance is visible in all variant view.

  • The method MIObject.isVisible() returns true if the object is visible in the current model view.

  • The method MIObject.isVisibleInModelView(IModelView) returns true if the object is visible in the specified model view.

  • The method MIObject.asViewedModelObject() returns a new IViewedModelObject instance using the currently active view.

  • The method MIObject.getPostBuildVariantSiblings() returns MDF object instances representing the same object but in all variants.

    For details about the sibling semantic see VariantSiblings.
  • The method getPostBuildVariantSiblingsWithoutMyself(MIObject) returns the same collection as getPostBuildVariantSiblings(MIObject) but without the specified object.

Execute code in a model view
// IPostBuildPredefinedVariantView viewDoorLeftFront = ...
// MIParameterValue variantParameter = ...

viewDoorLeftFront.activeWith {
    assert variance.currentlyActiveView == viewDoorLeftFront

    // The parameter instance is not visible in all variants ...
    assert !variantParameter.isModelInvariant()

    // ... but all variants have a sibling with the same value
    assert variantParameter.isPostBuildValueInvariant()
}

Variant Model Objects - PostBuild

  • The method MIObject.isPostBuildValueInvariant() returns true if the object has the same value in all PostBuild variants.

    See IPostBuildInvariantValuesView for more details to the concept.

    Attention: This must also return true for elements in other variants as the first PostBuild Predefined Variant, when the element is invariant! This is not the same result as IPostBuildInvariantValuesView isVisible() method returns.

    For details about invariant views see InvariantModelViews.
  • The method MIObject.isPostBuildEcucDefInvariant() returns true if the object is invariant according to its EcuC definition.

    See IPostBuildInvariantEcucDefView for more details to the concept.

    Attention: This must also return true for elements in other variants as the first PostBuild Predefined Variant, when the element is invariant! This is not the same result as IPostBuildInvariantEcucDefView isVisible() method returns.

  • The method MIObject.isNeverPostBuildVisible() returns true, if the object is invisible in all variant view.

  • The method MIObject.getVisiblePostBuildVariantViews(MIObject) returns all variant views the specified object is visible in.

  • The method MIObject.getVisiblePostBuildVariantViews(MIObject) returns all variant views the specified object is visible in.