public static ResponseJson.LayerData getLayerJsonData( ModelClassNS.ModelClass modelStruct, string layerId ) { Layers.Layer layer = modelStruct.layerDict.layers[layerId]; var ports = new Dictionary <string, ResponseJson.LayerPortData>(); var fields = new Dictionary <string, ResponseJson.LayerFieldData>(); foreach (string portName in layer.getPortNames()) { ports[portName] = new ResponseJson.LayerPortData { valueName = layer.getValueNameOfPort(portName), }; } List <string> occupiedValueNames = modelStruct.edgesByVertex[layerId].edgesIn.Select((string edgeId) => { return(modelStruct.layerDict.layers[layerId].getValueNameOfPort(modelStruct.graph.edges[edgeId].targetPortId)); }).ToList(); foreach (string fieldName in layer.getValueNames()) { bool fieldOccupiedByEdge = occupiedValueNames.Contains(fieldName); fields[fieldName] = new ResponseJson.LayerFieldData { value = layer.getValueString(fieldName), fieldIsReadonly = fieldOccupiedByEdge || layer.getValueIsReadonly(fieldName) }; } return(new ResponseJson.LayerData { ports = ports, fields = fields, }); }
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(); }