diff --git a/example/python/vis.py b/example/python/vis.py index 4076121f..c40337ad 100644 --- a/example/python/vis.py +++ b/example/python/vis.py @@ -36,8 +36,8 @@ class GraphCanvas(ogl.ShapeCanvas): self.position_map = position_map self.property_maps = property_maps self.vertex_position_rect = self.compute_rect() - self.vertex_to_shape = graph.get_vertex_object_map("shape") - self.edge_to_shape = graph.get_edge_object_map("shape") + self.vertex_to_shape = graph.get_vertex_object_map("__stored_shape") + self.edge_to_shape = graph.get_edge_object_map("__stored_shape") self.shape_to_vertex = {} for v in graph.vertices: @@ -611,7 +611,10 @@ class GraphEditorWindow(wx.Frame): defaultFile="", wildcard=wildcard, style=wx.OPEN | wx.CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() - graph = bgl.Graph(path, bgl.file_kind.graphviz) + try: + graph = bgl.Graph(path, bgl.file_kind.graphviz) + except bgl.directed_graph_error: + graph = bgl.Digraph(path, bgl.file_kind.graphviz) needs_layout = not graph.has_vertex_map("position") position_map = graph.get_vertex_point2d_map("position") if needs_layout: diff --git a/src/python/circle_layout.cpp b/src/python/circle_layout.cpp index bc8ee2a3..1f2d8e34 100644 --- a/src/python/circle_layout.cpp +++ b/src/python/circle_layout.cpp @@ -40,6 +40,13 @@ void export_circle_graph_layout() arg("position") = (vector_property_map*)0, arg("radius") = 250.0)); + + def("circle_graph_layout", + &circle_graph_layout, + (arg("graph"), + arg("position") = + (vector_property_map*)0, + arg("radius") = 250.0)); } } } } // end namespace boost::graph::python diff --git a/src/python/graphviz.cpp b/src/python/graphviz.cpp index 77db2404..0433fd13 100644 --- a/src/python/graphviz.cpp +++ b/src/python/graphviz.cpp @@ -8,7 +8,9 @@ // Andrew Lumsdaine #include "basic_graph.hpp" #include +#include #include +#include namespace boost { namespace graph { namespace python { @@ -35,6 +37,61 @@ basic_graph::write_graphviz(const std::string& filename, boost::write_graphviz(out, *this, dp, node_id, get_vertex_index_map()); } +template +class translate_exception +{ + explicit translate_exception(boost::python::object type) : type(type) { } + +public: + template + static void declare(const char* name) + { + using boost::python::class_; + using boost::python::bases; + + declare(class_ >(name)); + } + + static void declare(boost::python::object type) + { + using boost::python::register_exception_translator; + register_exception_translator(translate_exception(type)); + } + + void operator()(const E& e) const + { + using boost::python::object; + PyErr_SetObject(type.ptr(), object(e).ptr()); + } + +private: + boost::python::object type; +}; + +void export_graphviz() +{ + using boost::python::class_; + using boost::python::bases; + using boost::python::init; + using boost::python::no_init; + using boost::python::object; + + object ge_type = + class_("graph_exception", no_init); + translate_exception::declare(ge_type); + + object bpe_type = + class_ >("bad_parallel_edge", + no_init) + .def(init()); + translate_exception::declare(bpe_type); + + translate_exception + ::declare("directed_graph_error"); + translate_exception + ::declare("undirected_graph_error"); +} + // Explicit instantiations template void diff --git a/src/python/module.cpp b/src/python/module.cpp index 02615d65..3ba84d59 100644 --- a/src/python/module.cpp +++ b/src/python/module.cpp @@ -17,8 +17,7 @@ namespace boost { namespace graph { namespace python { extern void export_Graph(); extern void export_Digraph(); -extern void export_betweenness_centrality(); -extern void export_page_rank(); +extern void export_graphviz(); extern void export_breadth_first_search(); extern void export_depth_first_search(); extern void export_dijkstra_shortest_paths(); @@ -30,7 +29,7 @@ template void export_depth_first_search_in_graph(); template void export_dijkstra_shortest_paths_in_graph(); template void export_dag_shortest_paths_in_graph(); template void export_bellman_ford_shortest_paths_in_graph(); - template void export_prim_minimum_spanning_tree_in_graph(); +template void export_prim_minimum_spanning_tree_in_graph(); extern void export_connected_components(); extern void export_strong_components(); extern void export_biconnected_components(); @@ -39,6 +38,8 @@ extern void export_topological_sort(); extern void export_cuthill_mckee_ordering(); //extern void export_minimum_degree_ordering(); extern void export_sequential_vertex_coloring(); +extern void export_betweenness_centrality(); +extern void export_page_rank(); extern void export_circle_graph_layout(); extern void export_fruchterman_reingold_force_directed_layout(); extern void export_kamada_kawai_spring_layout(); @@ -99,8 +100,7 @@ BOOST_PYTHON_MODULE(bgl) export_Graph(); export_Digraph(); - export_betweenness_centrality(); - export_page_rank(); + export_graphviz(); // Core Algorithm Patterns export_breadth_first_search(); export_depth_first_search(); @@ -125,6 +125,8 @@ BOOST_PYTHON_MODULE(bgl) export_topological_sort(); export_transitive_closure(); export_sequential_vertex_coloring(); + export_betweenness_centrality(); + export_page_rank(); // Layout Algorithms export_circle_graph_layout();