Skip to content

Commit

Permalink
fix: when creating markers from an SVG file, the proposed marker coun…
Browse files Browse the repository at this point in the history
…t should be decreased by the number of markers that already exist
  • Loading branch information
ntamas committed Jul 14, 2023
1 parent eaa0248 commit 08b4d76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from sbstudio.api.errors import SkybrushStudioAPIError
from sbstudio.plugin.api import get_api
from sbstudio.plugin.selection import Collections

from .base import StaticMarkerCreationOperator, PointsAndColors

Expand Down Expand Up @@ -57,10 +56,7 @@ class AddMarkersFromSVGOperator(StaticMarkerCreationOperator, ImportHelper):
filename_ext = ".svg"

def invoke(self, context, event):
drones = Collections.find_drones(create=False)
if drones:
self.count = len(drones.objects)

self.count = self._propose_marker_count(context)
context.window_manager.fileselect_add(self)
return {"RUNNING_MODAL"}

Expand Down
21 changes: 20 additions & 1 deletion src/modules/sbstudio/plugin/operators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
from numpy.typing import NDArray

from sbstudio.plugin.errors import StoryboardValidationError
from sbstudio.plugin.model.formation import add_points_to_formation
from sbstudio.plugin.model.formation import (
add_points_to_formation,
get_markers_from_formation,
)
from sbstudio.plugin.selection import select_only
from sbstudio.plugin.selection import Collections


class FormationOperator(Operator):
Expand Down Expand Up @@ -185,3 +189,18 @@ def execute_on_formation(self, formation, context):
def _create_points(self, context) -> PointsAndColors:
"""Creates the points where the markers should be placed."""
raise NotImplementedError

def _propose_marker_count(self, context) -> int:
"""Calculates how many markers we need to add to the currently selected
formation in order to make it have exactly the same number of markers
as the number of drones in the project.
"""
drones = Collections.find_drones(create=False)
num_drones = len(drones.objects) if drones else 0
if num_drones > 0:
num_existing_markers = len(
get_markers_from_formation(context.scene.skybrush.formations.selected)
)
else:
num_existing_markers = 0
return max(0, num_drones - num_existing_markers)

0 comments on commit 08b4d76

Please sign in to comment.