def reconstruct_curve(self, data): """Reconstruct a single curve""" if (data is None or "sketch_data" not in data or "sketch_name" not in data or "curve_id" not in data): return self.runner.return_failure("reconstruct_curve data not specified") sketch_data = data["sketch_data"] sketch_name = data["sketch_name"] curve_id = data["curve_id"] # Optional transform transform = self.__get_transform(data) # Create the curve importer = SketchExtrudeImporter() sketch = importer.reconstruct_curve( sketch_data, sketch_name, curve_id, transform=transform, reconstruction=self.design_state.reconstruction.component ) # Serialize the data and return profile_data = serialize.sketch_profiles(sketch.profiles) return self.runner.return_success({ "sketch_name": sketch.name, "curve_id": curve_id, "profiles": profile_data })
def reconstruct_sketch(self, data): """Reconstruct a single sketch""" if (data is None or "sketch_data" not in data): return self.runner.return_failure("reconstruct_sketch data not specified") sketch_data = data["sketch_data"] # Optional sketch plane sketch_plane = None if "sketch_plane" in data: sketch_plane = match.sketch_plane(data["sketch_plane"]) # Optional transform transform = self.__get_transform(data) # Create the sketch importer = SketchExtrudeImporter() sketch = importer.reconstruct_sketch( sketch_data, sketch_plane=sketch_plane, transform=transform, reconstruction=self.design_state.reconstruction.component ) # Serialize the data and return profile_data = serialize.sketch_profiles(sketch.profiles) return self.runner.return_success({ "sketch_name": sketch.name, "profiles": profile_data })
def __add_circle(self, sketch, sketch_uuid, pt1, radius, transform=None): center_point = deserialize.point3d(pt1) if transform is not None: if isinstance(transform, str): # Transform world coords to sketch coords if transform.lower() == "world": center_point = sketch.modelToSketchSpace(center_point) elif isinstance(transform, dict): # For mapping Fusion exported data back correctly xform = deserialize.matrix3d(transform) sketch_transform = sketch.transform sketch_transform.invert() xform.transformBy(sketch_transform) center_point.transformBy(xform) circle = sketch.sketchCurves.sketchCircles.addByCenterRadius( center_point, radius) curve_uuid = name.set_uuid(circle) name.set_uuids_for_sketch(sketch) profile_data = serialize.sketch_profiles(sketch.profiles) return self.runner.return_success({ "sketch_id": sketch_uuid, "sketch_name": sketch.name, "curve_id": curve_uuid, "profiles": profile_data })
def __add_arc(self, sketch, sketch_uuid, pt1, pt2, angle_degrees, transform=None): start_point = deserialize.point3d(pt1) center_point = deserialize.point3d(pt2) angle_radians = math.radians(angle_degrees) if transform is not None: if isinstance(transform, str): # Transform world coords to sketch coords if transform.lower() == "world": start_point = sketch.modelToSketchSpace(start_point) center_point = sketch.modelToSketchSpace(center_point) elif isinstance(transform, dict): # For mapping Fusion exported data back correctly xform = deserialize.matrix3d(transform) sketch_transform = sketch.transform sketch_transform.invert() xform.transformBy(sketch_transform) start_point.transformBy(xform) center_point.transformBy(xform) arc = sketch.sketchCurves.sketchArcs.addByCenterStartSweep( center_point, start_point, angle_radians) end_point = serialize.point3d(arc.endSketchPoint.geometry) curve_uuid = name.set_uuid(arc) name.set_uuids_for_sketch(sketch) profile_data = serialize.sketch_profiles(sketch.profiles) if sketch.name not in self.state: self.__init_sketch_state(sketch.name, pt1, end_point, transform=transform) else: self.__inc_sketch_state(sketch.name, end_point, transform=transform) return self.runner.return_success({ "sketch_id": sketch_uuid, "sketch_name": sketch.name, "curve_id": curve_uuid, "profiles": profile_data })
def add_point(self, data): """Add a point to create a new sequential line in the given sketch""" if (data is None or "sketch_name" not in data or "pt" not in data): return self.runner.return_failure("add_point data not specified") sketch = match.sketch_by_name( data["sketch_name"], sketches=self.design_state.reconstruction.component.sketches) if sketch is None: return self.runner.return_failure("sketch not found") sketch_uuid = name.get_uuid(sketch) # If this is the first point, store it and return if sketch.name not in self.state: self.__init_sketch_state(sketch.name, data["pt"], data["pt"]) profile_data = serialize.sketch_profiles(sketch.profiles) return self.runner.return_success({ "sketch_id": sketch_uuid, "sketch_name": sketch.name, "profiles": profile_data }) state = self.state[sketch.name] transform = data["transform"] if "transform" in data else None return self.__add_line(sketch, sketch_uuid, state["last_pt"], data["pt"], transform)
def __add_line(self, sketch, sketch_uuid, pt1, pt2, transform=None): start_point = deserialize.point3d(pt1) end_point = deserialize.point3d(pt2) if transform is not None: if isinstance(transform, str): # Transform world coords to sketch coords if transform.lower() == "world": start_point = sketch.modelToSketchSpace(start_point) end_point = sketch.modelToSketchSpace(end_point) elif isinstance(transform, dict): # For mapping Fusion exported data back correctly xform = deserialize.matrix3d(transform) sketch_transform = sketch.transform sketch_transform.invert() xform.transformBy(sketch_transform) start_point.transformBy(xform) end_point.transformBy(xform) line = sketch.sketchCurves.sketchLines.addByTwoPoints( start_point, end_point) curve_uuid = name.set_uuid(line) name.set_uuids_for_sketch(sketch) profile_data = serialize.sketch_profiles(sketch.profiles) if sketch.name not in self.state: self.__init_sketch_state(sketch.name, pt1, pt2, transform=transform) else: self.__inc_sketch_state(sketch.name, pt2, transform=transform) return self.runner.return_success({ "sketch_id": sketch_uuid, "sketch_name": sketch.name, "curve_id": curve_uuid, "profiles": profile_data })