-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Center heated bed when frame is selected
- Loading branch information
Showing
9 changed files
with
212 additions
and
123 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from FreeCAD import Placement, Vector, Rotation | ||
|
||
|
||
def get_heated_bed_frame_centered_kwargs(frame): | ||
half_frame_size = frame.Size / 2 | ||
z = frame.Placement.Base.z | ||
placement = Placement( | ||
Vector(half_frame_size, half_frame_size, z), Rotation()) | ||
origin_translation_offset = Vector(0.5, 0.5, 0) | ||
return { | ||
'placement': placement, | ||
'origin_translation_offset': origin_translation_offset | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
def is_edge_parallel_to_x_axis(edge): | ||
return is_edge_parallel_to_axis(edge, 'x') | ||
|
||
|
||
def is_edge_parallel_to_y_axis(edge): | ||
return is_edge_parallel_to_axis(edge, 'y') | ||
|
||
|
||
def is_edge_parallel_to_z_axis(edge): | ||
return is_edge_parallel_to_axis(edge, 'z') | ||
|
||
|
||
def is_edge_parallel_to_axis(edge, axis): | ||
index_by_axis = {'x': 0, 'y': 1, 'z': 2} | ||
inverse_orientations = filter( | ||
lambda item: item[0] != axis, index_by_axis.items()) | ||
a_index, b_index = map(lambda item: item[1], inverse_orientations) | ||
first_point = edge.valueAt(edge.FirstParameter) | ||
a1 = round(first_point[a_index]) | ||
b1 = round(first_point[b_index]) | ||
|
||
last_point = edge.valueAt(edge.LastParameter) | ||
a2 = round(last_point[a_index]) | ||
b2 = round(last_point[b_index]) | ||
|
||
return a1 == a2 and b1 == b2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from FreeCAD import Vector | ||
|
||
|
||
def is_face_parallel_to_yz_plane(face): | ||
x_axis = Vector(1, 0, 0) | ||
return is_face_parallel_to_plane(face, x_axis) | ||
|
||
|
||
def is_face_parallel_to_xz_plane(face): | ||
y_axis = Vector(0, 1, 0) | ||
return is_face_parallel_to_plane(face, y_axis) | ||
|
||
|
||
def is_face_parallel_to_xy_plane(face): | ||
z_axis = Vector(0, 0, 1) | ||
return is_face_parallel_to_plane(face, z_axis) | ||
|
||
|
||
def is_face_parallel_to_plane(face, axis_vector): | ||
return axis_vector == Vector( | ||
abs(round(face.Surface.Axis.x)), | ||
abs(round(face.Surface.Axis.y)), | ||
abs(round(face.Surface.Axis.z)) | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from math import degrees | ||
|
||
import Part | ||
from FreeCAD import Console, Vector | ||
from ose3dprinter.core.is_edge_parallel_to_axis import ( | ||
is_edge_parallel_to_x_axis, is_edge_parallel_to_y_axis, | ||
is_edge_parallel_to_z_axis) | ||
|
||
|
||
class BaseModel(object): | ||
""" | ||
Base class for models that encapsulate the data (i.e. topography and shape) | ||
for a part, and is separate from the "view" or GUI representation. | ||
""" | ||
|
||
def __init__(self, placement, origin_translation_offset): | ||
""" | ||
Constructor | ||
Arguments | ||
--------- | ||
- obj: Created with document.addObject('Part::FeaturePython', '{name}') | ||
""" | ||
self.placement = placement | ||
self.origin_translation_offset = origin_translation_offset | ||
|
||
def move_parts(self, parts, reference_dimensions): | ||
base = self.placement.Base | ||
rotation = self.placement.Rotation | ||
|
||
translation_offset = get_translation_offset( | ||
reference_dimensions, rotation, self.origin_translation_offset) | ||
origin = base - translation_offset | ||
for part in parts: | ||
part.translate(origin) | ||
part.rotate(origin, rotation.Axis, degrees(rotation.Angle)) | ||
|
||
def move_part(self, part, reference_dimensions): | ||
base = self.placement.Base | ||
rotation = self.placement.Rotation | ||
|
||
translation_offset = get_translation_offset( | ||
reference_dimensions, rotation, self.origin_translation_offset) | ||
origin = base - translation_offset | ||
|
||
part.translate(origin) | ||
part.rotate(origin, rotation.Axis, degrees(rotation.Angle)) | ||
|
||
|
||
def get_translation_offset(reference_dimensions, | ||
rotation, | ||
origin_translation_offset): | ||
reference_box = Part.makeBox(*reference_dimensions) | ||
reference_box.rotate(Vector(0, 0, 0), rotation.Axis, | ||
degrees(rotation.Angle)) | ||
first_vertex = reference_box.Vertexes[0] | ||
first_vertex_edges = get_edges_connected_to_vertex( | ||
first_vertex, reference_box.Edges) | ||
num_edges = len(first_vertex_edges) | ||
if num_edges != 3: | ||
Console.PrintWarning( | ||
'Found {} edges connected to cube vertex instead of 3.\n'.format(num_edges)) | ||
x = y = z = 1.0 | ||
for e in first_vertex_edges: | ||
if is_edge_parallel_to_x_axis(e): | ||
x = e.Length | ||
elif is_edge_parallel_to_y_axis(e): | ||
y = e.Length | ||
elif is_edge_parallel_to_z_axis(e): | ||
z = e.Length | ||
else: | ||
Console.PrintWarning( | ||
'{} not parallel to x, y, or z axes\n'.format(e)) | ||
|
||
return Vector( | ||
x * origin_translation_offset.x, | ||
y * origin_translation_offset.y, | ||
z * origin_translation_offset.z | ||
) | ||
|
||
|
||
def get_edges_connected_to_vertex(vertex, edges): | ||
vertex_edges = [] | ||
for e in edges: | ||
for v in e.Vertexes: | ||
if v.isSame(vertex): | ||
vertex_edges.append(e) | ||
return vertex_edges |
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
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
Oops, something went wrong.