Blender V5.0
geometry_component_grease_pencil.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_geometry_set.hh"
7#include "BKE_lib_id.hh"
8
10
12
13namespace blender::bke {
14
15/* -------------------------------------------------------------------- */
18
20
25
27{
28 GreasePencilComponent *new_component = new GreasePencilComponent();
29 if (grease_pencil_ != nullptr) {
30 new_component->grease_pencil_ = BKE_grease_pencil_copy_for_eval(grease_pencil_);
31 new_component->ownership_ = GeometryOwnershipType::Owned;
32 }
33 return GeometryComponentPtr(new_component);
34}
35
37{
38 BLI_assert(this->is_mutable() || this->is_expired());
39 if (grease_pencil_ != nullptr) {
40 if (ownership_ == GeometryOwnershipType::Owned) {
41 BKE_id_free(nullptr, grease_pencil_);
42 }
43 grease_pencil_ = nullptr;
44 }
45}
46
48{
49 return grease_pencil_ != nullptr;
50}
51
53{
54 BLI_assert(this->is_mutable());
55 this->clear();
56 grease_pencil_ = grease_pencil;
57 ownership_ = ownership;
58}
59
61{
62 BLI_assert(this->is_mutable());
63 GreasePencil *grease_pencil = grease_pencil_;
64 grease_pencil_ = nullptr;
65 return grease_pencil;
66}
67
69{
70 return grease_pencil_;
71}
72
74{
75 BLI_assert(this->is_mutable());
76 if (ownership_ == GeometryOwnershipType::ReadOnly) {
77 grease_pencil_ = BKE_grease_pencil_copy_for_eval(grease_pencil_);
79 }
80 return grease_pencil_;
81}
82
84{
85 return grease_pencil_ == nullptr;
86}
87
89{
90 return ownership_ == GeometryOwnershipType::Owned;
91}
92
94{
95 BLI_assert(this->is_mutable());
96 if (ownership_ != GeometryOwnershipType::Owned) {
97 if (grease_pencil_) {
98 grease_pencil_ = BKE_grease_pencil_copy_for_eval(grease_pencil_);
99 }
100 ownership_ = GeometryOwnershipType::Owned;
101 }
102}
103
104} // namespace blender::bke
105
106namespace blender::bke {
107
108std::optional<AttributeAccessor> GreasePencilComponent::attributes() const
109{
111}
112
113std::optional<MutableAttributeAccessor> GreasePencilComponent::attributes_for_write()
114{
115 GreasePencil *grease_pencil = this->get_for_write();
117}
118
119} // namespace blender::bke
Low-level operations for grease pencil.
GreasePencil * BKE_grease_pencil_copy_for_eval(const GreasePencil *grease_pencil_src)
void BKE_id_free(Main *bmain, void *idv)
#define BLI_assert(a)
Definition BLI_assert.h:46
std::optional< AttributeAccessor > attributes() const final
std::optional< MutableAttributeAccessor > attributes_for_write() final
GeometryComponentPtr copy() const override
void replace(GreasePencil *grease_pencil, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const AttributeAccessorFunctions & get_attribute_accessor_functions()
ImplicitSharingPtr< GeometryComponent > GeometryComponentPtr