Stability process predicate evaluation module
This commit is contained in:
parent
78e31ea49c
commit
03bc34539c
19 changed files with 1365 additions and 123 deletions
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"cadFilePath":"/home/idontsudo/framework/geometric_feasibility_predicate/cubes.FCStd",
|
||||
"outPath":"/home/idontsudo/framework/geometric_feasibility_predicate/out/"
|
||||
"cadFilePath":"/home/idontsudo/framework/asp/out/disk_and_axis_n (2).FCStd",
|
||||
"outPath":"/home/idontsudo/framework/asp/out/"
|
||||
}
|
|
@ -189,7 +189,7 @@ class AdjacencyMatrix:
|
|||
@staticmethod
|
||||
def from_dict(obj: Any) -> 'AdjacencyMatrix':
|
||||
assert isinstance(obj, dict)
|
||||
all_pars = from_list(from_str, obj.get("allPars"))
|
||||
all_pars = from_list(from_str, obj.get("allParts"))
|
||||
first_detail = from_str(obj.get("firstDetail"))
|
||||
matrix = from_dict(lambda x: from_list(from_str, x), obj.get("matrix"))
|
||||
|
||||
|
@ -197,7 +197,7 @@ class AdjacencyMatrix:
|
|||
|
||||
def to_dict(self) -> dict:
|
||||
result: dict = {}
|
||||
result["allPars"] = from_list(from_str, self.all_parts)
|
||||
result["allParts"] = from_list(from_str, self.all_parts)
|
||||
result["firstDetail"] = from_str(self.first_detail)
|
||||
result["matrix"] = from_dict(
|
||||
lambda x: from_list(from_str, x), self.matrix)
|
||||
|
@ -449,13 +449,54 @@ class CadAdjacencyMatrix:
|
|||
part.Shape.distToShape(nextPart.Shape)[0])
|
||||
if (collisionResult == 0):
|
||||
matrix[part.Label].append(nextPart.Label)
|
||||
|
||||
return AdjacencyMatrix(all_parts=GetAllPartsLabelsUseCase(
|
||||
).call(), first_detail=GetFirstDetailUseCase().call(),
|
||||
matrix=matrix
|
||||
)
|
||||
|
||||
|
||||
def reduce(function, iterable, initializer=None):
|
||||
it = iter(iterable)
|
||||
if initializer is None:
|
||||
value = next(it)
|
||||
else:
|
||||
value = initializer
|
||||
for element in it:
|
||||
value = function(value, element)
|
||||
return value
|
||||
|
||||
|
||||
def to_ascii_hash(text):
|
||||
ascii_values = [ord(character) for character in text]
|
||||
return reduce(lambda x, y: x + y, ascii_values)
|
||||
|
||||
|
||||
def matrixGetUniqueContact(matrix):
|
||||
|
||||
detailsToCheck = []
|
||||
detailsHashCheck = {}
|
||||
for k, v in matrix.items():
|
||||
for el in v:
|
||||
if (el != k):
|
||||
hash = to_ascii_hash(k + el)
|
||||
if (detailsHashCheck.get(hash) == None):
|
||||
detailsHashCheck[hash] = hash
|
||||
detailsToCheck.append({
|
||||
'child': el,
|
||||
'parent': k
|
||||
})
|
||||
return detailsToCheck
|
||||
|
||||
def intersectionComputed(parts):
|
||||
App.activeDocument().addObject("Part::MultiCommon", "Common")
|
||||
App.activeDocument().Common.Shapes = [parts[0], parts[1]]
|
||||
App.activeDocument().getObject('Common').ViewObject.ShapeColor = getattr(parts[0].getLinkedObject(True).ViewObject, 'ShapeColor', App.activeDocument().getObject('Common').ViewObject.ShapeColor)
|
||||
App.activeDocument().getObject('Common').ViewObject.DisplayMode = getattr(parts[0].getLinkedObject(True).ViewObject, 'DisplayMode', App.activeDocument().getObject('Common').ViewObject.DisplayMode)
|
||||
App.ActiveDocument.recompute()
|
||||
area = App.activeDocument().getObject('Common').Shape.Area
|
||||
App.ActiveDocument.removeObject('Common')
|
||||
return area
|
||||
|
||||
def main():
|
||||
env = FS.readJSON('env.json')
|
||||
cadFile = env['cadFilePath']
|
||||
|
@ -464,14 +505,34 @@ def main():
|
|||
return TypeError('CadFile not found env.json')
|
||||
App.open(u'' + cadFile)
|
||||
|
||||
# Получение матрицы
|
||||
topologyMatrix = CadAdjacencyMatrix().primitiveMatrix()
|
||||
topologyMatrix = CadAdjacencyMatrix().matrixBySurfaces()
|
||||
import json
|
||||
sequences = json.dumps({"sequences": AllSequences(
|
||||
topologyMatrix.matrix).adj_matrix_names}, ensure_ascii=False, indent=4)
|
||||
matrix = topologyMatrix.matrix
|
||||
contacts = matrixGetUniqueContact(matrix)
|
||||
intersection_geometry = {
|
||||
'status':True,
|
||||
'recalculations':None
|
||||
}
|
||||
for el in contacts:
|
||||
child = App.ActiveDocument.getObjectsByLabel(el.get('child'))[0]
|
||||
parent = App.ActiveDocument.getObjectsByLabel(el.get('parent'))[0]
|
||||
area = intersectionComputed([child,parent])
|
||||
if(area != 0.0):
|
||||
if(intersection_geometry.get('recalculations') == None):
|
||||
intersection_geometry['status'] = False
|
||||
intersection_geometry['recalculations'] = []
|
||||
intersection_geometry['recalculations'].append({
|
||||
'area':area,
|
||||
'connect': el.get('child') + ' ' + el.get('parent')
|
||||
})
|
||||
|
||||
|
||||
FS.writeFile(json.dumps(intersection_geometry, ensure_ascii=False, indent=4), outPath, 'intersection_geometry.json')
|
||||
FS.writeFile(sequences, outPath, 'sequences.json')
|
||||
FS.writeFile(json.dumps(topologyMatrix.to_dict(),
|
||||
ensure_ascii=False, indent=4), outPath, 'adjacency_matrix.json')
|
||||
|
||||
|
||||
|
||||
main()
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue