Exemplo n.º 1
0
        /// <summary>
        /// The information from a definition file is added to the datagrid and possibly to the combo box.
        /// 
        /// An excpetion is thrown when retrieving details for the definition file fails.
        /// </summary>
        /// <param name="theDefinitionFullFileName">the full file name of the definition file.</param>
        private void AddSopClassToDataGridFromDefinitionFile(string theDefinitionFullFileName)
        {
            Dvtk.Sessions.Session theSession = GetSessionTreeViewManager().GetSelectedSession();
            Dvtk.Sessions.DefinitionFileDetails theDefinitionFileDetails;

            // Try to get detailed information about this definition file.
            theDefinitionFileDetails = theSession.DefinitionManagement.GetDefinitionFileDetails(theDefinitionFullFileName);

            // No excpetion thrown when calling GetDefinitionFileDetails (otherwise this statement would not have been reached)
            // so this is a valid definition file. Add it to the data frid.
            DefinitionFile theDataGridDefinitionFileInfo =
                new DefinitionFile(IsDefinitionFileLoaded(theDefinitionFullFileName),
                System.IO.Path.GetFileName(theDefinitionFullFileName),
                theDefinitionFileDetails.SOPClassName,
                theDefinitionFileDetails.SOPClassUID,
                theDefinitionFileDetails.ApplicationEntityName,
                theDefinitionFileDetails.ApplicationEntityVersion,
                System.IO.Path.GetDirectoryName(theDefinitionFullFileName));

            _DefinitionFilesInfoForDataGrid.Add(theDataGridDefinitionFileInfo);

            // If the AE title - version does not yet exist in the combo box, add it.
            bool IsAeTitleVersionAlreadyInComboBox = false;

            foreach (AeTitleVersion theAeTitleVersion in _ComboBoxAeTitle.Items)
            {
                if ( (theAeTitleVersion._AeTitle == theDefinitionFileDetails.ApplicationEntityName) &&
                    (theAeTitleVersion._Version == theDefinitionFileDetails.ApplicationEntityVersion) )
                {
                    IsAeTitleVersionAlreadyInComboBox = true;
                    break;
                }
            }

            if (!IsAeTitleVersionAlreadyInComboBox)
            {
                AeTitleVersion theAeTitleVersion = new AeTitleVersion(theDefinitionFileDetails.ApplicationEntityName, theDefinitionFileDetails.ApplicationEntityVersion);
                _ComboBoxAeTitle.Items.Add(theAeTitleVersion);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// When moving the mouse over other "loaded" check box while keeping the left mouse button pressed,
        /// change the "loaded" state to the new state when the left mouse button was pressed.
        /// </summary>
        /// <param name="e"></param>
        public void DataGrid_MouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            Dvtk.Sessions.Session theSession = GetSessionTreeViewManager().GetSelectedSession();

            if (e.Button == MouseButtons.Left)
            {
                System.Windows.Forms.DataGrid.HitTestInfo theHitTestInfo;

                theHitTestInfo = _DataGridSopClasses.HitTest(e.X, e.Y);

                switch (theHitTestInfo.Type)
                {
                case System.Windows.Forms.DataGrid.HitTestType.Cell:
                    // If this is the "loaded" column...
                    if (theHitTestInfo.Column == 0)
                    {
                        // If another "loaded" check box is pointed to, not the one where the state has
                        // last been changed...
                        if (theHitTestInfo.Row != _MouseEventInfoForDataGrid_LoadedStateChangedForRow)
                        {
                            DefinitionFile theDefinitionFile     = (DefinitionFile)_DefinitionFilesInfoForDataGrid[theHitTestInfo.Row];
                            bool           theCurrentLoadedState = theDefinitionFile.Loaded;

                            // Only if the state will change...
                            if (theCurrentLoadedState != _MouseEventInfoForDataGrid_LoadedStatedAfterMouseDown)
                            {
                                // Get the column style for the "loaded" column.
                                DataGridColumnStyle theDataGridColumnStyle;
                                theDataGridColumnStyle = _DataGridSopClasses.TableStyles[0].GridColumnStyles[0];

                                // Change the "loaded" stated in _DefinitionFilesInfoForDataGrid and the data grid itself.
                                _DataGridSopClasses.BeginEdit(theDataGridColumnStyle, theHitTestInfo.Row);
                                theDefinitionFile.Loaded = _MouseEventInfoForDataGrid_LoadedStatedAfterMouseDown;
                                _DataGridSopClasses.EndEdit(theDataGridColumnStyle, theHitTestInfo.Row, false);

                                // Change the "loaded" state in the session object.
                                string theFullFileName = System.IO.Path.Combine(theDefinitionFile.DefinitionRoot, theDefinitionFile.Filename);

                                if (_MouseEventInfoForDataGrid_LoadedStatedAfterMouseDown)
                                {
                                    // The definition file was not loaded yet. Load it now.
                                    theSession.DefinitionManagement.LoadDefinitionFile(theFullFileName);
                                }
                                else
                                {
                                    // The definition file was loaded. Unload it now.
                                    theSession.DefinitionManagement.UnLoadDefinitionFile(theFullFileName);
                                }

                                // Remember the cell we've changed. We don't want to change the loaded
                                // state with each minor mouse move.
                                _MouseEventInfoForDataGrid_LoadedStateChangedForRow = theHitTestInfo.Row;

                                // Notify the rest of the world.
                                SessionChange theSessionChange = new SessionChange(theSession, SessionChange.SessionChangeSubTypEnum.SOP_CLASSES_LOADED_STATE);
                                Notify(theSessionChange);
                            }
                            else
                            // State will not change. The cell under the mouse will not be selected. This
                            // results in scrolling that will not work when the mouse is moved to the bottom
                            // of the datagrid.
                            //
                            // To solve this, explicitly make the cell under the mouse selected.
                            {
                                DataGridCell currentSelectedCell = _DataGridSopClasses.CurrentCell;
                                DataGridCell newSelectedCell     = new DataGridCell(theHitTestInfo.Row, currentSelectedCell.ColumnNumber);

                                _DataGridSopClasses.CurrentCell = newSelectedCell;
                            }
                        }
                    }
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private void AddSelectLoadedSOPClasses()
        {
            string[]    files;

            files = this.selected_session.DefinitionManagement.LoadedDefinitionFileNames;

            foreach (string file in files)
            {
                FileInfo    fileInfo = new FileInfo (file);
                bool        found = false;
                foreach (DefinitionFile def_file in this.definition_files)
                {
                    if (file == fileInfo.Name)
                    {
                        // No directory element has been specified. Use the definition root
                        // as has been set in the Session file.
                        if ((file == def_file.Filename) &&
                            (this.selected_session.DefinitionManagement.DefinitionFileRootDirectory == def_file.DefinitionRoot))
                        {
                            def_file.Loaded = true;
                            found = true;
                        }
                    }
                    else
                    {
                        if ((fileInfo.Name == def_file.Filename) &&
                            (fileInfo.DirectoryName == def_file.DefinitionRoot))
                        {
                            def_file.Loaded = true;
                            found = true;
                        }
                    }
                }
                if (!found)
                {
                    DefinitionFile  def_file;
                    Dvtk.Sessions.DefinitionFileDetails def_details;

                    try
                    {

                        def_details = this.selected_session.DefinitionManagement.GetDefinitionFileDetails (fileInfo.FullName);
                        if (file == fileInfo.Name)
                        {
                            // No directory element has been specified. Use the definition root
                            // as has been set in the Session file.
                            def_file = new DefinitionFile (true,
                                fileInfo.Name,
                                def_details.SOPClassName,
                                def_details.SOPClassUID,
                                def_details.ApplicationEntityName,
                                def_details.ApplicationEntityVersion,
                                this.selected_session.DefinitionManagement.DefinitionFileRootDirectory);
                        }
                        else
                        {
                            def_file = new DefinitionFile (true,
                                fileInfo.Name,
                                def_details.SOPClassName,
                                def_details.SOPClassUID,
                                def_details.ApplicationEntityName,
                                def_details.ApplicationEntityVersion,
                                fileInfo.DirectoryName);
                        }
                        definition_files.Add (def_file);
                    }
                    catch
                    {
                        this.RichTextBoxInfo.Text +=
                        string.Format(
                            "Definition file {0} could not be loaded.\n",
                            fileInfo.FullName);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// The reason we handle the mouseup event ourselves, is because with the normal
        /// grid, you first have to select a cell, and only then you can enable/disable a
        /// checkbox. We want to enable/disable the checkbox with 1 click.
        /// </summary>
        /// <param name="e"></param>
        public void DataGrid_MouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            System.Windows.Forms.DataGrid.HitTestInfo theHitTestInfo;
            Dvtk.Sessions.Session theSession = GetSessionTreeViewManager().GetSelectedSession();

            // Find out what part of the data grid is below the mouse pointer.
            theHitTestInfo = _DataGridSopClasses.HitTest(e.X, e.Y);

            switch (theHitTestInfo.Type)
            {
            case System.Windows.Forms.DataGrid.HitTestType.Cell:
                // If this is the "loaded" column...
                if (theHitTestInfo.Column == 0)
                {
                    // Remember the cell we've changed. We don't want to change this cell when we move the mouse.
                    // (see DataGrid_MouseMove).
                    _MouseEventInfoForDataGrid_LoadedStateChangedForRow = theHitTestInfo.Row;

                    // Get the column style for the "loaded" column.
                    DataGridColumnStyle theDataGridColumnStyle;
                    theDataGridColumnStyle = _DataGridSopClasses.TableStyles[0].GridColumnStyles[0];

//						// Workaround for following problem:
//						// If the SOP classes tab has already been filled, and another session contains less
//						// records for the datagrid, windows gets confused and thinks there are more records
//						// then actually present in _DefinitionFilesInfoForDataGrid resulting in an assertion.
//						_DataGridSopClasses.SetDataBinding(null, "");
//
//						// Actually refresh the data grid.
//						_DataGridSopClasses.SetDataBinding(_DefinitionFilesInfoForDataGrid, "");

                    // Change the "loaded" stated in _DefinitionFilesInfoForDataGrid and the data grid itself.
                    _DataGridSopClasses.BeginEdit(theDataGridColumnStyle, theHitTestInfo.Row);
                    DefinitionFile theDefinitionFile = (DefinitionFile)_DefinitionFilesInfoForDataGrid[theHitTestInfo.Row];
                    theDefinitionFile.Loaded = !theDefinitionFile.Loaded;
                    _DataGridSopClasses.EndEdit(theDataGridColumnStyle, theHitTestInfo.Row, false);

                    // Change the "loaded" state in the session object.
                    string theFullFileName = System.IO.Path.Combine(theDefinitionFile.DefinitionRoot, theDefinitionFile.Filename);

                    if (theDefinitionFile.Loaded)
                    {
                        // The definition file was not loaded yet. Load it now.
                        theSession.DefinitionManagement.LoadDefinitionFile(theFullFileName);
                    }
                    else
                    {
                        // The definition file was loaded. Unload it now.
                        theSession.DefinitionManagement.UnLoadDefinitionFile(theFullFileName);
                    }

                    // Remember the new "loaded" state for the case where the mouse is moved over other
                    // "loaded" checkboxes while keeping the left mouse button pressed.
                    _MouseEventInfoForDataGrid_LoadedStatedAfterMouseDown = theDefinitionFile.Loaded;

                    // Notify the rest of the world.
                    SessionChange theSessionChange = new SessionChange(theSession, SessionChange.SessionChangeSubTypEnum.SOP_CLASSES_LOADED_STATE);
                    Notify(theSessionChange);
                }

//					// If this is the "Open Definition File" column...
//					if (theHitTestInfo.Column == 7)
//					{
//						// Remember the cell we've changed. We don't want to change this cell when we move the mouse.
//						// (see DataGrid_MouseMove).
//						_MouseEventInfoForDataGrid_OpenStateChangedForRow = theHitTestInfo.Row;
//
//						// Get the column style for the "Open" column.
//						DataGridColumnStyle theDataGridColumnStyle;
//						theDataGridColumnStyle = _DataGridSopClasses.TableStyles[0].GridColumnStyles[7];
//
//						// Change the "Open" stated in _DefinitionFilesInfoForDataGrid and the data grid itself.
//						_DataGridSopClasses.BeginEdit(theDataGridColumnStyle, theHitTestInfo.Row);
//						DefinitionFile theDefinitionFile = (DefinitionFile)_DefinitionFilesInfoForDataGrid[theHitTestInfo.Row];
//						theDefinitionFile.Open = !theDefinitionFile.Open;
//						_DataGridSopClasses.EndEdit (theDataGridColumnStyle, theHitTestInfo.Row, false);
//
//						// Get full definition file name.
//						string theFullFileName = System.IO.Path.Combine(theDefinitionFile.DefinitionRoot, theDefinitionFile.Filename);
//
//						if (theDefinitionFile.Open)
//						{
//							// Open the definition file in notepad.
//							System.Diagnostics.Process theProcess  = new System.Diagnostics.Process();
//
//							theProcess.StartInfo.FileName= "Notepad.exe";
//							theProcess.StartInfo.Arguments = theFullFileName;
//
//							theProcess.Start();
//						}
//
//						// Remember the new "Open" state for the case where the mouse is moved over other
//						// "Open" checkboxes while keeping the left mouse button pressed.
//						_MouseEventInfoForDataGrid_OpenStatedAfterMouseDown = theDefinitionFile.Open;
//					}
//
                break;
            }
        }
Exemplo n.º 5
0
        private void UpdateSOPClassesView()
        {
            DirectoryInfo   definition_dir;

            Cursor.Current = Cursors.WaitCursor;

            // When updating the SOP classes view, all fields need to be reset.
            this.ListBoxDefinitionDirs.Items.Clear ();

            // Clear the Info text box. This box will contain possible errors with
            // loading incorrect definition files.
            this.RichTextBoxInfo.Clear ();

            // Create and fill in the array containing all definition files found in the
            // definition root.
            this.definition_files = new ArrayList();
            foreach (string def_root in this.selected_session.DefinitionManagement.DefinitionFileDirectoryList)
            {
                string mod_root = def_root;

                // strip any leading / or \ from the def_root
                if ((def_root[def_root.Length-1] == '/') ||
                    (def_root[def_root.Length-1] == '\\'))
                    mod_root = def_root.Remove (def_root.Length-1, 1);

                // Add the definition root directory to the definition root list view.
                this.ListBoxDefinitionDirs.Items.Add (mod_root);

                definition_dir = new DirectoryInfo (mod_root);

                if (definition_dir.Exists)
                {
                    FileInfo[] files = definition_dir.GetFiles();
                    foreach (FileInfo file in files)
                    {
                        Dvtk.Sessions.DefinitionFileDetails def_details;
                        try
                        {
                            def_details = this.selected_session.DefinitionManagement.GetDefinitionFileDetails (file.FullName);
                            DefinitionFile  def_file = new DefinitionFile (false,
                                file.Name,
                                def_details.SOPClassName,
                                def_details.SOPClassUID,
                                def_details.ApplicationEntityName,
                                def_details.ApplicationEntityVersion,
                                mod_root);
                            this.definition_files.Add (def_file);
                        }
                        catch
                        {
                            this.RichTextBoxInfo.Text +=
                                string.Format(
                                "In definitionroot: {0} the file {1} is not a correct definition file.\n",
                                definition_dir.FullName,
                                file.FullName
                                );
                        }
                    }
                }
            }

            this.AddSelectLoadedSOPClasses ();
            if (this.definition_files.Count > 0)
            {
                // We can only select items when there is at least 1 definition file loaded.
                this.FillAETitleVersionComboBox ();
                this.SOPClasses.SetDataBinding (definition_files, "");
            }

            Cursor.Current = Cursors.Default;
        }