diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-04-13 13:39:25 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-04-13 13:39:25 +0400 |
commit | 54efb4c916f10a8dc8291aa33135385cef5cdd25 (patch) | |
tree | eac3ff321872f8fc2305d900f43881317e80b956 /source | |
parent | 4e66d4e676dcb9c67acc9b1b14ae1484e75322b3 (diff) |
external library, block locking spree. Many areas of blender allow changing of library data.
Added checks to the following areas
* half the material buttons
* multires, shapekeys, vert groups
* renaming a linked Object in the links could loose the object on next reload.
Made center functions check for library data as well as changing
the way it works.
Rather then centering all objects in the selection and stopping if it finds libdata, or a multiuser mesh.
It centers all that it can, and reports any objects that didnt center and why.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/src/buttons_editing.c | 27 | ||||
-rw-r--r-- | source/blender/src/buttons_object.c | 1 | ||||
-rw-r--r-- | source/blender/src/buttons_shading.c | 16 | ||||
-rw-r--r-- | source/blender/src/editobject.c | 303 |
4 files changed, 205 insertions, 142 deletions
diff --git a/source/blender/src/buttons_editing.c b/source/blender/src/buttons_editing.c index dc1ddae84f4..84ea33483cb 100644 --- a/source/blender/src/buttons_editing.c +++ b/source/blender/src/buttons_editing.c @@ -803,6 +803,7 @@ static void editing_panel_mesh_type(Object *ob, Mesh *me) block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_type", UI_EMBOSS, UI_HELV, curarea->win); if( uiNewPanel(curarea, block, "Mesh", "Editing", 320, 0, 318, 204)==0) return; + uiSetButLock(me->id.lib!=0, "Can't edit library data"); uiBlockBeginAlign(block); uiDefButBitS(block, TOG, ME_AUTOSMOOTH, REDRAWVIEW3D, "Auto Smooth",10,180,170,19, &me->flag, 0, 0, 0, 0, "Treats all set-smoothed faces with angles less than Degr: as 'smooth' during render"); @@ -2055,7 +2056,8 @@ static void editing_panel_modifiers(Object *ob) block= uiNewBlock(&curarea->uiblocks, "editing_panel_modifiers", UI_EMBOSS, UI_HELV, curarea->win); if( uiNewPanel(curarea, block, "Modifiers", "Editing", 640, 0, 318, 204)==0) return; - + + uiSetButLock(ob->id.lib!=0, "Can't edit library data"); uiNewPanelHeight(block, 204); uiDefBlockBut(block, modifiers_add_menu, ob, "Add Modifier", 0, 190, 130, 20, "Add a new modifier"); @@ -2107,6 +2109,9 @@ static void editing_panel_shapes(Object *ob) uiNewPanelTabbed("Modifiers", "Editing"); if( uiNewPanel(curarea, block, "Shapes", "Editing", 640, 0, 318, 204)==0) return; + /* Todo check data is library here */ + uiSetButLock(ob->id.lib!=0, "Can't edit library data"); + uiDefBut(block, BUT, B_ADDKEY, "Add Shape Key" , 10, 180, 150, 20, NULL, 0.0, 0.0, 0, 0, "Add new Shape Key"); key= ob_get_key(ob); @@ -4381,14 +4386,17 @@ static void editing_panel_links(Object *ob) block= uiNewBlock(&curarea->uiblocks, "editing_panel_links", UI_EMBOSS, UI_HELV, curarea->win); if(uiNewPanel(curarea, block, "Link and Materials", "Editing", 0, 0, 318, 204)==0) return; - + + if (ob) + uiSetButLock(ob->id.lib!=0, "Can't edit library data"); + buttons_active_id(&id, &idfrom); - + if(id) { int alone= 0; int local= 0; int browse= B_EDITBROWSE; - + if(ob->type==OB_MESH) { browse= B_MESHBROWSE; alone= B_MESHALONE; @@ -4424,6 +4432,7 @@ static void editing_panel_links(Object *ob) uiBlockSetCol(block, TH_AUTO); } if(ob) { + uiSetButLock(ob->id.lib!=0, "Can't edit library data"); but = uiDefBut(block, TEX, B_IDNAME, "OB:", xco, 180, 454-xco, YIC, ob->id.name+2, 0.0, 21.0, 0, 0, "Active Object name."); #ifdef WITH_VERSE if(ob->vnode) uiButSetFunc(but, test_and_send_idbutton_cb, ob, ob->id.name); @@ -4492,7 +4501,9 @@ static void editing_panel_links(Object *ob) } else { ID *id= ob->data; - + + uiSetButLock(id->lib!=0, "Can't edit library data"); + uiBlockBeginAlign (block); uiDefBut (block, BUT, B_NEWVGROUP, "New", 143, 90, 70, 21, 0, 0, 0, 0, 0, "Creates a new vertex group"); uiDefBut (block, BUT, B_DELVGROUP, "Delete", 213, 90, 70, 21, 0, 0, 0, 0, 0, "Removes the current vertex group"); @@ -5299,7 +5310,11 @@ void editing_panel_mesh_multires() block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_multires", UI_EMBOSS, UI_HELV, curarea->win); if(uiNewPanel(curarea, block, "Multires", "Editing", 500, 0, 318, 204)==0) return; - + + if (ob->id.lib || me->id.lib) + uiSetButLock(1, "Can't edit library data"); + + if(!me->mr) { but= uiDefBut(block,BUT,B_NOP,"Add Multires", cx,cy,268,19,0,0,0,0,0,""); uiButSetFunc(but,multires_make,ob,me); diff --git a/source/blender/src/buttons_object.c b/source/blender/src/buttons_object.c index a76fbe9cf2f..b22bc0fa2e1 100644 --- a/source/blender/src/buttons_object.c +++ b/source/blender/src/buttons_object.c @@ -1963,6 +1963,7 @@ static void object_panel_object(Object *ob) /* parent */ uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_OBJECTPANELPARENT, "Par:", xco+5, 180, 305-xco, 20, &ob->parent, "Parent Object"); + /* TODO, check for ob->id.lib */ but = uiDefButS(block, NUM, B_NOP, "PassIndex:", xco+5, 150, 305-xco, 20, &ob->index, 0.0, 1000.0, 0, 0, "Index # for the IndexOB render pass."); uiDefBlockBut(block, add_groupmenu, NULL, "Add to Group", 10,150,150,20, "Add Object to a new Group"); diff --git a/source/blender/src/buttons_shading.c b/source/blender/src/buttons_shading.c index 48b5aa1ea2c..51e1126bd21 100644 --- a/source/blender/src/buttons_shading.c +++ b/source/blender/src/buttons_shading.c @@ -2949,6 +2949,8 @@ static void material_panel_map_to(Material *ma, int from_nodes) uiNewPanelTabbed("Texture", "Material"); if(uiNewPanel(curarea, block, "Map To", "Material", 1600, 0, 318, 204)==0) return; + uiSetButLock(ma->id.lib!=NULL, "Can't edit library data"); + mtex= ma->mtex[ ma->texact ]; if(mtex==NULL) { mtex= &emptytex; @@ -3027,6 +3029,8 @@ static void material_panel_map_input(Object *ob, Material *ma) uiNewPanelTabbed("Texture", "Material"); if(uiNewPanel(curarea, block, "Map Input", "Material", 1280, 0, 318, 204)==0) return; + uiSetButLock(ma->id.lib!=NULL, "Can't edit library data"); + mtex= ma->mtex[ ma->texact ]; if(mtex==NULL) { mtex= &emptytex; @@ -3177,6 +3181,8 @@ static void material_panel_tramir(Material *ma) uiNewPanelTabbed("Shaders", "Material"); if(uiNewPanel(curarea, block, "Mirror Transp", "Material", 640, 0, 318, 204)==0) return; + uiSetButLock(ma->id.lib!=NULL, "Can't edit library data"); + uiDefButBitI(block, TOG, MA_RAYMIRROR, B_MATPRV,"Ray Mirror",210,180,100,20, &(ma->mode), 0, 0, 0, 0, "Enables raytracing for mirror reflection rendering"); uiBlockBeginAlign(block); @@ -3224,6 +3230,8 @@ static void material_panel_tramir_yafray(Material *ma) uiNewPanelTabbed("Shaders", "Material"); if(uiNewPanel(curarea, block, "Mirror Transp", "Material", 640, 0, 318, 204)==0) return; + uiSetButLock(ma->id.lib!=NULL, "Can't edit library data"); + /* material preset menu */ uiDefBut(block, LABEL, 0, "Mat.Preset", 20, 182, 100, 20, 0, 0.0, 0.0, 0, 0, ""); uiDefButI(block, MENU, B_MAT_YF_PRESET, mstr, 110, 182, 200, 20, &ma->YF_preset, 0.0, 0.0, 0, 0, "Basic material presets to start with"); @@ -3267,7 +3275,9 @@ static void material_panel_shading(Material *ma) block= uiNewBlock(&curarea->uiblocks, "material_panel_shading", UI_EMBOSS, UI_HELV, curarea->win); if(uiNewPanel(curarea, block, "Shaders", "Material", 640, 0, 318, 204)==0) return; - + + uiSetButLock(ma->id.lib!=NULL, "Can't edit library data"); + if(ma->mode & MA_HALO) { uiDefButF(block, NUM, B_MATPRV, "HaloSize: ", 10,155,190,18, &(ma->hasize), 0.0, 100.0, 10, 3, "Sets the dimension of the halo"); uiDefButS(block, NUMSLI, B_MATPRV, "Hard ", 10,135,190,18, &(ma->har), 1.0, 127.0, 0, 0, "Sets the hardness of the halo"); @@ -3372,7 +3382,9 @@ static void material_panel_ramps(Material *ma) block= uiNewBlock(&curarea->uiblocks, "material_panel_ramps", UI_EMBOSS, UI_HELV, curarea->win); uiNewPanelTabbed("Material", "Material"); if(uiNewPanel(curarea, block, "Ramps", "Material", 640, 0, 318, 204)==0) return; - + + uiSetButLock(ma->id.lib!=NULL, "Can't edit library data"); + uiBlockBeginAlign(block); uiBlockSetCol(block, TH_BUT_SETTING1); uiDefButS(block, ROW, B_REDR, "Show Col Ramp",10,180,150,20, &ma->ramp_show, 0, 0, 0, 0, "Show ramp buttons for material diffuse color"); diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c index 02adb3b12db..57de0de8cd1 100644 --- a/source/blender/src/editobject.c +++ b/source/blender/src/editobject.c @@ -1782,6 +1782,9 @@ void docenter(int centermode) EditVert *eve; float cent[3], centn[3], min[3], max[3], omat[3][3]; int a, total= 0; + + /* keep track of what is changed */ + int tot_change=0, tot_lib_error=0, tot_key_error=0, tot_multiuser_arm_error=0; MVert *mvert; if(G.scene->id.lib || G.vd==NULL) return; @@ -1817,21 +1820,18 @@ void docenter(int centermode) } recalc_editnormals(); + tot_change++; } } /* reset flags */ - base= FIRSTBASE; - while(base) { - if TESTBASELIB(base) { + for (base=FIRSTBASE; base; base= base->next) { + if TESTBASELIB(base) base->object->flag &= ~OB_DONE; - } - base= base->next; } - me= G.main->mesh.first; - while(me) { + + for (me= G.main->mesh.first; me; me= me->id.next) { me->flag &= ~ME_ISDONE; - me= me->id.next; } base= FIRSTBASE; @@ -1839,77 +1839,83 @@ void docenter(int centermode) if TESTBASELIB(base) { if((base->object->flag & OB_DONE)==0) { - base->object->flag |= OB_DONE; - if(G.obedit==0 && (me=get_mesh(base->object)) ) { + if(base->object->id.lib) { + tot_lib_error++; + } + else if(G.obedit==0 && (me=get_mesh(base->object)) ) { if(me->key) { - error("Can't change the center of a mesh with vertex keys"); - return; - } - - if(centermode==2) { - VECCOPY(cent, give_cursor()); - Mat4Invert(base->object->imat, base->object->obmat); - Mat4MulVecfl(base->object->imat, cent); + /*error("Can't change the center of a mesh with vertex keys"); + return;*/ + tot_key_error++; + } else if (me->id.lib) { + tot_lib_error++; } else { - INIT_MINMAX(min, max); + if(centermode==2) { + VECCOPY(cent, give_cursor()); + Mat4Invert(base->object->imat, base->object->obmat); + Mat4MulVecfl(base->object->imat, cent); + } else { + INIT_MINMAX(min, max); + mvert= me->mvert; + for(a=0; a<me->totvert; a++, mvert++) { + DO_MINMAX(mvert->co, min, max); + } + + cent[0]= (min[0]+max[0])/2.0f; + cent[1]= (min[1]+max[1])/2.0f; + cent[2]= (min[2]+max[2])/2.0f; + } + mvert= me->mvert; for(a=0; a<me->totvert; a++, mvert++) { - DO_MINMAX(mvert->co, min, max); + VecSubf(mvert->co, mvert->co, cent); } - - cent[0]= (min[0]+max[0])/2.0f; - cent[1]= (min[1]+max[1])/2.0f; - cent[2]= (min[2]+max[2])/2.0f; - } - - mvert= me->mvert; - for(a=0; a<me->totvert; a++, mvert++) { - VecSubf(mvert->co, mvert->co, cent); - } - me->flag |= ME_ISDONE; - - if(centermode) { - Mat3CpyMat4(omat, base->object->obmat); + me->flag |= ME_ISDONE; - VECCOPY(centn, cent); - Mat3MulVecfl(omat, centn); - base->object->loc[0]+= centn[0]; - base->object->loc[1]+= centn[1]; - base->object->loc[2]+= centn[2]; - - /* other users? */ - ob= G.main->object.first; - while(ob) { - if((ob->flag & OB_DONE)==0) { - tme= get_mesh(ob); - - if(tme==me) { - - ob->flag |= OB_DONE; - ob->recalc= OB_RECALC_OB|OB_RECALC_DATA; - - Mat3CpyMat4(omat, ob->obmat); - VECCOPY(centn, cent); - Mat3MulVecfl(omat, centn); - ob->loc[0]+= centn[0]; - ob->loc[1]+= centn[1]; - ob->loc[2]+= centn[2]; + if(centermode) { + Mat3CpyMat4(omat, base->object->obmat); + + VECCOPY(centn, cent); + Mat3MulVecfl(omat, centn); + base->object->loc[0]+= centn[0]; + base->object->loc[1]+= centn[1]; + base->object->loc[2]+= centn[2]; + + /* other users? */ + ob= G.main->object.first; + while(ob) { + if((ob->flag & OB_DONE)==0) { + tme= get_mesh(ob); - if(tme && (tme->flag & ME_ISDONE)==0) { - mvert= tme->mvert; - for(a=0; a<tme->totvert; a++, mvert++) { - VecSubf(mvert->co, mvert->co, cent); + if(tme==me) { + + ob->flag |= OB_DONE; + ob->recalc= OB_RECALC_OB|OB_RECALC_DATA; + + Mat3CpyMat4(omat, ob->obmat); + VECCOPY(centn, cent); + Mat3MulVecfl(omat, centn); + ob->loc[0]+= centn[0]; + ob->loc[1]+= centn[1]; + ob->loc[2]+= centn[2]; + + if(tme && (tme->flag & ME_ISDONE)==0) { + mvert= tme->mvert; + for(a=0; a<tme->totvert; a++, mvert++) { + VecSubf(mvert->co, mvert->co, cent); + } + tme->flag |= ME_ISDONE; } - tme->flag |= ME_ISDONE; } } + + ob= ob->id.next; } - - ob= ob->id.next; } + tot_change++; } } else if ELEM(base->object->type, OB_CURVE, OB_SURF) { @@ -1925,103 +1931,132 @@ void docenter(int centermode) nu1= cu->nurb.first; } - if(centermode==2) { - VECCOPY(cent, give_cursor()); - Mat4Invert(base->object->imat, base->object->obmat); - Mat4MulVecfl(base->object->imat, cent); - - /* don't allow Z change if curve is 2D */ - if( !( cu->flag & CU_3D ) ) - cent[2] = 0.0; + if (cu->id.lib) { + tot_lib_error++; } else { - INIT_MINMAX(min, max); - - nu= nu1; - while(nu) { - minmaxNurb(nu, min, max); - nu= nu->next; + if(centermode==2) { + VECCOPY(cent, give_cursor()); + Mat4Invert(base->object->imat, base->object->obmat); + Mat4MulVecfl(base->object->imat, cent); + + /* don't allow Z change if curve is 2D */ + if( !( cu->flag & CU_3D ) ) + cent[2] = 0.0; + } else { + INIT_MINMAX(min, max); + + nu= nu1; + while(nu) { + minmaxNurb(nu, min, max); + nu= nu->next; + } + + cent[0]= (min[0]+max[0])/2.0f; + cent[1]= (min[1]+max[1])/2.0f; + cent[2]= (min[2]+max[2])/2.0f; } - cent[0]= (min[0]+max[0])/2.0f; - cent[1]= (min[1]+max[1])/2.0f; - cent[2]= (min[2]+max[2])/2.0f; - } - - nu= nu1; - while(nu) { - if( (nu->type & 7)==1) { - a= nu->pntsu; - while (a--) { - VecSubf(nu->bezt[a].vec[0], nu->bezt[a].vec[0], cent); - VecSubf(nu->bezt[a].vec[1], nu->bezt[a].vec[1], cent); - VecSubf(nu->bezt[a].vec[2], nu->bezt[a].vec[2], cent); + nu= nu1; + while(nu) { + if( (nu->type & 7)==1) { + a= nu->pntsu; + while (a--) { + VecSubf(nu->bezt[a].vec[0], nu->bezt[a].vec[0], cent); + VecSubf(nu->bezt[a].vec[1], nu->bezt[a].vec[1], cent); + VecSubf(nu->bezt[a].vec[2], nu->bezt[a].vec[2], cent); + } + } + else { + a= nu->pntsu*nu->pntsv; + while (a--) + VecSubf(nu->bp[a].vec, nu->bp[a].vec, cent); } + nu= nu->next; } - else { - a= nu->pntsu*nu->pntsv; - while (a--) - VecSubf(nu->bp[a].vec, nu->bp[a].vec, cent); + + if(centermode && G.obedit==0) { + Mat3CpyMat4(omat, base->object->obmat); + + Mat3MulVecfl(omat, cent); + base->object->loc[0]+= cent[0]; + base->object->loc[1]+= cent[1]; + base->object->loc[2]+= cent[2]; } - nu= nu->next; - } - - if(centermode && G.obedit==0) { - Mat3CpyMat4(omat, base->object->obmat); - Mat3MulVecfl(omat, cent); - base->object->loc[0]+= cent[0]; - base->object->loc[1]+= cent[1]; - base->object->loc[2]+= cent[2]; - } - - if(G.obedit) { - if (centermode==0) { - DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA); + tot_change++; + if(G.obedit) { + if (centermode==0) { + DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA); + } + break; } - break; } - } else if(base->object->type==OB_FONT) { /* get from bb */ cu= base->object->data; - if(cu->bb==0) return; - - cu->xof= -0.5f*( cu->bb->vec[4][0] - cu->bb->vec[0][0]); - cu->yof= -0.5f -0.5f*( cu->bb->vec[0][1] - cu->bb->vec[2][1]); /* extra 0.5 is the height of above line */ - /* not really ok, do this better once! */ - cu->xof /= cu->fsize; - cu->yof /= cu->fsize; + if(cu->bb==0) { + /* do nothing*/ + } else if (cu->id.lib) { + tot_lib_error++; + } else { + cu->xof= -0.5f*( cu->bb->vec[4][0] - cu->bb->vec[0][0]); + cu->yof= -0.5f -0.5f*( cu->bb->vec[0][1] - cu->bb->vec[2][1]); /* extra 0.5 is the height of above line */ + + /* not really ok, do this better once! */ + cu->xof /= cu->fsize; + cu->yof /= cu->fsize; - allqueue(REDRAWBUTSEDIT, 0); + allqueue(REDRAWBUTSEDIT, 0); + tot_change++; + } } else if(base->object->type==OB_ARMATURE) { bArmature *arm = base->object->data; - if(arm->id.us>1) { - error("Can't apply to a multi user armature"); - return; + if (arm->id.lib) { + tot_lib_error++; + } else if(arm->id.us>1) { + /*error("Can't apply to a multi user armature"); + return;*/ + tot_multiuser_arm_error++; + } else { + /* Function to recenter armatures in editarmature.c + * Bone + object locations are handled there. + */ + docenter_armature(base->object, centermode); + tot_change++; + if(G.obedit) + break; } - - /* Function to recenter armatures in editarmature.c - * Bone + object locations are handled there. - */ - docenter_armature(base->object, centermode); - - if(G.obedit) - break; } base->object->recalc= OB_RECALC_OB|OB_RECALC_DATA; } } base= base->next; } - - DAG_scene_flush_update(G.scene, screen_view3d_layers()); - allqueue(REDRAWVIEW3D, 0); - BIF_undo_push("Do Center"); + if (tot_change) { + DAG_scene_flush_update(G.scene, screen_view3d_layers()); + allqueue(REDRAWVIEW3D, 0); + BIF_undo_push("Do Center"); + } + + /* Warn if any errors occured */ + if (tot_lib_error+tot_key_error+tot_multiuser_arm_error) { + char err[512]; + sprintf(err, "Warning %i Object(s) Not Centered, %i Changed%%t", tot_lib_error+tot_key_error+tot_multiuser_arm_error, tot_change); + + if (tot_lib_error) + sprintf(err+strlen(err), "|%i linked library objects", tot_lib_error); + if (tot_key_error) + sprintf(err+strlen(err), "|%i mesh key object(s)", tot_key_error); + if (tot_multiuser_arm_error) + sprintf(err+strlen(err), "|%i multiuser armature object(s)", tot_multiuser_arm_error); + + pupmenu(err); + } } void docenter_new(void) |