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_action_types.h"
37 #include "DNA_armature_types.h"
38 #include "DNA_constraint_types.h"
39 #include "DNA_curve_types.h"
40 #include "DNA_camera_types.h"
41 #include "DNA_image_types.h"
42 #include "DNA_ipo_types.h"
43 #include "DNA_group_types.h"
44 #include "DNA_key_types.h"
45 #include "DNA_lamp_types.h"
46 #include "DNA_material_types.h"
47 #include "DNA_mesh_types.h"
48 #include "DNA_meta_types.h"
49 #include "DNA_modifier_types.h"
50 #include "DNA_nla_types.h"
51 #include "DNA_object_types.h"
52 #include "DNA_oops_types.h"
53 #include "DNA_particle_types.h"
54 #include "DNA_scene_types.h"
55 #include "DNA_screen_types.h"
56 #include "DNA_space_types.h"
57 #include "DNA_texture_types.h"
58 #include "DNA_text_types.h"
59 #include "DNA_world_types.h"
60 #include "DNA_sequence_types.h"
62 #include "BLI_blenlib.h"
64 #include "IMB_imbuf_types.h"
66 #include "BKE_constraint.h"
67 #include "BKE_context.h"
68 #include "BKE_deform.h"
69 #include "BKE_depsgraph.h"
70 #include "BKE_global.h"
71 #include "BKE_group.h"
72 #include "BKE_library.h"
74 #include "BKE_material.h"
75 #include "BKE_modifier.h"
76 #include "BKE_object.h"
77 #include "BKE_screen.h"
78 #include "BKE_scene.h"
79 #include "BKE_utildefines.h"
81 #include "ED_screen.h"
89 #include "BIF_glutil.h"
90 #include "BIF_editarmature.h"
92 #include "UI_interface.h"
93 #include "UI_interface_icons.h"
94 #include "UI_resources.h"
95 #include "UI_view2d.h"
98 #include "outliner_intern.h"
104 #include "PIL_time.h"
110 #define OL_TOG_RESTRICT_VIEWX 54
111 #define OL_TOG_RESTRICT_SELECTX 36
112 #define OL_TOG_RESTRICT_RENDERX 18
114 #define OL_TOGW OL_TOG_RESTRICT_VIEWX
118 #define TREESTORE(a) ((a)?soops->treestore->data+(a)->store_index:NULL)
120 /* ************* XXX **************** */
122 static void allqueue() {}
123 static void BIF_undo_push() {}
124 static void BIF_preview_changed() {}
125 static void set_scene() {}
126 static void error() {}
127 static int pupmenu() {return 0;}
129 /* ********************************** */
132 /* ******************** PROTOTYPES ***************** */
133 static void outliner_draw_tree_element(Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty);
134 static void outliner_do_object_operation(Scene *scene, SpaceOops *soops, ListBase *lb,
135 void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *));
138 /* ******************** PERSISTANT DATA ***************** */
140 static void outliner_storage_cleanup(SpaceOops *soops)
142 TreeStore *ts= soops->treestore;
145 TreeStoreElem *tselem;
148 /* each element used once, for ID blocks with more users to have each a treestore */
149 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) tselem->used= 0;
151 /* cleanup only after reading file or undo step */
152 if(soops->storeflag & SO_TREESTORE_CLEANUP) {
154 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) {
155 if(tselem->id==NULL) unused++;
159 if(ts->usedelem == unused) {
162 ts->usedelem= ts->totelem= 0;
165 TreeStoreElem *tsnewar, *tsnew;
167 tsnew=tsnewar= MEM_mallocN((ts->usedelem-unused)*sizeof(TreeStoreElem), "new tselem");
168 for(a=0, tselem= ts->data; a<ts->usedelem; a++, tselem++) {
176 ts->usedelem-= unused;
177 ts->totelem= ts->usedelem;
184 static void check_persistant(SpaceOops *soops, TreeElement *te, ID *id, short type, short nr)
187 TreeStoreElem *tselem;
190 /* case 1; no TreeStore */
191 if(soops->treestore==NULL) {
192 ts= soops->treestore= MEM_callocN(sizeof(TreeStore), "treestore");
194 ts= soops->treestore;
196 /* check if 'te' is in treestore */
198 for(a=0; a<ts->usedelem; a++, tselem++) {
199 if(tselem->id==id && tselem->used==0) {
200 if((type==0 && tselem->type==0) ||(tselem->type==type && tselem->nr==nr)) {
208 /* add 1 element to treestore */
209 if(ts->usedelem==ts->totelem) {
210 TreeStoreElem *tsnew;
212 tsnew= MEM_mallocN((ts->totelem+TS_CHUNK)*sizeof(TreeStoreElem), "treestore data");
214 memcpy(tsnew, ts->data, ts->totelem*sizeof(TreeStoreElem));
218 ts->totelem+= TS_CHUNK;
221 tselem= ts->data+ts->usedelem;
224 if(type) tselem->nr= nr; // we're picky! :)
228 tselem->flag= TSE_CLOSED;
229 te->store_index= ts->usedelem;
234 /* ******************** TREE MANAGEMENT ****************** */
236 void outliner_free_tree(ListBase *lb)
240 TreeElement *te= lb->first;
242 outliner_free_tree(&te->subtree);
248 static void outliner_height(SpaceOops *soops, ListBase *lb, int *h)
250 TreeElement *te= lb->first;
252 TreeStoreElem *tselem= TREESTORE(te);
253 if((tselem->flag & TSE_CLOSED)==0)
254 outliner_height(soops, &te->subtree, h);
260 static void outliner_width(SpaceOops *soops, ListBase *lb, int *w)
262 TreeElement *te= lb->first;
264 TreeStoreElem *tselem= TREESTORE(te);
265 if(tselem->flag & TSE_CLOSED) {
269 outliner_width(soops, &te->subtree, w);
274 static TreeElement *outliner_find_tree_element(ListBase *lb, int store_index)
276 TreeElement *te= lb->first, *tes;
278 if(te->store_index==store_index) return te;
279 tes= outliner_find_tree_element(&te->subtree, store_index);
288 static ID *outliner_search_back(SpaceOops *soops, TreeElement *te, short idcode)
290 TreeStoreElem *tselem;
294 tselem= TREESTORE(te);
295 if(tselem->type==0 && te->idcode==idcode) return tselem->id;
308 static int treesort_alpha(const void *v1, const void *v2)
310 const struct treesort *x1= v1, *x2= v2;
313 /* first put objects last (hierarchy) */
314 comp= (x1->idcode==ID_OB);
315 if(x2->idcode==ID_OB) comp+=2;
317 if(comp==1) return 1;
318 else if(comp==2) return -1;
320 int comp= strcmp(x1->name, x2->name);
322 if( comp>0 ) return 1;
323 else if( comp<0) return -1;
329 /* this is nice option for later? doesnt look too useful... */
331 static int treesort_obtype_alpha(const void *v1, const void *v2)
333 const struct treesort *x1= v1, *x2= v2;
335 /* first put objects last (hierarchy) */
336 if(x1->idcode==ID_OB && x2->idcode!=ID_OB) return 1;
337 else if(x2->idcode==ID_OB && x1->idcode!=ID_OB) return -1;
339 /* 2nd we check ob type */
340 if(x1->idcode==ID_OB && x2->idcode==ID_OB) {
341 if( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return 1;
342 else if( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return -1;
346 int comp= strcmp(x1->name, x2->name);
348 if( comp>0 ) return 1;
349 else if( comp<0) return -1;
356 /* sort happens on each subtree individual */
357 static void outliner_sort(SpaceOops *soops, ListBase *lb)
360 TreeStoreElem *tselem;
365 tselem= TREESTORE(te);
367 /* sorting rules; only object lists or deformgroups */
368 if( (tselem->type==TSE_DEFGROUP) || (tselem->type==0 && te->idcode==ID_OB)) {
371 for(te= lb->first; te; te= te->next) totelem++;
374 struct treesort *tear= MEM_mallocN(totelem*sizeof(struct treesort), "tree sort array");
375 struct treesort *tp=tear;
378 for(te= lb->first; te; te= te->next, tp++) {
379 tselem= TREESTORE(te);
382 tp->idcode= te->idcode;
383 if(tselem->type && tselem->type!=TSE_DEFGROUP) tp->idcode= 0; // dont sort this
386 /* keep beginning of list */
387 for(tp= tear, skip=0; skip<totelem; skip++, tp++)
388 if(tp->idcode) break;
391 qsort(tear+skip, totelem-skip, sizeof(struct treesort), treesort_alpha);
393 lb->first=lb->last= NULL;
396 BLI_addtail(lb, tp->te);
403 for(te= lb->first; te; te= te->next) {
404 outliner_sort(soops, &te->subtree);
408 /* Prototype, see functions below */
409 static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv,
410 TreeElement *parent, short type, short index);
413 static void outliner_add_passes(SpaceOops *soops, TreeElement *tenla, ID *id, SceneRenderLayer *srl)
415 TreeStoreElem *tselem= TREESTORE(tenla);
418 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_COMBINED);
419 te->name= "Combined";
420 te->directdata= &srl->passflag;
422 /* save cpu cycles, but we add the first to invoke an open/close triangle */
423 if(tselem->flag & TSE_CLOSED)
426 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_Z);
428 te->directdata= &srl->passflag;
430 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_VECTOR);
432 te->directdata= &srl->passflag;
434 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_NORMAL);
436 te->directdata= &srl->passflag;
438 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_UV);
440 te->directdata= &srl->passflag;
442 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_MIST);
444 te->directdata= &srl->passflag;
446 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_INDEXOB);
447 te->name= "Index Object";
448 te->directdata= &srl->passflag;
450 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_RGBA);
452 te->directdata= &srl->passflag;
454 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_DIFFUSE);
456 te->directdata= &srl->passflag;
458 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_SPEC);
459 te->name= "Specular";
460 te->directdata= &srl->passflag;
462 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_SHADOW);
464 te->directdata= &srl->passflag;
466 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_AO);
468 te->directdata= &srl->passflag;
470 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_REFLECT);
471 te->name= "Reflection";
472 te->directdata= &srl->passflag;
474 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_REFRACT);
475 te->name= "Refraction";
476 te->directdata= &srl->passflag;
478 te= outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, SCE_PASS_RADIO);
479 te->name= "Radiosity";
480 te->directdata= &srl->passflag;
485 /* special handling of hierarchical non-lib data */
486 static void outliner_add_bone(SpaceOops *soops, ListBase *lb, ID *id, Bone *curBone,
487 TreeElement *parent, int *a)
489 TreeElement *te= outliner_add_element(soops, lb, id, parent, TSE_BONE, *a);
492 te->name= curBone->name;
493 te->directdata= curBone;
495 for(curBone= curBone->childbase.first; curBone; curBone=curBone->next) {
496 outliner_add_bone(soops, &te->subtree, id, curBone, te, a);
500 static void outliner_add_scene_contents(SpaceOops *soops, ListBase *lb, Scene *sce, TreeElement *te)
502 SceneRenderLayer *srl;
503 TreeElement *tenla= outliner_add_element(soops, lb, sce, te, TSE_R_LAYER_BASE, 0);
506 tenla->name= "RenderLayers";
507 for(a=0, srl= sce->r.layers.first; srl; srl= srl->next, a++) {
508 TreeElement *tenlay= outliner_add_element(soops, &tenla->subtree, sce, te, TSE_R_LAYER, a);
509 tenlay->name= srl->name;
510 tenlay->directdata= &srl->passflag;
512 if(srl->light_override)
513 outliner_add_element(soops, &tenlay->subtree, srl->light_override, tenlay, TSE_LINKED_LAMP, 0);
514 if(srl->mat_override)
515 outliner_add_element(soops, &tenlay->subtree, srl->mat_override, tenlay, TSE_LINKED_MAT, 0);
517 outliner_add_passes(soops, tenlay, &sce->id, srl);
520 outliner_add_element(soops, lb, sce->world, te, 0, 0);
522 if(sce->scriptlink.scripts) {
524 tenla= outliner_add_element(soops, lb, sce, te, TSE_SCRIPT_BASE, 0);
525 tenla->name= "Scripts";
526 for (a=0; a<sce->scriptlink.totscript; a++) {
527 outliner_add_element(soops, &tenla->subtree, sce->scriptlink.scripts[a], tenla, 0, 0);
533 static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv,
534 TreeElement *parent, short type, short index)
537 TreeStoreElem *tselem;
541 if(id==NULL) return NULL;
543 te= MEM_callocN(sizeof(TreeElement), "tree elem");
544 /* add to the visual tree */
546 /* add to the storage */
547 check_persistant(soops, te, id, type, index);
548 tselem= TREESTORE(te);
551 te->index= index; // for data arays
552 if((type!=TSE_SEQUENCE) && (type != TSE_SEQ_STRIP) && (type != TSE_SEQUENCE_DUP)) {
553 te->name= id->name+2; // default, can be overridden by Library or non-ID data
554 te->idcode= GS(id->name);
559 /* tuck pointer back in object, to construct hierarchy */
560 if(GS(id->name)==ID_OB) id->newid= (ID *)te;
562 /* expand specific data always */
563 switch(GS(id->name)) {
565 te->name= ((Library *)id)->name;
568 outliner_add_scene_contents(soops, &te->subtree, (Scene *)id, te);
572 Object *ob= (Object *)id;
574 if(ob->proxy && ob->id.lib==NULL)
575 outliner_add_element(soops, &te->subtree, ob->proxy, te, TSE_PROXY, 0);
577 outliner_add_element(soops, &te->subtree, ob->data, te, 0, 0);
582 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_POSE_BASE, 0);
586 if(ob!=G.obedit && (ob->flag & OB_POSEMODE)) { // channels undefined in editmode, but we want the 'tenla' pose icon itself
587 int a= 0, const_index= 1000; /* ensure unique id for bone constraints */
589 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next, a++) {
590 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_POSE_CHANNEL, a);
591 ten->name= pchan->name;
592 ten->directdata= pchan;
593 pchan->prev= (bPoseChannel *)ten;
595 if(pchan->constraints.first) {
599 TreeElement *tenla1= outliner_add_element(soops, &ten->subtree, ob, ten, TSE_CONSTRAINT_BASE, 0);
602 tenla1->name= "Constraints";
603 for(con= pchan->constraints.first; con; con= con->next, const_index++) {
604 ten1= outliner_add_element(soops, &tenla1->subtree, ob, tenla1, TSE_CONSTRAINT, const_index);
605 #if 0 /* disabled as it needs to be reworked for recoded constraints system */
606 target= get_constraint_target(con, &str);
607 if(str && str[0]) ten1->name= str;
608 else if(target) ten1->name= target->id.name+2;
609 else ten1->name= con->name;
611 ten1->name= con->name;
612 ten1->directdata= con;
613 /* possible add all other types links? */
618 ten= tenla->subtree.first;
620 TreeElement *nten= ten->next, *par;
621 tselem= TREESTORE(ten);
622 if(tselem->type==TSE_POSE_CHANNEL) {
623 pchan= (bPoseChannel *)ten->directdata;
625 BLI_remlink(&tenla->subtree, ten);
626 par= (TreeElement *)pchan->parent->prev;
627 BLI_addtail(&par->subtree, ten);
633 /* restore prev pointers */
634 pchan= ob->pose->chanbase.first;
635 if(pchan) pchan->prev= NULL;
636 for(; pchan; pchan= pchan->next) {
637 if(pchan->next) pchan->next->prev= pchan;
642 if(ob->pose->agroups.first) {
645 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_POSEGRP_BASE, 0);
648 tenla->name= "Bone Groups";
649 for (agrp=ob->pose->agroups.first; agrp; agrp=agrp->next, a++) {
650 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_POSEGRP, a);
651 ten->name= agrp->name;
652 ten->directdata= agrp;
657 outliner_add_element(soops, &te->subtree, ob->ipo, te, 0, 0);
658 outliner_add_element(soops, &te->subtree, ob->action, te, 0, 0);
660 for(a=0; a<ob->totcol; a++)
661 outliner_add_element(soops, &te->subtree, ob->mat[a], te, 0, a);
663 if(ob->constraints.first) {
667 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_CONSTRAINT_BASE, 0);
671 tenla->name= "Constraints";
672 for(con= ob->constraints.first; con; con= con->next, a++) {
673 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_CONSTRAINT, a);
674 #if 0 /* disabled due to constraints system targets recode... code here needs review */
675 target= get_constraint_target(con, &str);
676 if(str && str[0]) ten->name= str;
677 else if(target) ten->name= target->id.name+2;
678 else ten->name= con->name;
680 ten->name= con->name;
681 ten->directdata= con;
682 /* possible add all other types links? */
686 if(ob->modifiers.first) {
688 TreeElement *temod = outliner_add_element(soops, &te->subtree, ob, te, TSE_MODIFIER_BASE, 0);
691 temod->name = "Modifiers";
692 for (index=0,md=ob->modifiers.first; md; index++,md=md->next) {
693 TreeElement *te = outliner_add_element(soops, &temod->subtree, ob, temod, TSE_MODIFIER, index);
697 if (md->type==eModifierType_Lattice) {
698 outliner_add_element(soops, &te->subtree, ((LatticeModifierData*) md)->object, te, TSE_LINKED_OB, 0);
699 } else if (md->type==eModifierType_Curve) {
700 outliner_add_element(soops, &te->subtree, ((CurveModifierData*) md)->object, te, TSE_LINKED_OB, 0);
701 } else if (md->type==eModifierType_Armature) {
702 outliner_add_element(soops, &te->subtree, ((ArmatureModifierData*) md)->object, te, TSE_LINKED_OB, 0);
703 } else if (md->type==eModifierType_Hook) {
704 outliner_add_element(soops, &te->subtree, ((HookModifierData*) md)->object, te, TSE_LINKED_OB, 0);
705 } else if (md->type==eModifierType_ParticleSystem) {
707 ParticleSystem *psys= ((ParticleSystemModifierData*) md)->psys;
709 ten = outliner_add_element(soops, &te->subtree, ob, te, TSE_LINKED_PSYS, 0);
710 ten->directdata = psys;
711 ten->name = psys->part->id.name+2;
715 if(ob->defbase.first) {
716 bDeformGroup *defgroup;
718 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_DEFGROUP_BASE, 0);
721 tenla->name= "Vertex Groups";
722 for (defgroup=ob->defbase.first; defgroup; defgroup=defgroup->next, a++) {
723 ten= outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_DEFGROUP, a);
724 ten->name= defgroup->name;
725 ten->directdata= defgroup;
728 if(ob->scriptlink.scripts) {
729 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_SCRIPT_BASE, 0);
732 tenla->name= "Scripts";
733 for (a=0; a<ob->scriptlink.totscript; a++) { /* ** */
734 outliner_add_element(soops, &tenla->subtree, ob->scriptlink.scripts[a], te, 0, 0);
739 outliner_add_element(soops, &te->subtree, ob->dup_group, te, 0, 0);
741 if(ob->nlastrips.first) {
744 TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_NLA, 0);
747 tenla->name= "NLA strips";
748 for (strip=ob->nlastrips.first; strip; strip=strip->next, a++) {
749 ten= outliner_add_element(soops, &tenla->subtree, strip->act, tenla, TSE_NLA_ACTION, a);
750 if(ten) ten->directdata= strip;
758 Mesh *me= (Mesh *)id;
759 outliner_add_element(soops, &te->subtree, me->ipo, te, 0, 0);
760 outliner_add_element(soops, &te->subtree, me->key, te, 0, 0);
761 for(a=0; a<me->totcol; a++)
762 outliner_add_element(soops, &te->subtree, me->mat[a], te, 0, a);
763 /* could do tfaces with image links, but the images are not grouped nicely.
764 would require going over all tfaces, sort images in use. etc... */
769 Curve *cu= (Curve *)id;
770 for(a=0; a<cu->totcol; a++)
771 outliner_add_element(soops, &te->subtree, cu->mat[a], te, 0, a);
776 MetaBall *mb= (MetaBall *)id;
777 for(a=0; a<mb->totcol; a++)
778 outliner_add_element(soops, &te->subtree, mb->mat[a], te, 0, a);
783 Material *ma= (Material *)id;
785 outliner_add_element(soops, &te->subtree, ma->ipo, te, 0, 0);
786 for(a=0; a<MAX_MTEX; a++) {
787 if(ma->mtex[a]) outliner_add_element(soops, &te->subtree, ma->mtex[a]->tex, te, 0, a);
795 outliner_add_element(soops, &te->subtree, tex->ipo, te, 0, 0);
796 outliner_add_element(soops, &te->subtree, tex->ima, te, 0, 0);
801 Camera *ca= (Camera *)id;
802 outliner_add_element(soops, &te->subtree, ca->ipo, te, 0, 0);
807 Lamp *la= (Lamp *)id;
808 outliner_add_element(soops, &te->subtree, la->ipo, te, 0, 0);
809 for(a=0; a<MAX_MTEX; a++) {
810 if(la->mtex[a]) outliner_add_element(soops, &te->subtree, la->mtex[a]->tex, te, 0, a);
816 World *wrld= (World *)id;
817 outliner_add_element(soops, &te->subtree, wrld->ipo, te, 0, 0);
818 for(a=0; a<MAX_MTEX; a++) {
819 if(wrld->mtex[a]) outliner_add_element(soops, &te->subtree, wrld->mtex[a]->tex, te, 0, a);
826 outliner_add_element(soops, &te->subtree, key->ipo, te, 0, 0);
833 Object *lastadded= NULL;
835 for (icu= ipo->curve.first; icu; icu= icu->next) {
836 if (icu->driver && icu->driver->ob) {
837 if (lastadded != icu->driver->ob) {
838 outliner_add_element(soops, &te->subtree, icu->driver->ob, te, TSE_LINKED_OB, 0);
839 lastadded= icu->driver->ob;
847 bAction *act= (bAction *)id;
848 bActionChannel *chan;
851 tselem= TREESTORE(parent);
852 for (chan=act->chanbase.first; chan; chan=chan->next, a++) {
853 outliner_add_element(soops, &te->subtree, chan->ipo, te, 0, a);
859 bArmature *arm= (bArmature *)id;
862 if(G.obedit && G.obedit->data==arm) {
866 for (ebone = G.edbo.first; ebone; ebone=ebone->next, a++) {
867 ten= outliner_add_element(soops, &te->subtree, id, te, TSE_EBONE, a);
868 ten->directdata= ebone;
869 ten->name= ebone->name;
873 ten= te->subtree.first;
875 TreeElement *nten= ten->next, *par;
876 ebone= (EditBone *)ten->directdata;
878 BLI_remlink(&te->subtree, ten);
879 par= ebone->parent->temp;
880 BLI_addtail(&par->subtree, ten);
887 /* do not extend Armature when we have posemode */
888 tselem= TREESTORE(te->parent);
889 if( GS(tselem->id->name)==ID_OB && ((Object *)tselem->id)->flag & OB_POSEMODE);
892 for (curBone=arm->bonebase.first; curBone; curBone=curBone->next){
893 outliner_add_bone(soops, &te->subtree, id, curBone, te, &a);
901 else if(type==TSE_SEQUENCE) {
902 Sequence *seq= (Sequence*) idv;
906 * The idcode is a little hack, but the outliner
907 * only check te->idcode if te->type is equal to zero,
910 te->idcode= seq->type;
915 * This work like the sequence.
916 * If the sequence have a name (not default name)
917 * show it, in other case put the filename.
919 if(strcmp(seq->name, "SQ"))
922 if((seq->strip) && (seq->strip->stripdata))
923 te->name= seq->strip->stripdata->name;
924 else if((seq->strip) && (seq->strip->tstripdata) && (seq->strip->tstripdata->ibuf))
925 te->name= seq->strip->tstripdata->ibuf->name;
930 if(seq->type==SEQ_META) {
931 te->name= "Meta Strip";
932 p= seq->seqbase.first;
934 outliner_add_element(soops, &te->subtree, (void*)p, te, TSE_SEQUENCE, index);
939 outliner_add_element(soops, &te->subtree, (void*)seq->strip, te, TSE_SEQ_STRIP, index);
944 else if(type==TSE_SEQ_STRIP) {
945 Strip *strip= (Strip *)idv;
948 te->name= strip->dir;
950 te->name= "Strip None";
951 te->directdata= strip;
953 else if(type==TSE_SEQUENCE_DUP) {
954 Sequence *seq= (Sequence*)idv;
956 te->idcode= seq->type;
958 te->name= seq->strip->stripdata->name;
963 static void outliner_make_hierarchy(SpaceOops *soops, ListBase *lb)
965 TreeElement *te, *ten, *tep;
966 TreeStoreElem *tselem;
968 /* build hierarchy */
972 tselem= TREESTORE(te);
974 if(tselem->type==0 && te->idcode==ID_OB) {
975 Object *ob= (Object *)tselem->id;
976 if(ob->parent && ob->parent->id.newid) {
978 tep= (TreeElement *)ob->parent->id.newid;
979 BLI_addtail(&tep->subtree, te);
980 // set correct parent pointers
981 for(te=tep->subtree.first; te; te= te->next) te->parent= tep;
988 /* Helped function to put duplicate sequence in the same tree. */
989 int need_add_seq_dup(Sequence *seq)
993 if((!seq->strip) || (!seq->strip->stripdata) || (!seq->strip->stripdata->name))
997 * First check backward, if we found a duplicate
998 * sequence before this, don't need it, just return.
1002 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1007 if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1014 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1019 if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1026 void add_seq_dup(SpaceOops *soops, Sequence *seq, TreeElement *te, short index)
1033 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1038 if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1039 ch= outliner_add_element(soops, &te->subtree, (void*)p, te, TSE_SEQUENCE, index);
1044 static void outliner_build_tree(Scene *scene, SpaceOops *soops)
1048 TreeElement *te, *ten;
1049 TreeStoreElem *tselem;
1050 int show_opened= soops->treestore==NULL; /* on first view, we open scenes */
1052 if(soops->tree.first && (soops->storeflag & SO_TREESTORE_REDRAW))
1055 outliner_free_tree(&soops->tree);
1056 outliner_storage_cleanup(soops);
1058 /* clear ob id.new flags */
1059 for(ob= G.main->object.first; ob; ob= ob->id.next) ob->id.newid= NULL;
1062 if(soops->outlinevis == SO_LIBRARIES) {
1065 for(lib= G.main->library.first; lib; lib= lib->id.next) {
1066 ten= outliner_add_element(soops, &soops->tree, lib, NULL, 0, 0);
1067 lib->id.newid= (ID *)ten;
1069 /* make hierarchy */
1070 ten= soops->tree.first;
1072 TreeElement *nten= ten->next, *par;
1073 tselem= TREESTORE(ten);
1074 lib= (Library *)tselem->id;
1076 BLI_remlink(&soops->tree, ten);
1077 par= (TreeElement *)lib->parent->id.newid;
1078 BLI_addtail(&par->subtree, ten);
1083 /* restore newid pointers */
1084 for(lib= G.main->library.first; lib; lib= lib->id.next)
1085 lib->id.newid= NULL;
1088 else if(soops->outlinevis == SO_ALL_SCENES) {
1090 for(sce= G.main->scene.first; sce; sce= sce->id.next) {
1091 te= outliner_add_element(soops, &soops->tree, sce, NULL, 0, 0);
1092 tselem= TREESTORE(te);
1093 if(sce==scene && show_opened)
1094 tselem->flag &= ~TSE_CLOSED;
1096 for(base= sce->base.first; base; base= base->next) {
1097 ten= outliner_add_element(soops, &te->subtree, base->object, te, 0, 0);
1098 ten->directdata= base;
1100 outliner_make_hierarchy(soops, &te->subtree);
1101 /* clear id.newid, to prevent objects be inserted in wrong scenes (parent in other scene) */
1102 for(base= sce->base.first; base; base= base->next) base->object->id.newid= NULL;
1105 else if(soops->outlinevis == SO_CUR_SCENE) {
1107 outliner_add_scene_contents(soops, &soops->tree, scene, NULL);
1109 for(base= scene->base.first; base; base= base->next) {
1110 ten= outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1111 ten->directdata= base;
1113 outliner_make_hierarchy(soops, &soops->tree);
1115 else if(soops->outlinevis == SO_VISIBLE) {
1116 for(base= scene->base.first; base; base= base->next) {
1117 if(base->lay & scene->lay)
1118 outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1120 outliner_make_hierarchy(soops, &soops->tree);
1122 else if(soops->outlinevis == SO_GROUPS) {
1126 for(group= G.main->group.first; group; group= group->id.next) {
1128 te= outliner_add_element(soops, &soops->tree, group, NULL, 0, 0);
1129 tselem= TREESTORE(te);
1131 for(go= group->gobject.first; go; go= go->next) {
1132 ten= outliner_add_element(soops, &te->subtree, go->ob, te, 0, 0);
1133 ten->directdata= NULL; /* eh, why? */
1135 outliner_make_hierarchy(soops, &te->subtree);
1136 /* clear id.newid, to prevent objects be inserted in wrong scenes (parent in other scene) */
1137 for(go= group->gobject.first; go; go= go->next) go->ob->id.newid= NULL;
1141 else if(soops->outlinevis == SO_SAME_TYPE) {
1144 for(base= scene->base.first; base; base= base->next) {
1145 if(base->object->type==ob->type) {
1146 ten= outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1147 ten->directdata= base;
1150 outliner_make_hierarchy(soops, &soops->tree);
1153 else if(soops->outlinevis == SO_SELECTED) {
1154 for(base= scene->base.first; base; base= base->next) {
1155 if(base->lay & scene->lay) {
1156 if(base==BASACT || (base->flag & SELECT)) {
1157 ten= outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
1158 ten->directdata= base;
1162 outliner_make_hierarchy(soops, &soops->tree);
1164 else if(soops->outlinevis==SO_SEQUENCE) {
1173 seq= ed->seqbasep->first;
1178 op= need_add_seq_dup(seq);
1180 ten= outliner_add_element(soops, &soops->tree, (void*)seq, NULL, TSE_SEQUENCE, 0);
1182 ten= outliner_add_element(soops, &soops->tree, (void*)seq, NULL, TSE_SEQUENCE_DUP, 0);
1183 add_seq_dup(soops, seq, ten, 0);
1189 ten= outliner_add_element(soops, &soops->tree, OBACT, NULL, 0, 0);
1190 if(ten) ten->directdata= BASACT;
1194 outliner_sort(soops, &soops->tree);
1197 /* **************** INTERACTIVE ************* */
1199 static int outliner_count_levels(SpaceOops *soops, ListBase *lb, int curlevel)
1202 int level=curlevel, lev;
1204 for(te= lb->first; te; te= te->next) {
1206 lev= outliner_count_levels(soops, &te->subtree, curlevel+1);
1207 if(lev>level) level= lev;
1212 static int outliner_has_one_flag(SpaceOops *soops, ListBase *lb, short flag, short curlevel)
1215 TreeStoreElem *tselem;
1218 for(te= lb->first; te; te= te->next) {
1219 tselem= TREESTORE(te);
1220 if(tselem->flag & flag) return curlevel;
1222 level= outliner_has_one_flag(soops, &te->subtree, flag, curlevel+1);
1223 if(level) return level;
1228 static void outliner_set_flag(SpaceOops *soops, ListBase *lb, short flag, short set)
1231 TreeStoreElem *tselem;
1233 for(te= lb->first; te; te= te->next) {
1234 tselem= TREESTORE(te);
1235 if(set==0) tselem->flag &= ~flag;
1236 else tselem->flag |= flag;
1237 outliner_set_flag(soops, &te->subtree, flag, set);
1241 void object_toggle_visibility_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1243 Scene *scene= NULL; // XXX
1244 Base *base= (Base *)te->directdata;
1246 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1248 base->object->restrictflag^=OB_RESTRICT_VIEW;
1252 void outliner_toggle_visibility(Scene *scene, SpaceOops *soops)
1255 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_visibility_cb);
1257 BIF_undo_push("Outliner toggle selectability");
1259 allqueue(REDRAWVIEW3D, 1);
1260 allqueue(REDRAWOOPS, 0);
1261 allqueue(REDRAWINFO, 1);
1264 static void object_toggle_selectability_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1266 Scene *scene= NULL; // XXX
1267 Base *base= (Base *)te->directdata;
1269 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1271 base->object->restrictflag^=OB_RESTRICT_SELECT;
1275 void outliner_toggle_selectability(Scene *scene, SpaceOops *soops)
1278 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_selectability_cb);
1280 BIF_undo_push("Outliner toggle selectability");
1282 allqueue(REDRAWVIEW3D, 1);
1283 allqueue(REDRAWOOPS, 0);
1284 allqueue(REDRAWINFO, 1);
1287 void object_toggle_renderability_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
1289 Scene *scene= NULL; // XXX
1290 Base *base= (Base *)te->directdata;
1292 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
1294 base->object->restrictflag^=OB_RESTRICT_RENDER;
1298 void outliner_toggle_renderability(Scene *scene, SpaceOops *soops)
1301 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_renderability_cb);
1303 BIF_undo_push("Outliner toggle renderability");
1305 allqueue(REDRAWVIEW3D, 1);
1306 allqueue(REDRAWOOPS, 0);
1307 allqueue(REDRAWINFO, 1);
1310 void outliner_toggle_visible(SpaceOops *soops)
1313 if( outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1))
1314 outliner_set_flag(soops, &soops->tree, TSE_CLOSED, 0);
1316 outliner_set_flag(soops, &soops->tree, TSE_CLOSED, 1);
1318 BIF_undo_push("Outliner toggle visible");
1321 void outliner_toggle_selected(ARegion *ar, SpaceOops *soops)
1324 if( outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1))
1325 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
1327 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 1);
1329 BIF_undo_push("Outliner toggle selected");
1330 soops->storeflag |= SO_TREESTORE_REDRAW;
1334 static void outliner_openclose_level(SpaceOops *soops, ListBase *lb, int curlevel, int level, int open)
1337 TreeStoreElem *tselem;
1339 for(te= lb->first; te; te= te->next) {
1340 tselem= TREESTORE(te);
1343 if(curlevel<=level) tselem->flag &= ~TSE_CLOSED;
1346 if(curlevel>=level) tselem->flag |= TSE_CLOSED;
1349 outliner_openclose_level(soops, &te->subtree, curlevel+1, level, open);
1353 /* return 1 when levels were opened */
1354 static int outliner_open_back(SpaceOops *soops, TreeElement *te)
1356 TreeStoreElem *tselem;
1359 for (te= te->parent; te; te= te->parent) {
1360 tselem= TREESTORE(te);
1361 if (tselem->flag & TSE_CLOSED) {
1362 tselem->flag &= ~TSE_CLOSED;
1369 /* This is not used anywhere at the moment */
1371 static void outliner_open_reveal(SpaceOops *soops, ListBase *lb, TreeElement *teFind, int *found)
1374 TreeStoreElem *tselem;
1376 for (te= lb->first; te; te= te->next) {
1377 /* check if this tree-element was the one we're seeking */
1383 /* try to see if sub-tree contains it then */
1384 outliner_open_reveal(soops, &te->subtree, teFind, found);
1386 tselem= TREESTORE(te);
1387 if (tselem->flag & TSE_CLOSED)
1388 tselem->flag &= ~TSE_CLOSED;
1395 void outliner_one_level(SpaceOops *soops, int add)
1399 level= outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1);
1401 if(level) outliner_openclose_level(soops, &soops->tree, 1, level, 1);
1404 if(level==0) level= outliner_count_levels(soops, &soops->tree, 0);
1405 if(level) outliner_openclose_level(soops, &soops->tree, 1, level-1, 0);
1408 BIF_undo_push("Outliner show/hide one level");
1411 void outliner_page_up_down(Scene *scene, ARegion *ar, SpaceOops *soops, int up)
1413 int dy= ar->v2d.mask.ymax-ar->v2d.mask.ymin;
1415 if(up == -1) dy= -dy;
1416 ar->v2d.cur.ymin+= dy;
1417 ar->v2d.cur.ymax+= dy;
1419 soops->storeflag |= SO_TREESTORE_REDRAW;
1422 /* **** do clicks on items ******* */
1424 static int tree_element_active_renderlayer(TreeElement *te, TreeStoreElem *tselem, int set)
1428 /* paranoia check */
1429 if(te->idcode!=ID_SCE)
1431 sce= (Scene *)tselem->id;
1434 sce->r.actlay= tselem->nr;
1435 allqueue(REDRAWBUTSSCENE, 0);
1438 return sce->r.actlay==tselem->nr;
1443 static void tree_element_active_object(Scene *scene, SpaceOops *soops, TreeElement *te)
1445 TreeStoreElem *tselem= TREESTORE(te);
1449 int shift= 0; // XXX
1451 /* if id is not object, we search back */
1452 if(te->idcode==ID_OB) ob= (Object *)tselem->id;
1454 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1455 if(ob==OBACT) return;
1457 if(ob==NULL) return;
1459 sce= (Scene *)outliner_search_back(soops, te, ID_SCE);
1460 if(sce && scene != sce) {
1461 // XXX if(G.obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
1465 /* find associated base in current scene */
1466 for(base= FIRSTBASE; base; base= base->next)
1467 if(base->object==ob) break;
1471 if(base->flag & SELECT) base->flag &= ~SELECT;
1472 else if ((base->object->restrictflag & OB_RESTRICT_VIEW)==0) base->flag |= SELECT;
1473 base->object->flag= base->flag;
1477 /* deleselect all */
1478 for(b= FIRSTBASE; b; b= b->next) {
1480 b->object->flag= b->flag;
1482 if ((base->object->restrictflag & OB_RESTRICT_VIEW)==0) {
1483 base->flag |= SELECT;
1484 base->object->flag |= SELECT;
1487 // XXX set_active_base(base); /* editview.c */
1489 allqueue(REDRAWVIEW3D, 1);
1490 allqueue(REDRAWOOPS, 0);
1491 allqueue(REDRAWINFO, 1);
1494 // XXX if(ob!=G.obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
1495 // else countall(); /* exit_editmode calls f() */
1498 static int tree_element_active_material(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1503 /* we search for the object parent */
1504 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1505 if(ob==NULL || ob!=OBACT) return 0; // just paranoia
1507 /* searching in ob mat array? */
1509 if(tes->idcode==ID_OB) {
1511 ob->actcol= te->index+1;
1512 ob->colbits |= (1<<te->index); // make ob material active too
1515 if(ob->actcol == te->index+1)
1516 if(ob->colbits & (1<<te->index)) return 1;
1519 /* or we search for obdata material */
1522 ob->actcol= te->index+1;
1523 ob->colbits &= ~(1<<te->index); // make obdata material active too
1526 if(ob->actcol == te->index+1)
1527 if( (ob->colbits & (1<<te->index))==0 ) return 1;
1531 // XXX extern_set_butspace(F5KEY, 0); // force shading buttons
1532 BIF_preview_changed(ID_MA);
1533 allqueue(REDRAWBUTSSHADING, 1);
1534 allqueue(REDRAWNODE, 0);
1535 allqueue(REDRAWOOPS, 0);
1536 allqueue(REDRAWIPO, 0);
1541 static int tree_element_active_texture(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1544 TreeStoreElem *tselem, *tselemp;
1546 SpaceButs *sbuts=NULL;
1548 if(ob==NULL) return 0; // no active object
1550 tselem= TREESTORE(te);
1552 /* find buttons area (note, this is undefined really still, needs recode in blender) */
1553 /* XXX removed finding sbuts */
1555 /* where is texture linked to? */
1557 tselemp= TREESTORE(tep);
1559 if(tep->idcode==ID_WO) {
1560 World *wrld= (World *)tselemp->id;
1564 sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1567 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1568 wrld->texact= te->index;
1570 else if(tselemp->id == (ID *)(scene->world)) {
1571 if(wrld->texact==te->index) return 1;
1574 else if(tep->idcode==ID_LA) {
1575 Lamp *la= (Lamp *)tselemp->id;
1578 sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1581 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1582 la->texact= te->index;
1585 if(tselemp->id == ob->data) {
1586 if(la->texact==te->index) return 1;
1590 else if(tep->idcode==ID_MA) {
1591 Material *ma= (Material *)tselemp->id;
1594 //sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
1597 // XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
1598 ma->texact= (char)te->index;
1600 /* also set active material */
1601 ob->actcol= tep->index+1;
1603 else if(tep->flag & TE_ACTIVE) { // this is active material
1604 if(ma->texact==te->index) return 1;
1612 static int tree_element_active_lamp(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1616 /* we search for the object parent */
1617 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1618 if(ob==NULL || ob!=OBACT) return 0; // just paranoia
1621 // XXX extern_set_butspace(F5KEY, 0);
1622 BIF_preview_changed(ID_LA);
1623 allqueue(REDRAWBUTSSHADING, 1);
1624 allqueue(REDRAWOOPS, 0);
1625 allqueue(REDRAWIPO, 0);
1632 static int tree_element_active_world(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1635 TreeStoreElem *tselem=NULL;
1640 tselem= TREESTORE(tep);
1641 sce= (Scene *)tselem->id;
1644 if(set) { // make new scene active
1645 if(sce && scene != sce) {
1646 // XXX if(G.obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
1651 if(tep==NULL || tselem->id == (ID *)scene) {
1653 // XXX extern_set_butspace(F8KEY, 0);
1662 static int tree_element_active_ipo(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1665 TreeStoreElem *tselems=NULL;
1668 /* we search for the object parent */
1669 ob= (Object *)outliner_search_back(soops, te, ID_OB);
1670 if(ob==NULL || ob!=OBACT) return 0; // just paranoia
1672 /* the parent of ipo */
1674 tselems= TREESTORE(tes);
1677 if(tes->idcode==ID_AC) {
1678 if(ob->ipoflag & OB_ACTION_OB)
1680 else if(ob->ipoflag & OB_ACTION_KEY)
1685 else ob->ipowin= tes->idcode;
1687 if(ob->ipowin==ID_MA) tree_element_active_material(scene, soops, tes, 1);
1688 else if(ob->ipowin==ID_AC) {
1689 bActionChannel *chan;
1691 for(chan=ob->action->chanbase.first; chan; chan= chan->next) {
1692 if(a==te->index) break;
1695 // XXX deselect_actionchannels(ob->action, 0);
1697 // select_channel(ob->action, chan, SELECT_ADD);
1698 allqueue(REDRAWACTION, ob->ipowin);
1699 allqueue(REDRAWVIEW3D, ob->ipowin);
1702 allqueue(REDRAWIPO, ob->ipowin);
1705 if(tes->idcode==ID_AC) {
1706 if(ob->ipoflag & OB_ACTION_OB)
1707 return ob->ipowin==ID_OB;
1708 else if(ob->ipoflag & OB_ACTION_KEY)
1709 return ob->ipowin==ID_KE;
1710 else if(ob->ipowin==ID_AC) {
1711 bActionChannel *chan;
1713 for(chan=ob->action->chanbase.first; chan; chan= chan->next) {
1714 if(a==te->index) break;
1717 // XXX if(chan==get_hilighted_action_channel(ob->action)) return 1;
1720 else if(ob->ipowin==tes->idcode) {
1721 if(ob->ipowin==ID_MA) {
1722 Material *ma= give_current_material(ob, ob->actcol);
1723 if(ma==(Material *)tselems->id) return 1;
1731 static int tree_element_active_defgroup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1735 /* id in tselem is object */
1736 ob= (Object *)tselem->id;
1738 ob->actdef= te->index+1;
1739 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
1740 allqueue(REDRAWVIEW3D, ob->ipowin);
1744 if(ob->actdef== te->index+1) return 1;
1749 static int tree_element_active_nla_action(TreeElement *te, TreeStoreElem *tselem, int set)
1752 bActionStrip *strip= te->directdata;
1754 // XXX deselect_nlachannel_keys(0);
1755 strip->flag |= ACTSTRIP_SELECT;
1756 allqueue(REDRAWNLA, 0);
1760 /* id in tselem is action */
1761 bActionStrip *strip= te->directdata;
1763 if(strip->flag & ACTSTRIP_SELECT) return 1;
1769 static int tree_element_active_posegroup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1771 Object *ob= (Object *)tselem->id;
1775 ob->pose->active_group= te->index+1;
1776 allqueue(REDRAWBUTSEDIT, 0);
1780 if(ob==OBACT && ob->pose) {
1781 if (ob->pose->active_group== te->index+1) return 1;
1787 static int tree_element_active_posechannel(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1789 Object *ob= (Object *)tselem->id;
1790 bPoseChannel *pchan= te->directdata;
1793 if(!(pchan->bone->flag & BONE_HIDDEN_P)) {
1795 // XXX if(G.qual & LR_SHIFTKEY) deselectall_posearmature(ob, 2, 0); // 2 = clear active tag
1796 // else deselectall_posearmature(ob, 0, 0); // 0 = deselect
1797 pchan->bone->flag |= BONE_SELECTED|BONE_ACTIVE;
1799 allqueue(REDRAWVIEW3D, 0);
1800 allqueue(REDRAWOOPS, 0);
1801 allqueue(REDRAWACTION, 0);
1805 if(ob==OBACT && ob->pose) {
1806 if (pchan->bone->flag & BONE_SELECTED) return 1;
1812 static int tree_element_active_bone(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1814 bArmature *arm= (bArmature *)tselem->id;
1815 Bone *bone= te->directdata;
1818 if(!(bone->flag & BONE_HIDDEN_P)) {
1819 // XXX if(G.qual & LR_SHIFTKEY) deselectall_posearmature(OBACT, 2, 0); // 2 is clear active tag
1820 // else deselectall_posearmature(OBACT, 0, 0);
1821 bone->flag |= BONE_SELECTED|BONE_ACTIVE;
1823 allqueue(REDRAWVIEW3D, 0);
1824 allqueue(REDRAWOOPS, 0);
1825 allqueue(REDRAWACTION, 0);
1831 if(ob && ob->data==arm) {
1832 if (bone->flag & BONE_SELECTED) return 1;
1839 /* ebones only draw in editmode armature */
1840 static int tree_element_active_ebone(TreeElement *te, TreeStoreElem *tselem, int set)
1842 EditBone *ebone= te->directdata;
1843 // int shift= 0; // XXX
1846 if(!(ebone->flag & BONE_HIDDEN_A)) {
1848 // XXX if(shift) deselectall_armature(2, 0); // only clear active tag
1849 // else deselectall_armature(0, 0); // deselect
1851 ebone->flag |= BONE_SELECTED|BONE_ROOTSEL|BONE_TIPSEL|BONE_ACTIVE;
1853 if(ebone->parent && (ebone->flag & BONE_CONNECTED)) ebone->parent->flag |= BONE_TIPSEL;
1855 allqueue(REDRAWVIEW3D, 0);
1856 allqueue(REDRAWOOPS, 0);
1857 allqueue(REDRAWACTION, 0);
1861 if (ebone->flag & BONE_SELECTED) return 1;
1866 static int tree_element_active_modifier(TreeElement *te, TreeStoreElem *tselem, int set)
1869 // XXX extern_set_butspace(F9KEY, 0);
1875 static int tree_element_active_psys(TreeElement *te, TreeStoreElem *tselem, int set)
1878 // Object *ob= (Object *)tselem->id;
1879 // ParticleSystem *psys= te->directdata;
1881 // XXX PE_change_act_psys(ob, psys);
1882 // XXX extern_set_butspace(F7KEY, 0);
1888 static int tree_element_active_constraint(TreeElement *te, TreeStoreElem *tselem, int set)
1891 // XXX extern_set_butspace(F7KEY, 0);
1897 static int tree_element_active_text(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1903 /* generic call for ID data check or make/check active in UI */
1904 static int tree_element_active(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
1907 switch(te->idcode) {
1909 return tree_element_active_material(scene, soops, te, set);
1911 return tree_element_active_world(scene, soops, te, set);
1913 return tree_element_active_lamp(scene, soops, te, set);
1915 return tree_element_active_ipo(scene, soops, te, set);
1917 return tree_element_active_texture(scene, soops, te, set);
1919 return tree_element_active_text(scene, soops, te, set);
1924 static int tree_element_active_pose(TreeElement *te, TreeStoreElem *tselem, int set)
1926 Object *ob= (Object *)tselem->id;
1929 // XXX if(G.obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
1930 // if(ob->flag & OB_POSEMODE) exit_posemode();
1931 // else enter_posemode();
1934 if(ob->flag & OB_POSEMODE) return 1;
1939 static int tree_element_active_sequence(TreeElement *te, TreeStoreElem *tselem, int set)
1941 Sequence *seq= (Sequence*) te->directdata;
1944 // XXX select_single_seq(seq, 1);
1945 allqueue(REDRAWSEQ, 0);
1948 if(seq->flag & SELECT)
1954 static int tree_element_active_sequence_dup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
1959 seq= (Sequence*)te->directdata;
1961 if(seq->flag & SELECT)
1966 // XXX select_single_seq(seq, 1);
1968 p= ed->seqbasep->first;
1970 if((!p->strip) || (!p->strip->stripdata) || (!p->strip->stripdata->name)) {
1975 // if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name))
1976 // XXX select_single_seq(p, 0);
1979 allqueue(REDRAWSEQ, 0);
1983 /* generic call for non-id data to make/check active in UI */
1984 static int tree_element_type_active(Scene *scene, SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, int set)
1987 switch(tselem->type) {
1988 case TSE_NLA_ACTION:
1989 return tree_element_active_nla_action(te, tselem, set);
1991 return tree_element_active_defgroup(scene, te, tselem, set);
1993 return tree_element_active_bone(scene, te, tselem, set);
1995 return tree_element_active_ebone(te, tselem, set);
1997 return tree_element_active_modifier(te, tselem, set);
1999 if(set) tree_element_active_object(scene, soops, te);
2000 else if(tselem->id==(ID *)OBACT) return 1;
2002 case TSE_LINKED_PSYS:
2003 return tree_element_active_psys(te, tselem, set);
2006 return tree_element_active_pose(te, tselem, set);
2008 case TSE_POSE_CHANNEL:
2009 return tree_element_active_posechannel(scene, te, tselem, set);
2010 case TSE_CONSTRAINT:
2011 return tree_element_active_constraint(te, tselem, set);
2013 return tree_element_active_renderlayer(te, tselem, set);
2015 return tree_element_active_posegroup(scene, te, tselem, set);
2017 return tree_element_active_sequence(te, tselem, set);
2019 case TSE_SEQUENCE_DUP:
2020 return tree_element_active_sequence_dup(scene, te, tselem, set);
2026 static int do_outliner_mouse_event(Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, short event, float *mval)
2028 int shift= 0, ctrl= 0; // XXX
2030 if(mval[1]>te->ys && mval[1]<te->ys+OL_H) {
2031 TreeStoreElem *tselem= TREESTORE(te);
2034 /* open close icon, three things to check */
2035 if(event==RETKEY || event==PADENTER) openclose= 1; // enter opens/closes always
2036 else if((te->flag & TE_ICONROW)==0) { // hidden icon, no open/close
2037 if( mval[0]>te->xs && mval[0]<te->xs+OL_X) openclose= 1;
2042 /* all below close/open? */
2044 tselem->flag &= ~TSE_CLOSED;
2045 outliner_set_flag(soops, &te->subtree, TSE_CLOSED, !outliner_has_one_flag(soops, &te->subtree, TSE_CLOSED, 1));
2048 if(tselem->flag & TSE_CLOSED) tselem->flag &= ~TSE_CLOSED;
2049 else tselem->flag |= TSE_CLOSED;
2055 /* name and first icon */
2056 else if(mval[0]>te->xs && mval[0]<te->xend) {
2058 /* activate a name button? */
2059 if(event==LEFTMOUSE) {
2062 if(ELEM9(tselem->type, 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))
2063 error("Cannot edit builtin name");
2064 else if(ELEM3(tselem->type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP))
2065 error("Cannot edit sequence name");
2066 else if(tselem->id->lib) {
2067 // XXX error_libdata();
2068 } else if(te->idcode == ID_LI && te->parent) {
2069 error("Cannot edit the path of an indirectly linked library");
2071 tselem->flag |= TSE_TEXTBUT;
2074 /* always makes active object */
2075 if(tselem->type!=TSE_SEQUENCE && tselem->type!=TSE_SEQ_STRIP && tselem->type!=TSE_SEQUENCE_DUP)
2076 tree_element_active_object(scene, soops, te);
2078 if(tselem->type==0) { // the lib blocks
2080 if(te->idcode==ID_SCE) {
2081 if(scene!=(Scene *)tselem->id) {
2082 // XXX if(G.obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2083 set_scene((Scene *)tselem->id);
2086 else if(ELEM5(te->idcode, ID_ME, ID_CU, ID_MB, ID_LT, ID_AR)) {
2087 // XXX if(G.obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2089 // enter_editmode(EM_WAITCURSOR);
2090 // extern_set_butspace(F9KEY, 0);
2092 } else { // rest of types
2093 tree_element_active(scene, soops, te, 1);
2097 else tree_element_type_active(scene, soops, te, tselem, 1);
2100 else if(event==RIGHTMOUSE) {
2101 /* select object that's clicked on and popup context menu */
2102 if (!(tselem->flag & TSE_SELECTED)) {
2104 if ( outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1) )
2105 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
2107 tselem->flag |= TSE_SELECTED;
2108 /* redraw, same as outliner_select function */
2109 soops->storeflag |= SO_TREESTORE_REDRAW;
2110 // XXX screen_swapbuffers();
2113 outliner_operation_menu(scene, ar, soops);
2119 for(te= te->subtree.first; te; te= te->next) {
2120 if(do_outliner_mouse_event(scene, ar, soops, te, event, mval)) return 1;
2125 /* event can enterkey, then it opens/closes */
2126 static int outliner_activate_click(bContext *C, wmOperator *op, wmEvent *event)
2128 Scene *scene= CTX_data_scene(C);
2129 ARegion *ar= CTX_wm_region(C);
2130 SpaceOops *soops= (SpaceOops*)CTX_wm_space_data(C);
2134 UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, fmval, fmval+1);
2136 for(te= soops->tree.first; te; te= te->next) {
2137 if(do_outliner_mouse_event(scene, ar, soops, te, event->type, fmval)) break;
2141 BIF_undo_push("Outliner click event");
2144 outliner_select(ar, soops);
2146 ED_region_tag_redraw(ar);
2148 return OPERATOR_FINISHED;
2151 void ED_OUTLINER_OT_activate_click(wmOperatorType *ot)
2153 ot->name= "Activate Click";
2154 ot->idname= "ED_OUTLINER_OT_activate_click";
2156 ot->invoke= outliner_activate_click;
2158 ot->poll= ED_operator_areaactive;
2163 /* recursive helper for function below */
2164 static void outliner_set_coordinates_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
2166 TreeStoreElem *tselem= TREESTORE(te);
2168 /* store coord and continue, we need coordinates for elements outside view too */
2169 te->xs= (float)startx;
2170 te->ys= (float)(*starty);
2173 if((tselem->flag & TSE_CLOSED)==0) {
2175 for(ten= te->subtree.first; ten; ten= ten->next) {
2176 outliner_set_coordinates_element(soops, ten, startx+OL_X, starty);
2182 /* to retrieve coordinates with redrawing the entire tree */
2183 static void outliner_set_coordinates(ARegion *ar, SpaceOops *soops)
2186 int starty= (int)(ar->v2d.tot.ymax)-OL_H;
2189 for(te= soops->tree.first; te; te= te->next) {
2190 outliner_set_coordinates_element(soops, te, startx, &starty);
2194 static TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, ID *id)
2196 TreeElement *te, *tes;
2197 TreeStoreElem *tselem;
2199 for(te= lb->first; te; te= te->next) {
2200 tselem= TREESTORE(te);
2201 if(tselem->type==0) {
2202 if(tselem->id==id) return te;
2203 /* only deeper on scene or object */
2204 if( te->idcode==ID_OB || te->idcode==ID_SCE) {
2205 tes= outliner_find_id(soops, &te->subtree, id);
2213 void outliner_show_active(Scene *scene, ARegion *ar, SpaceOops *so)
2218 if(OBACT == NULL) return;
2220 te= outliner_find_id(so, &so->tree, (ID *)OBACT);
2222 /* make te->ys center of view */
2223 ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
2225 ar->v2d.cur.ymax= (float)ytop;
2226 ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
2228 /* make te->xs ==> te->xend center of view */
2229 xdelta = (int)(te->xs - ar->v2d.cur.xmin);
2230 ar->v2d.cur.xmin += xdelta;
2231 ar->v2d.cur.xmax += xdelta;
2233 so->storeflag |= SO_TREESTORE_REDRAW;
2237 void outliner_show_selected(Scene *scene, ARegion *ar, SpaceOops *so)
2242 te= outliner_find_id(so, &so->tree, (ID *)OBACT);
2244 /* make te->ys center of view */
2245 ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
2247 ar->v2d.cur.ymax= (float)ytop;
2248 ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
2250 /* make te->xs ==> te->xend center of view */
2251 xdelta = (int)(te->xs - ar->v2d.cur.xmin);
2252 ar->v2d.cur.xmin += xdelta;
2253 ar->v2d.cur.xmax += xdelta;
2255 so->storeflag |= SO_TREESTORE_REDRAW;
2260 /* find next element that has this name */
2261 static TreeElement *outliner_find_named(SpaceOops *soops, ListBase *lb, char *name, int flags, TreeElement *prev, int *prevFound)
2263 TreeElement *te, *tes;
2265 for (te= lb->first; te; te= te->next) {
2268 /* determine if match */
2270 found= BLI_strcasestr(te->name, name)!=NULL;
2271 else if(flags==OL_FIND_CASE)
2272 found= strstr(te->name, name)!=NULL;
2273 else if(flags==OL_FIND_COMPLETE)
2274 found= BLI_strcasecmp(te->name, name)==0;
2276 found= strcmp(te->name, name)==0;
2279 /* name is right, but is element the previous one? */
2281 if ((te != prev) && (*prevFound))
2291 tes= outliner_find_named(soops, &te->subtree, name, flags, prev, prevFound);
2295 /* nothing valid found */
2299 /* tse is not in the treestore, we use its contents to find a match */
2300 static TreeElement *outliner_find_tse(SpaceOops *soops, TreeStoreElem *tse)
2302 TreeStore *ts= soops->treestore;
2303 TreeStoreElem *tselem;
2306 if(tse->id==NULL) return NULL;
2308 /* check if 'tse' is in treestore */
2310 for(a=0; a<ts->usedelem; a++, tselem++) {
2311 if((tse->type==0 && tselem->type==0) || (tselem->type==tse->type && tselem->nr==tse->nr)) {
2312 if(tselem->id==tse->id) {
2318 return outliner_find_tree_element(&soops->tree, a);
2324 /* Called to find an item based on name.
2326 void outliner_find_panel(Scene *scene, ARegion *ar, SpaceOops *soops, int again, int flags)
2328 TreeElement *te= NULL;
2329 TreeElement *last_find;
2330 TreeStoreElem *tselem;
2331 int ytop, xdelta, prevFound=0;
2334 /* get last found tree-element based on stored search_tse */
2335 last_find= outliner_find_tse(soops, &soops->search_tse);
2337 /* determine which type of search to do */
2338 if (again && last_find) {
2339 /* no popup panel - previous + user wanted to search for next after previous */
2340 BLI_strncpy(name, soops->search_string, 33);
2341 flags= soops->search_flags;
2343 /* try to find matching element */
2344 te= outliner_find_named(soops, &soops->tree, name, flags, last_find, &prevFound);
2346 /* no more matches after previous, start from beginning again */
2348 te= outliner_find_named(soops, &soops->tree, name, flags, last_find, &prevFound);
2352 /* pop up panel - no previous, or user didn't want search after previous */
2354 // XXX if (sbutton(name, 0, sizeof(name)-1, "Find: ") && name[0]) {
2355 // te= outliner_find_named(soops, &soops->tree, name, flags, NULL, &prevFound);
2357 // else return; /* XXX RETURN! XXX */
2360 /* do selection and reveil */
2362 tselem= TREESTORE(te);
2364 /* expand branches so that it will be visible, we need to get correct coordinates */
2365 if( outliner_open_back(soops, te))
2366 outliner_set_coordinates(ar, soops);
2368 /* deselect all visible, and select found element */
2369 outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
2370 tselem->flag |= TSE_SELECTED;
2372 /* make te->ys center of view */
2373 ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
2375 ar->v2d.cur.ymax= (float)ytop;
2376 ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
2378 /* make te->xs ==> te->xend center of view */
2379 xdelta = (int)(te->xs - ar->v2d.cur.xmin);
2380 ar->v2d.cur.xmin += xdelta;
2381 ar->v2d.cur.xmax += xdelta;
2383 /* store selection */
2384 soops->search_tse= *tselem;
2386 BLI_strncpy(soops->search_string, name, 33);
2387 soops->search_flags= flags;
2390 soops->storeflag |= SO_TREESTORE_REDRAW;
2394 /* no tree-element found */
2395 error("Not found: %s", name);
2399 static int subtree_has_objects(SpaceOops *soops, ListBase *lb)
2402 TreeStoreElem *tselem;
2404 for(te= lb->first; te; te= te->next) {
2405 tselem= TREESTORE(te);
2406 if(tselem->type==0 && te->idcode==ID_OB) return 1;
2407 if( subtree_has_objects(soops, &te->subtree)) return 1;
2412 static void tree_element_show_hierarchy(Scene *scene, SpaceOops *soops, ListBase *lb)
2415 TreeStoreElem *tselem;
2417 /* open all object elems, close others */
2418 for(te= lb->first; te; te= te->next) {
2419 tselem= TREESTORE(te);
2421 if(tselem->type==0) {
2422 if(te->idcode==ID_SCE) {
2423 if(tselem->id!=(ID *)scene) tselem->flag |= TSE_CLOSED;
2424 else tselem->flag &= ~TSE_CLOSED;
2426 else if(te->idcode==ID_OB) {
2427 if(subtree_has_objects(soops, &te->subtree)) tselem->flag &= ~TSE_CLOSED;
2428 else tselem->flag |= TSE_CLOSED;
2431 else tselem->flag |= TSE_CLOSED;
2433 if(tselem->flag & TSE_CLOSED); else tree_element_show_hierarchy(scene, soops, &te->subtree);
2438 /* show entire object level hierarchy */
2439 void outliner_show_hierarchy(Scene *scene, SpaceOops *soops)
2442 tree_element_show_hierarchy(scene, soops, &soops->tree);
2444 BIF_undo_push("Outliner show hierarchy");
2447 static void do_outliner_select(SpaceOops *soops, ListBase *lb, float y1, float y2, short *selecting)
2450 TreeStoreElem *tselem;
2452 if(y1>y2) SWAP(float, y1, y2);
2454 for(te= lb->first; te; te= te->next) {
2455 tselem= TREESTORE(te);
2457 if(te->ys + OL_H < y1) return;
2459 if((te->flag & TE_ICONROW)==0) {
2460 if(*selecting == -1) {
2461 if( tselem->flag & TSE_SELECTED) *selecting= 0;
2464 if(*selecting) tselem->flag |= TSE_SELECTED;
2465 else tselem->flag &= ~TSE_SELECTED;
2468 if((tselem->flag & TSE_CLOSED)==0) do_outliner_select(soops, &te->subtree, y1, y2, selecting);
2472 /* its own redraw loop... urm */
2473 void outliner_select(ARegion *ar, SpaceOops *so)
2477 float fmval[2], y1, y2;
2478 short yo=-1, selecting= -1;
2480 UI_view2d_region_to_view(&ar->v2d, event->x, event->y, fmval, fmval+1);
2484 while (get_mbut() & (L_MOUSE|R_MOUSE)) {
2485 UI_view2d_region_to_view(&ar->v2d, event->x, event->y, fmval, fmval+1);
2489 /* select the 'ouliner row' */
2490 do_outliner_select(so, &so->tree, y1, y2, &selecting);
2493 so->storeflag |= SO_TREESTORE_REDRAW;
2494 // XXX screen_swapbuffers();
2498 else PIL_sleep_ms(30);
2501 BIF_undo_push("Outliner selection");
2505 /* ************ SELECTION OPERATIONS ********* */
2507 static void set_operation_types(SpaceOops *soops, ListBase *lb,
2514 TreeStoreElem *tselem;
2516 for(te= lb->first; te; te= te->next) {
2517 tselem= TREESTORE(te);
2518 if(tselem->flag & TSE_SELECTED) {
2520 if(tselem->type==TSE_SEQUENCE)
2521 *datalevel= TSE_SEQUENCE;
2522 else if(tselem->type==TSE_SEQ_STRIP)
2523 *datalevel= TSE_SEQ_STRIP;
2524 else if(tselem->type==TSE_SEQUENCE_DUP)
2525 *datalevel= TSE_SEQUENCE_DUP;
2526 else if(*datalevel!=tselem->type) *datalevel= -1;
2529 int idcode= GS(tselem->id->name);
2538 case ID_ME: case ID_CU: case ID_MB: case ID_LT:
2539 case ID_LA: case ID_AR: case ID_CA:
2540 case ID_MA: case ID_TE: case ID_IP: case ID_IM:
2541 case ID_SO: case ID_KE: case ID_WO: case ID_AC:
2542 case ID_NLA: case ID_TXT: case ID_GR:
2543 if(*idlevel==0) *idlevel= idcode;
2544 else if(*idlevel!=idcode) *idlevel= -1;
2549 if((tselem->flag & TSE_CLOSED)==0) {
2550 set_operation_types(soops, &te->subtree,
2551 scenelevel, objectlevel, idlevel, datalevel);
2556 static void unlink_material_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2558 Material **matar=NULL;
2561 if( GS(tsep->id->name)==ID_OB) {
2562 Object *ob= (Object *)tsep->id;
2566 else if( GS(tsep->id->name)==ID_ME) {
2567 Mesh *me= (Mesh *)tsep->id;
2571 else if( GS(tsep->id->name)==ID_CU) {
2572 Curve *cu= (Curve *)tsep->id;
2576 else if( GS(tsep->id->name)==ID_MB) {
2577 MetaBall *mb= (MetaBall *)tsep->id;
2582 for(a=0; a<totcol; a++) {
2583 if(a==te->index && matar[a]) {
2590 static void unlink_texture_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2595 if( GS(tsep->id->name)==ID_MA) {
2596 Material *ma= (Material *)tsep->id;
2599 else if( GS(tsep->id->name)==ID_LA) {
2600 Lamp *la= (Lamp *)tsep->id;
2603 else if( GS(tsep->id->name)==ID_WO) {
2604 World *wrld= (World *)tsep->id;
2609 for(a=0; a<MAX_MTEX; a++) {
2610 if(a==te->index && mtex[a]) {
2612 mtex[a]->tex->id.us--;
2619 static void unlink_group_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2621 Group *group= (Group *)tselem->id;
2624 if( GS(tsep->id->name)==ID_OB) {
2625 Object *ob= (Object *)tsep->id;
2626 ob->dup_group= NULL;
2631 unlink_group(group);
2635 static void outliner_do_libdata_operation(SpaceOops *soops, ListBase *lb,
2636 void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *))
2639 TreeStoreElem *tselem;
2641 for(te=lb->first; te; te= te->next) {
2642 tselem= TREESTORE(te);
2643 if(tselem->flag & TSE_SELECTED) {
2644 if(tselem->type==0) {
2645 TreeStoreElem *tsep= TREESTORE(te->parent);
2646 operation_cb(te, tsep, tselem);
2649 if((tselem->flag & TSE_CLOSED)==0) {
2650 outliner_do_libdata_operation(soops, &te->subtree, operation_cb);
2657 static void object_select_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2659 Scene *scene= NULL; // XXX
2660 Base *base= (Base *)te->directdata;
2662 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
2663 if(base && ((base->object->restrictflag & OB_RESTRICT_VIEW)==0)) {
2664 base->flag |= SELECT;
2665 base->object->flag |= SELECT;
2669 static void object_deselect_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2672 Base *base= (Base *)te->directdata;
2674 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
2676 base->flag &= ~SELECT;
2677 base->object->flag &= ~SELECT;
2681 static void object_delete_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2684 Base *base= (Base *)te->directdata;
2686 if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
2688 // check also library later
2689 // XXX if(G.obedit==base->object) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
2692 G.f &= ~(G_VERTEXPAINT+G_TEXTUREPAINT+G_WEIGHTPAINT+G_SCULPTMODE);
2693 // XXX setcursor_space(SPACE_VIEW3D, CURSOR_STD);
2696 // XXX free_and_unlink_base(base);
2697 te->directdata= NULL;
2702 static void id_local_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2704 if(tselem->id->lib && (tselem->id->flag & LIB_EXTERN)) {
2705 tselem->id->lib= NULL;
2706 tselem->id->flag= LIB_LOCAL;
2707 new_id(0, tselem->id, 0);
2711 static void group_linkobs2scene_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
2714 Group *group= (Group *)tselem->id;
2718 for(gob=group->gobject.first; gob; gob=gob->next) {
2719 base= object_in_scene(gob->ob, scene);
2721 base->object->flag |= SELECT;
2722 base->flag |= SELECT;
2725 base= MEM_callocN( sizeof(Base), "add_base");
2726 BLI_addhead(&scene->base, base);
2727 base->lay= (1<<20)-1; /*v3d->lay;*/ /* would be nice to use the 3d layer but the include's not here */
2728 gob->ob->flag |= SELECT;
2729 base->flag = gob->ob->flag;
2730 base->object= gob->ob;
2731 id_lib_extern((ID *)gob->ob); /* incase these are from a linked group */
2736 static void outliner_do_object_operation(Scene *scene, SpaceOops *soops, ListBase *lb,
2737 void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *))
2740 TreeStoreElem *tselem;
2742 for(te=lb->first; te; te= te->next) {
2743 tselem= TREESTORE(te);
2744 if(tselem->flag & TSE_SELECTED) {
2745 if(tselem->type==0 && te->idcode==ID_OB) {
2746 // when objects selected in other scenes... dunno if that should be allowed
2747 Scene *sce= (Scene *)outliner_search_back(soops, te, ID_SCE);
2748 if(sce && scene != sce) {
2752 operation_cb(te, NULL, tselem);
2755 if((tselem->flag & TSE_CLOSED)==0) {
2756 outliner_do_object_operation(scene, soops, &te->subtree, operation_cb);
2761 static void pchan_cb(int event, TreeElement *te, TreeStoreElem *tselem)
2763 bPoseChannel *pchan= (bPoseChannel *)te->directdata;
2766 pchan->bone->flag |= BONE_SELECTED;
2768 pchan->bone->flag &= ~BONE_SELECTED;
2770 pchan->bone->flag |= BONE_HIDDEN_P;
2771 pchan->bone->flag &= ~BONE_SELECTED;
2774 pchan->bone->flag &= ~BONE_HIDDEN_P;
2777 static void bone_cb(int event, TreeElement *te, TreeStoreElem *tselem)
2779 Bone *bone= (Bone *)te->directdata;
2782 bone->flag |= BONE_SELECTED;
2784 bone->flag &= ~BONE_SELECTED;
2786 bone->flag |= BONE_HIDDEN_P;
2787 bone->flag &= ~BONE_SELECTED;
2790 bone->flag &= ~BONE_HIDDEN_P;
2793 static void ebone_cb(int event, TreeElement *te, TreeStoreElem *tselem)
2795 EditBone *ebone= (EditBone *)te->directdata;
2798 ebone->flag |= BONE_SELECTED;
2800 ebone->flag &= ~BONE_SELECTED;
2802 ebone->flag |= BONE_HIDDEN_A;
2803 ebone->flag &= ~BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL;
2806 ebone->flag &= ~BONE_HIDDEN_A;
2809 static void sequence_cb(int event, TreeElement *te, TreeStoreElem *tselem)
2811 // Sequence *seq= (Sequence*) te->directdata;
2813 // XXX select_single_seq(seq, 1);
2814 allqueue(REDRAWSEQ, 0);
2818 static void outliner_do_data_operation(SpaceOops *soops, int type, int event, ListBase *lb,
2819 void (*operation_cb)(int, TreeElement *, TreeStoreElem *))
2822 TreeStoreElem *tselem;
2824 for(te=lb->first; te; te= te->next) {
2825 tselem= TREESTORE(te);
2826 if(tselem->flag & TSE_SELECTED) {
2827 if(tselem->type==type) {
2828 operation_cb(event, te, tselem);
2831 if((tselem->flag & TSE_CLOSED)==0) {
2832 outliner_do_data_operation(soops, type, event, &te->subtree, operation_cb);
2837 void outliner_del(Scene *scene, ARegion *ar, SpaceOops *soops)
2840 // XXX if(soops->outlinevis==SO_SEQUENCE)
2843 // outliner_do_object_operation(scene, soops, &soops->tree, object_delete_cb);
2844 // DAG_scene_sort(scene);
2845 // BIF_undo_push("Delete Objects");
2847 // allqueue(REDRAWALL, 0);
2851 void outliner_operation_menu(Scene *scene, ARegion *ar, SpaceOops *soops)
2853 int scenelevel=0, objectlevel=0, idlevel=0, datalevel=0;
2855 set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
2858 if(objectlevel || datalevel || idlevel) error("Mixed selection");
2859 else pupmenu("Scene Operations%t|Delete");
2861 else if(objectlevel) {
2862 short event= pupmenu("Select%x1|Deselect%x2|Delete%x4|Toggle Visible%x6|Toggle Selectable%x7|Toggle Renderable%x8"); /* make local: does not work... it doesn't set lib_extern flags... so data gets lost */
2867 Scene *sce= scene; // to be able to delete, scenes are set...
2868 outliner_do_object_operation(scene, soops, &soops->tree, object_select_cb);
2873 str= "Select Objects";
2876 outliner_do_object_operation(scene, soops, &soops->tree, object_deselect_cb);
2877 str= "Deselect Objects";
2880 outliner_do_object_operation(scene, soops, &soops->tree, object_delete_cb);
2881 DAG_scene_sort(scene);
2882 str= "Delete Objects";
2884 else if(event==5) { /* disabled, see above (ton) */
2885 outliner_do_object_operation(scene, soops, &soops->tree, id_local_cb);
2886 str= "Localized Objects";
2889 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_visibility_cb);
2890 str= "Toggle Visibility";
2893 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_selectability_cb);
2894 str= "Toggle Selectability";
2897 outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_renderability_cb);
2898 str= "Toggle Renderability";
2902 allqueue(REDRAWALL, 0);
2906 if(idlevel==-1 || datalevel) error("Mixed selection");
2910 event = pupmenu("Unlink %x1|Make Local %x2|Link Group Objects to Scene%x3");
2912 event = pupmenu("Unlink %x1|Make Local %x2");
2918 outliner_do_libdata_operation(soops, &soops->tree, unlink_material_cb);
2919 BIF_undo_push("Unlink material");
2920 allqueue(REDRAWBUTSSHADING, 1);