1 /*
2 * Copyright (c) Tony Bybell 1999-2011.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 */
9
10
11 /* AIX may need this for alloca to work */
12 #if defined _AIX
13 #pragma alloca
14 #endif
15
16 #include "globals.h"
17 #include <config.h>
18 #include <gtk/gtk.h>
19 #include "gtk12compat.h"
20 #include "analyzer.h"
21 #include "symbol.h"
22 #include "lx2.h"
23 #include "vcd.h"
24 #include "busy.h"
25 #include "debug.h"
26
27
hier_searchbox_is_active(void)28 int hier_searchbox_is_active(void)
29 {
30 return(GLOBALS->is_active_hiersearch_c_1);
31 }
32
33
refresh_hier_tree(struct tree * t)34 void refresh_hier_tree(struct tree *t)
35 {
36 struct tree *t2;
37 GtkCList *cl;
38 int len;
39 int row;
40 int pixlen=0, maxpixlen=0;
41 static char *dotdot="..";
42 struct treechain *tc;
43
44 gtk_clist_freeze(cl=GTK_CLIST(GLOBALS->clist_hiersearch_c_1));
45 gtk_clist_clear(cl);
46
47 GLOBALS->num_rows_hiersearch_c_1=0;
48
49 if(t!=GLOBALS->treeroot)
50 {
51 maxpixlen=font_engine_string_measure(GLOBALS->signalfont,(gchar *)(dotdot));
52 }
53
54 if(!GLOBALS->hier_grouping)
55 {
56 char *tmp, *tmp2, *tmp3;
57 t2=t;
58 while(t2)
59 {
60 {
61 if(t2->child)
62 {
63 tmp=wave_alloca(strlen(t2->name)+5);
64 strcpy(tmp, "(+) ");
65 strcpy(tmp+4, t2->name);
66 }
67 else
68 if(t2->t_which >= 0)
69 {
70 if(GLOBALS->facs[t2->t_which]->vec_root)
71 {
72 if(GLOBALS->autocoalesce)
73 {
74 if(GLOBALS->facs[t2->t_which]->vec_root!=GLOBALS->facs[t2->t_which])
75 {
76 t2=t2->next;
77 continue;
78 }
79
80 tmp2=makename_chain(GLOBALS->facs[t2->t_which]);
81 tmp3=leastsig_hiername(tmp2);
82 tmp=wave_alloca(strlen(tmp3)+4);
83 strcpy(tmp, "[] ");
84 strcpy(tmp+3, tmp3);
85 free_2(tmp2);
86 }
87 else
88 {
89 tmp=wave_alloca(strlen(t2->name)+4);
90 strcpy(tmp, "[] ");
91 strcpy(tmp+3, t2->name);
92 }
93 }
94 else
95 {
96 tmp=t2->name;
97 }
98 }
99 else
100 {
101 /* tmp=t2->name; */
102 goto skip_node; /* GHW */
103 }
104 row=gtk_clist_prepend(cl,(gchar **)&tmp);
105 pixlen=font_engine_string_measure(GLOBALS->signalfont,(gchar *)(tmp));
106 }
107 maxpixlen=(pixlen>maxpixlen)?pixlen:maxpixlen;
108 gtk_clist_set_row_data(cl, row,t2);
109 GLOBALS->num_rows_hiersearch_c_1++;
110 skip_node: t2=t2->next;
111 }
112 }
113 else
114 {
115 char *tmp, *tmp2, *tmp3;
116
117 t2=t;
118 while(t2)
119 {
120 if(!t2->child)
121 {
122 if(t2->t_which >= 0)
123 {
124 if(GLOBALS->facs[t2->t_which]->vec_root)
125 {
126 if(GLOBALS->autocoalesce)
127 {
128 if(GLOBALS->facs[t2->t_which]->vec_root!=GLOBALS->facs[t2->t_which])
129 {
130 t2=t2->next;
131 continue;
132 }
133
134 tmp2=makename_chain(GLOBALS->facs[t2->t_which]);
135 tmp3=leastsig_hiername(tmp2);
136 tmp=wave_alloca(strlen(tmp3)+4);
137 strcpy(tmp, "[] ");
138 strcpy(tmp+3, tmp3);
139 free_2(tmp2);
140 }
141 else
142 {
143 tmp=wave_alloca(strlen(t2->name)+4);
144 strcpy(tmp, "[] ");
145 strcpy(tmp+3, t2->name);
146 }
147 }
148 else
149 {
150 tmp=t2->name;
151 }
152 }
153 else
154 {
155 /* tmp=t2->name; */
156 goto skip_node_2; /* GHW */
157 }
158
159 row=gtk_clist_prepend(cl,(gchar **)&tmp);
160 pixlen=font_engine_string_measure(GLOBALS->signalfont,(gchar *)(tmp));
161 maxpixlen=(pixlen>maxpixlen)?pixlen:maxpixlen;
162 gtk_clist_set_row_data(cl, row,t2);
163 GLOBALS->num_rows_hiersearch_c_1++;
164 }
165 skip_node_2: t2=t2->next;
166 }
167
168 t2=t;
169 while(t2)
170 {
171 if(t2->child)
172 {
173 tmp=wave_alloca(strlen(t2->name)+5);
174 strcpy(tmp, "(+) ");
175 strcpy(tmp+4, t2->name);
176 row=gtk_clist_prepend(cl,(gchar **)&tmp);
177 pixlen=font_engine_string_measure(GLOBALS->signalfont,(gchar *)(tmp));
178 maxpixlen=(pixlen>maxpixlen)?pixlen:maxpixlen;
179 gtk_clist_set_row_data(cl, row,t2);
180 GLOBALS->num_rows_hiersearch_c_1++;
181 }
182 t2=t2->next;
183 }
184 }
185
186
187 if(t!=GLOBALS->treeroot)
188 {
189 row=gtk_clist_prepend(cl,(gchar **)&dotdot);
190 gtk_clist_set_row_data(cl, row,NULL);
191 GLOBALS->num_rows_hiersearch_c_1++;
192 }
193
194 if(maxpixlen)gtk_clist_set_column_width(GTK_CLIST(GLOBALS->clist_hiersearch_c_1),0,maxpixlen);
195 gtk_clist_thaw(cl);
196
197 if((tc=GLOBALS->treechain_hiersearch_c_1))
198 {
199 char *buf;
200 char hier_str[2];
201
202 len=1;
203 while(tc)
204 {
205 len+=strlen(tc->label->name);
206 if(tc->next) len++;
207 tc=tc->next;
208 }
209
210 buf=calloc_2(1,len);
211 hier_str[0]=GLOBALS->hier_delimeter;
212 hier_str[1]=0;
213
214 tc=GLOBALS->treechain_hiersearch_c_1;
215 while(tc)
216 {
217 strcat(buf,tc->label->name);
218 if(tc->next) strcat(buf,hier_str);
219 tc=tc->next;
220 }
221 gtk_entry_set_text(GTK_ENTRY(GLOBALS->entry_main_hiersearch_c_1), buf);
222 free_2(buf);
223 }
224 else
225 {
226 gtk_entry_set_text(GTK_ENTRY(GLOBALS->entry_main_hiersearch_c_1),"");
227 }
228 }
229
230
enter_callback_e(GtkWidget * widget,GtkWidget * nothing)231 static void enter_callback_e(GtkWidget *widget, GtkWidget *nothing)
232 {
233 (void)widget;
234 (void)nothing;
235
236 G_CONST_RETURN gchar *entry_text;
237 int len;
238 entry_text = gtk_entry_get_text(GTK_ENTRY(GLOBALS->entry_hiersearch_c_2));
239 entry_text = entry_text ? entry_text : "";
240 DEBUG(printf("Entry contents: %s\n", entry_text));
241 if(!(len=strlen(entry_text))) GLOBALS->entrybox_text_local_hiersearch_c_1=NULL;
242 else strcpy((GLOBALS->entrybox_text_local_hiersearch_c_1=(char *)malloc_2(len+1)),entry_text);
243
244 wave_gtk_grab_remove(GLOBALS->window1_hiersearch_c_1);
245 gtk_widget_destroy(GLOBALS->window1_hiersearch_c_1);
246 GLOBALS->window1_hiersearch_c_1 = NULL;
247
248 GLOBALS->cleanup_e_hiersearch_c_1();
249 }
250
destroy_callback_e(GtkWidget * widget,GtkWidget * nothing)251 static void destroy_callback_e(GtkWidget *widget, GtkWidget *nothing)
252 {
253 (void)widget;
254 (void)nothing;
255
256 DEBUG(printf("Entry Cancel\n"));
257 GLOBALS->entrybox_text_local_hiersearch_c_1=NULL;
258 wave_gtk_grab_remove(GLOBALS->window1_hiersearch_c_1);
259 gtk_widget_destroy(GLOBALS->window1_hiersearch_c_1);
260 GLOBALS->window1_hiersearch_c_1 = NULL;
261 }
262
entrybox_local(char * title,int width,char * default_text,int maxch,GtkSignalFunc func)263 static void entrybox_local(char *title, int width, char *default_text, int maxch, GtkSignalFunc func)
264 {
265 GtkWidget *vbox, *hbox;
266 GtkWidget *button1, *button2;
267
268 GLOBALS->cleanup_e_hiersearch_c_1=func;
269
270 /* fix problem where ungrab doesn't occur if button pressed + simultaneous accelerator key occurs */
271 if(GLOBALS->in_button_press_wavewindow_c_1) { gdk_pointer_ungrab(GDK_CURRENT_TIME); }
272
273 /* create a new modal window */
274 GLOBALS->window1_hiersearch_c_1 = gtk_window_new(GLOBALS->disable_window_manager ? GTK_WINDOW_POPUP : GTK_WINDOW_TOPLEVEL);
275 install_focus_cb(GLOBALS->window1_hiersearch_c_1, ((char *)&GLOBALS->window1_hiersearch_c_1) - ((char *)GLOBALS));
276
277 gtk_widget_set_usize( GTK_WIDGET (GLOBALS->window1_hiersearch_c_1), width, 60);
278 gtk_window_set_title(GTK_WINDOW (GLOBALS->window1_hiersearch_c_1), title);
279 gtkwave_signal_connect(GTK_OBJECT (GLOBALS->window1_hiersearch_c_1), "delete_event",(GtkSignalFunc) destroy_callback_e, NULL);
280
281 vbox = gtk_vbox_new (FALSE, 0);
282 gtk_container_add (GTK_CONTAINER (GLOBALS->window1_hiersearch_c_1), vbox);
283 gtk_widget_show (vbox);
284
285 GLOBALS->entry_hiersearch_c_2 = gtk_entry_new_with_max_length (maxch);
286 gtkwave_signal_connect(GTK_OBJECT(GLOBALS->entry_hiersearch_c_2), "activate",GTK_SIGNAL_FUNC(enter_callback_e),GLOBALS->entry_hiersearch_c_2);
287 gtk_entry_set_text (GTK_ENTRY (GLOBALS->entry_hiersearch_c_2), default_text);
288 gtk_entry_select_region (GTK_ENTRY (GLOBALS->entry_hiersearch_c_2),0, GTK_ENTRY(GLOBALS->entry_hiersearch_c_2)->text_length);
289 gtk_box_pack_start (GTK_BOX (vbox), GLOBALS->entry_hiersearch_c_2, TRUE, TRUE, 0);
290 gtk_widget_show (GLOBALS->entry_hiersearch_c_2);
291
292 hbox = gtk_hbox_new (FALSE, 1);
293 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
294 gtk_widget_show (hbox);
295
296 button1 = gtk_button_new_with_label ("OK");
297 gtk_widget_set_usize(button1, 100, -1);
298 gtkwave_signal_connect(GTK_OBJECT (button1), "clicked", GTK_SIGNAL_FUNC(enter_callback_e), NULL);
299 gtk_widget_show (button1);
300 gtk_container_add (GTK_CONTAINER (hbox), button1);
301 GTK_WIDGET_SET_FLAGS (button1, GTK_CAN_DEFAULT);
302 gtkwave_signal_connect_object (GTK_OBJECT (button1), "realize", (GtkSignalFunc) gtk_widget_grab_default, GTK_OBJECT (button1));
303
304 button2 = gtk_button_new_with_label ("Cancel");
305 gtk_widget_set_usize(button2, 100, -1);
306 gtkwave_signal_connect(GTK_OBJECT (button2), "clicked", GTK_SIGNAL_FUNC(destroy_callback_e), NULL);
307 GTK_WIDGET_SET_FLAGS (button2, GTK_CAN_DEFAULT);
308 gtk_widget_show (button2);
309 gtk_container_add (GTK_CONTAINER (hbox), button2);
310
311 gtk_widget_show(GLOBALS->window1_hiersearch_c_1);
312 wave_gtk_grab_add(GLOBALS->window1_hiersearch_c_1);
313 }
314
315 /***************************************************************************/
316
recurse_fetch_high_low(struct tree * t)317 void recurse_fetch_high_low(struct tree *t)
318 {
319 top:
320 if(t->t_which >= 0)
321 {
322 if(t->t_which > GLOBALS->fetchhigh) GLOBALS->fetchhigh = t->t_which;
323 if(GLOBALS->fetchlow < 0)
324 {
325 GLOBALS->fetchlow = t->t_which;
326 }
327 else
328 if(t->t_which < GLOBALS->fetchlow)
329 {
330 GLOBALS->fetchlow = t->t_which;
331 }
332 }
333
334 if(t->child)
335 {
336 recurse_fetch_high_low(t->child);
337 }
338
339 if(t->next) { t = t->next; goto top; }
340 }
341
342 /* Get the highest signal from T. */
fetchhigh(struct tree * t)343 struct tree *fetchhigh(struct tree *t)
344 {
345 while(t->child) t=t->child;
346 return(t);
347 }
348
349 /* Get the lowest signal from T. */
fetchlow(struct tree * t)350 struct tree *fetchlow(struct tree *t)
351 {
352 if(t->child)
353 {
354 t=t->child;
355
356 for(;;)
357 {
358 while(t->next) t=t->next;
359 if(t->child) t=t->child; else break;
360 }
361 }
362 return(t);
363 }
364
fetchvex2(struct tree * t,char direction,char level)365 static void fetchvex2(struct tree *t, char direction, char level)
366 {
367 while(t)
368 {
369 if(t->child)
370 {
371 if(t->child->child)
372 {
373 fetchvex2(t->child, direction, 1);
374 }
375 else
376 {
377 add_vector_range(NULL, fetchlow(t)->t_which,
378 fetchhigh(t)->t_which, direction);
379 }
380 }
381 if(level) { t=t->next; } else { break; }
382 }
383 }
384
fetchvex(struct tree * t,char direction)385 void fetchvex(struct tree *t, char direction)
386 {
387 if(t)
388 {
389 if(t->child)
390 {
391 fetchvex2(t, direction, 0);
392 }
393 else
394 {
395 add_vector_range(NULL, fetchlow(t)->t_which,
396 fetchhigh(t)->t_which, direction);
397 }
398 }
399 }
400
401
ok_callback(GtkWidget * widget,GtkWidget * nothing)402 static void ok_callback(GtkWidget *widget, GtkWidget *nothing)
403 {
404 (void)nothing;
405
406 int i;
407
408 if((!GLOBALS->h_selectedtree_hiersearch_c_1)||(!GLOBALS->h_selectedtree_hiersearch_c_1->child)) return;
409
410 set_window_busy(widget);
411
412 GLOBALS->fetchlow = GLOBALS->fetchhigh = -1;
413 recurse_fetch_high_low(GLOBALS->h_selectedtree_hiersearch_c_1->child);
414
415 for(i=GLOBALS->fetchlow;i<=GLOBALS->fetchhigh;i++)
416 {
417 struct symbol *s;
418 if(i<0) break; /* GHW */
419 s=GLOBALS->facs[i];
420 if(s->vec_root)
421 {
422 set_s_selected(s->vec_root, GLOBALS->autocoalesce);
423 }
424 }
425
426 /* LX2 */
427 if(GLOBALS->is_lx2)
428 {
429 int pre_import = 0;
430
431 for(i=GLOBALS->fetchlow;i<=GLOBALS->fetchhigh;i++)
432 {
433 struct symbol *s, *t;
434 if(i<0) break; /* GHW */
435 s=GLOBALS->facs[i];
436 t=s->vec_root;
437 if((t)&&(GLOBALS->autocoalesce))
438 {
439 if(get_s_selected(t))
440 {
441 while(t)
442 {
443 if(t->n->mv.mvlfac)
444 {
445 lx2_set_fac_process_mask(t->n);
446 pre_import++;
447 }
448 t=t->vec_chain;
449 }
450 }
451 }
452 else
453 {
454 if(s->n->mv.mvlfac)
455 {
456 lx2_set_fac_process_mask(s->n);
457 pre_import++;
458 }
459 }
460 }
461
462 if(pre_import)
463 {
464 lx2_import_masked();
465 }
466 }
467 /* LX2 */
468
469 for(i=GLOBALS->fetchlow;i<=GLOBALS->fetchhigh;i++)
470 {
471 int len;
472 struct symbol *s, *t;
473 if(i<0) break; /* GHW */
474 s=GLOBALS->facs[i];
475 t=s->vec_root;
476 if((t)&&(GLOBALS->autocoalesce))
477 {
478 if(get_s_selected(t))
479 {
480 set_s_selected(t, 0);
481 len=0;
482 while(t)
483 {
484 len++;
485 t=t->vec_chain;
486 }
487 if(len) add_vector_chain(s->vec_root, len);
488 }
489 }
490 else
491 {
492 AddNodeUnroll(s->n, NULL);
493 }
494 }
495
496 set_window_idle(widget);
497
498 GLOBALS->traces.scroll_top = GLOBALS->traces.scroll_bottom = GLOBALS->traces.last;
499 MaxSignalLength();
500 signalarea_configure_event(GLOBALS->signalarea, NULL);
501 wavearea_configure_event(GLOBALS->wavearea, NULL);
502 }
503
504
insert_callback(GtkWidget * widget,GtkWidget * nothing)505 static void insert_callback(GtkWidget *widget, GtkWidget *nothing)
506 {
507 (void)nothing;
508
509 Traces tcache;
510 int i;
511
512 if((!GLOBALS->h_selectedtree_hiersearch_c_1)||(!GLOBALS->h_selectedtree_hiersearch_c_1->child)) return;
513
514 memcpy(&tcache,&GLOBALS->traces,sizeof(Traces));
515 GLOBALS->traces.total=0;
516 GLOBALS->traces.first=GLOBALS->traces.last=NULL;
517
518 set_window_busy(widget);
519
520 GLOBALS->fetchlow = GLOBALS->fetchhigh = -1;
521 recurse_fetch_high_low(GLOBALS->h_selectedtree_hiersearch_c_1->child);
522
523 for(i=GLOBALS->fetchlow;i<=GLOBALS->fetchhigh;i++)
524 {
525 struct symbol *s;
526 if(i<0) break; /* GHW */
527 s=GLOBALS->facs[i];
528 if(s->vec_root)
529 {
530 set_s_selected(s->vec_root, GLOBALS->autocoalesce);
531 }
532 }
533
534 /* LX2 */
535 if(GLOBALS->is_lx2)
536 {
537 int pre_import = 0;
538
539 for(i=GLOBALS->fetchlow;i<=GLOBALS->fetchhigh;i++)
540 {
541 struct symbol *s, *t;
542 if(i<0) break; /* GHW */
543 s=GLOBALS->facs[i];
544 t=s->vec_root;
545 if((t)&&(GLOBALS->autocoalesce))
546 {
547 if(get_s_selected(t))
548 {
549 while(t)
550 {
551 if(t->n->mv.mvlfac)
552 {
553 lx2_set_fac_process_mask(t->n);
554 pre_import++;
555 }
556 t=t->vec_chain;
557 }
558 }
559 }
560 else
561 {
562 if(s->n->mv.mvlfac)
563 {
564 lx2_set_fac_process_mask(s->n);
565 pre_import++;
566 }
567 }
568 }
569
570 if(pre_import)
571 {
572 lx2_import_masked();
573 }
574 }
575 /* LX2 */
576
577 for(i=GLOBALS->fetchlow;i<=GLOBALS->fetchhigh;i++)
578 {
579 int len;
580 struct symbol *s, *t;
581 if(i<0) break; /* GHW */
582 s=GLOBALS->facs[i];
583 t=s->vec_root;
584 if((t)&&(GLOBALS->autocoalesce))
585 {
586 if(get_s_selected(t))
587 {
588 set_s_selected(t, 0);
589 len=0;
590 while(t)
591 {
592 len++;
593 t=t->vec_chain;
594 }
595 if(len) add_vector_chain(s->vec_root, len);
596 }
597 }
598 else
599 {
600 AddNodeUnroll(s->n, NULL);
601 }
602 }
603
604 set_window_idle(widget);
605
606 GLOBALS->traces.buffercount=GLOBALS->traces.total;
607 GLOBALS->traces.buffer=GLOBALS->traces.first;
608 GLOBALS->traces.bufferlast=GLOBALS->traces.last;
609 GLOBALS->traces.first=tcache.first;
610 GLOBALS->traces.last=tcache.last;
611 GLOBALS->traces.total=tcache.total;
612
613 PasteBuffer();
614
615 GLOBALS->traces.buffercount=tcache.buffercount;
616 GLOBALS->traces.buffer=tcache.buffer;
617 GLOBALS->traces.bufferlast=tcache.bufferlast;
618
619 MaxSignalLength();
620 signalarea_configure_event(GLOBALS->signalarea, NULL);
621 wavearea_configure_event(GLOBALS->wavearea, NULL);
622 }
623
624
replace_callback(GtkWidget * widget,GtkWidget * nothing)625 static void replace_callback(GtkWidget *widget, GtkWidget *nothing)
626 {
627 (void)nothing;
628
629 Traces tcache;
630 int i;
631 Trptr tfirst=NULL, tlast=NULL;
632
633 if((!GLOBALS->h_selectedtree_hiersearch_c_1)||(!GLOBALS->h_selectedtree_hiersearch_c_1->child)) return;
634
635 memcpy(&tcache,&GLOBALS->traces,sizeof(Traces));
636 GLOBALS->traces.total=0;
637 GLOBALS->traces.first=GLOBALS->traces.last=NULL;
638
639 set_window_busy(widget);
640
641 GLOBALS->fetchlow = GLOBALS->fetchhigh = -1;
642 recurse_fetch_high_low(GLOBALS->h_selectedtree_hiersearch_c_1->child);
643
644 for(i=GLOBALS->fetchlow;i<=GLOBALS->fetchhigh;i++)
645 {
646 struct symbol *s;
647 if(i<0) break; /* GHW */
648 s=GLOBALS->facs[i];
649 if(s->vec_root)
650 {
651 set_s_selected(s->vec_root, GLOBALS->autocoalesce);
652 }
653 }
654
655 /* LX2 */
656 if(GLOBALS->is_lx2)
657 {
658 int pre_import = 0;
659
660 for(i=GLOBALS->fetchlow;i<=GLOBALS->fetchhigh;i++)
661 {
662 struct symbol *s, *t;
663 if(i<0) break; /* GHW */
664 s=GLOBALS->facs[i];
665 t=s->vec_root;
666 if((t)&&(GLOBALS->autocoalesce))
667 {
668 if(get_s_selected(t))
669 {
670 while(t)
671 {
672 if(t->n->mv.mvlfac)
673 {
674 lx2_set_fac_process_mask(t->n);
675 pre_import++;
676 }
677 t=t->vec_chain;
678 }
679 }
680 }
681 else
682 {
683 if(s->n->mv.mvlfac)
684 {
685 lx2_set_fac_process_mask(s->n);
686 pre_import++;
687 }
688 }
689 }
690
691 if(pre_import)
692 {
693 lx2_import_masked();
694 }
695 }
696 /* LX2 */
697
698 for(i=GLOBALS->fetchlow;i<=GLOBALS->fetchhigh;i++)
699 {
700 int len;
701 struct symbol *s, *t;
702 if(i<0) break; /* GHW */
703 s=GLOBALS->facs[i];
704 t=s->vec_root;
705 if((t)&&(GLOBALS->autocoalesce))
706 {
707 if(get_s_selected(t))
708 {
709 set_s_selected(t, 0);
710 len=0;
711 while(t)
712 {
713 len++;
714 t=t->vec_chain;
715 }
716 if(len) add_vector_chain(s->vec_root, len);
717 }
718 }
719 else
720 {
721 AddNodeUnroll(s->n, NULL);
722 }
723 }
724
725 set_window_idle(widget);
726
727 tfirst=GLOBALS->traces.first; tlast=GLOBALS->traces.last; /* cache for highlighting */
728
729 GLOBALS->traces.buffercount=GLOBALS->traces.total;
730 GLOBALS->traces.buffer=GLOBALS->traces.first;
731 GLOBALS->traces.bufferlast=GLOBALS->traces.last;
732 GLOBALS->traces.first=tcache.first;
733 GLOBALS->traces.last=tcache.last;
734 GLOBALS->traces.total=tcache.total;
735
736 {
737 Trptr t = GLOBALS->traces.first;
738 Trptr *tp = NULL;
739 int numhigh = 0;
740 int it;
741
742 while(t) { if(t->flags & TR_HIGHLIGHT) { numhigh++; } t = t->t_next; }
743 if(numhigh)
744 {
745 tp = calloc_2(numhigh, sizeof(Trptr));
746 t = GLOBALS->traces.first;
747 it = 0;
748 while(t) { if(t->flags & TR_HIGHLIGHT) { tp[it++] = t; } t = t->t_next; }
749 }
750
751 PasteBuffer();
752
753 GLOBALS->traces.buffercount=tcache.buffercount;
754 GLOBALS->traces.buffer=tcache.buffer;
755 GLOBALS->traces.bufferlast=tcache.bufferlast;
756
757 for(i=0;i<numhigh;i++)
758 {
759 tp[i]->flags |= TR_HIGHLIGHT;
760 }
761
762 t = tfirst;
763 while(t)
764 {
765 t->flags &= ~TR_HIGHLIGHT;
766 if(t==tlast) break;
767 t=t->t_next;
768 }
769
770 CutBuffer();
771
772 while(tfirst)
773 {
774 tfirst->flags |= TR_HIGHLIGHT;
775 if(tfirst==tlast) break;
776 tfirst=tfirst->t_next;
777 }
778
779 if(tp)
780 {
781 free_2(tp);
782 }
783 }
784
785 MaxSignalLength();
786 signalarea_configure_event(GLOBALS->signalarea, NULL);
787 wavearea_configure_event(GLOBALS->wavearea, NULL);
788 }
789
790
791 static void
bundle_cleanup(GtkWidget * widget,gpointer data)792 bundle_cleanup(GtkWidget *widget, gpointer data)
793 {
794 (void)widget;
795 (void)data;
796
797 if(GLOBALS->entrybox_text_local_hiersearch_c_1)
798 {
799 char *efix;
800
801 if(!strlen(GLOBALS->entrybox_text_local_hiersearch_c_1))
802 {
803 DEBUG(printf("Bundle name is not specified--recursing into hierarchy.\n"));
804 fetchvex(GLOBALS->h_selectedtree_hiersearch_c_1, GLOBALS->bundle_direction_hiersearch_c_1);
805 }
806 else
807 {
808 efix=GLOBALS->entrybox_text_local_hiersearch_c_1;
809 while(*efix)
810 {
811 if(*efix==' ')
812 {
813 *efix='_';
814 }
815 efix++;
816 }
817
818 DEBUG(printf("Bundle name is: %s\n",GLOBALS->entrybox_text_local_hiersearch_c_1));
819 add_vector_range(GLOBALS->entrybox_text_local_hiersearch_c_1,
820 fetchlow(GLOBALS->h_selectedtree_hiersearch_c_1)->t_which,
821 fetchhigh(GLOBALS->h_selectedtree_hiersearch_c_1)->t_which,
822 GLOBALS->bundle_direction_hiersearch_c_1);
823 }
824 free_2(GLOBALS->entrybox_text_local_hiersearch_c_1);
825 }
826 else
827 {
828 DEBUG(printf("Bundle name is not specified--recursing into hierarchy.\n"));
829 fetchvex(GLOBALS->h_selectedtree_hiersearch_c_1, GLOBALS->bundle_direction_hiersearch_c_1);
830 }
831
832 MaxSignalLength();
833 signalarea_configure_event(GLOBALS->signalarea, NULL);
834 wavearea_configure_event(GLOBALS->wavearea, NULL);
835 }
836
837
838 static void
bundle_callback_generic(void)839 bundle_callback_generic(void)
840 {
841 if(!GLOBALS->autoname_bundles)
842 {
843 entrybox_local("Enter Bundle Name",300,"",128,GTK_SIGNAL_FUNC(bundle_cleanup));
844 }
845 else
846 {
847 GLOBALS->entrybox_text_local_hiersearch_c_1=NULL;
848 bundle_cleanup(NULL, NULL);
849 }
850 }
851
852
853 static void
bundle_callback_up(GtkWidget * widget,gpointer data)854 bundle_callback_up(GtkWidget *widget, gpointer data)
855 {
856 (void)widget;
857 (void)data;
858
859 GLOBALS->bundle_direction_hiersearch_c_1=0;
860 bundle_callback_generic();
861 }
862
863 static void
bundle_callback_down(GtkWidget * widget,gpointer data)864 bundle_callback_down(GtkWidget *widget, gpointer data)
865 {
866 (void)widget;
867 (void)data;
868
869 GLOBALS->bundle_direction_hiersearch_c_1=1;
870 bundle_callback_generic();
871 }
872
873 /****************************************************************************/
874
select_row_callback(GtkWidget * widget,gint row,gint column,GdkEventButton * event,gpointer data)875 static void select_row_callback(GtkWidget *widget, gint row, gint column,
876 GdkEventButton *event, gpointer data)
877 {
878 (void)widget;
879 (void)column;
880 (void)event;
881 (void)data;
882
883 struct tree *t;
884
885 t=(struct tree *)gtk_clist_get_row_data(GTK_CLIST(GLOBALS->clist_hiersearch_c_1), row);
886 if(t)
887 {
888 GLOBALS->h_selectedtree_hiersearch_c_1=t;
889 DEBUG(printf("Selected: %s\n",t->name));
890 if(t->child)
891 {
892 struct treechain *tc, *tc2;
893
894 tc=GLOBALS->treechain_hiersearch_c_1;
895 if(tc)
896 {
897 while(tc->next) tc=tc->next;
898
899 tc2=calloc_2(1,sizeof(struct treechain));
900 tc2->label=t;
901 tc2->tree=GLOBALS->current_tree_hiersearch_c_1;
902 tc->next=tc2;
903 }
904 else
905 {
906 GLOBALS->treechain_hiersearch_c_1=calloc_2(1,sizeof(struct treechain));
907 GLOBALS->treechain_hiersearch_c_1->tree=GLOBALS->current_tree_hiersearch_c_1;
908 GLOBALS->treechain_hiersearch_c_1->label=t;
909 }
910
911 GLOBALS->current_tree_hiersearch_c_1=t->child;
912 refresh_hier_tree(GLOBALS->current_tree_hiersearch_c_1);
913 }
914 }
915 else
916 {
917 struct treechain *tc;
918
919 GLOBALS->h_selectedtree_hiersearch_c_1=NULL;
920 tc=GLOBALS->treechain_hiersearch_c_1;
921 if(tc)
922 {
923 for(;;)
924 {
925 if(tc->next)
926 {
927 if(tc->next->next)
928 {
929 tc=tc->next;
930 continue;
931 }
932 else
933 {
934 GLOBALS->current_tree_hiersearch_c_1=tc->next->tree;
935 free_2(tc->next);
936 tc->next=NULL;
937 break;
938 }
939 }
940 else
941 {
942 free_2(tc);
943 GLOBALS->treechain_hiersearch_c_1=NULL;
944 GLOBALS->current_tree_hiersearch_c_1=GLOBALS->treeroot;
945 break;
946 }
947
948 }
949 refresh_hier_tree(GLOBALS->current_tree_hiersearch_c_1);
950 }
951 }
952
953 }
954
unselect_row_callback(GtkWidget * widget,gint row,gint column,GdkEventButton * event,gpointer data)955 static void unselect_row_callback(GtkWidget *widget, gint row, gint column,
956 GdkEventButton *event, gpointer data)
957 {
958 (void)widget;
959 (void)column;
960 (void)event;
961 (void)data;
962
963 struct tree *t;
964
965 t=(struct tree *)gtk_clist_get_row_data(GTK_CLIST(GLOBALS->clist_hiersearch_c_1), row);
966 GLOBALS->h_selectedtree_hiersearch_c_1=NULL;
967
968 if(t)
969 {
970 DEBUG(printf("Unselected: %s\n",t->name));
971 }
972 else
973 {
974 /* just ignore */
975 }
976 }
977
978
destroy_callback(GtkWidget * widget,GtkWidget * nothing)979 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
980 {
981 (void)widget;
982 (void)nothing;
983
984 GLOBALS->is_active_hiersearch_c_1=0;
985 gtk_widget_destroy(GLOBALS->window_hiersearch_c_3);
986 GLOBALS->window_hiersearch_c_3 = NULL;
987 }
988
989
990 /*
991 * mainline..
992 */
hier_searchbox(char * title,GtkSignalFunc func)993 void hier_searchbox(char *title, GtkSignalFunc func)
994 {
995 GtkWidget *scrolled_win;
996 GtkWidget *vbox1, *hbox;
997 GtkWidget *button1, *button2, *button3, *button3a, *button4, *button5;
998 GtkWidget *label;
999 gchar *titles[]={"Children"};
1000 GtkWidget *frame1, *frame2, *frameh;
1001 GtkWidget *table;
1002 GtkTooltips *tooltips;
1003
1004 /* fix problem where ungrab doesn't occur if button pressed + simultaneous accelerator key occurs */
1005 if(GLOBALS->in_button_press_wavewindow_c_1) { gdk_pointer_ungrab(GDK_CURRENT_TIME); }
1006
1007 if(GLOBALS->is_active_hiersearch_c_1)
1008 {
1009 gdk_window_raise(GLOBALS->window_hiersearch_c_3->window);
1010 return;
1011 }
1012
1013 GLOBALS->is_active_hiersearch_c_1=1;
1014 GLOBALS->cleanup_hiersearch_c_3=func;
1015 GLOBALS->num_rows_hiersearch_c_1=GLOBALS->selected_rows_hiersearch_c_1=0;
1016
1017 /* create a new modal window */
1018 GLOBALS->window_hiersearch_c_3 = gtk_window_new(GLOBALS->disable_window_manager ? GTK_WINDOW_POPUP : GTK_WINDOW_TOPLEVEL);
1019 install_focus_cb(GLOBALS->window_hiersearch_c_3, ((char *)&GLOBALS->window_hiersearch_c_3) - ((char *)GLOBALS));
1020
1021 gtk_window_set_title(GTK_WINDOW (GLOBALS->window_hiersearch_c_3), title);
1022 gtkwave_signal_connect(GTK_OBJECT (GLOBALS->window_hiersearch_c_3), "delete_event",(GtkSignalFunc) destroy_callback, NULL);
1023
1024 tooltips=gtk_tooltips_new_2();
1025
1026 table = gtk_table_new (256, 1, FALSE);
1027 gtk_widget_show (table);
1028
1029 vbox1 = gtk_vbox_new (FALSE, 0);
1030 gtk_container_border_width (GTK_CONTAINER (vbox1), 3);
1031 gtk_widget_show (vbox1);
1032 frame1 = gtk_frame_new (NULL);
1033 gtk_container_border_width (GTK_CONTAINER (frame1), 3);
1034 gtk_widget_show(frame1);
1035 gtk_table_attach (GTK_TABLE (table), frame1, 0, 1, 0, 1,
1036 GTK_FILL | GTK_EXPAND,
1037 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 1, 1);
1038
1039 label=gtk_label_new("Signal Hierarchy");
1040 gtk_widget_show(label);
1041
1042 gtk_box_pack_start (GTK_BOX (vbox1), label, TRUE, TRUE, 0);
1043
1044 GLOBALS->entry_main_hiersearch_c_1 = gtk_entry_new();
1045 gtk_entry_set_editable(GTK_ENTRY(GLOBALS->entry_main_hiersearch_c_1), FALSE);
1046 gtk_widget_show (GLOBALS->entry_main_hiersearch_c_1);
1047 gtk_tooltips_set_tip_2(tooltips, GLOBALS->entry_main_hiersearch_c_1,
1048 "The hierarchy is built here by clicking on the appropriate "
1049 "items below in the scrollable window. Click on \"..\" to "
1050 "go up a level."
1051 ,NULL);
1052
1053 gtk_box_pack_start (GTK_BOX (vbox1), GLOBALS->entry_main_hiersearch_c_1, TRUE, TRUE, 0);
1054 gtk_container_add (GTK_CONTAINER (frame1), vbox1);
1055
1056 frame2 = gtk_frame_new (NULL);
1057 gtk_container_border_width (GTK_CONTAINER (frame2), 3);
1058 gtk_widget_show(frame2);
1059
1060 gtk_table_attach (GTK_TABLE (table), frame2, 0, 1, 1, 254,
1061 GTK_FILL | GTK_EXPAND,
1062 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 1, 1);
1063
1064 GLOBALS->clist_hiersearch_c_1=gtk_clist_new_with_titles(1,titles);
1065 gtk_clist_column_titles_passive(GTK_CLIST(GLOBALS->clist_hiersearch_c_1));
1066
1067 gtk_clist_set_selection_mode(GTK_CLIST(GLOBALS->clist_hiersearch_c_1), GTK_SELECTION_SINGLE);
1068 gtkwave_signal_connect_object (GTK_OBJECT (GLOBALS->clist_hiersearch_c_1), "select_row",GTK_SIGNAL_FUNC(select_row_callback),NULL);
1069 gtkwave_signal_connect_object (GTK_OBJECT (GLOBALS->clist_hiersearch_c_1), "unselect_row",GTK_SIGNAL_FUNC(unselect_row_callback),NULL);
1070 gtk_widget_show (GLOBALS->clist_hiersearch_c_1);
1071
1072 scrolled_win = gtk_scrolled_window_new (NULL, NULL);
1073 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
1074 GTK_POLICY_AUTOMATIC,
1075 GTK_POLICY_AUTOMATIC);
1076 gtk_widget_set_usize( GTK_WIDGET (scrolled_win), -1, 300);
1077 gtk_widget_show(scrolled_win);
1078
1079 /* gtk_scrolled_window_add_with_viewport doesn't seen to work right here.. */
1080 gtk_container_add (GTK_CONTAINER (scrolled_win), GLOBALS->clist_hiersearch_c_1);
1081
1082 gtk_container_add (GTK_CONTAINER (frame2), scrolled_win);
1083
1084 frameh = gtk_frame_new (NULL);
1085 gtk_container_border_width (GTK_CONTAINER (frameh), 3);
1086 gtk_widget_show(frameh);
1087 gtk_table_attach (GTK_TABLE (table), frameh, 0, 1, 255, 256,
1088 GTK_FILL | GTK_EXPAND,
1089 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 1, 1);
1090
1091
1092 hbox = gtk_hbox_new (FALSE, 1);
1093 gtk_widget_show (hbox);
1094
1095 button1 = gtk_button_new_with_label ("Append");
1096 gtk_container_border_width (GTK_CONTAINER (button1), 3);
1097 gtkwave_signal_connect_object (GTK_OBJECT (button1), "clicked",GTK_SIGNAL_FUNC(ok_callback),GTK_OBJECT (GLOBALS->window_hiersearch_c_3));
1098 gtk_widget_show (button1);
1099 gtk_tooltips_set_tip_2(tooltips, button1,
1100 "Add selected signals to end of the display on the main window.",NULL);
1101
1102 gtk_box_pack_start (GTK_BOX (hbox), button1, TRUE, FALSE, 0);
1103
1104 button2 = gtk_button_new_with_label (" Insert ");
1105 gtk_container_border_width (GTK_CONTAINER (button2), 3);
1106 gtkwave_signal_connect_object (GTK_OBJECT (button2), "clicked",GTK_SIGNAL_FUNC(insert_callback),GTK_OBJECT (GLOBALS->window_hiersearch_c_3));
1107 gtk_widget_show (button2);
1108 gtk_tooltips_set_tip_2(tooltips, button2,
1109 "Add children after last highlighted signal on the main window.",NULL);
1110 gtk_box_pack_start (GTK_BOX (hbox), button2, TRUE, FALSE, 0);
1111
1112 if(GLOBALS->vcd_explicit_zero_subscripts>=0)
1113 {
1114 button3 = gtk_button_new_with_label (" Bundle Up ");
1115 gtk_container_border_width (GTK_CONTAINER (button3), 3);
1116 gtkwave_signal_connect_object (GTK_OBJECT (button3), "clicked",GTK_SIGNAL_FUNC(bundle_callback_up),GTK_OBJECT (GLOBALS->window_hiersearch_c_3));
1117 gtk_widget_show (button3);
1118 gtk_tooltips_set_tip_2(tooltips, button3,
1119 "Bundle children into a single bit vector with the topmost signal as the LSB and the lowest as the MSB.",NULL);
1120 gtk_box_pack_start (GTK_BOX (hbox), button3, TRUE, FALSE, 0);
1121
1122 button3a = gtk_button_new_with_label (" Bundle Down ");
1123 gtk_container_border_width (GTK_CONTAINER (button3a), 3);
1124 gtkwave_signal_connect_object (GTK_OBJECT (button3a), "clicked",GTK_SIGNAL_FUNC(bundle_callback_down),GTK_OBJECT (GLOBALS->window_hiersearch_c_3));
1125 gtk_widget_show (button3a);
1126 gtk_tooltips_set_tip_2(tooltips, button3a,
1127 "Bundle children into a single bit vector with the topmost signal as the MSB and the lowest as the LSB.",NULL);
1128 gtk_box_pack_start (GTK_BOX (hbox), button3a, TRUE, FALSE, 0);
1129 }
1130
1131 button4 = gtk_button_new_with_label (" Replace ");
1132 gtk_container_border_width (GTK_CONTAINER (button4), 3);
1133 gtkwave_signal_connect_object (GTK_OBJECT (button4), "clicked",GTK_SIGNAL_FUNC(replace_callback),GTK_OBJECT (GLOBALS->window_hiersearch_c_3));
1134 gtk_widget_show (button4);
1135 gtk_tooltips_set_tip_2(tooltips, button4,
1136 "Replace highlighted signals on the main window with children shown above.",NULL);
1137 gtk_box_pack_start (GTK_BOX (hbox), button4, TRUE, FALSE, 0);
1138
1139 button5 = gtk_button_new_with_label (" Exit ");
1140 gtk_container_border_width (GTK_CONTAINER (button5), 3);
1141 gtkwave_signal_connect_object (GTK_OBJECT (button5), "clicked",GTK_SIGNAL_FUNC(destroy_callback),GTK_OBJECT (GLOBALS->window_hiersearch_c_3));
1142 gtk_tooltips_set_tip_2(tooltips, button5,
1143 "Do nothing and return to the main window.",NULL);
1144 gtk_widget_show (button5);
1145 gtk_box_pack_start (GTK_BOX (hbox), button5, TRUE, FALSE, 0);
1146
1147 gtk_container_add (GTK_CONTAINER (frameh), hbox);
1148 gtk_container_add (GTK_CONTAINER (GLOBALS->window_hiersearch_c_3), table);
1149
1150 gtk_widget_show(GLOBALS->window_hiersearch_c_3);
1151
1152 if(!GLOBALS->current_tree_hiersearch_c_1)
1153 {
1154 GLOBALS->current_tree_hiersearch_c_1=GLOBALS->treeroot;
1155 GLOBALS->h_selectedtree_hiersearch_c_1=NULL;
1156 }
1157
1158 refresh_hier_tree(GLOBALS->current_tree_hiersearch_c_1);
1159 }
1160
1161