Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Ben Boeckel
SMTK
Commits
fa6832df
Commit
fa6832df
authored
Oct 20, 2017
by
David Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some syntactic sugar...
... to ease conversions between Entity and EntityRef.
parent
4cb3f9a1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
4 deletions
+54
-4
smtk/model/Entity.h
smtk/model/Entity.h
+7
-0
smtk/model/EntityRef.cxx
smtk/model/EntityRef.cxx
+21
-0
smtk/model/EntityRef.h
smtk/model/EntityRef.h
+11
-4
smtk/model/testing/cxx/unitEntityRef.cxx
smtk/model/testing/cxx/unitEntityRef.cxx
+15
-0
No files found.
smtk/model/Entity.h
View file @
fa6832df
...
...
@@ -62,6 +62,13 @@ public:
ResourcePtr
resource
()
const
override
;
ManagerPtr
modelResource
()
const
;
/// Return the templated object (usually EntityRef or a subclass) that points to this component.
template
<
typename
T
>
T
referenceAs
()
const
{
return
T
(
this
->
modelResource
(),
this
->
id
());
}
bool
reparent
(
ManagerPtr
newParent
);
int
dimension
()
const
;
...
...
smtk/model/EntityRef.cxx
View file @
fa6832df
...
...
@@ -50,6 +50,16 @@ EntityRef::EntityRef(ManagerPtr mgr, const smtk::common::UUID& inEntity)
{
}
/// Construct a entityref referencing a given \a entity residing in the given \a mgr.
EntityRef
::
EntityRef
(
EntityPtr
src
)
{
if
(
src
)
{
m_manager
=
src
->
modelResource
();
m_entity
=
src
->
id
();
}
}
/// Change the underlying manager the entityref references.
bool
EntityRef
::
setManager
(
ManagerPtr
mgr
)
{
...
...
@@ -89,6 +99,17 @@ const smtk::common::UUID& EntityRef::entity() const
return
this
->
m_entity
;
}
/// Return the smtk::model::Entity record for this model entity.
smtk
::
model
::
EntityPtr
EntityRef
::
entityRecord
()
const
{
auto
mgr
=
this
->
manager
();
if
(
!
mgr
)
{
return
nullptr
;
}
return
mgr
->
findEntity
(
this
->
m_entity
,
true
);
}
/// Return the resource component for this model entity.
smtk
::
resource
::
ComponentPtr
EntityRef
::
component
()
const
{
...
...
smtk/model/EntityRef.h
View file @
fa6832df
...
...
@@ -7,8 +7,7 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#ifndef __smtk_model_EntityRef_h
#define __smtk_model_EntityRef_h
#pragma once
/*! \file */
#include "smtk/CoreExports.h" // For EXPORT macro.
...
...
@@ -51,6 +50,14 @@ class MeshSet;
: superclass(inManager, entityId) \
{ \
} \
thisclass(EntityPtr src) \
{ \
if (src) \
{ \
m_manager = src->modelResource(); \
m_entity = src->id(); \
} \
} \
virtual ~thisclass() {}
/* Avoid warnings about non-virtual destructor */
\
bool isValid() const { return this->EntityRef::isValid(); } \
bool isValid(EntityPtr* entRec) const override \
...
...
@@ -94,6 +101,7 @@ public:
SMTK_BASE_TYPE
(
EntityRef
);
EntityRef
();
EntityRef
(
ManagerPtr
manager
,
const
smtk
::
common
::
UUID
&
entityId
);
EntityRef
(
EntityPtr
src
);
bool
setManager
(
ManagerPtr
manager
);
ManagerPtr
manager
();
...
...
@@ -102,6 +110,7 @@ public:
bool
setEntity
(
const
smtk
::
common
::
UUID
&
entityId
);
const
smtk
::
common
::
UUID
&
entity
()
const
;
smtk
::
model
::
EntityPtr
entityRecord
()
const
;
smtk
::
resource
::
ComponentPtr
component
()
const
;
int
dimension
()
const
;
...
...
@@ -415,5 +424,3 @@ EntityRef& EntityRef::removeMemberEntities(T begin, T end)
}
// namespace model
}
// namespace smtk
#endif // __smtk_model_EntityRef_h
smtk/model/testing/cxx/unitEntityRef.cxx
View file @
fa6832df
...
...
@@ -210,6 +210,20 @@ void testModelMethods()
test
(
m1
.
session
()
==
m0
.
session
(),
"Expected sessions to match for model and its submodel."
);
}
void
testResourceComponentConversion
()
{
ManagerPtr
sm
=
Manager
::
create
();
SessionRef
sess
=
sm
->
createSession
(
"native"
);
Model
m0
=
sm
->
addModel
();
smtk
::
model
::
EntityPtr
mep
=
m0
.
entityRecord
();
test
(
!!
mep
,
"No component for Model entity-ref."
);
test
(
mep
->
referenceAs
<
smtk
::
model
::
Model
>
()
==
m0
,
"Could not convert from component to ref."
);
test
(
smtk
::
model
::
Model
(
mep
)
==
m0
,
"Could not convert from ref to component."
);
smtk
::
resource
::
ComponentPtr
cmp
=
m0
.
component
();
test
(
cmp
==
smtk
::
dynamic_pointer_cast
<
smtk
::
resource
::
Component
>
(
mep
),
"Component/Entity mismatch."
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
(
void
)
argc
;
...
...
@@ -559,6 +573,7 @@ int main(int argc, char* argv[])
testTemplatedPropertyMethods
();
testVolumeEntityRef
();
testModelMethods
();
testResourceComponentConversion
();
}
catch
(
const
std
::
string
&
msg
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment