Skip to content

Commit

Permalink
fix bug in type info
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Feb 1, 2024
1 parent 19a2c81 commit 6b43f48
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 198 deletions.
4 changes: 2 additions & 2 deletions scripts/test_rhino_exchange/testsurfacedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
assert isinstance(surface, OCCNurbsSurface)
assert isinstance(surface, NurbsSurface)

for u, col in enumerate(surface.points):
for u, col in enumerate(surface.points): # type: ignore
for v, point in enumerate(col):
assert point == surface.points[u][v]
assert TOL.is_close(point[0], u * 18 / 3)
Expand All @@ -23,7 +23,7 @@
assert isinstance(after, OCCNurbsSurface)
assert isinstance(after, NurbsSurface)

for u, col in enumerate(surface.points):
for u, col in enumerate(surface.points): # type: ignore
for v, point in enumerate(col):
assert point == after.points[u][v]

Expand Down
24 changes: 10 additions & 14 deletions src/compas_occ/brep/brep.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,6 @@ class OCCBrep(Brep):

_occ_shape: TopoDS.TopoDS_Shape

def __init__(self) -> None:
super().__init__()
self._vertices = None
self._edges = None
self._loops = None
self._faces = None
self._shells = None
self._solids = None

# ==============================================================================
# Data
# ==============================================================================

@property
def __data__(self):
return {
Expand All @@ -119,6 +106,15 @@ def __from_data__(cls, data):
"""
raise NotImplementedError

def __init__(self) -> None:
super().__init__()
self._vertices = None
self._edges = None
self._loops = None
self._faces = None
self._shells = None
self._solids = None

def copy(self, *args, **kwargs):
"""Deep-copy this BRep using the native OCC copying mechanism.
Expand Down Expand Up @@ -706,7 +702,7 @@ def from_brepfaces(cls, faces: List[OCCBrepFace]) -> "OCCBrep":
return brep

@classmethod
def from_planes(cls, planes: list[Plane]) -> "OCCBrep":
def from_planes(cls, planes: List[Plane]) -> "OCCBrep":
"""
Make a BRep from a list of planes.
Expand Down
75 changes: 27 additions & 48 deletions src/compas_occ/brep/brepedge.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,35 @@ class OCCBrepEdge(BrepEdge):

_occ_edge: TopoDS.TopoDS_Edge

@property
def __data__(self):
if self.is_line:
curve = self.to_line()
elif self.is_circle:
curve = self.to_circle()
elif self.is_ellipse:
curve = self.to_ellipse()
elif self.is_hyperbola:
curve = self.to_hyperbola()
elif self.is_parabola:
curve = self.to_parabola()
else:
raise NotImplementedError
return {
"curve_type": self.type,
"curve": curve.__data__, # type: ignore
"frame": curve.frame.__data__, # type: ignore
"start_vertex": self.first_vertex.__data__,
"end_vertex": self.last_vertex.__data__,
"domain": curve.domain, # type: ignore
}

@classmethod
def __from_data__(cls, data):
raise NotImplementedError

def __init__(self, occ_edge: TopoDS.TopoDS_Edge):
super().__init__()
# self._curve = None
# self._nurbscurve = None
self._occ_adaptor = None
self.occ_edge = occ_edge
self.is_2d = False
Expand Down Expand Up @@ -140,52 +165,6 @@ def is_equal(self, other: "OCCBrepEdge"):
return False
return self.occ_edge.IsEqual(other.occ_edge)

# ==============================================================================
# Data
# ==============================================================================

@property
def __data__(self):
if self.is_line:
curve = self.to_line()
elif self.is_circle:
curve = self.to_circle()
elif self.is_ellipse:
curve = self.to_ellipse()
elif self.is_hyperbola:
curve = self.to_hyperbola()
elif self.is_parabola:
curve = self.to_parabola()
else:
raise NotImplementedError
return {
"curve_type": self.type,
"curve": curve.__data__, # type: ignore
"frame": curve.frame.__data__, # type: ignore
"start_vertex": self.first_vertex.__data__,
"end_vertex": self.last_vertex.__data__,
"domain": curve.domain, # type: ignore
}

@classmethod
def __from_data__(cls, data, builder):
"""Construct an object of this type from the provided data.
Parameters
----------
data : dict
The data dictionary.
builder : :class:`compas_rhino.geometry.BrepBuilder`
The object reconstructing the current Brep.
Returns
-------
:class:`compas.data.Data`
An instance of this object type if the data contained in the dict has the correct schema.
"""
raise NotImplementedError

# ==============================================================================
# OCC Properties
# ==============================================================================
Expand Down
66 changes: 31 additions & 35 deletions src/compas_occ/brep/brepface.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,37 @@ class OCCBrepFace(BrepFace):

_occ_face: TopoDS.TopoDS_Face

@property
def __data__(self):
return {
"type": self.type,
"surface": self.surface.__data__,
"domain_u": self.domain_u,
"domain_v": self.domain_v,
"frame": Frame.worldXY().__data__,
"loops": [self.outerloop.__data__]
+ [loop.__data__ for loop in self.innerloops],
}

@classmethod
def __from_data__(cls, data, builder):
"""Construct an object of this type from the provided data.
Parameters
----------
data : dict
The data dictionary.
builder : :class:`compas_rhino.geometry.BrepBuilder`
The object reconstructing the current Brep.
Returns
-------
:class:`compas.data.Data`
An instance of this object type if the data contained in the dict has the correct schema.
"""
raise NotImplementedError

def __init__(self, occ_face: TopoDS.TopoDS_Face):
super().__init__()
self.precision = 1e-6
Expand Down Expand Up @@ -119,41 +150,6 @@ def is_equal(self, other: "OCCBrepFace"):
return False
return self.occ_face.IsEqual(other.occ_face)

# ==============================================================================
# Data
# ==============================================================================

@property
def __data__(self):
return {
"type": self.type,
"surface": self.surface.__data__,
"domain_u": self.domain_u,
"domain_v": self.domain_v,
"frame": Frame.worldXY().__data__,
"loops": [self.outerloop.__data__]
+ [loop.__data__ for loop in self.innerloops],
}

@classmethod
def __from_data__(cls, data, builder):
"""Construct an object of this type from the provided data.
Parameters
----------
data : dict
The data dictionary.
builder : :class:`compas_rhino.geometry.BrepBuilder`
The object reconstructing the current Brep.
Returns
-------
:class:`compas.data.Data`
An instance of this object type if the data contained in the dict has the correct schema.
"""
raise NotImplementedError

# ==============================================================================
# OCC Properties
# ==============================================================================
Expand Down
58 changes: 27 additions & 31 deletions src/compas_occ/brep/breploop.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@ class OCCBrepLoop(BrepLoop):

_occ_wire: TopoDS.TopoDS_Wire

@property
def __data__(self):
# return {
# "type": str(self._loop.LoopType),
# "trims": [t.data for t in self._trims],
# }
raise NotImplementedError

@classmethod
def __from_data__(cls, data, builder):
"""Construct an object of this type from the provided data.
Parameters
----------
data : dict
The data dictionary.
builder : :class:`compas_rhino.geometry.BrepFaceBuilder`
The object reconstructing the current BrepFace.
Returns
-------
:class:`compas.data.Data`
An instance of this object type if the data contained in the dict has the correct schema.
"""
raise NotImplementedError

def __init__(self, occ_wire: TopoDS.TopoDS_Wire):
super().__init__()
self.occ_wire = occ_wire
Expand Down Expand Up @@ -100,37 +127,6 @@ def is_equal(self, other: "OCCBrepLoop"):
return False
return self.occ_wire.IsEqual(other.occ_wire)

# ==============================================================================
# Data
# ==============================================================================

@property
def __data__(self):
# return {
# "type": str(self._loop.LoopType),
# "trims": [t.data for t in self._trims],
# }
raise NotImplementedError

@classmethod
def __from_data__(cls, data, builder):
"""Construct an object of this type from the provided data.
Parameters
----------
data : dict
The data dictionary.
builder : :class:`compas_rhino.geometry.BrepFaceBuilder`
The object reconstructing the current BrepFace.
Returns
-------
:class:`compas.data.Data`
An instance of this object type if the data contained in the dict has the correct schema.
"""
raise NotImplementedError

# ==============================================================================
# OCC Properties
# ==============================================================================
Expand Down
24 changes: 10 additions & 14 deletions src/compas_occ/brep/brepvertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class OCCBrepVertex(BrepVertex):
"""

@property
def __data__(self):
return {
"point": self.point.__data__,
}

@classmethod
def __from_data__(cls, data):
return cls.from_point(Point.__from_data__(data["point"]))

def __init__(self, occ_vertex: TopoDS.TopoDS_Vertex):
super().__init__()
self._occ_vertex = None
Expand Down Expand Up @@ -70,20 +80,6 @@ def is_equal(self, other: "OCCBrepVertex"):
return False
return self.occ_vertex.IsEqual(other.occ_vertex)

# ==============================================================================
# Data
# ==============================================================================

@property
def __data__(self):
return {
"point": self.point.__data__,
}

@classmethod
def __from_data__(cls, data):
return cls.from_point(Point.__from_data__(data["point"]))

# ==============================================================================
# OCC Properties
# ==============================================================================
Expand Down
12 changes: 4 additions & 8 deletions src/compas_occ/geometry/curves/nurbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@ class OCCNurbsCurve(OCCCurve, NurbsCurve):

_occ_curve: Geom_BSplineCurve

def __init__(self, occ_curve: Geom_BSplineCurve, name: Optional[str] = None):
super(OCCNurbsCurve, self).__init__(occ_curve, name=name)
self.occ_curve = occ_curve

# ==============================================================================
# Data
# ==============================================================================

@property
def __data__(self) -> Dict:
return {
Expand Down Expand Up @@ -137,6 +129,10 @@ def __from_data__(cls, data: Dict) -> "OCCNurbsCurve":
is_periodic,
)

def __init__(self, occ_curve: Geom_BSplineCurve, name: Optional[str] = None):
super(OCCNurbsCurve, self).__init__(occ_curve, name=name)
self.occ_curve = occ_curve

# ==============================================================================
# OCC Properties
# ==============================================================================
Expand Down
Loading

0 comments on commit 6b43f48

Please sign in to comment.