11from dataclasses import dataclass
22from typing import List , Dict , Any , Optional
33
4- from ormatic .dao import AlternativeMapping
4+ from ormatic .dao import AlternativeMapping , T
55
66from ..prefixed_name import PrefixedName
77from ..spatial_types import RotationMatrix , Vector3 , Point3 , TransformationMatrix
88from ..spatial_types .spatial_types import Quaternion
99from ..spatial_types .symbol_manager import symbol_manager
1010from ..world import World , Body
11- from ..world_entity import Connection
11+ from ..world_entity import Connection , View
1212
1313
1414@dataclass
1515class WorldMapping (AlternativeMapping [World ]):
1616 bodies : List [Body ]
1717 connections : List [Connection ]
18+ views : List [View ]
1819
1920 @classmethod
2021 def create_instance (cls , obj : World ):
21- return cls (obj .bodies , obj .connections )
22+ return cls (obj .bodies , obj .connections , obj .views )
23+
24+ def create_from_dao (self ) -> World :
25+ result = World ()
26+
27+ with result .modify_world ():
28+ for body in self .bodies :
29+ result .add_body (body )
30+ for connection in self .connections :
31+ result .add_connection (connection )
32+ for view in self .views :
33+ result .add_view (view )
34+
35+ return result
2236
2337
2438@dataclass
@@ -34,6 +48,9 @@ def create_instance(cls, obj: Vector3):
3448 x , y , z , _ = symbol_manager .evaluate_expr (obj ).tolist ()
3549 return cls (x = x , y = y , z = z , reference_frame = obj .reference_frame )
3650
51+ def create_from_dao (self ) -> Vector3 :
52+ return Vector3 .from_xyz (x = self .x , y = self .y , z = self .z , reference_frame = self .reference_frame )
53+
3754
3855@dataclass
3956class Point3Mapping (AlternativeMapping [Point3 ]):
@@ -49,6 +66,8 @@ def create_instance(cls, obj: Point3):
4966 result = cls (x = x , y = y , z = z , reference_frame = obj .reference_frame )
5067 return result
5168
69+ def create_from_dao (self ) -> Point3 :
70+ return Point3 .from_xyz (x = self .x , y = self .y , z = self .z , reference_frame = self .reference_frame )
5271
5372@dataclass
5473class QuaternionMapping (AlternativeMapping [Quaternion ]):
@@ -64,6 +83,9 @@ def create_instance(cls, obj: Quaternion):
6483 result = cls (x = x , y = y , z = z , w = w , reference_frame = obj .reference_frame )
6584 return result
6685
86+ def create_from_dao (self ) -> Quaternion :
87+ return Quaternion .from_xyzw (x = self .x , y = self .y , z = self .z , w = self .w , reference_frame = self .reference_frame )
88+
6789@dataclass
6890class RotationMatrixMapping (AlternativeMapping [RotationMatrix ]):
6991 reference_frame : PrefixedName
@@ -73,6 +95,8 @@ class RotationMatrixMapping(AlternativeMapping[RotationMatrix]):
7395 def create_instance (cls , obj : RotationMatrix ):
7496 return cls (reference_frame = obj .reference_frame , rotation = obj .to_quaternion ())
7597
98+ def create_from_dao (self ) -> RotationMatrix :
99+ return RotationMatrix .from_quaternion (self .rotation )
76100
77101@dataclass
78102class TransformationMatrixMapping (AlternativeMapping [TransformationMatrix ]):
@@ -88,3 +112,9 @@ def create_instance(cls, obj: TransformationMatrix):
88112 result = cls (reference_frame = obj .reference_frame , child_frame = obj .child_frame , position = position ,
89113 rotation = rotation )
90114 return result
115+
116+ def create_from_dao (self ) -> TransformationMatrix :
117+ return TransformationMatrix .from_point_rotation_matrix (
118+ point = self .position ,
119+ rotation_matrix = RotationMatrix .from_quaternion (self .rotation ), reference_frame = self .reference_frame ,
120+ child_frame = self .child_frame ,)
0 commit comments