예제 #1
0
 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
예제 #2
0
    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)
예제 #3
0
 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
예제 #4
0
 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
예제 #5
0
 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
예제 #6
0
    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
예제 #7
0
 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
예제 #8
0
 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
예제 #9
0
    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
예제 #10
0
    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)
예제 #11
0
    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)
예제 #12
0
 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
예제 #13
0
 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
예제 #14
0
    def load_drawing_from_data(self, object_data: Dict[str, Any]) -> Drawing:
        # TODO: Maybe move this stuff into the classes and load_from_dict?

        prim_type = object_data["primitiveType"]
        visible = object_data["visible"]
        color = Rgba.from_color_string(object_data["colorString"])
        layer_name = object_data["layerName"]
        name = object_data["name"]
        mapX: float = object_data["mapX"]
        mapY: float = object_data["mapY"]
        position = Point(mapX, mapY, self._terrain)

        if prim_type == "Line":
            closed = object_data["closed"]
            line_thickness = object_data["thickness"]
            line_style = LineStyle(object_data["style"])
            line_mode = LineMode(object_data["lineMode"])
            points = self.load_points_from_data(object_data["points"])
            return LineDrawing(
                visible,
                position,
                name,
                color,
                layer_name,
                closed,
                line_thickness,
                line_style,
                line_mode,
                points,
            )
        elif prim_type == "Icon":
            file = object_data["file"]
            scale = object_data["scale"]
            angle = object_data["angle"]
            return Icon(visible, position, name, color, layer_name, file,
                        scale, angle)
        elif prim_type == "Polygon":
            polygon_mode = PolygonMode(object_data["polygonMode"])
            fill = Rgba.from_color_string(object_data["fillColorString"])
            line_thickness = object_data["thickness"]
            line_style = LineStyle(object_data["style"])

            if polygon_mode == PolygonMode.Circle:
                radius = object_data["radius"]
                return Circle(
                    visible,
                    position,
                    name,
                    color,
                    layer_name,
                    fill,
                    line_thickness,
                    line_style,
                    radius,
                )
            elif polygon_mode == PolygonMode.Oval:
                radius1 = object_data["r1"]
                radius2 = object_data["r2"]
                angle = object_data["angle"]
                return Oval(
                    visible,
                    position,
                    name,
                    color,
                    layer_name,
                    fill,
                    line_thickness,
                    line_style,
                    radius1,
                    radius2,
                    angle,
                )
            elif polygon_mode == PolygonMode.Rectangle:
                width = object_data["width"]
                height = object_data["height"]
                angle = object_data["angle"]
                return Rectangle(
                    visible,
                    position,
                    name,
                    color,
                    layer_name,
                    fill,
                    line_thickness,
                    line_style,
                    width,
                    height,
                    angle,
                )
            elif polygon_mode == PolygonMode.Free:
                points = self.load_points_from_data(object_data["points"])
                return FreeFormPolygon(
                    visible,
                    position,
                    name,
                    color,
                    layer_name,
                    fill,
                    line_thickness,
                    line_style,
                    points,
                )
            elif polygon_mode == PolygonMode.Arrow:
                angle = object_data["angle"]
                length = object_data["length"]
                points = self.load_points_from_data(object_data["points"])
                return Arrow(
                    visible,
                    position,
                    name,
                    color,
                    layer_name,
                    fill,
                    line_thickness,
                    line_style,
                    length,
                    angle,
                    points,
                )
        elif prim_type == "TextBox":
            text = object_data["text"]
            font_size = object_data["fontSize"]
            font = object_data["font"]
            border_thickness = object_data["borderThickness"]
            fill = Rgba.from_color_string(object_data["fillColorString"])
            angle = object_data["angle"]
            return TextBox(
                visible,
                position,
                name,
                color,
                layer_name,
                text,
                font_size,
                font,
                border_thickness,
                fill,
                angle,
            )
        raise RuntimeError(f"Unknown primitive type for layer: {prim_type}")