-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor reactor to assembly #304
Open
shimwell
wants to merge
19
commits into
develop
Choose a base branch
from
refactor_reactor_to_assembly
base: develop
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…gy/paramak into refactor_reactor_to_assembly
…gy/paramak into refactor_reactor_to_assembly
Alternatively I could inherit assembly like this class ChildAssembly(Assembly):
def __init__(self, obj: AssemblyObjects = None, loc: Optional[Location] = None, name: Optional[str] = None, color: Optional[Color] = None, metadata: Optional[Dict[str, Any]] = None):
super().__init__(obj, loc, name, color, metadata) |
I think I might try a different approach, using patching import cadquery as cq
@classmethod
def build_reactor(cls, height: float=1.):
plane='XY'
wp1 = cq.Workplane(plane).box(2.0, 2.0, height)
wp2 = cq.Workplane("XY").circle(2.0).rect(0.5, 0.75).extrude(0.5)
wp3 = cq.Workplane().build_component(height=height)
my_assembly=cq.Assembly()
my_assembly.add(wp1, name='wp1')
my_assembly.add(wp2, name='wp2')
my_assembly.add(wp3, name='wp3')
return my_assembly
cq.assembly.Assembly.build_reactor = build_reactor
@classmethod
def build_component(cls,
height: float = 10,
plane: str='XY'
):
wp = cq.Workplane(plane).box(2.0, 2.0, height)
return wp
cq.Workplane.build_component = build_component
my_component = cq.Workplane().build_component()
my_reactor = cq.Assembly().build_reactor(height=10)
my_reactor.save(path='reactor.step')
my_reactor.add(my_component, name='my_component')
my_reactor.save(path='reactor2.step') |
Perhaps the first stage is to make functions for the components, remove the shape.py and make a few util functions. example for BlanketConstantThicknessArcH might look like this from typing import Tuple
from cadquery import Workplane
def instructions_from_points(points):
# obtains the first two values of the points list
XZ_points = [(p[0], p[1]) for p in points]
# obtains the last values of the points list
connections = [p[2] for p in points[:-1]]
current_linetype = connections[0]
current_points_list = []
instructions = []
# groups together common connection types
for i, connection in enumerate(connections):
if connection == current_linetype:
current_points_list.append(XZ_points[i])
else:
current_points_list.append(XZ_points[i])
instructions.append({current_linetype: current_points_list})
current_linetype = connection
current_points_list = [XZ_points[i]]
instructions.append({current_linetype: current_points_list})
if list(instructions[-1].values())[0][-1] != XZ_points[0]:
keyname = list(instructions[-1].keys())[0]
instructions[-1][keyname].append(XZ_points[0])
return instructions
def create_wire_workplane_from_instructions(instructions,workplane='XY'):
solid = Workplane(workplane) #offset=extrusion_offset
for entry in instructions:
if list(entry.keys())[0] == "spline":
solid = solid.spline(listOfXYTuple=list(entry.values())[0])
if list(entry.keys())[0] == "straight":
solid = solid.polyline(list(entry.values())[0])
if list(entry.keys())[0] == "circle":
p0 = list(entry.values())[0][0]
p1 = list(entry.values())[0][1]
p2 = list(entry.values())[0][2]
solid = solid.moveTo(p0[0], p0[1]).threePointArc(p1, p2)
return solid.close()
def BlanketConstantThicknessArcH(
inner_mid_point: Tuple[float, float],
inner_upper_point: Tuple[float, float],
inner_lower_point: Tuple[float, float],
thickness: float,
rotation_angle=90,
# workplane
):
points = [
(inner_upper_point[0], inner_upper_point[1], "circle"),
(inner_mid_point[0], inner_mid_point[1], "circle"),
(inner_lower_point[0], inner_lower_point[1], "straight"),
(
inner_lower_point[0] + abs(thickness),
inner_lower_point[1],
"circle",
),
(
inner_mid_point[0] + abs(thickness),
inner_mid_point[1],
"circle",
),
(
inner_upper_point[0] + abs(thickness),
inner_upper_point[1],
"straight",
),
]
points.append(points[0])
instructions = instructions_from_points(points)
print(instructions)
wire = create_wire_workplane_from_instructions(instructions=instructions)
print(wire)
solid = wire.revolve(rotation_angle)
return solid
a=BlanketConstantThicknessArcH(
(10,0),
(2,10),
(2,-10),
10
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have been thinking about a refactor that makes use of the cadquery assembly.
This PR is a working progress but I think it shows some potential as we have a nice large reduction to the number of lines