// Generated by Haxe 4.3.3
package graph;

import haxe.root.*;

@SuppressWarnings(value={"rawtypes", "unchecked"})
public class DiagramAdapter extends haxe.lang.HxObject
{
	public DiagramAdapter(haxe.lang.EmptyObject empty)
	{
	}
	
	
	public DiagramAdapter()
	{
		//line 6 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
		graph.DiagramAdapter.__hx_ctor_graph_DiagramAdapter(this);
	}
	
	
	protected static void __hx_ctor_graph_DiagramAdapter(graph.DiagramAdapter __hx_this)
	{
	}
	
	
	public static haxe.root.Array<java.lang.Object> buildGraph(model.Diagram diagram)
	{
		//line 8 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
		haxe.root.Array<java.lang.Object> graph1 = new haxe.root.Array<java.lang.Object>();
		//line 9 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
		{
			//line 9 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			java.lang.Object set = new haxe.ds._StringMap.StringMapValueIterator<model.Set>(((haxe.ds.StringMap<model.Set>) (diagram.sets) ));
			//line 9 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			while (haxe.lang.Runtime.toBool(((java.lang.Boolean) (haxe.lang.Runtime.callField(set, "hasNext", null)) )))
			{
				//line 9 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				model.Set set1 = ((model.Set) (haxe.lang.Runtime.callField(set, "next", null)) );
				//line 10 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				java.lang.Object __temp_stmt3 = null;
				//line 10 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				{
					//line 10 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
					haxe.root.Array<java.lang.Object> __temp_odecl1 = new haxe.root.Array<java.lang.Object>();
					//line 10 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
					__temp_stmt3 = new haxe.lang.DynamicObject(new java.lang.String[]{"links", "name", "node"}, new java.lang.Object[]{__temp_odecl1, set1.name, set1}, new java.lang.String[]{}, new double[]{});
				}
				
				//line 10 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				graph1.push(__temp_stmt3);
			}
			
		}
		
		//line 13 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
		haxe.root.Array<model.Association> tmpAssociations = new haxe.root.Array<model.Association>();
		//line 14 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
		{
			//line 14 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			java.lang.Object assoc = new haxe.ds._StringMap.StringMapValueIterator<model.Association>(((haxe.ds.StringMap<model.Association>) (diagram.associations) ));
			//line 14 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			while (haxe.lang.Runtime.toBool(((java.lang.Boolean) (haxe.lang.Runtime.callField(assoc, "hasNext", null)) )))
			{
				//line 14 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				model.Association assoc1 = ((model.Association) (haxe.lang.Runtime.callField(assoc, "next", null)) );
				//line 15 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				tmpAssociations.push(assoc1);
			}
			
		}
		
		//line 18 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
		while (( tmpAssociations.length != 0 ))
		{
			//line 19 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			boolean postpone = false;
			//line 20 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			model.Association assoc2 = tmpAssociations.pop();
			//line 21 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			java.lang.Object node = null;
			//line 21 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			{
				//line 21 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				haxe.root.Array<java.lang.Object> __temp_odecl2 = new haxe.root.Array<java.lang.Object>();
				//line 21 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				node = new haxe.lang.DynamicObject(new java.lang.String[]{"links", "name", "node"}, new java.lang.Object[]{__temp_odecl2, assoc2.name, ((model.Set) (assoc2) )}, new java.lang.String[]{}, new double[]{});
			}
			
			//line 22 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			haxe.root.Array<java.lang.Object> linkedNodes = new haxe.root.Array<java.lang.Object>();
			//line 23 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			java.lang.String previousLink = "";
			//line 24 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			{
				//line 24 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				int _g = 0;
				//line 24 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				haxe.root.Array<model.Link> _g1 = assoc2.links;
				//line 24 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				while (( _g < _g1.length ))
				{
					//line 24 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
					model.Link link = _g1.__get(_g);
					//line 24 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
					 ++ _g;
					//line 25 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
					java.lang.Object ln = ((java.lang.Object) (haxe.root.Lambda.find(((java.lang.Object) (graph1) ), ((haxe.lang.Function) (new graph.DiagramAdapter_buildGraph_25__Fun(link)) ))) );
					//line 26 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
					if (( ln == null )) 
					{
						//line 27 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
						postpone = true;
					}
					else
					{
						//line 29 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
						if ( ! (haxe.lang.Runtime.valEq(haxe.lang.Runtime.toString(haxe.lang.Runtime.getField(ln, "name", true)), previousLink)) ) 
						{
							//line 30 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
							linkedNodes.push(ln);
							//line 31 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
							previousLink = haxe.lang.Runtime.toString(haxe.lang.Runtime.getField(ln, "name", true));
						}
						
					}
					
				}
				
			}
			
			//line 35 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			if (postpone) 
			{
				//line 36 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				tmpAssociations.push(assoc2);
			}
			else
			{
				//line 38 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				{
					//line 38 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
					int _g2 = 0;
					//line 38 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
					while (( _g2 < linkedNodes.length ))
					{
						//line 38 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
						java.lang.Object ln1 = linkedNodes.__get(_g2);
						//line 38 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
						 ++ _g2;
						//line 39 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
						((haxe.root.Array<java.lang.Object>) (haxe.lang.Runtime.getField(node, "links", true)) ).push(ln1);
						//line 40 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
						((haxe.root.Array<java.lang.Object>) (haxe.lang.Runtime.getField(ln1, "links", true)) ).push(node);
					}
					
				}
				
				//line 42 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				graph1.push(node);
			}
			
		}
		
		//line 46 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
		{
			//line 46 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			java.lang.Object set2 = new haxe.ds._StringMap.StringMapValueIterator<model.Set>(((haxe.ds.StringMap<model.Set>) (diagram.sets) ));
			//line 46 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
			while (haxe.lang.Runtime.toBool(((java.lang.Boolean) (haxe.lang.Runtime.callField(set2, "hasNext", null)) )))
			{
				//line 46 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				model.Set set3 = ((model.Set) (haxe.lang.Runtime.callField(set2, "next", null)) );
				//line 47 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
				if (( set3.superset != null )) 
				{
					//line 48 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
					java.lang.Object node1 = ((java.lang.Object) (haxe.root.Lambda.find(((java.lang.Object) (graph1) ), ((haxe.lang.Function) (new graph.DiagramAdapter_buildGraph_48__Fun(set3)) ))) );
					//line 49 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
					java.lang.Object ln2 = ((java.lang.Object) (haxe.root.Lambda.find(((java.lang.Object) (graph1) ), ((haxe.lang.Function) (new graph.DiagramAdapter_buildGraph_49__Fun(set3)) ))) );
					//line 50 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
					((haxe.root.Array<java.lang.Object>) (haxe.lang.Runtime.getField(node1, "links", true)) ).push(ln2);
					//line 51 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
					((haxe.root.Array<java.lang.Object>) (haxe.lang.Runtime.getField(ln2, "links", true)) ).push(node1);
				}
				
			}
			
		}
		
		//line 54 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
		return graph1;
	}
	
	
	public static void arrange(model.Diagram diagram)
	{
		//line 58 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
		haxe.root.Array<java.lang.Object> graph1 = graph.DiagramAdapter.buildGraph(diagram);
		//line 59 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
		graph.Positioner<model.Set> positioner = new graph.Positioner<model.Set>(((haxe.root.Array<java.lang.Object>) (graph1) ));
		//line 60 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
		haxe.root.Array<haxe.root.Array<model.Set>> grid = positioner.arrange();
		//line 61 "/home/frank/Documents/Developpements/dbconcept-0.5.1/src/graph/DiagramAdapter.hx"
		diagram.loadGrid(grid);
	}
	
	
}


