UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TopologicalLink.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "Core/CADEntity.h"
5#include "Math/Point.h"
7#include "UI/Message.h"
8
9namespace UE::CADKernel
10{
11
12class FTopologicalEdge;
13class FTopologicalVertex;
14
15template<typename EntityType>
17{
18 friend FEntity;
19
20protected:
21 friend EntityType;
22 EntityType* ActiveEntity;
23
25
27 : ActiveEntity(nullptr)
28 {
29 }
30
31 TTopologicalLink(EntityType& Entity)
32 : ActiveEntity(&Entity)
33 {
34 TwinEntities.Add(&Entity);
35 }
36
37public:
38
39 virtual ~TTopologicalLink() override
40 {
41 TTopologicalLink::Empty();
42 }
43
44 virtual void Serialize(FCADKernelArchive& Ar) override
45 {
46#ifdef CADKERNEL_DEV
47 if (Ar.IsSaving())
48 {
49 ensureCADKernel(ActiveEntity != nullptr);
50 ensureCADKernel(!ActiveEntity->IsDeleted());
51 }
52#endif
53 FEntity::Serialize(Ar);
54 SerializeIdent(Ar, &ActiveEntity, false);
55 SerializeIdents(Ar, TwinEntities, false);
56 }
57
58 virtual void Empty() override
59 {
60 TwinEntities.Empty();
61 ActiveEntity = nullptr;
62 }
63
64 const EntityType* GetActiveEntity() const
65 {
66 ensureCADKernel(ActiveEntity);
67 return ActiveEntity;
68 }
69
70 EntityType* GetActiveEntity()
71 {
72 ensureCADKernel(ActiveEntity);
73 return ActiveEntity;
74 }
75
77 {
78 return TwinEntities.Num();
79 }
80
82 {
83 return TwinEntities;
84 }
85
86 void ActivateEntity(const EntityType& NewActiveEntity)
87 {
89 for (EntityType* Entity : TwinEntities)
90 {
91 if (Entity == &NewActiveEntity)
92 {
93 return true;
94 }
95 }
96 FMessage::Error(TEXT("FTopologicalLink::ActivateEntity, the topological entity is not found in the twins entities"));
97 return false;
98 };
99
101 ActiveEntity = &NewActiveEntity;
102 }
103
105 {
106 EntityType* EntityPtr = *Entity;
107 RemoveEntity(*EntityPtr);
108 }
109
110 void RemoveEntity(EntityType& Entity)
111 {
112 TwinEntities.Remove(&Entity);
113 if (&Entity == ActiveEntity && TwinEntities.Num() > 0)
114 {
115 ActiveEntity = TwinEntities.HeapTop();
116 }
117
118 if (TwinEntities.Num() == 0)
119 {
120 ActiveEntity = nullptr;
121 Delete();
122 }
123 }
124
125 //void UnlinkTwinEntities()
126 //{
127 // for (EntityType* Entity : TwinsEntities)
128 // {
129 // Entity->ResetTopologicalLink();
130 // }
131 // TwinsEntities.Empty();
132 //}
133
134#ifdef CADKERNEL_DEV
135 virtual FInfoEntity& GetInfo(FInfoEntity& Info) const override;
136#endif
137
138 virtual EEntity GetEntityType() const override
139 {
140 return EEntity::EdgeLink;
141 }
142
143 void AddEntity(EntityType* Entity)
144 {
145 TwinEntities.Add(Entity);
146 }
147
148 void AddEntity(EntityType& Entity)
149 {
150 TwinEntities.Add(&Entity);
151 }
152
153 template <typename LinkableType>
154 void AddEntity(const LinkableType* Entity)
155 {
156 TwinEntities.Add((EntityType*)Entity);
157 }
158
159 template <typename ArrayType>
160 void AddEntities(const ArrayType& Entities)
161 {
162 TwinEntities.Insert(Entities, TwinEntities.Num());
163 }
164
168 virtual bool CleanLink()
169 {
171 NewTwinsEntities.Reserve(TwinEntities.Num());
172 for (EntityType* Entity : TwinEntities)
173 {
174 if (Entity)
175 {
177 }
178 }
179
180 if (NewTwinsEntities.Num() != TwinEntities.Num())
181 {
182 Swap(NewTwinsEntities, TwinEntities);
183 if (TwinEntities.Num())
184 {
185 ActiveEntity = TwinEntities.HeapTop();
186 return true;
187 }
188 }
189 return false;
190 }
191
193 {
194 for (EntityType* Entity : TwinEntities)
195 {
196 if (Entity)
197 {
198 Entity->ResetMarkers();
199 }
200 }
201 }
202};
203
204} // namespace UE::CADKernel
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define ensureCADKernel(InExpression)
Definition Types.h:115
const bool
Definition NetworkReplayStreaming.h:178
Definition Array.h:670
SizeType Remove(const ElementType &Item)
Definition Array.h:3091
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
UE_NODEBUG const ElementType & HeapTop() const UE_LIFETIMEBOUND
Definition Array.h:3848
SizeType Insert(std::initializer_list< ElementType > InitList, const SizeType InIndex)
Definition Array.h:1875
void Empty(SizeType Slack=0)
Definition Array.h:2273
UE_FORCEINLINE_HINT void Reserve(SizeType Number)
Definition Array.h:3016
Definition AndroidPlatformMisc.h:14
Definition SharedPointer.h:692
Definition CADKernelArchive.h:19
bool IsSaving() const
Definition CADKernelArchive.h:113
Definition CADEntity.h:56
Definition TopologicalEntity.h:16
Definition CADEntity.cpp:23
EEntity
Definition CADEntity.h:18