Skip to content

Commit 22ba907

Browse files
calumlockhart-bhpeterjamesnugent
authored andcommitted
Metadata, V2
1 parent acdbb29 commit 22ba907

File tree

20 files changed

+881
-59
lines changed

20 files changed

+881
-59
lines changed

MidasCivil_Adapter/AdapterActions/Execute.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,20 @@ public bool RunCommand(Open command)
200200
catch (DirectoryNotFoundException)
201201
{
202202
Engine.Reflection.Compute.RecordWarning(
203-
"No UNITS.txt file found, MidasCivil model units assumed to be Newtons, metres, kilojoules and celcius. Therefore, no unit conversion will occur when pushing and pulling to/from MidasCivil.");
203+
"No UNIT.txt file found, MidasCivil model units assumed to be Newtons, metres, kilojoules and celcius. Therefore, no unit conversion will occur when pushing and pulling to/from MidasCivil.");
204204
}
205205
catch (ArgumentOutOfRangeException)
206206
{
207207
Engine.Reflection.Compute.RecordWarning(
208-
"No UNITS.txt file found, MidasCivil model units assumed to be Newtons, metres, kilojoules and celcius. Therefore, no unit conversion will occur when pushing and pulling to/from MidasCivil.");
208+
"No UNIT.txt file found, MidasCivil model units assumed to be Newtons, metres, kilojoules and celcius. Therefore, no unit conversion will occur when pushing and pulling to/from MidasCivil.");
209209
}
210210

211211
Directory.CreateDirectory(m_directory + "\\Results");
212212

213213
}
214214

215-
return true;
215+
216+
return true;
216217
}
217218

218219
/***************************************************/

MidasCivil_Adapter/CRUD/Create/Create.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
using BH.oM.Structure.Loads;
3030
using BH.oM.Structure.SectionProperties;
3131
using BH.oM.Structure.SurfaceProperties;
32+
using BH.oM.Adapters.MidasCivil;
3233

3334
namespace BH.Adapter.MidasCivil
3435
{
@@ -42,8 +43,13 @@ protected override bool ICreate<T>(IEnumerable<T> objects, ActionConfig actionCo
4243
{
4344
bool success = true; //boolean returning if the creation was successfull or not
4445

46+
4547
if (objects.Count() > 0)
4648
{
49+
if (objects.First() is Metadata)
50+
{
51+
success = CreateCollection(objects.First() as Metadata);
52+
}
4753
if (objects.First() is Node)
4854
{
4955
success = CreateCollection(objects as IEnumerable<Node>);
@@ -138,4 +144,3 @@ protected override bool ICreate<T>(IEnumerable<T> objects, ActionConfig actionCo
138144

139145
}
140146
}
141-
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2021, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using System.IO;
24+
using BH.oM.Adapters.MidasCivil;
25+
using System.Text;
26+
27+
namespace BH.Adapter.MidasCivil
28+
{
29+
public partial class MidasCivilAdapter
30+
{
31+
/***************************************************/
32+
/**** Private Methods ****/
33+
/***************************************************/
34+
35+
private bool CreateCollection(Metadata metadata)
36+
{
37+
string path = CreateSectionFile("PROJINFO");
38+
StringBuilder midasMetadata = new StringBuilder();
39+
40+
midasMetadata = Adapters.MidasCivil.Convert.FromMetadata(metadata);
41+
42+
File.WriteAllText(path, midasMetadata.ToString(), System.Text.Encoding.GetEncoding(1252));
43+
44+
return true;
45+
}
46+
47+
/***************************************************/
48+
49+
}
50+
}
51+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2021, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using System.Collections.Generic;
24+
using BH.oM.Adapters.MidasCivil;
25+
26+
namespace BH.Adapter.MidasCivil
27+
{
28+
public partial class MidasCivilAdapter
29+
{
30+
/***************************************************/
31+
/**** Private Methods ****/
32+
/***************************************************/
33+
34+
private IEnumerable<Metadata> ReadMetadata(List<string> ids = null)
35+
{
36+
return Convert.ToMetadata(GetSectionText("PROJINFO"));
37+
}
38+
/***************************************************/
39+
40+
}
41+
}
42+

MidasCivil_Adapter/CRUD/Read/Read.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
using BH.oM.Structure.MaterialFragments;
3434
using BH.oM.Structure.Loads;
3535
using BH.oM.Structure.Results;
36+
using BH.oM.Adapters.MidasCivil;
3637

3738
namespace BH.Adapter.MidasCivil
3839
{
@@ -45,7 +46,9 @@ public partial class MidasCivilAdapter
4546
protected override IEnumerable<IBHoMObject> IRead(Type type, IList ids = null, ActionConfig actionConfig = null)
4647
{
4748
//Choose what to pull out depending on the type. Also see example methods below for pulling out bars and dependencies
48-
if (type == typeof(Node))
49+
if (type == typeof(Metadata))
50+
return ReadMetadata(ids as dynamic);
51+
else if (type == typeof(Node))
4952
return ReadNodes(ids as dynamic);
5053
else if (type == typeof(Bar))
5154
return ReadBars(ids as dynamic);
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2021, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using System.Collections.Generic;
24+
using BH.oM.Adapters.MidasCivil;
25+
using MCEngine = BH.Engine.Adapters.MidasCivil;
26+
27+
namespace BH.Adapter.MidasCivil
28+
{
29+
public static partial class Convert
30+
{
31+
/***************************************************/
32+
/**** Public Methods ****/
33+
/***************************************************/
34+
35+
public static IEnumerable<Metadata> ToMetadata(List<string> data)
36+
{
37+
Metadata metadata = new Metadata();
38+
List<Review> reviews = new List<Review>();
39+
List<string> comments = new List<string>();
40+
Review review1 = new Review();
41+
Review review2 = new Review();
42+
Review review3 = new Review();
43+
Review review4 = new Review();
44+
45+
foreach (string dataItem in data)
46+
{
47+
48+
if (dataItem.Contains("PROJECT=")) { metadata.ProjectNumber = dataItem.Split('=')[1]; }
49+
else if (dataItem.Contains("REVISION=")) { metadata.Revision = dataItem.Split('=')[1]; }
50+
else if (dataItem.Contains("USER=")) { metadata.Author = dataItem.Split('=')[1]; }
51+
else if (dataItem.Contains("EMAIL=")) { metadata.Email = dataItem.Split('=')[1]; }
52+
else if (dataItem.Contains("ADDRESS=")) { metadata.Location = dataItem.Split('=')[1]; }
53+
else if (dataItem.Contains("CLIENT=")) { metadata.Client = dataItem.Split('=')[1]; }
54+
else if (dataItem.Contains("TITLE=")) { metadata.ProjectName = dataItem.Split('=')[1]; }
55+
else if (dataItem.Contains("EDATE="))
56+
{
57+
metadata.CreationDate = MCEngine.Convert.Date(dataItem.Split('=')[1]);
58+
}
59+
else if (dataItem.Contains(";DESIGNSTAGE=")) { metadata.DesignStage = dataItem.Split('=')[1]; }
60+
else if (dataItem.Contains(";PROJECTLEAD=")) { metadata.ProjectLead = dataItem.Split('=')[1]; }
61+
else if (dataItem.Contains(";DESCRIPTION=")) { metadata.Description = dataItem.Split('=')[1]; }
62+
else if (dataItem.Contains(";DISCIPLINE=")) { metadata.Discipline = dataItem.Split('=')[1]; }
63+
64+
if (dataItem.Contains("CHECK1="))
65+
{
66+
review1.Reviewer = (dataItem.Split('=')[1]);
67+
reviews.Add(review1);
68+
}
69+
else if (dataItem.Contains("CHECK2="))
70+
{
71+
review2.Reviewer = (dataItem.Split('=')[1]);
72+
reviews.Add(review2);
73+
}
74+
else if (dataItem.Contains("CHECK3="))
75+
{
76+
review3.Reviewer = (dataItem.Split('=')[1]);
77+
reviews.Add(review3);
78+
}
79+
else if (dataItem.Contains("APPROVE="))
80+
{
81+
review4.Reviewer = (dataItem.Split('=')[1]);
82+
reviews.Add(review4);
83+
review4.Approved = true;
84+
}
85+
if (dataItem.Contains("CDATE1=")) { review1.ReviewDate = MCEngine.Convert.Date(dataItem.Split('=')[1]); }
86+
else if (dataItem.Contains("CDATE2=")) { review2.ReviewDate = MCEngine.Convert.Date(dataItem.Split('=')[1]); }
87+
else if (dataItem.Contains("CDATE3=")) { review3.ReviewDate = MCEngine.Convert.Date(dataItem.Split('=')[1]); }
88+
else if (dataItem.Contains("ADATE=")) { review4.ReviewDate = MCEngine.Convert.Date(dataItem.Split('=')[1]); }
89+
else if (dataItem.Contains("COMMENT="))
90+
{
91+
if (!dataItem.Contains("COMMENT=This Model Was Created Using BHoM Version:"))
92+
{
93+
comments.Add(dataItem.Split('=')[1]);
94+
if (!string.IsNullOrEmpty(review4.Reviewer))
95+
{
96+
review4.Comments = comments;
97+
}
98+
else if (!string.IsNullOrEmpty(review3.Reviewer))
99+
{
100+
review3.Comments = comments;
101+
}
102+
else if (!string.IsNullOrEmpty(review2.Reviewer))
103+
{
104+
review2.Comments = comments;
105+
}
106+
else if (!string.IsNullOrEmpty(review1.Reviewer))
107+
{
108+
review1.Comments = comments;
109+
}
110+
}
111+
}
112+
}
113+
reviews.Reverse();
114+
metadata.Reviews = reviews;
115+
116+
List<Metadata> returnMetadata = new List<Metadata>(1);
117+
returnMetadata.Add(metadata);
118+
119+
return returnMetadata;
120+
}
121+
122+
/***************************************************/
123+
}
124+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2021, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using System.Text;
24+
using BH.oM.Adapters.MidasCivil;
25+
using System.Collections.Generic;
26+
using BH.Engine.Base;
27+
28+
namespace BH.Adapter.Adapters.MidasCivil
29+
{
30+
public static partial class Convert
31+
{
32+
/***************************************************/
33+
/**** Public Methods ****/
34+
/***************************************************/
35+
36+
public static StringBuilder FromMetadata(Metadata metadata)
37+
{
38+
StringBuilder midasMetadata = new StringBuilder();
39+
List<Review> reviews = new List<Review>(metadata.Reviews);
40+
41+
midasMetadata.AppendLine("*PROJINFO");
42+
midasMetadata.AppendLine($"PROJECT={metadata.ProjectNumber}");
43+
midasMetadata.AppendLine($";DESIGNSTAGE={metadata.DesignStage}");
44+
midasMetadata.AppendLine($";PROJECTLEAD={metadata.ProjectLead}");
45+
midasMetadata.AppendLine($"REVISION={metadata.Revision}");
46+
midasMetadata.AppendLine($"USER={metadata.Author}");
47+
midasMetadata.AppendLine($"EMAIL={metadata.Email}");
48+
midasMetadata.AppendLine($"ADDRESS={metadata.Location.Replace(System.Environment.NewLine, ", ")}");
49+
midasMetadata.AppendLine($"CLIENT={metadata.Client}");
50+
midasMetadata.AppendLine($"TITLE={metadata.ProjectName}");
51+
midasMetadata.AppendLine($"ENGINEER={metadata.Author}");
52+
midasMetadata.AppendLine($"EDATE={metadata.CreationDate.ToString("yyyy-MM-dd")}");
53+
midasMetadata.AppendLine($";DESCRIPTION={metadata.Description.Replace('*', '†').Replace("=", " equals ").Replace($"{System.Environment.NewLine}"," ")}");
54+
midasMetadata.AppendLine($";DISCIPLINE={metadata.Discipline}");
55+
56+
if(reviews.Count > 4)
57+
{
58+
reviews.RemoveRange(1, reviews.Count - 3);
59+
Engine.Reflection.Compute.RecordWarning("The number of reviews exceeds the limit of MidasCivil. Only the first, last and second to last reviews will be recorded.");
60+
}
61+
if(reviews.Count >= 1)
62+
{
63+
midasMetadata.AppendLine($"CHECK1={reviews[0].Reviewer}");
64+
midasMetadata.AppendLine($"CDATE1={reviews[0].ReviewDate.ToString("yyyy-MM-dd")}");
65+
}
66+
if (reviews.Count >= 2)
67+
{
68+
midasMetadata.AppendLine($"CHECK2={reviews[1].Reviewer}");
69+
midasMetadata.AppendLine($"CDATE2={reviews[1].ReviewDate.ToString("yyyy-MM-dd")}");
70+
Engine.Reflection.Compute.RecordWarning("Only comments from the last review will be pushed to MidasCivil.");
71+
}
72+
if (reviews.Count >= 3)
73+
{
74+
midasMetadata.AppendLine($"CHECK3={reviews[2].Reviewer}");
75+
midasMetadata.AppendLine($"CDATE3={reviews[2].ReviewDate.ToString("yyyy-MM-dd")}");
76+
}
77+
if(reviews[reviews.Count - 1].Approved)
78+
{
79+
midasMetadata.AppendLine($"APPROVE={reviews[reviews.Count - 1].Reviewer}");
80+
midasMetadata.AppendLine($"ADATE={reviews[reviews.Count - 1].ReviewDate.ToString("yyyy-MM-dd")}");
81+
}
82+
83+
foreach(string comment in reviews[reviews.Count - 1].Comments)
84+
{
85+
midasMetadata.AppendLine($"COMMENT={comment.Replace('*', '†').Replace("=", " equals ").Replace($"{System.Environment.NewLine}", $"{System.Environment.NewLine}COMMENT=")}");
86+
}
87+
88+
return midasMetadata;
89+
}
90+
91+
/***************************************************/
92+
93+
}
94+
}

0 commit comments

Comments
 (0)