reference_editor.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:22k
- /*
- * ===========================================================================
- * PRODUCTION $Log: reference_editor.cpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 21:02:25 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
- * PRODUCTION
- * ===========================================================================
- */
- /*
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software / database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software / database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Lou Friedman
- *
- * File Description:
- * Implementaion of CReferenceEntryForm reference editing
- *
- */
- #include <ncbi_pch.hpp>
- #include "reference_editor.hpp"
- #include "auth_form.hpp"
- #include <gui/dialogs/entry_form/table.hpp>
- #include <corelib/ncbistre.hpp>
- #include <serial/iterator.hpp>
- #include <objects/general/Object_id.hpp>
- #include <objects/general/Date.hpp>
- #include <objects/general/Date_std.hpp>
- #include <objects/general/Person_id.hpp>
- #include <objects/general/Name_std.hpp>
- #include <objects/seq/Pubdesc.hpp>
- #include <objects/seq/Seq_inst.hpp>
- #include <objects/pub/Pub.hpp>
- #include <objects/pub/Pub_equiv.hpp>
- #include <objects/biblio/Cit_art.hpp>
- #include <objects/biblio/Cit_book.hpp>
- #include <objects/biblio/Cit_gen.hpp>
- #include <objects/biblio/Cit_jour.hpp>
- #include <objects/biblio/Cit_let.hpp>
- #include <objects/biblio/Cit_pat.hpp>
- #include <objects/biblio/Cit_proc.hpp>
- #include <objects/biblio/Cit_sub.hpp>
- #include <objects/biblio/Imprint.hpp>
- #include <objects/biblio/PubMedId.hpp>
- #include <objects/biblio/Auth_list.hpp>
- #include <objects/biblio/Author.hpp>
- #include <objects/biblio/Title.hpp>
- #include "paragraph.hpp"
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- SEditorFlatPub::SEditorFlatPub (CPubdesc* pub)
- : m_Pubdesc(0), m_Pub(0), m_CitType(CPub::e_not_set),
- m_PubClass(ePubClass_not_set), m_Medline_entry(0), m_PubMedId(0),
- m_Pub_equiv(0), m_Auth_list(0), m_Imprint(0), m_Title(0),
- m_Meeting(0), m_Date(0), m_FromAuth_list(0), m_FromImprint(0),
- m_FromTitle(0), m_Muid(0), m_Pmid(0)
- {
- m_Pubdesc = pub;
- m_Pub = NULL;
-
- NON_CONST_ITERATE (CPub_equiv::Tdata, it, pub->SetPub().Set()) {
- x_Init (**it);
- }
- }
- void SEditorFlatPub::x_Init (CPub& pub)
- {
- m_CitType = pub.Which();
- switch (m_CitType) {
- case CPub::e_Gen:
- {{
- m_Pub = &pub;
- CCit_gen& cit = pub.SetGen();
- if (cit.IsSetCit()) {
- if (NStr::CompareNocase(cit.GetCit(), "unpublished") == 0) {
- m_PubClass = eUnpub;
- } else if (NStr::CompareNocase(cit.GetCit(),
- "Online Publication") == 0 ||
- NStr::CompareNocase(cit.GetCit(),
- "Published Only in DataBase") == 0) {
- m_PubClass = eOnline;
- } else { // Assumed to be a journal publication
- m_PubClass = eJournal;
- }
-
- }
- if (cit.IsSetAuthors()) m_Auth_list = &cit.SetAuthors();
- if (cit.IsSetDate()) m_Date = &cit.SetDate();
-
- break;
- }}
- case CPub::e_Sub:
- {{
- CCit_sub& cit = pub.SetSub();
- m_Auth_list = &cit.SetAuthors();
- if (cit.IsSetImp()) {
- m_Date = &cit.SetImp().SetDate();
- } else {
- if (cit.IsSetDate()) m_Date = &cit.SetDate();
- }
- m_Pub = &pub;
- m_PubClass = eUnpub;
- break;
- }}
- case CPub::e_Medline:
- break;
- case CPub::e_Muid:
- m_Muid = pub.GetMuid();
- break;
- case CPub::e_Article:
- {{
- CCit_art& cit = pub.SetArticle();
- if (cit.IsSetAuthors()) m_Auth_list = &cit.SetAuthors();
- if (cit.IsSetTitle()) m_Title = &cit.SetTitle();
-
- m_Pub = &pub;
- CCit_art::C_From& from = cit.SetFrom();
- if (from.IsJournal()) {
- CCit_jour& from_cit = from.SetJournal();
- m_PubClass = eJournal;
- m_Imprint = &from_cit.SetImp();
- m_FromTitle = &from_cit.SetTitle();
- } else if (from.IsBook()) {
- CCit_book& from_cit = from.SetBook();
- m_PubClass = eBookChapter;
- m_Imprint = &from_cit.SetImp();
- m_FromTitle = &from_cit.SetTitle();
- m_FromAuth_list = &from_cit.SetAuthors();
- } else if (from.IsProc()) {
- CCit_proc& from_cit = from.SetProc();
- m_PubClass = eProcChapter;
- m_Meeting = &from_cit.SetMeet();
- CCit_book& citbook = from_cit.SetBook();
- m_Imprint = &citbook.SetImp();
- m_FromTitle = &citbook.SetTitle();
- m_FromAuth_list = &citbook.SetAuthors();
- } else {
- }
- break;
- }}
- case CPub::e_Journal:
- {{
- CCit_jour& cit = pub.SetJournal();
- m_Imprint = &cit.SetImp();
- m_Title = &cit.SetTitle();
- m_Pub = &pub;
- m_PubClass = eJournal;
- }}
- case CPub::e_Book:
- {{
- CCit_book& cit = pub.SetBook();
- m_Imprint = &cit.SetImp();
- m_Title = &cit.SetTitle();
- m_Auth_list = &cit.SetAuthors();
- m_Pub = &pub;
- m_PubClass = eBook;
- break;
- }}
- case CPub::e_Proc:
- {{
- CCit_proc& cit = pub.SetProc();
- m_Meeting = &cit.SetMeet();
- CCit_book& citbook = cit.SetBook();
- m_Imprint = &citbook.SetImp();
- m_Title = &citbook.SetTitle();
- m_Auth_list = &citbook.SetAuthors();
- m_Pub = &pub;
- m_PubClass = eProc;
-
- break;
- }}
- case CPub::e_Patent:
- break;
- case CPub::e_Man:
- break;
- case CPub::e_Equiv:
- #if 0
- ITERATE (CPub_equiv::Tdata, it, pub.GetEquiv().Get()) {
- x_Init(**it, ctx);
- }
- #endif
- break;
- case CPub::e_Pmid:
- {{
- m_Pmid = pub.GetPmid().Get();
- break;
- }}
- default:
- break;
- } // switch
- if (m_Date == 0 && m_Imprint) {
- m_Date = & m_Imprint->SetDate();
- }
- }
- SEditorFlatPub::EPubStatus SEditorFlatPub::GetPubStatus ()
- {
- if (m_CitType == CPub::e_Sub) {
- return SEditorFlatPub::eUnpublished;
- }
- if (m_CitType == CPub::e_Gen) {
- const CCit_gen& g = m_Pub->GetGen();
- if (g.IsSetCit() &&
- NStr::CompareNocase(g.GetCit(), "unpublished") == 0) {
- return SEditorFlatPub::eUnpublished;
- } else {
- return SEditorFlatPub::ePublished;
- }
- }
- if (m_Imprint && m_Imprint->IsSetPrepub()) {
- if (m_Imprint->GetPrepub() == CImprint::ePrepub_submitted) {
- return SEditorFlatPub::eUnpublished;
- } else if (m_Imprint->GetPrepub() == CImprint::ePrepub_in_press) {
- return SEditorFlatPub::eIn_press;
- }
- }
- return SEditorFlatPub::ePublished;
- }
- // Menu Declarations
- SMenuEntryInfo RefStatusEntries [] = {
- { "Unpublished", SEditorFlatPub::eUnpublished,
- &CReferenceEntryForm::DeactivateRefClassMenu },
- { "In Press", SEditorFlatPub::eIn_press,
- &CReferenceEntryForm::ActivateRefClassMenu },
- { "Published", SEditorFlatPub::ePublished,
- &CReferenceEntryForm::ActivateRefClassMenu },
- { 0, 0 }
- };
- CEntryFormMenu SRefStatusMenu(RefStatusEntries);
- // user data is set to 1. This indicates a redraw should
- // be called in the cb_UnpubUI and cb_PubUI call backs.
- SMenuEntryInfo RefClassEntries [] = {
- { " ", SEditorFlatPub::eUnpub,
- &CReferenceEntryForm::cb_UnpubUI, (void*)1 },
- { "Journal", SEditorFlatPub::eJournal,
- &CReferenceEntryForm::cb_PubUI, (void*)1 },
- { "Book Chapter", SEditorFlatPub::eBookChapter,
- &CReferenceEntryForm::cb_PubUI, (void*)1 },
- { "Book", SEditorFlatPub::eBook,
- &CReferenceEntryForm::cb_PubUI, (void*)1 },
- { "Thesis / Monograph", SEditorFlatPub::eThesis,
- &CReferenceEntryForm::cb_PubUI, (void*)1 },
- { "Proceedings Chapter", SEditorFlatPub::eProcChapter,
- &CReferenceEntryForm::cb_PubUI, (void*)1 },
- { "Proceedings", SEditorFlatPub::eProc,
- &CReferenceEntryForm::cb_PubUI, (void*)1 },
- { "Patent", SEditorFlatPub::ePatent,
- &CReferenceEntryForm::cb_PubUI, (void*)1 },
- { "Online Publication", SEditorFlatPub::eOnline,
- &CReferenceEntryForm::cb_PubUI, (void*)1 },
- { 0, 0 }
- };
- CEntryFormMenu SRefClassMenu(RefClassEntries);
- SMenuEntryInfo RefScopeEntries [] = {
- { "Refers to the entire sequence", 0 },
- { "Refers to part of the sequence", 0 },
- { "Cites a feature on the sequence", 0 },
- { 0, 0 }
- };
- CEntryFormMenu SRefScopeMenu(RefScopeEntries);
- CReferenceEntryForm::CReferenceEntryForm(CParagraph* p)
- : CGenbankEntryForm(p),
- m_FlatPub (const_cast<CPubdesc*> ((CPubdesc*) p->topic()))
-
- {
- CPubdesc* pubdesc =
- const_cast<CPubdesc*> (dynamic_cast<const CPubdesc*> (p->topic()));
- SEditorFlatPub flat_pub (pubdesc);
-
- SetTitle("Reference");
- auto_ptr<CEntryFormTable> t
- (new CEntryFormTable(GetFormWidget()->GetFormWidth(), 5));
- t->AddTitleRow ("Publication Type");
- m_Status = t->AddMenuRow("Status", SRefStatusMenu,
- SRefStatusMenu.FindEntry (m_FlatPub.GetPubStatus()),
- this);
- m_Class = t->AddMenuRow("Class", SRefClassMenu,
- SRefClassMenu.FindEntry (m_FlatPub.m_PubClass), this);
- m_Scope = t->AddMenuRow("Scope", SRefScopeMenu, 0);
- t->End();
- AddEditWidget(t.release());
- if (m_Status->value() == 0) {
- DeactivateRefClassMenu(m_Status, 0);
- }
- int ref_class = m_Class->value();
- if (m_Class->menu()[ref_class].callback()) {
- // user data is 0 to so that a Show will
- // not be issued (look in cb_PubUI and cb_UnpubUI)
- m_Class->menu()[ref_class].do_callback(m_Class, (void *)0);
- }
- }
- CReferenceEntryForm::~CReferenceEntryForm()
- {
- }
- void CReferenceEntryForm::DeactivateRefClassMenu(Fl_Widget* w, void *u)
- {
- CReferenceEntryForm* ref = (CReferenceEntryForm*) w->user_data();
- Fl_Choice* ref_class = ref->m_Class;
- for (int i = 1; ref_class->text(i); i++) {
- ref_class->mode(i, FL_MENU_INACTIVE);
- }
- // Set the Ref Class to blank
- ref_class->value(0);
- // Issue the callback for a Ref Class change
- if (ref_class->menu()[0].callback()) {
- // user data is 1 to so that a Show will
- // be issued (look in cb_PubUI and cb_UnpubUI)
- ref_class->menu()[0].do_callback(ref_class, (void *)1);
- }
-
- }
- void CReferenceEntryForm::ActivateRefClassMenu(Fl_Widget* w, void *u)
- {
- CReferenceEntryForm* ref = (CReferenceEntryForm*) w->user_data();
- Fl_Choice* ref_class = ref->m_Class;
- for (int i = 1; ref_class->text(i); i++) {
- ref_class->mode(i, 0);
- }
- // the default Ref Class is Journal (1)
- int menu_value = 1;
- if (ref->m_FlatPub.m_PubClass != SEditorFlatPub::eUnpub) {
- menu_value = SRefClassMenu.FindEntry (ref->m_FlatPub.m_PubClass);
- }
- ref_class->value(menu_value);
- // Issue the callback for a Ref Class change
- if (ref_class->menu()[menu_value].callback()) {
- // user data is 1 to so that a Show will
- // be issued (look in cb_PubUI and cb_UnpubUI)
- ref_class->menu()[menu_value].do_callback(ref_class, (void *)1);
- }
- }
- SMenuEntryInfo StandardRemarkEntries [] = {
- { " ", 0 },
- { "AA by submitter", 0, &CReferenceEntryForm::cb_StandardRemark},
- { "NT by submitter", 0, &CReferenceEntryForm::cb_StandardRemark},
- { "NT and AA by submitter", 0, &CReferenceEntryForm::cb_StandardRemark},
- { "AA by database", 0, &CReferenceEntryForm::cb_StandardRemark},
- { "NT by database", 0, &CReferenceEntryForm::cb_StandardRemark},
- { "NT and AA by database", 0, &CReferenceEntryForm::cb_StandardRemark},
- { 0, 0, &CReferenceEntryForm::cb_StandardRemark}
- };
- CEntryFormMenu SStandardRemarkMenu(StandardRemarkEntries);
- void CReferenceEntryForm::cb_UnpubUI(Fl_Widget* w, void *u)
- {
- CReferenceEntryForm *ref_ui = (CReferenceEntryForm *) (w->user_data());
- ref_ui->x_UnpubUI();
- // If user data is set, issue a Show to resize
- // and redraw the window.
- // The Show will be issued if the call back was
- // triggered by a Pub Class menu change. The redraw
- // is not issued if called from the constructor.
- if (u) {
- ref_ui->Show();
- }
- }
- void CReferenceEntryForm::x_UnpubUI ()
- {
- string title;
- string remark;
- SEditorFlatPub& flatpub = m_FlatPub;
- CPubdesc* pubdesc = flatpub.m_Pubdesc;
- CPub* pub = flatpub.m_Pub;
- x_Clear();
- auto_ptr<CEntryFormTable>
- t(new CEntryFormTable(GetFormWidget()->GetFormWidth(), 5));
- t->AddTitleRow ("Publication Information");
- if (flatpub.m_CitType == CPub::e_Gen) {
- const CCit_gen& g = pub->GetGen();
- m_Title = t->AddInputRow("Title", " ");
- if (g.IsSetTitle() && m_Title) {
- m_Title->value(g.GetTitle().c_str());
- }
- }
- m_Remark = t->AddInputRow("Remark", " ");
- if (pubdesc->IsSetComment() && m_Remark) {
- m_Remark->value(pubdesc->GetComment().c_str());
- }
- m_StandardRemark = t->AddMenuRow("Use Standard Remark",
- SStandardRemarkMenu, 0, this);
- t->End();
- AddEditWidget(t.release());
- x_AuthUI(flatpub);
- x_DateUI(flatpub);
- }
- void CReferenceEntryForm::cb_PubUI(Fl_Widget* w, void *u)
- {
- CReferenceEntryForm *ref_ui = (CReferenceEntryForm *) (w->user_data());
- ref_ui->x_PubUI();
- // If user data is set, issue a Show to resize
- // and redraw the window.
- // The Show will be issued if the call back was
- // triggered by a Pub Class menu change. The redraw
- // is not issued if called from the constructor.
- if (u) {
- ref_ui->Show();
- }
- }
- void CReferenceEntryForm::x_PubUI()
- {
- string data = " ";
- string remark;
- x_Clear();
- CPubdesc* pubdesc = m_FlatPub.m_Pubdesc;
- auto_ptr<CEntryFormTable>
- t(new CEntryFormTable(GetFormWidget()->GetFormWidth(), 5));
- t->AddTitleRow ("Publication Information");
- if (m_FlatPub.m_Title) {
- try {
- data = m_FlatPub.m_Title->GetTitle();
- }
- catch (...) {
- data = " ";
- }
- }
- m_Title = t->AddInputRow("Title", data.c_str());
- m_Remark = t->AddInputRow("Remark", " ");
- if (pubdesc->IsSetComment() && m_Remark) {
- m_Remark->value(pubdesc->GetComment().c_str());
- }
- m_StandardRemark = t->AddMenuRow("Use Standard Remark",
- SStandardRemarkMenu, 0, this);
- t->End();
- AddEditWidget(t.release());
- // SEditorFlatPub::EPubClass pub_class;
- int pub_class = RefClassEntries[m_Class->value()].m_Value;
- switch (pub_class) {
- case SEditorFlatPub::eJournal:
- x_AuthUI(m_FlatPub);
- x_JournalUI();
- x_DateUI(m_FlatPub);
- break;
- default:
- break;
- }
- }
- void CReferenceEntryForm::x_JournalUI()
- {
- string data;
- string title = " ";
- string volume = " ";
- string issue = " ";
- string pages = " ";
- string muid = " ";
- string pmid = " ";
- auto_ptr<CEntryFormTable>
- t(new CEntryFormTable(GetFormWidget()->GetFormWidth(), 5));
- t->AddTitleRow ("Journal Information");
- if (m_FlatPub.m_FromTitle) {
- try {
- title = m_FlatPub.m_FromTitle->GetTitle();
- }
- catch (...) {
- title = " ";
- }
- }
- CImprint* imp = m_FlatPub.m_Imprint;
- if (imp) {
- if (imp->IsSetVolume()) {
- volume = imp->GetVolume();
- }
- if (imp->IsSetIssue()) {
- issue = imp->GetIssue();
- }
- if (imp->IsSetPages()) {
- pages = imp->GetPages();
- }
- }
- if (m_FlatPub.m_Muid) {
- muid = NStr::IntToString(m_FlatPub.m_Muid);
- }
- if (m_FlatPub.m_Pmid) {
- pmid = NStr::IntToString(m_FlatPub.m_Pmid);
- }
- m_Title = t->AddInputRow("Title", title.c_str(),
- CEntryFormTable::eSingleLine);
- m_Volume = t->AddInputRow("Volume", volume.c_str(),
- CEntryFormTable::eSingleLine);
- m_Issue = t->AddInputRow("Issue", issue.c_str(),
- CEntryFormTable::eSingleLine);
- m_Pages = t->AddInputRow("Pages", pages.c_str(),
- CEntryFormTable::eSingleLine);
- m_Muid = t->AddInputRow("muid", muid.c_str(), CEntryFormTable::eInteger);
- m_Pmid = t->AddInputRow("pmid", pmid.c_str(), CEntryFormTable::eInteger);
- t->End();
- AddEditWidget(t.release());
- }
- void CReferenceEntryForm::cb_StandardRemark (Fl_Widget* w, void *u)
- {
-
- CReferenceEntryForm *ref_ui = (CReferenceEntryForm *) (w->user_data());
-
- Fl_Choice* menu = ref_ui->m_StandardRemark;
- const char* std_remark = menu->menu()[menu->value()].label();
- Fl_Input* input = ref_ui->m_Remark;
- CNcbiStrstream new_remark;
- new_remark << input->value() << " " << std_remark;
- input->value(new_remark.str());
- }
- SMenuEntryInfo DateMonthEntries [] = {
- { " ", 0 },
- { "January", 1 },
- { "February", 2 },
- { "March", 3 },
- { "April", 4 },
- { "May", 5 },
- { "June", 6 },
- { "July", 7 },
- { "August", 8 },
- { "September", 9 },
- { "October", 10 },
- { "November", 11 },
- { "December", 12 },
- { 0, 0 }
- };
- CEntryFormMenu SDateMonthMenu(DateMonthEntries);
- void CReferenceEntryForm::x_DateUI(SEditorFlatPub& flatpub)
- {
- CDate* date = flatpub.m_Date;
- auto_ptr<CEntryFormTable> t
- (new CEntryFormTable(GetFormWidget()->GetFormWidth(), 5));
- t->AddTitleRow("Date");
- m_Year = t->AddInputRow("Year", " ", CEntryFormTable::eInteger);
- m_Month = t->AddMenuRow("Month", SDateMonthMenu, 0);
- m_Day = t->AddInputRow("Day", " ", CEntryFormTable::eInteger);
- t->End();
- AddEditWidget(t.release());
-
- if (date == 0) return;
- if (date->IsStd()) {
- const CDate_std& std_date = date->GetStd();
- m_Year->value(NStr::IntToString(std_date.GetYear()).c_str());
- if (std_date.IsSetMonth()) {
- m_Month->value(std_date.GetMonth());
- }
- if (std_date.IsSetDay()) {
- m_Day->value(NStr::IntToString(std_date.GetDay()).c_str());
- }
- }
- }
- void CReferenceEntryForm::x_AuthUI(SEditorFlatPub& flatpub)
- {
- CAuth_list* auth_list = flatpub.m_Auth_list;
- auto_ptr<CAuthEntryFormTable>
- t(new CAuthEntryFormTable(GetFormWidget()->GetFormWidth(), 5));
- t->AddTitleRow("Authors");
- if (auth_list && auth_list->GetNames().IsStd()) {
-
- ITERATE (CAuth_list::C_Names::TStd, iter,
- auth_list->GetNames().GetStd()) {
- const CPerson_id& id = (*iter)->GetName();
- if (id.IsName()) {
- const CName_std& name = id.GetName();
- Fl_Group* row = t->AddAuthRow();
- if (name.IsSetFirst()) {
- t->FirstName(row, name.GetFirst().c_str());
- if (name.IsSetMiddle()) {
- t->MiddleName(row, name.GetMiddle().c_str());
- }
- } else if (name.IsSetInitials()) {
- const char* initials = name.GetInitials().c_str();
- int len = name.GetInitials().size();
- char letter[2] = " ";
- if (len) {
- *letter = *initials;
- t->FirstName(row, letter);
- if (len == 2 && initials[1] == '.') {
- *letter = initials[1];
- t->MiddleName(row, letter);
- } else if (len >= 3) {
- *letter = initials[2];
- t->MiddleName(row, letter);
- }
- }
- }
- t->LastName(row, name.GetLast().c_str());
- }
- }
- }
- t->AddButtonRow();
- t->End();
- m_Auth_list = t.get();
- AddEditWidget(t.release());
- }
-
- void CReferenceEntryForm::x_Clear()
- {
- while (GetFormWidget()->GetNumEntries() > 1) {
- GetFormWidget()->RemoveWidget(1);
- }
- /**
- Fl_Pack* edit_pack = GetEditPack();
- // remove and delete all the form tables in the entry form
- // except the Publication type (the first form table).
- while (edit_pack->children() > 1) {
- Fl_Widget* w = edit_pack->child(1);
- edit_pack->remove(w);
- delete w;
- }
- **/
- }
-
-
- END_NCBI_SCOPE