1
14 package demo.layout.module;
15
16 import y.module.LayoutModule;
17 import y.module.YModule;
18
19 import y.base.EdgeMap;
20 import y.layout.BendConverter;
21 import y.layout.CompositeLayoutStage;
22 import y.layout.LayoutStage;
23 import y.layout.Layouter;
24 import y.layout.SequentialLayouter;
25 import y.layout.grouping.GroupNodeHider;
26 import y.layout.organic.RemoveOverlapsLayoutStage;
27 import y.layout.router.OrganicEdgeRouter;
28 import y.option.OptionGroup;
29 import y.option.OptionHandler;
30 import y.view.Selections;
31
32
35 public class OrganicEdgeRouterModule extends LayoutModule
36 {
37 private static final String ORGANIC_EDGE_ROUTER = "ORGANIC_EDGE_ROUTER";
38 private static final String MINIMAL_NODE_DISTANCE = "MINIMAL_NODE_DISTANCE";
39 private static final String USE_BENDS = "USE_BENDS";
40 private static final String ROUTE_ONLY_NECESSARY = "ROUTE_ONLY_NECESSARY";
41 private static final String SELECTION_ONLY = "SELECTION_ONLY";
42 private static final String ALLOW_MOVING_NODES = "ALLOW_MOVING_NODES";
43
44 private static final String LAYOUT_OPTIONS = "LAYOUT_OPTIONS";
45
46
47
50 public OrganicEdgeRouterModule()
51 {
52 super(ORGANIC_EDGE_ROUTER, "Sebastian Mueller", "Routes edges organically");
53 }
54
55
59 public OptionHandler createOptionHandler()
60 {
61 OrganicEdgeRouter router = new OrganicEdgeRouter();
62
63 OptionHandler op = new OptionHandler(getModuleName());
64 OptionGroup og = new OptionGroup();
65 og.setAttribute(OptionGroup.ATTRIBUTE_TITLE, LAYOUT_OPTIONS);
66 og.addItem(op.addBool(SELECTION_ONLY, false));
67 og.addItem(op.addInt(MINIMAL_NODE_DISTANCE, (int)router.getMinimalDistance(), 10, 300));
68 og.addItem(op.addBool(USE_BENDS, router.isUsingBends()));
69 og.addItem(op.addBool(ROUTE_ONLY_NECESSARY, !router.isRoutingAll()));
70 og.addItem(op.addBool(ALLOW_MOVING_NODES, false));
71 return op;
72 }
73
74
77 protected void mainrun()
78 {
79 final OrganicEdgeRouter router = new OrganicEdgeRouter();
80 OptionHandler op = getOptionHandler();
81 router.setMinimalDistance(op.getInt(MINIMAL_NODE_DISTANCE));
82 router.setUsingBends(op.getBool(USE_BENDS));
83 router.setRoutingAll(!op.getBool(ROUTE_ONLY_NECESSARY));
84
85 RemoveOverlapsLayoutStage rmos = new RemoveOverlapsLayoutStage(0);
86 LayoutStage nodeEnlarger = router.createNodeEnlargementStage();
87 final CompositeLayoutStage cls = new CompositeLayoutStage();
88 cls.appendStage(nodeEnlarger);
89 if (router.isUsingBends()) {
90 cls.appendStage(new BendConverter());
91 }
92 cls.appendStage(rmos);
93
94 final SequentialLayouter sl = new SequentialLayouter();
95 if(op.getBool(ALLOW_MOVING_NODES)) {
96 sl.appendLayouter(cls);
97 }
98 sl.appendLayouter(router);
99 Layouter custom = new GroupNodeHider(sl);
100
101 if (op.getBool(SELECTION_ONLY)) {
103 EdgeMap nm = Selections.createSelectionEdgeMap(getGraph2D());
104 getGraph2D().addDataProvider(OrganicEdgeRouter.ROUTE_EDGE_DPKEY, nm);
105 launchLayouter(custom);
106 getGraph2D().removeDataProvider(OrganicEdgeRouter.ROUTE_EDGE_DPKEY);
107 } else {
108 launchLayouter(custom);
109 }
110 }
111 }
112
113
114
115
116
117