PPR Hub |
Product Modeler |
Setting Graphical PropertiesImplementing the CATIVisProperties interface |
Use Case | ||
CAAPstIntegrateNewFeatures > CAAPstINFBuildCatalog > CAAPstINFCreateDocument > CAAPstINFInitCont > CAAPstINFNavigate > CAAPstINFVisu > CAAPstINFGraphicalProperties > CAAPstINFEdit > CAAPstINFCCP > CAAPstINFDelete > CAAPstINFUpdate |
AbstractThis 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. |
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:
CATVPPoint
),
the lineic type (CATVPLine
or CATVPEdge
) or the
surfacic type (CATVPMesh
). Each type of geometry regroups
together a set of graphical properties. A such property, the color, the line
type etc, is a CATVisPropertyTypeWhen you want associate graphical properties with a feature, there are three questions to ask :
In this use case you will learn :
IsGeomTypeDefined
method and the GetSubTypeFromPath
method answer respectivelely to the first and second question.[Top]
CAAPstINFGraphicProperties is a use case of the CAAProductStructure.edu framework that illustrates Visualization and GeometryVisualization framework capabilities.
[Top]
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.
![]() |
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:
![]() |
You can see just above, that
It is possible thanks to:
CAAPstINFPoint
, CAAPstINFWire
and
CAAPstINFLine,
If you read the "Graphical Properties" [1] technical article, and more precisely the "Integration of the Graphical Properties in The Visualization Processus" section, you know that the visualization process calls one of these following methods to update the graphical representations (CATRep class):
SetPointGraphicAttribute
SetLineGraphicAttribute
SetMeshGraphicAttribute
SetEdgeGraphicAttribute
SetAsmGraphicAttribute
SetOtherGeomTypeGraphicAttribute
To be more precise, it is one or several methods which are called. It
depend on the number of geometry's types defined by the feature. The current
article describes the overwriting of the SetPointGraphicAttribute
and the SetLineGraphicAttribute
methods.
[Top]
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]
The CAAPstINFGraphicProperties use case is made of source files located in the CAAPstINFModeler.m module of the CAAProductStructure.edu framework.
Windows |
|
Unix |
|
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
[Top]
The main steps of CAAPstINFGraphicProperties are:
[Top]
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.
#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
//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:
oPropertyNumber
is not used by the visualization
mechanism, so valuate it by zero.CATVPGlobalType
. It
is done by the visualization mechanism.This method is explained for each feature later in the article.
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]
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.
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.
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
.
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]
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.
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.
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
.
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.
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.
... // 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]
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.
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.
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
.
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.
The goal of this method is to modify the color (CATVPColor
)
and the symbol (CATVPSymbol
) of all the markers. In case of
the CATVPAllPropertyType
the color and the symbol must be
changed.
void CAAEPstINFVisuWire::SetPointGraphicAttribute(CATRep *iRep, CATVisPropertyType iPropertyType, CATVisPropertiesValues & iPropertyValue) { if ( NULL == iRep ) return; CAT3DCustomRep * pRepWire = (CAT3DCustomRep *) iRep ; // Retrieve the CAT3DMarkerGP int NbGP = pRepWire->GetGPSize(); if ( NbGP != 2 ) return ; CATGraphicPrimitive * pGP = pRepWire->GetGP(0) ; if ( 0 == pGP->IsAKindOf("CAT3DMarkerGP") ) return; // Change the symbol if ( (iPropertyType == CATVPAllPropertyType ) || ( iPropertyType == CATVPSymbol)) { // Retrieve the new symbol unsigned int NewSymbol; if (SUCCEEDED(iPropertyValue.GetSymbol(NewSymbol))) { // Retrieve the current GP CAT3DMarkerGP * pOldPointGP = (CAT3DMarkerGP *) pGP ; if ( NULL != pOldPointGP ) { // retrieve the coordinate's points 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,nbPoints,(SymbolType) NewSymbol); //Replace the marker with the same graphic attribute pRepWire->Modify(pOldPointGP,pNewPointGP,NULL); //The old GP must be deleted CATGraphicPrimitive::Destroy(pOldPointGP); pOldPointGP = NULL ; } } } } // Change the color if ( (iPropertyType == CATVPAllPropertyType ) || ( iPropertyType == CATVPColor)) { // The color of the marker is modified CATGraphicAttributeSet * pAg = &(pRepWire->GetAttribut(0)); SetGraphicAttributeSet (pAg, CATVPColor, iPropertyValue); } } |
This method is slightly the same as for the CAAPstINFPoint
feature. The difference resides in retrieving the CAT3DMarkerGP
in the CAT3DCustomRep. If in the CAAPstINFPoint
case, the graphic primitive is unique, with the CAAPstINFWire
,
the CAT3DCustomRep contains at the creation, in first position the
marker GP and in second position the line GP. This order is always kept,
since even thought the CAT3DMarkerGP must be deleted to modify
the symbol, the Modify
method replaces the old GP by the
new GP.
The goal of this method is to modify the color (CATVPColor
),
the thickness (CATVPLineType) and the
type of line (CATVPLineType
)
of all the lines. In case of the CATVPAllPropertyType
the
three properties must be changed.
void CAAEPstINFVisuWire::SetLineGraphicAttribute(CATRep *iRep, CATVisPropertyType iPropertyType, CATVisPropertiesValues & iPropertyValue) { if ( NULL == iRep ) return; CAT3DCustomRep * pRepWire = (CAT3DCustomRep *) iRep ; // Test that the second GP is the GP which contains the lines int NbGP = pRepWire->GetGPSize(); if ( NbGP != 2 ) return ; CATGraphicPrimitive * pGP = pRepWire->GetGP(1) ; if ( 0 == pGP->IsAKindOf("CAT3DLineGP") ) return ; // Change the thickness if ( (iPropertyType == CATVPAllPropertyType ) || ( iPropertyType == CATVPWidth)) { CATGraphicAttributeSet * pAg = &(pRepWire->GetAttribut(1)); SetGraphicAttributeSet (pAg, CATVPWidth, iPropertyValue); } // Change the type if ( (iPropertyType == CATVPAllPropertyType ) || ( iPropertyType == CATVPLineType )) { CATGraphicAttributeSet * pAg = &(pRepWire->GetAttribut(1)); SetGraphicAttributeSet (pAg, CATVPLineType, iPropertyValue); } // Change the color if ( (iPropertyType == CATVPAllPropertyType ) || ( iPropertyType == CATVPColor)) { CATGraphicAttributeSet * pAg = &(pRepWire->GetAttribut(1)); SetGraphicAttributeSet (pAg, CATVPColor, iPropertyValue); } } |
For the lines graphical attributes it is easier than for the points,
all the properties are on a CATGraphicAttributeSet value. The
CAT3DLineGP being the second graphic primitive of the
CAT3DCustomRep, the CATGraphicAttributeSet value to modify is
those returned by the GetAttribut
method with 1
as argument.
[Top]
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:
This method defines the types of property defined by the feature. A type
of geometry is a CATVisGeomType whose the main predefined values are:
CATVPPoint, CATVPLine, CATVPEdge , CATVPMesh
and
CATVPGlobalType
This method defines for each properties displayed in the "Graphic Properties" toolbar the type of geometry affected.
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]
[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]
Version: 1 [May 2002] | Document created |
[Top] |
Copyright © 2002, Dassault Systèmes. All rights reserved.