1 /*   macrodlg.c
2 * ===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *            National Center for Biotechnology Information (NCBI)
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government do not place any restriction on its use or reproduction.
13 *  We would, however, appreciate having the NCBI and the author cited in
14 *  any work or product based on this material
15 *
16 *  Although all reasonable efforts have been taken to ensure the accuracy
17 *  and reliability of the software and data, the NLM and the U.S.
18 *  Government do not and cannot warrant the performance or results that
19 *  may be obtained by using this software or data. The NLM and the U.S.
20 *  Government disclaim all warranties, express or implied, including
21 *  warranties of performance, merchantability or fitness for any particular
22 *  purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name:  macrodlg.c
27 *
28 * Author:  Colleen Bollin
29 *
30 * Version Creation Date:   11/23/2007
31 *
32 * $Revision: 1.352 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date     Name        Description of modification
39 * -------  ----------  -----------------------------------------------------
40 *
41 *
42 * ==========================================================================
43 */
44 
45 #include <objseq.h>
46 #include <objfdef.h>
47 #include <sqnutils.h>
48 #include <vibforms.h>
49 #include <document.h>
50 #include <dlogutil.h>
51 #include <cdrgn.h>
52 #include <seqpanel.h>
53 #include <biosrc.h>
54 #define NLM_GENERATED_CODE_PROTO
55 #include <objmacro.h>
56 #include <macroapi.h>
57 #include <macrodlg.h>
58 
59 /* macro editor dialog */
60 typedef struct macroeditorform {
61   FORM_MESSAGE_BLOCK
62   DoC    macro_summary;
63   ButtoN run_btn;
64 
65   ValNodePtr macro_list;
66   CharPtr    last_filename;
67   Boolean    unsaved;
68   Boolean    indexer_version;
69   FonT       summary_font;
70 
71   MacroCloseCallback close_callback;
72   Pointer            callback_data;
73 } MacroEditorFormData, PNTR MacroEditorFormPtr;
74 
75 static Boolean SaveMacroFile (ForM f, CharPtr filename);
76 
BeforeCloseMacroEditor(MacroEditorFormPtr f)77 static Boolean BeforeCloseMacroEditor (MacroEditorFormPtr f)
78 {
79   if (f != NULL) {
80     if (f->unsaved) {
81       if (Message (MSG_YN, "Do you want to save changes to the current file?") == ANS_YES) {
82         if (!SaveMacroFile(f->form, f->last_filename)) {
83           return FALSE;
84         }
85       }
86     }
87     if (f->close_callback != NULL) {
88       (f->close_callback)(f->last_filename, f->callback_data);
89     }
90   }
91   return TRUE;
92 }
93 
94 
CloseMacroEditorWindowProc(WindoW w)95 extern void CloseMacroEditorWindowProc (WindoW w)
96 
97 {
98   MacroEditorFormPtr f;
99 
100   f = (MacroEditorFormPtr) GetObjectExtra (w);
101   if (BeforeCloseMacroEditor(f)) {
102     Remove (w);
103   }
104 }
105 
106 
CleanupMacroEditorForm(GraphiC g,VoidPtr data)107 static void CleanupMacroEditorForm (GraphiC g, VoidPtr data)
108 
109 {
110   MacroEditorFormPtr f;
111 
112   f = (MacroEditorFormPtr) data;
113   if (f != NULL) {
114     f->macro_list = MacroActionListFree (f->macro_list);
115     f->last_filename = MemFree (f->last_filename);
116   }
117   StdCleanupFormProc (g, data);
118 }
119 
120 
SetupMacroEditorFont(MacroEditorFormPtr f)121 static void SetupMacroEditorFont (MacroEditorFormPtr f)
122 
123 {
124   if (f == NULL) return;
125 
126 #ifdef WIN_MAC
127   f->summary_font = ParseFont ("Times,12");
128 #endif
129 #ifdef WIN_MSWIN
130   f->summary_font = ParseFont ("Times New Roman,12");
131 #endif
132 #ifdef WIN_MOTIF
133   f->summary_font = ParseFont ("Times,12");
134 #endif
135 }
136 
137 
138 static void SetMacroEditorFileItems (MacroEditorFormPtr mefp);
139 
SaveMacroFile(ForM f,CharPtr filename)140 static Boolean SaveMacroFile (ForM f, CharPtr filename)
141 
142 {
143   MacroEditorFormPtr mefp;
144   Boolean            rval = FALSE;
145   Char               path [PATH_MAX];
146   AsnIoPtr           aip;
147 
148   mefp = (MacroEditorFormPtr) GetObjectExtra (f);
149   if (mefp != NULL) {
150     path [0] = '\0';
151     StringNCpy_0 (path, filename, sizeof (path));
152     if (path [0] != '\0' || GetOutputFileName (path, sizeof (path), NULL)) {
153       aip = AsnIoOpen (path, "w");
154       if (aip == NULL) {
155         Message (MSG_ERROR, "Unable to open %s", path);
156       } else {
157         MacroActionListAsnWrite (mefp->macro_list, aip, NULL);
158         AsnIoClose (aip);
159         mefp->last_filename = MemFree (mefp->last_filename);
160         mefp->last_filename = StringSave (path);
161         mefp->unsaved = FALSE;
162         rval = TRUE;
163       }
164     }
165   }
166   return rval;
167 }
168 
169 
170 static const Int4 kNumberColumnWidth = 40;
171 
SummarizeMacro(DoC doc,ValNodePtr macro_list,FonT font)172 static void SummarizeMacro (DoC doc, ValNodePtr macro_list, FonT font)
173 {
174   ValNodePtr vnp;
175   CharPtr    str;
176   CharPtr    tmp;
177   RecT       r;
178   Int4       pos;
179   ParData    ParFmt = {FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0};
180   ColData    ColFmt[] =
181   {
182     {kNumberColumnWidth, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
183     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
184     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
185     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
186     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
187     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
188     {0, 0, 80, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, TRUE}
189   };
190 
191 
192   Reset (doc);
193 
194   ObjectRect (doc, &r);
195   InsetRect (&r, 4, 4);
196 
197   ColFmt[5].pixWidth = stdCharWidth;
198   ColFmt[6].pixWidth = r.right - r.left - stdCharWidth - 48 - kNumberColumnWidth;
199 
200   if (font == NULL) font = programFont;
201 
202   if (macro_list == NULL) {
203     AppendText (doc, "(Click here to start a new macro script)", NULL, NULL, font);
204   } else {
205     AppendText (doc, "(Click here to insert an action at the beginning of the script)", NULL, NULL, font);
206     for (vnp = macro_list, pos = 1; vnp != NULL; vnp = vnp->next, pos++) {
207       str = SummarizeMacroAction (vnp);
208       tmp = (CharPtr) MemNew (sizeof (Char) * (StringLen (str) + 30));
209       sprintf (tmp, "%d\t\t\t\t\tC\t%s\n", pos, str);
210       str = MemFree (str);
211       AppendText (doc, tmp, &ParFmt, ColFmt, font);
212       tmp = MemFree (tmp);
213     }
214     AppendText (doc, "(Click here to insert an action at the end of the script)", NULL, NULL, font);
215   }
216   UpdateDocument (doc, 0, 0);
217 }
218 
219 
OpenMacroFile(ForM f,CharPtr filename)220 static Boolean OpenMacroFile (ForM f, CharPtr filename)
221 
222 {
223   MacroEditorFormPtr mefp;
224   Boolean            rval = FALSE;
225   CharPtr            extension;
226   Char               path [PATH_MAX];
227   AsnIoPtr           aip;
228   ValNodePtr         action_list;
229 
230   mefp = (MacroEditorFormPtr) GetObjectExtra (f);
231   if (mefp != NULL) {
232     if (mefp->unsaved) {
233       if (Message (MSG_YN, "Do you want to save changes to the current file?") == ANS_YES) {
234         if (!SaveMacroFile(f, mefp->last_filename)) {
235            return FALSE;
236         }
237       }
238     }
239     path [0] = '\0';
240     StringNCpy_0 (path, filename, sizeof (path));
241     extension = NULL;
242     if (path [0] != '\0' || GetInputFileName (path, sizeof (path), extension, "TEXT")) {
243       aip = AsnIoOpen (path, "r");
244       if (aip == NULL) {
245         Message (MSG_ERROR, "Unable to open %s", path);
246       } else {
247         action_list = MacroActionListAsnRead (aip, NULL);
248         if (action_list == NULL) {
249           Message (MSG_ERROR, "Unable to read action list from %s.", path);
250         } else {
251           mefp->macro_list = MacroActionListFree (mefp->macro_list);
252           mefp->macro_list = action_list;
253           mefp->last_filename = MemFree (mefp->last_filename);
254           mefp->last_filename = StringSave (path);
255           mefp->unsaved = FALSE;
256           rval = TRUE;
257           SetMacroEditorFileItems (mefp);
258           SummarizeMacro (mefp->macro_summary, mefp->macro_list, mefp->summary_font);
259           SafeEnable (mefp->run_btn);
260         }
261         AsnIoClose (aip);
262       }
263     }
264   }
265   return rval;
266 }
267 
268 
ImportMacroFile(ForM f,CharPtr filename)269 static Boolean ImportMacroFile (ForM f, CharPtr filename)
270 
271 {
272   MacroEditorFormPtr mefp;
273   Boolean            rval = FALSE;
274   CharPtr            extension;
275   Char               path [PATH_MAX];
276   AsnIoPtr           aip;
277   ValNodePtr         action_list;
278 
279   mefp = (MacroEditorFormPtr) GetObjectExtra (f);
280   if (mefp == NULL) return FALSE;
281   path [0] = '\0';
282   StringNCpy_0 (path, filename, sizeof (path));
283   extension = NULL;
284   if (path [0] != '\0' || GetInputFileName (path, sizeof (path), extension, "TEXT")) {
285     aip = AsnIoOpen (path, "r");
286     if (aip == NULL) {
287       Message (MSG_ERROR, "Unable to open %s", path);
288     } else {
289       action_list = MacroActionListAsnRead (aip, NULL);
290       if (action_list == NULL) {
291         Message (MSG_ERROR, "Unable to read action list from %s.", path);
292       } else {
293         ValNodeLink (&(mefp->macro_list), action_list);
294         mefp->unsaved = FALSE;
295         rval = TRUE;
296         SetMacroEditorFileItems (mefp);
297         SummarizeMacro (mefp->macro_summary, mefp->macro_list, mefp->summary_font);
298         SafeEnable (mefp->run_btn);
299       }
300       AsnIoClose (aip);
301     }
302   }
303   return rval;
304 }
305 
306 
SetMacroEditorFileItems(MacroEditorFormPtr mefp)307 static void SetMacroEditorFileItems (MacroEditorFormPtr mefp)
308 
309 {
310   IteM  i;
311 
312   if (mefp != NULL) {
313     i = FindFormMenuItem ((BaseFormPtr) mefp, VIB_MSG_OPEN);
314     SafeSetTitle (i, "Load Macro File");
315     SafeEnable (i);
316 
317     i = FindFormMenuItem ((BaseFormPtr) mefp, VIB_MSG_IMPORT);
318     SafeSetTitle (i, "Add Macros from File to Script");
319     SafeEnable (i);
320 
321     i = FindFormMenuItem ((BaseFormPtr) mefp, VIB_MSG_SAVE);
322     SafeSetTitle (i, "Save Macro File");
323     if (mefp->macro_list == NULL) {
324       SafeDisable (i);
325     } else {
326       SafeEnable (i);
327     }
328     i = FindFormMenuItem ((BaseFormPtr) mefp, VIB_MSG_SAVE_AS);
329     SafeSetTitle (i, "Save Macro File As");
330     if (mefp->macro_list == NULL) {
331       SafeDisable (i);
332     } else {
333       SafeEnable (i);
334     }
335   }
336 }
337 
338 
MacroEditorFormMessage(ForM f,Int2 mssg)339 static void MacroEditorFormMessage (ForM f, Int2 mssg)
340 
341 {
342   MacroEditorFormPtr  mefp;
343   ValNodePtr          vnp, string_list = NULL;
344   Int4                len = 1;
345   CharPtr             str;
346 
347   mefp = (MacroEditorFormPtr) GetObjectExtra (f);
348   if (mefp != NULL) {
349     switch (mssg) {
350       case VIB_MSG_OPEN :
351         OpenMacroFile (f, NULL);
352         break;
353       case VIB_MSG_IMPORT :
354         ImportMacroFile (f, NULL);
355         break;
356       case VIB_MSG_SAVE :
357         SaveMacroFile (f, mefp->last_filename);
358         break;
359       case VIB_MSG_SAVE_AS :
360         SaveMacroFile (f, NULL);
361         break;
362       case VIB_MSG_CUT :
363         StdCutTextProc (NULL);
364         break;
365       case VIB_MSG_COPY :
366         /* get length of entire macro list */
367         for (vnp = mefp->macro_list; vnp != NULL; vnp = vnp->next) {
368           str = SummarizeMacroAction (vnp);
369           len += StringLen (str) + 2;
370           ValNodeAddPointer (&string_list, 0, str);
371         }
372         str = (CharPtr) MemNew (sizeof (Char) * len);
373         str[0] = 0;
374         for (vnp = string_list; vnp != NULL; vnp = vnp->next) {
375           StringCat (str, vnp->data.ptrvalue);
376           StringCat (str, "\r\n");
377         }
378         string_list = ValNodeFreeData (string_list);
379         StringToClipboard (str);
380         str = MemFree (str);
381         break;
382       case VIB_MSG_PASTE :
383         StdPasteTextProc (NULL);
384         break;
385       case VIB_MSG_DELETE :
386         break;
387       case VIB_MSG_CLOSE:
388       case VIB_MSG_QUIT:
389         CloseMacroEditorWindowProc ((WindoW)f);
390         break;
391       default :
392         break;
393     }
394   }
395 }
396 
397 static WindoW sMacroReportWindow = NULL;
398 
CloseMacroReportWindowProc(WindoW w)399 static void CloseMacroReportWindowProc (WindoW w)
400 
401 {
402   sMacroReportWindow = NULL;
403   Remove (w);
404 }
405 
MakeMacroReportWindow(LogInfoPtr lip)406 static void MakeMacroReportWindow (LogInfoPtr lip)
407 {
408   GrouP h;
409   DoC   doc;
410   ReadBufferData rbd;
411   CharPtr line;
412 
413   if (sMacroReportWindow == NULL) {
414     if (lip == NULL || StringHasNoText (lip->path) || !lip->data_in_log) {
415       return;
416     }
417     sMacroReportWindow = FixedWindow (-50, -33, -10, -10, "Macro Actions", CloseMacroReportWindowProc);
418     h = HiddenGroup (sMacroReportWindow, -1, 0, NULL);
419     SetGroupSpacing (h, 10, 10);
420     doc = DocumentPanel (h, stdCharWidth * 50, stdLineHeight * 24);
421     SetObjectExtra (sMacroReportWindow, doc, NULL);
422     RealizeWindow (sMacroReportWindow);
423   }
424   doc = (DoC) GetObjectExtra (sMacroReportWindow);
425   Reset (doc);
426   if (lip != NULL && !StringHasNoText (lip->path) && lip->data_in_log) {
427     FileClose (lip->fp);
428     lip->fp = NULL;
429     rbd.fp = FileOpen (lip->path, "r");
430     if (rbd.fp != NULL) {
431       rbd.current_data = NULL;
432       line = AbstractReadFunction (&rbd);
433       while (line != NULL)
434       {
435         AppendText (doc, line, NULL, NULL, systemFont);
436         line = MemFree (line);
437         line = AbstractReadFunction (&rbd);
438       }
439       FileClose (rbd.fp);
440     }
441   }
442 
443   /* redraw */
444   InvalDocument (doc);
445   Show (sMacroReportWindow);
446   Select (sMacroReportWindow);
447   Update();
448 }
449 
RunMacro(ButtoN b)450 static void RunMacro (ButtoN b)
451 {
452   MacroEditorFormPtr  f;
453   SeqEntryPtr         sep;
454   ValNodePtr          sep_list, vnp;
455   Uint2               entityID;
456   LogInfoPtr          lip;
457   Int4                num_no_op = 0, tmp;
458 
459   f = (MacroEditorFormPtr) GetObjectExtra (b);
460   if (f == NULL) return;
461 
462   if (f->macro_list == NULL) {
463     Message (MSG_ERROR, "No macro loaded!");
464   } else {
465     sep_list = GetViewedSeqEntryList ();
466     if (sep_list == NULL) {
467       Message (MSG_ERROR, "No records open!");
468     } else if (sep_list->next != NULL
469       && ANS_CANCEL == Message (MSG_OKC, "You have more than one record open - run macro for all open records?")) {
470       /* do nothing */
471     } else {
472       WatchCursor();
473       Update();
474       lip = OpenLog ("Macro Actions");
475       for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
476         sep = vnp->data.ptrvalue;
477         entityID = ObjMgrGetEntityIDForChoice(sep);
478         lip->data_in_log |= ApplyMacroToSeqEntryExEx (sep, f->macro_list, lip->fp, Sequin_GlobalAlign2Seq, &tmp);
479         num_no_op += tmp;
480         ObjMgrSetDirtyFlag (entityID, TRUE);
481         ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
482       }
483       sep_list = ValNodeFree (sep_list);
484       ArrowCursor ();
485       Update ();
486       if (lip->data_in_log) {
487         if (num_no_op > 0) {
488           fprintf (lip->fp, "%d actions had no effect.\n", num_no_op);
489         }
490       } else {
491         fprintf (lip->fp, "Macro had no effect\n");
492         lip->data_in_log = TRUE;
493       }
494       MakeMacroReportWindow (lip);
495       lip = FreeLog (lip);
496     }
497   }
498 }
499 
500 static Boolean EditMacroAction (ValNodePtr action, Boolean indexer_version);
501 
EditMacroItem(MacroEditorFormPtr f,Int2 item)502 static Boolean EditMacroItem (MacroEditorFormPtr f, Int2 item)
503 {
504   Boolean rval = FALSE;
505   ValNodePtr vnp;
506 
507   if (f == NULL) return FALSE;
508 
509   for (vnp = f->macro_list; vnp != NULL && item > 1; vnp = vnp->next, item--) {}
510   if (vnp != NULL) {
511     rval = EditMacroAction (vnp, f->indexer_version);
512   }
513   return rval;
514 }
515 
BuildDefaultAECRAction(Uint1 action_type,Uint1 qual_type)516 static AECRActionPtr BuildDefaultAECRAction (Uint1 action_type, Uint1 qual_type)
517 {
518   AECRActionPtr action = AECRActionNew();
519   ApplyActionPtr apply;
520   EditActionPtr  edit;
521   ConvertActionPtr convert;
522   CopyActionPtr copy;
523   SwapActionPtr swap;
524   AECRParseActionPtr parse;
525   RemoveActionPtr remove;
526   RemoveOutsideActionPtr ro;
527 
528   switch (action_type) {
529     case ActionChoice_apply:
530       apply = ApplyActionNew();
531       apply->field = ValNodeNew (NULL);
532       apply->field->choice = qual_type;
533       action->action = ValNodeNew (NULL);
534       action->action->choice = action_type;
535       action->action->data.ptrvalue = apply;
536       break;
537     case ActionChoice_edit:
538       edit = EditActionNew ();
539       edit->field = ValNodeNew (NULL);
540       edit->field->choice = qual_type;
541       action->action = ValNodeNew (NULL);
542       action->action->choice = action_type;
543       action->action->data.ptrvalue = edit;
544       break;
545     case ActionChoice_remove_outside:
546       ro = RemoveOutsideActionNew ();
547       ro->field = ValNodeNew (NULL);
548       ro->field->choice = qual_type;
549       action->action = ValNodeNew (NULL);
550       action->action->choice = action_type;
551       action->action->data.ptrvalue = ro;
552       break;
553     case ActionChoice_convert:
554       convert = ConvertActionNew();
555       convert->fields = ValNodeNew (NULL);
556       convert->fields->choice = qual_type;
557       action->action = ValNodeNew (NULL);
558       action->action->choice = action_type;
559       action->action->data.ptrvalue = convert;
560       break;
561     case ActionChoice_copy:
562       copy = CopyActionNew();
563       copy->fields = ValNodeNew (NULL);
564       copy->fields->choice = qual_type;
565       action->action = ValNodeNew (NULL);
566       action->action->choice = action_type;
567       action->action->data.ptrvalue = copy;
568       break;
569     case ActionChoice_swap:
570       swap = SwapActionNew();
571       swap->fields = ValNodeNew (NULL);
572       swap->fields->choice = qual_type;
573       action->action = ValNodeNew (NULL);
574       action->action->choice = action_type;
575       action->action->data.ptrvalue = swap;
576       break;
577     case ActionChoice_remove:
578       remove = RemoveActionNew();
579       remove->field = ValNodeNew (NULL);
580       remove->field->choice = qual_type;
581       action->action = ValNodeNew (NULL);
582       action->action->choice = action_type;
583       action->action->data.ptrvalue = remove;
584       break;
585     case ActionChoice_parse:
586       parse = AECRParseActionNew();
587       parse->fields = ValNodeNew (NULL);
588       parse->fields->choice = qual_type;
589       action->action = ValNodeNew (NULL);
590       action->action->choice = action_type;
591       action->action->data.ptrvalue = parse;
592       break;
593   }
594 
595   return action;
596 }
597 
598 
BuildDefaultApplyFeatureAction(Uint2 feat_type)599 static ApplyFeatureActionPtr BuildDefaultApplyFeatureAction (Uint2 feat_type)
600 {
601   ApplyFeatureActionPtr action;
602   FeatQualLegalValPtr   qual;
603 
604   action = ApplyFeatureActionNew ();
605   action->type = feat_type;
606   action->location = ValNodeNew (NULL);
607   action->location->choice = LocationChoice_whole_sequence;
608   action->seq_list = ValNodeNew (NULL);
609   action->seq_list->choice = SequenceListChoice_all;
610   qual = FeatQualLegalValNew ();
611   qual->qual = Feat_qual_legal_codon_start;
612   qual->val = StringSave ("best");
613   action->fields = ValNodeNew (NULL);
614   action->fields->choice = FeatQualLegalValChoice_qual;
615   action->fields->data.ptrvalue = qual;
616   return action;
617 }
618 
619 
BuildDefaultEditFeatureLocationAction(Uint2 feat_type)620 static EditFeatureLocationActionPtr BuildDefaultEditFeatureLocationAction (Uint2 feat_type)
621 {
622   EditFeatureLocationActionPtr a;
623   EditLocationStrandPtr strand;
624 
625   a = EditFeatureLocationActionNew ();
626   a->type = feat_type;
627   a->action = ValNodeNew (NULL);
628   a->action->choice = LocationEditType_strand;
629   strand = EditLocationStrandNew ();
630   strand->strand_to = Feature_location_strand_to_reverse;
631   a->action->data.ptrvalue = strand;
632   a->retranslate_cds = FALSE;
633   a->also_edit_gene = FALSE;
634   return a;
635 }
636 
637 
BuildDefaultRemoveFeatureAction(void)638 static RemoveFeatureActionPtr BuildDefaultRemoveFeatureAction (void)
639 {
640   RemoveFeatureActionPtr remove;
641 
642   remove = RemoveFeatureActionNew ();
643   return remove;
644 }
645 
646 
BuildDefaultNewMacroAction(void)647 static ValNodePtr BuildDefaultNewMacroAction (void)
648 {
649   ValNodePtr vnp;
650   ApplyFeatureActionPtr apply_feat;
651 
652   apply_feat = BuildDefaultApplyFeatureAction (Macro_feature_type_cds);
653 
654   vnp = ValNodeNew (NULL);
655   vnp->choice = MacroActionChoice_add_feature;
656   vnp->data.ptrvalue = apply_feat;
657   return vnp;
658 }
659 
660 
UpdateMacroSummary(MacroEditorFormPtr f,Int4 scroll_pos)661 static void UpdateMacroSummary (MacroEditorFormPtr f, Int4 scroll_pos)
662 {
663   Int4 scroll_max;
664   BaR  sb_vert;
665 
666   if (f == NULL) return;
667 
668   f->unsaved = TRUE;
669   SetMacroEditorFileItems (f);
670   SummarizeMacro (f->macro_summary, f->macro_list, f->summary_font);
671   if (f->macro_list == NULL) {
672     SafeDisable (f->run_btn);
673   } else {
674     SafeEnable (f->run_btn);
675   }
676   if (scroll_pos > 0) {
677     sb_vert = GetSlateVScrollBar ((SlatE) f->macro_summary);
678     scroll_max = GetBarMax (sb_vert);
679     if (scroll_pos > scroll_max) {
680       scroll_pos = scroll_max;
681     }
682     CorrectBarValue (sb_vert, scroll_pos);
683   }
684 }
685 
686 
687 static void AddMacroActions (MacroEditorFormPtr f, Int2 item);
688 
689 
CloneMacroItem(MacroEditorFormPtr f,Int2 item)690 static Boolean CloneMacroItem (MacroEditorFormPtr f, Int2 item)
691 {
692   ValNodePtr            this_action = NULL, new_action;
693   Int2                  pos;
694   Int4                  scroll_pos;
695   BaR                   sb_vert;
696 
697   if (f == NULL || item == 0 || f->macro_list == NULL) {
698     return FALSE;
699   }
700 
701   pos = 1;
702   this_action = f->macro_list;
703   while (pos < item && this_action != NULL) {
704     pos++;
705     this_action = this_action->next;
706   }
707   if (this_action == NULL) {
708     return FALSE;
709   }
710   new_action = AsnIoMemCopy (this_action, (AsnReadFunc) MacroActionChoiceAsnRead, (AsnWriteFunc) MacroActionChoiceAsnWrite);
711   if (new_action != NULL) {
712     new_action->next = this_action->next;
713     this_action->next = new_action;
714   }
715 
716   /* get current scroll position */
717   sb_vert = GetSlateVScrollBar ((SlatE) f->macro_summary);
718   scroll_pos = GetBarValue (sb_vert);
719   /* we will want to increase the scroll position after each addition
720    * note that we need to get the scroll bar and check the initial position
721    * each time - if there was no scroll bar after the last update, scroll_pos
722    * needs to be zero to start.
723    */
724   scroll_pos++;
725 
726   /* update summary */
727   UpdateMacroSummary (f, scroll_pos);
728   return TRUE;
729 }
730 
731 
ClickMacroDoc(DoC d,PoinT pt)732 static void ClickMacroDoc (DoC d, PoinT pt)
733 {
734   Int2               item, row, col;
735   RecT               rct;
736   MacroEditorFormPtr f;
737   ValNodePtr         vnp, vnp_prev = NULL, two_prev = NULL, vnp_next;
738   Boolean            changed_macro = FALSE;
739   BaR                sb_vert = NULL;
740   Int2               scroll_pos = 0;
741 
742   f = (MacroEditorFormPtr) GetObjectExtra (d);
743   if (f == NULL) return;
744 
745   MapDocPoint (d, pt, &item, &row, &col, &rct);
746   if (item == 0 && row == 0 && f->macro_list == NULL) {
747     AddMacroActions (f, 0);
748   } else if (item > 0 && row > 0) {
749     if (item == 1) {
750       /* add to beginning of list */
751       AddMacroActions (f, 0);
752     } else if (item == ValNodeLen (f->macro_list) + 2) {
753       /* add to end of list */
754       AddMacroActions (f, item);
755     } else {
756       /* correct for explanatory line */
757       item--;
758       sb_vert = GetSlateVScrollBar ((SlatE) f->macro_summary);
759       scroll_pos = GetBarValue (sb_vert);
760       switch (col) {
761         case 2:
762           /* delete this item */
763           for (vnp = f->macro_list; vnp != NULL && item > 1; vnp = vnp->next, item--) {
764             vnp_prev = vnp;
765           }
766           if (vnp != NULL) {
767             if (vnp_prev == NULL) {
768               f->macro_list = vnp->next;
769             } else {
770               vnp_prev->next = vnp->next;
771             }
772             vnp->next = NULL;
773             vnp = MacroActionListFree (vnp);
774             changed_macro = TRUE;
775           }
776           break;
777         case 3:
778           /* move this item up */
779           for (vnp = f->macro_list; vnp != NULL && item > 1; vnp = vnp->next, item--) {
780             two_prev = vnp_prev;
781             vnp_prev = vnp;
782           }
783           if (vnp != NULL && vnp_prev != NULL) {
784             vnp_prev->next = vnp->next;
785             vnp->next = vnp_prev;
786             if (two_prev == NULL) {
787               f->macro_list = vnp;
788             } else {
789               two_prev->next = vnp;
790             }
791             /* decrease the scroll position, so cursor will still be over the same item */
792             scroll_pos--;
793             changed_macro = TRUE;
794           }
795           break;
796         case 4:
797           /* move this item down */
798           for (vnp = f->macro_list; vnp != NULL && item > 1; vnp = vnp->next, item--) {
799             vnp_prev = vnp;
800           }
801           if (vnp != NULL && vnp->next != NULL) {
802             vnp_next = vnp->next;
803             vnp->next = vnp_next->next;
804             vnp_next->next = vnp;
805             if (vnp_prev == NULL) {
806               f->macro_list = vnp_next;
807             } else {
808               vnp_prev->next = vnp_next;
809             }
810             /* increase the scroll position, so cursor will still be over the same item */
811             scroll_pos++;
812             changed_macro = TRUE;
813           }
814           break;
815         case 5:
816           /* insert item */
817           if (pt.y >= rct.top && pt.y <= rct.top + 4) {
818             /* insert macro before this one */
819             AddMacroActions (f, item - 1);
820           } else if (pt.y >= rct.bottom - 4 && pt.y <= rct.bottom) {
821             /* insert macro after this one */
822             AddMacroActions (f, item);
823           }
824           break;
825         case 6:
826           /* clone item */
827           CloneMacroItem (f, item);
828           changed_macro = TRUE;
829           break;
830         case 7:
831           /* edit this item */
832           changed_macro = EditMacroItem (f, item);
833           break;
834       }
835     }
836   }
837   if (changed_macro) {
838     UpdateMacroSummary (f, scroll_pos);
839   }
840 }
841 
842 
DrawMacroDocControls(DoC d,RectPtr r,Int2 item,Int2 firstLine)843 static void DrawMacroDocControls (DoC d, RectPtr r, Int2 item, Int2 firstLine)
844 
845 {
846   MacroEditorFormPtr dlg;
847   RecT               rct;
848   Int4               width;
849   PoinT              pt1, pt2;
850 
851   dlg = (MacroEditorFormPtr) GetObjectExtra (d);
852   if (dlg == NULL) return;
853   /* don't draw controls for explanatory text */
854   if (item == 1 || item >= ValNodeLen (dlg->macro_list) + 2) return;
855 
856   if (dlg != NULL && r != NULL && item > 0 && firstLine == 0) {
857     rct = *r;
858 
859     rct.left += kNumberColumnWidth;
860 
861     width = 10;
862     /* draw X for deletion */
863     pt1.x = rct.left + 1;
864     pt1.y = rct.top + 1;
865     pt2.x = pt1.x + width;
866     pt2.y = pt1.y + width;
867     DrawLine (pt1, pt2);
868     pt1.x = rct.left + 1;
869     pt1.y = rct.top + 1 + width;
870     pt2.x = pt1.x + width;
871     pt2.y = rct.top + 1;
872     DrawLine (pt1, pt2);
873 
874     /* draw up arrow for moving step up */
875     if (item > 2) {
876       pt1.x = rct.left + width + 3;
877       pt1.y = rct.top + 3;
878       pt2.x = pt1.x + 5;
879       pt2.y = rct.top + 1;
880       DrawLine (pt1, pt2);
881       pt1.x = pt2.x + 5;
882       DrawLine (pt1, pt2);
883       pt1.x = pt2.x;
884       pt1.y = pt2.y + width;
885       DrawLine (pt1, pt2);
886     }
887     /* draw up arrow for moving step up */
888     if (item < ValNodeLen (dlg->macro_list) + 1) {
889       pt1.x = rct.left + 2 * width + 5;
890       pt1.y = rct.top + width - 2;
891       pt2.x = pt1.x + 5;
892       pt2.y = rct.top + width + 1;
893       DrawLine (pt1, pt2);
894       pt1.x = pt2.x + 5;
895       DrawLine (pt1, pt2);
896       pt1.x = pt2.x;
897       pt1.y = rct.top + 1;
898       DrawLine (pt1, pt2);
899     }
900 
901     /* draw insertion controls */
902     pt1.x = rct.left + 3 * width + 7;
903     pt1.y = rct.top + 4;
904     pt2.x = pt1.x + width;
905     pt2.y = rct.top;
906     if (item > 2) {
907       DrawLine (pt1, pt2);
908     }
909     pt1.y = rct.bottom - 4;
910     pt2.y = rct.bottom;
911     if (item < ValNodeLen (dlg->macro_list) + 1) {
912       DrawLine (pt1, pt2);
913     }
914   }
915 }
916 
917 
LaunchMacroEditor(Uint2 entityID,CharPtr filename,MacroCloseCallback close_callback,Pointer callback_data)918 NLM_EXTERN void LaunchMacroEditor (Uint2 entityID, CharPtr filename, MacroCloseCallback close_callback, Pointer callback_data)
919 {
920   WindoW              w;
921   MacroEditorFormPtr  f;
922   GrouP               h, c = NULL;
923   MenU                m;
924 #ifdef TEST_MACRO_TEMPLATE_EDITOR
925   ButtoN              b;
926 #endif
927 
928   f = (MacroEditorFormPtr) MemNew (sizeof (MacroEditorFormData));
929   if (f == NULL) return;
930 
931   w = FixedWindow (-50, -33, -10, -10, "Macro Editor", CloseMacroEditorWindowProc);
932   SetObjectExtra (w, f, CleanupMacroEditorForm);
933   f->form = (ForM) w;
934   f->input_entityID = entityID;
935 
936   f->formmessage = MacroEditorFormMessage;
937 
938   f->macro_list = NULL;
939   f->last_filename = NULL;
940   f->unsaved = FALSE;
941   f->indexer_version = TRUE;
942   f->close_callback = close_callback;
943   f->callback_data = callback_data;
944 
945   m = PulldownMenu (w, "File");
946   FormCommandItem (m, "Open", (BaseFormPtr)f, VIB_MSG_OPEN);
947   FormCommandItem (m, "Import", (BaseFormPtr)f, VIB_MSG_IMPORT);
948   FormCommandItem (m, "Save", (BaseFormPtr)f, VIB_MSG_SAVE);
949   FormCommandItem (m, "Save As", (BaseFormPtr)f, VIB_MSG_SAVE_AS);
950   SeparatorItem (m);
951   FormCommandItem (m, "Quit", (BaseFormPtr)f, VIB_MSG_QUIT);
952   m = PulldownMenu (w, "Edit");
953   FormCommandItem (m, "Copy All to Clipboard", (BaseFormPtr) f, VIB_MSG_COPY);
954 
955   SetupMacroEditorFont (f);
956   SetMacroEditorFileItems (f);
957 
958   h = HiddenGroup (w, -1, 0, NULL);
959   SetGroupSpacing (h, 10, 10);
960 
961   f->macro_summary = DocumentPanel (h, stdCharWidth * 50, stdLineHeight * 20);
962   SetObjectExtra (f->macro_summary, f, NULL);
963   SetDocProcs (f->macro_summary, ClickMacroDoc, NULL, NULL, NULL);
964   SetDocShade (f->macro_summary, DrawMacroDocControls, NULL, NULL, NULL);
965 
966   if (f->input_entityID != 0) {
967     c = HiddenGroup (h, 3, 0, NULL);
968     f->run_btn = PushButton (c, "Run", RunMacro);
969     SetObjectExtra (f->run_btn, f, NULL);
970     Disable (f->run_btn);
971   }
972 
973   AlignObjects (ALIGN_CENTER, (HANDLE) f->macro_summary, (HANDLE) c, NULL);
974   SummarizeMacro (f->macro_summary, f->macro_list, f->summary_font);
975   if (!StringHasNoText (filename)) {
976     OpenMacroFile (f->form, filename);
977   }
978   Show (w);
979 }
980 
981 
LaunchMacroEditorMenuItem(IteM i)982 NLM_EXTERN void LaunchMacroEditorMenuItem (IteM i)
983 {
984   BaseFormPtr         bfp;
985 
986 #ifdef WIN_MAC
987   bfp = currentFormDataPtr;
988 #else
989   bfp = GetObjectExtra (i);
990 #endif
991   LaunchMacroEditor (bfp->input_entityID, NULL, NULL, NULL);
992 }
993 
994 
ClearDialogBtn(ButtoN b)995 static void ClearDialogBtn (ButtoN b)
996 {
997   DialoG d;
998 
999   d = (DialoG) GetObjectExtra (b);
1000 
1001   PointerToDialog (d, NULL);
1002 }
1003 
1004 
1005 typedef struct textmarkerdialog
1006 {
1007   DIALOG_MESSAGE_BLOCK
1008 
1009   GrouP marker_choice;
1010   TexT  marker_text;
1011 
1012   Nlm_ChangeNotifyProc     change_notify;
1013   Pointer                  change_userdata;
1014 } TextMarkerDialogData, PNTR TextMarkerDialogPtr;
1015 
1016 
ResetTextMarkerDialog(DialoG d)1017 static void ResetTextMarkerDialog (DialoG d)
1018 {
1019   TextMarkerDialogPtr tp;
1020 
1021   tp = (TextMarkerDialogPtr) GetObjectExtra (d);
1022   if (tp == NULL) {
1023     return;
1024   }
1025   SetValue (tp->marker_choice, 1);
1026   SetTitle (tp->marker_text, "");
1027   Enable (tp->marker_text);
1028 }
1029 
1030 
TextMarkerToDialog(DialoG d,Pointer data)1031 static void TextMarkerToDialog(DialoG d, Pointer data)
1032 {
1033   TextMarkerDialogPtr tp;
1034   TextMarkerPtr       tdata;
1035 
1036   tp = (TextMarkerDialogPtr) GetObjectExtra (d);
1037   if (tp == NULL) {
1038     return;
1039   }
1040 
1041   tdata = (TextMarkerPtr) data;
1042 
1043   if (tdata == NULL) {
1044     ResetTextMarkerDialog(d);
1045   } else {
1046     if (tdata->choice == TextMarker_free_text) {
1047       SetValue (tp->marker_choice, 1);
1048       SetTitle (tp->marker_text, tdata->data.ptrvalue == NULL ? "" : tdata->data.ptrvalue);
1049       Enable (tp->marker_text);
1050     } else if (tdata->choice == TextMarker_digits) {
1051       SetValue (tp->marker_choice, 3);
1052       SetTitle (tp->marker_text, "");
1053       Disable (tp->marker_text);
1054     } else if (tdata->choice == TextMarker_letters) {
1055       SetValue (tp->marker_choice, 4);
1056       SetTitle (tp->marker_text, "");
1057       Disable (tp->marker_text);
1058     } else {
1059       SetValue (tp->marker_choice, 1);
1060       SetTitle (tp->marker_text, "");
1061       Enable (tp->marker_text);
1062     }
1063   }
1064 }
1065 
1066 
DialogToTextMarker(DialoG d)1067 static Pointer DialogToTextMarker (DialoG d)
1068 {
1069   TextMarkerDialogPtr tp;
1070   Int2                val;
1071   ValNodePtr          tdata = NULL;
1072 
1073   tp = (TextMarkerDialogPtr) GetObjectExtra (d);
1074   if (tp == NULL) {
1075     return NULL;
1076   }
1077 
1078   val = GetValue (tp->marker_choice);
1079   if (val == 1) {
1080     ValNodeAddPointer (&tdata, TextMarker_free_text, JustSaveStringFromText (tp->marker_text));
1081   } else if (val == 3) {
1082     tdata = ValNodeNew (NULL);
1083     tdata->choice = TextMarker_digits;
1084   } else if (val == 4) {
1085     tdata = ValNodeNew (NULL);
1086     tdata->choice = TextMarker_letters;
1087   }
1088 
1089   if (IsTextMarkerEmpty(tdata)) {
1090     tdata = TextMarkerFree (tdata);
1091   }
1092   return tdata;
1093 }
1094 
1095 
TextMarkerMessage(DialoG d,Int2 mssg)1096 static void TextMarkerMessage (DialoG d, Int2 mssg)
1097 
1098 {
1099   TextMarkerDialogPtr tp;
1100 
1101   tp = (TextMarkerDialogPtr) GetObjectExtra (d);
1102   if (tp != NULL) {
1103     switch (mssg) {
1104       case VIB_MSG_INIT :
1105         ResetTextMarkerDialog (d);
1106         break;
1107       case VIB_MSG_ENTER :
1108         Select (tp->marker_text);
1109         break;
1110       default :
1111         break;
1112     }
1113   }
1114 }
1115 
1116 
ChangeTextMarkerChoice(GrouP g)1117 static void ChangeTextMarkerChoice (GrouP g)
1118 {
1119   TextMarkerDialogPtr tp;
1120   Int2 val;
1121 
1122   tp = (TextMarkerDialogPtr) GetObjectExtra (g);
1123   if (tp == NULL) {
1124     return;
1125   }
1126 
1127   val = GetValue (tp->marker_choice);
1128   if (val == 1) {
1129     Enable (tp->marker_text);
1130   } else {
1131     Disable (tp->marker_text);
1132   }
1133 
1134   if (tp->change_notify != NULL) {
1135     (tp->change_notify) (tp->change_userdata);
1136   }
1137 }
1138 
1139 
ChangeTextMarkerText(TexT t)1140 static void ChangeTextMarkerText (TexT t)
1141 {
1142   TextMarkerDialogPtr tp;
1143 
1144   tp = (TextMarkerDialogPtr) GetObjectExtra (t);
1145   if (tp == NULL) {
1146     return;
1147   }
1148 
1149   if (tp->change_notify != NULL) {
1150     (tp->change_notify) (tp->change_userdata);
1151   }
1152 }
1153 
1154 
TextMarkerDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)1155 static DialoG TextMarkerDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
1156 {
1157   TextMarkerDialogPtr tp;
1158   GrouP               p;
1159 
1160   tp = (TextMarkerDialogPtr) MemNew (sizeof (TextMarkerDialogData));
1161   if (tp == NULL)
1162   {
1163     return NULL;
1164   }
1165 
1166   p = HiddenGroup (h, -1, 0, NULL);
1167   SetObjectExtra (p, tp, StdCleanupExtraProc);
1168 
1169   tp->dialog = (DialoG) p;
1170   tp->todialog = TextMarkerToDialog;
1171   tp->fromdialog = DialogToTextMarker;
1172   tp->dialogmessage = TextMarkerMessage;
1173   tp->testdialog = NULL;
1174 
1175   tp->change_notify = change_notify;
1176   tp->change_userdata = change_userdata;
1177 
1178   tp->marker_choice = HiddenGroup (p, 4, 0, ChangeTextMarkerChoice);
1179   SetObjectExtra (tp->marker_choice, tp, NULL);
1180   SetGroupSpacing (tp->marker_choice, 10, 10);
1181 
1182   RadioButton (tp->marker_choice, "Text");
1183   tp->marker_text = DialogText (tp->marker_choice, "", 10, ChangeTextMarkerText);
1184   SetObjectExtra (tp->marker_text, tp, NULL);
1185   RadioButton (tp->marker_choice, "Digits");
1186   RadioButton (tp->marker_choice, "Letters");
1187   SetValue (tp->marker_choice, 1);
1188 
1189   return (DialoG) p;
1190 }
1191 
1192 
1193 typedef struct textportiondialog
1194 {
1195   DIALOG_MESSAGE_BLOCK
1196 
1197   GrouP  start_choice;
1198   DialoG start_marker;
1199   GrouP  end_choice;
1200   DialoG end_marker;
1201   ButtoN rem_before;
1202   ButtoN also_rem_before;
1203   ButtoN rem_after;
1204   ButtoN also_rem_after;
1205   ButtoN insensitive;
1206   ButtoN whole_word;
1207 
1208   Boolean inside;
1209 
1210   Nlm_ChangeNotifyProc     change_notify;
1211   Pointer                  change_userdata;
1212 } TextPortionDialogData, PNTR TextPortionDialogPtr;
1213 
1214 
OutsideEnableDisable(TextPortionDialogPtr tp)1215 static void OutsideEnableDisable (TextPortionDialogPtr tp)
1216 {
1217   if (tp == NULL || tp->inside)
1218   {
1219     return;
1220   }
1221   if (GetStatus (tp->rem_before))
1222   {
1223     Enable (tp->start_marker);
1224     Enable (tp->also_rem_before);
1225   }
1226   else
1227   {
1228     Disable (tp->start_marker);
1229     Disable (tp->also_rem_before);
1230   }
1231   if (GetStatus (tp->rem_after))
1232   {
1233     Enable (tp->end_marker);
1234     Enable (tp->also_rem_after);
1235   }
1236   else
1237   {
1238     Disable (tp->end_marker);
1239     Disable (tp->also_rem_after);
1240   }
1241 }
1242 
ResetTextPortionDialog(TextPortionDialogPtr tp)1243 static void ResetTextPortionDialog (TextPortionDialogPtr tp)
1244 {
1245   if (tp == NULL)
1246   {
1247     return;
1248   }
1249   if (tp->inside)
1250   {
1251     SetValue (tp->start_choice, 1);
1252     SetValue (tp->end_choice, 1);
1253   }
1254   else
1255   {
1256     SetStatus (tp->rem_before, FALSE);
1257     SetStatus (tp->also_rem_before, FALSE);
1258     SetStatus (tp->rem_after, FALSE);
1259     SetStatus (tp->also_rem_after, FALSE);
1260   }
1261   PointerToDialog (tp->start_marker, NULL);
1262   PointerToDialog (tp->end_marker, NULL);
1263   SetStatus (tp->insensitive, FALSE);
1264   SetStatus (tp->whole_word, FALSE);
1265   OutsideEnableDisable (tp);
1266 }
1267 
TextPortionToDialog(DialoG d,Pointer data)1268 static void TextPortionToDialog (DialoG d, Pointer data)
1269 {
1270   TextPortionDialogPtr tdlg;
1271   TextPortionPtr       tdata;
1272 
1273   tdlg = (TextPortionDialogPtr) GetObjectExtra (d);
1274   if (tdlg == NULL) {
1275     return;
1276   }
1277   tdata = (TextPortionPtr) data;
1278   ResetTextPortionDialog (tdlg);
1279   if (tdata != NULL) {
1280     if (tdlg->inside) {
1281       if (tdata->include_left) {
1282         SetValue (tdlg->start_choice, 2);
1283       } else {
1284         SetValue (tdlg->start_choice, 1);
1285       }
1286       if (tdata->include_right) {
1287         SetValue (tdlg->end_choice, 2);
1288       } else {
1289         SetValue (tdlg->end_choice, 1);
1290       }
1291     } else {
1292       SetStatus (tdlg->rem_before, !IsTextMarkerEmpty(tdata->left_marker));
1293       SetStatus (tdlg->rem_after, !IsTextMarkerEmpty(tdata->right_marker));
1294       SetStatus (tdlg->also_rem_before, tdata->include_left);
1295       SetStatus (tdlg->also_rem_after, tdata->include_right);
1296     }
1297     PointerToDialog (tdlg->start_marker, tdata->left_marker);
1298     PointerToDialog (tdlg->end_marker, tdata->right_marker);
1299     SetStatus (tdlg->insensitive, !tdata->case_sensitive);
1300     SetStatus (tdlg->whole_word, tdata->whole_word);
1301   }
1302   OutsideEnableDisable (tdlg);
1303 }
1304 
DialogToTextPortion(DialoG d)1305 static Pointer DialogToTextPortion (DialoG d)
1306 {
1307   TextPortionDialogPtr tdlg;
1308   TextPortionPtr       tdata;
1309 
1310   tdlg = (TextPortionDialogPtr) GetObjectExtra (d);
1311   if (tdlg == NULL) {
1312     return NULL;
1313   }
1314 
1315   tdata = TextPortionNew();
1316   if (tdata != NULL) {
1317     if (tdlg->inside) {
1318       if (GetValue (tdlg->start_choice) == 1) {
1319         tdata->include_left = FALSE;
1320       } else {
1321         tdata->include_left = TRUE;
1322       }
1323       tdata->left_marker = DialogToPointer (tdlg->start_marker);
1324 
1325       if (GetValue (tdlg->end_choice) == 1) {
1326         tdata->include_right = FALSE;
1327       } else {
1328         tdata->include_right = TRUE;
1329       }
1330       tdata->right_marker = DialogToPointer (tdlg->end_marker);
1331     } else {
1332       if (GetStatus (tdlg->rem_before)) {
1333         tdata->left_marker = DialogToPointer (tdlg->start_marker);
1334       } else {
1335         tdata->left_marker = NULL;
1336       }
1337       if (GetStatus (tdlg->rem_after)) {
1338         tdata->right_marker = DialogToPointer (tdlg->end_marker);
1339       } else {
1340         tdata->right_marker = NULL;
1341       }
1342 
1343       tdata->include_left = GetStatus (tdlg->also_rem_before);
1344       tdata->include_right = GetStatus (tdlg->also_rem_after);
1345     }
1346 
1347     tdata->case_sensitive = !GetStatus (tdlg->insensitive);
1348     tdata->whole_word = GetStatus (tdlg->whole_word);
1349     tdata->inside = tdlg->inside;
1350   }
1351   return tdata;
1352 }
1353 
TextPortionMessage(DialoG d,Int2 mssg)1354 static void TextPortionMessage (DialoG d, Int2 mssg)
1355 
1356 {
1357   TextPortionDialogPtr tp;
1358 
1359   tp = (TextPortionDialogPtr) GetObjectExtra (d);
1360   if (tp != NULL) {
1361     switch (mssg) {
1362       case VIB_MSG_INIT :
1363         ResetTextPortionDialog (tp);
1364         break;
1365       case VIB_MSG_ENTER :
1366         Select (tp->start_marker);
1367         break;
1368       default :
1369         break;
1370     }
1371   }
1372 }
1373 
ChangeTextPortionGroup(GrouP g)1374 static void ChangeTextPortionGroup (GrouP g)
1375 {
1376   TextPortionDialogPtr tp;
1377 
1378   tp = (TextPortionDialogPtr) GetObjectExtra (g);
1379   if (tp == NULL) return;
1380 
1381   if (tp->change_notify != NULL)
1382   {
1383     (tp->change_notify) (tp->change_userdata);
1384   }
1385 }
1386 
1387 
ChangeTextPortionBtn(ButtoN b)1388 static void ChangeTextPortionBtn (ButtoN b)
1389 {
1390   TextPortionDialogPtr tp;
1391 
1392   tp = (TextPortionDialogPtr) GetObjectExtra (b);
1393   if (tp == NULL) return;
1394   OutsideEnableDisable (tp);
1395 
1396   if (tp->change_notify != NULL)
1397   {
1398     (tp->change_notify) (tp->change_userdata);
1399   }
1400 }
1401 
1402 
TestTextPortionDialog(DialoG d)1403 static ValNodePtr TestTextPortionDialog (DialoG d)
1404 {
1405   TextPortionDialogPtr tp;
1406   ValNodePtr err_list = NULL;
1407 
1408   tp = (TextPortionDialogPtr) GetObjectExtra (d);
1409   if (tp == NULL) return NULL;
1410 
1411   /* don't actually need to fill anything in.  Could want to copy the entire field. */
1412 
1413   return err_list;
1414 }
1415 
1416 
GetTextPortionStartChoiceGroup(DialoG d)1417 static GrouP GetTextPortionStartChoiceGroup (DialoG d)
1418 {
1419   TextPortionDialogPtr dlg;
1420 
1421   dlg = (TextPortionDialogPtr) GetObjectExtra (d);
1422   if (dlg == NULL) {
1423     return NULL;
1424   } else {
1425     return dlg->start_choice;
1426   }
1427 }
1428 
1429 
GetTextPortionEndChoiceGroup(DialoG d)1430 static GrouP GetTextPortionEndChoiceGroup (DialoG d)
1431 {
1432   TextPortionDialogPtr dlg;
1433 
1434   dlg = (TextPortionDialogPtr) GetObjectExtra (d);
1435   if (dlg == NULL) {
1436     return NULL;
1437   } else {
1438     return dlg->end_choice;
1439   }
1440 }
1441 
1442 
TextPortionDialog(GrouP h,Boolean inside,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)1443 NLM_EXTERN DialoG TextPortionDialog (GrouP h, Boolean inside, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
1444 {
1445   TextPortionDialogPtr tp;
1446   GrouP                p, g1, g2;
1447 
1448   tp = (TextPortionDialogPtr) MemNew (sizeof (TextPortionDialogData));
1449   if (tp == NULL)
1450   {
1451     return NULL;
1452   }
1453 
1454   p = HiddenGroup (h, -1, 0, NULL);
1455   SetObjectExtra (p, tp, StdCleanupExtraProc);
1456 
1457   tp->dialog = (DialoG) p;
1458   tp->todialog = TextPortionToDialog;
1459   tp->fromdialog = DialogToTextPortion;
1460   tp->dialogmessage = TextPortionMessage;
1461   tp->testdialog = TestTextPortionDialog;
1462 
1463   tp->change_notify = change_notify;
1464   tp->change_userdata = change_userdata;
1465   tp->inside = inside;
1466 
1467   g1 = HiddenGroup (p, 3, 0, NULL);
1468   SetGroupSpacing (g1, 10, 10);
1469 
1470   if (inside)
1471   {
1472     StaticPrompt (g1, "Between", 0, popupMenuHeight, programFont, 'r');
1473     tp->start_choice = HiddenGroup (g1, 2, 0, ChangeTextPortionGroup);
1474     RadioButton (tp->start_choice, "just after");
1475     RadioButton (tp->start_choice, "starting at");
1476     SetValue (tp->start_choice, 1);
1477     SetObjectExtra (tp->start_choice, tp, NULL);
1478 
1479     tp->start_marker = TextMarkerDialog (g1, tp->change_notify, tp->change_userdata);
1480 
1481     StaticPrompt (g1, "And", 0, popupMenuHeight, programFont, 'r');
1482     tp->end_choice = HiddenGroup (g1, 2, 0, ChangeTextPortionGroup);
1483     RadioButton (tp->end_choice, "up to");
1484     RadioButton (tp->end_choice, "including");
1485     SetValue (tp->end_choice, 1);
1486     SetObjectExtra (tp->end_choice, tp, NULL);
1487 
1488     tp->end_marker = TextMarkerDialog (g1, tp->change_notify, tp->change_userdata);
1489   }
1490   else
1491   {
1492     tp->rem_before = CheckBox (g1, "Before", ChangeTextPortionBtn);
1493     SetObjectExtra (tp->rem_before, tp, NULL);
1494     tp->start_marker = TextMarkerDialog (g1, tp->change_notify, tp->change_userdata);
1495     tp->also_rem_before = CheckBox (g1, "Also Remove Entered Text", ChangeTextPortionBtn);
1496 
1497     tp->rem_after = CheckBox (g1, "After", ChangeTextPortionBtn);
1498     SetObjectExtra (tp->rem_after, tp, NULL);
1499     tp->end_marker = TextMarkerDialog (g1, tp->change_notify, tp->change_userdata);
1500     tp->also_rem_after = CheckBox (g1, "Also Remove Entered Text", ChangeTextPortionBtn);
1501   }
1502 
1503   g2 = HiddenGroup (p, 2, 0, NULL);
1504   tp->insensitive = CheckBox (g2, "Case insensitive", ChangeTextPortionBtn);
1505   SetObjectExtra (tp->insensitive, tp, NULL);
1506   tp->whole_word = CheckBox (g2, "Whole word", ChangeTextPortionBtn);
1507   SetObjectExtra (tp->whole_word, tp, NULL);
1508 
1509   AlignObjects (ALIGN_CENTER, (HANDLE) g1, (HANDLE) g2, NULL);
1510 
1511   ResetTextPortionDialog (tp);
1512   return (DialoG) p;
1513 }
1514 
1515 
1516 typedef struct fieldeditdlg {
1517   DIALOG_MESSAGE_BLOCK
1518   TexT find_txt;
1519   TexT repl_txt;
1520   GrouP location;
1521   ButtoN case_insensitive;
1522   Nlm_ChangeNotifyProc change_notify;
1523   Pointer              change_userdata;
1524 } FieldEditDlgData, PNTR FieldEditDlgPtr;
1525 
1526 
ChangeFieldEditText(TexT t)1527 static void ChangeFieldEditText (TexT t)
1528 {
1529   FieldEditDlgPtr dlg;
1530 
1531   dlg = (FieldEditDlgPtr) GetObjectExtra (t);
1532   if (dlg != NULL && dlg->change_notify != NULL) {
1533     dlg->change_notify (dlg->change_userdata);
1534   }
1535 }
1536 
1537 
ChangeFieldEditGroup(GrouP g)1538 static void ChangeFieldEditGroup (GrouP g)
1539 {
1540   FieldEditDlgPtr dlg;
1541 
1542   dlg = (FieldEditDlgPtr) GetObjectExtra (g);
1543   if (dlg != NULL && dlg->change_notify != NULL) {
1544     dlg->change_notify (dlg->change_userdata);
1545   }
1546 }
1547 
1548 
FieldEditToDialog(DialoG d,Pointer data)1549 static void FieldEditToDialog (DialoG d, Pointer data)
1550 {
1551   FieldEditDlgPtr dlg;
1552   FieldEditPtr edit;
1553 
1554   dlg = (FieldEditDlgPtr) GetObjectExtra (d);
1555 
1556   if (dlg == NULL) return;
1557 
1558   edit = (FieldEditPtr) data;
1559   if (edit == NULL) {
1560     SetTitle (dlg->find_txt, "");
1561     SetTitle (dlg->repl_txt, "");
1562     SetValue (dlg->location, 1);
1563     SetStatus (dlg->case_insensitive, FALSE);
1564   } else {
1565     SetTitle (dlg->find_txt, edit->find_txt);
1566     SetTitle (dlg->repl_txt, edit->repl_txt);
1567     switch (edit->location) {
1568       case Field_edit_location_anywhere:
1569         SetValue (dlg->location, 1);
1570         break;
1571       case Field_edit_location_beginning:
1572         SetValue (dlg->location, 2);
1573         break;
1574       case Field_edit_location_end:
1575         SetValue (dlg->location, 3);
1576         break;
1577       default:
1578         SetValue (dlg->location, 1);
1579         break;
1580     }
1581     SetStatus (dlg->case_insensitive, edit->case_insensitive);
1582   }
1583   if (dlg->change_notify != NULL) {
1584     dlg->change_notify (dlg->change_userdata);
1585   }
1586 }
1587 
1588 
DialogToFieldEdit(DialoG d)1589 static Pointer DialogToFieldEdit (DialoG d)
1590 {
1591   FieldEditDlgPtr dlg;
1592   FieldEditPtr edit;
1593 
1594   dlg = (FieldEditDlgPtr) GetObjectExtra (d);
1595 
1596   if (dlg == NULL) return NULL;
1597 
1598   edit = FieldEditNew ();
1599   edit->find_txt = JustSaveStringFromText (dlg->find_txt);
1600   edit->repl_txt = JustSaveStringFromText (dlg->repl_txt);
1601   if ((edit->find_txt == NULL || edit->find_txt[0] == 0) && (edit->repl_txt == NULL || edit->repl_txt[0] == 0)) {
1602     edit = FieldEditFree (edit);
1603   } else {
1604     switch (GetValue (dlg->location)) {
1605       case 1:
1606         edit->location = Field_edit_location_anywhere;
1607         break;
1608       case 2:
1609         edit->location = Field_edit_location_beginning;
1610         break;
1611       case 3:
1612         edit->location = Field_edit_location_end;
1613         break;
1614       default:
1615         edit->location = Field_edit_location_anywhere;
1616         break;
1617     }
1618     edit->case_insensitive = GetStatus (dlg->case_insensitive);
1619   }
1620   return edit;
1621 }
1622 
1623 
FieldEditDlgCopy(ButtoN b)1624 static void FieldEditDlgCopy (ButtoN b)
1625 {
1626   FieldEditDlgPtr dlg;
1627   CharPtr         str = NULL;
1628 
1629   dlg = (FieldEditDlgPtr) GetObjectExtra (b);
1630   if (dlg == NULL)
1631   {
1632     return;
1633   }
1634   str = JustSaveStringFromText (dlg->find_txt);
1635   SetTitle (dlg->repl_txt, str);
1636   str = MemFree (str);
1637 }
1638 
TestFieldEditDialog(DialoG d)1639 static ValNodePtr TestFieldEditDialog (DialoG d)
1640 {
1641   FieldEditDlgPtr dlg;
1642   ValNodePtr err_list = NULL;
1643   CharPtr tmp;
1644 
1645   dlg = (FieldEditDlgPtr) GetObjectExtra (d);
1646   if (dlg == NULL) {
1647     return NULL;
1648   }
1649 
1650   tmp = JustSaveStringFromText (dlg->find_txt);
1651   if (tmp == NULL || tmp[0] == 0) {
1652     ValNodeAddPointer (&err_list, 0, "no find text");
1653   }
1654   tmp = MemFree (tmp);
1655   return err_list;
1656 }
1657 
1658 
SetFieldEditDialogText(DialoG d,CharPtr str_find,CharPtr str_repl)1659 static void SetFieldEditDialogText (DialoG d, CharPtr str_find, CharPtr str_repl)
1660 {
1661   FieldEditDlgPtr dlg;
1662 
1663   dlg = (FieldEditDlgPtr) GetObjectExtra (d);
1664   if (dlg != NULL) {
1665     if (str_find != NULL) {
1666       SetTitle (dlg->find_txt, str_find);
1667     }
1668     if (str_repl != NULL) {
1669       SetTitle (dlg->repl_txt, str_repl);
1670     }
1671   }
1672 }
1673 
1674 
FieldEditDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)1675 static DialoG FieldEditDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
1676 {
1677   FieldEditDlgPtr dlg;
1678   GrouP p, g;
1679   ButtoN b;
1680 
1681   p = HiddenGroup (h, -1, 0, NULL);
1682   dlg = (FieldEditDlgPtr) MemNew (sizeof (FieldEditDlgData));
1683   SetObjectExtra (p, dlg, StdCleanupExtraProc);
1684   dlg->dialog = (DialoG) p;
1685   dlg->fromdialog = DialogToFieldEdit;
1686   dlg->todialog = FieldEditToDialog;
1687   dlg->testdialog = TestFieldEditDialog;
1688   dlg->change_notify = change_notify;
1689   dlg->change_userdata = change_userdata;
1690 
1691   g = HiddenGroup (p, 3, 0, NULL);
1692   StaticPrompt (g, "Find", 0, dialogTextHeight, systemFont, 'r');
1693   dlg->find_txt = DialogText (g, "", 18, ChangeFieldEditText);
1694   SetObjectExtra (dlg->find_txt, dlg, NULL);
1695   b = PushButton (g, "Copy", FieldEditDlgCopy);
1696   SetObjectExtra (b, dlg, NULL);
1697   Hide (b);
1698   StaticPrompt (g, "Replace", 0, dialogTextHeight, systemFont, 'r');
1699   dlg->repl_txt = DialogText (g, "", 18, ChangeFieldEditText);
1700   SetObjectExtra (dlg->repl_txt, dlg, NULL);
1701   b = PushButton (g, "Copy", FieldEditDlgCopy);
1702   SetObjectExtra (b, dlg, NULL);
1703 
1704   dlg->location = HiddenGroup (p, 3, 0, ChangeFieldEditGroup);
1705   SetObjectExtra (dlg->location, dlg, NULL);
1706   RadioButton (dlg->location, "Anywhere in field");
1707   RadioButton (dlg->location, "At the beginning of the field");
1708   RadioButton (dlg->location, "At the end of the field");
1709   SetValue (dlg->location, 1);
1710 
1711   dlg->case_insensitive = CheckBox (p, "Case-insensitive", NULL);
1712 
1713   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) dlg->location, (HANDLE) dlg->case_insensitive, NULL);
1714 
1715   return (DialoG) p;
1716 }
1717 
1718 
1719 typedef struct existingtextdlg {
1720   DIALOG_MESSAGE_BLOCK
1721   GrouP                action_grp;
1722   ButtoN               append_btn;
1723   ButtoN               prefix_btn;
1724   ButtoN               add_field_btn;
1725   GrouP                delim_grp;
1726   Nlm_ChangeNotifyProc change_notify;
1727   Pointer              change_userdata;
1728 } ExistingTextDlgData, PNTR ExistingTextDlgPtr;
1729 
ChangeExistingTextActionChoice(GrouP g)1730 static void ChangeExistingTextActionChoice (GrouP g)
1731 {
1732   ExistingTextDlgPtr dlg;
1733   Int4               action_choice;
1734 
1735   dlg = (ExistingTextDlgPtr) GetObjectExtra (g);
1736   if (dlg == NULL) return;
1737 
1738   action_choice = GetValue (dlg->action_grp);
1739   if (action_choice == 2 || action_choice == 3) {
1740     Enable (dlg->delim_grp);
1741   } else {
1742     Disable (dlg->delim_grp);
1743   }
1744   if (dlg->change_notify != NULL) {
1745     (dlg->change_notify) (dlg->change_userdata);
1746   }
1747 }
1748 
1749 
SetExistingTextDialogValue(DialoG d,Uint2 existing_text)1750 static void SetExistingTextDialogValue (DialoG d, Uint2 existing_text)
1751 {
1752   ExistingTextDlgPtr dlg;
1753 
1754   dlg = (ExistingTextDlgPtr) GetObjectExtra (d);
1755   if (dlg == NULL) return;
1756   switch (existing_text) {
1757     case ExistingTextOption_append_semi :
1758       SetValue (dlg->action_grp, 2);
1759       SetValue (dlg->delim_grp, 1);
1760       break;
1761     case ExistingTextOption_append_space :
1762       SetValue (dlg->action_grp, 2);
1763       SetValue (dlg->delim_grp, 2);
1764       break;
1765     case ExistingTextOption_append_colon :
1766       SetValue (dlg->action_grp, 2);
1767       SetValue (dlg->delim_grp, 3);
1768       break;
1769     case ExistingTextOption_append_comma :
1770       SetValue (dlg->action_grp, 2);
1771       SetValue (dlg->delim_grp, 4);
1772       break;
1773     case ExistingTextOption_append_none :
1774       SetValue (dlg->action_grp, 2);
1775       SetValue (dlg->delim_grp, 5);
1776       break;
1777     case ExistingTextOption_prefix_semi :
1778       SetValue (dlg->action_grp, 3);
1779       SetValue (dlg->delim_grp, 1);
1780       break;
1781     case ExistingTextOption_prefix_space :
1782       SetValue (dlg->action_grp, 3);
1783       SetValue (dlg->delim_grp, 2);
1784       break;
1785     case ExistingTextOption_prefix_colon :
1786       SetValue (dlg->action_grp, 3);
1787       SetValue (dlg->delim_grp, 3);
1788       break;
1789     case ExistingTextOption_prefix_comma :
1790       SetValue (dlg->action_grp, 3);
1791       SetValue (dlg->delim_grp, 4);
1792       break;
1793     case ExistingTextOption_prefix_none :
1794       SetValue (dlg->action_grp, 3);
1795       SetValue (dlg->delim_grp, 5);
1796       break;
1797     case ExistingTextOption_leave_old :
1798       SetValue (dlg->action_grp, 4);
1799       break;
1800     case ExistingTextOption_add_qual :
1801       SetValue (dlg->action_grp, 5);
1802       break;
1803     case ExistingTextOption_replace_old :
1804       SetValue (dlg->action_grp, 1);
1805       break;
1806     default:
1807       SetValue (dlg->action_grp, 1);
1808       SetValue (dlg->delim_grp, 1);
1809       break;
1810   }
1811   ChangeExistingTextActionChoice (dlg->action_grp);
1812 }
1813 
1814 
ChangeExistingTextDelimChoice(GrouP g)1815 static void ChangeExistingTextDelimChoice (GrouP g)
1816 {
1817   ExistingTextDlgPtr dlg;
1818 
1819   dlg = (ExistingTextDlgPtr) GetObjectExtra (g);
1820   if (dlg == NULL) return;
1821   if (dlg->change_notify != NULL) {
1822     (dlg->change_notify) (dlg->change_userdata);
1823   }
1824 }
1825 
1826 
GetExistingTextDialogValue(DialoG d)1827 static Uint2 GetExistingTextDialogValue (DialoG d)
1828 {
1829   ExistingTextDlgPtr dlg;
1830   Int4 action_choice, separator_choice;
1831   Uint2 existing_text = ExistingTextOption_replace_old;
1832 
1833   dlg = (ExistingTextDlgPtr) GetObjectExtra (d);
1834   if (dlg == NULL) return existing_text;
1835   action_choice = GetValue (dlg->action_grp);
1836   separator_choice = GetValue (dlg->delim_grp);
1837   switch (action_choice) {
1838     case 1:
1839       existing_text = ExistingTextOption_replace_old;
1840       break;
1841     case 2:
1842       switch (separator_choice) {
1843         case 1:
1844           existing_text = ExistingTextOption_append_semi;
1845           break;
1846         case 2:
1847           existing_text = ExistingTextOption_append_space;
1848           break;
1849         case 3:
1850           existing_text = ExistingTextOption_append_colon;
1851           break;
1852         case 4:
1853           existing_text = ExistingTextOption_append_comma;
1854           break;
1855         case 5:
1856           existing_text = ExistingTextOption_append_none;
1857           break;
1858       }
1859       break;
1860     case 3:
1861       switch (separator_choice) {
1862         case 1:
1863           existing_text = ExistingTextOption_prefix_semi;
1864           break;
1865         case 2:
1866           existing_text = ExistingTextOption_prefix_space;
1867           break;
1868         case 3:
1869           existing_text = ExistingTextOption_prefix_colon;
1870           break;
1871         case 4:
1872           existing_text = ExistingTextOption_prefix_comma;
1873           break;
1874         case 5:
1875           existing_text = ExistingTextOption_prefix_none;
1876           break;
1877       }
1878       break;
1879     case 4:
1880       existing_text = ExistingTextOption_leave_old;
1881       break;
1882     case 5:
1883       existing_text = ExistingTextOption_add_qual;
1884       break;
1885   }
1886   return existing_text;
1887 }
1888 
1889 
TestExistingTextDialog(DialoG d)1890 static ValNodePtr TestExistingTextDialog (DialoG d)
1891 {
1892   ExistingTextDlgPtr dlg;
1893   ValNodePtr err_list = NULL;
1894   Int2       val;
1895 
1896   dlg = (ExistingTextDlgPtr) GetObjectExtra (d);
1897   if (dlg == NULL) return NULL;
1898 
1899   val = GetValue (dlg->action_grp);
1900   if ((val == 2 && !Enabled (dlg->append_btn)) || (val == 3 && !Enabled (dlg->prefix_btn))) {
1901     ValNodeAddPointer (&err_list, 0, "invalid existing text option for nontext value");
1902   } else if (val == 5 && !Enabled (dlg->add_field_btn)) {
1903     ValNodeAddPointer (&err_list, 0, "invalid existing text option for field type");
1904   }
1905   return err_list;
1906 }
1907 
1908 
EnableNonTextOptions(DialoG d)1909 static void EnableNonTextOptions (DialoG d)
1910 {
1911   ExistingTextDlgPtr dlg;
1912 
1913   dlg = (ExistingTextDlgPtr) GetObjectExtra (d);
1914   if (dlg == NULL) return;
1915 
1916   Enable (dlg->append_btn);
1917   Enable (dlg->prefix_btn);
1918 }
1919 
1920 
DisableNonTextOptions(DialoG d)1921 static void DisableNonTextOptions (DialoG d)
1922 {
1923   ExistingTextDlgPtr dlg;
1924 
1925   dlg = (ExistingTextDlgPtr) GetObjectExtra (d);
1926   if (dlg == NULL) return;
1927 
1928   Disable (dlg->append_btn);
1929   Disable (dlg->prefix_btn);
1930 }
1931 
1932 
EnableMultiOptions(DialoG d)1933 static void EnableMultiOptions (DialoG d)
1934 {
1935   ExistingTextDlgPtr dlg;
1936 
1937   dlg = (ExistingTextDlgPtr) GetObjectExtra (d);
1938   if (dlg == NULL) return;
1939 
1940   Enable (dlg->add_field_btn);
1941 }
1942 
1943 
DisableMultiOptions(DialoG d)1944 static void DisableMultiOptions (DialoG d)
1945 {
1946   ExistingTextDlgPtr dlg;
1947 
1948   dlg = (ExistingTextDlgPtr) GetObjectExtra (d);
1949   if (dlg == NULL) return;
1950 
1951   Disable (dlg->add_field_btn);
1952 }
1953 
1954 
ExistingTextDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)1955 static DialoG ExistingTextDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
1956 {
1957   ExistingTextDlgPtr dlg;
1958   GrouP              p;
1959   PrompT             ppt;
1960 
1961   dlg = (ExistingTextDlgPtr) MemNew (sizeof (ExistingTextDlgData));
1962   p = HiddenGroup (h, -1, 0, NULL);
1963   SetGroupSpacing (p, 10, 10);
1964   SetObjectExtra (p, dlg, StdCleanupExtraProc);
1965 
1966   dlg->dialog = (DialoG) p;
1967   dlg->testdialog = TestExistingTextDialog;
1968   dlg->change_notify = change_notify;
1969   dlg->change_userdata = change_userdata;
1970 
1971   dlg->action_grp = HiddenGroup (p, 5, 0, ChangeExistingTextActionChoice);
1972   SetGroupSpacing (dlg->action_grp, 10, 10);
1973   SetObjectExtra (dlg->action_grp, dlg, NULL);
1974   RadioButton (dlg->action_grp, "Overwrite existing text");
1975   dlg->append_btn = RadioButton (dlg->action_grp, "Append");
1976   dlg->prefix_btn = RadioButton (dlg->action_grp, "Prefix");
1977   RadioButton (dlg->action_grp, "Ignore new text");
1978   dlg->add_field_btn = RadioButton (dlg->action_grp, "Add new qual");
1979   Disable (dlg->add_field_btn);
1980   SetValue (dlg->action_grp, 1);
1981 
1982   ppt = StaticPrompt (p, "Separate new text and old text with",
1983                       0, dialogTextHeight, programFont, 'c');
1984 
1985   dlg->delim_grp = HiddenGroup (p, 5, 0, ChangeExistingTextDelimChoice);
1986   SetObjectExtra (dlg->delim_grp, dlg, NULL);
1987   SetGroupSpacing (dlg->delim_grp, 10, 10);
1988   RadioButton (dlg->delim_grp, "Semicolon");
1989   RadioButton (dlg->delim_grp, "Space");
1990   RadioButton (dlg->delim_grp, "Colon");
1991   RadioButton (dlg->delim_grp, "Comma");
1992   RadioButton (dlg->delim_grp, "Do not separate");
1993   SetValue (dlg->delim_grp, 1);
1994   Disable (dlg->delim_grp);
1995   return (DialoG) p;
1996 }
1997 
1998 
1999 /* ExistingText handling dialog and structures */
2000 typedef struct existingtexttwostepdlg
2001 {
2002   GrouP pre_app_grp;
2003   GrouP delim_grp;
2004 } ExistingTextTwoStepDlgData, PNTR ExistingTextTwoStepDlgPtr;
2005 
ChangePreAppIgnoreChoice(GrouP g)2006 static void ChangePreAppIgnoreChoice (GrouP g)
2007 {
2008   ExistingTextTwoStepDlgPtr etdp;
2009   Int4               handle_choice;
2010 
2011   etdp = (ExistingTextTwoStepDlgPtr) GetObjectExtra (g);
2012   if (etdp == NULL)
2013   {
2014     return;
2015   }
2016 
2017   handle_choice = GetValue (etdp->pre_app_grp);
2018   if (handle_choice == 1 || handle_choice == 2)
2019   {
2020     Enable (etdp->delim_grp);
2021   }
2022   else
2023   {
2024     Disable (etdp->delim_grp);
2025   }
2026 }
2027 
2028 
TwoStepExistingText(Int4 num_found,Boolean non_text,Boolean allow_multi)2029 NLM_EXTERN Uint2 TwoStepExistingText (Int4 num_found, Boolean non_text, Boolean allow_multi)
2030 {
2031   WindoW                w;
2032   GrouP                 h, c;
2033   Uint2                 existing_text = 0;
2034   ButtoN                b;
2035   ExistingTextTwoStepDlgData   etdd;
2036   ModalAcceptCancelData acd;
2037   Char                  txt [128];
2038   MsgAnswer             ans;
2039   PrompT                ppt;
2040   Int4                  handle_choice;
2041 
2042   if (num_found <= 0)
2043   {
2044     return ExistingTextOption_replace_old;
2045   }
2046 
2047   sprintf (txt, "%d affected fields already contain a value.  Do you wish to overwrite existing text?",
2048            num_found);
2049   ans = Message (MSG_YNC, txt, 0, dialogTextHeight, systemFont, 'l');
2050   if (ans == ANS_CANCEL)
2051   {
2052     return 0;
2053   }
2054   else if (ans == ANS_YES)
2055   {
2056     return ExistingTextOption_replace_old;
2057   }
2058 
2059   w = MovableModalWindow(-20, -13, -10, -10, "How to Add New Text", NULL);
2060   h = HiddenGroup (w, -1, 0, NULL);
2061   SetGroupSpacing (h, 10, 10);
2062   etdd.pre_app_grp = HiddenGroup (h, 0, 4, ChangePreAppIgnoreChoice);
2063   SetGroupSpacing (etdd.pre_app_grp, 10, 10);
2064   RadioButton (etdd.pre_app_grp, "Append");
2065   RadioButton (etdd.pre_app_grp, "Prefix");
2066   RadioButton (etdd.pre_app_grp, "Ignore new text");
2067   if (allow_multi) {
2068     RadioButton (etdd.pre_app_grp, "Add new qual");
2069   }
2070   SetValue (etdd.pre_app_grp, 1);
2071   SetObjectExtra (etdd.pre_app_grp, &etdd, NULL);
2072 
2073   ppt = StaticPrompt (h, "Separate new text and old text with",
2074                       0, dialogTextHeight, programFont, 'c');
2075   etdd.delim_grp = HiddenGroup (h, 0, 5, NULL);
2076   SetGroupSpacing (etdd.delim_grp, 10, 10);
2077   RadioButton (etdd.delim_grp, "Semicolon");
2078   RadioButton (etdd.delim_grp, "Space");
2079   RadioButton (etdd.delim_grp, "Colon");
2080   RadioButton (etdd.delim_grp, "Comma");
2081   RadioButton (etdd.delim_grp, "Do not separate");
2082   SetValue (etdd.delim_grp, 1);
2083 
2084   c = HiddenGroup (h, 2, 0, NULL);
2085   SetGroupSpacing (c, 10, 10);
2086   b = PushButton (c, "Accept", ModalAcceptButton);
2087   SetObjectExtra (b, &acd, NULL);
2088   b = PushButton (c, "Cancel", ModalCancelButton);
2089   SetObjectExtra (b, &acd, NULL);
2090   AlignObjects (ALIGN_CENTER, (HANDLE) etdd.pre_app_grp,
2091                               (HANDLE) ppt,
2092                               (HANDLE) etdd.delim_grp,
2093                               (HANDLE) c,
2094                               NULL);
2095   Show (w);
2096   Select (w);
2097   acd.accepted = FALSE;
2098   acd.cancelled = FALSE;
2099   while (!acd.accepted && ! acd.cancelled)
2100   {
2101     ProcessExternalEvent ();
2102     Update ();
2103   }
2104   ProcessAnEvent ();
2105   if (acd.cancelled)
2106   {
2107     existing_text = 0;
2108   }
2109   else
2110   {
2111     handle_choice = GetValue (etdd.pre_app_grp);
2112     if (handle_choice == 1)
2113     {
2114       switch (GetValue (etdd.delim_grp))
2115       {
2116         case 1:
2117           existing_text = ExistingTextOption_append_semi;
2118           break;
2119         case 2:
2120           existing_text = ExistingTextOption_append_space;
2121           break;
2122         case 3:
2123           existing_text = ExistingTextOption_append_colon;
2124           break;
2125         case 4:
2126           existing_text = ExistingTextOption_append_comma;
2127           break;
2128         case 5:
2129           existing_text = ExistingTextOption_append_none;
2130           break;
2131       }
2132     }
2133     else if (handle_choice == 2)
2134     {
2135       switch (GetValue (etdd.delim_grp))
2136       {
2137         case 1:
2138           existing_text = ExistingTextOption_prefix_semi;
2139           break;
2140         case 2:
2141           existing_text = ExistingTextOption_prefix_space;
2142           break;
2143         case 3:
2144           existing_text = ExistingTextOption_prefix_colon;
2145           break;
2146         case 4:
2147           existing_text = ExistingTextOption_prefix_comma;
2148           break;
2149         case 5:
2150           existing_text = ExistingTextOption_prefix_none;
2151           break;
2152       }
2153     }
2154     else if (handle_choice == 4)
2155     {
2156       existing_text = ExistingTextOption_add_qual;
2157     }
2158     else
2159     {
2160       existing_text = ExistingTextOption_leave_old;
2161     }
2162   }
2163   Remove (w);
2164   return existing_text;
2165 }
2166 
2167 
WordSubstitutionIsEmpty(WordSubstitutionPtr word)2168 static Boolean WordSubstitutionIsEmpty (WordSubstitutionPtr word)
2169 {
2170   ValNodePtr vnp;
2171   Boolean rval = FALSE;
2172 
2173   if (word == NULL) {
2174     rval = TRUE;
2175   } else if (word->word == NULL || word->word[0] == 0) {
2176     rval = TRUE;
2177     for (vnp = word->synonyms; vnp != NULL && rval; vnp = vnp->next) {
2178       if (vnp->data.ptrvalue != NULL || ((CharPtr)vnp->data.ptrvalue)[0] != 0) {
2179         rval = FALSE;
2180       }
2181     }
2182   } else {
2183     rval = FALSE;
2184   }
2185   return rval;
2186 }
2187 
2188 
2189 typedef struct editwordsubstitution {
2190   TexT  word;
2191   DialoG synonyms;
2192   ButtoN case_insensitive;
2193   ButtoN whole_word;
2194 
2195   ButtoN accept_btn;
2196 } EditWordSubstitutionData, PNTR EditWordSubstitutionPtr;
2197 
2198 
EditWordSubstitution(WordSubstitutionPtr word)2199 static Boolean EditWordSubstitution (WordSubstitutionPtr word)
2200 {
2201   ModalAcceptCancelData acd;
2202   EditWordSubstitutionData    ecd;
2203   Boolean               rval = FALSE;
2204   WindoW                w;
2205   ButtoN                b;
2206   GrouP                 h, g1, g2, c;
2207 
2208   if (word == NULL) return FALSE;
2209 
2210   w = MovableModalWindow(-20, -13, -10, -10, "Word Substitution", NULL);
2211   h = HiddenGroup (w, -1, 0, NULL);
2212   SetGroupSpacing (h, 10, 10);
2213 
2214   g1 = HiddenGroup (h, 2, 0, NULL);
2215   StaticPrompt (g1, "Pattern Word", 0, dialogTextHeight, programFont, 'c');
2216   ecd.word = DialogText (g1, "", 15, NULL);
2217 
2218   ecd.synonyms = CreateVisibleStringDialog (h, 3, -1, 25);
2219 
2220   g2 = HiddenGroup (h, 2, 0, NULL);
2221   ecd.case_insensitive = CheckBox (g2, "Case insensitive", NULL);
2222   ecd.whole_word = CheckBox (g2, "Whole Word", NULL);
2223 
2224   c = HiddenGroup (h, 2, 0, NULL);
2225   SetGroupSpacing (c, 10, 10);
2226   ecd.accept_btn = PushButton (c, "Accept", ModalAcceptButton);
2227   SetObjectExtra (ecd.accept_btn, &acd, NULL);
2228   b = PushButton (c, "Cancel", ModalCancelButton);
2229   SetObjectExtra (b, &acd, NULL);
2230   AlignObjects (ALIGN_CENTER, (HANDLE) ecd.word,
2231                               (HANDLE) g1,
2232                               (HANDLE) ecd.synonyms,
2233                               (HANDLE) g2,
2234                               (HANDLE) c,
2235                               NULL);
2236 
2237   if (word->word != NULL) {
2238     SetTitle (ecd.word, word->word);
2239   }
2240   if (word->synonyms != NULL) {
2241     PointerToDialog (ecd.synonyms, word->synonyms);
2242   }
2243   SetStatus (ecd.case_insensitive, !word->case_sensitive);
2244   SetStatus (ecd.whole_word, word->whole_word);
2245 
2246   Show (w);
2247   Select (w);
2248   acd.accepted = FALSE;
2249   acd.cancelled = FALSE;
2250   while (!acd.accepted && ! acd.cancelled)
2251   {
2252     ProcessExternalEvent ();
2253     Update ();
2254   }
2255   ProcessAnEvent ();
2256   if (!acd.cancelled)
2257   {
2258     word->word = MemFree (word->word);
2259     word->word = JustSaveStringFromText (ecd.word);
2260     word->synonyms = ValNodeFreeData (word->synonyms);
2261     word->synonyms = DialogToPointer (ecd.synonyms);
2262     word->case_sensitive = !GetStatus (ecd.case_insensitive);
2263     word->whole_word = GetStatus (ecd.whole_word);
2264 
2265     rval = TRUE;
2266   }
2267   Remove (w);
2268   return rval;
2269 }
2270 
2271 
2272 typedef struct wordsubstitutionsetdlg {
2273   DIALOG_MESSAGE_BLOCK
2274   DoC                     word_doc;
2275   WordSubstitutionSetPtr  word_list;
2276 
2277   Nlm_ChangeNotifyProc change_notify;
2278   Pointer              change_userdata;
2279 } WordSubstitutionSetDlgData, PNTR WordSubstitutionSetDlgPtr;
2280 
PopulateWordSubstitutionDoc(DoC d,WordSubstitutionSetPtr word_list)2281 static void PopulateWordSubstitutionDoc (DoC d, WordSubstitutionSetPtr word_list)
2282 {
2283   WordSubstitutionPtr word;
2284   CharPtr    phrase, tmp;
2285   RecT       r;
2286   ParData    ParFmt = {FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0};
2287   ColData    ColFmt[] =
2288   {
2289     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
2290     {0, 0, 80, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, TRUE}
2291   };
2292 
2293   if (d == NULL) return;
2294 
2295   Reset (d);
2296 
2297   ObjectRect (d, &r);
2298   InsetRect (&r, 4, 4);
2299 
2300   ColFmt[1].pixWidth = r.right - r.left - 12;
2301 
2302   Reset (d);
2303 
2304   for (word = word_list; word != NULL; word = word->next) {
2305     phrase = SummarizeWordSubstitution (word);
2306     if (phrase == NULL) {
2307       AppendText (d, "\tUnable to summarize word substitution\n", &ParFmt, ColFmt, programFont);
2308     } else {
2309       tmp = (CharPtr) MemNew (sizeof (Char) * (StringLen (phrase) + 3));
2310       sprintf (tmp, "\t%s\n", phrase);
2311       phrase = MemFree (phrase);
2312       AppendText (d, tmp, &ParFmt, ColFmt, programFont);
2313       tmp = MemFree (tmp);
2314     }
2315   }
2316   AppendText (d, "(Click here to add new word substitution)", NULL, NULL, programFont);
2317   UpdateDocument (d, 0, 0);
2318 }
2319 
2320 
WordSubstitutionSetLen(WordSubstitutionSetPtr word)2321 static Int4 WordSubstitutionSetLen (WordSubstitutionSetPtr word)
2322 {
2323   Int4 num_words = 0;
2324 
2325   while (word != NULL) {
2326     num_words++;
2327     word = word->next;
2328   }
2329   return num_words;
2330 }
2331 
2332 
DrawWordSubstitutionDocControls(DoC d,RectPtr r,Int2 item,Int2 firstLine)2333 static void DrawWordSubstitutionDocControls (DoC d, RectPtr r, Int2 item, Int2 firstLine)
2334 
2335 {
2336   RecT                rct;
2337   Int4                width;
2338   PoinT               pt1, pt2;
2339   WordSubstitutionSetDlgPtr dlg;
2340 
2341   dlg = (WordSubstitutionSetDlgPtr) GetObjectExtra (d);
2342   if (dlg != NULL && r != NULL && item > 0 && firstLine == 0 && item <= WordSubstitutionSetLen (dlg->word_list)) {
2343     rct = *r;
2344 
2345     /* draw X for deletion */
2346     width = 10;
2347     pt1.x = rct.left + 1;
2348     pt1.y = rct.top + 1;
2349     pt2.x = pt1.x + width;
2350     pt2.y = pt1.y + width;
2351     DrawLine (pt1, pt2);
2352     pt1.x = rct.left + 1;
2353     pt1.y = rct.top + 1 + width;
2354     pt2.x = pt1.x + width;
2355     pt2.y = rct.top + 1;
2356     DrawLine (pt1, pt2);
2357   }
2358 }
2359 
2360 
ClickWordSubstitutionDoc(DoC d,PoinT pt)2361 static void ClickWordSubstitutionDoc (DoC d, PoinT pt)
2362 {
2363   Int2      item, row, col;
2364   RecT      rct;
2365   BaR       sb_vert;
2366   Int4      scroll_pos = 0, scroll_max;
2367   WordSubstitutionSetDlgPtr f;
2368   WordSubstitutionPtr word, word_prev = NULL;
2369   Boolean             changed = FALSE;
2370 
2371   f = (WordSubstitutionSetDlgPtr) GetObjectExtra (d);
2372   if (f == NULL) return;
2373 
2374   MapDocPoint (d, pt, &item, &row, &col, &rct);
2375   if (item == 0 && row == 0 && f->word_list == NULL) {
2376     /* create new constraint */
2377     word = WordSubstitutionNew();
2378     if (EditWordSubstitution (word) && !WordSubstitutionIsEmpty(word)) {
2379       f->word_list = word;
2380       changed = TRUE;
2381     } else {
2382       word = WordSubstitutionFree (word);
2383     }
2384   } else if (item > 0 && row > 0) {
2385     if (item == WordSubstitutionSetLen(f->word_list) + 1) {
2386       /* create new constraint */
2387       word = WordSubstitutionNew();
2388       if (EditWordSubstitution (word) && !WordSubstitutionIsEmpty(word)) {
2389         if (f->word_list == NULL) {
2390           f->word_list = word;
2391         } else {
2392           word_prev = f->word_list;
2393           while (word_prev->next != NULL) {
2394             word_prev = word_prev->next;
2395           }
2396           word_prev->next = word;
2397         }
2398         changed = TRUE;
2399       } else {
2400         word = WordSubstitutionFree (word);
2401       }
2402     } else {
2403       for (word = f->word_list; word != NULL && item > 1; word = word->next, item--) {
2404         word_prev = word;
2405       }
2406       if (word != NULL) {
2407         sb_vert = GetSlateVScrollBar ((SlatE) f->word_doc);
2408         scroll_pos = GetBarValue (sb_vert);
2409         switch (col) {
2410           case 1:
2411             /* delete this item */
2412             if (word_prev == NULL) {
2413               f->word_list = word->next;
2414             } else {
2415               word_prev->next = word->next;
2416             }
2417             word->next = NULL;
2418             word = WordSubstitutionFree (word);
2419             changed = TRUE;
2420             break;
2421           case 2:
2422             /* edit */
2423             if (EditWordSubstitution (word)) {
2424               if (WordSubstitutionIsEmpty(word)) {
2425                 if (word_prev == NULL) {
2426                   f->word_list = word->next;
2427                 } else {
2428                   word_prev->next = word->next;
2429                 }
2430                 word->next = NULL;
2431                 word = WordSubstitutionFree (word);
2432               }
2433               changed = TRUE;
2434             }
2435             break;
2436         }
2437       }
2438     }
2439   }
2440   if (changed) {
2441     PopulateWordSubstitutionDoc (f->word_doc, f->word_list);
2442     if (scroll_pos > 0) {
2443       sb_vert = GetSlateVScrollBar ((SlatE) f->word_doc);
2444       scroll_max = GetBarMax (sb_vert);
2445       if (scroll_pos > scroll_max) {
2446         scroll_pos = scroll_max;
2447       }
2448       CorrectBarValue (sb_vert, scroll_pos);
2449     }
2450     if (f->change_notify != NULL) {
2451       (f->change_notify) (f->change_userdata);
2452     }
2453   }
2454 }
2455 
WordSubstitutionSetToDialog(DialoG d,Pointer data)2456 static void WordSubstitutionSetToDialog (DialoG d, Pointer data)
2457 {
2458   WordSubstitutionSetDlgPtr dlg;
2459 
2460   dlg = (WordSubstitutionSetDlgPtr) GetObjectExtra (d);
2461   if (dlg == NULL) return;
2462 
2463   dlg->word_list = WordSubstitutionSetFree (dlg->word_list);
2464   if (data != NULL) {
2465     dlg->word_list = AsnIoMemCopy ((WordSubstitutionSetPtr) data,
2466                                          (AsnReadFunc) WordSubstitutionSetAsnRead,
2467                                          (AsnWriteFunc) WordSubstitutionSetAsnWrite);
2468   }
2469   PopulateWordSubstitutionDoc (dlg->word_doc, dlg->word_list);
2470   if (dlg->change_notify != NULL) {
2471     (dlg->change_notify) (dlg->change_userdata);
2472   }
2473 }
2474 
2475 
WordSubstitutionSetFromDialog(DialoG d)2476 static Pointer WordSubstitutionSetFromDialog (DialoG d)
2477 {
2478   WordSubstitutionSetDlgPtr dlg;
2479   WordSubstitutionSetPtr word_list = NULL;
2480 
2481   dlg = (WordSubstitutionSetDlgPtr) GetObjectExtra (d);
2482   if (dlg == NULL) return NULL;
2483 
2484   if (dlg->word_list != NULL) {
2485     word_list = AsnIoMemCopy ((WordSubstitutionSetPtr) dlg->word_list,
2486                                     (AsnReadFunc) WordSubstitutionSetAsnRead,
2487                                     (AsnWriteFunc) WordSubstitutionSetAsnWrite);
2488   }
2489   return (Pointer) word_list;
2490 }
2491 
CleanupWordSubstitutionSetDialog(GraphiC g,VoidPtr data)2492 static void CleanupWordSubstitutionSetDialog (GraphiC g, VoidPtr data)
2493 
2494 {
2495   WordSubstitutionSetDlgPtr dlg;
2496 
2497   dlg = (WordSubstitutionSetDlgPtr) data;
2498   if (dlg != NULL) {
2499     dlg->word_list = WordSubstitutionSetFree(dlg->word_list);
2500   }
2501   StdCleanupExtraProc (g, data);
2502 }
2503 
2504 
AddWordSubstitutionBtn(ButtoN b)2505 static void AddWordSubstitutionBtn (ButtoN b)
2506 {
2507   WordSubstitutionSetDlgPtr dlg;
2508   WordSubstitutionPtr       word, prev_word;
2509   BaR       sb_vert;
2510   Int4      scroll_pos = 0, scroll_max;
2511 
2512   dlg = (WordSubstitutionSetDlgPtr) GetObjectExtra (b);
2513   if (dlg == NULL) {
2514     return;
2515   }
2516 
2517   sb_vert = GetSlateVScrollBar ((SlatE) dlg->word_doc);
2518   scroll_pos = GetBarValue (sb_vert);
2519 
2520   /* create new WordSubstitution */
2521   word = WordSubstitutionNew ();
2522   if (EditWordSubstitution (word) && !WordSubstitutionIsEmpty(word)) {
2523     if (dlg->word_list == NULL) {
2524       dlg->word_list = word;
2525     } else {
2526       prev_word = dlg->word_list;
2527       while (prev_word->next != NULL) {
2528         prev_word = prev_word->next;
2529       }
2530       prev_word->next = word;
2531     }
2532     PopulateWordSubstitutionDoc (dlg->word_doc, dlg->word_list);
2533     if (scroll_pos > 0) {
2534       sb_vert = GetSlateVScrollBar ((SlatE) dlg->word_doc);
2535       scroll_max = GetBarMax (sb_vert);
2536       if (scroll_pos > scroll_max) {
2537         scroll_pos = scroll_max;
2538       }
2539       CorrectBarValue (sb_vert, scroll_pos);
2540     }
2541     if (dlg->change_notify != NULL) {
2542       (dlg->change_notify) (dlg->change_userdata);
2543     }
2544   } else {
2545     word = WordSubstitutionFree (word);
2546   }
2547 
2548 }
2549 
2550 
WordSubstitutionSetDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)2551 NLM_EXTERN DialoG WordSubstitutionSetDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
2552 {
2553   WordSubstitutionSetDlgPtr dlg;
2554   GrouP               p, g;
2555   ButtoN              b;
2556 
2557   p = HiddenGroup (h, -1, 0, NULL);
2558   SetGroupSpacing (p, 10, 10);
2559   dlg = (WordSubstitutionSetDlgPtr) MemNew (sizeof ( WordSubstitutionSetDlgData));
2560   SetObjectExtra (p, dlg, CleanupWordSubstitutionSetDialog);
2561 
2562   dlg->dialog = (DialoG) p;
2563   dlg->todialog = WordSubstitutionSetToDialog;
2564   dlg->fromdialog = WordSubstitutionSetFromDialog;
2565   dlg->change_notify = change_notify;
2566   dlg->change_userdata = change_userdata;
2567 
2568   dlg->word_list = NULL;
2569   dlg->word_doc = DocumentPanel (p, stdCharWidth * 30, stdLineHeight * 3);
2570   SetObjectExtra (dlg->word_doc, dlg, NULL);
2571   SetDocProcs (dlg->word_doc, ClickWordSubstitutionDoc, NULL, NULL, NULL);
2572   SetDocShade (dlg->word_doc, DrawWordSubstitutionDocControls, NULL, NULL, NULL);
2573   PopulateWordSubstitutionDoc (dlg->word_doc, dlg->word_list);
2574 
2575   g = HiddenGroup (p, 2, 0, NULL);
2576   b = PushButton (g, "Add Word Substitution", AddWordSubstitutionBtn);
2577   SetObjectExtra (b, dlg, NULL);
2578   b = PushButton (g, "Clear Word Substitutions", ClearDialogBtn);
2579   SetObjectExtra (b, p, NULL);
2580 
2581   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->word_doc, (HANDLE) g, NULL);
2582 
2583   return (DialoG) p;
2584 }
2585 
2586 
2587 typedef struct stringconstraintdialog
2588 {
2589   DIALOG_MESSAGE_BLOCK
2590   DialoG tbs;
2591   GrouP  tab_pages[2];
2592   PopuP  match_choice;
2593   TexT   match_text;
2594   ButtoN insensitive;
2595   ButtoN whole_word;
2596   ButtoN ignore_space;
2597   ButtoN ignore_punct;
2598   ButtoN ignore_weasel;
2599   DialoG ignore_words;
2600   ButtoN is_all_caps;
2601   ButtoN is_all_lower;
2602   ButtoN is_all_punct;
2603 
2604   Int2   current_page;
2605   Nlm_ChangeNotifyProc change_notify;
2606   Pointer change_userdata;
2607 } StringConstraintDialogData, PNTR StringConstraintDialogPtr;
2608 
ResetStringConstraintDialog(StringConstraintDialogPtr scdp)2609 static void ResetStringConstraintDialog (StringConstraintDialogPtr scdp)
2610 {
2611   if (scdp == NULL) return;
2612 
2613   SetValue (scdp->match_choice, 1);
2614   SetTitle (scdp->match_text, "");
2615   SetStatus (scdp->insensitive, FALSE);
2616   SetStatus (scdp->whole_word, FALSE);
2617   SetStatus (scdp->ignore_space, FALSE);
2618   SetStatus (scdp->ignore_punct, FALSE);
2619   SetStatus (scdp->ignore_weasel, FALSE);
2620   SetStatus (scdp->is_all_caps, FALSE);
2621   SetStatus (scdp->is_all_lower, FALSE);
2622   SetStatus (scdp->is_all_punct, FALSE);
2623   PointerToDialog (scdp->ignore_words, NULL);
2624 }
2625 
2626 
ClearStringConstraintDialogText(DialoG d)2627 static void ClearStringConstraintDialogText (DialoG d)
2628 {
2629   StringConstraintDialogPtr dlg;
2630 
2631   dlg = (StringConstraintDialogPtr) GetObjectExtra (d);
2632   if (dlg != NULL) {
2633     SetTitle (dlg->match_text, "");
2634     PointerToDialog (dlg->ignore_words, NULL);
2635   }
2636 }
2637 
2638 
GetPopupPosForStringConstraint(StringConstraintPtr scp)2639 static Int4 GetPopupPosForStringConstraint (StringConstraintPtr scp)
2640 {
2641   Int4 rval = 1;
2642 
2643   if (scp == NULL) return 1;
2644 
2645   switch (scp->match_location)
2646   {
2647     case String_location_contains:
2648       if (scp->not_present)
2649       {
2650         rval = 2;
2651       } else {
2652         rval = 1;
2653       }
2654       break;
2655     case String_location_equals:
2656       if (scp->not_present) {
2657         rval = 4;
2658       } else {
2659         rval = 3;
2660       }
2661       break;
2662     case String_location_starts:
2663       if (scp->not_present) {
2664         rval = 9;
2665       } else {
2666         rval = 5;
2667       }
2668       break;
2669     case String_location_ends:
2670       if (scp->not_present) {
2671         rval = 10;
2672       } else {
2673         rval = 6;
2674       }
2675       break;
2676     case String_location_inlist:
2677       if (scp->not_present) {
2678         rval = 8;
2679       } else {
2680         rval = 7;
2681       }
2682       break;
2683   }
2684   return rval;
2685 }
2686 
2687 
StringConstraintToDialog(DialoG d,Pointer data)2688 static void StringConstraintToDialog (DialoG d, Pointer data)
2689 
2690 {
2691   StringConstraintDialogPtr scdp;
2692   StringConstraintPtr       scp;
2693 
2694   scdp = (StringConstraintDialogPtr) GetObjectExtra (d);
2695   scp = (StringConstraintPtr) data;
2696   if (scdp == NULL)
2697   {
2698     return;
2699   }
2700 
2701   if (scp == NULL)
2702   {
2703     ResetStringConstraintDialog (scdp);
2704   }
2705   else
2706   {
2707     SetValue (scdp->match_choice, GetPopupPosForStringConstraint (scp));
2708 
2709     if (scp->match_text == NULL)
2710     {
2711       SetTitle (scdp->match_text, "");
2712     }
2713     else
2714     {
2715       SetTitle (scdp->match_text, scp->match_text);
2716     }
2717 
2718     SetStatus (scdp->insensitive, !scp->case_sensitive);
2719     SetStatus (scdp->whole_word, scp->whole_word);
2720     SetStatus (scdp->ignore_space, scp->ignore_space);
2721     SetStatus (scdp->ignore_punct, scp->ignore_punct);
2722     SetStatus (scdp->ignore_weasel, scp->ignore_weasel);
2723     SetStatus (scdp->is_all_caps, scp->is_all_caps);
2724     SetStatus (scdp->is_all_lower, scp->is_all_lower);
2725     SetStatus (scdp->is_all_punct, scp->is_all_punct);
2726     PointerToDialog (scdp->ignore_words, scp->ignore_words);
2727   }
2728   if (scdp->change_notify != NULL) {
2729     (scdp->change_notify) (scdp->change_userdata);
2730   }
2731 }
2732 
DialogToStringConstraint(DialoG d)2733 static Pointer DialogToStringConstraint (DialoG d)
2734 
2735 {
2736   StringConstraintDialogPtr scdp;
2737   StringConstraintPtr       scp;
2738   Int4                      match_choice;
2739 
2740   scdp = (StringConstraintDialogPtr) GetObjectExtra (d);
2741   if (scdp == NULL)
2742   {
2743     return NULL;
2744   }
2745   scp = StringConstraintNew();
2746   if (scp != NULL)
2747   {
2748     scp->match_text = JustSaveStringFromText (scdp->match_text);
2749     scp->case_sensitive = !GetStatus (scdp->insensitive);
2750     scp->whole_word = GetStatus (scdp->whole_word);
2751     scp->ignore_space = GetStatus (scdp->ignore_space);
2752     scp->ignore_punct = GetStatus (scdp->ignore_punct);
2753     scp->is_all_caps = GetStatus (scdp->is_all_caps);
2754     scp->is_all_lower = GetStatus (scdp->is_all_lower);
2755     scp->is_all_punct = GetStatus (scdp->is_all_punct);
2756     scp->ignore_weasel = GetStatus (scdp->ignore_weasel);
2757     scp->ignore_words = DialogToPointer (scdp->ignore_words);
2758     match_choice = GetValue (scdp->match_choice);
2759     switch (match_choice)
2760     {
2761       case 1:
2762         scp->match_location = String_location_contains;
2763         scp->not_present = FALSE;
2764         break;
2765       case 2:
2766         scp->match_location = String_location_contains;
2767         scp->not_present = TRUE;
2768         break;
2769       case 3:
2770         scp->match_location = String_location_equals;
2771         scp->not_present = FALSE;
2772         break;
2773       case 4:
2774         scp->match_location = String_location_equals;
2775         scp->not_present = TRUE;
2776         break;
2777       case 5:
2778         scp->match_location = String_location_starts;
2779         scp->not_present = FALSE;
2780         break;
2781       case 6:
2782         scp->match_location = String_location_ends;
2783         scp->not_present = FALSE;
2784         break;
2785       case 7:
2786         scp->match_location = String_location_inlist;
2787         scp->not_present = FALSE;
2788         break;
2789       case 8:
2790         scp->match_location = String_location_inlist;
2791         scp->not_present = TRUE;
2792         break;
2793       case 9:
2794         scp->match_location = String_location_starts;
2795         scp->not_present = TRUE;
2796         break;
2797       case 10:
2798         scp->match_location = String_location_ends;
2799         scp->not_present = TRUE;
2800         break;
2801       default:
2802         scp->match_location = String_location_contains;
2803         scp->not_present = FALSE;
2804         break;
2805     }
2806   }
2807   return scp;
2808 }
2809 
StringConstraintMessage(DialoG d,Int2 mssg)2810 static void StringConstraintMessage (DialoG d, Int2 mssg)
2811 
2812 {
2813   StringConstraintDialogPtr scdp;
2814 
2815   scdp = (StringConstraintDialogPtr) GetObjectExtra (d);
2816   if (scdp != NULL) {
2817     switch (mssg) {
2818       case VIB_MSG_INIT :
2819         ResetStringConstraintDialog (scdp);
2820         break;
2821       case VIB_MSG_ENTER :
2822         Select (scdp->match_text);
2823         break;
2824       default :
2825         break;
2826     }
2827   }
2828 }
2829 
2830 
ChangeStringConstraintDialogText(TexT t)2831 static void ChangeStringConstraintDialogText (TexT t)
2832 {
2833   StringConstraintDialogPtr dlg;
2834 
2835   dlg = (StringConstraintDialogPtr) GetObjectExtra (t);
2836   if (dlg != NULL && dlg->change_notify != NULL) {
2837     (dlg->change_notify) (dlg->change_userdata);
2838   }
2839 }
2840 
2841 
ChangeStringConstraintDialogBtn(ButtoN b)2842 static void ChangeStringConstraintDialogBtn (ButtoN b)
2843 {
2844   StringConstraintDialogPtr dlg;
2845 
2846   dlg = (StringConstraintDialogPtr) GetObjectExtra (b);
2847   if (dlg == NULL) {
2848     return;
2849   }
2850 
2851   if (b == dlg->is_all_caps) {
2852     if (GetStatus (dlg->is_all_caps)) {
2853       SetStatus (dlg->is_all_lower, FALSE);
2854       SetStatus (dlg->is_all_punct, FALSE);
2855     }
2856   }
2857   if (b == dlg->is_all_lower) {
2858     if (GetStatus (dlg->is_all_lower)) {
2859       SetStatus (dlg->is_all_caps, FALSE);
2860       SetStatus (dlg->is_all_punct, FALSE);
2861     }
2862   }
2863   if (b == dlg->is_all_punct) {
2864     if (GetStatus (dlg->is_all_punct)) {
2865       SetStatus (dlg->is_all_caps, FALSE);
2866       SetStatus (dlg->is_all_lower, FALSE);
2867     }
2868   }
2869 
2870   if (dlg->change_notify != NULL) {
2871     (dlg->change_notify) (dlg->change_userdata);
2872   }
2873 }
2874 
2875 
TestStringConstraintDialog(DialoG d)2876 static ValNodePtr TestStringConstraintDialog (DialoG d)
2877 
2878 {
2879   ValNodePtr err_list = NULL;
2880   StringConstraintDialogPtr dlg;
2881 
2882   dlg = (StringConstraintDialogPtr) GetObjectExtra (d);
2883   if (dlg != NULL) {
2884   }
2885   return err_list;
2886 }
2887 
2888 
2889 static CharPtr  sStringConstraintTabs [] = {
2890   "String", "Word Substitution List", NULL
2891 };
2892 
2893 
ChangeStringConstraintPage(VoidPtr data,Int2 newval,Int2 oldval)2894 static void ChangeStringConstraintPage (VoidPtr data, Int2 newval, Int2 oldval)
2895 
2896 {
2897   StringConstraintDialogPtr  dlg;
2898 
2899   dlg = (StringConstraintDialogPtr) data;
2900   if (dlg == NULL) {
2901     return;
2902   }
2903   dlg->current_page = newval;
2904   switch (dlg->current_page) {
2905     case 0:
2906       Show (dlg->tab_pages[0]);
2907       Hide (dlg->tab_pages[1]);
2908       break;
2909     case 1:
2910       Show (dlg->tab_pages[1]);
2911       Hide (dlg->tab_pages[0]);
2912       break;
2913   }
2914 
2915     Update ();
2916 }
2917 
2918 
StringConstraintDialog(GrouP h,CharPtr label,Boolean clear_btn,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)2919 NLM_EXTERN DialoG StringConstraintDialog (GrouP h, CharPtr label, Boolean clear_btn, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
2920 
2921 {
2922   StringConstraintDialogPtr scdp;
2923   GrouP                     p, tab_grp, g, k, special_grp, special_grp2;
2924   ButtoN                    b = NULL;
2925 
2926   scdp = (StringConstraintDialogPtr) MemNew (sizeof (StringConstraintDialogData));
2927   if (scdp == NULL)
2928   {
2929     return NULL;
2930   }
2931 
2932   p = HiddenGroup (h, -1, 0, NULL);
2933   SetObjectExtra (p, scdp, StdCleanupExtraProc);
2934 
2935   scdp->dialog = (DialoG) p;
2936   scdp->todialog = StringConstraintToDialog;
2937   scdp->fromdialog = DialogToStringConstraint;
2938   scdp->dialogmessage = StringConstraintMessage;
2939   scdp->testdialog = TestStringConstraintDialog;
2940   scdp->change_notify = change_notify;
2941   scdp->change_userdata = change_userdata;
2942 
2943   scdp->tbs = CreateFolderTabs (p, sStringConstraintTabs, 0,
2944                                   0, 0, SYSTEM_FOLDER_TAB,
2945                                   ChangeStringConstraintPage, (Pointer) scdp);
2946   scdp->current_page = 0;
2947   tab_grp = HiddenGroup (p, 0, 0, NULL);
2948   scdp->tab_pages[0] = HiddenGroup (tab_grp, -1, 0, NULL);
2949   g = HiddenGroup (scdp->tab_pages[0], 3, 0, NULL);
2950   SetGroupSpacing (g, 10, 10);
2951 
2952   if (!StringHasNoText (label))
2953   {
2954     StaticPrompt (g, label, 0, dialogTextHeight, systemFont, 'l');
2955   }
2956 
2957   scdp->match_choice = PopupList (g, TRUE, NULL);
2958   PopupItem (scdp->match_choice, "Contains");
2959   PopupItem (scdp->match_choice, "Does not contain");
2960   PopupItem (scdp->match_choice, "Equals");
2961   PopupItem (scdp->match_choice, "Does not equal");
2962   PopupItem (scdp->match_choice, "Starts with");
2963   PopupItem (scdp->match_choice, "Ends with");
2964   PopupItem (scdp->match_choice, "Is one of");
2965   PopupItem (scdp->match_choice, "Is not one of");
2966   PopupItem (scdp->match_choice, "Does not start with");
2967   PopupItem (scdp->match_choice, "Does not end with");
2968   SetValue (scdp->match_choice, 1);
2969   scdp->match_text = DialogText (g, "", 15, ChangeStringConstraintDialogText);
2970   SetObjectExtra (scdp->match_text, scdp, NULL);
2971 
2972   k = HiddenGroup (scdp->tab_pages[0], 4, 0, NULL);
2973   SetGroupSpacing (k, 10, 10);
2974   scdp->insensitive = CheckBox (k, "Case Insensitive", NULL);
2975   scdp->whole_word = CheckBox (k, "Whole Word", NULL);
2976   scdp->ignore_space = CheckBox (k, "Ignore Space", NULL);
2977   scdp->ignore_punct = CheckBox (k, "Ignore Punctuation", NULL);
2978 
2979   special_grp2 = HiddenGroup (scdp->tab_pages[0], 3, 0, NULL);
2980   SetGroupSpacing (special_grp2, 10, 10);
2981   scdp->ignore_weasel = CheckBox (special_grp2, "Ignore 'putative' synonyms", NULL);
2982 
2983   special_grp = HiddenGroup (scdp->tab_pages[0], 3, 0, NULL);
2984   SetGroupSpacing (special_grp, 10, 10);
2985   scdp->is_all_caps = CheckBox (special_grp, "All letters are uppercase", ChangeStringConstraintDialogBtn);
2986   SetObjectExtra (scdp->is_all_caps, scdp, NULL);
2987   scdp->is_all_lower = CheckBox (special_grp, "All letters are lowercase", ChangeStringConstraintDialogBtn);
2988   SetObjectExtra (scdp->is_all_lower, scdp, NULL);
2989   scdp->is_all_punct = CheckBox (special_grp, "All characters are punctuation", ChangeStringConstraintDialogBtn);
2990   SetObjectExtra (scdp->is_all_punct, scdp, NULL);
2991 
2992   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) k, (HANDLE) special_grp2, (HANDLE) special_grp, NULL);
2993 
2994 
2995   scdp->tab_pages[1] = HiddenGroup (tab_grp, -1, 0, NULL);
2996   scdp->ignore_words = WordSubstitutionSetDialog (scdp->tab_pages[1], change_notify, change_userdata);
2997   Hide (scdp->tab_pages[1]);
2998   AlignObjects (ALIGN_CENTER, (HANDLE) scdp->tab_pages[0], scdp->tab_pages[1], NULL);
2999 
3000 
3001   if (clear_btn)
3002   {
3003     b = PushButton (p, "Clear Constraint", ClearDialogBtn);
3004     SetObjectExtra (b, p, NULL);
3005   }
3006 
3007   AlignObjects (ALIGN_CENTER, (HANDLE) tab_grp, (HANDLE) b, NULL);
3008 
3009   return (DialoG) p;
3010 }
3011 
3012 
3013 typedef struct enddistancedialog
3014 {
3015   DIALOG_MESSAGE_BLOCK
3016   PopuP dist_type;
3017   TexT  dist_val;
3018 
3019   Nlm_ChangeNotifyProc change_notify;
3020   Pointer change_userdata;
3021 } EndDistanceDialogData, PNTR EndDistanceDialogPtr;
3022 
3023 
ChangeEndDistanceDialogPopup(PopuP p)3024 static void ChangeEndDistanceDialogPopup (PopuP p)
3025 {
3026   EndDistanceDialogPtr dlg;
3027   Int2 val;
3028 
3029   dlg = (EndDistanceDialogPtr) GetObjectExtra (p);
3030   if (dlg == NULL) {
3031     return;
3032   }
3033 
3034   val = GetValue (dlg->dist_type);
3035   if (val == 2 || val == 3 || val == 4) {
3036     Show (dlg->dist_val);
3037   } else {
3038     Hide (dlg->dist_val);
3039   }
3040 
3041   if (dlg->change_notify != NULL) {
3042     (dlg->change_notify) (dlg->change_userdata);
3043   }
3044 }
3045 
3046 
ChangeEndDistanceDialogTexT(TexT t)3047 static void ChangeEndDistanceDialogTexT (TexT t)
3048 {
3049   EndDistanceDialogPtr dlg;
3050 
3051   dlg = (EndDistanceDialogPtr) GetObjectExtra (t);
3052   if (dlg != NULL && dlg->change_notify != NULL) {
3053     (dlg->change_notify) (dlg->change_userdata);
3054   }
3055 }
3056 
3057 
EndDistanceToDialog(DialoG d,Pointer data)3058 static void EndDistanceToDialog (DialoG d, Pointer data)
3059 {
3060   EndDistanceDialogPtr dlg;
3061   ValNodePtr v;
3062   Char       buf[15];
3063 
3064   dlg = (EndDistanceDialogPtr) GetObjectExtra (d);
3065   if (dlg == NULL) return;
3066 
3067   v = (ValNodePtr) data;
3068   if (v == NULL) {
3069     SetValue (dlg->dist_type, 1);
3070     SetTitle (dlg->dist_val, "");
3071     Hide (dlg->dist_val);
3072   } else {
3073     switch (v->choice) {
3074       case LocationPosConstraint_dist_from_end:
3075         SetValue (dlg->dist_type, 2);
3076         sprintf (buf, "%d", v->data.intvalue);
3077         SetTitle (dlg->dist_val, buf);
3078         Show (dlg->dist_val);
3079         break;
3080       case LocationPosConstraint_max_dist_from_end:
3081         SetValue (dlg->dist_type, 3);
3082         sprintf (buf, "%d", v->data.intvalue);
3083         SetTitle (dlg->dist_val, buf);
3084         Show (dlg->dist_val);
3085         break;
3086       case LocationPosConstraint_min_dist_from_end:
3087         SetValue (dlg->dist_type, 4);
3088         sprintf (buf, "%d", v->data.intvalue);
3089         SetTitle (dlg->dist_val, buf);
3090         Show (dlg->dist_val);
3091         break;
3092       default:
3093         SetValue (dlg->dist_type, 1);
3094         SetTitle (dlg->dist_val, "");
3095         Hide (dlg->dist_val);
3096         break;
3097     }
3098   }
3099 }
3100 
3101 
DialogToEndDistance(DialoG d)3102 static Pointer DialogToEndDistance (DialoG d)
3103 {
3104   EndDistanceDialogPtr dlg;
3105   Int2       val;
3106   ValNodePtr v = NULL;
3107   CharPtr    str;
3108 
3109   dlg = (EndDistanceDialogPtr) GetObjectExtra (d);
3110   if (dlg == NULL) return NULL;
3111 
3112   val = GetValue (dlg->dist_type);
3113   if ((val == 2 || val == 3 || val == 4)
3114        && !TextHasNoText(dlg->dist_val))
3115   {
3116     str = SaveStringFromText (dlg->dist_val);
3117     if (StringIsAllDigits (str)) {
3118       v = ValNodeNew (NULL);
3119       switch (val) {
3120         case 2:
3121           v->choice = LocationPosConstraint_dist_from_end;
3122           break;
3123         case 3:
3124           v->choice = LocationPosConstraint_max_dist_from_end;
3125           break;
3126         case 4:
3127           v->choice = LocationPosConstraint_min_dist_from_end;
3128           break;
3129       }
3130       str = SaveStringFromText (dlg->dist_val);
3131       v->data.intvalue = atoi (str);
3132     }
3133     str = MemFree (str);
3134   }
3135   return v;
3136 }
3137 
3138 
TestEndDistanceDialog(DialoG d)3139 static ValNodePtr TestEndDistanceDialog (DialoG d)
3140 {
3141   EndDistanceDialogPtr dlg;
3142   Int2       val;
3143   CharPtr    str;
3144   ValNodePtr err_list = NULL;
3145 
3146   dlg = (EndDistanceDialogPtr) GetObjectExtra (d);
3147   if (dlg != NULL) {
3148     val = GetValue (dlg->dist_type);
3149     if (val == 2 || val == 3 || val == 4) {
3150       if (TextHasNoText (dlg->dist_val)) {
3151         ValNodeAddPointer (&err_list, 0, "No distance value");
3152       } else {
3153         str = SaveStringFromText (dlg->dist_val);
3154         if (!StringIsAllDigits (str)) {
3155           ValNodeAddPointer (&err_list, 0, "Non-numeric value");
3156         }
3157       }
3158     }
3159   }
3160 
3161   return err_list;
3162 }
3163 
3164 
EndDistanceDialog(GrouP h,CharPtr title,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)3165 NLM_EXTERN DialoG EndDistanceDialog (GrouP h, CharPtr title, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
3166 
3167 {
3168   EndDistanceDialogPtr dlg;
3169   GrouP                p;
3170 
3171   dlg = (EndDistanceDialogPtr) MemNew (sizeof (EndDistanceDialogData));
3172   if (dlg == NULL)
3173   {
3174     return NULL;
3175   }
3176 
3177   p = HiddenGroup (h, 4, 0, NULL);
3178   SetObjectExtra (p, dlg, StdCleanupExtraProc);
3179 
3180   dlg->dialog = (DialoG) p;
3181   dlg->todialog = EndDistanceToDialog;
3182   dlg->fromdialog = DialogToEndDistance;
3183   dlg->testdialog = TestEndDistanceDialog;
3184   dlg->change_notify = change_notify;
3185   dlg->change_userdata = change_userdata;
3186 
3187   StaticPrompt (p, "Where end of sequence is ", 0, dialogTextHeight, systemFont, 'l');
3188   dlg->dist_type = PopupList (p, TRUE, ChangeEndDistanceDialogPopup);
3189   SetObjectExtra (dlg->dist_type, dlg, NULL);
3190   PopupItem (dlg->dist_type, "Any distance");
3191   PopupItem (dlg->dist_type, "Exactly");
3192   PopupItem (dlg->dist_type, "No more than");
3193   PopupItem (dlg->dist_type, "No less than");
3194   SetValue (dlg->dist_type, 1);
3195   dlg->dist_val = DialogText (p, "", 5, ChangeEndDistanceDialogTexT);
3196   SetObjectExtra (dlg->dist_val, dlg, NULL);
3197   Hide (dlg->dist_val);
3198   StaticPrompt (p, title, 0, dialogTextHeight, systemFont, 'l');
3199 
3200   return (DialoG) p;
3201 }
3202 
3203 
3204 typedef struct locationconstraintdialog
3205 {
3206   DIALOG_MESSAGE_BLOCK
3207   PopuP  strand;
3208   PopuP  sequence_type;
3209   PopuP  partial5;
3210   PopuP  partial3;
3211   PopuP  location_type;
3212   DialoG dist5;
3213   DialoG dist3;
3214 
3215   Nlm_ChangeNotifyProc change_notify;
3216   Pointer change_userdata;
3217 } LocationConstraintDialogData, PNTR LocationConstraintDialogPtr;
3218 
3219 
ChangeLocationConstraintDialogPopup(PopuP p)3220 static void ChangeLocationConstraintDialogPopup (PopuP p)
3221 {
3222   LocationConstraintDialogPtr dlg;
3223 
3224   dlg = (LocationConstraintDialogPtr) GetObjectExtra (p);
3225   if (dlg != NULL && dlg->change_notify != NULL) {
3226     (dlg->change_notify) (dlg->change_userdata);
3227   }
3228 }
3229 
3230 
LocationConstraintToDialog(DialoG d,Pointer data)3231 static void LocationConstraintToDialog (DialoG d, Pointer data)
3232 {
3233   LocationConstraintDialogPtr dlg;
3234   LocationConstraintPtr l;
3235 
3236   dlg = (LocationConstraintDialogPtr) GetObjectExtra (d);
3237   if (dlg == NULL) return;
3238 
3239   l = (LocationConstraintPtr) data;
3240   if (l == NULL) {
3241     SetValue (dlg->strand, 1);
3242     SetValue (dlg->sequence_type, 1);
3243     SetValue (dlg->partial5, 1);
3244     SetValue (dlg->partial3, 1);
3245     SetValue (dlg->location_type, 1);
3246     PointerToDialog (dlg->dist5, NULL);
3247     PointerToDialog (dlg->dist3, NULL);
3248   } else {
3249     switch (l->strand) {
3250       case Strand_constraint_any:
3251         SetValue (dlg->strand, 1);
3252         break;
3253       case Strand_constraint_plus:
3254         SetValue (dlg->strand, 2);
3255         break;
3256       case Strand_constraint_minus:
3257         SetValue (dlg->strand, 3);
3258         break;
3259       default:
3260         SetValue (dlg->strand, 1);
3261         break;
3262     }
3263     switch (l->seq_type) {
3264       case Seqtype_constraint_any:
3265         SetValue (dlg->sequence_type, 1);
3266         break;
3267       case Seqtype_constraint_nuc:
3268         SetValue (dlg->sequence_type, 2);
3269         break;
3270       case Seqtype_constraint_prot:
3271         SetValue (dlg->sequence_type, 3);
3272         break;
3273       default:
3274         SetValue (dlg->sequence_type, 1);
3275         break;
3276      }
3277     switch (l->partial5) {
3278       case Partial_constraint_either:
3279         SetValue (dlg->partial5, 1);
3280         break;
3281       case Partial_constraint_partial:
3282         SetValue (dlg->partial5, 2);
3283         break;
3284       case Partial_constraint_complete:
3285         SetValue (dlg->partial5, 3);
3286         break;
3287     }
3288     switch (l->partial3) {
3289       case Partial_constraint_either:
3290         SetValue (dlg->partial3, 1);
3291         break;
3292       case Partial_constraint_partial:
3293         SetValue (dlg->partial3, 2);
3294         break;
3295       case Partial_constraint_complete:
3296         SetValue (dlg->partial3, 3);
3297         break;
3298     }
3299     switch (l->location_type) {
3300       case Location_type_constraint_any:
3301         SetValue (dlg->location_type, 1);
3302         break;
3303       case Location_type_constraint_single_interval:
3304         SetValue (dlg->location_type, 2);
3305         break;
3306       case Location_type_constraint_joined:
3307         SetValue (dlg->location_type, 3);
3308         break;
3309       case Location_type_constraint_ordered:
3310         SetValue (dlg->location_type, 4);
3311         break;
3312     }
3313     PointerToDialog (dlg->dist5, l->end5);
3314     PointerToDialog (dlg->dist3, l->end3);
3315   }
3316   ChangeLocationConstraintDialogPopup (dlg->strand);
3317 }
3318 
3319 
DialogToLocationConstraint(DialoG d)3320 static Pointer DialogToLocationConstraint (DialoG d)
3321 {
3322   LocationConstraintDialogPtr dlg;
3323   LocationConstraintPtr l;
3324 
3325   dlg = (LocationConstraintDialogPtr) GetObjectExtra (d);
3326   if (dlg == NULL) return NULL;
3327   l = LocationConstraintNew();
3328   if (l != NULL) {
3329     switch (GetValue (dlg->strand)) {
3330       case 1:
3331         l->strand = Strand_constraint_any;
3332         break;
3333       case 2:
3334         l->strand = Strand_constraint_plus;
3335         break;
3336       case 3:
3337         l->strand = Strand_constraint_minus;
3338         break;
3339       default:
3340         l->strand = Strand_constraint_any;
3341         break;
3342     }
3343     switch (GetValue (dlg->sequence_type)) {
3344       case 1:
3345         l->seq_type = Seqtype_constraint_any;
3346         break;
3347       case 2:
3348         l->seq_type = Seqtype_constraint_nuc;
3349         break;
3350       case 3:
3351         l->seq_type = Seqtype_constraint_prot;
3352         break;
3353       default:
3354         l->seq_type = Seqtype_constraint_any;
3355         break;
3356     }
3357     switch (GetValue (dlg->partial5)) {
3358       case 1:
3359         l->partial5 = Partial_constraint_either;
3360         break;
3361       case 2:
3362         l->partial5 = Partial_constraint_partial;
3363         break;
3364       case 3:
3365         l->partial5 = Partial_constraint_complete;
3366         break;
3367     }
3368     switch (GetValue (dlg->partial3)) {
3369       case 1:
3370         l->partial3 = Partial_constraint_either;
3371         break;
3372       case 2:
3373         l->partial3 = Partial_constraint_partial;
3374         break;
3375       case 3:
3376         l->partial3 = Partial_constraint_complete;
3377         break;
3378     }
3379     switch (GetValue (dlg->location_type)) {
3380       case 1:
3381         l->location_type = Location_type_constraint_any;
3382         break;
3383       case 2:
3384         l->location_type = Location_type_constraint_single_interval;
3385         break;
3386       case 3:
3387         l->location_type = Location_type_constraint_joined;
3388         break;
3389       case 4:
3390         l->location_type = Location_type_constraint_ordered;
3391         break;
3392     }
3393     l->end5 = DialogToPointer (dlg->dist5);
3394     l->end3 = DialogToPointer (dlg->dist3);
3395   }
3396   if (IsLocationConstraintEmpty (l)) {
3397     l = LocationConstraintFree (l);
3398   }
3399   return l;
3400 }
3401 
3402 
TestLocationConstraintDialog(DialoG d)3403 static ValNodePtr TestLocationConstraintDialog (DialoG d)
3404 {
3405   LocationConstraintDialogPtr dlg;
3406   ValNodePtr err_list = NULL;
3407   LocationConstraintPtr lcp;
3408 
3409   dlg = (LocationConstraintDialogPtr) GetObjectExtra (d);
3410   if (dlg != NULL) {
3411     lcp = DialogToPointer (d);
3412     if (IsLocationConstraintEmpty (lcp)) {
3413       ValNodeAddPointer (&err_list, 0, "location constraint empty");
3414     }
3415     lcp = LocationConstraintFree (lcp);
3416     ValNodeLink (&err_list, TestDialog (dlg->dist5));
3417     ValNodeLink (&err_list, TestDialog (dlg->dist3));
3418   }
3419   return err_list;
3420 }
3421 
3422 
LocationConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)3423 NLM_EXTERN DialoG LocationConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
3424 
3425 {
3426   LocationConstraintDialogPtr dlg;
3427   GrouP                     p, g1, g2;
3428 
3429   dlg = (LocationConstraintDialogPtr) MemNew (sizeof (LocationConstraintDialogData));
3430   if (dlg == NULL)
3431   {
3432     return NULL;
3433   }
3434 
3435   p = HiddenGroup (h, -1, 0, NULL);
3436   SetGroupSpacing (p, 10, 10);
3437   SetObjectExtra (p, dlg, StdCleanupExtraProc);
3438 
3439   dlg->dialog = (DialoG) p;
3440   dlg->todialog = LocationConstraintToDialog;
3441   dlg->fromdialog = DialogToLocationConstraint;
3442   dlg->testdialog = TestLocationConstraintDialog;
3443   dlg->change_notify = change_notify;
3444   dlg->change_userdata = change_userdata;
3445 
3446   g1 = HiddenGroup (p, 4, 0, NULL);
3447   SetGroupSpacing (g1, 10, 10);
3448   StaticPrompt (g1, "on", 0, dialogTextHeight, systemFont, 'l');
3449   dlg->strand = PopupList (g1, TRUE, ChangeLocationConstraintDialogPopup);
3450   SetObjectExtra (dlg->strand, dlg, NULL);
3451   PopupItem (dlg->strand, "Any strand");
3452   PopupItem (dlg->strand, "Plus strand");
3453   PopupItem (dlg->strand, "Minus strand");
3454   SetValue (dlg->strand, 1);
3455 
3456   StaticPrompt (g1, "on", 0, dialogTextHeight, systemFont, 'l');
3457   dlg->sequence_type = PopupList (g1, TRUE, ChangeLocationConstraintDialogPopup);
3458   SetObjectExtra (dlg->sequence_type, dlg, NULL);
3459   PopupItem (dlg->sequence_type, "nucleotide and protein sequences");
3460   PopupItem (dlg->sequence_type, "nucleotide sequences only");
3461   PopupItem (dlg->sequence_type, "protein sequences only");
3462   SetValue (dlg->sequence_type, 1);
3463 
3464   StaticPrompt (g1, "5' end", 0, dialogTextHeight, systemFont, 'l');
3465   dlg->partial5 = PopupList (g1, TRUE, ChangeLocationConstraintDialogPopup);
3466   SetObjectExtra (dlg->partial5, dlg, NULL);
3467   PopupItem (dlg->partial5, "Partial or Complete");
3468   PopupItem (dlg->partial5, "Partial");
3469   PopupItem (dlg->partial5, "Complete");
3470   SetValue (dlg->partial5, 1);
3471 
3472   StaticPrompt (g1, "3' end", 0, dialogTextHeight, systemFont, 'l');
3473   dlg->partial3 = PopupList (g1, TRUE, ChangeLocationConstraintDialogPopup);
3474   SetObjectExtra (dlg->partial3, dlg, NULL);
3475   PopupItem (dlg->partial3, "Partial or Complete");
3476   PopupItem (dlg->partial3, "Partial");
3477   PopupItem (dlg->partial3, "Complete");
3478   SetValue (dlg->partial3, 1);
3479 
3480   StaticPrompt (g1, "location type", 0, dialogTextHeight, systemFont, 'l');
3481   dlg->location_type = PopupList (g1, TRUE, ChangeLocationConstraintDialogPopup);
3482   SetObjectExtra (dlg->location_type, dlg, NULL);
3483   PopupItem (dlg->location_type, "Any");
3484   PopupItem (dlg->location_type, "Single Interval");
3485   PopupItem (dlg->location_type, "Joined");
3486   PopupItem (dlg->location_type, "Ordered");
3487   SetValue (dlg->location_type, 1);
3488 
3489   g2 = HiddenGroup (p, 0, 2, NULL);
3490   SetGroupSpacing (g2, 10, 10);
3491   dlg->dist5 = EndDistanceDialog (g2, "from 5' end of feature", dlg->change_notify, dlg->change_userdata);
3492   dlg->dist3 = EndDistanceDialog (g2, "from 3' end of feature", dlg->change_notify, dlg->change_userdata);
3493 
3494   AlignObjects (ALIGN_CENTER, (HANDLE) g1, (HANDLE) g2, NULL);
3495 
3496   return (DialoG) p;
3497 }
3498 
3499 
3500 typedef struct sourcequalchoicedialog
3501 {
3502   DIALOG_MESSAGE_BLOCK
3503   DialoG dlg;
3504   DialoG tax_dlg;
3505   DialoG loc_dlg;
3506   DialoG orig_dlg;
3507   GrouP  choice_type;
3508   Nlm_ChangeNotifyProc change_notify;
3509   Pointer change_userdata;
3510 } SourceQualChoiceDialogData, PNTR SourceQualChoiceDialogPtr;
3511 
3512 
ChangeSourceQualChoice(GrouP g)3513 static void ChangeSourceQualChoice (GrouP g)
3514 {
3515   SourceQualChoiceDialogPtr dlg;
3516   Int4 val;
3517 
3518   dlg = (SourceQualChoiceDialogPtr) GetObjectExtra (g);
3519   if (dlg == NULL || dlg->choice_type == NULL) return;
3520 
3521   val = GetValue (dlg->choice_type);
3522   switch (val) {
3523     case 1:
3524       Show (dlg->dlg);
3525       Hide (dlg->tax_dlg);
3526       Hide (dlg->loc_dlg);
3527       Hide (dlg->orig_dlg);
3528       break;
3529     case 2:
3530       Hide (dlg->dlg);
3531       Show (dlg->tax_dlg);
3532       Hide (dlg->loc_dlg);
3533       Hide (dlg->orig_dlg);
3534       break;
3535     case 3:
3536       Hide (dlg->dlg);
3537       Hide (dlg->tax_dlg);
3538       Show (dlg->loc_dlg);
3539       Hide (dlg->orig_dlg);
3540       break;
3541     case 4:
3542       Hide (dlg->dlg);
3543       Hide (dlg->tax_dlg);
3544       Hide (dlg->loc_dlg);
3545       Show (dlg->orig_dlg);
3546       break;
3547     default:
3548       Hide (dlg->dlg);
3549       Hide (dlg->tax_dlg);
3550       Hide (dlg->loc_dlg);
3551       Hide (dlg->orig_dlg);
3552       break;
3553   }
3554   if (dlg->change_notify != NULL) {
3555     (dlg->change_notify) (dlg->change_userdata);
3556   }
3557 }
3558 
3559 
IsSourceQualTaxQual(Int4 srcqual)3560 static Boolean IsSourceQualTaxQual (Int4 srcqual)
3561 {
3562   if (srcqual == Source_qual_taxname
3563       || srcqual == Source_qual_lineage
3564       || srcqual == Source_qual_common_name
3565       || srcqual == Source_qual_division) {
3566     return TRUE;
3567   } else {
3568     return FALSE;
3569   }
3570 }
3571 
3572 
SourceQualChoiceToDialog(DialoG d,Pointer data)3573 static void SourceQualChoiceToDialog (DialoG d, Pointer data)
3574 {
3575   SourceQualChoiceDialogPtr dlg;
3576   ValNodePtr                vnp;
3577   ValNode                   vn;
3578 
3579   dlg = (SourceQualChoiceDialogPtr) GetObjectExtra (d);
3580   if (dlg == NULL) return;
3581   vnp = (ValNodePtr) data;
3582 
3583   if (vnp == NULL) {
3584     SafeSetValue (dlg->choice_type, 1);
3585     PointerToDialog (dlg->dlg, NULL);
3586   } else if (vnp->choice == SourceQualChoice_textqual) {
3587     vn.choice = 0;
3588     vn.next = NULL;
3589     vn.data.ptrvalue = GetSourceQualName (vnp->data.intvalue);
3590     if (IsSourceQualTaxQual (vnp->data.intvalue)) {
3591       SafeSetValue (dlg->choice_type, 2);
3592       PointerToDialog (dlg->tax_dlg, &vn);
3593     } else {
3594       SafeSetValue (dlg->choice_type, 1);
3595       PointerToDialog (dlg->dlg, &vn);
3596     }
3597   } else if (vnp->choice == SourceQualChoice_location) {
3598     SafeSetValue (dlg->choice_type, 3);
3599     vn.choice = vnp->data.intvalue;
3600     vn.next = NULL;
3601     vn.data.ptrvalue = NULL;
3602     PointerToDialog (dlg->loc_dlg, &vn);
3603   } else if (vnp->choice == SourceQualChoice_origin) {
3604     SafeSetValue (dlg->choice_type, 4);
3605     vn.choice = vnp->data.intvalue;
3606     vn.next = NULL;
3607     vn.data.ptrvalue = NULL;
3608     PointerToDialog (dlg->orig_dlg, &vn);
3609   }
3610 
3611   ChangeSourceQualChoice (dlg->choice_type);
3612 }
3613 
3614 
DialogToSourceQualChoice(DialoG d)3615 static Pointer DialogToSourceQualChoice (DialoG d)
3616 {
3617   SourceQualChoiceDialogPtr dlg;
3618   ValNodePtr                vnp, sqc = NULL;
3619   Int4                      choice_type = SourceQualChoice_textqual;
3620   DialoG                    text_dlg = NULL;
3621 
3622   dlg = (SourceQualChoiceDialogPtr) GetObjectExtra (d);
3623   if (dlg == NULL) return NULL;
3624 
3625   if (dlg->choice_type == NULL) {
3626     choice_type = SourceQualChoice_textqual;
3627     text_dlg = dlg->dlg;
3628   } else {
3629     switch (GetValue (dlg->choice_type)) {
3630       case 1:
3631         choice_type = SourceQualChoice_textqual;
3632         text_dlg = dlg->dlg;
3633         break;
3634       case 2:
3635         choice_type = SourceQualChoice_textqual;
3636         text_dlg = dlg->tax_dlg;
3637         break;
3638       case 3:
3639         choice_type = SourceQualChoice_location;
3640         break;
3641       case 4:
3642         choice_type = SourceQualChoice_origin;
3643         break;
3644     }
3645   }
3646   switch (choice_type) {
3647     case SourceQualChoice_textqual:
3648       vnp = DialogToPointer (text_dlg);
3649       if (vnp != NULL) {
3650         sqc = ValNodeNew (NULL);
3651         sqc->choice = SourceQualChoice_textqual;
3652         sqc->data.intvalue = GetSourceQualTypeByName (vnp->data.ptrvalue);
3653       }
3654       vnp = ValNodeFree (vnp);
3655       break;
3656     case SourceQualChoice_location:
3657       vnp = DialogToPointer (dlg->loc_dlg);
3658       sqc = ValNodeNew (NULL);
3659       sqc->choice = SourceQualChoice_location;
3660       if (vnp == NULL) {
3661         sqc->data.intvalue = 0;
3662       } else {
3663         sqc->data.intvalue = vnp->choice;
3664       }
3665       vnp = ValNodeFree (vnp);
3666       break;
3667     case SourceQualChoice_origin:
3668       vnp = DialogToPointer (dlg->orig_dlg);
3669       sqc = ValNodeNew (NULL);
3670       sqc->choice = SourceQualChoice_origin;
3671       if (vnp == NULL) {
3672         sqc->data.intvalue = 0;
3673       } else {
3674         sqc->data.intvalue = vnp->choice;
3675       }
3676       vnp = ValNodeFree (vnp);
3677       break;
3678   }
3679   return sqc;
3680 }
3681 
3682 
TestSourceQualChoiceDialog(DialoG d)3683 static ValNodePtr TestSourceQualChoiceDialog (DialoG d)
3684 {
3685   SourceQualChoiceDialogPtr dlg;
3686   ValNodePtr err_list = NULL;
3687   Int4 val;
3688 
3689   dlg = (SourceQualChoiceDialogPtr) GetObjectExtra (d);
3690   if (dlg == NULL) return NULL;
3691 
3692   if (dlg->choice_type == NULL) {
3693     err_list = TestDialog (dlg->dlg);
3694   } else {
3695     val = GetValue (dlg->choice_type);
3696     switch (val) {
3697       case 1:
3698         err_list = TestDialog (dlg->dlg);
3699         break;
3700       case 2:
3701         err_list = TestDialog (dlg->tax_dlg);
3702         break;
3703       case 3:
3704         err_list = TestDialog (dlg->loc_dlg);
3705         break;
3706       case 4:
3707         err_list = TestDialog (dlg->orig_dlg);
3708         break;
3709       default:
3710         ValNodeAddPointer (&err_list, 0, "no source qual choice");
3711         break;
3712     }
3713   }
3714   return err_list;
3715 }
3716 
3717 
SourceQualChoiceDialogMessage(DialoG d,Int2 mssg)3718 static void SourceQualChoiceDialogMessage (DialoG d, Int2 mssg)
3719 
3720 {
3721   SourceQualChoiceDialogPtr dlg;
3722   ValNode vn;
3723 
3724   dlg = (SourceQualChoiceDialogPtr) GetObjectExtra (d);
3725   if (dlg != NULL) {
3726     switch (mssg) {
3727       case VIB_MSG_ENTER :
3728         switch (GetValue (dlg->choice_type)) {
3729           case 1:
3730             MemSet (&vn, 0, sizeof (ValNode));
3731             vn.choice = Source_qual_acronym;
3732             vn.data.ptrvalue = "acronym";
3733             PointerToDialog (dlg->dlg, &vn);
3734             SendMessageToDialog (dlg->dlg, VIB_MSG_ENTER);
3735             break;
3736           case 2:
3737             Select (dlg->tax_dlg);
3738             break;
3739           case 3:
3740             Select (dlg->loc_dlg);
3741             break;
3742           case 4:
3743             Select (dlg->orig_dlg);
3744             break;
3745         }
3746       break;
3747     }
3748   }
3749 }
3750 
3751 
SourceQualChoiceDialog(GrouP h,Boolean text_only,Boolean for_remove,Boolean tall,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)3752 static DialoG SourceQualChoiceDialog (GrouP h, Boolean text_only, Boolean for_remove, Boolean tall, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
3753 {
3754   SourceQualChoiceDialogPtr dlg;
3755   GrouP                     p, g;
3756   ValNodePtr                qual_list, loc_list, orig_list, tax_list = NULL;
3757   ButtoN                    b1, b2, b3 = NULL, b4 = NULL;
3758   ValNode                   vn;
3759   Int2                      list_height;
3760 
3761   dlg = (SourceQualChoiceDialogPtr) MemNew (sizeof (SourceQualChoiceDialogData));
3762   if (dlg == NULL)
3763   {
3764     return NULL;
3765   }
3766 
3767   p = HiddenGroup (h, 2, 0, NULL);
3768   SetObjectExtra (p, dlg, StdCleanupExtraProc);
3769 
3770   dlg->dialog = (DialoG) p;
3771   dlg->todialog = SourceQualChoiceToDialog;
3772   dlg->fromdialog = DialogToSourceQualChoice;
3773   dlg->testdialog = TestSourceQualChoiceDialog;
3774   dlg->dialogmessage = SourceQualChoiceDialogMessage;
3775   dlg->change_notify = change_notify;
3776   dlg->change_userdata = change_userdata;
3777 
3778   if (tall) {
3779     list_height = TALL_SELECTION_LIST;
3780   } else {
3781     list_height = SHORT_SELECTION_LIST;
3782   }
3783 
3784   dlg->choice_type = HiddenGroup (p, 0, 4, ChangeSourceQualChoice);
3785   SetObjectExtra (dlg->choice_type, dlg, NULL);
3786   b1 = RadioButton (dlg->choice_type, "Text Qualifier");
3787   b2 = RadioButton (dlg->choice_type, "Taxonomy");
3788   if (!text_only) {
3789     b3 = RadioButton (dlg->choice_type, "Location");
3790     b4 = RadioButton (dlg->choice_type, "Origin");
3791   }
3792 
3793   g = HiddenGroup (p, 0, 0, NULL);
3794   qual_list = GetSourceQualList (for_remove);
3795   dlg->dlg = ValNodeSelectionDialog (g, qual_list, list_height,
3796                                                ValNodeStringName,
3797                                                ValNodeSimpleDataFree,
3798                                                ValNodeStringCopy,
3799                                                ValNodeStringMatch,
3800                                                "source qual",
3801                                                change_notify, change_userdata, FALSE);
3802 
3803   ValNodeAddPointer (&tax_list, 0, StringSave (GetSourceQualName(Source_qual_taxname)));
3804   ValNodeAddPointer (&tax_list, 0, StringSave (GetSourceQualName(Source_qual_common_name)));
3805   ValNodeAddPointer (&tax_list, 0, StringSave (GetSourceQualName(Source_qual_division)));
3806   ValNodeAddPointer (&tax_list, 0, StringSave (GetSourceQualName(Source_qual_lineage)));
3807   dlg->tax_dlg = ValNodeSelectionDialog (g, tax_list, list_height,
3808                                                ValNodeStringName,
3809                                                ValNodeSimpleDataFree,
3810                                                ValNodeStringCopy,
3811                                                ValNodeStringMatch,
3812                                                "source qual",
3813                                                change_notify, change_userdata, FALSE);
3814   vn.choice = 0;
3815   vn.data.ptrvalue = GetSourceQualName(Source_qual_taxname);
3816   vn.next = NULL;
3817   PointerToDialog (dlg->tax_dlg, &vn);
3818 
3819   if (!text_only) {
3820     if (for_remove) {
3821       loc_list = GetLocationList (for_remove);
3822     } else {
3823       loc_list = GetLocListForBioSource (NULL);
3824     }
3825     dlg->loc_dlg = ValNodeSelectionDialog (g, loc_list, list_height, ValNodeStringName,
3826                                            ValNodeSimpleDataFree, ValNodeStringCopy,
3827                                            ValNodeChoiceMatch, "location",
3828                                            change_notify, change_userdata, FALSE);
3829     if (for_remove) {
3830       vn.choice = Source_location_unknown;
3831       vn.data.ptrvalue = NULL;
3832       vn.next = NULL;
3833       PointerToDialog (dlg->loc_dlg, &vn);
3834     }
3835     orig_list = GetOriginList (for_remove);
3836     dlg->orig_dlg = ValNodeSelectionDialog (g, orig_list, list_height, ValNodeStringName,
3837                                            ValNodeSimpleDataFree, ValNodeStringCopy,
3838                                            ValNodeChoiceMatch, "origin",
3839                                            change_notify, change_userdata, FALSE);
3840     if (for_remove) {
3841       vn.choice = Source_origin_unknown;
3842       vn.data.ptrvalue = NULL;
3843       vn.next = NULL;
3844       PointerToDialog (dlg->orig_dlg, &vn);
3845     }
3846   }
3847   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->dlg, (HANDLE) dlg->tax_dlg, (HANDLE) dlg->loc_dlg, (HANDLE) dlg->orig_dlg, NULL);
3848 
3849   SetValue (dlg->choice_type, 1);
3850   ChangeSourceQualChoice (dlg->choice_type);
3851 
3852   return (DialoG) p;
3853 }
3854 
3855 
3856 typedef struct sourceconstraintdialog
3857 {
3858   DIALOG_MESSAGE_BLOCK
3859   GrouP  constraint_type;
3860 
3861   DialoG qual_present;
3862   GrouP sc_group;
3863   DialoG qual_string;
3864   DialoG string_constraint;
3865   GrouP match_group;
3866   DialoG qualmatch1;
3867   DialoG qualmatch2;
3868 
3869   Nlm_ChangeNotifyProc change_notify;
3870   Pointer change_userdata;
3871 } SourceConstraintDialogData, PNTR SourceConstraintDialogPtr;
3872 
3873 
ChangeSourceConstraintType(GrouP p)3874 static void ChangeSourceConstraintType (GrouP p)
3875 {
3876   SourceConstraintDialogPtr dlg;
3877   Int4                      constraint_type;
3878 
3879   dlg = (SourceConstraintDialogPtr) GetObjectExtra (p);
3880   if (dlg == NULL)
3881   {
3882     return;
3883   }
3884   Hide (dlg->qual_present);
3885   Hide (dlg->sc_group);
3886   Hide (dlg->match_group);
3887   constraint_type = GetValue (dlg->constraint_type);
3888   switch (constraint_type) {
3889     case 1:
3890       Show (dlg->qual_present);
3891       break;
3892     case 2:
3893       Show (dlg->sc_group);
3894       break;
3895     case 3:
3896       Show (dlg->match_group);
3897       break;
3898   }
3899   if (dlg->change_notify != NULL) {
3900     (dlg->change_notify)(dlg->change_userdata);
3901   }
3902 }
3903 
3904 
SourceConstraintToDialog(DialoG d,Pointer data)3905 static void SourceConstraintToDialog (DialoG d, Pointer data)
3906 {
3907   SourceConstraintDialogPtr dlg;
3908   SourceConstraintPtr s;
3909 
3910   dlg = (SourceConstraintDialogPtr) GetObjectExtra (d);
3911   if (dlg == NULL) return;
3912 
3913   s = (SourceConstraintPtr) data;
3914   SetValue (dlg->constraint_type, 1);
3915   PointerToDialog (dlg->qual_present, NULL);
3916   PointerToDialog (dlg->qual_string, NULL);
3917   PointerToDialog (dlg->string_constraint, NULL);
3918   PointerToDialog (dlg->qualmatch1, NULL);
3919   PointerToDialog (dlg->qualmatch2, NULL);
3920   if (s != NULL) {
3921     if (s->field1 != NULL && s->field2 != NULL) {
3922       SetValue (dlg->constraint_type, 3);
3923       PointerToDialog (dlg->qualmatch1, s->field1);
3924       PointerToDialog (dlg->qualmatch2, s->field2);
3925     } else if ((s->field1 != NULL || s->field2 != NULL) && s->constraint != NULL) {
3926       SetValue (dlg->constraint_type, 2);
3927       if (s->field1 != NULL) {
3928         PointerToDialog (dlg->qual_string, s->field1);
3929       } else if (s->field2 != NULL) {
3930         PointerToDialog (dlg->qual_string, s->field2);
3931       }
3932       PointerToDialog (dlg->string_constraint, s->constraint);
3933     } else if (s->field1 != NULL || s->field2 != NULL) {
3934       SetValue (dlg->constraint_type, 1);
3935       if (s->field1 != NULL) {
3936         PointerToDialog (dlg->qual_present, s->field1);
3937       } else if (s->field2 != NULL) {
3938         PointerToDialog (dlg->qual_present, s->field2);
3939       }
3940     }
3941   }
3942   ChangeSourceConstraintType (dlg->constraint_type);
3943 }
3944 
3945 
DialogToSourceConstraint(DialoG d)3946 static Pointer DialogToSourceConstraint (DialoG d)
3947 {
3948   SourceConstraintDialogPtr dlg;
3949   SourceConstraintPtr s = NULL;
3950   Int2                constraint_type;
3951 
3952   dlg = (SourceConstraintDialogPtr) GetObjectExtra (d);
3953   if (dlg == NULL) return NULL;
3954 
3955   constraint_type = GetValue (dlg->constraint_type);
3956   switch (constraint_type) {
3957     case 1:
3958       s = SourceConstraintNew();
3959       s->field1 = DialogToPointer (dlg->qual_present);
3960       break;
3961     case 2:
3962       s = SourceConstraintNew();
3963       s->field1 = DialogToPointer (dlg->qual_string);
3964       s->constraint = DialogToPointer (dlg->string_constraint);
3965       break;
3966     case 3:
3967       s = SourceConstraintNew();
3968       s->field1 = DialogToPointer (dlg->qualmatch1);
3969       s->field2 = DialogToPointer (dlg->qualmatch2);
3970       break;
3971   }
3972   return s;
3973 }
3974 
3975 
TestSourceConstraintDialog(DialoG d)3976 static ValNodePtr TestSourceConstraintDialog (DialoG d)
3977 {
3978   SourceConstraintPtr constraint;
3979   ValNodePtr err_list = NULL;
3980 
3981   constraint = DialogToPointer (d);
3982   if (IsSourceConstraintEmpty (constraint) || (constraint->field1 == NULL && constraint->field2 == NULL)) {
3983     ValNodeAddPointer (&err_list, 0, "empty source constraint");
3984   }
3985   constraint = SourceConstraintFree (constraint);
3986   return err_list;
3987 }
3988 
3989 
SourceConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)3990 static DialoG SourceConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
3991 
3992 {
3993   SourceConstraintDialogPtr dlg;
3994   GrouP                     p, g;
3995   ButtoN                    b1, b2, b3;
3996 
3997   dlg = (SourceConstraintDialogPtr) MemNew (sizeof (SourceConstraintDialogData));
3998   if (dlg == NULL)
3999   {
4000     return NULL;
4001   }
4002 
4003   p = HiddenGroup (h, -1, 0, NULL);
4004   SetObjectExtra (p, dlg, StdCleanupExtraProc);
4005 
4006   dlg->dialog = (DialoG) p;
4007   dlg->todialog = SourceConstraintToDialog;
4008   dlg->fromdialog = DialogToSourceConstraint;
4009   dlg->testdialog = TestSourceConstraintDialog;
4010   dlg->change_notify = change_notify;
4011   dlg->change_userdata = change_userdata;
4012 
4013   dlg->constraint_type = HiddenGroup (p, 3, 0, ChangeSourceConstraintType);
4014   SetObjectExtra (dlg->constraint_type, dlg, NULL);
4015   b1 = RadioButton (dlg->constraint_type, "When qualifier present");
4016   b2 = RadioButton (dlg->constraint_type, "String constraint");
4017   b3 = RadioButton (dlg->constraint_type, "When qualifiers match");
4018 
4019   g = HiddenGroup (p, 0, 0, NULL);
4020 
4021   dlg->qual_present = SourceQualChoiceDialog (g, TRUE, FALSE, TRUE, change_notify, change_userdata);
4022 
4023   dlg->sc_group = HiddenGroup (g, 2, 0, NULL);
4024   dlg->qual_string = SourceQualChoiceDialog (dlg->sc_group, TRUE, FALSE, TRUE, change_notify, change_userdata);
4025   dlg->string_constraint = StringConstraintDialog (dlg->sc_group, NULL, FALSE, change_notify, change_userdata);
4026 
4027   dlg->match_group = HiddenGroup (g, 3, 0, NULL);
4028   dlg->qualmatch1 = SourceQualChoiceDialog (dlg->match_group, TRUE, FALSE, TRUE, change_notify, change_userdata);
4029   StaticPrompt (dlg->match_group, "Equals", 0, dialogTextHeight, systemFont, 'l');
4030   dlg->qualmatch2 = SourceQualChoiceDialog (dlg->match_group, TRUE, FALSE, TRUE, change_notify, change_userdata);
4031 
4032   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->qual_present, (HANDLE) dlg->sc_group, (HANDLE) dlg->match_group, NULL);
4033 
4034   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->constraint_type, (HANDLE) g, NULL);
4035 
4036   SetValue (dlg->constraint_type, 1);
4037   ChangeSourceConstraintType (dlg->constraint_type);
4038   return (DialoG) p;
4039 }
4040 
4041 
4042 static DialoG CDSGeneProtFieldDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata);
4043 
4044 
4045 typedef struct cdsgeneprotpseudoconstraintdlg {
4046   DIALOG_MESSAGE_BLOCK
4047   DialoG feat;
4048   GrouP  pseudo;
4049 } CDSGeneProtPseudoConstraintDlgData, PNTR CDSGeneProtPseudoConstraintDlgPtr;
4050 
4051 
CDSGeneProtPseudoConstraintToDialog(DialoG d,Pointer data)4052 static void CDSGeneProtPseudoConstraintToDialog (DialoG d, Pointer data)
4053 {
4054   CDSGeneProtPseudoConstraintDlgPtr dlg;
4055   CDSGeneProtPseudoConstraintPtr pseudo;
4056   ValNode vn;
4057 
4058   dlg = (CDSGeneProtPseudoConstraintDlgPtr) GetObjectExtra (d);
4059   if (dlg == NULL) {
4060     return;
4061   }
4062 
4063   pseudo = (CDSGeneProtPseudoConstraintPtr) data;
4064 
4065   if (pseudo == NULL) {
4066     PointerToDialog (dlg->feat, NULL);
4067     SetValue (dlg->pseudo, 1);
4068   } else {
4069     vn.choice = (Uint1) pseudo->feature;
4070     vn.data.ptrvalue = NULL;
4071     vn.next = NULL;
4072     PointerToDialog (dlg->feat, &vn);
4073     if (pseudo->is_pseudo) {
4074       SetValue (dlg->pseudo, 1);
4075     } else {
4076       SetValue (dlg->pseudo, 2);
4077     }
4078   }
4079 }
4080 
4081 
DialogToCDSGeneProtPseudoConstraint(DialoG d)4082 static Pointer DialogToCDSGeneProtPseudoConstraint (DialoG d)
4083 {
4084   CDSGeneProtPseudoConstraintDlgPtr dlg;
4085   CDSGeneProtPseudoConstraintPtr constraint;
4086   Uint2 feat_type;
4087   ValNodePtr vnp;
4088   Int2       val;
4089 
4090   dlg = (CDSGeneProtPseudoConstraintDlgPtr) GetObjectExtra (d);
4091   if (dlg == NULL) {
4092     return NULL;
4093   }
4094 
4095   val = GetValue (dlg->pseudo);
4096   if (val < 1 || val > 2) {
4097     return NULL;
4098   }
4099   vnp = (ValNodePtr) DialogToPointer (dlg->feat);
4100   if (vnp == NULL) return NULL;
4101   feat_type = vnp->choice;
4102   vnp = ValNodeFree (vnp);
4103 
4104   constraint = CDSGeneProtPseudoConstraintNew ();
4105   constraint->feature = feat_type;
4106   constraint->is_pseudo = val == 1 ? TRUE : FALSE;
4107 
4108   return (Pointer) constraint;
4109 }
4110 
4111 
TestCDSGeneProtPseudoConstraintDialog(DialoG d)4112 static ValNodePtr TestCDSGeneProtPseudoConstraintDialog (DialoG d)
4113 {
4114   CDSGeneProtPseudoConstraintDlgPtr dlg;
4115   ValNodePtr err_list = NULL;
4116   Int4       val;
4117 
4118   dlg = (CDSGeneProtPseudoConstraintDlgPtr) GetObjectExtra (d);
4119   if (dlg != NULL) {
4120     val = GetValue (dlg->pseudo);
4121     if (val < 1 || val > 2) {
4122       ValNodeAddPointer (&err_list, 0, "pseudo");
4123     }
4124     ValNodeLink (&err_list, TestDialog (dlg->feat));
4125   }
4126   return err_list;
4127 }
4128 
CDSGeneProtPseudoConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)4129 static DialoG CDSGeneProtPseudoConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
4130 {
4131   CDSGeneProtPseudoConstraintDlgPtr dlg;
4132   ValNodePtr feat_list = NULL;
4133   GrouP p;
4134 
4135   p = HiddenGroup (h, -1, 0, NULL);
4136   dlg = (CDSGeneProtPseudoConstraintDlgPtr) MemNew (sizeof (CDSGeneProtPseudoConstraintDlgData));
4137   SetObjectExtra (p, dlg, StdCleanupExtraProc);
4138   dlg->dialog = (DialoG) p;
4139   dlg->todialog = CDSGeneProtPseudoConstraintToDialog;
4140   dlg->fromdialog = DialogToCDSGeneProtPseudoConstraint;
4141   dlg->testdialog = TestCDSGeneProtPseudoConstraintDialog;
4142 
4143   AddAllCDSGeneProtFeaturesToChoiceList (&feat_list);
4144   dlg->feat = ValNodeSelectionDialog (p, feat_list, TALL_SELECTION_LIST, ValNodeStringName,
4145                                 ValNodeSimpleDataFree, ValNodeStringCopy,
4146                                 ValNodeChoiceMatch, "feature type",
4147                                 change_notify, change_userdata, FALSE);
4148 
4149   dlg->pseudo = HiddenGroup (p, 2, 0, NULL);
4150   RadioButton (dlg->pseudo, "Is pseudo");
4151   RadioButton (dlg->pseudo, "Is not pseudo");
4152   SetValue (dlg->pseudo, 1);
4153   return (DialoG) p;
4154 }
4155 
4156 
4157 typedef struct cdsgeneprotqualconstraintdialog
4158 {
4159   DIALOG_MESSAGE_BLOCK
4160   GrouP  constraint_type;
4161 
4162   DialoG qual_present;
4163   GrouP sc_group;
4164   DialoG qual_string;
4165   DialoG string_constraint;
4166   GrouP match_group;
4167   DialoG qualmatch1;
4168   DialoG qualmatch2;
4169 
4170   Nlm_ChangeNotifyProc change_notify;
4171   Pointer change_userdata;
4172 } CDSGeneProtQualConstraintDialogData, PNTR CDSGeneProtQualConstraintDialogPtr;
4173 
4174 
ChangeCDSGeneProtQualConstraintType(GrouP p)4175 static void ChangeCDSGeneProtQualConstraintType (GrouP p)
4176 {
4177   CDSGeneProtQualConstraintDialogPtr dlg;
4178   Int4                      constraint_type;
4179 
4180   dlg = (CDSGeneProtQualConstraintDialogPtr) GetObjectExtra (p);
4181   if (dlg == NULL)
4182   {
4183     return;
4184   }
4185   Hide (dlg->qual_present);
4186   Hide (dlg->sc_group);
4187   Hide (dlg->match_group);
4188   constraint_type = GetValue (dlg->constraint_type);
4189   switch (constraint_type) {
4190     case 1:
4191       Show (dlg->qual_present);
4192       break;
4193     case 2:
4194       Show (dlg->sc_group);
4195       break;
4196     case 3:
4197       Show (dlg->match_group);
4198       break;
4199   }
4200   if (dlg->change_notify != NULL) {
4201     (dlg->change_notify) (dlg->change_userdata);
4202   }
4203 }
4204 
4205 
CDSGeneProtQualConstraintToDialog(DialoG d,Pointer data)4206 static void CDSGeneProtQualConstraintToDialog (DialoG d, Pointer data)
4207 {
4208   CDSGeneProtQualConstraintDialogPtr dlg;
4209   CDSGeneProtQualConstraintPtr s;
4210 
4211   dlg = (CDSGeneProtQualConstraintDialogPtr) GetObjectExtra (d);
4212   if (dlg == NULL) return;
4213 
4214   s = (CDSGeneProtQualConstraintPtr) data;
4215   SetValue (dlg->constraint_type, 1);
4216   PointerToDialog (dlg->qual_present, NULL);
4217   PointerToDialog (dlg->qual_string, NULL);
4218   PointerToDialog (dlg->string_constraint, NULL);
4219   PointerToDialog (dlg->qualmatch1, NULL);
4220   PointerToDialog (dlg->qualmatch2, NULL);
4221   if (s != NULL) {
4222     if (s->field1 != NULL && s->field2 != NULL) {
4223       SetValue (dlg->constraint_type, 3);
4224       PointerToDialog (dlg->qualmatch1, s->field1);
4225       PointerToDialog (dlg->qualmatch2, s->field2);
4226     } else if ((s->field1 != NULL || s->field2 != NULL) && s->constraint != NULL) {
4227       SetValue (dlg->constraint_type, 2);
4228       if (s->field1 != NULL) {
4229         PointerToDialog (dlg->qual_string, s->field1);
4230       } else if (s->field2 != NULL) {
4231         PointerToDialog (dlg->qual_string, s->field2);
4232       }
4233       PointerToDialog (dlg->string_constraint, s->constraint);
4234     } else if (s->field1 != NULL || s->field2 != NULL) {
4235       SetValue (dlg->constraint_type, 1);
4236       if (s->field1 != NULL) {
4237         PointerToDialog (dlg->qual_present, s->field1);
4238       } else if (s->field2 != NULL) {
4239         PointerToDialog (dlg->qual_present, s->field2);
4240       }
4241     }
4242   }
4243   ChangeCDSGeneProtQualConstraintType (dlg->constraint_type);
4244 }
4245 
4246 
DialogToCDSGeneProtQualConstraint(DialoG d)4247 static Pointer DialogToCDSGeneProtQualConstraint (DialoG d)
4248 {
4249   CDSGeneProtQualConstraintDialogPtr dlg;
4250   CDSGeneProtQualConstraintPtr s = NULL;
4251   Int2                constraint_type;
4252   ValNodePtr          qual;
4253 
4254   dlg = (CDSGeneProtQualConstraintDialogPtr) GetObjectExtra (d);
4255   if (dlg == NULL) return NULL;
4256 
4257   constraint_type = GetValue (dlg->constraint_type);
4258   switch (constraint_type) {
4259     case 1:
4260       s = CDSGeneProtQualConstraintNew();
4261       qual = DialogToPointer (dlg->qual_present);
4262       if (qual != NULL) {
4263         ValNodeAddInt (&(s->field1), CDSGeneProtConstraintField_field, qual->data.intvalue);
4264       }
4265       break;
4266     case 2:
4267       s = CDSGeneProtQualConstraintNew();
4268       qual = DialogToPointer (dlg->qual_string);
4269       if (qual != NULL) {
4270         ValNodeAddInt (&(s->field1), CDSGeneProtConstraintField_field, qual->data.intvalue);
4271       }
4272       s->constraint = DialogToPointer (dlg->string_constraint);
4273       break;
4274     case 3:
4275       s = CDSGeneProtQualConstraintNew();
4276       qual = DialogToPointer (dlg->qualmatch1);
4277       if (qual != NULL) {
4278         ValNodeAddInt (&(s->field1), CDSGeneProtConstraintField_field, qual->data.intvalue);
4279       }
4280       qual = DialogToPointer (dlg->qualmatch2);
4281       if (qual != NULL) {
4282         ValNodeAddInt (&(s->field2), CDSGeneProtConstraintField_field, qual->data.intvalue);
4283       }
4284       break;
4285   }
4286   return s;
4287 }
4288 
4289 
TestCDSGeneProtQualConstraintDialog(DialoG d)4290 static ValNodePtr TestCDSGeneProtQualConstraintDialog (DialoG d)
4291 {
4292   CDSGeneProtQualConstraintPtr constraint;
4293   ValNodePtr err_list = NULL;
4294 
4295   constraint = DialogToPointer (d);
4296   if (IsCDSGeneProtQualConstraintEmpty (constraint)) {
4297     ValNodeAddPointer (&err_list, 0, "empty CDS-gene-prot qual constraint");
4298   }
4299   constraint = CDSGeneProtQualConstraintFree (constraint);
4300   return err_list;
4301 }
4302 
4303 
CDSGeneProtQualConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)4304 static DialoG CDSGeneProtQualConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
4305 
4306 {
4307   CDSGeneProtQualConstraintDialogPtr dlg;
4308   GrouP                     p, g;
4309   ButtoN                    b1, b2, b3;
4310 
4311   dlg = (CDSGeneProtQualConstraintDialogPtr) MemNew (sizeof (CDSGeneProtQualConstraintDialogData));
4312   if (dlg == NULL)
4313   {
4314     return NULL;
4315   }
4316 
4317   p = HiddenGroup (h, -1, 0, NULL);
4318   SetObjectExtra (p, dlg, StdCleanupExtraProc);
4319 
4320   dlg->dialog = (DialoG) p;
4321   dlg->todialog = CDSGeneProtQualConstraintToDialog;
4322   dlg->fromdialog = DialogToCDSGeneProtQualConstraint;
4323   dlg->testdialog = TestCDSGeneProtQualConstraintDialog;
4324 
4325   dlg->change_notify = change_notify;
4326   dlg->change_userdata = change_userdata;
4327 
4328   dlg->constraint_type = HiddenGroup (p, 3, 0, ChangeCDSGeneProtQualConstraintType);
4329   SetObjectExtra (dlg->constraint_type, dlg, NULL);
4330   b1 = RadioButton (dlg->constraint_type, "When qualifier present");
4331   b2 = RadioButton (dlg->constraint_type, "String constraint");
4332   b3 = RadioButton (dlg->constraint_type, "When qualifiers match");
4333 
4334   g = HiddenGroup (p, 0, 0, NULL);
4335 
4336   dlg->qual_present = CDSGeneProtFieldDialog (g, change_notify, change_userdata);
4337 
4338   dlg->sc_group = HiddenGroup (g, 2, 0, NULL);
4339   dlg->qual_string = CDSGeneProtFieldDialog (dlg->sc_group, change_notify, change_userdata);
4340   dlg->string_constraint = StringConstraintDialog (dlg->sc_group, NULL, FALSE, change_notify, change_userdata);
4341 
4342   dlg->match_group = HiddenGroup (g, 3, 0, NULL);
4343   dlg->qualmatch1 = CDSGeneProtFieldDialog (dlg->match_group, change_notify, change_userdata);
4344   StaticPrompt (dlg->match_group, "Equals", 0, dialogTextHeight, systemFont, 'l');
4345   dlg->qualmatch2 = CDSGeneProtFieldDialog (dlg->match_group, change_notify, change_userdata);
4346 
4347   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->qual_present, (HANDLE) dlg->sc_group, (HANDLE) dlg->match_group, NULL);
4348 
4349   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->constraint_type, (HANDLE) g, NULL);
4350   SetValue (dlg->constraint_type, 1);
4351   ChangeCDSGeneProtQualConstraintType (dlg->constraint_type);
4352   return (DialoG) p;
4353 }
4354 
4355 
4356 typedef struct sequencequaldlg {
4357   DIALOG_MESSAGE_BLOCK
4358   PopuP field_type;
4359   DialoG molecule_dlg;
4360   DialoG technique_dlg;
4361   DialoG completedness_dlg;
4362   DialoG mol_class_dlg;
4363   DialoG topology_dlg;
4364   DialoG strand_dlg;
4365 
4366   Nlm_ChangeNotifyProc change_notify;
4367   Pointer change_userdata;
4368 } SequenceQualDlgData, PNTR SequenceQualDlgPtr;
4369 
4370 
ChangeSequenceQualType(PopuP p)4371 static void ChangeSequenceQualType (PopuP p)
4372 {
4373   SequenceQualDlgPtr dlg;
4374   Int2               val;
4375 
4376   dlg = (SequenceQualDlgPtr) GetObjectExtra (p);
4377   if (dlg == NULL) return;
4378 
4379   Hide (dlg->molecule_dlg);
4380   Hide (dlg->technique_dlg);
4381   Hide (dlg->completedness_dlg);
4382   Hide (dlg->mol_class_dlg);
4383   Hide (dlg->topology_dlg);
4384   Hide (dlg->strand_dlg);
4385 
4386   val = GetValue (dlg->field_type);
4387   switch (val) {
4388     case 1:
4389       Show (dlg->molecule_dlg);
4390       break;
4391     case 2:
4392       Show (dlg->technique_dlg);
4393       break;
4394     case 3:
4395       Show (dlg->completedness_dlg);
4396       break;
4397     case 4:
4398       Show (dlg->mol_class_dlg);
4399       break;
4400     case 5:
4401       Show (dlg->topology_dlg);
4402       break;
4403     case 6:
4404       Show (dlg->strand_dlg);
4405       break;
4406   }
4407   if (dlg->change_notify != NULL) {
4408     (dlg->change_notify) (dlg->change_userdata);
4409   }
4410 }
4411 
4412 
SequenceQualToDialog(DialoG d,Pointer data)4413 static void SequenceQualToDialog (DialoG d, Pointer data)
4414 {
4415   SequenceQualDlgPtr dlg;
4416   ValNodePtr         field;
4417   ValNode            vn;
4418 
4419   dlg = (SequenceQualDlgPtr) GetObjectExtra (d);
4420   if (dlg == NULL) return;
4421 
4422   field = (ValNodePtr) data;
4423 
4424   if (field == NULL) {
4425     SetValue (dlg->field_type, 1);
4426     PointerToDialog (dlg->molecule_dlg, NULL);
4427   } else {
4428     vn.next = NULL;
4429     vn.data.ptrvalue = NULL;
4430 
4431     switch (field->choice) {
4432       case MolinfoField_molecule:
4433         SetValue (dlg->field_type, 1);
4434         vn.choice = field->data.intvalue;
4435         PointerToDialog (dlg->molecule_dlg, &vn);
4436         break;
4437       case MolinfoField_technique:
4438         SetValue (dlg->field_type, 2);
4439         vn.choice = field->data.intvalue;
4440         PointerToDialog (dlg->technique_dlg, &vn);
4441         break;
4442       case MolinfoField_completedness:
4443         SetValue (dlg->field_type, 3);
4444         vn.choice = field->data.intvalue;
4445         PointerToDialog (dlg->completedness_dlg, &vn);
4446         break;
4447       case MolinfoField_mol_class:
4448         SetValue (dlg->field_type, 4);
4449         vn.choice = field->data.intvalue;
4450         PointerToDialog (dlg->mol_class_dlg, &vn);
4451         break;
4452       case MolinfoField_topology:
4453         SetValue (dlg->field_type, 5);
4454         vn.choice = field->data.intvalue;
4455         PointerToDialog (dlg->topology_dlg, &vn);
4456         break;
4457       case MolinfoField_strand:
4458         SetValue (dlg->field_type, 6);
4459         vn.choice = field->data.intvalue;
4460         PointerToDialog (dlg->strand_dlg, &vn);
4461         break;
4462       default:
4463         SetValue (dlg->field_type, 1);
4464         PointerToDialog (dlg->molecule_dlg, NULL);
4465         break;
4466     }
4467   }
4468   ChangeSequenceQualType (dlg->field_type);
4469 }
4470 
4471 
DialogToSequenceQual(DialoG d)4472 static Pointer DialogToSequenceQual (DialoG d)
4473 {
4474   SequenceQualDlgPtr dlg;
4475   ValNodePtr         field = NULL, vnp;
4476   Int2               val;
4477 
4478   dlg = (SequenceQualDlgPtr) GetObjectExtra (d);
4479   if (dlg == NULL) return NULL;
4480 
4481   val = GetValue (dlg->field_type);
4482   switch (val) {
4483     case 1:
4484       vnp = DialogToPointer (dlg->molecule_dlg);
4485       if (vnp != NULL) {
4486         field = ValNodeNew (NULL);
4487         field->choice = MolinfoField_molecule;
4488         field->data.intvalue = vnp->choice;
4489         vnp = ValNodeFree (vnp);
4490       }
4491       break;
4492     case 2:
4493       vnp = DialogToPointer (dlg->technique_dlg);
4494       if (vnp != NULL) {
4495         field = ValNodeNew (NULL);
4496         field->choice = MolinfoField_technique;
4497         field->data.intvalue = vnp->choice;
4498         vnp = ValNodeFree (vnp);
4499       }
4500       break;
4501     case 3:
4502       vnp = DialogToPointer (dlg->completedness_dlg);
4503       if (vnp != NULL) {
4504         field = ValNodeNew (NULL);
4505         field->choice = MolinfoField_completedness;
4506         field->data.intvalue = vnp->choice;
4507         vnp = ValNodeFree (vnp);
4508       }
4509       break;
4510     case 4:
4511       vnp = DialogToPointer (dlg->mol_class_dlg);
4512       if (vnp != NULL) {
4513         field = ValNodeNew (NULL);
4514         field->choice = MolinfoField_mol_class;
4515         field->data.intvalue = vnp->choice;
4516         vnp = ValNodeFree (vnp);
4517       }
4518       break;
4519     case 5:
4520       vnp = DialogToPointer (dlg->topology_dlg);
4521       if (vnp != NULL) {
4522         field = ValNodeNew (NULL);
4523         field->choice = MolinfoField_topology;
4524         field->data.intvalue = vnp->choice;
4525         vnp = ValNodeFree (vnp);
4526       }
4527       break;
4528     case 6:
4529       vnp = DialogToPointer (dlg->strand_dlg);
4530       if (vnp != NULL) {
4531         field = ValNodeNew (NULL);
4532         field->choice = MolinfoField_strand;
4533         field->data.intvalue = vnp->choice;
4534         vnp = ValNodeFree (vnp);
4535       }
4536       break;
4537   }
4538 
4539   return field;
4540 
4541 }
4542 
4543 
TestSequenceQualDialog(DialoG d)4544 static ValNodePtr TestSequenceQualDialog (DialoG d)
4545 {
4546   SequenceQualDlgPtr dlg;
4547   Int2               val;
4548   ValNodePtr         err_list = NULL;
4549 
4550   dlg = (SequenceQualDlgPtr) GetObjectExtra (d);
4551   if (dlg == NULL) return NULL;
4552 
4553   val = GetValue (dlg->field_type);
4554   if (val < 1 || val > 6) {
4555   }
4556   switch (val) {
4557     case 1:
4558       err_list = TestDialog (dlg->molecule_dlg);
4559       break;
4560     case 2:
4561       err_list = TestDialog (dlg->technique_dlg);
4562       break;
4563     case 3:
4564       err_list = TestDialog (dlg->completedness_dlg);
4565       break;
4566     case 4:
4567       err_list = TestDialog (dlg->mol_class_dlg);
4568       break;
4569     case 5:
4570       err_list = TestDialog (dlg->topology_dlg);
4571       break;
4572     case 6:
4573       err_list = TestDialog (dlg->strand_dlg);
4574       break;
4575     default:
4576       ValNodeAddPointer (&err_list, 0, "field type");
4577       break;
4578   }
4579 
4580   return err_list;
4581 }
4582 
4583 
SequenceQualDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)4584 static DialoG SequenceQualDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
4585 
4586 {
4587   SequenceQualDlgPtr dlg;
4588   GrouP              p, g;
4589   ValNodePtr         val_list;
4590 
4591   dlg = (SequenceQualDlgPtr) MemNew (sizeof (SequenceQualDlgData));
4592   if (dlg == NULL)
4593   {
4594     return NULL;
4595   }
4596 
4597   p = HiddenGroup (h, -1, 0, NULL);
4598   SetObjectExtra (p, dlg, StdCleanupExtraProc);
4599 
4600   dlg->dialog = (DialoG) p;
4601   dlg->todialog = SequenceQualToDialog;
4602   dlg->fromdialog = DialogToSequenceQual;
4603   dlg->testdialog = TestSequenceQualDialog;
4604 
4605   dlg->change_notify = change_notify;
4606   dlg->change_userdata = change_userdata;
4607 
4608   dlg->field_type = PopupList (p, TRUE, ChangeSequenceQualType);
4609   SetObjectExtra (dlg->field_type, dlg, NULL);
4610   PopupItem (dlg->field_type, "molecule");
4611   PopupItem (dlg->field_type, "technique");
4612   PopupItem (dlg->field_type, "completedness");
4613   PopupItem (dlg->field_type, "class");
4614   PopupItem (dlg->field_type, "topology");
4615   PopupItem (dlg->field_type, "strand");
4616   SetValue (dlg->field_type, 1);
4617 
4618   g = HiddenGroup (p, 0, 0, NULL);
4619 
4620   val_list = GetMoleculeTypeList ();
4621   dlg->molecule_dlg = ValNodeSelectionDialog (g, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
4622                                            ValNodeSimpleDataFree, ValNodeStringCopy,
4623                                            ValNodeChoiceMatch, "location",
4624                                            change_notify, change_userdata, FALSE);
4625   val_list = GetTechniqueTypeList ();
4626   dlg->technique_dlg = ValNodeSelectionDialog (g, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
4627                                            ValNodeSimpleDataFree, ValNodeStringCopy,
4628                                            ValNodeChoiceMatch, "location",
4629                                            change_notify, change_userdata, FALSE);
4630   val_list = GetCompletednessTypeList ();
4631   dlg->completedness_dlg = ValNodeSelectionDialog (g, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
4632                                            ValNodeSimpleDataFree, ValNodeStringCopy,
4633                                            ValNodeChoiceMatch, "location",
4634                                            change_notify, change_userdata, FALSE);
4635   val_list = GetMoleculeClassTypeList ();
4636   dlg->mol_class_dlg = ValNodeSelectionDialog (g, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
4637                                            ValNodeSimpleDataFree, ValNodeStringCopy,
4638                                            ValNodeChoiceMatch, "location",
4639                                            change_notify, change_userdata, FALSE);
4640   val_list = GetTopologyTypeList ();
4641   dlg->topology_dlg = ValNodeSelectionDialog (g, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
4642                                            ValNodeSimpleDataFree, ValNodeStringCopy,
4643                                            ValNodeChoiceMatch, "location",
4644                                            change_notify, change_userdata, FALSE);
4645   val_list = GetStrandTypeList ();
4646   dlg->strand_dlg = ValNodeSelectionDialog (g, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
4647                                            ValNodeSimpleDataFree, ValNodeStringCopy,
4648                                            ValNodeChoiceMatch, "location",
4649                                            change_notify, change_userdata, FALSE);
4650 
4651   AlignObjects (ALIGN_MIDDLE, (HANDLE) dlg->molecule_dlg,
4652                               (HANDLE) dlg->technique_dlg,
4653                               (HANDLE) dlg->completedness_dlg,
4654                               (HANDLE) dlg->mol_class_dlg,
4655                               (HANDLE) dlg->topology_dlg,
4656                               (HANDLE) dlg->strand_dlg,
4657                               NULL);
4658 
4659   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->field_type, (HANDLE) g, NULL);
4660   ChangeSequenceQualType (dlg->field_type);
4661   return (DialoG) p;
4662 }
4663 
4664 
4665 typedef struct sequencequalpairdlg {
4666   DIALOG_MESSAGE_BLOCK
4667   PopuP field_type;
4668   GrouP molecule_grp;
4669   DialoG molecule_from_dlg;
4670   DialoG molecule_to_dlg;
4671   GrouP technique_grp;
4672   DialoG technique_from_dlg;
4673   DialoG technique_to_dlg;
4674   GrouP completedness_grp;
4675   DialoG completedness_from_dlg;
4676   DialoG completedness_to_dlg;
4677   GrouP mol_class_grp;
4678   DialoG mol_class_from_dlg;
4679   DialoG mol_class_to_dlg;
4680   GrouP topology_grp;
4681   DialoG topology_from_dlg;
4682   DialoG topology_to_dlg;
4683   GrouP strand_grp;
4684   DialoG strand_from_dlg;
4685   DialoG strand_to_dlg;
4686 
4687   Nlm_ChangeNotifyProc change_notify;
4688   Pointer change_userdata;
4689 } SequenceQualPairDlgData, PNTR SequenceQualPairDlgPtr;
4690 
4691 
ChangeSequenceQualPairType(PopuP p)4692 static void ChangeSequenceQualPairType (PopuP p)
4693 {
4694   SequenceQualPairDlgPtr dlg;
4695   Int2                   val;
4696 
4697   dlg = (SequenceQualPairDlgPtr) GetObjectExtra (p);
4698   if (dlg == NULL) return;
4699 
4700   Hide (dlg->molecule_grp);
4701   Hide (dlg->technique_grp);
4702   Hide (dlg->completedness_grp);
4703   Hide (dlg->mol_class_grp);
4704   Hide (dlg->topology_grp);
4705   Hide (dlg->strand_grp);
4706 
4707   val = GetValue (dlg->field_type);
4708   switch (val) {
4709     case 1:
4710       Show (dlg->molecule_grp);
4711       break;
4712     case 2:
4713       Show (dlg->technique_grp);
4714       break;
4715     case 3:
4716       Show (dlg->completedness_grp);
4717       break;
4718     case 4:
4719       Show (dlg->mol_class_grp);
4720       break;
4721     case 5:
4722       Show (dlg->topology_grp);
4723       break;
4724     case 6:
4725       Show (dlg->strand_grp);
4726       break;
4727   }
4728   if (dlg->change_notify != NULL) {
4729     (dlg->change_notify) (dlg->change_userdata);
4730   }
4731 }
4732 
4733 
SequenceQualPairToDialog(DialoG d,Pointer data)4734 static void SequenceQualPairToDialog (DialoG d, Pointer data)
4735 {
4736   SequenceQualPairDlgPtr dlg;
4737   ValNodePtr m_fields;
4738   ValNode    vn;
4739 
4740   dlg = (SequenceQualPairDlgPtr) GetObjectExtra (d);
4741   if (dlg == NULL) return;
4742 
4743   m_fields = (ValNodePtr) data;
4744   if (m_fields == NULL) {
4745     SetValue (dlg->field_type, 1);
4746     PointerToDialog (dlg->molecule_from_dlg, NULL);
4747     PointerToDialog (dlg->molecule_to_dlg, NULL);
4748   } else {
4749     vn.data.ptrvalue = NULL;
4750     vn.next = NULL;
4751     switch (m_fields->choice) {
4752       case MolinfoFieldPair_molecule:
4753         SetValue (dlg->field_type, 1);
4754         if (m_fields->data.ptrvalue == NULL) {
4755           PointerToDialog (dlg->molecule_from_dlg, NULL);
4756           PointerToDialog (dlg->molecule_to_dlg, NULL);
4757         } else {
4758           vn.choice = (Uint1)((MolinfoMoleculePairPtr) m_fields->data.ptrvalue)->from;
4759           PointerToDialog (dlg->molecule_from_dlg, &vn);
4760           vn.choice = (Uint1)((MolinfoMoleculePairPtr) m_fields->data.ptrvalue)->to;
4761           PointerToDialog (dlg->molecule_to_dlg, &vn);
4762         }
4763         break;
4764       case MolinfoFieldPair_technique:
4765         SetValue (dlg->field_type, 2);
4766         if (m_fields->data.ptrvalue == NULL) {
4767           PointerToDialog (dlg->technique_from_dlg, NULL);
4768           PointerToDialog (dlg->technique_to_dlg, NULL);
4769         } else {
4770           vn.choice = (Uint1)((MolinfoTechniquePairPtr) m_fields->data.ptrvalue)->from;
4771           PointerToDialog (dlg->technique_from_dlg, &vn);
4772           vn.choice = (Uint1)((MolinfoTechniquePairPtr) m_fields->data.ptrvalue)->to;
4773           PointerToDialog (dlg->technique_to_dlg, &vn);
4774         }
4775         break;
4776       case MolinfoFieldPair_completedness:
4777         SetValue (dlg->field_type, 3);
4778         if (m_fields->data.ptrvalue == NULL) {
4779           PointerToDialog (dlg->completedness_from_dlg, NULL);
4780           PointerToDialog (dlg->completedness_to_dlg, NULL);
4781         } else {
4782           vn.choice = (Uint1)((MolinfoCompletednessPairPtr) m_fields->data.ptrvalue)->from;
4783           PointerToDialog (dlg->completedness_from_dlg, &vn);
4784           vn.choice = (Uint1)((MolinfoCompletednessPairPtr) m_fields->data.ptrvalue)->to;
4785           PointerToDialog (dlg->completedness_to_dlg, &vn);
4786         }
4787         break;
4788       case MolinfoFieldPair_mol_class:
4789         SetValue (dlg->field_type, 4);
4790         if (m_fields->data.ptrvalue == NULL) {
4791           PointerToDialog (dlg->mol_class_from_dlg, NULL);
4792           PointerToDialog (dlg->mol_class_to_dlg, NULL);
4793         } else {
4794           vn.choice = (Uint1)((MolinfoMolClassPairPtr) m_fields->data.ptrvalue)->from;
4795           PointerToDialog (dlg->mol_class_from_dlg, &vn);
4796           vn.choice = (Uint1)((MolinfoMolClassPairPtr) m_fields->data.ptrvalue)->to;
4797           PointerToDialog (dlg->mol_class_to_dlg, &vn);
4798         }
4799         break;
4800       case MolinfoFieldPair_topology:
4801         SetValue (dlg->field_type, 5);
4802         if (m_fields->data.ptrvalue == NULL) {
4803           PointerToDialog (dlg->topology_from_dlg, NULL);
4804           PointerToDialog (dlg->topology_to_dlg, NULL);
4805         } else {
4806           vn.choice = (Uint1)((MolinfoTopologyPairPtr) m_fields->data.ptrvalue)->from;
4807           PointerToDialog (dlg->topology_from_dlg, &vn);
4808           vn.choice = (Uint1)((MolinfoTopologyPairPtr) m_fields->data.ptrvalue)->to;
4809           PointerToDialog (dlg->topology_to_dlg, &vn);
4810         }
4811         break;
4812       case MolinfoFieldPair_strand:
4813         SetValue (dlg->field_type, 6);
4814         if (m_fields->data.ptrvalue == NULL) {
4815           PointerToDialog (dlg->strand_from_dlg, NULL);
4816           PointerToDialog (dlg->strand_to_dlg, NULL);
4817         } else {
4818           vn.choice = (Uint1)((MolinfoStrandPairPtr) m_fields->data.ptrvalue)->from;
4819           PointerToDialog (dlg->strand_from_dlg, &vn);
4820           vn.choice = (Uint1)((MolinfoStrandPairPtr) m_fields->data.ptrvalue)->to;
4821           PointerToDialog (dlg->strand_to_dlg, &vn);
4822         }
4823         break;
4824       default:
4825         SetValue (dlg->field_type, 1);
4826         PointerToDialog (dlg->molecule_from_dlg, NULL);
4827         PointerToDialog (dlg->molecule_to_dlg, NULL);
4828         break;
4829     }
4830   }
4831 }
4832 
4833 
DialogToSequenceQualPair(DialoG d)4834 static Pointer DialogToSequenceQualPair (DialoG d)
4835 {
4836   SequenceQualPairDlgPtr dlg;
4837   Int2                   val;
4838   ValNodePtr             field = NULL, vnp_from, vnp_to;
4839   MolinfoMoleculePairPtr mol;
4840   MolinfoTechniquePairPtr tech;
4841   MolinfoCompletednessPairPtr comp;
4842   MolinfoMolClassPairPtr mol_class;
4843   MolinfoTopologyPairPtr topology;
4844   MolinfoStrandPairPtr   strand;
4845 
4846   dlg = (SequenceQualPairDlgPtr) GetObjectExtra (d);
4847   if (dlg == NULL) return NULL;
4848 
4849   val = GetValue (dlg->field_type);
4850   switch (val) {
4851     case 1:
4852       field = ValNodeNew (NULL);
4853       field->choice = MolinfoFieldPair_molecule;
4854       vnp_from = DialogToPointer (dlg->molecule_from_dlg);
4855       vnp_to = DialogToPointer (dlg->molecule_to_dlg);
4856       mol = MolinfoMoleculePairNew ();
4857       field->data.ptrvalue = mol;
4858       if (vnp_from != NULL) {
4859         mol->from = vnp_from->choice;
4860         vnp_from = ValNodeFree (vnp_from);
4861       }
4862       if (vnp_to != NULL) {
4863         mol->to = vnp_to->choice;
4864         vnp_to = ValNodeFree (vnp_to);
4865       }
4866       break;
4867     case 2:
4868       field = ValNodeNew (NULL);
4869       field->choice = MolinfoFieldPair_technique;
4870       tech = MolinfoTechniquePairNew ();
4871       field->data.ptrvalue = tech;
4872       vnp_from = DialogToPointer (dlg->technique_from_dlg);
4873       vnp_to = DialogToPointer (dlg->technique_to_dlg);
4874       if (vnp_from != NULL) {
4875         tech->from = vnp_from->choice;
4876         vnp_from = ValNodeFree (vnp_from);
4877       }
4878       if (vnp_to != NULL) {
4879         tech->to = vnp_to->choice;
4880         vnp_to = ValNodeFree (vnp_to);
4881       }
4882       break;
4883     case 3:
4884       field = ValNodeNew (NULL);
4885       field->choice = MolinfoFieldPair_completedness;
4886       comp = MolinfoCompletednessPairNew ();
4887       field->data.ptrvalue = comp;
4888       vnp_from = DialogToPointer (dlg->completedness_from_dlg);
4889       vnp_to = DialogToPointer (dlg->completedness_to_dlg);
4890       if (vnp_from != NULL) {
4891         comp->from = vnp_from->choice;
4892         vnp_from = ValNodeFree (vnp_from);
4893       }
4894       if (vnp_to != NULL) {
4895         comp->to = vnp_to->choice;
4896         vnp_to = ValNodeFree (vnp_to);
4897       }
4898       break;
4899     case 4:
4900       field = ValNodeNew (NULL);
4901       field->choice = MolinfoFieldPair_technique;
4902       mol_class = MolinfoMolClassPairNew ();
4903       field->data.ptrvalue = mol_class;
4904       vnp_from = DialogToPointer (dlg->mol_class_from_dlg);
4905       vnp_to = DialogToPointer (dlg->mol_class_to_dlg);
4906       if (vnp_from != NULL) {
4907         mol_class->from = vnp_from->choice;
4908         vnp_from = ValNodeFree (vnp_from);
4909       }
4910       if (vnp_to != NULL) {
4911         mol_class->to = vnp_to->choice;
4912         vnp_to = ValNodeFree (vnp_to);
4913       }
4914       break;
4915     case 5:
4916       field = ValNodeNew (NULL);
4917       field->choice = MolinfoFieldPair_topology;
4918       topology = MolinfoTopologyPairNew ();
4919       field->data.ptrvalue = topology;
4920       vnp_from = DialogToPointer (dlg->topology_from_dlg);
4921       vnp_to = DialogToPointer (dlg->topology_to_dlg);
4922       if (vnp_from != NULL) {
4923         topology->from = vnp_from->choice;
4924         vnp_from = ValNodeFree (vnp_from);
4925       }
4926       if (vnp_to != NULL) {
4927         topology->to = vnp_to->choice;
4928         vnp_to = ValNodeFree (vnp_to);
4929       }
4930       break;
4931     case 6:
4932       field = ValNodeNew (NULL);
4933       field->choice = MolinfoFieldPair_strand;
4934       strand = MolinfoStrandPairNew ();
4935       field->data.ptrvalue = strand;
4936       vnp_from = DialogToPointer (dlg->strand_from_dlg);
4937       vnp_to = DialogToPointer (dlg->strand_to_dlg);
4938       if (vnp_from != NULL) {
4939         strand->from = vnp_from->choice;
4940         vnp_from = ValNodeFree (vnp_from);
4941       }
4942       if (vnp_to != NULL) {
4943         strand->to = vnp_to->choice;
4944         vnp_to = ValNodeFree (vnp_to);
4945       }
4946       break;
4947   }
4948   return field;
4949 }
4950 
4951 
TestSequenceQualPairDialog(DialoG d)4952 static ValNodePtr TestSequenceQualPairDialog (DialoG d)
4953 {
4954   ValNodePtr err_list = NULL, field;
4955   MolinfoMoleculePairPtr mol;
4956   MolinfoTechniquePairPtr tech;
4957   MolinfoCompletednessPairPtr comp;
4958   MolinfoMolClassPairPtr mol_class;
4959   MolinfoTopologyPairPtr topology;
4960   MolinfoStrandPairPtr   strand;
4961 
4962   field = DialogToPointer (d);
4963   if (field == NULL) {
4964     ValNodeAddPointer (&err_list, 0, "field");
4965   } else {
4966     switch (field->choice) {
4967       case MolinfoFieldPair_molecule:
4968         mol = (MolinfoMoleculePairPtr) field->data.ptrvalue;
4969         if (mol == NULL || mol->from == mol->to) {
4970           ValNodeAddPointer (&err_list, 0, "value");
4971         }
4972         break;
4973       case MolinfoFieldPair_technique:
4974         tech = (MolinfoTechniquePairPtr) field->data.ptrvalue;
4975         if (tech == NULL || tech->from == tech->to) {
4976           ValNodeAddPointer (&err_list, 0, "value");
4977         }
4978         break;
4979       case MolinfoFieldPair_completedness:
4980         comp = (MolinfoCompletednessPairPtr) field->data.ptrvalue;
4981         if (comp == NULL || comp->from == comp->to) {
4982           ValNodeAddPointer (&err_list, 0, "value");
4983         }
4984         break;
4985       case MolinfoFieldPair_mol_class:
4986         mol_class = (MolinfoMolClassPairPtr) field->data.ptrvalue;
4987         if (mol_class == NULL) {
4988           ValNodeAddPointer (&err_list, 0, "value");
4989         }
4990         break;
4991       case MolinfoFieldPair_topology:
4992         topology = (MolinfoTopologyPairPtr) field->data.ptrvalue;
4993         if (topology == NULL || topology->from == topology->to) {
4994           ValNodeAddPointer (&err_list, 0, "value");
4995         }
4996         break;
4997       case MolinfoFieldPair_strand:
4998         strand = (MolinfoStrandPairPtr) field->data.ptrvalue;
4999         if (strand == NULL || strand->from == strand->to) {
5000           ValNodeAddPointer (&err_list, 0, "value");
5001         }
5002         break;
5003       default:
5004         ValNodeAddPointer (&err_list, 0, "type");
5005         break;
5006     }
5007     field = MolinfoFieldPairFree (field);
5008   }
5009 
5010   return err_list;
5011 }
5012 
5013 
SequenceQualPairDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)5014 static DialoG SequenceQualPairDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
5015 
5016 {
5017   SequenceQualPairDlgPtr dlg;
5018   GrouP                  p, g;
5019   ValNodePtr             val_list;
5020 
5021   dlg = (SequenceQualPairDlgPtr) MemNew (sizeof (SequenceQualPairDlgData));
5022   if (dlg == NULL)
5023   {
5024     return NULL;
5025   }
5026 
5027   p = HiddenGroup (h, -1, 0, NULL);
5028   SetObjectExtra (p, dlg, StdCleanupExtraProc);
5029 
5030   dlg->dialog = (DialoG) p;
5031   dlg->todialog = SequenceQualPairToDialog;
5032   dlg->fromdialog = DialogToSequenceQualPair;
5033   dlg->testdialog = TestSequenceQualPairDialog;
5034 
5035   dlg->change_notify = change_notify;
5036   dlg->change_userdata = change_userdata;
5037 
5038   dlg->field_type = PopupList (p, TRUE, ChangeSequenceQualPairType);
5039   SetObjectExtra (dlg->field_type, dlg, NULL);
5040   PopupItem (dlg->field_type, "molecule");
5041   PopupItem (dlg->field_type, "technique");
5042   PopupItem (dlg->field_type, "completedness");
5043   PopupItem (dlg->field_type, "class");
5044   PopupItem (dlg->field_type, "topology");
5045   PopupItem (dlg->field_type, "strand");
5046   SetValue (dlg->field_type, 1);
5047 
5048   g = HiddenGroup (p, 0, 0, NULL);
5049 
5050   dlg->molecule_grp = HiddenGroup (g, 2, 0, NULL);
5051   StaticPrompt (dlg->molecule_grp, "From", 0, dialogTextHeight, programFont, 'l');
5052   StaticPrompt (dlg->molecule_grp, "To", 0, dialogTextHeight, programFont, 'l');
5053   val_list = GetMoleculeTypeList ();
5054   dlg->molecule_from_dlg = ValNodeSelectionDialog (dlg->molecule_grp, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5055                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5056                                            ValNodeChoiceMatch, "location",
5057                                            change_notify, change_userdata, FALSE);
5058   val_list = GetMoleculeTypeList ();
5059   dlg->molecule_to_dlg = ValNodeSelectionDialog (dlg->molecule_grp, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5060                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5061                                            ValNodeChoiceMatch, "location",
5062                                            change_notify, change_userdata, FALSE);
5063 
5064   dlg->technique_grp = HiddenGroup (g, 2, 0, NULL);
5065   StaticPrompt (dlg->technique_grp, "From", 0, dialogTextHeight, programFont, 'l');
5066   StaticPrompt (dlg->technique_grp, "To", 0, dialogTextHeight, programFont, 'l');
5067   val_list = GetTechniqueTypeList ();
5068   dlg->technique_from_dlg = ValNodeSelectionDialog (dlg->technique_grp, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5069                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5070                                            ValNodeChoiceMatch, "location",
5071                                            change_notify, change_userdata, FALSE);
5072   val_list = GetTechniqueTypeList ();
5073   dlg->technique_to_dlg = ValNodeSelectionDialog (dlg->technique_grp, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5074                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5075                                            ValNodeChoiceMatch, "location",
5076                                            change_notify, change_userdata, FALSE);
5077 
5078   dlg->completedness_grp = HiddenGroup (g, 2, 0, NULL);
5079   StaticPrompt (dlg->completedness_grp, "From", 0, dialogTextHeight, programFont, 'l');
5080   StaticPrompt (dlg->completedness_grp, "To", 0, dialogTextHeight, programFont, 'l');
5081   val_list = GetCompletednessTypeList ();
5082   dlg->completedness_from_dlg = ValNodeSelectionDialog (dlg->completedness_grp, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5083                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5084                                            ValNodeChoiceMatch, "location",
5085                                            change_notify, change_userdata, FALSE);
5086   val_list = GetCompletednessTypeList ();
5087   dlg->completedness_to_dlg = ValNodeSelectionDialog (dlg->completedness_grp, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5088                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5089                                            ValNodeChoiceMatch, "location",
5090                                            change_notify, change_userdata, FALSE);
5091 
5092   dlg->mol_class_grp = HiddenGroup (g, 2, 0, NULL);
5093   StaticPrompt (dlg->mol_class_grp, "From", 0, dialogTextHeight, programFont, 'l');
5094   StaticPrompt (dlg->mol_class_grp, "To", 0, dialogTextHeight, programFont, 'l');
5095   val_list = GetMoleculeClassTypeList ();
5096   dlg->mol_class_from_dlg = ValNodeSelectionDialog (dlg->mol_class_grp, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5097                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5098                                            ValNodeChoiceMatch, "location",
5099                                            change_notify, change_userdata, FALSE);
5100   val_list = GetMoleculeClassTypeList ();
5101   dlg->mol_class_to_dlg = ValNodeSelectionDialog (dlg->mol_class_grp, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5102                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5103                                            ValNodeChoiceMatch, "location",
5104                                            change_notify, change_userdata, FALSE);
5105 
5106   dlg->topology_grp = HiddenGroup (g, 2, 0, NULL);
5107   StaticPrompt (dlg->topology_grp, "From", 0, dialogTextHeight, programFont, 'l');
5108   StaticPrompt (dlg->topology_grp, "To", 0, dialogTextHeight, programFont, 'l');
5109   val_list = GetTopologyTypeList ();
5110   dlg->topology_from_dlg = ValNodeSelectionDialog (dlg->topology_grp, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5111                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5112                                            ValNodeChoiceMatch, "location",
5113                                            change_notify, change_userdata, FALSE);
5114   val_list = GetTopologyTypeList ();
5115   dlg->topology_to_dlg = ValNodeSelectionDialog (dlg->topology_grp, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5116                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5117                                            ValNodeChoiceMatch, "location",
5118                                            change_notify, change_userdata, FALSE);
5119 
5120   dlg->strand_grp = HiddenGroup (g, 2, 0, NULL);
5121   StaticPrompt (dlg->strand_grp, "From", 0, dialogTextHeight, programFont, 'l');
5122   StaticPrompt (dlg->strand_grp, "To", 0, dialogTextHeight, programFont, 'l');
5123 
5124   val_list = GetStrandTypeList ();
5125   dlg->strand_from_dlg = ValNodeSelectionDialog (dlg->strand_grp, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5126                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5127                                            ValNodeChoiceMatch, "location",
5128                                            change_notify, change_userdata, FALSE);
5129   val_list = GetStrandTypeList ();
5130   dlg->strand_to_dlg = ValNodeSelectionDialog (dlg->strand_grp, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5131                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5132                                            ValNodeChoiceMatch, "location",
5133                                            change_notify, change_userdata, FALSE);
5134 
5135   AlignObjects (ALIGN_MIDDLE, (HANDLE) dlg->molecule_grp,
5136                               (HANDLE) dlg->technique_grp,
5137                               (HANDLE) dlg->completedness_grp,
5138                               (HANDLE) dlg->mol_class_grp,
5139                               (HANDLE) dlg->topology_grp,
5140                               (HANDLE) dlg->strand_grp,
5141                               NULL);
5142 
5143   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->field_type, (HANDLE) g, NULL);
5144   ChangeSequenceQualPairType (dlg->field_type);
5145   return (DialoG) p;
5146 }
5147 
5148 
5149 static CharPtr  molinfo_block_labels [] = {
5150   "Molecule", "Technique", "Completedness",
5151   "Class", "Topology", "Strand", NULL
5152 };
5153 
5154 typedef struct molinfoblocklistdlg {
5155   DIALOG_MESSAGE_BLOCK
5156 
5157   DialoG molecule;
5158   DialoG technique;
5159   DialoG completedness;
5160   DialoG mol_class;
5161   DialoG topology;
5162   DialoG strand;
5163 
5164   Nlm_ChangeNotifyProc change_notify;
5165   Pointer change_userdata;
5166 } MolInfoBlockListDlgData, PNTR MolInfoBlockListDlgPtr;
5167 
5168 
MolInfoBlockListToDialog(DialoG d,Pointer data)5169 static void MolInfoBlockListToDialog (DialoG d, Pointer data)
5170 {
5171   MolInfoBlockListDlgPtr dlg;
5172   ValNodePtr         mol_fields, vnp;
5173   ValNode            val;
5174 
5175   dlg = (MolInfoBlockListDlgPtr) GetObjectExtra (d);
5176   if (dlg == NULL) {
5177     return;
5178   }
5179 
5180   mol_fields = (ValNodePtr) data;
5181 
5182   vnp = ValNodeNew(NULL);
5183   vnp->choice = 255;
5184   vnp->data.ptrvalue = StringSave ("any");
5185 
5186   PointerToDialog (dlg->molecule, vnp);
5187   PointerToDialog (dlg->technique, vnp);
5188   PointerToDialog (dlg->completedness, vnp);
5189   PointerToDialog (dlg->mol_class, vnp);
5190   PointerToDialog (dlg->topology, vnp);
5191   PointerToDialog (dlg->strand, vnp);
5192 
5193   vnp = ValNodeFreeData (vnp);
5194   MemSet (&val, 0, sizeof (ValNode));
5195 
5196   for (vnp = mol_fields; vnp != NULL; vnp = vnp->next) {
5197     val.choice = vnp->data.intvalue;
5198     switch (vnp->choice) {
5199       case MolinfoField_molecule:
5200         PointerToDialog (dlg->molecule, &val);
5201         break;
5202       case MolinfoField_technique:
5203         PointerToDialog (dlg->technique, &val);
5204         break;
5205       case MolinfoField_completedness:
5206         PointerToDialog (dlg->completedness, &val);
5207         break;
5208       case MolinfoField_mol_class:
5209         PointerToDialog (dlg->mol_class, &val);
5210         break;
5211       case MolinfoField_topology:
5212         PointerToDialog (dlg->topology, &val);
5213         break;
5214       case MolinfoField_strand:
5215         PointerToDialog (dlg->strand, &val);
5216         break;
5217     }
5218   }
5219 }
5220 
5221 
MolInfoBlockListFromDialog(DialoG d)5222 static Pointer MolInfoBlockListFromDialog (DialoG d)
5223 {
5224   MolInfoBlockListDlgPtr dlg;
5225   ValNodePtr         mol_fields = NULL, vnp;
5226 
5227   dlg = (MolInfoBlockListDlgPtr) GetObjectExtra (d);
5228   if (dlg == NULL) {
5229     return NULL;
5230   }
5231 
5232   vnp = DialogToPointer (dlg->molecule);
5233   if (vnp != NULL && vnp->choice != 255) {
5234     ValNodeAddInt (&mol_fields, MolinfoField_molecule, vnp->choice);
5235   }
5236   vnp = ValNodeFree (vnp);
5237 
5238   vnp = DialogToPointer (dlg->technique);
5239   if (vnp != NULL && vnp->choice != 255) {
5240     ValNodeAddInt (&mol_fields, MolinfoField_technique, vnp->choice);
5241   }
5242   vnp = ValNodeFree (vnp);
5243 
5244   vnp = DialogToPointer (dlg->completedness);
5245   if (vnp != NULL && vnp->choice != 255) {
5246     ValNodeAddInt (&mol_fields, MolinfoField_completedness, vnp->choice);
5247   }
5248   vnp = ValNodeFree (vnp);
5249 
5250   vnp = DialogToPointer (dlg->mol_class);
5251   if (vnp != NULL && vnp->choice != 255) {
5252     ValNodeAddInt (&mol_fields, MolinfoField_mol_class, vnp->choice);
5253   }
5254   vnp = ValNodeFree (vnp);
5255 
5256   vnp = DialogToPointer (dlg->topology);
5257   if (vnp != NULL && vnp->choice != 255) {
5258     ValNodeAddInt (&mol_fields, MolinfoField_topology, vnp->choice);
5259   }
5260   vnp = ValNodeFree (vnp);
5261 
5262   vnp = DialogToPointer (dlg->strand);
5263   if (vnp != NULL && vnp->choice != 255) {
5264     ValNodeAddInt (&mol_fields, MolinfoField_strand, vnp->choice);
5265   }
5266   vnp = ValNodeFree (vnp);
5267 
5268   return (Pointer) mol_fields;
5269 }
5270 
5271 
MolInfoBlockListDialog(GrouP h,CharPtr any_name,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)5272 static DialoG MolInfoBlockListDialog (GrouP h, CharPtr any_name, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
5273 {
5274   MolInfoBlockListDlgPtr dlg;
5275   GrouP                  p;
5276   Int2                   wid;
5277   ValNodePtr             val_list, vnp;
5278 
5279   dlg = (MolInfoBlockListDlgPtr) MemNew (sizeof (MolInfoBlockListDlgData));
5280   if (dlg == NULL)
5281   {
5282     return NULL;
5283   }
5284 
5285   p = HiddenGroup (h, 2, 0, NULL);
5286   SetObjectExtra (p, dlg, StdCleanupExtraProc);
5287 
5288   dlg->dialog = (DialoG) p;
5289   dlg->todialog = MolInfoBlockListToDialog;
5290   dlg->fromdialog = MolInfoBlockListFromDialog;
5291 
5292   dlg->change_notify = change_notify;
5293   dlg->change_userdata = change_userdata;
5294 
5295   SelectFont (programFont);
5296   wid = MaxStringWidths (molinfo_block_labels);
5297   SelectFont (systemFont);
5298 
5299   /* molecule */
5300   StaticPrompt (p, molinfo_block_labels[0], wid, popupMenuHeight, programFont, 'l');
5301   val_list = GetMoleculeTypeList ();
5302   if (any_name != NULL) {
5303     vnp = ValNodeNew (NULL);
5304     vnp->choice = 255;
5305     vnp->data.ptrvalue = StringSave (any_name);
5306     vnp->next = val_list;
5307     val_list = vnp;
5308   }
5309   dlg->molecule = ValNodeSelectionDialog (p, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5310                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5311                                            ValNodeChoiceMatch, "location",
5312                                            change_notify, change_userdata, FALSE);
5313 
5314   /* technique */
5315   StaticPrompt (p, molinfo_block_labels[1], wid, popupMenuHeight, programFont, 'l');
5316   val_list = GetTechniqueTypeList ();
5317   if (any_name != NULL) {
5318     vnp = ValNodeNew (NULL);
5319     vnp->choice = 255;
5320     vnp->data.ptrvalue = StringSave (any_name);
5321     vnp->next = val_list;
5322     val_list = vnp;
5323   }
5324   dlg->technique = ValNodeSelectionDialogExEx (p, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5325                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5326                                            ValNodeChoiceMatch, "location",
5327                                            change_notify, change_userdata, FALSE, FALSE, TRUE, NULL);
5328 
5329   /* completedness */
5330   StaticPrompt (p, molinfo_block_labels[2], wid, popupMenuHeight, programFont, 'l');
5331   val_list = GetCompletednessTypeList ();
5332   if (any_name != NULL) {
5333     vnp = ValNodeNew (NULL);
5334     vnp->choice = 255;
5335     vnp->data.ptrvalue = StringSave (any_name);
5336     vnp->next = val_list;
5337     val_list = vnp;
5338   }
5339   dlg->completedness = ValNodeSelectionDialog (p, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5340                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5341                                            ValNodeChoiceMatch, "location",
5342                                            change_notify, change_userdata, FALSE);
5343 
5344   /* mol_class */
5345   StaticPrompt (p, molinfo_block_labels[3], wid, popupMenuHeight, programFont, 'l');
5346   val_list = GetMoleculeClassTypeList ();
5347   if (any_name != NULL) {
5348     vnp = ValNodeNew (NULL);
5349     vnp->choice = 255;
5350     vnp->data.ptrvalue = StringSave (any_name);
5351     vnp->next = val_list;
5352     val_list = vnp;
5353   }
5354   dlg->mol_class = ValNodeSelectionDialog (p, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5355                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5356                                            ValNodeChoiceMatch, "location",
5357                                            change_notify, change_userdata, FALSE);
5358 
5359   /* topology */
5360   StaticPrompt (p, molinfo_block_labels[4], wid, popupMenuHeight, programFont, 'l');
5361   val_list = GetTopologyTypeList ();
5362   if (any_name != NULL) {
5363     vnp = ValNodeNew (NULL);
5364     vnp->choice = 255;
5365     vnp->data.ptrvalue = StringSave (any_name);
5366     vnp->next = val_list;
5367     val_list = vnp;
5368   }
5369   dlg->topology = ValNodeSelectionDialog (p, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5370                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5371                                            ValNodeChoiceMatch, "location",
5372                                            change_notify, change_userdata, FALSE);
5373   /* strand */
5374   StaticPrompt (p, molinfo_block_labels[5], wid, popupMenuHeight, programFont, 'l');
5375   val_list = GetStrandTypeList ();
5376   if (any_name != NULL) {
5377     vnp = ValNodeNew (NULL);
5378     vnp->choice = 255;
5379     vnp->data.ptrvalue = StringSave (any_name);
5380     vnp->next = val_list;
5381     val_list = vnp;
5382   }
5383   dlg->strand = ValNodeSelectionDialog (p, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
5384                                            ValNodeSimpleDataFree, ValNodeStringCopy,
5385                                            ValNodeChoiceMatch, "location",
5386                                            change_notify, change_userdata, FALSE);
5387 
5388   return (DialoG) p;
5389 }
5390 
5391 
5392 typedef struct molinfoblockdlg
5393 {
5394   DIALOG_MESSAGE_BLOCK
5395 
5396   DialoG to_list;
5397   DialoG from_list;
5398   DialoG constraint;
5399 
5400   Nlm_ChangeNotifyProc change_notify;
5401   Pointer change_userdata;
5402 } MolinfoBlockDlgData, PNTR MolinfoBlockDlgPtr;
5403 
5404 
MolInfoBlockToDialog(DialoG d,Pointer data)5405 static void MolInfoBlockToDialog (DialoG d, Pointer data)
5406 {
5407   MolinfoBlockDlgPtr dlg;
5408   MolinfoBlockPtr    mib;
5409 
5410   dlg = (MolinfoBlockDlgPtr) GetObjectExtra (d);
5411   if (dlg == NULL) {
5412     return;
5413   }
5414 
5415   mib = (MolinfoBlockPtr) data;
5416 
5417   if (mib == NULL) {
5418     PointerToDialog (dlg->from_list, NULL);
5419     PointerToDialog (dlg->to_list, NULL);
5420     PointerToDialog (dlg->constraint, NULL);
5421   } else {
5422     PointerToDialog (dlg->from_list, mib->from_list);
5423     PointerToDialog (dlg->to_list, mib->to_list);
5424     PointerToDialog (dlg->constraint, mib->constraint);
5425   }
5426 }
5427 
5428 
MolInfoBlockFromDialog(DialoG d)5429 static Pointer MolInfoBlockFromDialog (DialoG d)
5430 {
5431   MolinfoBlockDlgPtr dlg;
5432   MolinfoBlockPtr    mib;
5433 
5434   dlg = (MolinfoBlockDlgPtr) GetObjectExtra (d);
5435   if (dlg == NULL) {
5436     return NULL;
5437   }
5438 
5439   mib = MolinfoBlockNew ();
5440   mib->from_list = DialogToPointer (dlg->from_list);
5441   mib->to_list = DialogToPointer (dlg->to_list);
5442   mib->constraint = DialogToPointer (dlg->constraint);
5443 
5444   return (Pointer) mib;
5445 }
5446 
5447 
MolInfoBlockDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)5448 NLM_EXTERN DialoG MolInfoBlockDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
5449 {
5450   MolinfoBlockDlgPtr dlg;
5451   GrouP              p, g;
5452 
5453   dlg = (MolinfoBlockDlgPtr) MemNew (sizeof (MolinfoBlockDlgData));
5454   if (dlg == NULL)
5455   {
5456     return NULL;
5457   }
5458 
5459   p = HiddenGroup (h, -1, 0, NULL);
5460   SetObjectExtra (p, dlg, StdCleanupExtraProc);
5461   SetGroupSpacing (p, 10, 10);
5462 
5463   dlg->dialog = (DialoG) p;
5464   dlg->todialog = MolInfoBlockToDialog;
5465   dlg->fromdialog = MolInfoBlockFromDialog;
5466 
5467   dlg->change_notify = change_notify;
5468   dlg->change_userdata = change_userdata;
5469 
5470   g = HiddenGroup (p, edit ? 2 : -1 , 0, NULL);
5471 
5472   if (edit) {
5473     StaticPrompt (g, "From", 0, popupMenuHeight, programFont, 'c');
5474     StaticPrompt (g, "To", 0, popupMenuHeight, programFont, 'c');
5475     dlg->from_list = MolInfoBlockListDialog (g, "any", change_notify, change_userdata);
5476   }
5477   dlg->to_list = MolInfoBlockListDialog (g, "no change", change_notify, change_userdata);
5478 
5479   dlg->constraint = ComplexConstraintDialog (p, change_notify, change_userdata);
5480   ChangeComplexConstraintFieldType (dlg->constraint, FieldType_molinfo_field, NULL, Macro_feature_type_any);
5481 
5482   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) dlg->constraint, NULL);
5483 
5484   return (DialoG) p;
5485 }
5486 
5487 
5488 typedef struct capsaction {
5489   DIALOG_MESSAGE_BLOCK
5490   Uint1 action_type;
5491 } CapsActionDlgData, PNTR CapsActionDlgPtr;
5492 
5493 
CapsActionFromDialog(DialoG d)5494 static Pointer CapsActionFromDialog (DialoG d)
5495 {
5496   ValNodePtr vnp;
5497   CapsActionDlgPtr dlg;
5498 
5499   dlg = (CapsActionDlgPtr) GetObjectExtra (d);
5500   if (dlg == NULL) {
5501     return NULL;
5502   }
5503 
5504   vnp = ValNodeNew (NULL);
5505   vnp->choice = dlg->action_type;
5506   return vnp;
5507 }
5508 
5509 
CapsActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Uint1 action_type)5510 static DialoG CapsActionDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata, Uint1 action_type)
5511 {
5512   CapsActionDlgPtr dlg;
5513   GrouP              p;
5514 
5515   dlg = (CapsActionDlgPtr) MemNew (sizeof (CapsActionDlgData));
5516   if (dlg == NULL)
5517   {
5518     return NULL;
5519   }
5520 
5521   p = HiddenGroup (h, -1, 0, NULL);
5522   SetObjectExtra (p, dlg, StdCleanupExtraProc);
5523   SetGroupSpacing (p, 10, 10);
5524 
5525   dlg->dialog = (DialoG) p;
5526   dlg->todialog = NULL;
5527   dlg->fromdialog = CapsActionFromDialog;
5528   dlg->action_type = action_type;
5529 
5530   return (DialoG) p;
5531 }
5532 
5533 
MusMusculusActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)5534 static DialoG MusMusculusActionDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
5535 {
5536   return CapsActionDialog (h, edit, change_notify, change_userdata, FixCapsAction_mouse_strain);
5537 }
5538 
5539 
5540 #define MACRODIALOG_BLOCK         \
5541   DIALOG_MESSAGE_BLOCK \
5542   Nlm_ChangeNotifyProc change_notify; \
5543   Pointer              change_userdata;
5544 
5545 typedef struct macrodlg {
5546   MACRODIALOG_BLOCK
5547 } MacroDialogData, PNTR MacroDialogPtr;
5548 
5549 
ChangeMacroDialogBtn(ButtoN b)5550 static void ChangeMacroDialogBtn (ButtoN b)
5551 {
5552   MacroDialogPtr dlg;
5553 
5554   dlg = (MacroDialogPtr) GetObjectExtra (b);
5555   if (dlg != NULL && dlg->change_notify != NULL) {
5556     (dlg->change_notify) (dlg->change_userdata);
5557   }
5558 }
5559 
5560 
5561 typedef struct authorcapsaction {
5562   MACRODIALOG_BLOCK
5563   ButtoN last_name_only;
5564 } AuthorCapsActionDlgData, PNTR AuthorCapsActionDlgPtr;
5565 
5566 
AuthorCapsActionToDialog(DialoG d,Pointer data)5567 static void AuthorCapsActionToDialog (DialoG d, Pointer data)
5568 {
5569   AuthorCapsActionDlgPtr dlg;
5570   FixCapsActionPtr fix;
5571   FixAuthorCapsPtr fix_author;
5572 
5573   dlg = (AuthorCapsActionDlgPtr) GetObjectExtra (d);
5574   if (dlg == NULL) {
5575     return;
5576   }
5577 
5578   if ((fix = (FixCapsActionPtr) data) == NULL
5579       || fix->choice != FixCapsAction_author
5580       || (fix_author = (FixAuthorCapsPtr) fix->data.ptrvalue) == NULL) {
5581     SetStatus (dlg->last_name_only, FALSE);
5582   } else {
5583     SetStatus (dlg->last_name_only, fix_author->last_name_only);
5584   }
5585 }
5586 
5587 
AuthorCapsActionFromDialog(DialoG d)5588 static Pointer AuthorCapsActionFromDialog (DialoG d)
5589 {
5590   AuthorCapsActionDlgPtr dlg;
5591   FixCapsActionPtr fix;
5592   FixAuthorCapsPtr fix_author;
5593 
5594   dlg = (AuthorCapsActionDlgPtr) GetObjectExtra (d);
5595   if (dlg == NULL) {
5596     return NULL;
5597   }
5598 
5599   fix_author = FixAuthorCapsNew ();
5600   fix_author->last_name_only = GetStatus (dlg->last_name_only);
5601   fix = ValNodeNew (NULL);
5602   fix->choice = FixCapsAction_author;
5603   fix->data.ptrvalue = fix_author;
5604   return (Pointer) fix;
5605 }
5606 
5607 
AuthorCapsActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)5608 static DialoG AuthorCapsActionDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
5609 {
5610   AuthorCapsActionDlgPtr dlg;
5611   GrouP              p;
5612 
5613   dlg = (AuthorCapsActionDlgPtr) MemNew (sizeof (AuthorCapsActionDlgData));
5614   if (dlg == NULL)
5615   {
5616     return NULL;
5617   }
5618 
5619   p = HiddenGroup (h, -1, 0, NULL);
5620   SetObjectExtra (p, dlg, StdCleanupExtraProc);
5621   SetGroupSpacing (p, 10, 10);
5622 
5623   dlg->dialog = (DialoG) p;
5624   dlg->todialog = AuthorCapsActionToDialog;
5625   dlg->fromdialog = AuthorCapsActionFromDialog;
5626 
5627   dlg->last_name_only = CheckBox (p, "Last name only", ChangeMacroDialogBtn);
5628   SetObjectExtra (dlg->last_name_only, dlg, NULL);
5629 
5630   return (DialoG) p;
5631 }
5632 
5633 
FixCapsSourceCountryDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)5634 NLM_EXTERN DialoG FixCapsSourceCountryDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
5635 {
5636   return CapsActionDialog (h, edit, change_notify, change_userdata, FixCapsAction_src_country);
5637 }
5638 
5639 typedef struct srcqualcapsaction {
5640   DIALOG_MESSAGE_BLOCK
5641   DialoG field;
5642 } SrcQualCapsActionDlgData, PNTR SrcQualCapsActionDlgPtr;
5643 
5644 
SrcQualCapsActionFromDialog(DialoG d)5645 static Pointer SrcQualCapsActionFromDialog (DialoG d)
5646 {
5647   ValNodePtr vnp;
5648   SrcQualCapsActionDlgPtr dlg;
5649   Int4 val;
5650 
5651   dlg = (SrcQualCapsActionDlgPtr) GetObjectExtra (d);
5652   if (dlg == NULL) {
5653     return NULL;
5654   }
5655 
5656   vnp = DialogToPointer (dlg->field);
5657   val = GetSourceQualTypeByName (vnp->data.ptrvalue);
5658   vnp = ValNodeFree (vnp);
5659   vnp = ValNodeNew (NULL);
5660   vnp->choice = FixCapsAction_src_qual;
5661   vnp->data.intvalue = val;
5662   return vnp;
5663 }
5664 
5665 
SrcQualCapsActionToDialog(DialoG d,Pointer data)5666 static void SrcQualCapsActionToDialog (DialoG d, Pointer data)
5667 {
5668   ValNodePtr vnp;
5669   ValNode vn;
5670   SrcQualCapsActionDlgPtr dlg;
5671 
5672   dlg = (SrcQualCapsActionDlgPtr) GetObjectExtra (d);
5673   if (dlg == NULL) {
5674     return;
5675   }
5676   vnp = (ValNodePtr) data;
5677 
5678   MemSet (&vn, 0, sizeof (ValNode));
5679   if (vnp == NULL || vnp->data.intvalue == 0) {
5680     vn.data.ptrvalue = GetSourceQualName(Source_qual_sex);
5681   } else {
5682     vn.data.ptrvalue = GetSourceQualName (vnp->data.intvalue);
5683   }
5684   PointerToDialog (dlg->field, &vn);
5685 }
5686 
5687 
FixSrcQualCapsActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)5688 static DialoG FixSrcQualCapsActionDialog (GrouP h,  Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
5689 {
5690   SrcQualCapsActionDlgPtr dlg;
5691   GrouP            p;
5692   ValNodePtr       list = NULL;
5693 
5694   dlg = (SrcQualCapsActionDlgPtr) MemNew (sizeof (SrcQualCapsActionDlgData));
5695   if (dlg == NULL)
5696   {
5697     return NULL;
5698   }
5699 
5700   p = HiddenGroup (h, -1, 0, NULL);
5701   SetObjectExtra (p, dlg, StdCleanupExtraProc);
5702   SetGroupSpacing (p, 10, 10);
5703 
5704   dlg->dialog = (DialoG) p;
5705   dlg->todialog = SrcQualCapsActionToDialog;
5706   dlg->fromdialog = SrcQualCapsActionFromDialog;
5707 
5708   ValNodeAddPointer (&list, Source_qual_cell_type, StringSave (GetSourceQualName(Source_qual_cell_type)));
5709   ValNodeAddPointer (&list, Source_qual_dev_stage, StringSave (GetSourceQualName(Source_qual_dev_stage)));
5710   ValNodeAddPointer (&list, Source_qual_nat_host, StringSave (GetSourceQualName(Source_qual_nat_host)));
5711   ValNodeAddPointer (&list, Source_qual_isolation_source, StringSave (GetSourceQualName(Source_qual_isolation_source)));
5712   ValNodeAddPointer (&list, Source_qual_lab_host, StringSave (GetSourceQualName(Source_qual_lab_host)));
5713   ValNodeAddPointer (&list, Source_qual_sex, StringSave (GetSourceQualName(Source_qual_sex)));
5714   ValNodeAddPointer (&list, Source_qual_tissue_type, StringSave (GetSourceQualName(Source_qual_tissue_type)));
5715 
5716   dlg->field = ValNodeSelectionDialog (p, list, 4,
5717                                                ValNodeStringName,
5718                                                ValNodeSimpleDataFree,
5719                                                ValNodeStringCopy,
5720                                                ValNodeStringMatch,
5721                                                "source qual",
5722                                                change_notify, change_userdata, FALSE);
5723 
5724   return (DialoG) p;
5725 }
5726 
5727 
5728 typedef struct removexrefsaction {
5729   DIALOG_MESSAGE_BLOCK
5730   DialoG feature;
5731   PopuP  suppression;
5732   PopuP  necessary;
5733   DialoG constraint;
5734 
5735   Nlm_ChangeNotifyProc change_notify;
5736   Pointer change_userdata;
5737 } RemoveXrefsActionDlgData, PNTR RemoveXrefsActionDlgPtr;
5738 
5739 
RemoveXrefsActionFromDialog(DialoG d)5740 static Pointer RemoveXrefsActionFromDialog (DialoG d)
5741 {
5742   RemoveXrefsActionDlgPtr dlg;
5743   RemoveXrefsActionPtr    action;
5744   GeneXrefTypePtr         g;
5745   Int2                    val;
5746 
5747   dlg = (RemoveXrefsActionDlgPtr) GetObjectExtra (d);
5748   if (dlg == NULL) {
5749     return NULL;
5750   }
5751 
5752   g = GeneXrefTypeNew ();
5753   g->feature = GetFeatureTypeFromFeatureTypeDialog(dlg->feature);
5754 
5755   val = GetValue (dlg->necessary);
5756   switch (val) {
5757     case 1:
5758       g->necessary = Gene_xref_necessary_type_any;
5759       break;
5760     case 2:
5761       g->necessary = Gene_xref_necessary_type_necessary;
5762       break;
5763     case 3:
5764       g->necessary = Gene_xref_necessary_type_unnecessary;
5765       break;
5766     default:
5767       g->necessary = Gene_xref_necessary_type_any;
5768   }
5769 
5770   val = GetValue (dlg->suppression);
5771   switch (val) {
5772     case 1:
5773       g->suppression = Gene_xref_suppression_type_any;
5774       break;
5775     case 2:
5776       g->suppression = Gene_xref_suppression_type_suppressing;
5777       break;
5778     case 3:
5779       g->suppression = Gene_xref_suppression_type_non_suppressing;
5780       break;
5781     default:
5782       g->suppression = Gene_xref_suppression_type_any;
5783   }
5784 
5785   action = RemoveXrefsActionNew ();
5786   action->xref_type = ValNodeNew (NULL);
5787   action->xref_type->choice = XrefType_gene;
5788   action->xref_type->data.ptrvalue = g;
5789   action->constraint = DialogToPointer (dlg->constraint);
5790 
5791   return action;
5792 }
5793 
5794 
RemoveXrefsActionToDialog(DialoG d,Pointer data)5795 static void RemoveXrefsActionToDialog (DialoG d, Pointer data)
5796 {
5797   RemoveXrefsActionDlgPtr dlg;
5798   RemoveXrefsActionPtr    action;
5799   GeneXrefTypePtr         g;
5800 
5801   dlg = (RemoveXrefsActionDlgPtr) GetObjectExtra (d);
5802   if (dlg == NULL) {
5803     return;
5804   }
5805   action = (RemoveXrefsActionPtr) data;
5806   if (action == NULL
5807       || action->xref_type == NULL || action->xref_type->choice != XrefType_gene
5808       || (g = (GeneXrefTypePtr) action->xref_type->data.ptrvalue) == NULL) {
5809     PointerToDialog (dlg->feature, NULL);
5810     SetValue (dlg->suppression, 1);
5811     SetValue (dlg->necessary, 1);
5812   } else {
5813     SetFeatureTypeInFeatureTypeDialog(dlg->feature, g->feature);
5814     switch (g->necessary) {
5815       case Gene_xref_necessary_type_any:
5816         SetValue (dlg->necessary, 1);
5817         break;
5818       case Gene_xref_necessary_type_necessary:
5819         SetValue (dlg->necessary, 2);
5820         break;
5821       case Gene_xref_necessary_type_unnecessary:
5822         SetValue (dlg->necessary, 3);
5823         break;
5824       default:
5825         SetValue (dlg->necessary, 1);
5826         break;
5827     }
5828 
5829     switch (g->suppression) {
5830       case Gene_xref_suppression_type_any:
5831         SetValue (dlg->suppression, 1);
5832         break;
5833       case Gene_xref_suppression_type_suppressing:
5834         SetValue (dlg->suppression, 2);
5835         break;
5836       case Gene_xref_suppression_type_non_suppressing:
5837         SetValue (dlg->suppression, 3);
5838         break;
5839       default:
5840         SetValue (dlg->suppression, 1);
5841         break;
5842     }
5843   }
5844 
5845   if (action == NULL) {
5846     PointerToDialog (dlg->constraint, NULL);
5847   } else {
5848     PointerToDialog (dlg->constraint, action->constraint);
5849   }
5850 
5851 }
5852 
5853 
ChangeXrefsDialogPopup(PopuP p)5854 static void ChangeXrefsDialogPopup (PopuP p)
5855 {
5856   RemoveXrefsActionDlgPtr dlg;
5857 
5858   dlg = (RemoveXrefsActionDlgPtr) GetObjectExtra (p);
5859   if (dlg != NULL && dlg->change_notify != NULL) {
5860     (dlg->change_notify)(dlg->userdata);
5861   }
5862 }
5863 
5864 
RemoveXrefsDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)5865 static DialoG RemoveXrefsDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
5866 {
5867   RemoveXrefsActionDlgPtr dlg;
5868   GrouP                   p, k;
5869 
5870   dlg = (RemoveXrefsActionDlgPtr) MemNew (sizeof (RemoveXrefsActionDlgData));
5871   if (dlg == NULL)
5872   {
5873     return NULL;
5874   }
5875 
5876   p = HiddenGroup (h, -1, 0, NULL);
5877   SetObjectExtra (p, dlg, StdCleanupExtraProc);
5878   SetGroupSpacing (p, 10, 10);
5879 
5880   dlg->dialog = (DialoG) p;
5881   dlg->todialog = NULL;
5882   dlg->fromdialog = RemoveXrefsActionFromDialog;
5883   dlg->todialog = RemoveXrefsActionToDialog;
5884   dlg->change_notify = change_notify;
5885   dlg->change_userdata = change_userdata;
5886 
5887   dlg->feature = FeatureTypeDialog(p, change_notify, change_userdata);
5888 
5889   k = NormalGroup (p, 0, 3, "Remove Gene Xrefs that are", programFont, NULL);
5890   dlg->suppression = PopupList (k, TRUE, ChangeXrefsDialogPopup);
5891   SetObjectExtra (dlg->suppression, dlg, NULL);
5892   PopupItem (dlg->suppression, "Suppressing or non-suppressing");
5893   PopupItem (dlg->suppression, "Suppressing");
5894   PopupItem (dlg->suppression, "Non-suppressing");
5895   SetValue (dlg->suppression, 1);
5896 
5897   dlg->necessary = PopupList (k, TRUE, ChangeXrefsDialogPopup);
5898   SetObjectExtra (dlg->necessary, dlg, NULL);
5899   PopupItem (dlg->necessary, "Necessary or unnecessary");
5900   PopupItem (dlg->necessary, "Necessary");
5901   PopupItem (dlg->necessary, "Unnecessary");
5902   SetValue (dlg->necessary, 1);
5903 
5904   dlg->constraint = ConstraintSetDialog (p, dlg->change_notify, dlg->change_userdata);
5905 
5906   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->feature, (HANDLE) k, (HANDLE) dlg->constraint, NULL);
5907 
5908   return (DialoG) p;
5909 }
5910 
5911 
5912 typedef struct makegenexrefactiondialog {
5913   DIALOG_MESSAGE_BLOCK
5914   DialoG feature;
5915   DialoG constraint;
5916 
5917   Nlm_ChangeNotifyProc change_notify;
5918   Pointer change_userdata;
5919 } MakeGeneXrefActionDlgData, PNTR MakeGeneXrefActionDlgPtr;
5920 
5921 
MakeGeneXrefActionFromDialog(DialoG d)5922 static Pointer MakeGeneXrefActionFromDialog (DialoG d)
5923 {
5924   MakeGeneXrefActionDlgPtr dlg;
5925   MakeGeneXrefActionPtr    action = NULL;
5926   ValNodePtr constraint;
5927 
5928   dlg = (MakeGeneXrefActionDlgPtr) GetObjectExtra (d);
5929   if (dlg == NULL) {
5930     return NULL;
5931   }
5932 
5933   action = MakeGeneXrefActionNew ();
5934   action->feature = GetFeatureTypeFromFeatureTypeDialog(dlg->feature);
5935 
5936   constraint = DialogToPointer (dlg->constraint);
5937   action->constraint = constraint;
5938   return action;
5939 }
5940 
5941 
MakeGeneXrefActionToDialog(DialoG d,Pointer data)5942 static void MakeGeneXrefActionToDialog (DialoG d, Pointer data)
5943 {
5944   MakeGeneXrefActionDlgPtr dlg;
5945   MakeGeneXrefActionPtr    action;
5946 
5947   dlg = (MakeGeneXrefActionDlgPtr) GetObjectExtra (d);
5948   if (dlg == NULL) {
5949     return;
5950   }
5951 
5952   if ((action = (MakeGeneXrefActionPtr) data) == NULL) {
5953     SetFeatureTypeInFeatureTypeDialog(dlg->feature, Macro_feature_type_any);
5954     PointerToDialog (dlg->constraint, NULL);
5955   } else {
5956     SetFeatureTypeInFeatureTypeDialog(dlg->feature, action->feature);
5957     PointerToDialog (dlg->constraint, action->constraint);
5958   }
5959 }
5960 
5961 
MakeGeneXrefDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)5962 static DialoG MakeGeneXrefDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
5963 {
5964   MakeGeneXrefActionDlgPtr dlg;
5965   GrouP                    p;
5966 
5967   dlg = (MakeGeneXrefActionDlgPtr) MemNew (sizeof (MakeGeneXrefActionDlgData));
5968   if (dlg == NULL)
5969   {
5970     return NULL;
5971   }
5972 
5973   p = HiddenGroup (h, -1, 0, NULL);
5974   SetObjectExtra (p, dlg, StdCleanupExtraProc);
5975   SetGroupSpacing (p, 10, 10);
5976 
5977   dlg->dialog = (DialoG) p;
5978   dlg->todialog = NULL;
5979   dlg->fromdialog = MakeGeneXrefActionFromDialog;
5980   dlg->todialog = MakeGeneXrefActionToDialog;
5981   dlg->change_notify = change_notify;
5982   dlg->change_userdata = change_userdata;
5983 
5984   dlg->feature = FeatureTypeDialog(p, change_notify, change_userdata);
5985   dlg->constraint = ConstraintSetDialog (p, change_notify, change_userdata);
5986   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->feature, (HANDLE) dlg->constraint, NULL);
5987   return (DialoG) p;
5988 }
5989 
5990 
5991 typedef struct authorfixactiondialog {
5992   DIALOG_MESSAGE_BLOCK
5993   GrouP  fix_type;
5994   DialoG constraint;
5995 
5996   Nlm_ChangeNotifyProc change_notify;
5997   Pointer change_userdata;
5998 } AuthorFixActionDlgData, PNTR AuthorFixActionDlgPtr;
5999 
6000 
AuthorFixActionFromDialog(DialoG d)6001 static Pointer AuthorFixActionFromDialog (DialoG d)
6002 {
6003   AuthorFixActionDlgPtr dlg;
6004   AuthorFixActionPtr    action = NULL;
6005   ValNodePtr constraint;
6006 
6007   dlg = (AuthorFixActionDlgPtr) GetObjectExtra (d);
6008   if (dlg == NULL) {
6009     return NULL;
6010   }
6011 
6012   action = AuthorFixActionNew ();
6013   switch (GetValue (dlg->fix_type)) {
6014     case 1:
6015       action->fix_type = Author_fix_type_truncate_middle_initials;
6016       break;
6017     case 2:
6018       action->fix_type = Author_fix_type_strip_suffix;
6019       break;
6020     case 3:
6021       action->fix_type = Author_fix_type_move_middle_to_first;
6022       break;
6023     default:
6024       action->fix_type = Author_fix_type_truncate_middle_initials;
6025       break;
6026   }
6027   constraint = DialogToPointer (dlg->constraint);
6028   action->constraint = constraint;
6029   return action;
6030 }
6031 
6032 
AuthorFixActionToDialog(DialoG d,Pointer data)6033 static void AuthorFixActionToDialog (DialoG d, Pointer data)
6034 {
6035   AuthorFixActionDlgPtr dlg;
6036   AuthorFixActionPtr    action;
6037 
6038   dlg = (AuthorFixActionDlgPtr) GetObjectExtra (d);
6039   if (dlg == NULL) {
6040     return;
6041   }
6042 
6043   if ((action = (AuthorFixActionPtr) data) == NULL) {
6044     SetValue (dlg->fix_type, 1);
6045     PointerToDialog (dlg->constraint, NULL);
6046   } else {
6047     switch (action->fix_type) {
6048       case Author_fix_type_truncate_middle_initials:
6049         SetValue (dlg->fix_type, 1);
6050         break;
6051       case Author_fix_type_strip_suffix:
6052         SetValue (dlg->fix_type, 2);
6053         break;
6054       case Author_fix_type_move_middle_to_first:
6055         SetValue (dlg->fix_type, 3);
6056         break;
6057       default:
6058         SetValue (dlg->fix_type, 1);
6059         break;
6060     }
6061     PointerToDialog (dlg->constraint, action->constraint);
6062   }
6063 }
6064 
AuthorFixActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6065 static DialoG AuthorFixActionDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
6066 {
6067   AuthorFixActionDlgPtr dlg;
6068   GrouP                    p;
6069 
6070   dlg = (AuthorFixActionDlgPtr) MemNew (sizeof (AuthorFixActionDlgData));
6071   if (dlg == NULL)
6072   {
6073     return NULL;
6074   }
6075 
6076   p = HiddenGroup (h, -1, 0, NULL);
6077   SetObjectExtra (p, dlg, StdCleanupExtraProc);
6078   SetGroupSpacing (p, 10, 10);
6079 
6080   dlg->dialog = (DialoG) p;
6081   dlg->todialog = NULL;
6082   dlg->fromdialog = AuthorFixActionFromDialog;
6083   dlg->todialog = AuthorFixActionToDialog;
6084   dlg->change_notify = change_notify;
6085   dlg->change_userdata = change_userdata;
6086 
6087   dlg->fix_type = NormalGroup (p, 0, 3, "Author change", programFont, NULL);
6088   RadioButton (dlg->fix_type, "Truncate middle initials");
6089   RadioButton (dlg->fix_type, "Strip author suffix");
6090   RadioButton (dlg->fix_type, "Move middle name to first name");
6091   SetValue (dlg->fix_type, 1);
6092   dlg->constraint = ConstraintSetDialog (p, change_notify, change_userdata);
6093   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->fix_type, (HANDLE) dlg->constraint, NULL);
6094   return (DialoG) p;
6095 }
6096 
6097 
6098 typedef struct updatesequencesactiondialog {
6099   DIALOG_MESSAGE_BLOCK
6100   TexT filename;
6101   ButtoN add_cit_subs;
6102 
6103   Nlm_ChangeNotifyProc change_notify;
6104   Pointer change_userdata;
6105 } UpdateSequencesActionDlgData, PNTR UpdateSequencesActionDlgPtr;
6106 
6107 
UpdateSequencesActionFromDialog(DialoG d)6108 static Pointer UpdateSequencesActionFromDialog (DialoG d)
6109 {
6110   UpdateSequencesActionDlgPtr dlg;
6111   UpdateSequencesActionPtr    action = NULL;
6112 
6113   dlg = (UpdateSequencesActionDlgPtr) GetObjectExtra (d);
6114   if (dlg == NULL) {
6115     return NULL;
6116   }
6117 
6118   action = UpdateSequencesActionNew ();
6119   action->filename = SaveStringFromText (dlg->filename);
6120   action->add_cit_subs = GetStatus (dlg->add_cit_subs);
6121   return action;
6122 }
6123 
6124 
UpdateSequencesActionToDialog(DialoG d,Pointer data)6125 static void UpdateSequencesActionToDialog (DialoG d, Pointer data)
6126 {
6127   UpdateSequencesActionDlgPtr dlg;
6128   UpdateSequencesActionPtr    action;
6129 
6130   dlg = (UpdateSequencesActionDlgPtr) GetObjectExtra (d);
6131   if (dlg == NULL) {
6132     return;
6133   }
6134 
6135   if ((action = (UpdateSequencesActionPtr) data) == NULL) {
6136     SetTitle (dlg->filename, "");
6137     SetStatus (dlg->add_cit_subs, FALSE);
6138   } else {
6139     SetTitle (dlg->filename, action->filename);
6140     SetStatus (dlg->add_cit_subs, action->add_cit_subs);
6141   }
6142 }
6143 
6144 
ChangeUpdateSequencesActionText(TexT t)6145 static void ChangeUpdateSequencesActionText (TexT t)
6146 {
6147   UpdateSequencesActionDlgPtr dlg;
6148 
6149   dlg = (UpdateSequencesActionDlgPtr) GetObjectExtra (t);
6150   if (dlg != NULL && dlg->change_notify != NULL) {
6151     (dlg->change_notify)(dlg->change_userdata);
6152   }
6153 }
6154 
6155 
ChangeUpdateSequencesActionButton(ButtoN b)6156 static void ChangeUpdateSequencesActionButton (ButtoN b)
6157 {
6158   UpdateSequencesActionDlgPtr dlg;
6159 
6160   dlg = (UpdateSequencesActionDlgPtr) GetObjectExtra (b);
6161   if (dlg != NULL && dlg->change_notify != NULL) {
6162     (dlg->change_notify)(dlg->change_userdata);
6163   }
6164 }
6165 
6166 
TestUpdateSequencesActionDialog(DialoG d)6167 static ValNodePtr TestUpdateSequencesActionDialog (DialoG d)
6168 {
6169   UpdateSequencesActionDlgPtr dlg;
6170   ValNodePtr errs = NULL;
6171 
6172   dlg = (UpdateSequencesActionDlgPtr) GetObjectExtra (d);
6173   if (dlg != NULL) {
6174     if (TextHasNoText (dlg->filename)) {
6175       ValNodeAddPointer (&errs, 0, "Needs filename");
6176     }
6177   }
6178   return errs;
6179 }
6180 
6181 
UpdateSequencesActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6182 static DialoG UpdateSequencesActionDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
6183 {
6184   UpdateSequencesActionDlgPtr dlg;
6185   GrouP                    p, g;
6186 
6187   dlg = (UpdateSequencesActionDlgPtr) MemNew (sizeof (UpdateSequencesActionDlgData));
6188   if (dlg == NULL)
6189   {
6190     return NULL;
6191   }
6192 
6193   p = HiddenGroup (h, -1, 0, NULL);
6194   SetObjectExtra (p, dlg, StdCleanupExtraProc);
6195   SetGroupSpacing (p, 10, 10);
6196 
6197   dlg->dialog = (DialoG) p;
6198   dlg->todialog = NULL;
6199   dlg->fromdialog = UpdateSequencesActionFromDialog;
6200   dlg->todialog = UpdateSequencesActionToDialog;
6201   dlg->testdialog = TestUpdateSequencesActionDialog;
6202   dlg->change_notify = change_notify;
6203   dlg->change_userdata = change_userdata;
6204 
6205   g = HiddenGroup (p, 2, 0, NULL);
6206   SetGroupSpacing (g, 10, 10);
6207   StaticPrompt (g, "File Name", 0, dialogTextHeight, programFont, 'r');
6208   dlg->filename =  DialogText (g, "", 10, ChangeUpdateSequencesActionText);
6209   SetObjectExtra (dlg->filename, dlg, NULL);
6210 
6211   dlg->add_cit_subs = CheckBox (p, "Add CitSub", ChangeUpdateSequencesActionButton);
6212   SetObjectExtra (dlg->add_cit_subs, dlg, NULL);
6213 
6214   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) dlg->add_cit_subs, NULL);
6215   return (DialoG) p;
6216 }
6217 
6218 
6219 typedef struct applytableactiondialog {
6220   DIALOG_MESSAGE_BLOCK
6221   TexT filename;
6222   DialoG id_config;
6223   ButtoN also_change_mrna;
6224   ButtoN erase_when_blank;
6225 
6226   Nlm_ChangeNotifyProc change_notify;
6227   Pointer change_userdata;
6228 } ApplyTableActionDlgData, PNTR ApplyTableActionDlgPtr;
6229 
6230 
ApplyTableActionFromDialog(DialoG d)6231 static Pointer ApplyTableActionFromDialog (DialoG d)
6232 {
6233   ApplyTableActionDlgPtr dlg;
6234   ApplyTableActionPtr    action = NULL;
6235   MatchTypePtr           m;
6236 
6237   dlg = (ApplyTableActionDlgPtr) GetObjectExtra (d);
6238   if (dlg == NULL) {
6239     return NULL;
6240   }
6241 
6242   action = ApplyTableActionNew ();
6243   action->filename = SaveStringFromText (dlg->filename);
6244   m = DialogToPointer (dlg->id_config);
6245   action->match_type = TableMatchTypeFromMatchType(m);
6246   m = MatchTypeFree (m);
6247   action->also_change_mrna = GetStatus (dlg->also_change_mrna);
6248   action->skip_blanks = !GetStatus (dlg->erase_when_blank);
6249 
6250   return action;
6251 }
6252 
6253 
ApplyTableActionToDialog(DialoG d,Pointer data)6254 static void ApplyTableActionToDialog (DialoG d, Pointer data)
6255 {
6256   ApplyTableActionDlgPtr dlg;
6257   ApplyTableActionPtr    action;
6258   MatchTypePtr           m;
6259 
6260   dlg = (ApplyTableActionDlgPtr) GetObjectExtra (d);
6261   if (dlg == NULL) {
6262     return;
6263   }
6264 
6265   if ((action = (ApplyTableActionPtr) data) == NULL) {
6266     SetTitle (dlg->filename, "");
6267     PointerToDialog (dlg->id_config, NULL);
6268     SetStatus (dlg->also_change_mrna, FALSE);
6269     SetStatus (dlg->erase_when_blank, FALSE);
6270   } else {
6271     SetTitle (dlg->filename, action->filename);
6272     m = MatchTypeFromTableMatchType(action->match_type);
6273     PointerToDialog (dlg->id_config, m);
6274     m = MatchTypeFree (m);
6275     SetStatus (dlg->also_change_mrna, action->also_change_mrna);
6276     SetStatus (dlg->erase_when_blank, !action->skip_blanks);
6277   }
6278 }
6279 
6280 
ChangeApplyTableActionText(TexT t)6281 static void ChangeApplyTableActionText (TexT t)
6282 {
6283   ApplyTableActionDlgPtr dlg;
6284 
6285   dlg = (ApplyTableActionDlgPtr) GetObjectExtra (t);
6286   if (dlg != NULL && dlg->change_notify != NULL) {
6287     (dlg->change_notify)(dlg->change_userdata);
6288   }
6289 }
6290 
6291 
TestApplyTableActionDialog(DialoG d)6292 static ValNodePtr TestApplyTableActionDialog (DialoG d)
6293 {
6294   ApplyTableActionDlgPtr dlg;
6295   ValNodePtr errs = NULL;
6296   MatchTypePtr m;
6297 
6298   dlg = (ApplyTableActionDlgPtr) GetObjectExtra (d);
6299   if (dlg != NULL) {
6300     if (TextHasNoText (dlg->filename)) {
6301       ValNodeAddPointer (&errs, 0, "Needs filename");
6302     }
6303     m = DialogToPointer (dlg->id_config);
6304     if (m == NULL) {
6305       ValNodeAddPointer (&errs, 0, "Needs match type");
6306     }
6307     m = MatchTypeFree (m);
6308   }
6309   return errs;
6310 }
6311 
6312 
ChangeApplyTableActionButton(ButtoN b)6313 static void ChangeApplyTableActionButton (ButtoN b)
6314 {
6315   ApplyTableActionDlgPtr dlg;
6316 
6317   dlg = (ApplyTableActionDlgPtr) GetObjectExtra (b);
6318   if (dlg == NULL) {
6319     return;
6320   }
6321   if (dlg->change_notify != NULL) {
6322     dlg->change_notify(dlg->change_userdata);
6323   }
6324 }
6325 
6326 
ApplyTableActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6327 static DialoG ApplyTableActionDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
6328 {
6329   ApplyTableActionDlgPtr dlg;
6330   GrouP                  p, g;
6331 
6332   dlg = (ApplyTableActionDlgPtr) MemNew (sizeof (ApplyTableActionDlgData));
6333   if (dlg == NULL)
6334   {
6335     return NULL;
6336   }
6337 
6338   p = HiddenGroup (h, -1, 0, NULL);
6339   SetObjectExtra (p, dlg, StdCleanupExtraProc);
6340   SetGroupSpacing (p, 10, 10);
6341 
6342   dlg->dialog = (DialoG) p;
6343   dlg->todialog = NULL;
6344   dlg->fromdialog = ApplyTableActionFromDialog;
6345   dlg->todialog = ApplyTableActionToDialog;
6346   dlg->testdialog = TestApplyTableActionDialog;
6347   dlg->change_notify = change_notify;
6348   dlg->change_userdata = change_userdata;
6349 
6350   g = HiddenGroup (p, 2, 0, NULL);
6351   SetGroupSpacing (g, 10, 10);
6352   StaticPrompt (g, "File Name", 0, dialogTextHeight, programFont, 'r');
6353   dlg->filename =  DialogText (g, "", 10, ChangeApplyTableActionText);
6354   SetObjectExtra (dlg->filename, dlg, NULL);
6355   dlg->id_config = MatchTypeDialog (p, dlg->change_notify, dlg->change_userdata);
6356   dlg->erase_when_blank = CheckBox (p, "Erase fields when table cells are blank", ChangeApplyTableActionButton);
6357   SetObjectExtra (dlg->erase_when_blank, dlg, NULL);
6358   dlg->also_change_mrna = CheckBox (p, "Change mRNA when changing protein name", ChangeApplyTableActionButton);
6359   SetObjectExtra (dlg->also_change_mrna, dlg, NULL);
6360   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) dlg->id_config, NULL);
6361 
6362   return (DialoG) p;
6363 }
6364 
6365 
6366 typedef struct addfiledescriptorseactiondialog {
6367   DIALOG_MESSAGE_BLOCK
6368   TexT filename;
6369   DialoG constraint;
6370 
6371   Nlm_ChangeNotifyProc change_notify;
6372   Pointer change_userdata;
6373 } AddFileDescriptorsActionDlgData, PNTR AddFileDescriptorsActionDlgPtr;
6374 
6375 
AddDescriptorListFromDialog(DialoG d)6376 static Pointer AddDescriptorListFromDialog (DialoG d)
6377 {
6378   AddFileDescriptorsActionDlgPtr dlg;
6379   AddDescriptorListActionPtr    action = NULL;
6380 
6381   dlg = (AddFileDescriptorsActionDlgPtr) GetObjectExtra (d);
6382   if (dlg == NULL) {
6383     return NULL;
6384   }
6385 
6386   action = AddDescriptorListActionNew();
6387   action->descriptor_list = AddFileActionNew ();
6388   action->descriptor_list->filename = SaveStringFromText (dlg->filename);
6389   action->constraint = DialogToPointer (dlg->constraint);
6390 
6391   return action;
6392 }
6393 
6394 
AddDescriptorListToDialog(DialoG d,Pointer data)6395 static void AddDescriptorListToDialog (DialoG d, Pointer data)
6396 {
6397   AddFileDescriptorsActionDlgPtr dlg;
6398   AddDescriptorListActionPtr    action;
6399 
6400   dlg = (AddFileDescriptorsActionDlgPtr) GetObjectExtra (d);
6401   if (dlg == NULL) {
6402     return;
6403   }
6404 
6405   if ((action = (AddDescriptorListActionPtr) data) == NULL) {
6406     SetTitle (dlg->filename, "");
6407     PointerToDialog (dlg->constraint, NULL);
6408   } else {
6409     SetTitle (dlg->filename, action->descriptor_list->filename);
6410     PointerToDialog (dlg->constraint, action->constraint);
6411   }
6412 }
6413 
6414 
ChangeAddFileDescriptorsActionText(TexT t)6415 static void ChangeAddFileDescriptorsActionText (TexT t)
6416 {
6417   AddFileDescriptorsActionDlgPtr dlg;
6418 
6419   dlg = (AddFileDescriptorsActionDlgPtr) GetObjectExtra (t);
6420   if (dlg != NULL && dlg->change_notify != NULL) {
6421     (dlg->change_notify)(dlg->change_userdata);
6422   }
6423 }
6424 
6425 
TestAddFileDescriptorsActionDialog(DialoG d)6426 static ValNodePtr TestAddFileDescriptorsActionDialog (DialoG d)
6427 {
6428   AddFileDescriptorsActionDlgPtr dlg;
6429   ValNodePtr errs = NULL;
6430 
6431   dlg = (AddFileDescriptorsActionDlgPtr) GetObjectExtra (d);
6432   if (dlg != NULL) {
6433     if (TextHasNoText (dlg->filename)) {
6434       ValNodeAddPointer (&errs, 0, "Needs filename");
6435     }
6436   }
6437   return errs;
6438 }
6439 
6440 
AddFileDescriptorsActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6441 static DialoG AddFileDescriptorsActionDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
6442 {
6443   AddFileDescriptorsActionDlgPtr dlg;
6444   GrouP                  p, g;
6445 
6446   dlg = (AddFileDescriptorsActionDlgPtr) MemNew (sizeof (AddFileDescriptorsActionDlgData));
6447   if (dlg == NULL)
6448   {
6449     return NULL;
6450   }
6451 
6452   p = HiddenGroup (h, -1, 0, NULL);
6453   SetObjectExtra (p, dlg, StdCleanupExtraProc);
6454   SetGroupSpacing (p, 10, 10);
6455 
6456   dlg->dialog = (DialoG) p;
6457   dlg->todialog = NULL;
6458   dlg->fromdialog = AddDescriptorListFromDialog;
6459   dlg->todialog = AddDescriptorListToDialog;
6460   dlg->testdialog = TestAddFileDescriptorsActionDialog;
6461   dlg->change_notify = change_notify;
6462   dlg->change_userdata = change_userdata;
6463 
6464   g = HiddenGroup (p, 2, 0, NULL);
6465   SetGroupSpacing (g, 10, 10);
6466   StaticPrompt (g, "File Name", 0, dialogTextHeight, programFont, 'r');
6467   dlg->filename =  DialogText (g, "", 10, ChangeAddFileDescriptorsActionText);
6468   SetObjectExtra (dlg->filename, dlg, NULL);
6469   dlg->constraint = ConstraintSetDialog (p, dlg->change_notify, dlg->change_userdata);
6470   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) dlg->constraint, NULL);
6471 
6472   return (DialoG) p;
6473 }
6474 
6475 
6476 typedef struct removesequencesactiondialog {
6477   DIALOG_MESSAGE_BLOCK
6478   DialoG constraint;
6479 
6480   Nlm_ChangeNotifyProc change_notify;
6481   Pointer change_userdata;
6482 } RemoveSequencesActionDlgData, PNTR RemoveSequencesActionDlgPtr;
6483 
6484 
RemoveSequencesActionFromDialog(DialoG d)6485 static Pointer RemoveSequencesActionFromDialog (DialoG d)
6486 {
6487   RemoveSequencesActionDlgPtr dlg;
6488   RemoveSequencesActionPtr action;
6489 
6490   dlg = (RemoveSequencesActionDlgPtr) GetObjectExtra (d);
6491   if (dlg == NULL) {
6492     return NULL;
6493   }
6494 
6495   action = RemoveSequencesActionNew ();
6496   action->constraint = DialogToPointer (dlg->constraint);
6497   if (action->constraint == NULL) {
6498     action = RemoveSequencesActionFree (action);
6499   }
6500   return action;
6501 }
6502 
6503 
RemoveSequencesActionToDialog(DialoG d,Pointer data)6504 static void RemoveSequencesActionToDialog (DialoG d, Pointer data)
6505 {
6506   RemoveSequencesActionDlgPtr dlg;
6507   RemoveSequencesActionPtr action;
6508 
6509   dlg = (RemoveSequencesActionDlgPtr) GetObjectExtra (d);
6510   if (dlg == NULL) {
6511     return;
6512   }
6513 
6514   action = (RemoveSequencesActionPtr) data;
6515   if (action == NULL) {
6516     PointerToDialog (dlg->constraint, NULL);
6517   } else {
6518     PointerToDialog (dlg->constraint, action->constraint);
6519   }
6520 }
6521 
6522 
TestRemoveSequencesActionDialog(DialoG d)6523 static ValNodePtr TestRemoveSequencesActionDialog (DialoG d)
6524 {
6525   RemoveSequencesActionPtr action;
6526   ValNodePtr errs = NULL;
6527 
6528   action = DialogToPointer (d);
6529   if (action == NULL) {
6530     ValNodeAddPointer (&errs, 0, "Needs constraint");
6531   } else {
6532     action = RemoveSequencesActionFree (action);
6533   }
6534   return errs;
6535 }
6536 
6537 
RemoveSequencesActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6538 static DialoG RemoveSequencesActionDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
6539 {
6540   RemoveSequencesActionDlgPtr dlg;
6541   GrouP                  p;
6542 
6543   dlg = (RemoveSequencesActionDlgPtr) MemNew (sizeof (RemoveSequencesActionDlgData));
6544   if (dlg == NULL)
6545   {
6546     return NULL;
6547   }
6548   p = HiddenGroup (h, -1, 0, NULL);
6549   SetObjectExtra (p, dlg, StdCleanupExtraProc);
6550   SetGroupSpacing (p, 10, 10);
6551 
6552   dlg->dialog = (DialoG) p;
6553   dlg->todialog = NULL;
6554   dlg->fromdialog = RemoveSequencesActionFromDialog;
6555   dlg->todialog = RemoveSequencesActionToDialog;
6556   dlg->testdialog = TestRemoveSequencesActionDialog;
6557   dlg->change_notify = change_notify;
6558   dlg->change_userdata = change_userdata;
6559 
6560   dlg->constraint = ConstraintSetDialog (p, dlg->change_notify, dlg->change_userdata);
6561 
6562   return (DialoG) p;
6563 }
6564 
6565 
6566 typedef struct createtsaidsactiondialog {
6567   DIALOG_MESSAGE_BLOCK
6568   GrouP  src_choice;
6569   DialoG text_portion;
6570   TexT   suffix;
6571 
6572   Nlm_ChangeNotifyProc change_notify;
6573   Pointer change_userdata;
6574 } CreateTSAIdsActionDlgData, PNTR CreateTSAIdsActionDlgPtr;
6575 
CreateTSAIdsActionFromDialog(DialoG d)6576 static Pointer CreateTSAIdsActionFromDialog (DialoG d)
6577 {
6578   CreateTSAIdsActionDlgPtr dlg;
6579   CreateTSAIdsActionPtr action;
6580   TextPortionPtr text_portion;
6581 
6582   dlg = (CreateTSAIdsActionDlgPtr) GetObjectExtra (d);
6583   if (dlg == NULL) {
6584     return NULL;
6585   }
6586 
6587   action = CreateTSAIdsActionNew ();
6588   if (!TextHasNoText (dlg->suffix)) {
6589     action->suffix = SaveStringFromText (dlg->suffix);
6590   }
6591 
6592   if (GetValue (dlg->src_choice) == 2) {
6593     text_portion = DialogToPointer (dlg->text_portion);
6594     action->src = ValNodeNew (NULL);
6595     action->src->choice = CreateTSAIdsSrc_defline;
6596     action->src->data.ptrvalue = text_portion;
6597   } else {
6598     action->src = ValNodeNew (NULL);
6599     action->src->choice = CreateTSAIdsSrc_local_id;
6600     action->id_text_portion = DialogToPointer (dlg->text_portion);
6601   }
6602   return (Pointer) action;
6603 }
6604 
6605 
CreateTSAIdsActionToDialog(DialoG d,Pointer data)6606 static void CreateTSAIdsActionToDialog (DialoG d, Pointer data)
6607 {
6608   CreateTSAIdsActionDlgPtr dlg;
6609   CreateTSAIdsActionPtr action;
6610 
6611   dlg = (CreateTSAIdsActionDlgPtr) GetObjectExtra (d);
6612   if (dlg == NULL) {
6613     return;
6614   }
6615 
6616   action = (CreateTSAIdsActionPtr) data;
6617 
6618   if (action == NULL) {
6619     SetValue (dlg->src_choice, 1);
6620     SetTitle (dlg->suffix, "");
6621     PointerToDialog (dlg->text_portion, NULL);
6622   } else {
6623     if (action->src == NULL || action->src->choice != CreateTSAIdsSrc_defline) {
6624       SetValue (dlg->src_choice, 1);
6625       PointerToDialog (dlg->text_portion, action->id_text_portion);
6626     } else {
6627       SetValue (dlg->src_choice, 2);
6628       PointerToDialog (dlg->text_portion, action->src->data.ptrvalue);
6629     }
6630     SetTitle (dlg->suffix, action->suffix);
6631   }
6632 }
6633 
6634 
ChangeCreateTSAIDsSrcChoice(GrouP g)6635 static void ChangeCreateTSAIDsSrcChoice (GrouP g)
6636 {
6637   CreateTSAIdsActionDlgPtr dlg;
6638 
6639   dlg = (CreateTSAIdsActionDlgPtr) GetObjectExtra (g);
6640   if (dlg == NULL) {
6641     return;
6642   }
6643 
6644   if (dlg->change_notify != NULL) {
6645     (dlg->change_notify)(dlg->change_userdata);
6646   }
6647 }
6648 
6649 
ChangeCreateTSAIdsActionText(TexT t)6650 static void ChangeCreateTSAIdsActionText (TexT t)
6651 {
6652   CreateTSAIdsActionDlgPtr dlg;
6653 
6654   dlg = (CreateTSAIdsActionDlgPtr) GetObjectExtra (t);
6655   if (dlg == NULL) {
6656     return;
6657   }
6658 
6659   if (dlg->change_notify != NULL) {
6660     (dlg->change_notify)(dlg->change_userdata);
6661   }
6662 }
6663 
CreateTSAIdsActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6664 static DialoG CreateTSAIdsActionDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
6665 {
6666   CreateTSAIdsActionDlgPtr dlg;
6667   GrouP                    p, g;
6668 
6669   dlg = (CreateTSAIdsActionDlgPtr) MemNew (sizeof (CreateTSAIdsActionDlgData));
6670   if (dlg == NULL)
6671   {
6672     return NULL;
6673   }
6674 
6675   p = HiddenGroup (h, -1, 0, NULL);
6676   SetObjectExtra (p, dlg, StdCleanupExtraProc);
6677   SetGroupSpacing (p, 10, 10);
6678 
6679   dlg->dialog = (DialoG) p;
6680   dlg->todialog = NULL;
6681   dlg->fromdialog = CreateTSAIdsActionFromDialog;
6682   dlg->todialog = CreateTSAIdsActionToDialog;
6683   dlg->change_notify = change_notify;
6684   dlg->change_userdata = change_userdata;
6685 
6686   dlg->src_choice = NormalGroup (p, 0, 2, "Create TSA IDs from", programFont, ChangeCreateTSAIDsSrcChoice);
6687   SetGroupSpacing (dlg->src_choice, 10, 10);
6688   SetObjectExtra (dlg->src_choice, dlg, NULL);
6689   RadioButton (dlg->src_choice, "Local IDs");
6690   RadioButton (dlg->src_choice, "Definition Lines");
6691   SetValue (dlg->src_choice, 1);
6692 
6693   dlg->text_portion = TextPortionDialog (p, TRUE, change_notify, change_userdata);
6694 
6695   g = HiddenGroup (p, 2, 0, NULL);
6696   SetGroupSpacing (g, 10, 10);
6697   StaticPrompt (g, "Optional Suffix", 0, dialogTextHeight, programFont, 'r');
6698   dlg->suffix = DialogText (g, "", 10, ChangeCreateTSAIdsActionText);
6699   SetObjectExtra (dlg->suffix, dlg, NULL);
6700 
6701   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->src_choice, (HANDLE) dlg->text_portion, (HANDLE) g, NULL);
6702   return (DialoG) p;
6703 }
6704 
6705 
6706 typedef struct formataction {
6707   DIALOG_MESSAGE_BLOCK
6708   Uint1 action_type;
6709 } FormatActionDlgData, PNTR FormatActionDlgPtr;
6710 
6711 
FormatActionFromDialog(DialoG d)6712 static Pointer FormatActionFromDialog (DialoG d)
6713 {
6714   ValNodePtr vnp;
6715   FormatActionDlgPtr dlg;
6716 
6717   dlg = (FormatActionDlgPtr) GetObjectExtra (d);
6718   if (dlg == NULL) {
6719     return NULL;
6720   }
6721 
6722   vnp = ValNodeNew (NULL);
6723   vnp->choice = dlg->action_type;
6724   return vnp;
6725 }
6726 
6727 
FormatActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Uint1 action_type)6728 static DialoG FormatActionDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata, Uint1 action_type)
6729 {
6730   FormatActionDlgPtr dlg;
6731   GrouP              p;
6732 
6733   dlg = (FormatActionDlgPtr) MemNew (sizeof (FormatActionDlgData));
6734   if (dlg == NULL)
6735   {
6736     return NULL;
6737   }
6738 
6739   p = HiddenGroup (h, -1, 0, NULL);
6740   SetObjectExtra (p, dlg, StdCleanupExtraProc);
6741   SetGroupSpacing (p, 10, 10);
6742 
6743   dlg->dialog = (DialoG) p;
6744   dlg->todialog = NULL;
6745   dlg->fromdialog = FormatActionFromDialog;
6746   dlg->action_type = action_type;
6747 
6748   return (DialoG) p;
6749 }
6750 
6751 
FormatCollectionDateDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6752 static DialoG FormatCollectionDateDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
6753 {
6754   return FormatActionDialog (h, edit, change_notify, change_userdata, FixFormatAction_collection_date);
6755 }
6756 
6757 
FormatLatLonDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6758 static DialoG FormatLatLonDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
6759 {
6760   return FormatActionDialog (h, edit, change_notify, change_userdata, FixFormatAction_lat_lon);
6761 }
6762 
6763 
FormatPrimerDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6764 static DialoG FormatPrimerDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
6765 {
6766   return FormatActionDialog (h, edit, change_notify, change_userdata, FixFormatAction_primers);
6767 }
6768 
6769 
FormatProteinNameDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6770 static DialoG FormatProteinNameDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
6771 {
6772   return FormatActionDialog (h, edit, change_notify, change_userdata, FixFormatAction_protein_name);
6773 }
6774 
6775 
6776 
6777 typedef struct removeduplicatefeataction {
6778   DIALOG_MESSAGE_BLOCK
6779   DialoG feature_type;
6780   ButtoN ignore_partials;
6781   ButtoN case_sensitive;
6782   ButtoN remove_proteins;
6783   DialoG constraint;
6784 
6785   Nlm_ChangeNotifyProc change_notify;
6786   Pointer change_userdata;
6787 } RemoveDuplicateFeatActionDlgData, PNTR RemoveDuplicateFeatActionDlgPtr;
6788 
6789 
RemoveDuplicateFeatActionFromDialog(DialoG d)6790 static Pointer RemoveDuplicateFeatActionFromDialog (DialoG d)
6791 {
6792   RemoveDuplicateFeatureActionPtr action;
6793   RemoveDuplicateFeatActionDlgPtr dlg;
6794   ValNodePtr vnp;
6795 
6796   dlg = (RemoveDuplicateFeatActionDlgPtr) GetObjectExtra (d);
6797   if (dlg == NULL) {
6798     return NULL;
6799   }
6800 
6801   action = RemoveDuplicateFeatureActionNew ();
6802   vnp = DialogToPointer (dlg->feature_type);
6803   if (vnp == NULL) {
6804     action->type = Macro_feature_type_any;
6805   } else {
6806     action->type = vnp->choice;
6807   }
6808   vnp = ValNodeFree (vnp);
6809   action->ignore_partials = GetStatus (dlg->ignore_partials);
6810   action->remove_proteins = GetStatus (dlg->remove_proteins);
6811   action->case_sensitive = GetStatus (dlg->case_sensitive);
6812   action->rd_constraint = DialogToPointer (dlg->constraint);
6813   return action;
6814 }
6815 
6816 
RemoveDuplicateFeatActionToDialog(DialoG d,Pointer data)6817 static void RemoveDuplicateFeatActionToDialog (DialoG d, Pointer data)
6818 {
6819   RemoveDuplicateFeatureActionPtr action;
6820   RemoveDuplicateFeatActionDlgPtr dlg;
6821   ValNode vn;
6822 
6823   dlg = (RemoveDuplicateFeatActionDlgPtr) GetObjectExtra (d);
6824   if (dlg == NULL) {
6825     return;
6826   }
6827 
6828   action = (RemoveDuplicateFeatureActionPtr) data;
6829   if (data == NULL) {
6830     PointerToDialog (dlg->feature_type, NULL);
6831     SetStatus (dlg->ignore_partials, FALSE);
6832     SetStatus (dlg->remove_proteins, TRUE);
6833     SetStatus (dlg->case_sensitive, TRUE);
6834     PointerToDialog (dlg->constraint, NULL);
6835   } else {
6836     MemSet (&vn, 0, sizeof (ValNode));
6837     vn.choice = (Uint1)action->type;
6838     PointerToDialog (dlg->feature_type, &vn);
6839     SetStatus (dlg->ignore_partials, action->ignore_partials);
6840     SetStatus (dlg->remove_proteins, action->remove_proteins);
6841     SetStatus (dlg->case_sensitive, action->case_sensitive);
6842     PointerToDialog (dlg->constraint, action->rd_constraint);
6843   }
6844 }
6845 
6846 
ChangeRemoveDuplicateFeatActionButon(ButtoN b)6847 static void ChangeRemoveDuplicateFeatActionButon (ButtoN b)
6848 {
6849   RemoveDuplicateFeatActionDlgPtr dlg;
6850 
6851   dlg = (RemoveDuplicateFeatActionDlgPtr) GetObjectExtra (b);
6852   if (dlg == NULL) {
6853     return;
6854   }
6855   if (dlg->change_notify != NULL) {
6856     (dlg->change_notify)(dlg->change_userdata);
6857   }
6858 }
6859 
6860 
RemoveDuplicateFeatActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6861 NLM_EXTERN DialoG RemoveDuplicateFeatActionDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
6862 {
6863   RemoveDuplicateFeatActionDlgPtr dlg;
6864   GrouP              p;
6865   ValNodePtr         feature_list = NULL;
6866 
6867   dlg = (RemoveDuplicateFeatActionDlgPtr) MemNew (sizeof (RemoveDuplicateFeatActionDlgData));
6868   if (dlg == NULL)
6869   {
6870     return NULL;
6871   }
6872 
6873   p = HiddenGroup (h, -1, 0, NULL);
6874   SetObjectExtra (p, dlg, StdCleanupExtraProc);
6875   SetGroupSpacing (p, 10, 10);
6876 
6877   dlg->dialog = (DialoG) p;
6878   dlg->todialog = RemoveDuplicateFeatActionToDialog;
6879   dlg->fromdialog = RemoveDuplicateFeatActionFromDialog;
6880   dlg->change_notify = change_notify;
6881   dlg->change_userdata = change_userdata;
6882 
6883   feature_list = ValNodeNew (NULL);
6884   feature_list->choice = Macro_feature_type_any;
6885   feature_list->data.ptrvalue = StringSave ("Any");
6886   AddAllFeaturesToChoiceList (&feature_list);
6887   dlg->feature_type = ValNodeSelectionDialog (p, feature_list, TALL_SELECTION_LIST, ValNodeStringName,
6888                                 ValNodeSimpleDataFree, ValNodeStringCopy,
6889                                 ValNodeChoiceMatch, "feature type",
6890                                 change_notify, change_userdata, FALSE);
6891   dlg->ignore_partials = CheckBox (p, "Ignore partials", ChangeRemoveDuplicateFeatActionButon);
6892   SetObjectExtra (dlg->ignore_partials, dlg, NULL);
6893   dlg->case_sensitive = CheckBox (p, "Case sensitive", ChangeRemoveDuplicateFeatActionButon);
6894   SetObjectExtra (dlg->case_sensitive, dlg, NULL);
6895   SetStatus (dlg->case_sensitive, TRUE);
6896 
6897   dlg->remove_proteins = CheckBox (p, "Remove proteins", ChangeRemoveDuplicateFeatActionButon);
6898   SetObjectExtra (dlg->remove_proteins, dlg, NULL);
6899   SetStatus (dlg->remove_proteins, TRUE);
6900 
6901   dlg->constraint = ComplexConstraintDialog (p, change_notify, change_userdata);
6902   ChangeComplexConstraintFieldType (dlg->constraint, FieldType_feature_field, NULL, Macro_feature_type_any);
6903 
6904   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->feature_type,
6905                               (HANDLE) dlg->ignore_partials,
6906                               (HANDLE) dlg->case_sensitive,
6907                               (HANDLE) dlg->remove_proteins,
6908                               (HANDLE) dlg->constraint,
6909                               NULL);
6910 
6911   return (DialoG) p;
6912 }
6913 
6914 
6915 typedef struct updateeeplacedecnumbersdlg
6916 {
6917   DIALOG_MESSAGE_BLOCK
6918 
6919   ButtoN delete_improper_format;
6920   ButtoN delete_unrecognized;
6921   ButtoN delete_multiple_replacement;
6922 
6923   Nlm_ChangeNotifyProc change_notify;
6924   Pointer change_userdata;
6925 } UpdateReplacedECNumbersDlgData, PNTR UpdateReplacedECNumbersDlgPtr;
6926 
6927 
UpdateReplacedECNumbersToDialog(DialoG d,Pointer data)6928 static void UpdateReplacedECNumbersToDialog(DialoG d, Pointer data)
6929 {
6930   UpdateReplacedECNumbersDlgPtr dlg;
6931   UpdateReplacedEcNumbersActionPtr action;
6932 
6933   dlg = (UpdateReplacedECNumbersDlgPtr) GetObjectExtra (d);
6934   if (dlg == NULL) {
6935     return;
6936   }
6937   action = (UpdateReplacedEcNumbersActionPtr) data;
6938   if (action == NULL) {
6939     SetStatus (dlg->delete_improper_format, TRUE);
6940     SetStatus (dlg->delete_multiple_replacement, TRUE);
6941     SetStatus (dlg->delete_unrecognized, TRUE);
6942   } else {
6943     SetStatus (dlg->delete_improper_format, action->delete_improper_format);
6944     SetStatus (dlg->delete_multiple_replacement, action->delete_multiple_replacement);
6945     SetStatus (dlg->delete_unrecognized, action->delete_unrecognized);
6946   }
6947 }
6948 
6949 
UpdateReplacedECNumbersFromDialog(DialoG d)6950 static Pointer UpdateReplacedECNumbersFromDialog(DialoG d)
6951 {
6952   UpdateReplacedECNumbersDlgPtr dlg;
6953   UpdateReplacedEcNumbersActionPtr action;
6954 
6955   dlg = (UpdateReplacedECNumbersDlgPtr) GetObjectExtra (d);
6956   if (dlg == NULL) {
6957     return NULL;
6958   }
6959   action = (UpdateReplacedEcNumbersActionPtr) MemNew (sizeof (UpdateReplacedEcNumbersAction));
6960   action->delete_improper_format = GetStatus (dlg->delete_improper_format);
6961   action->delete_multiple_replacement = GetStatus (dlg->delete_multiple_replacement);
6962   action->delete_unrecognized = GetStatus (dlg->delete_unrecognized);
6963   return (Pointer) action;
6964 }
6965 
6966 
6967 
UpdateReplacedECNumbersDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6968 static DialoG UpdateReplacedECNumbersDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
6969 {
6970   UpdateReplacedECNumbersDlgPtr dlg;
6971   GrouP              p;
6972 
6973   dlg = (UpdateReplacedECNumbersDlgPtr) MemNew (sizeof (UpdateReplacedECNumbersDlgData));
6974   if (dlg == NULL)
6975   {
6976     return NULL;
6977   }
6978 
6979   p = HiddenGroup (h, 0, 3, NULL);
6980   SetObjectExtra (p, dlg, StdCleanupExtraProc);
6981   SetGroupSpacing (p, 10, 10);
6982 
6983   dlg->dialog = (DialoG) p;
6984   dlg->todialog = UpdateReplacedECNumbersToDialog;
6985   dlg->fromdialog = UpdateReplacedECNumbersFromDialog;
6986   dlg->change_notify = change_notify;
6987   dlg->change_userdata = change_userdata;
6988 
6989   dlg->delete_improper_format = CheckBox (p, "Delete improperly formatted EC numbers", ChangeMacroDialogBtn);
6990   SetObjectExtra (dlg->delete_improper_format, dlg, NULL);
6991   dlg->delete_unrecognized = CheckBox (p, "Delete unrecognized EC numbers", ChangeMacroDialogBtn);
6992   SetObjectExtra (dlg->delete_improper_format, dlg, NULL);
6993   dlg->delete_multiple_replacement = CheckBox (p, "Delete EC numbers replaced by more than one number", ChangeMacroDialogBtn);
6994   SetObjectExtra (dlg->delete_improper_format, dlg, NULL);
6995 
6996   return (DialoG) p;
6997 }
6998 
6999 
7000 typedef struct retranslatecdsaction {
7001   DIALOG_MESSAGE_BLOCK
7002   ButtoN obey_stop_codon;
7003 } RetranslateCDSActionDlgData, PNTR RetranslateCDSActionDlgPtr;
7004 
7005 
RetranslateCDSActionFromDialog(DialoG d)7006 static Pointer RetranslateCDSActionFromDialog (DialoG d)
7007 {
7008   RetranslateCdsActionPtr action = NULL;
7009   RetranslateCDSActionDlgPtr dlg;
7010 
7011   dlg = (RetranslateCDSActionDlgPtr) GetObjectExtra (d);
7012   if (dlg == NULL) {
7013     return NULL;
7014   }
7015 
7016   action = RetranslateCdsActionNew ();
7017   action->obey_stop_codon = GetStatus (dlg->obey_stop_codon);
7018 
7019   return action;
7020 }
7021 
7022 
RetranslateCDSActionToDialog(DialoG d,Pointer data)7023 static void RetranslateCDSActionToDialog (DialoG d, Pointer data)
7024 {
7025   RetranslateCdsActionPtr action;
7026   RetranslateCDSActionDlgPtr dlg;
7027 
7028   dlg = (RetranslateCDSActionDlgPtr) GetObjectExtra (d);
7029   if (dlg == NULL) {
7030     return;
7031   }
7032 
7033   action = (RetranslateCdsActionPtr)data;
7034   if (action) {
7035     SetStatus (dlg->obey_stop_codon, action->obey_stop_codon);
7036   } else {
7037     SetStatus (dlg->obey_stop_codon, TRUE);
7038   }
7039 }
7040 
7041 
RetranslateCdsActionDialog(GrouP h,Boolean edit,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)7042 static DialoG RetranslateCdsActionDialog (GrouP h, Boolean edit, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
7043 {
7044   RetranslateCDSActionDlgPtr dlg;
7045   GrouP              p;
7046 
7047   dlg = (RetranslateCDSActionDlgPtr) MemNew (sizeof (RetranslateCDSActionDlgData));
7048   if (dlg == NULL)
7049   {
7050     return NULL;
7051   }
7052 
7053   p = HiddenGroup (h, -1, 0, NULL);
7054   SetObjectExtra (p, dlg, StdCleanupExtraProc);
7055   SetGroupSpacing (p, 10, 10);
7056 
7057   dlg->dialog = (DialoG) p;
7058   dlg->todialog = RetranslateCDSActionToDialog;
7059   dlg->fromdialog = RetranslateCDSActionFromDialog;
7060 
7061   dlg->obey_stop_codon = CheckBox (p, "Obey stop codon", NULL);
7062   return (DialoG) p;
7063 }
7064 
7065 
PubFieldDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)7066 static DialoG PubFieldDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
7067 
7068 {
7069   return ValNodeSelectionDialog (h, GetPubFieldList(), TALL_SELECTION_LIST, ValNodeStringName,
7070                                 ValNodeSimpleDataFree, ValNodeStringCopy,
7071                                 ValNodeChoiceMatch, "pub field",
7072                                 change_notify, change_userdata, FALSE);
7073 }
7074 
7075 
7076 
7077 
7078 typedef struct PublicationConstraintdlg {
7079   DIALOG_MESSAGE_BLOCK
7080   PopuP pub_type;
7081   DialoG field_type;
7082   DialoG string_constraint;
7083 
7084   DialoG special_field;
7085   PopuP  special_field_type;
7086 
7087   Nlm_ChangeNotifyProc change_notify;
7088   Pointer change_userdata;
7089 } PublicationConstraintDialogData, PNTR PublicationConstraintDialogPtr;
7090 
7091 
ClearPublicationConstraintDialogText(DialoG d)7092 static void ClearPublicationConstraintDialogText (DialoG d)
7093 {
7094   PublicationConstraintDialogPtr dlg;
7095 
7096   dlg = (PublicationConstraintDialogPtr) GetObjectExtra (d);
7097   if (dlg == NULL) {
7098     return;
7099   }
7100 
7101   ClearStringConstraintDialogText (dlg->string_constraint);
7102 }
7103 
7104 
DialogToPublicationConstraint(DialoG d)7105 static Pointer DialogToPublicationConstraint (DialoG d)
7106 {
7107   PublicationConstraintDialogPtr dlg;
7108   StringConstraintPtr    string_constraint = NULL;
7109   PublicationConstraintPtr       constraint = NULL;
7110   PubFieldConstraintPtr  p;
7111   Int4                   val;
7112   ValNodePtr             vnp;
7113 
7114   dlg = (PublicationConstraintDialogPtr) GetObjectExtra (d);
7115   if (dlg == NULL) return NULL;
7116 
7117   constraint = PublicationConstraintNew ();
7118   val = GetValue (dlg->pub_type);
7119   switch (val) {
7120     case 2:
7121       constraint->type = Pub_type_published;
7122       break;
7123     case 3:
7124       constraint->type = Pub_type_unpublished;
7125       break;
7126     case 4:
7127       constraint->type = Pub_type_in_press;
7128       break;
7129     case 5:
7130       constraint->type = Pub_type_submitter_block;
7131       break;
7132     default:
7133       constraint->type = Pub_type_any;
7134       break;
7135   }
7136   string_constraint = DialogToPointer (dlg->string_constraint);
7137   vnp = DialogToPointer (dlg->field_type);
7138   if (vnp != NULL && !IsStringConstraintEmpty (string_constraint)) {
7139     p = PubFieldConstraintNew ();
7140     p->field = vnp->choice;
7141     p->constraint = string_constraint;
7142     string_constraint = NULL;
7143     constraint->field = p;
7144   }
7145   vnp = ValNodeFree (vnp);
7146   string_constraint = StringConstraintFree (string_constraint);
7147 
7148   vnp = DialogToPointer (dlg->special_field);
7149   if (vnp != NULL) {
7150     val = GetValue (dlg->special_field_type);
7151     if (val > 1 && val <= k_NumSpecialPubFieldWords + 1) {
7152       constraint->special_field = PubFieldSpecialConstraintNew ();
7153       constraint->special_field->field = vnp->choice;
7154       constraint->special_field->constraint = ValNodeNew (NULL);
7155       switch (val) {
7156         case 2:
7157           constraint->special_field->constraint->choice = PubFieldSpecialConstraintType_is_present;
7158           break;
7159         case 3:
7160           constraint->special_field->constraint->choice = PubFieldSpecialConstraintType_is_not_present;
7161           break;
7162         case 4:
7163           constraint->special_field->constraint->choice = PubFieldSpecialConstraintType_is_all_caps;
7164           break;
7165         case 5:
7166           constraint->special_field->constraint->choice = PubFieldSpecialConstraintType_is_all_lower;
7167           break;
7168         case 6:
7169           constraint->special_field->constraint->choice = PubFieldSpecialConstraintType_is_all_punct;
7170           break;
7171       }
7172     }
7173     vnp = ValNodeFree (vnp);
7174   }
7175 
7176   return (Pointer) constraint;
7177 }
7178 
7179 
PublicationConstraintToDialog(DialoG d,Pointer data)7180 static void PublicationConstraintToDialog (DialoG d, Pointer data)
7181 {
7182   PublicationConstraintDialogPtr dlg;
7183   ValNode vn;
7184   PublicationConstraintPtr constraint;
7185 
7186   dlg = (PublicationConstraintDialogPtr) GetObjectExtra (d);
7187   if (dlg == NULL) return;
7188 
7189   constraint = (PublicationConstraintPtr) data;
7190   if (constraint == NULL) {
7191     SetValue (dlg->pub_type, 1);
7192     PointerToDialog (dlg->field_type, NULL);
7193     PointerToDialog (dlg->string_constraint, NULL);
7194     PointerToDialog (dlg->special_field, NULL);
7195     SetValue (dlg->special_field_type, 1);
7196   } else {
7197     switch (constraint->type) {
7198       case Pub_type_published:
7199         SetValue (dlg->pub_type, 2);
7200         break;
7201       case Pub_type_unpublished:
7202         SetValue (dlg->pub_type, 3);
7203         break;
7204       case Pub_type_in_press:
7205         SetValue (dlg->pub_type, 4);
7206         break;
7207       case Pub_type_submitter_block:
7208         SetValue (dlg->pub_type, 5);
7209         break;
7210       case Pub_type_any:
7211       default:
7212         SetValue (dlg->pub_type, 1);
7213         break;
7214     }
7215     if (constraint->field == NULL) {
7216       PointerToDialog (dlg->field_type, NULL);
7217       PointerToDialog (dlg->string_constraint, NULL);
7218     } else {
7219       vn.choice = (Uint1)constraint->field->field;
7220       vn.data.ptrvalue = NULL;
7221       vn.next = NULL;
7222       PointerToDialog (dlg->field_type, &vn);
7223       PointerToDialog (dlg->string_constraint, constraint->field->constraint);
7224     }
7225     if (constraint->special_field == NULL) {
7226       PointerToDialog (dlg->special_field, NULL);
7227       SetValue (dlg->special_field_type, 1);
7228     } else {
7229       vn.choice = (Uint1)(constraint->special_field->field);
7230       vn.data.ptrvalue = NULL;
7231       vn.next = NULL;
7232       PointerToDialog (dlg->special_field, &vn);
7233       if (constraint->special_field->constraint == NULL) {
7234         SetValue (dlg->special_field_type, 1);
7235       } else {
7236         switch (constraint->special_field->constraint->choice) {
7237           case PubFieldSpecialConstraintType_is_present:
7238             SetValue (dlg->special_field_type, 2);
7239             break;
7240           case PubFieldSpecialConstraintType_is_not_present:
7241             SetValue (dlg->special_field_type, 3);
7242             break;
7243           case PubFieldSpecialConstraintType_is_all_caps:
7244             SetValue (dlg->special_field_type, 4);
7245             break;
7246           case PubFieldSpecialConstraintType_is_all_lower:
7247             SetValue (dlg->special_field_type, 5);
7248             break;
7249           case PubFieldSpecialConstraintType_is_all_punct:
7250             SetValue (dlg->special_field_type, 6);
7251             break;
7252           default:
7253             SetValue (dlg->special_field_type, 1);
7254             break;
7255         }
7256       }
7257     }
7258   }
7259 }
7260 
TestPublicationConstraintDialog(DialoG d)7261 static ValNodePtr TestPublicationConstraintDialog (DialoG d)
7262 {
7263   PublicationConstraintPtr p;
7264   ValNodePtr err_list = NULL;
7265 
7266   p = DialogToPointer (d);
7267   if (IsPublicationConstraintEmpty (p)) {
7268     ValNodeAddPointer (&err_list, 0, "No pub constraint");
7269   }
7270   p = PublicationConstraintFree (p);
7271   return err_list;
7272 }
7273 
7274 
ChangePublicationConstraintPopup(PopuP p)7275 static void ChangePublicationConstraintPopup (PopuP p)
7276 {
7277   PublicationConstraintDialogPtr dlg;
7278 
7279   dlg = (PublicationConstraintDialogPtr) GetObjectExtra (p);
7280   if (dlg != NULL && dlg->change_notify != NULL) {
7281     (dlg->change_notify) (dlg->change_userdata);
7282   }
7283 }
7284 
7285 
PublicationConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)7286 static DialoG PublicationConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
7287 {
7288   PublicationConstraintDialogPtr dlg;
7289   GrouP      p, g1, g2;
7290   Int4       i;
7291 
7292   dlg = (PublicationConstraintDialogPtr) MemNew (sizeof (PublicationConstraintDialogData));
7293   if (dlg == NULL)
7294   {
7295     return NULL;
7296   }
7297 
7298   p = HiddenGroup (h, -1, 0, NULL);
7299   SetObjectExtra (p, dlg, StdCleanupExtraProc);
7300 
7301   dlg->dialog = (DialoG) p;
7302   dlg->todialog = PublicationConstraintToDialog;
7303   dlg->fromdialog = DialogToPublicationConstraint;
7304   dlg->testdialog = TestPublicationConstraintDialog;
7305 
7306   dlg->change_notify = change_notify;
7307   dlg->change_userdata = change_userdata;
7308 
7309   g1 = HiddenGroup (p, 2, 0, NULL);
7310   StaticPrompt (g1, "Publication Status", 0, dialogTextHeight, programFont, 'r');
7311   dlg->pub_type = PopupList (g1, TRUE, ChangePublicationConstraintPopup);
7312   SetObjectExtra (dlg->pub_type, dlg, NULL);
7313   PopupItem (dlg->pub_type, "Any");
7314   PopupItem (dlg->pub_type, "Published");
7315   PopupItem (dlg->pub_type, "Unpublished");
7316   PopupItem (dlg->pub_type, "In-press");
7317   PopupItem (dlg->pub_type, "Submitter block");
7318   SetValue (dlg->pub_type, 1);
7319 
7320   g2 = HiddenGroup (p, 2, 0, NULL);
7321   dlg->field_type = PubFieldDialog (g2, change_notify, change_userdata);
7322   dlg->string_constraint = StringConstraintDialog (g2, NULL, FALSE, change_notify, change_userdata);
7323 
7324   dlg->special_field = PubFieldDialog (g2, change_notify, change_userdata);
7325   dlg->special_field_type = PopupList (g2, TRUE, ChangePublicationConstraintPopup);
7326   SetObjectExtra (dlg->special_field_type, dlg, NULL);
7327   PopupItem (dlg->special_field_type, "Any");
7328   for (i = 0; i < k_NumSpecialPubFieldWords; i++) {
7329     PopupItem (dlg->special_field_type, s_SpecialPubFieldWords[i]);
7330   }
7331   SetValue (dlg->special_field_type, 1);
7332 
7333   AlignObjects (ALIGN_CENTER, (HANDLE) g1, (HANDLE) g2, NULL);
7334 
7335   return (DialoG) p;
7336 }
7337 
7338 
7339 
7340 typedef struct quantityconstraintdlg {
7341   DIALOG_MESSAGE_BLOCK
7342   PopuP quantity_type;
7343   TexT  quantity;
7344 
7345   Nlm_ChangeNotifyProc change_notify;
7346   Pointer change_userdata;
7347 } QuantityConstraintDlgDaga, PNTR QuantityConstraintDlgPtr;
7348 
7349 
QuantityConstraintToDialog(DialoG d,Pointer data)7350 static void QuantityConstraintToDialog (DialoG d, Pointer data)
7351 {
7352   QuantityConstraintDlgPtr dlg;
7353   ValNodePtr               vnp;
7354   Char                     buf[15];
7355 
7356   dlg = (QuantityConstraintDlgPtr) GetObjectExtra (d);
7357 
7358   if (dlg == NULL) {
7359     return;
7360   }
7361 
7362   vnp = (ValNodePtr) data;
7363   if (vnp == NULL) {
7364     SetValue (dlg->quantity_type, 1);
7365     Hide (dlg->quantity);
7366   } else if (vnp->choice == QuantityConstraint_equals) {
7367     SetValue (dlg->quantity_type, 2);
7368     sprintf (buf, "%d", vnp->data.intvalue);
7369     SetTitle (dlg->quantity, buf);
7370     Show (dlg->quantity);
7371   } else if (vnp->choice == QuantityConstraint_greater_than) {
7372     SetValue (dlg->quantity_type, 3);
7373     sprintf (buf, "%d", vnp->data.intvalue);
7374     SetTitle (dlg->quantity, buf);
7375     Show (dlg->quantity);
7376   } else if (vnp->choice == QuantityConstraint_less_than) {
7377     SetValue (dlg->quantity_type, 4);
7378     sprintf (buf, "%d", vnp->data.intvalue);
7379     SetTitle (dlg->quantity, buf);
7380     Show (dlg->quantity);
7381   } else {
7382     SetValue (dlg->quantity_type, 1);
7383     Hide (dlg->quantity);
7384   }
7385 }
7386 
7387 
DialogToQuantityConstraint(DialoG d)7388 static Pointer DialogToQuantityConstraint (DialoG d)
7389 {
7390   QuantityConstraintDlgPtr dlg;
7391   ValNodePtr               vnp = NULL;
7392   Int2                     val;
7393   CharPtr                  num_text;
7394 
7395   dlg = (QuantityConstraintDlgPtr) GetObjectExtra (d);
7396 
7397   if (dlg == NULL) {
7398     return NULL;
7399   }
7400 
7401   if (!TextHasNoText (dlg->quantity)) {
7402     num_text = SaveStringFromText (dlg->quantity);
7403     if (StringIsAllDigits(num_text)) {
7404       val = GetValue (dlg->quantity_type);
7405       switch (val) {
7406         case 2:
7407           vnp = ValNodeNew (NULL);
7408           vnp->choice = QuantityConstraint_equals;
7409           vnp->data.intvalue = atoi (num_text);
7410           break;
7411         case 3:
7412           vnp = ValNodeNew (NULL);
7413           vnp->choice = QuantityConstraint_greater_than;
7414           vnp->data.intvalue = atoi (num_text);
7415           break;
7416         case 4:
7417           vnp = ValNodeNew (NULL);
7418           vnp->choice = QuantityConstraint_less_than;
7419           vnp->data.intvalue = atoi (num_text);
7420           break;
7421       }
7422     }
7423     num_text = MemFree (num_text);
7424   }
7425   return vnp;
7426 }
7427 
7428 
TestQuantityConstraintDialog(DialoG d)7429 static ValNodePtr TestQuantityConstraintDialog (DialoG d)
7430 {
7431   QuantityConstraintDlgPtr dlg;
7432   Int2                     val;
7433   CharPtr                  num_text;
7434   ValNodePtr err_list = NULL;
7435 
7436   dlg = (QuantityConstraintDlgPtr) GetObjectExtra (d);
7437   if (dlg != NULL) {
7438     val = GetValue (dlg->quantity_type);
7439     if (val > 1 && val <= k_NumQuantityWords + 1) {
7440       if (TextHasNoText (dlg->quantity)) {
7441         ValNodeAddPointer (&err_list, 0, "missing value");
7442       } else {
7443         num_text = SaveStringFromText (dlg->quantity);
7444         if (!StringIsAllDigits (num_text)) {
7445           ValNodeAddPointer (&err_list, 0, "bad value");
7446         }
7447         num_text = MemFree (num_text);
7448       }
7449     }
7450   }
7451   return err_list;
7452 }
7453 
7454 
ChangeQuantityConstraintQuantityType(PopuP p)7455 static void ChangeQuantityConstraintQuantityType (PopuP p)
7456 {
7457   QuantityConstraintDlgPtr dlg;
7458   Int2 val;
7459 
7460   dlg = (QuantityConstraintDlgPtr) GetObjectExtra (p);
7461   if (dlg == NULL) {
7462     return;
7463   }
7464   val = GetValue (dlg->quantity_type);
7465 
7466   if (val < 2 || val > k_NumQuantityWords + 1) {
7467     Hide (dlg->quantity);
7468   } else {
7469     Show (dlg->quantity);
7470   }
7471   if (dlg->change_notify != NULL) {
7472     (dlg->change_notify)(dlg->change_userdata);
7473   }
7474 }
7475 
7476 
ChangeQuantityConstraintQuantity(TexT t)7477 static void ChangeQuantityConstraintQuantity (TexT t)
7478 {
7479   QuantityConstraintDlgPtr dlg;
7480 
7481   dlg = (QuantityConstraintDlgPtr) GetObjectExtra (t);
7482   if (dlg != NULL && dlg->change_notify != NULL) {
7483     (dlg->change_notify)(dlg->change_userdata);
7484   }
7485 }
7486 
7487 
QuantityConstraintDialog(GrouP h,CharPtr title,CharPtr default_val,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)7488 static DialoG QuantityConstraintDialog (GrouP h, CharPtr title, CharPtr default_val, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
7489 {
7490   QuantityConstraintDlgPtr dlg;
7491   GrouP                    p;
7492   Int4                     i;
7493 
7494   dlg = (QuantityConstraintDlgPtr) MemNew (sizeof (QuantityConstraintDlgDaga));
7495   if (dlg == NULL)
7496   {
7497     return NULL;
7498   }
7499 
7500   p = HiddenGroup (h, 3, 0, NULL);
7501   SetGroupSpacing (p, 10, 10);
7502   SetObjectExtra (p, dlg, StdCleanupExtraProc);
7503 
7504   dlg->dialog = (DialoG) p;
7505   dlg->todialog = QuantityConstraintToDialog;
7506   dlg->fromdialog = DialogToQuantityConstraint;
7507   dlg->testdialog = TestQuantityConstraintDialog;
7508 
7509   dlg->change_notify = change_notify;
7510   dlg->change_userdata = change_userdata;
7511 
7512   StaticPrompt (p, title, 0, dialogTextHeight, programFont, 'r');
7513   dlg->quantity_type = PopupList (p, TRUE, ChangeQuantityConstraintQuantityType);
7514   SetObjectExtra (dlg->quantity_type, dlg, NULL);
7515   PopupItem (dlg->quantity_type, "Any");
7516   for (i = 0; i < k_NumQuantityWords; i++) {
7517     PopupItem (dlg->quantity_type, s_QuantityWords[i]);
7518   }
7519   SetValue (dlg->quantity_type, 1);
7520   dlg->quantity = DialogText (p, default_val, 5, ChangeQuantityConstraintQuantity);
7521   SetObjectExtra (dlg->quantity, dlg, NULL);
7522   Hide (dlg->quantity);
7523 
7524   return (DialoG) p;
7525 }
7526 
7527 
7528 typedef struct sequenceconstraintdlg {
7529   DIALOG_MESSAGE_BLOCK
7530   GrouP seqtype;
7531   GrouP rna_subtype_grp;
7532   DialoG rna_subtype;
7533   ButtoN feat_present;
7534   DialoG feature_type;
7535   DialoG num_type_features;
7536   DialoG num_features;
7537   DialoG length;
7538   DialoG id;
7539   PopuP  strandedness;
7540 
7541   Nlm_ChangeNotifyProc change_notify;
7542   Pointer change_userdata;
7543 } SequenceConstraintDlgData, PNTR SequenceConstraintDlgPtr;
7544 
7545 
ChangeSequenceConstraintButton(ButtoN b)7546 static void ChangeSequenceConstraintButton (ButtoN b)
7547 {
7548   SequenceConstraintDlgPtr dlg;
7549 
7550   dlg = (SequenceConstraintDlgPtr) GetObjectExtra (b);
7551   if (dlg == NULL) return;
7552 
7553   if (GetStatus (dlg->feat_present)) {
7554     Enable (dlg->feature_type);
7555   } else {
7556     Disable (dlg->feature_type);
7557   }
7558   if (dlg->change_notify != NULL) {
7559     (dlg->change_notify) (dlg->change_userdata);
7560   }
7561 }
7562 
7563 
ChangeSequenceConstraintGroup(GrouP g)7564 static void ChangeSequenceConstraintGroup (GrouP g)
7565 {
7566   SequenceConstraintDlgPtr dlg;
7567 
7568   dlg = (SequenceConstraintDlgPtr) GetObjectExtra (g);
7569   if (dlg == NULL) return;
7570 
7571   if (GetValue (dlg->seqtype) == 4) {
7572     Show (dlg->rna_subtype_grp);
7573   } else {
7574     Hide (dlg->rna_subtype_grp);
7575   }
7576 
7577   if (dlg->change_notify != NULL) {
7578     (dlg->change_notify) (dlg->change_userdata);
7579   }
7580 }
7581 
7582 
ChangeSequenceConstraintPopup(PopuP p)7583 static void ChangeSequenceConstraintPopup (PopuP p)
7584 {
7585   SequenceConstraintDlgPtr dlg;
7586 
7587   dlg = (SequenceConstraintDlgPtr) GetObjectExtra (p);
7588   if (dlg == NULL) return;
7589 
7590   if (dlg->change_notify != NULL) {
7591     (dlg->change_notify) (dlg->change_userdata);
7592   }
7593 }
7594 
7595 
SequenceConstraintToDialog(DialoG d,Pointer data)7596 static void SequenceConstraintToDialog (DialoG d, Pointer data)
7597 {
7598   SequenceConstraintDlgPtr dlg;
7599   SequenceConstraintPtr constraint;
7600   ValNode vn;
7601 
7602   dlg = (SequenceConstraintDlgPtr) GetObjectExtra (d);
7603   if (dlg == NULL) return;
7604 
7605   constraint = (SequenceConstraintPtr) data;
7606   if (constraint == NULL) {
7607     SetValue (dlg->seqtype, 2);
7608     PointerToDialog (dlg->rna_subtype, NULL);
7609     Hide (dlg->rna_subtype_grp);
7610     SetStatus (dlg->feat_present, FALSE);
7611     PointerToDialog (dlg->feature_type, NULL);
7612     PointerToDialog (dlg->num_type_features, NULL);
7613     PointerToDialog (dlg->id, NULL);
7614     PointerToDialog (dlg->num_features, NULL);
7615     PointerToDialog (dlg->length, NULL);
7616     SetValue (dlg->strandedness, 1);
7617   } else {
7618     if (constraint->seqtype == NULL) {
7619       SetValue (dlg->seqtype, 2);
7620       PointerToDialog (dlg->rna_subtype, NULL);
7621       Hide (dlg->rna_subtype_grp);
7622     } else {
7623       switch (constraint->seqtype->choice) {
7624         case SequenceConstraintMolTypeConstraint_any :
7625           SetValue (dlg->seqtype, 1);
7626           PointerToDialog (dlg->rna_subtype, NULL);
7627           Hide (dlg->rna_subtype_grp);
7628           break;
7629         case SequenceConstraintMolTypeConstraint_nucleotide :
7630           SetValue (dlg->seqtype, 2);
7631           PointerToDialog (dlg->rna_subtype, NULL);
7632           Hide (dlg->rna_subtype_grp);
7633           break;
7634         case SequenceConstraintMolTypeConstraint_dna :
7635           SetValue (dlg->seqtype, 3);
7636           PointerToDialog (dlg->rna_subtype, NULL);
7637           Hide (dlg->rna_subtype_grp);
7638           break;
7639         case SequenceConstraintMolTypeConstraint_rna :
7640           SetValue (dlg->seqtype, 4);
7641           vn.choice = constraint->seqtype->data.intvalue;
7642           vn.data.ptrvalue = NULL;
7643           vn.next = NULL;
7644           PointerToDialog (dlg->rna_subtype, &vn);
7645           Show (dlg->rna_subtype_grp);
7646           break;
7647         case SequenceConstraintMolTypeConstraint_protein :
7648           SetValue (dlg->seqtype, 5);
7649           PointerToDialog (dlg->rna_subtype, NULL);
7650           Hide (dlg->rna_subtype_grp);
7651           break;
7652       }
7653     }
7654 
7655     if (constraint->feature == Macro_feature_type_any) {
7656       SetStatus (dlg->feat_present, FALSE);
7657       PointerToDialog (dlg->feature_type, NULL);
7658     } else {
7659       SetStatus (dlg->feat_present, TRUE);
7660       vn.choice = (Uint1)constraint->feature;
7661       vn.data.ptrvalue = NULL;
7662       vn.next = NULL;
7663       PointerToDialog (dlg->feature_type, &vn);
7664     }
7665     PointerToDialog (dlg->num_type_features, constraint->num_type_features);
7666 
7667     PointerToDialog (dlg->id, constraint->id);
7668     PointerToDialog (dlg->num_features, constraint->num_features);
7669     PointerToDialog (dlg->length, constraint->length);
7670 
7671     switch (constraint->strandedness) {
7672       case Feature_strandedness_constraint_any:
7673         SetValue (dlg->strandedness, 1);
7674         break;
7675       case Feature_strandedness_constraint_minus_only:
7676         SetValue (dlg->strandedness, 2);
7677         break;
7678       case Feature_strandedness_constraint_plus_only:
7679         SetValue (dlg->strandedness, 3);
7680         break;
7681       case Feature_strandedness_constraint_at_least_one_minus:
7682         SetValue (dlg->strandedness, 4);
7683         break;
7684       case Feature_strandedness_constraint_at_least_one_plus:
7685         SetValue (dlg->strandedness, 5);
7686         break;
7687       case Feature_strandedness_constraint_no_minus:
7688         SetValue (dlg->strandedness, 6);
7689         break;
7690       case Feature_strandedness_constraint_no_plus:
7691         SetValue (dlg->strandedness, 7);
7692         break;
7693     }
7694   }
7695   ChangeSequenceConstraintButton (dlg->feat_present);
7696 }
7697 
7698 
SequenceConstraintFromDialog(DialoG d)7699 static Pointer SequenceConstraintFromDialog (DialoG d)
7700 {
7701   SequenceConstraintDlgPtr dlg;
7702   SequenceConstraintPtr constraint;
7703   ValNodePtr vnp;
7704   Int4 val;
7705 
7706   dlg = (SequenceConstraintDlgPtr) GetObjectExtra (d);
7707   if (dlg == NULL) return NULL;
7708   constraint = SequenceConstraintNew();
7709 
7710   val = GetValue (dlg->seqtype);
7711   switch (val) {
7712     case 1:
7713       /* don't bother to fill in, it's optional */
7714       break;
7715     case 2:
7716       constraint->seqtype = ValNodeNew (NULL);
7717       constraint->seqtype->choice = SequenceConstraintMolTypeConstraint_nucleotide;
7718       break;
7719     case 3:
7720       constraint->seqtype = ValNodeNew (NULL);
7721       constraint->seqtype->choice = SequenceConstraintMolTypeConstraint_dna;
7722       break;
7723     case 4:
7724       constraint->seqtype = ValNodeNew (NULL);
7725       constraint->seqtype->choice = SequenceConstraintMolTypeConstraint_rna;
7726       vnp = DialogToPointer (dlg->rna_subtype);
7727       if (vnp == NULL) {
7728         constraint->seqtype->data.intvalue = Sequence_constraint_rnamol_any;
7729       } else {
7730         constraint->seqtype->data.intvalue = vnp->choice;
7731       }
7732       break;
7733     case 5:
7734       constraint->seqtype = ValNodeNew (NULL);
7735       constraint->seqtype->choice = SequenceConstraintMolTypeConstraint_protein;
7736       break;
7737   }
7738 
7739   if (GetStatus (dlg->feat_present)) {
7740     vnp = DialogToPointer (dlg->feature_type);
7741     if (vnp == NULL) {
7742       constraint->feature = Macro_feature_type_any;
7743     } else {
7744       constraint->feature = vnp->choice;
7745     }
7746     vnp = ValNodeFree (vnp);
7747     constraint->num_type_features = DialogToPointer (dlg->num_type_features);
7748   } else {
7749     constraint->feature = Macro_feature_type_any;
7750   }
7751 
7752   constraint->id = DialogToPointer (dlg->id);
7753   if (IsStringConstraintEmpty (constraint->id)) {
7754     constraint->id = StringConstraintFree (constraint->id);
7755   }
7756   constraint->num_features = DialogToPointer (dlg->num_features);
7757   constraint->length = DialogToPointer (dlg->length);
7758   val = GetValue (dlg->strandedness);
7759   switch (val) {
7760     case 1:
7761       constraint->strandedness = Feature_strandedness_constraint_any;
7762       break;
7763     case 2:
7764       constraint->strandedness = Feature_strandedness_constraint_minus_only;
7765       break;
7766     case 3:
7767       constraint->strandedness = Feature_strandedness_constraint_plus_only;
7768       break;
7769     case 4:
7770       constraint->strandedness = Feature_strandedness_constraint_at_least_one_minus;
7771       break;
7772     case 5:
7773       constraint->strandedness = Feature_strandedness_constraint_at_least_one_plus;
7774       break;
7775     case 6:
7776       constraint->strandedness = Feature_strandedness_constraint_no_minus;
7777       break;
7778     case 7:
7779       constraint->strandedness = Feature_strandedness_constraint_no_plus;
7780       break;
7781   }
7782   return constraint;
7783 }
7784 
7785 
FeatureTypeDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)7786 NLM_EXTERN DialoG FeatureTypeDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
7787 {
7788   ValNodePtr feature_list = NULL;
7789 
7790   AddAllFeaturesToChoiceList (&feature_list);
7791   return ValNodeSelectionDialog (h, feature_list, TALL_SELECTION_LIST, ValNodeStringName,
7792                                 ValNodeSimpleDataFree, ValNodeStringCopy,
7793                                 ValNodeChoiceMatch, "feature type",
7794                                 change_notify, change_userdata, FALSE);
7795 }
7796 
7797 
GetFeatureTypeFromFeatureTypeDialog(DialoG d)7798 NLM_EXTERN Uint2 GetFeatureTypeFromFeatureTypeDialog (DialoG d)
7799 {
7800   ValNodePtr vnp;
7801   Uint2 feature;
7802 
7803   vnp = DialogToPointer (d);
7804   if (vnp == NULL) {
7805     feature = Macro_feature_type_any;
7806   } else {
7807     feature = vnp->choice;
7808   }
7809   vnp = ValNodeFree (vnp);
7810   return feature;
7811 }
7812 
7813 
SetFeatureTypeInFeatureTypeDialog(DialoG d,Uint2 feature)7814 NLM_EXTERN void SetFeatureTypeInFeatureTypeDialog (DialoG d, Uint2 feature)
7815 {
7816   ValNode vn;
7817 
7818   MemSet (&vn, 0, sizeof (ValNode));
7819   vn.choice = (Uint1)feature;
7820   PointerToDialog (d, &vn);
7821 }
7822 
7823 
FeatureTypeDialogMulti(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)7824 NLM_EXTERN DialoG FeatureTypeDialogMulti (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
7825 {
7826   ValNodePtr feature_list = NULL;
7827 
7828   ValNodeAddPointer (&feature_list, Macro_feature_type_any, StringSave ("Any"));
7829   AddAllFeaturesToChoiceList (&feature_list);
7830   return ValNodeSelectionDialog (h, feature_list, TALL_SELECTION_LIST, ValNodeStringName,
7831                                 ValNodeSimpleDataFree, ValNodeStringCopy,
7832                                 ValNodeChoiceMatch, "feature type",
7833                                 change_notify, change_userdata, FALSE);
7834 }
7835 
7836 
TestSequenceConstraintDialog(DialoG d)7837 static ValNodePtr TestSequenceConstraintDialog (DialoG d)
7838 {
7839   SequenceConstraintDlgPtr dlg;
7840   ValNodePtr err_list = NULL;
7841   SequenceConstraintPtr constraint;
7842 
7843   dlg = (SequenceConstraintDlgPtr) GetObjectExtra (d);
7844   if (dlg != NULL) {
7845     constraint = DialogToPointer (d);
7846     if (IsSequenceConstraintEmpty (constraint)) {
7847       ValNodeAddPointer (&err_list, 0, "empty constraint");
7848     }
7849     ValNodeLink (&err_list, TestDialog (dlg->num_features));
7850     ValNodeLink (&err_list, TestDialog (dlg->length));
7851     constraint = SequenceConstraintFree (constraint);
7852   }
7853   return err_list;
7854 }
7855 
7856 
SequenceConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)7857 NLM_EXTERN DialoG SequenceConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
7858 {
7859   SequenceConstraintDlgPtr dlg;
7860   GrouP p, g, grp1, grp2;
7861   ValNodePtr rna_subtypes = NULL;
7862 
7863   dlg = (SequenceConstraintDlgPtr) MemNew (sizeof (SequenceConstraintDlgData));
7864   p = HiddenGroup (h, 2, 0, NULL);
7865   SetGroupSpacing (p, 10, 10);
7866   SetObjectExtra (p, dlg, StdCleanupExtraProc);
7867   dlg->dialog = (DialoG) p;
7868   dlg->todialog = SequenceConstraintToDialog;
7869   dlg->fromdialog = SequenceConstraintFromDialog;
7870   dlg->testdialog = TestSequenceConstraintDialog;
7871   dlg->change_notify = change_notify;
7872   dlg->change_userdata = change_userdata;
7873 
7874   grp1 = HiddenGroup (p, -1, 0, NULL);
7875   dlg->seqtype = HiddenGroup (grp1, 5, 0, ChangeSequenceConstraintGroup);
7876   SetObjectExtra (dlg->seqtype, dlg, NULL);
7877   RadioButton (dlg->seqtype, "Any sequence");
7878   RadioButton (dlg->seqtype, "Nucleotides");
7879   RadioButton (dlg->seqtype, "DNA");
7880   RadioButton (dlg->seqtype, "RNA");
7881   RadioButton (dlg->seqtype, "Proteins");
7882   SetValue (dlg->seqtype, 2);
7883   dlg->rna_subtype_grp = HiddenGroup (grp1, 2, 0, NULL);
7884   StaticPrompt (dlg->rna_subtype_grp, "RNA Type", 0, dialogTextHeight, programFont, 'r');
7885   AddAllRNASubtypesToChoiceList (&rna_subtypes);
7886   dlg->rna_subtype = ValNodeSelectionDialog (dlg->rna_subtype_grp, rna_subtypes, TALL_SELECTION_LIST, ValNodeStringName,
7887                                 ValNodeSimpleDataFree, ValNodeStringCopy,
7888                                 ValNodeChoiceMatch, "rna subtype",
7889                                 change_notify, change_userdata, FALSE);
7890 
7891   Hide (dlg->rna_subtype_grp);
7892 
7893   g = HiddenGroup (grp1, 3, 0, NULL);
7894   dlg->feat_present = CheckBox (g, "Feature type", ChangeSequenceConstraintButton);
7895   SetObjectExtra (dlg->feat_present, dlg, NULL);
7896   dlg->feature_type = FeatureTypeDialog (g, change_notify, change_userdata);
7897   dlg->num_type_features = QuantityConstraintDialog (g, "Number present", "1", change_notify, change_userdata);
7898   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->seqtype,
7899                               (HANDLE) dlg->rna_subtype_grp,
7900                               (HANDLE) g,
7901                                NULL);
7902 
7903   StaticPrompt (g, "Strandedness of features", 0, popupMenuHeight, programFont, 'r');
7904   dlg->strandedness = PopupList (g, TRUE, ChangeSequenceConstraintPopup);
7905   SetObjectExtra (dlg->strandedness, dlg, NULL);
7906   PopupItem (dlg->strandedness, "Any");
7907   PopupItem (dlg->strandedness, SummarizeFeatureStrandedness(Feature_strandedness_constraint_minus_only));
7908   PopupItem (dlg->strandedness, SummarizeFeatureStrandedness(Feature_strandedness_constraint_plus_only));
7909   PopupItem (dlg->strandedness, SummarizeFeatureStrandedness(Feature_strandedness_constraint_at_least_one_minus));
7910   PopupItem (dlg->strandedness, SummarizeFeatureStrandedness(Feature_strandedness_constraint_at_least_one_plus));
7911   PopupItem (dlg->strandedness, SummarizeFeatureStrandedness(Feature_strandedness_constraint_no_minus));
7912   PopupItem (dlg->strandedness, SummarizeFeatureStrandedness(Feature_strandedness_constraint_no_plus));
7913 
7914   grp2 = HiddenGroup (p, -1, 0, NULL);
7915   dlg->id = StringConstraintDialog (grp2, "Where sequence ID", FALSE, change_notify, change_userdata);
7916   dlg->num_features = QuantityConstraintDialog (grp2, "Number of features present (any type)", "1", change_notify, change_userdata);
7917   dlg->length = QuantityConstraintDialog (grp2, "Length of sequence", "200", change_notify, change_userdata);
7918   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->id,
7919                               (HANDLE) dlg->num_features,
7920                               (HANDLE) dlg->length,
7921                                NULL);
7922 
7923 
7924   return (DialoG) p;
7925 }
7926 
7927 
7928 typedef struct molinfoconstraintdlg {
7929   DIALOG_MESSAGE_BLOCK
7930   DialoG field;
7931   ButtoN is_not;
7932 
7933   Nlm_ChangeNotifyProc change_notify;
7934   Pointer change_userdata;
7935 } MolinfoConstraintDlgDaga, PNTR MolinfoConstraintDlgPtr;
7936 
7937 
MolinfoConstraintToDialog(DialoG d,Pointer data)7938 static void MolinfoConstraintToDialog (DialoG d, Pointer data)
7939 {
7940   MolinfoConstraintDlgPtr   dlg;
7941   MolinfoFieldConstraintPtr constraint;
7942 
7943   dlg = (MolinfoConstraintDlgPtr) GetObjectExtra (d);
7944 
7945   if (dlg == NULL) {
7946     return;
7947   }
7948 
7949   constraint = (MolinfoFieldConstraintPtr) data;
7950   if (constraint == NULL) {
7951     PointerToDialog (dlg->field, NULL);
7952     SetStatus (dlg->is_not, FALSE);
7953   } else {
7954     PointerToDialog (dlg->field, constraint->field);
7955     SetStatus (dlg->is_not, constraint->is_not);
7956   }
7957 }
7958 
7959 
DialogToMolinfoConstraint(DialoG d)7960 static Pointer DialogToMolinfoConstraint (DialoG d)
7961 {
7962   MolinfoConstraintDlgPtr   dlg;
7963   MolinfoFieldConstraintPtr constraint = NULL;
7964 
7965   dlg = (MolinfoConstraintDlgPtr) GetObjectExtra (d);
7966 
7967   if (dlg == NULL) {
7968     return NULL;
7969   }
7970 
7971   constraint = MolinfoFieldConstraintNew();
7972   constraint->field = DialogToPointer (dlg->field);
7973   constraint->is_not = GetStatus (dlg->is_not);
7974   return constraint;
7975 }
7976 
7977 
TestMolinfoConstraintDialog(DialoG d)7978 static ValNodePtr TestMolinfoConstraintDialog (DialoG d)
7979 {
7980   MolinfoConstraintDlgPtr   dlg;
7981   ValNodePtr field;
7982   ValNodePtr err_list = NULL;
7983 
7984   dlg = (MolinfoConstraintDlgPtr) GetObjectExtra (d);
7985   if (dlg != NULL) {
7986     field = DialogToPointer (dlg->field);
7987     if (field == NULL) {
7988       ValNodeAddPointer (&err_list, 0, "missing field");
7989     }
7990     field = MolinfoFieldFree (field);
7991   }
7992   return err_list;
7993 }
7994 
7995 
ChangeMolinfoConstraintIsNot(ButtoN b)7996 static void ChangeMolinfoConstraintIsNot (ButtoN b)
7997 {
7998   MolinfoConstraintDlgPtr dlg;
7999 
8000   dlg = (MolinfoConstraintDlgPtr) GetObjectExtra (b);
8001   if (dlg == NULL) {
8002     return;
8003   }
8004   if (dlg->change_notify != NULL) {
8005     (dlg->change_notify)(dlg->change_userdata);
8006   }
8007 }
8008 
8009 
MolinfoConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)8010 static DialoG MolinfoConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
8011 {
8012   MolinfoConstraintDlgPtr dlg;
8013   GrouP                    p;
8014 
8015   dlg = (MolinfoConstraintDlgPtr) MemNew (sizeof (MolinfoConstraintDlgDaga));
8016   if (dlg == NULL)
8017   {
8018     return NULL;
8019   }
8020 
8021   p = HiddenGroup (h, -1, 0, NULL);
8022   SetGroupSpacing (p, 10, 10);
8023   SetObjectExtra (p, dlg, StdCleanupExtraProc);
8024 
8025   dlg->dialog = (DialoG) p;
8026   dlg->todialog = MolinfoConstraintToDialog;
8027   dlg->fromdialog = DialogToMolinfoConstraint;
8028   dlg->testdialog = TestMolinfoConstraintDialog;
8029 
8030   dlg->change_notify = change_notify;
8031   dlg->change_userdata = change_userdata;
8032 
8033   dlg->field = SequenceQualDialog (p, change_notify, change_userdata);
8034   dlg->is_not = CheckBox (p, "Is not", ChangeMolinfoConstraintIsNot);
8035   SetObjectExtra (dlg->is_not, dlg, NULL);
8036 
8037   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->field, (HANDLE) dlg->is_not, NULL);
8038 
8039   return (DialoG) p;
8040 }
8041 
8042 
8043 typedef struct translationconstraintdlg {
8044   DIALOG_MESSAGE_BLOCK
8045 
8046   DialoG actual_strings;
8047   DialoG transl_strings;
8048   PopuP  internal_stops;
8049   DialoG num_mismatches;
8050 
8051   Nlm_ChangeNotifyProc change_notify;
8052   Pointer change_userdata;
8053 } TranslationConstraintDlgData, PNTR TranslationConstraintDlgPtr;
8054 
8055 
TranslationConstraintToDialog(DialoG d,Pointer data)8056 static void TranslationConstraintToDialog(DialoG d, Pointer data)
8057 {
8058   TranslationConstraintDlgPtr dlg;
8059   TranslationConstraintPtr    constraint;
8060 
8061   dlg = (TranslationConstraintDlgPtr) GetObjectExtra (d);
8062   if (dlg == NULL) {
8063     return;
8064   }
8065 
8066   constraint = (TranslationConstraintPtr) data;
8067   if (constraint == NULL) {
8068     PointerToDialog (dlg->actual_strings, NULL);
8069     PointerToDialog (dlg->transl_strings, NULL);
8070     PointerToDialog (dlg->num_mismatches, NULL);
8071     SetValue (dlg->internal_stops, 1);
8072   } else {
8073     PointerToDialog (dlg->actual_strings, constraint->actual_strings);
8074     PointerToDialog (dlg->transl_strings, constraint->transl_strings);
8075     PointerToDialog (dlg->num_mismatches, constraint->num_mismatches);
8076     switch (constraint->internal_stops) {
8077       case Match_type_constraint_dont_care:
8078         SetValue (dlg->internal_stops, 1);
8079         break;
8080       case Match_type_constraint_yes:
8081         SetValue (dlg->internal_stops, 2);
8082         break;
8083       case Match_type_constraint_no:
8084         SetValue (dlg->internal_stops, 3);
8085         break;
8086       default:
8087         SetValue (dlg->internal_stops, 1);
8088         break;
8089     }
8090   }
8091 }
8092 
8093 
DialogToTranslationConstraint(DialoG d)8094 static Pointer DialogToTranslationConstraint (DialoG d)
8095 {
8096   TranslationConstraintDlgPtr dlg;
8097   TranslationConstraintPtr    constraint;
8098   Int2 val;
8099 
8100   dlg = (TranslationConstraintDlgPtr) GetObjectExtra (d);
8101   if (dlg == NULL) {
8102     return NULL;
8103   }
8104 
8105   constraint = TranslationConstraintNew();
8106   constraint->actual_strings = DialogToPointer (dlg->actual_strings);
8107   constraint->transl_strings = DialogToPointer (dlg->transl_strings);
8108   constraint->num_mismatches = DialogToPointer (dlg->num_mismatches);
8109   val = GetValue (dlg->internal_stops);
8110   switch (val) {
8111     case 1:
8112       constraint->internal_stops = Match_type_constraint_dont_care;
8113       break;
8114     case 2:
8115       constraint->internal_stops = Match_type_constraint_yes;
8116       break;
8117     case 3:
8118       constraint->internal_stops = Match_type_constraint_no;
8119       break;
8120     default:
8121       constraint->internal_stops = Match_type_constraint_dont_care;
8122       break;
8123   }
8124 
8125   if (IsTranslationConstraintEmpty(constraint)) {
8126     constraint = TranslationConstraintFree (constraint);
8127   }
8128   return constraint;
8129 }
8130 
8131 
TestTranslationConstraintDialog(DialoG d)8132 static ValNodePtr TestTranslationConstraintDialog (DialoG d)
8133 {
8134   TranslationConstraintPtr    constraint;
8135   ValNodePtr err_list = NULL;
8136 
8137   constraint = DialogToPointer (d);
8138   if (constraint == NULL) {
8139     ValNodeAddPointer (&err_list, 0, "constraint is empty");
8140   } else {
8141     constraint = TranslationConstraintFree (constraint);
8142   }
8143   return err_list;
8144 }
8145 
8146 
ChangeTranslationConstraintPopup(PopuP p)8147 static void ChangeTranslationConstraintPopup (PopuP p)
8148 {
8149   TranslationConstraintDlgPtr dlg;
8150 
8151   dlg = (TranslationConstraintDlgPtr) GetObjectExtra (p);
8152   if (dlg == NULL) {
8153     return;
8154   }
8155 
8156   if (dlg->change_notify != NULL) {
8157     (dlg->change_notify)(dlg->change_userdata);
8158   }
8159 }
8160 
8161 
TranslationConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)8162 static DialoG TranslationConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
8163 {
8164   TranslationConstraintDlgPtr dlg;
8165   GrouP                       p, g;
8166 
8167   dlg = (TranslationConstraintDlgPtr) MemNew (sizeof (TranslationConstraintDlgData));
8168   if (dlg == NULL)
8169   {
8170     return NULL;
8171   }
8172 
8173   p = HiddenGroup (h, -1, 0, NULL);
8174   SetGroupSpacing (p, 10, 10);
8175   SetObjectExtra (p, dlg, StdCleanupExtraProc);
8176 
8177   dlg->dialog = (DialoG) p;
8178   dlg->todialog = TranslationConstraintToDialog;
8179   dlg->fromdialog = DialogToTranslationConstraint;
8180   dlg->testdialog = TestTranslationConstraintDialog;
8181 
8182   dlg->change_notify = change_notify;
8183   dlg->change_userdata = change_userdata;
8184 
8185   dlg->actual_strings = StringConstraintDialog (p, "Where protein sequence", TRUE, change_notify, change_userdata);
8186   dlg->transl_strings = StringConstraintDialog (p, "Where translation", TRUE, change_notify, change_userdata);
8187 
8188   g = HiddenGroup (p, 2, 0, NULL);
8189   SetGroupSpacing (g, 10, 10);
8190   StaticPrompt (g, "Internal Stops in Translation", 0, dialogTextHeight, programFont, 'r');
8191   dlg->internal_stops = PopupList (g, TRUE, ChangeTranslationConstraintPopup);
8192   SetObjectExtra (dlg->internal_stops, dlg, NULL);
8193   PopupItem (dlg->internal_stops, "Don't care");
8194   PopupItem (dlg->internal_stops, "Yes");
8195   PopupItem (dlg->internal_stops, "No");
8196   SetValue (dlg->internal_stops, 1);
8197 
8198   dlg->num_mismatches = QuantityConstraintDialog (p, "Number of mismatches between protein sequence and translation", "1", change_notify, change_userdata);
8199   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->actual_strings, (HANDLE) dlg->transl_strings, (HANDLE) g, (HANDLE) dlg->internal_stops, NULL);
8200 
8201   return (DialoG) p;
8202 }
8203 
8204 
8205 static DialoG RNAFieldConstraintDialog (GrouP h, CharPtr type_label, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata);
8206 static DialoG FeatureFieldConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata);
8207 static DialoG MiscFieldConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata);
8208 
8209 
8210 /* Notes:
8211  * There can be more than one constraint, and the user will need to be able to view, edit, add, and delete them.
8212  * Should have a DOC that lists the constraints, user can click on buttons to edit or delete, another button to add.
8213  * Need to have an Edit window to edit individual constraints.
8214  * Let user toggle between types of constraints only when creating a new one?
8215  */
8216 typedef enum {
8217   eConstraintPopup_Location = 1,
8218   eConstraintPopup_Source,
8219   eConstraintPopup_CDSGeneProt,
8220   eConstraintPopup_CDSGeneProtPseudo,
8221   eConstraintPopup_Sequence,
8222   eConstraintPopup_Pub,
8223   eConstraintPopup_RNA,
8224   eConstraintPopup_FeatureField,
8225   eConstraintPopup_MiscField,
8226   eConstraintPopup_DBLinkField,
8227   eConstraintPopup_MolinfoField,
8228   eConstraintPopup_MissingField,
8229   eConstraintPopup_String,
8230   eConstraintPopup_Translation,
8231   eConstraintPopup_Max
8232 } EConstraintPopup;
8233 
8234 typedef struct constrainttable {
8235   CharPtr title;
8236   Uint1   constraint_choice;
8237 } ConstraintTableData, PNTR ConstraintTablePtr;
8238 
8239 static ConstraintTableData ConstraintTable[] = {
8240   {  "Location", ConstraintChoice_location },
8241   {  "Source", ConstraintChoice_source },
8242   {  "CDS-Gene-Prot Qualifier", ConstraintChoice_cdsgeneprot_qual },
8243   {  "CDS-Gene-Prot Pseudo Feature", ConstraintChoice_cdsgeneprot_pseudo },
8244   {  "Sequence and Feature", ConstraintChoice_sequence },
8245   {  "Publication", ConstraintChoice_pub },
8246   {  "RNA Field", ConstraintChoice_field },
8247   {  "Feature Field", ConstraintChoice_field },
8248   {  "Misc Field", ConstraintChoice_field },
8249   {  "DBLink Field", ConstraintChoice_field },
8250   {  "Molinfo Field", ConstraintChoice_molinfo },
8251   {  "Missing Field", ConstraintChoice_field_missing },
8252   {  "String (use with caution)", ConstraintChoice_string },
8253   {  "Translation", ConstraintChoice_translation }
8254 };
8255 
8256 
PopupFromConstraintChoice(Uint1 constraint_choice)8257 static Int2 PopupFromConstraintChoice (Uint1 constraint_choice)
8258 {
8259   Int2 val;
8260   for (val = 0; val < eConstraintPopup_Max - 1; val++) {
8261     if (ConstraintTable[val].constraint_choice == constraint_choice) {
8262       return val + 1;
8263     }
8264   }
8265   return 0;
8266 }
8267 
8268 
8269 typedef struct editconstraint {
8270   PopuP constraint_type;
8271 
8272   DialoG dlgs[eConstraintPopup_Max];
8273 
8274   ButtoN accept_btn;
8275 } EditConstraintData, PNTR EditConstraintPtr;
8276 
8277 
EnableEditConstraintAccept(Pointer data)8278 static void EnableEditConstraintAccept (Pointer data)
8279 {
8280   EditConstraintPtr ecp;
8281   Int2 val;
8282   ValNodePtr err_list = NULL;
8283   Boolean ok_to_accept = TRUE;
8284   ValNodePtr tmp;
8285   StringConstraintPtr scp;
8286 
8287   ecp = (EditConstraintPtr) data;
8288   if (ecp != NULL && ecp->accept_btn != NULL) {
8289     val = GetValue (ecp->constraint_type);
8290     switch (val) {
8291       case eConstraintPopup_String:
8292         scp = DialogToPointer (ecp->dlgs[val - 1]);
8293         if (IsStringConstraintEmpty (scp)) {
8294           ValNodeAddPointer (&err_list, 0, "empty string constraint");
8295         }
8296         scp = StringConstraintFree (scp);
8297         break;
8298       case eConstraintPopup_Location:
8299       case eConstraintPopup_Source:
8300       case eConstraintPopup_CDSGeneProt:
8301       case eConstraintPopup_CDSGeneProtPseudo:
8302       case eConstraintPopup_Sequence:
8303       case eConstraintPopup_Pub:
8304       case eConstraintPopup_MolinfoField:
8305       case eConstraintPopup_MissingField:
8306       case eConstraintPopup_Translation:
8307         err_list = TestDialog (ecp->dlgs[val - 1]);
8308         break;
8309       case eConstraintPopup_RNA:
8310       case eConstraintPopup_FeatureField:
8311       case eConstraintPopup_MiscField:
8312       case eConstraintPopup_DBLinkField:
8313         tmp = DialogToPointer (ecp->dlgs[val - 1]);
8314         if (tmp == NULL || IsFieldConstraintEmpty (tmp->data.ptrvalue)) {
8315           ValNodeAddPointer (&err_list, 0, "No constraint");
8316         }
8317         tmp = ConstraintChoiceFree (tmp);
8318         break;
8319       default:
8320         ok_to_accept = FALSE;
8321     }
8322     if (err_list != NULL) {
8323       ok_to_accept = FALSE;
8324       err_list = ValNodeFree (err_list);
8325     }
8326     if (ok_to_accept) {
8327       Enable (ecp->accept_btn);
8328     } else {
8329       Disable (ecp->accept_btn);
8330     }
8331   }
8332 }
8333 
8334 
ChangeEditConstraintType(PopuP p)8335 static void ChangeEditConstraintType (PopuP p)
8336 {
8337   EditConstraintPtr ecp;
8338   Int2 val;
8339 
8340   ecp = (EditConstraintPtr) GetObjectExtra (p);
8341   if (ecp == NULL) return;
8342 
8343   for (val = 0; val < eConstraintPopup_Max - 1; val++) {
8344     Hide (ecp->dlgs[val]);
8345   }
8346 
8347   val = GetValue (ecp->constraint_type);
8348   if (val > 0 && val < eConstraintPopup_Max) {
8349     Show (ecp->dlgs[val - 1]);
8350   }
8351   EnableEditConstraintAccept (ecp);
8352 }
8353 
8354 
FreeConstraintData(ValNodePtr constraint)8355 static void FreeConstraintData (ValNodePtr constraint)
8356 {
8357   if (constraint == NULL) return;
8358 
8359   switch (constraint->choice) {
8360     case ConstraintChoice_string:
8361       constraint->data.ptrvalue = StringConstraintFree (constraint->data.ptrvalue);
8362       break;
8363     case ConstraintChoice_location:
8364       constraint->data.ptrvalue = LocationConstraintFree (constraint->data.ptrvalue);
8365       break;
8366     case ConstraintChoice_source:
8367       constraint->data.ptrvalue = SourceConstraintFree (constraint->data.ptrvalue);
8368       break;
8369     case ConstraintChoice_cdsgeneprot_qual:
8370       constraint->data.ptrvalue = CDSGeneProtQualConstraintFree (constraint->data.ptrvalue);
8371       break;
8372     case ConstraintChoice_cdsgeneprot_pseudo:
8373       constraint->data.ptrvalue = CDSGeneProtPseudoConstraintFree (constraint->data.ptrvalue);
8374       break;
8375     case ConstraintChoice_sequence:
8376       constraint->data.ptrvalue = SequenceConstraintFree (constraint->data.ptrvalue);
8377       break;
8378     case ConstraintChoice_pub:
8379       constraint->data.ptrvalue = PublicationConstraintFree (constraint->data.ptrvalue);
8380       break;
8381     case ConstraintChoice_field:
8382       constraint->data.ptrvalue = FieldConstraintFree (constraint->data.ptrvalue);
8383       break;
8384     case ConstraintChoice_molinfo:
8385       constraint->data.ptrvalue = MolinfoFieldConstraintFree (constraint->data.ptrvalue);
8386       break;
8387     case ConstraintChoice_translation:
8388       constraint->data.ptrvalue = TranslationConstraintFree (constraint->data.ptrvalue);
8389       break;
8390   }
8391 }
8392 
8393 static DialoG SingleFieldTypeDialog (GrouP h, Boolean text_only, Boolean for_remove, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata);
8394 static DialoG DBLinkFieldConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata);
8395 
EditConstraint(ValNodePtr constraint)8396 static Boolean EditConstraint (ValNodePtr constraint)
8397 {
8398   ModalAcceptCancelData acd;
8399   EditConstraintData    ecd;
8400   Boolean               rval = FALSE;
8401   WindoW                w;
8402   ButtoN                b;
8403   GrouP                 h, g, c;
8404   Int2                  val;
8405   FieldConstraintPtr    fcp;
8406   ValNodePtr            tmp;
8407 
8408   if (constraint == NULL) return FALSE;
8409 
8410   w = MovableModalWindow(-20, -13, -10, -10, "Constraint", NULL);
8411   h = HiddenGroup (w, -1, 0, NULL);
8412   SetGroupSpacing (h, 10, 10);
8413 
8414   ecd.constraint_type = PopupList (h, TRUE, ChangeEditConstraintType);
8415   SetObjectExtra (ecd.constraint_type, &ecd, NULL);
8416   for (val = 1; val < eConstraintPopup_Max; val++) {
8417     PopupItem (ecd.constraint_type, ConstraintTable[val - 1].title);
8418   }
8419 
8420   g = HiddenGroup (h, 0, 0, NULL);
8421   ecd.accept_btn = NULL;
8422   ecd.dlgs[eConstraintPopup_String - 1] = StringConstraintDialog (g, "", TRUE, EnableEditConstraintAccept, &ecd);
8423   ecd.dlgs[eConstraintPopup_Location - 1] = LocationConstraintDialog (g, EnableEditConstraintAccept, &ecd);
8424   ecd.dlgs[eConstraintPopup_Source - 1] = SourceConstraintDialog (g, EnableEditConstraintAccept, &ecd);
8425   ecd.dlgs[eConstraintPopup_CDSGeneProt - 1] = CDSGeneProtQualConstraintDialog (g, EnableEditConstraintAccept, &ecd);
8426   ecd.dlgs[eConstraintPopup_CDSGeneProtPseudo - 1] = CDSGeneProtPseudoConstraintDialog (g, EnableEditConstraintAccept, &ecd);
8427   ecd.dlgs[eConstraintPopup_Sequence - 1] = SequenceConstraintDialog (g, EnableEditConstraintAccept, &ecd);
8428   ecd.dlgs[eConstraintPopup_Pub - 1] = PublicationConstraintDialog (g, EnableEditConstraintAccept, &ecd);
8429   ecd.dlgs[eConstraintPopup_RNA - 1] = RNAFieldConstraintDialog (g, "RNA Type", EnableEditConstraintAccept, &ecd);
8430   ecd.dlgs[eConstraintPopup_FeatureField - 1] = FeatureFieldConstraintDialog (g, EnableEditConstraintAccept, &ecd);
8431   ecd.dlgs[eConstraintPopup_MiscField - 1] = MiscFieldConstraintDialog (g, EnableEditConstraintAccept, &ecd);
8432   ecd.dlgs[eConstraintPopup_DBLinkField - 1] = DBLinkFieldConstraintDialog (g, EnableEditConstraintAccept, &ecd);
8433   ecd.dlgs[eConstraintPopup_MolinfoField - 1] = MolinfoConstraintDialog (g, EnableEditConstraintAccept, &ecd);
8434   ecd.dlgs[eConstraintPopup_MissingField - 1] = SingleFieldTypeDialog(g, TRUE, FALSE, EnableEditConstraintAccept, &ecd);
8435   ecd.dlgs[eConstraintPopup_Translation - 1] = TranslationConstraintDialog (g, EnableEditConstraintAccept, &ecd);
8436 
8437   AlignObjects (ALIGN_CENTER, (HANDLE) ecd.dlgs[eConstraintPopup_String - 1],
8438                               (HANDLE) ecd.dlgs[eConstraintPopup_Location - 1],
8439                               (HANDLE) ecd.dlgs[eConstraintPopup_Source - 1],
8440                               (HANDLE) ecd.dlgs[eConstraintPopup_CDSGeneProt - 1],
8441                               (HANDLE) ecd.dlgs[eConstraintPopup_CDSGeneProtPseudo - 1],
8442                               (HANDLE) ecd.dlgs[eConstraintPopup_Sequence - 1],
8443                               (HANDLE) ecd.dlgs[eConstraintPopup_Pub - 1],
8444                               (HANDLE) ecd.dlgs[eConstraintPopup_RNA - 1],
8445                               (HANDLE) ecd.dlgs[eConstraintPopup_FeatureField - 1],
8446                               (HANDLE) ecd.dlgs[eConstraintPopup_MiscField - 1],
8447                               (HANDLE) ecd.dlgs[eConstraintPopup_DBLinkField - 1],
8448                               (HANDLE) ecd.dlgs[eConstraintPopup_MolinfoField - 1],
8449                               (HANDLE) ecd.dlgs[eConstraintPopup_MissingField - 1],
8450                               (HANDLE) ecd.dlgs[eConstraintPopup_Translation - 1],
8451                               NULL);
8452 
8453   c = HiddenGroup (h, 2, 0, NULL);
8454   SetGroupSpacing (c, 10, 10);
8455   ecd.accept_btn = PushButton (c, "Accept", ModalAcceptButton);
8456   SetObjectExtra (ecd.accept_btn, &acd, NULL);
8457   b = PushButton (c, "Cancel", ModalCancelButton);
8458   SetObjectExtra (b, &acd, NULL);
8459   AlignObjects (ALIGN_CENTER, (HANDLE) ecd.constraint_type,
8460                               (HANDLE) g,
8461                               (HANDLE) c,
8462                               NULL);
8463 
8464   if (constraint->choice == ConstraintChoice_field) {
8465     fcp = (FieldConstraintPtr) constraint->data.ptrvalue;
8466     if (fcp == NULL || fcp->field == NULL || fcp->field->choice == FieldType_rna_field) {
8467       SetValue (ecd.constraint_type, eConstraintPopup_RNA);
8468       PointerToDialog (ecd.dlgs[eConstraintPopup_RNA - 1], constraint->data.ptrvalue);
8469     } else if (fcp->field->choice == FieldType_feature_field) {
8470       SetValue (ecd.constraint_type, eConstraintPopup_FeatureField);
8471       PointerToDialog (ecd.dlgs[eConstraintPopup_FeatureField - 1], constraint->data.ptrvalue);
8472     } else if (fcp->field->choice == FieldType_misc) {
8473       SetValue (ecd.constraint_type, eConstraintPopup_MiscField);
8474       PointerToDialog (ecd.dlgs[eConstraintPopup_MiscField - 1], constraint->data.ptrvalue);
8475     } else if (fcp->field->choice == FieldType_dblink) {
8476       SetValue (ecd.constraint_type, eConstraintPopup_DBLinkField);
8477       PointerToDialog (ecd.dlgs[eConstraintPopup_DBLinkField - 1], constraint->data.ptrvalue);
8478     }
8479   } else {
8480     val = PopupFromConstraintChoice (constraint->choice);
8481     if (val > 0 && val < eConstraintPopup_Max) {
8482       SetValue (ecd.constraint_type, val);
8483       PointerToDialog (ecd.dlgs[val - 1], constraint->data.ptrvalue);
8484     } else {
8485       SetValue (ecd.constraint_type, eConstraintPopup_String);
8486     }
8487   }
8488 
8489   ChangeEditConstraintType (ecd.constraint_type);
8490   Show (w);
8491   Select (w);
8492   acd.accepted = FALSE;
8493   acd.cancelled = FALSE;
8494   while (!acd.accepted && ! acd.cancelled)
8495   {
8496     ProcessExternalEvent ();
8497     Update ();
8498   }
8499   ProcessAnEvent ();
8500   if (!acd.cancelled)
8501   {
8502     val = GetValue (ecd.constraint_type);
8503     switch (val) {
8504       case eConstraintPopup_String:
8505       case eConstraintPopup_Location:
8506       case eConstraintPopup_Source:
8507       case eConstraintPopup_CDSGeneProt:
8508       case eConstraintPopup_CDSGeneProtPseudo:
8509       case eConstraintPopup_Sequence:
8510       case eConstraintPopup_Pub:
8511       case eConstraintPopup_MolinfoField:
8512       case eConstraintPopup_MissingField:
8513       case eConstraintPopup_Translation:
8514         FreeConstraintData (constraint);
8515         constraint->choice = ConstraintTable[val - 1].constraint_choice;
8516         constraint->data.ptrvalue = DialogToPointer (ecd.dlgs[val - 1]);
8517         rval = TRUE;
8518         break;
8519       case eConstraintPopup_RNA:
8520       case eConstraintPopup_FeatureField:
8521       case eConstraintPopup_MiscField:
8522       case eConstraintPopup_DBLinkField:
8523         FreeConstraintData (constraint);
8524         constraint->choice = ConstraintChoice_field;
8525         tmp = DialogToPointer (ecd.dlgs[val - 1]);
8526         if (tmp != NULL) {
8527           constraint->data.ptrvalue = tmp->data.ptrvalue;
8528           tmp = ValNodeFree (tmp);
8529         }
8530         rval = TRUE;
8531         break;
8532     }
8533   }
8534   Remove (w);
8535   return rval;
8536 }
8537 
8538 
8539 typedef struct constraintsetdlg {
8540   DIALOG_MESSAGE_BLOCK
8541   DoC                  constraint_doc;
8542   ValNodePtr           constraint_list;
8543   ValNodePtr           default_constraint;
8544 
8545   Nlm_ChangeNotifyProc change_notify;
8546   Pointer              change_userdata;
8547 } ConstraintSetDlgData, PNTR ConstraintSetDlgPtr;
8548 
PopulateConstraintDoc(DoC d,ValNodePtr constraint_list)8549 static void PopulateConstraintDoc (DoC d, ValNodePtr constraint_list)
8550 {
8551   ValNodePtr vnp;
8552   CharPtr    phrase, tmp;
8553   RecT       r;
8554   ParData    ParFmt = {FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0};
8555   ColData    ColFmt[] =
8556   {
8557     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
8558     {0, 0, 80, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, TRUE}
8559   };
8560 
8561   if (d == NULL) return;
8562 
8563   Reset (d);
8564 
8565   ObjectRect (d, &r);
8566   InsetRect (&r, 4, 4);
8567 
8568   ColFmt[1].pixWidth = r.right - r.left - 12;
8569 
8570   Reset (d);
8571 
8572   for (vnp = constraint_list; vnp != NULL; vnp = vnp->next) {
8573     phrase = SummarizeConstraint (vnp);
8574     if (phrase == NULL) {
8575       AppendText (d, "\tUnable to summarize constraint\n", &ParFmt, ColFmt, programFont);
8576     } else {
8577       tmp = (CharPtr) MemNew (sizeof (Char) * (StringLen (phrase) + 3));
8578       sprintf (tmp, "\t%s\n", phrase);
8579       phrase = MemFree (phrase);
8580       AppendText (d, tmp, &ParFmt, ColFmt, programFont);
8581       tmp = MemFree (tmp);
8582     }
8583   }
8584   AppendText (d, "(Click here to add new constraint)", NULL, NULL, programFont);
8585   UpdateDocument (d, 0, 0);
8586 }
8587 
DrawConstraintDocControls(DoC d,RectPtr r,Int2 item,Int2 firstLine)8588 static void DrawConstraintDocControls (DoC d, RectPtr r, Int2 item, Int2 firstLine)
8589 
8590 {
8591   RecT                rct;
8592   Int4                width;
8593   PoinT               pt1, pt2;
8594   ConstraintSetDlgPtr dlg;
8595 
8596   dlg = (ConstraintSetDlgPtr) GetObjectExtra (d);
8597   if (dlg != NULL && r != NULL && item > 0 && firstLine == 0 && item <= ValNodeLen (dlg->constraint_list)) {
8598     rct = *r;
8599 
8600     /* draw X for deletion */
8601     width = 10;
8602     pt1.x = rct.left + 1;
8603     pt1.y = rct.top + 1;
8604     pt2.x = pt1.x + width;
8605     pt2.y = pt1.y + width;
8606     DrawLine (pt1, pt2);
8607     pt1.x = rct.left + 1;
8608     pt1.y = rct.top + 1 + width;
8609     pt2.x = pt1.x + width;
8610     pt2.y = rct.top + 1;
8611     DrawLine (pt1, pt2);
8612   }
8613 }
8614 
8615 
8616 static ValNodePtr DefaultFeatureFieldConstraint (Int2 feat_type);
8617 
NewConstraintFromDefault(ValNodePtr default_constraint)8618 static ValNodePtr NewConstraintFromDefault (ValNodePtr default_constraint)
8619 {
8620   ValNodePtr vnp = NULL;
8621   FieldConstraintPtr f;
8622   FeatureFieldPtr ff;
8623   ErrSev     oldErrSev;
8624 
8625   if (default_constraint == NULL) {
8626     vnp = ValNodeNew (NULL);
8627     vnp->choice = ConstraintChoice_string;
8628   } else {
8629     if (default_constraint->choice == ConstraintChoice_field
8630         && (f = default_constraint->data.ptrvalue) != NULL
8631         && f->field != NULL
8632         && f->field->choice == FieldType_feature_field
8633         && (ff = f->field->data.ptrvalue) != NULL
8634         && ff->field == NULL) {
8635       vnp = DefaultFeatureFieldConstraint (ff->type);
8636     } else if (default_constraint->data.ptrvalue != NULL) {
8637       oldErrSev = ErrSetMessageLevel (SEV_FATAL);
8638       vnp = AsnIoMemCopy (default_constraint, (AsnReadFunc) ConstraintChoiceAsnRead, (AsnWriteFunc) ConstraintChoiceAsnWrite);
8639       ErrSetMessageLevel (oldErrSev);
8640     }
8641     if (vnp == NULL) {
8642       vnp = ValNodeNew (NULL);
8643       vnp->choice = default_constraint->choice;
8644     }
8645   }
8646   return vnp;
8647 }
8648 
8649 
ClickConstraintDoc(DoC d,PoinT pt)8650 static void ClickConstraintDoc (DoC d, PoinT pt)
8651 {
8652   Int2      item, row, col;
8653   RecT      rct;
8654   BaR       sb_vert;
8655   Int4      scroll_pos = 0, scroll_max;
8656   ConstraintSetDlgPtr f;
8657   ValNodePtr         vnp, vnp_prev = NULL;
8658   Boolean            changed = FALSE;
8659 
8660   f = (ConstraintSetDlgPtr) GetObjectExtra (d);
8661   if (f == NULL) return;
8662 
8663   MapDocPoint (d, pt, &item, &row, &col, &rct);
8664   if (item == 0 && row == 0 && f->constraint_list == NULL) {
8665     /* create new constraint */
8666     vnp = NewConstraintFromDefault (f->default_constraint);
8667     if (EditConstraint (vnp)) {
8668       f->constraint_list = vnp;
8669       changed = TRUE;
8670     } else {
8671       vnp = ConstraintChoiceFree (vnp);
8672     }
8673   } else if (item > 0 && row > 0) {
8674     if (item == ValNodeLen (f->constraint_list) + 1) {
8675       /* create new constraint */
8676       vnp = NewConstraintFromDefault (f->default_constraint);
8677       if (EditConstraint (vnp)) {
8678         ValNodeLink (&(f->constraint_list), vnp);
8679         changed = TRUE;
8680       } else {
8681         vnp = ConstraintChoiceFree (vnp);
8682       }
8683     } else {
8684       for (vnp = f->constraint_list; vnp != NULL && item > 1; vnp = vnp->next, item--) {
8685         vnp_prev = vnp;
8686       }
8687       if (vnp != NULL) {
8688         sb_vert = GetSlateVScrollBar ((SlatE) f->constraint_doc);
8689         scroll_pos = GetBarValue (sb_vert);
8690         switch (col) {
8691           case 1:
8692             /* delete this item */
8693             if (vnp_prev == NULL) {
8694               f->constraint_list = vnp->next;
8695             } else {
8696               vnp_prev->next = vnp->next;
8697             }
8698             vnp->next = NULL;
8699             vnp = ConstraintChoiceFree (vnp);
8700             changed = TRUE;
8701             break;
8702           case 2:
8703             /* edit */
8704             changed = EditConstraint (vnp);
8705             break;
8706         }
8707       }
8708     }
8709   }
8710   if (changed) {
8711     PopulateConstraintDoc (f->constraint_doc, f->constraint_list);
8712     if (scroll_pos > 0) {
8713       sb_vert = GetSlateVScrollBar ((SlatE) f->constraint_doc);
8714       scroll_max = GetBarMax (sb_vert);
8715       if (scroll_pos > scroll_max) {
8716         scroll_pos = scroll_max;
8717       }
8718       CorrectBarValue (sb_vert, scroll_pos);
8719     }
8720     if (f->change_notify != NULL) {
8721       (f->change_notify) (f->change_userdata);
8722     }
8723   }
8724 }
8725 
ConstraintSetToDialog(DialoG d,Pointer data)8726 static void ConstraintSetToDialog (DialoG d, Pointer data)
8727 {
8728   ConstraintSetDlgPtr dlg;
8729 
8730   dlg = (ConstraintSetDlgPtr) GetObjectExtra (d);
8731   if (dlg == NULL) return;
8732 
8733   dlg->constraint_list = ConstraintChoiceSetFree (dlg->constraint_list);
8734   if (data != NULL) {
8735     dlg->constraint_list = AsnIoMemCopy ((ConstraintChoiceSetPtr) data,
8736                                          (AsnReadFunc) ConstraintChoiceSetAsnRead,
8737                                          (AsnWriteFunc) ConstraintChoiceSetAsnWrite);
8738  }
8739  PopulateConstraintDoc (dlg->constraint_doc, dlg->constraint_list);
8740  if (dlg->change_notify != NULL) {
8741     (dlg->change_notify) (dlg->change_userdata);
8742   }
8743 }
8744 
8745 
ConstraintSetFromDialog(DialoG d)8746 static Pointer ConstraintSetFromDialog (DialoG d)
8747 {
8748   ConstraintSetDlgPtr dlg;
8749   ValNodePtr constraint_list = NULL;
8750 
8751   dlg = (ConstraintSetDlgPtr) GetObjectExtra (d);
8752   if (dlg == NULL) return NULL;
8753 
8754   if (dlg->constraint_list != NULL) {
8755     constraint_list = AsnIoMemCopy ((ConstraintChoiceSetPtr) dlg->constraint_list,
8756                                     (AsnReadFunc) ConstraintChoiceSetAsnRead,
8757                                     (AsnWriteFunc) ConstraintChoiceSetAsnWrite);
8758   }
8759   return (Pointer) constraint_list;
8760 }
8761 
CleanupConstraintSetDialog(GraphiC g,VoidPtr data)8762 static void CleanupConstraintSetDialog (GraphiC g, VoidPtr data)
8763 
8764 {
8765   ConstraintSetDlgPtr dlg;
8766 
8767   dlg = (ConstraintSetDlgPtr) data;
8768   if (dlg != NULL) {
8769     dlg->constraint_list = ConstraintChoiceSetFree (dlg->constraint_list);
8770     dlg->default_constraint = ConstraintChoiceFree (dlg->default_constraint);
8771   }
8772   StdCleanupExtraProc (g, data);
8773 }
8774 
8775 
SetConstraintSetDefaultConstraintType(DialoG d,Uint1 constraint_type)8776 NLM_EXTERN void SetConstraintSetDefaultConstraintType (DialoG d, Uint1 constraint_type)
8777 {
8778   ConstraintSetDlgPtr dlg;
8779 
8780   dlg = (ConstraintSetDlgPtr) GetObjectExtra (d);
8781   if (dlg != NULL) {
8782     dlg->default_constraint = ConstraintChoiceFree (dlg->default_constraint);
8783     dlg->default_constraint = ValNodeNew (NULL);
8784     dlg->default_constraint->choice = constraint_type;
8785   }
8786 }
8787 
8788 
SetConstraintSetDefaultConstraintTypeEx(DialoG d,ValNodePtr constraint)8789 static void SetConstraintSetDefaultConstraintTypeEx (DialoG d, ValNodePtr constraint)
8790 {
8791   ConstraintSetDlgPtr dlg;
8792 
8793   dlg = (ConstraintSetDlgPtr) GetObjectExtra (d);
8794   if (dlg != NULL) {
8795     dlg->default_constraint = ConstraintChoiceFree (dlg->default_constraint);
8796     if (constraint != NULL) {
8797       dlg->default_constraint = NewConstraintFromDefault (constraint);
8798     }
8799   }
8800 }
8801 
8802 
AddConstraintBtn(ButtoN b)8803 static void AddConstraintBtn (ButtoN b)
8804 {
8805   ConstraintSetDlgPtr dlg;
8806   ValNodePtr          vnp;
8807   BaR       sb_vert;
8808   Int4      scroll_pos = 0, scroll_max;
8809 
8810   dlg = (ConstraintSetDlgPtr) GetObjectExtra (b);
8811   if (dlg == NULL) {
8812     return;
8813   }
8814 
8815   sb_vert = GetSlateVScrollBar ((SlatE) dlg->constraint_doc);
8816   scroll_pos = GetBarValue (sb_vert);
8817 
8818   /* create new constraint */
8819   vnp = NewConstraintFromDefault (dlg->default_constraint);
8820   if (EditConstraint (vnp)) {
8821     ValNodeLink (&(dlg->constraint_list), vnp);
8822     PopulateConstraintDoc (dlg->constraint_doc, dlg->constraint_list);
8823     if (scroll_pos > 0) {
8824       sb_vert = GetSlateVScrollBar ((SlatE) dlg->constraint_doc);
8825       scroll_max = GetBarMax (sb_vert);
8826       if (scroll_pos > scroll_max) {
8827         scroll_pos = scroll_max;
8828       }
8829       CorrectBarValue (sb_vert, scroll_pos);
8830     }
8831     if (dlg->change_notify != NULL) {
8832       (dlg->change_notify) (dlg->change_userdata);
8833     }
8834   } else {
8835     vnp = ConstraintChoiceFree (vnp);
8836   }
8837 
8838 }
8839 
8840 
ConstraintSetDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)8841 NLM_EXTERN DialoG ConstraintSetDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
8842 {
8843   ConstraintSetDlgPtr dlg;
8844   GrouP               p, g;
8845   PrompT              ppt;
8846   ButtoN              b;
8847 
8848   p = HiddenGroup (h, -1, 0, NULL);
8849   SetGroupSpacing (p, 10, 10);
8850   dlg = (ConstraintSetDlgPtr) MemNew (sizeof (ConstraintSetDlgData));
8851   SetObjectExtra (p, dlg, CleanupConstraintSetDialog);
8852 
8853   dlg->dialog = (DialoG) p;
8854   dlg->todialog = ConstraintSetToDialog;
8855   dlg->fromdialog = ConstraintSetFromDialog;
8856   dlg->change_notify = change_notify;
8857   dlg->change_userdata = change_userdata;
8858 
8859   dlg->constraint_list = NULL;
8860   ppt = StaticPrompt (p, "Constraint List", 0, dialogTextHeight, programFont, 'c');
8861   dlg->constraint_doc = DocumentPanel (p, stdCharWidth * 30, stdLineHeight * 3);
8862   SetObjectExtra (dlg->constraint_doc, dlg, NULL);
8863   SetDocProcs (dlg->constraint_doc, ClickConstraintDoc, NULL, NULL, NULL);
8864   SetDocShade (dlg->constraint_doc, DrawConstraintDocControls, NULL, NULL, NULL);
8865   PopulateConstraintDoc (dlg->constraint_doc, dlg->constraint_list);
8866 
8867   g = HiddenGroup (p, 2, 0, NULL);
8868   b = PushButton (g, "Add Contraint", AddConstraintBtn);
8869   SetObjectExtra (b, dlg, NULL);
8870   b = PushButton (g, "Clear Constraints", ClearDialogBtn);
8871   SetObjectExtra (b, p, NULL);
8872 
8873   AlignObjects (ALIGN_CENTER, (HANDLE) ppt, (HANDLE) dlg->constraint_doc, (HANDLE) g, NULL);
8874 
8875   dlg->default_constraint = ValNodeNew (NULL);
8876   dlg->default_constraint->choice = ConstraintChoice_string;
8877   return (DialoG) p;
8878 }
8879 
8880 
8881 typedef struct texttransformtable {
8882   CharPtr title;
8883   Uint1   transform_choice;
8884 } TextTransformTableData, PNTR TextTransformTablePtr;
8885 
8886 static TextTransformTableData TextTransformTable[] = {
8887   {  "Edit", TextTransform_edit },
8888   {  "Capitalization", TextTransform_caps },
8889   {  "Remove Text Outside", TextTransform_remove }
8890 };
8891 
8892 
8893 typedef enum {
8894   eTextTransformPopup_Edit = 1,
8895   eTextTransformPopup_Caps,
8896   eTextTransformPopup_RemoveOutside,
8897   eTextTransformPopup_Max
8898 } ETextTransformPopup;
8899 
8900 
PopupFromTextTransformChoice(Uint1 transform_choice)8901 static Int2 PopupFromTextTransformChoice (Uint1 transform_choice)
8902 {
8903   Int2 val;
8904   for (val = 0; val < eTextTransformPopup_Max - 1; val++) {
8905     if (TextTransformTable[val].transform_choice == transform_choice) {
8906       return val + 1;
8907     }
8908   }
8909   return 0;
8910 }
8911 
8912 
8913 typedef struct edittexttransform {
8914   PopuP transform_type;
8915 
8916   DialoG dlgs[eTextTransformPopup_Max];
8917 
8918   ButtoN accept_btn;
8919 } EditTextTransformData, PNTR EditTextTransformPtr;
8920 
8921 
EnableEditTextTransformAccept(Pointer data)8922 static void EnableEditTextTransformAccept (Pointer data)
8923 {
8924   EditTextTransformPtr ecp;
8925   Int2 val;
8926   Boolean ok_to_accept = TRUE;
8927   ValNodePtr vnp;
8928 
8929   ecp = (EditTextTransformPtr) data;
8930   if (ecp != NULL && ecp->accept_btn != NULL) {
8931     val = GetValue (ecp->transform_type);
8932     switch (val) {
8933       case eTextTransformPopup_Edit:
8934       case eTextTransformPopup_RemoveOutside:
8935         vnp = ValNodeNew (NULL);
8936         vnp->choice = TextTransformTable[val - 1].transform_choice;
8937         vnp->data.ptrvalue = DialogToPointer (ecp->dlgs[val - 1]);
8938         if (IsTextTransformEmpty(vnp)) {
8939           ok_to_accept = FALSE;
8940         }
8941         vnp = TextTransformFree (vnp);
8942         break;
8943       case eTextTransformPopup_Caps:
8944         if (GetCapChangeDialogValue(ecp->dlgs[val - 1]) == Cap_change_none) {
8945           ok_to_accept = FALSE;
8946         }
8947         break;
8948       default:
8949         ok_to_accept = FALSE;
8950         break;
8951     }
8952     if (ok_to_accept) {
8953       Enable (ecp->accept_btn);
8954     } else {
8955       Disable (ecp->accept_btn);
8956     }
8957   }
8958 }
8959 
8960 
ChangeEditTextTransformType(PopuP p)8961 static void ChangeEditTextTransformType (PopuP p)
8962 {
8963   EditTextTransformPtr ecp;
8964   Int2 val;
8965 
8966   ecp = (EditTextTransformPtr) GetObjectExtra (p);
8967   if (ecp == NULL) return;
8968 
8969   for (val = 0; val < eTextTransformPopup_Max - 1; val++) {
8970     Hide (ecp->dlgs[val]);
8971   }
8972 
8973   val = GetValue (ecp->transform_type);
8974   if (val > 0 && val < eTextTransformPopup_Max) {
8975     Show (ecp->dlgs[val - 1]);
8976   }
8977   EnableEditTextTransformAccept (ecp);
8978 }
8979 
8980 
FreeTextTransformData(ValNodePtr transform)8981 static void FreeTextTransformData (ValNodePtr transform)
8982 {
8983   if (transform == NULL) return;
8984 
8985   switch (transform->choice) {
8986     case TextTransform_edit:
8987       transform->data.ptrvalue = FieldEditFree (transform->data.ptrvalue);
8988       break;
8989   }
8990 }
8991 
8992 
EditTextTransform(ValNodePtr transform)8993 static Boolean EditTextTransform (ValNodePtr transform)
8994 {
8995   ModalAcceptCancelData acd;
8996   EditTextTransformData    ecd;
8997   Boolean               rval = FALSE;
8998   WindoW                w;
8999   ButtoN                b;
9000   GrouP                 h, g, c;
9001   Int2                  val;
9002 
9003   if (transform == NULL) return FALSE;
9004 
9005   w = MovableModalWindow(-20, -13, -10, -10, "Text Transform", NULL);
9006   h = HiddenGroup (w, -1, 0, NULL);
9007   SetGroupSpacing (h, 10, 10);
9008 
9009   ecd.transform_type = PopupList (h, TRUE, ChangeEditTextTransformType);
9010   SetObjectExtra (ecd.transform_type, &ecd, NULL);
9011   for (val = 1; val < eTextTransformPopup_Max; val++) {
9012     PopupItem (ecd.transform_type, TextTransformTable[val - 1].title);
9013   }
9014 
9015   g = HiddenGroup (h, 0, 0, NULL);
9016   ecd.accept_btn = NULL;
9017   ecd.dlgs[eTextTransformPopup_Edit - 1] = FieldEditDialog (g, EnableEditTextTransformAccept, &ecd);
9018   ecd.dlgs[eTextTransformPopup_Caps - 1] = CapChangeDialog (g, EnableEditTextTransformAccept, &ecd);
9019   ecd.dlgs[eTextTransformPopup_RemoveOutside - 1] = TextPortionDialog (g, FALSE, EnableEditTextTransformAccept, &ecd);
9020 
9021   AlignObjects (ALIGN_CENTER, (HANDLE) ecd.dlgs[eTextTransformPopup_Edit - 1],
9022                               (HANDLE) ecd.dlgs[eTextTransformPopup_Caps - 1],
9023                               (HANDLE) ecd.dlgs[eTextTransformPopup_RemoveOutside - 1],
9024                               NULL);
9025 
9026   c = HiddenGroup (h, 2, 0, NULL);
9027   SetGroupSpacing (c, 10, 10);
9028   ecd.accept_btn = PushButton (c, "Accept", ModalAcceptButton);
9029   SetObjectExtra (ecd.accept_btn, &acd, NULL);
9030   b = PushButton (c, "Cancel", ModalCancelButton);
9031   SetObjectExtra (b, &acd, NULL);
9032   AlignObjects (ALIGN_CENTER, (HANDLE) ecd.transform_type,
9033                               (HANDLE) g,
9034                               (HANDLE) c,
9035                               NULL);
9036 
9037   val = PopupFromTextTransformChoice (transform->choice);
9038   if (val > 0 && val < eTextTransformPopup_Max) {
9039     SetValue (ecd.transform_type, val);
9040     if (val == eTextTransformPopup_Caps) {
9041       SetCapChangeDialogValue(ecd.dlgs[val - 1], transform->data.intvalue);
9042     } else {
9043       PointerToDialog (ecd.dlgs[val - 1], transform->data.ptrvalue);
9044     }
9045   } else {
9046     SetValue (ecd.transform_type, eTextTransformPopup_Edit);
9047   }
9048 
9049   ChangeEditTextTransformType (ecd.transform_type);
9050   Show (w);
9051   Select (w);
9052   acd.accepted = FALSE;
9053   acd.cancelled = FALSE;
9054   while (!acd.accepted && ! acd.cancelled)
9055   {
9056     ProcessExternalEvent ();
9057     Update ();
9058   }
9059   ProcessAnEvent ();
9060   if (!acd.cancelled)
9061   {
9062     val = GetValue (ecd.transform_type);
9063     switch (val) {
9064       case eTextTransformPopup_Edit:
9065       case eTextTransformPopup_RemoveOutside:
9066         FreeTextTransformData (transform);
9067         transform->choice = TextTransformTable[val - 1].transform_choice;
9068         transform->data.ptrvalue = DialogToPointer (ecd.dlgs[val - 1]);
9069         rval = TRUE;
9070         break;
9071       case eTextTransformPopup_Caps:
9072         FreeTextTransformData (transform);
9073         transform->choice = TextTransform_caps;
9074         transform->data.intvalue = GetCapChangeDialogValue(ecd.dlgs[val - 1]);
9075         rval = TRUE;
9076         break;
9077     }
9078   }
9079   Remove (w);
9080   return rval;
9081 }
9082 
9083 
9084 typedef struct texttransformsetdlg {
9085   DIALOG_MESSAGE_BLOCK
9086   DoC                  transform_doc;
9087   ValNodePtr           transform_list;
9088   ValNodePtr           default_transform;
9089 
9090   Nlm_ChangeNotifyProc change_notify;
9091   Pointer              change_userdata;
9092 } TextTransformSetDlgData, PNTR TextTransformSetDlgPtr;
9093 
PopulateTextTransformDoc(DoC d,ValNodePtr transform_list)9094 static void PopulateTextTransformDoc (DoC d, ValNodePtr transform_list)
9095 {
9096   ValNodePtr vnp;
9097   CharPtr    phrase, tmp;
9098   RecT       r;
9099   ParData    ParFmt = {FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0};
9100   ColData    ColFmt[] =
9101   {
9102     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
9103     {0, 0, 80, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, TRUE}
9104   };
9105 
9106   if (d == NULL) return;
9107 
9108   Reset (d);
9109 
9110   ObjectRect (d, &r);
9111   InsetRect (&r, 4, 4);
9112 
9113   ColFmt[1].pixWidth = r.right - r.left - 12;
9114 
9115   Reset (d);
9116 
9117   for (vnp = transform_list; vnp != NULL; vnp = vnp->next) {
9118     phrase = SummarizeTextTransform (vnp);
9119     if (phrase == NULL) {
9120       AppendText (d, "\tUnable to summarize text transform\n", &ParFmt, ColFmt, programFont);
9121     } else {
9122       tmp = (CharPtr) MemNew (sizeof (Char) * (StringLen (phrase) + 3));
9123       sprintf (tmp, "\t%s\n", phrase);
9124       phrase = MemFree (phrase);
9125       AppendText (d, tmp, &ParFmt, ColFmt, programFont);
9126       tmp = MemFree (tmp);
9127     }
9128   }
9129   AppendText (d, "(Click here to add new text transform)", NULL, NULL, programFont);
9130   UpdateDocument (d, 0, 0);
9131 }
9132 
DrawTextTransformDocControls(DoC d,RectPtr r,Int2 item,Int2 firstLine)9133 static void DrawTextTransformDocControls (DoC d, RectPtr r, Int2 item, Int2 firstLine)
9134 
9135 {
9136   RecT                   rct;
9137   Int4                   width;
9138   PoinT                  pt1, pt2;
9139   TextTransformSetDlgPtr dlg;
9140 
9141   dlg = (TextTransformSetDlgPtr) GetObjectExtra (d);
9142   if (dlg != NULL && r != NULL && item > 0 && firstLine == 0 && item <= ValNodeLen (dlg->transform_list)) {
9143     rct = *r;
9144 
9145     /* draw X for deletion */
9146     width = 10;
9147     pt1.x = rct.left + 1;
9148     pt1.y = rct.top + 1;
9149     pt2.x = pt1.x + width;
9150     pt2.y = pt1.y + width;
9151     DrawLine (pt1, pt2);
9152     pt1.x = rct.left + 1;
9153     pt1.y = rct.top + 1 + width;
9154     pt2.x = pt1.x + width;
9155     pt2.y = rct.top + 1;
9156     DrawLine (pt1, pt2);
9157   }
9158 }
9159 
ClickTextTransformDoc(DoC d,PoinT pt)9160 static void ClickTextTransformDoc (DoC d, PoinT pt)
9161 {
9162   Int2      item, row, col;
9163   RecT      rct;
9164   BaR       sb_vert;
9165   Int4      scroll_pos = 0, scroll_max;
9166   TextTransformSetDlgPtr f;
9167   ValNodePtr         vnp, vnp_prev = NULL;
9168   Boolean            changed = FALSE;
9169 
9170   f = (TextTransformSetDlgPtr) GetObjectExtra (d);
9171   if (f == NULL) return;
9172 
9173   MapDocPoint (d, pt, &item, &row, &col, &rct);
9174   if (item == 0 && row == 0 && f->transform_list == NULL) {
9175     /* create new constraint */
9176     vnp = ValNodeNew (NULL);
9177     vnp->choice = TextTransform_edit;
9178     if (EditTextTransform (vnp)) {
9179       f->transform_list = vnp;
9180       changed = TRUE;
9181     } else {
9182       vnp = TextTransformFree (vnp);
9183     }
9184   } else if (item > 0 && row > 0) {
9185     if (item == ValNodeLen (f->transform_list) + 1) {
9186       /* create new constraint */
9187       vnp = ValNodeNew (NULL);
9188       vnp->choice = TextTransform_edit;
9189       if (EditTextTransform (vnp)) {
9190         ValNodeLink (&(f->transform_list), vnp);
9191         changed = TRUE;
9192       } else {
9193         vnp = TextTransformFree (vnp);
9194       }
9195     } else {
9196       for (vnp = f->transform_list; vnp != NULL && item > 1; vnp = vnp->next, item--) {
9197         vnp_prev = vnp;
9198       }
9199       if (vnp != NULL) {
9200         sb_vert = GetSlateVScrollBar ((SlatE) f->transform_doc);
9201         scroll_pos = GetBarValue (sb_vert);
9202         switch (col) {
9203           case 1:
9204             /* delete this item */
9205             if (vnp_prev == NULL) {
9206               f->transform_list = vnp->next;
9207             } else {
9208               vnp_prev->next = vnp->next;
9209             }
9210             vnp->next = NULL;
9211             vnp = TextTransformFree (vnp);
9212             changed = TRUE;
9213             break;
9214           case 2:
9215             /* edit */
9216             changed = EditTextTransform (vnp);
9217             break;
9218         }
9219       }
9220     }
9221   }
9222   if (changed) {
9223     PopulateTextTransformDoc (f->transform_doc, f->transform_list);
9224     if (scroll_pos > 0) {
9225       sb_vert = GetSlateVScrollBar ((SlatE) f->transform_doc);
9226       scroll_max = GetBarMax (sb_vert);
9227       if (scroll_pos > scroll_max) {
9228         scroll_pos = scroll_max;
9229       }
9230       CorrectBarValue (sb_vert, scroll_pos);
9231     }
9232     if (f->change_notify != NULL) {
9233       (f->change_notify) (f->change_userdata);
9234     }
9235   }
9236 }
9237 
9238 
TextTransformSetToDialog(DialoG d,Pointer data)9239 static void TextTransformSetToDialog (DialoG d, Pointer data)
9240 {
9241   TextTransformSetDlgPtr dlg;
9242 
9243   dlg = (TextTransformSetDlgPtr) GetObjectExtra (d);
9244   if (dlg == NULL) return;
9245 
9246   dlg->transform_list = TextTransformSetFree (dlg->transform_list);
9247   if (data != NULL) {
9248     dlg->transform_list = AsnIoMemCopy ((TextTransformSetPtr) data,
9249                                          (AsnReadFunc) TextTransformSetAsnRead,
9250                                          (AsnWriteFunc) TextTransformSetAsnWrite);
9251  }
9252  PopulateTextTransformDoc (dlg->transform_doc, dlg->transform_list);
9253  if (dlg->change_notify != NULL) {
9254     (dlg->change_notify) (dlg->change_userdata);
9255   }
9256 }
9257 
9258 
TextTransformSetFromDialog(DialoG d)9259 static Pointer TextTransformSetFromDialog (DialoG d)
9260 {
9261   TextTransformSetDlgPtr dlg;
9262   ValNodePtr transform_list = NULL;
9263 
9264   dlg = (TextTransformSetDlgPtr) GetObjectExtra (d);
9265   if (dlg == NULL) return NULL;
9266 
9267   if (dlg->transform_list != NULL) {
9268     transform_list = AsnIoMemCopy ((TextTransformSetPtr) dlg->transform_list,
9269                                     (AsnReadFunc) TextTransformSetAsnRead,
9270                                     (AsnWriteFunc) TextTransformSetAsnWrite);
9271   }
9272   return (Pointer) transform_list;
9273 }
9274 
CleanupTextTransformSetDialog(GraphiC g,VoidPtr data)9275 static void CleanupTextTransformSetDialog (GraphiC g, VoidPtr data)
9276 
9277 {
9278   TextTransformSetDlgPtr dlg;
9279 
9280   dlg = (TextTransformSetDlgPtr) data;
9281   if (dlg != NULL) {
9282     dlg->transform_list = TextTransformSetFree (dlg->transform_list);
9283     dlg->default_transform = TextTransformFree (dlg->default_transform);
9284   }
9285   StdCleanupExtraProc (g, data);
9286 }
9287 
9288 
AddTextTransformBtn(ButtoN b)9289 static void AddTextTransformBtn (ButtoN b)
9290 {
9291   TextTransformSetDlgPtr dlg;
9292   ValNodePtr          vnp;
9293   BaR       sb_vert;
9294   Int4      scroll_pos = 0, scroll_max;
9295 
9296   dlg = (TextTransformSetDlgPtr) GetObjectExtra (b);
9297   if (dlg == NULL) {
9298     return;
9299   }
9300 
9301   sb_vert = GetSlateVScrollBar ((SlatE) dlg->transform_doc);
9302   scroll_pos = GetBarValue (sb_vert);
9303 
9304   /* create new constraint */
9305   vnp = ValNodeNew (NULL);
9306   vnp->choice = TextTransform_edit;
9307   if (EditTextTransform (vnp)) {
9308     ValNodeLink (&(dlg->transform_list), vnp);
9309     PopulateTextTransformDoc (dlg->transform_doc, dlg->transform_list);
9310     if (scroll_pos > 0) {
9311       sb_vert = GetSlateVScrollBar ((SlatE) dlg->transform_doc);
9312       scroll_max = GetBarMax (sb_vert);
9313       if (scroll_pos > scroll_max) {
9314         scroll_pos = scroll_max;
9315       }
9316       CorrectBarValue (sb_vert, scroll_pos);
9317     }
9318     if (dlg->change_notify != NULL) {
9319       (dlg->change_notify) (dlg->change_userdata);
9320     }
9321   } else {
9322     vnp = TextTransformFree (vnp);
9323   }
9324 
9325 }
9326 
9327 
TextTransformSetDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)9328 NLM_EXTERN DialoG TextTransformSetDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
9329 {
9330   TextTransformSetDlgPtr dlg;
9331   GrouP               p, g;
9332   PrompT              ppt;
9333   ButtoN              b;
9334 
9335   p = HiddenGroup (h, -1, 0, NULL);
9336   SetGroupSpacing (p, 10, 10);
9337   dlg = (TextTransformSetDlgPtr) MemNew (sizeof (TextTransformSetDlgData));
9338   SetObjectExtra (p, dlg, CleanupTextTransformSetDialog);
9339 
9340   dlg->dialog = (DialoG) p;
9341   dlg->todialog = TextTransformSetToDialog;
9342   dlg->fromdialog = TextTransformSetFromDialog;
9343   dlg->change_notify = change_notify;
9344   dlg->change_userdata = change_userdata;
9345 
9346   dlg->transform_list = NULL;
9347   ppt = StaticPrompt (p, "Text Transform List", 0, dialogTextHeight, programFont, 'c');
9348   dlg->transform_doc = DocumentPanel (p, stdCharWidth * 30, stdLineHeight * 2);
9349   SetObjectExtra (dlg->transform_doc, dlg, NULL);
9350   SetDocProcs (dlg->transform_doc, ClickTextTransformDoc, NULL, NULL, NULL);
9351   SetDocShade (dlg->transform_doc, DrawTextTransformDocControls, NULL, NULL, NULL);
9352   PopulateTextTransformDoc (dlg->transform_doc, dlg->transform_list);
9353 
9354   g = HiddenGroup (p, 2, 0, NULL);
9355   b = PushButton (g, "Add Text Transform", AddTextTransformBtn);
9356   SetObjectExtra (b, dlg, NULL);
9357   b = PushButton (g, "Clear Text Transforms", ClearDialogBtn);
9358   SetObjectExtra (b, p, NULL);
9359 
9360   AlignObjects (ALIGN_CENTER, (HANDLE) ppt, (HANDLE) dlg->transform_doc, (HANDLE) g, NULL);
9361 
9362   dlg->default_transform = ValNodeNew (NULL);
9363   dlg->default_transform->choice = TextTransform_edit;
9364   return (DialoG) p;
9365 }
9366 
9367 
9368 
9369 typedef struct oldcdsgeneprotconstraintdlg {
9370   DIALOG_MESSAGE_BLOCK
9371   DialoG string_qual_choice;
9372   DialoG string_constraint;
9373 
9374   Nlm_ChangeNotifyProc change_notify;
9375   Pointer              change_userdata;
9376 } OldCDSGeneProtConstraintDlgData, PNTR OldCDSGeneProtConstraintDlgPtr;
9377 
9378 
ConstraintToOldCDSGeneProtConstraintDlg(DialoG d,Pointer data)9379 static void ConstraintToOldCDSGeneProtConstraintDlg (DialoG d, Pointer data)
9380 {
9381   OldCDSGeneProtConstraintDlgPtr dlg;
9382   ValNodePtr                     constraint;
9383   CDSGeneProtQualConstraintPtr   cgp_constraint;
9384 
9385   dlg = (OldCDSGeneProtConstraintDlgPtr) GetObjectExtra (d);
9386   if (dlg == NULL) return;
9387   constraint = (ValNodePtr) data;
9388   if (constraint == NULL || constraint->choice != ConstraintChoice_cdsgeneprot_qual) {
9389     PointerToDialog (dlg->string_qual_choice, NULL);
9390     PointerToDialog (dlg->string_constraint, NULL);
9391   } else {
9392     cgp_constraint = (CDSGeneProtQualConstraintPtr) constraint->data.ptrvalue;
9393     if (cgp_constraint == NULL) {
9394       PointerToDialog (dlg->string_qual_choice, NULL);
9395       PointerToDialog (dlg->string_constraint, NULL);
9396     } else {
9397       PointerToDialog (dlg->string_qual_choice, cgp_constraint->field1);
9398       PointerToDialog (dlg->string_constraint, cgp_constraint->constraint);
9399     }
9400   }
9401 
9402   if (dlg->change_notify) {
9403     (dlg->change_notify) (dlg->change_userdata);
9404   }
9405 }
9406 
9407 
OldCDSGeneProtConstraintDlgToConstraint(DialoG d)9408 static Pointer OldCDSGeneProtConstraintDlgToConstraint (DialoG d)
9409 {
9410   OldCDSGeneProtConstraintDlgPtr dlg;
9411   ValNodePtr constraint = NULL;
9412   CDSGeneProtQualConstraintPtr   cgp_constraint;
9413   ValNodePtr                     vnp;
9414   StringConstraintPtr            string_constraint;
9415 
9416   dlg = (OldCDSGeneProtConstraintDlgPtr) GetObjectExtra (d);
9417   if (dlg == NULL) return NULL;
9418 
9419   /* string constraint */
9420   string_constraint = DialogToPointer (dlg->string_constraint);
9421   if (IsStringConstraintEmpty (string_constraint)) {
9422     string_constraint = StringConstraintFree (string_constraint);
9423   } else {
9424     vnp = DialogToPointer (dlg->string_qual_choice);
9425     if (vnp == NULL) {
9426       string_constraint = StringConstraintFree (string_constraint);
9427     } else {
9428       vnp->choice = CDSGeneProtConstraintField_field;
9429       cgp_constraint = CDSGeneProtQualConstraintNew ();
9430       cgp_constraint->field1 = vnp;
9431       cgp_constraint->constraint = string_constraint;
9432       ValNodeAddPointer (&constraint, ConstraintChoice_cdsgeneprot_qual, cgp_constraint);
9433     }
9434   }
9435   return (Pointer) constraint;
9436 }
9437 
9438 
ClearOldCDSGeneProtConstraintDialogText(DialoG d)9439 static void ClearOldCDSGeneProtConstraintDialogText (DialoG d)
9440 {
9441   OldCDSGeneProtConstraintDlgPtr dlg;
9442 
9443   dlg = (OldCDSGeneProtConstraintDlgPtr) GetObjectExtra (d);
9444   if (dlg == NULL) return;
9445 
9446   ClearStringConstraintDialogText (dlg->string_constraint);
9447 }
9448 
9449 
TestOldCDSGeneProtConstraintDlg(DialoG d)9450 static ValNodePtr TestOldCDSGeneProtConstraintDlg (DialoG d)
9451 {
9452   OldCDSGeneProtConstraintDlgPtr dlg;
9453   ValNodePtr                     err_list = NULL;
9454   StringConstraintPtr            scp;
9455 
9456   dlg = (OldCDSGeneProtConstraintDlgPtr) GetObjectExtra (d);
9457   if (dlg == NULL) return NULL;
9458 
9459   scp = DialogToPointer (dlg->string_constraint);
9460   if (!IsStringConstraintEmpty (scp)) {
9461     ValNodeLink (&err_list, TestDialog (dlg->string_qual_choice));
9462   }
9463   scp = StringConstraintFree (scp);
9464   return err_list;
9465 }
9466 
9467 
9468 static DialoG CDSGeneProtFieldDialogEx (GrouP h, Boolean tall, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata);
9469 
OldCDSGeneProtConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)9470 static DialoG OldCDSGeneProtConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
9471 {
9472   OldCDSGeneProtConstraintDlgPtr dlg;
9473   GrouP p, q;
9474   ButtoN b;
9475 
9476   dlg = (OldCDSGeneProtConstraintDlgPtr) MemNew (sizeof (OldCDSGeneProtConstraintDlgData));
9477 
9478   p = HiddenGroup (h, -1, 0, NULL);
9479   SetObjectExtra (p, dlg, StdCleanupExtraProc);
9480   SetGroupSpacing (p, 10, 10);
9481 
9482   dlg->dialog = (DialoG) p;
9483   dlg->todialog = ConstraintToOldCDSGeneProtConstraintDlg;
9484   dlg->fromdialog = OldCDSGeneProtConstraintDlgToConstraint;
9485   dlg->testdialog = TestOldCDSGeneProtConstraintDlg;
9486   dlg->change_notify = change_notify;
9487   dlg->change_userdata = change_userdata;
9488 
9489   q = HiddenGroup (p, 2, 0, NULL);
9490   dlg->string_qual_choice = CDSGeneProtFieldDialogEx (q, FALSE, change_notify, change_userdata);
9491   dlg->string_constraint = StringConstraintDialog (q, "", FALSE, change_notify, change_userdata);
9492 
9493 
9494   b = PushButton (p, "Clear Constraint", ClearDialogBtn);
9495   SetObjectExtra (b, p, NULL);
9496 
9497   AlignObjects (ALIGN_CENTER, (HANDLE) q, (HANDLE) b, NULL);
9498 
9499   return (DialoG) p;
9500 }
9501 
9502 
9503 typedef struct oldsrcconstraintdlg {
9504   DIALOG_MESSAGE_BLOCK
9505   DialoG string_qual_choice;
9506   DialoG string_constraint;
9507 
9508   Nlm_ChangeNotifyProc change_notify;
9509   Pointer              change_userdata;
9510 } OldSrcConstraintDlgData, PNTR OldSrcConstraintDlgPtr;
9511 
9512 
ConstraintToOldSrcConstraintDlg(DialoG d,Pointer data)9513 static void ConstraintToOldSrcConstraintDlg (DialoG d, Pointer data)
9514 {
9515   OldSrcConstraintDlgPtr dlg;
9516   SourceConstraintPtr    src_constraint;
9517   ValNodePtr             constraint;
9518 
9519   dlg = (OldSrcConstraintDlgPtr) GetObjectExtra (d);
9520   if (dlg == NULL) return;
9521   constraint = (ValNodePtr) data;
9522   if (constraint == NULL || constraint->choice != ConstraintChoice_source) {
9523     PointerToDialog (dlg->string_qual_choice, NULL);
9524     PointerToDialog (dlg->string_constraint, NULL);
9525   } else {
9526     src_constraint = (SourceConstraintPtr) constraint->data.ptrvalue;
9527     if (src_constraint == NULL) {
9528       PointerToDialog (dlg->string_qual_choice, NULL);
9529       PointerToDialog (dlg->string_constraint, NULL);
9530     } else {
9531       PointerToDialog (dlg->string_qual_choice, src_constraint->field1);
9532       PointerToDialog (dlg->string_constraint, src_constraint->constraint);
9533     }
9534   }
9535 
9536   if (dlg->change_notify != NULL) {
9537     (dlg->change_notify) (dlg->change_userdata);
9538   }
9539 }
9540 
9541 
ClearOldSrcConstraintDialogText(DialoG d)9542 static void ClearOldSrcConstraintDialogText (DialoG d)
9543 {
9544   OldSrcConstraintDlgPtr dlg;
9545   dlg = (OldSrcConstraintDlgPtr) GetObjectExtra (d);
9546   if (dlg == NULL) return;
9547 
9548   ClearStringConstraintDialogText (dlg->string_constraint);
9549 }
9550 
9551 
OldSrcConstraintDlgToConstraint(DialoG d)9552 static Pointer OldSrcConstraintDlgToConstraint (DialoG d)
9553 {
9554   OldSrcConstraintDlgPtr dlg;
9555   ValNodePtr             constraint = NULL;
9556   SourceConstraintPtr    src_constraint;
9557   StringConstraintPtr    string_constraint;
9558   ValNodePtr             vnp;
9559 
9560   dlg = (OldSrcConstraintDlgPtr) GetObjectExtra (d);
9561   if (dlg == NULL) return NULL;
9562 
9563   /* string constraint */
9564   string_constraint = DialogToPointer (dlg->string_constraint);
9565   if (IsStringConstraintEmpty (string_constraint)) {
9566     string_constraint = StringConstraintFree (string_constraint);
9567   } else {
9568     vnp = DialogToPointer (dlg->string_qual_choice);
9569     if (vnp == NULL) {
9570       string_constraint = StringConstraintFree (string_constraint);
9571     } else {
9572       src_constraint = SourceConstraintNew ();
9573       src_constraint->field1 = vnp;
9574       src_constraint->constraint = string_constraint;
9575       ValNodeAddPointer (&constraint, ConstraintChoice_source, src_constraint);
9576     }
9577   }
9578   return (Pointer) constraint;
9579 }
9580 
9581 
TestOldSrcConstraintDlg(DialoG d)9582 static ValNodePtr TestOldSrcConstraintDlg (DialoG d)
9583 {
9584   OldSrcConstraintDlgPtr dlg;
9585   ValNodePtr             err_list = NULL;
9586   StringConstraintPtr    scp;
9587 
9588   dlg = (OldSrcConstraintDlgPtr) GetObjectExtra (d);
9589   if (dlg == NULL) return NULL;
9590 
9591   scp = DialogToPointer (dlg->string_constraint);
9592   if (!IsStringConstraintEmpty (scp)) {
9593       ValNodeLink (&err_list, TestDialog (dlg->string_qual_choice));
9594   }
9595   scp = StringConstraintFree (scp);
9596   return err_list;
9597 }
9598 
9599 
OldSrcConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)9600 static DialoG OldSrcConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
9601 {
9602   OldSrcConstraintDlgPtr dlg;
9603   GrouP p, q;
9604   ButtoN b;
9605 
9606   dlg = (OldSrcConstraintDlgPtr) MemNew (sizeof (OldSrcConstraintDlgData));
9607 
9608   p = HiddenGroup (h, -1, 0, NULL);
9609   SetObjectExtra (p, dlg, StdCleanupExtraProc);
9610   SetGroupSpacing (p, 10, 10);
9611 
9612   dlg->dialog = (DialoG) p;
9613   dlg->todialog = ConstraintToOldSrcConstraintDlg;
9614   dlg->fromdialog = OldSrcConstraintDlgToConstraint;
9615   dlg->testdialog = TestOldSrcConstraintDlg;
9616   dlg->change_notify = change_notify;
9617   dlg->change_userdata = change_userdata;
9618 
9619   q = HiddenGroup (p, 2, 0, NULL);
9620   dlg->string_qual_choice = SourceQualChoiceDialog (q, TRUE, FALSE, TRUE, change_notify, change_userdata);
9621   dlg->string_constraint = StringConstraintDialog (q, "", FALSE, change_notify, change_userdata);
9622 
9623   b = PushButton (p, "Clear Constraint", ClearDialogBtn);
9624   SetObjectExtra (b, p, NULL);
9625 
9626   AlignObjects (ALIGN_CENTER, (HANDLE) q, (HANDLE) b, NULL);
9627 
9628   return (DialoG) p;
9629 }
9630 
9631 
9632 typedef struct simplesequenceconstraintdlg {
9633   DIALOG_MESSAGE_BLOCK
9634   GrouP seqtype;
9635   GrouP rna_subtype_grp;
9636   DialoG rna_subtype;
9637   DialoG src_loc;
9638   DialoG id;
9639 
9640   Nlm_ChangeNotifyProc change_notify;
9641   Pointer change_userdata;
9642 
9643 } SimpleSequenceConstraintDlgData, PNTR SimpleSequenceConstraintDlgPtr;
9644 
9645 
ClearSimpleSequenceConstraintDialogText(DialoG d)9646 static void ClearSimpleSequenceConstraintDialogText (DialoG d)
9647 {
9648   SimpleSequenceConstraintDlgPtr dlg;
9649 
9650   dlg = (SimpleSequenceConstraintDlgPtr) GetObjectExtra (d);
9651   if (dlg == NULL) return;
9652   ClearStringConstraintDialogText (dlg->id);
9653 }
9654 
9655 
ChangeSimpleSequenceConstraintGroup(GrouP g)9656 static void ChangeSimpleSequenceConstraintGroup (GrouP g)
9657 {
9658   SimpleSequenceConstraintDlgPtr dlg;
9659 
9660   dlg = (SimpleSequenceConstraintDlgPtr) GetObjectExtra (g);
9661   if (dlg == NULL) return;
9662 
9663   if (GetValue (dlg->seqtype) == 4) {
9664     Show (dlg->rna_subtype_grp);
9665   } else {
9666     Hide (dlg->rna_subtype_grp);
9667   }
9668 
9669   if (dlg->change_notify != NULL) {
9670     (dlg->change_notify) (dlg->change_userdata);
9671   }
9672 }
9673 
9674 
SimpleSequenceConstraintToDialog(DialoG d,Pointer data)9675 static void SimpleSequenceConstraintToDialog (DialoG d, Pointer data)
9676 {
9677   SimpleSequenceConstraintDlgPtr dlg;
9678   ConstraintChoiceSetPtr constraint;
9679   SequenceConstraintPtr  seq;
9680   SourceConstraintPtr    src;
9681   ValNode vn;
9682   Int4    loc_val;
9683 
9684   dlg = (SimpleSequenceConstraintDlgPtr) GetObjectExtra (d);
9685   if (dlg == NULL) return;
9686 
9687   PointerToDialog (dlg->src_loc, NULL);
9688   SetValue (dlg->seqtype, 2);
9689   PointerToDialog (dlg->rna_subtype, NULL);
9690   Hide (dlg->rna_subtype_grp);
9691   constraint = (ConstraintChoiceSetPtr) data;
9692   PointerToDialog (dlg->id, NULL);
9693 
9694   while (constraint != NULL) {
9695     if (constraint->choice == ConstraintChoice_sequence
9696       && (seq = (SequenceConstraintPtr) constraint->data.ptrvalue) != NULL) {
9697       if (seq->seqtype != NULL) {
9698         switch (seq->seqtype->choice) {
9699           case SequenceConstraintMolTypeConstraint_any :
9700             SetValue (dlg->seqtype, 1);
9701             PointerToDialog (dlg->rna_subtype, NULL);
9702             Hide (dlg->rna_subtype_grp);
9703             break;
9704           case SequenceConstraintMolTypeConstraint_nucleotide :
9705             SetValue (dlg->seqtype, 2);
9706             PointerToDialog (dlg->rna_subtype, NULL);
9707             Hide (dlg->rna_subtype_grp);
9708             break;
9709           case SequenceConstraintMolTypeConstraint_dna :
9710             SetValue (dlg->seqtype, 3);
9711             PointerToDialog (dlg->rna_subtype, NULL);
9712             Hide (dlg->rna_subtype_grp);
9713             break;
9714           case SequenceConstraintMolTypeConstraint_rna :
9715             SetValue (dlg->seqtype, 5);
9716             vn.choice = seq->seqtype->data.intvalue;
9717             vn.data.ptrvalue = NULL;
9718             vn.next = NULL;
9719             PointerToDialog (dlg->rna_subtype, &vn);
9720             Show (dlg->rna_subtype_grp);
9721             break;
9722           case SequenceConstraintMolTypeConstraint_protein :
9723             SetValue (dlg->seqtype, 4);
9724             PointerToDialog (dlg->rna_subtype, NULL);
9725             Hide (dlg->rna_subtype_grp);
9726             break;
9727         }
9728       }
9729       PointerToDialog (dlg->id, seq->id);
9730     } else if (constraint->choice == ConstraintChoice_source
9731       && (src = (SourceConstraintPtr) constraint->data.ptrvalue) != NULL) {
9732       if (src->field1 != NULL && src->field1->choice == SourceQualChoice_location) {
9733         vn.choice = src->field1->data.intvalue;
9734         vn.data.ptrvalue = NULL;
9735         vn.next = NULL;
9736         PointerToDialog (dlg->src_loc, &vn);
9737       } else if (src->field2 != NULL && src->field2->choice == SourceQualChoice_location) {
9738         vn.choice = src->field2->data.intvalue;
9739         vn.data.ptrvalue = NULL;
9740         vn.next = NULL;
9741         PointerToDialog (dlg->src_loc, &vn);
9742       }
9743       if (src->constraint != NULL
9744           && src->constraint->match_location == String_location_equals
9745           && (loc_val = GenomeFromLocName (src->constraint->match_text)) > 0) {
9746         vn.choice = SrcLocFromGenome (loc_val);
9747         vn.data.ptrvalue = NULL;
9748         vn.next = NULL;
9749         PointerToDialog (dlg->src_loc, &vn);
9750       }
9751     }
9752     constraint = constraint->next;
9753   }
9754 }
9755 
9756 
SimpleSequenceConstraintFromDialog(DialoG d)9757 static Pointer SimpleSequenceConstraintFromDialog (DialoG d)
9758 {
9759   SimpleSequenceConstraintDlgPtr dlg;
9760   SequenceConstraintPtr seq = NULL;
9761   SourceConstraintPtr   src = NULL;
9762   StringConstraintPtr   id = NULL;
9763   ValNodePtr            constraint = NULL, vnp;
9764   Int4 val;
9765 
9766   dlg = (SimpleSequenceConstraintDlgPtr) GetObjectExtra (d);
9767   if (dlg == NULL) return NULL;
9768 
9769   val = GetValue (dlg->seqtype);
9770   switch (val) {
9771     case 1:
9772       /* don't bother to fill in, it's optional */
9773       break;
9774     case 2:
9775       seq = SequenceConstraintNew ();
9776       seq->seqtype = ValNodeNew (NULL);
9777       seq->seqtype->choice = SequenceConstraintMolTypeConstraint_nucleotide;
9778       break;
9779     case 3:
9780       seq = SequenceConstraintNew ();
9781       seq->seqtype = ValNodeNew (NULL);
9782       seq->seqtype->choice = SequenceConstraintMolTypeConstraint_dna;
9783       break;
9784     case 4:
9785       seq = SequenceConstraintNew ();
9786       seq->seqtype = ValNodeNew (NULL);
9787       seq->seqtype->choice = SequenceConstraintMolTypeConstraint_protein;
9788       break;
9789     case 5:
9790       seq = SequenceConstraintNew ();
9791       seq->seqtype = ValNodeNew (NULL);
9792       seq->seqtype->choice = SequenceConstraintMolTypeConstraint_rna;
9793       vnp = DialogToPointer (dlg->rna_subtype);
9794       if (vnp == NULL) {
9795         seq->seqtype->data.intvalue = Sequence_constraint_rnamol_any;
9796       } else {
9797         seq->seqtype->data.intvalue = vnp->choice;
9798       }
9799       break;
9800   }
9801 
9802   id = DialogToPointer (dlg->id);
9803   if (IsStringConstraintEmpty (id)) {
9804     id = StringConstraintFree (id);
9805   } else {
9806     if (seq == NULL) {
9807       seq = SequenceConstraintNew ();
9808     }
9809     seq->id = id;
9810   }
9811 
9812   if (seq != NULL) {
9813     ValNodeAddPointer (&constraint, ConstraintChoice_sequence, seq);
9814   }
9815 
9816   vnp = DialogToPointer (dlg->src_loc);
9817   if (vnp != NULL && vnp->choice != Source_location_unknown) {
9818     src = SourceConstraintNew ();
9819     src->field1 = ValNodeNew (NULL);
9820     src->field1->choice = SourceQualChoice_location;
9821     src->field1->data.intvalue = vnp->choice;
9822     src->constraint = StringConstraintNew ();
9823     src->constraint->match_location = String_location_equals;
9824     src->constraint->match_text = StringSave (LocNameFromGenome (GenomeFromSrcLoc(vnp->choice)));
9825     ValNodeAddPointer (&constraint, ConstraintChoice_source, src);
9826   }
9827   vnp = ValNodeFree (vnp);
9828 
9829   return constraint;
9830 }
9831 
9832 
SimpleSequenceConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)9833 static DialoG SimpleSequenceConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
9834 {
9835   SimpleSequenceConstraintDlgPtr dlg;
9836   GrouP p, g, g2;
9837   ValNodePtr rna_subtypes = NULL, loc_list;
9838 
9839   dlg = (SimpleSequenceConstraintDlgPtr) MemNew (sizeof (SimpleSequenceConstraintDlgData));
9840   p = HiddenGroup (h, -1, 0, NULL);
9841   SetGroupSpacing (p, 10, 10);
9842   SetObjectExtra (p, dlg, StdCleanupExtraProc);
9843   dlg->dialog = (DialoG) p;
9844   dlg->todialog = SimpleSequenceConstraintToDialog;
9845   dlg->fromdialog = SimpleSequenceConstraintFromDialog;
9846   dlg->change_notify = change_notify;
9847   dlg->change_userdata = change_userdata;
9848 
9849   g2 = HiddenGroup (p, 2, 0, NULL);
9850   dlg->seqtype = HiddenGroup (g2, 5, 0, ChangeSimpleSequenceConstraintGroup);
9851   SetObjectExtra (dlg->seqtype, dlg, NULL);
9852   RadioButton (dlg->seqtype, "Any sequence");
9853   RadioButton (dlg->seqtype, "Nucleotides");
9854   RadioButton (dlg->seqtype, "DNA");
9855   RadioButton (dlg->seqtype, "Proteins");
9856   RadioButton (dlg->seqtype, "RNA");
9857   SetValue (dlg->seqtype, 2);
9858   dlg->rna_subtype_grp = HiddenGroup (g2, 2, 0, NULL);
9859   StaticPrompt (dlg->rna_subtype_grp, "RNA Type", 0, dialogTextHeight, programFont, 'r');
9860   AddAllRNASubtypesToChoiceList (&rna_subtypes);
9861   dlg->rna_subtype = ValNodeSelectionDialog (dlg->rna_subtype_grp, rna_subtypes, TALL_SELECTION_LIST, ValNodeStringName,
9862                                 ValNodeSimpleDataFree, ValNodeStringCopy,
9863                                 ValNodeChoiceMatch, "rna subtype",
9864                                 change_notify, change_userdata, FALSE);
9865 
9866   Hide (dlg->rna_subtype_grp);
9867 
9868   g = HiddenGroup (p, 2, 0, NULL);
9869   loc_list = GetLocationList (TRUE);
9870   StaticPrompt (g, "Where source location is", 0, dialogTextHeight, programFont, 'r');
9871   dlg->src_loc = ValNodeSelectionDialog (g,loc_list, 2, ValNodeStringName,
9872                                 ValNodeSimpleDataFree, ValNodeStringCopy,
9873                                 ValNodeChoiceMatch, "src location",
9874                                 change_notify, change_userdata, FALSE);
9875 
9876   dlg->id = StringConstraintDialog (p, "Where sequence ID", FALSE, change_notify, change_userdata);
9877 
9878   AlignObjects (ALIGN_CENTER, (HANDLE) g2, (HANDLE) g, (HANDLE) dlg->id, NULL);
9879   return (DialoG) p;
9880 }
9881 
9882 
9883 typedef struct rnafieldconstraintdlg {
9884   DIALOG_MESSAGE_BLOCK
9885 
9886   DialoG RNA_field;
9887   DialoG string_constraint;
9888 
9889   Nlm_ChangeNotifyProc change_notify;
9890   Pointer              change_userdata;
9891 } RNAFieldConstraintDlgData, PNTR RNAFieldConstraintDlgPtr;
9892 
9893 
ClearRnaFieldConstraintDialogText(DialoG d)9894 static void ClearRnaFieldConstraintDialogText (DialoG d)
9895 {
9896   RNAFieldConstraintDlgPtr  dlg;
9897 
9898   dlg = (RNAFieldConstraintDlgPtr) GetObjectExtra (d);
9899   if (dlg == NULL) {
9900     return;
9901   }
9902 
9903   ClearStringConstraintDialogText (dlg->string_constraint);
9904 }
9905 
9906 
RNAFieldConstraintDlgToData(DialoG d)9907 static Pointer RNAFieldConstraintDlgToData (DialoG d)
9908 {
9909   RNAFieldConstraintDlgPtr  dlg;
9910   ValNodePtr                constraint = NULL;
9911   FieldConstraintPtr        f = NULL;
9912   RnaQualPtr                q;
9913 
9914   dlg = (RNAFieldConstraintDlgPtr) GetObjectExtra (d);
9915   if (dlg == NULL) {
9916     return NULL;
9917   }
9918 
9919   q = DialogToPointer (dlg->RNA_field);
9920   if (q != NULL) {
9921     f = FieldConstraintNew ();
9922     f->field = ValNodeNew (NULL);
9923     f->field->choice = FieldType_rna_field;
9924     f->field->data.ptrvalue = q;
9925     f->string_constraint = DialogToPointer (dlg->string_constraint);
9926     ValNodeAddPointer (&constraint, ConstraintChoice_field, f);
9927   }
9928   return (Pointer) constraint;
9929 }
9930 
9931 
DataToRNAFieldConstraintDlg(DialoG d,Pointer data)9932 static void DataToRNAFieldConstraintDlg (DialoG d, Pointer data)
9933 {
9934   RNAFieldConstraintDlgPtr dlg;
9935   FieldConstraintPtr       f;
9936   RnaQualPtr               rq;
9937 
9938   dlg = (RNAFieldConstraintDlgPtr) GetObjectExtra (d);
9939   if (dlg == NULL) {
9940     return;
9941   }
9942   f = (FieldConstraintPtr) data;
9943   if (f == NULL) {
9944     PointerToDialog (dlg->RNA_field, NULL);
9945     PointerToDialog (dlg->string_constraint, NULL);
9946   } else {
9947     PointerToDialog (dlg->string_constraint, f->string_constraint);
9948     if (f->field == NULL) {
9949       PointerToDialog (dlg->RNA_field, NULL);
9950     } else if (f->field->choice == FieldType_rna_field) {
9951       PointerToDialog (dlg->RNA_field, f->field->data.ptrvalue);
9952     } else if (f->field->choice == FieldType_feature_field) {
9953       rq = RnaQualFromFeatureField (f->field->data.ptrvalue);
9954       PointerToDialog (dlg->RNA_field, rq);
9955       rq = RnaQualFree (rq);
9956     }
9957   }
9958 }
9959 
9960 
TestRNAFieldConstraintDlg(DialoG d)9961 static ValNodePtr TestRNAFieldConstraintDlg (DialoG d)
9962 {
9963   RNAFieldConstraintDlgPtr dlg;
9964   ValNodePtr               err_list = NULL;
9965 
9966   dlg = (RNAFieldConstraintDlgPtr) GetObjectExtra (d);
9967   if (dlg == NULL) {
9968     return NULL;
9969   }
9970   return err_list;
9971 }
9972 
9973 static DialoG RnaQualDialog (GrouP h, CharPtr type_label, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata);
9974 
RNAFieldConstraintDialog(GrouP h,CharPtr type_label,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)9975 static DialoG RNAFieldConstraintDialog (GrouP h, CharPtr type_label, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
9976 {
9977   GrouP p;
9978   RNAFieldConstraintDlgPtr dlg;
9979 
9980   dlg = (RNAFieldConstraintDlgPtr) MemNew (sizeof (RNAFieldConstraintDlgData));
9981 
9982   if (type_label == NULL) {
9983     p = NormalGroup (h, 2, 0, "RNA Field Constraint", programFont, NULL);
9984   } else {
9985     p = NormalGroup (h, -1, 0, "RNA Field Constraint", programFont, NULL);
9986   }
9987   SetObjectExtra (p, dlg, StdCleanupExtraProc);
9988   SetGroupSpacing (p, 10, 10);
9989 
9990   dlg->dialog = (DialoG) p;
9991   dlg->todialog = DataToRNAFieldConstraintDlg;
9992   dlg->fromdialog = RNAFieldConstraintDlgToData;
9993   dlg->testdialog = TestRNAFieldConstraintDlg;
9994   dlg->change_notify = change_notify;
9995   dlg->change_userdata = change_userdata;
9996 
9997   dlg->RNA_field = RnaQualDialog (p, type_label, dlg->change_notify, dlg->change_userdata);
9998   dlg->string_constraint = StringConstraintDialog (p, NULL, TRUE, dlg->change_notify, dlg->change_userdata);
9999   if (type_label != NULL) {
10000     AlignObjects (ALIGN_CENTER, (HANDLE) dlg->RNA_field, (HANDLE) dlg->string_constraint, NULL);
10001   }
10002 
10003   return (DialoG) p;
10004 }
10005 
10006 
10007 typedef struct featurefieldconstraintdlg {
10008   DIALOG_MESSAGE_BLOCK
10009 
10010   DialoG feature_type;
10011   DialoG feature_field;
10012   DialoG string_constraint;
10013 
10014   Nlm_ChangeNotifyProc change_notify;
10015   Pointer              change_userdata;
10016 } FeatureFieldConstraintDlgData, PNTR FeatureFieldConstraintDlgPtr;
10017 
10018 
ClearFeatureFieldConstraintDialogText(DialoG d)10019 static void ClearFeatureFieldConstraintDialogText (DialoG d)
10020 {
10021   FeatureFieldConstraintDlgPtr  dlg;
10022 
10023   dlg = (FeatureFieldConstraintDlgPtr) GetObjectExtra (d);
10024   if (dlg == NULL) {
10025     return;
10026   }
10027 
10028   ClearStringConstraintDialogText (dlg->string_constraint);
10029 }
10030 
10031 
FeatureFieldConstraintDlgToData(DialoG d)10032 static Pointer FeatureFieldConstraintDlgToData (DialoG d)
10033 {
10034   FeatureFieldConstraintDlgPtr  dlg;
10035   ValNodePtr                constraint = NULL, vnp, field = NULL;
10036   FieldConstraintPtr        f = NULL;
10037   FeatureFieldPtr           ff;
10038 
10039   dlg = (FeatureFieldConstraintDlgPtr) GetObjectExtra (d);
10040   if (dlg == NULL) {
10041     return NULL;
10042   }
10043 
10044   vnp = DialogToPointer (dlg->feature_type);
10045   if (vnp != NULL) {
10046     ff = FeatureFieldNew();
10047     ff->type = vnp->choice;
10048     ff->field = DialogToPointer (dlg->feature_field);
10049     field = ValNodeNew (NULL);
10050     field->choice = FieldType_feature_field;
10051     field->data.ptrvalue = ff;
10052     vnp = ValNodeFreeData (vnp);
10053   }
10054 
10055   if (field != NULL) {
10056     f = FieldConstraintNew ();
10057     f->field = field;
10058     f->string_constraint = DialogToPointer (dlg->string_constraint);
10059     ValNodeAddPointer (&constraint, ConstraintChoice_field, f);
10060   }
10061   return (Pointer) constraint;
10062 }
10063 
10064 
DataToFeatureFieldConstraintDlg(DialoG d,Pointer data)10065 static void DataToFeatureFieldConstraintDlg (DialoG d, Pointer data)
10066 {
10067   FeatureFieldConstraintDlgPtr dlg;
10068   FieldConstraintPtr           f;
10069   FeatureFieldPtr              ff;
10070   ValNode                      vn;
10071 
10072   dlg = (FeatureFieldConstraintDlgPtr) GetObjectExtra (d);
10073   if (dlg == NULL) {
10074     return;
10075   }
10076   f = (FieldConstraintPtr) data;
10077   if (f == NULL) {
10078     PointerToDialog (dlg->feature_type, NULL);
10079     PointerToDialog (dlg->feature_field, NULL);
10080     PointerToDialog (dlg->string_constraint, NULL);
10081   } else {
10082     PointerToDialog (dlg->string_constraint, f->string_constraint);
10083 
10084     if (f->field == NULL || f->field->choice != FieldType_feature_field) {
10085       PointerToDialog (dlg->feature_type, NULL);
10086       PointerToDialog (dlg->feature_field, NULL);
10087     } else {
10088       ff = (FeatureFieldPtr) f->field->data.ptrvalue;
10089       if (ff == NULL) {
10090         PointerToDialog (dlg->feature_type, NULL);
10091         PointerToDialog (dlg->feature_field, NULL);
10092       } else {
10093         vn.choice = (Uint1)ff->type;
10094         vn.data.ptrvalue = NULL;
10095         vn.next = NULL;
10096         PointerToDialog (dlg->feature_type, &vn);
10097         PointerToDialog (dlg->feature_field, ff->field);
10098       }
10099     }
10100   }
10101 }
10102 
10103 
TestFeatureFieldConstraintDlg(DialoG d)10104 static ValNodePtr TestFeatureFieldConstraintDlg (DialoG d)
10105 {
10106   FeatureFieldConstraintDlgPtr dlg;
10107   ValNodePtr               err_list = NULL;
10108   StringConstraintPtr      string_constraint;
10109 
10110   dlg = (FeatureFieldConstraintDlgPtr) GetObjectExtra (d);
10111   if (dlg == NULL) {
10112     return NULL;
10113   }
10114 
10115   string_constraint = DialogToPointer (dlg->string_constraint);
10116   if (!IsStringConstraintEmpty (string_constraint)) {
10117     err_list = TestDialog (dlg->feature_type);
10118     ValNodeLink (&err_list, TestDialog (dlg->feature_field));
10119   }
10120   string_constraint = StringConstraintFree (string_constraint);
10121   return err_list;
10122 }
10123 
10124 
10125 static DialoG FeatQualChoiceDialog (GrouP h, Boolean allow_illegal, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata);
10126 
ClearFeatureFieldConstraint(ButtoN b)10127 static void ClearFeatureFieldConstraint (ButtoN b)
10128 {
10129   FeatureFieldConstraintDlgPtr dlg;
10130 
10131   dlg = (FeatureFieldConstraintDlgPtr) GetObjectExtra (b);
10132   if (dlg == NULL) {
10133     return;
10134   }
10135 
10136   PointerToDialog (dlg->feature_type, NULL);
10137   PointerToDialog (dlg->feature_field, NULL);
10138   PointerToDialog (dlg->string_constraint, NULL);
10139 }
10140 
10141 
FeatureFieldConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)10142 static DialoG FeatureFieldConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
10143 {
10144   GrouP p, g;
10145   FeatureFieldConstraintDlgPtr dlg;
10146   ButtoN b;
10147 
10148   dlg = (FeatureFieldConstraintDlgPtr) MemNew (sizeof (FeatureFieldConstraintDlgData));
10149 
10150   p = NormalGroup (h, 3, 0, "Feature Field Constraint", programFont, NULL);
10151   SetObjectExtra (p, dlg, StdCleanupExtraProc);
10152   SetGroupSpacing (p, 10, 10);
10153 
10154   dlg->dialog = (DialoG) p;
10155   dlg->todialog = DataToFeatureFieldConstraintDlg;
10156   dlg->fromdialog = FeatureFieldConstraintDlgToData;
10157   dlg->testdialog = TestFeatureFieldConstraintDlg;
10158   dlg->change_notify = change_notify;
10159   dlg->change_userdata = change_userdata;
10160 
10161   dlg->feature_type = FeatureTypeDialog (p, change_notify, change_userdata);
10162   dlg->feature_field = FeatQualChoiceDialog (p, FALSE, change_notify, change_userdata);
10163 
10164   g = HiddenGroup (p, -1, 0, NULL);
10165   dlg->string_constraint = StringConstraintDialog (g, NULL, FALSE, dlg->change_notify, dlg->change_userdata);
10166   b = PushButton (g, "Clear Constraint", ClearFeatureFieldConstraint);
10167   SetObjectExtra (b, dlg, NULL);
10168   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->string_constraint, (HANDLE) b, NULL);
10169 
10170   return (DialoG) p;
10171 }
10172 
10173 typedef struct miscfieldconstraintdlg {
10174   DIALOG_MESSAGE_BLOCK
10175 
10176   DialoG field;
10177   DialoG string_constraint;
10178 
10179   Nlm_ChangeNotifyProc change_notify;
10180   Pointer              change_userdata;
10181 } MiscFieldConstraintDlgData, PNTR MiscFieldConstraintDlgPtr;
10182 
10183 
MiscFieldConstraintDlgToData(DialoG d)10184 static Pointer MiscFieldConstraintDlgToData (DialoG d)
10185 {
10186   MiscFieldConstraintDlgPtr  dlg;
10187   ValNodePtr                constraint = NULL, field = NULL;
10188   FieldConstraintPtr        f = NULL;
10189 
10190   dlg = (MiscFieldConstraintDlgPtr) GetObjectExtra (d);
10191   if (dlg == NULL) {
10192     return NULL;
10193   }
10194 
10195   field = DialogToPointer (dlg->field);
10196 
10197   if (field != NULL) {
10198     f = FieldConstraintNew ();
10199     f->field = field;
10200     f->string_constraint = DialogToPointer (dlg->string_constraint);
10201     ValNodeAddPointer (&constraint, ConstraintChoice_field, f);
10202   }
10203   return (Pointer) constraint;
10204 }
10205 
10206 
DataToMiscFieldConstraintDlg(DialoG d,Pointer data)10207 static void DataToMiscFieldConstraintDlg (DialoG d, Pointer data)
10208 {
10209   MiscFieldConstraintDlgPtr dlg;
10210   FieldConstraintPtr        f;
10211 
10212   dlg = (MiscFieldConstraintDlgPtr) GetObjectExtra (d);
10213   if (dlg == NULL) {
10214     return;
10215   }
10216   f = (FieldConstraintPtr) data;
10217   if (f == NULL) {
10218     PointerToDialog (dlg->field, NULL);
10219     PointerToDialog (dlg->string_constraint, NULL);
10220   } else {
10221     PointerToDialog (dlg->string_constraint, f->string_constraint);
10222 
10223     if (f->field == NULL) {
10224       PointerToDialog (dlg->field, NULL);
10225     } else {
10226       PointerToDialog (dlg->field, f->field);
10227     }
10228   }
10229 }
10230 
10231 
TestMiscFieldConstraintDlg(DialoG d)10232 static ValNodePtr TestMiscFieldConstraintDlg (DialoG d)
10233 {
10234   MiscFieldConstraintDlgPtr dlg;
10235   ValNodePtr                err_list = NULL;
10236 
10237   dlg = (MiscFieldConstraintDlgPtr) GetObjectExtra (d);
10238   if (dlg == NULL) {
10239     return NULL;
10240   }
10241 
10242   err_list = TestDialog (dlg->field);
10243   return err_list;
10244 }
10245 
10246 
ClearMiscFieldConstraint(ButtoN b)10247 static void ClearMiscFieldConstraint (ButtoN b)
10248 {
10249   MiscFieldConstraintDlgPtr dlg;
10250 
10251   dlg = (MiscFieldConstraintDlgPtr) GetObjectExtra (b);
10252   if (dlg == NULL) {
10253     return;
10254   }
10255 
10256   PointerToDialog (dlg->field, NULL);
10257   PointerToDialog (dlg->string_constraint, NULL);
10258 }
10259 
10260 
10261 static DialoG MiscFieldDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata);
10262 
10263 
MiscFieldConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)10264 static DialoG MiscFieldConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
10265 {
10266   GrouP p;
10267   MiscFieldConstraintDlgPtr dlg;
10268   ButtoN b;
10269 
10270   dlg = (MiscFieldConstraintDlgPtr) MemNew (sizeof (MiscFieldConstraintDlgData));
10271 
10272   p = NormalGroup (h, -1, 0, "Misc Field Constraint", programFont, NULL);
10273   SetObjectExtra (p, dlg, StdCleanupExtraProc);
10274   SetGroupSpacing (p, 10, 10);
10275 
10276   dlg->dialog = (DialoG) p;
10277   dlg->todialog = DataToMiscFieldConstraintDlg;
10278   dlg->fromdialog = MiscFieldConstraintDlgToData;
10279   dlg->testdialog = TestMiscFieldConstraintDlg;
10280   dlg->change_notify = change_notify;
10281   dlg->change_userdata = change_userdata;
10282 
10283   dlg->field = MiscFieldDialog (p, change_notify, change_userdata);
10284   dlg->string_constraint = StringConstraintDialog (p, NULL, FALSE, dlg->change_notify, dlg->change_userdata);
10285   b = PushButton (p, "Clear Constraint", ClearMiscFieldConstraint);
10286   SetObjectExtra (b, dlg, NULL);
10287   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->field, (HANDLE) dlg->string_constraint, (HANDLE) b, NULL);
10288 
10289   return (DialoG) p;
10290 }
10291 
10292 
10293 static DialoG DBLinkFieldDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata);
10294 
DBLinkFieldConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)10295 static DialoG DBLinkFieldConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
10296 {
10297   GrouP p;
10298   MiscFieldConstraintDlgPtr dlg;
10299   ButtoN b;
10300 
10301   dlg = (MiscFieldConstraintDlgPtr) MemNew (sizeof (MiscFieldConstraintDlgData));
10302 
10303   p = NormalGroup (h, -1, 0, "DBLink Field Constraint", programFont, NULL);
10304   SetObjectExtra (p, dlg, StdCleanupExtraProc);
10305   SetGroupSpacing (p, 10, 10);
10306 
10307   dlg->dialog = (DialoG) p;
10308   dlg->todialog = DataToMiscFieldConstraintDlg;
10309   dlg->fromdialog = MiscFieldConstraintDlgToData;
10310   dlg->testdialog = TestMiscFieldConstraintDlg;
10311   dlg->change_notify = change_notify;
10312   dlg->change_userdata = change_userdata;
10313 
10314   dlg->field = DBLinkFieldDialog (p, change_notify, change_userdata);
10315   dlg->string_constraint = StringConstraintDialog (p, NULL, FALSE, dlg->change_notify, dlg->change_userdata);
10316   b = PushButton (p, "Clear Constraint", ClearMiscFieldConstraint);
10317   SetObjectExtra (b, dlg, NULL);
10318   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->field, (HANDLE) dlg->string_constraint, (HANDLE) b, NULL);
10319 
10320   return (DialoG) p;
10321 }
10322 
10323 
ComplexConstraintTypeFromFeatureFieldType(Uint2 qualtype)10324 static EComplexConstraintType ComplexConstraintTypeFromFeatureFieldType (Uint2 qualtype)
10325 {
10326   EComplexConstraintType rval = eComplexConstraintType_string;
10327 
10328   switch (qualtype) {
10329     case FieldType_source_qual:
10330       rval = eComplexConstraintType_source;
10331       break;
10332     case FieldType_cds_gene_prot:
10333       rval = eComplexConstraintType_cdsgeneprot;
10334       break;
10335     case FieldType_pub:
10336       rval = eComplexConstraintType_pub;
10337       break;
10338     case FieldType_feature_field:
10339       rval = eComplexConstraintType_feature_field;
10340       break;
10341     case FieldType_rna_field:
10342       rval = eComplexConstraintType_rna_field;
10343       break;
10344     case FieldType_molinfo_field:
10345       rval = eComplexConstraintType_molinfo_field;
10346       break;
10347     case FieldType_struc_comment_field:
10348       rval = eComplexConstraintType_seqid;
10349       break;
10350   }
10351   return rval;
10352 }
10353 
10354 
FeatureFieldTypeFromComplexConstraintType(EComplexConstraintType constraint_type)10355 static Uint2 FeatureFieldTypeFromComplexConstraintType (EComplexConstraintType constraint_type)
10356 {
10357   Uint2 rval = 0;
10358 
10359   switch (constraint_type) {
10360     case eComplexConstraintType_source:
10361       rval = FieldType_source_qual;
10362       break;
10363     case eComplexConstraintType_cdsgeneprot:
10364       rval = FieldType_cds_gene_prot;
10365       break;
10366     case eComplexConstraintType_pub:
10367       rval = FieldType_pub;
10368       break;
10369     case eComplexConstraintType_feature_field:
10370       rval = FieldType_feature_field;
10371       break;
10372     case eComplexConstraintType_rna_field:
10373       rval = FieldType_rna_field;
10374       break;
10375     case eComplexConstraintType_molinfo_field:
10376       rval = FieldType_molinfo_field;
10377       break;
10378     default:
10379       break;
10380   }
10381   return rval;
10382 }
10383 
10384 
10385 typedef struct complexconstraintdlg {
10386   DIALOG_MESSAGE_BLOCK
10387 
10388   GrouP  constraint_choice;
10389   GrouP  old_constraint_grp;
10390   DialoG cgp_constraint;
10391   DialoG src_constraint;
10392   DialoG rna_constraint;
10393   DialoG pub_constraint;
10394   DialoG feat_field_constraint;
10395   DialoG seq_constraint;
10396   DialoG string_constraint;
10397   DialoG loc_constraint;
10398   DialoG constraint_set_dlg;
10399 
10400   ValNodePtr rna_type;
10401   Int2       feat_type;
10402 
10403   EComplexConstraintType constraint_type;
10404   Nlm_ChangeNotifyProc change_notify;
10405   Pointer              change_userdata;
10406 } ComplexConstraintDlgData, PNTR ComplexConstraintDlgPtr;
10407 
10408 
ShowSimpleConstraint(ComplexConstraintDlgPtr dlg)10409 static void ShowSimpleConstraint (ComplexConstraintDlgPtr dlg)
10410 {
10411   if (dlg == NULL) {
10412     return;
10413   }
10414 
10415   Hide (dlg->src_constraint);
10416   Hide (dlg->cgp_constraint);
10417   Hide (dlg->pub_constraint);
10418   Hide (dlg->feat_field_constraint);
10419   Hide (dlg->rna_constraint);
10420   Hide (dlg->seq_constraint);
10421   Hide (dlg->string_constraint);
10422   Hide (dlg->loc_constraint);
10423 
10424   switch (dlg->constraint_type) {
10425     case eComplexConstraintType_source:
10426       Show (dlg->src_constraint);
10427       break;
10428     case eComplexConstraintType_cdsgeneprot:
10429       Show (dlg->cgp_constraint);
10430       break;
10431     case eComplexConstraintType_pub:
10432       Show (dlg->pub_constraint);
10433       break;
10434     case eComplexConstraintType_feature_field:
10435       Show (dlg->feat_field_constraint);
10436       break;
10437     case eComplexConstraintType_rna_field:
10438       Show (dlg->rna_constraint);
10439       break;
10440     case eComplexConstraintType_molinfo_field:
10441       Show (dlg->seq_constraint);
10442       break;
10443     case eComplexConstraintType_seqid:
10444       Show (dlg->seq_constraint);
10445       break;
10446     case eComplexConstraintType_string:
10447       Show (dlg->string_constraint);
10448       break;
10449     case eComplexConstraintType_loc:
10450       Show (dlg->loc_constraint);
10451       break;
10452     default:
10453       break;
10454   }
10455 }
10456 
10457 
DefaultRNAFieldConstraint(ValNodePtr rna_type)10458 static ValNodePtr DefaultRNAFieldConstraint (ValNodePtr rna_type)
10459 {
10460   ValNodePtr vnp;
10461   FieldConstraintPtr      fcp;
10462   RnaQualPtr rq;
10463 
10464   rq = RnaQualNew ();
10465   rq->field = Rna_field_product;
10466   if (rna_type == NULL) {
10467     rq->type = ValNodeNew (NULL);
10468     rq->type->choice = RnaFeatType_any;
10469   } else {
10470     rq->type = AsnIoMemCopy (rna_type, (AsnReadFunc) RnaFeatTypeAsnRead, (AsnWriteFunc) RnaFeatTypeAsnWrite);
10471   }
10472   fcp = FieldConstraintNew ();
10473   fcp->field = ValNodeNew (NULL);
10474   fcp->field->choice = FieldType_rna_field;
10475   fcp->field->data.ptrvalue = rq;
10476   fcp->string_constraint = StringConstraintNew ();
10477   fcp->string_constraint->match_text = StringSave ("");
10478   vnp = ValNodeNew (NULL);
10479   vnp->choice = ConstraintChoice_field;
10480   vnp->data.ptrvalue = fcp;
10481   return vnp;
10482 }
10483 
10484 
DefaultFeatureFieldConstraint(Int2 feat_type)10485 static ValNodePtr DefaultFeatureFieldConstraint (Int2 feat_type)
10486 {
10487   ValNodePtr         vnp;
10488   FieldConstraintPtr fcp;
10489   FeatureFieldPtr    ff;
10490 
10491   ff = FeatureFieldNew ();
10492   ff->type = feat_type;
10493   fcp = FieldConstraintNew ();
10494   fcp->field = ValNodeNew (NULL);
10495   fcp->field->choice = FieldType_feature_field;
10496   fcp->field->data.ptrvalue = ff;
10497   fcp->string_constraint = StringConstraintNew ();
10498   fcp->string_constraint->match_text = StringSave ("");
10499   vnp = ValNodeNew (NULL);
10500   vnp->choice = ConstraintChoice_field;
10501   vnp->data.ptrvalue = fcp;
10502   return vnp;
10503 }
10504 
10505 
SetConstraintSetDefaultConstraintTypeFromFieldType(DialoG d,Uint2 qual_type,ValNodePtr rna_type,Int2 feat_type,DialoG related_constraint_dlg)10506 static void SetConstraintSetDefaultConstraintTypeFromFieldType (DialoG d, Uint2 qual_type, ValNodePtr rna_type, Int2 feat_type, DialoG related_constraint_dlg)
10507 {
10508   ValNodePtr              default_constraint;
10509 
10510   switch (qual_type) {
10511     case FieldType_source_qual:
10512       SetConstraintSetDefaultConstraintType (d, ConstraintChoice_source);
10513       break;
10514     case FieldType_cds_gene_prot:
10515       SetConstraintSetDefaultConstraintType (d, ConstraintChoice_cdsgeneprot_qual);
10516       break;
10517     case FieldType_pub:
10518       SetConstraintSetDefaultConstraintType (d, ConstraintChoice_pub);
10519       break;
10520     case FieldType_molinfo_field:
10521       SetConstraintSetDefaultConstraintType (d, ConstraintChoice_sequence);
10522       break;
10523     case FieldType_feature_field:
10524       default_constraint = DefaultFeatureFieldConstraint (feat_type);
10525       SetConstraintSetDefaultConstraintTypeEx (d, default_constraint);
10526       PointerToDialog (related_constraint_dlg, default_constraint->data.ptrvalue);
10527       default_constraint = ConstraintChoiceFree (default_constraint);
10528       break;
10529     case FieldType_rna_field:
10530       default_constraint = DefaultRNAFieldConstraint (rna_type);
10531       SetConstraintSetDefaultConstraintTypeEx (d, default_constraint);
10532       default_constraint = ConstraintChoiceFree (default_constraint);
10533       break;
10534     case FieldType_struc_comment_field:
10535       SetConstraintSetDefaultConstraintType (d, ConstraintChoice_sequence);
10536       break;
10537   }
10538 }
10539 
10540 
ChangeComplexConstraintFieldType(DialoG d,Uint2 qual_type,ValNodePtr rna_type,Int2 feat_type)10541 NLM_EXTERN void ChangeComplexConstraintFieldType (DialoG d, Uint2 qual_type, ValNodePtr rna_type, Int2 feat_type)
10542 {
10543   ComplexConstraintDlgPtr dlg;
10544 
10545   dlg = (ComplexConstraintDlgPtr) GetObjectExtra (d);
10546   if (dlg == NULL) return;
10547   dlg->constraint_type = ComplexConstraintTypeFromFeatureFieldType (qual_type);
10548   dlg->feat_type = feat_type;
10549   dlg->rna_type = RnaFeatTypeFree (dlg->rna_type);
10550   dlg->rna_type = AsnIoMemCopy (rna_type, (AsnReadFunc) RnaFeatTypeAsnRead, (AsnWriteFunc) RnaFeatTypeAsnWrite);
10551 
10552   /* set default constraint type for advanced constraints */
10553   SetConstraintSetDefaultConstraintTypeFromFieldType (dlg->constraint_set_dlg, qual_type, dlg->rna_type, dlg->feat_type, dlg->feat_field_constraint);
10554 
10555   /* change which constraint dialog is visible, if using "simple" constraints */
10556   if (GetValue (dlg->constraint_choice) == 1) {
10557     ShowSimpleConstraint (dlg);
10558   }
10559 }
10560 
10561 
SetComplexConstraintType(DialoG d,EComplexConstraintType constraint_type)10562 NLM_EXTERN void SetComplexConstraintType (DialoG d, EComplexConstraintType constraint_type)
10563 {
10564   Uint2 ftype;
10565   ComplexConstraintDlgPtr dlg;
10566 
10567   ftype = FeatureFieldTypeFromComplexConstraintType (constraint_type);
10568   if (ftype != 0) {
10569     ChangeComplexConstraintFieldType (d, ftype, NULL, Macro_feature_type_any);
10570   } else {
10571     dlg = (ComplexConstraintDlgPtr) GetObjectExtra (d);
10572     if (dlg != NULL) {
10573       dlg->constraint_type = constraint_type;
10574       /* change which constraint dialog is visible, if using "simple" constraints */
10575       if (GetValue (dlg->constraint_choice) == 1) {
10576         ShowSimpleConstraint (dlg);
10577       }
10578     }
10579   }
10580 }
10581 
10582 
ChangeComplexConstraintChoice(GrouP g)10583 static void ChangeComplexConstraintChoice (GrouP g)
10584 {
10585   ComplexConstraintDlgPtr dlg;
10586 
10587   dlg = (ComplexConstraintDlgPtr) GetObjectExtra (g);
10588   if (dlg == NULL) return;
10589   if (GetValue (dlg->constraint_choice) == 1) {
10590     Hide (dlg->constraint_set_dlg);
10591     Show (dlg->old_constraint_grp);
10592     ShowSimpleConstraint (dlg);
10593   } else {
10594     Hide (dlg->old_constraint_grp);
10595     Show (dlg->constraint_set_dlg);
10596   }
10597   if (dlg->change_notify != NULL) {
10598     (dlg->change_notify) (dlg->change_userdata);
10599   }
10600 }
10601 
10602 
DataToComplexConstraintDlg(DialoG d,Pointer data)10603 static void DataToComplexConstraintDlg (DialoG d, Pointer data)
10604 {
10605   ComplexConstraintDlgPtr dlg;
10606   ValNodePtr              constraint = NULL;
10607   FieldConstraintPtr      fcp;
10608 
10609   dlg = (ComplexConstraintDlgPtr) GetObjectExtra (d);
10610   if (dlg == NULL) return;
10611 
10612   constraint = (ValNodePtr) data;
10613 
10614   if (GetValue (dlg->constraint_choice) == 2
10615       || (constraint != NULL && constraint->next != NULL)) {
10616     PointerToDialog (dlg->constraint_set_dlg, constraint);
10617     SetValue (dlg->constraint_choice, 2);
10618   } else if (constraint == NULL) {
10619     switch (dlg->constraint_type) {
10620       case eComplexConstraintType_source:
10621         PointerToDialog (dlg->src_constraint, NULL);
10622         break;
10623       case eComplexConstraintType_cdsgeneprot:
10624         PointerToDialog (dlg->cgp_constraint, NULL);
10625         break;
10626       case eComplexConstraintType_pub:
10627         PointerToDialog (dlg->pub_constraint, NULL);
10628         break;
10629       case eComplexConstraintType_feature_field:
10630         PointerToDialog (dlg->feat_field_constraint, NULL);
10631         break;
10632       case eComplexConstraintType_rna_field:
10633         PointerToDialog (dlg->rna_constraint, NULL);
10634         break;
10635       case eComplexConstraintType_molinfo_field:
10636         PointerToDialog (dlg->seq_constraint, NULL);
10637         break;
10638       case eComplexConstraintType_seqid:
10639         PointerToDialog (dlg->seq_constraint, NULL);
10640         break;
10641       case eComplexConstraintType_string:
10642         PointerToDialog (dlg->string_constraint, NULL);
10643         break;
10644       case eComplexConstraintType_loc:
10645         PointerToDialog (dlg->loc_constraint, NULL);
10646         break;
10647     }
10648   } else {
10649     switch (constraint->choice) {
10650       case ConstraintChoice_field:
10651         fcp = constraint->data.ptrvalue;
10652         if (fcp->field == NULL || fcp->field->choice != FeatureFieldTypeFromComplexConstraintType(dlg->constraint_type)) {
10653           SetValue (dlg->constraint_choice, 2);
10654           PointerToDialog (dlg->constraint_set_dlg, constraint);
10655         } else if (dlg->constraint_type == eComplexConstraintType_feature_field) {
10656           PointerToDialog (dlg->feat_field_constraint, constraint);
10657         } else if (dlg->constraint_type == eComplexConstraintType_rna_field) {
10658           PointerToDialog (dlg->rna_constraint, constraint);
10659         }
10660         break;
10661       case ConstraintChoice_source:
10662         if (dlg->constraint_type == eComplexConstraintType_source) {
10663           PointerToDialog (dlg->src_constraint, constraint);
10664         } else {
10665           SetValue (dlg->constraint_choice, 2);
10666           PointerToDialog (dlg->constraint_set_dlg, constraint);
10667         }
10668         break;
10669       case ConstraintChoice_cdsgeneprot_qual:
10670       case ConstraintChoice_cdsgeneprot_pseudo:
10671         if (dlg->constraint_type == eComplexConstraintType_cdsgeneprot) {
10672           PointerToDialog (dlg->cgp_constraint, constraint);
10673         } else {
10674           SetValue (dlg->constraint_choice, 2);
10675           PointerToDialog (dlg->constraint_set_dlg, constraint);
10676         }
10677         break;
10678       case ConstraintChoice_sequence:
10679         SetValue (dlg->constraint_choice, 2);
10680         PointerToDialog (dlg->constraint_set_dlg, constraint);
10681         break;
10682       case ConstraintChoice_pub:
10683         if (dlg->constraint_type == eComplexConstraintType_pub) {
10684           PointerToDialog (dlg->pub_constraint, constraint->data.ptrvalue);
10685         } else {
10686           SetValue (dlg->constraint_choice, 2);
10687           PointerToDialog (dlg->constraint_set_dlg, constraint);
10688         }
10689         break;
10690       case eComplexConstraintType_loc:
10691         if (dlg->constraint_type == eComplexConstraintType_loc) {
10692           PointerToDialog (dlg->loc_constraint, constraint->data.ptrvalue);
10693         } else {
10694           SetValue (dlg->constraint_choice, 2);
10695           PointerToDialog (dlg->constraint_set_dlg, constraint);
10696         }
10697         break;
10698     }
10699   }
10700 
10701   ChangeComplexConstraintChoice(dlg->constraint_choice);
10702 }
10703 
10704 
DataFromComplexConstraintDlg(DialoG d)10705 static Pointer DataFromComplexConstraintDlg (DialoG d)
10706 {
10707   ComplexConstraintDlgPtr  dlg;
10708   ValNodePtr               constraint = NULL;
10709   FieldConstraintPtr       fc;
10710   RnaQualPtr               rq;
10711   PublicationConstraintPtr pub;
10712   StringConstraintPtr      scp;
10713   LocationConstraintPtr    lcp;
10714 
10715   dlg = (ComplexConstraintDlgPtr) GetObjectExtra (d);
10716   if (dlg == NULL) return NULL;
10717 
10718   if (GetValue (dlg->constraint_choice) == 2) {
10719     constraint = DialogToPointer (dlg->constraint_set_dlg);
10720   } else {
10721     switch (dlg->constraint_type) {
10722       case eComplexConstraintType_source:
10723         constraint = DialogToPointer (dlg->src_constraint);
10724         break;
10725       case eComplexConstraintType_cdsgeneprot:
10726         constraint = DialogToPointer (dlg->cgp_constraint);
10727         break;
10728       case eComplexConstraintType_pub:
10729         pub = DialogToPointer (dlg->pub_constraint);
10730         if (!IsPublicationConstraintEmpty (pub)) {
10731           ValNodeAddPointer (&constraint, ConstraintChoice_pub, pub);
10732         } else {
10733           pub = PublicationConstraintFree (pub);
10734         }
10735         break;
10736       case eComplexConstraintType_feature_field:
10737         constraint = DialogToPointer (dlg->feat_field_constraint);
10738         break;
10739       case eComplexConstraintType_rna_field:
10740         constraint = DialogToPointer (dlg->rna_constraint);
10741         if (constraint != NULL) {
10742           fc = (FieldConstraintPtr) constraint->data.ptrvalue;
10743           if (fc == NULL || fc->field == NULL) {
10744             constraint = ConstraintChoiceFree (constraint);
10745           } else if (fc->field->choice == FieldType_rna_field) {
10746             rq = (RnaQualPtr) fc->field->data.ptrvalue;
10747             if (rq != NULL) {
10748               rq->type = AsnIoMemCopy (dlg->rna_type, (AsnReadFunc) RnaFeatTypeAsnRead, (AsnWriteFunc) RnaFeatTypeAsnWrite);
10749             }
10750           }
10751         }
10752         break;
10753       case eComplexConstraintType_molinfo_field:
10754         constraint = DialogToPointer (dlg->seq_constraint);
10755         break;
10756       case eComplexConstraintType_seqid:
10757         constraint = DialogToPointer (dlg->seq_constraint);
10758         break;
10759       case eComplexConstraintType_string:
10760         scp = DialogToPointer (dlg->string_constraint);
10761         if (IsStringConstraintEmpty (scp)) {
10762           scp = StringConstraintFree(scp);
10763         } else {
10764           ValNodeAddPointer (&constraint, ConstraintChoice_string, scp);
10765         }
10766         break;
10767       case eComplexConstraintType_loc:
10768         lcp = DialogToPointer (dlg->loc_constraint);
10769         if (IsLocationConstraintEmpty (lcp)) {
10770           lcp = LocationConstraintFree (lcp);
10771         } else {
10772           ValNodeAddPointer (&constraint, ConstraintChoice_location, lcp);
10773         }
10774         break;
10775     }
10776   }
10777   return constraint;
10778 }
10779 
10780 
ClearComplexConstraintDialogText(DialoG d)10781 static void ClearComplexConstraintDialogText (DialoG d)
10782 {
10783   ComplexConstraintDlgPtr dlg;
10784 
10785   dlg = (ComplexConstraintDlgPtr) GetObjectExtra (d);
10786   if (dlg == NULL) return;
10787 
10788   ClearOldCDSGeneProtConstraintDialogText (dlg->cgp_constraint);
10789   ClearOldSrcConstraintDialogText (dlg->src_constraint);
10790   ClearRnaFieldConstraintDialogText (dlg->rna_constraint);
10791   ClearPublicationConstraintDialogText (dlg->pub_constraint);
10792   ClearFeatureFieldConstraintDialogText (dlg->feat_field_constraint);
10793   ClearSimpleSequenceConstraintDialogText (dlg->seq_constraint);
10794   ClearStringConstraintDialogText (dlg->string_constraint);
10795 }
10796 
10797 
TestComplexConstraintDlg(DialoG d)10798 static ValNodePtr TestComplexConstraintDlg (DialoG d)
10799 {
10800   ValNodePtr err_list = NULL;
10801   ComplexConstraintDlgPtr dlg;
10802   PublicationConstraintPtr pub;
10803 
10804   dlg = (ComplexConstraintDlgPtr) GetObjectExtra (d);
10805   if (dlg == NULL) return NULL;
10806 
10807   if (GetValue (dlg->constraint_choice) == 2) {
10808     err_list = TestDialog (dlg->constraint_set_dlg);
10809   } else {
10810     switch (dlg->constraint_type) {
10811       case eComplexConstraintType_source:
10812         err_list = TestDialog (dlg->src_constraint);
10813         break;
10814       case eComplexConstraintType_cdsgeneprot:
10815         err_list = TestDialog (dlg->cgp_constraint);
10816         break;
10817       case eComplexConstraintType_pub:
10818         pub = DialogToPointer (dlg->pub_constraint);
10819         if (!IsPublicationConstraintEmpty (pub)) {
10820           err_list = TestDialog (dlg->pub_constraint);
10821         }
10822         pub = PublicationConstraintFree (pub);
10823         break;
10824       case eComplexConstraintType_feature_field:
10825         err_list = TestDialog (dlg->feat_field_constraint);
10826         break;
10827       case eComplexConstraintType_rna_field:
10828         err_list = TestDialog (dlg->rna_constraint);
10829         break;
10830       case eComplexConstraintType_molinfo_field:
10831         err_list = TestDialog (dlg->seq_constraint);
10832         break;
10833       case eComplexConstraintType_seqid:
10834         err_list = TestDialog (dlg->seq_constraint);
10835         break;
10836       case eComplexConstraintType_string:
10837         err_list = TestDialog (dlg->string_constraint);
10838         break;
10839       case eComplexConstraintType_loc:
10840         err_list = TestDialog (dlg->loc_constraint);
10841         break;
10842     }
10843   }
10844   return err_list;
10845 }
10846 
10847 
CleanupComplexConstraintDialog(GraphiC g,VoidPtr data)10848 static void CleanupComplexConstraintDialog (GraphiC g, VoidPtr data)
10849 {
10850   ComplexConstraintDlgPtr dlg;
10851 
10852   dlg = (ComplexConstraintDlgPtr) data;
10853   if (dlg != NULL) {
10854     dlg->rna_type = RnaFeatTypeFree (dlg->rna_type);
10855   }
10856   StdCleanupExtraProc (g, data);
10857 }
10858 
10859 
ComplexConstraintDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)10860 NLM_EXTERN DialoG ComplexConstraintDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
10861 {
10862   GrouP p, constraint_grp;
10863   ComplexConstraintDlgPtr dlg;
10864 
10865   dlg = (ComplexConstraintDlgPtr) MemNew (sizeof (ComplexConstraintDlgData));
10866 
10867   p = NormalGroup (h, -1, 0, "Constraints", programFont, NULL);
10868   SetObjectExtra (p, dlg, CleanupComplexConstraintDialog);
10869   SetGroupSpacing (p, 10, 10);
10870 
10871   dlg->dialog = (DialoG) p;
10872   dlg->todialog = DataToComplexConstraintDlg;
10873   dlg->fromdialog = DataFromComplexConstraintDlg;
10874   dlg->testdialog = TestComplexConstraintDlg;
10875   dlg->change_notify = change_notify;
10876   dlg->change_userdata = change_userdata;
10877 
10878   constraint_grp = HiddenGroup (p, 0, 0, NULL);
10879   dlg->old_constraint_grp = HiddenGroup (constraint_grp, 0, 0, NULL);
10880   dlg->cgp_constraint = OldCDSGeneProtConstraintDialog (dlg->old_constraint_grp, dlg->change_notify, dlg->change_userdata);
10881   dlg->src_constraint = OldSrcConstraintDialog (dlg->old_constraint_grp, dlg->change_notify, dlg->change_userdata);
10882   dlg->pub_constraint = PublicationConstraintDialog (dlg->old_constraint_grp, dlg->change_notify, dlg->change_userdata);
10883   dlg->feat_field_constraint = FeatureFieldConstraintDialog (dlg->old_constraint_grp, dlg->change_notify, dlg->change_userdata);
10884   dlg->rna_constraint = RNAFieldConstraintDialog (dlg->old_constraint_grp, NULL, dlg->change_notify, dlg->change_userdata);
10885   dlg->seq_constraint = SimpleSequenceConstraintDialog (dlg->old_constraint_grp, dlg->change_notify, dlg->change_userdata);
10886   dlg->string_constraint = StringConstraintDialog (dlg->old_constraint_grp, "Where object text", TRUE, dlg->change_notify, dlg->change_userdata);
10887   dlg->loc_constraint = LocationConstraintDialog (dlg->old_constraint_grp, dlg->change_notify, dlg->change_userdata);
10888   AlignObjects (ALIGN_CENTER,
10889                 (HANDLE) dlg->cgp_constraint,
10890                 (HANDLE) dlg->src_constraint,
10891                 (HANDLE) dlg->pub_constraint,
10892                 (HANDLE) dlg->feat_field_constraint,
10893                 (HANDLE) dlg->rna_constraint,
10894                 (HANDLE) dlg->seq_constraint,
10895                 (HANDLE) dlg->string_constraint,
10896                 (HANDLE) dlg->loc_constraint,
10897                 NULL);
10898 
10899   dlg->constraint_set_dlg = ConstraintSetDialog (constraint_grp, dlg->change_notify, dlg->change_userdata);
10900   Hide (dlg->constraint_set_dlg);
10901   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->constraint_set_dlg, (HANDLE) dlg->old_constraint_grp, NULL);
10902   dlg->constraint_choice = HiddenGroup (p, 2, 0, ChangeComplexConstraintChoice);
10903   SetObjectExtra (dlg->constraint_choice, dlg, NULL);
10904   RadioButton (dlg->constraint_choice, "Simple");
10905   RadioButton (dlg->constraint_choice, "Advanced");
10906   SetValue (dlg->constraint_choice, 1);
10907   AlignObjects (ALIGN_CENTER, (HANDLE) constraint_grp, (HANDLE) dlg->constraint_choice, NULL);
10908   return (DialoG) p;
10909 }
10910 
10911 
LegalFeatQualChoiceDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)10912 static DialoG LegalFeatQualChoiceDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
10913 {
10914   ValNodePtr field_list = NULL;
10915 
10916   AddAllFeatureFieldsToChoiceList (&field_list);
10917   return ValNodeSelectionDialog (h, field_list, TALL_SELECTION_LIST, ValNodeStringName,
10918                                 ValNodeSimpleDataFree, ValNodeStringCopy,
10919                                 ValNodeChoiceMatch, "field type",
10920                                 change_notify, change_userdata, FALSE);
10921 }
10922 
10923 
10924 typedef struct featqualchoicedlg {
10925   DIALOG_MESSAGE_BLOCK
10926   DialoG legal_qual;
10927   DialoG illegal_qual;
10928   Boolean is_legal;
10929 } FeatQualChoiceDlgData, PNTR FeatQualChoiceDlgPtr;
10930 
10931 
FeatQualChoiceToDialog(DialoG d,Pointer data)10932 static void FeatQualChoiceToDialog (DialoG d, Pointer data)
10933 {
10934   FeatQualChoiceDlgPtr dlg;
10935   ValNodePtr vnp;
10936   ValNode vn;
10937 
10938   dlg = (FeatQualChoiceDlgPtr) GetObjectExtra (d);
10939   if (dlg == NULL) return;
10940 
10941   vnp = (ValNodePtr) data;
10942   if (vnp == NULL) {
10943     dlg->is_legal = TRUE;
10944     PointerToDialog (dlg->legal_qual, NULL);
10945     Show (dlg->legal_qual);
10946     SafeHide (dlg->illegal_qual);
10947   } else if (vnp->choice == FeatQualChoice_legal_qual) {
10948     dlg->is_legal = TRUE;
10949     vn.choice = vnp->data.intvalue;
10950     vn.data.ptrvalue = NULL;
10951     vn.next = NULL;
10952     PointerToDialog (dlg->legal_qual, &vn);
10953     Show (dlg->legal_qual);
10954     SafeHide (dlg->illegal_qual);
10955   } else if (vnp->choice == FeatQualChoice_illegal_qual) {
10956     dlg->is_legal = FALSE;
10957     PointerToDialog (dlg->illegal_qual, vnp->data.ptrvalue);
10958     Hide (dlg->legal_qual);
10959     SafeShow (dlg->illegal_qual);
10960   } else {
10961     dlg->is_legal = TRUE;
10962     PointerToDialog (dlg->legal_qual, NULL);
10963     Show (dlg->legal_qual);
10964     SafeHide (dlg->illegal_qual);
10965   }
10966 }
10967 
10968 
DialogToFeatQualChoice(DialoG d)10969 static Pointer DialogToFeatQualChoice (DialoG d)
10970 {
10971   FeatQualChoiceDlgPtr dlg;
10972   ValNodePtr vnp = NULL, vnp2;
10973   StringConstraintPtr scp;
10974 
10975   dlg = (FeatQualChoiceDlgPtr) GetObjectExtra (d);
10976   if (dlg == NULL) return NULL;
10977 
10978   if (dlg->is_legal) {
10979     vnp2 = (ValNodePtr) DialogToPointer (dlg->legal_qual);
10980     if (vnp2 != NULL) {
10981       vnp = ValNodeNew (NULL);
10982       vnp->choice = FeatQualChoice_legal_qual;
10983       vnp->data.intvalue = vnp2->choice;
10984       vnp2 = ValNodeFree (vnp2);
10985     }
10986   } else {
10987     scp = (StringConstraintPtr) DialogToPointer (dlg->illegal_qual);
10988     if (scp != NULL) {
10989       vnp = ValNodeNew (NULL);
10990       vnp->choice = FeatQualChoice_illegal_qual;
10991       vnp->data.ptrvalue = scp;
10992     }
10993   }
10994   return vnp;
10995 }
10996 
10997 
TestFeatQualChoiceDialog(DialoG d)10998 static ValNodePtr TestFeatQualChoiceDialog (DialoG d)
10999 {
11000   FeatQualChoiceDlgPtr dlg;
11001   ValNodePtr err_list = NULL;
11002   StringConstraintPtr scp;
11003 
11004   dlg = (FeatQualChoiceDlgPtr) GetObjectExtra (d);
11005   if (dlg == NULL) return NULL;
11006 
11007   if (dlg->is_legal) {
11008     err_list = TestDialog (dlg->legal_qual);
11009   } else {
11010     scp = DialogToPointer (dlg->illegal_qual);
11011     if (scp == NULL || StringHasNoText (scp->match_text)) {
11012       ValNodeAddPointer (&err_list, 0, "match text");
11013     }
11014   }
11015   return err_list;
11016 }
11017 
FeatQualChoiceDialog(GrouP h,Boolean allow_illegal,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)11018 static DialoG FeatQualChoiceDialog (GrouP h, Boolean allow_illegal, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
11019 {
11020   FeatQualChoiceDlgPtr dlg;
11021   GrouP                 p;
11022 
11023   dlg = (FeatQualChoiceDlgPtr) MemNew (sizeof (FeatQualChoiceDlgData));
11024   if (dlg == NULL)
11025   {
11026     return NULL;
11027   }
11028 
11029   p = HiddenGroup (h, 0, 0, NULL);
11030   SetObjectExtra (p, dlg, StdCleanupExtraProc);
11031 
11032   dlg->dialog = (DialoG) p;
11033   dlg->todialog = FeatQualChoiceToDialog;
11034   dlg->fromdialog = DialogToFeatQualChoice;
11035   dlg->testdialog = TestFeatQualChoiceDialog;
11036   dlg->is_legal = TRUE;
11037 
11038   dlg->legal_qual = LegalFeatQualChoiceDialog (p, change_notify, change_userdata);
11039   if (allow_illegal) {
11040     dlg->illegal_qual = StringConstraintDialog (p, NULL, FALSE, change_notify, change_userdata);
11041     Hide (dlg->illegal_qual);
11042   }
11043   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->legal_qual, (HANDLE) dlg->illegal_qual, NULL);
11044 
11045   return (DialoG) p;
11046 }
11047 
11048 
11049 typedef struct cdsgeneprotfielddlg {
11050   DIALOG_MESSAGE_BLOCK
11051   DialoG dlg;
11052 } CDSGeneProtFieldDlgData, PNTR CDSGeneProtFieldDlgPtr;
11053 
11054 
CDSGeneProtFieldToDialog(DialoG d,Pointer data)11055 static void CDSGeneProtFieldToDialog (DialoG d, Pointer data)
11056 {
11057   CDSGeneProtFieldDlgPtr dlg;
11058   ValNodePtr vnp;
11059   ValNode vn;
11060 
11061   dlg = (CDSGeneProtFieldDlgPtr) GetObjectExtra (d);
11062   if (dlg != NULL) {
11063     vnp = (ValNodePtr) data;
11064     if (vnp == NULL) {
11065       PointerToDialog (dlg->dlg, NULL);
11066     } else {
11067       vn.choice = vnp->data.intvalue;
11068       vn.data.ptrvalue = NULL;
11069       vn.next = NULL;
11070       PointerToDialog (dlg->dlg, &vn);
11071     }
11072   }
11073 }
11074 
DialogToCDSGeneProtField(DialoG d)11075 static Pointer DialogToCDSGeneProtField (DialoG d)
11076 {
11077   CDSGeneProtFieldDlgPtr dlg;
11078   ValNodePtr vnp, field = NULL;
11079 
11080   dlg = (CDSGeneProtFieldDlgPtr) GetObjectExtra (d);
11081   if (dlg != NULL) {
11082     vnp = (ValNodePtr) DialogToPointer (dlg->dlg);
11083     if (vnp != NULL) {
11084       field = ValNodeNew (NULL);
11085       field->choice = FieldType_cds_gene_prot;
11086       field->data.intvalue = vnp->choice;
11087     }
11088   }
11089   return field;
11090 }
11091 
11092 
TestCDSGeneProtFieldDialog(DialoG d)11093 static ValNodePtr TestCDSGeneProtFieldDialog (DialoG d)
11094 {
11095   CDSGeneProtFieldDlgPtr dlg;
11096   ValNodePtr err_list = NULL;
11097 
11098   dlg = (CDSGeneProtFieldDlgPtr) GetObjectExtra (d);
11099   if (dlg != NULL) {
11100     err_list = TestDialog (dlg->dlg);
11101   }
11102   return err_list;
11103 }
11104 
11105 
CDSGeneProtFieldDialogEx(GrouP h,Boolean tall,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)11106 static DialoG CDSGeneProtFieldDialogEx (GrouP h, Boolean tall, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
11107 {
11108   CDSGeneProtFieldDlgPtr dlg;
11109   GrouP                  p;
11110   ValNodePtr             field_list = NULL;
11111 
11112   dlg = (CDSGeneProtFieldDlgPtr) MemNew (sizeof (CDSGeneProtFieldDlgData));
11113   if (dlg == NULL)
11114   {
11115     return NULL;
11116   }
11117 
11118   p = HiddenGroup (h, 0, 0, NULL);
11119   SetObjectExtra (p, dlg, StdCleanupExtraProc);
11120 
11121   dlg->dialog = (DialoG) p;
11122   dlg->todialog = CDSGeneProtFieldToDialog;
11123   dlg->fromdialog = DialogToCDSGeneProtField;
11124   dlg->testdialog = TestCDSGeneProtFieldDialog;
11125 
11126   AddAllCDSGeneProtFieldsToChoiceList (&field_list);
11127   dlg->dlg = ValNodeSelectionDialog (p, field_list, tall ? TALL_SELECTION_LIST : SHORT_SELECTION_LIST, ValNodeStringName,
11128                                 ValNodeSimpleDataFree, ValNodeStringCopy,
11129                                 ValNodeChoiceMatch, "field type",
11130                                 change_notify, change_userdata, FALSE);
11131 
11132   return (DialoG) p;
11133 }
11134 
11135 
CDSGeneProtFieldDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)11136 static DialoG CDSGeneProtFieldDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
11137 {
11138   return CDSGeneProtFieldDialogEx (h, TRUE, change_notify, change_userdata);
11139 }
11140 
11141 
11142 typedef struct rnafeaturetypedlg {
11143   DIALOG_MESSAGE_BLOCK
11144   DialoG rna_type_dlg;
11145   GrouP  ncrna_class_grp;
11146   DialoG ncrna_class_dlg;
11147   Nlm_ChangeNotifyProc change_notify;
11148   Pointer change_userdata;
11149 } RnaFeatureTypeDlgData, PNTR RnaFeatureTypeDlgPtr;
11150 
11151 
11152 
ChangeRnaFeatureType(Pointer data)11153 static void ChangeRnaFeatureType (Pointer data)
11154 {
11155   RnaFeatureTypeDlgPtr dlg;
11156   ValNodePtr           vnp;
11157 
11158   dlg = (RnaFeatureTypeDlgPtr) data;
11159   if (dlg == NULL) return;
11160 
11161   vnp = DialogToPointer (dlg->rna_type_dlg);
11162   if (vnp == NULL || vnp->choice != RnaFeatType_ncRNA) {
11163     Hide (dlg->ncrna_class_grp);
11164   } else {
11165     Show (dlg->ncrna_class_grp);
11166   }
11167   vnp = ValNodeFree (vnp);
11168   if (dlg->change_notify != NULL) {
11169     (dlg->change_notify)(dlg->change_userdata);
11170   }
11171 }
11172 
11173 
RnaFeatureTypeToDialog(DialoG d,Pointer data)11174 static void RnaFeatureTypeToDialog (DialoG d, Pointer data)
11175 {
11176   RnaFeatureTypeDlgPtr dlg;
11177   RnaFeatTypePtr r;
11178   ValNode        vn;
11179 
11180   dlg = (RnaFeatureTypeDlgPtr) GetObjectExtra (d);
11181   if (dlg == NULL) return;
11182 
11183   r = (RnaFeatTypePtr) data;
11184 
11185   if (r == NULL) {
11186     vn.choice = RnaFeatType_rRNA;
11187     vn.data.ptrvalue = NULL;
11188     vn.next = NULL;
11189     PointerToDialog (dlg->rna_type_dlg, &vn);
11190     PointerToDialog (dlg->ncrna_class_dlg, NULL);
11191   } else {
11192     vn.choice = r->choice;
11193     vn.data.ptrvalue = NULL;
11194     vn.next = NULL;
11195     PointerToDialog (dlg->rna_type_dlg, &vn);
11196     if (r->choice == RnaFeatType_ncRNA) {
11197       PointerToDialog (dlg->ncrna_class_dlg, r->data.ptrvalue);
11198     } else {
11199       PointerToDialog (dlg->ncrna_class_dlg, NULL);
11200     }
11201   }
11202   ChangeRnaFeatureType (dlg);
11203 }
11204 
11205 
DialogToRnaFeatureType(DialoG d)11206 static Pointer DialogToRnaFeatureType (DialoG d)
11207 {
11208   RnaFeatureTypeDlgPtr dlg;
11209   RnaFeatTypePtr r = NULL;
11210   ValNodePtr     vnp;
11211 
11212   dlg = (RnaFeatureTypeDlgPtr) GetObjectExtra (d);
11213   if (dlg == NULL) return NULL;
11214 
11215   vnp = DialogToPointer (dlg->rna_type_dlg);
11216   if (vnp != NULL) {
11217     r = ValNodeNew (NULL);
11218     r->choice = vnp->choice;
11219     if (r->choice == RnaFeatType_ncRNA) {
11220       r->data.ptrvalue = DialogToPointer (dlg->ncrna_class_dlg);
11221     }
11222     vnp = ValNodeFree (vnp);
11223   }
11224   return r;
11225 }
11226 
11227 
TestRnaFeatureTypeDialog(DialoG d)11228 static ValNodePtr TestRnaFeatureTypeDialog (DialoG d)
11229 {
11230   RnaFeatureTypeDlgPtr dlg;
11231   ValNodePtr     vnp, err_list = NULL;
11232 
11233   dlg = (RnaFeatureTypeDlgPtr) GetObjectExtra (d);
11234   if (dlg == NULL) return NULL;
11235 
11236   vnp = DialogToPointer (dlg->rna_type_dlg);
11237   if (vnp == NULL) {
11238     ValNodeAddPointer (&err_list, 0, "no type");
11239   }
11240   vnp = ValNodeFree (vnp);
11241   return err_list;
11242 }
11243 
11244 
RnaFeatureTypeDialog(GrouP h,CharPtr type_label,Boolean allow_any,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)11245 static DialoG RnaFeatureTypeDialog (GrouP h, CharPtr type_label, Boolean allow_any, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
11246 {
11247   RnaFeatureTypeDlgPtr dlg;
11248   GrouP                  p;
11249   ValNodePtr             type_list = NULL;
11250 
11251   dlg = (RnaFeatureTypeDlgPtr) MemNew (sizeof (RnaFeatureTypeDlgData));
11252   if (dlg == NULL)
11253   {
11254     return NULL;
11255   }
11256 
11257   p = NormalGroup (h, -1, 0, type_label, programFont, NULL);
11258   SetObjectExtra (p, dlg, StdCleanupExtraProc);
11259 
11260   dlg->dialog = (DialoG) p;
11261   dlg->todialog = RnaFeatureTypeToDialog;
11262   dlg->fromdialog = DialogToRnaFeatureType;
11263   dlg->testdialog = TestRnaFeatureTypeDialog;
11264   dlg->change_notify = change_notify;
11265   dlg->change_userdata = change_userdata;
11266 
11267   if (allow_any) {
11268     ValNodeAddPointer (&type_list, RnaFeatType_any, StringSave ("any"));
11269   }
11270   ValNodeLink (&type_list, GetRNATypeList ());
11271   dlg->rna_type_dlg = ValNodeSelectionDialog (p, type_list, SHORT_SELECTION_LIST, ValNodeStringName,
11272                                 ValNodeSimpleDataFree, ValNodeStringCopy,
11273                                 ValNodeChoiceMatch, "field type",
11274                                 ChangeRnaFeatureType, dlg, FALSE);
11275 
11276   dlg->ncrna_class_grp = HiddenGroup (p, 2, 0, NULL);
11277   StaticPrompt (dlg->ncrna_class_grp, "ncRNA class", 0, dialogTextHeight, programFont, 'r');
11278   dlg->ncrna_class_dlg = CreatencRNAClassDialog (dlg->ncrna_class_grp, TRUE, change_notify, change_userdata);
11279   Hide (dlg->ncrna_class_grp);
11280   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->rna_type_dlg, (HANDLE) dlg->ncrna_class_grp, NULL);
11281 
11282   return (DialoG) p;
11283 
11284 }
11285 
11286 
11287 typedef struct rnaqualdlg {
11288   DIALOG_MESSAGE_BLOCK
11289   DialoG rnafeat_dlg;
11290   DialoG field_dlg;
11291   Nlm_ChangeNotifyProc change_notify;
11292   Pointer change_userdata;
11293 } RnaQualDlgData, PNTR RnaQualDlgPtr;
11294 
11295 
RnaQualToDialog(DialoG d,Pointer data)11296 static void RnaQualToDialog (DialoG d, Pointer data)
11297 {
11298   RnaQualDlgPtr dlg;
11299   RnaQualPtr    q;
11300   ValNode       vn;
11301 
11302   dlg = (RnaQualDlgPtr) GetObjectExtra (d);
11303   if (dlg == NULL) {
11304     return;
11305   }
11306 
11307   q = (RnaQualPtr) data;
11308   if (q == NULL) {
11309     PointerToDialog (dlg->rnafeat_dlg, NULL);
11310     PointerToDialog (dlg->field_dlg, NULL);
11311   } else {
11312     PointerToDialog (dlg->rnafeat_dlg, q->type);
11313     vn.choice = (Uint1)q->field;
11314     vn.data.ptrvalue = NULL;
11315     vn.next = NULL;
11316     PointerToDialog (dlg->field_dlg, &vn);
11317   }
11318 }
11319 
11320 
DialogToRnaQual(DialoG d)11321 static Pointer DialogToRnaQual (DialoG d)
11322 {
11323   RnaQualDlgPtr dlg;
11324   RnaQualPtr    q;
11325   ValNodePtr    vnp;
11326 
11327   dlg = (RnaQualDlgPtr) GetObjectExtra (d);
11328   if (dlg == NULL) {
11329     return NULL;
11330   }
11331 
11332   q = RnaQualNew ();
11333   q->type = DialogToPointer (dlg->rnafeat_dlg);
11334   vnp = DialogToPointer (dlg->field_dlg);
11335   if (vnp != NULL) {
11336     q->field = vnp->choice;
11337   }
11338   vnp = ValNodeFree (vnp);
11339   return (Pointer) q;
11340 }
11341 
11342 
TestRnaQualDialog(DialoG d)11343 static ValNodePtr TestRnaQualDialog (DialoG d)
11344 {
11345   ValNodePtr err_list = NULL;
11346   RnaQualDlgPtr dlg;
11347 
11348   dlg = (RnaQualDlgPtr) GetObjectExtra (d);
11349   if (dlg == NULL) {
11350     return NULL;
11351   }
11352 
11353   err_list = TestDialog (dlg->rnafeat_dlg);
11354   ValNodeLink (&err_list, TestDialog (dlg->field_dlg));
11355   return err_list;
11356 }
11357 
11358 
RnaQualDialogEx(GrouP h,CharPtr type_label,Boolean allow_any,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)11359 static DialoG RnaQualDialogEx (GrouP h, CharPtr type_label, Boolean allow_any, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
11360 {
11361   RnaQualDlgPtr dlg;
11362   GrouP          p;
11363   ValNodePtr     field_list = NULL;
11364   ValNode        vn;
11365   PrompT         ppt = NULL;
11366 
11367   dlg = (RnaQualDlgPtr) MemNew (sizeof (RnaQualDlgData));
11368   if (dlg == NULL)
11369   {
11370     return NULL;
11371   }
11372 
11373   p = HiddenGroup (h, -1, 0, NULL);
11374   SetObjectExtra (p, dlg, StdCleanupExtraProc);
11375 
11376   dlg->dialog = (DialoG) p;
11377   dlg->todialog = RnaQualToDialog;
11378   dlg->fromdialog = DialogToRnaQual;
11379   dlg->testdialog = TestRnaQualDialog;
11380   dlg->change_notify = change_notify;
11381   dlg->change_userdata = change_userdata;
11382 
11383   if (type_label != NULL) {
11384     dlg->rnafeat_dlg = RnaFeatureTypeDialog (p, type_label, allow_any, change_notify, change_userdata);
11385   }
11386   ppt = StaticPrompt (p, "RNA Field", 0, dialogTextHeight, programFont, 'l');
11387   field_list = GetRnaFieldList ();
11388   dlg->field_dlg = ValNodeSelectionDialog (p, field_list, SHORT_SELECTION_LIST, ValNodeStringName,
11389                                 ValNodeSimpleDataFree, ValNodeStringCopy,
11390                                 ValNodeChoiceMatch, "field type",
11391                                 change_notify, change_userdata, FALSE);
11392   vn.choice = field_list->choice;
11393   vn.data.ptrvalue = NULL;
11394   vn.next = NULL;
11395   PointerToDialog (dlg->field_dlg, &vn);
11396 
11397   AlignObjects (ALIGN_CENTER, (HANDLE) ppt, (HANDLE) dlg->field_dlg, (HANDLE) dlg->rnafeat_dlg, NULL);
11398   return (DialoG) p;
11399 }
11400 
11401 
RnaQualDialog(GrouP h,CharPtr type_label,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)11402 static DialoG RnaQualDialog (GrouP h, CharPtr type_label, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
11403 {
11404   return RnaQualDialogEx (h, type_label, FALSE, change_notify, change_userdata);
11405 }
11406 
11407 
11408 typedef struct structuredcommentfielddlg {
11409   DIALOG_MESSAGE_BLOCK
11410   PopuP field_type;
11411   TexT  field_name;
11412 
11413   Nlm_ChangeNotifyProc change_notify;
11414   Pointer change_userdata;
11415 } StructuredCommentFieldDlgData, PNTR StructuredCommentFieldDlgPtr;
11416 
11417 
ChangeStructureCommentFieldChoice(PopuP p)11418 static void ChangeStructureCommentFieldChoice (PopuP p)
11419 {
11420   Int2 val;
11421   StructuredCommentFieldDlgPtr dlg;
11422 
11423   dlg = (StructuredCommentFieldDlgPtr) GetObjectExtra (p);
11424 
11425   if (dlg == NULL) {
11426     return;
11427   }
11428 
11429   val = GetValue (dlg->field_type);
11430   switch (val) {
11431     case 2:
11432       Hide (dlg->field_name);
11433       break;
11434     case 1:
11435       Show (dlg->field_name);
11436       break;
11437     case 3:
11438       Hide (dlg->field_name);
11439       break;
11440   }
11441 
11442   if (dlg->change_notify != NULL) {
11443     (dlg->change_notify) (dlg->change_userdata);
11444   }
11445 }
11446 
11447 
StructuredCommentFieldToDialog(DialoG d,Pointer data)11448 static void StructuredCommentFieldToDialog (DialoG d, Pointer data)
11449 {
11450   StructuredCommentFieldDlgPtr dlg;
11451   StructuredCommentFieldPtr    field;
11452 
11453   dlg = (StructuredCommentFieldDlgPtr) GetObjectExtra (d);
11454   if (dlg == NULL) {
11455     return;
11456   }
11457 
11458   field = (StructuredCommentFieldPtr) data;
11459   if (field == NULL) {
11460     SetValue (dlg->field_type, 1);
11461   } else {
11462     switch (field->choice) {
11463       case StructuredCommentField_database:
11464         SetValue (dlg->field_type, 2);
11465         break;
11466       case StructuredCommentField_named:
11467         SetValue (dlg->field_type, 1);
11468         SetTitle (dlg->field_name, field->data.ptrvalue);
11469         break;
11470       case StructuredCommentField_field_name:
11471         SetValue (dlg->field_type, 3);
11472         break;
11473     }
11474   }
11475 
11476   ChangeStructureCommentFieldChoice (dlg->field_type);
11477 }
11478 
11479 
StructuredCommentFieldFromDialog(DialoG d)11480 static Pointer StructuredCommentFieldFromDialog (DialoG d)
11481 {
11482   StructuredCommentFieldDlgPtr dlg;
11483   StructuredCommentFieldPtr    field;
11484   Int2                         val;
11485 
11486   dlg = (StructuredCommentFieldDlgPtr) GetObjectExtra (d);
11487   if (dlg == NULL) {
11488     return NULL;
11489   }
11490 
11491   field = ValNodeNew (NULL);
11492   val = GetValue (dlg->field_type);
11493 
11494   switch (val) {
11495     case 2:
11496       field->choice = StructuredCommentField_database;
11497       break;
11498     case 1:
11499       field->choice = StructuredCommentField_named;
11500       field->data.ptrvalue = SaveStringFromText (dlg->field_name);
11501       if (StringHasNoText (field->data.ptrvalue)) {
11502         field = ValNodeFree (field);
11503       }
11504       break;
11505     case 3:
11506       field->choice = StructuredCommentField_field_name;
11507       break;
11508     default:
11509       field = ValNodeFree (field);
11510       break;
11511   }
11512   return (Pointer) field;
11513 }
11514 
11515 
TestStructuredCommentFieldDialog(DialoG d)11516 static ValNodePtr TestStructuredCommentFieldDialog (DialoG d)
11517 {
11518   ValNodePtr field, err_list = NULL;
11519 
11520   field = DialogToPointer (d);
11521   if (field == NULL) {
11522     ValNodeAddPointer (&err_list, 0, "bad field");
11523   } else {
11524     field = StructuredCommentFieldFree (field);
11525   }
11526   return err_list;
11527 }
11528 
11529 
ChangeStructureCommentFieldDialogText(TexT t)11530 static void ChangeStructureCommentFieldDialogText (TexT t)
11531 {
11532   StructuredCommentFieldDlgPtr dlg;
11533 
11534   dlg = (StructuredCommentFieldDlgPtr) GetObjectExtra (t);
11535   if (dlg == NULL) {
11536     return;
11537   }
11538 
11539   if (dlg->change_notify != NULL) {
11540     (dlg->change_notify) (dlg->change_userdata);
11541   }
11542 }
11543 
11544 
StructuredCommentFieldDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)11545 static DialoG StructuredCommentFieldDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
11546 {
11547   StructuredCommentFieldDlgPtr dlg;
11548   GrouP                 p;
11549 
11550   dlg = (StructuredCommentFieldDlgPtr) MemNew (sizeof (StructuredCommentFieldDlgData));
11551   if (dlg == NULL)
11552   {
11553     return NULL;
11554   }
11555 
11556   p = HiddenGroup (h, 2, 0, NULL);
11557   SetObjectExtra (p, dlg, StdCleanupExtraProc);
11558 
11559   dlg->dialog = (DialoG) p;
11560   dlg->todialog = StructuredCommentFieldToDialog;
11561   dlg->fromdialog = StructuredCommentFieldFromDialog;
11562   dlg->testdialog = TestStructuredCommentFieldDialog;
11563   dlg->change_notify = change_notify;
11564   dlg->change_userdata = change_userdata;
11565 
11566   dlg->field_type = PopupList (p, TRUE, ChangeStructureCommentFieldChoice);
11567   SetObjectExtra (dlg->field_type, dlg, NULL);
11568   PopupItem (dlg->field_type, "Field");
11569   PopupItem (dlg->field_type, "Database Name");
11570   PopupItem (dlg->field_type, "Field Name");
11571   SetValue (dlg->field_type, 1);
11572 
11573   dlg->field_name = DialogText (p, "", 20, ChangeStructureCommentFieldDialogText);
11574   SetObjectExtra (dlg->field_name, dlg, NULL);
11575 
11576   return (DialoG) p;
11577 }
11578 
11579 
11580 typedef struct miscfielddlg {
11581   DIALOG_MESSAGE_BLOCK
11582   PopuP field_type;
11583 
11584   Nlm_ChangeNotifyProc change_notify;
11585   Pointer change_userdata;
11586 } MiscFieldDlgData, PNTR MiscFieldDlgPtr;
11587 
11588 
ChangeMiscFieldChoice(PopuP p)11589 static void ChangeMiscFieldChoice (PopuP p)
11590 {
11591   MiscFieldDlgPtr dlg;
11592 
11593   dlg = (MiscFieldDlgPtr) GetObjectExtra (p);
11594 
11595   if (dlg == NULL) {
11596     return;
11597   }
11598 
11599   if (dlg->change_notify != NULL) {
11600     (dlg->change_notify) (dlg->change_userdata);
11601   }
11602 }
11603 
11604 
MiscFieldToDialog(DialoG d,Pointer data)11605 static void MiscFieldToDialog (DialoG d, Pointer data)
11606 {
11607   MiscFieldDlgPtr dlg;
11608   ValNodePtr    field;
11609 
11610   dlg = (MiscFieldDlgPtr) GetObjectExtra (d);
11611   if (dlg == NULL) {
11612     return;
11613   }
11614 
11615   field = (ValNodePtr) data;
11616   if (field == NULL) {
11617     SetValue (dlg->field_type, 1);
11618   } else {
11619     switch (field->data.intvalue) {
11620       case Misc_field_genome_project_id:
11621         SetValue (dlg->field_type, 1);
11622         break;
11623       case Misc_field_comment_descriptor:
11624         SetValue (dlg->field_type, 2);
11625         break;
11626       case Misc_field_defline:
11627         SetValue (dlg->field_type, 3);
11628         break;
11629       case Misc_field_keyword:
11630         SetValue (dlg->field_type, 4);
11631         break;
11632     }
11633   }
11634 
11635   ChangeMiscFieldChoice (dlg->field_type);
11636 }
11637 
11638 
MiscFieldFromDialog(DialoG d)11639 static Pointer MiscFieldFromDialog (DialoG d)
11640 {
11641   MiscFieldDlgPtr dlg;
11642   ValNodePtr      field;
11643   Int2            val;
11644 
11645   dlg = (MiscFieldDlgPtr) GetObjectExtra (d);
11646   if (dlg == NULL) {
11647     return NULL;
11648   }
11649 
11650   field = ValNodeNew (NULL);
11651   field->choice = FieldType_misc;
11652   val = GetValue (dlg->field_type);
11653 
11654   switch (val) {
11655     case 1:
11656       field->data.intvalue = Misc_field_genome_project_id;
11657       break;
11658     case 2:
11659       field->data.intvalue = Misc_field_comment_descriptor;
11660       break;
11661     case 3:
11662       field->data.intvalue = Misc_field_defline;
11663       break;
11664     case 4:
11665       field->data.intvalue = Misc_field_keyword;
11666       break;
11667     default:
11668       field = ValNodeFree (field);
11669       break;
11670   }
11671   return (Pointer) field;
11672 }
11673 
11674 
TestMiscFieldDialog(DialoG d)11675 static ValNodePtr TestMiscFieldDialog (DialoG d)
11676 {
11677   ValNodePtr field, err_list = NULL;
11678 
11679   field = DialogToPointer (d);
11680   if (field == NULL) {
11681     ValNodeAddPointer (&err_list, 0, "bad field");
11682   } else {
11683     field = ValNodeFree (field);
11684   }
11685   return err_list;
11686 }
11687 
11688 
MiscFieldDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)11689 static DialoG MiscFieldDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
11690 {
11691   MiscFieldDlgPtr dlg;
11692   GrouP           p;
11693 
11694   dlg = (MiscFieldDlgPtr) MemNew (sizeof (MiscFieldDlgData));
11695   if (dlg == NULL)
11696   {
11697     return NULL;
11698   }
11699 
11700   p = HiddenGroup (h, 2, 0, NULL);
11701   SetObjectExtra (p, dlg, StdCleanupExtraProc);
11702 
11703   dlg->dialog = (DialoG) p;
11704   dlg->todialog = MiscFieldToDialog;
11705   dlg->fromdialog = MiscFieldFromDialog;
11706   dlg->testdialog = TestMiscFieldDialog;
11707   dlg->change_notify = change_notify;
11708   dlg->change_userdata = change_userdata;
11709 
11710   dlg->field_type = PopupList (p, TRUE, ChangeMiscFieldChoice);
11711   SetObjectExtra (dlg->field_type, dlg, NULL);
11712   PopupItem (dlg->field_type, "Genome Project ID");
11713   PopupItem (dlg->field_type, "Comment Descriptor");
11714   PopupItem (dlg->field_type, "Definition Line");
11715   PopupItem (dlg->field_type, "Keyword");
11716   SetValue (dlg->field_type, 1);
11717 
11718   return (DialoG) p;
11719 }
11720 
11721 
11722 typedef struct dblinkfielddlg {
11723   DIALOG_MESSAGE_BLOCK
11724   PopuP field_type;
11725 
11726   Nlm_ChangeNotifyProc change_notify;
11727   Pointer change_userdata;
11728 } DBLinkFieldDlgData, PNTR DBLinkFieldDlgPtr;
11729 
11730 
ChangeDBLinkFieldChoice(PopuP p)11731 static void ChangeDBLinkFieldChoice (PopuP p)
11732 {
11733   DBLinkFieldDlgPtr dlg;
11734 
11735   dlg = (DBLinkFieldDlgPtr) GetObjectExtra (p);
11736 
11737   if (dlg == NULL) {
11738     return;
11739   }
11740 
11741   if (dlg->change_notify != NULL) {
11742     (dlg->change_notify) (dlg->change_userdata);
11743   }
11744 }
11745 
11746 
DBLinkFieldToDialog(DialoG d,Pointer data)11747 static void DBLinkFieldToDialog (DialoG d, Pointer data)
11748 {
11749   DBLinkFieldDlgPtr dlg;
11750   ValNodePtr    field;
11751 
11752   dlg = (DBLinkFieldDlgPtr) GetObjectExtra (d);
11753   if (dlg == NULL) {
11754     return;
11755   }
11756 
11757   field = (ValNodePtr) data;
11758   if (field == NULL) {
11759     SetValue (dlg->field_type, 1);
11760   } else {
11761     switch (field->data.intvalue) {
11762       case DBLink_field_type_trace_assembly:
11763         SetValue (dlg->field_type, 1);
11764         break;
11765       case DBLink_field_type_bio_sample :
11766         SetValue (dlg->field_type, 2);
11767         break;
11768       case DBLink_field_type_probe_db :
11769         SetValue (dlg->field_type, 3);
11770         break;
11771       case DBLink_field_type_sequence_read_archve :
11772         SetValue (dlg->field_type, 4);
11773         break;
11774       case DBLink_field_type_bio_project:
11775         SetValue (dlg->field_type, 5);
11776         break;
11777     }
11778   }
11779 
11780   ChangeDBLinkFieldChoice (dlg->field_type);
11781 }
11782 
11783 
DBLinkFieldFromDialog(DialoG d)11784 static Pointer DBLinkFieldFromDialog (DialoG d)
11785 {
11786   DBLinkFieldDlgPtr dlg;
11787   ValNodePtr      field;
11788   Int2            val;
11789 
11790   dlg = (DBLinkFieldDlgPtr) GetObjectExtra (d);
11791   if (dlg == NULL) {
11792     return NULL;
11793   }
11794 
11795   field = ValNodeNew (NULL);
11796   field->choice = FieldType_dblink;
11797   val = GetValue (dlg->field_type);
11798 
11799   switch (val) {
11800     case 1:
11801       field->data.intvalue = DBLink_field_type_trace_assembly;
11802       break;
11803     case 2:
11804       field->data.intvalue = DBLink_field_type_bio_sample ;
11805       break;
11806     case 3:
11807       field->data.intvalue = DBLink_field_type_probe_db ;
11808       break;
11809     case 4:
11810       field->data.intvalue = DBLink_field_type_sequence_read_archve ;
11811       break;
11812     case 5:
11813       field->data.intvalue = DBLink_field_type_bio_project;
11814       break;
11815     default:
11816       field = ValNodeFree (field);
11817       break;
11818   }
11819   return (Pointer) field;
11820 }
11821 
11822 
TestDBLinkFieldDialog(DialoG d)11823 static ValNodePtr TestDBLinkFieldDialog (DialoG d)
11824 {
11825   ValNodePtr field, err_list = NULL;
11826 
11827   field = DialogToPointer (d);
11828   if (field == NULL) {
11829     ValNodeAddPointer (&err_list, 0, "bad field");
11830   } else {
11831     field = ValNodeFree (field);
11832   }
11833   return err_list;
11834 }
11835 
11836 
DBLinkFieldDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)11837 static DialoG DBLinkFieldDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
11838 {
11839   DBLinkFieldDlgPtr dlg;
11840   GrouP           p;
11841 
11842   dlg = (DBLinkFieldDlgPtr) MemNew (sizeof (DBLinkFieldDlgData));
11843   if (dlg == NULL)
11844   {
11845     return NULL;
11846   }
11847 
11848   p = HiddenGroup (h, 2, 0, NULL);
11849   SetObjectExtra (p, dlg, StdCleanupExtraProc);
11850 
11851   dlg->dialog = (DialoG) p;
11852   dlg->todialog = DBLinkFieldToDialog;
11853   dlg->fromdialog = DBLinkFieldFromDialog;
11854   dlg->testdialog = TestDBLinkFieldDialog;
11855   dlg->change_notify = change_notify;
11856   dlg->change_userdata = change_userdata;
11857 
11858   dlg->field_type = PopupList (p, TRUE, ChangeDBLinkFieldChoice);
11859   SetObjectExtra (dlg->field_type, dlg, NULL);
11860   PopupItem (dlg->field_type, "Trace Assembly");
11861   PopupItem (dlg->field_type, "BioSample");
11862   PopupItem (dlg->field_type, "Probe DB");
11863   PopupItem (dlg->field_type, "Sequence Read Archive");
11864   PopupItem (dlg->field_type, "BioProject");
11865   SetValue (dlg->field_type, 1);
11866 
11867   return (DialoG) p;
11868 }
11869 
11870 
11871 typedef struct fieldtypedlg {
11872   DIALOG_MESSAGE_BLOCK
11873   Uint1 field_type;
11874   DialoG src_qual;
11875   GrouP feature_field_grp;
11876   DialoG feature_type;
11877   DialoG feature_field;
11878   DialoG cdsgeneprot;
11879   DialoG sequence_qual;
11880   DialoG pub_field;
11881   DialoG rna_field;
11882   DialoG structured_comment_field;
11883   DialoG misc_field;
11884   PopuP  dblink_field;
11885 
11886   Nlm_ChangeNotifyProc change_notify;
11887   Pointer change_userdata;
11888 } FieldTypeDlgData, PNTR FieldTypeDlgPtr;
11889 
11890 
FieldTypeToDialog(DialoG d,Pointer data)11891 static void FieldTypeToDialog (DialoG d, Pointer data)
11892 {
11893   FieldTypeDlgPtr dlg;
11894   FeatureFieldPtr ffp;
11895   ValNodePtr vnp;
11896   ValNode vn;
11897 
11898   dlg = (FieldTypeDlgPtr) GetObjectExtra (d);
11899   if (dlg == NULL) return;
11900 
11901   SafeHide (dlg->src_qual);
11902   SafeHide (dlg->feature_field_grp);
11903   SafeHide (dlg->cdsgeneprot);
11904   SafeHide (dlg->sequence_qual);
11905   SafeHide (dlg->pub_field);
11906   SafeHide (dlg->rna_field);
11907   SafeHide (dlg->structured_comment_field);
11908   SafeHide (dlg->misc_field);
11909   SafeHide (dlg->dblink_field);
11910 
11911   vnp = (ValNodePtr) data;
11912   if (vnp != NULL) {
11913     switch (vnp->choice) {
11914       case FieldType_source_qual:
11915         SafeShow (dlg->src_qual);
11916         PointerToDialog (dlg->src_qual, vnp->data.ptrvalue);
11917         dlg->field_type = FieldType_source_qual;
11918         break;
11919       case FieldType_feature_field:
11920         SafeShow (dlg->feature_field_grp);
11921         ffp = (FeatureFieldPtr) vnp->data.ptrvalue;
11922         if (ffp == NULL) {
11923           PointerToDialog (dlg->feature_type, NULL);
11924           PointerToDialog (dlg->feature_field, NULL);
11925         } else {
11926           vn.choice = (Uint1)ffp->type;
11927           vn.data.ptrvalue = NULL;
11928           vn.next = NULL;
11929           PointerToDialog (dlg->feature_type, &vn);
11930           PointerToDialog (dlg->feature_field, ffp->field);
11931         }
11932         dlg->field_type = FieldType_feature_field;
11933         break;
11934       case FieldType_cds_gene_prot:
11935         SafeShow (dlg->cdsgeneprot);
11936         PointerToDialog (dlg->cdsgeneprot, vnp);
11937         dlg->field_type = FieldType_cds_gene_prot;
11938         break;
11939       case FieldType_molinfo_field:
11940         SafeShow (dlg->sequence_qual);
11941         PointerToDialog (dlg->sequence_qual, vnp->data.ptrvalue);
11942         dlg->field_type = FieldType_molinfo_field;
11943         break;
11944       case FieldType_pub:
11945         SafeShow (dlg->pub_field);
11946         vn.choice = vnp->data.intvalue;
11947         vn.data.ptrvalue = NULL;
11948         vn.next = NULL;
11949         PointerToDialog (dlg->pub_field, &vn);
11950         dlg->field_type = FieldType_pub;
11951         break;
11952       case FieldType_rna_field:
11953         SafeShow (dlg->rna_field);
11954         PointerToDialog (dlg->rna_field, vnp->data.ptrvalue);
11955         dlg->field_type = FieldType_rna_field;
11956         break;
11957       case FieldType_struc_comment_field:
11958         SafeShow (dlg->structured_comment_field);
11959         PointerToDialog (dlg->structured_comment_field, vnp->data.ptrvalue);
11960         dlg->field_type = FieldType_struc_comment_field;
11961         break;
11962       case FieldType_misc:
11963         SafeShow (dlg->misc_field);
11964         PointerToDialog (dlg->misc_field, vnp);
11965         dlg->field_type = FieldType_misc;
11966         break;
11967       case FieldType_dblink:
11968         SafeShow (dlg->dblink_field);
11969         SetValue (dlg->dblink_field, vnp->data.intvalue);
11970         dlg->field_type = FieldType_dblink;
11971         break;
11972     }
11973   }
11974 }
11975 
11976 
GetFieldOfTypeFromFieldType(DialoG d,Uint1 field_type)11977 static ValNodePtr GetFieldOfTypeFromFieldType(DialoG d, Uint1 field_type)
11978 {
11979   FieldTypeDlgPtr dlg;
11980   FeatureFieldPtr ffp;
11981   ValNodePtr vnp = NULL, vnp2;
11982 
11983   dlg = (FieldTypeDlgPtr) GetObjectExtra (d);
11984   if (dlg == NULL) return NULL;
11985 
11986   switch (field_type) {
11987     case FieldType_source_qual:
11988       vnp = ValNodeNew(NULL);
11989       vnp->choice = FieldType_source_qual;
11990       vnp->data.ptrvalue = DialogToPointer (dlg->src_qual);
11991       break;
11992     case FieldType_feature_field:
11993       vnp2 = DialogToPointer (dlg->feature_type);
11994       if (vnp2 != NULL) {
11995         ffp = FeatureFieldNew();
11996         ffp->type = vnp2->choice;
11997         ffp->field = DialogToPointer (dlg->feature_field);
11998         vnp = ValNodeNew (NULL);
11999         vnp->choice = FieldType_feature_field;
12000         vnp->data.ptrvalue = ffp;
12001       }
12002       break;
12003     case FieldType_cds_gene_prot:
12004       vnp = DialogToPointer (dlg->cdsgeneprot);
12005       break;
12006     case FieldType_molinfo_field:
12007       vnp = ValNodeNew (NULL);
12008       vnp->choice = FieldType_molinfo_field;
12009       vnp->data.ptrvalue = DialogToPointer (dlg->sequence_qual);
12010       break;
12011     case FieldType_pub:
12012       vnp2 = DialogToPointer (dlg->pub_field);
12013       if (vnp2 != NULL) {
12014         vnp = ValNodeNew (NULL);
12015         vnp->choice = FieldType_pub;
12016         vnp->data.intvalue = vnp2->choice;
12017       }
12018       break;
12019     case FieldType_rna_field:
12020       vnp = ValNodeNew (NULL);
12021       vnp->choice = FieldType_rna_field;
12022       vnp->data.ptrvalue = DialogToPointer (dlg->rna_field);
12023       break;
12024     case FieldType_struc_comment_field:
12025       vnp = ValNodeNew (NULL);
12026       vnp->choice = FieldType_struc_comment_field;
12027       vnp->data.ptrvalue = DialogToPointer (dlg->structured_comment_field);
12028       break;
12029     case FieldType_misc:
12030       vnp = DialogToPointer (dlg->misc_field);
12031       break;
12032     case FieldType_dblink:
12033       vnp = ValNodeNew (NULL);
12034       vnp->choice = FieldType_dblink;
12035       vnp->data.intvalue = GetValue (dlg->dblink_field);
12036       break;
12037   }
12038   return vnp;
12039 }
12040 
12041 
DialogToFieldType(DialoG d)12042 static Pointer DialogToFieldType (DialoG d)
12043 {
12044   FieldTypeDlgPtr dlg;
12045 
12046   dlg = (FieldTypeDlgPtr) GetObjectExtra (d);
12047   if (dlg == NULL) return NULL;
12048 
12049   return GetFieldOfTypeFromFieldType(d, dlg->field_type);
12050 }
12051 
12052 
TestFieldTypeDialog(DialoG d)12053 static ValNodePtr TestFieldTypeDialog (DialoG d)
12054 {
12055   FieldTypeDlgPtr dlg;
12056   ValNodePtr      err_list = NULL;
12057 
12058   dlg = (FieldTypeDlgPtr) GetObjectExtra (d);
12059   if (dlg == NULL) return NULL;
12060 
12061   switch (dlg->field_type) {
12062     case FieldType_source_qual:
12063       ValNodeLink (&err_list, TestDialog (dlg->src_qual));
12064       break;
12065     case FieldType_feature_field:
12066       ValNodeLink (&err_list, TestDialog (dlg->feature_type));
12067       ValNodeLink (&err_list, TestDialog (dlg->feature_field));
12068       break;
12069     case FieldType_cds_gene_prot:
12070       ValNodeLink (&err_list, TestDialog (dlg->cdsgeneprot));
12071       break;
12072     case FieldType_molinfo_field:
12073       ValNodeLink (&err_list, TestDialog (dlg->sequence_qual));
12074       break;
12075     case FieldType_pub:
12076       ValNodeLink (&err_list, TestDialog (dlg->pub_field));
12077       break;
12078     case FieldType_rna_field:
12079       ValNodeLink (&err_list, TestDialog (dlg->rna_field));
12080       break;
12081     case FieldType_struc_comment_field:
12082       ValNodeLink (&err_list, TestDialog (dlg->structured_comment_field));
12083       break;
12084     case FieldType_misc:
12085       ValNodeLink (&err_list, TestDialog (dlg->misc_field));
12086       break;
12087     case FieldType_dblink:
12088       break;
12089     default :
12090       ValNodeAddPointer (&err_list, 0, "No field type chosen");
12091       break;
12092   }
12093   return err_list;
12094 }
12095 
12096 
ChangeFieldTypeDialogPopup(PopuP p)12097 static void ChangeFieldTypeDialogPopup (PopuP p)
12098 {
12099   FieldTypeDlgPtr dlg;
12100 
12101   dlg = (FieldTypeDlgPtr) GetObjectExtra (p);
12102   if (dlg == NULL) {
12103     return;
12104   }
12105 
12106   if (dlg->change_notify != NULL) {
12107     (dlg->change_notify)(dlg->change_userdata);
12108   }
12109 }
12110 
12111 
MakeDbLinkFieldPopup(GrouP h,Nlm_PupActnProc actn,Pointer extradata)12112 static PopuP MakeDbLinkFieldPopup (GrouP h, Nlm_PupActnProc actn, Pointer extradata)
12113 {
12114   Int4            num, i;
12115   PopuP           p;
12116 
12117   p = PopupList (h, TRUE, actn);
12118   SetObjectExtra (p, extradata, NULL);
12119   num = GetNumDBLinkFields();
12120   for (i = 1; i <= num; i++) {
12121     PopupItem (p, GetDBLinkNameFromDBLinkFieldType(i));
12122   }
12123   SetValue (p, 1);
12124   return p;
12125 }
12126 
12127 
FieldTypeDialogMessage(DialoG d,Int2 mssg)12128 static void FieldTypeDialogMessage (DialoG d, Int2 mssg)
12129 
12130 {
12131   FieldTypeDlgPtr dlg;
12132 
12133   dlg = (FieldTypeDlgPtr) GetObjectExtra (d);
12134   if (dlg != NULL) {
12135     switch (mssg) {
12136       case VIB_MSG_ENTER :
12137         switch (dlg->field_type) {
12138           case FieldType_source_qual:
12139             SendMessageToDialog (dlg->src_qual, VIB_MSG_ENTER);
12140             break;
12141           case FieldType_feature_field:
12142             Select (dlg->feature_field);
12143             break;
12144           case FieldType_cds_gene_prot:
12145             Select (dlg->cdsgeneprot);
12146             break;
12147           case FieldType_molinfo_field:
12148             Select (dlg->sequence_qual);
12149             break;
12150           case FieldType_pub:
12151             Select (dlg->pub_field);
12152             break;
12153           case FieldType_rna_field:
12154             Select (dlg->rna_field);
12155             break;
12156           case FieldType_struc_comment_field:
12157             Select (dlg->structured_comment_field);
12158             break;
12159           case FieldType_misc:
12160             Select (dlg->misc_field);
12161             break;
12162           case FieldType_dblink:
12163             Select (dlg->dblink_field);
12164             break;
12165         }
12166         break;
12167       default :
12168         break;
12169     }
12170   }
12171 }
12172 
12173 
FieldTypeDialog(GrouP h,Boolean text_only,Boolean for_remove,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)12174 static DialoG FieldTypeDialog (GrouP h, Boolean text_only, Boolean for_remove, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
12175 {
12176   FieldTypeDlgPtr dlg;
12177   GrouP           p;
12178 
12179   dlg = (FieldTypeDlgPtr) MemNew (sizeof (FieldTypeDlgData));
12180   if (dlg == NULL)
12181   {
12182     return NULL;
12183   }
12184 
12185   p = HiddenGroup (h, 0, 0, NULL);
12186   SetObjectExtra (p, dlg, StdCleanupExtraProc);
12187 
12188   dlg->dialog = (DialoG) p;
12189   dlg->todialog = FieldTypeToDialog;
12190   dlg->fromdialog = DialogToFieldType;
12191   dlg->testdialog = TestFieldTypeDialog;
12192   dlg->dialogmessage = FieldTypeDialogMessage;
12193   dlg->change_notify = change_notify;
12194   dlg->change_userdata = change_userdata;
12195 
12196   dlg->src_qual = SourceQualChoiceDialog (p, text_only, for_remove, TRUE, change_notify, change_userdata);
12197   dlg->feature_field_grp = HiddenGroup (p, 2, 0, NULL);
12198   dlg->feature_type = FeatureTypeDialog (dlg->feature_field_grp, change_notify, change_userdata);
12199   dlg->feature_field = FeatQualChoiceDialog (dlg->feature_field_grp, for_remove, change_notify, change_userdata);
12200   dlg->cdsgeneprot = CDSGeneProtFieldDialog (p, change_notify, change_userdata);
12201   dlg->sequence_qual = SequenceQualDialog (p, change_notify, change_userdata);
12202   dlg->pub_field = PubFieldDialog (p, change_notify, change_userdata);
12203   dlg->rna_field = RnaQualDialogEx (p, "RNA Type of Feature to be Edited", TRUE, change_notify, change_userdata);
12204   dlg->structured_comment_field = StructuredCommentFieldDialog (p, change_notify, change_userdata);
12205   dlg->misc_field = MiscFieldDialog (p, change_notify, change_userdata);
12206   dlg->dblink_field = MakeDbLinkFieldPopup (p, ChangeFieldTypeDialogPopup, dlg);
12207 
12208   SafeHide (dlg->src_qual);
12209   SafeHide (dlg->feature_field_grp);
12210   SafeHide (dlg->cdsgeneprot);
12211   SafeHide (dlg->sequence_qual);
12212   SafeHide (dlg->pub_field);
12213   SafeHide (dlg->rna_field);
12214   SafeHide (dlg->structured_comment_field);
12215   SafeHide (dlg->misc_field);
12216   SafeHide (dlg->dblink_field);
12217 
12218   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->src_qual,
12219                               (HANDLE) dlg->feature_field_grp,
12220                               (HANDLE) dlg->cdsgeneprot,
12221                               (HANDLE) dlg->sequence_qual,
12222                               (HANDLE) dlg->pub_field,
12223                               (HANDLE) dlg->rna_field,
12224                               (HANDLE) dlg->structured_comment_field,
12225                               (HANDLE) dlg->misc_field,
12226                               (HANDLE) dlg->dblink_field,
12227                               NULL);
12228 
12229   return (DialoG) p;
12230 }
12231 
12232 
12233 typedef struct fieldpairtypedlg {
12234   DIALOG_MESSAGE_BLOCK
12235   Uint1 field_type;
12236   GrouP src_qual_grp;
12237   DialoG src_qual_from;
12238   DialoG src_qual_to;
12239   GrouP feature_field_grp;
12240   DialoG feature_type;
12241   DialoG feature_field_from;
12242   DialoG feature_field_to;
12243   GrouP cdsgeneprot_grp;
12244   DialoG cdsgeneprot_from;
12245   DialoG cdsgeneprot_to;
12246   DialoG molinfo_dlg;
12247   GrouP  rna_grp;
12248   DialoG rna_feat_dlg;
12249   DialoG rna_field_from;
12250   DialoG rna_field_to;
12251   GrouP  dblink_grp;
12252   PopuP  dblink_field_from;
12253   PopuP  dblink_field_to;
12254 
12255   Nlm_ChangeNotifyProc change_notify;
12256   Pointer change_userdata;
12257 } FieldPairTypeDlgData, PNTR FieldPairTypeDlgPtr;
12258 
12259 
FieldPairTypeToDialog(DialoG d,Pointer data)12260 static void FieldPairTypeToDialog (DialoG d, Pointer data)
12261 {
12262   FieldPairTypeDlgPtr dlg;
12263   ValNodePtr vnp;
12264   ValNode      vn;
12265   FieldTypePtr from_field, to_field;
12266   FeatureFieldPairPtr ffp;
12267   CDSGeneProtFieldPairPtr cgp;
12268   RnaQualPairPtr          rna_quals;
12269   DBLinkFieldPairPtr      dblink;
12270 
12271   dlg = (FieldPairTypeDlgPtr) GetObjectExtra (d);
12272   if (dlg == NULL) return;
12273 
12274   SafeHide (dlg->src_qual_grp);
12275   SafeHide (dlg->feature_field_grp);
12276   SafeHide (dlg->cdsgeneprot_grp);
12277   SafeHide (dlg->molinfo_dlg);
12278   SafeHide (dlg->rna_grp);
12279   SafeHide (dlg->dblink_grp);
12280   vnp = (ValNodePtr) data;
12281   if (vnp == NULL) {
12282     dlg->field_type = 0;
12283   } else {
12284     switch (vnp->choice) {
12285       case FieldPairType_source_qual:
12286         SafeShow (dlg->src_qual_grp);
12287         from_field = GetFromFieldFromFieldPair (vnp);
12288         if (from_field == NULL) {
12289           PointerToDialog (dlg->src_qual_from, NULL);
12290         } else {
12291           PointerToDialog (dlg->src_qual_from, from_field->data.ptrvalue);
12292         }
12293         from_field = FieldTypeFree (from_field);
12294         to_field = GetToFieldFromFieldPair (vnp);
12295         if (to_field == NULL) {
12296           PointerToDialog (dlg->src_qual_to, NULL);
12297         } else {
12298           PointerToDialog (dlg->src_qual_to, to_field->data.ptrvalue);
12299         }
12300         to_field = FieldTypeFree (to_field);
12301         dlg->field_type = FieldType_source_qual;
12302         break;
12303       case FieldPairType_feature_field:
12304         SafeShow (dlg->feature_field_grp);
12305         ffp = (FeatureFieldPairPtr) vnp->data.ptrvalue;
12306         if (ffp == NULL) {
12307           PointerToDialog (dlg->feature_type, NULL);
12308           PointerToDialog (dlg->feature_field_from, NULL);
12309           PointerToDialog (dlg->feature_field_to, NULL);
12310         } else {
12311           vn.choice = (Uint1)ffp->type;
12312           vn.data.ptrvalue = NULL;
12313           vn.next = NULL;
12314           PointerToDialog (dlg->feature_type, &vn);
12315           PointerToDialog (dlg->feature_field_from, ffp->field_from);
12316           PointerToDialog (dlg->feature_field_to, ffp->field_to);
12317         }
12318         dlg->field_type = FieldType_feature_field;
12319         break;
12320       case FieldPairType_cds_gene_prot:
12321         SafeShow (dlg->cdsgeneprot_grp);
12322         cgp = (CDSGeneProtFieldPairPtr) vnp->data.ptrvalue;
12323         if (cgp == NULL) {
12324           PointerToDialog (dlg->cdsgeneprot_from, NULL);
12325           PointerToDialog (dlg->cdsgeneprot_to, NULL);
12326         } else {
12327           from_field = GetFromFieldFromFieldPair (vnp);
12328           PointerToDialog (dlg->cdsgeneprot_from, from_field);
12329           from_field = FieldTypeFree (from_field);
12330           to_field = GetToFieldFromFieldPair (vnp);
12331           PointerToDialog (dlg->cdsgeneprot_to, to_field);
12332           to_field = FieldTypeFree (to_field);
12333         }
12334         dlg->field_type = FieldType_cds_gene_prot;
12335         break;
12336       case FieldPairType_molinfo_field:
12337         SafeShow (dlg->molinfo_dlg);
12338         PointerToDialog (dlg->molinfo_dlg, vnp->data.ptrvalue);
12339         dlg->field_type = FieldPairType_molinfo_field;
12340         break;
12341       case FieldPairType_rna_field:
12342         SafeShow (dlg->rna_grp);
12343         rna_quals = (RnaQualPairPtr) vnp->data.ptrvalue;
12344         if (rna_quals == NULL) {
12345           PointerToDialog (dlg->rna_feat_dlg, NULL);
12346           PointerToDialog (dlg->rna_field_from, NULL);
12347           PointerToDialog (dlg->rna_field_to, NULL);
12348         } else {
12349           PointerToDialog (dlg->rna_feat_dlg, rna_quals->type);
12350           vn.choice = (Uint1)rna_quals->field_from;
12351           vn.data.ptrvalue = NULL;
12352           vn.next = NULL;
12353           PointerToDialog (dlg->rna_field_from, &vn);
12354           vn.choice = (Uint1)rna_quals->field_to;
12355           PointerToDialog (dlg->rna_field_to, &vn);
12356         }
12357         dlg->field_type = FieldPairType_rna_field;
12358         break;
12359       case FieldPairType_dblink:
12360         SafeShow (dlg->dblink_grp);
12361         dblink = (DBLinkFieldPairPtr) vnp->data.ptrvalue;
12362         if (dblink == NULL) {
12363           SetValue (dlg->dblink_field_from, 1);
12364           SetValue (dlg->dblink_field_to, 1);
12365         } else {
12366           SetValue (dlg->dblink_field_from, dblink->from);
12367           SetValue (dlg->dblink_field_to, dblink->to);
12368         }
12369         dlg->field_type = FieldPairType_dblink;
12370         break;
12371     }
12372   }
12373 }
12374 
12375 
DialogToFieldPairType(DialoG d)12376 static Pointer DialogToFieldPairType (DialoG d)
12377 {
12378   FieldPairTypeDlgPtr dlg;
12379   ValNodePtr vnp = NULL, vnp1, vnp2;
12380   SourceQualPairPtr sqp;
12381   FeatureFieldPairPtr ffp;
12382   CDSGeneProtFieldPairPtr cgp;
12383   RnaQualPairPtr          rna_quals;
12384   DBLinkFieldPairPtr dblink;
12385 
12386   dlg = (FieldPairTypeDlgPtr) GetObjectExtra (d);
12387   if (dlg == NULL) return NULL;
12388 
12389   switch (dlg->field_type) {
12390     case FieldPairType_source_qual:
12391       vnp1 = DialogToPointer (dlg->src_qual_from);
12392       vnp2 = DialogToPointer (dlg->src_qual_to);
12393       if (vnp1 != NULL || vnp2 != NULL) {
12394         sqp = SourceQualPairNew ();
12395         if (vnp1 != NULL) {
12396           sqp->field_from = vnp1->data.intvalue;
12397         }
12398         if (vnp2 != NULL) {
12399           sqp->field_to = vnp2->data.intvalue;
12400         }
12401         vnp = ValNodeNew (NULL);
12402         vnp->choice = FieldPairType_source_qual;
12403         vnp->data.ptrvalue = sqp;
12404       }
12405       vnp1 = SourceQualChoiceFree (vnp1);
12406       vnp2 = SourceQualChoiceFree (vnp2);
12407       break;
12408     case FieldPairType_feature_field:
12409       vnp2 = (ValNodePtr) DialogToPointer (dlg->feature_type);
12410       if (vnp2 != NULL) {
12411         ffp = FeatureFieldPairNew ();
12412         ffp->type = vnp2->choice;
12413         vnp2 = ValNodeFree (vnp2);
12414         ffp->field_from = DialogToPointer (dlg->feature_field_from);
12415         ffp->field_to = DialogToPointer (dlg->feature_field_to);
12416         vnp = ValNodeNew (NULL);
12417         vnp->choice = FieldPairType_feature_field;
12418         vnp->data.ptrvalue = ffp;
12419       }
12420       break;
12421     case FieldPairType_cds_gene_prot:
12422       vnp1 = DialogToPointer (dlg->cdsgeneprot_from);
12423       vnp2 = DialogToPointer (dlg->cdsgeneprot_to);
12424       if (vnp1 != NULL || vnp2 != NULL) {
12425         cgp = CDSGeneProtFieldPairNew ();
12426         if (vnp1 != NULL) {
12427           cgp->field_from = vnp1->data.intvalue;
12428         }
12429         if (vnp2 != NULL) {
12430           cgp->field_to = vnp2->data.intvalue;
12431         }
12432         vnp = ValNodeNew (NULL);
12433         vnp->choice = FieldPairType_cds_gene_prot;
12434         vnp->data.ptrvalue = cgp;
12435       }
12436       vnp1 = ValNodeFree (vnp1);
12437       vnp2 = ValNodeFree (vnp2);
12438       break;
12439     case FieldPairType_molinfo_field:
12440       vnp1 = DialogToPointer (dlg->molinfo_dlg);
12441       if (vnp1 != NULL) {
12442         vnp = ValNodeNew (NULL);
12443         vnp->choice = FieldPairType_molinfo_field;
12444         vnp->data.ptrvalue = vnp1;
12445       }
12446       break;
12447     case FieldPairType_rna_field:
12448       rna_quals = RnaQualPairNew ();
12449       rna_quals->type = DialogToPointer (dlg->rna_feat_dlg);
12450       vnp1 = DialogToPointer (dlg->rna_field_from);
12451       if (vnp1 != NULL) {
12452         rna_quals->field_from = vnp1->choice;
12453         vnp1 = ValNodeFree (vnp1);
12454       }
12455       vnp1 = DialogToPointer (dlg->rna_field_to);
12456       if (vnp1 != NULL) {
12457         rna_quals->field_to = vnp1->choice;
12458         vnp1 = ValNodeFree (vnp1);
12459       }
12460       vnp = ValNodeNew (NULL);
12461       vnp->choice = FieldPairType_rna_field;
12462       vnp->data.ptrvalue = rna_quals;
12463       break;
12464     case FieldPairType_dblink:
12465       dblink = DBLinkFieldPairNew ();
12466       dblink->from = GetValue (dlg->dblink_field_from);
12467       dblink->to = GetValue (dlg->dblink_field_to);
12468       vnp = ValNodeNew (NULL);
12469       vnp->choice = FieldPairType_dblink;
12470       vnp->data.ptrvalue = dblink;
12471       break;
12472   }
12473 
12474   return vnp;
12475 }
12476 
12477 
TestFieldPairTypeDialog(DialoG d)12478 static ValNodePtr TestFieldPairTypeDialog (DialoG d)
12479 {
12480   FieldPairTypeDlgPtr dlg;
12481   ValNodePtr err_list = NULL;
12482 
12483   dlg = (FieldPairTypeDlgPtr) GetObjectExtra (d);
12484   if (dlg == NULL) {
12485     return NULL;
12486   }
12487 
12488   switch (dlg->field_type) {
12489     case FieldPairType_source_qual:
12490       err_list = TestDialog (dlg->src_qual_from);
12491       ValNodeLink (&err_list, TestDialog (dlg->src_qual_to));
12492       break;
12493     case FieldPairType_feature_field:
12494       err_list = TestDialog (dlg->feature_type);
12495       ValNodeLink (&err_list, TestDialog (dlg->feature_field_from));
12496       ValNodeLink (&err_list, TestDialog (dlg->feature_field_to));
12497       break;
12498     case FieldPairType_cds_gene_prot:
12499       ValNodeLink (&err_list, TestDialog (dlg->cdsgeneprot_from));
12500       ValNodeLink (&err_list, TestDialog (dlg->cdsgeneprot_to));
12501       break;
12502     case FieldPairType_molinfo_field:
12503       ValNodeLink (&err_list, TestDialog (dlg->molinfo_dlg));
12504       break;
12505     case FieldPairType_rna_field:
12506       ValNodeLink (&err_list, TestDialog (dlg->rna_feat_dlg));
12507       ValNodeLink (&err_list, TestDialog (dlg->rna_field_from));
12508       ValNodeLink (&err_list, TestDialog (dlg->rna_field_to));
12509       break;
12510     case FieldPairType_dblink:
12511       break;
12512     default:
12513       ValNodeAddPointer (&err_list, 0, "No field type");
12514       break;
12515   }
12516   return err_list;
12517 }
12518 
12519 
ChangeFieldPairTypeDialogPopup(PopuP p)12520 static void ChangeFieldPairTypeDialogPopup (PopuP p)
12521 {
12522   FieldPairTypeDlgPtr dlg;
12523 
12524   dlg = (FieldPairTypeDlgPtr) GetObjectExtra (p);
12525   if (dlg == NULL) {
12526     return;
12527   }
12528 
12529   if (dlg->change_notify != NULL) {
12530     (dlg->change_notify)(dlg->change_userdata);
12531   }
12532 }
12533 
12534 
12535 
FieldPairTypeDialog(GrouP h,Boolean for_convert,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)12536 static DialoG FieldPairTypeDialog (GrouP h, Boolean for_convert, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
12537 {
12538   FieldPairTypeDlgPtr dlg;
12539   GrouP               p, g;
12540   ValNodePtr          field_list;
12541 
12542   dlg = (FieldPairTypeDlgPtr) MemNew (sizeof (FieldPairTypeDlgData));
12543   if (dlg == NULL)
12544   {
12545     return NULL;
12546   }
12547 
12548   p = HiddenGroup (h, 0, 0, NULL);
12549   SetObjectExtra (p, dlg, StdCleanupExtraProc);
12550 
12551   dlg->dialog = (DialoG) p;
12552   dlg->todialog = FieldPairTypeToDialog;
12553   dlg->fromdialog = DialogToFieldPairType;
12554   dlg->testdialog = TestFieldPairTypeDialog;
12555   dlg->change_notify = change_notify;
12556   dlg->change_userdata = change_userdata;
12557 
12558   dlg->src_qual_grp = HiddenGroup (p, 2, 0, NULL);
12559   StaticPrompt (dlg->src_qual_grp, "From", 0, dialogTextHeight, programFont, 'l');
12560   StaticPrompt (dlg->src_qual_grp, "To", 0, dialogTextHeight, programFont, 'l');
12561   dlg->src_qual_from = SourceQualChoiceDialog (dlg->src_qual_grp, TRUE, FALSE, TRUE, change_notify, change_userdata);
12562   dlg->src_qual_to = SourceQualChoiceDialog (dlg->src_qual_grp, TRUE, FALSE, TRUE, change_notify, change_userdata);
12563 
12564   dlg->feature_field_grp = HiddenGroup (p, 3, 0, NULL);
12565   StaticPrompt (dlg->feature_field_grp, "Feature Type", 0, dialogTextHeight, programFont, 'l');
12566   StaticPrompt (dlg->feature_field_grp, "From", 0, dialogTextHeight, programFont, 'l');
12567   StaticPrompt (dlg->feature_field_grp, "To", 0, dialogTextHeight, programFont, 'l');
12568   dlg->feature_type = FeatureTypeDialogMulti (dlg->feature_field_grp, change_notify, change_userdata);
12569   dlg->feature_field_from = FeatQualChoiceDialog (dlg->feature_field_grp, FALSE, change_notify, change_userdata);
12570   dlg->feature_field_to = FeatQualChoiceDialog (dlg->feature_field_grp, FALSE, change_notify, change_userdata);
12571 
12572   dlg->cdsgeneprot_grp = HiddenGroup (p, 2, 0, NULL);
12573   StaticPrompt (dlg->cdsgeneprot_grp, "From", 0, dialogTextHeight, programFont, 'l');
12574   StaticPrompt (dlg->cdsgeneprot_grp, "To", 0, dialogTextHeight, programFont, 'l');
12575   dlg->cdsgeneprot_from = CDSGeneProtFieldDialog (dlg->cdsgeneprot_grp, change_notify, change_userdata);
12576   dlg->cdsgeneprot_to = CDSGeneProtFieldDialog (dlg->cdsgeneprot_grp, change_notify, change_userdata);
12577 
12578   if (for_convert) {
12579     dlg->molinfo_dlg = SequenceQualPairDialog (p, change_notify, change_userdata);
12580   }
12581 
12582   dlg->rna_grp = HiddenGroup (p, -1, 0, NULL);
12583   StaticPrompt (dlg->rna_grp, "RNA Type", 0, dialogTextHeight, programFont, 'l');
12584   dlg->rna_feat_dlg = RnaFeatureTypeDialog (dlg->rna_grp, "RNA Type of Feature to be Edited", TRUE, change_notify, change_userdata);
12585   g = HiddenGroup (dlg->rna_grp, 2, 0, NULL);
12586   StaticPrompt (g, "From RNA Field", 0, dialogTextHeight, programFont, 'l');
12587   StaticPrompt (g, "To RNA Field", 0, dialogTextHeight, programFont, 'l');
12588   field_list = GetRnaFieldList ();
12589   dlg->rna_field_from = ValNodeSelectionDialog (g, field_list, SHORT_SELECTION_LIST, ValNodeStringName,
12590                                 ValNodeSimpleDataFree, ValNodeStringCopy,
12591                                 ValNodeChoiceMatch, "field type",
12592                                 change_notify, change_userdata, FALSE);
12593   field_list = GetRnaFieldList ();
12594   dlg->rna_field_to = ValNodeSelectionDialog (g, field_list, SHORT_SELECTION_LIST, ValNodeStringName,
12595                                 ValNodeSimpleDataFree, ValNodeStringCopy,
12596                                 ValNodeChoiceMatch, "field type",
12597                                 change_notify, change_userdata, FALSE);
12598   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->rna_feat_dlg, (HANDLE) g, NULL);
12599 
12600   dlg->dblink_grp = HiddenGroup (p, 2, 0, NULL);
12601   StaticPrompt (dlg->dblink_grp, "From", 0, dialogTextHeight, programFont, 'l');
12602   StaticPrompt (dlg->dblink_grp, "To", 0, dialogTextHeight, programFont, 'l');
12603   dlg->dblink_field_from = MakeDbLinkFieldPopup (dlg->dblink_grp, ChangeFieldPairTypeDialogPopup, dlg);
12604   dlg->dblink_field_to = MakeDbLinkFieldPopup (dlg->dblink_grp, ChangeFieldPairTypeDialogPopup, dlg);
12605 
12606   SafeHide (dlg->src_qual_grp);
12607   SafeHide (dlg->feature_field_grp);
12608   SafeHide (dlg->cdsgeneprot_grp);
12609   SafeHide (dlg->molinfo_dlg);
12610   SafeHide (dlg->rna_grp);
12611   SafeHide (dlg->dblink_grp);
12612 
12613   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->src_qual_grp,
12614                               (HANDLE) dlg->feature_field_grp,
12615                               (HANDLE) dlg->cdsgeneprot_grp,
12616                               (HANDLE) dlg->molinfo_dlg,
12617                               (HANDLE) dlg->rna_grp,
12618                               (HANDLE) dlg->dblink_grp,
12619                               NULL);
12620 
12621   return (DialoG) p;
12622 }
12623 
12624 
12625 typedef struct singlefielddlg {
12626   DIALOG_MESSAGE_BLOCK
12627 
12628   DialoG field_type;
12629   DialoG field;
12630 
12631   Nlm_ChangeNotifyProc change_notify;
12632   Pointer change_userdata;
12633 } SingleFieldDlgData, PNTR SingleFieldDlgPtr;
12634 
12635 
SingleFieldTypeToDialog(DialoG d,Pointer data)12636 static void SingleFieldTypeToDialog (DialoG d, Pointer data)
12637 {
12638   SingleFieldDlgPtr dlg;
12639   ValNodePtr field;
12640   ValNode vn;
12641 
12642   dlg = (SingleFieldDlgPtr) GetObjectExtra (d);
12643   if (dlg == NULL) {
12644     return;
12645   }
12646 
12647   MemSet (&vn, 0, sizeof (ValNode));
12648   field = (ValNodePtr) data;
12649   if (field == NULL) {
12650     vn.choice = FieldType_source_qual;
12651     PointerToDialog (dlg->field_type, &vn);
12652     PointerToDialog (dlg->field, &vn);
12653   } else {
12654     PointerToDialog (dlg->field_type, field);
12655     PointerToDialog (dlg->field, field);
12656   }
12657 
12658 }
12659 
12660 
DialogToSingleFieldType(DialoG d)12661 static Pointer DialogToSingleFieldType (DialoG d)
12662 {
12663   SingleFieldDlgPtr dlg;
12664 
12665   dlg = (SingleFieldDlgPtr) GetObjectExtra (d);
12666   if (dlg == NULL) {
12667     return NULL;
12668   }
12669 
12670   return DialogToPointer (dlg->field);
12671 }
12672 
12673 
TestSingleFieldTypeDialog(DialoG d)12674 static ValNodePtr TestSingleFieldTypeDialog (DialoG d)
12675 {
12676   SingleFieldDlgPtr dlg;
12677 
12678   dlg = (SingleFieldDlgPtr) GetObjectExtra (d);
12679   if (dlg == NULL) {
12680     return NULL;
12681   }
12682 
12683   return TestDialog (dlg->field);
12684 }
12685 
12686 
ChangeSingleFieldType(Pointer data)12687 static void ChangeSingleFieldType (Pointer data)
12688 {
12689   SingleFieldDlgPtr dlg;
12690   ValNodePtr vnp;
12691 
12692   if ((dlg = (SingleFieldDlgPtr) data) == NULL) {
12693     return;
12694   }
12695   vnp = DialogToPointer (dlg->field_type);
12696   vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
12697   PointerToDialog (dlg->field, vnp);
12698   vnp = FieldTypeFree (vnp);
12699 
12700 }
12701 
12702 
SingleFieldTypeDialog(GrouP h,Boolean text_only,Boolean for_remove,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)12703 static DialoG SingleFieldTypeDialog (GrouP h, Boolean text_only, Boolean for_remove, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
12704 {
12705   SingleFieldDlgPtr dlg;
12706   GrouP             p;
12707   ValNodePtr        val_list = NULL;
12708 
12709   dlg = (SingleFieldDlgPtr) MemNew (sizeof (SingleFieldDlgData));
12710   if (dlg == NULL)
12711   {
12712     return NULL;
12713   }
12714 
12715   p = HiddenGroup (h, -1, 0, NULL);
12716   SetObjectExtra (p, dlg, StdCleanupExtraProc);
12717 
12718   dlg->dialog = (DialoG) p;
12719   dlg->todialog = SingleFieldTypeToDialog;
12720   dlg->fromdialog = DialogToSingleFieldType;
12721   dlg->testdialog = TestSingleFieldTypeDialog;
12722   dlg->change_notify = change_notify;
12723   dlg->change_userdata = change_userdata;
12724 
12725 
12726   ValNodeAddPointer (&val_list, FieldType_source_qual, StringSave ("Source Qual"));
12727   ValNodeAddPointer (&val_list, FieldType_feature_field, StringSave ("Feature Qual"));
12728   ValNodeAddPointer (&val_list, FieldType_cds_gene_prot, StringSave ("CDS-Gene-Prot Qual"));
12729   ValNodeAddPointer (&val_list, FieldType_rna_field, StringSave ("RNA Qual"));
12730   ValNodeAddPointer (&val_list, FieldType_molinfo_field, StringSave ("MolInfo Qual"));
12731   ValNodeAddPointer (&val_list, FieldType_pub, StringSave ("Pub Field"));
12732   ValNodeAddPointer (&val_list, FieldType_struc_comment_field, StringSave ("Structured Comment Field"));
12733   ValNodeAddPointer (&val_list, FieldType_misc, StringSave ("Misc"));
12734   ValNodeAddPointer (&val_list, FieldType_dblink, StringSave ("DBLink"));
12735 
12736   dlg->field_type = ValNodeSelectionDialog (p, val_list, TALL_SELECTION_LIST, ValNodeStringName,
12737                                 ValNodeSimpleDataFree, ValNodeStringCopy,
12738                                 ValNodeChoiceMatch, "field type",
12739                                 ChangeSingleFieldType, dlg, FALSE);
12740   val_list = NULL;
12741   dlg->field = FieldTypeDialog (p, FALSE, FALSE, change_notify, change_userdata);
12742   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->field_type, dlg->field, NULL);
12743   return (DialoG) p;
12744 }
12745 
12746 
12747 #define AECR_DLG_BLOCK       \
12748   DIALOG_MESSAGE_BLOCK \
12749   DialoG qual_type_dlg; \
12750   DialoG field_dlg; \
12751   ButtoN autopopulate_btn; \
12752   Nlm_ChangeNotifyProc     autopopulate; \
12753   Pointer                  autopopulate_data; \
12754   Nlm_ChangeNotifyProc     change_notify; \
12755   Pointer                  change_userdata; \
12756   Nlm_ChangeNotifyProc     redraw_notify; \
12757   Pointer                  redraw_userdata;
12758 
12759 typedef struct aecractiondlg {
12760   AECR_DLG_BLOCK
12761 } AECRActionDlgData, PNTR AECRActionDlgPtr;
12762 
12763 
SetAECRActionDlgFieldTypeDialogs(DialoG d,DialoG qual_type_dlg,DialoG field_dlg)12764 static void SetAECRActionDlgFieldTypeDialogs (DialoG d, DialoG qual_type_dlg, DialoG field_dlg)
12765 {
12766   AECRActionDlgPtr dlg;
12767 
12768   dlg = (AECRActionDlgPtr) GetObjectExtra (d);
12769   if (dlg != NULL) {
12770     dlg->qual_type_dlg = qual_type_dlg;
12771     dlg->field_dlg = field_dlg;
12772   }
12773 }
12774 
12775 
FieldTypeChoiceFromAECRActionDlg(DialoG d)12776 static Uint1 FieldTypeChoiceFromAECRActionDlg (DialoG d)
12777 {
12778   AECRActionDlgPtr dlg;
12779   ValNodePtr       vnp;
12780   Uint1            rval = FieldType_source_qual;
12781 
12782   dlg = (AECRActionDlgPtr) GetObjectExtra (d);
12783   if (dlg != NULL) {
12784     vnp = DialogToPointer (dlg->qual_type_dlg);
12785     if (vnp != NULL) {
12786       rval = vnp->choice;
12787       vnp = ValNodeFree (vnp);
12788     }
12789   }
12790   return rval;
12791 }
12792 
12793 
SingleFieldToAECRActionDlg(DialoG d,ValNodePtr field)12794 static void SingleFieldToAECRActionDlg (DialoG d, ValNodePtr field)
12795 {
12796   AECRActionDlgPtr dlg;
12797   ValNode          vn;
12798 
12799   dlg = (AECRActionDlgPtr) GetObjectExtra (d);
12800   if (dlg != NULL) {
12801     if (field == NULL) {
12802       PointerToDialog (dlg->qual_type_dlg, NULL);
12803     } else {
12804       vn.choice = field->choice;
12805       vn.data.ptrvalue = NULL;
12806       vn.next = NULL;
12807       PointerToDialog (dlg->qual_type_dlg, &vn);
12808     }
12809     PointerToDialog (dlg->field_dlg, field);
12810   }
12811 }
12812 
12813 
FieldPairToAECRActionDlg(DialoG d,ValNodePtr fields)12814 static void FieldPairToAECRActionDlg (DialoG d, ValNodePtr fields)
12815 {
12816   AECRActionDlgPtr dlg;
12817   ValNode          vn;
12818 
12819   dlg = (AECRActionDlgPtr) GetObjectExtra (d);
12820   if (dlg != NULL) {
12821     if (fields == NULL) {
12822       PointerToDialog (dlg->qual_type_dlg, NULL);
12823     } else {
12824       vn.choice = FieldTypeChoiceFromFieldPairTypeChoice (fields->choice);
12825       vn.data.ptrvalue = NULL;
12826       vn.next = NULL;
12827       PointerToDialog (dlg->qual_type_dlg, &vn);
12828     }
12829     PointerToDialog (dlg->field_dlg, fields);
12830   }
12831 }
12832 
12833 
GetAutopopulateStatus(DialoG d)12834 static Boolean GetAutopopulateStatus (DialoG d)
12835 {
12836   AECRActionDlgPtr dlg;
12837 
12838   dlg = (AECRActionDlgPtr) GetObjectExtra (d);
12839   if (dlg == NULL || dlg->autopopulate_btn == NULL) {
12840     return FALSE;
12841   } else {
12842     return GetStatus (dlg->autopopulate_btn);
12843   }
12844 }
12845 
12846 
SetAutopopulateStatus(DialoG d,Boolean status)12847 static void SetAutopopulateStatus (DialoG d, Boolean status)
12848 {
12849   AECRActionDlgPtr dlg;
12850 
12851   dlg = (AECRActionDlgPtr) GetObjectExtra (d);
12852   if (dlg == NULL || dlg->autopopulate_btn == NULL) {
12853     return;
12854   } else {
12855     SetStatus (dlg->autopopulate_btn, status);
12856   }
12857 }
12858 
12859 
ChangeAutopopulateStatus(ButtoN b)12860 static void ChangeAutopopulateStatus (ButtoN b)
12861 {
12862   AECRActionDlgPtr dlg;
12863 
12864   dlg = (AECRActionDlgPtr) GetObjectExtra (b);
12865   if (dlg != NULL) {
12866     SetAppParam ("SEQUINCUSTOM", "BATCHDIALOG", "AUTOPOPULATE", GetStatus (b) ? "TRUE" : "FALSE");
12867     if (dlg->autopopulate) {
12868       (dlg->autopopulate)(dlg->autopopulate_data);
12869     }
12870   }
12871 }
12872 
12873 
IsFieldPubAuthors(ValNodePtr field)12874 static Boolean IsFieldPubAuthors (ValNodePtr field)
12875 {
12876   if (field == NULL) {
12877     return FALSE;
12878   } else if (field->choice != FieldType_pub) {
12879     return FALSE;
12880   } else if (field->data.intvalue == Publication_field_authors) {
12881     return TRUE;
12882   } else {
12883     return FALSE;
12884   }
12885 }
12886 
12887 
12888 typedef struct applyactiondlg {
12889   AECR_DLG_BLOCK
12890 
12891   TexT   value_txt;
12892   DialoG author_dlg;
12893   DialoG existing_text;
12894 } ApplyActionDlgData, PNTR ApplyActionDlgPtr;
12895 
12896 
DialogToApplyAction(DialoG d)12897 static Pointer DialogToApplyAction (DialoG d)
12898 {
12899   ApplyActionDlgPtr dlg;
12900   ApplyActionPtr     apply;
12901   AuthListPtr        alp;
12902 
12903   dlg = (ApplyActionDlgPtr) GetObjectExtra (d);
12904   if (dlg == NULL) return NULL;
12905 
12906   apply = ApplyActionNew();
12907   apply->field = DialogToPointer (dlg->field_dlg);
12908   if (apply->field == NULL) {
12909     ValNodeAddPointer (&apply->field, FieldTypeChoiceFromAECRActionDlg(d), NULL);
12910   }
12911 
12912   if (IsFieldPubAuthors (apply->field)) {
12913     alp = DialogToPointer (dlg->author_dlg);
12914     apply->value = GetAuthorListString (alp, NULL);
12915     alp = AuthListFree (alp);
12916   } else if (IsFieldTypeNonText (apply->field)) {
12917     apply->value = StringSave ("TRUE");
12918   } else {
12919     apply->value = SaveStringFromText (dlg->value_txt);
12920   }
12921   apply->existing_text = GetExistingTextDialogValue (dlg->existing_text);
12922   return (Pointer) apply;
12923 }
12924 
12925 
ApplyActionToDialog(DialoG d,Pointer data)12926 static void ApplyActionToDialog (DialoG d, Pointer data)
12927 {
12928   ApplyActionDlgPtr dlg;
12929   ApplyActionPtr    apply;
12930   AuthListPtr       alp;
12931 
12932   dlg = (ApplyActionDlgPtr) GetObjectExtra (d);
12933   if (dlg == NULL) return;
12934   apply = (ApplyActionPtr) data;
12935 
12936   if (apply == NULL) {
12937     SingleFieldToAECRActionDlg (d, NULL);
12938     SetTitle (dlg->value_txt, "");
12939     SetExistingTextDialogValue(dlg->existing_text, 0);
12940     Show (dlg->value_txt);
12941     Hide (dlg->author_dlg);
12942   } else {
12943     SingleFieldToAECRActionDlg (d, apply->field);
12944     if (IsFieldPubAuthors(apply->field)) {
12945       alp = AuthListNew ();
12946       alp->choice = 1;
12947       alp->names = ReadNameListFromString (apply->value);
12948       PointerToDialog (dlg->author_dlg, alp);
12949       alp = AuthListFree (alp);
12950       Show (dlg->author_dlg);
12951       Hide (dlg->value_txt);
12952     } else {
12953       SetTitle (dlg->value_txt, apply->value);
12954       Show (dlg->value_txt);
12955       Hide (dlg->author_dlg);
12956     }
12957     SetExistingTextDialogValue(dlg->existing_text, apply->existing_text);
12958   }
12959 }
12960 
12961 
TestApplyActionDialog(DialoG d)12962 static ValNodePtr TestApplyActionDialog (DialoG d)
12963 {
12964   ApplyActionDlgPtr dlg;
12965   Int2 field_type = 0;
12966   ValNodePtr err_list = NULL;
12967   ValNodePtr field, vnp;
12968   Boolean    field_is_nontext = FALSE;
12969   Boolean    field_is_authors = FALSE;
12970   AuthListPtr alp;
12971 
12972   dlg = (ApplyActionDlgPtr) GetObjectExtra (d);
12973   if (dlg == NULL) return NULL;
12974 
12975   err_list = TestDialog (dlg->qual_type_dlg);
12976   vnp = DialogToPointer (dlg->qual_type_dlg);
12977   if (vnp != NULL) {
12978     field_type = vnp->choice;
12979     vnp = ValNodeFree (vnp);
12980   }
12981 
12982   ValNodeLink (&err_list, TestDialog (dlg->field_dlg));
12983   ValNodeLink (&err_list, TestDialog (dlg->existing_text));
12984 
12985   field = DialogToPointer (dlg->field_dlg);
12986   field_is_nontext = IsFieldTypeNonText (field);
12987   field_is_authors = IsFieldPubAuthors (field);
12988   field = FieldTypeFree (field);
12989 
12990   if (field_is_authors) {
12991     alp = DialogToPointer (dlg->author_dlg);
12992     if (alp == NULL || alp->names == NULL) {
12993       ValNodeAddPointer (&err_list, 0, "no authors");
12994     }
12995     alp = AuthListFree (alp);
12996   } else if (TextHasNoText (dlg->value_txt) && !field_is_nontext) {
12997     ValNodeAddPointer (&err_list, 0, "no apply text");
12998   }
12999   return err_list;
13000 }
13001 
13002 
ChangeDialogForApplyFieldChoice(DialoG d)13003 static void ChangeDialogForApplyFieldChoice (DialoG d)
13004 {
13005   ValNodePtr field;
13006   ApplyActionDlgPtr dlg;
13007 
13008   dlg = (ApplyActionDlgPtr) GetObjectExtra (d);
13009   if (dlg == NULL) return;
13010   field = DialogToPointer (dlg->field_dlg);
13011   if (IsFieldPubAuthors (field)) {
13012     Show (dlg->author_dlg);
13013     EnableNonTextOptions (dlg->existing_text);
13014     Hide (dlg->value_txt);
13015   } else if (IsFieldTypeNonText (field)) {
13016     DisableNonTextOptions (dlg->existing_text);
13017     Hide (dlg->value_txt);
13018     Hide (dlg->author_dlg);
13019   } else {
13020     EnableNonTextOptions (dlg->existing_text);
13021     Show (dlg->value_txt);
13022     Hide (dlg->author_dlg);
13023   }
13024   if (AllowFieldMulti (field)) {
13025     EnableMultiOptions (dlg->existing_text);
13026   } else {
13027     DisableMultiOptions (dlg->existing_text);
13028   }
13029   field = FieldTypeFree (field);
13030 }
13031 
13032 
ChangeApplyActionDialogText(TexT t)13033 static void ChangeApplyActionDialogText (TexT t)
13034 {
13035   ApplyActionDlgPtr dlg;
13036 
13037   dlg = (ApplyActionDlgPtr) GetObjectExtra (t);
13038   if (dlg != NULL && dlg->change_notify != NULL) {
13039     (dlg->change_notify)(dlg->change_userdata);
13040   }
13041 }
13042 
SetApplyActionDialogText(DialoG d,CharPtr str)13043 static void SetApplyActionDialogText (DialoG d, CharPtr str)
13044 {
13045   ApplyActionDlgPtr dlg;
13046   FieldTypePtr      field;
13047   AuthListPtr       alp;
13048 
13049   dlg = (ApplyActionDlgPtr) GetObjectExtra (d);
13050   if (dlg != NULL) {
13051     field = DialogToPointer (dlg->field_dlg);
13052     if (IsFieldPubAuthors (field)) {
13053       alp = AuthListNew ();
13054       alp->choice = 1;
13055       alp->names = ReadNameListFromString(str);
13056       PointerToDialog (dlg->author_dlg, alp);
13057       alp = AuthListFree (alp);
13058     } else {
13059       SetTitle (dlg->value_txt, str);
13060     }
13061     field = FieldTypeFree (field);
13062   }
13063 }
13064 
13065 
13066 static DialoG
ApplyActionDialog(GrouP h,Boolean indexer_version,Boolean show_existing_text,Nlm_ChangeNotifyProc autopopulate,Pointer autopopulate_data,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Nlm_ChangeNotifyProc redraw_notify,Pointer redraw_userdata)13067 ApplyActionDialog
13068 (GrouP h,
13069  Boolean indexer_version,
13070  Boolean show_existing_text,
13071  Nlm_ChangeNotifyProc     autopopulate,
13072  Pointer                  autopopulate_data,
13073  Nlm_ChangeNotifyProc     change_notify,
13074  Pointer                  change_userdata,
13075  Nlm_ChangeNotifyProc     redraw_notify,
13076  Pointer                  redraw_userdata)
13077 {
13078   ApplyActionDlgPtr     dlg;
13079   GrouP                 p, val_grp;
13080 
13081   dlg = (ApplyActionDlgPtr) MemNew (sizeof (ApplyActionDlgData));
13082 
13083   p = HiddenGroup (h, -1, 0, NULL);
13084   SetObjectExtra (p, dlg, StdCleanupExtraProc);
13085   dlg->dialog = (DialoG) p;
13086   dlg->todialog = ApplyActionToDialog;
13087   dlg->fromdialog = DialogToApplyAction;
13088   dlg->testdialog = TestApplyActionDialog;
13089   dlg->autopopulate = autopopulate;
13090   dlg->autopopulate_data = autopopulate_data;
13091   dlg->change_notify = change_notify;
13092   dlg->change_userdata = change_userdata;
13093   dlg->redraw_notify = redraw_notify;
13094   dlg->redraw_userdata = redraw_userdata;
13095 
13096   if (dlg->autopopulate != NULL) {
13097     dlg->autopopulate_btn = CheckBox (p, "Autopopulate", ChangeAutopopulateStatus);
13098     SetObjectExtra (dlg->autopopulate_btn, dlg, NULL);
13099   }
13100 
13101   val_grp = HiddenGroup (p, 0, 0, NULL);
13102   dlg->value_txt = DialogText (val_grp, "", 20, ChangeApplyActionDialogText);
13103   SetObjectExtra (dlg->value_txt, dlg, NULL);
13104   dlg->author_dlg = CreateAuthorDialogEx(val_grp, 3, 2, TRUE, change_notify, change_userdata);
13105 
13106   if (show_existing_text) {
13107     dlg->existing_text = ExistingTextDialog (p, change_notify, change_userdata);
13108   } else {
13109     dlg->existing_text = NULL;
13110   }
13111   if (dlg->autopopulate == NULL) {
13112     AlignObjects (ALIGN_CENTER, (HANDLE) val_grp,
13113                                 (HANDLE) dlg->existing_text,
13114                                 NULL);
13115   } else {
13116     AlignObjects (ALIGN_CENTER, (HANDLE) dlg->autopopulate_btn,
13117                                 (HANDLE) val_grp,
13118                                 (HANDLE) dlg->existing_text,
13119                                 NULL);
13120   }
13121   ChangeDialogForApplyFieldChoice ((DialoG) p);
13122   return (DialoG) p;
13123 }
13124 
13125 
13126 typedef struct editactiondlg {
13127   AECR_DLG_BLOCK
13128 
13129   DialoG edit;
13130 } EditActionDlgData, PNTR EditActionDlgPtr;
13131 
13132 
PointerToEditActionDlg(DialoG d,Pointer data)13133 static void PointerToEditActionDlg (DialoG d, Pointer data)
13134 {
13135   EditActionDlgPtr dlg;
13136   EditActionPtr    edit;
13137 
13138   dlg = (EditActionDlgPtr) GetObjectExtra (d);
13139   if (dlg == NULL) return;
13140   edit = (EditActionPtr) data;
13141 
13142   if (edit == NULL) {
13143     SingleFieldToAECRActionDlg (d, NULL);
13144     PointerToDialog (dlg->edit, NULL);
13145   } else {
13146     SingleFieldToAECRActionDlg (d, edit->field);
13147     PointerToDialog (dlg->edit, edit->edit);
13148   }
13149 }
13150 
13151 
DialogToEditAction(DialoG d)13152 static Pointer DialogToEditAction (DialoG d)
13153 {
13154   EditActionDlgPtr dlg;
13155   EditActionPtr      edit;
13156 
13157   dlg = (EditActionDlgPtr) GetObjectExtra (d);
13158   if (dlg == NULL) return NULL;
13159 
13160   edit = EditActionNew ();
13161   edit->field = DialogToPointer (dlg->field_dlg);
13162   edit->edit = DialogToPointer (dlg->edit);
13163   return edit;
13164 }
13165 
13166 
TestEditActionDialog(DialoG d)13167 static ValNodePtr TestEditActionDialog (DialoG d)
13168 {
13169   EditActionDlgPtr dlg;
13170   Int2 field_type = 0;
13171   ValNodePtr err_list = NULL;
13172   ValNodePtr field, vnp;
13173   Boolean    field_is_nontext = FALSE;
13174 
13175   dlg = (EditActionDlgPtr) GetObjectExtra (d);
13176   if (dlg == NULL) return NULL;
13177 
13178   err_list = TestDialog (dlg->qual_type_dlg);
13179   vnp = DialogToPointer (dlg->qual_type_dlg);
13180   if (vnp != NULL) {
13181     field_type = vnp->choice;
13182     vnp = ValNodeFree (vnp);
13183   }
13184 
13185   ValNodeLink (&err_list, TestDialog (dlg->field_dlg));
13186 
13187   field = DialogToPointer (dlg->field_dlg);
13188   field_is_nontext = IsFieldTypeNonText (field);
13189   field = FieldTypeFree (field);
13190 
13191   if (field_is_nontext) {
13192     ValNodeAddPointer (&err_list, 0, "invalid action for field type");
13193   }
13194   ValNodeLink (&err_list, TestDialog (dlg->edit));
13195   return err_list;
13196 }
13197 
13198 
SetEditActionDialogText(DialoG d,CharPtr str_find,CharPtr str_repl)13199 static void SetEditActionDialogText (DialoG d, CharPtr str_find, CharPtr str_repl)
13200 {
13201   EditActionDlgPtr dlg;
13202 
13203   dlg = (EditActionDlgPtr) GetObjectExtra (d);
13204   if (dlg != NULL) {
13205     SetFieldEditDialogText (dlg->edit, str_find, str_repl);
13206   }
13207 }
13208 
13209 
EditActionDialogMessage(DialoG d,Int2 mssg)13210 static void EditActionDialogMessage (DialoG d, Int2 mssg)
13211 
13212 {
13213   EditActionDlgPtr dlg;
13214 
13215   dlg = (EditActionDlgPtr) GetObjectExtra (d);
13216   if (dlg != NULL) {
13217     switch (mssg) {
13218       case NUM_VIB_MSG + 1 :
13219         SetFieldEditDialogText (dlg->edit, "", "");
13220         break;
13221       default :
13222         break;
13223     }
13224   }
13225 }
13226 
13227 
13228 static DialoG
EditActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc autopopulate,Pointer autopopulate_data,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Nlm_ChangeNotifyProc redraw_notify,Pointer redraw_userdata)13229 EditActionDialog
13230 (GrouP h,
13231  Boolean indexer_version,
13232  Nlm_ChangeNotifyProc     autopopulate,
13233  Pointer                  autopopulate_data,
13234  Nlm_ChangeNotifyProc     change_notify,
13235  Pointer                  change_userdata,
13236  Nlm_ChangeNotifyProc     redraw_notify,
13237  Pointer                  redraw_userdata)
13238 {
13239   EditActionDlgPtr dlg;
13240   GrouP                 p;
13241 
13242   dlg = (EditActionDlgPtr) MemNew (sizeof (EditActionDlgData));
13243 
13244   p = HiddenGroup (h, -1, 0, NULL);
13245   SetObjectExtra (p, dlg, StdCleanupExtraProc);
13246   dlg->dialog = (DialoG) p;
13247   dlg->todialog = PointerToEditActionDlg;
13248   dlg->fromdialog = DialogToEditAction;
13249   dlg->testdialog = TestEditActionDialog;
13250   dlg->dialogmessage = EditActionDialogMessage;
13251   dlg->autopopulate = autopopulate;
13252   dlg->autopopulate_data = autopopulate_data;
13253   dlg->change_notify = change_notify;
13254   dlg->change_userdata = change_userdata;
13255   dlg->redraw_notify = redraw_notify;
13256   dlg->redraw_userdata = redraw_userdata;
13257 
13258   if (dlg->autopopulate != NULL) {
13259     dlg->autopopulate_btn = CheckBox (p, "Autopopulate", ChangeAutopopulateStatus);
13260     SetObjectExtra (dlg->autopopulate_btn, dlg, NULL);
13261   }
13262 
13263   dlg->edit = FieldEditDialog (p, change_notify, change_userdata);
13264   if (dlg->autopopulate_btn != NULL) {
13265     AlignObjects (ALIGN_CENTER, (HANDLE) dlg->autopopulate_btn, (HANDLE) dlg->edit, NULL);
13266   }
13267 
13268   return (DialoG) p;
13269 }
13270 
13271 
13272 typedef struct removeoutsideactiondlg {
13273   AECR_DLG_BLOCK
13274 
13275   DialoG portion;
13276   GrouP  if_not_found;
13277 } RemoveOutsideActionDlgData, PNTR RemoveOutsideActionDlgPtr;
13278 
13279 
PointerToRemoveOutsideActionDlg(DialoG d,Pointer data)13280 static void PointerToRemoveOutsideActionDlg (DialoG d, Pointer data)
13281 {
13282   RemoveOutsideActionDlgPtr dlg;
13283   RemoveOutsideActionPtr ro;
13284 
13285   dlg = (RemoveOutsideActionDlgPtr) GetObjectExtra (d);
13286   if (dlg == NULL) return;
13287   ro = (RemoveOutsideActionPtr) data;
13288 
13289   if (ro == NULL) {
13290     SingleFieldToAECRActionDlg (d, NULL);
13291     PointerToDialog (dlg->portion, NULL);
13292     SetValue (dlg->if_not_found, 1);
13293   } else {
13294     SingleFieldToAECRActionDlg (d, ro->field);
13295     PointerToDialog (dlg->portion, ro->portion);
13296     if (ro->remove_if_not_found) {
13297       SetValue (dlg->if_not_found, 2);
13298     } else {
13299       SetValue (dlg->if_not_found, 1);
13300     }
13301   }
13302 }
13303 
13304 
DialogToRemoveOutsideAction(DialoG d)13305 static Pointer DialogToRemoveOutsideAction (DialoG d)
13306 {
13307   RemoveOutsideActionDlgPtr dlg;
13308   RemoveOutsideActionPtr    edit;
13309 
13310   dlg = (RemoveOutsideActionDlgPtr) GetObjectExtra (d);
13311   if (dlg == NULL) return NULL;
13312 
13313   edit = RemoveOutsideActionNew ();
13314   edit->field = DialogToPointer (dlg->field_dlg);
13315   edit->portion = DialogToPointer (dlg->portion);
13316   if (GetValue(dlg->if_not_found) == 2) {
13317     edit->remove_if_not_found = TRUE;
13318   } else {
13319     edit->remove_if_not_found = FALSE;
13320   }
13321   return edit;
13322 }
13323 
13324 
TestRemoveOutsideActionDialog(DialoG d)13325 static ValNodePtr TestRemoveOutsideActionDialog (DialoG d)
13326 {
13327   RemoveOutsideActionDlgPtr dlg;
13328   Int2 field_type = 0;
13329   ValNodePtr err_list = NULL;
13330   ValNodePtr field, vnp;
13331   Boolean    field_is_nontext = FALSE;
13332 
13333   dlg = (RemoveOutsideActionDlgPtr) GetObjectExtra (d);
13334   if (dlg == NULL) return NULL;
13335 
13336   err_list = TestDialog (dlg->qual_type_dlg);
13337   vnp = DialogToPointer (dlg->qual_type_dlg);
13338   if (vnp != NULL) {
13339     field_type = vnp->choice;
13340     vnp = ValNodeFree (vnp);
13341   }
13342 
13343   ValNodeLink (&err_list, TestDialog (dlg->field_dlg));
13344 
13345   field = DialogToPointer (dlg->field_dlg);
13346   field_is_nontext = IsFieldTypeNonText (field);
13347   field = FieldTypeFree (field);
13348 
13349   if (field_is_nontext) {
13350     ValNodeAddPointer (&err_list, 0, "invalid action for field type");
13351   }
13352   ValNodeLink (&err_list, TestDialog (dlg->portion));
13353   return err_list;
13354 }
13355 
13356 
RemoveOutsideActionDialogMessage(DialoG d,Int2 mssg)13357 static void RemoveOutsideActionDialogMessage (DialoG d, Int2 mssg)
13358 
13359 {
13360   RemoveOutsideActionDlgPtr dlg;
13361 
13362   dlg = (RemoveOutsideActionDlgPtr) GetObjectExtra (d);
13363   if (dlg != NULL) {
13364     switch (mssg) {
13365       case NUM_VIB_MSG + 1 :
13366         SendMessageToDialog (dlg->portion, VIB_MSG_INIT);
13367         break;
13368       default :
13369         break;
13370     }
13371   }
13372 }
13373 
13374 
13375 static DialoG
RemoveOutsideActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc autopopulate,Pointer autopopulate_data,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Nlm_ChangeNotifyProc redraw_notify,Pointer redraw_userdata)13376 RemoveOutsideActionDialog
13377 (GrouP h,
13378  Boolean indexer_version,
13379  Nlm_ChangeNotifyProc     autopopulate,
13380  Pointer                  autopopulate_data,
13381  Nlm_ChangeNotifyProc     change_notify,
13382  Pointer                  change_userdata,
13383  Nlm_ChangeNotifyProc     redraw_notify,
13384  Pointer                  redraw_userdata)
13385 {
13386   RemoveOutsideActionDlgPtr dlg;
13387   GrouP                 p;
13388 
13389   dlg = (RemoveOutsideActionDlgPtr) MemNew (sizeof (RemoveOutsideActionDlgData));
13390 
13391   p = HiddenGroup (h, -1, 0, NULL);
13392   SetObjectExtra (p, dlg, StdCleanupExtraProc);
13393   dlg->dialog = (DialoG) p;
13394   dlg->todialog = PointerToRemoveOutsideActionDlg;
13395   dlg->fromdialog = DialogToRemoveOutsideAction;
13396   dlg->testdialog = TestRemoveOutsideActionDialog;
13397   dlg->dialogmessage = RemoveOutsideActionDialogMessage;
13398   dlg->autopopulate = autopopulate;
13399   dlg->autopopulate_data = autopopulate_data;
13400   dlg->change_notify = change_notify;
13401   dlg->change_userdata = change_userdata;
13402   dlg->redraw_notify = redraw_notify;
13403   dlg->redraw_userdata = redraw_userdata;
13404 
13405   if (dlg->autopopulate != NULL) {
13406     dlg->autopopulate_btn = CheckBox (p, "Autopopulate", ChangeAutopopulateStatus);
13407     SetObjectExtra (dlg->autopopulate_btn, dlg, NULL);
13408   }
13409 
13410   dlg->portion = TextPortionDialog (p, FALSE, change_notify, change_userdata);
13411   dlg->if_not_found = NormalGroup (p, 0, 2, "If field doesn't contain searched for text:", systemFont, NULL);
13412   RadioButton (dlg->if_not_found, "     Do nothing to field");
13413   RadioButton (dlg->if_not_found, "     Remove entire field text");
13414   SetValue (dlg->if_not_found, 1);
13415   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->portion, (HANDLE) dlg->if_not_found, (HANDLE) dlg->autopopulate_btn, NULL);
13416 
13417   return (DialoG) p;
13418 }
13419 
13420 
13421 typedef struct convertactiondlg {
13422   AECR_DLG_BLOCK
13423 
13424   ButtoN strip_name;
13425   ButtoN keep_original;
13426   DialoG capitalization;
13427   DialoG existing_text;
13428 
13429 } ConvertActionDlgData, PNTR ConvertActionDlgPtr;
13430 
13431 
PointerToConvertActionDlg(DialoG d,Pointer data)13432 static void PointerToConvertActionDlg (DialoG d, Pointer data)
13433 {
13434   ConvertActionDlgPtr dlg;
13435   ConvertActionPtr    convert;
13436 
13437   dlg = (ConvertActionDlgPtr) GetObjectExtra (d);
13438   if (dlg == NULL) return;
13439   convert = (ConvertActionPtr) data;
13440 
13441   if (convert == NULL) {
13442     FieldPairToAECRActionDlg (d, NULL);
13443     SetStatus (dlg->strip_name, FALSE);
13444     SetStatus (dlg->keep_original, FALSE);
13445     SetCapChangeDialogValue (dlg->capitalization, 0);
13446     SetExistingTextDialogValue(dlg->existing_text, 0);
13447   } else {
13448     FieldPairToAECRActionDlg (d, convert->fields);
13449     SetStatus (dlg->strip_name, convert->strip_name);
13450     SetStatus (dlg->keep_original, convert->keep_original);
13451     SetCapChangeDialogValue (dlg->capitalization, convert->capitalization);
13452     SetExistingTextDialogValue(dlg->existing_text, convert->existing_text);
13453   }
13454 }
13455 
13456 
DialogToConvertAction(DialoG d)13457 static Pointer DialogToConvertAction (DialoG d)
13458 {
13459   ConvertActionDlgPtr dlg;
13460   ConvertActionPtr   convert;
13461 
13462   dlg = (ConvertActionDlgPtr) GetObjectExtra (d);
13463   if (dlg == NULL) return NULL;
13464 
13465   convert = ConvertActionNew();
13466   convert->fields = DialogToPointer (dlg->field_dlg);
13467   convert->strip_name = GetStatus (dlg->strip_name);
13468   convert->keep_original = GetStatus (dlg->keep_original);
13469   convert->capitalization = GetCapChangeDialogValue (dlg->capitalization);
13470   convert->existing_text = GetExistingTextDialogValue (dlg->existing_text);
13471   return convert;
13472 }
13473 
13474 
TestConvertActionDialog(DialoG d)13475 static ValNodePtr TestConvertActionDialog (DialoG d)
13476 {
13477   ConvertActionDlgPtr dlg;
13478   Int2 field_type = 0;
13479   ValNodePtr err_list = NULL;
13480   ValNodePtr field_pair, field_from, field_to, vnp;
13481   Boolean    field_is_nontext = FALSE;
13482 
13483   dlg = (ConvertActionDlgPtr) GetObjectExtra (d);
13484   if (dlg == NULL) return NULL;
13485 
13486   err_list = TestDialog (dlg->qual_type_dlg);
13487   vnp = DialogToPointer (dlg->qual_type_dlg);
13488   if (vnp != NULL) {
13489     field_type = vnp->choice;
13490     vnp = ValNodeFree (vnp);
13491   }
13492 
13493   ValNodeLink (&err_list, TestDialog (dlg->field_dlg));
13494   ValNodeLink (&err_list, TestDialog (dlg->capitalization));
13495   ValNodeLink (&err_list, TestDialog (dlg->existing_text));
13496 
13497   field_pair = DialogToPointer (dlg->field_dlg);
13498   field_from = GetFromFieldFromFieldPair (field_pair);
13499   field_to = GetFromFieldFromFieldPair (field_pair);
13500   field_pair = FieldPairTypeFree (field_pair);
13501   field_is_nontext = IsFieldTypeNonText (field_from) || IsFieldTypeNonText (field_to);
13502   field_from = FieldTypeFree (field_from);
13503   field_to = FieldTypeFree (field_to);
13504 
13505   if (field_is_nontext && field_type != 4) {
13506     ValNodeAddPointer (&err_list, 0, "invalid action for field type");
13507   }
13508 
13509   return err_list;
13510 }
13511 
13512 
13513 static DialoG
ConvertActionDialog(GrouP h,Boolean indexer_version,Boolean show_existing_text,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Nlm_ChangeNotifyProc redraw_notify,Pointer redraw_userdata)13514 ConvertActionDialog
13515 (GrouP h,
13516  Boolean indexer_version,
13517  Boolean show_existing_text,
13518  Nlm_ChangeNotifyProc     change_notify,
13519  Pointer                  change_userdata,
13520  Nlm_ChangeNotifyProc     redraw_notify,
13521  Pointer                  redraw_userdata)
13522 {
13523   ConvertActionDlgPtr dlg;
13524   GrouP                 p, g;
13525 
13526   dlg = (ConvertActionDlgPtr) MemNew (sizeof (ConvertActionDlgData));
13527 
13528   p = HiddenGroup (h, -1, 0, NULL);
13529   SetObjectExtra (p, dlg, StdCleanupExtraProc);
13530   dlg->dialog = (DialoG) p;
13531   dlg->todialog = PointerToConvertActionDlg;
13532   dlg->fromdialog = DialogToConvertAction;
13533   dlg->testdialog = TestConvertActionDialog;
13534   dlg->change_notify = change_notify;
13535   dlg->change_userdata = change_userdata;
13536   dlg->redraw_notify = redraw_notify;
13537   dlg->redraw_userdata = redraw_userdata;
13538 
13539   g = HiddenGroup (p, 2, 0, NULL);
13540   dlg->keep_original = CheckBox (g, "Leave on original", NULL);
13541   dlg->strip_name = CheckBox (g, "Strip name from text", NULL);
13542 
13543   dlg->capitalization = CapChangeDialog(p, change_notify, change_userdata);
13544 
13545   if (show_existing_text) {
13546     dlg->existing_text = ExistingTextDialog (p, change_notify, change_userdata);
13547   } else {
13548     dlg->existing_text = NULL;
13549   }
13550 
13551   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) dlg->capitalization, (HANDLE) dlg->existing_text, NULL);
13552 
13553   return (DialoG) p;
13554 }
13555 
13556 
13557 typedef struct copyactiondlg {
13558   AECR_DLG_BLOCK
13559 
13560   DialoG existing_text;
13561 
13562 } CopyActionDlgData, PNTR CopyActionDlgPtr;
13563 
13564 
PointerToCopyActionDlg(DialoG d,Pointer data)13565 static void PointerToCopyActionDlg (DialoG d, Pointer data)
13566 {
13567   CopyActionDlgPtr dlg;
13568   CopyActionPtr    copy;
13569 
13570   dlg = (CopyActionDlgPtr) GetObjectExtra (d);
13571   if (dlg == NULL) return;
13572   copy = (CopyActionPtr) data;
13573 
13574   if (copy == NULL) {
13575     FieldPairToAECRActionDlg (d, NULL);
13576     SetExistingTextDialogValue(dlg->existing_text, 0);
13577   } else {
13578     FieldPairToAECRActionDlg (d, copy->fields);
13579     SetExistingTextDialogValue(dlg->existing_text, copy->existing_text);
13580   }
13581 }
13582 
13583 
DialogToCopyAction(DialoG d)13584 static Pointer DialogToCopyAction (DialoG d)
13585 {
13586   CopyActionDlgPtr dlg;
13587   CopyActionPtr    copy;
13588 
13589   dlg = (CopyActionDlgPtr) GetObjectExtra (d);
13590   if (dlg == NULL) return NULL;
13591 
13592   copy = CopyActionNew();
13593   copy->fields = DialogToPointer (dlg->field_dlg);
13594   copy->existing_text = GetExistingTextDialogValue (dlg->existing_text);
13595   return copy;
13596 }
13597 
13598 
TestCopyActionDialog(DialoG d)13599 static ValNodePtr TestCopyActionDialog (DialoG d)
13600 {
13601   CopyActionDlgPtr dlg;
13602   Int2 field_type = 0;
13603   ValNodePtr err_list = NULL;
13604   ValNodePtr field, vnp;
13605   Boolean    field_is_nontext = FALSE;
13606 
13607   dlg = (CopyActionDlgPtr) GetObjectExtra (d);
13608   if (dlg == NULL) return NULL;
13609 
13610   err_list = TestDialog (dlg->qual_type_dlg);
13611   vnp = DialogToPointer (dlg->qual_type_dlg);
13612   if (vnp != NULL) {
13613     field_type = vnp->choice;
13614     vnp = ValNodeFree (vnp);
13615   }
13616 
13617   ValNodeLink (&err_list, TestDialog (dlg->field_dlg));
13618   ValNodeLink (&err_list, TestDialog (dlg->existing_text));
13619 
13620   field = DialogToPointer (dlg->field_dlg);
13621   field_is_nontext = IsFieldTypeNonText (field);
13622   field = FieldTypeFree (field);
13623 
13624   if (field_is_nontext && field_type != 4) {
13625     ValNodeAddPointer (&err_list, 0, "invalid action for field type");
13626   }
13627 
13628   return err_list;
13629 }
13630 
13631 
13632 static DialoG
CopyActionDialog(GrouP h,Boolean indexer_version,Boolean show_existing_text,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Nlm_ChangeNotifyProc redraw_notify,Pointer redraw_userdata)13633 CopyActionDialog
13634 (GrouP h,
13635  Boolean indexer_version,
13636  Boolean show_existing_text,
13637  Nlm_ChangeNotifyProc     change_notify,
13638  Pointer                  change_userdata,
13639  Nlm_ChangeNotifyProc     redraw_notify,
13640  Pointer                  redraw_userdata)
13641 {
13642   CopyActionDlgPtr dlg;
13643   GrouP                 p;
13644 
13645   dlg = (CopyActionDlgPtr) MemNew (sizeof (CopyActionDlgData));
13646 
13647   p = HiddenGroup (h, -1, 0, NULL);
13648   SetObjectExtra (p, dlg, StdCleanupExtraProc);
13649   dlg->dialog = (DialoG) p;
13650   dlg->todialog = PointerToCopyActionDlg;
13651   dlg->fromdialog = DialogToCopyAction;
13652   dlg->testdialog = TestCopyActionDialog;
13653   dlg->change_notify = change_notify;
13654   dlg->change_userdata = change_userdata;
13655   dlg->redraw_notify = redraw_notify;
13656   dlg->redraw_userdata = redraw_userdata;
13657 
13658   if (show_existing_text) {
13659     dlg->existing_text = ExistingTextDialog (p, change_notify, change_userdata);
13660   } else {
13661     dlg->existing_text = NULL;
13662   }
13663 
13664   return (DialoG) p;
13665 }
13666 
13667 
13668 typedef struct removeactiondlg {
13669   AECR_DLG_BLOCK
13670 } RemoveActionDlgData, PNTR RemoveActionDlgPtr;
13671 
13672 
RemoveActionToDialog(DialoG d,Pointer data)13673 static void RemoveActionToDialog (DialoG d, Pointer data)
13674 {
13675   RemoveActionDlgPtr dlg;
13676   RemoveActionPtr    remove;
13677 
13678   dlg = (RemoveActionDlgPtr) GetObjectExtra (d);
13679   if (dlg == NULL) return;
13680   remove = (RemoveActionPtr) data;
13681 
13682   if (remove == NULL) {
13683     SingleFieldToAECRActionDlg (d, NULL);
13684   } else {
13685     SingleFieldToAECRActionDlg (d, remove->field);
13686     PointerToDialog (dlg->field_dlg, remove->field);
13687   }
13688 }
13689 
13690 
DialogToRemoveAction(DialoG d)13691 static Pointer DialogToRemoveAction (DialoG d)
13692 {
13693   RemoveActionDlgPtr dlg;
13694   RemoveActionPtr    remove;
13695 
13696   dlg = (RemoveActionDlgPtr) GetObjectExtra (d);
13697   if (dlg == NULL) return NULL;
13698 
13699   remove = RemoveActionNew();
13700   remove->field = DialogToPointer (dlg->field_dlg);
13701   return remove;
13702 
13703 }
13704 
13705 
TestRemoveActionDialog(DialoG d)13706 static ValNodePtr TestRemoveActionDialog (DialoG d)
13707 {
13708   RemoveActionDlgPtr dlg;
13709   ValNodePtr err_list = NULL;
13710 
13711   dlg = (RemoveActionDlgPtr) GetObjectExtra (d);
13712   if (dlg == NULL) return NULL;
13713 
13714   err_list = TestDialog (dlg->qual_type_dlg);
13715 
13716   ValNodeLink (&err_list, TestDialog (dlg->field_dlg));
13717 
13718   return err_list;
13719 }
13720 
13721 
13722 static DialoG
RemoveActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Nlm_ChangeNotifyProc redraw_notify,Pointer redraw_userdata)13723 RemoveActionDialog
13724 (GrouP h,
13725  Boolean indexer_version,
13726  Nlm_ChangeNotifyProc     change_notify,
13727  Pointer                  change_userdata,
13728  Nlm_ChangeNotifyProc     redraw_notify,
13729  Pointer                  redraw_userdata)
13730 {
13731   RemoveActionDlgPtr dlg;
13732   GrouP                 p;
13733 
13734   dlg = (RemoveActionDlgPtr) MemNew (sizeof (RemoveActionDlgData));
13735 
13736   p = HiddenGroup (h, -1, 0, NULL);
13737   SetObjectExtra (p, dlg, StdCleanupExtraProc);
13738   dlg->dialog = (DialoG) p;
13739   dlg->todialog = RemoveActionToDialog;
13740   dlg->fromdialog = DialogToRemoveAction;
13741   dlg->testdialog = TestRemoveActionDialog;
13742   dlg->change_notify = change_notify;
13743   dlg->change_userdata = change_userdata;
13744   dlg->redraw_notify = redraw_notify;
13745   dlg->redraw_userdata = redraw_userdata;
13746 
13747   return (DialoG) p;
13748 }
13749 
13750 
13751 typedef struct swapactiondlg {
13752   AECR_DLG_BLOCK
13753 } SwapActionDlgData, PNTR SwapActionDlgPtr;
13754 
13755 
SwapActionToDialog(DialoG d,Pointer data)13756 static void SwapActionToDialog (DialoG d, Pointer data)
13757 {
13758   SwapActionDlgPtr dlg;
13759   SwapActionPtr    swap;
13760 
13761   dlg = (SwapActionDlgPtr) GetObjectExtra (d);
13762   if (dlg == NULL) return;
13763   swap = (SwapActionPtr) data;
13764 
13765   if (swap == NULL) {
13766     FieldPairToAECRActionDlg (d, NULL);
13767   } else {
13768     FieldPairToAECRActionDlg (d, swap->fields);
13769   }
13770 
13771 }
13772 
13773 
DialogToSwapAction(DialoG d)13774 static Pointer DialogToSwapAction (DialoG d)
13775 {
13776   SwapActionDlgPtr dlg;
13777   SwapActionPtr    swap;
13778 
13779   dlg = (SwapActionDlgPtr) GetObjectExtra (d);
13780   if (dlg == NULL) return NULL;
13781 
13782   swap = SwapActionNew();
13783   swap->fields = DialogToPointer (dlg->field_dlg);
13784   return swap;
13785 
13786 }
13787 
13788 
TestSwapActionDialog(DialoG d)13789 static ValNodePtr TestSwapActionDialog (DialoG d)
13790 {
13791   SwapActionDlgPtr dlg;
13792   ValNodePtr err_list = NULL;
13793 
13794   dlg = (SwapActionDlgPtr) GetObjectExtra (d);
13795   if (dlg == NULL) return NULL;
13796 
13797   err_list = TestDialog (dlg->qual_type_dlg);
13798 
13799   ValNodeLink (&err_list, TestDialog (dlg->field_dlg));
13800 
13801   return err_list;
13802 }
13803 
13804 
13805 static DialoG
SwapActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Nlm_ChangeNotifyProc redraw_notify,Pointer redraw_userdata)13806 SwapActionDialog
13807 (GrouP h,
13808  Boolean indexer_version,
13809  Nlm_ChangeNotifyProc     change_notify,
13810  Pointer                  change_userdata,
13811  Nlm_ChangeNotifyProc     redraw_notify,
13812  Pointer                  redraw_userdata)
13813 {
13814   SwapActionDlgPtr dlg;
13815   GrouP                 p;
13816 
13817   dlg = (SwapActionDlgPtr) MemNew (sizeof (SwapActionDlgData));
13818 
13819   p = HiddenGroup (h, -1, 0, NULL);
13820   SetObjectExtra (p, dlg, StdCleanupExtraProc);
13821   dlg->dialog = (DialoG) p;
13822   dlg->todialog = SwapActionToDialog;
13823   dlg->fromdialog = DialogToSwapAction;
13824   dlg->testdialog = TestSwapActionDialog;
13825   dlg->change_notify = change_notify;
13826   dlg->change_userdata = change_userdata;
13827   dlg->redraw_notify = redraw_notify;
13828   dlg->redraw_userdata = redraw_userdata;
13829 
13830   return (DialoG) p;
13831 }
13832 
13833 
13834 typedef struct aecrparseactiondlg {
13835   AECR_DLG_BLOCK
13836 
13837   DialoG text_portion;
13838   DialoG transform;
13839   ButtoN remove_from_parsed;
13840   ButtoN remove_left;
13841   ButtoN remove_right;
13842   DialoG existing_text;
13843 
13844 } AECRParseActionDlgData, PNTR AECRParseActionDlgPtr;
13845 
13846 
AECRParseActionToDialog(DialoG d,Pointer data)13847 static void AECRParseActionToDialog (DialoG d, Pointer data)
13848 {
13849   AECRParseActionDlgPtr dlg;
13850   AECRParseActionPtr    parse;
13851 
13852   dlg = (AECRParseActionDlgPtr) GetObjectExtra (d);
13853   if (dlg == NULL) return;
13854   parse = (AECRParseActionPtr) data;
13855 
13856   if (parse == NULL) {
13857     FieldPairToAECRActionDlg (d, NULL);
13858     PointerToDialog (dlg->text_portion, NULL);
13859     PointerToDialog (dlg->transform, NULL);
13860     SetStatus (dlg->remove_from_parsed, FALSE);
13861     SetStatus (dlg->remove_left, FALSE);
13862     SetStatus (dlg->remove_right, FALSE);
13863     SetExistingTextDialogValue(dlg->existing_text, 0);
13864   } else {
13865     FieldPairToAECRActionDlg (d, parse->fields);
13866     PointerToDialog (dlg->text_portion, parse->portion);
13867     PointerToDialog (dlg->transform, parse->transform);
13868     SetStatus (dlg->remove_from_parsed, parse->remove_from_parsed);
13869     SetStatus (dlg->remove_left, parse->remove_left);
13870     SetStatus (dlg->remove_right, parse->remove_right);
13871     SetExistingTextDialogValue(dlg->existing_text, parse->existing_text);
13872   }
13873 
13874 }
13875 
13876 
DialogToAECRParseAction(DialoG d)13877 static Pointer DialogToAECRParseAction (DialoG d)
13878 {
13879   AECRParseActionDlgPtr dlg;
13880   AECRParseActionPtr    parse;
13881 
13882   dlg = (AECRParseActionDlgPtr) GetObjectExtra (d);
13883   if (dlg == NULL) return NULL;
13884 
13885   parse = AECRParseActionNew();
13886   parse->fields = DialogToPointer (dlg->field_dlg);
13887   parse->portion = DialogToPointer (dlg->text_portion);
13888   parse->transform = DialogToPointer (dlg->transform);
13889   parse->remove_from_parsed = GetStatus (dlg->remove_from_parsed);
13890   parse->remove_left = GetStatus (dlg->remove_left);
13891   parse->remove_right = GetStatus (dlg->remove_right);
13892   parse->existing_text = GetExistingTextDialogValue (dlg->existing_text);
13893   return parse;
13894 }
13895 
13896 
TestAECRParseActionDialog(DialoG d)13897 static ValNodePtr TestAECRParseActionDialog (DialoG d)
13898 {
13899   AECRParseActionDlgPtr dlg;
13900   ValNodePtr err_list = NULL;
13901   ValNodePtr field_pair, field;
13902   Boolean    field_is_nontext = FALSE;
13903 
13904   dlg = (AECRParseActionDlgPtr) GetObjectExtra (d);
13905   if (dlg == NULL) return NULL;
13906 
13907   err_list = TestDialog (dlg->qual_type_dlg);
13908 
13909   ValNodeLink (&err_list, TestDialog (dlg->field_dlg));
13910   ValNodeLink (&err_list, TestDialog (dlg->existing_text));
13911 
13912   field_pair = DialogToPointer (dlg->field_dlg);
13913   field = GetFromFieldFromFieldPair (field_pair);
13914   field_is_nontext = IsFieldTypeNonText (field);
13915   field = FieldTypeFree (field);
13916   if (!field_is_nontext) {
13917     field = GetToFieldFromFieldPair (field_pair);
13918     field_is_nontext = IsFieldTypeNonText (field);
13919     field = FieldTypeFree (field);
13920   }
13921 
13922   if (field_is_nontext) {
13923     ValNodeAddPointer (&err_list, 0, "invalid action for field type");
13924   }
13925   ValNodeLink (&err_list, TestDialog (dlg->text_portion));
13926 
13927   return err_list;
13928 }
13929 
13930 
ChangeAECRParseActionTextPortion(Pointer data)13931 static void ChangeAECRParseActionTextPortion (Pointer data)
13932 {
13933   AECRParseActionDlgPtr dlg;
13934   TextPortionPtr        tp;
13935 
13936   dlg = (AECRParseActionDlgPtr) data;
13937   if (dlg == NULL) {
13938     return;
13939   }
13940 
13941   if (GetStatus (dlg->remove_from_parsed)) {
13942     tp = DialogToPointer (dlg->text_portion);
13943     if (tp == NULL) {
13944       Hide (dlg->remove_left);
13945       Hide (dlg->remove_right);
13946     } else {
13947       if (!tp->include_left) {
13948         Show (dlg->remove_left);
13949       } else {
13950         Hide (dlg->remove_left);
13951       }
13952       if (!tp->include_right) {
13953         Show (dlg->remove_right);
13954       } else {
13955         Hide (dlg->remove_right);
13956       }
13957     }
13958   } else {
13959     Hide (dlg->remove_left);
13960     Hide (dlg->remove_right);
13961   }
13962 
13963   if (dlg->change_notify != NULL) {
13964     (dlg->change_notify) (dlg->change_userdata);
13965   }
13966 }
13967 
13968 
ChangeAECRParseActionRemove(ButtoN b)13969 static void ChangeAECRParseActionRemove (ButtoN b)
13970 {
13971   AECRParseActionDlgPtr dlg;
13972 
13973   dlg = (AECRParseActionDlgPtr) GetObjectExtra (b);
13974   if (dlg == NULL) {
13975     return;
13976   }
13977   ChangeAECRParseActionTextPortion (dlg);
13978 }
13979 
13980 
13981 static DialoG
AECRParseActionDialog(GrouP h,Boolean indexer_version,Boolean show_existing_text,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Nlm_ChangeNotifyProc redraw_notify,Pointer redraw_userdata)13982 AECRParseActionDialog
13983 (GrouP h,
13984  Boolean indexer_version,
13985  Boolean show_existing_text,
13986  Nlm_ChangeNotifyProc     change_notify,
13987  Pointer                  change_userdata,
13988  Nlm_ChangeNotifyProc     redraw_notify,
13989  Pointer                  redraw_userdata)
13990 {
13991   AECRParseActionDlgPtr dlg;
13992   GrouP                 p, g1, g2;
13993 
13994   dlg = (AECRParseActionDlgPtr) MemNew (sizeof (AECRParseActionDlgData));
13995 
13996   p = HiddenGroup (h, -1, 0, NULL);
13997   SetObjectExtra (p, dlg, StdCleanupExtraProc);
13998   dlg->dialog = (DialoG) p;
13999   dlg->todialog = AECRParseActionToDialog;
14000   dlg->fromdialog = DialogToAECRParseAction;
14001   dlg->testdialog = TestAECRParseActionDialog;
14002   dlg->change_notify = change_notify;
14003   dlg->change_userdata = change_userdata;
14004   dlg->redraw_notify = redraw_notify;
14005   dlg->redraw_userdata = redraw_userdata;
14006 
14007   g1 = HiddenGroup (p, 2, 0, NULL);
14008   dlg->text_portion = TextPortionDialog (g1, TRUE, ChangeAECRParseActionTextPortion, dlg);
14009   g2 = HiddenGroup (g1, 0, 2, NULL);
14010   dlg->remove_left = CheckBox (g2, "Also remove entered text", NULL);
14011   dlg->remove_right = CheckBox (g2, "Also remove entered text", NULL);
14012 
14013   AlignObjects (ALIGN_VERTICAL, (HANDLE) GetTextPortionStartChoiceGroup (dlg->text_portion), (HANDLE) dlg->remove_left, NULL);
14014   AlignObjects (ALIGN_VERTICAL, (HANDLE) GetTextPortionEndChoiceGroup (dlg->text_portion), (HANDLE) dlg->remove_right, NULL);
14015   Hide (dlg->remove_left);
14016   Hide (dlg->remove_right);
14017 
14018   dlg->remove_from_parsed = CheckBox (p, "Remove from parsed field", ChangeAECRParseActionRemove);
14019   SetObjectExtra (dlg->remove_from_parsed, dlg, NULL);
14020 
14021   dlg->transform = TextTransformSetDialog (p, NULL, NULL);
14022 
14023   if (show_existing_text) {
14024     dlg->existing_text = ExistingTextDialog (p, change_notify, change_userdata);
14025   } else {
14026     dlg->existing_text = NULL;
14027   }
14028 
14029   AlignObjects (ALIGN_CENTER,
14030                               (HANDLE) g1,
14031                               (HANDLE) dlg->transform,
14032                               (HANDLE) dlg->remove_from_parsed,
14033                               (HANDLE) dlg->qual_type_dlg,
14034                               (HANDLE) dlg->field_dlg,
14035                               (HANDLE) dlg->existing_text,
14036                               NULL);
14037   return (DialoG) p;
14038 }
14039 
14040 
14041 typedef struct editaecractiondlg {
14042   DIALOG_MESSAGE_BLOCK
14043   DialoG action_dlgs[8];
14044   DialoG constraint_dlg;
14045   ButtoN accept_btn;
14046 
14047   /* groups and dialogs for selecting field types */
14048   DialoG single_qual_type_dlg;
14049   DialoG single_field;
14050   DialoG single_field_remove;
14051   GrouP  single_field_grp;
14052   DialoG pair_qual_type_dlg;
14053   DialoG field_pair;
14054   DialoG field_pair_convert;
14055   GrouP  field_pair_grp;
14056   ButtoN also_change_mrna;
14057 
14058   Uint1      action_type;
14059 
14060   Nlm_ChangeNotifyProc     change_notify;
14061   Pointer                  change_userdata;
14062   Nlm_ChangeNotifyProc     redraw_notify;
14063   Pointer                  redraw_userdata;
14064 } EditAECRActionDlgData, PNTR EditAECRActionDlgPtr;
14065 
14066 
14067 
ActionTypeChoiceFromPopupValue(Int4 i)14068 static Uint1 ActionTypeChoiceFromPopupValue (Int4 i)
14069 {
14070   Uint1 action_type_choice = ActionChoice_apply;
14071 
14072   switch (i) {
14073     case 2:
14074       action_type_choice = ActionChoice_apply;
14075       break;
14076     case 3:
14077       action_type_choice = ActionChoice_edit;
14078       break;
14079     case 4:
14080       action_type_choice = ActionChoice_convert;
14081       break;
14082     case 5:
14083       action_type_choice = ActionChoice_copy;
14084       break;
14085     case 6:
14086       action_type_choice = ActionChoice_swap;
14087       break;
14088     case 8:
14089       action_type_choice = ActionChoice_remove;
14090       break;
14091     case 7:
14092       action_type_choice = ActionChoice_parse;
14093       break;
14094     case 9:
14095       action_type_choice = ActionChoice_remove_outside;
14096       break;
14097   }
14098   return action_type_choice;
14099 }
14100 
14101 
EditAECRDlgNumFromAECRActionType(Uint1 action_type)14102 static Uint1 EditAECRDlgNumFromAECRActionType (Uint1 action_type)
14103 {
14104   Uint1 dlg_num = 0;
14105 
14106   switch (action_type) {
14107     case ActionChoice_apply:
14108       dlg_num = 0;
14109       break;
14110     case ActionChoice_edit:
14111       dlg_num = 1;
14112       break;
14113     case ActionChoice_convert:
14114       dlg_num = 2;
14115       break;
14116     case ActionChoice_copy:
14117       dlg_num = 3;
14118       break;
14119     case ActionChoice_swap:
14120       dlg_num = 4;
14121       break;
14122     case ActionChoice_parse:
14123       dlg_num = 5;
14124       break;
14125     case ActionChoice_remove:
14126       dlg_num = 6;
14127       break;
14128     case ActionChoice_remove_outside:
14129       dlg_num = 7;
14130       break;
14131   }
14132   return dlg_num;
14133 }
14134 
14135 
FieldTypeChoiceFromEditAECRActionDialog(DialoG d)14136 static Uint1 FieldTypeChoiceFromEditAECRActionDialog (DialoG d)
14137 {
14138   EditAECRActionDlgPtr dlg;
14139   Uint1                rval = FieldType_source_qual;
14140 
14141   dlg = (EditAECRActionDlgPtr) GetObjectExtra (d);
14142   if (dlg != NULL) {
14143     rval = FieldTypeChoiceFromAECRActionDlg (dlg->action_dlgs[EditAECRDlgNumFromAECRActionType(dlg->action_type)]);
14144   }
14145 
14146   return rval;
14147 }
14148 
14149 
TestAECRActionDialog(DialoG d)14150 static ValNodePtr TestAECRActionDialog (DialoG d)
14151 {
14152   EditAECRActionDlgPtr dlg;
14153   ValNodePtr err_list = NULL;
14154 
14155   dlg = (EditAECRActionDlgPtr) GetObjectExtra (d);
14156   if (dlg == NULL) return NULL;
14157 
14158   err_list = TestDialog (dlg->action_dlgs[EditAECRDlgNumFromAECRActionType(dlg->action_type)]);
14159 
14160   return err_list;
14161 }
14162 
14163 
AECRActionAffectsCDSProduct(DialoG d)14164 static Boolean AECRActionAffectsCDSProduct (DialoG d)
14165 {
14166   EditAECRActionDlgPtr dlg;
14167   Uint1 qual_type;
14168   FieldTypePtr ft = NULL, tmp;
14169   Boolean show = FALSE;
14170 
14171   dlg = (EditAECRActionDlgPtr) GetObjectExtra (d);
14172   if (dlg == NULL) {
14173     return FALSE;
14174   }
14175   qual_type = FieldTypeChoiceFromEditAECRActionDialog (d);
14176   if (qual_type != FieldType_cds_gene_prot && qual_type != FieldType_feature_field) {
14177     return FALSE;
14178   }
14179 
14180   switch (dlg->action_type) {
14181     case ActionChoice_apply:
14182     case ActionChoice_edit:
14183     case ActionChoice_remove_outside:
14184       ft = DialogToPointer (dlg->single_field);
14185       show = IsFieldTypeCDSProduct (ft);
14186       ft = FieldTypeFree (ft);
14187       break;
14188     case ActionChoice_remove:
14189       ft = DialogToPointer (dlg->single_field_remove);
14190       show = IsFieldTypeCDSProduct (ft);
14191       ft = FieldTypeFree (ft);
14192       break;
14193 
14194     case ActionChoice_convert:
14195       tmp = DialogToPointer (dlg->field_pair_convert);
14196       ft = GetToFieldFromFieldPair (tmp);
14197       show = IsFieldTypeCDSProduct (ft);
14198       ft = FieldTypeFree (ft);
14199       ft = GetFromFieldFromFieldPair (tmp);
14200       show |= IsFieldTypeCDSProduct (ft);
14201       ft = FieldTypeFree (ft);
14202       tmp = FieldPairTypeFree (tmp);
14203       break;
14204     case ActionChoice_copy:
14205     case ActionChoice_swap:
14206     case ActionChoice_parse:
14207       tmp = DialogToPointer (dlg->field_pair);
14208       ft = GetToFieldFromFieldPair (tmp);
14209       show = IsFieldTypeCDSProduct (ft);
14210       ft = FieldTypeFree (ft);
14211       ft = GetFromFieldFromFieldPair (tmp);
14212       show |= IsFieldTypeCDSProduct (ft);
14213       ft = FieldTypeFree (ft);
14214       tmp = FieldPairTypeFree (tmp);
14215       break;
14216   }
14217   return show;
14218 }
14219 
14220 
AECRActionFromEditDialog(DialoG d)14221 static Pointer AECRActionFromEditDialog (DialoG d)
14222 {
14223   EditAECRActionDlgPtr dlg;
14224   AECRActionPtr      action = NULL;
14225 
14226   dlg = (EditAECRActionDlgPtr) GetObjectExtra (d);
14227   if (dlg == NULL) return NULL;
14228 
14229   action = AECRActionNew ();
14230   ValNodeAddPointer (&(action->action), dlg->action_type, DialogToPointer (dlg->action_dlgs[EditAECRDlgNumFromAECRActionType(dlg->action_type)]));
14231   if (AECRActionAffectsCDSProduct(d)) {
14232     action->also_change_mrna = GetStatus (dlg->also_change_mrna);
14233   } else {
14234     action->also_change_mrna = FALSE;
14235   }
14236   action->constraint = DialogToPointer (dlg->constraint_dlg);
14237 
14238   return (Pointer) action;
14239 }
14240 
14241 
ChangeConstraintForAECRActionQualType(Pointer data)14242 static void ChangeConstraintForAECRActionQualType (Pointer data)
14243 {
14244   EditAECRActionDlgPtr dlg;
14245   ValNodePtr           vnp;
14246 
14247   dlg = (EditAECRActionDlgPtr) data;
14248   if (dlg != NULL) {
14249     switch (dlg->action_type) {
14250       case ActionChoice_apply:
14251       case ActionChoice_edit:
14252       case ActionChoice_remove_outside:
14253       case ActionChoice_remove:
14254         vnp = DialogToPointer (dlg->single_qual_type_dlg);
14255         if (vnp != NULL) {
14256           vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
14257           SetConstraintSetDefaultConstraintTypeFromFieldType (dlg->constraint_dlg, vnp->choice, NULL, 0, NULL);
14258           vnp = FieldTypeFree (vnp);
14259         }
14260         break;
14261       case ActionChoice_convert:
14262       case ActionChoice_copy:
14263       case ActionChoice_swap:
14264       case ActionChoice_parse:
14265         vnp = DialogToPointer (dlg->pair_qual_type_dlg);
14266         if (vnp != NULL) {
14267           vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
14268           SetConstraintSetDefaultConstraintTypeFromFieldType (dlg->constraint_dlg, FieldTypeChoiceFromFieldPairTypeChoice(vnp->choice), NULL, 0, NULL);
14269           vnp = FieldTypeFree (vnp);
14270         }
14271         break;
14272     }
14273   }
14274 }
14275 
14276 
AECRActionToEditDialog(DialoG d,Pointer data)14277 static void AECRActionToEditDialog (DialoG d, Pointer data)
14278 {
14279   EditAECRActionDlgPtr dlg;
14280   AECRActionPtr action;
14281   Uint1         dlg_num;
14282 
14283   dlg = (EditAECRActionDlgPtr) GetObjectExtra (d);
14284   if (dlg == NULL) return;
14285   action = (AECRActionPtr) data;
14286 
14287   for (dlg_num = 0; dlg_num < 8; dlg_num++) {
14288     Hide (dlg->action_dlgs[dlg_num]);
14289   }
14290   if (action == NULL || action->action == NULL) {
14291     dlg->action_type = ActionChoice_apply;
14292     PointerToDialog (dlg->action_dlgs[0], NULL);
14293     Show (dlg->action_dlgs[0]);
14294   } else {
14295     dlg->action_type = action->action->choice;
14296     dlg_num = EditAECRDlgNumFromAECRActionType(dlg->action_type);
14297     PointerToDialog (dlg->action_dlgs[dlg_num], action->action->data.ptrvalue);
14298     Show (dlg->action_dlgs[dlg_num]);
14299   }
14300 
14301   switch (dlg->action_type) {
14302     case ActionChoice_apply:
14303     case ActionChoice_edit:
14304     case ActionChoice_remove_outside:
14305       Show (dlg->single_field_grp);
14306       Hide (dlg->field_pair_grp);
14307       Show (dlg->single_field);
14308       Hide (dlg->single_field_remove);
14309       break;
14310     case ActionChoice_remove:
14311       Show (dlg->single_field_grp);
14312       Hide (dlg->field_pair_grp);
14313       Hide (dlg->single_field);
14314       Show (dlg->single_field_remove);
14315       break;
14316     case ActionChoice_convert:
14317       Show (dlg->field_pair_grp);
14318       Show (dlg->field_pair_convert);
14319       Hide (dlg->field_pair);
14320       Hide (dlg->single_field_grp);
14321       break;
14322     case ActionChoice_copy:
14323     case ActionChoice_swap:
14324     case ActionChoice_parse:
14325       Show (dlg->field_pair_grp);
14326       Hide (dlg->field_pair_convert);
14327       Show (dlg->field_pair);
14328       Hide (dlg->single_field_grp);
14329       break;
14330   }
14331   /* set also mrna */
14332   if (AECRActionAffectsCDSProduct(d)) {
14333     SetStatus (dlg->also_change_mrna, action->also_change_mrna);
14334     Show (dlg->also_change_mrna);
14335   } else {
14336     SetStatus (dlg->also_change_mrna, FALSE);
14337     Hide (dlg->also_change_mrna);
14338   }
14339   /* set constraint */
14340   if (action == NULL) {
14341     PointerToDialog (dlg->constraint_dlg, NULL);
14342   } else {
14343     PointerToDialog (dlg->constraint_dlg, action->constraint);
14344   }
14345   ChangeConstraintForAECRActionQualType(dlg);
14346 }
14347 
14348 
ChangeEditAECRActionQualType(Pointer data)14349 static void ChangeEditAECRActionQualType (Pointer data)
14350 {
14351   EditAECRActionDlgPtr dlg;
14352   ValNodePtr           vnp;
14353 
14354   dlg = (EditAECRActionDlgPtr) data;
14355   if (dlg != NULL) {
14356     switch (dlg->action_type) {
14357       case ActionChoice_apply:
14358       case ActionChoice_edit:
14359       case ActionChoice_remove_outside:
14360         vnp = DialogToPointer (dlg->single_qual_type_dlg);
14361         SetConstraintSetDefaultConstraintTypeFromFieldType (dlg->constraint_dlg, vnp->choice, NULL, 0, NULL);
14362         vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
14363         PointerToDialog (dlg->single_field, vnp);
14364         vnp = FieldTypeFree (vnp);
14365         break;
14366       case ActionChoice_remove:
14367         vnp = DialogToPointer (dlg->single_qual_type_dlg);
14368         SetConstraintSetDefaultConstraintTypeFromFieldType (dlg->constraint_dlg, vnp->choice, NULL, 0, NULL);
14369         vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
14370         PointerToDialog (dlg->single_field_remove, vnp);
14371         vnp = FieldTypeFree (vnp);
14372         break;
14373       case ActionChoice_convert:
14374         vnp = DialogToPointer (dlg->pair_qual_type_dlg);
14375         SetConstraintSetDefaultConstraintTypeFromFieldType (dlg->constraint_dlg, FieldTypeChoiceFromFieldPairTypeChoice(vnp->choice), NULL, 0, NULL);
14376         vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
14377         PointerToDialog (dlg->field_pair_convert, vnp);
14378         vnp = FieldTypeFree (vnp);
14379         break;
14380       case ActionChoice_copy:
14381       case ActionChoice_swap:
14382       case ActionChoice_parse:
14383         vnp = DialogToPointer (dlg->pair_qual_type_dlg);
14384         SetConstraintSetDefaultConstraintTypeFromFieldType (dlg->constraint_dlg, FieldTypeChoiceFromFieldPairTypeChoice(vnp->choice), NULL, 0, NULL);
14385         vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
14386         PointerToDialog (dlg->field_pair, vnp);
14387         vnp = FieldTypeFree (vnp);
14388         break;
14389     }
14390 
14391     if (dlg->action_type == ActionChoice_apply) {
14392       ChangeDialogForApplyFieldChoice (dlg->action_dlgs[0]);
14393     }
14394     if (dlg->change_notify) {
14395       (dlg->change_notify) (dlg->change_userdata);
14396     }
14397   }
14398 }
14399 
14400 
ChangeEditAECRActionField(Pointer data)14401 static void ChangeEditAECRActionField (Pointer data)
14402 {
14403   EditAECRActionDlgPtr dlg;
14404 
14405   dlg = (EditAECRActionDlgPtr) data;
14406   if (dlg != NULL) {
14407     if (dlg->action_type == ActionChoice_apply) {
14408       ChangeDialogForApplyFieldChoice (dlg->action_dlgs[0]);
14409     }
14410     if (AECRActionAffectsCDSProduct (dlg->dialog)) {
14411       Show (dlg->also_change_mrna);
14412     } else {
14413       Hide (dlg->also_change_mrna);
14414     }
14415     if (dlg->change_notify) {
14416       (dlg->change_notify) (dlg->change_userdata);
14417     }
14418   }
14419 }
14420 
14421 
14422 static DialoG
EditAECRActionDialog(GrouP h,Boolean indexer_version,Boolean show_existing_text,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Nlm_ChangeNotifyProc redraw_notify,Pointer redraw_userdata)14423 EditAECRActionDialog
14424 (GrouP h,
14425  Boolean indexer_version,
14426  Boolean show_existing_text,
14427  Nlm_ChangeNotifyProc     change_notify,
14428  Pointer                  change_userdata,
14429  Nlm_ChangeNotifyProc     redraw_notify,
14430  Pointer                  redraw_userdata)
14431 {
14432   EditAECRActionDlgPtr dlg;
14433   GrouP                 p, g, field_grp, k;
14434   ValNodePtr            val_list = NULL;
14435 
14436   dlg = (EditAECRActionDlgPtr) MemNew (sizeof (EditAECRActionDlgData));
14437 
14438   p = HiddenGroup (h, -1, 0, NULL);
14439   SetObjectExtra (p, dlg, StdCleanupExtraProc);
14440   dlg->dialog = (DialoG) p;
14441   dlg->todialog = AECRActionToEditDialog;
14442   dlg->fromdialog = AECRActionFromEditDialog;
14443   dlg->testdialog = TestAECRActionDialog;
14444   dlg->change_notify = change_notify;
14445   dlg->change_userdata = change_userdata;
14446   dlg->redraw_notify = redraw_notify;
14447   dlg->redraw_userdata = redraw_userdata;
14448 
14449   dlg->action_type = ActionChoice_apply;
14450 
14451   field_grp = HiddenGroup (p, 0, 0, NULL);
14452   dlg->single_field_grp = HiddenGroup (field_grp, -1, 0, NULL);
14453 
14454   ValNodeAddPointer (&val_list, FieldType_source_qual, StringSave ("Source Qual"));
14455   ValNodeAddPointer (&val_list, FieldType_feature_field, StringSave ("Feature Qual"));
14456   ValNodeAddPointer (&val_list, FieldType_cds_gene_prot, StringSave ("CDS-Gene-Prot Qual"));
14457   ValNodeAddPointer (&val_list, FieldType_rna_field, StringSave ("RNA Qual"));
14458   ValNodeAddPointer (&val_list, FieldType_molinfo_field, StringSave ("MolInfo Qual"));
14459   ValNodeAddPointer (&val_list, FieldType_pub, StringSave ("Pub Field"));
14460   ValNodeAddPointer (&val_list, FieldType_struc_comment_field, StringSave ("Structured Comment Field"));
14461   ValNodeAddPointer (&val_list, FieldType_misc, StringSave ("Misc"));
14462   ValNodeAddPointer (&val_list, FieldType_dblink, StringSave ("DBLink"));
14463 
14464   dlg->single_qual_type_dlg = ValNodeSelectionDialog (dlg->single_field_grp, val_list, TALL_SELECTION_LIST, ValNodeStringName,
14465                                 ValNodeSimpleDataFree, ValNodeStringCopy,
14466                                 ValNodeChoiceMatch, "field type",
14467                                 ChangeEditAECRActionQualType, dlg, FALSE);
14468   val_list = NULL;
14469   k = HiddenGroup (dlg->single_field_grp, 0, 0, NULL);
14470   dlg->single_field = FieldTypeDialog (k, FALSE, FALSE, ChangeEditAECRActionField, dlg);
14471   dlg->single_field_remove = FieldTypeDialog (k, FALSE, TRUE, ChangeEditAECRActionField, dlg);
14472   AlignObjects (ALIGN_CENTER, (HANDLE) (HANDLE) dlg->single_field, (HANDLE) dlg->single_field_remove, NULL);
14473   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->single_qual_type_dlg, k, NULL);
14474 
14475   dlg->field_pair_grp = HiddenGroup (field_grp, -1, 0, NULL);
14476   ValNodeAddPointer (&val_list, FieldType_source_qual, StringSave ("Source Qual"));
14477   ValNodeAddPointer (&val_list, FieldType_feature_field, StringSave ("Feature Qual"));
14478   ValNodeAddPointer (&val_list, FieldType_cds_gene_prot, StringSave ("CDS-Gene-Prot Qual"));
14479   ValNodeAddPointer (&val_list, FieldType_rna_field, StringSave ("RNA Qual"));
14480   ValNodeAddPointer (&val_list, FieldType_struc_comment_field, StringSave ("Structured Comment Field"));
14481   ValNodeAddPointer (&val_list, FieldType_molinfo_field, StringSave ("MolInfo Qual"));
14482   ValNodeAddPointer (&val_list, FieldType_dblink, StringSave ("DBLink"));
14483   dlg->pair_qual_type_dlg = ValNodeSelectionDialog (dlg->field_pair_grp, val_list, TALL_SELECTION_LIST, ValNodeStringName,
14484                                 ValNodeSimpleDataFree, ValNodeStringCopy,
14485                                 ValNodeChoiceMatch, "field type",
14486                                 ChangeEditAECRActionQualType, dlg, FALSE);
14487   val_list = NULL;
14488 
14489   k = HiddenGroup (dlg->field_pair_grp, 0, 0, NULL);
14490   dlg->field_pair = FieldPairTypeDialog (k, FALSE, ChangeEditAECRActionField, dlg);
14491   dlg->field_pair_convert = FieldPairTypeDialog (k, TRUE, ChangeEditAECRActionField, dlg);
14492   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->field_pair_convert, (HANDLE) dlg->field_pair, NULL);
14493   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->pair_qual_type_dlg, (HANDLE) k, NULL);
14494 
14495   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->single_field_grp, (HANDLE) dlg->field_pair_grp, NULL);
14496 
14497   Hide (dlg->single_field_grp);
14498   Hide (dlg->field_pair_grp);
14499 
14500   g = HiddenGroup (p, 0, 0, NULL);
14501   dlg->action_dlgs[0] = ApplyActionDialog (g, indexer_version, show_existing_text, NULL, NULL, change_notify, change_userdata, redraw_notify, redraw_userdata);
14502   SetAECRActionDlgFieldTypeDialogs (dlg->action_dlgs[0], dlg->single_qual_type_dlg, dlg->single_field);
14503   dlg->action_dlgs[1] = EditActionDialog (g, indexer_version, NULL, NULL, change_notify, change_userdata, redraw_notify, redraw_userdata);
14504   SetAECRActionDlgFieldTypeDialogs (dlg->action_dlgs[1], dlg->single_qual_type_dlg, dlg->single_field);
14505   dlg->action_dlgs[2] = ConvertActionDialog (g, indexer_version, show_existing_text, change_notify, change_userdata, redraw_notify, redraw_userdata);
14506   SetAECRActionDlgFieldTypeDialogs (dlg->action_dlgs[2], dlg->pair_qual_type_dlg, dlg->field_pair_convert);
14507   dlg->action_dlgs[3] = CopyActionDialog (g, indexer_version, show_existing_text, change_notify, change_userdata, redraw_notify, redraw_userdata);
14508   SetAECRActionDlgFieldTypeDialogs (dlg->action_dlgs[3], dlg->pair_qual_type_dlg, dlg->field_pair);
14509   dlg->action_dlgs[4] = SwapActionDialog (g, indexer_version, change_notify, change_userdata, redraw_notify, redraw_userdata);
14510   SetAECRActionDlgFieldTypeDialogs (dlg->action_dlgs[4], dlg->pair_qual_type_dlg, dlg->field_pair);
14511   dlg->action_dlgs[5] = AECRParseActionDialog (g, indexer_version, show_existing_text, change_notify, change_userdata, redraw_notify, redraw_userdata);
14512   SetAECRActionDlgFieldTypeDialogs (dlg->action_dlgs[5], dlg->pair_qual_type_dlg, dlg->field_pair);
14513   dlg->action_dlgs[6] = RemoveActionDialog (g, indexer_version, change_notify, change_userdata, redraw_notify, redraw_userdata);
14514   SetAECRActionDlgFieldTypeDialogs (dlg->action_dlgs[6], dlg->single_qual_type_dlg, dlg->single_field_remove);
14515   dlg->action_dlgs[7] = RemoveOutsideActionDialog (g, FALSE, NULL, NULL, change_notify, change_userdata, redraw_notify, redraw_userdata);
14516   SetAECRActionDlgFieldTypeDialogs (dlg->action_dlgs[7], dlg->single_qual_type_dlg, dlg->single_field);
14517 
14518   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->action_dlgs[0],
14519                               (HANDLE) dlg->action_dlgs[1],
14520                               (HANDLE) dlg->action_dlgs[2],
14521                               (HANDLE) dlg->action_dlgs[3],
14522                               (HANDLE) dlg->action_dlgs[4],
14523                               (HANDLE) dlg->action_dlgs[5],
14524                               (HANDLE) dlg->action_dlgs[6],
14525                               (HANDLE) dlg->action_dlgs[7],
14526                               NULL);
14527 
14528   dlg->also_change_mrna = CheckBox (p, "Make mRNA product match CDS protein name", NULL);
14529   Hide (dlg->also_change_mrna);
14530 
14531   dlg->constraint_dlg = ConstraintSetDialog (p, change_notify, change_userdata);
14532 
14533   AlignObjects (ALIGN_CENTER, (HANDLE) g,
14534                               (HANDLE) dlg->also_change_mrna,
14535                               (HANDLE) dlg->constraint_dlg,
14536                               NULL);
14537   return (DialoG) p;
14538 }
14539 
14540 
CreateFeatureWithImportFeatureQuals(Uint1 featdef_type,ValNodePtr fields)14541 static SeqFeatPtr CreateFeatureWithImportFeatureQuals (Uint1 featdef_type, ValNodePtr fields)
14542 {
14543   SeqFeatPtr sfp;
14544   ValNodePtr vnp;
14545   FeatQualLegalValPtr q;
14546   GBQualPtr gbq;
14547   CharPtr   qualname, cp;
14548 
14549   sfp = SeqFeatNew();
14550   sfp->idx.subtype = featdef_type;
14551   sfp->data.choice = FindFeatFromFeatDefType (sfp->idx.subtype);
14552 
14553   for (vnp = fields; vnp != NULL; vnp = vnp->next) {
14554     q = (FeatQualLegalValPtr) vnp->data.ptrvalue;
14555     if (q != NULL && q->qual != Feat_qual_legal_gene && q->qual != Feat_qual_legal_gene_description && q->qual != Feat_qual_legal_note) {
14556       gbq = GBQualNew ();
14557       qualname = StringSave (GetFeatQualName(q->qual));
14558       cp = StringChr (qualname, '-');
14559       while (cp != NULL) {
14560         *cp = '_';
14561         cp = StringChr (cp + 1, '-');
14562       }
14563       gbq->qual = qualname;
14564       gbq->val = StringSave (q->val);
14565       gbq->next = sfp->qual;
14566       sfp->qual = gbq;
14567     }
14568   }
14569   return sfp;
14570 }
14571 
14572 
FindFeatQualValue(ValNodePtr vnp,Int4 featqual)14573 static CharPtr FindFeatQualValue (ValNodePtr vnp, Int4 featqual)
14574 {
14575   FeatQualLegalValPtr q;
14576   CharPtr str = NULL;
14577   while (vnp != NULL && str == NULL) {
14578     q = (FeatQualLegalValPtr) vnp->data.ptrvalue;
14579     if (q != NULL && q->qual == featqual) {
14580       str = q->val;
14581     }
14582     vnp = vnp->next;
14583   }
14584   if (str == NULL) {
14585     str = "";
14586   }
14587   return str;
14588 }
14589 
14590 
SetFeatQualValue(ValNodePtr PNTR fields,Int4 featqual,CharPtr val)14591 static void SetFeatQualValue (ValNodePtr PNTR fields, Int4 featqual, CharPtr val)
14592 {
14593   FeatQualLegalValPtr q;
14594 
14595   q = FeatQualLegalValNew ();
14596   q->qual = featqual;
14597   q->val = StringSave (val);
14598   ValNodeAddPointer (fields, 1, q);
14599 }
14600 
14601 
AddGBQualsToActionFields(GBQualPtr gbq,ValNodePtr PNTR fields)14602 static void AddGBQualsToActionFields (GBQualPtr gbq, ValNodePtr PNTR fields)
14603 {
14604   Int4 qualtype;
14605 
14606   if (fields == NULL) return;
14607 
14608   while (gbq != NULL) {
14609     qualtype = GetFeatQualByName (gbq->qual);
14610     if (qualtype > -1) {
14611       SetFeatQualValue (fields, qualtype, gbq->val);
14612     }
14613     gbq = gbq->next;
14614   }
14615 }
14616 
14617 
ApplyFeatureDetailsNew(ApplyFeatureActionPtr action)14618 NLM_EXTERN ApplyFeatureDetailsPtr ApplyFeatureDetailsNew (ApplyFeatureActionPtr action)
14619 {
14620   ApplyFeatureDetailsPtr details;
14621 
14622   details = (ApplyFeatureDetailsPtr) MemNew (sizeof (ApplyFeatureDetailsData));
14623 
14624   if (action != NULL) {
14625     details->add_mrna = action->add_mrna;
14626     details->fields = AsnIoMemCopy (action->fields, (AsnReadFunc) FeatQualLegalSetAsnRead, (AsnWriteFunc) FeatQualLegalSetAsnWrite);
14627     details->src_fields = AsnIoMemCopy(action->src_fields, (AsnReadFunc) SourceQualValSetAsnRead, (AsnWriteFunc) SourceQualValSetAsnWrite);
14628   }
14629   return details;
14630 }
14631 
14632 
ApplyFeatureDetailsFree(ApplyFeatureDetailsPtr details)14633 NLM_EXTERN ApplyFeatureDetailsPtr ApplyFeatureDetailsFree (ApplyFeatureDetailsPtr details)
14634 {
14635   if (details != NULL) {
14636     details->fields = FeatQualLegalSetFree (details->fields);
14637     details->src_fields = SourceQualValSetFree (details->src_fields);
14638     details = MemFree (details);
14639   }
14640   return details;
14641 }
14642 
14643 
14644 typedef struct applyfeaturedetailsdlg {
14645   DIALOG_MESSAGE_BLOCK
14646 
14647   /* for CDS */
14648   ButtoN                   add_mrna;
14649   PopuP                    reading_frame;
14650   TexT                     protein_name;
14651   TexT                     protein_description;
14652 
14653   /* for RNA */
14654   DialoG                   ncrna_class;
14655   TexT                     rna_name;
14656 
14657   /* for import features */
14658   DialoG                   quals;
14659 
14660   /* for source features */
14661   DialoG                   src_quals;
14662 
14663   /* for all */
14664   TexT                     gene_locus;
14665   TexT                     gene_description;
14666   TexT                     comment;
14667 
14668   Uint2                    featdef_type;
14669   Nlm_ChangeNotifyProc     change_notify;
14670   Pointer                  change_userdata;
14671 } ApplyFeatureDetailsDlgData, PNTR ApplyFeatureDetailsDlgPtr;
14672 
14673 
ApplyFeatureDetailsToDialog(DialoG d,Pointer data)14674 static void ApplyFeatureDetailsToDialog (DialoG d, Pointer data)
14675 {
14676   ApplyFeatureDetailsDlgPtr dlg;
14677   ApplyFeatureDetailsPtr    details;
14678   CharPtr                   txt;
14679   BioSourcePtr              biop;
14680 
14681   dlg = (ApplyFeatureDetailsDlgPtr) GetObjectExtra (d);
14682   if (dlg == NULL) {
14683     return;
14684   }
14685   details = (ApplyFeatureDetailsPtr) data;
14686 
14687   if (data == NULL) {
14688     /* for CDS */
14689     SafeSetStatus (dlg->add_mrna, FALSE);
14690     SafeSetValue (dlg->reading_frame, 4);
14691     SafeSetTitle (dlg->protein_name, "");
14692     SafeSetTitle (dlg->protein_description, "");
14693 
14694     /* for RNA */
14695     PointerToDialog (dlg->ncrna_class, NULL);
14696     SafeSetTitle (dlg->rna_name, "");
14697 
14698     /* for import features */
14699     PointerToDialog (dlg->quals, NULL);
14700 
14701     /* for source features */
14702     PointerToDialog (dlg->src_quals, NULL);
14703 
14704     /* for all */
14705     SafeSetTitle (dlg->gene_locus, "");
14706     SafeSetTitle (dlg->gene_description, "");
14707     SafeSetTitle (dlg->comment, "");
14708   } else {
14709     /* for CDS */
14710     SafeSetStatus (dlg->add_mrna, details->add_mrna);
14711     txt = FindFeatQualValue (details->fields, Feat_qual_legal_codon_start);
14712     if (StringICmp (txt, "best") == 0) {
14713       SafeSetValue (dlg->reading_frame, 4);
14714     } else {
14715       SafeSetValue (dlg->reading_frame, atoi (txt));
14716     }
14717 
14718     SafeSetTitle (dlg->protein_name, FindFeatQualValue (details->fields, Feat_qual_legal_product));
14719     SafeSetTitle (dlg->protein_description, FindFeatQualValue (details->fields, Feat_qual_legal_description));
14720 
14721     /* for source feature */
14722     biop = BioSourceFromSourceQualVals (details->src_fields);
14723     PointerToDialog (dlg->src_quals, biop);
14724     biop = BioSourceFree (biop);
14725 
14726     /* for RNA */
14727     PointerToDialog (dlg->ncrna_class, FindFeatQualValue (details->fields, Feat_qual_legal_ncRNA_class));
14728     SafeSetTitle (dlg->rna_name, FindFeatQualValue (details->fields, Feat_qual_legal_product));
14729 
14730     /* for all */
14731     SafeSetTitle (dlg->gene_locus, FindFeatQualValue (details->fields, Feat_qual_legal_gene));
14732     SafeSetTitle (dlg->gene_description, FindFeatQualValue (details->fields, Feat_qual_legal_gene_description));
14733     SafeSetTitle (dlg->comment, FindFeatQualValue (details->fields, Feat_qual_legal_note));
14734   }
14735 
14736   if (dlg->change_notify != NULL) {
14737     (dlg->change_notify) (dlg->change_userdata);
14738   }
14739 }
14740 
DialogToApplyFeatureDetails(DialoG d)14741 static Pointer DialogToApplyFeatureDetails (DialoG d)
14742 {
14743   ApplyFeatureDetailsDlgPtr dlg;
14744   ApplyFeatureDetailsPtr    details;
14745   CharPtr                  txt;
14746   Char                     num[15];
14747   Int4                     frame;
14748   GBQualPtr                gbq;
14749   BioSourcePtr             biop;
14750 
14751   dlg = (ApplyFeatureDetailsDlgPtr) GetObjectExtra (d);
14752   if (dlg == NULL) {
14753     return NULL;
14754   }
14755 
14756   details = ApplyFeatureDetailsNew (NULL);
14757 
14758   /* for CDS */
14759   if (dlg->add_mrna != NULL && GetStatus (dlg->add_mrna)) {
14760     details->add_mrna = TRUE;
14761   } else {
14762     details->add_mrna = FALSE;
14763   }
14764 
14765   if (dlg->reading_frame != NULL) {
14766     frame = GetValue (dlg->reading_frame);
14767     if (frame > 0 && frame < 4) {
14768       sprintf (num, "%d", frame);
14769       SetFeatQualValue (&(details->fields), Feat_qual_legal_codon_start, num);
14770     } else {
14771       SetFeatQualValue (&(details->fields), Feat_qual_legal_codon_start, "best");
14772     }
14773   }
14774 
14775   if (dlg->protein_name != NULL && !TextHasNoText (dlg->protein_name)) {
14776     txt = SaveStringFromText (dlg->protein_name);
14777     SetFeatQualValue (&(details->fields), Feat_qual_legal_product, txt);
14778     txt = MemFree (txt);
14779   }
14780   if (dlg->protein_name != NULL && !TextHasNoText (dlg->protein_description)) {
14781     txt = SaveStringFromText (dlg->protein_description);
14782     SetFeatQualValue (&(details->fields), Feat_qual_legal_description, txt);
14783     txt = MemFree (txt);
14784   }
14785 
14786   /* for RNA */
14787   if (dlg->ncrna_class != NULL) {
14788     txt = DialogToPointer (dlg->ncrna_class);
14789     if (!StringHasNoText (txt)) {
14790       SetFeatQualValue (&(details->fields), Feat_qual_legal_ncRNA_class, txt);
14791     }
14792     txt = MemFree (txt);
14793   }
14794   if (dlg->rna_name != NULL && !TextHasNoText (dlg->rna_name)) {
14795     txt = SaveStringFromText (dlg->rna_name);
14796     SetFeatQualValue (&(details->fields), Feat_qual_legal_product, txt);
14797     txt = MemFree (txt);
14798   }
14799 
14800   /* for source features */
14801   if (dlg->src_quals != NULL) {
14802     biop = DialogToPointer (dlg->src_quals);
14803     details->src_fields = SourceQualValsFromBioSourcePtr (biop);
14804     biop = BioSourceFree (biop);
14805   }
14806 
14807   /* for import features */
14808   if (dlg->quals != NULL) {
14809     gbq = DialogToPointer (dlg->quals);
14810     AddGBQualsToActionFields (gbq, &(details->fields));
14811     gbq = GBQualFree (gbq);
14812   }
14813 
14814   /* for all */
14815   if (dlg->gene_locus != NULL && !TextHasNoText (dlg->gene_locus)) {
14816     txt = SaveStringFromText (dlg->gene_locus);
14817     SetFeatQualValue (&(details->fields), Feat_qual_legal_gene, txt);
14818     txt = MemFree (txt);
14819   }
14820   if (dlg->gene_description != NULL && !TextHasNoText (dlg->gene_description)) {
14821     txt = SaveStringFromText (dlg->gene_description);
14822     SetFeatQualValue (&(details->fields), Feat_qual_legal_gene_description, txt);
14823     txt = MemFree (txt);
14824   }
14825   if (dlg->comment != NULL && !TextHasNoText (dlg->comment)) {
14826     txt = SaveStringFromText (dlg->comment);
14827     SetFeatQualValue (&(details->fields), Feat_qual_legal_note, txt);
14828     txt = MemFree (txt);
14829   }
14830 
14831   return (Pointer) details;
14832 }
14833 
AddTextToComment(ButtoN b,CharPtr text)14834 static void AddTextToComment (ButtoN b, CharPtr text)
14835 {
14836   ApplyFeatureDetailsDlgPtr dlg;
14837   CharPtr                  orig_comment;
14838   CharPtr                  new_comment;
14839 
14840   dlg = (ApplyFeatureDetailsDlgPtr) GetObjectExtra (b);
14841   if (dlg == NULL || StringHasNoText (text))
14842   {
14843     return;
14844   }
14845 
14846   orig_comment = SaveStringFromText (dlg->comment);
14847   if (StringHasNoText (orig_comment))
14848   {
14849     SetTitle (dlg->comment, text);
14850   }
14851   else
14852   {
14853     new_comment = (CharPtr) MemNew ((StringLen (orig_comment) + StringLen (text) + 3) * sizeof (Char));
14854     if (new_comment != NULL)
14855     {
14856       StringCpy (new_comment, orig_comment);
14857       StringCat (new_comment, "; ");
14858       StringCat (new_comment, text);
14859       SetTitle (dlg->comment, new_comment);
14860       new_comment = MemFree (new_comment);
14861     }
14862   }
14863   orig_comment = MemFree (orig_comment);
14864 }
14865 
14866 
Add18SITS28SToComment(ButtoN b)14867 static void Add18SITS28SToComment (ButtoN b)
14868 {
14869   AddTextToComment (b, "contains 18S ribosomal RNA, internal transcribed spacer 1, 5.8S ribosomal RNA, internal transcribed spacer 2, and 28S ribosomal RNA");
14870 }
14871 
14872 
Add16SIGS23SToComment(ButtoN b)14873 static void Add16SIGS23SToComment (ButtoN b)
14874 {
14875   AddTextToComment (b, "contains 16S ribosomal RNA, 16S-23S ribosomal RNA intergenic spacer, and 23S ribosomal RNA");
14876 }
14877 
14878 
ChangeApplyFeatureDetailsBtn(ButtoN b)14879 static void ChangeApplyFeatureDetailsBtn (ButtoN b)
14880 {
14881   ApplyFeatureDetailsDlgPtr dlg;
14882 
14883   dlg = (ApplyFeatureDetailsDlgPtr) GetObjectExtra (b);
14884   if (dlg == NULL) {
14885     return;
14886   }
14887 
14888   if (dlg->change_notify != NULL) {
14889     (dlg->change_notify) (dlg->change_userdata);
14890   }
14891 }
14892 
14893 
ApplyFeatureDetailsDialog(GrouP h,Uint1 featdef_type,ApplyFeatureDetailsPtr details,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)14894 NLM_EXTERN DialoG ApplyFeatureDetailsDialog (GrouP h, Uint1 featdef_type, ApplyFeatureDetailsPtr details, Boolean indexer_version, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
14895 {
14896   ApplyFeatureDetailsDlgPtr dlg;
14897   GrouP                 p;
14898   GrouP                 r, frame_grp = NULL, comment_btns_grp = NULL;
14899   ButtoN                comment_btn;
14900   Int4                  seqfeattype;
14901   SeqFeatPtr            sfp;
14902 
14903   dlg = (ApplyFeatureDetailsDlgPtr) MemNew (sizeof (ApplyFeatureDetailsDlgData));
14904   p = HiddenGroup (h, -1, 0, NULL);
14905   SetGroupSpacing (p, 10, 10);
14906   SetObjectExtra (p, dlg, StdCleanupExtraProc);
14907 
14908   dlg->dialog = (DialoG) p;
14909   dlg->todialog = ApplyFeatureDetailsToDialog;
14910   dlg->fromdialog = DialogToApplyFeatureDetails;
14911   dlg->dialogmessage = NULL;
14912   dlg->change_notify = change_notify;
14913   dlg->change_userdata = change_userdata;
14914 
14915   dlg->featdef_type = featdef_type;
14916 
14917   seqfeattype = FindFeatFromFeatDefType (featdef_type);
14918 
14919   if (featdef_type == FEATDEF_CDS) {
14920     if (indexer_version) {
14921       dlg->add_mrna = CheckBox (p, "Also add mRNA", ChangeApplyFeatureDetailsBtn);
14922       SetObjectExtra (dlg->add_mrna, dlg, NULL);
14923     }
14924 
14925     frame_grp = HiddenGroup (p, 2, 0, NULL);
14926     StaticPrompt (frame_grp, "Reading Frame", 0, dialogTextHeight, programFont, 'l');
14927     dlg->reading_frame = PopupList (frame_grp, TRUE, NULL);
14928     PopupItem (dlg->reading_frame, "1");
14929     PopupItem (dlg->reading_frame, "2");
14930     PopupItem (dlg->reading_frame, "3");
14931     PopupItem (dlg->reading_frame, "Best");
14932     SetValue (dlg->reading_frame, 4);
14933   } else if (featdef_type == FEATDEF_source) {
14934     dlg->src_quals = BioSourceDialog (p);
14935   }
14936 
14937   r = HiddenGroup (p, 2, 0, NULL);
14938   if (featdef_type == FEATDEF_CDS) {
14939 
14940     StaticPrompt (r, "Protein Name", 0, dialogTextHeight, programFont, 'l');
14941     dlg->protein_name = DialogText (r, "", 20, NULL);
14942     StaticPrompt (r, "Protein Description", 0, dialogTextHeight, programFont, 'l');
14943     dlg->protein_description = DialogText (r, "", 20, NULL);
14944   } else if (seqfeattype == SEQFEAT_RNA) {
14945     /* RNA name */
14946     StaticPrompt (r, "RNA Name", 0, dialogTextHeight, programFont, 'l');
14947     dlg->rna_name = DialogText (r, "", 20, NULL);
14948     /* ncRNA class */
14949     if (featdef_type == FEATDEF_ncRNA) {
14950       StaticPrompt (r, "ncRNA Class", 0, dialogTextHeight, programFont, 'l');
14951       dlg->ncrna_class = CreatencRNAClassDialog (r, FALSE, NULL, NULL);
14952     }
14953   } else if (featdef_type != FEATDEF_GENE && featdef_type != FEATDEF_source) {
14954     StaticPrompt (r, "Qualifiers", 0, dialogTextHeight, programFont, 'l');
14955     sfp = CreateFeatureWithImportFeatureQuals (featdef_type, details == NULL ? NULL : details->fields);
14956     dlg->quals = NewCreateImportFields (r, GetFeatureNameFromFeatureType (GetFeatureTypeFromFeatdef(featdef_type)), sfp, FALSE);
14957     sfp = SeqFeatFree (sfp);
14958   }
14959 
14960   /* gene qualifiers ( for all ) */
14961   StaticPrompt (r, "Gene Locus", 0, dialogTextHeight, programFont, 'l');
14962   dlg->gene_locus = DialogText (r, "", 20, NULL);
14963   StaticPrompt (r, "Gene Description", 0, dialogTextHeight, programFont, 'l');
14964   dlg->gene_description = DialogText (r, "", 20, NULL);
14965   StaticPrompt (r, "Comment", 0, dialogTextHeight, programFont, 'l');
14966   dlg->comment = DialogText (r, "", 20, NULL);
14967   if ((featdef_type == FEATDEF_otherRNA || featdef_type == FEATDEF_misc_RNA) && indexer_version) {
14968     comment_btns_grp = HiddenGroup (p, 2, 0, NULL);
14969     comment_btn = PushButton (comment_btns_grp, "Add '18S-ITS-5.8S-ITS-28S' to comment", Add18SITS28SToComment);
14970     SetObjectExtra (comment_btn, dlg, NULL);
14971     comment_btn = PushButton (comment_btns_grp, "Add '16S-IGS-23S' to comment", Add16SIGS23SToComment);
14972     SetObjectExtra (comment_btn, dlg, NULL);
14973   }
14974 
14975   if (frame_grp != NULL) {
14976     AlignObjects (ALIGN_CENTER, (HANDLE) r,
14977                                 (HANDLE) frame_grp,
14978                                 (HANDLE) dlg->add_mrna,
14979                                 NULL);
14980   } else if (comment_btns_grp != NULL) {
14981     AlignObjects (ALIGN_CENTER, (HANDLE) r,
14982                                 (HANDLE) comment_btns_grp,
14983                                 NULL);
14984   } else if (dlg->src_quals != NULL) {
14985     AlignObjects (ALIGN_CENTER, (HANDLE) r,
14986                                 (HANDLE) dlg->src_quals,
14987                                 NULL);
14988   } else {
14989     AlignObjects (ALIGN_CENTER, (HANDLE) r,
14990                                 NULL);
14991   }
14992   return (DialoG) p;
14993 }
14994 
14995 
14996 typedef struct applyfeatureactiondlg {
14997   DIALOG_MESSAGE_BLOCK
14998   DialoG                   feature_type_dlg;
14999   ButtoN                   apply_to_parts;
15000   TexT                     only_this_part;
15001   ButtoN                   partial5;
15002   ButtoN                   partial3;
15003   GrouP                    strand_group;
15004   GrouP                    use_whole_interval;
15005   TexT                     left_end;
15006   TexT                     right_end;
15007   GrouP                    all_or_some_group;
15008   TexT                     accession_list_txt;
15009   ButtoN                   add_redundant;
15010 
15011   DialoG                   details;
15012 
15013   Nlm_ChangeNotifyProc     change_notify;
15014   Pointer                  change_userdata;
15015 
15016 
15017 } ApplyFeatureActionDlgData, PNTR ApplyFeatureActionDlgPtr;
15018 
15019 
TestApplyFeatureActionDialog(DialoG d)15020 static ValNodePtr TestApplyFeatureActionDialog (DialoG d)
15021 {
15022   ApplyFeatureActionDlgPtr dlg;
15023   ValNodePtr err_list = NULL;
15024 
15025   dlg = (ApplyFeatureActionDlgPtr) GetObjectExtra (d);
15026   if (dlg == NULL) {
15027     return NULL;
15028   }
15029 
15030   err_list = TestDialog (dlg->feature_type_dlg);
15031 
15032   return err_list;
15033 }
15034 
15035 
ChangeApplyFeatureActionDlg(ApplyFeatureActionDlgPtr dlg)15036 static void ChangeApplyFeatureActionDlg (ApplyFeatureActionDlgPtr dlg)
15037 {
15038   if (dlg == NULL) return;
15039 
15040   if (GetStatus (dlg->apply_to_parts)) {
15041     SafeEnable (dlg->only_this_part);
15042   } else {
15043     SafeDisable (dlg->only_this_part);
15044   }
15045 
15046   if (dlg->use_whole_interval != NULL) {
15047     if (GetValue (dlg->use_whole_interval) == 2) {
15048       Enable (dlg->left_end);
15049       Enable (dlg->right_end);
15050     } else {
15051       Disable (dlg->left_end);
15052       Disable (dlg->right_end);
15053     }
15054   }
15055 
15056   if (dlg->all_or_some_group != NULL) {
15057     if (GetValue (dlg->all_or_some_group) == 2) {
15058       Enable (dlg->accession_list_txt);
15059     } else {
15060       Disable (dlg->accession_list_txt);
15061     }
15062   }
15063 
15064   if (dlg->change_notify != NULL) {
15065     (dlg->change_notify) (dlg->change_userdata);
15066   }
15067 }
15068 
15069 
SequenceListWrite(ValNodePtr seq_list)15070 static CharPtr SequenceListWrite (ValNodePtr seq_list)
15071 {
15072   Int4 len = 0;
15073   ValNodePtr vnp;
15074   CharPtr    txt = NULL;
15075 
15076   if (seq_list == NULL) return NULL;
15077   for (vnp = seq_list; vnp != NULL; vnp = vnp->next) {
15078     len += StringLen (vnp->data.ptrvalue) + 2;
15079   }
15080 
15081   txt = (CharPtr) MemNew (sizeof (Char) * len);
15082   for (vnp = seq_list; vnp != NULL; vnp = vnp->next) {
15083     StringCat (txt, vnp->data.ptrvalue);
15084     if (vnp->next != NULL) {
15085       StringCat (txt, ";");
15086     }
15087   }
15088   return txt;
15089 }
15090 
15091 
SequenceListCollect(CharPtr txt)15092 static ValNodePtr SequenceListCollect (CharPtr txt)
15093 {
15094   ValNodePtr seq_list = NULL;
15095   CharPtr    cp;
15096 
15097   if (StringHasNoText (txt)) {
15098     return NULL;
15099   }
15100   cp = StringChr (txt, ';');
15101   while (cp != NULL && *txt != 0) {
15102     *cp = 0;
15103     if (!StringHasNoText (txt)) {
15104       ValNodeAddPointer (&seq_list, 0, StringSave (txt));
15105     }
15106     *cp = ';';
15107     txt = cp + 1;
15108     cp = StringChr (txt, ':');
15109   }
15110   if (!StringHasNoText (txt)) {
15111     ValNodeAddPointer (&seq_list, 0, StringSave (txt));
15112   }
15113   return seq_list;
15114 }
15115 
15116 
ApplyFeatureActionToDialog(DialoG d,Pointer data)15117 static void ApplyFeatureActionToDialog (DialoG d, Pointer data)
15118 {
15119   ApplyFeatureActionDlgPtr dlg;
15120   ApplyFeatureActionPtr    action;
15121   Char                     num[20];
15122   LocationIntervalPtr      lint;
15123   CharPtr                  txt;
15124   ValNode                  vn;
15125   ApplyFeatureDetailsPtr   details;
15126 
15127   dlg = (ApplyFeatureActionDlgPtr) GetObjectExtra (d);
15128   if (dlg == NULL) {
15129     return;
15130   }
15131 
15132   action = (ApplyFeatureActionPtr) data;
15133 
15134   if (action == NULL) {
15135     PointerToDialog (dlg->feature_type_dlg, NULL);
15136     SetStatus (dlg->apply_to_parts, FALSE);
15137     SetTitle (dlg->only_this_part, "");
15138     SetStatus (dlg->partial5, FALSE);
15139     SetStatus (dlg->partial3, FALSE);
15140     SetValue (dlg->strand_group, 1);
15141     SetValue (dlg->use_whole_interval, 1);
15142     SetTitle (dlg->left_end, "");
15143     SetTitle (dlg->right_end, "");
15144     SetValue (dlg->all_or_some_group, 1);
15145     SetTitle (dlg->accession_list_txt, "");
15146     SetStatus (dlg->add_redundant, FALSE);
15147 
15148   } else {
15149     vn.choice = (Uint1) action->type;
15150     vn.next = NULL;
15151     vn.data.ptrvalue = NULL;
15152     PointerToDialog (dlg->feature_type_dlg, &vn);
15153 
15154     SetStatus (dlg->apply_to_parts, action->apply_to_parts);
15155     if (action->only_seg_num > -1) {
15156       sprintf (num, "%d", action->only_seg_num);
15157       SetTitle (dlg->only_this_part, num);
15158     } else {
15159       SetTitle (dlg->only_this_part, "");
15160     }
15161     SetStatus (dlg->partial5, action->partial5);
15162     SetStatus (dlg->partial3, action->partial3);
15163     if (action->plus_strand) {
15164       SetValue (dlg->strand_group, 1);
15165     } else {
15166       SetValue (dlg->strand_group, 2);
15167     }
15168     if (action->location == NULL || action->location->choice == LocationChoice_whole_sequence) {
15169       SetValue (dlg->use_whole_interval, 1);
15170       SetTitle (dlg->left_end, "");
15171       SetTitle (dlg->right_end, "");
15172     } else {
15173       SetValue (dlg->use_whole_interval, 2);
15174       if (action->location->choice == LocationChoice_interval) {
15175         lint = (LocationIntervalPtr) action->location->data.ptrvalue;
15176         if (lint == NULL) {
15177           SetTitle (dlg->left_end, "");
15178           SetTitle (dlg->right_end, "");
15179         } else {
15180           sprintf (num, "%d", lint->from);
15181           SetTitle (dlg->left_end, num);
15182           sprintf (num, "%d", lint->to);
15183           SetTitle (dlg->right_end, num);
15184         }
15185       } else if (action->location->choice == LocationChoice_point) {
15186         sprintf (num, "%d^", action->location->data.intvalue);
15187         SetTitle (dlg->left_end, num);
15188         sprintf (num, "%d", action->location->data.intvalue + 1);
15189         SetTitle (dlg->right_end, num);
15190       } else {
15191         SetTitle (dlg->left_end, "");
15192         SetTitle (dlg->right_end, "");
15193       }
15194     }
15195 
15196     if (action->seq_list == NULL || action->seq_list->choice == SequenceListChoice_all) {
15197       SetValue (dlg->all_or_some_group, 1);
15198       SetTitle (dlg->accession_list_txt, "");
15199     } else {
15200       txt = SequenceListWrite (action->seq_list->data.ptrvalue);
15201       SetValue (dlg->all_or_some_group, 2);
15202       SetTitle (dlg->accession_list_txt, txt);
15203       txt = MemFree (txt);
15204     }
15205 
15206     SetStatus (dlg->add_redundant, action->add_redundant);
15207   }
15208 
15209   details = ApplyFeatureDetailsNew (action);
15210   PointerToDialog (dlg->details, details);
15211   details = ApplyFeatureDetailsFree (details);
15212   ChangeApplyFeatureActionDlg (dlg);
15213   if (dlg->change_notify != NULL) {
15214     (dlg->change_notify) (dlg->change_userdata);
15215   }
15216 }
15217 
15218 
DialogToApplyFeatureAction(DialoG d)15219 static Pointer DialogToApplyFeatureAction (DialoG d)
15220 {
15221   ApplyFeatureActionDlgPtr dlg;
15222   ApplyFeatureActionPtr    action;
15223   CharPtr                  num_txt;
15224   LocationIntervalPtr      lint;
15225   ValNodePtr               vnp;
15226   ApplyFeatureDetailsPtr   details;
15227 
15228   dlg = (ApplyFeatureActionDlgPtr) GetObjectExtra (d);
15229   if (dlg == NULL) {
15230     return NULL;
15231   }
15232 
15233   vnp = DialogToPointer (dlg->feature_type_dlg);
15234   if (vnp == NULL) {
15235     return NULL;
15236   }
15237 
15238   action = ApplyFeatureActionNew();
15239 
15240   action->type = vnp->choice;
15241   vnp = ValNodeFree (vnp);
15242 
15243   action->apply_to_parts = GetStatus (dlg->apply_to_parts);
15244   if (action->apply_to_parts && !TextHasNoText (dlg->only_this_part)) {
15245     num_txt = SaveStringFromText (dlg->only_this_part);
15246     action->only_seg_num = atoi (num_txt);
15247     num_txt = MemFree (num_txt);
15248   }
15249 
15250   action->partial5 = GetStatus (dlg->partial5);
15251   action->partial3 = GetStatus (dlg->partial3);
15252   if (GetValue (dlg->strand_group) == 1) {
15253     action->plus_strand = TRUE;
15254   } else {
15255     action->plus_strand = FALSE;
15256   }
15257 
15258   if (GetValue (dlg->use_whole_interval) == 1) {
15259     action->location = ValNodeNew(NULL);
15260     action->location->choice = LocationChoice_whole_sequence;
15261   } else {
15262     num_txt = SaveStringFromText (dlg->left_end);
15263     if (num_txt != NULL && num_txt[StringLen(num_txt) - 1] == '^') {
15264       action->location = ValNodeNew(NULL);
15265       action->location->choice = LocationChoice_point;
15266       action->location->data.intvalue = atoi (num_txt);
15267       num_txt = MemFree (num_txt);
15268     } else {
15269       num_txt = MemFree (num_txt);
15270       num_txt = SaveStringFromText (dlg->right_end);
15271       if (num_txt != NULL && num_txt[0] == '^') {
15272         action->location = ValNodeNew(NULL);
15273         action->location->choice = LocationChoice_point;
15274         action->location->data.intvalue = atoi (num_txt + 1) - 1;
15275         num_txt = MemFree (num_txt);
15276       } else {
15277         num_txt = MemFree (num_txt);
15278         lint = LocationIntervalNew ();
15279         num_txt = SaveStringFromText (dlg->left_end);
15280         lint->from = atoi (num_txt);
15281         num_txt = MemFree (num_txt);
15282         num_txt = SaveStringFromText (dlg->right_end);
15283         lint->to = atoi (num_txt);
15284         num_txt = MemFree (num_txt);
15285         action->location = ValNodeNew(NULL);
15286         action->location->choice = LocationChoice_interval;
15287         action->location->data.ptrvalue = lint;
15288       }
15289     }
15290   }
15291   if (GetValue (dlg->all_or_some_group) == 1) {
15292     action->seq_list = ValNodeNew(NULL);
15293     action->seq_list->choice = SequenceListChoice_all;
15294   } else {
15295     num_txt = SaveStringFromText (dlg->accession_list_txt);
15296     action->seq_list = ValNodeNew(NULL);
15297     action->seq_list->choice = SequenceListChoice_list;
15298     action->seq_list->data.ptrvalue = SequenceListCollect (num_txt);
15299     num_txt = MemFree (num_txt);
15300   }
15301 
15302   action->add_redundant = GetStatus (dlg->add_redundant);
15303 
15304   details = DialogToPointer (dlg->details);
15305   action->add_mrna = details->add_mrna;
15306   action->fields = details->fields;
15307   details->fields = NULL;
15308   action->src_fields = details->src_fields;
15309   details->src_fields = NULL;
15310   details = ApplyFeatureDetailsFree (details);
15311 
15312   return action;
15313 }
15314 
15315 
ChangeApplyFeatureActionDlgBtn(ButtoN b)15316 static void ChangeApplyFeatureActionDlgBtn (ButtoN b)
15317 {
15318   ApplyFeatureActionDlgPtr dlg;
15319 
15320   dlg = (ApplyFeatureActionDlgPtr) GetObjectExtra (b);
15321   if (dlg == NULL) return;
15322   ChangeApplyFeatureActionDlg (dlg);
15323 }
15324 
15325 
ChangeApplyFeatureActionDlgGrp(GrouP g)15326 static void ChangeApplyFeatureActionDlgGrp (GrouP g)
15327 {
15328   ApplyFeatureActionDlgPtr dlg;
15329 
15330   dlg = (ApplyFeatureActionDlgPtr) GetObjectExtra (g);
15331   if (dlg == NULL) return;
15332   ChangeApplyFeatureActionDlg (dlg);
15333 }
15334 
15335 
15336 static DialoG
ApplyFeatureActionDialog(GrouP h,ApplyFeatureActionPtr action,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Nlm_ChangeNotifyProc redraw_notify,Pointer redraw_userdata)15337 ApplyFeatureActionDialog
15338 (GrouP h,
15339  ApplyFeatureActionPtr action,
15340  Boolean indexer_version,
15341  Nlm_ChangeNotifyProc     change_notify,
15342  Pointer                  change_userdata,
15343  Nlm_ChangeNotifyProc     redraw_notify,
15344  Pointer                  redraw_userdata)
15345 {
15346   ApplyFeatureActionDlgPtr dlg;
15347   GrouP                 p, g, parts_group, x, indexer_only_group = NULL;
15348   GrouP                 r2, r3, r4;
15349   ValNodePtr            feature_type_list = NULL;
15350   ApplyFeatureDetailsPtr details;
15351 
15352   dlg = (ApplyFeatureActionDlgPtr) MemNew (sizeof (ApplyFeatureActionDlgData));
15353   p = HiddenGroup (h, -1, 0, NULL);
15354   SetGroupSpacing (p, 10, 10);
15355   SetObjectExtra (p, dlg, StdCleanupExtraProc);
15356 
15357   dlg->dialog = (DialoG) p;
15358   dlg->todialog = ApplyFeatureActionToDialog;
15359   dlg->fromdialog = DialogToApplyFeatureAction;
15360   dlg->dialogmessage = NULL;
15361   dlg->testdialog = TestApplyFeatureActionDialog;
15362   dlg->change_notify = change_notify;
15363   dlg->change_userdata = change_userdata;
15364 
15365   ValNodeAddPointer (&feature_type_list, Macro_feature_type_cds, StringSave ("CDS"));
15366   ValNodeAddPointer (&feature_type_list, Macro_feature_type_gene, StringSave ("gene"));
15367   ValNodeAddPointer (&feature_type_list, Macro_feature_type_preRNA, StringSave ("precursor RNA"));
15368   ValNodeAddPointer (&feature_type_list, Macro_feature_type_mRNA, StringSave ("mRNA"));
15369   ValNodeAddPointer (&feature_type_list, Macro_feature_type_tRNA, StringSave ("tRNA"));
15370   ValNodeAddPointer (&feature_type_list, Macro_feature_type_rRNA, StringSave ("rRNA"));
15371   ValNodeAddPointer (&feature_type_list, Macro_feature_type_snRNA, StringSave ("snRNA"));
15372   ValNodeAddPointer (&feature_type_list, Macro_feature_type_scRNA, StringSave ("scRNA"));
15373   ValNodeAddPointer (&feature_type_list, Macro_feature_type_otherRNA, StringSave ("misc RNA"));
15374   ValNodeAddPointer (&feature_type_list, Macro_feature_type_ncRNA, StringSave ("ncRNA"));
15375   ValNodeAddPointer (&feature_type_list, Macro_feature_type_tmRNA, StringSave ("tmRNA"));
15376   AddImportFeaturesToChoiceList (&feature_type_list);
15377 
15378   /* note - the ValNodeSelectionDialog will free feature_type_list when done */
15379   dlg->feature_type_dlg = ValNodeSelectionDialog (p, feature_type_list, TALL_SELECTION_LIST, ValNodeStringName,
15380                                 ValNodeSimpleDataFree, ValNodeStringCopy,
15381                                 ValNodeChoiceMatch, "feature type",
15382                                 redraw_notify, redraw_userdata, FALSE);
15383 
15384   parts_group = HiddenGroup (p, 1, 0, NULL);
15385   dlg->apply_to_parts = CheckBox (parts_group, "Apply to segmented parts, not segmented sequence", ChangeApplyFeatureActionDlgBtn);
15386   SetObjectExtra (dlg->apply_to_parts, dlg, NULL);
15387   x = HiddenGroup (parts_group, 2, 0, NULL);
15388   StaticPrompt (x, "Apply only to particular numbered segment", 0, dialogTextHeight, programFont, 'l');
15389   dlg->only_this_part = DialogText (x, "", 4, NULL);
15390   Disable (dlg->only_this_part);
15391 
15392 
15393   g = HiddenGroup (p, 2, 0, NULL);
15394   dlg->partial5 = CheckBox (g, "Incomplete at 5' end", NULL);
15395   dlg->partial3 = CheckBox (g, "Incomplete at 3' end", NULL);
15396 
15397   /* group for strand */
15398   dlg->strand_group = HiddenGroup (p, 2, 0, NULL);
15399   SetObjectExtra (dlg->strand_group, dlg, NULL);
15400   RadioButton (dlg->strand_group, "Plus Strand");
15401   RadioButton (dlg->strand_group, "Minus Strand");
15402   SetValue (dlg->strand_group, 1);
15403 
15404   /* coordinates */
15405   if (indexer_version)
15406   {
15407     indexer_only_group = HiddenGroup (p, -1, 0, NULL);
15408     r2 = HiddenGroup (indexer_only_group, 5, 0, NULL);
15409     dlg->use_whole_interval = HiddenGroup (r2, 0, 2, ChangeApplyFeatureActionDlgGrp);
15410     SetObjectExtra (dlg->use_whole_interval, dlg, NULL);
15411     RadioButton (dlg->use_whole_interval, "Use Whole Sequence Interval");
15412     RadioButton (dlg->use_whole_interval, "Use these coordinates:");
15413     r3 = HiddenGroup (r2, 0, 2, NULL);
15414     StaticPrompt (r3, "", 0, dialogTextHeight, programFont, 'l');
15415     r4 = HiddenGroup (r3, 4, 0, NULL);
15416     StaticPrompt (r4, "From", 0, dialogTextHeight, programFont, 'l');
15417     dlg->left_end = DialogText (r4, "1", 5, NULL);
15418     StaticPrompt (r4, "To", 0, dialogTextHeight, programFont, 'l');
15419     dlg->right_end = DialogText (r4, "1", 5, NULL);
15420     SetValue (dlg->use_whole_interval, 1);
15421 
15422     /* apply to some sequences or all sequences */
15423     dlg->all_or_some_group = HiddenGroup (indexer_only_group, 1, 0, ChangeApplyFeatureActionDlgGrp);
15424     SetObjectExtra (dlg->all_or_some_group, dlg, NULL);
15425     RadioButton (dlg->all_or_some_group, "Apply to all sequences");
15426     RadioButton (dlg->all_or_some_group, "Apply to sequences in this list");
15427     dlg->accession_list_txt = DialogText (dlg->all_or_some_group, "", 25, NULL);
15428     SetValue (dlg->all_or_some_group, 1);
15429 
15430     dlg->add_redundant = CheckBox (indexer_only_group, "Add even if feature of same type already present", ChangeApplyFeatureActionDlgBtn);
15431     SetObjectExtra (dlg->add_redundant, dlg, NULL);
15432 
15433     AlignObjects (ALIGN_CENTER, (HANDLE) r2, (HANDLE) dlg->all_or_some_group, (HANDLE) dlg->add_redundant, NULL);
15434   }
15435 
15436   details = ApplyFeatureDetailsNew (action);
15437   dlg->details = ApplyFeatureDetailsDialog (p, action == NULL ? FEATDEF_CDS : GetFeatdefFromFeatureType(action->type),
15438                                             details, indexer_version, change_notify, change_userdata);
15439   details = ApplyFeatureDetailsFree (details);
15440 
15441   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->feature_type_dlg,
15442                               (HANDLE) parts_group,
15443                               (HANDLE) g,
15444                               (HANDLE) dlg->strand_group,
15445                               (HANDLE) dlg->details,
15446                               (HANDLE) indexer_only_group,
15447                               NULL);
15448 
15449   return (DialoG) p;
15450 }
15451 
15452 
15453 typedef struct removefeatureactiondlg {
15454   DIALOG_MESSAGE_BLOCK
15455   DialoG                   feature_type_dlg;
15456   DialoG                   constraint_dlg;
15457   Nlm_ChangeNotifyProc     change_notify;
15458   Pointer                  change_userdata;
15459 } RemoveFeatureActionDlgData, PNTR RemoveFeatureActionDlgPtr;
15460 
15461 
RemoveFeatureActionToDialog(DialoG d,Pointer data)15462 static void RemoveFeatureActionToDialog (DialoG d, Pointer data)
15463 {
15464   RemoveFeatureActionDlgPtr dlg;
15465   RemoveFeatureActionPtr    action;
15466   ValNode                   vn;
15467 
15468   dlg = (RemoveFeatureActionDlgPtr) GetObjectExtra (d);
15469   if (dlg == NULL) return;
15470 
15471   action = (RemoveFeatureActionPtr) data;
15472   if (action == NULL) {
15473     PointerToDialog (dlg->feature_type_dlg, NULL);
15474     PointerToDialog (dlg->constraint_dlg, NULL);
15475   } else {
15476     vn.choice = (Uint1)action->type;
15477     vn.data.ptrvalue = NULL;
15478     vn.next = NULL;
15479     PointerToDialog (dlg->feature_type_dlg, &vn);
15480     PointerToDialog (dlg->constraint_dlg, action->constraint);
15481   }
15482 
15483 }
15484 
15485 
DialogToRemoveFeatureAction(DialoG d)15486 static Pointer DialogToRemoveFeatureAction (DialoG d)
15487 {
15488   RemoveFeatureActionDlgPtr dlg;
15489   RemoveFeatureActionPtr    action;
15490   ValNodePtr                vnp;
15491 
15492   dlg = (RemoveFeatureActionDlgPtr) GetObjectExtra (d);
15493   if (dlg == NULL) return NULL;
15494 
15495   vnp = DialogToPointer (dlg->feature_type_dlg);
15496   if (vnp == NULL) return NULL;
15497 
15498   action = RemoveFeatureActionNew ();
15499   action->type = vnp->choice;
15500   vnp = ValNodeFree (vnp);
15501   action->constraint = DialogToPointer (dlg->constraint_dlg);
15502   return action;
15503 }
15504 
15505 
TestRemoveFeatureActionDialog(DialoG d)15506 static ValNodePtr TestRemoveFeatureActionDialog (DialoG d)
15507 {
15508   RemoveFeatureActionDlgPtr dlg;
15509   dlg = (RemoveFeatureActionDlgPtr) GetObjectExtra (d);
15510   if (dlg == NULL) return NULL;
15511   return TestDialog (dlg->feature_type_dlg);
15512 }
15513 
15514 
15515 static DialoG
RemoveFeatureActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)15516 RemoveFeatureActionDialog
15517 (GrouP h,
15518  Boolean indexer_version,
15519  Nlm_ChangeNotifyProc     change_notify,
15520  Pointer                  change_userdata)
15521 {
15522   RemoveFeatureActionDlgPtr dlg;
15523   GrouP                     p;
15524 
15525   dlg = (RemoveFeatureActionDlgPtr) MemNew (sizeof (RemoveFeatureActionDlgData));
15526   p = HiddenGroup (h, -1, 0, NULL);
15527   SetGroupSpacing (p, 10, 10);
15528   SetObjectExtra (p, dlg, StdCleanupExtraProc);
15529 
15530   dlg->dialog = (DialoG) p;
15531   dlg->todialog = RemoveFeatureActionToDialog;
15532   dlg->fromdialog = DialogToRemoveFeatureAction;
15533   dlg->dialogmessage = NULL;
15534   dlg->testdialog = TestRemoveFeatureActionDialog;
15535   dlg->change_notify = change_notify;
15536   dlg->change_userdata = change_userdata;
15537 
15538   dlg->feature_type_dlg = FeatureTypeDialogMulti (p, change_notify, change_userdata);
15539   dlg->constraint_dlg = ConstraintSetDialog (p, change_notify, change_userdata);
15540 
15541   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->feature_type_dlg, (HANDLE) dlg->constraint_dlg, NULL);
15542 
15543   return (DialoG) p;
15544 }
15545 
15546 
15547 typedef struct convertfromcdsoptionsdlg {
15548   DIALOG_MESSAGE_BLOCK
15549   ButtoN remove_mRNA;
15550   ButtoN remove_gene;
15551   ButtoN remove_transcript_id;
15552   Nlm_ChangeNotifyProc     change_notify;
15553   Pointer                  change_userdata;
15554 } ConvertFromCDSOptionsDlgData, PNTR ConvertFromCDSOptionsDlgPtr;
15555 
PointerToConvertFromCDSOptionsDialog(DialoG d,Pointer data)15556 static void PointerToConvertFromCDSOptionsDialog (DialoG d, Pointer data)
15557 {
15558   ConvertFromCDSOptionsDlgPtr dlg;
15559   ConvertFromCDSOptionsPtr    options;
15560 
15561   dlg = (ConvertFromCDSOptionsDlgPtr) GetObjectExtra (d);
15562   if (dlg == NULL) return;
15563 
15564   options = (ConvertFromCDSOptionsPtr) data;
15565   if (options == NULL) {
15566     SetStatus (dlg->remove_mRNA, FALSE);
15567     SetStatus (dlg->remove_gene, FALSE);
15568     SetStatus (dlg->remove_transcript_id, FALSE);
15569   } else {
15570     SetStatus (dlg->remove_mRNA, options->remove_mRNA);
15571     SetStatus (dlg->remove_gene, options->remove_gene);
15572     SetStatus (dlg->remove_transcript_id, options->remove_transcript_id);
15573   }
15574   if (dlg->change_notify != NULL) {
15575     (dlg->change_notify) (dlg->change_userdata);
15576   }
15577 }
15578 
ConvertFromCDSOptionsDialogToPointer(DialoG d)15579 static Pointer ConvertFromCDSOptionsDialogToPointer (DialoG d)
15580 {
15581   ConvertFromCDSOptionsDlgPtr dlg;
15582   ConvertFromCDSOptionsPtr    options;
15583 
15584   dlg = (ConvertFromCDSOptionsDlgPtr) GetObjectExtra (d);
15585   if (dlg == NULL) return NULL;
15586 
15587   options = ConvertFromCDSOptionsNew ();
15588   options->remove_mRNA = GetStatus (dlg->remove_mRNA);
15589   options->remove_gene = GetStatus (dlg->remove_gene);
15590   options->remove_transcript_id = GetStatus (dlg->remove_transcript_id);
15591   return (Pointer) options;
15592 }
15593 
15594 
ChangeConvertFromCDSOptionsBtn(ButtoN b)15595 static void ChangeConvertFromCDSOptionsBtn (ButtoN b)
15596 {
15597   ConvertFromCDSOptionsDlgPtr dlg;
15598   dlg = (ConvertFromCDSOptionsDlgPtr) GetObjectExtra (b);
15599   if (dlg != NULL) {
15600     if (dlg->change_notify != NULL) {
15601       (dlg->change_notify) (dlg->change_userdata);
15602     }
15603   }
15604 }
15605 
15606 
ConvertFromCDSOptionsDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)15607 static DialoG ConvertFromCDSOptionsDialog
15608 (GrouP h,
15609  Nlm_ChangeNotifyProc     change_notify,
15610  Pointer                  change_userdata)
15611 {
15612   ConvertFromCDSOptionsDlgPtr dlg;
15613   GrouP                       p;
15614 
15615   dlg = (ConvertFromCDSOptionsDlgPtr) MemNew (sizeof (ConvertFromCDSOptionsDlgData));
15616   p = HiddenGroup (h, 3, 0, NULL);
15617   SetGroupSpacing (p, 10, 10);
15618   SetObjectExtra (p, dlg, StdCleanupExtraProc);
15619 
15620   dlg->dialog = (DialoG) p;
15621   dlg->todialog = PointerToConvertFromCDSOptionsDialog;
15622   dlg->fromdialog = ConvertFromCDSOptionsDialogToPointer;
15623   dlg->dialogmessage = NULL;
15624   dlg->testdialog = NULL;
15625   dlg->change_notify = change_notify;
15626   dlg->change_userdata = change_userdata;
15627 
15628   dlg->remove_mRNA = CheckBox (p, "Remove overlapping mRNA", ChangeConvertFromCDSOptionsBtn);
15629   SetObjectExtra (dlg->remove_mRNA, dlg, NULL);
15630   dlg->remove_gene = CheckBox (p, "Remove overlapping gene", ChangeConvertFromCDSOptionsBtn);
15631   SetObjectExtra (dlg->remove_gene, dlg, NULL);
15632   dlg->remove_transcript_id = CheckBox (p, "Remove transcript ID", ChangeConvertFromCDSOptionsBtn);
15633   SetObjectExtra (dlg->remove_transcript_id, dlg, NULL);
15634 
15635   return (DialoG) p;
15636 }
15637 
15638 
15639 typedef struct convertfeatureactiondlg {
15640   DIALOG_MESSAGE_BLOCK
15641   DialoG                   feature_type_from_dlg;
15642   DialoG                   feature_type_to_dlg;
15643   PrompT                   supported;
15644 
15645   DialoG                   cds_options;
15646   DialoG                   bond_type;
15647   DialoG                   site_type;
15648   ButtoN                   create_prot_regions;
15649   DialoG                   ncrna_class_dlg;
15650 
15651   ButtoN                   leave_original;
15652 
15653   DialoG                   constraint_dlg;
15654   Nlm_ChangeNotifyProc     change_notify;
15655   Pointer                  change_userdata;
15656 } ConvertFeatureActionDlgData, PNTR ConvertFeatureActionDlgPtr;
15657 
15658 
15659 
ChangeConvertFeatureType(Pointer data)15660 static void ChangeConvertFeatureType (Pointer data)
15661 {
15662   ConvertFeatureActionDlgPtr dlg;
15663   ValNodePtr                 vnp;
15664   Uint2                      type_from = 0, type_to = 0;
15665 
15666   dlg = (ConvertFeatureActionDlgPtr) data;
15667   if (dlg == NULL) return;
15668 
15669   /* if from choice is coding region, show coding region options */
15670   vnp = DialogToPointer (dlg->feature_type_from_dlg);
15671   if (vnp == NULL || vnp->choice != Macro_feature_type_cds) {
15672     Hide (dlg->cds_options);
15673   } else {
15674     Show (dlg->cds_options);
15675   }
15676   if (vnp != NULL) {
15677     type_from = vnp->choice;
15678   }
15679   vnp = ValNodeFree (vnp);
15680 
15681   /* dst options */
15682   /* if to choice is bond, show bond options */
15683   /* if to choice is site, show site options */
15684   /* if to choice is region, show region checkbox */
15685   /* if to choice is ncRNA, show ncRNA_class choice */
15686   vnp = DialogToPointer (dlg->feature_type_to_dlg);
15687   Hide (dlg->bond_type);
15688   Hide (dlg->site_type);
15689   Hide (dlg->create_prot_regions);
15690   Hide (dlg->ncrna_class_dlg);
15691   if (vnp == NULL) {
15692     /* do nothing */
15693   } else if (vnp->choice == Macro_feature_type_bond) {
15694     Show (dlg->bond_type);
15695   } else if (vnp->choice == Macro_feature_type_site) {
15696     Show (dlg->site_type);
15697   } else if (vnp->choice == Macro_feature_type_region) {
15698     Show (dlg->create_prot_regions);
15699   } else if (vnp->choice == Macro_feature_type_ncRNA) {
15700     Show (dlg->ncrna_class_dlg);
15701   }
15702 
15703   if (vnp != NULL) {
15704     type_to = vnp->choice;
15705   }
15706   vnp = ValNodeFree (vnp);
15707 
15708   if (type_to == 0 || type_from == 0 || IsConversionSupported (type_from, type_to)) {
15709     SetTitle (dlg->supported, "");
15710   } else {
15711     SetTitle (dlg->supported, "Conversion is not supported");
15712   }
15713 
15714   if (dlg->change_notify != NULL) {
15715     (dlg->change_notify) (dlg->change_userdata);
15716   }
15717 }
15718 
15719 
ConvertFeatureActionToDialog(DialoG d,Pointer data)15720 static void ConvertFeatureActionToDialog (DialoG d, Pointer data)
15721 {
15722   ConvertFeatureActionDlgPtr dlg;
15723   ConvertFeatureActionPtr action;
15724   ValNode                 vn;
15725   RegionTypePtr           r;
15726 
15727   dlg = (ConvertFeatureActionDlgPtr) GetObjectExtra (d);
15728   if (dlg == NULL) return;
15729 
15730   action = (ConvertFeatureActionPtr) data;
15731   if (action == NULL) {
15732     PointerToDialog (dlg->feature_type_from_dlg, NULL);
15733     PointerToDialog (dlg->feature_type_to_dlg, NULL);
15734     PointerToDialog (dlg->cds_options, NULL);
15735     SetStatus (dlg->leave_original, FALSE);
15736   } else {
15737     vn.next = NULL;
15738     vn.data.ptrvalue = NULL;
15739     vn.choice = (Uint1)action->type_from;
15740     PointerToDialog (dlg->feature_type_from_dlg, &vn);
15741     vn.choice = (Uint1)action->type_to;
15742     PointerToDialog (dlg->feature_type_to_dlg, &vn);
15743     /* set source options */
15744     if (action->src_options != NULL && action->src_options->choice == ConvertFeatureSrcOptions_cds) {
15745       PointerToDialog (dlg->cds_options, action->src_options->data.ptrvalue);
15746     } else {
15747       PointerToDialog (dlg->cds_options, NULL);
15748     }
15749     /* set dest options */
15750     if (action->dst_options == NULL) {
15751       PointerToDialog (dlg->bond_type, NULL);
15752       PointerToDialog (dlg->site_type, NULL);
15753       SetStatus (dlg->create_prot_regions, TRUE);
15754     } else {
15755       switch (action->dst_options->choice) {
15756         case ConvertFeatureDstOptions_bond:
15757           vn.choice = action->dst_options->data.intvalue;
15758           PointerToDialog (dlg->bond_type, &vn);
15759           break;
15760         case ConvertFeatureDstOptions_site:
15761           vn.choice = action->dst_options->data.intvalue;
15762           PointerToDialog (dlg->site_type, &vn);
15763           break;
15764         case ConvertFeatureDstOptions_region:
15765           r = (RegionTypePtr) action->dst_options->data.ptrvalue;
15766           if (r == NULL || !r->create_nucleotide) {
15767             SetStatus (dlg->create_prot_regions, TRUE);
15768           } else {
15769             SetStatus (dlg->create_prot_regions, FALSE);
15770           }
15771           break;
15772         case ConvertFeatureDstOptions_ncrna_class:
15773           PointerToDialog (dlg->ncrna_class_dlg, action->dst_options->data.ptrvalue);
15774           break;
15775       }
15776     }
15777     SetStatus (dlg->leave_original, action->leave_original);
15778     PointerToDialog (dlg->constraint_dlg, action->src_feat_constraint);
15779   }
15780   ChangeConvertFeatureType (dlg);
15781 }
15782 
15783 
DialogToConvertFeatureAction(DialoG d)15784 static Pointer DialogToConvertFeatureAction (DialoG d)
15785 {
15786   ConvertFeatureActionDlgPtr dlg;
15787   ConvertFeatureActionPtr    action;
15788   ConvertFromCDSOptionsPtr   src_options;
15789   ValNodePtr                 vnp;
15790   RegionTypePtr              r;
15791 
15792   dlg = (ConvertFeatureActionDlgPtr) GetObjectExtra (d);
15793   if (dlg == NULL) return NULL;
15794 
15795   action = ConvertFeatureActionNew ();
15796   vnp = DialogToPointer (dlg->feature_type_from_dlg);
15797   if (vnp == NULL) {
15798     action = ConvertFeatureActionFree (action);
15799     return NULL;
15800   } else {
15801     action->type_from = vnp->choice;
15802   }
15803   vnp = ValNodeFree (vnp);
15804 
15805   vnp = DialogToPointer (dlg->feature_type_to_dlg);
15806   if (vnp == NULL) {
15807     action = ConvertFeatureActionFree (action);
15808     return NULL;
15809   } else {
15810     action->type_to = vnp->choice;
15811   }
15812   vnp = ValNodeFree (vnp);
15813 
15814   action->leave_original = GetStatus (dlg->leave_original);
15815 
15816   if (action->type_from == Macro_feature_type_cds) {
15817     src_options = (ConvertFromCDSOptionsPtr) DialogToPointer (dlg->cds_options);
15818     if (src_options != NULL) {
15819       ValNodeAddPointer (&(action->src_options), ConvertFeatureSrcOptions_cds, src_options);
15820     }
15821   }
15822 
15823   /* if type to is bond, site, or region, or ncRNA, get options */
15824   if (action->type_to == Macro_feature_type_bond) {
15825     vnp = DialogToPointer (dlg->bond_type);
15826     if (vnp == NULL) {
15827       action = ConvertFeatureActionFree (action);
15828       return NULL;
15829     } else {
15830       ValNodeAddInt (&(action->dst_options), ConvertFeatureDstOptions_bond, vnp->choice);
15831     }
15832     vnp = ValNodeFree (vnp);
15833   } else if (action->type_to == Macro_feature_type_site) {
15834     vnp = DialogToPointer (dlg->site_type);
15835     if (vnp == NULL) {
15836       action = ConvertFeatureActionFree (action);
15837       return NULL;
15838     } else {
15839       ValNodeAddInt (&(action->dst_options), ConvertFeatureDstOptions_site, vnp->choice);
15840     }
15841     vnp = ValNodeFree (vnp);
15842   } else if (action->type_to == Macro_feature_type_region) {
15843     r = RegionTypeNew ();
15844     r->create_nucleotide = !GetStatus (dlg->create_prot_regions);
15845     ValNodeAddPointer (&(action->dst_options), ConvertFeatureDstOptions_region, r);
15846   } else if (action->type_to == Macro_feature_type_ncRNA) {
15847     ValNodeAddPointer (&(action->dst_options), ConvertFeatureDstOptions_ncrna_class, DialogToPointer (dlg->ncrna_class_dlg));
15848   } else if (action->type_from == Macro_feature_type_cds && action->type_to == Macro_feature_type_mat_peptide_aa) {
15849     /* hack for converting from coding region to mat-peptide */
15850     action->dst_options = ValNodeNew (NULL);
15851     action->dst_options->choice = ConvertFeatureDstOptions_remove_original;
15852     action->dst_options->data.boolvalue = !action->leave_original;
15853   }
15854 
15855 
15856   action->src_feat_constraint = DialogToPointer (dlg->constraint_dlg);
15857 
15858   return action;
15859 }
15860 
15861 
TestConvertFeatureActionDialog(DialoG d)15862 static ValNodePtr TestConvertFeatureActionDialog (DialoG d)
15863 {
15864   ConvertFeatureActionDlgPtr dlg;
15865   ValNodePtr err_list = NULL, vnp;
15866   Uint2     type_from = 0, type_to = 0;
15867 
15868   dlg = (ConvertFeatureActionDlgPtr) GetObjectExtra (d);
15869   if (dlg == NULL) return NULL;
15870 
15871   ValNodeLink (&err_list, TestDialog (dlg->feature_type_from_dlg));
15872   ValNodeLink (&err_list, TestDialog (dlg->feature_type_to_dlg));
15873 
15874   vnp = DialogToPointer (dlg->feature_type_from_dlg);
15875   if (vnp != NULL) {
15876     type_from = vnp->choice;
15877     if (type_from == Macro_feature_type_cds) {
15878       ValNodeLink (&err_list, TestDialog (dlg->cds_options));
15879     }
15880   }
15881   vnp = ValNodeFree (vnp);
15882 
15883   vnp = DialogToPointer (dlg->feature_type_to_dlg);
15884   if (vnp == NULL) {
15885     /* do nothing */
15886   } else {
15887     type_to = vnp->choice;
15888     if (type_to == Macro_feature_type_bond) {
15889       ValNodeLink (&err_list, TestDialog (dlg->bond_type));
15890     } else if (type_to == Macro_feature_type_site) {
15891       ValNodeLink (&err_list, TestDialog (dlg->site_type));
15892     }
15893   }
15894   vnp = ValNodeFree (vnp);
15895   if (!IsConversionSupported (type_from, type_to)) {
15896     ValNodeAddPointer (&err_list, 0, "Unsupported conversion");
15897   }
15898   return err_list;
15899 }
15900 
ChangeConvertFeatureActionBtn(ButtoN b)15901 static void ChangeConvertFeatureActionBtn (ButtoN b)
15902 {
15903   ConvertFeatureActionDlgPtr dlg;
15904 
15905   dlg = (ConvertFeatureActionDlgPtr) GetObjectExtra (b);
15906   if (dlg != NULL) {
15907     if (dlg->change_notify != NULL) {
15908       (dlg->change_notify) (dlg->change_userdata);
15909     }
15910   }
15911 }
15912 
15913 
ConvertFeatureActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)15914 static DialoG ConvertFeatureActionDialog
15915 (GrouP h,
15916  Boolean indexer_version,
15917  Nlm_ChangeNotifyProc     change_notify,
15918  Pointer                  change_userdata)
15919 {
15920   ConvertFeatureActionDlgPtr dlg;
15921   GrouP                      p, g1, g2;
15922   ValNodePtr                 val_list;
15923 
15924   dlg = (ConvertFeatureActionDlgPtr) MemNew (sizeof (ConvertFeatureActionDlgData));
15925   p = HiddenGroup (h, -1, 0, NULL);
15926   SetGroupSpacing (p, 10, 10);
15927   SetObjectExtra (p, dlg, StdCleanupExtraProc);
15928 
15929   dlg->dialog = (DialoG) p;
15930   dlg->todialog = ConvertFeatureActionToDialog;
15931   dlg->fromdialog = DialogToConvertFeatureAction;
15932   dlg->dialogmessage = NULL;
15933   dlg->testdialog = TestConvertFeatureActionDialog;
15934   dlg->change_notify = change_notify;
15935   dlg->change_userdata = change_userdata;
15936 
15937   g1 = HiddenGroup (p, 2, 0, NULL);
15938   dlg->feature_type_from_dlg = FeatureTypeDialog (g1, ChangeConvertFeatureType, dlg);
15939   dlg->feature_type_to_dlg = FeatureTypeDialog (g1, ChangeConvertFeatureType, dlg);
15940 
15941   dlg->supported = StaticPrompt (p, "Conversion is not supported", 0, dialogTextHeight, systemFont, 'l');
15942 
15943   dlg->cds_options = ConvertFromCDSOptionsDialog (p, change_notify, change_userdata);
15944   Hide (dlg->cds_options);
15945 
15946   g2 = HiddenGroup (p, 0, 0, NULL);
15947   val_list = GetBondTypeList ();
15948   dlg->bond_type = ValNodeSelectionDialog (g2, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
15949                                            ValNodeSimpleDataFree, ValNodeStringCopy,
15950                                            ValNodeChoiceMatch, "bond_type",
15951                                            change_notify, change_userdata, FALSE);
15952   Hide (dlg->bond_type);
15953   val_list = GetSiteTypeList ();
15954   dlg->site_type = ValNodeSelectionDialog (g2, val_list, SHORT_SELECTION_LIST, ValNodeStringName,
15955                                            ValNodeSimpleDataFree, ValNodeStringCopy,
15956                                            ValNodeChoiceMatch, "site_type",
15957                                            change_notify, change_userdata, FALSE);
15958   Hide (dlg->site_type);
15959   dlg->create_prot_regions = CheckBox (g2, "Create region features on protein sequence of overlapping coding region", ChangeConvertFeatureActionBtn);
15960   SetObjectExtra (dlg->create_prot_regions, dlg, NULL);
15961   Hide (dlg->create_prot_regions);
15962 
15963   dlg->ncrna_class_dlg = CreatencRNAClassDialog (g2, FALSE, change_notify, change_userdata);
15964   Hide (dlg->ncrna_class_dlg);
15965   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->bond_type,
15966                               (HANDLE) dlg->site_type,
15967                               (HANDLE) dlg->create_prot_regions,
15968                               (HANDLE) dlg->ncrna_class_dlg,
15969                               NULL);
15970 
15971   dlg->leave_original = CheckBox (p, "Leave original", ChangeConvertFeatureActionBtn);
15972   SetObjectExtra (dlg->leave_original, dlg, NULL);
15973 
15974   dlg->constraint_dlg = ConstraintSetDialog (p, change_notify, change_userdata);
15975 
15976   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->supported, (HANDLE) g1, (HANDLE) dlg->cds_options, (HANDLE) g2, (HANDLE) dlg->leave_original, (HANDLE) dlg->constraint_dlg, NULL);
15977 
15978   return (DialoG) p;
15979 }
15980 
15981 
DescriptorTypeDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)15982 static DialoG DescriptorTypeDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
15983 {
15984   ValNodePtr desc_list = NULL;
15985 
15986   AddAllDescriptorsToChoiceList (&desc_list);
15987   return ValNodeSelectionDialog (h, desc_list, TALL_SELECTION_LIST, ValNodeStringName,
15988                                 ValNodeSimpleDataFree, ValNodeStringCopy,
15989                                 ValNodeChoiceMatch, "descriptor type",
15990                                 change_notify, change_userdata, FALSE);
15991 }
15992 
15993 
15994 typedef struct removedescriptoractiondlg {
15995   DIALOG_MESSAGE_BLOCK
15996   DialoG                   descriptor_type_dlg;
15997 
15998   DialoG                   constraint_dlg;
15999   Nlm_ChangeNotifyProc     change_notify;
16000   Pointer                  change_userdata;
16001 } RemoveDescriptorActionDlgData, PNTR RemoveDescriptorActionDlgPtr;
16002 
16003 
RemoveDescriptorActionToDialog(DialoG d,Pointer data)16004 static void RemoveDescriptorActionToDialog (DialoG d, Pointer data)
16005 {
16006   RemoveDescriptorActionDlgPtr dlg;
16007   RemoveDescriptorActionPtr    action;
16008   ValNode vn;
16009 
16010   dlg = (RemoveDescriptorActionDlgPtr) GetObjectExtra (d);
16011   if (dlg == NULL) {
16012     return;
16013   }
16014 
16015   vn.data.ptrvalue = NULL;
16016   vn.next = NULL;
16017 
16018   action = (RemoveDescriptorActionPtr) data;
16019   if (action == NULL) {
16020     vn.choice = Descriptor_type_all;
16021     PointerToDialog (dlg->descriptor_type_dlg, &vn);
16022     PointerToDialog (dlg->constraint_dlg, NULL);
16023   } else {
16024     vn.choice = (Uint1)action->type;
16025     PointerToDialog (dlg->descriptor_type_dlg, &vn);
16026     PointerToDialog (dlg->constraint_dlg, action->constraint);
16027   }
16028 }
16029 
16030 
DialogToRemoveDescriptorAction(DialoG d)16031 static Pointer DialogToRemoveDescriptorAction (DialoG d)
16032 {
16033   RemoveDescriptorActionDlgPtr dlg;
16034   RemoveDescriptorActionPtr    action;
16035   ValNodePtr                   vnp;
16036 
16037   dlg = (RemoveDescriptorActionDlgPtr) GetObjectExtra (d);
16038   if (dlg == NULL) {
16039     return NULL;
16040   }
16041 
16042   action = RemoveDescriptorActionNew();
16043 
16044   vnp = DialogToPointer (dlg->descriptor_type_dlg);
16045   if (vnp == NULL) {
16046     action->type = Descriptor_type_all;
16047   } else {
16048     action->type = vnp->choice;
16049   }
16050   vnp = ValNodeFree (vnp);
16051   action->constraint = DialogToPointer (dlg->constraint_dlg);
16052   return action;
16053 }
16054 
16055 
TestRemoveDescriptorActionDialog(DialoG d)16056 static ValNodePtr TestRemoveDescriptorActionDialog (DialoG d)
16057 {
16058   RemoveDescriptorActionDlgPtr dlg;
16059 
16060   dlg = (RemoveDescriptorActionDlgPtr) GetObjectExtra (d);
16061   if (dlg == NULL) {
16062     return NULL;
16063   }
16064 
16065   return TestDialog (dlg->descriptor_type_dlg);
16066 }
16067 
16068 
RemoveDescriptorActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)16069 static DialoG RemoveDescriptorActionDialog
16070 (GrouP h,
16071  Boolean indexer_version,
16072  Nlm_ChangeNotifyProc     change_notify,
16073  Pointer                  change_userdata)
16074 {
16075   RemoveDescriptorActionDlgPtr dlg;
16076   GrouP                      p;
16077 
16078   dlg = (RemoveDescriptorActionDlgPtr) MemNew (sizeof (RemoveDescriptorActionDlgData));
16079   p = HiddenGroup (h, -1, 0, NULL);
16080   SetGroupSpacing (p, 10, 10);
16081   SetObjectExtra (p, dlg, StdCleanupExtraProc);
16082 
16083   dlg->dialog = (DialoG) p;
16084   dlg->todialog = RemoveDescriptorActionToDialog;
16085   dlg->fromdialog = DialogToRemoveDescriptorAction;
16086   dlg->dialogmessage = NULL;
16087   dlg->testdialog = TestRemoveDescriptorActionDialog;
16088   dlg->change_notify = change_notify;
16089   dlg->change_userdata = change_userdata;
16090 
16091   dlg->descriptor_type_dlg = DescriptorTypeDialog (p, change_notify, change_userdata);
16092 
16093   dlg->constraint_dlg = ConstraintSetDialog (p, change_notify, change_userdata);
16094 
16095   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->descriptor_type_dlg, (HANDLE) dlg->constraint_dlg, NULL);
16096 
16097   return (DialoG) p;
16098 }
16099 
16100 
16101 typedef struct autodefactiondlg {
16102   DIALOG_MESSAGE_BLOCK
16103   DialoG                   modifiers_dlg;
16104   PopuP                    clause_list_type_popup;
16105   PopuP                    misc_feat_parse_rule;
16106 
16107   Nlm_ChangeNotifyProc     change_notify;
16108   Pointer                  change_userdata;
16109 } AutodefActionDlgData, PNTR AutodefActionDlgPtr;
16110 
16111 
AutodefActionToDialog(DialoG d,Pointer data)16112 static void AutodefActionToDialog(DialoG d, Pointer data)
16113 {
16114   AutodefActionDlgPtr dlg;
16115   AutodefActionPtr    action;
16116   ValNodePtr          list = NULL, vnp;
16117 
16118   dlg = (AutodefActionDlgPtr) GetObjectExtra (d);
16119   if (dlg == NULL) {
16120     return;
16121   }
16122   action = (AutodefActionPtr) data;
16123   if (action == NULL) {
16124     PointerToDialog (dlg->modifiers_dlg, NULL);
16125     SetValue (dlg->clause_list_type_popup, 2);
16126     SetValue (dlg->misc_feat_parse_rule, 2);
16127   } else {
16128     /* populate modifiers */
16129     for (vnp = action->modifiers; vnp != NULL; vnp = vnp->next) {
16130       ValNodeAddPointer (&list, 0, GetSourceQualName (vnp->data.intvalue));
16131     }
16132     PointerToDialog (dlg->modifiers_dlg, list);
16133 
16134     /* populate clause list type */
16135     switch (action->clause_list_type) {
16136       case Autodef_list_type_feature_list:
16137         SetValue (dlg->clause_list_type_popup, 1);
16138         break;
16139       case Autodef_list_type_complete_sequence:
16140         SetValue (dlg->clause_list_type_popup, 2);
16141         break;
16142       case Autodef_list_type_complete_genome:
16143         SetValue (dlg->clause_list_type_popup, 3);
16144         break;
16145       case Autodef_list_type_sequence:
16146         SetValue (dlg->clause_list_type_popup, 4);
16147         break;
16148       default:
16149         SetValue (dlg->clause_list_type_popup, 2);
16150         break;
16151     }
16152 
16153     SetValue (dlg->misc_feat_parse_rule, action->misc_feat_parse_rule);
16154   }
16155 }
16156 
16157 
DialogToAutodefAction(DialoG d)16158 static Pointer DialogToAutodefAction (DialoG d)
16159 {
16160   AutodefActionDlgPtr dlg;
16161   AutodefActionPtr    action = NULL;
16162   Int2                v;
16163   ValNodePtr          list, vnp;
16164 
16165   dlg = (AutodefActionDlgPtr) GetObjectExtra (d);
16166   if (dlg == NULL) {
16167     return NULL;
16168   }
16169 
16170   action = AutodefActionNew();
16171   v = GetValue (dlg->clause_list_type_popup);
16172   switch (v) {
16173     case 1:
16174       action->clause_list_type = Autodef_list_type_feature_list;
16175       break;
16176     case 2:
16177       action->clause_list_type = Autodef_list_type_complete_sequence;
16178       break;
16179     case 3:
16180       action->clause_list_type = Autodef_list_type_complete_genome;
16181       break;
16182     case 4:
16183       action->clause_list_type = Autodef_list_type_sequence;
16184       break;
16185     default:
16186       action->clause_list_type = Autodef_list_type_feature_list;
16187       break;
16188   }
16189 
16190   list = DialogToPointer (dlg->modifiers_dlg);
16191   for (vnp = list; vnp != NULL; vnp = vnp->next) {
16192     ValNodeAddInt (&(action->modifiers), SourceQualChoice_textqual, GetSourceQualTypeByName (vnp->data.ptrvalue));
16193   }
16194   list = ValNodeFree (list);
16195 
16196   action->misc_feat_parse_rule = GetValue (dlg->misc_feat_parse_rule);
16197   if (action->misc_feat_parse_rule < 1) {
16198     action->misc_feat_parse_rule = 2;
16199   }
16200   return action;
16201 }
16202 
16203 
ChangeAutodefPopup(PopuP p)16204 static void ChangeAutodefPopup (PopuP p)
16205 {
16206   AutodefActionDlgPtr dlg;
16207 
16208   dlg = (AutodefActionDlgPtr) GetObjectExtra (p);
16209   if (dlg == NULL) {
16210     return;
16211   }
16212   if (dlg->change_notify != NULL) {
16213     (dlg->change_notify) (dlg->change_userdata);
16214   }
16215 }
16216 
16217 
AutodefActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)16218 static DialoG AutodefActionDialog
16219 (GrouP h,
16220  Boolean indexer_version,
16221  Nlm_ChangeNotifyProc     change_notify,
16222  Pointer                  change_userdata)
16223 {
16224   AutodefActionDlgPtr dlg;
16225   GrouP               p;
16226   PrompT              ppt1, ppt2, ppt3;
16227   ValNodePtr          src_quals = NULL;
16228   ValNode             vn;
16229 
16230   dlg = (AutodefActionDlgPtr) MemNew (sizeof (AutodefActionDlgData));
16231   p = HiddenGroup (h, -1, 0, NULL);
16232   SetGroupSpacing (p, 10, 10);
16233   SetObjectExtra (p, dlg, StdCleanupExtraProc);
16234 
16235   dlg->dialog = (DialoG) p;
16236   dlg->todialog = AutodefActionToDialog;
16237   dlg->fromdialog = DialogToAutodefAction;
16238   dlg->dialogmessage = NULL;
16239   dlg->testdialog = NULL;
16240   dlg->change_notify = change_notify;
16241   dlg->change_userdata = change_userdata;
16242 
16243   ppt1 = StaticPrompt (p, "Modifiers", 0, dialogTextHeight, systemFont, 'l');
16244 
16245   ValNodeAddPointer (&src_quals, 0, StringSave ("clone"));
16246   ValNodeAddPointer (&src_quals, 0, StringSave ("cultivar"));
16247   ValNodeAddPointer (&src_quals, 0, StringSave ("culture-collection"));
16248   ValNodeAddPointer (&src_quals, 0, StringSave ("haplogroup"));
16249   ValNodeAddPointer (&src_quals, 0, StringSave ("isolate"));
16250   ValNodeAddPointer (&src_quals, 0, StringSave ("strain"));
16251   ValNodeAddPointer (&src_quals, 0, StringSave ("specimen-voucher"));
16252 
16253   dlg->modifiers_dlg = ValNodeSelectionDialog (p, src_quals, SHORT_SELECTION_LIST,
16254                                                ValNodeStringName,
16255                                                ValNodeSimpleDataFree,
16256                                                ValNodeStringCopy,
16257                                                ValNodeStringMatch,
16258                                                "source qual",
16259                                                change_notify, change_userdata, TRUE);
16260   vn.choice = 0;
16261   vn.next = NULL;
16262   vn.data.ptrvalue = "haplogroup";
16263   PointerToDialog (dlg->modifiers_dlg, &vn);
16264 
16265   ppt2 = StaticPrompt (p, "Features or Complete", 0, dialogTextHeight, systemFont, 'l');
16266 
16267   dlg->clause_list_type_popup = PopupList (p, TRUE, ChangeAutodefPopup);
16268   SetObjectExtra (dlg->clause_list_type_popup, dlg, NULL);
16269   PopupItem (dlg->clause_list_type_popup, "List Features");
16270   PopupItem (dlg->clause_list_type_popup, "Complete Sequence");
16271   PopupItem (dlg->clause_list_type_popup, "Complete Genome");
16272   PopupItem (dlg->clause_list_type_popup, "Sequence");
16273   SetValue (dlg->clause_list_type_popup, 2);
16274 
16275   ppt3 = StaticPrompt (p, "Use misc-feat", 0, dialogTextHeight, systemFont, 'l');
16276   dlg->misc_feat_parse_rule = PopupList (p, TRUE, ChangeAutodefPopup);
16277   SetObjectExtra (dlg->misc_feat_parse_rule, dlg, NULL);
16278   PopupItem (dlg->misc_feat_parse_rule, "Use comment before first semicolon");
16279   PopupItem (dlg->misc_feat_parse_rule, "Look for Noncoding Products");
16280   SetValue (dlg->misc_feat_parse_rule, 2);
16281 
16282 
16283   AlignObjects (ALIGN_CENTER, (HANDLE) ppt1, (HANDLE) dlg->modifiers_dlg,
16284                 (HANDLE) ppt2, (HANDLE) dlg->clause_list_type_popup,
16285                 (HANDLE) ppt3, (HANDLE) dlg->misc_feat_parse_rule, NULL);
16286 
16287   return (DialoG) p;
16288 }
16289 
16290 
16291 typedef struct fixpubcapsdlg {
16292   DIALOG_MESSAGE_BLOCK
16293 
16294   ButtoN fix_title;
16295   ButtoN fix_author;
16296   ButtoN fix_affil;
16297   ButtoN fix_affil_country;
16298   ButtoN punct_only;
16299   DialoG constraint;
16300 
16301   Nlm_ChangeNotifyProc     change_notify;
16302   Pointer                  change_userdata;
16303 } FixPubCapsDlgData, PNTR FixPubCapsDlgPtr;
16304 
16305 
FixPubCapsActionToDialog(DialoG d,Pointer data)16306 static void FixPubCapsActionToDialog (DialoG d, Pointer data)
16307 {
16308   FixPubCapsDlgPtr dlg;
16309   FixPubCapsActionPtr action;
16310 
16311   dlg = (FixPubCapsDlgPtr) GetObjectExtra (d);
16312   if (dlg == NULL) {
16313     return;
16314   }
16315 
16316   action = (FixPubCapsActionPtr) data;
16317   if (action == NULL) {
16318     SetStatus (dlg->fix_title, FALSE);
16319     SetStatus (dlg->fix_author, FALSE);
16320     SetStatus (dlg->fix_affil, FALSE);
16321     SetStatus (dlg->fix_affil_country, FALSE);
16322     SetStatus (dlg->punct_only, FALSE);
16323     PointerToDialog (dlg->constraint, NULL);
16324   } else {
16325     SetStatus (dlg->fix_title, action->title);
16326     SetStatus (dlg->fix_author, action->authors);
16327     SetStatus (dlg->fix_affil, action->affiliation);
16328     SetStatus (dlg->fix_affil_country, action->affil_country);
16329     SetStatus (dlg->punct_only, action->punct_only);
16330     PointerToDialog (dlg->constraint, action->constraint);
16331   }
16332 
16333 }
16334 
16335 
DialogToFixPubCapsAction(DialoG d)16336 static Pointer DialogToFixPubCapsAction (DialoG d)
16337 {
16338   FixPubCapsDlgPtr dlg;
16339   FixPubCapsActionPtr action = NULL;
16340 
16341   dlg = (FixPubCapsDlgPtr) GetObjectExtra (d);
16342   if (dlg == NULL) {
16343     return NULL;
16344   }
16345 
16346   action = FixPubCapsActionNew ();
16347   action->title = GetStatus (dlg->fix_title);
16348   action->authors = GetStatus (dlg->fix_author);
16349   action->affiliation = GetStatus (dlg->fix_affil);
16350   action->affil_country = GetStatus (dlg->fix_affil_country);
16351   action->punct_only = GetStatus (dlg->punct_only);
16352   if (IsFixPubCapsActionEmpty(action)) {
16353     action = FixPubCapsActionFree (action);
16354   } else {
16355     action->constraint = DialogToPointer (dlg->constraint);
16356   }
16357   return action;
16358 }
16359 
16360 
ChangeFixPubCapsActionBtn(ButtoN b)16361 static void ChangeFixPubCapsActionBtn (ButtoN b)
16362 {
16363   FixPubCapsDlgPtr dlg;
16364 
16365   dlg = (FixPubCapsDlgPtr) GetObjectExtra (b);
16366   if (dlg == NULL) {
16367     return;
16368   }
16369 
16370   if (dlg->change_notify != NULL) {
16371     (dlg->change_notify) (dlg->change_userdata);
16372   }
16373 }
16374 
16375 
TestFixPubCapsActionDialog(DialoG d)16376 static ValNodePtr TestFixPubCapsActionDialog (DialoG d)
16377 {
16378   FixPubCapsDlgPtr dlg;
16379   FixPubCapsActionPtr a;
16380   ValNodePtr err_list = NULL;
16381 
16382   dlg = (FixPubCapsDlgPtr) GetObjectExtra (d);
16383   if (dlg == NULL) return NULL;
16384   a = (FixPubCapsActionPtr) DialogToPointer (d);
16385   if (a == NULL) {
16386     ValNodeAddPointer (&err_list, 0, "bad action");
16387   }
16388   return err_list;
16389 }
16390 
16391 
FixPubCapsDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)16392 static DialoG FixPubCapsDialog
16393 (GrouP h,
16394  Boolean indexer_version,
16395  Nlm_ChangeNotifyProc     change_notify,
16396  Pointer                  change_userdata)
16397 {
16398   FixPubCapsDlgPtr dlg;
16399   GrouP            p, g1;
16400 
16401   dlg = (FixPubCapsDlgPtr) MemNew (sizeof (FixPubCapsDlgData));
16402   p = HiddenGroup (h, -1, 0, NULL);
16403   SetGroupSpacing (p, 10, 10);
16404   SetObjectExtra (p, dlg, StdCleanupExtraProc);
16405 
16406   dlg->dialog = (DialoG) p;
16407   dlg->todialog = FixPubCapsActionToDialog;
16408   dlg->fromdialog = DialogToFixPubCapsAction;
16409   dlg->dialogmessage = NULL;
16410   dlg->testdialog = TestFixPubCapsActionDialog;
16411   dlg->change_notify = change_notify;
16412   dlg->change_userdata = change_userdata;
16413 
16414   g1 = HiddenGroup (p, 0, 5, NULL);
16415   SetGroupSpacing (g1, 10, 10);
16416   dlg->fix_title = CheckBox (g1, "Fix title", ChangeFixPubCapsActionBtn);
16417   SetObjectExtra (dlg->fix_title, dlg, NULL);
16418   dlg->fix_author = CheckBox (g1, "Fix authors", ChangeFixPubCapsActionBtn);
16419   SetObjectExtra (dlg->fix_author, dlg, NULL);
16420   dlg->fix_affil = CheckBox (g1, "Fix affiliation", ChangeFixPubCapsActionBtn);
16421   SetObjectExtra (dlg->fix_affil, dlg, NULL);
16422   dlg->fix_affil_country = CheckBox (g1, "Fix affiliation country", ChangeFixPubCapsActionBtn);
16423   SetObjectExtra (dlg->fix_affil_country, dlg, NULL);
16424   dlg->punct_only = CheckBox (g1, "Punctuation only", ChangeFixPubCapsActionBtn);
16425   SetObjectExtra (dlg->punct_only, dlg, NULL);
16426 
16427   dlg->constraint = ConstraintSetDialog (p, change_notify, change_userdata);
16428 
16429   AlignObjects (ALIGN_CENTER, (HANDLE) g1, (HANDLE) dlg->constraint, NULL);
16430 
16431   return (DialoG) p;
16432 }
16433 
16434 
16435 typedef struct sortfieldsdlg {
16436   DIALOG_MESSAGE_BLOCK
16437 
16438   /* Note - for now, the only field you can sort is protein name */
16439   GrouP  order;
16440   DialoG constraint;
16441 
16442   Nlm_ChangeNotifyProc     change_notify;
16443   Pointer                  change_userdata;
16444 } SortFieldsDlgData, PNTR SortFieldsDlgPtr;
16445 
16446 
SortFieldsActionToDialog(DialoG d,Pointer data)16447 static void SortFieldsActionToDialog (DialoG d, Pointer data)
16448 {
16449   SortFieldsDlgPtr dlg;
16450   SortFieldsActionPtr action;
16451 
16452   dlg = (SortFieldsDlgPtr) GetObjectExtra (d);
16453   if (dlg == NULL) {
16454     return;
16455   }
16456 
16457   action = (SortFieldsActionPtr) data;
16458   if (action == NULL) {
16459     SetValue (dlg->order, 1);
16460     PointerToDialog (dlg->constraint, NULL);
16461   } else {
16462     if (action->order > 0) {
16463       SetValue (dlg->order, action->order);
16464     } else {
16465       SetValue (dlg->order, 1);
16466     }
16467     PointerToDialog (dlg->constraint, action->constraint);
16468   }
16469 
16470 }
16471 
16472 
DialogToSortFieldsAction(DialoG d)16473 static Pointer DialogToSortFieldsAction (DialoG d)
16474 {
16475   SortFieldsDlgPtr dlg;
16476   SortFieldsActionPtr action = NULL;
16477   FeatureFieldPtr ffield;
16478 
16479   dlg = (SortFieldsDlgPtr) GetObjectExtra (d);
16480   if (dlg == NULL) {
16481     return NULL;
16482   }
16483 
16484   action = SortFieldsActionNew ();
16485   action->order = GetValue (dlg->order);
16486   action->constraint = DialogToPointer (dlg->constraint);
16487 
16488   ffield = FeatureFieldNew ();
16489   ffield->type = Macro_feature_type_cds;
16490   ffield->field = ValNodeNew (NULL);
16491   ffield->field->choice = FeatQualChoice_legal_qual;
16492   ffield->field->data.intvalue = Feat_qual_legal_product;
16493   action->field = ValNodeNew (NULL);
16494   action->field->choice = FieldType_feature_field;
16495   action->field->data.ptrvalue = ffield;
16496   return action;
16497 }
16498 
16499 
ChangeSortFieldsActionGrp(GrouP g)16500 static void ChangeSortFieldsActionGrp (GrouP g)
16501 {
16502   SortFieldsDlgPtr dlg;
16503 
16504   dlg = (SortFieldsDlgPtr) GetObjectExtra (g);
16505   if (dlg == NULL) {
16506     return;
16507   }
16508 
16509   if (dlg->change_notify != NULL) {
16510     (dlg->change_notify) (dlg->change_userdata);
16511   }
16512 }
16513 
16514 
TestSortFieldsActionDialog(DialoG d)16515 static ValNodePtr TestSortFieldsActionDialog (DialoG d)
16516 {
16517   SortFieldsDlgPtr dlg;
16518   ValNodePtr err_list = NULL;
16519 
16520   dlg = (SortFieldsDlgPtr) GetObjectExtra (d);
16521   if (dlg == NULL) return NULL;
16522   return err_list;
16523 }
16524 
16525 
SortFieldsDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)16526 static DialoG SortFieldsDialog
16527 (GrouP h,
16528  Boolean indexer_version,
16529  Nlm_ChangeNotifyProc     change_notify,
16530  Pointer                  change_userdata)
16531 {
16532   SortFieldsDlgPtr dlg;
16533   GrouP            p;
16534 
16535   dlg = (SortFieldsDlgPtr) MemNew (sizeof (SortFieldsDlgData));
16536   p = HiddenGroup (h, -1, 0, NULL);
16537   SetGroupSpacing (p, 10, 10);
16538   SetObjectExtra (p, dlg, StdCleanupExtraProc);
16539 
16540   dlg->dialog = (DialoG) p;
16541   dlg->todialog = SortFieldsActionToDialog;
16542   dlg->fromdialog = DialogToSortFieldsAction;
16543   dlg->dialogmessage = NULL;
16544   dlg->testdialog = TestSortFieldsActionDialog;
16545   dlg->change_notify = change_notify;
16546   dlg->change_userdata = change_userdata;
16547 
16548   dlg->order = HiddenGroup (p, 0, 3, ChangeSortFieldsActionGrp);
16549   SetGroupSpacing (dlg->order, 10, 10);
16550   RadioButton (dlg->order, "By length, short to long");
16551   RadioButton (dlg->order, "By length, long to short");
16552   RadioButton (dlg->order, "Alphabetically");
16553   SetObjectExtra (dlg->order, dlg, NULL);
16554   SetValue (dlg->order, 1);
16555 
16556   dlg->constraint = ConstraintSetDialog (p, change_notify, change_userdata);
16557 
16558   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->order, (HANDLE) dlg->constraint, NULL);
16559 
16560   return (DialoG) p;
16561 }
16562 
16563 
16564 typedef struct extendtofeaturedlg {
16565   DIALOG_MESSAGE_BLOCK
16566   DialoG                   feature_type_dlg;
16567   DialoG                   distance_dlg;
16568   ButtoN                   include_feat;
16569   Nlm_ChangeNotifyProc     change_notify;
16570   Pointer                  change_userdata;
16571 } ExtendToFeatureDlgData, PNTR ExtendToFeatureDlgPtr;
16572 
16573 
DialogToExtendToFeature(DialoG d)16574 static Pointer DialogToExtendToFeature (DialoG d)
16575 {
16576   ExtendToFeatureDlgPtr dlg;
16577   ExtendToFeaturePtr    efp;
16578   ValNodePtr            vnp;
16579 
16580   dlg = (ExtendToFeatureDlgPtr) GetObjectExtra (d);
16581   if (dlg == NULL) return NULL;
16582 
16583   vnp = DialogToPointer (dlg->feature_type_dlg);
16584   if (vnp == NULL) return NULL;
16585 
16586   efp = ExtendToFeatureNew ();
16587   efp->type = vnp->choice;
16588   vnp = ValNodeFree (vnp);
16589   efp->include_feat = GetStatus (dlg->include_feat);
16590   efp->distance = DialogToPointer (dlg->distance_dlg);
16591 
16592   return efp;
16593 }
16594 
16595 
ExtendToFeatureToDialog(DialoG d,Pointer data)16596 static void ExtendToFeatureToDialog (DialoG d, Pointer data)
16597 {
16598   ExtendToFeatureDlgPtr dlg;
16599   ExtendToFeaturePtr    efp;
16600   ValNode               vn;
16601 
16602   dlg = (ExtendToFeatureDlgPtr) GetObjectExtra (d);
16603   if (dlg == NULL) return;
16604 
16605   efp = (ExtendToFeaturePtr) data;
16606 
16607   if (efp == NULL) {
16608     PointerToDialog (dlg->feature_type_dlg, NULL);
16609     PointerToDialog (dlg->distance_dlg, NULL);
16610     SetStatus (dlg->include_feat, FALSE);
16611   } else {
16612     vn.choice = (Uint1)efp->type;
16613     vn.data.ptrvalue = NULL;
16614     vn.next = NULL;
16615     PointerToDialog (dlg->feature_type_dlg, &vn);
16616     PointerToDialog (dlg->distance_dlg, efp->distance);
16617     SetStatus (dlg->include_feat, efp->include_feat);
16618   }
16619 }
16620 
16621 
TestExtendToFeatureDialog(DialoG d)16622 static ValNodePtr TestExtendToFeatureDialog (DialoG d)
16623 {
16624   ExtendToFeatureDlgPtr dlg;
16625   ValNodePtr err_list = NULL, vnp;
16626 
16627   dlg = (ExtendToFeatureDlgPtr) GetObjectExtra (d);
16628   if (dlg == NULL) return NULL;
16629   vnp = DialogToPointer (dlg->feature_type_dlg);
16630   if (vnp == NULL) {
16631     ValNodeAddPointer (&err_list, 0, "missing feature type");
16632   } else {
16633     vnp = ValNodeFree (err_list);
16634     err_list = TestDialog (dlg->distance_dlg);
16635   }
16636   return err_list;
16637 }
16638 
16639 
16640 static DialoG
ExtendToFeatureDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)16641 ExtendToFeatureDialog
16642 (GrouP h,
16643  Nlm_ChangeNotifyProc     change_notify,
16644  Pointer                  change_userdata)
16645 {
16646   ExtendToFeatureDlgPtr dlg;
16647   GrouP                     p;
16648 
16649   dlg = (ExtendToFeatureDlgPtr) MemNew (sizeof (ExtendToFeatureDlgData));
16650   p = HiddenGroup (h, -1, 0, NULL);
16651   SetGroupSpacing (p, 10, 10);
16652   SetObjectExtra (p, dlg, StdCleanupExtraProc);
16653 
16654   dlg->dialog = (DialoG) p;
16655   dlg->todialog = ExtendToFeatureToDialog;
16656   dlg->fromdialog = DialogToExtendToFeature;
16657   dlg->dialogmessage = NULL;
16658   dlg->testdialog = TestExtendToFeatureDialog;
16659   dlg->change_notify = change_notify;
16660   dlg->change_userdata = change_userdata;
16661 
16662   dlg->feature_type_dlg = FeatureTypeDialog (p, change_notify, change_userdata);
16663   dlg->distance_dlg = QuantityConstraintDialog (p, "feature distance", "50", change_notify, change_userdata);
16664   dlg->include_feat = CheckBox (p, "Include feature location", NULL);
16665 
16666   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->feature_type_dlg,
16667                               (HANDLE) dlg->distance_dlg,
16668                               (HANDLE) dlg->include_feat,
16669                               NULL);
16670 
16671   return (DialoG) p;
16672 }
16673 
16674 
16675 typedef struct editfeaturelocationactiondlg {
16676   DIALOG_MESSAGE_BLOCK
16677   DialoG                   feature_type_dlg;
16678   PopuP                    feature_edit_type;
16679   GrouP                    strand_edit_grp;
16680   PopuP                    strand_from;
16681   PopuP                    strand_to;
16682   GrouP                    set_5_partial_grp;
16683   PopuP                    set_5_type;
16684   ButtoN                   extend5;
16685   PopuP                    clear_5_type;
16686   GrouP                    set_3_partial_grp;
16687   PopuP                    set_3_type;
16688   ButtoN                   extend3;
16689   PopuP                    clear_3_type;
16690   GrouP                    set_both_partial_grp;
16691   PopuP                    set_both_type;
16692   ButtoN                   extendboth;
16693   PopuP                    clear_both_type;
16694   DialoG                   extend_to_feat;
16695   PopuP                    convert_loc;
16696   ButtoN                   retranslate_cds;
16697   ButtoN                   also_edit_gene;
16698   DialoG                   constraint_dlg;
16699   Nlm_ChangeNotifyProc     change_notify;
16700   Pointer                  change_userdata;
16701 } EditFeatureLocationActionDlgData, PNTR EditFeatureLocationActionDlgPtr;
16702 
16703 
ChangeFeatureLocationEditType(PopuP p)16704 static void ChangeFeatureLocationEditType (PopuP p)
16705 {
16706   EditFeatureLocationActionDlgPtr dlg;
16707   Int2 val;
16708 
16709   dlg = (EditFeatureLocationActionDlgPtr) GetObjectExtra (p);
16710   if (dlg == NULL) return;
16711 
16712   Hide (dlg->strand_edit_grp);
16713   Hide (dlg->set_5_partial_grp);
16714   Hide (dlg->clear_5_type);
16715   Hide (dlg->set_3_partial_grp);
16716   Hide (dlg->clear_3_type);
16717   Hide (dlg->set_both_partial_grp);
16718   Hide (dlg->clear_both_type);
16719   Hide (dlg->convert_loc);
16720   Hide (dlg->extend_to_feat);
16721 
16722   val = GetValue (dlg->feature_edit_type);
16723   switch (val) {
16724     case 1:
16725       Show (dlg->strand_edit_grp);
16726       break;
16727     case 2:
16728       Show (dlg->set_5_partial_grp);
16729       break;
16730     case 3:
16731       Show (dlg->clear_5_type);
16732       break;
16733     case 4:
16734       Show (dlg->set_3_partial_grp);
16735       break;
16736     case 5:
16737       Show (dlg->clear_3_type);
16738       break;
16739     case 6:
16740       Show (dlg->set_both_partial_grp);
16741       break;
16742     case 7:
16743       Show (dlg->clear_both_type);
16744       break;
16745     case 8:
16746       Show (dlg->convert_loc);
16747       break;
16748     case 11:
16749     case 12:
16750       Show (dlg->extend_to_feat);
16751       break;
16752   }
16753   if (dlg->change_notify != NULL) {
16754     (dlg->change_notify) (dlg->change_userdata);
16755   }
16756 }
16757 
16758 
ResetFeatureLocationActionEditType(EditFeatureLocationActionDlgPtr dlg)16759 static void ResetFeatureLocationActionEditType (EditFeatureLocationActionDlgPtr dlg)
16760 {
16761   if (dlg != NULL) {
16762     SetValue (dlg->feature_edit_type, 1);
16763     SetValue (dlg->strand_from, 1);
16764     SetValue (dlg->strand_to, 1);
16765     SetValue (dlg->retranslate_cds, FALSE);
16766     SetValue (dlg->also_edit_gene, FALSE);
16767     PointerToDialog (dlg->extend_to_feat, NULL);
16768   }
16769 }
16770 
16771 
EditFeatureLocationActionToDialog(DialoG d,Pointer data)16772 static void EditFeatureLocationActionToDialog (DialoG d, Pointer data)
16773 {
16774   EditFeatureLocationActionDlgPtr dlg;
16775   EditFeatureLocationActionPtr    action;
16776   ValNode                   vn;
16777   EditLocationStrandPtr    strand;
16778   Partial5SetActionPtr     set5;
16779   Partial3SetActionPtr     set3;
16780   PartialBothSetActionPtr  setboth;
16781 
16782   dlg = (EditFeatureLocationActionDlgPtr) GetObjectExtra (d);
16783   if (dlg == NULL) return;
16784 
16785   action = (EditFeatureLocationActionPtr) data;
16786   if (action == NULL) {
16787     PointerToDialog (dlg->feature_type_dlg, NULL);
16788     ResetFeatureLocationActionEditType (dlg);
16789     PointerToDialog (dlg->constraint_dlg, NULL);
16790     SetStatus (dlg->retranslate_cds, FALSE);
16791     SetStatus (dlg->also_edit_gene, FALSE);
16792   } else {
16793     vn.choice = (Uint1)action->type;
16794     vn.data.ptrvalue = NULL;
16795     vn.next = NULL;
16796     PointerToDialog (dlg->feature_type_dlg, &vn);
16797     PointerToDialog (dlg->constraint_dlg, action->constraint);
16798     SetStatus (dlg->retranslate_cds, action->retranslate_cds);
16799     SetStatus (dlg->also_edit_gene, action->also_edit_gene);
16800     if (action->action == NULL) {
16801       ResetFeatureLocationActionEditType (dlg);
16802     } else {
16803       switch (action->action->choice) {
16804         case LocationEditType_strand:
16805           SetValue (dlg->feature_edit_type, 1);
16806           strand = (EditLocationStrandPtr) action->action->data.ptrvalue;
16807           if (strand == NULL) {
16808             SetValue (dlg->strand_from, 1);
16809             SetValue (dlg->strand_to, 1);
16810           } else {
16811             switch (strand->strand_from) {
16812               case Feature_location_strand_from_any:
16813                 SetValue (dlg->strand_from, 1);
16814                 break;
16815               case Feature_location_strand_from_plus:
16816                 SetValue (dlg->strand_from, 2);
16817                 break;
16818               case Feature_location_strand_from_minus:
16819                 SetValue (dlg->strand_from, 3);
16820                 break;
16821               case Feature_location_strand_from_unknown:
16822                 SetValue (dlg->strand_from, 4);
16823                 break;
16824               case Feature_location_strand_from_both:
16825                 SetValue (dlg->strand_from, 5);
16826                 break;
16827               default:
16828                 SetValue (dlg->strand_from, 1);
16829                 break;
16830             }
16831             switch (strand->strand_to) {
16832               case Feature_location_strand_to_plus:
16833                 SetValue (dlg->strand_to, 1);
16834                 break;
16835               case Feature_location_strand_to_minus:
16836                 SetValue (dlg->strand_to, 2);
16837                 break;
16838               case Feature_location_strand_to_unknown:
16839                 SetValue (dlg->strand_to, 3);
16840                 break;
16841               case Feature_location_strand_to_both:
16842                 SetValue (dlg->strand_to, 4);
16843                 break;
16844               case Feature_location_strand_to_reverse:
16845                 SetValue (dlg->strand_to, 5);
16846                 break;
16847               default:
16848                 SetValue (dlg->strand_to, 1);
16849                 break;
16850             }
16851           }
16852           break;
16853         case LocationEditType_set_5_partial:
16854           SetValue (dlg->feature_edit_type, 2);
16855           set5 = (Partial5SetActionPtr) action->action->data.ptrvalue;
16856           if (set5 == NULL) {
16857             SetValue (dlg->set_5_type, 1);
16858             SetStatus (dlg->extend5, FALSE);
16859           } else {
16860             switch (set5->constraint) {
16861               case Partial_5_set_constraint_all:
16862                 SetValue (dlg->set_5_type, 1);
16863                 break;
16864               case Partial_5_set_constraint_at_end:
16865                 SetValue (dlg->set_5_type, 2);
16866                 break;
16867               case Partial_5_set_constraint_bad_start:
16868                 SetValue (dlg->set_5_type, 3);
16869                 break;
16870               case Partial_5_set_constraint_frame_not_one:
16871                 SetValue (dlg->set_5_type, 4);
16872                 break;
16873               default:
16874                 SetValue (dlg->set_5_type, 1);
16875                 break;
16876             }
16877             SetStatus (dlg->extend5, set5->extend);
16878           }
16879           break;
16880         case LocationEditType_clear_5_partial:
16881           SetValue (dlg->feature_edit_type, 3);
16882           switch (action->action->data.intvalue) {
16883             case Partial_5_clear_constraint_all:
16884               SetValue (dlg->clear_5_type, 1);
16885               break;
16886             case Partial_5_clear_constraint_not_at_end:
16887               SetValue (dlg->clear_5_type, 2);
16888               break;
16889             case Partial_5_clear_constraint_good_start:
16890               SetValue (dlg->clear_5_type, 3);
16891               break;
16892             default:
16893               SetValue (dlg->clear_5_type, 1);
16894               break;
16895           }
16896           break;
16897         case LocationEditType_set_3_partial:
16898           SetValue (dlg->feature_edit_type, 4);
16899           set3 = (Partial3SetActionPtr) action->action->data.ptrvalue;
16900           if (set3 == NULL) {
16901             SetValue (dlg->set_3_type, 1);
16902             SetStatus (dlg->extend3, FALSE);
16903           } else {
16904             switch (set3->constraint) {
16905               case Partial_3_set_constraint_all:
16906                 SetValue (dlg->set_3_type, 1);
16907                 break;
16908               case Partial_3_set_constraint_at_end:
16909                 SetValue (dlg->set_3_type, 2);
16910                 break;
16911               case Partial_3_set_constraint_bad_end:
16912                 SetValue (dlg->set_3_type, 3);
16913                 break;
16914               default:
16915                 SetValue (dlg->set_3_type, 1);
16916                 break;
16917             }
16918             SetStatus (dlg->extend3, set3->extend);
16919           }
16920           break;
16921         case LocationEditType_clear_3_partial:
16922           SetValue (dlg->feature_edit_type, 5);
16923           switch (action->action->data.intvalue) {
16924             case Partial_3_clear_constraint_all:
16925               SetValue (dlg->clear_3_type, 1);
16926               break;
16927             case Partial_3_clear_constraint_not_at_end:
16928               SetValue (dlg->clear_3_type, 2);
16929               break;
16930             case Partial_3_clear_constraint_good_end:
16931               SetValue (dlg->clear_3_type, 3);
16932               break;
16933             default:
16934               SetValue (dlg->clear_3_type, 1);
16935               break;
16936           }
16937           break;
16938         case LocationEditType_set_both_partial:
16939           SetValue (dlg->feature_edit_type, 6);
16940           setboth = (PartialBothSetActionPtr) action->action->data.ptrvalue;
16941           if (setboth == NULL) {
16942             SetValue (dlg->set_both_type, 1);
16943             SetStatus (dlg->extendboth, FALSE);
16944           } else {
16945             switch (setboth->constraint) {
16946               case Partial_both_set_constraint_all:
16947                 SetValue (dlg->set_both_type, 1);
16948                 break;
16949               case Partial_both_set_constraint_at_end:
16950                 SetValue (dlg->set_both_type, 2);
16951                 break;
16952               default:
16953                 SetValue (dlg->set_both_type, 1);
16954                 break;
16955             }
16956             SetStatus (dlg->extendboth, setboth->extend);
16957           }
16958           break;
16959         case LocationEditType_clear_both_partial:
16960           SetValue (dlg->feature_edit_type, 7);
16961           switch (action->action->data.intvalue) {
16962             case Partial_both_clear_constraint_all:
16963               SetValue (dlg->clear_both_type, 1);
16964               break;
16965             case Partial_both_clear_constraint_not_at_end:
16966               SetValue (dlg->clear_both_type, 2);
16967               break;
16968             default:
16969               SetValue (dlg->clear_both_type, 1);
16970               break;
16971           }
16972           break;
16973         case LocationEditType_convert:
16974           SetValue (dlg->feature_edit_type, 8);
16975           switch (action->action->data.intvalue) {
16976             case Convert_location_type_join:
16977               SetValue (dlg->convert_loc, 1);
16978               break;
16979             case Convert_location_type_order:
16980               SetValue (dlg->convert_loc, 2);
16981               break;
16982             case Convert_location_type_merge:
16983               SetValue (dlg->convert_loc, 3);
16984               break;
16985             default:
16986               SetValue (dlg->convert_loc, 1);
16987               break;
16988           }
16989           break;
16990         case LocationEditType_extend_5:
16991           SetValue (dlg->feature_edit_type, 9);
16992           break;
16993         case LocationEditType_extend_3:
16994           SetValue (dlg->feature_edit_type, 10);
16995           break;
16996         case LocationEditType_extend_5_to_feat:
16997           SetValue (dlg->feature_edit_type, 11);
16998           PointerToDialog (dlg->extend_to_feat, action->action->data.ptrvalue);
16999           break;
17000         case LocationEditType_extend_3_to_feat:
17001           SetValue (dlg->feature_edit_type, 12);
17002           PointerToDialog (dlg->extend_to_feat, action->action->data.ptrvalue);
17003           break;
17004         default:
17005           ResetFeatureLocationActionEditType (dlg);
17006           break;
17007       }
17008     }
17009   }
17010   ChangeFeatureLocationEditType (dlg->feature_edit_type);
17011 }
17012 
17013 
DialogToEditFeatureLocationAction(DialoG d)17014 static Pointer DialogToEditFeatureLocationAction (DialoG d)
17015 {
17016   EditFeatureLocationActionDlgPtr dlg;
17017   EditFeatureLocationActionPtr    action;
17018   ValNodePtr                vnp;
17019   Int2                      val, val2;
17020   EditLocationStrandPtr    strand;
17021   Partial5SetActionPtr     set5;
17022   Partial3SetActionPtr     set3;
17023   PartialBothSetActionPtr  setboth;
17024 
17025   dlg = (EditFeatureLocationActionDlgPtr) GetObjectExtra (d);
17026   if (dlg == NULL) return NULL;
17027 
17028   vnp = DialogToPointer (dlg->feature_type_dlg);
17029   if (vnp == NULL) return NULL;
17030 
17031   action = EditFeatureLocationActionNew ();
17032   action->type = vnp->choice;
17033   vnp = ValNodeFree (vnp);
17034   action->retranslate_cds = GetStatus (dlg->retranslate_cds);
17035   action->also_edit_gene = GetStatus (dlg->also_edit_gene);
17036   action->constraint = DialogToPointer (dlg->constraint_dlg);
17037 
17038   val = GetValue (dlg->feature_edit_type);
17039   switch (val) {
17040     case 1:
17041       strand = EditLocationStrandNew ();
17042       action->action = ValNodeNew (NULL);
17043       action->action->choice = LocationEditType_strand;
17044       action->action->data.ptrvalue = strand;
17045       val2 = GetValue (dlg->strand_from);
17046       switch (val2) {
17047         case 1:
17048           strand->strand_from = Feature_location_strand_from_any;
17049           break;
17050         case 2:
17051           strand->strand_from = Feature_location_strand_from_plus;
17052           break;
17053         case 3:
17054           strand->strand_from = Feature_location_strand_from_minus;
17055           break;
17056         case 4:
17057           strand->strand_from = Feature_location_strand_from_unknown;
17058           break;
17059         case 5:
17060           strand->strand_from = Feature_location_strand_from_both;
17061           break;
17062         default:
17063           action = EditFeatureLocationActionFree (action);
17064           return NULL;
17065       }
17066       val2 = GetValue (dlg->strand_to);
17067       switch (val2) {
17068         case 1:
17069           strand->strand_to = Feature_location_strand_to_plus;
17070           break;
17071         case 2:
17072           strand->strand_to = Feature_location_strand_to_minus;
17073           break;
17074         case 3:
17075           strand->strand_to = Feature_location_strand_to_unknown;
17076           break;
17077         case 4:
17078           strand->strand_to = Feature_location_strand_to_both;
17079           break;
17080         case 5:
17081           strand->strand_to = Feature_location_strand_to_reverse;
17082           break;
17083         default:
17084           action = EditFeatureLocationActionFree (action);
17085           break;
17086       }
17087       break;
17088     case 2:
17089       set5 = Partial5SetActionNew ();
17090       action->action = ValNodeNew (NULL);
17091       action->action->choice = LocationEditType_set_5_partial;
17092       action->action->data.ptrvalue = set5;
17093       set5->extend = GetStatus (dlg->extend5);
17094       val2 = GetValue (dlg->set_5_type);
17095       switch (val2) {
17096         case 1:
17097           set5->constraint = Partial_5_set_constraint_all;
17098           break;
17099         case 2:
17100           set5->constraint = Partial_5_set_constraint_at_end;
17101           break;
17102         case 3:
17103           set5->constraint = Partial_5_set_constraint_bad_start;
17104           break;
17105         case 4:
17106           set5->constraint = Partial_5_set_constraint_frame_not_one;
17107           break;
17108         default:
17109           action = EditFeatureLocationActionFree (action);
17110           return NULL;
17111           break;
17112       }
17113       break;
17114     case 3:
17115       action->action = ValNodeNew (NULL);
17116       action->action->choice = LocationEditType_clear_5_partial;
17117       val2 = GetValue (dlg->clear_5_type);
17118       switch (val2) {
17119         case 1:
17120           action->action->data.intvalue = Partial_5_clear_constraint_all;
17121           break;
17122         case 2:
17123           action->action->data.intvalue = Partial_5_clear_constraint_not_at_end;
17124           break;
17125         case 3:
17126           action->action->data.intvalue = Partial_5_clear_constraint_good_start;
17127           break;
17128         default:
17129           action = EditFeatureLocationActionFree (action);
17130           return NULL;
17131           break;
17132       }
17133       break;
17134     case 4:
17135       set3 = Partial3SetActionNew ();
17136       action->action = ValNodeNew (NULL);
17137       action->action->choice = LocationEditType_set_3_partial;
17138       action->action->data.ptrvalue = set3;
17139       set3->extend = GetStatus (dlg->extend3);
17140       val2 = GetValue (dlg->set_3_type);
17141       switch (val2) {
17142         case 1:
17143           set3->constraint = Partial_3_set_constraint_all;
17144           break;
17145         case 2:
17146           set3->constraint = Partial_3_set_constraint_at_end;
17147           break;
17148         case 3:
17149           set3->constraint = Partial_3_set_constraint_bad_end;
17150           break;
17151         default:
17152           action = EditFeatureLocationActionFree (action);
17153           return NULL;
17154           break;
17155       }
17156       break;
17157     case 5:
17158       action->action = ValNodeNew (NULL);
17159       action->action->choice = LocationEditType_clear_3_partial;
17160       val2 = GetValue (dlg->clear_3_type);
17161       switch (val2) {
17162         case 1:
17163           action->action->data.intvalue = Partial_3_clear_constraint_all;
17164           break;
17165         case 2:
17166           action->action->data.intvalue = Partial_3_clear_constraint_not_at_end;
17167           break;
17168         case 3:
17169           action->action->data.intvalue = Partial_3_clear_constraint_good_end;
17170           break;
17171         default:
17172           action = EditFeatureLocationActionFree (action);
17173           return NULL;
17174           break;
17175       }
17176       break;
17177     case 6:
17178       setboth = PartialBothSetActionNew ();
17179       action->action = ValNodeNew (NULL);
17180       action->action->choice = LocationEditType_set_both_partial;
17181       action->action->data.ptrvalue = setboth;
17182       setboth->extend = GetStatus (dlg->extendboth);
17183       val2 = GetValue (dlg->set_both_type);
17184       switch (val2) {
17185         case 1:
17186           setboth->constraint = Partial_both_set_constraint_all;
17187           break;
17188         case 2:
17189           setboth->constraint = Partial_both_set_constraint_at_end;
17190           break;
17191         default:
17192           action = EditFeatureLocationActionFree (action);
17193           return NULL;
17194           break;
17195       }
17196       break;
17197     case 7:
17198       action->action = ValNodeNew (NULL);
17199       action->action->choice = LocationEditType_clear_both_partial;
17200       val2 = GetValue (dlg->clear_both_type);
17201       switch (val2) {
17202         case 1:
17203           action->action->data.intvalue = Partial_both_clear_constraint_all;
17204           break;
17205         case 2:
17206           action->action->data.intvalue = Partial_both_clear_constraint_not_at_end;
17207           break;
17208         default:
17209           action = EditFeatureLocationActionFree (action);
17210           return NULL;
17211           break;
17212       }
17213       break;
17214     case 8:
17215       action->action = ValNodeNew (NULL);
17216       action->action->choice = LocationEditType_convert;
17217       val2 = GetValue (dlg->convert_loc);
17218       switch (val2) {
17219         case 1:
17220           action->action->data.intvalue = Convert_location_type_join;
17221           break;
17222         case 2:
17223           action->action->data.intvalue = Convert_location_type_order;
17224           break;
17225         case 3:
17226           action->action->data.intvalue = Convert_location_type_merge;
17227           break;
17228         default:
17229           action = EditFeatureLocationActionFree (action);
17230           return NULL;
17231           break;
17232       }
17233       break;
17234     case 9:
17235       action->action = ValNodeNew (NULL);
17236       action->action->choice = LocationEditType_extend_5;
17237       break;
17238     case 10:
17239       action->action = ValNodeNew (NULL);
17240       action->action->choice = LocationEditType_extend_3;
17241       break;
17242     case 11:
17243       action->action = ValNodeNew (NULL);
17244       action->action->choice = LocationEditType_extend_5_to_feat;
17245       action->action->data.ptrvalue = DialogToPointer (dlg->extend_to_feat);
17246       if (action->action->data.ptrvalue == NULL) {
17247         action = EditFeatureLocationActionFree (action);
17248       }
17249       break;
17250     case 12:
17251       action->action = ValNodeNew (NULL);
17252       action->action->choice = LocationEditType_extend_3_to_feat;
17253       action->action->data.ptrvalue = DialogToPointer (dlg->extend_to_feat);
17254       if (action->action->data.ptrvalue == NULL) {
17255         action = EditFeatureLocationActionFree (action);
17256       }
17257       break;
17258     default:
17259       action = EditFeatureLocationActionFree (action);
17260       break;
17261   }
17262 
17263   return action;
17264 }
17265 
17266 
TestEditFeatureLocationActionDialog(DialoG d)17267 static ValNodePtr TestEditFeatureLocationActionDialog (DialoG d)
17268 {
17269   EditFeatureLocationActionDlgPtr dlg;
17270   EditFeatureLocationActionPtr a;
17271   ValNodePtr err_list = NULL;
17272 
17273   dlg = (EditFeatureLocationActionDlgPtr) GetObjectExtra (d);
17274   if (dlg == NULL) return NULL;
17275   a = (EditFeatureLocationActionPtr) DialogToPointer (d);
17276   if (a == NULL) {
17277     ValNodeAddPointer (&err_list, 0, "bad action");
17278   } else {
17279     a = EditFeatureLocationActionFree (a);
17280     err_list = TestDialog (dlg->feature_type_dlg);
17281   }
17282   return err_list;
17283 }
17284 
17285 
ChangeEditFeatureLocationPopup(PopuP p)17286 static void ChangeEditFeatureLocationPopup (PopuP p)
17287 {
17288   EditFeatureLocationActionDlgPtr dlg;
17289 
17290   dlg = (EditFeatureLocationActionDlgPtr) GetObjectExtra (p);
17291   if (dlg != NULL && dlg->change_notify != NULL) {
17292     (dlg->change_notify) (dlg->change_userdata);
17293   }
17294 }
17295 
17296 
ChangeEditFeatureLocationButton(ButtoN b)17297 static void ChangeEditFeatureLocationButton (ButtoN b)
17298 {
17299   EditFeatureLocationActionDlgPtr dlg;
17300 
17301   dlg = (EditFeatureLocationActionDlgPtr) GetObjectExtra (b);
17302   if (dlg != NULL && dlg->change_notify != NULL) {
17303     (dlg->change_notify) (dlg->change_userdata);
17304   }
17305 }
17306 
17307 
17308 static DialoG
EditFeatureLocationActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)17309 EditFeatureLocationActionDialog
17310 (GrouP h,
17311  Boolean indexer_version,
17312  Nlm_ChangeNotifyProc     change_notify,
17313  Pointer                  change_userdata)
17314 {
17315   EditFeatureLocationActionDlgPtr dlg;
17316   GrouP                     p;
17317   GrouP                     g;
17318 
17319   dlg = (EditFeatureLocationActionDlgPtr) MemNew (sizeof (EditFeatureLocationActionDlgData));
17320   p = HiddenGroup (h, -1, 0, NULL);
17321   SetGroupSpacing (p, 10, 10);
17322   SetObjectExtra (p, dlg, StdCleanupExtraProc);
17323 
17324   dlg->dialog = (DialoG) p;
17325   dlg->todialog = EditFeatureLocationActionToDialog;
17326   dlg->fromdialog = DialogToEditFeatureLocationAction;
17327   dlg->dialogmessage = NULL;
17328   dlg->testdialog = TestEditFeatureLocationActionDialog;
17329   dlg->change_notify = change_notify;
17330   dlg->change_userdata = change_userdata;
17331 
17332   dlg->feature_type_dlg = FeatureTypeDialog (p, change_notify, change_userdata);
17333 
17334   dlg->feature_edit_type = PopupList (p, TRUE, ChangeFeatureLocationEditType);
17335   SetObjectExtra (dlg->feature_edit_type, dlg, NULL);
17336   PopupItem (dlg->feature_edit_type, "Edit Strand");
17337   PopupItem (dlg->feature_edit_type, "Set 5' Partial");
17338   PopupItem (dlg->feature_edit_type, "Clear 5' Partial");
17339   PopupItem (dlg->feature_edit_type, "Set 3' Partial");
17340   PopupItem (dlg->feature_edit_type, "Clear 3' Partial");
17341   PopupItem (dlg->feature_edit_type, "Set Both Ends Partial");
17342   PopupItem (dlg->feature_edit_type, "Clear Both Ends Partial");
17343   PopupItem (dlg->feature_edit_type, "Convert location");
17344   PopupItem (dlg->feature_edit_type, "Extend 5' end to end of sequence");
17345   PopupItem (dlg->feature_edit_type, "Extend 3' end to end of sequence");
17346   PopupItem (dlg->feature_edit_type, "Extend 5' end to upstream feature");
17347   PopupItem (dlg->feature_edit_type, "Extend 3' end to downstream feature");
17348   SetValue (dlg->feature_edit_type, 1);
17349 
17350   g = HiddenGroup (p, 0, 0, NULL);
17351   dlg->strand_edit_grp = HiddenGroup (g, 4, 0, NULL);
17352 
17353   /* strand */
17354   StaticPrompt (dlg->strand_edit_grp, "Convert location strand from", 0, dialogTextHeight, systemFont, 'l');
17355   dlg->strand_from = PopupList (dlg->strand_edit_grp, TRUE, ChangeEditFeatureLocationPopup);
17356   SetObjectExtra (dlg->strand_from, dlg, NULL);
17357   PopupItem (dlg->strand_from, "Any");
17358   PopupItem (dlg->strand_from, "Plus");
17359   PopupItem (dlg->strand_from, "Minus");
17360   PopupItem (dlg->strand_from, "Unknown");
17361   PopupItem (dlg->strand_from, "Both");
17362   SetValue (dlg->strand_from, 1);
17363   dlg->strand_to = PopupList (dlg->strand_edit_grp, TRUE, ChangeEditFeatureLocationPopup);
17364   SetObjectExtra (dlg->strand_to, dlg, NULL);
17365   PopupItem (dlg->strand_to, "Plus");
17366   PopupItem (dlg->strand_to, "Minus");
17367   PopupItem (dlg->strand_to, "Unknown");
17368   PopupItem (dlg->strand_to, "Both");
17369   PopupItem (dlg->strand_to, "Reverse");
17370   SetValue (dlg->strand_to, 5);
17371 
17372   /* partials */
17373   dlg->set_5_partial_grp = HiddenGroup (g, 2, 0, NULL);
17374   dlg->set_5_type = PopupList (dlg->set_5_partial_grp, TRUE, ChangeEditFeatureLocationPopup);
17375   SetObjectExtra (dlg->set_5_type, dlg, NULL);
17376   PopupItem (dlg->set_5_type, "All");
17377   PopupItem (dlg->set_5_type, "If 5' end at end of sequence");
17378   PopupItem (dlg->set_5_type, "If bad start codon");
17379   PopupItem (dlg->set_5_type, "If CDS frame > 1");
17380   SetValue (dlg->set_5_type, 1);
17381   dlg->extend5 = CheckBox (dlg->set_5_partial_grp, "Extend to 5' end if partial is set", ChangeEditFeatureLocationButton);
17382   SetObjectExtra (dlg->extend5, dlg, NULL);
17383 
17384   dlg->clear_5_type = PopupList (g, TRUE, ChangeEditFeatureLocationPopup);
17385   SetObjectExtra (dlg->clear_5_type, dlg, NULL);
17386   PopupItem (dlg->clear_5_type, "All");
17387   PopupItem (dlg->clear_5_type, "If 5' end not at end of sequence");
17388   PopupItem (dlg->clear_5_type, "If good start codon");
17389   SetValue (dlg->clear_5_type, 1);
17390 
17391   dlg->set_3_partial_grp = HiddenGroup (g, 2, 0, NULL);
17392   dlg->set_3_type = PopupList (dlg->set_3_partial_grp, TRUE, ChangeEditFeatureLocationPopup);
17393   SetObjectExtra (dlg->set_3_type, dlg, NULL);
17394   PopupItem (dlg->set_3_type, "All");
17395   PopupItem (dlg->set_3_type, "If 3' end at end of sequence");
17396   PopupItem (dlg->set_3_type, "If bad stop codon");
17397   SetValue (dlg->set_3_type, 1);
17398   dlg->extend3 = CheckBox (dlg->set_3_partial_grp, "Extend to 3' end if partial is set", ChangeEditFeatureLocationButton);
17399   SetObjectExtra (dlg->extend3, dlg, NULL);
17400 
17401   dlg->clear_3_type = PopupList (g, TRUE, ChangeEditFeatureLocationPopup);
17402   SetObjectExtra (dlg->clear_3_type, dlg, NULL);
17403   PopupItem (dlg->clear_3_type, "All");
17404   PopupItem (dlg->clear_3_type, "If 3' end not at end of sequence");
17405   PopupItem (dlg->clear_3_type, "If good stop codon");
17406   SetValue (dlg->clear_3_type, 1);
17407 
17408   dlg->set_both_partial_grp = HiddenGroup (g, 2, 0, NULL);
17409   dlg->set_both_type = PopupList (dlg->set_both_partial_grp, TRUE, ChangeEditFeatureLocationPopup);
17410   SetObjectExtra (dlg->set_both_type, dlg, NULL);
17411   PopupItem (dlg->set_both_type, "All");
17412   PopupItem (dlg->set_both_type, "If both ends at end of sequence");
17413   SetValue (dlg->set_both_type, 1);
17414   dlg->extendboth = CheckBox (dlg->set_both_partial_grp, "Extend to ends of sequence if partials are set", ChangeEditFeatureLocationButton);
17415   SetObjectExtra (dlg->extendboth, dlg, NULL);
17416 
17417   dlg->clear_both_type = PopupList (g, TRUE, ChangeEditFeatureLocationPopup);
17418   SetObjectExtra (dlg->clear_both_type, dlg, NULL);
17419   PopupItem (dlg->clear_both_type, "All");
17420   PopupItem (dlg->clear_both_type, "If both ends not at end of sequence");
17421   SetValue (dlg->clear_both_type, 1);
17422 
17423   /* convert location */
17424   dlg->convert_loc = PopupList (g, TRUE, ChangeEditFeatureLocationPopup);
17425   SetObjectExtra (dlg->convert_loc, dlg, NULL);
17426   PopupItem (dlg->convert_loc, "Join");
17427   PopupItem (dlg->convert_loc, "Order");
17428   PopupItem (dlg->convert_loc, "Single Interval");
17429   SetValue (dlg->convert_loc, 1);
17430 
17431   /* extending to features */
17432   dlg->extend_to_feat = ExtendToFeatureDialog (g, dlg->change_notify, dlg->change_userdata);
17433 
17434   AlignObjects (ALIGN_MIDDLE, (HANDLE) dlg->strand_edit_grp,
17435                               (HANDLE) dlg->set_5_partial_grp,
17436                               (HANDLE) dlg->clear_5_type,
17437                               (HANDLE) dlg->set_3_partial_grp,
17438                               (HANDLE) dlg->clear_3_type,
17439                               (HANDLE) dlg->set_both_partial_grp,
17440                               (HANDLE) dlg->clear_both_type,
17441                               (HANDLE) dlg->convert_loc,
17442                               (HANDLE) dlg->extend_to_feat,
17443                               (HANDLE) NULL);
17444 
17445   /* retranslate option */
17446   dlg->retranslate_cds = CheckBox (p, "Retranslate coding region if location changes", ChangeEditFeatureLocationButton);
17447   SetObjectExtra (dlg->retranslate_cds, dlg, NULL);
17448   dlg->also_edit_gene = CheckBox (p, "Also edit overlapping gene location", ChangeEditFeatureLocationButton);
17449   SetObjectExtra (dlg->also_edit_gene, dlg, NULL);
17450 
17451 //  dlg->constraint_dlg = ConstraintSetDialog (p, change_notify, change_userdata);
17452   dlg->constraint_dlg = ComplexConstraintDialog (p, change_notify, change_userdata);
17453   SetComplexConstraintType (dlg->constraint_dlg, eComplexConstraintType_loc);
17454 
17455   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->feature_type_dlg,
17456                               (HANDLE) dlg->feature_edit_type,
17457                               (HANDLE) g,
17458                               (HANDLE) dlg->retranslate_cds,
17459                               (HANDLE) dlg->also_edit_gene,
17460                               (HANDLE) dlg->constraint_dlg,
17461                               NULL);
17462 
17463   ChangeFeatureLocationEditType (dlg->feature_edit_type);
17464 
17465   return (DialoG) p;
17466 }
17467 
17468 
17469 typedef struct parsesrcgeneraliddlg {
17470  DIALOG_MESSAGE_BLOCK
17471  PopuP wanted;
17472  TexT  db_wanted;
17473  Nlm_ChangeNotifyProc change_notify;
17474  Pointer              change_userdata;
17475 } ParseSrcGeneralIdDlgData, PNTR ParseSrcGeneralIdDlgPtr;
17476 
17477 
ChangeParseSrcGeneralIdDialogPopup(PopuP p)17478 static void ChangeParseSrcGeneralIdDialogPopup (PopuP p)
17479 {
17480   ParseSrcGeneralIdDlgPtr dlg;
17481   Int2           val;
17482 
17483   dlg = (ParseSrcGeneralIdDlgPtr) GetObjectExtra (p);
17484   if (dlg == NULL) return;
17485 
17486   val = GetValue (dlg->wanted);
17487   if (val == 3) {
17488     Show (dlg->db_wanted);
17489   } else {
17490     Hide (dlg->db_wanted);
17491   }
17492   if (dlg->change_notify != NULL) {
17493     (dlg->change_notify) (dlg->change_userdata);
17494   }
17495 }
17496 
17497 
ParseSrcGeneralIdToDialog(DialoG d,Pointer data)17498 static void ParseSrcGeneralIdToDialog (DialoG d, Pointer data)
17499 {
17500   ParseSrcGeneralIdDlgPtr dlg;
17501   ValNodePtr  id;
17502 
17503   dlg = (ParseSrcGeneralIdDlgPtr) GetObjectExtra (d);
17504   if (dlg == NULL) return;
17505 
17506   Hide (dlg->db_wanted);
17507   if ((id = (ValNodePtr) data) == NULL) {
17508     SetValue (dlg->wanted, 1);
17509     SetTitle (dlg->db_wanted, "");
17510   } else {
17511     switch (id->choice) {
17512       case ParseSrcGeneralId_whole_text:
17513         SetValue (dlg->wanted, 1);
17514         SetTitle (dlg->db_wanted, "");
17515         break;
17516       case ParseSrcGeneralId_db:
17517         SetValue (dlg->wanted, 2);
17518         SetTitle (dlg->db_wanted, "");
17519         break;
17520       case ParseSrcGeneralId_tag:
17521         SetValue (dlg->wanted, 3);
17522         if (StringHasNoText (id->data.ptrvalue)) {
17523           SetTitle (dlg->db_wanted, "");
17524         } else {
17525           SetTitle (dlg->db_wanted, id->data.ptrvalue);
17526         }
17527         Show (dlg->db_wanted);
17528         break;
17529       default:
17530         SetValue (dlg->wanted, 1);
17531         SetTitle (dlg->db_wanted, "");
17532         break;
17533     }
17534   }
17535 }
17536 
17537 
ParseSrcGeneralIdFromDialog(DialoG d)17538 static Pointer ParseSrcGeneralIdFromDialog (DialoG d)
17539 {
17540   ParseSrcGeneralIdDlgPtr dlg;
17541   ValNodePtr  id;
17542   Int2        val;
17543 
17544   dlg = (ParseSrcGeneralIdDlgPtr) GetObjectExtra (d);
17545   if (dlg == NULL) return NULL;
17546 
17547   id = ValNodeNew (NULL);
17548   val = GetValue (dlg->wanted);
17549   switch (val) {
17550     case 1:
17551       id->choice = ParseSrcGeneralId_whole_text;
17552       break;
17553     case 2:
17554       id->choice = ParseSrcGeneralId_db;
17555       break;
17556     case 3:
17557       id->choice = ParseSrcGeneralId_tag;
17558       if (!TextHasNoText (dlg->db_wanted)) {
17559         id->data.ptrvalue = SaveStringFromText (dlg->db_wanted);
17560       }
17561       break;
17562     default:
17563       id->choice = ParseSrcGeneralId_whole_text;
17564       break;
17565   }
17566   return id;
17567 }
17568 
17569 
ChangeParseGeneralIdDlgText(TexT t)17570 static void ChangeParseGeneralIdDlgText (TexT t)
17571 {
17572   ParseSrcGeneralIdDlgPtr dlg;
17573 
17574   dlg = (ParseSrcGeneralIdDlgPtr) GetObjectExtra (t);
17575   if (dlg == NULL) {
17576     return;
17577   }
17578   if (dlg->change_notify != NULL) {
17579     (dlg->change_notify) (dlg->change_userdata);
17580   }
17581 }
17582 
17583 
ParseGeneralIdDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)17584 static DialoG ParseGeneralIdDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
17585 {
17586   ParseSrcGeneralIdDlgPtr dlg;
17587   GrouP          p;
17588 
17589   p = HiddenGroup (h, 2, 0, NULL);
17590   SetGroupSpacing (p, 10, 10);
17591 
17592   dlg = (ParseSrcGeneralIdDlgPtr) MemNew (sizeof (ParseSrcGeneralIdDlgData));
17593   SetObjectExtra (p, dlg, StdCleanupExtraProc);
17594 
17595   dlg->dialog = (DialoG) p;
17596   dlg->fromdialog = ParseSrcGeneralIdFromDialog;
17597   dlg->todialog = ParseSrcGeneralIdToDialog;
17598   dlg->change_notify = change_notify;
17599   dlg->change_userdata = change_userdata;
17600 
17601   dlg->wanted = PopupList (p, TRUE, ChangeParseSrcGeneralIdDialogPopup);
17602   SetObjectExtra (dlg->wanted, dlg, NULL);
17603   PopupItem (dlg->wanted, "Entire General ID");
17604   PopupItem (dlg->wanted, "General ID db");
17605   PopupItem (dlg->wanted, "General ID tag");
17606   SetValue (dlg->wanted, 1);
17607   dlg->db_wanted = DialogText (p, "", 5, ChangeParseGeneralIdDlgText);
17608   SetObjectExtra (dlg->db_wanted, dlg, NULL);
17609   Hide (dlg->db_wanted);
17610 
17611   return (DialoG) p;
17612 }
17613 
17614 
17615 typedef struct parsesrcdlg {
17616  DIALOG_MESSAGE_BLOCK
17617  PopuP main_choice;
17618  GrouP src_grp;
17619  DialoG src_qual_choice;
17620  GrouP feat_or_desc;
17621  TexT  structured_comment_field;
17622  DialoG structured_comment_field_list;
17623  DialoG general_id_dlg;
17624 
17625  Nlm_ChangeNotifyProc change_notify;
17626  Pointer              change_userdata;
17627 } ParseSrcDlgData, PNTR ParseSrcDlgPtr;
17628 
17629 
ChangeParseSrcDialogPopup(PopuP p)17630 static void ChangeParseSrcDialogPopup (PopuP p)
17631 {
17632   ParseSrcDlgPtr dlg;
17633   Int2           val;
17634 
17635   dlg = (ParseSrcDlgPtr) GetObjectExtra (p);
17636   if (dlg == NULL) return;
17637 
17638   val = GetValue (dlg->main_choice);
17639   switch (val) {
17640     case 5:
17641       Show (dlg->src_grp);
17642       SafeHide (dlg->structured_comment_field);
17643       SafeHide (dlg->structured_comment_field_list);
17644       SafeHide (dlg->general_id_dlg);
17645       break;
17646     case 8:
17647       SafeShow (dlg->structured_comment_field);
17648       SafeShow (dlg->structured_comment_field_list);
17649       SafeHide (dlg->general_id_dlg);
17650       Hide (dlg->src_grp);
17651       break;
17652     case 11:
17653       SafeHide (dlg->structured_comment_field);
17654       SafeHide (dlg->structured_comment_field_list);
17655       SafeShow (dlg->general_id_dlg);
17656       Hide (dlg->src_grp);
17657       break;
17658     default:
17659       SafeHide (dlg->structured_comment_field);
17660       SafeHide (dlg->structured_comment_field_list);
17661       SafeHide (dlg->general_id_dlg);
17662       Hide (dlg->src_grp);
17663       break;
17664   }
17665   if (dlg->change_notify != NULL) {
17666     (dlg->change_notify) (dlg->change_userdata);
17667   }
17668 }
17669 
17670 
ChangeParseSrcDialogText(TexT t)17671 static void ChangeParseSrcDialogText (TexT t)
17672 {
17673   ParseSrcDlgPtr dlg;
17674 
17675   dlg = (ParseSrcDlgPtr) GetObjectExtra (t);
17676   if (dlg == NULL) return;
17677 
17678   if (dlg->change_notify != NULL) {
17679     (dlg->change_notify) (dlg->change_userdata);
17680   }
17681 }
17682 
17683 
ParseSrcToDialog(DialoG d,Pointer data)17684 static void ParseSrcToDialog (DialoG d, Pointer data)
17685 {
17686   ParseSrcDlgPtr dlg;
17687   ValNodePtr src;
17688   ParseSrcOrgPtr org;
17689   ValNode        vn;
17690 
17691   dlg = (ParseSrcDlgPtr) GetObjectExtra (d);
17692   if (dlg == NULL) return;
17693 
17694   src = (ValNodePtr) data;
17695   if (src == NULL) {
17696     SetValue (dlg->main_choice, 4);
17697     vn.choice = 0;
17698     vn.data.ptrvalue = kTaxnameAfterBinomialString;
17699     vn.next = NULL;
17700     PointerToDialog (dlg->src_qual_choice, &vn);
17701     SetValue (dlg->feat_or_desc, 1);
17702   } else {
17703     switch (src->choice) {
17704       case ParseSrc_defline:
17705         SetValue (dlg->main_choice, 1);
17706         break;
17707       case ParseSrc_flatfile:
17708         SetValue (dlg->main_choice, 2);
17709         break;
17710       case ParseSrc_local_id:
17711         SetValue (dlg->main_choice, 3);
17712         break;
17713       case ParseSrc_org:
17714         org = (ParseSrcOrgPtr) src->data.ptrvalue;
17715         if (org == NULL) {
17716           SetValue (dlg->main_choice, 5);
17717           SetValue (dlg->feat_or_desc, 1);
17718           PointerToDialog (dlg->src_qual_choice, NULL);
17719         } else {
17720           switch (org->type) {
17721             case Object_type_constraint_any:
17722               SetValue (dlg->feat_or_desc, 1);
17723               break;
17724             case Object_type_constraint_feature:
17725               SetValue (dlg->feat_or_desc, 2);
17726               break;
17727             case Object_type_constraint_descriptor:
17728               SetValue (dlg->feat_or_desc, 3);
17729               break;
17730             default:
17731               SetValue (dlg->feat_or_desc, 1);
17732               break;
17733           }
17734           if (org->field == NULL) {
17735             PointerToDialog (dlg->src_qual_choice, NULL);
17736             SetValue (dlg->main_choice, 5);
17737           } else if (org->field->choice == ParseSrcOrgChoice_taxname_after_binomial) {
17738             SetValue (dlg->main_choice, 9);
17739           } else if (org->field->choice == ParseSrcOrgChoice_source_qual) {
17740             vn.choice = 0;
17741             vn.data.ptrvalue = GetSourceQualName (org->field->data.intvalue);
17742             vn.next = NULL;
17743             PointerToDialog (dlg->src_qual_choice, &vn);
17744             if (org->field->data.intvalue == Source_qual_taxname) {
17745               SetValue (dlg->main_choice, 4);
17746             } else {
17747               SetValue (dlg->main_choice, 5);
17748             }
17749           } else {
17750             PointerToDialog (dlg->src_qual_choice, NULL);
17751             SetValue (dlg->main_choice, 5);
17752           }
17753         }
17754         break;
17755       case ParseSrc_comment:
17756         SetValue (dlg->main_choice, 6);
17757         break;
17758       case ParseSrc_bankit_comment:
17759         SetValue (dlg->main_choice, 7);
17760         break;
17761       case ParseSrc_structured_comment:
17762         SetValue (dlg->main_choice, 8);
17763         if (dlg->structured_comment_field != NULL) {
17764           SetTitle (dlg->structured_comment_field, src->data.ptrvalue);
17765         } else {
17766           PointerToDialog (dlg->structured_comment_field_list, src->data.ptrvalue);
17767         }
17768         break;
17769       case ParseSrc_file_id:
17770         SetValue (dlg->main_choice, 10);
17771         break;
17772       case ParseSrc_general_id:
17773         SetValue (dlg->main_choice, 11);
17774         PointerToDialog (dlg->general_id_dlg, src->data.ptrvalue);
17775         break;
17776       default:
17777         SetValue (dlg->main_choice, 0);
17778         break;
17779     }
17780   }
17781 
17782   ChangeParseSrcDialogPopup (dlg->main_choice);
17783 }
17784 
17785 
DialogToParseSrc(DialoG d)17786 static Pointer DialogToParseSrc (DialoG d)
17787 {
17788   ParseSrcDlgPtr dlg;
17789   ParseSrcOrgPtr org;
17790   ValNodePtr     src = NULL, vnp;
17791   Int2           val;
17792 
17793   dlg = (ParseSrcDlgPtr) GetObjectExtra (d);
17794   if (dlg == NULL) return NULL;
17795 
17796   val = GetValue (dlg->main_choice);
17797   switch (val) {
17798     case 1:
17799       src = ValNodeNew (NULL);
17800       src->choice = ParseSrc_defline;
17801       break;
17802     case 2:
17803       src = ValNodeNew (NULL);
17804       src->choice = ParseSrc_flatfile;
17805       break;
17806     case 3:
17807       src = ValNodeNew (NULL);
17808       src->choice = ParseSrc_local_id;
17809       break;
17810     case 4:
17811       org = ParseSrcOrgNew ();
17812       switch (GetValue (dlg->feat_or_desc)) {
17813         case 1:
17814           org->type = Object_type_constraint_any;
17815           break;
17816         case 2:
17817           org->type = Object_type_constraint_feature;
17818           break;
17819         case 3:
17820           org->type = Object_type_constraint_descriptor;
17821           break;
17822         default:
17823           org->type = Object_type_constraint_any;
17824           break;
17825       }
17826       org->field = ValNodeNew (NULL);
17827       org->field->choice = ParseSrcOrgChoice_source_qual;
17828       org->field->data.intvalue = Source_qual_taxname;
17829       src = ValNodeNew (NULL);
17830       src->choice = ParseSrc_org;
17831       src->data.ptrvalue = org;
17832       break;
17833     case 5:
17834       org = ParseSrcOrgNew ();
17835       switch (GetValue (dlg->feat_or_desc)) {
17836         case 1:
17837           org->type = Object_type_constraint_any;
17838           break;
17839         case 2:
17840           org->type = Object_type_constraint_feature;
17841           break;
17842         case 3:
17843           org->type = Object_type_constraint_descriptor;
17844           break;
17845         default:
17846           org->type = Object_type_constraint_any;
17847           break;
17848       }
17849       vnp = (ValNodePtr) DialogToPointer (dlg->src_qual_choice);
17850       if (vnp != NULL) {
17851         org->field = ValNodeNew (NULL);
17852         if (StringCmp (vnp->data.ptrvalue, kTaxnameAfterBinomialString) == 0) {
17853           org->field->choice = ParseSrcOrgChoice_taxname_after_binomial;
17854         } else {
17855           org->field->choice = ParseSrcOrgChoice_source_qual;
17856           org->field->data.intvalue = GetSourceQualTypeByName (vnp->data.ptrvalue);
17857         }
17858         vnp = ValNodeFree (vnp);
17859       }
17860       src = ValNodeNew (NULL);
17861       src->choice = ParseSrc_org;
17862       src->data.ptrvalue = org;
17863       break;
17864     case 6:
17865       src = ValNodeNew (NULL);
17866       src->choice = ParseSrc_comment;
17867       break;
17868     case 7:
17869       src = ValNodeNew (NULL);
17870       src->choice = ParseSrc_bankit_comment;
17871       break;
17872     case 8:
17873       src = ValNodeNew (NULL);
17874       src->choice = ParseSrc_structured_comment;
17875       if (dlg->structured_comment_field != NULL) {
17876         src->data.ptrvalue = SaveStringFromText (dlg->structured_comment_field);
17877       } else {
17878         src->data.ptrvalue = DialogToPointer (dlg->structured_comment_field_list);
17879       }
17880       break;
17881     case 9:
17882       org = ParseSrcOrgNew ();
17883       switch (GetValue (dlg->feat_or_desc)) {
17884         case 1:
17885           org->type = Object_type_constraint_any;
17886           break;
17887         case 2:
17888           org->type = Object_type_constraint_feature;
17889           break;
17890         case 3:
17891           org->type = Object_type_constraint_descriptor;
17892           break;
17893         default:
17894           org->type = Object_type_constraint_any;
17895           break;
17896       }
17897       org->field = ValNodeNew (NULL);
17898       org->field->choice = ParseSrcOrgChoice_taxname_after_binomial;
17899       src = ValNodeNew (NULL);
17900       src->choice = ParseSrc_org;
17901       src->data.ptrvalue = org;
17902       break;
17903     case 10:
17904       src = ValNodeNew (NULL);
17905       src->choice = ParseSrc_file_id;
17906       break;
17907     case 11:
17908       src = ValNodeNew (NULL);
17909       src->choice = ParseSrc_general_id;
17910       src->data.ptrvalue = DialogToPointer (dlg->general_id_dlg);
17911       break;
17912   }
17913   return src;
17914 }
17915 
17916 
TestParseSrcDialog(DialoG d)17917 static ValNodePtr TestParseSrcDialog (DialoG d)
17918 {
17919   ParseSrcDlgPtr dlg;
17920   Int2 val;
17921   ValNodePtr err_list = NULL;
17922 
17923   dlg = (ParseSrcDlgPtr) GetObjectExtra (d);
17924   if (dlg == NULL) return NULL;
17925 
17926   val = GetValue (dlg->main_choice);
17927   if (val < 1 || val > 11) {
17928     ValNodeAddPointer (&err_list, 0, "main choice");
17929   } else if (val == 5) {
17930     ValNodeLink (&err_list, TestDialog (dlg->src_qual_choice));
17931   } else if (val == 8 &&
17932              ((dlg->structured_comment_field != NULL && TextHasNoText (dlg->structured_comment_field)))) {
17933     ValNodeAddPointer (&err_list, 0, "structured comment field");
17934   }
17935   return err_list;
17936 }
17937 
17938 
AddCommentFieldName(SeqDescrPtr sdp,Pointer userdata)17939 static void AddCommentFieldName (SeqDescrPtr sdp, Pointer userdata)
17940 {
17941   UserObjectPtr uop;
17942   ObjectIdPtr   oip;
17943   UserFieldPtr  ufp;
17944   ValNodePtr    vnp;
17945   Boolean       found;
17946   ValNodePtr PNTR comment_field_list = (ValNodePtr PNTR) userdata;
17947 
17948   if (comment_field_list == NULL
17949       || sdp->choice != Seq_descr_user
17950       || sdp->extended == 0
17951       || sdp->data.ptrvalue == NULL) {
17952     return;
17953   }
17954 
17955   uop = (UserObjectPtr) sdp->data.ptrvalue;
17956   oip = uop->type;
17957   if (oip != NULL && StringCmp (oip->str, "StructuredComment") == 0)
17958   {
17959     for (ufp = uop->data; ufp != NULL; ufp = ufp->next)
17960     {
17961       oip = ufp->label;
17962       if (oip != NULL && !StringHasNoText (oip->str))
17963       {
17964         found = FALSE;
17965         vnp = *comment_field_list;
17966         while (vnp != NULL && !found) {
17967           if (StringCmp (vnp->data.ptrvalue, oip->str) == 0) {
17968             found = TRUE;
17969           }
17970           vnp = vnp->next;
17971         }
17972         if (!found) {
17973           ValNodeAddPointer (comment_field_list, 0, StringSave (oip->str));
17974         }
17975       }
17976     }
17977   }
17978 }
17979 
17980 
ParseSrcDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,SeqEntryPtr sep)17981 static DialoG ParseSrcDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata, SeqEntryPtr sep)
17982 {
17983   ParseSrcDlgPtr dlg;
17984   GrouP          p, g;
17985   ValNodePtr     qual_list;
17986   ValNodePtr     structured_comment_field_list = NULL;
17987   ValNode        vn;
17988 
17989   p = HiddenGroup (h, 2, 0, NULL);
17990   SetGroupSpacing (p, 10, 10);
17991 
17992   dlg = (ParseSrcDlgPtr) MemNew (sizeof (ParseSrcDlgData));
17993   SetObjectExtra (p, dlg, StdCleanupExtraProc);
17994 
17995   dlg->dialog = (DialoG) p;
17996   dlg->fromdialog = DialogToParseSrc;
17997   dlg->todialog = ParseSrcToDialog;
17998   dlg->testdialog = TestParseSrcDialog;
17999   dlg->change_notify = change_notify;
18000   dlg->change_userdata = change_userdata;
18001 
18002   VisitDescriptorsInSep (sep, &structured_comment_field_list, AddCommentFieldName);
18003 
18004   dlg->main_choice = PopupList (p, TRUE, ChangeParseSrcDialogPopup);
18005   SetObjectExtra (dlg->main_choice, dlg, NULL);
18006   PopupItem (dlg->main_choice, "Definition Line");
18007   PopupItem (dlg->main_choice, "GenBank FlatFile");
18008   PopupItem (dlg->main_choice, "Local ID");
18009   PopupItem (dlg->main_choice, "Organism Name");
18010   PopupItem (dlg->main_choice, "Source Qualifier");
18011   PopupItem (dlg->main_choice, "Comment");
18012   PopupItem (dlg->main_choice, "BankIT Comment");
18013   PopupItem (dlg->main_choice, "Structured Comment");
18014   PopupItem (dlg->main_choice, "Taxname after Binomial");
18015   PopupItem (dlg->main_choice, "File ID");
18016   PopupItem (dlg->main_choice, "General ID");
18017   SetValue (dlg->main_choice, 4);
18018 
18019   g = HiddenGroup (p, 0, 0, NULL);
18020   dlg->src_grp = HiddenGroup (g, -1, 0, NULL);
18021   qual_list = ValNodeNew (NULL);
18022   qual_list->choice = 0;
18023   qual_list->data.ptrvalue = StringSave (kTaxnameAfterBinomialString);
18024   qual_list->next = GetSourceQualList (FALSE);
18025   dlg->src_qual_choice = ValNodeSelectionDialog (dlg->src_grp, qual_list, SHORT_SELECTION_LIST,
18026                                                ValNodeStringName,
18027                                                ValNodeSimpleDataFree,
18028                                                ValNodeStringCopy,
18029                                                ValNodeStringMatch,
18030                                                "source qual",
18031                                                change_notify, change_userdata, FALSE);
18032   vn.choice = 0;
18033   vn.data.ptrvalue = "Taxname after binomial";
18034   vn.next = NULL;
18035   PointerToDialog (dlg->src_qual_choice, &vn);
18036   dlg->feat_or_desc = HiddenGroup (dlg->src_grp, 3, 0, NULL);
18037   RadioButton (dlg->feat_or_desc, "Descriptors and Features");
18038   RadioButton (dlg->feat_or_desc, "Descriptors Only");
18039   RadioButton (dlg->feat_or_desc, "Features Only");
18040   SetValue (dlg->feat_or_desc, 1);
18041 
18042   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->src_qual_choice, (HANDLE) dlg->feat_or_desc, NULL);
18043   Hide (dlg->src_grp);
18044 
18045   if (structured_comment_field_list == NULL) {
18046     dlg->structured_comment_field = DialogText (g, "", 20, ChangeParseSrcDialogText);
18047     SetObjectExtra (dlg->structured_comment_field, dlg, NULL);
18048     Hide (dlg->structured_comment_field);
18049   } else {
18050     dlg->structured_comment_field_list = StringComboDialog (g, structured_comment_field_list, SHORT_SELECTION_LIST, 20, change_notify, change_userdata);
18051     Hide (dlg->structured_comment_field_list);
18052   }
18053 
18054   dlg->general_id_dlg = ParseGeneralIdDialog(g, change_notify, change_userdata);
18055   Hide (dlg->general_id_dlg);
18056 
18057   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->src_grp, (HANDLE) dlg->structured_comment_field, (HANDLE) dlg->general_id_dlg, NULL);
18058 
18059   return (DialoG) p;
18060 }
18061 
18062 
18063 typedef struct parsedstdlg {
18064  DIALOG_MESSAGE_BLOCK
18065  PopuP main_choice;
18066  GrouP src_grp;
18067  PopuP biosrc_list;
18068  DialoG src_qual_choice;
18069  GrouP feat_or_desc;
18070  PopuP  gene_field;
18071  DialoG rna_field;
18072  PopuP protein_field;
18073  GrouP  feature_field_grp;
18074  DialoG feature_type_choice;
18075  DialoG feature_field_choice;
18076  DialoG feature_note;
18077  TexT  dbxref_db;
18078  Nlm_ChangeNotifyProc change_notify;
18079  Pointer              change_userdata;
18080 } ParseDstDlgData, PNTR ParseDstDlgPtr;
18081 
18082 typedef enum {
18083   eParseDstDialog_defline = 1,
18084   eParseDstDialog_biosrc,
18085   eParseDstDialog_srcqual,
18086   eParseDstDialog_genefield,
18087   eParseDstDialog_rnafield,
18088   eParseDstDialog_cdscomment,
18089   eParseDstDialog_proteinfield,
18090   eParseDstDialog_featqual,
18091   eParseDstDialog_featnote,
18092   eParseDstDialog_commentdesc,
18093   eParseDstDialog_dbxref
18094 } EParseDstDialog;
18095 
18096 #define eParseDstDialog_last eParseDstDialog_dbxref
18097 
ChangeParseDstDialogPopup(PopuP p)18098 static void ChangeParseDstDialogPopup (PopuP p)
18099 {
18100   ParseDstDlgPtr dlg;
18101   Int2 val;
18102 
18103   dlg = (ParseDstDlgPtr) GetObjectExtra (p);
18104   if (dlg == NULL) return;
18105 
18106   val = GetValue (dlg->main_choice);
18107   switch (val) {
18108     case eParseDstDialog_biosrc:
18109       Show (dlg->src_grp);
18110       Show (dlg->biosrc_list);
18111       Hide (dlg->src_qual_choice);
18112       Hide (dlg->feature_field_grp);
18113       Hide (dlg->dbxref_db);
18114       Hide (dlg->rna_field);
18115       Hide (dlg->gene_field);
18116       Hide (dlg->protein_field);
18117       Hide (dlg->feature_note);
18118       break;
18119     case eParseDstDialog_srcqual:
18120       Show (dlg->src_grp);
18121       Hide (dlg->biosrc_list);
18122       Show (dlg->src_qual_choice);
18123       Hide (dlg->feature_field_grp);
18124       Hide (dlg->dbxref_db);
18125       Hide (dlg->rna_field);
18126       Hide (dlg->gene_field);
18127       Hide (dlg->protein_field);
18128       Hide (dlg->feature_note);
18129       break;
18130     case eParseDstDialog_genefield:
18131       Show (dlg->gene_field);
18132       Hide (dlg->src_grp);
18133       Hide (dlg->feature_field_grp);
18134       Hide (dlg->dbxref_db);
18135       Hide (dlg->rna_field);
18136       Hide (dlg->protein_field);
18137       Hide (dlg->feature_note);
18138       break;
18139     case eParseDstDialog_rnafield:
18140       Show (dlg->rna_field);
18141       Hide (dlg->src_grp);
18142       Hide (dlg->feature_field_grp);
18143       Hide (dlg->dbxref_db);
18144       Hide (dlg->gene_field);
18145       Hide (dlg->protein_field);
18146       Hide (dlg->feature_note);
18147       break;
18148     case eParseDstDialog_proteinfield:
18149       Show (dlg->protein_field);
18150       Hide (dlg->rna_field);
18151       Hide (dlg->src_grp);
18152       Hide (dlg->feature_field_grp);
18153       Hide (dlg->dbxref_db);
18154       Hide (dlg->gene_field);
18155       Hide (dlg->feature_note);
18156       break;
18157     case eParseDstDialog_featqual:
18158       Hide (dlg->src_grp);
18159       Show (dlg->feature_field_grp);
18160       Hide (dlg->dbxref_db);
18161       Hide (dlg->rna_field);
18162       Hide (dlg->gene_field);
18163       Hide (dlg->protein_field);
18164       Hide (dlg->feature_note);
18165       break;
18166     case eParseDstDialog_featnote:
18167       Show (dlg->feature_note);
18168       Hide (dlg->src_grp);
18169       Hide (dlg->feature_field_grp);
18170       Hide (dlg->dbxref_db);
18171       Hide (dlg->rna_field);
18172       Hide (dlg->gene_field);
18173       Hide (dlg->protein_field);
18174       break;
18175     case eParseDstDialog_dbxref:
18176       Hide (dlg->src_grp);
18177       Hide (dlg->feature_field_grp);
18178       Show (dlg->dbxref_db);
18179       Hide (dlg->rna_field);
18180       Hide (dlg->gene_field);
18181       Hide (dlg->protein_field);
18182       Hide (dlg->feature_note);
18183       break;
18184     default:
18185       Hide (dlg->src_grp);
18186       Hide (dlg->feature_field_grp);
18187       Hide (dlg->dbxref_db);
18188       Hide (dlg->rna_field);
18189       Hide (dlg->gene_field);
18190       Hide (dlg->protein_field);
18191       Hide (dlg->feature_note);
18192       break;
18193   }
18194   if (dlg->change_notify != NULL) {
18195     (dlg->change_notify)(dlg->change_userdata);
18196   }
18197 }
18198 
18199 
ChangeParseDstDialogText(TexT t)18200 static void ChangeParseDstDialogText (TexT t)
18201 {
18202   ParseDstDlgPtr dlg;
18203 
18204   dlg = (ParseDstDlgPtr) GetObjectExtra (t);
18205   if (dlg == NULL) return;
18206 
18207   if (dlg->change_notify != NULL) {
18208     (dlg->change_notify)(dlg->change_userdata);
18209   }
18210 }
18211 
18212 
ParseDstToDialog(DialoG d,Pointer data)18213 static void ParseDstToDialog (DialoG d, Pointer data)
18214 {
18215   ParseDstDlgPtr dlg;
18216   ValNodePtr     dst;
18217   ParseDstOrgPtr org;
18218   FeatureFieldLegalPtr ffp;
18219   ValNode        vn;
18220 
18221   dlg = (ParseDstDlgPtr) GetObjectExtra (d);
18222   if (dlg == NULL) return;
18223 
18224   dst = (ValNodePtr) data;
18225   if (dst == NULL) {
18226     SetValue (dlg->main_choice, eParseDstDialog_defline);
18227   } else {
18228     switch (dst->choice) {
18229       case ParseDest_defline:
18230         SetValue (dlg->main_choice, eParseDstDialog_defline );
18231         break;
18232       case ParseDest_org:
18233         org = (ParseDstOrgPtr) dst->data.ptrvalue;
18234         if (org == NULL) {
18235           SetValue (dlg->main_choice, eParseDstDialog_srcqual);
18236           PointerToDialog (dlg->src_qual_choice, NULL);
18237           SetValue (dlg->feat_or_desc, 1);
18238         } else {
18239           switch (org->type) {
18240             case Object_type_constraint_any:
18241               SetValue (dlg->feat_or_desc, 1);
18242               break;
18243             case Object_type_constraint_feature:
18244               SetValue (dlg->feat_or_desc, 3);
18245               break;
18246             case Object_type_constraint_descriptor:
18247               SetValue (dlg->feat_or_desc, 2);
18248               break;
18249             default:
18250               SetValue (dlg->feat_or_desc, 1);
18251               break;
18252           }
18253           if (org->field == NULL) {
18254             PointerToDialog (dlg->src_qual_choice, NULL);
18255             SetValue (dlg->main_choice, eParseDstDialog_srcqual);
18256           } else {
18257             switch (org->field->data.intvalue) {
18258               case Source_qual_taxname:
18259                 SetValue (dlg->biosrc_list, 1);
18260                 SetValue (dlg->main_choice, eParseDstDialog_biosrc);
18261                 break;
18262               case Source_qual_lineage:
18263                 SetValue (dlg->biosrc_list, 2);
18264                 SetValue (dlg->main_choice, eParseDstDialog_biosrc);
18265                 break;
18266               case Source_qual_division:
18267                 SetValue (dlg->biosrc_list, 3);
18268                 SetValue (dlg->main_choice, eParseDstDialog_biosrc);
18269                 break;
18270               default:
18271                 vn.choice = 0;
18272                 vn.data.ptrvalue = GetSourceQualName (org->field->data.intvalue);
18273                 vn.next = NULL;
18274                 PointerToDialog (dlg->src_qual_choice, &vn);
18275                 SetValue (dlg->main_choice, eParseDstDialog_srcqual);
18276                 break;
18277             }
18278           }
18279         }
18280         break;
18281       case ParseDest_featqual:
18282         /* TODO - look for RNA fields, gene fields, cds comment, feature note? */
18283         SetValue (dlg->main_choice, eParseDstDialog_featqual);
18284         ffp = (FeatureFieldLegalPtr) dst->data.ptrvalue;
18285         if (ffp == NULL) {
18286           PointerToDialog (dlg->feature_type_choice, NULL);
18287           PointerToDialog (dlg->feature_field_choice, NULL);
18288         } else {
18289           vn.choice = (Uint1)ffp->type;
18290           vn.data.ptrvalue = NULL;
18291           vn.next = NULL;
18292           PointerToDialog (dlg->feature_type_choice, &vn);
18293           vn.choice = (Uint1)ffp->field;
18294           PointerToDialog (dlg->feature_field_choice, &vn);
18295         }
18296         break;
18297       case ParseDest_comment_descriptor:
18298         SetValue (dlg->main_choice, eParseDstDialog_commentdesc);
18299         break;
18300       case ParseDest_dbxref:
18301         SetValue (dlg->main_choice, eParseDstDialog_dbxref);
18302         SetTitle (dlg->dbxref_db, dst->data.ptrvalue);
18303         break;
18304     }
18305   }
18306 
18307   ChangeParseDstDialogPopup (dlg->main_choice);
18308 }
18309 
18310 
DialogToParseDst(DialoG d)18311 static Pointer DialogToParseDst (DialoG d)
18312 {
18313   ParseDstDlgPtr dlg;
18314   ParseDstOrgPtr org;
18315   FeatureFieldLegalPtr ffp;
18316   FeatureFieldPtr ff;
18317   ValNodePtr     dst = NULL, vnp;
18318   Int2           val, subval;
18319   RnaQualPtr     rq;
18320 
18321   dlg = (ParseDstDlgPtr) GetObjectExtra (d);
18322   if (dlg == NULL) return NULL;
18323 
18324   val = GetValue (dlg->main_choice);
18325   switch (val) {
18326     case eParseDstDialog_defline:
18327       dst = ValNodeNew (NULL);
18328       dst->choice = ParseDest_defline;
18329       break;
18330     case eParseDstDialog_biosrc:
18331       org = ParseDstOrgNew ();
18332       switch (GetValue (dlg->feat_or_desc)) {
18333         case 1:
18334           org->type = Object_type_constraint_any;
18335           break;
18336         case 3:
18337           org->type = Object_type_constraint_feature;
18338           break;
18339         case 2:
18340           org->type = Object_type_constraint_descriptor;
18341           break;
18342         default:
18343           org->type = Object_type_constraint_any;
18344           break;
18345       }
18346       subval = GetValue (dlg->biosrc_list);
18347       switch (subval) {
18348         case 1:
18349           org->field = ValNodeNew (NULL);
18350           org->field->choice = SourceQualChoice_textqual;
18351           org->field->data.intvalue = Source_qual_taxname;
18352           break;
18353         case 2:
18354           org->field = ValNodeNew (NULL);
18355           org->field->choice = SourceQualChoice_textqual;
18356           org->field->data.intvalue = Source_qual_lineage;
18357           break;
18358         case 3:
18359           org->field = ValNodeNew (NULL);
18360           org->field->choice = SourceQualChoice_textqual;
18361           org->field->data.intvalue = Source_qual_division;
18362           break;
18363       }
18364       dst = ValNodeNew (NULL);
18365       dst->choice = ParseDest_org;
18366       dst->data.ptrvalue = org;
18367       break;
18368     case eParseDstDialog_srcqual:
18369       org = ParseDstOrgNew ();
18370       switch (GetValue (dlg->feat_or_desc)) {
18371         case 1:
18372           org->type = Object_type_constraint_any;
18373           break;
18374         case 3:
18375           org->type = Object_type_constraint_feature;
18376           break;
18377         case 2:
18378           org->type = Object_type_constraint_descriptor;
18379           break;
18380         default:
18381           org->type = Object_type_constraint_any;
18382           break;
18383       }
18384       vnp = (ValNodePtr) DialogToPointer (dlg->src_qual_choice);
18385       if (vnp != NULL) {
18386         org->field = ValNodeNew (NULL);
18387         org->field->choice = SourceQualChoice_textqual;
18388         org->field->data.intvalue = GetSourceQualTypeByName (vnp->data.ptrvalue);
18389         vnp = ValNodeFree (vnp);
18390       }
18391       dst = ValNodeNew (NULL);
18392       dst->choice = ParseDest_org;
18393       dst->data.ptrvalue = org;
18394       break;
18395     case eParseDstDialog_genefield:
18396       subval = GetValue (dlg->gene_field);
18397       switch (subval) {
18398         case 1: /* locus */
18399           ffp = FeatureFieldLegalNew ();
18400           ffp->type = Macro_feature_type_gene;
18401           ffp->field = Feat_qual_legal_gene;
18402           dst = ValNodeNew (NULL);
18403           dst->choice = ParseDest_featqual;
18404           dst->data.ptrvalue = ffp;
18405           break;
18406         case 2: /* description */
18407           ffp = FeatureFieldLegalNew ();
18408           ffp->type = Macro_feature_type_gene;
18409           ffp->field = Feat_qual_legal_gene_description;
18410           dst = ValNodeNew (NULL);
18411           dst->choice = ParseDest_featqual;
18412           dst->data.ptrvalue = ffp;
18413           break;
18414         case 3: /* comment */
18415           ffp = FeatureFieldLegalNew ();
18416           ffp->type = Macro_feature_type_gene;
18417           ffp->field = Feat_qual_legal_note;
18418           dst = ValNodeNew (NULL);
18419           dst->choice = ParseDest_featqual;
18420           dst->data.ptrvalue = ffp;
18421           break;
18422         case 4: /* allele */
18423           ffp = FeatureFieldLegalNew ();
18424           ffp->type = Macro_feature_type_gene;
18425           ffp->field = Feat_qual_legal_allele;
18426           dst = ValNodeNew (NULL);
18427           dst->choice = ParseDest_featqual;
18428           dst->data.ptrvalue = ffp;
18429           break;
18430         case 5: /* maploc */
18431           ffp = FeatureFieldLegalNew ();
18432           ffp->type = Macro_feature_type_gene;
18433           ffp->field = Feat_qual_legal_map;
18434           dst = ValNodeNew (NULL);
18435           dst->choice = ParseDest_featqual;
18436           dst->data.ptrvalue = ffp;
18437           break;
18438         case 6: /* locus tag */
18439           ffp = FeatureFieldLegalNew ();
18440           ffp->type = Macro_feature_type_gene;
18441           ffp->field = Feat_qual_legal_locus_tag;
18442           dst = ValNodeNew (NULL);
18443           dst->choice = ParseDest_featqual;
18444           dst->data.ptrvalue = ffp;
18445           break;
18446         case 7: /* synonym */
18447           ffp = FeatureFieldLegalNew ();
18448           ffp->type = Macro_feature_type_gene;
18449           ffp->field = Feat_qual_legal_synonym;
18450           dst = ValNodeNew (NULL);
18451           dst->choice = ParseDest_featqual;
18452           dst->data.ptrvalue = ffp;
18453           break;
18454         case 8: /* old locus tag */
18455           ffp = FeatureFieldLegalNew ();
18456           ffp->type = Macro_feature_type_gene;
18457           ffp->field = Feat_qual_legal_old_locus_tag;
18458           dst = ValNodeNew (NULL);
18459           dst->choice = ParseDest_featqual;
18460           dst->data.ptrvalue = ffp;
18461           break;
18462       }
18463       break;
18464     case eParseDstDialog_rnafield:
18465       /* get rna qual, translate to feature qual */
18466       rq = DialogToPointer (dlg->rna_field);
18467       ff = FeatureFieldFromRnaQual (rq);
18468       rq = RnaQualFree (rq);
18469       if (ff != NULL) {
18470         ffp = FeatureFieldLegalNew ();
18471         ffp->type = ff->type;
18472         if (ff->field != NULL) {
18473           ffp->field = ff->field->data.intvalue;
18474         }
18475         dst = ValNodeNew (NULL);
18476         dst->choice = ParseDest_featqual;
18477         dst->data.ptrvalue = ffp;
18478       }
18479       ff = FeatureFieldFree (ff);
18480       break;
18481     case eParseDstDialog_cdscomment:
18482       ffp = FeatureFieldLegalNew ();
18483       ffp->type = Macro_feature_type_cds;
18484       ffp->field = Feat_qual_legal_note;
18485       dst = ValNodeNew (NULL);
18486       dst->choice = ParseDest_featqual;
18487       dst->data.ptrvalue = ffp;
18488       break;
18489     case eParseDstDialog_proteinfield:
18490       subval = GetValue (dlg->protein_field);
18491       switch (subval) {
18492         case 1: /* name */
18493           ffp = FeatureFieldLegalNew ();
18494           ffp->type = Macro_feature_type_cds;
18495           ffp->field = Feat_qual_legal_product;
18496           dst = ValNodeNew (NULL);
18497           dst->choice = ParseDest_featqual;
18498           dst->data.ptrvalue = ffp;
18499           break;
18500         case 2: /* description */
18501           ffp = FeatureFieldLegalNew ();
18502           ffp->type = Macro_feature_type_prot;
18503           ffp->field = Feat_qual_legal_description;
18504           dst = ValNodeNew (NULL);
18505           dst->choice = ParseDest_featqual;
18506           dst->data.ptrvalue = ffp;
18507           break;
18508         case 3: /* e.c. number */
18509           ffp = FeatureFieldLegalNew ();
18510           ffp->type = Macro_feature_type_prot;
18511           ffp->field = Feat_qual_legal_ec_number;
18512           dst = ValNodeNew (NULL);
18513           dst->choice = ParseDest_featqual;
18514           dst->data.ptrvalue = ffp;
18515           break;
18516         case 4: /* activity */
18517           ffp = FeatureFieldLegalNew ();
18518           ffp->type = Macro_feature_type_prot;
18519           ffp->field = Feat_qual_legal_activity;
18520           dst = ValNodeNew (NULL);
18521           dst->choice = ParseDest_featqual;
18522           dst->data.ptrvalue = ffp;
18523           break;
18524         case 5: /* comment */
18525           ffp = FeatureFieldLegalNew ();
18526           ffp->type = Macro_feature_type_prot;
18527           ffp->field = Feat_qual_legal_note;
18528           dst = ValNodeNew (NULL);
18529           dst->choice = ParseDest_featqual;
18530           dst->data.ptrvalue = ffp;
18531           break;
18532         case 6: /* mat-peptide name */
18533           ffp = FeatureFieldLegalNew ();
18534           ffp->type = Macro_feature_type_mat_peptide_aa;
18535           ffp->field = Feat_qual_legal_product;
18536           dst = ValNodeNew (NULL);
18537           dst->choice = ParseDest_featqual;
18538           dst->data.ptrvalue = ffp;
18539           break;
18540         case 7: /* mat-peptide description */
18541           ffp = FeatureFieldLegalNew ();
18542           ffp->type = Macro_feature_type_mat_peptide_aa;
18543           ffp->field = Feat_qual_legal_description;
18544           dst = ValNodeNew (NULL);
18545           dst->choice = ParseDest_featqual;
18546           dst->data.ptrvalue = ffp;
18547           break;
18548         case 8: /* mat-peptide comment */
18549           ffp = FeatureFieldLegalNew ();
18550           ffp->type = Macro_feature_type_mat_peptide_aa;
18551           ffp->field = Feat_qual_legal_note;
18552           dst = ValNodeNew (NULL);
18553           dst->choice = ParseDest_featqual;
18554           dst->data.ptrvalue = ffp;
18555           break;
18556       }
18557       break;
18558     case eParseDstDialog_featqual:
18559       ffp = FeatureFieldLegalNew ();
18560       vnp = (ValNodePtr) DialogToPointer (dlg->feature_type_choice);
18561       if (vnp != NULL) {
18562         ffp->type = vnp->choice;
18563         vnp = ValNodeFree (vnp);
18564       }
18565       vnp = (ValNodePtr) DialogToPointer (dlg->feature_field_choice);
18566       if (vnp != NULL) {
18567         ffp->field = vnp->choice;
18568         vnp = ValNodeFree (vnp);
18569       }
18570       dst = ValNodeNew (NULL);
18571       dst->choice = ParseDest_featqual;
18572       dst->data.ptrvalue = ffp;
18573       break;
18574     case eParseDstDialog_featnote:
18575       ffp = FeatureFieldLegalNew ();
18576       vnp = (ValNodePtr) DialogToPointer (dlg->feature_note);
18577       if (vnp != NULL) {
18578         ffp->type = vnp->choice;
18579         vnp = ValNodeFree (vnp);
18580       }
18581       ffp->field = Feat_qual_legal_note;
18582       dst = ValNodeNew (NULL);
18583       dst->choice = ParseDest_featqual;
18584       dst->data.ptrvalue = ffp;
18585       break;
18586     case eParseDstDialog_commentdesc:
18587       dst = ValNodeNew (NULL);
18588       dst->choice = ParseDest_comment_descriptor;
18589       break;
18590     case eParseDstDialog_dbxref:
18591       dst = ValNodeNew (NULL);
18592       dst->choice = ParseDest_dbxref;
18593       dst->data.ptrvalue = SaveStringFromText (dlg->dbxref_db);
18594       break;
18595   }
18596   return dst;
18597 }
18598 
18599 
TestParseDstDialog(DialoG d)18600 static ValNodePtr TestParseDstDialog (DialoG d)
18601 {
18602   ParseDstDlgPtr dlg;
18603   ValNodePtr     err_list = NULL;
18604   Int2           val;
18605 
18606   dlg = (ParseDstDlgPtr) GetObjectExtra (d);
18607   if (dlg == NULL) return NULL;
18608 
18609   val = GetValue (dlg->main_choice);
18610   if (val < 1 || val > eParseDstDialog_last) {
18611     ValNodeAddPointer (&err_list, 0, "main choice");
18612   } else if (val == eParseDstDialog_srcqual) {
18613     ValNodeLink (&err_list, TestDialog (dlg->src_qual_choice));
18614   } else if (val == eParseDstDialog_rnafield) {
18615     ValNodeLink (&err_list, TestDialog (dlg->rna_field));
18616   } else if (val == eParseDstDialog_featqual) {
18617     ValNodeLink (&err_list, TestDialog (dlg->feature_type_choice));
18618     ValNodeLink (&err_list, TestDialog (dlg->feature_field_choice));
18619   } else if (val == eParseDstDialog_featnote) {
18620     ValNodeLink (&err_list, TestDialog (dlg->feature_note));
18621   } else if (val == eParseDstDialog_dbxref && TextHasNoText (dlg->dbxref_db)) {
18622     ValNodeAddPointer (&err_list, 0, "dbxref db");
18623   }
18624   return err_list;
18625 }
18626 
18627 
ParseDstDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)18628 NLM_EXTERN DialoG ParseDstDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
18629 {
18630   ParseDstDlgPtr dlg;
18631   GrouP          p, g, g2;
18632   ValNodePtr     qual_list;
18633 
18634   p = HiddenGroup (h, 2, 0, NULL);
18635   SetGroupSpacing (p, 10, 10);
18636 
18637   dlg = (ParseDstDlgPtr) MemNew (sizeof (ParseDstDlgData));
18638   SetObjectExtra (p, dlg, StdCleanupExtraProc);
18639 
18640   dlg->dialog = (DialoG) p;
18641   dlg->todialog = ParseDstToDialog;
18642   dlg->fromdialog = DialogToParseDst;
18643   dlg->testdialog = TestParseDstDialog;
18644   dlg->change_notify = change_notify;
18645   dlg->change_userdata = change_userdata;
18646 
18647   dlg->main_choice = PopupList (p, TRUE, ChangeParseDstDialogPopup);
18648   SetObjectExtra (dlg->main_choice, dlg, NULL);
18649   PopupItem (dlg->main_choice, "Definition Line");
18650   PopupItem (dlg->main_choice, "Biosource");
18651   PopupItem (dlg->main_choice, "Source Qualifier");
18652   PopupItem (dlg->main_choice, "Gene Field");
18653   PopupItem (dlg->main_choice, "RNA Field");
18654   PopupItem (dlg->main_choice, "CDS Comment");
18655   PopupItem (dlg->main_choice, "Protein Field");
18656   PopupItem (dlg->main_choice, "Feature Qualifier");
18657   PopupItem (dlg->main_choice, "Feature Note");
18658   PopupItem (dlg->main_choice, "Comment Descriptor");
18659   PopupItem (dlg->main_choice, "Dbxref");
18660   SetValue (dlg->main_choice, 1);
18661 
18662   g = HiddenGroup (p, 0, 0, NULL);
18663   dlg->src_grp = HiddenGroup (g, -1, 0, NULL);
18664   g2 = HiddenGroup (dlg->src_grp, 0, 0, NULL);
18665   qual_list = GetSourceQualList (FALSE);
18666   dlg->src_qual_choice = ValNodeSelectionDialog (g2, qual_list, SHORT_SELECTION_LIST,
18667                                                ValNodeStringName,
18668                                                ValNodeSimpleDataFree,
18669                                                ValNodeStringCopy,
18670                                                ValNodeStringMatch,
18671                                                "source qual",
18672                                                change_notify, change_userdata, FALSE);
18673   dlg->biosrc_list = PopupList (g2, TRUE, ChangeParseDstDialogPopup);
18674   SetObjectExtra (dlg->biosrc_list, dlg, NULL);
18675   PopupItem (dlg->biosrc_list, "Organism Name");
18676   PopupItem (dlg->biosrc_list, "Lineage");
18677   PopupItem (dlg->biosrc_list, "Division");
18678   SetValue (dlg->biosrc_list, 1);
18679 
18680   dlg->feat_or_desc = HiddenGroup (dlg->src_grp, 3, 0, NULL);
18681   RadioButton (dlg->feat_or_desc, "Descriptors and Features");
18682   RadioButton (dlg->feat_or_desc, "Descriptors Only");
18683   RadioButton (dlg->feat_or_desc, "Features Only");
18684   SetValue (dlg->feat_or_desc, 1);
18685   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->src_qual_choice, (HANDLE) dlg->feat_or_desc, NULL);
18686   Hide (dlg->src_grp);
18687 
18688   dlg->gene_field = PopupList (g, TRUE, ChangeParseDstDialogPopup);
18689   SetObjectExtra (dlg->gene_field, dlg, NULL);
18690   PopupItem (dlg->gene_field, "locus");
18691   PopupItem (dlg->gene_field, "description");
18692   PopupItem (dlg->gene_field, "comment");
18693   PopupItem (dlg->gene_field, "allele");
18694   PopupItem (dlg->gene_field, "maploc");
18695   PopupItem (dlg->gene_field, "locus_tag");
18696   PopupItem (dlg->gene_field, "synonym");
18697   PopupItem (dlg->gene_field, "old_locus_tag");
18698   SetValue (dlg->gene_field, 1);
18699   Hide (dlg->gene_field);
18700 
18701   dlg->rna_field = RnaQualDialog (g, "RNA Type", change_notify, change_userdata);
18702   Hide (dlg->rna_field);
18703 
18704   dlg->protein_field = PopupList (g, TRUE, ChangeParseDstDialogPopup);
18705   SetObjectExtra (dlg->protein_field, dlg, NULL);
18706   PopupItem (dlg->protein_field, "name");
18707   PopupItem (dlg->protein_field, "description");
18708   PopupItem (dlg->protein_field, "E.C. number");
18709   PopupItem (dlg->protein_field, "activity");
18710   PopupItem (dlg->protein_field, "comment");
18711   PopupItem (dlg->protein_field, "mat_peptide name");
18712   PopupItem (dlg->protein_field, "mat_peptide description");
18713   PopupItem (dlg->protein_field, "mat_peptide comment");
18714   SetValue (dlg->protein_field, 1);
18715   Hide (dlg->protein_field);
18716 
18717   dlg->feature_field_grp = HiddenGroup (g, 2, 0, NULL);
18718   dlg->feature_type_choice = FeatureTypeDialog (dlg->feature_field_grp, change_notify, change_userdata);
18719   dlg->feature_field_choice = LegalFeatQualChoiceDialog (dlg->feature_field_grp, change_notify, change_userdata);
18720   Hide (dlg->feature_field_grp);
18721 
18722   dlg->feature_note = FeatureTypeDialog (g, change_notify, change_userdata);
18723   Hide (dlg->feature_note);
18724 
18725   dlg->dbxref_db = DialogText (g, "", 20, ChangeParseDstDialogText);
18726   SetObjectExtra (dlg->dbxref_db, dlg, NULL);
18727   Hide (dlg->dbxref_db);
18728 
18729   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->src_grp, (HANDLE) dlg->feature_field_grp, (HANDLE) dlg->dbxref_db, NULL);
18730 
18731   return (DialoG) p;
18732 }
18733 
18734 
18735 typedef struct capchangedlg {
18736  DIALOG_MESSAGE_BLOCK
18737  GrouP  cap_change;
18738  Boolean allow_none;
18739  Nlm_ChangeNotifyProc change_notify;
18740  Pointer              change_userdata;
18741 } CapChangeDlgData, PNTR CapChangeDlgPtr;
18742 
18743 
GetCapChangeValForGroup(Int4 cap_change,Boolean allow_none)18744 static Int4 GetCapChangeValForGroup (Int4 cap_change, Boolean allow_none)
18745 {
18746   Int4 val = 0;
18747 
18748   switch (cap_change) {
18749     case Cap_change_none:
18750       val = 1;
18751       break;
18752     case Cap_change_tolower:
18753       val = 2;
18754       break;
18755     case Cap_change_toupper:
18756       val = 3;
18757       break;
18758     case Cap_change_firstcap:
18759       val = 4;
18760       break;
18761     case Cap_change_firstcaprestnochange:
18762       val = 5;
18763       break;
18764     case Cap_change_firstlower_restnochange:
18765       val = 6;
18766       break;
18767     case Cap_change_cap_word_space:
18768       val = 7;
18769       break;
18770     case Cap_change_cap_word_space_punc:
18771       val = 8;
18772       break;
18773     default:
18774       val = 1;
18775       break;
18776   }
18777   if (!allow_none) {
18778     val -= 1;
18779   }
18780   return val;
18781 }
18782 
18783 
GetCapChangeValFromGroup(Int4 cap_change,Boolean allow_none)18784 static Int4 GetCapChangeValFromGroup (Int4 cap_change, Boolean allow_none)
18785 {
18786   Int4 val = 0;
18787 
18788   if (!allow_none) {
18789     cap_change += 1;
18790   }
18791   switch (cap_change) {
18792     case 1:
18793       val = Cap_change_none;
18794       break;
18795     case 2:
18796       val = Cap_change_tolower;
18797       break;
18798     case 3:
18799       val = Cap_change_toupper;
18800       break;
18801     case 4:
18802       val = Cap_change_firstcap;
18803       break;
18804     case 5:
18805       val = Cap_change_firstcaprestnochange;
18806       break;
18807     case 6:
18808       val = Cap_change_firstlower_restnochange;
18809       break;
18810     case 7:
18811       val = Cap_change_cap_word_space;
18812       break;
18813     case 8:
18814       val = Cap_change_cap_word_space_punc;
18815       break;
18816     default:
18817       val = Cap_change_none;
18818       break;
18819   }
18820   return val;
18821 }
18822 
18823 
SetCapChangeDialogValue(DialoG d,Int4 cap_change)18824 NLM_EXTERN void SetCapChangeDialogValue (DialoG d, Int4 cap_change)
18825 {
18826   CapChangeDlgPtr dlg;
18827 
18828   dlg = (CapChangeDlgPtr) GetObjectExtra (d);
18829   if (dlg == NULL) {
18830     return;
18831   }
18832   SetValue (dlg->cap_change, GetCapChangeValForGroup(cap_change, dlg->allow_none));
18833   if (dlg->change_notify != NULL) {
18834     (dlg->change_notify) (dlg->change_userdata);
18835   }
18836 }
18837 
18838 
GetCapChangeDialogValue(DialoG d)18839 NLM_EXTERN Int2 GetCapChangeDialogValue (DialoG d)
18840 {
18841   CapChangeDlgPtr dlg;
18842   Int2 cap_change = Cap_change_none;
18843 
18844   dlg = (CapChangeDlgPtr) GetObjectExtra (d);
18845   if (dlg == NULL) return cap_change;
18846 
18847   cap_change = GetCapChangeValFromGroup (GetValue (dlg->cap_change), dlg->allow_none);
18848   return cap_change;
18849 }
18850 
18851 
ChangeCapChangeGrp(GrouP g)18852 static void ChangeCapChangeGrp (GrouP g)
18853 {
18854   CapChangeDlgPtr dlg;
18855   dlg = (CapChangeDlgPtr) GetObjectExtra (g);
18856   if (dlg == NULL) return;
18857   if (dlg->change_notify != NULL) {
18858     (dlg->change_notify)(dlg->change_userdata);
18859   }
18860 }
18861 
18862 
TestCapChangeDialog(DialoG d)18863 static ValNodePtr TestCapChangeDialog (DialoG d)
18864 {
18865   CapChangeDlgPtr dlg;
18866   ValNodePtr err_list = NULL;
18867   Int2 val;
18868 
18869   dlg = (CapChangeDlgPtr) GetObjectExtra (d);
18870   if (dlg == NULL) return NULL;
18871 
18872   val = GetValue (dlg->cap_change);
18873   if (val < 1) {
18874     ValNodeAddPointer (&err_list, 0, "cap change");
18875   }
18876   return err_list;
18877 }
18878 
18879 
18880 NLM_EXTERN DialoG
CapChangeDialogEx(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,Boolean allow_none)18881 CapChangeDialogEx
18882 (GrouP h,
18883  Nlm_ChangeNotifyProc     change_notify,
18884  Pointer                  change_userdata,
18885  Boolean                  allow_none)
18886 {
18887   CapChangeDlgPtr dlg;
18888   GrouP           p;
18889 
18890   dlg = (CapChangeDlgPtr) MemNew (sizeof (CapChangeDlgData));
18891   p = NormalGroup (h, 0, 2, "Capitalization", programFont, ChangeCapChangeGrp);
18892   SetGroupSpacing (p, 10, 10);
18893   SetObjectExtra (p, dlg, StdCleanupExtraProc);
18894 
18895   dlg->dialog = (DialoG) p;
18896   dlg->dialogmessage = NULL;
18897   dlg->testdialog = TestCapChangeDialog;
18898   dlg->change_notify = change_notify;
18899   dlg->change_userdata = change_userdata;
18900   dlg->allow_none = allow_none;
18901 
18902   dlg->cap_change = p;
18903   SetGroupSpacing (dlg->cap_change, 10, 10);
18904 
18905   if (dlg->allow_none) {
18906     RadioButton (dlg->cap_change, "No change");
18907   }
18908   RadioButton (dlg->cap_change, "To lower");
18909   RadioButton (dlg->cap_change, "To upper");
18910   RadioButton (dlg->cap_change, "First cap, rest lower");
18911   RadioButton (dlg->cap_change, "First cap, rest no change");
18912   RadioButton (dlg->cap_change, "First lower, rest no change");
18913   RadioButton (dlg->cap_change, "Cap words, start at spaces");
18914   RadioButton (dlg->cap_change, "Cap words, start at spaces or punctuation");
18915   SetValue (dlg->cap_change, 1);
18916 
18917   return (DialoG) p;
18918 }
18919 
18920 
18921 NLM_EXTERN DialoG
CapChangeDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)18922 CapChangeDialog
18923 (GrouP h,
18924  Nlm_ChangeNotifyProc     change_notify,
18925  Pointer                  change_userdata)
18926 {
18927   return CapChangeDialogEx (h, change_notify, change_userdata, TRUE);
18928 }
18929 
18930 
18931 typedef struct parseactiondlg {
18932  DIALOG_MESSAGE_BLOCK
18933  DialoG text_portion;
18934  DialoG src;
18935  DialoG dst;
18936  DialoG cap_change;
18937  DialoG transform;
18938  ButtoN remove_from_parsed;
18939  DialoG existing_text;
18940  Nlm_ChangeNotifyProc change_notify;
18941  Pointer              change_userdata;
18942  Nlm_ChangeNotifyProc redraw_notify;
18943  Pointer              redraw_userdata;
18944 } ParseActionDlgData, PNTR ParseActionDlgPtr;
18945 
18946 
ParseActionToDialog(DialoG d,Pointer data)18947 static void ParseActionToDialog (DialoG d, Pointer data)
18948 {
18949   ParseActionDlgPtr dlg;
18950   ParseActionPtr action;
18951 
18952   dlg = (ParseActionDlgPtr) GetObjectExtra (d);
18953   if (dlg == NULL) return;
18954 
18955   action = (ParseActionPtr) data;
18956   if (action == NULL) {
18957     PointerToDialog (dlg->text_portion, NULL);
18958     PointerToDialog (dlg->src, NULL);
18959     PointerToDialog (dlg->dst, NULL);
18960     PointerToDialog (dlg->cap_change, NULL);
18961     PointerToDialog (dlg->transform, NULL);
18962     SetStatus (dlg->remove_from_parsed, FALSE);
18963     SetExistingTextDialogValue(dlg->existing_text, 0);
18964   } else {
18965     PointerToDialog (dlg->text_portion, action->portion);
18966     PointerToDialog (dlg->src, action->src);
18967     PointerToDialog (dlg->dst, action->dest);
18968     SetCapChangeDialogValue (dlg->cap_change, action->capitalization);
18969     PointerToDialog (dlg->transform, action->transform);
18970     SetStatus (dlg->remove_from_parsed, action->remove_from_parsed);
18971     SetExistingTextDialogValue(dlg->existing_text, action->existing_text);
18972   }
18973 }
18974 
18975 
DialogToParseAction(DialoG d)18976 static Pointer DialogToParseAction (DialoG d)
18977 {
18978   ParseActionDlgPtr dlg;
18979   ParseActionPtr    action;
18980 
18981   dlg = (ParseActionDlgPtr) GetObjectExtra (d);
18982   if (dlg == NULL) return NULL;
18983 
18984   action = ParseActionNew();
18985   action->portion = DialogToPointer (dlg->text_portion);
18986   action->src = DialogToPointer (dlg->src);
18987   action->dest = DialogToPointer (dlg->dst);
18988   action->remove_from_parsed = GetStatus (dlg->remove_from_parsed);
18989   action->capitalization = GetCapChangeDialogValue (dlg->cap_change);
18990   action->transform = DialogToPointer (dlg->transform);
18991   action->existing_text = GetExistingTextDialogValue (dlg->existing_text);
18992   return action;
18993 }
18994 
18995 
TestParseActionDialog(DialoG d)18996 static ValNodePtr TestParseActionDialog (DialoG d)
18997 {
18998   ParseActionDlgPtr dlg;
18999   ValNodePtr err_list = NULL;
19000 
19001   dlg = (ParseActionDlgPtr) GetObjectExtra (d);
19002   if (dlg == NULL) return NULL;
19003 
19004   ValNodeLink (&err_list, TestDialog (dlg->text_portion));
19005   ValNodeLink (&err_list, TestDialog (dlg->src));
19006   ValNodeLink (&err_list, TestDialog (dlg->dst));
19007   ValNodeLink (&err_list, TestDialog (dlg->existing_text));
19008   ValNodeLink (&err_list, TestDialog (dlg->cap_change));
19009   return err_list;
19010 }
19011 
19012 
19013 static DialoG
ParseActionDialogEx(GrouP h,Boolean indexer_version,Boolean use_existing_text,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata,SeqEntryPtr sep)19014 ParseActionDialogEx
19015 (GrouP h,
19016  Boolean indexer_version,
19017  Boolean use_existing_text,
19018  Nlm_ChangeNotifyProc     change_notify,
19019  Pointer                  change_userdata,
19020  SeqEntryPtr              sep)
19021 {
19022   ParseActionDlgPtr dlg;
19023   GrouP                 p, g1, g2, g3;
19024 
19025   dlg = (ParseActionDlgPtr) MemNew (sizeof (ParseActionDlgData));
19026   p = HiddenGroup (h, -1, 0, NULL);
19027   SetGroupSpacing (p, 10, 10);
19028   SetObjectExtra (p, dlg, StdCleanupExtraProc);
19029 
19030   dlg->dialog = (DialoG) p;
19031   dlg->todialog = ParseActionToDialog;
19032   dlg->fromdialog = DialogToParseAction;
19033   dlg->dialogmessage = NULL;
19034   dlg->testdialog = TestParseActionDialog;
19035   dlg->change_notify = change_notify;
19036   dlg->change_userdata = change_userdata;
19037 
19038   g3 =HiddenGroup (p, 2, 0, NULL);
19039   StaticPrompt (g3, "Select text", 0, dialogTextHeight, systemFont, 'l');
19040   dlg->text_portion = TextPortionDialog (g3, TRUE, change_notify, change_userdata);
19041 
19042   g1 = HiddenGroup (p, 2, 0, NULL);
19043   StaticPrompt (g1, "From", 0, dialogTextHeight, systemFont, 'r');
19044   dlg->src = ParseSrcDialog (g1, change_notify, change_userdata, sep);
19045   g2 = HiddenGroup (p, 2, 0, NULL);
19046   StaticPrompt (g2, "And place in", 0, dialogTextHeight, systemFont, 'r');
19047   dlg->dst = ParseDstDialog (g2, change_notify, change_userdata);
19048   dlg->cap_change = CapChangeDialog (p, NULL, NULL);
19049 
19050   dlg->transform = TextTransformSetDialog (p, change_notify, change_userdata);
19051 
19052   dlg->remove_from_parsed = CheckBox (p, "Remove from parsed field", NULL);
19053 
19054   if (use_existing_text) {
19055     dlg->existing_text = ExistingTextDialog (p, change_notify, change_userdata);
19056   }
19057 
19058   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->cap_change,
19059                               (HANDLE) dlg->transform,
19060                               (HANDLE) dlg->remove_from_parsed,
19061                               (HANDLE) g3,
19062                               (HANDLE) g1, (HANDLE) g2,
19063                               (HANDLE) dlg->existing_text,
19064                               NULL);
19065 
19066   return (DialoG) p;
19067 }
19068 
19069 
19070 static DialoG
ParseActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)19071 ParseActionDialog
19072 (GrouP h,
19073  Boolean indexer_version,
19074  Nlm_ChangeNotifyProc     change_notify,
19075  Pointer                  change_userdata)
19076 {
19077   return ParseActionDialogEx (h, indexer_version, TRUE, change_notify, change_userdata, NULL);
19078 }
19079 
19080 
19081 typedef struct autofixactiondlg {
19082  DIALOG_MESSAGE_BLOCK
19083  PopuP  test_popup;
19084 
19085  CharPtr PNTR test_names;
19086  Int4Ptr test_types;
19087  Int4    num_tests;
19088 
19089  Nlm_ChangeNotifyProc change_notify;
19090  Pointer              change_userdata;
19091 } AutofixActionDlgData, PNTR AutofixActionDlgPtr;
19092 
19093 
CleanupAutofixActionDialog(GraphiC g,VoidPtr data)19094 static void CleanupAutofixActionDialog (GraphiC g, VoidPtr data)
19095 
19096 {
19097   AutofixActionDlgPtr dlg;
19098 
19099   dlg = (AutofixActionDlgPtr) data;
19100   if (dlg != NULL) {
19101     dlg->test_names = MemFree (dlg->test_names);
19102     dlg->test_types = MemFree (dlg->test_types);
19103   }
19104   StdCleanupExtraProc (g, data);
19105 }
19106 
19107 
AutofixActionToDialog(DialoG d,Pointer userdata)19108 static void AutofixActionToDialog (DialoG d, Pointer userdata)
19109 {
19110   AutofixActionDlgPtr dlg;
19111   AutofixActionPtr action;
19112   DiscrepancyType test_type;
19113   Boolean found = FALSE;
19114   Int4 j;
19115 
19116   dlg = (AutofixActionDlgPtr) GetObjectExtra (d);
19117   if (dlg == NULL) return;
19118 
19119   action = (AutofixActionPtr)userdata;
19120 
19121   if (action == NULL || (test_type = GetDiscrepancyTypeFromSettingName (action->test_name)) == MAX_DISC_TYPE) {
19122     SetValue (dlg->test_popup, 0);
19123   } else {
19124     for (j = 0; j < dlg->num_tests && !found; j++) {
19125       if (dlg->test_types[j] == test_type) {
19126         SetValue (dlg->test_popup, j + 1);
19127         found = TRUE;
19128       }
19129     }
19130     if (!found) {
19131       SetValue (dlg->test_popup, 0);
19132     }
19133   }
19134 }
19135 
19136 
DialogToAutofixAction(DialoG d)19137 static Pointer DialogToAutofixAction (DialoG d)
19138 {
19139   AutofixActionDlgPtr dlg;
19140   AutofixActionPtr action;
19141   Int2            j;
19142 
19143   dlg = (AutofixActionDlgPtr) GetObjectExtra (d);
19144   if (dlg == NULL) return NULL;
19145 
19146   j = GetValue (dlg->test_popup);
19147   if (j < 1 || j > dlg->num_tests) {
19148     return NULL;
19149   }
19150   action = AutofixActionNew ();
19151   action->test_name = StringSave (dlg->test_names[j - 1]);
19152   return action;
19153 }
19154 
19155 
TestAutofixActionDialog(DialoG d)19156 static ValNodePtr TestAutofixActionDialog(DialoG d)
19157 {
19158   AutofixActionDlgPtr dlg;
19159   ValNodePtr err_list = NULL;
19160 
19161   dlg = (AutofixActionDlgPtr) GetObjectExtra (d);
19162   if (dlg == NULL) return NULL;
19163 
19164   if (GetValue (dlg->test_popup) < 1) {
19165     ValNodeAddPointer (&err_list, 0, "No test selected");
19166   }
19167   return err_list;
19168 }
19169 
19170 
ChangeAutofixActionPopup(PopuP p)19171 static void ChangeAutofixActionPopup (PopuP p)
19172 {
19173   AutofixActionDlgPtr dlg;
19174 
19175   dlg = (AutofixActionDlgPtr) GetObjectExtra (p);
19176   if (dlg == NULL) return;
19177 
19178   if (dlg->change_notify != NULL) {
19179     (dlg->change_notify) (dlg->change_userdata);
19180   }
19181 }
19182 
19183 
19184 static DialoG
CreateAutofixActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)19185 CreateAutofixActionDialog
19186 (GrouP h,
19187  Boolean indexer_version,
19188  Nlm_ChangeNotifyProc     change_notify,
19189  Pointer                  change_userdata)
19190 {
19191   AutofixActionDlgPtr dlg;
19192   GrouP               p;
19193   Int4                i, j;
19194 
19195   dlg = (AutofixActionDlgPtr) MemNew (sizeof (AutofixActionDlgData));
19196   p = HiddenGroup (h, 2, 0, NULL);
19197   SetGroupSpacing (p, 10, 10);
19198   SetObjectExtra (p, dlg, CleanupAutofixActionDialog);
19199 
19200   dlg->dialog = (DialoG) p;
19201   dlg->todialog = AutofixActionToDialog;
19202   dlg->fromdialog = DialogToAutofixAction;
19203   dlg->dialogmessage = NULL;
19204   dlg->testdialog = TestAutofixActionDialog;
19205   dlg->change_notify = change_notify;
19206   dlg->change_userdata = change_userdata;
19207 
19208   StaticPrompt (p, "Perform Autofix for Discrepancy Test:", 0, dialogTextHeight, systemFont, 'l');
19209   dlg->test_popup = PopupList (p, TRUE, ChangeAutofixActionPopup);
19210   SetObjectExtra (dlg->test_popup, dlg, NULL);
19211 
19212   dlg->num_tests = 0;
19213   for (i = 0; i < MAX_DISC_TYPE; i++) {
19214     if (DiscrepancyTestHasAutofix(i)) {
19215       dlg->num_tests++;
19216     }
19217   }
19218 
19219   dlg->test_names = (CharPtr PNTR) MemNew (sizeof (CharPtr) * dlg->num_tests);
19220   dlg->test_types = (Int4Ptr) MemNew (sizeof (Int4) * dlg->num_tests);
19221   j = 0;
19222   for (i = 0; i < MAX_DISC_TYPE; i++) {
19223     if (DiscrepancyTestHasAutofix(i)) {
19224       dlg->test_names[j] = GetDiscrepancyTestSettingName(i);
19225       dlg->test_types[j] = i;
19226       PopupItem (dlg->test_popup, dlg->test_names[j]);
19227       j++;
19228     }
19229   }
19230   SetValue (dlg->test_popup, 0);
19231 
19232   return (DialoG) p;
19233 }
19234 
19235 
19236 typedef struct fixsetsactiondlg {
19237  DIALOG_MESSAGE_BLOCK
19238  PopuP  fix_popup;
19239 
19240  Nlm_ChangeNotifyProc change_notify;
19241  Pointer              change_userdata;
19242 } FixSetsActionDlgData, PNTR FixSetsActionDlgPtr;
19243 
19244 
FixSetsActionToDialog(DialoG d,Pointer userdata)19245 static void FixSetsActionToDialog (DialoG d, Pointer userdata)
19246 {
19247   FixSetsActionDlgPtr dlg;
19248   FixSetsActionPtr action;
19249 
19250   dlg = (FixSetsActionDlgPtr) GetObjectExtra (d);
19251   if (dlg == NULL) return;
19252 
19253   action = (FixSetsActionPtr)userdata;
19254 
19255   if (action == NULL) {
19256     SetValue (dlg->fix_popup, 0);
19257   } else {
19258     SetValue (dlg->fix_popup, action->choice);
19259   }
19260 }
19261 
19262 
DialogToFixSetsAction(DialoG d)19263 static Pointer DialogToFixSetsAction (DialoG d)
19264 {
19265   FixSetsActionDlgPtr dlg;
19266   FixSetsActionPtr action = NULL;
19267   Int2            j;
19268 
19269   dlg = (FixSetsActionDlgPtr) GetObjectExtra (d);
19270   if (dlg == NULL) return NULL;
19271 
19272   j = GetValue (dlg->fix_popup);
19273   if (j > 0) {
19274     action = ValNodeNew (NULL);
19275     action->choice = j;
19276   }
19277   return action;
19278 }
19279 
19280 
TestFixSetsActionDialog(DialoG d)19281 static ValNodePtr TestFixSetsActionDialog(DialoG d)
19282 {
19283   FixSetsActionDlgPtr dlg;
19284   ValNodePtr err_list = NULL;
19285 
19286   dlg = (FixSetsActionDlgPtr) GetObjectExtra (d);
19287   if (dlg == NULL) return NULL;
19288 
19289   if (GetValue (dlg->fix_popup) < 1) {
19290     ValNodeAddPointer (&err_list, 0, "No action selected");
19291   }
19292   return err_list;
19293 }
19294 
19295 
ChangeFixSetsActionPopup(PopuP p)19296 static void ChangeFixSetsActionPopup (PopuP p)
19297 {
19298   FixSetsActionDlgPtr dlg;
19299 
19300   dlg = (FixSetsActionDlgPtr) GetObjectExtra (p);
19301   if (dlg == NULL) return;
19302 
19303   if (dlg->change_notify != NULL) {
19304     (dlg->change_notify) (dlg->change_userdata);
19305   }
19306 }
19307 
19308 
19309 static DialoG
CreateFixSetsActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)19310 CreateFixSetsActionDialog
19311 (GrouP h,
19312  Boolean indexer_version,
19313  Nlm_ChangeNotifyProc     change_notify,
19314  Pointer                  change_userdata)
19315 {
19316   FixSetsActionDlgPtr dlg;
19317   GrouP               p;
19318   FixSetsActionPtr    action;
19319   CharPtr             summ;
19320 
19321   dlg = (FixSetsActionDlgPtr) MemNew (sizeof (FixSetsActionDlgData));
19322   p = HiddenGroup (h, -1, 0, NULL);
19323   SetGroupSpacing (p, 10, 10);
19324   SetObjectExtra (p, dlg, StdCleanupExtraProc);
19325 
19326   dlg->dialog = (DialoG) p;
19327   dlg->todialog = FixSetsActionToDialog;
19328   dlg->fromdialog = DialogToFixSetsAction;
19329   dlg->dialogmessage = NULL;
19330   dlg->testdialog = TestFixSetsActionDialog;
19331   dlg->change_notify = change_notify;
19332   dlg->change_userdata = change_userdata;
19333 
19334   dlg->fix_popup = PopupList (p, TRUE, ChangeFixSetsActionPopup);
19335   SetObjectExtra (dlg->fix_popup, dlg, NULL);
19336   action = ValNodeNew (NULL);
19337   for (action->choice = FixSetsAction_remove_single_item_set;
19338        action->choice <= FixSetsAction_fix_pop_to_phy;
19339        action->choice++) {
19340     summ = SummarizeFixSetsAction(action);
19341     PopupItem (dlg->fix_popup, summ);
19342     summ = MemFree (summ);
19343   }
19344 
19345   return (DialoG) p;
19346 }
19347 
19348 typedef struct adjustfeaturesforgapsdlg
19349 {
19350   DIALOG_MESSAGE_BLOCK
19351 
19352   ButtoN adjust_for_unknown_length_gaps;
19353   ButtoN adjust_for_known_length_gaps;
19354   ButtoN trim_ends_in_gaps;
19355   ButtoN split_for_internal_gaps;
19356   ButtoN even_when_gaps_are_in_introns;
19357 
19358   PopuP make_truncated_ends_partial;
19359 
19360   Nlm_ChangeNotifyProc change_notify;
19361   Pointer change_userdata;
19362 } AdjustFeaturesForGapsDlgData, PNTR AdjustFeaturesForGapsDlgPtr;
19363 
19364 
AdjustFeaturesForGapsToDialog(DialoG d,Pointer data)19365 static void AdjustFeaturesForGapsToDialog(DialoG d, Pointer data)
19366 {
19367   AdjustFeaturesForGapsDlgPtr dlg;
19368   AdjustFeaturesForGapsActionPtr action;
19369 
19370   dlg = (AdjustFeaturesForGapsDlgPtr) GetObjectExtra (d);
19371   if (dlg == NULL) {
19372     return;
19373   }
19374   action = (AdjustFeaturesForGapsActionPtr) data;
19375   if (action == NULL) {
19376     SetStatus (dlg->adjust_for_unknown_length_gaps, TRUE);
19377     SetStatus (dlg->adjust_for_known_length_gaps, TRUE);
19378     SetStatus (dlg->trim_ends_in_gaps, TRUE);
19379     SetStatus (dlg->split_for_internal_gaps, TRUE);
19380     SetStatus (dlg->even_when_gaps_are_in_introns, TRUE);
19381     SetValue (dlg->make_truncated_ends_partial, 1);
19382   } else {
19383     SetStatus (dlg->adjust_for_unknown_length_gaps, action->adjust_for_unknown_length_gaps);
19384     SetStatus (dlg->adjust_for_known_length_gaps, action->adjust_for_known_length_gaps);
19385     SetStatus (dlg->trim_ends_in_gaps, action->trim_ends_in_gaps);
19386     SetStatus (dlg->split_for_internal_gaps, action->split_for_internal_gaps);
19387     SetStatus (dlg->even_when_gaps_are_in_introns, action->even_when_gaps_are_in_introns);
19388     SetValue (dlg->make_truncated_ends_partial, action->make_truncated_ends_partial);
19389   }
19390 }
19391 
19392 
AdjustFeaturesForGapsFromDialog(DialoG d)19393 static Pointer AdjustFeaturesForGapsFromDialog(DialoG d)
19394 {
19395   AdjustFeaturesForGapsDlgPtr dlg;
19396   AdjustFeaturesForGapsActionPtr action;
19397 
19398   dlg = (AdjustFeaturesForGapsDlgPtr) GetObjectExtra (d);
19399   if (dlg == NULL) {
19400     return NULL;
19401   }
19402   action = (AdjustFeaturesForGapsActionPtr) MemNew (sizeof (AdjustFeaturesForGapsAction));
19403   action->adjust_for_unknown_length_gaps = GetStatus (dlg->adjust_for_unknown_length_gaps);
19404   action->adjust_for_known_length_gaps = GetStatus (dlg->adjust_for_known_length_gaps);
19405   action->trim_ends_in_gaps = GetStatus (dlg->trim_ends_in_gaps);
19406   action->split_for_internal_gaps = GetStatus (dlg->split_for_internal_gaps);
19407   action->even_when_gaps_are_in_introns = GetStatus (dlg->even_when_gaps_are_in_introns);
19408   action->make_truncated_ends_partial = GetValue (dlg->make_truncated_ends_partial);
19409   return (Pointer) action;
19410 }
19411 
AdjustFeaturesForGapsDialogBtn(ButtoN b)19412 static void AdjustFeaturesForGapsDialogBtn (ButtoN b)
19413 {
19414   AdjustFeaturesForGapsDlgPtr dlg;
19415 
19416   dlg = (AdjustFeaturesForGapsDlgPtr) GetObjectExtra (b);
19417   if (dlg != NULL && dlg->change_notify != NULL) {
19418     (dlg->change_notify) (dlg->change_userdata);
19419   }
19420 }
19421 
AdjustFeaturesForGapsDialogPopup(PopuP p)19422 static void AdjustFeaturesForGapsDialogPopup (PopuP p)
19423 {
19424   AdjustFeaturesForGapsDlgPtr dlg;
19425 
19426   dlg = (AdjustFeaturesForGapsDlgPtr) GetObjectExtra (p);
19427   if (dlg != NULL && dlg->change_notify != NULL) {
19428     (dlg->change_notify) (dlg->change_userdata);
19429   }
19430 }
19431 
19432 
19433 
CreateAdjustFeaturesForGapsActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)19434 static DialoG CreateAdjustFeaturesForGapsActionDialog (GrouP h, Boolean indexer_version, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
19435 {
19436   AdjustFeaturesForGapsDlgPtr dlg;
19437   GrouP              p;
19438 
19439   dlg = (AdjustFeaturesForGapsDlgPtr) MemNew (sizeof (AdjustFeaturesForGapsDlgData));
19440   if (dlg == NULL)
19441   {
19442     return NULL;
19443   }
19444 
19445   p = HiddenGroup (h, 0, 3, NULL);
19446   SetObjectExtra (p, dlg, StdCleanupExtraProc);
19447   SetGroupSpacing (p, 10, 10);
19448 
19449   dlg->dialog = (DialoG) p;
19450   dlg->todialog = AdjustFeaturesForGapsToDialog;
19451   dlg->fromdialog = AdjustFeaturesForGapsFromDialog;
19452   dlg->change_notify = change_notify;
19453   dlg->change_userdata = change_userdata;
19454 
19455   dlg->adjust_for_unknown_length_gaps = CheckBox (p, "Unknown length gaps", AdjustFeaturesForGapsDialogBtn);
19456   SetObjectExtra (dlg->adjust_for_unknown_length_gaps, dlg, NULL);
19457   dlg->adjust_for_known_length_gaps = CheckBox (p, "Known length gaps", AdjustFeaturesForGapsDialogBtn);
19458   SetObjectExtra (dlg->adjust_for_known_length_gaps, dlg, NULL);
19459 
19460   dlg->make_truncated_ends_partial = PopupList (p, TRUE, AdjustFeaturesForGapsDialogPopup);
19461   SetObjectExtra (dlg->make_truncated_ends_partial, dlg, NULL);
19462   PopupItem (dlg->make_truncated_ends_partial, "Always");
19463   PopupItem (dlg->make_truncated_ends_partial, "Unless pseudo");
19464   PopupItem (dlg->make_truncated_ends_partial, "Never");
19465   SetValue (dlg->make_truncated_ends_partial, 1);
19466 
19467   dlg->trim_ends_in_gaps = CheckBox (p, "Trim ends in gaps", AdjustFeaturesForGapsDialogBtn);
19468   SetObjectExtra (dlg->trim_ends_in_gaps, dlg, NULL);
19469   dlg->split_for_internal_gaps = CheckBox (p, "Split for internal gaps", AdjustFeaturesForGapsDialogBtn);
19470   SetObjectExtra (dlg->split_for_internal_gaps, dlg, NULL);
19471   dlg->even_when_gaps_are_in_introns = CheckBox (p, "(Even when gaps are in introns)", AdjustFeaturesForGapsDialogBtn);
19472   SetObjectExtra (dlg->even_when_gaps_are_in_introns, dlg, NULL);
19473 
19474   return (DialoG) p;
19475 }
19476 
19477 
19478 static DialoG
SimpleEditAECRActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)19479 SimpleEditAECRActionDialog
19480 (GrouP h,
19481  Boolean indexer_version,
19482  Nlm_ChangeNotifyProc     change_notify,
19483  Pointer                  change_userdata)
19484 {
19485   return EditAECRActionDialog (h, indexer_version, TRUE, change_notify, change_userdata, change_notify, change_userdata);
19486 }
19487 
19488 
SimpleApplyFeatureActionDialog(GrouP h,Boolean indexer_version,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)19489 static DialoG SimpleApplyFeatureActionDialog
19490 (GrouP h,
19491  Boolean indexer_version,
19492  Nlm_ChangeNotifyProc     change_notify,
19493  Pointer                  change_userdata)
19494 {
19495   return ApplyFeatureActionDialog (h, NULL, indexer_version, change_notify, change_userdata, change_notify, change_userdata);
19496 }
19497 
19498 
19499 typedef DialoG (*MacroActionChoiceDialog) PROTO((GrouP h, Boolean indexer_version, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata));
19500 
19501 typedef enum {
19502   eMacroCategoryNone = 0,
19503   eMacroCategoryDescriptorActions,
19504   eMacroCategoryFeatureActions,
19505   eMacroCategorySpecialProjects,
19506   eMacroCategoryPublicationActions,
19507   eMacroCategorySequenceActions,
19508   eMacroCategorySetActions,
19509   eMacroCategorySourceActions
19510 } EMacroCategory;
19511 
19512 
19513 static CharPtr s_MacroCategoryList[] = {
19514   NULL,
19515   "Descriptor Actions",
19516   "Feature Actions",
19517   "Special Projects",
19518   "Publication Actions",
19519   "Sequence Actions",
19520   "Set Actions",
19521   "Source Actions"
19522 };
19523 
19524 #define NUM_MacroCategory sizeof (s_MacroCategoryList) / sizeof (CharPtr)
19525 
19526 
19527 typedef struct macropopup {
19528   CharPtr popup_label;
19529   EMacroCategory category;
19530   Int4 action_choice;
19531   MacroActionChoiceDialog dialog_func;
19532 } MacroPopupData, PNTR MacroPopupPtr;
19533 
19534 typedef enum {
19535   eMacroPopup_AddFeature = 1,
19536   eMacroPopup_ApplyQualifier,
19537   eMacroPopup_EditQualifier,
19538   eMacroPopup_ConvertQualifier,
19539   eMacroPopup_CopyQualifier,
19540   eMacroPopup_SwapQualifier,
19541   eMacroPopup_ParseQualifier,
19542   eMacroPopup_RemoveQualifier,
19543   eMacroPopup_RemoveTextOutsideStringInQualifier,
19544   eMacroPopup_ParseText,
19545   eMacroPopup_RemoveFeature,
19546   eMacroPopup_EditFeatureLocation,
19547   eMacroPopup_ConvertFeature,
19548   eMacroPopup_RemoveDescriptor,
19549   eMacroPopup_Autodef,
19550   eMacroPopup_EditMolInfoFields,
19551   eMacroPopup_FixSpell,
19552   eMacroPopup_RemoveXrefs,
19553   eMacroPopup_ApplyTable,
19554   eMacroPopup_AddDescriptorList,
19555   eMacroPopup_AutoApplyStructuredCommentPrefixes,
19556   eMacroPopup_InstantiateProteinTitles,
19557   eMacroPopup_PropagateAssemblyData,
19558   eMacroPopup_RemoveDuplicateStructuredComments,
19559   eMacroPopup_ResortStructuredCommentFields,
19560   eMacroPopup_AdjustCodingRegionsForConsensusSpliceSites,
19561   eMacroPopup_FormatProteinName,
19562   eMacroPopup_MakeGeneXrefs,
19563   eMacroPopup_RemoveDuplicateFeatures,
19564   eMacroPopup_RemoveInvalidECNumbers,
19565   eMacroPopup_RemoveTrailingStopFromCodingRegions,
19566   eMacroPopup_SetTransSplicingException,
19567   eMacroPopup_SynchronizeCodingRegionPartials,
19568   eMacroPopup_SortProteinNames,
19569   eMacroPopup_UpdateReplacedEcnumbers,
19570   eMacroPopup_RetranslateCodingRegions,
19571   eMacroPopup_CreateTSAIds,
19572   eMacroPopup_MakeBarcodeXrefs,
19573   eMacroPopup_PerformAutofix,
19574   eMacroPopup_FixAuthorNames,
19575   eMacroPopup_FixCapsInAuthor,
19576   eMacroPopup_FixPublicationCapitalization,
19577   eMacroPopup_FixUSAandStateAbbreviationsInPublications,
19578   eMacroPopup_LookupPubs,
19579   eMacroPopup_TrimTerminalNs,
19580   eMacroPopup_RemoveSequences,
19581   eMacroPopup_UpdateSequences,
19582   eMacroPopup_FixSets,
19583   eMacroPopup_RemoveDuplicateNestedSets,
19584   eMacroPopup_RemoveSegGaps,
19585   eMacroPopup_LookupTaxonomy,
19586   eMacroPopup_FormatLatLon,
19587   eMacroPopup_FormatCollectionDate,
19588   eMacroPopup_FixSourceCountryQualCapitalization,
19589   eMacroPopup_FixSourceQualCapitalization,
19590   eMacroPopup_FormatPrimers,
19591   eMacroPopup_TrimJunkInPrimerSeqs,
19592   eMacroPopup_RemoveLineageSourceNotes,
19593   eMacroPopup_FixCapsInCommonMusMusculusStrains,
19594   eMacroPopup_PropagateOldName
19595 } EMacroPopup;
19596 
19597 
19598 static MacroPopupData s_MacroPopupList[] = {
19599   {"Apply Feature", eMacroCategoryNone, MacroActionChoice_add_feature, SimpleApplyFeatureActionDialog},
19600   {"Apply Qualifier", eMacroCategoryNone, MacroActionChoice_aecr, SimpleEditAECRActionDialog},
19601   {"Edit Qualifier", eMacroCategoryNone,  MacroActionChoice_aecr, SimpleEditAECRActionDialog},
19602   {"Convert Qualifier", eMacroCategoryNone, MacroActionChoice_aecr, SimpleEditAECRActionDialog},
19603   {"Copy Qualifier", eMacroCategoryNone, MacroActionChoice_aecr, SimpleEditAECRActionDialog},
19604   {"Swap Qualifier", eMacroCategoryNone, MacroActionChoice_aecr, SimpleEditAECRActionDialog},
19605   {"Parse Qualifier", eMacroCategoryNone, MacroActionChoice_aecr, SimpleEditAECRActionDialog},
19606   {"Remove Qualifier", eMacroCategoryNone, MacroActionChoice_aecr, SimpleEditAECRActionDialog},
19607   {"Remove Text Outside String in Qualifier", eMacroCategoryNone, MacroActionChoice_aecr, SimpleEditAECRActionDialog},
19608   {"Parse Text", eMacroCategoryNone, MacroActionChoice_parse, ParseActionDialog },
19609   {"Remove Feature", eMacroCategoryNone, MacroActionChoice_remove_feature, RemoveFeatureActionDialog },
19610   {"Edit Feature Location", eMacroCategoryNone, MacroActionChoice_edit_location, EditFeatureLocationActionDialog },
19611   {"Convert Feature", eMacroCategoryNone, MacroActionChoice_convert_feature, ConvertFeatureActionDialog },
19612   {"Remove Descriptor", eMacroCategoryNone, MacroActionChoice_remove_descriptor, RemoveDescriptorActionDialog },
19613   {"Autodef", eMacroCategoryNone, MacroActionChoice_autodef, AutodefActionDialog },
19614   {"Edit MolInfo Fields", eMacroCategoryNone, MacroActionChoice_apply_molinfo_block, MolInfoBlockDialog },
19615   {"Fix spelling", eMacroCategoryNone, MacroActionChoice_fix_spell, NULL } ,
19616   {"Remove Xrefs", eMacroCategoryNone, MacroActionChoice_remove_xrefs, RemoveXrefsDialog } ,
19617   {"Apply Table", eMacroCategoryNone, MacroActionChoice_apply_table, ApplyTableActionDialog } ,
19618   {"Add Descriptors From File", eMacroCategoryDescriptorActions, MacroActionChoice_add_file_descriptors, AddFileDescriptorsActionDialog } ,
19619   {"Autoapply structured comment prefixes", eMacroCategoryDescriptorActions, MacroActionChoice_autoapply_structured_comments, NULL } ,
19620   {"Instantiate Protein Titles", eMacroCategoryDescriptorActions, MacroActionChoice_instantiate_protein_titles, NULL } ,
19621   {"Propagate Assembly-Data", eMacroCategoryDescriptorActions, MacroActionChoice_propagate_sequence_technology, NULL } ,
19622   {"Remove duplicate structured comments", eMacroCategoryDescriptorActions, MacroActionChoice_remove_duplicate_structured_comments, NULL } ,
19623   {"Reorder structured comment fields", eMacroCategoryDescriptorActions, MacroActionChoice_reorder_structured_comments, NULL } ,
19624   {"Adjust coding regions for consensus splice sites", eMacroCategoryFeatureActions, MacroActionChoice_adjust_for_consensus_splice, NULL},
19625   {"Fix protein name format", eMacroCategoryFeatureActions, MacroActionChoice_fix_format, FormatProteinNameDialog } ,
19626   {"Make gene xrefs from features", eMacroCategoryFeatureActions, MacroActionChoice_make_gene_xrefs, MakeGeneXrefDialog } ,
19627   {"Remove Duplicate Features", eMacroCategoryFeatureActions, MacroActionChoice_remove_duplicate_features, RemoveDuplicateFeatActionDialog } ,
19628   {"Remove invalid EC_numbers", eMacroCategoryFeatureActions, MacroActionChoice_remove_invalid_ecnumbers, NULL } ,
19629   {"Remove trailing * from Coding Regions", eMacroCategoryFeatureActions, MacroActionChoice_trim_stop_from_complete_cds, NULL},
19630   {"Set trans-splicing exception in genes", eMacroCategoryFeatureActions, MacroActionChoice_add_trans_splicing, NULL } ,
19631   {"Synchronize Coding Region Partials", eMacroCategoryFeatureActions, MacroActionChoice_synchronize_cds_partials, NULL},
19632   {"Sort Protein Names", eMacroCategoryFeatureActions, MacroActionChoice_sort_fields, SortFieldsDialog },
19633   {"Update Replaced EC_numbers", eMacroCategoryFeatureActions, MacroActionChoice_update_replaced_ecnumbers, UpdateReplacedECNumbersDialog } ,
19634   {"Retranslate Coding Regions", eMacroCategoryFeatureActions, MacroActionChoice_retranslate_cds, RetranslateCdsActionDialog },
19635   {"Create TSA IDs", eMacroCategorySpecialProjects, MacroActionChoice_create_tsa_ids, CreateTSAIdsActionDialog } ,
19636   {"Make Barcode Xrefs", eMacroCategorySpecialProjects, MacroActionChoice_make_bold_xrefs, NULL } ,
19637   {"Perform Discrepancy Report Autofix", eMacroCategorySpecialProjects, MacroActionChoice_perform_autofix, CreateAutofixActionDialog } ,
19638   {"Fix Author Names", eMacroCategoryPublicationActions, MacroActionChoice_fix_author, AuthorFixActionDialog } ,
19639   {"Fix capitalization in author", eMacroCategoryPublicationActions, MacroActionChoice_fix_caps, AuthorCapsActionDialog } ,
19640   {"Fix publication capitalization", eMacroCategoryPublicationActions, MacroActionChoice_fix_pub_caps, FixPubCapsDialog },
19641   {"Fix USA and state abbreviations in publications", eMacroCategoryPublicationActions, MacroActionChoice_fix_usa_and_states, NULL},
19642   {"Perform Pub Lookup", eMacroCategoryPublicationActions, MacroActionChoice_lookup_pubs, NULL } ,
19643   {"Trim Terminal Ns", eMacroCategorySequenceActions, MacroActionChoice_trim_terminal_ns, NULL } ,
19644   {"Remove Sequences", eMacroCategorySequenceActions, MacroActionChoice_remove_sequences, RemoveSequencesActionDialog } ,
19645   {"Update Sequences", eMacroCategorySequenceActions, MacroActionChoice_update_sequences, UpdateSequencesActionDialog } ,
19646   {"Fix Sets", eMacroCategorySetActions, MacroActionChoice_fix_sets, CreateFixSetsActionDialog } ,
19647   {"Remove Duplicate Nested Sets", eMacroCategorySetActions, MacroActionChoice_removesets, NULL},
19648   {"Remove Seg-gaps", eMacroCategorySetActions, MacroActionChoice_remove_seg_gaps, NULL},
19649   {"Perform Taxonomy Lookup and correct genetic codes", eMacroCategorySourceActions, MacroActionChoice_lookup_taxonomy, NULL } ,
19650   {"Fix lat-lon format", eMacroCategorySourceActions, MacroActionChoice_fix_format, FormatLatLonDialog } ,
19651   {"Fix collection-date format", eMacroCategorySourceActions, MacroActionChoice_fix_format, FormatCollectionDateDialog } ,
19652   {"Fix source country qual capitalization", eMacroCategorySourceActions, MacroActionChoice_fix_caps, FixCapsSourceCountryDialog },
19653   {"Fix source qual capitalization", eMacroCategorySourceActions, MacroActionChoice_fix_caps, FixSrcQualCapsActionDialog },
19654   {"Fix primer format", eMacroCategorySourceActions, MacroActionChoice_fix_format, FormatPrimerDialog } ,
19655   {"Trim Junk in Primer Seqs", eMacroCategorySourceActions, MacroActionChoice_trim_junk_from_primer_seq, NULL},
19656   {"Remove Lineage Source Notes", eMacroCategorySourceActions, MacroActionChoice_remove_lineage_notes, NULL } ,
19657   {"Fix capitalization in common Mus musculus strains", eMacroCategorySourceActions, MacroActionChoice_fix_caps, MusMusculusActionDialog } ,
19658   {"Propagate Missing Old-name Qualifiers", eMacroCategorySourceActions, MacroActionChoice_propagate_missing_old_name, NULL } ,
19659   {"Replace selenocysteine stops", eMacroCategoryFeatureActions, MacroActionChoice_add_selenocysteine_except, NULL } ,
19660   {"Join short tRNAs", eMacroCategoryFeatureActions, MacroActionChoice_join_short_trnas, NULL } ,
19661   {"Adjust Features for Gaps", eMacroCategoryFeatureActions, MacroActionChoice_adjust_features_for_gaps, CreateAdjustFeaturesForGapsActionDialog } ,
19662 };
19663 
19664 #define NUM_MacroPopup sizeof (s_MacroPopupList) / sizeof (MacroPopupData)
19665 
19666 
GetNumInCategory(Int2 category)19667 static Int2 GetNumInCategory (Int2 category)
19668 {
19669   Int2 num_in_category = 0;
19670   Int4 j;
19671 
19672   for (j = 0; j < NUM_MacroPopup; j++) {
19673     if (s_MacroPopupList[j].category == category) {
19674       num_in_category++;
19675     }
19676   }
19677   return num_in_category;
19678 }
19679 
19680 
GetPopupForNthInCategory(Int2 cat,Int2 nth)19681 static Int2 GetPopupForNthInCategory (Int2 cat, Int2 nth)
19682 {
19683   Int2 num_in_category = 0;
19684   Int4 j;
19685 
19686   for (j = 0; j < NUM_MacroPopup; j++) {
19687     if (s_MacroPopupList[j].category == cat) {
19688       num_in_category++;
19689       if (num_in_category == nth) {
19690         return j + 1;
19691       }
19692     }
19693   }
19694   return 0;
19695 }
19696 
19697 
GetActionChoiceForCategoryPopupChoice(Int2 category,Int2 popup_choice)19698 static Uint1 GetActionChoiceForCategoryPopupChoice (Int2 category, Int2 popup_choice)
19699 {
19700   Int2 num_in_category = 0;
19701   Int4 j;
19702 
19703   for (j = 0; j < NUM_MacroPopup; j++) {
19704     if (s_MacroPopupList[j].category == category) {
19705       num_in_category++;
19706       if (num_in_category == popup_choice) {
19707         return s_MacroPopupList[j].action_choice;
19708       }
19709     }
19710   }
19711   return -1;
19712 }
19713 
19714 
GetCategoryForActionChoice(Uint1 action_choice)19715 static Int2 GetCategoryForActionChoice (Uint1 action_choice)
19716 {
19717   Int2 j;
19718 
19719   for (j = 0; j < NUM_MacroPopup; j++) {
19720     if (s_MacroPopupList[j].action_choice == action_choice) {
19721       return s_MacroPopupList[j].category;
19722     }
19723   }
19724   return eMacroCategoryNone;
19725 }
19726 
19727 
GetPopupForActionChoice(Uint1 action_choice)19728 static Int2 GetPopupForActionChoice (Uint1 action_choice)
19729 {
19730   Int2 j;
19731 
19732   for (j = 0; j < NUM_MacroPopup; j++) {
19733     if (s_MacroPopupList[j].action_choice == action_choice) {
19734       return j + 1;
19735     }
19736   }
19737   return eMacroCategoryNone;
19738 }
19739 
19740 
GetCategoryForPopupChoice(Int2 popup_choice)19741 static Int2 GetCategoryForPopupChoice (Int2 popup_choice)
19742 {
19743   if (popup_choice > 0 && popup_choice <= NUM_MacroPopup) {
19744     return s_MacroPopupList[popup_choice - 1].category;
19745   } else {
19746     return eMacroCategoryNone;
19747   }
19748 }
19749 
19750 
GetActionInCategoryPositionForPopupChoice(Int2 popup_choice,Int2 category)19751 static Int2 GetActionInCategoryPositionForPopupChoice (Int2 popup_choice, Int2 category)
19752 {
19753   Int2 j;
19754   Int2 num_in_category = 0;
19755 
19756   for (j = 0; j < NUM_MacroPopup; j++) {
19757     if (s_MacroPopupList[j].category == category) {
19758       num_in_category++;
19759       if (j == popup_choice - 1) {
19760         return num_in_category;
19761       }
19762     }
19763   }
19764   return 1;
19765 }
19766 
19767 
GetPopupChoiceForAction(ValNodePtr action)19768 static Int2 GetPopupChoiceForAction (ValNodePtr action)
19769 {
19770   Int2 popup = eMacroPopup_AddFeature;
19771   AECRActionPtr aecr;
19772   FixCapsActionPtr fc;
19773   FixFormatActionPtr fa;
19774 
19775   if (action == NULL) {
19776     return eMacroPopup_AddFeature;
19777   }
19778 
19779   /* handle special cases */
19780   switch (action->choice) {
19781     case MacroActionChoice_aecr:
19782       popup = eMacroPopup_ApplyQualifier;
19783       aecr = (AECRActionPtr) action->data.ptrvalue;
19784       if (aecr != NULL && aecr->action != NULL) {
19785         switch (aecr->action->choice) {
19786           case ActionChoice_apply:
19787             popup = eMacroPopup_ApplyQualifier;
19788             break;
19789           case ActionChoice_edit:
19790             popup = eMacroPopup_EditQualifier;
19791             break;
19792           case ActionChoice_convert:
19793             popup = eMacroPopup_ConvertQualifier;
19794             break;
19795           case ActionChoice_copy:
19796             popup = eMacroPopup_CopyQualifier;
19797             break;
19798           case ActionChoice_swap:
19799             popup = eMacroPopup_SwapQualifier;
19800             break;
19801           case ActionChoice_parse:
19802             popup = eMacroPopup_ParseQualifier;
19803             break;
19804           case ActionChoice_remove:
19805             popup = eMacroPopup_RemoveQualifier;
19806             break;
19807           case ActionChoice_remove_outside:
19808             popup = eMacroPopup_RemoveTextOutsideStringInQualifier;
19809             break;
19810           default:
19811             popup = eMacroPopup_ApplyQualifier;
19812             break;
19813         }
19814       }
19815       break;
19816     case MacroActionChoice_fix_caps:
19817       fc = (FixCapsActionPtr) action->data.ptrvalue;
19818       if (fc == NULL) {
19819         popup = eMacroPopup_FixSourceCountryQualCapitalization;
19820       } else {
19821         switch (fc->choice) {
19822           case FixCapsAction_pub:
19823             popup = eMacroPopup_FixPublicationCapitalization;
19824             break;
19825           case FixCapsAction_src_country:
19826             popup = eMacroPopup_FixSourceCountryQualCapitalization;
19827             break;
19828           case FixCapsAction_mouse_strain:
19829             popup = eMacroPopup_FixCapsInCommonMusMusculusStrains;
19830             break;
19831           case FixCapsAction_author:
19832             popup = eMacroPopup_FixCapsInAuthor;
19833             break;
19834           case FixCapsAction_src_qual:
19835             popup = eMacroPopup_FixSourceQualCapitalization;
19836             break;
19837           default:
19838             popup = eMacroPopup_FixSourceCountryQualCapitalization;
19839             break;
19840         }
19841       }
19842       break;
19843     case MacroActionChoice_fix_format:
19844       fa = (FixFormatActionPtr) action->data.ptrvalue;
19845       if (fa == NULL) {
19846         popup = eMacroPopup_FormatCollectionDate;
19847       } else {
19848         switch (fa->choice) {
19849           case FixFormatAction_collection_date:
19850             popup = eMacroPopup_FormatCollectionDate;
19851             break;
19852           case FixFormatAction_lat_lon:
19853             popup = eMacroPopup_FormatLatLon;
19854             break;
19855           case FixFormatAction_primers:
19856             popup = eMacroPopup_FormatPrimers;
19857             break;
19858           case FixFormatAction_protein_name:
19859             popup = eMacroPopup_FormatProteinName;
19860             break;
19861           default:
19862             popup = eMacroPopup_FormatCollectionDate;
19863             break;
19864         }
19865       }
19866       break;
19867     default:
19868       popup = GetPopupForActionChoice(action->choice);
19869       break;
19870   }
19871   return popup;
19872 }
19873 
19874 
19875 typedef struct actionselectordlg {
19876   DIALOG_MESSAGE_BLOCK
19877   LisT action_category;
19878   LisT action_list[NUM_MacroCategory];
19879 
19880 
19881   Nlm_ChangeNotifyProc     change_notify;
19882   Pointer                  change_userdata;
19883 } ActionSelectorDlgData, PNTR ActionSelectorDlgPtr;
19884 
19885 
ChangeActionCategory(LisT p)19886 static void ChangeActionCategory (LisT p)
19887 {
19888   ActionSelectorDlgPtr dlg;
19889   Int2 i, val, num_none;
19890 
19891   dlg = (ActionSelectorDlgPtr) GetObjectExtra (p);
19892   if (dlg == NULL) {
19893     return;
19894   }
19895 
19896   for (i = 1; i < NUM_MacroCategory; i++) {
19897     Hide (dlg->action_list[i - 1]);
19898   }
19899   val = GetValue (p);
19900   num_none = GetNumInCategory (eMacroCategoryNone);
19901   if (val > num_none) {
19902     Show (dlg->action_list[val - num_none - 1]);
19903     if (GetValue (dlg->action_list[val - num_none - 1]) == 0) {
19904       SetValue (dlg->action_list[val - num_none - 1], 1);
19905     }
19906   }
19907 
19908   if (dlg->change_notify != NULL) {
19909     (dlg->change_notify)(dlg->change_userdata);
19910   }
19911 }
19912 
19913 
ChangeActionSelectorList(LisT l)19914 static void ChangeActionSelectorList (LisT l)
19915 {
19916   ActionSelectorDlgPtr dlg;
19917 
19918   dlg = (ActionSelectorDlgPtr) GetObjectExtra (l);
19919   if (dlg == NULL) {
19920     return;
19921   }
19922 
19923   if (dlg->change_notify != NULL) {
19924     (dlg->change_notify)(dlg->change_userdata);
19925   }
19926 }
19927 
19928 
ActionSelectorDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)19929 static DialoG ActionSelectorDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
19930 {
19931   ActionSelectorDlgPtr dlg;
19932   GrouP                p, g;
19933   Int2                 i, j;
19934 
19935   dlg = (ActionSelectorDlgPtr) MemNew (sizeof (ActionSelectorDlgData));
19936   p = HiddenGroup (h, 3, 0, NULL);
19937   SetGroupSpacing (p, 10, 10);
19938   SetObjectExtra (p, dlg, StdCleanupExtraProc);
19939 
19940   dlg->dialog = (DialoG) p;
19941   dlg->change_notify = change_notify;
19942   dlg->change_userdata = change_userdata;
19943 
19944   StaticPrompt (p, "Choose Macro Action Type", 0, 0, programFont, 'r');
19945 
19946   dlg->action_category = SingleList (p, 17, 8, ChangeActionCategory);
19947   SetObjectExtra (dlg->action_category, dlg, NULL);
19948   for (i = 0; i < NUM_MacroPopup; i++) {
19949     if (s_MacroPopupList[i].category == eMacroCategoryNone) {
19950       ListItem (dlg->action_category, s_MacroPopupList[i].popup_label);
19951     }
19952   }
19953   for (i = 1; i < NUM_MacroCategory; i++) {
19954     ListItem (dlg->action_category, s_MacroCategoryList[i]);
19955   }
19956   g = HiddenGroup (p, 0, 0, NULL);
19957   for (i = 1; i < NUM_MacroCategory; i++) {
19958     dlg->action_list[i - 1] = SingleList (g, 17, 8, ChangeActionSelectorList);
19959     SetObjectExtra (dlg->action_list[i - 1], dlg, NULL);
19960     for (j = 0; j < NUM_MacroPopup; j++) {
19961       if (s_MacroPopupList[j].category == i) {
19962         ListItem (dlg->action_list[i - 1], s_MacroPopupList[j].popup_label);
19963       }
19964     }
19965     Hide (dlg->action_list[i - 1]);
19966   }
19967   return (DialoG) p;
19968 }
19969 
19970 
SetActionSelector(DialoG d,ValNodePtr action)19971 static void SetActionSelector (DialoG d, ValNodePtr action)
19972 {
19973   ActionSelectorDlgPtr dlg;
19974   Int2 i, popup, cat, act, num_none;
19975 
19976   dlg = (ActionSelectorDlgPtr) GetObjectExtra (d);
19977   if (dlg == NULL) {
19978     return;
19979   }
19980 
19981   for (i = 1; i < NUM_MacroCategory; i++) {
19982     Hide (dlg->action_list[i - 1]);
19983   }
19984 
19985   if (action == NULL) {
19986     SetValue (dlg->action_category, 1);
19987   } else {
19988     popup = GetPopupChoiceForAction (action);
19989     cat = GetCategoryForPopupChoice (popup);
19990     act = GetActionInCategoryPositionForPopupChoice (popup, cat);
19991     if (cat == eMacroCategoryNone) {
19992       SetValue (dlg->action_category, act);
19993     } else {
19994       num_none = GetNumInCategory (eMacroCategoryNone);
19995       SetValue (dlg->action_category, cat + num_none);
19996       Show (dlg->action_list[cat - 1]);
19997       SetValue (dlg->action_list[cat - 1], act);
19998     }
19999   }
20000 }
20001 
20002 
GetPopupChoiceFromActionSelector(DialoG d)20003 static Int2 GetPopupChoiceFromActionSelector (DialoG d)
20004 {
20005   ActionSelectorDlgPtr dlg;
20006   Int2 popup, cat, act, num_none;
20007 
20008   dlg = (ActionSelectorDlgPtr) GetObjectExtra (d);
20009   if (dlg == NULL) {
20010     return eMacroPopup_AddFeature;
20011   }
20012 
20013   num_none = GetNumInCategory (eMacroCategoryNone);
20014   cat = GetValue (dlg->action_category);
20015   if (cat < num_none) {
20016     popup = GetPopupForNthInCategory (eMacroCategoryNone, cat);
20017   } else {
20018     act = GetValue (dlg->action_list[cat - num_none - 1]);
20019     if (act < 1) {
20020       act = 1;
20021     }
20022     popup = GetPopupForNthInCategory (cat - num_none, act);
20023   }
20024 
20025   return popup;
20026 }
20027 
20028 
GetActionChoiceForPopupChoice(Int2 popup_choice)20029 static Uint1 GetActionChoiceForPopupChoice (Int2 popup_choice)
20030 {
20031   if (popup_choice > NUM_MacroPopup || popup_choice < 1) {
20032     return -1;
20033   } else {
20034     return s_MacroPopupList[popup_choice - 1].action_choice;
20035   }
20036 }
20037 
GetPopupChoiceForActionChoice(Uint1 action_choice)20038 static Int2 GetPopupChoiceForActionChoice (Uint1 action_choice)
20039 {
20040   Int2 j;
20041 
20042   for (j = 0; j < NUM_MacroPopup; j++) {
20043     if (s_MacroPopupList[j].action_choice == action_choice) {
20044       return j + 1;
20045     }
20046   }
20047   return 1;
20048 }
20049 
20050 
20051 typedef struct editmacroaction {
20052   DialoG action_selector;
20053 
20054   DialoG action_dlg;
20055 
20056   ButtoN accept_btn;
20057   ButtoN test_btn;
20058   ButtoN undo_btn;
20059   ButtoN leave_dlg_up;
20060   WindoW w;
20061   Boolean rebuild_window;
20062   Char    undo_file [PATH_MAX];
20063   ValNodePtr action_copy;
20064   Boolean    indexer_version;
20065   Uint2      entityID;
20066   Uint1      last_qual_type;
20067 } EditMacroActionData, PNTR EditMacroActionPtr;
20068 
20069 static void AdjustMacroActionForRebuild (EditMacroActionPtr d);
20070 
20071 /* rebuild dialog with new feature type */
ChangeMacroAction(Pointer data)20072 static void ChangeMacroAction (Pointer data)
20073 {
20074   EditMacroActionPtr e;
20075   Int2 old_popup, new_popup;
20076 
20077   e = (EditMacroActionPtr) data;
20078   if (e != NULL) {
20079     old_popup = GetPopupChoiceForAction (e->action_copy);
20080     new_popup = GetPopupChoiceFromActionSelector (e->action_selector);
20081     if (new_popup == eMacroPopup_AddFeature) {
20082       e->rebuild_window = TRUE;
20083     } else if (s_MacroPopupList[old_popup - 1].dialog_func == NULL && s_MacroPopupList[new_popup - 1].dialog_func == NULL) {
20084       e->action_copy->choice = GetActionChoiceForPopupChoice(new_popup);
20085     } else if (s_MacroPopupList[old_popup - 1].dialog_func == s_MacroPopupList[new_popup - 1].dialog_func) {
20086       AdjustMacroActionForRebuild(e);
20087       PointerToDialog (e->action_dlg, e->action_copy->data.ptrvalue);
20088     } else {
20089       e->rebuild_window = TRUE;
20090     }
20091   }
20092 }
20093 
20094 
ChangeMacroActionPopup(LisT t)20095 static void ChangeMacroActionPopup (LisT t)
20096 {
20097   ChangeMacroAction (GetObjectExtra (t));
20098 }
20099 
20100 
EnableEditMacroActionAccept(Pointer data)20101 static void EnableEditMacroActionAccept (Pointer data)
20102 {
20103   EditMacroActionPtr e;
20104   ValNodePtr err_list = NULL;
20105 
20106   e = (EditMacroActionPtr) data;
20107   if (e != NULL) {
20108     err_list = TestDialog (e->action_dlg);
20109     if (err_list == NULL) {
20110       Enable (e->accept_btn);
20111       Enable (e->test_btn);
20112     } else {
20113       Disable (e->accept_btn);
20114       Disable (e->test_btn);
20115     }
20116     err_list = ValNodeFree (err_list);
20117   }
20118 }
20119 
20120 
RunMacroInEditor(ButtoN b)20121 static void RunMacroInEditor (ButtoN b)
20122 {
20123   EditMacroActionPtr e;
20124   ValNodePtr  action;
20125   ValNodePtr  sep_list, vnp;
20126   SeqEntryPtr sep;
20127   Uint2       entityID;
20128   LogInfoPtr  lip;
20129   Int4        num_no_op = 0, tmp;
20130 
20131   e = (EditMacroActionPtr) GetObjectExtra (b);
20132   if (e == NULL) return;
20133 
20134   action = ValNodeNew (NULL);
20135   action->choice = GetActionChoiceForPopupChoice(GetPopupChoiceFromActionSelector(e->action_selector));
20136   action->data.ptrvalue = DialogToPointer (e->action_dlg);
20137 
20138   sep_list = GetViewedSeqEntryList ();
20139   if (sep_list == NULL) {
20140     Message (MSG_ERROR, "No records open!");
20141   } else if (sep_list->next != NULL
20142     && ANS_CANCEL == Message (MSG_OKC, "You have more than one record open - run macro for all open records?")) {
20143     /* do nothing */
20144   } else {
20145     WatchCursor();
20146     Update();
20147     lip = OpenLog ("Macro Actions");
20148     for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
20149       sep = vnp->data.ptrvalue;
20150       entityID = ObjMgrGetEntityIDForChoice(sep);
20151       lip->data_in_log |= ApplyMacroToSeqEntryExEx (sep, action, lip->fp, Sequin_GlobalAlign2Seq, &tmp);
20152       num_no_op += tmp;
20153       ObjMgrSetDirtyFlag (entityID, TRUE);
20154       ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
20155     }
20156     sep_list = ValNodeFree (sep_list);
20157     ArrowCursor ();
20158     Update ();
20159     if (lip->data_in_log) {
20160       if (num_no_op > 0) {
20161         fprintf (lip->fp, "%d actions had no effect.\n", num_no_op);
20162       }
20163     } else {
20164       fprintf (lip->fp, "Macro had no effect\n");
20165       lip->data_in_log = TRUE;
20166     }
20167     MakeMacroReportWindow (lip);
20168     lip = FreeLog (lip);
20169   }
20170 
20171   action = MacroActionChoiceFree (action);
20172   Enable (e->undo_btn);
20173 }
20174 
20175 
SaveBackupSeqEntryList(CharPtr path)20176 static Boolean SaveBackupSeqEntryList (CharPtr path)
20177 {
20178   ValNodePtr sep_list, vnp;
20179   AsnIoPtr   aip;
20180 
20181   aip = AsnIoOpen (path, "w");
20182   if (aip == NULL) {
20183     Message (MSG_ERROR, "Unable to open file for backup");
20184     return FALSE;
20185   }
20186 
20187   sep_list = GetViewedSeqEntryList ();
20188   if (sep_list == NULL) {
20189     AsnIoClose (aip);
20190     return FALSE;
20191   }
20192 
20193   for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
20194     SeqEntryAsnWrite (vnp->data.ptrvalue, aip, NULL);
20195   }
20196 
20197   AsnIoClose (aip);
20198   sep_list = ValNodeFree (sep_list);
20199   return TRUE;
20200 }
20201 
20202 
ReadBackupSeqEntryList(CharPtr path)20203 static ValNodePtr ReadBackupSeqEntryList (CharPtr path)
20204 {
20205   AsnIoPtr   aip;
20206   ValNodePtr sep_list = NULL;
20207   SeqEntryPtr sep;
20208 
20209   aip = AsnIoOpen (path, "r");
20210   if (aip == NULL) {
20211     Message (MSG_ERROR, "Unable to open %s", path);
20212   } else {
20213     while ((sep = SeqEntryAsnRead (aip, NULL)) != NULL) {
20214       ValNodeAddPointer (&sep_list, 0, sep);
20215     }
20216     AsnIoClose (aip);
20217   }
20218   return sep_list;
20219 }
20220 
20221 
RestoreList(ValNodePtr curr_sep_list,ValNodePtr backup_sep_list)20222 static void RestoreList (ValNodePtr curr_sep_list, ValNodePtr backup_sep_list)
20223 {
20224   ValNodePtr vnp_c, vnp_b;
20225   SeqEntryPtr sep_c, sep_b;
20226   Uint2       entityID;
20227 
20228   if (curr_sep_list == NULL) return;
20229   if (ValNodeLen (curr_sep_list) != ValNodeLen (backup_sep_list)) {
20230     Message (MSG_ERROR, "Backup list does not match current list.  Unable to undo.");
20231     return;
20232   }
20233 
20234   for (vnp_c = curr_sep_list, vnp_b = backup_sep_list; vnp_c != NULL && vnp_b != NULL; vnp_c = vnp_c->next, vnp_b = vnp_b->next) {
20235     sep_c = vnp_c->data.ptrvalue;
20236     sep_b = vnp_b->data.ptrvalue;
20237     SeqEntrySetScope (NULL);
20238     ReplaceSeqEntryWithSeqEntry (sep_c, sep_b, TRUE);
20239     entityID = ObjMgrGetEntityIDForChoice (sep_c);
20240     ObjMgrSetDirtyFlag (entityID, TRUE);
20241     ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
20242   }
20243   Update();
20244 }
20245 
20246 
UndoMacroActionTest(ButtoN b)20247 static void UndoMacroActionTest (ButtoN b)
20248 {
20249   EditMacroActionPtr e;
20250   ValNodePtr         curr_list;
20251   ValNodePtr         backup_list;
20252 
20253   e = (EditMacroActionPtr) GetObjectExtra (b);
20254   if (e == NULL) return;
20255 
20256   curr_list = GetViewedSeqEntryList ();
20257   if (curr_list == NULL) {
20258     Message (MSG_ERROR, "No records to undo");
20259     Disable (e->undo_btn);
20260     return;
20261   } else {
20262     backup_list = ReadBackupSeqEntryList (e->undo_file);
20263     RestoreList (curr_list, backup_list);
20264     Disable (e->undo_btn);
20265     curr_list = ValNodeFree (curr_list);
20266     backup_list = ValNodeFree (backup_list);
20267   }
20268 
20269 }
20270 
20271 
20272 static WindoW
BuildEditMacroActionWindow(EditMacroActionPtr d,ModalAcceptCancelPtr acp,Boolean adding_new)20273 BuildEditMacroActionWindow
20274 (EditMacroActionPtr d,
20275  ModalAcceptCancelPtr acp,
20276  Boolean adding_new)
20277 {
20278   WindoW                w;
20279   GrouP                 h, c;
20280   ButtoN                b;
20281   Int2                  action_type;
20282 
20283   w = MovableModalWindow(-20, -13, -10, -10, "Edit Action", NULL);
20284 #ifndef WIN_MAC
20285   CreateStandardEditMenu (w);
20286 #endif
20287 
20288   h = HiddenGroup (w, -1, 0, NULL);
20289   SetGroupSpacing (h, 10, 10);
20290 
20291   d->action_selector = ActionSelectorDialog (h, ChangeMacroAction, d);
20292   SetActionSelector(d->action_selector, d->action_copy);
20293 
20294   d->action_dlg = NULL;
20295 
20296   action_type = GetPopupChoiceFromActionSelector (d->action_selector);
20297   /* set up remaining controls */
20298   if (action_type == eMacroPopup_AddFeature) {
20299     d->action_dlg = ApplyFeatureActionDialog (h, d->action_copy == NULL ? NULL : d->action_copy->data.ptrvalue,
20300                 d->indexer_version, EnableEditMacroActionAccept, d, ChangeMacroAction, d);
20301     PointerToDialog (d->action_dlg, d->action_copy->data.ptrvalue);
20302   } else if (s_MacroPopupList[action_type - 1].dialog_func != NULL) {
20303     d->action_dlg = s_MacroPopupList[action_type - 1].dialog_func (h, d->indexer_version, EnableEditMacroActionAccept, d);
20304     PointerToDialog (d->action_dlg, d->action_copy->data.ptrvalue);
20305   }
20306 
20307   c = HiddenGroup (h, 4, 0, NULL);
20308   SetGroupSpacing (c, 10, 10);
20309   d->accept_btn = PushButton (c, "Accept", ModalAcceptButton);
20310   SetObjectExtra (d->accept_btn, acp, NULL);
20311   if (d->undo_file[0] != 0) {
20312     d->test_btn = PushButton (c, "Test", RunMacroInEditor);
20313     SetObjectExtra (d->test_btn, d, NULL);
20314     d->undo_btn = PushButton (c, "Undo", UndoMacroActionTest);
20315     SetObjectExtra (d->undo_btn, d, NULL);
20316     Disable (d->undo_btn);
20317   }
20318   b = PushButton (c, "Cancel", ModalCancelButton);
20319   SetObjectExtra (b, acp, NULL);
20320 
20321   if (adding_new) {
20322     if (d->undo_file[0] == 0) {
20323       d->leave_dlg_up = CheckBox (h, "Leave dialog up", NULL);
20324     } else {
20325       d->leave_dlg_up = CheckBox (h, "Leave dialog up (and add more macro actions)", NULL);
20326     }
20327   }
20328   AlignObjects (ALIGN_CENTER, (HANDLE) c,
20329                               (HANDLE) d->action_selector,
20330                               (HANDLE) d->action_dlg,
20331                               (HANDLE) d->leave_dlg_up,
20332                               NULL);
20333   EnableEditMacroActionAccept (d);
20334   return w;
20335 }
20336 
20337 
AdjustMacroActionForRebuild(EditMacroActionPtr d)20338 static void AdjustMacroActionForRebuild (EditMacroActionPtr d)
20339 {
20340   Int2       action_type;
20341   Uint1      new_action_choice;
20342   ValNodePtr vnp;
20343 
20344   /* copy data from dialog if compatible */
20345   action_type = GetPopupChoiceFromActionSelector (d->action_selector);
20346   new_action_choice = GetActionChoiceForPopupChoice (action_type);
20347   if (d->action_copy != NULL && d->action_copy->choice == MacroActionChoice_aecr) {
20348     d->last_qual_type = FieldTypeChoiceFromEditAECRActionDialog (d->action_dlg);
20349   }
20350   if (d->action_copy != NULL && d->action_copy->choice == MacroActionChoice_aecr && new_action_choice == MacroActionChoice_aecr) {
20351     d->action_copy = MacroActionChoiceFree (d->action_copy);
20352     d->action_copy = ValNodeNew (NULL);
20353     d->action_copy->choice = MacroActionChoice_aecr;
20354     d->action_copy->data.ptrvalue = BuildDefaultAECRAction (ActionTypeChoiceFromPopupValue (action_type), d->last_qual_type);
20355   } else if (d->action_copy != NULL && new_action_choice == MacroActionChoice_fix_format) {
20356     d->action_copy = MacroActionChoiceFree (d->action_copy);
20357     d->action_copy = ValNodeNew (NULL);
20358     d->action_copy->choice = MacroActionChoice_fix_format;
20359     vnp = ValNodeNew (NULL);
20360     d->action_copy->data.ptrvalue = vnp;
20361     switch (action_type) {
20362       case eMacroPopup_FormatCollectionDate:
20363         vnp->choice = FixFormatAction_collection_date;
20364         break;
20365       case eMacroPopup_FormatLatLon:
20366         vnp->choice = FixFormatAction_lat_lon;
20367         break;
20368       case eMacroPopup_FormatPrimers:
20369         vnp->choice = FixFormatAction_primers;
20370         break;
20371       case eMacroPopup_FormatProteinName:
20372         vnp->choice = FixFormatAction_protein_name;
20373         break;
20374       default:
20375         vnp->choice = FixFormatAction_collection_date;
20376         break;
20377     }
20378   } else if (new_action_choice == MacroActionChoice_fix_caps) {
20379     d->action_copy = MacroActionChoiceFree (d->action_copy);
20380     d->action_copy = ValNodeNew (NULL);
20381     d->action_copy->choice = MacroActionChoice_fix_caps;
20382     vnp = ValNodeNew (NULL);
20383     d->action_copy->data.ptrvalue = vnp;
20384     switch (action_type) {
20385       case eMacroPopup_FixPublicationCapitalization:
20386         vnp->choice = FixCapsAction_pub;
20387         break;
20388       case eMacroPopup_FixSourceCountryQualCapitalization:
20389         vnp->choice = FixCapsAction_src_country;
20390         break;
20391       case eMacroPopup_FixCapsInCommonMusMusculusStrains:
20392         vnp->choice = FixCapsAction_mouse_strain;
20393         break;
20394       case eMacroPopup_FixCapsInAuthor:
20395         vnp->choice = FixCapsAction_author;
20396         break;
20397       case eMacroPopup_FixSourceQualCapitalization:
20398         vnp->choice = FixCapsAction_src_qual;
20399         break;
20400       default:
20401         vnp->choice = FixCapsAction_src_country;
20402         break;
20403     }
20404   } else if (d->action_copy != NULL && d->action_copy->choice == new_action_choice) {
20405     d->action_copy = MacroActionChoiceFree (d->action_copy);
20406     d->action_copy = ValNodeNew (NULL);
20407     d->action_copy->choice = new_action_choice;
20408     d->action_copy->data.ptrvalue = DialogToPointer (d->action_dlg);
20409   } else {
20410     d->action_copy = MacroActionChoiceFree (d->action_copy);
20411     d->action_copy = ValNodeNew (NULL);
20412     d->action_copy->choice = new_action_choice;
20413     /* note - only need to set default actions where "NULL" isn't sufficient */
20414     switch (new_action_choice) {
20415       case MacroActionChoice_aecr:
20416         d->action_copy->data.ptrvalue = BuildDefaultAECRAction (ActionTypeChoiceFromPopupValue (action_type), d->last_qual_type);
20417         break;
20418       case MacroActionChoice_remove_feature:
20419         d->action_copy->data.ptrvalue = BuildDefaultRemoveFeatureAction ();
20420         break;
20421       case MacroActionChoice_edit_location:
20422         d->action_copy->data.ptrvalue = BuildDefaultEditFeatureLocationAction (Macro_feature_type_gene);
20423         break;
20424       case MacroActionChoice_fix_caps:
20425         vnp = ValNodeNew (NULL);
20426         d->action_copy->data.ptrvalue = vnp;
20427         switch (action_type) {
20428           case eMacroPopup_FixPublicationCapitalization:
20429             vnp->choice = FixCapsAction_pub;
20430             break;
20431           case eMacroPopup_FixSourceCountryQualCapitalization:
20432             vnp->choice = FixCapsAction_src_country;
20433             break;
20434           case eMacroPopup_FixCapsInCommonMusMusculusStrains:
20435             vnp->choice = FixCapsAction_mouse_strain;
20436             break;
20437           case eMacroPopup_FixCapsInAuthor:
20438             vnp->choice = FixCapsAction_author;
20439             break;
20440           case eMacroPopup_FixSourceQualCapitalization:
20441             vnp->choice = FixCapsAction_src_qual;
20442             break;
20443           default:
20444             vnp->choice = FixCapsAction_src_country;
20445             break;
20446         }
20447         break;
20448     }
20449   }
20450 }
20451 
20452 
EditMacroAction(ValNodePtr action,Boolean indexer_version)20453 static Boolean EditMacroAction (ValNodePtr action, Boolean indexer_version)
20454 {
20455   EditMacroActionData   d;
20456   ModalAcceptCancelData acd;
20457   Boolean               rval = FALSE;
20458   WindoW                w, repl_w;
20459   ValNodePtr            tmp;
20460 
20461   if (action == NULL) return FALSE;
20462 
20463   d.indexer_version = indexer_version;
20464   d.accept_btn = NULL;
20465   d.test_btn = NULL;
20466   d.leave_dlg_up = NULL;
20467 
20468   TmpNam (d.undo_file);
20469   if (!SaveBackupSeqEntryList (d.undo_file)) {
20470     d.undo_file[0] = 0;
20471   }
20472 
20473   d.action_copy = AsnIoMemCopy (action, (AsnReadFunc) MacroActionChoiceAsnRead, (AsnWriteFunc) MacroActionChoiceAsnWrite);
20474   w = BuildEditMacroActionWindow (&d, &acd, FALSE);
20475   d.rebuild_window = FALSE;
20476   d.last_qual_type = FieldType_source_qual;
20477 
20478   Show (w);
20479   Select (w);
20480   acd.accepted = FALSE;
20481   acd.cancelled = FALSE;
20482   while (!acd.accepted && ! acd.cancelled)
20483   {
20484     ProcessExternalEvent ();
20485     if (d.rebuild_window) {
20486       /* copy data from dialog if compatible */
20487       AdjustMacroActionForRebuild (&d);
20488 
20489       /* replace window */
20490       Remove (w);
20491       repl_w = BuildEditMacroActionWindow (&d, &acd, FALSE);
20492       w = repl_w;
20493       Show (w);
20494       Select (w);
20495       d.rebuild_window = FALSE;
20496     }
20497     Update ();
20498   }
20499   ProcessAnEvent ();
20500   if (!acd.cancelled)
20501   {
20502     rval = TRUE;
20503     tmp = ValNodeNew (NULL);
20504     tmp->choice = action->choice;
20505     tmp->data.ptrvalue = action->data.ptrvalue;
20506     action->data.ptrvalue = NULL;
20507     tmp = MacroActionChoiceFree(tmp);
20508     action->choice = GetActionChoiceForPopupChoice(GetPopupChoiceFromActionSelector (d.action_selector));
20509     action->data.ptrvalue = DialogToPointer (d.action_dlg);
20510   }
20511   Remove (w);
20512   FileRemove (d.undo_file);
20513 
20514   d.action_copy = MacroActionChoiceFree (d.action_copy);
20515   return rval;
20516 }
20517 
20518 
AddMacroActions(MacroEditorFormPtr f,Int2 item)20519 static void AddMacroActions (MacroEditorFormPtr f, Int2 item)
20520 {
20521   EditMacroActionData   d;
20522   ModalAcceptCancelData acd;
20523   Boolean               rval = FALSE;
20524   WindoW                w, repl_w;
20525   ValNodePtr            new_action, prev_action = NULL;
20526   Int2                  pos;
20527   Boolean               done = FALSE, leave_up;
20528   Int4                  scroll_pos;
20529   BaR                   sb_vert;
20530 
20531   if (f == NULL) return;
20532 
20533   if (item > 0 && f->macro_list != NULL) {
20534     pos = 1;
20535     prev_action = f->macro_list;
20536     while (pos < item && prev_action->next != NULL) {
20537       pos++;
20538       prev_action = prev_action->next;
20539     }
20540   }
20541 
20542   d.action_copy = BuildDefaultNewMacroAction ();
20543   d.accept_btn = NULL;
20544   d.test_btn = NULL;
20545   d.leave_dlg_up = NULL;
20546   d.indexer_version = f->indexer_version;
20547   if (f->input_entityID != 0) {
20548     TmpNam (d.undo_file);
20549     if (!SaveBackupSeqEntryList (d.undo_file)) {
20550       d.undo_file[0] = 0;
20551     }
20552   }
20553   w = BuildEditMacroActionWindow (&d, &acd, TRUE);
20554   d.rebuild_window = FALSE;
20555   d.last_qual_type = FieldType_source_qual;
20556 
20557   Show (w);
20558   Select (w);
20559   while (!done) {
20560     acd.accepted = FALSE;
20561     acd.cancelled = FALSE;
20562     while (!acd.accepted && ! acd.cancelled)
20563     {
20564       ProcessExternalEvent ();
20565       if (d.rebuild_window) {
20566         /* copy data from dialog if compatible */
20567         AdjustMacroActionForRebuild (&d);
20568 
20569         /* replace window */
20570         leave_up = GetStatus (d.leave_dlg_up);
20571         Remove (w);
20572         repl_w = BuildEditMacroActionWindow (&d, &acd, TRUE);
20573         SetStatus (d.leave_dlg_up, leave_up);
20574         w = repl_w;
20575         Show (w);
20576         Select (w);
20577         d.rebuild_window = FALSE;
20578       }
20579       Update ();
20580     }
20581     ProcessAnEvent ();
20582     if (acd.cancelled) {
20583       done = TRUE;
20584     } else {
20585       /* get current scroll position */
20586       sb_vert = GetSlateVScrollBar ((SlatE) f->macro_summary);
20587       scroll_pos = GetBarValue (sb_vert);
20588       /* we will want to increase the scroll position after each addition
20589        * note that we need to get the scroll bar and check the initial position
20590        * each time - if there was no scroll bar after the last update, scroll_pos
20591        * needs to be zero to start.
20592        */
20593       scroll_pos++;
20594 
20595       rval = TRUE;
20596       /* create new action based on contents of dialog */
20597       new_action = ValNodeNew (NULL);
20598       new_action->choice = GetActionChoiceForPopupChoice(GetPopupChoiceFromActionSelector (d.action_selector));
20599       new_action->data.ptrvalue = DialogToPointer (d.action_dlg);
20600       /* add action to macro list */
20601       if (prev_action == NULL) {
20602         /* put at start of list */
20603         new_action->next = f->macro_list;
20604         f->macro_list = new_action;
20605       } else {
20606         /* insert in list */
20607         new_action->next = prev_action->next;
20608         prev_action->next = new_action;
20609       }
20610       /* next action will be inserted after this one */
20611       prev_action = new_action;
20612       /* update summary */
20613       UpdateMacroSummary (f, scroll_pos);
20614 
20615       /* done if leave_dlg_up not checked */
20616       if (!GetStatus (d.leave_dlg_up)) {
20617         done = TRUE;
20618       }
20619     }
20620   }
20621   Remove (w);
20622   d.action_copy = MacroActionChoiceFree (d.action_copy);
20623 }
20624 
20625 
20626 /* for executing macro actions without creating a macro script */
20627 
20628 typedef struct sampledialog {
20629   DIALOG_MESSAGE_BLOCK
20630   DoC                doc;
20631   Int2               start_item;
20632   Int2               start_row;
20633   Int2               start_col;
20634   Int2               end_item;
20635   Int2               end_row;
20636   Int2               end_col;
20637 
20638 } SampleDialogData, PNTR SampleDialogPtr;
20639 
20640 
PointerToSampleDialog(DialoG d,Pointer data)20641 static void PointerToSampleDialog (DialoG d, Pointer data)
20642 {
20643   SampleDialogPtr    dlg;
20644   ValNodePtr         sample_list;
20645   ValNodePtr         vnp;
20646   AECRSamplePtr      sample;
20647   CharPtr            line_txt;
20648   CharPtr            line_same_fmt = "%s\t(%d same)\t%s\n";
20649   CharPtr            line_mix_fmt = "%s\t(%d mixed)\t%s\n";
20650   CharPtr            fmt;
20651   RecT            r;
20652   ParData         ParFmt = {FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0};
20653   ColData         ColFmt[] =
20654   {
20655     {0, 0, 80, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
20656     {0, 0, 80, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
20657     {0, 0, 80, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, TRUE}
20658   };
20659   Int4            max_char_per_line;
20660   CharPtr         field_name;
20661 
20662 
20663   dlg = (SampleDialogPtr) GetObjectExtra (d);
20664 
20665   if (dlg == NULL) return;
20666   Reset (dlg->doc);
20667 
20668   sample_list = (ValNodePtr) data;
20669   if (sample_list == NULL) return;
20670 
20671   ObjectRect (dlg->doc, &r);
20672   InsetRect (&r, 4, 4);
20673   ColFmt[0].pixWidth = (r.right - r.left) / 3;
20674   ColFmt[1].pixWidth = (r.right - r.left) / 4;
20675   ColFmt[2].pixWidth = (r.right - r.left)  - ColFmt[0].pixWidth - ColFmt[1].pixWidth;
20676 
20677   SelectFont (programFont);
20678   max_char_per_line = ColFmt[2].pixWidth / CharWidth ('0');
20679 
20680   for (vnp = sample_list; vnp != NULL; vnp = vnp->next) {
20681     sample = vnp->data.ptrvalue;
20682     if (sample != NULL) {
20683       field_name = SummarizeFieldType (sample->field);
20684 
20685       if (sample->all_same) {
20686         fmt = line_same_fmt;
20687       } else {
20688         fmt = line_mix_fmt;
20689       }
20690 
20691       line_txt = (CharPtr) MemNew (sizeof (Char) * (StringLen (fmt) + StringLen (field_name) + StringLen (sample->first_value) + 15));
20692       sprintf (line_txt, fmt, field_name, sample->num_found, sample->first_value == NULL ? "" : sample->first_value);
20693       AppendText (dlg->doc, line_txt, &ParFmt, ColFmt, programFont);
20694       MemFree (line_txt);
20695       field_name = MemFree (field_name);
20696     }
20697   }
20698   InvalDocument (dlg->doc);
20699 }
20700 
20701 
20702 static void
GetSampleDialogStartAndEnd(SampleDialogPtr dlg,Int2Ptr start_item,Int2Ptr start_row,Int2Ptr start_col,Int2Ptr end_item,Int2Ptr end_row,Int2Ptr end_col)20703 GetSampleDialogStartAndEnd
20704 (SampleDialogPtr dlg,
20705  Int2Ptr         start_item,
20706  Int2Ptr         start_row,
20707  Int2Ptr         start_col,
20708  Int2Ptr         end_item,
20709  Int2Ptr         end_row,
20710  Int2Ptr         end_col)
20711 {
20712   if (dlg == NULL || start_item == NULL || start_row == NULL
20713       || start_col == NULL || end_item == NULL
20714       || end_row == NULL || end_col == NULL)
20715   {
20716     return;
20717   }
20718 
20719   if (dlg->start_item < 0)
20720   {
20721     *start_item = -1;
20722     *start_row = -1;
20723     *start_col = -1;
20724     *end_item = -1;
20725     *end_row = -1;
20726     *end_col = -1;
20727   }
20728   else if (dlg->end_item < 0)
20729   {
20730     *start_item = dlg->start_item;
20731     *start_row = dlg->start_row;
20732     *start_col = dlg->start_col;
20733     *end_item = *start_item;
20734     *end_row = *start_row;
20735     *end_col = *start_col;
20736   }
20737   else if (dlg->start_item <= dlg->end_item)
20738   {
20739     *start_item = dlg->start_item;
20740     *end_item = dlg->end_item;
20741     if (dlg->start_row <= dlg->end_row)
20742     {
20743       *start_row = dlg->start_row;
20744       *end_row = dlg->end_row;
20745       if (dlg->start_col <= dlg->end_col)
20746       {
20747         *start_col = dlg->start_col;
20748         *end_col = dlg->end_col;
20749       }
20750       else
20751       {
20752         *start_col = dlg->end_col;
20753         *end_col = dlg->start_col;
20754       }
20755     }
20756     else
20757     {
20758       *start_row = dlg->end_row;
20759       *start_col = dlg->end_col;
20760       *end_row = dlg->start_row;
20761       *end_col = dlg->start_col;
20762     }
20763   }
20764   else
20765   {
20766     *start_item = dlg->end_item;
20767     *start_row = dlg->end_row;
20768     *start_col = dlg->end_col;
20769     *end_item = dlg->start_item;
20770     *end_row = dlg->start_row;
20771     *end_col = dlg->start_col;
20772   }
20773 
20774 }
20775 
SampleDialogCopy(SampleDialogPtr dlg)20776 static void SampleDialogCopy (SampleDialogPtr dlg)
20777 {
20778   Int2       start_row = 0, end_row = 0, tmp_row, first_row, last_row;
20779   Int2       start_col = 0, end_col = 0, first_col, last_col;
20780   Int2       start_item = 0, end_item = 0, tmp_item;
20781   CharPtr    str;
20782   ValNodePtr strings = NULL;
20783   Int2       num_rows, num_cols;
20784 
20785   if (dlg->start_row < 0)
20786   {
20787     return;
20788   }
20789 
20790   GetSampleDialogStartAndEnd (dlg, &start_item, &start_row, &start_col,
20791                               &end_item, &end_row, &end_col);
20792 
20793   first_row = start_row;
20794   first_col = start_col;
20795   for (tmp_item = start_item; tmp_item <= end_item; tmp_item++)
20796   {
20797     GetItemParams (dlg->doc, tmp_item, NULL, &num_rows, &num_cols, NULL, NULL);
20798     if (tmp_item == end_item)
20799     {
20800       last_row = end_row;
20801     }
20802     else
20803     {
20804       last_row = num_rows;
20805     }
20806     for (tmp_row = first_row; tmp_row <= last_row; tmp_row++)
20807     {
20808       if (tmp_row == last_row && tmp_item == end_item)
20809       {
20810         last_col = end_col;
20811       }
20812       else
20813       {
20814         last_col = num_cols;
20815       }
20816       str = GetDocText (dlg->doc, tmp_item, tmp_row, 3);
20817       ValNodeAddPointer (&strings, 0, str);
20818     }
20819     first_row = 1;
20820   }
20821   str = MergeValNodeStrings (strings, FALSE);
20822 
20823   StringToClipboard (str);
20824   MemFree (str);
20825   strings = ValNodeFreeData (strings);
20826 }
20827 
InvalidateSampleDialogRows(DoC d,Int2 start_item,Int2 end_item)20828 static void InvalidateSampleDialogRows (DoC d, Int2 start_item, Int2 end_item)
20829 {
20830   Int2 num_rows;
20831   if (d == NULL)
20832   {
20833     return;
20834   }
20835   if (start_item < 1)
20836   {
20837     start_item = 1;
20838   }
20839   if (end_item < 1)
20840   {
20841     end_item = start_item;
20842   }
20843   while (start_item <= end_item)
20844   {
20845     GetItemParams (d, start_item, NULL, &num_rows, NULL, NULL, NULL);
20846     InvalDocRows (d, start_item, 1, num_rows);
20847     start_item++;
20848   }
20849 }
20850 
SampleDialogOnClick(DoC d,PoinT pt)20851 static void SampleDialogOnClick (DoC d, PoinT pt)
20852 {
20853   SampleDialogPtr   dlg;
20854   Int2              pos_item, pos_row, pos_col;
20855   Int2              start_item = 0, start_row, start_col;
20856   Int2              end_item = -1, end_row, end_col;
20857 
20858   dlg = (SampleDialogPtr) GetObjectExtra (d);
20859   if (dlg == NULL) return;
20860 
20861   MapDocPoint (d, pt, &(pos_item), &(pos_row), &(pos_col), NULL);
20862   if (dlg->start_item == pos_item
20863       && dlg->start_row == pos_row
20864       && dlg->start_col == pos_col)
20865   {
20866     dlg->start_row = -1;
20867     dlg->start_col = -1;
20868 
20869   }
20870   else
20871   {
20872     if (dlg->start_item > -1)
20873     {
20874       GetSampleDialogStartAndEnd (dlg, &start_item, &start_row, &start_col,
20875                                   &end_item, &end_row, &end_col);
20876     }
20877     dlg->start_item = pos_item;
20878     dlg->start_row = pos_row;
20879     dlg->start_col = pos_col;
20880   }
20881   dlg->end_item = -1;
20882   dlg->end_row = -1;
20883   dlg->end_col = -1;
20884   InvalidateSampleDialogRows (d, start_item, end_item);
20885   InvalidateSampleDialogRows (d, pos_item, pos_item);
20886 }
20887 
SampleDialogOnDrag(DoC d,PoinT pt)20888 static void SampleDialogOnDrag (DoC d, PoinT pt)
20889 {
20890   SampleDialogPtr   dlg;
20891 
20892   dlg = (SampleDialogPtr) GetObjectExtra (d);
20893   if (dlg == NULL) return;
20894 
20895   MapDocPoint (d, pt, &(dlg->end_item), &(dlg->end_row), &(dlg->end_col), NULL);
20896   InvalDocument (d);
20897 }
20898 
SampleDialogOnRelease(DoC d,PoinT pt)20899 static void SampleDialogOnRelease (DoC d, PoinT pt)
20900 {
20901   SampleDialogPtr   dlg;
20902 
20903   dlg = (SampleDialogPtr) GetObjectExtra (d);
20904   if (dlg == NULL) return;
20905 
20906   MapDocPoint (d, pt, &(dlg->end_item), &(dlg->end_row), &(dlg->end_col), NULL);
20907   InvalDocument (d);
20908 }
20909 
SampleDialogInvert(DoC d,Int2 item,Int2 row,Int2 col)20910 static Boolean SampleDialogInvert (DoC d, Int2 item, Int2 row, Int2 col)
20911 {
20912   SampleDialogPtr   dlg;
20913   Int2              start_item = 0, start_row = 0, start_col = 0;
20914   Int2              end_item = 0, end_row = 0, end_col = 0;
20915   Boolean           rval = FALSE;
20916 
20917   dlg = (SampleDialogPtr) GetObjectExtra (d);
20918   if (dlg == NULL) return FALSE;
20919 
20920   if (dlg->start_row < 0)
20921   {
20922     return FALSE;
20923   }
20924 
20925   if (dlg->end_item == -1)
20926   {
20927     if(dlg->start_item == item
20928        && dlg->start_row == row
20929        && dlg->start_col == col)
20930     {
20931       return TRUE;
20932     }
20933     else
20934     {
20935       return FALSE;
20936     }
20937   }
20938   GetSampleDialogStartAndEnd (dlg, &start_item, &start_row, &start_col,
20939                               &end_item, &end_row, &end_col);
20940   if (start_item <= item && end_item >= item)
20941   {
20942     rval = TRUE;
20943     if (start_item == item)
20944     {
20945       if (start_row == row)
20946       {
20947         if (start_col > col)
20948         {
20949           rval = FALSE;
20950         }
20951       }
20952       else if (start_row > row)
20953       {
20954         rval = FALSE;
20955       }
20956     }
20957 
20958     if (end_item == item)
20959     {
20960       if (end_row == row)
20961       {
20962         if (end_col < col)
20963         {
20964           rval = FALSE;
20965         }
20966       }
20967       else if (end_row < row)
20968       {
20969         rval = FALSE;
20970       }
20971     }
20972   }
20973   if (col == 3)
20974   {
20975     return rval;
20976   }
20977   else
20978   {
20979     return FALSE;
20980   }
20981 }
20982 
SampleDialogOnKey(SlatE s,Char ch)20983 static void SampleDialogOnKey (SlatE s, Char ch)
20984 {
20985   DoC             d;
20986   SampleDialogPtr dlg;
20987 
20988   d = (DoC) s;
20989   Select (d);
20990   dlg = (SampleDialogPtr) GetObjectExtra (d);
20991   if (dlg == NULL) return;
20992   CaptureSlateFocus ((SlatE) s);
20993 
20994 #ifdef WIN_MSWIN
20995   if (ch == 3)
20996   {
20997     SampleDialogCopy (dlg);
20998   }
20999 #else
21000   if (ctrlKey)
21001   {
21002     if (ch == 'c')
21003     {
21004       SampleDialogCopy (dlg);
21005     }
21006   }
21007 #endif
21008 }
21009 
21010 
SampleDialog(GrouP h)21011 static DialoG SampleDialog (GrouP h)
21012 {
21013   SampleDialogPtr dlg;
21014   GrouP           p;
21015   PrompT          ppt;
21016 
21017   dlg = (SampleDialogPtr) MemNew (sizeof (SampleDialogData));
21018   if (dlg == NULL)
21019   {
21020     return NULL;
21021   }
21022 
21023   p = HiddenGroup (h, -1, 0, NULL);
21024 
21025   SetObjectExtra (p, dlg, StdCleanupExtraProc);
21026 
21027   dlg->dialog = (DialoG) p;
21028   dlg->todialog = PointerToSampleDialog;
21029   dlg->fromdialog = NULL;
21030 
21031   ppt = StaticPrompt (p, "Sample Values", 0, dialogTextHeight, programFont, 'l');
21032 
21033   dlg->doc = DocumentPanel (p, stdCharWidth * 27, stdLineHeight * 8);
21034   SetObjectExtra (dlg->doc, dlg, NULL);
21035   SetDocProcs (dlg->doc, SampleDialogOnClick, SampleDialogOnDrag, SampleDialogOnRelease, NULL);
21036   SetDocShade (dlg->doc, NULL, NULL, SampleDialogInvert, NULL);
21037   SetDocAutoAdjust (dlg->doc, TRUE);
21038   SetSlateChar ((SlatE) dlg->doc, SampleDialogOnKey);
21039 
21040   AlignObjects (ALIGN_CENTER, (HANDLE) ppt, (HANDLE) dlg->doc, NULL);
21041 
21042   return (DialoG) p;
21043 }
21044 
21045 
GetSampleDialogValueLen(DialoG d)21046 static Int4 GetSampleDialogValueLen (DialoG d)
21047 {
21048   SampleDialogPtr dlg;
21049   RecT            r;
21050   Int4            max_char_per_line;
21051 
21052   dlg = (SampleDialogPtr) GetObjectExtra (d);
21053   if (dlg == NULL) return 0;
21054 
21055   ObjectRect (dlg->doc, &r);
21056   InsetRect (&r, 4, 4);
21057   SelectFont (programFont);
21058   max_char_per_line = (r.right - r.left - ((r.right - r.left) / 3) - ((r.right - r.left) / 4)) / CharWidth ('0');
21059   return max_char_per_line;
21060 }
21061 
21062 
21063 typedef struct onemacroaction {
21064   FORM_MESSAGE_BLOCK
21065 
21066   DialoG sample_doc;
21067   PopuP  action_type;
21068   DialoG action_dlgs[8];
21069   DialoG constraint_dlg;
21070 
21071   /* groups and dialogs for selecting field types */
21072   DialoG single_qual_type_dlg;
21073   DialoG single_field;
21074   DialoG single_field_remove;
21075   GrouP  single_field_grp;
21076   DialoG pair_qual_type_dlg;
21077   DialoG field_pair;
21078   DialoG field_pair_convert;
21079   GrouP  field_pair_grp;
21080 
21081   ButtoN also_change_mrna;
21082 
21083   ButtoN accept_btn;
21084   ButtoN leave_dlg_up;
21085 
21086   ButtoN clear_on_change;
21087 
21088   WindoW  sample_window;
21089   Boolean indexer_version;
21090   Boolean no_callback;
21091   Int2   prev_action_type;
21092   Int2    win_num;
21093 } OneMacroActionData, PNTR OneMacroActionPtr;
21094 
21095 /* list for keeping track of macro action windows and their sample dialogs */
21096 static ValNodePtr macro_action_window_list = NULL;
21097 
RemoveMacroActionWindow(WindoW w)21098 static void RemoveMacroActionWindow (WindoW w)
21099 {
21100   ValNodePtr vnp, prev = NULL;
21101   OneMacroActionPtr frm;
21102 
21103   vnp = macro_action_window_list;
21104   while (vnp != NULL && vnp->data.ptrvalue != w) {
21105     prev = vnp;
21106     vnp = vnp->next;
21107   }
21108   if (vnp != NULL) {
21109     if (prev == NULL) {
21110       macro_action_window_list = vnp->next;
21111     } else {
21112       prev->next = vnp->next;
21113     }
21114     vnp->next = NULL;
21115     vnp = ValNodeFree (vnp);
21116   }
21117   frm = (OneMacroActionPtr) GetObjectExtra (w);
21118   if (frm != NULL && frm->sample_window != NULL) {
21119     Remove (frm->sample_window);
21120   }
21121 
21122   /* clean up userdata */
21123   if (frm != NULL) {
21124     ObjMgrFreeUserData (0, 0, frm->proctype, frm->userkey);
21125   }
21126   Remove (w);
21127 }
21128 
21129 
AddMacroActionWindow(WindoW w)21130 static Int2 AddMacroActionWindow (WindoW w)
21131 {
21132   Int2 max = 0;
21133   ValNodePtr vnp;
21134 
21135   for (vnp = macro_action_window_list; vnp != NULL; vnp = vnp->next) {
21136     if (vnp->choice > max) {
21137       max = vnp->choice;
21138     }
21139   }
21140   vnp = ValNodeNew (NULL);
21141   vnp->choice = max + 1;
21142   vnp->data.ptrvalue = w;
21143   vnp->next = macro_action_window_list;
21144   macro_action_window_list = vnp;
21145   return max + 1;
21146 }
21147 
21148 
21149 /* for creating, updating, and closing the sample window */
TruncateStringAfterTwoLines(CharPtr str,Uint4 char_per_line)21150 static void TruncateStringAfterTwoLines (CharPtr str, Uint4 char_per_line)
21151 {
21152   CharPtr cp;
21153   Uint4    string_len;
21154 
21155   if (StringHasNoText (str)) {
21156     return;
21157   }
21158 
21159   string_len = StringLen (str);
21160   if (string_len < char_per_line) {
21161     return;
21162   }
21163 
21164   cp = str + char_per_line;
21165   while (! isspace ((Int4)(*cp)) && cp > str) {
21166     cp--;
21167   }
21168   if (cp == str) {
21169     if (string_len > 2 * char_per_line) {
21170       str [2 * char_per_line] = 0;
21171     }
21172   } else {
21173     if (StringLen (cp) > char_per_line) {
21174       cp[char_per_line] = 0;
21175     }
21176   }
21177 }
21178 
21179 
21180 static CharPtr action_names[] = {
21181   "Apply Qualifier" ,
21182   "Edit Qualifier" ,
21183   "Convert Qualifier" ,
21184   "Copy Qualifier" ,
21185   "Swap Qualifier" ,
21186   "Parse Qualifier" ,
21187   "Remove Qualifier" ,
21188   "Remove Text Outside String in Qualifier" };
21189 
21190 #define NUM_AECR_ACTIONS 8
21191 
RefreshAECRSample(ButtoN b)21192 static void RefreshAECRSample (ButtoN b)
21193 {
21194   OneMacroActionPtr d;
21195   Int2              val;
21196   Uint1             qual_type;
21197   ValNodePtr        sample_list = NULL, vnp;
21198   AECRSamplePtr     sample;
21199   Int4              max_char_per_line;
21200 
21201   d = (OneMacroActionPtr) GetObjectExtra (b);
21202 
21203   if (d == NULL || d->sample_doc == NULL) return;
21204 
21205   max_char_per_line = GetSampleDialogValueLen (d->sample_doc);
21206   val = GetValue (d->action_type);
21207   if (val >= 1 && val <= NUM_AECR_ACTIONS) {
21208     qual_type = FieldTypeChoiceFromAECRActionDlg (d->action_dlgs[val - 1]);
21209     sample_list = GetAECRSampleListForSeqEntry (qual_type, GetTopSeqEntryForEntityID (d->input_entityID));
21210   }
21211 
21212   for (vnp = sample_list; vnp != NULL; vnp = vnp->next) {
21213     sample = vnp->data.ptrvalue;
21214     if (sample != NULL) {
21215       TruncateStringAfterTwoLines (sample->first_value, max_char_per_line);
21216     }
21217   }
21218 
21219   PointerToDialog (d->sample_doc, sample_list);
21220   sample_list = AECRSampleListFree (sample_list);
21221 
21222 }
21223 
21224 
ExportAECRSample(ButtoN b)21225 static void ExportAECRSample (ButtoN b)
21226 {
21227   OneMacroActionPtr d;
21228   FILE               *fp;
21229   Char               path [PATH_MAX];
21230   Int2               val;
21231   Uint1              qual_type;
21232 
21233   d = (OneMacroActionPtr) GetObjectExtra (b);
21234 
21235   if (d == NULL || d->sample_doc == NULL) return;
21236   val = GetValue (d->action_type);
21237   if (val >= 1 && val <= NUM_AECR_ACTIONS) {
21238     if (GetOutputFileName (path, sizeof (path), NULL)) {
21239       fp = FileOpen (path, "w");
21240       if (fp == NULL) {
21241         Message (MSG_ERROR, "Unable to open %s", path);
21242       } else {
21243         qual_type = FieldTypeChoiceFromAECRActionDlg (d->action_dlgs[val - 1]);
21244         GetAECRExistingTextList (qual_type, GetTopSeqEntryForEntityID (d->input_entityID), fp);
21245         FileClose (fp);
21246       }
21247     }
21248   }
21249 }
21250 
21251 
CloseMacroSampleWindowProc(WindoW w)21252 static void CloseMacroSampleWindowProc (WindoW w)
21253 {
21254   OneMacroActionPtr     frm;
21255 
21256   frm = (OneMacroActionPtr) GetObjectExtra (w);
21257   if (frm != NULL) {
21258     frm->sample_window = NULL;
21259     frm->sample_doc = NULL;
21260   }
21261   Remove (w);
21262 }
21263 
21264 
CloseSampleWindow(ButtoN b)21265 static void CloseSampleWindow (ButtoN b)
21266 {
21267   OneMacroActionPtr     frm;
21268 
21269   frm = (OneMacroActionPtr) GetObjectExtra (b);
21270   if (frm != NULL) {
21271     CloseMacroSampleWindowProc (frm->sample_window);
21272   }
21273 }
21274 
21275 
ShowMacroSampleWindow(ButtoN b)21276 static void ShowMacroSampleWindow (ButtoN b)
21277 {
21278   OneMacroActionPtr     frm;
21279   GrouP                 h, g;
21280   ButtoN                b2;
21281   CharPtr               title_fmt = "Sample Values (%d)";
21282   CharPtr               title;
21283 
21284   frm = (OneMacroActionPtr) GetObjectExtra (b);
21285   if (frm != NULL) {
21286     if (frm->sample_window == NULL) {
21287       title = (CharPtr) MemNew (sizeof (Char) * (StringLen (title_fmt) + 15));
21288       sprintf (title, title_fmt, frm->win_num);
21289       frm->sample_window = FixedWindow (-20, -13, -10, -10, title, CloseMacroSampleWindowProc);
21290       title = MemFree (title);
21291       SetObjectExtra (frm->sample_window, frm, NULL);
21292       h = HiddenGroup (frm->sample_window, -1, 0, NULL);
21293       SetGroupSpacing (h, 10, 10);
21294       frm->sample_doc = SampleDialog (h);
21295       g = HiddenGroup (h, 3, 0, NULL);
21296       b2 = PushButton (g, "Refresh Sample", RefreshAECRSample);
21297       SetObjectExtra (b2, frm, NULL);
21298       b2 = PushButton (g, "Export Sample", ExportAECRSample);
21299       SetObjectExtra (b2, frm, NULL);
21300       b2 = PushButton (g, "Close", CloseSampleWindow);
21301       SetObjectExtra (b2, frm, NULL);
21302       AlignObjects (ALIGN_CENTER, (HANDLE) frm->sample_doc, (HANDLE) g, NULL);
21303     }
21304     RefreshAECRSample (frm->accept_btn);
21305     Show (frm->sample_window);
21306     Select (frm->sample_window);
21307   }
21308 }
21309 
21310 
21311 /* EnableSingleMacroActionAccept
21312  * This function should be called whenever anything on the form changes.
21313  */
EnableSingleMacroActionAccept(Pointer data)21314 static void EnableSingleMacroActionAccept (Pointer data)
21315 {
21316   OneMacroActionPtr e;
21317   ValNodePtr err_list = NULL;
21318   Int2       val;
21319   IteM       i;
21320 
21321   e = (OneMacroActionPtr) data;
21322   if (e != NULL) {
21323     val = GetValue (e->action_type);
21324     if (val >= 1 && val <= NUM_AECR_ACTIONS) {
21325       err_list = TestDialog (e->action_dlgs[val - 1]);
21326       ValNodeLink (&err_list, TestDialog (e->constraint_dlg));
21327     }
21328     i = FindFormMenuItem ((BaseFormPtr) e, VIB_MSG_ACCEPT);
21329     if (val < 1 || val > NUM_AECR_ACTIONS) {
21330       Disable (e->accept_btn);
21331       SafeDisable (i);
21332     } else {
21333       if (err_list == NULL) {
21334         Enable (e->accept_btn);
21335         SafeEnable (i);
21336       } else {
21337         Disable (e->accept_btn);
21338         SafeDisable (i);
21339       }
21340     }
21341     err_list = ValNodeFree (err_list);
21342   }
21343 }
21344 
21345 
GetQualTypeName(Uint1 qual_type)21346 static CharPtr GetQualTypeName (Uint1 qual_type)
21347 {
21348   CharPtr txt = NULL;
21349   switch (qual_type) {
21350     case FieldType_source_qual:
21351       txt = "Source";
21352       break;
21353     case FieldType_feature_field:
21354       txt = "Feature";
21355       break;
21356     case FieldType_cds_gene_prot:
21357       txt = "CDS-Gene-Prot";
21358       break;
21359     case FieldType_molinfo_field:
21360       txt = "MolInfo";
21361       break;
21362     case FieldType_pub:
21363       txt = "Pub";
21364       break;
21365     case FieldType_rna_field:
21366       txt = "RNA";
21367       break;
21368     case FieldType_struc_comment_field:
21369       txt = "Structured Comment Field";
21370       break;
21371     case FieldType_misc:
21372       txt = "Misc";
21373       break;
21374     default:
21375       txt = "Unknown";
21376       break;
21377   }
21378   return txt;
21379 }
21380 
21381 
21382 /* AdjustSingleMacroActionTitle
21383  * This function should be called whenever the action or the qual type changes.
21384  */
AdjustSingleMacroActionTitle(OneMacroActionPtr d)21385 static void AdjustSingleMacroActionTitle (OneMacroActionPtr d)
21386 {
21387   Int2              val;
21388   Uint1             qual_type;
21389   CharPtr           qual_name, cp;
21390   CharPtr           new_title;
21391   CharPtr           title_fmt = " %s Qualifier (%d)";
21392 
21393   if (d == NULL) {
21394     return;
21395   }
21396 
21397   val = GetValue (d->action_type);
21398   if (val < 1 || val > NUM_AECR_ACTIONS) {
21399     return;
21400   }
21401 
21402   /* change window title */
21403   qual_type = FieldTypeChoiceFromAECRActionDlg (d->action_dlgs[val - 1]);
21404   qual_name = GetQualTypeName(qual_type);
21405   new_title = (CharPtr) MemNew (sizeof (Char) * (StringLen (title_fmt) + StringLen (action_names[val - 1]) + StringLen (qual_name) + 15));
21406   StringCpy (new_title, action_names[val - 1]);
21407   cp = StringChr (new_title, ' ');
21408   if (cp == NULL) {
21409     cp = new_title + StringLen (new_title);
21410   }
21411   sprintf (cp, title_fmt, qual_name, d->win_num);
21412   SetTitle (d->form, new_title);
21413   new_title = MemFree (new_title);
21414 }
21415 
21416 
21417 
IsSingleFieldActionVal(Int2 val)21418 static Boolean IsSingleFieldActionVal (Int2 val)
21419 {
21420   if (val == 1 || val == 2 || val == 7 || val == 8) {
21421     return TRUE;
21422   } else {
21423     return FALSE;
21424   }
21425 }
21426 
21427 
IsConvertFieldActionVal(Int2 val)21428 static Boolean IsConvertFieldActionVal (Int2 val)
21429 {
21430   if (val == 3) {
21431     return TRUE;
21432   } else {
21433     return FALSE;
21434   }
21435 }
21436 
21437 
IsDoubleFieldActionVal(Int2 val)21438 static Boolean IsDoubleFieldActionVal (Int2 val)
21439 {
21440   if (val == 4 || val == 5 || val == 6) {
21441     return TRUE;
21442   } else {
21443     return FALSE;
21444   }
21445 }
21446 
21447 
ActionAffectsCDSProduct(OneMacroActionPtr d)21448 static Boolean ActionAffectsCDSProduct (OneMacroActionPtr d)
21449 {
21450   Int2 action_val;
21451   FieldTypePtr ft = NULL, tmp;
21452   Boolean show = FALSE;
21453 
21454   if (d == NULL) {
21455     return FALSE;
21456   }
21457 
21458   action_val = GetValue (d->action_type);
21459   switch (action_val) {
21460     case 1:
21461     case 2:
21462     case 8:
21463       ft = DialogToPointer (d->single_field);
21464       show = IsFieldTypeCDSProduct (ft);
21465       ft = FieldTypeFree (ft);
21466       break;
21467     case 7:
21468       ft = DialogToPointer (d->single_field_remove);
21469       show = IsFieldTypeCDSProduct (ft);
21470       ft = FieldTypeFree (ft);
21471       break;
21472     case 3:
21473       tmp = DialogToPointer (d->field_pair_convert);
21474       ft = GetToFieldFromFieldPair (tmp);
21475       show = IsFieldTypeCDSProduct (ft);
21476       ft = FieldTypeFree (ft);
21477       ft = GetFromFieldFromFieldPair (tmp);
21478       show |= IsFieldTypeCDSProduct (ft);
21479       ft = FieldTypeFree (ft);
21480       tmp = FieldPairTypeFree (tmp);
21481       break;
21482     case 4:
21483     case 5:
21484     case 6:
21485       tmp = DialogToPointer (d->field_pair);
21486       ft = GetToFieldFromFieldPair (tmp);
21487       show = IsFieldTypeCDSProduct (ft);
21488       ft = FieldTypeFree (ft);
21489       ft = GetFromFieldFromFieldPair (tmp);
21490       show |= IsFieldTypeCDSProduct (ft);
21491       ft = FieldTypeFree (ft);
21492       tmp = FieldPairTypeFree (tmp);
21493       break;
21494   }
21495   return show;
21496 }
21497 
21498 
ShowOrHideAlsoChangeMrna(OneMacroActionPtr d)21499 static void ShowOrHideAlsoChangeMrna (OneMacroActionPtr d)
21500 {
21501   if (d == NULL) {
21502     return;
21503   }
21504   if (ActionAffectsCDSProduct (d)) {
21505     Show (d->also_change_mrna);
21506   } else {
21507     Hide (d->also_change_mrna);
21508   }
21509 }
21510 
21511 
GetRNATypeFromSingleMacroActionForm(OneMacroActionPtr d,Int2 action_val)21512 static ValNodePtr GetRNATypeFromSingleMacroActionForm (OneMacroActionPtr d, Int2 action_val)
21513 {
21514   ValNodePtr   rna_type = NULL;
21515   RnaQualPtr   rq = NULL;
21516   FieldTypePtr ft = NULL;
21517   RnaQualPairPtr   rqp = NULL;
21518   FieldPairTypePtr fpt = NULL;
21519 
21520   if (d == NULL) {
21521     return NULL;
21522   }
21523   switch (action_val) {
21524     case 1:
21525     case 2:
21526     case 8:
21527       ft = DialogToPointer (d->single_field);
21528       if (ft != NULL && ft->choice == FieldType_rna_field) {
21529         rq = (RnaQualPtr) ft->data.ptrvalue;
21530         if (rq != NULL && rq->type != NULL) {
21531           rna_type = AsnIoMemCopy (rq->type, (AsnReadFunc) RnaFeatTypeAsnRead, (AsnWriteFunc) RnaFeatTypeAsnWrite);
21532         }
21533       }
21534       ft = FieldTypeFree (ft);
21535       break;
21536     case 7:
21537       ft = DialogToPointer (d->single_field_remove);
21538       if (ft != NULL && ft->choice == FieldType_rna_field) {
21539         rq = (RnaQualPtr) ft->data.ptrvalue;
21540         if (rq != NULL && rq->type != NULL) {
21541           rna_type = AsnIoMemCopy (rq->type, (AsnReadFunc) RnaFeatTypeAsnRead, (AsnWriteFunc) RnaFeatTypeAsnWrite);
21542         }
21543       }
21544       ft = FieldTypeFree (ft);
21545       break;
21546     case 3:
21547       fpt = DialogToPointer (d->field_pair_convert);
21548       if (fpt != NULL && fpt->choice == FieldPairType_rna_field) {
21549         rqp = (RnaQualPairPtr) fpt->data.ptrvalue;
21550         if (rqp != NULL && rqp->type != NULL) {
21551           rna_type = AsnIoMemCopy (rqp->type, (AsnReadFunc) RnaFeatTypeAsnRead, (AsnWriteFunc) RnaFeatTypeAsnWrite);
21552         }
21553       }
21554       fpt = FieldPairTypeFree (fpt);
21555       break;
21556     case 4:
21557     case 5:
21558     case 6:
21559       fpt = DialogToPointer (d->field_pair);
21560       if (fpt != NULL && fpt->choice == FieldPairType_rna_field) {
21561         rqp = (RnaQualPairPtr) fpt->data.ptrvalue;
21562         if (rqp != NULL && rqp->type != NULL) {
21563           rna_type = AsnIoMemCopy (rqp->type, (AsnReadFunc) RnaFeatTypeAsnRead, (AsnWriteFunc) RnaFeatTypeAsnWrite);
21564         }
21565       }
21566       fpt = FieldPairTypeFree (fpt);
21567       break;
21568   }
21569   return rna_type;
21570 }
21571 
21572 
CopyQualTypeFromPreviousAction(Int2 action,Int2 prev_action,Boolean set_field,OneMacroActionPtr d)21573 static void CopyQualTypeFromPreviousAction (Int2 action, Int2 prev_action, Boolean set_field, OneMacroActionPtr d)
21574 {
21575   ValNodePtr prev_field = NULL;
21576   ValNodePtr new_field = NULL;
21577 
21578   if (d == NULL) {
21579     return;
21580   }
21581 
21582   /* get qual type (and field, if requested) from previous action */
21583   if (IsSingleFieldActionVal (prev_action)) {
21584     if (set_field) {
21585       if (prev_action == 7) {
21586         prev_field = DialogToPointer (d->single_field_remove);
21587       } else {
21588         prev_field = DialogToPointer (d->single_field);
21589       }
21590     }
21591     if (prev_field == NULL) {
21592       prev_field = DialogToPointer (d->single_qual_type_dlg);
21593       if (prev_field != NULL) {
21594         prev_field->data.ptrvalue = MemFree (prev_field->data.ptrvalue);
21595       }
21596     }
21597   } else {
21598     if (set_field) {
21599       if (IsConvertFieldActionVal (prev_action)) {
21600         prev_field = DialogToPointer (d->field_pair_convert);
21601       } else {
21602         prev_field = DialogToPointer (d->field_pair);
21603       }
21604     }
21605     if (prev_field == NULL) {
21606       prev_field = DialogToPointer (d->pair_qual_type_dlg);
21607       if (prev_field != NULL) {
21608         prev_field->data.ptrvalue = MemFree (prev_field->data.ptrvalue);
21609       }
21610     }
21611   }
21612 
21613   /* if necessary, convert from field pair to single field or vice versa */
21614   if (IsSingleFieldActionVal (prev_action) && !IsSingleFieldActionVal (action)) {
21615     new_field = BuildFieldPairFromFromField (prev_field);
21616   } else if (!IsSingleFieldActionVal (prev_action) && IsSingleFieldActionVal (action)) {
21617     new_field = GetFromFieldFromFieldPair (prev_field);
21618     if (new_field == NULL && prev_field != NULL) {
21619       new_field = ValNodeNew (NULL);
21620       new_field->choice = prev_field->choice;
21621     }
21622   } else {
21623     new_field = prev_field;
21624   }
21625 
21626   /* apply field to dialogs for new action */
21627   if (IsSingleFieldActionVal (action)) {
21628     PointerToDialog (d->single_qual_type_dlg, new_field);
21629     if (action == 7) {
21630       PointerToDialog (d->single_field_remove, new_field);
21631     } else {
21632       PointerToDialog (d->single_field, new_field);
21633     }
21634   } else {
21635     PointerToDialog (d->pair_qual_type_dlg, new_field);
21636     if (IsConvertFieldActionVal (action)) {
21637       PointerToDialog (d->field_pair_convert, new_field);
21638     } else {
21639       PointerToDialog (d->field_pair, new_field);
21640     }
21641   }
21642 
21643   /* free field */
21644   if (new_field != prev_field) {
21645     if (IsSingleFieldActionVal (action)) {
21646       new_field = FieldTypeFree (new_field);
21647     } else {
21648       new_field = FieldPairTypeFree (new_field);
21649     }
21650   }
21651 
21652   if (IsSingleFieldActionVal (prev_action)) {
21653     prev_field = FieldTypeFree (prev_field);
21654   } else {
21655     prev_field = FieldPairTypeFree (prev_field);
21656   }
21657 
21658   ShowOrHideAlsoChangeMrna (d);
21659 }
21660 
21661 
MakeQualDialogsVisible(Int2 action,OneMacroActionPtr d)21662 static void MakeQualDialogsVisible (Int2 action, OneMacroActionPtr d)
21663 {
21664   if (d == NULL) {
21665     return;
21666   }
21667 
21668   /* choose whether single or double fields are seen */
21669   if (IsSingleFieldActionVal (action)) {
21670     Show (d->single_field_grp);
21671     Hide (d->field_pair_grp);
21672     if (action == 7) {
21673       Show (d->single_field_remove);
21674       Hide (d->single_field);
21675     } else {
21676       Hide (d->single_field_remove);
21677       Show (d->single_field);
21678     }
21679   } else if (IsConvertFieldActionVal (action)) {
21680     Hide (d->single_field_grp);
21681     Show (d->field_pair_grp);
21682     Show (d->field_pair_convert);
21683     Hide (d->field_pair);
21684   } else if (IsDoubleFieldActionVal (action)) {
21685     Hide (d->single_field_grp);
21686     Show (d->field_pair_grp);
21687     Hide (d->field_pair_convert);
21688     Show (d->field_pair);
21689   }
21690 }
21691 
21692 
21693 static AECRActionPtr AECRActionFromSingleMacroDialog (OneMacroActionPtr d);
21694 
PrepopulateField(OneMacroActionPtr d)21695 static void PrepopulateField (OneMacroActionPtr d)
21696 {
21697   Int2 val;
21698   FieldTypePtr  single_field;
21699   Boolean       is_nontext;
21700   AECRActionPtr act;
21701   ValNodePtr    sample_list = NULL;
21702   AECRSamplePtr     sample;
21703 
21704   if (d == NULL) {
21705     return;
21706   }
21707 
21708   val = GetValue (d->action_type);
21709   if (val == 1 || val == 2) {
21710     if (GetAutopopulateStatus (d->action_dlgs[val - 1])) {
21711       single_field = DialogToPointer (d->single_field);
21712       if (single_field != NULL) {
21713         is_nontext = IsFieldTypeNonText (single_field);
21714         if (!is_nontext) {
21715           act = AECRActionFromSingleMacroDialog (d);
21716           sample_list = GetAECRSampleList (act, GetTopSeqEntryForEntityID (d->input_entityID));
21717           act = AECRActionFree (act);
21718           sample = GetFieldSampleFromList (sample_list, single_field);
21719           if (val == 1) {
21720             if (sample == NULL) {
21721               SetApplyActionDialogText (d->action_dlgs[0], "");
21722             } else {
21723               SetApplyActionDialogText (d->action_dlgs[0], sample->first_value);
21724             }
21725           } else {
21726             if (sample == NULL) {
21727               SetEditActionDialogText (d->action_dlgs[1], "", NULL);
21728             } else {
21729               SetEditActionDialogText (d->action_dlgs[1], sample->first_value, NULL);
21730             }
21731           }
21732           sample_list = AECRSampleListFree (sample_list);
21733         }
21734       }
21735       single_field = FieldTypeFree (single_field);
21736     }
21737   }
21738 }
21739 
21740 
21741 /* When the action changes, the following things must happen:
21742  * () change which field type and qual type dialogs are visible
21743  * () copy qual type from previously used qual type dialog to new one
21744  * () if we are not clearing on change, copy the field from the previous field type dialog
21745  * () make the correct action dialog visible
21746  * () adjust apply options (if the action is apply)
21747  * () prepopulate fields based on sample
21748  * () adjust the window title
21749  * () enable the accept button
21750  */
ChangeSingleMacroActionPopup(PopuP p)21751 static void ChangeSingleMacroActionPopup (PopuP p)
21752 {
21753   OneMacroActionPtr d;
21754   Int2              val;
21755   Int4              i;
21756 
21757   d = (OneMacroActionPtr) GetObjectExtra (p);
21758   if (d == NULL || d->no_callback) return;
21759 
21760   val = GetValue (d->action_type);
21761   if (val < 1 || val > NUM_AECR_ACTIONS) {
21762     return;
21763   }
21764 
21765   d->no_callback = TRUE;
21766 
21767   MakeQualDialogsVisible (val, d);
21768   CopyQualTypeFromPreviousAction (val, d->prev_action_type, !GetStatus (d->clear_on_change), d);
21769 
21770   /* change which dialog is displayed */
21771   for (i = 0; i < NUM_AECR_ACTIONS; i++) {
21772     Hide (d->action_dlgs[i]);
21773   }
21774   Show (d->action_dlgs[val - 1]);
21775 
21776   /* set action-specific options that depend on field type */
21777   if (val == 1) {
21778     ChangeDialogForApplyFieldChoice (d->action_dlgs[val - 1]);
21779   }
21780 
21781   PrepopulateField (d);
21782 
21783   AdjustSingleMacroActionTitle (d);
21784 
21785   d->prev_action_type = val;
21786   EnableSingleMacroActionAccept (d);
21787   d->no_callback = FALSE;
21788 }
21789 
21790 
GetFieldFromQualTypeDlg(DialoG d)21791 static ValNodePtr GetFieldFromQualTypeDlg (DialoG d)
21792 {
21793   ValNodePtr field;
21794 
21795   field = DialogToPointer (d);
21796   if (field != NULL) {
21797     field->data.ptrvalue = NULL;
21798   }
21799   return field;
21800 }
21801 
21802 
GetFeatureTypeFromSingleMacroActionForm(OneMacroActionPtr d)21803 static Int2 GetFeatureTypeFromSingleMacroActionForm (OneMacroActionPtr d)
21804 {
21805   Int2 val, feat_type = Macro_feature_type_any;
21806   ValNodePtr field = NULL, field_pair;
21807 
21808   if (d == NULL) {
21809     return feat_type;
21810   }
21811 
21812   val = GetValue (d->action_type);
21813   if (IsSingleFieldActionVal (val)) {
21814     if (val == 7) {
21815       field = DialogToPointer (d->single_field_remove);
21816     } else {
21817       field = DialogToPointer (d->single_field);
21818     }
21819   } else {
21820     if (IsConvertFieldActionVal (val)) {
21821       field_pair = DialogToPointer (d->field_pair_convert);
21822     } else {
21823       field_pair = DialogToPointer (d->field_pair);
21824     }
21825     field = GetFromFieldFromFieldPair (field_pair);
21826     field_pair = FieldPairTypeFree (field_pair);
21827   }
21828 
21829   feat_type = FeatureTypeFromFieldType (field);
21830   field = FieldTypeFree (field);
21831   return feat_type;
21832 }
21833 
21834 
SetFieldType(OneMacroActionPtr d)21835 static void SetFieldType (OneMacroActionPtr d)
21836 {
21837   Int2              val;
21838   FieldTypePtr      single_field = NULL, tmp;
21839   FieldPairTypePtr  field_pair = NULL;
21840   Uint1             qual_type = 0;
21841   ValNodePtr        rna_type = NULL;
21842   Int2              feat_type = Macro_feature_type_any;
21843 
21844   if (d == NULL) {
21845     return;
21846   }
21847   /* set field type */
21848   val = GetValue (d->action_type);
21849   if (IsSingleFieldActionVal (val)) {
21850     single_field = GetFieldFromQualTypeDlg (d->single_qual_type_dlg);
21851     if (single_field != NULL) {
21852       if (val == 7) {
21853         tmp = GetFieldOfTypeFromFieldType(d->single_field_remove, single_field->choice);
21854       } else {
21855         tmp = GetFieldOfTypeFromFieldType(d->single_field, single_field->choice);
21856       }
21857       if (tmp != NULL) {
21858         single_field = FieldTypeFree (single_field);
21859         single_field = tmp;
21860       }
21861     }
21862     if (val == 7) {
21863       PointerToDialog (d->single_field_remove, single_field);
21864     } else {
21865       PointerToDialog (d->single_field, single_field);
21866     }
21867   } else {
21868     single_field = GetFieldFromQualTypeDlg (d->pair_qual_type_dlg);
21869     field_pair = BuildFieldPairFromFromField (single_field);
21870     if (IsConvertFieldActionVal (val)) {
21871       PointerToDialog (d->field_pair_convert, field_pair);
21872     } else {
21873       PointerToDialog (d->field_pair, field_pair);
21874     }
21875   }
21876 
21877   if (single_field != NULL) {
21878     qual_type = single_field->choice;
21879   }
21880   single_field = FieldTypeFree (single_field);
21881   field_pair = FieldPairTypeFree (field_pair);
21882 
21883   /* change which constraint dialog is visible, if using "simple" constraints */
21884   if (qual_type == FieldType_rna_field) {
21885     rna_type = GetRNATypeFromSingleMacroActionForm (d, val);
21886   }
21887 
21888   feat_type = GetFeatureTypeFromSingleMacroActionForm (d);
21889 
21890   ChangeComplexConstraintFieldType (d->constraint_dlg, qual_type, rna_type, feat_type);
21891   rna_type = RnaFeatTypeFree (rna_type);
21892 
21893 }
21894 
21895 /* when qual type changes, must:
21896  * () set field type
21897  * () adjust constraints
21898  * () prepopulate field
21899  * () refresh sample
21900  * () adjust window title
21901  * () enable accept button
21902  */
ChangeQualType(Pointer data)21903 static void ChangeQualType (Pointer data)
21904 {
21905   OneMacroActionPtr d;
21906 
21907   d = (OneMacroActionPtr) data;
21908   if (d == NULL || d->no_callback) return;
21909 
21910   d->no_callback = TRUE;
21911   SetFieldType (d);
21912 
21913   /* set action-specific options that depend on field type */
21914   if (GetValue (d->action_type) == 1) {
21915     ChangeDialogForApplyFieldChoice (d->action_dlgs[0]);
21916   }
21917 
21918   PrepopulateField (d);
21919 
21920   /* refresh sample values */
21921   RefreshAECRSample (d->accept_btn);
21922 
21923   /* adjust title */
21924   AdjustSingleMacroActionTitle (d);
21925 
21926   /* enable accept button */
21927   EnableSingleMacroActionAccept (d);
21928   d->no_callback = FALSE;
21929 }
21930 
21931 
21932 /* when field changes, must:
21933  * () change constraint dialog (for RNA only)
21934  * () prepopulate field
21935  * () enable accept button
21936  */
ChangeSingleMacroActionFieldChoice(Pointer data)21937 static void ChangeSingleMacroActionFieldChoice (Pointer data)
21938 {
21939   OneMacroActionPtr d;
21940   FieldTypePtr      single_field;
21941   Uint1             qual_type;
21942   ValNodePtr        rna_type = NULL;
21943   Int2              val, feat_type = Macro_feature_type_any;
21944 
21945   d = (OneMacroActionPtr) data;
21946   if (d == NULL || d->no_callback) return;
21947 
21948   val = GetValue (d->action_type);
21949   if (IsSingleFieldActionVal (val)) {
21950     single_field = GetFieldFromQualTypeDlg (d->single_qual_type_dlg);
21951   } else {
21952     single_field = GetFieldFromQualTypeDlg (d->pair_qual_type_dlg);
21953   }
21954 
21955   if (single_field == NULL) {
21956     return;
21957   }
21958   qual_type = single_field->choice;
21959   single_field = FieldTypeFree (single_field);
21960 
21961   d->no_callback = TRUE;
21962 
21963   if (qual_type == FieldType_rna_field) {
21964     rna_type = GetRNATypeFromSingleMacroActionForm (d, val);
21965   }
21966   feat_type = GetFeatureTypeFromSingleMacroActionForm (d);
21967 
21968   ChangeComplexConstraintFieldType (d->constraint_dlg, qual_type, rna_type, feat_type);
21969   rna_type = RnaFeatTypeFree (rna_type);
21970 
21971   /* set action-specific options that depend on field type */
21972   if (val == 1) {
21973     ChangeDialogForApplyFieldChoice (d->action_dlgs[0]);
21974   }
21975 
21976   ShowOrHideAlsoChangeMrna (d);
21977 
21978   PrepopulateField (d);
21979 
21980   /* enable accept button */
21981   EnableSingleMacroActionAccept (d);
21982   d->no_callback = FALSE;
21983 }
21984 
21985 
AutopopulateSingleMacroDialog(OneMacroActionPtr frm)21986 static void AutopopulateSingleMacroDialog (OneMacroActionPtr frm)
21987 {
21988   Int2 val;
21989   Boolean status;
21990 
21991   if (frm != NULL) {
21992     val = GetValue (frm->action_type);
21993     if (val == 1 || val == 2) {
21994       status = GetAutopopulateStatus (frm->action_dlgs[val - 1]);
21995       SetAutopopulateStatus (frm->action_dlgs[0], status);
21996       SetAutopopulateStatus (frm->action_dlgs[1], status);
21997       if (status) {
21998         frm->no_callback = TRUE;
21999         PrepopulateField (frm);
22000         EnableSingleMacroActionAccept (frm);
22001         frm->no_callback = FALSE;
22002       }
22003     }
22004   }
22005 }
22006 
22007 
AECRActionFromSingleMacroDialog(OneMacroActionPtr d)22008 static AECRActionPtr AECRActionFromSingleMacroDialog (OneMacroActionPtr d)
22009 {
22010   Int2 val;
22011   AECRActionPtr aecr = NULL;
22012 
22013   if (d == NULL) return NULL;
22014 
22015   /* create new action based on contents of dialog */
22016   val = GetValue (d->action_type);
22017   switch (val) {
22018     case 1:
22019       aecr = AECRActionNew ();
22020       ValNodeAddPointer (&(aecr->action), ActionChoice_apply, DialogToPointer (d->action_dlgs[val - 1]));
22021       aecr->constraint = DialogToPointer (d->constraint_dlg);
22022       break;
22023     case 2:
22024       aecr = AECRActionNew ();
22025       ValNodeAddPointer (&(aecr->action), ActionChoice_edit, DialogToPointer (d->action_dlgs[val - 1]));
22026       aecr->constraint = DialogToPointer (d->constraint_dlg);
22027       break;
22028     case 3:
22029       aecr = AECRActionNew ();
22030       ValNodeAddPointer (&(aecr->action), ActionChoice_convert, DialogToPointer (d->action_dlgs[val - 1]));
22031       aecr->constraint = DialogToPointer (d->constraint_dlg);
22032       break;
22033     case 4:
22034       aecr = AECRActionNew ();
22035       ValNodeAddPointer (&(aecr->action), ActionChoice_copy, DialogToPointer (d->action_dlgs[val - 1]));
22036       aecr->constraint = DialogToPointer (d->constraint_dlg);
22037       break;
22038     case 5:
22039       aecr = AECRActionNew ();
22040       ValNodeAddPointer (&(aecr->action), ActionChoice_swap, DialogToPointer (d->action_dlgs[val - 1]));
22041       aecr->constraint = DialogToPointer (d->constraint_dlg);
22042       break;
22043     case 6:
22044       aecr = AECRActionNew ();
22045       ValNodeAddPointer (&(aecr->action), ActionChoice_parse, DialogToPointer (d->action_dlgs[val - 1]));
22046       aecr->constraint = DialogToPointer (d->constraint_dlg);
22047       break;
22048     case 7:
22049       aecr = AECRActionNew ();
22050       ValNodeAddPointer (&(aecr->action), ActionChoice_remove, DialogToPointer (d->action_dlgs[val - 1]));
22051       aecr->constraint = DialogToPointer (d->constraint_dlg);
22052       break;
22053     case 8:
22054       aecr = AECRActionNew ();
22055       ValNodeAddPointer (&(aecr->action), ActionChoice_remove_outside, DialogToPointer (d->action_dlgs[val - 1]));
22056       aecr->constraint = DialogToPointer (d->constraint_dlg);
22057       break;
22058   }
22059   if (aecr != NULL && ActionAffectsCDSProduct (d)) {
22060       aecr->also_change_mrna = GetStatus (d->also_change_mrna);
22061   }
22062   return aecr;
22063 }
22064 
22065 
SingleMacroAcceptButton(ButtoN b)22066 static void SingleMacroAcceptButton (ButtoN b)
22067 {
22068   OneMacroActionPtr d;
22069   ValNodePtr        new_action;
22070   SeqEntryPtr       sep;
22071   Int4              num_fields, num_features;
22072   Int2              val;
22073   Uint2             existing_txt = ExistingTextOption_replace_old;
22074   AECRActionPtr     action;
22075   ApplyActionPtr    apply;
22076   ConvertActionPtr  convert;
22077   CopyActionPtr     copy;
22078   AECRParseActionPtr parse;
22079   ValNodePtr        sample_list = NULL;
22080   AECRSamplePtr     sample;
22081   FieldTypePtr      dest_field;
22082 
22083   d = (OneMacroActionPtr) GetObjectExtra (b);
22084   if (d == NULL) return;
22085 
22086   /* create new action based on contents of dialog */
22087   val = GetValue (d->action_type);
22088 
22089   new_action = ValNodeNew (NULL);
22090   switch (val) {
22091     case 1: /* apply */
22092       new_action->choice = MacroActionChoice_aecr;
22093       action = AECRActionFromSingleMacroDialog (d);
22094       new_action->data.ptrvalue = action;
22095       apply = action->action->data.ptrvalue;
22096       sample_list = GetAECRSampleList (action, GetTopSeqEntryForEntityID (d->input_entityID));
22097       sample = GetFieldSampleFromList (sample_list, apply->field);
22098       if (sample != NULL && sample->num_found > 0) {
22099         existing_txt = TwoStepExistingText (sample->num_found, IsFieldTypeNonText(apply->field), AllowFieldMulti (apply->field));
22100       }
22101       sample_list = AECRSampleListFree (sample_list);
22102       if (existing_txt == 0) {
22103         new_action = MacroActionChoiceFree (new_action);
22104       } else {
22105         apply->existing_text = existing_txt;
22106       }
22107       break;
22108     case 3: /* convert */
22109       new_action->choice = MacroActionChoice_aecr;
22110       action = AECRActionFromSingleMacroDialog (d);
22111       new_action->data.ptrvalue = action;
22112       convert = action->action->data.ptrvalue;
22113       sample_list = GetAECRSampleList (action, GetTopSeqEntryForEntityID (d->input_entityID));
22114       dest_field = GetToFieldFromFieldPair (convert->fields);
22115       sample = GetFieldSampleFromList (sample_list, dest_field);
22116       if (sample != NULL && sample->num_found > 0) {
22117         existing_txt = TwoStepExistingText (sample->num_found, IsFieldTypeNonText(dest_field), AllowFieldMulti (dest_field));
22118       }
22119       sample_list = AECRSampleListFree (sample_list);
22120       dest_field = FieldTypeFree (dest_field);
22121       if (existing_txt == 0) {
22122         new_action = MacroActionChoiceFree (new_action);
22123       } else {
22124         convert->existing_text = existing_txt;
22125       }
22126       break;
22127     case 4: /* copy */
22128       new_action->choice = MacroActionChoice_aecr;
22129       action = AECRActionFromSingleMacroDialog (d);
22130       new_action->data.ptrvalue = action;
22131       copy = action->action->data.ptrvalue;
22132       sample_list = GetAECRSampleList (action, GetTopSeqEntryForEntityID (d->input_entityID));
22133       dest_field = GetToFieldFromFieldPair (copy->fields);
22134       sample = GetFieldSampleFromList (sample_list, dest_field);
22135       if (sample != NULL && sample->num_found > 0) {
22136         existing_txt = TwoStepExistingText (sample->num_found, IsFieldTypeNonText(dest_field), AllowFieldMulti (dest_field));
22137       }
22138       sample_list = AECRSampleListFree (sample_list);
22139       dest_field = FieldTypeFree (dest_field);
22140       if (existing_txt == 0) {
22141         new_action = MacroActionChoiceFree (new_action);
22142       } else {
22143         copy->existing_text = existing_txt;
22144       }
22145       break;
22146     case 6: /* parse */
22147       new_action->choice = MacroActionChoice_aecr;
22148       action = AECRActionFromSingleMacroDialog (d);
22149       new_action->data.ptrvalue = action;
22150       parse = action->action->data.ptrvalue;
22151       sample_list = GetAECRSampleList (action, GetTopSeqEntryForEntityID (d->input_entityID));
22152       dest_field = GetToFieldFromFieldPair (parse->fields);
22153       sample = GetFieldSampleFromList (sample_list, dest_field);
22154       if (sample != NULL && sample->num_found > 0) {
22155         existing_txt = TwoStepExistingText (sample->num_found, IsFieldTypeNonText(dest_field), AllowFieldMulti (dest_field));
22156       }
22157       sample_list = AECRSampleListFree (sample_list);
22158       dest_field = FieldTypeFree (dest_field);
22159       if (existing_txt == 0) {
22160         new_action = MacroActionChoiceFree (new_action);
22161       } else {
22162         parse->existing_text = existing_txt;
22163       }
22164       break;
22165     case 2: /* edit */
22166     case 5: /* swap */
22167     case 7: /* remove */
22168     case 8: /* remove text outside string */
22169       new_action->choice = MacroActionChoice_aecr;
22170       new_action->data.ptrvalue = AECRActionFromSingleMacroDialog (d);
22171       break;
22172   }
22173 
22174   if (new_action == NULL) {
22175     return;
22176   }
22177 
22178   /* execute action */
22179   WatchCursor();
22180   Update();
22181 
22182   sep = GetTopSeqEntryForEntityID (d->input_entityID);
22183   num_fields = 0;
22184   num_features = 0;
22185   ApplyMacroToSeqEntryEx (sep, new_action, NULL, Sequin_GlobalAlign2Seq);
22186   ObjMgrSetDirtyFlag (d->input_entityID, TRUE);
22187   ObjMgrSendMsg (OM_MSG_UPDATE, d->input_entityID, 0, 0);
22188 
22189   ArrowCursor ();
22190   Update ();
22191   new_action = MacroActionChoiceFree (new_action);
22192 
22193   /* done if leave_dlg_up not checked */
22194   if (!GetStatus (d->leave_dlg_up)) {
22195     RemoveMacroActionWindow ((WindoW)(d->form));
22196   }
22197 }
22198 
22199 
SingleMacroCancelButton(ButtoN b)22200 static void SingleMacroCancelButton (ButtoN b)
22201 {
22202   OneMacroActionPtr d;
22203 
22204   d = (OneMacroActionPtr) GetObjectExtra (b);
22205   if (d == NULL) return;
22206 
22207   RemoveMacroActionWindow ((WindoW)(d->form));
22208 }
22209 
22210 
ActionToSingleMacroActionForm(ForM f,Pointer data)22211 static void ActionToSingleMacroActionForm (ForM f, Pointer data)
22212 {
22213   OneMacroActionPtr     frm;
22214   ValNodePtr            action;
22215   AECRActionPtr         aecr;
22216   Int2                  val, i;
22217 
22218 
22219   frm = (OneMacroActionPtr) GetObjectExtra (f);
22220   if (frm == NULL) return;
22221 
22222   frm->no_callback = TRUE;
22223   action = (ValNodePtr) data;
22224 
22225   if (action == NULL) {
22226     SetValue (frm->action_type, 1);
22227     PointerToDialog (frm->action_dlgs[0], NULL);
22228     val = 1;
22229   } else if (action->choice == MacroActionChoice_aecr) {
22230     aecr = (AECRActionPtr) action->data.ptrvalue;
22231     if (aecr == NULL || aecr->action == NULL) {
22232       SetValue (frm->action_type, 1);
22233       val = 1;
22234     } else {
22235       switch (aecr->action->choice) {
22236         case ActionChoice_apply:
22237           SetValue (frm->action_type, 1);
22238           break;
22239         case ActionChoice_edit:
22240           SetValue (frm->action_type, 2);
22241           break;
22242         case ActionChoice_convert:
22243           SetValue (frm->action_type, 3);
22244           break;
22245         case ActionChoice_copy:
22246           SetValue (frm->action_type, 4);
22247           break;
22248         case ActionChoice_swap:
22249           SetValue (frm->action_type, 5);
22250           break;
22251         case ActionChoice_parse:
22252           SetValue (frm->action_type, 6);
22253           break;
22254         case ActionChoice_remove:
22255           SetValue (frm->action_type, 7);
22256           break;
22257         case ActionChoice_remove_outside:
22258           SetValue (frm->action_type, 8);
22259           break;
22260         default:
22261           SetValue (frm->action_type, 1);
22262           break;
22263       }
22264       val = GetValue (frm->action_type);
22265       PointerToDialog (frm->action_dlgs[val - 1], aecr->action->data.ptrvalue);
22266     }
22267   }
22268 
22269   /* change which dialog is displayed */
22270   for (i = 0; i < NUM_AECR_ACTIONS; i++) {
22271     Hide (frm->action_dlgs[i]);
22272   }
22273   Show (frm->action_dlgs[val - 1]);
22274 
22275   /* set field type */
22276   SetFieldType(frm);
22277 
22278   MakeQualDialogsVisible (val, frm);
22279 
22280   /* set action-specific options that depend on field type */
22281   if (val == 1) {
22282     ChangeDialogForApplyFieldChoice (frm->action_dlgs[0]);
22283   }
22284 
22285   PrepopulateField (frm);
22286 
22287   AdjustSingleMacroActionTitle (frm);
22288 
22289   RefreshAECRSample (frm->accept_btn);
22290   EnableSingleMacroActionAccept (frm);
22291   frm->no_callback = FALSE;
22292 }
22293 
22294 
ClearSingleMacroAction(ButtoN b)22295 static void ClearSingleMacroAction (ButtoN b)
22296 {
22297   OneMacroActionPtr frm;
22298   Int2              val;
22299   ValNodePtr        qual_type;
22300   DialoG            qual_dlg;
22301 
22302   frm = (OneMacroActionPtr) GetObjectExtra (b);
22303   if (frm == NULL) {
22304     return;
22305   }
22306 
22307   val = GetValue (frm->action_type);
22308 
22309   /* get field type, so that we can put it back after the clear */
22310   if (IsSingleFieldActionVal (val)) {
22311     qual_dlg = frm->single_qual_type_dlg;
22312   } else {
22313     qual_dlg = frm->pair_qual_type_dlg;
22314   }
22315   qual_type = DialogToPointer (qual_dlg);
22316 
22317   /* clear action dialog */
22318   if (val > 0 && val < NUM_AECR_ACTIONS) {
22319     PointerToDialog (frm->action_dlgs[val - 1], NULL);
22320   }
22321 
22322   /* reapply field type */
22323   PointerToDialog (qual_dlg, qual_type);
22324   qual_type = ValNodeFreeData (qual_type);
22325   SetFieldType (frm);
22326 
22327   /* also clear constraints */
22328   PointerToDialog (frm->constraint_dlg, NULL);
22329 }
22330 
22331 
ClearTextSingleMacroAction(ButtoN b)22332 static void ClearTextSingleMacroAction (ButtoN b)
22333 {
22334   OneMacroActionPtr frm;
22335   Int2              val;
22336 
22337   frm = (OneMacroActionPtr) GetObjectExtra (b);
22338   if (frm == NULL) {
22339     return;
22340   }
22341 
22342   val = GetValue (frm->action_type);
22343 
22344   switch (val) {
22345     case 1:
22346       SetApplyActionDialogText (frm->action_dlgs[0], "");
22347       break;
22348     case 2:
22349       SetEditActionDialogText (frm->action_dlgs[1], "", "");
22350       break;
22351     case 3:
22352       break;
22353     case 4:
22354       break;
22355     case 5:
22356       break;
22357     case 6:
22358       break;
22359     case 7:
22360       break;
22361     case 8:
22362       break;
22363   }
22364   /* also clear text in simple constraint if shown */
22365   ClearComplexConstraintDialogText (frm->constraint_dlg);
22366   EnableSingleMacroActionAccept (frm);
22367 }
22368 
22369 
SingleMacroActionMsgFunc(OMMsgStructPtr ommsp)22370 static Int2 LIBCALLBACK SingleMacroActionMsgFunc (OMMsgStructPtr ommsp)
22371 
22372 {
22373   ObjMgrDataPtr   omdp;
22374   OMUserDataPtr   omudp;
22375   OneMacroActionPtr frm;
22376 
22377   omudp = (OMUserDataPtr)(ommsp->omuserdata);
22378   if (omudp == NULL) return OM_MSG_RET_ERROR;
22379   frm = (OneMacroActionPtr) omudp->userdata.ptrvalue;
22380   if (frm == NULL) return OM_MSG_RET_ERROR;
22381   switch (ommsp->message) {
22382     case OM_MSG_DEL:
22383       omdp = ObjMgrGetData (ommsp->entityID);
22384       if (omdp != NULL) {
22385         if (ObjMgrWholeEntity (omdp, ommsp->itemID, ommsp->itemtype)) {
22386           /* clear text here */
22387           SendMessageToDialog (frm->action_dlgs[1], NUM_VIB_MSG + 1);
22388           return OM_MSG_RET_OK;
22389         }
22390       }
22391       break;
22392     default :
22393       break;
22394   }
22395   return OM_MSG_RET_OK;
22396 }
22397 
22398 
SingleMacroActionFormMessage(ForM f,Int2 mssg)22399 static void SingleMacroActionFormMessage (ForM f, Int2 mssg)
22400 {
22401   OneMacroActionPtr frm;
22402 
22403   frm = (OneMacroActionPtr) GetObjectExtra (f);
22404   if (frm != NULL) {
22405     switch (mssg) {
22406       case VIB_MSG_ACCEPT :
22407         SingleMacroAcceptButton (frm->accept_btn);
22408         break;
22409       case VIB_MSG_CLOSE:
22410         RemoveMacroActionWindow ((WindoW)(frm->form));
22411         break;
22412       case VIB_MSG_ENTER :
22413         Select (f);
22414         Select (frm->single_field);
22415         break;
22416       default :
22417         break;
22418     }
22419   }
22420 }
22421 
22422 
22423 #ifndef WIN_MAC
CreateSingleMacroActionFormMenus(WindoW w)22424 static void CreateSingleMacroActionFormMenus (WindoW w)
22425 
22426 {
22427   BaseFormPtr   bfp;
22428   MenU          m;
22429 
22430   bfp = (BaseFormPtr) GetObjectExtra (w);
22431   if (bfp != NULL) {
22432     m = PulldownMenu (w, "File");
22433     FormCommandItem (m, "Accept", bfp, VIB_MSG_ACCEPT);
22434     FormCommandItem (m, "Cancel", bfp, VIB_MSG_CLOSE);
22435     m = PulldownMenu (w, "Edit");
22436     FormCommandItem (m, CUT_MENU_ITEM, bfp, VIB_MSG_CUT);
22437     FormCommandItem (m, COPY_MENU_ITEM, bfp, VIB_MSG_COPY);
22438     FormCommandItem (m, PASTE_MENU_ITEM, bfp, VIB_MSG_PASTE);
22439     FormCommandItem (m, CLEAR_MENU_ITEM, bfp, VIB_MSG_DELETE);
22440   }
22441 }
22442 #endif
22443 
22444 
22445 /* for executing macro actions without creating a macro script */
22446 NLM_EXTERN ForM
SingleMacroAction(Uint2 entityID,Boolean indexer_version)22447 SingleMacroAction (Uint2 entityID, Boolean indexer_version)
22448 {
22449   WindoW                w;
22450   GrouP                 h, g5, c, field_grp, k, c1, not_constraint, split_grp;
22451   ButtoN                b, show_sample_btn;
22452   OneMacroActionPtr     frm;
22453   Int4                  i;
22454   ValNodePtr            val_list = NULL;
22455   Char                  tmpval[30];
22456   OMUserDataPtr         omudp;
22457 
22458   frm = (OneMacroActionPtr) MemNew (sizeof (OneMacroActionData));
22459 
22460   w = FixedWindow(-20, -13, -10, -10, "Edit Action", RemoveMacroActionWindow);
22461   SetObjectExtra (w, frm, NULL);
22462 
22463   frm->form = (ForM) w;
22464   frm->input_entityID = entityID;
22465   frm->toform = ActionToSingleMacroActionForm;
22466   frm->formmessage = SingleMacroActionFormMessage;
22467   frm->indexer_version = indexer_version;
22468 
22469   frm->win_num = AddMacroActionWindow (w);
22470 
22471   /* register to receive update messages */
22472   frm->userkey = OMGetNextUserKey ();
22473   frm->procid = 0;
22474   frm->proctype = OMPROC_EDIT;
22475   omudp = ObjMgrAddUserData (0, 0, frm->proctype, frm->userkey);
22476   if (omudp != NULL) {
22477     omudp->userdata.ptrvalue = (Pointer) frm;
22478     omudp->messagefunc = SingleMacroActionMsgFunc;
22479   }
22480 
22481   h = HiddenGroup (w, -1, 0, NULL);
22482   SetGroupSpacing (h, 10, 10);
22483 
22484   frm->action_type = PopupList (h, TRUE, ChangeSingleMacroActionPopup);
22485   SetObjectExtra (frm->action_type, frm, NULL);
22486   for (i = 0; i < NUM_AECR_ACTIONS; i++) {
22487     PopupItem (frm->action_type, action_names[i]);
22488   }
22489   SetValue (frm->action_type, 1);
22490   frm->prev_action_type = 1;
22491   frm->clear_on_change = CheckBox (h, "Clear when changing actions", NULL);
22492 
22493   split_grp = h;
22494 
22495   not_constraint = HiddenGroup (split_grp, -1, 0, NULL);
22496   SetGroupSpacing (not_constraint, 10, 10);
22497   field_grp = HiddenGroup (not_constraint, 0, 0, NULL);
22498   frm->single_field_grp = HiddenGroup (field_grp, -1, 0, NULL);
22499 
22500   ValNodeAddPointer (&val_list, FieldType_source_qual, StringSave ("Source Qual"));
22501   ValNodeAddPointer (&val_list, FieldType_feature_field, StringSave ("Feature Qual"));
22502   ValNodeAddPointer (&val_list, FieldType_cds_gene_prot, StringSave ("CDS-Gene-Prot Qual"));
22503   ValNodeAddPointer (&val_list, FieldType_rna_field, StringSave ("RNA Qual"));
22504   ValNodeAddPointer (&val_list, FieldType_molinfo_field, StringSave ("MolInfo Qual"));
22505   ValNodeAddPointer (&val_list, FieldType_pub, StringSave ("Pub Field"));
22506   ValNodeAddPointer (&val_list, FieldType_struc_comment_field, StringSave ("Structured Comment Field"));
22507   ValNodeAddPointer (&val_list, FieldType_dblink, StringSave ("DBLink Field"));
22508   ValNodeAddPointer (&val_list, FieldType_misc, StringSave ("Misc"));
22509 
22510   frm->single_qual_type_dlg = ValNodeSelectionDialog (frm->single_field_grp, val_list, TALL_SELECTION_LIST, ValNodeStringName,
22511                                 ValNodeSimpleDataFree, ValNodeStringCopy,
22512                                 ValNodeChoiceMatch, "field type",
22513                                 ChangeQualType, frm, FALSE);
22514   val_list = NULL;
22515   k = HiddenGroup (frm->single_field_grp, 0, 0, NULL);
22516   frm->single_field = FieldTypeDialog (k, FALSE, FALSE, ChangeSingleMacroActionFieldChoice, frm);
22517   frm->single_field_remove = FieldTypeDialog (k, FALSE, TRUE, ChangeSingleMacroActionFieldChoice, frm);
22518   AlignObjects (ALIGN_CENTER, (HANDLE) frm->single_field, (HANDLE) frm->single_field_remove, NULL);
22519   AlignObjects (ALIGN_CENTER, (HANDLE) frm->single_qual_type_dlg, (HANDLE) k, NULL);
22520 
22521   frm->field_pair_grp = HiddenGroup (field_grp, -1, 0, NULL);
22522   ValNodeAddPointer (&val_list, FieldType_source_qual, StringSave ("Source Qual"));
22523   ValNodeAddPointer (&val_list, FieldType_feature_field, StringSave ("Feature Qual"));
22524   ValNodeAddPointer (&val_list, FieldType_cds_gene_prot, StringSave ("CDS-Gene-Prot Qual"));
22525   ValNodeAddPointer (&val_list, FieldType_rna_field, StringSave ("RNA Qual"));
22526   ValNodeAddPointer (&val_list, FieldType_molinfo_field, StringSave ("MolInfo Qual"));
22527   ValNodeAddPointer (&val_list, FieldType_dblink, StringSave ("DBLink Field"));
22528   frm->pair_qual_type_dlg = ValNodeSelectionDialog (frm->field_pair_grp, val_list, TALL_SELECTION_LIST, ValNodeStringName,
22529                                 ValNodeSimpleDataFree, ValNodeStringCopy,
22530                                 ValNodeChoiceMatch, "field type",
22531                                 ChangeQualType, frm, FALSE);
22532   val_list = NULL;
22533 
22534   k = HiddenGroup (frm->field_pair_grp, 0, 0, NULL);
22535   frm->field_pair = FieldPairTypeDialog (k, FALSE, ChangeSingleMacroActionFieldChoice, frm);
22536   frm->field_pair_convert = FieldPairTypeDialog (k, TRUE, ChangeSingleMacroActionFieldChoice, frm);
22537   AlignObjects (ALIGN_CENTER, (HANDLE) frm->field_pair_convert, (HANDLE) frm->field_pair, NULL);
22538   AlignObjects (ALIGN_CENTER, (HANDLE) frm->pair_qual_type_dlg, (HANDLE) k, NULL);
22539 
22540   AlignObjects (ALIGN_CENTER, (HANDLE) frm->single_field_grp, (HANDLE) frm->field_pair_grp, NULL);
22541 
22542   Hide (frm->single_field_grp);
22543   Hide (frm->field_pair_grp);
22544 
22545   g5 = HiddenGroup (not_constraint, 0, 0, NULL);
22546   /* temporarily shut off callbacks */
22547   frm->no_callback = TRUE;
22548   frm->action_dlgs[0] = ApplyActionDialog (g5, frm->indexer_version, FALSE, (Nlm_ChangeNotifyProc) AutopopulateSingleMacroDialog, frm, EnableSingleMacroActionAccept, frm, EnableSingleMacroActionAccept, frm);
22549   SetAECRActionDlgFieldTypeDialogs (frm->action_dlgs[0], frm->single_qual_type_dlg, frm->single_field);
22550   frm->action_dlgs[1] = EditActionDialog (g5, frm->indexer_version, (Nlm_ChangeNotifyProc) AutopopulateSingleMacroDialog, frm, EnableSingleMacroActionAccept, frm, EnableSingleMacroActionAccept, frm);
22551   SetAECRActionDlgFieldTypeDialogs (frm->action_dlgs[1], frm->single_qual_type_dlg, frm->single_field);
22552   frm->action_dlgs[2] = ConvertActionDialog (g5, frm->indexer_version, FALSE, EnableSingleMacroActionAccept, frm, EnableSingleMacroActionAccept, frm);
22553   SetAECRActionDlgFieldTypeDialogs (frm->action_dlgs[2], frm->pair_qual_type_dlg, frm->field_pair_convert);
22554   frm->action_dlgs[3] = CopyActionDialog (g5, frm->indexer_version, FALSE, EnableSingleMacroActionAccept, frm, EnableSingleMacroActionAccept, frm);
22555   SetAECRActionDlgFieldTypeDialogs (frm->action_dlgs[3], frm->pair_qual_type_dlg, frm->field_pair);
22556   frm->action_dlgs[4] = SwapActionDialog (g5, frm->indexer_version, EnableSingleMacroActionAccept, frm, EnableSingleMacroActionAccept, frm);
22557   SetAECRActionDlgFieldTypeDialogs (frm->action_dlgs[4], frm->pair_qual_type_dlg, frm->field_pair);
22558   frm->action_dlgs[5] = AECRParseActionDialog (g5, frm->indexer_version, FALSE, EnableSingleMacroActionAccept, frm, EnableSingleMacroActionAccept, frm);
22559   SetAECRActionDlgFieldTypeDialogs (frm->action_dlgs[5], frm->pair_qual_type_dlg, frm->field_pair);
22560   frm->action_dlgs[6] = RemoveActionDialog (g5, frm->indexer_version, EnableSingleMacroActionAccept, frm, EnableSingleMacroActionAccept, frm);
22561   SetAECRActionDlgFieldTypeDialogs (frm->action_dlgs[6], frm->single_qual_type_dlg, frm->single_field_remove);
22562   frm->action_dlgs[7] = RemoveOutsideActionDialog (g5, frm->indexer_version, (Nlm_ChangeNotifyProc) AutopopulateSingleMacroDialog, frm, EnableSingleMacroActionAccept, frm, EnableSingleMacroActionAccept, frm);
22563   SetAECRActionDlgFieldTypeDialogs (frm->action_dlgs[7], frm->single_qual_type_dlg, frm->single_field);
22564   AlignObjects (ALIGN_CENTER, (HANDLE) frm->action_dlgs[0],
22565                               (HANDLE) frm->action_dlgs[1],
22566                               (HANDLE) frm->action_dlgs[2],
22567                               (HANDLE) frm->action_dlgs[3],
22568                               (HANDLE) frm->action_dlgs[4],
22569                               (HANDLE) frm->action_dlgs[5],
22570                               (HANDLE) frm->action_dlgs[6],
22571                               (HANDLE) frm->action_dlgs[7],
22572                               NULL);
22573 
22574   /* set default autopopulate value */
22575   if (GetAppParam ("SEQUINCUSTOM", "BATCHDIALOG", "AUTOPOPULATE", NULL, tmpval, sizeof (tmpval))
22576         && StringICmp (tmpval, "TRUE") == 0) {
22577     SetAutopopulateStatus (frm->action_dlgs[0], TRUE);
22578     SetAutopopulateStatus (frm->action_dlgs[1], TRUE);
22579   } else {
22580     SetAutopopulateStatus (frm->action_dlgs[0], FALSE);
22581     SetAutopopulateStatus (frm->action_dlgs[1], FALSE);
22582   }
22583 
22584   frm->also_change_mrna = CheckBox (not_constraint, "Make mRNA product match CDS protein name", NULL);
22585   Hide (frm->also_change_mrna);
22586 
22587   AlignObjects (ALIGN_CENTER, (HANDLE) field_grp, (HANDLE) g5, (HANDLE) frm->also_change_mrna, NULL);
22588 
22589   frm->constraint_dlg = ComplexConstraintDialog (split_grp, EnableSingleMacroActionAccept, frm);
22590 
22591   c1 = HiddenGroup (h, 4, 0, NULL);
22592   show_sample_btn = PushButton (c1, "Show Sample", ShowMacroSampleWindow);
22593   SetObjectExtra (show_sample_btn, frm, NULL);
22594   b = PushButton (c1, "Clear", ClearSingleMacroAction);
22595   SetObjectExtra (b, frm, NULL);
22596   b = PushButton (c1, "Clear Text", ClearTextSingleMacroAction);
22597   SetObjectExtra (b, frm, NULL);
22598   frm->leave_dlg_up = CheckBox (c1, "Leave dialog up", NULL);
22599 
22600 
22601   c = HiddenGroup (h, 4, 0, NULL);
22602   SetGroupSpacing (c, 10, 10);
22603   frm->accept_btn = DefaultButton (c, "Accept", SingleMacroAcceptButton);
22604   SetObjectExtra (frm->accept_btn, frm, NULL);
22605   b = PushButton (c, "Cancel", SingleMacroCancelButton);
22606   SetObjectExtra (b, frm, NULL);
22607 
22608   AlignObjects (ALIGN_CENTER, (HANDLE) frm->action_type,
22609                               (HANDLE) frm->clear_on_change,
22610                               (HANDLE) not_constraint,
22611                               (HANDLE) frm->constraint_dlg,
22612                               (HANDLE) c1,
22613                               (HANDLE) c,
22614                               NULL);
22615 
22616 #ifndef WIN_MAC
22617   CreateSingleMacroActionFormMenus (w);
22618 #endif
22619 
22620   /* turn callbacks back on */
22621   frm->no_callback = FALSE;
22622   ChangeSingleMacroActionPopup (frm->action_type);
22623 
22624   return (ForM) w;
22625 }
22626 
22627 
22628 
SingleAECRMacroAction(Uint2 entityID,Boolean indexer_version,Uint1 AECR_action_type,Uint1 AECR_qual_type)22629 NLM_EXTERN void SingleAECRMacroAction (Uint2 entityID, Boolean indexer_version, Uint1 AECR_action_type, Uint1 AECR_qual_type)
22630 {
22631   ForM f;
22632   ValNodePtr action;
22633 
22634   f = SingleMacroAction (entityID, indexer_version);
22635   action = ValNodeNew (NULL);
22636   action->choice = MacroActionChoice_aecr;
22637   action->data.ptrvalue = BuildDefaultAECRAction (AECR_action_type, AECR_qual_type);
22638   PointerToForm (f, action);
22639   action = MacroActionChoiceFree (action);
22640 
22641   Show (f);
22642   Select (f);
22643   SendMessageToForm (f, VIB_MSG_ENTER);
22644 }
22645 
22646 
22647 typedef struct genericmacroaction {
22648   FORM_MESSAGE_BLOCK
22649 
22650   DialoG action_dlg;
22651   Int4   action_type;
22652 
22653   ButtoN accept_btn;
22654   ButtoN leave_dlg_up;
22655 
22656   Boolean indexer_version;
22657 } GenericMacroActionData, PNTR GenericMacroActionPtr;
22658 
22659 
GenericMacroAcceptButton(ButtoN b)22660 static void GenericMacroAcceptButton (ButtoN b)
22661 {
22662   GenericMacroActionPtr frm;
22663   ValNodePtr            macro;
22664   SeqEntryPtr           sep;
22665 
22666   frm = (GenericMacroActionPtr) GetObjectExtra (b);
22667   if (frm == NULL) {
22668     return;
22669   }
22670 
22671   macro = ValNodeNew (NULL);
22672   macro->choice = frm->action_type;
22673   macro->data.ptrvalue = DialogToPointer (frm->action_dlg);
22674 
22675   sep = GetTopSeqEntryForEntityID (frm->input_entityID);
22676   ApplyMacroToSeqEntryEx (sep, macro, NULL, Sequin_GlobalAlign2Seq);
22677   ObjMgrSetDirtyFlag (frm->input_entityID, TRUE);
22678   ObjMgrSendMsg (OM_MSG_UPDATE, frm->input_entityID, 0, 0);
22679   if (!GetStatus (frm->leave_dlg_up)) {
22680     Remove (frm->form);
22681   }
22682   Update ();
22683 }
22684 
22685 
GenericMacroActionForm(Uint2 entityID,ValNodePtr action,Boolean indexer_version)22686 NLM_EXTERN void GenericMacroActionForm (Uint2 entityID, ValNodePtr action, Boolean indexer_version)
22687 {
22688   WindoW                w;
22689   GrouP                 h, c;
22690   ButtoN                b;
22691   GenericMacroActionPtr frm;
22692   Int4                  i;
22693 
22694   if (action == NULL) {
22695     return;
22696   }
22697   for (i = 0; i < NUM_MacroPopup; i++) {
22698     if (s_MacroPopupList[i].action_choice == action->choice) {
22699       break;
22700     }
22701   }
22702 
22703   if (i >= NUM_MacroPopup || s_MacroPopupList[i].dialog_func == NULL) {
22704     Message (MSG_ERROR, "Dialog not implemented yet");
22705     return;
22706   }
22707 
22708   frm = (GenericMacroActionPtr) MemNew (sizeof (GenericMacroActionData));
22709 
22710   w = FixedWindow(-20, -13, -10, -10, s_MacroPopupList[i].popup_label, StdCloseWindowProc);
22711   SetObjectExtra (w, frm, NULL);
22712 
22713   frm->form = (ForM) w;
22714   frm->input_entityID = entityID;
22715   frm->indexer_version = indexer_version;
22716   frm->action_type = action->choice;
22717 
22718   h = HiddenGroup (w, -1, 0, NULL);
22719   SetGroupSpacing (h, 10, 10);
22720 
22721   frm->action_dlg = s_MacroPopupList[i].dialog_func (h, indexer_version, NULL, NULL);
22722   PointerToDialog (frm->action_dlg, action->data.ptrvalue);
22723 
22724   c = HiddenGroup (h, 4, 0, NULL);
22725   SetGroupSpacing (c, 10, 10);
22726   frm->accept_btn = PushButton (c, "Accept", GenericMacroAcceptButton);
22727   SetObjectExtra (frm->accept_btn, frm, NULL);
22728   b = PushButton (c, "Cancel", StdCancelButtonProc);
22729   SetObjectExtra (b, frm, NULL);
22730   frm->leave_dlg_up = CheckBox (c, "Leave dialog up", NULL);
22731 
22732   AlignObjects (ALIGN_CENTER, (HANDLE) frm->action_dlg,
22733                               (HANDLE) c,
22734                               NULL);
22735 
22736   Show (w);
22737   Select (w);
22738 }
22739 
22740 
MacroApplyKeyword(Uint2 entityID,Boolean indexer_version)22741 NLM_EXTERN void MacroApplyKeyword (Uint2 entityID, Boolean indexer_version)
22742 {
22743   ForM f;
22744   ValNodePtr action;
22745   AECRActionPtr aecr;
22746   ApplyActionPtr apply;
22747 
22748   f = SingleMacroAction (entityID, indexer_version);
22749   action = ValNodeNew (NULL);
22750   action->choice = MacroActionChoice_aecr;
22751 
22752   aecr = AECRActionNew ();
22753   aecr->action = ValNodeNew (NULL);
22754   aecr->action->choice = ActionChoice_apply;
22755   apply = ApplyActionNew ();
22756   apply->field = ValNodeNew (NULL);
22757   apply->field->choice = FieldType_misc;
22758   apply->field->data.intvalue = Misc_field_keyword;
22759   apply->value = StringSave ("");
22760   apply->existing_text = ExistingTextOption_add_qual;
22761   aecr->action->data.ptrvalue = apply;
22762   action->data.ptrvalue = aecr;
22763   PointerToForm (f, action);
22764   action = MacroActionChoiceFree (action);
22765 
22766   Show (f);
22767   Select (f);
22768 }
22769 
22770 
22771 typedef struct singleparseactionfrm {
22772   FORM_MESSAGE_BLOCK
22773   DialoG dlg;
22774   ButtoN leave_dlg_up;
22775   ButtoN accept_btn;
22776 } SingleParseActionFrmData, PNTR SingleParseActionFrmPtr;
22777 
22778 
ChangeSingleParseAction(Pointer data)22779 static void ChangeSingleParseAction (Pointer data)
22780 {
22781   SingleParseActionFrmPtr frm;
22782   ValNodePtr err_list;
22783 
22784   frm = (SingleParseActionFrmPtr) data;
22785   if (frm == NULL) {
22786     return;
22787   }
22788 
22789   /* enable or disable accept button */
22790   err_list = TestDialog (frm->dlg);
22791   if (err_list == NULL) {
22792     Enable (frm->accept_btn);
22793   } else {
22794     Disable (frm->accept_btn);
22795   }
22796   err_list = ValNodeFree (err_list);
22797 }
22798 
22799 
ClearSingleParseAction(ButtoN b)22800 static void ClearSingleParseAction (ButtoN b)
22801 {
22802   SingleParseActionFrmPtr frm;
22803 
22804   frm = (SingleParseActionFrmPtr) GetObjectExtra (b);
22805   if (frm == NULL) {
22806     return;
22807   }
22808 
22809   PointerToDialog (frm->dlg, NULL);
22810   ChangeSingleParseAction (frm);
22811 }
22812 
22813 
ClearTextSingleParseAction(ButtoN b)22814 static void ClearTextSingleParseAction (ButtoN b)
22815 {
22816   SingleParseActionFrmPtr frm;
22817   ParseActionPtr parse;
22818 
22819   frm = (SingleParseActionFrmPtr) GetObjectExtra (b);
22820   if (frm == NULL) {
22821     return;
22822   }
22823 
22824   parse = DialogToPointer (frm->dlg);
22825 
22826   if (parse != NULL && parse->portion != NULL) {
22827     parse->portion->left_marker = TextMarkerFree (parse->portion->left_marker);
22828     parse->portion->right_marker = TextMarkerFree (parse->portion->right_marker);
22829     PointerToDialog (frm->dlg, parse);
22830     parse = ParseActionFree (parse);
22831     ChangeSingleParseAction (frm);
22832   }
22833 }
22834 
22835 
ActionToSingleParseActionForm(ForM f,Pointer data)22836 static void ActionToSingleParseActionForm (ForM f, Pointer data)
22837 {
22838   SingleParseActionFrmPtr frm;
22839   ParseActionPtr          parse;
22840 
22841 
22842   frm = (SingleParseActionFrmPtr) GetObjectExtra (f);
22843   if (frm == NULL) return;
22844 
22845   parse = (ParseActionPtr) data;
22846 
22847   PointerToDialog (frm->dlg, parse);
22848   ChangeSingleParseAction (frm);
22849 }
22850 
22851 
FormToParseAction(ForM f)22852 static Pointer FormToParseAction (ForM f)
22853 {
22854   SingleParseActionFrmPtr frm;
22855   ParseActionPtr          parse;
22856 
22857 
22858   frm = (SingleParseActionFrmPtr) GetObjectExtra (f);
22859   if (frm == NULL) return NULL;
22860 
22861   parse = DialogToPointer (frm->dlg);
22862   return parse;
22863 }
22864 
22865 
22866 
SingleParseAcceptButton(ButtoN b)22867 static void SingleParseAcceptButton (ButtoN b)
22868 {
22869   SingleParseActionFrmPtr frm;
22870   ParseActionPtr          parse;
22871   AECRSamplePtr           sample;
22872   SeqEntryPtr             sep;
22873   ValNodePtr              vnp;
22874 
22875   frm = (SingleParseActionFrmPtr) GetObjectExtra (b);
22876   if (frm == NULL) {
22877     return;
22878   }
22879 
22880   sep = GetTopSeqEntryForEntityID (frm->input_entityID);
22881 
22882   parse = DialogToPointer (frm->dlg);
22883   if (parse == NULL) {
22884     return;
22885   }
22886 
22887   /* check for existing text, then set value in parse*/
22888   sample = GetExistingTextForParseAction (parse, sep);
22889   if (sample != NULL && sample->num_found > 0) {
22890     parse->existing_text = TwoStepExistingText (sample->num_found, FALSE, FALSE);
22891   } else {
22892     parse->existing_text = ExistingTextOption_replace_old;
22893   }
22894   sample = AECRSampleFree (sample);
22895   if (parse->existing_text == 0) {
22896     parse = ParseActionFree (parse);
22897     return;
22898   }
22899 
22900   vnp = ValNodeNew (NULL);
22901   vnp->choice = MacroActionChoice_parse;
22902   vnp->data.ptrvalue = parse;
22903 
22904   ApplyMacroToSeqEntryEx (sep, vnp, NULL, Sequin_GlobalAlign2Seq);
22905 
22906   vnp = MacroActionChoiceFree (vnp);
22907 
22908   ObjMgrSetDirtyFlag (frm->input_entityID, TRUE);
22909   ObjMgrSendMsg (OM_MSG_UPDATE, frm->input_entityID, 0, 0);
22910   if (!GetStatus (frm->leave_dlg_up)) {
22911     Remove (frm->form);
22912   }
22913   Update ();
22914 }
22915 
22916 
22917 /* todo - later allow different starting setups */
SingleParseAction(Uint2 entityID)22918 NLM_EXTERN ForM SingleParseAction (Uint2 entityID)
22919 {
22920   WindoW                w;
22921   GrouP                 h, c, c1;
22922   ButtoN                b;
22923   SingleParseActionFrmPtr frm;
22924   SeqEntryPtr             sep;
22925 
22926   frm = (SingleParseActionFrmPtr) MemNew (sizeof (SingleParseActionFrmData));
22927 
22928   w = FixedWindow(-20, -13, -10, -10, "Parse Text", StdCloseWindowProc);
22929   SetObjectExtra (w, frm, NULL);
22930 
22931   frm->form = (ForM) w;
22932   frm->input_entityID = entityID;
22933   frm->toform = ActionToSingleParseActionForm;
22934   frm->fromform = FormToParseAction;
22935 
22936   h = HiddenGroup (w, -1, 0, NULL);
22937   SetGroupSpacing (h, 10, 10);
22938 
22939   sep = GetTopSeqEntryForEntityID (entityID);
22940 
22941   frm->dlg = ParseActionDialogEx (h, FALSE, FALSE, ChangeSingleParseAction, frm, sep);
22942 
22943   c1 = HiddenGroup (h, 3, 0, NULL);
22944   b = PushButton (c1, "Clear", ClearSingleParseAction);
22945   SetObjectExtra (b, frm, NULL);
22946   b = PushButton (c1, "Clear Text", ClearTextSingleParseAction);
22947   SetObjectExtra (b, frm, NULL);
22948   frm->leave_dlg_up = CheckBox (c1, "Leave dialog up", NULL);
22949 
22950 
22951   c = HiddenGroup (h, 4, 0, NULL);
22952   SetGroupSpacing (c, 10, 10);
22953   frm->accept_btn = PushButton (c, "Accept", SingleParseAcceptButton);
22954   SetObjectExtra (frm->accept_btn, frm, NULL);
22955   b = PushButton (c, "Cancel", StdCancelButtonProc);
22956 
22957   AlignObjects (ALIGN_CENTER, (HANDLE) frm->dlg,
22958                               (HANDLE) c1,
22959                               (HANDLE) c,
22960                               NULL);
22961 
22962   return (ForM) w;
22963 
22964 }
22965 
22966 
22967 /* For applying selected actions from a macro script */
22968 typedef struct macrorunform {
22969   FORM_MESSAGE_BLOCK
22970   DoC        macro_summary;
22971   FonT       summary_font;
22972 
22973   ValNodePtr macro_list;
22974   BoolPtr    ok_to_run;
22975   Int4       num_actions;
22976 } MacroRunFormData, PNTR MacroRunFormPtr;
22977 
22978 
CleanupMacroRunForm(GraphiC g,VoidPtr data)22979 static void CleanupMacroRunForm (GraphiC g, VoidPtr data)
22980 
22981 {
22982   MacroRunFormPtr f;
22983 
22984   f = (MacroRunFormPtr) data;
22985   if (f != NULL) {
22986     f->macro_list = MacroActionListFree (f->macro_list);
22987     f->ok_to_run = MemFree (f->ok_to_run);
22988   }
22989   StdCleanupFormProc (g, data);
22990 }
22991 
ClickMacroRunDoc(DoC d,PoinT pt)22992 static void ClickMacroRunDoc (DoC d, PoinT pt)
22993 {
22994   Int2            item, row, col;
22995   RecT            rct;
22996   MacroRunFormPtr f;
22997 
22998   f = (MacroRunFormPtr) GetObjectExtra (d);
22999   if (f == NULL) return;
23000 
23001   MapDocPoint (d, pt, &item, &row, &col, &rct);
23002   if (item > 0 && item <= f->num_actions && col == 1) {
23003     /* check or uncheck item */
23004     if (f->ok_to_run[item - 1]) {
23005       f->ok_to_run[item - 1] = FALSE;
23006     } else {
23007       f->ok_to_run[item - 1] = TRUE;
23008     }
23009     InvalDocument (f->macro_summary);
23010   }
23011 }
23012 
23013 
DrawMacroRunControls(DoC d,RectPtr r,Int2 item,Int2 firstLine)23014 static void DrawMacroRunControls (DoC d, RectPtr r, Int2 item, Int2 firstLine)
23015 
23016 {
23017   MacroRunFormPtr dlg;
23018   RecT            rct;
23019   Int4            width;
23020   PoinT           pt1, pt2;
23021 
23022   dlg = (MacroRunFormPtr) GetObjectExtra (d);
23023   if (dlg == NULL) return;
23024   /* don't draw controls for explanatory text */
23025   if (item == 0 || item > dlg->num_actions) return;
23026 
23027   if (dlg != NULL && r != NULL && item > 0 && item <= dlg->num_actions && firstLine == 0) {
23028     rct = *r;
23029 
23030     width = 10;
23031     /* draw box */
23032     pt1.x = rct.left + 1;
23033     pt1.y = rct.top + 1;
23034     pt2.x = pt1.x + width;
23035     pt2.y = pt1.y;
23036     DrawLine (pt1, pt2);
23037     pt1.x = pt2.x;
23038     pt1.y = pt2.y + width;
23039     DrawLine (pt1, pt2);
23040     pt2.x = pt1.x - width;
23041     pt2.y = pt1.y;
23042     DrawLine (pt1, pt2);
23043     pt1.x = pt2.x;
23044     pt1.y = pt2.y - width;
23045     DrawLine (pt1, pt2);
23046 
23047     if (dlg->ok_to_run[item - 1]) {
23048       /* draw X for check */
23049       pt1.x = rct.left + 1;
23050       pt1.y = rct.top + 1;
23051       pt2.x = pt1.x + width;
23052       pt2.y = pt1.y + width;
23053       DrawLine (pt1, pt2);
23054       pt1.x = rct.left + 1;
23055       pt1.y = rct.top + 1 + width;
23056       pt2.x = pt1.x + width;
23057       pt2.y = rct.top + 1;
23058       DrawLine (pt1, pt2);
23059     }
23060   }
23061 }
23062 
23063 
RunSelectedMacro(ButtoN b)23064 static void RunSelectedMacro (ButtoN b)
23065 {
23066   MacroRunFormPtr  f;
23067   ValNodePtr       vnp, tmp_list = NULL, last = NULL, newaction, tmp;
23068   Int4             i;
23069   ValNodePtr       sep_list;
23070   LogInfoPtr       lip;
23071   SeqEntryPtr      sep;
23072   Uint2            entityID;
23073   Int4             num_no_op = 0, tmp_num;
23074 
23075   f = (MacroRunFormPtr) GetObjectExtra (b);
23076   if (f == NULL) {
23077     return;
23078   }
23079 
23080   /* make temporary macro list */
23081   for (vnp = f->macro_list, i = 0; vnp != NULL && i < f->num_actions; vnp = vnp->next, i++) {
23082     if (f->ok_to_run[i]) {
23083       tmp = vnp->next;
23084       vnp->next = NULL;
23085       newaction = AsnIoMemCopy (vnp, (AsnReadFunc) MacroActionListAsnRead, (AsnWriteFunc) MacroActionListAsnWrite);
23086       vnp->next = tmp;
23087       if (last == NULL) {
23088         tmp_list = newaction;
23089       } else {
23090         last->next = newaction;
23091       }
23092       last = newaction;
23093     }
23094   }
23095 
23096   if (tmp_list == NULL) {
23097     Message (MSG_ERROR, "No actions selected!");
23098     return;
23099   }
23100 
23101   /* run it */
23102   sep_list = GetViewedSeqEntryList ();
23103   if (sep_list == NULL) {
23104     Message (MSG_ERROR, "No records open!");
23105   } else if (sep_list->next != NULL
23106     && ANS_CANCEL == Message (MSG_OKC, "You have more than one record open - run macro for all open records?")) {
23107     /* do nothing */
23108   } else {
23109     WatchCursor();
23110     Update();
23111     lip = OpenLog ("Macro Actions");
23112     for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
23113       sep = vnp->data.ptrvalue;
23114       entityID = ObjMgrGetEntityIDForChoice(sep);
23115       lip->data_in_log |= ApplyMacroToSeqEntryExEx (sep, tmp_list, lip->fp, Sequin_GlobalAlign2Seq, &tmp_num);
23116       num_no_op += tmp_num;
23117       ObjMgrSetDirtyFlag (entityID, TRUE);
23118       ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
23119     }
23120     sep_list = ValNodeFree (sep_list);
23121     ArrowCursor ();
23122     Update ();
23123     /* show log from actions */
23124     if (lip->data_in_log) {
23125       if (num_no_op > 0) {
23126         fprintf (lip->fp, "%d actions had no effect.\n", num_no_op);
23127       }
23128     } else {
23129       fprintf (lip->fp, "Macro had no effect\n");
23130       lip->data_in_log = TRUE;
23131     }
23132     MakeMacroReportWindow (lip);
23133     lip = FreeLog (lip);
23134   }
23135   /* free temporary macro list */
23136   tmp_list = MacroActionListFree (tmp_list);
23137 }
23138 
23139 
PrintMacroList(ButtoN b)23140 static void PrintMacroList(ButtoN b)
23141 {
23142   MacroRunFormPtr  f;
23143   ValNodePtr       vnp;
23144   CharPtr          str;
23145   Char             path [PATH_MAX];
23146   FILE * fp;
23147 
23148   f = (MacroRunFormPtr) GetObjectExtra (b);
23149   if (f == NULL) {
23150     return;
23151   }
23152 
23153   TmpNam (path);
23154   fp = FileOpen (path, "w");
23155   if (fp != NULL) {
23156     for (vnp = f->macro_list; vnp != NULL; vnp = vnp->next) {
23157       str = SummarizeMacroAction (vnp);
23158       fprintf (fp, "%s\n", str == NULL ? "Unknown action" : str);
23159       str = MemFree (str);
23160     }
23161     FileClose (fp);
23162     LaunchGeneralTextViewer (path, "Autofix");
23163   }
23164   FileRemove (path);
23165 }
23166 
23167 
SummarizeRunMacro(DoC doc,ValNodePtr macro_list,FonT font)23168 static void SummarizeRunMacro (DoC doc, ValNodePtr macro_list, FonT font)
23169 {
23170   ValNodePtr vnp;
23171   CharPtr    str;
23172   CharPtr    tmp;
23173   RecT       r;
23174   ParData    ParFmt = {FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0};
23175   ColData    ColFmt[] =
23176   {
23177     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
23178     {0, 0, 80, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, TRUE}
23179   };
23180 
23181 
23182   Reset (doc);
23183 
23184   ObjectRect (doc, &r);
23185   InsetRect (&r, 4, 4);
23186 
23187   ColFmt[1].pixWidth = r.right - r.left - 12;
23188 
23189   if (font == NULL) font = programFont;
23190 
23191   for (vnp = macro_list; vnp != NULL; vnp = vnp->next) {
23192     str = SummarizeMacroAction (vnp);
23193     tmp = (CharPtr) MemNew (sizeof (Char) * (StringLen (str) + 6));
23194     sprintf (tmp, "\t%s\n", str);
23195     str = MemFree (str);
23196     AppendText (doc, tmp, &ParFmt, ColFmt, font);
23197     tmp = MemFree (tmp);
23198   }
23199   UpdateDocument (doc, 0, 0);
23200 }
23201 
23202 
SelectiveMacroRun(ValNodePtr macro_list)23203 NLM_EXTERN void SelectiveMacroRun (ValNodePtr macro_list)
23204 {
23205   WindoW           w;
23206   MacroRunFormPtr  f;
23207   GrouP            h, c;
23208   ButtoN           b;
23209   Int4             i;
23210 
23211   if (macro_list == NULL) {
23212     return;
23213   }
23214   f = (MacroRunFormPtr) MemNew (sizeof (MacroRunFormData));
23215   if (f == NULL) return;
23216 
23217   w = FixedWindow (-50, -33, -10, -10, "Autofix", StdCloseWindowProc);
23218   SetObjectExtra (w, f, CleanupMacroRunForm);
23219   f->form = (ForM) w;
23220 
23221   f->macro_list = macro_list;
23222   f->num_actions = ValNodeLen (macro_list);
23223   f->ok_to_run = (BoolPtr) MemNew (sizeof (Boolean) * f->num_actions);
23224   /* by default, run everything */
23225   for (i = 0; i < f->num_actions; i++) {
23226     f->ok_to_run[i] = TRUE;
23227   }
23228 
23229   /* set up font */
23230 #ifdef WIN_MAC
23231   f->summary_font = ParseFont ("Times,12");
23232 #endif
23233 #ifdef WIN_MSWIN
23234   f->summary_font = ParseFont ("Times New Roman,12");
23235 #endif
23236 #ifdef WIN_MOTIF
23237   f->summary_font = ParseFont ("Times,12");
23238 #endif
23239 
23240   h = HiddenGroup (w, -1, 0, NULL);
23241   SetGroupSpacing (h, 10, 10);
23242 
23243   f->macro_summary = DocumentPanel (h, stdCharWidth * 50, stdLineHeight * 30);
23244   SetObjectExtra (f->macro_summary, f, NULL);
23245   SetDocProcs (f->macro_summary, ClickMacroRunDoc, NULL, NULL, NULL);
23246   SetDocShade (f->macro_summary, DrawMacroRunControls, NULL, NULL, NULL);
23247 
23248   c = HiddenGroup (h, 3, 0, NULL);
23249   b = PushButton (c, "Run", RunSelectedMacro);
23250   SetObjectExtra (b, f, NULL);
23251   b = PushButton (c, "Print Macro List", PrintMacroList);
23252   SetObjectExtra (b, f, NULL);
23253   b = PushButton (c, "Close", StdCancelButtonProc);
23254 
23255   AlignObjects (ALIGN_CENTER, (HANDLE) f->macro_summary, (HANDLE) c, NULL);
23256   SummarizeRunMacro (f->macro_summary, f->macro_list, f->summary_font);
23257   Show (w);
23258 }
23259 
23260 
23261 typedef struct structuredcommentdatabasenamedialog {
23262   DIALOG_MESSAGE_BLOCK
23263 
23264   DialoG known_names;
23265   TexT   new_name;
23266   GrouP  known_or_new;
23267 
23268   ValNodePtr prefix_list;  /* note - prefix_list will be freed by the known_names dialg */
23269   Nlm_ChangeNotifyProc     change_notify;
23270   Pointer                  change_userdata;
23271 } StructuredCommentDatabaseNameDlgData, PNTR StructuredCommentDatabaseNameDlgPtr;
23272 
23273 
ChangeStructuredCommentDatabaseNameNewOrKnown(GrouP g)23274 static void ChangeStructuredCommentDatabaseNameNewOrKnown(GrouP g)
23275 {
23276   StructuredCommentDatabaseNameDlgPtr dlg;
23277 
23278   dlg = (StructuredCommentDatabaseNameDlgPtr) GetObjectExtra (g);
23279   if (dlg == NULL) {
23280     return;
23281   }
23282 
23283   if (GetValue (dlg->known_or_new) == 1) {
23284     Enable (dlg->known_names);
23285     Disable (dlg->new_name);
23286   } else {
23287     Enable (dlg->known_names);
23288     Disable (dlg->new_name);
23289   }
23290   if (dlg->change_notify != NULL) {
23291     (dlg->change_notify) (dlg->change_userdata);
23292   }
23293 }
23294 
23295 
StructuredCommentDatabaseNameToDialog(DialoG d,Pointer data)23296 static void StructuredCommentDatabaseNameToDialog (DialoG d, Pointer data)
23297 {
23298   StructuredCommentDatabaseNameDlgPtr dlg;
23299   ValNodePtr vnp;
23300   CharPtr    str = (CharPtr) data;
23301   ValNode    vn;
23302   Boolean    is_known = FALSE;
23303 
23304   dlg = (StructuredCommentDatabaseNameDlgPtr) GetObjectExtra (d);
23305   if (dlg == NULL) {
23306     return;
23307   }
23308 
23309   if (str == NULL) {
23310     PointerToDialog (dlg->known_names, NULL);
23311     SetTitle (dlg->new_name, "");
23312     SetValue (dlg->known_or_new, 2);
23313     ChangeStructuredCommentDatabaseNameNewOrKnown (dlg->known_or_new);
23314   } else {
23315     /* first, determine if known or unknown */
23316     for (vnp = dlg->prefix_list; vnp != NULL && !is_known; vnp = vnp->next) {
23317       if (StringCmp ((CharPtr) vnp->data.ptrvalue, str) == 0) {
23318         is_known = TRUE;
23319       }
23320     }
23321     if (is_known) {
23322       MemSet (&vn, 0, sizeof (ValNode));
23323       vn.data.ptrvalue = str;
23324       PointerToDialog (dlg->known_names, &vn);
23325       SetTitle (dlg->new_name, "");
23326       SetValue (dlg->known_or_new, 1);
23327     } else {
23328       PointerToDialog (dlg->known_names, NULL);
23329       SetTitle (dlg->new_name, str == NULL ? "" : str);
23330       SetValue (dlg->known_or_new, 2);
23331     }
23332     ChangeStructuredCommentDatabaseNameNewOrKnown (dlg->known_or_new);
23333   }
23334 }
23335 
23336 
StructuredCommentDatabaseNameFromDialog(DialoG d)23337 static Pointer StructuredCommentDatabaseNameFromDialog (DialoG d)
23338 {
23339   StructuredCommentDatabaseNameDlgPtr dlg;
23340   ValNodePtr vnp;
23341   CharPtr    str = NULL;
23342 
23343   dlg = (StructuredCommentDatabaseNameDlgPtr) GetObjectExtra (d);
23344   if (dlg == NULL) {
23345     return NULL;
23346   }
23347 
23348   if (GetValue(dlg->known_or_new) == 1) {
23349     vnp = DialogToPointer (dlg->known_names);
23350     if (vnp != NULL) {
23351       str = StringSave (vnp->data.ptrvalue);
23352     }
23353   } else {
23354     str = SaveStringFromText (dlg->new_name);
23355   }
23356   return str;
23357 }
23358 
23359 
ChangeStructuredCommentDatabaseNameText(TexT t)23360 static void ChangeStructuredCommentDatabaseNameText(TexT t)
23361 {
23362   StructuredCommentDatabaseNameDlgPtr dlg;
23363 
23364   dlg = (StructuredCommentDatabaseNameDlgPtr) GetObjectExtra (t);
23365   if (dlg == NULL) {
23366     return;
23367   }
23368 
23369   if (dlg->change_notify != NULL) {
23370     (dlg->change_notify) (dlg->change_userdata);
23371   }
23372 }
23373 
23374 
StructuredCommentDatabaseNameDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)23375 NLM_EXTERN DialoG StructuredCommentDatabaseNameDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
23376 {
23377   StructuredCommentDatabaseNameDlgPtr dlg;
23378   GrouP p;
23379 
23380   dlg = (StructuredCommentDatabaseNameDlgPtr) MemNew (sizeof (StructuredCommentDatabaseNameDlgData));
23381 
23382   p = HiddenGroup (h, -1, 0, NULL);
23383   SetObjectExtra (p, dlg, StdCleanupExtraProc);
23384 
23385   dlg->dialog = (DialoG) p;
23386   dlg->fromdialog = StructuredCommentDatabaseNameFromDialog;
23387   dlg->todialog = StructuredCommentDatabaseNameToDialog;
23388   dlg->change_notify = change_notify;
23389   dlg->change_userdata = change_userdata;
23390 
23391   dlg->known_or_new = HiddenGroup (p, 0, 2, ChangeStructuredCommentDatabaseNameNewOrKnown);
23392   SetObjectExtra (dlg->known_or_new, dlg, NULL);
23393   SetGroupSpacing (dlg->known_or_new, 10, 10);
23394   RadioButton (dlg->known_or_new, "Known");
23395   RadioButton (dlg->known_or_new, "New");
23396   dlg->prefix_list = GetStructuredCommentPrefixList();
23397   dlg->known_names = ValNodeSelectionDialog (dlg->known_or_new,
23398                                              dlg->prefix_list,
23399                                              TALL_SELECTION_LIST,
23400                                              ValNodeStringName,
23401                                              ValNodeSimpleDataFree,
23402                                              ValNodeStringCopy,
23403                                              ValNodeStringMatch,
23404                                              "dbname",
23405                                              change_notify, change_userdata, FALSE);
23406   dlg->new_name = DialogText (dlg->known_or_new, "", 10, ChangeStructuredCommentDatabaseNameText);
23407   SetObjectExtra (dlg->new_name, dlg, NULL);
23408   SetValue (dlg->known_or_new, 2);
23409   Disable (dlg->known_names);
23410 
23411   return (DialoG) p;
23412 }
23413 
23414 
23415 /* for editing macro "templates" where we only want to change the values */
23416 /* any action that we don't have a template editor for, just print a string describing the action */
23417 
23418 typedef struct macrotemplatestringdlg {
23419   DIALOG_MESSAGE_BLOCK
23420   DoC summ;
23421   ValNodePtr original_action;
23422 } MacroTemplateStringDlgData, PNTR MacroTemplateStringDlgPtr;
23423 
23424 
MacroFromMacroTemplateStringDialog(DialoG d)23425 static Pointer MacroFromMacroTemplateStringDialog (DialoG d)
23426 {
23427   MacroTemplateStringDlgPtr dlg;
23428 
23429   dlg = (MacroTemplateStringDlgPtr) GetObjectExtra (d);
23430   if (dlg == NULL) {
23431     return NULL;
23432   }
23433 
23434   return AsnIoMemCopy (dlg->original_action, (AsnReadFunc) MacroActionChoiceAsnRead, (AsnWriteFunc) MacroActionChoiceAsnWrite);
23435 }
23436 
23437 
MacroToMacroTemplateStringDialog(DialoG d,Pointer data)23438 static void MacroToMacroTemplateStringDialog (DialoG d, Pointer data)
23439 {
23440   MacroTemplateStringDlgPtr dlg;
23441   CharPtr summ;
23442 
23443   dlg = (MacroTemplateStringDlgPtr) GetObjectExtra (d);
23444   if (dlg == NULL) {
23445     return;
23446   }
23447   dlg->original_action = (ValNodePtr) data;
23448 
23449   summ = SummarizeMacroAction (dlg->original_action);
23450   Reset(dlg->summ);
23451   AppendText (dlg->summ, summ, NULL, NULL, programFont);
23452   summ = MemFree (summ);
23453 }
23454 
23455 
MacroTemplateStringDialog(GrouP h)23456 NLM_EXTERN DialoG MacroTemplateStringDialog (GrouP h)
23457 {
23458   MacroTemplateStringDlgPtr dlg;
23459   GrouP p;
23460 
23461   dlg = (MacroTemplateStringDlgPtr) MemNew (sizeof (MacroTemplateStringDlgData));
23462 
23463   p = HiddenGroup (h, -1, 0, NULL);
23464   SetObjectExtra (p, dlg, StdCleanupExtraProc);
23465 
23466   dlg->dialog = (DialoG) p;
23467   dlg->fromdialog = MacroFromMacroTemplateStringDialog;
23468   dlg->todialog = MacroToMacroTemplateStringDialog;
23469 
23470   dlg->summ = DocumentPanel (p, stdCharWidth * 50, stdLineHeight * 1);
23471 
23472 
23473   return (DialoG) p;
23474 }
23475 
23476 
23477 typedef struct macrotemplateapplytextdlg {
23478   DIALOG_MESSAGE_BLOCK
23479   DoC summ;
23480   TexT text;
23481   ValNodePtr original_action;
23482 } MacroTemplateApplyTextDlgData, PNTR MacroTemplateApplyTextDlgPtr;
23483 
23484 
MacroFromMacroTemplateApplyTextDialog(DialoG d)23485 static Pointer MacroFromMacroTemplateApplyTextDialog (DialoG d)
23486 {
23487   MacroTemplateApplyTextDlgPtr dlg;
23488   ValNodePtr macro;
23489   AECRActionPtr action;
23490   ApplyActionPtr apply;
23491 
23492   dlg = (MacroTemplateApplyTextDlgPtr) GetObjectExtra (d);
23493   if (dlg == NULL) {
23494     return NULL;
23495   }
23496 
23497   macro = AsnIoMemCopy (dlg->original_action, (AsnReadFunc) MacroActionChoiceAsnRead, (AsnWriteFunc) MacroActionChoiceAsnWrite);
23498   if (macro != NULL && macro->choice == MacroActionChoice_aecr
23499       && (action = (AECRActionPtr) macro->data.ptrvalue) != NULL
23500       && action->action != NULL
23501       && action->action->choice == ActionChoice_apply
23502       && (apply = (ApplyActionPtr) action->action->data.ptrvalue) != NULL) {
23503     apply->value = MemFree (apply->value);
23504     apply->value = JustSaveStringFromText (dlg->text);
23505   }
23506   return macro;
23507 }
23508 
23509 
MacroToMacroTemplateApplyTextDialog(DialoG d,Pointer data)23510 static void MacroToMacroTemplateApplyTextDialog (DialoG d, Pointer data)
23511 {
23512   MacroTemplateApplyTextDlgPtr dlg;
23513   ValNodePtr macro;
23514   AECRActionPtr action;
23515   ApplyActionPtr apply;
23516   CharPtr field, existing, constraint;
23517   CharPtr fmt = "to %s (%s)";
23518   CharPtr summ;
23519 
23520   dlg = (MacroTemplateApplyTextDlgPtr) GetObjectExtra (d);
23521   if (dlg == NULL) {
23522     return;
23523   }
23524   dlg->original_action = (ValNodePtr) data;
23525   macro = dlg->original_action;
23526 
23527   Reset(dlg->summ);
23528   if ((macro = (ValNodePtr)data) == NULL || macro->choice != MacroActionChoice_aecr
23529       || (action = (AECRActionPtr) macro->data.ptrvalue) == NULL
23530       || action->action == NULL
23531       || action->action->choice != ActionChoice_apply
23532       || (apply = (ApplyActionPtr) action->action->data.ptrvalue) == NULL
23533       || IsNonTextFieldType(apply->field)) {
23534     SetTitle (dlg->text, "");
23535   } else {
23536     SetTitle (dlg->text, apply->value);
23537     field = SummarizeFieldType (apply->field);
23538     existing = SummarizeExistingText (apply->existing_text);
23539     constraint = SummarizeConstraintSet (action->constraint);
23540     summ = (CharPtr) MemNew (sizeof (Char) *
23541           (StringLen (fmt) + StringLen (field) + StringLen (existing) + StringLen (constraint)));
23542     sprintf (summ, fmt, field, existing);
23543     if (constraint != NULL) {
23544       StringCat (summ, constraint);
23545     }
23546     field = MemFree (field);
23547     constraint = MemFree (constraint);
23548     AppendText (dlg->summ, summ, NULL, NULL, programFont);
23549     summ = MemFree (summ);
23550   }
23551 }
23552 
23553 
MacroTemplateApplyTextDialog(GrouP h)23554 NLM_EXTERN DialoG MacroTemplateApplyTextDialog (GrouP h)
23555 {
23556   MacroTemplateApplyTextDlgPtr dlg;
23557   GrouP p;
23558 
23559   dlg = (MacroTemplateApplyTextDlgPtr) MemNew (sizeof (MacroTemplateApplyTextDlgData));
23560 
23561   p = HiddenGroup (h, 3, 0, NULL);
23562   SetObjectExtra (p, dlg, StdCleanupExtraProc);
23563 
23564   dlg->dialog = (DialoG) p;
23565   dlg->fromdialog = MacroFromMacroTemplateApplyTextDialog;
23566   dlg->todialog = MacroToMacroTemplateApplyTextDialog;
23567 
23568   StaticPrompt (p, "Apply", 0, popupMenuHeight, programFont, 'r');
23569   dlg->text = DialogText (p, "", 15, NULL);
23570   dlg->summ = DocumentPanel (p, stdCharWidth * 35, stdLineHeight * 1);
23571 
23572   return (DialoG) p;
23573 }
23574 
23575 
IsTextApply(ValNodePtr macro)23576 static Boolean IsTextApply (ValNodePtr macro)
23577 {
23578   AECRActionPtr action;
23579   ApplyActionPtr apply;
23580 
23581   if (macro == NULL || macro->choice != MacroActionChoice_aecr
23582       || (action = (AECRActionPtr) macro->data.ptrvalue) == NULL
23583       || action->action == NULL
23584       || action->action->choice != ActionChoice_apply
23585       || (apply = (ApplyActionPtr) action->action->data.ptrvalue) == NULL
23586       || IsNonTextFieldType(apply->field)) {
23587     return FALSE;
23588   } else {
23589     return TRUE;
23590   }
23591 }
23592 
23593 
23594 typedef struct macrotemplateform {
23595   FORM_MESSAGE_BLOCK
23596 
23597   DialoG PNTR action_dlgs;
23598   ButtoN PNTR keep_btn;
23599 
23600   Int4 num_actions;
23601 } MacroTemplateFormData, PNTR MacroTemplateFormPtr;
23602 
CleanupMacroTemplateForm(GraphiC g,VoidPtr data)23603 static void CleanupMacroTemplateForm (GraphiC g, VoidPtr data)
23604 
23605 {
23606   MacroTemplateFormPtr f;
23607 
23608   f = (MacroTemplateFormPtr) data;
23609   if (f != NULL) {
23610     f->action_dlgs = MemFree (f->action_dlgs);
23611   }
23612   StdCleanupFormProc (g, data);
23613 }
23614 
23615 
RunTemplateMacro(ButtoN b)23616 static void RunTemplateMacro (ButtoN b)
23617 {
23618   ValNodePtr actions = NULL, last_action = NULL, new_action, vnp, sep_list;
23619   MacroTemplateFormPtr  f;
23620   SeqEntryPtr sep;
23621   LogInfoPtr lip;
23622   Uint2 entityID;
23623   Int4  i;
23624   Int4  num_no_op = 0, tmp;
23625 
23626   f = (MacroTemplateFormPtr) GetObjectExtra (b);
23627   if (f == NULL) {
23628     return;
23629   }
23630   for (i = 0; i < f->num_actions; i++) {
23631     if (GetStatus (f->keep_btn[i])) {
23632       new_action = DialogToPointer (f->action_dlgs[i]);
23633       if (new_action != NULL) {
23634         if (last_action == NULL) {
23635           actions = new_action;
23636         } else {
23637           last_action->next = new_action;
23638         }
23639         last_action = new_action;
23640       }
23641     }
23642   }
23643   /* run it */
23644   sep_list = GetViewedSeqEntryList ();
23645   if (sep_list == NULL) {
23646     Message (MSG_ERROR, "No records open!");
23647   } else if (sep_list->next != NULL
23648     && ANS_CANCEL == Message (MSG_OKC, "You have more than one record open - run macro for all open records?")) {
23649     /* do nothing */
23650   } else {
23651     WatchCursor();
23652     Update();
23653     lip = OpenLog ("Macro Actions");
23654     for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
23655       sep = vnp->data.ptrvalue;
23656       entityID = ObjMgrGetEntityIDForChoice(sep);
23657       lip->data_in_log |= ApplyMacroToSeqEntryExEx (sep, actions, lip->fp, Sequin_GlobalAlign2Seq, &tmp);
23658       num_no_op += tmp;
23659       ObjMgrSetDirtyFlag (entityID, TRUE);
23660       ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
23661     }
23662     sep_list = ValNodeFree (sep_list);
23663     ArrowCursor ();
23664     Update ();
23665     /* show log from actions */
23666     if (lip->data_in_log) {
23667       if (num_no_op > 0) {
23668         fprintf (lip->fp, "%d actions had no effect.\n", num_no_op);
23669       }
23670     } else {
23671       fprintf (lip->fp, "Macro had no effect\n");
23672       lip->data_in_log = TRUE;
23673     }
23674     MakeMacroReportWindow (lip);
23675     lip = FreeLog (lip);
23676   }
23677   /* free temporary macro list */
23678   actions = MacroActionListFree (actions);
23679 
23680 }
23681 
23682 
SaveTemplateValues(ButtoN b)23683 static void SaveTemplateValues (ButtoN b)
23684 {
23685   ValNodePtr actions = NULL, last_action = NULL, new_action;
23686   MacroTemplateFormPtr  f;
23687   Int4 i;
23688   Char             path [PATH_MAX];
23689   AsnIoPtr         aip;
23690 
23691   f = (MacroTemplateFormPtr) GetObjectExtra (b);
23692   if (f == NULL) {
23693     return;
23694   }
23695   for (i = 0; i < f->num_actions; i++) {
23696     new_action = DialogToPointer (f->action_dlgs[i]);
23697     if (new_action != NULL) {
23698       if (last_action == NULL) {
23699         actions = new_action;
23700       } else {
23701         last_action->next = new_action;
23702       }
23703       last_action = new_action;
23704     }
23705   }
23706   path [0] = '\0';
23707   if (GetOutputFileName (path, sizeof (path), NULL)) {
23708     aip = AsnIoOpen (path, "w");
23709     if (aip == NULL) {
23710       Message (MSG_ERROR, "Unable to open %s", path);
23711     } else {
23712       MacroActionListAsnWrite (actions, aip, NULL);
23713       AsnIoClose (aip);
23714     }
23715   }
23716   actions = MacroActionListFree (actions);
23717 }
23718 
23719 
EditMacroTemplate(void)23720 NLM_EXTERN void EditMacroTemplate (void)
23721 {
23722   WindoW           w;
23723   MacroTemplateFormPtr  f;
23724   GrouP            h, g, c;
23725   ButtoN           b;
23726   Int4             i;
23727   ValNodePtr       vnp;
23728   Char             path [PATH_MAX];
23729   AsnIoPtr         aip;
23730   ValNodePtr       macro_list;
23731 
23732   path [0] = '\0';
23733   if (!GetInputFileName (path, sizeof (path), NULL, "TEXT")) {
23734     return;
23735   } else if ((aip = AsnIoOpen (path, "r")) == NULL) {
23736     Message (MSG_ERROR, "Unable to open %s", path);
23737     return;
23738   } else if ((macro_list = MacroActionListAsnRead (aip, NULL)) == NULL) {
23739     Message (MSG_ERROR, "Unable to read action list from %s.", path);
23740     aip = AsnIoClose (aip);
23741     return;
23742   }
23743   AsnIoClose (aip);
23744 
23745   f = (MacroTemplateFormPtr) MemNew (sizeof (MacroTemplateFormData));
23746   if (f == NULL) return;
23747 
23748   w = FixedWindow (-50, -33, -10, -10, "Macro Template", StdCloseWindowProc);
23749   SetObjectExtra (w, f, CleanupMacroTemplateForm);
23750   f->form = (ForM) w;
23751 
23752   f->num_actions = ValNodeLen (macro_list);
23753   f->action_dlgs = (DialoG PNTR) MemNew (sizeof (DialoG) * f->num_actions);
23754   f->keep_btn = (ButtoN PNTR) MemNew (sizeof (ButtoN) * f->num_actions);
23755 
23756   h = HiddenGroup (w, -1, 0, NULL);
23757   SetGroupSpacing (h, 10, 10);
23758 
23759   g = HiddenGroup (h, 2, 0, NULL);
23760   for (i = 0, vnp = macro_list; i < f->num_actions && vnp != NULL; i++, vnp = vnp->next) {
23761     f->keep_btn[i] = CheckBox (g, "", NULL);
23762     SetStatus (f->keep_btn[i], TRUE);
23763     if (IsTextApply(vnp)) {
23764       f->action_dlgs[i] = MacroTemplateApplyTextDialog(g);
23765     } else {
23766       f->action_dlgs[i] = MacroTemplateStringDialog (g);
23767     }
23768     PointerToDialog (f->action_dlgs[i], vnp);
23769   }
23770 
23771   c = HiddenGroup (h, 3, 0, NULL);
23772   b = PushButton (c, "Run", RunTemplateMacro);
23773   SetObjectExtra (b, f, NULL);
23774   b = PushButton (c, "Save Template with New Values", SaveTemplateValues);
23775   SetObjectExtra (b, f, NULL);
23776   b = PushButton (c, "Close", StdCancelButtonProc);
23777 
23778   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, NULL);
23779   Show (w);
23780 }
23781 
23782 
LaunchMacroTemplateEditor(IteM i)23783 NLM_EXTERN void LaunchMacroTemplateEditor (IteM i)
23784 {
23785   BaseFormPtr         bfp;
23786 
23787 #ifdef WIN_MAC
23788   bfp = currentFormDataPtr;
23789 #else
23790   bfp = GetObjectExtra (i);
23791 #endif
23792   EditMacroTemplate ();
23793 }
23794 
23795 
23796 /* For using macro functions to apply tables */
23797 
23798 typedef struct idmatchlocationdlg {
23799   DIALOG_MESSAGE_BLOCK
23800   PopuP  match_location;
23801 
23802   Nlm_ChangeNotifyProc     change_notify;
23803   Pointer                  change_userdata;
23804 } IdMatchLocationDlgData, PNTR IdMatchLocationDlgPtr;
23805 
23806 
23807 typedef enum {
23808   eTabColumnConfigMatchLocation_equals = 1,
23809   eTabColumnConfigMatchLocation_contains,
23810   eTabColumnConfigMatchLocation_starts,
23811   eTabColumnConfigMatchLocation_ends,
23812   eTabColumnConfigMatchLocation_inlist
23813 } ETabColumnConfigMatchLocation;
23814 
23815 
StringConstraintLocationFromTabColumnConfigMatchLocation(Int2 i)23816 static Uint1 StringConstraintLocationFromTabColumnConfigMatchLocation (Int2 i)
23817 {
23818   Uint1 val = String_location_equals;
23819   switch (i) {
23820     case eTabColumnConfigMatchLocation_equals:
23821       val = String_location_equals;
23822       break;
23823     case eTabColumnConfigMatchLocation_contains:
23824       val = String_location_contains;
23825       break;
23826     case eTabColumnConfigMatchLocation_starts:
23827       val = String_location_starts;
23828       break;
23829     case eTabColumnConfigMatchLocation_ends:
23830       val = String_location_ends;
23831       break;
23832     case eTabColumnConfigMatchLocation_inlist:
23833       val = String_location_inlist;
23834       break;
23835     default:
23836       val = String_location_equals;
23837       break;
23838   }
23839   return val;
23840 }
23841 
23842 
TabColumnConfigMatchLocationFromStringConstraintLocation(Uint1 u)23843 static Int2 TabColumnConfigMatchLocationFromStringConstraintLocation (Uint1 u)
23844 {
23845   Int2 val = eTabColumnConfigMatchLocation_equals;
23846 
23847   switch (u) {
23848     case String_location_equals:
23849       val = eTabColumnConfigMatchLocation_equals;
23850       break;
23851     case String_location_contains:
23852       val = eTabColumnConfigMatchLocation_contains;
23853       break;
23854     case String_location_starts:
23855       val = eTabColumnConfigMatchLocation_starts;
23856       break;
23857     case String_location_ends:
23858       val = eTabColumnConfigMatchLocation_ends;
23859       break;
23860     case String_location_inlist:
23861       val = eTabColumnConfigMatchLocation_inlist;
23862       break;
23863     default:
23864       val = eTabColumnConfigMatchLocation_equals;
23865       break;
23866   }
23867   return val;
23868 }
23869 
23870 
ChangeIdMatchLocationPopup(PopuP p)23871 static void ChangeIdMatchLocationPopup (PopuP p)
23872 {
23873   IdMatchLocationDlgPtr dlg;
23874 
23875   dlg = (IdMatchLocationDlgPtr) GetObjectExtra (p);
23876   if (dlg == NULL) {
23877     return;
23878   }
23879 
23880   if (dlg->change_notify) {
23881     (dlg->change_notify)(dlg->change_userdata);
23882   }
23883 }
23884 
23885 
IdMatchLocationDlg(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)23886 NLM_EXTERN DialoG IdMatchLocationDlg (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
23887 {
23888   IdMatchLocationDlgPtr dlg;
23889   GrouP p;
23890 
23891   dlg = (IdMatchLocationDlgPtr) MemNew (sizeof (IdMatchLocationDlgData));
23892 
23893   p = HiddenGroup (h, -1, 0, NULL);
23894   SetObjectExtra (p, dlg, StdCleanupExtraProc);
23895 
23896   dlg->dialog = (DialoG) p;
23897   dlg->change_notify = change_notify;
23898   dlg->change_userdata = change_userdata;
23899   dlg->match_location = PopupList (p, TRUE, ChangeIdMatchLocationPopup);
23900   SetObjectExtra (dlg->match_location, dlg, NULL);
23901   PopupItem (dlg->match_location, "Matches");
23902   PopupItem (dlg->match_location, "Is contained in");
23903   PopupItem (dlg->match_location, "Is start of");
23904   PopupItem (dlg->match_location, "Is end of");
23905   PopupItem (dlg->match_location, "List contains");
23906   SetValue (dlg->match_location, 1);
23907 
23908   return (DialoG) p;
23909 }
23910 
23911 
GetMatchLocationFromIdMatchLocationDlg(DialoG d)23912 NLM_EXTERN Uint1 GetMatchLocationFromIdMatchLocationDlg (DialoG d)
23913 {
23914   IdMatchLocationDlgPtr dlg;
23915 
23916   dlg = (IdMatchLocationDlgPtr) GetObjectExtra (d);
23917   if (dlg == NULL) {
23918     return String_location_equals;
23919   }
23920 
23921   return StringConstraintLocationFromTabColumnConfigMatchLocation (GetValue (dlg->match_location));
23922 }
23923 
23924 
SetMatchLocationInIdMatchLocationDlg(DialoG d,Uint1 match_location)23925 NLM_EXTERN void SetMatchLocationInIdMatchLocationDlg (DialoG d, Uint1 match_location)
23926 {
23927   IdMatchLocationDlgPtr dlg;
23928 
23929   dlg = (IdMatchLocationDlgPtr) GetObjectExtra (d);
23930   if (dlg == NULL) {
23931     return;
23932   }
23933 
23934   SetValue (dlg->match_location, TabColumnConfigMatchLocationFromStringConstraintLocation (match_location));
23935 }
23936 
23937 
23938 /* for configuring how a column in a table will be used */
23939 typedef struct tabcolumnconfigdlg {
23940   DIALOG_MESSAGE_BLOCK
23941   LisT                     column_action;
23942   GrouP                    match_grp;
23943   DialoG                   match_location;
23944   DialoG                   src_qual_match;
23945   GrouP                    qual_grp;
23946   DialoG                   src_qual;
23947   GrouP                    feature_field_grp;
23948   DialoG                   feature_type;
23949   DialoG                   feature_field;
23950   DialoG                   cdsgeneprot;
23951   DialoG                   pub_field;
23952   DialoG                   molinfo_field;
23953   DialoG                   struccomm_field;
23954   PopuP                    dblink_field;
23955 
23956   ButtoN                   change_mrna;
23957   GrouP                    apply_options;
23958   ButtoN                   erase_when_blank;
23959   DialoG                   existing_text;
23960   DialoG                   constraint;
23961 
23962   Nlm_ChangeNotifyProc     change_notify;
23963   Pointer                  change_userdata;
23964 } TabColumnConfigDlgData, PNTR TabColumnConfigDlgPtr;
23965 
23966 typedef enum {
23967   eTabColumnConfig_Ignore = 1,
23968   eTabColumnConfig_Match_NucleotideID,
23969   eTabColumnConfig_Match_Taxname,
23970   eTabColumnConfig_Match_SourceQual,
23971   eTabColumnConfig_Match_FeatureID,
23972   eTabColumnConfig_Match_GeneLocusTag,
23973   eTabColumnConfig_Match_ProteinID,
23974   eTabColumnConfig_Match_ProteinName,  /* J. Chen */
23975   eTabColumnConfig_Match_Dbxref,
23976   eTabColumnConfig_Match_BioProject,
23977   eTabColumnConfig_Match_Any,
23978   eTabColumnConfig_Blank,
23979   eTabColumnConfig_Apply_Taxname,
23980   eTabColumnConfig_Apply_SourceQual,
23981   eTabColumnConfig_Apply_CDSGeneProtField,
23982   eTabColumnConfig_Apply_FeatureField,
23983   eTabColumnConfig_Apply_PubField,
23984   eTabColumnConfig_Apply_GenomeProjectId,
23985   eTabColumnConfig_Apply_CommentDescriptor,
23986   eTabColumnConfig_Apply_Defline,
23987   eTabColumnConfig_Apply_Keyword,
23988   eTabColumnConfig_Apply_Molinfo,
23989   eTabColumnConfig_Apply_StructuredCommentField,
23990   eTabColumnConfig_Apply_Dblink,
23991 } ETabColumnConfig;
23992 
TabColumnConfigFieldChange(Pointer data)23993 static void TabColumnConfigFieldChange (Pointer data)
23994 {
23995   TabColumnConfigDlgPtr dlg;
23996   TabColumnConfigPtr    config;
23997 
23998   dlg = (TabColumnConfigDlgPtr) data;
23999   if (dlg != NULL) {
24000     config = (TabColumnConfigPtr) DialogToPointer (dlg->dialog);
24001     if (config == NULL) {
24002       Disable (dlg->change_mrna);
24003       DisableNonTextOptions (dlg->existing_text);
24004       DisableMultiOptions (dlg->existing_text);
24005     } else {
24006       if (!IsFieldTypeCDSProduct(config->field)) {
24007         Disable (dlg->change_mrna);
24008       } else {
24009         Enable (dlg->change_mrna);
24010       }
24011       if (AllowFieldMulti (config->field)) {
24012         EnableMultiOptions (dlg->existing_text);
24013       } else {
24014         DisableMultiOptions (dlg->existing_text);
24015       }
24016     }
24017 
24018     config = TabColumnConfigFree (config);
24019     if (dlg->change_notify != NULL) {
24020       (dlg->change_notify) (dlg->change_userdata);
24021     }
24022   }
24023 }
24024 
24025 
TabColumnConfigDialogToChoice(DialoG d)24026 static Pointer TabColumnConfigDialogToChoice (DialoG d)
24027 {
24028   TabColumnConfigDlgPtr dlg;
24029   TabColumnConfigPtr    f;
24030   Int2                  val;
24031   FeatureFieldPtr       ff;
24032   ValNodePtr            vnp;
24033 
24034   dlg = (TabColumnConfigDlgPtr) GetObjectExtra (d);
24035   if (dlg == NULL) return NULL;
24036 
24037   f = TabColumnConfigNew ();
24038   f->match_mrna = FALSE;
24039 
24040   val = GetValue (dlg->column_action);
24041   if (val < 2 || val == eTabColumnConfig_Blank) {
24042     f = TabColumnConfigFree (f);
24043   } else if (val < eTabColumnConfig_Blank) {
24044     f->match_type = MatchTypeNew ();
24045     f->match_type->match_location = GetMatchLocationFromIdMatchLocationDlg (dlg->match_location);
24046     switch (val) {
24047       case eTabColumnConfig_Match_ProteinName:   /* J. Chen */
24048         f->match_type->choice = eTableMatchProteinName;
24049         break;
24050       case eTabColumnConfig_Match_FeatureID:
24051         f->match_type->choice = eTableMatchFeatureID;
24052         break;
24053       case eTabColumnConfig_Match_GeneLocusTag:
24054         f->match_type->choice = eTableMatchGeneLocusTag;
24055         break;
24056       case eTabColumnConfig_Match_ProteinID:
24057         f->match_type->choice = eTableMatchProteinID;
24058         break;
24059       case eTabColumnConfig_Match_Dbxref:
24060         f->match_type->choice = eTableMatchDbxref;
24061         break;
24062       case eTabColumnConfig_Match_NucleotideID:
24063         f->match_type->choice = eTableMatchNucID;
24064         break;
24065       case eTabColumnConfig_Match_Taxname:
24066         f->match_type->choice = eTableMatchBioSource;
24067         break;
24068       case eTabColumnConfig_Match_SourceQual:
24069         f->match_type->choice = eTableMatchSourceQual;
24070         f->match_type->data = DialogToPointer (dlg->src_qual_match);
24071         break;
24072       case eTabColumnConfig_Match_BioProject:
24073         f->match_type->choice = eTableMatchBioProject;
24074         break;
24075       case eTabColumnConfig_Match_Any:
24076         f->match_type->choice = eTableMatchAny;
24077         break;
24078       default:
24079         f->match_type = MatchTypeFree (f->match_type);
24080         break;
24081     }
24082     f->existing_text = ExistingTextOption_replace_old;
24083     f->skip_blank = TRUE;
24084   } else {
24085     if (val == eTabColumnConfig_Apply_Taxname) {
24086       vnp = ValNodeNew (NULL);
24087       vnp->choice = SourceQualChoice_textqual;
24088       vnp->data.intvalue = Source_qual_taxname;
24089       f->field = ValNodeNew (NULL);
24090       f->field->choice = FieldType_source_qual;
24091       f->field->data.ptrvalue = vnp;
24092     } else if (val == eTabColumnConfig_Apply_SourceQual) {
24093       f->field = ValNodeNew (NULL);
24094       f->field->choice = FieldType_source_qual;
24095       f->field->data.ptrvalue = DialogToPointer (dlg->src_qual);
24096     } else if (val == eTabColumnConfig_Apply_FeatureField) {
24097       f->field = ValNodeNew (NULL);
24098       f->field->choice = FieldType_feature_field;
24099       ff = FeatureFieldNew ();
24100       vnp = DialogToPointer (dlg->feature_type);
24101       if (vnp != NULL) {
24102         ff->type = vnp->choice;
24103         vnp = ValNodeFree (vnp);
24104       }
24105       vnp = DialogToPointer (dlg->feature_field);
24106       if (vnp != NULL) {
24107         ValNodeAddInt (&(ff->field), FeatQualChoice_legal_qual, vnp->choice);
24108         ValNodeFree (vnp);
24109       }
24110       f->field->data.ptrvalue = ff;
24111     } else if (val == eTabColumnConfig_Apply_CDSGeneProtField) {
24112       f->field = DialogToPointer (dlg->cdsgeneprot);
24113     } else if (val == eTabColumnConfig_Apply_PubField) {
24114       vnp = DialogToPointer (dlg->pub_field);
24115       if (vnp != NULL) {
24116         f->field = ValNodeNew (NULL);
24117         f->field->choice = FieldType_pub;
24118         f->field->data.intvalue = vnp->choice;
24119         vnp = ValNodeFree (vnp);
24120       }
24121     } else if (val == eTabColumnConfig_Apply_GenomeProjectId) {
24122       f->field = ValNodeNew (NULL);
24123       f->field->choice = FieldType_misc;
24124       f->field->data.intvalue = Misc_field_genome_project_id;
24125     } else if (val == eTabColumnConfig_Apply_CommentDescriptor) {
24126       f->field = ValNodeNew (NULL);
24127       f->field->choice = FieldType_misc;
24128       f->field->data.intvalue = Misc_field_comment_descriptor;
24129     } else if (val == eTabColumnConfig_Apply_Defline) {
24130       f->field = ValNodeNew (NULL);
24131       f->field->choice = FieldType_misc;
24132       f->field->data.intvalue = Misc_field_defline;
24133     } else if (val == eTabColumnConfig_Apply_Keyword) {
24134       f->field = ValNodeNew (NULL);
24135       f->field->choice = FieldType_misc;
24136       f->field->data.intvalue = Misc_field_keyword;
24137     } else if (val == eTabColumnConfig_Apply_Molinfo) {
24138       f->field = ValNodeNew (NULL);
24139       f->field->choice = FieldType_molinfo_field;
24140       f->field->data.ptrvalue = DialogToPointer (dlg->molinfo_field);
24141     } else if (val == eTabColumnConfig_Apply_StructuredCommentField) {
24142       f->field = ValNodeNew (NULL);
24143       f->field->choice = FieldType_struc_comment_field;
24144       f->field->data.ptrvalue = DialogToPointer (dlg->struccomm_field);
24145     } else if (val == eTabColumnConfig_Apply_Dblink) {
24146       f->field = ValNodeNew (NULL);
24147       f->field->choice = FieldType_dblink;
24148       f->field->data.intvalue = GetValue (dlg->dblink_field);
24149     }
24150 
24151 
24152     if (dlg->erase_when_blank == NULL) {
24153       f->skip_blank = TRUE;
24154     } else {
24155       f->skip_blank = !GetStatus (dlg->erase_when_blank);
24156     }
24157     if (IsFieldTypeCDSProduct (f->field)) {
24158       f->match_mrna = GetStatus (dlg->change_mrna);
24159     }
24160 
24161     f->existing_text = GetExistingTextDialogValue (dlg->existing_text);
24162     f->constraint = DialogToPointer (dlg->constraint);
24163   }
24164 
24165   return f;
24166 }
24167 
24168 
TabColumnActionChange(LisT p)24169 static void TabColumnActionChange (LisT p)
24170 {
24171   TabColumnConfigDlgPtr dlg;
24172   TabColumnConfigPtr    config;
24173   Int2 val;
24174 
24175   dlg = (TabColumnConfigDlgPtr) GetObjectExtra (p);
24176   if (dlg == NULL) return;
24177 
24178   Hide (dlg->dblink_field);
24179 
24180   val = GetValue (p);
24181 
24182   switch (val) {
24183     case eTabColumnConfig_Ignore:
24184     case eTabColumnConfig_Blank:
24185     case eTabColumnConfig_Match_FeatureID:
24186     case eTabColumnConfig_Match_GeneLocusTag:
24187     case eTabColumnConfig_Match_ProteinID:
24188     case eTabColumnConfig_Match_Dbxref:
24189     case eTabColumnConfig_Match_NucleotideID:
24190     case eTabColumnConfig_Match_Taxname:
24191     case eTabColumnConfig_Match_BioProject:
24192       /* matching, hide apply controls */
24193       Show (dlg->match_grp);
24194       Show (dlg->match_location);
24195       Hide (dlg->src_qual_match);
24196       Hide (dlg->qual_grp);
24197       Disable (dlg->apply_options);
24198       break;
24199     case eTabColumnConfig_Match_Any:
24200       /* matching, hide apply controls */
24201       Show (dlg->match_grp);
24202       Hide (dlg->match_location);
24203       Hide (dlg->src_qual_match);
24204       Hide (dlg->qual_grp);
24205       Disable (dlg->apply_options);
24206       break;
24207     case eTabColumnConfig_Match_SourceQual:
24208       /* matching to source qual, hide apply controls, show sourcequal match dialog */
24209       Hide (dlg->qual_grp);
24210       Disable (dlg->apply_options);
24211       Show (dlg->match_grp);
24212       Show (dlg->src_qual_match);
24213       break;
24214     case eTabColumnConfig_Apply_Taxname:
24215       /* choice is taxname, no need to show anything */
24216       Hide (dlg->qual_grp);
24217       Enable (dlg->apply_options);
24218       Hide (dlg->match_grp);
24219       EnableNonTextOptions (dlg->existing_text);
24220       break;
24221     case eTabColumnConfig_Apply_SourceQual:
24222       /* show source qual, hide others */
24223       Show (dlg->qual_grp);
24224       Show (dlg->src_qual);
24225       Hide (dlg->feature_field_grp);
24226       Hide (dlg->cdsgeneprot);
24227       Hide (dlg->pub_field);
24228       Hide (dlg->molinfo_field);
24229       Hide (dlg->struccomm_field);
24230       Disable (dlg->change_mrna);
24231       Enable (dlg->apply_options);
24232       Hide (dlg->match_grp);
24233       EnableNonTextOptions (dlg->existing_text);
24234       break;
24235     case eTabColumnConfig_Apply_FeatureField:
24236       /* show feature qual, hide others */
24237       Show (dlg->qual_grp);
24238       Hide (dlg->src_qual);
24239       Show (dlg->feature_field_grp);
24240       Hide (dlg->cdsgeneprot);
24241       Hide (dlg->pub_field);
24242       Hide (dlg->molinfo_field);
24243       Hide (dlg->struccomm_field);
24244       config = DialogToPointer (dlg->dialog);
24245       if (config == NULL || !IsFieldTypeCDSProduct (config->field)) {
24246         SafeDisable (dlg->change_mrna);
24247       } else {
24248         SafeEnable (dlg->change_mrna);
24249       }
24250       config = TabColumnConfigFree (config);
24251       Enable (dlg->apply_options);
24252       Hide (dlg->match_grp);
24253       EnableNonTextOptions (dlg->existing_text);
24254       break;
24255     case eTabColumnConfig_Apply_CDSGeneProtField:
24256       /* show cds-gene-prot qual, hide others */
24257       Show (dlg->qual_grp);
24258       Hide (dlg->src_qual);
24259       Hide (dlg->feature_field_grp);
24260       Show (dlg->cdsgeneprot);
24261       Hide (dlg->pub_field);
24262       Hide (dlg->molinfo_field);
24263       Hide (dlg->struccomm_field);
24264       config = DialogToPointer (dlg->dialog);
24265       if (config == NULL || !IsFieldTypeCDSProduct (config->field)) {
24266         SafeDisable (dlg->change_mrna);
24267       } else {
24268         SafeEnable (dlg->change_mrna);
24269       }
24270       config = TabColumnConfigFree (config);
24271       Enable (dlg->apply_options);
24272       Hide (dlg->match_grp);
24273       EnableNonTextOptions (dlg->existing_text);
24274       break;
24275     case eTabColumnConfig_Apply_PubField:
24276       Show (dlg->qual_grp);
24277       Hide (dlg->src_qual);
24278       Hide (dlg->feature_field_grp);
24279       Hide (dlg->cdsgeneprot);
24280       Show (dlg->pub_field);
24281       Hide (dlg->molinfo_field);
24282       Hide (dlg->struccomm_field);
24283       Enable (dlg->apply_options);
24284       Hide (dlg->match_grp);
24285       EnableNonTextOptions (dlg->existing_text);
24286       break;
24287     case eTabColumnConfig_Apply_GenomeProjectId:
24288     case eTabColumnConfig_Apply_CommentDescriptor:
24289     case eTabColumnConfig_Apply_Defline:
24290       Show (dlg->qual_grp);
24291       Hide (dlg->src_qual);
24292       Hide (dlg->feature_field_grp);
24293       Hide (dlg->cdsgeneprot);
24294       Hide (dlg->pub_field);
24295       Hide (dlg->molinfo_field);
24296       Hide (dlg->struccomm_field);
24297       Enable (dlg->apply_options);
24298       Hide (dlg->match_grp);
24299       Disable (dlg->change_mrna);
24300       DisableMultiOptions (dlg->existing_text);
24301       EnableNonTextOptions (dlg->existing_text);
24302       break;
24303     case eTabColumnConfig_Apply_Keyword:
24304       Show (dlg->qual_grp);
24305       Hide (dlg->src_qual);
24306       Hide (dlg->feature_field_grp);
24307       Hide (dlg->cdsgeneprot);
24308       Hide (dlg->pub_field);
24309       Hide (dlg->molinfo_field);
24310       Hide (dlg->struccomm_field);
24311       Enable (dlg->apply_options);
24312       Hide (dlg->match_grp);
24313       Disable (dlg->change_mrna);
24314       EnableMultiOptions (dlg->existing_text);
24315       EnableNonTextOptions (dlg->existing_text);
24316       break;
24317     case eTabColumnConfig_Apply_Molinfo:
24318       Show (dlg->qual_grp);
24319       Hide (dlg->src_qual);
24320       Hide (dlg->feature_field_grp);
24321       Hide (dlg->cdsgeneprot);
24322       Hide (dlg->pub_field);
24323       Show (dlg->molinfo_field);
24324       Hide (dlg->struccomm_field);
24325       Enable (dlg->apply_options);
24326       Hide (dlg->match_grp);
24327       Disable (dlg->change_mrna);
24328       DisableMultiOptions (dlg->existing_text);
24329       DisableNonTextOptions (dlg->existing_text);
24330       break;
24331     case eTabColumnConfig_Apply_StructuredCommentField:
24332       Show (dlg->qual_grp);
24333       Hide (dlg->src_qual);
24334       Hide (dlg->feature_field_grp);
24335       Hide (dlg->cdsgeneprot);
24336       Hide (dlg->pub_field);
24337       Hide (dlg->molinfo_field);
24338       Show (dlg->struccomm_field);
24339       Enable (dlg->apply_options);
24340       Hide (dlg->match_grp);
24341       Disable (dlg->change_mrna);
24342       DisableMultiOptions (dlg->existing_text);
24343       EnableNonTextOptions (dlg->existing_text);
24344       break;
24345     case eTabColumnConfig_Apply_Dblink:
24346       Show (dlg->qual_grp);
24347       Show (dlg->dblink_field);
24348       Hide (dlg->src_qual);
24349       Hide (dlg->feature_field_grp);
24350       Hide (dlg->cdsgeneprot);
24351       Hide (dlg->pub_field);
24352       Hide (dlg->molinfo_field);
24353       Hide (dlg->struccomm_field);
24354       Enable (dlg->apply_options);
24355       Hide (dlg->match_grp);
24356       Disable (dlg->change_mrna);
24357       EnableMultiOptions (dlg->existing_text);
24358       DisableNonTextOptions (dlg->existing_text);
24359       break;
24360   }
24361   if (dlg != NULL && dlg->change_notify != NULL) {
24362     (dlg->change_notify) (dlg->change_userdata);
24363   }
24364 }
24365 
24366 
TabColumnConfigToDialog(DialoG d,Pointer data)24367 static void TabColumnConfigToDialog (DialoG d, Pointer data)
24368 {
24369   TabColumnConfigDlgPtr dlg;
24370   TabColumnConfigPtr    f;
24371   FeatureFieldPtr       ff;
24372   ValNode               vn;
24373   ValNodePtr            src_field;
24374 
24375   dlg = (TabColumnConfigDlgPtr) GetObjectExtra (d);
24376   if (dlg == NULL) return;
24377   f = (TabColumnConfigPtr) data;
24378   if (f == NULL) {
24379     SetValue (dlg->column_action, 1);
24380     PointerToDialog (dlg->constraint, NULL);
24381   } else {
24382     f = TabColumnConfigCopy (f);
24383     if (f->match_type != NULL) {
24384       switch (f->match_type->choice) {
24385         case eTableMatchProteinName:    /* J. Chen */
24386           SetValue (dlg->column_action, eTabColumnConfig_Match_ProteinName);
24387           break;
24388         case eTableMatchFeatureID:
24389           SetValue (dlg->column_action, eTabColumnConfig_Match_FeatureID);
24390           break;
24391         case eTableMatchGeneLocusTag:
24392           SetValue (dlg->column_action, eTabColumnConfig_Match_GeneLocusTag);
24393           break;
24394         case eTableMatchProteinID:
24395           SetValue (dlg->column_action, eTabColumnConfig_Match_ProteinID);
24396           break;
24397         case eTableMatchDbxref:
24398           SetValue (dlg->column_action, eTabColumnConfig_Match_Dbxref);
24399           SetMatchLocationInIdMatchLocationDlg (dlg->match_location, f->match_type->match_location);
24400           break;
24401         case eTableMatchNucID:
24402           SetValue (dlg->column_action, eTabColumnConfig_Match_NucleotideID);
24403           break;
24404         case eTableMatchBioSource:
24405           SetValue (dlg->column_action, eTabColumnConfig_Match_Taxname);
24406           SetMatchLocationInIdMatchLocationDlg (dlg->match_location, f->match_type->match_location);
24407           break;
24408         case eTableMatchSourceQual:
24409           SetValue (dlg->column_action, eTabColumnConfig_Match_SourceQual);
24410           PointerToDialog (dlg->src_qual_match, f->match_type->data);
24411           SetMatchLocationInIdMatchLocationDlg (dlg->match_location, f->match_type->match_location);
24412           break;
24413         case eTableMatchBioProject:
24414           SetValue (dlg->column_action, eTabColumnConfig_Match_BioProject);
24415           break;
24416         case eTableMatchAny:
24417           SetValue (dlg->column_action, eTabColumnConfig_Match_Any);
24418           break;
24419       }
24420       PointerToDialog (dlg->constraint, NULL);
24421     } else if (f->field == NULL) {
24422       SetValue (dlg->column_action, eTabColumnConfig_Ignore);
24423       PointerToDialog (dlg->constraint, NULL);
24424     } else {
24425       if (f->field->choice == FieldType_source_qual) {
24426         src_field = f->field->data.ptrvalue;
24427         if (src_field != NULL
24428             && src_field->choice == SourceQualChoice_textqual
24429             && src_field->data.intvalue == Source_qual_taxname) {
24430           SetValue (dlg->column_action, eTabColumnConfig_Apply_Taxname);
24431         } else {
24432           SetValue (dlg->column_action, eTabColumnConfig_Apply_SourceQual);
24433           PointerToDialog (dlg->src_qual, f->field->data.ptrvalue);
24434         }
24435       } else if (f->field->choice == FieldType_feature_field) {
24436         SetValue (dlg->column_action, eTabColumnConfig_Apply_FeatureField);
24437         ff = (FeatureFieldPtr) f->field->data.ptrvalue;
24438         if (ff == NULL) {
24439           PointerToDialog (dlg->feature_type, NULL);
24440           PointerToDialog (dlg->feature_field, NULL);
24441         } else {
24442           vn.choice = (Uint1) ff->type;
24443           vn.data.ptrvalue = NULL;
24444           vn.next = NULL;
24445           PointerToDialog (dlg->feature_type, &vn);
24446           if (ff->field == NULL || ff->field->choice != FeatQualChoice_legal_qual) {
24447             PointerToDialog (dlg->feature_field, NULL);
24448           } else {
24449             vn.choice = ff->field->data.intvalue;
24450             vn.data.ptrvalue = NULL;
24451             vn.next = NULL;
24452             PointerToDialog (dlg->feature_field, &vn);
24453           }
24454         }
24455       } else if (f->field->choice == FieldType_cds_gene_prot) {
24456         SetValue (dlg->column_action, eTabColumnConfig_Apply_CDSGeneProtField);
24457         PointerToDialog (dlg->cdsgeneprot, f->field);
24458       } else if (f->field->choice == FieldType_pub) {
24459         SetValue (dlg->column_action, eTabColumnConfig_Apply_PubField);
24460         vn.choice = f->field->data.intvalue;
24461         vn.data.ptrvalue = NULL;
24462         vn.next = NULL;
24463         PointerToDialog (dlg->pub_field, &vn);
24464       } else if (f->field->choice == FieldType_misc && f->field->data.intvalue == Misc_field_genome_project_id) {
24465         SetValue (dlg->column_action, eTabColumnConfig_Apply_GenomeProjectId);
24466       } else if (f->field->choice == FieldType_misc && f->field->data.intvalue == Misc_field_comment_descriptor) {
24467         SetValue (dlg->column_action, eTabColumnConfig_Apply_CommentDescriptor);
24468       } else if (f->field->choice == FieldType_misc && f->field->data.intvalue == Misc_field_defline) {
24469         SetValue (dlg->column_action, eTabColumnConfig_Apply_Defline);
24470       } else if (f->field->choice == FieldType_misc && f->field->data.intvalue == Misc_field_keyword) {
24471         SetValue (dlg->column_action, eTabColumnConfig_Apply_Keyword);
24472       } else if (f->field->choice == FieldType_molinfo_field) {
24473         SetValue (dlg->column_action, eTabColumnConfig_Apply_Molinfo);
24474         PointerToDialog (dlg->molinfo_field, f->field->data.ptrvalue);
24475       } else if (f->field->choice == FieldType_struc_comment_field) {
24476         SetValue (dlg->column_action, eTabColumnConfig_Apply_StructuredCommentField);
24477         PointerToDialog (dlg->struccomm_field, f->field->data.ptrvalue);
24478       } else if (f->field->choice == FieldType_dblink) {
24479         SetValue (dlg->column_action, eTabColumnConfig_Apply_Dblink);
24480         SetValue (dlg->dblink_field, f->field->data.intvalue);
24481       }
24482 
24483       SafeSetStatus (dlg->change_mrna, f->match_mrna);
24484       SafeSetStatus (dlg->erase_when_blank, !f->skip_blank);
24485       SetExistingTextDialogValue(dlg->existing_text, f->existing_text);
24486       PointerToDialog (dlg->constraint, (Pointer) f->constraint);
24487     }
24488     f = TabColumnConfigFree (f);
24489   }
24490   TabColumnActionChange (dlg->column_action);
24491 }
24492 
24493 
TabColumnConfigButtonChange(ButtoN b)24494 static void TabColumnConfigButtonChange (ButtoN b)
24495 {
24496   TabColumnConfigDlgPtr dlg;
24497 
24498   dlg = (TabColumnConfigDlgPtr) GetObjectExtra (b);
24499   if (dlg != NULL && dlg->change_notify != NULL) {
24500     (dlg->change_notify) (dlg->change_userdata);
24501   }
24502 }
24503 
24504 
TabColumnConfigPopupChange(PopuP p)24505 static void TabColumnConfigPopupChange (PopuP p)
24506 {
24507   TabColumnConfigDlgPtr dlg;
24508 
24509   dlg = (TabColumnConfigDlgPtr) GetObjectExtra (p);
24510   if (dlg != NULL && dlg->change_notify != NULL) {
24511     (dlg->change_notify) (dlg->change_userdata);
24512   }
24513 }
24514 
24515 
SetTabColumnConfigDialogTitle(DialoG d,CharPtr title,Int4 num_blank)24516 static void SetTabColumnConfigDialogTitle (DialoG d, CharPtr title, Int4 num_blank)
24517 {
24518   CharPtr real_title;
24519   CharPtr title_fmt = "(%d are blank)%s";
24520   TabColumnConfigDlgPtr dlg;
24521 
24522   if (title == NULL) {
24523     real_title = "";
24524   } else if (num_blank > 0) {
24525     real_title = (CharPtr) MemNew (sizeof (Char) * (StringLen (title_fmt) + StringLen (title) + 15));
24526     sprintf (real_title, title_fmt, num_blank, title);
24527   } else {
24528     real_title = title;
24529   }
24530 
24531   SetTitle (d, real_title);
24532 
24533   if (real_title != title) {
24534     real_title = MemFree (real_title);
24535   }
24536 
24537   dlg = (TabColumnConfigDlgPtr) GetObjectExtra (d);
24538   if (dlg != NULL) {
24539     if (num_blank == 0) {
24540       SafeDisable (dlg->erase_when_blank);
24541     } else {
24542       SafeEnable (dlg->erase_when_blank);
24543     }
24544   }
24545 }
24546 
24547 
TabColumnConfigDialog(GrouP h,CharPtr title,Int4 num_blank,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)24548 NLM_EXTERN DialoG TabColumnConfigDialog
24549 (GrouP                    h,
24550  CharPtr                  title,
24551  Int4                     num_blank,
24552  Nlm_ChangeNotifyProc     change_notify,
24553  Pointer                  change_userdata)
24554 {
24555   TabColumnConfigDlgPtr dlg;
24556   GrouP p, k, choice_grp;
24557   CharPtr real_title;
24558   CharPtr title_fmt = "(%d are blank)%s";
24559   Boolean free_title = FALSE;
24560 
24561   dlg = (TabColumnConfigDlgPtr) MemNew (sizeof (TabColumnConfigDlgData));
24562 
24563   if (title == NULL) {
24564     real_title = "";
24565   } else if (num_blank > 0) {
24566     real_title = (CharPtr) MemNew (sizeof (Char) * (StringLen (title_fmt) + StringLen (title) + 15));
24567     sprintf (real_title, title_fmt, num_blank, title);
24568     free_title = TRUE;
24569   } else {
24570     real_title = title;
24571   }
24572 
24573   p = NormalGroup (h, -1, 0, real_title, programFont, NULL);
24574   SetObjectExtra (p, dlg, StdCleanupExtraProc);
24575 
24576   if (free_title) {
24577     real_title = MemFree (real_title);
24578   }
24579   dlg->dialog = (DialoG) p;
24580   dlg->fromdialog = TabColumnConfigDialogToChoice;
24581   dlg->todialog = TabColumnConfigToDialog;
24582   dlg->change_notify = change_notify;
24583   dlg->change_userdata = change_userdata;
24584 
24585   choice_grp = HiddenGroup (p, 2, 0, NULL);
24586   SetGroupSpacing (choice_grp, 10, 10);
24587   dlg->column_action = SingleList (choice_grp, 12, 12, TabColumnActionChange);
24588   SetObjectExtra (dlg->column_action, dlg, NULL);
24589   ListItem (dlg->column_action, "Ignore column");
24590   ListItem (dlg->column_action, "Match to Nucleotide ID");
24591   ListItem (dlg->column_action, "Match to Taxname");
24592   ListItem (dlg->column_action, "Match to Source Qual");
24593   ListItem (dlg->column_action, "Match to Feature ID");
24594   ListItem (dlg->column_action, "Match to Gene locus tag");
24595   ListItem (dlg->column_action, "Match to Protein ID");
24596   ListItem (dlg->column_action, "Match to Protein Name");   /* J. Chen */
24597   ListItem (dlg->column_action, "Match to Dbxref");
24598   ListItem (dlg->column_action, "Match to BioProject");
24599   ListItem (dlg->column_action, "Match to Any");
24600   ListItem (dlg->column_action, " ");
24601   ListItem (dlg->column_action, "Apply to Taxname");
24602   ListItem (dlg->column_action, "Apply to Source Qual");
24603   ListItem (dlg->column_action, "Apply to CDS-Gene-Prot Field");
24604   ListItem (dlg->column_action, "Apply to Feature Field");
24605   ListItem (dlg->column_action, "Apply to Publication Field");
24606   ListItem (dlg->column_action, "Apply to Genome Project ID");
24607   ListItem (dlg->column_action, "Apply to Comment Descriptor");
24608   ListItem (dlg->column_action, "Apply to Definition Line");
24609   ListItem (dlg->column_action, "Apply to Keyword");
24610   ListItem (dlg->column_action, "Apply to Molinfo");
24611   ListItem (dlg->column_action, "Apply to Structured Comment Field");
24612   ListItem (dlg->column_action, "Apply to Dblink");
24613   SetValue (dlg->column_action, 1);
24614 
24615   k = HiddenGroup (choice_grp, 0, 0, NULL);
24616   dlg->match_grp = HiddenGroup (k, 2, 0, NULL);
24617   dlg->match_location = IdMatchLocationDlg (dlg->match_grp, change_notify, change_userdata);
24618   dlg->src_qual_match = SourceQualChoiceDialog (dlg->match_grp, TRUE, FALSE, TRUE, change_notify, change_userdata);
24619 
24620   dlg->qual_grp = HiddenGroup (k, 0, 0, NULL);
24621   dlg->src_qual = SourceQualChoiceDialog (dlg->qual_grp, TRUE, FALSE, TRUE, TabColumnConfigFieldChange, dlg);
24622   dlg->feature_field_grp = HiddenGroup (dlg->qual_grp, 2, 0, NULL);
24623   dlg->feature_type = FeatureTypeDialog (dlg->feature_field_grp, TabColumnConfigFieldChange, dlg);
24624   dlg->feature_field = LegalFeatQualChoiceDialog (dlg->feature_field_grp, TabColumnConfigFieldChange, dlg);
24625   dlg->cdsgeneprot = CDSGeneProtFieldDialog (dlg->qual_grp, TabColumnConfigFieldChange, dlg);
24626   dlg->pub_field = PubFieldDialog (dlg->qual_grp, TabColumnConfigFieldChange, dlg);
24627   dlg->molinfo_field = MolinfoFieldChoiceDialog  (dlg->qual_grp, TabColumnConfigFieldChange, dlg);
24628   dlg->struccomm_field = StructuredCommentFieldDialog (dlg->qual_grp, TabColumnConfigFieldChange, dlg);
24629   dlg->dblink_field = MakeDbLinkFieldPopup (dlg->qual_grp, TabColumnConfigPopupChange, dlg);
24630   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->match_grp, (HANDLE) dlg->qual_grp, NULL);
24631 
24632   dlg->change_mrna = CheckBox (p, "Also change mRNA product name", TabColumnConfigButtonChange);
24633   SetObjectExtra (dlg->change_mrna, dlg, NULL);
24634   Disable (dlg->change_mrna);
24635 
24636   dlg->apply_options = HiddenGroup (p, -1, 0, NULL);
24637   if (num_blank > 0 || title == NULL) {
24638     dlg->erase_when_blank = CheckBox (dlg->apply_options, "Erase field when table cell is blank", TabColumnConfigButtonChange);
24639     SetObjectExtra (dlg->erase_when_blank, dlg, NULL);
24640     if (num_blank == 0) {
24641       Disable (dlg->erase_when_blank);
24642     }
24643   } else {
24644     dlg->erase_when_blank = NULL;
24645   }
24646   dlg->existing_text = ExistingTextDialog (dlg->apply_options, change_notify, change_userdata);
24647   dlg->constraint = ConstraintSetDialog (dlg->apply_options, change_notify, change_userdata);
24648 
24649   Disable (dlg->apply_options);
24650 
24651   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->existing_text,
24652                               (HANDLE) dlg->constraint,
24653                               (HANDLE) dlg->erase_when_blank,
24654                               NULL);
24655 
24656   AlignObjects (ALIGN_CENTER, (HANDLE) choice_grp, (HANDLE) dlg->apply_options, (HANDLE) dlg->change_mrna, NULL);
24657 
24658   TabColumnActionChange (dlg->column_action);
24659 
24660   return (DialoG) p;
24661 }
24662 
24663 
SummarizeMatchType(MatchTypePtr match_type)24664 static CharPtr SummarizeMatchType (MatchTypePtr match_type)
24665 {
24666   CharPtr location_word = "Matches";
24667   CharPtr type_word = "feature ID";
24668   CharPtr match_fmt = "%s %s";
24669   CharPtr summ = NULL;
24670 
24671   if (match_type == NULL) {
24672     return NULL;
24673   }
24674   switch (match_type->match_location) {
24675     case String_location_contains :
24676       location_word = "Contained in";
24677       break;
24678     case String_location_equals :
24679       location_word = "Matches";
24680       break;
24681     case String_location_starts :
24682       location_word = "Is start of";
24683       break;
24684     case String_location_ends :
24685       location_word = "Is end of";
24686       break;
24687     case String_location_inlist :
24688       location_word = "List contains";
24689       break;
24690   }
24691 
24692   switch (match_type->choice) {
24693     case eTableMatchProteinName:     /* J. Chen */
24694       summ = StringSave ("Match to Protein Name");
24695       break;
24696     case eTableMatchFeatureID:
24697       summ = StringSave ("Match to feature ID");
24698       break;
24699     case eTableMatchGeneLocusTag:
24700       summ = StringSave ("Match to gene locus tag");
24701       break;
24702     case eTableMatchProteinID:
24703       summ = StringSave ("Match to protein ID");
24704       break;
24705     case eTableMatchDbxref:
24706       type_word = "feature dbxref";
24707       summ = (CharPtr) MemNew (sizeof (Char) * (StringLen (match_fmt) + StringLen (type_word) + StringLen (location_word)));
24708       sprintf (summ, match_fmt, location_word, type_word);
24709       break;
24710     case eTableMatchNucID:
24711       summ = StringSave ("Match to nucleotide ID");
24712       break;
24713     case eTableMatchBioSource:
24714       type_word = "taxname";
24715       summ = (CharPtr) MemNew (sizeof (Char) * (StringLen (match_fmt) + StringLen (type_word) + StringLen (location_word)));
24716       sprintf (summ, match_fmt, location_word, type_word);
24717       break;
24718     case eTableMatchSourceQual:
24719       if (match_type->data == NULL) {
24720         type_word = "unspecified source qualifier";
24721         summ = (CharPtr) MemNew (sizeof (Char) * (StringLen (match_fmt) + StringLen (type_word) + StringLen (location_word)));
24722         sprintf (summ, match_fmt, location_word, type_word);
24723       } else {
24724         type_word = SummarizeSourceQual (match_type->data);
24725         summ = (CharPtr) MemNew (sizeof (Char) * (StringLen (match_fmt) + StringLen (type_word) + StringLen (location_word)));
24726         sprintf (summ, match_fmt, location_word, type_word);
24727         type_word = MemFree (type_word);
24728       }
24729       break;
24730     case eTableMatchBioProject:
24731       summ = StringSave ("Match to BioProject");
24732       break;
24733     case eTableMatchAny:
24734       summ = StringSave ("Match to any sequence");
24735       break;
24736   }
24737   return summ;
24738 }
24739 
SummarizeTabColumnConfig(TabColumnConfigPtr t)24740 static CharPtr SummarizeTabColumnConfig (TabColumnConfigPtr t)
24741 {
24742   CharPtr summ = NULL;
24743   CharPtr apply_fmt = "Apply to %s %s%s(%s)";
24744   CharPtr field;
24745   CharPtr erase_when_blank = ", remove field when cell is blank";
24746   CharPtr also_mrna = ", make mRNA product match new CDS product";
24747   CharPtr existing_text;
24748   CharPtr constraint;
24749   Int4    summ_len = 0;
24750 
24751   if (t == NULL) return StringSave ("Ignore column");
24752 
24753   if (t->match_type == NULL) {
24754     field = SummarizeFieldType (t->field);
24755     if (field == NULL) {
24756       field = StringSave ("unspecified field");
24757     }
24758     existing_text = SummarizeExistingText (t->existing_text);
24759     constraint = SummarizeConstraintSet (t->constraint);
24760     summ_len = StringLen (apply_fmt) + StringLen (field) + StringLen (existing_text) + StringLen (constraint);
24761     if (!t->skip_blank) {
24762       summ_len += StringLen (erase_when_blank);
24763     }
24764     if (t->match_mrna) {
24765       summ_len += StringLen (also_mrna);
24766     }
24767     summ = (CharPtr) MemNew (sizeof (Char) * summ_len);
24768     sprintf (summ, apply_fmt, field, constraint == NULL ? "" : constraint, constraint == NULL ? "" : " ", existing_text);
24769     if (!t->skip_blank) {
24770       StringCat (summ, erase_when_blank);
24771     }
24772     if (t->match_mrna) {
24773       StringCat (summ, also_mrna);
24774     }
24775     field = MemFree (field);
24776   } else {
24777     summ = SummarizeMatchType (t->match_type);
24778   }
24779   return summ;
24780 }
24781 
24782 
CleanupTabColumnConfigListDialog(GraphiC g,VoidPtr data)24783 static void CleanupTabColumnConfigListDialog (GraphiC g, VoidPtr data)
24784 
24785 {
24786   TabColumnConfigListDlgPtr dlg;
24787   Int4 i;
24788 
24789   dlg = (TabColumnConfigListDlgPtr) data;
24790   if (dlg != NULL) {
24791     for (i = 0; i < dlg->num_columns; i++) {
24792       dlg->column_list[i] = TabColumnConfigFree (dlg->column_list[i]);
24793       dlg->first_values[i] = MemFree (dlg->first_values[i]);
24794     }
24795     dlg->column_list = MemFree (dlg->column_list);
24796     dlg->first_values = MemFree (dlg->first_values);
24797     dlg->blank_list = MemFree (dlg->blank_list);
24798   }
24799   StdCleanupExtraProc (g, data);
24800 }
24801 
24802 
24803 
24804 
DialogToTabColumnConfigList(DialoG d)24805 static Pointer DialogToTabColumnConfigList (DialoG d)
24806 {
24807   TabColumnConfigListDlgPtr dlg;
24808   Int4 i;
24809   ValNodePtr column_list = NULL;
24810 
24811   dlg = (TabColumnConfigListDlgPtr) GetObjectExtra (d);
24812   if (dlg == NULL) return NULL;
24813   for (i = 0; i < dlg->num_columns; i++) {
24814     ValNodeAddPointer (&column_list, 0, TabColumnConfigCopy (dlg->column_list[i]));
24815   }
24816   return (Pointer) column_list;
24817 }
24818 
24819 
TestTabColumnConfigListDialog(DialoG d)24820 static ValNodePtr TestTabColumnConfigListDialog (DialoG d)
24821 {
24822   TabColumnConfigListDlgPtr dlg;
24823   Int4 i;
24824   ValNodePtr err_list = NULL;
24825   Int4 num_match = 0;
24826   Boolean have_apply = FALSE;
24827 
24828   dlg = (TabColumnConfigListDlgPtr) GetObjectExtra (d);
24829   if (dlg == NULL) return NULL;
24830 
24831   for (i = 0; i < dlg->num_columns; i++) {
24832     if (dlg->column_list[i] != NULL) {
24833       if (dlg->column_list[i]->match_type != NULL) {
24834         if (dlg->column_list[i]->match_type->choice != eTableMatchSourceQual
24835             || dlg->column_list[i]->match_type->data != NULL) {
24836           num_match++;
24837         }
24838       } else if (!IsFieldTypeEmpty(dlg->column_list[i]->field)) {
24839         have_apply = TRUE;
24840       }
24841     }
24842   }
24843   if (num_match == 0) {
24844     ValNodeAddPointer (&err_list, 0, "No match column");
24845   } else if (num_match > 1) {
24846     ValNodeAddPointer (&err_list, 0, "Too many match columns");
24847   }
24848   if (!have_apply) {
24849     ValNodeAddPointer (&err_list, 0, "No apply column");
24850   }
24851   return err_list;
24852 }
24853 
24854 
PopulateTabConfigListColumnListDoc(DialoG d)24855 NLM_EXTERN void PopulateTabConfigListColumnListDoc (DialoG d)
24856 {
24857   TabColumnConfigListDlgPtr dlg;
24858   Int4 i, len;
24859   CharPtr str, tmp;
24860   CharPtr    row_fmt = "%d\t%s\t%s\n";
24861   RecT       r;
24862   FonT       font = programFont;
24863   ParData    ParFmt = {FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0};
24864   ColData    ColFmt[] =
24865   {
24866     {0, 0, 4, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE}, /* column number */
24867     {0, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE}, /* action */
24868     {0, 0, 80, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, TRUE}   /* first value */
24869   };
24870   Int4 scroll_pos = 0;
24871   BaR  sb_vert;
24872 
24873 
24874   dlg = (TabColumnConfigListDlgPtr) GetObjectExtra (d);
24875   if (dlg == NULL) return;
24876 
24877   sb_vert = GetSlateVScrollBar ((SlatE) dlg->column_list_doc);
24878   if (sb_vert) {
24879     scroll_pos = GetBarValue (sb_vert);
24880   }
24881 
24882   Reset (dlg->column_list_doc);
24883 
24884   ObjectRect (dlg->column_list_doc, &r);
24885   InsetRect (&r, 4, 4);
24886 
24887   if (dlg->num_columns < 10) {
24888     ColFmt[0].pixWidth = stdCharWidth * 2;
24889   } else {
24890     ColFmt[0].pixWidth = stdCharWidth * 3;
24891   }
24892   ColFmt[1].pixWidth = (r.right - r.left - ColFmt[0].pixWidth) / 2;
24893   ColFmt[2].pixWidth = ColFmt[1].pixWidth;
24894   for (i = 0; i < dlg->num_columns; i++) {
24895     str = SummarizeTabColumnConfig (dlg->column_list[i]);
24896     len = StringLen (str) + StringLen (dlg->first_values[i]) + 15 + StringLen (row_fmt);
24897     tmp = (CharPtr) MemNew (sizeof (Char) * len);
24898     sprintf (tmp, row_fmt, i + 1, str, dlg->first_values[i]);
24899     str = MemFree (str);
24900     AppendText (dlg->column_list_doc, tmp, &ParFmt, ColFmt, font);
24901     tmp = MemFree (tmp);
24902   }
24903   UpdateDocument (dlg->column_list_doc, 0, 0);
24904   if (scroll_pos > 0) {
24905     CorrectBarValue (sb_vert, scroll_pos);
24906   }
24907 }
24908 
24909 
ClickColumnListDoc(DoC d,PoinT pt)24910 static void ClickColumnListDoc (DoC d, PoinT pt)
24911 {
24912   Int2               item, row, col;
24913   RecT               rct;
24914   TabColumnConfigListDlgPtr dlg;
24915   TabColumnConfigPtr        data;
24916 
24917   dlg = (TabColumnConfigListDlgPtr) GetObjectExtra (d);
24918   if (dlg == NULL) return;
24919 
24920   MapDocPoint (d, pt, &item, &row, &col, &rct);
24921   if (item > 0 && item <= dlg->num_columns) {
24922     dlg->current_column = item - 1;
24923     data = dlg->column_list[item - 1];
24924     PointerToDialog (dlg->edit_col_dlg, data);
24925     SetTabColumnConfigDialogTitle (dlg->edit_col_dlg, dlg->first_values[item - 1], dlg->blank_list[item - 1]);
24926   }
24927 }
24928 
ShowSelectedColumn(DoC doc,Int2 item,Int2 row,Int2 col)24929 static Boolean ShowSelectedColumn (DoC doc, Int2 item, Int2 row, Int2 col)
24930 {
24931   TabColumnConfigListDlgPtr dlg;
24932 
24933   dlg = (TabColumnConfigListDlgPtr) GetObjectExtra (doc);
24934   if (dlg == NULL) return FALSE;
24935 
24936   if (dlg->current_column == item - 1) {
24937     return TRUE;
24938   } else {
24939     return FALSE;
24940   }
24941 }
24942 
24943 
ChangeTabColumnConfig(Pointer userdata)24944 static void ChangeTabColumnConfig (Pointer userdata)
24945 {
24946   TabColumnConfigListDlgPtr dlg;
24947 
24948   dlg = (TabColumnConfigListDlgPtr) userdata;
24949   if (dlg == NULL || dlg->column_list == NULL) return;
24950 
24951   dlg->column_list[dlg->current_column] = TabColumnConfigFree (dlg->column_list[dlg->current_column]);
24952   dlg->column_list[dlg->current_column] = DialogToPointer (dlg->edit_col_dlg);
24953   PopulateTabConfigListColumnListDoc (dlg->dialog);
24954   if (dlg->change_notify != NULL) {
24955     (dlg->change_notify)(dlg->change_userdata);
24956   }
24957 }
24958 
24959 
TabColumnConfigListToDialog(DialoG d,Pointer data)24960 static void TabColumnConfigListToDialog (DialoG d, Pointer data)
24961 {
24962   TabColumnConfigListDlgPtr dlg;
24963   Int4 i;
24964   ValNodePtr vnp;
24965 
24966   dlg = (TabColumnConfigListDlgPtr) GetObjectExtra (d);
24967   if (dlg == NULL) return;
24968 
24969   vnp = (ValNodePtr) data;
24970   for (i = 0; i < dlg->num_columns; i++) {
24971     dlg->column_list[i] = TabColumnConfigFree (dlg->column_list[i]);
24972     if (vnp != NULL) {
24973       dlg->column_list[i] = TabColumnConfigCopy (vnp->data.ptrvalue);
24974       vnp = vnp->next;
24975     }
24976   }
24977   PopulateTabConfigListColumnListDoc (dlg->dialog);
24978   PointerToDialog (dlg->edit_col_dlg, dlg->column_list[dlg->current_column]);
24979   if (dlg->change_notify != NULL) {
24980     (dlg->change_notify)(dlg->change_userdata);
24981   }
24982 }
24983 
24984 
24985 
24986 
TabColumnConfigListDialog(GrouP h,ValNodePtr first_values,ValNodePtr blank_list,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)24987 NLM_EXTERN DialoG TabColumnConfigListDialog (GrouP h, ValNodePtr first_values, ValNodePtr blank_list, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
24988 {
24989   TabColumnConfigListDlgPtr dlg;
24990   GrouP                p;
24991   ValNodePtr           vnp_v, vnp_b;
24992   Int4                 i;
24993 
24994   dlg = (TabColumnConfigListDlgPtr) MemNew (sizeof (TabColumnConfigListDlgData));
24995   if (dlg == NULL)
24996   {
24997     return NULL;
24998   }
24999 
25000   p = HiddenGroup (h, -1, 0, NULL);
25001   SetObjectExtra (p, dlg, CleanupTabColumnConfigListDialog);
25002 
25003   dlg->dialog = (DialoG) p;
25004   dlg->fromdialog = DialogToTabColumnConfigList;
25005   dlg->todialog = TabColumnConfigListToDialog;
25006   dlg->testdialog = TestTabColumnConfigListDialog;
25007 
25008   dlg->change_notify = change_notify;
25009   dlg->change_userdata = change_userdata;
25010 
25011 
25012   dlg->column_list_doc = DocumentPanel (p, stdCharWidth * 50, stdLineHeight * 8);
25013   SetObjectExtra (dlg->column_list_doc, dlg, NULL);
25014   SetDocProcs (dlg->column_list_doc, ClickColumnListDoc, NULL, NULL, NULL);
25015   SetDocShade (dlg->column_list_doc, NULL, NULL, ShowSelectedColumn, NULL);
25016 
25017   dlg->edit_col_dlg = TabColumnConfigDialog (p, NULL, 0, ChangeTabColumnConfig, dlg);
25018 
25019   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->column_list_doc, (HANDLE) dlg->edit_col_dlg, NULL);
25020 
25021   /* populate column list */
25022   dlg->num_columns = ValNodeLen (blank_list);
25023   dlg->column_list = (TabColumnConfigPtr PNTR) MemNew (sizeof (TabColumnConfigPtr) * dlg->num_columns);
25024   MemSet (dlg->column_list, 0, sizeof (TabColumnConfigPtr) * dlg->num_columns);
25025   dlg->first_values = MemNew (sizeof (CharPtr) * dlg->num_columns);
25026   dlg->blank_list = (Int4Ptr) MemNew (sizeof (Int4) * dlg->num_columns);
25027 
25028   vnp_v = first_values;
25029   vnp_b = blank_list;
25030   i = 0;
25031   while (vnp_b != NULL) {
25032     dlg->blank_list[i] = vnp_b->data.intvalue;
25033     if (vnp_v == NULL || StringHasNoText (vnp_v->data.ptrvalue)) {
25034       dlg->first_values[i] = StringSave ("First row value is blank");
25035     } else {
25036       dlg->first_values[i] = StringSave (vnp_v->data.ptrvalue);
25037     }
25038     dlg->column_list[i] = NULL;
25039     vnp_b = vnp_b->next;
25040     if (vnp_v != NULL) {
25041       vnp_v = vnp_v->next;
25042     }
25043     i++;
25044   }
25045 
25046   PopulateTabConfigListColumnListDoc ((DialoG) p);
25047 
25048   dlg->current_column = 0;
25049   PointerToDialog (dlg->edit_col_dlg, dlg->column_list[0]);
25050   SetTabColumnConfigDialogTitle (dlg->edit_col_dlg, dlg->first_values[0], dlg->blank_list[0]);
25051 
25052   return (DialoG) p;
25053 }
25054 
25055 
ChangeDataForTabColumnConfigListDialog(DialoG d,ValNodePtr first_values,ValNodePtr blank_list)25056 NLM_EXTERN void ChangeDataForTabColumnConfigListDialog (DialoG d, ValNodePtr first_values, ValNodePtr blank_list)
25057 {
25058   TabColumnConfigListDlgPtr dlg;
25059   TabColumnConfigPtr PNTR column_list;
25060   Int4 num_columns, i;
25061   ValNodePtr           vnp_v, vnp_b;
25062 
25063   dlg = (TabColumnConfigListDlgPtr) GetObjectExtra (d);
25064   if (dlg == NULL) {
25065     return;
25066   }
25067 
25068   num_columns = ValNodeLen (blank_list);
25069   if (num_columns < dlg->num_columns) {
25070     /* truncate existing list */
25071     for (i = num_columns; i < dlg->num_columns; i++) {
25072       dlg->column_list[i] = TabColumnConfigFree (dlg->column_list[i]);
25073       dlg->first_values[i] = MemFree (dlg->first_values[i]);
25074     }
25075     if (dlg->current_column >= num_columns) {
25076       dlg->current_column = num_columns - 1;
25077     }
25078 
25079     dlg->num_columns = num_columns;
25080   } else if (num_columns > dlg->num_columns) {
25081     /* need larger lists */
25082     for (i = 0; i < dlg->num_columns; i++) {
25083       dlg->first_values[i] = MemFree (dlg->first_values[i]);
25084     }
25085     dlg->first_values = MemFree (dlg->first_values);
25086     dlg->first_values = MemNew (sizeof (CharPtr) * num_columns);
25087 
25088     dlg->blank_list = MemFree (dlg->blank_list);
25089     dlg->blank_list = (Int4Ptr) MemNew (sizeof (Int4) * num_columns);
25090 
25091     column_list = (TabColumnConfigPtr PNTR) MemNew (sizeof (TabColumnConfigPtr) * num_columns);
25092     for (i = 0; i < dlg->num_columns; i++) {
25093       column_list[i] = dlg->column_list[i];
25094       dlg->column_list[i] = NULL;
25095     }
25096     dlg->column_list = MemFree (dlg->column_list);
25097     dlg->column_list = column_list;
25098 
25099     dlg->num_columns = num_columns;
25100   }
25101 
25102   /* populate column list */
25103   vnp_v = first_values;
25104   vnp_b = blank_list;
25105   i = 0;
25106   while (vnp_b != NULL) {
25107     dlg->blank_list[i] = vnp_b->data.intvalue;
25108     if (vnp_v == NULL || StringHasNoText (vnp_v->data.ptrvalue)) {
25109       dlg->first_values[i] = StringSave ("First row value is blank");
25110     } else {
25111       dlg->first_values[i] = StringSave (vnp_v->data.ptrvalue);
25112     }
25113     vnp_b = vnp_b->next;
25114     if (vnp_v != NULL) {
25115       vnp_v = vnp_v->next;
25116     }
25117     i++;
25118   }
25119 
25120   PopulateTabConfigListColumnListDoc (d);
25121 
25122   PointerToDialog (dlg->edit_col_dlg, dlg->column_list[dlg->current_column]);
25123   SetTabColumnConfigDialogTitle (dlg->edit_col_dlg, dlg->first_values[dlg->current_column], dlg->blank_list[dlg->current_column]);
25124 
25125 }
25126 
25127 
25128 typedef struct matchtypedlg {
25129   DIALOG_MESSAGE_BLOCK
25130   PopuP match_type;
25131   DialoG match_location;
25132   DialoG src_qual_match;
25133 
25134   Nlm_ChangeNotifyProc     change_notify;
25135   Pointer                  change_userdata;
25136 } MatchTypeDlgData, PNTR MatchTypeDlgPtr;
25137 
25138 typedef enum matchtypechoice {
25139   eMatchType_NucleotideID = 1,
25140   eMatchType_Taxname,
25141   eMatchType_SourceQual,
25142   eMatchType_FeatureID,
25143   eMatchType_GeneLocusTag,
25144   eMatchType_ProteinID,
25145   eMatchType_Dbxref,
25146   eMatchType_ProteinName,
25147   eMatchType_BioProject,
25148   eMatchType_Any,
25149   eMatchType_Filename
25150 } EMatchTypeChoice;
25151 
25152 
ChangeMatchTypeChoice(PopuP p)25153 static void ChangeMatchTypeChoice (PopuP p)
25154 {
25155   MatchTypeDlgPtr dlg;
25156   Int2            val;
25157 
25158   dlg = (MatchTypeDlgPtr) GetObjectExtra (p);
25159   if (dlg != NULL) {
25160     val = GetValue (dlg->match_type);
25161     switch (val) {
25162       case eMatchType_Taxname:
25163       case eMatchType_Dbxref:
25164         Show (dlg->match_location);
25165         Hide (dlg->src_qual_match);
25166         break;
25167       case eMatchType_SourceQual:
25168         Show (dlg->match_location);
25169         Show (dlg->src_qual_match);
25170         break;
25171       case eMatchType_NucleotideID:
25172       case eMatchType_FeatureID:
25173       case eMatchType_GeneLocusTag:
25174       case eMatchType_ProteinID:
25175       case eMatchType_BioProject:
25176       case eMatchType_Any:
25177       default:
25178         Hide (dlg->match_location);
25179         Hide (dlg->src_qual_match);
25180         break;
25181     }
25182     if (dlg->change_notify != NULL) {
25183       (dlg->change_notify) (dlg->change_userdata);
25184     }
25185   }
25186 }
25187 
25188 
MatchTypeToDialog(DialoG d,Pointer data)25189 static void MatchTypeToDialog (DialoG d, Pointer data)
25190 {
25191   MatchTypeDlgPtr dlg;
25192   MatchTypePtr match_type;
25193 
25194   dlg = (MatchTypeDlgPtr) GetObjectExtra (d);
25195   if (dlg == NULL) {
25196     return;
25197   }
25198   match_type = (MatchTypePtr) data;
25199   if (match_type == NULL) {
25200     SetValue (dlg->match_type, 1);
25201     SetMatchLocationInIdMatchLocationDlg (dlg->match_location, String_location_equals);
25202   } else {
25203     SetMatchLocationInIdMatchLocationDlg (dlg->match_location, match_type->match_location);
25204     switch (match_type->choice) {
25205       case eTableMatchProteinName:
25206         SetValue (dlg->match_type, eMatchType_ProteinName);
25207         break;
25208       case eTableMatchFeatureID:
25209         SetValue (dlg->match_type, eMatchType_FeatureID);
25210         break;
25211       case eTableMatchGeneLocusTag:
25212         SetValue (dlg->match_type, eMatchType_GeneLocusTag);
25213         break;
25214       case eTableMatchProteinID:
25215         SetValue (dlg->match_type, eMatchType_ProteinID);
25216         break;
25217       case eTableMatchDbxref:
25218         SetValue (dlg->match_type, eMatchType_Dbxref);
25219         break;
25220       case eTableMatchNucID:
25221         SetValue (dlg->match_type, eMatchType_NucleotideID);
25222         break;
25223       case eTableMatchBioSource:
25224         SetValue (dlg->match_type, eMatchType_Taxname);
25225         break;
25226       case eTableMatchSourceQual:
25227         SetValue (dlg->match_type, eMatchType_SourceQual);
25228         PointerToDialog (dlg->src_qual_match, match_type->data);
25229         break;
25230       case eTableMatchBioProject:
25231         SetValue (dlg->match_type, eMatchType_BioProject);
25232         break;
25233       case eTableMatchAny:
25234         SetValue (dlg->match_type, eMatchType_Any);
25235         break;
25236     }
25237   }
25238 }
25239 
25240 
DialogToMatchType(DialoG d)25241 static Pointer DialogToMatchType (DialoG d)
25242 {
25243   MatchTypeDlgPtr dlg;
25244   MatchTypePtr match_type = NULL;
25245   Int2 val;
25246 
25247   dlg = (MatchTypeDlgPtr) GetObjectExtra (d);
25248   if (dlg != NULL) {
25249     val = GetValue (dlg->match_type);
25250     match_type = MatchTypeNew ();
25251     match_type->match_location = GetMatchLocationFromIdMatchLocationDlg (dlg->match_location);
25252     switch (val) {
25253       case eMatchType_ProteinName:    /* J. Chen */
25254         match_type->choice = eTableMatchProteinName;
25255         break;
25256       case eMatchType_FeatureID:
25257         match_type->choice = eTableMatchFeatureID;
25258         break;
25259       case eMatchType_GeneLocusTag:
25260         match_type->choice = eTableMatchGeneLocusTag;
25261         break;
25262       case eMatchType_ProteinID:
25263         match_type->choice = eTableMatchProteinID;
25264         break;
25265       case eMatchType_Dbxref:
25266         match_type->choice = eTableMatchDbxref;
25267         break;
25268       case eMatchType_NucleotideID:
25269         match_type->choice = eTableMatchNucID;
25270         break;
25271       case eMatchType_Taxname:
25272         match_type->choice = eTableMatchBioSource;
25273         break;
25274       case eMatchType_SourceQual:
25275         match_type->choice = eTableMatchSourceQual;
25276         match_type->data = DialogToPointer (dlg->src_qual_match);
25277         break;
25278       case eMatchType_Any:
25279         match_type->choice = eTableMatchAny;
25280         break;
25281       case eMatchType_BioProject:
25282         match_type->choice = eTableMatchBioProject;
25283         break;
25284       default:
25285         match_type = MatchTypeFree (match_type);
25286         break;
25287     }
25288   }
25289   return match_type;
25290 }
25291 
25292 
TestMatchTypeDialog(DialoG d)25293 static ValNodePtr TestMatchTypeDialog (DialoG d)
25294 {
25295   ValNodePtr err_list = NULL;
25296   MatchTypePtr match_type = NULL;
25297 
25298   match_type = DialogToPointer (d);
25299   if (match_type == NULL) {
25300     ValNodeAddPointer (&err_list, 0, "No match type");
25301   }
25302   match_type = MatchTypeFree (match_type);
25303   return err_list;
25304 }
25305 
25306 
MatchTypeDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)25307 NLM_EXTERN DialoG MatchTypeDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
25308 {
25309   MatchTypeDlgPtr dlg;
25310   GrouP           p, k;
25311 
25312   dlg = (MatchTypeDlgPtr) MemNew (sizeof (MatchTypeDlgData));
25313   if (dlg == NULL)
25314   {
25315     return NULL;
25316   }
25317 
25318   p = HiddenGroup (h, -1, 0, NULL);
25319   SetObjectExtra (p, dlg, StdCleanupExtraProc);
25320 
25321   dlg->dialog = (DialoG) p;
25322   dlg->fromdialog = DialogToMatchType;
25323   dlg->todialog = MatchTypeToDialog;
25324   dlg->testdialog = TestMatchTypeDialog;
25325 
25326   dlg->change_notify = change_notify;
25327   dlg->change_userdata = change_userdata;
25328 
25329   dlg->match_type = PopupList (p, TRUE, ChangeMatchTypeChoice);
25330   SetObjectExtra (dlg->match_type, dlg, NULL);
25331   PopupItem (dlg->match_type, "Match to Nucleotide ID");
25332   PopupItem (dlg->match_type, "Match to Taxname");
25333   PopupItem (dlg->match_type, "Match to Source Qual");
25334   PopupItem (dlg->match_type, "Match to Feature ID");
25335   PopupItem (dlg->match_type, "Match to Gene locus tag");
25336   PopupItem (dlg->match_type, "Match to Protein ID");
25337   PopupItem (dlg->match_type, "Match to Protein Name");   /* J. Chen */
25338   PopupItem (dlg->match_type, "Match to Dbxref");
25339   PopupItem (dlg->match_type, "Match to BioProject");
25340   PopupItem (dlg->match_type, "Match to All Rows");
25341   SetValue (dlg->match_type, 1);
25342 
25343   k = HiddenGroup (p, 2, 0, NULL);
25344   dlg->match_location = IdMatchLocationDlg (k, change_notify, change_userdata);
25345   dlg->src_qual_match = SourceQualChoiceDialog (k, TRUE, FALSE, FALSE, change_notify, change_userdata);
25346   Hide (dlg->match_location);
25347   Hide (dlg->src_qual_match);
25348 
25349   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->match_type, (HANDLE) k, NULL);
25350   return (DialoG) p;
25351 }
25352 
25353 /* dialog for molinfo fields to be read from table */
25354 typedef struct molinfofieldchoicedlg {
25355   DIALOG_MESSAGE_BLOCK
25356   PopuP molinfo_field;
25357   Nlm_ChangeNotifyProc     change_notify;
25358   Pointer                  change_userdata;
25359 } MolinfoFieldChoiceDlgData, PNTR MolinfoFieldChoiceDlgPtr;
25360 
25361 
MolinfoFieldChoiceDialogToChoice(DialoG d)25362 static Pointer MolinfoFieldChoiceDialogToChoice (DialoG d)
25363 {
25364   MolinfoFieldChoiceDlgPtr dlg;
25365   ValNodePtr vnp;
25366   Int2       val;
25367 
25368   dlg = (MolinfoFieldChoiceDlgPtr) GetObjectExtra (d);
25369   if (dlg == NULL) {
25370     return NULL;
25371   }
25372   vnp = ValNodeNew (NULL);
25373   val = GetValue (dlg->molinfo_field);
25374   switch (val) {
25375     case 1:
25376       vnp->choice = MolinfoField_molecule;
25377       break;
25378     case 2:
25379       vnp->choice = MolinfoField_technique;
25380       break;
25381     case 3:
25382       vnp->choice = MolinfoField_completedness;
25383       break;
25384     case 4:
25385       vnp->choice = MolinfoField_mol_class;
25386       break;
25387     case 5:
25388       vnp->choice = MolinfoField_topology;
25389       break;
25390     case 6:
25391       vnp->choice = MolinfoField_strand;
25392       break;
25393     default:
25394       vnp->choice = MolinfoField_molecule;
25395       break;
25396   }
25397   return (Pointer) vnp;
25398 }
25399 
25400 
MolinfoFieldChoiceToDialog(DialoG d,Pointer data)25401 static void MolinfoFieldChoiceToDialog (DialoG d, Pointer data)
25402 {
25403   MolinfoFieldChoiceDlgPtr dlg;
25404   ValNodePtr vnp;
25405 
25406   dlg = (MolinfoFieldChoiceDlgPtr) GetObjectExtra (d);
25407   if (dlg == NULL) {
25408     return;
25409   }
25410   vnp = (ValNodePtr) data;
25411   if (vnp == NULL) {
25412     SetValue (dlg->molinfo_field, 1);
25413   } else {
25414     switch (vnp->choice) {
25415       case MolinfoField_molecule:
25416         SetValue (dlg->molinfo_field, 1);
25417         break;
25418       case MolinfoField_technique:
25419         SetValue (dlg->molinfo_field, 2);
25420         break;
25421       case MolinfoField_completedness:
25422         SetValue (dlg->molinfo_field, 3);
25423         break;
25424       case MolinfoField_mol_class:
25425         SetValue (dlg->molinfo_field, 4);
25426         break;
25427       case MolinfoField_topology:
25428         SetValue (dlg->molinfo_field, 5);
25429         break;
25430       case MolinfoField_strand:
25431         SetValue (dlg->molinfo_field, 6);
25432         break;
25433       default:
25434         SetValue (dlg->molinfo_field, 1);
25435         break;
25436     }
25437   }
25438 }
25439 
25440 
MolinfoFieldChoicePopupChange(PopuP p)25441 static void MolinfoFieldChoicePopupChange (PopuP p)
25442 {
25443   MolinfoFieldChoiceDlgPtr dlg;
25444 
25445   dlg = (MolinfoFieldChoiceDlgPtr) GetObjectExtra (p);
25446   if (dlg == NULL) {
25447     return;
25448   }
25449   if (dlg->change_notify != NULL) {
25450     (dlg->change_notify) (dlg->change_userdata);
25451   }
25452 }
25453 
25454 
MolinfoFieldChoiceDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)25455 NLM_EXTERN DialoG MolinfoFieldChoiceDialog
25456 (GrouP                    h,
25457  Nlm_ChangeNotifyProc     change_notify,
25458  Pointer                  change_userdata)
25459 {
25460   MolinfoFieldChoiceDlgPtr dlg;
25461   GrouP p;
25462 
25463   dlg = (MolinfoFieldChoiceDlgPtr) MemNew (sizeof (MolinfoFieldChoiceDlgData));
25464 
25465   p = HiddenGroup (h, -1, 0, NULL);
25466   SetObjectExtra (p, dlg, StdCleanupExtraProc);
25467 
25468   dlg->dialog = (DialoG) p;
25469   dlg->fromdialog = MolinfoFieldChoiceDialogToChoice;
25470   dlg->todialog = MolinfoFieldChoiceToDialog;
25471   dlg->change_notify = change_notify;
25472   dlg->change_userdata = change_userdata;
25473 
25474   dlg->molinfo_field = PopupList (p, TRUE, MolinfoFieldChoicePopupChange);
25475   SetObjectExtra (dlg->molinfo_field, dlg, NULL);
25476   PopupItem (dlg->molinfo_field, "molecule");
25477   PopupItem (dlg->molinfo_field, "technique");
25478   PopupItem (dlg->molinfo_field, "completedness");
25479   PopupItem (dlg->molinfo_field, "class");
25480   PopupItem (dlg->molinfo_field, "topology");
25481   PopupItem (dlg->molinfo_field, "strand");
25482   SetValue (dlg->molinfo_field, 1);
25483 
25484   return (DialoG) p;
25485 }
25486 
25487 /* suspect product rule editing*/
25488 
25489 typedef Boolean (*IsObjectEmpty) PROTO ((Pointer));
25490 typedef Pointer (*FreeObject) PROTO ((Pointer));
25491 typedef DialoG  (*ObjEditDialog) PROTO ((GrouP, Nlm_ChangeNotifyProc, Pointer));
25492 
25493 typedef struct editobject {
25494   DialoG dlg;
25495   ButtoN accept_btn;
25496   IsObjectEmpty empty_func;
25497   FreeObject free_func;
25498 } EditObjectData, PNTR EditObjectPtr;
25499 
25500 
ChangeObject(Pointer data)25501 static void ChangeObject (Pointer data)
25502 {
25503   EditObjectPtr e;
25504   Pointer obj;
25505 
25506   if ( (e = (EditObjectPtr) data) == NULL) {
25507     return;
25508   }
25509 
25510   /* if object is empty, disable accept button, otherwise enable it */
25511   obj = DialogToPointer (e->dlg);
25512   if (obj == NULL) {
25513     Disable (e->accept_btn);
25514   } else if (e->empty_func == NULL) {
25515     Enable (e->accept_btn);
25516   } else {
25517     if (e->empty_func(obj)) {
25518       Disable (e->accept_btn);
25519     } else {
25520       Enable (e->accept_btn);
25521     }
25522   }
25523   if (e->free_func == NULL) {
25524     obj = MemFree (obj);
25525   } else {
25526     obj = e->free_func(obj);
25527   }
25528 }
25529 
25530 
EditObject(Pointer orig,CharPtr title,IsObjectEmpty empty_func,FreeObject free_func,ObjEditDialog make_dlg)25531 static Pointer EditObject (Pointer orig, CharPtr title, IsObjectEmpty empty_func, FreeObject free_func, ObjEditDialog make_dlg)
25532 {
25533   ModalAcceptCancelData acd;
25534   EditObjectData        esd;
25535   WindoW                w;
25536   ButtoN                b;
25537   GrouP                 h, c;
25538   Pointer               new_obj = NULL;
25539 
25540   w = MovableModalWindow(-20, -13, -10, -10, title, NULL);
25541   h = HiddenGroup (w, -1, 0, NULL);
25542   SetGroupSpacing (h, 10, 10);
25543 
25544   MemSet (&esd, 0, sizeof (EditObjectData));
25545   esd.empty_func = empty_func;
25546   esd.free_func = free_func;
25547 
25548   esd.dlg = make_dlg (h, ChangeObject, &esd);
25549   c = HiddenGroup (h, 2, 0, NULL);
25550   SetGroupSpacing (c, 10, 10);
25551   esd.accept_btn = PushButton (c, "Accept", ModalAcceptButton);
25552   SetObjectExtra (esd.accept_btn, &acd, NULL);
25553   b = PushButton (c, "Cancel", ModalCancelButton);
25554   SetObjectExtra (b, &acd, NULL);
25555   AlignObjects (ALIGN_CENTER, (HANDLE) esd.dlg,
25556                               (HANDLE) c,
25557                               NULL);
25558 
25559   PointerToDialog (esd.dlg, orig);
25560 
25561   ChangeObject (&esd);
25562   Show (w);
25563   Select (w);
25564   acd.accepted = FALSE;
25565   acd.cancelled = FALSE;
25566   while (!acd.accepted && ! acd.cancelled)
25567   {
25568     ProcessExternalEvent ();
25569     Update ();
25570   }
25571   ProcessAnEvent ();
25572   if (!acd.cancelled)
25573   {
25574     new_obj = DialogToPointer (esd.dlg);
25575   }
25576   Remove (w);
25577   return new_obj;
25578 }
25579 
25580 
25581 typedef struct searchfuncdlg {
25582   DIALOG_MESSAGE_BLOCK
25583 
25584   PopuP func_choice;
25585   DialoG string_constraint;
25586   TexT   text;
25587 
25588   Nlm_ChangeNotifyProc     change_notify;
25589   Pointer                  change_userdata;
25590 } SearchFuncDlgData, PNTR SearchFuncDlgPtr;
25591 
25592 
SearchFuncDlgPopupChange(PopuP p)25593 static void SearchFuncDlgPopupChange (PopuP p)
25594 {
25595   SearchFuncDlgPtr dlg;
25596   Int2 val;
25597 
25598   dlg = (SearchFuncDlgPtr) GetObjectExtra (p);
25599   if (dlg == NULL) {
25600     return;
25601   }
25602 
25603   val = GetValue (dlg->func_choice);
25604   switch (val) {
25605     case 1:
25606       Show (dlg->string_constraint);
25607       Hide (dlg->text);
25608       break;
25609     case 2:
25610     case 4:
25611     case 5:
25612     case 7:
25613     case 8:
25614       Hide (dlg->string_constraint);
25615       Hide (dlg->text);
25616       break;
25617     case 3:
25618     case 6:
25619     case 9:
25620     case 10:
25621       Hide (dlg->string_constraint);
25622       Show (dlg->text);
25623       break;
25624   }
25625 
25626   if (dlg->change_notify != NULL) {
25627     (dlg->change_notify) (dlg->change_userdata);
25628   }
25629 }
25630 
25631 
SearchFuncDlgTextChange(TexT t)25632 static void SearchFuncDlgTextChange (TexT t)
25633 {
25634   SearchFuncDlgPtr dlg;
25635 
25636   dlg = (SearchFuncDlgPtr) GetObjectExtra (t);
25637   if (dlg == NULL) {
25638     return;
25639   }
25640   if (dlg->change_notify != NULL) {
25641     (dlg->change_notify) (dlg->change_userdata);
25642   }
25643 }
25644 
25645 
SearchFuncFromDialog(DialoG d)25646 static Pointer SearchFuncFromDialog (DialoG d)
25647 {
25648   SearchFuncDlgPtr dlg;
25649   Int2 val;
25650   CharPtr str;
25651   SearchFuncPtr func;
25652 
25653   dlg = (SearchFuncDlgPtr) GetObjectExtra (d);
25654   if (dlg == NULL) {
25655     return NULL;
25656   }
25657 
25658   func = ValNodeNew (NULL);
25659   val = GetValue (dlg->func_choice);
25660   switch (val) {
25661     case 1:
25662       func->choice = SearchFunc_string_constraint;
25663       func->data.ptrvalue = DialogToPointer (dlg->string_constraint);
25664       break;
25665     case 2:
25666       func->choice = SearchFunc_contains_plural;
25667       break;
25668     case 3:
25669       func->choice = SearchFunc_n_or_more_brackets_or_parentheses;
25670       str = SaveStringFromText (dlg->text);
25671       if (str == NULL) {
25672         func->data.intvalue = 0;
25673       } else {
25674         func->data.intvalue = atoi (str);
25675       }
25676       str = MemFree (str);
25677       break;
25678     case 4:
25679       func->choice = SearchFunc_three_numbers;
25680       break;
25681     case 5:
25682       func->choice = SearchFunc_underscore;
25683       break;
25684     case 6:
25685       func->choice = SearchFunc_prefix_and_numbers;
25686       func->data.ptrvalue = SaveStringFromText (dlg->text);
25687       break;
25688     case 7:
25689       func->choice = SearchFunc_all_caps;
25690       break;
25691     case 8:
25692       func->choice = SearchFunc_unbalanced_paren;
25693       break;
25694     case 9:
25695       func->choice = SearchFunc_too_long;
25696       str = SaveStringFromText (dlg->text);
25697       if (str == NULL) {
25698         func->data.intvalue = 0;
25699       } else {
25700         func->data.intvalue = atoi (str);
25701       }
25702       str = MemFree (str);
25703       break;
25704     case 10:
25705       func->choice = SearchFunc_has_term;
25706       func->data.ptrvalue = SaveStringFromText (dlg->text);
25707       break;
25708     default:
25709       func = ValNodeFree (func);
25710       break;
25711   }
25712   return (Pointer) func;
25713 }
25714 
25715 
SearchFuncDialogChange(Pointer data)25716 static void SearchFuncDialogChange (Pointer data)
25717 {
25718   SearchFuncDlgPtr dlg;
25719 
25720   if ((dlg = (SearchFuncDlgPtr) data) != NULL
25721     && dlg->change_notify != NULL) {
25722     (dlg->change_notify) (dlg->change_userdata);
25723   }
25724 }
25725 
25726 
SearchFuncToDialog(DialoG d,Pointer data)25727 static void SearchFuncToDialog (DialoG d, Pointer data)
25728 {
25729   SearchFuncDlgPtr dlg;
25730   Char buf[15];
25731   SearchFuncPtr func;
25732 
25733   dlg = (SearchFuncDlgPtr) GetObjectExtra (d);
25734   if (dlg == NULL) {
25735     return;
25736   }
25737 
25738   func = (SearchFuncPtr) data;
25739   if (func == NULL) {
25740     SetValue (dlg->func_choice, 1);
25741     PointerToDialog (dlg->string_constraint, NULL);
25742     return;
25743   }
25744 
25745   switch (func->choice) {
25746     case SearchFunc_string_constraint:
25747       SetValue (dlg->func_choice, 1);
25748       PointerToDialog (dlg->string_constraint, func->data.ptrvalue);
25749       break;
25750     case SearchFunc_contains_plural:
25751       SetValue (dlg->func_choice, 2);
25752       break;
25753     case SearchFunc_n_or_more_brackets_or_parentheses:
25754       SetValue (dlg->func_choice, 3);
25755       sprintf (buf, "%d", func->data.intvalue);
25756       SetTitle (dlg->text, buf);
25757       break;
25758     case SearchFunc_three_numbers:
25759       SetValue (dlg->func_choice, 4);
25760       break;
25761     case SearchFunc_underscore:
25762       SetValue (dlg->func_choice, 5);
25763       break;
25764     case SearchFunc_prefix_and_numbers:
25765       SetValue (dlg->func_choice, 6);
25766       SetTitle (dlg->text, func->data.ptrvalue == NULL ? "" : func->data.ptrvalue);
25767       break;
25768     case SearchFunc_all_caps:
25769       SetValue (dlg->func_choice, 7);
25770       break;
25771     case SearchFunc_unbalanced_paren:
25772       SetValue (dlg->func_choice, 8);
25773       break;
25774     case SearchFunc_too_long:
25775       SetValue (dlg->func_choice, 9);
25776       sprintf (buf, "%d", func->data.intvalue);
25777       SetTitle (dlg->text, buf);
25778       break;
25779     case SearchFunc_has_term:
25780       SetValue (dlg->func_choice, 10);
25781       SetTitle (dlg->text, func->data.ptrvalue == NULL ? "" : func->data.ptrvalue);
25782       break;
25783     default:
25784       SetValue (dlg->func_choice, 1);
25785       PointerToDialog (dlg->string_constraint, NULL);
25786       break;
25787   }
25788   SearchFuncDlgPopupChange(dlg->func_choice);
25789 }
25790 
25791 
25792 
SearchFuncDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)25793 NLM_EXTERN DialoG SearchFuncDialog
25794 (GrouP                    h,
25795  Nlm_ChangeNotifyProc     change_notify,
25796  Pointer                  change_userdata)
25797 {
25798   SearchFuncDlgPtr dlg;
25799   GrouP p, g;
25800 
25801   dlg = (SearchFuncDlgPtr) MemNew (sizeof (SearchFuncDlgData));
25802 
25803   p = HiddenGroup (h, -1, 0, NULL);
25804   SetObjectExtra (p, dlg, StdCleanupExtraProc);
25805 
25806   dlg->dialog = (DialoG) p;
25807   dlg->fromdialog = SearchFuncFromDialog;
25808   dlg->todialog = SearchFuncToDialog;
25809   dlg->change_notify = change_notify;
25810   dlg->change_userdata = change_userdata;
25811 
25812   dlg->func_choice = PopupList (p, TRUE, SearchFuncDlgPopupChange);
25813   SetObjectExtra (dlg->func_choice, dlg, NULL);
25814   PopupItem (dlg->func_choice, "String Constraint");
25815   PopupItem (dlg->func_choice, "Contains plural");
25816   PopupItem (dlg->func_choice, "N or more brackets or parentheses");
25817   PopupItem (dlg->func_choice, "Three numbers");
25818   PopupItem (dlg->func_choice, "Contains underscore");
25819   PopupItem (dlg->func_choice, "Is prefix and numbers");
25820   PopupItem (dlg->func_choice, "Is all caps");
25821   PopupItem (dlg->func_choice, "Contains unbalanced parentheses");
25822   PopupItem (dlg->func_choice, "Is too long");
25823   PopupItem (dlg->func_choice, "Contains special term");
25824   SetValue (dlg->func_choice, 1);
25825 
25826   g = HiddenGroup (p, 0, 0, NULL);
25827   /* note  - need to also have string constraint list dialog */
25828   dlg->text = DialogText (g, "", 10, SearchFuncDlgTextChange);
25829   SetObjectExtra (dlg->text, dlg, NULL);
25830   Hide (dlg->text);
25831   dlg->string_constraint = StringConstraintDialog (g, NULL, FALSE, SearchFuncDialogChange, dlg);
25832   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->text, (HANDLE) dlg->string_constraint, NULL);
25833 
25834   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->func_choice, (HANDLE) g, NULL);
25835 
25836   return (DialoG) p;
25837 }
25838 
25839 
25840 typedef struct simplereplacedlg {
25841   DIALOG_MESSAGE_BLOCK
25842   TexT  replace;
25843   ButtoN whole_string;
25844   ButtoN weasel_to_putative;
25845 
25846   Nlm_ChangeNotifyProc     change_notify;
25847   Pointer                  change_userdata;
25848 } SimpleReplaceDlgData, PNTR SimpleReplaceDlgPtr;
25849 
25850 
ChangeSimpleReplaceText(TexT t)25851 static void ChangeSimpleReplaceText (TexT t)
25852 {
25853   SimpleReplaceDlgPtr dlg;
25854 
25855   dlg = (SimpleReplaceDlgPtr) GetObjectExtra (t);
25856   if (dlg == NULL) {
25857     return;
25858   }
25859 
25860   if (dlg->change_notify != NULL) {
25861     (dlg->change_notify) (dlg->change_userdata);
25862   }
25863 }
25864 
25865 
ChangeSimpleReplaceBtn(ButtoN b)25866 static void ChangeSimpleReplaceBtn (ButtoN b)
25867 {
25868   SimpleReplaceDlgPtr dlg;
25869 
25870   dlg = (SimpleReplaceDlgPtr) GetObjectExtra (b);
25871   if (dlg == NULL) {
25872     return;
25873   }
25874 
25875   if (dlg->change_notify != NULL) {
25876     (dlg->change_notify) (dlg->change_userdata);
25877   }
25878 }
25879 
25880 
SimpleReplaceFromDialog(DialoG d)25881 static Pointer SimpleReplaceFromDialog (DialoG d)
25882 {
25883   SimpleReplaceDlgPtr dlg;
25884   SimpleReplacePtr    simple_replace;
25885 
25886   dlg = (SimpleReplaceDlgPtr) GetObjectExtra (d);
25887   if (dlg == NULL) {
25888     return NULL;
25889   }
25890 
25891   simple_replace = SimpleReplaceNew();
25892   simple_replace->replace = JustSaveStringFromText (dlg->replace);
25893   simple_replace->whole_string = GetStatus (dlg->whole_string);
25894   simple_replace->weasel_to_putative = GetStatus (dlg->weasel_to_putative);
25895 
25896   return simple_replace;
25897 }
25898 
25899 
SimpleReplaceToDialog(DialoG d,Pointer data)25900 static void SimpleReplaceToDialog (DialoG d, Pointer data)
25901 {
25902   SimpleReplaceDlgPtr dlg;
25903   SimpleReplacePtr    simple_replace;
25904 
25905   dlg = (SimpleReplaceDlgPtr) GetObjectExtra (d);
25906   if (dlg == NULL) {
25907     return;
25908   }
25909 
25910   simple_replace = (SimpleReplacePtr) data;
25911   if (simple_replace == NULL) {
25912     SetTitle (dlg->replace, "");
25913     SetStatus (dlg->whole_string, FALSE);
25914     SetStatus (dlg->weasel_to_putative, FALSE);
25915   } else {
25916     SetTitle (dlg->replace, simple_replace->replace == NULL ? "" : simple_replace->replace);
25917     SetStatus (dlg->whole_string, simple_replace->whole_string);
25918     SetStatus (dlg->weasel_to_putative, simple_replace->weasel_to_putative);
25919   }
25920 }
25921 
25922 
SimpleReplaceDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)25923 NLM_EXTERN DialoG SimpleReplaceDialog
25924 (GrouP                    h,
25925  Nlm_ChangeNotifyProc     change_notify,
25926  Pointer                  change_userdata)
25927 {
25928   SimpleReplaceDlgPtr dlg;
25929   GrouP p, g;
25930 
25931   dlg = (SimpleReplaceDlgPtr) MemNew (sizeof (SimpleReplaceDlgData));
25932 
25933   p = HiddenGroup (h, 2, 0, NULL);
25934   SetObjectExtra (p, dlg, StdCleanupExtraProc);
25935 
25936   dlg->dialog = (DialoG) p;
25937   dlg->fromdialog = SimpleReplaceFromDialog;
25938   dlg->todialog = SimpleReplaceToDialog;
25939   dlg->change_notify = change_notify;
25940   dlg->change_userdata = change_userdata;
25941 
25942   dlg->replace = DialogText (p, "", 15, ChangeSimpleReplaceText);
25943   SetObjectExtra (dlg->replace, dlg, NULL);
25944   g = HiddenGroup (p, 2, 0, NULL);
25945   SetGroupSpacing (g, 10, 10);
25946   dlg->whole_string = CheckBox (g, "Replace entire string", ChangeSimpleReplaceBtn);
25947   SetObjectExtra (dlg->whole_string, dlg, NULL);
25948   dlg->weasel_to_putative = CheckBox (g, "Retain and normalize 'putative' synonym", ChangeSimpleReplaceBtn);
25949   SetObjectExtra (dlg->weasel_to_putative, dlg, NULL);
25950 
25951   return (DialoG) p;
25952 }
25953 
25954 
25955 typedef struct replacefuncdlg {
25956   DIALOG_MESSAGE_BLOCK
25957 
25958   PopuP func_type;
25959   DialoG simple_replace;
25960   TexT   text;
25961 
25962   Nlm_ChangeNotifyProc     change_notify;
25963   Pointer                  change_userdata;
25964 } ReplaceFuncDlgData, PNTR ReplaceFuncDlgPtr;
25965 
25966 
ChangeReplaceFuncPopup(PopuP p)25967 static void ChangeReplaceFuncPopup (PopuP p)
25968 {
25969   ReplaceFuncDlgPtr dlg;
25970   Int2 val;
25971 
25972   dlg = (ReplaceFuncDlgPtr) GetObjectExtra (p);
25973   if (dlg == NULL) {
25974     return;
25975   }
25976 
25977   val = GetValue (dlg->func_type);
25978   switch (val) {
25979     case 2:
25980       Show (dlg->simple_replace);
25981       Hide (dlg->text);
25982       break;
25983     case 3:
25984       Hide (dlg->simple_replace);
25985       Show (dlg->text);
25986       break;
25987     case 4:
25988       Hide (dlg->simple_replace);
25989       Hide (dlg->text);
25990       break;
25991     default:
25992       Hide (dlg->text);
25993       Hide (dlg->simple_replace);
25994       break;
25995   }
25996 
25997   if (dlg->change_notify != NULL) {
25998     (dlg->change_notify)(dlg->change_userdata);
25999   }
26000 }
26001 
26002 
ChangeReplaceFuncText(TexT t)26003 static void ChangeReplaceFuncText (TexT t)
26004 {
26005   ReplaceFuncDlgPtr dlg;
26006 
26007   dlg = (ReplaceFuncDlgPtr) GetObjectExtra (t);
26008   if (dlg == NULL) {
26009     return;
26010   }
26011 
26012   if (dlg->change_notify != NULL) {
26013     (dlg->change_notify)(dlg->change_userdata);
26014   }
26015 }
26016 
26017 
ReplaceFuncFromDialog(DialoG d)26018 static Pointer ReplaceFuncFromDialog (DialoG d)
26019 {
26020   ReplaceFuncDlgPtr dlg;
26021   ReplaceFuncPtr    replace_func;
26022   SimpleReplacePtr  simple_replace;
26023   Int2              val;
26024 
26025   dlg = (ReplaceFuncDlgPtr) GetObjectExtra (d);
26026   if (dlg == NULL) {
26027     return NULL;
26028   }
26029 
26030   replace_func = ValNodeNew (NULL);
26031   val = GetValue (dlg->func_type);
26032   switch (val) {
26033     case 2:
26034       replace_func->choice = ReplaceFunc_simple_replace;
26035       replace_func->data.ptrvalue = DialogToPointer (dlg->simple_replace);
26036       break;
26037     case 3:
26038       replace_func->choice = ReplaceFunc_haem_replace;
26039       replace_func->data.ptrvalue = SaveStringFromText (dlg->text);
26040       break;
26041     case 4:
26042       replace_func->choice = ReplaceFunc_simple_replace;
26043       simple_replace = SimpleReplaceNew();
26044       simple_replace->replace = StringSave ("hypothetical protein");
26045       simple_replace->whole_string = TRUE;
26046       simple_replace->weasel_to_putative = FALSE;
26047       replace_func->data.ptrvalue = simple_replace;
26048       break;
26049     default:
26050       replace_func = ValNodeFree (replace_func);
26051       break;
26052   }
26053   /* note - need to return null if it's empty */
26054   return replace_func;
26055 }
26056 
26057 
IsHypotheticalSimpleReplace(SimpleReplacePtr simple_replace)26058 static Boolean IsHypotheticalSimpleReplace (SimpleReplacePtr simple_replace)
26059 {
26060   if (simple_replace == NULL) {
26061     return FALSE;
26062   } else if (!simple_replace->whole_string || simple_replace->weasel_to_putative) {
26063     return FALSE;
26064   } else if (StringCmp (simple_replace->replace, "hypothetical protein") == 0) {
26065     return TRUE;
26066   } else {
26067     return FALSE;
26068   }
26069 }
26070 
26071 
ReplaceFuncToDialog(DialoG d,Pointer data)26072 static void ReplaceFuncToDialog (DialoG d, Pointer data)
26073 {
26074   ReplaceFuncDlgPtr dlg;
26075   ReplaceFuncPtr replace_func;
26076 
26077   dlg = (ReplaceFuncDlgPtr) GetObjectExtra (d);
26078   if (dlg == NULL) {
26079     return;
26080   }
26081 
26082   replace_func = (ReplaceFuncPtr) data;
26083   if (replace_func == NULL) {
26084     SetValue (dlg->func_type, 1);
26085   } else {
26086     switch (replace_func->choice) {
26087       case ReplaceFunc_simple_replace:
26088         if (IsHypotheticalSimpleReplace(replace_func->data.ptrvalue)) {
26089           SetValue (dlg->func_type, 4);
26090         } else {
26091           SetValue (dlg->func_type, 2);
26092           PointerToDialog (dlg->simple_replace, replace_func->data.ptrvalue);
26093         }
26094         break;
26095       case ReplaceFunc_haem_replace:
26096         SetValue (dlg->func_type, 3);
26097         SetTitle (dlg->text, replace_func->data.ptrvalue == NULL ? "" : replace_func->data.ptrvalue);
26098         break;
26099       default:
26100         SetValue (dlg->func_type, 1);
26101         break;
26102     }
26103   }
26104   ChangeReplaceFuncPopup (dlg->func_type);
26105 }
26106 
26107 
ReplaceFuncDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)26108 static DialoG ReplaceFuncDialog
26109 (GrouP                    h,
26110  Nlm_ChangeNotifyProc     change_notify,
26111  Pointer                  change_userdata)
26112 {
26113   ReplaceFuncDlgPtr dlg;
26114   GrouP p, g;
26115 
26116   dlg = (ReplaceFuncDlgPtr) MemNew (sizeof (ReplaceFuncDlgData));
26117 
26118   p = HiddenGroup (h, -1, 0, NULL);
26119   SetObjectExtra (p, dlg, StdCleanupExtraProc);
26120 
26121   dlg->dialog = (DialoG) p;
26122   dlg->fromdialog = ReplaceFuncFromDialog;
26123   dlg->todialog = ReplaceFuncToDialog;
26124   dlg->change_notify = change_notify;
26125   dlg->change_userdata = change_userdata;
26126 
26127   dlg->func_type = PopupList (p, TRUE, ChangeReplaceFuncPopup);
26128   SetObjectExtra (dlg->func_type, dlg, NULL);
26129   PopupItem (dlg->func_type, "None");
26130   PopupItem (dlg->func_type, "Simple");
26131   PopupItem (dlg->func_type, "Haem");
26132   PopupItem (dlg->func_type, "Hypothetical");
26133   SetValue (dlg->func_type, 1);
26134 
26135   g = HiddenGroup (p, 0, 0, NULL);
26136   dlg->simple_replace = SimpleReplaceDialog (g, change_notify, change_userdata);
26137   Hide (dlg->simple_replace);
26138   dlg->text = DialogText (g, "", 15, ChangeReplaceFuncText);
26139   Hide (dlg->text);
26140   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->simple_replace, (HANDLE) dlg->text, NULL);
26141 
26142   return (DialoG) p;
26143 }
26144 
26145 
26146 typedef struct replaceruledlg {
26147   DIALOG_MESSAGE_BLOCK
26148 
26149   DialoG replace_func;
26150   ButtoN move_to_note;
26151 
26152   Nlm_ChangeNotifyProc     change_notify;
26153   Pointer                  change_userdata;
26154 } ReplaceRuleDlgData, PNTR ReplaceRuleDlgPtr;
26155 
26156 
ChangeReplaceRuleBtn(ButtoN b)26157 static void ChangeReplaceRuleBtn (ButtoN b)
26158 {
26159   ReplaceRuleDlgPtr dlg;
26160 
26161   dlg = (ReplaceRuleDlgPtr) GetObjectExtra (b);
26162   if (dlg == NULL) {
26163     return;
26164   }
26165   if (dlg->change_notify != NULL) {
26166     (dlg->change_notify)(dlg->change_userdata);
26167   }
26168 }
26169 
26170 
ReplaceRuleToDialog(DialoG d,Pointer data)26171 static void ReplaceRuleToDialog (DialoG d, Pointer data)
26172 {
26173   ReplaceRuleDlgPtr dlg;
26174   ReplaceRulePtr rule;
26175 
26176   dlg = (ReplaceRuleDlgPtr) GetObjectExtra (d);
26177   if (dlg == NULL) {
26178     return;
26179   }
26180   rule = (ReplaceRulePtr) data;
26181   if (rule == NULL) {
26182     PointerToDialog (dlg->replace_func, NULL);
26183     SetStatus (dlg->move_to_note, FALSE);
26184   } else {
26185     PointerToDialog (dlg->replace_func, rule->replace_func);
26186     SetStatus (dlg->move_to_note, rule->move_to_note);
26187   }
26188   if (dlg->change_notify != NULL) {
26189     (dlg->change_notify)(dlg->change_userdata);
26190   }
26191 }
26192 
26193 
ReplaceRuleFromDialog(DialoG d)26194 static Pointer ReplaceRuleFromDialog (DialoG d)
26195 {
26196   ReplaceRuleDlgPtr dlg;
26197   ReplaceRulePtr rule;
26198 
26199   dlg = (ReplaceRuleDlgPtr) GetObjectExtra (d);
26200   if (dlg == NULL) {
26201     return NULL;
26202   }
26203   rule = ReplaceRuleNew();
26204   rule->replace_func =  DialogToPointer (dlg->replace_func);
26205   rule->move_to_note = GetStatus (dlg->move_to_note);
26206   if (rule->replace_func == NULL && !rule->move_to_note) {
26207     rule = ReplaceRuleFree (rule);
26208   }
26209   return rule;
26210 }
26211 
26212 
ChangeReplaceRuleFunc(Pointer data)26213 static void ChangeReplaceRuleFunc (Pointer data)
26214 {
26215   ReplaceRuleDlgPtr dlg;
26216   ValNodePtr replace_func;
26217 
26218   dlg = (ReplaceRuleDlgPtr) data;
26219   if (dlg == NULL) {
26220     return;
26221   }
26222 
26223   replace_func = DialogToPointer (dlg->replace_func);
26224   if (replace_func != NULL
26225       && replace_func->choice == ReplaceFunc_simple_replace
26226       && IsHypotheticalSimpleReplace (replace_func->data.ptrvalue)) {
26227     SetStatus (dlg->move_to_note, TRUE);
26228   }
26229 
26230   if (dlg->change_notify != NULL) {
26231     (dlg->change_notify)(dlg->change_userdata);
26232   }
26233 }
26234 
26235 
ReplaceRuleDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)26236 static DialoG ReplaceRuleDialog
26237 (GrouP                    h,
26238  Nlm_ChangeNotifyProc     change_notify,
26239  Pointer                  change_userdata)
26240 {
26241   ReplaceRuleDlgPtr dlg;
26242   GrouP p, g;
26243 
26244   dlg = (ReplaceRuleDlgPtr) MemNew (sizeof (ReplaceRuleDlgData));
26245 
26246   p = NormalGroup (h, -1, 0, "Replacement Action", programFont, NULL);
26247   SetObjectExtra (p, dlg, StdCleanupExtraProc);
26248 
26249   dlg->dialog = (DialoG) p;
26250   dlg->fromdialog = ReplaceRuleFromDialog;
26251   dlg->todialog = ReplaceRuleToDialog;
26252   dlg->change_notify = change_notify;
26253   dlg->change_userdata = change_userdata;
26254 
26255   g = HiddenGroup (p, 2, 0, NULL);
26256   SetGroupSpacing (g, 10, 10);
26257   StaticPrompt (g, "Rule", 0, popupMenuHeight, programFont, 'r');
26258   dlg->replace_func = ReplaceFuncDialog (g, ChangeReplaceRuleFunc, dlg);
26259   dlg->move_to_note = CheckBox (p, "Move original to note", ChangeReplaceRuleBtn);
26260   SetObjectExtra (dlg->move_to_note, dlg, NULL);
26261 
26262   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) dlg->move_to_note, NULL);
26263 
26264 
26265   return (DialoG) p;
26266 }
26267 
26268 
26269 typedef struct suspectruledlg {
26270   DIALOG_MESSAGE_BLOCK
26271 
26272   PopuP rule_type;
26273   DialoG find;
26274   DialoG except;
26275   DialoG replace;
26276   DialoG feat_constraint;
26277   TexT   description;
26278   ButtoN is_fatal;
26279 
26280   Nlm_ChangeNotifyProc     change_notify;
26281   Pointer                  change_userdata;
26282 } SuspectRuleDlgData, PNTR SuspectRuleDlgPtr;
26283 
26284 
SuspectRuleDlgPopupChange(PopuP p)26285 static void SuspectRuleDlgPopupChange (PopuP p)
26286 {
26287   SuspectRuleDlgPtr dlg;
26288 
26289   dlg = (SuspectRuleDlgPtr) GetObjectExtra (p);
26290   if (dlg == NULL) {
26291     return;
26292   }
26293   if (dlg->change_notify != NULL) {
26294     (dlg->change_notify)(dlg->change_userdata);
26295   }
26296 }
26297 
26298 
SuspectRuleFromDialog(DialoG d)26299 static Pointer SuspectRuleFromDialog (DialoG d)
26300 {
26301   SuspectRuleDlgPtr dlg;
26302   SuspectRulePtr new_rule;
26303 
26304   dlg = (SuspectRuleDlgPtr) GetObjectExtra (d);
26305   if (dlg == NULL) {
26306     return NULL;
26307   }
26308 
26309   new_rule = SuspectRuleNew();
26310   new_rule->rule_type = GetValue (dlg->rule_type) - 1;
26311   new_rule->find = DialogToPointer (dlg->find);
26312   new_rule->except = DialogToPointer (dlg->except);
26313   if (IsSearchFuncEmpty(new_rule->except)) {
26314     new_rule->except = SearchFuncFree (new_rule->except);
26315   }
26316   new_rule->replace = DialogToPointer (dlg->replace);
26317   new_rule->feat_constraint = DialogToPointer (dlg->feat_constraint);
26318   new_rule->description = SaveStringFromText (dlg->description);
26319   new_rule->fatal = GetStatus (dlg->is_fatal);
26320   return new_rule;
26321 }
26322 
26323 
SuspectRuleToDialog(DialoG d,Pointer data)26324 static void SuspectRuleToDialog (DialoG d, Pointer data)
26325 {
26326   SuspectRuleDlgPtr dlg;
26327   SuspectRulePtr new_rule;
26328   SearchFuncPtr func;
26329   StringConstraintPtr scp;
26330 
26331   dlg = (SuspectRuleDlgPtr) GetObjectExtra (d);
26332   if (dlg == NULL) {
26333     return;
26334   }
26335 
26336   new_rule = (SuspectRulePtr) data;
26337   if (new_rule == NULL) {
26338     SetValue (dlg->rule_type, 1);
26339     scp = StringConstraintNew();
26340     scp->case_sensitive = FALSE;
26341     scp->ignore_weasel = TRUE;
26342     func = ValNodeNew (NULL);
26343     func->choice = SearchFunc_string_constraint;
26344     func->data.ptrvalue = scp;
26345     PointerToDialog (dlg->find, func);
26346     func = SearchFuncFree (func);
26347     PointerToDialog (dlg->except, NULL);
26348     PointerToDialog (dlg->replace, NULL);
26349     PointerToDialog (dlg->feat_constraint, NULL);
26350     SetTitle (dlg->description, "");
26351     SetStatus (dlg->is_fatal, FALSE);
26352   } else {
26353     SetValue (dlg->rule_type, new_rule->rule_type + 1);
26354     PointerToDialog (dlg->find, new_rule->find);
26355     PointerToDialog (dlg->except, new_rule->except);
26356     PointerToDialog (dlg->replace, new_rule->replace);
26357     PointerToDialog (dlg->feat_constraint, new_rule->feat_constraint);
26358     SetTitle (dlg->description, new_rule->description);
26359     SetStatus (dlg->is_fatal, (Boolean) new_rule->fatal);
26360   }
26361 }
26362 
26363 
SuspectRuleDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)26364 NLM_EXTERN DialoG SuspectRuleDialog
26365 (GrouP                    h,
26366  Nlm_ChangeNotifyProc     change_notify,
26367  Pointer                  change_userdata)
26368 {
26369   SuspectRuleDlgPtr dlg;
26370   GrouP p;
26371   Int2 val;
26372   GrouP g1, g2;
26373   PrompT ppt;
26374 
26375   dlg = (SuspectRuleDlgPtr) MemNew (sizeof (SuspectRuleDlgData));
26376 
26377   p = HiddenGroup (h, -1, 0, NULL);
26378   SetObjectExtra (p, dlg, StdCleanupExtraProc);
26379 
26380   dlg->dialog = (DialoG) p;
26381   dlg->fromdialog = SuspectRuleFromDialog;
26382   dlg->todialog = SuspectRuleToDialog;
26383   dlg->change_notify = change_notify;
26384   dlg->change_userdata = change_userdata;
26385 
26386   dlg->rule_type = PopupList (p, TRUE, SuspectRuleDlgPopupChange);
26387   SetObjectExtra (dlg->rule_type, dlg, NULL);
26388   for (val = 0; val <= Fix_type_gene; val++) {
26389     PopupItem (dlg->rule_type, SummarizeFixType(val));
26390   }
26391   SetValue (dlg->rule_type, 1);
26392 
26393   g1 = NormalGroup (p, 0, 0, "Where Product Matches", programFont, NULL);
26394   dlg->find = SearchFuncDialog (g1, change_notify, change_userdata);
26395   g2 = NormalGroup (p, 0, 0, "But Product does not Match", programFont, NULL);
26396   dlg->except = SearchFuncDialog (g2, change_notify, change_userdata);
26397   dlg->replace = ReplaceRuleDialog (p, change_notify, change_userdata);
26398   dlg->is_fatal = CheckBox(p, "Fatal", NULL);
26399   dlg->feat_constraint = ConstraintSetDialog (p, dlg->change_notify, dlg->change_userdata);
26400   ppt = StaticPrompt (p, "Description", 0, popupMenuHeight, programFont, 'c');
26401   dlg->description = ScrollText (p, 20, 3, programFont, TRUE, NULL);
26402 
26403   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->rule_type, (HANDLE) g1, (HANDLE) g2, (HANDLE) dlg->replace,
26404                               (HANDLE) dlg->feat_constraint,
26405                               (HANDLE) ppt,
26406                               (HANDLE) dlg->description,
26407                               NULL);
26408 
26409   return (DialoG) p;
26410 }
26411 
26412 
EditObjectFreeSuspectRule(Pointer rule)26413 static Pointer EditObjectFreeSuspectRule (Pointer rule)
26414 {
26415   return (Pointer) SuspectRuleFree ((SuspectRulePtr)rule);
26416 }
26417 
26418 
EditSuspectRule(SuspectRulePtr orig)26419 static SuspectRulePtr EditSuspectRule (SuspectRulePtr orig)
26420 {
26421   return EditObject (orig, "Suspect Rule", (IsObjectEmpty) IsSuspectRuleEmpty, EditObjectFreeSuspectRule, SuspectRuleDialog);
26422 }
26423 
26424 
26425 /* suspect product rule editor */
26426 typedef struct suspectproductruleeditorform {
26427   FORM_MESSAGE_BLOCK
26428   DoC    rule_summary;
26429 
26430   SuspectRuleSetPtr rule_list;
26431   CharPtr    last_filename;
26432   Boolean    unsaved;
26433   FonT       summary_font;
26434 } SuspectProductRuleEditorFormData, PNTR SuspectProductRuleEditorFormPtr;
26435 
CleanupSuspectProductRuleEditorForm(GraphiC g,VoidPtr data)26436 static void CleanupSuspectProductRuleEditorForm (GraphiC g, VoidPtr data)
26437 
26438 {
26439   SuspectProductRuleEditorFormPtr f;
26440 
26441   f = (SuspectProductRuleEditorFormPtr) data;
26442   if (f != NULL) {
26443     f->rule_list = SuspectRuleSetFree (f->rule_list);
26444     f->last_filename = MemFree (f->last_filename);
26445   }
26446   StdCleanupFormProc (g, data);
26447 }
26448 
26449 
SetupSuspectProductRuleEditorFont(SuspectProductRuleEditorFormPtr f)26450 static void SetupSuspectProductRuleEditorFont (SuspectProductRuleEditorFormPtr f)
26451 
26452 {
26453   if (f == NULL) return;
26454 
26455 #ifdef WIN_MAC
26456   f->summary_font = ParseFont ("Times,12");
26457 #endif
26458 #ifdef WIN_MSWIN
26459   f->summary_font = ParseFont ("Times New Roman,12");
26460 #endif
26461 #ifdef WIN_MOTIF
26462   f->summary_font = ParseFont ("Times,12");
26463 #endif
26464 }
26465 
26466 
SummarizeSuspectProductRule(DoC doc,SuspectRuleSetPtr rule_list,FonT font)26467 static void SummarizeSuspectProductRule (DoC doc, SuspectRuleSetPtr rule_list, FonT font)
26468 {
26469   SuspectRulePtr rule;
26470   CharPtr    str;
26471   CharPtr    tmp;
26472   Int4       pos = 1;
26473   RecT       r;
26474   ParData    ParFmt = {FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0};
26475   ColData    ColFmt[] =
26476   {
26477     {kNumberColumnWidth, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
26478     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
26479     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
26480     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
26481     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
26482     {12, 0, 1, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},
26483     {0, 0, 80, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, TRUE}
26484   };
26485 
26486 
26487   Reset (doc);
26488 
26489   ObjectRect (doc, &r);
26490   InsetRect (&r, 4, 4);
26491 
26492   ColFmt[5].pixWidth = stdCharWidth;
26493   ColFmt[6].pixWidth = r.right - r.left - stdCharWidth - 48 - kNumberColumnWidth;
26494 
26495   if (font == NULL) font = programFont;
26496 
26497   if (rule_list == NULL) {
26498     AppendText (doc, "(Click here to start a new rule list)", NULL, NULL, font);
26499   } else {
26500     AppendText (doc, "(Click here to insert a rule at the beginning of the list)", NULL, NULL, font);
26501     for (rule = rule_list; rule != NULL; rule = rule->next) {
26502       str = SummarizeSuspectRule (rule);
26503       tmp = (CharPtr) MemNew (sizeof (Char) * (StringLen (str) + 25));
26504       sprintf (tmp, "%d\t\t\t\t\tC\t%s\n", pos, str);
26505       str = MemFree (str);
26506       pos++;
26507       AppendText (doc, tmp, &ParFmt, ColFmt, font);
26508       tmp = MemFree (tmp);
26509     }
26510     AppendText (doc, "(Click here to insert a rule at the end of the list)", NULL, NULL, font);
26511   }
26512   UpdateDocument (doc, 0, 0);
26513 }
26514 
26515 
SetSuspectProductRuleEditorFileItems(SuspectProductRuleEditorFormPtr frm)26516 static void SetSuspectProductRuleEditorFileItems (SuspectProductRuleEditorFormPtr frm)
26517 
26518 {
26519   IteM  i;
26520 
26521   if (frm != NULL) {
26522     i = FindFormMenuItem ((BaseFormPtr) frm, VIB_MSG_OPEN);
26523     SafeSetTitle (i, "Load Rule List");
26524     SafeEnable (i);
26525 
26526     i = FindFormMenuItem ((BaseFormPtr) frm, VIB_MSG_IMPORT);
26527     SafeSetTitle (i, "Add Rules from File to List");
26528     SafeEnable (i);
26529 
26530     i = FindFormMenuItem ((BaseFormPtr) frm, VIB_MSG_SAVE);
26531     SafeSetTitle (i, "Save Rule List");
26532   }
26533 }
26534 
26535 
OpenSuspectProductRuleFile(ForM f,CharPtr filename)26536 static Boolean OpenSuspectProductRuleFile (ForM f, CharPtr filename)
26537 
26538 {
26539   SuspectProductRuleEditorFormPtr mefp;
26540   Boolean            rval = FALSE;
26541   CharPtr            extension;
26542   Char               path [PATH_MAX];
26543   AsnIoPtr           aip;
26544   SuspectRuleSetPtr  rule_list;
26545 
26546   mefp = (SuspectProductRuleEditorFormPtr) GetObjectExtra (f);
26547   if (mefp != NULL) {
26548     if (mefp->unsaved) {
26549       if (Message (MSG_YN, "Do you want to save changes to the current file?") == ANS_YES) {
26550         if (!SaveMacroFile(f, mefp->last_filename)) {
26551            return FALSE;
26552         }
26553       }
26554     }
26555     path [0] = '\0';
26556     StringNCpy_0 (path, filename, sizeof (path));
26557     extension = NULL;
26558     if (path [0] != '\0' || GetInputFileName (path, sizeof (path), extension, "TEXT")) {
26559       aip = AsnIoOpen (path, "r");
26560       if (aip == NULL) {
26561         Message (MSG_ERROR, "Unable to open %s", path);
26562       } else {
26563         rule_list = SuspectRuleSetAsnRead (aip, NULL);
26564         if (rule_list == NULL) {
26565           Message (MSG_ERROR, "Unable to read rule list from %s.", path);
26566         } else {
26567           mefp->rule_list = SuspectRuleSetFree (mefp->rule_list);
26568           mefp->rule_list = rule_list;
26569           mefp->last_filename = MemFree (mefp->last_filename);
26570           mefp->last_filename = StringSave (path);
26571           mefp->unsaved = FALSE;
26572           rval = TRUE;
26573           SetSuspectProductRuleEditorFileItems (mefp);
26574           SummarizeSuspectProductRule (mefp->rule_summary, mefp->rule_list, mefp->summary_font);
26575         }
26576         AsnIoClose (aip);
26577       }
26578     }
26579   }
26580   return rval;
26581 }
26582 
26583 
SaveSuspectProductRuleFile(ForM f,CharPtr filename)26584 static Boolean SaveSuspectProductRuleFile (ForM f, CharPtr filename)
26585 
26586 {
26587   SuspectProductRuleEditorFormPtr mefp;
26588   Boolean            rval = FALSE;
26589   Char               path [PATH_MAX];
26590   AsnIoPtr           aip;
26591 
26592   mefp = (SuspectProductRuleEditorFormPtr) GetObjectExtra (f);
26593   if (mefp != NULL) {
26594     path [0] = '\0';
26595     StringNCpy_0 (path, filename, sizeof (path));
26596     if (path [0] != '\0' || GetOutputFileName (path, sizeof (path), NULL)) {
26597       aip = AsnIoOpen (path, "w");
26598       if (aip == NULL) {
26599         Message (MSG_ERROR, "Unable to open %s", path);
26600       } else {
26601         SuspectRuleSetAsnWrite (mefp->rule_list, aip, NULL);
26602         AsnIoClose (aip);
26603         mefp->last_filename = MemFree (mefp->last_filename);
26604         mefp->last_filename = StringSave (path);
26605         mefp->unsaved = FALSE;
26606         rval = TRUE;
26607       }
26608     }
26609   }
26610   return rval;
26611 }
26612 
26613 
ImportSuspectProductRuleFile(ForM f,CharPtr filename)26614 static Boolean ImportSuspectProductRuleFile (ForM f, CharPtr filename)
26615 
26616 {
26617   SuspectProductRuleEditorFormPtr mefp;
26618   Boolean            rval = FALSE;
26619   CharPtr            extension;
26620   Char               path [PATH_MAX];
26621   AsnIoPtr           aip;
26622   SuspectRuleSetPtr  rule_list, last;
26623 
26624   mefp = (SuspectProductRuleEditorFormPtr) GetObjectExtra (f);
26625   if (mefp == NULL) return FALSE;
26626   path [0] = '\0';
26627   StringNCpy_0 (path, filename, sizeof (path));
26628   extension = NULL;
26629   if (path [0] != '\0' || GetInputFileName (path, sizeof (path), extension, "TEXT")) {
26630     aip = AsnIoOpen (path, "r");
26631     if (aip == NULL) {
26632       Message (MSG_ERROR, "Unable to open %s", path);
26633     } else {
26634       rule_list = SuspectRuleSetAsnRead (aip, NULL);
26635       if (rule_list == NULL) {
26636         Message (MSG_ERROR, "Unable to read rule list from %s.", path);
26637       } else {
26638         if (mefp->rule_list == NULL) {
26639           mefp->rule_list = rule_list;
26640         } else {
26641           last = mefp->rule_list;
26642           while (last->next != NULL) {
26643             last = last->next;
26644           }
26645           last->next = rule_list;
26646         }
26647         mefp->unsaved = TRUE;
26648         rval = TRUE;
26649         SetSuspectProductRuleEditorFileItems (mefp);
26650         SummarizeSuspectProductRule (mefp->rule_summary, mefp->rule_list, mefp->summary_font);
26651       }
26652       AsnIoClose (aip);
26653     }
26654   }
26655   return rval;
26656 }
26657 
26658 
SuspectProductRuleEditorFormMessage(ForM f,Int2 mssg)26659 static void SuspectProductRuleEditorFormMessage (ForM f, Int2 mssg)
26660 
26661 {
26662   SuspectProductRuleEditorFormPtr  mefp;
26663 
26664   mefp = (SuspectProductRuleEditorFormPtr) GetObjectExtra (f);
26665   if (mefp != NULL) {
26666     switch (mssg) {
26667       case VIB_MSG_OPEN :
26668         OpenSuspectProductRuleFile (f, NULL);
26669         break;
26670       case VIB_MSG_IMPORT :
26671         ImportSuspectProductRuleFile (f, NULL);
26672         break;
26673       case VIB_MSG_SAVE :
26674         SaveSuspectProductRuleFile (f, mefp->last_filename);
26675         break;
26676       case VIB_MSG_SAVE_AS :
26677         SaveSuspectProductRuleFile (f, NULL);
26678         break;
26679       case VIB_MSG_CLOSE:
26680       case VIB_MSG_QUIT:
26681         if (mefp->unsaved) {
26682           if (Message (MSG_YN, "Do you want to save changes to the current file?") == ANS_YES) {
26683             if (SaveSuspectProductRuleFile(f, mefp->last_filename)) {
26684               Remove (mefp->form);
26685             }
26686           }
26687         }
26688         Remove (mefp->form);
26689         break;
26690       case NUM_VIB_MSG + 2:
26691         /* sort by find */
26692         SortSuspectRuleSetByFind(&(mefp->rule_list));
26693         SetSuspectProductRuleEditorFileItems (mefp);
26694         SummarizeSuspectProductRule (mefp->rule_summary, mefp->rule_list, mefp->summary_font);
26695         break;
26696       case NUM_VIB_MSG + 3:
26697         /* sort by fix-type, then find */
26698         SortSuspectRuleSetByFixTypeThenFind(&(mefp->rule_list));
26699         SetSuspectProductRuleEditorFileItems (mefp);
26700         SummarizeSuspectProductRule (mefp->rule_summary, mefp->rule_list, mefp->summary_font);
26701         break;
26702       default :
26703         break;
26704     }
26705   }
26706 }
26707 
26708 
UpdateSuspectProductRuleSummary(SuspectProductRuleEditorFormPtr f,Int4 scroll_pos)26709 static void UpdateSuspectProductRuleSummary (SuspectProductRuleEditorFormPtr f, Int4 scroll_pos)
26710 {
26711   Int4 scroll_max;
26712   BaR  sb_vert;
26713 
26714   if (f == NULL) return;
26715 
26716   f->unsaved = TRUE;
26717   SetSuspectProductRuleEditorFileItems (f);
26718   SummarizeSuspectProductRule (f->rule_summary, f->rule_list, f->summary_font);
26719   if (scroll_pos > 0) {
26720     sb_vert = GetSlateVScrollBar ((SlatE) f->rule_summary);
26721     scroll_max = GetBarMax (sb_vert);
26722     if (scroll_pos > scroll_max) {
26723       scroll_pos = scroll_max;
26724     }
26725     CorrectBarValue (sb_vert, scroll_pos);
26726   }
26727 }
26728 
26729 
CloneSuspectProductRuleItem(SuspectProductRuleEditorFormPtr f,Int2 item)26730 static Boolean CloneSuspectProductRuleItem (SuspectProductRuleEditorFormPtr f, Int2 item)
26731 {
26732   SuspectRulePtr        this_rule = NULL, new_rule;
26733   Int2                  pos;
26734   Int4                  scroll_pos;
26735   BaR                   sb_vert;
26736 
26737   if (f == NULL || item == 0 || f->rule_list == NULL) {
26738     return FALSE;
26739   }
26740 
26741   pos = 1;
26742   this_rule = f->rule_list;
26743   while (pos < item && this_rule != NULL) {
26744     pos++;
26745     this_rule = this_rule->next;
26746   }
26747   if (this_rule == NULL) {
26748     return FALSE;
26749   }
26750   new_rule = AsnIoMemCopy (this_rule, (AsnReadFunc) SuspectRuleAsnRead, (AsnWriteFunc) SuspectRuleAsnWrite);
26751   if (new_rule != NULL) {
26752     new_rule->next = this_rule->next;
26753     this_rule->next = new_rule;
26754   }
26755 
26756   /* get current scroll position */
26757   sb_vert = GetSlateVScrollBar ((SlatE) f->rule_summary);
26758   scroll_pos = GetBarValue (sb_vert);
26759   /* we will want to increase the scroll position after each addition
26760    * note that we need to get the scroll bar and check the initial position
26761    * each time - if there was no scroll bar after the last update, scroll_pos
26762    * needs to be zero to start.
26763    */
26764   scroll_pos++;
26765 
26766   /* update summary */
26767   UpdateSuspectProductRuleSummary (f, scroll_pos);
26768   return TRUE;
26769 }
26770 
26771 
AddSuspectProductRule(SuspectProductRuleEditorFormPtr f,Int4 item)26772 static void AddSuspectProductRule (SuspectProductRuleEditorFormPtr f, Int4 item)
26773 {
26774   SuspectRulePtr new_rule, prev_rule = NULL;
26775   Int2                  pos;
26776   Int4                  scroll_pos;
26777   BaR                   sb_vert;
26778 
26779   if (f == NULL) {
26780     return;
26781   }
26782 
26783   new_rule = EditSuspectRule(NULL);
26784   if (new_rule == NULL) {
26785     return;
26786   }
26787 
26788   if (f->rule_list == NULL || item == 0) {
26789     new_rule->next = f->rule_list;
26790     f->rule_list = new_rule;
26791   } else if (item > 0) {
26792     pos = 1;
26793     prev_rule = f->rule_list;
26794     while (pos < item && prev_rule->next != NULL) {
26795       pos++;
26796       prev_rule = prev_rule->next;
26797     }
26798     if (prev_rule == NULL) {
26799       new_rule->next = f->rule_list;
26800       f->rule_list = new_rule;
26801     } else {
26802       new_rule->next = prev_rule->next;
26803       prev_rule->next = new_rule;
26804     }
26805   }
26806 
26807   /* get current scroll position */
26808   sb_vert = GetSlateVScrollBar ((SlatE) f->rule_summary);
26809   scroll_pos = GetBarValue (sb_vert);
26810   /* we will want to increase the scroll position after each addition
26811    * note that we need to get the scroll bar and check the initial position
26812    * each time - if there was no scroll bar after the last update, scroll_pos
26813    * needs to be zero to start.
26814    */
26815   scroll_pos++;
26816 
26817   UpdateSuspectProductRuleSummary (f, scroll_pos);
26818   f->unsaved = TRUE;
26819 }
26820 
26821 
EditSuspectProductRuleItem(SuspectProductRuleEditorFormPtr f,Int2 item)26822 static Boolean EditSuspectProductRuleItem (SuspectProductRuleEditorFormPtr f, Int2 item)
26823 {
26824   Boolean rval = FALSE;
26825   SuspectRulePtr vnp, vnp_prev = NULL, new_rule;
26826 
26827   if (f == NULL) return FALSE;
26828 
26829   for (vnp = f->rule_list; vnp != NULL && item > 1; vnp = vnp->next, item--) {
26830     vnp_prev = vnp;
26831   }
26832   if (vnp != NULL) {
26833     new_rule = EditSuspectRule (vnp);
26834     if (new_rule != NULL) {
26835       if (vnp_prev == NULL) {
26836         f->rule_list = new_rule;
26837       } else {
26838         vnp_prev->next = new_rule;
26839       }
26840       new_rule->next = vnp->next;
26841       vnp->next = NULL;
26842       vnp = SuspectRuleFree (vnp);
26843       rval = TRUE;
26844     }
26845   }
26846   return rval;
26847 }
26848 
26849 
ClickSuspectProductRuleDoc(DoC d,PoinT pt)26850 static void ClickSuspectProductRuleDoc (DoC d, PoinT pt)
26851 {
26852   Int2               item, row, col;
26853   RecT               rct;
26854   SuspectProductRuleEditorFormPtr f;
26855   SuspectRuleSetPtr  vnp, vnp_prev = NULL, two_prev = NULL, vnp_next;
26856   Boolean            changed = FALSE;
26857   BaR                sb_vert = NULL;
26858   Int2               scroll_pos = 0;
26859 
26860   f = (SuspectProductRuleEditorFormPtr) GetObjectExtra (d);
26861   if (f == NULL) return;
26862 
26863   MapDocPoint (d, pt, &item, &row, &col, &rct);
26864   if (item == 0 && row == 0 && f->rule_list == NULL) {
26865     AddSuspectProductRule (f, 0);
26866   } else if (item > 0 && row > 0) {
26867     if (item == 1) {
26868       /* add to beginning of list */
26869       AddSuspectProductRule (f, 0);
26870     } else if (item == CountSuspectRuleSet (f->rule_list) + 2) {
26871       /* add to end of list */
26872       AddSuspectProductRule (f, item);
26873     } else {
26874       /* correct for explanatory line */
26875       item--;
26876       sb_vert = GetSlateVScrollBar ((SlatE) f->rule_summary);
26877       scroll_pos = GetBarValue (sb_vert);
26878       switch (col) {
26879         case 2:
26880           /* delete this item */
26881           for (vnp = f->rule_list; vnp != NULL && item > 1; vnp = vnp->next, item--) {
26882             vnp_prev = vnp;
26883           }
26884           if (vnp != NULL) {
26885             if (vnp_prev == NULL) {
26886               f->rule_list = vnp->next;
26887             } else {
26888               vnp_prev->next = vnp->next;
26889             }
26890             vnp->next = NULL;
26891             vnp = SuspectRuleFree (vnp);
26892             changed = TRUE;
26893           }
26894           break;
26895         case 3:
26896           /* move this item up */
26897           for (vnp = f->rule_list; vnp != NULL && item > 1; vnp = vnp->next, item--) {
26898             two_prev = vnp_prev;
26899             vnp_prev = vnp;
26900           }
26901           if (vnp != NULL && vnp_prev != NULL) {
26902             vnp_prev->next = vnp->next;
26903             vnp->next = vnp_prev;
26904             if (two_prev == NULL) {
26905               f->rule_list = vnp;
26906             } else {
26907               two_prev->next = vnp;
26908             }
26909             /* decrease the scroll position, so cursor will still be over the same item */
26910             scroll_pos--;
26911             changed = TRUE;
26912           }
26913           break;
26914         case 4:
26915           /* move this item down */
26916           for (vnp = f->rule_list; vnp != NULL && item > 1; vnp = vnp->next, item--) {
26917             vnp_prev = vnp;
26918           }
26919           if (vnp != NULL && vnp->next != NULL) {
26920             vnp_next = vnp->next;
26921             vnp->next = vnp_next->next;
26922             vnp_next->next = vnp;
26923             if (vnp_prev == NULL) {
26924               f->rule_list = vnp_next;
26925             } else {
26926               vnp_prev->next = vnp_next;
26927             }
26928             /* increase the scroll position, so cursor will still be over the same item */
26929             scroll_pos++;
26930             changed = TRUE;
26931           }
26932           break;
26933         case 5:
26934           /* insert item */
26935           if (pt.y >= rct.top && pt.y <= rct.top + 4) {
26936             /* insert macro before this one */
26937             AddSuspectProductRule (f, item - 1);
26938           } else if (pt.y >= rct.bottom - 4 && pt.y <= rct.bottom) {
26939             /* insert macro after this one */
26940             AddSuspectProductRule (f, item);
26941           }
26942           break;
26943         case 6:
26944           /* clone item */
26945           CloneSuspectProductRuleItem (f, item);
26946           changed = TRUE;
26947           break;
26948         case 7:
26949           /* edit this item */
26950           changed = EditSuspectProductRuleItem (f, item);
26951           break;
26952       }
26953     }
26954   }
26955   if (changed) {
26956     f->unsaved = TRUE;
26957     UpdateSuspectProductRuleSummary (f, scroll_pos);
26958   }
26959 }
26960 
26961 
DrawSuspectProductRuleDocControls(DoC d,RectPtr r,Int2 item,Int2 firstLine)26962 static void DrawSuspectProductRuleDocControls (DoC d, RectPtr r, Int2 item, Int2 firstLine)
26963 
26964 {
26965   SuspectProductRuleEditorFormPtr dlg;
26966   RecT               rct;
26967   Int4               width;
26968   PoinT              pt1, pt2;
26969   Int4               num_items;
26970 
26971   dlg = (SuspectProductRuleEditorFormPtr) GetObjectExtra (d);
26972   if (dlg == NULL) return;
26973 
26974   num_items = CountSuspectRuleSet (dlg->rule_list);
26975 
26976   /* don't draw controls for explanatory text */
26977   if (item == 1 || item >= num_items + 2) return;
26978 
26979   if (dlg != NULL && r != NULL && item > 0 && firstLine == 0) {
26980     rct = *r;
26981 
26982     rct.left += kNumberColumnWidth;
26983 
26984     width = 10;
26985     /* draw X for deletion */
26986     pt1.x = rct.left + 1;
26987     pt1.y = rct.top + 1;
26988     pt2.x = pt1.x + width;
26989     pt2.y = pt1.y + width;
26990     DrawLine (pt1, pt2);
26991     pt1.x = rct.left + 1;
26992     pt1.y = rct.top + 1 + width;
26993     pt2.x = pt1.x + width;
26994     pt2.y = rct.top + 1;
26995     DrawLine (pt1, pt2);
26996 
26997     /* draw up arrow for moving step up */
26998     if (item > 2) {
26999       pt1.x = rct.left + width + 3;
27000       pt1.y = rct.top + 3;
27001       pt2.x = pt1.x + 5;
27002       pt2.y = rct.top + 1;
27003       DrawLine (pt1, pt2);
27004       pt1.x = pt2.x + 5;
27005       DrawLine (pt1, pt2);
27006       pt1.x = pt2.x;
27007       pt1.y = pt2.y + width;
27008       DrawLine (pt1, pt2);
27009     }
27010     /* draw up arrow for moving step up */
27011     if (item < num_items + 1) {
27012       pt1.x = rct.left + 2 * width + 5;
27013       pt1.y = rct.top + width - 2;
27014       pt2.x = pt1.x + 5;
27015       pt2.y = rct.top + width + 1;
27016       DrawLine (pt1, pt2);
27017       pt1.x = pt2.x + 5;
27018       DrawLine (pt1, pt2);
27019       pt1.x = pt2.x;
27020       pt1.y = rct.top + 1;
27021       DrawLine (pt1, pt2);
27022     }
27023 
27024     /* draw insertion controls */
27025     pt1.x = rct.left + 3 * width + 7;
27026     pt1.y = rct.top + 4;
27027     pt2.x = pt1.x + width;
27028     pt2.y = rct.top;
27029     if (item > 2) {
27030       DrawLine (pt1, pt2);
27031     }
27032     pt1.y = rct.bottom - 4;
27033     pt2.y = rct.bottom;
27034     if (item < num_items + 1) {
27035       DrawLine (pt1, pt2);
27036     }
27037   }
27038 }
27039 
27040 
ListSuspectRuleMatches(ButtoN b)27041 static void ListSuspectRuleMatches (ButtoN b)
27042 {
27043   SuspectProductRuleEditorFormPtr  f;
27044   ValNodePtr sep_list;
27045   Char         path [PATH_MAX];
27046   FILE         *fp;
27047 
27048   f = (SuspectProductRuleEditorFormPtr) GetObjectExtra (b);
27049   if (f == NULL) {
27050     return;
27051   }
27052 
27053   sep_list = GetViewedSeqEntryList ();
27054   if (sep_list == NULL) {
27055     return;
27056   }
27057 
27058   TmpNam (path);
27059   fp = FileOpen (path, "wb");
27060   if (fp != NULL) {
27061     PrintSuspectRuleMatches (sep_list->data.ptrvalue, f->rule_list, fp);
27062     FileClose (fp);
27063     LaunchGeneralTextViewer (path, "Suspect Rule Matches");
27064     FileRemove (path);
27065   }
27066 
27067   sep_list = ValNodeFree (sep_list);
27068 }
27069 
27070 
ApplySuspectRuleFixes(ButtoN b)27071 static void ApplySuspectRuleFixes (ButtoN b)
27072 {
27073   SuspectProductRuleEditorFormPtr  f;
27074   ValNodePtr sep_list;
27075   Char         path [PATH_MAX];
27076   FILE         *fp;
27077   SeqEntryPtr  sep;
27078 
27079   f = (SuspectProductRuleEditorFormPtr) GetObjectExtra (b);
27080   if (f == NULL) {
27081     return;
27082   }
27083 
27084   sep_list = GetViewedSeqEntryList ();
27085   if (sep_list == NULL) {
27086     return;
27087   }
27088   sep = sep_list->data.ptrvalue;
27089 
27090   TmpNam (path);
27091   fp = FileOpen (path, "wb");
27092   if (fp != NULL) {
27093     ApplySuspectRuleFixesToSeqEntry (sep, f->rule_list, fp);
27094 
27095     FileClose (fp);
27096     LaunchGeneralTextViewer (path, "Suspect Rule Fixes");
27097     FileRemove (path);
27098   }
27099 
27100   sep_list = ValNodeFree (sep_list);
27101 }
27102 
27103 
MakeProductUpdateTable(ButtoN b)27104 static void MakeProductUpdateTable (ButtoN b)
27105 {
27106   SuspectProductRuleEditorFormPtr  f;
27107   ValNodePtr sep_list;
27108   Char         path [PATH_MAX];
27109   FILE         *fp;
27110   SeqEntryPtr  sep;
27111 
27112   f = (SuspectProductRuleEditorFormPtr) GetObjectExtra (b);
27113   if (f == NULL) {
27114     return;
27115   }
27116 
27117   sep_list = GetViewedSeqEntryList ();
27118   if (sep_list == NULL) {
27119     return;
27120   }
27121   sep = sep_list->data.ptrvalue;
27122 
27123   if (GetOutputFileName (path, sizeof (path), NULL)) {
27124     fp = FileOpen (path, "w");
27125     if (fp == NULL) {
27126       Message (MSG_ERROR, "Unable to open %s", path);
27127     } else {
27128       ExportProductUpdateTableWithPrecomputedSuggestions (fp, sep, f->rule_list);
27129       FileClose (fp);
27130 #ifdef WIN_MSWIN
27131       Nlm_MSWin_OpenApplication ("excel.exe", path);
27132 #endif
27133     }
27134   }
27135   sep_list = ValNodeFree (sep_list);
27136 }
27137 
27138 
ExportRuleSetText(SuspectRuleSetPtr set,FILE * fp)27139 static void ExportRuleSetText (SuspectRuleSetPtr set, FILE *fp)
27140 {
27141   CharPtr tmp;
27142 
27143   if (fp == NULL) {
27144     return;
27145   }
27146   while (set != NULL) {
27147     tmp = SummarizeSuspectRule(set);
27148     if (tmp != NULL) {
27149       fprintf (fp, "%s\n", tmp);
27150     }
27151     set = set->next;
27152   }
27153 }
27154 
27155 
DisplayRuleText(SuspectRuleSetPtr set,CharPtr title)27156 static void DisplayRuleText (SuspectRuleSetPtr set, CharPtr title)
27157 {
27158   Char  path [PATH_MAX];
27159   FILE *fp;
27160 
27161   TmpNam (path);
27162   fp = FileOpen (path, "w");
27163   if (fp != NULL) {
27164     ExportRuleSetText(set, fp);
27165     FileClose (fp);
27166     LaunchGeneralTextViewer (path, title);
27167   }
27168   FileRemove (path);
27169 }
27170 
27171 
DisplaySuspectProductRuleDescriptions(ButtoN b)27172 static void DisplaySuspectProductRuleDescriptions (ButtoN b)
27173 {
27174   SuspectProductRuleEditorFormPtr frm;
27175 
27176   frm = (SuspectProductRuleEditorFormPtr) GetObjectExtra (b);
27177   if (frm == NULL) {
27178     return;
27179   }
27180   DisplayRuleText (frm->rule_list, "Suspect Rule Descriptions");
27181 }
27182 
27183 
ShowSuspectRuleDiffs(ButtoN b)27184 static void ShowSuspectRuleDiffs (ButtoN b)
27185 {
27186   SuspectProductRuleEditorFormPtr  f;
27187   Char               path [PATH_MAX];
27188   AsnIoPtr           aip;
27189   SuspectRuleSetPtr  rule_list;
27190   SuspectRuleSetPtr  in1not2 = NULL, in2not1 = NULL;
27191   CharPtr            title;
27192   CharPtr            title1_fmt = "Found in current list but not %s";
27193   CharPtr            title2_fmt = "Found in %s but not in current list";
27194 
27195   f = (SuspectProductRuleEditorFormPtr) GetObjectExtra (b);
27196   if (f == NULL) {
27197     return;
27198   }
27199 
27200   path [0] = '\0';
27201   if (GetInputFileName (path, sizeof (path), NULL, "TEXT")) {
27202     aip = AsnIoOpen (path, "r");
27203     if (aip == NULL) {
27204       Message (MSG_ERROR, "Unable to open %s", path);
27205     } else {
27206       rule_list = SuspectRuleSetAsnRead (aip, NULL);
27207       if (rule_list == NULL) {
27208         Message (MSG_ERROR, "Unable to read rule list from %s.", path);
27209       } else {
27210         FindDiffsBetweenRuleSets (f->rule_list, rule_list, &in1not2, &in2not1);
27211         title = (CharPtr) MemNew (sizeof (Char) * (StringLen (title1_fmt) + StringLen (path)));
27212         sprintf (title, title1_fmt, path);
27213         DisplayRuleText (in1not2, title);
27214         title = MemFree (title);
27215         title = (CharPtr) MemNew (sizeof (Char) * (StringLen (title2_fmt) + StringLen (path)));
27216         sprintf (title, title2_fmt, path);
27217         DisplayRuleText (in2not1, title);
27218         title = MemFree (title);
27219         rule_list = SuspectRuleSetFree (rule_list);
27220         in1not2 = SuspectRuleSetFree (in1not2);
27221         in2not1 = SuspectRuleSetFree (in2not1);
27222       }
27223     }
27224   }
27225 }
27226 
27227 
ApplyProductUpdateTableBtn(ButtoN b)27228 static void ApplyProductUpdateTableBtn (ButtoN b)
27229 {
27230   ValNodePtr   sep_list, vnp, table;
27231   Char         path [PATH_MAX];
27232   FILE         *fp;
27233   SeqEntryPtr  sep;
27234   Uint2        entityID;
27235   LogInfoPtr   lip = NULL;
27236 
27237   sep_list = GetViewedSeqEntryList ();
27238   if (sep_list == NULL) {
27239     return;
27240   }
27241 
27242   path [0] = '\0';
27243   if (GetInputFileName (path, sizeof (path), "", "TEXT")) {
27244     fp = FileOpen (path, "r");
27245     if (fp == NULL) {
27246       Message (MSG_ERROR, "Unable to open %s", path);
27247     } else {
27248       table = ReadProductUpdateTable (fp);
27249       FileClose (fp);
27250       if (table == NULL) {
27251         Message (MSG_ERROR, "Unable to read table from %s", path);
27252       } else {
27253         lip = OpenLog("Product name changes");
27254         for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
27255           sep = vnp->data.ptrvalue;
27256           if (sep == NULL) continue;
27257           entityID = ObjMgrGetEntityIDForChoice(sep);
27258           lip->data_in_log |= ApplyProductUpdateTable (table, sep, lip->fp);
27259           ObjMgrSetDirtyFlag (entityID, TRUE);
27260           ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
27261         }
27262       }
27263       CloseLog (lip);
27264       FreeLog (lip);
27265       table = ProductUpdateTableFree (table);
27266     }
27267   }
27268   sep_list = ValNodeFree (sep_list);
27269 }
27270 
27271 
LaunchSuspectProductRuleEditorBaseForm(BaseFormPtr bfp)27272 NLM_EXTERN void LaunchSuspectProductRuleEditorBaseForm (BaseFormPtr bfp)
27273 {
27274   WindoW              w;
27275   SuspectProductRuleEditorFormPtr  f;
27276   GrouP               h, c;
27277   MenU                m;
27278   ButtoN              b;
27279 
27280   if (bfp == NULL) return;
27281 
27282   f = (SuspectProductRuleEditorFormPtr) MemNew (sizeof (SuspectProductRuleEditorFormData));
27283   if (f == NULL) return;
27284 
27285   w = FixedWindow (-50, -33, -10, -10, "Suspect Product Rule Editor", StdCloseWindowProc);
27286   SetObjectExtra (w, f, CleanupSuspectProductRuleEditorForm);
27287   f->form = (ForM) w;
27288   f->input_entityID = bfp->input_entityID;
27289 
27290   f->formmessage = SuspectProductRuleEditorFormMessage;
27291 
27292   f->rule_list = NULL;
27293   f->last_filename = NULL;
27294   f->unsaved = FALSE;
27295 
27296   m = PulldownMenu (w, "File");
27297   FormCommandItem (m, "Open", (BaseFormPtr)f, VIB_MSG_OPEN);
27298   FormCommandItem (m, "Add Rules from File to List", (BaseFormPtr)f, VIB_MSG_IMPORT);
27299   FormCommandItem (m, "Save", (BaseFormPtr)f, VIB_MSG_SAVE);
27300   FormCommandItem (m, "Save As", (BaseFormPtr)f, VIB_MSG_SAVE_AS);
27301   SeparatorItem (m);
27302   FormCommandItem (m, "Quit", (BaseFormPtr)f, VIB_MSG_QUIT);
27303   m = PulldownMenu (w, "Sort");
27304   FormCommandItem (m, "By Find", (BaseFormPtr) f, NUM_VIB_MSG + 2);
27305   FormCommandItem (m, "By Category, then Find", (BaseFormPtr) f, NUM_VIB_MSG + 3);
27306 
27307 
27308   SetupSuspectProductRuleEditorFont (f);
27309   SetSuspectProductRuleEditorFileItems (f);
27310 
27311   h = HiddenGroup (w, -1, 0, NULL);
27312   SetGroupSpacing (h, 10, 10);
27313 
27314   f->rule_summary = DocumentPanel (h, stdCharWidth * 50, stdLineHeight * 20);
27315   SetObjectExtra (f->rule_summary, f, NULL);
27316   SetDocProcs (f->rule_summary, ClickSuspectProductRuleDoc, NULL, NULL, NULL);
27317   SetDocShade (f->rule_summary, DrawSuspectProductRuleDocControls, NULL, NULL, NULL);
27318 
27319   c = HiddenGroup (h, 6, 0, NULL);
27320   b = PushButton (c, "List current matches", ListSuspectRuleMatches);
27321   SetObjectExtra (b, f, NULL);
27322   b = PushButton (c, "Apply fixes", ApplySuspectRuleFixes);
27323   SetObjectExtra (b, f, NULL);
27324   b = PushButton (c, "Make Product Update Table", MakeProductUpdateTable);
27325   SetObjectExtra (b, f, NULL);
27326   b = PushButton (c, "Apply Product Update Table", ApplyProductUpdateTableBtn);
27327   SetObjectExtra (b, f, NULL);
27328   b = PushButton (c, "Show diffs with other file", ShowSuspectRuleDiffs);
27329   SetObjectExtra (b, f, NULL);
27330   b = PushButton (c, "Display Rule Text", DisplaySuspectProductRuleDescriptions);
27331   SetObjectExtra (b, f, NULL);
27332 
27333   AlignObjects (ALIGN_CENTER, (HANDLE) f->rule_summary, (HANDLE) c, NULL);
27334   SummarizeSuspectProductRule (f->rule_summary, f->rule_list, f->summary_font);
27335   Show (w);
27336 }
27337 
27338 
LaunchSuspectProductRuleEditor(IteM i)27339 NLM_EXTERN void LaunchSuspectProductRuleEditor (IteM i)
27340 {
27341   BaseFormPtr         bfp;
27342 
27343 #ifdef WIN_MAC
27344   bfp = currentFormDataPtr;
27345 #else
27346   bfp = GetObjectExtra (i);
27347 #endif
27348   LaunchSuspectProductRuleEditorBaseForm (bfp);
27349 }
27350