-
Notifications
You must be signed in to change notification settings - Fork 147
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
Conversation
src/conv/k-g/k-g.cpp
Outdated
@@ -122,6 +122,8 @@ int main | |||
bot.addTriangle(point1, point3, point4); | |||
} | |||
} | |||
|
|||
regions.setAttributes(partName,(it->second).attributes); |
There was a problem hiding this comment.
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.
src/conv/k-g/k_parser.cpp
Outdated
} | ||
else { | ||
std::cout << "Attributes should come in pairs in k-file" << fileName << "\n"; | ||
break; |
There was a problem hiding this comment.
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.
src/conv/k-g/region_list.cpp
Outdated
bu_avs_add(avs, it->first.c_str(), it->second.c_str()); | ||
} | ||
|
||
bu_avs_print(avs, name); |
There was a problem hiding this comment.
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.
src/conv/k-g/region_list.cpp
Outdated
dbip = wdbp->dbip; | ||
dp = db_lookup(dbip, name, 0); | ||
|
||
rt_db_get_internal(®ion_internal, dp, dbip, bn_mat_identity, &rt_uniresource); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/conv/k-g/region_list.cpp
Outdated
struct rt_db_internal region_internal; | ||
struct directory* dp; | ||
struct db_i* dbip; | ||
bu_attribute_value_set* avs; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/conv/k-g/region_list.h
Outdated
|
||
class RegionList { | ||
public: | ||
RegionList(void); | ||
|
||
Bot& addRegion(const std::string& name); | ||
|
||
Bot& getBot(const std::string& name); | ||
Bot& getBot(const std::string& name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why so many spaces?
There was a problem hiding this comment.
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 :)
src/conv/k-g/region_list.cpp
Outdated
|
||
rt_db_get_internal(®ion_internal, dp, dbip, bn_mat_identity, &rt_uniresource); | ||
avs = ®ion_internal.idb_avs; | ||
rt_db_get_internal(®ion_internal, dp, dbip, NULL, &rt_uniresource); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
src/conv/k-g/region_list.cpp
Outdated
return; | ||
} | ||
|
||
if (rt_db_get_internal(®ion_internal, dp, dbip, NULL, &rt_uniresource) <= 0) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/conv/k-g/region_list.cpp
Outdated
return; | ||
} | ||
|
||
if (rt_db_get_internal(®ion_internal, dp, dbip, NULL, &rt_uniresource) > 0) { |
There was a problem hiding this comment.
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 😈
There was a problem hiding this comment.
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
This code is written to handle unexpected command *PART_ADAPTIVE_FAILURE by adding it as an attribute to the region.