- added redraw notifier.
authorCampbell Barton <ideasman42@gmail.com>
Sat, 10 Oct 2009 10:49:17 +0000 (10:49 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 10 Oct 2009 10:49:17 +0000 (10:49 +0000)
- removed custom invoke function, use generic names (was misleading since conversion is done on selection, not just active).
- made convert mesh to curve use the 'keep_original' option.

source/blender/blenkernel/intern/mesh.c
source/blender/editors/object/object_add.c

index ce30075c424a9df2775b597ec89b14a7e3854874..0065c348ad00a643849ebe3c22ddf34ef7468aca 100644 (file)
@@ -983,23 +983,23 @@ void mesh_to_curve(Scene *scene, Object *ob)
        /* make new mesh data from the original copy */
        DerivedMesh *dm= mesh_get_derived_final(scene, ob, CD_MASK_MESH);
 
        /* make new mesh data from the original copy */
        DerivedMesh *dm= mesh_get_derived_final(scene, ob, CD_MASK_MESH);
 
-       MVert *mv, *mverts= dm->getVertArray(dm);
+       MVert *mverts= dm->getVertArray(dm);
        MEdge *med, *medge= dm->getEdgeArray(dm);
        MFace *mf,  *mface= dm->getFaceArray(dm);
 
        MEdge *med, *medge= dm->getEdgeArray(dm);
        MFace *mf,  *mface= dm->getFaceArray(dm);
 
-       int totvert = dm->getNumVerts(dm);
        int totedge = dm->getNumEdges(dm);
        int totface = dm->getNumFaces(dm);
        int totedges = 0;
        int i;
 
        int totedge = dm->getNumEdges(dm);
        int totface = dm->getNumFaces(dm);
        int totedges = 0;
        int i;
 
+       /* only to detect edge polylines */
        EdgeHash *eh = BLI_edgehash_new();
        EdgeHash *eh_edge = BLI_edgehash_new();
 
        EdgeHash *eh = BLI_edgehash_new();
        EdgeHash *eh_edge = BLI_edgehash_new();
 
-       ListBase edges = {NULL, NULL};
-       EdgeLink *edl;
 
 
+       ListBase edges = {NULL, NULL};
 
 
+       /* create edges from all faces (so as to find edges not in any faces) */
        mf= mface;
        for (i = 0; i < totface; i++, mf++) {
                if (!BLI_edgehash_haskey(eh, mf->v1, mf->v2))
        mf= mface;
        for (i = 0; i < totface; i++, mf++) {
                if (!BLI_edgehash_haskey(eh, mf->v1, mf->v2))
@@ -1021,9 +1021,9 @@ void mesh_to_curve(Scene *scene, Object *ob)
        med= medge;
        for(i=0; i<totedge; i++, med++) {
                if (!BLI_edgehash_haskey(eh, med->v1, med->v2)) {
        med= medge;
        for(i=0; i<totedge; i++, med++) {
                if (!BLI_edgehash_haskey(eh, med->v1, med->v2)) {
-                       BLI_edgehash_insert(eh_edge, med->v1, med->v2, NULL);
+                       EdgeLink *edl= MEM_callocN(sizeof(EdgeLink), "EdgeLink");
 
 
-                       edl= MEM_callocN(sizeof(EdgeLink), "EdgeLink");
+                       BLI_edgehash_insert(eh_edge, med->v1, med->v2, NULL);
                        edl->edge= med;
 
                        BLI_addtail(&edges, edl);       totedges++;
                        edl->edge= med;
 
                        BLI_addtail(&edges, edl);       totedges++;
@@ -1037,7 +1037,9 @@ void mesh_to_curve(Scene *scene, Object *ob)
                cu->flag |= CU_3D;
 
                while(edges.first) {
                cu->flag |= CU_3D;
 
                while(edges.first) {
-                       ListBase polyline = {NULL, NULL};
+                       /* each iteration find a polyline and add this as a nurbs poly spline */
+
+                       ListBase polyline = {NULL, NULL}; /* store a list of VertLink's */
                        int closed = FALSE;
                        int totpoly= 0;
                        MEdge *med_current= ((EdgeLink *)edges.last)->edge;
                        int closed = FALSE;
                        int totpoly= 0;
                        MEdge *med_current= ((EdgeLink *)edges.last)->edge;
@@ -1045,43 +1047,40 @@ void mesh_to_curve(Scene *scene, Object *ob)
                        int endVert= med_current->v2;
                        int ok= TRUE;
 
                        int endVert= med_current->v2;
                        int ok= TRUE;
 
-                       Nurb *nu;
-                       BPoint *bp;
-                       VertLink *vl;
-
                        appendPolyLineVert(&polyline, startVert);       totpoly++;
                        appendPolyLineVert(&polyline, endVert);         totpoly++;
                        BLI_freelinkN(&edges, edges.last);                      totedges--;
 
                        appendPolyLineVert(&polyline, startVert);       totpoly++;
                        appendPolyLineVert(&polyline, endVert);         totpoly++;
                        BLI_freelinkN(&edges, edges.last);                      totedges--;
 
-
-                       while(ok) {
+                       while(ok) { /* while connected edges are found... */
                                ok = FALSE;
                                i= totedges;
                                while(i) {
                                ok = FALSE;
                                i= totedges;
                                while(i) {
-                                       MEdge *ed= edl->edge;
+                                       EdgeLink *edl;
+
                                        i-=1;
                                        edl= BLI_findlink(&edges, i);
                                        i-=1;
                                        edl= BLI_findlink(&edges, i);
+                                       med= edl->edge;
 
 
-                                       if(ed->v1==endVert) {
-                                               endVert = ed->v2;
-                                               appendPolyLineVert(&polyline, ed->v2);  totpoly++;
+                                       if(med->v1==endVert) {
+                                               endVert = med->v2;
+                                               appendPolyLineVert(&polyline, med->v2); totpoly++;
                                                BLI_freelinkN(&edges, edl);                             totedges--;
                                                ok= TRUE;
                                        }
                                                BLI_freelinkN(&edges, edl);                             totedges--;
                                                ok= TRUE;
                                        }
-                                       else if(ed->v2==endVert) {
-                                               endVert = ed->v1;
+                                       else if(med->v2==endVert) {
+                                               endVert = med->v1;
                                                appendPolyLineVert(&polyline, endVert); totpoly++;
                                                BLI_freelinkN(&edges, edl);                             totedges--;
                                                ok= TRUE;
                                        }
                                                appendPolyLineVert(&polyline, endVert); totpoly++;
                                                BLI_freelinkN(&edges, edl);                             totedges--;
                                                ok= TRUE;
                                        }
-                                       else if(ed->v1==startVert) {
-                                               startVert = ed->v2;
+                                       else if(med->v1==startVert) {
+                                               startVert = med->v2;
                                                prependPolyLineVert(&polyline, startVert);      totpoly++;
                                                BLI_freelinkN(&edges, edl);                                     totedges--;
                                                ok= TRUE;
                                        }
                                                prependPolyLineVert(&polyline, startVert);      totpoly++;
                                                BLI_freelinkN(&edges, edl);                                     totedges--;
                                                ok= TRUE;
                                        }
-                                       else if(ed->v2==startVert) {
-                                               startVert = ed->v1;
+                                       else if(med->v2==startVert) {
+                                               startVert = med->v1;
                                                prependPolyLineVert(&polyline, startVert);      totpoly++;
                                                BLI_freelinkN(&edges, edl);                                     totedges--;
                                                ok= TRUE;
                                                prependPolyLineVert(&polyline, startVert);      totpoly++;
                                                BLI_freelinkN(&edges, edl);                                     totedges--;
                                                ok= TRUE;
@@ -1097,32 +1096,38 @@ void mesh_to_curve(Scene *scene, Object *ob)
                        }
 
                        /* --- nurbs --- */
                        }
 
                        /* --- nurbs --- */
+                       {
+                               Nurb *nu;
+                               BPoint *bp;
+                               VertLink *vl;
+
+                               /* create new 'nurb' within the curve */
+                               nu = (Nurb *)MEM_callocN(sizeof(Nurb), "MeshNurb");
+
+                               nu->pntsu= totpoly;
+                               nu->pntsv= 1;
+                               nu->orderu= 4;
+                               nu->flagu= 2 | (closed ? CU_CYCLIC:0);  /* endpoint */
+                               nu->resolu= 12;
+
+                               nu->bp= (BPoint *)MEM_callocN(sizeof(BPoint)*totpoly, "bpoints");
+
+                               /* add points */
+                               vl= polyline.first;
+                               for (i=0, bp=nu->bp; i < totpoly; i++, bp++, vl=(VertLink *)vl->next) {
+                                       VecCopyf(bp->vec, mverts[vl->index].co);
+                                       bp->f1= SELECT;
+                                       bp->radius = bp->weight = 1.0;
+                               }
+                               BLI_freelistN(&polyline);
 
 
-                       /* create new 'nurb' within the curve */
-                       nu = (Nurb *)MEM_callocN(sizeof(Nurb), "MeshNurb");
-
-                       nu->pntsu= totpoly;
-                       nu->pntsv= 1;
-                       nu->orderu= 4;
-                       nu->flagu= 2 | (closed ? CU_CYCLIC:0);  /* endpoint */
-                       nu->resolu= 12;
-
-                       nu->bp= (BPoint *)MEM_callocN(sizeof(BPoint)*totpoly, "bpoints");
-
-                       /* add points */
-                       vl= polyline.first;
-                       for (i=0, bp=nu->bp; i < totpoly; i++, bp++, vl=vl->next) {
-                               VecCopyf(bp->vec, mverts[vl->index].co);
-                               bp->f1= SELECT;
-                               bp->radius = bp->weight = 1.0;
+                               /* add nurb to curve */
+                               BLI_addtail(&cu->nurb, nu);
                        }
                        }
-                       BLI_freelistN(&polyline);
-
-                       /* add nurb to curve */
-                       BLI_addtail(&cu->nurb, nu);
                        /* --- done with nurbs --- */
                }
 
                        /* --- done with nurbs --- */
                }
 
+               ((Mesh *)ob->data)->id.us--;
                ob->data= cu;
                ob->type= OB_CURVE;
        }
                ob->data= cu;
                ob->type= OB_CURVE;
        }
index 47053ea6d9339d66b6be6fe9d2540cc63f8f3dac..0b7dbf791e03190937dab90391ea74224e40dc61 100644 (file)
@@ -1018,8 +1018,8 @@ void OBJECT_OT_duplicates_make_real(wmOperatorType *ot)
 /**************************** Convert **************************/
 
 static EnumPropertyItem convert_target_items[]= {
 /**************************** Convert **************************/
 
 static EnumPropertyItem convert_target_items[]= {
-       {OB_CURVE, "CURVE", 0, "Curve", ""},
-       {OB_MESH, "MESH", 0, "Mesh", ""},
+       {OB_CURVE, "CURVE", ICON_OUTLINER_OB_CURVE, "Curve from Mesh/Text", ""},
+       {OB_MESH, "MESH", ICON_OUTLINER_OB_MESH, "Mesh from Curve/Meta/Surf/Mesh", ""},
        {0, NULL, 0, NULL, NULL}};
 
 static void curvetomesh(Scene *scene, Object *ob) 
        {0, NULL, 0, NULL, NULL}};
 
 static void curvetomesh(Scene *scene, Object *ob) 
@@ -1035,14 +1035,6 @@ static void curvetomesh(Scene *scene, Object *ob)
                object_free_modifiers(ob);
 }
 
                object_free_modifiers(ob);
 }
 
-static void meshtocurve(Scene *scene, Object *ob)
-{
-       mesh_to_curve(scene, ob);
-
-       if(ob->type == OB_CURVE)
-               object_free_modifiers(ob);
-}
-
 static int convert_poll(bContext *C)
 {
        Object *obact= CTX_data_active_object(C);
 static int convert_poll(bContext *C)
 {
        Object *obact= CTX_data_active_object(C);
@@ -1081,8 +1073,22 @@ static int convert_exec(bContext *C, wmOperator *op)
                        continue;
                else if (ob->type==OB_MESH && target == OB_CURVE) {
                        ob->flag |= OB_DONE;
                        continue;
                else if (ob->type==OB_MESH && target == OB_CURVE) {
                        ob->flag |= OB_DONE;
-                       meshtocurve(scene, ob);
-                       ob->recalc |= OB_RECALC;
+
+                       ob1= copy_object(ob);
+                       ob1->recalc |= OB_RECALC;
+
+                       basen= MEM_mallocN(sizeof(Base), "duplibase");
+                       *basen= *base;
+                       BLI_addhead(&scene->base, basen);       /* addhead: otherwise eternal loop */
+                       basen->object= ob1;
+                       basen->flag |= SELECT;
+                       base->flag &= ~SELECT;
+                       ob->flag &= ~SELECT;
+
+                       mesh_to_curve(scene, ob1);
+
+                       if(ob1->type==OB_CURVE)
+                               object_free_modifiers(ob1);     /* after derivedmesh calls! */
                }
                else if(ob->type==OB_MESH && ob->modifiers.first) { /* converting a mesh with no modifiers causes a segfault */
                        ob->flag |= OB_DONE;
                }
                else if(ob->type==OB_MESH && ob->modifiers.first) { /* converting a mesh with no modifiers causes a segfault */
                        ob->flag |= OB_DONE;
@@ -1233,48 +1239,14 @@ static int convert_exec(bContext *C, wmOperator *op)
        BASACT= basact;
 
        DAG_scene_sort(scene);
        BASACT= basact;
 
        DAG_scene_sort(scene);
-       WM_event_add_notifier(C, NC_SCENE, scene);
+       WM_event_add_notifier(C, NC_SCENE|ND_DRAW, scene);
 
 
-       return OPERATOR_FINISHED;
-}
-
-static int convert_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       Object *obact= CTX_data_active_object(C);
-       uiPopupMenu *pup;
-       uiLayout *layout;
-       char *title;
-
-       if(obact->type==OB_FONT) {
-               pup= uiPupMenuBegin(C, "Convert Font to", 0);
-               layout= uiPupMenuLayout(pup);
 
 
-               uiItemEnumO(layout, "Curve", 0, op->type->idname, "target", OB_CURVE);
-       }
-       else {
-               if(obact->type == OB_MBALL)
-                       title= "Convert Metaball to";
-               else if(obact->type == OB_CURVE)
-                       title= "Convert Curve to";
-               else if(obact->type == OB_SURF)
-                       title= "Convert Nurbs Surface to";
-               else if(obact->type == OB_MESH)
-                       title= "Convert Modifiers to";
-               else
-                       return OPERATOR_CANCELLED;
 
 
-               pup= uiPupMenuBegin(C, title, 0);
-               layout= uiPupMenuLayout(pup);
-       }
-
-       uiItemBooleanO(layout, "Mesh (keep original)", 0, op->type->idname, "keep_original", 1);
-       uiItemBooleanO(layout, "Mesh (delete original)", 0, op->type->idname, "keep_original", 0);
-
-       uiPupMenuEnd(C, pup);
-
-       return OPERATOR_CANCELLED;
+       return OPERATOR_FINISHED;
 }
 
 }
 
+
 void OBJECT_OT_convert(wmOperatorType *ot)
 {
        /* identifiers */
 void OBJECT_OT_convert(wmOperatorType *ot)
 {
        /* identifiers */
@@ -1283,7 +1255,7 @@ void OBJECT_OT_convert(wmOperatorType *ot)
        ot->idname= "OBJECT_OT_convert";
        
        /* api callbacks */
        ot->idname= "OBJECT_OT_convert";
        
        /* api callbacks */
-       ot->invoke= convert_invoke;
+       ot->invoke= WM_menu_invoke;
        ot->exec= convert_exec;
        ot->poll= convert_poll;
        
        ot->exec= convert_exec;
        ot->poll= convert_poll;