36class ObjectChildrenHolder
48 [[nodiscard]]
MRMESH_API std::shared_ptr<Object> getSharedPtr() const;
52 [[nodiscard]]
MRMESH_API size_t heapBytes() const;
56 std::vector< std::shared_ptr< Object > > children_;
57 std::vector< std::weak_ptr< Object > > bastards_;
65 Object( Object && ) noexcept = default;
66 Object & operator = ( Object && ) noexcept = default;
67 virtual ~Object() = default;
70 constexpr static const
char* StaticTypeName() noexcept {
return "Object"; }
71 virtual const char* typeName()
const {
return StaticTypeName(); }
74 constexpr static const char* StaticClassName() noexcept {
return "Object"; }
75 virtual std::string className()
const {
return StaticClassName(); }
78 constexpr static const char* StaticClassNameInPlural() noexcept {
return "Objects"; }
79 virtual std::string classNameInPlural()
const {
return StaticClassNameInPlural(); }
82 T * asType() {
return dynamic_cast<T*
>( this ); }
84 const T * asType()
const {
return dynamic_cast<const T*
>( this ); }
86 const std::string &
name()
const {
return name_; }
87 virtual void setName( std::string name ) { name_ = std::move( name ); }
90 MRMESH_API std::shared_ptr<const Object>
find(
const std::string_view & name )
const;
91 std::shared_ptr<Object>
find(
const std::string_view & name ) {
return std::const_pointer_cast<Object>(
const_cast<const Object*
>(
this )->
find( name ) ); }
95 std::shared_ptr<const T>
find()
const;
97 std::shared_ptr<T>
find() {
return std::const_pointer_cast<T>(
const_cast<const Object*
>(
this )->find<T>() ); }
100 template <
typename T>
101 std::shared_ptr<const T>
find(
const std::string_view & name )
const;
102 template <
typename T>
103 std::shared_ptr<T>
find(
const std::string_view & name ) {
return std::const_pointer_cast<T>(
const_cast<const Object*
>(
this )->find<T>( name ) ); }
107 const AffineXf3f & xf( ViewportId
id = {},
bool * isDef = nullptr )
const {
return xf_.get(
id, isDef ); }
108 MRMESH_API virtual void setXf(
const AffineXf3f& xf, ViewportId
id = {} );
110 MRMESH_API virtual void resetXf( ViewportId
id = {} );
113 const ViewportProperty<AffineXf3f> & xfsForAllViewports()
const {
return xf_; }
115 virtual void setXfsForAllViewports( ViewportProperty<AffineXf3f> xf ) { xf_ = std::move( xf ); }
119 MRMESH_API AffineXf3f worldXf( ViewportId
id = {},
bool * isDef = nullptr )
const;
120 MRMESH_API void setWorldXf(
const AffineXf3f& xf, ViewportId
id = {} );
123 MRMESH_API virtual void applyScale(
float scaleFactor );
126 MRMESH_API ViewportMask globalVisibilityMask()
const;
128 bool globalVisibility( ViewportMask viewportMask = ViewportMask::any() )
const {
return !( globalVisibilityMask() & viewportMask ).empty(); }
130 MRMESH_API void setGlobalVisibility(
bool on, ViewportMask viewportMask = ViewportMask::any() );
133 bool isLocked()
const {
return locked_; }
134 virtual void setLocked(
bool on ) { locked_ = on; }
138 [[nodiscard]]
bool isParentLocked()
const {
return parentLocked_; }
139 virtual void setParentLocked(
bool lock ) { parentLocked_ = lock; }
142 const Object * parent()
const {
return static_cast<const Object *
>( parent_ ); }
143 Object * parent() {
return static_cast<Object *
>( parent_ ); }
146 MRMESH_API bool isAncestor(
const Object* ancestor )
const;
151 [[nodiscard]]
MRMESH_API Object* findCommonAncestor( Object& other );
152 [[nodiscard]]
const Object* findCommonAncestor(
const Object& other )
const
154 return const_cast<Object &
>( *this ).findCommonAncestor(
const_cast<Object &
>( other ) );
161 const std::vector<std::shared_ptr<Object>>& children() {
return children_; }
164 #pragma GCC diagnostic push
165 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
167 const std::vector<std::shared_ptr<const Object>>& children()
const {
return reinterpret_cast<const std::vector< std::shared_ptr< const Object >
> &>( children_ ); }
169 #pragma GCC diagnostic pop
176 MRMESH_API virtual bool addChild( std::shared_ptr<Object> child,
bool recognizedChild =
true );
180 MRMESH_API virtual bool addChildBefore( std::shared_ptr<Object> newChild,
const std::shared_ptr<Object> & existingChild );
182 bool removeChild(
const std::shared_ptr<Object>& child ) {
return removeChild( child.get() ); }
183 MRMESH_API virtual bool removeChild( Object* child );
191 virtual bool isSelected()
const {
return selected_; }
195 MRMESH_API virtual void setAncillary(
bool ancillary );
196 bool isAncillary()
const {
return ancillary_; }
201 MRMESH_API void setVisible(
bool on, ViewportMask viewportMask = ViewportMask::all() );
203 bool isVisible( ViewportMask viewportMask = ViewportMask::any() )
const {
return !( visibilityMask() & viewportMask ).empty(); }
205 MRMESH_API virtual void setVisibilityMask( ViewportMask viewportMask );
207 virtual ViewportMask visibilityMask()
const {
return visibilityMask_; }
210 virtual bool getRedrawFlag( ViewportMask )
const {
return needRedraw_; }
211 void resetRedrawFlag()
const { needRedraw_ =
false; }
214 MRMESH_API std::shared_ptr<Object> cloneTree()
const;
216 MRMESH_API virtual std::shared_ptr<Object> clone()
const;
219 MRMESH_API std::shared_ptr<Object> shallowCloneTree()
const;
222 MRMESH_API virtual std::shared_ptr<Object> shallowClone()
const;
225 MRMESH_API virtual std::vector<std::string> getInfoLines()
const;
234 MRMESH_API MR_BIND_IGNORE Expected<std::vector<std::future<Expected<void>>>> serializeRecursive(
const std::filesystem::path& path, Json::Value& root,
int childId )
const;
239 MRMESH_API Expected<void> deserializeRecursive(
const std::filesystem::path& path,
const Json::Value& root,
240 ProgressCallback progressCb = {},
int* objCounter = nullptr );
248 virtual Box3f getWorldBox( ViewportId = {} )
const {
return {}; }
250 MRMESH_API Box3f getWorldTreeBox( ViewportId = {} )
const;
253 [[nodiscard]]
virtual bool hasVisualRepresentation()
const {
return false; }
257 [[nodiscard]]
virtual bool hasModel()
const {
return false; }
261 const std::set<std::string>& tags()
const {
return tags_; }
268 MRMESH_API bool removeTag(
const std::string& tag );
271 [[nodiscard]]
MRMESH_API virtual size_t heapBytes()
const;
274 MRMESH_API virtual bool sameModels(
const Object& other )
const;
276 MRMESH_API virtual size_t getModelHash()
const;
281 using XfChangedSignal = Signal<void()>;
282 XfChangedSignal worldXfChangedSignal;
301 MRMESH_API virtual Expected<std::future<Expected<void>>> serializeModel_(
const std::filesystem::path& path )
const;
305 MRMESH_API virtual void serializeFields_( Json::Value& root )
const;
308 MRMESH_API virtual Expected<void> deserializeModel_(
const std::filesystem::path& path, ProgressCallback progressCb = {} );
310 MRMESH_API virtual Expected<void> setSharedModel_(
const Object& other );
314 MRMESH_API virtual void deserializeFields_(
const Json::Value& root );
317 ViewportProperty<AffineXf3f> xf_;
318 ViewportMask visibilityMask_ = ViewportMask::all();
319 bool locked_ =
false;
320 bool parentLocked_ =
false;
321 bool selected_{
false };
322 bool ancillary_{
false };
323 mutable bool needRedraw_{
false};
324 std::set<std::string> tags_;
335 struct MapSharedObjects;
336 Expected<std::vector<std::future<Expected<void>>>> serializeRecursive_(
const std::filesystem::path& path, Json::Value& root,
337 int childId, MapSharedObjects* mapSharedObjects )
const;
340 struct MapLinkToSharedObjectModel;
341 Expected<void> deserializeRecursive_(
const std::filesystem::path& path,
const Json::Value& root,
342 int* objCounter, MapLinkToSharedObjectModel& mapLinkToSharedObjectModel,
const ProgressCallback& progressCb );
348 for (
const auto & child : children_ )
349 if (
auto res = std::dynamic_pointer_cast<T>( child ) )
355std::shared_ptr<const T>
Object::find(
const std::string_view & name )
const
357 for (
const auto & child : children_ )
358 if ( child->name() == name )
359 if (
auto res = std::dynamic_pointer_cast<T>( child ) )
#define MRMESH_API
Definition MRMeshFwd.h:80
#define MRMESH_CLASS
Definition MRMeshFwd.h:87
unsafe ObjectChildrenHolder()
std::shared_ptr< const T > find() const
finds a direct child by type
Definition MRObject.h:346
std::string name(const T &primitive)
Definition MRFeatures.h:309
MRVOXELS_API double find(const Mesh &mesh, const FindParams ¶ms, FaceBitSet &outUndercuts, const UndercutMetric &metric={})
Definition MRCameraOrientationPlugin.h:8
Definition MRObject.h:284
ProtectedStruct()=default