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)(...);
84 CallbackType_Populate,
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) {
121 HC_Define_Callback_Name(
"ooc_selection_on_populate_key", reinterpret_cast<CallbackFunc>(StaticOnPopulateKey));
122 HC_Define_Callback_Name(
"ooc_selection_on_deleted_key", reinterpret_cast<CallbackFunc>(StaticOnDeletedKey));
123 callback_names_defined =
true;
125 HC_Define_System_Options(H_FORMAT_TEXT(
"populate key callback = ooc_selection_on_populate_key"));
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 if (callback_key_infos->Count() == 0) {
312 bool update_needed =
false;
322 VArray<CallbackKeyInfo> * infos = callback_key_infos;
323 callback_key_infos =
new VArray<CallbackKeyInfo>();
325 size_t const count = infos->Count();
326 for (
size_t i = 0; i < count; ++i) {
327 CallbackKeyInfo
const & info = infos->GetData(i);
329 case CallbackType_Populate: {
330 HC_KEY const segment_key = info.key;
331 ooc::Point min_bounding;
332 ooc::Point max_bounding;
333 HC_Open_Segment_By_Key(segment_key);{
334 HC_Show_Bounding_Cuboid(&min_bounding, &max_bounding);
335 if (!filter.RejectBounding(min_bounding, max_bounding)) {
336 HC_Begin_Contents_Search(
".",
"shell");{
338 while (HC_Find_Contents(
nullptr, &shell_key)) {
340 HC_Show_Shell_Size(shell_key, &point_count,
nullptr);
341 ooc::Point
const * points;
342 HC_Show_Geometry_Pointer(shell_key,
"points", &points);
343 std::vector<int> points_to_highlight;
344 for (
int i = 0; i < point_count; ++i) {
345 ooc::Point
const & point = points[i];
346 if (filter.AcceptPoint(point, static_cast<size_t>(i))) {
347 points_to_highlight.push_back(i);
350 if (!points_to_highlight.empty()) {
351 update_needed |= SelectSubentityOOC(
352 shell_key,
sizeof(key_path) /
sizeof(
HC_KEY), key_path,
353 static_cast<int>(points_to_highlight.size()),
354 nullptr, points_to_highlight.data(),
nullptr,
true);
357 }HC_End_Contents_Search();
362 case CallbackType_Deleted: {
363 HC_KEY const shell_key = info.key;
364 update_needed |= DeSelectOOC(shell_key,
sizeof(key_path) /
sizeof(
HC_KEY), key_path);
375 return update_needed;
386 filter.AddRectangleWindow(*GetView(), min, max);
398 filter.AddTriangleWindow(*GetView(), p1, p2, p3);
405 template <
typename Func>
413 virtual bool Tick (
float request_time,
float actual_time)
415 UNREFERENCED(request_time);
416 UNREFERENCED(actual_time);
425 void OnPopulateKey (HC_KEY segment_key)
427 if (filter.HasWindows()) {
428 LockGuard lock(selection_mutex);
429 if (filter.HasWindows()) {
430 CallbackKeyInfo info(segment_key, CallbackType_Populate);
431 callback_key_infos->Append(info);
436 static void HC_CDECL StaticOnPopulateKey (HC_KEY segment_key)
441 void OnDeletedKey (HC_KEY key,
int type)
443 if (type == HIC_Geometry_Type_SHELL) {
444 if (filter.HasWindows()) {
445 LockGuard lock(selection_mutex);
446 if (filter.HasWindows()) {
447 CallbackKeyInfo info(key, CallbackType_Deleted);
448 callback_key_infos->Append(info);
454 static void HC_CDECL StaticOnDeletedKey (HC_KEY key,
int type)
462 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:915
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:920
Definition: HWindowFilterOOC.h:44
void AddTriangleWindow(ooc::Point const &p1, ooc::Point const &p2, ooc::Point const &p3)
Definition: HSelectionSetOOC.h:395
void AddRectangleWindow(ooc::Point const &min, ooc::Point const &max)
Definition: HSelectionSetOOC.h:383
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:406
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