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_outliner_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_armature.h"
86 #include "ED_object.h"
87 #include "ED_screen.h"
95 #include "BIF_glutil.h"
97 #include "UI_interface.h"
98 #include "UI_interface_icons.h"
99 #include "UI_resources.h"
100 #include "UI_view2d.h"
102 #include "RNA_access.h"
103 #include "RNA_define.h"
105 #include "ED_armature.h"
106 #include "ED_keyframing.h"
107 #include "ED_object.h"
108 #include "ED_particle.h"
109 #include "ED_screen.h"
110 #include "ED_view3d.h"
112 #include "outliner_intern.h"
114 #include "PIL_time.h"
120 #define OL_TOG_RESTRICT_VIEWX 54
121 #define OL_TOG_RESTRICT_SELECTX 36
122 #define OL_TOG_RESTRICT_RENDERX 18
124 #define OL_TOGW OL_TOG_RESTRICT_VIEWX
126 #define OL_RNA_COLX 300
127 #define OL_RNA_COL_SIZEX 150
128 #define OL_RNA_COL_SPACEX 50
132 #define TREESTORE(a) ((a)?soops->treestore->data+(a)->store_index:NULL)
134 /* ************* XXX **************** */
136 static void error() {}
138 /* ********************************** */
141 /* ******************** PROTOTYPES ***************** */
142 static void outliner_draw_tree_element(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty);
143 static void outliner_do_object_operation(bContext *C, Scene *scene, SpaceOops *soops, ListBase *lb,
144 void (*operation_cb)(bContext *C, Scene *scene, TreeElement *, TreeStoreElem *, TreeStoreElem *));
147 /* ******************** PERSISTANT DATA ***************** */
149 static void outliner_storage_cleanup(SpaceOops *soops)
151 TreeStore *ts= soops->treestore;
154 TreeStoreElem *tselem;
157 /* each element used once, for ID blocks with more users to have each a treestore */
158 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) tselem->used= 0;
160 /* cleanup only after reading file or undo step, and always for
161 * RNA datablocks view in order to save memory */
162 if(soops->storeflag & SO_TREESTORE_CLEANUP) {
164 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) {
165 if(tselem->id==NULL) unused++;
169 if(ts->usedelem == unused) {
172 ts->usedelem= ts->totelem= 0;
175 TreeStoreElem *tsnewar, *tsnew;
177 tsnew=tsnewar= MEM_mallocN((ts->usedelem-unused)*sizeof(TreeStoreElem), "new tselem");
178 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) {
186 ts->usedelem-= unused;
187 ts->totelem= ts->usedelem;
194 static void check_persistant(SpaceOops *soops, TreeElement *te, ID *id, short type, short nr)
197 TreeStoreElem *tselem;
200 /* case 1; no TreeStore */
201 if(soops->treestore==NULL) {
202 ts= soops->treestore= MEM_callocN(sizeof(TreeStore), "treestore");
204 ts= soops->treestore;
206 /* check if 'te' is in treestore */
208 for(a=0; a<ts->usedelem; a++, tselem++) {
209 if(tselem->id==id && tselem->used==0) {
210 if((type==0 && tselem->type==0) ||(tselem->type==type && tselem->nr==nr)) {
218 /* add 1 element to treestore */
219 if(ts->usedelem==ts->totelem) {
220 TreeStoreElem *tsnew;
222 tsnew= MEM_mallocN((ts->totelem+TS_CHUNK)*sizeof(TreeStoreElem), "treestore data");
224 memcpy(tsnew, ts->data, ts->totelem*sizeof(TreeStoreElem));
228 ts->totelem+= TS_CHUNK;
231 tselem= ts->data+ts->usedelem;
234 if(type) tselem->nr= nr; // we're picky! :)
238 tselem->flag= TSE_CLOSED;
239 te->store_index= ts->usedelem;
244 /* ******************** TREE MANAGEMENT ****************** */
246 void outliner_free_tree(ListBase *lb)
250 TreeElement *te= lb->first;
252 outliner_free_tree(&te->subtree);
255 if(te->flag & TE_FREE_NAME) MEM_freeN(te->name);
260 static void outliner_height(SpaceOops *soops, ListBase *lb, int *h)
262 TreeElement *te= lb->first;
264 TreeStoreElem *tselem= TREESTORE(te);
265 if((tselem->flag & TSE_CLOSED)==0)
266 outliner_height(soops, &te->subtree, h);
272 #if 0 // XXX this is currently disabled until te->xend is set correctly
273 static void outliner_width(SpaceOops *soops, ListBase *lb, int *w)
275 TreeElement *te= lb->first;
277 // TreeStoreElem *tselem= TREESTORE(te);
279 // XXX fixme... te->xend is not set yet
280 if(tselem->flag & TSE_CLOSED) {
284 outliner_width(soops, &te->subtree, w);
290 static void outliner_rna_width(SpaceOops *soops, ListBase *lb, int *w, int startx)
292 TreeElement *te= lb->first;
294 TreeStoreElem *tselem= TREESTORE(te);
295 // XXX fixme... (currently, we're using a fixed length of 100)!
303 if((tselem->flag & TSE_CLOSED)==0)
304 outliner_rna_width(soops, &te->subtree, w, startx+OL_X);
309 static TreeElement *outliner_find_tree_element(ListBase *lb, int store_index)
311 TreeElement *te= lb->first, *tes;
313 if(te->store_index==store_index) return te;
314 tes= outliner_find_tree_element(&te->subtree, store_index);
323 static ID *outliner_search_back(SpaceOops *soops, TreeElement *te, short idcode)
325 TreeStoreElem *tselem;
329 tselem= TREESTORE(te);
330 if(tselem->type==0 && te->idcode==idcode) return tselem->id;
343 static int treesort_alpha(const void *v1, const void *v2)
345 const struct treesort *x1= v1, *x2= v2;
348 /* first put objects last (hierarchy) */
349 comp= (x1->idcode==ID_OB);
350 if(x2->idcode==ID_OB) comp+=2;
352 if(comp==1) return 1;
353 else if(comp==2) return -1;
355 int comp= strcmp(x1->name, x2->name);
357 if( comp>0 ) return 1;
358 else if( comp<0) return -1;
364 /* this is nice option for later? doesnt look too useful... */
366 static int treesort_obtype_alpha(const void *v1, const void *v2)
368 const struct treesort *x1= v1, *x2= v2;
370 /* first put objects last (hierarchy) */
371 if(x1->idcode==ID_OB && x2->idcode!=ID_OB) return 1;
372 else if(x2->idcode==ID_OB && x1->idcode!=ID_OB) return -1;
374 /* 2nd we check ob type */
375 if(x1->idcode==ID_OB && x2->idcode==ID_OB) {
376 if( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return 1;
377 else if( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return -1;
381 int comp= strcmp(x1->name, x2->name);
383 if( comp>0 ) return 1;
384 else if( comp<0) return -1;
391 /* sort happens on each subtree individual */
392 static void outliner_sort(SpaceOops *soops, ListBase *lb)
395 TreeStoreElem *tselem;
400 tselem= TREESTORE(te);
402 /* sorting rules; only object lists or deformgroups */
403 if( (tselem->type==TSE_DEFGROUP) || (tselem->type==0 && te->idcode==ID_OB)) {
406 for(te= lb->first; te; te= te->next) totelem++;
409 struct treesort *tear= MEM_mallocN(totelem*sizeof(struct treesort), "tree sort array");
410 struct treesort *tp=tear;
413 for(te= lb->first; te; te= te->next, tp++) {
414 tselem= TREESTORE(te);
417 tp->idcode= te->idcode;
418 if(tselem->type && tselem->type!=TSE_DEFGROUP) tp->idcode= 0; // dont sort this
421 /* keep beginning of list */
422 for(tp= tear, skip=0; skip<totelem; skip++, tp++)
423 if(tp->idcode) break;
426 qsort(tear+skip, totelem-skip, sizeof(struct treesort), treesort_alpha);
428 lb->first=lb->last= NULL;
431 BLI_addtail(lb, tp->te);
438 for(te= lb->first; te; te= te->next) {
439 outliner_sort(soops, &te->subtree);
443 /* Prototype, see functions below */
444 static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv,
445 TreeElement *parent, short type, short index);
448 static void outliner_add_passes(SpaceOops *soops, TreeElement *tenla, ID *id, SceneRenderLayer *srl)
450 TreeStoreElem *tselem= TREESTORE(tenla);
453 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_COMBINED);
454 te->name= "Combined";
455 te->directdata= &srl->passflag;
457 /* save cpu cycles, but we add the first to invoke an open/close triangle */
458 if(tselem->flag & TSE_CLOSED)
461 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_Z);
463 te->directdata= &srl->passflag;
465 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_VECTOR);
467 te->directdata= &srl->passflag;
469 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_NORMAL);
471 te->directdata= &srl->passflag;
473 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_UV);
475 te->directdata= &srl->passflag;
477 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_MIST);
479 te->directdata= &srl->passflag;
481 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_INDEXOB);
482 te->name= "Index Object";
483 te->directdata= &srl->passflag;
485 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_RGBA);
487 te->directdata= &srl->passflag;
489 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_DIFFUSE);
491 te->directdata= &srl->passflag;
493 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_SPEC);
494 te->name= "Specular";
495 te->directdata= &srl->passflag;
497 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_SHADOW);
499 te->directdata= &srl->passflag;
501 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_AO);
503 te->directdata= &srl->passflag;
505 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_REFLECT);
506 te->name= "Reflection";
507 te->directdata= &srl->passflag;
509 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_REFRACT);
510 te->name= "Refraction";
511 te->directdata= &srl->passflag;
513 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_RADIO);
514 te->name= "Radiosity";
515 te->directdata= &srl->passflag;
520 /* special handling of hierarchical non-lib data */
521 static void outliner_add_bone(SpaceOops *soops, ListBase *lb, ID *id, Bone *curBone,
522 TreeElement *parent, int *a)
524 TreeElement *te= outliner_add_element(soops, lb, id, parent, TSE_BONE, *a);
527 te->name= curBone->name;
528 te->directdata= curBone;
530 for(curBone= curBone->childbase.first; curBone; curBone=curBone->next) {
531 outliner_add_bone(soops, &te->subtree, id, curBone, te, a);
535 static void outliner_add_scene_contents(SpaceOops *soops, ListBase *lb, Scene *sce, TreeElement *te)
537 SceneRenderLayer *srl;
538 TreeElement *tenla= outliner_add_element(soops, lb, sce, te, TSE_R_LAYER_BASE, 0);
541 tenla->name= "RenderLayers";
542 for(a=0, srl= sce->r.layers.first; srl; srl= srl->next, a++) {
543 TreeElement *tenlay= outliner_add_element(soops, &tenla->subtree, sce, te, TSE_R_LAYER, a);
544 tenlay->name= srl->name;
545 tenlay->directdata= &srl->passflag;
547 if(srl->light_override)
548 outliner_add_element(soops, &tenlay->subtree, srl->light_override, tenlay, TSE_LINKED_LAMP, 0);
549 if(srl->mat_override)
550 outliner_add_element(soops, &tenlay->subtree, srl->mat_override, tenlay, TSE_LINKED_MAT, 0);
552 outliner_add_passes(soops, tenlay, &sce->id, srl);
555 outliner_add_element(soops, lb, sce->world, te, 0, 0);
558 static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv,
559 TreeElement *parent, short type, short index)
562 TreeStoreElem *tselem;
566 if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
567 id= ((PointerRNA*)idv)->id.data;
568 if(!id) id= ((PointerRNA*)idv)->data;
571 if(id==NULL) return NULL;
573 te= MEM_callocN(sizeof(TreeElement), "tree elem");
574 /* add to the visual tree */
576 /* add to the storage */
577 check_persistant(soops, te, id, type, index);
578 tselem= TREESTORE(te);
581 te->index= index; // for data arays
582 if(ELEM3(type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP));
583 else if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM));
584 else if(type==TSE_ANIM_DATA);
586 te->name= id->name+2; // default, can be overridden by Library or non-ID data
587 te->idcode= GS(id->name);
592 /* tuck pointer back in object, to construct hierarchy */
593 if(GS(id->name)==ID_OB) id->newid= (ID *)te;
595 /* expand specific data always */
596 switch(GS(id->name)) {
598 te->name= ((Library *)id)->name;
601 outliner_add_scene_contents(soops, &te->subtree, (Scene *)id, te);
605 Object *ob= (Object *)id;
607 outliner_add_element(soops, &te->subtree, ob->adt, te, TSE_ANIM_DATA, 0);
608 outliner_add_element(soops, &te->subtree, ob->poselib, te, 0, 0); // XXX FIXME.. add a special type for this
610 if(ob->proxy && ob->id.lib==NULL)
611 outliner_add_element(soops, &te->subtree, ob->proxy, te, TSE_PROXY, 0);
613 outliner_add_element(soops, &te->subtree, ob->data, te, 0, 0);
616 bArmature *arm= ob->data;
619 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_POSE_BASE, 0);
623 if(arm->edbo==NULL && (ob->flag & OB_POSEMODE)) { // channels undefined in editmode, but we want the 'tenla' pose icon itself
624 int a= 0, const_index= 1000; /* ensure unique id for bone constraints */
626 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next, a++) {
627 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_POSE_CHANNEL, a);
628 ten->name= pchan->name;
629 ten->directdata= pchan;
630 pchan->prev= (bPoseChannel *)ten;
632 if(pchan->constraints.first) {
636 TreeElement *tenla1= outliner_add_element(soops, &ten->subtree, ob, ten, TSE_CONSTRAINT_BASE, 0);
639 tenla1->name= "Constraints";
640 for(con= pchan->constraints.first; con; con= con->next, const_index++) {
641 ten1= outliner_add_element(soops, &tenla1->subtree, ob, tenla1, TSE_CONSTRAINT, const_index);
642 #if 0 /* disabled as it needs to be reworked for recoded constraints system */
643 target= get_constraint_target(con, &str);
644 if(str && str[0]) ten1->name= str;
645 else if(target) ten1->name= target->id.name+2;
646 else ten1->name= con->name;
648 ten1->name= con->name;
649 ten1->directdata= con;
650 /* possible add all other types links? */
655 ten= tenla->subtree.first;
657 TreeElement *nten= ten->next, *par;
658 tselem= TREESTORE(ten);
659 if(tselem->type==TSE_POSE_CHANNEL) {
660 pchan= (bPoseChannel *)ten->directdata;
662 BLI_remlink(&tenla->subtree, ten);
663 par= (TreeElement *)pchan->parent->prev;
664 BLI_addtail(&par->subtree, ten);
670 /* restore prev pointers */
671 pchan= ob->pose->chanbase.first;
672 if(pchan) pchan->prev= NULL;
673 for(; pchan; pchan= pchan->next) {
674 if(pchan->next) pchan->next->prev= pchan;
679 if(ob->pose->agroups.first) {
682 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_POSEGRP_BASE, 0);
685 tenla->name= "Bone Groups";
686 for (agrp=ob->pose->agroups.first; agrp; agrp=agrp->next, a++) {
687 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_POSEGRP, a);
688 ten->name= agrp->name;
689 ten->directdata= agrp;
694 for(a=0; a<ob->totcol; a++)
695 outliner_add_element(soops, &te->subtree, ob->mat[a], te, 0, a);
697 if(ob->constraints.first) {
701 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_CONSTRAINT_BASE, 0);
705 tenla->name= "Constraints";
706 for(con= ob->constraints.first; con; con= con->next, a++) {
707 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_CONSTRAINT, a);
708 #if 0 /* disabled due to constraints system targets recode... code here needs review */
709 target= get_constraint_target(con, &str);
710 if(str && str[0]) ten->name= str;
711 else if(target) ten->name= target->id.name+2;
712 else ten->name= con->name;
714 ten->name= con->name;
715 ten->directdata= con;
716 /* possible add all other types links? */
720 if(ob->modifiers.first) {
722 TreeElement *temod = outliner_add_element(soops, &te->subtree, ob, te, TSE_MODIFIER_BASE, 0);
725 temod->name = "Modifiers";
726 for (index=0,md=ob->modifiers.first; md; index++,md=md->next) {
727 TreeElement *te = outliner_add_element(soops, &temod->subtree, ob, temod, TSE_MODIFIER, index);
731 if (md->type==eModifierType_Lattice) {
732 outliner_add_element(soops, &te->subtree, ((LatticeModifierData*) md)->object, te, TSE_LINKED_OB, 0);
733 } else if (md->type==eModifierType_Curve) {
734 outliner_add_element(soops, &te->subtree, ((CurveModifierData*) md)->object, te, TSE_LINKED_OB, 0);
735 } else if (md->type==eModifierType_Armature) {
736 outliner_add_element(soops, &te->subtree, ((ArmatureModifierData*) md)->object, te, TSE_LINKED_OB, 0);
737 } else if (md->type==eModifierType_Hook) {
738 outliner_add_element(soops, &te->subtree, ((HookModifierData*) md)->object, te, TSE_LINKED_OB, 0);
739 } else if (md->type==eModifierType_ParticleSystem) {
741 ParticleSystem *psys= ((ParticleSystemModifierData*) md)->psys;
743 ten = outliner_add_element(soops, &te->subtree, ob, te, TSE_LINKED_PSYS, 0);
744 ten->directdata = psys;
745 ten->name = psys->part->id.name+2;
749 if(ob->defbase.first) {
750 bDeformGroup *defgroup;
752 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_DEFGROUP_BASE, 0);
755 tenla->name= "Vertex Groups";
756 for (defgroup=ob->defbase.first; defgroup; defgroup=defgroup->next, a++) {
757 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_DEFGROUP, a);
758 ten->name= defgroup->name;
759 ten->directdata= defgroup;
764 outliner_add_element(soops, &te->subtree, ob->dup_group, te, 0, 0);
770 Mesh *me= (Mesh *)id;
772 //outliner_add_element(soops, &te->subtree, me->adt, te, TSE_ANIM_DATA, 0);
774 outliner_add_element(soops, &te->subtree, me->key, te, 0, 0);
775 for(a=0; a<me->totcol; a++)
776 outliner_add_element(soops, &te->subtree, me->mat[a], te, 0, a);
777 /* could do tfaces with image links, but the images are not grouped nicely.
778 would require going over all tfaces, sort images in use. etc... */
783 Curve *cu= (Curve *)id;
785 outliner_add_element(soops, &te->subtree, cu->adt, te, TSE_ANIM_DATA, 0);
787 for(a=0; a<cu->totcol; a++)
788 outliner_add_element(soops, &te->subtree, cu->mat[a], te, 0, a);
793 MetaBall *mb= (MetaBall *)id;
794 for(a=0; a<mb->totcol; a++)
795 outliner_add_element(soops, &te->subtree, mb->mat[a], te, 0, a);
800 Material *ma= (Material *)id;
802 outliner_add_element(soops, &te->subtree, ma->adt, te, TSE_ANIM_DATA, 0);
804 for(a=0; a<MAX_MTEX; a++) {
805 if(ma->mtex[a]) outliner_add_element(soops, &te->subtree, ma->mtex[a]->tex, te, 0, a);
813 outliner_add_element(soops, &te->subtree, tex->adt, te, TSE_ANIM_DATA, 0);
814 outliner_add_element(soops, &te->subtree, tex->ima, te, 0, 0);
819 Camera *ca= (Camera *)id;
820 outliner_add_element(soops, &te->subtree, ca->adt, te, TSE_ANIM_DATA, 0);
825 Lamp *la= (Lamp *)id;
827 outliner_add_element(soops, &te->subtree, la->adt, te, TSE_ANIM_DATA, 0);
829 for(a=0; a<MAX_MTEX; a++) {
830 if(la->mtex[a]) outliner_add_element(soops, &te->subtree, la->mtex[a]->tex, te, 0, a);
836 World *wrld= (World *)id;
838 outliner_add_element(soops, &te->subtree, wrld->adt, te, TSE_ANIM_DATA, 0);
840 for(a=0; a<MAX_MTEX; a++) {
841 if(wrld->mtex[a]) outliner_add_element(soops, &te->subtree, wrld->mtex[a]->tex, te, 0, a);
849 outliner_add_element(soops, &te->subtree, key->adt, te, TSE_ANIM_DATA, 0);
854 // XXX do we want to be exposing the F-Curves here?
855 //bAction *act= (bAction *)id;
860 bArmature *arm= (bArmature *)id;
867 for (ebone = arm->edbo->first; ebone; ebone=ebone->next, a++) {
868 ten= outliner_add_element(soops, &te->subtree, id, te, TSE_EBONE, a);
869 ten->directdata= ebone;
870 ten->name= ebone->name;
874 ten= te->subtree.first;
876 TreeElement *nten= ten->next, *par;
877 ebone= (EditBone *)ten->directdata;
879 BLI_remlink(&te->subtree, ten);
880 par= ebone->parent->temp;
881 BLI_addtail(&par->subtree, ten);
888 /* do not extend Armature when we have posemode */
889 tselem= TREESTORE(te->parent);
890 if( GS(tselem->id->name)==ID_OB && ((Object *)tselem->id)->flag & OB_POSEMODE);
893 for (curBone=arm->bonebase.first; curBone; curBone=curBone->next){
894 outliner_add_bone(soops, &te->subtree, id, curBone, te, &a);
902 else if(type==TSE_ANIM_DATA) {
903 AnimData *adt= (AnimData *)idv;
905 /* this element's info */
906 te->name= "Animation";
909 outliner_add_element(soops, &te->subtree, adt->action, te, 0, 0);
912 if (adt->drivers.first) {
913 TreeElement *ted= outliner_add_element(soops, &te->subtree, adt, te, TSE_DRIVER_BASE, 0);
918 ted->name= "Drivers";
920 for (fcu= adt->drivers.first; fcu; fcu= fcu->next) {
921 if (fcu->driver && fcu->driver->targets.first) {
922 for (dtar= fcu->driver->targets.first; dtar; dtar= dtar->next) {
923 if (lastadded != dtar->id) {
924 // XXX this lastadded check is rather lame, and also fails quite badly...
925 outliner_add_element(soops, &ted->subtree, dtar->id, ted, TSE_LINKED_OB, 0);
934 if (adt->nla_tracks.first) {
935 TreeElement *tenla= outliner_add_element(soops, &te->subtree, adt, te, TSE_NLA, 0);
939 tenla->name= "NLA Tracks";
941 for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) {
942 TreeElement *tenlt= outliner_add_element(soops, &tenla->subtree, nlt, tenla, TSE_NLA_TRACK, a);
947 tenlt->name= nlt->name;
949 for (strip=nlt->strips.first; strip; strip=strip->next, b++) {
950 ten= outliner_add_element(soops, &tenlt->subtree, strip->act, tenlt, TSE_NLA_ACTION, b);
951 if(ten) ten->directdata= strip;
956 else if(type==TSE_SEQUENCE) {
957 Sequence *seq= (Sequence*) idv;
961 * The idcode is a little hack, but the outliner
962 * only check te->idcode if te->type is equal to zero,
965 te->idcode= seq->type;
970 * This work like the sequence.
971 * If the sequence have a name (not default name)
972 * show it, in other case put the filename.
974 if(strcmp(seq->name, "SQ"))
977 if((seq->strip) && (seq->strip->stripdata))
978 te->name= seq->strip->stripdata->name;
979 else if((seq->strip) && (seq->strip->tstripdata) && (seq->strip->tstripdata->ibuf))
980 te->name= seq->strip->tstripdata->ibuf->name;
985 if(seq->type==SEQ_META) {
986 te->name= "Meta Strip";
987 p= seq->seqbase.first;
989 outliner_add_element(soops, &te->subtree, (void*)p, te, TSE_SEQUENCE, index);
994 outliner_add_element(soops, &te->subtree, (void*)seq->strip, te, TSE_SEQ_STRIP, index);
999 else if(type==TSE_SEQ_STRIP) {
1000 Strip *strip= (Strip *)idv;
1003 te->name= strip->dir;
1005 te->name= "Strip None";
1006 te->directdata= strip;
1008 else if(type==TSE_SEQUENCE_DUP) {
1009 Sequence *seq= (Sequence*)idv;
1011 te->idcode= seq->type;
1012 te->directdata= seq;
1013 te->name= seq->strip->stripdata->name;
1015 else if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
1016 PointerRNA pptr, propptr, *ptr= (PointerRNA*)idv;
1017 PropertyRNA *prop, *iterprop;
1018 PropertyType proptype;
1019 PropertySubType propsubtype;
1022 /* we do lazy build, for speed and to avoid infinite recusion */
1024 if(ptr->data == NULL) {
1025 te->name= "(empty)";
1027 else if(type == TSE_RNA_STRUCT) {
1029 te->name= RNA_struct_name_get_alloc(ptr, NULL, 0);
1032 te->flag |= TE_FREE_NAME;
1034 te->name= (char*)RNA_struct_ui_name(ptr->type);
1036 iterprop= RNA_struct_iterator_property(ptr->type);
1037 tot= RNA_property_collection_length(ptr, iterprop);
1039 /* auto open these cases */
1040 if(!parent || (RNA_property_type(parent->directdata)) == PROP_POINTER)
1042 tselem->flag &= ~TSE_CLOSED;
1044 if(!(tselem->flag & TSE_CLOSED)) {
1045 for(a=0; a<tot; a++)
1046 outliner_add_element(soops, &te->subtree, (void*)ptr, te, TSE_RNA_PROPERTY, a);
1049 te->flag |= TE_LAZY_CLOSED;
1053 else if(type == TSE_RNA_PROPERTY) {
1055 iterprop= RNA_struct_iterator_property(ptr->type);
1056 RNA_property_collection_lookup_int(ptr, iterprop, index, &propptr);
1059 proptype= RNA_property_type(prop);
1061 te->name= (char*)RNA_property_ui_name(prop);
1062 te->directdata= prop;
1065 if(proptype == PROP_POINTER) {
1066 pptr= RNA_property_pointer_get(ptr, prop);
1069 if(!(tselem->flag & TSE_CLOSED))
1070 outliner_add_element(soops, &te->subtree, (void*)&pptr, te, TSE_RNA_STRUCT, -1);
1072 te->flag |= TE_LAZY_CLOSED;
1075 else if(proptype == PROP_COLLECTION) {
1076 tot= RNA_property_collection_length(ptr, prop);
1078 if(!(tselem->flag & TSE_CLOSED)) {
1079 for(a=0; a<tot; a++) {
1080 RNA_property_collection_lookup_int(ptr, prop, a, &pptr);
1081 outliner_add_element(soops, &te->subtree, (void*)&pptr, te, TSE_RNA_STRUCT, -1);
1085 te->flag |= TE_LAZY_CLOSED;
1087 else if(ELEM3(proptype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
1088 tot= RNA_property_array_length(prop);
1090 if(!(tselem->flag & TSE_CLOSED)) {
1091 for(a=0; a<tot; a++)
1092 outliner_add_element(soops, &te->subtree, (void*)ptr, te, TSE_RNA_ARRAY_ELEM, a);
1095 te->flag |= TE_LAZY_CLOSED;
1098 else if(type == TSE_RNA_ARRAY_ELEM) {
1099 /* array property element */
1100 static char *vectoritem[4]= {" x", " y", " z", " w"};
1101 static char *quatitem[4]= {" w", " x", " y", " z"};
1102 static char *coloritem[4]= {" r", " g", " b", " a"};
1104 prop= parent->directdata;
1105 proptype= RNA_property_type(prop);
1106 propsubtype= RNA_property_subtype(prop);
1107 tot= RNA_property_array_length(prop);
1109 te->directdata= prop;
1113 if(tot == 4 && propsubtype == PROP_ROTATION)
1114 te->name= quatitem[index];
1115 else if(tot <= 4 && (propsubtype == PROP_VECTOR || propsubtype == PROP_ROTATION))
1116 te->name= vectoritem[index];
1117 else if(tot <= 4 && propsubtype == PROP_COLOR)
1118 te->name= coloritem[index];
1120 te->name= MEM_callocN(sizeof(char)*20, "OutlinerRNAArrayName");
1121 sprintf(te->name, " %d", index+1);
1122 te->flag |= TE_FREE_NAME;
1130 static void outliner_make_hierarchy(SpaceOops *soops, ListBase *lb)
1132 TreeElement *te, *ten, *tep;
1133 TreeStoreElem *tselem;
1135 /* build hierarchy */
1136 // XXX also, set extents here...
1140 tselem= TREESTORE(te);
1142 if(tselem->type==0 && te->idcode==ID_OB) {
1143 Object *ob= (Object *)tselem->id;
1144 if(ob->parent && ob->parent->id.newid) {
1145 BLI_remlink(lb, te);
1146 tep= (TreeElement *)ob->parent->id.newid;
1147 BLI_addtail(&tep->subtree, te);
1148 // set correct parent pointers
1149 for(te=tep->subtree.first; te; te= te->next) te->parent= tep;
1156 /* Helped function to put duplicate sequence in the same tree. */
1157 int need_add_seq_dup(Sequence *seq)
1161 if((!seq->strip) || (!seq->strip->stripdata) || (!seq->strip->stripdata->name))
1165 * First check backward, if we found a duplicate
1166 * sequence before this, don't need it, just return.
1170 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1175 if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1182 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1187 if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1194 void add_seq_dup(SpaceOops *soops, Sequence *seq, TreeElement *te, short index)
1201 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1206 if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1207 ch= outliner_add_element(soops, &te->subtree, (void*)p, te, TSE_SEQUENCE, index);
1212 static void outliner_build_tree(Main *mainvar, Scene *scene, SpaceOops *soops)
1216 TreeElement *te=NULL, *ten;
1217 TreeStoreElem *tselem;
1218 int show_opened= (soops->treestore==NULL); /* on first view, we open scenes */
1220 if(soops->tree.first && (soops->storeflag & SO_TREESTORE_REDRAW))
1223 outliner_free_tree(&soops->tree);
1224 outliner_storage_cleanup(soops);
1226 /* clear ob id.new flags */
1227 for(ob= mainvar->object.first; ob; ob= ob->id.next) ob->id.newid= NULL;
1230 if(soops->outlinevis == SO_LIBRARIES) {
1233 for(lib= mainvar->library.first; lib; lib= lib->id.next) {
1234 ten= outliner_add_element(soops, &soops->tree, lib, NULL, 0, 0);
1235 lib->id.newid= (ID *)ten;
1237 /* make hierarchy */
1238 ten= soops->tree.first;
1240 TreeElement *nten= ten->next, *par;
1241 tselem= TREESTORE(ten);
1242 lib= (Library *)tselem->id;
1244 BLI_remlink(&soops->tree, ten);
1245 par= (TreeElement *)lib->parent->id.newid;
1246 BLI_addtail(&par->subtree, ten);
1251 /* restore newid pointers */
1252 for(lib= mainvar->library.first; lib; lib= lib->id.next)
1253 lib->id.newid= NULL;
1256 else if(soops->outlinevis == SO_ALL_SCENES) {
1258 for(sce= mainvar->scene.first; sce; sce= sce->id.next) {
1259 te= outliner_add_element(soops, &soops->tree, sce, NULL, 0, 0);
1260 tselem= TREESTORE(te);
1261 if(sce==scene && show_opened)
1262 tselem->flag &= ~TSE_CLOSED;
1264 for(base= sce->base.first; base; base= base->next) {
1265 ten= outliner_add_element(soops, &te->subtree, base->object, te, 0, 0);
1266 ten->directdata= base;
1268 outliner_make_hierarchy(soops, &te->subtree);
1269 /* clear id.newid, to prevent objects be inserted in wrong scenes (parent in other scene) */
1270 for(base= sce->base.first; base; base= base->next) base->object->id.newid= NULL;
1273 else if(soops->outlinevis == SO_CUR_SCENE) {
1275 outliner_add_scene_contents(soops, &soops->tree, scene, NULL);
1277 for(base= scene->base.first; base; base= base->next) {
1278 ten= outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1279 ten->directdata= base;
1281 outliner_make_hierarchy(soops, &soops->tree);
1283 else if(soops->outlinevis == SO_VISIBLE) {
1284 for(base= scene->base.first; base; base= base->next) {
1285 if(base->lay & scene->lay)
1286 outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1288 outliner_make_hierarchy(soops, &soops->tree);
1290 else if(soops->outlinevis == SO_GROUPS) {
1294 for(group= mainvar->group.first; group; group= group->id.next) {
1296 te= outliner_add_element(soops, &soops->tree, group, NULL, 0, 0);
1297 tselem= TREESTORE(te);
1299 for(go= group->gobject.first; go; go= go->next) {
1300 ten= outliner_add_element(soops, &te->subtree, go->ob, te, 0, 0);
1301 ten->directdata= NULL; /* eh, why? */
1303 outliner_make_hierarchy(soops, &te->subtree);
1304 /* clear id.newid, to prevent objects be inserted in wrong scenes (parent in other scene) */
1305 for(go= group->gobject.first; go; go= go->next) go->ob->id.newid= NULL;
1309 else if(soops->outlinevis == SO_SAME_TYPE) {
1312 for(base= scene->base.first; base; base= base->next) {
1313 if(base->object->type==ob->type) {
1314 ten= outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1315 ten->directdata= base;
1318 outliner_make_hierarchy(soops, &soops->tree);
1321 else if(soops->outlinevis == SO_SELECTED) {
1322 for(base= scene->base.first; base; base= base->next) {
1323 if(base->lay & scene->lay) {
1324 if(base==BASACT || (base->flag & SELECT)) {
1325 ten= outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1326 ten->directdata= base;
1330 outliner_make_hierarchy(soops, &soops->tree);
1332 else if(soops->outlinevis==SO_SEQUENCE) {
1334 Editing *ed= seq_give_editing(scene, FALSE);
1340 seq= ed->seqbasep->first;
1345 op= need_add_seq_dup(seq);
1347 ten= outliner_add_element(soops, &soops->tree, (void*)seq, NULL, TSE_SEQUENCE, 0);
1349 ten= outliner_add_element(soops, &soops->tree, (void*)seq, NULL, TSE_SEQUENCE_DUP, 0);
1350 add_seq_dup(soops, seq, ten, 0);
1355 else if(soops->outlinevis==SO_DATABLOCKS) {
1358 RNA_main_pointer_create(mainvar, &mainptr);
1360 ten= outliner_add_element(soops, &soops->tree, (void*)&mainptr, NULL, TSE_RNA_STRUCT, -1);
1363 tselem= TREESTORE(ten);
1364 tselem->flag &= ~TSE_CLOSED;
1367 else if(soops->outlinevis==SO_USERDEF) {
1368 PointerRNA userdefptr;
1370 RNA_pointer_create(NULL, &RNA_UserPreferences, &U, &userdefptr);
1372 ten= outliner_add_element(soops, &soops->tree, (void*)&userdefptr, NULL, TSE_RNA_STRUCT, -1);
1375 tselem= TREESTORE(ten);
1376 tselem->flag &= ~TSE_CLOSED;
1380 ten= outliner_add_element(soops, &soops->tree, OBACT, NULL, 0, 0);
1381 if(ten) ten->directdata= BASACT;
1384 outliner_sort(soops, &soops->tree);
1387 /* **************** INTERACTIVE ************* */
1389 static int outliner_count_levels(SpaceOops *soops, ListBase *lb, int curlevel)
1392 int level=curlevel, lev;
1394 for(te= lb->first; te; te= te->next) {
1396 lev= outliner_count_levels(soops, &te->subtree, curlevel+1);
1397 if(lev>level) level= lev;
1402 static int outliner_has_one_flag(SpaceOops *soops, ListBase *lb, short flag, short curlevel)
1405 TreeStoreElem *tselem;
1408 for(te= lb->first; te; te= te->next) {
1409 tselem= TREESTORE(te);
1410 if(tselem->flag & flag) return curlevel;
1412 level= outliner_has_one_flag(soops, &te->subtree, flag, curlevel+1);
1413 if(level) return level;
1418 static void outliner_set_flag(SpaceOops *soops, ListBase *lb, short flag, short set)
1421 TreeStoreElem *tselem;
1423 for(te= lb->first; te; te= te->next) {
1424 tselem= TREESTORE(te);
1425 if(set==0) tselem->flag &= ~flag;
1426 else tselem->flag |= flag;
1427 outliner_set_flag(soops, &te->subtree, flag, set);
1433 void object_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1435 Base *base= (Base *)te->directdata;
1437 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1439 base->object->restrictflag^=OB_RESTRICT_VIEW;
1443 static int outliner_toggle_visibility_exec(bContext *C, wmOperator *op)
1445 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
1446 Scene *scene= CTX_data_scene(C);
1447 ARegion *ar= CTX_wm_region(C);
1449 outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_visibility_cb);
1451 ED_region_tag_redraw(ar);
1453 return OPERATOR_FINISHED;
1456 void OUTLINER_OT_visibility_toggle(wmOperatorType *ot)
1459 ot->name= "Toggle Visability";
1460 ot->idname= "OUTLINER_OT_visibility_toggle";
1461 ot->description= "Toggle the visibility of selected items.";
1464 ot->exec= outliner_toggle_visibility_exec;
1465 ot->poll= ED_operator_outliner_active;
1467 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1472 static void object_toggle_selectability_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1474 Base *base= (Base *)te->directdata;
1476 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1478 base->object->restrictflag^=OB_RESTRICT_SELECT;
1482 static int outliner_toggle_selectability_exec(bContext *C, wmOperator *op)
1484 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
1485 Scene *scene= CTX_data_scene(C);
1486 ARegion *ar= CTX_wm_region(C);
1488 outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_selectability_cb);
1490 ED_region_tag_redraw(ar);
1492 return OPERATOR_FINISHED;
1495 void OUTLINER_OT_selectability_toggle(wmOperatorType *ot)
1498 ot->name= "Toggle Selectability";
1499 ot->idname= "OUTLINER_OT_selectability_toggle";
1500 ot->description= "Toggle the selectability";
1503 ot->exec= outliner_toggle_selectability_exec;
1504 ot->poll= ED_operator_outliner_active;
1506 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1511 void object_toggle_renderability_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1513 Base *base= (Base *)te->directdata;
1515 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1517 base->object->restrictflag^=OB_RESTRICT_RENDER;
1521 static int outliner_toggle_renderability_exec(bContext *C, wmOperator *op)
1523 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
1524 Scene *scene= CTX_data_scene(C);
1525 ARegion *ar= CTX_wm_region(C);
1527 outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_renderability_cb);
1529 ED_region_tag_redraw(ar);
1531 return OPERATOR_FINISHED;
1534 void OUTLINER_OT_renderability_toggle(wmOperatorType *ot)
1537 ot->name= "Toggle Renderability";
1538 ot->idname= "OUTLINER_OT_renderability_toggle";
1539 ot->description= "Toggle the renderbility of selected items.";
1542 ot->exec= outliner_toggle_renderability_exec;
1543 ot->poll= ED_operator_outliner_active;
1545 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1550 static int outliner_toggle_expanded_exec(bContext *C, wmOperator *op)
1552 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
1553 ARegion *ar= CTX_wm_region(C);
1555 if (outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1))
1556 outliner_set_flag(soops, &soops->tree, TSE_CLOSED, 0);
1558 outliner_set_flag(soops, &soops->tree, TSE_CLOSED, 1);
1560 ED_region_tag_redraw(ar);
1562 return OPERATOR_FINISHED;
1565 void OUTLINER_OT_expanded_toggle(wmOperatorType *ot)
1568 ot->name= "Expand/Collapse All";
1569 ot->idname= "OUTLINER_OT_expanded_toggle";
1570 ot->description= "Expand/Collapse all items.";
1573 ot->exec= outliner_toggle_expanded_exec;
1574 ot->poll= ED_operator_outliner_active;
1576 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1581 static int outliner_toggle_selected_exec(bContext *C, wmOperator *op)
1583 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
1584 ARegion *ar= CTX_wm_region(C);
1586 if (outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1))
1587 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
1589 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 1);
1591 soops->storeflag |= SO_TREESTORE_REDRAW;
1593 ED_region_tag_redraw(ar);
1595 return OPERATOR_FINISHED;
1598 void OUTLINER_OT_selected_toggle(wmOperatorType *ot)
1601 ot->name= "Toggle Selected";
1602 ot->idname= "OUTLINER_OT_selected_toggle";
1603 ot->description= "Toggle the Outliner selection of items.";
1606 ot->exec= outliner_toggle_selected_exec;
1607 ot->poll= ED_operator_outliner_active;
1609 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1614 /* helper function for Show/Hide one level operator */
1615 static void outliner_openclose_level(SpaceOops *soops, ListBase *lb, int curlevel, int level, int open)
1618 TreeStoreElem *tselem;
1620 for(te= lb->first; te; te= te->next) {
1621 tselem= TREESTORE(te);
1624 if(curlevel<=level) tselem->flag &= ~TSE_CLOSED;
1627 if(curlevel>=level) tselem->flag |= TSE_CLOSED;
1630 outliner_openclose_level(soops, &te->subtree, curlevel+1, level, open);
1634 static int outliner_one_level_exec(bContext *C, wmOperator *op)
1636 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
1637 ARegion *ar= CTX_wm_region(C);
1638 int add= RNA_boolean_get(op->ptr, "open");
1641 level= outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1);
1643 if(level) outliner_openclose_level(soops, &soops->tree, 1, level, 1);
1646 if(level==0) level= outliner_count_levels(soops, &soops->tree, 0);
1647 if(level) outliner_openclose_level(soops, &soops->tree, 1, level-1, 0);
1650 ED_region_tag_redraw(ar);
1652 return OPERATOR_FINISHED;
1655 void OUTLINER_OT_show_one_level(wmOperatorType *ot)
1658 ot->name= "Show/Hide One Level";
1659 ot->idname= "OUTLINER_OT_show_one_level";
1662 ot->exec= outliner_one_level_exec;
1663 ot->poll= ED_operator_outliner_active;
1665 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1668 RNA_def_boolean(ot->srna, "open", 1, "Open", "Expand all entries one level deep.");
1671 /* return 1 when levels were opened */
1672 static int outliner_open_back(SpaceOops *soops, TreeElement *te)
1674 TreeStoreElem *tselem;
1677 for (te= te->parent; te; te= te->parent) {
1678 tselem= TREESTORE(te);
1679 if (tselem->flag & TSE_CLOSED) {
1680 tselem->flag &= ~TSE_CLOSED;
1687 /* This is not used anywhere at the moment */
1689 static void outliner_open_reveal(SpaceOops *soops, ListBase *lb, TreeElement *teFind, int *found)
1692 TreeStoreElem *tselem;
1694 for (te= lb->first; te; te= te->next) {
1695 /* check if this tree-element was the one we're seeking */
1701 /* try to see if sub-tree contains it then */
1702 outliner_open_reveal(soops, &te->subtree, teFind, found);
1704 tselem= TREESTORE(te);
1705 if (tselem->flag & TSE_CLOSED)
1706 tselem->flag &= ~TSE_CLOSED;
1713 // XXX just use View2D ops for this?
1714 void outliner_page_up_down(Scene *scene, ARegion *ar, SpaceOops *soops, int up)
1716 int dy= ar->v2d.mask.ymax-ar->v2d.mask.ymin;
1718 if(up == -1) dy= -dy;
1719 ar->v2d.cur.ymin+= dy;
1720 ar->v2d.cur.ymax+= dy;
1722 soops->storeflag |= SO_TREESTORE_REDRAW;
1725 /* **** do clicks on items ******* */
1727 static int tree_element_active_renderlayer(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
1731 /* paranoia check */
1732 if(te->idcode!=ID_SCE)
1734 sce= (Scene *)tselem->id;
1737 sce->r.actlay= tselem->nr;
1738 WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, sce);
1741 return sce->r.actlay==tselem->nr;
1746 static void tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1748 TreeStoreElem *tselem= TREESTORE(te);
1753 /* if id is not object, we search back */
1754 if(te->idcode==ID_OB) ob= (Object *)tselem->id;
1756 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1757 if(ob==OBACT) return;
1759 if(ob==NULL) return;
1761 sce= (Scene *)outliner_search_back(soops, te, ID_SCE);
1762 if(sce && scene != sce) {
1763 ED_screen_set_scene(C, sce);
1766 /* find associated base in current scene */
1767 for(base= FIRSTBASE; base; base= base->next)
1768 if(base->object==ob) break;
1772 if(base->flag & SELECT)
1773 ED_base_object_select(base, BA_DESELECT);
1775 ED_base_object_select(base, BA_SELECT);
1779 /* deleselect all */
1780 for(b= FIRSTBASE; b; b= b->next) {
1782 b->object->flag= b->flag;
1784 ED_base_object_select(base, BA_SELECT);
1787 ED_base_object_activate(C, base); /* adds notifier */
1790 if(ob!=scene->obedit)
1791 ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
1793 WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
1797 static int tree_element_active_material(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1802 /* we search for the object parent */
1803 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1804 if(ob==NULL || ob!=OBACT) return 0; // just paranoia
1806 /* searching in ob mat array? */
1808 if(tes->idcode==ID_OB) {
1810 ob->actcol= te->index+1;
1811 ob->matbits[te->index]= 1; // make ob material active too
1812 ob->colbits |= (1<<te->index);
1815 if(ob->actcol == te->index+1)
1816 if(ob->matbits[te->index]) return 1;
1819 /* or we search for obdata material */
1822 ob->actcol= te->index+1;
1823 ob->matbits[te->index]= 0; // make obdata material active too
1824 ob->colbits &= ~(1<<te->index);
1827 if(ob->actcol == te->index+1)
1828 if(ob->matbits[te->index]==0) return 1;
1832 WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING, NULL);
1837 static int tree_element_active_texture(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1840 TreeStoreElem *tselem, *tselemp;
1842 SpaceButs *sbuts=NULL;
1844 if(ob==NULL) return 0; // no active object
1846 tselem= TREESTORE(te);
1848 /* find buttons area (note, this is undefined really still, needs recode in blender) */
1849 /* XXX removed finding sbuts */
1851 /* where is texture linked to? */
1853 tselemp= TREESTORE(tep);
1855 if(tep->idcode==ID_WO) {
1856 World *wrld= (World *)tselemp->id;
1860 // XXX sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1861 // XXX sbuts->texfrom= 1;
1863 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1864 wrld->texact= te->index;
1866 else if(tselemp->id == (ID *)(scene->world)) {
1867 if(wrld->texact==te->index) return 1;
1870 else if(tep->idcode==ID_LA) {
1871 Lamp *la= (Lamp *)tselemp->id;
1874 // XXX sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1875 // XXX sbuts->texfrom= 2;
1877 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1878 la->texact= te->index;
1881 if(tselemp->id == ob->data) {
1882 if(la->texact==te->index) return 1;
1886 else if(tep->idcode==ID_MA) {
1887 Material *ma= (Material *)tselemp->id;
1890 //sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1891 // XXX sbuts->texfrom= 0;
1893 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1894 ma->texact= (char)te->index;
1896 /* also set active material */
1897 ob->actcol= tep->index+1;
1899 else if(tep->flag & TE_ACTIVE) { // this is active material
1900 if(ma->texact==te->index) return 1;
1908 static int tree_element_active_lamp(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1912 /* we search for the object parent */
1913 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1914 if(ob==NULL || ob!=OBACT) return 0; // just paranoia
1917 // XXX extern_set_butspace(F5KEY, 0);
1924 static int tree_element_active_world(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1927 TreeStoreElem *tselem=NULL;
1932 tselem= TREESTORE(tep);
1933 sce= (Scene *)tselem->id;
1936 if(set) { // make new scene active
1937 if(sce && scene != sce) {
1938 ED_screen_set_scene(C, sce);
1942 if(tep==NULL || tselem->id == (ID *)scene) {
1944 // XXX extern_set_butspace(F8KEY, 0);
1953 static int tree_element_active_defgroup(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1957 /* id in tselem is object */
1958 ob= (Object *)tselem->id;
1960 ob->actdef= te->index+1;
1961 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
1962 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
1966 if(ob->actdef== te->index+1) return 1;
1971 static int tree_element_active_posegroup(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1973 Object *ob= (Object *)tselem->id;
1977 ob->pose->active_group= te->index+1;
1978 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
1982 if(ob==OBACT && ob->pose) {
1983 if (ob->pose->active_group== te->index+1) return 1;
1989 static int tree_element_active_posechannel(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1991 Object *ob= (Object *)tselem->id;
1992 bPoseChannel *pchan= te->directdata;
1995 if(!(pchan->bone->flag & BONE_HIDDEN_P)) {
1997 if(set==2) ED_pose_deselectall(ob, 2, 0); // 2 = clear active tag
1998 else ED_pose_deselectall(ob, 0, 0); // 0 = deselect
2000 if(set==2 && (pchan->bone->flag & BONE_SELECTED))
2001 pchan->bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE);
2003 pchan->bone->flag |= BONE_SELECTED|BONE_ACTIVE;
2005 WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, ob);
2010 if(ob==OBACT && ob->pose) {
2011 if (pchan->bone->flag & BONE_SELECTED) return 1;
2017 static int tree_element_active_bone(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
2019 bArmature *arm= (bArmature *)tselem->id;
2020 Bone *bone= te->directdata;
2023 if(!(bone->flag & BONE_HIDDEN_P)) {
2024 if(set==2) ED_pose_deselectall(OBACT, 2, 0); // 2 is clear active tag
2025 else ED_pose_deselectall(OBACT, 0, 0);
2027 if(set==2 && (bone->flag & BONE_SELECTED))
2028 bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE);
2030 bone->flag |= BONE_SELECTED|BONE_ACTIVE;
2032 WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, OBACT);
2038 if(ob && ob->data==arm) {
2039 if (bone->flag & BONE_SELECTED) return 1;
2046 /* ebones only draw in editmode armature */
2047 static int tree_element_active_ebone(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
2049 EditBone *ebone= te->directdata;
2052 if(!(ebone->flag & BONE_HIDDEN_A)) {
2054 if(set==2) ED_armature_deselectall(scene->obedit, 2, 0); // only clear active tag
2055 else ED_armature_deselectall(scene->obedit, 0, 0); // deselect
2057 ebone->flag |= BONE_SELECTED|BONE_ROOTSEL|BONE_TIPSEL|BONE_ACTIVE;
2059 if(ebone->parent && (ebone->flag & BONE_CONNECTED)) ebone->parent->flag |= BONE_TIPSEL;
2061 WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, scene->obedit);
2065 if (ebone->flag & BONE_SELECTED) return 1;
2070 static int tree_element_active_modifier(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
2073 Object *ob= (Object *)tselem->id;
2075 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
2077 // XXX extern_set_butspace(F9KEY, 0);
2083 static int tree_element_active_psys(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
2086 Object *ob= (Object *)tselem->id;
2087 ParticleSystem *psys= te->directdata;
2089 PE_change_act_psys(scene, ob, psys);
2090 WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob);
2092 // XXX extern_set_butspace(F7KEY, 0);
2098 static int tree_element_active_constraint(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
2101 Object *ob= (Object *)tselem->id;
2103 WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
2104 // XXX extern_set_butspace(F7KEY, 0);
2110 static int tree_element_active_text(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
2116 /* generic call for ID data check or make/check active in UI */
2117 static int tree_element_active(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
2120 switch(te->idcode) {
2122 return tree_element_active_material(C, scene, soops, te, set);
2124 return tree_element_active_world(C, scene, soops, te, set);
2126 return tree_element_active_lamp(C, scene, soops, te, set);
2128 return tree_element_active_texture(C, scene, soops, te, set);
2130 return tree_element_active_text(C, scene, soops, te, set);
2135 static int tree_element_active_pose(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
2137 Object *ob= (Object *)tselem->id;
2138 Base *base= object_in_scene(ob, scene);
2142 ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2144 if(ob->flag & OB_POSEMODE)
2145 ED_armature_exit_posemode(C, base);
2147 ED_armature_enter_posemode(C, base);
2150 if(ob->flag & OB_POSEMODE) return 1;
2155 static int tree_element_active_sequence(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
2157 Sequence *seq= (Sequence*) te->directdata;
2160 // XXX select_single_seq(seq, 1);
2163 if(seq->flag & SELECT)
2169 static int tree_element_active_sequence_dup(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
2172 Editing *ed= seq_give_editing(scene, FALSE);
2174 seq= (Sequence*)te->directdata;
2176 if(seq->flag & SELECT)
2181 // XXX select_single_seq(seq, 1);
2182 p= ed->seqbasep->first;
2184 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
2189 // if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
2190 // XXX select_single_seq(p, 0);
2196 /* generic call for non-id data to make/check active in UI */
2197 /* Context can be NULL when set==0 */
2198 static int tree_element_type_active(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, int set)
2201 switch(tselem->type) {
2203 return tree_element_active_defgroup(C, scene, te, tselem, set);
2205 return tree_element_active_bone(C, scene, te, tselem, set);
2207 return tree_element_active_ebone(C, scene, te, tselem, set);
2209 return tree_element_active_modifier(C, te, tselem, set);
2211 if(set) tree_element_set_active_object(C, scene, soops, te, set);
2212 else if(tselem->id==(ID *)OBACT) return 1;
2214 case TSE_LINKED_PSYS:
2215 return tree_element_active_psys(C, scene, te, tselem, set);
2218 return tree_element_active_pose(C, scene, te, tselem, set);
2220 case TSE_POSE_CHANNEL:
2221 return tree_element_active_posechannel(C, scene, te, tselem, set);
2222 case TSE_CONSTRAINT:
2223 return tree_element_active_constraint(C, te, tselem, set);
2225 return tree_element_active_renderlayer(C, te, tselem, set);
2227 return tree_element_active_posegroup(C, scene, te, tselem, set);
2229 return tree_element_active_sequence(C, te, tselem, set);
2231 case TSE_SEQUENCE_DUP:
2232 return tree_element_active_sequence_dup(C, scene, te, tselem, set);
2238 static int do_outliner_item_activate(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int extend, float *mval)
2241 if(mval[1]>te->ys && mval[1]<te->ys+OL_H) {
2242 TreeStoreElem *tselem= TREESTORE(te);
2245 /* open close icon */
2246 if((te->flag & TE_ICONROW)==0) { // hidden icon, no open/close
2247 if( mval[0]>te->xs && mval[0]<te->xs+OL_X)
2252 /* all below close/open? */
2254 tselem->flag &= ~TSE_CLOSED;
2255 outliner_set_flag(soops, &te->subtree, TSE_CLOSED, !outliner_has_one_flag(soops, &te->subtree, TSE_CLOSED, 1));
2258 if(tselem->flag & TSE_CLOSED) tselem->flag &= ~TSE_CLOSED;
2259 else tselem->flag |= TSE_CLOSED;
2262 soops->storeflag |= SO_TREESTORE_REDRAW;
2266 /* name and first icon */
2267 else if(mval[0]>te->xs && mval[0]<te->xend) {
2269 /* always makes active object */
2270 if(tselem->type!=TSE_SEQUENCE && tselem->type!=TSE_SEQ_STRIP && tselem->type!=TSE_SEQUENCE_DUP)
2271 tree_element_set_active_object(C, scene, soops, te, 1 + (extend!=0 && tselem->type==0));
2273 if(tselem->type==0) { // the lib blocks
2275 if(te->idcode==ID_SCE) {
2276 if(scene!=(Scene *)tselem->id) {
2277 ED_screen_set_scene(C, (Scene *)tselem->id);
2280 else if(ELEM5(te->idcode, ID_ME, ID_CU, ID_MB, ID_LT, ID_AR)) {
2281 Object *obedit= CTX_data_edit_object(C);
2283 ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2285 ED_object_enter_editmode(C, EM_WAITCURSOR);
2286 // XXX extern_set_butspace(F9KEY, 0);
2288 } else { // rest of types
2289 tree_element_active(C, scene, soops, te, 1);
2293 else tree_element_type_active(C, scene, soops, te, tselem, 1+(extend!=0));
2299 for(te= te->subtree.first; te; te= te->next) {
2300 if(do_outliner_item_activate(C, scene, ar, soops, te, extend, mval)) return 1;
2305 /* event can enterkey, then it opens/closes */
2306 static int outliner_item_activate(bContext *C, wmOperator *op, wmEvent *event)
2308 Scene *scene= CTX_data_scene(C);
2309 ARegion *ar= CTX_wm_region(C);
2310 SpaceOops *soops= (SpaceOops*)CTX_wm_space_data(C);
2313 int extend= RNA_boolean_get(op->ptr, "extend");
2315 UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, fmval, fmval+1);
2317 for(te= soops->tree.first; te; te= te->next) {
2318 if(do_outliner_item_activate(C, scene, ar, soops, te, extend, fmval)) break;
2322 ED_undo_push(C, "Outliner click event");
2325 short selecting= -1;
2328 /* get row number - 100 here is just a dummy value since we don't need the column */
2329 UI_view2d_listview_view_to_cell(&ar->v2d, 1000, OL_H, 0.0f, 0.0f,
2330 fmval[0], fmval[1], NULL, &row);
2332 /* select relevant row */
2333 outliner_select(soops, &soops->tree, &row, &selecting);
2335 soops->storeflag |= SO_TREESTORE_REDRAW;
2337 ED_undo_push(C, "Outliner selection event");
2340 ED_region_tag_redraw(ar);
2342 return OPERATOR_FINISHED;
2345 void OUTLINER_OT_item_activate(wmOperatorType *ot)
2347 ot->name= "Activate Item";
2348 ot->idname= "OUTLINER_OT_item_activate";
2350 ot->invoke= outliner_item_activate;
2352 ot->poll= ED_operator_outliner_active;
2354 RNA_def_boolean(ot->srna, "extend", 1, "Extend", "Extend selection for activation.");
2359 static int do_outliner_item_openclose(bContext *C, SpaceOops *soops, TreeElement *te, int all, float *mval)
2362 if(mval[1]>te->ys && mval[1]<te->ys+OL_H) {
2363 TreeStoreElem *tselem= TREESTORE(te);
2365 /* all below close/open? */
2367 tselem->flag &= ~TSE_CLOSED;
2368 outliner_set_flag(soops, &te->subtree, TSE_CLOSED, !outliner_has_one_flag(soops, &te->subtree, TSE_CLOSED, 1));
2371 if(tselem->flag & TSE_CLOSED) tselem->flag &= ~TSE_CLOSED;
2372 else tselem->flag |= TSE_CLOSED;
2375 soops->storeflag |= SO_TREESTORE_REDRAW;
2380 for(te= te->subtree.first; te; te= te->next) {
2381 if(do_outliner_item_openclose(C, soops, te, all, mval))
2388 /* event can enterkey, then it opens/closes */
2389 static int outliner_item_openclose(bContext *C, wmOperator *op, wmEvent *event)
2391 ARegion *ar= CTX_wm_region(C);
2392 SpaceOops *soops= (SpaceOops*)CTX_wm_space_data(C);
2395 int all= RNA_boolean_get(op->ptr, "all");
2397 UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, fmval, fmval+1);
2399 for(te= soops->tree.first; te; te= te->next) {
2400 if(do_outliner_item_openclose(C, soops, te, all, fmval))
2404 ED_region_tag_redraw(ar);
2406 return OPERATOR_FINISHED;
2409 void OUTLINER_OT_item_openclose(wmOperatorType *ot)
2411 ot->name= "Open/Close Item";
2412 ot->idname= "OUTLINER_OT_item_openclose";
2414 ot->invoke= outliner_item_openclose;
2416 ot->poll= ED_operator_outliner_active;
2418 RNA_def_boolean(ot->srna, "all", 1, "All", "Close or open all items.");
2423 /* ********************************************** */
2425 static int do_outliner_item_rename(bContext *C, ARegion *ar, SpaceOops *soops, TreeElement *te, float *mval)
2428 if(mval[1]>te->ys && mval[1]<te->ys+OL_H) {
2429 TreeStoreElem *tselem= TREESTORE(te);
2431 /* name and first icon */
2432 if(mval[0]>te->xs && mval[0]<te->xend) {
2434 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))
2435 error("Cannot edit builtin name");
2436 else if(ELEM3(tselem->type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP))
2437 error("Cannot edit sequence name");
2438 else if(tselem->id->lib) {
2439 // XXX error_libdata();
2440 } else if(te->idcode == ID_LI && te->parent) {
2441 error("Cannot edit the path of an indirectly linked library");
2443 tselem->flag |= TSE_TEXTBUT;
2444 ED_region_tag_redraw(ar);
2450 for(te= te->subtree.first; te; te= te->next) {
2451 if(do_outliner_item_rename(C, ar, soops, te, mval)) return 1;
2456 static int outliner_item_rename(bContext *C, wmOperator *op, wmEvent *event)
2458 ARegion *ar= CTX_wm_region(C);
2459 SpaceOops *soops= (SpaceOops*)CTX_wm_space_data(C);
2463 UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, fmval, fmval+1);
2465 for(te= soops->tree.first; te; te= te->next) {
2466 if(do_outliner_item_rename(C, ar, soops, te, fmval)) break;
2469 return OPERATOR_FINISHED;
2473 void OUTLINER_OT_item_rename(wmOperatorType *ot)
2475 ot->name= "Rename Item";
2476 ot->idname= "OUTLINER_OT_item_rename";
2478 ot->invoke= outliner_item_rename;
2480 ot->poll= ED_operator_outliner_active;
2485 /* recursive helper for function below */
2486 static void outliner_set_coordinates_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
2488 TreeStoreElem *tselem= TREESTORE(te);
2490 /* store coord and continue, we need coordinates for elements outside view too */
2491 te->xs= (float)startx;
2492 te->ys= (float)(*starty);
2495 if((tselem->flag & TSE_CLOSED)==0) {
2497 for(ten= te->subtree.first; ten; ten= ten->next) {
2498 outliner_set_coordinates_element(soops, ten, startx+OL_X, starty);
2504 /* to retrieve coordinates with redrawing the entire tree */
2505 static void outliner_set_coordinates(ARegion *ar, SpaceOops *soops)
2508 int starty= (int)(ar->v2d.tot.ymax)-OL_H;
2511 for(te= soops->tree.first; te; te= te->next) {
2512 outliner_set_coordinates_element(soops, te, startx, &starty);
2516 static TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, ID *id)
2518 TreeElement *te, *tes;
2519 TreeStoreElem *tselem;
2521 for(te= lb->first; te; te= te->next) {
2522 tselem= TREESTORE(te);
2523 if(tselem->type==0) {
2524 if(tselem->id==id) return te;
2525 /* only deeper on scene or object */
2526 if( te->idcode==ID_OB || te->idcode==ID_SCE) {
2527 tes= outliner_find_id(soops, &te->subtree, id);
2535 static int outliner_show_active_exec(bContext *C, wmOperator *op)
2537 SpaceOops *so= (SpaceOops *)CTX_wm_space_data(C);
2538 Scene *scene= CTX_data_scene(C);
2539 ARegion *ar= CTX_wm_region(C);
2540 View2D *v2d= &ar->v2d;
2545 // TODO: make this get this info from context instead...
2547 return OPERATOR_CANCELLED;
2549 te= outliner_find_id(so, &so->tree, (ID *)OBACT);
2551 /* make te->ys center of view */
2552 ytop= (int)(te->ys + (v2d->mask.ymax - v2d->mask.ymin)/2);
2553 if (ytop>0) ytop= 0;
2555 v2d->cur.ymax= (float)ytop;
2556 v2d->cur.ymin= (float)(ytop-(v2d->mask.ymax - v2d->mask.ymin));
2558 /* make te->xs ==> te->xend center of view */
2559 xdelta = (int)(te->xs - v2d->cur.xmin);
2560 v2d->cur.xmin += xdelta;
2561 v2d->cur.xmax += xdelta;
2563 so->storeflag |= SO_TREESTORE_REDRAW;
2566 ED_region_tag_redraw(ar);
2568 return OPERATOR_FINISHED;
2571 void OUTLINER_OT_show_active(wmOperatorType *ot)
2574 ot->name= "Show Active";
2575 ot->idname= "OUTLINER_OT_show_active";
2576 ot->description= "Adjust the view so that the active Object is shown centered.";
2579 ot->exec= outliner_show_active_exec;
2580 ot->poll= ED_operator_outliner_active;
2582 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2585 /* find next element that has this name */
2586 static TreeElement *outliner_find_named(SpaceOops *soops, ListBase *lb, char *name, int flags, TreeElement *prev, int *prevFound)
2588 TreeElement *te, *tes;
2590 for (te= lb->first; te; te= te->next) {
2593 /* determine if match */
2595 found= BLI_strcasestr(te->name, name)!=NULL;
2596 else if(flags==OL_FIND_CASE)
2597 found= strstr(te->name, name)!=NULL;
2598 else if(flags==OL_FIND_COMPLETE)
2599 found= BLI_strcasecmp(te->name, name)==0;
2601 found= strcmp(te->name, name)==0;
2604 /* name is right, but is element the previous one? */
2606 if ((te != prev) && (*prevFound))
2616 tes= outliner_find_named(soops, &te->subtree, name, flags, prev, prevFound);
2620 /* nothing valid found */
2624 /* tse is not in the treestore, we use its contents to find a match */
2625 static TreeElement *outliner_find_tse(SpaceOops *soops, TreeStoreElem *tse)
2627 TreeStore *ts= soops->treestore;
2628 TreeStoreElem *tselem;
2631 if(tse->id==NULL) return NULL;
2633 /* check if 'tse' is in treestore */
2635 for(a=0; a<ts->usedelem; a++, tselem++) {
2636 if((tse->type==0 && tselem->type==0) || (tselem->type==tse->type && tselem->nr==tse->nr)) {
2637 if(tselem->id==tse->id) {
2643 return outliner_find_tree_element(&soops->tree, a);
2649 /* Called to find an item based on name.
2651 void outliner_find_panel(Scene *scene, ARegion *ar, SpaceOops *soops, int again, int flags)
2653 TreeElement *te= NULL;
2654 TreeElement *last_find;
2655 TreeStoreElem *tselem;
2656 int ytop, xdelta, prevFound=0;
2659 /* get last found tree-element based on stored search_tse */
2660 last_find= outliner_find_tse(soops, &soops->search_tse);
2662 /* determine which type of search to do */
2663 if (again && last_find) {
2664 /* no popup panel - previous + user wanted to search for next after previous */
2665 BLI_strncpy(name, soops->search_string, 33);
2666 flags= soops->search_flags;
2668 /* try to find matching element */
2669 te= outliner_find_named(soops, &soops->tree, name, flags, last_find, &prevFound);
2671 /* no more matches after previous, start from beginning again */
2673 te= outliner_find_named(soops, &soops->tree, name, flags, last_find, &prevFound);
2677 /* pop up panel - no previous, or user didn't want search after previous */
2679 // XXX if (sbutton(name, 0, sizeof(name)-1, "Find: ") && name[0]) {
2680 // te= outliner_find_named(soops, &soops->tree, name, flags, NULL, &prevFound);
2682 // else return; /* XXX RETURN! XXX */
2685 /* do selection and reveal */
2687 tselem= TREESTORE(te);
2689 /* expand branches so that it will be visible, we need to get correct coordinates */
2690 if( outliner_open_back(soops, te))
2691 outliner_set_coordinates(ar, soops);
2693 /* deselect all visible, and select found element */
2694 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
2695 tselem->flag |= TSE_SELECTED;
2697 /* make te->ys center of view */
2698 ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
2700 ar->v2d.cur.ymax= (float)ytop;
2701 ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
2703 /* make te->xs ==> te->xend center of view */
2704 xdelta = (int)(te->xs - ar->v2d.cur.xmin);
2705 ar->v2d.cur.xmin += xdelta;
2706 ar->v2d.cur.xmax += xdelta;
2708 /* store selection */
2709 soops->search_tse= *tselem;
2711 BLI_strncpy(soops->search_string, name, 33);
2712 soops->search_flags= flags;
2715 soops->storeflag |= SO_TREESTORE_REDRAW;
2719 /* no tree-element found */
2720 error("Not found: %s", name);
2724 /* helper function for tree_element_shwo_hierarchy() - recursively checks whether subtrees have any objects*/
2725 static int subtree_has_objects(SpaceOops *soops, ListBase *lb)
2728 TreeStoreElem *tselem;
2730 for(te= lb->first; te; te= te->next) {
2731 tselem= TREESTORE(te);
2732 if(tselem->type==0 && te->idcode==ID_OB) return 1;
2733 if( subtree_has_objects(soops, &te->subtree)) return 1;
2738 /* recursive helper function for Show Hierarchy operator */
2739 static void tree_element_show_hierarchy(Scene *scene, SpaceOops *soops, ListBase *lb)
2742 TreeStoreElem *tselem;
2744 /* open all object elems, close others */
2745 for(te= lb->first; te; te= te->next) {
2746 tselem= TREESTORE(te);
2748 if(tselem->type==0) {
2749 if(te->idcode==ID_SCE) {
2750 if(tselem->id!=(ID *)scene) tselem->flag |= TSE_CLOSED;
2751 else tselem->flag &= ~TSE_CLOSED;
2753 else if(te->idcode==ID_OB) {
2754 if(subtree_has_objects(soops, &te->subtree)) tselem->flag &= ~TSE_CLOSED;
2755 else tselem->flag |= TSE_CLOSED;
2758 else tselem->flag |= TSE_CLOSED;
2760 if(tselem->flag & TSE_CLOSED); else tree_element_show_hierarchy(scene, soops, &te->subtree);
2764 /* show entire object level hierarchy */
2765 static int outliner_show_hierarchy_exec(bContext *C, wmOperator *op)
2767 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
2768 ARegion *ar= CTX_wm_region(C);
2769 Scene *scene= CTX_data_scene(C);
2771 /* recursively open/close levels */
2772 tree_element_show_hierarchy(scene, soops, &soops->tree);
2774 ED_region_tag_redraw(ar);
2776 return OPERATOR_FINISHED;
2779 void OUTLINER_OT_show_hierarchy(wmOperatorType *ot)
2782 ot->name= "Show Hierarchy";
2783 ot->idname= "OUTLINER_OT_show_hierarchy";
2784 ot->description= "Open all object entries and close all others.";
2787 ot->exec= outliner_show_hierarchy_exec;
2788 ot->poll= ED_operator_outliner_active; // TODO: shouldn't be allowed in RNA views...
2790 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2793 void outliner_select(SpaceOops *soops, ListBase *lb, int *index, short *selecting)
2796 TreeStoreElem *tselem;
2798 for (te= lb->first; te && *index >= 0; te=te->next, (*index)--) {
2799 tselem= TREESTORE(te);
2801 /* if we've encountered the right item, set its 'Outliner' selection status */
2803 /* this should be the last one, so no need to do anything with index */
2804 if ((te->flag & TE_ICONROW)==0) {
2805 /* -1 value means toggle testing for now... */
2806 if (*selecting == -1) {
2807 if (tselem->flag & TSE_SELECTED)
2815 tselem->flag |= TSE_SELECTED;
2817 tselem->flag &= ~TSE_SELECTED;
2820 else if ((tselem->flag & TSE_CLOSED)==0) {
2821 /* Only try selecting sub-elements if we haven't hit the right element yet
2824 * Index must be reduced before supplying it to the sub-tree to try to do
2825 * selection, however, we need to increment it again for the next loop to
2826 * function correctly
2829 outliner_select(soops, &te->subtree, index, selecting);
2835 /* ************ SELECTION OPERATIONS ********* */
2837 static void set_operation_types(SpaceOops *soops, ListBase *lb,
2844 TreeStoreElem *tselem;
2846 for(te= lb->first; te; te= te->next) {
2847 tselem= TREESTORE(te);
2848 if(tselem->flag & TSE_SELECTED) {
2851 *datalevel= tselem->type;
2852 else if(*datalevel!=tselem->type)
2856 int idcode= GS(tselem->id->name);
2865 case ID_ME: case ID_CU: case ID_MB: case ID_LT:
2866 case ID_LA: case ID_AR: case ID_CA:
2867 case ID_MA: case ID_TE: case ID_IP: case ID_IM:
2868 case ID_SO: case ID_KE: case ID_WO: case ID_AC:
2869 case ID_NLA: case ID_TXT: case ID_GR:
2870 if(*idlevel==0) *idlevel= idcode;
2871 else if(*idlevel!=idcode) *idlevel= -1;
2876 if((tselem->flag & TSE_CLOSED)==0) {
2877 set_operation_types(soops, &te->subtree,
2878 scenelevel, objectlevel, idlevel, datalevel);
2883 static void unlink_material_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2885 Material **matar=NULL;
2888 if( GS(tsep->id->name)==ID_OB) {