File: gui_defect.c

package info (click to toggle)
gdis 0.90-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 10,332 kB
  • ctags: 9,022
  • sloc: ansic: 71,121; perl: 298; sh: 123; python: 115; makefile: 69; xml: 26
file content (190 lines) | stat: -rw-r--r-- 6,559 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
Copyright (C) 2003 by Sean David Fleming

sean@ivec.org

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

The GNU GPL can also be found at http://www.gnu.org
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "gdis.h"
#include "defect.h"
#include "dialog.h"
#include "matrix.h"
#include "gui_shorts.h"
#include "interface.h"

/* globals */
extern struct sysenv_pak sysenv;
struct defect_pak defect;

/**********************/
/* setup gui defaults */
/**********************/
void gui_defect_default(void)
{
defect.cleave = FALSE;
defect.neutral = FALSE;
defect.cluster = FALSE;
VEC2SET(defect.region, 10, 10);
VEC3SET(defect.orient, 1, 0, 0);
VEC3SET(defect.burgers, 1, 0, 0);
VEC2SET(defect.origin, 0, 0);
VEC2SET(defect.center, 0, 0);
}

/*****************************************/
/* callback to start the defect building */
/*****************************************/
void gui_defect_build(void)
{
struct model_pak *model;

/* checks and setup */
model = sysenv.active_model;
if (!model)
  return;
if (model->periodic != 3)
  return;

/* TODO - if the building is long - run in background */
defect_new(&defect, model);
}

/**************************/
/* update on model switch */
/**************************/
void gui_defect_refresh(gpointer data)
{
}

/**********************************/
/* neutralization scheme callback */
/**********************************/
void gui_defect_neutralization(GtkWidget *entry)
{
const gchar *text;

g_assert(entry != NULL);
g_assert(GTK_IS_ENTRY(entry));

text = gtk_entry_get_text(GTK_ENTRY(entry));
}

/************************************/
/* setup the defect creation dialog */
/************************************/
void gui_defect_dialog(void)
{
gpointer dialog;
GList *list;
GtkWidget *window, *vbox, *hbox, *table, *label, *spin, *combo;

/* create new dialog */
/* TODO - get rid of the need for a unique code in this call */
/* replace with lookups based on the name & single/multiple instance allowed */
dialog = dialog_request(100, "Dislocation builder", gui_defect_refresh, NULL, NULL);
if (!dialog)
  return;
window = dialog_window(dialog);

/* init */
gui_defect_default();

/* defect build setup frame */
vbox = gui_frame_vbox("Geometry", FALSE, FALSE, GTK_DIALOG(window)->vbox);
table = gtk_table_new(4, 5, FALSE);
gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0); 

label = gtk_label_new("Orientation vector ");
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(table),label,0,1,0,1);
spin = gui_direct_spin(NULL, &defect.orient[0], -20, 20, 1, NULL, NULL, NULL);
gtk_table_attach_defaults(GTK_TABLE(table),spin,1,2,0,1);
spin = gui_direct_spin(NULL, &defect.orient[1], -20, 20, 1, NULL, NULL, NULL);
gtk_table_attach_defaults(GTK_TABLE(table),spin,2,3,0,1);
spin = gui_direct_spin(NULL, &defect.orient[2], -20, 20, 1, NULL, NULL, NULL);
gtk_table_attach_defaults(GTK_TABLE(table),spin,3,4,0,1);

label = gtk_label_new("Burgers vector ");
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(table),label,0,1,1,2);
spin = gui_direct_spin(NULL, &defect.burgers[0], -20, 20, 0.05, NULL, NULL, NULL);
gtk_table_attach_defaults(GTK_TABLE(table),spin,1,2,1,2);
spin = gui_direct_spin(NULL, &defect.burgers[1], -20, 20, 0.05, NULL, NULL, NULL);
gtk_table_attach_defaults(GTK_TABLE(table),spin,2,3,1,2);
spin = gui_direct_spin(NULL, &defect.burgers[2], -20, 20, 0.05, NULL, NULL, NULL);
gtk_table_attach_defaults(GTK_TABLE(table),spin,3,4,1,2);

label = gtk_label_new("Defect origin ");
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(table),label,0,1,2,3);
spin = gui_direct_spin(NULL, &defect.origin[0], 0.0, 1.0, 0.05, NULL, NULL, NULL);
gtk_table_attach_defaults(GTK_TABLE(table),spin,2,3,2,3);
spin = gui_direct_spin(NULL, &defect.origin[1], 0.0, 1.0, 0.05, NULL, NULL, NULL);
gtk_table_attach_defaults(GTK_TABLE(table),spin,3,4,2,3);

label = gtk_label_new("Defect center ");
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(table),label,0,1,3,4);
spin = gui_direct_spin(NULL, &defect.center[0], 0.0, 1.0, 0.05, NULL, NULL, NULL);
gtk_table_attach_defaults(GTK_TABLE(table),spin,2,3,3,4);
spin = gui_direct_spin(NULL, &defect.center[1], 0.0, 1.0, 0.05, NULL, NULL, NULL);
gtk_table_attach_defaults(GTK_TABLE(table),spin,3,4,3,4);

label = gtk_label_new("Region sizes ");
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(table),label,0,1,4,5);
spin = gui_direct_spin(NULL, &defect.region[0], 0, 999, 1, NULL, NULL, NULL);
gtk_table_attach_defaults(GTK_TABLE(table),spin,2,3,4,5);
spin = gui_direct_spin(NULL, &defect.region[1], 0, 999, 1, NULL, NULL, NULL);
gtk_table_attach_defaults(GTK_TABLE(table),spin,3,4,4,5);

/* construct setup frame */
vbox = gui_frame_vbox("Options", FALSE, FALSE, GTK_DIALOG(window)->vbox);

hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); 
label = gtk_label_new("Charge neutralization ");
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); 
list = NULL;
list = g_list_prepend(list, "none");
combo = gtk_combo_new();
gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(combo)->entry), FALSE);
gtk_combo_set_popdown_strings(GTK_COMBO(combo), list);
g_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "changed", 
                 GTK_SIGNAL_FUNC(gui_defect_neutralization), NULL);
gtk_box_pack_end(GTK_BOX(hbox), combo, FALSE, FALSE, 0); 

gui_direct_check("Allow bond cleaving ", &defect.cleave, NULL, NULL, vbox);
gui_direct_check("Discard periodicity ", &defect.cluster, NULL, NULL, vbox);

/* terminating buttons */
gui_stock_button(GTK_STOCK_EXECUTE, gui_defect_build, NULL,
                   GTK_DIALOG(window)->action_area);

gui_stock_button(GTK_STOCK_CLOSE, dialog_destroy, dialog,
                   GTK_DIALOG(window)->action_area);

gtk_widget_show_all(window);
}