public override void DoWork(Action <string, double> ReportProgress, Action Done) { if (CancellationToken.IsCancellationRequested) { return; } int branchIndex = 0, completed = 0; foreach (var list in Objects.Branches) { var path = Objects.Paths[branchIndex]; foreach (var item in list) { if (CancellationToken.IsCancellationRequested) { return; } var converted = Utilities.TryConvertItemToNative(item?.Value, Converter); ConvertedObjects.Append(converted, path); ReportProgress(Id, (completed++ + 1) / (double)Objects.Count()); } branchIndex++; } Done(); }
public override void DoWork(Action <string, double> ReportProgress, Action Done) { if (CancellationToken.IsCancellationRequested) { return; } int branchIndex = 0, completed = 0; foreach (var list in Objects.Branches) { var path = Objects.Paths[branchIndex]; foreach (var item in list) { if (CancellationToken.IsCancellationRequested) { return; } var converted = Extras.Utilities.TryConvertItemToSpeckle(item, Converter) as Base; ConvertedObjects.Append(new GH_SpeckleBase { Value = converted }, Objects.Paths[branchIndex]); ReportProgress(Id, ((completed++ + 1) / (double)Objects.Count())); } branchIndex++; } Done(); }
public override void DoWork(Action <string, double> ReportProgress, Action Done) { try { if (CancellationToken.IsCancellationRequested) { return; } int branchIndex = 0, completed = 0; foreach (var list in Objects.Branches) { var path = Objects.Paths[branchIndex]; foreach (var item in list) { if (CancellationToken.IsCancellationRequested) { return; } if (item != null) { try { var serialised = Operations.Serialize(item.Value); ConvertedObjects.Append(new GH_String { Value = serialised }, path); } catch (Exception e) { Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, e.Message); } } else { ConvertedObjects.Append(new GH_String { Value = null }, path); Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Object at {Objects.Paths[branchIndex]} is not a Speckle object."); } ReportProgress(Id, ((completed++ + 1) / (double)Objects.Count())); } branchIndex++; } Done(); } catch (Exception e) { // If we reach this, something happened that we weren't expecting... Log.CaptureException(e); Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Something went terribly wrong... " + e.Message); Parent.Message = "Error"; } }
public override void DoWork(Action <string, double> ReportProgress, Action Done) { try { if (CancellationToken.IsCancellationRequested) { return; } int branchIndex = 0, completed = 0; foreach (var list in Objects.Branches) { var path = Objects.Paths[branchIndex]; foreach (var item in list) { if (CancellationToken.IsCancellationRequested) { return; } var converted = Utilities.TryConvertItemToSpeckle(item, Converter, true); if (converted == null) { RuntimeMessages.Add((GH_RuntimeMessageLevel.Warning, $"Cannot convert item at {path}[{list.IndexOf(item)}] to Speckle.")); } else if (converted.GetType().IsSimpleType()) { ConvertedObjects.Append(new GH_ObjectWrapper(converted)); } else { ConvertedObjects.Append(new GH_SpeckleBase { Value = converted as Base }, Objects.Paths[branchIndex]); } ReportProgress(Id, Math.Round((completed++ + 1) / (double)Objects.Count(), 2)); } branchIndex++; } } catch (Exception e) { // If we reach this, something happened that we weren't expecting... Log.CaptureException(e); RuntimeMessages.Add((GH_RuntimeMessageLevel.Error, "Something went terribly wrong... " + e.Message)); Parent.Message = "Error"; } Done(); }
public override void DoWork(Action <string, double> ReportProgress, Action Done) { try { if (CancellationToken.IsCancellationRequested) { return; } int branchIndex = 0, completed = 0; foreach (var list in Objects.Branches) { var path = Objects.Paths[branchIndex]; foreach (var item in list) { if (CancellationToken.IsCancellationRequested) { return; } try { var deserialized = Operations.Deserialize(item.Value); ConvertedObjects.Append(new GH_SpeckleBase { Value = deserialized }, path); } catch (Exception e) { // Add null to objects to respect output paths. ConvertedObjects.Append(null, path); RuntimeMessages.Add((GH_RuntimeMessageLevel.Warning, $"Cannot deserialize object at path {path}[{list.IndexOf(item)}]: {e.Message}.")); } ReportProgress(Id, ((completed++ + 1) / (double)Objects.Count())); } branchIndex++; } Done(); } catch (Exception e) { // If we reach this, something happened that we weren't expecting... Log.CaptureException(e); RuntimeMessages.Add((GH_RuntimeMessageLevel.Error, "Something went terribly wrong... " + e.Message)); Parent.Message = "Error"; } }
public override void DoWork(Action <string, double> ReportProgress, Action Done) { if (CancellationToken.IsCancellationRequested) { return; } int branchIndex = 0, completed = 0; foreach (var list in Objects.Branches) { var path = Objects.Paths[branchIndex]; foreach (var item in list) { if (CancellationToken.IsCancellationRequested) { return; } if (item != null) { try { var serialised = Operations.Serialize(item.Value); ConvertedObjects.Append(new GH_String { Value = serialised }, path); } catch (Exception e) { } } else { ConvertedObjects.Append(new GH_String { Value = null }, path); Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Object at {Objects.Paths[branchIndex]} is not a Speckle object."); } ReportProgress(Id, ((completed++ + 1) / (double)Objects.Count())); } branchIndex++; } Done(); }
public override void DoWork(Action <string, double> ReportProgress, Action Done) { try { if (CancellationToken.IsCancellationRequested) { return; } int branchIndex = 0, completed = 0; foreach (var list in Objects.Branches) { var path = Objects.Paths[branchIndex]; foreach (var item in list) { if (CancellationToken.IsCancellationRequested) { return; } var converted = Utilities.TryConvertItemToSpeckle(item, Converter) as Base; ConvertedObjects.Append(new GH_SpeckleBase { Value = converted }, Objects.Paths[branchIndex]); ReportProgress(Id, ((completed++ + 1) / (double)Objects.Count())); } branchIndex++; } Done(); } catch (Exception e) { // If we reach this, something happened that we weren't expecting... Log.CaptureException(e); Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Something went terribly wrong... " + e.Message); Parent.Message = "Error"; } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Structure <IGH_GeometricGoo> iMeshTree = new GH_Structure <IGH_GeometricGoo>(); GH_Structure <GH_Integer> ilevelsTree = new GH_Structure <GH_Integer>(); DA.GetDataTree <IGH_GeometricGoo>(0, out iMeshTree); DA.GetDataTree <GH_Integer>(1, out ilevelsTree); GH_Structure <IGH_GeometricGoo> SubdivideMesh = new GH_Structure <IGH_GeometricGoo>(); GH_Structure <GH_Integer> selectVertices = new GH_Structure <GH_Integer>(); GH_Structure <GH_Integer> selectEdges = new GH_Structure <GH_Integer>(); GH_Structure <GH_Integer> selectFaces = new GH_Structure <GH_Integer>(); #region input parameters switch (_mode) { case FoldMode.SimpleSubdivision: break; case FoldMode.Vertices: DA.GetDataTree(2, out selectVertices); break; case FoldMode.Edges: DA.GetDataTree(2, out selectEdges); break; case FoldMode.Faces: DA.GetDataTree(2, out selectFaces); break; case FoldMode.VerticesAndEdges: DA.GetDataTree(2, out selectVertices); DA.GetDataTree(3, out selectEdges); break; case FoldMode.VerticesAndFaces: DA.GetDataTree(2, out selectVertices); DA.GetDataTree(3, out selectFaces); break; case FoldMode.EdgesAndFace: DA.GetDataTree(2, out selectEdges); DA.GetDataTree(3, out selectFaces); break; case FoldMode.AllSelect: DA.GetDataTree(2, out selectVertices); DA.GetDataTree(3, out selectEdges); DA.GetDataTree(4, out selectFaces); break; default: throw new ArgumentOutOfRangeException(); } #endregion for (int i = 0; i < iMeshTree.PathCount; i++) { GH_Path path = iMeshTree.get_Path(i); for (int j = 0; j < iMeshTree.Branches[i].Count; j++) { Mesh mesh; if (!iMeshTree.Branches[i][j].CastTo <Mesh>(out mesh)) { continue; } else { List <int> verticesIndices = new List <int>(); List <int> edgesIndices = new List <int>(); List <int> facesIndices = new List <int>(); #region select vertices for (int vi = 0; vi < selectVertices.PathCount; vi++) { if (path != selectVertices.get_Path(vi)) { continue; } else { foreach (var sv in selectVertices[vi].ToList()) { int number; sv.CastTo <int>(out number); verticesIndices.Add(number); } } } #endregion #region select edges for (int vi = 0; vi < selectEdges.PathCount; vi++) { if (path != selectEdges.get_Path(vi)) { continue; } else { foreach (var sv in selectEdges[vi].ToList()) { int number; sv.CastTo <int>(out number); edgesIndices.Add(number); } } } #endregion #region select faces for (int vi = 0; vi < selectFaces.PathCount; vi++) { if (path != selectFaces.get_Path(vi)) { continue; } else { foreach (var sv in selectFaces[vi].ToList()) { int number; sv.CastTo <int>(out number); facesIndices.Add(number); } } } #endregion #region level for (int l = 0; l < ilevelsTree.PathCount; l++) { int level; GH_Path pathLevel = ilevelsTree.get_Path(l); if (ilevelsTree.Count() == 1) { ilevelsTree.Branches[l][0].CastTo <int>(out level); SubdivideMesh.Append( GH_Convert.ToGeometricGoo( mesh.ToPlanktonMesh().CatmullClark( level, verticesIndices, edgesIndices, facesIndices).ToRhinoMesh()), path); break; } else if (path != pathLevel) { continue; } else { for (int vj = 0; vj < ilevelsTree.Branches[l].Count; vj++) { ilevelsTree.Branches[l][vj].CastTo <int>(out level); SubdivideMesh.Append( GH_Convert.ToGeometricGoo( mesh.ToPlanktonMesh().CatmullClark( level, verticesIndices, edgesIndices, facesIndices).ToRhinoMesh()), path); } } } #endregion } } } DA.SetDataTree(0, SubdivideMesh); }