Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Author: Carl Balajadia 08/19/19
- --Updated by Jayson Barateta : 04/12/19 Sprint 7.3 - Minor update
- --Updated by Jayson Barateta : 09/12/19 Sprint 7.4 - Minor update
- local json = require("json");
- function main()
- CheckEngine.SetCheckType("Building")
- CheckEngine.BindCheckFunc("checkRule")
- CheckEngine.RunCheckPipeline()
- end
- function checkRule(Building)
- local ok, path = pcall(FXPUB.GetFilePath())
- local parsedXml = FXPUB.ParseXml(path(), "SSW_1_2_3_C_DRAINLINES_FOR_MULTIPLE_LOTS")
- local systemTypes = FXRule.ParseValues(parsedXml, "SystemType")
- local tblValues = FXRule.FilterTableValuesNew(parsedXml)
- local conditionValues1 = FXRule.ParseValues(parsedXml,'Condition1')
- local conditionValues2 = FXRule.ParseValues(parsedXml,'Condition2')
- local conditionValues3 = FXRule.ParseValues(parsedXml,'Condition3')
- local conditionValues4 = FXRule.ParseValues(parsedXml,'Condition4')
- local Bridgeinitialized = FXBIMRL.InitializeBridge(Building)
- local FedID = FXBIMRL.GetFedID(Building)
- local drainLineStr = conditionValues1[2]
- local publicSewerStr = conditionValues1[4]:lower()
- local strYJunction = conditionValues2[2]
- local sitePset = conditionValues3[1];
- local json = require("json")
- local hasError = false
- local isObjsComplete = true
- local hasYjunctionResult = false
- local strIfcTypeIC
- local strPredefinedIC
- local strIfcTypeDrainLine
- local strPredefinedDrainLine
- local strIfcTypeJunction
- local strPredefinedJunction
- local strIfcTypeManhole
- local strPredefinedManhole
- local nonCompliantIC = {}
- local nonCompliantSite = {}
- local nonCompliantNIC = {}
- local nonCompliantDrainLine = {}
- for k,v in pairs(tblValues) do
- --table data for drain-line
- if k == "Pipe" then
- for k1,v1 in pairs (v) do
- for k2,v2 in pairs (v1) do
- if type(v2) == "table" then
- strPredefinedDrainLine = v2["operator"]
- else
- if k2 == "type" then
- strIfcTypeDrainLine = v2;
- end
- end
- end
- end
- end
- --table data for inspection chamber
- if k == "IC" then
- for k1,v1 in pairs (v) do
- for k2,v2 in pairs (v1) do
- if type(v2) == "table" then
- strPredefinedIC = v2["operator"]
- else
- if k2 == "type" then
- strIfcTypeIC = v2;
- end
- end
- end
- end
- end
- --table data for manhole
- if k == "Manhole" then
- for k1,v1 in pairs (v) do
- for k2,v2 in pairs (v1) do
- if type(v2) == "table" then
- strPredefinedManhole = v2["operator"]
- else
- if k2 == "type" then
- strIfcTypeManhole = v2;
- end
- end
- end
- end
- end
- --table data for junctions
- if k == "Junction" then
- for k1,v1 in pairs (v) do
- for k2,v2 in pairs (v1) do
- if type(v2) == "table" then
- strPredefinedJunction = v2["operator"]
- else
- if k2 == "type" then
- strIfcTypeJunction = v2;
- end
- end
- end
- end
- end
- end
- local inspectionChamberStr = FX_OUTPUTSTRING.GetResourceString(strPredefinedIC)
- local manholeStr = FX_OUTPUTSTRING.GetResourceString(strPredefinedManhole)
- local yJunctionStr = strYJunction;
- local CheckedPipe = {};
- if FX_OUTPUTSTRING.CheckInResourceList( inspectionChamberStr ) == false or FX_OUTPUTSTRING.CheckInResourceList( manholeStr ) == false then
- FXLOGGER.LogSystemError(debug.getinfo(1,'S').source.." (".. debug.getinfo(1).currentline.."): Invalid set value found.")
- hasError = true;
- end
- if not Bridgeinitialized then
- FXLOGGER.LogSystemError(debug.getinfo(1,'S').source.." (".. debug.getinfo(1).currentline.."): Initialize bridge failed.")
- hasError = true;
- end
- if not FedID then
- FXLOGGER.LogSystemError(debug.getinfo(1,'S').source.." (".. debug.getinfo(1).currentline.."): No federated ID found.")
- hasError = true;
- end
- if not hasError then
- FXBIMRL.initSystemGraphVariables(FedID);
- FXBIMRL.initFullSystemGraphs();
- FXBIMRL.excludeElementID("Dummy Port Element");
- FXBIMRL.setSystemFlowDirection(0);
- FXBIMRL.generateGraph();
- local querySite = "SELECT DISTINCT obj.elementid, prop.propertyvalue AS reference \n"..
- "FROM \n"..
- "bimrl_element obj \n"..
- "LEFT JOIN bimrl_elementproperties prop \n"..
- "ON obj.elementid = prop.elementid \n"..
- "WHERE \n"..
- "obj.elementtype = 'IFCSITE' \n"..
- "AND prop.propertygroupname SIMILAR TO 'PUBPset_IfcSite|PUBPset_Site' \n"..
- "AND lower(prop.propertyname) LIKE lower('"..sitePset.."')";
- print(querySite)
- local jsonSite = FXBIMRL.GetQueryByFederatedId(querySite)
- print("querySite")
- print(jsonSite)
- if jsonSite == nil then
- FXUtility.DisplaySolid_Attention(Building, "Site is not provided.")
- isObjsComplete = false
- return
- end
- local PDevSet = Building:GetAuxAttri(conditionValues4[1]);
- local PDevList = FXPUB.Split(conditionValues4[2],",");
- local PDevFlag = false;
- if PDevSet ~= nil then
- for _,vPDL in pairs(PDevList) do
- if FXUtility.HasPatterInString( PDevSet, vPDL) then
- PDevFlag = true;
- end
- end
- else
- FXUtility.DisplaySolid_Attention(Building,"Project development type is not provided.");
- return;
- end
- if not PDevFlag then
- FXUtility.DisplaySolid_Attention(Building,"Project development type does not match.");
- return;
- end
- local queryManhole = "SELECT DISTINCT obj.elementid \n"..
- "FROM \n"..
- "bimrl_element obj, \n"..
- "bimrl_type type \n"..
- "WHERE \n"..
- "obj.elementtype = 'IFCDISTRIBUTIONCHAMBERELEMENT' \n"..
- "AND obj.typeid = type.elementid \n"..
- "AND type.ifctype = '"..strIfcTypeManhole:upper().."' \n"..
- "AND type.predefinedtype = '"..strPredefinedManhole:upper().."'";
- print(queryManhole)
- print("queryManhole")
- local grpManhole, tblManhole_ID = ReturnQuery( queryManhole )
- if grpManhole == nil then
- FXUtility.DisplaySolid_Attention(Building, manholeStr.." is not provided")
- isObjsComplete = false
- return
- end
- print(isObjsComplete)
- if isObjsComplete then
- local tblSite = json:decode(jsonSite)["Table1"]
- if #tblSite > 0 then
- for i=1, #tblSite do
- local siteID = tblSite[i]["elementid"]
- local siteReference = tblSite[i]["reference"]
- if siteReference ~= nil and siteReference ~= "nil" then
- local hasICConnectedToManhole = false
- local targetExcluded
- local grpIC, tblIC_ID = GetSiteIC(siteID, strIfcTypeIC, strPredefinedIC)
- if grpIC == nil or #grpIC == 0 then
- FXUtility.DisplaySolid_Attention(Building, inspectionChamberStr.." is not provided")
- else
- for i=1, #tblIC_ID do
- local IC_ID = tblIC_ID[i]["elementid"]
- local targetTblManhole = {strIfcTypeManhole:upper(), strPredefinedManhole:upper()}
- local targetTblIC = {strIfcTypeIC:upper(), strPredefinedIC:upper()}
- local targetTbl1 = {targetTblManhole}
- local targetTbl2 = {targetTblIC}
- local target = json:encode(targetTbl1)
- targetExcluded = json:encode(targetTbl2)
- local initResult = FXBIMRL.findPathToSpecificTypeObjectWithNegativeCondition(IC_ID, target, targetExcluded, 0)
- local lastICObjs = {}
- print(initResult)
- if initResult ~= nil and initResult ~= '[["No path found"]]' then
- local tbl = FXRule.DecodeJSONToTable(initResult)
- local IC_Obj = FXMeasure.GetElementbyGUID(IC_ID)
- local hasYJunction = false;
- local hasJunction = false;
- local hasManhole = false;
- local connManhole
- local connJunction
- for k, v in pairs(tbl) do
- for k1, v1 in pairs (v) do
- table.insert(lastICObjs, v1);
- local obj = FXMeasure.GetElementbyGUID(v1)
- local preDef = FXRule.NewGetPredefinedType(obj, "IFCPIPEFITTINGTYPE")
- if connJunction == nil and FXUtility.HasPatterInString(obj.Type, "FlowFitting") and (preDef ~= nil and FXUtility.HasPatterInString(preDef, "JUNCTION")) then
- connJunction = obj
- else
- connManhole = obj
- end
- end
- end
- if #lastICObjs > 0 then
- hasICConnectedToManhole = true
- local yJunctionVal
- if connJunction ~= nil then
- hasJunction = true
- yJunctionVal, hasBackdrop = checkFittingAngle(connJunction, IC_Obj, connManhole)
- if yJunctionVal == 1 then
- hasYJunction = true
- end
- end
- if connManhole ~= nil then
- local drainLine, tempjunction;
- local Grp, Tbl = FXPUB.FindPath(IC_ID,connManhole:GetAttri("GlobalId"));
- Grp:ForEach(function(element )
- if element.Type == 'FlowSegment' and tempjunction == nil then
- drainLine = element;
- end
- if element.Type == 'FlowFitting' and tempjunction == nil then
- local preDef = FXRule.NewGetPredefinedType(element, "IFCPIPEFITTINGTYPE")
- if preDef == 'JUNCTION' then
- tempjunction = element;
- end
- end
- end)
- if hasJunction then
- if hasYJunction then
- FXUtility.DisplaySolid_Compliant(IC_Obj, "Individual "..drainLineStr:lower().." connection from last IC to "..publicSewerStr:lower().." via "..yJunctionStr.." to "..manholeStr:lower()..".")
- CheckReport.AddRelatedObj(connManhole, connManhole:GetAttri("Name"))
- CheckReport.AddRelatedObj(connJunction, connJunction:GetAttri("Name"))
- else
- FXUtility.DisplaySolid_Error(IC_Obj, tblSite[i]["reference"].." unit "..drainLineStr:lower().." connection from last IC to "..publicSewerStr:lower().." via "..yJunctionStr.." is not provided.")
- CheckReport.AddRelatedObj(connManhole, connManhole:GetAttri("Name"))
- CheckReport.AddRelatedObj(connJunction, connJunction:GetAttri("Name"))
- end
- else
- FXUtility.DisplaySolid_Compliant(IC_Obj, drainLineStr.." connection from last IC to "..publicSewerStr:lower().." is provided.")
- CheckReport.AddRelatedObj(connManhole, connManhole:GetAttri("Name"))
- end
- if drainLine ~= nil then
- CheckReport.AddRelatedObj(drainLine, drainLine:GetAttri("Name"))
- end
- end
- end
- end
- end
- end
- if not hasICConnectedToManhole then
- local lastICNotConnected = {}
- local drainLineTbl = {}
- local neigborICTbl = {}
- local grpIC, neighborIC_ID = GetSiteIC(tblSite, strIfcTypeIC, strPredefinedIC, siteID)
- print("neighborIC_ID")
- print(neighborIC_ID)
- if neighborIC_ID ~= nil then
- neighborIC_ID = checkSameICTbl(tblIC_ID, neighborIC_ID)
- for i=1, #tblIC_ID do
- local tblIC = tblIC_ID
- local newTbl = {}
- for j=1, #tblIC do
- if not FXUtility.HasPatterInString(tblIC[j]["elementid"], tblIC_ID[i]["elementid"]) then
- table.insert(newTbl, tblIC[j]["elementid"])
- end
- end
- FXBIMRL.resetGraph()
- FXBIMRL.initSystemGraphVariables(FedID)
- FXBIMRL.initFullSystemGraphs()
- table.insert(newTbl,"Dummy Port Element")
- local targetExTbl = {newTbl}
- local targetEx = json:encode(targetExTbl)
- FXBIMRL.excludeElementID(targetEx)
- FXBIMRL.setSystemFlowDirection(2)
- FXBIMRL.generateGraph()
- local isConnectedToOtherIC = false;
- local neighborICObjs = {}
- local prevObjs = {}
- for j=1, #neighborIC_ID do
- local objsBetween = FXBIMRL.findPathWithNegativeCondition(tblIC_ID[i]["elementid"], neighborIC_ID[j], targetEx, 0)
- if objsBetween ~= nil then
- local tbl = FXRule.DecodeJSONToTable(objsBetween)
- if #prevObjs == 0 or #prevObjs > #tbl then
- for k, v in pairs(tbl) do
- for k1, v1 in pairs (v) do
- if not FXUtility.HasPatterInString(v1,"No path found") then
- prevObjs = tbl
- end
- end
- end
- end
- end
- end
- if prevObjs ~= nil and #prevObjs > 0 then
- print("prevObjs")
- print(#prevObjs)
- for k, v in pairs(prevObjs) do
- for k1, v1 in pairs (v) do
- isConnectedToOtherIC = true
- if not FXUtility.HasPatterInString(v1, tblIC_ID[i]["elementid"]) then
- table.insert(neighborICObjs, v1)
- end
- end
- end
- end
- local x = 0
- print("isConnectedToOtherIC")
- print(isConnectedToOtherIC)
- if isConnectedToOtherIC then
- x = x+1
- table.insert(lastICNotConnected, tblIC_ID[i]["elementid"])
- neigborICTbl[x] = neighborICObjs
- local drainLine = getConnectedDrainLine (FedID, tblIC_ID[i]["elementid"], neighborICObjs, strIfcTypeDrainLine, strPredefinedDrainLine, systemTypes)
- table.insert(drainLineTbl, drainLine)
- end
- end
- end
- if #lastICNotConnected > 0 then
- for i=1, #lastICNotConnected do
- table.insert(nonCompliantIC, FXMeasure.GetElementbyGUID(lastICNotConnected[i]))
- table.insert(nonCompliantNIC, neigborICTbl[i])
- table.insert(nonCompliantSite, siteReference)
- table.insert(nonCompliantDrainLine, drainLineTbl[i])
- end
- else
- FXUtility.DisplaySolid_Attention(Building, "No last IC to check in "..siteReference..".")
- end
- end
- else
- FXUtility.DisplaySolid_Attention(Building, "Site reference is not provided.")
- end
- end
- if #nonCompliantIC > 0 then
- for i=1, #nonCompliantIC do
- if hasYjunctionResult then
- FXUtility.DisplaySolid_Error(nonCompliantIC[i], nonCompliantSite[i].." "..drainLineStr:lower().." connection from last IC to "..publicSewerStr:lower().." via "..yJunctionStr.." is not provided.")
- for j=1, #nonCompliantNIC[i] do
- local obj = FXMeasure.GetElementbyGUID(nonCompliantNIC[i][j])
- CheckReport.AddRelatedObj(obj, obj:GetAttri("Name"))
- end
- else
- FXUtility.DisplaySolid_Error(nonCompliantIC[i], drainLineStr.." connection from last IC to "..publicSewerStr:lower().." is not provided in "..nonCompliantSite[i])
- for j=1, #nonCompliantNIC[i] do
- if j < 3 then
- local obj = FXMeasure.GetElementbyGUID(nonCompliantNIC[i][j])
- CheckReport.AddRelatedObj(obj, obj:GetAttri("Name"))
- end
- end
- end
- end
- end
- end
- end
- else
- FXUtility.DisplaySolid_Attention(Building, "Unable to complete rule checking due to system error.")
- end
- end
- function getConnectedDrainLine (FedID, IC_ID, lastICObjs, strIfcTypeDrainLine, strPredefinedDrainLine, systemTypes)
- local drainLine
- local queryIC = "SELECT DISTINCT obj.elementid \n"..
- "FROM \n"..
- "bimrl_element obj \n"..
- "WHERE \n"..
- "obj.elementid = '"..IC_ID.."'";
- local queryDrainLine = "SELECT DISTINCT obj.elementid \n"..
- "FROM \n"..
- "bimrl_element obj, \n"..
- "bimrl_element sys, \n"..
- "bimrl_type type, \n"..
- "bimrl_relgroup grp \n"..
- "WHERE \n"..
- "obj.typeid = type.elementid \n"..
- "AND type.ifctype = '"..strIfcTypeDrainLine.."' \n"..
- "AND type.predefinedtype SIMILAR TO lower('"..strPredefinedDrainLine.."|NOTDEFINED') \n"..
- "AND lower(sys.name) SIMILAR TO lower('%("..FXUtility.ConcatStringTable(systemTypes)..")%') \n"..
- "AND sys.elementid = grp.groupelementid \n"..
- "AND obj.elementid = grp.memberelementid";
- local collidedObjTbl = FXUtility.CheckCollidedFromObjSet(FedID, queryIC, queryDrainLine, true);
- if collidedObjTbl ~= nil and #collidedObjTbl ~= 0 then
- for i=1, #collidedObjTbl do
- if not FXUtility.HasPatterInTable(collidedObjTbl[i][2], lastICObjs) then
- drainLine = FXMeasure.GetElementbyGUID(collidedObjTbl[i][2]);
- end
- end
- end
- return drainLine
- end
- function checkSameICTbl ( tblIC_ID, neighborIC_ID )
- local newICTbl = {}
- for j=1, #neighborIC_ID do
- local isEqual = false
- for i=1, #tblIC_ID do
- if FXUtility.HasPatterInString(neighborIC_ID[j]["elementid"], tblIC_ID[i]["elementid"] ) then
- isEqual = true
- end
- end
- if not isEqual then
- table.insert(newICTbl, neighborIC_ID[j]["elementid"])
- end
- end
- return newICTbl
- end
- function checkSiteIDTbl( siteID, currentSiteID )
- local newSiteTbl = {}
- for i=1, #siteID do
- if not FXUtility.HasPatterInString(siteID[i]["elementid"], currentSiteID) then
- table.insert(newSiteTbl, siteID[i]["elementid"] )
- end
- end
- return newSiteTbl
- end
- function GetSiteIC(siteID, strIfcTypeIC, strPredefinedIC, currentSiteID)
- if type(siteID) == "table" and currentSiteID ~= nil then
- local newSiteTbl = checkSiteIDTbl( siteID, currentSiteID )
- if newSiteTbl ~= nil and #newSiteTbl > 0 then
- siteID = FXUtility.ConcatStringTable(newSiteTbl)
- else
- siteID = siteID[1].elementid;
- end
- end
- local querySiteIC = "SELECT DISTINCT e2.elementid, e2.elementtype \n"..
- "FROM bimrl_element e,bimrl_spatialindex i, \n"..
- "bimrl_element e2 \n"..
- "WHERE e.elementid SIMILAR TO '"..siteID.."' \n"..
- "AND e.elementid = i.elementid \n"..
- "AND EXISTS \n"..
- "(SELECT FROM bimrl_element e1 \n"..
- "LEFT JOIN bimrl_spatialindex i1 on e1.elementid = i1.elementid \n"..
- "LEFT JOIN bimrl_type t on t.elementid = e1.typeid \n"..
- "WHERE \n"..
- "t.ifctype = '"..strIfcTypeIC:upper().."' AND \n"..
- "t.predefinedtype = '"..strPredefinedIC:upper().."' \n"..
- "AND (i.yminbound = i1.yminbound or i.ymaxbound = i1.ymaxbound) \n"..
- "AND (i.xminbound = i1.xminbound or i.xmaxbound = i1.xmaxbound) \n"..
- "AND e1.elementid = e2.elementid) ";
- print(querySiteIC)
- print("querySiteIC")
- local grpIC, tblIC_ID = ReturnQuery( querySiteIC )
- return grpIC, tblIC_ID
- end
- function checkFittingAngle(junction, IC_Obj, connManhole)
- --[[
- 1 = Y junction
- 2 = Other junction
- ]]--
- local val
- local pipeA
- local pipeB
- local faceA
- local faceB
- local pipeGrpConnManhole = FXGroup.new()
- local isConnectedToManhole = false
- local isConnectedToIC = false
- local connToICAndManhole = false
- if junction ~= nil then
- if (FXPUBSeriesSSW.getPipeFittingType(junction) == 1) then
- val = 1
- if #pipeGrpConnManhole > 0 then
- pipeGrpConnManhole:ForEach(function ( pipe )
- if FXClashDetection.IsCollided(pipe, connManhole) then
- isConnectedToManhole = true
- end
- if FXClashDetection.IsCollided(pipe, IC_Obj) then
- isConnectedToIC = true
- end
- end)
- end
- if isConnectedToManhole and isConnectedToIC then
- connToICAndManhole = true
- end
- else
- val = 2
- end
- end
- return val, connToICAndManhole
- end
- function getFace(face, junction)
- local tempFace
- local faceFace
- local temp
- local finalFace
- local juncMidPos = FXGeom.GetBoundingBox(junction):MidPos()
- for i = 1, #face do
- if face[i]:GetVoidFaceNumber() == 0 then
- local diam = FXMeasure.GetOuterDiameterLines(face[i])
- local centerPoint = FXUtility.CenterPoint(diam:GetStartPoint(), diam:GetEndPoint())
- local length = Line3D(centerPoint, juncMidPos):Length()
- if temp == nil then
- temp = length
- tempFace = face[i]
- else
- faceFace = face[i]
- if temp < length then
- finalFace = tempFace
- else
- finalFace = faceFace
- end
- end
- end
- end
- return finalFace
- end
- function ReturnQuery( query )
- local grpA, grpB;
- local retVal = FXBIMRL.GetQueryByFederatedId(query);
- print(retVal)
- if retVal ~= nil and FXUtility.HasPatterInString(retVal,"Table1") then
- grpA, grpB = FXPUB.GrpElementbyGUID(retVal);
- end
- return grpA, grpB;
- end
- function GetPathToSpecificObj( TargetIFCtype, TargetPtype, NotMeetIFCtype, NotMeetPtype, BaseId, Count )
- local CountS = 0
- if Count ~= nil then
- CountS = Count;
- end
- local BetweenObjsGrp = FXGroup.new();
- local BetweenObjsGrp2 = {};
- local table1 = {TargetIFCtype, TargetPtype}
- local table11 = {table1}
- local target = json:encode(table11)
- local table2 = {NotMeetIFCtype, NotMeetPtype}
- local table22 = {table2}
- local notmeet = json:encode(table22)
- local initResult = FXBIMRL.findPathToSpecificTypeObjectWithNegativeCondition(BaseId , target, notmeet, CountS)
- if initResult ~= nil then
- local tbl = FXRule.DecodeJSONToTable(initResult)
- for k6,v6 in pairs(tbl) do
- for k7 , v7 in pairs (v6) do
- if not FXUtility.HasPatterInString(v7,"No path found") then
- local Obj = FXMeasure.GetElementbyGUID(v7)
- BetweenObjsGrp:Add(Obj);
- table.insert(BetweenObjsGrp2,v7);
- end
- end
- end
- end
- return BetweenObjsGrp, BetweenObjsGrp2;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement