take care link in xcos diagram positionning
antoine ELIAS [Fri, 30 Oct 2009 18:38:27 +0000 (19:38 +0100)]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/BlockReader.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/BasicLink.java

index f07e70d..833231d 100644 (file)
@@ -124,7 +124,8 @@ public class BlockReader {
                                        blocks.add(currentBlock);
                                        minX = Math.min(minX, currentBlock.getGeometry().getX());
                                        minY = Math.min(minY, currentBlock.getGeometry().getY()/* - currentBlock.getGeometry().getHeight()*/);
-                               }else{
+                               }else if(isLink(data, i)){
+                                       System.err.println("Link !");
                                        //for minX and minY
                                }
                        } catch (BlockReaderException e) {
@@ -134,19 +135,6 @@ public class BlockReader {
                        }
                }
                
-               double offsetX = 0;
-               offsetX = -minX + 20;
-
-               double offsetY = 0;
-               offsetY = -minY + 20;
-
-               
-               for (int i = 0; i < blocks.size(); ++i) {
-                       blocks.get(i).getGeometry().setX(blocks.get(i).getGeometry().getX() + offsetX);
-                       blocks.get(i).getGeometry().setY(blocks.get(i).getGeometry().getY() + offsetY);
-               }
-               result.put("Blocks", blocks);
-               
                List<BasicPort[]> linkPorts = new ArrayList<BasicPort[]>(); 
                List<double[][]> linkPoints = new ArrayList<double[][]>(); 
                // Read all Links
@@ -207,8 +195,8 @@ public class BlockReader {
                                                double[][] linkPoint = new double[link.get(1).getHeight() - 2][2]; 
                                                for(int point = 0 ; point < link.get(1).getHeight() - 2 ; point++){
                                                        linkPoint[point] = getLinkPoint(link, point);
-                                                       linkPoint[point][0] += offsetX;
-                                                       linkPoint[point][1] += offsetY;
+                                                       minX = Math.min(minX, linkPoint[point][0]);
+                                                       minY = Math.min(minY, linkPoint[point][1]);
                                                }
                                                linkPoints.add(linkPoint);
                                        }
@@ -255,18 +243,34 @@ public class BlockReader {
 
                }
 
-               offsetX = -minX + 20;
-               offsetY = -minY + 20;
+               double offsetX = -minX + 20;
+               double offsetY = -minY + 20;
 
                
+               for (int i = 0; i < blocks.size(); ++i) {
+                       blocks.get(i).getGeometry().setX(blocks.get(i).getGeometry().getX() + offsetX);
+                       blocks.get(i).getGeometry().setY(blocks.get(i).getGeometry().getY() + offsetY);
+               }
+
+               for (int i = 0; i < linkPoints.size(); i++) {
+                       if(linkPoints.get(i) != null){
+                               System.err.println("");
+                               for (int j = 0; j < linkPoints.get(i).length; j++) {
+                                       linkPoints.get(i)[j][0] += offsetX;
+                                       linkPoints.get(i)[j][1] += offsetY;
+                                       System.err.println("(" + linkPoints.get(i)[j][0] + "," + linkPoints.get(i)[j][1] + ")");
+                               }
+                       }
+               }
+
                for (int i = 0; i < textBlocks.size(); ++i) {
                        textBlocks.get(i).getGeometry().setX(textBlocks.get(i).getGeometry().getX() + offsetX);
                        textBlocks.get(i).getGeometry().setY(textBlocks.get(i).getGeometry().getY() + offsetY);
                }
+
+               //put all data
+               result.put("Blocks", blocks);
                result.put("TextBlocks", textBlocks);
-               
-               ////
-               
                links.put("Ports", linkPorts);
                links.put("Points", linkPoints);
                result.put("Links", links);
index 920f423..8769676 100644 (file)
@@ -194,7 +194,6 @@ public abstract class BasicLink extends XcosUIDObject {
                // xx
                xx[0][0] = getSource().getGeometry().getCenterX() + getSource().getParent().getGeometry().getX();
                for(int i = 0 ; i < getPointCount() ; i++){
-                       System.err.println("Point : " + ((mxPoint)getGeometry().getPoints().get(i)).getX());
                        xx[0][i+1] = ((mxPoint)getGeometry().getPoints().get(i)).getX();
                }
                xx[0][1 + getPointCount()] = getTarget().getGeometry().getCenterX() + getTarget().getParent().getGeometry().getX();
@@ -204,7 +203,6 @@ public abstract class BasicLink extends XcosUIDObject {
                double[][] yy = new double[1][2 + getPointCount()];
                yy[0][0] = -(getSource().getGeometry().getCenterY() + getSource().getParent().getGeometry().getY() - getSource().getParent().getGeometry().getHeight());
                for(int i = 0 ; i < getPointCount() ; i++){
-                       System.err.println("Point : " + - ((mxPoint)getGeometry().getPoints().get(i)).getY());
                        yy[0][i+1] = - ((mxPoint)getGeometry().getPoints().get(i)).getY() + getSource().getParent().getGeometry().getHeight();
                }
                yy[0][1 + getPointCount()] = -(getTarget().getGeometry().getCenterY() + getTarget().getParent().getGeometry().getY() - getSource().getParent().getGeometry().getHeight());