# Using yFiles for Java Layout Algorithms from C++

This article describes and demonstrates how the sophisticated layout algorithms provided by yFiles for Java can be used from within a C++ application. The main idea to make this work is to provide a convenient communication layer for a C++ application and a Java process executing a yFiles-based layout service. What this package includes C++ Source Code that will allow you to

1. construct a graph with nodes and edges
2. define additional properties relevant for the layout process
3. start the layout service as a separate process
4. encode the graph to a format that the layout service understands
5. invoke the layout algorithm by sending the encoded graph to the layout server
6. decode the resulting layout information and make it available through the graph
7. fetch the resulting layout coordinates

Furthermore, the package includes Java Source Code for the yFiles layout server, and sample code that shows how to effectively use the C++ extension.

## Requirements

- C++ extension package for yFiles v1.0 (includes C++ Client and Java Layout Server)
- yFiles 2.7 for Java
- JRE 5.0 or higher to execute the layout service
- Visual Studio 10 to compile the C++ sources
- Windows Vista or Windows 7

## Installation

1. Unzip the [CppExtensionForYFiles.zip]. The unzipped file contains following folders:

- yFilesCPPClient - The C++ source code for the layout service
- yFilesLayoutServer - The Java source code for the server part of the layout service
- lib - The folder contains third party library xerces (used by the client) and the jar file of layout server (pre-build of the layout server)
- doc - The documentation
- Debug - This folder will contain the executable demo file "yFilesCPPDemo.exe", after a successfully demo build

2. From your yFiles 2.7 for Java distribution, now copy lib/y.jar to the lib folder of the C++ extension.

## Building on Windows using Microsoft Visual C++

The Visual Studio project file (yFilesCPPInterface.sln) is located in the root path of the yFilesCPP distribution. 1. Open the project file. 2. Build the solution with F7. 3. Execute the demo with F5 or start the "yFilesCPPDemo.exe" from the Debug folder (yFilesCPPRoot/Debug).

## Sample Code

The C++ extension currently comes with four source code demos. Each of the examples creates their own graph, configures the corresponding layout algorithm, manipulates the graph by an automatic layout and writes the output to the console and to an XML-encoded GraphML file. The output to the console represents each of the graphs, before and after the layout calculation. The generated GraphML files contains the graph including the resulting layout. To view these GraphML files (example1.graphml ... example4.graphml) you can use the freely availalbe yEd Graph Editor. The GraphML files are located in the debug folder (yFilesCPPRoot/Debug).

## 3rd Party Notices

The C++ extension for yFiles uses the freely available Xerces-C++ library to implement the communication protocol for the layout service. The Xerces-C++ library is partially included in the lib/ directory of the extension package. The Apache License ver. 2.0 applies to the Xerces-C++ distribution.