CODComponent Class

class CODComponent: public CCmdTarget, public MvcVisualComponent, public CPropertyContainer< IODPropertyContainer, CPropertyNoopAccessor >

Base class for component objects.

A component occupies a rectangular area in the logical space of the model. The virtual function  Draw is inherited from MvcVisualComponent . The virtual function  OnDraw is called from  Draw and is overridden in subclasses to implement drawing.

The origin and size of a component are stored as logical integers. Points are also represented as logical integers. These logical units are converted to device units when the component is rendered to a device context. The mapping mode, window extents, and viewport extents set in the device context determine the number of pixels that are drawn on the output device.

All components contain a transform matrix - see  CODTransform. The transformation matrix is used to translate, rotate, and scale points used to draw the component. The functions  Translate,  Rotate, and  Scale are used to set values in the matrix. Subclasses generally transform their points just before rendering in  OnPrepareDC.

Points are referred to as local coordinates prior to having a component's transformations applied. Local coordinates are points that are relative to the component's own local coordinate system. Local coordinates become world coordinates after they are transformed using the component's transformation matrix. World coordinates are still logical coordinates. They become device coordinates when they are used in a device context. The component's  CODRgn member variable and the bounding rectangle returned by GetBounds are calculated and stored in world coordinates.

Components can be assigned properties at runtime. A property is an object that consists of an identifier and a value. The base class for all properties is  CODProperty. Properties can include fonts, line widths and colors, brush colors, booleans, strings, integers, etc. Additionally, CODComponent supports  IODPropertyContainer which provides a generic way to access and manipulate a component's properties.

Components can be nested. A component can have 0 to N child components.

The following properties are added to the component by this class:

OD_PROP_EDIT

Defined in: OdComponent.h

See Also

Component Property Identifiers

Class Members

Construction/Destruction

 CODComponent()

Constructor.

 CODComponent(const CODComponent& src)

Copy constructor.

virtual  ~CODComponent()

Destructor.

BOOL  Create(UINT nID)

Creates the component and initializes the data members.

BOOL  Create(CODComponentSet* pCompSet)

Creates the component out of a list of visual components.

BOOL  InitTypeAndName(UINT nID)

Initializes the type and name strings of the component.

CODComponent&  operator=(const CODComponent& src)

Assignment operator.

virtual CODComponent*  Dup() const

Create a duplicate copy of this object.

Attributes

ODComponentId m_lID

Unique ID for the component.

int m_nZOrder

The order in which this component is drawn with respect to its peers.

CPen* m_pPen

Pen for general drawing or tracking.

CFont* m_pFont

Font for general drawing or tracking.

CBrush* m_pBrush

Brush for general drawing or tracking.

CODRgn m_rgn

Region occupied by component.

CRect m_rcAlign

Rectangle used to align the component to the grid.

CRect m_rcOldBounds

The previous bounding rectangle.

BOOL m_bTracking

TRUE if the component is in tracking mode.

CODTransform* m_pXform

Transformation matrix.

static CThreadLocal&ltCODTransformStack> m_transformStack

Transformation stack.

CODComponent* m_pParent

Pointer to component's parent

CODComponentSet m_setComponents

List of child components

CList&ltCODPropPtr,CODPropPtr> m_listProperties

List of component properties.

CObject* m_pUserData

Hook for user data object.

ULONG m_ulRefCount

Reference count value.

virtual ULONG STDMETHODCALLTYPE  AddRef()

Add a reference to this object.

virtual ULONG STDMETHODCALLTYPE  Release()

Release a reference to this object.

Identification methods

ODComponentId  GetID() const

Get the ID of the component.

void  SetID(const ODComponentId lID)

Set the ID of this component. Do not call this directly! This is for use by the diagram model.

virtual IUnknown* GetAxControl()

Get a pointer to the IUnknown for an ActiveX control component

virtual IODIdGenerator*  GetIdGenerator()

Get a pointer to the ID generator interface for this component.

virtual ODComponentId  RegisterID(IODIdGenerator* pIIdGenerator)

Register a unique ID for this component with the ID generator.

virtual BOOL  UnregisterID(IODIdGenerator* pIIdGenerator)

Remove the unique ID for this component from the ID generator.

CString  GetType() const

Get the type of the component.

void  SetType(const CString strType)

Set the type of the component.

CString  GetName() const

Get the name of the component.

virtual void  SetName(const CString strName)

Set the name of the component.

Z-Order methods

int  GetZOrder() const

Gets the z-order of this component with respect to its peers.

void  SetZOrder(const int nZOrder)

Sets the z-order of this component.

void  UpdateZOrder(int nIndex)

Updates the z-order of this component's children.

void  ZOrderSort(CODComponentSet* pCompSet)

Sorts a set of components based on their z-order.

void  ZOrderSort(CODComponentSet* pCompSet, int nLower, int nUpper)

Sorts a set of components based on their z-order.

virtual CODBspTree*  GetBspTree()

Gets the binary space partitioning tree in which to store positional information.

virtual CODBspTree*  GetParentBspTree()

Gets the parent's binary space partitioning tree in which to store positional information.

Composite methods

virtual CODComponentSet*  GetComponents()

Return a pointer to the list of child components.

virtual int  GetChildCount() const

Return number of children in the composite.

virtual void  SetParent(CODComponent* pParent)

Set the parent of this component.

virtual CODComponent*  GetParent() const

Return a pointer to the parent of this component.

virtual int  LocateChild(CODComponent* pChild) const

Return the collection index of a given child in the composite.

virtual CODComponent*  GetChild(const int nIndex) const

Return a pointer to a child given the collection index.

virtual BOOL  AppendChild(CODComponent* pChild)

Add a child to the end of the collection.

virtual BOOL  AppendChildren(CODComponentSet* pCompSet)

Add a set of children to the end of the collection.

virtual BOOL  InsertChild(CODComponent* pChild, const int nIndex)

Insert a child into the composite at a given position.

BOOL  InsertChild(CODComponent* pChild, const int nIndex, CPoint ptInsertAt)

Insert a child into the composite at a given position.

virtual BOOL  RemoveChild(const int nIndex)

Remove a child from the composite.

BOOL  RemoveChild(CODComponent* pChild)

Remove a child from the composite.

void  RemoveChildren(CODComponentSet* pCompSet)

Remove a list of children from the composite.

void  RemoveAllChildren()

Remove all children from the composite.

virtual BOOL  IsChild(CODComponent* pComp) const

Determines if the given component is a child of this component.

CODComponent*  LocateParent(CODComponent* pChild)

Return a pointer to the parent component of the given child.

virtual void  InitChildProperties(CODComponent* pChild)

Parent has a chance to initialize properties for new children.

virtual BOOL  GroupCompatible(CODComponentSet* pCompSet) const

Test to determine if this component can be included in the given group.

Property methods

virtual int  GetPropertyCount() const

Get the number of properties in the container.

virtual sfl::IProperty*  GetPropertyAt(const int nPropIdx)

Get the property using an index into the container.

virtual bool  GetPropertyValue(const sfl::PropertyId propId, VARIANT& propVal) const

Get a property value using the property ID.

virtual bool  GetPropertyString(const sfl::PropertyId propId, BSTR& propVal) const

Get a string representing the property value using a property ID.

virtual bool  GetPropertyContainer(const sfl::PropertyId propId, sfl::IPropertyContainer **container) const

Get a property value using the property ID. Converts value to container if applicable.

virtual bool  PutPropertyValue(const sfl::PropertyId propId, const VARIANT& propVal)

Set a property value using the property ID.

virtual bool  PutPropertyString(const sfl::PropertyId propId, const BSTR& propVal)

Set a property value using the property ID and a string representing the value.

CODProperty*  GetProperty(int nPropId, const BOOL bSearchParents = FALSE) const

Return a pointer to the specified property.

BOOL  GetProperty(CODProperty* pPropOut, int nPropId, const BOOL bSearchParents = FALSE) const

Return a copy of the specified property.

virtual void  SetProperty(CODProperty* pProperty)

Set the specified property.

virtual BOOL  ChangeProperty(CODProperty* pProperty, DWORD dwChangeFlags = OD_CHANGE_ALL)

Changes the specified property.

virtual BOOL  AddProperty(CODProperty& prop)

Add the specified property.

virtual BOOL  UpdateProperty(CODProperty& prop)

Updates the specified property.

virtual BOOL  RemoveProperty(const int nPropId)

Remove the specified property.

virtual BOOL  GetProperty(const int nPropId, CODProperty& prop)

Return a copy of the specified property.

virtual BOOL  GetValue(const int nPropId, CString& strValue) const

Gets the value of the given string property.

virtual BOOL  GetValue(const int nPropId, int& nValue) const

Gets the value of the given integer property.

virtual BOOL  GetValue(const int nPropId, UINT& nValue) const

Gets the value of the given unsigned integer property.

virtual BOOL  GetValue(const int nPropId, DWORD& dwValue) const

Gets the value of the given DWORD property.

virtual BOOL  GetValue(const int nPropId, float& fValue) const

Gets the value of the given float property.

virtual BOOL  SetValue(const int nPropId, LPCTSTR lpszValue)

Sets the value of the given string property.

virtual BOOL  SetValue(const int nPropId, const int nValue)

Sets the value of the given integer property.

virtual BOOL  SetValue(const int nPropId, const UINT nValue)

Sets the value of the given unsigned integer property.

virtual BOOL  SetValue(const int nPropId, const DWORD dwValue)

Sets the value of the given unsigned DWORD property.

virtual BOOL  SetValue(const int nPropId, const float fValue)

Sets the value of the given float property.

virtual IODPropertyContainer*  GetAmbientPropertyContainer() const

Return a pointer to the ambient property container.

virtual void  OnPropertyChange(const CODProperty& prop)

Called when a property is changed.

virtual void  OnAmbientPropertyChange(const int nPropId)

Called when an ambient property is changed.

virtual void  AssignDefaultProperties(CODPropertySet* pDefaults = NULL)

Assign default properties.

void  CacheProperties()

Update property cache and eliminate duplicates.

static BOOL  IsSetEditable(CODComponentSet* pCompSet)

Static helper function to determine if the properties of a component set can be edited

Transformation and movement methods

virtual CPoint  SetOrigin(int x, int y)

Set the origin of this component relative to the container and in the container's units

virtual CPoint  OffsetOrigin(int xOff, int yOff)

Offset the origin of this component by specified deltas

virtual CPoint  MoveOrigin(int xOff,int yOff)

Move the origin of this component by specified deltas

virtual CODTransform*  GetTransform()

Return the transformation matrix for this component.

void  GetTransform(CODTransform& xForm)

Return the transformation matrix for this component.

virtual void  SetTransform(CODTransform* pXform)

Set the transformation matrix for this component.

void  SetTransform(const CODTransform& xForm)

Set the transformation matrix for this component.

virtual void  Translate(int nOffsetX, int nOffsetY)

Moves the component by an offset.

virtual BOOL  ValidateTranslate(int& nOffsetX, int& nOffsetY) const

Determines if the component can be moved to the given offsets.

virtual void  Rotate(int nAngle, float fOriginX, float fOriginY, CSize sizeAspectRatio = odg_sizeDefaultAspectRatio)

Rotates the component about a point.

virtual BOOL  ValidateRotate(int& nAngle, float& fOriginX, float& fOriginY, const CSize& sizeAspectRatio = odg_sizeDefaultAspectRatio) const

Determines if the component can be scaled to the given ratios.

virtual void  Scale(float fScaleX, float fScaleY, float fOriginX, float fOriginY)

Scales the component in reference to a point.

virtual void  Scale(const CSize& szBounds, const OD_CONTROL_POINT nControlPoint = OD_CENTER)

Scales the component about its center to the size specified.

virtual BOOL  ValidateScale(float& fScaleX, float& fScaleY, float& fOriginX, float& fOriginY) const

Determines if the component can be scaled to the given ratios.

virtual void  MoveTo(CPoint point)

Moves the component so its top left corner is at the specified point.

virtual void  MoveTo(const CRect& rcPosition)

Moves and scales the component so that its bounds match the given rectangle.

virtual void  CenterOnPoint(CPoint point)

Centers the component on the point.

static CODTransformStack*  GetTransformStack()

Get a pointer to the transform stack

virtual void  PushTransform()

Push this component's transform onto the transform stack

virtual void  PopTransform()

Pop the transform stack.

void  PushParentTransforms()

Push the transforms of this component's parents onto the stack.

void  PopParentTransforms()

Pop the stack once for each of this component's parents.

void  ConcatParentTransforms(CODTransform& transformRes) const

Concatenate the transforms of this component's parents into a single transform

void  ConcatAllTransforms(CODTransform& transformRes) const

Concatenate this component's transform with its parents transforms

virtual CODComponentPosition*  GetPosition()

Returns the current position and size of the component as an object.

virtual BOOL  SetPosition(CODComponentPosition* pCompPos)

Restores the position and size of the component to a previously saved state.

virtual int  GetTranslateSet(CODComponentSet& setComponents)

Return a list of components to be translated along with this component.

virtual int  GetRotateSet(CODComponentSet& setComponents)

Return a list of components to be rotated along with this component.

virtual int  GetScaleSet(CODComponentSet& setComponents)

Return a list of components to be scaled along with this component.

Measurement and conversion

virtual void  CalculateLogicalUnits(CDC* pDC)

Convert any real-world measurements, such as points, to logical units using the given device context.

Vertex and control point methods

virtual CPoint  GetControlPoint(OD_CONTROL_POINT nControlPoint) const

Gets one of the control points of the component.

virtual void  GetControlPoint(OD_CONTROL_POINT nControlPoint, float& fControlX, float& fControlY) const

Gets one of the control points of the component.

virtual CPoint  GetAlignmentPoint(OD_CONTROL_POINT nAlignPoint)

Gets one of the alignment points of the component.

virtual void  GetAlignmentPoint(OD_CONTROL_POINT nAlignPoint, float& fAlignX, float& fAlignY) const

Gets one of the alignment points of the component.

virtual void  GetHandles(CODPointArray* pHandleArray, BOOL bVertexHandles = FALSE)

Gets the center points of the control handles.

virtual CPoint  GetHandle(int nIndex, BOOL bVertexHandles = FALSE)

Gets the center points of one handle.

virtual void  GetVertices(CODPointArray* pVertexArray, BOOL bTracking = FALSE)

Gets the vertices for the component.

virtual BOOL  CanInsertVertex()

Determines if points can be inserted to the component.

virtual BOOL  CanDeleteVertex()

Determines if points can be removed from the component.

Drawing

virtual void  Draw(CDC* pDC)

Draws the component to a device context.

virtual void  Track(CDC* pDC)

Draws tracking outline of the component to a device context.

BOOL  IsTracking() const

Determine if the component is currently being drawn in tracking mode.

void  SetTracking(const BOOL bTracking)

Enable or disable tracking mode for the component.

BOOL  IsVisible() const

Indicates if component is visible or not.

void  SetVisible(const BOOL bVisible)

Sets a flag that indicates if the component is visible or not.

virtual void  OnPrepareDC(CDC* pDC)

Creates GDI objects and sets up the device context for drawing.

virtual void  OnDraw(CDC* pDC)

Does the actual drawing of the component.

virtual void  OnCleanupDC(CDC* pDC)

Frees GDI objects and restores the state of the device context.

Hit Testing

BOOL  ContainsPointEx(const CPoint& pt) const

Does the bounding rectangle of this component contain the specified point? This version augments the one implemented in MvcVisualComponent by taking into account the fact that the width or height of a component may be zero (i.e. a line).

BOOL  IntersectsEx(const CRect& rc) const

Does the bounding rectangle of this component overlap the specified rectangle? This version augments the one implemented in MvcVisualComponent by taking into account the fact that the width or height of a component may be zero (i.e. a line).

int  GetComponentsAt(const CPoint& pt, CODComponentSet& setComponents)

Return a list of all child components at the given point

int  GetComponentsWithin(CRect rcHit, CODComponentSet& setComponents)

Gets set of components contained within the specified rectangle

int  GetComponentsIntersecting(CRect rcHit, CODComponentSet& setComponents)

Gets set of components whose bounding rectangles intersect the specified rectangle

virtual int  GetComponentsHit(const CPoint& pt, CODComponentSet& setComponents, int nPadding = 0)

Return a list of all child components at the given point

virtual int  GetContainerSet(CODComponentSet& setComponents)

Return a list of components contained by this component.

Region and bounding rectangle methods

virtual const CODRgn&  GetRgn() const

Gets the region of the component.

virtual CODRgn  GetEdgeRgn()

Returns a region surrounding the edges of the component.

virtual CODRgn  UpdateRgn(const BOOL bNotifyParents = FALSE)

Update the region data and bounding rectangle based on current points, transforms, or any other criteria.

virtual void  CalculateRgn(CODRgn* pRgn)

Calculate the region occupied by the component.

virtual void  OnChildRgnUpdate(CODComponent* pComp)

Called by the framework to notify a parent that a child region has changed.

virtual const CODRgn&  DoRgnUpdate()

Performs the work of updating the region of the component and its children.

virtual const CODRgn&  GetBaseRgn() const

Return a reference to the base region object.

virtual CPoint  ValidatePosition(const CRect& rcIn) const

Determines if the position of the given bounding rectangle is valid.

virtual CSize  ValidateSize(const CRect& rcIn) const

Determines if the size of the given bounding rectangle is valid.

CRect  GetOldBounds() const

Gets the previous bounding rectangle of the component.

void  SetOldBounds(const CRect rcBounds)

Sets the previous bounding rectangle of the component.

CRect  GetAlignRect() const

Gets the alignment rectangle of the component.

virtual CRect  CalculateAlignRect()

Calculates the aligment rectangle of the component.

Input focus

virtual BOOL  SetFocus()

Set input focus to this component.

Callbacks

virtual void  OnAdd(CODComponent* pParent)

Called by the framework when the component is added to a parent.

virtual void  OnRemove(CODComponent* pParent)

Called by the framework when the component is removed from its parent.

virtual void  OnAddChild(CODComponent* pChild)

Called by the framework when a child is added to this component.

virtual void  OnRemoveChild(CODComponent* pChild)

Called by the framework when a child is removed from this component.

virtual void  OnMove()

Called by the framework when the component changes position.

virtual BOOL  OnDoubleClick()

Called by the framework when the component is double-clicked.

virtual void  OnGroup(CODComponent* pGroup)

Called by the framework when the component is added to a group.

virtual void  OnUngroup(CODComponent* pGroup)

Called by the framework when the component is removed from a group.

Serialization

virtual void  Serialize(CArchive& ar)

Serialize the component.

User data methods

CObject*  GetUserData()

Returns pointer to user assigned data object.

void  SetUserData(CObject* pUserData)

Assigns pointer to user data object.

Debug drawing methods

virtual void  DrawBounds(CDC* pDC)

Draw the bounds of the component.

virtual void  DrawRgn(CDC* pDC)

Draw the region of the component.

virtual void  DrawVertices(CDC* pDC)

Draw the vertices of the component.

virtual void  TrackBounds(CDC* pDC)

Draw bounds of component in tracking mode.

virtual void  TrackRgn(CDC* pDC)

Draw region points in tracking mode.

virtual void  TrackVertices(CDC* pDC)

Draw vertices in tracking mode.