82 T *
asType() {
return dynamic_cast<T*
>( this ); }
84 const T *
asType()
const {
return dynamic_cast<const T*
>( this ); }
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 ); }
154 return const_cast<Object &
>( *this ).findCommonAncestor(
const_cast<Object &
>(
other ) );
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
257 [[nodiscard]]
virtual bool hasModel()
const {
return false; }
261 const std::set<std::string>&
tags()
const {
return tags_; }
335 struct MapSharedObjects;
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 );
349 if (
auto res = std::dynamic_pointer_cast<T>( child ) )
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
std::shared_ptr< Object > getSharedPtr() const
std::vector< std::shared_ptr< Object > > children_
Definition MRObject.h:56
std::vector< std::weak_ptr< Object > > bastards_
recognized ones
Definition MRObject.h:57
ObjectChildrenHolder & operator=(const ObjectChildrenHolder &) noexcept
Definition MRObject.h:41
ObjectChildrenHolder(const ObjectChildrenHolder &) noexcept
Definition MRObject.h:40
ObjectChildrenHolder * parent_
Definition MRObject.h:55
ObjectChildrenHolder(ObjectChildrenHolder &&) noexcept
ObjectChildrenHolder()=default
named object in the data model
Definition MRObject.h:62
Object * parent()
Definition MRObject.h:143
virtual std::shared_ptr< Object > shallowClone() const
std::shared_ptr< const Object > find(const std::string_view &name) const
finds a direct child by name
bool selected_
Definition MRObject.h:321
virtual void setXf(const AffineXf3f &xf, ViewportId id={})
bool globalVisibility(ViewportMask viewportMask=ViewportMask::any()) const
returns true if this object is visible together with all its parents in any of given viewports
Definition MRObject.h:128
T * asType()
Definition MRObject.h:82
virtual Expected< void > deserializeModel_(const std::filesystem::path &path, ProgressCallback progressCb={})
Reads model from file.
bool isAncestor(const Object *ancestor) const
return true if given object is ancestor of this one, false otherwise
virtual void resetXf(ViewportId id={})
forgets specific transform in given viewport (or forgets all specific transforms for {}...
AffineXf3f worldXf(ViewportId id={}, bool *isDef=nullptr) const
void setGlobalVisibility(bool on, ViewportMask viewportMask=ViewportMask::any())
if true sets all predecessors visible, otherwise sets this object invisible
const std::vector< std::shared_ptr< const Object > > & children() const
Definition MRObject.h:167
bool parentLocked_
Definition MRObject.h:320
std::shared_ptr< T > find()
Definition MRObject.h:97
ViewportMask globalVisibilityMask() const
returns all viewports where this object is visible together with all its parents
virtual bool hasModel() const
Definition MRObject.h:257
virtual void swapSignals_(Object &other)
virtual void applyScale(float scaleFactor)
scale object size (all point positions)
virtual std::shared_ptr< Object > clone() const
clones current object only, without parent and/or children
std::string name_
Definition MRObject.h:316
bool isAncillary() const
Definition MRObject.h:196
virtual bool isSelected() const
Definition MRObject.h:191
virtual size_t getModelHash() const
return hash of model (or hash object pointer if object has no model)
std::shared_ptr< Object > shallowCloneTree() const
virtual const char * typeName() const
Definition MRObject.h:71
virtual bool removeChild(Object *child)
static constexpr const char * StaticClassNameInPlural() noexcept
return human readable name of subclass in plural form
Definition MRObject.h:78
virtual bool getRedrawFlag(ViewportMask) const
this method virtual because others data model types could have dirty flags or something
Definition MRObject.h:210
void sortChildren()
sort recognized children by name
virtual Expected< std::future< Expected< void > > > serializeModel_(const std::filesystem::path &path) const
void sendWorldXfChangedSignal_()
virtual size_t heapBytes() const
returns the amount of memory this object occupies on heap
bool addTag(std::string tag)
Expected< void > deserializeRecursive(const std::filesystem::path &path, const Json::Value &root, ProgressCallback progressCb={}, int *objCounter=nullptr)
ViewportProperty< AffineXf3f > xf_
Definition MRObject.h:317
const AffineXf3f & xf(ViewportId id={}, bool *isDef=nullptr) const
Definition MRObject.h:107
void setWorldXf(const AffineXf3f &xf, ViewportId id={})
std::shared_ptr< Object > find(const std::string_view &name)
Definition MRObject.h:91
const T * asType() const
Definition MRObject.h:84
bool isGlobalAncillary() const
returns true if the object or any of its ancestors are ancillary
const Object * parent() const
returns parent object in the tree
Definition MRObject.h:142
const ViewportProperty< AffineXf3f > & xfsForAllViewports() const
returns xfs for all viewports, combined into a single object
Definition MRObject.h:113
virtual bool select(bool on)
selects the object, returns true if value changed, otherwise returns false
virtual void setXfsForAllViewports(ViewportProperty< AffineXf3f > xf)
modifies xfs for all viewports at once
Definition MRObject.h:115
virtual std::string classNameInPlural() const
Definition MRObject.h:79
virtual bool addChild(std::shared_ptr< Object > child, bool recognizedChild=true)
bool ancillary_
Definition MRObject.h:322
Object(ProtectedStruct, const Object &obj)
Definition MRObject.h:287
virtual void removeAllChildren()
detaches all recognized children from this, keeping all unrecognized ones
void setVisible(bool on, ViewportMask viewportMask=ViewportMask::all())
sets the object visible in the viewports specified by the mask (by default in all viewports)
std::shared_ptr< T > find(const std::string_view &name)
Definition MRObject.h:103
virtual std::vector< std::string > getInfoLines() const
return several info lines that can better describe object in the UI
MR_BIND_IGNORE Expected< std::vector< std::future< Expected< void > > > > serializeRecursive(const std::filesystem::path &path, Json::Value &root, int childId) const
Object * findCommonAncestor(Object &other)
XfChangedSignal worldXfChangedSignal
Definition MRObject.h:282
const std::vector< std::shared_ptr< Object > > & children()
an object can hold other sub-objects
Definition MRObject.h:161
virtual void swapBase_(Object &other)
swaps whole object (signals too)
bool needRedraw_
Definition MRObject.h:323
virtual ViewportMask visibilityMask() const
gets object visibility as bitmask of viewports
Definition MRObject.h:207
bool locked_
Prefer to not read directly. Use the getter, as it can be overridden.
Definition MRObject.h:319
bool isVisible(ViewportMask viewportMask=ViewportMask::any()) const
checks whether the object is visible in any of the viewports specified by the mask (by default in any...
Definition MRObject.h:203
void resetRedrawFlag() const
Definition MRObject.h:211
virtual bool hasVisualRepresentation() const
does the object have any visual representation (visible points, triangles, edges, etc....
Definition MRObject.h:253
bool removeChild(const std::shared_ptr< Object > &child)
returns false if it was not child of this
Definition MRObject.h:182
static constexpr const char * StaticClassName() noexcept
return human readable name of subclass
Definition MRObject.h:74
virtual void onWorldXfChanged_()
Emits worldXfChangedSignal, but derived classes can add additional behavior to it.
bool removeTag(const std::string &tag)
static constexpr const char * StaticTypeName() noexcept
return name of subtype for serialization purposes
Definition MRObject.h:70
Object(Object &&) noexcept=default
virtual void setVisibilityMask(ViewportMask viewportMask)
specifies object visibility as bitmask of viewports
virtual bool sameModels(const Object &other) const
return true if model of current object equals to model (the same) of other
std::set< std::string > tags_
Definition MRObject.h:324
const std::set< std::string > & tags() const
Definition MRObject.h:261
virtual void setLocked(bool on)
Definition MRObject.h:134
Object(const Object &obj)=default
user should not be able to call copy implicitly, use clone() function instead
virtual void setParentLocked(bool lock)
Definition MRObject.h:139
virtual bool detachFromParent()
virtual void deserializeFields_(const Json::Value &root)
virtual void setName(std::string name)
Definition MRObject.h:87
std::shared_ptr< Object > cloneTree() const
clones all tree of this object (except ancillary and unrecognized children)
Box3f getWorldTreeBox(ViewportId={}) const
returns bounding box of this object and all children visible in given (or default) viewport in world ...
bool isLocked() const
object properties lock for UI
Definition MRObject.h:133
Signal< void()> XfChangedSignal
Definition MRObject.h:281
virtual Expected< void > setSharedModel_(const Object &other)
shares model from other object
virtual bool addChildBefore(std::shared_ptr< Object > newChild, const std::shared_ptr< Object > &existingChild)
bool isParentLocked() const
Definition MRObject.h:138
const std::string & name() const
Definition MRObject.h:86
ViewportMask visibilityMask_
Definition MRObject.h:318
virtual Box3f getWorldBox(ViewportId={}) const
returns bounding box of this object in world coordinates for default or specific viewport
Definition MRObject.h:248
virtual void serializeFields_(Json::Value &root) const
const Object * findCommonAncestor(const Object &other) const
Definition MRObject.h:152
virtual void setAncillary(bool ancillary)
virtual std::string className() const
Definition MRObject.h:75
Definition MRViewportId.h:16
stores mask of viewport unique identifiers
Definition MRViewportId.h:42
static ViewportMask any()
Definition MRViewportId.h:50
static ViewportMask all()
mask meaning all or any viewports
Definition MRViewportId.h:49
Definition MRViewportProperty.h:17
std::function< bool(float)> ProgressCallback
Definition MRMeshFwd.h:753
std::shared_ptr< const T > find() const
finds a direct child by type
Definition MRObject.h:346
tl::expected< T, E > Expected
Definition MRExpected.h:31
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:13
@ other
Angle, normally float. Measure in radians.
Definition MRFeatureObject.h:27
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRObject.h:284
ProtectedStruct()=default