def test_add_drawings_to_loaded_mission(self) -> None: m: Mission = dcs.mission.Mission() self.assertEqual(0, len(m.load_file('tests/missions/Draw_tool_test.miz'))) circle = Circle( True, Point(10, 10, m.terrain), "TEST CIRCLE", Rgba(20, 30, 40, 200), ":S", Rgba(50, 60, 70, 150), 10, LineStyle.Solid, 100 ) m.drawings.layers[0].add_drawing(circle) self.assertEqual("TEST CIRCLE", m.drawings.layers[0].objects[1].name) mission_path = 'missions/Draw_tool_test_added_drawings.miz' m.save(mission_path) m2 = dcs.mission.Mission() self.assertEqual(0, len(m2.load_file(mission_path))) self.assert_expected_stuff(m2) self.assertEqual("TEST CIRCLE", m2.drawings.layers[0].objects[1].name)
def add_oval( self, position: Point, radius1: float, radius2: float, color=Rgba(255, 0, 0, 255), fill=Rgba(255, 0, 0, 60), line_thickness=8, line_style=LineStyle.Solid, angle=0, ) -> Oval: drawing = Oval( True, position, "An oval", color, self.name, fill, line_thickness, line_style, radius1, radius2, angle, ) self.add_drawing(drawing) return drawing
def add_arrow( self, position: Point, angle: float, length: float, color=Rgba(255, 0, 0, 255), fill=Rgba(255, 0, 0, 255), line_thickness=8, line_style=LineStyle.Solid, ) -> Arrow: drawing = Arrow( True, position, "An arrow", color, self.name, fill, line_thickness, line_style, length, angle, Arrow.get_default_arrow_points(self._terrain), ) self.add_drawing(drawing) return drawing
def add_rectangle( self, position: Point, width: float, height: float, color=Rgba(255, 0, 0, 255), fill=Rgba(255, 0, 0, 60), line_thickness=8, line_style=LineStyle.Solid, angle=0, ) -> Rectangle: drawing = Rectangle( True, position, "A rectangle", color, self.name, fill, line_thickness, line_style, width, height, angle, ) self.add_drawing(drawing) return drawing
def add_text_box( self, position: Point, text: str, color=Rgba(255, 0, 0, 255), fill=Rgba(255, 0, 0, 60), font_size=20, font="DejaVuLGCSansCondensed.ttf", border_thickness=2, angle=0, ) -> TextBox: drawing = TextBox( True, position, "A text box", color, self.name, text, font_size, font, border_thickness, fill, angle, ) self.add_drawing(drawing) return drawing
def add_oblong( self, p1: Point, p2: Point, radius: float, color=Rgba(255, 0, 0, 255), fill=Rgba(255, 0, 0, 60), line_thickness=4, line_style=LineStyle.Solid, resolution=20, ) -> FreeFormPolygon: hdg_p1_p2 = p1.heading_between_point(p2) points: List[Point] = [] for i in range(0, resolution + 1): hdg = hdg_p1_p2 - 90 + i * (180 / resolution) points.append(p2.point_from_heading(hdg, radius)) for i in range(0, resolution + 1): hdg = hdg_p1_p2 + 90 + i * (180 / resolution) points.append(p1.point_from_heading(hdg, radius)) # Copy first point and insert last to close the polygon points.append(points[0] * 1) # Transform points to local coordinates startPoint = points[0] * 1 # Copy for point in points: point.x -= startPoint.x point.y -= startPoint.y polygon = self.add_freeform_polygon( startPoint, points, color=color, fill=fill, line_thickness=line_thickness, line_style=line_style, ) return polygon
def add_freeform_polygon( self, position: Point, points: List[Point], color=Rgba(255, 0, 0, 255), fill=Rgba(255, 0, 0, 60), line_thickness=8, line_style=LineStyle.Solid, ) -> FreeFormPolygon: drawing = FreeFormPolygon( True, position, "A freeform polygon", color, self.name, fill, line_thickness, line_style, points, ) self.add_drawing(drawing) return drawing
def add_circle( self, position: Point, radius: float, color=Rgba(255, 0, 0, 255), fill=Rgba(255, 0, 0, 60), line_thickness=8, line_style=LineStyle.Solid, ) -> Circle: drawing = Circle( True, position, "A circle", color, self.name, fill, line_thickness, line_style, radius, ) self.add_drawing(drawing) return drawing
def add_icon(self, position: Point, file: Union[str, StandardIcon], scale=1.0, color=Rgba(255, 0, 0, 255)) -> Icon: if isinstance(file, StandardIcon): file_str = file.value else: file_str = file drawing = Icon(True, position, "An icon", color, self.name, file_str, scale, 0) self.add_drawing(drawing) return drawing
def test_add_drawings_to_new_mission(self) -> None: m: Mission = dcs.mission.Mission() circle = Circle( True, Point(10, 10, m.terrain), "TEST CIRCLE", Rgba(20, 30, 40, 200), ":S", Rgba(50, 60, 70, 150), 10, LineStyle.Solid, 100 ) red_layer = m.drawings.get_layer(StandardLayer.Red) red_layer.add_drawing(circle) red_layer.add_line_segments( Point(1, 1, m.terrain), [Point(6, 6, m.terrain), Point(7, 7, m.terrain)], closed=True, ) m.drawings.options.hiddenOnF10Map["Pilot"]["Red"] = True m.drawings.options.hiddenOnF10Map["Instructor"]["Blue"] = True m.drawings.options.hiddenOnF10Map["Observer"]["Neutral"] = True mission_path = 'missions/New_mission_w_added_drawings.miz' m.save(mission_path) m2 = dcs.mission.Mission() self.assertEqual(0, len(m2.load_file(mission_path))) red_layer2 = m2.drawings.get_layer(StandardLayer.Red) self.assertEqual("TEST CIRCLE", red_layer2.objects[0].name) self.assertEqual("A line", red_layer2.objects[1].name) self.assertEqual(True, red_layer2.objects[1].closed) self.assertEqual("Red", red_layer2.objects[0].layer_name) self.assertEqual("Red", red_layer2.objects[1].layer_name)
def assert_expected_stuff(self, m: Mission) -> None: self.assertEqual(5, len(m.drawings.layers)) self.assertEqual(False, m.drawings.options.hiddenOnF10Map["Observer"]["Neutral"]) red_layer = m.drawings.get_layer(StandardLayer.Red) self.assertEqual(True, red_layer.visible) self.assertEqual("Red", red_layer.name) self.assertEqual("Icon 2", red_layer.objects[0].name) line = m.drawings.get_layer(StandardLayer.Blue).objects[0] self.assertEqual("Line 2 segments closed", line.name) self.assertEqual(Rgba(255, 255, 0, 131), line.color) self.assertEqual(-260885.56415634, line.position.x) self.assertEqual(671996.90379981, line.position.y) self.assertEqual(0, line.points[0].x) self.assertEqual(0, line.points[0].y) self.assertEqual(-6076.521389334, line.points[2].x) self.assertEqual(3038.260694667, line.points[2].y)
def add_line_freeform( self, position: Point, points: List[Point], color=Rgba(255, 0, 0, 255), line_thickness=8, line_style=LineStyle.Solid, closed=False, ) -> LineDrawing: drawing = LineDrawing( True, position, "A line", color, self.name, closed, line_thickness, line_style, LineMode.Free, points, ) self.add_drawing(drawing) return drawing
def add_line_segment( self, position: Point, end_point: Point, color=Rgba(255, 0, 0, 255), line_thickness=8, line_style=LineStyle.Solid, ) -> LineDrawing: points = [Point(0, 0, self._terrain), end_point] drawing = LineDrawing( True, position, "A line", color, self.name, False, line_thickness, line_style, LineMode.Segment, points, ) self.add_drawing(drawing) return drawing