/*************************************************************************
 * Copyright (c) 2011 AT&T Intellectual Property
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 *
 * Contributors: Details at https://graphviz.org
 *************************************************************************/

#include "config.h"

#include <stdio.h>

#include <gvc/gvplugin_layout.h>

// FIXME - globals.h is needed for Nop
#include <common/globals.h>

typedef enum {
  LAYOUT_NEATO,
  LAYOUT_FDP,
  LAYOUT_SFDP,
  LAYOUT_TWOPI,
  LAYOUT_CIRCO,
  LAYOUT_PATCHWORK,
  LAYOUT_CLUSTER,
  LAYOUT_NOP1,
  LAYOUT_NOP2,
} layout_type;

extern void neato_layout(graph_t *g);
extern void fdp_layout(graph_t *g);
extern void sfdp_layout(graph_t *g);
extern void twopi_layout(graph_t *g);
extern void circo_layout(graph_t *g);
extern void patchwork_layout(graph_t *g);
extern void osage_layout(graph_t *g);

extern void neato_cleanup(graph_t *g);
extern void fdp_cleanup(graph_t *g);
extern void sfdp_cleanup(graph_t *g);
extern void twopi_cleanup(graph_t *g);
extern void circo_cleanup(graph_t *g);
extern void patchwork_cleanup(graph_t *g);
extern void osage_cleanup(graph_t *g);

static void nop1_layout(graph_t *g) {
  Nop = 1;
  neato_layout(g);
  Nop = 0;
}

static void nop2_layout(graph_t *g) {
  Nop = 2;
  neato_layout(g);
  Nop = 0;
}

static gvlayout_engine_t neatogen_engine = {
    neato_layout,
    neato_cleanup,
};

static gvlayout_engine_t fdpgen_engine = {
    fdp_layout,
    fdp_cleanup,
};

#ifdef SFDP
static gvlayout_engine_t sfdpgen_engine = {
    sfdp_layout,
    sfdp_cleanup,
};
#endif

static gvlayout_engine_t twopigen_engine = {
    twopi_layout,
    twopi_cleanup,
};

static gvlayout_engine_t circogen_engine = {
    circo_layout,
    circo_cleanup,
};

static gvlayout_engine_t nop1gen_engine = {
    nop1_layout,
    neato_cleanup,
};

static gvlayout_engine_t nop2gen_engine = {
    nop2_layout,
    neato_cleanup,
};

static gvlayout_engine_t patchwork_engine = {
    patchwork_layout,
    patchwork_cleanup,
};

static gvlayout_engine_t osage_engine = {
    osage_layout,
    osage_cleanup,
};

static gvlayout_features_t neatogen_features = {
    0,
};

gvplugin_installed_t gvlayout_neato_types[] = {
    {LAYOUT_NEATO, "neato", 0, &neatogen_engine, &neatogen_features},
    {LAYOUT_FDP, "fdp", 0, &fdpgen_engine, &neatogen_features},
#ifdef SFDP
    {LAYOUT_SFDP, "sfdp", 0, &sfdpgen_engine, &neatogen_features},
#endif
    {LAYOUT_TWOPI, "twopi", 0, &twopigen_engine, &neatogen_features},
    {LAYOUT_CIRCO, "circo", 0, &circogen_engine, &neatogen_features},
    {LAYOUT_PATCHWORK, "patchwork", 0, &patchwork_engine, &neatogen_features},
    {LAYOUT_CLUSTER, "osage", 0, &osage_engine, &neatogen_features},
    {LAYOUT_NOP1, "nop", 0, &nop1gen_engine, &neatogen_features},
    {LAYOUT_NOP1, "nop1", 0, &nop1gen_engine, &neatogen_features},
    {LAYOUT_NOP2, "nop2", 0, &nop2gen_engine, &neatogen_features},
    {0, NULL, 0, NULL, NULL}};
