Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- u_iso/v_iso: Returns the u-iso/v-iso curve of the surface.
- Plane3D/CylindricalSurface/ConicalSurface/SphericalSurface3D : normal_at_point

#### core_compiled
- Add custom Schemas for Vectors & Points

#### shells.py
- first version boolean operations with any faces.


#### global
- Add reference_path to a handful of classes

Expand Down
2 changes: 1 addition & 1 deletion volmdlr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
linesegment2d_point_distance, LineSegment3DDistance,
linesegment3d_point_distance, get_minimum_distance_points_lines,
Matrix22, Matrix33, Point2D, Point3D, Vector2D,
Vector3D)
Vector3D, Vector)


TWO_PI = 2 * math.pi
Expand Down
53 changes: 53 additions & 0 deletions volmdlr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from numpy.typing import NDArray

import dessia_common.core as dc
from dessia_common.schemas.core import SchemaAttribute, Schema

import volmdlr
import volmdlr.templates
Expand Down Expand Up @@ -999,3 +1000,55 @@ def __init__(self, primitives: List[Primitive3D], name: str = ''):

def __getattr__(self, name):
return getattr(self.instance, name)


class VectorSchema(Schema):
def __init__(self, class_, annotations, attributes):
self.classname = f"{class_.__module__}.{class_.__name__}"

super().__init__(annotations=annotations, attributes=attributes)

def to_dict(self, **kwargs):
dict_ = super().to_dict()
dict_.update({"standalone_in_db": False, "classes": [self.classname]})
return dict_


class Vector2Schema(VectorSchema):
def __init__(self, class_):
annotations = {"x": float, "y": float, "name": str}
attributes = [SchemaAttribute("x"), SchemaAttribute("y"), SchemaAttribute("name", default_value="")]
super().__init__(class_=class_, annotations=annotations, attributes=attributes)


class Vector3Schema(VectorSchema):
def __init__(self, class_):
annotations = {"x": float, "y": float, "z": float, "name": str}
attributes = [SchemaAttribute("x"), SchemaAttribute("y"),
SchemaAttribute("z"), SchemaAttribute("name", default_value="")]
super().__init__(class_=class_, annotations=annotations, attributes=attributes)


class VectorBlueprint(volmdlr.Vector):
@classmethod
def raw_schema(cls):
raise NotImplementedError("Cannot compute schema for base class 'Vector'. Should be one of its children class")

@classmethod
def schema(cls):
""" Write raw schema as a dict in order to make it jsonable. """
return cls.raw_schema().to_dict()


class Vector2DBlueprint(volmdlr.Vector2D):
@classmethod
def raw_schema(cls):
""" Custom Schema implementation in order to allow vectors and points to be used in forms. """
return Vector2Schema(cls)


class Vector3DBlueprint(volmdlr.Vector3D):
@classmethod
def raw_schema(cls):
""" Custom Schema implementation in order to allow vectors and points to be used in forms. """
return Vector3Schema(cls)