
import FreeCAD as App
from helper.is_solid import is_object_solid


class GeometryUseCase:
    def call() -> dict:
        labels = []
        Error = False
        for el in App.ActiveDocument.Objects:
            try:
                    
                if is_object_solid(el):
                    labels.append(el.Label)
                    
                    geometry = {
                        "euler": {
                            "x": None,
                            "y": None,
                            "z": None
                        },
                        "position": {
                            "x": None,
                            "y": None,
                            "z": None
                        },
                        "rotation": {
                            "x": None,
                            "y": None,
                            "z": None
                        },
                        "center": {
                            "x": None,
                            "y": None,
                            "z": None
                        },
                        
                    }

                    boundBox = el.Shape.BoundBox
                    geometry["center"]["x"] = boundBox.Center.x
                    geometry["center"]["y"] = boundBox.Center.y
                    geometry["center"]["z"] = boundBox.Center.z
                    geometry["position"]['x'] = boundBox.XMax
                    geometry["position"]['y'] = boundBox.YMax
                    geometry["position"]['z'] = boundBox.ZMax
                    rotation = el.Placement.Rotation
                    geometry["rotation"]['x'] = rotation.Axis.z
                    geometry["rotation"]['y'] = rotation.Axis.y
                    geometry["rotation"]['z'] = rotation.Axis.z
                    euler = el.Placement.Rotation.toEuler()
                    geometry["euler"]['x'] = euler[0]
                    geometry["euler"]['y'] = euler[1]
                    geometry["euler"]['z'] = euler[2]
            except Exception as e:
                print(e)
                #  App.Console.PrintMessage("Clicked on position: ("+str(pos[0])+", "+str(pos[1])+")\n")
        return {"geometry": geometry, "labels": labels, "label": el.Label}
