コード例 #1
0
        /// <summary>
        /// Register the given loader so that it is available as a choice in the fileopen dialog.
        /// </summary>
        /// <param name="loader">A <see cref="ISpecFileLoader"/> reference of the loader to be registered.</param>
        public static void RegisterSpecFileLoader(ISpecFileLoader loader)
        {
            if (loader == null)
            {
                throw new ArgumentNullException("loader");
            }

            specFileLoaderList.Add(loader);
        }
コード例 #2
0
        /// <summary>
        /// Overloaded Opens the document specified by the given <paramref name="fileName"/>
        /// and uses the specified  <paramref name="loader"/>.
        /// </summary>
        /// <param name="fileName">The document to be opened.</param>
        /// <param name="loader">The loader associated with the file type.</param>
        /// <param name="roiObjects">list of RegionOfInterest to add to the ImageView</param>
        /// <returns>A <see cref="bool"/> value indicating the success of the attempt to open a document.</returns>
        internal bool OpenDocument(string fileName, ISpecFileLoader loader, List <RegionOfInterest> roiObjects)
        {
            if (loader == null || string.IsNullOrEmpty(fileName))
            {
                return(false);
            }

            ISpecFileContent specFileContent = loader.Load(fileName);

            if (specFileContent == null)
            {
                return(false);
            }

            Document doc = specFileContent.Document;

            if (doc == null)
            {
                return(false);
            }

            AppContext.DocumentList.Add(doc);

            ViewCollection views = specFileContent.GetContentViews(doc);

            if (views != null)
            {
                foreach (ViewImage view in views)
                {
                    // Add in the ImageDataObject to each of the roiObjects
                    // Probably not the best place to put this.. but will do for now.
                    foreach (RegionOfInterest regionofinterest in roiObjects)
                    {
                        regionofinterest.ImageData = view.GetImagingData();
                    }

                    view.RoiObjects = roiObjects;
                    view.RoiInitialSetup();
                }

                foreach (IView view in views)
                {
                    AppContext.Application.AddView(view);
                    doc.ViewCollection.Add(view);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Opens the document specified by the given <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">The document to be opened.</param>
        /// <returns>A <see cref="bool"/> value indicating the success of the attempt to open a document.</returns>
        public bool OpenDocument(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(false);
            }

            // identify the loader on the basis of the extension...
            string          extension = Path.GetExtension(fileName);
            ISpecFileLoader loader    = AppContext.SpecFileLoaders.FindSupportingLoader(extension);

            return(this.OpenDocument(fileName, loader));
        }
コード例 #4
0
        /// <summary>
        /// A new version of OpenDocument that allows views to be opened via the ROI Project UI
        /// it includes a list of ROI objects associated to this view
        /// </summary>
        /// <param name="fileName">File name/path of file containing the image</param>
        /// <param name="roiObjects">List of RegionOfInterest Object</param>
        /// <returns>value indicating the success of the attempt to open a document</returns>
        public bool OpenDocument(string fileName, List <RegionOfInterest> roiObjects)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(false);
            }

            // identify the loader on the basis of the extension...
            string          extension = Path.GetExtension(fileName);
            ISpecFileLoader loader    = AppContext.SpecFileLoaders.FindSupportingLoader(extension);

            bool returnresult = this.OpenDocument(fileName, loader, roiObjects);

            return(returnresult);
        }
コード例 #5
0
        /// <summary>
        /// Opens the document specified by the given <paramref name="fileName"/>
        /// and uses the specified  <paramref name="loader"/>.
        /// </summary>
        /// <param name="fileName">The document to be opened.</param>
        /// <param name="loader">The loader associated with the file type.</param>
        /// <returns>A <see cref="bool"/> value indicating the success of the attempt to open a document.</returns>
        internal bool OpenDocument(string fileName, ISpecFileLoader loader)
        {
            if (loader == null || string.IsNullOrEmpty(fileName))
            {
                return(false);
            }

            ISpecFileContent specFileContent = loader.Load(fileName);

            if (specFileContent == null)
            {
                return(false);
            }

            Document doc = specFileContent.Document;

            if (doc == null)
            {
                return(false);
            }

            AppContext.DocumentList.Add(doc);

            ViewCollection views = specFileContent.GetContentViews(doc);

            if (views != null)
            {
                foreach (IView view in views)
                {
                    AppContext.Application.AddView(view);
                    doc.ViewCollection.Add(view);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Load and convert the file specified by <paramref name="fileName"/> to the format specified by <paramref name="targetExt"/>
        /// and/or create a bitmap of the file. The bitmap format is defined by <paramref name="bitmapExt"/>. The result will be stored
        /// in the directory given by <paramref name="targetDir"/>.
        /// </summary>
        /// <param name="fileName">The full qualified filename of the file to process.</param>
        /// <param name="targetDir">The directory where the results should be stored.</param>
        /// <param name="targetExt">The target format to which to convert the given file. If empty, no conversion takes place.</param>
        /// <param name="bitmapExt">If not empty a bitmap of the type specified by this extension is created from the files (image) content.</param>
        /// <param name="bitmapDir">Specifies an additional directory where a copy of the bitmap (if any) should be created.</param>
        /// <returns>A <see cref="bool"/> value indicating the success of the operation.</returns>
        public bool BatchProcess(string fileName, string targetDir, string targetExt, string bitmapExt, string bitmapDir)
        {
            if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
            {
                return(false);
            }

            // load the file...
            try
            {
                // identify the loader on the basis of the extension...
                string          extension = Path.GetExtension(fileName);
                ISpecFileLoader loader    = AppContext.SpecFileLoaders.FindSupportingLoader(extension);
                if (loader == null)
                {
                    return(false);
                }

                // find the matching image writer
                IImagingWriter imageWriter = null;
                if (!string.IsNullOrEmpty(targetExt))
                {
                    foreach (var candidate in AppContext.ImagingWriters)
                    {
                        if (candidate != null)
                        {
                            bool found = false;
                            foreach (FileTypeDescriptor fileType in candidate.SupportedFileTypes)
                            {
                                if (fileType != null && fileType.IncludesExtension(targetExt))
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (found)
                            {
                                imageWriter = candidate;
                                break;
                            }
                        }
                    }
                }

                // find the matching bitmap writer
                IBitmapWriter bitmapWriter = null;
                if (!string.IsNullOrEmpty(bitmapExt))
                {
                    foreach (IBitmapWriter candidate in AppContext.BitmapWriters)
                    {
                        if (candidate != null)
                        {
                            bool found = false;
                            foreach (FileTypeDescriptor fileType in candidate.SupportedFileTypes)
                            {
                                if (fileType != null && fileType.IncludesExtension(bitmapExt))
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (found)
                            {
                                bitmapWriter = candidate as BitmapWriter;
                                break;
                            }
                        }
                    }
                }

                if (imageWriter == null && bitmapWriter == null)
                {
                    // no appropriate writers found for requested operation
                    return(false);
                }

                // let the loader load
                ISpecFileContent specFileContent = loader.Load(fileName);
                if (specFileContent == null)
                {
                    return(false);
                }

                BaseObjectList baseObjects = specFileContent.GetContent();
                if (baseObjects == null)
                {
                    return(false);
                }

                string outDir   = (!string.IsNullOrEmpty(targetDir) && Directory.Exists(targetDir)) ? targetDir : Path.GetDirectoryName(fileName);
                string filename = Path.GetFileNameWithoutExtension(fileName);

                // loop over the images an process
                foreach (BaseObject baseObject in baseObjects)
                {
                    var imaging = baseObject as Imaging;
                    if (imaging == null)
                    {
                        continue;
                    }

                    // perform image conversion if requested...
                    if (imageWriter != null)
                    {
                        // compose filename
                        string targetFile = filename + " - " + imaging.Name;
                        targetFile = Util.SubstitueInvalidPathChars(targetFile, '-');
                        targetFile = targetFile.Replace('.', '_');
                        targetFile = Path.Combine(outDir, targetFile + targetExt);
                        imageWriter.Write(imaging, targetFile, false);
                    }

                    // create a bitmap if required
                    if (bitmapWriter != null)
                    {
                        BitmapSourceList bitmaps = imaging.GetBitmaps();
                        if (bitmaps != null && bitmaps.Count > 0)
                        {
                            System.Windows.Media.Imaging.BitmapSource bitmap = bitmaps[0];
                            if (bitmap != null)
                            {
                                // compose filename
                                string bitmapFileName = filename + " - " + imaging.Name;
                                bitmapFileName = Util.SubstitueInvalidPathChars(bitmapFileName, '-');
                                bitmapFileName = bitmapFileName.Replace('.', '_');
                                string bitmapFilePath = Path.Combine(outDir, bitmapFileName + bitmapExt);
                                bitmapWriter.Write(bitmap, bitmapFilePath, false);
                                if (!string.IsNullOrEmpty(bitmapDir) && Directory.Exists(bitmapDir))
                                {
                                    bitmapFilePath = Path.Combine(bitmapDir, bitmapFileName + bitmapExt);
                                    bitmapWriter.Write(bitmap, bitmapFilePath, false);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Util.ReportException(e);
                return(false);
            }

            return(true);
        }