public DataContainer CollectData(List <List <object> > dataFromApp) { DataContainer dataContainer = new DataContainer(dataFromApp.Count); for (int i = 0; i < dataFromApp.Count; i++) { DataNode <ParasiteAbstractObject>[] nodeArray = new DataNode <ParasiteAbstractObject> [dataFromApp[i].Count]; for (int j = 0; j < dataFromApp[i].Count; j++) { if (dataFromApp[i][j] == null) { continue; } else if (dataFromApp[i][j] is ParasiteObject pObj) { if (pObj.Data is Solid) { Solid s = pObj.Data as Solid; Parasite_BrepSolid pSolid = ParasiteConversion.ToParasiteType(s); pObj.Data = pSolid; nodeArray[j] = new DataNode <ParasiteAbstractObject>(pObj); } } else if (dataFromApp[i][j] is Point p) { Parasite_Point3d point = ParasiteConversion.ToParasiteType(p); nodeArray[j] = new DataNode <ParasiteAbstractObject>(point); } else if (dataFromApp[i][j] is Sphere sph) { Parasite_Sphere s = new Parasite_Sphere(ParasiteConversion.ToParasiteType(sph.CenterPoint), sph.Radius); nodeArray[j] = new DataNode <ParasiteAbstractObject>(s); } else if (dataFromApp[i][j] is Solid solid) { Parasite_BrepSolid pSolid = ParasiteConversion.ToParasiteType(solid); nodeArray[j] = new DataNode <ParasiteAbstractObject>(pSolid); } //else // throw new ParasiteNotImplementedExceptions("Object type not implemented yet!"); } dataContainer.Data[i] = nodeArray; } return(dataContainer); }
/// <summary> /// /// </summary> /// <param name="brep"></param> /// <returns></returns> public static Autodesk.DesignScript.Geometry.Solid ToDynamoType(Parasite_BrepSolid brep) { //Parasite_Point3d[][] vertices = brep.Vertices; //List<Autodesk.DesignScript.Geometry.Surface> surfaces = new List<Autodesk.DesignScript.Geometry.Surface>(); //for (int i = 0; i < vertices.Length; i++) //{ // IEnumerable<Autodesk.DesignScript.Geometry.Point> pts = vertices[i].Select(x => ToDynamoType(x)); // surfaces.Add(Autodesk.DesignScript.Geometry.Surface.ByPerimeterPoints(pts)); //} //return Autodesk.DesignScript.Geometry.Solid.ByJoinedSurfaces(surfaces); throw new NotImplementedException(); }
/// <summary> /// /// </summary> /// <param name="solid"></param> /// <returns></returns> public static Brep ToRhinoType(Parasite_BrepSolid solid, double RhinoDocTol) { int n = solid.Faces.Length; Brep[] faces = new Brep[n]; for (int i = 0; i < n; i++) { Parasite_Point3d[] verts = solid.Faces[i].Vertices.ToArray(); if (verts.Length < 3) { throw new ParasiteArgumentException("A Brep Face cant be constructed from less than 2 vertices!"); } else if (verts.Length == 3) { Point3d a = ToRhinoType(verts[0]); Point3d b = ToRhinoType(verts[1]); Point3d c = ToRhinoType(verts[2]); faces[i] = Brep.CreateFromCornerPoints(a, b, c, RhinoDocTol); } else if (verts.Length == 4) { Point3d a = ToRhinoType(verts[0]); Point3d b = ToRhinoType(verts[1]); Point3d c = ToRhinoType(verts[2]); Point3d d = ToRhinoType(verts[3]); faces[i] = Brep.CreateFromCornerPoints(a, b, c, d, RhinoDocTol); } /// Build curve from vertices to then build a Brep face else { IEnumerable <Parasite_Line> edges = solid.Faces[i].Edges; IEnumerable <Curve> edgesAsCurves = ToRhinoType(edges); Brep[] b = Brep.CreatePlanarBreps(edgesAsCurves, RhinoDocTol); faces[i] = b[0]; } } Brep output = null; try { Brep[] joinedBreps = Brep.JoinBreps(faces, RhinoDocTol); output = joinedBreps[0]; } catch { if (output == null) { // Check if folder exists, if not create it. if (!Directory.Exists(FolderInfo.dirPath)) { Directory.CreateDirectory(FolderInfo.dirPath); } string pathToFolder = Path.Combine(FolderInfo.dirPath, "RebelBreps"); FileStream fs = new FileStream(pathToFolder, FileMode.Create); // Construct a BinaryFormatter and use it to serialize the data to the stream. BinaryFormatter formatter = new BinaryFormatter(); try { formatter.Serialize(fs, faces); } catch (SerializationException e) { throw new SerializationException("Failed to serialize: " + e.Message); } finally { fs.Close(); } throw new ParasiteConversionExceptions(output.GetType(), solid.GetType()); } } return(output); }