/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // INPUT // output path string _envimetFolder = null; // location and grid Location _envimetLocation = GetLocationInit(BASE_LOC_NAME, BASE_LOC_ROTATION); GridLib _envimentGrid = new GridLib(); NestingGrid nestingGrid_ = new NestingGrid(); // list objects List <Entity> _envimentObjects_ = new List <Entity>(); // path string fileName_ = "Morpho"; // toggle bool _runIt = false; bool viewGrid_ = false; DA.GetData(0, ref _envimetFolder); DA.GetData(1, ref _envimetLocation); DA.GetData(2, ref _envimentGrid); DA.GetData(3, ref nestingGrid_); DA.GetDataList(4, _envimentObjects_); DA.GetData(5, ref fileName_); DA.GetData(6, ref _runIt); DA.GetData(7, ref viewGrid_); if (_envimetFolder == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Use DF Envimet Installation Directory to set installation folder of envimet."); return; } Preparation preparation = new Preparation(_envimentGrid, _envimetLocation); string information = String.Format("Dimension of grid: {0},{1},{2}\nNumber of nesting grid: {3}", _envimentGrid.NumX, _envimentGrid.NumY, _envimentGrid.NumZ, nestingGrid_.NumNestingGrid); DA.SetData(0, information); if (viewGrid_) { DA.SetDataList(1, _envimentGrid.GridXY()); DA.SetDataList(2, _envimentGrid.GridXZ()); DA.SetDataList(3, _envimentGrid.GridYZ()); } if (_runIt) { // default preparation object List <Building> buildings = new List <Building>(); List <Object2d> soils = new List <Object2d>(); List <Object2d> plant2d = new List <Object2d>(); List <Plant3d> plant3d = new List <Plant3d>(); List <Receptor> receptors = new List <Receptor>(); List <Object2d> sources = new List <Object2d>(); List <Terrain> terrain = new List <Terrain>(); List <SimpleWall> simpleW = new List <SimpleWall>(); preparation.EnvimetPart["grid"] = _envimentGrid; preparation.EnvimetPart["nestingGrid"] = nestingGrid_; preparation.EnvimetPart["location"] = _envimetLocation; if (_envimentObjects_.Count > 0) { Dictionary <string, List <Entity> > objectDict = GetObjectDivideByType(_envimentObjects_); string soilMatrix = null; string plant2dMatrix = null; string sourceMatrix = null; string simpleWallShadingsMatrix = null; List <string[]> plant3dXml = new List <string[]>(); List <string[]> receptorsXml = new List <string[]>(); // building and terrain if (objectDict["building"].Count > 0 && objectDict["terrain"].Count == 0) { buildings = objectDict["building"].ConvertAll(o => (Building)o); Tuple <Dictionary <string, string>, List <string[]> > buildingComponents = Preparation.GetBuildingPreparationMatrix(_envimentGrid, buildings, null, demVoxel: new Point3d[] { }); if (BuildingWarning(buildingComponents)) { return; } preparation.EnvimetPart["building"] = buildingComponents; } else if (objectDict["building"].Count == 0 && objectDict["terrain"].Count > 0) { terrain = objectDict["terrain"].ConvertAll(o => (Terrain)o); Warning(terrain); Tuple <Point3d[], string, string> terrainComponents = Preparation.GetDemMatrix(terrain[0], _envimentGrid); preparation.EnvimetPart["dem"] = terrainComponents; } else if (objectDict["building"].Count > 0 && objectDict["terrain"].Count > 0) { terrain = objectDict["terrain"].ConvertAll(o => (Terrain)o); buildings = objectDict["building"].ConvertAll(o => (Building)o); Warning(terrain); Tuple <Point3d[], string, string> terrainComponents = Preparation.GetDemMatrix(terrain[0], _envimentGrid); preparation.EnvimetPart["dem"] = terrainComponents; Tuple <Dictionary <string, string>, List <string[]> > buildingComponents = Preparation.GetBuildingPreparationMatrix(_envimentGrid, buildings, terrain[0], demVoxel: terrainComponents.Item1); if (BuildingWarning(buildingComponents)) { return; } preparation.EnvimetPart["building"] = buildingComponents; } if (objectDict["soil"].Count > 0) { soils = objectDict["soil"].ConvertAll(o => (Object2d)o); soilMatrix = Preparation.Get2dObjectMatrix(_envimentGrid, soils, Material.CommonSoilMaterial); preparation.EnvimetPart["soils2D"] = soilMatrix; } if (objectDict["plant2d"].Count > 0) { plant2d = objectDict["plant2d"].ConvertAll(o => (Object2d)o); plant2dMatrix = Preparation.Get2dObjectMatrix(_envimentGrid, plant2d, Material.DefaultEmpty); preparation.EnvimetPart["simpleplants2D"] = plant2dMatrix; } if (objectDict["plant3d"].Count > 0) { plant3d = objectDict["plant3d"].ConvertAll(o => (Plant3d)o); plant3dXml = Preparation.GetPlant3dMatrix(_envimentGrid, plant3d); preparation.EnvimetPart["plant3d"] = plant3dXml; } if (objectDict["receptors"].Count > 0) { receptors = objectDict["receptors"].ConvertAll(o => (Receptor)o); receptorsXml = Preparation.GetReceptorsMatrix(_envimentGrid, receptors); preparation.EnvimetPart["receptors"] = receptorsXml; } if (objectDict["source"].Count > 0) { sources = objectDict["source"].ConvertAll(o => (Object2d)o); sourceMatrix = Preparation.Get2dObjectMatrix(_envimentGrid, sources, Material.DefaultEmpty); preparation.EnvimetPart["sources2D"] = sourceMatrix; } if (objectDict["simpleW"].Count > 0) { simpleW = objectDict["simpleW"].ConvertAll(o => (SimpleWall)o); simpleWallShadingsMatrix = Preparation.GetSimpleWallZMatrix(_envimentGrid, simpleW); preparation.EnvimetPart["simpleW"] = simpleWallShadingsMatrix; } } string fileName = (fileName_ != null) ? fileName_ + ".INX" : "DragonflyEnvimet.INX"; string fullName = System.IO.Path.Combine(_envimetFolder, fileName); df_envimet_lib.IO.Inx.INXwriteMethod(fullName, preparation); DA.SetData(4, fullName); CleanObject(_envimentObjects_); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // INPUT // declaration string _INXfileAddress = null; PostProcessing editEnvimetBuilding = new PostProcessing(); df_envimet_lib.Geometry.Grid _envimentGrid = null; Curve crv = null; List <Mesh> meshes = new List <Mesh>(); string matx = Material.CommonWallMaterial; string maty = Material.CommonWallMaterial; string matz = Material.CommonRoofMaterial; bool runIt = false; DA.GetData(0, ref _INXfileAddress); DA.GetData(1, ref _envimentGrid); DA.GetData(2, ref crv); DA.GetDataList(3, meshes); DA.GetData(4, ref matx); DA.GetData(5, ref maty); DA.GetData(6, ref matz); DA.GetData(7, ref runIt); // action string word = "ID_wallDB"; List <string> rowData = new List <string>(); if (_INXfileAddress != null) { try { if (runIt) { // create a list of points List <Point3d> points = editEnvimetBuilding.ExtractPointFromINX(_INXfileAddress, _envimentGrid, word, ref rowData); Mesh testShapes = editEnvimetBuilding.UnionMeshUtility(meshes); // every row is a series of numbers and text separated by comma string[] newValueText = new string[points.Count]; for (int i = 0; i < points.Count; i++) { if (PostProcessing.PointContainmentCheck(points[i], crv)) { CellMaterial newMaterial; newMaterial.MaterialX = matx; newMaterial.MaterialY = maty; newMaterial.MaterialZ = matz; if (meshes.Count > 0) { if (editEnvimetBuilding.PointsInShapesCheck(testShapes, points[i])) { newValueText[i] = editEnvimetBuilding.UpdateRowTextMaterial(rowData[i], newMaterial); } else { newValueText[i] = rowData[i]; } } else { newValueText[i] = editEnvimetBuilding.UpdateRowTextMaterial(rowData[i], newMaterial); } } else { newValueText[i] = rowData[i]; } } // Handle invalid tags within INX string myFile = File.ReadAllText(_INXfileAddress); myFile = myFile.Replace("3Dplants", "threeDplants"); // Parse XML XDocument doc = XDocument.Parse(myFile); string newValue = "\n" + String.Join("\n", newValueText) + "\n"; XElement wall = doc.Root.Element("WallDB").Element("ID_wallDB"); XElement singleWall = doc.Root.Element("SingleWallDB").Element("ID_singlewallDB"); XElement greenWall = doc.Root.Element("GreeningDB").Element("ID_GreeningDB"); XElement terrain = doc.Root.Element("dem3D").Element("terrainflag"); WorkaroundNewString(wall); WorkaroundNewString(singleWall); WorkaroundNewString(greenWall); WorkaroundNewString(terrain); wall.SetValue(newValue); string finalText = editEnvimetBuilding.RestoreInvalidTag(doc.ToString()); // write file in a new destination File.WriteAllText(_INXfileAddress, finalText); DA.SetData(0, _INXfileAddress); } } catch { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Something went wrong... only output from DF Envimet Spaces are supported now."); } } }