Overte C++ Documentation
EntityEditFilters.h
1 //
2 // EntityEditFilters.h
3 // libraries/entities/src
4 //
5 // Created by David Kelly on 2/7/2017.
6 // Copyright 2017 High Fidelity, Inc.
7 // Copyright 2023 Overte e.V.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 // SPDX-License-Identifier: Apache-2.0
12 //
13 #ifndef hifi_EntityEditFilters_h
14 #define hifi_EntityEditFilters_h
15 
16 #include <QObject>
17 #include <QMap>
18 #include <glm/glm.hpp>
19 
20 #include <functional>
21 
22 #include <ScriptValue.h>
23 
24 #include "EntityItemID.h"
25 #include "EntityItemProperties.h"
26 #include "EntityTree.h"
27 
28 class ScriptEngine;
29 
30 class EntityEditFilters : public QObject, public Dependency {
31  Q_OBJECT
32 public:
33  struct FilterData {
34  ScriptValue filterFn;
35  bool wantsOriginalProperties { false };
36  bool wantsZoneProperties { false };
37 
38  bool wantsToFilterAdd { true };
39  bool wantsToFilterEdit { true };
40  bool wantsToFilterPhysics { true };
41  bool wantsToFilterDelete { true };
42 
43  EntityPropertyFlags includedOriginalProperties;
44  EntityPropertyFlags includedZoneProperties;
45  bool wantsZoneBoundingBox { false };
46 
47  std::function<bool()> uncaughtExceptions;
48  ScriptEnginePointer engine;
49  bool rejectAll;
50 
51  FilterData(): rejectAll(false) {};
52  bool valid() { return (rejectAll || (engine != nullptr && filterFn.isFunction() && uncaughtExceptions)); }
53  };
54 
55  EntityEditFilters() {};
56  EntityEditFilters(EntityTreePointer tree ): _tree(tree) {};
57 
58  void addFilter(EntityItemID entityID, QString filterURL);
59  void removeFilter(EntityItemID entityID);
60 
61  bool filter(glm::vec3& position, EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged,
62  EntityTree::FilterType filterType, EntityItemID& entityID, const EntityItemPointer& existingEntity);
63 
64 signals:
65  void filterAdded(EntityItemID id, bool success);
66 
67 private slots:
68  void scriptRequestFinished(EntityItemID entityID);
69 
70 private:
71  QList<EntityItemID> getZonesByPosition(glm::vec3& position);
72 
73  EntityTreePointer _tree {};
74  bool _rejectAll {false};
75  ScriptValue _nullObjectForFilter{};
76 
77  QReadWriteLock _lock;
78  QMap<EntityItemID, FilterData> _filterDataMap;
79 };
80 
81 #endif //hifi_EntityEditFilters_h
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28
Definition: EntityItemProperties.h:106
Provides an engine-independent interface for a scripting engine.
Definition: ScriptEngine.h:93
[ScriptInterface] Provides an engine-independent interface for QScriptValue
Definition: ScriptValue.h:40