11/*
22 * This file is part of the Buildings and Habitats object Model (BHoM)
3- * Copyright (c) 2015 - 2023 , the respective contributors. All rights reserved.
3+ * Copyright (c) 2015 - 2024 , the respective contributors. All rights reserved.
44 *
55 * Each contributor holds copyright over their respective contributions.
66 * The project versioning (Git) records all such contribution source information.
2020 * along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
2121 */
2222
23+ using System ;
24+ using System . Reflection ;
25+ using System . IO ;
26+ using System . Diagnostics ;
2327using BH . Engine . Geometry ;
2428using BH . Engine . Adapters . Lusas . Object_Comparer . Equality_Comparer ;
2529using BH . oM . Adapter ;
26- using BH . oM . Adapters . Lusas ;
2730using BH . oM . Structure . Elements ;
2831using BH . oM . Geometry ;
2932using BH . oM . Structure . Constraints ;
3033using BH . oM . Structure . SectionProperties ;
3134using BH . oM . Structure . SurfaceProperties ;
3235using BH . oM . Structure . Loads ;
3336using BH . oM . Structure . MaterialFragments ;
34- using BH . Engine . Adapter ;
3537using Lusas . LPI ;
3638using System . Collections . Generic ;
3739using System . Linq ;
3840using BH . Engine . Base . Objects ;
39- using System ;
40- using System . Reflection ;
4141using BH . Engine . Base ;
42- using BH . Engine . Spatial ;
4342using BH . oM . Adapters . Lusas . Fragments ;
4443
4544namespace BH . Adapter . Lusas
@@ -52,6 +51,8 @@ public partial class LusasV19Adapter
5251 public partial class LusasV191Adapter
5352#elif Debug200 || Release200
5453 public partial class LusasV200Adapter
54+ #elif Debug210 || Release210
55+ public partial class LusasV210Adapter
5556#else
5657 public partial class LusasV17Adapter
5758#endif
@@ -81,6 +82,10 @@ protected override bool ICreate<T>(IEnumerable<T> objects, ActionConfig actionCo
8182 {
8283 success = CreateCollection ( objects as IEnumerable < Edge > ) ;
8384 }
85+ else if ( objects . First ( ) is Opening )
86+ {
87+ success = CreateCollection ( objects as IEnumerable < Opening > ) ;
88+ }
8489 else if ( objects . First ( ) is Point )
8590 {
8691 success = CreateCollection ( objects as IEnumerable < Point > ) ;
@@ -175,15 +180,13 @@ private bool CreateCollection(IEnumerable<Node> nodes)
175180 {
176181 CreateTags ( nodes ) ;
177182
178- ReduceRuntime ( true ) ;
179-
180183 foreach ( Node node in nodes )
181184 {
182185 IFPoint lusasPoint = CreatePoint ( node ) ;
183186 }
184187
185- ReduceRuntime ( false ) ;
186188 }
189+
187190 return true ;
188191 }
189192
@@ -199,15 +202,12 @@ private bool CreateCollection(IEnumerable<Point> points)
199202
200203 List < Point > lusasPoints = distinctPoints . Except ( existingPoints ) . ToList ( ) ;
201204
202- ReduceRuntime ( true ) ;
203-
204205 foreach ( Point point in lusasPoints )
205206 {
206207 IFPoint lusasPoint = CreatePoint ( point ) ;
207208 }
208-
209- ReduceRuntime ( false ) ;
210209 }
210+
211211 return true ;
212212 }
213213
@@ -225,8 +225,6 @@ private bool CreateCollection(IEnumerable<Bar> bars)
225225
226226 BHoMObjectNameComparer comparer = new BHoMObjectNameComparer ( ) ;
227227
228- ReduceRuntime ( true ) ;
229-
230228 foreach ( var barGroup in barGroups )
231229 {
232230 List < MeshSettings1D > distinctMeshes = barGroup . Select ( x => x . FindFragment < MeshSettings1D > ( ) )
@@ -244,23 +242,19 @@ private bool CreateCollection(IEnumerable<Bar> bars)
244242 IFLine lusasLine = CreateLine ( bar ) ;
245243 }
246244 }
247- ReduceRuntime ( false ) ;
245+
248246 d_LusasData . resetMesh ( ) ;
249247 d_LusasData . updateMesh ( ) ;
250248 }
251249 else
252250 {
253- ReduceRuntime ( true ) ;
254-
255251 foreach ( Bar bar in bars )
256252 {
257253 IFLine lusasLine = CreateLine ( bar ) ;
258254 }
259-
260- ReduceRuntime ( false ) ;
261-
262255 }
263256 }
257+
264258 return true ;
265259 }
266260
@@ -281,12 +275,10 @@ private bool CreateCollection(IEnumerable<Panel> panels)
281275 if ( CheckPropertyError ( panel , p => p . ExternalEdges ) )
282276 if ( CheckPropertyError ( panel . ExternalEdges , e => e . Select ( x => x . Curve ) ) )
283277 if ( panel . ExternalEdges . All ( x => x != null ) && panel . ExternalEdges . Select ( x => x . Curve ) . All ( y => y != null ) )
284- {
285- if ( panel . Openings . Count > 0 )
286- Engine . Base . Compute . RecordWarning ( "Lusas_Toolkit does not support Panels with Openings. The Panel will be pushed if valid, the Openings will not be pushed." ) ;
278+ {
287279 if ( panel . ExternalEdges . All ( x => ! Engine . Adapters . Lusas . Query . InvalidEdge ( x ) ) )
288280 {
289- if ( Engine . Spatial . Query . IsPlanar ( panel , false , Tolerance . MacroDistance ) )
281+ if ( Engine . Spatial . Query . IsPlanar ( panel , true , m_mergeTolerance ) )
290282 {
291283 for ( int i = 0 ; i < panel . ExternalEdges . Count ; i ++ )
292284 {
@@ -324,15 +316,13 @@ private bool CreateCollection(IEnumerable<Panel> panels)
324316 validPanel . AddFragment ( distinctMeshes . First ( x => comparer . Equals ( x , ( validPanel . FindFragment < MeshSettings2D > ( ) ) ) ) , true ) ;
325317 }
326318
327- ReduceRuntime ( true ) ;
328-
329319 IFSurface lusasSurface = null ;
330320
331321 foreach ( Panel validPanel in validPanels )
332322 lusasSurface = CreateSurface ( validPanel ) ;
333323
334- ReduceRuntime ( false ) ;
335324 }
325+
336326 return true ;
337327 }
338328
@@ -360,23 +350,17 @@ private bool CreateCollection(IEnumerable<Edge> edges)
360350 List < Point > existingPoints = ReadPoints ( ) ;
361351 List < Point > pointsToPush = distinctPoints . Except ( existingPoints , new PointDistanceComparer ( ) ) . ToList ( ) ;
362352
363- ReduceRuntime ( true ) ;
364-
365353 foreach ( Point point in pointsToPush )
366354 {
367355 IFPoint lusasPoint = CreatePoint ( point ) ;
368356 }
369357
370- ReduceRuntime ( false ) ;
371-
372358 List < Point > points = ReadPoints ( ) ;
373359
374360 List < IFPoint > lusasPoints = ReadLusasPoints ( ) ;
375361
376362 CreateTags ( distinctEdges ) ;
377363
378- ReduceRuntime ( true ) ;
379-
380364 foreach ( Edge edge in distinctEdges )
381365 {
382366 IFPoint startPoint = lusasPoints [ points . FindIndex (
@@ -385,8 +369,54 @@ private bool CreateCollection(IEnumerable<Edge> edges)
385369 m => m . Equals ( edge . Curve . IEndPoint ( ) . ClosestPoint ( points ) ) ) ] ;
386370 IFLine lusasLine = CreateEdge ( edge , startPoint , endPoint ) ;
387371 }
372+ }
373+
374+ return true ;
375+ }
376+
377+ /***************************************************/
378+
379+ private bool CreateCollection ( IEnumerable < Opening > openings )
380+ {
381+ if ( openings != null )
382+ {
383+ CreateTags ( openings ) ;
384+
385+ List < Opening > validOpenings = new List < Opening > ( ) ;
386+
387+ foreach ( Opening opening in openings )
388+ {
389+ if ( CheckPropertyError ( opening , p => p . Edges ) )
390+ if ( CheckPropertyError ( opening . Edges , e => e . Select ( x => x . Curve ) ) )
391+ {
392+ if ( opening . Edges . All ( x => ! Engine . Adapters . Lusas . Query . InvalidEdge ( x ) ) )
393+ {
394+ if ( Engine . Spatial . Query . IsPlanar ( opening , false , m_mergeTolerance ) ) //Check if this works.
395+ {
396+ for ( int i = 0 ; i < opening . Edges . Count ; i ++ )
397+ {
398+ if ( ! CheckPropertyError ( opening , p => opening . Edges [ i ] ) && Engine . Adapters . Lusas . Query . InvalidEdge ( opening . Edges [ i ] ) )
399+ break ;
400+
401+ if ( i == opening . Edges . Count - 1 )
402+ validOpenings . Add ( opening ) ;
403+ }
404+ }
405+ else
406+ Engine . Base . Compute . RecordError ( "The geometry defining one of the Openings of the Panel is not Planar, and therefore the Opening will not be created." ) ;
407+ }
408+ else
409+ Engine . Base . Compute . RecordError ( "One or more of the Internal Edges of the Panel are invalid, and therefore the Opening will not be created." ) ;
410+ }
411+ else
412+ Engine . Base . Compute . RecordError ( "One of more of the Internal Edges of the Panel or Curves defining the Opening are null." ) ;
413+ }
414+
415+
416+ IFSurface lusasSurface = null ;
388417
389- ReduceRuntime ( false ) ;
418+ foreach ( Opening validOpening in validOpenings )
419+ lusasSurface = CreateSurface ( validOpening ) ;
390420 }
391421 return true ;
392422 }
@@ -401,7 +431,6 @@ private bool CreateCollection(IEnumerable<ISectionProperty> sectionProperties)
401431 {
402432 IFAttribute lusasGeometricLine = CreateGeometricLine ( sectionProperty ) ;
403433 }
404-
405434 }
406435
407436 return true ;
@@ -734,9 +763,4 @@ private bool CreateCollection(IEnumerable<MeshSettings2D> meshSettings2Ds)
734763 /***************************************************/
735764
736765 }
737- }
738-
739-
740-
741-
742-
766+ }
0 commit comments