Autolayout plug-in (was: Re: Dia Automatic Layouting)



Am 05.08.2008 21:22, Fred Morcos schrieb:
Patch attached. Taken off revision 4102 from Dia's root dir using svn diff.

Thanks for the patch. I have played with it a bit but am still not able to completely wrap my head around it. Here is what I think I have understood:

 * Repulsion is calculated as a force between the current node and
   every other node - be it connected or not.
 * Attraction is calculated only between the current and it's
   directly connected nodes.
 * The calcualtion is done for every node in the graph and
   applied instantly. During one loop the only state accumulated is
   the overall graph energy.
 * The above is repeated until a maximum number of iterations is reached
   or the energy falls below a certain value.
 * There is no state outside of the diagram (here: the modified object
   positions) shared between different iterations

The graph is constructed from the diagram('s selection) by translating (only connected) connection objects to edges and the other objects to nodes. The only additional parameters taken from the diagram are 'mass of node' (currently defined as Object::bounding_box area), their position and the distance between the nodes (currently defined as the distance between the Object::position).

If the above summary is right the intermediate 'Graph' allocation is only needed for convenience and as a cache to avoid the recalculation of node masses. To verify my assumptions I have reimplemented the functionality as a PyDia plug-in, and indeed it gave the same result for everthing I have tested. I hope it is useful to illustrate the remaining open questions regarding Handle, ConnectionPoint an Object relation better than my previous attempts ;-)


Your current patch adds the algorithm to lib/ and its dialog to app/. My gut feeling is both should be added together into a new plug-in/autolayout. The necessary glue code is attached. I only have integrated it with the
win32/msvc build yet.


There are also some formal aspects with your patch which need to be addressed before it is ready for inclusion with Dia.

 * please use tab-width 8 (apparently you used 4)
 * the first file to include in every .c file is config.h
 * prototypes only used in a single file should be declared locally
   and static
 * a function name in the implementation should start at the beginning
   of a line, the return value is on it's own line
 * every user-visble string needs to be marked for translation,
   e.g. _(""Spacing:"")
 * some variable naming looked strange to me, e.g. 'Graph diagram;'
   IMHO this make the code unnecessary harder to understand.


The undo thing and other things I've forgotten is left for another mail. I think this one is already long enough ;)

Regards,
        Hans

-------- Hans "at" Breuer "dot" Org -----------
Tell me what you need, and I'll tell you how to
get along without it.                -- Dilbert
/* Dia -- an diagram creation/manipulation program
 * Copyright (C) 1998 Alexander Larsson
 *
 * autolayout-register.c -  registeration of auto-layout algoritms as plug-in
 * Copyright (c) 2008 Hans Breuer <hans breuer org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * 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.
 */
#include <config.h>

#include "intl.h"
#include "message.h"
#include "filter.h"
#include "plug-ins.h"

#include "autolayout-force.h"

static void
autolayout_force_callback (DiagramData *data,
                           const gchar *filename,
                           guint flags, /* further additions */
                           void *user_data)
{
  //FIXME: make use of the passed in parameters
  objects_layout_callback (NULL);
}

static DiaCallbackFilter cb_auto_layout_force = {
    "AutoLayoutForce",
    N_("Layout (force) ..."),
    "/DisplayMenu/Objects/Layout/LayoutForce",
    autolayout_force_callback,
    NULL
};

static gboolean
_plugin_can_unload (PluginInfo *info)
{
  /* there is no filter_unregister_callback yet */
  return FALSE;
}

static void
_plugin_unload (PluginInfo *info)
{
}

/* --- dia plug-in interface --- */

DIA_PLUGIN_CHECK_INIT

PluginInitResult
dia_plugin_init(PluginInfo *info)
{
  if (!dia_plugin_info_init(info, "AutoLayout",
                            _("Layout Algorithms"),
                            _plugin_can_unload,
                            _plugin_unload))
    return DIA_PLUGIN_INIT_ERROR;

  filter_register_callback (&cb_auto_layout_force);

  return DIA_PLUGIN_INIT_OK;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]