CODViewport Class
class CODViewport: public MvcViewport
The viewport renders the model to an area of a window. The viewport takes care of preparing a device context for rendering in the OnPrepareDC method. The Draw method performs the rendering to a device context. The viewport contains various other helper methods that draw different aspects of the view, such as the grid, selection handles, page boundaries, and background.The viewport contains mapping mode and extent ratio information that allow it uses to prepare the device context. The mapping mode and extents are used to map logical coordinates to device coordinates. The viewport also contains a CODRuler object that uses the coordinate mapping information to provide methods for converting to and from real-world measurements and logical units.
Defined in: OdViewport.h
Class Members
Constructors & Destructor
Constructor.
virtual ~CODViewport()
Destructor.
Attributes
BOOL m_bAngleSnap
Angle snap.
BOOL m_bSnapToGrid
Snap to grid.
BOOL m_bGridVisible
Grid is visible.
CODMeasure m_gridSpacingX
Horizontal grid spacing.
CODMeasure m_gridSpacingY
Vertical grid spacing.
COLORREF m_crGridColor
Grid color.
OD_SELECTION_MODE m_selectionMode
Current viewport rubber-band selection mode.
BOOL m_bPagesVisible
Indicates if page boundaries are visible.
int m_nPadding
Padding to go around lines for selection.
CSize m_sizeHandles
Size of the control and vertex handles.
int m_nZoomMin
Minimum zoom percentage
int m_nZoomMax
Maximum zoom percentage
int m_nZoomIncrement
Percentage to zoom in or out.
int m_nNumPreviewPages
Maximum extent used for printing/scaling.
CSize m_szOldExtent
Previous extents for x and y values, so we can keep track over MFC print calls.
CODPropertySet m_setDefProperties
Default property set
CPoint m_ptPasteInsPoint
Paste insertion point.
CSize m_szPageDimensions
Page dimensions in logical units.
CODRuler* m_pRuler
Pointer to ruler object for this viewport.
sfl::YAxisDirection m_YAxisDirection
Enum representing desired direction of positive Y-Axis
BOOL m_bPrintCurView
Print the currently zoomed view. i.e. what is displayed on screen.
BOOL m_bPrintXByYPages
Print content to X by Y pages.
BOOL m_bPrintMaintainAspectRatio
Maintain the aspect ratio when printing X by Y pages.
CSize m_szMag
Viewport Magnification
Initialization
virtual void OnInitialUpdate()
Initializes the viewport.
virtual BOOL CreateController()
Creates the controller that works with this viewport.
Attribute Access
virtual BOOL CreateChildWnd(CODWndComponent* pWndComp)
Creates the window component as a child of the viewport's owner window.
virtual BOOL DestroyChildWnd(CODWndComponent* pWndComp)
Destroys the window of a windowed component
virtual BOOL CreateChildrenWnds(CODComponent* pComp)
Creates the window components as children of the viewport's owner window for the all windowed components in a brunch from the given component
virtual BOOL DestroyChildrenWnds(CODComponent* pComp)
Destroys the window components for the all windowed components in a brunch from the given component
Attribute Access
CODModel* GetCanvasModel()
Returns the pointer to the model this viewport is observing.
CODController* GetCanvasCtlr()
Returns the controller that handles user interaction for this viewport.
CODModel* GetModel()
Returns the pointer to the model this viewport is observing.
CODController* GetCtlr()
Returns the controller that handles user interaction for this viewport.
CODRuler* GetRuler()
Return a pointer to the ruler.
BOOL GetAngleSnap() const
Returns TRUE if angle snap is on.
void SetAngleSnap(BOOL bAngleSnap)
Sets angle snap on or off.
Size and position
void CenterOnComponents(CODComponentSet* pCompSet)
Centers the viewport on a set of components.
virtual BOOL SizeToModel()
Changes the viewport size to match the size of the model.
virtual BOOL PageIsBlank(int nPageIndex)
Determines if a diagram page is blank
virtual CRect GetHiMetricBounds() const
Returns bounding rectangle in MM_HIMETRIC units.
virtual CSize GetAspectRatio()
Determines the aspect ratio of the viewport.
Grid Management
BOOL GetGridVisible() const
Returns TRUE if the grid is visible.
void SetGridVisible(BOOL bGridVisible)
Sets whether the grid is visible.
BOOL GetSnapToGrid() const
Returns TRUE if snap to grid is on.
void SetSnapToGrid(BOOL bSnapToGrid)
Set snap to grid on or off.
void GetHorizontalGridSpacing(float& fGridSpacingX) const
Gets the horizontal grid spacing.
const CODMeasure& GetHorizontalGridSpacing() const
Gets the horizontal grid spacing.
void SetHorizontalGridSpacing(float fGridSpacingX)
Sets the horizontal grid spacing.
void SetHorizontalGridSpacing(const CODMeasure& gridSpacingX)
Sets the horizontal grid spacing.
void GetVerticalGridSpacing(float& fGridSpacingY) const
Gets the vertical grid spacing.
const CODMeasure& GetVerticalGridSpacing() const
Gets the vertical grid spacing.
void SetVerticalGridSpacing(float fGridSpacingY)
Sets the vertical grid spacing.
void SetVerticalGridSpacing(const CODMeasure& gridSpacingY)
Sets the vertical grid spacing.
virtual CODMeasure GetMinGridSpacing() const
Return minimum logical grid spacing value.
virtual CODMeasure GetMaxGridSpacing() const
Return maximum logical grid spacing value.
virtual CSize GetMinGridPelSpacing() const
Return the minimum grid spacing in pixels.
virtual CSize GetMaxGridPelSpacing() const
Return the minimum grid spacing in pixels.
COLORREF GetGridColor()
Gets the color of the grid.
void SetGridColor(COLORREF crGridColor)
Sets the color of the grid.
CPoint FindClosestGridPoint(CPoint point)
Finds the closest grid point to the point passed in.
Component Selection
OD_SELECTION_MODE GetSelectionMode() const
Gets the current viewport rubber-band selection mode.
void SetSelectionMode(OD_SELECTION_MODE selectionMode)
Sets the current viewport rubber-band selection mode.
virtual void CreateHandlePolygon(CPoint ptHandle, LPPOINT lpPolygon)
Creates a polygon that represents a control handle.
virtual CRect CreateHandleRect(CPoint ptHandle)
Creates a rectangle that represents a control handle.
virtual void DrawHandles(CDC* pDC, CODComponentSet* pCompSet, CODComponent* pAnchor, const CRect &rcUpdate)
Draw the control handles for a list of components.
virtual void UpdateSelection(CODComponentSet* pCompSet)
Called when the set of selected components changes.
CPoint GetPasteInsertionPoint() const
Gets paste insertion point (point at which components are inserted when paste command issued.
void SetPasteInsertionPoint(CPoint ptPasteInsPoint)
Sets paste insertion point (point at which components are inserted when paste command issued.
Default Properties
CODPropertySet* GetDefProperties()
Gets pointer to viewport's set of default properties.
void SetDefProperties(CODPropertySet* pDefProperties)
Sets viewport's default properties.
void InitCompProperties(CODComponent* pComp)
Initializes a component with the viewport's default set of properties.
void InitCompProperties(CODComponentSet* pCompSet)
Initializes a set of components with the viewport's default set of properties.
Unit Conversion
int PointsToLog(const int nPoints, BOOL bVertical = TRUE)
Converts points to logical units.
int LogToPoints(const int nLog, BOOL bVertical = TRUE)
Converts logical units to points.
float PointsToInches(int nPoints, BOOL bWidth)
Converts pixels to inches.
int InchesToPoints(float fInches, BOOL bWidth)
Converts inches to pixels.
Rendering
virtual void PrepareDC(CDC* pDC, const BOOL bEnableZooming = TRUE)
Readies the device context for subsequent rendering or logical to device coordinate mapping.
virtual void CalculateLogicalUnits(CDC* pDC)
Convert any real-world measurements, such as points, to logical units using the given device context.
virtual void Draw(CDC* pDC)
Draw the viewport to a device context.
virtual void DrawRect(CDC* pDC, const CRect& rcUpdate)
Draw a rectangular area of the viewport to a device context.
virtual void DrawComponents(CDC* pDC, CODComponentSet* pCompSet = NULL)
Draws a set of components onto a given device context.
virtual void DrawGrid(CDC* pDC, const CRect &rcUpdate)
Draws the grid.
virtual void DrawAxes(CDC* pDC, const CRect &rcUpdate)
Draws the X and Y axes.
virtual void DrawBkgndComponent(CDC* pDC, const CRect &rcUpdate)
Draws the background component.
virtual void DrawPageBounds(CDC* pDC, const CRect &rcUpdate)
Draw page boundaries
virtual void EraseBkgnd(CDC* pDC, const CRect& rcUpdate)
Erase the background with the background color.
void EraseBkgnd(CDC* pDC)
Erase the background with the background color.
virtual COLORREF GetOutOfBoundsColor() const
Get the color used to fill the area outside of the diagram
virtual void DrawMetafile(CDC* pDC)
Draw the viewport to a metafile device context.
virtual CMetaFileDC* CreateMetafile(CODComponentSet& setComponents)
Creates a metafile DC and draws the set of components into it.
virtual BOOL TrackMovement(CODComponentSetTracker* pSetTracker, int nOffsetX, int nOffsetY)
Draws the tracking for components that are being moved.
virtual void TrackRotation(CODComponentSetTracker* pSetTracker, int nAngle)
Draws the tracking for components that are being rotated.
virtual void TrackScaling(CODComponentSetTracker* pSetTracker, float fScaleX, float fScaleY, OD_CONTROL_POINT nControlPoint)
Draws the tracking for components that are being scaled.
virtual OD_MOVEVERTEX_RC TrackMovingVertex(CODComponentSetTracker* pSetTracker, int nVertexIndex, int nOffsetX, int nOffsetY)
Draws the tracking for a component whose vertex is being moved.
virtual void DrawTracking(CODComponentSetTracker* pSetTracker)
Draw tracking for a set of components.
virtual void EraseTracking(CODComponentSetTracker* pSetTracker)
Draw tracking for a set of components.
virtual void ClipToVirtualBounds(CRect& rcClip)
Clip the given rectangle to the virtual size of the viewport.
Invalidation
void UpdateAll()
Redraws the entire viewport.
virtual void UpdateComponents(CODComponentSet* pCompSet)
Draws the given components and invalidates their regions
virtual CRect DrawComponents(CODComponentSet* pCompSet)
Draws the given components
virtual void InvalidateComponents(CODComponentSet* pCompSet)
Invalidate the area occupied by the given set of components
Hit Testing
virtual CODComponent* ComponentHitTest(CPoint ptHit)
Returns a pointer to the topmost component that contains the point, or NULL if there is no component at the point.
virtual CODComponent* ControlHandleHitTest(CPoint ptHit, int& nHandleIndex)
Checks if one of the control handles of a selected component hit is at the point.
virtual CODComponent* EdgeHitTest(CPoint ptHit, int& nEdgeIndex)
Checks to see if a component's edges have been hit.
CODPortComponent* PortHitTest(CPoint ptHit, const int nSlop)
Returns a pointer to the topmost port that contains the point, or NULL if there is no port at the point.
Zooming
void ZoomIn(const CRect& rcZoom)
Zoom in on a given rectangle
void ZoomIn(CPoint ptDev)
Increase magnification by 25%
void ZoomOut(CPoint ptDev)
Decrease magnification by 25%
void GetZoomRange(int& nZoomMin, int& nZoomMax)
Get minimum and maximum zoom percentages
void SetZoomRange(int nZoomMin, int nZoomMax)
Sets the minimum and maximum zoom percentages
virtual CSize SetMagnification(const int nPctX, const int nPctY)
Set logical scaling as percent magnification
Pagination
BOOL GetPagesVisible() const
Returns TRUE if page boundaries are visible.
void SetPagesVisible(BOOL bPagesVisible)
Sets whether page boundaries are visible.
virtual void CalcPageDimensions()
Calculate the page dimensions in logical units based on page settings in the diagram model.
void GetPageDimensions(int& nPageWidth, int& nPageLength) const
Returns the page dimensions in logical units.
CSize GetPageDimensions() const
Returns the page dimensions in logical units.
int GetPageCount()
Returns the page count based on the diagram's page info.
CRect GetPageBounds(const int nPageNo)
Returns the page boundaries given a page number.
CRect GetPageBoundsNormal(const int nPageNo)
Internal - Returns page boundaries for normal printing.
CRect GetPageBoundsCurView(const int nPageNo)
Internal - Returns page boundaries for current view printing.
CRect GetPageMargins()
Returns the page margins.
File export
virtual BOOL WriteMetafile(CFile& outFile, LPCTSTR lpszDescription = NULL)
Writes contents of viewport to an enhanced metafile.
virtual BOOL DrawImage(sfl::SECImage* pImage, CDC* pDC = NULL)
Draws contents of viewport to an image.
Callbacks
virtual void OnUpdate(sfl::IMvcSubject* pSubject, sfl::IMvcMessage* pMsg)
Called when the model that this viewport observes is changed.
virtual void OnUpdateMappingMode()
Called when the mapping mode or extents are modified.
virtual void OnPrepareDC(CDC* pDC)
Readies the device context for subsequent rendering or logical to device coordinate mapping.
virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
Readies the device context for subsequent rendering or logical to device coordinate mapping.
Printing
virtual BOOL PreparePrinting(CPrintInfo* pInfo)
Prepares the diagram for printing.
virtual BOOL PreparePrinting(CPrintInfo* pInfo, long percentOfNorm)
Prepares the diagram for printing fit to xxx% normal size.
virtual BOOL PreparePrinting(CPrintInfo* pInfo, long percentOfNorm, CRect rcCurView)
Prepares the diagram for printing the current view and the current zoom.
virtual BOOL PreparePrinting(CPrintInfo* pInfo, long x_pages_wide, long y_pages_tall)
Prepares the diagram for printing fit to X page(s) wide by Y page(s) tall
virtual BOOL PreparePrinting(CPrintInfo* pInfo, long percentOfNorm, long x_pages_wide, long y_pages_tall, CRect rcCurView)
Prepares the diagram for printing fit to X page(s) wide by Y page(s) tall
virtual void Print(CDC* pDC, CPrintInfo* pInfo)
Prints the diagram.
virtual void EndPrinting(CDC* pDC, CPrintInfo* pInfo)
Cleanup when printing is finished.
Overrides
virtual void SetVirtualSize(int cx,int cy)
Set the total virtual size in logical units
virtual CSize GetVirtualSize() const
Get the total virtual size in logical units
virtual void SetVirtualOrigin(int x,int y)
Set the total virtual size in logical units
virtual CPoint GetVirtualOrigin() const
Get the location of the virtual origin in logical units.
virtual sfl::YAxisDirection GetYAxisDirection() const
Returns the direction of the positive Y axis
virtual void SetYAxisDirection(sfl::YAxisDirection direction)
Sets the direction of the positive Y Axis
virtual sfl::CEventFactory* GetEventFactory()
Returns a pointer to the event factory for this viewport.
inline virtual void SetIsPrintCurView(BOOL bPrintCurView)
Set whether or not the area to print will be the currently zoomed view.
inline virtual BOOL GetIsPrintCurView()
Returns TRUE or FALSE if the current area to print is the current zoomed view.
inline virtual void SetIsPrintXByYPages(BOOL bPrintXByYPages)
Enable printing X by Y pages.
inline virtual BOOL GetIsPrintXByYPages()
Is printing X by Y pages enabled?
inline virtual void SetIsPrintMaintainAspect(BOOL bMaintainAspectRatio)
Enable print with aspect ratio maintained.
inline virtual BOOL GetIsPrintMaintainAspect()
Is print with aspect ratio maintained enabled?
CRect CalcVisibleVpRect()
Calculate the visible portion of the viewport displayed on the screen. Returns a rect in logical units.