Click or drag to resize

IMcDisplayEditPasteAoi Method

Image data previously placed on the the clipboard is pasted into the ImageToDisplay.

Namespace:  MediaCy.IQL.Display.Viewer
Assembly:  MediaCy.IQL.Display.Viewer (in MediaCy.IQL.Display.Viewer.dll) Version: 10.0.6912.0
Syntax
VB
Sub EditPasteAoi ( 
	Optional OptionFlags As mcEditPasteAoiOptionFlags = mcEditPasteAoiOptionFlags.mcepaofUseSettings,
	<OptionalAttribute> AlignLeftTop As Object,
	Optional BlendPercent As Integer = -1,
	Optional BlendOptionFlags As mcViewBlendStyle = mcViewBlendStyle.mvbsUseSettings
)

Parameters

OptionFlags (Optional)
Type: MediaCy.IQL.Display.ViewermcEditPasteAoiOptionFlags
These flags (along with the BlendOptionFlags argument) control the technique used to merge an image the is in the clipboard with the ImageToDisplay. If the default value of mcepaofUseSettings is given, then values are determined from the settings saved by Application.CommandDialogs("Preferences").Pages("PasteOptions").
AlignLeftTop (Optional)
Type: SystemObject
If given, this is a LONGPOINT or an array of two numeric values (x,y) that gives the alignment between the clipboard image and the ImageToDisplay. It is given as the offset of the left,top of the clipboard image into the ImageToDisplay; the values may be positive or negative. When the paste is previewed (OptionFlags mcepaofPreviewThePaste flag is set) then this offset is used as the intial blending alignment for the preview, otherwise it is used as the final paste alignment. If the AlignLeftTop argument is not given, then it is set so that the left,top of the clipboard image AOI bounds is aligned with the left,top of the ImageToDisplay AOI bounds.
BlendPercent (Optional)
Type: SystemInt32
This value is used wherever a blending percentage is needed both during preview (OptionFlags mcepaofPreviewWithBlend flag is set) and/or during the apply of the paste (OptionFlags mcepaofApplyWithBlend flag is set). The BlendPercent specifies the percentage of the clipboard luminance that is to be blended into the ImageToDisplay; 100% is a full paste. If the default value of -1 is given, then the blend percentage is taken from the settings saved by Application.CommandDialogs("Preferences").Pages("PasteOptions").
BlendOptionFlags (Optional)
Type: MediaCy.IQL.Display.ViewermcViewBlendStyle
These blending flags are used wherever a blending is done both during preview (OptionFlags mcepaofPreviewWithBlend flag is set) and/or during the apply of the paste (OptionFlags mcepaofApplyWithBlend flag is set). However, whether or not the mcepaofPreviewWithBlend and/or mcepaofApplyWithBlend option flags are set, the BlendOptionFlags mvbsMaskBySourceAoi and/or mvbsMaskByDestAoi flags are always honored to determine if the blend/paste should be restricted to pixels interior to the source and/or destination AOI(s). If the default value of mvbsUseSettings is given, then the blend percentage is taken from the settings saved by Application.CommandDialogs("Preferences").Pages("PasteOptions").
Remarks
EditPasteAoi is a flexible and powerful tool for merging into the ImageToDisplay an image previously placed on the clipboard by EditCopy or EditCut. The method has arguments for options that reflect the settings saved by Application.CommandDialogs("Preferences").Pages("PasteOptions"). In fact the default behavior for the method is to use the options that were last set in the Preferences dialog (see Example 1). The operation is relatively straightforward when the mcepaofPreviewThePaste OptionFlags is not set (i.e., when no user preview of the paste is called for, see Example 2). In this case, the clipboard image is just blended into the ImageToDisplay at the given alignment with the given BlendingOptionFlags (the actual blending operation is performed with the MOpLib's McGeometry.Blend method; a 100% blend is a paste). Once the paste is complete, the the ImageToDisplay AOI is optionally changed based on the mcEditPasteAoiOptionFlags OptionFlags argument. Things are a bit more complex when the mcepaofPreviewThePaste OptionFlags is set (i.e., when a user preview of the paste is called for, see Example 3). In this case, the method starts the McOvrMgr McBlendTool on the ImageToDisplay.ImageToolsOverlay McGraphOverlay. The OwningView is made the working McView for the tool and then the EditPasteAoi method returns. The actual paste will not occur until the user presses the Enter key or double-clicks with the left mouse button to indicate that they have finished placing the image to be pasted. If the user presses the escape key or if some other tool is invoked, then no paste will ever occur. EditPasteAoi determines how the user ended the paste preview by monitoring the IMcGraphOverlayEvents.ToolDeselected event from the McBlendTool. In rare circumstances you may need to take over this monitoring job in order to do the paste yourself (e.g., if you wanted to push undo information. Or if you wanted to use the McGeometry.Blend mcBlendControlFlags mcbcfDoNotScaleSource flag, which EditPasteAoi does not set.). Setting the OptionFlags mcEditPasteAoiOptionFlags mcepaofDoNotApplyThePaste bit makes you responsible for monitoring the ToolDeselected event and doing the actual paste. Example 4 shows how this might be done.
Note Note
The pasted image data may have been previously placed there by a call to the EditCopy or EditCut methods, or it may be a new image created from a bitmap placed on the clipboard by some other application. If multiple image clipboard formats are available, their precedence is mcwcftMcImageAoi, mcwcftMcImageDisplayArea, mcwcftCF_DIB, mcwcftCF_BITMAP, and then mcwcftCF_ENHMETAFILE.
Examples
VB
'Example 1. Paste into the ActiveWindow using the default paste settings
If Not ThisApplication.ActiveWindow.View.Display.IsActionAvailable( mcwaMcImageToPaste) Then
MsgBox "There is no image on the clipboard"
Exit Sub
EndIf
ThisApplication.ActiveWindow.View.Display.EditPasteAoi
'Example 2. Paste the intersection of the source and destination AOI's
' into Images(0) without user preview.
Dim PasteOptionFlags As mcEditPasteAoiOptionFlags
PasteOptionFlags = mcepaofAoiAfter_IntersectSrcAndDest
' Use 100% blending
Dim BlendOptionFlags As mcViewBlendStyle
BlendOptionFlags = mvbsMaskBySourceAoi + mvbsMaskByDestAoi
'Use the default alignment (align src and dest AOI's)
Images(0).Display.EditPasteAoi PasteOptionFlags,,100,BlendOptionFlags
'Example 3. Paste the source AOI where the user places it during preview
' Use 50% blending during preview but apply the paste 100%
Dim PasteOptionFlags As mcEditPasteAoiOptionFlags
PasteOptionFlags = mcepaofPreviewThePaste + mcepaofPreviewWithBlend + mcepaofAoiAfter_PasteSrcAoi
' During blending and the paste, mask by the source AOI
Dim BlendOptionFlags As mcViewBlendStyle
BlendOptionFlags = mvbsMaskBySourceAoi
'Use the default starting alignment (align src and dest AOI's)
Images(0).Display.EditPasteAoi PasteOptionFlags,,50,BlendOptionFlags
'Example 4.  Handle the paste ourselves. This must be in a CLS or FRM module
Private WithEvents activeOverlay As McGraphOverlay
Private PasteOptions As mcEditPasteAoiOptionFlags
Private PasteBlendStyle As mcViewBlendStyle
Private lPasteBlendFactor As Long
' Sub to call to set up and start blend tracking for EditPasteAoi
Sub StartEditPasteAoi()
If ActiveWindow Is Nothing Then Exit Sub
If Not ThisApplication.ActiveWindow.View.Display.IsActionAvailable(mcwaMcImageToPaste) Then Exit Sub
' Get the PasteOptions, BlendingFactor and BlendingStyle
PasteOptions =  mcepaofPreviewThePaste + mcepaofPreviewWithBlend + mcepaofAoiAfter_PasteSrcAoi
lPasteBlendFactor = 50
PasteBlendStyle = mvbsMaskBySourceAoi
' Start the EditPasteAoi, without letting it apply the paste
ThisApplication.ActiveWindow.View.Display.EditPasteAoi _
PasteOptions + mcepaofDoNotApplyThePaste, , lPasteBlendFactor, PasteBlendStyle
Set activeOverlay = ThisApplication.ActiveImage.ImageToolsOverlay ' monitor the ToolDeselect event
' The final paste actions all occur in the activeOverlay_ToolDeselected sub, below
End Sub 'StartEditPasteAoi
' Event notification Sub to find out how the user ends the tool
Private Sub activeOverlay_ToolDeselected(ByVal Overlay As McGraphOverlay, _
ByVal Tool As Object, ByVal GraphObjClassName As String, ByVal TemplateID As Long)
Set activeOverlay = Nothing ' we won't need notifications any more
Dim activetool As McGraphToolServer
Set activetool = Overlay.activetool
If activetool.ToolClassName <> "McOvrMgr.McBlendTool" Then ' Sanity check
Debug.Print "Logic error: activeOverlay_ToolDeselected from some tool other than the McBlendTool."
Exit Sub
End If
' capture the shutdown mode CommandFlags before we stop blending (which changes them)
Dim lShutdownModeCommandFlags As Long
lShutdownModeCommandFlags = activetool.CommandFlags(mcbtcfEndBlend + mcbtcfAbortBlend) 'mask
Dim workingmcview As McView
activetool.CommandFlags = mcvtcfGetWorkingMcView
Set workingmcview = activetool.CommandData
If workingmcview Is Nothing Then
Debug.Print "Blend tool terminated before getting a working McView."
ThisApplication.ActiveWindow.View.Display.BlendingImage = Nothing   'Stop blending in the active window
Exit Sub
End If
'ELSE workingmcview is a real McView
'Stop blending in the working McView
workingmcview.Display.BlendingImage = Nothing
' Normal McBlendTool termination?
If lShutdownModeCommandFlags = mcbtcfEndBlend Then
'Normal preview end.  Get the BlendAlign last left by the user during preview
Dim Align As LONGPOINT
workingmcview.Display.GetBlendAlignLeftTop Align.x, Align.y
' Apply the paste without preview
Dim rectBlended As LONGRECT
rectBlended = workingmcview.Display.EditPasteAoiRectangle
' Check to see if there is no overlap to paste
If rectBlended.Left < rectBlended.Right Then    ' something will be pasted?
workingmcview.ImageToDisplay.UndoStack.Push workingmcview.ImageToDisplay, _
mciuofSaveActiveFrameRange, rectBlended, Empty, "My Paste"
Else ' no overlap, so nothing will be pasted
Debug.Print "Attempt to paste an empty target rectangle"
Exit Sub  ' In this case, we just bail out.
End If
Dim FinalPasteOptions As mcEditPasteAoiOptionFlags
FinalPasteOptions = PasteOptions And Not mcepaofPreviewThePaste
workingmcview.Display.EditPasteAoi FinalPasteOptions, _
varAlign, lPasteBlendFactor, PasteBlendStyle
' Abort McBlendTool termination?
ElseIf lShutdownModeCommandFlags = mcbtcfAbortBlend Then
Debug.Print "User aborted the Blend with the Esc key."
Else ' Some other McBlendTool Termination
Debug.Print "The Blend tool was stopped due to error or some other tool being invoked."
End If ' how McBlendTool terminates
End Sub 'activeOverlay_ToolDeselected event
See Also