'****************************************************************************
'* Copyright (C) 2008 Peter Mortensen and Matthias Mann *
'* This file is part of MSQuant. *
'* *
'* MSQuant is distributed under the terms of *
'* the GNU General Public License. See src/COPYING.TXT or *
'* <http://www.gnu.org/licenses/gpl.txt> for details. *
'* *
'* MSQuant is free software; you can redistribute it *
'* and/or modify it under the terms of the GNU *
'* General Public License as published by the Free *
'* Software Foundation; either version 2 of the *
'* License, or (at your option) any later version. *
'* *
'* MSQuant is distributed in the hope that it will be *
'* useful, but WITHOUT ANY WARRANTY; without even the *
'* implied warranty of MERCHANTABILITY or FITNESS FOR *
'* A PARTICULAR PURPOSE. See the GNU General Public *
'* License for more details. *
'* *
'* You should have received a copy of the GNU General *
'* Public License along with MSQuant; if not, write to *
'* the Free Software Foundation, Inc., 59 Temple *
'* Place, Suite 330, Boston, MA 02111-1307 USA *
'* *
'* Purpose: <to be filled in>. *
'* *
'****************************************************************************
'****************************************************************************
'* CEBI *
'* Software Development Group *
'* Peter Mortensen *
'* E-mail: NUKESPAMMERSdrmortensen@get2netZZZZZZ.dk *
'* WWW: http://www.cebi.sdu.dk/ *
'* *
'* Program for post-processing of result from search in mass *
'* spectrometric data. *
'* *
'* FILENAME: overlaySpectrumMarking.vb *
'* TYPE: VISUAL_BASIC *
'* *
'* CREATED: PM 2004-10-01 Vrs 1.0. Estimated date. *
'* UPDATED: PM 2008-xx-xx *
'* *
'****************************************************************************
Option Strict On
Option Explicit On
Imports massSpectrometryBase 'For ionTypeEnum.
Imports System.Text.RegularExpressions 'For Match
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Class overlaySpectrumMarking
Inherits SDUPspectrumMarking
Const DELETEDPOSITION_Y As Integer = 20007
Private mFarOff As Point '(2000,100)
Private mMarkersHeight As Integer
Protected mParentForm As Form 'Where the "Label"s live. We implement
' the overlay by using Labels both for lines (1 pixel wide Labels) and
' text (e.g. fragment ion names line "y8++").
Private mTooltipForExactMass As System.Windows.Forms.ToolTip
Private mMarkerFont As System.Drawing.Font
Private mMaxNumControls As Integer
Private mNewLabelCount As Integer
Private m_xOffsetForMarkers As Integer
Private m_xOffsetFromRightEdge As Integer
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Sub New( _
ByRef aParentForm As Form, _
ByRef anInOutTooltip As System.Windows.Forms.ToolTip)
mParentForm = aParentForm
mTooltipForExactMass = anInOutTooltip
m_xOffsetForMarkers = -1
m_xOffsetFromRightEdge = -1
mNewLabelCount = 0
mMaxNumControls = 0
mMarkerFont = New System.Drawing.Font( _
"Microsoft Sans Serif", 8.25!, _
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, _
CType(0, Byte))
End Sub 'Constructor.
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Sub init2( _
ByVal anIn_xOffsetForMarkers As Integer, _
ByVal anIn_xOffsetFromRightEdge As Integer, _
ByVal aMarkerYlevel As Integer, _
ByVal aMarkersHeight As Integer)
m_xOffsetForMarkers = anIn_xOffsetForMarkers
m_xOffsetFromRightEdge = anIn_xOffsetFromRightEdge
mFarOff.X = 2000
mFarOff.Y = aMarkerYlevel
mMarkersHeight = aMarkersHeight
End Sub 'init2
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Overrides Sub newXaxisPosition(ByVal aNewPixelXvalue As Integer)
m_xOffsetForMarkers = aNewPixelXvalue
End Sub 'newXaxisPosition
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Overrides Sub addIonMarker( _
ByVal anIon As fragmentExStructure, _
ByVal aMCRdelta As Double, _
ByVal aToken As Integer)
Dim ionType2 As ionTypeEnum = anIon.ionType
'Changed PM_FINNEGAN_LABELS 2004-05-04
Dim newMarker As markerStructure
newMarker.MCR = anIon.MCRcalcLoc
'Changed PM_REFACTOR 2005-01-26
'newMarker.Yion = .Yion
'newMarker.Bion = .Bion
newMarker.ionType3 = ionType2
'Changed PM_FRAGMENTS_EXTRAINFO 2005-08-18
'Changed PM_VS2005 2006-06-15
'Why can't this be in a block???
Dim extraStr As String = ""
If ionType2 <> ionTypeEnum.enumPrecursorIon2 Then
Dim seq2 As String = anIon.seq
If PILgeneralisedIonSeries.isForwardIon(ionType2) Then
Dim lastIndex As Integer = seq2.Length - 1
extraStr = ",+" & seq2.Substring(lastIndex)
Else
extraStr = ",+" & seq2.Substring(0, 1)
End If
End If
newMarker.moreDescription = extraStr
newMarker.labelDescription = anIon.descStr
newMarker.charge = anIon.charge
newMarker.tag = aToken.ToString
'Changed PM_FRAGMENTDISPLAY 2008-05-18
newMarker.matchingData = anIon.ionMatched
Dim yDisplayLevel As Integer = anIon.yDisplayLevel2 'E.g. 1 for double
' charged, 2 for b ions, 3 for y ions, 4 for matched ions.
If anIon.ionMatched Then
yDisplayLevel = anIon.yDisplayLevelForMatching2
End If
' 'This is policy: if the ion is matched (by data/peak) then we ignore
' ' the specification for the ion series and place those matched on
' ' the same/separate line.
' If anIon.ionMatched Then
' If anIon.yDisplayLevel = -1 Then '-1 due to the subtraction
' ' of 1 in computeFragments()...
' yDisplayLevel = 3 'E.g. matched b-98 and y-98
' Else
' yDisplayLevel = 4 'E.g. matched b and y
' End If
'
' 'This is to adopt to the subtraction of 1 in computeFragments()...
' yDisplayLevel -= 1
' End If
Me.addMarker2( _
newMarker, _
mMarkersHeight, _
False, _
Color.Empty, _
labelDirectionEnum.enumLineDown, _
0, _
yDisplayLevel)
End Sub 'addIonMarker
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Overrides Sub lastMarkerAdded(ByVal aHighestX As Double)
'Nothing for now..
End Sub 'lastMarkerAdded
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Overrides Sub addMarker2( _
ByRef anInMarker As markerStructure, _
ByVal anInBaseLineLength3 As Integer, _
ByVal anInHighlight As Boolean, _
ByVal anOverrideColour As Color, _
ByVal anInLabelDirection As labelDirectionEnum, _
ByVal anInYpixelOffset As Integer, _
ByVal anYdisplayLevel As Integer)
'anYdisplayLevel: low integers; 0, 1, 2, 3. Is NOT pixels.
Const LEVELSPACINGPIXELS2 As Integer = 16
Dim absPixel As Integer = labelXposition(anInMarker.MCR)
'Changed PM_FRAGMENTDISPLAY 2008-05-18
Dim baseLineLength As Integer = _
anInBaseLineLength3 + anYdisplayLevel * LEVELSPACINGPIXELS2
'Changed PM_MARKER_MEMORY_EFFICIENCY 2008-01-30
'Opportunity to save on memory here by
'using (and reusing) StringBuilder (and its AppendFormat ?).
'Changed PM_FRAGMENTMATCHING_MARKER_BUG 2006-03-02. Terminate name
'with underscore such that e.g. a match string "idx3" will not
'incorrectly match a Control name "_marker_899_idx38".
Dim name As String = _
"_marker_" & absPixel.ToString & "_idx" & anInMarker.tag & "_"
'Changed PM_FASTER_SPECTRUM_LABELS 2005-01-27
'Dim newMarker As Label = New Label
Dim createdNew As Boolean
Dim newMarker As Label = getNewLabel(createdNew)
If anOverrideColour.Equals(Color.Empty) Then
' It would be better with just a colour specification. It is
' misleading with ion-types in a class like this.
Select Case anInMarker.ionType3
Case ionTypeEnum.enumYion2
newMarker.BackColor = _
System.Drawing.Color.Blue
'Changed PM_FRAGMENTDISPLAY 2008-05-18. Now determined externally.
'anInBaseLineLength += levelSpacingPixels
Case ionTypeEnum.enumBion2
newMarker.BackColor = _
System.Drawing.Color.Red
Case ionTypeEnum.enumAion2
'Orange
newMarker.BackColor = _
System.Drawing.Color.FromArgb( _
CType(255, Byte), CType(128, Byte), CType(0, Byte))
Case ionTypeEnum.enumPrecursorIon2
'Dark green
newMarker.BackColor = _
System.Drawing.Color.FromArgb( _
CType(0, Byte), CType(168, Byte), CType(0, Byte))
'Changed PM_FRAGMENTDISPLAY 2008-05-18. Now determined externally.
'anInBaseLineLength += levelSpacingPixels
Case Else
Trace.Assert(False, _
"PIL ASSERT. Select Case never fall-through")
End Select
Else
newMarker.BackColor = anOverrideColour
End If
'Changed PM_FRAGMENTDISPLAY 2008-05-18. Now determined externally.
'If anInMarker.charge > 1 Then
' anInBaseLineLength += levelSpacingPixels
'End If
If anInYpixelOffset > 0 Then
Dim peter0 As Integer = 0 'For breakpoints.
End If
'Changed PM_ISOTOPEDISTRIBUTION_PLOT 2008-01-31
Dim loc2 As Point = mFarOff
loc2.Y -= anInYpixelOffset
''newMarker.Location = New System.Drawing.Point(xpos, ypos)
'newMarker.Location = mFarOff 'Only place where y is set, at least for now.
newMarker.Location = loc2 'Only place where y is set, at least for now.
newMarker.Name = name
'What is 16??? Answer: it is arbitrary, but is set to 1 (to make
' it appear as a line), in call to moveFarOffAndWidthSet() below...
newMarker.Size = New System.Drawing.Size(16, baseLineLength)
newMarker.TabIndex = 99
' asdasd() 'How are the vertical labels setup??? Width of a few pixels.
newMarker.Anchor = _
((System.Windows.Forms.AnchorStyles.Top Or _
System.Windows.Forms.AnchorStyles.Left _
) Or _
System.Windows.Forms.AnchorStyles.Right)
newMarker.Font = mMarkerFont
newMarker.Text = name 'Why is this needed????
'Changed PM_MARKERS_MASS_IN_TOOLTIPS 2005-02-10
'Changed PM_ZOOM_MARKERS 2004-06-17
Dim MCRstring As String = anInMarker.MCR.ToString("0.00000")
Dim helpText As String = MCRstring & anInMarker.moreDescription
newMarker.Tag = MCRstring
mTooltipForExactMass.SetToolTip( _
newMarker, helpText)
moveFarOffAndWidthSet(newMarker, mFarOff, anInLabelDirection)
moveLabelInX(newMarker, absPixel)
'Changed PM_FASTER_SPECTRUM_LABELS 2005-01-27
If createdNew Then
mParentForm.Controls.Add(newMarker)
Else
Dim peter8 As Integer = 8 'For breakpoints
End If
newMarker.BringToFront() 'Note: this MUST come after the Add()....
newMarker.Show()
Me.addTextLabel( _
newMarker, anInMarker.labelDescription, helpText)
If anInHighlight Then
Dim someID As Integer = CInt(anInMarker.tag)
Me.highLightMarker(someID)
End If
End Sub 'addMarker
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Overrides Sub highLightMarker(ByVal aTag As Integer)
'Changed PM_FRAGMENTMATCHING_MARKER_BUG 2006-03-02. Also moved
'it out of loop as it is constant.
'Dim matchStr As String = "idx" & aTag
Dim matchStr As String = "idx" & aTag & "_"
Dim removedSomething As Boolean = False
Dim someControl As Control
For Each someControl In mParentForm.Controls
Dim name As String = someControl.Name
If name.StartsWith("_marker_") Then
If name.IndexOf("descr") < 0 Then 'Don't touch the
' descriptive labels.
Dim result As Match = Regex.Match(name, matchStr)
If result.Success Then
someControl.Width = 2
someControl.BackColor = System.Drawing.Color.Cyan
Exit For
End If
End If
End If
Next
End Sub 'highLightMarker
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Overrides Sub clearMarkers()
Dim farOff_DeletedPosition As Point
setFarOff_DeletedPosition(farOff_DeletedPosition)
Dim numControls As Integer = mParentForm.Controls.Count
If numControls > mMaxNumControls Then
mMaxNumControls = numControls
End If
'Changed PM_MASSMARKERS_ACCUMULATING 2008-05-23
''Changed PM_ACCUM_MARKERS_BUG 2005-03-04
'Trace.Assert(numControls < 500, _
' "PIL ASSERT. The mass markers are accumulating!!!.")
Dim mLimit As Integer = 1200
Trace.Assert(numControls < mLimit, _
"PIL ASSERT. The mass markers are accumulating!!!. Count: " & _
numControls & ". Limit: " & mLimit & ".")
'Note: the while loop is only really needed if we actually
' remove/delete labels.
Dim someControl As Control
Dim done As Boolean = False
While Not done
Dim removedSomething As Boolean = False
For Each someControl In mParentForm.Controls
If someControl.Name.StartsWith("_marker_") Then
'Changed PM_FASTER_SPECTRUM_LABELS 2005-01-27. Move instead
'of really deleting.
'Changed PM_FASTER_SPECTRUM_LABELS 2005-01-27. As we
'are not removing anything we can be done with all the
'labels in one go.
'anInOutForm.Controls.Remove(control)
'removedSomething = True
'Exit For
someControl.Location = farOff_DeletedPosition
End If
Next
If Not removedSomething Then
done = True
End If
End While
End Sub 'clearMarkers
'Changed PM_ZOOM_MARKERS 2004-06-17
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Overrides Sub updateMarkersPosition()
Dim control As Control
Dim done As Boolean = False
For Each control In mParentForm.Controls
If control.Name.StartsWith("_marker_") Then
Dim mass As Double = CDbl(control.Tag)
Dim absPixel As Integer = labelXposition(mass)
moveLabelInX(DirectCast(control, Label), absPixel)
End If
Next
End Sub 'updateMarkersPosition
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Private Function getNewLabel( _
ByRef anOutCreatedNewLabel As Boolean) _
As Label
Dim toReturn As Label = Nothing
anOutCreatedNewLabel = False
'First look for a label that was previously marked deleted - moved
'off screen to the "delete location".
Dim farOff_DeletedPosition As Point
setFarOff_DeletedPosition(farOff_DeletedPosition)
Dim foundDeletedLabel As Boolean = False
Dim control As Control
For Each control In mParentForm.Controls
If control.Name.StartsWith("_marker_") Then
'Changed PM_ACCUM_MARKERS_BUG 2005-03-04
'Note: we only use and test the y as deleted because
' labels may be moved off screen in the x-direction..
'If control.Location.X = farOff_DeletedPosition.X AndAlso _
' control.Location.Y = farOff_DeletedPosition.Y Then
If control.Location.Y = farOff_DeletedPosition.Y Then
toReturn = DirectCast(control, Label)
foundDeletedLabel = True
Exit For
End If
End If
Next
Dim labels As Integer = mParentForm.Controls.Count 'Only for diagnostics
If Not foundDeletedLabel Then
toReturn = New Label
anOutCreatedNewLabel = True
mNewLabelCount += 1
Dim lstr As String = toReturn.ToString
Else
'Reset some fields so that it is similar to creating a new Label.
toReturn.BackColor = mParentForm.BackColor
toReturn.Width = 0
toReturn.AutoSize = False
End If
Return toReturn
End Function 'getNewLabel
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Private Shared Sub setFarOff_DeletedPosition(ByRef aOutLocation As Point)
aOutLocation.X = 0
aOutLocation.Y = DELETEDPOSITION_Y
End Sub 'setFarOff_DeletedPosition
'Changed PM_REFACTOR 2004-06-17
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Private Function labelXposition(ByVal aMass As Double) As Integer
'Changed PM_REFACTOR 2007-09-19
''Changed PM_ANALYST_MARKERS 2005-02-10
''Dim relPixelStart As Integer = 42
''Dim endSpectrumToRightEdgePixels As Integer = 18
'Dim relPixelStart As Integer = Me.xOffsetForMarkers()
'Check for second level initialisation.
Trace.Assert(m_xOffsetForMarkers <> -1, _
"PIL ASSERT. m_xOffsetForMarkers is not set - init2() was not called!.")
Dim relPixelStart As Integer = m_xOffsetForMarkers
'Changed PM_REFACTOR 2007-09-19
'Dim endSpectrumToRightEdgePixels As Integer = Me.xOffsetFromRightEdge()
Trace.Assert(m_xOffsetFromRightEdge <> -1, _
"PIL ASSERT. m_xOffsetFromRightEdge is not set.")
Dim endSpectrumToRightEdgePixels As Integer = m_xOffsetFromRightEdge
'Dim specX As Integer = mAxXSpecDisplay_FINNEGANCOM.Location.X
'Dim specY As Integer = mAxXSpecDisplay_FINNEGANCOM.Location.Y
''Changed PM_REFACTOR 2004-06-10
'Dim specSize As System.Drawing.Size = mAxXSpecDisplay_FINNEGANCOM.Size
'Dim sizeX As Integer = specSize.Width
'Dim sizeY As Integer = specSize.Height
Dim specX As Integer
Dim specY As Integer
Dim sizeX As Integer
Dim sizeY As Integer
'Changed PM_REFACTOR 2007-09-19
'Me.spectrumControlLocAndSize(specX, specY, sizeX, sizeY)
specX = mSpectrumControlX
specY = mSpectrumControlY
sizeX = mSpectrumControlSizeX
sizeY = mSpectrumControlSizeY
Dim displayMassWindow As Double = mZoom.endMass - mZoom.startMass
'Test for 0.0 .... To avoid crash below. pixelsPerDalton becomes infinity.
'Changed PM_ORBI_EMPTYSPECTRA 2005-09-28
If displayMassWindow < 0.000000001 Then
Dim peter1 As Integer = 1
Trace.Assert(False, "PIL ASSERT. Empty display range..")
Else
Dim peter2 As Integer = 2
End If
'Dim pixelScale As Integer = 537 - relPixelStart
'Dim effectiveWidth As Integer = 902
'Dim effectiveWidth As Integer = sizeX - 18
Dim effectiveWidth As Integer = sizeX - endSpectrumToRightEdgePixels
Dim pixelScale As Integer = effectiveWidth - relPixelStart
Dim absPixelStart As Integer = (specX + 4) + relPixelStart '4: the actual
' start of the white area of the control is 4 pixel added to Location.X.
Dim pixelsPerDalton As Double = pixelScale / displayMassWindow
Dim labelWidthCorrection As Integer = 0
Dim spectrumPixel As Integer = _
CInt(pixelsPerDalton * (aMass - mZoom.startMass))
Dim absPixel As Integer = spectrumPixel + absPixelStart
absPixel -= 4 'Note: there seems to be a 4 pixel offset between
' the X location we set on a Label and the actual location of
' the 1 pixel wide visual 'line'. So we adjust for it here....
absPixel -= labelWidthCorrection
If aMass < mZoom.startMass Or aMass > mZoom.endMass Then
absPixel = 10000
End If
Return absPixel
End Function 'labelXposition
'Note: redundant with DTASuperCharge's function. Should be refactored.
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Private Shared Sub moveLabelInX(ByRef aLabelToMove As Label, _
ByVal anAbsXPixel As Integer)
Dim lloc As Point = aLabelToMove.Location
lloc.X = anAbsXPixel
aLabelToMove.Location = lloc
'aLabelToMove.Width = 1
End Sub
'Note: redundant with DTASuperCharge's function. Should be refactored.
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Private Shared Sub moveFarOffAndWidthSet( _
ByRef anInOutSomeLabel As Label, ByRef aFarOff As Point, _
ByVal anInLabelDirection As labelDirectionEnum)
Dim pos As Point = anInOutSomeLabel.Location
pos.X = aFarOff.X
anInOutSomeLabel.Location = pos
anInOutSomeLabel.Width = 5
anInOutSomeLabel.Width = 1
If anInLabelDirection = labelDirectionEnum.enumLineRight Then
'Change from vertical line to horizontal line.
Dim oSize As Size = anInOutSomeLabel.Size
anInOutSomeLabel.Width = oSize.Height
anInOutSomeLabel.Height = oSize.Width
End If
End Sub 'moveFarOffAndWidthSet
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Private Sub addTextLabel(ByRef aLine As Label, _
ByRef aText As String, ByRef anInHelpText As String)
'Copy fields from input label and change from line-type label
'to text label.
'Changed PM_FASTER_SPECTRUM_LABELS 2005-01-27
'Dim newTextLabel As Label = New Label
Dim createdNew As Boolean
Dim newTextLabel As Label = getNewLabel(createdNew)
newTextLabel.ForeColor = aLine.BackColor
Dim loc As Point = aLine.Location
loc.Y += 6 + aLine.Height
loc.X -= 3 'To center text wrt. to line.
newTextLabel.Location = loc
newTextLabel.Name = aLine.Name & "_descr"
newTextLabel.TabIndex = aLine.TabIndex + 1
newTextLabel.Font = aLine.Font
newTextLabel.Text = aText
'Changed PM_MARKERS_MASS_IN_TOOLTIPS 2005-02-10
mTooltipForExactMass.SetToolTip(newTextLabel, anInHelpText)
'Changed PM_ZOOM_MARKERS 2004-06-17
newTextLabel.Tag = aLine.Tag
'Moved down here.
'newTextLabel.Size = New System.Drawing.Size(32, 24)
newTextLabel.AutoSize = True
If createdNew Then
mParentForm.Controls.Add(newTextLabel)
Else
Dim peter8 As Integer = 8 'For breakpoints
End If
newTextLabel.BringToFront() 'Note: this MUST come after the Add()....
newTextLabel.Show()
End Sub 'addTextLabel
End Class 'overlaySpectrumMarking
Generated by script codePublish.pl at 2009-01-05T15:20:59.