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"
101 #include "RNA_access.h"
103 #include "ED_armature.h"
104 #include "ED_object.h"
105 #include "ED_screen.h"
107 #include "outliner_intern.h"
113 #include "PIL_time.h"
119 #define OL_TOG_RESTRICT_VIEWX 54
120 #define OL_TOG_RESTRICT_SELECTX 36
121 #define OL_TOG_RESTRICT_RENDERX 18
123 #define OL_TOGW OL_TOG_RESTRICT_VIEWX
125 #define OL_RNA_COLX 300
126 #define OL_RNA_COL_SIZEX 150
127 #define OL_RNA_COL_SPACEX 50
131 #define TREESTORE(a) ((a)?soops->treestore->data+(a)->store_index:NULL)
133 /* ************* XXX **************** */
135 static void BIF_undo_push() {}
136 static void BIF_preview_changed() {}
137 static void error() {}
138 static int pupmenu() {return 0;}
140 /* ********************************** */
143 /* ******************** PROTOTYPES ***************** */
144 static void outliner_draw_tree_element(Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty);
145 static void outliner_do_object_operation(Scene *scene, SpaceOops *soops, ListBase *lb,
146 void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *));
149 /* ******************** PERSISTANT DATA ***************** */
151 static void outliner_storage_cleanup(SpaceOops *soops)
153 TreeStore *ts= soops->treestore;
156 TreeStoreElem *tselem;
159 /* each element used once, for ID blocks with more users to have each a treestore */
160 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) tselem->used= 0;
162 /* cleanup only after reading file or undo step, and always for
163 * RNA datablocks view in order to save memory */
164 if(soops->storeflag & SO_TREESTORE_CLEANUP) {
166 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) {
167 if(tselem->id==NULL) unused++;
171 if(ts->usedelem == unused) {
174 ts->usedelem= ts->totelem= 0;
177 TreeStoreElem *tsnewar, *tsnew;
179 tsnew=tsnewar= MEM_mallocN((ts->usedelem-unused)*sizeof(TreeStoreElem), "new tselem");
180 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) {
188 ts->usedelem-= unused;
189 ts->totelem= ts->usedelem;
196 static void check_persistant(SpaceOops *soops, TreeElement *te, ID *id, short type, short nr)
199 TreeStoreElem *tselem;
202 /* case 1; no TreeStore */
203 if(soops->treestore==NULL) {
204 ts= soops->treestore= MEM_callocN(sizeof(TreeStore), "treestore");
206 ts= soops->treestore;
208 /* check if 'te' is in treestore */
210 for(a=0; a<ts->usedelem; a++, tselem++) {
211 if(tselem->id==id && tselem->used==0) {
212 if((type==0 && tselem->type==0) ||(tselem->type==type && tselem->nr==nr)) {
220 /* add 1 element to treestore */
221 if(ts->usedelem==ts->totelem) {
222 TreeStoreElem *tsnew;
224 tsnew= MEM_mallocN((ts->totelem+TS_CHUNK)*sizeof(TreeStoreElem), "treestore data");
226 memcpy(tsnew, ts->data, ts->totelem*sizeof(TreeStoreElem));
230 ts->totelem+= TS_CHUNK;
233 tselem= ts->data+ts->usedelem;
236 if(type) tselem->nr= nr; // we're picky! :)
240 tselem->flag= TSE_CLOSED;
241 te->store_index= ts->usedelem;
246 /* ******************** TREE MANAGEMENT ****************** */
248 void outliner_free_tree(ListBase *lb)
252 TreeElement *te= lb->first;
254 outliner_free_tree(&te->subtree);
257 if(te->flag & TE_FREE_NAME) MEM_freeN(te->name);
262 static void outliner_height(SpaceOops *soops, ListBase *lb, int *h)
264 TreeElement *te= lb->first;
266 TreeStoreElem *tselem= TREESTORE(te);
267 if((tselem->flag & TSE_CLOSED)==0)
268 outliner_height(soops, &te->subtree, h);
274 #if 0 // XXX this is currently disabled until te->xend is set correctly
275 static void outliner_width(SpaceOops *soops, ListBase *lb, int *w)
277 TreeElement *te= lb->first;
279 // TreeStoreElem *tselem= TREESTORE(te);
281 // XXX fixme... te->xend is not set yet
282 if(tselem->flag & TSE_CLOSED) {
286 outliner_width(soops, &te->subtree, w);
292 static void outliner_rna_width(SpaceOops *soops, ListBase *lb, int *w, int startx)
294 TreeElement *te= lb->first;
296 TreeStoreElem *tselem= TREESTORE(te);
297 // XXX fixme... (currently, we're using a fixed length of 100)!
305 if((tselem->flag & TSE_CLOSED)==0)
306 outliner_rna_width(soops, &te->subtree, w, startx+OL_X);
311 static TreeElement *outliner_find_tree_element(ListBase *lb, int store_index)
313 TreeElement *te= lb->first, *tes;
315 if(te->store_index==store_index) return te;
316 tes= outliner_find_tree_element(&te->subtree, store_index);
325 static ID *outliner_search_back(SpaceOops *soops, TreeElement *te, short idcode)
327 TreeStoreElem *tselem;
331 tselem= TREESTORE(te);
332 if(tselem->type==0 && te->idcode==idcode) return tselem->id;
345 static int treesort_alpha(const void *v1, const void *v2)
347 const struct treesort *x1= v1, *x2= v2;
350 /* first put objects last (hierarchy) */
351 comp= (x1->idcode==ID_OB);
352 if(x2->idcode==ID_OB) comp+=2;
354 if(comp==1) return 1;
355 else if(comp==2) return -1;
357 int comp= strcmp(x1->name, x2->name);
359 if( comp>0 ) return 1;
360 else if( comp<0) return -1;
366 /* this is nice option for later? doesnt look too useful... */
368 static int treesort_obtype_alpha(const void *v1, const void *v2)
370 const struct treesort *x1= v1, *x2= v2;
372 /* first put objects last (hierarchy) */
373 if(x1->idcode==ID_OB && x2->idcode!=ID_OB) return 1;
374 else if(x2->idcode==ID_OB && x1->idcode!=ID_OB) return -1;
376 /* 2nd we check ob type */
377 if(x1->idcode==ID_OB && x2->idcode==ID_OB) {
378 if( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return 1;
379 else if( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return -1;
383 int comp= strcmp(x1->name, x2->name);
385 if( comp>0 ) return 1;
386 else if( comp<0) return -1;
393 /* sort happens on each subtree individual */
394 static void outliner_sort(SpaceOops *soops, ListBase *lb)
397 TreeStoreElem *tselem;
402 tselem= TREESTORE(te);
404 /* sorting rules; only object lists or deformgroups */
405 if( (tselem->type==TSE_DEFGROUP) || (tselem->type==0 && te->idcode==ID_OB)) {
408 for(te= lb->first; te; te= te->next) totelem++;
411 struct treesort *tear= MEM_mallocN(totelem*sizeof(struct treesort), "tree sort array");
412 struct treesort *tp=tear;
415 for(te= lb->first; te; te= te->next, tp++) {
416 tselem= TREESTORE(te);
419 tp->idcode= te->idcode;
420 if(tselem->type && tselem->type!=TSE_DEFGROUP) tp->idcode= 0; // dont sort this
423 /* keep beginning of list */
424 for(tp= tear, skip=0; skip<totelem; skip++, tp++)
425 if(tp->idcode) break;
428 qsort(tear+skip, totelem-skip, sizeof(struct treesort), treesort_alpha);
430 lb->first=lb->last= NULL;
433 BLI_addtail(lb, tp->te);
440 for(te= lb->first; te; te= te->next) {
441 outliner_sort(soops, &te->subtree);
445 /* Prototype, see functions below */
446 static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv,
447 TreeElement *parent, short type, short index);
450 static void outliner_add_passes(SpaceOops *soops, TreeElement *tenla, ID *id, SceneRenderLayer *srl)
452 TreeStoreElem *tselem= TREESTORE(tenla);
455 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_COMBINED);
456 te->name= "Combined";
457 te->directdata= &srl->passflag;
459 /* save cpu cycles, but we add the first to invoke an open/close triangle */
460 if(tselem->flag & TSE_CLOSED)
463 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_Z);
465 te->directdata= &srl->passflag;
467 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_VECTOR);
469 te->directdata= &srl->passflag;
471 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_NORMAL);
473 te->directdata= &srl->passflag;
475 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_UV);
477 te->directdata= &srl->passflag;
479 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_MIST);
481 te->directdata= &srl->passflag;
483 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_INDEXOB);
484 te->name= "Index Object";
485 te->directdata= &srl->passflag;
487 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_RGBA);
489 te->directdata= &srl->passflag;
491 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_DIFFUSE);
493 te->directdata= &srl->passflag;
495 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_SPEC);
496 te->name= "Specular";
497 te->directdata= &srl->passflag;
499 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_SHADOW);
501 te->directdata= &srl->passflag;
503 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_AO);
505 te->directdata= &srl->passflag;
507 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_REFLECT);
508 te->name= "Reflection";
509 te->directdata= &srl->passflag;
511 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_REFRACT);
512 te->name= "Refraction";
513 te->directdata= &srl->passflag;
515 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_RADIO);
516 te->name= "Radiosity";
517 te->directdata= &srl->passflag;
522 /* special handling of hierarchical non-lib data */
523 static void outliner_add_bone(SpaceOops *soops, ListBase *lb, ID *id, Bone *curBone,
524 TreeElement *parent, int *a)
526 TreeElement *te= outliner_add_element(soops, lb, id, parent, TSE_BONE, *a);
529 te->name= curBone->name;
530 te->directdata= curBone;
532 for(curBone= curBone->childbase.first; curBone; curBone=curBone->next) {
533 outliner_add_bone(soops, &te->subtree, id, curBone, te, a);
537 static void outliner_add_scene_contents(SpaceOops *soops, ListBase *lb, Scene *sce, TreeElement *te)
539 SceneRenderLayer *srl;
540 TreeElement *tenla= outliner_add_element(soops, lb, sce, te, TSE_R_LAYER_BASE, 0);
543 tenla->name= "RenderLayers";
544 for(a=0, srl= sce->r.layers.first; srl; srl= srl->next, a++) {
545 TreeElement *tenlay= outliner_add_element(soops, &tenla->subtree, sce, te, TSE_R_LAYER, a);
546 tenlay->name= srl->name;
547 tenlay->directdata= &srl->passflag;
549 if(srl->light_override)
550 outliner_add_element(soops, &tenlay->subtree, srl->light_override, tenlay, TSE_LINKED_LAMP, 0);
551 if(srl->mat_override)
552 outliner_add_element(soops, &tenlay->subtree, srl->mat_override, tenlay, TSE_LINKED_MAT, 0);
554 outliner_add_passes(soops, tenlay, &sce->id, srl);
557 outliner_add_element(soops, lb, sce->world, te, 0, 0);
559 if(sce->scriptlink.scripts) {
561 tenla= outliner_add_element(soops, lb, sce, te, TSE_SCRIPT_BASE, 0);
562 tenla->name= "Scripts";
563 for (a=0; a<sce->scriptlink.totscript; a++) {
564 outliner_add_element(soops, &tenla->subtree, sce->scriptlink.scripts[a], tenla, 0, 0);
570 static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv,
571 TreeElement *parent, short type, short index)
574 TreeStoreElem *tselem;
578 if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
579 id= ((PointerRNA*)idv)->id.data;
580 if(!id) id= ((PointerRNA*)idv)->data;
583 if(id==NULL) return NULL;
585 te= MEM_callocN(sizeof(TreeElement), "tree elem");
586 /* add to the visual tree */
588 /* add to the storage */
589 check_persistant(soops, te, id, type, index);
590 tselem= TREESTORE(te);
593 te->index= index; // for data arays
594 if(ELEM3(type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP));
595 else if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM));
596 else if(type==TSE_ANIM_DATA);
598 te->name= id->name+2; // default, can be overridden by Library or non-ID data
599 te->idcode= GS(id->name);
604 /* tuck pointer back in object, to construct hierarchy */
605 if(GS(id->name)==ID_OB) id->newid= (ID *)te;
607 /* expand specific data always */
608 switch(GS(id->name)) {
610 te->name= ((Library *)id)->name;
613 outliner_add_scene_contents(soops, &te->subtree, (Scene *)id, te);
617 Object *ob= (Object *)id;
619 outliner_add_element(soops, &te->subtree, ob->adt, te, TSE_ANIM_DATA, 0);
621 if(ob->proxy && ob->id.lib==NULL)
622 outliner_add_element(soops, &te->subtree, ob->proxy, te, TSE_PROXY, 0);
624 outliner_add_element(soops, &te->subtree, ob->data, te, 0, 0);
627 bArmature *arm= ob->data;
630 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_POSE_BASE, 0);
634 if(arm->edbo==NULL && (ob->flag & OB_POSEMODE)) { // channels undefined in editmode, but we want the 'tenla' pose icon itself
635 int a= 0, const_index= 1000; /* ensure unique id for bone constraints */
637 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next, a++) {
638 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_POSE_CHANNEL, a);
639 ten->name= pchan->name;
640 ten->directdata= pchan;
641 pchan->prev= (bPoseChannel *)ten;
643 if(pchan->constraints.first) {
647 TreeElement *tenla1= outliner_add_element(soops, &ten->subtree, ob, ten, TSE_CONSTRAINT_BASE, 0);
650 tenla1->name= "Constraints";
651 for(con= pchan->constraints.first; con; con= con->next, const_index++) {
652 ten1= outliner_add_element(soops, &tenla1->subtree, ob, tenla1, TSE_CONSTRAINT, const_index);
653 #if 0 /* disabled as it needs to be reworked for recoded constraints system */
654 target= get_constraint_target(con, &str);
655 if(str && str[0]) ten1->name= str;
656 else if(target) ten1->name= target->id.name+2;
657 else ten1->name= con->name;
659 ten1->name= con->name;
660 ten1->directdata= con;
661 /* possible add all other types links? */
666 ten= tenla->subtree.first;
668 TreeElement *nten= ten->next, *par;
669 tselem= TREESTORE(ten);
670 if(tselem->type==TSE_POSE_CHANNEL) {
671 pchan= (bPoseChannel *)ten->directdata;
673 BLI_remlink(&tenla->subtree, ten);
674 par= (TreeElement *)pchan->parent->prev;
675 BLI_addtail(&par->subtree, ten);
681 /* restore prev pointers */
682 pchan= ob->pose->chanbase.first;
683 if(pchan) pchan->prev= NULL;
684 for(; pchan; pchan= pchan->next) {
685 if(pchan->next) pchan->next->prev= pchan;
690 if(ob->pose->agroups.first) {
693 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_POSEGRP_BASE, 0);
696 tenla->name= "Bone Groups";
697 for (agrp=ob->pose->agroups.first; agrp; agrp=agrp->next, a++) {
698 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_POSEGRP, a);
699 ten->name= agrp->name;
700 ten->directdata= agrp;
705 for(a=0; a<ob->totcol; a++)
706 outliner_add_element(soops, &te->subtree, ob->mat[a], te, 0, a);
708 if(ob->constraints.first) {
712 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_CONSTRAINT_BASE, 0);
716 tenla->name= "Constraints";
717 for(con= ob->constraints.first; con; con= con->next, a++) {
718 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_CONSTRAINT, a);
719 #if 0 /* disabled due to constraints system targets recode... code here needs review */
720 target= get_constraint_target(con, &str);
721 if(str && str[0]) ten->name= str;
722 else if(target) ten->name= target->id.name+2;
723 else ten->name= con->name;
725 ten->name= con->name;
726 ten->directdata= con;
727 /* possible add all other types links? */
731 if(ob->modifiers.first) {
733 TreeElement *temod = outliner_add_element(soops, &te->subtree, ob, te, TSE_MODIFIER_BASE, 0);
736 temod->name = "Modifiers";
737 for (index=0,md=ob->modifiers.first; md; index++,md=md->next) {
738 TreeElement *te = outliner_add_element(soops, &temod->subtree, ob, temod, TSE_MODIFIER, index);
742 if (md->type==eModifierType_Lattice) {
743 outliner_add_element(soops, &te->subtree, ((LatticeModifierData*) md)->object, te, TSE_LINKED_OB, 0);
744 } else if (md->type==eModifierType_Curve) {
745 outliner_add_element(soops, &te->subtree, ((CurveModifierData*) md)->object, te, TSE_LINKED_OB, 0);
746 } else if (md->type==eModifierType_Armature) {
747 outliner_add_element(soops, &te->subtree, ((ArmatureModifierData*) md)->object, te, TSE_LINKED_OB, 0);
748 } else if (md->type==eModifierType_Hook) {
749 outliner_add_element(soops, &te->subtree, ((HookModifierData*) md)->object, te, TSE_LINKED_OB, 0);
750 } else if (md->type==eModifierType_ParticleSystem) {
752 ParticleSystem *psys= ((ParticleSystemModifierData*) md)->psys;
754 ten = outliner_add_element(soops, &te->subtree, ob, te, TSE_LINKED_PSYS, 0);
755 ten->directdata = psys;
756 ten->name = psys->part->id.name+2;
760 if(ob->defbase.first) {
761 bDeformGroup *defgroup;
763 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_DEFGROUP_BASE, 0);
766 tenla->name= "Vertex Groups";
767 for (defgroup=ob->defbase.first; defgroup; defgroup=defgroup->next, a++) {
768 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_DEFGROUP, a);
769 ten->name= defgroup->name;
770 ten->directdata= defgroup;
773 if(ob->scriptlink.scripts) {
774 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_SCRIPT_BASE, 0);
777 tenla->name= "Scripts";
778 for (a=0; a<ob->scriptlink.totscript; a++) { /* ** */
779 outliner_add_element(soops, &tenla->subtree, ob->scriptlink.scripts[a], te, 0, 0);
784 outliner_add_element(soops, &te->subtree, ob->dup_group, te, 0, 0);
790 Mesh *me= (Mesh *)id;
792 //outliner_add_element(soops, &te->subtree, me->adt, te, TSE_ANIM_DATA, 0);
794 outliner_add_element(soops, &te->subtree, me->key, te, 0, 0);
795 for(a=0; a<me->totcol; a++)
796 outliner_add_element(soops, &te->subtree, me->mat[a], te, 0, a);
797 /* could do tfaces with image links, but the images are not grouped nicely.
798 would require going over all tfaces, sort images in use. etc... */
803 Curve *cu= (Curve *)id;
805 outliner_add_element(soops, &te->subtree, cu->adt, te, TSE_ANIM_DATA, 0);
807 for(a=0; a<cu->totcol; a++)
808 outliner_add_element(soops, &te->subtree, cu->mat[a], te, 0, a);
813 MetaBall *mb= (MetaBall *)id;
814 for(a=0; a<mb->totcol; a++)
815 outliner_add_element(soops, &te->subtree, mb->mat[a], te, 0, a);
820 Material *ma= (Material *)id;
822 outliner_add_element(soops, &te->subtree, ma->adt, te, TSE_ANIM_DATA, 0);
824 for(a=0; a<MAX_MTEX; a++) {
825 if(ma->mtex[a]) outliner_add_element(soops, &te->subtree, ma->mtex[a]->tex, te, 0, a);
833 outliner_add_element(soops, &te->subtree, tex->adt, te, TSE_ANIM_DATA, 0);
834 outliner_add_element(soops, &te->subtree, tex->ima, te, 0, 0);
839 Camera *ca= (Camera *)id;
840 outliner_add_element(soops, &te->subtree, ca->adt, te, TSE_ANIM_DATA, 0);
845 Lamp *la= (Lamp *)id;
847 outliner_add_element(soops, &te->subtree, la->adt, te, TSE_ANIM_DATA, 0);
849 for(a=0; a<MAX_MTEX; a++) {
850 if(la->mtex[a]) outliner_add_element(soops, &te->subtree, la->mtex[a]->tex, te, 0, a);
856 World *wrld= (World *)id;
858 outliner_add_element(soops, &te->subtree, wrld->adt, te, TSE_ANIM_DATA, 0);
860 for(a=0; a<MAX_MTEX; a++) {
861 if(wrld->mtex[a]) outliner_add_element(soops, &te->subtree, wrld->mtex[a]->tex, te, 0, a);
869 outliner_add_element(soops, &te->subtree, key->adt, te, TSE_ANIM_DATA, 0);
874 // XXX do we want to be exposing the F-Curves here?
875 //bAction *act= (bAction *)id;
880 bArmature *arm= (bArmature *)id;
887 for (ebone = arm->edbo->first; ebone; ebone=ebone->next, a++) {
888 ten= outliner_add_element(soops, &te->subtree, id, te, TSE_EBONE, a);
889 ten->directdata= ebone;
890 ten->name= ebone->name;
894 ten= te->subtree.first;
896 TreeElement *nten= ten->next, *par;
897 ebone= (EditBone *)ten->directdata;
899 BLI_remlink(&te->subtree, ten);
900 par= ebone->parent->temp;
901 BLI_addtail(&par->subtree, ten);
908 /* do not extend Armature when we have posemode */
909 tselem= TREESTORE(te->parent);
910 if( GS(tselem->id->name)==ID_OB && ((Object *)tselem->id)->flag & OB_POSEMODE);
913 for (curBone=arm->bonebase.first; curBone; curBone=curBone->next){
914 outliner_add_bone(soops, &te->subtree, id, curBone, te, &a);
922 else if(type==TSE_ANIM_DATA) {
923 AnimData *adt= (AnimData *)idv;
925 /* this element's info */
926 te->name= "Animation";
929 outliner_add_element(soops, &te->subtree, adt->action, te, 0, 0);
932 if (adt->drivers.first) {
933 TreeElement *ted= outliner_add_element(soops, &te->subtree, adt, te, TSE_DRIVER_BASE, 0);
937 ted->name= "Drivers";
939 for (fcu= adt->drivers.first; fcu; fcu= fcu->next) {
940 if (fcu->driver && fcu->driver->id) {
941 if (lastadded != fcu->driver->id) {
942 outliner_add_element(soops, &ted->subtree, fcu->driver->id, ted, TSE_LINKED_OB, 0);
943 lastadded= fcu->driver->id;
950 if (adt->nla_tracks.first) {
952 TreeElement *tenla= outliner_add_element(soops, &te->subtree, adt, te, TSE_NLA, 0);
956 tenla->name= "NLA Tracks";
958 for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) {
959 TreeElement *tenlt= outliner_add_element(soops, &te->subtree, nlt, te, TSE_NLA_TRACK, a);
964 for (strip=nlt->strips.first; strip; strip=strip->next, a++) {
965 ten= outliner_add_element(soops, &tenla->subtree, strip->act, tenla, TSE_NLA_ACTION, a);
966 if(ten) ten->directdata= strip;
972 else if(type==TSE_SEQUENCE) {
973 Sequence *seq= (Sequence*) idv;
977 * The idcode is a little hack, but the outliner
978 * only check te->idcode if te->type is equal to zero,
981 te->idcode= seq->type;
986 * This work like the sequence.
987 * If the sequence have a name (not default name)
988 * show it, in other case put the filename.
990 if(strcmp(seq->name, "SQ"))
993 if((seq->strip) && (seq->strip->stripdata))
994 te->name= seq->strip->stripdata->name;
995 else if((seq->strip) && (seq->strip->tstripdata) && (seq->strip->tstripdata->ibuf))
996 te->name= seq->strip->tstripdata->ibuf->name;
1001 if(seq->type==SEQ_META) {
1002 te->name= "Meta Strip";
1003 p= seq->seqbase.first;
1005 outliner_add_element(soops, &te->subtree, (void*)p, te, TSE_SEQUENCE, index);
1010 outliner_add_element(soops, &te->subtree, (void*)seq->strip, te, TSE_SEQ_STRIP, index);
1015 else if(type==TSE_SEQ_STRIP) {
1016 Strip *strip= (Strip *)idv;
1019 te->name= strip->dir;
1021 te->name= "Strip None";
1022 te->directdata= strip;
1024 else if(type==TSE_SEQUENCE_DUP) {
1025 Sequence *seq= (Sequence*)idv;
1027 te->idcode= seq->type;
1028 te->directdata= seq;
1029 te->name= seq->strip->stripdata->name;
1031 else if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
1032 PointerRNA pptr, propptr, *ptr= (PointerRNA*)idv;
1033 PropertyRNA *prop, *iterprop, *nameprop;
1034 PropertyType proptype;
1035 PropertySubType propsubtype;
1038 /* we do lazy build, for speed and to avoid infinite recusion */
1040 if(ptr->data == NULL) {
1041 te->name= "(empty)";
1043 else if(type == TSE_RNA_STRUCT) {
1045 nameprop= RNA_struct_name_property(ptr);
1048 te->name= RNA_property_string_get_alloc(ptr, nameprop, NULL, 0);
1049 te->flag |= TE_FREE_NAME;
1052 te->name= (char*)RNA_struct_ui_name(ptr);
1054 iterprop= RNA_struct_iterator_property(ptr);
1055 tot= RNA_property_collection_length(ptr, iterprop);
1057 /* auto open these cases */
1058 if(!parent || (RNA_property_type(&parent->rnaptr, 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);
1074 RNA_property_collection_lookup_int(ptr, iterprop, index, &propptr);
1077 proptype= RNA_property_type(ptr, prop);
1079 te->name= (char*)RNA_property_ui_name(ptr, 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(ptr, 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(ptr, prop);
1124 propsubtype= RNA_property_subtype(ptr, prop);
1125 tot= RNA_property_array_length(ptr, 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);
1449 void object_toggle_visibility_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1451 Scene *scene= NULL; // XXX
1452 Base *base= (Base *)te->directdata;
1454 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1456 base->object->restrictflag^=OB_RESTRICT_VIEW;
1460 void outliner_toggle_visibility(Scene *scene, SpaceOops *soops)
1463 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_visibility_cb);
1465 BIF_undo_push("Outliner toggle selectability");
1469 static void object_toggle_selectability_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1471 Scene *scene= NULL; // XXX
1472 Base *base= (Base *)te->directdata;
1474 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1476 base->object->restrictflag^=OB_RESTRICT_SELECT;
1480 void outliner_toggle_selectability(Scene *scene, SpaceOops *soops)
1483 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_selectability_cb);
1485 BIF_undo_push("Outliner toggle selectability");
1489 void object_toggle_renderability_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1491 Scene *scene= NULL; // XXX
1492 Base *base= (Base *)te->directdata;
1494 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1496 base->object->restrictflag^=OB_RESTRICT_RENDER;
1500 void outliner_toggle_renderability(Scene *scene, SpaceOops *soops)
1503 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_renderability_cb);
1505 BIF_undo_push("Outliner toggle renderability");
1509 void outliner_toggle_visible(SpaceOops *soops)
1512 if( outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1))
1513 outliner_set_flag(soops, &soops->tree, TSE_CLOSED, 0);
1515 outliner_set_flag(soops, &soops->tree, TSE_CLOSED, 1);
1517 BIF_undo_push("Outliner toggle visible");
1520 void outliner_toggle_selected(ARegion *ar, SpaceOops *soops)
1523 if( outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1))
1524 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
1526 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 1);
1528 BIF_undo_push("Outliner toggle selected");
1529 soops->storeflag |= SO_TREESTORE_REDRAW;
1533 static void outliner_openclose_level(SpaceOops *soops, ListBase *lb, int curlevel, int level, int open)
1536 TreeStoreElem *tselem;
1538 for(te= lb->first; te; te= te->next) {
1539 tselem= TREESTORE(te);
1542 if(curlevel<=level) tselem->flag &= ~TSE_CLOSED;
1545 if(curlevel>=level) tselem->flag |= TSE_CLOSED;
1548 outliner_openclose_level(soops, &te->subtree, curlevel+1, level, open);
1552 /* return 1 when levels were opened */
1553 static int outliner_open_back(SpaceOops *soops, TreeElement *te)
1555 TreeStoreElem *tselem;
1558 for (te= te->parent; te; te= te->parent) {
1559 tselem= TREESTORE(te);
1560 if (tselem->flag & TSE_CLOSED) {
1561 tselem->flag &= ~TSE_CLOSED;
1568 /* This is not used anywhere at the moment */
1570 static void outliner_open_reveal(SpaceOops *soops, ListBase *lb, TreeElement *teFind, int *found)
1573 TreeStoreElem *tselem;
1575 for (te= lb->first; te; te= te->next) {
1576 /* check if this tree-element was the one we're seeking */
1582 /* try to see if sub-tree contains it then */
1583 outliner_open_reveal(soops, &te->subtree, teFind, found);
1585 tselem= TREESTORE(te);
1586 if (tselem->flag & TSE_CLOSED)
1587 tselem->flag &= ~TSE_CLOSED;
1594 void outliner_one_level(SpaceOops *soops, int add)
1598 level= outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1);
1600 if(level) outliner_openclose_level(soops, &soops->tree, 1, level, 1);
1603 if(level==0) level= outliner_count_levels(soops, &soops->tree, 0);
1604 if(level) outliner_openclose_level(soops, &soops->tree, 1, level-1, 0);
1607 BIF_undo_push("Outliner show/hide one level");
1610 void outliner_page_up_down(Scene *scene, ARegion *ar, SpaceOops *soops, int up)
1612 int dy= ar->v2d.mask.ymax-ar->v2d.mask.ymin;
1614 if(up == -1) dy= -dy;
1615 ar->v2d.cur.ymin+= dy;
1616 ar->v2d.cur.ymax+= dy;
1618 soops->storeflag |= SO_TREESTORE_REDRAW;
1621 /* **** do clicks on items ******* */
1623 static int tree_element_active_renderlayer(TreeElement *te, TreeStoreElem *tselem, int set)
1627 /* paranoia check */
1628 if(te->idcode!=ID_SCE)
1630 sce= (Scene *)tselem->id;
1633 sce->r.actlay= tselem->nr;
1636 return sce->r.actlay==tselem->nr;
1641 static void tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te)
1643 TreeStoreElem *tselem= TREESTORE(te);
1647 int shift= 0; // XXX
1649 /* if id is not object, we search back */
1650 if(te->idcode==ID_OB) ob= (Object *)tselem->id;
1652 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1653 if(ob==OBACT) return;
1655 if(ob==NULL) return;
1657 sce= (Scene *)outliner_search_back(soops, te, ID_SCE);
1658 if(sce && scene != sce) {
1659 ED_screen_set_scene(C, sce);
1662 /* find associated base in current scene */
1663 for(base= FIRSTBASE; base; base= base->next)
1664 if(base->object==ob) break;
1668 if(base->flag & SELECT)
1669 ED_base_object_select(base, BA_DESELECT);
1671 ED_base_object_select(base, BA_SELECT);
1675 /* deleselect all */
1676 for(b= FIRSTBASE; b; b= b->next) {
1678 b->object->flag= b->flag;
1680 ED_base_object_select(base, BA_SELECT);
1683 ED_base_object_activate(C, base); /* adds notifier */
1686 // XXX if(ob!=obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
1687 // else countall(); /* exit_editmode calls f() */
1690 static int tree_element_active_material(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1695 /* we search for the object parent */
1696 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1697 if(ob==NULL || ob!=OBACT) return 0; // just paranoia
1699 /* searching in ob mat array? */
1701 if(tes->idcode==ID_OB) {
1703 ob->actcol= te->index+1;
1704 ob->colbits |= (1<<te->index); // make ob material active too
1707 if(ob->actcol == te->index+1)
1708 if(ob->colbits & (1<<te->index)) return 1;
1711 /* or we search for obdata material */
1714 ob->actcol= te->index+1;
1715 ob->colbits &= ~(1<<te->index); // make obdata material active too
1718 if(ob->actcol == te->index+1)
1719 if( (ob->colbits & (1<<te->index))==0 ) return 1;
1723 // XXX extern_set_butspace(F5KEY, 0); // force shading buttons
1724 BIF_preview_changed(ID_MA);
1729 static int tree_element_active_texture(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1732 TreeStoreElem *tselem, *tselemp;
1734 SpaceButs *sbuts=NULL;
1736 if(ob==NULL) return 0; // no active object
1738 tselem= TREESTORE(te);
1740 /* find buttons area (note, this is undefined really still, needs recode in blender) */
1741 /* XXX removed finding sbuts */
1743 /* where is texture linked to? */
1745 tselemp= TREESTORE(tep);
1747 if(tep->idcode==ID_WO) {
1748 World *wrld= (World *)tselemp->id;
1752 sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1755 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1756 wrld->texact= te->index;
1758 else if(tselemp->id == (ID *)(scene->world)) {
1759 if(wrld->texact==te->index) return 1;
1762 else if(tep->idcode==ID_LA) {
1763 Lamp *la= (Lamp *)tselemp->id;
1766 sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1769 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1770 la->texact= te->index;
1773 if(tselemp->id == ob->data) {
1774 if(la->texact==te->index) return 1;
1778 else if(tep->idcode==ID_MA) {
1779 Material *ma= (Material *)tselemp->id;
1782 //sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1785 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1786 ma->texact= (char)te->index;
1788 /* also set active material */
1789 ob->actcol= tep->index+1;
1791 else if(tep->flag & TE_ACTIVE) { // this is active material
1792 if(ma->texact==te->index) return 1;
1800 static int tree_element_active_lamp(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1804 /* we search for the object parent */
1805 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1806 if(ob==NULL || ob!=OBACT) return 0; // just paranoia
1809 // XXX extern_set_butspace(F5KEY, 0);
1810 BIF_preview_changed(ID_LA);
1817 static int tree_element_active_world(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1820 TreeStoreElem *tselem=NULL;
1825 tselem= TREESTORE(tep);
1826 sce= (Scene *)tselem->id;
1829 if(set) { // make new scene active
1830 if(sce && scene != sce) {
1831 // XXX ED_screen_set_scene(C, sce);
1835 if(tep==NULL || tselem->id == (ID *)scene) {
1837 // XXX extern_set_butspace(F8KEY, 0);
1846 static int tree_element_active_defgroup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1850 /* id in tselem is object */
1851 ob= (Object *)tselem->id;
1853 ob->actdef= te->index+1;
1854 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
1858 if(ob->actdef== te->index+1) return 1;
1863 static int tree_element_active_posegroup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1865 Object *ob= (Object *)tselem->id;
1869 ob->pose->active_group= te->index+1;
1873 if(ob==OBACT && ob->pose) {
1874 if (ob->pose->active_group== te->index+1) return 1;
1880 static int tree_element_active_posechannel(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1882 Object *ob= (Object *)tselem->id;
1883 bPoseChannel *pchan= te->directdata;
1886 if(!(pchan->bone->flag & BONE_HIDDEN_P)) {
1888 // XXX if(G.qual & LR_SHIFTKEY) deselectall_posearmature(ob, 2, 0); // 2 = clear active tag
1889 // else deselectall_posearmature(ob, 0, 0); // 0 = deselect
1890 pchan->bone->flag |= BONE_SELECTED|BONE_ACTIVE;
1895 if(ob==OBACT && ob->pose) {
1896 if (pchan->bone->flag & BONE_SELECTED) return 1;
1902 static int tree_element_active_bone(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1904 bArmature *arm= (bArmature *)tselem->id;
1905 Bone *bone= te->directdata;
1908 if(!(bone->flag & BONE_HIDDEN_P)) {
1909 // XXX if(G.qual & LR_SHIFTKEY) deselectall_posearmature(OBACT, 2, 0); // 2 is clear active tag
1910 // else deselectall_posearmature(OBACT, 0, 0);
1911 bone->flag |= BONE_SELECTED|BONE_ACTIVE;
1918 if(ob && ob->data==arm) {
1919 if (bone->flag & BONE_SELECTED) return 1;
1926 /* ebones only draw in editmode armature */
1927 static int tree_element_active_ebone(TreeElement *te, TreeStoreElem *tselem, int set)
1929 EditBone *ebone= te->directdata;
1930 // int shift= 0; // XXX
1933 if(!(ebone->flag & BONE_HIDDEN_A)) {
1935 // XXX if(shift) deselectall_armature(2, 0); // only clear active tag
1936 // else deselectall_armature(0, 0); // deselect
1938 ebone->flag |= BONE_SELECTED|BONE_ROOTSEL|BONE_TIPSEL|BONE_ACTIVE;
1940 if(ebone->parent && (ebone->flag & BONE_CONNECTED)) ebone->parent->flag |= BONE_TIPSEL;
1945 if (ebone->flag & BONE_SELECTED) return 1;
1950 static int tree_element_active_modifier(TreeElement *te, TreeStoreElem *tselem, int set)
1953 // XXX extern_set_butspace(F9KEY, 0);
1959 static int tree_element_active_psys(TreeElement *te, TreeStoreElem *tselem, int set)
1962 // Object *ob= (Object *)tselem->id;
1963 // ParticleSystem *psys= te->directdata;
1965 // XXX PE_change_act_psys(ob, psys);
1966 // XXX extern_set_butspace(F7KEY, 0);
1972 static int tree_element_active_constraint(TreeElement *te, TreeStoreElem *tselem, int set)
1975 // XXX extern_set_butspace(F7KEY, 0);
1981 static int tree_element_active_text(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1987 /* generic call for ID data check or make/check active in UI */
1988 static int tree_element_active(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1991 switch(te->idcode) {
1993 return tree_element_active_material(scene, soops, te, set);
1995 return tree_element_active_world(scene, soops, te, set);
1997 return tree_element_active_lamp(scene, soops, te, set);
1999 return tree_element_active_texture(scene, soops, te, set);
2001 return tree_element_active_text(scene, soops, te, set);
2006 static int tree_element_active_pose(TreeElement *te, TreeStoreElem *tselem, int set)
2008 Object *ob= (Object *)tselem->id;
2011 // XXX if(obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2012 // if(ob->flag & OB_POSEMODE) exit_posemode();
2013 // else enter_posemode();
2016 if(ob->flag & OB_POSEMODE) return 1;
2021 static int tree_element_active_sequence(TreeElement *te, TreeStoreElem *tselem, int set)
2023 Sequence *seq= (Sequence*) te->directdata;
2026 // XXX select_single_seq(seq, 1);
2029 if(seq->flag & SELECT)
2035 static int tree_element_active_sequence_dup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
2038 Editing *ed= seq_give_editing(scene, FALSE);
2040 seq= (Sequence*)te->directdata;
2042 if(seq->flag & SELECT)
2047 // XXX select_single_seq(seq, 1);
2048 p= ed->seqbasep->first;
2050 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
2055 // if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
2056 // XXX select_single_seq(p, 0);
2062 /* generic call for non-id data to make/check active in UI */
2063 /* Context can be NULL when set==0 */
2064 static int tree_element_type_active(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, int set)
2067 switch(tselem->type) {
2069 return tree_element_active_defgroup(scene, te, tselem, set);
2071 return tree_element_active_bone(scene, te, tselem, set);
2073 return tree_element_active_ebone(te, tselem, set);
2075 return tree_element_active_modifier(te, tselem, set);
2077 if(set) tree_element_set_active_object(C, scene, soops, te);
2078 else if(tselem->id==(ID *)OBACT) return 1;
2080 case TSE_LINKED_PSYS:
2081 return tree_element_active_psys(te, tselem, set);
2084 return tree_element_active_pose(te, tselem, set);
2086 case TSE_POSE_CHANNEL:
2087 return tree_element_active_posechannel(scene, te, tselem, set);
2088 case TSE_CONSTRAINT:
2089 return tree_element_active_constraint(te, tselem, set);
2091 return tree_element_active_renderlayer(te, tselem, set);
2093 return tree_element_active_posegroup(scene, te, tselem, set);
2095 return tree_element_active_sequence(te, tselem, set);
2097 case TSE_SEQUENCE_DUP:
2098 return tree_element_active_sequence_dup(scene, te, tselem, set);
2104 static int do_outliner_mouse_event(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, short event, float *mval)
2106 int shift= 0, ctrl= 0; // XXX
2108 if(mval[1]>te->ys && mval[1]<te->ys+OL_H) {
2109 TreeStoreElem *tselem= TREESTORE(te);
2112 /* open close icon, three things to check */
2113 if(event==RETKEY || event==PADENTER) openclose= 1; // enter opens/closes always
2114 else if((te->flag & TE_ICONROW)==0) { // hidden icon, no open/close
2115 if( mval[0]>te->xs && mval[0]<te->xs+OL_X) openclose= 1;
2120 /* all below close/open? */
2122 tselem->flag &= ~TSE_CLOSED;
2123 outliner_set_flag(soops, &te->subtree, TSE_CLOSED, !outliner_has_one_flag(soops, &te->subtree, TSE_CLOSED, 1));
2126 if(tselem->flag & TSE_CLOSED) tselem->flag &= ~TSE_CLOSED;
2127 else tselem->flag |= TSE_CLOSED;
2133 /* name and first icon */
2134 else if(mval[0]>te->xs && mval[0]<te->xend) {
2136 /* activate a name button? */
2137 if(event==LEFTMOUSE) {
2140 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))
2141 error("Cannot edit builtin name");
2142 else if(ELEM3(tselem->type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP))
2143 error("Cannot edit sequence name");
2144 else if(tselem->id->lib) {
2145 // XXX error_libdata();
2146 } else if(te->idcode == ID_LI && te->parent) {
2147 error("Cannot edit the path of an indirectly linked library");
2149 tselem->flag |= TSE_TEXTBUT;
2152 /* always makes active object */
2153 if(tselem->type!=TSE_SEQUENCE && tselem->type!=TSE_SEQ_STRIP && tselem->type!=TSE_SEQUENCE_DUP)
2154 tree_element_set_active_object(C, scene, soops, te);
2156 if(tselem->type==0) { // the lib blocks
2158 if(te->idcode==ID_SCE) {
2159 if(scene!=(Scene *)tselem->id) {
2160 ED_screen_set_scene(C, (Scene *)tselem->id);
2163 else if(ELEM5(te->idcode, ID_ME, ID_CU, ID_MB, ID_LT, ID_AR)) {
2164 // XXX if(obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2166 // enter_editmode(EM_WAITCURSOR);
2167 // extern_set_butspace(F9KEY, 0);
2169 } else { // rest of types
2170 tree_element_active(scene, soops, te, 1);
2174 else tree_element_type_active(C, scene, soops, te, tselem, 1);
2177 else if(event==RIGHTMOUSE) {
2178 /* select object that's clicked on and popup context menu */
2179 if (!(tselem->flag & TSE_SELECTED)) {
2181 if ( outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1) )
2182 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
2184 tselem->flag |= TSE_SELECTED;
2185 /* redraw, same as outliner_select function */
2186 soops->storeflag |= SO_TREESTORE_REDRAW;
2187 // XXX screen_swapbuffers();
2190 outliner_operation_menu(scene, ar, soops);
2196 for(te= te->subtree.first; te; te= te->next) {
2197 if(do_outliner_mouse_event(C, scene, ar, soops, te, event, mval)) return 1;
2202 /* event can enterkey, then it opens/closes */
2203 static int outliner_activate_click(bContext *C, wmOperator *op, wmEvent *event)
2205 Scene *scene= CTX_data_scene(C);
2206 ARegion *ar= CTX_wm_region(C);
2207 SpaceOops *soops= (SpaceOops*)CTX_wm_space_data(C);
2211 UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, fmval, fmval+1);
2213 for(te= soops->tree.first; te; te= te->next) {
2214 if(do_outliner_mouse_event(C, scene, ar, soops, te, event->type, fmval)) break;
2218 BIF_undo_push("Outliner click event");
2221 short selecting= -1;
2224 /* get row number - 100 here is just a dummy value since we don't need the column */
2225 UI_view2d_listview_view_to_cell(&ar->v2d, 1000, OL_H, 0.0f, 0.0f,
2226 fmval[0], fmval[1], NULL, &row);
2228 /* select relevant row */
2229 outliner_select(soops, &soops->tree, &row, &selecting);
2231 // XXX old flag found in old code, do we still use this?
2232 //soops->storeflag |= SO_TREESTORE_REDRAW;
2234 BIF_undo_push("Outliner selection event");
2237 ED_region_tag_redraw(ar);
2239 return OPERATOR_FINISHED;
2242 void OUTLINER_OT_activate_click(wmOperatorType *ot)
2244 ot->name= "Activate Click";
2245 ot->idname= "OUTLINER_OT_activate_click";
2247 ot->invoke= outliner_activate_click;
2249 ot->poll= ED_operator_outliner_active;
2254 /* recursive helper for function below */
2255 static void outliner_set_coordinates_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
2257 TreeStoreElem *tselem= TREESTORE(te);
2259 /* store coord and continue, we need coordinates for elements outside view too */
2260 te->xs= (float)startx;
2261 te->ys= (float)(*starty);
2264 if((tselem->flag & TSE_CLOSED)==0) {
2266 for(ten= te->subtree.first; ten; ten= ten->next) {
2267 outliner_set_coordinates_element(soops, ten, startx+OL_X, starty);
2273 /* to retrieve coordinates with redrawing the entire tree */
2274 static void outliner_set_coordinates(ARegion *ar, SpaceOops *soops)
2277 int starty= (int)(ar->v2d.tot.ymax)-OL_H;
2280 for(te= soops->tree.first; te; te= te->next) {
2281 outliner_set_coordinates_element(soops, te, startx, &starty);
2285 static TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, ID *id)
2287 TreeElement *te, *tes;
2288 TreeStoreElem *tselem;
2290 for(te= lb->first; te; te= te->next) {
2291 tselem= TREESTORE(te);
2292 if(tselem->type==0) {
2293 if(tselem->id==id) return te;
2294 /* only deeper on scene or object */
2295 if( te->idcode==ID_OB || te->idcode==ID_SCE) {
2296 tes= outliner_find_id(soops, &te->subtree, id);
2304 void outliner_show_active(Scene *scene, ARegion *ar, SpaceOops *so)
2309 if(OBACT == NULL) return;
2311 te= outliner_find_id(so, &so->tree, (ID *)OBACT);
2313 /* make te->ys center of view */
2314 ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
2316 ar->v2d.cur.ymax= (float)ytop;
2317 ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
2319 /* make te->xs ==> te->xend center of view */
2320 xdelta = (int)(te->xs - ar->v2d.cur.xmin);
2321 ar->v2d.cur.xmin += xdelta;
2322 ar->v2d.cur.xmax += xdelta;
2324 so->storeflag |= SO_TREESTORE_REDRAW;
2328 void outliner_show_selected(Scene *scene, ARegion *ar, SpaceOops *so)
2333 te= outliner_find_id(so, &so->tree, (ID *)OBACT);
2335 /* make te->ys center of view */
2336 ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
2338 ar->v2d.cur.ymax= (float)ytop;
2339 ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
2341 /* make te->xs ==> te->xend center of view */
2342 xdelta = (int)(te->xs - ar->v2d.cur.xmin);
2343 ar->v2d.cur.xmin += xdelta;
2344 ar->v2d.cur.xmax += xdelta;
2346 so->storeflag |= SO_TREESTORE_REDRAW;
2351 /* find next element that has this name */
2352 static TreeElement *outliner_find_named(SpaceOops *soops, ListBase *lb, char *name, int flags, TreeElement *prev, int *prevFound)
2354 TreeElement *te, *tes;
2356 for (te= lb->first; te; te= te->next) {
2359 /* determine if match */
2361 found= BLI_strcasestr(te->name, name)!=NULL;
2362 else if(flags==OL_FIND_CASE)
2363 found= strstr(te->name, name)!=NULL;
2364 else if(flags==OL_FIND_COMPLETE)
2365 found= BLI_strcasecmp(te->name, name)==0;
2367 found= strcmp(te->name, name)==0;
2370 /* name is right, but is element the previous one? */
2372 if ((te != prev) && (*prevFound))
2382 tes= outliner_find_named(soops, &te->subtree, name, flags, prev, prevFound);
2386 /* nothing valid found */
2390 /* tse is not in the treestore, we use its contents to find a match */
2391 static TreeElement *outliner_find_tse(SpaceOops *soops, TreeStoreElem *tse)
2393 TreeStore *ts= soops->treestore;
2394 TreeStoreElem *tselem;
2397 if(tse->id==NULL) return NULL;
2399 /* check if 'tse' is in treestore */
2401 for(a=0; a<ts->usedelem; a++, tselem++) {
2402 if((tse->type==0 && tselem->type==0) || (tselem->type==tse->type && tselem->nr==tse->nr)) {
2403 if(tselem->id==tse->id) {
2409 return outliner_find_tree_element(&soops->tree, a);
2415 /* Called to find an item based on name.
2417 void outliner_find_panel(Scene *scene, ARegion *ar, SpaceOops *soops, int again, int flags)
2419 TreeElement *te= NULL;
2420 TreeElement *last_find;
2421 TreeStoreElem *tselem;
2422 int ytop, xdelta, prevFound=0;
2425 /* get last found tree-element based on stored search_tse */
2426 last_find= outliner_find_tse(soops, &soops->search_tse);
2428 /* determine which type of search to do */
2429 if (again && last_find) {
2430 /* no popup panel - previous + user wanted to search for next after previous */
2431 BLI_strncpy(name, soops->search_string, 33);
2432 flags= soops->search_flags;
2434 /* try to find matching element */
2435 te= outliner_find_named(soops, &soops->tree, name, flags, last_find, &prevFound);
2437 /* no more matches after previous, start from beginning again */
2439 te= outliner_find_named(soops, &soops->tree, name, flags, last_find, &prevFound);
2443 /* pop up panel - no previous, or user didn't want search after previous */
2445 // XXX if (sbutton(name, 0, sizeof(name)-1, "Find: ") && name[0]) {
2446 // te= outliner_find_named(soops, &soops->tree, name, flags, NULL, &prevFound);
2448 // else return; /* XXX RETURN! XXX */
2451 /* do selection and reveal */
2453 tselem= TREESTORE(te);
2455 /* expand branches so that it will be visible, we need to get correct coordinates */
2456 if( outliner_open_back(soops, te))
2457 outliner_set_coordinates(ar, soops);
2459 /* deselect all visible, and select found element */
2460 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
2461 tselem->flag |= TSE_SELECTED;
2463 /* make te->ys center of view */
2464 ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
2466 ar->v2d.cur.ymax= (float)ytop;
2467 ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
2469 /* make te->xs ==> te->xend center of view */
2470 xdelta = (int)(te->xs - ar->v2d.cur.xmin);
2471 ar->v2d.cur.xmin += xdelta;
2472 ar->v2d.cur.xmax += xdelta;
2474 /* store selection */
2475 soops->search_tse= *tselem;
2477 BLI_strncpy(soops->search_string, name, 33);
2478 soops->search_flags= flags;
2481 soops->storeflag |= SO_TREESTORE_REDRAW;
2485 /* no tree-element found */
2486 error("Not found: %s", name);
2490 static int subtree_has_objects(SpaceOops *soops, ListBase *lb)
2493 TreeStoreElem *tselem;
2495 for(te= lb->first; te; te= te->next) {
2496 tselem= TREESTORE(te);
2497 if(tselem->type==0 && te->idcode==ID_OB) return 1;
2498 if( subtree_has_objects(soops, &te->subtree)) return 1;
2503 static void tree_element_show_hierarchy(Scene *scene, SpaceOops *soops, ListBase *lb)
2506 TreeStoreElem *tselem;
2508 /* open all object elems, close others */
2509 for(te= lb->first; te; te= te->next) {
2510 tselem= TREESTORE(te);
2512 if(tselem->type==0) {
2513 if(te->idcode==ID_SCE) {
2514 if(tselem->id!=(ID *)scene) tselem->flag |= TSE_CLOSED;
2515 else tselem->flag &= ~TSE_CLOSED;
2517 else if(te->idcode==ID_OB) {
2518 if(subtree_has_objects(soops, &te->subtree)) tselem->flag &= ~TSE_CLOSED;
2519 else tselem->flag |= TSE_CLOSED;
2522 else tselem->flag |= TSE_CLOSED;
2524 if(tselem->flag & TSE_CLOSED); else tree_element_show_hierarchy(scene, soops, &te->subtree);
2529 /* show entire object level hierarchy */
2530 void outliner_show_hierarchy(Scene *scene, SpaceOops *soops)
2533 tree_element_show_hierarchy(scene, soops, &soops->tree);
2535 BIF_undo_push("Outliner show hierarchy");
2538 void outliner_select(SpaceOops *soops, ListBase *lb, int *index, short *selecting)
2541 TreeStoreElem *tselem;
2543 for (te= lb->first; te && *index >= 0; te=te->next, (*index)--) {
2544 tselem= TREESTORE(te);
2546 /* if we've encountered the right item, set its 'Outliner' selection status */
2548 /* this should be the last one, so no need to do anything with index */
2549 if ((te->flag & TE_ICONROW)==0) {
2550 /* -1 value means toggle testing for now... */
2551 if (*selecting == -1) {
2552 if (tselem->flag & TSE_SELECTED)
2560 tselem->flag |= TSE_SELECTED;
2562 tselem->flag &= ~TSE_SELECTED;
2565 else if ((tselem->flag & TSE_CLOSED)==0) {
2566 /* Only try selecting sub-elements if we haven't hit the right element yet
2569 * Index must be reduced before supplying it to the sub-tree to try to do
2570 * selection, however, we need to increment it again for the next loop to
2571 * function correctly
2574 outliner_select(soops, &te->subtree, index, selecting);
2580 /* ************ SELECTION OPERATIONS ********* */
2582 static void set_operation_types(SpaceOops *soops, ListBase *lb,
2589 TreeStoreElem *tselem;
2591 for(te= lb->first; te; te= te->next) {
2592 tselem= TREESTORE(te);
2593 if(tselem->flag & TSE_SELECTED) {
2595 if(tselem->type==TSE_SEQUENCE)
2596 *datalevel= TSE_SEQUENCE;
2597 else if(tselem->type==TSE_SEQ_STRIP)
2598 *datalevel= TSE_SEQ_STRIP;
2599 else if(tselem->type==TSE_SEQUENCE_DUP)
2600 *datalevel= TSE_SEQUENCE_DUP;
2601 else if(*datalevel!=tselem->type) *datalevel= -1;
2604 int idcode= GS(tselem->id->name);
2613 case ID_ME: case ID_CU: case ID_MB: case ID_LT:
2614 case ID_LA: case ID_AR: case ID_CA:
2615 case ID_MA: case ID_TE: case ID_IP: case ID_IM:
2616 case ID_SO: case ID_KE: case ID_WO: case ID_AC:
2617 case ID_NLA: case ID_TXT: case ID_GR:
2618 if(*idlevel==0) *idlevel= idcode;
2619 else if(*idlevel!=idcode) *idlevel= -1;
2624 if((tselem->flag & TSE_CLOSED)==0) {
2625 set_operation_types(soops, &te->subtree,
2626 scenelevel, objectlevel, idlevel, datalevel);
2631 static void unlink_material_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2633 Material **matar=NULL;
2636 if( GS(tsep->id->name)==ID_OB) {
2637 Object *ob= (Object *)tsep->id;
2641 else if( GS(tsep->id->name)==ID_ME) {
2642 Mesh *me= (Mesh *)tsep->id;
2646 else if( GS(tsep->id->name)==ID_CU) {
2647 Curve *cu= (Curve *)tsep->id;
2651 else if( GS(tsep->id->name)==ID_MB) {
2652 MetaBall *mb= (MetaBall *)tsep->id;
2657 for(a=0; a<totcol; a++) {
2658 if(a==te->index && matar[a]) {
2665 static void unlink_texture_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2670 if( GS(tsep->id->name)==ID_MA) {
2671 Material *ma= (Material *)tsep->id;
2674 else if( GS(tsep->id->name)==ID_LA) {
2675 Lamp *la= (Lamp *)tsep->id;
2678 else if( GS(tsep->id->name)==ID_WO) {
2679 World *wrld= (World *)tsep->id;
2684 for(a=0; a<MAX_MTEX; a++) {
2685 if(a==te->index && mtex[a]) {
2687 mtex[a]->tex->id.us--;
2694 static void unlink_group_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2696 Group *group= (Group *)tselem->id;
2699 if( GS(tsep->id->name)==ID_OB) {
2700 Object *ob= (Object *)tsep->id;
2701 ob->dup_group= NULL;
2706 unlink_group(group);
2710 static void outliner_do_libdata_operation(SpaceOops *soops, ListBase *lb,
2711 void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *))
2714 TreeStoreElem *tselem;
2716 for(te=lb->first; te; te= te->next) {
2717 tselem= TREESTORE(te);
2718 if(tselem->flag & TSE_SELECTED) {
2719 if(tselem->type==0) {
2720 TreeStoreElem *tsep= TREESTORE(te->parent);
2721 operation_cb(te, tsep, tselem);
2724 if((tselem->flag & TSE_CLOSED)==0) {
2725 outliner_do_libdata_operation(soops, &te->subtree, operation_cb);
2732 static void object_select_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2734 Scene *scene= NULL; // XXX
2735 Base *base= (Base *)te->directdata;
2737 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
2738 if(base && ((base->object->restrictflag & OB_RESTRICT_VIEW)==0)) {
2739 base->flag |= SELECT;
2740 base->object->flag |= SELECT;
2744 static void object_deselect_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2747 Base *base= (Base *)te->directdata;
2749 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
2751 base->flag &= ~SELECT;
2752 base->object->flag &= ~SELECT;
2756 static void object_delete_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2759 Base *base= (Base *)te->directdata;
2761 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
2763 // check also library later
2764 // XXX if(obedit==base->object) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2767 G.f &= ~(G_VERTEXPAINT+G_TEXTUREPAINT+G_WEIGHTPAINT+G_SCULPTMODE);
2768 // XXX setcursor_space(SPACE_VIEW3D, CURSOR_STD);
2771 // XXX free_and_unlink_base(base);
2772 te->directdata= NULL;
2777 static void id_local_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2779 if(tselem->id->lib && (tselem->id->flag & LIB_EXTERN)) {
2780 tselem->id->lib= NULL;
2781 tselem->id->flag= LIB_LOCAL;
2782 new_id(0, tselem->id, 0);
2786 static void group_linkobs2scene_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2789 Group *group= (Group *)tselem->id;
2793 for(gob=group->gobject.first; gob; gob=gob->next) {
2794 base= object_in_scene(gob->ob, scene);
2796 base->object->flag |= SELECT;
2797 base->flag |= SELECT;
2800 base= MEM_callocN( sizeof(Base), "add_base");
2801 BLI_addhead(&scene->base, base);
2802 base->lay= (1<<20)-1; /*v3d->lay;*/ /* would be nice to use the 3d layer but the include's not here */
2803 gob->ob->flag |= SELECT;
2804 base->flag = gob->ob->flag;
2805 base->object= gob->ob;
2806 id_lib_extern((ID *)gob->ob); /* incase these are from a linked group */
2811 static void outliner_do_object_operation(Scene *scene, SpaceOops *soops, ListBase *lb,
2812 void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *))
2815 TreeStoreElem *tselem;
2817 for(te=lb->first; te; te= te->next) {
2818 tselem= TREESTORE(te);
2819 if(tselem->flag & TSE_SELECTED) {
2820 if(tselem->type==0 && te->idcode==ID_OB) {
2821 // when objects selected in other scenes... dunno if that should be allowed
2822 Scene *sce= (Scene *)outliner_search_back(soops, te, ID_SCE);
2823 if(sce && scene != sce) {
2824 // XXX ED_screen_set_scene(C, sce);
2827 operation_cb(te, NULL, tselem);
2830 if((tselem->flag & TSE_CLOSED)==0) {
2831 outliner_do_object_operation(scene, soops, &te->subtree, operation_cb);
2836 static void pchan_cb(int event, TreeElement *te, TreeStoreElem *tselem)
2838 bPoseChannel *pchan= (bPoseChannel *)te->directdata;
2841 pchan->bone->flag |= BONE_SELECTED;
2843 pchan->bone->flag &= ~BONE_SELECTED;
2845 pchan->bone->flag |= BONE_HIDDEN_P;
2846 pchan->bone->flag &= ~BONE_SELECTED;
2849 pchan->bone->flag &= ~BONE_HIDDEN_P;
2852 static void bone_cb(int event, TreeElement *te, TreeStoreElem *tselem)