Example #1
0
 public override bool IsReady()
 {
     if (!base.IsReady())
     {
         return(false);
     }
     lines = streamReader.ReadToEnd().Split(lineEnding);
     if (lines.Length < 2)
     {
         G3DLogger.Log(NODATA_ERR, this.filePath);
         return(false);
     }
     for (int i = 0; i < lines.Length; i++)
     {
         string line = lines[i];
         lines[i] = line.Replace("\n", String.Empty).Replace("\r", String.Empty).Trim();
     }
     columnNames = lines[0].Split(delimiter);
     if (!new HashSet <string>(requiredRecordKeys).IsSubsetOf(new HashSet <string>(columnNames)))
     {
         string missingKeys = string.Join(", ", requiredRecordKeys);
         G3DLogger.Log(MISSINGKEYS_ERR, new object[] { this.filePath, missingKeys });
         return(false);
     }
     return(true);
 }
Example #2
0
        public Node[] make(IRecord[] nodeRecords)
        {
            List <Node> nodes = new List <Node>();
            Node        node;
            string      id;
            string      label;

            foreach (IRecord nodeRecord in nodeRecords)
            {
                if (nodeRecord.TryGet("id", out id))
                {
                    node = new Node(id);
                    if (nodeRecord.TryGet("label", out label))
                    {
                        node.SetLabel(label);
                    }
                    nodes.Add(node);
                }
                else
                {
                    G3DLogger.Log("NodeFactory misses id in NodeRecord, skipping.");
                }
            }
            return(nodes.ToArray());
        }
Example #3
0
 public void SetEdgeType(string edgeType)
 {
     if (edgeType.Length == 1)
     {
         this.SetEdgeType((char)edgeType[0]);
     }
     else
     {
         G3DLogger.Log("Unknown edge-type '{0}' for edge id {1}", new object[] { edgeType, this.GetId() });
     }
 }
Example #4
0
        public bool TryGetElementRecords(string dataFolderPath, string fileFormat, out ElementRecords elementRecords)
        {
            switch (fileFormat)
            {
            case "csv":
                return(importCSV(dataFolderPath, out elementRecords));

            default:
                G3DLogger.Log("Unsupported file format: {0}", fileFormat);
                elementRecords = null;
                return(false);
            }
        }
Example #5
0
 public virtual bool IsReady()
 {
     try
     {
         streamReader = new StreamReader(filePath);
         G3DLogger.Log(STREAMREADER_SUCCESS, filePath);
         return(true);
     }
     catch (Exception e)
     {
         G3DLogger.Log(STREAMREADER_EXCPTN, e.Message);
     }
     return(false);
 }
Example #6
0
        public Edge[] make(IRecord[] edgeRecords)
        {
            List <Edge> edges = new List <Edge>();
            Edge        edge;
            INode       sourceNode;
            INode       targetNode;
            string      id;
            string      sourceId;
            string      targetId;
            string      label;
            string      type;

            foreach (IRecord edgeRecord in edgeRecords)
            {
                if (edgeRecord.TryGet("id", out id) &&
                    edgeRecord.TryGet("source", out sourceId) &&
                    edgeRecord.TryGet("target", out targetId))
                {
                    if (this.graph.TryGetNode(sourceId, out sourceNode) &&
                        this.graph.TryGetNode(targetId, out targetNode))
                    {
                        edge = new Edge(id, sourceNode, targetNode);

                        if (edgeRecord.TryGet("label", out label))
                        {
                            edge.SetLabel(label);
                        }
                        if (edgeRecord.TryGet("type", out type))
                        {
                            edge.SetEdgeType(type);
                        }
                        edges.Add(edge);
                    }
                    else
                    {
                        G3DLogger.Log("EdgeFactory can't find source or target node in Graph for Edge  {0} ", id);
                    }
                }
                else
                {
                    G3DLogger.Log("EdgeFactory misses id, sourceId, targetId in edgeRecord");
                }
            }
            return(edges.ToArray());
        }
Example #7
0
        public CSVRecord[] GetRecords()
        {
            int numKeys = columnNames.Length;
            List <CSVRecord> recordList = new List <CSVRecord>();

            string[] values;
            for (int i = 1; i < lines.Length; i++)
            {
                values = lines[i].Split(delimiter);
                if (values.Length > 0)
                {
                    try
                    {
                        recordList.Add(new CSVRecord(columnNames, values));
                    }
                    catch (IndexOutOfRangeException e)
                    {
                        G3DLogger.Log(FIELDNUMBER_ERR, new object[] { values.Length, numKeys, i, this.filePath });
                    }
                }
            }

            return(recordList.ToArray());
        }
Example #8
0
        public void SetHighlighted(int state)
        {
            switch (state)
            {
            case 0:
                this.ownlineRenderer.material        = this.NormalMaterial;
                this.ownlineRenderer.widthMultiplier = normalWidth;
                break;

            case 1:
                this.ownlineRenderer.material        = this.HighlitedMaterial;
                this.ownlineRenderer.widthMultiplier = highlightedWidth;
                break;

            case 2:
                this.ownlineRenderer.material        = this.HighlitedMaterial2;
                this.ownlineRenderer.widthMultiplier = highlightedWidth * 2;
                break;

            default:
                G3DLogger.Log("HighlightableTernary got invalid state argument {1} in 'SetHighlighted(int state)', state must be 0, 1 or 2!", state);
                break;
            }
        }
Example #9
0
        public EdgeAvatar(GameObject nodeAvatarPrefab, IEdge edge)
        {
            this.gameObject = MonoBehaviour.Instantiate(nodeAvatarPrefab, Vector3.zero, Quaternion.identity);

            MBEdgeAvatar mbEdegAvatar = this.gameObject.GetComponent <MBEdgeAvatar>();
            INode        source       = edge.GetSourceNode();
            INode        target       = edge.GetTargetNode();
            IAvatar      sourceAvatar;
            IAvatar      targetAvatar;

            if (source.TryGetAvatar(out sourceAvatar) && target.TryGetAvatar(out targetAvatar) && mbEdegAvatar != null)
            {
                this.sourceNodeAvatar = (INodeAvatar)sourceAvatar;
                this.targetNodeAvatar = (INodeAvatar)targetAvatar;

                mbEdegAvatar.SetSourceNodeAvatar(this.sourceNodeAvatar);
                mbEdegAvatar.SetTargetNodeAvatar(this.targetNodeAvatar);
            }
            else
            {
                G3DLogger.Log("Missing component in edge {0}, avatar constructor failed.", edge.GetId());
                this.SelfDestruct();
            }
        }