MeshLib Documentation
Loading...
Searching...
No Matches
MR::Object Class Reference

named object in the data model More...

#include <MRObject.h>

+ Inheritance diagram for MR::Object:

Classes

struct  ProtectedStruct
 

Public Types

using XfChangedSignal = Signal<void() >
 

Public Member Functions

 Object ()=default
 
 Object (Object &&) noexcept=default
 
Objectoperator= (Object &&) noexcept=default
 
virtual ~Object ()=default
 
virtual const char * typeName () const
 
template<typename T >
T * asType ()
 
template<typename T >
const T * asType () const
 
const std::string & name () const
 
virtual void setName (std::string name)
 
MRMESH_API std::shared_ptr< const Objectfind (const std::string_view &name) const
 finds a direct child by name
 
std::shared_ptr< Objectfind (const std::string_view &name)
 
template<typename T >
std::shared_ptr< const T > find () const
 finds a direct child by type
 
template<typename T >
std::shared_ptr< T > find ()
 
template<typename T >
std::shared_ptr< const T > find (const std::string_view &name) const
 finds a direct child by name and type
 
template<typename T >
std::shared_ptr< T > find (const std::string_view &name)
 
const AffineXf3f & xf (ViewportId id={}, bool *isDef=nullptr) const
 
virtual MRMESH_API void setXf (const AffineXf3f &xf, ViewportId id={})
 
virtual MRMESH_API void resetXf (ViewportId id={})
 forgets specific transform in given viewport (or forgets all specific transforms for {} input)
 
const ViewportProperty< AffineXf3f > & xfsForAllViewports () const
 returns xfs for all viewports, combined into a single object
 
virtual void setXfsForAllViewports (ViewportProperty< AffineXf3f > xf)
 modifies xfs for all viewports at once
 
MRMESH_API AffineXf3f worldXf (ViewportId id={}, bool *isDef=nullptr) const
 
MRMESH_API void setWorldXf (const AffineXf3f &xf, ViewportId id={})
 
virtual MRMESH_API void applyScale (float scaleFactor)
 scale object size (all point positions)
 
MRMESH_API ViewportMask globalVisibilityMask () const
 returns all viewports where this object is visible together with all its parents
 
bool globalVisibility (ViewportMask viewportMask=ViewportMask::any()) const
 returns true if this object is visible together with all its parents in any of given viewports
 
MRMESH_API void setGlobalVisibility (bool on, ViewportMask viewportMask=ViewportMask::any())
 if true sets all predecessors visible, otherwise sets this object invisible
 
bool isLocked () const
 object properties lock for UI
 
virtual void setLocked (bool on)
 
bool isParentLocked () const
 
virtual void setParentLocked (bool lock)
 
const Objectparent () const
 returns parent object in the tree
 
Objectparent ()
 
MRMESH_API bool isAncestor (const Object *ancestor) const
 return true if given object is ancestor of this one, false otherwise
 
MRMESH_API ObjectfindCommonAncestor (Object &other)
 
const ObjectfindCommonAncestor (const Object &other) const
 
virtual MRMESH_API bool detachFromParent ()
 
const std::vector< std::shared_ptr< Object > > & children ()
 an object can hold other sub-objects
 
const std::vector< std::shared_ptr< const Object > > & children () const
 
virtual MRMESH_API bool addChild (std::shared_ptr< Object > child, bool recognizedChild=true)
 
virtual MRMESH_API bool addChildBefore (std::shared_ptr< Object > newChild, const std::shared_ptr< Object > &existingChild)
 
bool removeChild (const std::shared_ptr< Object > &child)
 returns false if it was not child of this
 
virtual MRMESH_API bool removeChild (Object *child)
 
virtual MRMESH_API void removeAllChildren ()
 detaches all recognized children from this, keeping all unrecognized ones
 
MRMESH_API void sortChildren ()
 sort recognized children by name
 
virtual MRMESH_API bool select (bool on)
 selects the object, returns true if value changed, otherwise returns false
 
virtual bool isSelected () const
 
virtual MRMESH_API void setAncillary (bool ancillary)
 
bool isAncillary () const
 
MRMESH_API void setVisible (bool on, ViewportMask viewportMask=ViewportMask::all())
 sets the object visible in the viewports specified by the mask (by default in all viewports)
 
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 viewport)
 
virtual MRMESH_API void setVisibilityMask (ViewportMask viewportMask)
 specifies object visibility as bitmask of viewports
 
virtual ViewportMask visibilityMask () const
 gets object visibility as bitmask of viewports
 
virtual bool getRedrawFlag (ViewportMask) const
 this method virtual because others data model types could have dirty flags or something
 
void resetRedrawFlag () const
 
MRMESH_API std::shared_ptr< ObjectcloneTree () const
 clones all tree of this object (except ancillary and unrecognized children)
 
virtual MRMESH_API std::shared_ptr< Objectclone () const
 clones current object only, without parent and/or children
 
MRMESH_API std::shared_ptr< ObjectshallowCloneTree () const
 
virtual MRMESH_API std::shared_ptr< ObjectshallowClone () const
 
virtual MRMESH_API std::vector< std::string > getInfoLines () const
 return several info lines that can better describe object in the UI
 
virtual std::string getClassName () const
 return human readable name of subclass
 
MRMESH_API Expected< std::vector< std::future< Expected< void > > > > serializeRecursive (const std::filesystem::path &path, Json::Value &root, int childId) const
 
MRMESH_API Expected< void > deserializeRecursive (const std::filesystem::path &path, const Json::Value &root, ProgressCallback progressCb={}, int *objCounter=nullptr)
 
MRMESH_API void swap (Object &other)
 
virtual Box3f getWorldBox (ViewportId={}) const
 returns bounding box of this object in world coordinates for default or specific viewport
 
MRMESH_API Box3f getWorldTreeBox (ViewportId={}) const
 returns bounding box of this object and all children visible in given (or default) viewport in world coordinates
 
virtual bool hasVisualRepresentation () const
 does the object have any visual representation (visible points, triangles, edges, etc.), no considering child objects
 
virtual bool hasModel () const
 
virtual MRMESH_API size_t heapBytes () const
 returns the amount of memory this object occupies on heap
 
 Object (ProtectedStruct, const Object &obj)
 
- Public Member Functions inherited from MR::ObjectChildrenHolder
 ObjectChildrenHolder ()=default
 
 ObjectChildrenHolder (const ObjectChildrenHolder &) noexcept
 
ObjectChildrenHolderoperator= (const ObjectChildrenHolder &) noexcept
 
MRMESH_API ObjectChildrenHolder (ObjectChildrenHolder &&) noexcept
 
MRMESH_API ObjectChildrenHolderoperator= (ObjectChildrenHolder &&) noexcept
 
MRMESH_API ~ObjectChildrenHolder ()
 
MRMESH_API std::shared_ptr< ObjectgetSharedPtr () const
 
MRMESH_API size_t heapBytes () const
 

Static Public Member Functions

static constexpr const char * TypeName () noexcept
 

Public Attributes

XfChangedSignal worldXfChangedSignal
 

Protected Member Functions

 Object (const Object &obj)=default
 user should not be able to call copy implicitly, use clone() function instead
 
virtual MRMESH_API void swapBase_ (Object &other)
 swaps whole object (signals too)
 
virtual MRMESH_API void swapSignals_ (Object &other)
 
virtual MRMESH_API Expected< std::future< Expected< void > > > serializeModel_ (const std::filesystem::path &path) const
 
virtual MRMESH_API void serializeFields_ (Json::Value &root) const
 
virtual MRMESH_API Expected< void > deserializeModel_ (const std::filesystem::path &path, ProgressCallback progressCb={})
 Reads model from file.
 
virtual MRMESH_API void deserializeFields_ (const Json::Value &root)
 
virtual MRMESH_API void propagateWorldXfChangedSignal_ ()
 

Protected Attributes

std::string name_
 
ViewportProperty< AffineXf3f > xf_
 
ViewportMask visibilityMask_ = ViewportMask::all()
 
bool locked_ = false
 
bool parentLocked_ = false
 
bool selected_ { false }
 
bool ancillary_ { false }
 
bool needRedraw_ {false}
 
- Protected Attributes inherited from MR::ObjectChildrenHolder
ObjectChildrenHolderparent_ = nullptr
 
std::vector< std::shared_ptr< Object > > children_
 
std::vector< std::weak_ptr< Object > > bastards_
 recognized ones
 

Detailed Description

named object in the data model

Member Typedef Documentation

◆ XfChangedSignal

signal about xf changing triggered in setXf and setWorldXf, it is called for children too triggered in addChild and addChildBefore, it is called only for children object

Constructor & Destructor Documentation

◆ Object() [1/4]

MR::Object::Object ( )
default

◆ Object() [2/4]

MR::Object::Object ( Object && )
defaultnoexcept

◆ ~Object()

virtual MR::Object::~Object ( )
virtualdefault

◆ Object() [3/4]

MR::Object::Object ( ProtectedStruct ,
const Object & obj )
inline
Note
this ctor is public only for std::make_shared used inside clone()

◆ Object() [4/4]

MR::Object::Object ( const Object & obj)
protecteddefault

user should not be able to call copy implicitly, use clone() function instead

Member Function Documentation

◆ addChild()

virtual MRMESH_API bool MR::Object::addChild ( std::shared_ptr< Object > child,
bool recognizedChild = true )
virtual

adds given object at the end of children (recognized or not); returns false if it was already child of this, of if given pointer is empty; child object will always report this as parent after the call;

Parameters
recognizedChildif set to false then child object will be excluded from children() and it will be stored by weak_ptr

◆ addChildBefore()

virtual MRMESH_API bool MR::Object::addChildBefore ( std::shared_ptr< Object > newChild,
const std::shared_ptr< Object > & existingChild )
virtual

adds given object in the recognized children before existingChild; if newChild was already among this children then moves it just before existingChild keeping the order of other children intact; returns false if newChild is nullptr, or existingChild is not a child of this

◆ applyScale()

virtual MRMESH_API void MR::Object::applyScale ( float scaleFactor)
virtual

◆ asType() [1/2]

template<typename T >
T * MR::Object::asType ( )
inline

◆ asType() [2/2]

template<typename T >
const T * MR::Object::asType ( ) const
inline

◆ children() [1/2]

const std::vector< std::shared_ptr< Object > > & MR::Object::children ( )
inline

an object can hold other sub-objects

◆ children() [2/2]

const std::vector< std::shared_ptr< const Object > > & MR::Object::children ( ) const
inline

◆ clone()

◆ cloneTree()

MRMESH_API std::shared_ptr< Object > MR::Object::cloneTree ( ) const

clones all tree of this object (except ancillary and unrecognized children)

◆ deserializeFields_()

virtual MRMESH_API void MR::Object::deserializeFields_ ( const Json::Value & root)
protectedvirtual

◆ deserializeModel_()

virtual MRMESH_API Expected< void > MR::Object::deserializeModel_ ( const std::filesystem::path & path,
ProgressCallback progressCb = {} )
protectedvirtual

◆ deserializeRecursive()

MRMESH_API Expected< void > MR::Object::deserializeRecursive ( const std::filesystem::path & path,
const Json::Value & root,
ProgressCallback progressCb = {},
int * objCounter = nullptr )

loads subtree into this Object models from the folder by given path and fields from given JSON

◆ detachFromParent()

virtual MRMESH_API bool MR::Object::detachFromParent ( )
virtual

removes this from its parent children list returns false if it was already orphan

◆ find() [1/4]

template<typename T >
std::shared_ptr< T > MR::Object::find ( )
inline

◆ find() [2/4]

std::shared_ptr< Object > MR::Object::find ( const std::string_view & name)
inline

◆ find() [3/4]

template<typename T >
std::shared_ptr< T > MR::Object::find ( const std::string_view & name)
inline

◆ find() [4/4]

MRMESH_API std::shared_ptr< const Object > MR::Object::find ( const std::string_view & name) const

finds a direct child by name

◆ findCommonAncestor() [1/2]

const Object * MR::Object::findCommonAncestor ( const Object & other) const
inlinenodiscard

◆ findCommonAncestor() [2/2]

MRMESH_API Object * MR::Object::findCommonAncestor ( Object & other)
nodiscard

Find a common ancestor between this object and the other one. Returns null on failure (which is impossible if both are children of the scene root). Will return this if other matches this.

◆ getClassName()

◆ getInfoLines()

virtual MRMESH_API std::vector< std::string > MR::Object::getInfoLines ( ) const
virtual

◆ getRedrawFlag()

virtual bool MR::Object::getRedrawFlag ( ViewportMask ) const
inlinevirtual

this method virtual because others data model types could have dirty flags or something

Reimplemented in MR::ObjectMeshHolder, and MR::VisualObject.

◆ getWorldBox()

virtual Box3f MR::Object::getWorldBox ( ViewportId = {}) const
inlinevirtual

returns bounding box of this object in world coordinates for default or specific viewport

Reimplemented in MR::ObjectLabel, MR::ObjectLinesHolder, MR::ObjectMeshHolder, MR::ObjectPointsHolder, and MR::VisualObject.

◆ getWorldTreeBox()

MRMESH_API Box3f MR::Object::getWorldTreeBox ( ViewportId = {}) const

returns bounding box of this object and all children visible in given (or default) viewport in world coordinates

empty box

◆ globalVisibility()

bool MR::Object::globalVisibility ( ViewportMask viewportMask = ViewportMask::any()) const
inline

returns true if this object is visible together with all its parents in any of given viewports

◆ globalVisibilityMask()

MRMESH_API ViewportMask MR::Object::globalVisibilityMask ( ) const

returns all viewports where this object is visible together with all its parents

◆ hasModel()

virtual bool MR::Object::hasModel ( ) const
inlinenodiscardvirtual

does the object have any model available (but possibly empty), e.g. ObjectMesh has valid mesh() or ObjectPoints has valid pointCloud()

Reimplemented in MR::ObjectDistanceMap, MR::ObjectLinesHolder, MR::ObjectMeshHolder, MR::ObjectPointsHolder, and MR::ObjectVoxels.

◆ hasVisualRepresentation()

virtual bool MR::Object::hasVisualRepresentation ( ) const
inlinenodiscardvirtual

does the object have any visual representation (visible points, triangles, edges, etc.), no considering child objects

Reimplemented in MR::ObjectImGuiLabel, MR::ObjectLabel, MR::ObjectLinesHolder, MR::ObjectMeshHolder, MR::ObjectPointsHolder, and MR::ObjectVoxels.

◆ heapBytes()

virtual MRMESH_API size_t MR::Object::heapBytes ( ) const
nodiscardvirtual

◆ isAncestor()

MRMESH_API bool MR::Object::isAncestor ( const Object * ancestor) const

return true if given object is ancestor of this one, false otherwise

◆ isAncillary()

bool MR::Object::isAncillary ( ) const
inline

◆ isLocked()

bool MR::Object::isLocked ( ) const
inline

object properties lock for UI

◆ isParentLocked()

bool MR::Object::isParentLocked ( ) const
inlinenodiscard

If true, the scene tree GUI doesn't allow you to drag'n'drop this object into a different parent. Defaults to false.

◆ isSelected()

◆ isVisible()

bool MR::Object::isVisible ( ViewportMask viewportMask = ViewportMask::any()) const
inline

checks whether the object is visible in any of the viewports specified by the mask (by default in any viewport)

◆ name()

const std::string & MR::Object::name ( ) const
inline

◆ operator=()

Object & MR::Object::operator= ( Object && )
defaultnoexcept

◆ parent() [1/2]

Object * MR::Object::parent ( )
inline

◆ parent() [2/2]

const Object * MR::Object::parent ( ) const
inline

returns parent object in the tree

◆ propagateWorldXfChangedSignal_()

virtual MRMESH_API void MR::Object::propagateWorldXfChangedSignal_ ( )
protectedvirtual

◆ removeAllChildren()

virtual MRMESH_API void MR::Object::removeAllChildren ( )
virtual

detaches all recognized children from this, keeping all unrecognized ones

◆ removeChild() [1/2]

bool MR::Object::removeChild ( const std::shared_ptr< Object > & child)
inline

returns false if it was not child of this

◆ removeChild() [2/2]

virtual MRMESH_API bool MR::Object::removeChild ( Object * child)
virtual

◆ resetRedrawFlag()

void MR::Object::resetRedrawFlag ( ) const
inline

◆ resetXf()

virtual MRMESH_API void MR::Object::resetXf ( ViewportId id = {})
virtual

forgets specific transform in given viewport (or forgets all specific transforms for {} input)

Reimplemented in MR::FeatureObject.

◆ select()

virtual MRMESH_API bool MR::Object::select ( bool on)
virtual

selects the object, returns true if value changed, otherwise returns false

Reimplemented in MR::ObjectGcode, and MR::SceneRootObject.

◆ serializeFields_()

◆ serializeModel_()

virtual MRMESH_API Expected< std::future< Expected< void > > > MR::Object::serializeModel_ ( const std::filesystem::path & path) const
protectedvirtual

Creates future to save object model (e.g. mesh) in given file path is full filename without extension

Reimplemented in MR::CircleObject, MR::ConeObject, MR::CylinderObject, MR::LineObject, MR::ObjectDistanceMap, MR::ObjectMeshHolder, MR::ObjectPointsHolder, MR::ObjectVoxels, MR::PlaneObject, MR::PointObject, and MR::SphereObject.

◆ serializeRecursive()

MRMESH_API Expected< std::vector< std::future< Expected< void > > > > MR::Object::serializeRecursive ( const std::filesystem::path & path,
Json::Value & root,
int childId ) const

creates futures that save this object subtree: models in the folder by given path and fields in given JSON

Parameters
childIdis its ordinal number within the parent

◆ setAncillary()

virtual MRMESH_API void MR::Object::setAncillary ( bool ancillary)
virtual

ancillary object is an object hidden (in scene menu) from a regular user such objects cannot be selected, and if it has been selected, it is unselected when turn ancillary

Reimplemented in MR::SceneRootObject.

◆ setGlobalVisibility()

MRMESH_API void MR::Object::setGlobalVisibility ( bool on,
ViewportMask viewportMask = ViewportMask::any() )

if true sets all predecessors visible, otherwise sets this object invisible

◆ setLocked()

virtual void MR::Object::setLocked ( bool on)
inlinevirtual

◆ setName()

virtual void MR::Object::setName ( std::string name)
inlinevirtual

Reimplemented in MR::SceneRootObject.

◆ setParentLocked()

virtual void MR::Object::setParentLocked ( bool lock)
inlinevirtual

◆ setVisibilityMask()

virtual MRMESH_API void MR::Object::setVisibilityMask ( ViewportMask viewportMask)
virtual

specifies object visibility as bitmask of viewports

◆ setVisible()

MRMESH_API void MR::Object::setVisible ( bool on,
ViewportMask viewportMask = ViewportMask::all() )

sets the object visible in the viewports specified by the mask (by default in all viewports)

◆ setWorldXf()

MRMESH_API void MR::Object::setWorldXf ( const AffineXf3f & xf,
ViewportId id = {} )

◆ setXf()

virtual MRMESH_API void MR::Object::setXf ( const AffineXf3f & xf,
ViewportId id = {} )
virtual

Reimplemented in MR::FeatureObject.

◆ setXfsForAllViewports()

virtual void MR::Object::setXfsForAllViewports ( ViewportProperty< AffineXf3f > xf)
inlinevirtual

modifies xfs for all viewports at once

◆ shallowClone()

◆ shallowCloneTree()

MRMESH_API std::shared_ptr< Object > MR::Object::shallowCloneTree ( ) const

clones all tree of this object (except ancillary and unrecognied children) clones only pointers to mesh, points or voxels

◆ sortChildren()

MRMESH_API void MR::Object::sortChildren ( )

sort recognized children by name

◆ swap()

MRMESH_API void MR::Object::swap ( Object & other)

swaps this object with other note: do not swap object signals, so listeners will get notifications from swapped object requires implementation of swapBase_ and swapSignals_ (if type has signals)

◆ swapBase_()

◆ swapSignals_()

virtual MRMESH_API void MR::Object::swapSignals_ ( Object & other)
protectedvirtual

swaps signals, used in swap function to return back signals after swapBase_

Note
pls call Parent::swapSignals_ first when overriding this function

Reimplemented in MR::ObjectGcode, MR::ObjectLines, MR::ObjectMesh, MR::ObjectMeshHolder, MR::ObjectPoints, MR::ObjectPointsHolder, and MR::ObjectVoxels.

◆ TypeName()

static constexpr const char * MR::Object::TypeName ( )
inlinestaticconstexprnoexcept

◆ typeName()

◆ visibilityMask()

virtual ViewportMask MR::Object::visibilityMask ( ) const
inlinevirtual

gets object visibility as bitmask of viewports

◆ worldXf()

MRMESH_API AffineXf3f MR::Object::worldXf ( ViewportId id = {},
bool * isDef = nullptr ) const

this space to world space transformation for default or specific viewport

Parameters
isDefreceives true if the object has default transformation in this viewport (same as worldXf() returns)

◆ xf()

const AffineXf3f & MR::Object::xf ( ViewportId id = {},
bool * isDef = nullptr ) const
inline

this space to parent space transformation (to world space if no parent) for default or given viewport

Parameters
isDefreceives true if the object has default transformation in this viewport (same as xf() returns)

◆ xfsForAllViewports()

const ViewportProperty< AffineXf3f > & MR::Object::xfsForAllViewports ( ) const
inline

returns xfs for all viewports, combined into a single object

Member Data Documentation

◆ ancillary_

bool MR::Object::ancillary_ { false }
protected

◆ locked_

bool MR::Object::locked_ = false
protected

◆ name_

std::string MR::Object::name_
protected

◆ needRedraw_

bool MR::Object::needRedraw_ {false}
mutableprotected

◆ parentLocked_

bool MR::Object::parentLocked_ = false
protected

◆ selected_

bool MR::Object::selected_ { false }
protected

◆ visibilityMask_

ViewportMask MR::Object::visibilityMask_ = ViewportMask::all()
protected

◆ worldXfChangedSignal

XfChangedSignal MR::Object::worldXfChangedSignal

◆ xf_

ViewportProperty<AffineXf3f> MR::Object::xf_
protected

The documentation for this class was generated from the following file: