From 67f1e83508ac1312b6b41093cb1946363ce3d0fd Mon Sep 17 00:00:00 2001 From: Martin Poirier Date: Sat, 10 Mar 2012 21:40:35 +0000 Subject: [PATCH 001/310] [#30373] Which part to snap in volume snapping is removed By Bug reported by Pep Ribal Also fixed an object mode bug with volume snapping and made it compatible with the edit mode "Snap on self" option --- release/scripts/startup/bl_ui/space_view3d.py | 4 +-- .../editors/armature/editarmature_sketch.c | 2 +- source/blender/editors/include/ED_numinput.h | 9 +++++ source/blender/editors/include/ED_transform.h | 4 +-- .../editors/transform/transform_snap.c | 33 +++++++++---------- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index e639300998a..f18394edd91 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -88,10 +88,10 @@ class VIEW3D_HT_header(Header): row = layout.row(align=True) row.prop(toolsettings, "use_snap", text="") row.prop(toolsettings, "snap_element", text="", icon_only=True) - if snap_element not in {'INCREMENT', 'VOLUME'}: + if snap_element != 'INCREMENT': row.prop(toolsettings, "snap_target", text="") if obj: - if obj.mode == 'OBJECT': + if obj.mode == 'OBJECT' and snap_element != 'VOLUME': row.prop(toolsettings, "use_snap_align_rotation", text="") elif obj.mode == 'EDIT': row.prop(toolsettings, "use_snap_self", text="") diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c index 9ea731150e8..27e2d12a288 100644 --- a/source/blender/editors/armature/editarmature_sketch.c +++ b/source/blender/editors/armature/editarmature_sketch.c @@ -1079,7 +1079,7 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S mvalf[0]= dd->mval[0]; mvalf[1]= dd->mval[1]; - peelObjectsContext(C, &sketch->depth_peels, mvalf); + peelObjectsContext(C, &sketch->depth_peels, mvalf, SNAP_ALL); if (stk->nb_points > 0 && stk->points[stk->nb_points - 1].type == PT_CONTINUOUS) { diff --git a/source/blender/editors/include/ED_numinput.h b/source/blender/editors/include/ED_numinput.h index 2b99e52057d..e723ff73532 100644 --- a/source/blender/editors/include/ED_numinput.h +++ b/source/blender/editors/include/ED_numinput.h @@ -28,6 +28,15 @@ #define __ED_NUMINPUT_H__ +/* + The ctrl value has different meaning: + 0 : No value has been typed + + otherwise, |value| - 1 is where the cursor is located after the period + Positive : number is positive + Negative : number is negative +*/ + typedef struct NumInput { short idx; short idx_max; diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h index 4532a351c7d..f6dee351c29 100644 --- a/source/blender/editors/include/ED_transform.h +++ b/source/blender/editors/include/ED_transform.h @@ -175,8 +175,8 @@ typedef enum SnapMode #define SNAP_MIN_DISTANCE 30 -int peelObjectsTransForm(struct TransInfo *t, struct ListBase *depth_peels, const float mval[2]); -int peelObjectsContext(struct bContext *C, struct ListBase *depth_peels, const float mval[2]); +int peelObjectsTransForm(struct TransInfo *t, struct ListBase *depth_peels, const float mval[2], SnapMode mode); +int peelObjectsContext(struct bContext *C, struct ListBase *depth_peels, const float mval[2], SnapMode mode); int snapObjectsTransform(struct TransInfo *t, const float mval[2], int *r_dist, float r_loc[3], float r_no[3], SnapMode mode); int snapObjectsContext(struct bContext *C, const float mval[2], int *r_dist, float r_loc[3], float r_no[3], SnapMode mode); diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index c4e871f83c5..5713812ebd6 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -785,7 +785,7 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec)) depth_peels.first = depth_peels.last = NULL; - peelObjectsTransForm(t, &depth_peels, mval); + peelObjectsTransForm(t, &depth_peels, mval, t->tsnap.modeSelect); // if (LAST_SNAP_POINT_VALID) // { @@ -1862,7 +1862,7 @@ static int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], return retval; } -static int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, ListBase *depth_peels, const float mval[2]) +static int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, ListBase *depth_peels, const float mval[2], SnapMode mode) { Base *base; int retval = 0; @@ -1874,6 +1874,7 @@ static int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, L if ( BASE_SELECTABLE(v3d, base) ) { Object *ob = base->object; +#if 0 //BMESH_TODO if (ob->transflag & OB_DUPLI) { DupliObject *dupli_ob; ListBase *lb = object_duplilist(scene, ob); @@ -1883,7 +1884,6 @@ static int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, L Object *dob = dupli_ob->ob; if (dob->type == OB_MESH) { -#if 0 //BMESH_TODO EditMesh *em; DerivedMesh *dm = NULL; int val; @@ -1903,33 +1903,32 @@ static int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, L retval = retval || val; dm->release(dm); -#endif } } free_object_duplilist(lb); } +#endif if (ob->type == OB_MESH) { - BMEditMesh *em; - DerivedMesh *dm = NULL; - int val; + int val = 0; - if (ob != obedit) { - dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); + if (ob != obedit && ((mode == SNAP_NOT_SELECTED && (base->flag & (SELECT|BA_WAS_SEL)) == 0) || ELEM(mode, SNAP_ALL, SNAP_NOT_OBEDIT))) { + DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); val = peelDerivedMesh(ob, dm, ob->obmat, ray_start, ray_normal, mval, depth_peels); + dm->release(dm); } - else { - em = BMEdit_FromObject(ob); - dm = editbmesh_get_derived_cage(scene, obedit, em, CD_MASK_BAREMESH); + else if (ob == obedit && mode != SNAP_NOT_OBEDIT) { + BMEditMesh *em = BMEdit_FromObject(ob); + DerivedMesh *dm = editbmesh_get_derived_cage(scene, obedit, em, CD_MASK_BAREMESH); val = peelDerivedMesh(ob, dm, ob->obmat, ray_start, ray_normal, mval, depth_peels); + dm->release(dm); } retval = retval || val; - dm->release(dm); } } } @@ -1940,17 +1939,17 @@ static int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, L return retval; } -int peelObjectsTransForm(TransInfo *t, ListBase *depth_peels, const float mval[2]) +int peelObjectsTransForm(TransInfo *t, ListBase *depth_peels, const float mval[2], SnapMode mode) { - return peelObjects(t->scene, t->view, t->ar, t->obedit, depth_peels, mval); + return peelObjects(t->scene, t->view, t->ar, t->obedit, depth_peels, mval, mode); } -int peelObjectsContext(bContext *C, ListBase *depth_peels, const float mval[2]) +int peelObjectsContext(bContext *C, ListBase *depth_peels, const float mval[2], SnapMode mode) { ScrArea *sa = CTX_wm_area(C); View3D *v3d = sa->spacedata.first; - return peelObjects(CTX_data_scene(C), v3d, CTX_wm_region(C), CTX_data_edit_object(C), depth_peels, mval); + return peelObjects(CTX_data_scene(C), v3d, CTX_wm_region(C), CTX_data_edit_object(C), depth_peels, mval, mode); } /*================================================================*/ From 7f34653f59ad3f7bed75eb9a36aa6ed928eef181 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 10 Mar 2012 22:00:55 +0000 Subject: [PATCH 002/310] style cleanup: + some warning fixes, also remove unused metaelem extern. --- .../Detour/Source/DetourStatNavMesh.cpp | 4 +- source/blender/editors/mesh/bmesh_select.c | 12 ++-- source/blender/editors/mesh/bmesh_tools.c | 8 +-- .../editors/space_view3d/drawarmature.c | 58 +++++++++++++------ .../blender/editors/space_view3d/drawmesh.c | 6 +- .../blender/editors/space_view3d/drawobject.c | 32 +++++----- .../editors/space_view3d/view3d_edit.c | 26 +++++---- .../blender/editors/space_view3d/view3d_fly.c | 4 +- .../editors/space_view3d/view3d_select.c | 11 ++-- .../editors/space_view3d/view3d_snap.c | 2 +- .../editors/transform/transform_conversions.c | 2 - .../editors/transform/transform_generics.c | 2 - .../transform/transform_orientations.c | 1 - 13 files changed, 93 insertions(+), 75 deletions(-) diff --git a/extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp b/extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp index 8da8e2c1e1e..a02211816a2 100644 --- a/extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp +++ b/extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp @@ -465,7 +465,7 @@ int dtStatNavMesh::raycast(dtStatPolyRef centerRef, const float* startPos, const if (!m_header) return 0; if (!centerRef) return 0; - dtStatPolyRef prevRef = centerRef; + /* dtStatPolyRef prevRef = centerRef; */ /* UNUSED */ dtStatPolyRef curRef = centerRef; t = 0; @@ -506,7 +506,7 @@ int dtStatNavMesh::raycast(dtStatPolyRef centerRef, const float* startPos, const } // No hit, advance to neighbour polygon. - prevRef = curRef; + /* prevRef = curRef; */ /* UNUSED */ curRef = nextRef; } diff --git a/source/blender/editors/mesh/bmesh_select.c b/source/blender/editors/mesh/bmesh_select.c index 2c5e8439b57..5b7237155c8 100644 --- a/source/blender/editors/mesh/bmesh_select.c +++ b/source/blender/editors/mesh/bmesh_select.c @@ -227,9 +227,9 @@ int EDBM_mask_init_backbuf_border(ViewContext *vc, int mcords[][2], short tot, s /* method in use for face selecting too */ if (vc->obedit == NULL) { - if (paint_facesel_test(vc->obact)); - else if (paint_vertsel_test(vc->obact)); - else return 0; + if (!(paint_facesel_test(vc->obact) || paint_vertsel_test(vc->obact))) { + return 0; + } } else if (vc->v3d->drawtype < OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT) == 0) { return 0; @@ -289,9 +289,9 @@ int EDBM_init_backbuf_circle(ViewContext *vc, short xs, short ys, short rads) /* method in use for face selecting too */ if (vc->obedit == NULL) { - if (paint_facesel_test(vc->obact)); - else if (paint_vertsel_test(vc->obact)); - else return 0; + if (!(paint_facesel_test(vc->obact) || paint_vertsel_test(vc->obact))) { + return 0; + } } else if (vc->v3d->drawtype < OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT) == 0) return 0; diff --git a/source/blender/editors/mesh/bmesh_tools.c b/source/blender/editors/mesh/bmesh_tools.c index 6b136bde141..da08b3354e1 100644 --- a/source/blender/editors/mesh/bmesh_tools.c +++ b/source/blender/editors/mesh/bmesh_tools.c @@ -465,7 +465,7 @@ static int EDBM_Extrude_Mesh(Scene *scene, Object *obedit, BMEditMesh *em, wmOpe if (nr < 1) return 'g'; - if (nr == 1 && em->selectmode & SCE_SELECT_VERTEX) + if (nr == 1 && (em->selectmode & SCE_SELECT_VERTEX)) transmode = EDBM_Extrude_vert(obedit, em, BM_ELEM_SELECT, nor); else if (nr == 1) transmode = EDBM_Extrude_edge(obedit, em, BM_ELEM_SELECT, nor); else if (nr == 4) transmode = EDBM_Extrude_verts_indiv(em, op, BM_ELEM_SELECT, nor); @@ -1810,12 +1810,6 @@ void MESH_OT_faces_shade_flat(wmOperatorType *ot) /********************** UV/Color Operators *************************/ - -static const EnumPropertyItem axis_items[] = { - {OPUVC_AXIS_X, "X", 0, "X", ""}, - {OPUVC_AXIS_Y, "Y", 0, "Y", ""}, - {0, NULL, 0, NULL, NULL}}; - static int mesh_rotate_uvs(bContext *C, wmOperator *op) { Object *ob = CTX_data_edit_object(C); diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index 54dff3e4786..373b665a84c 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -170,10 +170,18 @@ static short set_pchan_glColor (short colCode, int boneflag, short constflag) glColor3ubv(cp); } else { - if (boneflag & BONE_DRAW_ACTIVE && boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_BONE_POSE, 40); - else if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorBlend(TH_WIRE, TH_BONE_POSE, 0.15f); /* unselected active */ - else if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_BONE_POSE); - else UI_ThemeColor(TH_WIRE); + if ((boneflag & BONE_DRAW_ACTIVE) && (boneflag & BONE_SELECTED)) { + UI_ThemeColorShade(TH_BONE_POSE, 40); + } + else if (boneflag & BONE_DRAW_ACTIVE) { + UI_ThemeColorBlend(TH_WIRE, TH_BONE_POSE, 0.15f); /* unselected active */ + } + else if (boneflag & BONE_SELECTED) { + UI_ThemeColor(TH_BONE_POSE); + } + else { + UI_ThemeColor(TH_WIRE); + } } return 1; @@ -290,10 +298,18 @@ static short set_pchan_glColor (short colCode, int boneflag, short constflag) static void set_ebone_glColor(const unsigned int boneflag) { - if (boneflag & BONE_DRAW_ACTIVE && boneflag & BONE_SELECTED) UI_ThemeColor(TH_EDGE_SELECT); - else if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorBlend(TH_WIRE, TH_EDGE_SELECT, 0.15f); /* unselected active */ - else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_EDGE_SELECT, -20); - else UI_ThemeColor(TH_WIRE); + if ((boneflag & BONE_DRAW_ACTIVE) && (boneflag & BONE_SELECTED)) { + UI_ThemeColor(TH_EDGE_SELECT); + } + else if (boneflag & BONE_DRAW_ACTIVE) { + UI_ThemeColorBlend(TH_WIRE, TH_EDGE_SELECT, 0.15f); /* unselected active */ + } + else if (boneflag & BONE_SELECTED) { + UI_ThemeColorShade(TH_EDGE_SELECT, -20); + } + else { + UI_ThemeColor(TH_WIRE); + } } /* *************** Armature drawing, helper calls for parts ******************* */ @@ -1749,16 +1765,21 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, OB_SOLID, arm->flag, flag, index, bone->length); } } - else if (arm->drawtype==ARM_LINE) - ; /* nothing in solid */ - else if (arm->drawtype==ARM_WIRE) - ; /* nothing in solid */ - else if (arm->drawtype==ARM_ENVELOPE) + else if (arm->drawtype == ARM_LINE) { + /* nothing in solid */ + } + else if (arm->drawtype == ARM_WIRE) { + /* nothing in solid */ + } + else if (arm->drawtype == ARM_ENVELOPE) { draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL); - else if (arm->drawtype==ARM_B_BONE) + } + else if (arm->drawtype == ARM_B_BONE) { draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL); - else + } + else { draw_bone(OB_SOLID, arm->flag, flag, 0, index, bone->length); + } glPopMatrix(); } @@ -1937,8 +1958,9 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, /* set color-set to use */ set_pchan_colorset(ob, pchan); - if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) - ; // custom bone shapes should not be drawn here! + if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) { + /* custom bone shapes should not be drawn here! */ + } else if (arm->drawtype==ARM_ENVELOPE) { if (dt < OB_SOLID) draw_sphere_bone_wire(smat, imat, arm->flag, flag, constflag, index, pchan, NULL); @@ -1973,7 +1995,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, draw_pose_dofs(ob); /* finally names and axes */ - if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES) && is_outline == 0) { + if ((arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) && (is_outline == 0)) { /* patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing */ if ((G.f & G_PICKSEL) == 0) { float vec[3]; diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index 651b0edb123..c69879fcd32 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -404,7 +404,7 @@ static DMDrawOption draw_tface__set_draw_legacy(MTFace *tface, int has_mcol, int glColor3ub(0xFF, 0x00, 0xFF); return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */ } - else if (ma && ma->shade_flag&MA_OBCOLOR) { + else if (ma && (ma->shade_flag&MA_OBCOLOR)) { glColor3ubv(Gtexdraw.obcol); return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */ } @@ -444,7 +444,7 @@ static DMDrawOption draw_tface__set_draw(MTFace *tface, int has_mcol, int matnr) if (tface && set_draw_settings_cached(0, tface, ma, Gtexdraw)) { return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */ } - else if (tface && tface->mode&TF_OBCOL) { + else if (tface && (tface->mode & TF_OBCOL)) { return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */ } else if (!has_mcol) { @@ -486,7 +486,7 @@ static void add_tface_color_layer(DerivedMesh *dm) finalCol[i*4+j].r = 255; } } - else if (tface && tface->mode&TF_OBCOL) { + else if (tface && (tface->mode & TF_OBCOL)) { for (j=0;j<4;j++) { finalCol[i*4+j].b = FTOCHAR(Gtexdraw.obcol[0]); finalCol[i*4+j].g = FTOCHAR(Gtexdraw.obcol[1]); diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 43fde303dcd..33578738def 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -197,7 +197,7 @@ static int check_ob_drawface_dot(Scene *sce, View3D *vd, char dt) if (dt==OB_TEXTURE && vd->drawtype==OB_TEXTURE) return 0; - if (vd->drawtype>=OB_SOLID && vd->flag2 & V3D_SOLID_TEX) + if ((vd->drawtype >= OB_SOLID) && (vd->flag2 & V3D_SOLID_TEX)) return 0; return 1; @@ -3246,7 +3246,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW); if (dt==OB_BOUNDBOX) { - if ((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0) + if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= OB_WIRE)==0) draw_bounding_volume(scene, ob, ob->boundtype); } else if (hasHaloMat || (totface==0 && totedge==0)) { @@ -3498,7 +3498,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D glDepthMask(0); // disable write in zbuffer, selected edge wires show better } - if ((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_SOLID)==0) + if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= OB_SOLID)==0) dm->drawEdges(dm, (dt==OB_WIRE || totface==0), me->drawflag & ME_ALLEDGES); if (dt!=OB_WIRE && (draw_wire == OBDRAW_WIRE_ON_DEPTH)) { @@ -3540,8 +3540,8 @@ static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D } if (obedit && ob!=obedit && ob->data==obedit->data) { - if (ob_get_key(ob) || ob_get_key(obedit)); - else if (ob->modifiers.first || obedit->modifiers.first); + if (ob_get_key(ob) || ob_get_key(obedit)) {} + else if (ob->modifiers.first || obedit->modifiers.first) {} else drawlinked= 1; } @@ -3853,7 +3853,7 @@ static int drawCurveDerivedMesh(Scene *scene, View3D *v3d, RegionView3D *rv3d, B GPU_end_object_materials(); } else { - if ((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_SOLID)==0) + if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= OB_SOLID)==0) drawCurveDMWired (ob); } @@ -5407,7 +5407,9 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel) } } else { - if ( (bp->f1 & SELECT) && ( bp1->f1 & SELECT) ); + if ((bp->f1 & SELECT) && (bp1->f1 & SELECT)) { + /* pass */ + } else { UI_ThemeColor(TH_NURB_ULINE); @@ -5440,7 +5442,9 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel) } } else { - if ( (bp->f1 & SELECT) && ( bp1->f1 & SELECT) ); + if ((bp->f1 & SELECT) && (bp1->f1 & SELECT)) { + /* pass */ + } else { UI_ThemeColor(TH_NURB_VLINE); @@ -5504,7 +5508,7 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, /* direction vectors for 3d curve paths * when at its lowest, dont render normals */ - if (cu->flag & CU_3D && ts->normalsize > 0.0015f && (cu->drawflag & CU_HIDE_NORMALS)==0) { + if ((cu->flag & CU_3D) && (ts->normalsize > 0.0015f) && (cu->drawflag & CU_HIDE_NORMALS)==0) { UI_ThemeColor(TH_WIRE); for (bl=cu->bev.first,nu=nurb; nu && bl; bl=bl->next,nu=nu->next) { @@ -6620,7 +6624,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) } } else if (dt==OB_BOUNDBOX) { - if ((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE) == 0) { + if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= OB_WIRE) == 0) { draw_bounding_volume(scene, ob, ob->boundtype); } } @@ -6638,8 +6642,9 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) drawnurb(scene, v3d, rv3d, base, nurbs->first, dt); } else if (dt==OB_BOUNDBOX) { - if ((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0) + if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && (v3d->drawtype >= OB_WIRE)) == 0) { draw_bounding_volume(scene, ob, ob->boundtype); + } } else if (ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) { empty_object= drawDispList(scene, v3d, rv3d, base, dt); @@ -6655,8 +6660,9 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) if (mb->editelems) drawmball(scene, v3d, rv3d, base, dt); else if (dt==OB_BOUNDBOX) { - if ((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0) + if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && (v3d->drawtype >= OB_WIRE)) == 0) { draw_bounding_volume(scene, ob, ob->boundtype); + } } else empty_object= drawmball(scene, v3d, rv3d, base, dt); @@ -7295,7 +7301,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec bm_wireoffs= bm_solidoffs + em->bm->totedge; // we draw verts if vert select mode or if in transform (for snap). - if (ts->selectmode & SCE_SELECT_VERTEX || G.moving & G_TRANSFORM_EDIT) { + if ((ts->selectmode & SCE_SELECT_VERTEX) || (G.moving & G_TRANSFORM_EDIT)) { bbs_mesh_verts(em, dm, bm_wireoffs); bm_vertoffs= bm_wireoffs + em->bm->totvert; } diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 0b12db5d290..e27cd760c92 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -517,8 +517,6 @@ static void viewops_data_free(bContext *C, wmOperator *op) /* ************************** viewrotate **********************************/ -static const float thres = 0.93f; //cos(20 deg); - #define COS45 0.7071068 #define SIN45 COS45 @@ -2135,8 +2133,8 @@ static int viewselected_exec(bContext *C, wmOperator *UNUSED(op)) INIT_MINMAX(min, max); - if (ob && ob->mode & OB_MODE_WEIGHT_PAINT) { - /* hardcoded exception, we look for the one selected armature */ + if (ob && (ob->mode & OB_MODE_WEIGHT_PAINT)) { + /* hard-coded exception, we look for the one selected armature */ /* this is weak code this way, we should make a generic active/selection callback interface once... */ Base *base; for (base=scene->base.first; base; base= base->next) { @@ -2681,16 +2679,20 @@ static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar, /* normal operation */ if (rv3d->viewlock) { /* only pass on if */ - if (rv3d->view==RV3D_VIEW_FRONT && view==RV3D_VIEW_BACK); - else if (rv3d->view==RV3D_VIEW_BACK && view==RV3D_VIEW_FRONT); - else if (rv3d->view==RV3D_VIEW_RIGHT && view==RV3D_VIEW_LEFT); - else if (rv3d->view==RV3D_VIEW_LEFT && view==RV3D_VIEW_RIGHT); - else if (rv3d->view==RV3D_VIEW_BOTTOM && view==RV3D_VIEW_TOP); - else if (rv3d->view==RV3D_VIEW_TOP && view==RV3D_VIEW_BOTTOM); - else return; + + /* nice confusing if-block */ + if (!((rv3d->view == RV3D_VIEW_FRONT && view == RV3D_VIEW_BACK) || + (rv3d->view == RV3D_VIEW_BACK && view == RV3D_VIEW_FRONT) || + (rv3d->view == RV3D_VIEW_RIGHT && view == RV3D_VIEW_LEFT) || + (rv3d->view == RV3D_VIEW_LEFT && view == RV3D_VIEW_RIGHT) || + (rv3d->view == RV3D_VIEW_BOTTOM && view == RV3D_VIEW_TOP) || + (rv3d->view == RV3D_VIEW_TOP && view == RV3D_VIEW_BOTTOM))) + { + return; + } } - rv3d->view= view; + rv3d->view = view; } if (rv3d->viewlock) { diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index 614fa45771d..53b64b971aa 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -185,7 +185,7 @@ typedef struct FlyInfo { * 0) disabled * 1) enabled but not checking because mouse hasn't moved outside the margin since locking was checked an not needed * when the mouse moves, locking is set to 2 so checks are done. - * 2) mouse moved and checking needed, if no view altering is donem its changed back to 1 */ + * 2) mouse moved and checking needed, if no view altering is done its changed back to 1 */ short xlock, zlock; float xlock_momentum, zlock_momentum; /* nicer dynamics */ float grid; /* world scale 1.0 default */ @@ -525,7 +525,7 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) fly->time_lastdraw = PIL_check_seconds_timer(); break; default: - ; // should always be one of the above 3 + break; /* should always be one of the above 3 */ } } /* handle modal keymap first */ diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 93cf656dea4..3d1156c8ad1 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -816,12 +816,11 @@ int do_paintvert_box_select(ViewContext *vc, rcti *rect, int select, int extend) } mvert= me->mvert; - for (a=1; a<=me->totvert; a++, mvert++) { + for (a = 1; a <= me->totvert; a++, mvert++) { if (selar[a]) { - if (mvert->flag & ME_HIDE); - else { - if (select) mvert->flag |= SELECT; - else mvert->flag &= ~SELECT; + if ((mvert->flag & ME_HIDE) == 0) { + if (select) mvert->flag |= SELECT; + else mvert->flag &= ~SELECT; } } } @@ -1595,7 +1594,7 @@ static int mouse_select(bContext *C, const int mval[2], short extend, short obce WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, basact->object); /* in weightpaint, we use selected bone to select vertexgroup, so no switch to new active object */ - if (BASACT && BASACT->object->mode & OB_MODE_WEIGHT_PAINT) { + if (BASACT && (BASACT->object->mode & OB_MODE_WEIGHT_PAINT)) { /* prevent activating */ basact= NULL; } diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index 5d2f0c432fb..ef02e96b47e 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -331,7 +331,7 @@ static void make_trans_verts(Object *obedit, float *min, float *max, int mode) if (ebo->layer & arm->layer) { short tipsel= (ebo->flag & BONE_TIPSEL); short rootsel= (ebo->flag & BONE_ROOTSEL); - short rootok= (!(ebo->parent && (ebo->flag & BONE_CONNECTED) && ebo->parent->flag & BONE_TIPSEL)); + short rootok= (!(ebo->parent && (ebo->flag & BONE_CONNECTED) && (ebo->parent->flag & BONE_TIPSEL))); if ((tipsel && rootsel) || (rootsel)) { /* Don't add the tip (unless mode & TM_ALL_JOINTS, for getting all joints), diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 4dbf87fb500..faffa289c2a 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -111,8 +111,6 @@ #include "RNA_access.h" -extern ListBase editelems; - #include "transform.h" #include "bmesh.h" diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index d24081ae472..509d7bdd0e7 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -107,8 +107,6 @@ #include "transform.h" -extern ListBase editelems; - /* ************************** Functions *************************** */ void getViewVector(TransInfo *t, float coord[3], float vec[3]) diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 2b5758c5ec1..76fa08e0702 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -752,7 +752,6 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], else if(obedit->type==OB_MBALL){ #if 0 // XXX /* editmball.c */ - extern ListBase editelems; /* go away ! */ MetaElem *ml, *ml_sel = NULL; /* loop and check that only one element is selected */ From 0c50bedd9c960763d3e8e695b63957a964565be0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Mar 2012 00:00:27 +0000 Subject: [PATCH 003/310] code cleanup: remove unused externs. --- source/blender/editors/animation/anim_draw.c | 3 --- source/blender/editors/space_node/drawnode.c | 4 ---- source/blender/editors/space_sequencer/sequencer_edit.c | 5 +---- source/blender/imbuf/intern/indexer.c | 8 -------- source/blender/windowmanager/intern/wm_init_exit.c | 7 +------ source/creator/creator.c | 3 --- 6 files changed, 2 insertions(+), 28 deletions(-) diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c index 1ef02f46000..bab341ae70b 100644 --- a/source/blender/editors/animation/anim_draw.c +++ b/source/blender/editors/animation/anim_draw.c @@ -51,9 +51,6 @@ #include "UI_resources.h" #include "UI_view2d.h" -/* XXX */ -extern void ui_rasterpos_safe(float x, float y, float aspect); - /* *************************************************** */ /* TIME CODE FORMATTING */ diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 64af846a79b..4660b7703d8 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -79,10 +79,6 @@ #include "node_intern.h" - -// XXX interface.h -extern void ui_dropshadow(rctf *rct, float radius, float aspect, int select); - /* ****************** SOCKET BUTTON DRAW FUNCTIONS ***************** */ static void node_sync_cb(bContext *UNUSED(C), void *snode_v, void *node_v) diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 2815297eb13..049e11a4f6a 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -75,9 +75,6 @@ /* own include */ #include "sequencer_intern.h" -static int okee(const char *UNUSED(dummy)) {return 0;} - - /* XXX */ /* RNA Enums, used in multiple files */ EnumPropertyItem sequencer_prop_effect_types[] = { @@ -866,7 +863,7 @@ static void UNUSED_FUNCTION(touch_seq_files)(Scene *scene) if(ed==NULL) return; - if(okee("Touch and print selected movies")==0) return; + // XXX25 if(okee("Touch and print selected movies")==0) return; WM_cursor_wait(1); diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c index 7a2977da473..cf354371ddc 100644 --- a/source/blender/imbuf/intern/indexer.c +++ b/source/blender/imbuf/intern/indexer.c @@ -61,14 +61,6 @@ static int tc_types[] = { IMB_TC_RECORD_RUN, #define INDEX_FILE_VERSION 1 -/* ---------------------------------------------------------------------- - - special indexers - ---------------------------------------------------------------------- - */ - -extern void IMB_indexer_dv_new(anim_index_builder * idx); - - /* ---------------------------------------------------------------------- - time code index functions ---------------------------------------------------------------------- */ diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index f5dec4dbcd3..9656a45509c 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -317,9 +317,6 @@ static void free_openrecent(void) /* bad stuff*/ -extern wchar_t *copybuf; -extern wchar_t *copybufinfo; - // XXX copy/paste buffer stuff... extern void free_anim_copybuf(void); extern void free_anim_drivers_copybuf(void); @@ -419,9 +416,7 @@ void WM_exit_ext(bContext *C, const short do_python) GPU_global_buffer_pool_free(); GPU_free_unused_buffers(); GPU_extensions_exit(); - -// if (copybuf) MEM_freeN(copybuf); -// if (copybufinfo) MEM_freeN(copybufinfo); + if (!G.background) { BKE_undo_save_quit(); // saves quit.blend if global undo is on } diff --git a/source/creator/creator.c b/source/creator/creator.c index 4a4887f52f9..3cc2c4f1c4c 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -319,9 +319,6 @@ static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data) return 0; } - -double PIL_check_seconds_timer(void); - static int end_arguments(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data)) { return -1; From 21fd09c028dce833f58cdaa8a1ff45876a5e5a2f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Mar 2012 02:45:27 +0000 Subject: [PATCH 004/310] bmesh py api: change .from_mesh() / .to_mesh() to be class methods of BMesh rather than functions in the module. added example script which converts a mesh to a bmesh, edits and converts back again. --- release/scripts/templates/bmesh_simple.py | 21 +++++ ...gamelogic_basic.py => gamelogic_simple.py} | 0 source/blender/python/bmesh/bmesh_py_api.c | 82 ++++-------------- source/blender/python/bmesh/bmesh_py_types.c | 83 +++++++++++++++++++ source/blender/python/bmesh/bmesh_py_types.h | 2 +- 5 files changed, 123 insertions(+), 65 deletions(-) create mode 100644 release/scripts/templates/bmesh_simple.py rename release/scripts/templates/{gamelogic_basic.py => gamelogic_simple.py} (100%) diff --git a/release/scripts/templates/bmesh_simple.py b/release/scripts/templates/bmesh_simple.py new file mode 100644 index 00000000000..656febf4918 --- /dev/null +++ b/release/scripts/templates/bmesh_simple.py @@ -0,0 +1,21 @@ +# This example assumes we have a mesh object selected + +import bpy +import bmesh + +# Get the active mesh +me = bpy.context.object.data + + +# Get a BMesh representation +bm = bmesh.new() # create an empty BMesh +bm.from_mesh(me) # fill it in from a Mesh + + +# Modify the BMesh, can do anything here... +for v in bm.verts: + v.co.x += 1.0 + + +# Finish up, write the bmesh back to the mesh +bm.to_mesh(me) diff --git a/release/scripts/templates/gamelogic_basic.py b/release/scripts/templates/gamelogic_simple.py similarity index 100% rename from release/scripts/templates/gamelogic_basic.py rename to release/scripts/templates/gamelogic_simple.py diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c index 3990005d139..280bab26c4b 100644 --- a/source/blender/python/bmesh/bmesh_py_api.c +++ b/source/blender/python/bmesh/bmesh_py_api.c @@ -40,17 +40,14 @@ #include "BLI_utildefines.h" #include "BKE_tessmesh.h" -#include "BKE_depsgraph.h" #include "DNA_mesh_types.h" -#include "DNA_object_types.h" #include "../generic/py_capi_utils.h" #include "bmesh_py_api.h" /* own include */ - PyDoc_STRVAR(bpy_bm_new_doc, ".. method:: new()\n" "\n" @@ -70,88 +67,40 @@ static PyObject *bpy_bm_new(PyObject *UNUSED(self)) return (PyObject *)py_bmesh; } -PyDoc_STRVAR(bpy_bm_from_mesh_doc, -".. method:: from_mesh(mesh)\n" +PyDoc_STRVAR(bpy_bm_from_edit_mesh_doc, +".. method:: from_edit_mesh(mesh)\n" "\n" " Return a BMesh from this mesh, currently the mesh must already be in editmode.\n" "\n" " :return: the BMesh assosiated with this mesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n" ); - -static PyObject *bpy_bm_from_mesh(PyObject *UNUSED(self), PyObject *value) +static PyObject *bpy_bm_from_edit_mesh(PyObject *UNUSED(self), PyObject *value) { BPy_BMesh *py_bmesh; BMesh *bm; Mesh *me = PyC_RNA_AsPointer(value, "Mesh"); - int py_owns; if (me == NULL) { return NULL; } - /* temp! */ - if (!me->edit_btmesh) { - bm = BM_mesh_create(NULL, &bm_mesh_allocsize_default); - BM_mesh_to_bmesh(bm, me, 0, 0); /* BMESH_TODO add args */ - py_owns = TRUE; - } - else { - bm = me->edit_btmesh->bm; - py_owns = FALSE; + if (me->edit_btmesh == NULL) { + PyErr_SetString(PyExc_ValueError, + "The mesh must be in editmode"); + return NULL; } + bm = me->edit_btmesh->bm; + py_bmesh = (BPy_BMesh *)BPy_BMesh_CreatePyObject(bm); - py_bmesh->py_owns = py_owns; + py_bmesh->py_owns = FALSE; return (PyObject *)py_bmesh; } -PyDoc_STRVAR(bpy_bm_to_mesh_doc, -".. method:: to_mesh(mesh, bmesh)\n" -"\n" -" Return a BMesh from this mesh, currently the mesh must already be in editmode.\n" -"\n" -" :return: the BMesh assosiated with this mesh.\n" -" :rtype: :class:`bmesh.types.BMesh`\n" -); - -static PyObject *bpy_bm_to_mesh(PyObject *UNUSED(self), PyObject *args) -{ - PyObject *py_mesh; - BPy_BMesh *py_bmesh; - Mesh *me; - BMesh *bm; - - if (!PyArg_ParseTuple(args, "OO!:to_mesh", &py_mesh, &BPy_BMesh_Type, &py_bmesh) || - !(me = PyC_RNA_AsPointer(py_mesh, "Mesh"))) - { - return NULL; - } - - BPY_BM_CHECK_OBJ(py_bmesh); - - if (me->edit_btmesh) { - PyErr_Format(PyExc_ValueError, - "to_mesh(): Mesh '%s' is in editmode", me->id.name + 2); - return NULL; - } - - bm = py_bmesh->bm; - - BM_mesh_from_bmesh(bm, me, FALSE); - - /* we could have the user do this but if they forget blender can easy crash - * since the references arrays for the objects derived meshes are now invalid */ - DAG_id_tag_update(&me->id, OB_RECALC_DATA); - - Py_RETURN_NONE; -} - static struct PyMethodDef BPy_BM_methods[] = { - /* THESE NAMES MAY CHANGE! */ - {"new", (PyCFunction)bpy_bm_new, METH_NOARGS, bpy_bm_new_doc}, - {"from_mesh", (PyCFunction)bpy_bm_from_mesh, METH_O, bpy_bm_from_mesh_doc}, - {"to_mesh", (PyCFunction)bpy_bm_to_mesh, METH_VARARGS, bpy_bm_to_mesh_doc}, + {"new", (PyCFunction)bpy_bm_new, METH_NOARGS, bpy_bm_new_doc}, + {"from_edit_mesh", (PyCFunction)bpy_bm_from_edit_mesh, METH_O, bpy_bm_from_edit_mesh_doc}, {NULL, NULL, 0, NULL} }; @@ -163,6 +112,12 @@ PyDoc_STRVAR(BPy_BM_doc, "\n" "* :mod:`bmesh.utils`\n" "* :mod:`bmesh.types`\n" +"\n" +"\n" +"Example Script\n" +"--------------\n" +"\n" +".. literalinclude:: ../../../release/scripts/templates/bmesh_simple.py\n" ); static struct PyModuleDef BPy_BM_module_def = { PyModuleDef_HEAD_INIT, @@ -185,7 +140,6 @@ PyObject *BPyInit_bmesh(void) BPy_BM_init_types(); BPy_BM_init_select_types(); - mod = PyModule_Create(&BPy_BM_module_def); /* bmesh.types */ diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index c15323186ac..eefe3ccbe02 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -31,6 +31,10 @@ #include "BLI_math.h" +#include "DNA_mesh_types.h" +#include "DNA_object_types.h" + +#include "BKE_depsgraph.h" #include "BKE_customdata.h" #include "bmesh.h" @@ -586,6 +590,82 @@ static PyGetSetDef bpy_bmloop_getseters[] = { /* Mesh * ---- */ +PyDoc_STRVAR(bpy_bmesh_to_mesh_doc, +".. method:: to_mesh(mesh)\n" +"\n" +" Writes this BMesh data into an existing Mesh datablock.\n" +"\n" +" :arg mesh: The mesh data to write into.\n" +" :type mesh: :class:`Mesh`\n" +); +static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args) +{ + PyObject *py_mesh; + Mesh *me; + BMesh *bm; + + BPY_BM_CHECK_OBJ(self); + + if (!PyArg_ParseTuple(args, "O:to_mesh", &py_mesh) || + !(me = PyC_RNA_AsPointer(py_mesh, "Mesh"))) + { + return NULL; + } + + /* we could allow this but its almost certainly _not_ what script authors want */ + if (me->edit_btmesh) { + PyErr_Format(PyExc_ValueError, + "to_mesh(): Mesh '%s' is in editmode", me->id.name + 2); + return NULL; + } + + bm = self->bm; + + BM_mesh_from_bmesh(bm, me, FALSE); + + /* we could have the user do this but if they forget blender can easy crash + * since the references arrays for the objects derived meshes are now invalid */ + DAG_id_tag_update(&me->id, OB_RECALC_DATA); + + Py_RETURN_NONE; +} + +PyDoc_STRVAR(bpy_bmesh_from_mesh_doc, +".. method:: from_mesh(mesh, use_shape_key=False, shape_key_index=0)\n" +"\n" +" Initialize this bmesh from existing mesh datablock.\n" +"\n" +" :arg mesh: The mesh data to load.\n" +" :type mesh: :class:`Mesh`\n" +" :arg use_shape_key: Use the locations from a shape key.\n" +" :type use_shape_key: boolean\n" +" :arg shape_key_index: The shape key index to use.\n" +" :type shape_key_index: int\n" +); +static PyObject *bpy_bmesh_from_mesh(BPy_BMesh *self, PyObject *args, PyObject *kw) +{ + static const char *kwlist[] = {"mesh", "use_shape_key", "shape_key_index", NULL}; + BMesh *bm; + PyObject *py_mesh; + Mesh *me; + int use_shape_key = FALSE; + int shape_key_index = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kw, "O|ii:to_mesh", (char **)kwlist, + &py_mesh, &use_shape_key, &shape_key_index) || + !(me = PyC_RNA_AsPointer(py_mesh, "Mesh"))) + { + return NULL; + } + + bm = self->bm; + + BM_mesh_to_bmesh(bm, me, use_shape_key, shape_key_index + 1); + + Py_RETURN_NONE; +} + + PyDoc_STRVAR(bpy_bmesh_select_flush_mode_doc, ".. method:: select_flush_mode()\n" "\n" @@ -1716,6 +1796,9 @@ static PyObject *bpy_bmelemseq_index_update(BPy_BMElemSeq *self) static struct PyMethodDef bpy_bmesh_methods[] = { + {"from_mesh", (PyCFunction)bpy_bmesh_from_mesh, METH_VARARGS | METH_KEYWORDS, bpy_bmesh_from_mesh_doc}, + {"to_mesh", (PyCFunction)bpy_bmesh_to_mesh, METH_VARARGS, bpy_bmesh_to_mesh_doc}, + {"select_flush_mode", (PyCFunction)bpy_bmesh_select_flush_mode, METH_NOARGS, bpy_bmesh_select_flush_mode_doc}, {"select_flush", (PyCFunction)bpy_bmesh_select_flush, METH_O, bpy_bmesh_select_flush_doc}, {"normal_update", (PyCFunction)bpy_bmesh_normal_update, METH_VARARGS, bpy_bmesh_normal_update_doc}, diff --git a/source/blender/python/bmesh/bmesh_py_types.h b/source/blender/python/bmesh/bmesh_py_types.h index 52a82c50dd1..88569c5eeaf 100644 --- a/source/blender/python/bmesh/bmesh_py_types.h +++ b/source/blender/python/bmesh/bmesh_py_types.h @@ -62,7 +62,7 @@ typedef struct BPy_BMElem { typedef struct BPy_BMesh { PyObject_VAR_HEAD struct BMesh *bm; /* keep first */ - char py_owns; + char py_owns; /* when set, free along with the PyObject */ } BPy_BMesh; /* element types */ From 050439fd9dcf3b7e79bae1fd409364cb1220e598 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Mar 2012 04:07:22 +0000 Subject: [PATCH 005/310] bmesh py api - correct class references in docs and rename mesh conversion funcs to ne less confusing. --- source/blender/bmesh/intern/bmesh_mesh_conv.c | 4 +- source/blender/bmesh/intern/bmesh_mesh_conv.h | 4 +- .../blender/bmesh/operators/bmo_mesh_conv.c | 4 +- source/blender/python/bmesh/bmesh_py_api.c | 4 +- source/blender/python/bmesh/bmesh_py_types.c | 4 +- source/blender/python/bmesh/bmesh_py_utils.c | 52 +++++++++---------- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.c b/source/blender/bmesh/intern/bmesh_mesh_conv.c index 7b0a59d2ca1..3b7f5182d2d 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_conv.c +++ b/source/blender/bmesh/intern/bmesh_mesh_conv.c @@ -49,7 +49,7 @@ #include "MEM_guardedalloc.h" /* Mesh -> BMesh */ -void BM_mesh_to_bmesh(BMesh *bm, Mesh *me, int set_key, int act_key_nr) +void BM_mesh_bm_from_me(BMesh *bm, Mesh *me, int set_key, int act_key_nr) { MVert *mvert; BLI_array_declare(verts); @@ -421,7 +421,7 @@ BM_INLINE void bmesh_quick_edgedraw_flag(MEdge *med, BMEdge *e) } } -void BM_mesh_from_bmesh(BMesh *bm, Mesh *me, int dotess) +void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, int dotess) { MLoop *mloop; MPoly *mpoly; diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.h b/source/blender/bmesh/intern/bmesh_mesh_conv.h index f1b820767d4..f9c51584081 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_conv.h +++ b/source/blender/bmesh/intern/bmesh_mesh_conv.h @@ -34,7 +34,7 @@ struct Mesh; -void BM_mesh_to_bmesh(BMesh *bm, struct Mesh *me, int set_key, int act_key_nr); -void BM_mesh_from_bmesh(BMesh *bm, struct Mesh *me, int dotess); +void BM_mesh_bm_from_me(BMesh *bm, struct Mesh *me, int set_key, int act_key_nr); +void BM_mesh_bm_to_me(BMesh *bm, struct Mesh *me, int dotess); #endif /* __BMESH_MESH_CONV_H__ */ diff --git a/source/blender/bmesh/operators/bmo_mesh_conv.c b/source/blender/bmesh/operators/bmo_mesh_conv.c index 3e0fc881bfa..651093806b6 100644 --- a/source/blender/bmesh/operators/bmo_mesh_conv.c +++ b/source/blender/bmesh/operators/bmo_mesh_conv.c @@ -57,7 +57,7 @@ void bmo_mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) Mesh *me = BMO_slot_ptr_get(op, "mesh"); int set_key = BMO_slot_bool_get(op, "set_shapekey"); - BM_mesh_to_bmesh(bm, me, set_key, ob->shapenr - 1); + BM_mesh_bm_from_me(bm, me, set_key, ob->shapenr - 1); if (me->key && ob->shapenr > me->key->totkey) { ob->shapenr = me->key->totkey - 1; @@ -79,5 +79,5 @@ void bmo_bmesh_to_mesh_exec(BMesh *bm, BMOperator *op) /* Object *ob = BMO_slot_ptr_get(op, "object"); */ int dotess = !BMO_slot_bool_get(op, "notessellation"); - BM_mesh_from_bmesh(bm, me, dotess); + BM_mesh_bm_to_me(bm, me, dotess); } diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c index 280bab26c4b..51c4acda45e 100644 --- a/source/blender/python/bmesh/bmesh_py_api.c +++ b/source/blender/python/bmesh/bmesh_py_api.c @@ -51,8 +51,8 @@ PyDoc_STRVAR(bpy_bm_new_doc, ".. method:: new()\n" "\n" -" :return: Retyrn a new, empty mesh.\n" -" :rtype: :class:`BMesh`\n" +" :return: Return a new, empty BMesh.\n" +" :rtype: :class:`bmesh.types.BMesh`\n" ); static PyObject *bpy_bm_new(PyObject *UNUSED(self)) diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index eefe3ccbe02..075e4889515 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -621,7 +621,7 @@ static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args) bm = self->bm; - BM_mesh_from_bmesh(bm, me, FALSE); + BM_mesh_bm_to_me(bm, me, FALSE); /* we could have the user do this but if they forget blender can easy crash * since the references arrays for the objects derived meshes are now invalid */ @@ -660,7 +660,7 @@ static PyObject *bpy_bmesh_from_mesh(BPy_BMesh *self, PyObject *args, PyObject * bm = self->bm; - BM_mesh_to_bmesh(bm, me, use_shape_key, shape_key_index + 1); + BM_mesh_bm_from_me(bm, me, use_shape_key, shape_key_index + 1); Py_RETURN_NONE; } diff --git a/source/blender/python/bmesh/bmesh_py_utils.c b/source/blender/python/bmesh/bmesh_py_utils.c index 8e9537f1d86..a41d5e7f766 100644 --- a/source/blender/python/bmesh/bmesh_py_utils.c +++ b/source/blender/python/bmesh/bmesh_py_utils.c @@ -49,11 +49,11 @@ PyDoc_STRVAR(bpy_bm_utils_vert_collapse_edge_doc, " Collapse a vertex into an edge.\n" "\n" " :arg vert: The vert that will be collapsed.\n" -" :type vert: :class:`BMVert`\n" +" :type vert: :class:`bmesh.types.BMVert`\n" " :arg edge: The edge to collapse into.\n" -" :type edge: :class:`BMEdge`\n" +" :type edge: :class:`bmesh.types.BMEdge`\n" " :return: The resulting edge from the collapse operation.\n" -" :rtype: :class:`BMEdge`\n" +" :rtype: :class:`bmesh.types.BMEdge`\n" ); static PyObject *bpy_bm_utils_vert_collapse_edge(PyObject *UNUSED(self), PyObject *args) { @@ -109,13 +109,13 @@ PyDoc_STRVAR(bpy_bm_utils_vert_collapse_faces_doc, " Split an edge, return the newly created data.\n" "\n" " :arg vert: The vert that will be collapsed.\n" -" :type vert: :class:`BMVert`\n" +" :type vert: :class:`bmesh.types.BMVert`\n" " :arg edge: The edge to collapse into.\n" -" :type edge: :class:`BMEdge`\n" +" :type edge: :class:`bmesh.types.BMEdge`\n" " :arg fac: The factor to use when merging customdata [0 - 1].\n" " :type fac: float\n" " :return: The resulting edge from the collapse operation.\n" -" :rtype: :class:`BMEdge`\n" +" :rtype: :class:`bmesh.types.BMEdge`\n" ); static PyObject *bpy_bm_utils_vert_collapse_faces(PyObject *UNUSED(self), PyObject *args) { @@ -175,7 +175,7 @@ PyDoc_STRVAR(bpy_bm_utils_vert_dissolve_doc, " Dissolve this vertex (will be removed).\n" "\n" " :arg vert: The vert to be dissolved.\n" -" :type vert: :class:`BMVert`\n" +" :type vert: :class:`bmesh.types.BMVert`\n" " :return: True when the vertex dissolve is successful.\n" " :rtype: boolean\n" ); @@ -204,11 +204,11 @@ PyDoc_STRVAR(bpy_bm_utils_vert_separate_doc, " Separate this vertex at every edge.\n" "\n" " :arg vert: The vert to be separated.\n" -" :type vert: :class:`BMVert`\n" +" :type vert: :class:`bmesh.types.BMVert`\n" " :arg edges: The edges to separated.\n" -" :type edges: :class:`BMEdge`\n" +" :type edges: :class:`bmesh.types.BMEdge`\n" " :return: The newly separated verts (including the vertex passed).\n" -" :rtype: tuple of :class:`BMVert`\n" +" :rtype: tuple of :class:`bmesh.types.BMVert`\n" ); static PyObject *bpy_bm_utils_vert_separate(PyObject *UNUSED(self), PyObject *args) { @@ -266,9 +266,9 @@ PyDoc_STRVAR(bpy_bm_utils_edge_split_doc, " Split an edge, return the newly created data.\n" "\n" " :arg edge: The edge to split.\n" -" :type edge: :class:`BMEdge`\n" +" :type edge: :class:`bmesh.types.BMEdge`\n" " :arg vert: One of the verts on the edge, defines the split direction.\n" -" :type vert: :class:`BMVert`\n" +" :type vert: :class:`bmesh.types.BMVert`\n" " :arg fac: The point on the edge where the new vert will be created [0 - 1].\n" " :type fac: float\n" " :return: The newly created (edge, vert) pair.\n" @@ -329,11 +329,11 @@ PyDoc_STRVAR(bpy_bm_utils_edge_rotate_doc, " If rotating the edge fails, None will be returned.\n" "\n" " :arg edge: The edge to rotate.\n" -" :type edge: :class:`BMEdge`\n" +" :type edge: :class:`bmesh.types.BMEdge`\n" " :arg ccw: When True the edge will be rotated counter clockwise.\n" " :type ccw: boolean\n" " :return: The newly rotated edge.\n" -" :rtype: :class:`BMEdge`\n" +" :rtype: :class:`bmesh.types.BMEdge`\n" ); static PyObject *bpy_bm_utils_edge_rotate(PyObject *UNUSED(self), PyObject *args) { @@ -371,13 +371,13 @@ PyDoc_STRVAR(bpy_bm_utils_face_split_doc, " Split an edge, return the newly created data.\n" "\n" " :arg face: The face to cut.\n" -" :type face: :class:`BMFace`\n" +" :type face: :class:`bmesh.types.BMFace`\n" " :arg vert_a: First vertex to cut in the face (face must contain the vert).\n" -" :type vert_a: :class:`BMVert`\n" +" :type vert_a: :class:`bmesh.types.BMVert`\n" " :arg vert_b: Second vertex to cut in the face (face must contain the vert).\n" -" :type vert_b: :class:`BMVert`\n" +" :type vert_b: :class:`bmesh.types.BMVert`\n" " :arg edge_example: Optional edge argument, newly created edge will copy settings from this one.\n" -" :type edge_example: :class:`BMEdge`\n" +" :type edge_example: :class:`bmesh.types.BMEdge`\n" ); static PyObject *bpy_bm_utils_face_split(PyObject *UNUSED(self), PyObject *args) { @@ -448,9 +448,9 @@ PyDoc_STRVAR(bpy_bm_utils_face_join_doc, " Joins a sequence of faces.\n" "\n" " :arg faces: Sequence of faces.\n" -" :type faces: :class:`BMFace`\n" +" :type faces: :class:`bmesh.types.BMFace`\n" " :return: The newly created face or None on failure.\n" -" :rtype: :class:`BMFace`\n" +" :rtype: :class:`bmesh.types.BMFace`\n" ); static PyObject *bpy_bm_utils_face_join(PyObject *UNUSED(self), PyObject *value) { @@ -488,11 +488,11 @@ PyDoc_STRVAR(bpy_bm_utils_face_vert_separate_doc, " Rip a vertex in a face away and add a new vertex.\n" "\n" " :arg face: The face to separate.\n" -" :type face: :class:`BMFace`\n" +" :type face: :class:`bmesh.types.BMFace`\n" " :arg vert: A vertex in the face to separate.\n" -" :type vert: :class:`BMVert`\n" +" :type vert: :class:`bmesh.types.BMVert`\n" " :return vert: The newly created vertex or None of failure.\n" -" :rtype vert: :class:`BMVert`\n" +" :rtype vert: :class:`bmesh.types.BMVert`\n" "\n" " .. note::\n" "\n" @@ -550,7 +550,7 @@ PyDoc_STRVAR(bpy_bm_utils_face_flip_doc, " Flip the faces direction.\n" "\n" " :arg face: Face to flip.\n" -" :type face: :class:`BMFace`\n" +" :type face: :class:`bmesh.types.BMFace`\n" ); static PyObject *bpy_bm_utils_face_flip(PyObject *UNUSED(self), BPy_BMFace *value) { @@ -576,9 +576,9 @@ PyDoc_STRVAR(bpy_bm_utils_loop_separate_doc, " Rip a vertex in a face away and add a new vertex.\n" "\n" " :arg loop: The to separate.\n" -" :type loop: :class:`BMFace`\n" +" :type loop: :class:`bmesh.types.BMFace`\n" " :return vert: The newly created vertex or None of failure.\n" -" :rtype vert: :class:`BMVert`\n" +" :rtype vert: :class:`bmesh.types.BMVert`\n" ); static PyObject *bpy_bm_utils_loop_separate(PyObject *UNUSED(self), BPy_BMLoop *value) { From 7fa7e4ba1faf7a122f99a683c04935e01725061c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Mar 2012 05:58:22 +0000 Subject: [PATCH 006/310] bmesh python api additions: - BMesh.is_wrapped - BMesh.copy() - BMesh.clear() - BMesh.free() - BMesh.from_object(obj, apply_modifiers=True) - BMEdge.calc_length() - BMLoop.calc_normal() - BMLoop.calc_tangent() --- source/blender/bmesh/intern/bmesh_mesh.c | 17 +- source/blender/bmesh/intern/bmesh_queries.c | 59 ++++++ source/blender/bmesh/intern/bmesh_queries.h | 2 + source/blender/python/bmesh/bmesh_py_api.c | 10 +- source/blender/python/bmesh/bmesh_py_types.c | 212 +++++++++++++++++-- source/blender/python/bmesh/bmesh_py_types.h | 9 +- 6 files changed, 276 insertions(+), 33 deletions(-) diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index 63719e778f7..392887e3aec 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -154,13 +154,6 @@ void BM_mesh_data_free(BMesh *bm) BLI_freelistN(&bm->selected); - if (bm->py_handle) { - extern void bpy_bm_generic_invalidate(void *self); - - bpy_bm_generic_invalidate(bm->py_handle); - bm->py_handle = NULL; - } - BMO_error_clear(bm); } @@ -195,6 +188,16 @@ void BM_mesh_clear(BMesh *bm) void BM_mesh_free(BMesh *bm) { BM_mesh_data_free(bm); + + if (bm->py_handle) { + /* keep this out of 'BM_mesh_data_free' because we wan't python + * to be able to clear the mesh and maintain access. */ + extern void bpy_bm_generic_invalidate(void *self); + + bpy_bm_generic_invalidate(bm->py_handle); + bm->py_handle = NULL; + } + MEM_freeN(bm); } diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index e6dc1e1dd80..4d9b21e391c 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -616,6 +616,65 @@ float BM_loop_face_angle(BMesh *UNUSED(bm), BMLoop *l) l->next->v->co); } +/** + * \brief BM_loop_face_normal + * + * Calculate the normal at this loop corner or fallback to the face normal on straignt lines. + * + * \param bm The BMesh + * \param l The loop to calculate the normal at + * \param r_normal Resulting normal + */ +void BM_loop_face_normal(BMesh *UNUSED(bm), BMLoop *l, float r_normal[3]) +{ + if (normal_tri_v3(r_normal, + l->prev->v->co, + l->v->co, + l->next->v->co) != 0.0f) + { + return; + } + else { + copy_v3_v3(r_normal, l->f->no); + } +} + +/** + * \brief BM_loop_face_tangent + * + * Calculate the tangent at this loop corner or fallback to the face normal on straignt lines. + * This vector always points inward into the face. + * + * \param bm The BMesh + * \param l The loop to calculate the tangent at + * \param r_tangent Resulting tangent + */ +void BM_loop_face_tangent(BMesh *UNUSED(bm), BMLoop *l, float r_tangent[3]) +{ + float v_prev[3]; + float v_next[3]; + + sub_v3_v3v3(v_prev, l->prev->v->co, l->v->co); + sub_v3_v3v3(v_next, l->v->co, l->next->v->co); + + normalize_v3(v_prev); + normalize_v3(v_next); + + if (compare_v3v3(v_prev, v_next, FLT_EPSILON) == FALSE) { + float dir[3]; + float nor[3]; /* for this purpose doesnt need to be normalized */ + add_v3_v3v3(dir, v_prev, v_next); + cross_v3_v3v3(nor, v_prev, v_next); + cross_v3_v3v3(r_tangent, dir, nor); + } + else { + /* prev/next are the same - compare with face normal since we dont have one */ + cross_v3_v3v3(r_tangent, v_next, l->f->no); + } + + normalize_v3(r_tangent); +} + /** * \brief BMESH EDGE/FACE ANGLE * diff --git a/source/blender/bmesh/intern/bmesh_queries.h b/source/blender/bmesh/intern/bmesh_queries.h index a394999d439..6975c40c10a 100644 --- a/source/blender/bmesh/intern/bmesh_queries.h +++ b/source/blender/bmesh/intern/bmesh_queries.h @@ -54,6 +54,8 @@ int BM_edge_is_manifold(BMesh *bm, BMEdge *e); int BM_edge_is_boundary(BMEdge *e); float BM_loop_face_angle(BMesh *bm, BMLoop *l); +void BM_loop_face_normal(BMesh *bm, BMLoop *l, float r_normal[3]); +void BM_loop_face_tangent(BMesh *bm, BMLoop *l, float r_tangent[3]); float BM_edge_face_angle(BMesh *bm, BMEdge *e); float BM_vert_edge_angle(BMesh *bm, BMVert *v); diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c index 51c4acda45e..1601034542b 100644 --- a/source/blender/python/bmesh/bmesh_py_api.c +++ b/source/blender/python/bmesh/bmesh_py_api.c @@ -57,14 +57,11 @@ PyDoc_STRVAR(bpy_bm_new_doc, static PyObject *bpy_bm_new(PyObject *UNUSED(self)) { - BPy_BMesh *py_bmesh; BMesh *bm; bm = BM_mesh_create(NULL, &bm_mesh_allocsize_default); - py_bmesh = (BPy_BMesh *)BPy_BMesh_CreatePyObject(bm); - py_bmesh->py_owns = TRUE; - return (PyObject *)py_bmesh; + return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_NOP); } PyDoc_STRVAR(bpy_bm_from_edit_mesh_doc, @@ -77,7 +74,6 @@ PyDoc_STRVAR(bpy_bm_from_edit_mesh_doc, ); static PyObject *bpy_bm_from_edit_mesh(PyObject *UNUSED(self), PyObject *value) { - BPy_BMesh *py_bmesh; BMesh *bm; Mesh *me = PyC_RNA_AsPointer(value, "Mesh"); @@ -93,9 +89,7 @@ static PyObject *bpy_bm_from_edit_mesh(PyObject *UNUSED(self), PyObject *value) bm = me->edit_btmesh->bm; - py_bmesh = (BPy_BMesh *)BPy_BMesh_CreatePyObject(bm); - py_bmesh->py_owns = FALSE; - return (PyObject *)py_bmesh; + return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_IS_WRAPPED); } static struct PyMethodDef BPy_BM_methods[] = { diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 075e4889515..53f32292cc3 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -36,6 +36,7 @@ #include "BKE_depsgraph.h" #include "BKE_customdata.h" +#include "BKE_DerivedMesh.h" #include "bmesh.h" @@ -252,6 +253,15 @@ static PyObject *bpy_bm_is_valid_get(BPy_BMGeneric *self) return PyBool_FromLong(BPY_BM_IS_VALID(self)); } +PyDoc_STRVAR(bpy_bmesh_is_wrapped_doc, +"True when this mesh is owned by blender (typically the editmode BMesh).\n\n:type: boolean" +); +static PyObject *bpy_bmesh_is_wrapped_get(BPy_BMesh *self) +{ + BPY_BM_CHECK_OBJ(self); + + return PyBool_FromLong(self->flag & BPY_BMFLAG_IS_WRAPPED); +} PyDoc_STRVAR(bpy_bmesh_select_mode_doc, "The selection mode, values can be {'VERT', 'EDGE', 'FACE'}, can't be assigned an empty set.\n\n:type: set" @@ -484,7 +494,8 @@ static PyGetSetDef bpy_bmesh_getseters[] = { {(char *)"select_history", (getter)bpy_bmesh_select_history_get, (setter)bpy_bmesh_select_history_set, (char *)bpy_bmesh_select_history_doc, NULL}, /* readonly checks */ - {(char *)"is_valid", (getter)bpy_bm_is_valid_get, (setter)NULL, (char *)bpy_bm_is_valid_doc, NULL}, + {(char *)"is_wrapped", (getter)bpy_bmesh_is_wrapped_get, (setter)NULL, (char *)bpy_bmesh_is_wrapped_doc, NULL}, /* as with mathutils */ + {(char *)"is_valid", (getter)bpy_bm_is_valid_get, (setter)NULL, (char *)bpy_bm_is_valid_doc, NULL}, {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; @@ -590,6 +601,76 @@ static PyGetSetDef bpy_bmloop_getseters[] = { /* Mesh * ---- */ +PyDoc_STRVAR(bpy_bmesh_copy_doc, +".. method:: copy()\n" +"\n" +" :return: A copy of this BMesh.\n" +" :rtype: :class:`BMesh`\n" +); +static PyObject *bpy_bmesh_copy(BPy_BMesh *self) +{ + BMesh *bm; + BMesh *bm_copy; + + BPY_BM_CHECK_OBJ(self); + + bm = self->bm; + + bm_copy = BM_mesh_copy(bm); + + if (bm_copy) { + return BPy_BMesh_CreatePyObject(bm_copy, BPY_BMFLAG_NOP); + } + else { + PyErr_SetString(PyExc_SystemError, "Unable to copy BMesh, internal error"); + return NULL; + } +} + +PyDoc_STRVAR(bpy_bmesh_clear_doc, +".. method:: clear()\n" +"\n" +" Clear all mesh data.\n" +); +static PyObject *bpy_bmesh_clear(BPy_BMesh *self) +{ + BMesh *bm; + + BPY_BM_CHECK_OBJ(self); + + bm = self->bm; + + BM_mesh_clear(bm); + + Py_RETURN_NONE; +} + +PyDoc_STRVAR(bpy_bmesh_free_doc, +".. method:: free()\n" +"\n" +" Explicitly free the BMesh data from memory, causing exceptions on further access.\n" +"\n" +" .. note::\n" +"\n" +" The BMesh is freed automatically, typically when the script finishes executing.\n" +" However in some cases its hard to predict when this will be and its useful to\n" +" explicitly free the data.\n" +); +static PyObject *bpy_bmesh_free(BPy_BMesh *self) +{ + if (self->bm) { + BMesh *bm = self->bm; + + if ((self->flag & BPY_BMFLAG_IS_WRAPPED) == 0) { + BM_mesh_free(bm); + } + + bpy_bm_generic_invalidate((BPy_BMGeneric *)self); + } + + Py_RETURN_NONE; +} + PyDoc_STRVAR(bpy_bmesh_to_mesh_doc, ".. method:: to_mesh(mesh)\n" "\n" @@ -630,6 +711,49 @@ static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args) Py_RETURN_NONE; } +/* note: rna_Object_to_mesh() also has apply_modifiers arg that works the same way */ +PyDoc_STRVAR(bpy_bmesh_from_object_doc, +".. method:: from_object(mesh, apply_modifiers=True)\n" +"\n" +" Initialize this bmesh from existing object datablock.\n" +"\n" +" :arg object: The object data to load.\n" +" :type object: :class:`Object`\n" +" :arg apply_modifiers: Use the final display mesh rather then the deformed cage.\n" +" :type apply_modifiers: boolean\n" +); +static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args) +{ + PyObject *py_object; + Object *ob; + BMesh *bm; + int apply_modifiers = TRUE; + DerivedMesh *dm; + + BPY_BM_CHECK_OBJ(self); + + if (!PyArg_ParseTuple(args, "O|i:from_object", &py_object, &apply_modifiers) || + !(ob = PyC_RNA_AsPointer(py_object, "Object"))) + { + return NULL; + } + + dm = apply_modifiers ? ob->derivedFinal : ob->derivedDeform; + + if (dm == NULL) { + PyErr_Format(PyExc_ValueError, + "from_object(...): Object '%s' has no usable mesh data", ob->id.name + 2); + return NULL; + } + + bm = self->bm; + + DM_to_bmesh_ex(dm, bm); + + Py_RETURN_NONE; +} + + PyDoc_STRVAR(bpy_bmesh_from_mesh_doc, ".. method:: from_mesh(mesh, use_shape_key=False, shape_key_index=0)\n" "\n" @@ -651,7 +775,7 @@ static PyObject *bpy_bmesh_from_mesh(BPy_BMesh *self, PyObject *args, PyObject * int use_shape_key = FALSE; int shape_key_index = 0; - if (!PyArg_ParseTupleAndKeywords(args, kw, "O|ii:to_mesh", (char **)kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kw, "O|ii:from_mesh", (char **)kwlist, &py_mesh, &use_shape_key, &shape_key_index) || !(me = PyC_RNA_AsPointer(py_mesh, "Mesh"))) { @@ -1001,12 +1125,22 @@ static PyObject *bpy_bmvert_normal_update(BPy_BMVert *self) /* Edge * ---- */ +PyDoc_STRVAR(bpy_bmedge_calc_length_doc, +".. method:: calc_length()\n" +"\n" +" :return: The length between both verts.\n" +" :rtype: float\n" +); +static PyObject *bpy_bmedge_calc_length(BPy_BMEdge *self) +{ + BPY_BM_CHECK_OBJ(self); + return PyFloat_FromDouble(len_v3v3(self->e->v1->co, self->e->v2->co)); +} + PyDoc_STRVAR(bpy_bmedge_calc_face_angle_doc, ".. method:: calc_face_angle()\n" "\n" -" Return the angle between 2 connected faces.\n" -"\n" -" :return: The angle between both faces in radians.\n" +" :return: The angle between 2 connected faces in radians.\n" " :rtype: float\n" ); static PyObject *bpy_bmedge_calc_face_angle(BPy_BMEdge *self) @@ -1270,21 +1404,54 @@ static PyObject *bpy_bmloop_copy_from_face_interp(BPy_BMLoop *self, PyObject *ar } -PyDoc_STRVAR(bpy_bmloop_calc_face_angle_doc, -".. method:: calc_face_angle()\n" +PyDoc_STRVAR(bpy_bmloop_calc_angle_doc, +".. method:: calc_angle()\n" "\n" -" Return angle at this loops corner of the face.\n" +" Return the angle at this loops corner of the face.\n" " This is calculated so sharper corners give lower angles.\n" "\n" " :return: The angle in radians.\n" " :rtype: float\n" ); -static PyObject *bpy_bmloop_calc_face_angle(BPy_BMLoop *self) +static PyObject *bpy_bmloop_calc_angle(BPy_BMLoop *self) { BPY_BM_CHECK_OBJ(self); return PyFloat_FromDouble(BM_loop_face_angle(self->bm, self->l)); } +PyDoc_STRVAR(bpy_bmloop_calc_normal_doc, +".. method:: calc_normal()\n" +"\n" +" Return normal at this loops corner of the face.\n" +" Falls back to the face normal for straignt lines.\n" +"\n" +" :return: a normalized vector.\n" +" :rtype: :class:`mathutils.Vector`\n" +); +static PyObject *bpy_bmloop_calc_normal(BPy_BMLoop *self) +{ + float vec[3]; + BPY_BM_CHECK_OBJ(self); + BM_loop_face_normal(self->bm, self->l, vec); + return Vector_CreatePyObject(vec, 3, Py_NEW, NULL); +} + +PyDoc_STRVAR(bpy_bmloop_calc_tangent_doc, +".. method:: calc_tangent()\n" +"\n" +" Return the tangent at this loops corner of the face (pointing inward into the face).\n" +" Falls back to the face normal for straignt lines.\n" +"\n" +" :return: a normalized vector.\n" +" :rtype: :class:`mathutils.Vector`\n" +); +static PyObject *bpy_bmloop_calc_tangent(BPy_BMLoop *self) +{ + float vec[3]; + BPY_BM_CHECK_OBJ(self); + BM_loop_face_tangent(self->bm, self->l, vec); + return Vector_CreatePyObject(vec, 3, Py_NEW, NULL); +} /* Vert Seq * -------- */ @@ -1796,9 +1963,17 @@ static PyObject *bpy_bmelemseq_index_update(BPy_BMElemSeq *self) static struct PyMethodDef bpy_bmesh_methods[] = { - {"from_mesh", (PyCFunction)bpy_bmesh_from_mesh, METH_VARARGS | METH_KEYWORDS, bpy_bmesh_from_mesh_doc}, - {"to_mesh", (PyCFunction)bpy_bmesh_to_mesh, METH_VARARGS, bpy_bmesh_to_mesh_doc}, + /* utility */ + {"copy", (PyCFunction)bpy_bmesh_copy, METH_NOARGS, bpy_bmesh_copy_doc}, + {"clear", (PyCFunction)bpy_bmesh_clear, METH_NOARGS, bpy_bmesh_clear_doc}, + {"free", (PyCFunction)bpy_bmesh_free, METH_NOARGS, bpy_bmesh_free_doc}, + /* conversion */ + {"from_object", (PyCFunction)bpy_bmesh_from_object, METH_VARARGS | METH_KEYWORDS, bpy_bmesh_from_object_doc}, + {"from_mesh", (PyCFunction)bpy_bmesh_from_mesh, METH_VARARGS | METH_KEYWORDS, bpy_bmesh_from_mesh_doc}, + {"to_mesh", (PyCFunction)bpy_bmesh_to_mesh, METH_VARARGS, bpy_bmesh_to_mesh_doc}, + + /* meshdata */ {"select_flush_mode", (PyCFunction)bpy_bmesh_select_flush_mode, METH_NOARGS, bpy_bmesh_select_flush_mode_doc}, {"select_flush", (PyCFunction)bpy_bmesh_select_flush, METH_O, bpy_bmesh_select_flush_doc}, {"normal_update", (PyCFunction)bpy_bmesh_normal_update, METH_VARARGS, bpy_bmesh_normal_update_doc}, @@ -1827,6 +2002,7 @@ static struct PyMethodDef bpy_bmedge_methods[] = { {"other_vert", (PyCFunction)bpy_bmedge_other_vert, METH_O, bpy_bmedge_other_vert_doc}, + {"calc_length", (PyCFunction)bpy_bmedge_calc_length, METH_NOARGS, bpy_bmedge_calc_length_doc}, {"calc_face_angle", (PyCFunction)bpy_bmedge_calc_face_angle, METH_NOARGS, bpy_bmedge_calc_face_angle_doc}, {"normal_update", (PyCFunction)bpy_bmedge_normal_update, METH_NOARGS, bpy_bmedge_normal_update_doc}, @@ -1856,7 +2032,9 @@ static struct PyMethodDef bpy_bmloop_methods[] = { {"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc}, {"copy_from_face_interp", (PyCFunction)bpy_bmloop_copy_from_face_interp, METH_O, bpy_bmloop_copy_from_face_interp_doc}, - {"calc_angle", (PyCFunction)bpy_bmloop_calc_face_angle, METH_NOARGS, bpy_bmloop_calc_face_angle_doc}, + {"calc_angle", (PyCFunction)bpy_bmloop_calc_angle, METH_NOARGS, bpy_bmloop_calc_angle_doc}, + {"calc_normal", (PyCFunction)bpy_bmloop_calc_normal, METH_NOARGS, bpy_bmloop_calc_normal_doc}, + {"calc_tangent", (PyCFunction)bpy_bmloop_calc_tangent, METH_NOARGS, bpy_bmloop_calc_tangent_doc}, {NULL, NULL, 0, NULL} }; @@ -2143,10 +2321,10 @@ static void bpy_bmesh_dealloc(BPy_BMesh *self) BM_data_layer_free(bm, &bm->ldata, CD_BM_ELEM_PYPTR); bm->py_handle = NULL; - } - if (self->py_owns) { - BM_mesh_free(bm); + if ((self->flag & BPY_BMFLAG_IS_WRAPPED) == 0) { + BM_mesh_free(bm); + } } PyObject_DEL(self); @@ -2476,7 +2654,7 @@ PyObject *BPyInit_bmesh_types(void) /* Utility Functions * ***************** */ -PyObject *BPy_BMesh_CreatePyObject(BMesh *bm) +PyObject *BPy_BMesh_CreatePyObject(BMesh *bm, int flag) { BPy_BMesh *self; @@ -2487,6 +2665,8 @@ PyObject *BPy_BMesh_CreatePyObject(BMesh *bm) else { self = PyObject_New(BPy_BMesh, &BPy_BMesh_Type); self->bm = bm; + self->flag = flag; + bm->py_handle = self; /* point back */ BM_data_layer_add(bm, &bm->vdata, CD_BM_ELEM_PYPTR); diff --git a/source/blender/python/bmesh/bmesh_py_types.h b/source/blender/python/bmesh/bmesh_py_types.h index 88569c5eeaf..b5b96002ccc 100644 --- a/source/blender/python/bmesh/bmesh_py_types.h +++ b/source/blender/python/bmesh/bmesh_py_types.h @@ -62,7 +62,7 @@ typedef struct BPy_BMElem { typedef struct BPy_BMesh { PyObject_VAR_HEAD struct BMesh *bm; /* keep first */ - char py_owns; /* when set, free along with the PyObject */ + int flag; } BPy_BMesh; /* element types */ @@ -120,7 +120,12 @@ void BPy_BM_init_types(void); PyObject *BPyInit_bmesh_types(void); -PyObject *BPy_BMesh_CreatePyObject(BMesh *bm); +enum { + BPY_BMFLAG_NOP = 0, /* do nothing */ + BPY_BMFLAG_IS_WRAPPED = 1 /* the mesh is owned by editmode */ +}; + +PyObject *BPy_BMesh_CreatePyObject(BMesh *bm, int flag); PyObject *BPy_BMVert_CreatePyObject(BMesh *bm, BMVert *v); PyObject *BPy_BMEdge_CreatePyObject(BMesh *bm, BMEdge *e); PyObject *BPy_BMFace_CreatePyObject(BMesh *bm, BMFace *f); From 2382afa968afa338bbbc3f2e615c847e5ddbc770 Mon Sep 17 00:00:00 2001 From: Jens Verwiebe Date: Sun, 11 Mar 2012 11:23:30 +0000 Subject: [PATCH 007/310] OSX/libmv: added a ahck to fix compiling with 10.6.sdk, unwind.h related --- extern/libmv/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index 73c2baa0207..db788059800 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -37,6 +37,9 @@ set(INC set(INC_SYS ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS} + if(APPLE) # this is a momentary hack to find unwind.h in 10.6.sdk + ${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include + endif() ) set(SRC From fa169fdcb69ef3310b747c9433eddbc4b0435a95 Mon Sep 17 00:00:00 2001 From: Jens Verwiebe Date: Sun, 11 Mar 2012 12:15:39 +0000 Subject: [PATCH 008/310] OSX/libmv: restrict the unwind.h workaround to 10.6.sdk only --- extern/libmv/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index db788059800..3bd021209df 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -37,7 +37,7 @@ set(INC set(INC_SYS ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS} - if(APPLE) # this is a momentary hack to find unwind.h in 10.6.sdk + if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.6") # this is a momentary hack to find unwind.h in 10.6.sdk ${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include endif() ) From 19400d418d4ac5e3b064dd41f825d2a257472127 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Mar 2012 15:27:08 +0000 Subject: [PATCH 009/310] fix for debug assignment left in from own commit r44778 also removed private face normal update functions - they were same as public. --- .../blenkernel/intern/editderivedmesh.c | 2 +- source/blender/bmesh/intern/bmesh_mesh.c | 2 +- source/blender/bmesh/intern/bmesh_polygon.c | 66 ++++++++----------- source/blender/bmesh/intern/bmesh_polygon.h | 3 +- source/blender/bmesh/intern/bmesh_private.h | 4 -- .../blender/makesrna/intern/rna_object_api.c | 2 +- 6 files changed, 33 insertions(+), 46 deletions(-) diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index ff798f5f2a1..3f4ca1b00a2 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -1689,7 +1689,7 @@ DerivedMesh *getEditDerivedBMesh( i = 0; BM_ITER(efa, &fiter, bm, BM_FACES_OF_MESH, NULL) { BM_elem_index_set(efa, i); /* set_inline */ - BM_face_normal_update_vcos(bm, efa, bmdm->polyNos[i], vertexCos); + BM_face_normal_update_vcos(bm, efa, bmdm->polyNos[i], (float const (*)[3])vertexCos); i++; } bm->elem_index_dirty &= ~BM_FACE; diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index 392887e3aec..c01e8afd716 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -228,7 +228,7 @@ void BM_mesh_normals_update(BMesh *bm, const short skip_hidden) continue; #endif - bmesh_face_normal_update(bm, f, f->no); + BM_face_normal_update(bm, f); } /* Zero out vertex normals */ diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index 54063c28ea5..bdecdfee850 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -75,15 +75,13 @@ static short testedgesidef(const float v1[2], const float v2[2], const float v3[ * polygon See Graphics Gems for * computing newell normal. */ -static void compute_poly_normal(float normal[3], float (*verts)[3], int nverts) +static void compute_poly_normal(float normal[3], float const (* verts)[3], int nverts) { float const *v_prev = verts[nverts - 1]; float const *v_curr = verts[0]; float n[3] = {0.0f}; int i; - verts[0][0] = 1; - /* Newell's Method */ for (i = 0; i < nverts; v_prev = v_curr, v_curr = verts[++i]) { n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]); @@ -132,14 +130,15 @@ static void bm_face_compute_poly_normal(BMFace *f) * Same as #compute_poly_normal and #bm_face_compute_poly_normal * but takes an array of vertex locations. */ -static void bm_face_compute_poly_normal_vcos(BMFace *f, float (*vertexCos)[3]) +static void bm_face_compute_poly_normal_vertex_cos(BMFace *f, float n[3], + float const (*vertexCos)[3]) { BMLoop *l_first = BM_FACE_FIRST_LOOP(f); BMLoop *l_iter = l_first; float const *v_prev = vertexCos[BM_elem_index_get(l_first->prev->v)]; float const *v_curr = vertexCos[BM_elem_index_get(l_first->v)]; - float n[3] = {0.0f}; + zero_v3(n); /* Newell's Method */ do { @@ -152,8 +151,8 @@ static void bm_face_compute_poly_normal_vcos(BMFace *f, float (*vertexCos)[3]) v_curr = vertexCos[BM_elem_index_get(l_iter->v)]; } while (l_iter != l_first); - if (UNLIKELY(normalize_v3_v3(f->no, n) == 0.0f)) { - f->no[2] = 1.0f; /* other axis set to 0.0 */ + if (UNLIKELY(normalize_v3(n) == 0.0f)) { + n[2] = 1.0f; /* other axis set to 0.0 */ } } @@ -164,7 +163,7 @@ static void bm_face_compute_poly_normal_vcos(BMFace *f, float (*vertexCos)[3]) * area of a polygon in the X/Y * plane. */ -static int compute_poly_center(float center[3], float *r_area, float (*verts)[3], int nverts) +static int compute_poly_center(float center[3], float *r_area, float (* const verts)[3], int nverts) { int i, j; float atmp = 0.0f, xtmp = 0.0f, ytmp = 0.0f, ai; @@ -359,25 +358,6 @@ void poly_rotate_plane(const float normal[3], float (*verts)[3], const int nvert mul_m3_v3(mat, verts[i]); } -/** - * \brief BMESH UPDATE FACE NORMAL - * - * Updates the stored normal for the - * given face. Requires that a buffer - * of sufficient length to store projected - * coordinates for all of the face's vertices - * is passed in as well. - */ -void BM_face_normal_update(BMesh *bm, BMFace *f) -{ - bmesh_face_normal_update(bm, f, f->no); -} -/* same as BM_face_normal_update but takes vertex coords */ -void BM_face_normal_update_vcos(BMesh *bm, BMFace *f, float no[3], float (*vertexCos)[3]) -{ - bmesh_face_normal_update_vertex_cos(bm, f, no, vertexCos); -} - /** * updates face and vertex normals incident on an edge */ @@ -440,7 +420,17 @@ void BM_vert_normal_update_all(BMesh *bm, BMVert *v) BM_vert_normal_update(bm, v); } -void bmesh_face_normal_update(BMesh *UNUSED(bm), BMFace *f, float no[3]) +/** + * \brief BMESH UPDATE FACE NORMAL + * + * Updates the stored normal for the + * given face. Requires that a buffer + * of sufficient length to store projected + * coordinates for all of the face's vertices + * is passed in as well. + */ + +void BM_face_normal_update(BMesh *UNUSED(bm), BMFace *f) { BMLoop *l; @@ -453,7 +443,7 @@ void bmesh_face_normal_update(BMesh *UNUSED(bm), BMFace *f, float no[3]) const float *co3 = (l = l->next)->v->co; const float *co4 = (l->next)->v->co; - normal_quad_v3(no, co1, co2, co3, co4); + normal_quad_v3(f->no, co1, co2, co3, co4); break; } case 3: @@ -462,12 +452,12 @@ void bmesh_face_normal_update(BMesh *UNUSED(bm), BMFace *f, float no[3]) const float *co2 = (l = l->next)->v->co; const float *co3 = (l->next)->v->co; - normal_tri_v3(no, co1, co2, co3); + normal_tri_v3(f->no, co1, co2, co3); break; } case 0: { - zero_v3(no); + zero_v3(f->no); break; } default: @@ -478,8 +468,8 @@ void bmesh_face_normal_update(BMesh *UNUSED(bm), BMFace *f, float no[3]) } } /* exact same as 'bmesh_face_normal_update' but accepts vertex coords */ -void bmesh_face_normal_update_vertex_cos(BMesh *bm, BMFace *f, float no[3], - float (*vertexCos)[3]) +void BM_face_normal_update_vcos(BMesh *bm, BMFace *f, float no[3], + float const (*vertexCos)[3]) { BMLoop *l; @@ -514,7 +504,7 @@ void bmesh_face_normal_update_vertex_cos(BMesh *bm, BMFace *f, float no[3], } default: { - bm_face_compute_poly_normal_vcos(f, vertexCos); + bm_face_compute_poly_normal_vertex_cos(f, no, vertexCos); break; } } @@ -634,7 +624,7 @@ int BM_face_point_inside_test(BMesh *bm, BMFace *f, const float co[3]) return crosses % 2 != 0; } -static int goodline(float (*projectverts)[3], BMFace *f, int v1i, +static int goodline(float const (*projectverts)[3], BMFace *f, int v1i, int v2i, int v3i, int UNUSED(nvert)) { BMLoop *l_iter; @@ -720,7 +710,7 @@ static BMLoop *find_ear(BMesh *UNUSED(bm), BMFace *f, float (*verts)[3], const i if (BM_edge_exists(v1, v3)) { isear = 0; } - else if (!goodline(verts, f, BM_elem_index_get(v1), BM_elem_index_get(v2), BM_elem_index_get(v3), nvert)) { + else if (!goodline((float const (*)[3])verts, f, BM_elem_index_get(v1), BM_elem_index_get(v2), BM_elem_index_get(v3), nvert)) { isear = 0; } @@ -785,7 +775,7 @@ void BM_face_triangulate(BMesh *bm, BMFace *f, float (*projectverts)[3], ///bmesh_face_normal_update(bm, f, f->no, projectverts); - compute_poly_normal(f->no, projectverts, f->len); + compute_poly_normal(f->no, (float const (*)[3])projectverts, f->len); poly_rotate_plane(f->no, projectverts, i); nvert = f->len; @@ -899,7 +889,7 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) a++; } - compute_poly_normal(no, projverts, f->len); + compute_poly_normal(no, (float const (*)[3])projverts, f->len); poly_rotate_plane(no, projverts, f->len); poly_rotate_plane(no, edgeverts, len * 2); diff --git a/source/blender/bmesh/intern/bmesh_polygon.h b/source/blender/bmesh/intern/bmesh_polygon.h index 49fe2d7a809..3c8f3dc3339 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.h +++ b/source/blender/bmesh/intern/bmesh_polygon.h @@ -32,7 +32,8 @@ void BM_face_center_bounds_calc(BMesh *bm, BMFace *f, float center[3]); void BM_face_center_mean_calc(BMesh *bm, BMFace *f, float center[3]); void BM_face_normal_update(BMesh *bm, BMFace *f); -void BM_face_normal_update_vcos(BMesh *bm, BMFace *f, float no[3], float (*vertexCos)[3]); +void BM_face_normal_update_vcos(BMesh *bm, BMFace *f, float no[3], + float const (*vertexCos)[3]); void BM_edge_normals_update(BMesh *bm, BMEdge *e); diff --git a/source/blender/bmesh/intern/bmesh_private.h b/source/blender/bmesh/intern/bmesh_private.h index d44eaba039b..3f67deb7997 100644 --- a/source/blender/bmesh/intern/bmesh_private.h +++ b/source/blender/bmesh/intern/bmesh_private.h @@ -65,10 +65,6 @@ int bmesh_disk_count(BMVert *v); #define BM_ELEM_API_FLAG_DISABLE(element, f) ((element)->oflags[0].pflag &= ~(f)) #define BM_ELEM_API_FLAG_TEST(element, f) ((element)->oflags[0].pflag & (f)) -void bmesh_face_normal_update(BMesh *bm, BMFace *f, float no[3]); -void bmesh_face_normal_update_vertex_cos(BMesh *bm, BMFace *f, float no[3], - float (*vertexCos)[3]); - void compute_poly_plane(float (*verts)[3], int nverts); void poly_rotate_plane(const float normal[3], float (*verts)[3], const int nverts); diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index f33cf1a3993..ed806c96beb 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -527,7 +527,7 @@ void RNA_api_object(StructRNA *srna) static EnumPropertyItem mesh_dm_info_items[] = { {0, "SOURCE", 0, "Source", "Source mesh"}, {1, "DEFORM", 0, "Deform", "Objects deform mesh"}, - {2, "FINAL", 0, "Final", "Objects final mesh"}, + {2, "FINAL", 0, "Final", "Objects final mesh"}, {0, NULL, 0, NULL, NULL} }; #endif From e13e78495bea15cc2a5941dff51b2a958081bba6 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Sun, 11 Mar 2012 16:25:58 +0000 Subject: [PATCH 010/310] Cycles UI files: * Minor cleanup and raise blender version to 2.62 in the addon. --- intern/cycles/blender/addon/__init__.py | 2 +- intern/cycles/blender/addon/ui.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/intern/cycles/blender/addon/__init__.py b/intern/cycles/blender/addon/__init__.py index 6a5ccbb0499..41591085d0a 100644 --- a/intern/cycles/blender/addon/__init__.py +++ b/intern/cycles/blender/addon/__init__.py @@ -22,7 +22,7 @@ bl_info = { "name": "Cycles Render Engine", "author": "", "version": (0, 0), - "blender": (2, 6, 0), + "blender": (2, 6, 2), "location": "Info header, render engine menu", "description": "Cycles Render Engine integration.", "warning": "", diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index 745fb8366da..39f55aafa39 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -527,9 +527,9 @@ class CyclesWorld_PT_ambient_occlusion(CyclesButtonsPanel, Panel): layout.active = light.use_ambient_occlusion - split = layout.split() - split.prop(light, "ao_factor", text="Factor") - split.prop(light, "distance", text="Distance") + row = layout.row() + row.prop(light, "ao_factor", text="Factor") + row.prop(light, "distance", text="Distance") class CyclesWorld_PT_settings(CyclesButtonsPanel, Panel): @@ -649,7 +649,6 @@ class CyclesTexture_PT_context(CyclesButtonsPanel, Panel): pin_id = space.pin_id use_pin_id = space.use_pin_id user = context.texture_user - # node = context.texture_node if not use_pin_id or not isinstance(pin_id, bpy.types.Texture): pin_id = None From 178c2c32f2b39e8d797ca4e4fed3fb9283e3e210 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Mar 2012 17:24:03 +0000 Subject: [PATCH 011/310] [#30503] Callback for render job completion from Jason van Gumster (thefallenweeble) adds render_complete and render_cancel callbacks to bpy.app.handlers --- source/blender/blenlib/BLI_callbacks.h | 2 ++ source/blender/python/intern/bpy_app_handlers.c | 2 ++ source/blender/render/intern/source/pipeline.c | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/source/blender/blenlib/BLI_callbacks.h b/source/blender/blenlib/BLI_callbacks.h index f4f92a0cbee..b32a1e272c8 100644 --- a/source/blender/blenlib/BLI_callbacks.h +++ b/source/blender/blenlib/BLI_callbacks.h @@ -42,6 +42,8 @@ typedef enum { BLI_CB_EVT_RENDER_PRE, BLI_CB_EVT_RENDER_POST, BLI_CB_EVT_RENDER_STATS, + BLI_CB_EVT_RENDER_COMPLETE, + BLI_CB_EVT_RENDER_CANCEL, BLI_CB_EVT_LOAD_PRE, BLI_CB_EVT_LOAD_POST, BLI_CB_EVT_SAVE_PRE, diff --git a/source/blender/python/intern/bpy_app_handlers.c b/source/blender/python/intern/bpy_app_handlers.c index f4962cd39b6..daa842f0629 100644 --- a/source/blender/python/intern/bpy_app_handlers.c +++ b/source/blender/python/intern/bpy_app_handlers.c @@ -47,6 +47,8 @@ static PyStructSequence_Field app_cb_info_fields[] = { {(char *)"render_pre", (char *)"Callback list - on render (before)"}, {(char *)"render_post", (char *)"Callback list - on render (after)"}, {(char *)"render_stats", (char *)"Callback list - on printing render statistics"}, + {(char *)"render_complete", (char *)"Callback list - on completion of render job"}, + {(char *)"render_cancel", (char *)"Callback list - on cancelling a render job"}, {(char *)"load_pre", (char *)"Callback list - on loading a new blend file (before)"}, {(char *)"load_post", (char *)"Callback list - on loading a new blend file (after)"}, {(char *)"save_pre", (char *)"Callback list - on saving a blend file (before)"}, diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 73305755fc5..87d55795924 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -2022,6 +2022,8 @@ void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *sr BLI_exec_cb(re->main, (ID *)scene, BLI_CB_EVT_RENDER_POST); /* keep after file save */ } + BLI_exec_cb(re->main, (ID *)scene, G.afbreek ? BLI_CB_EVT_RENDER_CANCEL : BLI_CB_EVT_RENDER_COMPLETE); + /* UGLY WARNING */ G.rendering= 0; } @@ -2239,6 +2241,8 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri re->flag &= ~R_ANIMATION; + BLI_exec_cb(re->main, (ID *)scene, G.afbreek ? BLI_CB_EVT_RENDER_CANCEL : BLI_CB_EVT_RENDER_COMPLETE); + /* UGLY WARNING */ G.rendering= 0; } From 65895a2a383738d6edf0d82b428483065d672305 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Mar 2012 17:41:19 +0000 Subject: [PATCH 012/310] improve confusing macro GET_ACF_FLAG_PTR - was operating on `type` which wasnt an argument to the macro. - was calling return within the macro (makes code harder to follow). --- .../editors/animation/anim_channels_defines.c | 95 +++++++++---------- 1 file changed, 46 insertions(+), 49 deletions(-) diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index 9e3630aea67..81513eb0842 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -87,12 +87,9 @@ #define ANIM_CHAN_NAME_SIZE 256 /* macros used for type defines */ - /* get the pointer used for some flag */ -#define GET_ACF_FLAG_PTR(ptr) \ - { \ - *type= sizeof((ptr)); \ - return &(ptr); \ - } + +/* get the pointer used for some flag and return */ +#define GET_ACF_FLAG_PTR(ptr, type) ((*(type) = sizeof((ptr))), &(ptr)) /* *********************************************** */ @@ -453,7 +450,7 @@ static void *acf_summary_setting_ptr(bAnimListElem *ale, int setting, short *typ bDopeSheet *ads= &saction->ads; /* return pointer to DopeSheet's flag */ - GET_ACF_FLAG_PTR(ads->flag); + return GET_ACF_FLAG_PTR(ads->flag, type); } else { /* can't return anything useful - unsupported */ @@ -547,15 +544,15 @@ static void *acf_scene_setting_ptr(bAnimListElem *ale, int setting, short *type) switch (setting) { case ACHANNEL_SETTING_SELECT: /* selected */ - GET_ACF_FLAG_PTR(scene->flag); + return GET_ACF_FLAG_PTR(scene->flag, type); case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(scene->flag); + return GET_ACF_FLAG_PTR(scene->flag, type); case ACHANNEL_SETTING_MUTE: /* mute (only in NLA) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (scene->adt) - GET_ACF_FLAG_PTR(scene->adt->flag) + return GET_ACF_FLAG_PTR(scene->adt->flag, type); else return NULL; @@ -694,15 +691,15 @@ static void *acf_object_setting_ptr(bAnimListElem *ale, int setting, short *type switch (setting) { case ACHANNEL_SETTING_SELECT: /* selected */ - GET_ACF_FLAG_PTR(ob->flag); + return GET_ACF_FLAG_PTR(ob->flag, type); case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(ob->nlaflag); // xxx + return GET_ACF_FLAG_PTR(ob->nlaflag, type); // xxx case ACHANNEL_SETTING_MUTE: /* mute (only in NLA) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (ob->adt) - GET_ACF_FLAG_PTR(ob->adt->flag) + return GET_ACF_FLAG_PTR(ob->adt->flag, type); else return NULL; @@ -835,7 +832,7 @@ static void *acf_group_setting_ptr(bAnimListElem *ale, int UNUSED(setting), shor bActionGroup *agrp= (bActionGroup *)ale->data; /* all flags are just in agrp->flag for now... */ - GET_ACF_FLAG_PTR(agrp->flag); + return GET_ACF_FLAG_PTR(agrp->flag, type); } /* group type define */ @@ -922,7 +919,7 @@ static void *acf_fcurve_setting_ptr(bAnimListElem *ale, int UNUSED(setting), sho FCurve *fcu= (FCurve *)ale->data; /* all flags are just in agrp->flag for now... */ - GET_ACF_FLAG_PTR(fcu->flag); + return GET_ACF_FLAG_PTR(fcu->flag, type); } /* fcurve type define */ @@ -997,13 +994,13 @@ static void *acf_fillactd_setting_ptr(bAnimListElem *ale, int setting, short *ty switch (setting) { case ACHANNEL_SETTING_SELECT: /* selected */ if (adt) { - GET_ACF_FLAG_PTR(adt->flag); + return GET_ACF_FLAG_PTR(adt->flag, type); } else return NULL; case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(act->flag); + return GET_ACF_FLAG_PTR(act->flag, type); default: /* unsupported */ return NULL; @@ -1082,7 +1079,7 @@ static void *acf_filldrivers_setting_ptr(bAnimListElem *ale, int setting, short switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(adt->flag); + return GET_ACF_FLAG_PTR(adt->flag, type); default: /* unsupported */ return NULL; @@ -1152,13 +1149,13 @@ static void *acf_dsmat_setting_ptr(bAnimListElem *ale, int setting, short *type) switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(ma->flag); + return GET_ACF_FLAG_PTR(ma->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (ma->adt) - GET_ACF_FLAG_PTR(ma->adt->flag) + return GET_ACF_FLAG_PTR(ma->adt->flag, type); else return NULL; @@ -1229,13 +1226,13 @@ static void *acf_dslam_setting_ptr(bAnimListElem *ale, int setting, short *type) switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(la->flag); + return GET_ACF_FLAG_PTR(la->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (la->adt) - GET_ACF_FLAG_PTR(la->adt->flag) + return GET_ACF_FLAG_PTR(la->adt->flag, type); else return NULL; @@ -1313,13 +1310,13 @@ static void *acf_dstex_setting_ptr(bAnimListElem *ale, int setting, short *type) switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(tex->flag); + return GET_ACF_FLAG_PTR(tex->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (tex->adt) - GET_ACF_FLAG_PTR(tex->adt->flag) + return GET_ACF_FLAG_PTR(tex->adt->flag, type); else return NULL; @@ -1390,13 +1387,13 @@ static void *acf_dscam_setting_ptr(bAnimListElem *ale, int setting, short *type) switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(ca->flag); + return GET_ACF_FLAG_PTR(ca->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (ca->adt) - GET_ACF_FLAG_PTR(ca->adt->flag) + return GET_ACF_FLAG_PTR(ca->adt->flag, type); else return NULL; @@ -1477,13 +1474,13 @@ static void *acf_dscur_setting_ptr(bAnimListElem *ale, int setting, short *type) switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(cu->flag); + return GET_ACF_FLAG_PTR(cu->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (cu->adt) - GET_ACF_FLAG_PTR(cu->adt->flag) + return GET_ACF_FLAG_PTR(cu->adt->flag, type); else return NULL; @@ -1554,13 +1551,13 @@ static void *acf_dsskey_setting_ptr(bAnimListElem *ale, int setting, short *type switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(key->flag); + return GET_ACF_FLAG_PTR(key->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (key->adt) - GET_ACF_FLAG_PTR(key->adt->flag) + return GET_ACF_FLAG_PTR(key->adt->flag, type); else return NULL; @@ -1631,13 +1628,13 @@ static void *acf_dswor_setting_ptr(bAnimListElem *ale, int setting, short *type) switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(wo->flag); + return GET_ACF_FLAG_PTR(wo->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (wo->adt) - GET_ACF_FLAG_PTR(wo->adt->flag) + return GET_ACF_FLAG_PTR(wo->adt->flag, type); else return NULL; @@ -1708,13 +1705,13 @@ static void *acf_dspart_setting_ptr(bAnimListElem *ale, int setting, short *type switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(part->flag); + return GET_ACF_FLAG_PTR(part->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (part->adt) - GET_ACF_FLAG_PTR(part->adt->flag) + return GET_ACF_FLAG_PTR(part->adt->flag, type); else return NULL; @@ -1785,13 +1782,13 @@ static void *acf_dsmball_setting_ptr(bAnimListElem *ale, int setting, short *typ switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(mb->flag); + return GET_ACF_FLAG_PTR(mb->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (mb->adt) - GET_ACF_FLAG_PTR(mb->adt->flag) + return GET_ACF_FLAG_PTR(mb->adt->flag, type); else return NULL; @@ -1862,13 +1859,13 @@ static void *acf_dsarm_setting_ptr(bAnimListElem *ale, int setting, short *type) switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(arm->flag); + return GET_ACF_FLAG_PTR(arm->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (arm->adt) - GET_ACF_FLAG_PTR(arm->adt->flag) + return GET_ACF_FLAG_PTR(arm->adt->flag, type); else return NULL; @@ -1950,13 +1947,13 @@ static void *acf_dsntree_setting_ptr(bAnimListElem *ale, int setting, short *typ switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(ntree->flag); + return GET_ACF_FLAG_PTR(ntree->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (ntree->adt) - GET_ACF_FLAG_PTR(ntree->adt->flag) + return GET_ACF_FLAG_PTR(ntree->adt->flag, type); else return NULL; @@ -2027,13 +2024,13 @@ static void *acf_dsmesh_setting_ptr(bAnimListElem *ale, int setting, short *type switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(me->flag); + return GET_ACF_FLAG_PTR(me->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (me->adt) - GET_ACF_FLAG_PTR(me->adt->flag) + return GET_ACF_FLAG_PTR(me->adt->flag, type); else return NULL; @@ -2104,13 +2101,13 @@ static void *acf_dslat_setting_ptr(bAnimListElem *ale, int setting, short *type) switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(lt->flag); + return GET_ACF_FLAG_PTR(lt->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (lt->adt) - GET_ACF_FLAG_PTR(lt->adt->flag) + return GET_ACF_FLAG_PTR(lt->adt->flag, type); else return NULL; @@ -2181,13 +2178,13 @@ static void *acf_dsspk_setting_ptr(bAnimListElem *ale, int setting, short *type) switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - GET_ACF_FLAG_PTR(spk->flag); + return GET_ACF_FLAG_PTR(spk->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ if (spk->adt) - GET_ACF_FLAG_PTR(spk->adt->flag) + return GET_ACF_FLAG_PTR(spk->adt->flag, type); else return NULL; @@ -2296,7 +2293,7 @@ static void *acf_shapekey_setting_ptr(bAnimListElem *ale, int setting, short *ty case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted */ case ACHANNEL_SETTING_PROTECT: /* protected */ - GET_ACF_FLAG_PTR(kb->flag) + return GET_ACF_FLAG_PTR(kb->flag, type); default: /* unsupported */ return NULL; @@ -2375,7 +2372,7 @@ static void *acf_gpd_setting_ptr(bAnimListElem *ale, int UNUSED(setting), short bGPdata *gpd= (bGPdata *)ale->data; /* all flags are just in gpd->flag for now... */ - GET_ACF_FLAG_PTR(gpd->flag); + return GET_ACF_FLAG_PTR(gpd->flag, type); } /* gpencil datablock type define */ @@ -2464,7 +2461,7 @@ static void *acf_gpl_setting_ptr(bAnimListElem *ale, int UNUSED(setting), short bGPDlayer *gpl= (bGPDlayer *)ale->data; /* all flags are just in agrp->flag for now... */ - GET_ACF_FLAG_PTR(gpl->flag); + return GET_ACF_FLAG_PTR(gpl->flag, type); } /* grease pencil layer type define */ From c21c58f44c16b3d503d81577c1943f1f4b47b675 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Mar 2012 19:09:01 +0000 Subject: [PATCH 013/310] style cleanup, also remove unused externs. --- .../blender/blenfont/intern/blf_translation.c | 2 +- source/blender/blenkernel/BKE_cloth.h | 30 +++++------ source/blender/blenkernel/BKE_collision.h | 6 +-- source/blender/blenkernel/BKE_curve.h | 54 +++++++++---------- .../blender/blenkernel/intern/DerivedMesh.c | 2 - source/blender/blenkernel/intern/bvhutils.c | 2 +- .../blender/blenkernel/intern/cdderivedmesh.c | 8 +-- source/blender/blenkernel/intern/collision.c | 2 +- source/blender/blenkernel/intern/displist.c | 2 - source/blender/blenkernel/intern/mball.c | 6 +-- .../blenkernel/intern/particle_system.c | 2 +- source/blender/blenkernel/intern/property.c | 2 +- source/blender/blenkernel/intern/sequencer.c | 2 +- source/blender/blenkernel/intern/softbody.c | 4 +- source/blender/blenkernel/intern/text.c | 10 ++-- source/blender/blenlib/intern/BLI_kdopbvh.c | 4 +- source/blender/blenlib/intern/path_util.c | 21 ++++---- source/blender/blenloader/intern/readfile.c | 5 +- source/blender/bmesh/operators/bmo_extrude.c | 6 +-- .../bmesh/operators/bmo_join_triangles.c | 12 +++-- .../editors/animation/keyframes_edit.c | 1 - .../editors/interface/interface_draw.c | 2 +- .../editors/interface/interface_handlers.c | 2 +- source/blender/editors/screen/screen_edit.c | 4 +- source/blender/gpu/GPU_buffers.h | 20 +++---- source/blender/imbuf/intern/thumbs.c | 2 +- .../blender/makesrna/intern/rna_object_api.c | 12 ++--- .../modifiers/intern/MOD_fluidsim_util.c | 12 ++--- source/blender/render/intern/include/sunsky.h | 2 +- .../render/intern/raytrace/reorganize.h | 5 +- source/blender/render/intern/raytrace/vbvh.h | 4 +- .../blender/render/intern/source/rayshade.c | 2 +- source/blender/render/intern/source/sss.c | 2 - .../GameLogic/Joystick/SCA_Joystick.h | 4 +- source/gameengine/Ketsji/KX_GameObject.h | 4 +- 35 files changed, 129 insertions(+), 131 deletions(-) diff --git a/source/blender/blenfont/intern/blf_translation.c b/source/blender/blenfont/intern/blf_translation.c index 0ddb6549717..201722acdbf 100644 --- a/source/blender/blenfont/intern/blf_translation.c +++ b/source/blender/blenfont/intern/blf_translation.c @@ -94,7 +94,7 @@ const char* BLF_gettext(const char *msgid) { #ifdef WITH_INTERNATIONAL if( msgid[0] ) - return gettext( msgid ); + return gettext(msgid); return ""; #else return msgid; diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index 98e273f59b2..435832f8c87 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -198,32 +198,32 @@ int cloth_bvh_objcollision (struct Object *ob, struct ClothModifierData * clmd, //////////////////////////////////////////////// // needed for cloth.c -int implicit_init ( struct Object *ob, struct ClothModifierData *clmd ); -int implicit_free ( struct ClothModifierData *clmd ); -int implicit_solver ( struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors ); -void implicit_set_positions ( struct ClothModifierData *clmd ); +int implicit_init (struct Object *ob, struct ClothModifierData *clmd ); +int implicit_free (struct ClothModifierData *clmd ); +int implicit_solver (struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors ); +void implicit_set_positions (struct ClothModifierData *clmd ); ///////////////////////////////////////////////// // cloth.c //////////////////////////////////////////////// // needed for modifier.c -void cloth_free_modifier_extern ( struct ClothModifierData *clmd ); -void cloth_free_modifier ( struct ClothModifierData *clmd ); -void cloth_init ( struct ClothModifierData *clmd ); -void clothModifier_do ( struct ClothModifierData *clmd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3]); +void cloth_free_modifier_extern (struct ClothModifierData *clmd ); +void cloth_free_modifier (struct ClothModifierData *clmd ); +void cloth_init (struct ClothModifierData *clmd ); +void clothModifier_do (struct ClothModifierData *clmd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3]); int cloth_uses_vgroup(struct ClothModifierData *clmd); // needed for collision.c -void bvhtree_update_from_cloth ( struct ClothModifierData *clmd, int moving ); -void bvhselftree_update_from_cloth ( struct ClothModifierData *clmd, int moving ); +void bvhtree_update_from_cloth (struct ClothModifierData *clmd, int moving ); +void bvhselftree_update_from_cloth (struct ClothModifierData *clmd, int moving ); // needed for button_object.c -void cloth_clear_cache ( struct Object *ob, struct ClothModifierData *clmd, float framenr ); +void cloth_clear_cache (struct Object *ob, struct ClothModifierData *clmd, float framenr ); // needed for cloth.c -int cloth_add_spring ( struct ClothModifierData *clmd, unsigned int indexA, unsigned int indexB, float restlength, int spring_type); +int cloth_add_spring (struct ClothModifierData *clmd, unsigned int indexA, unsigned int indexB, float restlength, int spring_type); //////////////////////////////////////////////// @@ -242,9 +242,9 @@ typedef struct { const char *name; CM_SOLVER_ID id; - int ( *init ) ( struct Object *ob, struct ClothModifierData *clmd ); - int ( *solver ) ( struct Object *ob, float framenr, struct ClothModifierData *clmd, struct ListBase *effectors ); - int ( *free ) ( struct ClothModifierData *clmd ); + int ( *init ) (struct Object *ob, struct ClothModifierData *clmd ); + int ( *solver ) (struct Object *ob, float framenr, struct ClothModifierData *clmd, struct ListBase *effectors ); + int ( *free ) (struct ClothModifierData *clmd ); } CM_SOLVER_DEF; diff --git a/source/blender/blenkernel/BKE_collision.h b/source/blender/blenkernel/BKE_collision.h index 75fdc4981a0..d20417d5604 100644 --- a/source/blender/blenkernel/BKE_collision.h +++ b/source/blender/blenkernel/BKE_collision.h @@ -130,14 +130,14 @@ FaceCollPair; // used in modifier.c from collision.c ///////////////////////////////////////////////// -BVHTree *bvhtree_build_from_mvert ( struct MFace *mfaces, unsigned int numfaces, struct MVert *x, unsigned int numverts, float epsilon ); -void bvhtree_update_from_mvert ( BVHTree * bvhtree, struct MFace *faces, int numfaces, struct MVert *x, struct MVert *xnew, int numverts, int moving ); +BVHTree *bvhtree_build_from_mvert(struct MFace *mfaces, unsigned int numfaces, struct MVert *x, unsigned int numverts, float epsilon ); +void bvhtree_update_from_mvert(BVHTree * bvhtree, struct MFace *faces, int numfaces, struct MVert *x, struct MVert *xnew, int numverts, int moving ); ///////////////////////////////////////////////// // move Collision modifier object inter-frame with step = [0,1] // defined in collisions.c -void collision_move_object ( struct CollisionModifierData *collmd, float step, float prevstep ); +void collision_move_object(struct CollisionModifierData *collmd, float step, float prevstep); ///////////////////////////////////////////////// // used in effect.c diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index dd0c021f281..fa3a1a6897a 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -54,27 +54,27 @@ struct Scene; #define CU_DO_RADIUS(cu, nu) ((CU_DO_TILT(cu, nu) || ((cu)->flag & CU_PATH_RADIUS) || (cu)->bevobj || (cu)->ext1!=0.0f || (cu)->ext2!=0.0f) ? 1:0) -void unlink_curve( struct Curve *cu); +void unlink_curve(struct Curve *cu); void free_curve_editNurb_keyIndex(struct EditNurb *editnurb); void free_curve_editNurb(struct Curve *cu); -void free_curve( struct Curve *cu); +void free_curve(struct Curve *cu); void BKE_free_editfont(struct Curve *cu); struct Curve *add_curve(const char *name, int type); -struct Curve *copy_curve( struct Curve *cu); -void make_local_curve( struct Curve *cu); +struct Curve *copy_curve(struct Curve *cu); +void make_local_curve(struct Curve *cu); struct ListBase *curve_editnurbs(struct Curve *cu); -short curve_type( struct Curve *cu); -void test_curve_type( struct Object *ob); -void update_curve_dimension( struct Curve *cu ); -void tex_space_curve( struct Curve *cu); -int count_curveverts( struct ListBase *nurb); -int count_curveverts_without_handles( struct ListBase *nurb); -void freeNurb( struct Nurb *nu); -void freeNurblist( struct ListBase *lb); -struct Nurb *duplicateNurb( struct Nurb *nu); -void duplicateNurblist( struct ListBase *lb1, struct ListBase *lb2); -void test2DNurb( struct Nurb *nu); -void minmaxNurb( struct Nurb *nu, float *min, float *max); +short curve_type(struct Curve *cu); +void test_curve_type(struct Object *ob); +void update_curve_dimension(struct Curve *cu ); +void tex_space_curve(struct Curve *cu); +int count_curveverts(struct ListBase *nurb); +int count_curveverts_without_handles(struct ListBase *nurb); +void freeNurb(struct Nurb *nu); +void freeNurblist(struct ListBase *lb); +struct Nurb *duplicateNurb(struct Nurb *nu); +void duplicateNurblist(struct ListBase *lb1, struct ListBase *lb2); +void test2DNurb(struct Nurb *nu); +void minmaxNurb(struct Nurb *nu, float *min, float *max); void nurbs_knot_calc_u(struct Nurb *nu); void nurbs_knot_calc_v(struct Nurb *nu); @@ -83,19 +83,19 @@ void makeNurbfaces(struct Nurb *nu, float *coord_array, int rowstride, int resol void makeNurbcurve(struct Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, float *weight_array, int resolu, int stride); void forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride); float *make_orco_curve(struct Scene *scene, struct Object *ob); -float *make_orco_surf( struct Object *ob); +float *make_orco_surf(struct Object *ob); void makebevelcurve(struct Scene *scene, struct Object *ob, struct ListBase *disp, int forRender); -void makeBevelList( struct Object *ob); +void makeBevelList(struct Object *ob); -void calchandleNurb( struct BezTriple *bezt, struct BezTriple *prev, struct BezTriple *next, int mode); -void calchandlesNurb( struct Nurb *nu); -void testhandlesNurb( struct Nurb *nu); -void autocalchandlesNurb( struct Nurb *nu, int flag); +void calchandleNurb(struct BezTriple *bezt, struct BezTriple *prev, struct BezTriple *next, int mode); +void calchandlesNurb(struct Nurb *nu); +void testhandlesNurb(struct Nurb *nu); +void autocalchandlesNurb(struct Nurb *nu, int flag); void autocalchandlesNurb_all(ListBase *editnurb, int flag); void sethandlesNurb(ListBase *editnurb, short code); -void switchdirectionNurb( struct Nurb *nu); +void switchdirectionNurb(struct Nurb *nu); void addNurbPoints(struct Nurb *nu, int number); void addNurbPointsBezier(struct Nurb *nu, int number); @@ -107,11 +107,11 @@ float (*curve_getKeyVertexCos(struct Curve *cu, struct ListBase *lb, float *key) void curve_applyKeyVertexTilts(struct Curve *cu, struct ListBase *lb, float *key); /* nurb checks if they can be drawn, also clamp order func */ -int check_valid_nurb_u( struct Nurb *nu); -int check_valid_nurb_v( struct Nurb *nu); +int check_valid_nurb_u(struct Nurb *nu); +int check_valid_nurb_v(struct Nurb *nu); -int clamp_nurb_order_u( struct Nurb *nu); -int clamp_nurb_order_v( struct Nurb *nu); +int clamp_nurb_order_u(struct Nurb *nu); +int clamp_nurb_order_v(struct Nurb *nu); ListBase *BKE_curve_nurbs(struct Curve *cu); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 4c683b2b2c8..235bc695b66 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -80,8 +80,6 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm); #include "GPU_extensions.h" #include "GPU_material.h" -extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */ - static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *ob); static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid); diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index 4cade876d09..bbe210f2ce6 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -754,7 +754,7 @@ void bvhcache_insert(BVHCache *cache, BVHTree *tree, int type) item->type = type; item->tree = tree; - BLI_linklist_prepend( cache, item ); + BLI_linklist_prepend(cache, item); } diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index cf435e96332..cc3705780e4 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -441,14 +441,14 @@ static void cdDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges } if( prevdraw != draw ) { if( prevdraw > 0 && (i-prevstart) > 0 ) { - GPU_buffer_draw_elements( dm->drawObject->edges, GL_LINES, prevstart*2, (i-prevstart)*2 ); + GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i - prevstart) * 2); } prevstart = i; } prevdraw = draw; } if( prevdraw > 0 && (i-prevstart) > 0 ) { - GPU_buffer_draw_elements( dm->drawObject->edges, GL_LINES, prevstart*2, (i-prevstart)*2 ); + GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i-prevstart) * 2); } } GPU_buffer_unbind(); @@ -489,14 +489,14 @@ static void cdDM_drawLooseEdges(DerivedMesh *dm) } if( prevdraw != draw ) { if( prevdraw > 0 && (i-prevstart) > 0) { - GPU_buffer_draw_elements( dm->drawObject->edges, GL_LINES, prevstart*2, (i-prevstart)*2 ); + GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i - prevstart) * 2); } prevstart = i; } prevdraw = draw; } if( prevdraw > 0 && (i-prevstart) > 0 ) { - GPU_buffer_draw_elements( dm->drawObject->edges, GL_LINES, prevstart*2, (i-prevstart)*2 ); + GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i - prevstart) * 2); } } GPU_buffer_unbind(); diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index f19226cedf0..7d850c3576e 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -75,7 +75,7 @@ Collision modifier code start ***********************************/ /* step is limited from 0 (frame start position) to 1 (frame end position) */ -void collision_move_object ( CollisionModifierData *collmd, float step, float prevstep ) +void collision_move_object(CollisionModifierData *collmd, float step, float prevstep) { float tv[3] = {0, 0, 0}; unsigned int i = 0; diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index d10c060cc7f..21f897d16ff 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -62,8 +62,6 @@ #include "BLO_sys_types.h" // for intptr_t support -extern Material defmaterial; /* material.c */ - static void boundbox_displist(Object *ob); void free_disp_elem(DispList *dl) diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index f3225a6b6f5..22f8d38de4a 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -696,12 +696,12 @@ float metaball(float x, float y, float z) } else{ for(a=0; atotpart = activeParts; BLI_snprintf(debugStrBuffer,sizeof(debugStrBuffer),"readFsPartData::done - particles:%d, active:%d, file:%d, mask:%d \n", psys->totpart,activeParts,fileParts,readMask); diff --git a/source/blender/blenkernel/intern/property.c b/source/blender/blenkernel/intern/property.c index baf682b4cb6..9daee575080 100644 --- a/source/blender/blenkernel/intern/property.c +++ b/source/blender/blenkernel/intern/property.c @@ -79,7 +79,7 @@ bProperty *copy_property(bProperty *prop) void copy_properties(ListBase *lbn, ListBase *lbo) { bProperty *prop, *propn; - free_properties( lbn ); /* in case we are copying to an object with props */ + free_properties(lbn); /* in case we are copying to an object with props */ prop= lbo->first; while(prop) { propn= copy_property(prop); diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 8f8874d3a3c..b57e2f3dab9 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -3755,7 +3755,7 @@ Sequence *sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo /* basic defaults */ seq->strip= strip= MEM_callocN(sizeof(Strip), "strip"); - strip->len = seq->len = IMB_anim_get_duration( an, IMB_TC_RECORD_RUN ); + strip->len = seq->len = IMB_anim_get_duration(an, IMB_TC_RECORD_RUN); strip->us= 1; /* we only need 1 element for MOVIE strips */ diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index b0075f5c121..33da4443b6f 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -3610,13 +3610,13 @@ static void curve_surf_to_softbody(Scene *scene, Object *ob) bs->v1= curindex; bs->v2= curindex+1; bs->springtype=SB_HANDLE; - bs->len= globallen( bezt->vec[0], bezt->vec[1], ob ); + bs->len= globallen(bezt->vec[0], bezt->vec[1], ob); bs++; bs->v1= curindex+1; bs->v2= curindex+2; bs->springtype=SB_HANDLE; - bs->len= globallen( bezt->vec[1], bezt->vec[2], ob ); + bs->len= globallen(bezt->vec[1], bezt->vec[2], ob); bs++; } } diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 3f382cc5543..141d390d571 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -600,7 +600,7 @@ void clear_text(Text *text) /* called directly from rna */ txt_set_undostate( 1 ); txt_sel_all( text ); txt_delete_sel(text); - txt_set_undostate( oldstate ); + txt_set_undostate(oldstate); txt_make_dirty(text); } @@ -609,10 +609,10 @@ void write_text(Text *text, const char *str) /* called directly from rna */ { int oldstate; - oldstate = txt_get_undostate( ); - txt_insert_buf( text, str ); - txt_move_eof( text, 0 ); - txt_set_undostate( oldstate ); + oldstate = txt_get_undostate(); + txt_insert_buf(text, str); + txt_move_eof(text, 0); + txt_set_undostate(oldstate); txt_make_dirty(text); } diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index b992d518b49..67e0ea6ebb9 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -1687,7 +1687,7 @@ static void dfs_range_query(RangeQueryData *data, BVHNode *node) if(node->children[i]->totnode == 0) { data->hits++; - data->callback( data->userdata, node->children[i]->index, dist ); + data->callback(data->userdata, node->children[i]->index, dist); } else dfs_range_query( data, node->children[i] ); @@ -1719,7 +1719,7 @@ int BLI_bvhtree_range_query(BVHTree *tree, const float co[3], float radius, BVHT if(root->totnode == 0) { data.hits++; - data.callback( data.userdata, root->index, dist ); + data.callback(data.userdata, root->index, dist); } else dfs_range_query( &data, root ); diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index a512ac746f9..0d251133e0d 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -331,7 +331,7 @@ void BLI_cleanup_path(const char *relabase, char *dir) } /* Note - * memmove( start, eind, strlen(eind)+1 ); + * memmove(start, eind, strlen(eind) + 1); * is the same as * strcpy( start, eind ); * except strcpy should not be used because there is overlap, @@ -357,18 +357,18 @@ void BLI_cleanup_path(const char *relabase, char *dir) if (a<0) { break; } else { - memmove( dir+a, eind, strlen(eind)+1 ); + memmove(dir + a, eind, strlen(eind) + 1); } } while ( (start = strstr(dir,"\\.\\")) ) { eind = start + strlen("\\.\\") - 1; - memmove( start, eind, strlen(eind)+1 ); + memmove(start, eind, strlen(eind) + 1); } while ( (start = strstr(dir,"\\\\" )) ) { eind = start + strlen("\\\\") - 1; - memmove( start, eind, strlen(eind)+1 ); + memmove(start, eind, strlen(eind) + 1); } #else if(dir[0]=='.') { /* happens, for example in FILE_MAIN */ @@ -381,7 +381,7 @@ void BLI_cleanup_path(const char *relabase, char *dir) * this is a valid path in blender but we cant handle this the usual way below * simply strip this prefix then evaluate the path as usual. pythons os.path.normpath() does this */ while((strncmp(dir, "/../", 4)==0)) { - memmove( dir, dir + 4, strlen(dir + 4) + 1 ); + memmove(dir, dir + 4, strlen(dir + 4) + 1); } while ( (start = strstr(dir, "/../")) ) { @@ -393,19 +393,20 @@ void BLI_cleanup_path(const char *relabase, char *dir) } if (a<0) { break; - } else { - memmove( dir+a, eind, strlen(eind)+1 ); + } + else { + memmove(dir+a, eind, strlen(eind) + 1); } } while ( (start = strstr(dir,"/./")) ) { eind = start + (3 - 1) /* strlen("/./") - 1 */; - memmove( start, eind, strlen(eind)+1 ); + memmove(start, eind, strlen(eind) + 1); } while ( (start = strstr(dir,"//" )) ) { eind = start + (2 - 1) /* strlen("//") - 1 */; - memmove( start, eind, strlen(eind)+1 ); + memmove(start, eind, strlen(eind) + 1); } #endif } @@ -1479,7 +1480,7 @@ void BLI_split_dirfile(const char *string, char *dir, char *file, const size_t d if (dir) { if (lslash) { - BLI_strncpy( dir, string, MIN2(dirlen, lslash + 1)); /* +1 to include the slash and the last char */ + BLI_strncpy(dir, string, MIN2(dirlen, lslash + 1)); /* +1 to include the slash and the last char */ } else { dir[0] = '\0'; diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 517ba303a1a..50b8e0997ee 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -10574,8 +10574,9 @@ static void do_versions(FileData *fd, Library *lib, Main *main) bMessageActuator *msgAct = (bMessageActuator *) act->data; if (BLI_strnlen(msgAct->toPropName, 3) > 2) { /* strip first 2 chars, would have only worked if these were OB anyway */ - memmove( msgAct->toPropName, msgAct->toPropName+2, sizeof(msgAct->toPropName)-2 ); - } else { + memmove(msgAct->toPropName, msgAct->toPropName + 2, sizeof(msgAct->toPropName) - 2); + } + else { msgAct->toPropName[0] = '\0'; } } diff --git a/source/blender/bmesh/operators/bmo_extrude.c b/source/blender/bmesh/operators/bmo_extrude.c index 595502586b9..8e5792b6a15 100644 --- a/source/blender/bmesh/operators/bmo_extrude.c +++ b/source/blender/bmesh/operators/bmo_extrude.c @@ -201,7 +201,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) BMO_slot_buffer_flag_enable(bm, op, "edgefacein", EXT_INPUT, BM_EDGE|BM_FACE); - /* if one flagged face is bordered by an unflagged face, then we delete + /* if one flagged face is bordered by an un-flagged face, then we delete * original geometry unless caller explicitly asked to keep it. */ if (!BMO_slot_bool_get(op, "alwayskeeporig")) { BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) { @@ -226,13 +226,13 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) } if ((edge_face_tot > 1) && (found == FALSE)) { - /* edge has a face user, that face isnt extrude input */ + /* edge has a face user, that face isn't extrude input */ BMO_elem_flag_enable(bm, e, EXT_DEL); } } } - /* calculate verts to delet */ + /* calculate verts to delete */ BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { found = FALSE; diff --git a/source/blender/bmesh/operators/bmo_join_triangles.c b/source/blender/bmesh/operators/bmo_join_triangles.c index 1d8b77e9300..dda3e144220 100644 --- a/source/blender/bmesh/operators/bmo_join_triangles.c +++ b/source/blender/bmesh/operators/bmo_join_triangles.c @@ -50,13 +50,13 @@ static float measure_facepair(BMesh *UNUSED(bm), BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4, float limit) { - /* gives a 'weight' to a pair of triangles that join an edge to decide how good a join they would mak */ + /* gives a 'weight' to a pair of triangles that join an edge to decide how good a join they would make */ /* Note: this is more complicated than it needs to be and should be cleaned up.. */ float n1[3], n2[3], measure = 0.0f, angle1, angle2, diff; float edgeVec1[3], edgeVec2[3], edgeVec3[3], edgeVec4[3]; float minarea, maxarea, areaA, areaB; - /* First Test: Normal differenc */ + /* First Test: Normal difference */ normal_tri_v3(n1, v1->co, v2->co, v3->co); normal_tri_v3(n2, v1->co, v3->co, v4->co); @@ -74,7 +74,7 @@ static float measure_facepair(BMesh *UNUSED(bm), BMVert *v1, BMVert *v2, return measure; } - /* Second test: Colinearit */ + /* Second test: Colinearity */ sub_v3_v3v3(edgeVec1, v1->co, v2->co); sub_v3_v3v3(edgeVec2, v2->co, v3->co); sub_v3_v3v3(edgeVec3, v3->co, v4->co); @@ -95,7 +95,7 @@ static float measure_facepair(BMesh *UNUSED(bm), BMVert *v1, BMVert *v2, return measure; } - /* Third test: Concavit */ + /* Third test: Concavity */ areaA = area_tri_v3(v1->co, v2->co, v3->co) + area_tri_v3(v1->co, v3->co, v4->co); areaB = area_tri_v3(v2->co, v3->co, v4->co) + area_tri_v3(v4->co, v1->co, v2->co); @@ -176,7 +176,9 @@ static int compareFaceAttribs(BMesh *bm, BMEdge *e, int douvs, int dovcols) /* do UV */ if (luv1 && douvs) { - if (tp1->tpage != tp2->tpage); /* do nothin */ + if (tp1->tpage != tp2->tpage) { + /* do nothing */ + } else { int i; diff --git a/source/blender/editors/animation/keyframes_edit.c b/source/blender/editors/animation/keyframes_edit.c index f140c408e68..c6aed3133e2 100644 --- a/source/blender/editors/animation/keyframes_edit.c +++ b/source/blender/editors/animation/keyframes_edit.c @@ -751,7 +751,6 @@ KeyframeEditFunc ANIM_editkeyframes_mirror(short type) return mirror_bezier_value; default: /* just in case */ return mirror_bezier_yaxis; - break; } } diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 01700e1c52a..cfd9f65cf00 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -1088,7 +1088,7 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect) for( a = 1; a <= sizex; a++ ) { pos = ((float)a) / (sizex-1); - do_colorband( coba, pos, colf ); + do_colorband(coba, pos, colf); if (but->block->color_profile != BLI_PR_NONE) linearrgb_to_srgb_v3_v3(colf, colf); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index cae6f61d269..537de167153 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1229,7 +1229,7 @@ static int ui_textedit_delete_selection(uiBut *but, uiHandleButtonData *data) int len= strlen(str); int change= 0; if(but->selsta != but->selend && len) { - memmove( str+but->selsta, str+but->selend, (len - but->selend) + 1 ); + memmove(str + but->selsta, str + but->selend, (len - but->selend) + 1); change= 1; } diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index 6288f39367e..4ed6e08fb31 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -1845,8 +1845,8 @@ void ED_update_for_newframe(Main *bmain, Scene *scene, bScreen *screen, int UNUS { Tex *tex; for(tex= bmain->tex.first; tex; tex= tex->id.next) - if( tex->use_nodes && tex->nodetree ) { - ntreeTexTagAnimated( tex->nodetree ); + if (tex->use_nodes && tex->nodetree) { + ntreeTexTagAnimated(tex->nodetree); } } diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h index 09314351078..33055b5efd5 100644 --- a/source/blender/gpu/GPU_buffers.h +++ b/source/blender/gpu/GPU_buffers.h @@ -123,16 +123,16 @@ void GPU_global_buffer_pool_free(void); GPUBuffer *GPU_buffer_alloc(int size); void GPU_buffer_free(GPUBuffer *buffer); -GPUDrawObject *GPU_drawobject_new( struct DerivedMesh *dm ); -void GPU_drawobject_free( struct DerivedMesh *dm ); +GPUDrawObject *GPU_drawobject_new(struct DerivedMesh *dm ); +void GPU_drawobject_free(struct DerivedMesh *dm ); /* called before drawing */ -void GPU_vertex_setup( struct DerivedMesh *dm ); -void GPU_normal_setup( struct DerivedMesh *dm ); -void GPU_uv_setup( struct DerivedMesh *dm ); -void GPU_color_setup( struct DerivedMesh *dm ); -void GPU_edge_setup( struct DerivedMesh *dm ); /* does not mix with other data */ -void GPU_uvedge_setup( struct DerivedMesh *dm ); +void GPU_vertex_setup(struct DerivedMesh *dm ); +void GPU_normal_setup(struct DerivedMesh *dm ); +void GPU_uv_setup(struct DerivedMesh *dm ); +void GPU_color_setup(struct DerivedMesh *dm ); +void GPU_edge_setup(struct DerivedMesh *dm ); /* does not mix with other data */ +void GPU_uvedge_setup(struct DerivedMesh *dm ); int GPU_attrib_element_size( GPUAttrib data[], int numdata ); void GPU_interleaved_attrib_setup( GPUBuffer *buffer, GPUAttrib data[], int numdata ); @@ -142,7 +142,7 @@ void *GPU_buffer_lock_stream( GPUBuffer *buffer ); void GPU_buffer_unlock( GPUBuffer *buffer ); /* upload three unsigned chars, representing RGB colors, for each vertex. Resets dm->drawObject->colType to -1 */ -void GPU_color3_upload( struct DerivedMesh *dm, unsigned char *data ); +void GPU_color3_upload(struct DerivedMesh *dm, unsigned char *data ); /* switch color rendering on=1/off=0 */ void GPU_color_switch( int mode ); @@ -153,7 +153,7 @@ void GPU_buffer_draw_elements( GPUBuffer *elements, unsigned int mode, int start void GPU_buffer_unbind(void); /* used to check whether to use the old (without buffers) code */ -int GPU_buffer_legacy( struct DerivedMesh *dm ); +int GPU_buffer_legacy(struct DerivedMesh *dm ); /* Buffers for non-DerivedMesh drawing */ typedef struct GPU_Buffers GPU_Buffers; diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index f863fe8de21..fdc9e50bcd8 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -167,7 +167,7 @@ static void to_hex_char(char* hexbytes, const unsigned char* bytes, int len) /** ----- end of adapted code from glib --- */ -static int uri_from_filename( const char *path, char *uri ) +static int uri_from_filename(const char *path, char *uri) { char orig_uri[URI_MAX]; const char* dirstart = path; diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index ed806c96beb..08c8f69d076 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -160,17 +160,17 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_ DerivedMesh *dm; /* CustomDataMask mask = CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL; */ CustomDataMask mask = CD_MASK_MESH; /* this seems more suitable, exporter, - for example, needs CD_MASK_MDEFORMVERT */ + * for example, needs CD_MASK_MDEFORMVERT */ /* Write the display mesh into the dummy mesh */ if (render) - dm = mesh_create_derived_render( sce, ob, mask ); + dm = mesh_create_derived_render(sce, ob, mask); else - dm = mesh_create_derived_view( sce, ob, mask ); + dm = mesh_create_derived_view(sce, ob, mask); - tmpmesh = add_mesh( "Mesh" ); - DM_to_mesh( dm, tmpmesh, ob ); - dm->release( dm ); + tmpmesh = add_mesh("Mesh"); + DM_to_mesh(dm, tmpmesh, ob); + dm->release(dm); } break; diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index 42a6f74aba5..31a50a6a16b 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -210,7 +210,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam gotBytes = gzread(gzf, &wri, sizeof(wri)); numfaces = wri; - gzclose( gzf ); + gzclose(gzf); // ------------------------------------------------ if(!numfaces || !numverts || !gotBytes) @@ -226,7 +226,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam if(!dm) { - gzclose( gzf ); + gzclose(gzf); return NULL; } @@ -245,7 +245,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam { if(dm) dm->release(dm); - gzclose( gzf ); + gzclose(gzf); return NULL; } @@ -254,7 +254,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam { if(dm) dm->release(dm); - gzclose( gzf ); + gzclose(gzf); return NULL; } @@ -272,7 +272,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam printf("Fluidsim: error in reading data from file.\n"); if(dm) dm->release(dm); - gzclose( gzf ); + gzclose(gzf); MEM_freeN(normals); return NULL; } @@ -299,7 +299,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam } - gzclose( gzf ); + gzclose(gzf); CDDM_calc_edges(dm); diff --git a/source/blender/render/intern/include/sunsky.h b/source/blender/render/intern/include/sunsky.h index 62b68484629..6a41517b113 100644 --- a/source/blender/render/intern/include/sunsky.h +++ b/source/blender/render/intern/include/sunsky.h @@ -79,7 +79,7 @@ void InitSunSky(struct SunSky *sunsky, float turb, float *toSun, float horizon_b void GetSkyXYZRadiance(struct SunSky *sunsky, float theta, float phi, float color_out[3]); void GetSkyXYZRadiancef(struct SunSky *sunsky, const float varg[3], float color_out[3]); void InitAtmosphere(struct SunSky *sunSky, float sun_intens, float mief, float rayf, float inscattf, float extincf, float disf); -void AtmospherePixleShader( struct SunSky *sunSky, float view[3], float s, float rgb[3]); +void AtmospherePixleShader(struct SunSky *sunSky, float view[3], float s, float rgb[3]); void ClipColor(float c[3]); #endif /*__SUNSKY_H__*/ diff --git a/source/blender/render/intern/raytrace/reorganize.h b/source/blender/render/intern/raytrace/reorganize.h index 6efe37b81a3..11d12dac23c 100644 --- a/source/blender/render/intern/raytrace/reorganize.h +++ b/source/blender/render/intern/raytrace/reorganize.h @@ -271,8 +271,9 @@ void pushdown(Node *parent) s_child = next_s_child; } - for(Node *i = parent->child; RE_rayobject_isAligned(i) && i; i = i->sibling) - pushdown( i ); + for (Node *i = parent->child; RE_rayobject_isAligned(i) && i; i = i->sibling) { + pushdown(i); + } } diff --git a/source/blender/render/intern/raytrace/vbvh.h b/source/blender/render/intern/raytrace/vbvh.h index 7d4d25c8d00..e1b4ec420ef 100644 --- a/source/blender/render/intern/raytrace/vbvh.h +++ b/source/blender/render/intern/raytrace/vbvh.h @@ -167,8 +167,8 @@ struct BuildBinaryVBVH { Node *node = create_node(); INIT_MINMAX(node->bb, node->bb+3); - rtbuild_merge_bb(builder, node->bb, node->bb+3); - node->child = (Node*) rtbuild_get_primitive( builder, 0 ); + rtbuild_merge_bb(builder, node->bb, node->bb+3); + node->child = (Node *) rtbuild_get_primitive(builder, 0); return node; } else diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index 9272dcf5b30..c072a664fff 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -134,7 +134,7 @@ static RayObject* RE_rayobject_create(Render *re, int type, int size) if(res) - RE_rayobject_config_control( res, re ); + RE_rayobject_config_control(res, re); return res; } diff --git a/source/blender/render/intern/source/sss.c b/source/blender/render/intern/source/sss.c index a60db8a963f..6e37c81b882 100644 --- a/source/blender/render/intern/source/sss.c +++ b/source/blender/render/intern/source/sss.c @@ -77,8 +77,6 @@ #include "sss.h" #include "zbuf.h" -extern Render R; // meh - /* Generic Multiple Scattering API */ /* Relevant papers: diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h index a992150fad3..a6809716e32 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h +++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h @@ -134,8 +134,8 @@ class SCA_Joystick public: - static SCA_Joystick *GetInstance( short int joyindex ); - static void HandleEvents( void ); + static SCA_Joystick *GetInstance(short int joyindex); + static void HandleEvents(void); void ReleaseInstance(); diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 69e7a7cf5a6..cf3aae2bc90 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -518,7 +518,7 @@ public: return m_pBlenderObject; } - void SetBlenderObject( struct Object* obj) + void SetBlenderObject(struct Object* obj) { m_pBlenderObject = obj; } @@ -528,7 +528,7 @@ public: return m_pBlenderGroupObject; } - void SetBlenderGroupObject( struct Object* obj) + void SetBlenderGroupObject(struct Object* obj) { m_pBlenderGroupObject = obj; } From 42b3463030b07ba3a87574c173e759e3bb15353b Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sun, 11 Mar 2012 19:52:25 +0000 Subject: [PATCH 014/310] Bundle new upstream version of libmv from own branch This version of libmv includes new gflags and glog libraries which makes it possible to compile libmv with clang compiler. Also remove code from CMakeLists which was disabling libmv if using clang. Tested on linux with gcc-4.6 and clang-3.0, windows cmake+msvc and scons+mingw. Could be some issues with other platforms/build system which shall be simple to resolve. --- CMakeLists.txt | 8 - extern/libmv/CMakeLists.txt | 6 +- extern/libmv/ChangeLog | 75 +++- extern/libmv/files.txt | 10 +- extern/libmv/libmv-capi.cpp | 1 + extern/libmv/libmv/logging/logging.h | 2 +- .../libmv/libmv/simple_pipeline/pipeline.cc | 19 + extern/libmv/patches/bundle_tweaks.patch | 152 ------- extern/libmv/patches/clang-3.diff | 49 --- extern/libmv/patches/series | 2 - extern/libmv/third_party/gflags/AUTHORS | 2 + extern/libmv/third_party/gflags/COPYING | 28 ++ extern/libmv/third_party/gflags/ChangeLog | 195 +++++++++ extern/libmv/third_party/gflags/NEWS | 158 ++++++++ extern/libmv/third_party/gflags/README.libmv | 2 +- extern/libmv/third_party/gflags/config.h | 19 +- extern/libmv/third_party/gflags/gflags.cc | 291 +++++++------- .../third_party/gflags/{ => gflags}/gflags.h | 255 ++++++------ .../gflags/{ => gflags}/gflags_completions.h | 23 +- .../gflags/gflags/gflags_declare.h | 112 ++++++ .../third_party/gflags/gflags_completions.cc | 109 ++--- .../third_party/gflags/gflags_reporting.cc | 81 ++-- extern/libmv/third_party/gflags/mutex.h | 13 +- extern/libmv/third_party/gflags/util.h | 339 ++++++++++++++++ extern/libmv/third_party/glog/ChangeLog | 10 + extern/libmv/third_party/glog/README.libmv | 50 +-- .../glog/src/base/commandlineflags.h | 4 +- .../third_party/glog/src/base/googleinit.h | 2 +- .../third_party/glog/src/config_freebsd.h | 11 +- .../libmv/third_party/glog/src/config_linux.h | 30 +- .../libmv/third_party/glog/src/config_mac.h | 12 +- extern/libmv/third_party/glog/src/demangle.cc | 378 +++++++++++------- .../third_party/glog/src/glog/log_severity.h | 10 +- .../libmv/third_party/glog/src/glog/logging.h | 96 +++-- .../third_party/glog/src/glog/raw_logging.h | 12 +- extern/libmv/third_party/glog/src/logging.cc | 83 ++-- .../libmv/third_party/glog/src/raw_logging.cc | 2 +- .../third_party/glog/src/signalhandler.cc | 10 +- .../glog/src/stacktrace_libunwind-inl.h | 2 +- .../glog/src/stacktrace_x86_64-inl.h | 4 - .../libmv/third_party/glog/src/symbolize.cc | 8 +- extern/libmv/third_party/glog/src/symbolize.h | 2 +- .../libmv/third_party/glog/src/utilities.cc | 27 +- extern/libmv/third_party/glog/src/utilities.h | 4 + .../libmv/third_party/glog/src/vlog_is_on.cc | 6 +- .../glog/src/windows/glog/log_severity.h | 10 +- .../glog/src/windows/glog/logging.h | 95 +++-- .../glog/src/windows/glog/raw_logging.h | 12 +- .../libmv/third_party/glog/src/windows/port.h | 18 +- .../glog/src/windows/preprocess.sh | 0 50 files changed, 1853 insertions(+), 996 deletions(-) delete mode 100644 extern/libmv/patches/bundle_tweaks.patch delete mode 100644 extern/libmv/patches/clang-3.diff create mode 100644 extern/libmv/third_party/gflags/AUTHORS create mode 100644 extern/libmv/third_party/gflags/COPYING create mode 100644 extern/libmv/third_party/gflags/ChangeLog create mode 100644 extern/libmv/third_party/gflags/NEWS rename extern/libmv/third_party/gflags/{ => gflags}/gflags.h (76%) rename extern/libmv/third_party/gflags/{ => gflags}/gflags_completions.h (89%) create mode 100644 extern/libmv/third_party/gflags/gflags/gflags_declare.h create mode 100644 extern/libmv/third_party/gflags/util.h mode change 100755 => 100644 extern/libmv/third_party/glog/src/windows/preprocess.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 25ed193b266..384a39c107f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1533,14 +1533,6 @@ if(MSVC10) endif() endif() -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - if(WITH_LIBMV) - message(WARNING "Using Clang as CXX compiler: disabling WITH_LIBMV, this feature will be missing.") - set(WITH_LIBMV OFF) - endif() -endif() - - # ensure python header is found since detection can fail, this could happen # with _any_ library but since we used a fixed python version this tends to # be most problematic. diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index 3bd021209df..c16d842dd65 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -132,9 +132,11 @@ set(SRC third_party/fast/fast.h third_party/gflags/config.h - third_party/gflags/gflags_completions.h - third_party/gflags/gflags.h + third_party/gflags/gflags/gflags_completions.h + third_party/gflags/gflags/gflags_declare.h + third_party/gflags/gflags/gflags.h third_party/gflags/mutex.h + third_party/gflags/util.h third_party/ldl/Include/ldl.h third_party/msinttypes/inttypes.h third_party/msinttypes/stdint.h diff --git a/extern/libmv/ChangeLog b/extern/libmv/ChangeLog index f49a07de350..68c3431314a 100644 --- a/extern/libmv/ChangeLog +++ b/extern/libmv/ChangeLog @@ -1,3 +1,60 @@ +commit bf0c3423ba41b90638e89a56500aeaeb120fbaf1 +Author: Sergey I. Sharybin +Date: Sun Mar 11 20:34:15 2012 +0600 + + Replace "third_party/glog/src/glog/logging.h" with + + It was needed because of how build systems is setup in Blender but think + this will be helpful change for other applications too because it makes + it's easier to move libraries around and even use libraries installed + on the operation system. + +commit 3e2673282f313c5bd19720f26d769f5d240a0563 +Author: Sergey I. Sharybin +Date: Sun Mar 11 19:27:41 2012 +0600 + + Upgrade gflags and glog libraries - stage 2 (final) + + Changes to upstream code which are needed to make libmv compile smooth on all platforms + + * Replace with "third_party/gflags/gflags/gflags.h" which is easier + to setup things in libmv and also helps with setting up building libmv into + external applications. + * Replace "glog/logging.h" and "glog/logging.h" with and + which is needed on Windows platform because otherwise files like logging.cc will be using + relative path which points to headers used by linux instead of headers need to be used + on Windows. + * Replace _asm int 3 with __debugbreak(). Such assembler code is obsolete and doesn't work + with 64bit versions of MSVC compilers. + * Do not use stacktrace for MinGW and FreeBSD because it leads into issues accessing + some specific data on this platforms. + * Define HAVE_LIB_GFLAGS for Windows builds. + * Do not define __declspec(dllimport) for MinGW platforms. + * Setup proper includes and datatypes for int32, uint32, int64 and uint64 for MinGW + * Do not define va_copy for MinGW platforms (it's already defined there). + * Patch localtime_r to be working fine with MinGW, disable strerror_r for MinGW because + of lack of needed functions. + +commit 8ed07abfa49d1e0511752021c972e0715e5a1383 +Author: Sergey I. Sharybin +Date: Sun Mar 11 19:06:33 2012 +0600 + + Upgrade gflags and glog libraries - stage 1 + + This commit copies sources from latest original release of gflags and glog + over currently bundled versions of this libraries without any modifications. + + This revision can't b compiled, all needed changes to make new libraries working + fine will be done with next commit to make it clear which changes were necessary + for easier bundling further newer version and extract patches and put them to + gflags/glog upstream repo. + + Such upgrade of libraries is needed to make it able to compile libmv + with clang compilers. Currently used versions: + + - gflags is version 2.0 + - glog is version 0.3.2 + commit 75b9af405964ff2c7d3f0a44500e27e63b37c91b Author: Sergey Sharybin Date: Fri Feb 17 23:29:11 2012 +0600 @@ -429,21 +486,3 @@ Author: Matthias Fauconneau Date: Thu Aug 18 23:14:17 2011 +0200 Fix affine iteration. - -commit 4e8e0aa6018e3eb2fbebdad7f1cbd6c909d26e79 -Author: Matthias Fauconneau -Date: Thu Aug 18 23:03:26 2011 +0200 - - Handle rotations. - -commit 3ce41cf3c1b5c136a61d8f4c63ccae3cafbdb8da -Author: Matthias Fauconneau -Date: Thu Aug 18 22:24:47 2011 +0200 - - Slow brute-force affine diamond search implementation. - -commit 1c4acd03e030c1c50dc6fc36c419c72ea69a0713 -Author: Matthias Fauconneau -Date: Thu Aug 18 20:51:43 2011 +0200 - - Fix detect.cc. diff --git a/extern/libmv/files.txt b/extern/libmv/files.txt index 96dfd89828e..028af579d11 100644 --- a/extern/libmv/files.txt +++ b/extern/libmv/files.txt @@ -78,14 +78,20 @@ third_party/fast/LICENSE third_party/fast/nonmax.c third_party/fast/README third_party/fast/README.libmv +third_party/gflags/AUTHORS +third_party/gflags/ChangeLog third_party/gflags/config.h +third_party/gflags/COPYING third_party/gflags/gflags.cc third_party/gflags/gflags_completions.cc -third_party/gflags/gflags_completions.h -third_party/gflags/gflags.h +third_party/gflags/gflags/gflags_completions.h +third_party/gflags/gflags/gflags_declare.h +third_party/gflags/gflags/gflags.h third_party/gflags/gflags_reporting.cc third_party/gflags/mutex.h +third_party/gflags/NEWS third_party/gflags/README.libmv +third_party/gflags/util.h third_party/glog/AUTHORS third_party/glog/ChangeLog third_party/glog/COPYING diff --git a/extern/libmv/libmv-capi.cpp b/extern/libmv/libmv-capi.cpp index 1835c53b53f..465bf519dbd 100644 --- a/extern/libmv/libmv-capi.cpp +++ b/extern/libmv/libmv-capi.cpp @@ -30,6 +30,7 @@ #include "libmv-capi.h" +#include "third_party/gflags/gflags/gflags.h" #include "glog/logging.h" #include "libmv/logging/logging.h" diff --git a/extern/libmv/libmv/logging/logging.h b/extern/libmv/libmv/logging/logging.h index af86c4baa42..776d9d52f7a 100644 --- a/extern/libmv/libmv/logging/logging.h +++ b/extern/libmv/libmv/logging/logging.h @@ -21,7 +21,7 @@ #ifndef LIBMV_LOGGING_LOGGING_H #define LIBMV_LOGGING_LOGGING_H -#include "glog/logging.h" +#include #define LG LOG(INFO) #define V0 LOG(INFO) diff --git a/extern/libmv/libmv/simple_pipeline/pipeline.cc b/extern/libmv/libmv/simple_pipeline/pipeline.cc index 2e4e5a6491d..2459d059114 100644 --- a/extern/libmv/libmv/simple_pipeline/pipeline.cc +++ b/extern/libmv/libmv/simple_pipeline/pipeline.cc @@ -280,6 +280,25 @@ double InternalReprojectionError(const Tracks &image_tracks, double ex = reprojected_marker.x - markers[i].x; double ey = reprojected_marker.y - markers[i].y; + const int N = 100; + char line[N]; + snprintf(line, N, + "image %-3d track %-3d " + "x %7.1f y %7.1f " + "rx %7.1f ry %7.1f " + "ex %7.1f ey %7.1f" + " e %7.1f", + markers[i].image, + markers[i].track, + markers[i].x, + markers[i].y, + reprojected_marker.x, + reprojected_marker.y, + ex, + ey, + sqrt(ex*ex + ey*ey)); + LG << line; + total_error += sqrt(ex*ex + ey*ey); } LG << "Skipped " << num_skipped << " markers."; diff --git a/extern/libmv/patches/bundle_tweaks.patch b/extern/libmv/patches/bundle_tweaks.patch deleted file mode 100644 index aebc257f7f9..00000000000 --- a/extern/libmv/patches/bundle_tweaks.patch +++ /dev/null @@ -1,152 +0,0 @@ -diff --git a/src/libmv/logging/logging.h b/src/libmv/logging/logging.h -index 067da52..af86c4b 100644 ---- a/src/libmv/logging/logging.h -+++ b/src/libmv/logging/logging.h -@@ -21,7 +21,7 @@ - #ifndef LIBMV_LOGGING_LOGGING_H - #define LIBMV_LOGGING_LOGGING_H - --#include "third_party/glog/src/glog/logging.h" -+#include "glog/logging.h" - - #define LG LOG(INFO) - #define V0 LOG(INFO) -diff --git a/src/libmv/simple_pipeline/pipeline.cc b/src/libmv/simple_pipeline/pipeline.cc -index 2459d05..2e4e5a6 100644 ---- a/src/libmv/simple_pipeline/pipeline.cc -+++ b/src/libmv/simple_pipeline/pipeline.cc -@@ -280,25 +280,6 @@ double InternalReprojectionError(const Tracks &image_tracks, - double ex = reprojected_marker.x - markers[i].x; - double ey = reprojected_marker.y - markers[i].y; - -- const int N = 100; -- char line[N]; -- snprintf(line, N, -- "image %-3d track %-3d " -- "x %7.1f y %7.1f " -- "rx %7.1f ry %7.1f " -- "ex %7.1f ey %7.1f" -- " e %7.1f", -- markers[i].image, -- markers[i].track, -- markers[i].x, -- markers[i].y, -- reprojected_marker.x, -- reprojected_marker.y, -- ex, -- ey, -- sqrt(ex*ex + ey*ey)); -- LG << line; -- - total_error += sqrt(ex*ex + ey*ey); - } - LG << "Skipped " << num_skipped << " markers."; -diff --git a/src/third_party/glog/src/glog/logging.h b/src/third_party/glog/src/glog/logging.h -index 57615ef..a58d478 100644 ---- a/src/third_party/glog/src/glog/logging.h -+++ b/src/third_party/glog/src/glog/logging.h -@@ -33,6 +33,7 @@ - // Pretty much everybody needs to #include this file so that they can - // log various happenings. - // -+ - #ifndef _LOGGING_H_ - #define _LOGGING_H_ - -diff --git a/src/third_party/glog/src/logging.cc b/src/third_party/glog/src/logging.cc -index 868898f..1bb3867 100644 ---- a/src/third_party/glog/src/logging.cc -+++ b/src/third_party/glog/src/logging.cc -@@ -58,8 +58,8 @@ - #include // for errno - #include - #include "base/commandlineflags.h" // to get the program name --#include "glog/logging.h" --#include "glog/raw_logging.h" -+#include -+#include - #include "base/googleinit.h" - - #ifdef HAVE_STACKTRACE -@@ -1232,7 +1232,9 @@ void LogMessage::RecordCrashReason( - } - - static void logging_fail() { --#if defined(_DEBUG) && defined(_MSC_VER) -+// #if defined(_DEBUG) && defined(_MSC_VER) -+// doesn't work for my laptop (sergey) -+#if 0 - // When debugging on windows, avoid the obnoxious dialog and make - // it possible to continue past a LOG(FATAL) in the debugger - _asm int 3 -diff --git a/src/third_party/glog/src/raw_logging.cc b/src/third_party/glog/src/raw_logging.cc -index 50c6a71..b179a1e 100644 ---- a/src/third_party/glog/src/raw_logging.cc -+++ b/src/third_party/glog/src/raw_logging.cc -@@ -42,8 +42,8 @@ - #include // for open() - #include - #include "config.h" --#include "glog/logging.h" // To pick up flag settings etc. --#include "glog/raw_logging.h" -+#include // To pick up flag settings etc. -+#include - #include "base/commandlineflags.h" - - #ifdef HAVE_STACKTRACE -diff --git a/src/third_party/glog/src/utilities.h b/src/third_party/glog/src/utilities.h -index c4ae256..5c841a0 100644 ---- a/src/third_party/glog/src/utilities.h -+++ b/src/third_party/glog/src/utilities.h -@@ -79,7 +79,7 @@ - #endif - - #include "config.h" --#include "glog/logging.h" -+#include - - // There are three different ways we can try to get the stack trace: - // -diff --git a/src/third_party/glog/src/vlog_is_on.cc b/src/third_party/glog/src/vlog_is_on.cc -index ee0e412..ed88514 100644 ---- a/src/third_party/glog/src/vlog_is_on.cc -+++ b/src/third_party/glog/src/vlog_is_on.cc -@@ -40,8 +40,8 @@ - #include - #include - #include "base/commandlineflags.h" --#include "glog/logging.h" --#include "glog/raw_logging.h" -+#include -+#include - #include "base/googleinit.h" - - // glog doesn't have annotation -diff --git a/src/third_party/glog/src/windows/config.h b/src/third_party/glog/src/windows/config.h -index 114762e..682a1b9 100755 ---- a/src/third_party/glog/src/windows/config.h -+++ b/src/third_party/glog/src/windows/config.h -@@ -19,7 +19,7 @@ - #undef HAVE_LIBUNWIND_H - - /* define if you have google gflags library */ --#undef HAVE_LIB_GFLAGS -+#define HAVE_LIB_GFLAGS 1 - - /* define if you have libunwind */ - #undef HAVE_LIB_UNWIND -diff --git a/src/third_party/glog/src/windows/glog/logging.h b/src/third_party/glog/src/windows/glog/logging.h -index 4257375..2f41681 100755 ---- a/src/third_party/glog/src/windows/glog/logging.h -+++ b/src/third_party/glog/src/windows/glog/logging.h -@@ -82,8 +82,8 @@ - #include // a third place for uint16_t or u_int16_t - #endif - --#if 0 --#include -+#if 1 -+#include "third_party/gflags/gflags.h" - #endif - - #ifdef __MINGW32__ diff --git a/extern/libmv/patches/clang-3.diff b/extern/libmv/patches/clang-3.diff deleted file mode 100644 index 9e73490827d..00000000000 --- a/extern/libmv/patches/clang-3.diff +++ /dev/null @@ -1,49 +0,0 @@ -Index: third_party/glog/src/utilities.h -=================================================================== ---- third_party/glog/src/utilities.h (revision 44501) -+++ third_party/glog/src/utilities.h (working copy) -@@ -105,7 +105,7 @@ - # undef STACKTRACE_H - #elif defined(HAVE_LIB_UNWIND) - # define STACKTRACE_H "stacktrace_libunwind-inl.h" --#elif !defined(NO_FRAME_POINTER) -+#elif !defined(NO_FRAME_POINTER) && !defined(__clang__) - # if defined(__i386__) && __GNUC__ >= 2 - # define STACKTRACE_H "stacktrace_x86-inl.h" - # elif defined(__x86_64__) && __GNUC__ >= 2 -Index: third_party/glog/src/logging.cc -=================================================================== ---- third_party/glog/src/logging.cc (revision 44501) -+++ third_party/glog/src/logging.cc (working copy) -@@ -1231,6 +1231,14 @@ - #endif - } - -+#if defined(HAVE___ATTRIBUTE__) -+typedef void (*fail_func_t)() __attribute__((noreturn)); -+static void logging_fail() __attribute__((noreturn)); -+#else -+typedef void (*fail_func_t)(); -+static void logging_fail(); -+#endif -+ - static void logging_fail() { - // #if defined(_DEBUG) && defined(_MSC_VER) - // doesn't work for my laptop (sergey) -@@ -1243,14 +1251,9 @@ - #endif - } - --#ifdef HAVE___ATTRIBUTE__ --GOOGLE_GLOG_DLL_DECL --void (*g_logging_fail_func)() __attribute__((noreturn)) = &logging_fail; --#else --GOOGLE_GLOG_DLL_DECL void (*g_logging_fail_func)() = &logging_fail; --#endif -+GOOGLE_GLOG_DLL_DECL fail_func_t g_logging_fail_func = &logging_fail; - --void InstallFailureFunction(void (*fail_func)()) { -+void InstallFailureFunction(fail_func_t fail_func) { - g_logging_fail_func = fail_func; - } - diff --git a/extern/libmv/patches/series b/extern/libmv/patches/series index 2b2e69bd849..1db7983fdd0 100644 --- a/extern/libmv/patches/series +++ b/extern/libmv/patches/series @@ -1,3 +1 @@ v3d_verbosity.patch -bundle_tweaks.patch -clang-3.diff diff --git a/extern/libmv/third_party/gflags/AUTHORS b/extern/libmv/third_party/gflags/AUTHORS new file mode 100644 index 00000000000..887918bd00e --- /dev/null +++ b/extern/libmv/third_party/gflags/AUTHORS @@ -0,0 +1,2 @@ +google-gflags@googlegroups.com + diff --git a/extern/libmv/third_party/gflags/COPYING b/extern/libmv/third_party/gflags/COPYING new file mode 100644 index 00000000000..d15b0c24134 --- /dev/null +++ b/extern/libmv/third_party/gflags/COPYING @@ -0,0 +1,28 @@ +Copyright (c) 2006, Google Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/extern/libmv/third_party/gflags/ChangeLog b/extern/libmv/third_party/gflags/ChangeLog new file mode 100644 index 00000000000..f9ef9350984 --- /dev/null +++ b/extern/libmv/third_party/gflags/ChangeLog @@ -0,0 +1,195 @@ +Wed Jan 25 15:09:14 2012 Google Inc. + + * gflags: version 2.0 + * Changed the 'official' gflags email in setup.py/etc + * Renamed google-gflags.sln to gflags.sln + * Changed copyright text to reflect Google's relinquished ownership + +Tue Dec 20 19:48:57 2011 Google Inc. + + * google-gflags: version 1.7 + * Add CommandLineFlagInfo::flag_ptr pointing to current storage (musji) + * PORTING: flush after writing to stderr, needed on cygwin + * PORTING: Clean up the GFLAGS_DLL_DECL stuff better + * Fix a bug in StringPrintf() that affected large strings (csilvers) + * Die at configure-time when g++ isn't installed + +Fri Jul 29 19:05:21 2011 Google Inc. + + * google-gflags: version 1.6 + * BUGFIX: Fix a bug where we were leaving out a required $(top_srcdir) + * Fix definition of clstring (jyrki) + * Split up flag declares into its own file (jyrki) + * Add --version support (csilvers) + * Update the README for gflags with static libs + * Update acx_pthread.m4 for nostdlib + * Change ReparseCommandLineFlags to return void (csilvers) + * Some doc typofixes and example augmentation (various) + +Mon Jan 24 16:11:35 2011 Google Inc. + + * google-gflags: version 1.5 + * Better reporting of current vs default value (handler) + * Add API for cleaning up of memory at program-exit (jmarantz) + * Fix macros to work inside namespaces (csilvers) + * Use our own string typedef in case string is redefined (csilvers) + * Updated to autoconf 2.65 + +Wed Oct 13 17:40:12 2010 Google Inc. + + * google-gflags: version 1.4 + * Add a check to prevent passing 0 to DEFINE_string (jorg) + * Reduce compile (.o) size (jyrki) + * Some small changes to quiet debug compiles (alexk) + * PORTING: better support static linking on windows (csilvers) + * DOCUMENTATION: change default values, use validators, etc. + * Update the NEWS file to be non-empty + * Add pkg-config (.pc) files for libgflags and libgflags_nothreads + +Mon Jan 4 18:09:30 2010 Google Inc. + + * google-gflags: version 1.3 + * PORTABILITY: can now build and run tests under MSVC (csilvers) + * Remove the python gflags code, which is now its own package (tansell) + * Clarify that "last flag wins" in the docs (csilvers) + * Comment danger of using GetAllFlags in validators (wojtekm) + * PORTABILITY: Some fixes necessary for c++0x (mboerger) + * Makefile fix: $(srcdir) -> $(top_srcdir) in one place (csilvres) + * INSTALL: autotools to autoconf v2.64 + automake v1.11 (csilvers) + +Thu Sep 10 12:53:04 2009 Google Inc. + + * google-gflags: version 1.2 + * PORTABILITY: can now build and run tests under mingw (csilvers) + * Using a string arg for a bool flag is a compile-time error (rbayardo) + * Add --helpxml to gflags.py (salcianu) + * Protect against a hypothetical global d'tor mutex problem (csilvers) + * BUGFIX: can now define a flag after 'using namespace google' (hamaji) + +Tue Apr 14 12:35:25 2009 Google Inc. + + * google-gflags: version 1.1 + * Add both foo and nofoo for boolean flags, with --undefok (andychu) + * Better document how validators work (wojtekm) + * Improve binary-detection for bash-completion (mtamsky) + * Python: Add a concept of "key flags", used with --help (salcianu) + * Python: Robustify flag_values (salcianu) + * Python: Add a new DEFINE_bool alias (keir, andrewliu) + * Python: Do module introspection based on module name (dsturtevant) + * Fix autoconf a bit better, especially on windows and solaris (ajenjo) + * BUG FIX: gflags_nothreads was linking against the wrong lib (ajenjo) + * BUG FIX: threads-detection failed on FreeBSD; replace it (ajenjo) + * PORTABILITY: Quiet an internal compiler error with SUSE 10 (csilvers) + * PORTABILITY: Update deb.sh for more recenty debuilds (csilvers) + * PORTABILITY: #include more headers to satify new gcc's (csilvers) + * INSTALL: Updated to autoconf 2.61 and libtool 1.5.26 (csilvers) + +Fri Oct 3 15:16:46 2008 Google Inc. + + * google-gflags: version 1.0 + * Add a missing newline to an error string (bcmills) + * (otherwise exactly the same as gflags 1.0rc2) + +Thu Sep 18 12:58:05 2008 Google Inc. + + * google-gflags: version 1.0rc2 + * Report current flag values in --helpxml (hdn) + * Fix compilation troubles with gcc 4.3.3 (simonb) + * BUG FIX: I was missing a std:: in DECLARE_string (csilvers) + * BUG FIX: Clarify in docs how to specify --bool flags (csilvers) + * BUG FIX: Fix --helpshort for source files not in a subdir (csilvers) + * BUG FIX: Fix python unittest for 64-bit builds (bcmills) + +Tue Aug 19 16:15:48 2008 + + * google-gflags: version 1.0rc1 + * Move #include files from google/ to gflags/ (csilvers) + * Small optimizations to reduce binary (library) size (jyrki) + * BUGFIX: forgot a std:: in one of the .h files (csilvers) + * Speed up locking by making sure calls are inlined (ajenjo) + * 64-BIT COMPATIBILITY: Use %PRId64 instead of %lld (csilvers) + * PORTABILITY: fix Makefile to work with Cygwin (ajenjo) + * PORTABILITY: fix code to compile under Visual Studio (ajenjo) + * PORTABILITY: fix code to compile under Solaris 10 with CC (csilvers) + +Mon Jul 21 23:01:38 2008 Google Inc. + + * google-gflags: version 0.9 + * Add the ability to validate a command-line flag (csilvers) + * Add completion support for commandline flags in bash (daven) + * Add -W compile flags to Makefile, when using gcc (csilvers) + * Allow helpstring to be NULL (cristianoc) + * Improved documentation of classes in the .cc file (csilvers) + * Fix python bug with AppendFlagValues + shortnames (jjtswan) + * Use bool instead of int for boolean flags in gflags.py (bcmills) + * Simplify the way we declare flags, now more foolproof (csilvers) + * Better error messages when bool flags collide (colohan) + * Only evaluate DEFINE_foo macro args once (csilvers) + +Wed Mar 26 15:20:18 2008 Google Inc. + + * google-gflags: version 0.8 + * Export DescribeOneFlag() in the API + * Add support for automatic line wrapping at 80 cols for gflags.py + * Bugfix: do not treat an isolated "-" the same as an isolated "--" + * Update rpm spec to point to Google Code rather than sourceforge (!) + * Improve documentation (including documenting thread-safety) + * Improve #include hygiene + * Improve testing + +Thu Oct 18 11:33:20 2007 Google Inc. + + * google-gflags: version 0.7 + * Deal even more correctly with libpthread not linked in (csilvers) + * Add STRIP_LOG, an improved DO_NOT_SHOW_COMMANDLINE_HELP (sioffe) + * Be more accurate printing default flag values in --help (dsturtevant) + * Reduce .o file size a bit by using shorter namespace names (jeff) + * Use relative install path, so 'setup.py --home' works (csilvers) + * Notice when a boolean flag has a non-boolean default (bnmouli) + * Broaden --helpshort to match foo-main.cc and foo_main.cc (hendrie) + * Fix "no modules match" message for --helpshort, etc (hendrie) + +Wed Aug 15 07:35:51 2007 Google Inc. + + * google-gflags: version 0.6 + * Deal correctly with case that libpthread is not linked in (csilvers) + * Update Makefile/tests so we pass "make distcheck" (csilvers) + * Document and test that last assignment to a flag wins (wan) + +Tue Jun 12 15:23:42 2007 Google Inc. + + * google-gflags: version 0.5 + * Include all m4 macros in the distribution (csilvers) + * Python: Fix broken data_files field in setup.py (sidlon) + * Python: better string serliaizing and unparsing (abo, csimmons) + * Fix checks for NaN and inf to work with Mac OS X (csilvers) + +Thu Apr 19 15:15:07 2007 Google Inc. + + * google-gflags: version 0.4 + * Remove is_default from GetCommandLineFlagInfo (csilvers) + * Portability fixes: includes, strtoll, gcc4.3 errors (csilvers) + * A few doc typo cleanups (csilvers) + +Wed Mar 28 12:15:56 2007 Google Inc. + + * google-gflags: version 0.3 + * python portability fix: use popen instead of subprocess (csilvers) + * Add is_default to CommandLineFlagInfo (pchien) + * Make docs a bit prettier (csilvers) + * Actually include the python files in the distribution! :-/ (csilvers) + +Mon Jan 22 15:33:06 2007 Google Inc. + + * google-gflags: version 0.2 + * added support for python commandlineflags, as well as c++ + * gflags2man, a script to turn flags into a man page (dchristian) + +Wed Dec 13 12:37:19 2006 Google Inc. + + * google-gflags: initial release: + The gflags package contains a library that implements commandline + flags processing. As such it's a replacement for getopt(). It + has increased flexibility, including built-in support for C++ + types like string, and the ability to define flags in the source + file in which they're used. diff --git a/extern/libmv/third_party/gflags/NEWS b/extern/libmv/third_party/gflags/NEWS new file mode 100644 index 00000000000..ffc0127d91e --- /dev/null +++ b/extern/libmv/third_party/gflags/NEWS @@ -0,0 +1,158 @@ +== 25 January 2012 == + +I've just released gflags 2.0. + +The `google-gflags` project has been renamed to `gflags`. I +(csilvers) am stepping down as maintainer, to be replaced by Andreas +Schuh. Welcome to the team, Andreas! I've seen the energy you have +around gflags and the ideas you have for the project going forward, +and look forward to having you on the team. + +I bumped the major version number up to 2 to reflect the new community +ownership of the project. All the +[http://gflags.googlecode.com/svn/tags/gflags-2.0/ChangeLog changes] +are related to the renaming. There are no functional changes from +gflags 1.7. In particular, I've kept the code in the namespace +`google`, though in a future version it should be renamed to `gflags`. +I've also kept the `/usr/local/include/google/` subdirectory as +synonym of `/usr/local/include/gflags/`, though the former name has +been obsolete for some time now. + + +=== 18 January 2011 === + +The `google-gflags` Google Code page has been renamed to +`gflags`, in preparation for the project being renamed to +`gflags`. In the coming weeks, I'll be stepping down as +maintainer for the gflags project, and as part of that Google is +relinquishing ownership of the project; it will now be entirely +community run. The name change reflects that shift. + + +=== 20 December 2011 === + +I've just released gflags 1.7. This is a minor release; the major +change is that `CommandLineFlagInfo` now exports the address in memory +where the flag is located. There has also been a bugfix involving +very long --help strings, and some other minor +[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.7/ChangeLog changes]. + +=== 29 July 2011 === + +I've just released gflags 1.6. The major new feature in this release +is support for setting version info, so that --version does something +useful. + +One minor change has required bumping the library number: +`ReparseCommandlineFlags` now returns `void` instead of `int` (the int +return value was always meaningless). Though I doubt anyone ever used +this (meaningless) return value, technically it's a change to the ABI +that requires a version bump. A bit sad. + +There's also a procedural change with this release: I've changed the +internal tools used to integrate Google-supplied patches for gflags +into the opensource release. These new tools should result in more +frequent updates with better change descriptions. They will also +result in future `ChangeLog` entries being much more verbose (for better +or for worse). + +See the +[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.6/ChangeLog ChangeLog] +for a full list of changes for this release. + +=== 24 January 2011 === + +I've just released gflags 1.5. This release has only minor changes +from 1.4, including some slightly better reporting in --help, and +an new memory-cleanup function that can help when running gflags-using +libraries under valgrind. The major change is to fix up the macros +(`DEFINE_bool` and the like) to work more reliably inside namespaces. + +If you have not had a problem with these macros, and don't need any of +the other changes described, there is no need to upgrade. See the +[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.5/ChangeLog ChangeLog] +for a full list of changes for this release. + +=== 11 October 2010 === + +I've just released gflags 1.4. This release has only minor changes +from 1.3, including some documentation tweaks and some work to make +the library smaller. If 1.3 is working well for you, there's no +particular reason to upgrade. + +=== 4 January 2010 === + +I've just released gflags 1.3. gflags now compiles under MSVC, and +all tests pass. I *really* never thought non-unix-y Windows folks +would want gflags, but at least some of them do. + +The major news, though, is that I've separated out the python package +into its own library, [http://code.google.com/p/python-gflags python-gflags]. +If you're interested in the Python version of gflags, that's the place to +get it now. + +=== 10 September 2009 == + +I've just released gflags 1.2. The major change from gflags 1.1 is it +now compiles under MinGW (as well as cygwin), and all tests pass. I +never thought Windows folks would want unix-style command-line flags, +since they're so different from the Windows style, but I guess I was +wrong! + +The other changes are minor, such as support for --htmlxml in the +python version of gflags. + +=== 15 April 2009 === + +I've just released gflags 1.1. It has only minor changes fdrom gflags +1.0 (see the +[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.1/ChangeLog ChangeLog] +for details). The major change is that I moved to a new +system for creating .deb and .rpm files. This allows me to create +x86_64 deb and rpm files. + +In the process of moving to this new system, I noticed an +inconsistency: the tar.gz and .rpm files created libraries named +libgflags.so, but the deb file created libgoogle-gflags.so. I have +fixed the deb file to create libraries like the others. I'm no expert +in debian packaging, but I believe this has caused the package name to +change as well. Please let me know (at +[mailto:google-gflags@googlegroups.com +google-gflags@googlegroups.com]) if this causes problems for you -- +especially if you know of a fix! I would be happy to change the deb +packages to add symlinks from the old library name to the new +(libgoogle-gflags.so -> libgflags.so), but that is beyond my knowledge +of how to make .debs. + +If you've tried to install a .rpm or .deb and it doesn't work for you, +let me know. I'm excited to finally have 64-bit package files, but +there may still be some wrinkles in the new system to iron out. + +===1 October 2008=== + +gflags 1.0rc2 was out for a few weeks without any issues, so gflags +1.0 is now released. This is much like gflags 0.9. The major change +is that the .h files have been moved from `/usr/include/google` to +`/usr/include/gflags`. While I have backwards-compatibility +forwarding headeds in place, please rewrite existing code to say +{{{ + #include +}}} +instead of +{{{ + #include +}}} + +I've kept the default namespace to google. You can still change with +with the appropriate flag to the configure script (`./configure +--help` to see the flags). If you have feedback as to whether the +default namespace should change to gflags, which would be a +non-backwards-compatible change, send mail to +`google-gflags@googlegroups.com`! + +Version 1.0 also has some neat new features, like support for bash +commandline-completion of help flags. See the +[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.0rc2/ChangeLog +ChangeLog] for more details. + +If I don't hear any bad news for a few weeks, I'll release 1.0-final. diff --git a/extern/libmv/third_party/gflags/README.libmv b/extern/libmv/third_party/gflags/README.libmv index f2bdef6563e..673099ce618 100644 --- a/extern/libmv/third_party/gflags/README.libmv +++ b/extern/libmv/third_party/gflags/README.libmv @@ -1,7 +1,7 @@ Project: Google Flags URL: http://code.google.com/p/google-gflags/ License: New BSD -Upstream version: 1.5 +Upstream version: 2.0 Local modifications: - Flattened the tree and only included files needed for libmv. This involved diff --git a/extern/libmv/third_party/gflags/config.h b/extern/libmv/third_party/gflags/config.h index ca2c1276c44..03ed03ca99b 100644 --- a/extern/libmv/third_party/gflags/config.h +++ b/extern/libmv/third_party/gflags/config.h @@ -15,7 +15,7 @@ #define HAVE_DLFCN_H 1 /* Define to 1 if you have the header file. */ -#undef HAVE_FNMATCH_H +/* #ubdef HAVE_FNMATCH_H 1 */ /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 @@ -29,12 +29,6 @@ /* Define if you have POSIX threads libraries and header files. */ #define HAVE_PTHREAD 1 -/* Define to 1 if you have the `putenv' function. */ -#define HAVE_PUTENV 1 - -/* Define to 1 if you have the `setenv' function. */ -#define HAVE_SETENV 1 - /* Define to 1 if you have the header file. */ #define HAVE_STDINT_H 1 @@ -73,22 +67,19 @@ #define PACKAGE "gflags" /* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "opensource@google.com" +#define PACKAGE_BUGREPORT "google-gflags@googlegroups.com" /* Define to the full name of this package. */ #define PACKAGE_NAME "gflags" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "gflags 1.5" +#define PACKAGE_STRING "gflags 2.0" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "gflags" -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.5" +#define PACKAGE_VERSION "2.0" /* Define to necessary symbol if this constant uses a non-standard name on your system. */ @@ -101,7 +92,7 @@ #define STL_NAMESPACE std /* Version number of package */ -#define VERSION "1.5" +#define VERSION "2.0" /* Stops putting the code inside the Google namespace */ #define _END_GOOGLE_NAMESPACE_ } diff --git a/extern/libmv/third_party/gflags/gflags.cc b/extern/libmv/third_party/gflags/gflags.cc index 34fe95dac59..4ba2b6f393c 100644 --- a/extern/libmv/third_party/gflags/gflags.cc +++ b/extern/libmv/third_party/gflags/gflags.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006, Google Inc. +// Copyright (c) 1999, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -28,7 +28,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // --- -// Author: Ray Sidney // Revamped and reorganized by Craig Silverstein // // This file contains the implementation of all our command line flags @@ -88,76 +87,35 @@ // other hand, hooks into CommandLineFlagParser. Other API functions // are, similarly, mostly hooks into the functionality described above. -#include "config.h" // This comes first to ensure we define __STDC_FORMAT_MACROS in time. -#ifdef HAVE_INTTYPES_H -#ifndef __STDC_FORMAT_MACROS +#include "config.h" +#if defined(HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS) # define __STDC_FORMAT_MACROS 1 // gcc requires this to get PRId64, etc. #endif -#include -#endif // HAVE_INTTYPES_H -#include // for snprintf + +#include "gflags/gflags.h" +#include #include #include -#include -#include // For va_list and related operations -#include -#include #ifdef HAVE_FNMATCH_H -#include -#endif // HAVE_FNMATCH_H -#include -#include -#include -#include // for pair<> +# include +#endif +#include // For va_list and related operations +#include +#include + #include -#include "gflags.h" +#include +#include +#include // for pair<> +#include #include "mutex.h" +#include "util.h" #ifndef PATH_SEPARATOR #define PATH_SEPARATOR '/' #endif -// Work properly if either strtoll or strtoq is on this system -#ifdef HAVE_STRTOLL -# define strtoint64 strtoll -# define strtouint64 strtoull -#elif HAVE_STRTOQ -# define strtoint64 strtoq -# define strtouint64 strtouq -#else -// Neither strtoll nor strtoq are defined. I hope strtol works! -# define strtoint64 strtol -# define strtouint64 strtoul -#endif - -// If we have inttypes.h, it will have defined PRId32/etc for us. If -// not, take our best guess. -#ifndef PRId32 -# define PRId32 "d" -#endif -#ifndef PRId64 -# define PRId64 "lld" -#endif -#ifndef PRIu64 -# define PRIu64 "llu" -#endif - -// Windows is missing random bits like strcasecmp, strtoll, strtoull, and -// snprintf in the usual locations. Put them somewhere sensible. -// -// TODO(keir): Get the upstream Windows port and use that instead. -#ifdef _MSC_VER -# define snprintf _snprintf -# undef strtoint64 -# define strtoint64 _strtoi64 -# undef strtouint64 -# define strtouint64 _strtoui64 -# define strcasecmp _stricmp -#endif - -typedef signed char int8; -typedef unsigned char uint8; // Special flags, type 1: the 'recursive' flags. They set another flag's val. DEFINE_string(flagfile, "", @@ -183,20 +141,21 @@ using std::sort; using std::string; using std::vector; +// This is used by the unittest to test error-exit code +void GFLAGS_DLL_DECL (*gflags_exitfunc)(int) = &exit; // from stdlib.h + + // The help message indicating that the commandline flag has been // 'stripped'. It will not show up when doing "-help" and its // variants. The flag is stripped if STRIP_FLAG_HELP is set to 1 -// before including gflags/gflags.h. +// before including base/gflags.h -// This is used by this file, and also in commandlineflags_reporting.cc +// This is used by this file, and also in gflags_reporting.cc const char kStrippedFlagHelp[] = "\001\002\003\004 (unknown) \004\003\002\001"; -// This is used by the unittest to test error-exit code -void GFLAGS_DLL_DECL (*commandlineflags_exitfunc)(int) = &exit; // from stdlib.h - namespace { -// There are also 'reporting' flags, in commandlineflags_reporting.cc. +// There are also 'reporting' flags, in gflags_reporting.cc. static const char kError[] = "ERROR: "; @@ -218,12 +177,14 @@ enum DieWhenReporting { DIE, DO_NOT_DIE }; // Report Error and exit if requested. static void ReportError(DieWhenReporting should_die, const char* format, ...) { + char error_message[255]; va_list ap; va_start(ap, format); - vfprintf(stderr, format, ap); + vsnprintf(error_message, sizeof(error_message), format, ap); va_end(ap); - if (should_die == DIE) - commandlineflags_exitfunc(1); // almost certainly exit() + fprintf(stderr, "%s", error_message); + fflush(stderr); // should be unnecessary, but cygwin's rxvt buffers stderr + if (should_die == DIE) gflags_exitfunc(1); } @@ -317,6 +278,7 @@ bool FlagValue::ParseFrom(const char* value) { if (type_ == FV_BOOL) { const char* kTrue[] = { "1", "t", "true", "y", "yes" }; const char* kFalse[] = { "0", "f", "false", "n", "no" }; + COMPILE_ASSERT(sizeof(kTrue) == sizeof(kFalse), true_false_equal); for (size_t i = 0; i < sizeof(kTrue)/sizeof(*kTrue); ++i) { if (strcasecmp(value, kTrue[i]) == 0) { SET_VALUE_AS(bool, true); @@ -346,7 +308,7 @@ bool FlagValue::ParseFrom(const char* value) { switch (type_) { case FV_INT32: { - const int64 r = strtoint64(value, &end, base); + const int64 r = strto64(value, &end, base); if (errno || end != value + strlen(value)) return false; // bad parse if (static_cast(r) != r) // worked, but number out of range return false; @@ -354,7 +316,7 @@ bool FlagValue::ParseFrom(const char* value) { return true; } case FV_INT64: { - const int64 r = strtoint64(value, &end, base); + const int64 r = strto64(value, &end, base); if (errno || end != value + strlen(value)) return false; // bad parse SET_VALUE_AS(int64, r); return true; @@ -362,7 +324,7 @@ bool FlagValue::ParseFrom(const char* value) { case FV_UINT64: { while (*value == ' ') value++; if (*value == '-') return false; // negative number - const uint64 r = strtouint64(value, &end, base); + const uint64 r = strtou64(value, &end, base); if (errno || end != value + strlen(value)) return false; // bad parse SET_VALUE_AS(uint64, r); return true; @@ -531,6 +493,7 @@ class CommandLineFlag { string default_value() const { return defvalue_->ToString(); } const char* type_name() const { return defvalue_->TypeName(); } ValidateFnProto validate_function() const { return validate_fn_proto_; } + const void* flag_ptr() const { return current_->value_buffer_; } void FillCommandLineFlagInfo(struct CommandLineFlagInfo* result); @@ -583,7 +546,6 @@ const char* CommandLineFlag::CleanFileName() const { // search full path backwards. // Stop going backwards at kRootDir; and skip by the first slash. static const char kRootDir[] = ""; // can set this to root directory, - // e.g. "myproject" if (sizeof(kRootDir)-1 == 0) // no prefix to strip return filename(); @@ -592,8 +554,7 @@ const char* CommandLineFlag::CleanFileName() const { while ( clean_name > filename() ) { if (*clean_name == PATH_SEPARATOR) { if (strncmp(clean_name, kRootDir, sizeof(kRootDir)-1) == 0) { - // ".../myproject/base/logging.cc" ==> "base/logging.cc" - clean_name += sizeof(kRootDir)-1; // past "/myproject/" + clean_name += sizeof(kRootDir)-1; // past root-dir break; } } @@ -614,6 +575,7 @@ void CommandLineFlag::FillCommandLineFlagInfo( UpdateModifiedBit(); result->is_default = !modified_; result->has_validator_fn = validate_function() != NULL; + result->flag_ptr = flag_ptr(); } void CommandLineFlag::UpdateModifiedBit() { @@ -634,6 +596,7 @@ void CommandLineFlag::CopyFrom(const CommandLineFlag& src) { } bool CommandLineFlag::Validate(const FlagValue& value) const { + if (validate_function() == NULL) return true; else @@ -657,10 +620,14 @@ struct StringCmp { // Used by the FlagRegistry map class to compare char*'s } }; + class FlagRegistry { public: - FlagRegistry() { } + FlagRegistry() { + } ~FlagRegistry() { + // Not using STLDeleteElements as that resides in util and this + // class is base. for (FlagMap::iterator p = flags_.begin(), e = flags_.end(); p != e; ++p) { CommandLineFlag* flag = p->second; delete flag; @@ -672,12 +639,12 @@ class FlagRegistry { global_registry_ = NULL; } - void Lock() { lock_.Lock(); } - void Unlock() { lock_.Unlock(); } - // Store a flag in this registry. Takes ownership of the given pointer. void RegisterFlag(CommandLineFlag* flag); + void Lock() { lock_.Lock(); } + void Unlock() { lock_.Unlock(); } + // Returns the flag object for the specified name, or NULL if not found. CommandLineFlag* FindFlagLocked(const char* name); @@ -718,26 +685,26 @@ class FlagRegistry { typedef map FlagPtrMap; FlagPtrMap flags_by_ptr_; - Mutex lock_; - static FlagRegistry* global_registry_; // a singleton registry - static Mutex global_registry_lock_; // guards creation of global_registry_ + + Mutex lock_; + static Mutex global_registry_lock_; + + static void InitGlobalRegistry(); // Disallow FlagRegistry(const FlagRegistry&); FlagRegistry& operator=(const FlagRegistry&); }; -FlagRegistry* FlagRegistry::global_registry_ = NULL; -Mutex FlagRegistry::global_registry_lock_(Mutex::LINKER_INITIALIZED); +class FlagRegistryLock { + public: + explicit FlagRegistryLock(FlagRegistry* fr) : fr_(fr) { fr_->Lock(); } + ~FlagRegistryLock() { fr_->Unlock(); } + private: + FlagRegistry *const fr_; +}; -FlagRegistry* FlagRegistry::GlobalRegistry() { - MutexLock acquire_lock(&global_registry_lock_); - if (!global_registry_) { - global_registry_ = new FlagRegistry; - } - return global_registry_; -} void FlagRegistry::RegisterFlag(CommandLineFlag* flag) { Lock(); @@ -807,22 +774,22 @@ CommandLineFlag* FlagRegistry::SplitArgumentLocked(const char* arg, // In that case, we want to return flag 'x'. if (!(flag_name[0] == 'n' && flag_name[1] == 'o')) { // flag-name is not 'nox', so we're not in the exception case. - *error_message = (string(kError) + - "unknown command line flag '" + *key + "'\n"); + *error_message = StringPrintf("%sunknown command line flag '%s'\n", + kError, key->c_str()); return NULL; } flag = FindFlagLocked(flag_name+2); if (flag == NULL) { // No flag named 'x' exists, so we're not in the exception case. - *error_message = (string(kError) + - "unknown command line flag '" + *key + "'\n"); + *error_message = StringPrintf("%sunknown command line flag '%s'\n", + kError, key->c_str()); return NULL; } if (strcmp(flag->type_name(), "bool") != 0) { // 'x' exists but is not boolean, so we're not in the exception case. - *error_message = (string(kError) + - "boolean value (" + *key + ") specified for " + - flag->type_name() + " command line flag\n"); + *error_message = StringPrintf( + "%sboolean value (%s) specified for %s command line flag\n", + kError, key->c_str(), flag->type_name()); return NULL; } // We're in the exception case! @@ -845,25 +812,27 @@ bool TryParseLocked(const CommandLineFlag* flag, FlagValue* flag_value, FlagValue* tentative_value = flag_value->New(); if (!tentative_value->ParseFrom(value)) { if (msg) { - *msg += (string(kError) + "illegal value '" + value + - + "' specified for " + flag->type_name() + " flag '" - + flag->name() + "'\n"); + StringAppendF(msg, + "%sillegal value '%s' specified for %s flag '%s'\n", + kError, value, + flag->type_name(), flag->name()); } delete tentative_value; return false; } else if (!flag->Validate(*tentative_value)) { if (msg) { - *msg += (string(kError) + "failed validation of new value " - + "'" + tentative_value->ToString() + "' for flag '" + - + flag->name() + "'\n"); + StringAppendF(msg, + "%sfailed validation of new value '%s' for flag '%s'\n", + kError, tentative_value->ToString().c_str(), + flag->name()); } delete tentative_value; return false; } else { flag_value->CopyFrom(*tentative_value); if (msg) { - *msg += (string(flag->name()) + " set to " + flag_value->ToString() - + "\n"); + StringAppendF(msg, "%s set to %s\n", + flag->name(), flag_value->ToString().c_str()); } delete tentative_value; return true; @@ -890,7 +859,8 @@ bool FlagRegistry::SetFlagLocked(CommandLineFlag* flag, return false; flag->modified_ = true; } else { - *msg = string(flag->name()) + " set to " + flag->current_value(); + *msg = StringPrintf("%s set to %s", + flag->name(), flag->current_value().c_str()); } break; } @@ -914,13 +884,17 @@ bool FlagRegistry::SetFlagLocked(CommandLineFlag* flag, return true; } -class FlagRegistryLock { - public: - explicit FlagRegistryLock(FlagRegistry* fr) : fr_(fr) { fr_->Lock(); } - ~FlagRegistryLock() { fr_->Unlock(); } - private: - FlagRegistry *const fr_; -}; +// Get the singleton FlagRegistry object +FlagRegistry* FlagRegistry::global_registry_ = NULL; +Mutex FlagRegistry::global_registry_lock_(Mutex::LINKER_INITIALIZED); + +FlagRegistry* FlagRegistry::GlobalRegistry() { + MutexLock acquire_lock(&global_registry_lock_); + if (!global_registry_) { + global_registry_ = new FlagRegistry; + } + return global_registry_; +} // -------------------------------------------------------------------- // CommandLineFlagParser @@ -1002,12 +976,12 @@ class CommandLineFlagParser { static void ParseFlagList(const char* value, vector* flags) { for (const char *p = value; p && *p; value = p) { p = strchr(value, ','); - int len; + size_t len; if (p) { - len = static_cast(p - value); + len = p - value; p++; } else { - len = static_cast(strlen(value)); + len = strlen(value); } if (len == 0) @@ -1023,7 +997,7 @@ static void ParseFlagList(const char* value, vector* flags) { // can do all the I/O in one place and not worry about it everywhere. // Plus, it's convenient to have the whole file contents at hand. // Adds a newline at the end of the file. -#define PFATAL(s) do { perror(s); commandlineflags_exitfunc(1); } while (0) +#define PFATAL(s) do { perror(s); gflags_exitfunc(1); } while (0) static string ReadFileIntoString(const char* filename) { const int kBufSize = 8092; @@ -1112,9 +1086,9 @@ uint32 CommandLineFlagParser::ParseNewCommandLineFlags(int* argc, char*** argv, && strcmp(flag->type_name(), "string") == 0 && (strstr(flag->help(), "true") || strstr(flag->help(), "false"))) { - fprintf(stderr, "Did you really mean to set flag '%s'" - " to the value '%s'?\n", - flag->name(), value); + LOG(WARNING) << "Did you really mean to set flag '" + << flag->name() << "' to the value '" + << value << "'?"; } } } @@ -1165,9 +1139,10 @@ string CommandLineFlagParser::ProcessFromenvLocked(const string& flagval, const char* flagname = flaglist[i].c_str(); CommandLineFlag* flag = registry_->FindFlagLocked(flagname); if (flag == NULL) { - error_flags_[flagname] = (string(kError) + "unknown command line flag" - + " '" + flagname + "'" - + " (via --fromenv or --tryfromenv)\n"); + error_flags_[flagname] = + StringPrintf("%sunknown command line flag '%s' " + "(via --fromenv or --tryfromenv)\n", + kError, flagname); undefined_names_[flagname] = ""; continue; } @@ -1185,8 +1160,9 @@ string CommandLineFlagParser::ProcessFromenvLocked(const string& flagval, // Avoid infinite recursion. if ((strcmp(envval, "fromenv") == 0) || (strcmp(envval, "tryfromenv") == 0)) { - error_flags_[flagname] = (string(kError) + "infinite recursion on " + - "environment flag '" + envval + "'\n"); + error_flags_[flagname] = + StringPrintf("%sinfinite recursion on environment flag '%s'\n", + kError, envval); continue; } @@ -1289,7 +1265,7 @@ string CommandLineFlagParser::ProcessOptionsFromStringLocked( while (*flagfile_contents && isspace(*flagfile_contents)) ++flagfile_contents; line_end = strchr(flagfile_contents, '\n'); - size_t len = line_end ? static_cast(line_end - flagfile_contents) + size_t len = line_end ? line_end - flagfile_contents : strlen(flagfile_contents); string line(flagfile_contents, len); @@ -1340,17 +1316,17 @@ string CommandLineFlagParser::ProcessOptionsFromStringLocked( space = word + strlen(word); const string glob(word, space - word); // We try matching both against the full argv0 and basename(argv0) + if (glob == ProgramInvocationName() // small optimization + || glob == ProgramInvocationShortName() #ifdef HAVE_FNMATCH_H - if (fnmatch(glob.c_str(), - ProgramInvocationName(), - FNM_PATHNAME) == 0 || - fnmatch(glob.c_str(), - ProgramInvocationShortName(), - FNM_PATHNAME) == 0) { -#else // !HAVE_FNMATCH_H - if ((glob == ProgramInvocationName()) || - (glob == ProgramInvocationShortName())) { -#endif // HAVE_FNMATCH_H + || fnmatch(glob.c_str(), + ProgramInvocationName(), + FNM_PATHNAME) == 0 + || fnmatch(glob.c_str(), + ProgramInvocationShortName(), + FNM_PATHNAME) == 0 +#endif + ) { flags_are_relevant = true; } } @@ -1391,14 +1367,14 @@ bool AddFlagValidator(const void* flag_ptr, ValidateFnProto validate_fn_proto) { // This is the CommandLineFlag whose current_->value_buffer_ == flag CommandLineFlag* flag = registry->FindFlagViaPtrLocked(flag_ptr); if (!flag) { - // WARNING << "Ignoring RegisterValidateFunction() for flag pointer " - // << flag_ptr << ": no flag found at that address"; + LOG(WARNING) << "Ignoring RegisterValidateFunction() for flag pointer " + << flag_ptr << ": no flag found at that address"; return false; } else if (validate_fn_proto == flag->validate_function()) { return true; // ok to register the same function over and over again } else if (validate_fn_proto != NULL && flag->validate_function() != NULL) { - // WARNING << "Ignoring RegisterValidateFunction() for flag '" - // << flag->name() << "': validate-fn already registered"; + LOG(WARNING) << "Ignoring RegisterValidateFunction() for flag '" + << flag->name() << "': validate-fn already registered"; return false; } else { flag->validate_fn_proto_ = validate_fn_proto; @@ -1548,6 +1524,24 @@ const char* ProgramUsage() { return "Warning: SetUsageMessage() never called"; } +// -------------------------------------------------------------------- +// SetVersionString() +// VersionString() +// -------------------------------------------------------------------- + +static const char* version_string = NULL; + +void SetVersionString(const string& version) { + if (version_string != NULL) + ReportError(DIE, "ERROR: SetVersionString() called twice\n"); + version_string = strdup(version.c_str()); // small memory leak +} + +const char* VersionString() { + return version_string ? version_string : ""; +} + + // -------------------------------------------------------------------- // GetCommandLineOption() // GetCommandLineFlagInfo() @@ -1601,7 +1595,7 @@ CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name) { CommandLineFlagInfo info; if (!GetCommandLineFlagInfo(name, &info)) { fprintf(stderr, "FATAL ERROR: flag name '%s' doesn't exist\n", name); - commandlineflags_exitfunc(1); // almost certainly exit() + gflags_exitfunc(1); // almost certainly gflags_exitfunc() } return info; } @@ -1616,10 +1610,7 @@ string SetCommandLineOptionWithMode(const char* name, const char* value, CommandLineFlagParser parser(registry); result = parser.ProcessSingleOptionLocked(flag, value, set_mode); if (!result.empty()) { // in the error case, we've already logged - // You could consider logging this change, if you wanted to know it: - //fprintf(stderr, "%sFLAGS_%s\n", - // (set_mode == SET_FLAGS_DEFAULT ? "default value of " : ""), - // result); + // Could consider logging this change } } // The API of this function is that we return empty string on error @@ -1765,7 +1756,7 @@ bool ReadFlagsFromString(const string& flagfilecontents, if (parser.ReportErrors()) { // Error. Restore all global flags to their previous values. if (errors_are_fatal) - commandlineflags_exitfunc(1); // almost certainly exit() + gflags_exitfunc(1); saved_states.RestoreToRegistry(); return false; } @@ -1917,7 +1908,7 @@ static uint32 ParseCommandLineFlagsInternal(int* argc, char*** argv, parser.ValidateAllFlags(); if (parser.ReportErrors()) // may cause us to exit on illegal flags - commandlineflags_exitfunc(1); // almost certainly exit() + gflags_exitfunc(1); return r; } @@ -1947,7 +1938,7 @@ void AllowCommandLineReparsing() { allow_command_line_reparsing = true; } -uint32 ReparseCommandLineNonHelpFlags() { +void ReparseCommandLineNonHelpFlags() { // We make a copy of argc and argv to pass in const vector& argvs = GetArgvs(); int tmp_argc = static_cast(argvs.size()); @@ -1955,13 +1946,11 @@ uint32 ReparseCommandLineNonHelpFlags() { for (int i = 0; i < tmp_argc; ++i) tmp_argv[i] = strdup(argvs[i].c_str()); // TODO(csilvers): don't dup - const int retval = ParseCommandLineNonHelpFlags(&tmp_argc, &tmp_argv, false); + ParseCommandLineNonHelpFlags(&tmp_argc, &tmp_argv, false); for (int i = 0; i < tmp_argc; ++i) free(tmp_argv[i]); delete[] tmp_argv; - - return retval; } void ShutDownCommandLineFlags() { diff --git a/extern/libmv/third_party/gflags/gflags.h b/extern/libmv/third_party/gflags/gflags/gflags.h similarity index 76% rename from extern/libmv/third_party/gflags/gflags.h rename to extern/libmv/third_party/gflags/gflags/gflags.h index cefbd62ae51..e69812c8c38 100644 --- a/extern/libmv/third_party/gflags/gflags.h +++ b/extern/libmv/third_party/gflags/gflags/gflags.h @@ -28,7 +28,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // --- -// Author: Ray Sidney // Revamped and reorganized by Craig Silverstein // // This is the file that should be included by any file which declares @@ -52,8 +51,8 @@ // if (FLAGS_verbose) printf("Records %d-%d\n", FLAGS_start, FLAGS_end); // } // -// Then, at the command-line: -// ./foo --noverbose --start=5 --end=100 +// Then, at the command-line: +// ./foo --noverbose --start=5 --end=100 // // For more details, see // doc/gflags.html @@ -76,48 +75,22 @@ // other thread is writing to the variable or calling non-const // methods of this class. -#ifndef GOOGLE_GFLAGS_H_ -#define GOOGLE_GFLAGS_H_ +#ifndef BASE_COMMANDLINEFLAGS_H_ +#define BASE_COMMANDLINEFLAGS_H_ #include #include - -// We care a lot about number of bits things take up. Unfortunately, -// systems define their bit-specific ints in a lot of different ways. -// We use our own way, and have a typedef to get there. -// Note: these commands below may look like "#if 1" or "#if 0", but -// that's because they were constructed that way at ./configure time. -// Look at gflags.h.in to see how they're calculated (based on your config). -#if 1 -#include // the normal place uint16_t is defined -#endif -#if 1 -#include // the normal place u_int16_t is defined -#endif -#if 1 -#include // a third place for uint16_t or u_int16_t -#endif - +#include "gflags_declare.h" // IWYU pragma: export namespace google { -#if 1 // the C99 format -typedef int32_t int32; -typedef uint32_t uint32; -typedef int64_t int64; -typedef uint64_t uint64; -#elif 1 // the BSD format -typedef int32_t int32; -typedef u_int32_t uint32; -typedef int64_t int64; -typedef u_int64_t uint64; -#elif 0 // the windows (vc7) format -typedef __int32 int32; -typedef unsigned __int32 uint32; -typedef __int64 int64; -typedef unsigned __int64 uint64; -#else -#error Do not know how to define a 32-bit integer quantity on your system -#endif +// +// NOTE: all functions below MUST have an explicit 'extern' before +// them. Our automated opensourcing tools use this as a signal to do +// appropriate munging for windows, which needs to add GFLAGS_DLL_DECL. +// +#define GFLAGS_DLL_DECL /* rewritten to be non-empty in windows dir */ +#define GFLAGS_DLL_DEFINE_FLAG /* rewritten to be non-empty in windows dir */ + // -------------------------------------------------------------------- // To actually define a flag in a file, use DEFINE_bool, @@ -148,18 +121,19 @@ typedef unsigned __int64 uint64; // Returns true if successfully registered, false if not (because the // first argument doesn't point to a command-line flag, or because a // validator is already registered for this flag). -bool RegisterFlagValidator(const bool* flag, - bool (*validate_fn)(const char*, bool)); -bool RegisterFlagValidator(const int32* flag, - bool (*validate_fn)(const char*, int32)); -bool RegisterFlagValidator(const int64* flag, - bool (*validate_fn)(const char*, int64)); -bool RegisterFlagValidator(const uint64* flag, - bool (*validate_fn)(const char*, uint64)); -bool RegisterFlagValidator(const double* flag, - bool (*validate_fn)(const char*, double)); -bool RegisterFlagValidator(const std::string* flag, - bool (*validate_fn)(const char*, const std::string&)); +extern bool RegisterFlagValidator(const bool* flag, + bool (*validate_fn)(const char*, bool)); +extern bool RegisterFlagValidator(const int32* flag, + bool (*validate_fn)(const char*, int32)); +extern bool RegisterFlagValidator(const int64* flag, + bool (*validate_fn)(const char*, int64)); +extern bool RegisterFlagValidator(const uint64* flag, + bool (*validate_fn)(const char*, uint64)); +extern bool RegisterFlagValidator(const double* flag, + bool (*validate_fn)(const char*, double)); +extern bool RegisterFlagValidator(const std::string* flag, + bool (*validate_fn)(const char*, + const std::string&)); // -------------------------------------------------------------------- @@ -173,26 +147,27 @@ bool RegisterFlagValidator(const std::string* flag, // name) and argv (the entire commandline), which we sock away a copy of. // These variables are static, so you should only set them once. -struct CommandLineFlagInfo { - std::string name; // the name of the flag - std::string type; // the type of the flag: int32, etc - std::string description; // the "help text" associated with the flag - std::string current_value; // the current value, as a string - std::string default_value; // the default value, as a string - std::string filename; // 'cleaned' version of filename holding the flag - bool has_validator_fn; // true if RegisterFlagValidator called on flag - bool is_default; // true if the flag has the default value and - // has not been set explicitly from the cmdline - // or via SetCommandLineOption +struct GFLAGS_DLL_DECL CommandLineFlagInfo { + std::string name; // the name of the flag + std::string type; // the type of the flag: int32, etc + std::string description; // the "help text" associated with the flag + std::string current_value; // the current value, as a string + std::string default_value; // the default value, as a string + std::string filename; // 'cleaned' version of filename holding the flag + bool has_validator_fn; // true if RegisterFlagValidator called on this flag + bool is_default; // true if the flag has the default value and + // has not been set explicitly from the cmdline + // or via SetCommandLineOption + const void* flag_ptr; // pointer to the flag's current value (i.e. FLAGS_foo) }; // Using this inside of a validator is a recipe for a deadlock. -// TODO(wojtekm) Fix locking when validators are running, to make it safe to +// TODO(user) Fix locking when validators are running, to make it safe to // call validators during ParseAllFlags. // Also make sure then to uncomment the corresponding unit test in -// commandlineflags_unittest.sh +// gflags_unittest.sh extern void GetAllFlags(std::vector* OUTPUT); -// These two are actually defined in commandlineflags_reporting.cc. +// These two are actually defined in gflags_reporting.cc. extern void ShowUsageWithFlags(const char *argv0); // what --help does extern void ShowUsageWithFlagsRestrict(const char *argv0, const char *restrict); @@ -202,17 +177,24 @@ extern std::string DescribeOneFlag(const CommandLineFlagInfo& flag); // Thread-hostile; meant to be called before any threads are spawned. extern void SetArgv(int argc, const char** argv); + // The following functions are thread-safe as long as SetArgv() is // only called before any threads start. -extern const std::vector& GetArgvs(); // all of argv as a vector -extern const char* GetArgv(); // all of argv as a string -extern const char* GetArgv0(); // only argv0 -extern uint32 GetArgvSum(); // simple checksum of argv -extern const char* ProgramInvocationName(); // argv0, or "UNKNOWN" if not set +extern const std::vector& GetArgvs(); +extern const char* GetArgv(); // all of argv as a string +extern const char* GetArgv0(); // only argv0 +extern uint32 GetArgvSum(); // simple checksum of argv +extern const char* ProgramInvocationName(); // argv0, or "UNKNOWN" if not set extern const char* ProgramInvocationShortName(); // basename(argv0) + // ProgramUsage() is thread-safe as long as SetUsageMessage() is only // called before any threads start. -extern const char* ProgramUsage(); // string set by SetUsageMessage() +extern const char* ProgramUsage(); // string set by SetUsageMessage() + +// VersionString() is thread-safe as long as SetVersionString() is only +// called before any threads start. +extern const char* VersionString(); // string set by SetVersionString() + // -------------------------------------------------------------------- @@ -237,7 +219,7 @@ extern bool GetCommandLineFlagInfo(const char* name, // if (GetCommandLineFlagInfoOrDie("foo").is_default) ... extern CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name); -enum FlagSettingMode { +enum GFLAGS_DLL_DECL FlagSettingMode { // update the flag's value (can call this multiple times). SET_FLAGS_VALUE, // update the flag's value, but *only if* it has not yet been updated @@ -259,7 +241,7 @@ enum FlagSettingMode { // SetCommandLineOption uses set_mode == SET_FLAGS_VALUE (the common case) extern std::string SetCommandLineOption(const char* name, const char* value); extern std::string SetCommandLineOptionWithMode(const char* name, const char* value, - FlagSettingMode set_mode); + FlagSettingMode set_mode); // -------------------------------------------------------------------- @@ -280,14 +262,17 @@ extern std::string SetCommandLineOptionWithMode(const char* name, const char* va // // without worrying about restoring the FLAG values. // } // -// Note: This class is marked with __attribute__((unused)) because all the +// Note: This class is marked with ATTRIBUTE_UNUSED because all the // work is done in the constructor and destructor, so in the standard // usage example above, the compiler would complain that it's an // unused variable. // -// This class is thread-safe. +// This class is thread-safe. However, its destructor writes to +// exactly the set of flags that have changed value during its +// lifetime, so concurrent _direct_ access to those flags +// (i.e. FLAGS_foo instead of {Get,Set}CommandLineOption()) is unsafe. -class FlagSaver { +class GFLAGS_DLL_DECL FlagSaver { public: FlagSaver(); ~FlagSaver(); @@ -311,12 +296,11 @@ extern std::string CommandlineFlagsIntoString(); // Usually where this is used, a FlagSaver should be used instead. extern bool ReadFlagsFromString(const std::string& flagfilecontents, const char* prog_name, - bool errors_are_fatal); // uses SET_FLAGS_VALUE + bool errors_are_fatal); // uses SET_FLAGS_VALUE // These let you manually implement --flagfile functionality. // DEPRECATED. extern bool AppendFlagsIntoFile(const std::string& filename, const char* prog_name); -extern bool SaveCommandFlags(); // actually defined in google.cc ! extern bool ReadFromFlagsFile(const std::string& filename, const char* prog_name, bool errors_are_fatal); // uses SET_FLAGS_VALUE @@ -338,7 +322,7 @@ extern const char *StringFromEnv(const char *varname, const char *defval); // -------------------------------------------------------------------- -// The next two functions parse commandlineflags from main(): +// The next two functions parse gflags from main(): // Set the "usage" message for this program. For example: // string usage("This program does nothing. Sample usage:\n"); @@ -348,6 +332,12 @@ extern const char *StringFromEnv(const char *varname, const char *defval); // Thread-hostile; meant to be called before any threads are spawned. extern void SetUsageMessage(const std::string& usage); +// Sets the version string, which is emitted with --version. +// For instance: SetVersionString("1.3"); +// Thread-hostile; meant to be called before any threads are spawned. +extern void SetVersionString(const std::string& version); + + // Looks for flags in argv and parses them. Rearranges argv to put // flags first, or removes them entirely if remove_flags is true. // If a flag is defined more than once in the command line or flag @@ -355,8 +345,7 @@ extern void SetUsageMessage(const std::string& usage); // of the first non-flag argument. // See top-of-file for more details on this function. #ifndef SWIG // In swig, use ParseCommandLineFlagsScript() instead. -extern uint32 ParseCommandLineFlags(int *argc, char*** argv, - bool remove_flags); +extern uint32 ParseCommandLineFlags(int *argc, char*** argv, bool remove_flags); #endif @@ -372,10 +361,10 @@ extern uint32 ParseCommandLineFlags(int *argc, char*** argv, // non-flag argument. (If remove_flags is true, will always return 1.) extern uint32 ParseCommandLineNonHelpFlags(int *argc, char*** argv, bool remove_flags); -// This is actually defined in commandlineflags_reporting.cc. +// This is actually defined in gflags_reporting.cc. // This function is misnamed (it also handles --version, etc.), but // it's too late to change that now. :-( -extern void HandleCommandLineHelpFlags(); // in commandlineflags_reporting.cc +extern void HandleCommandLineHelpFlags(); // in gflags_reporting.cc // Allow command line reparsing. Disables the error normally // generated when an unknown flag is found, since it may be found in a @@ -389,18 +378,17 @@ extern void AllowCommandLineReparsing(); // separate command line argument that follows the flag argument. // Intended for handling flags from dynamically loaded libraries, // since their flags are not registered until they are loaded. -// Returns the index (into the original argv) of the first non-flag -// argument. (If remove_flags is true, will always return 1.) -extern uint32 ReparseCommandLineNonHelpFlags(); +extern void ReparseCommandLineNonHelpFlags(); // Clean up memory allocated by flags. This is only needed to reduce // the quantity of "potentially leaked" reports emitted by memory // debugging tools such as valgrind. It is not required for normal -// operation, or for the perftools heap-checker. It must only be called -// when the process is about to exit, and all threads that might -// access flags are quiescent. Referencing flags after this is called -// will have unexpected consequences. This is not safe to run when -// multiple threads might be running: the function is thread-hostile. +// operation, or for the google perftools heap-checker. It must only +// be called when the process is about to exit, and all threads that +// might access flags are quiescent. Referencing flags after this is +// called will have unexpected consequences. This is not safe to run +// when multiple threads might be running: the function is +// thread-hostile. extern void ShutDownCommandLineFlags(); @@ -441,15 +429,13 @@ extern void ShutDownCommandLineFlags(); // people can't DECLARE_int32 something that they DEFINE_bool'd // elsewhere. -class FlagRegisterer { +class GFLAGS_DLL_DECL FlagRegisterer { public: FlagRegisterer(const char* name, const char* type, const char* help, const char* filename, void* current_storage, void* defvalue_storage); }; -extern bool FlagsTypeWarn(const char *name); - // If your application #defines STRIP_FLAG_HELP to a non-zero value // before #including this file, we remove the help message from the // binary file. This can reduce the size of the resulting binary @@ -463,7 +449,8 @@ extern const char kStrippedFlagHelp[]; #if defined(STRIP_FLAG_HELP) && STRIP_FLAG_HELP > 0 // Need this construct to avoid the 'defined but not used' warning. -#define MAYBE_STRIPPED_HELP(txt) (false ? (txt) : ::google::kStrippedFlagHelp) +#define MAYBE_STRIPPED_HELP(txt) \ + (false ? (txt) : ::google::kStrippedFlagHelp) #else #define MAYBE_STRIPPED_HELP(txt) txt #endif @@ -479,21 +466,16 @@ extern const char kStrippedFlagHelp[]; // FLAGS_no. This serves the second purpose of assuring a // compile error if someone tries to define a flag named no // which is illegal (--foo and --nofoo both affect the "foo" flag). -#define DEFINE_VARIABLE(type, shorttype, name, value, help) \ - namespace fL##shorttype { \ - static const type FLAGS_nono##name = value; \ - type FLAGS_##name = FLAGS_nono##name; \ - type FLAGS_no##name = FLAGS_nono##name; \ - static ::google::FlagRegisterer o_##name( \ - #name, #type, MAYBE_STRIPPED_HELP(help), __FILE__, \ - &FLAGS_##name, &FLAGS_no##name); \ - } \ - using fL##shorttype::FLAGS_##name - -#define DECLARE_VARIABLE(type, shorttype, name) \ - namespace fL##shorttype { \ - extern type FLAGS_##name; \ - } \ +#define DEFINE_VARIABLE(type, shorttype, name, value, help) \ + namespace fL##shorttype { \ + static const type FLAGS_nono##name = value; \ + /* We always want to export defined variables, dll or no */ \ + GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = FLAGS_nono##name; \ + type FLAGS_no##name = FLAGS_nono##name; \ + static ::google::FlagRegisterer o_##name( \ + #name, #type, MAYBE_STRIPPED_HELP(help), __FILE__, \ + &FLAGS_##name, &FLAGS_no##name); \ + } \ using fL##shorttype::FLAGS_##name // For DEFINE_bool, we want to do the extra check that the passed-in @@ -503,34 +485,39 @@ extern const char kStrippedFlagHelp[]; // We'll use 'sizeof(IsBool(val))' to distinguish. This code requires // that the compiler have different sizes for bool & double. Since // this is not guaranteed by the standard, we check it with a -// compile-time assert (msg[-1] will give a compile-time error). +// COMPILE_ASSERT. namespace fLB { struct CompileAssert {}; typedef CompileAssert expected_sizeof_double_neq_sizeof_bool[ (sizeof(double) != sizeof(bool)) ? 1 : -1]; -template double IsBoolFlag(const From& from); -bool IsBoolFlag(bool from); +template double GFLAGS_DLL_DECL IsBoolFlag(const From& from); +GFLAGS_DLL_DECL bool IsBoolFlag(bool from); } // namespace fLB -#define DECLARE_bool(name) DECLARE_VARIABLE(bool, B, name) -#define DEFINE_bool(name, val, txt) \ - namespace fLB { \ - typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool[ \ +// Here are the actual DEFINE_*-macros. The respective DECLARE_*-macros +// are in a separate include, gflags_declare.h, for reducing +// the physical transitive size for DECLARE use. +#define DEFINE_bool(name, val, txt) \ + namespace fLB { \ + typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool[ \ (sizeof(::fLB::IsBoolFlag(val)) != sizeof(double)) ? 1 : -1]; \ - } \ + } \ DEFINE_VARIABLE(bool, B, name, val, txt) -#define DECLARE_int32(name) DECLARE_VARIABLE(::google::int32, I, name) -#define DEFINE_int32(name,val,txt) DEFINE_VARIABLE(::google::int32, I, name, val, txt) +#define DEFINE_int32(name, val, txt) \ + DEFINE_VARIABLE(::google::int32, I, \ + name, val, txt) -#define DECLARE_int64(name) DECLARE_VARIABLE(::google::int64, I64, name) -#define DEFINE_int64(name,val,txt) DEFINE_VARIABLE(::google::int64, I64, name, val, txt) +#define DEFINE_int64(name, val, txt) \ + DEFINE_VARIABLE(::google::int64, I64, \ + name, val, txt) -#define DECLARE_uint64(name) DECLARE_VARIABLE(::google::uint64, U64, name) -#define DEFINE_uint64(name,val,txt) DEFINE_VARIABLE(::google::uint64, U64, name, val, txt) +#define DEFINE_uint64(name,val, txt) \ + DEFINE_VARIABLE(::google::uint64, U64, \ + name, val, txt) -#define DECLARE_double(name) DECLARE_VARIABLE(double, D, name) -#define DEFINE_double(name, val, txt) DEFINE_VARIABLE(double, D, name, val, txt) +#define DEFINE_double(name, val, txt) \ + DEFINE_VARIABLE(double, D, name, val, txt) // Strings are trickier, because they're not a POD, so we can't // construct them at static-initialization time (instead they get @@ -540,11 +527,6 @@ bool IsBoolFlag(bool from); // into it later. It's not perfect, but the best we can do. namespace fLS { -// The meaning of "string" might be different between now and when the -// macros below get invoked (e.g., if someone is experimenting with -// other string implementations that get defined after this file is -// included). Save the current meaning now and use it in the macros. -typedef std::string clstring; inline clstring* dont_pass0toDEFINE_string(char *stringspot, const char *value) { @@ -558,9 +540,6 @@ inline clstring* dont_pass0toDEFINE_string(char *stringspot, int value); } // namespace fLS -#define DECLARE_string(name) namespace fLS { extern ::fLS::clstring& FLAGS_##name; } \ - using fLS::FLAGS_##name - // We need to define a var named FLAGS_no##name so people don't define // --string and --nostring. And we need a temporary place to put val // so we don't have to evaluate it twice. Two great needs that go @@ -575,10 +554,10 @@ inline clstring* dont_pass0toDEFINE_string(char *stringspot, clstring* const FLAGS_no##name = ::fLS:: \ dont_pass0toDEFINE_string(s_##name[0].s, \ val); \ - static ::google::FlagRegisterer o_##name( \ + static ::google::FlagRegisterer o_##name( \ #name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \ s_##name[0].s, new (s_##name[1].s) clstring(*FLAGS_no##name)); \ - extern clstring& FLAGS_##name; \ + extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \ using fLS::FLAGS_##name; \ clstring& FLAGS_##name = *FLAGS_no##name; \ } \ @@ -586,4 +565,4 @@ inline clstring* dont_pass0toDEFINE_string(char *stringspot, #endif // SWIG -#endif // GOOGLE_GFLAGS_H_ +#endif // BASE_COMMANDLINEFLAGS_H_ diff --git a/extern/libmv/third_party/gflags/gflags_completions.h b/extern/libmv/third_party/gflags/gflags/gflags_completions.h similarity index 89% rename from extern/libmv/third_party/gflags/gflags_completions.h rename to extern/libmv/third_party/gflags/gflags/gflags_completions.h index 9d9ce7a5f75..37f5b0ec2cf 100644 --- a/extern/libmv/third_party/gflags/gflags_completions.h +++ b/extern/libmv/third_party/gflags/gflags/gflags_completions.h @@ -28,7 +28,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // --- -// Author: Dave Nicponski + // // Implement helpful bash-style command line flag completions // @@ -88,8 +88,8 @@ // file would be (your path to gflags_completions.sh file may differ): /* -$ complete -o bashdefault -o default -o nospace -C \ - '/usr/local/bin/gflags_completions.sh --tab_completion_columns $COLUMNS' \ +$ complete -o bashdefault -o default -o nospace -C \ + '/home/build/eng/bash/bash_completions.sh --tab_completion_columns $COLUMNS' \ time env binary_name another_binary [...] */ @@ -109,13 +109,22 @@ $ complete -o bashdefault -o default -o nospace -C \ // produce the expected completion output. -#ifndef GOOGLE_GFLAGS_COMPLETIONS_H_ -#define GOOGLE_GFLAGS_COMPLETIONS_H_ +#ifndef BASE_COMMANDLINEFLAGS_COMPLETIONS_H_ +#define BASE_COMMANDLINEFLAGS_COMPLETIONS_H_ + +// Annoying stuff for windows -- makes sure clients can import these functions +// +// NOTE: all functions below MUST have an explicit 'extern' before +// them. Our automated opensourcing tools use this as a signal to do +// appropriate munging for windows, which needs to add GFLAGS_DLL_DECL. +// +#define GFLAGS_DLL_DECL /* rewritten to be non-empty in windows dir */ + namespace google { -void HandleCommandLineCompletions(void); +extern void HandleCommandLineCompletions(void); } -#endif // GOOGLE_GFLAGS_COMPLETIONS_H_ +#endif // BASE_COMMANDLINEFLAGS_COMPLETIONS_H_ diff --git a/extern/libmv/third_party/gflags/gflags/gflags_declare.h b/extern/libmv/third_party/gflags/gflags/gflags_declare.h new file mode 100644 index 00000000000..e3013826d53 --- /dev/null +++ b/extern/libmv/third_party/gflags/gflags/gflags_declare.h @@ -0,0 +1,112 @@ +// Copyright (c) 1999, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// --- +// +// Revamped and reorganized by Craig Silverstein +// +// This is the file that should be included by any file which declares +// command line flag. + +#ifndef BASE_COMMANDLINEFLAGS_DECLARE_H_ +#define BASE_COMMANDLINEFLAGS_DECLARE_H_ + +#include +#if 1 +#include // the normal place uint16_t is defined +#endif +#if 1 +#include // the normal place u_int16_t is defined +#endif +#if 1 +#include // a third place for uint16_t or u_int16_t +#endif + +namespace google { +#if 1 // the C99 format +typedef int32_t int32; +typedef uint32_t uint32; +typedef int64_t int64; +typedef uint64_t uint64; +#elif 1 // the BSD format +typedef int32_t int32; +typedef u_int32_t uint32; +typedef int64_t int64; +typedef u_int64_t uint64; +#elif 0 // the windows (vc7) format +typedef __int32 int32; +typedef unsigned __int32 uint32; +typedef __int64 int64; +typedef unsigned __int64 uint64; +#else +#error Do not know how to define a 32-bit integer quantity on your system +#endif +} + + +#define GFLAGS_DLL_DECLARE_FLAG /* rewritten to be non-empty in windows dir */ + +namespace fLS { + +// The meaning of "string" might be different between now and when the +// macros below get invoked (e.g., if someone is experimenting with +// other string implementations that get defined after this file is +// included). Save the current meaning now and use it in the macros. +typedef std::string clstring; + +} + +#define DECLARE_VARIABLE(type, shorttype, name) \ + /* We always want to import declared variables, dll or no */ \ + namespace fL##shorttype { extern GFLAGS_DLL_DECLARE_FLAG type FLAGS_##name; } \ + using fL##shorttype::FLAGS_##name + +#define DECLARE_bool(name) \ + DECLARE_VARIABLE(bool, B, name) + +#define DECLARE_int32(name) \ + DECLARE_VARIABLE(::google::int32, I, name) + +#define DECLARE_int64(name) \ + DECLARE_VARIABLE(::google::int64, I64, name) + +#define DECLARE_uint64(name) \ + DECLARE_VARIABLE(::google::uint64, U64, name) + +#define DECLARE_double(name) \ + DECLARE_VARIABLE(double, D, name) + +#define DECLARE_string(name) \ + namespace fLS { \ + using ::fLS::clstring; \ + extern GFLAGS_DLL_DECLARE_FLAG ::fLS::clstring& FLAGS_##name; \ + } \ + using fLS::FLAGS_##name + +#endif // BASE_COMMANDLINEFLAGS_DECLARE_H_ diff --git a/extern/libmv/third_party/gflags/gflags_completions.cc b/extern/libmv/third_party/gflags/gflags_completions.cc index a129611d8a1..75e9236ef63 100644 --- a/extern/libmv/third_party/gflags/gflags_completions.cc +++ b/extern/libmv/third_party/gflags/gflags_completions.cc @@ -28,8 +28,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // --- -// Author: Dave Nicponski -// + // Bash-style command line flag completion for C++ binaries // // This module implements bash-style completions. It achieves this @@ -58,7 +57,12 @@ #include #include -#include "gflags.h" +#include "gflags/gflags.h" +#include "util.h" + +using std::set; +using std::string; +using std::vector; #ifndef PATH_SEPARATOR #define PATH_SEPARATOR '/' @@ -74,11 +78,6 @@ DEFINE_int32(tab_completion_columns, 80, _START_GOOGLE_NAMESPACE_ namespace { - -using std::set; -using std::string; -using std::vector; - // Function prototypes and Type forward declarations. Code may be // more easily understood if it is roughly ordered according to // control flow, rather than by C's "declare before use" ordering @@ -210,12 +209,12 @@ static void PrintFlagCompletionInfo(void) { &canonical_token, &options); - //VLOG(1) << "Identified canonical_token: '" << canonical_token << "'"; + DVLOG(1) << "Identified canonical_token: '" << canonical_token << "'"; vector all_flags; set matching_flags; GetAllFlags(&all_flags); - //VLOG(2) << "Found " << all_flags.size() << " flags overall"; + DVLOG(2) << "Found " << all_flags.size() << " flags overall"; string longest_common_prefix; FindMatchingFlags( @@ -224,28 +223,28 @@ static void PrintFlagCompletionInfo(void) { canonical_token, &matching_flags, &longest_common_prefix); - //VLOG(1) << "Identified " << matching_flags.size() << " matching flags"; - //VLOG(1) << "Identified " << longest_common_prefix - // << " as longest common prefix."; + DVLOG(1) << "Identified " << matching_flags.size() << " matching flags"; + DVLOG(1) << "Identified " << longest_common_prefix + << " as longest common prefix."; if (longest_common_prefix.size() > canonical_token.size()) { // There's actually a shared common prefix to all matching flags, // so may as well output that and quit quickly. - //VLOG(1) << "The common prefix '" << longest_common_prefix - // << "' was longer than the token '" << canonical_token - // << "'. Returning just this prefix for completion."; + DVLOG(1) << "The common prefix '" << longest_common_prefix + << "' was longer than the token '" << canonical_token + << "'. Returning just this prefix for completion."; fprintf(stdout, "--%s", longest_common_prefix.c_str()); return; } if (matching_flags.empty()) { - //VLOG(1) << "There were no matching flags, returning nothing."; + VLOG(1) << "There were no matching flags, returning nothing."; return; } string module; string package_dir; TryFindModuleAndPackageDir(all_flags, &module, &package_dir); - //VLOG(1) << "Identified module: '" << module << "'"; - //VLOG(1) << "Identified package_dir: '" << package_dir << "'"; + DVLOG(1) << "Identified module: '" << module << "'"; + DVLOG(1) << "Identified package_dir: '" << package_dir << "'"; NotableFlags notable_flags; CategorizeAllMatchingFlags( @@ -254,12 +253,12 @@ static void PrintFlagCompletionInfo(void) { module, package_dir, ¬able_flags); - //VLOG(2) << "Categorized matching flags:"; - //VLOG(2) << " perfect_match: " << notable_flags.perfect_match_flag.size(); - //VLOG(2) << " module: " << notable_flags.module_flags.size(); - //VLOG(2) << " package: " << notable_flags.package_flags.size(); - //VLOG(2) << " most common: " << notable_flags.most_common_flags.size(); - //VLOG(2) << " subpackage: " << notable_flags.subpackage_flags.size(); + DVLOG(2) << "Categorized matching flags:"; + DVLOG(2) << " perfect_match: " << notable_flags.perfect_match_flag.size(); + DVLOG(2) << " module: " << notable_flags.module_flags.size(); + DVLOG(2) << " package: " << notable_flags.package_flags.size(); + DVLOG(2) << " most common: " << notable_flags.most_common_flags.size(); + DVLOG(2) << " subpackage: " << notable_flags.subpackage_flags.size(); vector completions; FinalizeCompletionOutput( @@ -271,13 +270,13 @@ static void PrintFlagCompletionInfo(void) { if (options.force_no_update) completions.push_back("~"); - //VLOG(1) << "Finalized with " << completions.size() - // << " chosen completions"; + DVLOG(1) << "Finalized with " << completions.size() + << " chosen completions"; for (vector::const_iterator it = completions.begin(); it != completions.end(); ++it) { - //VLOG(9) << " Completion entry: '" << *it << "'"; + DVLOG(9) << " Completion entry: '" << *it << "'"; fprintf(stdout, "%s\n", it->c_str()); } } @@ -397,7 +396,7 @@ static bool DoesSingleFlagMatch( flag.filename.find(match_token) != string::npos) return true; - // TODO(daven): All searches should probably be case-insensitive + // TODO(user): All searches should probably be case-insensitive // (especially this one...) if (options.flag_description_substring_search && flag.description.find(match_token) != string::npos) @@ -426,8 +425,8 @@ static void CategorizeAllMatchingFlags( all_matches.begin(); it != all_matches.end(); ++it) { - //VLOG(2) << "Examining match '" << (*it)->name << "'"; - //VLOG(7) << " filename: '" << (*it)->filename << "'"; + DVLOG(2) << "Examining match '" << (*it)->name << "'"; + DVLOG(7) << " filename: '" << (*it)->filename << "'"; string::size_type pos = string::npos; if (!package_dir.empty()) pos = (*it)->filename.find(package_dir); @@ -440,36 +439,34 @@ static void CategorizeAllMatchingFlags( if ((*it)->name == search_token) { // Exact match on some flag's name notable_flags->perfect_match_flag.insert(*it); - //VLOG(3) << "Result: perfect match"; + DVLOG(3) << "Result: perfect match"; } else if (!module.empty() && (*it)->filename == module) { // Exact match on module filename notable_flags->module_flags.insert(*it); - //VLOG(3) << "Result: module match"; + DVLOG(3) << "Result: module match"; } else if (!package_dir.empty() && pos != string::npos && slash == string::npos) { // In the package, since there was no slash after the package portion notable_flags->package_flags.insert(*it); - //VLOG(3) << "Result: package match"; + DVLOG(3) << "Result: package match"; } else if (false) { // In the list of the XXX most commonly supplied flags overall - // TODO(daven): Compile this list. - //VLOG(3) << "Result: most-common match"; + // TODO(user): Compile this list. + DVLOG(3) << "Result: most-common match"; } else if (!package_dir.empty() && pos != string::npos && slash != string::npos) { // In a subdirectory of the package notable_flags->subpackage_flags.insert(*it); - //VLOG(3) << "Result: subpackage match"; + DVLOG(3) << "Result: subpackage match"; } - //VLOG(3) << "Result: not special match"; + DVLOG(3) << "Result: not special match"; } } static void PushNameWithSuffix(vector* suffixes, const char* suffix) { - string s("/"); - s += ProgramInvocationShortName(); - s += suffix; - suffixes->push_back(s); + suffixes->push_back( + StringPrintf("/%s%s", ProgramInvocationShortName(), suffix)); } static void TryFindModuleAndPackageDir( @@ -480,7 +477,7 @@ static void TryFindModuleAndPackageDir( package_dir->clear(); vector suffixes; - // TODO(daven): There's some inherant ambiguity here - multiple directories + // TODO(user): There's some inherant ambiguity here - multiple directories // could share the same trailing folder and file structure (and even worse, // same file names), causing us to be unsure as to which of the two is the // actual package for this binary. In this case, we'll arbitrarily choose. @@ -499,7 +496,7 @@ static void TryFindModuleAndPackageDir( for (vector::const_iterator suffix = suffixes.begin(); suffix != suffixes.end(); ++suffix) { - // TODO(daven): Make sure the match is near the end of the string + // TODO(user): Make sure the match is near the end of the string if (it->filename.find(*suffix) != string::npos) { *module = it->filename; string::size_type sep = it->filename.rfind(PATH_SEPARATOR); @@ -696,12 +693,14 @@ static void OutputSingleGroupWithLimit( static string GetShortFlagLine( const string &line_indentation, const CommandLineFlagInfo &info) { - string prefix = - line_indentation + "--" + info.name + " [" + - (info.type == "string" ? - ("'" + info.default_value + "'") : - info.default_value) - + "] "; + string prefix; + bool is_string = (info.type == "string"); + SStringPrintf(&prefix, "%s--%s [%s%s%s] ", + line_indentation.c_str(), + info.name.c_str(), + (is_string ? "'" : ""), + info.default_value.c_str(), + (is_string ? "'" : "")); int remainder = FLAGS_tab_completion_columns - static_cast(prefix.size()); string suffix; @@ -731,8 +730,12 @@ static string GetLongFlagLine( static const char kNewlineWithIndent[] = "\n "; output.replace(output.find(" type:"), 1, string(kNewlineWithIndent)); output.replace(output.find(" default:"), 1, string(kNewlineWithIndent)); - output = line_indentation + " Details for '--" + info.name + "':\n" + - output + " defined: " + info.filename; + output = StringPrintf("%s Details for '--%s':\n" + "%s defined: %s", + line_indentation.c_str(), + info.name.c_str(), + output.c_str(), + info.filename.c_str()); // Eliminate any doubled newlines that crept in. Specifically, if // DescribeOneFlag() decided to break the line just before "type" @@ -759,7 +762,7 @@ static string GetLongFlagLine( void HandleCommandLineCompletions(void) { if (FLAGS_tab_completion_word.empty()) return; PrintFlagCompletionInfo(); - exit(0); + gflags_exitfunc(0); } _END_GOOGLE_NAMESPACE_ diff --git a/extern/libmv/third_party/gflags/gflags_reporting.cc b/extern/libmv/third_party/gflags/gflags_reporting.cc index fa3024d974e..c74bcc8d762 100644 --- a/extern/libmv/third_party/gflags/gflags_reporting.cc +++ b/extern/libmv/third_party/gflags/gflags_reporting.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006, Google Inc. +// Copyright (c) 1999, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -28,7 +28,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // --- -// Author: Ray Sidney +// // Revamped and reorganized by Craig Silverstein // // This file contains code for handling the 'reporting' flags. These @@ -40,7 +40,7 @@ // HandleCommandLineHelpFlags(). (Well, actually, ShowUsageWithFlags(), // ShowUsageWithFlagsRestrict(), and DescribeOneFlag() can be called // externally too, but there's little need for it.) These are all -// declared in the main commandlineflags.h header file. +// declared in the main gflags.h header file. // // HandleCommandLineHelpFlags() will check what 'reporting' flags have // been defined, if any -- the "help" part of the function name is a @@ -55,14 +55,15 @@ #include #include #include -#include "gflags.h" -#include "gflags_completions.h" +#include "gflags/gflags.h" +#include "gflags/gflags_completions.h" +#include "util.h" #ifndef PATH_SEPARATOR #define PATH_SEPARATOR '/' #endif -// The 'reporting' flags. They all call exit(). +// The 'reporting' flags. They all call gflags_exitfunc(). DEFINE_bool(help, false, "show help on all flags [tip: all flags can have two dashes]"); DEFINE_bool(helpfull, false, @@ -85,11 +86,12 @@ _START_GOOGLE_NAMESPACE_ using std::string; using std::vector; + // -------------------------------------------------------------------- // DescribeOneFlag() // DescribeOneFlagInXML() // Routines that pretty-print info about a flag. These use -// a CommandLineFlagInfo, which is the way the commandlineflags +// a CommandLineFlagInfo, which is the way the gflags // API exposes static info about a flag. // -------------------------------------------------------------------- @@ -114,17 +116,19 @@ static string PrintStringFlagsWithQuotes(const CommandLineFlagInfo& flag, const char* c_string = (current ? flag.current_value.c_str() : flag.default_value.c_str()); if (strcmp(flag.type.c_str(), "string") == 0) { // add quotes for strings - return text + ": \"" + c_string + "\""; + return StringPrintf("%s: \"%s\"", text.c_str(), c_string); } else { - return text + ": " + c_string; + return StringPrintf("%s: %s", text.c_str(), c_string); } } // Create a descriptive string for a flag. // Goes to some trouble to make pretty line breaks. string DescribeOneFlag(const CommandLineFlagInfo& flag) { - string main_part = (string(" -") + flag.name + - " (" + flag.description + ')'); + string main_part; + SStringPrintf(&main_part, " -%s (%s)", + flag.name.c_str(), + flag.description.c_str()); const char* c_string = main_part.c_str(); int chars_left = static_cast(main_part.length()); string final_string = ""; @@ -164,7 +168,7 @@ string DescribeOneFlag(const CommandLineFlagInfo& flag) { } if (*c_string == '\0') break; - final_string += "\n "; + StringAppendF(&final_string, "\n "); chars_in_line = 6; } @@ -173,7 +177,7 @@ string DescribeOneFlag(const CommandLineFlagInfo& flag) { // The listed default value will be the actual default from the flag // definition in the originating source file, unless the value has // subsequently been modified using SetCommandLineOptionWithMode() with mode - // SET_FLAGS_DEFAULT, or by setting FLAGS_foo = bar before initializing. + // SET_FLAGS_DEFAULT, or by setting FLAGS_foo = bar before ParseCommandLineFlags(). AddString(PrintStringFlagsWithQuotes(flag, "default", false), &final_string, &chars_in_line); if (!flag.is_default) { @@ -181,7 +185,7 @@ string DescribeOneFlag(const CommandLineFlagInfo& flag) { &final_string, &chars_in_line); } - final_string += '\n'; + StringAppendF(&final_string, "\n"); return final_string; } @@ -196,15 +200,10 @@ static string XMLText(const string& txt) { } static void AddXMLTag(string* r, const char* tag, const string& txt) { - *r += ('<'); - *r += (tag); - *r += ('>'); - *r += (XMLText(txt)); - *r += ("'); + StringAppendF(r, "<%s>%s", tag, XMLText(txt).c_str(), tag); } + static string DescribeOneFlagInXML(const CommandLineFlagInfo& flag) { // The file and flagname could have been attributes, but default // and meaning need to avoid attribute normalization. This way it @@ -265,9 +264,9 @@ static bool FileMatchesSubstring(const string& filename, // Show help for every filename which matches any of the target substrings. // If substrings is empty, shows help for every file. If a flag's help message -// has been stripped (e.g. by adding '#define STRIP_FLAG_HELP 1' before -// including gflags/gflags.h), then this flag will not be displayed by -// '--help' and its variants. +// has been stripped (e.g. by adding '#define STRIP_FLAG_HELP 1' +// before including gflags/gflags.h), then this flag will not be displayed +// by '--help' and its variants. static void ShowUsageWithFlagsMatching(const char *argv0, const vector &substrings) { fprintf(stdout, "%s: %s\n", Basename(argv0), ProgramUsage()); @@ -347,10 +346,13 @@ static void ShowXMLOfFlags(const char *prog_name) { // -------------------------------------------------------------------- static void ShowVersion() { - fprintf(stdout, "%s\n", ProgramInvocationShortName()); - // TODO: add other stuff, like a timestamp, who built it, what - // target they built, etc. - + const char* version_string = VersionString(); + if (version_string && *version_string) { + fprintf(stdout, "%s version %s\n", + ProgramInvocationShortName(), version_string); + } else { + fprintf(stdout, "%s\n", ProgramInvocationShortName()); + } # if !defined(NDEBUG) fprintf(stdout, "Debug build (NDEBUG not #defined)\n"); # endif @@ -375,7 +377,6 @@ static void AppendPrognameStrings(vector* substrings, void HandleCommandLineHelpFlags() { const char* progname = ProgramInvocationShortName(); - extern void (*commandlineflags_exitfunc)(int); // in gflags.cc HandleCommandLineCompletions(); @@ -386,21 +387,21 @@ void HandleCommandLineHelpFlags() { // show only flags related to this binary: // E.g. for fileutil.cc, want flags containing ... "/fileutil." cc ShowUsageWithFlagsMatching(progname, substrings); - commandlineflags_exitfunc(1); // almost certainly exit() + gflags_exitfunc(1); } else if (FLAGS_help || FLAGS_helpfull) { // show all options ShowUsageWithFlagsRestrict(progname, ""); // empty restrict - commandlineflags_exitfunc(1); + gflags_exitfunc(1); } else if (!FLAGS_helpon.empty()) { string restrict = "/" + FLAGS_helpon + "."; ShowUsageWithFlagsRestrict(progname, restrict.c_str()); - commandlineflags_exitfunc(1); + gflags_exitfunc(1); } else if (!FLAGS_helpmatch.empty()) { ShowUsageWithFlagsRestrict(progname, FLAGS_helpmatch.c_str()); - commandlineflags_exitfunc(1); + gflags_exitfunc(1); } else if (FLAGS_helppackage) { // Shows help for all files in the same directory as main(). We @@ -419,27 +420,27 @@ void HandleCommandLineHelpFlags() { const string package = Dirname(flag->filename) + "/"; if (package != last_package) { ShowUsageWithFlagsRestrict(progname, package.c_str()); + VLOG(7) << "Found package: " << package; if (!last_package.empty()) { // means this isn't our first pkg - fprintf(stderr, "WARNING: Multiple packages contain a file=%s\n", - progname); + LOG(WARNING) << "Multiple packages contain a file=" << progname; } last_package = package; } } if (last_package.empty()) { // never found a package to print - fprintf(stderr, "WARNING: Unable to find a package for file=%s\n", - progname); + LOG(WARNING) << "Unable to find a package for file=" << progname; } - commandlineflags_exitfunc(1); + gflags_exitfunc(1); } else if (FLAGS_helpxml) { ShowXMLOfFlags(progname); - commandlineflags_exitfunc(1); + gflags_exitfunc(1); } else if (FLAGS_version) { ShowVersion(); // Unlike help, we may be asking for version in a script, so return 0 - commandlineflags_exitfunc(0); + gflags_exitfunc(0); + } } diff --git a/extern/libmv/third_party/gflags/mutex.h b/extern/libmv/third_party/gflags/mutex.h index 6e1e8976b6d..7c3c060a043 100644 --- a/extern/libmv/third_party/gflags/mutex.h +++ b/extern/libmv/third_party/gflags/mutex.h @@ -28,7 +28,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // --- -// Author: Craig Silverstein. // // A simple mutex wrapper, supporting locks and read-write locks. // You should assume the locks are *not* re-entrant. @@ -117,7 +116,12 @@ #if defined(NO_THREADS) typedef int MutexType; // to keep a lock-count #elif defined(_WIN32) || defined(__CYGWIN32__) || defined(__CYGWIN64__) -# define WIN32_LEAN_AND_MEAN // We only need minimal includes +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN // We only need minimal includes +# endif +# ifndef NOMINMAX +# define NOMINMAX // Don't want windows to override min()/max() +# endif # ifdef GMUTEX_TRYLOCK // We need Windows NT or later for TryEnterCriticalSection(). If you // don't need that functionality, you can remove these _WIN32_WINNT @@ -134,7 +138,10 @@ // *does* cause problems for FreeBSD, or MacOSX, but isn't needed // for locking there.) # ifdef __linux__ -# define _XOPEN_SOURCE 500 // may be needed to get the rwlock calls +# if _XOPEN_SOURCE < 500 // including not being defined at all +# undef _XOPEN_SOURCE +# define _XOPEN_SOURCE 500 // may be needed to get the rwlock calls +# endif # endif # include typedef pthread_rwlock_t MutexType; diff --git a/extern/libmv/third_party/gflags/util.h b/extern/libmv/third_party/gflags/util.h new file mode 100644 index 00000000000..8e2b1b89525 --- /dev/null +++ b/extern/libmv/third_party/gflags/util.h @@ -0,0 +1,339 @@ +// Copyright (c) 2011, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// --- +// +// Some generically useful utility routines that in google-land would +// be their own projects. We make a shortened version here. + +#ifndef GFLAGS_UTIL_H_ +#define GFLAGS_UTIL_H_ + +#include +#include "config.h" +#ifdef HAVE_INTTYPES_H +# include +#endif +#include // for va_* +#include +#include +#include +#include +#ifdef HAVE_SYS_STAT_H +# include +#endif // for mkdir() + +_START_GOOGLE_NAMESPACE_ + +// This is used for unittests for death-testing. It is defined in gflags.cc. +extern GFLAGS_DLL_DECL void (*gflags_exitfunc)(int); + +// Work properly if either strtoll or strtoq is on this system +#ifdef HAVE_STRTOLL +# define strto64 strtoll +# define strtou64 strtoull +#elif HAVE_STRTOQ +# define strto64 strtoq +# define strtou64 strtouq +#else +// Neither strtoll nor strtoq are defined. I hope strtol works! +# define strto64 strtol +# define strtou64 strtoul +#endif + +// If we have inttypes.h, it will have defined PRId32/etc for us. If +// not, take our best guess. +#ifndef PRId32 +# define PRId32 "d" +#endif +#ifndef PRId64 +# define PRId64 "lld" +#endif +#ifndef PRIu64 +# define PRIu64 "llu" +#endif + +typedef signed char int8; +typedef unsigned char uint8; + +// -- utility macros --------------------------------------------------------- + +template struct CompileAssert {}; +#define COMPILE_ASSERT(expr, msg) \ + typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] + +// Returns the number of elements in an array. +#define arraysize(arr) (sizeof(arr)/sizeof(*(arr))) + + +// -- logging and testing --------------------------------------------------- + +// For now, we ignore the level for logging, and don't show *VLOG's at +// all, except by hand-editing the lines below +#define LOG(level) std::cerr +#define VLOG(level) if (true) {} else std::cerr +#define DVLOG(level) if (true) {} else std::cerr + +// CHECK dies with a fatal error if condition is not true. It is *not* +// controlled by NDEBUG, so the check will be executed regardless of +// compilation mode. Therefore, it is safe to do things like: +// CHECK(fp->Write(x) == 4) +// We allow stream-like objects after this for debugging, but they're ignored. +#define EXPECT_TRUE(condition) \ + if (true) { \ + if (!(condition)) { \ + fprintf(stderr, "Check failed: %s\n", #condition); \ + exit(1); \ + } \ + } else std::cerr << "" + +#define EXPECT_OP(op, val1, val2) \ + if (true) { \ + if (!((val1) op (val2))) { \ + fprintf(stderr, "Check failed: %s %s %s\n", #val1, #op, #val2); \ + exit(1); \ + } \ + } else std::cerr << "" + +#define EXPECT_EQ(val1, val2) EXPECT_OP(==, val1, val2) +#define EXPECT_NE(val1, val2) EXPECT_OP(!=, val1, val2) +#define EXPECT_LE(val1, val2) EXPECT_OP(<=, val1, val2) +#define EXPECT_LT(val1, val2) EXPECT_OP(< , val1, val2) +#define EXPECT_GE(val1, val2) EXPECT_OP(>=, val1, val2) +#define EXPECT_GT(val1, val2) EXPECT_OP(> , val1, val2) +#define EXPECT_FALSE(cond) EXPECT_TRUE(!(cond)) + +// C99 declares isnan and isinf should be macros, so the #ifdef test +// should be reliable everywhere. Of course, it's not, but these +// are testing pertty marginal functionality anyway, so it's ok to +// not-run them even in situations they might, with effort, be made to work. +#ifdef isnan // Some compilers, like sun's for Solaris 10, don't define this +#define EXPECT_NAN(arg) \ + do { \ + if (!isnan(arg)) { \ + fprintf(stderr, "Check failed: isnan(%s)\n", #arg); \ + exit(1); \ + } \ + } while (0) +#else +#define EXPECT_NAN(arg) +#endif + +#ifdef isinf // Some compilers, like sun's for Solaris 10, don't define this +#define EXPECT_INF(arg) \ + do { \ + if (!isinf(arg)) { \ + fprintf(stderr, "Check failed: isinf(%s)\n", #arg); \ + exit(1); \ + } \ + } while (0) +#else +#define EXPECT_INF(arg) +#endif + +#define EXPECT_DOUBLE_EQ(val1, val2) \ + do { \ + if (((val1) < (val2) - 0.001 || (val1) > (val2) + 0.001)) { \ + fprintf(stderr, "Check failed: %s == %s\n", #val1, #val2); \ + exit(1); \ + } \ + } while (0) + +#define EXPECT_STREQ(val1, val2) \ + do { \ + if (strcmp((val1), (val2)) != 0) { \ + fprintf(stderr, "Check failed: streq(%s, %s)\n", #val1, #val2); \ + exit(1); \ + } \ + } while (0) + +// Call this in a .cc file where you will later call RUN_ALL_TESTS in main(). +#define TEST_INIT \ + static std::vector g_testlist; /* the tests to run */ \ + static int RUN_ALL_TESTS() { \ + std::vector::const_iterator it; \ + for (it = g_testlist.begin(); it != g_testlist.end(); ++it) { \ + (*it)(); /* The test will error-exit if there's a problem. */ \ + } \ + fprintf(stderr, "\nPassed %d tests\n\nPASS\n", \ + static_cast(g_testlist.size())); \ + return 0; \ + } + +// Note that this macro uses a FlagSaver to keep tests isolated. +#define TEST(a, b) \ + struct Test_##a##_##b { \ + Test_##a##_##b() { g_testlist.push_back(&Run); } \ + static void Run() { \ + FlagSaver fs; \ + fprintf(stderr, "Running test %s/%s\n", #a, #b); \ + RunTest(); \ + } \ + static void RunTest(); \ + }; \ + static Test_##a##_##b g_test_##a##_##b; \ + void Test_##a##_##b::RunTest() + +// This is a dummy class that eases the google->opensource transition. +namespace testing { +class Test {}; +} + +// Call this in a .cc file where you will later call EXPECT_DEATH +#define EXPECT_DEATH_INIT \ + static bool g_called_exit; \ + static void CalledExit(int) { g_called_exit = true; } + +#define EXPECT_DEATH(fn, msg) \ + do { \ + g_called_exit = false; \ + gflags_exitfunc = &CalledExit; \ + fn; \ + gflags_exitfunc = &exit; /* set back to its default */ \ + if (!g_called_exit) { \ + fprintf(stderr, "Function didn't die (%s): %s\n", msg, #fn); \ + exit(1); \ + } \ + } while (0) + +#define GTEST_HAS_DEATH_TEST 1 + +// -- path routines ---------------------------------------------------------- + +// Tries to create the directory path as a temp-dir. If it fails, +// changes path to some directory it *can* create. +#if defined(__MINGW32__) +#include +inline void MakeTmpdir(std::string* path) { + // I had trouble creating a directory in /tmp from mingw + *path = "./gflags_unittest_testdir"; + mkdir(path->c_str()); // mingw has a weird one-arg mkdir +} +#elif defined(_MSC_VER) +#include +#include +inline void MakeTmpdir(std::string* path) { + char tmppath_buffer[1024]; + int tmppath_len = GetTempPathA(sizeof(tmppath_buffer), tmppath_buffer); + assert(tmppath_len > 0 && tmppath_len < sizeof(tmppath_buffer)); + assert(tmppath_buffer[tmppath_len - 1] == '\\'); // API guarantees it + *path = std::string(tmppath_buffer) + "gflags_unittest_testdir"; + _mkdir(path->c_str()); +} +// Windows is missing random bits like strcasecmp, strtoll, strtoull, and +// snprintf in the usual locations. Put them somewhere sensible. +// +// TODO(keir): Get the upstream Windows port and use that instead. +#define snprintf _snprintf +#undef strtoint64 +#define strtoint64 _strtoi64 +#undef strtouint64 +#define strtouint64 _strtoui64 +#define strcasecmp _stricmp +#define va_copy(dst, src) ((dst) = (src)) +#define strto64 _strtoi64 +#define strtou64 _strtoui64 +#else +inline void MakeTmpdir(std::string* path) { + mkdir(path->c_str(), 0755); +} +#endif + +// -- string routines -------------------------------------------------------- + +inline void InternalStringPrintf(std::string* output, const char* format, + va_list ap) { + char space[128]; // try a small buffer and hope it fits + + // It's possible for methods that use a va_list to invalidate + // the data in it upon use. The fix is to make a copy + // of the structure before using it and use that copy instead. + va_list backup_ap; + va_copy(backup_ap, ap); + int bytes_written = vsnprintf(space, sizeof(space), format, backup_ap); + va_end(backup_ap); + + if ((bytes_written >= 0) && (bytes_written < sizeof(space))) { + output->append(space, bytes_written); + return; + } + + // Repeatedly increase buffer size until it fits. + int length = sizeof(space); + while (true) { + if (bytes_written < 0) { + // Older snprintf() behavior. :-( Just try doubling the buffer size + length *= 2; + } else { + // We need exactly "bytes_written+1" characters + length = bytes_written+1; + } + char* buf = new char[length]; + + // Restore the va_list before we use it again + va_copy(backup_ap, ap); + bytes_written = vsnprintf(buf, length, format, backup_ap); + va_end(backup_ap); + + if ((bytes_written >= 0) && (bytes_written < length)) { + output->append(buf, bytes_written); + delete[] buf; + return; + } + delete[] buf; + } +} + +// Clears output before writing to it. +inline void SStringPrintf(std::string* output, const char* format, ...) { + va_list ap; + va_start(ap, format); + output->clear(); + InternalStringPrintf(output, format, ap); + va_end(ap); +} + +inline void StringAppendF(std::string* output, const char* format, ...) { + va_list ap; + va_start(ap, format); + InternalStringPrintf(output, format, ap); + va_end(ap); +} + +inline std::string StringPrintf(const char* format, ...) { + va_list ap; + va_start(ap, format); + std::string output; + InternalStringPrintf(&output, format, ap); + va_end(ap); + return output; +} + +_END_GOOGLE_NAMESPACE_ + +#endif // GFLAGS_UTIL_H_ diff --git a/extern/libmv/third_party/glog/ChangeLog b/extern/libmv/third_party/glog/ChangeLog index 350fee921e3..6ac0b0f0575 100644 --- a/extern/libmv/third_party/glog/ChangeLog +++ b/extern/libmv/third_party/glog/ChangeLog @@ -1,3 +1,13 @@ +2012-01-12 Google Inc. + + * google-glog: version 0.3.2 + * Clang support. + * Demangler and stacktrace improvement for newer GCCs. + * Now fork(2) doesn't mess up log files. + * Make valgrind happier. + * Reduce warnings for more -W options. + * Provide a workaround for ERROR defined by windows.h. + 2010-06-15 Google Inc. * google-glog: version 0.3.1 diff --git a/extern/libmv/third_party/glog/README.libmv b/extern/libmv/third_party/glog/README.libmv index 8f1243b2430..025a70b76a5 100644 --- a/extern/libmv/third_party/glog/README.libmv +++ b/extern/libmv/third_party/glog/README.libmv @@ -1,38 +1,24 @@ Project: Google Logging URL: http://code.google.com/p/google-glog/ License: New BSD -Upstream version: 0.3.1 +Upstream version: 0.3.2 Local modifications: Upgrading Notes -* Had to change #include to #include "gflags/gflags.h" -* Make sure to copy over a config_YOUR_PLATFORM.h and put it in config.h - -Old changes which got obsoleted (maybe?) by 0.3.1 merge: -* The config_linux.h is generated by configure on Keir's Ubuntu 9.04 desktop. -* Commented out some struct ::tm weirdness causing compile failures on - ubuntu 8.10 and 9.04. -* Switched several initializers to memset instead of = {}. -* Changed some includes pointing to gflags. Not sure why the regular inclusion - didn't work. -* Added some compile flags to silence various warnings, allowing us to keep the - differences between upstream small. -* Don't redefine _XOPEN_SOURCE. -* Added "google::" to GetReferenceableValue in CHECK_OP_LOG. -* Add virtual destructor to Thread in googletest.h. -* Update windows/glog/log_severity to build with QT library that include WinGDI - (It cause a double definition of ERROR variable). - -Old changes which got obsoleted (maybe?) by 0.2.1 merge: -* Added #ifndef / def REG_EIP; not sure what that is. -* Added (void) arg stuff to prevent unused variable warnings. -* Added google:: namespace prefix to GetReferencableValue -* Added assignments for several functions marked with no_ignore_return, where - the return value was ignored. -* Commented out the unused function DumpPCAndSymbol() in utilities.cc to silent - gcc on the mac - -TODO(keir): Remove any obsoleted changes above if they are not necessary after -testing on more platforms. - -WARNING: Mac port not updated for 0.2.1 +* Replace with "third_party/gflags/gflags/gflags.h" which is easier + to setup things in libmv and also helps with setting up building libmv into + external applications. +* Replace "glog/logging.h" and "glog/logging.h" with and + which is needed on Windows platform because otherwise files like logging.cc will be using + relative path which points to headers used by linux instead of headers need to be used + on Windows. +* Replace _asm int 3 with __debugbreak(). Such assembler code is obsolete and doesn't work + with 64bit versions of MSVC compilers. +* Do not use stacktrace for MinGW and FreeBSD because it leads into issues accessing + some specific data on this platforms. +* Define HAVE_LIB_GFLAGS for Windows builds. +* Do not define __declspec(dllimport) for MinGW platforms. +* Setup proper includes and datatypes for int32, uint32, int64 and uint64 for MinGW +* Do not define va_copy for MinGW platforms (it's already defined there). +* Patch localtime_r to be working fine with MinGW, disable strerror_r for MinGW because + of lack of needed functions. diff --git a/extern/libmv/third_party/glog/src/base/commandlineflags.h b/extern/libmv/third_party/glog/src/base/commandlineflags.h index 6c529ccd847..483a96ee80b 100644 --- a/extern/libmv/third_party/glog/src/base/commandlineflags.h +++ b/extern/libmv/third_party/glog/src/base/commandlineflags.h @@ -55,11 +55,11 @@ #ifdef HAVE_LIB_GFLAGS -#include "third_party/gflags/gflags.h" +#include "third_party/gflags/gflags/gflags.h" #else -#include "glog/logging.h" +#include #define DECLARE_VARIABLE(type, name, tn) \ namespace FLAG__namespace_do_not_use_directly_use_DECLARE_##tn##_instead { \ diff --git a/extern/libmv/third_party/glog/src/base/googleinit.h b/extern/libmv/third_party/glog/src/base/googleinit.h index c907308e852..5a8b515cd60 100644 --- a/extern/libmv/third_party/glog/src/base/googleinit.h +++ b/extern/libmv/third_party/glog/src/base/googleinit.h @@ -36,7 +36,7 @@ class GoogleInitializer { public: typedef void (*void_function)(void); - GoogleInitializer(const char* name, void_function f) { + GoogleInitializer(const char*, void_function f) { f(); } }; diff --git a/extern/libmv/third_party/glog/src/config_freebsd.h b/extern/libmv/third_party/glog/src/config_freebsd.h index 28fa1f1c78b..a671a0080b3 100644 --- a/extern/libmv/third_party/glog/src/config_freebsd.h +++ b/extern/libmv/third_party/glog/src/config_freebsd.h @@ -122,13 +122,13 @@ #define PACKAGE_NAME "glog" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "glog 0.3.1" +#define PACKAGE_STRING "glog 0.3.2" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "glog" /* Define to the version of this package. */ -#define PACKAGE_VERSION "0.3.1" +#define PACKAGE_VERSION "0.3.2" /* How to access the PC from a struct ucontext */ /* #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP] */ @@ -151,7 +151,7 @@ #define TEST_SRC_DIR "." /* Version number of package */ -#define VERSION "0.3.1" +#define VERSION "0.3.2" /* Stops putting the code inside the Google namespace */ #define _END_GOOGLE_NAMESPACE_ } @@ -159,3 +159,8 @@ /* Puts following code inside the Google namespace */ #define _START_GOOGLE_NAMESPACE_ namespace google { +/* isn't getting defined by configure script when clang compilers are used + and cuases compilation errors in stactrace/unwind modules */ +#ifdef __clang__ +# define NO_FRAME_POINTER +#endif diff --git a/extern/libmv/third_party/glog/src/config_linux.h b/extern/libmv/third_party/glog/src/config_linux.h index faf032949bb..19beaa5cf40 100644 --- a/extern/libmv/third_party/glog/src/config_linux.h +++ b/extern/libmv/third_party/glog/src/config_linux.h @@ -110,7 +110,11 @@ #define HAVE___BUILTIN_EXPECT 1 /* define if your compiler has __sync_val_compare_and_swap */ -/* #undef HAVE___SYNC_VAL_COMPARE_AND_SWAP */ +#define HAVE___SYNC_VAL_COMPARE_AND_SWAP 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" /* Name of package */ #define PACKAGE "glog" @@ -122,22 +126,19 @@ #define PACKAGE_NAME "glog" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "glog 0.3.1" +#define PACKAGE_STRING "glog 0.3.2" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "glog" +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + /* Define to the version of this package. */ -#define PACKAGE_VERSION "0.3.1" +#define PACKAGE_VERSION "0.3.2" /* How to access the PC from a struct ucontext */ -#if defined(_M_X64) || defined(__amd64__) || defined(__x86_64__) - #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP] -#elif defined(_M_IX86) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) - #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_EIP] -#else - #undef PC_FROM_UCONTEXT -#endif +#define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP] /* Define to necessary symbol if this constant uses a non-standard name on your system. */ @@ -149,7 +150,6 @@ /* Define to 1 if you have the ANSI C header files. */ /* #undef STDC_HEADERS */ -#define STDC_HEADERS 1 /* the namespace where STL code like vector<> is defined */ #define STL_NAMESPACE std @@ -157,10 +157,16 @@ #define TEST_SRC_DIR "." /* Version number of package */ -#define VERSION "0.3.1" +#define VERSION "0.3.2" /* Stops putting the code inside the Google namespace */ #define _END_GOOGLE_NAMESPACE_ } /* Puts following code inside the Google namespace */ #define _START_GOOGLE_NAMESPACE_ namespace google { + +/* isn't getting defined by configure script when clang compilers are used + and cuases compilation errors in stactrace/unwind modules */ +#ifdef __clang__ +# define NO_FRAME_POINTER +#endif diff --git a/extern/libmv/third_party/glog/src/config_mac.h b/extern/libmv/third_party/glog/src/config_mac.h index 5f953d17ba9..9756fde22f3 100644 --- a/extern/libmv/third_party/glog/src/config_mac.h +++ b/extern/libmv/third_party/glog/src/config_mac.h @@ -122,13 +122,13 @@ #define PACKAGE_NAME "glog" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "glog 0.3.1" +#define PACKAGE_STRING "glog 0.3.2" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "glog" /* Define to the version of this package. */ -#define PACKAGE_VERSION "0.3.1" +#define PACKAGE_VERSION "0.3.2" /* How to access the PC from a struct ucontext */ #undef PC_FROM_UCONTEXT @@ -150,10 +150,16 @@ #define TEST_SRC_DIR "." /* Version number of package */ -#define VERSION "0.3.1" +#define VERSION "0.3.2" /* Stops putting the code inside the Google namespace */ #define _END_GOOGLE_NAMESPACE_ } /* Puts following code inside the Google namespace */ #define _START_GOOGLE_NAMESPACE_ namespace google { + +/* isn't getting defined by configure script when clang compilers are used + and cuases compilation errors in stactrace/unwind modules */ +#ifdef __clang__ +# define NO_FRAME_POINTER +#endif diff --git a/extern/libmv/third_party/glog/src/demangle.cc b/extern/libmv/third_party/glog/src/demangle.cc index 46556bf3c13..0daf30893b3 100644 --- a/extern/libmv/third_party/glog/src/demangle.cc +++ b/extern/libmv/third_party/glog/src/demangle.cc @@ -28,6 +28,11 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Author: Satoru Takabayashi +// +// For reference check out: +// http://www.codesourcery.com/public/cxx-abi/abi.html#mangling +// +// Note that we only have partial C++0x support yet. #include // for NULL #include "demangle.h" @@ -138,14 +143,12 @@ static const AbbrevPair kSubstitutionList[] = { // State needed for demangling. typedef struct { const char *mangled_cur; // Cursor of mangled name. - const char *mangled_end; // End of mangled name. char *out_cur; // Cursor of output string. const char *out_begin; // Beginning of output string. const char *out_end; // End of output string. const char *prev_name; // For constructors/destructors. int prev_name_length; // For constructors/destructors. - int nest_level; // For nested names. - int number; // Remember the previous number. + short nest_level; // For nested names. bool append; // Append flag. bool overflowed; // True if output gets overflowed. } State; @@ -161,6 +164,16 @@ static size_t StrLen(const char *str) { return len; } +// Returns true if "str" has at least "n" characters remaining. +static bool AtLeastNumCharsRemaining(const char *str, int n) { + for (int i = 0; i < n; ++i) { + if (str == '\0') { + return false; + } + } + return true; +} + // Returns true if "str" has "prefix" as a prefix. static bool StrPrefix(const char *str, const char *prefix) { size_t i = 0; @@ -174,39 +187,33 @@ static bool StrPrefix(const char *str, const char *prefix) { static void InitState(State *state, const char *mangled, char *out, int out_size) { state->mangled_cur = mangled; - state->mangled_end = mangled + StrLen(mangled); state->out_cur = out; state->out_begin = out; state->out_end = out + out_size; state->prev_name = NULL; state->prev_name_length = -1; state->nest_level = -1; - state->number = -1; state->append = true; state->overflowed = false; } -// Calculates the remaining length of the mangled name. -static int RemainingLength(State *state) { - return state->mangled_end - state->mangled_cur; -} - -// Returns true and advances "mangled_cur" if we find "c" at -// "mangled_cur" position. -static bool ParseChar(State *state, const char c) { - if (RemainingLength(state) >= 1 && *state->mangled_cur == c) { +// Returns true and advances "mangled_cur" if we find "one_char_token" +// at "mangled_cur" position. It is assumed that "one_char_token" does +// not contain '\0'. +static bool ParseOneCharToken(State *state, const char one_char_token) { + if (state->mangled_cur[0] == one_char_token) { ++state->mangled_cur; return true; } return false; } -// Returns true and advances "mangled_cur" if we find "two_chars" at -// "mangled_cur" position. -static bool ParseTwoChar(State *state, const char *two_chars) { - if (RemainingLength(state) >= 2 && - state->mangled_cur[0] == two_chars[0] && - state->mangled_cur[1] == two_chars[1]) { +// Returns true and advances "mangled_cur" if we find "two_char_token" +// at "mangled_cur" position. It is assumed that "two_char_token" does +// not contain '\0'. +static bool ParseTwoCharToken(State *state, const char *two_char_token) { + if (state->mangled_cur[0] == two_char_token[0] && + state->mangled_cur[1] == two_char_token[1]) { state->mangled_cur += 2; return true; } @@ -216,13 +223,13 @@ static bool ParseTwoChar(State *state, const char *two_chars) { // Returns true and advances "mangled_cur" if we find any character in // "char_class" at "mangled_cur" position. static bool ParseCharClass(State *state, const char *char_class) { - if (state->mangled_cur == state->mangled_end) { + if (state->mangled_cur == '\0') { return false; } const char *p = char_class; for (; *p != '\0'; ++p) { - if (*state->mangled_cur == *p) { - state->mangled_cur += 1; + if (state->mangled_cur[0] == *p) { + ++state->mangled_cur; return true; } } @@ -230,7 +237,7 @@ static bool ParseCharClass(State *state, const char *char_class) { } // This function is used for handling an optional non-terminal. -static bool Optional(bool status) { +static bool Optional(bool) { return true; } @@ -245,6 +252,16 @@ static bool OneOrMore(ParseFunc parse_func, State *state) { return false; } +// This function is used for handling * syntax. The function +// always returns true and must be followed by a termination token or a +// terminating sequence not handled by parse_func (e.g. +// ParseOneCharToken(state, 'E')). +static bool ZeroOrMore(ParseFunc parse_func, State *state) { + while (parse_func(state)) { + } + return true; +} + // Append "str" at "out_cur". If there is an overflow, "overflowed" // is set to true for later use. The output string is ensured to // always terminate with '\0' as long as there is no overflow. @@ -270,7 +287,37 @@ static bool IsLower(char c) { } static bool IsAlpha(char c) { - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); +} + +static bool IsDigit(char c) { + return c >= '0' && c <= '9'; +} + +// Returns true if "str" is a function clone suffix. These suffixes are used +// by GCC 4.5.x and later versions to indicate functions which have been +// cloned during optimization. We treat any sequence (.+.+)+ as +// a function clone suffix. +static bool IsFunctionCloneSuffix(const char *str) { + size_t i = 0; + while (str[i] != '\0') { + // Consume a single .+.+ sequence. + if (str[i] != '.' || !IsAlpha(str[i + 1])) { + return false; + } + i += 2; + while (IsAlpha(str[i])) { + ++i; + } + if (str[i] != '.' || !IsDigit(str[i + 1])) { + return false; + } + i += 2; + while (IsDigit(str[i])) { + ++i; + } + } + return true; // Consumed everything in "str". } // Append "str" with some tweaks, iff "append" state is true. @@ -309,7 +356,7 @@ static bool EnterNestedName(State *state) { } // This function is used for handling nested names. -static bool LeaveNestedName(State *state, int prev_value) { +static bool LeaveNestedName(State *state, short prev_value) { state->nest_level = prev_value; return true; } @@ -349,11 +396,11 @@ static void MaybeCancelLastSeparator(State *state) { } } -// Returns true if identifier pointed by "mangled_cur" is anonymous -// namespace. -static bool IdentifierIsAnonymousNamespace(State *state) { - const char anon_prefix[] = "_GLOBAL__N_"; - return (state->number > sizeof(anon_prefix) - 1 && // Should be longer. +// Returns true if the identifier of the given length pointed to by +// "mangled_cur" is anonymous namespace. +static bool IdentifierIsAnonymousNamespace(State *state, int length) { + static const char anon_prefix[] = "_GLOBAL__N_"; + return (length > (int)sizeof(anon_prefix) - 1 && // Should be longer. StrPrefix(state->mangled_cur, anon_prefix)); } @@ -368,10 +415,10 @@ static bool ParsePrefix(State *state); static bool ParseUnqualifiedName(State *state); static bool ParseSourceName(State *state); static bool ParseLocalSourceName(State *state); -static bool ParseNumber(State *state); +static bool ParseNumber(State *state, int *number_out); static bool ParseFloatNumber(State *state); static bool ParseSeqId(State *state); -static bool ParseIdentifier(State *state); +static bool ParseIdentifier(State *state, int length); static bool ParseOperatorName(State *state); static bool ParseSpecialName(State *state); static bool ParseCallOffset(State *state); @@ -428,17 +475,7 @@ static bool ParseSubstitution(State *state); // ::= _Z static bool ParseMangledName(State *state) { - if (ParseTwoChar(state, "_Z") && ParseEncoding(state)) { - // Append trailing version suffix if any. - // ex. _Z3foo@@GLIBCXX_3.4 - if (state->mangled_cur < state->mangled_end && - state->mangled_cur[0] == '@') { - MaybeAppend(state, state->mangled_cur); - state->mangled_cur = state->mangled_end; - } - return true; - } - return false; + return ParseTwoCharToken(state, "_Z") && ParseEncoding(state); } // ::= <(function) name> @@ -488,7 +525,7 @@ static bool ParseUnscopedName(State *state) { } State copy = *state; - if (ParseTwoChar(state, "St") && + if (ParseTwoCharToken(state, "St") && MaybeAppend(state, "std::") && ParseUnqualifiedName(state)) { return true; @@ -507,12 +544,12 @@ static bool ParseUnscopedTemplateName(State *state) { // ::= N [] E static bool ParseNestedName(State *state) { State copy = *state; - if (ParseChar(state, 'N') && + if (ParseOneCharToken(state, 'N') && EnterNestedName(state) && Optional(ParseCVQualifiers(state)) && ParsePrefix(state) && LeaveNestedName(state, copy.nest_level) && - ParseChar(state, 'E')) { + ParseOneCharToken(state, 'E')) { return true; } *state = copy; @@ -565,7 +602,8 @@ static bool ParseUnqualifiedName(State *state) { // ::= static bool ParseSourceName(State *state) { State copy = *state; - if (ParseNumber(state) && ParseIdentifier(state)) { + int length = -1; + if (ParseNumber(state, &length) && ParseIdentifier(state, length)) { return true; } *state = copy; @@ -579,7 +617,7 @@ static bool ParseSourceName(State *state) { // http://gcc.gnu.org/viewcvs?view=rev&revision=124467 static bool ParseLocalSourceName(State *state) { State copy = *state; - if (ParseChar(state, 'L') && ParseSourceName(state) && + if (ParseOneCharToken(state, 'L') && ParseSourceName(state) && Optional(ParseDiscriminator(state))) { return true; } @@ -588,15 +626,17 @@ static bool ParseLocalSourceName(State *state) { } // ::= [n] -static bool ParseNumber(State *state) { +// If "number_out" is non-null, then *number_out is set to the value of the +// parsed number on success. +static bool ParseNumber(State *state, int *number_out) { int sign = 1; - if (ParseChar(state, 'n')) { + if (ParseOneCharToken(state, 'n')) { sign = -1; } const char *p = state->mangled_cur; int number = 0; - for (;p < state->mangled_end; ++p) { - if ((*p >= '0' && *p <= '9')) { + for (;*p != '\0'; ++p) { + if (IsDigit(*p)) { number = number * 10 + (*p - '0'); } else { break; @@ -604,7 +644,9 @@ static bool ParseNumber(State *state) { } if (p != state->mangled_cur) { // Conversion succeeded. state->mangled_cur = p; - state->number = number * sign; + if (number_out != NULL) { + *number_out = number * sign; + } return true; } return false; @@ -614,19 +656,13 @@ static bool ParseNumber(State *state) { // hexadecimal string. static bool ParseFloatNumber(State *state) { const char *p = state->mangled_cur; - int number = 0; - for (;p < state->mangled_end; ++p) { - if ((*p >= '0' && *p <= '9')) { - number = number * 16 + (*p - '0'); - } else if (*p >= 'a' && *p <= 'f') { - number = number * 16 + (*p - 'a' + 10); - } else { + for (;*p != '\0'; ++p) { + if (!IsDigit(*p) && !(*p >= 'a' && *p <= 'f')) { break; } } if (p != state->mangled_cur) { // Conversion succeeded. state->mangled_cur = p; - state->number = number; return true; } return false; @@ -636,37 +672,30 @@ static bool ParseFloatNumber(State *state) { // using digits and upper case letters static bool ParseSeqId(State *state) { const char *p = state->mangled_cur; - int number = 0; - for (;p < state->mangled_end; ++p) { - if ((*p >= '0' && *p <= '9')) { - number = number * 36 + (*p - '0'); - } else if (*p >= 'A' && *p <= 'Z') { - number = number * 36 + (*p - 'A' + 10); - } else { + for (;*p != '\0'; ++p) { + if (!IsDigit(*p) && !(*p >= 'A' && *p <= 'Z')) { break; } } if (p != state->mangled_cur) { // Conversion succeeded. state->mangled_cur = p; - state->number = number; return true; } return false; } -// ::= -static bool ParseIdentifier(State *state) { - if (state->number == -1 || - RemainingLength(state) < state->number) { +// ::= (of given length) +static bool ParseIdentifier(State *state, int length) { + if (length == -1 || + !AtLeastNumCharsRemaining(state->mangled_cur, length)) { return false; } - if (IdentifierIsAnonymousNamespace(state)) { + if (IdentifierIsAnonymousNamespace(state, length)) { MaybeAppend(state, "(anonymous namespace)"); } else { - MaybeAppendWithLength(state, state->mangled_cur, state->number); + MaybeAppendWithLength(state, state->mangled_cur, length); } - state->mangled_cur += state->number; - state->number = -1; // Reset the number. + state->mangled_cur += length; return true; } @@ -674,12 +703,12 @@ static bool ParseIdentifier(State *state) { // ::= cv # (cast) // ::= v # vendor extended operator static bool ParseOperatorName(State *state) { - if (RemainingLength(state) < 2) { + if (!AtLeastNumCharsRemaining(state->mangled_cur, 2)) { return false; } // First check with "cv" (cast) case. State copy = *state; - if (ParseTwoChar(state, "cv") && + if (ParseTwoCharToken(state, "cv") && MaybeAppend(state, "operator ") && EnterNestedName(state) && ParseType(state) && @@ -689,7 +718,7 @@ static bool ParseOperatorName(State *state) { *state = copy; // Then vendor extended operators. - if (ParseChar(state, 'v') && ParseCharClass(state, "0123456789") && + if (ParseOneCharToken(state, 'v') && ParseCharClass(state, "0123456789") && ParseSourceName(state)) { return true; } @@ -738,34 +767,34 @@ static bool ParseOperatorName(State *state) { // stack traces. The are special data. static bool ParseSpecialName(State *state) { State copy = *state; - if (ParseChar(state, 'T') && + if (ParseOneCharToken(state, 'T') && ParseCharClass(state, "VTIS") && ParseType(state)) { return true; } *state = copy; - if (ParseTwoChar(state, "Tc") && ParseCallOffset(state) && + if (ParseTwoCharToken(state, "Tc") && ParseCallOffset(state) && ParseCallOffset(state) && ParseEncoding(state)) { return true; } *state = copy; - if (ParseTwoChar(state, "GV") && + if (ParseTwoCharToken(state, "GV") && ParseName(state)) { return true; } *state = copy; - if (ParseChar(state, 'T') && ParseCallOffset(state) && + if (ParseOneCharToken(state, 'T') && ParseCallOffset(state) && ParseEncoding(state)) { return true; } *state = copy; // G++ extensions - if (ParseTwoChar(state, "TC") && ParseType(state) && - ParseNumber(state) && ParseChar(state, '_') && + if (ParseTwoCharToken(state, "TC") && ParseType(state) && + ParseNumber(state, NULL) && ParseOneCharToken(state, '_') && DisableAppend(state) && ParseType(state)) { RestoreAppend(state, copy.append); @@ -773,23 +802,23 @@ static bool ParseSpecialName(State *state) { } *state = copy; - if (ParseChar(state, 'T') && ParseCharClass(state, "FJ") && + if (ParseOneCharToken(state, 'T') && ParseCharClass(state, "FJ") && ParseType(state)) { return true; } *state = copy; - if (ParseTwoChar(state, "GR") && ParseName(state)) { + if (ParseTwoCharToken(state, "GR") && ParseName(state)) { return true; } *state = copy; - if (ParseTwoChar(state, "GA") && ParseEncoding(state)) { + if (ParseTwoCharToken(state, "GA") && ParseEncoding(state)) { return true; } *state = copy; - if (ParseChar(state, 'T') && ParseCharClass(state, "hv") && + if (ParseOneCharToken(state, 'T') && ParseCharClass(state, "hv") && ParseCallOffset(state) && ParseEncoding(state)) { return true; } @@ -801,14 +830,14 @@ static bool ParseSpecialName(State *state) { // ::= v _ static bool ParseCallOffset(State *state) { State copy = *state; - if (ParseChar(state, 'h') && - ParseNVOffset(state) && ParseChar(state, '_')) { + if (ParseOneCharToken(state, 'h') && + ParseNVOffset(state) && ParseOneCharToken(state, '_')) { return true; } *state = copy; - if (ParseChar(state, 'v') && - ParseVOffset(state) && ParseChar(state, '_')) { + if (ParseOneCharToken(state, 'v') && + ParseVOffset(state) && ParseOneCharToken(state, '_')) { return true; } *state = copy; @@ -818,14 +847,14 @@ static bool ParseCallOffset(State *state) { // ::= <(offset) number> static bool ParseNVOffset(State *state) { - return ParseNumber(state); + return ParseNumber(state, NULL); } // ::= <(offset) number> _ <(virtual offset) number> static bool ParseVOffset(State *state) { State copy = *state; - if (ParseNumber(state) && ParseChar(state, '_') && - ParseNumber(state)) { + if (ParseNumber(state, NULL) && ParseOneCharToken(state, '_') && + ParseNumber(state, NULL)) { return true; } *state = copy; @@ -836,7 +865,7 @@ static bool ParseVOffset(State *state) { // ::= D0 | D1 | D2 static bool ParseCtorDtorName(State *state) { State copy = *state; - if (ParseChar(state, 'C') && + if (ParseOneCharToken(state, 'C') && ParseCharClass(state, "123")) { const char * const prev_name = state->prev_name; const int prev_name_length = state->prev_name_length; @@ -845,7 +874,7 @@ static bool ParseCtorDtorName(State *state) { } *state = copy; - if (ParseChar(state, 'D') && + if (ParseOneCharToken(state, 'D') && ParseCharClass(state, "012")) { const char * const prev_name = state->prev_name; const int prev_name_length = state->prev_name_length; @@ -858,11 +887,12 @@ static bool ParseCtorDtorName(State *state) { } // ::= -// ::= P -// ::= R -// ::= C -// ::= G -// ::= U +// ::= P # pointer-to +// ::= R # reference-to +// ::= O # rvalue reference-to (C++0x) +// ::= C # complex pair (C 2000) +// ::= G # imaginary (C 2000) +// ::= U # vendor extended type qualifier // ::= // ::= // ::= @@ -871,6 +901,11 @@ static bool ParseCtorDtorName(State *state) { // ::= // ::= // ::= +// ::= Dp # pack expansion of (C++0x) +// ::= Dt E # decltype of an id-expression or class +// # member access (C++0x) +// ::= DT E # decltype of an expression (C++0x) +// static bool ParseType(State *state) { // We should check CV-qualifers, and PRGC things first. State copy = *state; @@ -879,12 +914,23 @@ static bool ParseType(State *state) { } *state = copy; - if (ParseCharClass(state, "PRCG") && ParseType(state)) { + if (ParseCharClass(state, "OPRCG") && ParseType(state)) { return true; } *state = copy; - if (ParseChar(state, 'U') && ParseSourceName(state) && + if (ParseTwoCharToken(state, "Dp") && ParseType(state)) { + return true; + } + *state = copy; + + if (ParseOneCharToken(state, 'D') && ParseCharClass(state, "tT") && + ParseExpression(state) && ParseOneCharToken(state, 'E')) { + return true; + } + *state = copy; + + if (ParseOneCharToken(state, 'U') && ParseSourceName(state) && ParseType(state)) { return true; } @@ -918,9 +964,9 @@ static bool ParseType(State *state) { // ParseType(). static bool ParseCVQualifiers(State *state) { int num_cv_qualifiers = 0; - num_cv_qualifiers += ParseChar(state, 'r'); - num_cv_qualifiers += ParseChar(state, 'V'); - num_cv_qualifiers += ParseChar(state, 'K'); + num_cv_qualifiers += ParseOneCharToken(state, 'r'); + num_cv_qualifiers += ParseOneCharToken(state, 'V'); + num_cv_qualifiers += ParseOneCharToken(state, 'K'); return num_cv_qualifiers > 0; } @@ -937,7 +983,7 @@ static bool ParseBuiltinType(State *state) { } State copy = *state; - if (ParseChar(state, 'u') && ParseSourceName(state)) { + if (ParseOneCharToken(state, 'u') && ParseSourceName(state)) { return true; } *state = copy; @@ -947,8 +993,9 @@ static bool ParseBuiltinType(State *state) { // ::= F [Y] E static bool ParseFunctionType(State *state) { State copy = *state; - if (ParseChar(state, 'F') && Optional(ParseChar(state, 'Y')) && - ParseBareFunctionType(state) && ParseChar(state, 'E')) { + if (ParseOneCharToken(state, 'F') && + Optional(ParseOneCharToken(state, 'Y')) && + ParseBareFunctionType(state) && ParseOneCharToken(state, 'E')) { return true; } *state = copy; @@ -977,14 +1024,14 @@ static bool ParseClassEnumType(State *state) { // ::= A [<(dimension) expression>] _ <(element) type> static bool ParseArrayType(State *state) { State copy = *state; - if (ParseChar(state, 'A') && ParseNumber(state) && - ParseChar(state, '_') && ParseType(state)) { + if (ParseOneCharToken(state, 'A') && ParseNumber(state, NULL) && + ParseOneCharToken(state, '_') && ParseType(state)) { return true; } *state = copy; - if (ParseChar(state, 'A') && Optional(ParseExpression(state)) && - ParseChar(state, '_') && ParseType(state)) { + if (ParseOneCharToken(state, 'A') && Optional(ParseExpression(state)) && + ParseOneCharToken(state, '_') && ParseType(state)) { return true; } *state = copy; @@ -994,7 +1041,7 @@ static bool ParseArrayType(State *state) { // ::= M <(class) type> <(member) type> static bool ParsePointerToMemberType(State *state) { State copy = *state; - if (ParseChar(state, 'M') && ParseType(state) && + if (ParseOneCharToken(state, 'M') && ParseType(state) && ParseType(state)) { return true; } @@ -1005,14 +1052,14 @@ static bool ParsePointerToMemberType(State *state) { // ::= T_ // ::= T _ static bool ParseTemplateParam(State *state) { - if (ParseTwoChar(state, "T_")) { + if (ParseTwoCharToken(state, "T_")) { MaybeAppend(state, "?"); // We don't support template substitutions. return true; } State copy = *state; - if (ParseChar(state, 'T') && ParseNumber(state) && - ParseChar(state, '_')) { + if (ParseOneCharToken(state, 'T') && ParseNumber(state, NULL) && + ParseOneCharToken(state, '_')) { MaybeAppend(state, "?"); // We don't support template substitutions. return true; } @@ -1032,9 +1079,9 @@ static bool ParseTemplateTemplateParam(State *state) { static bool ParseTemplateArgs(State *state) { State copy = *state; DisableAppend(state); - if (ParseChar(state, 'I') && + if (ParseOneCharToken(state, 'I') && OneOrMore(ParseTemplateArg, state) && - ParseChar(state, 'E')) { + ParseOneCharToken(state, 'E')) { RestoreAppend(state, copy.append); MaybeAppend(state, "<>"); return true; @@ -1045,16 +1092,25 @@ static bool ParseTemplateArgs(State *state) { // ::= // ::= +// ::= I * E # argument pack // ::= X E static bool ParseTemplateArg(State *state) { + State copy = *state; + if (ParseOneCharToken(state, 'I') && + ZeroOrMore(ParseTemplateArg, state) && + ParseOneCharToken(state, 'E')) { + return true; + } + *state = copy; + if (ParseType(state) || ParseExprPrimary(state)) { return true; } + *state = copy; - State copy = *state; - if (ParseChar(state, 'X') && ParseExpression(state) && - ParseChar(state, 'E')) { + if (ParseOneCharToken(state, 'X') && ParseExpression(state) && + ParseOneCharToken(state, 'E')) { return true; } *state = copy; @@ -1097,19 +1153,19 @@ static bool ParseExpression(State *state) { } *state = copy; - if (ParseTwoChar(state, "st") && ParseType(state)) { + if (ParseTwoCharToken(state, "st") && ParseType(state)) { return true; } *state = copy; - if (ParseTwoChar(state, "sr") && ParseType(state) && + if (ParseTwoCharToken(state, "sr") && ParseType(state) && ParseUnqualifiedName(state) && ParseTemplateArgs(state)) { return true; } *state = copy; - if (ParseTwoChar(state, "sr") && ParseType(state) && + if (ParseTwoCharToken(state, "sr") && ParseType(state) && ParseUnqualifiedName(state)) { return true; } @@ -1124,28 +1180,28 @@ static bool ParseExpression(State *state) { // ::= LZ E static bool ParseExprPrimary(State *state) { State copy = *state; - if (ParseChar(state, 'L') && ParseType(state) && - ParseNumber(state) && - ParseChar(state, 'E')) { + if (ParseOneCharToken(state, 'L') && ParseType(state) && + ParseNumber(state, NULL) && + ParseOneCharToken(state, 'E')) { return true; } *state = copy; - if (ParseChar(state, 'L') && ParseType(state) && + if (ParseOneCharToken(state, 'L') && ParseType(state) && ParseFloatNumber(state) && - ParseChar(state, 'E')) { + ParseOneCharToken(state, 'E')) { return true; } *state = copy; - if (ParseChar(state, 'L') && ParseMangledName(state) && - ParseChar(state, 'E')) { + if (ParseOneCharToken(state, 'L') && ParseMangledName(state) && + ParseOneCharToken(state, 'E')) { return true; } *state = copy; - if (ParseTwoChar(state, "LZ") && ParseEncoding(state) && - ParseChar(state, 'E')) { + if (ParseTwoCharToken(state, "LZ") && ParseEncoding(state) && + ParseOneCharToken(state, 'E')) { return true; } *state = copy; @@ -1158,15 +1214,15 @@ static bool ParseExprPrimary(State *state) { // := Z <(function) encoding> E s [] static bool ParseLocalName(State *state) { State copy = *state; - if (ParseChar(state, 'Z') && ParseEncoding(state) && - ParseChar(state, 'E') && MaybeAppend(state, "::") && + if (ParseOneCharToken(state, 'Z') && ParseEncoding(state) && + ParseOneCharToken(state, 'E') && MaybeAppend(state, "::") && ParseName(state) && Optional(ParseDiscriminator(state))) { return true; } *state = copy; - if (ParseChar(state, 'Z') && ParseEncoding(state) && - ParseTwoChar(state, "Es") && Optional(ParseDiscriminator(state))) { + if (ParseOneCharToken(state, 'Z') && ParseEncoding(state) && + ParseTwoCharToken(state, "Es") && Optional(ParseDiscriminator(state))) { return true; } *state = copy; @@ -1176,7 +1232,7 @@ static bool ParseLocalName(State *state) { // := _ <(non-negative) number> static bool ParseDiscriminator(State *state) { State copy = *state; - if (ParseChar(state, '_') && ParseNumber(state)) { + if (ParseOneCharToken(state, '_') && ParseNumber(state, NULL)) { return true; } *state = copy; @@ -1187,21 +1243,21 @@ static bool ParseDiscriminator(State *state) { // ::= S _ // ::= St, etc. static bool ParseSubstitution(State *state) { - if (ParseTwoChar(state, "S_")) { + if (ParseTwoCharToken(state, "S_")) { MaybeAppend(state, "?"); // We don't support substitutions. return true; } State copy = *state; - if (ParseChar(state, 'S') && ParseSeqId(state) && - ParseChar(state, '_')) { + if (ParseOneCharToken(state, 'S') && ParseSeqId(state) && + ParseOneCharToken(state, '_')) { MaybeAppend(state, "?"); // We don't support substitutions. return true; } *state = copy; // Expand abbreviations like "St" => "std". - if (ParseChar(state, 'S')) { + if (ParseOneCharToken(state, 'S')) { const AbbrevPair *p; for (p = kSubstitutionList; p->abbrev != NULL; ++p) { if (state->mangled_cur[0] == p->abbrev[1]) { @@ -1210,7 +1266,7 @@ static bool ParseSubstitution(State *state) { MaybeAppend(state, "::"); MaybeAppend(state, p->real_name); } - state->mangled_cur += 1; + ++state->mangled_cur; return true; } } @@ -1219,13 +1275,33 @@ static bool ParseSubstitution(State *state) { return false; } +// Parse , optionally followed by either a function-clone suffix +// or version suffix. Returns true only if all of "mangled_cur" was consumed. +static bool ParseTopLevelMangledName(State *state) { + if (ParseMangledName(state)) { + if (state->mangled_cur[0] != '\0') { + // Drop trailing function clone suffix, if any. + if (IsFunctionCloneSuffix(state->mangled_cur)) { + return true; + } + // Append trailing version suffix if any. + // ex. _Z3foo@@GLIBCXX_3.4 + if (state->mangled_cur[0] == '@') { + MaybeAppend(state, state->mangled_cur); + return true; + } + return false; // Unconsumed suffix. + } + return true; + } + return false; +} + // The demangler entry point. bool Demangle(const char *mangled, char *out, int out_size) { State state; InitState(&state, mangled, out, out_size); - return (ParseMangledName(&state) && - state.overflowed == false && - RemainingLength(&state) == 0); + return ParseTopLevelMangledName(&state) && !state.overflowed; } _END_GOOGLE_NAMESPACE_ diff --git a/extern/libmv/third_party/glog/src/glog/log_severity.h b/extern/libmv/third_party/glog/src/glog/log_severity.h index 17805fbadd4..99945a426da 100644 --- a/extern/libmv/third_party/glog/src/glog/log_severity.h +++ b/extern/libmv/third_party/glog/src/glog/log_severity.h @@ -44,7 +44,15 @@ // you ever need to change their values or add a new severity. typedef int LogSeverity; -const int INFO = 0, WARNING = 1, ERROR = 2, FATAL = 3, NUM_SEVERITIES = 4; +const int GLOG_INFO = 0, GLOG_WARNING = 1, GLOG_ERROR = 2, GLOG_FATAL = 3, + NUM_SEVERITIES = 4; +#ifndef GLOG_NO_ABBREVIATED_SEVERITIES +# ifdef ERROR +# error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail. +# endif +const int INFO = GLOG_INFO, WARNING = GLOG_WARNING, + ERROR = GLOG_ERROR, FATAL = GLOG_FATAL; +#endif // DFATAL is FATAL in debug mode, ERROR in normal mode #ifdef NDEBUG diff --git a/extern/libmv/third_party/glog/src/glog/logging.h b/extern/libmv/third_party/glog/src/glog/logging.h index a58d478ab17..005649c17c2 100644 --- a/extern/libmv/third_party/glog/src/glog/logging.h +++ b/extern/libmv/third_party/glog/src/glog/logging.h @@ -33,7 +33,6 @@ // Pretty much everybody needs to #include this file so that they can // log various happenings. // - #ifndef _LOGGING_H_ #define _LOGGING_H_ @@ -80,7 +79,7 @@ #endif #if 1 -#include "third_party/gflags/gflags.h" +#include "third_party/gflags/gflags/gflags.h" #endif namespace google { @@ -153,21 +152,21 @@ typedef unsigned __int64 uint64; // You can also do occasional logging (log every n'th occurrence of an // event): // -// LOG_EVERY_N(INFO, 10) << "Got the " << COUNTER << "th cookie"; +// LOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie"; // // The above will cause log messages to be output on the 1st, 11th, 21st, ... -// times it is executed. Note that the special COUNTER value is used to -// identify which repetition is happening. +// times it is executed. Note that the special google::COUNTER value is used +// to identify which repetition is happening. // // You can also do occasional conditional logging (log every n'th // occurrence of an event, when condition is satisfied): // -// LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << COUNTER +// LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER // << "th big cookie"; // // You can log messages the first N times your code executes a line. E.g. // -// LOG_FIRST_N(INFO, 20) << "Got the " << COUNTER << "th cookie"; +// LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie"; // // Outputs log messages for the first 20 times it is executed. // @@ -184,7 +183,7 @@ typedef unsigned __int64 uint64; // // DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies"; // -// DLOG_EVERY_N(INFO, 10) << "Got the " << COUNTER << "th cookie"; +// DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie"; // // All "debug mode" logging is compiled away to nothing for non-debug mode // compiles. @@ -228,11 +227,11 @@ typedef unsigned __int64 uint64; // "program with --v=1 or more"; // VLOG_EVERY_N(1, 10) // << "I'm printed every 10th occurrence, and when you run the program " -// "with --v=1 or more. Present occurence is " << COUNTER; +// "with --v=1 or more. Present occurence is " << google::COUNTER; // VLOG_IF_EVERY_N(1, (size > 1024), 10) // << "I'm printed on every 10th occurence of case when size is more " // " than 1024, when you run the program with --v=1 or more. "; -// "Present occurence is " << COUNTER; +// "Present occurence is " << google::COUNTER; // // The supported severity levels for macros that allow you to specify one // are (in increasing order of severity) INFO, WARNING, ERROR, and FATAL. @@ -369,7 +368,7 @@ DECLARE_bool(stop_logging_if_full_disk); #define COMPACT_GOOGLE_LOG_INFO google::LogMessage( \ __FILE__, __LINE__) #define LOG_TO_STRING_INFO(message) google::LogMessage( \ - __FILE__, __LINE__, google::INFO, message) + __FILE__, __LINE__, google::GLOG_INFO, message) #else #define COMPACT_GOOGLE_LOG_INFO google::NullStream() #define LOG_TO_STRING_INFO(message) google::NullStream() @@ -377,9 +376,9 @@ DECLARE_bool(stop_logging_if_full_disk); #if GOOGLE_STRIP_LOG <= 1 #define COMPACT_GOOGLE_LOG_WARNING google::LogMessage( \ - __FILE__, __LINE__, google::WARNING) + __FILE__, __LINE__, google::GLOG_WARNING) #define LOG_TO_STRING_WARNING(message) google::LogMessage( \ - __FILE__, __LINE__, google::WARNING, message) + __FILE__, __LINE__, google::GLOG_WARNING, message) #else #define COMPACT_GOOGLE_LOG_WARNING google::NullStream() #define LOG_TO_STRING_WARNING(message) google::NullStream() @@ -387,9 +386,9 @@ DECLARE_bool(stop_logging_if_full_disk); #if GOOGLE_STRIP_LOG <= 2 #define COMPACT_GOOGLE_LOG_ERROR google::LogMessage( \ - __FILE__, __LINE__, google::ERROR) + __FILE__, __LINE__, google::GLOG_ERROR) #define LOG_TO_STRING_ERROR(message) google::LogMessage( \ - __FILE__, __LINE__, google::ERROR, message) + __FILE__, __LINE__, google::GLOG_ERROR, message) #else #define COMPACT_GOOGLE_LOG_ERROR google::NullStream() #define LOG_TO_STRING_ERROR(message) google::NullStream() @@ -399,7 +398,7 @@ DECLARE_bool(stop_logging_if_full_disk); #define COMPACT_GOOGLE_LOG_FATAL google::LogMessageFatal( \ __FILE__, __LINE__) #define LOG_TO_STRING_FATAL(message) google::LogMessage( \ - __FILE__, __LINE__, google::FATAL, message) + __FILE__, __LINE__, google::GLOG_FATAL, message) #else #define COMPACT_GOOGLE_LOG_FATAL google::NullStreamFatal() #define LOG_TO_STRING_FATAL(message) google::NullStreamFatal() @@ -411,32 +410,32 @@ DECLARE_bool(stop_logging_if_full_disk); #define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR #elif GOOGLE_STRIP_LOG <= 3 #define COMPACT_GOOGLE_LOG_DFATAL google::LogMessage( \ - __FILE__, __LINE__, google::FATAL) + __FILE__, __LINE__, google::GLOG_FATAL) #else #define COMPACT_GOOGLE_LOG_DFATAL google::NullStreamFatal() #endif -#define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::INFO, counter, &google::LogMessage::SendToLog) +#define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, &google::LogMessage::SendToLog) #define SYSLOG_INFO(counter) \ - google::LogMessage(__FILE__, __LINE__, google::INFO, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_WARNING(counter) \ - google::LogMessage(__FILE__, __LINE__, google::WARNING, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \ &google::LogMessage::SendToLog) #define SYSLOG_WARNING(counter) \ - google::LogMessage(__FILE__, __LINE__, google::WARNING, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_ERROR(counter) \ - google::LogMessage(__FILE__, __LINE__, google::ERROR, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \ &google::LogMessage::SendToLog) #define SYSLOG_ERROR(counter) \ - google::LogMessage(__FILE__, __LINE__, google::ERROR, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_FATAL(counter) \ - google::LogMessage(__FILE__, __LINE__, google::FATAL, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \ &google::LogMessage::SendToLog) #define SYSLOG_FATAL(counter) \ - google::LogMessage(__FILE__, __LINE__, google::FATAL, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_DFATAL(counter) \ google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \ @@ -455,7 +454,7 @@ DECLARE_bool(stop_logging_if_full_disk); FORMAT_MESSAGE_FROM_SYSTEM, \ 0, result, 0, msg, 100, NULL); \ if (message_length > 0) { \ - google::LogMessage(__FILE__, __LINE__, ERROR, 0, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, 0, \ &google::LogMessage::SendToLog).stream() << message; \ LocalFree(message); \ } \ @@ -502,12 +501,12 @@ class LogSink; // defined below #define LOG_TO_SINK(sink, severity) \ google::LogMessage( \ __FILE__, __LINE__, \ - google::severity, \ + google::GLOG_ ## severity, \ static_cast(sink), true).stream() #define LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity) \ google::LogMessage( \ __FILE__, __LINE__, \ - google::severity, \ + google::GLOG_ ## severity, \ static_cast(sink), false).stream() // If a non-NULL string pointer is given, we write this message to that string. @@ -772,7 +771,7 @@ DECLARE_CHECK_STROP_IMPL(strcasecmp, false) #define GOOGLE_PLOG(severity, counter) \ google::ErrnoLogMessage( \ - __FILE__, __LINE__, google::severity, counter, \ + __FILE__, __LINE__, google::GLOG_ ## severity, counter, \ &google::LogMessage::SendToLog) #define PLOG_IF(severity, condition) \ @@ -811,7 +810,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \ if (LOG_OCCURRENCES_MOD_N == 1) \ google::LogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() #define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \ @@ -820,7 +819,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ if (condition && \ ((LOG_OCCURRENCES_MOD_N=(LOG_OCCURRENCES_MOD_N + 1) % n) == (1 % n))) \ google::LogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() #define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \ @@ -829,7 +828,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \ if (LOG_OCCURRENCES_MOD_N == 1) \ google::ErrnoLogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() #define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \ @@ -838,7 +837,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ ++LOG_OCCURRENCES; \ if (LOG_OCCURRENCES <= n) \ google::LogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() namespace glog_internal_namespace_ { @@ -852,7 +851,7 @@ struct CrashReason; typedef google::glog_internal_namespace_::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] #define LOG_EVERY_N(severity, n) \ - GOOGLE_GLOG_COMPILE_ASSERT(google::severity < \ + GOOGLE_GLOG_COMPILE_ASSERT(google::GLOG_ ## severity < \ google::NUM_SEVERITIES, \ INVALID_REQUESTED_LOG_SEVERITY); \ SOME_KIND_OF_LOG_EVERY_N(severity, (n), google::LogMessage::SendToLog) @@ -872,6 +871,27 @@ struct CrashReason; // We want the special COUNTER value available for LOG_EVERY_X()'ed messages enum PRIVATE_Counter {COUNTER}; +#ifdef GLOG_NO_ABBREVIATED_SEVERITIES +// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets +// substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us +// to keep using this syntax, we define this macro to do the same thing +// as COMPACT_GOOGLE_LOG_ERROR. +#define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR +#define SYSLOG_0 SYSLOG_ERROR +#define LOG_TO_STRING_0 LOG_TO_STRING_ERROR +// Needed for LOG_IS_ON(ERROR). +const LogSeverity GLOG_0 = GLOG_ERROR; +#else +// Users may include windows.h after logging.h without +// GLOG_NO_ABBREVIATED_SEVERITIES nor WIN32_LEAN_AND_MEAN. +// For this case, we cannot detect if ERROR is defined before users +// actually use ERROR. Let's make an undefined symbol to warn users. +# define GLOG_ERROR_MSG ERROR_macro_is_defined_Define_GLOG_NO_ABBREVIATED_SEVERITIES_before_including_logging_h_See_the_document_for_detail +# define COMPACT_GOOGLE_LOG_0 GLOG_ERROR_MSG +# define SYSLOG_0 GLOG_ERROR_MSG +# define LOG_TO_STRING_0 GLOG_ERROR_MSG +# define GLOG_0 GLOG_ERROR_MSG +#endif // Plus some debug-logging macros that get compiled to nothing for production @@ -1016,14 +1036,14 @@ public: # pragma warning(default: 4275) #endif public: - LogStream(char *buf, int len, int ctr) + LogStream(char *buf, int len, int ctr_in) : ostrstream(buf, len), - ctr_(ctr) { + ctr_(ctr_in) { self_ = this; } int ctr() const { return ctr_; } - void set_ctr(int ctr) { ctr_ = ctr; } + void set_ctr(int ctr_in) { ctr_ = ctr_in; } LogStream* self() const { return self_; } private: @@ -1465,7 +1485,7 @@ class GOOGLE_GLOG_DLL_DECL NullStream : public LogMessage::LogStream { // converted to LogStream and the message will be computed and then // quietly discarded. template -inline NullStream& operator<<(NullStream &str, const T &value) { return str; } +inline NullStream& operator<<(NullStream &str, const T &) { return str; } // Similar to NullStream, but aborts the program (without stack // trace), like LogMessageFatal. diff --git a/extern/libmv/third_party/glog/src/glog/raw_logging.h b/extern/libmv/third_party/glog/src/glog/raw_logging.h index 9e9b3772f3b..65278f62803 100644 --- a/extern/libmv/third_party/glog/src/glog/raw_logging.h +++ b/extern/libmv/third_party/glog/src/glog/raw_logging.h @@ -68,7 +68,7 @@ namespace google { // I0821 211317 file.cc:142] RAW: status is 20 #define RAW_LOG(severity, ...) \ do { \ - switch (google::severity) { \ + switch (google::GLOG_ ## severity) { \ case 0: \ RAW_LOG_INFO(__VA_ARGS__); \ break; \ @@ -100,28 +100,28 @@ namespace google { #endif // STRIP_LOG == 0 #if STRIP_LOG == 0 -#define RAW_LOG_INFO(...) google::RawLog__(google::INFO, \ +#define RAW_LOG_INFO(...) google::RawLog__(google::GLOG_INFO, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__) #endif // STRIP_LOG == 0 #if STRIP_LOG <= 1 -#define RAW_LOG_WARNING(...) google::RawLog__(google::WARNING, \ +#define RAW_LOG_WARNING(...) google::RawLog__(google::GLOG_WARNING, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__) #endif // STRIP_LOG <= 1 #if STRIP_LOG <= 2 -#define RAW_LOG_ERROR(...) google::RawLog__(google::ERROR, \ +#define RAW_LOG_ERROR(...) google::RawLog__(google::GLOG_ERROR, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__) #endif // STRIP_LOG <= 2 #if STRIP_LOG <= 3 -#define RAW_LOG_FATAL(...) google::RawLog__(google::FATAL, \ +#define RAW_LOG_FATAL(...) google::RawLog__(google::GLOG_FATAL, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_FATAL(...) \ @@ -162,7 +162,7 @@ namespace google { // Stub log function used to work around for unused variable warnings when // building with STRIP_LOG > 0. -static inline void RawLogStub__(int ignored, ...) { +static inline void RawLogStub__(int /* ignored */, ...) { } // Helper function to implement RAW_LOG and RAW_VLOG diff --git a/extern/libmv/third_party/glog/src/logging.cc b/extern/libmv/third_party/glog/src/logging.cc index 1bb3867aa10..bf4d85be5b3 100644 --- a/extern/libmv/third_party/glog/src/logging.cc +++ b/extern/libmv/third_party/glog/src/logging.cc @@ -111,7 +111,7 @@ _END_GOOGLE_NAMESPACE_ // The default is ERROR instead of FATAL so that users can see problems // when they run a program without having to look in another file. DEFINE_int32(stderrthreshold, - GOOGLE_NAMESPACE::ERROR, + GOOGLE_NAMESPACE::GLOG_ERROR, "log messages at or above this level are copied to stderr in " "addition to logfiles. This flag obsoletes --alsologtostderr."); @@ -311,8 +311,10 @@ class LogDestination { static const int kNetworkBytes = 1400; static const string& hostname(); - private: + static void DeleteLogDestinations(); + + private: LogDestination(LogSeverity severity, const char* base_filename); ~LogDestination() { } @@ -503,7 +505,7 @@ inline void LogDestination::SetEmailLogging(LogSeverity min_severity, static void WriteToStderr(const char* message, size_t len) { // Avoid using cerr from this module since we may get called during // exit code, and cerr may be partially or fully destroyed by then. - write(STDERR_FILENO, message, len); + fwrite(message, len, 1, stderr); } inline void LogDestination::MaybeLogToStderr(LogSeverity severity, @@ -607,6 +609,13 @@ inline LogDestination* LogDestination::log_destination(LogSeverity severity) { return log_destinations_[severity]; } +void LogDestination::DeleteLogDestinations() { + for (int severity = 0; severity < NUM_SEVERITIES; ++severity) { + delete log_destinations_[severity]; + log_destinations_[severity] = NULL; + } +} + namespace { LogFileObject::LogFileObject(LogSeverity severity, @@ -719,14 +728,18 @@ bool LogFileObject::CreateLogfile(const char* time_pid_string) { // Make the symlink be relative (in the same dir) so that if the // entire log directory gets relocated the link is still valid. const char *linkdest = slash ? (slash + 1) : filename; - symlink(linkdest, linkpath.c_str()); // silently ignore failures + if (symlink(linkdest, linkpath.c_str()) != 0) { + // silently ignore failures + } // Make an additional link to the log file in a place specified by // FLAGS_log_link, if indicated if (!FLAGS_log_link.empty()) { linkpath = FLAGS_log_link + "/" + linkname; unlink(linkpath.c_str()); // delete old one if it exists - symlink(filename, linkpath.c_str()); // silently ignore failures + if (symlink(filename, linkpath.c_str()) != 0) { + // silently ignore failures + } } #endif } @@ -745,7 +758,8 @@ void LogFileObject::Write(bool force_flush, return; } - if (static_cast(file_length_ >> 20) >= MaxLogSize()) { + if (static_cast(file_length_ >> 20) >= MaxLogSize() || + PidHasChanged()) { if (file_ != NULL) fclose(file_); file_ = NULL; file_length_ = bytes_since_flush_ = 0; @@ -936,12 +950,12 @@ LogMessage::LogMessage(const char* file, int line, LogSeverity severity, LogMessage::LogMessage(const char* file, int line, const CheckOpString& result) { - Init(file, line, FATAL, &LogMessage::SendToLog); + Init(file, line, GLOG_FATAL, &LogMessage::SendToLog); stream() << "Check failed: " << (*result.str_) << " "; } LogMessage::LogMessage(const char* file, int line) { - Init(file, line, INFO, &LogMessage::SendToLog); + Init(file, line, GLOG_INFO, &LogMessage::SendToLog); } LogMessage::LogMessage(const char* file, int line, LogSeverity severity) { @@ -972,7 +986,7 @@ void LogMessage::Init(const char* file, LogSeverity severity, void (LogMessage::*send_method)()) { allocated_ = NULL; - if (severity != FATAL || !exit_on_dfatal) { + if (severity != GLOG_FATAL || !exit_on_dfatal) { allocated_ = new LogMessageData(); data_ = allocated_; data_->buf_ = new char[kMaxLogMessageLen+1]; @@ -1123,7 +1137,7 @@ void ReprintFatalMessage() { // Also write to stderr WriteToStderr(fatal_message, n); } - LogDestination::LogToAllLogfiles(ERROR, fatal_time, fatal_message, n); + LogDestination::LogToAllLogfiles(GLOG_ERROR, fatal_time, fatal_message, n); } } @@ -1181,7 +1195,7 @@ void LogMessage::SendToLog() EXCLUSIVE_LOCKS_REQUIRED(log_mutex) { // If we log a FATAL message, flush all the log destinations, then toss // a signal for others to catch. We leave the logs in a state that // someone else can use them (as long as they flush afterwards) - if (data_->severity_ == FATAL && exit_on_dfatal) { + if (data_->severity_ == GLOG_FATAL && exit_on_dfatal) { if (data_->first_fatal_) { // Store crash information so that it is accessible from within signal // handlers that may be invoked later. @@ -1212,7 +1226,9 @@ void LogMessage::SendToLog() EXCLUSIVE_LOCKS_REQUIRED(log_mutex) { LogDestination::WaitForSinks(data_); const char* message = "*** Check failure stack trace: ***\n"; - write(STDERR_FILENO, message, strlen(message)); + if (write(STDERR_FILENO, message, strlen(message)) < 0) { + // Ignore errors. + } Fail(); } } @@ -1231,27 +1247,31 @@ void LogMessage::RecordCrashReason( #endif } +#ifdef HAVE___ATTRIBUTE__ +# define ATTRIBUTE_NORETURN __attribute__((noreturn)) +#else +# define ATTRIBUTE_NORETURN +#endif + +static void logging_fail() ATTRIBUTE_NORETURN; + static void logging_fail() { -// #if defined(_DEBUG) && defined(_MSC_VER) -// doesn't work for my laptop (sergey) -#if 0 +#if defined(_DEBUG) && defined(_MSC_VER) // When debugging on windows, avoid the obnoxious dialog and make // it possible to continue past a LOG(FATAL) in the debugger - _asm int 3 + __debugbreak(); #else abort(); #endif } -#ifdef HAVE___ATTRIBUTE__ +typedef void (*logging_fail_func_t)() ATTRIBUTE_NORETURN; + GOOGLE_GLOG_DLL_DECL -void (*g_logging_fail_func)() __attribute__((noreturn)) = &logging_fail; -#else -GOOGLE_GLOG_DLL_DECL void (*g_logging_fail_func)() = &logging_fail; -#endif +logging_fail_func_t g_logging_fail_func = &logging_fail; void InstallFailureFunction(void (*fail_func)()) { - g_logging_fail_func = fail_func; + g_logging_fail_func = (logging_fail_func_t)fail_func; } void LogMessage::Fail() { @@ -1544,7 +1564,7 @@ static void GetTempDirectories(vector* list) { "/tmp", }; - for (int i = 0; i < ARRAYSIZE(candidates); i++) { + for (size_t i = 0; i < ARRAYSIZE(candidates); i++) { const char *d = candidates[i]; if (!d) continue; // Empty env var @@ -1631,9 +1651,9 @@ void TruncateLogFile(const char *path, int64 limit, int64 keep) { // rather scary. // Instead just truncate the file to something we can manage if (truncate(path, 0) == -1) { - PLOG(ERROR) << "Unable to truncate " << path; + PLOG(ERROR) << "Unable to truncate " << path; } else { - LOG(ERROR) << "Truncated " << path << " due to EFBIG error"; + LOG(ERROR) << "Truncated " << path << " due to EFBIG error"; } } else { PLOG(ERROR) << "Unable to open " << path; @@ -1769,7 +1789,7 @@ int posix_strerror_r(int err, char *buf, size_t len) { } LogMessageFatal::LogMessageFatal(const char* file, int line) : - LogMessage(file, line, FATAL) {} + LogMessage(file, line, GLOG_FATAL) {} LogMessageFatal::LogMessageFatal(const char* file, int line, const CheckOpString& result) : @@ -1780,4 +1800,15 @@ LogMessageFatal::~LogMessageFatal() { LogMessage::Fail(); } +void InitGoogleLogging(const char* argv0) { + glog_internal_namespace_::InitGoogleLoggingUtilities(argv0); +} + +void ShutdownGoogleLogging() { + glog_internal_namespace_::ShutdownGoogleLoggingUtilities(); + LogDestination::DeleteLogDestinations(); + delete logging_directories_list; + logging_directories_list = NULL; +} + _END_GOOGLE_NAMESPACE_ diff --git a/extern/libmv/third_party/glog/src/raw_logging.cc b/extern/libmv/third_party/glog/src/raw_logging.cc index b179a1eded4..42676cba5de 100644 --- a/extern/libmv/third_party/glog/src/raw_logging.cc +++ b/extern/libmv/third_party/glog/src/raw_logging.cc @@ -151,7 +151,7 @@ void RawLog__(LogSeverity severity, const char* file, int line, // libc (to side-step any libc interception). // We write just once to avoid races with other invocations of RawLog__. safe_write(STDERR_FILENO, buffer, strlen(buffer)); - if (severity == FATAL) { + if (severity == GLOG_FATAL) { if (!sync_val_compare_and_swap(&crashed, false, true)) { crash_reason.filename = file; crash_reason.line_number = line; diff --git a/extern/libmv/third_party/glog/src/signalhandler.cc b/extern/libmv/third_party/glog/src/signalhandler.cc index 9fc91b3390d..e95e9e97274 100644 --- a/extern/libmv/third_party/glog/src/signalhandler.cc +++ b/extern/libmv/third_party/glog/src/signalhandler.cc @@ -34,7 +34,7 @@ #include "utilities.h" #include "stacktrace.h" #include "symbolize.h" -#include "glog/logging.h" +#include #include #include @@ -142,7 +142,9 @@ class MinimalFormatter { // Writes the given data with the size to the standard error. void WriteToStderr(const char* data, int size) { - write(STDERR_FILENO, data, size); + if (write(STDERR_FILENO, data, size) < 0) { + // Ignore errors. + } } // The writer function can be changed by InstallFailureWriter(). @@ -167,7 +169,7 @@ void DumpTimeInfo() { void DumpSignalInfo(int signal_number, siginfo_t *siginfo) { // Get the signal name. const char* signal_name = NULL; - for (int i = 0; i < ARRAYSIZE(kFailureSignals); ++i) { + for (size_t i = 0; i < ARRAYSIZE(kFailureSignals); ++i) { if (signal_number == kFailureSignals[i].number) { signal_name = kFailureSignals[i].name; } @@ -336,7 +338,7 @@ void InstallFailureSignalHandler() { sig_action.sa_flags |= SA_SIGINFO; sig_action.sa_sigaction = &FailureSignalHandler; - for (int i = 0; i < ARRAYSIZE(kFailureSignals); ++i) { + for (size_t i = 0; i < ARRAYSIZE(kFailureSignals); ++i) { CHECK_ERR(sigaction(kFailureSignals[i].number, &sig_action, NULL)); } } diff --git a/extern/libmv/third_party/glog/src/stacktrace_libunwind-inl.h b/extern/libmv/third_party/glog/src/stacktrace_libunwind-inl.h index 0dc14c6506e..46002c1b019 100644 --- a/extern/libmv/third_party/glog/src/stacktrace_libunwind-inl.h +++ b/extern/libmv/third_party/glog/src/stacktrace_libunwind-inl.h @@ -37,7 +37,7 @@ extern "C" { #define UNW_LOCAL_ONLY #include } -#include "glog/raw_logging.h" +#include #include "stacktrace.h" _START_GOOGLE_NAMESPACE_ diff --git a/extern/libmv/third_party/glog/src/stacktrace_x86_64-inl.h b/extern/libmv/third_party/glog/src/stacktrace_x86_64-inl.h index e3729e1fd39..f7d1dca85bc 100644 --- a/extern/libmv/third_party/glog/src/stacktrace_x86_64-inl.h +++ b/extern/libmv/third_party/glog/src/stacktrace_x86_64-inl.h @@ -33,10 +33,6 @@ extern "C" { #include // for NULL -#if defined(__FreeBSD__) -/* devel/libunwind only includes _Unwind_Backtrace if this is set */ -#define _GNU_SOURCE 1 -#endif #include // ABI defined unwinder } #include "stacktrace.h" diff --git a/extern/libmv/third_party/glog/src/symbolize.cc b/extern/libmv/third_party/glog/src/symbolize.cc index 3465de6c6fe..d1831e4ea79 100644 --- a/extern/libmv/third_party/glog/src/symbolize.cc +++ b/extern/libmv/third_party/glog/src/symbolize.cc @@ -82,8 +82,8 @@ static ATTRIBUTE_NOINLINE void DemangleInplace(char *out, int out_size) { char demangled[256]; // Big enough for sane demangled symbols. if (Demangle(out, demangled, sizeof(demangled))) { // Demangling succeeded. Copy to out if the space allows. - int len = strlen(demangled); - if (len + 1 <= out_size) { // +1 for '\0'. + size_t len = strlen(demangled); + if (len + 1 <= (size_t)out_size) { // +1 for '\0'. SAFE_ASSERT(len < sizeof(demangled)); memmove(out, demangled, len + 1); } @@ -111,7 +111,7 @@ _END_GOOGLE_NAMESPACE_ #include "symbolize.h" #include "config.h" -#include "glog/raw_logging.h" +#include // Re-runs fn until it doesn't cause EINTR. #define NO_INTR(fn) do {} while ((fn) < 0 && errno == EINTR) @@ -637,7 +637,7 @@ static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out, int out_size) { Dl_info info; if (dladdr(pc, &info)) { - if (strlen(info.dli_sname) < out_size) { + if ((int)strlen(info.dli_sname) < out_size) { strcpy(out, info.dli_sname); // Symbolization succeeded. Now we try to demangle the symbol. DemangleInplace(out, out_size); diff --git a/extern/libmv/third_party/glog/src/symbolize.h b/extern/libmv/third_party/glog/src/symbolize.h index 1ebe4dd94a2..04e482bc315 100644 --- a/extern/libmv/third_party/glog/src/symbolize.h +++ b/extern/libmv/third_party/glog/src/symbolize.h @@ -56,7 +56,7 @@ #include "utilities.h" #include "config.h" -#include "glog/logging.h" +#include #ifdef HAVE_SYMBOLIZE diff --git a/extern/libmv/third_party/glog/src/utilities.cc b/extern/libmv/third_party/glog/src/utilities.cc index 6d64b923703..27b2a905055 100644 --- a/extern/libmv/third_party/glog/src/utilities.cc +++ b/extern/libmv/third_party/glog/src/utilities.cc @@ -77,9 +77,11 @@ typedef void DebugWriter(const char*, void*); // For some environments, add two extra bytes for the leading "0x". static const int kPrintfPointerFieldWidth = 2 + 2 * sizeof(void*); -static void DebugWriteToStderr(const char* data, void *unused) { +static void DebugWriteToStderr(const char* data, void *) { // This one is signal-safe. - write(STDERR_FILENO, data, strlen(data)); + if (write(STDERR_FILENO, data, strlen(data)) < 0) { + // Ignore errors. + } } void DebugWriteToString(const char* data, void *arg) { @@ -221,9 +223,18 @@ int32 GetMainThreadPid() { return g_main_thread_pid; } +bool PidHasChanged() { + int32 pid = getpid(); + if (g_main_thread_pid == pid) { + return false; + } + g_main_thread_pid = pid; + return true; +} + pid_t GetTID() { // On Linux and FreeBSD, we try to use gettid(). -#if defined OS_LINUX || defined OS_MACOSX +#if defined OS_LINUX || defined OS_FREEBSD || defined OS_MACOSX #ifndef __NR_gettid #ifdef OS_MACOSX #define __NR_gettid SYS_gettid @@ -302,9 +313,7 @@ void SetCrashReason(const CrashReason* r) { r); } -} // namespace glog_internal_namespace_ - -void InitGoogleLogging(const char* argv0) { +void InitGoogleLoggingUtilities(const char* argv0) { CHECK(!IsGoogleLoggingInitialized()) << "You called InitGoogleLogging() twice!"; const char* slash = strrchr(argv0, '/'); @@ -319,14 +328,16 @@ void InitGoogleLogging(const char* argv0) { #endif } -void ShutdownGoogleLogging() { +void ShutdownGoogleLoggingUtilities() { CHECK(IsGoogleLoggingInitialized()) - << "You called ShutdownGoogleLogging() without InitGoogleLogging() first!"; + << "You called ShutdownGoogleLogging() without calling InitGoogleLogging() first!"; #ifdef HAVE_SYSLOG_H closelog(); #endif } +} // namespace glog_internal_namespace_ + _END_GOOGLE_NAMESPACE_ // Make an implementation of stacktrace compiled. diff --git a/extern/libmv/third_party/glog/src/utilities.h b/extern/libmv/third_party/glog/src/utilities.h index bbb0eb0746c..c8215b73f33 100644 --- a/extern/libmv/third_party/glog/src/utilities.h +++ b/extern/libmv/third_party/glog/src/utilities.h @@ -161,6 +161,7 @@ typedef double WallTime; WallTime WallTime_Now(); int32 GetMainThreadPid(); +bool PidHasChanged(); pid_t GetTID(); @@ -215,6 +216,9 @@ struct CrashReason { void SetCrashReason(const CrashReason* r); +void InitGoogleLoggingUtilities(const char* argv0); +void ShutdownGoogleLoggingUtilities(); + } // namespace glog_internal_namespace_ _END_GOOGLE_NAMESPACE_ diff --git a/extern/libmv/third_party/glog/src/vlog_is_on.cc b/extern/libmv/third_party/glog/src/vlog_is_on.cc index ed88514dce5..5eefc96324a 100644 --- a/extern/libmv/third_party/glog/src/vlog_is_on.cc +++ b/extern/libmv/third_party/glog/src/vlog_is_on.cc @@ -70,8 +70,8 @@ GOOGLE_GLOG_DLL_DECL bool SafeFNMatch_(const char* pattern, size_t patt_len, const char* str, size_t str_len) { - int p = 0; - int s = 0; + size_t p = 0; + size_t s = 0; while (1) { if (p == patt_len && s == str_len) return true; if (p == patt_len) return false; @@ -211,7 +211,7 @@ bool InitVLOG3__(int32** site_flag, int32* site_default, const char* base = strrchr(fname, '/'); base = base ? (base+1) : fname; const char* base_end = strchr(base, '.'); - size_t base_length = base_end ? (base_end - base) : strlen(base); + size_t base_length = base_end ? size_t(base_end - base) : strlen(base); // Trim out trailing "-inl" if any if (base_length >= 4 && (memcmp(base+base_length-4, "-inl", 4) == 0)) { diff --git a/extern/libmv/third_party/glog/src/windows/glog/log_severity.h b/extern/libmv/third_party/glog/src/windows/glog/log_severity.h index 5e7d09effb2..22a4191ab8b 100644 --- a/extern/libmv/third_party/glog/src/windows/glog/log_severity.h +++ b/extern/libmv/third_party/glog/src/windows/glog/log_severity.h @@ -48,7 +48,15 @@ // you ever need to change their values or add a new severity. typedef int LogSeverity; -const int INFO = 0, WARNING = 1, ERROR = 2, FATAL = 3, NUM_SEVERITIES = 4; +const int GLOG_INFO = 0, GLOG_WARNING = 1, GLOG_ERROR = 2, GLOG_FATAL = 3, + NUM_SEVERITIES = 4; +#ifndef GLOG_NO_ABBREVIATED_SEVERITIES +# ifdef ERROR +# error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail. +# endif +const int INFO = GLOG_INFO, WARNING = GLOG_WARNING, + ERROR = GLOG_ERROR, FATAL = GLOG_FATAL; +#endif // DFATAL is FATAL in debug mode, ERROR in normal mode #ifdef NDEBUG diff --git a/extern/libmv/third_party/glog/src/windows/glog/logging.h b/extern/libmv/third_party/glog/src/windows/glog/logging.h index 2f41681edbe..f623cd9e793 100644 --- a/extern/libmv/third_party/glog/src/windows/glog/logging.h +++ b/extern/libmv/third_party/glog/src/windows/glog/logging.h @@ -83,7 +83,7 @@ #endif #if 1 -#include "third_party/gflags/gflags.h" +#include "third_party/gflags/gflags/gflags.h" #endif #ifdef __MINGW32__ @@ -170,21 +170,21 @@ typedef uint64_t uint64; // You can also do occasional logging (log every n'th occurrence of an // event): // -// LOG_EVERY_N(INFO, 10) << "Got the " << COUNTER << "th cookie"; +// LOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie"; // // The above will cause log messages to be output on the 1st, 11th, 21st, ... -// times it is executed. Note that the special COUNTER value is used to -// identify which repetition is happening. +// times it is executed. Note that the special google::COUNTER value is used +// to identify which repetition is happening. // // You can also do occasional conditional logging (log every n'th // occurrence of an event, when condition is satisfied): // -// LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << COUNTER +// LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER // << "th big cookie"; // // You can log messages the first N times your code executes a line. E.g. // -// LOG_FIRST_N(INFO, 20) << "Got the " << COUNTER << "th cookie"; +// LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie"; // // Outputs log messages for the first 20 times it is executed. // @@ -201,7 +201,7 @@ typedef uint64_t uint64; // // DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies"; // -// DLOG_EVERY_N(INFO, 10) << "Got the " << COUNTER << "th cookie"; +// DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie"; // // All "debug mode" logging is compiled away to nothing for non-debug mode // compiles. @@ -245,11 +245,11 @@ typedef uint64_t uint64; // "program with --v=1 or more"; // VLOG_EVERY_N(1, 10) // << "I'm printed every 10th occurrence, and when you run the program " -// "with --v=1 or more. Present occurence is " << COUNTER; +// "with --v=1 or more. Present occurence is " << google::COUNTER; // VLOG_IF_EVERY_N(1, (size > 1024), 10) // << "I'm printed on every 10th occurence of case when size is more " // " than 1024, when you run the program with --v=1 or more. "; -// "Present occurence is " << COUNTER; +// "Present occurence is " << google::COUNTER; // // The supported severity levels for macros that allow you to specify one // are (in increasing order of severity) INFO, WARNING, ERROR, and FATAL. @@ -386,7 +386,7 @@ DECLARE_bool(stop_logging_if_full_disk); #define COMPACT_GOOGLE_LOG_INFO google::LogMessage( \ __FILE__, __LINE__) #define LOG_TO_STRING_INFO(message) google::LogMessage( \ - __FILE__, __LINE__, google::INFO, message) + __FILE__, __LINE__, google::GLOG_INFO, message) #else #define COMPACT_GOOGLE_LOG_INFO google::NullStream() #define LOG_TO_STRING_INFO(message) google::NullStream() @@ -394,9 +394,9 @@ DECLARE_bool(stop_logging_if_full_disk); #if GOOGLE_STRIP_LOG <= 1 #define COMPACT_GOOGLE_LOG_WARNING google::LogMessage( \ - __FILE__, __LINE__, google::WARNING) + __FILE__, __LINE__, google::GLOG_WARNING) #define LOG_TO_STRING_WARNING(message) google::LogMessage( \ - __FILE__, __LINE__, google::WARNING, message) + __FILE__, __LINE__, google::GLOG_WARNING, message) #else #define COMPACT_GOOGLE_LOG_WARNING google::NullStream() #define LOG_TO_STRING_WARNING(message) google::NullStream() @@ -404,9 +404,9 @@ DECLARE_bool(stop_logging_if_full_disk); #if GOOGLE_STRIP_LOG <= 2 #define COMPACT_GOOGLE_LOG_ERROR google::LogMessage( \ - __FILE__, __LINE__, google::ERROR) + __FILE__, __LINE__, google::GLOG_ERROR) #define LOG_TO_STRING_ERROR(message) google::LogMessage( \ - __FILE__, __LINE__, google::ERROR, message) + __FILE__, __LINE__, google::GLOG_ERROR, message) #else #define COMPACT_GOOGLE_LOG_ERROR google::NullStream() #define LOG_TO_STRING_ERROR(message) google::NullStream() @@ -416,7 +416,7 @@ DECLARE_bool(stop_logging_if_full_disk); #define COMPACT_GOOGLE_LOG_FATAL google::LogMessageFatal( \ __FILE__, __LINE__) #define LOG_TO_STRING_FATAL(message) google::LogMessage( \ - __FILE__, __LINE__, google::FATAL, message) + __FILE__, __LINE__, google::GLOG_FATAL, message) #else #define COMPACT_GOOGLE_LOG_FATAL google::NullStreamFatal() #define LOG_TO_STRING_FATAL(message) google::NullStreamFatal() @@ -428,32 +428,32 @@ DECLARE_bool(stop_logging_if_full_disk); #define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR #elif GOOGLE_STRIP_LOG <= 3 #define COMPACT_GOOGLE_LOG_DFATAL google::LogMessage( \ - __FILE__, __LINE__, google::FATAL) + __FILE__, __LINE__, google::GLOG_FATAL) #else #define COMPACT_GOOGLE_LOG_DFATAL google::NullStreamFatal() #endif -#define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::INFO, counter, &google::LogMessage::SendToLog) +#define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, &google::LogMessage::SendToLog) #define SYSLOG_INFO(counter) \ - google::LogMessage(__FILE__, __LINE__, google::INFO, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_WARNING(counter) \ - google::LogMessage(__FILE__, __LINE__, google::WARNING, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \ &google::LogMessage::SendToLog) #define SYSLOG_WARNING(counter) \ - google::LogMessage(__FILE__, __LINE__, google::WARNING, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_ERROR(counter) \ - google::LogMessage(__FILE__, __LINE__, google::ERROR, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \ &google::LogMessage::SendToLog) #define SYSLOG_ERROR(counter) \ - google::LogMessage(__FILE__, __LINE__, google::ERROR, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_FATAL(counter) \ - google::LogMessage(__FILE__, __LINE__, google::FATAL, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \ &google::LogMessage::SendToLog) #define SYSLOG_FATAL(counter) \ - google::LogMessage(__FILE__, __LINE__, google::FATAL, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_DFATAL(counter) \ google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \ @@ -472,7 +472,7 @@ DECLARE_bool(stop_logging_if_full_disk); FORMAT_MESSAGE_FROM_SYSTEM, \ 0, result, 0, msg, 100, NULL); \ if (message_length > 0) { \ - google::LogMessage(__FILE__, __LINE__, ERROR, 0, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, 0, \ &google::LogMessage::SendToLog).stream() << message; \ LocalFree(message); \ } \ @@ -519,12 +519,12 @@ class LogSink; // defined below #define LOG_TO_SINK(sink, severity) \ google::LogMessage( \ __FILE__, __LINE__, \ - google::severity, \ + google::GLOG_ ## severity, \ static_cast(sink), true).stream() #define LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity) \ google::LogMessage( \ __FILE__, __LINE__, \ - google::severity, \ + google::GLOG_ ## severity, \ static_cast(sink), false).stream() // If a non-NULL string pointer is given, we write this message to that string. @@ -789,7 +789,7 @@ DECLARE_CHECK_STROP_IMPL(strcasecmp, false) #define GOOGLE_PLOG(severity, counter) \ google::ErrnoLogMessage( \ - __FILE__, __LINE__, google::severity, counter, \ + __FILE__, __LINE__, google::GLOG_ ## severity, counter, \ &google::LogMessage::SendToLog) #define PLOG_IF(severity, condition) \ @@ -828,7 +828,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \ if (LOG_OCCURRENCES_MOD_N == 1) \ google::LogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() #define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \ @@ -837,7 +837,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ if (condition && \ ((LOG_OCCURRENCES_MOD_N=(LOG_OCCURRENCES_MOD_N + 1) % n) == (1 % n))) \ google::LogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() #define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \ @@ -846,7 +846,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \ if (LOG_OCCURRENCES_MOD_N == 1) \ google::ErrnoLogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() #define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \ @@ -855,7 +855,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ ++LOG_OCCURRENCES; \ if (LOG_OCCURRENCES <= n) \ google::LogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() namespace glog_internal_namespace_ { @@ -869,7 +869,7 @@ struct CrashReason; typedef google::glog_internal_namespace_::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] #define LOG_EVERY_N(severity, n) \ - GOOGLE_GLOG_COMPILE_ASSERT(google::severity < \ + GOOGLE_GLOG_COMPILE_ASSERT(google::GLOG_ ## severity < \ google::NUM_SEVERITIES, \ INVALID_REQUESTED_LOG_SEVERITY); \ SOME_KIND_OF_LOG_EVERY_N(severity, (n), google::LogMessage::SendToLog) @@ -889,6 +889,27 @@ struct CrashReason; // We want the special COUNTER value available for LOG_EVERY_X()'ed messages enum PRIVATE_Counter {COUNTER}; +#ifdef GLOG_NO_ABBREVIATED_SEVERITIES +// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets +// substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us +// to keep using this syntax, we define this macro to do the same thing +// as COMPACT_GOOGLE_LOG_ERROR. +#define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR +#define SYSLOG_0 SYSLOG_ERROR +#define LOG_TO_STRING_0 LOG_TO_STRING_ERROR +// Needed for LOG_IS_ON(ERROR). +const LogSeverity GLOG_0 = GLOG_ERROR; +#else +// Users may include windows.h after logging.h without +// GLOG_NO_ABBREVIATED_SEVERITIES nor WIN32_LEAN_AND_MEAN. +// For this case, we cannot detect if ERROR is defined before users +// actually use ERROR. Let's make an undefined symbol to warn users. +# define GLOG_ERROR_MSG ERROR_macro_is_defined_Define_GLOG_NO_ABBREVIATED_SEVERITIES_before_including_logging_h_See_the_document_for_detail +# define COMPACT_GOOGLE_LOG_0 GLOG_ERROR_MSG +# define SYSLOG_0 GLOG_ERROR_MSG +# define LOG_TO_STRING_0 GLOG_ERROR_MSG +# define GLOG_0 GLOG_ERROR_MSG +#endif // Plus some debug-logging macros that get compiled to nothing for production @@ -1033,14 +1054,14 @@ public: # pragma warning(default: 4275) #endif public: - LogStream(char *buf, int len, int ctr) + LogStream(char *buf, int len, int ctr_in) : ostrstream(buf, len), - ctr_(ctr) { + ctr_(ctr_in) { self_ = this; } int ctr() const { return ctr_; } - void set_ctr(int ctr) { ctr_ = ctr; } + void set_ctr(int ctr_in) { ctr_ = ctr_in; } LogStream* self() const { return self_; } private: @@ -1482,7 +1503,7 @@ class GOOGLE_GLOG_DLL_DECL NullStream : public LogMessage::LogStream { // converted to LogStream and the message will be computed and then // quietly discarded. template -inline NullStream& operator<<(NullStream &str, const T &value) { return str; } +inline NullStream& operator<<(NullStream &str, const T &) { return str; } // Similar to NullStream, but aborts the program (without stack // trace), like LogMessageFatal. diff --git a/extern/libmv/third_party/glog/src/windows/glog/raw_logging.h b/extern/libmv/third_party/glog/src/windows/glog/raw_logging.h index c81e67bf99c..4757a719db7 100644 --- a/extern/libmv/third_party/glog/src/windows/glog/raw_logging.h +++ b/extern/libmv/third_party/glog/src/windows/glog/raw_logging.h @@ -72,7 +72,7 @@ namespace google { // I0821 211317 file.cc:142] RAW: status is 20 #define RAW_LOG(severity, ...) \ do { \ - switch (google::severity) { \ + switch (google::GLOG_ ## severity) { \ case 0: \ RAW_LOG_INFO(__VA_ARGS__); \ break; \ @@ -104,28 +104,28 @@ namespace google { #endif // STRIP_LOG == 0 #if STRIP_LOG == 0 -#define RAW_LOG_INFO(...) google::RawLog__(google::INFO, \ +#define RAW_LOG_INFO(...) google::RawLog__(google::GLOG_INFO, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__) #endif // STRIP_LOG == 0 #if STRIP_LOG <= 1 -#define RAW_LOG_WARNING(...) google::RawLog__(google::WARNING, \ +#define RAW_LOG_WARNING(...) google::RawLog__(google::GLOG_WARNING, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__) #endif // STRIP_LOG <= 1 #if STRIP_LOG <= 2 -#define RAW_LOG_ERROR(...) google::RawLog__(google::ERROR, \ +#define RAW_LOG_ERROR(...) google::RawLog__(google::GLOG_ERROR, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__) #endif // STRIP_LOG <= 2 #if STRIP_LOG <= 3 -#define RAW_LOG_FATAL(...) google::RawLog__(google::FATAL, \ +#define RAW_LOG_FATAL(...) google::RawLog__(google::GLOG_FATAL, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_FATAL(...) \ @@ -166,7 +166,7 @@ namespace google { // Stub log function used to work around for unused variable warnings when // building with STRIP_LOG > 0. -static inline void RawLogStub__(int ignored, ...) { +static inline void RawLogStub__(int /* ignored */, ...) { } // Helper function to implement RAW_LOG and RAW_VLOG diff --git a/extern/libmv/third_party/glog/src/windows/port.h b/extern/libmv/third_party/glog/src/windows/port.h index d5078120009..abfcf65384c 100644 --- a/extern/libmv/third_party/glog/src/windows/port.h +++ b/extern/libmv/third_party/glog/src/windows/port.h @@ -59,16 +59,14 @@ * used by both C and C++ code, so we put all the C++ together. */ -#if _MSC_VER - /* 4244: otherwise we get problems when substracting two size_t's to an int - * 4251: it's complaining about a private struct I've chosen not to dllexport - * 4355: we use this in a constructor, but we do it safely - * 4715: for some reason VC++ stopped realizing you can't return after abort() - * 4800: we know we're casting ints/char*'s to bools, and we're ok with that - * 4996: Yes, we're ok using "unsafe" functions like fopen() and strerror() - */ -# pragma warning(disable:4244 4251 4355 4715 4800 4996) -#endif +/* 4244: otherwise we get problems when substracting two size_t's to an int + * 4251: it's complaining about a private struct I've chosen not to dllexport + * 4355: we use this in a constructor, but we do it safely + * 4715: for some reason VC++ stopped realizing you can't return after abort() + * 4800: we know we're casting ints/char*'s to bools, and we're ok with that + * 4996: Yes, we're ok using "unsafe" functions like fopen() and strerror() + */ +#pragma warning(disable:4244 4251 4355 4715 4800 4996) /* file I/O */ #define PATH_MAX 1024 diff --git a/extern/libmv/third_party/glog/src/windows/preprocess.sh b/extern/libmv/third_party/glog/src/windows/preprocess.sh old mode 100755 new mode 100644 From b330abc290622b32419ba084b8bc7e6a8ea9aaa2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Mar 2012 19:58:56 +0000 Subject: [PATCH 015/310] remove Object member from BMesh struct - was only used for undo and BMEditMesh already stores an object pointer. also fix for own mistake with mesh conversion refactor, shape key index was off by 1 when switching editmode. --- source/blender/blenkernel/BKE_DerivedMesh.h | 4 ++-- source/blender/blenkernel/intern/mesh.c | 2 +- source/blender/blenkernel/intern/modifiers_bmesh.c | 8 ++++---- source/blender/bmesh/bmesh_class.h | 3 +-- source/blender/bmesh/intern/bmesh_construct.c | 2 +- source/blender/bmesh/intern/bmesh_mesh.c | 14 +++----------- source/blender/bmesh/intern/bmesh_mesh.h | 2 +- source/blender/bmesh/intern/bmesh_mesh_conv.c | 2 +- source/blender/bmesh/operators/bmo_mesh_conv.c | 2 +- source/blender/editors/mesh/bmesh_tools.c | 2 +- source/blender/editors/mesh/bmesh_utils.c | 11 +++++++++-- source/blender/editors/transform/transform.c | 6 ++---- source/blender/modifiers/intern/MOD_array.c | 6 +++--- source/blender/modifiers/intern/MOD_bevel.c | 10 +++++----- source/blender/modifiers/intern/MOD_edgesplit.c | 4 ++-- source/blender/python/bmesh/bmesh_py_api.c | 2 +- 16 files changed, 38 insertions(+), 42 deletions(-) diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 87ba2092437..b8cedfb5708 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -447,12 +447,12 @@ int DM_release(DerivedMesh *dm); */ void DM_to_mesh(DerivedMesh *dm, struct Mesh *me, struct Object *ob); -struct BMEditMesh *DM_to_editbmesh(struct Object *ob, struct DerivedMesh *dm, +struct BMEditMesh *DM_to_editbmesh(struct DerivedMesh *dm, struct BMEditMesh *existing, int do_tesselate); /* conversion to bmesh only */ void DM_to_bmesh_ex(struct DerivedMesh *dm, struct BMesh *bm); -struct BMesh *DM_to_bmesh(struct Object *ob, struct DerivedMesh *dm); +struct BMesh *DM_to_bmesh(struct DerivedMesh *dm); /* utility function to convert a DerivedMesh to a shape key block diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 909a87cfd4b..054cbe0021b 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -546,7 +546,7 @@ BMesh *BKE_mesh_to_bmesh(Mesh *me, Object *ob) { BMesh *bm; - bm = BM_mesh_create(ob, &bm_mesh_allocsize_default); + bm = BM_mesh_create(&bm_mesh_allocsize_default); BMO_op_callf(bm, "mesh_to_bmesh mesh=%p object=%p set_shapekey=%b", me, ob, TRUE); diff --git a/source/blender/blenkernel/intern/modifiers_bmesh.c b/source/blender/blenkernel/intern/modifiers_bmesh.c index 8fe8c9cbaed..46bdcc6fdd8 100644 --- a/source/blender/blenkernel/intern/modifiers_bmesh.c +++ b/source/blender/blenkernel/intern/modifiers_bmesh.c @@ -137,7 +137,7 @@ void DM_to_bmesh_ex(DerivedMesh *dm, BMesh *bm) /* converts a cddm to a BMEditMesh. if existing is non-NULL, the * new geometry will be put in there.*/ -BMEditMesh *DM_to_editbmesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, int do_tesselate) +BMEditMesh *DM_to_editbmesh(DerivedMesh *dm, BMEditMesh *existing, int do_tesselate) { BMEditMesh *em = existing; BMesh *bm; @@ -146,7 +146,7 @@ BMEditMesh *DM_to_editbmesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, i bm = em->bm; } else { - bm = BM_mesh_create(ob, &bm_mesh_allocsize_default); + bm = BM_mesh_create(&bm_mesh_allocsize_default); } DM_to_bmesh_ex(dm, bm); @@ -163,11 +163,11 @@ BMEditMesh *DM_to_editbmesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, i return em; } -BMesh *DM_to_bmesh(Object *ob, DerivedMesh *dm) +BMesh *DM_to_bmesh(DerivedMesh *dm) { BMesh *bm; - bm = BM_mesh_create(ob, &bm_mesh_allocsize_default); + bm = BM_mesh_create(&bm_mesh_allocsize_default); DM_to_bmesh_ex(dm, bm); diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h index 02953f84a22..8d79ba52953 100644 --- a/source/blender/bmesh/bmesh_class.h +++ b/source/blender/bmesh/bmesh_class.h @@ -194,8 +194,7 @@ typedef struct BMesh { BMFace *act_face; ListBase errorstack; - struct Object *ob; /* owner object */ - + void *py_handle; int opflag; /* current operator flag */ diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index f58c1141561..b27f40777e6 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -593,7 +593,7 @@ BMesh *BM_mesh_copy(BMesh *bm_old) bm_old->totface}; /* allocate a bmesh */ - bm_new = BM_mesh_create(bm_old->ob, &allocsize); + bm_new = BM_mesh_create(&allocsize); CustomData_copy(&bm_old->vdata, &bm_new->vdata, CD_MASK_BMESH, CD_CALLOC, 0); CustomData_copy(&bm_old->edata, &bm_new->edata, CD_MASK_BMESH, CD_CALLOC, 0); diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index c01e8afd716..04279d30e61 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -71,12 +71,10 @@ static void bm_mempool_init(BMesh *bm, const BMAllocTemplate *allocsize) * * \note ob is needed by multires */ -BMesh *BM_mesh_create(struct Object *ob, BMAllocTemplate *allocsize) +BMesh *BM_mesh_create(BMAllocTemplate *allocsize) { /* allocate the structure */ BMesh *bm = MEM_callocN(sizeof(BMesh), __func__); - - bm->ob = ob; /* allocate the memory pools for the mesh elements */ bm_mempool_init(bm, allocsize); @@ -164,15 +162,10 @@ void BM_mesh_data_free(BMesh *bm) */ void BM_mesh_clear(BMesh *bm) { - Object *ob = bm->ob; - /* free old mesh */ BM_mesh_data_free(bm); memset(bm, 0, sizeof(BMesh)); - - /* re-initialize mesh */ - bm->ob = ob; - + /* allocate the memory pools for the mesh elements */ bm_mempool_init(bm, &bm_mesh_allocsize_default); @@ -344,11 +337,10 @@ static void bm_rationalize_normals(BMesh *bm, int undo) BMO_op_finish(bm, &bmop); } -static void UNUSED_FUNCTION(bm_mdisps_space_set)(BMesh *bm, int from, int to) +static void UNUSED_FUNCTION(bm_mdisps_space_set)(Object *ob, BMesh *bm, int from, int to) { /* switch multires data out of tangent space */ if (CustomData_has_layer(&bm->ldata, CD_MDISPS)) { - Object *ob = bm->ob; BMEditMesh *em = BMEdit_Create(bm, FALSE); DerivedMesh *dm = CDDM_from_BMEditMesh(em, NULL, TRUE, FALSE); MDisps *mdisps; diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h index d045cd8be90..f48cc09af3b 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.h +++ b/source/blender/bmesh/intern/bmesh_mesh.h @@ -29,7 +29,7 @@ struct BMAllocTemplate; -BMesh *BM_mesh_create(struct Object *ob, struct BMAllocTemplate *allocsize); +BMesh *BM_mesh_create(struct BMAllocTemplate *allocsize); void BM_mesh_free(BMesh *bm); void BM_mesh_data_free(BMesh *bm); diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.c b/source/blender/bmesh/intern/bmesh_mesh_conv.c index 3b7f5182d2d..24cb2bc4d5a 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_conv.c +++ b/source/blender/bmesh/intern/bmesh_mesh_conv.c @@ -582,7 +582,7 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, int dotess) int i, j; for (ob = G.main->object.first; ob; ob = ob->id.next) { - if (ob->parent == bm->ob && ELEM(ob->partype, PARVERT1, PARVERT3)) { + if ((ob->parent) && (ob->parent->data == me) && ELEM(ob->partype, PARVERT1, PARVERT3)) { if (vertMap == NULL) { vertMap = bm_to_mesh_vertex_map(bm, ototvert); diff --git a/source/blender/bmesh/operators/bmo_mesh_conv.c b/source/blender/bmesh/operators/bmo_mesh_conv.c index 651093806b6..4578270d571 100644 --- a/source/blender/bmesh/operators/bmo_mesh_conv.c +++ b/source/blender/bmesh/operators/bmo_mesh_conv.c @@ -57,7 +57,7 @@ void bmo_mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) Mesh *me = BMO_slot_ptr_get(op, "mesh"); int set_key = BMO_slot_bool_get(op, "set_shapekey"); - BM_mesh_bm_from_me(bm, me, set_key, ob->shapenr - 1); + BM_mesh_bm_from_me(bm, me, set_key, ob->shapenr); if (me->key && ob->shapenr > me->key->totkey) { ob->shapenr = me->key->totkey - 1; diff --git a/source/blender/editors/mesh/bmesh_tools.c b/source/blender/editors/mesh/bmesh_tools.c index da08b3354e1..bbfbb16a5bb 100644 --- a/source/blender/editors/mesh/bmesh_tools.c +++ b/source/blender/editors/mesh/bmesh_tools.c @@ -3222,7 +3222,7 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO if (!em) return OPERATOR_CANCELLED; - bm_new = BM_mesh_create(obedit, &bm_mesh_allocsize_default); + bm_new = BM_mesh_create(&bm_mesh_allocsize_default); CustomData_copy(&em->bm->vdata, &bm_new->vdata, CD_MASK_BMESH, CD_CALLOC, 0); CustomData_copy(&em->bm->edata, &bm_new->edata, CD_MASK_BMESH, CD_CALLOC, 0); CustomData_copy(&em->bm->ldata, &bm_new->ldata, CD_MASK_BMESH, CD_CALLOC, 0); diff --git a/source/blender/editors/mesh/bmesh_utils.c b/source/blender/editors/mesh/bmesh_utils.c index bee4d4283f6..8ca5dce647f 100644 --- a/source/blender/editors/mesh/bmesh_utils.c +++ b/source/blender/editors/mesh/bmesh_utils.c @@ -514,7 +514,7 @@ static void *editbtMesh_to_undoMesh(void *emv, void *obdata) Mesh *obme = obdata; undomesh *um = MEM_callocN(sizeof(undomesh), "undo Mesh"); - BLI_strncpy(um->obname, em->bm->ob->id.name + 2, sizeof(um->obname)); + BLI_strncpy(um->obname, em->ob->id.name + 2, sizeof(um->obname)); /* make sure shape keys work */ um->me.key = obme->key ? copy_key_nolib(obme->key) : NULL; @@ -546,7 +546,7 @@ static void undoMesh_to_editbtMesh(void *umv, void *emv, void *UNUSED(obdata)) BMEdit_Free(em); - bm = BM_mesh_create(ob, &bm_mesh_allocsize_default); + bm = BM_mesh_create(&bm_mesh_allocsize_default); BMO_op_callf(bm, "mesh_to_bmesh mesh=%p object=%p set_shapekey=%b", &um->me, ob, FALSE); em2 = BMEdit_Create(bm, TRUE); @@ -572,6 +572,13 @@ static void free_undo(void *umv) /* and this is all the undo system needs to know */ void undo_push_mesh(bContext *C, const char *name) { + /* em->ob gets out of date and crashes on mesh undo, + * this is an easy way to ensure its OK + * though we could investigate the matter further. */ + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = BMEdit_FromObject(obedit); + em->ob = obedit; + undo_editmode_push(C, name, getEditMesh, free_undo, undoMesh_to_editbtMesh, editbtMesh_to_undoMesh, NULL); } diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 666d0a2f7f2..7b98a2f0083 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -4552,7 +4552,7 @@ static int createSlideVerts(TransInfo *t) float vec1[3], dis2, mval[2] = {t->mval[0], t->mval[1]}, d; /* search cross edges for visible edge to the mouse cursor, - * then use the shared vertex to calculate screen vector*/ + * then use the shared vertex to calculate screen vector*/ dis2 = -1.0f; for (i=0; i<2; i++) { v = i?e->v1:e->v2; @@ -4590,8 +4590,7 @@ static int createSlideVerts(TransInfo *t) } } } - - em->bm->ob = t->obedit; + bmesh_edit_begin(em->bm, BMO_OP_FLAG_UNTAN_MULTIRES); /*create copies of faces for customdata projection*/ @@ -4779,7 +4778,6 @@ void freeSlideVerts(TransInfo *t) freeSlideTempFaces(sld); - sld->em->bm->ob = t->obedit; bmesh_edit_end(sld->em->bm, BMO_OP_FLAG_UNTAN_MULTIRES); BLI_smallhash_release(&sld->vhash); diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c index 2fbec392b1e..05fcb04d7ea 100644 --- a/source/blender/modifiers/intern/MOD_array.c +++ b/source/blender/modifiers/intern/MOD_array.c @@ -186,11 +186,11 @@ static void bm_merge_dm_transform(BMesh* bm, DerivedMesh *dm, float mat[4][4]) } static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, - Scene *scene, Object *ob, DerivedMesh *dm, - int UNUSED(initFlags)) + Scene *scene, Object *ob, DerivedMesh *dm, + int UNUSED(initFlags)) { DerivedMesh *result; - BMEditMesh *em = DM_to_editbmesh(ob, dm, NULL, FALSE); + BMEditMesh *em = DM_to_editbmesh(dm, NULL, FALSE); BMOperator op, oldop, weldop; int i, j, indexLen; /* offset matrix */ diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c index 3e110909702..112b9398d23 100644 --- a/source/blender/modifiers/intern/MOD_bevel.c +++ b/source/blender/modifiers/intern/MOD_bevel.c @@ -105,10 +105,10 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) * note: this code is very close to MOD_edgesplit.c. * note: if 0'd code from trunk included below. */ -static DerivedMesh *applyModifier(ModifierData *md, struct Object *ob, - DerivedMesh *dm, - int UNUSED(useRenderParams), - int UNUSED(isFinalCalc)) +static DerivedMesh *applyModifier(ModifierData *md, struct Object *UNUSED(ob), + DerivedMesh *dm, + int UNUSED(useRenderParams), + int UNUSED(isFinalCalc)) { DerivedMesh *result; BMesh *bm; @@ -118,7 +118,7 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Object *ob, BevelModifierData *bmd = (BevelModifierData*) md; float threshold = cos((bmd->bevel_angle + 0.00001) * M_PI / 180.0); - em = DM_to_editbmesh(ob, dm, NULL, FALSE); + em = DM_to_editbmesh(dm, NULL, FALSE); bm = em->bm; BM_mesh_normals_update(bm, FALSE); diff --git a/source/blender/modifiers/intern/MOD_edgesplit.c b/source/blender/modifiers/intern/MOD_edgesplit.c index 481ab805c5a..9fb4821229c 100644 --- a/source/blender/modifiers/intern/MOD_edgesplit.c +++ b/source/blender/modifiers/intern/MOD_edgesplit.c @@ -57,7 +57,7 @@ #define EDGE_MARK 1 -static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd, Object *ob) +static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd, Object *UNUSED(ob)) { DerivedMesh *result; BMesh *bm; @@ -66,7 +66,7 @@ static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd, Obj BMEdge *e; float threshold = cos((emd->split_angle + 0.00001) * M_PI / 180.0); - em = DM_to_editbmesh(ob, dm, NULL, FALSE); + em = DM_to_editbmesh(dm, NULL, FALSE); bm = em->bm; BM_mesh_normals_update(bm, FALSE); diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c index 1601034542b..d3dcc979015 100644 --- a/source/blender/python/bmesh/bmesh_py_api.c +++ b/source/blender/python/bmesh/bmesh_py_api.c @@ -59,7 +59,7 @@ static PyObject *bpy_bm_new(PyObject *UNUSED(self)) { BMesh *bm; - bm = BM_mesh_create(NULL, &bm_mesh_allocsize_default); + bm = BM_mesh_create(&bm_mesh_allocsize_default); return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_NOP); } From d6b8b0330534e26c5cf2872121889932b5b14d87 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sun, 11 Mar 2012 20:01:26 +0000 Subject: [PATCH 016/310] Port changes from libmv/CMakeLists.txt to build rules files generator script --- extern/libmv/bundle.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extern/libmv/bundle.sh b/extern/libmv/bundle.sh index f259635035e..fbf4364f7fe 100755 --- a/extern/libmv/bundle.sh +++ b/extern/libmv/bundle.sh @@ -129,6 +129,9 @@ set(INC set(INC_SYS \${PNG_INCLUDE_DIR} \${ZLIB_INCLUDE_DIRS} + if(\${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.6") # this is a momentary hack to find unwind.h in 10.6.sdk + \${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include + endif() ) set(SRC From 33d81047163cf13c45e6f9914a10d16a768d954b Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Sun, 11 Mar 2012 20:45:58 +0000 Subject: [PATCH 017/310] Fix edge loop selection. Now boundary selection checks only for filled edges to determine when to stop and stops at vertices shared by only 2 edges. --- source/blender/bmesh/intern/bmesh_queries.c | 17 +++++++++++++++++ source/blender/bmesh/intern/bmesh_queries.h | 2 ++ .../blender/bmesh/intern/bmesh_walkers_impl.c | 9 +++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index 4d9b21e391c..357afbe391e 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -291,6 +291,23 @@ int BM_vert_edge_count(BMVert *v) return bmesh_disk_count(v); } +int BM_vert_edge_count_nonwire( BMesh *bm, BMVert *v) +{ + int count = 0; + BMIter eiter; + BMEdge *edge; + BM_ITER(edge, &eiter, bm, BM_EDGES_OF_VERT, v){ + if (!edge) return count; + + if (count >= (1 << 20)) { + printf(" bmesh error: infinite loop in disk cycle!\n"); + return 0; + } + + if(edge->l) count++; + } + return count; +} /** * Returns the number of faces around this edge */ diff --git a/source/blender/bmesh/intern/bmesh_queries.h b/source/blender/bmesh/intern/bmesh_queries.h index 6975c40c10a..0ce5fb3a665 100644 --- a/source/blender/bmesh/intern/bmesh_queries.h +++ b/source/blender/bmesh/intern/bmesh_queries.h @@ -49,6 +49,8 @@ int BM_vert_face_count(BMVert *v); int BM_vert_is_wire(BMesh *bm, BMVert *v); int BM_edge_is_wire(BMesh *bm, BMEdge *e); +int BM_vert_edge_count_nonwire( BMesh *bm, BMVert *v); + int BM_vert_is_manifold(BMesh *bm, BMVert *v); int BM_edge_is_manifold(BMesh *bm, BMEdge *e); int BM_edge_is_boundary(BMEdge *e); diff --git a/source/blender/bmesh/intern/bmesh_walkers_impl.c b/source/blender/bmesh/intern/bmesh_walkers_impl.c index 30bbc9e9b2a..20386a78604 100644 --- a/source/blender/bmesh/intern/bmesh_walkers_impl.c +++ b/source/blender/bmesh/intern/bmesh_walkers_impl.c @@ -464,11 +464,12 @@ static void *bmw_LoopWalker_step(BMWalker *walker) v = (e->v1 == lwalk->lastv) ? e->v2 : e->v1; - val = BM_vert_edge_count(v); - rlen = owalk.startrad; - if (val == 4 || val == 2 || rlen == 1) { + val = BM_vert_edge_count_nonwire(walker->bm, v); + + /* however, why use 2 here at all? I guess for internal ngon loops it can be useful. Antony R. */ + if (((val == 4 || val == 2) && rlen > 1) || (rlen == 1 && val > 2)) { i = 0; stopi = val / 2; while (1) { @@ -481,7 +482,7 @@ static void *bmw_LoopWalker_step(BMWalker *walker) l2 = l->radial_next; - if (l2 == l) { + if (l2 == l || !l2) { break; } From ac24d98e24c0d8d1dfd005d4f332e906f1b9664c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Mar 2012 21:47:14 +0000 Subject: [PATCH 018/310] bmesh: edge loop select add support for loop selecting boundry edges only - handy for loop selecting the side of an ngon. --- source/blender/bmesh/intern/bmesh_queries.c | 13 ++----- source/blender/bmesh/intern/bmesh_queries.h | 3 +- .../blender/bmesh/intern/bmesh_walkers_impl.c | 39 +++++++++++++------ .../bmesh/intern/bmesh_walkers_private.h | 4 +- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index 357afbe391e..cc9dfe1701b 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -291,20 +291,15 @@ int BM_vert_edge_count(BMVert *v) return bmesh_disk_count(v); } -int BM_vert_edge_count_nonwire( BMesh *bm, BMVert *v) +int BM_vert_edge_count_nonwire(BMVert *v) { int count = 0; BMIter eiter; BMEdge *edge; - BM_ITER(edge, &eiter, bm, BM_EDGES_OF_VERT, v){ - if (!edge) return count; - - if (count >= (1 << 20)) { - printf(" bmesh error: infinite loop in disk cycle!\n"); - return 0; + BM_ITER(edge, &eiter, NULL, BM_EDGES_OF_VERT, v){ + if(edge->l) { + count++; } - - if(edge->l) count++; } return count; } diff --git a/source/blender/bmesh/intern/bmesh_queries.h b/source/blender/bmesh/intern/bmesh_queries.h index 0ce5fb3a665..2524d090a4e 100644 --- a/source/blender/bmesh/intern/bmesh_queries.h +++ b/source/blender/bmesh/intern/bmesh_queries.h @@ -42,6 +42,7 @@ BMVert *BM_edge_other_vert(BMEdge *e, BMVert *v); BMLoop *BM_face_other_edge_loop(BMFace *f, BMEdge *e, BMVert *v); BMLoop *BM_face_other_vert_loop(BMFace *f, BMVert *v_prev, BMVert *v); +int BM_vert_edge_count_nonwire(BMVert *v); int BM_vert_edge_count(BMVert *v); int BM_edge_face_count(BMEdge *e); int BM_vert_face_count(BMVert *v); @@ -49,8 +50,6 @@ int BM_vert_face_count(BMVert *v); int BM_vert_is_wire(BMesh *bm, BMVert *v); int BM_edge_is_wire(BMesh *bm, BMEdge *e); -int BM_vert_edge_count_nonwire( BMesh *bm, BMVert *v); - int BM_vert_is_manifold(BMesh *bm, BMVert *v); int BM_edge_is_manifold(BMesh *bm, BMEdge *e); int BM_edge_is_boundary(BMEdge *e); diff --git a/source/blender/bmesh/intern/bmesh_walkers_impl.c b/source/blender/bmesh/intern/bmesh_walkers_impl.c index 20386a78604..cd815c9be83 100644 --- a/source/blender/bmesh/intern/bmesh_walkers_impl.c +++ b/source/blender/bmesh/intern/bmesh_walkers_impl.c @@ -398,7 +398,9 @@ static void bmw_LoopWalker_begin(BMWalker *walker, void *data) lwalk->cur = lwalk->start = e; lwalk->lastv = lwalk->startv = v; lwalk->stage2 = 0; - lwalk->startrad = BM_edge_face_count(e); + lwalk->is_boundry = BM_edge_is_boundary(e); + lwalk->is_single = (BM_vert_edge_count_nonwire(e->v1) == 2 && + BM_vert_edge_count_nonwire(e->v2) == 2); /* rewin */ while (BMW_current_state(walker)) { @@ -433,7 +435,9 @@ static void *bmw_LoopWalker_step(BMWalker *walker) BMEdge *e = lwalk->cur, *nexte = NULL; BMLoop *l, *l2; BMVert *v; - int val, rlen /* , found = 0 */, i = 0, stopi; + int vert_edge_tot; + int i = 0, stopi; + /* int found = 0; */ /* UNUSED */ owalk = *lwalk; BMW_state_remove(walker); @@ -452,7 +456,8 @@ static void *bmw_LoopWalker_step(BMWalker *walker) lwalk = BMW_state_add(walker); lwalk->cur = nexte; lwalk->lastv = v; - lwalk->startrad = owalk.startrad; + lwalk->is_boundry = owalk.is_boundry; + lwalk->is_single = owalk.is_single; BLI_ghash_insert(walker->visithash, nexte, NULL); } @@ -462,18 +467,27 @@ static void *bmw_LoopWalker_step(BMWalker *walker) return owalk.cur; } - v = (e->v1 == lwalk->lastv) ? e->v2 : e->v1; + v = BM_edge_other_vert(e, lwalk->lastv); - rlen = owalk.startrad; + vert_edge_tot = BM_vert_edge_count_nonwire(v); - val = BM_vert_edge_count_nonwire(walker->bm, v); + if (/* check if we should step, this is fairly involved */ - /* however, why use 2 here at all? I guess for internal ngon loops it can be useful. Antony R. */ - if (((val == 4 || val == 2) && rlen > 1) || (rlen == 1 && val > 2)) { + /* typical loopiong over edges in the middle of a mesh */ + /* however, why use 2 here at all? I guess for internal ngon loops it can be useful. Antony R. */ + ((vert_edge_tot == 4 || vert_edge_tot == 2) && owalk.is_boundry == FALSE) || + + /* walk over boundry of faces but stop at corners */ + (owalk.is_boundry == TRUE && owalk.is_single == FALSE && vert_edge_tot > 2) || + + /* initial edge was a boundry, so is this edge and vertex is only apart of this face + * this lets us walk over the the boundry of an ngon which is handy */ + (owalk.is_boundry == TRUE && owalk.is_single == TRUE && vert_edge_tot == 2 && BM_edge_is_boundary(e))) + { i = 0; - stopi = val / 2; + stopi = vert_edge_tot / 2; while (1) { - if (rlen != 1 && i == stopi) break; + if (owalk.is_boundry == FALSE && i == stopi) break; l = BM_face_other_edge_loop(l->f, l->e, v); @@ -496,11 +510,12 @@ static void *bmw_LoopWalker_step(BMWalker *walker) } if (l != e->l && !BLI_ghash_haskey(walker->visithash, l->e)) { - if (!(rlen != 1 && i != stopi)) { + if (!(owalk.is_boundry == FALSE && i != stopi)) { lwalk = BMW_state_add(walker); lwalk->cur = l->e; lwalk->lastv = v; - lwalk->startrad = owalk.startrad; + lwalk->is_boundry = owalk.is_boundry; + lwalk->is_single = owalk.is_single; BLI_ghash_insert(walker->visithash, l->e, NULL); } } diff --git a/source/blender/bmesh/intern/bmesh_walkers_private.h b/source/blender/bmesh/intern/bmesh_walkers_private.h index b1447b52d1a..d51a3b3ddb1 100644 --- a/source/blender/bmesh/intern/bmesh_walkers_private.h +++ b/source/blender/bmesh/intern/bmesh_walkers_private.h @@ -61,7 +61,9 @@ typedef struct BMwLoopWalker { BMwGenericWalker header; BMEdge *cur, *start; BMVert *lastv, *startv; - int startrad, stage2; + int stage2; + short is_boundry; /* boundry looping changes behavior */ + short is_single; /* single means the edge verts are only connected to 1 face */ } BMwLoopWalker; typedef struct BMwFaceLoopWalker { From cae11a98f98cf0fc299dbb641c6a748b83589054 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Mar 2012 23:47:41 +0000 Subject: [PATCH 019/310] style cleanup --- source/blender/blenlib/intern/BLI_ghash.c | 166 +++++++++--------- source/blender/blenlib/intern/BLI_heap.c | 35 ++-- source/blender/blenlib/intern/BLI_memarena.c | 65 ++++--- source/blender/blenlib/intern/BLI_mempool.c | 40 +++-- source/blender/blenlib/intern/bpath.c | 96 +++++----- .../blenlib/intern/string_cursor_utf8.c | 32 ++-- source/blender/blenlib/intern/uvproject.c | 101 ++++++----- .../editors/sculpt_paint/paint_vertex.c | 2 - 8 files changed, 268 insertions(+), 269 deletions(-) diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index b05a1c00d0f..49da6f9cb6b 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -33,11 +33,8 @@ #include #include - #include "MEM_guardedalloc.h" - - // #include "BLI_blenlib.h" #include "BLI_utildefines.h" @@ -47,7 +44,7 @@ #include "BLO_sys_types.h" // for intptr_t support /***/ -unsigned int hashsizes[]= { +unsigned int hashsizes[] = { 5, 11, 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209, 16411, 32771, 65537, 131101, 262147, 524309, 1048583, 2097169, 4194319, 8388617, 16777259, 33554467, 67108879, 134217757, @@ -58,18 +55,18 @@ unsigned int hashsizes[]= { GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) { - GHash *gh= MEM_mallocN(sizeof(*gh), info); - gh->hashfp= hashfp; - gh->cmpfp= cmpfp; + GHash *gh = MEM_mallocN(sizeof(*gh), info); + gh->hashfp = hashfp; + gh->cmpfp = cmpfp; gh->entrypool = BLI_mempool_create(sizeof(Entry), 64, 64, 0); - gh->cursize= 0; - gh->nentries= 0; - gh->nbuckets= hashsizes[gh->cursize]; - - gh->buckets= MEM_mallocN(gh->nbuckets*sizeof(*gh->buckets), "buckets"); - memset(gh->buckets, 0, gh->nbuckets*sizeof(*gh->buckets)); - + gh->cursize = 0; + gh->nentries = 0; + gh->nbuckets = hashsizes[gh->cursize]; + + gh->buckets = MEM_mallocN(gh->nbuckets * sizeof(*gh->buckets), "buckets"); + memset(gh->buckets, 0, gh->nbuckets * sizeof(*gh->buckets)); + return gh; } @@ -80,31 +77,31 @@ int BLI_ghash_size(GHash *gh) void BLI_ghash_insert(GHash *gh, void *key, void *val) { - unsigned int hash= gh->hashfp(key)%gh->nbuckets; - Entry *e= (Entry*) BLI_mempool_alloc(gh->entrypool); + unsigned int hash = gh->hashfp(key) % gh->nbuckets; + Entry *e = (Entry*)BLI_mempool_alloc(gh->entrypool); - e->key= key; - e->val= val; - e->next= gh->buckets[hash]; - gh->buckets[hash]= e; + e->key = key; + e->val = val; + e->next = gh->buckets[hash]; + gh->buckets[hash] = e; - if (++gh->nentries>(float)gh->nbuckets/2) { - Entry **old= gh->buckets; - int i, nold= gh->nbuckets; + if (++gh->nentries > (float)gh->nbuckets / 2) { + Entry **old = gh->buckets; + int i, nold = gh->nbuckets; - gh->nbuckets= hashsizes[++gh->cursize]; - gh->buckets= (Entry**)MEM_mallocN(gh->nbuckets*sizeof(*gh->buckets), "buckets"); - memset(gh->buckets, 0, gh->nbuckets*sizeof(*gh->buckets)); + gh->nbuckets = hashsizes[++gh->cursize]; + gh->buckets = (Entry**)MEM_mallocN(gh->nbuckets * sizeof(*gh->buckets), "buckets"); + memset(gh->buckets, 0, gh->nbuckets * sizeof(*gh->buckets)); - for (i=0; inext; + for (i = 0; i < nold; i++) { + for (e = old[i]; e;) { + Entry *n = e->next; - hash= gh->hashfp(e->key)%gh->nbuckets; - e->next= gh->buckets[hash]; - gh->buckets[hash]= e; + hash = gh->hashfp(e->key) % gh->nbuckets; + e->next = gh->buckets[hash]; + gh->buckets[hash] = e; - e= n; + e = n; } } @@ -114,33 +111,35 @@ void BLI_ghash_insert(GHash *gh, void *key, void *val) void *BLI_ghash_lookup(GHash *gh, const void *key) { - if(gh) { - unsigned int hash= gh->hashfp(key)%gh->nbuckets; + if (gh) { + unsigned int hash = gh->hashfp(key) % gh->nbuckets; Entry *e; - for (e= gh->buckets[hash]; e; e= e->next) - if (gh->cmpfp(key, e->key)==0) + for (e = gh->buckets[hash]; e; e = e->next) + if (gh->cmpfp(key, e->key) == 0) return e->val; } return NULL; } -int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) +int BLI_ghash_remove(GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) { - unsigned int hash= gh->hashfp(key)%gh->nbuckets; + unsigned int hash = gh->hashfp(key) % gh->nbuckets; Entry *e; Entry *p = NULL; - for (e= gh->buckets[hash]; e; e= e->next) { - if (gh->cmpfp(key, e->key)==0) { - Entry *n= e->next; + for (e = gh->buckets[hash]; e; e = e->next) { + if (gh->cmpfp(key, e->key) == 0) { + Entry *n = e->next; - if (keyfreefp) keyfreefp(e->key); - if (valfreefp) valfreefp(e->val); + if (keyfreefp) + keyfreefp(e->key); + if (valfreefp) + valfreefp(e->val); BLI_mempool_free(gh->entrypool, e); /* correct but 'e' isnt used before return */ - /* e= n; */ /*UNUSED*/ + /* e= n; *//*UNUSED*/ if (p) p->next = n; else @@ -157,11 +156,11 @@ int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFr int BLI_ghash_haskey(GHash *gh, void *key) { - unsigned int hash= gh->hashfp(key)%gh->nbuckets; + unsigned int hash = gh->hashfp(key) % gh->nbuckets; Entry *e; - for (e= gh->buckets[hash]; e; e= e->next) - if (gh->cmpfp(key, e->key)==0) + for (e = gh->buckets[hash]; e; e = e->next) + if (gh->cmpfp(key, e->key) == 0) return 1; return 0; @@ -170,22 +169,22 @@ int BLI_ghash_haskey(GHash *gh, void *key) void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) { int i; - + if (keyfreefp || valfreefp) { - for (i=0; inbuckets; i++) { + for (i = 0; i < gh->nbuckets; i++) { Entry *e; - - for (e= gh->buckets[i]; e; ) { - Entry *n= e->next; - + + for (e = gh->buckets[i]; e;) { + Entry *n = e->next; + if (keyfreefp) keyfreefp(e->key); if (valfreefp) valfreefp(e->val); - e= n; + e = n; } } } - + MEM_freeN(gh->buckets); BLI_mempool_destroy(gh->entrypool); gh->buckets = NULL; @@ -198,28 +197,28 @@ void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreef GHashIterator *BLI_ghashIterator_new(GHash *gh) { - GHashIterator *ghi= MEM_mallocN(sizeof(*ghi), "ghash iterator"); - ghi->gh= gh; - ghi->curEntry= NULL; - ghi->curBucket= -1; + GHashIterator *ghi = MEM_mallocN(sizeof(*ghi), "ghash iterator"); + ghi->gh = gh; + ghi->curEntry = NULL; + ghi->curBucket = -1; while (!ghi->curEntry) { ghi->curBucket++; - if (ghi->curBucket==ghi->gh->nbuckets) + if (ghi->curBucket == ghi->gh->nbuckets) break; - ghi->curEntry= ghi->gh->buckets[ghi->curBucket]; + ghi->curEntry = ghi->gh->buckets[ghi->curBucket]; } return ghi; } void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh) { - ghi->gh= gh; - ghi->curEntry= NULL; - ghi->curBucket= -1; + ghi->gh = gh; + ghi->curEntry = NULL; + ghi->curBucket = -1; while (!ghi->curEntry) { ghi->curBucket++; - if (ghi->curBucket==ghi->gh->nbuckets) + if (ghi->curBucket == ghi->gh->nbuckets) break; - ghi->curEntry= ghi->gh->buckets[ghi->curBucket]; + ghi->curEntry = ghi->gh->buckets[ghi->curBucket]; } } void BLI_ghashIterator_free(GHashIterator *ghi) @@ -229,22 +228,22 @@ void BLI_ghashIterator_free(GHashIterator *ghi) void *BLI_ghashIterator_getKey(GHashIterator *ghi) { - return ghi->curEntry?ghi->curEntry->key:NULL; + return ghi->curEntry ? ghi->curEntry->key : NULL; } void *BLI_ghashIterator_getValue(GHashIterator *ghi) { - return ghi->curEntry?ghi->curEntry->val:NULL; + return ghi->curEntry ? ghi->curEntry->val : NULL; } void BLI_ghashIterator_step(GHashIterator *ghi) { if (ghi->curEntry) { - ghi->curEntry= ghi->curEntry->next; + ghi->curEntry = ghi->curEntry->next; while (!ghi->curEntry) { ghi->curBucket++; - if (ghi->curBucket==ghi->gh->nbuckets) + if (ghi->curBucket == ghi->gh->nbuckets) break; - ghi->curEntry= ghi->gh->buckets[ghi->curBucket]; + ghi->curEntry = ghi->gh->buckets[ghi->curBucket]; } } } @@ -261,10 +260,10 @@ unsigned int BLI_ghashutil_ptrhash(const void *key) } int BLI_ghashutil_ptrcmp(const void *a, const void *b) { - if (a==b) + if (a == b) return 0; else - return (afirst, B->first); - if(cmp == 0) + if (cmp == 0) return BLI_ghashutil_intcmp(SET_INT_IN_POINTER(A->second), SET_INT_IN_POINTER(B->second)); return cmp; } diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c index 62a38e7933a..01a38cf123e 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -30,7 +30,6 @@ * \ingroup bli */ - #include #include "MEM_guardedalloc.h" @@ -55,26 +54,26 @@ struct Heap { }; #define SWAP(type, a, b) \ - { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } -#define HEAP_PARENT(i) ((i-1)>>1) -#define HEAP_LEFT(i) ((i<<1)+1) -#define HEAP_RIGHT(i) ((i<<1)+2) + { type sw_ap; sw_ap = (a); (a) = (b); (b) = sw_ap; } +#define HEAP_PARENT(i) ((i - 1) >> 1) +#define HEAP_LEFT(i) ((i << 1) + 1) +#define HEAP_RIGHT(i) ((i << 1) + 2) #define HEAP_COMPARE(a, b) (a->value < b->value) #define HEAP_EQUALS(a, b) (a->value == b->value) #define HEAP_SWAP(heap, i, j) \ { \ SWAP(int, heap->tree[i]->index, heap->tree[j]->index); \ - SWAP(HeapNode*, heap->tree[i], heap->tree[j]); \ + SWAP(HeapNode *, heap->tree[i], heap->tree[j]); \ } /***/ Heap *BLI_heap_new(void) { - Heap *heap = (Heap*)MEM_callocN(sizeof(Heap), "BLIHeap"); + Heap *heap = (Heap *)MEM_callocN(sizeof(Heap), __func__); heap->bufsize = 1; - heap->tree = (HeapNode**)MEM_mallocN(sizeof(HeapNode*), "BLIHeapTree"); - heap->arena = BLI_memarena_new(1<<16, "heap arena"); + heap->tree = (HeapNode **)MEM_mallocN(sizeof(HeapNode *), "BLIHeapTree"); + heap->arena = BLI_memarena_new(1 << 16, "heap arena"); return heap; } @@ -86,7 +85,7 @@ void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp) if (ptrfreefp) for (i = 0; i < heap->size; i++) ptrfreefp(heap->tree[i]->ptr); - + MEM_freeN(heap->tree); BLI_memarena_free(heap->arena); MEM_freeN(heap); @@ -99,11 +98,11 @@ static void BLI_heap_down(Heap *heap, int i) int l = HEAP_LEFT(i); int r = HEAP_RIGHT(i); - smallest = ((l < size) && HEAP_COMPARE(heap->tree[l], heap->tree[i]))? l: i; + smallest = ((l < size) && HEAP_COMPARE(heap->tree[l], heap->tree[i])) ? l : i; if ((r < size) && HEAP_COMPARE(heap->tree[r], heap->tree[smallest])) smallest = r; - + if (smallest == i) break; @@ -130,11 +129,11 @@ HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr) HeapNode *node; if ((heap->size + 1) > heap->bufsize) { - int newsize = heap->bufsize*2; + int newsize = heap->bufsize * 2; HeapNode **newtree; - newtree = (HeapNode**)MEM_mallocN(newsize*sizeof(*newtree), "BLIHeapTree"); - memcpy(newtree, heap->tree, sizeof(HeapNode*)*heap->size); + newtree = (HeapNode **)MEM_mallocN(newsize * sizeof(*newtree), __func__); + memcpy(newtree, heap->tree, sizeof(HeapNode *) * heap->size); MEM_freeN(heap->tree); heap->tree = newtree; @@ -143,10 +142,10 @@ HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr) if (heap->freenodes) { node = heap->freenodes; - heap->freenodes = (HeapNode*)(((HeapNode*)heap->freenodes)->ptr); + heap->freenodes = (HeapNode *)(((HeapNode *)heap->freenodes)->ptr); } else - node = (HeapNode*)BLI_memarena_alloc(heap->arena, sizeof *node); + node = (HeapNode *)BLI_memarena_alloc(heap->arena, sizeof *node); node->value = value; node->ptr = ptr; @@ -156,7 +155,7 @@ HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr) heap->size++; - BLI_heap_up(heap, heap->size-1); + BLI_heap_up(heap, heap->size - 1); return node; } diff --git a/source/blender/blenlib/intern/BLI_memarena.c b/source/blender/blenlib/intern/BLI_memarena.c index 72f312ba6e4..95a007db43e 100644 --- a/source/blender/blenlib/intern/BLI_memarena.c +++ b/source/blender/blenlib/intern/BLI_memarena.c @@ -30,8 +30,6 @@ * \ingroup bli */ - - #include "MEM_guardedalloc.h" #include "BLI_memarena.h" @@ -41,31 +39,31 @@ struct MemArena { unsigned char *curbuf; int bufsize, cursize; const char *name; - - int use_calloc; + + int use_calloc; int align; - + LinkNode *bufs; }; MemArena *BLI_memarena_new(int bufsize, const char *name) { - MemArena *ma= MEM_callocN(sizeof(*ma), "memarena"); - ma->bufsize= bufsize; + MemArena *ma = MEM_callocN(sizeof(*ma), "memarena"); + ma->bufsize = bufsize; ma->align = 8; - ma->name= name; - + ma->name = name; + return ma; } void BLI_memarena_use_calloc(MemArena *ma) { - ma->use_calloc= 1; + ma->use_calloc = 1; } void BLI_memarena_use_malloc(MemArena *ma) { - ma->use_calloc= 0; + ma->use_calloc = 0; } void BLI_memarena_use_align(struct MemArena *ma, int align) @@ -76,46 +74,47 @@ void BLI_memarena_use_align(struct MemArena *ma, int align) void BLI_memarena_free(MemArena *ma) { - BLI_linklist_free(ma->bufs, (void(*)(void*)) MEM_freeN); + BLI_linklist_free(ma->bufs, (void(*)(void *))MEM_freeN); MEM_freeN(ma); } - /* amt must be power of two */ -#define PADUP(num, amt) ((num+(amt-1))&~(amt-1)) +/* amt must be power of two */ +#define PADUP(num, amt) ((num + (amt - 1)) &~ (amt-1)) void *BLI_memarena_alloc(MemArena *ma, int size) { void *ptr; - /* ensure proper alignment by rounding - * size up to multiple of 8 */ - size= PADUP(size, ma->align); - - if (size>ma->cursize) { + /* ensure proper alignment by rounding + * size up to multiple of 8 */ + size = PADUP(size, ma->align); + + if (size > ma->cursize) { unsigned char *tmp; - - if(size > ma->bufsize - (ma->align - 1)) { + + if (size > ma->bufsize - (ma->align - 1)) { ma->cursize = PADUP(size+1, ma->align); } - else ma->cursize = ma->bufsize; - - if(ma->use_calloc) - ma->curbuf= MEM_callocN(ma->cursize, ma->name); else - ma->curbuf= MEM_mallocN(ma->cursize, ma->name); - + ma->cursize = ma->bufsize; + + if (ma->use_calloc) + ma->curbuf = MEM_callocN(ma->cursize, ma->name); + else + ma->curbuf = MEM_mallocN(ma->cursize, ma->name); + BLI_linklist_prepend(&ma->bufs, ma->curbuf); /* align alloc'ed memory (needed if align > 8) */ tmp = (unsigned char*)PADUP( (intptr_t) ma->curbuf, ma->align); ma->cursize -= (tmp - ma->curbuf); - ma->curbuf = tmp; + ma->curbuf = tmp; } - - ptr= ma->curbuf; - ma->curbuf+= size; - ma->cursize-= size; - + + ptr = ma->curbuf; + ma->curbuf += size; + ma->cursize -= size; + return ptr; } diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index d5df882ba29..b8a18b5e376 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -74,7 +74,7 @@ struct BLI_mempool { int flag; /* keeps aligned to 16 bits */ - BLI_freenode *free; /* free element list. Interleaved into chunk datas. */ + BLI_freenode *free; /* free element list. Interleaved into chunk datas. */ int totalloc, totused; /* total number of elements allocated in total, * and currently in use */ }; @@ -83,9 +83,9 @@ struct BLI_mempool { BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag) { - BLI_mempool *pool = NULL; + BLI_mempool *pool = NULL; BLI_freenode *lasttail = NULL, *curnode = NULL; - int i,j, maxchunks; + int i, j, maxchunks; char *addr; /* allocate the pool structure */ @@ -113,7 +113,7 @@ BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag) pool->csize = esize * pchunk; pool->chunks.first = pool->chunks.last = NULL; pool->totused = 0; - + maxchunks = totelem / pchunk + 1; if (maxchunks == 0) { maxchunks = 1; @@ -124,17 +124,17 @@ BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag) BLI_mempool_chunk *mpchunk; if (flag & BLI_MEMPOOL_SYSMALLOC) { - mpchunk = malloc(sizeof(BLI_mempool_chunk)); + mpchunk = malloc(sizeof(BLI_mempool_chunk)); mpchunk->data = malloc(pool->csize); } else { - mpchunk = MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk"); + mpchunk = MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk"); mpchunk->data = MEM_mallocN(pool->csize, "BLI Mempool Chunk Data"); } mpchunk->next = mpchunk->prev = NULL; BLI_addtail(&(pool->chunks), mpchunk); - + if (i == 0) { pool->free = mpchunk->data; /* start of the list */ if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) { @@ -304,7 +304,9 @@ void *BLI_mempool_findelem(BLI_mempool *pool, int index) BLI_mempool_iter iter; void *elem; BLI_mempool_iternew(pool, &iter); - for (elem = BLI_mempool_iterstep(&iter); index-- != 0; elem = BLI_mempool_iterstep(&iter)) { }; + for (elem = BLI_mempool_iterstep(&iter); index-- != 0; elem = BLI_mempool_iterstep(&iter)) { + /* do nothing */ + }; return elem; } @@ -317,10 +319,10 @@ void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) fprintf(stderr, "%s: Error! you can't iterate over this mempool!\n", __func__); iter->curchunk = NULL; iter->curindex = 0; - + return; } - + iter->pool = pool; iter->curchunk = pool->chunks.first; iter->curindex = 0; @@ -332,29 +334,29 @@ void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) static void *bli_mempool_iternext(BLI_mempool_iter *iter) { void *ret = NULL; - + if (!iter->curchunk || !iter->pool->totused) return NULL; - + ret = ((char *)iter->curchunk->data) + iter->pool->esize * iter->curindex; - + iter->curindex++; - + if (iter->curindex >= iter->pool->pchunk) { iter->curchunk = iter->curchunk->next; iter->curindex = 0; } - + return ret; } void *BLI_mempool_iterstep(BLI_mempool_iter *iter) { BLI_freenode *ret; - + do { ret = bli_mempool_iternext(iter); - } while (ret && ret->freeword == FREEWORD); - + }while (ret && ret->freeword == FREEWORD); + return ret; } @@ -383,7 +385,7 @@ void *BLI_mempool_iterstep(BLI_mempool_iter *iter) iter->curchunk = iter->curchunk->next; } } while (ret->freeword == FREEWORD); - + return ret; } diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 6436afe85aa..bedae13f36e 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -43,11 +43,11 @@ /* path/file handeling stuff */ #ifndef WIN32 - #include - #include +# include +# include #else - #include - #include "BLI_winstuff.h" +# include +# include "BLI_winstuff.h" #endif #include "MEM_guardedalloc.h" @@ -82,7 +82,7 @@ static int checkMissingFiles_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src) { - ReportList *reports= (ReportList *)userdata; + ReportList *reports = (ReportList *)userdata; if (!BLI_exists(path_src)) { BKE_reportf(reports, RPT_WARNING, "Path Not Found \"%s\"", path_src); @@ -97,8 +97,7 @@ void checkMissingFiles(Main *bmain, ReportList *reports) bpath_traverse_main(bmain, checkMissingFiles_visit_cb, BPATH_TRAVERSE_ABS, reports); } -typedef struct BPathRemap_Data -{ +typedef struct BPathRemap_Data { const char *basedir; ReportList *reports; @@ -109,17 +108,17 @@ typedef struct BPathRemap_Data static int makeFilesRelative_visit_cb(void *userdata, char *path_dst, const char *path_src) { - BPathRemap_Data *data= (BPathRemap_Data *)userdata; + BPathRemap_Data *data = (BPathRemap_Data *)userdata; data->count_tot++; - if(strncmp(path_src, "//", 2)==0) { + if (strncmp(path_src, "//", 2) == 0) { return FALSE; /* already relative */ } else { strcpy(path_dst, path_src); BLI_path_rel(path_dst, data->basedir); - if (strncmp(path_dst, "//", 2)==0) { + if (strncmp(path_dst, "//", 2) == 0) { data->count_changed++; } else { @@ -132,15 +131,15 @@ static int makeFilesRelative_visit_cb(void *userdata, char *path_dst, const char void makeFilesRelative(Main *bmain, const char *basedir, ReportList *reports) { - BPathRemap_Data data= {NULL}; + BPathRemap_Data data = {NULL}; - if(basedir[0] == '\0') { + if (basedir[0] == '\0') { printf("%s: basedir='', this is a bug\n", __func__); return; } - data.basedir= basedir; - data.reports= reports; + data.basedir = basedir; + data.reports = reports; bpath_traverse_main(bmain, makeFilesRelative_visit_cb, 0, (void *)&data); @@ -151,17 +150,17 @@ void makeFilesRelative(Main *bmain, const char *basedir, ReportList *reports) static int makeFilesAbsolute_visit_cb(void *userdata, char *path_dst, const char *path_src) { - BPathRemap_Data *data= (BPathRemap_Data *)userdata; + BPathRemap_Data *data = (BPathRemap_Data *)userdata; data->count_tot++; - if(strncmp(path_src, "//", 2)!=0) { + if (strncmp(path_src, "//", 2) != 0) { return FALSE; /* already absolute */ } else { strcpy(path_dst, path_src); BLI_path_abs(path_dst, data->basedir); - if (strncmp(path_dst, "//", 2)!=0) { + if (strncmp(path_dst, "//", 2) != 0) { data->count_changed++; } else { @@ -175,15 +174,15 @@ static int makeFilesAbsolute_visit_cb(void *userdata, char *path_dst, const char /* similar to makeFilesRelative - keep in sync! */ void makeFilesAbsolute(Main *bmain, const char *basedir, ReportList *reports) { - BPathRemap_Data data= {NULL}; + BPathRemap_Data data = {NULL}; - if(basedir[0] == '\0') { + if (basedir[0] == '\0') { printf("%s: basedir='', this is a bug\n", __func__); return; } - data.basedir= basedir; - data.reports= reports; + data.basedir = basedir; + data.reports = reports; bpath_traverse_main(bmain, makeFilesAbsolute_visit_cb, 0, (void *)&data); @@ -192,7 +191,6 @@ void makeFilesAbsolute(Main *bmain, const char *basedir, ReportList *reports) data.count_tot, data.count_changed, data.count_failed); } - /* find this file recursively, use the biggest file so thumbnails dont get used by mistake * - dir: subdir to search * - filename: set this filename @@ -217,17 +215,17 @@ static int findFileRecursive(char *filename_new, filename_new[0] = '\0'; - dir= opendir(dirname); + dir = opendir(dirname); - if (dir==NULL) + if (dir == NULL) return found; if (*filesize == -1) - *filesize= 0; /* dir opened fine */ + *filesize = 0; /* dir opened fine */ - while ((de= readdir(dir)) != NULL) { + while ((de = readdir(dir)) != NULL) { - if (strcmp(".", de->d_name)==0 || strcmp("..", de->d_name)==0) + if (strcmp(".", de->d_name) == 0 || strcmp("..", de->d_name) == 0) continue; BLI_join_dirfile(path, sizeof(path), dirname, de->d_name); @@ -236,11 +234,11 @@ static int findFileRecursive(char *filename_new, continue; /* cant stat, dont bother with this file, could print debug info here */ if (S_ISREG(status.st_mode)) { /* is file */ - if (strncmp(filename, de->d_name, FILE_MAX)==0) { /* name matches */ + if (strncmp(filename, de->d_name, FILE_MAX) == 0) { /* name matches */ /* open the file to read its size */ - size= status.st_size; + size = status.st_size; if ((size > 0) && (size > *filesize)) { /* find the biggest file */ - *filesize= size; + *filesize = size; BLI_strncpy(filename_new, path, FILE_MAX); found = TRUE; } @@ -258,8 +256,7 @@ static int findFileRecursive(char *filename_new, return found; } -typedef struct BPathFind_Data -{ +typedef struct BPathFind_Data { const char *basedir; char searchdir[FILE_MAX]; ReportList *reports; @@ -267,11 +264,11 @@ typedef struct BPathFind_Data static int findMissingFiles_visit_cb(void *userdata, char *path_dst, const char *path_src) { - BPathFind_Data *data= (BPathFind_Data *)userdata; + BPathFind_Data *data = (BPathFind_Data *)userdata; char filename_new[FILE_MAX]; - int filesize= -1; - int recur_depth= 0; + int filesize = -1; + int recur_depth = 0; int found; found = findFileRecursive(filename_new, @@ -298,9 +295,9 @@ static int findMissingFiles_visit_cb(void *userdata, char *path_dst, const char void findMissingFiles(Main *bmain, const char *searchpath, ReportList *reports) { - struct BPathFind_Data data= {NULL}; + struct BPathFind_Data data = {NULL}; - data.reports= reports; + data.reports = reports; BLI_split_dir_part(searchpath, data.searchdir, sizeof(data.searchdir)); bpath_traverse_main(bmain, findMissingFiles_visit_cb, 0, (void *)&data); @@ -316,10 +313,10 @@ static int rewrite_path_fixed(char *path, BPathVisitor visit_cb, const char *abs if (absbase) { BLI_strncpy(path_src_buf, path, sizeof(path_src_buf)); BLI_path_abs(path_src_buf, absbase); - path_src= path_src_buf; + path_src = path_src_buf; } else { - path_src= path; + path_src = path; } if (visit_cb(userdata, path_dst, path_src)) { @@ -364,15 +361,15 @@ static int rewrite_path_alloc(char **path, BPathVisitor visit_cb, const char *ab if (absbase) { BLI_strncpy(path_src_buf, *path, sizeof(path_src_buf)); BLI_path_abs(path_src_buf, absbase); - path_src= path_src_buf; + path_src = path_src_buf; } else { - path_src= *path; + path_src = *path; } if (visit_cb(userdata, path_dst, path_src)) { MEM_freeN((*path)); - (*path)= BLI_strdup(path_dst); + (*path) = BLI_strdup(path_dst); return TRUE; } else { @@ -384,7 +381,7 @@ static int rewrite_path_alloc(char **path, BPathVisitor visit_cb, const char *ab void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int flag, void *bpath_user_data) { Image *ima; - const char *absbase= (flag & BPATH_TRAVERSE_ABS) ? ID_BLEND_PATH(bmain, id) : NULL; + const char *absbase = (flag & BPATH_TRAVERSE_ABS) ? ID_BLEND_PATH(bmain, id) : NULL; if ((flag & BPATH_TRAVERSE_SKIP_LIBRARY) && id->lib) { return; @@ -428,7 +425,6 @@ void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int fla ModifierData *md; ParticleSystem *psys; - /* do via modifiers instead */ #if 0 if (ob->fluidsimSettings) { @@ -581,7 +577,7 @@ void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int fla void bpath_traverse_id_list(Main *bmain, ListBase *lb, BPathVisitor visit_cb, const int flag, void *bpath_user_data) { ID *id; - for(id= lb->first; id; id= id->next) { + for (id = lb->first; id; id = id->next) { bpath_traverse_id(bmain, id, visit_cb, flag, bpath_user_data); } } @@ -589,8 +585,10 @@ void bpath_traverse_id_list(Main *bmain, ListBase *lb, BPathVisitor visit_cb, co void bpath_traverse_main(Main *bmain, BPathVisitor visit_cb, const int flag, void *bpath_user_data) { ListBase *lbarray[MAX_LIBARRAY]; - int a= set_listbasepointers(bmain, lbarray); - while(a--) bpath_traverse_id_list(bmain, lbarray[a], visit_cb, flag, bpath_user_data); + int a = set_listbasepointers(bmain, lbarray); + while (a--) { + bpath_traverse_id_list(bmain, lbarray[a], visit_cb, flag, bpath_user_data); + } } /* Rewrites a relative path to be relative to the main file - unless the path is @@ -599,8 +597,8 @@ int bpath_relocate_visitor(void *pathbase_v, char *path_dst, const char *path_sr { /* be sure there is low chance of the path being too short */ char filepath[(FILE_MAXDIR * 2) + FILE_MAXFILE]; - const char *base_new= ((char **)pathbase_v)[0]; - const char *base_old= ((char **)pathbase_v)[1]; + const char *base_new = ((char **)pathbase_v)[0]; + const char *base_old = ((char **)pathbase_v)[1]; if (strncmp(base_old, "//", 2) == 0) { printf("%s: error, old base path '%s' is not absolute.\n", diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c index 56998cfd927..baf52d92230 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -101,7 +101,7 @@ static strCursorDelimType test_special_char(const char ch) case ':': case ';': case '?': - /* case '_': */ /* special case, for python */ + /* case '_': *//* special case, for python */ return STRCUR_DELIM_OTHER; default: @@ -112,12 +112,14 @@ static strCursorDelimType test_special_char(const char ch) int BLI_str_cursor_step_next_utf8(const char *str, size_t maxlen, int *pos) { - const char *str_end= str + (maxlen + 1); - const char *str_pos= str + (*pos); - const char *str_next= BLI_str_find_next_char_utf8(str_pos, str_end); + const char *str_end = str + (maxlen + 1); + const char *str_pos = str + (*pos); + const char *str_next = BLI_str_find_next_char_utf8(str_pos, str_end); if (str_next) { (*pos) += (str_next - str_pos); - if((*pos) > maxlen) (*pos)= maxlen; + if ((*pos) > maxlen) { + (*pos) = maxlen; + } return TRUE; } @@ -126,9 +128,9 @@ int BLI_str_cursor_step_next_utf8(const char *str, size_t maxlen, int *pos) int BLI_str_cursor_step_prev_utf8(const char *str, size_t UNUSED(maxlen), int *pos) { - if((*pos) > 0) { - const char *str_pos= str + (*pos); - const char *str_prev= BLI_str_find_prev_char_utf8(str, str_pos); + if ((*pos) > 0) { + const char *str_pos = str + (*pos); + const char *str_prev = BLI_str_find_prev_char_utf8(str, str_pos); if (str_prev) { (*pos) -= (str_pos - str_prev); return TRUE; @@ -142,19 +144,20 @@ void BLI_str_cursor_step_utf8(const char *str, size_t maxlen, int *pos, strCursorJumpDirection direction, strCursorJumpType jump) { - const short pos_prev= *pos; + const short pos_prev = *pos; if (direction == STRCUR_DIR_NEXT) { BLI_str_cursor_step_next_utf8(str, maxlen, pos); if (jump != STRCUR_JUMP_NONE) { - const strCursorDelimType is_special= (*pos) < maxlen ? test_special_char(str[(*pos)]) : STRCUR_DELIM_NONE; + const strCursorDelimType is_special = (*pos) < maxlen ? test_special_char(str[(*pos)]) : STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), * look at function test_special_char() for complete * list of special character, ctr -> */ while ((*pos) < maxlen) { if (BLI_str_cursor_step_next_utf8(str, maxlen, pos)) { - if ((jump != STRCUR_JUMP_ALL) && (is_special != test_special_char(str[(*pos)]))) break; + if ((jump != STRCUR_JUMP_ALL) && (is_special != test_special_char(str[(*pos)]))) + break; } else { break; /* unlikely but just in case */ @@ -165,14 +168,15 @@ void BLI_str_cursor_step_utf8(const char *str, size_t maxlen, else if (direction == STRCUR_DIR_PREV) { BLI_str_cursor_step_prev_utf8(str, maxlen, pos); - if(jump != STRCUR_JUMP_NONE) { - const strCursorDelimType is_special= (*pos) > 1 ? test_special_char(str[(*pos) - 1]) : STRCUR_DELIM_NONE; + if (jump != STRCUR_JUMP_NONE) { + const strCursorDelimType is_special = (*pos) > 1 ? test_special_char(str[(*pos) - 1]) : STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), * look at function test_special_char() for complete * list of special character, ctr -> */ while ((*pos) > 0) { if (BLI_str_cursor_step_prev_utf8(str, maxlen, pos)) { - if ((jump != STRCUR_JUMP_ALL) && (is_special != test_special_char(str[(*pos)]))) break; + if ((jump != STRCUR_JUMP_ALL) && (is_special != test_special_char(str[(*pos)]))) + break; } else { break; diff --git a/source/blender/blenlib/intern/uvproject.c b/source/blender/blenlib/intern/uvproject.c index 8b00d8e48a6..89621cdf48d 100644 --- a/source/blender/blenlib/intern/uvproject.c +++ b/source/blender/blenlib/intern/uvproject.c @@ -22,7 +22,6 @@ * \ingroup bli */ - #include #include "MEM_guardedalloc.h" @@ -48,45 +47,46 @@ void project_from_camera(float target[2], float source[3], UvCameraInfo *uci) float pv4[4]; copy_v3_v3(pv4, source); - pv4[3]= 1.0; + pv4[3] = 1.0; /* rotmat is the object matrix in this case */ - if(uci->do_rotmat) + if (uci->do_rotmat) mul_m4_v4(uci->rotmat, pv4); /* caminv is the inverse camera matrix */ mul_m4_v4(uci->caminv, pv4); - if(uci->do_pano) { - float angle= atan2f(pv4[0], -pv4[2]) / ((float)M_PI * 2.0f); /* angle around the camera */ - if (uci->do_persp==0) { - target[0]= angle; /* no correct method here, just map to 0-1 */ - target[1]= pv4[1] / uci->camsize; + if (uci->do_pano) { + float angle = atan2f(pv4[0], -pv4[2]) / ((float)M_PI * 2.0f); /* angle around the camera */ + if (uci->do_persp == 0) { + target[0] = angle; /* no correct method here, just map to 0-1 */ + target[1] = pv4[1] / uci->camsize; } else { float vec2d[2]; /* 2D position from the camera */ - vec2d[0]= pv4[0]; - vec2d[1]= pv4[2]; - target[0]= angle * ((float)M_PI / uci->camangle); - target[1]= pv4[1] / (len_v2(vec2d) * (uci->camsize * 2.0f)); + vec2d[0] = pv4[0]; + vec2d[1] = pv4[2]; + target[0] = angle * ((float)M_PI / uci->camangle); + target[1] = pv4[1] / (len_v2(vec2d) * (uci->camsize * 2.0f)); } } else { - if (pv4[2]==0.0f) pv4[2]= 0.00001f; /* don't allow div by 0 */ + if (pv4[2] == 0.0f) + pv4[2] = 0.00001f; /* don't allow div by 0 */ - if (uci->do_persp==0) { - target[0]= (pv4[0]/uci->camsize); - target[1]= (pv4[1]/uci->camsize); + if (uci->do_persp == 0) { + target[0] = (pv4[0] / uci->camsize); + target[1] = (pv4[1] / uci->camsize); } else { - target[0]= (-pv4[0]*((1.0f/uci->camsize)/pv4[2])) / 2.0f; - target[1]= (-pv4[1]*((1.0f/uci->camsize)/pv4[2])) / 2.0f; + target[0] = (-pv4[0] * ((1.0f / uci->camsize) / pv4[2])) / 2.0f; + target[1] = (-pv4[1] * ((1.0f / uci->camsize) / pv4[2])) / 2.0f; } } target[0] *= uci->xasp; target[1] *= uci->yasp; - + /* adds camera shift + 0.5 */ target[0] += uci->shiftx; target[1] += uci->shifty; @@ -95,54 +95,54 @@ void project_from_camera(float target[2], float source[3], UvCameraInfo *uci) /* could rv3d->persmat */ void project_from_view(float target[2], float source[3], float persmat[4][4], float rotmat[4][4], float winx, float winy) { - float pv[3], pv4[4], x= 0.0, y= 0.0; + float pv[3], pv4[4], x = 0.0, y = 0.0; mul_v3_m4v3(pv, rotmat, source); copy_v3_v3(pv4, source); - pv4[3]= 1.0; + pv4[3] = 1.0; /* rotmat is the object matrix in this case */ - mul_m4_v4(rotmat, pv4); + mul_m4_v4(rotmat, pv4); /* almost project_short */ mul_m4_v4(persmat, pv4); - if(fabsf(pv4[3]) > 0.00001f) { /* avoid division by zero */ - target[0] = winx/2.0f + (winx/2.0f) * pv4[0] / pv4[3]; - target[1] = winy/2.0f + (winy/2.0f) * pv4[1] / pv4[3]; + if (fabsf(pv4[3]) > 0.00001f) { /* avoid division by zero */ + target[0] = winx / 2.0f + (winx / 2.0f) * pv4[0] / pv4[3]; + target[1] = winy / 2.0f + (winy / 2.0f) * pv4[1] / pv4[3]; } else { /* scaling is lost but give a valid result */ - target[0] = winx/2.0f + (winx/2.0f) * pv4[0]; - target[1] = winy/2.0f + (winy/2.0f) * pv4[1]; + target[0] = winx / 2.0f + (winx / 2.0f) * pv4[0]; + target[1] = winy / 2.0f + (winy / 2.0f) * pv4[1]; } - /* v3d->persmat seems to do this funky scaling */ - if(winx > winy) { - y= (winx - winy)/2.0f; + /* v3d->persmat seems to do this funky scaling */ + if (winx > winy) { + y = (winx - winy) / 2.0f; winy = winx; } else { - x= (winy - winx)/2.0f; + x = (winy - winx) / 2.0f; winx = winy; } - target[0]= (x + target[0]) / winx; - target[1]= (y + target[1]) / winy; + target[0] = (x + target[0]) / winx; + target[1] = (y + target[1]) / winy; } /* 'rotmat' can be obedit->obmat when uv project is used. - * 'winx' and 'winy' can be from scene->r.xsch/ysch */ -UvCameraInfo *project_camera_info(Object *ob, float (*rotmat)[4], float winx, float winy) + * 'winx' and 'winy' can be from scene->r.xsch/ysch */ +UvCameraInfo *project_camera_info(Object *ob, float(*rotmat)[4], float winx, float winy) { UvCameraInfo uci; - Camera *camera= ob->data; + Camera *camera = ob->data; uci.do_pano = (camera->flag & CAM_PANORAMA); - uci.do_persp = (camera->type==CAM_PERSP); + uci.do_persp = (camera->type == CAM_PERSP); - uci.camangle= focallength_to_fov(camera->lens, camera->sensor_x) / 2.0f; - uci.camsize= uci.do_persp ? tanf(uci.camangle) : camera->ortho_scale; + uci.camangle = focallength_to_fov(camera->lens, camera->sensor_x) / 2.0f; + uci.camsize = uci.do_persp ? tanf(uci.camangle) : camera->ortho_scale; /* account for scaled cameras */ copy_m4_m4(uci.caminv, ob->obmat); @@ -152,30 +152,30 @@ UvCameraInfo *project_camera_info(Object *ob, float (*rotmat)[4], float winx, fl UvCameraInfo *uci_pt; /* normal projection */ - if(rotmat) { + if (rotmat) { copy_m4_m4(uci.rotmat, rotmat); - uci.do_rotmat= 1; + uci.do_rotmat = 1; } else { - uci.do_rotmat= 0; + uci.do_rotmat = 0; } /* also make aspect ratio adjustment factors */ if (winx > winy) { - uci.xasp= 1.0f; - uci.yasp= winx / winy; + uci.xasp = 1.0f; + uci.yasp = winx / winy; } else { - uci.xasp= winy / winx; - uci.yasp= 1.0f; + uci.xasp = winy / winx; + uci.yasp = 1.0f; } - + /* include 0.5f here to move the UVs into the center */ uci.shiftx = 0.5f - (camera->shiftx * uci.xasp); uci.shifty = 0.5f - (camera->shifty * uci.yasp); - - uci_pt= MEM_mallocN(sizeof(UvCameraInfo), "UvCameraInfo"); - *uci_pt= uci; + + uci_pt = MEM_mallocN(sizeof(UvCameraInfo), "UvCameraInfo"); + *uci_pt = uci; return uci_pt; } @@ -193,7 +193,6 @@ void project_from_view_ortho(float target[2], float source[3], float rotmat[4][4 target[1] = pv[2]; } - void project_camera_info_scale(UvCameraInfo *uci, float scale_x, float scale_y) { uci->xasp *= scale_x; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index dcd89a52a80..11f4ec5c041 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -477,7 +477,6 @@ void vpaint_fill(Object *ob, unsigned int paintcol) selected= (me->editflag & ME_EDIT_PAINT_MASK); mp = me->mpoly; - lcol = me->mloopcol; for (i=0; itotpoly; i++, mp++) { if (!(!selected || mp->flag & ME_FACE_SEL)) continue; @@ -3062,4 +3061,3 @@ void PAINT_OT_weight_from_bones(wmOperatorType *ot) /* properties */ ot->prop= RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "Method to use for assigning weights"); } - From 7afeb21a419a86aef36bcded1470b941a40f27c9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 12 Mar 2012 00:03:42 +0000 Subject: [PATCH 020/310] text delimiter - convert to unicode before comparing characters. --- .../blenlib/intern/string_cursor_utf8.c | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c index baf52d92230..97559d6ba10 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -48,19 +48,21 @@ typedef enum strCursorDelimType { } strCursorDelimType; /* return 1 if char ch is special character, otherwise return 0 */ -static strCursorDelimType test_special_char(const char ch) +static strCursorDelimType test_special_char(const char *ch_utf8) { - /* TODO - use BLI_str_utf8_as_unicode rather then assuming ascii */ + /* for full unicode support we really need to have large lookup tables to figure + * out whats what in every possible char set - and python, glib both have these. */ + unsigned int uch = BLI_str_utf8_as_unicode(ch_utf8); - if ((ch >= 'a' && ch <= 'z') || - (ch >= 'A' && ch <= 'Z') || - (ch == '_') /* not quite correct but allow for python, could become configurable */ + if ((uch >= 'a' && uch <= 'z') || + (uch >= 'A' && uch <= 'Z') || + (uch == '_') /* not quite correct but allow for python, could become configurable */ ) { return STRCUR_DELIM_ALPHA; } - switch (ch) { + switch (uch) { case ',': case '.': return STRCUR_DELIM_PUNCT; @@ -150,13 +152,13 @@ void BLI_str_cursor_step_utf8(const char *str, size_t maxlen, BLI_str_cursor_step_next_utf8(str, maxlen, pos); if (jump != STRCUR_JUMP_NONE) { - const strCursorDelimType is_special = (*pos) < maxlen ? test_special_char(str[(*pos)]) : STRCUR_DELIM_NONE; + const strCursorDelimType is_special = (*pos) < maxlen ? test_special_char(&str[*pos]) : STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), * look at function test_special_char() for complete * list of special character, ctr -> */ while ((*pos) < maxlen) { if (BLI_str_cursor_step_next_utf8(str, maxlen, pos)) { - if ((jump != STRCUR_JUMP_ALL) && (is_special != test_special_char(str[(*pos)]))) + if ((jump != STRCUR_JUMP_ALL) && (is_special != test_special_char(&str[*pos]))) break; } else { @@ -169,13 +171,13 @@ void BLI_str_cursor_step_utf8(const char *str, size_t maxlen, BLI_str_cursor_step_prev_utf8(str, maxlen, pos); if (jump != STRCUR_JUMP_NONE) { - const strCursorDelimType is_special = (*pos) > 1 ? test_special_char(str[(*pos) - 1]) : STRCUR_DELIM_NONE; + const strCursorDelimType is_special = (*pos) > 1 ? test_special_char(&str[(*pos) - 1]) : STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), * look at function test_special_char() for complete * list of special character, ctr -> */ while ((*pos) > 0) { if (BLI_str_cursor_step_prev_utf8(str, maxlen, pos)) { - if ((jump != STRCUR_JUMP_ALL) && (is_special != test_special_char(str[(*pos)]))) + if ((jump != STRCUR_JUMP_ALL) && (is_special != test_special_char(&str[*pos]))) break; } else { From a04f44f4866138ebcec309b7f2ec48addc504374 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 12 Mar 2012 01:34:38 +0000 Subject: [PATCH 021/310] fix [#30472] 3d view objects not rendered, cycles. holdout layer wasnt initializes in some cases. --- intern/cycles/blender/blender_sync.cpp | 1 + intern/cycles/blender/blender_sync.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp index defdb7b447d..9fb2c6e1328 100644 --- a/intern/cycles/blender/blender_sync.cpp +++ b/intern/cycles/blender/blender_sync.cpp @@ -192,6 +192,7 @@ void BlenderSync::sync_render_layers(BL::SpaceView3D b_v3d, const char *layer) if(b_v3d) { render_layer.scene_layer = get_layer(b_v3d.layers()); render_layer.layer = render_layer.scene_layer; + render_layer.holdout_layer = 0; render_layer.material_override = PointerRNA_NULL; } else { diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h index 87080e23f28..bfb530c9f99 100644 --- a/intern/cycles/blender/blender_sync.h +++ b/intern/cycles/blender/blender_sync.h @@ -106,7 +106,7 @@ private: struct RenderLayerInfo { RenderLayerInfo() - : scene_layer(0), layer(0), + : scene_layer(0), layer(0), holdout_layer(0), material_override(PointerRNA_NULL) {} From 1979679ad677f949f648546d7acdfdad029a1234 Mon Sep 17 00:00:00 2001 From: "Guillermo S. Romero" Date: Mon, 12 Mar 2012 04:35:06 +0000 Subject: [PATCH 022/310] SVN maintenance. --- extern/libmv/third_party/glog/src/windows/preprocess.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 extern/libmv/third_party/glog/src/windows/preprocess.sh diff --git a/extern/libmv/third_party/glog/src/windows/preprocess.sh b/extern/libmv/third_party/glog/src/windows/preprocess.sh old mode 100644 new mode 100755 From 0873cbaed5aea31f3fc8b16dacecb2d332c9b6f5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 12 Mar 2012 06:07:16 +0000 Subject: [PATCH 023/310] style cleanup: line length - some over 300 long. --- source/blender/makesrna/intern/makesrna.c | 121 +++++++++++++++++----- 1 file changed, 94 insertions(+), 27 deletions(-) diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 2e8090c71f4..be7ced4b656 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -567,11 +567,15 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr fprintf(f, "{\n"); if (manualfunc) { if (strcmp(manualfunc, "rna_iterator_listbase_get") == 0 || - strcmp(manualfunc, "rna_iterator_array_get") == 0 || - strcmp(manualfunc, "rna_iterator_array_dereference_get") == 0) - fprintf(f, " return rna_pointer_inherit_refine(&iter->parent, &RNA_%s, %s(iter));\n", (cprop->item_type)? (const char*)cprop->item_type: "UnknownType", manualfunc); - else + strcmp(manualfunc, "rna_iterator_array_get") == 0 || + strcmp(manualfunc, "rna_iterator_array_dereference_get") == 0) + { + fprintf(f, " return rna_pointer_inherit_refine(&iter->parent, &RNA_%s, %s(iter));\n", + (cprop->item_type) ? (const char *)cprop->item_type: "UnknownType", manualfunc); + } + else { fprintf(f, " return %s(iter);\n", manualfunc); + } } fprintf(f, "}\n\n"); break; @@ -603,10 +607,14 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr } if (dp->dnaarraylength == 1) { - if (prop->type == PROP_BOOLEAN && dp->booleanbit) - fprintf(f, " values[i]= %s((data->%s & (%d<booleannegative)? "!": "", dp->dnaname, dp->booleanbit); - else - fprintf(f, " values[i]= (%s)%s((&data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname); + if (prop->type == PROP_BOOLEAN && dp->booleanbit) { + fprintf(f, " values[i]= %s((data->%s & (%d<booleannegative)? "!": "", dp->dnaname, dp->booleanbit); + } + else { + fprintf(f, " values[i]= (%s)%s((&data->%s)[i]);\n", + rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname); + } } else { if (prop->type == PROP_BOOLEAN && dp->booleanbit) { @@ -614,12 +622,18 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr rna_int_print(f, dp->booleanbit); fprintf(f, ") != 0);\n"); } - else if (rna_color_quantize(prop, dp)) - fprintf(f, " values[i]= (%s)(data->%s[i]*(1.0f/255.0f));\n", rna_type_type(prop), dp->dnaname); - else if (dp->dnatype) - fprintf(f, " values[i]= (%s)%s(((%s*)data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnatype, dp->dnaname); - else - fprintf(f, " values[i]= (%s)%s((data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname); + else if (rna_color_quantize(prop, dp)) { + fprintf(f, " values[i]= (%s)(data->%s[i]*(1.0f/255.0f));\n", + rna_type_type(prop), dp->dnaname); + } + else if (dp->dnatype) { + fprintf(f, " values[i]= (%s)%s(((%s*)data->%s)[i]);\n", + rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnatype, dp->dnaname); + } + else { + fprintf(f, " values[i]= (%s)%s((data->%s)[i]);\n", + rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname); + } } fprintf(f, " }\n"); } @@ -2235,7 +2249,10 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr break; } - fprintf(f, "%s%s rna_%s%s_%s = {\n", (prop->flag & PROP_EXPORT)? "": "", rna_property_structname(prop->type), srna->identifier, strnest, prop->identifier); + fprintf(f, "%s%s rna_%s%s_%s = {\n", + (prop->flag & PROP_EXPORT) ? "": "", + rna_property_structname(prop->type), + srna->identifier, strnest, prop->identifier); if (prop->next) fprintf(f, "\t{(PropertyRNA*)&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier); else fprintf(f, "\t{NULL, "); @@ -2248,8 +2265,22 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr rna_print_c_string(f, prop->description); fprintf(f, ",\n\t"); fprintf(f, "%d,\n", prop->icon); rna_print_c_string(f, prop->translation_context); fprintf(f, ",\n\t"); - fprintf(f, "\t%s, %s|%s, %s, %u, {%u, %u, %u}, %u,\n", RNA_property_typename(prop->type), rna_property_subtypename(prop->subtype), rna_property_subtype_unit(prop->subtype), rna_function_string(prop->getlength), prop->arraydimension, prop->arraylength[0], prop->arraylength[1], prop->arraylength[2], prop->totarraylength); - fprintf(f, "\t%s%s, %d, %s, %s,\n", (prop->flag & PROP_CONTEXT_UPDATE)? "(UpdateFunc)": "", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable), rna_function_string(prop->itemeditable)); + fprintf(f, "\t%s, %s|%s, %s, %u, {%u, %u, %u}, %u,\n", + RNA_property_typename(prop->type), + rna_property_subtypename(prop->subtype), + rna_property_subtype_unit(prop->subtype), + rna_function_string(prop->getlength), + prop->arraydimension, + prop->arraylength[0], + prop->arraylength[1], + prop->arraylength[2], + prop->totarraylength); + fprintf(f, "\t%s%s, %d, %s, %s,\n", + (prop->flag & PROP_CONTEXT_UPDATE) ? "(UpdateFunc)": "", + rna_function_string(prop->update), + prop->noteflag, + rna_function_string(prop->editable), + rna_function_string(prop->itemeditable)); if (prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop); else fprintf(f, "\t0, -1"); @@ -2263,27 +2294,44 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr switch (prop->type) { case PROP_BOOLEAN: { BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop; - fprintf(f, "\t%s, %s, %s, %s, %d, ", rna_function_string(bprop->get), rna_function_string(bprop->set), rna_function_string(bprop->getarray), rna_function_string(bprop->setarray), bprop->defaultvalue); - if (prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier); + fprintf(f, "\t%s, %s, %s, %s, %d, ", + rna_function_string(bprop->get), + rna_function_string(bprop->set), + rna_function_string(bprop->getarray), + rna_function_string(bprop->setarray), + bprop->defaultvalue); + if (prop->arraydimension && prop->totarraylength) + fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier); else fprintf(f, "NULL\n"); break; } case PROP_INT: { IntPropertyRNA *iprop = (IntPropertyRNA*)prop; - fprintf(f, "\t%s, %s, %s, %s, %s,\n\t", rna_function_string(iprop->get), rna_function_string(iprop->set), rna_function_string(iprop->getarray), rna_function_string(iprop->setarray), rna_function_string(iprop->range)); + fprintf(f, "\t%s, %s, %s, %s, %s,\n\t", + rna_function_string(iprop->get), + rna_function_string(iprop->set), + rna_function_string(iprop->getarray), + rna_function_string(iprop->setarray), + rna_function_string(iprop->range)); rna_int_print(f, iprop->softmin); fprintf(f, ", "); rna_int_print(f, iprop->softmax); fprintf(f, ", "); rna_int_print(f, iprop->hardmin); fprintf(f, ", "); rna_int_print(f, iprop->hardmax); fprintf(f, ", "); rna_int_print(f, iprop->step); fprintf(f, ", "); rna_int_print(f, iprop->defaultvalue); fprintf(f, ", "); - if (prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier); + if (prop->arraydimension && prop->totarraylength) + fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier); else fprintf(f, "NULL\n"); break; } case PROP_FLOAT: { FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop; - fprintf(f, "\t%s, %s, %s, %s, %s, ", rna_function_string(fprop->get), rna_function_string(fprop->set), rna_function_string(fprop->getarray), rna_function_string(fprop->setarray), rna_function_string(fprop->range)); + fprintf(f, "\t%s, %s, %s, %s, %s, ", + rna_function_string(fprop->get), + rna_function_string(fprop->set), + rna_function_string(fprop->getarray), + rna_function_string(fprop->setarray), + rna_function_string(fprop->range)); rna_float_print(f, fprop->softmin); fprintf(f, ", "); rna_float_print(f, fprop->softmax); fprintf(f, ", "); rna_float_print(f, fprop->hardmin); fprintf(f, ", "); @@ -2291,19 +2339,27 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr rna_float_print(f, fprop->step); fprintf(f, ", "); rna_int_print(f, (int)fprop->precision); fprintf(f, ", "); rna_float_print(f, fprop->defaultvalue); fprintf(f, ", "); - if (prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier); + if (prop->arraydimension && prop->totarraylength) + fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier); else fprintf(f, "NULL\n"); break; } case PROP_STRING: { StringPropertyRNA *sprop = (StringPropertyRNA*)prop; - fprintf(f, "\t%s, %s, %s, %d, ", rna_function_string(sprop->get), rna_function_string(sprop->length), rna_function_string(sprop->set), sprop->maxlength); + fprintf(f, "\t%s, %s, %s, %d, ", + rna_function_string(sprop->get), + rna_function_string(sprop->length), + rna_function_string(sprop->set), + sprop->maxlength); rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n"); break; } case PROP_ENUM: { EnumPropertyRNA *eprop = (EnumPropertyRNA*)prop; - fprintf(f, "\t%s, %s, %s, NULL, ", rna_function_string(eprop->get), rna_function_string(eprop->set), rna_function_string(eprop->itemf)); + fprintf(f, "\t%s, %s, %s, NULL, ", + rna_function_string(eprop->get), + rna_function_string(eprop->set), + rna_function_string(eprop->itemf)); if (eprop->item) fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier); else @@ -2313,14 +2369,25 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr } case PROP_POINTER: { PointerPropertyRNA *pprop = (PointerPropertyRNA*)prop; - fprintf(f, "\t%s, %s, %s, %s,", rna_function_string(pprop->get), rna_function_string(pprop->set), rna_function_string(pprop->typef), rna_function_string(pprop->poll)); + fprintf(f, "\t%s, %s, %s, %s,", rna_function_string(pprop->get), + rna_function_string(pprop->set), + rna_function_string(pprop->typef), + rna_function_string(pprop->poll)); if (pprop->type) fprintf(f, "&RNA_%s\n", (const char*)pprop->type); else fprintf(f, "NULL\n"); break; } case PROP_COLLECTION: { CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)prop; - fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, %s, ", rna_function_string(cprop->begin), rna_function_string(cprop->next), rna_function_string(cprop->end), rna_function_string(cprop->get), rna_function_string(cprop->length), rna_function_string(cprop->lookupint), rna_function_string(cprop->lookupstring), rna_function_string(cprop->assignint)); + fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, %s, ", + rna_function_string(cprop->begin), + rna_function_string(cprop->next), + rna_function_string(cprop->end), + rna_function_string(cprop->get), + rna_function_string(cprop->length), + rna_function_string(cprop->lookupint), + rna_function_string(cprop->lookupstring), + rna_function_string(cprop->assignint)); if (cprop->item_type) fprintf(f, "&RNA_%s\n", (const char*)cprop->item_type); else fprintf(f, "NULL\n"); break; From aedd4af57e5777dd32585560980f4661ec4d491d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 12 Mar 2012 06:53:47 +0000 Subject: [PATCH 024/310] code cleanup/bugfix uninitialized values - edgebisect bmesh operator used uninialized beauty field. - BLI_join_dirfile could read from before the string bounds when passed an empty dir string. - pransform could use an uninitialized projected coordinate (unlikely but possible) - RNA_property_path_from_ID_check would compare against an uninitialized pointer when the path wasn't found. also have bmesh walker use BM_edge_other_vert() utility function. --- source/blender/blenlib/intern/path_util.c | 6 +- .../blender/bmesh/intern/bmesh_walkers_impl.c | 11 ++-- .../blender/bmesh/operators/bmo_subdivide.c | 4 +- source/blender/editors/transform/transform.c | 63 ++++++++++--------- source/blender/editors/transform/transform.h | 6 +- source/blender/makesrna/intern/rna_access.c | 8 ++- 6 files changed, 52 insertions(+), 46 deletions(-) diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 0d251133e0d..dccec7a6a42 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1523,9 +1523,9 @@ void BLI_join_dirfile(char *dst, const size_t maxlen, const char *dir, const cha } /* inline BLI_add_slash */ - if (dst[dirlen - 1] != SEP) { - dst[dirlen++]= SEP; - dst[dirlen ]= '\0'; + if ((dirlen > 0) && (dst[dirlen - 1] != SEP)) { + dst[dirlen++] = SEP; + dst[dirlen ] = '\0'; } if (dirlen >= maxlen) { diff --git a/source/blender/bmesh/intern/bmesh_walkers_impl.c b/source/blender/bmesh/intern/bmesh_walkers_impl.c index cd815c9be83..23d82f0ab34 100644 --- a/source/blender/bmesh/intern/bmesh_walkers_impl.c +++ b/source/blender/bmesh/intern/bmesh_walkers_impl.c @@ -256,8 +256,7 @@ static void *bmw_IslandboundWalker_step(BMWalker *walker) owalk = *iwalk; - if (iwalk->lastv == e->v1) v = e->v2; - else v = e->v1; + v = BM_edge_other_vert(e, iwalk->lastv); if (!BM_vert_is_manifold(walker->bm, v)) { BMW_reset(walker); @@ -411,10 +410,7 @@ static void bmw_LoopWalker_begin(BMWalker *walker, void *data) lwalk = BMW_state_add(walker); *lwalk = owalk; - if (lwalk->lastv == owalk.cur->v1) lwalk->lastv = owalk.cur->v2; - else lwalk->lastv = owalk.cur->v1; - - lwalk->startv = lwalk->lastv; + lwalk->lastv = lwalk->startv = BM_edge_other_vert(owalk.cur, lwalk->lastv); BLI_ghash_free(walker->visithash, NULL, NULL); walker->visithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh walkers 2"); @@ -625,8 +621,9 @@ static void *bmw_FaceLoopWalker_step(BMWalker *walker) l = l->radial_next; - if (lwalk->nocalc) + if (lwalk->nocalc) { return f; + } if (!bmw_FaceLoopWalker_include_face(walker, l)) { l = lwalk->l; diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index 9a6d9e7b836..24f9c1e9937 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -1080,10 +1080,10 @@ void bmo_edgebisect_exec(BMesh *bm, BMOperator *op) { BMOIter siter; BMEdge *e; - SubDParams params; + SubDParams params = {0}; int skey; - params.numcuts = BMO_slot_get(op, "numcuts")->data.i; + params.numcuts = BMO_slot_int_get(op, "numcuts"); params.op = op; BM_data_layer_add(bm, &bm->vdata, CD_SHAPEKEY); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 7b98a2f0083..4334d323737 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -136,28 +136,28 @@ static void convertViewVec2D(View2D *v2d, float vec[3], int dx, int dy) vec[2]= 0.0f; } -void convertViewVec(TransInfo *t, float vec[3], int dx, int dy) +void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy) { if ((t->spacetype == SPACE_VIEW3D) && (t->ar->regiontype == RGN_TYPE_WINDOW)) { float mval_f[2]; mval_f[0] = dx; mval_f[1] = dy; - ED_view3d_win_to_delta(t->ar, mval_f, vec); + ED_view3d_win_to_delta(t->ar, mval_f, r_vec); } else if(t->spacetype==SPACE_IMAGE) { float aspx, aspy; - convertViewVec2D(t->view, vec, dx, dy); + convertViewVec2D(t->view, r_vec, dx, dy); ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); - vec[0]*= aspx; - vec[1]*= aspy; + r_vec[0] *= aspx; + r_vec[1] *= aspy; } else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) { - convertViewVec2D(t->view, vec, dx, dy); + convertViewVec2D(t->view, r_vec, dx, dy); } else if(ELEM(t->spacetype, SPACE_NODE, SPACE_SEQ)) { - convertViewVec2D(&t->ar->v2d, vec, dx, dy); + convertViewVec2D(&t->ar->v2d, r_vec, dx, dy); } else if(t->spacetype==SPACE_CLIP) { View2D *v2d = t->view; @@ -166,17 +166,17 @@ void convertViewVec(TransInfo *t, float vec[3], int dx, int dy) divx= v2d->mask.xmax-v2d->mask.xmin; divy= v2d->mask.ymax-v2d->mask.ymin; - vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx; - vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy; - vec[2]= 0.0f; + r_vec[0] = (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx; + r_vec[1] = (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy; + r_vec[2] = 0.0f; } else { printf("%s: called in an invalid context\n", __func__); - zero_v3(vec); + zero_v3(r_vec); } } -void projectIntView(TransInfo *t, float *vec, int *adr) +void projectIntView(TransInfo *t, const float vec[3], int adr[2]) { if (t->spacetype==SPACE_VIEW3D) { if(t->ar->regiontype == RGN_TYPE_WINDOW) @@ -229,26 +229,31 @@ void projectIntView(TransInfo *t, float *vec, int *adr) } } -void projectFloatView(TransInfo *t, float *vec, float *adr) +void projectFloatView(TransInfo *t, const float vec[3], float adr[2]) { - if (t->spacetype==SPACE_VIEW3D) { - if(t->ar->regiontype == RGN_TYPE_WINDOW) - project_float_noclip(t->ar, vec, adr); + switch (t->spacetype) { + case SPACE_VIEW3D: + { + if (t->ar->regiontype == RGN_TYPE_WINDOW) { + project_float_noclip(t->ar, vec, adr); + return; + } + break; + } + case SPACE_IMAGE: + case SPACE_CLIP: + case SPACE_IPO: + case SPACE_NLA: + { + int a[2]; + projectIntView(t, vec, a); + adr[0] = a[0]; + adr[1] = a[1]; + return; + } } - else if(ELEM(t->spacetype, SPACE_IMAGE, SPACE_CLIP)) { - int a[2]; - projectIntView(t, vec, a); - adr[0]= a[0]; - adr[1]= a[1]; - } - else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) { - int a[2]; - - projectIntView(t, vec, a); - adr[0]= a[0]; - adr[1]= a[1]; - } + zero_v2(adr); } void applyAspectRatio(TransInfo *t, float *vec) diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 48c05f00ea8..0bef33149d7 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -444,9 +444,9 @@ void transformApply(struct bContext *C, TransInfo *t); int transformEnd(struct bContext *C, TransInfo *t); void setTransformViewMatrices(TransInfo *t); -void convertViewVec(TransInfo *t, float *vec, int dx, int dy); -void projectIntView(TransInfo *t, float *vec, int *adr); -void projectFloatView(TransInfo *t, float *vec, float *adr); +void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy); +void projectIntView(TransInfo *t, const float vec[3], int adr[2]); +void projectFloatView(TransInfo *t, const float vec[3], float adr[2]); void applyAspectRatio(TransInfo *t, float *vec); void removeAspectRatio(TransInfo *t, float *vec); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 2ccd7d293d3..543824eb5d5 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1430,8 +1430,12 @@ int RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop) PropertyRNA *r_prop; RNA_id_pointer_create(ptr->id.data, &id_ptr); - RNA_path_resolve(&id_ptr, path, &r_ptr, &r_prop); - ret = (prop == r_prop); + if (RNA_path_resolve(&id_ptr, path, &r_ptr, &r_prop) == TRUE) { + ret = (prop == r_prop); + } + else { + ret = FALSE; + } MEM_freeN(path); } From ea56a54747dde1aaa8aa2e89d04486870c05e815 Mon Sep 17 00:00:00 2001 From: Miika Hamalainen Date: Mon, 12 Mar 2012 07:21:22 +0000 Subject: [PATCH 025/310] Fix msvc compilation errors. (__func__ undeclared) --- source/blender/blenlib/intern/BLI_heap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c index 01a38cf123e..ea22ed0c4da 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -35,6 +35,7 @@ #include "MEM_guardedalloc.h" #include "BLI_memarena.h" #include "BLI_heap.h" +#include "BLI_utildefines.h" /***/ From b22e06bf7b7aa643ae68fa08f05848475bb3dd8f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 12 Mar 2012 08:45:06 +0000 Subject: [PATCH 026/310] Re-bundle libmv from own branch. Should resolve compilation error on some platforms when using linux and compilation error of libmv on FreeBSB. It was a regression caused by not applied changes on config_linux.h and some changes made to utilities.cc were also occasionally missed. --- extern/libmv/ChangeLog | 19 +++++++++++-------- .../libmv/third_party/glog/src/config_linux.h | 11 +++++++++-- .../libmv/third_party/glog/src/utilities.cc | 6 +++--- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/extern/libmv/ChangeLog b/extern/libmv/ChangeLog index 68c3431314a..4e5c093c484 100644 --- a/extern/libmv/ChangeLog +++ b/extern/libmv/ChangeLog @@ -1,4 +1,13 @@ -commit bf0c3423ba41b90638e89a56500aeaeb120fbaf1 +commit 9fe49c32e990f28c83f2bbb1d18057aed8879af7 +Author: Sergey Sharybin +Date: Mon Mar 12 09:36:15 2012 +0600 + + Code cleanup: convert line endings to Unix style (native on my platform) so it + wouldn't confuse other versioning systems used for project where libmv is bundled to, + + Also change mode to +x for glog's windows-related script. + +commit fe74ae2b53769389b0ed9d7e604c8e60be81077d Author: Sergey I. Sharybin Date: Sun Mar 11 20:34:15 2012 +0600 @@ -9,7 +18,7 @@ Date: Sun Mar 11 20:34:15 2012 +0600 it's easier to move libraries around and even use libraries installed on the operation system. -commit 3e2673282f313c5bd19720f26d769f5d240a0563 +commit 37fc726701479f2d321d6af878fa93f3176278d5 Author: Sergey I. Sharybin Date: Sun Mar 11 19:27:41 2012 +0600 @@ -480,9 +489,3 @@ Date: Fri Aug 19 00:02:12 2011 +0200 Document coordinate descent method in affine SAD matcher. Add heuristic to prevent high distortions. - -commit 75520f4bc4ccbb272a1b4149d3b8d05a90f7f896 -Author: Matthias Fauconneau -Date: Thu Aug 18 23:14:17 2011 +0200 - - Fix affine iteration. diff --git a/extern/libmv/third_party/glog/src/config_linux.h b/extern/libmv/third_party/glog/src/config_linux.h index 19beaa5cf40..5877029882a 100644 --- a/extern/libmv/third_party/glog/src/config_linux.h +++ b/extern/libmv/third_party/glog/src/config_linux.h @@ -110,7 +110,7 @@ #define HAVE___BUILTIN_EXPECT 1 /* define if your compiler has __sync_val_compare_and_swap */ -#define HAVE___SYNC_VAL_COMPARE_AND_SWAP 1 +/* #undef HAVE___SYNC_VAL_COMPARE_AND_SWAP */ /* Define to the sub-directory in which libtool stores uninstalled libraries. */ @@ -138,7 +138,13 @@ #define PACKAGE_VERSION "0.3.2" /* How to access the PC from a struct ucontext */ -#define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP] +#if defined(_M_X64) || defined(__amd64__) || defined(__x86_64__) + #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP] +#elif defined(_M_IX86) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) + #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_EIP] +#else + #undef PC_FROM_UCONTEXT +#endif /* Define to necessary symbol if this constant uses a non-standard name on your system. */ @@ -150,6 +156,7 @@ /* Define to 1 if you have the ANSI C header files. */ /* #undef STDC_HEADERS */ +#define STDC_HEADERS 1 /* the namespace where STL code like vector<> is defined */ #define STL_NAMESPACE std diff --git a/extern/libmv/third_party/glog/src/utilities.cc b/extern/libmv/third_party/glog/src/utilities.cc index 27b2a905055..c9db2b7f7cd 100644 --- a/extern/libmv/third_party/glog/src/utilities.cc +++ b/extern/libmv/third_party/glog/src/utilities.cc @@ -233,8 +233,8 @@ bool PidHasChanged() { } pid_t GetTID() { - // On Linux and FreeBSD, we try to use gettid(). -#if defined OS_LINUX || defined OS_FREEBSD || defined OS_MACOSX + // On Linux and MACOSX , we try to use gettid(). +#if defined OS_LINUX || defined OS_MACOSX #ifndef __NR_gettid #ifdef OS_MACOSX #define __NR_gettid SYS_gettid @@ -256,7 +256,7 @@ pid_t GetTID() { // the value change to "true". lacks_gettid = true; } -#endif // OS_LINUX || OS_FREEBSD +#endif // OS_LINUX || OS_MACOSX // If gettid() could not be used, we use one of the following. #if defined OS_LINUX From e3df2697c3470b64b51eea094867b23bf386a930 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 12 Mar 2012 08:46:53 +0000 Subject: [PATCH 027/310] Commit patch from Shane Ambler to make VideoTexture compile with a clang on FreeBSD. Thanks! --- source/gameengine/VideoTexture/VideoFFmpeg.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/gameengine/VideoTexture/VideoFFmpeg.h b/source/gameengine/VideoTexture/VideoFFmpeg.h index 1c07bc957f3..40b2658eb42 100644 --- a/source/gameengine/VideoTexture/VideoFFmpeg.h +++ b/source/gameengine/VideoTexture/VideoFFmpeg.h @@ -28,6 +28,10 @@ http://www.gnu.org/copyleft/lesser.txt. #define __VIDEOFFMPEG_H__ #ifdef WITH_FFMPEG +#if defined(__FreeBSD__) +/* this needs to be parsed with __cplusplus defined before included through ffmpeg_compat.h */ +#include +#endif extern "C" { #undef __cplusplus #include From 51c553befba6799b47df14902b93c652275cebee Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 12 Mar 2012 09:20:38 +0000 Subject: [PATCH 028/310] Removing SWAP macro define from BLI_heap.c, already present in BLI_utildefines.h, giving compile error. --- source/blender/blenlib/intern/BLI_heap.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c index ea22ed0c4da..fa7b91b8539 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -54,8 +54,6 @@ struct Heap { HeapNode **tree; }; -#define SWAP(type, a, b) \ - { type sw_ap; sw_ap = (a); (a) = (b); (b) = sw_ap; } #define HEAP_PARENT(i) ((i - 1) >> 1) #define HEAP_LEFT(i) ((i << 1) + 1) #define HEAP_RIGHT(i) ((i << 1) + 2) From 30907594b6bcbc8c401d425a57bf7eadefdcaf61 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 12 Mar 2012 09:22:16 +0000 Subject: [PATCH 029/310] Style cleanup in blenfont (spaces, C++ comments, etc.). --- source/blender/blenfont/BLF_api.h | 59 +-- source/blender/blenfont/BLF_translation.h | 5 +- source/blender/blenfont/intern/blf.c | 224 +++++----- source/blender/blenfont/intern/blf_dir.c | 76 ++-- source/blender/blenfont/intern/blf_font.c | 404 +++++++++--------- source/blender/blenfont/intern/blf_glyph.c | 236 +++++----- source/blender/blenfont/intern/blf_internal.h | 2 +- source/blender/blenfont/intern/blf_lang.c | 80 ++-- .../blender/blenfont/intern/blf_translation.c | 20 +- source/blender/blenfont/intern/blf_util.c | 2 +- 10 files changed, 549 insertions(+), 559 deletions(-) diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 1e242deece4..334d356f6f9 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -76,61 +76,49 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l void BLF_draw(int fontid, const char *str, size_t len); void BLF_draw_ascii(int fontid, const char *str, size_t len); -/* - * This function return the bounding box of the string +/* This function return the bounding box of the string * and are not multiplied by the aspect. */ void BLF_boundbox(int fontid, const char *str, struct rctf *box); -/* - * The next both function return the width and height +/* The next both function return the width and height * of the string, using the current font and both value * are multiplied by the aspect of the font. */ float BLF_width(int fontid, const char *str); float BLF_height(int fontid, const char *str); -/* - * Return dimensions of the font without any sample text. - */ +/* Return dimensions of the font without any sample text. */ float BLF_height_max(int fontid); float BLF_width_max(int fontid); float BLF_descender(int fontid); float BLF_ascender(int fontid); -/* - * The following function return the width and height of the string, but +/* The following function return the width and height of the string, but * just in one call, so avoid extra freetype2 stuff. */ void BLF_width_and_height(int fontid, const char *str, float *width, float *height); -/* - * For fixed width fonts only, returns the width of a +/* For fixed width fonts only, returns the width of a * character. */ float BLF_fixed_width(int fontid); -/* - * and this two function return the width and height +/* and this two function return the width and height * of the string, using the default font and both value * are multiplied by the aspect of the font. */ float BLF_width_default(const char *str); float BLF_height_default(const char *str); -/* - * Set rotation for default font. - */ +/* Set rotation for default font. */ void BLF_rotation_default(float angle); -/* - * Enable/disable options to the default font. - */ +/* Enable/disable options to the default font. */ void BLF_enable_default(int option); void BLF_disable_default(int option); -/* - * By default, rotation and clipping are disable and +/* By default, rotation and clipping are disable and * have to be enable/disable using BLF_enable/disable. */ void BLF_rotation(int fontid, float angle); @@ -141,39 +129,34 @@ void BLF_blur(int fontid, int size); void BLF_enable(int fontid, int option); void BLF_disable(int fontid, int option); -/* - * Shadow options, level is the blur level, can be 3, 5 or 0 and +/* Shadow options, level is the blur level, can be 3, 5 or 0 and * the other argument are the rgba color. - * Take care that shadow need to be enable using BLF_enable!!. + * Take care that shadow need to be enable using BLF_enable!!! */ void BLF_shadow(int fontid, int level, float r, float g, float b, float a); -/* - * Set the offset for shadow text, this is the current cursor +/* Set the offset for shadow text, this is the current cursor * position plus this offset, don't need call BLF_position before * this function, the current position is calculate only on * BLF_draw, so it's safe call this whenever you like. */ void BLF_shadow_offset(int fontid, int x, int y); -/* - * Set the buffer, size and number of channels to draw, one thing to take care is call +/* Set the buffer, size and number of channels to draw, one thing to take care is call * this function with NULL pointer when we finish, for example: - * BLF_buffer(my_fbuf, my_cbuf, 100, 100, 4); * - * ... set color, position and draw ... + * BLF_buffer(my_fbuf, my_cbuf, 100, 100, 4); * - * BLF_buffer(NULL, NULL, 0, 0, 0); + * ... set color, position and draw ... + * + * BLF_buffer(NULL, NULL, 0, 0, 0); */ void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch); -/* - * Set the color to be used for text. - */ +/* Set the color to be used for text. */ void BLF_buffer_col(int fontid, float r, float g, float b, float a); -/* - * Draw the string into the buffer, this function draw in both buffer, float and unsigned char _BUT_ +/* Draw the string into the buffer, this function draw in both buffer, float and unsigned char _BUT_ * it's not necessary set both buffer, NULL is valid here. */ void BLF_draw_buffer(int fontid, const char *str); @@ -200,8 +183,8 @@ void BLF_dir_free(char **dirs, int count); #define BLF_DRAW_STR_DUMMY_MAX 1024 -// XXX, bad design +/* XXX, bad design */ extern int blf_mono_font; -extern int blf_mono_font_render; // dont mess drawing with render threads. +extern int blf_mono_font_render; /* dont mess drawing with render threads. */ #endif /* __BLF_API_H__ */ diff --git a/source/blender/blenfont/BLF_translation.h b/source/blender/blenfont/BLF_translation.h index 868a58d23c0..4e09eb60928 100644 --- a/source/blender/blenfont/BLF_translation.h +++ b/source/blender/blenfont/BLF_translation.h @@ -47,8 +47,7 @@ const char *BLF_pgettext(const char *context, const char *message); /* blf_lang.c */ -/* - * Search the path directory to the locale files, this try all +/* Search the path directory to the locale files, this try all * the case for Linux, Win and Mac. */ void BLF_lang_init(void); @@ -66,7 +65,7 @@ const char *BLF_translate_do_iface(const char *msgid); const char *BLF_translate_do_tooltip(const char *msgid); -/*#define _(msgid) BLF_gettext(msgid)*/ +/* #define _(msgid) BLF_gettext(msgid) */ /* The "translation-marker" macro. */ #define N_(msgid) msgid /* Those macros should be used everywhere in UI code. */ diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index a387b416c38..626c591c40f 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -62,13 +62,13 @@ static FontBLF *global_font[BLF_MAX_FONT] = {0}; /* Default size and dpi, for BLF_draw_default. */ -static int global_font_default= -1; -static int global_font_points= 11; -static int global_font_dpi= 72; +static int global_font_default = -1; +static int global_font_points = 11; +static int global_font_dpi = 72; -// XXX, should these be made into global_font_'s too? -int blf_mono_font= -1; -int blf_mono_font_render= -1; +/* XXX, should these be made into global_font_'s too? */ +int blf_mono_font = -1; +int blf_mono_font_render = -1; static FontBLF *BLF_get(int fontid) { @@ -81,11 +81,11 @@ int BLF_init(int points, int dpi) { int i; - for (i= 0; i < BLF_MAX_FONT; i++) - global_font[i]= NULL; + for (i = 0; i < BLF_MAX_FONT; i++) + global_font[i] = NULL; - global_font_points= points; - global_font_dpi= dpi; + global_font_points = points; + global_font_dpi = dpi; return blf_font_init(); } @@ -94,11 +94,11 @@ void BLF_exit(void) FontBLF *font; int i; - for (i= 0; i < BLF_MAX_FONT; i++) { - font= global_font[i]; + for (i = 0; i < BLF_MAX_FONT; i++) { + font = global_font[i]; if (font) { blf_font_free(font); - global_font[i]= NULL; + global_font[i] = NULL; } } @@ -110,8 +110,8 @@ void BLF_cache_clear(void) FontBLF *font; int i; - for (i= 0; i < BLF_MAX_FONT; i++) { - font= global_font[i]; + for (i = 0; i < BLF_MAX_FONT; i++) { + font = global_font[i]; if (font) blf_glyph_cache_clear(font); } @@ -122,8 +122,8 @@ static int blf_search(const char *name) FontBLF *font; int i; - for (i= 0; i < BLF_MAX_FONT; i++) { - font= global_font[i]; + for (i = 0; i < BLF_MAX_FONT; i++) { + font = global_font[i]; if (font && (!strcmp(font->name, name))) return i; } @@ -135,8 +135,8 @@ static int blf_search_available(void) { int i; - for (i= 0; i < BLF_MAX_FONT; i++) - if(!global_font[i]) + for (i = 0; i < BLF_MAX_FONT; i++) + if (!global_font[i]) return i; return -1; @@ -152,7 +152,7 @@ int BLF_load(const char *name) return -1; /* check if we already load this font. */ - i= blf_search(name); + i = blf_search(name); if (i >= 0) { /*font= global_font[i];*/ /*UNUSED*/ return i; @@ -164,13 +164,13 @@ int BLF_load(const char *name) return -1; } - filename= blf_dir_search(name); + filename = blf_dir_search(name); if (!filename) { printf("Can't find font: %s\n", name); return -1; } - font= blf_font_new(name, filename); + font = blf_font_new(name, filename); MEM_freeN(filename); if (!font) { @@ -178,7 +178,7 @@ int BLF_load(const char *name) return -1; } - global_font[i]= font; + global_font[i] = font; return i; } @@ -200,13 +200,13 @@ int BLF_load_unique(const char *name) return -1; } - filename= blf_dir_search(name); + filename = blf_dir_search(name); if (!filename) { printf("Can't find font: %s\n", name); return -1; } - font= blf_font_new(name, filename); + font = blf_font_new(name, filename); MEM_freeN(filename); if (!font) { @@ -214,13 +214,13 @@ int BLF_load_unique(const char *name) return -1; } - global_font[i]= font; + global_font[i] = font; return i; } void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { blf_font_attach_from_mem(font, mem, mem_size); @@ -235,7 +235,7 @@ int BLF_load_mem(const char *name, unsigned char *mem, int mem_size) if (!name) return -1; - i= blf_search(name); + i = blf_search(name); if (i >= 0) { /*font= global_font[i];*/ /*UNUSED*/ return i; @@ -252,13 +252,13 @@ int BLF_load_mem(const char *name, unsigned char *mem, int mem_size) return -1; } - font= blf_font_new_from_mem(name, mem, mem_size); + font = blf_font_new_from_mem(name, mem, mem_size); if (!font) { printf("Can't load font: %s from memory!!\n", name); return -1; } - global_font[i]= font; + global_font[i] = font; return i; } @@ -285,13 +285,13 @@ int BLF_load_mem_unique(const char *name, unsigned char *mem, int mem_size) return -1; } - font= blf_font_new_from_mem(name, mem, mem_size); + font = blf_font_new_from_mem(name, mem, mem_size); if (!font) { printf("Can't load font: %s from memory!!\n", name); return -1; } - global_font[i]= font; + global_font[i] = font; return i; } @@ -300,19 +300,19 @@ void BLF_unload(const char *name) FontBLF *font; int i; - for (i= 0; i < BLF_MAX_FONT; i++) { - font= global_font[i]; + for (i = 0; i < BLF_MAX_FONT; i++) { + font = global_font[i]; if (font && (!strcmp(font->name, name))) { blf_font_free(font); - global_font[i]= NULL; + global_font[i] = NULL; } } } void BLF_enable(int fontid, int option) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { font->flags |= option; @@ -321,7 +321,7 @@ void BLF_enable(int fontid, int option) void BLF_disable(int fontid, int option) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { font->flags &= ~option; @@ -330,7 +330,7 @@ void BLF_disable(int fontid, int option) void BLF_enable_default(int option) { - FontBLF *font= BLF_get(global_font_default); + FontBLF *font = BLF_get(global_font_default); if (font) { font->flags |= option; @@ -339,7 +339,7 @@ void BLF_enable_default(int option) void BLF_disable_default(int option) { - FontBLF *font= BLF_get(global_font_default); + FontBLF *font = BLF_get(global_font_default); if (font) { font->flags &= ~option; @@ -348,18 +348,18 @@ void BLF_disable_default(int option) void BLF_aspect(int fontid, float x, float y, float z) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { - font->aspect[0]= x; - font->aspect[1]= y; - font->aspect[2]= z; + font->aspect[0] = x; + font->aspect[1] = y; + font->aspect[2] = z; } } void BLF_matrix(int fontid, const double m[16]) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { memcpy(font->m, m, sizeof(font->m)); @@ -368,24 +368,24 @@ void BLF_matrix(int fontid, const double m[16]) void BLF_position(int fontid, float x, float y, float z) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { float xa, ya, za; float remainder; if (font->flags & BLF_ASPECT) { - xa= font->aspect[0]; - ya= font->aspect[1]; - za= font->aspect[2]; + xa = font->aspect[0]; + ya = font->aspect[1]; + za = font->aspect[2]; } else { - xa= 1.0f; - ya= 1.0f; - za= 1.0f; + xa = 1.0f; + ya = 1.0f; + za = 1.0f; } - remainder= x - floorf(x); + remainder = x - floorf(x); if (remainder > 0.4f && remainder < 0.6f) { if (remainder < 0.5f) x -= 0.1f * xa; @@ -393,7 +393,7 @@ void BLF_position(int fontid, float x, float y, float z) x += 0.1f * xa; } - remainder= y - floorf(y); + remainder = y - floorf(y); if (remainder > 0.4f && remainder < 0.6f) { if (remainder < 0.5f) y -= 0.1f * ya; @@ -401,7 +401,7 @@ void BLF_position(int fontid, float x, float y, float z) y += 0.1f * ya; } - remainder= z - floorf(z); + remainder = z - floorf(z); if (remainder > 0.4f && remainder < 0.6f) { if (remainder < 0.5f) z -= 0.1f * za; @@ -409,15 +409,15 @@ void BLF_position(int fontid, float x, float y, float z) z += 0.1f * za; } - font->pos[0]= x; - font->pos[1]= y; - font->pos[2]= z; + font->pos[0] = x; + font->pos[1] = y; + font->pos[2] = z; } } void BLF_size(int fontid, int size, int dpi) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { blf_font_size(font, size, dpi); @@ -426,10 +426,10 @@ void BLF_size(int fontid, int size, int dpi) void BLF_blur(int fontid, int size) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { - font->blur= size; + font->blur = size; } } @@ -439,7 +439,7 @@ void BLF_draw_default(float x, float y, float z, const char *str, size_t len) return; if (global_font_default == -1) - global_font_default= blf_search("default"); + global_font_default = blf_search("default"); if (global_font_default == -1) { printf("Warning: Can't found default font!!\n"); @@ -458,7 +458,7 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l return; if (global_font_default == -1) - global_font_default= blf_search("default"); + global_font_default = blf_search("default"); if (global_font_default == -1) { printf("Warning: Can't found default font!!\n"); @@ -472,10 +472,10 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l void BLF_rotation_default(float angle) { - FontBLF *font= BLF_get(global_font_default); + FontBLF *font = BLF_get(global_font_default); if (font) { - font->angle= angle; + font->angle = angle; } } @@ -511,11 +511,11 @@ static void blf_draw__start(FontBLF *font, GLint *mode, GLint *param) if (font->flags & BLF_ROTATION) glRotatef(font->angle, 0.0f, 0.0f, 1.0f); - if(font->shadow || font->blur) + if (font->shadow || font->blur) glGetFloatv(GL_CURRENT_COLOR, font->orig_col); /* always bind the texture for the first glyph */ - font->tex_bind_state= -1; + font->tex_bind_state = -1; /* Save the current parameter to restore it later. */ glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param); @@ -544,7 +544,7 @@ static void blf_draw__end(GLint mode, GLint param) void BLF_draw(int fontid, const char *str, size_t len) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); GLint mode, param; if (font && font->glyph_cache) { @@ -556,7 +556,7 @@ void BLF_draw(int fontid, const char *str, size_t len) void BLF_draw_ascii(int fontid, const char *str, size_t len) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); GLint mode, param; if (font && font->glyph_cache) { @@ -568,7 +568,7 @@ void BLF_draw_ascii(int fontid, const char *str, size_t len) void BLF_boundbox(int fontid, const char *str, rctf *box) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { blf_font_boundbox(font, str, box); @@ -577,7 +577,7 @@ void BLF_boundbox(int fontid, const char *str, rctf *box) void BLF_width_and_height(int fontid, const char *str, float *width, float *height) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font && font->glyph_cache) { blf_font_width_and_height(font, str, width, height); @@ -586,7 +586,7 @@ void BLF_width_and_height(int fontid, const char *str, float *width, float *heig float BLF_width(int fontid, const char *str) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font && font->glyph_cache) { return blf_font_width(font, str); @@ -597,7 +597,7 @@ float BLF_width(int fontid, const char *str) float BLF_fixed_width(int fontid) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font && font->glyph_cache) { return blf_font_fixed_width(font); @@ -609,7 +609,7 @@ float BLF_fixed_width(int fontid) float BLF_width_default(const char *str) { if (global_font_default == -1) - global_font_default= blf_search("default"); + global_font_default = blf_search("default"); if (global_font_default == -1) { printf("Error: Can't found default font!!\n"); @@ -622,7 +622,7 @@ float BLF_width_default(const char *str) float BLF_height(int fontid, const char *str) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font && font->glyph_cache) { return blf_font_height(font, str); @@ -633,7 +633,7 @@ float BLF_height(int fontid, const char *str) float BLF_height_max(int fontid) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font && font->glyph_cache) { return font->glyph_cache->max_glyph_height; @@ -644,7 +644,7 @@ float BLF_height_max(int fontid) float BLF_width_max(int fontid) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font && font->glyph_cache) { return font->glyph_cache->max_glyph_width; @@ -655,7 +655,7 @@ float BLF_width_max(int fontid) float BLF_descender(int fontid) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font && font->glyph_cache) { return font->glyph_cache->descender; @@ -666,7 +666,7 @@ float BLF_descender(int fontid) float BLF_ascender(int fontid) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font && font->glyph_cache) { return font->glyph_cache->ascender; @@ -678,7 +678,7 @@ float BLF_ascender(int fontid) float BLF_height_default(const char *str) { if (global_font_default == -1) - global_font_default= blf_search("default"); + global_font_default = blf_search("default"); if (global_font_default == -1) { printf("Error: Can't found default font!!\n"); @@ -692,88 +692,88 @@ float BLF_height_default(const char *str) void BLF_rotation(int fontid, float angle) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { - font->angle= angle; + font->angle = angle; } } void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { - font->clip_rec.xmin= xmin; - font->clip_rec.ymin= ymin; - font->clip_rec.xmax= xmax; - font->clip_rec.ymax= ymax; + font->clip_rec.xmin = xmin; + font->clip_rec.ymin = ymin; + font->clip_rec.xmax = xmax; + font->clip_rec.ymax = ymax; } } void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax) { - FontBLF *font= BLF_get(global_font_default); + FontBLF *font = BLF_get(global_font_default); if (font) { - font->clip_rec.xmin= xmin; - font->clip_rec.ymin= ymin; - font->clip_rec.xmax= xmax; - font->clip_rec.ymax= ymax; + font->clip_rec.xmin = xmin; + font->clip_rec.ymin = ymin; + font->clip_rec.xmax = xmax; + font->clip_rec.ymax = ymax; } } void BLF_shadow(int fontid, int level, float r, float g, float b, float a) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { - font->shadow= level; - font->shadow_col[0]= r; - font->shadow_col[1]= g; - font->shadow_col[2]= b; - font->shadow_col[3]= a; + font->shadow = level; + font->shadow_col[0] = r; + font->shadow_col[1] = g; + font->shadow_col[2] = b; + font->shadow_col[3] = a; } } void BLF_shadow_offset(int fontid, int x, int y) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { - font->shadow_x= x; - font->shadow_y= y; + font->shadow_x = x; + font->shadow_y = y; } } void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { - font->b_fbuf= fbuf; - font->b_cbuf= cbuf; - font->bw= w; - font->bh= h; - font->bch= nch; + font->b_fbuf = fbuf; + font->b_cbuf = cbuf; + font->bw = w; + font->bh = h; + font->bch = nch; } } void BLF_buffer_col(int fontid, float r, float g, float b, float a) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font) { - font->b_col[0]= r; - font->b_col[1]= g; - font->b_col[2]= b; - font->b_col[3]= a; + font->b_col[0] = r; + font->b_col[1] = g; + font->b_col[2] = b; + font->b_col[3] = a; } } void BLF_draw_buffer(int fontid, const char *str) { - FontBLF *font= BLF_get(fontid); + FontBLF *font = BLF_get(fontid); if (font && font->glyph_cache && (font->b_fbuf || font->b_cbuf)) { blf_font_buffer(font, str); diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c index b82393fad92..824f1715f3c 100644 --- a/source/blender/blenfont/intern/blf_dir.c +++ b/source/blender/blenfont/intern/blf_dir.c @@ -51,17 +51,17 @@ #include "blf_internal_types.h" #include "blf_internal.h" -static ListBase global_font_dir= { NULL, NULL }; +static ListBase global_font_dir = { NULL, NULL }; static DirBLF *blf_dir_find(const char *path) { DirBLF *p; - p= global_font_dir.first; + p = global_font_dir.first; while (p) { if (BLI_path_cmp(p->path, path) == 0) return p; - p= p->next; + p = p->next; } return NULL; } @@ -70,12 +70,12 @@ void BLF_dir_add(const char *path) { DirBLF *dir; - dir= blf_dir_find(path); + dir = blf_dir_find(path); if (dir) /* already in the list ? just return. */ return; - dir= (DirBLF *)MEM_callocN(sizeof(DirBLF), "BLF_dir_add"); - dir->path= BLI_strdup(path); + dir = (DirBLF *)MEM_callocN(sizeof(DirBLF), "BLF_dir_add"); + dir->path = BLI_strdup(path); BLI_addhead(&global_font_dir, dir); } @@ -83,7 +83,7 @@ void BLF_dir_rem(const char *path) { DirBLF *dir; - dir= blf_dir_find(path); + dir = blf_dir_find(path); if (dir) { BLI_remlink(&global_font_dir, dir); MEM_freeN(dir->path); @@ -98,19 +98,19 @@ char **BLF_dir_get(int *ndir) char *path; int i, count; - count= BLI_countlist(&global_font_dir); + count = BLI_countlist(&global_font_dir); if (!count) return NULL; - dirs= (char **)MEM_callocN(sizeof(char *) * count, "BLF_dir_get"); - p= global_font_dir.first; - i= 0; + dirs = (char **)MEM_callocN(sizeof(char *) * count, "BLF_dir_get"); + p = global_font_dir.first; + i = 0; while (p) { - path= BLI_strdup(p->path); - dirs[i]= path; - p= p->next; + path = BLI_strdup(p->path); + dirs[i] = path; + p = p->next; } - *ndir= i; + *ndir = i; return dirs; } @@ -119,8 +119,8 @@ void BLF_dir_free(char **dirs, int count) char *path; int i; - for (i= 0; i < count; i++) { - path= dirs[i]; + for (i = 0; i < count; i++) { + path = dirs[i]; MEM_freeN(path); } MEM_freeN(dirs); @@ -130,12 +130,12 @@ char *blf_dir_search(const char *file) { DirBLF *dir; char full_path[FILE_MAX]; - char *s= NULL; + char *s = NULL; - for(dir=global_font_dir.first; dir; dir= dir->next) { + for (dir = global_font_dir.first; dir; dir = dir->next) { BLI_join_dirfile(full_path, sizeof(full_path), dir->path, file); if (BLI_exists(full_path)) { - s= BLI_strdup(full_path); + s = BLI_strdup(full_path); break; } } @@ -143,32 +143,32 @@ char *blf_dir_search(const char *file) if (!s) { /* check the current directory, why not ? */ if (BLI_exists(file)) - s= BLI_strdup(file); + s = BLI_strdup(file); } return s; } -#if 0 // UNUSED +#if 0 /* UNUSED */ int blf_dir_split(const char *str, char *file, int *size) { int i, len; char *s; /* Window, Linux or Mac, this is always / */ - s= strrchr(str, '/'); + s = strrchr(str, '/'); if (s) { - len= s - str; - for (i= 0; i < len; i++) - file[i]= str[i]; + len = s - str; + for (i = 0; i < len; i++) + file[i] = str[i]; - file[i]= '.'; - file[i+1]= 't'; - file[i+2]= 't'; - file[i+3]= 'f'; - file[i+4]= '\0'; + file[i] = '.'; + file[i+1] = 't'; + file[i+2] = 't'; + file[i+3] = 'f'; + file[i+4] = '\0'; s++; - *size= atoi(s); + *size = atoi(s); return 1; } return 0; @@ -183,24 +183,24 @@ char *blf_dir_metrics_search(const char *filename) char *mfile; char *s; - mfile= BLI_strdup(filename); - s= strrchr(mfile, '.'); + mfile = BLI_strdup(filename); + s = strrchr(mfile, '.'); if (s) { if (BLI_strnlen(s, 4) < 4) { MEM_freeN(mfile); return NULL; } s++; - s[0]= 'a'; - s[1]= 'f'; - s[2]= 'm'; + s[0] = 'a'; + s[1] = 'f'; + s[2] = 'm'; /* first check .afm */ if (BLI_exists(s)) return s; /* and now check .pfm */ - s[0]= 'p'; + s[0] = 'p'; if (BLI_exists(s)) return s; diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 7ec7e2357dd..69259aa6719 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -73,43 +73,43 @@ void blf_font_size(FontBLF *font, int size, int dpi) GlyphCacheBLF *gc; FT_Error err; - err= FT_Set_Char_Size(font->face, 0, (size * 64), dpi, dpi); + err = FT_Set_Char_Size(font->face, 0, (size * 64), dpi, dpi); if (err) { /* FIXME: here we can go through the fixed size and choice a close one */ printf("The current font don't support the size, %d and dpi, %d\n", size, dpi); return; } - font->size= size; - font->dpi= dpi; + font->size = size; + font->dpi = dpi; - gc= blf_glyph_cache_find(font, size, dpi); + gc = blf_glyph_cache_find(font, size, dpi); if (gc) - font->glyph_cache= gc; + font->glyph_cache = gc; else { - gc= blf_glyph_cache_new(font); + gc = blf_glyph_cache_new(font); if (gc) - font->glyph_cache= gc; + font->glyph_cache = gc; else - font->glyph_cache= NULL; + font->glyph_cache = NULL; } } static void blf_font_ensure_ascii_table(FontBLF *font) { - GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; + GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table; /* build ascii on demand */ - if(glyph_ascii_table['0']==NULL) { + if (glyph_ascii_table['0'] == NULL) { GlyphBLF *g; unsigned int i; - for(i=0; i<256; i++) { - g= blf_glyph_search(font->glyph_cache, i); + for (i = 0; i<256; i++) { + g = blf_glyph_search(font->glyph_cache, i); if (!g) { - FT_UInt glyph_index= FT_Get_Char_Index(font->face, i); - g= blf_glyph_add(font, glyph_index, i); + FT_UInt glyph_index = FT_Get_Char_Index(font->face, i); + g = blf_glyph_add(font, glyph_index, i); } - glyph_ascii_table[i]= g; + glyph_ascii_table[i] = g; } } } @@ -122,67 +122,69 @@ static void blf_font_ensure_ascii_table(FontBLF *font) /* Note, * blf_font_ensure_ascii_table(font); must be called before this macro */ -#define BLF_UTF8_NEXT_FAST(_font, _g, _str, _i, _c, _glyph_ascii_table) \ - if(((_c)= (_str)[_i]) < 0x80) { \ - _g= (_glyph_ascii_table)[_c]; \ - _i++; \ - } \ - else if ((_c= BLI_str_utf8_as_unicode_step(_str, &(_i)))!=BLI_UTF8_ERR) { \ - if ((_g= blf_glyph_search((_font)->glyph_cache, _c)) == NULL) { \ - _g= blf_glyph_add(_font, \ - FT_Get_Char_Index((_font)->face, _c), _c); \ - } \ - } \ +#define BLF_UTF8_NEXT_FAST(_font, _g, _str, _i, _c, _glyph_ascii_table) \ + if (((_c) = (_str)[_i]) < 0x80) { \ + _g = (_glyph_ascii_table)[_c]; \ + _i++; \ + } \ + else if ((_c = BLI_str_utf8_as_unicode_step(_str, &(_i))) != BLI_UTF8_ERR) { \ + if ((_g = blf_glyph_search((_font)->glyph_cache, _c)) == NULL) { \ + _g = blf_glyph_add(_font, \ + FT_Get_Char_Index((_font)->face, _c), _c); \ + } \ + } \ -#define BLF_KERNING_VARS(_font, _has_kerning, _kern_mode) \ - const short _has_kerning= FT_HAS_KERNING((_font)->face); \ - const FT_UInt _kern_mode= (_has_kerning == 0) ? 0 : \ - (((_font)->flags & BLF_KERNING_DEFAULT) ? \ - ft_kerning_default : FT_KERNING_UNFITTED) \ +#define BLF_KERNING_VARS(_font, _has_kerning, _kern_mode) \ + const short _has_kerning = FT_HAS_KERNING((_font)->face); \ + const FT_UInt _kern_mode = (_has_kerning == 0) ? 0 : \ + (((_font)->flags & BLF_KERNING_DEFAULT) ? \ + ft_kerning_default : FT_KERNING_UNFITTED) \ -#define BLF_KERNING_STEP(_font, _kern_mode, _g_prev, _g, _delta, _pen_x) \ -{ \ - if (_g_prev) { \ - _delta.x= _delta.y= 0; \ - if (FT_Get_Kerning((_font)->face, \ - (_g_prev)->idx, \ - (_g)->idx, \ - _kern_mode, \ - &(_delta)) == 0) \ - { \ - _pen_x += delta.x >> 6; \ - } \ - } \ -} \ +#define BLF_KERNING_STEP(_font, _kern_mode, _g_prev, _g, _delta, _pen_x) \ +{ \ + if (_g_prev) { \ + _delta.x = _delta.y = 0; \ + if (FT_Get_Kerning((_font)->face, \ + (_g_prev)->idx, \ + (_g)->idx, \ + _kern_mode, \ + &(_delta)) == 0) \ + { \ + _pen_x += delta.x >> 6; \ + } \ + } \ +} \ void blf_font_draw(FontBLF *font, const char *str, unsigned int len) { unsigned int c; - GlyphBLF *g, *g_prev= NULL; + GlyphBLF *g, *g_prev = NULL; FT_Vector delta; - int pen_x= 0, pen_y= 0; - size_t i= 0; - GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; + int pen_x = 0, pen_y = 0; + size_t i = 0; + GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table; BLF_KERNING_VARS(font, has_kerning, kern_mode); blf_font_ensure_ascii_table(font); while (str[i] && i < len) { - BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); - if (c == BLI_UTF8_ERR) break; - if (g == NULL) continue; - if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); + if (c == BLI_UTF8_ERR) + break; + if (g == NULL) + continue; + if (has_kerning) + BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); /* do not return this loop if clipped, we want every character tested */ blf_glyph_render(font, g, (float)pen_x, (float)pen_y); pen_x += g->advance; - g_prev= g; + g_prev = g; } } @@ -190,24 +192,26 @@ void blf_font_draw(FontBLF *font, const char *str, unsigned int len) void blf_font_draw_ascii(FontBLF *font, const char *str, unsigned int len) { unsigned char c; - GlyphBLF *g, *g_prev= NULL; + GlyphBLF *g, *g_prev = NULL; FT_Vector delta; - int pen_x= 0, pen_y= 0; - GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; + int pen_x = 0, pen_y = 0; + GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table; BLF_KERNING_VARS(font, has_kerning, kern_mode); blf_font_ensure_ascii_table(font); - while ((c= *(str++)) && len--) { - if ((g= glyph_ascii_table[c]) == NULL) continue; - if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); + while ((c = *(str++)) && len--) { + if ((g = glyph_ascii_table[c]) == NULL) + continue; + if (has_kerning) + BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); /* do not return this loop if clipped, we want every character tested */ blf_glyph_render(font, g, (float)pen_x, (float)pen_y); pen_x += g->advance; - g_prev= g; + g_prev = g; } } @@ -215,17 +219,17 @@ void blf_font_draw_ascii(FontBLF *font, const char *str, unsigned int len) void blf_font_buffer(FontBLF *font, const char *str) { unsigned int c; - GlyphBLF *g, *g_prev= NULL; + GlyphBLF *g, *g_prev = NULL; FT_Vector delta; - int pen_x= (int)font->pos[0], pen_y= 0; - size_t i= 0; - GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; + int pen_x = (int)font->pos[0], pen_y = 0; + size_t i = 0; + GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table; /* buffer specific vars*/ - const unsigned char b_col_char[4]= {font->b_col[0] * 255, - font->b_col[1] * 255, - font->b_col[2] * 255, - font->b_col[3] * 255}; + const unsigned char b_col_char[4] = {font->b_col[0] * 255, + font->b_col[1] * 255, + font->b_col[2] * 255, + font->b_col[3] * 255}; unsigned char *cbuf; int chx, chy; int y, x; @@ -236,15 +240,17 @@ void blf_font_buffer(FontBLF *font, const char *str) blf_font_ensure_ascii_table(font); while (str[i]) { - BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); - if (c == BLI_UTF8_ERR) break; - if (g == NULL) continue; - if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); + if (c == BLI_UTF8_ERR) + break; + if (g == NULL) + continue; + if (has_kerning) + BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); - chx= pen_x + ((int)g->pos_x); - chy= (int)font->pos[1] + g->height; + chx = pen_x + ((int)g->pos_x); + chy = (int)font->pos[1] + g->height; if (g->pitch < 0) { pen_y = (int)font->pos[1] + (g->height - (int)g->pos_y); @@ -255,41 +261,42 @@ void blf_font_buffer(FontBLF *font, const char *str) if ((chx + g->width) >= 0 && chx < font->bw && (pen_y + g->height) >= 0 && pen_y < font->bh) { /* dont draw beyond the buffer bounds */ - int width_clip= g->width; - int height_clip= g->height; - int yb_start= g->pitch < 0 ? 0 : g->height-1; + int width_clip = g->width; + int height_clip = g->height; + int yb_start = g->pitch < 0 ? 0 : g->height-1; - if (width_clip + chx > font->bw) width_clip -= chx + width_clip - font->bw; - if (height_clip + pen_y > font->bh) height_clip -= pen_y + height_clip - font->bh; + if (width_clip + chx > font->bw) + width_clip -= chx + width_clip - font->bw; + if (height_clip + pen_y > font->bh) + height_clip -= pen_y + height_clip - font->bh; /* drawing below the image? */ - if(pen_y < 0) { + if (pen_y < 0) { yb_start += (g->pitch < 0) ? -pen_y : pen_y; height_clip += pen_y; - pen_y= 0; + pen_y = 0; } if (font->b_fbuf) { - int yb= yb_start; - for (y=(chy >= 0 ? 0:-chy); y < height_clip; y++) { - for (x=(chx >= 0 ? 0:-chx); x < width_clip; x++) { - - a= *(g->bitmap + x + (yb * g->pitch)) / 255.0f; + int yb = yb_start; + for (y = (chy >= 0 ? 0:-chy); y < height_clip; y++) { + for (x = (chx >= 0 ? 0:-chx); x < width_clip; x++) { + a = *(g->bitmap + x + (yb * g->pitch)) / 255.0f; - if(a > 0.0f) { + if (a > 0.0f) { float alphatest; - fbuf= font->b_fbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw)); + fbuf = font->b_fbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw)); if (a >= 1.0f) { - fbuf[0]= font->b_col[0]; - fbuf[1]= font->b_col[1]; - fbuf[2]= font->b_col[2]; - fbuf[3]= (alphatest= (fbuf[3] + (font->b_col[3]))) < 1.0f ? alphatest : 1.0f; + fbuf[0] = font->b_col[0]; + fbuf[1] = font->b_col[1]; + fbuf[2] = font->b_col[2]; + fbuf[3] = (alphatest = (fbuf[3] + (font->b_col[3]))) < 1.0f ? alphatest : 1.0f; } else { - fbuf[0]= (font->b_col[0]*a) + (fbuf[0] * (1-a)); - fbuf[1]= (font->b_col[1]*a) + (fbuf[1] * (1-a)); - fbuf[2]= (font->b_col[2]*a) + (fbuf[2] * (1-a)); - fbuf[3]= (alphatest= (fbuf[3] + (font->b_col[3]*a))) < 1.0f ? alphatest : 1.0f; + fbuf[0] = (font->b_col[0]*a) + (fbuf[0] * (1-a)); + fbuf[1] = (font->b_col[1]*a) + (fbuf[1] * (1-a)); + fbuf[2] = (font->b_col[2]*a) + (fbuf[2] * (1-a)); + fbuf[3] = (alphatest = (fbuf[3] + (font->b_col[3]*a))) < 1.0f ? alphatest : 1.0f; } } } @@ -302,25 +309,26 @@ void blf_font_buffer(FontBLF *font, const char *str) } if (font->b_cbuf) { - int yb= yb_start; - for (y= 0; y < height_clip; y++) { - for (x= 0; x < width_clip; x++) { - a= *(g->bitmap + x + (yb * g->pitch)) / 255.0f; + int yb = yb_start; + for (y = 0; y < height_clip; y++) { + for (x = 0; x < width_clip; x++) { + a = *(g->bitmap + x + (yb * g->pitch)) / 255.0f; - if(a > 0.0f) { + if (a > 0.0f) { int alphatest; - cbuf= font->b_cbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw)); + cbuf = font->b_cbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw)); if (a >= 1.0f) { - cbuf[0]= b_col_char[0]; - cbuf[1]= b_col_char[1]; - cbuf[2]= b_col_char[2]; - cbuf[3]= (alphatest= ((int)cbuf[3] + (int)b_col_char[3])) < 255 ? alphatest : 255; + cbuf[0] = b_col_char[0]; + cbuf[1] = b_col_char[1]; + cbuf[2] = b_col_char[2]; + cbuf[3] = (alphatest = ((int)cbuf[3] + (int)b_col_char[3])) < 255 ? alphatest : 255; } else { - cbuf[0]= (b_col_char[0]*a) + (cbuf[0] * (1-a)); - cbuf[1]= (b_col_char[1]*a) + (cbuf[1] * (1-a)); - cbuf[2]= (b_col_char[2]*a) + (cbuf[2] * (1-a)); - cbuf[3]= (alphatest= ((int)cbuf[3] + (int)((font->b_col[3]*a)*255.0f))) < 255 ? alphatest : 255; + cbuf[0] = (b_col_char[0]*a) + (cbuf[0] * (1-a)); + cbuf[1] = (b_col_char[1]*a) + (cbuf[1] * (1-a)); + cbuf[2] = (b_col_char[2]*a) + (cbuf[2] * (1-a)); + cbuf[3] = (alphatest = ((int)cbuf[3] + (int)((font->b_col[3]*a)*255.0f))) < + 255 ? alphatest : 255; } } } @@ -334,58 +342,60 @@ void blf_font_buffer(FontBLF *font, const char *str) } pen_x += g->advance; - g_prev= g; + g_prev = g; } } void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) { unsigned int c; - GlyphBLF *g, *g_prev= NULL; + GlyphBLF *g, *g_prev = NULL; FT_Vector delta; - int pen_x= 0, pen_y= 0; - size_t i= 0; - GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; + int pen_x = 0, pen_y = 0; + size_t i = 0; + GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table; rctf gbox; BLF_KERNING_VARS(font, has_kerning, kern_mode); - box->xmin= 32000.0f; - box->xmax= -32000.0f; - box->ymin= 32000.0f; - box->ymax= -32000.0f; + box->xmin = 32000.0f; + box->xmax = -32000.0f; + box->ymin = 32000.0f; + box->ymax = -32000.0f; blf_font_ensure_ascii_table(font); while (str[i]) { - BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); - if (c == BLI_UTF8_ERR) break; - if (g == NULL) continue; - if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); + if (c == BLI_UTF8_ERR) + break; + if (g == NULL) + continue; + if (has_kerning) + BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); - gbox.xmin= pen_x; - gbox.xmax= pen_x + g->advance; - gbox.ymin= g->box.ymin + pen_y; - gbox.ymax= g->box.ymax + pen_y; + gbox.xmin = pen_x; + gbox.xmax = pen_x + g->advance; + gbox.ymin = g->box.ymin + pen_y; + gbox.ymax = g->box.ymax + pen_y; - if (gbox.xmin < box->xmin) box->xmin= gbox.xmin; - if (gbox.ymin < box->ymin) box->ymin= gbox.ymin; + if (gbox.xmin < box->xmin) box->xmin = gbox.xmin; + if (gbox.ymin < box->ymin) box->ymin = gbox.ymin; - if (gbox.xmax > box->xmax) box->xmax= gbox.xmax; - if (gbox.ymax > box->ymax) box->ymax= gbox.ymax; + if (gbox.xmax > box->xmax) box->xmax = gbox.xmax; + if (gbox.ymax > box->ymax) box->ymax = gbox.ymax; pen_x += g->advance; - g_prev= g; + g_prev = g; } if (box->xmin > box->xmax) { - box->xmin= 0.0f; - box->ymin= 0.0f; - box->xmax= 0.0f; - box->ymax= 0.0f; + box->xmin = 0.0f; + box->ymin = 0.0f; + box->xmax = 0.0f; + box->ymax = 0.0f; } } @@ -395,17 +405,17 @@ void blf_font_width_and_height(FontBLF *font, const char *str, float *width, flo rctf box; if (font->flags & BLF_ASPECT) { - xa= font->aspect[0]; - ya= font->aspect[1]; + xa = font->aspect[0]; + ya = font->aspect[1]; } else { - xa= 1.0f; - ya= 1.0f; + xa = 1.0f; + ya = 1.0f; } blf_font_boundbox(font, str, &box); - *width= ((box.xmax - box.xmin) * xa); - *height= ((box.ymax - box.ymin) * ya); + *width = ((box.xmax - box.xmin) * xa); + *height = ((box.ymax - box.ymin) * ya); } float blf_font_width(FontBLF *font, const char *str) @@ -414,9 +424,9 @@ float blf_font_width(FontBLF *font, const char *str) rctf box; if (font->flags & BLF_ASPECT) - xa= font->aspect[0]; + xa = font->aspect[0]; else - xa= 1.0f; + xa = 1.0f; blf_font_boundbox(font, str, &box); return (box.xmax - box.xmin) * xa; @@ -428,9 +438,9 @@ float blf_font_height(FontBLF *font, const char *str) rctf box; if (font->flags & BLF_ASPECT) - ya= font->aspect[1]; + ya = font->aspect[1]; else - ya= 1.0f; + ya = 1.0f; blf_font_boundbox(font, str, &box); return (box.ymax - box.ymin) * ya; @@ -439,9 +449,9 @@ float blf_font_height(FontBLF *font, const char *str) float blf_font_fixed_width(FontBLF *font) { const unsigned int c = ' '; - GlyphBLF *g= blf_glyph_search(font->glyph_cache, c); + GlyphBLF *g = blf_glyph_search(font->glyph_cache, c); if (!g) { - g= blf_glyph_add(font, FT_Get_Char_Index(font->face, c), c); + g = blf_glyph_add(font, FT_Get_Char_Index(font->face, c), c); /* if we don't find the glyph. */ if (!g) { @@ -456,9 +466,9 @@ void blf_font_free(FontBLF *font) { GlyphCacheBLF *gc; - font->glyph_cache= NULL; + font->glyph_cache = NULL; while (font->cache.first) { - gc= font->cache.first; + gc = font->cache.first; BLI_remlink(&font->cache, gc); blf_glyph_cache_free(gc); } @@ -475,38 +485,38 @@ static void blf_font_fill(FontBLF *font) { unsigned int i; - font->aspect[0]= 1.0f; - font->aspect[1]= 1.0f; - font->aspect[2]= 1.0f; - font->pos[0]= 0.0f; - font->pos[1]= 0.0f; - font->angle= 0.0f; + font->aspect[0] = 1.0f; + font->aspect[1] = 1.0f; + font->aspect[2] = 1.0f; + font->pos[0] = 0.0f; + font->pos[1] = 0.0f; + font->angle = 0.0f; - for (i= 0; i < 16; i++) - font->m[i]= 0; + for (i = 0; i < 16; i++) + font->m[i] = 0; - font->clip_rec.xmin= 0.0f; - font->clip_rec.xmax= 0.0f; - font->clip_rec.ymin= 0.0f; - font->clip_rec.ymax= 0.0f; - font->flags= 0; - font->dpi= 0; - font->size= 0; - font->cache.first= NULL; - font->cache.last= NULL; - font->glyph_cache= NULL; - font->blur= 0; - font->max_tex_size= -1; - font->b_fbuf= NULL; - font->b_cbuf= NULL; - font->bw= 0; - font->bh= 0; - font->bch= 0; - font->b_col[0]= 0; - font->b_col[1]= 0; - font->b_col[2]= 0; - font->b_col[3]= 0; - font->ft_lib= ft_lib; + font->clip_rec.xmin = 0.0f; + font->clip_rec.xmax = 0.0f; + font->clip_rec.ymin = 0.0f; + font->clip_rec.ymax = 0.0f; + font->flags = 0; + font->dpi = 0; + font->size = 0; + font->cache.first = NULL; + font->cache.last = NULL; + font->glyph_cache = NULL; + font->blur = 0; + font->max_tex_size = -1; + font->b_fbuf = NULL; + font->b_cbuf = NULL; + font->bw = 0; + font->bh = 0; + font->bch = 0; + font->b_col[0] = 0; + font->b_col[1] = 0; + font->b_col[2] = 0; + font->b_col[3] = 0; + font->ft_lib = ft_lib; } FontBLF *blf_font_new(const char *name, const char *filename) @@ -515,14 +525,14 @@ FontBLF *blf_font_new(const char *name, const char *filename) FT_Error err; char *mfile; - font= (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new"); - err= FT_New_Face(ft_lib, filename, 0, &font->face); + font = (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new"); + err = FT_New_Face(ft_lib, filename, 0, &font->face); if (err) { MEM_freeN(font); return NULL; } - err= FT_Select_Charmap(font->face, ft_encoding_unicode); + err = FT_Select_Charmap(font->face, ft_encoding_unicode); if (err) { printf("Can't set the unicode character map!\n"); FT_Done_Face(font->face); @@ -530,17 +540,17 @@ FontBLF *blf_font_new(const char *name, const char *filename) return NULL; } - mfile= blf_dir_metrics_search(filename); + mfile = blf_dir_metrics_search(filename); if (mfile) { - err= FT_Attach_File(font->face, mfile); - if(err) { + err = FT_Attach_File(font->face, mfile); + if (err) { fprintf(stderr, "FT_Attach_File failed to load '%s' with error %d\n", filename, (int)err); } MEM_freeN(mfile); } - font->name= BLI_strdup(name); - font->filename= BLI_strdup(filename); + font->name = BLI_strdup(name); + font->filename = BLI_strdup(filename); blf_font_fill(font); return font; } @@ -549,9 +559,9 @@ void blf_font_attach_from_mem(FontBLF *font, const unsigned char *mem, int mem_s { FT_Open_Args open; - open.flags= FT_OPEN_MEMORY; - open.memory_base= (FT_Byte *)mem; - open.memory_size= mem_size; + open.flags = FT_OPEN_MEMORY; + open.memory_base = (FT_Byte *)mem; + open.memory_size = mem_size; FT_Attach_Stream(font->face, &open); } @@ -560,14 +570,14 @@ FontBLF *blf_font_new_from_mem(const char *name, unsigned char *mem, int mem_siz FontBLF *font; FT_Error err; - font= (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new_from_mem"); - err= FT_New_Memory_Face(ft_lib, mem, mem_size, 0, &font->face); + font = (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new_from_mem"); + err = FT_New_Memory_Face(ft_lib, mem, mem_size, 0, &font->face); if (err) { MEM_freeN(font); return NULL; } - err= FT_Select_Charmap(font->face, ft_encoding_unicode); + err = FT_Select_Charmap(font->face, ft_encoding_unicode); if (err) { printf("Can't set the unicode character map!\n"); FT_Done_Face(font->face); @@ -575,8 +585,8 @@ FontBLF *blf_font_new_from_mem(const char *name, unsigned char *mem, int mem_siz return NULL; } - font->name= BLI_strdup(name); - font->filename= NULL; + font->name = BLI_strdup(name); + font->filename = NULL; blf_font_fill(font); return font; } diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index f0cfcdc97b9..e542e247755 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -59,11 +59,11 @@ GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi) { GlyphCacheBLF *p; - p= (GlyphCacheBLF *)font->cache.first; + p = (GlyphCacheBLF *)font->cache.first; while (p) { if (p->size == size && p->dpi == dpi) return p; - p= p->next; + p = p->next; } return NULL; } @@ -73,43 +73,43 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font) { GlyphCacheBLF *gc; - gc= (GlyphCacheBLF *)MEM_callocN(sizeof(GlyphCacheBLF), "blf_glyph_cache_new"); - gc->next= NULL; - gc->prev= NULL; - gc->size= font->size; - gc->dpi= font->dpi; + gc = (GlyphCacheBLF *)MEM_callocN(sizeof(GlyphCacheBLF), "blf_glyph_cache_new"); + gc->next = NULL; + gc->prev = NULL; + gc->size = font->size; + gc->dpi = font->dpi; memset(gc->glyph_ascii_table, 0, sizeof(gc->glyph_ascii_table)); memset(gc->bucket, 0, sizeof(gc->bucket)); - gc->textures= (GLuint *)malloc(sizeof(GLuint)*256); - gc->ntex= 256; - gc->cur_tex= -1; - gc->x_offs= 0; - gc->y_offs= 0; - gc->pad= 3; + gc->textures = (GLuint *)malloc(sizeof(GLuint)*256); + gc->ntex = 256; + gc->cur_tex = -1; + gc->x_offs = 0; + gc->y_offs = 0; + gc->pad = 3; - gc->num_glyphs= font->face->num_glyphs; - gc->rem_glyphs= font->face->num_glyphs; - gc->ascender= ((float)font->face->size->metrics.ascender) / 64.0f; - gc->descender= ((float)font->face->size->metrics.descender) / 64.0f; + gc->num_glyphs = font->face->num_glyphs; + gc->rem_glyphs = font->face->num_glyphs; + gc->ascender = ((float)font->face->size->metrics.ascender) / 64.0f; + gc->descender = ((float)font->face->size->metrics.descender) / 64.0f; if (FT_IS_SCALABLE(font->face)) { - gc->max_glyph_width= (float)((font->face->bbox.xMax - font->face->bbox.xMin) * - (((float)font->face->size->metrics.x_ppem) / - ((float)font->face->units_per_EM))); + gc->max_glyph_width = (float)((font->face->bbox.xMax - font->face->bbox.xMin) * + (((float)font->face->size->metrics.x_ppem) / + ((float)font->face->units_per_EM))); - gc->max_glyph_height= (float)((font->face->bbox.yMax - font->face->bbox.yMin) * - (((float)font->face->size->metrics.y_ppem) / - ((float)font->face->units_per_EM))); + gc->max_glyph_height = (float)((font->face->bbox.yMax - font->face->bbox.yMin) * + (((float)font->face->size->metrics.y_ppem) / + ((float)font->face->units_per_EM))); } else { - gc->max_glyph_width= ((float)font->face->size->metrics.max_advance) / 64.0f; - gc->max_glyph_height= ((float)font->face->size->metrics.height) / 64.0f; + gc->max_glyph_width = ((float)font->face->size->metrics.max_advance) / 64.0f; + gc->max_glyph_height = ((float)font->face->size->metrics.height) / 64.0f; } - gc->p2_width= 0; - gc->p2_height= 0; + gc->p2_width = 0; + gc->p2_height = 0; BLI_addhead(&font->cache, gc); return gc; @@ -121,10 +121,10 @@ void blf_glyph_cache_clear(FontBLF *font) GlyphBLF *g; int i; - for(gc=font->cache.first; gc; gc=gc->next) { - for (i= 0; i < 257; i++) { + for (gc = font->cache.first; gc; gc = gc->next) { + for (i = 0; i < 257; i++) { while (gc->bucket[i].first) { - g= gc->bucket[i].first; + g = gc->bucket[i].first; BLI_remlink(&(gc->bucket[i]), g); blf_glyph_free(g); } @@ -139,9 +139,9 @@ void blf_glyph_cache_free(GlyphCacheBLF *gc) GlyphBLF *g; int i; - for (i= 0; i < 257; i++) { + for (i = 0; i < 257; i++) { while (gc->bucket[i].first) { - g= gc->bucket[i].first; + g = gc->bucket[i].first; BLI_remlink(&(gc->bucket[i]), g); blf_glyph_free(g); } @@ -163,25 +163,25 @@ static void blf_glyph_cache_texture(FontBLF *font, GlyphCacheBLF *gc) if (gc->cur_tex >= gc->ntex) { gc->ntex *= 2; - gc->textures= (GLuint *)realloc((void *)gc->textures, sizeof(GLuint)*gc->ntex); + gc->textures = (GLuint *)realloc((void *)gc->textures, sizeof(GLuint)*gc->ntex); } - gc->p2_width= blf_next_p2((gc->rem_glyphs * gc->max_glyph_width) + (gc->pad * 2)); + gc->p2_width = blf_next_p2((gc->rem_glyphs * gc->max_glyph_width) + (gc->pad * 2)); if (gc->p2_width > font->max_tex_size) - gc->p2_width= font->max_tex_size; + gc->p2_width = font->max_tex_size; - i= (int)((gc->p2_width - (gc->pad * 2)) / gc->max_glyph_width); - gc->p2_height= blf_next_p2(((gc->num_glyphs / i) + 1) * gc->max_glyph_height); + i = (int)((gc->p2_width - (gc->pad * 2)) / gc->max_glyph_width); + gc->p2_height = blf_next_p2(((gc->num_glyphs / i) + 1) * gc->max_glyph_height); if (gc->p2_height > font->max_tex_size) - gc->p2_height= font->max_tex_size; + gc->p2_height = font->max_tex_size; - tot_mem= gc->p2_width * gc->p2_height; - buf= (unsigned char *)malloc(tot_mem); + tot_mem = gc->p2_width * gc->p2_height; + buf = (unsigned char *)malloc(tot_mem); memset((void *)buf, 0, tot_mem); glGenTextures(1, &gc->textures[gc->cur_tex]); - glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state= gc->textures[gc->cur_tex])); + glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = gc->textures[gc->cur_tex])); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -196,12 +196,12 @@ GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c) GlyphBLF *p; unsigned int key; - key= blf_hash(c); - p= gc->bucket[key].first; + key = blf_hash(c); + p = gc->bucket[key].first; while (p) { if (p->c == c) return p; - p= p->next; + p = p->next; } return NULL; } @@ -216,7 +216,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c) FT_BBox bbox; unsigned int key; - g= blf_glyph_search(font->glyph_cache, c); + g = blf_glyph_search(font->glyph_cache, c); if (g) return g; @@ -228,7 +228,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c) return NULL; /* get the glyph. */ - slot= font->face->glyph; + slot = font->face->glyph; if (sharp) { err = FT_Render_Glyph(slot, FT_RENDER_MODE_MONO); @@ -246,40 +246,40 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c) if (err || slot->format != FT_GLYPH_FORMAT_BITMAP) return NULL; - g= (GlyphBLF *)MEM_callocN(sizeof(GlyphBLF), "blf_glyph_add"); - g->c= c; - g->idx= (FT_UInt)index; - g->xoff= -1; - g->yoff= -1; - bitmap= slot->bitmap; - g->width= bitmap.width; - g->height= bitmap.rows; + g = (GlyphBLF *)MEM_callocN(sizeof(GlyphBLF), "blf_glyph_add"); + g->c = c; + g->idx = (FT_UInt)index; + g->xoff = -1; + g->yoff = -1; + bitmap = slot->bitmap; + g->width = bitmap.width; + g->height = bitmap.rows; if (g->width && g->height) { if (sharp) { /* Font buffer uses only 0 or 1 values, Blender expects full 0..255 range */ int i; - for (i=0; i < (g->width * g->height); i++) { + for (i = 0; i < (g->width * g->height); i++) { bitmap.buffer[i] = 255 * bitmap.buffer[i]; } } - g->bitmap= (unsigned char *)MEM_mallocN(g->width * g->height, "glyph bitmap"); + g->bitmap = (unsigned char *)MEM_mallocN(g->width * g->height, "glyph bitmap"); memcpy((void *)g->bitmap, (void *)bitmap.buffer, g->width * g->height); } - g->advance= ((float)slot->advance.x) / 64.0f; - g->pos_x= slot->bitmap_left; - g->pos_y= slot->bitmap_top; - g->pitch= slot->bitmap.pitch; + g->advance = ((float)slot->advance.x) / 64.0f; + g->pos_x = slot->bitmap_left; + g->pos_y = slot->bitmap_top; + g->pitch = slot->bitmap.pitch; FT_Outline_Get_CBox(&(slot->outline), &bbox); - g->box.xmin= ((float)bbox.xMin) / 64.0f; - g->box.xmax= ((float)bbox.xMax) / 64.0f; - g->box.ymin= ((float)bbox.yMin) / 64.0f; - g->box.ymax= ((float)bbox.yMax) / 64.0f; + g->box.xmin = ((float)bbox.xMin) / 64.0f; + g->box.xmax = ((float)bbox.xMax) / 64.0f; + g->box.ymin = ((float)bbox.yMin) / 64.0f; + g->box.ymax = ((float)bbox.yMax) / 64.0f; - key= blf_hash(g->c); + key = blf_hash(g->c); BLI_addhead(&(font->glyph_cache->bucket[key]), g); return g; } @@ -296,7 +296,6 @@ void blf_glyph_free(GlyphBLF *g) static void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, float y2) { - glBegin(GL_QUADS); glTexCoord2f(uv[0][0], uv[0][1]); glVertex2f(dx, y1); @@ -310,27 +309,26 @@ static void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, floa glTexCoord2f(uv[1][0], uv[0][1]); glVertex2f(dx1, y1); glEnd(); - } static void blf_texture5_draw(const float shadow_col[4], float uv[2][2], float x1, float y1, float x2, float y2) { - float soft[25]= {1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f, - 1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, - 2/60.0f, 5/60.0f, 8/60.0f, 5/60.0f, 2/60.0f, - 1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, - 1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f}; + float soft[25] = {1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f, + 1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, + 2/60.0f, 5/60.0f, 8/60.0f, 5/60.0f, 2/60.0f, + 1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, + 1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f}; - float color[4], *fp= soft; + float color[4], *fp = soft; int dx, dy; - color[0]= shadow_col[0]; - color[1]= shadow_col[1]; - color[2]= shadow_col[2]; + color[0] = shadow_col[0]; + color[1] = shadow_col[1]; + color[2] = shadow_col[2]; - for(dx=-2; dx<3; dx++) { - for(dy=-2; dy<3; dy++, fp++) { - color[3]= *(fp) * shadow_col[3]; + for (dx = -2; dx < 3; dx++) { + for (dy = -2; dy < 3; dy++, fp++) { + color[3] = *(fp) * shadow_col[3]; glColor4fv(color); blf_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy); } @@ -341,20 +339,20 @@ static void blf_texture5_draw(const float shadow_col[4], float uv[2][2], float x static void blf_texture3_draw(const float shadow_col[4], float uv[2][2], float x1, float y1, float x2, float y2) { - float soft[9]= {1/16.0f, 2/16.0f, 1/16.0f, - 2/16.0f,4/16.0f, 2/16.0f, - 1/16.0f, 2/16.0f, 1/16.0f}; + float soft[9] = {1/16.0f, 2/16.0f, 1/16.0f, + 2/16.0f,4/16.0f, 2/16.0f, + 1/16.0f, 2/16.0f, 1/16.0f}; - float color[4], *fp= soft; + float color[4], *fp = soft; int dx, dy; - color[0]= shadow_col[0]; - color[1]= shadow_col[1]; - color[2]= shadow_col[2]; + color[0] = shadow_col[0]; + color[1] = shadow_col[1]; + color[2] = shadow_col[2]; - for(dx=-1; dx<2; dx++) { - for(dy=-1; dy<2; dy++, fp++) { - color[3]= *(fp) * shadow_col[3]; + for (dx = -1; dx < 2; dx++) { + for (dy = -1; dy < 2; dy++, fp++) { + color[3] = *(fp) * shadow_col[3]; glColor4fv(color); blf_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy); } @@ -373,30 +371,30 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y) return 1; if (g->build_tex == 0) { - GlyphCacheBLF *gc= font->glyph_cache; + GlyphCacheBLF *gc = font->glyph_cache; if (font->max_tex_size == -1) glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&font->max_tex_size); if (gc->cur_tex == -1) { blf_glyph_cache_texture(font, gc); - gc->x_offs= gc->pad; - gc->y_offs= gc->pad; + gc->x_offs = gc->pad; + gc->y_offs = gc->pad; } if (gc->x_offs > (gc->p2_width - gc->max_glyph_width)) { - gc->x_offs= gc->pad; + gc->x_offs = gc->pad; gc->y_offs += gc->max_glyph_height; if (gc->y_offs > (gc->p2_height - gc->max_glyph_height)) { - gc->y_offs= gc->pad; + gc->y_offs = gc->pad; blf_glyph_cache_texture(font, gc); } } - g->tex= gc->textures[gc->cur_tex]; - g->xoff= gc->x_offs; - g->yoff= gc->y_offs; + g->tex = gc->textures[gc->cur_tex]; + g->xoff = gc->x_offs; + g->yoff = gc->y_offs; glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); @@ -407,32 +405,32 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y) glTexSubImage2D(GL_TEXTURE_2D, 0, g->xoff, g->yoff, g->width, g->height, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap); glPopClientAttrib(); - g->uv[0][0]= ((float)g->xoff) / ((float)gc->p2_width); - g->uv[0][1]= ((float)g->yoff) / ((float)gc->p2_height); - g->uv[1][0]= ((float)(g->xoff + g->width)) / ((float)gc->p2_width); - g->uv[1][1]= ((float)(g->yoff + g->height)) / ((float)gc->p2_height); + g->uv[0][0] = ((float)g->xoff) / ((float)gc->p2_width); + g->uv[0][1] = ((float)g->yoff) / ((float)gc->p2_height); + g->uv[1][0] = ((float)(g->xoff + g->width)) / ((float)gc->p2_width); + g->uv[1][1] = ((float)(g->yoff + g->height)) / ((float)gc->p2_height); /* update the x offset for the next glyph. */ gc->x_offs += (int)(g->box.xmax - g->box.xmin + gc->pad); gc->rem_glyphs--; - g->build_tex= 1; + g->build_tex = 1; } - xo= 0.0f; - yo= 0.0f; + xo = 0.0f; + yo = 0.0f; if (font->flags & BLF_SHADOW) { - xo= x; - yo= y; + xo = x; + yo = y; x += font->shadow_x; y += font->shadow_y; } - dx= floor(x + g->pos_x); - dx1= dx + g->width; - y1= y + g->pos_y; - y2= y + g->pos_y - g->height; + dx = floor(x + g->pos_x); + dx1 = dx + g->width; + y1 = y + g->pos_y; + y2 = y + g->pos_y - g->height; if (font->flags & BLF_CLIPPING) { if (!BLI_in_rctf(&font->clip_rec, dx + font->pos[0], y1 + font->pos[1])) @@ -446,12 +444,12 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y) } if (font->tex_bind_state != g->tex) { - glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state= g->tex)); + glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = g->tex)); } if (font->flags & BLF_SHADOW) { - switch(font->shadow) { + switch (font->shadow) { case 3: blf_texture3_draw(font->shadow_col, g->uv, dx, y1, dx1, y2); break; @@ -466,16 +464,16 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y) glColor4fv(font->orig_col); - x= xo; - y= yo; + x = xo; + y = yo; - dx= floor(x + g->pos_x); - dx1= dx + g->width; - y1= y + g->pos_y; - y2= y + g->pos_y - g->height; + dx = floor(x + g->pos_x); + dx1 = dx + g->width; + y1 = y + g->pos_y; + y2 = y + g->pos_y - g->height; } - switch(font->blur) { + switch (font->blur) { case 3: blf_texture3_draw(font->orig_col, g->uv, dx, y1, dx1, y2); break; diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index 3ef0b3422fe..f43fa8a7458 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -41,7 +41,7 @@ unsigned int blf_hash(unsigned int val); char *blf_dir_search(const char *file); char *blf_dir_metrics_search(const char *filename); -// int blf_dir_split(const char *str, char *file, int *size); // UNUSED +/* int blf_dir_split(const char *str, char *file, int *size); *//* UNUSED */ int blf_font_init(void); void blf_font_exit(void); diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index 95203c2b1c0..0c68bca20bd 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -55,7 +55,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_linklist.h" /* linknode */ +#include "BLI_linklist.h" /* linknode */ #include "BLI_string.h" #include "BLI_utildefines.h" #include "BLI_path_util.h" @@ -109,7 +109,7 @@ static const char *locales[] = { void BLF_lang_init(void) { - char *messagepath= BLI_get_folder(BLENDER_DATAFILES, "locale"); + char *messagepath = BLI_get_folder(BLENDER_DATAFILES, "locale"); BLI_strncpy(global_encoding_name, SYSTEM_ENCODING_DEFAULT, sizeof(global_encoding_name)); @@ -118,7 +118,7 @@ void BLF_lang_init(void) } else { printf("%s: 'locale' data path for translations not found, continuing\n", __func__); - global_messagepath[0]= '\0'; + global_messagepath[0] = '\0'; } } @@ -126,18 +126,18 @@ void BLF_lang_init(void) /* get LANG/LANGUAGE environment variable */ static void get_language_variable(const char *varname, char *var, int maxlen) { - char *env= getenv(varname); + char *env = getenv(varname); - if(env) { + if (env) { char *s; /* store defaul locale */ BLI_strncpy(var, env, maxlen); /* use first language as default */ - s= strchr(var, ':'); - if(s) - s[0]= 0; + s = strchr(var, ':'); + if (s) + s[0] = 0; } } @@ -146,7 +146,7 @@ static void get_language_variable(const char *varname, char *var, int maxlen) */ static void get_language(const char *locale, const char *lang, char *language, int maxlen) { - if(locale[0]) { + if (locale[0]) { BLI_strncpy(language, locale, maxlen); } else { @@ -154,9 +154,9 @@ static void get_language(const char *locale, const char *lang, char *language, i BLI_strncpy(language, lang, maxlen); - s= strchr(language, '.'); - if(s) - s[0]= 0; + s = strchr(language, '.'); + if (s) + s[0] = 0; } } @@ -165,22 +165,22 @@ void BLF_lang_set(const char *str) { char *locreturn; const char *short_locale; - int ok= 1; + int ok = 1; const char *long_locale = locales[2 * U.language]; - if((U.transopts&USER_DOTRANSLATE)==0) + if ((U.transopts&USER_DOTRANSLATE) == 0) return; - if(str) + if (str) short_locale = str; else short_locale = locales[ 2 * U.language + 1]; #if defined (_WIN32) && !defined(FREE_WINDOWS) - if(short_locale) { + if (short_locale) { char *envStr; - if( U.language==0 )/* use system setting */ + if (U.language == 0)/* use system setting */ envStr = BLI_sprintfN( "LANG=%s", getenv("LANG") ); else envStr = BLI_sprintfN( "LANG=%s", short_locale ); @@ -189,48 +189,48 @@ void BLF_lang_set(const char *str) MEM_freeN(envStr); } - locreturn= setlocale(LC_ALL, long_locale); + locreturn = setlocale(LC_ALL, long_locale); if (locreturn == NULL) { - if(G.f & G_DEBUG) + if (G.f & G_DEBUG) printf("Could not change locale to %s\n", long_locale); - ok= 0; + ok = 0; } #else { - static char default_lang[64]="\0"; - static char default_language[64]="\0"; + static char default_lang[64] ="\0"; + static char default_language[64] ="\0"; - if(default_lang[0]==0) + if (default_lang[0] == 0) get_language_variable("LANG", default_lang, sizeof(default_lang)); - if(default_language[0]==0) + if (default_language[0] == 0) get_language_variable("LANGUAGE", default_language, sizeof(default_language)); - if(short_locale[0]) { - if(G.f & G_DEBUG) + if (short_locale[0]) { + if (G.f & G_DEBUG) printf("Setting LANG= and LANGUAGE to %s\n", short_locale); BLI_setenv("LANG", short_locale); BLI_setenv("LANGUAGE", short_locale); } else { - if(G.f & G_DEBUG) + if (G.f & G_DEBUG) printf("Setting LANG=%s and LANGUAGE=%s\n", default_lang, default_language); BLI_setenv("LANG", default_lang); BLI_setenv("LANGUAGE", default_language); } - locreturn= setlocale(LC_ALL, short_locale); + locreturn = setlocale(LC_ALL, short_locale); - if(locreturn == NULL) { - char *short_locale_utf8= NULL; + if (locreturn == NULL) { + char *short_locale_utf8 = NULL; - if(short_locale[0]) { - short_locale_utf8= BLI_sprintfN("%s.UTF-8", short_locale); - locreturn= setlocale(LC_ALL, short_locale_utf8); + if (short_locale[0]) { + short_locale_utf8 = BLI_sprintfN("%s.UTF-8", short_locale); + locreturn = setlocale(LC_ALL, short_locale_utf8); } if (locreturn == NULL) { @@ -238,8 +238,8 @@ void BLF_lang_set(const char *str) get_language(long_locale, default_lang, language, sizeof(language)); - if(G.f & G_DEBUG) { - if(short_locale[0]) + if (G.f & G_DEBUG) { + if (short_locale[0]) printf("Could not change locale to %s nor %s\n", short_locale, short_locale_utf8); else printf("Could not reset locale\n"); @@ -251,19 +251,19 @@ void BLF_lang_set(const char *str) BLI_setenv("LANG", default_lang); BLI_setenv("LANGUAGE", language); - locreturn= setlocale(LC_ALL, ""); + locreturn = setlocale(LC_ALL, ""); - ok= 0; + ok = 0; } - if(short_locale_utf8) + if (short_locale_utf8) MEM_freeN(short_locale_utf8); } } #endif - if(ok) { - //printf("Change locale to %s\n", locreturn ); + if (ok) { + /*printf("Change locale to %s\n", locreturn ); */ BLI_strncpy(global_language, locreturn, sizeof(global_language)); } diff --git a/source/blender/blenfont/intern/blf_translation.c b/source/blender/blenfont/intern/blf_translation.c index 201722acdbf..457545eeb17 100644 --- a/source/blender/blenfont/intern/blf_translation.c +++ b/source/blender/blenfont/intern/blf_translation.c @@ -57,34 +57,34 @@ #include "DNA_userdef_types.h" /* For user settings. */ #ifdef WITH_INTERNATIONAL -static const char unifont_filename[]="droidsans.ttf.gz"; -static unsigned char *unifont_ttf= NULL; -static int unifont_size= 0; +static const char unifont_filename[] ="droidsans.ttf.gz"; +static unsigned char *unifont_ttf = NULL; +static int unifont_size = 0; unsigned char *BLF_get_unifont(int *unifont_size_r) { - if(unifont_ttf==NULL) { + if (unifont_ttf == NULL) { char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts"); if (fontpath) { char unifont_path[1024]; BLI_snprintf(unifont_path, sizeof(unifont_path), "%s/%s", fontpath, unifont_filename); - unifont_ttf= (unsigned char*)BLI_file_ungzip_to_mem(unifont_path, &unifont_size); + unifont_ttf = (unsigned char*)BLI_file_ungzip_to_mem(unifont_path, &unifont_size); } else { printf("%s: 'fonts' data path not found for international font, continuing\n", __func__); } } - *unifont_size_r= unifont_size; + *unifont_size_r = unifont_size; return unifont_ttf; } void BLF_free_unifont(void) { - if(unifont_ttf) + if (unifont_ttf) MEM_freeN(unifont_ttf); } @@ -93,7 +93,7 @@ void BLF_free_unifont(void) const char* BLF_gettext(const char *msgid) { #ifdef WITH_INTERNATIONAL - if( msgid[0] ) + if (msgid[0]) return gettext(msgid); return ""; #else @@ -157,7 +157,7 @@ int BLF_translate_tooltips(void) const char *BLF_translate_do_iface(const char *msgid) { #ifdef WITH_INTERNATIONAL - if(BLF_translate_iface()) + if (BLF_translate_iface()) return BLF_gettext(msgid); else return msgid; @@ -169,7 +169,7 @@ const char *BLF_translate_do_iface(const char *msgid) const char *BLF_translate_do_tooltip(const char *msgid) { #ifdef WITH_INTERNATIONAL - if(BLF_translate_tooltips()) + if (BLF_translate_tooltips()) return BLF_gettext(msgid); else return msgid; diff --git a/source/blender/blenfont/intern/blf_util.c b/source/blender/blenfont/intern/blf_util.c index 45e01e58312..8240906dd3b 100644 --- a/source/blender/blenfont/intern/blf_util.c +++ b/source/blender/blenfont/intern/blf_util.c @@ -53,7 +53,7 @@ unsigned int blf_hash(unsigned int val) { unsigned int key; - key= val; + key = val; key += ~(key << 16); key ^= (key >> 5); key += (key << 3); From ca5fd21bb5c43d605c8fef270e397184ec73d480 Mon Sep 17 00:00:00 2001 From: Howard Trickey Date: Mon, 12 Mar 2012 11:27:59 +0000 Subject: [PATCH 030/310] Make knifetool more robust against crashes. Fix some hole problems. Sometimes split would fail to make a face - make sure it doesn't crash if that happens. Chain finding code for holes would sometimes go back to same vertex on the face, which causes problems, so fixe that. Also, disallowed a cut that starts at a vertex or edge and cycles back to that same point in a face - this would make a face with a repeated vertex, which may not be handled by the rest of the system properly. --- source/blender/editors/mesh/knifetool.c | 65 ++++++++++++++++++------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/source/blender/editors/mesh/knifetool.c b/source/blender/editors/mesh/knifetool.c index e1380e6f1e1..0231fa4ade3 100644 --- a/source/blender/editors/mesh/knifetool.c +++ b/source/blender/editors/mesh/knifetool.c @@ -2099,6 +2099,8 @@ static int find_hole_search(knifetool_opdata *kcd, KnifeVert *kfvfirst, KnifeVer kfe = r->ref; if (kfe == kfelast) continue; + if (kfe->v1->v || kfe->v2->v) + continue; kfv_other = NULL; if (kfe->v1 == kfv) kfv_other = kfe->v2; @@ -2165,7 +2167,7 @@ static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, KnifeVert **hv; KnifeEdge **he; Ref *r; - KnifeVert *kfv; + KnifeVert *kfv, *kfvother; KnifeEdge *kfe; ListBase *chain; BMVert *v; @@ -2190,14 +2192,21 @@ static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, i = 0; kfv = NULL; + kfvother = NULL; for (r = hole->first; r; r = r->next) { kfe = r->ref; he[i] = kfe; - kfv = (kfv == kfe->v1)? kfe->v2 : kfe->v1; + if (kfvother == NULL) { + kfv = kfe->v1; + } else { + kfv = kfvother; + BLI_assert(kfv == kfe->v1 || kfv == kfe->v2); + } hco[i] = BLI_memarena_alloc(kcd->arena, 2*sizeof(float)); hco[i][0] = kfv->co[ax]; hco[i][1] = kfv->co[ay]; hv[i] = kfv; + kfvother = (kfe->v1 == kfv) ? kfe->v2 : kfe->v1; i++; } @@ -2213,7 +2222,7 @@ static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, /* For first diagonal (m==0), want shortest length. * For second diagonal (m==1), want max separation of index of hole * vertex from the hole vertex used in the first diagonal, and from there - * want the one with shortest length. */ + * want the one with shortest length not to the same vertex as the first diagonal. */ for (m = 0; m < 2; m++) { besti[m] = -1; bestj[m] = -1; @@ -2230,6 +2239,8 @@ static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, bestd = FLT_MAX; } for (j = 0; j < nf; j++) { + if (m == 1 && j == bestj[0]) + continue; d = len_squared_v2v2(hco[i], fco[j]); if (d > bestd) continue; @@ -2261,6 +2272,7 @@ static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, } if (besti[0] != -1 && besti[1] != -1) { + BLI_assert(besti[0] != besti[1] && bestj[0] != bestj[1]); kfe = new_knife_edge(kcd); kfe->v1 = get_bm_knife_vert(kcd, fv[bestj[0]]); kfe->v2 = hv[besti[0]]; @@ -2291,10 +2303,14 @@ static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, static int knife_edge_in_face(knifetool_opdata *kcd, KnifeEdge *kfe, BMFace *f) { BMesh *bm = kcd->em->bm; BMVert *v1, *v2; - BMLoop *l1, *l2, *l, *loops[2]; + BMLoop *l1, *l2, *l; + float mid[3]; BMIter iter; int v1inside, v2inside; + if (!f) + return FALSE; + v1 = kfe->v1->v; v2 = kfe->v2->v; l1 = NULL; @@ -2315,11 +2331,11 @@ static int knife_edge_in_face(knifetool_opdata *kcd, KnifeEdge *kfe, BMFace *f) return TRUE; if (l1 && l2) { /* Can have case where v1 and v2 are on shared chain between two faces. - * BM_face_legal_splits does visibility and self-intersection tests. */ - loops[0] = l1; - loops[1] = l2; - BM_face_legal_splits(bm, f, (BMLoop *(*)[2])loops, 1); - return (loops[0] != NULL); + * BM_face_legal_splits does visibility and self-intersection tests, + * but it is expensive and maybe a bit buggy, so use a simple + * "is the midpoint in the face" test */ + mid_v3_v3v3(mid, kfe->v1->co, kfe->v2->co); + return BM_face_point_inside_test(bm, f, mid); } return FALSE; } @@ -2356,13 +2372,20 @@ static void knife_make_chain_cut(knifetool_opdata *kcd, BMFace *f, ListBase *cha kfvprev = kfv; } BLI_assert(i == nco); - fnew = BM_face_split_n(bm, f, v1, v2, cos, nco, &lnew, NULL); - *newface = fnew; + lnew = NULL; + if (nco == 0) { + *newface = BM_face_split(bm, f, v1, v2, &lnew, NULL, TRUE); + } else { + fnew = BM_face_split_n(bm, f, v1, v2, cos, nco, &lnew, NULL); + *newface = fnew; - /* Now go through lnew chain matching up chain kv's and assign real v's to them */ - for (l_iter = lnew->next, i = 0; i < nco; l_iter = l_iter->next, i++) { - BLI_assert(equals_v3v3(cos[i], l_iter->v->co)); - kverts[i]->v = l_iter->v; + if (fnew) { + /* Now go through lnew chain matching up chain kv's and assign real v's to them */ + for (l_iter = lnew->next, i = 0; i < nco; l_iter = l_iter->next, i++) { + BLI_assert(equals_v3v3(cos[i], l_iter->v->co)); + kverts[i]->v = l_iter->v; + } + } } BLI_array_fixedstack_free(cos); @@ -2381,6 +2404,10 @@ static void knife_make_face_cuts(knifetool_opdata *kcd, BMFace *f, ListBase *kfe oldcount = BLI_countlist(kfedges); while ((chain = find_chain(kcd, kfedges)) != NULL) { knife_make_chain_cut(kcd, f, chain, &fnew); + if (!fnew) { + BLI_assert("!knife failed chain cut"); + return; + } /* Move kfedges to fnew_kfedges if they are now in fnew. * The chain edges were removed already */ @@ -2413,6 +2440,10 @@ static void knife_make_face_cuts(knifetool_opdata *kcd, BMFace *f, ListBase *kfe * from the second last vertex to the second vertex. */ knife_make_chain_cut(kcd, f, chain, &fnew); + if (!fnew) { + BLI_assert(!"knife failed hole cut"); + return; + } kfe = ((Ref *)sidechain->first)->ref; if (knife_edge_in_face(kcd, kfe, f)) { knife_make_chain_cut(kcd, f, sidechain, &fnew2); @@ -2423,8 +2454,8 @@ static void knife_make_face_cuts(knifetool_opdata *kcd, BMFace *f, ListBase *kfe fhole = fnew2; } else { - /* shouldn't happen */ - BLI_assert(0); + /* shouldn't happen except in funny edge cases */ + return; } BM_face_kill(bm, fhole); /* Move kfedges to either fnew or fnew2 if appropriate. From b53cbb4e011f7912f7ef5dcada86e77d55b76766 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 12 Mar 2012 11:32:23 +0000 Subject: [PATCH 031/310] Fix #30512: external render saved render result after reporting error. --- source/blender/blenkernel/BKE_report.h | 2 ++ source/blender/blenkernel/intern/report.c | 17 ++++++++++++++--- .../render/intern/source/external_engine.c | 4 ++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/BKE_report.h b/source/blender/blenkernel/BKE_report.h index fd372ae6d83..f6307806491 100644 --- a/source/blender/blenkernel/BKE_report.h +++ b/source/blender/blenkernel/BKE_report.h @@ -66,6 +66,8 @@ char *BKE_reports_string(ReportList *reports, ReportType level); void BKE_reports_print(ReportList *reports, ReportType level); Report *BKE_reports_last_displayable(ReportList *reports); + +int BKE_reports_contain(ReportList *reports, ReportType level); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c index ffa9e027108..04bb45df282 100644 --- a/source/blender/blenkernel/intern/report.c +++ b/source/blender/blenkernel/intern/report.c @@ -37,7 +37,6 @@ #include "BKE_report.h" #include "BKE_global.h" /* G.background only */ - #include #include #include @@ -264,12 +263,24 @@ void BKE_reports_print(ReportList *reports, ReportType level) Report *BKE_reports_last_displayable(ReportList *reports) { - Report *report=NULL; + Report *report; - for (report= (Report *)reports->list.last; report; report=report->prev) { + for (report= reports->list.last; report; report=report->prev) { if (ELEM3(report->type, RPT_ERROR, RPT_WARNING, RPT_INFO)) return report; } return NULL; } + +int BKE_reports_contain(ReportList *reports, ReportType level) +{ + Report *report; + + for(report=reports->list.first; report; report=report->next) + if(report->type >= level) + return TRUE; + + return FALSE; +} + diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index 335de2dd055..3aa69171aa5 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -42,6 +42,7 @@ #include "BLI_string.h" #include "BLI_utildefines.h" +#include "BKE_global.h" #include "BKE_report.h" #include "BKE_scene.h" @@ -323,6 +324,9 @@ int RE_engine_render(Render *re, int do_all) RE_engine_free(engine); + if(BKE_reports_contain(re->reports, RPT_ERROR)) + G.afbreek = 1; + return 1; } From cd2d2f2f4e6121ba862bf033f79d0bd000c3acea Mon Sep 17 00:00:00 2001 From: Jens Verwiebe Date: Mon, 12 Mar 2012 12:03:52 +0000 Subject: [PATCH 032/310] OSX/cmake: use again 10.5 as general deployment target ( pls verify 10.5 compatibility works with automatic weaklinking), use now then sdk which for sure exists, remove obsolete slash --- CMakeLists.txt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 384a39c107f..8a13851b8d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -262,10 +262,8 @@ if(APPLE) endif() message(STATUS "Detected system-version: " ${OSX_SYSTEM}) - if(${OSX_SYSTEM} GREATER 10.6) - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.6" CACHE STRING "" FORCE) # 10.7 does not have 10.5sdk !!! - else() - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5" CACHE STRING "" FORCE) # 10.5 is our minimum target + if(NOT CMAKE_OSX_DEPLOYMENT_TARGET) + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5" CACHE STRING "" FORCE) # 10.5 is our minimum target, if you have higher sdk, weak linking happens endif() if(${CMAKE_GENERATOR} MATCHES "Xcode") @@ -1097,12 +1095,12 @@ elseif(APPLE) endif() if(${XCODE_VERSION} LESS 4.3) - SET(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${CMAKE_OSX_DEPLOYMENT_TARGET}.sdk CACHE PATH "" FORCE ) + SET(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE ) # use guaranteed existing sdk else() # note: i don't use xcode-select path on purpose, cause also /Applications/Xcode.app would be allowed # absolute pathes are more foolproof here ! SET(OSX_SYSROOT_PREFIX /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform) - SET(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${CMAKE_OSX_DEPLOYMENT_TARGET}.sdk) + SET(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk SET(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE) endif() From 50af47a67fe9df08598d874d56b1f62b9d386584 Mon Sep 17 00:00:00 2001 From: Howard Trickey Date: Mon, 12 Mar 2012 12:45:55 +0000 Subject: [PATCH 033/310] Code cleanup: knife gathers pos-related state into a struct. No functional change. This is in preparation for bug fixing and cleanup related to tracking of bmface and is_space state variables. And makes it more likely to avoid bugs in future where some part of state is copied but not all. --- source/blender/editors/mesh/knifetool.c | 308 ++++++++++++------------ 1 file changed, 151 insertions(+), 157 deletions(-) diff --git a/source/blender/editors/mesh/knifetool.c b/source/blender/editors/mesh/knifetool.c index 0231fa4ade3..d6eb14fb6e2 100644 --- a/source/blender/editors/mesh/knifetool.c +++ b/source/blender/editors/mesh/knifetool.c @@ -19,7 +19,7 @@ * All rights reserved. * * - * Contributor(s): Joseph Eagar, Joshua Leung + * Contributor(s): Joseph Eagar, Joshua Leung, Howard Trickey * * ***** END GPL LICENSE BLOCK ***** */ @@ -62,7 +62,6 @@ /* this code here is kindof messy. . .I might need to eventually rework it - joeedh */ -#define MAXGROUP 30 #define KMAXDIST 10 /* max mouse distance from edge before not detecting it */ /* knifetool operator */ @@ -99,6 +98,21 @@ typedef struct BMEdgeHit { BMFace *f; } BMEdgeHit; +typedef struct KnifePosData { + float co[3]; + float cage[3]; + + /* At most one of vert, edge, or bmface should be non-NULL, + * saying whether the point is snapped to a vertex, edge, or in a face. + * If none are set, this point is in space and is_space should be true. */ + KnifeVert *vert; + KnifeEdge *edge; + BMFace *bmface; + int is_space; + + int mval[2]; /* mouse screen position */ +} KnifePosData; + /* struct for properties used while drawing */ typedef struct knifetool_opdata { ARegion *ar; /* region that knifetool was activated in */ @@ -124,21 +138,14 @@ typedef struct knifetool_opdata { float vthresh; float ethresh; - float vertco[3], vertcage[3]; - float prevco[3], prevcage[3]; - /* used for drag-cutting */ BMEdgeHit *linehits; int totlinehit; - /* if curedge is NULL, attach to curvert; - * if curvert is NULL, attach to curbmface, - * otherwise create null vert */ - KnifeEdge *curedge, *prevedge; - KnifeVert *curvert, *prevvert; - BMFace *curbmface, *prevbmface; + /* Data for mouse-position-derived data (cur) and previous click (prev) */ + KnifePosData cur, prev; - int totkedge, totkvert, cutnr; + int totkedge, totkvert; BLI_mempool *refs; @@ -156,7 +163,6 @@ typedef struct knifetool_opdata { int snap_midpoints, prevmode, extend; int ignore_edge_snapping, ignore_vert_snapping; - int prevmval[2]; enum { ANGLE_FREE, @@ -166,7 +172,6 @@ typedef struct knifetool_opdata { ANGLE_135 } angle_snapping; - int is_space, prev_is_space; /*1 if current cut location, vertco, isn't on the mesh */ float (*cagecos)[3]; } knifetool_opdata; @@ -180,6 +185,16 @@ static void knife_project_v3(knifetool_opdata *kcd, const float co[3], float sco ED_view3d_project_float_v3(kcd->ar, co, sco, kcd->projmat); } +static void knife_pos_data_clear(KnifePosData *kpd) { + zero_v3(kpd->co); + zero_v3(kpd->cage); + kpd->vert = NULL; + kpd->edge = NULL; + kpd->bmface = NULL; + kpd->mval[0] = 0; + kpd->mval[1] = 0; +} + static ListBase *knife_empty_list(knifetool_opdata *kcd) { ListBase *lst; @@ -280,33 +295,26 @@ static KnifeEdge *get_bm_knife_edge(knifetool_opdata *kcd, BMEdge *e) return kfe; } +/* User has just clicked for first time or first time after a restart (E key). + * Copy the current position data into prev. */ static void knife_start_cut(knifetool_opdata *kcd) { - kcd->prevedge = kcd->curedge; - kcd->prevvert = kcd->curvert; - kcd->prevbmface = kcd->curbmface; - kcd->cutnr++; - kcd->prev_is_space = kcd->is_space; - kcd->is_space = 0; - kcd->prevmval[0] = kcd->vc.mval[0]; - kcd->prevmval[1] = kcd->vc.mval[1]; + kcd->prev = kcd->cur; + kcd->cur.is_space = 0; /*TODO: why do we do this? */ - copy_v3_v3(kcd->prevco, kcd->vertco); - copy_v3_v3(kcd->prevcage, kcd->vertcage); - - if (kcd->prevvert == NULL && kcd->prevedge == NULL && is_zero_v3(kcd->prevcage)) { + if (kcd->prev.vert == NULL && kcd->prev.edge == NULL && is_zero_v3(kcd->prev.cage)) { /* Make prevcage a point on the view ray to mouse closest to a point on model: choose vertex 0 */ float origin[3], ray[3], co[3]; BMVert *v0; - knife_input_ray_cast(kcd, kcd->vc.mval, origin, ray); + knife_input_ray_cast(kcd, kcd->cur.mval, origin, ray); add_v3_v3v3(co, origin, ray); v0 = BM_vert_at_index(kcd->em->bm, 0); if (v0) { - closest_to_line_v3(kcd->prevcage, v0->co, co, origin); - copy_v3_v3(kcd->prevco, kcd->prevcage); - copy_v3_v3(kcd->vertcage, kcd->prevcage); - copy_v3_v3(kcd->vertco, kcd->prevco); + closest_to_line_v3(kcd->prev.cage, v0->co, co, origin); + copy_v3_v3(kcd->prev.co, kcd->prev.cage); /*TODO: do we need this? */ + copy_v3_v3(kcd->cur.cage, kcd->prev.cage); + copy_v3_v3(kcd->cur.co, kcd->prev.co); } } } @@ -339,9 +347,9 @@ static void knife_find_basef(knifetool_opdata *kcd, KnifeEdge *kfe) if (kfe->v1->isface || kfe->v2->isface) { if (kfe->v2->isface) - kfe->basef = kcd->curbmface; + kfe->basef = kcd->cur.bmface; else - kfe->basef = kcd->prevbmface; + kfe->basef = kcd->prev.bmface; } else { for (r1 = kfe->v1->edges.first; r1 && !kfe->basef; r1 = r1->next) { @@ -408,48 +416,50 @@ static KnifeVert *knife_split_edge(knifetool_opdata *kcd, KnifeEdge *kfe, float return newkfe->v2; } +/* Make a single KnifeEdge for cut from kcd->prev to kcd->cur. + * and move cur data to prev. */ static void knife_add_single_cut(knifetool_opdata *kcd) { KnifeEdge *kfe = new_knife_edge(kcd), *kfe2 = NULL, *kfe3 = NULL; - if (kcd->prevvert && kcd->prevvert == kcd->curvert) + if (kcd->prev.vert && kcd->prev.vert == kcd->cur.vert) return; - if (kcd->prevedge && kcd->prevedge == kcd->curedge) + if (kcd->prev.edge && kcd->prev.edge == kcd->cur.edge) return; kfe->draw = 1; - if (kcd->prevvert) { - kfe->v1 = kcd->prevvert; + if (kcd->prev.vert) { + kfe->v1 = kcd->prev.vert; } - else if (kcd->prevedge) { - kfe->v1 = knife_split_edge(kcd, kcd->prevedge, kcd->prevco, &kfe2); + else if (kcd->prev.edge) { + kfe->v1 = knife_split_edge(kcd, kcd->prev.edge, kcd->prev.co, &kfe2); } else { - kfe->v1 = new_knife_vert(kcd, kcd->prevco, kcd->prevco); - kfe->v1->draw = kfe->draw = !kcd->prev_is_space; - kfe->v1->inspace = kcd->prev_is_space; - kfe->draw = !kcd->prev_is_space; + kfe->v1 = new_knife_vert(kcd, kcd->prev.co, kcd->prev.co); + kfe->v1->draw = kfe->draw = !kcd->prev.is_space; + kfe->v1->inspace = kcd->prev.is_space; + kfe->draw = !kcd->prev.is_space; kfe->v1->isface = 1; } - if (kcd->curvert) { - kfe->v2 = kcd->curvert; + if (kcd->cur.vert) { + kfe->v2 = kcd->cur.vert; } - else if (kcd->curedge) { - kfe->v2 = knife_split_edge(kcd, kcd->curedge, kcd->vertco, &kfe3); - kcd->curvert = kfe->v2; + else if (kcd->cur.edge) { + kfe->v2 = knife_split_edge(kcd, kcd->cur.edge, kcd->cur.co, &kfe3); + kcd->cur.vert = kfe->v2; } else { - kfe->v2 = new_knife_vert(kcd, kcd->vertco, kcd->vertco); - kfe->v2->draw = !kcd->is_space; + kfe->v2 = new_knife_vert(kcd, kcd->cur.co, kcd->cur.co); + kfe->v2->draw = !kcd->cur.is_space; kfe->v2->isface = 1; - kfe->v2->inspace = kcd->is_space; + kfe->v2->inspace = kcd->cur.is_space; - if (kcd->is_space) + if (kcd->cur.is_space) kfe->draw = 0; - kcd->curvert = kfe->v2; + kcd->cur.vert = kfe->v2; } knife_find_basef(kcd, kfe); @@ -460,27 +470,20 @@ static void knife_add_single_cut(knifetool_opdata *kcd) knife_edge_append_face(kcd, kfe, kfe->basef); /* sanity check to make sure we're in the right edge/face lists */ - if (kcd->curbmface) { - if (!find_ref(&kfe->faces, kcd->curbmface)) { - knife_edge_append_face(kcd, kfe, kcd->curbmface); + if (kcd->cur.bmface) { + if (!find_ref(&kfe->faces, kcd->cur.bmface)) { + knife_edge_append_face(kcd, kfe, kcd->cur.bmface); } - if (kcd->prevbmface && kcd->prevbmface != kcd->curbmface) { - if (!find_ref(&kfe->faces, kcd->prevbmface)) { - knife_edge_append_face(kcd, kfe, kcd->prevbmface); + if (kcd->prev.bmface && kcd->prev.bmface != kcd->cur.bmface) { + if (!find_ref(&kfe->faces, kcd->prev.bmface)) { + knife_edge_append_face(kcd, kfe, kcd->prev.bmface); } } } /* set up for next cut */ - kcd->prevbmface = kcd->curbmface; - kcd->prevvert = kcd->curvert; - kcd->prevedge = kcd->curedge; - copy_v3_v3(kcd->prevco, kcd->vertco); - copy_v3_v3(kcd->prevcage, kcd->vertcage); - kcd->prev_is_space = kcd->is_space; - kcd->prevmval[0] = kcd->vc.mval[0]; - kcd->prevmval[1] = kcd->vc.mval[1]; + kcd->prev = kcd->cur; } static int verge_linehit(const void *vlh1, const void *vlh2) @@ -562,26 +565,26 @@ static void knife_cut_through(knifetool_opdata *kcd) qsort(kcd->linehits, kcd->totlinehit, sizeof(BMEdgeHit), verge_linehit); splitkfe = MEM_callocN(kcd->totlinehit * sizeof(KnifeEdge *), "knife_cut_through"); - if (kcd->prevvert) { - if (kcd->prevvert == kcd->curvert) + if (kcd->prev.vert) { + if (kcd->prev.vert == kcd->cur.vert) return; - firstv = kcd->prevvert; - knife_get_vert_faces(kcd, firstv, kcd->prevbmface, &firstfaces); + firstv = kcd->prev.vert; + knife_get_vert_faces(kcd, firstv, kcd->prev.bmface, &firstfaces); } - else if (kcd->prevedge) { - if (kcd->prevedge == kcd->curedge) + else if (kcd->prev.edge) { + if (kcd->prev.edge == kcd->cur.edge) return; - firstv = knife_split_edge(kcd, kcd->prevedge, kcd->prevco, &kfe3); - knife_get_edge_faces(kcd, kcd->prevedge, &firstfaces); + firstv = knife_split_edge(kcd, kcd->prev.edge, kcd->prev.co, &kfe3); + knife_get_edge_faces(kcd, kcd->prev.edge, &firstfaces); } - if (kcd->curvert) { - lastv = kcd->curvert; - knife_get_vert_faces(kcd, lastv, kcd->curbmface, &lastfaces); + if (kcd->cur.vert) { + lastv = kcd->cur.vert; + knife_get_vert_faces(kcd, lastv, kcd->cur.bmface, &lastfaces); } - else if (kcd->curedge) { - lastv = knife_split_edge(kcd, kcd->curedge, kcd->vertco, &kfe3); - knife_get_edge_faces(kcd, kcd->curedge, &lastfaces); + else if (kcd->cur.edge) { + lastv = knife_split_edge(kcd, kcd->cur.edge, kcd->cur.co, &kfe3); + knife_get_edge_faces(kcd, kcd->cur.edge, &lastfaces); } if (firstv) { @@ -650,19 +653,15 @@ static void knife_cut_through(knifetool_opdata *kcd) kcd->totlinehit = 0; /* set up for next cut */ - kcd->prevbmface = kcd->curbmface; - kcd->prevvert = kcd->curvert; - kcd->prevedge = kcd->curedge; - copy_v3_v3(kcd->prevco, kcd->vertco); - copy_v3_v3(kcd->prevcage, kcd->vertcage); - kcd->prev_is_space = kcd->is_space; - kcd->prevmval[0] = kcd->vc.mval[0]; - kcd->prevmval[1] = kcd->vc.mval[1]; + kcd->prev = kcd->cur; } +/* User has just left-clicked after the first time. + * Add all knife cuts implied by line from prev to cur. + * If that line crossed edges then kcd->linehits will be non-NULL. */ static void knife_add_cut(knifetool_opdata *kcd) { - knifetool_opdata oldkcd = *kcd; + KnifePosData savcur = kcd->cur; if (kcd->cut_through) { knife_cut_through(kcd); @@ -687,56 +686,46 @@ static void knife_add_cut(knifetool_opdata *kcd) if (firstlh->v || lastlh->v) { KnifeVert *kfv = firstlh->v ? firstlh->v : lastlh->v; - kcd->prevvert = kfv; - copy_v3_v3(kcd->prevco, firstlh->hit); - copy_v3_v3(kcd->prevcage, firstlh->cagehit); - kcd->prevedge = NULL; - kcd->prevbmface = f; + kcd->prev.vert = kfv; + copy_v3_v3(kcd->prev.co, firstlh->hit); + copy_v3_v3(kcd->prev.cage, firstlh->cagehit); + kcd->prev.edge = NULL; + kcd->prev.bmface = f; + /* TODO: should we set prev.in_space = 0 ? */ } lastlh = firstlh = NULL; } - if (len_v3v3(kcd->prevcage, lh->realhit) < FLT_EPSILON * 80) + if (len_v3v3(kcd->prev.cage, lh->realhit) < FLT_EPSILON * 80) continue; - if (len_v3v3(kcd->vertcage, lh->realhit) < FLT_EPSILON * 80) + if (len_v3v3(kcd->cur.cage, lh->realhit) < FLT_EPSILON * 80) continue; - if (kcd->prev_is_space) { - kcd->prev_is_space = 0; - copy_v3_v3(kcd->prevco, lh->hit); - copy_v3_v3(kcd->prevcage, lh->cagehit); - kcd->prevvert = NULL; - kcd->prevedge = lh->kfe; - kcd->prevbmface = lh->f; + if (kcd->prev.is_space) { + kcd->prev.is_space = 0; + copy_v3_v3(kcd->prev.co, lh->hit); + copy_v3_v3(kcd->prev.cage, lh->cagehit); + kcd->prev.vert = NULL; + kcd->prev.edge = lh->kfe; + kcd->prev.bmface = lh->f; continue; } - kcd->is_space = 0; - kcd->curedge = lh->kfe; - kcd->curbmface = lh->f; - kcd->curvert = lh->v; - copy_v3_v3(kcd->vertco, lh->hit); - copy_v3_v3(kcd->vertcage, lh->cagehit); + kcd->cur.is_space = 0; + kcd->cur.edge = lh->kfe; + kcd->cur.bmface = lh->f; + kcd->cur.vert = lh->v; + copy_v3_v3(kcd->cur.co, lh->hit); + copy_v3_v3(kcd->cur.cage, lh->cagehit); knife_add_single_cut(kcd); } - if (oldkcd.is_space) { - kcd->prevbmface = oldkcd.curbmface; - kcd->prevvert = oldkcd.curvert; - kcd->prevedge = oldkcd.curedge; - copy_v3_v3(kcd->prevco, oldkcd.vertco); - copy_v3_v3(kcd->prevcage, oldkcd.vertcage); - kcd->prev_is_space = oldkcd.is_space; + if (savcur.is_space) { + kcd->prev = savcur; } else { - kcd->curbmface = oldkcd.curbmface; - kcd->curvert = oldkcd.curvert; - kcd->curedge = oldkcd.curedge; - kcd->is_space = oldkcd.is_space; - copy_v3_v3(kcd->vertco, oldkcd.vertco); - copy_v3_v3(kcd->vertcage, oldkcd.vertcage); - + kcd->cur = savcur; knife_add_single_cut(kcd); } @@ -762,7 +751,7 @@ static void knifetool_draw_angle_snapping(knifetool_opdata *kcd) /* make u the window coords of prevcage */ view3d_get_transformation(kcd->ar, kcd->vc.rv3d, kcd->ob, &mats); - gluProject(kcd->prevcage[0], kcd->prevcage[1], kcd->prevcage[2], + gluProject(kcd->prev.cage[0], kcd->prev.cage[1], kcd->prev.cage[2], mats.modelview, mats.projection, mats.viewport, &u[0], &u[1], &u[2]); @@ -871,39 +860,39 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void glLineWidth(2.0); glBegin(GL_LINES); - glVertex3fv(kcd->prevcage); - glVertex3fv(kcd->vertcage); + glVertex3fv(kcd->prev.cage); + glVertex3fv(kcd->cur.cage); glEnd(); glLineWidth(1.0); } - if (kcd->curedge) { + if (kcd->cur.edge) { glColor3f(0.5, 0.3, 0.15); glLineWidth(2.0); glBegin(GL_LINES); - glVertex3fv(kcd->curedge->v1->cageco); - glVertex3fv(kcd->curedge->v2->cageco); + glVertex3fv(kcd->cur.edge->v1->cageco); + glVertex3fv(kcd->cur.edge->v2->cageco); glEnd(); glLineWidth(1.0); } - else if (kcd->curvert) { + else if (kcd->cur.vert) { glColor3f(0.8, 0.2, 0.1); glPointSize(11); glBegin(GL_POINTS); - glVertex3fv(kcd->vertcage); + glVertex3fv(kcd->cur.cage); glEnd(); } - if (kcd->curbmface) { + if (kcd->cur.bmface) { glColor3f(0.1, 0.8, 0.05); glPointSize(9); glBegin(GL_POINTS); - glVertex3fv(kcd->vertcage); + glVertex3fv(kcd->cur.cage); glEnd(); } @@ -1047,7 +1036,7 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, for (ref = lst->first; ref; ref = ref->next) { KnifeEdge *kfe = ref->ref; - //if (kfe == kcd->curedge || kfe == kcd->prevedge) + //if (kfe == kcd->cur.edge || kfe == kcd->prev.edge) // continue; if (isect_line_tri_v3(kfe->v1->cageco, kfe->v2->cageco, v1, v2, v3, &lambda, uv)) { @@ -1055,12 +1044,12 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, interp_v3_v3v3(p, kfe->v1->cageco, kfe->v2->cageco, lambda); - if (kcd->curvert && len_squared_v3v3(kcd->curvert->cageco, p) < depsilon_squared) + if (kcd->cur.vert && len_squared_v3v3(kcd->cur.vert->cageco, p) < depsilon_squared) continue; - if (kcd->prevvert && len_squared_v3v3(kcd->prevvert->cageco, p) < depsilon_squared) + if (kcd->prev.vert && len_squared_v3v3(kcd->prev.vert->cageco, p) < depsilon_squared) continue; - if ( len_squared_v3v3(kcd->prevcage, p) < depsilon_squared || - len_squared_v3v3(kcd->vertcage, p) < depsilon_squared) + if ( len_squared_v3v3(kcd->prev.cage, p) < depsilon_squared || + len_squared_v3v3(kcd->cur.cage, p) < depsilon_squared) { continue; } @@ -1091,8 +1080,8 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, if (!hitf && !BLI_smallhash_haskey(ehash, (intptr_t)kfe)) { BMEdgeHit hit; - if ( len_squared_v3v3(p, kcd->vertco) < depsilon_squared || - len_squared_v3v3(p, kcd->prevco) < depsilon_squared) + if ( len_squared_v3v3(p, kcd->cur.co) < depsilon_squared || + len_squared_v3v3(p, kcd->prev.co) < depsilon_squared) { continue; } @@ -1172,8 +1161,8 @@ static void knife_find_line_hits(knifetool_opdata *kcd) kcd->totlinehit = 0; } - copy_v3_v3(v1, kcd->prevcage); - copy_v3_v3(v2, kcd->vertcage); + copy_v3_v3(v1, kcd->prev.cage); + copy_v3_v3(v2, kcd->cur.cage); /* project screen line's 3d coordinates back into 2d */ knife_project_v3(kcd, v1, s1); @@ -1359,7 +1348,7 @@ static KnifeEdge *knife_find_closest_edge(knifetool_opdata *kcd, float p[3], flo copy_v3_v3(p, co); copy_v3_v3(cagep, cageco); - kcd->curbmface = f; + kcd->cur.bmface = f; if (f) { KnifeEdge *cure = NULL; @@ -1446,7 +1435,7 @@ static KnifeVert *knife_find_closest_vert(knifetool_opdata *kcd, float p[3], flo /* set p to co, in case we don't find anything, means a face cut */ copy_v3_v3(p, co); copy_v3_v3(cagep, p); - kcd->curbmface = f; + kcd->cur.bmface = f; if (f) { ListBase *lst; @@ -1517,8 +1506,8 @@ static void knife_snap_angle(knifetool_opdata *kcd) int dx, dy; float w, abs_tan; - dx = kcd->vc.mval[0] - kcd->prevmval[0]; - dy = kcd->vc.mval[1] - kcd->prevmval[1]; + dx = kcd->vc.mval[0] - kcd->prev.mval[0]; + dy = kcd->vc.mval[1] - kcd->prev.mval[1]; if (dx == 0 || dy == 0) return; @@ -1526,21 +1515,21 @@ static void knife_snap_angle(knifetool_opdata *kcd) abs_tan = fabsf(w); if (abs_tan <= 0.4142f) { /* tan(22.5 degrees) = 0.4142 */ kcd->angle_snapping = ANGLE_0; - kcd->vc.mval[1] = kcd->prevmval[1]; + kcd->vc.mval[1] = kcd->prev.mval[1]; } else if (abs_tan < 2.4142f) { /* tan(67.5 degrees) = 2.4142 */ if (w > 0) { kcd->angle_snapping = ANGLE_45; - kcd->vc.mval[1] = kcd->prevmval[1] + dx; + kcd->vc.mval[1] = kcd->prev.mval[1] + dx; } else { kcd->angle_snapping = ANGLE_135; - kcd->vc.mval[1] = kcd->prevmval[1] - dx; + kcd->vc.mval[1] = kcd->prev.mval[1] - dx; } } else { kcd->angle_snapping = ANGLE_90; - kcd->vc.mval[0] = kcd->prevmval[0]; + kcd->vc.mval[0] = kcd->prev.mval[0]; } } @@ -1550,24 +1539,26 @@ static int knife_update_active(knifetool_opdata *kcd) if (kcd->angle_snapping != ANGLE_FREE && kcd->mode == MODE_DRAGGING) knife_snap_angle(kcd); - kcd->curvert = NULL; kcd->curedge = NULL; kcd->curbmface = NULL; + knife_pos_data_clear(&kcd->cur); + kcd->cur.mval[0] = kcd->vc.mval[0]; + kcd->cur.mval[1] = kcd->vc.mval[1]; - kcd->curvert = knife_find_closest_vert(kcd, kcd->vertco, kcd->vertcage, &kcd->curbmface, &kcd->is_space); - if (!kcd->curvert) { - kcd->curedge = knife_find_closest_edge(kcd, kcd->vertco, kcd->vertcage, &kcd->curbmface, &kcd->is_space); + kcd->cur.vert = knife_find_closest_vert(kcd, kcd->cur.co, kcd->cur.cage, &kcd->cur.bmface, &kcd->cur.is_space); + if (!kcd->cur.vert) { + kcd->cur.edge = knife_find_closest_edge(kcd, kcd->cur.co, kcd->cur.cage, &kcd->cur.bmface, &kcd->cur.is_space); } /* if no hits are found this would normally default to (0,0,0) so instead * get a point at the mouse ray closest to the previous point. * Note that drawing lines in `free-space` isn't properly supported * but theres no guarantee (0,0,0) has any geometry either - campbell */ - if (kcd->curvert == NULL && kcd->curedge == NULL) { + if (kcd->cur.vert == NULL && kcd->cur.edge == NULL) { float origin[3], ray[3], co[3]; knife_input_ray_cast(kcd, kcd->vc.mval, origin, ray); add_v3_v3v3(co, origin, ray); - closest_to_line_v3(kcd->vertcage, kcd->prevcage, co, origin); + closest_to_line_v3(kcd->cur.cage, kcd->prev.cage, co, origin); } if (kcd->mode == MODE_DRAGGING) { @@ -2720,6 +2711,9 @@ static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut)) /* cut all the way through the mesh if use_occlude_geometry button not pushed */ kcd->cut_through = !(kcd->vc.v3d->flag & V3D_ZBUF_SELECT); + knife_pos_data_clear(&kcd->cur); + knife_pos_data_clear(&kcd->prev); + return 1; } From 74b7bc1228b502c1fec88e1399601144d7bd34f2 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 12 Mar 2012 13:04:06 +0000 Subject: [PATCH 034/310] Fix #30524: documentation example code for bge.types.KX_MeshProxy did not work, using fix suggested by Ryan King. --- doc/python_api/rst/bge.types.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/python_api/rst/bge.types.rst b/doc/python_api/rst/bge.types.rst index 3c15362a4ec..fda05bb6ed5 100644 --- a/doc/python_api/rst/bge.types.rst +++ b/doc/python_api/rst/bge.types.rst @@ -1806,9 +1806,9 @@ Game Types (bge.types) object = cont.owner for mesh in object.meshes: - for material in mesh.materials: + for m_index in range(len(mesh.materials)): for v_index in range(mesh.getVertexArrayLength(mat)): - vertex = mesh.getVertex(mat, v_index) + vertex = mesh.getVertex(m_index, v_index) # Do something with vertex here... # ... eg: colour the vertex red. vertex.colour = [1.0, 0.0, 0.0, 1.0] From a527e3ea25bd66e4cd6d6842bcdab865be0c913f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 12 Mar 2012 14:35:07 +0000 Subject: [PATCH 035/310] Fix #30496: Bugs and crashes about "make links modifers" function. Was missed check for if modifier is available for particular object type which ended up with unpredictable results when modifier which isn't supported yet for some object type as linked to that object type. --- source/blender/blenkernel/BKE_object.h | 2 ++ source/blender/blenkernel/intern/object.c | 29 +++++++++++++++++++ .../blender/editors/object/object_modifier.c | 3 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index 1e9bb85b549..f5937304e76 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -67,6 +67,8 @@ void update_base_layer(struct Scene *scene, struct Object *ob); void free_object(struct Object *ob); void object_free_display(struct Object *ob); +int object_support_modifier_type(struct Object *ob, int modifier_type); + void object_link_modifiers(struct Object *ob, struct Object *from); void object_free_modifiers(struct Object *ob); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 32a3ca2b732..0557fcf5fcd 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -199,16 +199,40 @@ void object_free_modifiers(Object *ob) object_free_softbody(ob); } +int object_support_modifier_type(Object *ob, int modifier_type) +{ + ModifierTypeInfo *mti; + + mti = modifierType_getInfo(modifier_type); + + if (!((mti->flags & eModifierTypeFlag_AcceptsCVs) || + (ob->type==OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh)))) + { + return FALSE; + } + + return TRUE; +} + void object_link_modifiers(struct Object *ob, struct Object *from) { ModifierData *md; object_free_modifiers(ob); + if (!ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) { + /* only objects listed above can have modifiers and linking them to objects + * which doesn't have modifiers stack is quite silly */ + return; + } + for (md=from->modifiers.first; md; md=md->next) { ModifierData *nmd = NULL; if (ELEM4(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_ParticleInstance, eModifierType_Collision)) continue; + if (!object_support_modifier_type(ob, md->type)) + continue; + nmd = modifier_new(md->type); modifier_copyData(md, nmd); BLI_addtail(&ob->modifiers, nmd); @@ -954,6 +978,11 @@ void copy_object_particlesystems(Object *obn, Object *ob) ParticleSystem *psys, *npsys; ModifierData *md; + if (obn->type != OB_MESH) { + /* currently only mesh objects can have soft body */ + return; + } + obn->particlesystem.first= obn->particlesystem.last= NULL; for (psys=ob->particlesystem.first; psys; psys=psys->next) { npsys= copy_particlesystem(psys); diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index de9e3db25b8..f1222ccf7f7 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -670,8 +670,7 @@ static EnumPropertyItem *modifier_add_itemf(bContext *C, PointerRNA *UNUSED(ptr) if(mti->flags & eModifierTypeFlag_NoUserAdd) continue; - if(!((mti->flags & eModifierTypeFlag_AcceptsCVs) || - (ob->type==OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh)))) + if(!object_support_modifier_type(ob, md_item->value)) continue; } else { From d3e271c55a5740e7ea9b3302c57555605d860d12 Mon Sep 17 00:00:00 2001 From: Lukas Toenne Date: Mon, 12 Mar 2012 14:39:37 +0000 Subject: [PATCH 036/310] Fix for lasso gestures. After executing the modal gesture operator the list of gesture points is copied to the operator "path" id property, which is simply a collection of points. This list must be cleared before adding new lasso points to it, since operator properties are now stored after each execution. Noticed by Olivier Amrein (oenvoyage) on IRC. --- source/blender/windowmanager/intern/wm_operators.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 22e6d5be383..405daff829e 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -2683,6 +2683,7 @@ static void gesture_lasso_apply(bContext *C, wmOperator *op) /* operator storage as path. */ + RNA_collection_clear(op->ptr, "path"); for(i=0; ipoints; i++, lasso+=2) { loc[0]= lasso[0]; loc[1]= lasso[1]; From e0a2e79f4ddc95636e7969f91a1c4d91449e1ce7 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 12 Mar 2012 14:55:56 +0000 Subject: [PATCH 037/310] Fix #30406: Hooks ignore Automatic handles setting in curves Update handles positions after applying modifiers which seems to be expected behavior. The only currently unsolved issue is about updating aligned handles because this needs to determine in which order handles need to be recalculated which currently depends on selection flags and which is quite tricky to do when running modifiers and animation data, so currently just not update their positions for now. --- source/blender/blenkernel/intern/curve.c | 25 +++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 5af72e6115c..0a10b894551 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -2480,7 +2480,7 @@ void makeBevelList(Object *ob) */ /* mode: is not zero when FCurve, is 2 when forced horizontal for autohandles */ -void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode) +static void calchandleNurb_intern(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode, int skip_align) { float *p1,*p2,*p3, pt[3]; float dvec_a[3], dvec_b[3]; @@ -2627,6 +2627,13 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode) madd_v3_v3v3fl(p2+3, p2, dvec_b, 1.0f/3.0f); } + if(skip_align) { + /* handles need to be updated during animation and applying stuff like hooks, + * but in such situatios it's quite difficult to distinguish in which order + * align handles should be aligned so skip them for now */ + return; + } + len_b= len_v3v3(p2, p2+3); len_a= len_v3v3(p2, p2-3); if(len_a==0.0f) len_a= 1.0f; @@ -2670,7 +2677,7 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode) } } -void calchandlesNurb(Nurb *nu) /* first, if needed, set handle flags */ +static void calchandlesNurb_intern(Nurb *nu, int skip_align) { BezTriple *bezt, *prev, *next; short a; @@ -2685,7 +2692,7 @@ void calchandlesNurb(Nurb *nu) /* first, if needed, set handle flags */ next= bezt+1; while(a--) { - calchandleNurb(bezt, prev, next, 0); + calchandleNurb_intern(bezt, prev, next, 0, skip_align); prev= bezt; if(a==1) { if(nu->flagu & CU_NURB_CYCLIC) next= nu->bezt; @@ -2697,6 +2704,16 @@ void calchandlesNurb(Nurb *nu) /* first, if needed, set handle flags */ } } +void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode) +{ + calchandleNurb_intern(bezt, prev, next, mode, FALSE); +} + +void calchandlesNurb(Nurb *nu) /* first, if needed, set handle flags */ +{ + calchandlesNurb_intern(nu, FALSE); +} + void testhandlesNurb(Nurb *nu) { @@ -3080,6 +3097,8 @@ void curve_applyVertexCos(Curve *UNUSED(cu), ListBase *lb, float (*vertexCos)[3] copy_v3_v3(bp->vec, co); co+=3; } } + + calchandlesNurb_intern(nu, TRUE); } } From 30790e9390305a1e9108318e98c85a2b4699a045 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 12 Mar 2012 21:09:27 +0000 Subject: [PATCH 038/310] fix [#30529] BMesh: Wrong Indizes of Faces problem was bow-tie quads would add opposite normals together and result in zero vector which was used for projection. Now is_quad_convex_v3() checks if quad contains 2 faces which point away from eachother when split by either direction. Theres another fix for this bug which can be done since creating the face can use existing edges in the example given so it wont have to guess which order of verts to use. --- source/blender/blenlib/intern/math_geom.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 8217439b7be..b8cb9790d9e 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -3058,10 +3058,23 @@ float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], fl { float nor[3], nor1[3], nor2[3], vec[4][2]; int axis_a, axis_b; - + /* define projection, do both trias apart, quad is undefined! */ + + /* strictly speaking this isn't necessarily convex, + * but when try normals point away from eachother + * we don't wan't to make that face */ + normal_tri_v3(nor1, v2, v3, v4); + normal_tri_v3(nor2, v1, v2, v4); + if (UNLIKELY(dot_v3v3(nor1, nor2) < 0.0f)) { + return FALSE; + } normal_tri_v3(nor1, v1, v2, v3); normal_tri_v3(nor2, v1, v3, v4); + if (UNLIKELY(dot_v3v3(nor1, nor2) < 0.0f)) { + return FALSE; + } + add_v3_v3v3(nor, nor1, nor2); axis_dominant_v3(&axis_a, &axis_b, nor); @@ -3071,7 +3084,7 @@ float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], fl vec[2][0]= v3[axis_a]; vec[2][1]= v3[axis_b]; vec[3][0]= v4[axis_a]; vec[3][1]= v4[axis_b]; - + /* linetests, the 2 diagonals have to instersect to be convex */ - return (isect_line_line_v2(vec[0], vec[2], vec[1], vec[3]) > 0) ? 1 : 0; + return (isect_line_line_v2(vec[0], vec[2], vec[1], vec[3]) > 0) ? TRUE : FALSE; } From e3cfca511f55495de1b58bf714fb4b8cabc633db Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 12 Mar 2012 21:18:28 +0000 Subject: [PATCH 039/310] Bundle latest version of Carve library which shall resolve compilation issues with clang --- extern/carve/CMakeLists.txt | 186 +++++++++--------- extern/carve/bundle.sh | 2 +- extern/carve/include/carve/exact.hpp | 8 +- extern/carve/include/carve/kd_node.hpp | 6 +- extern/carve/include/carve/mesh_impl.hpp | 3 +- .../carve/include/carve/polyhedron_impl.hpp | 12 +- extern/carve/patches/strict_flags.patch | 24 --- 7 files changed, 109 insertions(+), 132 deletions(-) diff --git a/extern/carve/CMakeLists.txt b/extern/carve/CMakeLists.txt index cbf92ee293e..660538998a1 100644 --- a/extern/carve/CMakeLists.txt +++ b/extern/carve/CMakeLists.txt @@ -35,115 +35,115 @@ set(INC_SYS ) set(SRC - lib/carve.cpp - lib/mesh.cpp - lib/intersect_group.cpp - lib/intersect_classify_edge.cpp - lib/intersect_classify_group.cpp - lib/polyhedron.cpp - lib/geom3d.cpp - lib/polyline.cpp - lib/csg_collector.cpp - lib/triangulator.cpp - lib/intersect_face_division.cpp - lib/intersect_half_classify_group.cpp - lib/edge.cpp - lib/math.cpp - lib/geom2d.cpp - lib/tag.cpp lib/intersection.cpp - lib/convex_hull.cpp - lib/csg.cpp lib/intersect.cpp - lib/face.cpp + lib/triangulator.cpp + lib/convex_hull.cpp + lib/polyhedron.cpp + lib/polyline.cpp lib/pointset.cpp - lib/timing.cpp - lib/octree.cpp + lib/geom2d.cpp + lib/math.cpp + lib/intersect_half_classify_group.cpp + lib/intersect_face_division.cpp + lib/tag.cpp lib/aabb.cpp + lib/intersect_classify_group.cpp + lib/mesh.cpp + lib/timing.cpp + lib/geom3d.cpp + lib/intersect_group.cpp + lib/carve.cpp + lib/intersect_classify_edge.cpp + lib/csg.cpp + lib/face.cpp + lib/csg_collector.cpp lib/intersect_debug.cpp + lib/edge.cpp + lib/octree.cpp - lib/intersect_classify_common.hpp - lib/csg_data.hpp - lib/csg_collector.hpp - lib/intersect_common.hpp - lib/intersect_classify_common_impl.hpp - lib/csg_detail.hpp lib/intersect_debug.hpp + lib/csg_collector.hpp + lib/csg_data.hpp + lib/intersect_classify_common.hpp + lib/intersect_common.hpp + lib/csg_detail.hpp + lib/intersect_classify_common_impl.hpp - include/carve/polyhedron_decl.hpp - include/carve/geom2d.hpp - include/carve/exact.hpp - include/carve/triangulator_impl.hpp - include/carve/collection.hpp - include/carve/pointset.hpp - include/carve/djset.hpp - include/carve/kd_node.hpp - include/carve/polyline.hpp - include/carve/polyline_iter.hpp - include/carve/geom3d.hpp - include/carve/edge_decl.hpp - include/carve/face_decl.hpp + include/carve/vertex_impl.hpp include/carve/aabb_impl.hpp - include/carve/colour.hpp - include/carve/pointset_iter.hpp - include/carve/polyline_decl.hpp - include/carve/rescale.hpp - include/carve/mesh_impl.hpp - include/carve/classification.hpp - include/carve/util.hpp - include/carve/triangulator.hpp - include/carve/polyhedron_base.hpp - include/carve/rtree.hpp - include/carve/math.hpp - include/carve/math_constants.hpp - include/carve/octree_decl.hpp - include/carve/input.hpp - include/carve/mesh_ops.hpp - include/carve/debug_hooks.hpp - include/carve/mesh_simplify.hpp - include/carve/interpolator.hpp - include/carve/poly_decl.hpp include/carve/csg.hpp + include/carve/pointset_iter.hpp + include/carve/debug_hooks.hpp include/carve/mesh.hpp - include/carve/carve.hpp - include/carve/gnu_cxx.h - include/carve/polyhedron_impl.hpp - include/carve/poly_impl.hpp - include/carve/aabb.hpp - include/carve/convex_hull.hpp - include/carve/vertex_decl.hpp - include/carve/win32.h - include/carve/edge_impl.hpp - include/carve/tag.hpp - include/carve/tree.hpp - include/carve/heap.hpp - include/carve/matrix.hpp - include/carve/poly.hpp - include/carve/vector.hpp - include/carve/intersection.hpp - include/carve/faceloop.hpp - include/carve/geom_impl.hpp - include/carve/octree_impl.hpp - include/carve/spacetree.hpp - include/carve/collection/unordered/std_impl.hpp + include/carve/triangulator_impl.hpp + include/carve/edge_decl.hpp + include/carve/collection/unordered.hpp include/carve/collection/unordered/tr1_impl.hpp + include/carve/collection/unordered/fallback_impl.hpp + include/carve/collection/unordered/std_impl.hpp + include/carve/collection/unordered/vcpp_impl.hpp include/carve/collection/unordered/libstdcpp_impl.hpp include/carve/collection/unordered/boost_impl.hpp - include/carve/collection/unordered/vcpp_impl.hpp - include/carve/collection/unordered/fallback_impl.hpp - include/carve/collection/unordered.hpp - include/carve/face_impl.hpp - include/carve/pointset_impl.hpp - include/carve/cbrt.h - include/carve/vcpp_config.h + include/carve/convex_hull.hpp include/carve/geom.hpp - include/carve/vertex_impl.hpp - include/carve/polyline_impl.hpp - include/carve/pointset_decl.hpp - include/carve/timing.hpp - include/carve/csg_triangulator.hpp - include/carve/iobj.hpp include/carve/collection_types.hpp + include/carve/cbrt.h + include/carve/util.hpp + include/carve/iobj.hpp + include/carve/polyline_decl.hpp + include/carve/polyline_impl.hpp + include/carve/win32.h + include/carve/edge_impl.hpp + include/carve/carve.hpp + include/carve/polyline.hpp + include/carve/face_decl.hpp + include/carve/matrix.hpp + include/carve/classification.hpp + include/carve/geom_impl.hpp + include/carve/faceloop.hpp + include/carve/mesh_ops.hpp + include/carve/tree.hpp + include/carve/geom2d.hpp + include/carve/face_impl.hpp + include/carve/polyhedron_decl.hpp + include/carve/interpolator.hpp + include/carve/poly_decl.hpp + include/carve/mesh_impl.hpp + include/carve/gnu_cxx.h + include/carve/mesh_simplify.hpp + include/carve/triangulator.hpp + include/carve/pointset_impl.hpp + include/carve/rtree.hpp + include/carve/math_constants.hpp + include/carve/vector.hpp + include/carve/octree_impl.hpp + include/carve/pointset.hpp + include/carve/math.hpp + include/carve/intersection.hpp + include/carve/colour.hpp + include/carve/kd_node.hpp + include/carve/input.hpp + include/carve/geom3d.hpp + include/carve/exact.hpp + include/carve/rescale.hpp + include/carve/polyhedron_base.hpp + include/carve/heap.hpp + include/carve/spacetree.hpp + include/carve/polyhedron_impl.hpp + include/carve/vcpp_config.h + include/carve/aabb.hpp + include/carve/polyline_iter.hpp + include/carve/djset.hpp + include/carve/vertex_decl.hpp + include/carve/csg_triangulator.hpp + include/carve/poly.hpp + include/carve/timing.hpp + include/carve/octree_decl.hpp + include/carve/pointset_decl.hpp + include/carve/tag.hpp + include/carve/collection.hpp + include/carve/poly_impl.hpp ) if(WITH_BOOST) diff --git a/extern/carve/bundle.sh b/extern/carve/bundle.sh index bc719ae5ba8..e68b2c7e90e 100755 --- a/extern/carve/bundle.sh +++ b/extern/carve/bundle.sh @@ -47,7 +47,7 @@ cat > CMakeLists.txt << EOF # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # The Original Code is Copyright (C) 2006, Blender Foundation # All rights reserved. diff --git a/extern/carve/include/carve/exact.hpp b/extern/carve/include/carve/exact.hpp index afb491211fd..0d674e66ef7 100644 --- a/extern/carve/include/carve/exact.hpp +++ b/extern/carve/include/carve/exact.hpp @@ -639,9 +639,11 @@ namespace carve { } - // XXX: not implemented yet - //exact_t operator+(const exact_t &a, const exact_t &b) { - //} + exact_t operator+(const exact_t &a, const exact_t &b) { + exact_t r; + sum_zeroelim(a, b, r); + return r; + } diff --git a/extern/carve/include/carve/kd_node.hpp b/extern/carve/include/carve/kd_node.hpp index f62584d50c2..45e0ac85739 100644 --- a/extern/carve/include/carve/kd_node.hpp +++ b/extern/carve/include/carve/kd_node.hpp @@ -230,7 +230,7 @@ namespace carve { } // distance_t must provide: - // double operator()(kd_node::data_t, vector); + // double operator()(data_t, vector); // double operator()(axis_pos, vector); template struct near_point_query { @@ -238,7 +238,7 @@ namespace carve { // q_t - the priority queue value type. // q_t.first: distance from object to query point. // q_t.second: pointer to object - typedef std::pair q_t; + typedef std::pair q_t; // the queue priority should sort from smallest distance to largest, and on equal distance, by object pointer. struct pcmp { @@ -266,7 +266,7 @@ namespace carve { } } - const typename kd_node::data_t *next() { + const data_t *next() { while (1) { if (pq.size()) { q_t t = pq.top(); diff --git a/extern/carve/include/carve/mesh_impl.hpp b/extern/carve/include/carve/mesh_impl.hpp index 23b0a436573..d55df8c8130 100644 --- a/extern/carve/include/carve/mesh_impl.hpp +++ b/extern/carve/include/carve/mesh_impl.hpp @@ -624,8 +624,7 @@ namespace carve { CARVE_ASSERT(e->rev != NULL); e = e->rev->next; CARVE_ASSERT(e->v1() == emin->v1()); - CARVE_ASSERT(e->v1()->v < e->v2()->v); - CARVE_ASSERT(e->v1()->v.x <= e->v2()->v.x); + CARVE_ASSERT(e->v1()->v <= e->v2()->v); } while (e != emin); double max_abs_x = 0.0; diff --git a/extern/carve/include/carve/polyhedron_impl.hpp b/extern/carve/include/carve/polyhedron_impl.hpp index 06d841c7192..de61324140d 100644 --- a/extern/carve/include/carve/polyhedron_impl.hpp +++ b/extern/carve/include/carve/polyhedron_impl.hpp @@ -88,9 +88,9 @@ namespace carve { *(*result)++ = f; int r = 1; - for (size_t i = 0; i < f->edges.size(); ++i) { - const std::vector &edge_faces = connectivity.edge_to_face[edgeToIndex_fast(f->edges[i])]; - const face_t *f2 = connectedFace(f, f->edges[i]); + for (size_t i = 0; i < f->nEdges(); ++i) { + const std::vector &edge_faces = connectivity.edge_to_face[edgeToIndex_fast(f->edge(i))]; + const face_t *f2 = connectedFace(f, f->edge(i)); if (f2) { r += _faceNeighbourhood(f2, depth - 1, (*result)); } @@ -116,7 +116,7 @@ namespace carve { int r = 0; const std::vector &edge_faces = connectivity.edge_to_face[edgeToIndex_fast(e)]; for (size_t i = 0; i < edge_faces.size(); ++i) { - face_t *f = edge_faces[i]; + const face_t *f = edge_faces[i]; if (f && f->manifold_id == m_id) { r += _faceNeighbourhood(f, depth, &result); } } return r; @@ -131,7 +131,7 @@ namespace carve { int r = 0; const std::vector &vertex_faces = connectivity.vertex_to_face[vertexToIndex_fast(v)]; for (size_t i = 0; i < vertex_faces.size(); ++i) { - face_t *f = vertex_faces[i]; + const face_t *f = vertex_faces[i]; if (f && f->manifold_id == m_id) { r += _faceNeighbourhood(f, depth, &result); } } return r; @@ -142,7 +142,7 @@ namespace carve { // accessing connectivity information. template int Geometry<3>::vertexToEdges(const vertex_t *v, T result) const { - std::vector &e = connectivity.vertex_to_edge[vertexToIndex_fast(v)]; + const std::vector &e = connectivity.vertex_to_edge[vertexToIndex_fast(v)]; std::copy(e.begin(), e.end(), result); return e.size(); } diff --git a/extern/carve/patches/strict_flags.patch b/extern/carve/patches/strict_flags.patch index 5e4b867ba26..5c7e8967d39 100644 --- a/extern/carve/patches/strict_flags.patch +++ b/extern/carve/patches/strict_flags.patch @@ -9,30 +9,6 @@ diff -r 47dfdaff1dd5 include/carve/csg_triangulator.hpp } carve::mesh::MeshSet<3>::face_t *mergeQuad(edge_map_t::iterator i, edge_map_t &edge_map) { -diff -r 47dfdaff1dd5 include/carve/exact.hpp ---- a/include/carve/exact.hpp Thu Jan 12 15:49:04 2012 -0500 -+++ b/include/carve/exact.hpp Fri Jan 13 03:13:32 2012 +0600 -@@ -379,7 +379,7 @@ - prod_2_1(b, a, r); - } - -- static inline double prod_4_1(const double *a, const double *b, double *r) { -+ static inline void prod_4_1(const double *a, const double *b, double *r) { - double b_sp[2]; split(b[0], b_sp); - double t1[2]; prod_1_1s(a+0, b, b_sp, t1); - r[0] = t1[0]; -@@ -639,8 +639,9 @@ - } - - -- exact_t operator+(const exact_t &a, const exact_t &b) { -- } -+ // XXX: not implemented yet -+ //exact_t operator+(const exact_t &a, const exact_t &b) { -+ //} - - - diff -r 47dfdaff1dd5 src/selfintersect.cpp --- a/src/selfintersect.cpp Thu Jan 12 15:49:04 2012 -0500 +++ b/src/selfintersect.cpp Fri Jan 13 03:13:32 2012 +0600 From 07ffbbfcb6b4448b147e54eab303a029b10db04e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 12 Mar 2012 21:38:13 +0000 Subject: [PATCH 040/310] better fix for [#30529], find the right axis rather then checking for folded quads. --- source/blender/blenlib/BLI_math_geom.h | 2 +- source/blender/blenlib/intern/math_geom.c | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index a725a3ff4c1..b9f1e9a392a 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -54,7 +54,7 @@ float area_tri_v3(const float a[3], const float b[3], const float c[3]); float area_quad_v3(const float a[3], const float b[3], const float c[3], const float d[3]); float area_poly_v3(int nr, float verts[][3], const float normal[3]); -int is_quad_convex_v3(const float *v1, const float *v2, const float *v3, const float *v4); +int is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]); /********************************* Distance **********************************/ diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index b8cb9790d9e..fab6b7b1066 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -3054,25 +3054,23 @@ float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], fl } /* evaluate if entire quad is a proper convex quad */ - int is_quad_convex_v3(const float *v1, const float *v2, const float *v3, const float *v4) + int is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]) { float nor[3], nor1[3], nor2[3], vec[4][2]; int axis_a, axis_b; /* define projection, do both trias apart, quad is undefined! */ - /* strictly speaking this isn't necessarily convex, - * but when try normals point away from eachother - * we don't wan't to make that face */ - normal_tri_v3(nor1, v2, v3, v4); - normal_tri_v3(nor2, v1, v2, v4); - if (UNLIKELY(dot_v3v3(nor1, nor2) < 0.0f)) { - return FALSE; - } normal_tri_v3(nor1, v1, v2, v3); normal_tri_v3(nor2, v1, v3, v4); + + /* when the face is folded over as 2 tris we probably don't want to create + * a quad from it, but go ahead with the intersection test since this + * isn't a function for degenerate faces */ if (UNLIKELY(dot_v3v3(nor1, nor2) < 0.0f)) { - return FALSE; + /* flip so adding normals in the opposite direction + * doesnt give a zero length vector */ + negate_v3(nor2); } add_v3_v3v3(nor, nor1, nor2); From dfc9a57b3e2b801a5a4a13b1231f08491dc4e0ab Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Mon, 12 Mar 2012 22:52:20 +0000 Subject: [PATCH 041/310] Code cleanup: replace multires update function pointer with direct call. Renamed the multiresModifier_update() function to multires_modifier_update_mdisps() and made it visible to subsurf_ccg.c so it can be called directly. No functional change, just a bit simpler. --- source/blender/blenkernel/BKE_multires.h | 3 +++ source/blender/blenkernel/BKE_subsurf.h | 2 -- source/blender/blenkernel/intern/multires.c | 3 +-- source/blender/blenkernel/intern/subsurf_ccg.c | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h index 34123229863..e966991c35a 100644 --- a/source/blender/blenkernel/BKE_multires.h +++ b/source/blender/blenkernel/BKE_multires.h @@ -48,6 +48,9 @@ void multires_force_update(struct Object *ob); void multires_force_render_update(struct Object *ob); void multires_force_external_reload(struct Object *ob); +/* internal, only called in subsurf_ccg.c */ +void multires_modifier_update_mdisps(struct DerivedMesh *dm); + void multiresModifier_set_levels_from_disps(struct MultiresModifierData *mmd, struct Object *ob); struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*, diff --git a/source/blender/blenkernel/BKE_subsurf.h b/source/blender/blenkernel/BKE_subsurf.h index f3cdd858e7d..7f4ff1bf2e3 100644 --- a/source/blender/blenkernel/BKE_subsurf.h +++ b/source/blender/blenkernel/BKE_subsurf.h @@ -102,8 +102,6 @@ typedef struct CCGDerivedMesh { struct Object *ob; int modified; - - void (*update)(DerivedMesh*); } multires; struct EdgeHash *ehash; diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 06de3cbe5a6..7d50ec6d13a 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -842,7 +842,7 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm } } -static void multiresModifier_update(DerivedMesh *dm) +void multires_modifier_update_mdisps(struct DerivedMesh *dm) { CCGDerivedMesh *ccgdm= (CCGDerivedMesh*)dm; Object *ob; @@ -1109,7 +1109,6 @@ DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, int loca ccgdm->multires.lvl = lvl; ccgdm->multires.totlvl = mmd->totlvl; ccgdm->multires.modified = 0; - ccgdm->multires.update = multiresModifier_update; } numGrids = result->getNumGrids(result); diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 58b39ea8204..dbce2e144f2 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -55,6 +55,7 @@ #include "BKE_global.h" #include "BKE_mesh.h" #include "BKE_modifier.h" +#include "BKE_multires.h" #include "BKE_paint.h" #include "BKE_scene.h" #include "BKE_subsurf.h" @@ -2344,7 +2345,7 @@ static void ccgDM_release(DerivedMesh *dm) if(!ccgdm->multires.local_mmd && BLI_findindex(&ccgdm->multires.ob->modifiers, ccgdm->multires.mmd) < 0) ccgdm->multires.mmd = NULL; if(ccgdm->multires.mmd) - ccgdm->multires.update(dm); + multires_modifier_update_mdisps(dm); } if (ccgdm->ehash) From caac81d75f27c01e4aa0cec3d2814485203613bc Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Mon, 12 Mar 2012 23:03:43 +0000 Subject: [PATCH 042/310] Code cleanup: use explicit PBVH type enum rather than checking for grids or faces. No functional changes, this is just a bit easier to read I think (and nicer if we add more PBVH types in the future, e.g. for dynamic topology sculpting.) --- source/blender/blenlib/BLI_pbvh.h | 8 ++++ source/blender/blenlib/intern/pbvh.c | 65 ++++++++++++++++++---------- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/source/blender/blenlib/BLI_pbvh.h b/source/blender/blenlib/BLI_pbvh.h index f0d56a3cf52..ed763498687 100644 --- a/source/blender/blenlib/BLI_pbvh.h +++ b/source/blender/blenlib/BLI_pbvh.h @@ -89,6 +89,14 @@ int BLI_pbvh_node_planes_contain_AABB(PBVHNode *node, void *data); void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], int (*setMaterial)(int, void *attribs)); +/* PBVH Access */ +typedef enum { + PBVH_FACES, + PBVH_GRIDS, +} PBVHType; + +PBVHType BLI_pbvh_type(const PBVH *bvh); + /* Node Access */ typedef enum { diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index dcf03590808..952a3df7109 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -119,6 +119,8 @@ struct PBVHNode { }; struct PBVH { + PBVHType type; + PBVHNode *nodes; int node_mem_count, totnode; @@ -601,6 +603,7 @@ void BLI_pbvh_build_mesh(PBVH *bvh, MFace *faces, MVert *verts, int totface, int BB cb; int i, j; + bvh->type = PBVH_FACES; bvh->faces = faces; bvh->verts = verts; bvh->vert_bitmap = BLI_BITMAP_NEW(totvert, "bvh->vert_bitmap"); @@ -642,6 +645,7 @@ void BLI_pbvh_build_grids(PBVH *bvh, DMGridData **grids, DMGridAdjacency *gridad BB cb; int i, j; + bvh->type = PBVH_GRIDS; bvh->grids= grids; bvh->gridadj= gridadj; bvh->gridfaces= gridfaces; @@ -996,7 +1000,7 @@ static void pbvh_update_normals(PBVH *bvh, PBVHNode **nodes, float (*vnor)[3]; int n; - if(bvh->grids) + if(bvh->type != PBVH_FACES) return; /* could be per node to save some memory, but also means @@ -1124,20 +1128,22 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode) node= nodes[n]; if(node->flag & PBVH_UpdateDrawBuffers) { - if(bvh->grids) { + switch(bvh->type) { + case PBVH_GRIDS: GPU_update_grid_buffers(node->draw_buffers, bvh->grids, bvh->grid_flag_mats, node->prim_indices, node->totprim, bvh->gridsize); - } - else { + break; + case PBVH_FACES: GPU_update_mesh_buffers(node->draw_buffers, bvh->verts, node->vert_indices, node->uniq_verts + node->face_verts); + break; } node->flag &= ~PBVH_UpdateDrawBuffers; @@ -1271,6 +1277,13 @@ void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *tot *gridfaces= faces; } +/***************************** PBVH Access ***********************************/ + +PBVHType BLI_pbvh_type(const PBVH *bvh) +{ + return bvh->type; +} + /***************************** Node Access ***********************************/ void BLI_pbvh_node_mark_update(PBVHNode *node) @@ -1286,34 +1299,40 @@ void BLI_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node, int **vert_indices, MVer void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node, int *uniquevert, int *totvert) { - if(bvh->grids) { - const int tot= node->totprim*bvh->gridsize*bvh->gridsize; + int tot; + + switch(bvh->type) { + case PBVH_GRIDS: + tot= node->totprim*bvh->gridsize*bvh->gridsize; if(totvert) *totvert= tot; if(uniquevert) *uniquevert= tot; - } - else { + break; + case PBVH_FACES: if(totvert) *totvert= node->uniq_verts + node->face_verts; if(uniquevert) *uniquevert= node->uniq_verts; + break; } } void BLI_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node, int **grid_indices, int *totgrid, int *maxgrid, int *gridsize, DMGridData ***griddata, DMGridAdjacency **gridadj) { - if(bvh->grids) { + switch(bvh->type) { + case PBVH_GRIDS: if(grid_indices) *grid_indices= node->prim_indices; if(totgrid) *totgrid= node->totprim; if(maxgrid) *maxgrid= bvh->totgrid; if(gridsize) *gridsize= bvh->gridsize; if(griddata) *griddata= bvh->grids; if(gridadj) *gridadj= bvh->gridadj; - } - else { + break; + case PBVH_FACES: if(grid_indices) *grid_indices= NULL; if(totgrid) *totgrid= 0; if(maxgrid) *maxgrid= 0; if(gridsize) *gridsize= 0; if(griddata) *griddata= NULL; if(gridadj) *gridadj= NULL; + break; } } @@ -1433,13 +1452,15 @@ static int ray_face_intersection(float ray_start[3], float ray_normal[3], int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], float ray_start[3], float ray_normal[3], float *dist) { - int hit= 0; + MVert *vert; + int *faces, totface, gridsize, totgrid; + int i, x, y, hit= 0; - if(bvh->faces) { - MVert *vert = bvh->verts; - int *faces= node->prim_indices; - int totface= node->totprim; - int i; + switch(bvh->type) { + case PBVH_FACES: + vert = bvh->verts; + faces= node->prim_indices; + totface= node->totprim; for(i = 0; i < totface; ++i) { MFace *f = bvh->faces + faces[i]; @@ -1464,11 +1485,10 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], dist); } } - } - else { - int totgrid= node->totprim; - int gridsize= bvh->gridsize; - int i, x, y; + break; + case PBVH_GRIDS: + totgrid= node->totprim; + gridsize= bvh->gridsize; for(i = 0; i < totgrid; ++i) { DMGridData *grid= bvh->grids[node->prim_indices[i]]; @@ -1499,6 +1519,7 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], if(origco) origco += gridsize*gridsize; } + break; } return hit; From b457c7fdbdf0b8cf7a4535574d9894d8850c55f4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 12 Mar 2012 23:56:11 +0000 Subject: [PATCH 043/310] style cleanup --- source/blender/blenlib/intern/BLI_mempool.c | 2 +- source/blender/blenlib/intern/bpath.c | 2 +- source/blender/bmesh/operators/bmo_create.c | 20 +- source/blender/bmesh/tools/BME_bevel.c | 2 +- source/blender/editors/mesh/knifetool.c | 614 +++++++++--------- .../editors/uvedit/uvedit_smart_stitch.c | 8 +- source/blender/imbuf/intern/targa.c | 8 +- 7 files changed, 333 insertions(+), 323 deletions(-) diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index b8a18b5e376..cbded248589 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -355,7 +355,7 @@ void *BLI_mempool_iterstep(BLI_mempool_iter *iter) do { ret = bli_mempool_iternext(iter); - }while (ret && ret->freeword == FREEWORD); + } while (ret && ret->freeword == FREEWORD); return ret; } diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index bedae13f36e..2134cb59dc6 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -41,7 +41,7 @@ #include #include -/* path/file handeling stuff */ +/* path/file handling stuff */ #ifndef WIN32 # include # include diff --git a/source/blender/bmesh/operators/bmo_create.c b/source/blender/bmesh/operators/bmo_create.c index 2dfd1867379..cb63ad60f17 100644 --- a/source/blender/bmesh/operators/bmo_create.c +++ b/source/blender/bmesh/operators/bmo_create.c @@ -68,7 +68,7 @@ typedef struct EdgeData { typedef struct VertData { BMEdge *e; - float no[3], offco[3], sco[3]; /* offco is vertex coordinate slightly offset randoml */ + float no[3], offco[3], sco[3]; /* offco is vertex coordinate slightly offset randomly */ int tag; } VertData; @@ -234,7 +234,7 @@ static int UNUSED_FUNCTION(rotsys_fill_faces)(BMesh *bm, EdgeData *edata, VertDa continue; } - /* do two passes, going forward then backwar */ + /* do two passes, going forward then backward */ for (i = 0; i < 2; i++) { BLI_smallhash_init(hash); @@ -401,7 +401,7 @@ static void init_rotsys(BMesh *bm, EdgeData *edata, VertData *vdata) normalize_v3(no); } - /* generate plane-flattened coordinate */ + /* generate plane-flattened coordinates */ for (i = 0; i < totedge; i++) { BMEdge *e1; BMVert *v2; @@ -749,7 +749,7 @@ static EPath *edge_find_shortest_path(BMesh *bm, BMOperator *op, BMEdge *edge, E v1 = last->v; if (v1 == endv) { - /* make sure this path loop doesn't already exist */ + /* make sure this path loop doesn't already exists */ i = 0; BLI_array_empty(verts); for (i = 0, node = path->nodes.first; node; node = node->next, i++) { @@ -814,7 +814,7 @@ static EPath *edge_find_shortest_path(BMesh *bm, BMOperator *op, BMEdge *edge, E continue; } - /* add path back into hea */ + /* add path back into heap */ BLI_heap_insert(heap, path->weight, path); /* put v2 in gh ma */ @@ -1343,7 +1343,7 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) /* --- end special case support, continue as normal --- */ /* call edgenet create */ - /* call edgenet prepare op so additional face creation cases wor */ + /* call edgenet prepare op so additional face creation cases wore */ BMO_op_initf(bm, &op2, "edgenet_prepare edges=%fe", ELE_NEW); BMO_op_exec(bm, &op2); BMO_slot_buffer_flag_enable(bm, &op2, "edgeout", ELE_NEW, BM_EDGE); @@ -1352,7 +1352,7 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) BMO_op_initf(bm, &op2, "edgenet_fill edges=%fe use_fill_check=%b", ELE_NEW, TRUE); BMO_op_exec(bm, &op2); - /* return if edge net create did somethin */ + /* return if edge net create did something */ if (BMO_slot_buffer_count(bm, &op2, "faceout")) { BMO_slot_copy(&op2, op, "faceout", "faceout"); BMO_op_finish(bm, &op2); @@ -1374,7 +1374,7 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) BMO_op_finish(bm, &op2); - /* now, count how many verts we hav */ + /* now, count how many verts we have */ amount = 0; BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { if (BMO_elem_flag_test(bm, v, ELE_NEW)) { @@ -1386,12 +1386,12 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) } if (amount == 2) { - /* create edg */ + /* create edge */ e = BM_edge_create(bm, verts[0], verts[1], NULL, TRUE); BMO_elem_flag_enable(bm, e, ELE_OUT); } else if (amount == 3) { - /* create triangl */ + /* create triangle */ f = BM_face_create_quad_tri(bm, verts[0], verts[1], verts[2], NULL, NULL, TRUE); if (f) { diff --git a/source/blender/bmesh/tools/BME_bevel.c b/source/blender/bmesh/tools/BME_bevel.c index 1bed4898166..1422b6516d6 100644 --- a/source/blender/bmesh/tools/BME_bevel.c +++ b/source/blender/bmesh/tools/BME_bevel.c @@ -973,7 +973,7 @@ static BMesh *BME_bevel_mesh(BMesh *bm, float value, int UNUSED(res), int option BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { if(BMO_elem_flag_test(bm, v, BME_BEVEL_ORIG) && BMO_elem_flag_test(bm, v, BME_BEVEL_BEVEL)) { curedge = v->e; - do{ + do { l = curedge->l; l2 = l->radial_next; if(l->v != v) l = l->next; diff --git a/source/blender/editors/mesh/knifetool.c b/source/blender/editors/mesh/knifetool.c index d6eb14fb6e2..f70257614bf 100644 --- a/source/blender/editors/mesh/knifetool.c +++ b/source/blender/editors/mesh/knifetool.c @@ -26,7 +26,6 @@ #define _USE_MATH_DEFINES - #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" @@ -44,7 +43,6 @@ #include "BIF_gl.h" #include "BIF_glutil.h" /* for paint cursor */ - #include "ED_screen.h" #include "ED_space_api.h" #include "ED_view3d.h" @@ -83,7 +81,7 @@ typedef struct KnifeEdge { BMFace *basef; /* face to restrict face fill to */ ListBase faces; int draw; - + BMEdge *e, *oe; /* non-NULL if this is an original edge */ } KnifeEdge; @@ -110,7 +108,7 @@ typedef struct KnifePosData { BMFace *bmface; int is_space; - int mval[2]; /* mouse screen position */ + int mval[2]; /* mouse screen position */ } KnifePosData; /* struct for properties used while drawing */ @@ -119,51 +117,51 @@ typedef struct knifetool_opdata { void *draw_handle; /* for drawing preview loop */ ViewContext vc; bContext *C; - + Object *ob; BMEditMesh *em; - + MemArena *arena; GHash *origvertmap; GHash *origedgemap; - + GHash *kedgefacemap; - + BMBVHTree *bmbvh; BLI_mempool *kverts; BLI_mempool *kedges; - + float vthresh; float ethresh; - + /* used for drag-cutting */ BMEdgeHit *linehits; int totlinehit; - + /* Data for mouse-position-derived data (cur) and previous click (prev) */ KnifePosData cur, prev; int totkedge, totkvert; - + BLI_mempool *refs; - + float projmat[4][4]; int is_ortho; int cut_through; float clipsta, clipend; - + enum { MODE_IDLE, MODE_DRAGGING, MODE_CONNECT, MODE_PANNING } mode; - + int snap_midpoints, prevmode, extend; int ignore_edge_snapping, ignore_vert_snapping; - + enum { ANGLE_FREE, ANGLE_0, @@ -185,7 +183,8 @@ static void knife_project_v3(knifetool_opdata *kcd, const float co[3], float sco ED_view3d_project_float_v3(kcd->ar, co, sco, kcd->projmat); } -static void knife_pos_data_clear(KnifePosData *kpd) { +static void knife_pos_data_clear(KnifePosData *kpd) +{ zero_v3(kpd->co); zero_v3(kpd->cage); kpd->vert = NULL; @@ -273,19 +272,19 @@ static KnifeEdge *get_bm_knife_edge(knifetool_opdata *kcd, BMEdge *e) if (!kfe) { BMIter iter; BMFace *f; - + kfe = new_knife_edge(kcd); kfe->e = e; kfe->v1 = get_bm_knife_vert(kcd, e->v1); kfe->v2 = get_bm_knife_vert(kcd, e->v2); knife_add_to_vert_edges(kcd, kfe); - + BLI_ghash_insert(kcd->origedgemap, e, kfe); - + BM_ITER(f, &iter, kcd->em->bm, BM_FACES_OF_EDGE, e) { knife_append_list(kcd, &kfe->faces, f); - + /* ensures the kedges lst for this f is initialized, * it automatically adds kfe by itself */ knife_get_face_kedges(kcd, f); @@ -328,7 +327,7 @@ static ListBase *knife_get_face_kedges(knifetool_opdata *kcd, BMFace *f) BMEdge *e; lst = knife_empty_list(kcd); - + BM_ITER(e, &iter, kcd->em->bm, BM_EDGES_OF_FACE, f) { knife_append_list(kcd, lst, get_bm_knife_edge(kcd, e)); } @@ -348,7 +347,7 @@ static void knife_find_basef(knifetool_opdata *kcd, KnifeEdge *kfe) if (kfe->v1->isface || kfe->v2->isface) { if (kfe->v2->isface) kfe->basef = kcd->cur.bmface; - else + else kfe->basef = kcd->prev.bmface; } else { @@ -357,12 +356,12 @@ static void knife_find_basef(knifetool_opdata *kcd, KnifeEdge *kfe) for (r2 = ke1->faces.first; r2 && !kfe->basef; r2 = r2->next) { for (r3 = kfe->v2->edges.first; r3 && !kfe->basef; r3 = r3->next) { KnifeEdge *ke2 = r3->ref; - + for (r4 = ke2->faces.first; r4 && !kfe->basef; r4 = r4->next) { if (r2->ref == r4->ref) { kfe->basef = r2->ref; } - } + } } } } @@ -455,7 +454,7 @@ static void knife_add_single_cut(knifetool_opdata *kcd) kfe->v2->draw = !kcd->cur.is_space; kfe->v2->isface = 1; kfe->v2->inspace = kcd->cur.is_space; - + if (kcd->cur.is_space) kfe->draw = 0; @@ -490,13 +489,12 @@ static int verge_linehit(const void *vlh1, const void *vlh2) { const BMEdgeHit *lh1 = vlh1, *lh2 = vlh2; - if (lh1->l < lh2->l) return -1; - else if (lh1->l > lh2->l) return 1; + if (lh1->l < lh2->l) return -1; + else if (lh1->l > lh2->l) return 1; else return 0; } -static void knife_add_single_cut_through(knifetool_opdata *kcd, - KnifeVert *v1, KnifeVert *v2, BMFace *f) +static void knife_add_single_cut_through(knifetool_opdata *kcd, KnifeVert *v1, KnifeVert *v2, BMFace *f) { KnifeEdge *kfenew; @@ -551,7 +549,7 @@ static void knife_cut_through(knifetool_opdata *kcd) BMFace *f; KnifeEdge *kfe, *kfe2, *kfe3; KnifeVert *v1, *v2, *firstv = NULL, *lastv = NULL; - ListBase firstfaces = {NULL, NULL}, lastfaces = { NULL, NULL}; + ListBase firstfaces = {NULL, NULL}, lastfaces = {NULL, NULL}; Ref *r, *r2; KnifeEdge **splitkfe; int i, j, found; @@ -590,7 +588,7 @@ static void knife_cut_through(knifetool_opdata *kcd) if (firstv) { /* For each face incident to firstv, * find the first following linehit (if any) sharing that face and connect */ - for (r = firstfaces.first; r; r = r->next ) { + for (r = firstfaces.first; r; r = r->next) { f = r->ref; found = 0; for (j = 0, lh2 = kcd->linehits; j < kcd->totlinehit; j++, lh2++) { @@ -627,8 +625,8 @@ static void knife_cut_through(knifetool_opdata *kcd) kfe2 = lh2->kfe; for (r2 = kfe2->faces.first; r2; r2 = r2->next) { if (r2->ref == f) { - v1 = splitkfe[i]? kfe->v1 : knife_split_edge(kcd, kfe, lh->hit, &splitkfe[i]); - v2 = splitkfe[j]? kfe2->v1 : knife_split_edge(kcd, kfe2, lh2->hit, &splitkfe[j]); + v1 = splitkfe[i] ? kfe->v1 : knife_split_edge(kcd, kfe, lh->hit, &splitkfe[i]); + v2 = splitkfe[j] ? kfe2->v1 : knife_split_edge(kcd, kfe2, lh2->hit, &splitkfe[j]); knife_add_single_cut_through(kcd, v1, v2, f); found = 1; break; @@ -638,7 +636,7 @@ static void knife_cut_through(knifetool_opdata *kcd) if (!found && lastv) { for (r2 = lastfaces.first; r2; r2 = r2->next) { if (r2->ref == f) { - v1 = splitkfe[i]? kfe->v1 : knife_split_edge(kcd, kfe, lh->hit, &splitkfe[i]); + v1 = splitkfe[i] ? kfe->v1 : knife_split_edge(kcd, kfe, lh->hit, &splitkfe[i]); knife_add_single_cut_through(kcd, v1, lastv, f); break; } @@ -685,7 +683,7 @@ static void knife_add_cut(knifetool_opdata *kcd) else if (lastlh && firstlh) { if (firstlh->v || lastlh->v) { KnifeVert *kfv = firstlh->v ? firstlh->v : lastlh->v; - + kcd->prev.vert = kfv; copy_v3_v3(kcd->prev.co, firstlh->hit); copy_v3_v3(kcd->prev.cage, firstlh->cagehit); @@ -709,7 +707,7 @@ static void knife_add_cut(knifetool_opdata *kcd) kcd->prev.edge = lh->kfe; kcd->prev.bmface = lh->f; continue; - } + } kcd->cur.is_space = 0; kcd->cur.edge = lh->kfe; @@ -844,65 +842,65 @@ static void knifetool_draw_angle_snapping(knifetool_opdata *kcd) static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void *arg) { knifetool_opdata *kcd = arg; - + glDisable(GL_DEPTH_TEST); - + glPolygonOffset(1.0f, 1.0f); - + glPushMatrix(); glMultMatrixf(kcd->ob->obmat); - + if (kcd->mode == MODE_DRAGGING) { if (kcd->angle_snapping != ANGLE_FREE) knifetool_draw_angle_snapping(kcd); glColor3f(0.1, 0.1, 0.1); glLineWidth(2.0); - + glBegin(GL_LINES); glVertex3fv(kcd->prev.cage); glVertex3fv(kcd->cur.cage); glEnd(); - + glLineWidth(1.0); } - + if (kcd->cur.edge) { glColor3f(0.5, 0.3, 0.15); glLineWidth(2.0); - + glBegin(GL_LINES); glVertex3fv(kcd->cur.edge->v1->cageco); glVertex3fv(kcd->cur.edge->v2->cageco); glEnd(); - + glLineWidth(1.0); } else if (kcd->cur.vert) { glColor3f(0.8, 0.2, 0.1); glPointSize(11); - + glBegin(GL_POINTS); glVertex3fv(kcd->cur.cage); glEnd(); } - - if (kcd->cur.bmface) { + + if (kcd->cur.bmface) { glColor3f(0.1, 0.8, 0.05); glPointSize(9); - + glBegin(GL_POINTS); glVertex3fv(kcd->cur.cage); glEnd(); } - + if (kcd->totlinehit > 0) { BMEdgeHit *lh; int i; - + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - + /* draw any snapped verts first */ glColor4f(0.8, 0.2, 0.1, 0.4); glPointSize(11); @@ -910,11 +908,11 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void lh = kcd->linehits; for (i = 0; i < kcd->totlinehit; i++, lh++) { float sv1[3], sv2[3]; - + knife_project_v3(kcd, lh->kfe->v1->cageco, sv1); knife_project_v3(kcd, lh->kfe->v2->cageco, sv2); knife_project_v3(kcd, lh->cagehit, lh->schit); - + if (len_v2v2(lh->schit, sv1) < kcd->vthresh / 4.0f) { copy_v3_v3(lh->cagehit, lh->kfe->v1->cageco); glVertex3fv(lh->cagehit); @@ -927,7 +925,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void } } glEnd(); - + /* now draw the rest */ glColor4f(0.1, 0.8, 0.05, 0.4); glPointSize(7); @@ -939,11 +937,11 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void glEnd(); glDisable(GL_BLEND); } - + if (kcd->totkedge > 0) { BLI_mempool_iter iter; KnifeEdge *kfe; - + glLineWidth(1.0); glBegin(GL_LINES); @@ -951,13 +949,13 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void for (kfe = BLI_mempool_iterstep(&iter); kfe; kfe = BLI_mempool_iterstep(&iter)) { if (!kfe->draw) continue; - + glColor3f(0.2, 0.2, 0.2); - + glVertex3fv(kfe->v1->cageco); glVertex3fv(kfe->v2->cageco); } - + glEnd(); glLineWidth(1.0); } @@ -965,20 +963,20 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void if (kcd->totkvert > 0) { BLI_mempool_iter iter; KnifeVert *kfv; - + glPointSize(5.0); - + glBegin(GL_POINTS); BLI_mempool_iternew(kcd->kverts, &iter); for (kfv = BLI_mempool_iterstep(&iter); kfv; kfv = BLI_mempool_iterstep(&iter)) { if (!kfv->draw) continue; - + glColor3f(0.6, 0.1, 0.2); - + glVertex3fv(kfv->cageco); } - + glEnd(); } @@ -1007,7 +1005,7 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, float cos[9], uv[3], lambda; unsigned int tot = 0; int i, j; - + /* for comparing distances, error of intersection depends on triangle scale. * need to scale down before squaring for accurate comparison */ const float depsilon = 50 * FLT_EPSILON * len_v3_tri_side_max(v1, v2, v3); @@ -1019,31 +1017,31 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, BLI_bvhtree_insert(tree2, 0, cos, 3); BLI_bvhtree_balance(tree2); - + result = results = BLI_bvhtree_overlap(tree, tree2, &tot); - + for (i = 0; i < tot; i++, result++) { float p[3]; - + ls = (BMLoop **)kcd->em->looptris[result->indexA]; - + for (j = 0; j < 3; j++) { BMLoop *l1 = ls[j]; BMFace *hitf; ListBase *lst = knife_get_face_kedges(kcd, l1->f); Ref *ref; - + for (ref = lst->first; ref; ref = ref->next) { KnifeEdge *kfe = ref->ref; - + //if (kfe == kcd->cur.edge || kfe == kcd->prev.edge) // continue; - + if (isect_line_tri_v3(kfe->v1->cageco, kfe->v2->cageco, v1, v2, v3, &lambda, uv)) { float no[3], view[3], sp[3]; - + interp_v3_v3v3(p, kfe->v1->cageco, kfe->v2->cageco, lambda); - + if (kcd->cur.vert && len_squared_v3v3(kcd->cur.vert->cageco, p) < depsilon_squared) continue; if (kcd->prev.vert && len_squared_v3v3(kcd->prev.vert->cageco, p) < depsilon_squared) @@ -1075,28 +1073,28 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, /* ray cast */ hitf = BMBVH_RayCast(bmtree, p, no, NULL, NULL); } - + /* ok, if visible add the new point */ if (!hitf && !BLI_smallhash_haskey(ehash, (intptr_t)kfe)) { BMEdgeHit hit; - if ( len_squared_v3v3(p, kcd->cur.co) < depsilon_squared || - len_squared_v3v3(p, kcd->prev.co) < depsilon_squared) + if (len_squared_v3v3(p, kcd->cur.co) < depsilon_squared || + len_squared_v3v3(p, kcd->prev.co) < depsilon_squared) { continue; } - + hit.kfe = kfe; hit.v = NULL; - + knife_find_basef(kcd, kfe); hit.f = kfe->basef; hit.perc = len_v3v3(p, kfe->v1->cageco) / len_v3v3(kfe->v1->cageco, kfe->v2->cageco); copy_v3_v3(hit.cagehit, p); - + interp_v3_v3v3(p, kfe->v1->co, kfe->v2->co, hit.perc); copy_v3_v3(hit.realhit, p); - + /* BMESH_TODO: should also snap to vertices */ if (kcd->snap_midpoints) { float perc = hit.perc; @@ -1111,7 +1109,7 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, else { perc = 1.0f; } - + interp_v3_v3v3(hit.hit, kfe->v1->co, kfe->v2->co, perc); interp_v3_v3v3(hit.cagehit, kfe->v1->cageco, kfe->v2->cageco, perc); } @@ -1119,7 +1117,7 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, copy_v3_v3(hit.hit, p); } knife_project_v3(kcd, hit.cagehit, hit.schit); - + BLI_array_append(edges, hit); BLI_smallhash_insert(ehash, (intptr_t)kfe, NULL); } @@ -1127,13 +1125,13 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, } } } - + if (results) MEM_freeN(results); - + BLI_bvhtree_free(tree2); *count = BLI_array_count(edges); - + return edges; } @@ -1152,7 +1150,7 @@ static void knife_find_line_hits(knifetool_opdata *kcd) SmallHash hash, *ehash = &hash; float v1[3], v2[3], v3[3], v4[4], s1[3], s2[3]; int i, c1, c2; - + knife_bgl_get_mats(kcd, &mats); if (kcd->linehits) { @@ -1238,33 +1236,32 @@ static void knife_input_ray_cast(knifetool_opdata *kcd, const int mval_i[2], mul_m3_v3(imat, r_ray); } - static BMFace *knife_find_closest_face(knifetool_opdata *kcd, float co[3], float cageco[3], int *is_space) { BMFace *f; int dist = KMAXDIST; float origin[3]; float ray[3]; - + /* unproject to find view ray */ knife_input_ray_cast(kcd, kcd->vc.mval, origin, ray); add_v3_v3v3(co, origin, ray); f = BMBVH_RayCast(kcd->bmbvh, origin, ray, co, cageco); - + if (is_space) *is_space = !f; - + if (!f) { /* try to use backbuffer selection method if ray casting failed */ f = EDBM_findnearestface(&kcd->vc, &dist); - + /* cheat for now; just put in the origin instead * of a true coordinate on the face. * This just puts a point 1.0f infront of the view. */ add_v3_v3v3(co, origin, ray); } - + return f; } @@ -1275,35 +1272,35 @@ static int knife_sample_screen_density(knifetool_opdata *kcd, float radius) BMFace *f; int is_space; float co[3], cageco[3], sco[3]; - + f = knife_find_closest_face(kcd, co, cageco, &is_space); - + if (f && !is_space) { ListBase *lst; Ref *ref; float dis; int c = 0; - + knife_project_v3(kcd, cageco, sco); - + lst = knife_get_face_kedges(kcd, f); for (ref = lst->first; ref; ref = ref->next) { KnifeEdge *kfe = ref->ref; int i; - + for (i = 0; i < 2; i++) { KnifeVert *kfv = i ? kfe->v2 : kfe->v1; - + knife_project_v3(kcd, kfv->cageco, kfv->sco); - + dis = len_v2v2(kfv->sco, sco); if (dis < radius) { if (kcd->vc.rv3d->rflag & RV3D_CLIPPING) { float vec[3]; - + copy_v3_v3(vec, kfv->cageco); mul_m4_v3(kcd->vc.obedit->obmat, vec); - + if (ED_view3d_clipping_test(kcd->vc.rv3d, vec, TRUE) == 0) { c++; } @@ -1314,10 +1311,10 @@ static int knife_sample_screen_density(knifetool_opdata *kcd, float radius) } } } - + return c; } - + return 0; } @@ -1326,9 +1323,9 @@ static int knife_sample_screen_density(knifetool_opdata *kcd, float radius) static float knife_snap_size(knifetool_opdata *kcd, float maxsize) { float density = (float)knife_sample_screen_density(kcd, maxsize * 2.0f); - + density = MAX2(density, 1); - + return MIN2(maxsize / (density * 0.5f), maxsize); } @@ -1337,32 +1334,32 @@ static KnifeEdge *knife_find_closest_edge(knifetool_opdata *kcd, float p[3], flo { BMFace *f; float co[3], cageco[3], sco[3], maxdist = knife_snap_size(kcd, kcd->ethresh); - + if (kcd->ignore_vert_snapping) maxdist *= 0.5; f = knife_find_closest_face(kcd, co, cageco, NULL); *is_space = !f; - + /* set p to co, in case we don't find anything, means a face cut */ copy_v3_v3(p, co); copy_v3_v3(cagep, cageco); - + kcd->cur.bmface = f; - + if (f) { KnifeEdge *cure = NULL; ListBase *lst; Ref *ref; float dis, curdis = FLT_MAX; - + knife_project_v3(kcd, cageco, sco); - + /* look through all edges associated with this face */ lst = knife_get_face_kedges(kcd, f); for (ref = lst->first; ref; ref = ref->next) { KnifeEdge *kfe = ref->ref; - + /* project edge vertices into screen space */ knife_project_v3(kcd, kfe->v1->cageco, kfe->v1->sco); knife_project_v3(kcd, kfe->v2->cageco, kfe->v2->sco); @@ -1372,12 +1369,12 @@ static KnifeEdge *knife_find_closest_edge(knifetool_opdata *kcd, float p[3], flo if (kcd->vc.rv3d->rflag & RV3D_CLIPPING) { float labda = labda_PdistVL2Dfl(sco, kfe->v1->sco, kfe->v2->sco); float vec[3]; - + vec[0] = kfe->v1->cageco[0] + labda * (kfe->v2->cageco[0] - kfe->v1->cageco[0]); vec[1] = kfe->v1->cageco[1] + labda * (kfe->v2->cageco[1] - kfe->v1->cageco[1]); vec[2] = kfe->v1->cageco[2] + labda * (kfe->v2->cageco[2] - kfe->v1->cageco[2]); mul_m4_v3(kcd->vc.obedit->obmat, vec); - + if (ED_view3d_clipping_test(kcd->vc.rv3d, vec, TRUE) == 0) { cure = kfe; curdis = dis; @@ -1389,10 +1386,10 @@ static KnifeEdge *knife_find_closest_edge(knifetool_opdata *kcd, float p[3], flo } } } - + if (fptr) *fptr = f; - + if (cure && p) { if (!kcd->ignore_edge_snapping || !(cure->e)) { if (kcd->snap_midpoints) { @@ -1401,7 +1398,7 @@ static KnifeEdge *knife_find_closest_edge(knifetool_opdata *kcd, float p[3], flo } else { float d; - + closest_to_line_segment_v3(cagep, cageco, cure->v1->cageco, cure->v2->cageco); d = len_v3v3(cagep, cure->v1->cageco) / len_v3v3(cure->v1->cageco, cure->v2->cageco); interp_v3_v3v3(p, cure->v1->co, cure->v2->co, d); @@ -1411,58 +1408,59 @@ static KnifeEdge *knife_find_closest_edge(knifetool_opdata *kcd, float p[3], flo return NULL; } } - + return cure; } - + if (fptr) *fptr = NULL; - + return NULL; } /* find a vertex near the mouse cursor, if it exists */ -static KnifeVert *knife_find_closest_vert(knifetool_opdata *kcd, float p[3], float cagep[3], BMFace **fptr, int *is_space) +static KnifeVert *knife_find_closest_vert(knifetool_opdata *kcd, float p[3], float cagep[3], BMFace **fptr, + int *is_space) { BMFace *f; float co[3], cageco[3], sco[3], maxdist = knife_snap_size(kcd, kcd->vthresh); - + if (kcd->ignore_vert_snapping) maxdist *= 0.5; - + f = knife_find_closest_face(kcd, co, cageco, is_space); - + /* set p to co, in case we don't find anything, means a face cut */ copy_v3_v3(p, co); copy_v3_v3(cagep, p); kcd->cur.bmface = f; - + if (f) { ListBase *lst; Ref *ref; KnifeVert *curv = NULL; float dis, curdis = FLT_MAX; - + knife_project_v3(kcd, cageco, sco); - + lst = knife_get_face_kedges(kcd, f); for (ref = lst->first; ref; ref = ref->next) { KnifeEdge *kfe = ref->ref; int i; - + for (i = 0; i < 2; i++) { KnifeVert *kfv = i ? kfe->v2 : kfe->v1; - + knife_project_v3(kcd, kfv->cageco, kfv->sco); - + dis = len_v2v2(kfv->sco, sco); if (dis < curdis && dis < maxdist) { if (kcd->vc.rv3d->rflag & RV3D_CLIPPING) { float vec[3]; - + copy_v3_v3(vec, kfv->cageco); mul_m4_v3(kcd->vc.obedit->obmat, vec); - + if (ED_view3d_clipping_test(kcd->vc.rv3d, vec, TRUE) == 0) { curv = kfv; curdis = dis; @@ -1475,29 +1473,29 @@ static KnifeVert *knife_find_closest_vert(knifetool_opdata *kcd, float p[3], flo } } } - + if (!kcd->ignore_vert_snapping || !(curv && curv->v)) { if (fptr) *fptr = f; - + if (curv && p) { copy_v3_v3(p, curv->co); copy_v3_v3(cagep, curv->cageco); } - + return curv; } else { if (fptr) *fptr = f; - + return NULL; } } - + if (fptr) *fptr = NULL; - + return NULL; } @@ -1513,7 +1511,7 @@ static void knife_snap_angle(knifetool_opdata *kcd) w = (float)dy / (float)dx; abs_tan = fabsf(w); - if (abs_tan <= 0.4142f) { /* tan(22.5 degrees) = 0.4142 */ + if (abs_tan <= 0.4142f) { /* tan(22.5 degrees) = 0.4142 */ kcd->angle_snapping = ANGLE_0; kcd->vc.mval[1] = kcd->prev.mval[1]; } @@ -1553,12 +1551,12 @@ static int knife_update_active(knifetool_opdata *kcd) * Note that drawing lines in `free-space` isn't properly supported * but theres no guarantee (0,0,0) has any geometry either - campbell */ if (kcd->cur.vert == NULL && kcd->cur.edge == NULL) { - float origin[3], ray[3], co[3]; + float origin[3], ray[3], co[3]; - knife_input_ray_cast(kcd, kcd->vc.mval, origin, ray); - add_v3_v3v3(co, origin, ray); + knife_input_ray_cast(kcd, kcd->vc.mval, origin, ray); + add_v3_v3v3(co, origin, ray); - closest_to_line_v3(kcd->cur.cage, kcd->prev.cage, co, origin); + closest_to_line_v3(kcd->cur.cage, kcd->prev.cage, co, origin); } if (kcd->mode == MODE_DRAGGING) { @@ -1586,7 +1584,7 @@ typedef struct facenet_entry { static void rnd_offset_co(float co[3], float scale) { int i; - + for (i = 0; i < 3; i++) { co[i] += (BLI_drand()-0.5)*scale; } @@ -1604,62 +1602,62 @@ static void remerge_faces(knifetool_opdata *kcd) BLI_array_declare(faces); BMOperator bmop; int idx; - + BMO_op_initf(bm, &bmop, "beautify_fill faces=%ff constrain_edges=%fe", FACE_NEW, BOUNDARY); - + BMO_op_exec(bm, &bmop); BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", FACE_NEW, BM_FACE); - + BMO_op_finish(bm, &bmop); - + BLI_smallhash_init(visit); BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) { BMIter eiter; BMEdge *e; BMFace *f2; - + if (!BMO_elem_flag_test(bm, f, FACE_NEW)) continue; - + if (BLI_smallhash_haskey(visit, (intptr_t)f)) continue; - + BLI_array_empty(stack); BLI_array_empty(faces); BLI_array_append(stack, f); BLI_smallhash_insert(visit, (intptr_t)f, NULL); - + do { f2 = BLI_array_pop(stack); - + BLI_array_append(faces, f2); - + BM_ITER(e, &eiter, bm, BM_EDGES_OF_FACE, f2) { BMIter fiter; BMFace *f3; - + if (BMO_elem_flag_test(bm, e, BOUNDARY)) continue; - + BM_ITER(f3, &fiter, bm, BM_FACES_OF_EDGE, e) { if (!BMO_elem_flag_test(bm, f3, FACE_NEW)) continue; if (BLI_smallhash_haskey(visit, (intptr_t)f3)) continue; - + BLI_smallhash_insert(visit, (intptr_t)f3, NULL); BLI_array_append(stack, f3); } - } + } } while (BLI_array_count(stack) > 0); - + if (BLI_array_count(faces) > 0) { idx = BM_elem_index_get(faces[0]); - + f2 = BM_faces_join(bm, faces, BLI_array_count(faces)); if (f2) { BMO_elem_flag_enable(bm, f2, FACE_NEW); - BM_elem_index_set(f2, idx); /* set_dirty! */ /* BMESH_TODO, check if this is valid or not */ + BM_elem_index_set(f2, idx); /* set_dirty! *//* BMESH_TODO, check if this is valid or not */ } } } @@ -1689,7 +1687,7 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) MemArena *arena = BLI_memarena_new(1 << 16, "knifenet_fill_faces"); SmallHash shash; int i, j, k = 0, totface = bm->totface; - + BMO_push(bm, NULL); bmesh_edit_begin(bm, BMO_OP_FLAG_UNTAN_MULTIRES); @@ -1701,7 +1699,7 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) i++; } bm->elem_index_dirty &= ~BM_FACE; - + BM_ITER(e, &bmiter, bm, BM_EDGES_OF_MESH, NULL) { BMO_elem_flag_enable(bm, e, BOUNDARY); } @@ -1722,9 +1720,9 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) BMO_elem_flag_enable(bm, kfv->v, MARK); } - + /* we want to only do changed faces. first, go over new edges and add to - * face net lists.*/ + * face net lists.*/ i = j = k = 0; BLI_mempool_iternew(kcd->kedges, &iter); for (kfe = BLI_mempool_iterstep(&iter); kfe; kfe = BLI_mempool_iterstep(&iter)) { @@ -1738,9 +1736,9 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) kfe->oe = kfe->e; continue; } - + j++; - + if (kfe->e) { kfe->oe = kfe->e; @@ -1748,37 +1746,37 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) BMO_elem_flag_disable(bm, kfe->e, BOUNDARY); kfe->e = NULL; } - + kfe->e = BM_edge_create(bm, kfe->v1->v, kfe->v2->v, NULL, TRUE); BMO_elem_flag_enable(bm, kfe->e, BOUNDARY); - + for (ref = kfe->faces.first; ref; ref = ref->next) { f = ref->ref; - + entry = BLI_memarena_alloc(arena, sizeof(*entry)); entry->kfe = kfe; BLI_addtail(face_nets + BM_elem_index_get(f), entry); } } - + /* go over original edges, and add to faces with new geometry */ BLI_mempool_iternew(kcd->kedges, &iter); for (kfe = BLI_mempool_iterstep(&iter); kfe; kfe = BLI_mempool_iterstep(&iter)) { Ref *ref; - + if (!kfe->v1 || !kfe->v2 || kfe->v1->inspace || kfe->v2->inspace) continue; if (!(kfe->oe && kfe->v1->v == kfe->oe->v1 && kfe->v2->v == kfe->oe->v2)) continue; - + k++; - + BMO_elem_flag_enable(bm, kfe->e, BOUNDARY); kfe->oe = kfe->e; - + for (ref = kfe->faces.first; ref; ref = ref->next) { f = ref->ref; - + if (face_nets[BM_elem_index_get(f)].first) { entry = BLI_memarena_alloc(arena, sizeof(*entry)); entry->kfe = kfe; @@ -1786,22 +1784,22 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) } } } - + for (i = 0; i < totface; i++) { SmallHash *hash = &shash; ScanFillFace *efa; ScanFillVert *eve, *lasteve; int j; float rndscale = FLT_EPSILON * 25; - + f = faces[i]; BLI_smallhash_init(hash); - + if (face_nets[i].first) BMO_elem_flag_enable(bm, f, DEL); - + BLI_begin_edgefill(); - + for (entry = face_nets[i].first; entry; entry = entry->next) { if (!BLI_smallhash_haskey(hash, (intptr_t)entry->kfe->v1)) { eve = BLI_addfillvert(entry->kfe->v1->v->co); @@ -1817,27 +1815,27 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) rnd_offset_co(eve->co, rndscale); eve->tmp.p = entry->kfe->v2->v; BLI_smallhash_insert(hash, (intptr_t)entry->kfe->v2, eve); - } + } } - + for (j = 0, entry = face_nets[i].first; entry; entry = entry->next, j++) { lasteve = BLI_smallhash_lookup(hash, (intptr_t)entry->kfe->v1); eve = BLI_smallhash_lookup(hash, (intptr_t)entry->kfe->v2); - + eve->poly_nr++; lasteve->poly_nr++; } - + for (j = 0, entry = face_nets[i].first; entry; entry = entry->next, j++) { lasteve = BLI_smallhash_lookup(hash, (intptr_t)entry->kfe->v1); eve = BLI_smallhash_lookup(hash, (intptr_t)entry->kfe->v2); - + if (eve->poly_nr > 1 && lasteve->poly_nr > 1) { ScanFillEdge *eed; eed = BLI_addfilledge(lasteve, eve); if (entry->kfe->oe) - eed->f = FILLBOUNDARY; /* mark as original boundary edge */ - + eed->f = FILLBOUNDARY; /* mark as original boundary edge */ + BMO_elem_flag_disable(bm, entry->kfe->e->v1, DEL); BMO_elem_flag_disable(bm, entry->kfe->e->v2, DEL); } @@ -1848,45 +1846,45 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) BLI_remlink(&fillvertbase, eve); } } - + BLI_edgefill(0); - + for (efa = fillfacebase.first; efa; efa = efa->next) { BMVert *v1 = efa->v3->tmp.p, *v2 = efa->v2->tmp.p, *v3 = efa->v1->tmp.p; BMFace *f2; BMLoop *l_iter; BMVert *verts[3] = {v1, v2, v3}; - + if (v1 == v2 || v2 == v3 || v1 == v3) continue; if (BM_face_exists(bm, verts, 3, &f2)) continue; - + f2 = BM_face_create_quad_tri(bm, - v1, v2, v3, NULL, - NULL, FALSE); + v1, v2, v3, NULL, + NULL, FALSE); BMO_elem_flag_enable(bm, f2, FACE_NEW); - + l_iter = BM_FACE_FIRST_LOOP(f2); do { BMO_elem_flag_disable(bm, l_iter->e, DEL); } while ((l_iter = l_iter->next) != BM_FACE_FIRST_LOOP(f2)); - + BMO_elem_flag_disable(bm, f2, DEL); - BM_elem_index_set(f2, i); /* set_dirty! */ /* note, not 100% sure this is dirty? need to check */ + BM_elem_index_set(f2, i); /* set_dirty! *//* note, not 100% sure this is dirty? need to check */ BM_face_normal_update(bm, f2); if (dot_v3v3(f->no, f2->no) < 0.0f) { BM_face_normal_flip(bm, f2); } } - + BLI_end_edgefill(); BLI_smallhash_release(hash); } bm->elem_index_dirty |= BM_FACE; - + /* interpolate customdata */ BM_ITER(f, &bmiter, bm, BM_FACES_OF_MESH, NULL) { BMLoop *l1; @@ -1895,14 +1893,14 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) if (!BMO_elem_flag_test(bm, f, FACE_NEW)) continue; - + f2 = faces[BM_elem_index_get(f)]; if (BM_elem_index_get(f) < 0 || BM_elem_index_get(f) >= totface) { fprintf(stderr, "%s: face index out of range! (bmesh internal error)\n", __func__); } BM_elem_attrs_copy(bm, bm, f2, f); - + BM_ITER(l1, &liter1, bm, BM_LOOPS_OF_FACE, f) { BM_loop_interp_from_face(bm, l1, f2, TRUE, TRUE); } @@ -1921,7 +1919,7 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) if (faces) MEM_freeN(faces); BLI_memarena_free(arena); - + BMO_error_clear(bm); /* remerge_faces sometimes raises errors, so make sure to clear them */ bmesh_edit_end(bm, BMO_OP_FLAG_UNTAN_MULTIRES); @@ -1931,7 +1929,8 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) #else /* use direct (non-scanfill) method for cuts */ /* assuming v is on line ab, what fraction of the way is v from a to b? */ -static float frac_along(const float a[3], const float b[3], const float v[3]) { +static float frac_along(const float a[3], const float b[3], const float v[3]) +{ float lab; lab = len_v3v3(a, b); @@ -1944,7 +1943,8 @@ static float frac_along(const float a[3], const float b[3], const float v[3]) { } /* sort list of kverts by fraction along edge e */ -static void sort_by_frac_along(ListBase *lst, BMEdge *e) { +static void sort_by_frac_along(ListBase *lst, BMEdge *e) +{ KnifeVert *vcur, *vprev; float *v1co, *v2co; Ref *cur = NULL, *prev = NULL, *next = NULL; @@ -1976,8 +1976,9 @@ static void sort_by_frac_along(ListBase *lst, BMEdge *e) { /* The chain so far goes from an instantiated vertex to kfv (some may be reversed). * If possible, complete the chain to another instantiated vertex and return 1, else return 0. * The visited hash says which KnifeVert's have already been tried, not including kfv. */ -static int find_chain_search(knifetool_opdata *kcd, KnifeVert *kfv, - ListBase *fedges, SmallHash *visited, ListBase *chain) { +static int find_chain_search(knifetool_opdata *kcd, KnifeVert *kfv, ListBase *fedges, SmallHash *visited, + ListBase *chain) +{ Ref *r; KnifeEdge *kfe; KnifeVert *kfv_other; @@ -2007,8 +2008,8 @@ static int find_chain_search(knifetool_opdata *kcd, KnifeVert *kfv, return FALSE; } -static ListBase * find_chain_from_vertex(knifetool_opdata *kcd, KnifeEdge *kfe, - BMVert *v, ListBase *fedges) { +static ListBase * find_chain_from_vertex(knifetool_opdata *kcd, KnifeEdge *kfe, BMVert *v, ListBase *fedges) +{ SmallHash visited_, *visited = &visited_; ListBase *ans; int found; @@ -2037,7 +2038,8 @@ static ListBase * find_chain_from_vertex(knifetool_opdata *kcd, KnifeEdge *kfe, /* Find a chain in fedges from one instantiated vertex to another. * Remove the edges in the chain from fedges and return a separate list of the chain. */ -static ListBase * find_chain(knifetool_opdata *kcd, ListBase *fedges) { +static ListBase * find_chain(knifetool_opdata *kcd, ListBase *fedges) +{ Ref *r, *ref; KnifeEdge *kfe; BMVert *v1, *v2; @@ -2075,8 +2077,9 @@ static ListBase * find_chain(knifetool_opdata *kcd, ListBase *fedges) { /* The hole so far goes from kfvfirst to kfv (some may be reversed). * If possible, complete the hole back to kfvfirst and return 1, else return 0. * The visited hash says which KnifeVert's have already been tried, not including kfv or kfvfirst. */ -static int find_hole_search(knifetool_opdata *kcd, KnifeVert *kfvfirst, KnifeVert *kfv, - ListBase *fedges, SmallHash *visited, ListBase *hole) { +static int find_hole_search(knifetool_opdata *kcd, KnifeVert *kfvfirst, KnifeVert *kfv, ListBase *fedges, + SmallHash *visited, ListBase *hole) +{ Ref *r; KnifeEdge *kfe, *kfelast; KnifeVert *kfv_other; @@ -2109,7 +2112,8 @@ static int find_hole_search(knifetool_opdata *kcd, KnifeVert *kfvfirst, KnifeVer /* Find a hole (simple cycle with no instantiated vertices). * Remove the edges in the cycle from fedges and return a separate list of the cycle */ -static ListBase *find_hole(knifetool_opdata *kcd, ListBase *fedges) { +static ListBase *find_hole(knifetool_opdata *kcd, ListBase *fedges) +{ ListBase *ans; Ref *r, *ref; KnifeEdge *kfe; @@ -2151,8 +2155,9 @@ static ListBase *find_hole(knifetool_opdata *kcd, ListBase *fedges) { * If found, return TRUE and make a 'main chain' going across f which uses * the two diagonals and one part of the hole, and a 'side chain' that * completes the hole. */ -static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, - ListBase **mainchain, ListBase **sidechain) { +static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, ListBase **mainchain, + ListBase **sidechain) +{ float **fco, **hco; BMVert **fv; KnifeVert **hv; @@ -2189,11 +2194,12 @@ static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, he[i] = kfe; if (kfvother == NULL) { kfv = kfe->v1; - } else { + } + else { kfv = kfvother; BLI_assert(kfv == kfe->v1 || kfv == kfe->v2); } - hco[i] = BLI_memarena_alloc(kcd->arena, 2*sizeof(float)); + hco[i] = BLI_memarena_alloc(kcd->arena, 2 * sizeof(float)); hco[i][0] = kfv->co[ax]; hco[i][1] = kfv->co[ay]; hv[i] = kfv; @@ -2203,7 +2209,7 @@ static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, j = 0; BM_ITER(v, &iter, kcd->em->bm, BM_VERTS_OF_FACE, f) { - fco[j] = BLI_memarena_alloc(kcd->arena, 2*sizeof(float)); + fco[j] = BLI_memarena_alloc(kcd->arena, 2 * sizeof(float)); fco[j][0] = v->co[ax]; fco[j][1] = v->co[ay]; fv[j] = v; @@ -2238,17 +2244,17 @@ static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, ok = TRUE; for (k = 0; k < nh && ok; k++) { - if (k == i || (k+1) % nh == i) + if (k == i || (k + 1) % nh == i) continue; - if (isect_line_line_v2(hco[i], fco[j], hco[k], hco[(k+1) % nh])) + if (isect_line_line_v2(hco[i], fco[j], hco[k], hco[(k + 1) % nh])) ok = FALSE; } if (!ok) continue; for (k = 0; k < nf && ok; k++) { - if (k == j || (k+1) % nf == j) + if (k == j || (k + 1) % nf == j) continue; - if (isect_line_line_v2(hco[i], fco[j], fco[k], fco[(k+1) % nf])) + if (isect_line_line_v2(hco[i], fco[j], fco[k], fco[(k + 1) % nf])) ok = FALSE; } if (ok) { @@ -2269,7 +2275,7 @@ static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, kfe->v2 = hv[besti[0]]; chain = knife_empty_list(kcd); knife_append_list(kcd, chain, kfe); - for (i = besti[0]; i != besti[1]; i = (i+1) % nh) { + for (i = besti[0]; i != besti[1]; i = (i + 1) % nh) { knife_append_list(kcd, chain, he[i]); } kfe = new_knife_edge(kcd); @@ -2279,7 +2285,7 @@ static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, *mainchain = chain; chain = knife_empty_list(kcd); - for (i = besti[1]; i != besti[0]; i = (i+1) % nh) { + for (i = besti[1]; i != besti[0]; i = (i + 1) % nh) { knife_append_list(kcd, chain, he[i]); } *sidechain = chain; @@ -2291,7 +2297,8 @@ static int find_hole_chains(knifetool_opdata *kcd, ListBase *hole, BMFace *f, } } -static int knife_edge_in_face(knifetool_opdata *kcd, KnifeEdge *kfe, BMFace *f) { +static int knife_edge_in_face(knifetool_opdata *kcd, KnifeEdge *kfe, BMFace *f) +{ BMesh *bm = kcd->em->bm; BMVert *v1, *v2; BMLoop *l1, *l2, *l; @@ -2333,13 +2340,14 @@ static int knife_edge_in_face(knifetool_opdata *kcd, KnifeEdge *kfe, BMFace *f) /* Split face f with KnifeEdges on chain. f remains as one side, the face formed is put in *newface. * The new face will be on the left side of the chain as viewed from the normal-out side of f. */ -static void knife_make_chain_cut(knifetool_opdata *kcd, BMFace *f, ListBase *chain, BMFace **newface) { +static void knife_make_chain_cut(knifetool_opdata *kcd, BMFace *f, ListBase *chain, BMFace **newface) +{ BMesh *bm = kcd->em->bm; KnifeEdge *kfe, *kfelast; BMVert *v1, *v2; BMFace *fnew; Ref *ref; - KnifeVert *kfv, *kfvprev; + KnifeVert *kfv, *kfvprev; BMLoop *lnew, *l_iter; int i; int nco = BLI_countlist(chain) - 1; @@ -2354,10 +2362,10 @@ static void knife_make_chain_cut(knifetool_opdata *kcd, BMFace *f, ListBase *cha v2 = kfelast->v2->v ? kfelast->v2->v : kfelast->v1->v; BLI_assert(v1 != NULL && v2 != NULL); kfvprev = kfe->v1->v == v1 ? kfe->v1 : kfe->v2; - for (ref = chain->first, i=0; i < nco && ref != chain->last; ref = ref->next, i++) { + for (ref = chain->first, i = 0; i < nco && ref != chain->last; ref = ref->next, i++) { kfe = ref->ref; BLI_assert(kfvprev == kfe->v1 || kfvprev == kfe->v2); - kfv = kfe->v1 == kfvprev? kfe->v2 : kfe->v1; + kfv = kfe->v1 == kfvprev ? kfe->v2 : kfe->v1; copy_v3_v3(cos[i], kfv->co); kverts[i] = kfv; kfvprev = kfv; @@ -2366,7 +2374,8 @@ static void knife_make_chain_cut(knifetool_opdata *kcd, BMFace *f, ListBase *cha lnew = NULL; if (nco == 0) { *newface = BM_face_split(bm, f, v1, v2, &lnew, NULL, TRUE); - } else { + } + else { fnew = BM_face_split_n(bm, f, v1, v2, cos, nco, &lnew, NULL); *newface = fnew; @@ -2383,7 +2392,8 @@ static void knife_make_chain_cut(knifetool_opdata *kcd, BMFace *f, ListBase *cha BLI_array_fixedstack_free(kverts); } -static void knife_make_face_cuts(knifetool_opdata *kcd, BMFace *f, ListBase *kfedges) { +static void knife_make_face_cuts(knifetool_opdata *kcd, BMFace *f, ListBase *kfedges) +{ BMesh *bm = kcd->em->bm; KnifeEdge *kfe; BMFace *fnew, *fnew2, *fhole; @@ -2524,7 +2534,7 @@ static void knife_make_cuts(knifetool_opdata *kcd) BLI_mempool_iternew(kcd->kverts, &iter); for (kfv = BLI_mempool_iterstep(&iter); kfv; kfv = BLI_mempool_iterstep(&iter)) { if (kfv->v) - continue; /* already have a BMVert */ + continue; /* already have a BMVert */ for (ref = kfv->edges.first; ref; ref = ref->next) { kfe = ref->ref; e = kfe->e; @@ -2567,15 +2577,15 @@ static void knife_make_cuts(knifetool_opdata *kcd) static void knifetool_finish(bContext *C, wmOperator *op) { knifetool_opdata *kcd = op->customdata; - + #if SCANFILL_CUTS knifenet_fill_faces(kcd); #else knife_make_cuts(kcd); #endif - + DAG_id_tag_update(kcd->ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, kcd->ob->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, kcd->ob->data); } /* copied from paint_image.c */ @@ -2595,29 +2605,29 @@ static int project_knife_view_clip(View3D *v3d, RegionView3D *rv3d, float *clips static void knife_recalc_projmat(knifetool_opdata *kcd) { ARegion *ar = CTX_wm_region(kcd->C); - + if (!ar) return; - + invert_m4_m4(kcd->ob->imat, kcd->ob->obmat); ED_view3d_ob_project_mat_get(ar->regiondata, kcd->ob, kcd->projmat); //mult_m4_m4m4(kcd->projmat, kcd->vc.rv3d->winmat, kcd->vc.rv3d->viewmat); - + kcd->is_ortho = project_knife_view_clip(kcd->vc.v3d, kcd->vc.rv3d, &kcd->clipsta, &kcd->clipend); } /* called when modal loop selection is done... */ -static void knifetool_exit (bContext *UNUSED(C), wmOperator *op) +static void knifetool_exit(bContext *UNUSED(C), wmOperator *op) { knifetool_opdata *kcd = op->customdata; - + if (!kcd) return; - + /* deactivate the extra drawing stuff in 3D-View */ ED_region_draw_cb_exit(kcd->ar->type, kcd->draw_handle); - + /* free the custom data */ BLI_mempool_destroy(kcd->refs); BLI_mempool_destroy(kcd->kverts); @@ -2626,10 +2636,10 @@ static void knifetool_exit (bContext *UNUSED(C), wmOperator *op) BLI_ghash_free(kcd->origedgemap, NULL, NULL); BLI_ghash_free(kcd->origvertmap, NULL, NULL); BLI_ghash_free(kcd->kedgefacemap, NULL, NULL); - + BMBVH_FreeBVH(kcd->bmbvh); BLI_memarena_free(kcd->arena); - + /* tag for redraw */ ED_region_tag_redraw(kcd->ar); @@ -2641,14 +2651,13 @@ static void knifetool_exit (bContext *UNUSED(C), wmOperator *op) op->customdata = NULL; } -static void cage_mapped_verts_callback(void *userData, int index, float *co, - float *UNUSED(no_f), short *UNUSED(no_s)) +static void cage_mapped_verts_callback(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { void **data = userData; BMEditMesh *em = data[0]; float (*cagecos)[3] = data[1]; SmallHash *hash = data[2]; - + if (index >= 0 && index < em->bm->totvert && !BLI_smallhash_haskey(hash, index)) { BLI_smallhash_insert(hash, index, NULL); copy_v3_v3(cagecos[index], co); @@ -2664,10 +2673,10 @@ static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut)) DerivedMesh *cage, *final; SmallHash shash; void *data[3]; - + /* alloc new customdata */ kcd = op->customdata = MEM_callocN(sizeof(knifetool_opdata), "knifetool Modal Op Data"); - + /* assign the drawing handle for drawing preview line... */ kcd->ob = obedit; kcd->ar = CTX_wm_region(C); @@ -2684,26 +2693,26 @@ static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut)) data[0] = kcd->em; data[1] = kcd->cagecos; data[2] = &shash; - + BLI_smallhash_init(&shash); cage->foreachMappedVert(cage, cage_mapped_verts_callback, data); BLI_smallhash_release(&shash); - - kcd->bmbvh = BMBVH_NewBVH(kcd->em, BMBVH_USE_CAGE|BMBVH_RETURN_ORIG, scene, obedit); + + kcd->bmbvh = BMBVH_NewBVH(kcd->em, BMBVH_USE_CAGE | BMBVH_RETURN_ORIG, scene, obedit); kcd->arena = BLI_memarena_new(1 << 15, "knife"); kcd->vthresh = KMAXDIST - 1; kcd->ethresh = KMAXDIST; - + kcd->extend = 1; - + knife_recalc_projmat(kcd); - + ED_region_tag_redraw(kcd->ar); - + kcd->refs = BLI_mempool_create(sizeof(Ref), 1, 2048, 0); kcd->kverts = BLI_mempool_create(sizeof(KnifeVert), 1, 512, BLI_MEMPOOL_ALLOW_ITER); kcd->kedges = BLI_mempool_create(sizeof(KnifeEdge), 1, 512, BLI_MEMPOOL_ALLOW_ITER); - + kcd->origedgemap = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "knife origedgemap"); kcd->origvertmap = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "knife origvertmap"); kcd->kedgefacemap = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "knife origvertmap"); @@ -2717,14 +2726,14 @@ static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut)) return 1; } -static int knifetool_cancel (bContext *C, wmOperator *op) +static int knifetool_cancel(bContext *C, wmOperator *op) { /* this is just a wrapper around exit() */ knifetool_exit(C, op); return OPERATOR_CANCELLED; } -static int knifetool_invoke (bContext *C, wmOperator *op, wmEvent *evt) +static int knifetool_invoke(bContext *C, wmOperator *op, wmEvent *evt) { knifetool_opdata *kcd; @@ -2732,14 +2741,14 @@ static int knifetool_invoke (bContext *C, wmOperator *op, wmEvent *evt) if (!knifetool_init(C, op, 0)) return OPERATOR_CANCELLED; - + /* add a modal handler for this operator - handles loop selection */ WM_event_add_modal_handler(C, op); kcd = op->customdata; kcd->vc.mval[0] = evt->mval[0]; kcd->vc.mval[1] = evt->mval[1]; - + return OPERATOR_RUNNING_MODAL; } @@ -2758,27 +2767,28 @@ enum { wmKeyMap *knifetool_modal_keymap(wmKeyConfig *keyconf) { static EnumPropertyItem modal_items[] = { - {KNF_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""}, - {KNF_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""}, - {KNF_MODAL_MIDPOINT_ON, "SNAP_MIDPOINTS_ON", 0, "Snap To Midpoints On", ""}, - {KNF_MODAL_MIDPOINT_OFF, "SNAP_MIDPOINTS_OFF", 0, "Snap To Midpoints Off", ""}, - {KNF_MODEL_IGNORE_SNAP_ON, "IGNORE_SNAP_ON", 0, "Ignore Snapping On", ""}, - {KNF_MODEL_IGNORE_SNAP_OFF, "IGNORE_SNAP_OFF", 0, "Ignore Snapping Off", ""}, - {KNF_MODAL_ANGLE_SNAP_TOGGLE, "ANGLE_SNAP_TOGGLE", 0, "Toggle Angle Snapping", ""}, - {KNF_MODAL_NEW_CUT, "NEW_CUT", 0, "End Current Cut", ""}, - {KNF_MODAL_ADD_CUT, "ADD_CUT", 0, "Add Cut", ""}, + {KNF_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""}, + {KNF_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""}, + {KNF_MODAL_MIDPOINT_ON, "SNAP_MIDPOINTS_ON", 0, "Snap To Midpoints On", ""}, + {KNF_MODAL_MIDPOINT_OFF, "SNAP_MIDPOINTS_OFF", 0, "Snap To Midpoints Off", ""}, + {KNF_MODEL_IGNORE_SNAP_ON, "IGNORE_SNAP_ON", 0, "Ignore Snapping On", ""}, + {KNF_MODEL_IGNORE_SNAP_OFF, "IGNORE_SNAP_OFF", 0, "Ignore Snapping Off", ""}, + {KNF_MODAL_ANGLE_SNAP_TOGGLE, "ANGLE_SNAP_TOGGLE", 0, "Toggle Angle Snapping", ""}, + {KNF_MODAL_NEW_CUT, "NEW_CUT", 0, "End Current Cut", ""}, + {KNF_MODAL_ADD_CUT, "ADD_CUT", 0, "Add Cut", ""}, {0, NULL, 0, NULL, NULL}}; - + wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "Knife Tool Modal Map"); - + /* this function is called for each spacetype, only needs to add map once */ - if (keymap) return NULL; - + if (keymap) + return NULL; + keymap = WM_modalkeymap_add(keyconf, "Knife Tool Modal Map", modal_items); - + /* items for modal map */ - WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, KNF_MODAL_CANCEL); + WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, KNF_MODAL_CANCEL); WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, KNF_MODAL_ADD_CUT); WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_PRESS, KM_ANY, 0, KNF_MODAL_CONFIRM); WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, KNF_MODAL_CONFIRM); @@ -2794,23 +2804,23 @@ wmKeyMap *knifetool_modal_keymap(wmKeyConfig *keyconf) WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, KNF_MODEL_IGNORE_SNAP_OFF); WM_modalkeymap_add_item(keymap, RIGHTSHIFTKEY, KM_PRESS, KM_ANY, 0, KNF_MODEL_IGNORE_SNAP_ON); WM_modalkeymap_add_item(keymap, RIGHTSHIFTKEY, KM_RELEASE, KM_ANY, 0, KNF_MODEL_IGNORE_SNAP_OFF); - + WM_modalkeymap_add_item(keymap, CKEY, KM_PRESS, 0, 0, KNF_MODAL_ANGLE_SNAP_TOGGLE); WM_modalkeymap_assign(keymap, "MESH_OT_knifetool"); - + return keymap; } -static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event) +static int knifetool_modal(bContext *C, wmOperator *op, wmEvent *event) { Object *obedit; knifetool_opdata *kcd = op->customdata; - + if (!C) { return OPERATOR_FINISHED; } - + obedit = CTX_data_edit_object(C); if (!obedit || obedit->type != OB_MESH || BMEdit_FromObject(obedit) != kcd->em) { knifetool_exit(C, op); @@ -2818,27 +2828,27 @@ static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event) } view3d_operator_needs_opengl(C); - + if (kcd->mode == MODE_PANNING) kcd->mode = kcd->prevmode; - + /* handle modal keymap */ if (event->type == EVT_MODAL_MAP) { switch (event->val) { case KNF_MODAL_CANCEL: /* finish */ ED_region_tag_redraw(kcd->ar); - + knifetool_exit(C, op); - + return OPERATOR_CANCELLED; case KNF_MODAL_CONFIRM: /* finish */ ED_region_tag_redraw(kcd->ar); - + knifetool_finish(C, op); knifetool_exit(C, op); - + return OPERATOR_FINISHED; case KNF_MODAL_MIDPOINT_ON: kcd->snap_midpoints = 1; @@ -2884,10 +2894,10 @@ static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event) knife_start_cut(kcd); kcd->mode = MODE_DRAGGING; } - + ED_region_tag_redraw(kcd->ar); break; - } + } } else { /* non-modal-mapped events */ switch (event->type) { @@ -2903,41 +2913,41 @@ static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event) else { kcd->mode = kcd->prevmode; } - + ED_region_tag_redraw(kcd->ar); return OPERATOR_PASS_THROUGH; - - case MOUSEMOVE: /* mouse moved somewhere to select another loop */ + + case MOUSEMOVE: /* mouse moved somewhere to select another loop */ if (kcd->mode != MODE_PANNING) { knife_recalc_projmat(kcd); kcd->vc.mval[0] = event->mval[0]; kcd->vc.mval[1] = event->mval[1]; - - if (knife_update_active(kcd)) + + if (knife_update_active(kcd)) ED_region_tag_redraw(kcd->ar); } - + break; } } - + /* keep going until the user confirms */ return OPERATOR_RUNNING_MODAL; } -void MESH_OT_knifetool (wmOperatorType *ot) +void MESH_OT_knifetool(wmOperatorType *ot) { /* description */ ot->name = "Knife Topology Tool"; ot->idname = "MESH_OT_knifetool"; ot->description = "Cut new topology"; - + /* callbacks */ ot->invoke = knifetool_invoke; ot->modal = knifetool_modal; ot->cancel = knifetool_cancel; ot->poll = ED_operator_editmesh_view3d; - + /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; } diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c index 676701b9c2a..64c15f6f496 100644 --- a/source/blender/editors/uvedit/uvedit_smart_stitch.c +++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c @@ -527,10 +527,10 @@ static void stitch_setup_face_preview_for_uv_group(UvElement *element, StitchSta island_stitch_data[element->island].addedForPreview = 1; } - do{ + do { stitch_set_face_preview_buffer_position(element->face, preview, preview_position); element = element->next; - }while(element && !element->separate); + } while(element && !element->separate); } @@ -835,7 +835,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) if(element->flag & STITCH_STITCHABLE){ UvElement *element_iter = element; /* propagate to coincident uvs */ - do{ + do { BMLoop *l; MLoopUV *luv; @@ -862,7 +862,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) } element_iter = element_iter->next; - }while(element_iter && !element_iter->separate); + } while(element_iter && !element_iter->separate); } } diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c index 895f922a0da..b5552a174a9 100644 --- a/source/blender/imbuf/intern/targa.c +++ b/source/blender/imbuf/intern/targa.c @@ -128,7 +128,7 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI copy = last^this; while (bytes > 0){ if (copy){ - do{ + do { last = this; this = *rect++; if (last == this){ @@ -137,7 +137,7 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI break; } } - }while (--bytes != 0); + } while (--bytes != 0); copy = rect-rectstart; copy --; @@ -151,9 +151,9 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI if (copy>=128) last = 128; copy -= last; if (fputc(last-1,file) == EOF) return(0); - do{ + do { if (out(*rect++,file) == EOF) return(0); - }while(--last != 0); + } while(--last != 0); } rectstart = rect; rect = temp; From 8646bb446419592f8acc8ed0cdf8337bfc4a07eb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Mar 2012 01:11:08 +0000 Subject: [PATCH 044/310] workaround [#30480] Knife tool flicker the problem was numeric precision when in ortho mode the start/end points for the view vector would be 2000 apart which caused trouble for the intersection test. --- source/blender/blenlib/BLI_math_geom.h | 1 + source/blender/blenlib/intern/math_geom.c | 19 +++++++++++++++++++ source/blender/editors/mesh/bmesh_tools.c | 5 ++--- source/blender/editors/mesh/knifetool.c | 10 ++++++++++ .../python/mathutils/mathutils_Quaternion.c | 2 +- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index b9f1e9a392a..9b5e3638609 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -73,6 +73,7 @@ void closest_to_plane_v3(float r[3], const float plane_co[3], const float plane float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3]); float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2]); +void limit_dist_v3(float v1[3], float v2[3], const float dist); /******************************* Intersection ********************************/ diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index fab6b7b1066..f491ea25075 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -1320,6 +1320,25 @@ float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2 return(dot_v2v2(u, h)/dot_v2v2(u, u)); } +/* ensyre the distance between these points is no greater then 'dist' + * if it is, scale then both into the center */ +void limit_dist_v3(float v1[3], float v2[3], const float dist) +{ + const float dist_old = len_v3v3(v1, v2); + + if (dist_old > dist) { + float v1_old[3]; + float v2_old[3]; + float fac = (dist / dist_old) * 0.5f; + + copy_v3_v3(v1_old, v1); + copy_v3_v3(v2_old, v2); + + interp_v3_v3v3(v1, v1_old, v2_old, 0.5f - fac); + interp_v3_v3v3(v2, v1_old, v2_old, 0.5f + fac); + } +} + /* Similar to LineIntersectsTriangleUV, except it operates on a quad and in 2d, assumes point is in quad */ void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2[2], const float v3[2], const float pt[2], float r_uv[2]) { diff --git a/source/blender/editors/mesh/bmesh_tools.c b/source/blender/editors/mesh/bmesh_tools.c index bbfbb16a5bb..7fd82be7571 100644 --- a/source/blender/editors/mesh/bmesh_tools.c +++ b/source/blender/editors/mesh/bmesh_tools.c @@ -4447,7 +4447,7 @@ static int mesh_bevel_exec(bContext *C, wmOperator *op) BMIter iter; BMEdge *eed; BMOperator bmop; - float factor = RNA_float_get(op->ptr, "percent"), fac = factor /*, dfac */ /* UNUSED */, df, s; + float factor = RNA_float_get(op->ptr, "percent"), /*, dfac */ /* UNUSED */, df, s; int i, recursion = RNA_int_get(op->ptr, "recursion"); const int use_even = RNA_boolean_get(op->ptr, "use_even"); const int use_dist = RNA_boolean_get(op->ptr, "use_dist"); @@ -4484,9 +4484,8 @@ static int mesh_bevel_exec(bContext *C, wmOperator *op) mul_vn_fl(w, recursion, 1.0f / (float)ftot); - fac = factor; for (i = 0; i < recursion; i++) { - fac = w[recursion - i - 1] * factor; + float fac = w[recursion - i - 1] * factor; if (!EDBM_InitOpf(em, &bmop, op, "bevel geom=%hev percent=%f lengthlayer=%i use_lengths=%b use_even=%b use_dist=%b", diff --git a/source/blender/editors/mesh/knifetool.c b/source/blender/editors/mesh/knifetool.c index f70257614bf..1866b88a1bf 100644 --- a/source/blender/editors/mesh/knifetool.c +++ b/source/blender/editors/mesh/knifetool.c @@ -1178,6 +1178,16 @@ static void knife_find_line_hits(knifetool_opdata *kcd) mul_m4_v3(kcd->ob->imat, v3); mul_m4_v3(kcd->ob->imat, v4); + /* numeric error, 'v1' -> 'v2', 'v2' -> 'v4' can end up being ~2000 units apart in otho mode + * (from ED_view3d_win_to_segment_clip() above) + * this gives precision error in 'knife_edge_tri_isect', rather then solving properly + * (which may involve using doubles everywhere!), + * limit the distance between these points */ + if (kcd->is_ortho) { + limit_dist_v3(v1, v3, 200.0f); + limit_dist_v3(v2, v4, 200.0f); + } + BLI_smallhash_init(ehash); /* test two triangles of sceen line's plane */ diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c index b3767d2b8bb..96beccea5d3 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.c +++ b/source/blender/python/mathutils/mathutils_Quaternion.c @@ -1101,7 +1101,7 @@ static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObjec } } -/* axis vector suffers from precission errors, use this function to ensure */ +/* axis vector suffers from precision errors, use this function to ensure */ static void quat__axis_angle_sanitize(float axis[3], float *angle) { if (axis) { From a97825dfd71994dde7748ed38f5ce91e16df06ae Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Mar 2012 01:55:25 +0000 Subject: [PATCH 045/310] stule cleanup for rct.c and fix for error in last commit. --- source/blender/blenlib/intern/rct.c | 140 ++++++++++------------ source/blender/editors/mesh/bmesh_tools.c | 2 +- 2 files changed, 66 insertions(+), 76 deletions(-) diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index 3b9fd2e07f6..d3bb5a1b17f 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -1,12 +1,4 @@ /* - * - * rct.c - * - * april 95 - * - * - * A minimalist lib for functions doing stuff with rectangle structs. - * * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or @@ -36,6 +28,8 @@ /** \file blender/blenlib/intern/rct.c * \ingroup bli + * + * A minimalist lib for functions doing stuff with rectangle structs. */ #include @@ -46,91 +40,85 @@ int BLI_rcti_is_empty(rcti * rect) { - return ((rect->xmax<=rect->xmin) || - (rect->ymax<=rect->ymin)); + return ((rect->xmax <= rect->xmin) || (rect->ymax <= rect->ymin)); } int BLI_rctf_is_empty(rctf * rect) { - return ((rect->xmax<=rect->xmin) || - (rect->ymax<=rect->ymin)); + return ((rect->xmax <= rect->xmin) || (rect->ymax <= rect->ymin)); } int BLI_in_rcti(rcti * rect, int x, int y) { - - if(xxmin) return 0; - if(x>rect->xmax) return 0; - if(yymin) return 0; - if(y>rect->ymax) return 0; + if (x < rect->xmin) return 0; + if (x > rect->xmax) return 0; + if (y < rect->ymin) return 0; + if (y > rect->ymax) return 0; return 1; } int BLI_in_rctf(rctf *rect, float x, float y) { - - if(xxmin) return 0; - if(x>rect->xmax) return 0; - if(yymin) return 0; - if(y>rect->ymax) return 0; + if (x < rect->xmin) return 0; + if (x > rect->xmax) return 0; + if (y < rect->ymin) return 0; + if (y > rect->ymax) return 0; return 1; } void BLI_union_rctf(rctf *rct1, rctf *rct2) { - - if(rct1->xmin>rct2->xmin) rct1->xmin= rct2->xmin; - if(rct1->xmaxxmax) rct1->xmax= rct2->xmax; - if(rct1->ymin>rct2->ymin) rct1->ymin= rct2->ymin; - if(rct1->ymaxymax) rct1->ymax= rct2->ymax; + if (rct1->xmin > rct2->xmin) rct1->xmin = rct2->xmin; + if (rct1->xmax < rct2->xmax) rct1->xmax = rct2->xmax; + if (rct1->ymin > rct2->ymin) rct1->ymin = rct2->ymin; + if (rct1->ymax < rct2->ymax) rct1->ymax = rct2->ymax; } void BLI_union_rcti(rcti *rct1, rcti *rct2) { - - if(rct1->xmin>rct2->xmin) rct1->xmin= rct2->xmin; - if(rct1->xmaxxmax) rct1->xmax= rct2->xmax; - if(rct1->ymin>rct2->ymin) rct1->ymin= rct2->ymin; - if(rct1->ymaxymax) rct1->ymax= rct2->ymax; + if (rct1->xmin > rct2->xmin) rct1->xmin = rct2->xmin; + if (rct1->xmax < rct2->xmax) rct1->xmax = rct2->xmax; + if (rct1->ymin > rct2->ymin) rct1->ymin = rct2->ymin; + if (rct1->ymax < rct2->ymax) rct1->ymax = rct2->ymax; } void BLI_init_rctf(rctf *rect, float xmin, float xmax, float ymin, float ymax) { - if(xmin <= xmax) { - rect->xmin= xmin; - rect->xmax= xmax; + if (xmin <= xmax) { + rect->xmin = xmin; + rect->xmax = xmax; } else { - rect->xmax= xmin; - rect->xmin= xmax; + rect->xmax = xmin; + rect->xmin = xmax; } - if(ymin <= ymax) { - rect->ymin= ymin; - rect->ymax= ymax; + if (ymin <= ymax) { + rect->ymin = ymin; + rect->ymax = ymax; } else { - rect->ymax= ymin; - rect->ymin= ymax; + rect->ymax = ymin; + rect->ymin = ymax; } } void BLI_init_rcti(rcti *rect, int xmin, int xmax, int ymin, int ymax) { - if(xmin <= xmax) { - rect->xmin= xmin; - rect->xmax= xmax; + if (xmin <= xmax) { + rect->xmin = xmin; + rect->xmax = xmax; } else { - rect->xmax= xmin; - rect->xmin= xmax; + rect->xmax = xmin; + rect->xmin = xmax; } - if(ymin <= ymax) { - rect->ymin= ymin; - rect->ymax= ymax; + if (ymin <= ymax) { + rect->ymin = ymin; + rect->ymax = ymax; } else { - rect->ymax= ymin; - rect->ymin= ymax; + rect->ymax = ymin; + rect->ymin = ymax; } } @@ -152,22 +140,22 @@ void BLI_translate_rctf(rctf *rect, float x, float y) /* change width & height around the central location */ void BLI_resize_rcti(rcti *rect, int x, int y) { - rect->xmin= rect->xmax= (rect->xmax + rect->xmin) / 2; - rect->ymin= rect->ymax= (rect->ymax + rect->ymin) / 2; + rect->xmin = rect->xmax = (rect->xmax + rect->xmin) / 2; + rect->ymin = rect->ymax = (rect->ymax + rect->ymin) / 2; rect->xmin -= x / 2; rect->ymin -= y / 2; - rect->xmax= rect->xmin + x; - rect->ymax= rect->ymin + y; + rect->xmax = rect->xmin + x; + rect->ymax = rect->ymin + y; } void BLI_resize_rctf(rctf *rect, float x, float y) { - rect->xmin= rect->xmax= (rect->xmax + rect->xmin) * 0.5f; - rect->ymin= rect->ymax= (rect->ymax + rect->ymin) * 0.5f; + rect->xmin = rect->xmax = (rect->xmax + rect->xmin) * 0.5f; + rect->ymin = rect->ymax = (rect->ymax + rect->ymin) * 0.5f; rect->xmin -= x * 0.5f; rect->ymin -= y * 0.5f; - rect->xmax= rect->xmin + x; - rect->ymax= rect->ymin + y; + rect->xmax = rect->xmin + x; + rect->ymax = rect->ymin + y; } int BLI_isect_rctf(rctf *src1, rctf *src2, rctf *dest) @@ -179,9 +167,9 @@ int BLI_isect_rctf(rctf *src1, rctf *src2, rctf *dest) xmax = (src1->xmax) < (src2->xmax) ? (src1->xmax) : (src2->xmax); ymin = (src1->ymin) > (src2->ymin) ? (src1->ymin) : (src2->ymin); ymax = (src1->ymax) < (src2->ymax) ? (src1->ymax) : (src2->ymax); - - if(xmax>=xmin && ymax>=ymin) { - if(dest) { + + if (xmax >= xmin && ymax >= ymin) { + if (dest) { dest->xmin = xmin; dest->xmax = xmax; dest->ymin = ymin; @@ -190,7 +178,7 @@ int BLI_isect_rctf(rctf *src1, rctf *src2, rctf *dest) return 1; } else { - if(dest) { + if (dest) { dest->xmin = 0; dest->xmax = 0; dest->ymin = 0; @@ -204,14 +192,14 @@ int BLI_isect_rcti(rcti *src1, rcti *src2, rcti *dest) { int xmin, xmax; int ymin, ymax; - + xmin = (src1->xmin) > (src2->xmin) ? (src1->xmin) : (src2->xmin); xmax = (src1->xmax) < (src2->xmax) ? (src1->xmax) : (src2->xmax); ymin = (src1->ymin) > (src2->ymin) ? (src1->ymin) : (src2->ymin); ymax = (src1->ymax) < (src2->ymax) ? (src1->ymax) : (src2->ymax); - - if(xmax>=xmin && ymax>=ymin) { - if(dest) { + + if (xmax >= xmin && ymax >= ymin) { + if (dest) { dest->xmin = xmin; dest->xmax = xmax; dest->ymin = ymin; @@ -220,7 +208,7 @@ int BLI_isect_rcti(rcti *src1, rcti *src2, rcti *dest) return 1; } else { - if(dest) { + if (dest) { dest->xmin = 0; dest->xmax = 0; dest->ymin = 0; @@ -232,18 +220,20 @@ int BLI_isect_rcti(rcti *src1, rcti *src2, rcti *dest) void BLI_copy_rcti_rctf(rcti *tar, const rctf *src) { - tar->xmin= floor(src->xmin + 0.5f); - tar->xmax= floor((src->xmax - src->xmin) + 0.5f); - tar->ymin= floor(src->ymin + 0.5f); - tar->ymax= floor((src->ymax - src->ymin) + 0.5f); + tar->xmin = floor(src->xmin + 0.5f); + tar->xmax = floor((src->xmax - src->xmin) + 0.5f); + tar->ymin = floor(src->ymin + 0.5f); + tar->ymax = floor((src->ymax - src->ymin) + 0.5f); } void print_rctf(const char *str, rctf *rect) { - printf("%s: xmin %.3f, xmax %.3f, ymin %.3f, ymax %.3f (%.3fx%.3f)\n", str, rect->xmin, rect->xmax, rect->ymin, rect->ymax, rect->xmax - rect->xmin, rect->ymax - rect->ymin); + printf("%s: xmin %.3f, xmax %.3f, ymin %.3f, ymax %.3f (%.3fx%.3f)\n", str, + rect->xmin, rect->xmax, rect->ymin, rect->ymax, rect->xmax - rect->xmin, rect->ymax - rect->ymin); } void print_rcti(const char *str, rcti *rect) { - printf("%s: xmin %d, xmax %d, ymin %d, ymax %d (%dx%d)\n", str, rect->xmin, rect->xmax, rect->ymin, rect->ymax, rect->xmax - rect->xmin, rect->ymax - rect->ymin); + printf("%s: xmin %d, xmax %d, ymin %d, ymax %d (%dx%d)\n", str, + rect->xmin, rect->xmax, rect->ymin, rect->ymax, rect->xmax - rect->xmin, rect->ymax - rect->ymin); } diff --git a/source/blender/editors/mesh/bmesh_tools.c b/source/blender/editors/mesh/bmesh_tools.c index 7fd82be7571..13852667d35 100644 --- a/source/blender/editors/mesh/bmesh_tools.c +++ b/source/blender/editors/mesh/bmesh_tools.c @@ -4447,7 +4447,7 @@ static int mesh_bevel_exec(bContext *C, wmOperator *op) BMIter iter; BMEdge *eed; BMOperator bmop; - float factor = RNA_float_get(op->ptr, "percent"), /*, dfac */ /* UNUSED */, df, s; + float factor = RNA_float_get(op->ptr, "percent") /*, dfac */ /* UNUSED */, df, s; int i, recursion = RNA_int_get(op->ptr, "recursion"); const int use_even = RNA_boolean_get(op->ptr, "use_even"); const int use_dist = RNA_boolean_get(op->ptr, "use_dist"); From d25dc3b87232fddfaf56c890b7d112f01b32f1d7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Mar 2012 02:18:46 +0000 Subject: [PATCH 046/310] bmesh: Pressing Fkey when a face cant be made falls back to the selection history and creates edges in the order of verts selected, pressing F again will make an NGon. (fun feature while our bug tracker is down) --- source/blender/bmesh/operators/bmo_create.c | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/source/blender/bmesh/operators/bmo_create.c b/source/blender/bmesh/operators/bmo_create.c index cb63ad60f17..1f1c8294a9b 100644 --- a/source/blender/bmesh/operators/bmo_create.c +++ b/source/blender/bmesh/operators/bmo_create.c @@ -1428,4 +1428,49 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) BMO_elem_flag_enable(bm, f, ELE_OUT); } } + else { + /* tricky feature for making a line/edge from selection history... + * + * Rather then do nothing, when 5+ verts are selected, check if they are in our history, + * when this is so, we can make edges from them, but _not_ a face, + * if it is the intention to make a face the user can just hit F again since there will be edges next + * time around. + * + * if all history verts have ELE_NEW flagged and the total number of history verts == totv, + * then we know the history contains all verts here and we can continue... + */ + + BMEditSelection *ese; + int tot_ese_v = 0; + + for (ese = bm->selected.first; ese; ese = ese->next) { + if (ese->htype == BM_VERT) { + if (BMO_elem_flag_test(bm, (BMElemF *)ese->ele, ELE_NEW)) { + tot_ese_v++; + } + else { + /* unflagged vert means we are not in sync */ + tot_ese_v = -1; + break; + } + } + } + + if (tot_ese_v == totv) { + BMVert *v_prev = NULL; + /* yes, all select-history verts are accounted for, now make edges */ + + for (ese = bm->selected.first; ese; ese = ese->next) { + if (ese->htype == BM_VERT) { + v = (BMVert *)ese->ele; + if (v_prev) { + e = BM_edge_create(bm, v, v_prev, NULL, TRUE); + BMO_elem_flag_enable(bm, e, ELE_OUT); + } + v_prev = v; + } + } + } + /* done creating edges */ + } } From a69585573e460ca96af340800d4d8534bdece9f6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Mar 2012 02:59:42 +0000 Subject: [PATCH 047/310] bmesh python api: BMesh.select_history.remove/clear/validate functions. --- source/blender/bmesh/intern/bmesh_marking.c | 6 +- source/blender/bmesh/intern/bmesh_marking.h | 2 +- source/blender/python/bmesh/bmesh_py_select.c | 73 ++++++++++++++++--- 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c index f05a75e74bf..4108d00fe7a 100644 --- a/source/blender/bmesh/intern/bmesh_marking.c +++ b/source/blender/bmesh/intern/bmesh_marking.c @@ -701,15 +701,17 @@ int BM_select_history_check(BMesh *bm, const BMElem *ele) return FALSE; } -void BM_select_history_remove(BMesh *bm, BMElem *ele) +int BM_select_history_remove(BMesh *bm, BMElem *ele) { BMEditSelection *ese; for (ese = bm->selected.first; ese; ese = ese->next) { if (ese->ele == ele) { BLI_freelinkN(&(bm->selected), ese); - break; + return TRUE; } } + + return FALSE; } void BM_select_history_clear(BMesh *bm) diff --git a/source/blender/bmesh/intern/bmesh_marking.h b/source/blender/bmesh/intern/bmesh_marking.h index 598cc02126a..8e4a4ab7d66 100644 --- a/source/blender/bmesh/intern/bmesh_marking.h +++ b/source/blender/bmesh/intern/bmesh_marking.h @@ -70,7 +70,7 @@ void BM_editselection_normal(float r_normal[3], BMEditSelection *ese); void BM_editselection_plane(BMesh *bm, float r_plane[3], BMEditSelection *ese); int BM_select_history_check(BMesh *bm, const BMElem *ele); -void BM_select_history_remove(BMesh *bm, BMElem *ele); +int BM_select_history_remove(BMesh *bm, BMElem *ele); void BM_select_history_store(BMesh *bm, BMElem *ele); void BM_select_history_validate(BMesh *bm); void BM_select_history_clear(BMesh *em); diff --git a/source/blender/python/bmesh/bmesh_py_select.c b/source/blender/python/bmesh/bmesh_py_select.c index c5c66c0aaaa..cd6145709e0 100644 --- a/source/blender/python/bmesh/bmesh_py_select.c +++ b/source/blender/python/bmesh/bmesh_py_select.c @@ -69,8 +69,65 @@ static PyGetSetDef bpy_bmeditselseq_getseters[] = { {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; +PyDoc_STRVAR(bpy_bmeditselseq_validate_doc, +".. method:: validate()\n" +"\n" +" Ensures all elements in the selection history are selected.\n" +); +static PyObject *bpy_bmeditselseq_validate(BPy_BMEditSelSeq *self) +{ + BPY_BM_CHECK_OBJ(self); + BM_select_history_validate(self->bm); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(bpy_bmeditselseq_clear_doc, +".. method:: clear()\n" +"\n" +" Empties the selection history.\n" +); +static PyObject *bpy_bmeditselseq_clear(BPy_BMEditSelSeq *self) +{ + BPY_BM_CHECK_OBJ(self); + BM_select_history_clear(self->bm); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(bpy_bmeditselseq_remove_doc, +".. method:: remove(element)\n" +"\n" +" Remove an element from the selection history.\n" +); +static PyObject *bpy_bmeditselseq_remove(BPy_BMEditSelSeq *self, BPy_BMElem *value) +{ + BPY_BM_CHECK_OBJ(self); + + if ((BPy_BMVert_Check(value) || + BPy_BMEdge_Check(value) || + BPy_BMFace_Check(value)) == FALSE) + { + PyErr_Format(PyExc_TypeError, + "Expected a BMVert/BMedge/BMFace not a %.200s", Py_TYPE(value)->tp_name); + return NULL; + } + + BPY_BM_CHECK_OBJ(value); + + if ((self->bm != value->bm) || + (BM_select_history_remove(self->bm, value->ele) == FALSE)) + { + PyErr_SetString(PyExc_ValueError, + "Element not found in selection history"); + return NULL; + } + + Py_RETURN_NONE; +} + static struct PyMethodDef bpy_bmeditselseq_methods[] = { - // {"select_flush_mode", (PyCFunction)bpy_bmesh_select_flush_mode, METH_NOARGS, bpy_bmesh_select_flush_mode_doc}, + {"validate", (PyCFunction)bpy_bmeditselseq_validate, METH_NOARGS, bpy_bmeditselseq_validate_doc}, + {"clear", (PyCFunction)bpy_bmeditselseq_clear, METH_NOARGS, bpy_bmeditselseq_clear_doc}, + {"remove", (PyCFunction)bpy_bmeditselseq_remove, METH_O, bpy_bmeditselseq_remove_doc}, {NULL, NULL, 0, NULL} }; @@ -103,7 +160,7 @@ static PyObject *bpy_bmeditselseq_subscript_int(BPy_BMEditSelSeq *self, int keyn } else { PyErr_Format(PyExc_IndexError, - "BMElemSeq[index]: index %d out of range", keynum); + "BMElemSeq[index]: index %d out of range", keynum); return NULL; } } @@ -213,15 +270,7 @@ static int bpy_bmeditselseq_contains(BPy_BMEditSelSeq *self, PyObject *value) value_bm_ele = (BPy_BMElem *)value; if (value_bm_ele->bm == self->bm) { - BMEditSelection *ese_test; - BMElem *ele; - - ele = value_bm_ele->ele; - for (ese_test = self->bm->selected.first; ese_test; ese_test = ese_test->next) { - if (ele == ese_test->ele) { - return 1; - } - } + return BM_select_history_check(self->bm, value_bm_ele->ele); } return 0; @@ -274,7 +323,7 @@ static PyObject *bpy_bmeditseliter_next(BPy_BMEditSelIter *self) } } -PyTypeObject BPy_BMEditSelSeq_Type = {{{0}}}; +PyTypeObject BPy_BMEditSelSeq_Type = {{{0}}}; PyTypeObject BPy_BMEditSelIter_Type = {{{0}}}; From 2fbb5ce8338838a58f7cf518ceaa40580d290791 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Mar 2012 06:22:43 +0000 Subject: [PATCH 048/310] bmesh py api: more comprehensive intro page, also fix some spelling errors. --- CMakeLists.txt | 4 +- doc/python_api/rst/include__bmesh.rst | 103 ++++++++++++++++++ doc/python_api/sphinx_doc_gen.py | 40 +++++-- intern/ghost/GHOST_ISystem.h | 2 +- .../nodes/node_composite_doubleEdgeMask.c | 2 +- source/blender/python/bmesh/bmesh_py_api.c | 5 +- source/blender/python/intern/bpy_rna.c | 2 +- .../python/mathutils/mathutils_Matrix.c | 2 +- source/gameengine/Ketsji/KX_GameObject.cpp | 2 +- source/gameengine/Ketsji/KX_GameObject.h | 2 +- 10 files changed, 143 insertions(+), 21 deletions(-) create mode 100644 doc/python_api/rst/include__bmesh.rst diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a13851b8d4..c06567103f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,7 +124,7 @@ mark_as_advanced(WITH_PYTHON) # dont want people disabling this unless they rea mark_as_advanced(WITH_PYTHON_SECURITY) # some distrobutions see this as a security issue, rather than have them patch it, make a build option. option(WITH_PYTHON_SAFETY "Enable internal API error checking to track invalid data to prevent crash on access (at the expense of some effeciency, only enable for development)." OFF) -option(WITH_PYTHON_MODULE "Enable building as a python module (experemental, only enable for development)" OFF) +option(WITH_PYTHON_MODULE "Enable building as a python module (experimental, only enable for development)" OFF) option(WITH_BUILDINFO "Include extra build details (only disable for development & faster builds)" ON) option(WITH_IK_ITASC "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON) option(WITH_FFTW3 "Enable FFTW3 support (Used for smoke and audio effects)" OFF) @@ -176,7 +176,7 @@ option(WITH_MOD_SMOKE "Enable Smoke Modifier (Smoke Simulation)" ON) option(WITH_MOD_DECIMATE "Enable Decimate Modifier" ON) option(WITH_MOD_BOOLEAN "Enable Boolean Modifier" ON) option(WITH_MOD_REMESH "Enable Remesh Modifier" ON) -option(WITH_MOD_CLOTH_ELTOPO "Enable Experemental cloth solver" OFF) +option(WITH_MOD_CLOTH_ELTOPO "Enable Experimental cloth solver" OFF) mark_as_advanced(WITH_MOD_CLOTH_ELTOPO) option(WITH_MOD_OCEANSIM "Enable Ocean Modifier" OFF) diff --git a/doc/python_api/rst/include__bmesh.rst b/doc/python_api/rst/include__bmesh.rst new file mode 100644 index 00000000000..1c702275f62 --- /dev/null +++ b/doc/python_api/rst/include__bmesh.rst @@ -0,0 +1,103 @@ +.. + This document is appended to the auto generated bmesh api doc to avoid clogging up the C files with details. + to test this run: + ./blender.bin -b -noaudio -P doc/python_api/sphinx_doc_gen.py -- --partial bmesh* ; cd doc/python_api ; sphinx-build sphinx-in sphinx-out ; cd ../../ + + +Intro +----- + +This API gives access the blenders internal mesh editing api, featuring geometry connectivity data and +access to editing operations such as split, separate, collapse and dissolve. + +The features exposed closely follow the C API, +giving python access to the functions used by blenders own mesh editing tools. + +For an overview of BMesh data types and how they reference each other see: +`BMesh Design Document `_ . + + +.. note:: + + **Disk** and **Radial** data is not exposed by the python api since this is for internal use only. + + +.. warning:: + + This API is still in development and experimental, while we don't expect to see large changes, + many areas are not well tested yet and so its possible changes will be made that break scripts. + + *Campbell Barton, 13, March 2012* + + +.. todo:: + + * add access to BMesh **walkers** + * add access selection history (readonly access done) + * add a way to re-tessellate an editmode bmesh. + + +Stand-Alone Module +^^^^^^^^^^^^^^^^^^ + +The bmesh module is written to be standalone except for :mod:`mathutils` +which is used for vertex locations and normals. + +The only other exception to this are when converting mesh data to and from :class:`bpy.types.Mesh`. + + +Mesh Access +----------- + +There are 2 ways to access BMesh data, you can create a new BMesh by converting a mesh from +:class:`bpy.types.BlendData.meshes` or by accessing the current edit mode mesh. +see: :class:`bmesh.types.BMesh.from_mesh` and :mod:`bmesh.from_edit_mesh` respectively. + +When explicitly converting from mesh data python **owns** the data, that is to say - that the mesh only exists while +python holds a reference to it, and the script is responsible for putting it back into a mesh data-block when the edits +are done. + +Note that unlike :mod:`bpy`, a BMesh does not necessarily correspond to data in the currently open blend file, +a BMesh can be created, edited and freed without the user ever seeing or having access to it. +Unlike edit mode, the bmesh module can use multiple BMesh instances at once. + +Take care when dealing with multiple BMesh instances since the mesh data can use a lot of memory, while a mesh that +python owns will be freed in when the script holds no references to it, +its good practice to call :class:`bmesh.types.BMesh.free` which will remove all the mesh data immediately and disable +further access. + + +Keeping a Correct State +----------------------- + +When modeling in blender there are certain assumptions made about the state of the mesh. + +* hidden geometry isn't selected. +* when an edge is selected, its vertices's are selected too. +* when a face is selected, its edges and vertices's are selected. +* duplicate edges / faces don't exist. +* faces have at least 3 vertices's. + +To give developers flexibility these conventions are not enforced, +however tools must leave the mesh in a valid state else other tools may behave incorrectly. + +Any errors that arise from not following these conventions is considered a bug in the script, +not a bug in blender. + + +Selection / Flushing +^^^^^^^^^^^^^^^^^^^^ + +As mentioned above, it is possible to create an invalid selection state +(by selecting a state and then de-selecting one of its vertices's for example), mostly the best way to solve this is to +flush the selection after performing a series of edits. this validates the selection state. + + +Example Script +-------------- + +.. literalinclude:: ../../../release/scripts/templates/bmesh_simple.py + + +Module Functions +---------------- diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py index d8407121ae1..49193ad8f22 100644 --- a/doc/python_api/sphinx_doc_gen.py +++ b/doc/python_api/sphinx_doc_gen.py @@ -37,6 +37,7 @@ API dump in RST files For quick builds: ./blender.bin -b -P doc/python_api/sphinx_doc_gen.py -- -q + Sphinx: HTML generation ----------------------- After you have built doc/python_api/sphinx-in (see above), @@ -47,6 +48,7 @@ Sphinx: HTML generation This requires sphinx 1.0.7 to be installed. + Sphinx: PDF generation ---------------------- After you have built doc/python_api/sphinx-in (see above), @@ -139,11 +141,11 @@ def handle_args(): help="Rewrite all rst files in sphinx-in/ (default=False)", required=False) - parser.add_argument("-t", "--testdump", - dest="test_dump", - default=False, - action='store_true', - help="Dumps a small part of the API (default=False)", + parser.add_argument("-p", "--partial", + dest="partial", + type=str, + default="", + help="Use a wildcard to only build spesific module(s)", required=False) parser.add_argument("-b", "--bpy", @@ -173,7 +175,7 @@ sphinx-build doc/python_api/sphinx-in doc/python_api/sphinx-out """ # Switch for quick testing so doc-builds don't take so long -if not ARGS.test_dump: +if not ARGS.partial: # full build FILTER_BPY_OPS = None FILTER_BPY_TYPES = None @@ -181,6 +183,7 @@ if not ARGS.test_dump: EXCLUDE_MODULES = () else: + # can manually edit this too: FILTER_BPY_OPS = ("import.scene", ) # allow FILTER_BPY_TYPES = ("bpy_struct", "Operator", "ID") # allow EXCLUDE_INFO_DOCS = True @@ -195,9 +198,9 @@ else: "bge.types", "bgl", "blf", - #"bmesh", - #"bmesh.types", - #"bmesh.utils", + "bmesh", + "bmesh.types", + "bmesh.utils", "bpy.app", "bpy.app.handlers", "bpy.context", @@ -214,6 +217,22 @@ else: "mathutils.noise", ) + # ------ + # Filter + # + # TODO, support bpy.ops and bpy.types filtering + import fnmatch + m = None + EXCLUDE_MODULES = tuple([m for m in EXCLUDE_MODULES if not fnmatch.fnmatchcase(m, ARGS.partial)]) + del m + del fnmatch + + print("Partial Doc Build, Skipping: %s\n" % "\n ".join(sorted(EXCLUDE_MODULES))) + + # + # done filtering + # -------------- + try: __import__("aud") except ImportError: @@ -1527,6 +1546,9 @@ def copy_handwritten_rsts(basepath): "bge.constraints", "bgl", # "Blender OpenGl wrapper" "gpu", # "GPU Shader Module" + + # includes... + "include__bmesh", ] for mod_name in handwritten_modules: if mod_name not in EXCLUDE_MODULES: diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h index be44bbee99a..eeee8c0477b 100644 --- a/intern/ghost/GHOST_ISystem.h +++ b/intern/ghost/GHOST_ISystem.h @@ -82,7 +82,7 @@ class GHOST_IEventConsumer; *
  • OSX Carbon.
  • *
  • Windows.
  • *
  • X11.
  • - *
  • SDL1.3 (experemental).
  • + *
  • SDL1.3 (experimental).
  • *
  • NULL (headless mode).
  • * * diff --git a/source/blender/nodes/composite/nodes/node_composite_doubleEdgeMask.c b/source/blender/nodes/composite/nodes/node_composite_doubleEdgeMask.c index 7b2e682e968..d3c6561ac34 100644 --- a/source/blender/nodes/composite/nodes/node_composite_doubleEdgeMask.c +++ b/source/blender/nodes/composite/nodes/node_composite_doubleEdgeMask.c @@ -998,7 +998,7 @@ static void do_fillGradientBuffer(unsigned int rw, float *res, unsigned short *g purpose of GO for the proportion calculation. For the purposes of the minimun distance comparisons, we only check - the sums-of-squares against eachother, since they are in the same + the sums-of-squares against each other, since they are in the same mathematical sort-order as if we did go ahead and take square roots Loop through all gradient pixels. diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c index d3dcc979015..5526926ec8e 100644 --- a/source/blender/python/bmesh/bmesh_py_api.c +++ b/source/blender/python/bmesh/bmesh_py_api.c @@ -108,10 +108,7 @@ PyDoc_STRVAR(BPy_BM_doc, "* :mod:`bmesh.types`\n" "\n" "\n" -"Example Script\n" -"--------------\n" -"\n" -".. literalinclude:: ../../../release/scripts/templates/bmesh_simple.py\n" +".. include:: include__bmesh.rst\n" ); static struct PyModuleDef BPy_BM_module_def = { PyModuleDef_HEAD_INIT, diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index b543f426751..1af1f8fc9e4 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -4524,7 +4524,7 @@ static struct PyMethodDef pyrna_struct_methods[] = { {"type_recast", (PyCFunction)pyrna_struct_type_recast, METH_NOARGS, pyrna_struct_type_recast_doc}, {"__dir__", (PyCFunction)pyrna_struct_dir, METH_NOARGS, NULL}, - /* experemental */ + /* experimental */ {"callback_add", (PyCFunction)pyrna_callback_add, METH_VARARGS, NULL}, {"callback_remove", (PyCFunction)pyrna_callback_remove, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c index ea329b17013..1d9bda02311 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.c +++ b/source/blender/python/mathutils/mathutils_Matrix.c @@ -780,7 +780,7 @@ PyDoc_STRVAR(C_Matrix_Shear_doc, " :arg size: The size of the shear matrix to construct [2, 4].\n" " :type size: int\n" " :arg factor: The factor of shear to apply. For a 3 or 4 *size* matrix\n" -" pass a pair of floats corrasponding with the *plane* axis.\n" +" pass a pair of floats corresponding with the *plane* axis.\n" " :type factor: float or float pair\n" " :return: A new shear matrix.\n" " :rtype: :class:`Matrix`\n" diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 5db9958f269..11129248338 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1662,7 +1662,7 @@ PyAttributeDef KX_GameObject::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("attrDict", KX_GameObject, pyattr_get_attrDict), KX_PYATTRIBUTE_RW_FUNCTION("color", KX_GameObject, pyattr_get_obcolor, pyattr_set_obcolor), - /* Experemental, dont rely on these yet */ + /* experimental, don't rely on these yet */ KX_PYATTRIBUTE_RO_FUNCTION("sensors", KX_GameObject, pyattr_get_sensors), KX_PYATTRIBUTE_RO_FUNCTION("controllers", KX_GameObject, pyattr_get_controllers), KX_PYATTRIBUTE_RO_FUNCTION("actuators", KX_GameObject, pyattr_get_actuators), diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index cf3aae2bc90..a173ef1ed8f 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -995,7 +995,7 @@ public: static PyObject* pyattr_get_obcolor(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_obcolor(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - /* Experemental! */ + /* Experimental! */ static PyObject* pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_controllers(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); From f34c3580acc1904a995205646319a0ab618c0cb3 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 13 Mar 2012 10:31:42 +0000 Subject: [PATCH 049/310] Fix possible usage of NULL function reported by clang --- source/blender/blenkernel/intern/tracking.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 1d275cfdb28..9cc45d49e9f 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -2716,6 +2716,9 @@ ImBuf *BKE_tracking_stabilize(MovieTracking *tracking, int framenr, ImBuf *ibuf, interpolation = bilinear_interpolation; else if(filter == TRACKING_FILTER_BICUBIC) interpolation = bicubic_interpolation; + else + /* fallback to default interpolation method */ + interpolation = neareast_interpolation; for(j=0; jy; j++) { for(i=0; ix;i++) { From 59303e35fc63c9b5df3c57f674c23632f50f2f7c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Mar 2012 14:28:58 +0000 Subject: [PATCH 050/310] WITH_GHOST_SDL working again (missing std:: update) --- CMakeLists.txt | 5 +++++ intern/ghost/intern/GHOST_SystemSDL.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c06567103f0..2bda4b9f133 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -358,6 +358,11 @@ if(WITH_INSTALL_PORTABLE) set(CMAKE_SKIP_BUILD_RPATH TRUE) endif() +if(WITH_GHOST_SDL OR WITH_HEADLESS) + set(WITH_GHOST_XDND OFF) +endif() + + #----------------------------------------------------------------------------- # Initialize un-cached vars, avoid unused warning diff --git a/intern/ghost/intern/GHOST_SystemSDL.cpp b/intern/ghost/intern/GHOST_SystemSDL.cpp index dd5124a0aac..4d1159fbfbe 100644 --- a/intern/ghost/intern/GHOST_SystemSDL.cpp +++ b/intern/ghost/intern/GHOST_SystemSDL.cpp @@ -481,8 +481,8 @@ GHOST_SystemSDL::setCursorPosition(GHOST_TInt32 x, bool GHOST_SystemSDL::generateWindowExposeEvents() { - vector::iterator w_start= m_dirty_windows.begin(); - vector::const_iterator w_end= m_dirty_windows.end(); + std::vector::iterator w_start= m_dirty_windows.begin(); + std::vector::const_iterator w_end= m_dirty_windows.end(); bool anyProcessed= false; for (;w_start != w_end; ++w_start) { @@ -563,10 +563,10 @@ GHOST_SystemSDL::findGhostWindow(SDL_Window *sdl_win) // We should always check the window manager's list of windows // and only process events on these windows. - vector & win_vec= m_windowManager->getWindows(); + std::vector & win_vec= m_windowManager->getWindows(); - vector::iterator win_it= win_vec.begin(); - vector::const_iterator win_end= win_vec.end(); + std::vector::iterator win_it= win_vec.begin(); + std::vector::const_iterator win_end= win_vec.end(); for (; win_it != win_end; ++win_it) { GHOST_WindowSDL * window= static_cast(*win_it); From 1581816d549c148b80eff6cae7234b41966af85a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Mar 2012 15:44:48 +0000 Subject: [PATCH 051/310] patch [#30511] from r44792, broke setting the window state from the command line (-W / -w). Fix this by storing if the border is set - before this was only done for the window dimensions. also move these variables into a static struct so this logic is easier to follow. --- .../blender/windowmanager/intern/wm_window.c | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index ed1a5f9d577..7893ac2f639 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -78,9 +78,20 @@ /* the global to talk to ghost */ static GHOST_SystemHandle g_system= NULL; +typedef enum WinOverrideFlag { + WIN_OVERRIDE_GEOM = (1 << 0), + WIN_OVERRIDE_WINSTATE = (1 << 1) +} WinOverrideFlag; + /* set by commandline */ -static int prefsizx= 0, prefsizy= 0, prefstax= 0, prefstay= 0, initialstate= GHOST_kWindowStateNormal; -static unsigned short useprefsize= 0; +static struct WMInitStruct { + /* window geometry */ + int size_x, size_y; + int start_x, start_y; + + int windowstate; + WinOverrideFlag override_flag; +} wm_init_state = {0, 0, 0, 0, GHOST_kWindowStateNormal, 0}; /* ******** win open & close ************ */ @@ -370,33 +381,37 @@ void wm_window_add_ghostwindows(wmWindowManager *wm) * Note that these values will be used only * when there is no startup.blend yet. */ - if (!prefsizx) { - wm_get_screensize(&prefsizx, &prefsizy); + if (wm_init_state.size_x == 0) { + wm_get_screensize(&wm_init_state.size_x, &wm_init_state.size_y); #if defined(__APPLE__) && !defined(GHOST_COCOA) //Cocoa provides functions to get correct max window size { extern void wm_set_apple_prefsize(int, int); /* wm_apple.c */ - wm_set_apple_prefsize(prefsizx, prefsizy); + wm_set_apple_prefsize(wm_init_state.size_x, wm_init_state.size_y); } #else - prefstax= 0; - prefstay= 0; + wm_init_state.start_x = 0; + wm_init_state.start_y = 0; #endif } - for(win= wm->windows.first; win; win= win->next) { - if(win->ghostwin==NULL) { - if(win->sizex==0 || useprefsize) { - win->posx= prefstax; - win->posy= prefstay; - win->sizex= prefsizx; - win->sizey= prefsizy; - win->windowstate= initialstate; - useprefsize= 0; + for (win= wm->windows.first; win; win= win->next) { + if (win->ghostwin==NULL) { + if ((win->sizex == 0) || (wm_init_state.override_flag & WIN_OVERRIDE_GEOM)) { + win->posx = wm_init_state.start_x; + win->posy = wm_init_state.start_y; + win->sizex = wm_init_state.size_x; + win->sizey = wm_init_state.size_y; + wm_init_state.override_flag &= ~WIN_OVERRIDE_GEOM; } + + if (wm_init_state.override_flag & WIN_OVERRIDE_WINSTATE) { + win->windowstate = wm_init_state.windowstate; + } + wm_window_add_ghostwindow("Blender", win); } /* happens after fileread */ @@ -1144,22 +1159,24 @@ void wm_get_cursor_position(wmWindow *win, int *x, int *y) /* called whem no ghost system was initialized */ void WM_setprefsize(int stax, int stay, int sizx, int sizy) { - prefstax= stax; - prefstay= stay; - prefsizx= sizx; - prefsizy= sizy; - useprefsize= 1; + wm_init_state.start_x = stax; /* left hand pos */ + wm_init_state.start_y = stay; /* bottom pos */ + wm_init_state.size_x = sizx; + wm_init_state.size_y = sizy; + wm_init_state.override_flag |= WIN_OVERRIDE_GEOM; } /* for borderless and border windows set from command-line */ void WM_setinitialstate_fullscreen(void) { - initialstate= GHOST_kWindowStateFullScreen; + wm_init_state.windowstate = GHOST_kWindowStateFullScreen; + wm_init_state.override_flag |= WIN_OVERRIDE_WINSTATE; } void WM_setinitialstate_normal(void) { - initialstate= GHOST_kWindowStateNormal; + wm_init_state.windowstate = GHOST_kWindowStateNormal; + wm_init_state.override_flag |= WIN_OVERRIDE_WINSTATE; } /* This function requires access to the GHOST_SystemHandle (g_system) */ From b47e2ee907a7cc4c949a6a6e4dc895532ca53f5e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Mar 2012 17:13:44 +0000 Subject: [PATCH 052/310] code/style cleanup for loop walker which was is fairly confusing and hard to extend. - only have one return at the end of the function. - break up functionality more clearly between wire/face walk. - remove unused struct member. --- .../blender/bmesh/intern/bmesh_walkers_impl.c | 98 ++++++++++--------- .../bmesh/intern/bmesh_walkers_private.h | 1 - 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/source/blender/bmesh/intern/bmesh_walkers_impl.c b/source/blender/bmesh/intern/bmesh_walkers_impl.c index 23d82f0ab34..3c8e2c1f974 100644 --- a/source/blender/bmesh/intern/bmesh_walkers_impl.c +++ b/source/blender/bmesh/intern/bmesh_walkers_impl.c @@ -396,7 +396,6 @@ static void bmw_LoopWalker_begin(BMWalker *walker, void *data) lwalk->cur = lwalk->start = e; lwalk->lastv = lwalk->startv = v; - lwalk->stage2 = 0; lwalk->is_boundry = BM_edge_is_boundary(e); lwalk->is_single = (BM_vert_edge_count_nonwire(e->v1) == 2 && BM_vert_edge_count_nonwire(e->v2) == 2); @@ -427,21 +426,18 @@ static void *bmw_LoopWalker_yield(BMWalker *walker) static void *bmw_LoopWalker_step(BMWalker *walker) { BMwLoopWalker *lwalk = BMW_current_state(walker), owalk; - BMIter eiter; BMEdge *e = lwalk->cur, *nexte = NULL; - BMLoop *l, *l2; + BMLoop *l; BMVert *v; - int vert_edge_tot; - int i = 0, stopi; - /* int found = 0; */ /* UNUSED */ + int i; owalk = *lwalk; BMW_state_remove(walker); l = e->l; - /* handle wire edge case */ - if (!l) { + if (!l) { /* WIRE EDGE */ + BMIter eiter; /* match trunk: mark all connected wire edges */ for (i = 0; i < 2; i++) { @@ -459,60 +455,66 @@ static void *bmw_LoopWalker_step(BMWalker *walker) } } } - - return owalk.cur; } + else { /* FACE EDGE */ + int vert_edge_tot; + int stopi; - v = BM_edge_other_vert(e, lwalk->lastv); + v = BM_edge_other_vert(e, lwalk->lastv); - vert_edge_tot = BM_vert_edge_count_nonwire(v); + vert_edge_tot = BM_vert_edge_count_nonwire(v); - if (/* check if we should step, this is fairly involved */ + if (/* check if we should step, this is fairly involved */ - /* typical loopiong over edges in the middle of a mesh */ - /* however, why use 2 here at all? I guess for internal ngon loops it can be useful. Antony R. */ - ((vert_edge_tot == 4 || vert_edge_tot == 2) && owalk.is_boundry == FALSE) || + /* typical loopiong over edges in the middle of a mesh */ + /* however, why use 2 here at all? I guess for internal ngon loops it can be useful. Antony R. */ + ((vert_edge_tot == 4 || vert_edge_tot == 2) && owalk.is_boundry == FALSE) || - /* walk over boundry of faces but stop at corners */ - (owalk.is_boundry == TRUE && owalk.is_single == FALSE && vert_edge_tot > 2) || + /* walk over boundry of faces but stop at corners */ + (owalk.is_boundry == TRUE && owalk.is_single == FALSE && vert_edge_tot > 2) || - /* initial edge was a boundry, so is this edge and vertex is only apart of this face - * this lets us walk over the the boundry of an ngon which is handy */ - (owalk.is_boundry == TRUE && owalk.is_single == TRUE && vert_edge_tot == 2 && BM_edge_is_boundary(e))) - { - i = 0; - stopi = vert_edge_tot / 2; - while (1) { - if (owalk.is_boundry == FALSE && i == stopi) break; + /* initial edge was a boundry, so is this edge and vertex is only apart of this face + * this lets us walk over the the boundry of an ngon which is handy */ + (owalk.is_boundry == TRUE && owalk.is_single == TRUE && vert_edge_tot == 2 && BM_edge_is_boundary(e))) + { + i = 0; + stopi = vert_edge_tot / 2; + while (1) { + if ((owalk.is_boundry == FALSE) && (i == stopi)) { + break; + } - l = BM_face_other_edge_loop(l->f, l->e, v); + l = BM_face_other_edge_loop(l->f, l->e, v); - if (!l) - break; + if (l == NULL) { + break; + } + else { + BMLoop *l_next; - l2 = l->radial_next; + l_next = l->radial_next; - if (l2 == l || !l2) { - break; + if ((l_next == l) || (l_next == NULL)) { + break; + } + + l = l_next; + i++; + } } - - l = l2; - i += 1; } - } - if (!l) { - return owalk.cur; - } - - if (l != e->l && !BLI_ghash_haskey(walker->visithash, l->e)) { - if (!(owalk.is_boundry == FALSE && i != stopi)) { - lwalk = BMW_state_add(walker); - lwalk->cur = l->e; - lwalk->lastv = v; - lwalk->is_boundry = owalk.is_boundry; - lwalk->is_single = owalk.is_single; - BLI_ghash_insert(walker->visithash, l->e, NULL); + if (l != NULL) { + if (l != e->l && !BLI_ghash_haskey(walker->visithash, l->e)) { + if (!(owalk.is_boundry == FALSE && i != stopi)) { + lwalk = BMW_state_add(walker); + lwalk->cur = l->e; + lwalk->lastv = v; + lwalk->is_boundry = owalk.is_boundry; + lwalk->is_single = owalk.is_single; + BLI_ghash_insert(walker->visithash, l->e, NULL); + } + } } } diff --git a/source/blender/bmesh/intern/bmesh_walkers_private.h b/source/blender/bmesh/intern/bmesh_walkers_private.h index d51a3b3ddb1..d8eccda2063 100644 --- a/source/blender/bmesh/intern/bmesh_walkers_private.h +++ b/source/blender/bmesh/intern/bmesh_walkers_private.h @@ -61,7 +61,6 @@ typedef struct BMwLoopWalker { BMwGenericWalker header; BMEdge *cur, *start; BMVert *lastv, *startv; - int stage2; short is_boundry; /* boundry looping changes behavior */ short is_single; /* single means the edge verts are only connected to 1 face */ } BMwLoopWalker; From 01b3e9cc9fdd0875b93ba749c8209e6c43570d13 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Mar 2012 18:37:31 +0000 Subject: [PATCH 053/310] loopwalker support for selecting the sides of ngons see: wiki.blender.org/uploads/d/dc/BMesh_NGon_Loop_Select.png --- .../blender/bmesh/intern/bmesh_walkers_impl.c | 91 ++++++++++++++----- .../bmesh/intern/bmesh_walkers_private.h | 1 + 2 files changed, 70 insertions(+), 22 deletions(-) diff --git a/source/blender/bmesh/intern/bmesh_walkers_impl.c b/source/blender/bmesh/intern/bmesh_walkers_impl.c index 3c8e2c1f974..d4942412bae 100644 --- a/source/blender/bmesh/intern/bmesh_walkers_impl.c +++ b/source/blender/bmesh/intern/bmesh_walkers_impl.c @@ -385,22 +385,42 @@ static void bmw_LoopWalker_begin(BMWalker *walker, void *data) BMwLoopWalker *lwalk = NULL, owalk; BMEdge *e = data; BMVert *v; - /* int found = 1, val; */ /* UNUSED */ + int vert_edge_count[2] = {BM_vert_edge_count_nonwire(e->v1), + BM_vert_edge_count_nonwire(e->v2)}; v = e->v1; - /* val = BM_vert_edge_count(v); */ /* UNUSED */ - lwalk = BMW_state_add(walker); BLI_ghash_insert(walker->visithash, e, NULL); lwalk->cur = lwalk->start = e; lwalk->lastv = lwalk->startv = v; lwalk->is_boundry = BM_edge_is_boundary(e); - lwalk->is_single = (BM_vert_edge_count_nonwire(e->v1) == 2 && - BM_vert_edge_count_nonwire(e->v2) == 2); + lwalk->is_single = (vert_edge_count[0] == 2 && vert_edge_count[1] == 2); - /* rewin */ + /* could also check that vertex*/ + if ((lwalk->is_boundry == FALSE) && + (vert_edge_count[0] == 3 || vert_edge_count[1] == 3)) + { + BMIter iter; + BMFace *f_iter; + BMFace *f_best = NULL; + + BM_ITER(f_iter, &iter, walker->bm, BM_FACES_OF_EDGE, e) { + if (f_best == NULL || f_best->len < f_iter->len) { + f_best = f_iter; + } + } + + /* only use hub selection for 5+ sides else this could + * conflict with normal edge loop selection. */ + lwalk->f_hub = f_best->len > 4 ? f_best : NULL; + } + else { + lwalk->f_hub = NULL; + } + + /* rewind */ while (BMW_current_state(walker)) { owalk = *((BMwLoopWalker *)BMW_current_state(walker)); BMW_walk(walker); @@ -436,27 +456,29 @@ static void *bmw_LoopWalker_step(BMWalker *walker) l = e->l; - if (!l) { /* WIRE EDGE */ - BMIter eiter; + if (owalk.f_hub) { /* NGON EDGE */ + int vert_edge_tot; - /* match trunk: mark all connected wire edges */ - for (i = 0; i < 2; i++) { - v = i ? e->v2 : e->v1; + v = BM_edge_other_vert(e, lwalk->lastv); - BM_ITER(nexte, &eiter, walker->bm, BM_EDGES_OF_VERT, v) { - if ((nexte->l == NULL) && !BLI_ghash_haskey(walker->visithash, nexte)) { - lwalk = BMW_state_add(walker); - lwalk->cur = nexte; - lwalk->lastv = v; - lwalk->is_boundry = owalk.is_boundry; - lwalk->is_single = owalk.is_single; + vert_edge_tot = BM_vert_edge_count_nonwire(v); - BLI_ghash_insert(walker->visithash, nexte, NULL); - } - } + if (vert_edge_tot == 3) { + l = BM_face_other_vert_loop(owalk.f_hub, lwalk->lastv, v); + nexte = BM_edge_exists(v, l->v); + + lwalk = BMW_state_add(walker); + lwalk->cur = nexte; + lwalk->lastv = v; + + lwalk->is_boundry = owalk.is_boundry; + lwalk->is_single = owalk.is_single; + lwalk->f_hub = owalk.f_hub; + + BLI_ghash_insert(walker->visithash, nexte, NULL); } } - else { /* FACE EDGE */ + else if (l) { /* NORMAL EDGE WITH FACES */ int vert_edge_tot; int stopi; @@ -510,13 +532,38 @@ static void *bmw_LoopWalker_step(BMWalker *walker) lwalk = BMW_state_add(walker); lwalk->cur = l->e; lwalk->lastv = v; + lwalk->is_boundry = owalk.is_boundry; lwalk->is_single = owalk.is_single; + lwalk->f_hub = owalk.f_hub; + BLI_ghash_insert(walker->visithash, l->e, NULL); } } } } + else { /* WIRE EDGE */ + BMIter eiter; + + /* match trunk: mark all connected wire edges */ + for (i = 0; i < 2; i++) { + v = i ? e->v2 : e->v1; + + BM_ITER(nexte, &eiter, walker->bm, BM_EDGES_OF_VERT, v) { + if ((nexte->l == NULL) && !BLI_ghash_haskey(walker->visithash, nexte)) { + lwalk = BMW_state_add(walker); + lwalk->cur = nexte; + lwalk->lastv = v; + + lwalk->is_boundry = owalk.is_boundry; + lwalk->is_single = owalk.is_single; + lwalk->f_hub = owalk.f_hub; + + BLI_ghash_insert(walker->visithash, nexte, NULL); + } + } + } + } return owalk.cur; } diff --git a/source/blender/bmesh/intern/bmesh_walkers_private.h b/source/blender/bmesh/intern/bmesh_walkers_private.h index d8eccda2063..b6c7a974fce 100644 --- a/source/blender/bmesh/intern/bmesh_walkers_private.h +++ b/source/blender/bmesh/intern/bmesh_walkers_private.h @@ -61,6 +61,7 @@ typedef struct BMwLoopWalker { BMwGenericWalker header; BMEdge *cur, *start; BMVert *lastv, *startv; + BMFace *f_hub; short is_boundry; /* boundry looping changes behavior */ short is_single; /* single means the edge verts are only connected to 1 face */ } BMwLoopWalker; From 08f17b2a53dce465d25bb625e92ac33ad0eb29a0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Mar 2012 20:24:05 +0000 Subject: [PATCH 054/310] SDL ghost update to work with SDL2. this gives some problems because SDL2 Needs a window before fullscreen is set, the player currently doesnt have a window created when fullscreen is called. --- .../ghost/intern/GHOST_DisplayManagerSDL.cpp | 151 +++++++----------- 1 file changed, 56 insertions(+), 95 deletions(-) diff --git a/intern/ghost/intern/GHOST_DisplayManagerSDL.cpp b/intern/ghost/intern/GHOST_DisplayManagerSDL.cpp index 1b875e657d9..e76068f42e6 100644 --- a/intern/ghost/intern/GHOST_DisplayManagerSDL.cpp +++ b/intern/ghost/intern/GHOST_DisplayManagerSDL.cpp @@ -32,6 +32,8 @@ #include "GHOST_SystemSDL.h" #include "GHOST_DisplayManagerSDL.h" +#include "GHOST_WindowManager.h" + GHOST_DisplayManagerSDL::GHOST_DisplayManagerSDL(GHOST_SystemSDL *system) : GHOST_DisplayManager(), @@ -52,22 +54,29 @@ GHOST_TSuccess GHOST_DisplayManagerSDL::getNumDisplaySettings(GHOST_TUns8 displa GHOST_TInt32& numSettings) const { GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n"); - int i; - SDL_Rect **vidmodes; - vidmodes = SDL_ListModes(NULL, SDL_HWSURFACE | SDL_OPENGL | - SDL_FULLSCREEN | SDL_HWPALETTE); - if (!vidmodes) { - fprintf(stderr, "Could not get available video modes: %s.\n", - SDL_GetError()); - return GHOST_kFailure; - } - for (i = 0; vidmodes[i]; i++); - numSettings = GHOST_TInt32(i); + numSettings = SDL_GetNumDisplayModes(display - 1); return GHOST_kSuccess; } +static void ghost_mode_from_sdl(GHOST_DisplaySetting& setting, SDL_DisplayMode *mode) +{ + setting.xPixels = mode->w; + setting.yPixels = mode->h; + setting.bpp = SDL_BYTESPERPIXEL(mode->format) * 8; + /* Just guess the frequency :( */ + setting.frequency = mode->refresh_rate ? mode->refresh_rate : 60; +} + +static void ghost_mode_to_sdl(const GHOST_DisplaySetting& setting, SDL_DisplayMode *mode) +{ + mode->w = setting.xPixels; + mode->h = setting.yPixels; + // setting.bpp = SDL_BYTESPERPIXEL(mode->format) * 8; ??? + mode->refresh_rate = setting.frequency; +} + GHOST_TSuccess GHOST_DisplayManagerSDL::getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, @@ -75,36 +84,10 @@ GHOST_DisplayManagerSDL::getDisplaySetting(GHOST_TUns8 display, { GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n"); - int i; - SDL_Rect **vidmodes; - /* NULL is passed in here to get the modes for the current bit depth. - * Other bit depths may be possible; in that case, an SDL_PixelFormat struct - * should be passed in. To get a complete profile, all possible bit depths - * would need to be iterated over. - z0r */ - vidmodes = SDL_ListModes(NULL, SDL_HWSURFACE | SDL_OPENGL | - SDL_FULLSCREEN | SDL_HWPALETTE); - if (!vidmodes) { - fprintf(stderr, "Could not get available video modes: %s.\n", - SDL_GetError()); - return GHOST_kFailure; - } - for (i = 0; vidmodes[i]; i++); - GHOST_ASSERT(index < i, "Requested setting outside of valid range.\n"); + SDL_DisplayMode mode; + SDL_GetDisplayMode(display, index, &mode); - setting.xPixels = vidmodes[index]->w; - setting.yPixels = vidmodes[index]->h; - - SDL_Surface *surf; - surf = SDL_GetVideoSurface(); - if (surf == NULL) { - fprintf(stderr, "Getting display setting: %s\n", SDL_GetError()); - /* Just guess the bit depth */ - setting.bpp = 32; - } else { - setting.bpp = surf->format->BitsPerPixel; - } - /* Just guess the frequency :( */ - setting.frequency = 60; + ghost_mode_from_sdl(setting, &mode); return GHOST_kSuccess; } @@ -113,30 +96,10 @@ GHOST_TSuccess GHOST_DisplayManagerSDL::getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const { - SDL_Surface *surf; - const SDL_VideoInfo *info; + SDL_DisplayMode mode; + SDL_GetCurrentDisplayMode(display, &mode); - /* Note: not using SDL_GetDesktopDisplayMode because that does not return - * the current mode. Try to use GetVideoSurface first, as it seems more - * accurate. If that fails, try other methods. - z0r */ - surf = SDL_GetVideoSurface(); - - if (surf != NULL) { - setting.xPixels = surf->w; - setting.yPixels = surf->h; - setting.bpp = surf->format->BitsPerPixel; - /* Just guess the frequency :( */ - setting.frequency = 60; - } else { - /* This may happen if the surface hasn't been created yet, e.g. on - * application startup. */ - info = SDL_GetVideoInfo(); - setting.xPixels = info->current_w; - setting.yPixels = info->current_h; - setting.bpp = info->vfmt->BitsPerPixel; - /* Just guess the frequency :( */ - setting.frequency = 60; - } + ghost_mode_from_sdl(setting, &mode); return GHOST_kSuccess; } @@ -145,7 +108,6 @@ GHOST_TSuccess GHOST_DisplayManagerSDL:: setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting) { - /* * Mode switching code ported from Quake 2 version 3.21 and bzflag version * 2.4.0: @@ -154,31 +116,28 @@ GHOST_DisplayManagerSDL:: setCurrentDisplaySetting(GHOST_TUns8 display, * http://wiki.bzflag.org/BZFlag_Source * See src/platform/SDLDisplay.cxx:SDLDisplay and createWindow */ - SDL_Surface *surf; + SDL_DisplayMode mode; + const int num_modes = SDL_GetNumDisplayModes(display); int best_fit, best_dist, dist, x, y; - SDL_Rect **vidmodes = SDL_ListModes(NULL, SDL_HWSURFACE | SDL_OPENGL | - SDL_FULLSCREEN | SDL_HWPALETTE); - if (!vidmodes) { - fprintf(stderr, "Could not get available video modes: %s.\n", - SDL_GetError()); - } - best_dist = 9999999; best_fit = -1; - if (vidmodes == (SDL_Rect **) -1) { + if (num_modes == 0) { /* Any mode is OK. */ - x = setting.xPixels; - y = setting.yPixels; - } else { - for (int i = 0; vidmodes[i]; i++) { - if (setting.xPixels > vidmodes[i]->w || - setting.yPixels > vidmodes[i]->h) + ghost_mode_to_sdl(setting, &mode); + } + else { + for (int i = 0; i < num_modes; i++) { + + SDL_GetDisplayMode(display, i, &mode); + + if (setting.xPixels > mode.w || + setting.yPixels > mode.h) continue; - x = setting.xPixels - vidmodes[i]->w; - y = setting.yPixels - vidmodes[i]->h; + x = setting.xPixels - mode.w; + y = setting.yPixels - mode.h; dist = (x * x) + (y * y); if (dist < best_dist) { best_dist = dist; @@ -189,24 +148,26 @@ GHOST_DisplayManagerSDL:: setCurrentDisplaySetting(GHOST_TUns8 display, if (best_fit == -1) return GHOST_kFailure; - x = vidmodes[best_fit]->w; - y = vidmodes[best_fit]->h; + SDL_GetDisplayMode(display, best_fit, &mode); } -# ifdef _DEBUG - printf("Switching to video mode %dx%d\n", x, y); -# endif + /* evil, SDL2 needs a window to adjust display modes */ + GHOST_WindowSDL *win = (GHOST_WindowSDL *)m_system->getWindowManager()->getActiveWindow(); - // limit us to the main display - static char singleDisplayEnv[] = "SDL_SINGLEDISPLAY=1"; - putenv(singleDisplayEnv); + if (win) { + SDL_Window *sdl_win = win->getSDLWindow(); - // change to the mode - surf = SDL_SetVideoMode(x, y, setting.bpp, SDL_OPENGL | SDL_FULLSCREEN); - if (surf == NULL) { - fprintf(stderr, "Could not set video mode: %s.\n", SDL_GetError()); + + SDL_SetWindowDisplayMode(sdl_win, &mode); + SDL_ShowWindow(sdl_win); + SDL_SetWindowFullscreen(sdl_win, SDL_TRUE); + + return GHOST_kSuccess; + } + else { + /* this is a problem for the BGE player :S, perhaps SDL2 will resolve at some point. + * we really need SDL_SetDisplayModeForDisplay() to become an API func! - campbell */ + printf("no windows available, cant fullscreen"); return GHOST_kFailure; } - - return GHOST_kSuccess; } From 489526477c2e39060f8136fa48de39d91c4c75ed Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Mar 2012 22:27:21 +0000 Subject: [PATCH 055/310] print warning when release/datafiles/locale is missing when building with cmake (git-svn causes this). --- CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bda4b9f133..0c1130ac1aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -292,6 +292,7 @@ if(APPLE) option(WITH_LIBS10.5 "Use 10.5 libs (needed for 64bit builds)" OFF) endif() + #----------------------------------------------------------------------------- # Check for conflicting/unsupported configurations @@ -351,7 +352,14 @@ if(WITH_CYCLES OR WITH_CARVE) set(WITH_BOOST ON) endif() -TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG) +if(WITH_INTERNATIONAL) + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale") + message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, " + "This is an 'svn external', which are known not to work with bridges to other version " + "control systems, disabling 'WITH_INTERNATIONAL'.") + set(WITH_INTERNATIONAL OFF) + endif() +endif() # don't store paths to libs for portable distrobution if(WITH_INSTALL_PORTABLE) @@ -362,6 +370,8 @@ if(WITH_GHOST_SDL OR WITH_HEADLESS) set(WITH_GHOST_XDND OFF) endif() +TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG) + #----------------------------------------------------------------------------- # Initialize un-cached vars, avoid unused warning From a64ee8433a57d961faab1c6eee6107cdedc944b7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Mar 2012 23:28:02 +0000 Subject: [PATCH 056/310] fix [#30493] GE crashes on exit because of using freed mtfaces from tessfaces prevent gpu_draw.c holding a pointer to a freed array. --- source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 1a1e046f54c..66cbcdb914c 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -235,8 +235,12 @@ void KX_BlenderMaterial::OnExit() mTextures[i].DisableUnit(); } - if( mMaterial->tface ) - GPU_set_tpage(mMaterial->tface, 1, mMaterial->alphablend); + /* used to call with 'mMaterial->tface' but this can be a freed array, + * see: [#30493], so just call with NULL, this is best since it clears + * the 'lastface' pointer in GPU too - campbell */ + if (mMaterial->tface) { + GPU_set_tpage(NULL, 1, mMaterial->alphablend); + } } From f80fa544281afb22815ca083d0badd3a9979d17d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 14 Mar 2012 00:30:20 +0000 Subject: [PATCH 057/310] documentation edit to address bmesh py api bug [#30453] warn when addons are not found when running cmake. --- CMakeLists.txt | 31 ++++++++++++++------ source/blender/python/bmesh/bmesh_py_types.c | 5 ++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c1130ac1aa..ddf2f18312c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -352,15 +352,6 @@ if(WITH_CYCLES OR WITH_CARVE) set(WITH_BOOST ON) endif() -if(WITH_INTERNATIONAL) - if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale") - message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, " - "This is an 'svn external', which are known not to work with bridges to other version " - "control systems, disabling 'WITH_INTERNATIONAL'.") - set(WITH_INTERNATIONAL OFF) - endif() -endif() - # don't store paths to libs for portable distrobution if(WITH_INSTALL_PORTABLE) set(CMAKE_SKIP_BUILD_RPATH TRUE) @@ -373,6 +364,28 @@ endif() TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG) +#----------------------------------------------------------------------------- +# Check for valid directories +# ... svn extern paths can be missing because of svn-git. + +if(WITH_INTERNATIONAL) + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale") + message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, " + "This is an 'svn external', which are known not to work with bridges to other version " + "control systems, disabling 'WITH_INTERNATIONAL'.") + set(WITH_INTERNATIONAL OFF) + endif() +endif() + +if(WITH_PYTHON) + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons") + message(WARNING "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, " + "This is an 'svn external', which are known not to work with bridges to other version " + "control systems: * CONTINUING WITHOUT ADDONS *") + set(WITH_INTERNATIONAL OFF) + endif() +endif() + #----------------------------------------------------------------------------- # Initialize un-cached vars, avoid unused warning diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 53f32292cc3..6d4d1b20e7b 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -938,6 +938,11 @@ PyDoc_STRVAR(bpy_bm_elem_select_set_doc, "\n" " :arg select: Select or de-select.\n" " :type select: boolean\n" +"\n" +" .. note::\n" +"\n" +" Currently this only flushes down, so selecting a face will select all its vertices but de-selecting a vertex " +" won't de-select all the faces that use it, before finishing with a mesh typically flushing is still needed.\n" ); static PyObject *bpy_bm_elem_select_set(BPy_BMElem *self, PyObject *value) { From 99f72dfbfcb004418ae3c701f3badfd36996e6e5 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Wed, 14 Mar 2012 03:10:18 +0000 Subject: [PATCH 058/310] Add 'level' field to struct MDisps, companion to 'totdisp'. Gets initialized when loading old files and updated at the same places totdisp is updated. Saves having to do log+sqrt to extract level from totdisp. --- source/blender/blenkernel/intern/customdata.c | 3 +++ source/blender/blenkernel/intern/mesh.c | 1 + source/blender/blenkernel/intern/multires.c | 6 ++++++ source/blender/blenloader/intern/readfile.c | 9 +++++++++ source/blender/bmesh/intern/bmesh_interp.c | 1 + source/blender/bmesh/intern/bmesh_mesh.c | 1 + source/blender/makesdna/DNA_meshdata_types.h | 2 +- 7 files changed, 22 insertions(+), 1 deletion(-) diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 233d0202540..2520c9b666e 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -485,10 +485,12 @@ static void layerCopy_mdisps(const void *source, void *dest, int count) if(s[i].disps) { d[i].disps = MEM_dupallocN(s[i].disps); d[i].totdisp = s[i].totdisp; + d[i].level = s[i].level; } else { d[i].disps = NULL; d[i].totdisp = 0; + d[i].level = 0; } } @@ -504,6 +506,7 @@ static void layerFree_mdisps(void *data, int count, int UNUSED(size)) MEM_freeN(d[i].disps); d[i].disps = NULL; d[i].totdisp = 0; + d[i].level = 0; } } diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 054cbe0021b..6600099fff7 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1877,6 +1877,7 @@ static void bm_corners_to_loops(Mesh *me, int findex, int loopstart, int numTex, for (i=0; itotdisp = side*side; + ld->level = (int)(logf(side - 1.0f) / M_LN2) + 1; if (ld->disps) MEM_freeN(ld->disps); diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 7d50ec6d13a..b708f33537f 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -320,6 +320,7 @@ static void multires_set_tot_mdisps(Mesh *me, int lvl) if (mdisps) { for (i = 0; i < me->totloop; i++, mdisps++) { mdisps->totdisp = multires_grid_tot[lvl]; + mdisps->level = lvl; } } } @@ -338,6 +339,7 @@ static void multires_reallocate_mdisps(int totloop, MDisps *mdisps, int lvl) mdisps[i].disps = disps; mdisps[i].totdisp = totdisp; + mdisps[i].level = lvl; } } @@ -426,6 +428,7 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl) MEM_freeN(mdisp->disps); mdisp->disps = disps; mdisp->totdisp = totdisp; + mdisp->level = lvl; } } } @@ -999,6 +1002,7 @@ void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to) /* when adding new faces in edit mode, need to allocate disps */ if (!mdisp->disps) { mdisp->totdisp = gridSize*gridSize; + mdisp->level = totlvl; mdisp->disps = MEM_callocN(sizeof(float)*3*mdisp->totdisp, "disp in multires_set_space"); } @@ -1224,6 +1228,7 @@ static void old_mdisps_convert(MFace *mface, MDisps *mdisp) MEM_freeN(mdisp->disps); mdisp->totdisp= newtotdisp; + mdisp->level= newlvl; mdisp->disps= disps; } @@ -1252,6 +1257,7 @@ void multires_load_old_250(Mesh *me) for (j=0; j < mf->v4 ? 4 : 3; j++, k++) { mdisps2[k].disps = MEM_callocN(sizeof(float)*3*totdisp, "multires disp in conversion"); mdisps2[k].totdisp = totdisp; + mdisps2[k].level = mdisps[i].level; memcpy(mdisps2[k].disps, mdisps[i].disps + totdisp*j, totdisp); } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 50b8e0997ee..2cbb8a300ed 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3751,6 +3751,15 @@ static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int exte for(i = 0; i < count; ++i) { mdisps[i].disps = newdataadr(fd, mdisps[i].disps); + if (mdisps[i].totdisp && !mdisps[i].level) { + /* this calculation is only correct for loop mdisps; + if loading pre-BMesh face mdisps this will be + overwritten with the correct value in + bm_corners_to_loops() */ + float gridsize = sqrtf(mdisps[i].totdisp); + mdisps[i].level = (int)(logf(gridsize - 1.0f) / M_LN2) + 1; + } + if( (fd->flags & FD_FLAGS_SWITCH_ENDIAN) && (mdisps[i].disps) ) { /* DNA_struct_switch_endian doesn't do endian swap for (*disps)[] */ /* this does swap for data written at write_mdisps() - readfile.c */ diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c index 7074adc324f..5b8b537c669 100644 --- a/source/blender/bmesh/intern/bmesh_interp.c +++ b/source/blender/bmesh/intern/bmesh_interp.c @@ -426,6 +426,7 @@ static void bm_loop_interp_mdisps(BMesh *bm, BMLoop *target, BMFace *source) MDisps *md2 = CustomData_bmesh_get(&bm->ldata, BM_FACE_FIRST_LOOP(source)->head.data, CD_MDISPS); mdisps->totdisp = md2->totdisp; + mdisps->level = md2->level; if (mdisps->totdisp) { mdisps->disps = MEM_callocN(sizeof(float) * 3 * mdisps->totdisp, "mdisp->disps in bmesh_loop_intern_mdisps"); diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index 04279d30e61..096c1fabc5e 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -371,6 +371,7 @@ static void UNUSED_FUNCTION(bm_mdisps_space_set)(Object *ob, BMesh *bm, int from lmd->disps = MEM_dupallocN(mdisps->disps); lmd->totdisp = mdisps->totdisp; + lmd->level = mdisps->level; } mdisps++; diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index 4367d259b1f..f5a8a185556 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -164,7 +164,7 @@ typedef struct OrigSpaceLoop { typedef struct MDisps { /* Strange bug in SDNA: if disps pointer comes first, it fails to see totdisp */ int totdisp; - char pad[4]; + int level; float (*disps)[3]; } MDisps; From f15c15e992a9836a7295166af275522690ada315 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 14 Mar 2012 04:46:12 +0000 Subject: [PATCH 059/310] bmesh py api: finished todo - editable select_history eg: bm.select_history = vert, face, edge bm.select_history.add(edge) --- doc/python_api/rst/include__bmesh.rst | 1 - doc/python_api/sphinx_doc_gen.py | 5 +- source/blender/bmesh/intern/bmesh_marking.c | 14 ++-- source/blender/bmesh/intern/bmesh_marking.h | 1 + source/blender/python/bmesh/bmesh_py_select.c | 71 +++++++++++++++++++ source/blender/python/bmesh/bmesh_py_select.h | 3 + source/blender/python/bmesh/bmesh_py_types.c | 58 ++++++++++----- source/blender/python/bmesh/bmesh_py_types.h | 4 +- source/blender/python/bmesh/bmesh_py_utils.c | 4 +- 9 files changed, 134 insertions(+), 27 deletions(-) diff --git a/doc/python_api/rst/include__bmesh.rst b/doc/python_api/rst/include__bmesh.rst index 1c702275f62..2481c4a739c 100644 --- a/doc/python_api/rst/include__bmesh.rst +++ b/doc/python_api/rst/include__bmesh.rst @@ -33,7 +33,6 @@ For an overview of BMesh data types and how they reference each other see: .. todo:: * add access to BMesh **walkers** - * add access selection history (readonly access done) * add a way to re-tessellate an editmode bmesh. diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py index 49193ad8f22..b15fcd9303b 100644 --- a/doc/python_api/sphinx_doc_gen.py +++ b/doc/python_api/sphinx_doc_gen.py @@ -94,12 +94,13 @@ def handle_args(): usage=SCRIPT_HELP_MSG ) - # optional arguments + # optional arguments parser.add_argument("-o", "--output", dest="output_dir", type=str, default=SCRIPT_DIR, - help="Path of the API docs (default=