gimppdb-utils.c 19.4 KB
Newer Older
1 2 3
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21
 */

#include "config.h"

#include <string.h>

22
#include <gegl.h>
23 24 25 26 27 28 29

#include "pdb-types.h"

#include "core/gimp.h"
#include "core/gimpbrushgenerated.h"
#include "core/gimpcontainer.h"
#include "core/gimpdatafactory.h"
30
#include "core/gimpdrawable.h"
31
#include "core/gimpimage.h"
32
#include "core/gimpitem.h"
33

34 35
#include "text/gimptextlayer.h"

36 37
#include "vectors/gimpvectors.h"

38 39 40 41 42 43
#include "gimppdb-utils.h"
#include "gimppdberror.h"

#include "gimp-intl.h"


44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
static GimpObject *
gimp_pdb_get_data_factory_item (GimpDataFactory *data_factory,
                                const gchar     *name)
{
  GimpObject *gimp_object;

  gimp_object = gimp_container_get_child_by_name (gimp_data_factory_get_container (data_factory), name);

  if (! gimp_object)
    gimp_object = gimp_container_get_child_by_name (gimp_data_factory_get_container_obsolete (data_factory), name);

  return gimp_object;
}


59 60 61 62 63 64 65 66 67 68 69 70 71
GimpBrush *
gimp_pdb_get_brush (Gimp         *gimp,
                    const gchar  *name,
                    gboolean      writable,
                    GError      **error)
{
  GimpBrush *brush;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (! name || ! strlen (name))
    {
72
      g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
73
			   _("Invalid empty brush name"));
74 75 76
      return NULL;
    }

77
  brush = (GimpBrush *) gimp_pdb_get_data_factory_item (gimp->brush_factory, name);
78 79 80

  if (! brush)
    {
81
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
82 83
                   _("Brush '%s' not found"), name);
    }
84
  else if (writable && ! gimp_data_is_writable (GIMP_DATA (brush)))
85
    {
86
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
                   _("Brush '%s' is not editable"), name);
      return NULL;
    }

  return brush;
}

GimpBrush *
gimp_pdb_get_generated_brush (Gimp         *gimp,
                              const gchar  *name,
                              gboolean      writable,
                              GError      **error)
{
  GimpBrush *brush;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  brush = gimp_pdb_get_brush (gimp, name, writable, error);

  if (! brush)
    return NULL;

  if (! GIMP_IS_BRUSH_GENERATED (brush))
    {
112
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
113 114 115 116 117 118 119
                   _("Brush '%s' is not a generated brush"), name);
      return NULL;
    }

  return brush;
}

120 121 122 123 124 125 126 127 128 129 130 131 132
GimpDynamics *
gimp_pdb_get_dynamics (Gimp         *gimp,
                       const gchar  *name,
                       gboolean      writable,
                       GError      **error)
{
  GimpDynamics *dynamics;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (! name || ! strlen (name))
    {
133
      g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
134 135 136 137 138 139 140 141
			   _("Invalid empty paint dynamics name"));
      return NULL;
    }

  dynamics = (GimpDynamics *) gimp_pdb_get_data_factory_item (gimp->dynamics_factory, name);

  if (! dynamics)
    {
142
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
143 144 145 146
                   _("Paint dynamics '%s' not found"), name);
    }
  else if (writable && ! gimp_data_is_writable (GIMP_DATA (dynamics)))
    {
147
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
148 149 150 151 152 153 154
                   _("Paint dynamics '%s' is not editable"), name);
      return NULL;
    }

  return dynamics;
}

155 156 157 158 159 160 161 162 163 164 165 166
GimpPattern *
gimp_pdb_get_pattern (Gimp         *gimp,
                      const gchar  *name,
                      GError      **error)
{
  GimpPattern *pattern;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (! name || ! strlen (name))
    {
167
      g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
168
			   _("Invalid empty pattern name"));
169 170 171
      return NULL;
    }

172
  pattern = (GimpPattern *) gimp_pdb_get_data_factory_item (gimp->pattern_factory, name);
173 174 175

  if (! pattern)
    {
176
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
                   _("Pattern '%s' not found"), name);
    }

  return pattern;
}

GimpGradient *
gimp_pdb_get_gradient (Gimp         *gimp,
                       const gchar  *name,
                       gboolean      writable,
                       GError      **error)
{
  GimpGradient *gradient;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (! name || ! strlen (name))
    {
196
      g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
197
			   _("Invalid empty gradient name"));
198 199 200
      return NULL;
    }

201
  gradient = (GimpGradient *) gimp_pdb_get_data_factory_item (gimp->gradient_factory, name);
202 203 204

  if (! gradient)
    {
205
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
206 207
                   _("Gradient '%s' not found"), name);
    }
208
  else if (writable && ! gimp_data_is_writable (GIMP_DATA (gradient)))
209
    {
210
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
                   _("Gradient '%s' is not editable"), name);
      return NULL;
    }

  return gradient;
}

GimpPalette *
gimp_pdb_get_palette (Gimp         *gimp,
                      const gchar  *name,
                      gboolean      writable,
                      GError      **error)
{
  GimpPalette *palette;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (! name || ! strlen (name))
    {
231
      g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
232
			   _("Invalid empty palette name"));
233 234 235
      return NULL;
    }

236
  palette = (GimpPalette *) gimp_pdb_get_data_factory_item (gimp->palette_factory, name);
237 238 239

  if (! palette)
    {
240
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
241 242
                   _("Palette '%s' not found"), name);
    }
243
  else if (writable && ! gimp_data_is_writable (GIMP_DATA (palette)))
244
    {
245
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
                   _("Palette '%s' is not editable"), name);
      return NULL;
    }

  return palette;
}

GimpFont *
gimp_pdb_get_font (Gimp         *gimp,
                   const gchar  *name,
                   GError      **error)
{
  GimpFont *font;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (! name || ! strlen (name))
    {
265
      g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
266
			   _("Invalid empty font name"));
267 268 269 270 271 272 273 274
      return NULL;
    }

  font = (GimpFont *)
    gimp_container_get_child_by_name (gimp->fonts, name);

  if (! font)
    {
275
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
                   _("Font '%s' not found"), name);
    }

  return font;
}

GimpBuffer *
gimp_pdb_get_buffer (Gimp         *gimp,
                     const gchar  *name,
                     GError      **error)
{
  GimpBuffer *buffer;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (! name || ! strlen (name))
    {
294
      g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
295
			   _("Invalid empty buffer name"));
296 297 298 299 300 301 302 303
      return NULL;
    }

  buffer = (GimpBuffer *)
    gimp_container_get_child_by_name (gimp->named_buffers, name);

  if (! buffer)
    {
304
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
                   _("Named buffer '%s' not found"), name);
    }

  return buffer;
}

GimpPaintInfo *
gimp_pdb_get_paint_info (Gimp         *gimp,
                         const gchar  *name,
                         GError      **error)
{
  GimpPaintInfo *paint_info;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (! name || ! strlen (name))
    {
323
      g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
324
			   _("Invalid empty paint method name"));
325 326 327 328 329 330 331 332
      return NULL;
    }

  paint_info = (GimpPaintInfo *)
    gimp_container_get_child_by_name (gimp->paint_info_list, name);

  if (! paint_info)
    {
333
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
334 335 336 337 338
                   _("Paint method '%s' does not exist"), name);
    }

  return paint_info;
}
339 340 341

gboolean
gimp_pdb_item_is_attached (GimpItem  *item,
342
                           GimpImage *image,
343
                           gboolean   writable,
344 345 346
                           GError   **error)
{
  g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
347
  g_return_val_if_fail (image == NULL || GIMP_IS_IMAGE (image), FALSE);
348 349
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

350 351
  if (! gimp_item_is_attached (item))
    {
352
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
353
                   _("Item '%s' (%d) cannot be used because it has not "
354
                     "been added to an image"),
355
                   gimp_object_get_name (item),
356 357 358
                   gimp_item_get_ID (item));
      return FALSE;
    }
359

360 361
  if (image && image != gimp_item_get_image (item))
    {
362
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
363
                   _("Item '%s' (%d) cannot be used because it is "
364 365 366 367 368 369
                     "attached to another image"),
                   gimp_object_get_name (item),
                   gimp_item_get_ID (item));
      return FALSE;
    }

370 371 372
  if (writable)
    return gimp_pdb_item_is_writable (item, error);

373
  return TRUE;
374 375
}

376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
gboolean
gimp_pdb_item_is_in_tree (GimpItem   *item,
                          GimpImage  *image,
                          gboolean    writable,
                          GError    **error)
{
  g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
  g_return_val_if_fail (image == NULL || GIMP_IS_IMAGE (image), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  if (! gimp_pdb_item_is_attached (item, image, writable, error))
    return FALSE;

  if (! gimp_item_get_tree (item))
    {
391
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
392
                   _("Item '%s' (%d) cannot be used because it is not "
393 394 395 396 397 398 399 400 401
                     "a direct child of an item tree"),
                   gimp_object_get_name (item),
                   gimp_item_get_ID (item));
      return FALSE;
    }

  return TRUE;
}

402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
gboolean
gimp_pdb_item_is_in_same_tree (GimpItem   *item,
                               GimpItem   *item2,
                               GimpImage  *image,
                               GError    **error)
{
  g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
  g_return_val_if_fail (GIMP_IS_ITEM (item2), FALSE);
  g_return_val_if_fail (image == NULL || GIMP_IS_IMAGE (image), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  if (! gimp_pdb_item_is_in_tree (item, image, FALSE, error) ||
      ! gimp_pdb_item_is_in_tree (item2, image, FALSE, error))
    return FALSE;

  if (gimp_item_get_tree (item) != gimp_item_get_tree (item2))
    {
419
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
                   _("Items '%s' (%d) and '%s' (%d) cannot be used "
                     "because they are not part of the same item tree"),
                   gimp_object_get_name (item),
                   gimp_item_get_ID (item),
                   gimp_object_get_name (item2),
                   gimp_item_get_ID (item2));
      return FALSE;
    }

  return TRUE;
}

gboolean
gimp_pdb_item_is_not_ancestor (GimpItem  *item,
                               GimpItem  *not_descendant,
                               GError   **error)
{
  g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
  g_return_val_if_fail (GIMP_IS_ITEM (not_descendant), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  if (gimp_viewable_is_ancestor (GIMP_VIEWABLE (item),
                                 GIMP_VIEWABLE (not_descendant)))
    {
444
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
445 446 447 448 449 450 451 452 453 454 455 456
                   _("Item '%s' (%d) must not be an ancestor of "
                     "'%s' (%d)"),
                   gimp_object_get_name (item),
                   gimp_item_get_ID (item),
                   gimp_object_get_name (not_descendant),
                   gimp_item_get_ID (not_descendant));
      return FALSE;
    }

  return TRUE;
}

457 458
gboolean
gimp_pdb_item_is_floating (GimpItem  *item,
459
                           GimpImage *dest_image,
460 461 462
                           GError   **error)
{
  g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
463
  g_return_val_if_fail (GIMP_IS_IMAGE (dest_image), FALSE);
464 465
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

466 467
  if (! g_object_is_floating (item))
    {
468
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
469
                   _("Item '%s' (%d) has already been added to an image"),
470
                   gimp_object_get_name (item),
471 472 473 474 475
                   gimp_item_get_ID (item));
      return FALSE;
    }
  else if (gimp_item_get_image (item) != dest_image)
    {
476
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
477
                   _("Trying to add item '%s' (%d) to wrong image"),
478
                   gimp_object_get_name (item),
479 480 481
                   gimp_item_get_ID (item));
      return FALSE;
    }
482

483
  return TRUE;
484
}
485

486 487 488 489 490 491 492
gboolean
gimp_pdb_item_is_writable (GimpItem  *item,
                           GError   **error)
{
  g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

493
  if (gimp_item_is_content_locked (item))
494
    {
495
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
496 497
                   _("Item '%s' (%d) cannot be modified because its "
                     "contents are locked"),
498
                   gimp_object_get_name (item),
499 500 501 502 503 504 505
                   gimp_item_get_ID (item));
      return FALSE;
    }

  return TRUE;
}

506 507 508 509 510 511 512 513 514
gboolean
gimp_pdb_item_is_group (GimpItem  *item,
                        GError   **error)
{
  g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  if (! gimp_viewable_get_children (GIMP_VIEWABLE (item)))
    {
515
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
516 517 518 519 520 521 522 523 524 525
                   _("Item '%s' (%d) cannot be used because it is "
                     "not a group item"),
                   gimp_object_get_name (item),
                   gimp_item_get_ID (item));
      return FALSE;
    }

  return TRUE;
}

526 527 528 529 530 531 532 533 534
gboolean
gimp_pdb_item_is_not_group (GimpItem  *item,
                            GError   **error)
{
  g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  if (gimp_viewable_get_children (GIMP_VIEWABLE (item)))
    {
535
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
536 537
                   _("Item '%s' (%d) cannot be modified because it "
                     "is a group item"),
538
                   gimp_object_get_name (item),
539 540 541 542 543 544 545
                   gimp_item_get_ID (item));
      return FALSE;
    }

  return TRUE;
}

546 547
gboolean
gimp_pdb_layer_is_text_layer (GimpLayer  *layer,
548
                              gboolean    writable,
549 550 551 552 553
                              GError    **error)
{
  g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

554
  if (! gimp_item_is_text_layer (GIMP_ITEM (layer)))
555
    {
556
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
557
                   _("Layer '%s' (%d) cannot be used because it is not "
558
                     "a text layer"),
559
                   gimp_object_get_name (layer),
560 561 562 563 564
                   gimp_item_get_ID (GIMP_ITEM (layer)));

      return FALSE;
    }

565
  return gimp_pdb_item_is_attached (GIMP_ITEM (layer), NULL, writable, error);
566 567
}

568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
static const gchar *
gimp_pdb_enum_value_get_nick (GType enum_type,
                              gint  value)
{
  GEnumClass  *enum_class;
  GEnumValue  *enum_value;
  const gchar *nick;

  enum_class = g_type_class_ref (enum_type);
  enum_value = g_enum_get_value (enum_class, value);

  nick = enum_value->value_nick;

  g_type_class_unref (enum_class);

  return nick;
}

gboolean
gimp_pdb_image_is_base_type (GimpImage          *image,
                             GimpImageBaseType   type,
                             GError            **error)
{
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  if (gimp_image_base_type (image) == type)
    return TRUE;

597
  g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
Sven Neumann's avatar
Sven Neumann committed
598 599
               _("Image '%s' (%d) is of type '%s', "
                 "but an image of type '%s' is expected"),
600
               gimp_image_get_display_name (image),
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
               gimp_image_get_ID (image),
               gimp_pdb_enum_value_get_nick (GIMP_TYPE_IMAGE_BASE_TYPE,
                                             gimp_image_base_type (image)),
               gimp_pdb_enum_value_get_nick (GIMP_TYPE_IMAGE_BASE_TYPE, type));

  return FALSE;
}

gboolean
gimp_pdb_image_is_not_base_type (GimpImage          *image,
                                 GimpImageBaseType   type,
                                 GError            **error)
{
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  if (gimp_image_base_type (image) != type)
    return TRUE;

620
  g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
Sven Neumann's avatar
Sven Neumann committed
621
               _("Image '%s' (%d) is already of type '%s'"),
622
               gimp_image_get_display_name (image),
623 624 625 626 627
               gimp_image_get_ID (image),
               gimp_pdb_enum_value_get_nick (GIMP_TYPE_IMAGE_BASE_TYPE, type));

  return FALSE;
}
628

629 630 631
GimpStroke *
gimp_pdb_get_vectors_stroke (GimpVectors  *vectors,
                             gint          stroke_ID,
632
                             gboolean      writable,
633 634
                             GError      **error)
{
635
  GimpStroke *stroke = NULL;
636 637 638 639

  g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

640 641 642
  if (! gimp_pdb_item_is_not_group (GIMP_ITEM (vectors), error))
    return NULL;

643
  if (! writable || gimp_pdb_item_is_writable (GIMP_ITEM (vectors), error))
644
    {
645 646 647
      stroke = gimp_vectors_stroke_get_by_ID (vectors, stroke_ID);

      if (! stroke)
648
        g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
649 650
                     _("Vectors object %d does not contain stroke with ID %d"),
                     gimp_item_get_ID (GIMP_ITEM (vectors)), stroke_ID);
651 652 653 654
    }

  return stroke;
}