2023-07-04 07:19:55 +00:00
|
|
|
|
import FreeCAD as App
|
|
|
|
|
import json
|
|
|
|
|
import re
|
|
|
|
|
from pyquaternion import Quaternion
|
|
|
|
|
|
2023-07-05 16:03:51 +03:00
|
|
|
|
|
2023-07-04 07:19:55 +00:00
|
|
|
|
def importObjAtPath(path: str):
|
|
|
|
|
import importOBJ
|
|
|
|
|
importOBJ.insert(u"" + path, App.ActiveDocument.Label)
|
|
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getFullPathObj(assemblyFolder: str, name: str):
|
|
|
|
|
return assemblyFolder + 'sdf/meshes/' + name + '.obj'
|
|
|
|
|
|
|
|
|
|
|
2023-07-05 16:03:51 +03:00
|
|
|
|
def computedStability(refElement, childElement):
|
2023-07-05 13:33:45 +00:00
|
|
|
|
rootElement = childElement.Shape.BoundBox
|
|
|
|
|
# Создание обьекта на котором делается операция пересечения
|
2023-07-04 07:19:55 +00:00
|
|
|
|
App.activeDocument().addObject("Part::MultiCommon", "Common")
|
|
|
|
|
App.activeDocument().Common.Shapes = [refElement, childElement, ]
|
2023-07-05 13:33:45 +00:00
|
|
|
|
App.ActiveDocument.getObject('Common').ViewObject.ShapeColor = getattr(App.ActiveDocument.getObject(
|
|
|
|
|
refElement.Name).getLinkedObject(True).ViewObject, 'ShapeColor', App.ActiveDocument.getObject('Common').ViewObject.ShapeColor)
|
|
|
|
|
App.ActiveDocument.getObject('Common').ViewObject.DisplayMode = getattr(App.ActiveDocument.getObject(
|
|
|
|
|
childElement.Name).getLinkedObject(True).ViewObject, 'DisplayMode', App.ActiveDocument.getObject('Common').ViewObject.DisplayMode)
|
2023-07-04 07:19:55 +00:00
|
|
|
|
App.ActiveDocument.recompute()
|
|
|
|
|
obj = App.ActiveDocument.getObjectsByLabel('Common')[0]
|
2023-07-05 13:33:45 +00:00
|
|
|
|
|
2023-07-04 07:19:55 +00:00
|
|
|
|
shp = obj.Shape
|
|
|
|
|
bbox = shp.BoundBox
|
2023-07-05 13:33:45 +00:00
|
|
|
|
# Если после операции пересечения зона обьекта совпадает с зоной тестируемого обьекта то тест прошел успешно
|
|
|
|
|
if bbox.XLength == rootElement.XLength and bbox.YLength == rootElement.YLength and rootElement.ZLength == bbox.ZLength:
|
2023-07-04 07:19:55 +00:00
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
App.newDocument()
|
2023-07-05 16:03:51 +03:00
|
|
|
|
# загрузка env интерфейса
|
2023-07-04 07:19:55 +00:00
|
|
|
|
env = json.loads((open('./env.json')).read())
|
2023-07-05 16:03:51 +03:00
|
|
|
|
|
|
|
|
|
# получение пути координат файла
|
|
|
|
|
coordinatesFilePath = env.get('pathToTheSimulationCoordinatesFile')
|
|
|
|
|
|
|
|
|
|
# получение папки сборки
|
2023-07-04 07:19:55 +00:00
|
|
|
|
assemblyFolder = env.get('generationFolder')
|
2023-07-05 16:03:51 +03:00
|
|
|
|
buildNumber = int(re.findall(r'\d', coordinatesFilePath)[0])
|
2023-07-04 07:19:55 +00:00
|
|
|
|
|
2023-07-05 16:03:51 +03:00
|
|
|
|
# загрузка последовательности сборки ввиде списка строк деталей
|
2023-07-04 07:19:55 +00:00
|
|
|
|
assemblyStructure = json.loads(
|
|
|
|
|
(open(assemblyFolder + 'step-structure.json')).read())
|
2023-07-05 16:03:51 +03:00
|
|
|
|
# получение номера тестируемой сборки
|
2023-07-04 07:19:55 +00:00
|
|
|
|
assemblyNumber = int(buildNumber)
|
2023-07-05 16:03:51 +03:00
|
|
|
|
# получение тестируемой детали в сборке
|
2023-07-04 07:19:55 +00:00
|
|
|
|
activeDetail = assemblyStructure[assemblyNumber]
|
2023-07-05 16:03:51 +03:00
|
|
|
|
|
2023-07-04 07:19:55 +00:00
|
|
|
|
subassemblyNotParticipatingInMarkup = assemblyStructure[0:assemblyNumber - 1]
|
|
|
|
|
detailOfTheMarkingZoneOfWhich = assemblyStructure[assemblyNumber - 1]
|
|
|
|
|
importObjAtPath(getFullPathObj(assemblyFolder, activeDetail))
|
|
|
|
|
importObjAtPath(getFullPathObj(
|
|
|
|
|
assemblyFolder, detailOfTheMarkingZoneOfWhich))
|
|
|
|
|
meshMark = App.ActiveDocument.Objects[0]
|
|
|
|
|
meshDetailOfTheMarkZone = App.ActiveDocument.Objects[1]
|
|
|
|
|
meshMark.ViewObject.ShapeColor = (0.31, 0.77, 0.87)
|
|
|
|
|
meshDetailOfTheMarkZone.ViewObject.ShapeColor = (0.68, 0.66, 0.95)
|
|
|
|
|
for el in list(map(lambda el: getFullPathObj(assemblyFolder, el), subassemblyNotParticipatingInMarkup)):
|
|
|
|
|
importObjAtPath(el)
|
|
|
|
|
for el in App.ActiveDocument.Objects[2:App.ActiveDocument.Objects.__len__()]:
|
|
|
|
|
el.ViewObject.ShapeColor = (0.32, 0.05, 0.38)
|
2023-07-05 16:03:51 +03:00
|
|
|
|
# загрузка координат
|
|
|
|
|
coordinates = json.loads((open(coordinatesFilePath)).read())
|
2023-07-04 07:19:55 +00:00
|
|
|
|
inc = 1
|
2023-07-05 16:03:51 +03:00
|
|
|
|
# перемещение обьектов в документе на точки стабильность полученные из pybullet
|
2023-07-04 07:19:55 +00:00
|
|
|
|
for el in App.ActiveDocument.Objects:
|
2023-07-05 16:03:51 +03:00
|
|
|
|
pos = coordinates[inc]['position']
|
|
|
|
|
qua = coordinates[inc]['quaternion']
|
2023-07-04 07:19:55 +00:00
|
|
|
|
new_quaternion = Quaternion(qua[0], qua[1], qua[2], qua[3])
|
|
|
|
|
rotation_matrix = new_quaternion.rotation_matrix
|
|
|
|
|
current_position = el.Placement.Base
|
2023-07-05 16:03:51 +03:00
|
|
|
|
new_position = App.Vector(
|
|
|
|
|
current_position.x, current_position.y, current_position.z)
|
2023-07-04 07:19:55 +00:00
|
|
|
|
new_placement = App.Placement(new_position, rotation_matrix)
|
|
|
|
|
el.Placement = new_placement
|
|
|
|
|
App.ActiveDocument.recompute()
|
|
|
|
|
el.Placement.move(App.Vector(pos[0], pos[1], pos[2]))
|
2023-07-05 16:03:51 +03:00
|
|
|
|
# вычисление стабильность
|
|
|
|
|
computedStability(meshMark, meshDetailOfTheMarkZone)
|
2023-07-04 07:19:55 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main()
|