Blender  V2.93
object_identifier.cc
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  * The Original Code is Copyright (C) 2019 Blender Foundation.
17  * All rights reserved.
18  */
20 
21 #include "BKE_duplilist.h"
22 
23 extern "C" {
24 #include <climits> /* For INT_MAX. */
25 }
26 #include <cstring>
27 #include <sstream>
28 
29 namespace blender::io {
30 
32  Object *duplicated_by,
33  const PersistentID &persistent_id)
34  : object(object), duplicated_by(duplicated_by), persistent_id(persistent_id)
35 {
36 }
37 
39 {
40  return ObjectIdentifier(object, nullptr, PersistentID());
41 }
42 
44 {
45  if (context == nullptr) {
46  return for_graph_root();
47  }
48  if (context->duplicator != nullptr) {
49  return ObjectIdentifier(context->object, context->duplicator, context->persistent_id);
50  }
51  return for_real_object(context->object);
52 }
53 
55  Object *duplicated_by)
56 {
57  return ObjectIdentifier(dupli_object->ob, duplicated_by, PersistentID(dupli_object));
58 }
59 
61 {
62  return ObjectIdentifier(nullptr, nullptr, PersistentID());
63 }
64 
66 {
67  return object == nullptr;
68 }
69 
70 bool operator<(const ObjectIdentifier &obj_ident_a, const ObjectIdentifier &obj_ident_b)
71 {
72  if (obj_ident_a.object != obj_ident_b.object) {
73  return obj_ident_a.object < obj_ident_b.object;
74  }
75 
76  if (obj_ident_a.duplicated_by != obj_ident_b.duplicated_by) {
77  return obj_ident_a.duplicated_by < obj_ident_b.duplicated_by;
78  }
79 
80  if (obj_ident_a.duplicated_by == nullptr) {
81  /* Both are real objects, no need to check the persistent ID. */
82  return false;
83  }
84 
85  /* Same object, both are duplicated, use the persistent IDs to determine order. */
86  return obj_ident_a.persistent_id < obj_ident_b.persistent_id;
87 }
88 
89 bool operator==(const ObjectIdentifier &obj_ident_a, const ObjectIdentifier &obj_ident_b)
90 {
91  if (obj_ident_a.object != obj_ident_b.object) {
92  return false;
93  }
94  if (obj_ident_a.duplicated_by != obj_ident_b.duplicated_by) {
95  return false;
96  }
97  if (obj_ident_a.duplicated_by == nullptr) {
98  return true;
99  }
100 
101  /* Same object, both are duplicated, use the persistent IDs to determine equality. */
102  return obj_ident_a.persistent_id == obj_ident_b.persistent_id;
103 }
104 
105 } // namespace blender::io
static ObjectIdentifier for_graph_root()
static ObjectIdentifier for_duplicated_object(const DupliObject *dupli_object, Object *duplicated_by)
static ObjectIdentifier for_real_object(Object *object)
static ObjectIdentifier for_hierarchy_context(const HierarchyContext *context)
ObjectIdentifier(Object *object, Object *duplicated_by, const PersistentID &persistent_id)
bool operator<(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b)
bool operator==(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b)
struct SELECTID_Context context
Definition: select_engine.c:47
struct Object * ob
Definition: BKE_duplilist.h:45