Skip to content

Commit

Permalink
Merge pull request #940 from shawnlaffan/issue_891_plot_polygons
Browse files Browse the repository at this point in the history
GUI: plot polygons
  • Loading branch information
shawnlaffan authored Jun 4, 2024
2 parents 046367f + a68f488 commit 433c100
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 77 deletions.
6 changes: 3 additions & 3 deletions bin/ui/wndOverlays.ui
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
Expand Down Expand Up @@ -121,13 +121,13 @@
</child>
<child>
<object class="GtkButton" id="btnDelete">
<property name="label">gtk-delete</property>
<property name="label">Remove</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="has_tooltip">True</property>
<property name="tooltip-text" translatable="yes">Delete selected file from the list</property>
<property name="tooltip-text" translatable="yes">Remove selected entry from the list</property>
<property name="use_stock">True</property>
</object>
<packing>
Expand Down
11 changes: 11 additions & 0 deletions lib/Biodiverse/GUI/GUIManager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ BEGIN {
gladexml => undef, # Main window widgets
tabs => [], # Stores refs to Tabs objects. In order of page index.
progress_bars => undef,
overlay_components => undef,
test_val => ''
};
bless $singleton, 'Biodiverse::GUI::GUIManager';
Expand Down Expand Up @@ -331,6 +332,16 @@ sub show_progress {
}
}

sub get_overlay_components {
my ($self) = @_;
return $self->{overlay_components};
}

sub set_overlay_components {
my ($self, $components) = @_;
$self->{overlay_components} = $components;
}

##########################################################
# Initialisation
##########################################################
Expand Down
35 changes: 26 additions & 9 deletions lib/Biodiverse/GUI/Grid.pm
Original file line number Diff line number Diff line change
Expand Up @@ -616,19 +616,21 @@ sub get_base_struct {

# Draws a polygonal shapefile
sub set_overlay {
my $self = shift;
my $shapefile = shift;
my $colour = shift || OVERLAY_COLOUR;
my ($self, %args) = @_;


# Delete any existing
if ($self->{shapefile_group}) {
$self->{shapefile_group}->destroy;
delete $self->{shapefile_group};
}

if ($shapefile) {
my @args = @{ $self->{dataset_info} };
$self->load_shapefile(@args, $shapefile, $colour);
if (defined $args{shapefile}) {
$self->load_shapefile(
colour => OVERLAY_COLOUR, # default
dataset_info => $self->{dataset_info},
%args,
);
}

return;
Expand All @@ -649,7 +651,13 @@ EOL
}

sub load_shapefile {
my ($self, $min_x, $min_y, $max_x, $max_y, $cell_x, $cell_y, $shapefile, $colour) = @_;
my ($self, %args) = @_;

my $info = $args{info} // $self->{dataset_info};
my ($min_x, $min_y, $max_x, $max_y, $cell_x, $cell_y) = @$info;
my $shapefile = $args{shapefile};
my $colour = $args{colour};
my $plot_as_poly = $args{plot_as_poly};

my @rect = (
$min_x - $cell_x,
Expand Down Expand Up @@ -691,7 +699,16 @@ sub load_shapefile {
y => 0,
);

$shapefile_group->raise_to_top();
my $is_polygon = $shapefile->shape_type_text =~ m/polygon/i;

my $canvas_shape_type = 'Gnome2::Canvas::Line';
if ($is_polygon && $plot_as_poly) {
$canvas_shape_type = 'Gnome2::Canvas::Polygon';
$shapefile_group->lower_to_bottom();
}
else {
$shapefile_group->raise_to_top();
}
$self->{shapefile_group} = $shapefile_group;

# Add all shapes
Expand Down Expand Up @@ -735,7 +752,7 @@ sub load_shapefile {
if (@plot_points > 2) { # must have more than one point (two coords)
my $poly = Gnome2::Canvas::Item->new (
$shapefile_group,
'Gnome2::Canvas::Line',
$canvas_shape_type,
points => \@plot_points,
fill_color_gdk => $colour,
);
Expand Down
Loading

0 comments on commit 433c100

Please sign in to comment.