Supporting input and output

@imran.rafique
I have downloaded version 17.9 but i cannot seem to get the connections points to connect. I have tried many different options but the lines always get drawn in same place.

it should look like :
router -> connector -> firewall -> connector -> router

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ccp;

import com.aspose.diagram.Connection;
import com.aspose.diagram.ConnectionPointPlace;
import com.aspose.diagram.Diagram;
import com.aspose.diagram.Page;
import com.aspose.diagram.SaveFileFormat;
import com.aspose.diagram.Shape;
import com.aspose.diagram.Txt;
import com.aspose.diagram.TypeValue;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Array;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.DOMException;
import org.xml.sax.SAXException;
import com.aspose.diagram.ConnectionPointPlace;
import com.aspose.diagram.Diagram;
import com.aspose.diagram.DiagramSaveOptions;
import com.aspose.diagram.Page;
import com.aspose.diagram.SaveFileFormat;
import com.aspose.diagram.Shape;
//import com.aspose.diagram.examples.Utils;

/**
 *
 * @author UddinS2
 */
public class Main {

    public static void main(String argv[]) throws Exception {

        try {
            String dataDir = "C:\\Users\\Uddins2\\Documents\\aspose\\";
            File fXmlFile = new File(dataDir + "comms_matrix.xml");
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(fXmlFile);

            //optional, but recommended
            //read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
            doc.getDocumentElement().normalize();

            System.out.println("Root element :" + doc.getDocumentElement().getNodeName());

            NodeList nList = doc.getElementsByTagName("flow");
            //Flow[] flows;
            //flows = new Flow[nList.getLength()];
            
            // initialize a new drawing
            Diagram diagram = new Diagram();
            
            // get page by index
            Page page = diagram.getPages().get(0);
            
           
            String connectorMaster = "Dynamic connector";
            String router = "Router";
            String firewall = "Firewall";
            int pageNumber = 0;
            int xR1 = 1;
            int xR2 = 3;
            int xR3 = 5;
            double y = 1;
           
            // Set stencil file path
            //String templateFileName = dataDir + "stencil\\Network Connectivity.vss";
            //FileInputStream stream = new FileInputStream(templateFileName);
            // adds master to diagram from source diagram
            Diagram src = new Diagram(dataDir + "Example Diagram.vdx");
            diagram.addMaster(src, router);
            diagram.addMaster(src, firewall);
            diagram.addMaster(src, connectorMaster);

            

            String source;
            String destination;
            for (int temp = 0; temp < nList.getLength(); temp++) {

                Node nNode = nList.item(temp);

                System.out.println("\nCurrent Element :" + nNode.getNodeName());

                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element) nNode;                    
                    source = eElement.getElementsByTagName("src").item(0).getTextContent();
                    destination = eElement.getElementsByTagName("dst").item(0).getTextContent();
                    
                    // add shapes
                    /*
                    long shape1_ID = diagram.addShape(xR1, y, router, pageNumber);
                    long shape2_ID = diagram.addShape(xR2, y, firewall, pageNumber);
                    long shape3_ID = diagram.addShape(xR3, y, router, pageNumber);
                    */
                    long shape1_ID = diagram.addShape(4.5, 7, router, pageNumber);
                    long shape2_ID = diagram.addShape(2.25, 4.5, firewall, pageNumber);
                    long shape3_ID = diagram.addShape(4.5, 4.5, router, pageNumber);
                    
                    // get shapes by ID
                    Shape shape1 = page.getShapes().getShape(shape1_ID);
                    Shape shape2 = page.getShapes().getShape(shape2_ID);
                    Shape shape3 = page.getShapes().getShape(shape3_ID);                    
                    //shape1.getText().getValue().add(new Txt(source));
                    //shape3.getText().getValue().add(new Txt(destination));
                    
                    // add two more connection points
                    Connection connection1 = new Connection();
                    connection1.getX().getUfe().setF("Width*0.33");
                    connection1.getY().getUfe().setF("Height*0");
                    Connection connection3 = new Connection();
                    connection3.getX().getUfe().setF("Width*0.66");
                    connection3.getY().getUfe().setF("Height*0");
                    shape1.getConnections().add(connection1);
                    shape1.getConnections().add(connection3);
                    
                    // add connector shapes
                    Shape connector1 = new Shape();
                    Shape connector2 = new Shape();
                    //Shape connector3 = new Shape();
                    long connecter1Id = diagram.addShape(connector1, connectorMaster, 0);
                    long connecter2Id = diagram.addShape(connector2, connectorMaster, 0);
                    //long connecter3Id = diagram.addShape(connector3, connectorMaster, 0);
                    // connect shapes by index of conneecting points
                    //System.out.println(page);
                    System.out.println(shape1_ID + " " + shape2_ID + " " + shape3_ID);
                    //System.out.println(shape3_ID);
                    //System.out.println(connecter1Id);

                    // connect shapes by index of conneecting points
                    page.connectShapesViaConnectorIndex(shape1.getID(), 6, shape2.getID(), 3, connecter1Id);
                    page.connectShapesViaConnectorIndex(shape1.getID(), 1, shape3.getID(), 3, connecter2Id);
                    //page.connectShapesViaConnectorIndex(shape1.getID(), 7, shape4.getID(), 3, connecter3Id);
                    
                    //page.connectShapesViaConnectorIndex(shape1.getID(), 7, shape4.getID(), 3, connecter3Id);
                    //page.connectShapesViaConnectorIndex(shape1_ID, ConnectionPointPlace.RIGHT, shape2_ID, ConnectionPointPlace.LEFT, connecter1Id);
                    //page.connectShapesViaConnectorIndex(shape2_ID, ConnectionPointPlace.RIGHT, shape3_ID, ConnectionPointPlace.LEFT, connecter2Id);
                    //page.connectShapesViaConnectorIndex(shape1.getID(), xR1, shape2.getID(), xR2, connecter1Id);
                    //page.connectShapesViaConnectorIndex(shape1.getID(), 7, shape4.getID(), 3, connecter3Id);
                    //Connection connection1 = new Connection(); 
                    //shape1.Connections.Add(connection1); 
                    y++;y++;
                }
            } //end of for loop
            // save drawing
            DiagramSaveOptions options = new DiagramSaveOptions(SaveFileFormat.VSDX);
            options.setAutoFitPageToDrawingContent(false);
            diagram.save(dataDir + "Drawing2_out.vsdx", options);
            
            //System.out.println(flows.length);
        } catch (IOException e) {
        } catch (ParserConfigurationException e) {
        } catch (DOMException e) {
        } catch (SAXException e) {
        }

    }
}

You should have the same files I uploaded on previous posts.
Drawing2_out.zip (38.2 KB)

when i use the following code i get the result below

long shape1_ID = diagram.addShape(xR1, y, router, pageNumber);
                    long shape2_ID = diagram.addShape(xR2, y, firewall, pageNumber);
                    long shape3_ID = diagram.addShape(xR3, y, router, pageNumber);
                    
                    /*
                    long shape1_ID = diagram.addShape(4.5, 7, router, pageNumber);
                    long shape2_ID = diagram.addShape(2.25, 4.5, firewall, pageNumber);
                    long shape3_ID = diagram.addShape(4.5, 4.5, router, pageNumber);
                    */

Drawing2_out (2).zip (38.1 KB)

@sharif.uddin1,

We have re-evaluated the linked ticket ID DIAGRAMJAVA-50566 and reopened to further investigate. We will let you know once a significant progress has been made in this regard.

@sharif.uddin1,

In reference to the ticket ID DIAGRAMJAVA-50566, please download and try the latest version 17.12 of Aspose.Diagram for Java API. Please also set IX property of connection, like this line of code: connection1.setIX(0);

@imran.rafique can you provide sample code that will work with what i am trying to do?

@sharif.uddin1,

We are sorry for the inconvenience caused. We are in communication with our product team and will get back to you soon.

@sharif.uddin1,

Please try the following code example: Code and Output Drawing.zip (14.8 KB)

So i have checked the code. can I ask how to control the width and alignment of the line being attached from router to router. Untitled.png (49.1 KB)

Your online documentations are not very clear on what I am trying to do so I can achieve my end goal with this product.

What does the following lines mean and do? where do you have examples of this?
connection1.setIX(0);

What is difference with connection1.getX().getUfe().setF("Width*0.33"); and connection3.getX().getUfe().setF("Width*0.66"); ?

I have done the following but the line seems to not be straight. how can I straighten this? I added connector1.setConnectorsType(ConnectorsTypeValue.STRAIGHT_LINES); but it made no difference

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ccp;

import com.aspose.diagram.Connection;
import com.aspose.diagram.ConnectionPointPlace;
import com.aspose.diagram.Diagram;
import com.aspose.diagram.Page;
import com.aspose.diagram.SaveFileFormat;
import com.aspose.diagram.Shape;
import com.aspose.diagram.Txt;
import com.aspose.diagram.TypeValue;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Array;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.DOMException;
import org.xml.sax.SAXException;
import com.aspose.diagram.ConnectionPointPlace;
import com.aspose.diagram.ConnectorsTypeValue;
import com.aspose.diagram.Diagram;
import com.aspose.diagram.DiagramSaveOptions;
import com.aspose.diagram.Page;
import com.aspose.diagram.SaveFileFormat;
import com.aspose.diagram.Shape;

/**
 *
 * @author UddinS2
 */
public class fromaspose {

    public static void main(String argv[]) throws Exception {
        String dataDir = "C:\\Users\\Uddins2\\Documents\\aspose\\";
        File fXmlFile = new File(dataDir + "comms_matrix.xml");
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(fXmlFile);

        //optional, but recommended
        //read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
        doc.getDocumentElement().normalize();

        System.out.println("Root element :" + doc.getDocumentElement().getNodeName());

        NodeList nList = doc.getElementsByTagName("flow");
//             Flow[] flows;
//             flows = new Flow[nList.getLength()];

        // initialize a new drawing
        Diagram diagram = new Diagram();

        // get page by index
        Page page = diagram.getPages().get(0);

        String connectorMaster = "Connector";
        String router = "Router";
        String firewall = "Firewall";
        int pageNumber = 0;
        int xR1 = 1;
        int xR2 = 4;
        int xR3 = 7;
        double y = 1;

        // Set stencil file path
        //String templateFileName = dataDir + "stencil\\Network Connectivity.vss";
        //FileInputStream stream = new FileInputStream(templateFileName);
        // adds master to diagram from source diagram
        Diagram src = new Diagram(dataDir + "Network Connectivity.vdx");
        diagram.addMaster(src, router);
        diagram.addMaster(src, firewall);
        diagram.addMaster(src, connectorMaster);

        for (int temp = 0; temp < nList.getLength() - 1; temp++) {

            Node nNode = nList.item(temp);

            System.out.println("\nCurrent Element :" + nNode.getNodeName());

            if (nNode.getNodeType() == Node.ELEMENT_NODE) {

                Element eElement = (Element) nNode;
//                     Flow currentflow = new Flow(eElement.getElementsByTagName("src").item(0).getTextContent(), eElement.getElementsByTagName("dst").item(0).getTextContent());
//                     flows[temp] = currentflow;
                //System.out.println("src : " + eElement.getElementsByTagName("src").item(0).getTextContent());
                //System.out.println("dst : " + eElement.getElementsByTagName("dst").item(0).getTextContent());

                // add shapes
                long shape1_ID = diagram.addShape(xR1, y, router, pageNumber);
                long shape2_ID = diagram.addShape(xR2, y, firewall, pageNumber);
                long shape3_ID = diagram.addShape(xR3, y, router, pageNumber);

                // get shapes by ID
                Shape shape1 = page.getShapes().getShape(shape1_ID);
                Shape shape2 = page.getShapes().getShape(shape2_ID);
                Shape shape3 = page.getShapes().getShape(shape3_ID);

                // add two more connection points
                Connection connection1 = new Connection();
                connection1.setIX(0);
                connection1.getX().getUfe().setF("Width*0.33");
//                     connection1.getX().setValue(0.2984);
                connection1.getY().getUfe().setF("Height*0");
//                     connection1.getY().setValue(0);
                Connection connection2 = new Connection();
                connection2.getX().getUfe().setF("Width*0.66");
//                     connection3.getX().setValue(0.5968);
                connection2.getY().getUfe().setF("Height*0");
//                     connection3.getY().setValue(0);
                connection2.setIX(1);
                shape1.getConnections().add(connection1);
                shape1.getConnections().add(connection2);

                Connection connection3 = new Connection();
                connection3.getX().getUfe().setF("Width*0.33");
//                     connection4.getX().setValue(0.2984);
                connection3.getY().getUfe().setF("Height*0");
//                     connection4.getY().setValue(0);
                connection3.setIX(0);
                Connection connection4 = new Connection();
                connection4.getX().getUfe().setF("Width*0.66");
//                     connection3.getX().setValue(0.5968);
                connection4.getY().getUfe().setF("Height*0");
//                     connection3.getY().setValue(0);
                connection4.setIX(1);
                shape2.getConnections().add(connection3);
                shape2.getConnections().add(connection4);
                
                Connection connection5 = new Connection();
                connection5.getX().getUfe().setF("Width*0.33");
//                     connection4.getX().setValue(0.2984);
                connection5.getY().getUfe().setF("Height*0");
//                     connection4.getY().setValue(0);
                connection5.setIX(0);
                shape3.getConnections().add(connection5);

                // add connector shapes
                Shape connector1 = new Shape();
                diagram.addShape(connector1, connectorMaster, 0);
                connector1.setConnectorsType(ConnectorsTypeValue.STRAIGHT_LINES);//.setConnectorsType(ConnectorsTypeValue.RIGHT_ANGLE);
                Shape connector2 = new Shape();
                diagram.addShape(connector2, connectorMaster, 0);
                connector2.setConnectorsType(ConnectorsTypeValue.STRAIGHT_LINES);

                System.out.println(page);
                //ConnectionPointPlace  x = connection2;
               //page.connectShapesViaConnector(shape3, xR3, shape1, xR1, shape2);
                page.connectShapesViaConnector(shape1, ConnectionPointPlace.RIGHT, shape2, ConnectionPointPlace.LEFT, connector1);
                page.connectShapesViaConnector(shape2, ConnectionPointPlace.RIGHT, shape3, ConnectionPointPlace.LEFT, connector2);
                //page.connectShapesViaConnectorIndex(shape1_ID, 1, shape2_ID, 0, connecter1Id);
                //page.connectShapesViaConnectorIndex(shape2_ID, 1, shape3_ID, 0, connecter1Id);

                y++;
                y++;
            }
        }
        
        // save drawing
        DiagramSaveOptions options = new DiagramSaveOptions(SaveFileFormat.VSDX);
        options.setAutoFitPageToDrawingContent(false);
        diagram.save(dataDir + "Drawing3_out.vsdx", options);
    }

}

see imageUntitled2.png (52.1 KB)

@sharif.uddin1,

Well, you can change the width of the connecting line, but it will disconnect shapes. In order to change the position of a shape and keep the lines connected, you can call move or moveTo methods. In reference to the alignment of connecting lines, you can edit the geometry of the connecting line. Please refer to these help topics: Setting Height and Width of a Shape, Change the Position of a Shape and Working with Geometry Section.

The IX attribute described the order of Char elements. Please view the details of IX attribute on this Microsoft help topic: [Working with a Shape’s Text in DatadiagramML]

With these lines of code, we formulate X-axis coordinate of the connection point on the shape. If the shape’s width is 100, then the horizontal position of the connection point is 33 (Width*0.33) and 66 (Width*0.66).

@sharif.uddin1,

We managed to replicate the problem not being able to set straight lines. It has been logged under the ticket ID DIAGRAMJAVA-50582 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

@sharif.uddin1,

The linked ticket ID DIAGRAMJAVA-50582 has been resolved and will be included in next version 18.2 of Aspose.Diagram for Java API. We will notify you once the next version is published.

@sharif.uddin1,

In reference to the linked ticket ID DIAGRAMJAVA-50582, please download and try the Hotfix version 18.1.1 of Aspose.Diagram for Java.

@sharif.uddin1,

The linked ticket ID DIAGRAMJAVA-50582 has been resolved and included in the full version 18.2 of Aspose.Diagram for Java API. Please download and try the latest version 18.2 of Aspose.Diagram for Java API.

@imran.rafique i have downlaoded On Premise File Format API Releases | Aspose and On Premise File Format API Releases | Aspose buit it is still drawing the same.

here is my code https://github.com/shorif2000/aspose/blob/master/src/ccp/nitxtrace.java can you please show a how it works to keep the connectors straight and keeping the shape on top of the connector line.

i can seem to add connectors from shape 2-3 then shape3-4 etc… in a loop

@sharif.uddin1,

We have re-evaluated the linked ticket ID DIAGRAMJAVA-50582 with the latest version 18.5 of Aspose.Diagram for Java API, and the connecting lines are straight. This is the ZIP of output Visio drawing: Drawing3_out18.5.zip (15.6 KB)

We have tried to execute this code example, but facing an error on parsing XML file as follows:

[Fatal Error] nitx_trace_src10.106.164.0_25dst47.73.107.128_25protoTCPport=3389.xml:1:1: Content is not allowed in prolog.
Exception in thread “main” org.xml.sax.SAXParseException; systemId: file:/C:/Diagram/test2346/nitx_trace_src10.106.164.0_25dst47.73.107.128_25protoTCPport=3389.xml; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at pkgDiagram.nitxtrace.main(nitxtrace.java:44)

Please review and send us your source XML file.

@imran.rafique i have updated the xml CCP

problem i am having is within the second loop. it only connects the 1st shape.

Also how can i add label under each shape?

how can i add support for visio 2010 VSD extension?

@sharif.uddin1,

We are unable to run Java code example (nitxtrace.java) because it shows a null pointer error while retrieving shape Id from the array. Please simplify code, and then send us this Java file.
Java

long shape_ID1 = shape_ID[i];
long shape_ID2 = shape_ID[(i + 1)];

You can find and choose text label shape from the stencil file, and then set PinX and PinY values with respect to the position of target shape. Please refer to this help topic: Adding a New Shape in Visio

Aspose.Diagram for Java API has support of reading VSD drawings, and the writing support of VSD drawings is not incorporated. You can open a VSD drawing with Aspose.Diagram API, and then save in the VSDX format.

@imran.rafique i need to be able to save as viso 2010 format (VSD). is this possible to support?

i have attacthed the working example including the output. i tried to resize the shapes so it fits in on the page. can you help with this? also the lines are not straight again.

nitx_trace_src10.106.164.0_25dst47.73.107.128_25protoTCPport=3389.zip (3.2 KB)

Drawing3_out.zip (16.7 KB)

here is output without resize. with this one i want to put shapes on top of the connector lines.

Drawing3_out no resize.zip (16.3 KB)

can you also tell me how I can do page-> fit to drawing?

Drawing3_out final.zip (17.2 KB)

@sharif.uddin1,

Please note, saving Visio drawings in VSD (binary format) is a complex task and we have a less number of requests from clients because they can save drawings to an alternative VDX or VSDX format. We have linked your post to this feature request which is logged under the ticket ID DIAGRAM-31002, and will notify you once it is fixed.

In reference to the incorrect size of the router shape, an investigation has been logged under the ticket ID DIAGRAMJAVA-50601 in our bug tracking system. As a workaround, the Diagram instance has multiple addShape methods and also helps to set the width and height of the shape as follows:
Java

diagram.addShape(PinX, PinY, width, height, masterstring, pagenumber);

You can also change the position of a shape with the move method of the shape instance. Please refer to this help topic: Change the Position of a Shape

@sharif.uddin1,

We have tested your scenario and the AutoFitPageToDrawingContent property is not working as expected. It has been logged under the ticket ID DIAGRAMJAVA-50602 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.