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

VIEWS_API CODComponent()

Constructor.

VIEWS_API CODComponent(const CODComponent& src)

Copy constructor.

VIEWS_API virtual ~CODComponent()

Destructor.

VIEWS_API BOOL Create(UINT nID)

Creates the component and initializes the data members.

VIEWS_API BOOL Create(CODComponentSet* pCompSet)

Creates the component out of a list of visual components.

VIEWS_API BOOL InitTypeAndName(UINT nID)

Initializes the type and name strings of the component.

VIEWS_API CODComponent& operator=(const CODComponent& src)

Assignment operator.

VIEWS_API 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.

VIEWS_API static CThreadLocal<CODTransformStack> m_transformStack

Transformation stack.

CODComponent* m_pParent

Pointer to component's parent

CODComponentSet m_setComponents

List of child components

CList<CODPropPtr,CODPropPtr> m_listProperties

List of component properties.

CObject* m_pUserData

Hook for user data object.

ULONG m_ulRefCount

Reference count value.

VIEWS_API virtual ULONG STDMETHODCALLTYPE AddRef()

Add a reference to this object.

VIEWS_API virtual ULONG STDMETHODCALLTYPE Release()

Release a reference to this object.

Identification methods

VIEWS_API ODComponentId GetID() const

Get the ID of the component.

VIEWS_API void SetID(const ODComponentId lID)

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

VIEWS_API virtual IUnknown* GetAxControl()

Get a pointer to the IUnknown for an ActiveX control component

VIEWS_API virtual IODIdGenerator* GetIdGenerator()

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

VIEWS_API virtual ODComponentId RegisterID(IODIdGenerator* pIIdGenerator)

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

VIEWS_API virtual BOOL UnregisterID(IODIdGenerator* pIIdGenerator)

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

VIEWS_API CString GetType() const

Get the type of the component.

VIEWS_API void SetType(const CString strType)

Set the type of the component.

VIEWS_API CString GetName() const

Get the name of the component.

VIEWS_API virtual void SetName(const CString strName)

Set the name of the component.

Z-Order methods

VIEWS_API int GetZOrder() const

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

VIEWS_API void SetZOrder(const int nZOrder)

Sets the z-order of this component.

VIEWS_API void UpdateZOrder(int nIndex)

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

VIEWS_API void ZOrderSort(CODComponentSet* pCompSet)

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

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

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

VIEWS_API virtual CODBspTree* GetBspTree()

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

VIEWS_API virtual CODBspTree* GetParentBspTree()

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

Composite methods

VIEWS_API virtual CODComponentSet* GetComponents()

Return a pointer to the list of child components.

VIEWS_API virtual int GetChildCount() const

Return number of children in the composite.

VIEWS_API virtual void SetParent(CODComponent* pParent)

Set the parent of this component.

VIEWS_API virtual CODComponent* GetParent() const

Return a pointer to the parent of this component.

VIEWS_API virtual int LocateChild(CODComponent* pChild) const

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

VIEWS_API virtual CODComponent* GetChild(const int nIndex) const

Return a pointer to a child given the collection index.

VIEWS_API virtual BOOL AppendChild(CODComponent* pChild)

Add a child to the end of the collection.

VIEWS_API virtual BOOL AppendChildren(CODComponentSet* pCompSet)

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

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

Insert a child into the composite at a given position.

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

Insert a child into the composite at a given position.

VIEWS_API virtual BOOL RemoveChild(const int nIndex)

Remove a child from the composite.

VIEWS_API BOOL RemoveChild(CODComponent* pChild)

Remove a child from the composite.

VIEWS_API void RemoveChildren(CODComponentSet* pCompSet)

Remove a list of children from the composite.

VIEWS_API void RemoveAllChildren()

Remove all children from the composite.

VIEWS_API virtual BOOL IsChild(CODComponent* pComp) const

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

VIEWS_API CODComponent* LocateParent(CODComponent* pChild)

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

VIEWS_API virtual void InitChildProperties(CODComponent* pChild)

Parent has a chance to initialize properties for new children.

VIEWS_API virtual BOOL GroupCompatible(CODComponentSet* pCompSet) const

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

Property methods

VIEWS_API virtual int GetPropertyCount() const

Get the number of properties in the container.

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

Get the property using an index into the container.

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

Get a property value using the property ID.

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

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

VIEWS_API 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.

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

Set a property value using the property ID.

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

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

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

Return a pointer to the specified property.

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

Return a copy of the specified property.

VIEWS_API virtual void SetProperty(CODProperty* pProperty)

Set the specified property.

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

Changes the specified property.

VIEWS_API virtual BOOL AddProperty(CODProperty& prop)

Add the specified property.

VIEWS_API virtual BOOL UpdateProperty(CODProperty& prop)

Updates the specified property.

VIEWS_API virtual BOOL RemoveProperty(const int nPropId)

Remove the specified property.

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

Return a copy of the specified property.

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

Gets the value of the given string property.

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

Gets the value of the given integer property.

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

Gets the value of the given unsigned integer property.

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

Gets the value of the given DWORD property.

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

Gets the value of the given float property.

VIEWS_API virtual BOOL SetValue(const int nPropId, LPCTSTR lpszValue)

Sets the value of the given string property.

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

Sets the value of the given integer property.

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

Sets the value of the given unsigned integer property.

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

Sets the value of the given unsigned DWORD property.

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

Sets the value of the given float property.

VIEWS_API virtual IODPropertyContainer* GetAmbientPropertyContainer() const

Return a pointer to the ambient property container.

VIEWS_API virtual void OnPropertyChange(const CODProperty& prop)

Called when a property is changed.

VIEWS_API virtual void OnAmbientPropertyChange(const int nPropId)

Called when an ambient property is changed.

VIEWS_API virtual void AssignDefaultProperties(CODPropertySet* pDefaults = NULL)

Assign default properties.

VIEWS_API void CacheProperties()

Update property cache and eliminate duplicates.

VIEWS_API static BOOL IsSetEditable(CODComponentSet* pCompSet)

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

Transformation and movement methods

VIEWS_API virtual CPoint SetOrigin(int x, int y)

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

VIEWS_API virtual CPoint OffsetOrigin(int xOff, int yOff)

Offset the origin of this component by specified deltas

VIEWS_API virtual CPoint MoveOrigin(int xOff,int yOff)

Move the origin of this component by specified deltas

VIEWS_API virtual CODTransform* GetTransform()

Return the transformation matrix for this component.

VIEWS_API void GetTransform(CODTransform& xForm)

Return the transformation matrix for this component.

VIEWS_API virtual void SetTransform(CODTransform* pXform)

Set the transformation matrix for this component.

VIEWS_API void SetTransform(const CODTransform& xForm)

Set the transformation matrix for this component.

VIEWS_API virtual void Translate(int nOffsetX, int nOffsetY)

Moves the component by an offset.

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

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

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

Rotates the component about a point.

VIEWS_API 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.

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

Scales the component in reference to a point.

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

Scales the component about its center to the size specified.

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

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

VIEWS_API virtual void MoveTo(CPoint point)

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

VIEWS_API virtual void MoveTo(const CRect& rcPosition)

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

VIEWS_API virtual void CenterOnPoint(CPoint point)

Centers the component on the point.

VIEWS_API static CODTransformStack* GetTransformStack()

Get a pointer to the transform stack

VIEWS_API virtual void PushTransform()

Push this component's transform onto the transform stack

VIEWS_API virtual void PopTransform()

Pop the transform stack.

VIEWS_API void PushParentTransforms()

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

VIEWS_API void PopParentTransforms()

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

VIEWS_API void ConcatParentTransforms(CODTransform& transformRes) const

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

VIEWS_API void ConcatAllTransforms(CODTransform& transformRes) const

Concatenate this component's transform with its parents transforms

VIEWS_API virtual CODComponentPosition* GetPosition()

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

VIEWS_API virtual BOOL SetPosition(CODComponentPosition* pCompPos)

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

VIEWS_API virtual int GetTranslateSet(CODComponentSet& setComponents)

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

VIEWS_API virtual int GetRotateSet(CODComponentSet& setComponents)

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

VIEWS_API virtual int GetScaleSet(CODComponentSet& setComponents)

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

Measurement and conversion

VIEWS_API 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

VIEWS_API virtual CPoint GetControlPoint(OD_CONTROL_POINT nControlPoint) const

Gets one of the control points of the component.

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

Gets one of the control points of the component.

VIEWS_API virtual CPoint GetAlignmentPoint(OD_CONTROL_POINT nAlignPoint)

Gets one of the alignment points of the component.

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

Gets one of the alignment points of the component.

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

Gets the center points of the control handles.

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

Gets the center points of one handle.

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

Gets the vertices for the component.

VIEWS_API virtual BOOL CanInsertVertex()

Determines if points can be inserted to the component.

VIEWS_API virtual BOOL CanDeleteVertex()

Determines if points can be removed from the component.

Drawing

VIEWS_API virtual void Draw(CDC* pDC)

Draws the component to a device context.

VIEWS_API virtual void Track(CDC* pDC)

Draws tracking outline of the component to a device context.

VIEWS_API BOOL IsTracking() const

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

VIEWS_API void SetTracking(const BOOL bTracking)

Enable or disable tracking mode for the component.

VIEWS_API BOOL IsVisible() const

Indicates if component is visible or not.

VIEWS_API void SetVisible(const BOOL bVisible)

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

VIEWS_API virtual void OnPrepareDC(CDC* pDC)

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

VIEWS_API virtual void OnDraw(CDC* pDC)

Does the actual drawing of the component.

VIEWS_API virtual void OnCleanupDC(CDC* pDC)

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

Hit Testing

VIEWS_API 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).

VIEWS_API 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).

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

Return a list of all child components at the given point

VIEWS_API int GetComponentsWithin(CRect rcHit, CODComponentSet& setComponents)

Gets set of components contained within the specified rectangle

VIEWS_API int GetComponentsIntersecting(CRect rcHit, CODComponentSet& setComponents)

Gets set of components whose bounding rectangles intersect the specified rectangle

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

Return a list of all child components at the given point

VIEWS_API virtual int GetContainerSet(CODComponentSet& setComponents)

Return a list of components contained by this component.

Region and bounding rectangle methods

VIEWS_API virtual const CODRgn& GetRgn() const

Gets the region of the component.

VIEWS_API virtual CODRgn GetEdgeRgn()

Returns a region surrounding the edges of the component.

VIEWS_API virtual CODRgn UpdateRgn(const BOOL bNotifyParents = FALSE)

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

VIEWS_API virtual void CalculateRgn(CODRgn* pRgn)

Calculate the region occupied by the component.

VIEWS_API virtual void OnChildRgnUpdate(CODComponent* pComp)

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

VIEWS_API virtual const CODRgn& DoRgnUpdate()

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

VIEWS_API virtual const CODRgn& GetBaseRgn() const

Return a reference to the base region object.

VIEWS_API virtual CPoint ValidatePosition(const CRect& rcIn) const

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

VIEWS_API virtual CSize ValidateSize(const CRect& rcIn) const

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

VIEWS_API CRect GetOldBounds() const

Gets the previous bounding rectangle of the component.

VIEWS_API void SetOldBounds(const CRect rcBounds)

Sets the previous bounding rectangle of the component.

CRect GetAlignRect() const

Gets the alignment rectangle of the component.

VIEWS_API virtual CRect CalculateAlignRect()

Calculates the aligment rectangle of the component.

Input focus

VIEWS_API virtual BOOL SetFocus()

Set input focus to this component.

Callbacks

VIEWS_API virtual void OnAdd(CODComponent* pParent)

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

VIEWS_API virtual void OnRemove(CODComponent* pParent)

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

VIEWS_API virtual void OnAddChild(CODComponent* pChild)

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

VIEWS_API virtual void OnRemoveChild(CODComponent* pChild)

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

VIEWS_API virtual void OnMove()

Called by the framework when the component changes position.

VIEWS_API virtual BOOL OnDoubleClick()

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

VIEWS_API virtual void OnGroup(CODComponent* pGroup)

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

VIEWS_API virtual void OnUngroup(CODComponent* pGroup)

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

Serialization

VIEWS_API virtual void Serialize(CArchive& ar)

Serialize the component.

User data methods

CObject* GetUserData()

Returns pointer to user assigned data object.

VIEWS_API void SetUserData(CObject* pUserData)

Assigns pointer to user data object.

Debug drawing methods

VIEWS_API virtual void DrawBounds(CDC* pDC)

Draw the bounds of the component.

VIEWS_API virtual void DrawRgn(CDC* pDC)

Draw the region of the component.

VIEWS_API virtual void DrawVertices(CDC* pDC)

Draw the vertices of the component.

VIEWS_API virtual void TrackBounds(CDC* pDC)

Draw bounds of component in tracking mode.

VIEWS_API virtual void TrackRgn(CDC* pDC)

Draw region points in tracking mode.

VIEWS_API virtual void TrackVertices(CDC* pDC)

Draw vertices in tracking mode.