13 #ifdef HMFC_STATIC_LIB 14 # error "Code cannot be statically linked." 27 #include "HMutexOOC.h" 30 #include "HWindowFilterOOC.h" 31 #include "PointCloudAPI.h" 40 # pragma warning(disable: 4127) 46 # define ASSERT(x) do {} while (false) 49 # define ASSERT(x) ((!(x)) ? __debugbreak() : 1) 52 # define ASSERT assert 76 template <
typename SelectionSet>
79 typedef void (HC_CDECL * CallbackFunc)(...);
88 struct CallbackKeyInfo {
91 : type(CallbackType_Invalid)
94 CallbackKeyInfo (HC_KEY key, CallbackType type)
98 ASSERT(type != CallbackType_Invalid);
108 : SelectionSet(&view)
110 , filter(deep_select)
111 , callback_key_infos(
new VArray<CallbackKeyInfo>())
113 static bool callback_names_defined =
false;
115 static_cast<HSelectionSet *
>(
static_cast<SelectionSet *
>(
this));
120 if (!callback_names_defined) {
122 HC_Define_Callback_Name(
"ooc_selection_on_deleted_key", reinterpret_cast<CallbackFunc>(StaticOnDeletedKey));
123 callback_names_defined =
true;
126 HC_Define_System_Options(H_FORMAT_TEXT(
"deleted key callback = ooc_selection_on_deleted_key"));
138 HC_Define_System_Options(
"no populate key callback");
139 HC_Define_System_Options(
"no deleted key callback");
142 delete callback_key_infos;
144 Instance() =
nullptr;
158 if (instance ==
nullptr) {
172 return Instance() ==
nullptr;
181 delete callback_key_infos;
182 callback_key_infos =
new VArray<CallbackKeyInfo>();
185 SelectionSet::Reset();
200 using namespace ooc::delta;
201 using namespace ooc::query;
207 has_root = HC_QShow_Existence(
"root",
"self") > 0;
211 return SelectionSet::DeleteSelection();
214 std::map<ooc::NodeHandle, std::vector<int>> handle_to_indices;
218 QueryIterator::Status status = it.GetStatus();
219 if (status != QueryIterator::Status_Alive) {
220 if (status != QueryIterator::Status_Dead) {
226 QueryResult
const & res = *it;
227 NodeHandle
const & handle = res.GetNodeHandle();
228 int point_index =
static_cast<int>(res.GetNodePointIndex());
229 handle_to_indices[handle].push_back(point_index);
234 HC_KEY
const ooc_root = HC_Create_Segment_Key_By_Key(view.
GetModelKey(),
"root");
236 if (!GetEnv(ooc_root, env)) {
240 SyncResult sync_res = ooc::delta::SynchronizeWith(env, [&](SyncToken
const & sync_token) {
242 using namespace ooc::delta;
244 auto const end = handle_to_indices.end();
245 auto it = handle_to_indices.begin();
246 for (; it != end; ++it) {
248 NodeHandle
const & handle = pair.first;
249 std::vector<int> & indices = pair.second;
250 ModifyResult result = DeleteSpecificPoints(sync_token, handle, indices.data(), indices.size());
251 if (result != ModifyResult_Success) {
257 if (sync_res != SyncResult_Success) {
265 m_pView->EmitDeleteSelectionListMessage();
286 HC_KEY
const ooc_root = HC_Create_Segment_Key_By_Key(view.
GetModelKey(),
"root");
288 if (!ooc::GetEnv(ooc_root, env)) {
290 return ooc::query::QueryIterator();
292 return ooc::query::QueryPoints(env, filter);
306 bool update_needed =
false;
308 std::vector<HC_KEY> seg_keys;
309 seg_keys.resize(1024);
313 int n = HC_Inspect_Proxies(seg_keys.data(), (int)seg_keys.size());
324 if (callback_key_infos->Count() == 0 && seg_keys.empty())
331 HC_KEY key_path[] = {
336 auto process_populate = [&](HC_KEY
const segment_key)
338 ooc::Point min_bounding;
339 ooc::Point max_bounding;
340 HC_Open_Segment_By_Key(segment_key); {
341 HC_Show_Bounding_Cuboid(&min_bounding, &max_bounding);
342 if (!filter.RejectBounding(min_bounding, max_bounding)) {
343 HC_Begin_Contents_Search(
".",
"shell"); {
345 while (HC_Find_Contents(
nullptr, &shell_key)) {
347 HC_Show_Shell_Size(shell_key, &point_count,
nullptr);
348 ooc::Point
const * points;
349 HC_Show_Geometry_Pointer(shell_key,
"points", &points);
350 std::vector<int> points_to_highlight;
351 for (
int i = 0; i < point_count; ++i) {
352 ooc::Point
const & point = points[i];
353 if (filter.AcceptPoint(point, static_cast<size_t>(i))) {
354 points_to_highlight.push_back(i);
357 if (!points_to_highlight.empty()) {
358 update_needed |= SelectSubentityOOC(
359 shell_key,
sizeof(key_path) /
sizeof(HC_KEY), key_path,
360 static_cast<int>(points_to_highlight.size()),
361 nullptr, points_to_highlight.data(),
nullptr,
true);
364 }HC_End_Contents_Search();
369 if (!seg_keys.empty() && filter.HasWindows())
371 for (
auto seg_key : seg_keys)
372 process_populate(seg_key);
376 VArray<CallbackKeyInfo> * infos = callback_key_infos;
377 callback_key_infos =
new VArray<CallbackKeyInfo>();
379 size_t const count = infos->Count();
380 for (
size_t i = 0; i < count; ++i) {
381 CallbackKeyInfo
const & info = infos->GetData(i);
387 case CallbackType_Deleted: {
388 HC_KEY
const shell_key = info.key;
389 update_needed |= DeSelectOOC(shell_key,
sizeof(key_path) /
sizeof(HC_KEY), key_path);
400 return update_needed;
411 filter.AddRectangleWindow(*GetView(), min, max);
423 filter.AddTriangleWindow(*GetView(), p1, p2, p3);
428 return filter.HasWindows();
435 template <
typename Func>
443 virtual bool Tick (
float request_time,
float actual_time)
445 UNREFERENCED(request_time);
446 UNREFERENCED(actual_time);
471 void OnDeletedKey (HC_KEY key,
int type)
473 if (type == HIC_Geometry_Type_SHELL) {
474 if (filter.HasWindows()) {
475 LockGuard lock(selection_mutex);
476 if (filter.HasWindows()) {
477 CallbackKeyInfo info(key, CallbackType_Deleted);
478 callback_key_infos->Append(info);
484 static void HC_CDECL StaticOnDeletedKey (HC_KEY key,
int type)
492 VArray<CallbackKeyInfo> * callback_key_infos;
Definition: HSelectionSetOOC.h:77
HTClient(float interval=0.1f, HTCStyle style=HTCS_Invalid, HTClientTickFunction tick_function=0, void *user_data=0)
Definition: HTManager.h:168
HC_KEY GetViewKey()
Definition: HBaseView.h:922
Definition: HMutexOOC.h:24
The HSelectionSet class manages a list of selected items.
Definition: HSelectionSet.h:66
Definition: HTManager.h:157
HC_KEY GetIncludeLinkKey()
Definition: HBaseView.h:927
Definition: HWindowFilterOOC.h:44
void AddTriangleWindow(ooc::Point const &p1, ooc::Point const &p2, ooc::Point const &p3)
Definition: HSelectionSetOOC.h:420
void AddRectangleWindow(ooc::Point const &min, ooc::Point const &max)
Definition: HSelectionSetOOC.h:408
static HTManager * GetHTManager()
Definition: HMutexOOC.h:28
Similar to HTCS_Periodic but this option has no make-up events.
Definition: HTManager.h:106
auto SynchronizeWith(Func const &task) -> decltype(task())
Definition: HSelectionSetOOC.h:436
void SetDeepSelection(bool deep_select)
Definition: HSelectionSetOOC.h:274
The HBaseView class defines and manages a view of model information.
Definition: HBaseView.h:332
ooc::query::QueryIterator SelectedPoints()
Definition: HSelectionSetOOC.h:283
bool UpdateSelection()
Definition: HSelectionSetOOC.h:304
virtual bool DeleteSelection(bool emit_message=false)
Definition: HSelectionSetOOC.h:197
static bool CanCreateInstance()
Definition: HSelectionSetOOC.h:170
void UnRegisterClient(HTClient *c)
virtual void Reset()
Definition: HSelectionSetOOC.h:177
void RegisterClient(HTClient *c)
static HSelectionSetOOC * CreateInstance(HBaseView &view, bool deep_select)
Definition: HSelectionSetOOC.h:154
Definition: HSelectionSetOOC.h:61