-
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 (work in progress)
- Loading branch information
Showing
5 changed files
with
153 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
from math import degrees | ||
|
||
import Part | ||
from FreeCAD import Vector, Console | ||
|
||
|
||
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 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} | ||
opposite_orientations = filter( | ||
lambda item: item[0] != axis, index_by_axis.items()) | ||
a_index, b_index = map(lambda item: item[1], opposite_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 | ||
|
||
|
||
def get_vertex_edges(vertex, edges): | ||
vertex_edges = [] | ||
for e in edges: | ||
for v in e.Vertexes: | ||
if v.isSame(vertex): | ||
vertex_edges.append(e) | ||
return vertex_edges | ||
|
||
|
||
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_vertex_edges(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 | ||
) |
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
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
11 changes: 8 additions & 3 deletions
11
ose3dprinter/workbench/part/heated_bed/create_heated_bed.py
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 |
---|---|---|
@@ -1,12 +1,17 @@ | ||
from FreeCAD import Placement, Vector | ||
from ose3dprinter.core.model import HeatedBedModel | ||
|
||
|
||
def create_heated_bed(document, name): | ||
def create_heated_bed(document, | ||
name, | ||
placement=Placement(), | ||
origin_translation_offset=Vector()): | ||
""" | ||
Creates a heated bed object with the given name, | ||
and adds it to the document. | ||
""" | ||
obj = document.addObject('Part::FeaturePython', name) | ||
HeatedBedModel(obj) | ||
obj.ViewObject.Proxy = 0 # Mandatory unless ViewProvider is coded | ||
HeatedBedModel(obj, placement, origin_translation_offset) | ||
if obj.ViewObject is not None: | ||
obj.ViewObject.Proxy = 0 # Mandatory unless ViewProvider is coded | ||
return obj |