public static PathMap ImportFromCSV(string text, IPathmapErrorHandler errorHandler) { CsvFrame frame; try { frame = CsvFrame.ParseOne(text); } catch (Exception) { errorHandler.Error("Incorrect CSV format."); return(null); } if (frame.VariableSetOwner != "Global") { errorHandler.Error("Need the global variable set, got the '" + frame.VariableSetOwner + "' variable set instead."); return(null); } List <Vertex> vectors = new List <Vertex>(); CsvArray nodeArray = frame.VariableValues[nodesOut] as CsvArray; if (nodeArray == null) { errorHandler.Error("Incorrect format, 'nodesOut' is not an array. Did you compile your pathmap?"); return(null); } for (int i = 0; i < nodeArray.Values.Length; i++) { CsvVector nodeVector = (CsvVector)nodeArray.Values[i]; vectors.Add(nodeVector.Value); } List <Segment> segments = new List <Segment>(); CsvArray segmentArray = frame.VariableValues[segmentsOut] as CsvArray; if (segmentArray == null) { errorHandler.Error("Incorrect format, 'segmentsOut' is not an array."); return(null); } for (int i = 0; i < segmentArray.Values.Length; i++) { CsvVector segmentVector = (CsvVector)segmentArray.Values[i]; segments.Add(new Segment( (int)segmentVector.Value.X, (int)segmentVector.Value.Y, (int)Math.Round((segmentVector.Value.X % 1) * 100), (int)Math.Round((segmentVector.Value.Y % 1) * 100) )); } return(new PathMap(vectors.ToArray(), segments.ToArray())); }
public static Pathmap ImportFromActionSet(string text, IPathmapErrorHandler errorHandler) { ConvertTextToElement tte = new ConvertTextToElement(text); Workshop workshop = tte.GetActionList(); Vertex[] nodeArray = null; Vertex[] segmentArray = null; Vertex[] attributeArray = null; const string nodesOut = "nodesOut", segmentsOut = "segmentsOut", attributesOut = "attributesOut"; // Get the variable values. foreach (var action in workshop.Actions) { if (action is SetVariableAction setVariable) { // Get the variable name. switch (setVariable.Variable.Name) { // Nodes case nodesOut: nodeArray = ExtractVertexArray(nodesOut, errorHandler, setVariable.Value); break; // Segments case segmentsOut: segmentArray = ExtractVertexArray(segmentsOut, errorHandler, setVariable.Value); break; // Attributes case attributesOut: attributeArray = ExtractVertexArray(attributesOut, errorHandler, setVariable.Value); break; } } } if (nodeArray == null) { errorHandler.Error($"Incorrect format, '{nodesOut}' does not exist. Did you compile your pathmap?"); return(null); } if (segmentArray == null) { errorHandler.Error($"Incorrect format, '{segmentsOut}' does not exist. Did you compile your pathmap?"); return(null); } if (attributeArray == null) { errorHandler.Error($"Incorrect format, '{attributesOut}' does not exist. Did you compile your pathmap?"); return(null); } Segment[] segments = new Segment[segmentArray.Length]; for (int i = 0; i < segments.Length; i++) { segments[i] = new Segment((int)segmentArray[i].X, (int)segmentArray[i].Y); } MapAttribute[] attributes = new MapAttribute[attributeArray.Length]; for (int i = 0; i < attributes.Length; i++) { attributes[i] = new MapAttribute( (int)attributeArray[i].X, (int)attributeArray[i].Y, (int)attributeArray[i].Z ); } return(new Pathmap(nodeArray, segments, attributes)); }
public static Pathmap ImportFromCSV(string text, IPathmapErrorHandler errorHandler) { CsvFrame frame; try { frame = CsvFrame.ParseOne(text); } catch (Exception) { errorHandler.Error("Incorrect CSV format."); return(null); } if (frame.VariableSetOwner != "Global") { errorHandler.Error("Need the global variable set, got the '" + frame.VariableSetOwner + "' variable set instead."); return(null); } // Get nodes CsvArray nodeArray = frame.VariableValues[nodesOut] as CsvArray; if (nodeArray == null) { errorHandler.Error("Incorrect format, 'nodesOut' is not an array. Did you compile your pathmap?"); return(null); } Vertex[] vectors = new Vertex[nodeArray.Values.Length]; for (int i = 0; i < nodeArray.Values.Length; i++) { CsvVector nodeVector = (CsvVector)nodeArray.Values[i]; vectors[i] = nodeVector.Value; } // Get segments CsvArray segmentArray = frame.VariableValues[segmentsOut] as CsvArray; if (segmentArray == null) { errorHandler.Error("Incorrect format, 'segmentsOut' is not an array."); return(null); } Segment[] segments = new Segment[segmentArray.Values.Length]; for (int i = 0; i < segmentArray.Values.Length; i++) { CsvVector segmentVector = (CsvVector)segmentArray.Values[i]; segments[i] = new Segment( (int)segmentVector.Value.X, (int)segmentVector.Value.Y ); } // Get attributes CsvArray attributeArray = frame.VariableValues[attributesOut] as CsvArray; if (attributeArray == null) { errorHandler.Error("Incorrect format, 'attributesOut' is not an array."); return(null); } MapAttribute[] attributes = new MapAttribute[attributeArray.Values.Length]; for (int i = 0; i < attributeArray.Values.Length; i++) { CsvVector attributeVector = (CsvVector)attributeArray.Values[i]; attributes[i] = new MapAttribute( (int)attributeVector.Value.X, (int)attributeVector.Value.Y, (int)attributeVector.Value.Z ); } return(new Pathmap(vectors.ToArray(), segments.ToArray(), attributes)); }