1   /****************************************************************************
2    **
3    ** This file is part of yFiles-2.9. 
4    ** 
5    ** yWorks proprietary/confidential. Use is subject to license terms.
6    **
7    ** Redistribution of this file or of an unauthorized byte-code version
8    ** of this file is strictly forbidden.
9    **
10   ** Copyright (c) 2000-2011 by yWorks GmbH, Vor dem Kreuzberg 28, 
11   ** 72070 Tuebingen, Germany. All rights reserved.
12   **
13   ***************************************************************************/
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  /**
33   * Module for the Organic Edge Router Algorithm.
34   */
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    /**
48     * Creates a new Instance of this Module.
49     */
50    public OrganicEdgeRouterModule()
51    {
52      super(ORGANIC_EDGE_ROUTER, "Sebastian Mueller", "Routes edges organically");
53    }
54    
55    /**
56     * Creates an option handler for this module that
57     * manages options for the force transfer algorithm.
58     */
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    /**
75     * Launches this module.
76     */
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     // register grouping relevant DataProviders
102     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