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

Refactor the abstract class CreateConnectedElementI #1047

Open
wants to merge 1 commit into
base: cpacs_creator_dev_merge
Choose a base branch
from

Conversation

svengoldberg
Copy link
Contributor

Description

In the current implementation of the CPACS Creator, the Wing and Fuselage class are inherited from an abstract class (cf. #1042). We want to avoid this behaviour and fix the code style by removing this class and adding a new std::variant type instead. In the actual code, it is then decided whether the current object is of type Wing or Fuselage and the respective member function is called.
Later on, the variant type can be extended by any other class (such as Duct, Pylon, Tank, ...), if the CPACS Creator should be able to add CPACS elements/sections within the according object.

The general procedure (and whether this is the best way) of course still can be discussed. Nonetheless, @joergbrech and I had a disscussion about it and agreed that using std::variant seems to be a good way to solve this code style issue.

Fix #1042

Task Finished Reviewer Approved
At least one test for the new functionality was added.
  • yes
  • does not apply
  • OK
New classes have been added to the Python interface.
  • yes
  • does not apply
  • OK
The code is properly documented with doxygen docstrings
  • yes
  • does not apply
  • OK
Changes are documented at the top of ChangeLog.md
  • yes
  • does not apply
  • OK

…riant

In the current implementation of the CPACS Creator, the Wing and Fuselage class are inherited from an abstract class. We want to avoid this behaviour and fix the code style by removing this class and adding a new std::variant type instead. In the actual code, it is then decided whether the current object is of type Wing or Fuselage and the respective member function is called.
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.40%. Comparing base (2466e1d) to head (6b8166b).
Report is 11 commits behind head on cpacs_creator_dev_merge.

Additional details and impacted files

Impacted file tree graph

@@                   Coverage Diff                    @@
##           cpacs_creator_dev_merge    #1047   +/-   ##
========================================================
  Coverage                    71.40%   71.40%           
========================================================
  Files                          312      312           
  Lines                        28978    28976    -2     
========================================================
  Hits                         20691    20691           
+ Misses                        8287     8285    -2     
Flag Coverage Δ
unittests 71.40% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/fuselage/CCPACSFuselage.h 100.00% <ø> (ø)
src/wing/CCPACSWing.h 100.00% <ø> (ø)

... and 1 file with indirect coverage changes

createConnectedElementI->CreateNewConnectedElementBefore(startUID);
// Construction to 'unwrap' the std::variant createConnectedElement and apply the defined function from the correct class (which is part of the std::variant)
std::visit(
[startUID](auto& element){
Copy link
Contributor

Choose a reason for hiding this comment

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

You could capture startUID by reference here as well.

Suggested change
[startUID](auto& element){
[&startUID](auto& element){

createConnectedElementI->CreateNewConnectedElementAfter(startUID);
// Construction to 'unwrap' the std::variant createConnectedElement and apply the defined function from the correct class (which is part of the std::variant)
std::visit(
[startUID](auto& element){
Copy link
Contributor

Choose a reason for hiding this comment

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

You could capture startUID by reference here as well

Suggested change
[startUID](auto& element){
[&startUID](auto& element){

createConnectedElementI->DeleteConnectedElement(uid.toStdString());
// Construction to 'unwrap' the std::variant createConnectedElement and apply the defined function from the correct class (which is part of the std::variant)
std::visit(
[uid](auto& element){
Copy link
Contributor

Choose a reason for hiding this comment

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

You could capture uid by reference here as well.

elementI = dynamic_cast<tigl::CreateConnectedElementI* >(&fuselage);
Ui::ElementModificatorInterface* element;
try {
element = reinterpret_cast<Ui::ElementModificatorInterface* >(typePtr.ptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not entirely sure that this is safe. The UIDManager first casts a a CCPACSWing* or a CCPACSFuselage* to a void*. Then you reinterpret_cast this void pointer to a pointer of type ui::ElementModificatorInterface*. This might work, depending on memeroy layout, I really don't know to be honest. It might also result in undefined behavior.

Just to be save, we could go two ways:

  • Redefine the ui::ElementModificatorInterface to be a std:;variant<CCPACSWing*, CCPACSFuselage*>` and create an instance (not a pointer) directly from the wing or fuselage pointer
  • Don't use std::variant at all. Instead, everywhere where you use std::visit currently, you could use the TypedPtr and query the type in an if-then-else.

Currently, I am not sure which I prefer, both have their pros and cons....

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