Commit a6fd0d53 authored by Bob Obara's avatar Bob Obara Committed by Kitware Robot

Merge topic 'addingUserDataClasses'

d7943374 ENH: Adding UserDataClasses
69f5e10b DOC: Adding Release Issue Template to SMTK's GitLab
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: John Tourtellott's avatarJohn Tourtellott <john.tourtellott@kitware.com>
Merge-request: !1447
parents 0a1a7366 d7943374
Pipeline #128020 running with stage
......@@ -39,7 +39,7 @@ git tag -a -m 'SMTK VERSION' vVERSION HEAD
- Integrate changes to `release` branch
- [ ] `git push origin update-to-vVERSION:release vVERSION`
- Update documentation page
- Update documentation page
- [ ] See `https://github.com/Kitware/paraview-docs/blob/gh-pages/versions.json`
# Upload documentation
......
# Changes made to Simulation Namespace
## General Changes
* Added UserData classes to represent Ints, Doubles, and Strings
......@@ -12,6 +12,7 @@
#include "smtk/attribute/Definition.h"
#include "smtk/attribute/Resource.h"
#include "smtk/attribute/StringItemDefinition.h"
#include "smtk/simulation/UserData.h"
#include <iostream>
......@@ -92,6 +93,41 @@ int unitAttributeBasics(int, char* [])
att->setAppliesToInteriorNodes(false);
smtkTest(!att->appliesToInteriorNodes(), "Should not applied to interior node.");
smtkTest(att->resource() == resptr, "Should be this resource.");
// Lets test the UserData Interface
auto data = smtk::simulation::UserDataInt::New();
auto dataI = std::dynamic_pointer_cast<smtk::simulation::UserDataInt>(data);
dataI->setValue(10);
data = smtk::simulation::UserDataString::New();
auto dataS = std::dynamic_pointer_cast<smtk::simulation::UserDataString>(data);
dataS->setValue("foo");
att->setUserData("dataInt", dataI);
att->setUserData("dataString", dataS);
data = att->userData("dataFoo");
smtkTest(data == nullptr, "Should not have found user data dataFoo");
data = att->userData("dataInt");
smtkTest(data != nullptr, "Should have found user data dataInt");
dataI = std::dynamic_pointer_cast<smtk::simulation::UserDataInt>(data);
smtkTest(dataI != nullptr, "Should have found user data dataInt as Integer Data");
smtkTest(dataI->value() == 10,
"DataInt should have value 10 but instead has value : " << dataI->value());
data = att->userData("dataString");
smtkTest(data != nullptr, "Should have found user data dataString");
dataS = std::dynamic_pointer_cast<smtk::simulation::UserDataString>(data);
smtkTest(dataS != nullptr, "Should have found user data dataString as String Data");
smtkTest(dataS->value() == "foo",
"DataString should have value foo but instead has value : " << dataS->value());
att->clearUserData("dataInt");
data = att->userData("dataInt");
smtkTest(data == nullptr, "Should not have found user data dataInt");
data = att->userData("dataString");
smtkTest(data != nullptr, "Should have found user data dataString after clearing dataInt");
att->clearAllUserData();
data = att->userData("dataString");
smtkTest(
data == nullptr, "Should not have found user data dataString after clearing all user data");
resptr = nullptr;
smtkTest(wresptr.lock() == nullptr, "Resource was not destroyed") return status;
}
......@@ -18,6 +18,7 @@ Requires smtkCorePython.so to be in module path
import smtk
from smtk import attribute
from smtk import simulation
if __name__ == '__main__':
import sys
......@@ -93,6 +94,50 @@ if __name__ == '__main__':
if att.appliesToInteriorNodes():
print("Should not applies to interior node.\n")
status = -1
# Testing User Data methods
dataI = smtk.simulation.UserDataInt.New()
dataI.setValue(10)
att.setUserData("dataInt", dataI)
dataS = smtk.simulation.UserDataString.New()
dataS.setValue("foo")
att.setUserData("dataString", dataS)
data = att.userData("bar")
if data is not None:
print ("Should not have found user data bar.\n")
status = -1
data = att.userData("dataInt")
if data is None:
print ("Can not find user data dataInt.\n")
status = -1
else:
if data.value() != 10:
print ("dataInt is not 10.\n")
status = -1
data = att.userData("dataString")
if data is None:
print ("Can not find user data dataString.\n")
status = -1
else:
if data.value() != "foo":
print ("dataString is not foo.\n")
status = -1
att.clearUserData("dataInt")
data = att.userData("dataInt")
if data is not None:
print ("Found user data dataInt after trying to clear it.\n")
status = -1
data = att.userData("dataString")
if data is None:
print (
"Can not find user data dataString after removing dataInt from user data.\n")
status = -1
att.clearAllUserData()
data = att.userData("dataString")
if data is not None:
print ("Found user data dataString after removing all user data.\n")
status = -1
if status == 0:
print ("Passed all User Data Tests.\n")
# if att.resource() is not None:
# print("Should not be null.\n")
# status = -1
......
......@@ -22,5 +22,31 @@ UserData::~UserData()
{
}
UserDataInt::UserDataInt()
: m_value(0)
{
}
UserDataInt::~UserDataInt()
{
}
UserDataDouble::UserDataDouble()
: m_value(0.0)
{
}
UserDataDouble::~UserDataDouble()
{
}
UserDataString::UserDataString()
{
}
UserDataString::~UserDataString()
{
}
} // namespace simulation
} // namespace smtk
......@@ -36,6 +36,65 @@ protected:
UserData();
};
// User Data Representing Integers
class SMTKCORE_EXPORT UserDataInt : public UserData
{
public:
static smtk::simulation::UserDataPtr New()
{
return smtk::simulation::UserDataPtr(new UserDataInt());
}
int value() const { return m_value; }
void setValue(int val) { m_value = val; }
virtual ~UserDataInt();
protected:
UserDataInt();
int m_value;
};
// User Data Representing Doubles
class SMTKCORE_EXPORT UserDataDouble : public UserData
{
public:
static smtk::simulation::UserDataPtr New()
{
return smtk::simulation::UserDataPtr(new UserDataDouble());
}
double value() const { return m_value; }
void setValue(double val) { m_value = val; }
virtual ~UserDataDouble();
protected:
UserDataDouble();
double m_value;
};
// User Data Representing Strings
class SMTKCORE_EXPORT UserDataString : public UserData
{
public:
static smtk::simulation::UserDataPtr New()
{
return smtk::simulation::UserDataPtr(new UserDataString());
}
const std::string& value() const { return m_value; }
void setValue(const std::string& val) { m_value = val; }
virtual ~UserDataString();
protected:
UserDataString();
std::string m_value;
};
} // namespace simulation
} // namespace smtk
......
......@@ -33,5 +33,8 @@ PYBIND11_MODULE(_smtkPybindSimulation, simulation)
// The order of these function calls is important! It was determined by
// comparing the dependencies of each of the wrapped objects.
py::class_< smtk::simulation::ExportSpec > smtk_simulation_ExportSpec = pybind11_init_smtk_simulation_ExportSpec(simulation);
py::class_< smtk::simulation::UserData > smtk_simulation_UserData = pybind11_init_smtk_simulation_UserData(simulation);
PySharedPtrClass< smtk::simulation::UserData > smtk_simulation_UserData = pybind11_init_smtk_simulation_UserData(simulation);
PySharedPtrClass< smtk::simulation::UserDataInt > smtk_simulation_UserDataInt = pybind11_init_smtk_simulation_UserDataInt(simulation);
PySharedPtrClass< smtk::simulation::UserDataDouble > smtk_simulation_UserDataDouble = pybind11_init_smtk_simulation_UserDataDouble(simulation);
PySharedPtrClass< smtk::simulation::UserDataString > smtk_simulation_UserDataString = pybind11_init_smtk_simulation_UserDataString(simulation);
}
......@@ -17,9 +17,9 @@
namespace py = pybind11;
py::class_< smtk::simulation::UserData > pybind11_init_smtk_simulation_UserData(py::module &m)
PySharedPtrClass< smtk::simulation::UserData > pybind11_init_smtk_simulation_UserData(py::module &m)
{
py::class_< smtk::simulation::UserData > instance(m, "UserData");
PySharedPtrClass< smtk::simulation::UserData > instance(m, "UserData");
instance
.def(py::init<::smtk::simulation::UserData const &>())
.def("deepcopy", (smtk::simulation::UserData & (smtk::simulation::UserData::*)(::smtk::simulation::UserData const &)) &smtk::simulation::UserData::operator=)
......@@ -28,4 +28,43 @@ py::class_< smtk::simulation::UserData > pybind11_init_smtk_simulation_UserData(
return instance;
}
PySharedPtrClass< smtk::simulation::UserDataInt, smtk::simulation::UserData > pybind11_init_smtk_simulation_UserDataInt(py::module &m)
{
PySharedPtrClass< smtk::simulation::UserDataInt, smtk::simulation::UserData > instance(m, "UserDataInt");
instance
.def(py::init<::smtk::simulation::UserDataInt const &>())
.def("deepcopy", (smtk::simulation::UserDataInt & (smtk::simulation::UserDataInt::*)(::smtk::simulation::UserDataInt const &)) &smtk::simulation::UserDataInt::operator=)
.def_static("New", &smtk::simulation::UserDataInt::New)
.def("value", &smtk::simulation::UserDataInt::value)
.def("setValue", &smtk::simulation::UserDataInt::setValue, py::arg("value"))
;
return instance;
}
PySharedPtrClass< smtk::simulation::UserDataDouble, smtk::simulation::UserData > pybind11_init_smtk_simulation_UserDataDouble(py::module &m)
{
PySharedPtrClass< smtk::simulation::UserDataDouble, smtk::simulation::UserData > instance(m, "UserDataDouble");
instance
.def(py::init<::smtk::simulation::UserDataDouble const &>())
.def("deepcopy", (smtk::simulation::UserDataDouble & (smtk::simulation::UserDataDouble::*)(::smtk::simulation::UserDataDouble const &)) &smtk::simulation::UserDataDouble::operator=)
.def_static("New", &smtk::simulation::UserDataDouble::New)
.def("value", &smtk::simulation::UserDataDouble::value)
.def("setValue", &smtk::simulation::UserDataDouble::setValue, py::arg("value"))
;
return instance;
}
PySharedPtrClass< smtk::simulation::UserDataString, smtk::simulation::UserData > pybind11_init_smtk_simulation_UserDataString(py::module &m)
{
PySharedPtrClass< smtk::simulation::UserDataString, smtk::simulation::UserData > instance(m, "UserDataString");
instance
.def(py::init<::smtk::simulation::UserDataString const &>())
.def("deepcopy", (smtk::simulation::UserDataString & (smtk::simulation::UserDataString::*)(::smtk::simulation::UserDataString const &)) &smtk::simulation::UserDataString::operator=)
.def_static("New", &smtk::simulation::UserDataString::New)
.def("value", &smtk::simulation::UserDataString::value)
.def("setValue", &smtk::simulation::UserDataString::setValue, py::arg("value"))
;
return instance;
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment