From 0a3de0305c35f3dbe472b87d4e8f98ff117aa3ad Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 14 Jan 2022 12:53:19 +0100 Subject: Cleanup: move attribute operators to c++ --- source/blender/editors/geometry/CMakeLists.txt | 6 +- .../blender/editors/geometry/geometry_attributes.c | 182 --------------------- .../editors/geometry/geometry_attributes.cc | 182 +++++++++++++++++++++ source/blender/editors/geometry/geometry_intern.h | 30 ---- source/blender/editors/geometry/geometry_intern.hh | 30 ++++ source/blender/editors/geometry/geometry_ops.c | 36 ---- source/blender/editors/geometry/geometry_ops.cc | 36 ++++ 7 files changed, 251 insertions(+), 251 deletions(-) delete mode 100644 source/blender/editors/geometry/geometry_attributes.c create mode 100644 source/blender/editors/geometry/geometry_attributes.cc delete mode 100644 source/blender/editors/geometry/geometry_intern.h create mode 100644 source/blender/editors/geometry/geometry_intern.hh delete mode 100644 source/blender/editors/geometry/geometry_ops.c create mode 100644 source/blender/editors/geometry/geometry_ops.cc (limited to 'source/blender/editors/geometry') diff --git a/source/blender/editors/geometry/CMakeLists.txt b/source/blender/editors/geometry/CMakeLists.txt index 75b334b9ec6..65b9633da98 100644 --- a/source/blender/editors/geometry/CMakeLists.txt +++ b/source/blender/editors/geometry/CMakeLists.txt @@ -29,10 +29,10 @@ set(INC_SYS ) set(SRC - geometry_attributes.c - geometry_ops.c + geometry_attributes.cc + geometry_ops.cc - geometry_intern.h + geometry_intern.hh ) set(LIB diff --git a/source/blender/editors/geometry/geometry_attributes.c b/source/blender/editors/geometry/geometry_attributes.c deleted file mode 100644 index 5cb491f116a..00000000000 --- a/source/blender/editors/geometry/geometry_attributes.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (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 - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2020 Blender Foundation. - * All rights reserved. - */ - -/** \file - * \ingroup edgeometry - */ - -#include "BKE_attribute.h" -#include "BKE_context.h" - -#include "RNA_access.h" -#include "RNA_define.h" -#include "RNA_enum_types.h" - -#include "DEG_depsgraph.h" - -#include "WM_api.h" -#include "WM_types.h" - -#include "ED_object.h" - -#include "geometry_intern.h" - -/*********************** Attribute Operators ************************/ - -static bool geometry_attributes_poll(bContext *C) -{ - Object *ob = ED_object_context(C); - ID *data = (ob) ? ob->data : NULL; - return (ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data)) && - BKE_id_attributes_supported(data); -} - -static bool geometry_attributes_remove_poll(bContext *C) -{ - if (!geometry_attributes_poll(C)) { - return false; - } - - Object *ob = ED_object_context(C); - ID *data = (ob) ? ob->data : NULL; - if (BKE_id_attributes_active_get(data) != NULL) { - return true; - } - - return false; -} - -static const EnumPropertyItem *geometry_attribute_domain_itemf(bContext *C, - PointerRNA *UNUSED(ptr), - PropertyRNA *UNUSED(prop), - bool *r_free) -{ - if (C == NULL) { - return DummyRNA_NULL_items; - } - - Object *ob = ED_object_context(C); - if (ob == NULL) { - return DummyRNA_NULL_items; - } - - return rna_enum_attribute_domain_itemf(ob->data, r_free); -} - -static int geometry_attribute_add_exec(bContext *C, wmOperator *op) -{ - Object *ob = ED_object_context(C); - ID *id = ob->data; - - char name[MAX_NAME]; - RNA_string_get(op->ptr, "name", name); - CustomDataType type = (CustomDataType)RNA_enum_get(op->ptr, "data_type"); - AttributeDomain domain = (AttributeDomain)RNA_enum_get(op->ptr, "domain"); - CustomDataLayer *layer = BKE_id_attribute_new(id, name, type, domain, op->reports); - - if (layer == NULL) { - return OPERATOR_CANCELLED; - } - - BKE_id_attributes_active_set(id, layer); - - DEG_id_tag_update(id, ID_RECALC_GEOMETRY); - WM_main_add_notifier(NC_GEOM | ND_DATA, id); - - return OPERATOR_FINISHED; -} - -void GEOMETRY_OT_attribute_add(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Add Geometry Attribute"; - ot->description = "Add attribute to geometry"; - ot->idname = "GEOMETRY_OT_attribute_add"; - - /* api callbacks */ - ot->poll = geometry_attributes_poll; - ot->exec = geometry_attribute_add_exec; - ot->invoke = WM_operator_props_popup_confirm; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* properties */ - PropertyRNA *prop; - - prop = RNA_def_string(ot->srna, "name", "Attribute", MAX_NAME, "Name", "Name of new attribute"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); - - prop = RNA_def_enum(ot->srna, - "domain", - rna_enum_attribute_domain_items, - ATTR_DOMAIN_POINT, - "Domain", - "Type of element that attribute is stored on"); - RNA_def_enum_funcs(prop, geometry_attribute_domain_itemf); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); - - prop = RNA_def_enum(ot->srna, - "data_type", - rna_enum_attribute_type_items, - CD_PROP_FLOAT, - "Data Type", - "Type of data stored in attribute"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); -} - -static int geometry_attribute_remove_exec(bContext *C, wmOperator *op) -{ - Object *ob = ED_object_context(C); - ID *id = ob->data; - CustomDataLayer *layer = BKE_id_attributes_active_get(id); - - if (layer == NULL) { - return OPERATOR_CANCELLED; - } - - if (!BKE_id_attribute_remove(id, layer, op->reports)) { - return OPERATOR_CANCELLED; - } - - int *active_index = BKE_id_attributes_active_index_p(id); - if (*active_index > 0) { - *active_index -= 1; - } - - DEG_id_tag_update(id, ID_RECALC_GEOMETRY); - WM_main_add_notifier(NC_GEOM | ND_DATA, id); - - return OPERATOR_FINISHED; -} - -void GEOMETRY_OT_attribute_remove(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Remove Geometry Attribute"; - ot->description = "Remove attribute from geometry"; - ot->idname = "GEOMETRY_OT_attribute_remove"; - - /* api callbacks */ - ot->exec = geometry_attribute_remove_exec; - ot->poll = geometry_attributes_remove_poll; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} diff --git a/source/blender/editors/geometry/geometry_attributes.cc b/source/blender/editors/geometry/geometry_attributes.cc new file mode 100644 index 00000000000..9c0f6728701 --- /dev/null +++ b/source/blender/editors/geometry/geometry_attributes.cc @@ -0,0 +1,182 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (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 + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup edgeometry + */ + +#include "BKE_attribute.h" +#include "BKE_context.h" + +#include "RNA_access.h" +#include "RNA_define.h" +#include "RNA_enum_types.h" + +#include "DEG_depsgraph.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_object.h" + +#include "geometry_intern.hh" + +/*********************** Attribute Operators ************************/ + +static bool geometry_attributes_poll(bContext *C) +{ + Object *ob = ED_object_context(C); + ID *data = (ob) ? static_cast(ob->data) : nullptr; + return (ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data)) && + BKE_id_attributes_supported(data); +} + +static bool geometry_attributes_remove_poll(bContext *C) +{ + if (!geometry_attributes_poll(C)) { + return false; + } + + Object *ob = ED_object_context(C); + ID *data = (ob) ? static_cast(ob->data) : nullptr; + if (BKE_id_attributes_active_get(data) != nullptr) { + return true; + } + + return false; +} + +static const EnumPropertyItem *geometry_attribute_domain_itemf(bContext *C, + PointerRNA *UNUSED(ptr), + PropertyRNA *UNUSED(prop), + bool *r_free) +{ + if (C == nullptr) { + return DummyRNA_NULL_items; + } + + Object *ob = ED_object_context(C); + if (ob == nullptr) { + return DummyRNA_NULL_items; + } + + return rna_enum_attribute_domain_itemf(static_cast(ob->data), r_free); +} + +static int geometry_attribute_add_exec(bContext *C, wmOperator *op) +{ + Object *ob = ED_object_context(C); + ID *id = static_cast(ob->data); + + char name[MAX_NAME]; + RNA_string_get(op->ptr, "name", name); + CustomDataType type = (CustomDataType)RNA_enum_get(op->ptr, "data_type"); + AttributeDomain domain = (AttributeDomain)RNA_enum_get(op->ptr, "domain"); + CustomDataLayer *layer = BKE_id_attribute_new(id, name, type, domain, op->reports); + + if (layer == nullptr) { + return OPERATOR_CANCELLED; + } + + BKE_id_attributes_active_set(id, layer); + + DEG_id_tag_update(id, ID_RECALC_GEOMETRY); + WM_main_add_notifier(NC_GEOM | ND_DATA, id); + + return OPERATOR_FINISHED; +} + +void GEOMETRY_OT_attribute_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Add Geometry Attribute"; + ot->description = "Add attribute to geometry"; + ot->idname = "GEOMETRY_OT_attribute_add"; + + /* api callbacks */ + ot->poll = geometry_attributes_poll; + ot->exec = geometry_attribute_add_exec; + ot->invoke = WM_operator_props_popup_confirm; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + PropertyRNA *prop; + + prop = RNA_def_string(ot->srna, "name", "Attribute", MAX_NAME, "Name", "Name of new attribute"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_enum(ot->srna, + "domain", + rna_enum_attribute_domain_items, + ATTR_DOMAIN_POINT, + "Domain", + "Type of element that attribute is stored on"); + RNA_def_enum_funcs(prop, geometry_attribute_domain_itemf); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_enum(ot->srna, + "data_type", + rna_enum_attribute_type_items, + CD_PROP_FLOAT, + "Data Type", + "Type of data stored in attribute"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); +} + +static int geometry_attribute_remove_exec(bContext *C, wmOperator *op) +{ + Object *ob = ED_object_context(C); + ID *id = static_cast(ob->data); + CustomDataLayer *layer = BKE_id_attributes_active_get(id); + + if (layer == nullptr) { + return OPERATOR_CANCELLED; + } + + if (!BKE_id_attribute_remove(id, layer, op->reports)) { + return OPERATOR_CANCELLED; + } + + int *active_index = BKE_id_attributes_active_index_p(id); + if (*active_index > 0) { + *active_index -= 1; + } + + DEG_id_tag_update(id, ID_RECALC_GEOMETRY); + WM_main_add_notifier(NC_GEOM | ND_DATA, id); + + return OPERATOR_FINISHED; +} + +void GEOMETRY_OT_attribute_remove(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Remove Geometry Attribute"; + ot->description = "Remove attribute from geometry"; + ot->idname = "GEOMETRY_OT_attribute_remove"; + + /* api callbacks */ + ot->exec = geometry_attribute_remove_exec; + ot->poll = geometry_attributes_remove_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} diff --git a/source/blender/editors/geometry/geometry_intern.h b/source/blender/editors/geometry/geometry_intern.h deleted file mode 100644 index 8a0f9294722..00000000000 --- a/source/blender/editors/geometry/geometry_intern.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (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 - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2020 Blender Foundation. - * All rights reserved. - */ - -/** \file - * \ingroup edgeometry - */ - -#pragma once - -struct wmOperatorType; - -/* *** geometry_attributes.c *** */ -void GEOMETRY_OT_attribute_add(struct wmOperatorType *ot); -void GEOMETRY_OT_attribute_remove(struct wmOperatorType *ot); diff --git a/source/blender/editors/geometry/geometry_intern.hh b/source/blender/editors/geometry/geometry_intern.hh new file mode 100644 index 00000000000..14992476edd --- /dev/null +++ b/source/blender/editors/geometry/geometry_intern.hh @@ -0,0 +1,30 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (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 + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup edgeometry + */ + +#pragma once + +struct wmOperatorType; + +/* *** geometry_attributes.cc *** */ +void GEOMETRY_OT_attribute_add(struct wmOperatorType *ot); +void GEOMETRY_OT_attribute_remove(struct wmOperatorType *ot); diff --git a/source/blender/editors/geometry/geometry_ops.c b/source/blender/editors/geometry/geometry_ops.c deleted file mode 100644 index ed0aeda731b..00000000000 --- a/source/blender/editors/geometry/geometry_ops.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (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 - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2020 Blender Foundation. - * All rights reserved. - */ - -/** \file - * \ingroup edgeometry - */ - -#include "WM_api.h" - -#include "ED_geometry.h" - -#include "geometry_intern.h" - -/**************************** registration **********************************/ - -void ED_operatortypes_geometry(void) -{ - WM_operatortype_append(GEOMETRY_OT_attribute_add); - WM_operatortype_append(GEOMETRY_OT_attribute_remove); -} diff --git a/source/blender/editors/geometry/geometry_ops.cc b/source/blender/editors/geometry/geometry_ops.cc new file mode 100644 index 00000000000..ba8afe0e62f --- /dev/null +++ b/source/blender/editors/geometry/geometry_ops.cc @@ -0,0 +1,36 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (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 + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup edgeometry + */ + +#include "WM_api.h" + +#include "ED_geometry.h" + +#include "geometry_intern.hh" + +/**************************** registration **********************************/ + +void ED_operatortypes_geometry(void) +{ + WM_operatortype_append(GEOMETRY_OT_attribute_add); + WM_operatortype_append(GEOMETRY_OT_attribute_remove); +} -- cgit v1.2.3