atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
atom_insert.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'atom_insert.c'
24*
25* Contains:
26*
27
28 - The functions to insert bond(s) in a project
29
30*
31* List of functions:
32
33 void add_bonds_to_project (project * this_proj, int removed, int nbd, int ** new_bond_list);
34 void add_bonds_to_list (int ** new_bond_list, int nat, int nbd, atomic_object * object);
35 void prepare_to_instert (gchar * key, project * this_proj, atom_search * asearch, gboolean visible);
36
37 G_MODULE_EXPORT void set_atoms_to_insert (GtkComboBox * box, gpointer data);
38
39*/
40
41#include "atom_edit.h"
42
53void add_bonds_to_project (project * this_proj, int removed, int nbd, int ** new_bond_list)
54{
55 int i, j;
56 if (nbd)
57 {
58 i = this_proj -> modelgl -> bonds[0][0];
59 this_proj -> modelgl -> bondid[0][0] = g_realloc (this_proj -> modelgl -> bondid[0][0], (i+nbd)*sizeof*this_proj -> modelgl -> bondid[0][0]);
60 for (j=0; j<nbd; j++)
61 {
62 this_proj -> modelgl -> bondid[0][0][j+i] = allocint (2);
63 this_proj -> modelgl -> bondid[0][0][j+i][0] = new_bond_list[j][0] + this_proj -> natomes - removed;
64 this_proj -> modelgl -> bondid[0][0][j+i][1] = new_bond_list[j][1] + this_proj -> natomes - removed;
65 }
66 this_proj -> modelgl -> bonds[0][0] += nbd;
67 this_proj -> modelgl -> allbonds[0] += nbd;
68 }
69}
70
81void add_bonds_to_list (int ** new_bond_list, int nat, int nbd, atomic_object * object)
82{
83 int i;
84 if (object -> bonds)
85 {
86 for (i=0; i<object -> bonds; i++)
87 {
88 new_bond_list[i+nbd][0] = object -> ibonds[i][0] + nat;
89 new_bond_list[i+nbd][1] = object -> ibonds[i][1] + nat;
90 }
91 }
92}
93
104void prepare_to_instert (gchar * key, project * this_proj, atom_search * asearch, gboolean visible)
105{
106 int i = get_selected_object_id (visible, this_proj -> id, key, asearch);
107 if (i == FROM_PROJECT || i == FROM_DATA || i > 0) to_insert_in_project (i, -1, this_proj, asearch, visible);
108}
109
118G_MODULE_EXPORT void set_atoms_to_insert (GtkComboBox * box, gpointer data)
119{
120 GValue val = {0, };
121 GtkTreeModel * cmodel = gtk_combo_box_get_model (box);
122 GtkTreeIter iter;
123 if (gtk_combo_box_get_active_iter (box, & iter))
124 {
125 gtk_tree_model_get_value (cmodel, & iter, 0, & val);
126 tint * dat = (tint *)data;
127 gchar * str = g_strdup_printf ("%s", (char *)g_value_get_string (& val));
128 project * this_proj = get_project_by_id (dat -> a);
129 prepare_to_instert (str, this_proj, this_proj -> modelgl -> search_widg[dat -> c], TRUE);
130 g_free (str);
131 }
132 gtk_combo_box_set_active (box, 0);
133}
Function declarations for the mode edition window.
int get_selected_object_id(gboolean visible, int p, gchar *str, atom_search *asearch)
get the id of the object selected (in contextual menu, or in combo box)
Definition w_search.c:2385
void to_insert_in_project(int stat, int orig, project *this_proj, atom_search *asearch, gboolean visible)
to insert object in project
void add_bonds_to_list(int **new_bond_list, int nat, int nbd, atomic_object *object)
add object bond(s) list to overall bond(s) list
Definition atom_insert.c:81
void add_bonds_to_project(project *this_proj, int removed, int nbd, int **new_bond_list)
add bond list to project bond list
Definition atom_insert.c:53
G_MODULE_EXPORT void set_atoms_to_insert(GtkComboBox *box, gpointer data)
change the object to insert
void prepare_to_instert(gchar *key, project *this_proj, atom_search *asearch, gboolean visible)
prepare to insert something
int bonds[NUM_STYLES][2]
float val
Definition dlp_init.c:117
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
@ FROM_PROJECT
Definition glwin.h:81
@ FROM_DATA
Definition glwin.h:74
Definition global.h:104
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95