forked from tazjel/declaracad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
part.py
139 lines (98 loc) · 3.21 KB
/
part.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"""
Copyright (c) 2016-2018, Jairus Martin.
Distributed under the terms of the GPL v3 License.
The full license is in the file LICENSE, distributed with this software.
Created on Sept 28, 2016
@author: jrm
"""
import enaml
from atom.api import Typed, ForwardTyped, Str, Enum, observe
from enaml.core.declarative import d_
from .shape import Shape, ProxyShape
class ProxyPart(ProxyShape):
#: A reference to the Shape declaration.
declaration = ForwardTyped(lambda: Part)
class ProxyRawPart(ProxyPart):
#: A reference to the shape declaration.
declaration = ForwardTyped(lambda: RawPart)
def get_shapes(self):
raise NotImplementedError
class ProxyLoadPart(ProxyPart):
#: A reference to the shape declaration.
declaration = ForwardTyped(lambda: LoadPart)
def set_path(self, path):
raise NotImplementedError
def set_loader(self, loader):
raise NotImplementedError
class Part(Shape):
""" A Part is a compound shape. It may contain
any number of nested parts and is typically subclassed.
Attributes
----------
name: String
An optional name for the part
description: String
An optional description for the part
Examples
--------
enamldef Case(Part):
TopCover:
# etc..
BottomCover:
# etc..
"""
#: Reference to the implementation control
proxy = Typed(ProxyPart)
#: Optional name of the part
name = d_(Str())
#: Optional description of the part
description = d_(Str())
#: Cache
cache = {}
@property
def shapes(self):
return [child for child in self.children if isinstance(child, Shape)]
class RawPart(Shape):
""" A RawPart is a part that delegates creation to the declaration.
This allows custom shapes to be added to the 3D model hierarchy. Users
should subclass this and implement the `create_shapes` method.
Examples
--------
from OCC.TopoDS import TopoDS_Shape
from OCC.StlAPI import StlAPI_Reader
class StlShape(RawShape):
#: Loads a shape from an stl file
def create_shape(self, parent):
stl_reader = StlAPI_Reader()
shape = TopoDS_Shape()
stl_reader.Read(shape, './models/fan.stl')
return shape
"""
#: Reference to the implementation control
proxy = Typed(ProxyRawPart)
def create_shapes(self, parent):
""" Create the shape for the control.
This method should create and initialize the shape.
Parameters
----------
parent : shape or None
The parent shape for the control.
Returns
-------
result : List[shape]
The shapes for the control.
"""
raise NotImplementedError
def get_shapes(self):
""" Retrieve the shapes for display.
Returns
-------
shapes : List[shape] or None
The toolkit shape that was previously created by the
call to 'create_shapes' or None if the proxy is not
active or the shape has been destroyed.
"""
if self.proxy_is_active:
return self.proxy.get_shapes()
with enaml.imports():
from .loader import LoadedPart