MvcPresentationModel_T Class
class MvcPresentationModel_T: public MvcModel, public IMvcVirtualPart, public IMvcUndoRedo
A presentation model is a kind of model that models a presentation. Broadly speaking, there are two types of models:
o System Models
o Presentation Models.
A system model is an MvcModel-derived class that models some non-graphical, real-world system or process. A presentation model models a graphical presentation. System and presentation models can be used exclusively or in combination. Used in combination, a presentation model provides the presentation for a system model, essentially mapping the system into the graphical realm.
A presentation model is a templatized class, which multiply inherits from both MvcModel and MvcVisualPart. The use of multiple inheritance here allows the presentation model to function as both a model and a visual - in effect, a visual model. A good example of where this idea is useful is in the implementation of a diagramming application. It is very natural to implement a diagram class as a presentation model. A diagram would be a kind of presentation model, which manages the graphical symbol data, font choices, pen widths etc. Like a model, it manages data, albeit graphical data, and exports functionality. But, like a visual part, a diagram can draw itself and even be nested as a symbol inside a parent diagram. Therefore, a diagram is both a model and a visual part.
You may be thinking, "if a presentation model can draw itself, what is the viewport left to do?" Actually, the viewport is offloaded to some degree, but it still has a well-defined role. When using a presentation model, a viewport becomes a gateway for a presentation model to render itself through. In other words, the viewport becomes a perspective on the presentation, defining what subregion of the overall presentation (or diagram) to display. The presentation model is essentially a graphics server, serving up whatever rectangular portion of the graphics the viewport instructs it to paint. This rectangle is measured in logical units and corresponds to the zoom factor and scroll positions of the viewport.
The presentation model is also an IMvcVirtualPart which means your viewports can receive to types of change notifications from their presentation model: change notifications and invalidate reqests. If you want to use this technique, your viewports should register themselves as renders of the presentation model. When the presentation model changes the graphics it is serving, the viewports will be told directly by the presentation model to invalidate themselves. The presentation model notifies each render of what rectangle in logical coordinates has been invalidated. How does the virtual part send this rectangle? By simply calling InvalidateRect(), which then broadcasts the invalidate call to all renders.
It is the responsibility of the viewport renderer to figure out where that logical rectangle is on its display surface and (if it is currently showing the invalid region) to perform a true windows invalidation.
This technique is very convenient. It allows the presentation model to draw and erase within its own virtual space using its own logical units, blissfully ignorant of how the graphics it produces get mapped onto a device.
Defined in: MvcPresentationModel.h
Class Members
virtual BOOL IsModified() const
Tests whether the presentation model has been modified
virtual stingray::foundation::MvcTransactionModel* GetTransactionModel()
Accessor for the transaction model associated with this model
virtual void SetTransactionModel(stingray::foundation::MvcTransactionModel* pTransModel)
Set for the transaction model associated with this model
virtual BOOL Do(CMvcCommand* pCmd)
Execute and log a command
virtual CMvcCommand* Undo()
Undo a command
virtual CMvcCommand* Redo()
Redo a command
virtual CMvcCommand* PeekUndo()
Get the next command on the undo stack
virtual CMvcCommand* PeekRedo()
Get the next command on the undo stack
virtual CMvcCommand* PeekUndo(int)
Get the Undo command with specified index
virtual CMvcCommand* PeekRedo(int)
Get the Redo command with specified index
MvcCommand* PopUndo()
Pop the Undo command from stack
MvcCommand* PopRedo()
Pop the Redo command from stack
void PushUndo(MvcCommand* pCmd)
Push the Undo command into stack
void PushRedo(MvcCommand* pCmd)
Push the Redo command into stack
int GetUndoCommandsCount() const
Get the Undo commands count
int GetRedoCommandsCount() const
Get the Redo commands count
virtual void AddRendering(stingray::foundation::MvcVisualPart* pVisualPart)
Adds a visual part to the list of renderers of this presentation model.
virtual void RemoveRendering(stingray::foundation::MvcVisualPart* pVisualPart)
The visual part identified by the argument is removed from this virtual part's list of renderers.
virtual void InvalidateRect(const CRect& rcLog, BOOL bErase = TRUE, BOOL bRepairNow = FALSE)
Invalidate the specified logical rectangle within this virtual part. The invalidation will be broadcasted to all renderers.