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_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"
100 #include "RNA_access.h"
101 #include "RNA_define.h"
103 #include "ED_armature.h"
104 #include "ED_keyframing.h"
105 #include "ED_object.h"
106 #include "ED_screen.h"
108 #include "outliner_intern.h"
110 #include "PIL_time.h"
116 #define OL_TOG_RESTRICT_VIEWX 54
117 #define OL_TOG_RESTRICT_SELECTX 36
118 #define OL_TOG_RESTRICT_RENDERX 18
120 #define OL_TOGW OL_TOG_RESTRICT_VIEWX
122 #define OL_RNA_COLX 300
123 #define OL_RNA_COL_SIZEX 150
124 #define OL_RNA_COL_SPACEX 50
128 #define TREESTORE(a) ((a)?soops->treestore->data+(a)->store_index:NULL)
130 /* ************* XXX **************** */
132 static void BIF_undo_push() {}
133 static void BIF_preview_changed() {}
134 static void error() {}
135 static int pupmenu() {return 0;}
137 /* ********************************** */
140 /* ******************** PROTOTYPES ***************** */
141 static void outliner_draw_tree_element(Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty);
142 static void outliner_do_object_operation(Scene *scene, SpaceOops *soops, ListBase *lb,
143 void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *));
146 /* ******************** PERSISTANT DATA ***************** */
148 static void outliner_storage_cleanup(SpaceOops *soops)
150 TreeStore *ts= soops->treestore;
153 TreeStoreElem *tselem;
156 /* each element used once, for ID blocks with more users to have each a treestore */
157 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) tselem->used= 0;
159 /* cleanup only after reading file or undo step, and always for
160 * RNA datablocks view in order to save memory */
161 if(soops->storeflag & SO_TREESTORE_CLEANUP) {
163 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) {
164 if(tselem->id==NULL) unused++;
168 if(ts->usedelem == unused) {
171 ts->usedelem= ts->totelem= 0;
174 TreeStoreElem *tsnewar, *tsnew;
176 tsnew=tsnewar= MEM_mallocN((ts->usedelem-unused)*sizeof(TreeStoreElem), "new tselem");
177 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) {
185 ts->usedelem-= unused;
186 ts->totelem= ts->usedelem;
193 static void check_persistant(SpaceOops *soops, TreeElement *te, ID *id, short type, short nr)
196 TreeStoreElem *tselem;
199 /* case 1; no TreeStore */
200 if(soops->treestore==NULL) {
201 ts= soops->treestore= MEM_callocN(sizeof(TreeStore), "treestore");
203 ts= soops->treestore;
205 /* check if 'te' is in treestore */
207 for(a=0; a<ts->usedelem; a++, tselem++) {
208 if(tselem->id==id && tselem->used==0) {
209 if((type==0 && tselem->type==0) ||(tselem->type==type && tselem->nr==nr)) {
217 /* add 1 element to treestore */
218 if(ts->usedelem==ts->totelem) {
219 TreeStoreElem *tsnew;
221 tsnew= MEM_mallocN((ts->totelem+TS_CHUNK)*sizeof(TreeStoreElem), "treestore data");
223 memcpy(tsnew, ts->data, ts->totelem*sizeof(TreeStoreElem));
227 ts->totelem+= TS_CHUNK;
230 tselem= ts->data+ts->usedelem;
233 if(type) tselem->nr= nr; // we're picky! :)
237 tselem->flag= TSE_CLOSED;
238 te->store_index= ts->usedelem;
243 /* ******************** TREE MANAGEMENT ****************** */
245 void outliner_free_tree(ListBase *lb)
249 TreeElement *te= lb->first;
251 outliner_free_tree(&te->subtree);
254 if(te->flag & TE_FREE_NAME) MEM_freeN(te->name);
259 static void outliner_height(SpaceOops *soops, ListBase *lb, int *h)
261 TreeElement *te= lb->first;
263 TreeStoreElem *tselem= TREESTORE(te);
264 if((tselem->flag & TSE_CLOSED)==0)
265 outliner_height(soops, &te->subtree, h);
271 #if 0 // XXX this is currently disabled until te->xend is set correctly
272 static void outliner_width(SpaceOops *soops, ListBase *lb, int *w)
274 TreeElement *te= lb->first;
276 // TreeStoreElem *tselem= TREESTORE(te);
278 // XXX fixme... te->xend is not set yet
279 if(tselem->flag & TSE_CLOSED) {
283 outliner_width(soops, &te->subtree, w);
289 static void outliner_rna_width(SpaceOops *soops, ListBase *lb, int *w, int startx)
291 TreeElement *te= lb->first;
293 TreeStoreElem *tselem= TREESTORE(te);
294 // XXX fixme... (currently, we're using a fixed length of 100)!
302 if((tselem->flag & TSE_CLOSED)==0)
303 outliner_rna_width(soops, &te->subtree, w, startx+OL_X);
308 static TreeElement *outliner_find_tree_element(ListBase *lb, int store_index)
310 TreeElement *te= lb->first, *tes;
312 if(te->store_index==store_index) return te;
313 tes= outliner_find_tree_element(&te->subtree, store_index);
322 static ID *outliner_search_back(SpaceOops *soops, TreeElement *te, short idcode)
324 TreeStoreElem *tselem;
328 tselem= TREESTORE(te);
329 if(tselem->type==0 && te->idcode==idcode) return tselem->id;
342 static int treesort_alpha(const void *v1, const void *v2)
344 const struct treesort *x1= v1, *x2= v2;
347 /* first put objects last (hierarchy) */
348 comp= (x1->idcode==ID_OB);
349 if(x2->idcode==ID_OB) comp+=2;
351 if(comp==1) return 1;
352 else if(comp==2) return -1;
354 int comp= strcmp(x1->name, x2->name);
356 if( comp>0 ) return 1;
357 else if( comp<0) return -1;
363 /* this is nice option for later? doesnt look too useful... */
365 static int treesort_obtype_alpha(const void *v1, const void *v2)
367 const struct treesort *x1= v1, *x2= v2;
369 /* first put objects last (hierarchy) */
370 if(x1->idcode==ID_OB && x2->idcode!=ID_OB) return 1;
371 else if(x2->idcode==ID_OB && x1->idcode!=ID_OB) return -1;
373 /* 2nd we check ob type */
374 if(x1->idcode==ID_OB && x2->idcode==ID_OB) {
375 if( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return 1;
376 else if( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return -1;
380 int comp= strcmp(x1->name, x2->name);
382 if( comp>0 ) return 1;
383 else if( comp<0) return -1;
390 /* sort happens on each subtree individual */
391 static void outliner_sort(SpaceOops *soops, ListBase *lb)
394 TreeStoreElem *tselem;
399 tselem= TREESTORE(te);
401 /* sorting rules; only object lists or deformgroups */
402 if( (tselem->type==TSE_DEFGROUP) || (tselem->type==0 && te->idcode==ID_OB)) {
405 for(te= lb->first; te; te= te->next) totelem++;
408 struct treesort *tear= MEM_mallocN(totelem*sizeof(struct treesort), "tree sort array");
409 struct treesort *tp=tear;
412 for(te= lb->first; te; te= te->next, tp++) {
413 tselem= TREESTORE(te);
416 tp->idcode= te->idcode;
417 if(tselem->type && tselem->type!=TSE_DEFGROUP) tp->idcode= 0; // dont sort this
420 /* keep beginning of list */
421 for(tp= tear, skip=0; skip<totelem; skip++, tp++)
422 if(tp->idcode) break;
425 qsort(tear+skip, totelem-skip, sizeof(struct treesort), treesort_alpha);
427 lb->first=lb->last= NULL;
430 BLI_addtail(lb, tp->te);
437 for(te= lb->first; te; te= te->next) {
438 outliner_sort(soops, &te->subtree);
442 /* Prototype, see functions below */
443 static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv,
444 TreeElement *parent, short type, short index);
447 static void outliner_add_passes(SpaceOops *soops, TreeElement *tenla, ID *id, SceneRenderLayer *srl)
449 TreeStoreElem *tselem= TREESTORE(tenla);
452 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_COMBINED);
453 te->name= "Combined";
454 te->directdata= &srl->passflag;
456 /* save cpu cycles, but we add the first to invoke an open/close triangle */
457 if(tselem->flag & TSE_CLOSED)
460 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_Z);
462 te->directdata= &srl->passflag;
464 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_VECTOR);
466 te->directdata= &srl->passflag;
468 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_NORMAL);
470 te->directdata= &srl->passflag;
472 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_UV);
474 te->directdata= &srl->passflag;
476 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_MIST);
478 te->directdata= &srl->passflag;
480 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_INDEXOB);
481 te->name= "Index Object";
482 te->directdata= &srl->passflag;
484 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_RGBA);
486 te->directdata= &srl->passflag;
488 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_DIFFUSE);
490 te->directdata= &srl->passflag;
492 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_SPEC);
493 te->name= "Specular";
494 te->directdata= &srl->passflag;
496 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_SHADOW);
498 te->directdata= &srl->passflag;
500 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_AO);
502 te->directdata= &srl->passflag;
504 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_REFLECT);
505 te->name= "Reflection";
506 te->directdata= &srl->passflag;
508 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_REFRACT);
509 te->name= "Refraction";
510 te->directdata= &srl->passflag;
512 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_RADIO);
513 te->name= "Radiosity";
514 te->directdata= &srl->passflag;
519 /* special handling of hierarchical non-lib data */
520 static void outliner_add_bone(SpaceOops *soops, ListBase *lb, ID *id, Bone *curBone,
521 TreeElement *parent, int *a)
523 TreeElement *te= outliner_add_element(soops, lb, id, parent, TSE_BONE, *a);
526 te->name= curBone->name;
527 te->directdata= curBone;
529 for(curBone= curBone->childbase.first; curBone; curBone=curBone->next) {
530 outliner_add_bone(soops, &te->subtree, id, curBone, te, a);
534 static void outliner_add_scene_contents(SpaceOops *soops, ListBase *lb, Scene *sce, TreeElement *te)
536 SceneRenderLayer *srl;
537 TreeElement *tenla= outliner_add_element(soops, lb, sce, te, TSE_R_LAYER_BASE, 0);
540 tenla->name= "RenderLayers";
541 for(a=0, srl= sce->r.layers.first; srl; srl= srl->next, a++) {
542 TreeElement *tenlay= outliner_add_element(soops, &tenla->subtree, sce, te, TSE_R_LAYER, a);
543 tenlay->name= srl->name;
544 tenlay->directdata= &srl->passflag;
546 if(srl->light_override)
547 outliner_add_element(soops, &tenlay->subtree, srl->light_override, tenlay, TSE_LINKED_LAMP, 0);
548 if(srl->mat_override)
549 outliner_add_element(soops, &tenlay->subtree, srl->mat_override, tenlay, TSE_LINKED_MAT, 0);
551 outliner_add_passes(soops, tenlay, &sce->id, srl);
554 outliner_add_element(soops, lb, sce->world, te, 0, 0);
556 if(sce->scriptlink.scripts) {
558 tenla= outliner_add_element(soops, lb, sce, te, TSE_SCRIPT_BASE, 0);
559 tenla->name= "Scripts";
560 for (a=0; a<sce->scriptlink.totscript; a++) {
561 outliner_add_element(soops, &tenla->subtree, sce->scriptlink.scripts[a], tenla, 0, 0);
567 static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv,
568 TreeElement *parent, short type, short index)
571 TreeStoreElem *tselem;
575 if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
576 id= ((PointerRNA*)idv)->id.data;
577 if(!id) id= ((PointerRNA*)idv)->data;
580 if(id==NULL) return NULL;
582 te= MEM_callocN(sizeof(TreeElement), "tree elem");
583 /* add to the visual tree */
585 /* add to the storage */
586 check_persistant(soops, te, id, type, index);
587 tselem= TREESTORE(te);
590 te->index= index; // for data arays
591 if(ELEM3(type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP));
592 else if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM));
593 else if(type==TSE_ANIM_DATA);
595 te->name= id->name+2; // default, can be overridden by Library or non-ID data
596 te->idcode= GS(id->name);
601 /* tuck pointer back in object, to construct hierarchy */
602 if(GS(id->name)==ID_OB) id->newid= (ID *)te;
604 /* expand specific data always */
605 switch(GS(id->name)) {
607 te->name= ((Library *)id)->name;
610 outliner_add_scene_contents(soops, &te->subtree, (Scene *)id, te);
614 Object *ob= (Object *)id;
616 outliner_add_element(soops, &te->subtree, ob->adt, te, TSE_ANIM_DATA, 0);
617 outliner_add_element(soops, &te->subtree, ob->poselib, te, 0, 0); // XXX FIXME.. add a special type for this
619 if(ob->proxy && ob->id.lib==NULL)
620 outliner_add_element(soops, &te->subtree, ob->proxy, te, TSE_PROXY, 0);
622 outliner_add_element(soops, &te->subtree, ob->data, te, 0, 0);
625 bArmature *arm= ob->data;
628 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_POSE_BASE, 0);
632 if(arm->edbo==NULL && (ob->flag & OB_POSEMODE)) { // channels undefined in editmode, but we want the 'tenla' pose icon itself
633 int a= 0, const_index= 1000; /* ensure unique id for bone constraints */
635 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next, a++) {
636 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_POSE_CHANNEL, a);
637 ten->name= pchan->name;
638 ten->directdata= pchan;
639 pchan->prev= (bPoseChannel *)ten;
641 if(pchan->constraints.first) {
645 TreeElement *tenla1= outliner_add_element(soops, &ten->subtree, ob, ten, TSE_CONSTRAINT_BASE, 0);
648 tenla1->name= "Constraints";
649 for(con= pchan->constraints.first; con; con= con->next, const_index++) {
650 ten1= outliner_add_element(soops, &tenla1->subtree, ob, tenla1, TSE_CONSTRAINT, const_index);
651 #if 0 /* disabled as it needs to be reworked for recoded constraints system */
652 target= get_constraint_target(con, &str);
653 if(str && str[0]) ten1->name= str;
654 else if(target) ten1->name= target->id.name+2;
655 else ten1->name= con->name;
657 ten1->name= con->name;
658 ten1->directdata= con;
659 /* possible add all other types links? */
664 ten= tenla->subtree.first;
666 TreeElement *nten= ten->next, *par;
667 tselem= TREESTORE(ten);
668 if(tselem->type==TSE_POSE_CHANNEL) {
669 pchan= (bPoseChannel *)ten->directdata;
671 BLI_remlink(&tenla->subtree, ten);
672 par= (TreeElement *)pchan->parent->prev;
673 BLI_addtail(&par->subtree, ten);
679 /* restore prev pointers */
680 pchan= ob->pose->chanbase.first;
681 if(pchan) pchan->prev= NULL;
682 for(; pchan; pchan= pchan->next) {
683 if(pchan->next) pchan->next->prev= pchan;
688 if(ob->pose->agroups.first) {
691 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_POSEGRP_BASE, 0);
694 tenla->name= "Bone Groups";
695 for (agrp=ob->pose->agroups.first; agrp; agrp=agrp->next, a++) {
696 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_POSEGRP, a);
697 ten->name= agrp->name;
698 ten->directdata= agrp;
703 for(a=0; a<ob->totcol; a++)
704 outliner_add_element(soops, &te->subtree, ob->mat[a], te, 0, a);
706 if(ob->constraints.first) {
710 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_CONSTRAINT_BASE, 0);
714 tenla->name= "Constraints";
715 for(con= ob->constraints.first; con; con= con->next, a++) {
716 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_CONSTRAINT, a);
717 #if 0 /* disabled due to constraints system targets recode... code here needs review */
718 target= get_constraint_target(con, &str);
719 if(str && str[0]) ten->name= str;
720 else if(target) ten->name= target->id.name+2;
721 else ten->name= con->name;
723 ten->name= con->name;
724 ten->directdata= con;
725 /* possible add all other types links? */
729 if(ob->modifiers.first) {
731 TreeElement *temod = outliner_add_element(soops, &te->subtree, ob, te, TSE_MODIFIER_BASE, 0);
734 temod->name = "Modifiers";
735 for (index=0,md=ob->modifiers.first; md; index++,md=md->next) {
736 TreeElement *te = outliner_add_element(soops, &temod->subtree, ob, temod, TSE_MODIFIER, index);
740 if (md->type==eModifierType_Lattice) {
741 outliner_add_element(soops, &te->subtree, ((LatticeModifierData*) md)->object, te, TSE_LINKED_OB, 0);
742 } else if (md->type==eModifierType_Curve) {
743 outliner_add_element(soops, &te->subtree, ((CurveModifierData*) md)->object, te, TSE_LINKED_OB, 0);
744 } else if (md->type==eModifierType_Armature) {
745 outliner_add_element(soops, &te->subtree, ((ArmatureModifierData*) md)->object, te, TSE_LINKED_OB, 0);
746 } else if (md->type==eModifierType_Hook) {
747 outliner_add_element(soops, &te->subtree, ((HookModifierData*) md)->object, te, TSE_LINKED_OB, 0);
748 } else if (md->type==eModifierType_ParticleSystem) {
750 ParticleSystem *psys= ((ParticleSystemModifierData*) md)->psys;
752 ten = outliner_add_element(soops, &te->subtree, ob, te, TSE_LINKED_PSYS, 0);
753 ten->directdata = psys;
754 ten->name = psys->part->id.name+2;
758 if(ob->defbase.first) {
759 bDeformGroup *defgroup;
761 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_DEFGROUP_BASE, 0);
764 tenla->name= "Vertex Groups";
765 for (defgroup=ob->defbase.first; defgroup; defgroup=defgroup->next, a++) {
766 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_DEFGROUP, a);
767 ten->name= defgroup->name;
768 ten->directdata= defgroup;
771 if(ob->scriptlink.scripts) {
772 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_SCRIPT_BASE, 0);
775 tenla->name= "Scripts";
776 for (a=0; a<ob->scriptlink.totscript; a++) { /* ** */
777 outliner_add_element(soops, &tenla->subtree, ob->scriptlink.scripts[a], te, 0, 0);
782 outliner_add_element(soops, &te->subtree, ob->dup_group, te, 0, 0);
788 Mesh *me= (Mesh *)id;
790 //outliner_add_element(soops, &te->subtree, me->adt, te, TSE_ANIM_DATA, 0);
792 outliner_add_element(soops, &te->subtree, me->key, te, 0, 0);
793 for(a=0; a<me->totcol; a++)
794 outliner_add_element(soops, &te->subtree, me->mat[a], te, 0, a);
795 /* could do tfaces with image links, but the images are not grouped nicely.
796 would require going over all tfaces, sort images in use. etc... */
801 Curve *cu= (Curve *)id;
803 outliner_add_element(soops, &te->subtree, cu->adt, te, TSE_ANIM_DATA, 0);
805 for(a=0; a<cu->totcol; a++)
806 outliner_add_element(soops, &te->subtree, cu->mat[a], te, 0, a);
811 MetaBall *mb= (MetaBall *)id;
812 for(a=0; a<mb->totcol; a++)
813 outliner_add_element(soops, &te->subtree, mb->mat[a], te, 0, a);
818 Material *ma= (Material *)id;
820 outliner_add_element(soops, &te->subtree, ma->adt, te, TSE_ANIM_DATA, 0);
822 for(a=0; a<MAX_MTEX; a++) {
823 if(ma->mtex[a]) outliner_add_element(soops, &te->subtree, ma->mtex[a]->tex, te, 0, a);
831 outliner_add_element(soops, &te->subtree, tex->adt, te, TSE_ANIM_DATA, 0);
832 outliner_add_element(soops, &te->subtree, tex->ima, te, 0, 0);
837 Camera *ca= (Camera *)id;
838 outliner_add_element(soops, &te->subtree, ca->adt, te, TSE_ANIM_DATA, 0);
843 Lamp *la= (Lamp *)id;
845 outliner_add_element(soops, &te->subtree, la->adt, te, TSE_ANIM_DATA, 0);
847 for(a=0; a<MAX_MTEX; a++) {
848 if(la->mtex[a]) outliner_add_element(soops, &te->subtree, la->mtex[a]->tex, te, 0, a);
854 World *wrld= (World *)id;
856 outliner_add_element(soops, &te->subtree, wrld->adt, te, TSE_ANIM_DATA, 0);
858 for(a=0; a<MAX_MTEX; a++) {
859 if(wrld->mtex[a]) outliner_add_element(soops, &te->subtree, wrld->mtex[a]->tex, te, 0, a);
867 outliner_add_element(soops, &te->subtree, key->adt, te, TSE_ANIM_DATA, 0);
872 // XXX do we want to be exposing the F-Curves here?
873 //bAction *act= (bAction *)id;
878 bArmature *arm= (bArmature *)id;
885 for (ebone = arm->edbo->first; ebone; ebone=ebone->next, a++) {
886 ten= outliner_add_element(soops, &te->subtree, id, te, TSE_EBONE, a);
887 ten->directdata= ebone;
888 ten->name= ebone->name;
892 ten= te->subtree.first;
894 TreeElement *nten= ten->next, *par;
895 ebone= (EditBone *)ten->directdata;
897 BLI_remlink(&te->subtree, ten);
898 par= ebone->parent->temp;
899 BLI_addtail(&par->subtree, ten);
906 /* do not extend Armature when we have posemode */
907 tselem= TREESTORE(te->parent);
908 if( GS(tselem->id->name)==ID_OB && ((Object *)tselem->id)->flag & OB_POSEMODE);
911 for (curBone=arm->bonebase.first; curBone; curBone=curBone->next){
912 outliner_add_bone(soops, &te->subtree, id, curBone, te, &a);
920 else if(type==TSE_ANIM_DATA) {
921 AnimData *adt= (AnimData *)idv;
923 /* this element's info */
924 te->name= "Animation";
927 outliner_add_element(soops, &te->subtree, adt->action, te, 0, 0);
930 if (adt->drivers.first) {
931 TreeElement *ted= outliner_add_element(soops, &te->subtree, adt, te, TSE_DRIVER_BASE, 0);
936 ted->name= "Drivers";
938 for (fcu= adt->drivers.first; fcu; fcu= fcu->next) {
939 if (fcu->driver && fcu->driver->targets.first) {
940 for (dtar= fcu->driver->targets.first; dtar; dtar= dtar->next) {
941 if (lastadded != dtar->id) {
942 // XXX this lastadded check is rather lame, and also fails quite badly...
943 outliner_add_element(soops, &ted->subtree, dtar->id, ted, TSE_LINKED_OB, 0);
952 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, &tenla->subtree, nlt, tenla, TSE_NLA_TRACK, a);
965 tenlt->name= nlt->name;
967 for (strip=nlt->strips.first; strip; strip=strip->next, b++) {
968 ten= outliner_add_element(soops, &tenlt->subtree, strip->act, tenlt, TSE_NLA_ACTION, b);
969 if(ten) ten->directdata= strip;
974 else if(type==TSE_SEQUENCE) {
975 Sequence *seq= (Sequence*) idv;
979 * The idcode is a little hack, but the outliner
980 * only check te->idcode if te->type is equal to zero,
983 te->idcode= seq->type;
988 * This work like the sequence.
989 * If the sequence have a name (not default name)
990 * show it, in other case put the filename.
992 if(strcmp(seq->name, "SQ"))
995 if((seq->strip) && (seq->strip->stripdata))
996 te->name= seq->strip->stripdata->name;
997 else if((seq->strip) && (seq->strip->tstripdata) && (seq->strip->tstripdata->ibuf))
998 te->name= seq->strip->tstripdata->ibuf->name;
1000 te->name= "SQ None";
1003 if(seq->type==SEQ_META) {
1004 te->name= "Meta Strip";
1005 p= seq->seqbase.first;
1007 outliner_add_element(soops, &te->subtree, (void*)p, te, TSE_SEQUENCE, index);
1012 outliner_add_element(soops, &te->subtree, (void*)seq->strip, te, TSE_SEQ_STRIP, index);
1017 else if(type==TSE_SEQ_STRIP) {
1018 Strip *strip= (Strip *)idv;
1021 te->name= strip->dir;
1023 te->name= "Strip None";
1024 te->directdata= strip;
1026 else if(type==TSE_SEQUENCE_DUP) {
1027 Sequence *seq= (Sequence*)idv;
1029 te->idcode= seq->type;
1030 te->directdata= seq;
1031 te->name= seq->strip->stripdata->name;
1033 else if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
1034 PointerRNA pptr, propptr, *ptr= (PointerRNA*)idv;
1035 PropertyRNA *prop, *iterprop;
1036 PropertyType proptype;
1037 PropertySubType propsubtype;
1040 /* we do lazy build, for speed and to avoid infinite recusion */
1042 if(ptr->data == NULL) {
1043 te->name= "(empty)";
1045 else if(type == TSE_RNA_STRUCT) {
1047 te->name= RNA_struct_name_get_alloc(ptr, NULL, 0);
1050 te->flag |= TE_FREE_NAME;
1052 te->name= (char*)RNA_struct_ui_name(ptr->type);
1054 iterprop= RNA_struct_iterator_property(ptr->type);
1055 tot= RNA_property_collection_length(ptr, iterprop);
1057 /* auto open these cases */
1058 if(!parent || (RNA_property_type(parent->directdata)) == PROP_POINTER)
1060 tselem->flag &= ~TSE_CLOSED;
1062 if(!(tselem->flag & TSE_CLOSED)) {
1063 for(a=0; a<tot; a++)
1064 outliner_add_element(soops, &te->subtree, (void*)ptr, te, TSE_RNA_PROPERTY, a);
1067 te->flag |= TE_LAZY_CLOSED;
1071 else if(type == TSE_RNA_PROPERTY) {
1073 iterprop= RNA_struct_iterator_property(ptr->type);
1074 RNA_property_collection_lookup_int(ptr, iterprop, index, &propptr);
1077 proptype= RNA_property_type(prop);
1079 te->name= (char*)RNA_property_ui_name(prop);
1080 te->directdata= prop;
1083 if(proptype == PROP_POINTER) {
1084 pptr= RNA_property_pointer_get(ptr, prop);
1087 if(!(tselem->flag & TSE_CLOSED))
1088 outliner_add_element(soops, &te->subtree, (void*)&pptr, te, TSE_RNA_STRUCT, -1);
1090 te->flag |= TE_LAZY_CLOSED;
1093 else if(proptype == PROP_COLLECTION) {
1094 tot= RNA_property_collection_length(ptr, prop);
1096 if(!(tselem->flag & TSE_CLOSED)) {
1097 for(a=0; a<tot; a++) {
1098 RNA_property_collection_lookup_int(ptr, prop, a, &pptr);
1099 outliner_add_element(soops, &te->subtree, (void*)&pptr, te, TSE_RNA_STRUCT, -1);
1103 te->flag |= TE_LAZY_CLOSED;
1105 else if(ELEM3(proptype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
1106 tot= RNA_property_array_length(prop);
1108 if(!(tselem->flag & TSE_CLOSED)) {
1109 for(a=0; a<tot; a++)
1110 outliner_add_element(soops, &te->subtree, (void*)ptr, te, TSE_RNA_ARRAY_ELEM, a);
1113 te->flag |= TE_LAZY_CLOSED;
1116 else if(type == TSE_RNA_ARRAY_ELEM) {
1117 /* array property element */
1118 static char *vectoritem[4]= {" x", " y", " z", " w"};
1119 static char *quatitem[4]= {" w", " x", " y", " z"};
1120 static char *coloritem[4]= {" r", " g", " b", " a"};
1122 prop= parent->directdata;
1123 proptype= RNA_property_type(prop);
1124 propsubtype= RNA_property_subtype(prop);
1125 tot= RNA_property_array_length(prop);
1127 te->directdata= prop;
1131 if(tot == 4 && propsubtype == PROP_ROTATION)
1132 te->name= quatitem[index];
1133 else if(tot <= 4 && (propsubtype == PROP_VECTOR || propsubtype == PROP_ROTATION))
1134 te->name= vectoritem[index];
1135 else if(tot <= 4 && propsubtype == PROP_COLOR)
1136 te->name= coloritem[index];
1138 te->name= MEM_callocN(sizeof(char)*20, "OutlinerRNAArrayName");
1139 sprintf(te->name, " %d", index+1);
1140 te->flag |= TE_FREE_NAME;
1148 static void outliner_make_hierarchy(SpaceOops *soops, ListBase *lb)
1150 TreeElement *te, *ten, *tep;
1151 TreeStoreElem *tselem;
1153 /* build hierarchy */
1154 // XXX also, set extents here...
1158 tselem= TREESTORE(te);
1160 if(tselem->type==0 && te->idcode==ID_OB) {
1161 Object *ob= (Object *)tselem->id;
1162 if(ob->parent && ob->parent->id.newid) {
1163 BLI_remlink(lb, te);
1164 tep= (TreeElement *)ob->parent->id.newid;
1165 BLI_addtail(&tep->subtree, te);
1166 // set correct parent pointers
1167 for(te=tep->subtree.first; te; te= te->next) te->parent= tep;
1174 /* Helped function to put duplicate sequence in the same tree. */
1175 int need_add_seq_dup(Sequence *seq)
1179 if((!seq->strip) || (!seq->strip->stripdata) || (!seq->strip->stripdata->name))
1183 * First check backward, if we found a duplicate
1184 * sequence before this, don't need it, just return.
1188 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1193 if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1200 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1205 if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1212 void add_seq_dup(SpaceOops *soops, Sequence *seq, TreeElement *te, short index)
1219 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1224 if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1225 ch= outliner_add_element(soops, &te->subtree, (void*)p, te, TSE_SEQUENCE, index);
1230 static void outliner_build_tree(Main *mainvar, Scene *scene, SpaceOops *soops)
1234 TreeElement *te=NULL, *ten;
1235 TreeStoreElem *tselem;
1236 int show_opened= (soops->treestore==NULL); /* on first view, we open scenes */
1238 if(soops->tree.first && (soops->storeflag & SO_TREESTORE_REDRAW))
1241 outliner_free_tree(&soops->tree);
1242 outliner_storage_cleanup(soops);
1244 /* clear ob id.new flags */
1245 for(ob= mainvar->object.first; ob; ob= ob->id.next) ob->id.newid= NULL;
1248 if(soops->outlinevis == SO_LIBRARIES) {
1251 for(lib= mainvar->library.first; lib; lib= lib->id.next) {
1252 ten= outliner_add_element(soops, &soops->tree, lib, NULL, 0, 0);
1253 lib->id.newid= (ID *)ten;
1255 /* make hierarchy */
1256 ten= soops->tree.first;
1258 TreeElement *nten= ten->next, *par;
1259 tselem= TREESTORE(ten);
1260 lib= (Library *)tselem->id;
1262 BLI_remlink(&soops->tree, ten);
1263 par= (TreeElement *)lib->parent->id.newid;
1264 BLI_addtail(&par->subtree, ten);
1269 /* restore newid pointers */
1270 for(lib= mainvar->library.first; lib; lib= lib->id.next)
1271 lib->id.newid= NULL;
1274 else if(soops->outlinevis == SO_ALL_SCENES) {
1276 for(sce= mainvar->scene.first; sce; sce= sce->id.next) {
1277 te= outliner_add_element(soops, &soops->tree, sce, NULL, 0, 0);
1278 tselem= TREESTORE(te);
1279 if(sce==scene && show_opened)
1280 tselem->flag &= ~TSE_CLOSED;
1282 for(base= sce->base.first; base; base= base->next) {
1283 ten= outliner_add_element(soops, &te->subtree, base->object, te, 0, 0);
1284 ten->directdata= base;
1286 outliner_make_hierarchy(soops, &te->subtree);
1287 /* clear id.newid, to prevent objects be inserted in wrong scenes (parent in other scene) */
1288 for(base= sce->base.first; base; base= base->next) base->object->id.newid= NULL;
1291 else if(soops->outlinevis == SO_CUR_SCENE) {
1293 outliner_add_scene_contents(soops, &soops->tree, scene, NULL);
1295 for(base= scene->base.first; base; base= base->next) {
1296 ten= outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1297 ten->directdata= base;
1299 outliner_make_hierarchy(soops, &soops->tree);
1301 else if(soops->outlinevis == SO_VISIBLE) {
1302 for(base= scene->base.first; base; base= base->next) {
1303 if(base->lay & scene->lay)
1304 outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1306 outliner_make_hierarchy(soops, &soops->tree);
1308 else if(soops->outlinevis == SO_GROUPS) {
1312 for(group= mainvar->group.first; group; group= group->id.next) {
1314 te= outliner_add_element(soops, &soops->tree, group, NULL, 0, 0);
1315 tselem= TREESTORE(te);
1317 for(go= group->gobject.first; go; go= go->next) {
1318 ten= outliner_add_element(soops, &te->subtree, go->ob, te, 0, 0);
1319 ten->directdata= NULL; /* eh, why? */
1321 outliner_make_hierarchy(soops, &te->subtree);
1322 /* clear id.newid, to prevent objects be inserted in wrong scenes (parent in other scene) */
1323 for(go= group->gobject.first; go; go= go->next) go->ob->id.newid= NULL;
1327 else if(soops->outlinevis == SO_SAME_TYPE) {
1330 for(base= scene->base.first; base; base= base->next) {
1331 if(base->object->type==ob->type) {
1332 ten= outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1333 ten->directdata= base;
1336 outliner_make_hierarchy(soops, &soops->tree);
1339 else if(soops->outlinevis == SO_SELECTED) {
1340 for(base= scene->base.first; base; base= base->next) {
1341 if(base->lay & scene->lay) {
1342 if(base==BASACT || (base->flag & SELECT)) {
1343 ten= outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1344 ten->directdata= base;
1348 outliner_make_hierarchy(soops, &soops->tree);
1350 else if(soops->outlinevis==SO_SEQUENCE) {
1352 Editing *ed= seq_give_editing(scene, FALSE);
1358 seq= ed->seqbasep->first;
1363 op= need_add_seq_dup(seq);
1365 ten= outliner_add_element(soops, &soops->tree, (void*)seq, NULL, TSE_SEQUENCE, 0);
1367 ten= outliner_add_element(soops, &soops->tree, (void*)seq, NULL, TSE_SEQUENCE_DUP, 0);
1368 add_seq_dup(soops, seq, ten, 0);
1373 else if(soops->outlinevis==SO_DATABLOCKS) {
1376 RNA_main_pointer_create(mainvar, &mainptr);
1378 ten= outliner_add_element(soops, &soops->tree, (void*)&mainptr, NULL, TSE_RNA_STRUCT, -1);
1381 tselem= TREESTORE(ten);
1382 tselem->flag &= ~TSE_CLOSED;
1385 else if(soops->outlinevis==SO_USERDEF) {
1386 PointerRNA userdefptr;
1388 RNA_pointer_create(NULL, &RNA_UserPreferences, &U, &userdefptr);
1390 ten= outliner_add_element(soops, &soops->tree, (void*)&userdefptr, NULL, TSE_RNA_STRUCT, -1);
1393 tselem= TREESTORE(ten);
1394 tselem->flag &= ~TSE_CLOSED;
1398 ten= outliner_add_element(soops, &soops->tree, OBACT, NULL, 0, 0);
1399 if(ten) ten->directdata= BASACT;
1402 outliner_sort(soops, &soops->tree);
1405 /* **************** INTERACTIVE ************* */
1407 static int outliner_count_levels(SpaceOops *soops, ListBase *lb, int curlevel)
1410 int level=curlevel, lev;
1412 for(te= lb->first; te; te= te->next) {
1414 lev= outliner_count_levels(soops, &te->subtree, curlevel+1);
1415 if(lev>level) level= lev;
1420 static int outliner_has_one_flag(SpaceOops *soops, ListBase *lb, short flag, short curlevel)
1423 TreeStoreElem *tselem;
1426 for(te= lb->first; te; te= te->next) {
1427 tselem= TREESTORE(te);
1428 if(tselem->flag & flag) return curlevel;
1430 level= outliner_has_one_flag(soops, &te->subtree, flag, curlevel+1);
1431 if(level) return level;
1436 static void outliner_set_flag(SpaceOops *soops, ListBase *lb, short flag, short set)
1439 TreeStoreElem *tselem;
1441 for(te= lb->first; te; te= te->next) {
1442 tselem= TREESTORE(te);
1443 if(set==0) tselem->flag &= ~flag;
1444 else tselem->flag |= flag;
1445 outliner_set_flag(soops, &te->subtree, flag, set);
1451 void object_toggle_visibility_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1453 Scene *scene= NULL; // XXX
1454 Base *base= (Base *)te->directdata;
1456 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1458 base->object->restrictflag^=OB_RESTRICT_VIEW;
1462 static int outliner_toggle_visibility_exec(bContext *C, wmOperator *op)
1464 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
1465 Scene *scene= CTX_data_scene(C);
1466 ARegion *ar= CTX_wm_region(C);
1468 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_visibility_cb);
1470 // XXX need proper notifiers here instead
1471 ED_region_tag_redraw(ar);
1473 return OPERATOR_FINISHED;
1476 void OUTLINER_OT_visibility_toggle(wmOperatorType *ot)
1479 ot->name= "Toggle Visability";
1480 ot->idname= "OUTLINER_OT_visibility_toggle";
1481 ot->description= "Toggle the visibility of selected items.";
1484 ot->exec= outliner_toggle_visibility_exec;
1485 ot->poll= ED_operator_outliner_active;
1487 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1492 static void object_toggle_selectability_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1494 Scene *scene= NULL; // XXX
1495 Base *base= (Base *)te->directdata;
1497 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1499 base->object->restrictflag^=OB_RESTRICT_SELECT;
1503 static int outliner_toggle_selectability_exec(bContext *C, wmOperator *op)
1505 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
1506 Scene *scene= CTX_data_scene(C);
1507 ARegion *ar= CTX_wm_region(C);
1509 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_selectability_cb);
1511 // XXX need proper notifiers here instead
1512 ED_region_tag_redraw(ar);
1514 return OPERATOR_FINISHED;
1517 void OUTLINER_OT_selectability_toggle(wmOperatorType *ot)
1520 ot->name= "Toggle Selectability";
1521 ot->idname= "OUTLINER_OT_selectability_toggle";
1522 ot->description= "Toggle the selectability";
1525 ot->exec= outliner_toggle_selectability_exec;
1526 ot->poll= ED_operator_outliner_active;
1528 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1533 void object_toggle_renderability_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1535 Scene *scene= NULL; // XXX
1536 Base *base= (Base *)te->directdata;
1538 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1540 base->object->restrictflag^=OB_RESTRICT_RENDER;
1544 static int outliner_toggle_renderability_exec(bContext *C, wmOperator *op)
1546 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
1547 Scene *scene= CTX_data_scene(C);
1548 ARegion *ar= CTX_wm_region(C);
1550 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_renderability_cb);
1552 // XXX need proper notifiers here instead
1553 ED_region_tag_redraw(ar);
1555 return OPERATOR_FINISHED;
1558 void OUTLINER_OT_renderability_toggle(wmOperatorType *ot)
1561 ot->name= "Toggle Renderability";
1562 ot->idname= "OUTLINER_OT_renderability_toggle";
1563 ot->description= "Toggle the renderbility of selected items.";
1566 ot->exec= outliner_toggle_renderability_exec;
1567 ot->poll= ED_operator_outliner_active;
1569 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1574 static int outliner_toggle_expanded_exec(bContext *C, wmOperator *op)
1576 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
1577 ARegion *ar= CTX_wm_region(C);
1579 if (outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1))
1580 outliner_set_flag(soops, &soops->tree, TSE_CLOSED, 0);
1582 outliner_set_flag(soops, &soops->tree, TSE_CLOSED, 1);
1584 // XXX need proper notifiers here instead
1585 ED_region_tag_redraw(ar);
1587 return OPERATOR_FINISHED;
1590 void OUTLINER_OT_expanded_toggle(wmOperatorType *ot)
1593 ot->name= "Expand/Collapse All";
1594 ot->idname= "OUTLINER_OT_expanded_toggle";
1595 ot->description= "Expand/Collapse all items.";
1598 ot->exec= outliner_toggle_expanded_exec;
1599 ot->poll= ED_operator_outliner_active;
1601 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1606 static int outliner_toggle_selected_exec(bContext *C, wmOperator *op)
1608 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
1609 ARegion *ar= CTX_wm_region(C);
1611 if (outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1))
1612 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
1614 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 1);
1616 soops->storeflag |= SO_TREESTORE_REDRAW;
1618 // XXX need proper notifiers here instead
1619 ED_region_tag_redraw(ar);
1621 return OPERATOR_FINISHED;
1624 void OUTLINER_OT_selected_toggle(wmOperatorType *ot)
1627 ot->name= "Toggle Selected";
1628 ot->idname= "OUTLINER_OT_selected_toggle";
1629 ot->description= "Toggle the Outliner selection of items.";
1632 ot->exec= outliner_toggle_selected_exec;
1633 ot->poll= ED_operator_outliner_active;
1635 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1640 /* helper function for Show/Hide one level operator */
1641 static void outliner_openclose_level(SpaceOops *soops, ListBase *lb, int curlevel, int level, int open)
1644 TreeStoreElem *tselem;
1646 for(te= lb->first; te; te= te->next) {
1647 tselem= TREESTORE(te);
1650 if(curlevel<=level) tselem->flag &= ~TSE_CLOSED;
1653 if(curlevel>=level) tselem->flag |= TSE_CLOSED;
1656 outliner_openclose_level(soops, &te->subtree, curlevel+1, level, open);
1660 static int outliner_one_level_exec(bContext *C, wmOperator *op)
1662 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
1663 ARegion *ar= CTX_wm_region(C);
1664 int add= RNA_boolean_get(op->ptr, "open");
1667 level= outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1);
1669 if(level) outliner_openclose_level(soops, &soops->tree, 1, level, 1);
1672 if(level==0) level= outliner_count_levels(soops, &soops->tree, 0);
1673 if(level) outliner_openclose_level(soops, &soops->tree, 1, level-1, 0);
1676 // XXX need proper notifiers here instead
1677 ED_region_tag_redraw(ar);
1679 return OPERATOR_FINISHED;
1682 void OUTLINER_OT_show_one_level(wmOperatorType *ot)
1685 ot->name= "Show/Hide One Level";
1686 ot->idname= "OUTLINER_OT_show_one_level";
1689 ot->exec= outliner_one_level_exec;
1690 ot->poll= ED_operator_outliner_active;
1692 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1695 RNA_def_boolean(ot->srna, "open", 1, "Open", "Expand all entries one level deep.");
1698 /* return 1 when levels were opened */
1699 static int outliner_open_back(SpaceOops *soops, TreeElement *te)
1701 TreeStoreElem *tselem;
1704 for (te= te->parent; te; te= te->parent) {
1705 tselem= TREESTORE(te);
1706 if (tselem->flag & TSE_CLOSED) {
1707 tselem->flag &= ~TSE_CLOSED;
1714 /* This is not used anywhere at the moment */
1716 static void outliner_open_reveal(SpaceOops *soops, ListBase *lb, TreeElement *teFind, int *found)
1719 TreeStoreElem *tselem;
1721 for (te= lb->first; te; te= te->next) {
1722 /* check if this tree-element was the one we're seeking */
1728 /* try to see if sub-tree contains it then */
1729 outliner_open_reveal(soops, &te->subtree, teFind, found);
1731 tselem= TREESTORE(te);
1732 if (tselem->flag & TSE_CLOSED)
1733 tselem->flag &= ~TSE_CLOSED;
1740 // XXX just use View2D ops for this?
1741 void outliner_page_up_down(Scene *scene, ARegion *ar, SpaceOops *soops, int up)
1743 int dy= ar->v2d.mask.ymax-ar->v2d.mask.ymin;
1745 if(up == -1) dy= -dy;
1746 ar->v2d.cur.ymin+= dy;
1747 ar->v2d.cur.ymax+= dy;
1749 soops->storeflag |= SO_TREESTORE_REDRAW;
1752 /* **** do clicks on items ******* */
1754 static int tree_element_active_renderlayer(TreeElement *te, TreeStoreElem *tselem, int set)
1758 /* paranoia check */
1759 if(te->idcode!=ID_SCE)
1761 sce= (Scene *)tselem->id;
1764 sce->r.actlay= tselem->nr;
1767 return sce->r.actlay==tselem->nr;
1772 static void tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te)
1774 TreeStoreElem *tselem= TREESTORE(te);
1778 int shift= 0; // XXX
1780 /* if id is not object, we search back */
1781 if(te->idcode==ID_OB) ob= (Object *)tselem->id;
1783 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1784 if(ob==OBACT) return;
1786 if(ob==NULL) return;
1788 sce= (Scene *)outliner_search_back(soops, te, ID_SCE);
1789 if(sce && scene != sce) {
1790 ED_screen_set_scene(C, sce);
1793 /* find associated base in current scene */
1794 for(base= FIRSTBASE; base; base= base->next)
1795 if(base->object==ob) break;
1799 if(base->flag & SELECT)
1800 ED_base_object_select(base, BA_DESELECT);
1802 ED_base_object_select(base, BA_SELECT);
1806 /* deleselect all */
1807 for(b= FIRSTBASE; b; b= b->next) {
1809 b->object->flag= b->flag;
1811 ED_base_object_select(base, BA_SELECT);
1814 ED_base_object_activate(C, base); /* adds notifier */
1817 // XXX if(ob!=obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
1818 // else countall(); /* exit_editmode calls f() */
1821 static int tree_element_active_material(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1826 /* we search for the object parent */
1827 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1828 if(ob==NULL || ob!=OBACT) return 0; // just paranoia
1830 /* searching in ob mat array? */
1832 if(tes->idcode==ID_OB) {
1834 ob->actcol= te->index+1;
1835 ob->matbits[te->index]= 1; // make ob material active too
1836 ob->colbits |= (1<<te->index);
1839 if(ob->actcol == te->index+1)
1840 if(ob->matbits[te->index]) return 1;
1843 /* or we search for obdata material */
1846 ob->actcol= te->index+1;
1847 ob->matbits[te->index]= 0; // make obdata material active too
1848 ob->colbits &= ~(1<<te->index);
1851 if(ob->actcol == te->index+1)
1852 if(ob->matbits[te->index]==0) return 1;
1856 // XXX extern_set_butspace(F5KEY, 0); // force shading buttons
1857 BIF_preview_changed(ID_MA);
1862 static int tree_element_active_texture(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1865 TreeStoreElem *tselem, *tselemp;
1867 SpaceButs *sbuts=NULL;
1869 if(ob==NULL) return 0; // no active object
1871 tselem= TREESTORE(te);
1873 /* find buttons area (note, this is undefined really still, needs recode in blender) */
1874 /* XXX removed finding sbuts */
1876 /* where is texture linked to? */
1878 tselemp= TREESTORE(tep);
1880 if(tep->idcode==ID_WO) {
1881 World *wrld= (World *)tselemp->id;
1885 // XXX sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1888 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1889 wrld->texact= te->index;
1891 else if(tselemp->id == (ID *)(scene->world)) {
1892 if(wrld->texact==te->index) return 1;
1895 else if(tep->idcode==ID_LA) {
1896 Lamp *la= (Lamp *)tselemp->id;
1899 // XXX sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1902 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1903 la->texact= te->index;
1906 if(tselemp->id == ob->data) {
1907 if(la->texact==te->index) return 1;
1911 else if(tep->idcode==ID_MA) {
1912 Material *ma= (Material *)tselemp->id;
1915 //sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1918 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1919 ma->texact= (char)te->index;
1921 /* also set active material */
1922 ob->actcol= tep->index+1;
1924 else if(tep->flag & TE_ACTIVE) { // this is active material
1925 if(ma->texact==te->index) return 1;
1933 static int tree_element_active_lamp(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1937 /* we search for the object parent */
1938 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1939 if(ob==NULL || ob!=OBACT) return 0; // just paranoia
1942 // XXX extern_set_butspace(F5KEY, 0);
1943 BIF_preview_changed(ID_LA);
1950 static int tree_element_active_world(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1953 TreeStoreElem *tselem=NULL;
1958 tselem= TREESTORE(tep);
1959 sce= (Scene *)tselem->id;
1962 if(set) { // make new scene active
1963 if(sce && scene != sce) {
1964 // XXX ED_screen_set_scene(C, sce);
1968 if(tep==NULL || tselem->id == (ID *)scene) {
1970 // XXX extern_set_butspace(F8KEY, 0);
1979 static int tree_element_active_defgroup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1983 /* id in tselem is object */
1984 ob= (Object *)tselem->id;
1986 ob->actdef= te->index+1;
1987 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
1991 if(ob->actdef== te->index+1) return 1;
1996 static int tree_element_active_posegroup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1998 Object *ob= (Object *)tselem->id;
2002 ob->pose->active_group= te->index+1;
2006 if(ob==OBACT && ob->pose) {
2007 if (ob->pose->active_group== te->index+1) return 1;
2013 static int tree_element_active_posechannel(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
2015 Object *ob= (Object *)tselem->id;
2016 bPoseChannel *pchan= te->directdata;
2019 if(!(pchan->bone->flag & BONE_HIDDEN_P)) {
2021 // XXX if(G.qual & LR_SHIFTKEY) deselectall_posearmature(ob, 2, 0); // 2 = clear active tag
2022 // else deselectall_posearmature(ob, 0, 0); // 0 = deselect
2023 pchan->bone->flag |= BONE_SELECTED|BONE_ACTIVE;
2028 if(ob==OBACT && ob->pose) {
2029 if (pchan->bone->flag & BONE_SELECTED) return 1;
2035 static int tree_element_active_bone(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
2037 bArmature *arm= (bArmature *)tselem->id;
2038 Bone *bone= te->directdata;
2041 if(!(bone->flag & BONE_HIDDEN_P)) {
2042 // XXX if(G.qual & LR_SHIFTKEY) deselectall_posearmature(OBACT, 2, 0); // 2 is clear active tag
2043 // else deselectall_posearmature(OBACT, 0, 0);
2044 bone->flag |= BONE_SELECTED|BONE_ACTIVE;
2051 if(ob && ob->data==arm) {
2052 if (bone->flag & BONE_SELECTED) return 1;
2059 /* ebones only draw in editmode armature */
2060 static int tree_element_active_ebone(TreeElement *te, TreeStoreElem *tselem, int set)
2062 EditBone *ebone= te->directdata;
2063 // int shift= 0; // XXX
2066 if(!(ebone->flag & BONE_HIDDEN_A)) {
2068 // XXX if(shift) deselectall_armature(2, 0); // only clear active tag
2069 // else deselectall_armature(0, 0); // deselect
2071 ebone->flag |= BONE_SELECTED|BONE_ROOTSEL|BONE_TIPSEL|BONE_ACTIVE;
2073 if(ebone->parent && (ebone->flag & BONE_CONNECTED)) ebone->parent->flag |= BONE_TIPSEL;
2078 if (ebone->flag & BONE_SELECTED) return 1;
2083 static int tree_element_active_modifier(TreeElement *te, TreeStoreElem *tselem, int set)
2086 // XXX extern_set_butspace(F9KEY, 0);
2092 static int tree_element_active_psys(TreeElement *te, TreeStoreElem *tselem, int set)
2095 // Object *ob= (Object *)tselem->id;
2096 // ParticleSystem *psys= te->directdata;
2098 // XXX PE_change_act_psys(ob, psys);
2099 // XXX extern_set_butspace(F7KEY, 0);
2105 static int tree_element_active_constraint(TreeElement *te, TreeStoreElem *tselem, int set)
2108 // XXX extern_set_butspace(F7KEY, 0);
2114 static int tree_element_active_text(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
2120 /* generic call for ID data check or make/check active in UI */
2121 static int tree_element_active(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
2124 switch(te->idcode) {
2126 return tree_element_active_material(scene, soops, te, set);
2128 return tree_element_active_world(scene, soops, te, set);
2130 return tree_element_active_lamp(scene, soops, te, set);
2132 return tree_element_active_texture(scene, soops, te, set);
2134 return tree_element_active_text(scene, soops, te, set);
2139 static int tree_element_active_pose(TreeElement *te, TreeStoreElem *tselem, int set)
2141 Object *ob= (Object *)tselem->id;
2144 // XXX if(obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2145 // if(ob->flag & OB_POSEMODE) exit_posemode();
2146 // else enter_posemode();
2149 if(ob->flag & OB_POSEMODE) return 1;
2154 static int tree_element_active_sequence(TreeElement *te, TreeStoreElem *tselem, int set)
2156 Sequence *seq= (Sequence*) te->directdata;
2159 // XXX select_single_seq(seq, 1);
2162 if(seq->flag & SELECT)
2168 static int tree_element_active_sequence_dup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
2171 Editing *ed= seq_give_editing(scene, FALSE);
2173 seq= (Sequence*)te->directdata;
2175 if(seq->flag & SELECT)
2180 // XXX select_single_seq(seq, 1);
2181 p= ed->seqbasep->first;
2183 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
2188 // if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
2189 // XXX select_single_seq(p, 0);
2195 /* generic call for non-id data to make/check active in UI */
2196 /* Context can be NULL when set==0 */
2197 static int tree_element_type_active(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, int set)
2200 switch(tselem->type) {
2202 return tree_element_active_defgroup(scene, te, tselem, set);
2204 return tree_element_active_bone(scene, te, tselem, set);
2206 return tree_element_active_ebone(te, tselem, set);
2208 return tree_element_active_modifier(te, tselem, set);
2210 if(set) tree_element_set_active_object(C, scene, soops, te);
2211 else if(tselem->id==(ID *)OBACT) return 1;
2213 case TSE_LINKED_PSYS:
2214 return tree_element_active_psys(te, tselem, set);
2217 return tree_element_active_pose(te, tselem, set);
2219 case TSE_POSE_CHANNEL:
2220 return tree_element_active_posechannel(scene, te, tselem, set);
2221 case TSE_CONSTRAINT:
2222 return tree_element_active_constraint(te, tselem, set);
2224 return tree_element_active_renderlayer(te, tselem, set);
2226 return tree_element_active_posegroup(scene, te, tselem, set);
2228 return tree_element_active_sequence(te, tselem, set);
2230 case TSE_SEQUENCE_DUP:
2231 return tree_element_active_sequence_dup(scene, te, tselem, set);
2237 static int do_outliner_mouse_event(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, short event, float *mval)
2239 int shift= 0, ctrl= 0; // XXX
2241 if(mval[1]>te->ys && mval[1]<te->ys+OL_H) {
2242 TreeStoreElem *tselem= TREESTORE(te);
2245 /* open close icon, three things to check */
2246 if(event==RETKEY || event==PADENTER) openclose= 1; // enter opens/closes always
2247 else if((te->flag & TE_ICONROW)==0) { // hidden icon, no open/close
2248 if( mval[0]>te->xs && mval[0]<te->xs+OL_X) openclose= 1;
2253 /* all below close/open? */
2255 tselem->flag &= ~TSE_CLOSED;
2256 outliner_set_flag(soops, &te->subtree, TSE_CLOSED, !outliner_has_one_flag(soops, &te->subtree, TSE_CLOSED, 1));
2259 if(tselem->flag & TSE_CLOSED) tselem->flag &= ~TSE_CLOSED;
2260 else tselem->flag |= TSE_CLOSED;
2266 /* name and first icon */
2267 else if(mval[0]>te->xs && mval[0]<te->xend) {
2269 /* activate a name button? */
2270 if(event==LEFTMOUSE) {
2273 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))
2274 error("Cannot edit builtin name");
2275 else if(ELEM3(tselem->type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP))
2276 error("Cannot edit sequence name");
2277 else if(tselem->id->lib) {
2278 // XXX error_libdata();
2279 } else if(te->idcode == ID_LI && te->parent) {
2280 error("Cannot edit the path of an indirectly linked library");
2282 tselem->flag |= TSE_TEXTBUT;
2285 /* always makes active object */
2286 if(tselem->type!=TSE_SEQUENCE && tselem->type!=TSE_SEQ_STRIP && tselem->type!=TSE_SEQUENCE_DUP)
2287 tree_element_set_active_object(C, scene, soops, te);
2289 if(tselem->type==0) { // the lib blocks
2291 if(te->idcode==ID_SCE) {
2292 if(scene!=(Scene *)tselem->id) {
2293 ED_screen_set_scene(C, (Scene *)tselem->id);
2296 else if(ELEM5(te->idcode, ID_ME, ID_CU, ID_MB, ID_LT, ID_AR)) {
2297 // XXX if(obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2299 // enter_editmode(EM_WAITCURSOR);
2300 // extern_set_butspace(F9KEY, 0);
2302 } else { // rest of types
2303 tree_element_active(scene, soops, te, 1);
2307 else tree_element_type_active(C, scene, soops, te, tselem, 1);
2310 else if(event==RIGHTMOUSE) {
2311 /* select object that's clicked on and popup context menu */
2312 if (!(tselem->flag & TSE_SELECTED)) {
2314 if ( outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1) )
2315 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
2317 tselem->flag |= TSE_SELECTED;
2318 /* redraw, same as outliner_select function */
2319 soops->storeflag |= SO_TREESTORE_REDRAW;
2320 // XXX screen_swapbuffers();
2323 outliner_operation_menu(scene, ar, soops);
2329 for(te= te->subtree.first; te; te= te->next) {
2330 if(do_outliner_mouse_event(C, scene, ar, soops, te, event, mval)) return 1;
2335 /* event can enterkey, then it opens/closes */
2336 static int outliner_activate_click(bContext *C, wmOperator *op, wmEvent *event)
2338 Scene *scene= CTX_data_scene(C);
2339 ARegion *ar= CTX_wm_region(C);
2340 SpaceOops *soops= (SpaceOops*)CTX_wm_space_data(C);
2344 UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, fmval, fmval+1);
2346 for(te= soops->tree.first; te; te= te->next) {
2347 if(do_outliner_mouse_event(C, scene, ar, soops, te, event->type, fmval)) break;
2351 BIF_undo_push("Outliner click event");
2354 short selecting= -1;
2357 /* get row number - 100 here is just a dummy value since we don't need the column */
2358 UI_view2d_listview_view_to_cell(&ar->v2d, 1000, OL_H, 0.0f, 0.0f,
2359 fmval[0], fmval[1], NULL, &row);
2361 /* select relevant row */
2362 outliner_select(soops, &soops->tree, &row, &selecting);
2364 // XXX old flag found in old code, do we still use this?
2365 //soops->storeflag |= SO_TREESTORE_REDRAW;
2367 BIF_undo_push("Outliner selection event");
2370 // XXX need proper notifiers here instead
2371 ED_region_tag_redraw(ar);
2373 return OPERATOR_FINISHED;
2376 void OUTLINER_OT_activate_click(wmOperatorType *ot)
2378 ot->name= "Activate Click";
2379 ot->idname= "OUTLINER_OT_activate_click";
2381 ot->invoke= outliner_activate_click;
2383 ot->poll= ED_operator_outliner_active;
2388 /* recursive helper for function below */
2389 static void outliner_set_coordinates_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
2391 TreeStoreElem *tselem= TREESTORE(te);
2393 /* store coord and continue, we need coordinates for elements outside view too */
2394 te->xs= (float)startx;
2395 te->ys= (float)(*starty);
2398 if((tselem->flag & TSE_CLOSED)==0) {
2400 for(ten= te->subtree.first; ten; ten= ten->next) {
2401 outliner_set_coordinates_element(soops, ten, startx+OL_X, starty);
2407 /* to retrieve coordinates with redrawing the entire tree */
2408 static void outliner_set_coordinates(ARegion *ar, SpaceOops *soops)
2411 int starty= (int)(ar->v2d.tot.ymax)-OL_H;
2414 for(te= soops->tree.first; te; te= te->next) {
2415 outliner_set_coordinates_element(soops, te, startx, &starty);
2419 static TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, ID *id)
2421 TreeElement *te, *tes;
2422 TreeStoreElem *tselem;
2424 for(te= lb->first; te; te= te->next) {
2425 tselem= TREESTORE(te);
2426 if(tselem->type==0) {
2427 if(tselem->id==id) return te;
2428 /* only deeper on scene or object */
2429 if( te->idcode==ID_OB || te->idcode==ID_SCE) {
2430 tes= outliner_find_id(soops, &te->subtree, id);
2438 static int outliner_show_active_exec(bContext *C, wmOperator *op)
2440 SpaceOops *so= (SpaceOops *)CTX_wm_space_data(C);
2441 Scene *scene= CTX_data_scene(C);
2442 ARegion *ar= CTX_wm_region(C);
2443 View2D *v2d= &ar->v2d;
2448 // TODO: make this get this info from context instead...
2450 return OPERATOR_CANCELLED;
2452 te= outliner_find_id(so, &so->tree, (ID *)OBACT);
2454 /* make te->ys center of view */
2455 ytop= (int)(te->ys + (v2d->mask.ymax - v2d->mask.ymin)/2);
2456 if (ytop>0) ytop= 0;
2458 v2d->cur.ymax= (float)ytop;
2459 v2d->cur.ymin= (float)(ytop-(v2d->mask.ymax - v2d->mask.ymin));
2461 /* make te->xs ==> te->xend center of view */
2462 xdelta = (int)(te->xs - v2d->cur.xmin);
2463 v2d->cur.xmin += xdelta;
2464 v2d->cur.xmax += xdelta;
2466 so->storeflag |= SO_TREESTORE_REDRAW;
2469 // XXX need proper notifiers here instead
2470 ED_region_tag_redraw(ar);
2472 return OPERATOR_FINISHED;
2475 void OUTLINER_OT_show_active(wmOperatorType *ot)
2478 ot->name= "Show Active";
2479 ot->idname= "OUTLINER_OT_show_active";
2480 ot->description= "Adjust the view so that the active Object is shown centered.";
2483 ot->exec= outliner_show_active_exec;
2484 ot->poll= ED_operator_outliner_active;
2486 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2489 /* find next element that has this name */
2490 static TreeElement *outliner_find_named(SpaceOops *soops, ListBase *lb, char *name, int flags, TreeElement *prev, int *prevFound)
2492 TreeElement *te, *tes;
2494 for (te= lb->first; te; te= te->next) {
2497 /* determine if match */
2499 found= BLI_strcasestr(te->name, name)!=NULL;
2500 else if(flags==OL_FIND_CASE)
2501 found= strstr(te->name, name)!=NULL;
2502 else if(flags==OL_FIND_COMPLETE)
2503 found= BLI_strcasecmp(te->name, name)==0;
2505 found= strcmp(te->name, name)==0;
2508 /* name is right, but is element the previous one? */
2510 if ((te != prev) && (*prevFound))
2520 tes= outliner_find_named(soops, &te->subtree, name, flags, prev, prevFound);
2524 /* nothing valid found */
2528 /* tse is not in the treestore, we use its contents to find a match */
2529 static TreeElement *outliner_find_tse(SpaceOops *soops, TreeStoreElem *tse)
2531 TreeStore *ts= soops->treestore;
2532 TreeStoreElem *tselem;
2535 if(tse->id==NULL) return NULL;
2537 /* check if 'tse' is in treestore */
2539 for(a=0; a<ts->usedelem; a++, tselem++) {
2540 if((tse->type==0 && tselem->type==0) || (tselem->type==tse->type && tselem->nr==tse->nr)) {
2541 if(tselem->id==tse->id) {
2547 return outliner_find_tree_element(&soops->tree, a);
2553 /* Called to find an item based on name.
2555 void outliner_find_panel(Scene *scene, ARegion *ar, SpaceOops *soops, int again, int flags)
2557 TreeElement *te= NULL;
2558 TreeElement *last_find;
2559 TreeStoreElem *tselem;
2560 int ytop, xdelta, prevFound=0;
2563 /* get last found tree-element based on stored search_tse */
2564 last_find= outliner_find_tse(soops, &soops->search_tse);
2566 /* determine which type of search to do */
2567 if (again && last_find) {
2568 /* no popup panel - previous + user wanted to search for next after previous */
2569 BLI_strncpy(name, soops->search_string, 33);
2570 flags= soops->search_flags;
2572 /* try to find matching element */
2573 te= outliner_find_named(soops, &soops->tree, name, flags, last_find, &prevFound);
2575 /* no more matches after previous, start from beginning again */
2577 te= outliner_find_named(soops, &soops->tree, name, flags, last_find, &prevFound);
2581 /* pop up panel - no previous, or user didn't want search after previous */
2583 // XXX if (sbutton(name, 0, sizeof(name)-1, "Find: ") && name[0]) {
2584 // te= outliner_find_named(soops, &soops->tree, name, flags, NULL, &prevFound);
2586 // else return; /* XXX RETURN! XXX */
2589 /* do selection and reveal */
2591 tselem= TREESTORE(te);
2593 /* expand branches so that it will be visible, we need to get correct coordinates */
2594 if( outliner_open_back(soops, te))
2595 outliner_set_coordinates(ar, soops);
2597 /* deselect all visible, and select found element */
2598 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
2599 tselem->flag |= TSE_SELECTED;
2601 /* make te->ys center of view */
2602 ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
2604 ar->v2d.cur.ymax= (float)ytop;
2605 ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
2607 /* make te->xs ==> te->xend center of view */
2608 xdelta = (int)(te->xs - ar->v2d.cur.xmin);
2609 ar->v2d.cur.xmin += xdelta;
2610 ar->v2d.cur.xmax += xdelta;
2612 /* store selection */
2613 soops->search_tse= *tselem;
2615 BLI_strncpy(soops->search_string, name, 33);
2616 soops->search_flags= flags;
2619 soops->storeflag |= SO_TREESTORE_REDRAW;
2623 /* no tree-element found */
2624 error("Not found: %s", name);
2628 /* helper function for tree_element_shwo_hierarchy() - recursively checks whether subtrees have any objects*/
2629 static int subtree_has_objects(SpaceOops *soops, ListBase *lb)
2632 TreeStoreElem *tselem;
2634 for(te= lb->first; te; te= te->next) {
2635 tselem= TREESTORE(te);
2636 if(tselem->type==0 && te->idcode==ID_OB) return 1;
2637 if( subtree_has_objects(soops, &te->subtree)) return 1;
2642 /* recursive helper function for Show Hierarchy operator */
2643 static void tree_element_show_hierarchy(Scene *scene, SpaceOops *soops, ListBase *lb)
2646 TreeStoreElem *tselem;
2648 /* open all object elems, close others */
2649 for(te= lb->first; te; te= te->next) {
2650 tselem= TREESTORE(te);
2652 if(tselem->type==0) {
2653 if(te->idcode==ID_SCE) {
2654 if(tselem->id!=(ID *)scene) tselem->flag |= TSE_CLOSED;
2655 else tselem->flag &= ~TSE_CLOSED;
2657 else if(te->idcode==ID_OB) {
2658 if(subtree_has_objects(soops, &te->subtree)) tselem->flag &= ~TSE_CLOSED;
2659 else tselem->flag |= TSE_CLOSED;
2662 else tselem->flag |= TSE_CLOSED;
2664 if(tselem->flag & TSE_CLOSED); else tree_element_show_hierarchy(scene, soops, &te->subtree);
2668 /* show entire object level hierarchy */
2669 static int outliner_show_hierarchy_exec(bContext *C, wmOperator *op)
2671 SpaceOops *soops= (SpaceOops *)CTX_wm_space_data(C);
2672 ARegion *ar= CTX_wm_region(C);
2673 Scene *scene= CTX_data_scene(C);
2675 /* recursively open/close levels */
2676 tree_element_show_hierarchy(scene, soops, &soops->tree);
2678 // XXX need proper notifiers here instead
2679 ED_region_tag_redraw(ar);
2681 return OPERATOR_FINISHED;
2684 void OUTLINER_OT_show_hierarchy(wmOperatorType *ot)
2687 ot->name= "Show Hierarchy";
2688 ot->idname= "OUTLINER_OT_show_hierarchy";
2689 ot->description= "Open all object entries and close all others.";
2692 ot->exec= outliner_show_hierarchy_exec;
2693 ot->poll= ED_operator_outliner_active; // TODO: shouldn't be allowed in RNA views...
2695 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2698 void outliner_select(SpaceOops *soops, ListBase *lb, int *index, short *selecting)
2701 TreeStoreElem *tselem;
2703 for (te= lb->first; te && *index >= 0; te=te->next, (*index)--) {
2704 tselem= TREESTORE(te);
2706 /* if we've encountered the right item, set its 'Outliner' selection status */
2708 /* this should be the last one, so no need to do anything with index */
2709 if ((te->flag & TE_ICONROW)==0) {
2710 /* -1 value means toggle testing for now... */
2711 if (*selecting == -1) {
2712 if (tselem->flag & TSE_SELECTED)
2720 tselem->flag |= TSE_SELECTED;
2722 tselem->flag &= ~TSE_SELECTED;
2725 else if ((tselem->flag & TSE_CLOSED)==0) {
2726 /* Only try selecting sub-elements if we haven't hit the right element yet
2729 * Index must be reduced before supplying it to the sub-tree to try to do
2730 * selection, however, we need to increment it again for the next loop to
2731 * function correctly
2734 outliner_select(soops, &te->subtree, index, selecting);
2740 /* ************ SELECTION OPERATIONS ********* */
2742 static void set_operation_types(SpaceOops *soops, ListBase *lb,
2749 TreeStoreElem *tselem;
2751 for(te= lb->first; te; te= te->next) {
2752 tselem= TREESTORE(te);
2753 if(tselem->flag & TSE_SELECTED) {
2755 if(tselem->type==TSE_SEQUENCE)
2756 *datalevel= TSE_SEQUENCE;
2757 else if(tselem->type==TSE_SEQ_STRIP)
2758 *datalevel= TSE_SEQ_STRIP;
2759 else if(tselem->type==TSE_SEQUENCE_DUP)
2760 *datalevel= TSE_SEQUENCE_DUP;
2761 else if(*datalevel!=tselem->type) *datalevel= -1;
2764 int idcode= GS(tselem->id->name);
2773 case ID_ME: case ID_CU: case ID_MB: case ID_LT:
2774 case ID_LA: case ID_AR: case ID_CA:
2775 case ID_MA: case ID_TE: case ID_IP: case ID_IM:
2776 case ID_SO: case ID_KE: case ID_WO: case ID_AC:
2777 case ID_NLA: case ID_TXT: case ID_GR:
2778 if(*idlevel==0) *idlevel= idcode;
2779 else if(*idlevel!=idcode) *idlevel= -1;
2784 if((tselem->flag & TSE_CLOSED)==0) {
2785 set_operation_types(soops, &te->subtree,
2786 scenelevel, objectlevel, idlevel, datalevel);
2791 static void unlink_material_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2793 Material **matar=NULL;
2796 if( GS(tsep->id->name)==ID_OB) {
2797 Object *ob= (Object *)tsep->id;
2801 else if( GS(tsep->id->name)==ID_ME) {
2802 Mesh *me= (Mesh *)tsep->id;
2806 else if( GS(tsep->id->name)==ID_CU) {
2807 Curve *cu= (Curve *)tsep->id;
2811 else if( GS(tsep->id->name)==ID_MB) {
2812 MetaBall *mb= (MetaBall *)tsep->id;
2817 for(a=0; a<totcol; a++) {
2818 if(a==te->index && matar[a]) {
2825 static void unlink_texture_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2830 if( GS(tsep->id->name)==ID_MA) {
2831 Material *ma= (Material *)tsep->id;
2834 else if( GS(tsep->id->name)==ID_LA) {
2835 Lamp *la= (Lamp *)tsep->id;
2838 else if( GS(tsep->id->name)==ID_WO) {
2839 World *wrld= (World *)tsep->id;
2844 for(a=0; a<MAX_MTEX; a++) {
2845 if(a==te->index && mtex[a]) {
2847 mtex[a]->tex->id.us--;
2854 static void unlink_group_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2856 Group *group= (Group *)tselem->id;
2859 if( GS(tsep->id->name)==ID_OB) {
2860 Object *ob= (Object *)tsep->id;
2861 ob->dup_group= NULL;