Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
clean
  • Loading branch information
LLipter committed Jan 15, 2024
1 parent 0f7a314 commit a17c288
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/openrave/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,9 @@ class OPENRAVE_API EnvironmentBase : public boost::enable_shared_from_this<Envir

enum EnvironmentInfoField {
EIF_UnitInfo = (1 << 0), // _unitInfo field
EIF_Description = (1 << 1), // _description field
EIF_Keywords = (1 << 2), // _keywords field
EIF_Int64Parameters = (1 << 3), // _uInt64Parameters field
};
inline bool IsModifiedField(EnvironmentInfoField field) const {
return !!(_modifiedFields & field);
Expand Down
6 changes: 6 additions & 0 deletions include/openrave/kinbody.h
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,8 @@ class OPENRAVE_API KinBody : public InterfaceBase
LinkInfoPtr diffInfo = boost::make_shared<KinBody::LinkInfo>();
diffInfo->_id = _info._id;
diffInfo->_vgeometryinfos.push_back(geometryInfo);
diffInfo->_isPartial = true;
diffInfo->_modifiedFields = 0;
_callbackOnModify(diffInfo);
}
}
Expand Down Expand Up @@ -3739,6 +3741,8 @@ class OPENRAVE_API KinBody : public InterfaceBase
KinBodyInfoPtr diffInfo = boost::make_shared<KinBody::KinBodyInfo>();
diffInfo->_id = _id;
diffInfo->_vLinkInfos.push_back(linkInfo);
diffInfo->_isPartial = true;
diffInfo->_modifiedFields = 0;
_callbackOnModify(diffInfo);
}
}
Expand All @@ -3747,6 +3751,8 @@ class OPENRAVE_API KinBody : public InterfaceBase
KinBodyInfoPtr diffInfo = boost::make_shared<KinBody::KinBodyInfo>();
diffInfo->_id = _id;
diffInfo->_vJointInfos.push_back(jointInfo);
diffInfo->_isPartial = true;
diffInfo->_modifiedFields = 0;
_callbackOnModify(diffInfo);
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/libopenrave-core/environment-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2788,6 +2788,9 @@ class Environment : public EnvironmentBase
if (_callbackOnModify != nullptr) {
EnvironmentBaseInfoPtr diffInfo = boost::make_shared<EnvironmentBaseInfo>();
diffInfo->_unitInfo = _unitInfo;
diffInfo->_isPartial = true;
diffInfo->_modifiedFields = 0;
diffInfo->AddModifiedField(EnvironmentBaseInfo::EIF_UnitInfo);
_callbackOnModify(diffInfo);
}
}
Expand Down Expand Up @@ -3252,6 +3255,9 @@ class Environment : public EnvironmentBase
if (_callbackOnModify != nullptr) {
EnvironmentBaseInfoPtr diffInfo = boost::make_shared<EnvironmentBaseInfo>();
diffInfo->_description = _description;
diffInfo->_isPartial = true;
diffInfo->_modifiedFields = 0;
diffInfo->AddModifiedField(EnvironmentBaseInfo::EIF_Description);
_callbackOnModify(diffInfo);
}
}
Expand All @@ -3267,6 +3273,9 @@ class Environment : public EnvironmentBase
if (_callbackOnModify != nullptr) {
EnvironmentBaseInfoPtr diffInfo = boost::make_shared<EnvironmentBaseInfo>();
diffInfo->_keywords = _keywords;
diffInfo->_isPartial = true;
diffInfo->_modifiedFields = 0;
diffInfo->AddModifiedField(EnvironmentBaseInfo::EIF_Keywords);
_callbackOnModify(diffInfo);
}
}
Expand All @@ -3282,6 +3291,9 @@ class Environment : public EnvironmentBase
if (_callbackOnModify != nullptr) {
EnvironmentBaseInfoPtr diffInfo = boost::make_shared<EnvironmentBaseInfo>();
diffInfo->_uInt64Parameters = _mapUInt64Parameters;
diffInfo->_isPartial = true;
diffInfo->_modifiedFields = 0;
diffInfo->AddModifiedField(EnvironmentBaseInfo::EIF_Int64Parameters);
_callbackOnModify(diffInfo);
}
}
Expand Down Expand Up @@ -4352,6 +4364,8 @@ class Environment : public EnvironmentBase
if (_callbackOnModify != nullptr) {
EnvironmentBaseInfoPtr diffInfo = boost::make_shared<EnvironmentBaseInfo>();
diffInfo->_vBodyInfos.push_back(kinBodyInfo);
diffInfo->_isPartial = true;
diffInfo->_modifiedFields = 0;
_callbackOnModify(diffInfo);
}
}
Expand Down
42 changes: 42 additions & 0 deletions src/libopenrave/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,48 @@ void EnvironmentBase::EnvironmentBaseInfo::SerializeJSON(rapidjson::Value& rEnvI
// for all SerializeJSON, we clear the output
rEnvInfo.SetObject();

if (_isPartial) {
if (IsModifiedField(EnvironmentBaseInfo::EIF_UnitInfo)) {
orjson::SetJsonValueByKey(rEnvInfo, "unitInfo", _unitInfo, allocator);
}
if (IsModifiedField(EnvironmentBaseInfo::EIF_Description)) {
orjson::SetJsonValueByKey(rEnvInfo, "description", _description, allocator);
}
if (IsModifiedField(EnvironmentBaseInfo::EIF_Keywords)) {
orjson::SetJsonValueByKey(rEnvInfo, "keywords", _keywords, allocator);
}
if (IsModifiedField(EnvironmentBaseInfo::EIF_Int64Parameters)) {
if( _uInt64Parameters.size() > 0 ) {
rapidjson::Value rUInt64Parameters;
rUInt64Parameters.SetArray();
FOREACHC(it, _uInt64Parameters) {
rapidjson::Value rInt64Parameter;
rInt64Parameter.SetObject();
orjson::SetJsonValueByKey(rInt64Parameter, "id", it->first, allocator);
orjson::SetJsonValueByKey(rInt64Parameter, "value", it->second, allocator);
rUInt64Parameters.PushBack(rInt64Parameter, allocator);
}
rEnvInfo.AddMember("uint64Parameters", rUInt64Parameters, allocator);
}
}

if (_vBodyInfos.size() > 0) {
rapidjson::Value rBodiesValue;
rBodiesValue.SetArray();
rBodiesValue.Reserve(_vBodyInfos.size(), allocator);
for (const KinBody::KinBodyInfoPtr& pinfo : _vBodyInfos) {
if (!pinfo) {
continue;
}
rapidjson::Value bodyValue;
pinfo->SerializeJSON(bodyValue, allocator, fUnitScale, options);
rBodiesValue.PushBack(bodyValue, allocator);
}
rEnvInfo.AddMember("bodies", rBodiesValue, allocator);
}
return;
}

orjson::SetJsonValueByKey(rEnvInfo, "keywords", _keywords, allocator);
if( !_description.empty() ) {
orjson::SetJsonValueByKey(rEnvInfo, "description", _description, allocator);
Expand Down

0 comments on commit a17c288

Please sign in to comment.