/* * ACE/gredit - 2d finite element grid generation * * Paul J. Turner and Antonio M. Baptista * * Copyright 1990-2003 Oregon Health and Science University * All Rights Reserved. * */ /* * Set properties of nodes and elements * */ #ifndef lint static char RCSid[] = "$Id: propwin.c,v 1.2 2003/07/24 15:44:05 pturner Exp $"; #endif #include #include #include #include "motifinc.h" #include "defines.h" #include "globals.h" extern Widget app_shell; extern XmStringCharSet charset; static Widget prop_frame; static Widget prop_panel; static Widget prop_write_item; static Widget *prop_type_item; /* type of prop */ static Widget *prop_propn_item; /* which prop struct to use */ static Widget *prop_color_item; /* which color to use */ static Widget prop_default_item; static Widget prop_current_item; static Widget display_prop; static Widget writep_frame; static Widget writep_panel; void create_writep_popup(void); void writep_accept_proc(void); void drawgrid_prop_filled(int gridno); static FILE *propfp; static int propcnt; static double defval; static double curval; typedef struct _Prop_struct { int type; /* nodes, elements, element type, node type, * or just XY */ int stype; /* storage type, real or integer */ int active; Isolparms propip; int *nodes; int *els; int *ncolor; int *ecolor; double *dprop; int n; double *x, *y; } Prop; Prop p[10]; int curprop; int curcolor; extern int draw_prop; void create_prop_popup(void); void propread_accept_proc(void); static Widget propread_frame; static Widget *rprop_choice_item; void create_readprop_frame(void) { Widget wbut, rc; int i; Arg a; if (!propread_frame) { propread_frame = XmCreateFileSelectionDialog(app_shell, "propread_frame", NULL, 0); XtVaSetValues(propread_frame, XmNtitle, XmStringCreate("Read property", charset), XmNdirMask, XmStringCreate("*.prop", charset), NULL); rc = XmCreateRowColumn(propread_frame, "rc", NULL, 0); rprop_choice_item = CreatePanelChoice1(rc, "Read property: ", 3, "Property at nodes", "Propery at elements", NULL, NULL); XtManageChild(rc); XtAddCallback(propread_frame, XmNcancelCallback, (XtCallbackProc) destroy_dialog, propread_frame); XtAddCallback(propread_frame, XmNokCallback, (XtCallbackProc) propread_accept_proc, NULL); } XtRaise(propread_frame); } void prop_isolines_proc(void) { /* PBP */ int i,propn; curprop = propn = GetChoice(prop_propn_item); p[propn].propip.active=1;p[propn].propip.loctype = WORLD;p[propn].propip.p.prec=2; p[propn].propip.p.format = DECIMAL;p[propn].propip.p.color = 1; create_isolines_popup("Element properties", &(p->propip)); } void propread_accept_proc(void) { Arg args; XmString list_item; char *s, buf[256]; int flowno, gridno,ptype,propn,i; float jf; double dp,min,max; Widget textw; FILE *pf; XtSetArg(args, XmNtextString, &list_item); XtGetValues(propread_frame, &args, 1); XmStringGetLtoR(list_item, charset, &s); set_wait_cursor(propread_frame); curprop = propn = GetChoice(prop_propn_item); ptype = GetChoice(rprop_choice_item); switch (ptype) { case 0: p[propn].type = ptype; p[propn].active = 1; p[propn].nodes = (int *) malloc(grid[curgrid].nmnp * sizeof(int)); p[propn].ncolor = (int *) malloc(grid[curgrid].nmnp * sizeof(int)); p[propn].dprop = (double *) malloc(grid[curgrid].nmnp * sizeof(double)); for (i = 0; i < grid[curgrid].nmnp; i++) { p[propn].dprop[i] = dp; p[propn].ncolor[i] = curcolor; } break; case 1: p[propn].type = ptype; p[propn].active = 1; p[propn].stype = 1; p[propn].els = (int *) malloc(grid[curgrid].nmel * sizeof(int)); p[propn].ecolor = (int *) malloc(grid[curgrid].nmel * sizeof(int)); p[propn].dprop = (double *) malloc(grid[curgrid].nmel * sizeof(double)); strcpy(buf,s); if ((pf = fopen(buf,"r")) == NULL) { errwin("Unable to open file"); return; } for (i = 0; i < grid[curgrid].nmel; i++) { if (fgets(buf,250,pf) == NULL) { errwin("Not enough lines in depth file, operation cancelled."); fclose(pf); return; } sscanf(buf,"%*d %le", &dp); if (i == 0) { min = max = dp; } if (dp>max) { max=dp; } if (dp=p[j].propip.cis[k] && dp= 0 && nl[j].nodes[i] < grid[gridno].nmnp) { nn = nl[j].nodes[i]; setcolor(nl[j].color[i]); x = grid[gridno].xord[nn]; y = grid[gridno].yord[nn]; drawpolysym(&x, &y, 1, SYM_CIRCLE, 0, 0, 0.5 + nl[j].color[i] / 15.0); } } } } setcolor(1); } void create_nodelist_frame(void); void create_readnodelist_frame(void); void create_writenodelist_frame(void); void nodelist_read_proc(void); void nodelist_write_proc(void); static Widget rnodelist_frame; static Widget wnodelist_frame; void create_readnodelist_frame(void) { Widget wbut, rc; int i; if (!rnodelist_frame) { rnodelist_frame = XmCreateFileSelectionDialog(app_shell, "rnodelist_frame", NULL, 0); XtVaSetValues(rnodelist_frame, XmNtitle, XmStringCreate("Read node list", charset), XmNdirMask, XmStringCreate("*.nlist", charset), NULL); rc = XmCreateRowColumn(rnodelist_frame, "rc", NULL, 0); XtManageChild(rc); XtAddCallback(rnodelist_frame, XmNcancelCallback, (XtCallbackProc) destroy_dialog, rnodelist_frame); XtAddCallback(rnodelist_frame, XmNokCallback, (XtCallbackProc) nodelist_read_proc, NULL); } XtRaise(rnodelist_frame); } void nodelist_read_proc(void) { Arg args; XmString list_item; char *s, buf[256]; XtSetArg(args, XmNtextString, &list_item); XtGetValues(rnodelist_frame, &args, 1); XmStringGetLtoR(list_item, charset, &s); set_wait_cursor(rnodelist_frame); if (ReadPNodeList(s)) { sprintf(buf, "Error reading file %s", s); errwin(buf); } else { XtUnmanageChild(rnodelist_frame); } unset_wait_cursor(rnodelist_frame); } void create_writenodelist_frame(void) { extern Widget app_shell; Widget bt, fr, rc, rc1; Widget wbut; int i; if (!wnodelist_frame) { wnodelist_frame = XmCreateFileSelectionDialog(app_shell, "wnodelist_frame", NULL, 0); XtVaSetValues(wnodelist_frame, XmNtitle, XmStringCreate("Write node list", charset), XmNdirMask, XmStringCreate("*.nlist", charset), NULL); rc = XmCreateRowColumn(wnodelist_frame, "rc", NULL, 0); XtManageChild(rc); XtAddCallback(wnodelist_frame, XmNcancelCallback, (XtCallbackProc) destroy_dialog, wnodelist_frame); XtAddCallback(wnodelist_frame, XmNokCallback, (XtCallbackProc) nodelist_write_proc, NULL); } XtRaise(wnodelist_frame); } void nodelist_write_proc(void) { Arg args; XmString list_item; char *s; XtSetArg(args, XmNtextString, &list_item); XtGetValues(wnodelist_frame, &args, 1); XmStringGetLtoR(list_item, charset, &s); set_wait_cursor(wnodelist_frame); if (WritePNodeList(s)) { } else { XtUnmanageChild(wnodelist_frame); } unset_wait_cursor(wnodelist_frame); } static Widget nodelist_frame; static Widget nodelist_panel; static Widget display_nodelist_item; static Widget nodelist_ival_item; static Widget nodelist_dval_item; static Widget *nodelist_color_item; static Widget nlbut[10]; void nodelist_accept_proc(void) { int i; curnlival = atoi((char *) xv_getstr(nodelist_ival_item)); curnldval = atof((char *) xv_getstr(nodelist_dval_item)); curnlcolor = GetChoice(nodelist_color_item); displaynl = XmToggleButtonGetState(display_nodelist_item); /* for (i = 0; i < 4; i++) { XtSetSensitive(nlbut[i], True); } */ } void update_nodelist(void) { char buf[128]; if (nodelist_frame) { sprintf(buf, "%d", curnlival); xv_setstr(nodelist_ival_item, buf); sprintf(buf, "%lf", curnldval); xv_setstr(nodelist_dval_item, buf); SetChoice(nodelist_color_item, curnlcolor); XmToggleButtonSetState(display_nodelist_item, displaynl, False); } } void nodelist_done_proc(void) { XtUnmanageChild(nodelist_frame); } void create_nodelist_popup(void) { Widget bt, fr, rc, rc2; int i; if (nodelist_frame) { update_nodelist(); XtRaise(nodelist_frame); return; } CreatePNodeList(0); nodelist_frame = XmCreateDialogShell(app_shell, "Select nodes", NULL, 0); handle_close(nodelist_frame); nodelist_panel = XmCreateRowColumn(nodelist_frame, "panel", NULL, 0); fr = XmCreateFrame(nodelist_panel, "frame1", NULL, 0); rc = XmCreateRowColumn(fr, "rc1", NULL, 0); nodelist_ival_item = CreateTextItem2(rc, 15, "Current node ival: "); nodelist_dval_item = CreateTextItem2(rc, 15, "Current node dval: "); nodelist_color_item = CreateColorChoice(rc, "Color: ", 1); display_nodelist_item = XtVaCreateManagedWidget("Display selected nodes", xmToggleButtonWidgetClass, rc, NULL); XtManageChild(rc); XtManageChild(fr); fr = XmCreateFrame(nodelist_panel, "frame1", NULL, 0); rc = XmCreateRowColumn(fr, "rc1", NULL, 0); XtVaSetValues(rc, XmNorientation, XmHORIZONTAL, NULL); bt = XtVaCreateManagedWidget("Accept", xmPushButtonWidgetClass, rc, NULL); XtAddCallback(bt, XmNactivateCallback, (XtCallbackProc) nodelist_accept_proc, NULL); nlbut[0] = XtVaCreateManagedWidget("Pick", xmPushButtonWidgetClass, rc, NULL); XtAddCallback(nlbut[0], XmNactivateCallback, (XtCallbackProc) PickPNodeList, NULL); nlbut[1] = XtVaCreateManagedWidget("Clear All", xmPushButtonWidgetClass, rc, NULL); XtAddCallback(nlbut[1], XmNactivateCallback, (XtCallbackProc) DestroyAllPNodeLists, NULL); nlbut[2] = XtVaCreateManagedWidget("Read...", xmPushButtonWidgetClass, rc, NULL); XtAddCallback(nlbut[2], XmNactivateCallback, (XtCallbackProc) create_readnodelist_frame, NULL); nlbut[3] = XtVaCreateManagedWidget("Write...", xmPushButtonWidgetClass, rc, NULL); XtAddCallback(nlbut[3], XmNactivateCallback, (XtCallbackProc) create_writenodelist_frame, NULL); bt = XtVaCreateManagedWidget("Done", xmPushButtonWidgetClass, rc, NULL); XtAddCallback(bt, XmNactivateCallback, (XtCallbackProc) destroy_dialog, nodelist_frame); XtManageChild(rc); XtManageChild(fr); XtManageChild(nodelist_panel); XtManageChild(nodelist_frame); /* for (i = 0; i < 4; i++) { XtSetSensitive(nlbut[i], False); } */ update_nodelist(); } typedef struct { Widget top; Widget display; Widget *item; Isolparms delhip; Isolparms delhhip; Isolparms hip; } DelHUI; static DelHUI dui; int display_delh = 0; void delh_accept_proc(Widget w, XtPointer clientd, XtPointer calld) { DelHUI *dui = (DelHUI *) clientd; display_delh = XmToggleButtonGetState(dui->display); } void drawdelh(int gridno) { extern int mapisolconc[]; int cd = GetChoice(dui.item); int i, n1, n2, n3; double hmin, hmax, delh, h; switch ((int) cd) { case 0: for (i = 0; i < grid[gridno].nmel; i++) { n1 = grid[gridno].icon[i].nl[0]; n2 = grid[gridno].icon[i].nl[1]; n3 = grid[gridno].icon[i].nl[2]; hmax = hmin = grid[gridno].depth[n1]; if (hmin > grid[gridno].depth[n2]) { hmin = grid[gridno].depth[n2]; } if (hmin > grid[gridno].depth[n3]) { hmin = grid[gridno].depth[n3]; } if (hmax < grid[gridno].depth[n2]) { hmax = grid[gridno].depth[n2]; } if (hmax < grid[gridno].depth[n3]) { hmax = grid[gridno].depth[n3]; } delh = hmax - hmin; /*PBPFOUND*/ fillel(i, delh, dui.delhip, mapisolconc, dui.delhip.nisol); } if (dui.delhip.lactive == ON) { dolegend(dui.delhip, mapisolconc, dui.delhip.nisol); } break; case 1: for (i = 0; i < grid[gridno].nmel; i++) { n1 = grid[gridno].icon[i].nl[0]; n2 = grid[gridno].icon[i].nl[1]; n3 = grid[gridno].icon[i].nl[2]; hmax = hmin = grid[gridno].depth[n1]; if (hmin > grid[gridno].depth[n2]) { hmin = grid[gridno].depth[n2]; } if (hmin > grid[gridno].depth[n3]) { hmin = grid[gridno].depth[n3]; } if (hmax < grid[gridno].depth[n2]) { hmax = grid[gridno].depth[n2]; } if (hmax < grid[gridno].depth[n3]) { hmax = grid[gridno].depth[n3]; } delh = hmax - hmin; h = (grid[gridno].depth[n1] + grid[gridno].depth[n2] + grid[gridno].depth[n3]); h *= 0.333333333333; if (h < 1.0) { h = 1.0; } fillel(i, delh / h, dui.delhhip, mapisolconc, dui.delhhip.nisol); } if (dui.delhhip.lactive == ON) { dolegend(dui.delhhip, mapisolconc, dui.delhhip.nisol); } break; case 2: for (i = 0; i < grid[gridno].nmel; i++) { n1 = grid[gridno].icon[i].nl[0]; n2 = grid[gridno].icon[i].nl[1]; n3 = grid[gridno].icon[i].nl[2]; h = (grid[gridno].depth[n1] + grid[gridno].depth[n2] + grid[gridno].depth[n3]); h *= 0.333333333333; fillel(i, h, dui.hip, mapisolconc, dui.hip.nisol); } if (dui.hip.lactive == ON) { dolegend(dui.hip, mapisolconc, dui.hip.nisol); } break; } } void set_delh_limits(int gridno) { int i, n1, n2, n3; double h, delh, delhh; double tmin, tmax; double hmin, hmax; double delhmin, delhmax; double delhhmin, delhhmax; delhmin = delhhmin = 1e38; delhmax = delhhmax = -1e38; for (i = 0; i < grid[gridno].nmel; i++) { n1 = grid[gridno].icon[i].nl[0]; n2 = grid[gridno].icon[i].nl[1]; n3 = grid[gridno].icon[i].nl[2]; tmax = tmin = grid[gridno].depth[n1]; if (tmin > grid[gridno].depth[n2]) { tmin = grid[gridno].depth[n2]; } if (tmin > grid[gridno].depth[n3]) { tmin = grid[gridno].depth[n3]; } if (tmax < grid[gridno].depth[n2]) { tmax = grid[gridno].depth[n2]; } if (tmax < grid[gridno].depth[n3]) { tmax = grid[gridno].depth[n3]; } delh = tmax - tmin; if (delhmin > delh) { delhmin = delh; } if (delhmax < delh) { delhmax = delh; } h = (grid[gridno].depth[n1] + grid[gridno].depth[n2] + grid[gridno].depth[n3]); h *= 0.333333333333; if (h < 1.0) { h = 1.0; } if (hmin > h) { hmin = h; } if (hmax < h) { hmax = h; } delhh = delh / h; if (delhhmin > delhh) { delhhmin = delhh; } if (delhhmax < delhh) { delhhmax = delhh; } } dui.delhip.cmin = delhmin; dui.delhip.cmax = delhmax; dui.delhhip.cmin = delhhmin; dui.delhhip.cmax = delhhmax; dui.hip.cmin = hmin; dui.hip.cmax = hmax; } void delh_isol_proc(Widget w, XtPointer clientd, XtPointer calld) { DelHUI *dui = (DelHUI *) clientd; int cd = GetChoice(dui->item); switch ((int) cd) { case 0: create_isolines_popup("Delta H", &(dui->delhip)); break; case 1: create_isolines_popup("Delta H / H", &(dui->delhhip)); break; case 2: create_isolines_popup("H", &(dui->hip)); break; } } void update_delh(DelHUI dui) { if (dui.top) { } } void create_delh_popup(void) { Widget panel, bt, fr, rc, rc2, lab; if (dui.top) { set_delh_limits(curgrid); update_delh(dui); XtRaise(dui.top); return; } dui.top = XmCreateDialogShell(app_shell, "DelH/H", NULL, 0); panel = XmCreateRowColumn(dui.top, "panel", NULL, 0); dui.display = XtVaCreateManagedWidget("Display selected quantity", xmToggleButtonWidgetClass, panel, NULL); dui.item = CreatePanelChoice1(panel, "Show: ", 4, "Delta H", "Delta H / H", "H", NULL, 0); rc2 = XmCreateRowColumn(panel, "rc", NULL, 0); XtVaSetValues(rc2, XmNorientation, XmHORIZONTAL, XmNpacking, XmPACK_TIGHT, NULL); bt = XtVaCreateManagedWidget("Accept", xmPushButtonWidgetClass, rc2, NULL); XtAddCallback(bt, XmNactivateCallback, (XtCallbackProc) delh_accept_proc, (XtPointer) & dui); bt = XtVaCreateManagedWidget("Isolines...", xmPushButtonWidgetClass, rc2, NULL); XtAddCallback(bt, XmNactivateCallback, (XtCallbackProc) delh_isol_proc, (XtPointer) & dui); bt = XtVaCreateManagedWidget("Done", xmPushButtonWidgetClass, rc2, NULL); XtAddCallback(bt, XmNactivateCallback, (XtCallbackProc) destroy_dialog, (XtPointer) dui.top); XtManageChild(rc2); XtManageChild(panel); XtManageChild(dui.top); set_isolines_defaults(&dui.delhip); set_isolines_defaults(&dui.delhhip); set_isolines_defaults(&dui.hip); set_delh_limits(curgrid); update_delh(dui); } typedef struct { Widget top; Widget display; Widget *item; Isolparms ip; } ElDepthsUI; void update_dpe(ElDepthsUI dui) { if (dui.top) { } } void dpe_isol_proc(Widget w, XtPointer clientd, XtPointer calld) { ElDepthsUI *dui = (ElDepthsUI *) clientd; set_isolines_defaults(dui->ip); create_isolines_popup("Element depths", &(dui->ip)); } void dpe_read_proc(Widget w, XtPointer clientd, XtPointer calld) { ElDepthsUI *dui = (ElDepthsUI *) clientd; } void dpe_write_proc(Widget w, XtPointer clientd, XtPointer calld) { ElDepthsUI *dui = (ElDepthsUI *) clientd; } void dpe_accept_proc(Widget w, XtPointer clientd, XtPointer calld) { ElDepthsUI *dui = (ElDepthsUI *) clientd; } void dpe_query_proc(Widget w, XtPointer clientd, XtPointer calld) { ElDepthsUI *dui = (ElDepthsUI *) clientd; } /* * Depths at elements */ void create_dpe_frame(void) { static ElDepthsUI ui; Widget panel, bt, fr, rc, rc2, lab; if (ui.top) { update_dpe(ui); XtRaise(ui.top); return; } ui.top = XmCreateDialogShell(app_shell, "Depths at Elements", NULL, 0); panel = XmCreateRowColumn(ui.top, "panel", NULL, 0); ui.display = XtVaCreateManagedWidget("Display selected quantity", xmToggleButtonWidgetClass, panel, NULL); ui.item = CreatePanelChoice1(panel, "Show: ", 3, "Isolines", "Values", NULL, 0); rc2 = XmCreateRowColumn(panel, "rc", NULL, 0); XtVaSetValues(rc2, XmNorientation, XmHORIZONTAL, XmNpacking, XmPACK_TIGHT, NULL); bt = XtVaCreateManagedWidget("Accept", xmPushButtonWidgetClass, rc2, NULL); XtAddCallback(bt, XmNactivateCallback, (XtCallbackProc) dpe_accept_proc, (XtPointer) & ui); bt = XtVaCreateManagedWidget("Read...", xmPushButtonWidgetClass, rc2, NULL); XtAddCallback(bt, XmNactivateCallback, (XtCallbackProc) dpe_read_proc, (XtPointer) & ui); bt = XtVaCreateManagedWidget("Write...", xmPushButtonWidgetClass, rc2, NULL); XtAddCallback(bt, XmNactivateCallback, (XtCallbackProc) dpe_write_proc, (XtPointer) & ui); bt = XtVaCreateManagedWidget("Query...", xmPushButtonWidgetClass, rc2, NULL); XtAddCallback(bt, XmNactivateCallback, (XtCallbackProc) dpe_write_proc, (XtPointer) & ui); bt = XtVaCreateManagedWidget("Isolines...", xmPushButtonWidgetClass, rc2, NULL); XtAddCallback(bt, XmNactivateCallback, (XtCallbackProc) dpe_isol_proc, (XtPointer) & ui); bt = XtVaCreateManagedWidget("Done", xmPushButtonWidgetClass, rc2, NULL); XtAddCallback(bt, XmNactivateCallback, (XtCallbackProc) destroy_dialog, (XtPointer) ui.top); XtManageChild(rc2); XtManageChild(panel); XtManageChild(ui.top); set_isolines_defaults(&ui.ip); update_dpe(ui); }