diff --git a/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java b/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java index f0a42ba1..eff29d66 100755 --- a/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java +++ b/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java @@ -47,7 +47,10 @@ public class FreemindImporter implements Importer { public static final String CODE_VERSION = "pela"; - public static final int HALF_ROOT_TOPICS_SEPARATION = 25; + public static final int SECOND_LEVEL_TOPIC_HEIGHT = 25; + public static final int ROOT_LEVEL_TOPIC_HEIGHT = SECOND_LEVEL_TOPIC_HEIGHT; + public static final int CENTRAL_TO_TOPIC_DISTANCE = 200; + public static final int TOPIC_TO_TOPIC_DISTANCE = 90; private com.wisemapping.xml.mindmap.ObjectFactory mindmapObjectFactory; private static final String POSITION_LEFT = "left"; private static final String BOLD = "bold"; @@ -133,7 +136,8 @@ public class FreemindImporter convertChildNodes(freeNode, wiseTopic, 1); - addRelationships(mindmapMap); + // @Todo: Pablo, tenemos que ver como arreglamos esto. No estoy seteando a los hijos la posicion. + //addRelationships(mindmapMap); JAXBUtils.saveMap(mindmapMap, baos, "com.wisemapping.xml.mindmap"); @@ -173,49 +177,36 @@ public class FreemindImporter } } - private void fixRelationshipControlPoints(@NotNull RelationshipType relationship) { + private void fixRelationshipControlPoints(@NotNull RelationshipType rel) { //Both relationship node's ids should be freemind ones at this point. - TopicType srcTopic = nodesMap.get(relationship.getSrcTopicId()); - TopicType destTopicType = nodesMap.get(relationship.getDestTopicId()); + TopicType srcTopic = nodesMap.get(rel.getSrcTopicId()); + TopicType destTopicType = nodesMap.get(rel.getDestTopicId()); //Fix x coord - if (isOnLeftSide(srcTopic)) { - String[] srcCtrlPoint = relationship.getSrcCtrlPoint().split(","); - int x = Integer.valueOf(srcCtrlPoint[0]) * -1; - relationship.setSrcCtrlPoint(x + "," + srcCtrlPoint[1]); + final Coord srcCtrlCoord = Coord.parse(rel.getSrcCtrlPoint()); + final Coord destCtrlCoord = Coord.parse(rel.getDestCtrlPoint()); + + if (Coord.parse(srcTopic.getPosition()).isOnLeftSide()) { + int x = srcCtrlCoord.x * -1; + rel.setSrcCtrlPoint(x + "," + srcCtrlCoord.y); } - if (isOnLeftSide(destTopicType)) { - String[] destCtrlPoint = relationship.getDestCtrlPoint().split(","); - int x = Integer.valueOf(destCtrlPoint[0]) * -1; - relationship.setDestCtrlPoint(x + "," + destCtrlPoint[1]); + if (Coord.parse(destTopicType.getPosition()).isOnLeftSide()) { + int x = destCtrlCoord.x * -1; + rel.setDestCtrlPoint(x + "," + destCtrlCoord.y); } //Fix coord - if (srcTopic.getOrder()!=null && srcTopic.getOrder() % 2 != 0) { //Odd order. - String[] srcCtrlPoint = relationship.getSrcCtrlPoint().split(","); - int y = Integer.valueOf(srcCtrlPoint[1]) * -1; - relationship.setSrcCtrlPoint(srcCtrlPoint[0] + "," + y); + if (srcTopic.getOrder() != null && srcTopic.getOrder() % 2 != 0) { //Odd order. + int y = srcCtrlCoord.y * -1; + rel.setSrcCtrlPoint(srcCtrlCoord.x + "," + y); } - if (destTopicType.getOrder()!=null && destTopicType.getOrder() % 2 != 0) { //Odd order. - String[] destCtrlPoint = relationship.getDestCtrlPoint().split(","); - int y = Integer.valueOf(destCtrlPoint[1]) * -1; - relationship.setDestCtrlPoint(destCtrlPoint[0] + "," + y); + if (destTopicType.getOrder() != null && destTopicType.getOrder() % 2 != 0) { //Odd order. + int y = destCtrlCoord.y * -1; + rel.setDestCtrlPoint(destCtrlCoord.x + "," + y); } } - private boolean isOnLeftSide(TopicType topic) { - String[] position = topic.getPosition().split(","); - int x = Integer.parseInt(position[0]); - return x < 0; - } - - private boolean isOnLeftSide(@NotNull String pos) { - String[] position = pos.split(","); - int x = Integer.parseInt(position[0]); - return x < 0; - } - private void convertChildNodes(@NotNull Node freeParent, @NotNull TopicType wiseParent, final int depth) { final List freeChilden = freeParent.getArrowlinkOrCloudOrEdge(); TopicType currentWiseTopic = wiseParent; @@ -242,9 +233,14 @@ public class FreemindImporter } wiseChild.setOrder(norder); - // Convert node position ... - final String position = convertPosition(wiseParent, freeChild, depth, norder); - wiseChild.setPosition(position); + + // @Todo: This is required in the old layout. Pablo, we need to discuss this. + if (depth == 1) { + // Convert node position + int childrenCount = freeChilden.size(); + final String position = convertPosition(wiseParent, freeChild, depth, norder, childrenCount); + wiseChild.setPosition(position); + } // Convert the rest of the node properties ... convertNodeProperties(freeChild, wiseChild); @@ -305,29 +301,40 @@ public class FreemindImporter } } else if (element instanceof Arrowlink) { final Arrowlink arrow = (Arrowlink) element; - RelationshipType relationship = mindmapObjectFactory.createRelationshipType(); + RelationshipType relt = mindmapObjectFactory.createRelationshipType(); String destId = arrow.getDESTINATION(); - relationship.setSrcTopicId(freeParent.getID()); - relationship.setDestTopicId(destId); + relt.setSrcTopicId(freeParent.getID()); + relt.setDestTopicId(destId); String[] inclination = arrow.getENDINCLINATION().split(";"); - relationship.setDestCtrlPoint(inclination[0] + "," + inclination[1]); + relt.setDestCtrlPoint(inclination[0] + "," + inclination[1]); inclination = arrow.getSTARTINCLINATION().split(";"); - relationship.setSrcCtrlPoint(inclination[0] + "," + inclination[1]); + relt.setSrcCtrlPoint(inclination[0] + "," + inclination[1]); //relationship.setCtrlPointRelative(true); - relationship.setEndArrow(!arrow.getENDARROW().toLowerCase().equals("none")); - relationship.setStartArrow(!arrow.getSTARTARROW().toLowerCase().equals("none")); - relationship.setLineType("3"); - relationships.add(relationship); + relt.setEndArrow(!arrow.getENDARROW().toLowerCase().equals("none")); + relt.setStartArrow(!arrow.getSTARTARROW().toLowerCase().equals("none")); + relt.setLineType("3"); + relationships.add(relt); } } } + /** + * Sort the freemind node following this pattern: + *

+ * 0 -> 3 + * 1 -> 1 + * 2 -> 0 + * 3 -> 2 + * 4 -> 4 + */ private int calcFirstLevelOrder(@NotNull List freeChilden, @NotNull Node freeChild) { final List nodes = new ArrayList(); int result; + if (freeChild.getWorder() != null) { result = freeChild.getWorder().intValue(); } else { + // Collect all the nodes of the same side ... for (Object child : freeChilden) { if (child instanceof Node) { Node node = (Node) child; @@ -348,14 +355,15 @@ public class FreemindImporter nodeIndex++; } - int size = ORDER_SEPARATION_FACTOR * nodes.size(); + int size = nodes.size(); int center = (size - 1) / 2; - result = (nodeIndex * ORDER_SEPARATION_FACTOR) - center + ((size % 2 == 0) ? 0 : 1); + result = nodeIndex - center; + + if (result < 0) { + result = (result * ORDER_SEPARATION_FACTOR * -2) - 1; - if (result > 0) { - result = (result - 1) * 2; } else { - result = (result * -2) + 1; + result = result * ORDER_SEPARATION_FACTOR * 2; } } @@ -369,37 +377,103 @@ public class FreemindImporter */ private @NotNull - String convertPosition(@NotNull TopicType wiseParent, @NotNull Node freeChild, final int depth, int order) { + String convertPosition(@NotNull TopicType wiseParent, @NotNull Node freeChild, final int depth, int order, int childrenCount) { // Which side must be the node be positioned ? String result = freeChild.getWcoords(); if (result == null) { - BigInteger vgap = freeChild.getVSHIFT(); - BigInteger hgap = freeChild.getHGAP(); - if(hgap==null){ - hgap = BigInteger.valueOf(0L); + + // Calculate X ... + + // Problem on setting X position: + // Text Size is not taken into account ... + int x = CENTRAL_TO_TOPIC_DISTANCE + ((depth - 1) * TOPIC_TO_TOPIC_DISTANCE); + if (depth == 1) { + + final String side = freeChild.getPOSITION(); + assert side != null : "This should not happen"; + x = x * (POSITION_LEFT.equals(side) ? -1 : 1); + } else { + final Coord coord = Coord.parse(wiseParent.getPosition()); + x = x * (coord.isOnLeftSide() ? -1 : 1); } - if(vgap == null){ - vgap = BigInteger.valueOf(20L*order); + + + // Calculate y ... + int y; + if (depth == 1) { + + // Follow the following algorithm ... + // Order: 3 = -100 1 + // Order: 1 = -50 2 + // Order: 0 = 0 3 + // Order: 2 = 50 4 + // Order: 4 = 100 5 + if (order % 2 == 0) { + y = ROOT_LEVEL_TOPIC_HEIGHT * order; + } else { + y = -ROOT_LEVEL_TOPIC_HEIGHT * (order + 1); + } + } else { + + // Problem: What happen if the node is more tall than what is defined here. + Coord coord = Coord.parse(wiseParent.getPosition()); + int parentY = coord.y; + y = parentY - ((childrenCount / 2) * SECOND_LEVEL_TOPIC_HEIGHT - (order * SECOND_LEVEL_TOPIC_HEIGHT)); + + } - String[] position = wiseParent.getPosition().split(","); - BigInteger fix = BigInteger.valueOf(1L); - if((freeChild.getPOSITION() !=null && POSITION_LEFT.equals(freeChild.getPOSITION().toLowerCase())) - || freeChild.getPOSITION()==null && isOnLeftSide(wiseParent)) - fix=BigInteger.valueOf(-1L); - BigInteger firstLevelDistance = BigInteger.valueOf(0L); - BigInteger defaultXDistance = BigInteger.valueOf(200L); - if(depth==1){ - firstLevelDistance = BigInteger.valueOf(200L); - defaultXDistance = BigInteger.valueOf(0L); - } - BigInteger x = BigInteger.valueOf(Integer.valueOf(position[0])).add(hgap.multiply(fix).add(firstLevelDistance.multiply(fix)).add(defaultXDistance.multiply(fix))); - BigInteger y = BigInteger.valueOf(Integer.valueOf(position[1])).add(vgap); - result = x.toString()+","+y.toString(); + result = x + "," + y; + } return result; } + /** + * Position is (x,y). + * x values greater than 0 are right axis + * x values lower than 0 are left axis + */ +// private +// @NotNull +// String convertPosition(@NotNull TopicType wiseParent, @NotNull Node freeChild, final int depth, int order) { +// +// // Which side must be the node be positioned ? +// String result = freeChild.getWcoords(); +// if (result == null) { +// BigInteger vgap = freeChild.getVSHIFT(); +// BigInteger hgap = freeChild.getHGAP(); +// +// if (hgap == null) { +// hgap = BigInteger.valueOf(0L); +// } +// +// if (vgap == null) { +// vgap = BigInteger.valueOf(HALF_ROOT_TOPICS_SEPARATION * order); +// } +// +// +// final String[] position = wiseParent.getPosition().split(","); +// BigInteger fix = BigInteger.valueOf(1L); +// if ((freeChild.getPOSITION() != null && POSITION_LEFT.equals(freeChild.getPOSITION().toLowerCase())) +// || freeChild.getPOSITION() == null && isOnLeftSide(wiseParent)) { +// fix = BigInteger.valueOf(-1L); +// +// } +// +// BigInteger firstLevelDistance = BigInteger.valueOf(0L); +// BigInteger defaultXDistance = BigInteger.valueOf(200L); +// if (depth == 1) { +// firstLevelDistance = BigInteger.valueOf(200L); +// defaultXDistance = BigInteger.valueOf(0L); +// } +// +// BigInteger x = BigInteger.valueOf(Integer.valueOf(position[0])).add(hgap.multiply(fix).add(firstLevelDistance.multiply(fix)).add(defaultXDistance.multiply(fix))); +// BigInteger y = BigInteger.valueOf(Integer.valueOf(position[1])).add(vgap); +// result = x.toString() + "," + y.toString(); +// } +// return result; +// } private String getRichContent(Richcontent content) { String result = null; List elementList = content.getHtml().getAny(); @@ -557,4 +631,23 @@ public class FreemindImporter } return result; } + + static private class Coord { + private int y; + private int x; + + private Coord(@NotNull String pos) { + final String[] split = pos.split(","); + x = Integer.parseInt(split[0]); + y = Integer.parseInt(split[1]); + } + + public static Coord parse(@NotNull String position) { + return new Coord(position); + } + + private boolean isOnLeftSide() { + return x < 0; + } + } } diff --git a/wise-webapp/src/main/java/com/wisemapping/xml/freemind/Node.java b/wise-webapp/src/main/java/com/wisemapping/xml/freemind/Node.java index 14fe003c..e2daf0c8 100644 --- a/wise-webapp/src/main/java/com/wisemapping/xml/freemind/Node.java +++ b/wise-webapp/src/main/java/com/wisemapping/xml/freemind/Node.java @@ -130,7 +130,7 @@ public class Node { // Wise Extensions @XmlAttribute(name = "wCOORDS") protected String wcoords; - @XmlAttribute(name = "WORDER") + @XmlAttribute(name = "wORDER") protected BigInteger worder; /** diff --git a/wise-webapp/src/test/data/freemind/basic.mmr b/wise-webapp/src/test/data/freemind/basic.mmr index df9fe2e5..6197beec 100644 --- a/wise-webapp/src/test/data/freemind/basic.mmr +++ b/wise-webapp/src/test/data/freemind/basic.mmr @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/basic.wxml b/wise-webapp/src/test/data/freemind/basic.wxml index a868e280..48ba0ca3 100644 --- a/wise-webapp/src/test/data/freemind/basic.wxml +++ b/wise-webapp/src/test/data/freemind/basic.wxml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/fonts.mmr b/wise-webapp/src/test/data/freemind/fonts.mmr index 11524e6a..8ce674e5 100644 --- a/wise-webapp/src/test/data/freemind/fonts.mmr +++ b/wise-webapp/src/test/data/freemind/fonts.mmr @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/fonts.wxml b/wise-webapp/src/test/data/freemind/fonts.wxml index 2c5b7158..cbf0aeaa 100644 --- a/wise-webapp/src/test/data/freemind/fonts.wxml +++ b/wise-webapp/src/test/data/freemind/fonts.wxml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/i18n.mmr b/wise-webapp/src/test/data/freemind/i18n.mmr index c13ce775..a1476b37 100644 --- a/wise-webapp/src/test/data/freemind/i18n.mmr +++ b/wise-webapp/src/test/data/freemind/i18n.mmr @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/i18n.wxml b/wise-webapp/src/test/data/freemind/i18n.wxml index 3f74480f..229f7e6d 100644 --- a/wise-webapp/src/test/data/freemind/i18n.wxml +++ b/wise-webapp/src/test/data/freemind/i18n.wxml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/icons.mmr b/wise-webapp/src/test/data/freemind/icons.mmr index 9a6882f3..d0006f9b 100644 --- a/wise-webapp/src/test/data/freemind/icons.mmr +++ b/wise-webapp/src/test/data/freemind/icons.mmr @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/icons.wxml b/wise-webapp/src/test/data/freemind/icons.wxml index 176704de..3c30ee22 100644 --- a/wise-webapp/src/test/data/freemind/icons.wxml +++ b/wise-webapp/src/test/data/freemind/icons.wxml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/links.mmr b/wise-webapp/src/test/data/freemind/links.mmr index b6937289..385eeff8 100644 --- a/wise-webapp/src/test/data/freemind/links.mmr +++ b/wise-webapp/src/test/data/freemind/links.mmr @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/links.wxml b/wise-webapp/src/test/data/freemind/links.wxml index 454cc984..c30563d9 100644 --- a/wise-webapp/src/test/data/freemind/links.wxml +++ b/wise-webapp/src/test/data/freemind/links.wxml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/longnodes.mmr b/wise-webapp/src/test/data/freemind/longnodes.mmr index 3abe3922..5d13ccb7 100644 --- a/wise-webapp/src/test/data/freemind/longnodes.mmr +++ b/wise-webapp/src/test/data/freemind/longnodes.mmr @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/longnodes.wxml b/wise-webapp/src/test/data/freemind/longnodes.wxml index d601d0c7..aa337201 100644 --- a/wise-webapp/src/test/data/freemind/longnodes.wxml +++ b/wise-webapp/src/test/data/freemind/longnodes.wxml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/node-styles.mmr b/wise-webapp/src/test/data/freemind/node-styles.mmr index 0ed5020d..97375d32 100644 --- a/wise-webapp/src/test/data/freemind/node-styles.mmr +++ b/wise-webapp/src/test/data/freemind/node-styles.mmr @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/node-styles.wxml b/wise-webapp/src/test/data/freemind/node-styles.wxml index 2ed5ef7c..afe84e96 100644 --- a/wise-webapp/src/test/data/freemind/node-styles.wxml +++ b/wise-webapp/src/test/data/freemind/node-styles.wxml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/relationships.mmr b/wise-webapp/src/test/data/freemind/relationships.mmr index e2cc1beb..94b67877 100644 --- a/wise-webapp/src/test/data/freemind/relationships.mmr +++ b/wise-webapp/src/test/data/freemind/relationships.mmr @@ -1,3 +1,3 @@ - %5El%3A%5El%3A%5El - \ No newline at end of file + %5El%3A%5El%3A%5El + \ No newline at end of file diff --git a/wise-webapp/src/test/data/freemind/relationships.wxml b/wise-webapp/src/test/data/freemind/relationships.wxml index db1b710b..8f66a2ad 100644 --- a/wise-webapp/src/test/data/freemind/relationships.wxml +++ b/wise-webapp/src/test/data/freemind/relationships.wxml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wise-webapp/src/test/java/com/wisemapping/test/freemind/pepe.xml b/wise-webapp/src/test/java/com/wisemapping/test/freemind/pepe.xml new file mode 100644 index 00000000..02985956 --- /dev/null +++ b/wise-webapp/src/test/java/com/wisemapping/test/freemind/pepe.xml @@ -0,0 +1,20 @@ +Actual : + + + + + + + + + + + + + + + + + + +