Source code for MSQuant: frmRawFileMapping.vb, MSQuant/msquant/src/GUI/forms/frmRawFileMapping.vb.

Table of contents page.

Home page for MSQuant.

'****************************************************************************
'* 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: Holds Class frmDimensions, see below for                        *
'*          documentation.                                                  *
'*                                                                          *
'****************************************************************************

'****************************************************************************
'*                               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:   frmRawFileMapping.vb                                      *
'*    TYPE:  VISUAL_BASIC                                                   *
'*                                                                          *
'* CREATED: PM 2008-08-29   Vrs 1.0.                                        *
'* UPDATED: PM 2008-xx-xx                                                   *
'*                                                                          *
'****************************************************************************

Option Strict On
Option Explicit On

Imports System.Text 'For StringBuilder
Imports System.Collections.Generic 'Dictionary.
Imports System.IO 'For Path

Imports SDUPutility 'For vectorElementStruct
Imports App 'For quantApplication.


'****************************************************************************
'*    <placeholder for header>                                              *
'****************************************************************************
Public Class frmRawFileMapping


    Private mLastPointGUIindex As Integer 'For the N-point pop-up, raw file mapping.

    'Mapping between the pop-up index in the GUI and the raw file. Note that
    'this index is not the same as (...???)
    Private mIndex2rawFileInfo As Dictionary(Of Integer, rawFileStruct4)

    'This is the actual output (and input) for this class/dialog.
    '
    '  Other name ?:  RawFileMapping
    '
    '
    'A member (hash) to remember mapping from N-point (represented by
    'the key/code) to file name.
    '
    Private mNpointkey2rawFileInfo As _
      Dictionary(Of Integer, rawFileStruct4)

    'Changed PM_EXPORT_TO_ANY_RAWFILEMAPPINGDLG 2008-12-18
    Private mExportTargetSettings As exportTargetSettingsStruct

    Public Event rawFileMappingDismissed( _
      ByVal aSender As Object, _
      ByVal anEvent As rawFileMappingEventArgs)


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Public Sub New( _
      ByRef anInVectorSet As Dictionary(Of Integer, List(Of vectorElementStruct)), _
      ByRef aRawFileMapping As Dictionary(Of Integer, rawFileStruct4), _
      ByVal anInExportTargetSettings As exportTargetSettingsStruct _
      )

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        mIndex2rawFileInfo = Nothing 'Just in case.
        mLastPointGUIindex = -1 'Flag for the event that is fired during setup.

        Me.Init(anInVectorSet, aRawFileMapping, anInExportTargetSettings)
    End Sub 'Constructor.


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub Init( _
      ByRef anInVectorSet As _
        Dictionary(Of Integer, List(Of vectorElementStruct)), _
      ByRef aRawFileMapping As _
        Dictionary(Of Integer, rawFileStruct4), _
      ByVal anInExportTargetSettings As exportTargetSettingsStruct)

        'Changed PM_EXPORT_TO_ANY_RAWFILEMAPPINGDLG 2008-12-18
        mExportTargetSettings = anInExportTargetSettings

        Me.rawFileMappingSetup2(anInVectorSet, aRawFileMapping)
    End Sub 'Init()


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub rawFileMappingSetup2( _
      ByRef anInVectorSet As _
        Dictionary(Of Integer, List(Of vectorElementStruct)), _
      ByRef aRawFileMapping As _
        Dictionary(Of Integer, rawFileStruct4))

        'We build it up, effectively copying the input (if appropriate).
        mNpointkey2rawFileInfo = _
          New Dictionary(Of Integer, rawFileStruct4)

        'Dimensioning to raw file name mapping.
        If True Then
            cbxDimensionPoints.Items.Clear()

            Dim sb As StringBuilder = New StringBuilder(20)

            'Dim set2 As Dictionary(Of Integer, List(Of vectorElementStruct)) = _
            '  anInSettings.getVectorSet()
            Dim set2 As Dictionary(Of Integer, List(Of vectorElementStruct)) = _
              anInVectorSet

            mIndex2rawFileInfo = New Dictionary(Of Integer, rawFileStruct4)

            Dim index2 As Integer = 0
            'Unfortunately no sort order here... User may be confused.
            Dim hashEnumerator2 As Dictionary( _
              Of Integer, List(Of vectorElementStruct)).Enumerator = _
                set2.GetEnumerator()
            While (hashEnumerator2.MoveNext())

                'Note: key is actually the key used in CEBIspaces/anInSettings.
                Dim NpointKey2 As Integer = hashEnumerator2.Current.Key

                Dim curVector As List(Of vectorElementStruct) = _
                  hashEnumerator2.Current.Value

                sb.Length = 0
                Dim someItem As vectorElementStruct
                'Dim indexOne As Integer = 1
                Dim vIndex As Integer = 0
                Dim vLastIndex As Integer = curVector.Count() - 1
                For Each someItem In curVector
                    sb.Append(someItem.shortName3)
                    'sb.Append(indexOne.ToString)

                    If vIndex <> vLastIndex Then
                        sb.Append(",")
                    End If

                    vIndex += 1
                Next 'Through curVector
                sb.Append(": ")

                cbxDimensionPoints.Items.Add(sb.ToString)

                Dim someRawFileInfo As rawFileStruct4
                If aRawFileMapping.ContainsKey(NpointKey2) Then
                    someRawFileInfo = aRawFileMapping(NpointKey2)
                Else
                    'Mapping not known in input. Add it.

                    someRawFileInfo.rawFile = "" 'For now!!! No initial list.
                    someRawFileInfo.rawFileID7 = -1
                End If

                'For reverse lookup.
                someRawFileInfo.NpointKey4 = NpointKey2
                mNpointkey2rawFileInfo(NpointKey2) = someRawFileInfo

                'This is for GUI mapping, from visual index to data.
                mIndex2rawFileInfo(index2) = someRawFileInfo 'Note: as we
                '  have the N-point key we can later get from GUI index to
                '  N-point key and we can update what will become the
                '  output, mNpointkey2rawFileInfo.

                index2 += 1
            End While

            cbxDimensionPoints.SelectedIndex = 0
        End If 'Block.
    End Sub 'rawFileMappingSetup2()


    'Note: some redundancy with frmExportTarget.vb. In other
    '      words: refactoring opportunity.
    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub userSelectInputFile( _
      ByVal anInDialogTitle As String, ByRef aInOutFolderName As String, _
      ByRef anExtension As String)

        OpenFileDialog1.RestoreDirectory() = False 'do not restore directory
        OpenFileDialog1.Title = "Select " & anInDialogTitle & "..."
        OpenFileDialog1.DereferenceLinks = True
        OpenFileDialog1.Filter = _
          "Executable files (*." & anExtension & ")|*." & anExtension & ""
        OpenFileDialog1.FileName = ""
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            aInOutFolderName = OpenFileDialog1.FileName
        End If
    End Sub 'userSelectInputFile


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub btnBrowseForRawFile_Click( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles btnBrowseForRawFile.Click

        Me.userSelectInputFile( _
          "raw file", _
          txtRawFilePath.Text, "raw") 'Only Finnigan for now!!!
    End Sub 'btnBrowseForRawFile_Click


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub captureRawfileFromGUI()

        'Put current raw file path into the old point's place.
        If mLastPointGUIindex <> -1 Then 'Is -1 the first when there is
            '  no old value.

            Dim prevContent As rawFileStruct4 = _
              mIndex2rawFileInfo(mLastPointGUIindex)

            'Read off GUI... This is the value for the previous GUI index.
            Dim rawFilePath As String = txtRawFilePath.Text

            prevContent.rawFile = rawFilePath
            prevContent.rawFileID7 = -1 'Not yet.
            mIndex2rawFileInfo(mLastPointGUIindex) = prevContent

            'This is the real output from this class/dialog. That we have
            'to update here.
            Dim NpointKey2 As Integer = prevContent.NpointKey4
            mNpointkey2rawFileInfo(NpointKey2) = prevContent
        End If
    End Sub 'captureRawfileFromGUI()


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub cbxDimensionPoints_SelectedIndexChanged( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles cbxDimensionPoints.SelectedIndexChanged

        Me.captureRawfileFromGUI()

        'Display raw file for new.
        mLastPointGUIindex = cbxDimensionPoints.SelectedIndex()
        Dim nextRawFile As String = _
          mIndex2rawFileInfo(mLastPointGUIindex).rawFile
        txtRawFilePath.Text = nextRawFile
    End Sub 'cbxDimensionPoints_SelectedIndexChanged


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub btnOK_Click( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles btnOK.Click

        'Fire event with the output from this dialog.
        '
        'Output: mNpointkey2rawFileInfo

        'No validation for now....
        Try
            'Note: update datastructures for the last input file name in the
            '      text box... (updating as in )
            Me.captureRawfileFromGUI()

            RaiseEvent rawFileMappingDismissed( _
              aSender, New rawFileMappingEventArgs(mNpointkey2rawFileInfo))
            Me.Close()
        Catch exceptionObject As Exception
            AppCommon2.displayStandardExceptionInfo( _
              exceptionObject, _
              "Could not read values dialog in dialog. " & _
              "Some numeric fields may hold letters, etc.")
            Exit Sub
        End Try
    End Sub 'btnOK_Click()


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub btnCancel_Click( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles btnCancel.Click

        Me.Close()
    End Sub 'btnCancel_Click


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub btnExportRawFilesMapping_Click( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles btnExportRawFilesMapping.Click

        'Changed PM_EXPORT_RAWFILEMAPPING_BUG 2008-10-07
        Me.captureRawfileFromGUI() 'Needed, otherwise we will miss
        '  the most recently added in the export...


        Dim len As Integer = mNpointkey2rawFileInfo.Count
        Dim sb As StringBuilder = New StringBuilder(20 * len)

        'Dim appVersionString As String = _
        '  quantApplication.versionString_withDate()
        'Dim isoDate As String = AppCommon2.iso8601FullTime()

        'Proper name??
        Dim context As String = _
          "This document was " & _
          quantApplication.appAndDateStamp()
        Dim existStr As String

        sb.Append(context)
        sb.Append(ControlChars.CrLf)
        sb.Append(ControlChars.CrLf)

        sb.Append("Npoint mapping to raw files.")
        sb.Append(ControlChars.CrLf)
        sb.Append(ControlChars.CrLf)

        sb.Append("Npoints:")
        sb.Append(ControlChars.Tab)
        sb.Append(len)
        sb.Append(ControlChars.CrLf)
        sb.Append(ControlChars.CrLf)

        sb.Append("Npoint name")
        sb.Append(ControlChars.Tab)
        sb.Append("Raw file name")
        sb.Append(ControlChars.Tab)
        sb.Append("Full file path")
        sb.Append(ControlChars.Tab)
        sb.Append("Exists")
        sb.Append(ControlChars.Tab)
        sb.Append(ControlChars.CrLf)

        Dim hashEnumerator2 As Dictionary( _
          Of Integer, rawFileStruct4).Enumerator = _
            mIndex2rawFileInfo.GetEnumerator()

        While hashEnumerator2.MoveNext()

            'Note: key is index in the GUI drop-down list.
            Dim curKey As Integer = hashEnumerator2.Current.Key

            Dim curValue As rawFileStruct4 = hashEnumerator2.Current.Value
            Dim fullFilePath As String = curValue.rawFile

            'Read-off from GUI...
            Dim NpointStr As String = CStr(cbxDimensionPoints.Items(curKey))

            If File.Exists(fullFilePath) Then
                existStr = "YES"
            Else
                existStr = "NO"
            End If

            sb.Append(NpointStr)
            sb.Append(ControlChars.Tab)

            sb.Append(Path.GetFileName(fullFilePath))
            sb.Append(ControlChars.Tab)

            sb.Append(fullFilePath)
            sb.Append(ControlChars.Tab)

            sb.Append(existStr)
            sb.Append(ControlChars.Tab)

            sb.Append(ControlChars.CrLf)
        End While 'Hash iteration.

        Dim reportStr As String = sb.ToString()
        Dim actualLen As Integer = reportStr.Length()

        'Changed PM_EXPORT_TO_ANY_RAWFILEMAPPINGDLG 2008-12-18
        'Dim exportTargetSettings As exportTargetSettingsStruct
        'exportTargetSettings.target = targetEnum.enumExportToOpenOffice
        '
        'exportTargetSettings.filePath = Nothing 'Keep compiler happy.
        'exportTargetSettings.userAppPath = Nothing 'Keep compiler happy.
        'exportTargetSettings.openFileAfterGeneration = False 'Just in case.
        Dim exportTargetSettings As exportTargetSettingsStruct = _
          mExportTargetSettings

        'Assume client has checked it...

        PILInputOutput.pushToTarget( _
          reportStr, exportTargetSettings, AppCommon2.appPath())
    End Sub 'btnExportRawFilesMapping_Click()


End Class 'frmRawFileMapping


'Helper class for rawFileMappingDismissed event.
'****************************************************************************
'*    <placeholder for header>                                              *
'****************************************************************************
Public Class rawFileMappingEventArgs
    Inherits System.EventArgs

    Private mFileMapping As Dictionary(Of Integer, rawFileStruct4)


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Public Sub New( _
      ByVal aSomeValue As Dictionary(Of Integer, rawFileStruct4))

        mFileMapping = aSomeValue
    End Sub 'Constructor.


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Public Function getMapping() _
      As Dictionary(Of Integer, rawFileStruct4)

        Return mFileMapping 'What about deep copy???
    End Function 'getMapping()


End Class 'rawFileMappingEventArgs


    

    

Generated by script codePublish.pl at 2009-01-05T15:20:59.