Blender  V2.93
spreadsheet_data_source_geometry.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
19 #include <mutex>
20 
21 #include "BLI_resource_scope.hh"
22 
23 #include "BKE_geometry_set.hh"
24 
26 
27 struct bContext;
28 
29 namespace blender::ed::spreadsheet {
30 
32  private:
33  Object *object_eval_;
34  const GeometrySet geometry_set_;
35  const GeometryComponent *component_;
36  AttributeDomain domain_;
37 
38  /* Some data is computed on the fly only when it is requested. Computing it does not change the
39  * logical state of this data source. Therefore, the corresponding methods are const and need to
40  * be protected with a mutex. */
41  mutable std::mutex mutex_;
42  mutable ResourceScope scope_;
43 
44  public:
46  GeometrySet geometry_set,
47  const GeometryComponentType component_type,
48  const AttributeDomain domain)
49  : object_eval_(object_eval),
50  geometry_set_(std::move(geometry_set)),
51  component_(geometry_set_.get_component_for_read(component_type)),
52  domain_(domain)
53  {
54  }
55 
57  {
58  return object_eval_;
59  }
60 
62 
64  FunctionRef<void(const SpreadsheetColumnID &)> fn) const override;
65 
66  std::unique_ptr<ColumnValues> get_column_values(
67  const SpreadsheetColumnID &column_id) const override;
68 
69  int tot_rows() const override;
70 };
71 
73  const GeometrySet geometry_set_;
74  const InstancesComponent *component_;
75 
76  public:
78  : geometry_set_(std::move(geometry_set)),
79  component_(geometry_set_.get_component_for_read<InstancesComponent>())
80  {
81  }
82 
84  FunctionRef<void(const SpreadsheetColumnID &)> fn) const override;
85 
86  std::unique_ptr<ColumnValues> get_column_values(
87  const SpreadsheetColumnID &column_id) const override;
88 
89  int tot_rows() const override;
90 };
91 
92 std::unique_ptr<DataSource> data_source_from_geometry(const bContext *C, Object *object_eval);
93 
94 } // namespace blender::ed::spreadsheet
AttributeDomain
Definition: BKE_attribute.h:41
GeometryComponentType
ThreadMutex mutex
void foreach_default_column_ids(FunctionRef< void(const SpreadsheetColumnID &)> fn) const override
std::unique_ptr< ColumnValues > get_column_values(const SpreadsheetColumnID &column_id) const override
GeometryDataSource(Object *object_eval, GeometrySet geometry_set, const GeometryComponentType component_type, const AttributeDomain domain)
std::unique_ptr< ColumnValues > get_column_values(const SpreadsheetColumnID &column_id) const override
void foreach_default_column_ids(FunctionRef< void(const SpreadsheetColumnID &)> fn) const override
std::unique_ptr< DataSource > data_source_from_geometry(const bContext *C, Object *object_eval)