protected override void SolveInstance(IGH_DataAccess DA) { string p = ""; Point3d sPt = Point3d.Unset; bool b = false; double tol = 1.0; if (!DA.GetData(0, ref p)) { return; } if (!DA.GetData(1, ref sPt)) { return; } if (!DA.GetData(2, ref b)) { return; } DA.GetData(3, ref tol); // Recalculate tolerance to be in correct (local) units tol *= RhinoUtilities.ScalingFactor(); if (b) { // Get raw data List <string[, ]> data = ExcelTools.ExcelUtilities.GetAllData2(p); if (data.Count != 2) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Excel file containing " + data.Count + " worksheet(s) rather than the expected 2. File correct?"); if (data.Count < 2) { return; } } // Get subsets string[,] xyProfileData = GetXYProfileData(data[0]); string[,] hProfileData = GetHeightProfileData(data[1]); //Create plane curve TrackCurve xyTC = CreateXYProfileTrackCurve(xyProfileData, tol); TrackCurve hTC = CreateHeightProfileCurve(hProfileData); TrackCurve combTC = TrackCurveUtilities.JoinTrackCurves(xyTC, hTC, tol); xyTC.Translate((Vector3d)sPt); hTC.Translate((Vector3d)sPt); combTC.Translate((Vector3d)sPt); DA.SetData(0, xyTC); DA.SetData(1, hTC); DA.SetData(2, combTC); //DA.SetData(3, CurveDebug); } }
/////////////////////////////// HEIGHT /////////////////////////////// private TrackCurve CreateHeightProfileCurve(string[,] hProfileData) { List <Curve> crvs = new List <Curve>(); List <TrackSection> ts = new List <TrackSection>(); Point3d sPt = CreateFirstHeightPoint(hProfileData); Point3d cePt = new Point3d(sPt.X, sPt.Y, sPt.Z); bool b; for (int i = 0; i < hProfileData.GetLength(0); i++) { b = false; if (hProfileData[i, 0] == "Raklinje") { crvs.Add(CreateHeightLine(hProfileData, i, cePt, 1).ToNurbsCurve()); // DEBUG TOLERANCE! b = true; } else if (hProfileData[i, 0] == "Cirkulär") { crvs.Add(CreateHeightArc(hProfileData, i, cePt, 1).ToNurbsCurve()); // DEBUG TOLERANCE! b = true; } // Update current end point if curve has been added if (b) { cePt = crvs[crvs.Count - 1].PointAtEnd; } // Create track section if (hProfileData[i, 1].StartsWith("KM")) { TrackSection tc = null; if (b || hProfileData[i, 0] == "Slutsektion") { if (CreateTrackSection(hProfileData[i, 1], crvs[crvs.Count - 1].PointAtStart, crvs[crvs.Count - 1], out tc)) { ts.Add(tc); } } else { if (CreateTrackSectionConnection(hProfileData[i, 1], cePt, crvs[crvs.Count - 1], out tc)) { ts.Add(tc); } } } } Curve[] oCrvs = Curve.JoinCurves(crvs); if (oCrvs.Length != 1) { string message = "Error: more than one height curve created."; AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message); throw new Exception(message); } else { TrackCurve tc = new TrackCurve(oCrvs[0], ts); // Move to origo Vector3d v = new Vector3d(-crvs[0].PointAtStart.X, 0, 0); tc.Translate(v); return(tc); } }
private TrackCurve CreateXYProfileTrackCurve(string[,] xyProfileData, double tol) { List <Curve> crvs = new List <Curve>(); List <TrackSection> tcs = new List <TrackSection>(); for (int i = 0; i < xyProfileData.GetLength(0); i++) { if (xyProfileData[i, 1] == "RL") { crvs.Add(CreateXYLine(xyProfileData, i).ToNurbsCurve()); } else if (xyProfileData[i, 1] == "C") { crvs.Add(CreateXYArc(xyProfileData, i).ToNurbsCurve()); } else if (xyProfileData[i, 1] == "ÖK") { crvs.Add(CreateXYClothoid(xyProfileData, i, tol).ToNurbsCurve()); } // Create track sections if (xyProfileData[i, 2].StartsWith("KM")) { TrackSection tc = null; if (xyProfileData[i, 1] != "") { if (CreateTrackSection(xyProfileData[i, 2], crvs[crvs.Count - 1].PointAtStart, crvs[crvs.Count - 1], out tc)) { tcs.Add(tc); } else // Maybe add another check here if (CreateTrackSectionConnection(xyProfileData[i, 2], crvs[crvs.Count - 1].PointAtEnd, crvs[crvs.Count - 1], out tc)) { tcs.Add(tc); } } } } Curve[] jCrvs = Curve.JoinCurves(crvs); //CurveDebug = jCrvs[0]; //DEBUG if (jCrvs.Length > 1) { throw new Exception("Unable to join curves"); } else { // Join and add track sections TrackCurve tc = new TrackCurve(jCrvs[0]); tc.AddTrackSection(tcs); // Vector from start point of curve to origin Vector3d v = new Vector3d(jCrvs[0].PointAtStart); v.Reverse(); tc.Translate(v); return(tc); } }