def test_add_extrudes_by_target_face(self): r = self.client.set_target(self.couch_design_smt_file) self.assertIsNotNone(r, msg="set_target response is not None") self.assertEqual(r.status_code, 200, msg="set_target status code") response_json = r.json() graph = response_json["data"]["graph"] nodes = graph["nodes"] # Guessing these based on the order r = self.client.add_extrudes_by_target_face([{ "start_face": nodes[0]["id"], "end_face": nodes[9]["id"], "operation": "NewBodyFeatureOperation" }, { "start_face": nodes[1]["id"], "end_face": nodes[3]["id"], "operation": "CutFeatureOperation" }]) self.assertIsNotNone( r, msg="add_extrudes_by_target_face response is not None") self.assertEqual(r.status_code, 200, msg="add_extrudes_by_target_face status code") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data, has_iou=True)
def test_reconstruct_curves_extrude_image(self): self.client.clear() with open(self.hex_design_json_file) as file_handle: json_data = json.load(file_handle) sketch_id = json_data["timeline"][0]["entity"] sketch_data = json_data["entities"][sketch_id] del sketch_data["profiles"] del sketch_data["transform"] del sketch_data["reference_plane"] # Add sketch r = self.client.add_sketch("XY") self.assertEqual(r.status_code, 200, msg="add_sketch status code") response_json = r.json() response_data = response_json["data"] self.assertIn("sketch_name", response_data, msg="add_sketch response has sketch_name") sketch_name = response_data["sketch_name"] # Reconstruct all curves at once r = self.client.reconstruct_curves(sketch_data, sketch_name) self.assertIsNotNone(r, msg="reconstruct response is not None") self.assertEqual(r.status_code, 200, msg="reconstruct status code") response_json = r.json() response_data = response_json["data"] self.__test_sketch_response(response_data) # Pull out the first profile id profile_id = next(iter(response_data["profiles"])) self.assertIsInstance(profile_id, str, msg="profile_id is string") self.assertEqual(len(profile_id), 36, msg="profile_id length equals 36") # Extrude the first profile r = self.client.add_extrude(sketch_name, profile_id, 5.0, "NewBodyFeatureOperation") self.assertEqual(r.status_code, 200, msg="add_extrude status code") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data) # Export a screenshot test_screenshot_png_file = self.output_dir / "sketch_extrude.png" r = self.client.screenshot(test_screenshot_png_file, 512, 512) self.assertIsNotNone(r, msg="screenshot response is not None") self.assertEqual(r.status_code, 200, msg="screenshot status code") self.assertTrue(test_screenshot_png_file.exists(), msg="screenshot exists") self.assertGreater(test_screenshot_png_file.stat().st_size, 0, msg="screenshot file size greater than 0")
def test_set_target_add_extrude(self): # Set target box r = self.client.set_target(self.box_design_smt_file) self.assertIsNotNone(r, msg="set_target response is not None") self.assertEqual(r.status_code, 200, msg="set_target status code") response_json = r.json() common_test.check_graph_format(self, response_json["data"]) common_test.check_bounding_box(self, response_json["data"]) # Sketch r = self.client.add_sketch("XY") response_json = r.json() sketch_name = response_json["data"]["sketch_name"] self.assertIsInstance(sketch_name, str, msg="sketch_name is string") pts = [{ "x": -1, "y": 0 }, { "x": 1, "y": 0 }, { "x": 1, "y": 1 }, { "x": -1, "y": 1 }, { "x": -1, "y": 0 }] for index in range(4): r = self.client.add_line(sketch_name, pts[index], pts[index + 1]) self.assertEqual(r.status_code, 200, msg="add_line status code") response_json = r.json() response_data = response_json["data"] # Pull out the first profile id profile_id = next(iter(response_data["profiles"])) # Extrude r = self.client.add_extrude(sketch_name, profile_id, 1.0, "NewBodyFeatureOperation") self.assertEqual(r.status_code, 200, msg="add_extrude status code") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data, has_iou=True) self.assertAlmostEqual(response_data["iou"], 0.5, places=2, msg="iou ~= 0.5") r = self.client.clear()
def test_set_extrude_reset_extrude(self): r = self.client.set_target(self.box_design_smt_file) self.assertIsNotNone(r, msg="set_target response is not None") self.assertEqual(r.status_code, 200, msg="set_target status code") response_json = r.json() response_data = response_json["data"] graph = response_data["graph"] common_test.check_graph_format(self, response_data) # Make an extrude nodes = graph["nodes"] start_face = nodes[0]["id"] end_face = nodes[2]["id"] r = self.client.add_extrude_by_target_face(start_face, end_face, "NewBodyFeatureOperation") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data, has_iou=True) # Revert to target r = self.client.revert_to_target() self.assertIsNotNone(r, msg="revert_to_target response is not None") self.assertEqual(r.status_code, 200, msg="revert_to_target status code") response_json = r.json() response_data = response_json["data"] common_test.check_graph_format(self, response_data) revert_graph = response_data["graph"] self.assertDictEqual(graph, revert_graph, msg="target graph identical if reverted") start_face = nodes[0]["id"] end_face = nodes[2]["id"] r = self.client.add_extrude_by_target_face(start_face, end_face, "NewBodyFeatureOperation") self.assertIsNotNone( r, msg="add_extrude_by_target_face response is not None") self.assertEqual(r.status_code, 200, msg="add_extrude_by_target_face status code") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data, has_iou=True) self.assertAlmostEqual(response_data["iou"], 1, places=4, msg="iou ~= 1")
def test_add_extrude(self): self.client.clear() r = self.client.add_sketch("XY") response_json = r.json() sketch_name = response_json["data"]["sketch_name"] self.assertIsInstance(sketch_name, str, msg="sketch_name is string") pts = [{ "x": 0, "y": 0 }, { "x": 10, "y": 0 }, { "x": 10, "y": 10 }, { "x": 0, "y": 10 }, { "x": 0, "y": 0 }] for index in range(4): r = self.client.add_line(sketch_name, pts[index], pts[index + 1]) self.assertEqual(r.status_code, 200, msg="add_line status code") response_json = r.json() response_data = response_json["data"] # Pull out the first profile id profile_id = next(iter(response_data["profiles"])) self.assertIsInstance(profile_id, str, msg="profile_id is string") self.assertEqual(len(profile_id), 36, msg="profile_id length equals 36") # Extrude r = self.client.add_extrude(sketch_name, profile_id, 5.0, "NewBodyFeatureOperation") self.assertEqual(r.status_code, 200, msg="add_extrude status code") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data)
def test_add_extrudes_by_target_face_revert(self): r = self.client.set_target(self.couch_design_smt_file) self.assertIsNotNone(r, msg="set_target response is not None") self.assertEqual(r.status_code, 200, msg="set_target status code") response_json = r.json() response_data = response_json["data"] common_test.check_graph_format(self, response_data) # Multiple Extrudes graph = response_data["graph"] nodes = graph["nodes"] actions = [{ "start_face": nodes[0]["id"], "end_face": nodes[9]["id"], "operation": "NewBodyFeatureOperation" }, { "start_face": nodes[1]["id"], "end_face": nodes[3]["id"], "operation": "CutFeatureOperation" }] r = self.client.add_extrudes_by_target_face(actions) response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data, has_iou=True) prev_iou = response_data["iou"] # Reconstruct again but revert this time r = self.client.add_extrudes_by_target_face(actions, revert=True) self.assertIsNotNone( r, msg="add_extrudes_by_target_face response is not None") self.assertEqual(r.status_code, 200, msg="add_extrudes_by_target_face status code") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data, has_iou=True) self.assertEqual(response_data["iou"], prev_iou, msg="iou == prev_iou")
def test_add_extrude_by_target_face(self): r = self.client.set_target(self.box_design_smt_file) self.assertIsNotNone(r, msg="set_target response is not None") self.assertEqual(r.status_code, 200, msg="set_target status code") response_json = r.json() graph = response_json["data"]["graph"] nodes = graph["nodes"] # Guessing these based on the order start_face = nodes[0]["id"] end_face = nodes[2]["id"] r = self.client.add_extrude_by_target_face(start_face, end_face, "NewBodyFeatureOperation") self.assertIsNotNone( r, msg="add_extrude_by_target_face response is not None") self.assertEqual(r.status_code, 200, msg="add_extrude_by_target_face status code") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data, has_iou=True) self.assertAlmostEqual(response_data["iou"], 1, places=4, msg="iou ~= 1")
def test_add_three_point_close_extrude(self): self.client.clear() r = self.client.add_sketch("XY") response_json = r.json() response_data = response_json["data"] sketch_name = response_data["sketch_name"] pt1 = {"x": 0, "y": 0} pt2 = {"x": 0, "y": 10} pt3 = {"x": 10, "y": 10} r = self.client.add_point(sketch_name, pt1) r = self.client.add_point(sketch_name, pt2) r = self.client.add_point(sketch_name, pt3) r = self.client.close_profile(sketch_name) response_json = r.json() response_data = response_json["data"] profile_id = next(iter(response_data["profiles"])) # Extrude r = self.client.add_extrude(sketch_name, profile_id, 5.0, "NewBodyFeatureOperation") self.assertEqual(r.status_code, 200, msg="add_extrude status code") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data)
def test_add_line_world(self): self.client.clear() r = self.client.add_sketch("XY") response_json = r.json() sketch_name = response_json["data"]["sketch_name"] pts = [{ "x": 0, "y": 0 }, { "x": 10, "y": 0 }, { "x": 10, "y": 10 }, { "x": 0, "y": 10 }, { "x": 0, "y": 0 }] for index in range(4): r = self.client.add_line(sketch_name, pts[index], pts[index + 1]) response_json = r.json() response_data = response_json["data"] # Pull out the first profile id profile_id = next(iter(response_data["profiles"])) # Extrude r = self.client.add_extrude(sketch_name, profile_id, 10.0, "NewBodyFeatureOperation") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data) faces = response_data["extrude"]["faces"] # Start the second sketch with a point on the side face r = self.client.add_sketch({"x": 10.0, "y": 5.0, "z": 5.0}) response_json = r.json() sketch_name = response_json["data"]["sketch_name"] # Global points on the side face pts = [{ "x": 10.0, "y": 2.5, "z": 2.5 }, { "x": 10.0, "y": 2.5, "z": 7.5 }, { "x": 10.0, "y": 7.5, "z": 7.5 }, { "x": 10.0, "y": 7.5, "z": 2.5 }, { "x": 10.0, "y": 2.5, "z": 2.5 }] for index in range(4): r = self.client.add_line(sketch_name, pts[index], pts[index + 1], transform="world") response_json = r.json() response_data = response_json["data"] # Pull out the first profile id profile_id = next(iter(response_data["profiles"])) # Extrude2 r = self.client.add_extrude(sketch_name, profile_id, 2.0, "JoinFeatureOperation") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data)
def test_add_double_extrude_by_id(self): self.client.clear() # Create an empty sketch on the XY plane r = self.client.add_sketch("XY") # Get the unique name of the sketch created response_json = r.json() sketch_name = response_json["data"]["sketch_name"] # Add four lines to the sketch to make a square pts = [{ "x": 0, "y": 0 }, { "x": 10, "y": 0 }, { "x": 10, "y": 10 }, { "x": 0, "y": 10 }, { "x": 0, "y": 0 }] for index in range(4): r = self.client.add_line(sketch_name, pts[index], pts[index + 1]) # Pull out the first profile id response_json = r.json() response_data = response_json["data"] profile_id = next(iter(response_data["profiles"])) # Extrude by a given distance to make a new body r = self.client.add_extrude(sketch_name, profile_id, 5.0, "NewBodyFeatureOperation") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data) # Find the end face faces = response_data["extrude"]["faces"] for face in faces: if face["location_in_feature"] == "EndFace": xy_face = face # Create a second sketch on the end face r = self.client.add_sketch(xy_face["face_id"]) response_json = r.json() sketch_name = response_json["data"]["sketch_name"] # Draw the second smaller square pts = [{ "x": 2.5, "y": 2.5 }, { "x": 7.5, "y": 2.5 }, { "x": 7.5, "y": 7.5 }, { "x": 2.5, "y": 7.5 }, { "x": 2.5, "y": 2.5 }] for index in range(4): r = self.client.add_line(sketch_name, pts[index], pts[index + 1]) # Pull out the first profile id response_json = r.json() response_data = response_json["data"] profile_id = next(iter(response_data["profiles"])) # Extrude by a given distance, adding to the existing body r = self.client.add_extrude(sketch_name, profile_id, 2.0, "JoinFeatureOperation") response_json = r.json() response_data = response_json["data"] common_test.check_extrude_data(self, response_data)