예제 #1
0
        public bool ExportAnnotations(string filename)
        {
            var  settings = GetExportAnnotationSettings();
            bool success  = false;

            try
            {
                var documentAnnotations = new DocumentAnnotations(Document);
                using (var longWaitDlg = new LongWaitDlg())
                {
                    longWaitDlg.PerformWork(this, 1000, broker =>
                    {
                        using (var fileSaver = new FileSaver(filename))
                        {
                            documentAnnotations.WriteAnnotationsToFile(broker.CancellationToken, settings, fileSaver.SafeName);
                            fileSaver.Commit();
                        }
                        success = true;
                    });
                }
            }
            catch (Exception e)
            {
                MessageDlg.ShowException(this, e);
                return(false);
            }
            return(success);
        }
예제 #2
0
        private bool Init()
        {
            // Check support required to use this demo
            if (RasterSupport.IsLocked(RasterSupportType.Document))
            {
                Messager.ShowError(this, string.Format(DemosGlobalization.GetResxString(GetType(), "resx_DemoWillExit"), "RasterSupportType.Document"));
                return(false);
            }

            _rasterCodecs = new RasterCodecs();

            _demoOptions = DemoOptions.Load();

            _viewerControl.Visible = false;
            _pagesControl.Visible  = false;

            _documentAnnotations = new DocumentAnnotations(this);

            _viewerControl.BringToFront();

            UpdateUIState();

            LoadDefaultDocument();

            return(true);
        }
        public void TestCommandLineImportAnnotations()
        {
            var         testFilesDir   = new TestFilesDir(TestContext, @"TestA\CommandLineImportAnnotationsTest.zip");
            var         inDocPath      = testFilesDir.GetTestPath("original.sky");
            var         outDocPath     = testFilesDir.GetTestPath("AnnotatedDocument.sky");
            var         annotationPath = testFilesDir.GetTestPath("annotations.csv");
            SrmDocument originalDocument;

            using (var stream = new FileStream(inDocPath, FileMode.Open))
            {
                originalDocument = (SrmDocument) new XmlSerializer(typeof(SrmDocument)).Deserialize(stream);
            }
            Assert.IsTrue(originalDocument.Settings.HasResults);
            var replicateAnnotation =
                originalDocument.Settings.DataSettings.AnnotationDefs.First(
                    def => def.Name == REPLICATE_ANNOTATION);

            Assert.IsNotNull(replicateAnnotation);
            Assert.IsTrue(replicateAnnotation.AnnotationTargets.Contains(AnnotationDef.AnnotationTarget.replicate));
            Assert.AreEqual(AnnotationDef.AnnotationType.text, replicateAnnotation.Type);
            var chromatograms = originalDocument.MeasuredResults.Chromatograms.ToArray();

            Assert.AreNotEqual(0, chromatograms.Length);
            for (int i = 0; i < chromatograms.Length; i++)
            {
                var chromSet = chromatograms[i];
                chromSet = chromSet.ChangeAnnotations(
                    chromSet.Annotations.ChangeAnnotation(replicateAnnotation, "Replicate" + i));
                chromatograms[i] = chromSet;
            }
            SrmDocument annotatedDocument = originalDocument.ChangeMeasuredResults(
                originalDocument.MeasuredResults.ChangeChromatograms(chromatograms));

            Assert.AreNotEqual(originalDocument, annotatedDocument);
            var documentAnnotations = new DocumentAnnotations(annotatedDocument);

            documentAnnotations.WriteAnnotationsToFile(CancellationToken.None, ExportAnnotationSettings.AllAnnotations(annotatedDocument), annotationPath);
            Assert.IsTrue(File.Exists(annotationPath));
            RunCommand("--in=" + inDocPath, "--out=" + outDocPath, "--import-annotations=" + annotationPath);
            Assert.IsTrue(File.Exists(outDocPath));
            SrmDocument outputDocument;

            using (var stream = new FileStream(outDocPath, FileMode.Open))
            {
                outputDocument = (SrmDocument) new XmlSerializer(typeof(SrmDocument)).Deserialize(stream);
            }
            Assert.AreEqual(annotatedDocument.Settings.MeasuredResults.Chromatograms,
                            outputDocument.Settings.MeasuredResults.Chromatograms);
        }
예제 #4
0
 protected override ThreadedPageWorkerPageProcessedEventArgs ProcessPage(int pageNumber)
 {
     // Get the thumbnail for this page
     try
     {
         using (RasterCodecs codecs = new RasterCodecs())
         {
             DocumentAnnotations.SetRasterCodecsOptions(_document, codecs, pageNumber);
             RasterImage thumbnailImage = _document.GetThumbnail(codecs, pageNumber, _thumbnailWidth, _thumbnailHeight);
             return(new ThreadedPageWorkerPageProcessedEventArgs(pageNumber, thumbnailImage, null));
         }
     }
     catch (Exception e)
     {
         return(new ThreadedPageWorkerPageProcessedEventArgs(pageNumber, null, e));
     }
 }
예제 #5
0
        protected override void DoTest()
        {
            RunUI(() => SkylineWindow.OpenFile(TestFilesDir.GetTestPath("ImportAnnotationsTest.sky")));
            WaitForDocumentLoaded();
            var annotationAdder = new AnnotationAdder();

            Assert.IsTrue(SkylineWindow.SetDocument(annotationAdder.DefineTestAnnotations(SkylineWindow.Document), SkylineWindow.Document));
            var    annotatedDocument   = annotationAdder.AddAnnotationTestValues(SkylineWindow.Document);
            var    documentAnnotations = new DocumentAnnotations(annotatedDocument);
            string annotationPath      = TestFilesDir.GetTestPath("annotations.csv");

            documentAnnotations.WriteAnnotationsToFile(CancellationToken.None, annotationPath);
            RunUI(() => SkylineWindow.ImportAnnotations(annotationPath));
            Assert.AreEqual(annotatedDocument, SkylineWindow.Document);
            using (var reader = new StreamReader(annotationPath))
            {
                var lines = reader.ReadToEnd().Split('\n').Where(line => !string.IsNullOrEmpty(line)).ToArray();
                Assert.AreEqual(annotationAdder.ElementCount + 1, lines.Length);
            }
        }
예제 #6
0
        public void GotoPage(int pageNumber, bool resetFindText)
        {
            if (_document == null || pageNumber <= 0)
            {
                return;
            }

            try
            {
                _viewerControl.HighlightSelectedImageObject = false;
                using (WaitCursor wait = new WaitCursor())
                {
                    DocumentAnnotations.SetRasterCodecsOptions(_document, _rasterCodecs, pageNumber);
                    RasterImage pageImage = _document.GetPageImage(_rasterCodecs, pageNumber);

                    _currentPageNumber = pageNumber;

                    _pagesControl.SetCurrentPageNumber(pageNumber);
                    _viewerControl.SetCurrentPageNumber(pageNumber, pageImage);
                    _documentAnnotations.SetCurrentPageNumber(pageNumber);
                    //set function will hide/show objects
                    _documentAnnotations.IsAnnotationsVisible = _documentAnnotations.IsAnnotationsVisible;
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
            finally
            {
                if (resetFindText)
                {
                    _findTextHelper.Reset();
                }

                UpdateUIState();
            }
        }
        private static void SetAnnotationOnDocument(Organization organization)
        {
            Console.WriteLine("SetAnnotationOnDocument");

            string fileCabinetId = "00000000-0000-0000-0000-000000000000";
            int    documentId    = 4;
            int    pageNumber    = 0;
            int    sectionNumber = 0;
            int    layer         = 1; //Layer can be 1 to 5

            FileCabinet fileCabinet = organization.GetFileCabinetsFromFilecabinetsRelation().FileCabinet
                                      .FirstOrDefault(fc => fc.Id == fileCabinetId);

            if (fileCabinet == null)
            {
                Console.WriteLine("FileCabinet is null!");
            }
            else
            {
                Platform.ServerClient.Document document = fileCabinet.GetDocumentsQueryResultFromDocumentsRelation()
                                                          .Items
                                                          .FirstOrDefault(d => d.Id == documentId);

                if (document == null)
                {
                    Console.WriteLine("Document is null!");
                }
                else
                {
                    document = document.GetDocumentFromSelfRelation();

                    Annotation annotation = new Annotation()
                    {
                        Layer = new List <Layer>()
                        {
                            new Layer()
                            {
                                Id    = layer,
                                Items = new List <EntryBase>()
                                {
                                    new TextEntry()
                                    {
                                        Location = new AnnotationRectangle()
                                        {
                                            Left   = 100,
                                            Top    = 100,
                                            Width  = 200,
                                            Height = 200
                                        },
                                        Value = "Test text",
                                        Font  = new Font()
                                        {
                                            FontSize = 10 * 20,
                                            FontName = "Arial"
                                        }
                                    },
                                    new RectEntry()
                                    {
                                        Location = new AnnotationRectangle()
                                        {
                                            Left   = 300,
                                            Top    = 300,
                                            Width  = 200,
                                            Height = 200
                                        },
                                        Filled  = true,
                                        Ellipse = true
                                    },
                                    new LineEntry()
                                    {
                                        From = new AnnotationPoint()
                                        {
                                            X = 500, Y = 500
                                        },
                                        To = new AnnotationPoint()
                                        {
                                            X = 800, Y = 800
                                        },
                                        Arrow = true,
                                    }
                                }
                            }
                        }
                    };

                    DocumentAnnotationsPlacement documentAnnotationsPlacement = new DocumentAnnotationsPlacement()
                    {
                        Annotations = new List <SectionAnnotationsPlacement>()
                        {
                            new SectionAnnotationsPlacement()
                            {
                                PageNumber           = pageNumber,
                                SectionNumber        = sectionNumber,
                                AnnotationsPlacement = new AnnotationsPlacement()
                                {
                                    Items = new List <object>()
                                    {
                                        annotation
                                    }
                                }
                            }
                        }
                    };

                    DocumentAnnotations documentAnnotations = document.PostToAnnotationRelationForDocumentAnnotations(documentAnnotationsPlacement);
                }
            }
        }
        private static void SetStampOnDocumentWithSpecificPosition(Organization organization)
        {
            Console.WriteLine("SetStampOnDocumentWithSpecificPosition");

            string fileCabinetId = "00000000-0000-0000-0000-000000000000";
            int    documentId    = 1;
            string stampId       = "00000000-0000-0000-0000-000000000000";
            int    layer         = 2; //Layer can be 1 to 5
            double locationX     = 100;
            double locationY     = 100;
            string itemValue     = "December";
            int    pageNumber    = 0;
            int    sectionNumber = 0;

            FileCabinet fileCabinet = organization.GetFileCabinetsFromFilecabinetsRelation().FileCabinet
                                      .FirstOrDefault(fc => fc.Id == fileCabinetId);

            if (fileCabinet == null)
            {
                Console.WriteLine("FileCabinet is null!");
            }
            else
            {
                Platform.ServerClient.Document document = fileCabinet.GetDocumentsQueryResultFromDocumentsRelation()
                                                          .Items
                                                          .FirstOrDefault(d => d.Id == documentId);

                if (document == null)
                {
                    Console.WriteLine("Document is null!");
                }
                else
                {
                    document = document.GetDocumentFromSelfRelation();


                    StampPlacement stampPlacement = new StampPlacement()
                    {
                        StampId  = stampId,
                        Layer    = layer,
                        Location = new DWPoint()
                        {
                            X = locationX,
                            Y = locationY
                        },
                        Field = new List <FormFieldValue>()
                        {
                            new FormFieldValue()
                            {
                                Name       = "<#1>",
                                TypedValue = new DocumentIndexFieldValue()
                                {
                                    ItemElementName = ItemChoiceType.String,
                                    Item            = itemValue
                                }
                            }
                        }
                    };

                    DocumentAnnotationsPlacement documentAnnotationsPlacement = new DocumentAnnotationsPlacement()
                    {
                        Annotations = new List <SectionAnnotationsPlacement>()
                        {
                            new SectionAnnotationsPlacement()
                            {
                                PageNumber           = pageNumber,
                                SectionNumber        = sectionNumber,
                                AnnotationsPlacement = new AnnotationsPlacement()
                                {
                                    Items = new List <object>()
                                    {
                                        stampPlacement
                                    }
                                }
                            }
                        }
                    };

                    DocumentAnnotations documentAnnotations = document.PostToAnnotationRelationForDocumentAnnotations(documentAnnotationsPlacement);
                }
            }
        }