6325
8848
ClearFeatProducts (i, FEATDEF_mRNA);
8851
static void ConsolidateOneLikeSubSourceModifier (
8852
SubSourcePtr match_to,
8853
Boolean use_semicolon
8856
SubSourcePtr prev, index;
8857
Int4 len, num_matches;
8860
if (match_to == NULL) return;
8861
len = StringLen (match_to->name) + 1;
8864
index = match_to->next;
8865
while (index != NULL)
8867
if (index->subtype == match_to->subtype && index->name != NULL)
8869
len += StringLen (index->name) + 2;
8872
index = index->next;
8874
if (num_matches == 0) return;
8876
new_value = MemNew (len * sizeof (char));
8877
if (new_value == NULL) return;
8879
StringCpy (new_value, match_to->name);
8880
index = match_to->next;
8881
while (index != NULL)
8883
if (index->subtype == match_to->subtype && index->name != NULL)
8887
StringCat (new_value, "; ");
8891
StringCat (new_value, " ");
8893
StringCat (new_value, index->name);
8894
prev->next = index->next;
8896
SubSourceFree (index);
8900
index = index->next;
8902
MemFree (match_to->name);
8903
match_to->name = new_value;
8906
static void ConsolidateOneLikeOrganismModifier (
8908
Boolean use_semicolon
8911
OrgModPtr prev, index;
8912
Int4 len, num_matches;
8915
if (match_to == NULL) return;
8916
len = StringLen (match_to->subname) + 1;
8919
index = match_to->next;
8920
while (index != NULL)
8922
if (index->subtype == match_to->subtype && index->subname != NULL)
8924
len += StringLen (index->subname) + 2;
8927
index = index->next;
8929
if (num_matches == 0) return;
8931
new_value = MemNew (len * sizeof (char));
8932
if (new_value == NULL) return;
8934
StringCpy (new_value, match_to->subname);
8935
index = match_to->next;
8936
while (index != NULL)
8938
if (index->subtype == match_to->subtype && index->subname != NULL)
8942
StringCat (new_value, "; ");
8946
StringCat (new_value, " ");
8948
StringCat (new_value, index->subname);
8949
prev->next = index->next;
8955
index = index->next;
8957
MemFree (match_to->subname);
8958
match_to->subname = new_value;
8961
static void ConsolidateLikeModifiersProc (BioSourcePtr biop, Pointer userdata)
8965
Boolean use_semicolon;
8967
if (biop == NULL || userdata == NULL) return;
8969
use_semicolon = *((Boolean PNTR) userdata);
8971
for (ssp = biop->subtype; ssp != NULL; ssp = ssp->next)
8973
if (ssp->name != NULL)
8975
ConsolidateOneLikeSubSourceModifier (ssp, use_semicolon);
8979
if (biop->org == NULL || biop->org->orgname == NULL) return;
8980
for (mod = biop->org->orgname->mod; mod != NULL; mod = mod->next)
8982
if (mod->subname != NULL)
8984
ConsolidateOneLikeOrganismModifier (mod, use_semicolon);
8989
static void ConsolidateLikeModifiers (IteM i, Boolean use_semicolon)
8995
bfp = currentFormDataPtr;
8997
bfp = GetObjectExtra (i);
8999
if (bfp == NULL) return;
9000
sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
9001
if (sep == NULL) return;
9002
VisitBioSourcesInSep (sep, &use_semicolon, ConsolidateLikeModifiersProc);
9003
ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
9004
ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
9007
extern void ConsolidateLikeModifiersWithSemicolons (IteM i)
9009
ConsolidateLikeModifiers (i, TRUE);
9012
extern void ConsolidateLikeModifiersWithoutSemicolons (IteM i)
9014
ConsolidateLikeModifiers (i, FALSE);
9017
static void ConsolidateOrganismNotesProc (BioSourcePtr biop, Pointer userdata)
9019
SubSourcePtr ssp, note_ssp;
9020
OrgModPtr mod, note_mod;
9022
if (biop == NULL) return;
9024
for (ssp = biop->subtype; ssp != NULL; ssp = ssp->next)
9026
if (ssp->subtype == 255 && ssp->name != NULL)
9028
ConsolidateOneLikeSubSourceModifier (ssp, TRUE);
9033
if (biop->org == NULL || biop->org->orgname == NULL) return;
9034
for (mod = biop->org->orgname->mod; mod != NULL; mod = mod->next)
9036
if (mod->subtype == 255 && mod->subname != NULL)
9038
ConsolidateOneLikeOrganismModifier (mod, TRUE);
9044
extern void ConsolidateOrganismNotes (IteM i)
9050
bfp = currentFormDataPtr;
9052
bfp = GetObjectExtra (i);
9054
if (bfp == NULL) return;
9055
sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
9056
if (sep == NULL) return;
9057
VisitBioSourcesInSep (sep, NULL, ConsolidateOrganismNotesProc);
9058
ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
9059
ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
9062
static void CountryLookupProc (BioSourcePtr biop, Pointer userdata)
9067
CharPtr cp, before, newname;
9068
Int4 len_cntry, len_qual, len_name;
9070
if (biop == NULL || (list = (CharPtr PNTR)userdata) == NULL)
9075
for (ssp = biop->subtype; ssp != NULL; ssp = ssp->next)
9077
if (ssp->subtype != SUBSRC_country || ssp->name == NULL) continue;
9078
for (ptr = list; ptr != NULL && *ptr != NULL; ptr++)
9080
len_cntry = StringLen (*ptr);
9081
cp = StringStr (ssp->name, *ptr);
9082
if (cp != NULL && !isalpha (cp [len_cntry]))
9084
len_qual = StringLen (ssp->name);
9085
if (cp == ssp->name)
9087
if (len_cntry == len_qual || ssp->name [len_cntry] == ':')
9089
/* exact match, don't need to do anything */
9092
ssp->name [len_cntry] = ':';
9097
if (isalpha (*(cp - 1)))
9099
/* not really a match, part of another word */
9104
newname = (CharPtr) MemNew (len_qual + 3);
9106
before = StringSave (ssp->name);
9107
StringNCpy (newname, *ptr, len_cntry);
9108
newname [len_cntry] = ':';
9109
newname [len_cntry + 1] = ' ';
9110
StringNCpy (newname + len_cntry + 2, before, StringLen (before));
9111
StringCpy (newname + len_cntry + 2 + StringLen (before), cp + len_cntry);
9112
len_name = StringLen (newname);
9113
while (isspace (newname[len_name - 1]) || ispunct (newname [len_name - 1]))
9115
newname [len_name - 1] = 0;
9118
before = MemFree (before);
9119
MemFree (ssp->name);
9120
ssp->name = newname;
9128
extern void CountryLookup (IteM i)
9136
bfp = currentFormDataPtr;
9138
bfp = GetObjectExtra (i);
9140
if (bfp == NULL) return;
9141
sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
9142
if (sep == NULL) return;
9144
list = GetValidCountryList ();
9145
if (list == NULL) return;
9146
VisitBioSourcesInSep (sep, list, CountryLookupProc);
9147
ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
9148
ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
9151
static Int4 ExtractNumber (CharPtr str)
9157
if (str == NULL) return 0;
9159
for (cp = str; *cp != 0 && ! ispunct (*cp) && j < 14; cp++)
9163
num_str [j++] = *cp;
9167
return atoi (num_str);
9170
static Int4 GetProteinCoordinate (SeqFeatPtr cds, Int4 loc, BoolPtr warn)
9173
SeqMgrFeatContext context;
9176
if (cds == NULL) return 0;
9178
bsp = BioseqFindFromSeqLoc (cds->location);
9179
if (bsp == NULL) return 0;
9181
cds = SeqMgrGetDesiredFeature (cds->idx.entityID, bsp, cds->idx.itemID, 0, cds, &context);
9182
if (cds == NULL) return;
9185
for (j = 0; j < context.numivals; j++)
9187
if (context.strand == Seq_strand_minus)
9189
if (context.ivals [j] >= loc)
9191
if (context.ivals [j + 1] > loc)
9193
len += context.ivals [j] - context.ivals [j + 1] + 1;
9197
len += context.ivals [j] - loc + 1;
9203
if (context.ivals [j] <= loc)
9205
if (context.ivals [j + 1] < loc)
9207
len += context.ivals [j + 1] - context.ivals [j] + 1;
9211
len += loc - context.ivals [j] + 1;
9217
if (warn != NULL && len % 3 != 2)
9224
typedef struct logfiledata
9227
Boolean data_in_log;
9228
} LogFileData, PNTR LogFilePtr;
9230
static void ExtractProteinFeaturesFromNoteCallback (SeqFeatPtr sfp, Pointer userdata)
9232
CharPtr site_string, loc_string, stop_string;
9233
CharPtr format_str = "predicted by PSort:";
9234
SeqFeatPtr site_feat;
9247
if (sfp == NULL || sfp->idx.subtype != FEATDEF_CDS) return;
9248
lfp = (LogFilePtr)userdata;
9250
sip = SeqLocId (sfp->product);
9251
if (sip == NULL) return;
9253
bsp = BioseqFind (sip);
9254
if (bsp == NULL) return;
9256
site_string = StringISearch (sfp->comment, format_str);
9257
if (site_string == NULL) return;
9258
site_string += StringLen (format_str);
9259
/* need to parse semicolon-delimited list of site features */
9260
while (site_string != NULL)
9262
stop_string = StringChr (site_string, ';');
9263
loc_string = StringChr (site_string, ':');
9264
if (loc_string == NULL || (stop_string != NULL && loc_string > stop_string))
9266
site_string = stop_string + 1;
9271
/* need to parse location */
9272
from = ExtractNumber (loc_string);
9273
cp = StringChr (loc_string, '-');
9274
if (cp == NULL || (stop_string != NULL && cp > stop_string))
9276
site_string = stop_string + 1;
9279
to = ExtractNumber (cp + 1);
9281
/* coordinates in comment start at 1, in SeqLoc start at 0 */
9290
from = GetProteinCoordinate (sfp, from - 1, &warn);
9291
/* Psort right end is off by one */
9292
to = GetProteinCoordinate (sfp, to - 1, &warn);
9293
if (warn && lfp != NULL)
9295
if (stop_string != NULL)
9300
fprintf (lfp->fp, "Cannot convert nucleotide coordinates to protein coordinates: %s\n",
9302
lfp->data_in_log = TRUE;
9303
if (stop_string != NULL)
9309
/* parse feature type */
9312
if (StringISearch (site_string, "transmembrane")!= NULL)
9314
feat_type = SEQFEAT_REGION;
9316
else if (StringISearch (site_string, "signal") != NULL)
9318
feat_type = SEQFEAT_PROT;
9322
feat_type = SEQFEAT_COMMENT;
9325
slp = SeqLocIntNew(from, to, SeqLocStrand (sfp->location),
9326
SeqIdFindBest(sip, SEQID_GI));
9327
if (slp == NULL) return;
9329
site_feat = CreateNewFeatureOnBioseq (bsp, feat_type, slp);
9330
if (site_feat == NULL) return;
9333
case SEQFEAT_REGION:
9334
site_feat->data.value.ptrvalue = StringSave ("Transmembrane domain");
9337
prp = ProtRefNew ();
9338
site_feat->data.value.ptrvalue = prp;
9344
case SEQFEAT_COMMENT:
9345
site_feat->data.choice = SEQFEAT_REGION;
9346
site_feat->data.value.ptrvalue = StringSave (site_string);
9351
/* move to next feature */
9352
site_string = stop_string;
9353
if (site_string != NULL)
9356
if (*site_string == 0)
9364
extern void ExtractProteinFeaturesFromNote (IteM i)
9369
Char path [PATH_MAX];
9372
bfp = currentFormDataPtr;
9374
bfp = GetObjectExtra (i);
9376
if (bfp == NULL) return;
9377
sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
9378
if (sep == NULL) return;
9381
lfd.fp = FileOpen (path, "w");
9382
lfd.data_in_log = FALSE;
9384
VisitFeaturesInSep (sep, (Pointer) &lfd, ExtractProteinFeaturesFromNoteCallback);
9387
if (lfd.data_in_log)
9389
LaunchGeneralTextViewer (path, "Protein Feature Location Errors");
9393
ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
9394
ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
9398
extern void ConvertPseudoCDSToMiscFeat (IteM i)
9403
bfp = currentFormDataPtr;
9405
bfp = GetObjectExtra (i);
9407
if (bfp == NULL) return;
9408
ConvertPseudoCDSToMiscFeatsForEntityID (bfp->input_entityID);
9409
ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
9410
ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
9414
extern void ProcessPseudoMiscFeat (IteM i)
9419
bfp = currentFormDataPtr;
9421
bfp = GetObjectExtra (i);
9423
if (bfp == NULL) return;
9424
ProcessPseudoMiscFeatsForEntityID (bfp->input_entityID);
9425
ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
9426
ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
9430
static void ConvertGeneLocusTagToOldLocusTagCallback
9431
(SeqFeatPtr sfp, Pointer userdata)
9436
GBQualPtr new_qual, prev_qual;
9437
SeqMgrFeatContext context;
9439
if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) return;
9441
gene = SeqMgrGetOverlappingGene (sfp->location, &context);
9442
if (gene == NULL) return;
9444
grp = (GeneRefPtr) gene->data.value.ptrvalue;
9445
if (grp == NULL || StringHasNoText (grp->locus_tag))
9449
locus_tag = grp->locus_tag;
9450
grp->locus_tag = NULL;
9452
new_qual = GBQualNew ();
9453
if (new_qual == NULL) return;
9454
new_qual->qual = StringSave ("old_locus_tag");
9455
new_qual->val = locus_tag;
9456
new_qual->next = NULL;
9458
if (gene->qual == NULL)
9460
gene->qual = new_qual;
9464
for (prev_qual = gene->qual; prev_qual->next != NULL; prev_qual = prev_qual->next)
9467
prev_qual->next = new_qual;
9471
extern void ConvertGeneLocusTagToOldLocusTag (IteM i)
9477
bfp = currentFormDataPtr;
9479
bfp = GetObjectExtra (i);
9481
if (bfp == NULL) return;
9483
sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
9484
if (sep == NULL) return;
9485
VisitFeaturesInSep (sep, NULL, ConvertGeneLocusTagToOldLocusTagCallback);
9486
ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
9487
ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
9491
static void ParseInfluenzaAVirusNamesCallback (BioSourcePtr biop, Pointer userdata)
9493
CharPtr desired_name = "Influenza A virus";
9494
Int4 desired_len = StringLen (desired_name);
9495
CharPtr first_paren = NULL, second_paren = NULL;
9496
CharPtr first_paren_close = NULL, second_paren_close = NULL;
9498
Int4 strain_len, serotype_len;
9499
CharPtr strain, serotype;
9500
OrgModPtr strain_omp, serotype_omp, last_omp, omp;
9501
Boolean added_strain = FALSE, added_serotype = FALSE;
9503
if (biop == NULL || biop->org == NULL || biop->org->taxname == NULL) return;
9505
if (StringNCmp (biop->org->taxname, desired_name, desired_len) != 0)
9510
first_paren = StringChr (biop->org->taxname + desired_len, '(');
9511
if (first_paren == NULL) return;
9512
cp = first_paren + 1;
9513
while (*cp != ')' && *cp != '(' && *cp != 0)
9523
while (*cp != ')' && *cp != '(' && *cp != 0)
9531
second_paren_close = cp;
9533
while (*cp != ')' && *cp != '(' && *cp != 0)
9541
first_paren_close = cp;
9543
if (biop->org->orgname == NULL)
9545
biop->org->orgname = OrgNameNew ();
9546
if (biop->org->orgname == NULL)
9552
strain_len = second_paren - first_paren + first_paren_close - second_paren_close;
9553
serotype_len = second_paren_close - second_paren;
9554
strain = (CharPtr) MemNew (strain_len * sizeof (Char));
9555
serotype = (CharPtr) MemNew (serotype_len * sizeof (Char));
9556
if (strain == NULL || serotype == NULL)
9558
strain = MemFree (strain);
9559
serotype = MemFree (serotype);
9562
StringNCpy (strain, first_paren + 1, second_paren - first_paren - 1);
9563
if (first_paren_close - second_paren_close > 1)
9565
StringCat (strain, " ");
9566
StringNCat (strain, second_paren_close + 1, first_paren_close - second_paren_close - 1);
9568
StringNCpy (serotype, second_paren + 1, second_paren_close - second_paren - 1);
9571
for (omp = biop->org->orgname->mod;
9572
omp != NULL && (!added_strain || ! added_serotype);
9575
if (omp->subtype == ORGMOD_strain)
9577
omp->subname = MemFree (omp->subname);
9578
omp->subname = strain;
9579
added_strain = TRUE;
9581
else if (omp->subtype == ORGMOD_serotype)
9583
omp->subname = MemFree (omp->subname);
9584
omp->subname = serotype;
9585
added_serotype = TRUE;
9591
strain_omp = OrgModNew ();
9592
if (strain_omp != NULL)
9594
strain_omp->subtype = ORGMOD_strain;
9595
strain_omp->subname = strain;
9596
if (last_omp == NULL)
9598
biop->org->orgname->mod = strain_omp;
9602
last_omp->next = strain_omp;
9604
last_omp = strain_omp;
9607
if (!added_serotype)
9609
serotype_omp = OrgModNew ();
9610
if (serotype_omp != NULL)
9612
serotype_omp->subtype = ORGMOD_serotype;
9613
serotype_omp->subname = serotype;
9614
if (last_omp == NULL)
9616
biop->org->orgname->mod = serotype_omp;
9620
last_omp->next = serotype_omp;
9627
extern void ParseInfluenzaAVirusNames (IteM i)
9633
bfp = currentFormDataPtr;
9635
bfp = GetObjectExtra (i);
9637
if (bfp == NULL) return;
9639
sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
9640
if (sep == NULL) return;
9641
VisitBioSourcesInSep (sep, NULL, ParseInfluenzaAVirusNamesCallback);
9642
ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
9643
ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
9647
/* The following code is used for global publication editing. */
9653
PUB_FIELD_FIRST_NAME,
9654
PUB_FIELD_MIDDLE_INITIAL,
9655
PUB_FIELD_LAST_NAME,
9657
PUB_FIELD_CONSORTIUM,
9658
PUB_FIELD_INSTITUTION,
9659
PUB_FIELD_DEPARTMENT,
9670
static ENUM_ALIST(pub_field_alist)
9671
{"Any Pub Field", PUB_FIELD_ANY},
9672
{"Title", PUB_FIELD_TITLE},
9673
{"Author First Name", PUB_FIELD_FIRST_NAME},
9674
{"Author Middle Initial", PUB_FIELD_MIDDLE_INITIAL},
9675
{"Author Last Name", PUB_FIELD_LAST_NAME},
9676
{"Author Suffix", PUB_FIELD_SUFFIX},
9677
{"Author Consortium", PUB_FIELD_CONSORTIUM},
9678
{"Affiliation Institution", PUB_FIELD_INSTITUTION},
9679
{"Affiliation Department", PUB_FIELD_DEPARTMENT},
9680
{"Affiliation Address", PUB_FIELD_ADDRESS},
9681
{"Affiliation City", PUB_FIELD_CITY},
9682
{"Affiliation State", PUB_FIELD_STATE},
9683
{"Affiliation Country", PUB_FIELD_COUNTRY},
9684
{"Affiliation Zip Code", PUB_FIELD_ZIP},
9685
{"Affiliation Email", PUB_FIELD_EMAIL},
9686
{"Affiliation Phone", PUB_FIELD_PHONE},
9687
{"Affiliation Fax", PUB_FIELD_FAX},
9690
static ENUM_ALIST(pub_field_no_any_alist)
9691
{"Title", PUB_FIELD_TITLE},
9692
{"Author First Name", PUB_FIELD_FIRST_NAME},
9693
{"Author Middle Initial", PUB_FIELD_MIDDLE_INITIAL},
9694
{"Author Last Name", PUB_FIELD_LAST_NAME},
9695
{"Author Suffix", PUB_FIELD_SUFFIX},
9696
{"Author Consortium", PUB_FIELD_CONSORTIUM},
9697
{"Affiliation Institution", PUB_FIELD_INSTITUTION},
9698
{"Affiliation Department", PUB_FIELD_DEPARTMENT},
9699
{"Affiliation Address", PUB_FIELD_ADDRESS},
9700
{"Affiliation City", PUB_FIELD_CITY},
9701
{"Affiliation State", PUB_FIELD_STATE},
9702
{"Affiliation Country", PUB_FIELD_COUNTRY},
9703
{"Affiliation Zip Code", PUB_FIELD_ZIP},
9704
{"Affiliation Email", PUB_FIELD_EMAIL},
9705
{"Affiliation Phone", PUB_FIELD_PHONE},
9706
{"Affiliation Fax", PUB_FIELD_FAX},
9714
PUB_STAT_UNPUBLISHED,
9716
PUB_STAT_PUBLISHED_SUBMISSION
9719
static ENUM_ALIST(pub_stat_alist)
9720
{"Any", PUB_STAT_ANY},
9721
{"Published", PUB_STAT_PUBLISHED},
9722
{"Unpublished", PUB_STAT_UNPUBLISHED},
9723
{"In Press", PUB_STAT_INPRESS},
9724
{"Submitter Block", PUB_STAT_PUBLISHED_SUBMISSION},
9727
/* The following functions are used for getting and setting various types of data
9730
static CharPtr GetPubTitleSample (PubPtr the_pub)
9736
CharPtr retp = NULL;
9738
if (the_pub == NULL || the_pub->data.ptrvalue == NULL) return NULL;
9740
switch (the_pub->choice) {
9742
cgp = (CitGenPtr) the_pub->data.ptrvalue;
9748
cap = (CitArtPtr) the_pub->data.ptrvalue;
9749
if(cap->title != NULL)
9751
retp = cap->title->data.ptrvalue;
9756
cbp = (CitBookPtr) the_pub->data.ptrvalue;
9757
if(cbp->title != NULL)
9759
retp = cbp->title->data.ptrvalue;
9763
cpp = (CitPatPtr) the_pub->data.ptrvalue;
9772
static void SetPubTitle (PubPtr the_pub, CharPtr new_title)
9779
if (the_pub == NULL || new_title == NULL) return;
9781
switch (the_pub->choice) {
9783
cgp = (CitGenPtr) the_pub->data.ptrvalue;
9784
cgp->title = MemFree (cgp->title);
9785
cgp->title = StringSave (new_title);
9790
cap = (CitArtPtr) the_pub->data.ptrvalue;
9791
if (cap->title == NULL)
9793
cap->title = ValNodeNew (cap->title);
9794
cap->title->choice = 1;
9796
if(cap->title != NULL)
9798
cap->title->data.ptrvalue = MemFree (cap->title->data.ptrvalue);
9799
cap->title->data.ptrvalue = StringSave (new_title);
9804
cbp = (CitBookPtr) the_pub->data.ptrvalue;
9805
if (cbp->title == NULL)
9807
cbp->title = ValNodeNew (cbp->title);
9808
cbp->title->choice = 1;
9810
if(cbp->title != NULL)
9812
cbp->title->data.ptrvalue = MemFree (cbp->title->data.ptrvalue);
9813
cbp->title->data.ptrvalue = StringSave (new_title);
9817
cpp = (CitPatPtr) the_pub->data.ptrvalue;
9818
cpp->title = MemFree (cpp->title);
9819
cpp->title = StringSave (new_title);
9827
static AuthListPtr GetAuthorListForPub (PubPtr the_pub)
9834
AuthListPtr alp = NULL;
9836
if (the_pub == NULL) return NULL;
9838
switch (the_pub->choice) {
9840
cgp = (CitGenPtr) the_pub->data.ptrvalue;
9844
csp = (CitSubPtr) the_pub->data.ptrvalue;
9848
cap = (CitArtPtr) the_pub->data.ptrvalue;
9853
cbp = (CitBookPtr) the_pub->data.ptrvalue;
9857
cpp = (CitPatPtr) the_pub->data.ptrvalue;
9866
static Boolean SetPubAuthorList (PubPtr the_pub, AuthListPtr alp)
9873
Boolean rval = FALSE;
9875
if (the_pub == NULL || the_pub->data.ptrvalue == NULL || alp == NULL)
9878
switch (the_pub->choice) {
9880
cgp = (CitGenPtr) the_pub->data.ptrvalue;
9881
cgp->authors = AuthListFree (cgp->authors);
9886
csp = (CitSubPtr) the_pub->data.ptrvalue;
9887
csp->authors = AuthListFree (csp->authors);
9892
cap = (CitArtPtr) the_pub->data.ptrvalue;
9893
cap->authors = AuthListFree (cap->authors);
9899
cbp = (CitBookPtr) the_pub->data.ptrvalue;
9900
cbp->authors = AuthListFree (cbp->authors);
9905
cpp = (CitPatPtr) the_pub->data.ptrvalue;
9906
cpp->authors = AuthListFree (cpp->authors);
9917
static CharPtr GetAuthorField (AuthorPtr ap, Int4 field_for_find)
9919
CharPtr retp = NULL;
9920
NameStdPtr pNameStandard;
9922
if (ap == NULL || field_for_find == PUB_FIELD_ANY) return NULL;
9924
if (ap->name->choice == 2)
9926
pNameStandard = (NameStdPtr) ap->name->data;
9927
if (pNameStandard != NULL)
9929
switch (field_for_find)
9931
case PUB_FIELD_FIRST_NAME:
9932
retp = pNameStandard->names [1];
9934
case PUB_FIELD_MIDDLE_INITIAL:
9935
retp = pNameStandard->names [2];
9937
case PUB_FIELD_LAST_NAME:
9938
retp = pNameStandard->names [0];
9940
case PUB_FIELD_SUFFIX:
9941
retp = pNameStandard->names [5];
9946
else if (ap->name->choice == 5 && field_for_find == PUB_FIELD_CONSORTIUM)
9948
retp = ap->name->data;
9953
static CharPtr GetAuthorListFieldSample (PubPtr pub, Int4 field_for_find)
9955
CharPtr retp = NULL;
9960
if (pub == NULL || field_for_find == PUB_FIELD_ANY)
9964
alp = GetAuthorListForPub (pub);
9965
if (alp == NULL) return;
9967
for (names = alp->names; names != NULL && retp == NULL; names = names->next)
9969
ap = names->data.ptrvalue;
9970
retp = GetAuthorField (ap, field_for_find);
9971
if (StringHasNoText (retp))
9980
static void MakeNewInitials (NameStdPtr name_std)
9982
Char frstinits [64];
9985
if (name_std == NULL) return;
9986
FirstNameToInitials (name_std->names [1], frstinits, sizeof (frstinits) - 1);
9987
init_len = StringLen (name_std->names [1]) + StringLen (name_std->names [2]) + 1;
9988
name_std->names [4] = MemFree (name_std->names [4]);
9989
name_std->names [4] = (CharPtr) MemNew (sizeof (Char) * init_len);
9990
if (name_std->names [4] != NULL)
9992
StringCpy (name_std->names [4], frstinits);
9993
StringCat (name_std->names [4], name_std->names [2]);
9998
static void SetAuthorString (AuthorPtr ap, Int4 field_to_set, CharPtr str)
10000
NameStdPtr name_std;
10002
if (field_to_set == PUB_FIELD_FIRST_NAME
10003
|| field_to_set == PUB_FIELD_LAST_NAME
10004
|| field_to_set == PUB_FIELD_MIDDLE_INITIAL
10005
|| field_to_set == PUB_FIELD_SUFFIX)
10007
if (ap->name->choice != 2)
10009
name_std = NameStdNew ();
10010
if (name_std != NULL)
10012
ap->name->data = MemFree (ap->name->data);
10013
ap->name->data = name_std;
10014
ap->name->choice = 2;
10017
if (ap->name->choice == 2)
10019
name_std = (NameStdPtr) ap->name->data;
10020
if (field_to_set == PUB_FIELD_FIRST_NAME)
10022
name_std->names[1] = MemFree (name_std->names[1]);
10023
name_std->names[1] = StringSave (str);
10024
MakeNewInitials (name_std);
10026
else if (field_to_set == PUB_FIELD_LAST_NAME)
10028
name_std->names[0] = MemFree (name_std->names[0]);
10029
name_std->names[0] = StringSave (str);
10031
else if (field_to_set == PUB_FIELD_MIDDLE_INITIAL)
10033
name_std->names[2] = MemFree (name_std->names[2]);
10034
name_std->names[2] = StringSave (str);
10035
MakeNewInitials (name_std);
10037
else if (field_to_set == PUB_FIELD_SUFFIX)
10039
name_std->names[5] = MemFree (name_std->names[5]);
10040
name_std->names[5] = StringSave (str);
10044
else if (field_to_set == PUB_FIELD_CONSORTIUM)
10046
if (ap->name->choice != 5)
10048
if (ap->name->choice == 2)
10050
ap->name->data = NameStdFree (ap->name->data);
10054
ap->name->data = MemFree (ap->name->data);
10056
ap->name->choice = 5;
10058
if (ap->name->choice == 5)
10060
ap->name->data = MemFree (ap->name->data);
10061
ap->name->data = StringSave (str);
10067
static CharPtr GetAffiliationFieldSample (PubPtr pub, Int4 field_for_find)
10069
CharPtr retp = NULL;
10073
if (pub == NULL || field_for_find == PUB_FIELD_ANY)
10077
alp = GetAuthorListForPub (pub);
10078
if (alp == NULL) return;
10080
affil = alp->affil;
10082
if (affil == NULL) return;
10084
switch (field_for_find)
10086
case PUB_FIELD_INSTITUTION:
10087
retp = affil->affil;
10089
case PUB_FIELD_DEPARTMENT:
10092
case PUB_FIELD_ADDRESS:
10093
retp = affil->street;
10095
case PUB_FIELD_CITY:
10096
retp = affil->city;
10098
case PUB_FIELD_STATE:
10101
case PUB_FIELD_COUNTRY:
10102
retp = affil->country;
10104
case PUB_FIELD_ZIP:
10105
retp = affil->postal_code;
10107
case PUB_FIELD_EMAIL:
10108
retp = affil->email;
10110
case PUB_FIELD_PHONE:
10111
retp = affil->phone;
10113
case PUB_FIELD_FAX:
10121
static AffilPtr SetAffilString (AffilPtr affil, Int4 field_to_set, CharPtr str)
10125
affil = AffilNew ();
10126
if (affil == NULL) return NULL;
10129
else if (affil->choice != 2)
10133
if (field_to_set == PUB_FIELD_INSTITUTION)
10135
affil->affil = MemFree (affil->affil);
10136
affil->affil = StringSave (str);
10138
else if (field_to_set == PUB_FIELD_DEPARTMENT)
10140
affil->div = MemFree (affil->div);
10141
affil->div = StringSave (str);
10143
else if (field_to_set == PUB_FIELD_ADDRESS)
10145
affil->street = MemFree (affil->street);
10146
affil->street = StringSave (str);
10148
else if (field_to_set == PUB_FIELD_CITY)
10150
affil->city = MemFree (affil->city);
10151
affil->city = StringSave (str);
10153
else if (field_to_set == PUB_FIELD_STATE)
10155
affil->sub = MemFree (affil->sub);
10156
affil->sub = StringSave (str);
10158
else if (field_to_set == PUB_FIELD_COUNTRY)
10160
affil->country = MemFree (affil->country);
10161
affil->country = StringSave (str);
10163
else if (field_to_set == PUB_FIELD_ZIP)
10165
affil->postal_code = MemFree (affil->postal_code);
10166
affil->postal_code = StringSave (str);
10168
else if (field_to_set == PUB_FIELD_EMAIL)
10170
affil->email = MemFree (affil->email);
10171
affil->email = StringSave (str);
10173
else if (field_to_set == PUB_FIELD_PHONE)
10175
affil->phone = MemFree (affil->phone);
10176
affil->phone = StringSave (str);
10178
else if (field_to_set == PUB_FIELD_FAX)
10180
affil->fax = MemFree (affil->fax);
10181
affil->fax = StringSave (str);
10187
static CharPtr GetSampleStringFromPub (PubdescPtr pdp, Int4 field_num)
10190
CharPtr retp = NULL;
10192
if (pdp == NULL || pdp->pub == NULL || field_num == PUB_FIELD_ANY)
10197
for (pub = pdp->pub; pub != NULL && retp == NULL; pub = pub->next)
10201
case PUB_FIELD_TITLE:
10202
retp = GetPubTitleSample (pub);
10204
case PUB_FIELD_FIRST_NAME:
10205
case PUB_FIELD_MIDDLE_INITIAL:
10206
case PUB_FIELD_LAST_NAME:
10207
case PUB_FIELD_SUFFIX:
10208
case PUB_FIELD_CONSORTIUM:
10209
retp = GetAuthorListFieldSample (pub, field_num);
10211
case PUB_FIELD_INSTITUTION:
10212
case PUB_FIELD_DEPARTMENT:
10213
case PUB_FIELD_ADDRESS:
10214
case PUB_FIELD_CITY:
10215
case PUB_FIELD_STATE:
10216
case PUB_FIELD_COUNTRY:
10217
case PUB_FIELD_ZIP:
10218
case PUB_FIELD_EMAIL:
10219
case PUB_FIELD_PHONE:
10220
case PUB_FIELD_FAX:
10221
retp = GetAffiliationFieldSample (pub, field_num);
10224
if (StringHasNoText (retp))
10233
static Int4 GetPubStatus (PubPtr the_pub)
10240
ImprintPtr imp = NULL;
10241
Int4 status = PUB_STAT_ANY;
10243
if (the_pub == NULL || the_pub->data.ptrvalue == NULL)
10245
return PUB_STAT_ANY;
10248
switch (the_pub->choice)
10251
cgp = (CitGenPtr) the_pub->data.ptrvalue;
10252
if (cgp->cit != NULL && StringICmp (cgp->cit, "unpublished") == 0)
10254
status = PUB_STAT_UNPUBLISHED;
10258
status = PUB_STAT_PUBLISHED;
10262
csp = (CitSubPtr) the_pub->data.ptrvalue;
10263
status = PUB_STAT_PUBLISHED_SUBMISSION;
10266
cap = (CitArtPtr) the_pub->data.ptrvalue;
10267
if (cap->from == 1)
10269
cjp = (CitJourPtr) cap->fromptr;
10275
else if (cap->from == 2 || cap->from == 3)
10277
cbp = (CitBookPtr) the_pub->data.ptrvalue;
10285
cjp = (CitJourPtr) the_pub->data.ptrvalue;
10289
cbp = (CitBookPtr) the_pub->data.ptrvalue;
10293
status = PUB_STAT_PUBLISHED;
10301
if (imp->prepub == 0)
10303
status = PUB_STAT_PUBLISHED;
10305
else if (imp->prepub == 2)
10307
status = PUB_STAT_INPRESS;
10309
else if (imp->prepub == 1 && the_pub->choice == PUB_Sub)
10311
status = PUB_STAT_PUBLISHED_SUBMISSION;
10315
status = PUB_STAT_UNPUBLISHED;
10323
/* The PubConstraintData structure is used by all of the global publication editing
10324
* code to determine which publications to apply the requested changes to.
10326
typedef struct pubconstraint
10329
Int4 field_for_find;
10330
Boolean insensitive_to_case;
10333
ButtoN insensitive_to_case_btn;
10334
PopuP field_for_find_popup;
10335
PopuP pub_status_popup;
10336
} PubConstraintData, PNTR PubConstraintPtr;
10338
static PubConstraintPtr PubConstraintNew (void)
10340
PubConstraintPtr p;
10342
p = (PubConstraintPtr) MemNew (sizeof (PubConstraintData));
10345
p->find_str = NULL;
10346
p->field_for_find = 0;
10347
p->insensitive_to_case = FALSE;
10349
p->find_str_txt = NULL;
10350
p->insensitive_to_case_btn = NULL;
10351
p->field_for_find_popup = NULL;
10352
p->pub_status_popup = NULL;
10357
static PubConstraintPtr PubConstraintFree (PubConstraintPtr p)
10361
p->find_str = MemFree (p->find_str);
10367
static void LoadConstraintFromSelectedPub (ButtoN b)
10369
PubConstraintPtr p;
10371
SeqMgrFeatContext fcontext;
10372
SeqMgrDescContext dcontext;
10373
PubdescPtr pdp = NULL;
10376
CharPtr field_val = NULL;
10378
Int4 field_num = PUB_FIELD_ANY;
10380
p = (PubConstraintPtr) GetObjectExtra (b);
10381
if (p == NULL) return;
10383
if (GetEnumPopup (p->field_for_find_popup, pub_field_alist, &val))
10388
if (field_num == PUB_FIELD_ANY) return;
10390
ssp = ObjMgrGetSelected();
10392
while (NULL != ssp && field_val == NULL)
10394
if (ssp->itemtype == OBJ_SEQFEAT)
10396
sfp = SeqMgrGetDesiredFeature (ssp->entityID, NULL, ssp->itemID, 0, NULL, &fcontext);
10397
if (sfp != NULL && sfp->data.choice == SEQFEAT_PUB)
10399
pdp = sfp->data.value.ptrvalue;
10400
field_val = GetSampleStringFromPub (pdp, field_num);
10403
else if (ssp->itemtype == OBJ_SEQDESC)
10405
sdp = SeqMgrGetDesiredDescriptor (ssp->entityID, NULL, ssp->itemID, 0, NULL, &dcontext);
10406
if (sdp != NULL && sdp->choice == Seq_descr_pub)
10408
pdp = sdp->data.ptrvalue;
10409
field_val = GetSampleStringFromPub (pdp, field_num);
10415
SetTitle (p->find_str_txt, field_val);
10418
/* This function creates the controls used for gathering the information
10419
* from the user for the PubConstraint.
10421
static void CreatePubConstraintControls (GrouP h, PubConstraintPtr p)
10423
GrouP g, k1, k2, k3;
10426
if (h == NULL || p == NULL) return;
10428
g = HiddenGroup (h, -1, 0, NULL);
10429
k1 = HiddenGroup (g, 5, 0, NULL);
10430
StaticPrompt (k1, "Where", 0, dialogTextHeight, programFont, 'c');
10431
p->find_str_txt = DialogText (k1, "", 15, NULL);
10432
StaticPrompt (k1, "occurs in", 0, dialogTextHeight, programFont, 'c');
10433
p->field_for_find_popup = PopupList (k1, TRUE, NULL);
10434
InitEnumPopup (p->field_for_find_popup, pub_field_alist, NULL);
10435
SetEnumPopup (p->field_for_find_popup, pub_field_alist, PUB_FIELD_ANY);
10436
k2 = HiddenGroup (g, 2, 0, NULL);
10437
p->insensitive_to_case_btn = CheckBox (k2, "Ignore case", NULL);
10438
b = PushButton (k2, "Load Constraint Value From Selected Publication", LoadConstraintFromSelectedPub);
10439
SetObjectExtra (b, p, NULL);
10440
k3 = HiddenGroup (g, 2, 0, NULL);
10441
StaticPrompt (k3, "Publication Status", 0, dialogTextHeight, programFont, 'c');
10442
p->pub_status_popup = PopupList (k3, TRUE, NULL);
10443
InitEnumPopup (p->pub_status_popup, pub_stat_alist, NULL);
10444
SetEnumPopup (p->pub_status_popup, pub_stat_alist, 0);
10446
AlignObjects (ALIGN_CENTER, (HANDLE) k1, (HANDLE) k2, (HANDLE) k3, NULL);
10449
/* This function reads values from the PubConstraint controls. */
10450
static void PopulatePubConstraint (PubConstraintPtr p)
10454
if (p == NULL) return;
10456
p->find_str = MemFree (p->find_str);
10457
p->find_str = SaveStringFromText (p->find_str_txt);
10458
if (StringHasNoText (p->find_str))
10460
p->find_str = MemFree (p->find_str);
10462
if (GetEnumPopup (p->field_for_find_popup, pub_field_alist, &val))
10464
p->field_for_find = val;
10466
p->insensitive_to_case = GetStatus (p->insensitive_to_case_btn);
10467
if (GetEnumPopup (p->pub_status_popup, pub_field_alist, &val))
10469
p->pub_status = val;
10473
/* The following functions are used to determine whether a particular section of a
10474
* publication matches the value specified in the PubConstraint.
10476
static Boolean DoesPubTitleMatchConstraint (PubPtr the_pub, PubConstraintPtr p)
10482
Boolean rval = FALSE;
10485
if (the_pub == NULL || p == NULL || the_pub->data.ptrvalue == NULL)
10489
if (p->find_str == NULL) return TRUE;
10491
switch (the_pub->choice) {
10493
cgp = (CitGenPtr) the_pub->data.ptrvalue;
10494
if ((p->insensitive_to_case
10495
&& StringISearch (cgp->title, p->find_str) != NULL)
10496
|| StringSearch (cgp->title, p->find_str) != NULL)
10504
cap = (CitArtPtr) the_pub->data.ptrvalue;
10505
if(cap->title != NULL)
10507
title = (CharPtr) (cap->title->data.ptrvalue);
10508
if ((p->insensitive_to_case
10509
&& StringISearch (title, p->find_str) != NULL)
10510
|| StringSearch (title, p->find_str) != NULL)
10518
cbp = (CitBookPtr) the_pub->data.ptrvalue;
10519
if(cbp->title != NULL) {
10520
title = (CharPtr) (cbp->title->data.ptrvalue);
10521
if ((p->insensitive_to_case
10522
&& StringISearch (title, p->find_str) != NULL)
10523
|| StringSearch (title, p->find_str) != NULL)
10530
cpp = (CitPatPtr) the_pub->data.ptrvalue;
10531
if ((p->insensitive_to_case
10532
&& StringISearch (cpp->title, p->find_str) != NULL)
10533
|| StringSearch (cpp->title, p->find_str) != NULL)
10545
static Boolean DoesAffiliationMatchString (AffilPtr ap, PubConstraintPtr p)
10547
Boolean rval = FALSE;
10549
if (ap == NULL || p == NULL) return FALSE;
10551
if (p->find_str == NULL) return TRUE;
10553
if ((p->field_for_find == PUB_FIELD_ANY || p->field_for_find == PUB_FIELD_INSTITUTION)
10554
&& ((p->insensitive_to_case && StringISearch (ap->affil, p->find_str) != NULL)
10555
|| StringSearch (ap->affil, p->find_str) != NULL))
10559
if ((p->field_for_find == PUB_FIELD_ANY || p->field_for_find == PUB_FIELD_DEPARTMENT)
10560
&& ((p->insensitive_to_case && StringISearch (ap->div, p->find_str) != NULL)
10561
|| StringSearch (ap->div, p->find_str) != NULL))
10565
if ((p->field_for_find == PUB_FIELD_ANY || p->field_for_find == PUB_FIELD_ADDRESS)
10566
&& ((p->insensitive_to_case && StringISearch (ap->street, p->find_str) != NULL)
10567
|| StringSearch (ap->street, p->find_str) != NULL))
10571
if ((p->field_for_find == PUB_FIELD_ANY || p->field_for_find == PUB_FIELD_CITY)
10572
&& ((p->insensitive_to_case && StringISearch (ap->city, p->find_str) != NULL)
10573
|| StringSearch (ap->city, p->find_str) != NULL))
10577
if ((p->field_for_find == PUB_FIELD_ANY || p->field_for_find == PUB_FIELD_STATE)
10578
&& ((p->insensitive_to_case && StringISearch (ap->sub, p->find_str) != NULL)
10579
|| StringSearch (ap->sub, p->find_str) != NULL))
10583
if ((p->field_for_find == PUB_FIELD_ANY || p->field_for_find == PUB_FIELD_COUNTRY)
10584
&& ((p->insensitive_to_case && StringISearch (ap->country, p->find_str) != NULL)
10585
|| StringSearch (ap->country, p->find_str) != NULL))
10589
if ((p->field_for_find == PUB_FIELD_ANY || p->field_for_find == PUB_FIELD_EMAIL)
10590
&& ((p->insensitive_to_case && StringISearch (ap->email, p->find_str) != NULL)
10591
|| StringSearch (ap->email, p->find_str) != NULL))
10595
if ((p->field_for_find == PUB_FIELD_ANY || p->field_for_find == PUB_FIELD_ZIP)
10596
&& ((p->insensitive_to_case && StringISearch (ap->postal_code, p->find_str) != NULL)
10597
|| StringSearch (ap->postal_code, p->find_str) != NULL))
10601
if ((p->field_for_find == PUB_FIELD_ANY || p->field_for_find == PUB_FIELD_PHONE)
10602
&& ((p->insensitive_to_case && StringISearch (ap->phone, p->find_str) != NULL)
10603
|| StringSearch (ap->phone, p->find_str) != NULL))
10607
if ((p->field_for_find == PUB_FIELD_ANY || p->field_for_find == PUB_FIELD_FAX)
10608
&& ((p->insensitive_to_case && StringISearch (ap->fax, p->find_str) != NULL)
10609
|| StringSearch (ap->fax, p->find_str) != NULL))
10617
static Boolean DoesOneAuthorMatchString (AuthorPtr ap, PubConstraintPtr p)
10619
Boolean rval = FALSE;
10620
NameStdPtr pNameStandard = NULL;
10622
if (ap == NULL || p == NULL) return FALSE;
10623
if (p->find_str == NULL) return TRUE;
10625
if (ap->name->choice == 2)
10627
pNameStandard = (NameStdPtr) ap->name->data;
10628
if (((p->field_for_find == PUB_FIELD_ANY
10629
|| p->field_for_find == PUB_FIELD_FIRST_NAME))
10630
&& ((p->insensitive_to_case && StringISearch (pNameStandard->names[1], p->find_str) != NULL)
10631
|| StringSearch (pNameStandard->names[1], p->find_str) != NULL))
10635
if (((p->field_for_find == PUB_FIELD_ANY
10636
|| p->field_for_find == PUB_FIELD_LAST_NAME))
10637
&& ((p->insensitive_to_case && StringISearch (pNameStandard->names[0], p->find_str) != NULL)
10638
|| StringSearch (pNameStandard->names[0], p->find_str) != NULL))
10642
if (((p->field_for_find == PUB_FIELD_ANY
10643
|| p->field_for_find == PUB_FIELD_MIDDLE_INITIAL))
10644
&& ((p->insensitive_to_case && StringISearch (pNameStandard->names[2], p->find_str) != NULL)
10645
|| StringSearch (pNameStandard->names[2], p->find_str) != NULL))
10649
if (((p->field_for_find == PUB_FIELD_ANY
10650
|| p->field_for_find == PUB_FIELD_SUFFIX))
10651
&& ((p->insensitive_to_case && StringICmp (pNameStandard->names[5], p->find_str) == 0)
10652
|| StringCmp (pNameStandard->names[5], p->find_str) == 0))
10657
if (ap->name->choice == 5
10658
&& (p->field_for_find == PUB_FIELD_ANY || p->field_for_find == PUB_FIELD_CONSORTIUM)
10659
&& ((p->insensitive_to_case && StringISearch (ap->name->data, p->find_str) != NULL)
10660
|| StringSearch (ap->name->data, p->find_str) != NULL))
10669
static Boolean DoesAuthorListMatchConstraint (AuthListPtr alp, PubConstraintPtr p)
10671
Boolean rval = FALSE;
10675
if (alp == NULL || p == NULL)
10679
if (p->find_str == NULL) return TRUE;
10681
for (names = alp->names; names != NULL && !rval; names = names->next)
10683
ap = names->data.ptrvalue;
10684
rval = DoesOneAuthorMatchString (ap, p);
10691
static Boolean DoesPubMatchConstraint (PubPtr the_pub, PubConstraintPtr p)
10693
Boolean rval = FALSE;
10696
if (the_pub == NULL || p == NULL) return FALSE;
10698
if (p->pub_status != PUB_STAT_ANY && p->pub_status != GetPubStatus (the_pub))
10702
if ((p->field_for_find == PUB_FIELD_ANY || p->field_for_find == PUB_FIELD_TITLE)
10703
&& DoesPubTitleMatchConstraint (the_pub, p))
10709
alp = GetAuthorListForPub (the_pub);
10712
rval = DoesAuthorListMatchConstraint (alp, p);
10713
if (!rval && DoesAffiliationMatchString (alp->affil, p))
10723
/* This structure is used for the Edit Publications dialog.
10724
* It contains a PubConstraint plus the necessary controls
10725
* to collect user input for editing a single field,
10726
* replacing a publication section, or merging author lists.
10728
typedef struct EditPubform
10732
PubConstraintData pcd;
10735
/* used for single field replace */
10736
TexT repl_string_txt;
10737
PopuP field_to_set_popup;
10738
CharPtr repl_string;
10741
/* used for replacing publication section */
10742
ButtoN replace_author_list;
10743
ButtoN replace_title;
10744
ButtoN replace_affiliation;
10750
/* used for author list merge */
10751
ValNodePtr names_list;
10753
GrouP edit_type_group;
10755
GrouP single_field_group;
10756
GrouP replace_sect_group;
10757
GrouP merge_auth_list_group;
10758
ButtoN specify_author_order;
10760
} EditPubFormData, PNTR EditPubFormPtr;
10763
typedef void (LIBCALLBACK *operateOnPubFunction) (
10765
EditPubFormPtr epfp
10768
typedef struct operatepub
10770
operateOnPubFunction op_pub;
10771
EditPubFormPtr epfp;
10772
} OperatePubData, PNTR OperatePubPtr;
10774
static void OperateOnPubFeatureCallback (SeqFeatPtr sfp, Pointer userdata)
10780
if (sfp == NULL || sfp->data.choice != SEQFEAT_PUB || userdata == NULL)
10784
opp = (OperatePubPtr) userdata;
10785
if (opp->op_pub == NULL || opp->epfp == NULL) return;
10786
pdp = (PubdescPtr) sfp->data.value.ptrvalue;
10787
if (pdp == NULL) return;
10788
for (pub = pdp->pub; pub != NULL; pub = pub->next)
10790
opp->op_pub (pub, opp->epfp);
10794
static void OperateOnPubDescriptorCallback (SeqDescPtr sdp, Pointer userdata)
10800
if (sdp == NULL || sdp->choice != Seq_descr_pub || userdata == NULL)
10804
opp = (OperatePubPtr) userdata;
10805
if (opp->op_pub == NULL || opp->epfp == NULL) return;
10806
pdp = (PubdescPtr) sdp->data.ptrvalue;
10807
if (pdp == NULL) return;
10808
for (pub = pdp->pub; pub != NULL; pub = pub->next)
10810
opp->op_pub (pub, opp->epfp);
10815
static void OperateOnPubByConstraint (SeqEntryPtr sep, EditPubFormPtr epfp, operateOnPubFunction op_pub)
10817
OperatePubData opd;
10819
if (sep == NULL || epfp == NULL || op_pub == NULL) return;
10821
opd.op_pub = op_pub;
10823
VisitFeaturesInSep (sep, &opd, OperateOnPubFeatureCallback);
10824
VisitDescriptorsInSep (sep, &opd, OperateOnPubDescriptorCallback);
10828
/* The following code is used for setting the value of a single field
10829
* in a publication.
10831
static void SetFieldByConstraint
10833
PubConstraintPtr p,
10840
if (pdp == NULL || p == NULL ||
10841
(p->pub_status != PUB_STAT_ANY && p->pub_status != GetPubStatus (pdp)))
10846
if (field_to_set == PUB_FIELD_TITLE)
10848
if (DoesPubMatchConstraint (pdp, p))
10850
SetPubTitle (pdp, str);
10853
else if (field_to_set >= PUB_FIELD_FIRST_NAME
10854
&& field_to_set <= PUB_FIELD_CONSORTIUM)
10856
alp = GetAuthorListForPub (pdp);
10859
alp = AuthListNew ();
10860
if (! SetPubAuthorList (pdp, alp))
10866
if ((p->field_for_find == PUB_FIELD_TITLE && DoesPubTitleMatchConstraint (pdp, p))
10867
|| (p->field_for_find >= PUB_FIELD_INSTITUTION && p->field_for_find <= PUB_FIELD_FAX
10868
&& DoesAffiliationMatchString (alp->affil, p)))
10870
for (names = alp->names; names != NULL; names = names->next)
10872
SetAuthorString (names->data.ptrvalue, field_to_set, str);
10875
else if (p->field_for_find >= PUB_FIELD_FIRST_NAME
10876
&& p->field_for_find <= PUB_FIELD_CONSORTIUM)
10878
for (names = alp->names; names != NULL; names = names->next)
10880
if (DoesOneAuthorMatchString (names->data.ptrvalue, p))
10882
SetAuthorString (names->data.ptrvalue, field_to_set, str);
10887
else if (field_to_set >= PUB_FIELD_INSTITUTION
10888
&& field_to_set <= PUB_FIELD_FAX
10891
alp = GetAuthorListForPub (pdp);
10894
alp = AuthListNew ();
10895
if (! SetPubAuthorList (pdp, alp))
10901
if (DoesPubMatchConstraint (pdp, p))
10903
alp->affil = SetAffilString (alp->affil, field_to_set, str);
10908
static void LIBCALLBACK EditPubSingleField (PubPtr pub, EditPubFormPtr epfp)
10910
if (pub == NULL || epfp == NULL) return;
10912
SetFieldByConstraint (pub, &(epfp->pcd), epfp->field_to_set, epfp->repl_string);
10916
/* this code is used for replacing pub sections */
10917
static void LIBCALLBACK ReplacePubSectByConstraint (PubPtr pub, EditPubFormPtr epfp)
10921
if (pub == NULL || epfp == NULL)
10925
if (DoesPubMatchConstraint (pub, &(epfp->pcd)))
10927
if (epfp->alp != NULL)
10929
alp = AsnIoMemCopy ((Pointer) epfp->alp,
10930
(AsnReadFunc) AuthListAsnRead,
10931
(AsnWriteFunc) AuthListAsnWrite);
10934
SetPubAuthorList (pub, alp);
10937
if (epfp->title_str != NULL)
10939
SetPubTitle (pub, epfp->title_str);
10941
if (epfp->affil != NULL)
10943
alp = GetAuthorListForPub (pub);
10946
alp->affil = AffilFree (alp->affil);
10947
alp->affil = AsnIoMemCopy ((Pointer) epfp->affil,
10948
(AsnReadFunc) AffilAsnRead,
10949
(AsnWriteFunc) AffilAsnWrite);
10956
/* this code is used for merging author lists */
10957
static Boolean AreAuthorNamesIdentical (AuthorPtr ap1, AuthorPtr ap2)
10959
NameStdPtr pNameStandard1, pNameStandard2;
10961
Boolean rval = FALSE;
10964
if (ap1 == NULL || ap2 == NULL) return FALSE;
10966
if (ap1->name->choice != ap2->name->choice)
10972
switch (ap1->name->choice)
10975
pNameStandard1 = (NameStdPtr) ap1->name->data;
10976
pNameStandard2 = (NameStdPtr) ap2->name->data;
10978
for (idx = 0; idx < 7 && rval; idx++)
10980
if (StringHasNoText (pNameStandard1->names[idx]))
10982
if (!StringHasNoText (pNameStandard2->names[idx]))
10987
else if (StringHasNoText (pNameStandard2->names[idx]))
10991
else if (StringCmp (pNameStandard1->names[idx], pNameStandard2->names[idx]) != 0)
10999
n1 = (CharPtr) ap1->name->data;
11000
n2 = (CharPtr) ap2->name->data;
11001
if (StringCmp (n1, n2) == 0)
11012
static void LIBCALLBACK GetMergedAuthorListByConstraint (PubPtr pub, EditPubFormPtr epfp)
11015
ValNodePtr name_in_this, name_in_list;
11016
AuthorPtr ap1, ap2;
11017
Boolean found_match;
11019
if (pub == NULL || epfp == NULL)
11023
if (DoesPubMatchConstraint (pub, &(epfp->pcd)))
11025
alp = GetAuthorListForPub (pub);
11028
for (name_in_this = alp->names; name_in_this != NULL; name_in_this = name_in_this->next)
11030
ap1 = name_in_this->data.ptrvalue;
11031
found_match = FALSE;
11032
for (name_in_list = epfp->names_list;
11033
name_in_list != NULL && !found_match;
11034
name_in_list = name_in_list->next)
11036
ap2 = name_in_list->data.ptrvalue;
11037
if (AreAuthorNamesIdentical (ap1, ap2))
11039
found_match = TRUE;
11044
ap2 = AsnIoMemCopy ((Pointer) ap1,
11045
(AsnReadFunc) AuthorAsnRead,
11046
(AsnWriteFunc) AuthorAsnWrite);
11049
ValNodeAddPointer (&(epfp->names_list), name_in_this->choice, ap2);
11057
static ValNodePtr FreeAuthorNameList (ValNodePtr names_list)
11061
for (vnp = names_list; vnp != NULL; vnp = vnp->next)
11063
vnp->data.ptrvalue = AuthorFree (vnp->data.ptrvalue);
11065
names_list = ValNodeFree (names_list);
11069
static void ReplaceNameList (AuthListPtr alp, ValNodePtr new_name_list)
11071
ValNodePtr new_name;
11074
if (alp == NULL) return;
11076
alp->names = FreeAuthorNameList (alp->names);
11078
for (new_name = new_name_list; new_name != NULL; new_name = new_name->next)
11080
new_ap = AsnIoMemCopy (new_name->data.ptrvalue,
11081
(AsnReadFunc) AuthorAsnRead,
11082
(AsnWriteFunc) AuthorAsnWrite);
11083
if (new_ap != NULL)
11085
ValNodeAddPointer (&(alp->names), new_name->choice, new_ap);
11090
static void LIBCALLBACK SetMergedAuthorListByConstraint (PubPtr pub, EditPubFormPtr epfp)
11094
if (pub == NULL || epfp == NULL)
11098
if (DoesPubMatchConstraint (pub, &(epfp->pcd)))
11100
alp = GetAuthorListForPub (pub);
11101
ReplaceNameList (alp, epfp->names_list);
11106
static PubdescPtr FindFirstSelectedPub (void)
11111
PubdescPtr pdp = NULL;
11112
SeqMgrFeatContext fcontext;
11113
SeqMgrDescContext dcontext;
11116
/* find the selected pub */
11117
ssp = ObjMgrGetSelected();
11119
while (NULL != ssp && pdp == NULL)
11121
if (ssp->itemtype == OBJ_SEQFEAT)
11123
sfp = SeqMgrGetDesiredFeature (ssp->entityID, NULL, ssp->itemID, 0, NULL, &fcontext);
11124
if (sfp != NULL && sfp->data.choice == SEQFEAT_PUB)
11126
pdp = sfp->data.value.ptrvalue;
11129
else if (ssp->itemtype == OBJ_SEQDESC)
11131
sdp = SeqMgrGetDesiredDescriptor (ssp->entityID, NULL, ssp->itemID, 0, NULL, &dcontext);
11132
if (sdp != NULL && sdp->choice == Seq_descr_pub)
11134
pdp = sdp->data.ptrvalue;
11142
typedef Int4 (LIBCALLBACK *GetItemTextLength) (Pointer userdata);
11144
typedef void (LIBCALLBACK *PrintItemToBuffer) (CharPtr cp, Pointer userdata);
11146
typedef struct doublelist
11152
ButtoN from_button;
11153
ButtoN accept_button;
11159
BoolPtr list1_clicked;
11160
BoolPtr list2_clicked;
11162
GetItemTextLength getlenproc;
11163
PrintItemToBuffer printitemproc;
11164
Boolean none_in_1_ok;
11165
Boolean none_in_2_ok;
11166
} DoubleListData, PNTR DoubleListPtr;
11168
static ColData doubleListCol [] = {
11169
{0, 0, 80, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, FALSE},
11170
{0, 0, 0, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, FALSE},
11171
{0, 0, 0, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, FALSE},
11172
{0, 0, 0, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, FALSE},
11173
{0, 0, 0, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, FALSE},
11174
{0, 0, 0, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, FALSE},
11175
{0, 0, 0, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, FALSE},
11176
{0, 0, 0, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, TRUE}};
11178
static ParData doubleListPar = {FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0};
11180
static CharPtr AllLinePrtProc (DoC d, Int2 item, Pointer ptr)
11186
tmp = (CharPtr) ptr;
11187
return StringSave (tmp);
11193
static CharPtr GetDoubleListTextList (ValNodePtr item_list, DoubleListPtr dlp)
11197
CharPtr text_list, cp;
11199
if (dlp == NULL || dlp->getlenproc == NULL || dlp->printitemproc == NULL)
11203
for (vnp = item_list; vnp != NULL; vnp = vnp->next)
11205
text_len += dlp->getlenproc (vnp->data.ptrvalue);
11207
if (text_len == 0) return NULL;
11208
text_list = (CharPtr) MemNew (text_len * sizeof (Char));
11209
if (text_list == NULL) return NULL;
11211
for (vnp = item_list; vnp != NULL; vnp = vnp->next)
11213
dlp->printitemproc (cp, vnp->data.ptrvalue);
11214
cp += StringLen (cp);
11219
static void ClickList1 (DoC d, PoinT pt)
11226
dlp = (DoubleListPtr) GetObjectExtra (d);
11228
MapDocPoint (d, pt, &item, &row, NULL, NULL);
11229
if (item > 0 && row > 0) {
11230
dlp->list1_clicked [row - 1] = ! dlp->list1_clicked [row - 1];
11231
InvalDocRows (d, 1, row, row);
11236
static void ClickList2 (DoC d, PoinT pt)
11243
dlp = (DoubleListPtr) GetObjectExtra (d);
11245
MapDocPoint (d, pt, &item, &row, NULL, NULL);
11246
if (item > 0 && row > 0) {
11247
dlp->list2_clicked [row - 1] = ! dlp->list2_clicked [row - 1];
11248
InvalDocRows (d, 1, row, row);
11254
static void ReleaseDoubleListItem (DoC d, PoinT pt)
11261
dlp = (DoubleListPtr) GetObjectExtra (d);
11263
MapDocPoint (d, pt, &item, &row, NULL, NULL);
11264
if (item > 0 && row > 0) {
11270
static Boolean HighlightList1 (DoC d, Int2 item, Int2 row, Int2 col)
11275
dlp = (DoubleListPtr) GetObjectExtra (d);
11277
return dlp->list1_clicked [row - 1];
11283
static Boolean HighlightList2 (DoC d, Int2 item, Int2 row, Int2 col)
11288
dlp = (DoubleListPtr) GetObjectExtra (d);
11290
return dlp->list2_clicked [row - 1];
11296
static void PopulateDoubleListPanels (DoubleListPtr dlp)
11301
if (dlp == NULL) return;
11303
Reset(dlp->list1_ctrl);
11304
SetDocAutoAdjust (dlp->list1_ctrl, FALSE);
11305
new_text = GetDoubleListTextList (dlp->list1, dlp);
11306
AppendItem (dlp->list1_ctrl, AllLinePrtProc, new_text, FALSE, ValNodeLen (dlp->list1),
11307
&doubleListPar, doubleListCol, programFont);
11308
SetDocAutoAdjust (dlp->list1_ctrl, TRUE);
11309
SetDocProcs (dlp->list1_ctrl, ClickList1, NULL, ReleaseDoubleListItem, NULL);
11310
SetDocShade (dlp->list1_ctrl, NULL, NULL, HighlightList1, NULL);
11311
InvalDocRows (dlp->list1_ctrl, 1, 1, ValNodeLen (dlp->list1));
11313
Reset(dlp->list2_ctrl);
11314
SetDocAutoAdjust (dlp->list2_ctrl, FALSE);
11315
new_text = GetDoubleListTextList (dlp->list2, dlp);
11316
AppendItem (dlp->list2_ctrl, AllLinePrtProc, new_text, FALSE, ValNodeLen (dlp->list2),
11317
&doubleListPar, doubleListCol, programFont);
11318
SetDocAutoAdjust (dlp->list2_ctrl, TRUE);
11319
SetDocProcs (dlp->list2_ctrl, ClickList2, NULL, ReleaseDoubleListItem, NULL);
11320
SetDocShade (dlp->list2_ctrl, NULL, NULL, HighlightList2, NULL);
11321
InvalDocRows (dlp->list2_ctrl, 1, 1, ValNodeLen (dlp->list2));
11323
/* clear selections for both lists */
11324
for (idx = 0; idx < dlp->num_total; idx++)
11326
dlp->list1_clicked [idx] = FALSE;
11327
dlp->list2_clicked [idx] = FALSE;
11330
if (! dlp->none_in_1_ok && dlp->list1 == NULL)
11332
Disable (dlp->accept_button);
11334
else if (! dlp->none_in_2_ok && dlp->list2 == NULL)
11336
Disable (dlp->accept_button);
11340
Enable (dlp->accept_button);
11345
static void MoveToList2 (ButtoN b)
11348
ValNodePtr vnp, prev = NULL, vnp_next;
11351
dlp = (DoubleListPtr) GetObjectExtra (b);
11354
for (vnp = dlp->list1, idx = 0;
11355
vnp != NULL && idx < dlp->num_total;
11356
vnp = vnp_next, idx++)
11358
vnp_next = vnp->next;
11359
if (dlp->list1_clicked [idx])
11361
/* add item to list2 */
11362
ValNodeAddPointer (&dlp->list2, vnp->choice, vnp->data.ptrvalue);
11364
/* remove item from list1 */
11365
vnp->data.ptrvalue = NULL;
11368
dlp->list1 = vnp->next;
11372
prev->next = vnp->next;
11384
/* redraw contents of docpanels */
11385
PopulateDoubleListPanels (dlp);
11388
static void MoveToList1 (ButtoN b)
11391
ValNodePtr vnp, prev = NULL, vnp_next;
11394
dlp = (DoubleListPtr) GetObjectExtra (b);
11397
for (vnp = dlp->list2, idx = 0;
11398
vnp != NULL && idx < dlp->num_total;
11399
vnp = vnp_next, idx++)
11401
vnp_next = vnp->next;
11402
if (dlp->list2_clicked [idx])
11404
/* add item to list2 */
11405
ValNodeAddPointer (&dlp->list1, vnp->choice, vnp->data.ptrvalue);
11407
/* remove item from list1 */
11408
vnp->data.ptrvalue = NULL;
11411
dlp->list2 = vnp->next;
11415
prev->next = vnp->next;
11427
/* redraw contents of docpanels */
11428
PopulateDoubleListPanels (dlp);
11432
static void AcceptDoubleList (ButtoN b)
11436
dlp = (DoubleListPtr) GetObjectExtra (b);
11437
if (dlp == NULL) return;
11439
dlp->accepted = TRUE;
11444
static void CancelDoubleList (ButtoN b)
11448
dlp = (DoubleListPtr) GetObjectExtra (b);
11449
if (dlp == NULL) return;
11451
dlp->accepted = FALSE;
11455
static void DrawDoubleListWindow (DoubleListPtr dlp, CharPtr list1_name, CharPtr list2_name)
11459
Int2 height = LineHeight ();
11462
if (dlp == NULL) return;
11464
dlp->w = ModalWindow (-50, -33, -10, -10, NULL);
11465
doubleListCol [0].pixWidth = screenRect.right - screenRect.left;
11467
h = HiddenGroup (dlp->w, -1, 0, NULL);
11468
SetGroupSpacing (h, 10, 10);
11470
g = HiddenGroup (h, 3, 0, NULL);
11471
/* top row - labels */
11472
StaticPrompt (g, list1_name, 0, dialogTextHeight, programFont, 'c');
11473
StaticPrompt (g, "", 0, dialogTextHeight, programFont, 'c');
11474
StaticPrompt (g, list2_name, 0, dialogTextHeight, programFont, 'c');
11476
dlp->list1_ctrl = DocumentPanel (g, stdCharWidth * 25, height * 6);
11477
SetObjectExtra (dlp->list1_ctrl, dlp, NULL);
11478
/* movement buttons */
11479
k = HiddenGroup (g, 0, 2, NULL);
11480
dlp->to_button = PushButton (k, "->", MoveToList2);
11481
SetObjectExtra (dlp->to_button, dlp, NULL);
11482
dlp->from_button = PushButton (k, "<-", MoveToList1);
11483
SetObjectExtra (dlp->from_button, dlp, NULL);
11485
dlp->list2_ctrl = DocumentPanel (g, stdCharWidth * 25, height * 6);
11486
SetObjectExtra (dlp->list2_ctrl, dlp, NULL);
11488
c = HiddenGroup (h, 4, 0, NULL);
11489
dlp->accept_button = PushButton (c, "Accept", AcceptDoubleList);
11490
SetObjectExtra (dlp->accept_button, dlp, NULL);
11491
b = PushButton (c, "Cancel", CancelDoubleList);
11492
SetObjectExtra (b, dlp, NULL);
11494
PopulateDoubleListPanels (dlp);
11496
AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, NULL);
11500
static Int4 LIBCALLBACK GetAuthorPrintLen (Pointer userdata)
11506
ap = (AuthorPtr) userdata;
11507
if (ap == NULL || ap->name == NULL || ap->name->data == NULL) return 0;
11509
if (ap->name->choice == 2)
11511
pName = (NameStdPtr) ap->name->data;
11512
if (!StringHasNoText (pName->names[0]))
11514
text_len += StringLen (pName->names [0]) + 3;
11516
if (!StringHasNoText (pName->names[4]))
11518
text_len += StringLen (pName->names[4]) + 2;
11521
else if (ap->name->choice == 4 || ap->name->choice == 5)
11523
text_len = StringLen (ap->name->data) + 2;
11528
static void LIBCALLBACK PrintAuthor (CharPtr cp, Pointer userdata)
11533
ap = (AuthorPtr) userdata;
11534
if (ap == NULL || ap->name == NULL || ap->name->data == NULL || cp == NULL) return;
11536
if (ap->name->choice == 2)
11538
pName = (NameStdPtr) ap->name->data;
11539
if (!StringHasNoText (pName->names[0]))
11541
StringCat (cp, pName->names[0]);
11542
if (!StringHasNoText (pName->names[4]))
11544
StringCat (cp, ", ");
11547
if (!StringHasNoText (pName->names[4]))
11549
StringCat (cp, pName->names[4]);
11552
else if (ap->name->choice == 4 || ap->name->choice == 5)
11554
StringCat (cp, ap->name->data);
11556
StringCat (cp, "\n");
11559
static Boolean ChangeAuthorOrder (EditPubFormPtr epfp)
11561
DoubleListData dld;
11562
ValNodePtr tmp_list = NULL, vnp;
11565
if (epfp == NULL || epfp->edit_type != 3)
11570
if (epfp->names_list == NULL || epfp->names_list->next == NULL)
11575
/* create temporary copy of list */
11576
for (vnp = epfp->names_list; vnp != NULL; vnp = vnp->next)
11578
ap = AsnIoMemCopy (vnp->data.ptrvalue,
11579
(AsnReadFunc) AuthorAsnRead,
11580
(AsnWriteFunc) AuthorAsnWrite);
11583
ValNodeAddPointer (&(tmp_list), vnp->choice, ap);
11587
dld.list1 = tmp_list;
11589
dld.num_total = ValNodeLen (dld.list1);
11590
dld.list1_clicked = (BoolPtr) MemNew (dld.num_total * sizeof (Boolean));
11591
dld.list2_clicked = (BoolPtr) MemNew (dld.num_total * sizeof (Boolean));
11593
dld.getlenproc = GetAuthorPrintLen;
11594
dld.printitemproc = PrintAuthor;
11595
dld.none_in_1_ok = TRUE;
11596
dld.none_in_2_ok = FALSE;
11598
DrawDoubleListWindow (&dld, "Available Authors", "Final List");
11600
RealizeWindow (dld.w);
11606
ProcessExternalEvent ();
11612
/* now change author order */
11613
tmp_list = epfp->names_list;
11614
epfp->names_list = dld.list2;
11615
dld.list2 = tmp_list;
11619
for (vnp = dld.list1; vnp != NULL; vnp = vnp->next)
11621
vnp->data.ptrvalue = AuthorFree (vnp->data.ptrvalue);
11623
dld.list1 = ValNodeFree (dld.list1);
11624
for (vnp = dld.list2; vnp != NULL; vnp = vnp->next)
11626
vnp->data.ptrvalue = AuthorFree (vnp->data.ptrvalue);
11628
dld.list2 = ValNodeFree (dld.list2);
11631
return dld.accepted;
11634
static void DoEditPubs (ButtoN b)
11637
EditPubFormPtr epfp;
11642
epfp = (EditPubFormPtr) GetObjectExtra (b);
11643
if (epfp == NULL) return;
11645
sep = GetTopSeqEntryForEntityID (epfp->input_entityID);
11646
if (sep == NULL) return;
11648
PopulatePubConstraint (&(epfp->pcd));
11650
switch (epfp->edit_type)
11653
if (GetEnumPopup (epfp->field_to_set_popup, pub_field_no_any_alist, &val))
11655
epfp->field_to_set = val;
11662
epfp->repl_string = SaveStringFromText (epfp->repl_string_txt);
11663
OperateOnPubByConstraint (sep, epfp, EditPubSingleField);
11667
epfp->pdp = FindFirstSelectedPub ();
11668
if (epfp->pdp == NULL)
11670
Message (MSG_ERROR, "No selected pub!");
11674
epfp->alp = AuthListFree (epfp->alp);
11675
if (GetStatus (epfp->replace_author_list))
11677
pub = epfp->pdp->pub;
11678
while (epfp->alp == NULL && pub != NULL)
11680
epfp->alp = GetAuthorListForPub (pub);
11683
/* make a copy, so that if the selected pub matches the contraint, we won't wipe out
11684
* the contents of the master when we free the AuthListPtr for the selected pub
11685
* when we replace it with itself.
11687
if (epfp->alp != NULL)
11689
epfp->alp = AsnIoMemCopy ((Pointer) epfp->alp,
11690
(AsnReadFunc) AuthListAsnRead,
11691
(AsnWriteFunc) AuthListAsnWrite);
11695
epfp->title_str = MemFree (epfp->title_str);
11696
if (GetStatus (epfp->replace_title))
11698
pub = epfp->pdp->pub;
11699
while (epfp->title_str == NULL && pub != NULL)
11701
epfp->title_str = GetPubTitleSample (pub);
11704
epfp->title_str = StringSave (epfp->title_str);
11707
epfp->affil = AffilFree (epfp->affil);
11708
if (GetStatus (epfp->replace_affiliation))
11710
pub = epfp->pdp->pub;
11711
while (epfp->affil == NULL && pub != NULL)
11713
alp = GetAuthorListForPub (pub);
11714
if (alp != NULL && alp->affil != NULL)
11716
epfp->affil = AsnIoMemCopy ((Pointer) alp->affil,
11717
(AsnReadFunc) AffilAsnRead,
11718
(AsnWriteFunc) AffilAsnWrite);
11723
OperateOnPubByConstraint (sep, epfp, ReplacePubSectByConstraint);
11728
/* clear out any old list */
11729
epfp->names_list = FreeAuthorNameList (epfp->names_list);
11731
/* get the merged list */
11732
OperateOnPubByConstraint (sep, epfp, GetMergedAuthorListByConstraint);
11734
if (GetStatus (epfp->specify_author_order))
11736
if (!ChangeAuthorOrder (epfp))
11738
/* cancelled - go back to dialog */
11743
/* now set the merged list */
11744
OperateOnPubByConstraint (sep, epfp, SetMergedAuthorListByConstraint);
11748
ObjMgrSetDirtyFlag (epfp->input_entityID, TRUE);
11749
ObjMgrSendMsg (OM_MSG_UPDATE, epfp->input_entityID, 0, 0);
11752
if (! GetStatus (epfp->leaveDlgUp))
11754
Remove (epfp->form);
11759
static void ChangePubEditType (GrouP g)
11761
EditPubFormPtr epfp;
11763
epfp = (EditPubFormPtr) GetObjectExtra (g);
11764
if (epfp == NULL) return;
11766
epfp->edit_type = GetValue (epfp->edit_type_group);
11767
switch (epfp->edit_type)
11770
Show (epfp->single_field_group);
11771
Hide (epfp->replace_sect_group);
11772
Hide (epfp->merge_auth_list_group);
11775
Hide (epfp->single_field_group);
11776
Show (epfp->replace_sect_group);
11777
Hide (epfp->merge_auth_list_group);
11780
Hide (epfp->single_field_group);
11781
Hide (epfp->replace_sect_group);
11782
Show (epfp->merge_auth_list_group);
11783
epfp->edit_type = 3;
11789
static void LoadValueFromSelectedPub (ButtoN b)
11791
EditPubFormPtr epfp;
11793
SeqMgrFeatContext fcontext;
11794
SeqMgrDescContext dcontext;
11795
PubdescPtr pdp = NULL;
11798
CharPtr field_val = NULL;
11800
Int4 field_to_set = PUB_FIELD_ANY;
11802
epfp = (EditPubFormPtr) GetObjectExtra (b);
11803
if (epfp == NULL) return;
11805
if (GetEnumPopup (epfp->field_to_set_popup, pub_field_no_any_alist, &val))
11807
field_to_set = val;
11810
if (field_to_set == PUB_FIELD_ANY) return;
11812
ssp = ObjMgrGetSelected();
11814
while (NULL != ssp && field_val == NULL)
11816
if (ssp->itemtype == OBJ_SEQFEAT)
11818
sfp = SeqMgrGetDesiredFeature (ssp->entityID, NULL, ssp->itemID, 0, NULL, &fcontext);
11819
if (sfp != NULL && sfp->data.choice == SEQFEAT_PUB)
11821
pdp = sfp->data.value.ptrvalue;
11822
field_val = GetSampleStringFromPub (pdp, field_to_set);
11825
else if (ssp->itemtype == OBJ_SEQDESC)
11827
sdp = SeqMgrGetDesiredDescriptor (ssp->entityID, NULL, ssp->itemID, 0, NULL, &dcontext);
11828
if (sdp != NULL && sdp->choice == Seq_descr_pub)
11830
pdp = sdp->data.ptrvalue;
11831
field_val = GetSampleStringFromPub (pdp, field_to_set);
11837
SetTitle (epfp->repl_string_txt, field_val);
11840
static void CleanupEditPub (GraphiC g, VoidPtr data)
11842
EditPubFormPtr epfp;
11844
epfp = (EditPubFormPtr) data;
11847
/* cleanup for single field replace */
11848
epfp->repl_string = MemFree (epfp->repl_string);
11850
/* cleanup for replace section */
11851
epfp->alp = AuthListFree (epfp->alp);
11852
epfp->title_str = MemFree (epfp->title_str);
11853
epfp->affil = AffilFree (epfp->affil);
11855
/* cleanup for author list merge */
11856
epfp->names_list = FreeAuthorNameList (epfp->names_list);
11858
/* cleanup constraint */
11859
epfp->pcd.find_str = MemFree (epfp->pcd.find_str);
11861
StdCleanupFormProc (g, data);
11864
extern void EditPubs (IteM i)
11867
GrouP h, k, g, n, m, c;
11868
EditPubFormPtr epfp;
11874
bfp = currentFormDataPtr;
11876
bfp = GetObjectExtra (i);
11878
if (bfp == NULL) return;
11880
epfp = (EditPubFormPtr) MemNew (sizeof (EditPubFormData));
11881
if (epfp == NULL) return;
11882
epfp->input_entityID = bfp->input_entityID;
11883
epfp->input_itemID = bfp->input_itemID;
11884
epfp->input_itemtype = bfp->input_itemtype;
11886
w = FixedWindow (-50, -33, -10, -10, "Edit Publications", StdCloseWindowProc);
11887
SetObjectExtra (w, epfp, CleanupEditPub);
11888
epfp->form = (ForM) w;
11890
h = HiddenGroup (w, -1, 0, NULL);
11891
SetGroupSpacing (h, 10, 10);
11893
epfp->edit_type_group = NormalGroup (h, 3, 0, "Type of Edit", systemFont, ChangePubEditType);
11894
SetObjectExtra (epfp->edit_type_group, epfp, NULL);
11895
RadioButton (epfp->edit_type_group, "Replace Single Field");
11896
RadioButton (epfp->edit_type_group, "Replace Section");
11897
RadioButton (epfp->edit_type_group, "Merge author lists");
11898
SetValue (epfp->edit_type_group, 1);
11900
m = HiddenGroup (h, 0, 0, NULL);
11902
epfp->single_field_group = HiddenGroup (m, -1, 0, NULL);
11903
g = HiddenGroup (epfp->single_field_group, 2, 0, NULL);
11904
StaticPrompt (g, "Set text in", 0, dialogTextHeight, programFont, 'c');
11905
epfp->field_to_set_popup = PopupList (g, TRUE, NULL);
11906
InitEnumPopup (epfp->field_to_set_popup, pub_field_no_any_alist, NULL);
11907
SetEnumPopup (epfp->field_to_set_popup, pub_field_no_any_alist, PUB_FIELD_TITLE);
11908
StaticPrompt (g, "To new value", 0, dialogTextHeight, programFont, 'c');
11909
epfp->repl_string_txt = DialogText (g, "", 15, NULL);
11910
n = HiddenGroup (epfp->single_field_group, 1, 0, NULL);
11911
b = PushButton (n, "Load New Value from Selected Publication", LoadValueFromSelectedPub);
11912
SetObjectExtra (b, epfp, NULL);
11913
AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) n, NULL);
11915
epfp->replace_sect_group = HiddenGroup (m, 1, 0, NULL);
11916
epfp->replace_author_list = CheckBox (epfp->replace_sect_group, "Replace Author List with Selected Author List", NULL);
11917
epfp->replace_title = CheckBox (epfp->replace_sect_group, "Replace Title with Selected Title", NULL);
11918
epfp->replace_affiliation = CheckBox (epfp->replace_sect_group, "Replace Affiliation with Selected Affiliation", NULL);
11920
epfp->merge_auth_list_group = HiddenGroup (m, -1, 0, NULL);
11921
p = StaticPrompt (epfp->merge_auth_list_group, "Merge publication author lists", 0, dialogTextHeight, programFont, 'c');
11922
epfp->specify_author_order = CheckBox (epfp->merge_auth_list_group, "Specify Author Order", NULL);
11923
AlignObjects (ALIGN_CENTER, (HANDLE) p, (HANDLE) epfp->specify_author_order, NULL);
11924
ChangePubEditType (epfp->edit_type_group);
11926
k = HiddenGroup (h, -1, 0, NULL);
11927
SetGroupSpacing (k, 10, 10);
11928
CreatePubConstraintControls (k, &(epfp->pcd));
11930
c = HiddenGroup (h, 4, 0, NULL);
11931
b = DefaultButton (c, "Accept", DoEditPubs);
11932
SetObjectExtra (b, epfp, NULL);
11933
PushButton (c, "Cancel", StdCancelButtonProc);
11934
epfp->leaveDlgUp = CheckBox (c, "Leave Dialog Up", NULL);
11936
AlignObjects (ALIGN_CENTER, (HANDLE) epfp->edit_type_group, (HANDLE) m, (HANDLE) k, (HANDLE) c, NULL);