Ejemplo n.º 1
0
        public static void cloneVertex(
            NetworkContainersNS.Graph graph,
            Dictionary <string, ModelClassNS.VertexEdgesInfo> edgesByVertex,
            string sourceVertexId,
            string newVertexId,
            float x,
            float y
            )
        {
            if (graph.vertices.ContainsKey(newVertexId))
            {
                throw new System.Exception("Vertex with new key already exists");
            }
            if (!graph.vertices.ContainsKey(sourceVertexId))
            {
                throw new System.Exception("Vertex with source id does not exist");
            }

            NetworkContainersNS.Vertex newVtx = graph.vertices[sourceVertexId].clone();
            graph.vertices[newVertexId] = newVtx;
            newVtx.xLocation            = x;
            newVtx.yLocation            = y;

            edgesByVertex[newVertexId] = new ModelClassNS.VertexEdgesInfo {
                edgesIn  = new List <string>(),
                edgesOut = new List <string>()
            };
        }
Ejemplo n.º 2
0
        public static void addLayer(
            VersionedModelClassNS.VersionedModelClass versionedModel,
            string layerId,
            string layerType,
            float x,
            float y
            )
        {
            ModelClassNS.ModelClass modelClass = versionedModel.getCurrent();

            Layers.Layer layer = Layers.Layer.getNewLayerByType(layerType);

            NetworkContainersNS.Vertex newVertex = new NetworkContainersNS.Vertex {
                label     = layerType + " Layer",
                xLocation = x,
                yLocation = y,
                ports     = new Dictionary <string, NetworkContainersNS.NetworkPort>()
            };

            List <string> inputPortNames  = new List <string>();
            List <string> outputPortNames = new List <string>();

            foreach (string portName in layer.getPortNames())
            {
                if (layer.getValueIsReadonly(layer.getValueNameOfPort(portName)))
                {
                    outputPortNames.Add(portName);
                }
                else
                {
                    inputPortNames.Add(portName);
                }
            }

            for (int i = 0; i < inputPortNames.Count; i++)
            {
                // System.Console.Error.WriteLine(((float)(i + 1)) / ((float)(inputPortNames.Count + 1)));
                newVertex.ports[inputPortNames[i]] = new NetworkContainersNS.NetworkPort {
                    side     = NetworkContainersNS.SideType.Top,
                    position = ((float)(i + 1)) / ((float)(inputPortNames.Count + 1)),
                    type     = NetworkContainersNS.PortType.Input,
                };
            }

            for (int i = 0; i < outputPortNames.Count; i++)
            {
                newVertex.ports[outputPortNames[i]] = new NetworkContainersNS.NetworkPort {
                    side     = NetworkContainersNS.SideType.Bottom,
                    position = ((float)(i + 1)) / ((float)(outputPortNames.Count + 1)),
                    type     = NetworkContainersNS.PortType.Output,
                };
            }

            modelClass.graph.vertices[layerId]   = newVertex;
            modelClass.layerDict.layers[layerId] = layer;
            modelClass.edgesByVertex[layerId]    = new ModelClassNS.VertexEdgesInfo();
        }
Ejemplo n.º 3
0
 public static void moveVertex(
     NetworkContainersNS.Graph graph,
     string vertexId,
     float x,
     float y
     )
 {
     NetworkContainersNS.Vertex vtx = graph.vertices[vertexId];
     vtx.xLocation = x;
     vtx.yLocation = y;
 }
Ejemplo n.º 4
0
        private static ResponseJson.VertexData getVertexJsonData(NetworkContainersNS.Vertex vtx)
        {
            ResponseJson.VertexData jsonVtxData = new ResponseJson.VertexData {
                label = vtx.label,
                geo   = new ResponseJson.GeoData {
                    x = vtx.xLocation,
                    y = vtx.yLocation,
                },
                ports = new Dictionary <string, ResponseJson.GraphPortData>()
            };

            foreach (KeyValuePair <string, NetworkContainersNS.NetworkPort> edgeEntry in vtx.ports)
            {
                jsonVtxData.ports[edgeEntry.Key] = new ResponseJson.GraphPortData {
                    side     = GraphUtils.getPortSideString(edgeEntry.Value.side),
                    position = edgeEntry.Value.position,
                    portType = GraphUtils.getPortTypeString(edgeEntry.Value.type)
                };
            }

            return(jsonVtxData);
        }