4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2004 Blender Foundation.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
34 #include "MEM_guardedalloc.h"
36 #include "DNA_anim_types.h"
37 #include "DNA_action_types.h"
38 #include "DNA_armature_types.h"
39 #include "DNA_constraint_types.h"
40 #include "DNA_curve_types.h"
41 #include "DNA_camera_types.h"
42 #include "DNA_image_types.h"
43 #include "DNA_ipo_types.h"
44 #include "DNA_group_types.h"
45 #include "DNA_key_types.h"
46 #include "DNA_lamp_types.h"
47 #include "DNA_material_types.h"
48 #include "DNA_mesh_types.h"
49 #include "DNA_meta_types.h"
50 #include "DNA_modifier_types.h"
51 #include "DNA_nla_types.h"
52 #include "DNA_object_types.h"
53 #include "DNA_oops_types.h"
54 #include "DNA_particle_types.h"
55 #include "DNA_scene_types.h"
56 #include "DNA_screen_types.h"
57 #include "DNA_space_types.h"
58 #include "DNA_texture_types.h"
59 #include "DNA_text_types.h"
60 #include "DNA_world_types.h"
61 #include "DNA_sequence_types.h"
63 #include "BLI_blenlib.h"
65 #include "IMB_imbuf_types.h"
67 #include "BKE_animsys.h"
68 #include "BKE_constraint.h"
69 #include "BKE_context.h"
70 #include "BKE_deform.h"
71 #include "BKE_depsgraph.h"
72 #include "BKE_global.h"
73 #include "BKE_group.h"
74 #include "BKE_library.h"
76 #include "BKE_material.h"
77 #include "BKE_modifier.h"
78 #include "BKE_object.h"
79 #include "BKE_report.h"
80 #include "BKE_screen.h"
81 #include "BKE_scene.h"
82 #include "BKE_sequence.h"
83 #include "BKE_utildefines.h"
85 #include "ED_screen.h"
93 #include "BIF_glutil.h"
95 #include "UI_interface.h"
96 #include "UI_interface_icons.h"
97 #include "UI_resources.h"
98 #include "UI_view2d.h"
101 #include "RNA_access.h"
103 #include "ED_armature.h"
104 #include "ED_object.h"
105 #include "ED_screen.h"
107 #include "outliner_intern.h"
113 #include "PIL_time.h"
119 #define OL_TOG_RESTRICT_VIEWX 54
120 #define OL_TOG_RESTRICT_SELECTX 36
121 #define OL_TOG_RESTRICT_RENDERX 18
123 #define OL_TOGW OL_TOG_RESTRICT_VIEWX
125 #define OL_RNA_COLX 300
126 #define OL_RNA_COL_SIZEX 150
127 #define OL_RNA_COL_SPACEX 50
131 #define TREESTORE(a) ((a)?soops->treestore->data+(a)->store_index:NULL)
133 /* ************* XXX **************** */
135 static void allqueue() {}
136 static void BIF_undo_push() {}
137 static void BIF_preview_changed() {}
138 static void error() {}
139 static int pupmenu() {return 0;}
141 /* ********************************** */
144 /* ******************** PROTOTYPES ***************** */
145 static void outliner_draw_tree_element(Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty);
146 static void outliner_do_object_operation(Scene *scene, SpaceOops *soops, ListBase *lb,
147 void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *));
150 /* ******************** PERSISTANT DATA ***************** */
152 static void outliner_storage_cleanup(SpaceOops *soops)
154 TreeStore *ts= soops->treestore;
157 TreeStoreElem *tselem;
160 /* each element used once, for ID blocks with more users to have each a treestore */
161 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) tselem->used= 0;
163 /* cleanup only after reading file or undo step, and always for
164 * RNA datablocks view in order to save memory */
165 if(soops->storeflag & SO_TREESTORE_CLEANUP) {
167 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) {
168 if(tselem->id==NULL) unused++;
172 if(ts->usedelem == unused) {
175 ts->usedelem= ts->totelem= 0;
178 TreeStoreElem *tsnewar, *tsnew;
180 tsnew=tsnewar= MEM_mallocN((ts->usedelem-unused)*sizeof(TreeStoreElem), "new tselem");
181 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) {
189 ts->usedelem-= unused;
190 ts->totelem= ts->usedelem;
197 static void check_persistant(SpaceOops *soops, TreeElement *te, ID *id, short type, short nr)
200 TreeStoreElem *tselem;
203 /* case 1; no TreeStore */
204 if(soops->treestore==NULL) {
205 ts= soops->treestore= MEM_callocN(sizeof(TreeStore), "treestore");
207 ts= soops->treestore;
209 /* check if 'te' is in treestore */
211 for(a=0; a<ts->usedelem; a++, tselem++) {
212 if(tselem->id==id && tselem->used==0) {
213 if((type==0 && tselem->type==0) ||(tselem->type==type && tselem->nr==nr)) {
221 /* add 1 element to treestore */
222 if(ts->usedelem==ts->totelem) {
223 TreeStoreElem *tsnew;
225 tsnew= MEM_mallocN((ts->totelem+TS_CHUNK)*sizeof(TreeStoreElem), "treestore data");
227 memcpy(tsnew, ts->data, ts->totelem*sizeof(TreeStoreElem));
231 ts->totelem+= TS_CHUNK;
234 tselem= ts->data+ts->usedelem;
237 if(type) tselem->nr= nr; // we're picky! :)
241 tselem->flag= TSE_CLOSED;
242 te->store_index= ts->usedelem;
247 /* ******************** TREE MANAGEMENT ****************** */
249 void outliner_free_tree(ListBase *lb)
253 TreeElement *te= lb->first;
255 outliner_free_tree(&te->subtree);
258 if(te->flag & TE_FREE_NAME) MEM_freeN(te->name);
263 static void outliner_height(SpaceOops *soops, ListBase *lb, int *h)
265 TreeElement *te= lb->first;
267 TreeStoreElem *tselem= TREESTORE(te);
268 if((tselem->flag & TSE_CLOSED)==0)
269 outliner_height(soops, &te->subtree, h);
275 #if 0 // XXX this is currently disabled until te->xend is set correctly
276 static void outliner_width(SpaceOops *soops, ListBase *lb, int *w)
278 TreeElement *te= lb->first;
280 // TreeStoreElem *tselem= TREESTORE(te);
282 // XXX fixme... te->xend is not set yet
283 if(tselem->flag & TSE_CLOSED) {
287 outliner_width(soops, &te->subtree, w);
293 static void outliner_rna_width(SpaceOops *soops, ListBase *lb, int *w, int startx)
295 TreeElement *te= lb->first;
297 TreeStoreElem *tselem= TREESTORE(te);
298 // XXX fixme... (currently, we're using a fixed length of 100)!
306 if((tselem->flag & TSE_CLOSED)==0)
307 outliner_rna_width(soops, &te->subtree, w, startx+OL_X);
312 static TreeElement *outliner_find_tree_element(ListBase *lb, int store_index)
314 TreeElement *te= lb->first, *tes;
316 if(te->store_index==store_index) return te;
317 tes= outliner_find_tree_element(&te->subtree, store_index);
326 static ID *outliner_search_back(SpaceOops *soops, TreeElement *te, short idcode)
328 TreeStoreElem *tselem;
332 tselem= TREESTORE(te);
333 if(tselem->type==0 && te->idcode==idcode) return tselem->id;
346 static int treesort_alpha(const void *v1, const void *v2)
348 const struct treesort *x1= v1, *x2= v2;
351 /* first put objects last (hierarchy) */
352 comp= (x1->idcode==ID_OB);
353 if(x2->idcode==ID_OB) comp+=2;
355 if(comp==1) return 1;
356 else if(comp==2) return -1;
358 int comp= strcmp(x1->name, x2->name);
360 if( comp>0 ) return 1;
361 else if( comp<0) return -1;
367 /* this is nice option for later? doesnt look too useful... */
369 static int treesort_obtype_alpha(const void *v1, const void *v2)
371 const struct treesort *x1= v1, *x2= v2;
373 /* first put objects last (hierarchy) */
374 if(x1->idcode==ID_OB && x2->idcode!=ID_OB) return 1;
375 else if(x2->idcode==ID_OB && x1->idcode!=ID_OB) return -1;
377 /* 2nd we check ob type */
378 if(x1->idcode==ID_OB && x2->idcode==ID_OB) {
379 if( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return 1;
380 else if( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return -1;
384 int comp= strcmp(x1->name, x2->name);
386 if( comp>0 ) return 1;
387 else if( comp<0) return -1;
394 /* sort happens on each subtree individual */
395 static void outliner_sort(SpaceOops *soops, ListBase *lb)
398 TreeStoreElem *tselem;
403 tselem= TREESTORE(te);
405 /* sorting rules; only object lists or deformgroups */
406 if( (tselem->type==TSE_DEFGROUP) || (tselem->type==0 && te->idcode==ID_OB)) {
409 for(te= lb->first; te; te= te->next) totelem++;
412 struct treesort *tear= MEM_mallocN(totelem*sizeof(struct treesort), "tree sort array");
413 struct treesort *tp=tear;
416 for(te= lb->first; te; te= te->next, tp++) {
417 tselem= TREESTORE(te);
420 tp->idcode= te->idcode;
421 if(tselem->type && tselem->type!=TSE_DEFGROUP) tp->idcode= 0; // dont sort this
424 /* keep beginning of list */
425 for(tp= tear, skip=0; skip<totelem; skip++, tp++)
426 if(tp->idcode) break;
429 qsort(tear+skip, totelem-skip, sizeof(struct treesort), treesort_alpha);
431 lb->first=lb->last= NULL;
434 BLI_addtail(lb, tp->te);
441 for(te= lb->first; te; te= te->next) {
442 outliner_sort(soops, &te->subtree);
446 /* Prototype, see functions below */
447 static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv,
448 TreeElement *parent, short type, short index);
451 static void outliner_add_passes(SpaceOops *soops, TreeElement *tenla, ID *id, SceneRenderLayer *srl)
453 TreeStoreElem *tselem= TREESTORE(tenla);
456 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_COMBINED);
457 te->name= "Combined";
458 te->directdata= &srl->passflag;
460 /* save cpu cycles, but we add the first to invoke an open/close triangle */
461 if(tselem->flag & TSE_CLOSED)
464 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_Z);
466 te->directdata= &srl->passflag;
468 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_VECTOR);
470 te->directdata= &srl->passflag;
472 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_NORMAL);
474 te->directdata= &srl->passflag;
476 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_UV);
478 te->directdata= &srl->passflag;
480 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_MIST);
482 te->directdata= &srl->passflag;
484 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_INDEXOB);
485 te->name= "Index Object";
486 te->directdata= &srl->passflag;
488 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_RGBA);
490 te->directdata= &srl->passflag;
492 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_DIFFUSE);
494 te->directdata= &srl->passflag;
496 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_SPEC);
497 te->name= "Specular";
498 te->directdata= &srl->passflag;
500 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_SHADOW);
502 te->directdata= &srl->passflag;
504 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_AO);
506 te->directdata= &srl->passflag;
508 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_REFLECT);
509 te->name= "Reflection";
510 te->directdata= &srl->passflag;
512 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_REFRACT);
513 te->name= "Refraction";
514 te->directdata= &srl->passflag;
516 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_RADIO);
517 te->name= "Radiosity";
518 te->directdata= &srl->passflag;
523 /* special handling of hierarchical non-lib data */
524 static void outliner_add_bone(SpaceOops *soops, ListBase *lb, ID *id, Bone *curBone,
525 TreeElement *parent, int *a)
527 TreeElement *te= outliner_add_element(soops, lb, id, parent, TSE_BONE, *a);
530 te->name= curBone->name;
531 te->directdata= curBone;
533 for(curBone= curBone->childbase.first; curBone; curBone=curBone->next) {
534 outliner_add_bone(soops, &te->subtree, id, curBone, te, a);
538 static void outliner_add_scene_contents(SpaceOops *soops, ListBase *lb, Scene *sce, TreeElement *te)
540 SceneRenderLayer *srl;
541 TreeElement *tenla= outliner_add_element(soops, lb, sce, te, TSE_R_LAYER_BASE, 0);
544 tenla->name= "RenderLayers";
545 for(a=0, srl= sce->r.layers.first; srl; srl= srl->next, a++) {
546 TreeElement *tenlay= outliner_add_element(soops, &tenla->subtree, sce, te, TSE_R_LAYER, a);
547 tenlay->name= srl->name;
548 tenlay->directdata= &srl->passflag;
550 if(srl->light_override)
551 outliner_add_element(soops, &tenlay->subtree, srl->light_override, tenlay, TSE_LINKED_LAMP, 0);
552 if(srl->mat_override)
553 outliner_add_element(soops, &tenlay->subtree, srl->mat_override, tenlay, TSE_LINKED_MAT, 0);
555 outliner_add_passes(soops, tenlay, &sce->id, srl);
558 outliner_add_element(soops, lb, sce->world, te, 0, 0);
560 if(sce->scriptlink.scripts) {
562 tenla= outliner_add_element(soops, lb, sce, te, TSE_SCRIPT_BASE, 0);
563 tenla->name= "Scripts";
564 for (a=0; a<sce->scriptlink.totscript; a++) {
565 outliner_add_element(soops, &tenla->subtree, sce->scriptlink.scripts[a], tenla, 0, 0);
571 static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv,
572 TreeElement *parent, short type, short index)
575 TreeStoreElem *tselem;
579 if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
580 id= ((PointerRNA*)idv)->id.data;
581 if(!id) id= ((PointerRNA*)idv)->data;
584 if(id==NULL) return NULL;
586 te= MEM_callocN(sizeof(TreeElement), "tree elem");
587 /* add to the visual tree */
589 /* add to the storage */
590 check_persistant(soops, te, id, type, index);
591 tselem= TREESTORE(te);
594 te->index= index; // for data arays
595 if(ELEM3(type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP));
596 else if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM));
597 else if(type==TSE_ANIM_DATA);
599 te->name= id->name+2; // default, can be overridden by Library or non-ID data
600 te->idcode= GS(id->name);
605 /* tuck pointer back in object, to construct hierarchy */
606 if(GS(id->name)==ID_OB) id->newid= (ID *)te;
608 /* expand specific data always */
609 switch(GS(id->name)) {
611 te->name= ((Library *)id)->name;
614 outliner_add_scene_contents(soops, &te->subtree, (Scene *)id, te);
618 Object *ob= (Object *)id;
620 outliner_add_element(soops, &te->subtree, ob->adt, te, TSE_ANIM_DATA, 0);
622 if(ob->proxy && ob->id.lib==NULL)
623 outliner_add_element(soops, &te->subtree, ob->proxy, te, TSE_PROXY, 0);
625 outliner_add_element(soops, &te->subtree, ob->data, te, 0, 0);
628 bArmature *arm= ob->data;
631 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_POSE_BASE, 0);
635 if(arm->edbo==NULL && (ob->flag & OB_POSEMODE)) { // channels undefined in editmode, but we want the 'tenla' pose icon itself
636 int a= 0, const_index= 1000; /* ensure unique id for bone constraints */
638 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next, a++) {
639 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_POSE_CHANNEL, a);
640 ten->name= pchan->name;
641 ten->directdata= pchan;
642 pchan->prev= (bPoseChannel *)ten;
644 if(pchan->constraints.first) {
648 TreeElement *tenla1= outliner_add_element(soops, &ten->subtree, ob, ten, TSE_CONSTRAINT_BASE, 0);
651 tenla1->name= "Constraints";
652 for(con= pchan->constraints.first; con; con= con->next, const_index++) {
653 ten1= outliner_add_element(soops, &tenla1->subtree, ob, tenla1, TSE_CONSTRAINT, const_index);
654 #if 0 /* disabled as it needs to be reworked for recoded constraints system */
655 target= get_constraint_target(con, &str);
656 if(str && str[0]) ten1->name= str;
657 else if(target) ten1->name= target->id.name+2;
658 else ten1->name= con->name;
660 ten1->name= con->name;
661 ten1->directdata= con;
662 /* possible add all other types links? */
667 ten= tenla->subtree.first;
669 TreeElement *nten= ten->next, *par;
670 tselem= TREESTORE(ten);
671 if(tselem->type==TSE_POSE_CHANNEL) {
672 pchan= (bPoseChannel *)ten->directdata;
674 BLI_remlink(&tenla->subtree, ten);
675 par= (TreeElement *)pchan->parent->prev;
676 BLI_addtail(&par->subtree, ten);
682 /* restore prev pointers */
683 pchan= ob->pose->chanbase.first;
684 if(pchan) pchan->prev= NULL;
685 for(; pchan; pchan= pchan->next) {
686 if(pchan->next) pchan->next->prev= pchan;
691 if(ob->pose->agroups.first) {
694 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_POSEGRP_BASE, 0);
697 tenla->name= "Bone Groups";
698 for (agrp=ob->pose->agroups.first; agrp; agrp=agrp->next, a++) {
699 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_POSEGRP, a);
700 ten->name= agrp->name;
701 ten->directdata= agrp;
706 for(a=0; a<ob->totcol; a++)
707 outliner_add_element(soops, &te->subtree, ob->mat[a], te, 0, a);
709 if(ob->constraints.first) {
713 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_CONSTRAINT_BASE, 0);
717 tenla->name= "Constraints";
718 for(con= ob->constraints.first; con; con= con->next, a++) {
719 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_CONSTRAINT, a);
720 #if 0 /* disabled due to constraints system targets recode... code here needs review */
721 target= get_constraint_target(con, &str);
722 if(str && str[0]) ten->name= str;
723 else if(target) ten->name= target->id.name+2;
724 else ten->name= con->name;
726 ten->name= con->name;
727 ten->directdata= con;
728 /* possible add all other types links? */
732 if(ob->modifiers.first) {
734 TreeElement *temod = outliner_add_element(soops, &te->subtree, ob, te, TSE_MODIFIER_BASE, 0);
737 temod->name = "Modifiers";
738 for (index=0,md=ob->modifiers.first; md; index++,md=md->next) {
739 TreeElement *te = outliner_add_element(soops, &temod->subtree, ob, temod, TSE_MODIFIER, index);
743 if (md->type==eModifierType_Lattice) {
744 outliner_add_element(soops, &te->subtree, ((LatticeModifierData*) md)->object, te, TSE_LINKED_OB, 0);
745 } else if (md->type==eModifierType_Curve) {
746 outliner_add_element(soops, &te->subtree, ((CurveModifierData*) md)->object, te, TSE_LINKED_OB, 0);
747 } else if (md->type==eModifierType_Armature) {
748 outliner_add_element(soops, &te->subtree, ((ArmatureModifierData*) md)->object, te, TSE_LINKED_OB, 0);
749 } else if (md->type==eModifierType_Hook) {
750 outliner_add_element(soops, &te->subtree, ((HookModifierData*) md)->object, te, TSE_LINKED_OB, 0);
751 } else if (md->type==eModifierType_ParticleSystem) {
753 ParticleSystem *psys= ((ParticleSystemModifierData*) md)->psys;
755 ten = outliner_add_element(soops, &te->subtree, ob, te, TSE_LINKED_PSYS, 0);
756 ten->directdata = psys;
757 ten->name = psys->part->id.name+2;
761 if(ob->defbase.first) {
762 bDeformGroup *defgroup;
764 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_DEFGROUP_BASE, 0);
767 tenla->name= "Vertex Groups";
768 for (defgroup=ob->defbase.first; defgroup; defgroup=defgroup->next, a++) {
769 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_DEFGROUP, a);
770 ten->name= defgroup->name;
771 ten->directdata= defgroup;
774 if(ob->scriptlink.scripts) {
775 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_SCRIPT_BASE, 0);
778 tenla->name= "Scripts";
779 for (a=0; a<ob->scriptlink.totscript; a++) { /* ** */
780 outliner_add_element(soops, &tenla->subtree, ob->scriptlink.scripts[a], te, 0, 0);
785 outliner_add_element(soops, &te->subtree, ob->dup_group, te, 0, 0);
791 Mesh *me= (Mesh *)id;
793 //outliner_add_element(soops, &te->subtree, me->adt, te, TSE_ANIM_DATA, 0);
795 outliner_add_element(soops, &te->subtree, me->key, te, 0, 0);
796 for(a=0; a<me->totcol; a++)
797 outliner_add_element(soops, &te->subtree, me->mat[a], te, 0, a);
798 /* could do tfaces with image links, but the images are not grouped nicely.
799 would require going over all tfaces, sort images in use. etc... */
804 Curve *cu= (Curve *)id;
806 outliner_add_element(soops, &te->subtree, cu->adt, te, TSE_ANIM_DATA, 0);
808 for(a=0; a<cu->totcol; a++)
809 outliner_add_element(soops, &te->subtree, cu->mat[a], te, 0, a);
814 MetaBall *mb= (MetaBall *)id;
815 for(a=0; a<mb->totcol; a++)
816 outliner_add_element(soops, &te->subtree, mb->mat[a], te, 0, a);
821 Material *ma= (Material *)id;
823 outliner_add_element(soops, &te->subtree, ma->adt, te, TSE_ANIM_DATA, 0);
825 for(a=0; a<MAX_MTEX; a++) {
826 if(ma->mtex[a]) outliner_add_element(soops, &te->subtree, ma->mtex[a]->tex, te, 0, a);
834 outliner_add_element(soops, &te->subtree, tex->adt, te, TSE_ANIM_DATA, 0);
835 outliner_add_element(soops, &te->subtree, tex->ima, te, 0, 0);
840 Camera *ca= (Camera *)id;
841 outliner_add_element(soops, &te->subtree, ca->adt, te, TSE_ANIM_DATA, 0);
846 Lamp *la= (Lamp *)id;
848 outliner_add_element(soops, &te->subtree, la->adt, te, TSE_ANIM_DATA, 0);
850 for(a=0; a<MAX_MTEX; a++) {
851 if(la->mtex[a]) outliner_add_element(soops, &te->subtree, la->mtex[a]->tex, te, 0, a);
857 World *wrld= (World *)id;
859 outliner_add_element(soops, &te->subtree, wrld->adt, te, TSE_ANIM_DATA, 0);
861 for(a=0; a<MAX_MTEX; a++) {
862 if(wrld->mtex[a]) outliner_add_element(soops, &te->subtree, wrld->mtex[a]->tex, te, 0, a);
870 outliner_add_element(soops, &te->subtree, key->adt, te, TSE_ANIM_DATA, 0);
875 // XXX do we want to be exposing the F-Curves here?
876 //bAction *act= (bAction *)id;
881 bArmature *arm= (bArmature *)id;
888 for (ebone = arm->edbo->first; ebone; ebone=ebone->next, a++) {
889 ten= outliner_add_element(soops, &te->subtree, id, te, TSE_EBONE, a);
890 ten->directdata= ebone;
891 ten->name= ebone->name;
895 ten= te->subtree.first;
897 TreeElement *nten= ten->next, *par;
898 ebone= (EditBone *)ten->directdata;
900 BLI_remlink(&te->subtree, ten);
901 par= ebone->parent->temp;
902 BLI_addtail(&par->subtree, ten);
909 /* do not extend Armature when we have posemode */
910 tselem= TREESTORE(te->parent);
911 if( GS(tselem->id->name)==ID_OB && ((Object *)tselem->id)->flag & OB_POSEMODE);
914 for (curBone=arm->bonebase.first; curBone; curBone=curBone->next){
915 outliner_add_bone(soops, &te->subtree, id, curBone, te, &a);
923 else if(type==TSE_ANIM_DATA) {
924 AnimData *adt= (AnimData *)idv;
926 /* this element's info */
927 te->name= "Animation";
930 outliner_add_element(soops, &te->subtree, adt->action, te, 0, 0);
933 if (adt->drivers.first) {
934 TreeElement *ted= outliner_add_element(soops, &te->subtree, adt, te, TSE_DRIVER_BASE, 0);
938 ted->name= "Drivers";
940 for (fcu= adt->drivers.first; fcu; fcu= fcu->next) {
941 if (fcu->driver && fcu->driver->id) {
942 if (lastadded != fcu->driver->id) {
943 outliner_add_element(soops, &ted->subtree, fcu->driver->id, ted, TSE_LINKED_OB, 0);
944 lastadded= fcu->driver->id;
951 if (adt->nla_tracks.first) {
953 TreeElement *tenla= outliner_add_element(soops, &te->subtree, adt, te, TSE_NLA, 0);
957 tenla->name= "NLA Tracks";
959 for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) {
960 TreeElement *tenlt= outliner_add_element(soops, &te->subtree, nlt, te, TSE_NLA_TRACK, a);
965 for (strip=nlt->strips.first; strip; strip=strip->next, a++) {
966 ten= outliner_add_element(soops, &tenla->subtree, strip->act, tenla, TSE_NLA_ACTION, a);
967 if(ten) ten->directdata= strip;
973 else if(type==TSE_SEQUENCE) {
974 Sequence *seq= (Sequence*) idv;
978 * The idcode is a little hack, but the outliner
979 * only check te->idcode if te->type is equal to zero,
982 te->idcode= seq->type;
987 * This work like the sequence.
988 * If the sequence have a name (not default name)
989 * show it, in other case put the filename.
991 if(strcmp(seq->name, "SQ"))
994 if((seq->strip) && (seq->strip->stripdata))
995 te->name= seq->strip->stripdata->name;
996 else if((seq->strip) && (seq->strip->tstripdata) && (seq->strip->tstripdata->ibuf))
997 te->name= seq->strip->tstripdata->ibuf->name;
1002 if(seq->type==SEQ_META) {
1003 te->name= "Meta Strip";
1004 p= seq->seqbase.first;
1006 outliner_add_element(soops, &te->subtree, (void*)p, te, TSE_SEQUENCE, index);
1011 outliner_add_element(soops, &te->subtree, (void*)seq->strip, te, TSE_SEQ_STRIP, index);
1016 else if(type==TSE_SEQ_STRIP) {
1017 Strip *strip= (Strip *)idv;
1020 te->name= strip->dir;
1022 te->name= "Strip None";
1023 te->directdata= strip;
1025 else if(type==TSE_SEQUENCE_DUP) {
1026 Sequence *seq= (Sequence*)idv;
1028 te->idcode= seq->type;
1029 te->directdata= seq;
1030 te->name= seq->strip->stripdata->name;
1032 else if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
1033 PointerRNA pptr, propptr, *ptr= (PointerRNA*)idv;
1034 PropertyRNA *prop, *iterprop, *nameprop;
1035 PropertyType proptype;
1036 PropertySubType propsubtype;
1039 /* we do lazy build, for speed and to avoid infinite recusion */
1041 if(ptr->data == NULL) {
1042 te->name= "(empty)";
1044 else if(type == TSE_RNA_STRUCT) {
1046 nameprop= RNA_struct_name_property(ptr);
1049 te->name= RNA_property_string_get_alloc(ptr, nameprop, NULL, 0);
1050 te->flag |= TE_FREE_NAME;
1053 te->name= (char*)RNA_struct_ui_name(ptr);
1055 iterprop= RNA_struct_iterator_property(ptr);
1056 tot= RNA_property_collection_length(ptr, iterprop);
1058 /* auto open these cases */
1059 if(!parent || (RNA_property_type(&parent->rnaptr, parent->directdata)) == PROP_POINTER)
1061 tselem->flag &= ~TSE_CLOSED;
1063 if(!(tselem->flag & TSE_CLOSED)) {
1064 for(a=0; a<tot; a++)
1065 outliner_add_element(soops, &te->subtree, (void*)ptr, te, TSE_RNA_PROPERTY, a);
1068 te->flag |= TE_LAZY_CLOSED;
1072 else if(type == TSE_RNA_PROPERTY) {
1074 iterprop= RNA_struct_iterator_property(ptr);
1075 RNA_property_collection_lookup_int(ptr, iterprop, index, &propptr);
1078 proptype= RNA_property_type(ptr, prop);
1080 te->name= (char*)RNA_property_ui_name(ptr, prop);
1081 te->directdata= prop;
1084 if(proptype == PROP_POINTER) {
1085 pptr= RNA_property_pointer_get(ptr, prop);
1088 if(!(tselem->flag & TSE_CLOSED))
1089 outliner_add_element(soops, &te->subtree, (void*)&pptr, te, TSE_RNA_STRUCT, -1);
1091 te->flag |= TE_LAZY_CLOSED;
1094 else if(proptype == PROP_COLLECTION) {
1095 tot= RNA_property_collection_length(ptr, prop);
1097 if(!(tselem->flag & TSE_CLOSED)) {
1098 for(a=0; a<tot; a++) {
1099 RNA_property_collection_lookup_int(ptr, prop, a, &pptr);
1100 outliner_add_element(soops, &te->subtree, (void*)&pptr, te, TSE_RNA_STRUCT, -1);
1104 te->flag |= TE_LAZY_CLOSED;
1106 else if(ELEM3(proptype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
1107 tot= RNA_property_array_length(ptr, prop);
1109 if(!(tselem->flag & TSE_CLOSED)) {
1110 for(a=0; a<tot; a++)
1111 outliner_add_element(soops, &te->subtree, (void*)ptr, te, TSE_RNA_ARRAY_ELEM, a);
1114 te->flag |= TE_LAZY_CLOSED;
1117 else if(type == TSE_RNA_ARRAY_ELEM) {
1118 /* array property element */
1119 static char *vectoritem[4]= {" x", " y", " z", " w"};
1120 static char *quatitem[4]= {" w", " x", " y", " z"};
1121 static char *coloritem[4]= {" r", " g", " b", " a"};
1123 prop= parent->directdata;
1124 proptype= RNA_property_type(ptr, prop);
1125 propsubtype= RNA_property_subtype(ptr, prop);
1126 tot= RNA_property_array_length(ptr, prop);
1128 te->directdata= prop;
1132 if(tot == 4 && propsubtype == PROP_ROTATION)
1133 te->name= quatitem[index];
1134 else if(tot <= 4 && (propsubtype == PROP_VECTOR || propsubtype == PROP_ROTATION))
1135 te->name= vectoritem[index];
1136 else if(tot <= 4 && propsubtype == PROP_COLOR)
1137 te->name= coloritem[index];
1139 te->name= MEM_callocN(sizeof(char)*20, "OutlinerRNAArrayName");
1140 sprintf(te->name, " %d", index+1);
1141 te->flag |= TE_FREE_NAME;
1149 static void outliner_make_hierarchy(SpaceOops *soops, ListBase *lb)
1151 TreeElement *te, *ten, *tep;
1152 TreeStoreElem *tselem;
1154 /* build hierarchy */
1155 // XXX also, set extents here...
1159 tselem= TREESTORE(te);
1161 if(tselem->type==0 && te->idcode==ID_OB) {
1162 Object *ob= (Object *)tselem->id;
1163 if(ob->parent && ob->parent->id.newid) {
1164 BLI_remlink(lb, te);
1165 tep= (TreeElement *)ob->parent->id.newid;
1166 BLI_addtail(&tep->subtree, te);
1167 // set correct parent pointers
1168 for(te=tep->subtree.first; te; te= te->next) te->parent= tep;
1175 /* Helped function to put duplicate sequence in the same tree. */
1176 int need_add_seq_dup(Sequence *seq)
1180 if((!seq->strip) || (!seq->strip->stripdata) || (!seq->strip->stripdata->name))
1184 * First check backward, if we found a duplicate
1185 * sequence before this, don't need it, just return.
1189 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1194 if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1201 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1206 if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1213 void add_seq_dup(SpaceOops *soops, Sequence *seq, TreeElement *te, short index)
1220 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1225 if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1226 ch= outliner_add_element(soops, &te->subtree, (void*)p, te, TSE_SEQUENCE, index);
1231 static void outliner_build_tree(Main *mainvar, Scene *scene, SpaceOops *soops)
1235 TreeElement *te=NULL, *ten;
1236 TreeStoreElem *tselem;
1237 int show_opened= (soops->treestore==NULL); /* on first view, we open scenes */
1239 if(soops->tree.first && (soops->storeflag & SO_TREESTORE_REDRAW))
1242 outliner_free_tree(&soops->tree);
1243 outliner_storage_cleanup(soops);
1245 /* clear ob id.new flags */
1246 for(ob= mainvar->object.first; ob; ob= ob->id.next) ob->id.newid= NULL;
1249 if(soops->outlinevis == SO_LIBRARIES) {
1252 for(lib= mainvar->library.first; lib; lib= lib->id.next) {
1253 ten= outliner_add_element(soops, &soops->tree, lib, NULL, 0, 0);
1254 lib->id.newid= (ID *)ten;
1256 /* make hierarchy */
1257 ten= soops->tree.first;
1259 TreeElement *nten= ten->next, *par;
1260 tselem= TREESTORE(ten);
1261 lib= (Library *)tselem->id;
1263 BLI_remlink(&soops->tree, ten);
1264 par= (TreeElement *)lib->parent->id.newid;
1265 BLI_addtail(&par->subtree, ten);
1270 /* restore newid pointers */
1271 for(lib= mainvar->library.first; lib; lib= lib->id.next)
1272 lib->id.newid= NULL;
1275 else if(soops->outlinevis == SO_ALL_SCENES) {
1277 for(sce= mainvar->scene.first; sce; sce= sce->id.next) {
1278 te= outliner_add_element(soops, &soops->tree, sce, NULL, 0, 0);
1279 tselem= TREESTORE(te);
1280 if(sce==scene && show_opened)
1281 tselem->flag &= ~TSE_CLOSED;
1283 for(base= sce->base.first; base; base= base->next) {
1284 ten= outliner_add_element(soops, &te->subtree, base->object, te, 0, 0);
1285 ten->directdata= base;
1287 outliner_make_hierarchy(soops, &te->subtree);
1288 /* clear id.newid, to prevent objects be inserted in wrong scenes (parent in other scene) */
1289 for(base= sce->base.first; base; base= base->next) base->object->id.newid= NULL;
1292 else if(soops->outlinevis == SO_CUR_SCENE) {
1294 outliner_add_scene_contents(soops, &soops->tree, scene, NULL);
1296 for(base= scene->base.first; base; base= base->next) {
1297 ten= outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1298 ten->directdata= base;
1300 outliner_make_hierarchy(soops, &soops->tree);
1302 else if(soops->outlinevis == SO_VISIBLE) {
1303 for(base= scene->base.first; base; base= base->next) {
1304 if(base->lay & scene->lay)
1305 outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1307 outliner_make_hierarchy(soops, &soops->tree);
1309 else if(soops->outlinevis == SO_GROUPS) {
1313 for(group= mainvar->group.first; group; group= group->id.next) {
1315 te= outliner_add_element(soops, &soops->tree, group, NULL, 0, 0);
1316 tselem= TREESTORE(te);
1318 for(go= group->gobject.first; go; go= go->next) {
1319 ten= outliner_add_element(soops, &te->subtree, go->ob, te, 0, 0);
1320 ten->directdata= NULL; /* eh, why? */
1322 outliner_make_hierarchy(soops, &te->subtree);
1323 /* clear id.newid, to prevent objects be inserted in wrong scenes (parent in other scene) */
1324 for(go= group->gobject.first; go; go= go->next) go->ob->id.newid= NULL;
1328 else if(soops->outlinevis == SO_SAME_TYPE) {
1331 for(base= scene->base.first; base; base= base->next) {
1332 if(base->object->type==ob->type) {
1333 ten= outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1334 ten->directdata= base;
1337 outliner_make_hierarchy(soops, &soops->tree);
1340 else if(soops->outlinevis == SO_SELECTED) {
1341 for(base= scene->base.first; base; base= base->next) {
1342 if(base->lay & scene->lay) {
1343 if(base==BASACT || (base->flag & SELECT)) {
1344 ten= outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1345 ten->directdata= base;
1349 outliner_make_hierarchy(soops, &soops->tree);
1351 else if(soops->outlinevis==SO_SEQUENCE) {
1353 Editing *ed= seq_give_editing(scene, FALSE);
1359 seq= ed->seqbasep->first;
1364 op= need_add_seq_dup(seq);
1366 ten= outliner_add_element(soops, &soops->tree, (void*)seq, NULL, TSE_SEQUENCE, 0);
1368 ten= outliner_add_element(soops, &soops->tree, (void*)seq, NULL, TSE_SEQUENCE_DUP, 0);
1369 add_seq_dup(soops, seq, ten, 0);
1374 else if(soops->outlinevis==SO_DATABLOCKS) {
1377 RNA_main_pointer_create(mainvar, &mainptr);
1379 ten= outliner_add_element(soops, &soops->tree, (void*)&mainptr, NULL, TSE_RNA_STRUCT, -1);
1382 tselem= TREESTORE(ten);
1383 tselem->flag &= ~TSE_CLOSED;
1386 else if(soops->outlinevis==SO_USERDEF) {
1387 PointerRNA userdefptr;
1389 RNA_pointer_create(NULL, &RNA_UserPreferences, &U, &userdefptr);
1391 ten= outliner_add_element(soops, &soops->tree, (void*)&userdefptr, NULL, TSE_RNA_STRUCT, -1);
1394 tselem= TREESTORE(ten);
1395 tselem->flag &= ~TSE_CLOSED;
1399 ten= outliner_add_element(soops, &soops->tree, OBACT, NULL, 0, 0);
1400 if(ten) ten->directdata= BASACT;
1403 outliner_sort(soops, &soops->tree);
1406 /* **************** INTERACTIVE ************* */
1408 static int outliner_count_levels(SpaceOops *soops, ListBase *lb, int curlevel)
1411 int level=curlevel, lev;
1413 for(te= lb->first; te; te= te->next) {
1415 lev= outliner_count_levels(soops, &te->subtree, curlevel+1);
1416 if(lev>level) level= lev;
1421 static int outliner_has_one_flag(SpaceOops *soops, ListBase *lb, short flag, short curlevel)
1424 TreeStoreElem *tselem;
1427 for(te= lb->first; te; te= te->next) {
1428 tselem= TREESTORE(te);
1429 if(tselem->flag & flag) return curlevel;
1431 level= outliner_has_one_flag(soops, &te->subtree, flag, curlevel+1);
1432 if(level) return level;
1437 static void outliner_set_flag(SpaceOops *soops, ListBase *lb, short flag, short set)
1440 TreeStoreElem *tselem;
1442 for(te= lb->first; te; te= te->next) {
1443 tselem= TREESTORE(te);
1444 if(set==0) tselem->flag &= ~flag;
1445 else tselem->flag |= flag;
1446 outliner_set_flag(soops, &te->subtree, flag, set);
1450 void object_toggle_visibility_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1452 Scene *scene= NULL; // XXX
1453 Base *base= (Base *)te->directdata;
1455 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1457 base->object->restrictflag^=OB_RESTRICT_VIEW;
1461 void outliner_toggle_visibility(Scene *scene, SpaceOops *soops)
1464 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_visibility_cb);
1466 BIF_undo_push("Outliner toggle selectability");
1468 allqueue(REDRAWVIEW3D, 1);
1469 allqueue(REDRAWOOPS, 0);
1470 allqueue(REDRAWINFO, 1);
1473 static void object_toggle_selectability_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1475 Scene *scene= NULL; // XXX
1476 Base *base= (Base *)te->directdata;
1478 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1480 base->object->restrictflag^=OB_RESTRICT_SELECT;
1484 void outliner_toggle_selectability(Scene *scene, SpaceOops *soops)
1487 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_selectability_cb);
1489 BIF_undo_push("Outliner toggle selectability");
1491 allqueue(REDRAWVIEW3D, 1);
1492 allqueue(REDRAWOOPS, 0);
1493 allqueue(REDRAWINFO, 1);
1496 void object_toggle_renderability_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1498 Scene *scene= NULL; // XXX
1499 Base *base= (Base *)te->directdata;
1501 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1503 base->object->restrictflag^=OB_RESTRICT_RENDER;
1507 void outliner_toggle_renderability(Scene *scene, SpaceOops *soops)
1510 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_renderability_cb);
1512 BIF_undo_push("Outliner toggle renderability");
1514 allqueue(REDRAWVIEW3D, 1);
1515 allqueue(REDRAWOOPS, 0);
1516 allqueue(REDRAWINFO, 1);
1519 void outliner_toggle_visible(SpaceOops *soops)
1522 if( outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1))
1523 outliner_set_flag(soops, &soops->tree, TSE_CLOSED, 0);
1525 outliner_set_flag(soops, &soops->tree, TSE_CLOSED, 1);
1527 BIF_undo_push("Outliner toggle visible");
1530 void outliner_toggle_selected(ARegion *ar, SpaceOops *soops)
1533 if( outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1))
1534 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
1536 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 1);
1538 BIF_undo_push("Outliner toggle selected");
1539 soops->storeflag |= SO_TREESTORE_REDRAW;
1543 static void outliner_openclose_level(SpaceOops *soops, ListBase *lb, int curlevel, int level, int open)
1546 TreeStoreElem *tselem;
1548 for(te= lb->first; te; te= te->next) {
1549 tselem= TREESTORE(te);
1552 if(curlevel<=level) tselem->flag &= ~TSE_CLOSED;
1555 if(curlevel>=level) tselem->flag |= TSE_CLOSED;
1558 outliner_openclose_level(soops, &te->subtree, curlevel+1, level, open);
1562 /* return 1 when levels were opened */
1563 static int outliner_open_back(SpaceOops *soops, TreeElement *te)
1565 TreeStoreElem *tselem;
1568 for (te= te->parent; te; te= te->parent) {
1569 tselem= TREESTORE(te);
1570 if (tselem->flag & TSE_CLOSED) {
1571 tselem->flag &= ~TSE_CLOSED;
1578 /* This is not used anywhere at the moment */
1580 static void outliner_open_reveal(SpaceOops *soops, ListBase *lb, TreeElement *teFind, int *found)
1583 TreeStoreElem *tselem;
1585 for (te= lb->first; te; te= te->next) {
1586 /* check if this tree-element was the one we're seeking */
1592 /* try to see if sub-tree contains it then */
1593 outliner_open_reveal(soops, &te->subtree, teFind, found);
1595 tselem= TREESTORE(te);
1596 if (tselem->flag & TSE_CLOSED)
1597 tselem->flag &= ~TSE_CLOSED;
1604 void outliner_one_level(SpaceOops *soops, int add)
1608 level= outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1);
1610 if(level) outliner_openclose_level(soops, &soops->tree, 1, level, 1);
1613 if(level==0) level= outliner_count_levels(soops, &soops->tree, 0);
1614 if(level) outliner_openclose_level(soops, &soops->tree, 1, level-1, 0);
1617 BIF_undo_push("Outliner show/hide one level");
1620 void outliner_page_up_down(Scene *scene, ARegion *ar, SpaceOops *soops, int up)
1622 int dy= ar->v2d.mask.ymax-ar->v2d.mask.ymin;
1624 if(up == -1) dy= -dy;
1625 ar->v2d.cur.ymin+= dy;
1626 ar->v2d.cur.ymax+= dy;
1628 soops->storeflag |= SO_TREESTORE_REDRAW;
1631 /* **** do clicks on items ******* */
1633 static int tree_element_active_renderlayer(TreeElement *te, TreeStoreElem *tselem, int set)
1637 /* paranoia check */
1638 if(te->idcode!=ID_SCE)
1640 sce= (Scene *)tselem->id;
1643 sce->r.actlay= tselem->nr;
1644 allqueue(REDRAWBUTSSCENE, 0);
1647 return sce->r.actlay==tselem->nr;
1652 static void tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te)
1654 TreeStoreElem *tselem= TREESTORE(te);
1658 int shift= 0; // XXX
1660 /* if id is not object, we search back */
1661 if(te->idcode==ID_OB) ob= (Object *)tselem->id;
1663 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1664 if(ob==OBACT) return;
1666 if(ob==NULL) return;
1668 sce= (Scene *)outliner_search_back(soops, te, ID_SCE);
1669 if(sce && scene != sce) {
1670 ED_screen_set_scene(C, sce);
1673 /* find associated base in current scene */
1674 for(base= FIRSTBASE; base; base= base->next)
1675 if(base->object==ob) break;
1679 if(base->flag & SELECT)
1680 ED_base_object_select(base, BA_DESELECT);
1682 ED_base_object_select(base, BA_SELECT);
1686 /* deleselect all */
1687 for(b= FIRSTBASE; b; b= b->next) {
1689 b->object->flag= b->flag;
1691 ED_base_object_select(base, BA_SELECT);
1694 ED_base_object_activate(C, base); /* adds notifier */
1697 // XXX if(ob!=obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
1698 // else countall(); /* exit_editmode calls f() */
1701 static int tree_element_active_material(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1706 /* we search for the object parent */
1707 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1708 if(ob==NULL || ob!=OBACT) return 0; // just paranoia
1710 /* searching in ob mat array? */
1712 if(tes->idcode==ID_OB) {
1714 ob->actcol= te->index+1;
1715 ob->colbits |= (1<<te->index); // make ob material active too
1718 if(ob->actcol == te->index+1)
1719 if(ob->colbits & (1<<te->index)) return 1;
1722 /* or we search for obdata material */
1725 ob->actcol= te->index+1;
1726 ob->colbits &= ~(1<<te->index); // make obdata material active too
1729 if(ob->actcol == te->index+1)
1730 if( (ob->colbits & (1<<te->index))==0 ) return 1;
1734 // XXX extern_set_butspace(F5KEY, 0); // force shading buttons
1735 BIF_preview_changed(ID_MA);
1736 allqueue(REDRAWBUTSSHADING, 1);
1737 allqueue(REDRAWNODE, 0);
1738 allqueue(REDRAWOOPS, 0);
1739 allqueue(REDRAWIPO, 0);
1744 static int tree_element_active_texture(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1747 TreeStoreElem *tselem, *tselemp;
1749 SpaceButs *sbuts=NULL;
1751 if(ob==NULL) return 0; // no active object
1753 tselem= TREESTORE(te);
1755 /* find buttons area (note, this is undefined really still, needs recode in blender) */
1756 /* XXX removed finding sbuts */
1758 /* where is texture linked to? */
1760 tselemp= TREESTORE(tep);
1762 if(tep->idcode==ID_WO) {
1763 World *wrld= (World *)tselemp->id;
1767 sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1770 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1771 wrld->texact= te->index;
1773 else if(tselemp->id == (ID *)(scene->world)) {
1774 if(wrld->texact==te->index) return 1;
1777 else if(tep->idcode==ID_LA) {
1778 Lamp *la= (Lamp *)tselemp->id;
1781 sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1784 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1785 la->texact= te->index;
1788 if(tselemp->id == ob->data) {
1789 if(la->texact==te->index) return 1;
1793 else if(tep->idcode==ID_MA) {
1794 Material *ma= (Material *)tselemp->id;
1797 //sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1800 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1801 ma->texact= (char)te->index;
1803 /* also set active material */
1804 ob->actcol= tep->index+1;
1806 else if(tep->flag & TE_ACTIVE) { // this is active material
1807 if(ma->texact==te->index) return 1;
1815 static int tree_element_active_lamp(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1819 /* we search for the object parent */
1820 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1821 if(ob==NULL || ob!=OBACT) return 0; // just paranoia
1824 // XXX extern_set_butspace(F5KEY, 0);
1825 BIF_preview_changed(ID_LA);
1826 allqueue(REDRAWBUTSSHADING, 1);
1827 allqueue(REDRAWOOPS, 0);
1828 allqueue(REDRAWIPO, 0);
1835 static int tree_element_active_world(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1838 TreeStoreElem *tselem=NULL;
1843 tselem= TREESTORE(tep);
1844 sce= (Scene *)tselem->id;
1847 if(set) { // make new scene active
1848 if(sce && scene != sce) {
1849 // XXX ED_screen_set_scene(C, sce);
1853 if(tep==NULL || tselem->id == (ID *)scene) {
1855 // XXX extern_set_butspace(F8KEY, 0);
1864 static int tree_element_active_defgroup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1868 /* id in tselem is object */
1869 ob= (Object *)tselem->id;
1871 ob->actdef= te->index+1;
1872 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
1873 allqueue(REDRAWVIEW3D, ob->ipowin);
1877 if(ob->actdef== te->index+1) return 1;
1882 static int tree_element_active_posegroup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1884 Object *ob= (Object *)tselem->id;
1888 ob->pose->active_group= te->index+1;
1889 allqueue(REDRAWBUTSEDIT, 0);
1893 if(ob==OBACT && ob->pose) {
1894 if (ob->pose->active_group== te->index+1) return 1;
1900 static int tree_element_active_posechannel(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1902 Object *ob= (Object *)tselem->id;
1903 bPoseChannel *pchan= te->directdata;
1906 if(!(pchan->bone->flag & BONE_HIDDEN_P)) {
1908 // XXX if(G.qual & LR_SHIFTKEY) deselectall_posearmature(ob, 2, 0); // 2 = clear active tag
1909 // else deselectall_posearmature(ob, 0, 0); // 0 = deselect
1910 pchan->bone->flag |= BONE_SELECTED|BONE_ACTIVE;
1912 allqueue(REDRAWVIEW3D, 0);
1913 allqueue(REDRAWOOPS, 0);
1914 allqueue(REDRAWACTION, 0);
1918 if(ob==OBACT && ob->pose) {
1919 if (pchan->bone->flag & BONE_SELECTED) return 1;
1925 static int tree_element_active_bone(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1927 bArmature *arm= (bArmature *)tselem->id;
1928 Bone *bone= te->directdata;
1931 if(!(bone->flag & BONE_HIDDEN_P)) {
1932 // XXX if(G.qual & LR_SHIFTKEY) deselectall_posearmature(OBACT, 2, 0); // 2 is clear active tag
1933 // else deselectall_posearmature(OBACT, 0, 0);
1934 bone->flag |= BONE_SELECTED|BONE_ACTIVE;
1936 allqueue(REDRAWVIEW3D, 0);
1937 allqueue(REDRAWOOPS, 0);
1938 allqueue(REDRAWACTION, 0);
1944 if(ob && ob->data==arm) {
1945 if (bone->flag & BONE_SELECTED) return 1;
1952 /* ebones only draw in editmode armature */
1953 static int tree_element_active_ebone(TreeElement *te, TreeStoreElem *tselem, int set)
1955 EditBone *ebone= te->directdata;
1956 // int shift= 0; // XXX
1959 if(!(ebone->flag & BONE_HIDDEN_A)) {
1961 // XXX if(shift) deselectall_armature(2, 0); // only clear active tag
1962 // else deselectall_armature(0, 0); // deselect
1964 ebone->flag |= BONE_SELECTED|BONE_ROOTSEL|BONE_TIPSEL|BONE_ACTIVE;
1966 if(ebone->parent && (ebone->flag & BONE_CONNECTED)) ebone->parent->flag |= BONE_TIPSEL;
1968 allqueue(REDRAWVIEW3D, 0);
1969 allqueue(REDRAWOOPS, 0);
1970 allqueue(REDRAWACTION, 0);
1974 if (ebone->flag & BONE_SELECTED) return 1;
1979 static int tree_element_active_modifier(TreeElement *te, TreeStoreElem *tselem, int set)
1982 // XXX extern_set_butspace(F9KEY, 0);
1988 static int tree_element_active_psys(TreeElement *te, TreeStoreElem *tselem, int set)
1991 // Object *ob= (Object *)tselem->id;
1992 // ParticleSystem *psys= te->directdata;
1994 // XXX PE_change_act_psys(ob, psys);
1995 // XXX extern_set_butspace(F7KEY, 0);
2001 static int tree_element_active_constraint(TreeElement *te, TreeStoreElem *tselem, int set)
2004 // XXX extern_set_butspace(F7KEY, 0);
2010 static int tree_element_active_text(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
2016 /* generic call for ID data check or make/check active in UI */
2017 static int tree_element_active(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
2020 switch(te->idcode) {
2022 return tree_element_active_material(scene, soops, te, set);
2024 return tree_element_active_world(scene, soops, te, set);
2026 return tree_element_active_lamp(scene, soops, te, set);
2028 return tree_element_active_texture(scene, soops, te, set);
2030 return tree_element_active_text(scene, soops, te, set);
2035 static int tree_element_active_pose(TreeElement *te, TreeStoreElem *tselem, int set)
2037 Object *ob= (Object *)tselem->id;
2040 // XXX if(obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2041 // if(ob->flag & OB_POSEMODE) exit_posemode();
2042 // else enter_posemode();
2045 if(ob->flag & OB_POSEMODE) return 1;
2050 static int tree_element_active_sequence(TreeElement *te, TreeStoreElem *tselem, int set)
2052 Sequence *seq= (Sequence*) te->directdata;
2055 // XXX select_single_seq(seq, 1);
2056 allqueue(REDRAWSEQ, 0);
2059 if(seq->flag & SELECT)
2065 static int tree_element_active_sequence_dup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
2068 Editing *ed= seq_give_editing(scene, FALSE);
2070 seq= (Sequence*)te->directdata;
2072 if(seq->flag & SELECT)
2077 // XXX select_single_seq(seq, 1);
2078 p= ed->seqbasep->first;
2080 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
2085 // if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
2086 // XXX select_single_seq(p, 0);
2089 allqueue(REDRAWSEQ, 0);
2093 /* generic call for non-id data to make/check active in UI */
2094 /* Context can be NULL when set==0 */
2095 static int tree_element_type_active(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, int set)
2098 switch(tselem->type) {
2100 return tree_element_active_defgroup(scene, te, tselem, set);
2102 return tree_element_active_bone(scene, te, tselem, set);
2104 return tree_element_active_ebone(te, tselem, set);
2106 return tree_element_active_modifier(te, tselem, set);
2108 if(set) tree_element_set_active_object(C, scene, soops, te);
2109 else if(tselem->id==(ID *)OBACT) return 1;
2111 case TSE_LINKED_PSYS:
2112 return tree_element_active_psys(te, tselem, set);
2115 return tree_element_active_pose(te, tselem, set);
2117 case TSE_POSE_CHANNEL:
2118 return tree_element_active_posechannel(scene, te, tselem, set);
2119 case TSE_CONSTRAINT:
2120 return tree_element_active_constraint(te, tselem, set);
2122 return tree_element_active_renderlayer(te, tselem, set);
2124 return tree_element_active_posegroup(scene, te, tselem, set);
2126 return tree_element_active_sequence(te, tselem, set);
2128 case TSE_SEQUENCE_DUP:
2129 return tree_element_active_sequence_dup(scene, te, tselem, set);
2135 static int do_outliner_mouse_event(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, short event, float *mval)
2137 int shift= 0, ctrl= 0; // XXX
2139 if(mval[1]>te->ys && mval[1]<te->ys+OL_H) {
2140 TreeStoreElem *tselem= TREESTORE(te);
2143 /* open close icon, three things to check */
2144 if(event==RETKEY || event==PADENTER) openclose= 1; // enter opens/closes always
2145 else if((te->flag & TE_ICONROW)==0) { // hidden icon, no open/close
2146 if( mval[0]>te->xs && mval[0]<te->xs+OL_X) openclose= 1;
2151 /* all below close/open? */
2153 tselem->flag &= ~TSE_CLOSED;
2154 outliner_set_flag(soops, &te->subtree, TSE_CLOSED, !outliner_has_one_flag(soops, &te->subtree, TSE_CLOSED, 1));
2157 if(tselem->flag & TSE_CLOSED) tselem->flag &= ~TSE_CLOSED;
2158 else tselem->flag |= TSE_CLOSED;
2164 /* name and first icon */
2165 else if(mval[0]>te->xs && mval[0]<te->xend) {
2167 /* activate a name button? */
2168 if(event==LEFTMOUSE) {
2171 if(ELEM10(tselem->type, TSE_ANIM_DATA, TSE_NLA, TSE_DEFGROUP_BASE, TSE_CONSTRAINT_BASE, TSE_MODIFIER_BASE, TSE_SCRIPT_BASE, TSE_POSE_BASE, TSE_POSEGRP_BASE, TSE_R_LAYER_BASE, TSE_R_PASS))
2172 error("Cannot edit builtin name");
2173 else if(ELEM3(tselem->type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP))
2174 error("Cannot edit sequence name");
2175 else if(tselem->id->lib) {
2176 // XXX error_libdata();
2177 } else if(te->idcode == ID_LI && te->parent) {
2178 error("Cannot edit the path of an indirectly linked library");
2180 tselem->flag |= TSE_TEXTBUT;
2183 /* always makes active object */
2184 if(tselem->type!=TSE_SEQUENCE && tselem->type!=TSE_SEQ_STRIP && tselem->type!=TSE_SEQUENCE_DUP)
2185 tree_element_set_active_object(C, scene, soops, te);
2187 if(tselem->type==0) { // the lib blocks
2189 if(te->idcode==ID_SCE) {
2190 if(scene!=(Scene *)tselem->id) {
2191 ED_screen_set_scene(C, (Scene *)tselem->id);
2194 else if(ELEM5(te->idcode, ID_ME, ID_CU, ID_MB, ID_LT, ID_AR)) {
2195 // XXX if(obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2197 // enter_editmode(EM_WAITCURSOR);
2198 // extern_set_butspace(F9KEY, 0);
2200 } else { // rest of types
2201 tree_element_active(scene, soops, te, 1);
2205 else tree_element_type_active(C, scene, soops, te, tselem, 1);
2208 else if(event==RIGHTMOUSE) {
2209 /* select object that's clicked on and popup context menu */
2210 if (!(tselem->flag & TSE_SELECTED)) {
2212 if ( outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1) )
2213 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
2215 tselem->flag |= TSE_SELECTED;
2216 /* redraw, same as outliner_select function */
2217 soops->storeflag |= SO_TREESTORE_REDRAW;
2218 // XXX screen_swapbuffers();
2221 outliner_operation_menu(scene, ar, soops);
2227 for(te= te->subtree.first; te; te= te->next) {
2228 if(do_outliner_mouse_event(C, scene, ar, soops, te, event, mval)) return 1;
2233 /* event can enterkey, then it opens/closes */
2234 static int outliner_activate_click(bContext *C, wmOperator *op, wmEvent *event)
2236 Scene *scene= CTX_data_scene(C);
2237 ARegion *ar= CTX_wm_region(C);
2238 SpaceOops *soops= (SpaceOops*)CTX_wm_space_data(C);
2242 UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, fmval, fmval+1);
2244 for(te= soops->tree.first; te; te= te->next) {
2245 if(do_outliner_mouse_event(C, scene, ar, soops, te, event->type, fmval)) break;
2249 BIF_undo_push("Outliner click event");
2252 short selecting= -1;
2255 /* get row number - 100 here is just a dummy value since we don't need the column */
2256 UI_view2d_listview_view_to_cell(&ar->v2d, 1000, OL_H, 0.0f, 0.0f,
2257 fmval[0], fmval[1], NULL, &row);
2259 /* select relevant row */
2260 outliner_select(soops, &soops->tree, &row, &selecting);
2262 // XXX old flag found in old code, do we still use this?
2263 //soops->storeflag |= SO_TREESTORE_REDRAW;
2265 BIF_undo_push("Outliner selection event");
2268 ED_region_tag_redraw(ar);
2270 return OPERATOR_FINISHED;
2273 void OUTLINER_OT_activate_click(wmOperatorType *ot)
2275 ot->name= "Activate Click";
2276 ot->idname= "OUTLINER_OT_activate_click";
2278 ot->invoke= outliner_activate_click;
2280 ot->poll= ED_operator_outliner_active;
2285 /* recursive helper for function below */
2286 static void outliner_set_coordinates_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
2288 TreeStoreElem *tselem= TREESTORE(te);
2290 /* store coord and continue, we need coordinates for elements outside view too */
2291 te->xs= (float)startx;
2292 te->ys= (float)(*starty);
2295 if((tselem->flag & TSE_CLOSED)==0) {
2297 for(ten= te->subtree.first; ten; ten= ten->next) {
2298 outliner_set_coordinates_element(soops, ten, startx+OL_X, starty);
2304 /* to retrieve coordinates with redrawing the entire tree */
2305 static void outliner_set_coordinates(ARegion *ar, SpaceOops *soops)
2308 int starty= (int)(ar->v2d.tot.ymax)-OL_H;
2311 for(te= soops->tree.first; te; te= te->next) {
2312 outliner_set_coordinates_element(soops, te, startx, &starty);
2316 static TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, ID *id)
2318 TreeElement *te, *tes;
2319 TreeStoreElem *tselem;
2321 for(te= lb->first; te; te= te->next) {
2322 tselem= TREESTORE(te);
2323 if(tselem->type==0) {
2324 if(tselem->id==id) return te;
2325 /* only deeper on scene or object */
2326 if( te->idcode==ID_OB || te->idcode==ID_SCE) {
2327 tes= outliner_find_id(soops, &te->subtree, id);
2335 void outliner_show_active(Scene *scene, ARegion *ar, SpaceOops *so)
2340 if(OBACT == NULL) return;
2342 te= outliner_find_id(so, &so->tree, (ID *)OBACT);
2344 /* make te->ys center of view */
2345 ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
2347 ar->v2d.cur.ymax= (float)ytop;
2348 ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
2350 /* make te->xs ==> te->xend center of view */
2351 xdelta = (int)(te->xs - ar->v2d.cur.xmin);
2352 ar->v2d.cur.xmin += xdelta;
2353 ar->v2d.cur.xmax += xdelta;
2355 so->storeflag |= SO_TREESTORE_REDRAW;
2359 void outliner_show_selected(Scene *scene, ARegion *ar, SpaceOops *so)
2364 te= outliner_find_id(so, &so->tree, (ID *)OBACT);
2366 /* make te->ys center of view */
2367 ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
2369 ar->v2d.cur.ymax= (float)ytop;
2370 ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
2372 /* make te->xs ==> te->xend center of view */
2373 xdelta = (int)(te->xs - ar->v2d.cur.xmin);
2374 ar->v2d.cur.xmin += xdelta;
2375 ar->v2d.cur.xmax += xdelta;
2377 so->storeflag |= SO_TREESTORE_REDRAW;
2382 /* find next element that has this name */
2383 static TreeElement *outliner_find_named(SpaceOops *soops, ListBase *lb, char *name, int flags, TreeElement *prev, int *prevFound)
2385 TreeElement *te, *tes;
2387 for (te= lb->first; te; te= te->next) {
2390 /* determine if match */
2392 found= BLI_strcasestr(te->name, name)!=NULL;
2393 else if(flags==OL_FIND_CASE)
2394 found= strstr(te->name, name)!=NULL;
2395 else if(flags==OL_FIND_COMPLETE)
2396 found= BLI_strcasecmp(te->name, name)==0;
2398 found= strcmp(te->name, name)==0;
2401 /* name is right, but is element the previous one? */
2403 if ((te != prev) && (*prevFound))
2413 tes= outliner_find_named(soops, &te->subtree, name, flags, prev, prevFound);
2417 /* nothing valid found */
2421 /* tse is not in the treestore, we use its contents to find a match */
2422 static TreeElement *outliner_find_tse(SpaceOops *soops, TreeStoreElem *tse)
2424 TreeStore *ts= soops->treestore;
2425 TreeStoreElem *tselem;
2428 if(tse->id==NULL) return NULL;
2430 /* check if 'tse' is in treestore */
2432 for(a=0; a<ts->usedelem; a++, tselem++) {
2433 if((tse->type==0 && tselem->type==0) || (tselem->type==tse->type && tselem->nr==tse->nr)) {
2434 if(tselem->id==tse->id) {
2440 return outliner_find_tree_element(&soops->tree, a);
2446 /* Called to find an item based on name.
2448 void outliner_find_panel(Scene *scene, ARegion *ar, SpaceOops *soops, int again, int flags)
2450 TreeElement *te= NULL;
2451 TreeElement *last_find;
2452 TreeStoreElem *tselem;
2453 int ytop, xdelta, prevFound=0;
2456 /* get last found tree-element based on stored search_tse */
2457 last_find= outliner_find_tse(soops, &soops->search_tse);
2459 /* determine which type of search to do */
2460 if (again && last_find) {
2461 /* no popup panel - previous + user wanted to search for next after previous */
2462 BLI_strncpy(name, soops->search_string, 33);
2463 flags= soops->search_flags;
2465 /* try to find matching element */
2466 te= outliner_find_named(soops, &soops->tree, name, flags, last_find, &prevFound);
2468 /* no more matches after previous, start from beginning again */
2470 te= outliner_find_named(soops, &soops->tree, name, flags, last_find, &prevFound);
2474 /* pop up panel - no previous, or user didn't want search after previous */
2476 // XXX if (sbutton(name, 0, sizeof(name)-1, "Find: ") && name[0]) {
2477 // te= outliner_find_named(soops, &soops->tree, name, flags, NULL, &prevFound);
2479 // else return; /* XXX RETURN! XXX */
2482 /* do selection and reveal */
2484 tselem= TREESTORE(te);
2486 /* expand branches so that it will be visible, we need to get correct coordinates */
2487 if( outliner_open_back(soops, te))
2488 outliner_set_coordinates(ar, soops);
2490 /* deselect all visible, and select found element */
2491 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
2492 tselem->flag |= TSE_SELECTED;
2494 /* make te->ys center of view */
2495 ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
2497 ar->v2d.cur.ymax= (float)ytop;
2498 ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
2500 /* make te->xs ==> te->xend center of view */
2501 xdelta = (int)(te->xs - ar->v2d.cur.xmin);
2502 ar->v2d.cur.xmin += xdelta;
2503 ar->v2d.cur.xmax += xdelta;
2505 /* store selection */
2506 soops->search_tse= *tselem;
2508 BLI_strncpy(soops->search_string, name, 33);
2509 soops->search_flags= flags;
2512 soops->storeflag |= SO_TREESTORE_REDRAW;
2516 /* no tree-element found */
2517 error("Not found: %s", name);
2521 static int subtree_has_objects(SpaceOops *soops, ListBase *lb)
2524 TreeStoreElem *tselem;
2526 for(te= lb->first; te; te= te->next) {
2527 tselem= TREESTORE(te);
2528 if(tselem->type==0 && te->idcode==ID_OB) return 1;
2529 if( subtree_has_objects(soops, &te->subtree)) return 1;
2534 static void tree_element_show_hierarchy(Scene *scene, SpaceOops *soops, ListBase *lb)
2537 TreeStoreElem *tselem;
2539 /* open all object elems, close others */
2540 for(te= lb->first; te; te= te->next) {
2541 tselem= TREESTORE(te);
2543 if(tselem->type==0) {
2544 if(te->idcode==ID_SCE) {
2545 if(tselem->id!=(ID *)scene) tselem->flag |= TSE_CLOSED;
2546 else tselem->flag &= ~TSE_CLOSED;
2548 else if(te->idcode==ID_OB) {
2549 if(subtree_has_objects(soops, &te->subtree)) tselem->flag &= ~TSE_CLOSED;
2550 else tselem->flag |= TSE_CLOSED;
2553 else tselem->flag |= TSE_CLOSED;
2555 if(tselem->flag & TSE_CLOSED); else tree_element_show_hierarchy(scene, soops, &te->subtree);
2560 /* show entire object level hierarchy */
2561 void outliner_show_hierarchy(Scene *scene, SpaceOops *soops)
2564 tree_element_show_hierarchy(scene, soops, &soops->tree);
2566 BIF_undo_push("Outliner show hierarchy");
2569 void outliner_select(SpaceOops *soops, ListBase *lb, int *index, short *selecting)
2572 TreeStoreElem *tselem;
2574 for (te= lb->first; te && *index >= 0; te=te->next, (*index)--) {
2575 tselem= TREESTORE(te);
2577 /* if we've encountered the right item, set its 'Outliner' selection status */
2579 /* this should be the last one, so no need to do anything with index */
2580 if ((te->flag & TE_ICONROW)==0) {
2581 /* -1 value means toggle testing for now... */
2582 if (*selecting == -1) {
2583 if (tselem->flag & TSE_SELECTED)
2591 tselem->flag |= TSE_SELECTED;
2593 tselem->flag &= ~TSE_SELECTED;
2596 else if ((tselem->flag & TSE_CLOSED)==0) {
2597 /* Only try selecting sub-elements if we haven't hit the right element yet
2600 * Index must be reduced before supplying it to the sub-tree to try to do
2601 * selection, however, we need to increment it again for the next loop to
2602 * function correctly
2605 outliner_select(soops, &te->subtree, index, selecting);
2611 /* ************ SELECTION OPERATIONS ********* */
2613 static void set_operation_types(SpaceOops *soops, ListBase *lb,
2620 TreeStoreElem *tselem;
2622 for(te= lb->first; te; te= te->next) {
2623 tselem= TREESTORE(te);
2624 if(tselem->flag & TSE_SELECTED) {
2626 if(tselem->type==TSE_SEQUENCE)
2627 *datalevel= TSE_SEQUENCE;
2628 else if(tselem->type==TSE_SEQ_STRIP)
2629 *datalevel= TSE_SEQ_STRIP;
2630 else if(tselem->type==TSE_SEQUENCE_DUP)
2631 *datalevel= TSE_SEQUENCE_DUP;
2632 else if(*datalevel!=tselem->type) *datalevel= -1;
2635 int idcode= GS(tselem->id->name);
2644 case ID_ME: case ID_CU: case ID_MB: case ID_LT:
2645 case ID_LA: case ID_AR: case ID_CA:
2646 case ID_MA: case ID_TE: case ID_IP: case ID_IM:
2647 case ID_SO: case ID_KE: case ID_WO: case ID_AC:
2648 case ID_NLA: case ID_TXT: case ID_GR:
2649 if(*idlevel==0) *idlevel= idcode;
2650 else if(*idlevel!=idcode) *idlevel= -1;
2655 if((tselem->flag & TSE_CLOSED)==0) {
2656 set_operation_types(soops, &te->subtree,
2657 scenelevel, objectlevel, idlevel, datalevel);
2662 static void unlink_material_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2664 Material **matar=NULL;
2667 if( GS(tsep->id->name)==ID_OB) {
2668 Object *ob= (Object *)tsep->id;
2672 else if( GS(tsep->id->name)==ID_ME) {
2673 Mesh *me= (Mesh *)tsep->id;
2677 else if( GS(tsep->id->name)==ID_CU) {
2678 Curve *cu= (Curve *)tsep->id;
2682 else if( GS(tsep->id->name)==ID_MB) {
2683 MetaBall *mb= (MetaBall *)tsep->id;
2688 for(a=0; a<totcol; a++) {
2689 if(a==te->index && matar[a]) {
2696 static void unlink_texture_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2701 if( GS(tsep->id->name)==ID_MA) {
2702 Material *ma= (Material *)tsep->id;
2705 else if( GS(tsep->id->name)==ID_LA) {
2706 Lamp *la= (Lamp *)tsep->id;
2709 else if( GS(tsep->id->name)==ID_WO) {
2710 World *wrld= (World *)tsep->id;
2715 for(a=0; a<MAX_MTEX; a++) {
2716 if(a==te->index && mtex[a]) {
2718 mtex[a]->tex->id.us--;
2725 static void unlink_group_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2727 Group *group= (Group *)tselem->id;
2730 if( GS(tsep->id->name)==ID_OB) {
2731 Object *ob= (Object *)tsep->id;
2732 ob->dup_group= NULL;
2737 unlink_group(group);
2741 static void outliner_do_libdata_operation(SpaceOops *soops, ListBase *lb,
2742 void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *))
2745 TreeStoreElem *tselem;
2747 for(te=lb->first; te; te= te->next) {
2748 tselem= TREESTORE(te);
2749 if(tselem->flag & TSE_SELECTED) {
2750 if(tselem->type==0) {
2751 TreeStoreElem *tsep= TREESTORE(te->parent);
2752 operation_cb(te, tsep, tselem);
2755 if((tselem->flag & TSE_CLOSED)==0) {
2756 outliner_do_libdata_operation(soops, &te->subtree, operation_cb);
2763 static void object_select_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2765 Scene *scene= NULL; // XXX
2766 Base *base= (Base *)te->directdata;
2768 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
2769 if(base && ((base->object->restrictflag & OB_RESTRICT_VIEW)==0)) {
2770 base->flag |= SELECT;
2771 base->object->flag |= SELECT;
2775 static void object_deselect_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2778 Base *base= (Base *)te->directdata;
2780 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
2782 base->flag &= ~SELECT;
2783 base->object->flag &= ~SELECT;
2787 static void object_delete_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2790 Base *base= (Base *)te->directdata;
2792 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
2794 // check also library later
2795 // XXX if(obedit==base->object) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2798 G.f &= ~(G_VERTEXPAINT+G_TEXTUREPAINT+G_WEIGHTPAINT+G_SCULPTMODE);
2799 // XXX setcursor_space(SPACE_VIEW3D, CURSOR_STD);
2802 // XXX free_and_unlink_base(base);
2803 te->directdata= NULL;
2808 static void id_local_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2810 if(tselem->id->lib && (tselem->id->flag & LIB_EXTERN)) {
2811 tselem->id->lib= NULL;
2812 tselem->id->flag= LIB_LOCAL;
2813 new_id(0, tselem->id, 0);
2817 static void group_linkobs2scene_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2820 Group *group= (Group *)tselem->id;
2824 for(gob=group->gobject.first; gob; gob=gob->next) {
2825 base= object_in_scene(gob->ob, scene);
2827 base->object->flag |= SELECT;
2828 base->flag |= SELECT;
2831 base= MEM_callocN( sizeof(Base), "add_base");
2832 BLI_addhead(&scene->base, base);
2833 base->lay= (1<<20)-1; /*v3d->lay;*/ /* would be nice to use the 3d layer but the include's not here */
2834 gob->ob->flag |= SELECT;
2835 base->flag = gob->ob->flag;
2836 base->object= gob->ob;
2837 id_lib_extern((ID *)gob->ob); /* incase these are from a linked group */
2842 static void outliner_do_object_operation(Scene *scene, SpaceOops *soops, ListBase *lb,
2843 void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *))
2846 TreeStoreElem *tselem;
2848 for(te=lb->first; te; te= te->next) {
2849 tselem= TREESTORE(te);
2850 if(tselem->flag & TSE_SELECTED) {
2851 if(tselem->type==0 && te->idcode==ID_OB) {
2852 // when objects selected in other scenes... dunno if th