PPR Hub

Product Modeler

Setting Graphical Properties

Implementing the CATIVisProperties interface

Use Case
CAAPstIntegrateNewFeatures > CAAPstINFBuildCatalog > CAAPstINFCreateDocument > CAAPstINFInitCont > CAAPstINFNavigate > CAAPstINFVisu > CAAPstINFGraphicalProperties > CAAPstINFEdit > CAAPstINFCCP > CAAPstINFDelete > CAAPstINFUpdate

Abstract

This article shows how to implement the CATIVisProperties interface. It enables you to associate graphical properties to features. But, sometimes, implementing the CATIVisProperties interface is not enough, and you should overwrite methods of the CATExtIVisu adapter class of the CATIVisu interface. It is also described in this article.


What You Will Learn With This Use Case

Before reading this article, it is recommended to see the "Graphical Properties" technical article [1] to understand how the graphical properties are proceeded in the visualization mechanism. It is based on three interfaces:

When you want associate graphical properties with a feature, there are three questions to ask :

In this use case you will learn :

[Top]

The CAAPstINFGraphicProperties Use Case

CAAPstINFGraphicProperties is a use case of the CAAProductStructure.edu framework that illustrates Visualization and GeometryVisualization framework capabilities.

[Top]

What Does CAAPstINFGraphicProperties Do

This use case enables to modify the graphical properties of the CAAPstINFPoint, CAAPstINFWire and CAAPstINFLine features. Refer to the "Creating a New StartUp Catalog " use case [2] to have more details about these three features. The document CAAPstINFDocument [Fig.1] created by the "Creating New Features 'From Scratch' in a Product Document" use case [3] contains some instances of theses features.

Fig.1: The CAAPstINFDocument Document

In selecting the Properties command (Contextual menu or in the Edit menu), it is possible to modify some graphical properties of these features. See an example [Fig.2] that you can obtain:

Fig.2: The CAAPstINFDocument Document after some graphical modifications

You can see just above, that

It is possible thanks to:

[Top]

How to Launch CAAPstINFGraphicProperties

See the section entitled "How to Launch the CAAPstIntegrateNewFeatures Use Case" in the "Integrating New Features in a Product Structure" use case for a detailed description of how this use case should be launched.

Specifically, the code described in this article is executed upon loading the Product document (you can use the CAAPstINFDocument.CATProduct document that can be found in the CNext/resources/graphic directory of the CAAProductStructure.edu framework [Fig.1] ) into the CATIA session.

Interactive scenario once the CAAPstINFDocument.CATProduct is loaded:

[Top]

Where to Find the CAAPstINFGraphicProperties Code

The CAAPstINFGraphicProperties use case is made of source files located in the CAAPstINFModeler.m module of the CAAProductStructure.edu framework.

Windows
  • InstallRootDirectory\CAAProductStructure.edu\CAAPstINFModeler.m\
Unix
  • InstallRootDirectory/CAAProductStructure.edu/CAAPstINFModeler.m\

where InstallRootDirectory is the directory where the CAA CD-ROM is installed.

[Top]

Step-by-Step

The main steps of CAAPstINFGraphicProperties are:

  1. Creating the CATIVisProperties Data Extension
  2. Processing the Line Feature
  3. Processing the Point Feature
  4. Processing the Wire Feature

[Top]

Creating the CATIVisProperties Data Extension

For the three features the CATIVisProperties interface is implemented in creating a data extension. To be shorter, only the case of the CAAPstINFPoint feature is described. For the line and the wire, change CAAPstINFPoint by CAAPstINFLine and CAAPstINFWire respectively.

  1. Header source
  2. #ifndef CAAEPstVisPropertiesPoint_H
    #define CAAEPstVisPropertiesPoint_H
    
    #include "CATExtIVisProperties.h"    // Need to derive from
    
    class CAAEPstVisPropertiesPoint : public CATExtIVisProperties
    {
      CATDeclareClass;
    
      public:
    
        CAAEPstVisPropertiesPoint();
        virtual ~CAAEPstVisPropertiesPoint();
    
        HRESULT IsGeomTypeDefined(CATVisGeomType & iGeomType) ;
    
        HRESULT GetSubTypeFromPath(CATPathElement     & iPathElement,
                                   CATVisPropertyType   iPropertyType,
                                   CATVisGeomType     & oGeomType,
                                   unsigned int       & oPropertyNumber) ;
    
      private:
    
      CAAEPstVisPropertiesPoint(const CAAEPstVisPropertiesPoint &iObjectToCopy);
      CAAEPstVisPropertiesPoint & operator = (const CAAEPstVisPropertiesPoint &iObjectToCopy);
    
    };
    #endif

    The CAAEPstVisPropertiesPoint C++ class derives from CATExtIVisProperties, the adapter class of the CATIVisProperties interface. The CATDeclareClass macro declares that the CAAEPstVisPropertiesPoint class belongs to a component. The copy constructor and the "=" operator are set as private to prevent the compiler from automatically creating them as public.

    The public methods, other than the constructor and the destructor, are methods defined in the CATIVisProperties interface

  3. Code source
  4. //Local Framework
    #include "CAAEPstVisPropertiesPoint.h"
    
    #include "TIE_CATIVisProperties.h"
    TIE_CATIVisProperties(CAAEPstVisPropertiesPoint);
    
    CATImplementClass(CAAEPstVisPropertiesPoint, DataExtension, CATBaseUnknown, CAAPstINFPoint);
    
    CAAEPstVisPropertiesPoint::CAAEPstVisPropertiesPoint()
    {
    }
    
    CAAEPstVisPropertiesPoint::~CAAEPstVisPropertiesPoint()
    {
    }
    ...

    The CAAEPstVisPropertiesPoint class states that it implements the CATIVisProperties interface thanks to the TIE_CATIVisProperties macro. This extension class is dedicated to the CAAPstINFPoint feature. The CATImplementClass macro declares that the CAAEPstVisPropertiesPoint class is a data extension class, thanks to the DataExtension keyword, and that it extends the component whose main class is CAAPstINFPoint. The third parameter must always be set to CATBaseUnknown (unused parameter)

    The constructor and destructor are empty.

    ...
    HRESULT CAAEPstVisPropertiesPoint::IsGeomTypeDefined(CATVisGeomType & iGeomType)
    {
      see the implementation for the point
      see the implementation for the line 
      see the implementation for the wire
    } 
    ...

    The goal of this method is to return S_OK when the input argument, iGeomType, is available for the feature, otherwise it returns E_FAIL. This method is explained for each feature later in the article.

    ...
    HRESULT CAAEPstVisPropertiesPoint::GetSubTypeFromPath(CATPathElement & iPathElement,
                                                             CATVisPropertyType        iPropertyType,
                                                             CATVisGeomType          & oGeomType,
                                                             unsigned int            & oPropertyNumber)
    {
      see the implementation for the point
      see the implementation for the line 
      see the implementation for the wire
    }

    This method is automatically called to update the "Graphic Properties" toolbar. This toolbar contains combos to modify the color, the type of a line, etc... of the selected feature(s). The goal of this method is to return the type of geometrie, oGeomType, for the input graphical properties iPropertyType, concerned by the toolbar modifications. The returned type of geometry must be of course defined by the feature.

    Remarks:

    This method is explained for each feature later in the article.

  5. Modifying the interface dictionary
  6. In the interface dictionary dedicated to the CAAProductStructure.edu framework, it is necessary to add the following lines to indicate that the CAAPstINFPoint, CAAPstINFLine, and CAAPstINFWire features implement the CATIVisProperties interface in the libCAAPstINFModeler module.

    ...
    CAAPstINFPoint             CATIVisProperties             libCAAPstINFModeler
    CAAPstINFine               CATIVisProperties             libCAAPstINFModeler
    CAAPstINFWire              CATIVisProperties             libCAAPstINFModeler
    ...

[Top]

Processing the Line Feature

The CAAPstINFLine feature is graphically represented by a line between the two CAAPstINFPoint which constitue it. Refer to the "Enabling the Visualization of New Features in a Product Document" [4] article to see how the BuildRep method of the CATI3DGeoVisu interface is implemented.

  1. The IsGeomTypeDefined method of the CATIVisProperties interface
  2. HRESULT CAAEPstVisPropertiesLine::IsGeomTypeDefined(CATVisGeomType & iGeomType)
    {
        HRESULT rc = E_FAIL ;
    
        if ( (CATVPLine == iGeomType) || (CATVPGlobalType == iGeomType) )
            rc =  S_OK ;
    
        return rc ;
    } 

    The CAAPstINFLine feature defines the CATVPLine geometry type to modify the color, the thickness and the type of the line. The CATVPGlobalType type enables to modify the show/no show flag, the pick/no pick flag, the lowint flag and the number of the layer.

  3. The GetSubTypeFromPath method of the CATIVisProperties interface
  4. HRESULT CAAEPstVisPropertiesLine::GetSubTypeFromPath(CATPathElement & iPathElement,
                                                         CATVisPropertyType           iPropertyType,
                                                         CATVisGeomType             & oGeomType,
                                                         unsigned int               & oPropertyNumber)
    {
        HRESULT rc = E_FAIL ;
    
        switch ( iPropertyType )
        {
        case CATVPColor:
        case CATVPLineType:
        case CATVPWidth:
            oGeomType = CATVPLine ;c
            rc = S_OK ;
            break;
    
        }
        oPropertyNumber = 0 ;
        return rc ;
    }

    For the CAAPstINFLine feature there is no ambiguity, for the CATVPColor, CATVPLineType and the CATVPWidth properties, the type of geometry is CATVPLine.

  5. CATExtIVisu methods

    The type of geometry is CATVPLine , so it is the SetLineGraphicAttribute method of the CATExtIVisu adapter class which is concerned. The graphic representation of the CAAPstINFLine feature is a CAT3DCustomRep which contains one graphic primitive a CAT3DLineGP. So the default implementation, those of the CATExtIVisu adapter class, will correctly process the properties modifications. It is not necessary to overwrite this method.

[Top]

Processing the Point Feature

The CAAPstINFPoint feature is graphically represented by a marker. Refer to the "Enabling the Visualization of New Features in a Product Document" [4] article to see how the BuildRep method of the CATI3DGeoVisu interface is implemented.

  1. The IsGeomTypeDefined method of the CATIVisProperties interface
  2. HRESULT CAAEPstVisPropertiesPoint::IsGeomTypeDefined(CATVisGeomType & iGeomType)
    {
        HRESULT rc = E_FAIL ;
    
        if ( (CATVPPoint == iGeomType) || (CATVPGlobalType == iGeomType) )
            rc =  S_OK ;
        return rc ;
    } 

    The CAAPstINFPoint feature defines the CATVPPoint geometry type to modify the color and the symbol of the marker. The CATVPGlobalType type enables to modify the show/no show flag, the pick/no pick flag, the lowint flag and the number of the layer.

  3. The GetSubTypeFromPath method of the CATIVisProperties interface
  4. HRESULT CAAEPstVisPropertiesPoint::GetSubTypeFromPath(CATPathElement & iPathElement,
                                                             CATVisPropertyType        iPropertyType,
                                                             CATVisGeomType          & oGeomType,
                                                             unsigned int            & oPropertyNumber)
    {
        HRESULT rc = E_FAIL ;
    
        switch ( iPropertyType )
        {
        case CATVPColor:
        case CATVPSymbol:
            oGeomType = CATVPPoint ;
            rc = S_OK ;
            break;
    
        }    
        oPropertyNumber = 0 ;
        return rc ;
    }

    For the CAAPstINFPoint feature there is no ambiguity, for the CATVPColor and the CATVPSymbol properties, the type of geometry is CATVPPoint.

  5. CATExtIVisu method

    The type of geometry is CATVPPoint , so it is the SetPointGraphicAttribute method of the CATExtIVisu adapter class which is concerned. The graphic representation of the CAAPstINFLine feature is a CAT3DCustomRep which contains one graphic primitive a CAT3DMarkerGP. So the default implementation, those of the CATExtIVisu adapter class, will not correctly process the properties modifications. It is necessary to overwrite this method.

    The goal of this method is to modify the color (CATVPColor) and the symbol (CATVPSymbol) of the marker. In case of the CATVPAllPropertyType the color and the symbol must be changed.

    1. The symbol of the marker
    2. void CAAEPstINFVisuPoint::SetPointGraphicAttribute(CATRep *iRep, 
                                                         CATVisPropertyType iPropertyType,
                                                         CATVisPropertiesValues & iPropertyValue)
      {
         if ( NULL == iRep ) return;
        
         CAT3DCustomRep * pRepPoint = (CAT3DCustomRep *) iRep ;
      
         // The symbol property
         if ( (iPropertyType == CATVPAllPropertyType ) || ( iPropertyType == CATVPSymbol))
         {
            // retrieve the new symbol
            unsigned int NewSymbol;
            if (SUCCEEDED(iPropertyValue.GetSymbol(NewSymbol)))
            {
               // Retrieve the current GP 
               CATGraphicPrimitive * pOldGP = pRepPoint->GetGP(0) ;
               if ( NULL != pOldGP )
               {
                  CAT3DMarkerGP * pOldPointGP = (CAT3DMarkerGP *) pOldGP ;
      
                  // retrieve the coordinate's point and the current symbol
                  float * points;
                  int nbPoints;
                  SymbolType OldSymbol;
                  
                  pOldPointGP->Get(&points, &nbPoints, &OldSymbol);
      
                  if ( NewSymbol != OldSymbol )
                  {
                     // Creation of a new marker with the new symbol
                     CAT3DMarkerGP * pNewPointGP = new CAT3DMarkerGP(points,1,(SymbolType) NewSymbol);
      
                     //Replace the marker with the same graphic attribute
                     pRepPoint->Modify(pOldPointGP,pNewPointGP,NULL);
      
                     //The old GP must be deleted
                     CATGraphicPrimitive::Destroy(pOldPointGP);
                     pOldPointGP = NULL ;
                  }
               }
           } 
        }
       ...
      }

      The symbol of the CAT3DMarkerGP is not set into a CATGraphicAttributeSet instance. The value is given at the graphic primitive (GP) construction. So to change it, a new GP must be created.

      If the new symbol is different from the current, a new CAT3DMarkerGP will be created. The new GP replaces the old thanks to the Modify method of the CAT3DCustomRep class. The old GP must be destroyed, thanks to Destroy method.

  6. The color
  7. ...
      // The color property
      if ( (iPropertyType == CATVPAllPropertyType ) || ( iPropertyType == CATVPColor))   
      {
        CATGraphicAttributeSet * pAg = &(pRepPoint->GetAttribut(0));
        SetGraphicAttributeSet (pAg, CATVPColor, iPropertyValue);      
      }
    }

    The color is modified on the CATGraphicAttributeSet instance associated with the first (0) GP of the CAT3DCustomRep. You retrieve it thanks to the GetAttribut method. The SetGraphicAttributeSet method enables to modify on the pAg graphic attribute, the CATVPColor properties read on the iPropertyValue argument.

[Top]

Processing the Wire Feature

The CAAPstINFWire feature is graphically represented markers and lines between each markers. Refer to the "Enabling the Visualization of New Features in a Product Document" [4] article to see how the BuildRep method of the CATI3DGeoVisu interface is implemented.

  1. The IsGeomTypeDefined method of the CATIVisProperties interface
  2. HRESULT CAAEPstVisPropertiesWire::IsGeomTypeDefined(CATVisGeomType & iGeomType)
    {
        HRESULT rc = E_FAIL ;
    
        if ( (CATVPLine == iGeomType) || (CATVPPoint == iGeomType) || (CATVPGlobalType == iGeomType) )
            rc =  S_OK ;
    
        return rc ;
    } 

    The CAAPstINFWire feature defines the CATVPLine geometry type to modify the color, the thickness and the type of the lines and defines the CATVPPoint geometry type to modify the color and the symbol of the markers. The CATVPGlobalType type enables to modify the show/no show flag, the pick/no pick flag, the lowint flag and the number of the layer.

  3. The GetSubTypeFromPath method of the CATIVisProperties interface
  4. HRESULT CAAEPstVisPropertiesWire::GetSubTypeFromPath(CATPathElement & iPathElement,
                                                         CATVisPropertyType           iPropertyType,
                                                         CATVisGeomType             & oGeomType,
                                                         unsigned int               & oPropertyNumber)
    {
    
        HRESULT rc = E_FAIL ;
    
        switch ( iPropertyType )
        {
        case CATVPColor:
        case CATVPLineType:
        case CATVPWidth:
            oGeomType = CATVPLine ;
            rc = S_OK ;
            break;
    
        case CATVPSymbol:
            oGeomType = CATVPPoint ;
            rc = S_OK ;
            break;
        }
        oPropertyNumber = 0 ;
        return rc ;
    }

    For the CATVPLineType, CATVPWidth ou CATVPSymbol property type there are no ambiguite, it is either CATVPLine for the lineic geometry or CATVPPoint for the marker. But for the color, the choice is between the line and the marker geometry. Here the choice is CATVPLine.

  5. CATExtIVisu methods
  6. The type of geometries are CATVPPoint and CATVPLine, so the concerned methods of the CATExtIVisu class adapter are SetPointGraphicAttribute and SetLineGraphicAttribute. The graphic representation of the CAAPstINFWire feature is a CAT3DCustomRep which contains two graphic primitives: a CAT3DMarkerGP with N points and a CAT3DLineGP with the same points. The default SetPointGraphicAttribute method don't process the CAT3DCustomRep, and the default SetLineGraphicAttribute modifies all the graphic Primitive of the CAT3DCustomRep without testing the type of the graphic primitive. It is necessary to overwrite these two methods.

[Top]


In Short

This article illustrates how to to implement the CATIVisProperties to associate graphical properties to features. This interface has an adapter class, CATExtIVisProperties, whose two methods are to be overwriten:

The graphical representations take account of the graphical properties thanks to methods of the CATExtIVisu class adapter of the CATIVisu interface: SetPointGraphicAttribute, SetLineGraphicAttribute, etc. When the default implementation of these methods cannot modify correctly the graphic representation of the feature, it is necessary to overwrite them.

[Top]


References

[1] Graphical Properties
[2] Creating a New StartUp Catalog
[3] Creating New Features "From Scratch" in a Product Document
[4] Enabling the Visualization of New Features in a Product Document

[Top]


History

Version: 1 [May 2002] Document created
[Top]

Copyright © 2002, Dassault Systèmes. All rights reserved.