static Object *add_hook_object_new(Scene *scene, Object *obedit) { Base *base, *basedit; Object *ob; ob= add_object(scene, OB_EMPTY); basedit = object_in_scene(obedit, scene); base = object_in_scene(ob, scene); base->lay = ob->lay = obedit->lay; /* icky, add_object sets new base as active. * so set it back to the original edit object */ scene->basact = basedit; return ob; }
void object_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { Base *base= (Base *)te->directdata; if(base==NULL) base= object_in_scene((Object *)tselem->id, scene); if(base) { base->object->restrictflag^=OB_RESTRICT_RENDER; } }
static void object_deselect_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { Base *base= (Base *)te->directdata; if (base==NULL) base= object_in_scene((Object *)tselem->id, scene); if (base) { base->flag &= ~SELECT; base->object->flag &= ~SELECT; } }
static void object_select_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { Base *base= (Base *)te->directdata; if (base==NULL) base= object_in_scene((Object *)tselem->id, scene); if (base && ((base->object->restrictflag & OB_RESTRICT_VIEW)==0)) { base->flag |= SELECT; base->object->flag |= SELECT; } }
void object_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { Base *base= (Base *)te->directdata; Object *ob = (Object *)tselem->id; /* add check for edit mode */ if(!common_restrict_check(C, ob)) return; if(base || (base= object_in_scene(ob, scene))) { if((base->object->restrictflag ^= OB_RESTRICT_VIEW)) { ED_base_object_select(base, BA_DESELECT); } } }
static void object_delete_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { Base *base= (Base *)te->directdata; if (base==NULL) base= object_in_scene((Object *)tselem->id, scene); if (base) { // check also library later if (scene->obedit==base->object) ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO); ED_base_object_free_and_unlink(CTX_data_main(C), scene, base); te->directdata= NULL; tselem->id= NULL; } }
static int tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set) { TreeStoreElem *tselem= TREESTORE(te); Scene *sce; Base *base; Object *ob= NULL; /* if id is not object, we search back */ if(te->idcode==ID_OB) ob= (Object *)tselem->id; else { ob= (Object *)outliner_search_back(soops, te, ID_OB); if(ob==OBACT) return 0; } if(ob==NULL) return 0; sce= (Scene *)outliner_search_back(soops, te, ID_SCE); if(sce && scene != sce) { ED_screen_set_scene(C, sce); } /* find associated base in current scene */ base= object_in_scene(ob, scene); if(base) { if(set==2) { /* swap select */ if(base->flag & SELECT) ED_base_object_select(base, BA_DESELECT); else ED_base_object_select(base, BA_SELECT); } else { /* deleselect all */ scene_deselect_all(scene); ED_base_object_select(base, BA_SELECT); } if(C) { ED_base_object_activate(C, base); /* adds notifier */ WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene); } } if(ob!=scene->obedit) ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO); return 1; }
static int tree_element_active_pose(bContext *C, Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *tselem, int set) { Object *ob= (Object *)tselem->id; Base *base= object_in_scene(ob, scene); if(set) { if(scene->obedit) ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO); if(ob->mode & OB_MODE_POSE) ED_armature_exit_posemode(C, base); else ED_armature_enter_posemode(C, base); } else { if(ob->mode & OB_MODE_POSE) return 1; } return 0; }
static void group_linkobs2scene_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { Group *group= (Group *)tselem->id; GroupObject *gob; Base *base; for (gob=group->gobject.first; gob; gob=gob->next) { base= object_in_scene(gob->ob, scene); if (base) { base->object->flag |= SELECT; base->flag |= SELECT; } else { /* link to scene */ base= MEM_callocN( sizeof(Base), "add_base"); BLI_addhead(&scene->base, base); base->lay= (1<<20)-1; /*v3d->lay;*/ /* would be nice to use the 3d layer but the include's not here */ gob->ob->flag |= SELECT; base->flag = gob->ob->flag; base->object= gob->ob; id_lib_extern((ID *)gob->ob); /* in case these are from a linked group */ } } }
void DocumentImporter::finish() { if(mImportStage!=General) return; /** TODO Break up and put into 2-pass parsing of DAE */ std::vector<const COLLADAFW::VisualScene*>::iterator it; for (it = vscenes.begin(); it != vscenes.end(); it++) { PointerRNA sceneptr, unit_settings; PropertyRNA *system, *scale; // TODO: create a new scene except the selected <visual_scene> - use current blender scene for it Scene *sce = CTX_data_scene(mContext); // for scene unit settings: system, scale_length RNA_id_pointer_create(&sce->id, &sceneptr); unit_settings = RNA_pointer_get(&sceneptr, "unit_settings"); system = RNA_struct_find_property(&unit_settings, "system"); scale = RNA_struct_find_property(&unit_settings, "scale_length"); switch(unit_converter.isMetricSystem()) { case UnitConverter::Metric: RNA_property_enum_set(&unit_settings, system, USER_UNIT_METRIC); break; case UnitConverter::Imperial: RNA_property_enum_set(&unit_settings, system, USER_UNIT_IMPERIAL); break; default: RNA_property_enum_set(&unit_settings, system, USER_UNIT_NONE); break; } RNA_property_float_set(&unit_settings, scale, unit_converter.getLinearMeter()); const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes(); for (unsigned int i = 0; i < roots.getCount(); i++) { write_node(roots[i], NULL, sce, NULL, false); } } armature_importer.set_tags_map(this->uid_tags_map); armature_importer.make_armatures(mContext); #if 0 armature_importer.fix_animation(); #endif for (std::vector<const COLLADAFW::VisualScene*>::iterator it = vscenes.begin(); it != vscenes.end(); it++) { const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes(); for (unsigned int i = 0; i < roots.getCount(); i++) translate_anim_recursive(roots[i],NULL,NULL); } if (libnode_ob.size()) { Scene *sce = CTX_data_scene(mContext); fprintf(stderr, "got %d library nodes to free\n", (int)libnode_ob.size()); // free all library_nodes std::vector<Object*>::iterator it; for (it = libnode_ob.begin(); it != libnode_ob.end(); it++) { Object *ob = *it; Base *base = object_in_scene(ob, sce); if (base) { BLI_remlink(&sce->base, base); free_libblock_us(&G.main->object, base->object); if (sce->basact==base) sce->basact= NULL; MEM_freeN(base); } } libnode_ob.clear(); DAG_scene_sort(CTX_data_main(mContext), sce); DAG_ids_flush_update(CTX_data_main(mContext), 0); } }
static int ed_marker_select(bContext *C, wmEvent *evt, int extend, int camera) { ListBase *markers= ED_context_get_markers(C); View2D *v2d= UI_view2d_fromcontext(C); float viewx; int x, y, cfra; if (markers == NULL) return OPERATOR_PASS_THROUGH; x= evt->x - CTX_wm_region(C)->winrct.xmin; y= evt->y - CTX_wm_region(C)->winrct.ymin; UI_view2d_region_to_view(v2d, x, y, &viewx, NULL); cfra= ED_markers_find_nearest_marker_time(markers, viewx); if (extend) select_timeline_marker_frame(markers, cfra, 1); else select_timeline_marker_frame(markers, cfra, 0); #ifdef DURIAN_CAMERA_SWITCH if (camera) { Scene *scene= CTX_data_scene(C); Base *base; TimeMarker *marker; int sel= 0; if (!extend) scene_deselect_all(scene); for (marker= markers->first; marker; marker= marker->next) { if(marker->frame==cfra) { sel= (marker->flag & SELECT); break; } } for (marker= markers->first; marker; marker= marker->next) { if (marker->camera) { if (marker->frame==cfra) { base= object_in_scene(marker->camera, scene); if (base) { ED_base_object_select(base, sel); if(sel) ED_base_object_activate(C, base); } } } } WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene); } #else (void)camera; #endif WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL); WM_event_add_notifier(C, NC_ANIMATION|ND_MARKERS, NULL); /* allowing tweaks, but needs OPERATOR_FINISHED, otherwise renaming fails... [#25987] */ return OPERATOR_FINISHED|OPERATOR_PASS_THROUGH; }
static int do_outliner_item_activate(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int extend, const float mval[2]) { if(mval[1]>te->ys && mval[1]<te->ys+UI_UNIT_Y) { TreeStoreElem *tselem= TREESTORE(te); int openclose= 0; /* open close icon */ if((te->flag & TE_ICONROW)==0) { // hidden icon, no open/close if( mval[0]>te->xs && mval[0]<te->xs+UI_UNIT_X) openclose= 1; } if(openclose) { /* all below close/open? */ if(extend) { tselem->flag &= ~TSE_CLOSED; outliner_set_flag(soops, &te->subtree, TSE_CLOSED, !outliner_has_one_flag(soops, &te->subtree, TSE_CLOSED, 1)); } else { if(tselem->flag & TSE_CLOSED) tselem->flag &= ~TSE_CLOSED; else tselem->flag |= TSE_CLOSED; } return 1; } /* name and first icon */ else if(mval[0]>te->xs+UI_UNIT_X && mval[0]<te->xend) { /* always makes active object */ if(tselem->type!=TSE_SEQUENCE && tselem->type!=TSE_SEQ_STRIP && tselem->type!=TSE_SEQUENCE_DUP) tree_element_set_active_object(C, scene, soops, te, 1 + (extend!=0 && tselem->type==0)); if(tselem->type==0) { // the lib blocks /* editmode? */ if(te->idcode==ID_SCE) { if(scene!=(Scene *)tselem->id) { ED_screen_set_scene(C, (Scene *)tselem->id); } } else if(te->idcode==ID_GR) { Group *gr= (Group *)tselem->id; GroupObject *gob; if(extend) { int sel= BA_SELECT; for(gob= gr->gobject.first; gob; gob= gob->next) { if(gob->ob->flag & SELECT) { sel= BA_DESELECT; break; } } for(gob= gr->gobject.first; gob; gob= gob->next) { ED_base_object_select(object_in_scene(gob->ob, scene), sel); } } else { scene_deselect_all(scene); for(gob= gr->gobject.first; gob; gob= gob->next) { if((gob->ob->flag & SELECT) == 0) ED_base_object_select(object_in_scene(gob->ob, scene), BA_SELECT); } } WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene); } else if(ELEM5(te->idcode, ID_ME, ID_CU, ID_MB, ID_LT, ID_AR)) { WM_operator_name_call(C, "OBJECT_OT_editmode_toggle", WM_OP_INVOKE_REGION_WIN, NULL); } else { // rest of types tree_element_active(C, scene, soops, te, 1); } } else tree_element_type_active(C, scene, soops, te, tselem, 1+(extend!=0)); return 1; } } for(te= te->subtree.first; te; te= te->next) { if(do_outliner_item_activate(C, scene, ar, soops, te, extend, mval)) return 1; } return 0; }