Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling unexpected command *PART_ADAPTIVE_FAILURE #142

Merged
merged 6 commits into from
Jun 9, 2024

Conversation

AliHaider93
Copy link
Contributor

This code is written to handle unexpected command *PART_ADAPTIVE_FAILURE by adding it as an attribute to the region.

@@ -122,6 +122,8 @@ int main
bot.addTriangle(point1, point3, point4);
}
}

regions.setAttributes(partName,(it->second).attributes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be on the same level as the closing bracket, i.e. 4 spaces back.

}
else {
std::cout << "Attributes should come in pairs in k-file" << fileName << "\n";
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "break" is not needed here. The next one will do it for all.

bu_avs_add(avs, it->first.c_str(), it->second.c_str());
}

bu_avs_print(avs, name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for debugging purpose, but I wouldn't leave it in the final code.

dbip = wdbp->dbip;
dp = db_lookup(dbip, name, 0);

rt_db_get_internal(&region_internal, dp, dbip, bn_mat_identity, &rt_uniresource);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bn_mat_identity and not NULL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I didn't check what it means, now that I checked we are not applying matrix transform on the object and the correct way is to put NULL.

struct rt_db_internal region_internal;
struct directory* dp;
struct db_i* dbip;
bu_attribute_value_set* avs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very much C-style. In C++, you can declare the variables where you need them: declaration = initialization

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right. I will modify it


class RegionList {
public:
RegionList(void);

Bot& addRegion(const std::string& name);

Bot& getBot(const std::string& name);
Bot& getBot(const std::string& name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so many spaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because there was the function const std::map<std::string, std::string> getAttributes() under it and I wanted to kep them next to each other. then we deleted getAttributes() and I forgot to bring it back :)


rt_db_get_internal(&region_internal, dp, dbip, bn_mat_identity, &rt_uniresource);
avs = &region_internal.idb_avs;
rt_db_get_internal(&region_internal, dp, dbip, NULL, &rt_uniresource);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think that it's neccessary to check the id returend by
rt_db_get_internal()==ID_COMBINATION?

Copy link
Member

@drossberg drossberg Jun 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. However, the ID is not so important, because writeAttributes() could write the attributes to any database object. But, you should check if the command was successful, i.e. the return value is >= 0.

Same for dp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they both need testing. I modified the code. please let me know if you have any notes

return;
}

if (rt_db_get_internal(&region_internal, dp, dbip, NULL, &rt_uniresource) <= 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation says that <0 means error, i.e. 0 would be okay too. In addition, even in case of error, region_internal has to be freed. Therefore, why not

if (rt_db_get_internal() >= 0) {
    // write the attributes
    // update database
}
else
    // error message

// free region_internal

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did see in the code that most of the checks where rt_db_get_internal()<0, I think I should read more the documentaion is it the hacking guid you are talking about?. you are right the check you did is better I will modify.

return;
}

if (rt_db_get_internal(&region_internal, dp, dbip, NULL, &rt_uniresource) > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>= 0?
BTW, the documentation I referred to where the comments in the header file include/rt/db_internal.h.

Hmm, it should be in the Doxygen documentation https://brlcad.org/docs/api/ (could be a bit outdated)
https://brlcad.org/docs/api/d2/de5/db__internal_8h.html#a5fabf39a9c6246df52172a92c2a2b221

This are the kind of references you can find only if you know that they exist 😈

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am really sorry it's >=0. I was distracted

@drossberg drossberg merged commit 16f1fc3 into BRL-CAD:devel_k-g Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants