Skip to content

Commit e3cc52a

Browse files
committed
refactor for using l_info
1 parent 40f088f commit e3cc52a

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/creo2urdf/include/creo2urdf/Creo2Urdf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Creo2Urdf : public pfcUICommandActionListener {
9292
* @brief Populate the exported frame information map from the Creo model handle.
9393
* @param modelhdl The Creo model handle.
9494
*/
95-
void populateExportedFrameInfoMap(pfcModel_ptr modelhdl);
95+
void populateExportedFrameInfoMap(LinkInfo& link_info);
9696

9797
/**
9898
* @brief Read assigned inertias from the loaded YAML configuration.
@@ -115,7 +115,7 @@ class Creo2Urdf : public pfcUICommandActionListener {
115115
* @param mesh_transform The 3D transform associated to the mesh.
116116
* @return True if successful, false otherwise.
117117
*/
118-
bool addMeshAndExport(pfcModel_ptr component_handle, const std::string& mesh_transform);
118+
bool addMeshAndExport(const LinkInfo& link_info);
119119

120120
/**
121121
* @brief Load YAML configuration from a file.

src/creo2urdf/src/Creo2Urdf.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ bool Creo2Urdf::processAsmItems(pfcModelItems_ptr asmListItems, pfcModel_ptr mod
4040
continue;
4141
}
4242

43-
//printToMessageWindow("Processing " + string(component_handle->GetFullName()) + " Owner " + string(model_owner->GetFullName()));
44-
4543
xintsequence_ptr seq = xintsequence::create();
4644
seq->append(asmItemAsFeat->GetId());
4745

@@ -126,10 +124,10 @@ bool Creo2Urdf::processAsmItems(pfcModelItems_ptr asmListItems, pfcModel_ptr mod
126124

127125
LinkInfo l_info{ urdf_link_name, component_handle, parentAsm_H_linkFrame, csysAsm_H_linkFrame, link_frame_name };
128126
link_info_map.insert(std::make_pair(link_name, l_info));
129-
populateExportedFrameInfoMap(component_handle);
127+
populateExportedFrameInfoMap(l_info);
130128

131129
idyn_model.addLink(urdf_link_name, link);
132-
if (!addMeshAndExport(component_handle, link_frame_name)) {
130+
if (!addMeshAndExport(l_info)) {
133131
printToMessageWindow("Failed to export mesh for " + link_name, c2uLogLevel::WARN);
134132
if (warningsAreFatal) {
135133
return false;
@@ -544,12 +542,12 @@ iDynTree::SpatialInertia Creo2Urdf::computeSpatialInertiafromCreo(pfcMassPropert
544542
return sp_inertia;
545543
}
546544

547-
void Creo2Urdf::populateExportedFrameInfoMap(pfcModel_ptr modelhdl) {
545+
void Creo2Urdf::populateExportedFrameInfoMap(LinkInfo& link_info) {
548546

549547
// The revolute joints are defined by aligning along the
550548
// rotational axis
551-
auto link_name = string(modelhdl->GetFullName());
552-
auto csys_list = modelhdl->ListItems(pfcModelItemType::pfcITEM_COORD_SYS);
549+
auto link_name = link_info.name;
550+
auto csys_list = link_info.modelhdl->ListItems(pfcModelItemType::pfcITEM_COORD_SYS);
553551

554552
if (csys_list->getarraysize() == 0) {
555553
printToMessageWindow("There is no CSYS in the part " + link_name, c2uLogLevel::WARN);
@@ -572,14 +570,13 @@ void Creo2Urdf::populateExportedFrameInfoMap(pfcModel_ptr modelhdl) {
572570

573571
if (exported_frame_info_map.find(csys_name) != exported_frame_info_map.end()) {
574572
auto& exported_frame_info = exported_frame_info_map.at(csys_name);
575-
auto& link_info = link_info_map.at(link_name);
576573
bool ret{ false };
577574
iDynTree::Transform csys_H_additionalFrame {iDynTree::Transform::Identity()};
578575
iDynTree::Transform csys_H_linkFrame {iDynTree::Transform::Identity()};
579576
iDynTree::Transform linkFrame_H_additionalFrame {iDynTree::Transform::Identity()};
580577

581-
std::tie(ret, csys_H_additionalFrame) = getTransformFromPart(modelhdl, csys_name, scale);
582-
std::tie(ret, csys_H_linkFrame) = getTransformFromPart(modelhdl, link_info.link_frame_name, scale);
578+
std::tie(ret, csys_H_additionalFrame) = getTransformFromPart(link_info.modelhdl, csys_name, scale);
579+
std::tie(ret, csys_H_linkFrame) = getTransformFromPart(link_info.modelhdl, link_info.link_frame_name, scale);
583580

584581
linkFrame_H_additionalFrame = csys_H_linkFrame.inverse() * csys_H_additionalFrame;
585582
exported_frame_info.linkFrame_H_additionalFrame = linkFrame_H_additionalFrame;
@@ -649,12 +646,12 @@ void Creo2Urdf::readExportedFramesFromConfig() {
649646
}
650647
}
651648

652-
bool Creo2Urdf::addMeshAndExport(pfcModel_ptr component_handle, const std::string& mesh_transform)
649+
bool Creo2Urdf::addMeshAndExport(const LinkInfo& link_info)
653650
{
654651
bool export_mesh = true;
655652
std::string file_extension = ".stl";
656653
std::string meshFormat = "stl_binary";
657-
std::string link_name = component_handle->GetFullName();
654+
std::string link_name = link_info.modelhdl->GetFullName();
658655
std::string renamed_link_name = link_name;
659656

660657
if (config["rename"][link_name].IsDefined())
@@ -717,13 +714,13 @@ bool Creo2Urdf::addMeshAndExport(pfcModel_ptr component_handle, const std::strin
717714

718715
try {
719716
if (meshFormat == "stl_binary") {
720-
component_handle->Export(mesh_file_name.c_str(), pfcExportInstructions::cast(pfcSTLBinaryExportInstructions().Create(mesh_transform.c_str())));
717+
link_info.modelhdl->Export(mesh_file_name.c_str(), pfcExportInstructions::cast(pfcSTLBinaryExportInstructions().Create(link_info.link_frame_name.c_str())));
721718
}
722719
else if(meshFormat =="stl_ascii") {
723-
component_handle->Export(mesh_file_name.c_str(), pfcExportInstructions::cast(pfcSTLASCIIExportInstructions().Create(mesh_transform.c_str())));
720+
link_info.modelhdl->Export(mesh_file_name.c_str(), pfcExportInstructions::cast(pfcSTLASCIIExportInstructions().Create(link_info.link_frame_name.c_str())));
724721
}
725722
else if (meshFormat == "step") {
726-
component_handle->ExportIntf3D(mesh_file_name.c_str(), pfcExportType::pfcEXPORT_STEP);
723+
link_info.modelhdl->ExportIntf3D(mesh_file_name.c_str(), pfcExportType::pfcEXPORT_STEP);
727724
}
728725
else {
729726
return false;

0 commit comments

Comments
 (0)