|
| 1 | +from typing import Callable, Optional, overload |
| 2 | + |
| 3 | +import Sofa |
| 4 | +import dataclasses |
| 5 | + |
| 6 | + |
| 7 | +class VisualModel(Sofa.Core.BasePrefab): |
| 8 | + def __init__(self, params, **kwargs): |
| 9 | + Sofa.Core.Node.__init__(self, **kwargs) |
| 10 | + |
| 11 | + class Parameters(object): |
| 12 | + enabled : bool |
| 13 | + filename : str |
| 14 | + |
| 15 | + class DefaultParameters(object): |
| 16 | + enabled : bool |
| 17 | + filename : str |
| 18 | + |
| 19 | +class CollisionModel(Sofa.Core.BasePrefab): |
| 20 | + def __init__(self, params, **kwargs): |
| 21 | + Sofa.Core.Node.__init__(self, **kwargs) |
| 22 | + |
| 23 | + class Parameters(object): |
| 24 | + enabled : bool = False |
| 25 | + |
| 26 | +class MechanicalObject(Sofa.Core.Object): |
| 27 | + positions : list[float] |
| 28 | + |
| 29 | + @dataclasses.dataclass |
| 30 | + class Parameters(object): |
| 31 | + name : str = "MechanicalObject" |
| 32 | + |
| 33 | + def to_dict(self): |
| 34 | + return dataclasses.asdict(self) |
| 35 | + |
| 36 | + |
| 37 | +def addBidule(self): |
| 38 | + return self.addChild("Bidule") |
| 39 | + |
| 40 | +class Entity(Sofa.Core.Node): |
| 41 | + # A simulated object |
| 42 | + visual : VisualModel |
| 43 | + collision : CollisionModel |
| 44 | + |
| 45 | + @staticmethod |
| 46 | + def addSolver(self): |
| 47 | + pass |
| 48 | + |
| 49 | + @dataclasses.dataclass |
| 50 | + class Parameters(object): |
| 51 | + addSolver : Callable = addBidule |
| 52 | + addConstitutiveLaw : Callable = addBidule |
| 53 | + addBoundaryCondition : Callable = addBidule |
| 54 | + |
| 55 | + mechanical : MechanicalObject.Parameters = MechanicalObject.Parameters() |
| 56 | + collision : CollisionModel.Parameters = CollisionModel.Parameters() |
| 57 | + visual : VisualModel.Parameters = VisualModel.Parameters() |
| 58 | + |
| 59 | + name = "Entity" |
| 60 | + |
| 61 | + def to_dict(self): |
| 62 | + return dataclasses.asdict(self) |
| 63 | + |
| 64 | + # Ici mettre un prefab simplfié. |
| 65 | + def __init__(self, **kwargs): |
| 66 | + print("CCOUou") |
| 67 | + params = kwargs.get("params", None) # type: Entity.Parameters |
| 68 | + Sofa.Core.Node.__init__(self, params.name) |
| 69 | + |
| 70 | + print("ZUT ZUT ") |
| 71 | + |
| 72 | + print("COUCOU") |
| 73 | + self.addObject("MechanicalObject", **params.mechanical.to_dict()) |
| 74 | + print("COUCO S") |
| 75 | + |
| 76 | + #if(params.visual != None): |
| 77 | + # self.addChild(VisualModel(params.visual), |
| 78 | + # name="visual") |
| 79 | + |
| 80 | + #if(params.collision != None): |
| 81 | + # self.addChild(CollisionModel(params.collision), |
| 82 | + # name="collision") |
| 83 | + |
| 84 | +class Rigid(Entity): |
| 85 | + def __init__(self, **kwargs): |
| 86 | + Entity.__init__(self, **kwargs) |
| 87 | + |
| 88 | + class Parameters(Entity.Parameters): |
| 89 | + pass |
| 90 | + |
| 91 | +class Deformable(Entity): |
| 92 | + def __init__(self, **kwargs): |
| 93 | + print("ZUT") |
| 94 | + Entity.__init__(self, **kwargs) |
| 95 | + print("DEFORMABLE") |
| 96 | + |
| 97 | + class Parameters(Entity.Parameters): |
| 98 | + addConstitutiveLaw : Callable |
| 99 | + mass = 3.4 |
| 100 | + name = "Deformable" |
| 101 | + |
| 102 | + def to_dict(self): |
| 103 | + return dataclasses.asdict(self) |
| 104 | + |
| 105 | + |
| 106 | +Entity.Rigid = Rigid |
| 107 | +Entity.Deformable = Deformable |
| 108 | + |
| 109 | +class SoftRobots: |
| 110 | + class Cable(Sofa.Core.BasePrefab): |
| 111 | + length : float |
| 112 | + |
| 113 | + def __init__(self,**kwargs): |
| 114 | + pass |
| 115 | + |
| 116 | + def Parameters(object): |
| 117 | + lenght : float |
| 118 | + |
| 119 | +class Trunk(Sofa.Core.BasePrefab): |
| 120 | + body : Entity.Deformable |
| 121 | + cables : list [SoftRobots.Cable] |
| 122 | + |
| 123 | + def __init__(self, params): |
| 124 | + body = Entity.Deformable() |
| 125 | + |
| 126 | + for param in range(params.cables): |
| 127 | + cables.append(SoftRobots.Cable(body, param)) |
| 128 | + |
| 129 | + class Parameters(object): |
| 130 | + body : Entity.Deformable.Parameters |
| 131 | + cables : list[SoftRobots.Cable.Parameters] |
| 132 | + |
0 commit comments