void merge_group(struct group *group, struct group *child) { struct groupdata *groupdata = group->data; struct groupdata *childdata = child->data; for (size_t i = 0; i < ptrarray_count(childdata->blocks); ++i) { struct block *copy = copy_block(get_ptrarray(childdata->blocks, i)); translate_block(copy, &child->position); push_ptrarray(groupdata->blocks, copy); } for (size_t i = 0; i < ptrarray_count(childdata->groups); ++i) { struct group *copy = copy_group(get_ptrarray(childdata->groups, i)); vec3_add(©->position, ©->position, &child->position); insert_group(group, copy); } destroy_group(child); update_group_vertexarray(group); }
int id_copy(ID *id, ID **newid, int test) { if(!test) *newid= NULL; /* conventions: * - make shallow copy, only this ID block * - id.us of the new ID is set to 1 */ switch(GS(id->name)) { case ID_SCE: return 0; /* can't be copied from here */ case ID_LI: return 0; /* can't be copied from here */ case ID_OB: if(!test) *newid= (ID*)copy_object((Object*)id); return 1; case ID_ME: if(!test) *newid= (ID*)copy_mesh((Mesh*)id); return 1; case ID_CU: if(!test) *newid= (ID*)copy_curve((Curve*)id); return 1; case ID_MB: if(!test) *newid= (ID*)copy_mball((MetaBall*)id); return 1; case ID_MA: if(!test) *newid= (ID*)copy_material((Material*)id); return 1; case ID_TE: if(!test) *newid= (ID*)copy_texture((Tex*)id); return 1; case ID_IM: if(!test) *newid= (ID*)copy_image((Image*)id); return 1; case ID_LT: if(!test) *newid= (ID*)copy_lattice((Lattice*)id); return 1; case ID_LA: if(!test) *newid= (ID*)copy_lamp((Lamp*)id); return 1; case ID_SPK: if(!test) *newid= (ID*)copy_speaker((Speaker*)id); return 1; case ID_CA: if(!test) *newid= (ID*)copy_camera((Camera*)id); return 1; case ID_IP: return 0; /* deprecated */ case ID_KE: if(!test) *newid= (ID*)copy_key((Key*)id); return 1; case ID_WO: if(!test) *newid= (ID*)copy_world((World*)id); return 1; case ID_SCR: return 0; /* can't be copied from here */ case ID_VF: return 0; /* not implemented */ case ID_TXT: if(!test) *newid= (ID*)copy_text((Text*)id); return 1; case ID_SCRIPT: return 0; /* deprecated */ case ID_SO: return 0; /* not implemented */ case ID_GR: if(!test) *newid= (ID*)copy_group((Group*)id); return 1; case ID_AR: if(!test) *newid= (ID*)copy_armature((bArmature*)id); return 1; case ID_AC: if(!test) *newid= (ID*)copy_action((bAction*)id); return 1; case ID_NT: if(!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id); return 1; case ID_BR: if(!test) *newid= (ID*)copy_brush((Brush*)id); return 1; case ID_PA: if(!test) *newid= (ID*)psys_copy_settings((ParticleSettings*)id); return 1; case ID_WM: return 0; /* can't be copied from here */ case ID_GD: return 0; /* not implemented */ } return 0; }
static gmx_bool parse_entry(char **string, int natoms, t_atoms *atoms, t_blocka *block, char ***gn, atom_id *nr, atom_id *index, char *gname) { static char **names, *ostring; static gmx_bool bFirst = TRUE; int j, n_names, sel_nr1; atom_id i, nr1, *index1; char c; gmx_bool bRet, bCompl; if (bFirst) { bFirst = FALSE; snew(names, MAXNAMES); for (i = 0; i < MAXNAMES; i++) { snew(names[i], NAME_LEN+1); } } bRet = FALSE; sel_nr1 = NOTSET; while (*string[0] == ' ') { (*string)++; } if ((*string)[0] == '!') { bCompl = TRUE; (*string)++; while (*string[0] == ' ') { (*string)++; } } else { bCompl = FALSE; } ostring = *string; if (parse_int(string, &sel_nr1) || parse_string(string, &sel_nr1, block->nr, *gn)) { if ((sel_nr1 >= 0) && (sel_nr1 < block->nr)) { copy_group(sel_nr1, block, nr, index); strcpy(gname, (*gn)[sel_nr1]); printf("Copied index group %d '%s'\n", sel_nr1, (*gn)[sel_nr1]); bRet = TRUE; } else { printf("Group %d does not exist\n", sel_nr1); } } else if ((*string)[0] == 'a') { (*string)++; if (check_have_atoms(atoms, ostring)) { if (parse_int(string, &sel_nr1)) { bRet = select_atomnumbers(string, atoms, sel_nr1, nr, index, gname); } else if (parse_names(string, &n_names, names)) { bRet = select_atomnames(atoms, n_names, names, nr, index, FALSE); make_gname(n_names, names, gname); } } } else if ((*string)[0] == 't') { (*string)++; if (check_have_atoms(atoms, ostring) && parse_names(string, &n_names, names)) { if (atoms->atomtype == NULL) { printf("Need a run input file to select atom types\n"); } else { bRet = select_atomnames(atoms, n_names, names, nr, index, TRUE); make_gname(n_names, names, gname); } } } else if (strncmp(*string, "res", 3) == 0) { (*string) += 3; if (check_have_atoms(atoms, ostring) && parse_int(string, &sel_nr1) && (sel_nr1 >= 0) && (sel_nr1 < block->nr) ) { bRet = atoms_from_residuenumbers(atoms, sel_nr1, block, nr, index, (*gn)[sel_nr1]); sprintf(gname, "atom_%s", (*gn)[sel_nr1]); } } else if (strncmp(*string, "ri", 2) == 0) { (*string) += 2; if (check_have_atoms(atoms, ostring) && parse_int_char(string, &sel_nr1, &c)) { bRet = select_residueindices(string, atoms, sel_nr1, c, nr, index, gname); } } else if ((*string)[0] == 'r') { (*string)++; if (check_have_atoms(atoms, ostring)) { if (parse_int_char(string, &sel_nr1, &c)) { bRet = select_residuenumbers(string, atoms, sel_nr1, c, nr, index, gname); } else if (parse_names(string, &n_names, names)) { bRet = select_residuenames(atoms, n_names, names, nr, index); make_gname(n_names, names, gname); } } } else if (strncmp(*string, "chain", 5) == 0) { (*string) += 5; if (check_have_atoms(atoms, ostring) && parse_names(string, &n_names, names)) { bRet = select_chainnames(atoms, n_names, names, nr, index); sprintf(gname, "ch%s", names[0]); for (i = 1; i < n_names; i++) { strcat(gname, names[i]); } } } if (bRet && bCompl) { snew(index1, natoms-*nr); nr1 = 0; for (i = 0; i < natoms; i++) { j = 0; while ((j < *nr) && (index[j] != i)) { j++; } if (j == *nr) { if (nr1 >= natoms-*nr) { printf("There are double atoms in your index group\n"); break; } index1[nr1] = i; nr1++; } } *nr = nr1; for (i = 0; i < nr1; i++) { index[i] = index1[i]; } sfree(index1); for (i = strlen(gname)+1; i > 0; i--) { gname[i] = gname[i-1]; } gname[0] = '!'; printf("Complemented group: %d atoms\n", *nr); } return bRet; }