예제 #1
0
        public static KnowledgeItem CombineQuotations(List <KnowledgeItem> quotations)
        {
            if (quotations.Count() == 1)
            {
                return(quotations.FirstOrDefault());
            }
            if (quotations.Count == 0)
            {
                return(null);
            }

            // Static Variables

            PreviewControl previewControl = PreviewMethods.GetPreviewControl();

            if (previewControl == null)
            {
                return(null);
            }

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

            if (pdfViewControl == null)
            {
                return(null);
            }

            Document document = pdfViewControl.Document;

            if (document == null)
            {
                return(null);
            }

            Reference reference = quotations.FirstOrDefault().Reference;

            if (reference == null)
            {
                return(null);
            }

            Project project = Program.ActiveProjectShell.Project;

            if (project == null)
            {
                return(null);
            }

            List <Location> locations = quotations.GetPDFLocations().Distinct().ToList();

            if (locations.Count != 1)
            {
                return(null);
            }
            Location location = locations.FirstOrDefault();

            List <QuotationType> quotationTypes = quotations.Select(q => q.QuotationType).Distinct().ToList();
            var itemToRemove = quotationTypes.SingleOrDefault(q => q == QuotationType.Highlight);

            quotationTypes.Remove(itemToRemove);

            QuotationType quotationType = quotationTypes.FirstOrDefault();

            if (quotationTypes.Count == 0)
            {
                quotationType = QuotationType.Highlight;
            }

            // Dynamic Variables

            KnowledgeItem newQuotation = new KnowledgeItem(reference, quotationType);

            string text = string.Empty;

            List <Quad>      quads          = new List <Quad>();
            List <PageRange> pageRangesList = new List <PageRange>();
            string           pageRangeText  = string.Empty;

            List <PageWidth> store = new List <PageWidth>();

            // The Magic

            if (document != null)
            {
                for (int i = 1; i <= document.GetPageCount(); i++)
                {
                    pdftron.PDF.Page page = document.GetPage(i);
                    if (page.IsValid())
                    {
                        var re = page.GetCropBox();
                        store.Add(new PageWidth(location, i, re.Width()));
                    }
                    else
                    {
                        store.Add(new PageWidth(location, i, 0.00));
                    }
                }
            }

            quotations.Sort(new KnowledgeItemComparer(store));

            foreach (KnowledgeItem quotation in quotations)
            {
                if (!string.IsNullOrEmpty(quotation.Text))
                {
                    text = MergeRTF(text, quotation.TextRtf);
                }
                if (!string.IsNullOrEmpty(quotation.PageRange.OriginalString))
                {
                    pageRangesList.Add(quotation.PageRange);
                }
            }

            pageRangesList = PageRangeMerger.MergeAdjacent(pageRangesList);
            pageRangeText  = PageRangeMerger.PageRangeListToString(pageRangesList);

            newQuotation.TextRtf   = text;
            newQuotation.PageRange = pageRangeText;
            newQuotation.PageRange = newQuotation.PageRange.Update(quotations[0].PageRange.NumberingType);
            newQuotation.PageRange = newQuotation.PageRange.Update(quotations[0].PageRange.NumeralSystem);

            reference.Quotations.Add(newQuotation);
            project.AllKnowledgeItems.Add(newQuotation);

            return(newQuotation);
        }
예제 #2
0
        public static void CreatesummaryOnQuotations(List <KnowledgeItem> quotations)
        {
            Reference reference = Program.ActiveProjectShell.PrimaryMainForm.ActiveReference;

            if (reference == null)
            {
                return;
            }

            Project project = reference.Project;

            if (project == null)
            {
                return;
            }

            PreviewControl previewControl = Program.ActiveProjectShell.PrimaryMainForm.PreviewControl;

            if (previewControl == null)
            {
                return;
            }

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

            if (pdfViewControl == null)
            {
                return;
            }

            Document document = pdfViewControl.Document;

            if (document == null)
            {
                return;
            }

            Location location = reference.Locations.Where
                                (
                l =>
                l.LocationType == LocationType.ElectronicAddress &&
                l.Address.Resolve().LocalPath.EndsWith(".pdf") &&
                l.Address.Resolve().LocalPath == document.GetFileName()
                                )
                                .FirstOrDefault();

            if (location == null)
            {
                return;
            }

            Control quotationSmartRepeater = Program.ActiveProjectShell.PrimaryMainForm.Controls.Find("quotationSmartRepeater", true).FirstOrDefault();

            SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater quotationSmartRepeaterAsQuotationSmartRepeater = quotationSmartRepeater as SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater;

            List <PageRange> pageRanges = new List <PageRange>();
            List <Quad>      quads      = new List <Quad>();

            Annotation newAnnotation = new Annotation(location);

            KnowledgeItem summary = new KnowledgeItem(reference, QuotationType.Summary);

            reference.Quotations.Add(summary);

            foreach (KnowledgeItem quotation in quotations)
            {
                pageRanges.Add(quotation.PageRange);

                EntityLink summaryQuotationLink = new EntityLink(project);
                summaryQuotationLink.Source     = summary;
                summaryQuotationLink.Target     = quotation;
                summaryQuotationLink.Indication = EntityLink.CommentOnQuotationIndication;
                project.EntityLinks.Add(summaryQuotationLink);

                Annotation quotationAnnotation = quotation.EntityLinks.Where(link => link.Target is Annotation).FirstOrDefault().Target as Annotation;
                if (quotationAnnotation == null)
                {
                    continue;
                }

                quads.AddRange(quotationAnnotation.Quads);
            }

            newAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0);
            newAnnotation.Quads         = quads;
            newAnnotation.Visible       = false;

            location.Annotations.Add(newAnnotation);

            summary.PageRange = PageRangeMerger.PageRangeListToString(pageRanges);
            summary.CoreStatementUpdateType = UpdateType.Automatic;

            EntityLink summaryAnnotationLink = new EntityLink(project);

            summaryAnnotationLink.Source     = summary;
            summaryAnnotationLink.Target     = newAnnotation;
            summaryAnnotationLink.Indication = EntityLink.PdfKnowledgeItemIndication;
            project.EntityLinks.Add(summaryAnnotationLink);

            quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate(summary, true);
            pdfViewControl.GoToAnnotation(newAnnotation);
        }