6 * $Date: 2012-07-04 23:09:19 +0200 (Mi, 04. Jul 2012) $
7 ***************************************************************/
10 * \brief Implements grid mapping mechanism of class GridLayoutModule
12 * \author Carsten Gutwenger
15 * This file is part of the Open Graph Drawing Framework (OGDF).
19 * See README.txt in the root directory of the OGDF installation for details.
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
44 #include <ogdf/module/GridLayoutModule.h>
50 void GridLayoutModule::call(GraphAttributes
&AG
)
52 const Graph
&G
= AG
.constGraph();
54 // compute grid layout
55 GridLayout
gridLayout(G
);
56 doCall(G
,gridLayout
,m_gridBoundingBox
);
58 // transform grid layout to real layout
59 mapGridLayout(G
,gridLayout
,AG
);
63 void GridLayoutModule::callGrid(const Graph
&G
, GridLayout
&gridLayout
)
66 doCall(G
,gridLayout
,m_gridBoundingBox
);
70 void GridLayoutModule::mapGridLayout(const Graph
&G
,
71 GridLayout
&gridLayout
,
74 double maxWidth
= 0; // maximum width of columns and rows;
79 if (AG
.width (v
) > maxWidth
) maxWidth
= AG
.width (v
);
80 if (AG
.height(v
) > maxWidth
) maxWidth
= AG
.height(v
);
81 if (gridLayout
.y(v
) > yMax
) yMax
= gridLayout
.y(v
);
84 maxWidth
+= m_separation
;
86 // set position of nodes
88 AG
.x(v
) = gridLayout
.x(v
) * maxWidth
;
89 AG
.y(v
) = (yMax
- gridLayout
.y(v
)) * maxWidth
;
92 // transform bend points of edges
95 DPolyline
&dpl
= AG
.bends(e
);
98 IPolyline ipl
= gridLayout
.polyline(e
);
99 ListConstIterator
<IPoint
> it
;
100 for(it
= ipl
.begin(); it
.valid(); ++it
) {
101 const IPoint
&ip
= *it
;
102 dpl
.pushBack(DPoint(ip
.m_x
*maxWidth
, (yMax
-ip
.m_y
)*maxWidth
));
108 void PlanarGridLayoutModule::callFixEmbed(GraphAttributes
&AG
, adjEntry adjExternal
)
110 const Graph
&G
= AG
.constGraph();
112 // compute grid layout
113 GridLayout
gridLayout(G
);
114 doCall(G
,adjExternal
,gridLayout
,m_gridBoundingBox
,true);
116 // transform grid layout to real layout
117 mapGridLayout(G
,gridLayout
,AG
);
121 void PlanarGridLayoutModule::callGridFixEmbed(
123 GridLayout
&gridLayout
,
124 adjEntry adjExternal
)
127 doCall(G
,adjExternal
,gridLayout
,m_gridBoundingBox
,true);
131 void GridLayoutPlanRepModule::callGrid(PlanRep
&PG
, GridLayout
&gridLayout
)
134 doCall(PG
,0,gridLayout
,m_gridBoundingBox
,false);
137 void GridLayoutPlanRepModule::callGridFixEmbed(
139 GridLayout
&gridLayout
,
140 adjEntry adjExternal
)
143 doCall(PG
,adjExternal
,gridLayout
,m_gridBoundingBox
,true);
146 void GridLayoutPlanRepModule::doCall(
148 adjEntry adjExternal
,
149 GridLayout
&gridLayout
,
153 // create temporary graph copy and grid layout
155 PG
.initCC(0); // currently only for a single component!
158 // determine adjacency entry on external face of PG (if required)
159 if(adjExternal
!= 0) {
160 edge eG
= adjExternal
->theEdge();
161 edge ePG
= PG
.copy(eG
);
162 adjExternal
= (adjExternal
== eG
->adjSource()) ? ePG
->adjSource() : ePG
->adjTarget();
165 // call algorithm for copy
166 doCall(PG
,adjExternal
,glPG
,boundingBox
,fixEmbedding
);
168 // extract layout for original graph
171 node vPG
= PG
.copy(v
);
172 gridLayout
.x(v
) = glPG
.x(vPG
);
173 gridLayout
.y(v
) = glPG
.y(vPG
);
178 IPolyline
&ipl
= gridLayout
.bends(e
);
181 ListConstIterator
<edge
> it
;
182 for(it
= PG
.chain(e
).begin(); it
.valid(); ++it
)
183 ipl
.conc(glPG
.bends(*it
));
188 } // end namespace ogdf