Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI: plot polygons #940

Merged
merged 13 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading