Blender V5.3
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
8
9#include "BKE_geometry_set.hh"
10#include "BKE_grease_pencil.hh"
11#include "BKE_lib_id.hh"
12
14
15namespace blender {
16
17namespace bke {
18
19/* -------------------------------------------------------------------- */
22
24
29
31{
32 GreasePencilComponent *new_component = new GreasePencilComponent();
33 if (grease_pencil_ != nullptr) {
34 new_component->grease_pencil_ = BKE_grease_pencil_copy_for_eval(grease_pencil_);
35 new_component->ownership_ = GeometryOwnershipType::Owned;
36 }
37 return GeometryComponentPtr(new_component);
38}
39
41{
42 BLI_assert(this->is_mutable() || this->is_expired());
43 if (grease_pencil_ != nullptr) {
44 if (ownership_ == GeometryOwnershipType::Owned) {
45 BKE_id_free(nullptr, grease_pencil_);
46 }
47 grease_pencil_ = nullptr;
48 }
49}
50
52{
53 return grease_pencil_ != nullptr;
54}
55
57{
58 BLI_assert(this->is_mutable());
59 this->clear();
60 grease_pencil_ = grease_pencil;
61 ownership_ = ownership;
62}
63
65{
66 BLI_assert(this->is_mutable());
67 GreasePencil *grease_pencil = grease_pencil_;
68 grease_pencil_ = nullptr;
69 return grease_pencil;
70}
71
73{
74 return grease_pencil_;
75}
76
78{
79 BLI_assert(this->is_mutable());
80 if (ownership_ == GeometryOwnershipType::ReadOnly) {
81 grease_pencil_ = BKE_grease_pencil_copy_for_eval(grease_pencil_);
83 }
84 return grease_pencil_;
85}
86
88{
89 return grease_pencil_ == nullptr;
90}
91
93{
94 return ownership_ == GeometryOwnershipType::Owned;
95}
96
98{
99 BLI_assert(this->is_mutable());
100 if (ownership_ != GeometryOwnershipType::Owned) {
101 if (grease_pencil_) {
102 grease_pencil_ = BKE_grease_pencil_copy_for_eval(grease_pencil_);
103 }
104 ownership_ = GeometryOwnershipType::Owned;
105 }
106}
107
108} // namespace bke
109
110namespace bke {
111
112std::optional<AttributeAccessor> GreasePencilComponent::attributes() const
113{
115}
116
122
124
125} // namespace bke
126} // namespace blender
Low-level operations for grease pencil.
AttributeAccessor(const void *owner, const AttributeAccessorFunctions &fn)
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)
MutableAttributeAccessor(void *owner, const AttributeAccessorFunctions &fn)
const AttributeAccessorFunctions & get_attribute_accessor_functions()
ImplicitSharingPtr< GeometryComponent > GeometryComponentPtr
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
GreasePencil * BKE_grease_pencil_copy_for_eval(const GreasePencil *grease_pencil_src)
void BKE_id_free(Main *bmain, void *idv)