From 6b8166bde59128a6560793479fbad96464e1e7fa Mon Sep 17 00:00:00 2001 From: Sven Goldberg Date: Thu, 19 Dec 2024 17:57:51 +0100 Subject: [PATCH 1/2] Refactor the abstract class CreateConnectedElementI by adding std::variant 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. --- TIGLViewer/src/ModificatorContainerWidget.cpp | 6 +- TIGLViewer/src/ModificatorContainerWidget.h | 3 +- TIGLViewer/src/ModificatorManager.cpp | 17 ++-- .../ModificatorSectionsWidget.cpp | 54 +++++++++--- .../modificators/ModificatorSectionsWidget.h | 11 ++- src/fuselage/CCPACSFuselage.h | 13 ++- src/geometry/CreateConnectedElementI.h | 84 ------------------- src/wing/CCPACSWing.h | 13 ++- 8 files changed, 75 insertions(+), 126 deletions(-) delete mode 100644 src/geometry/CreateConnectedElementI.h diff --git a/TIGLViewer/src/ModificatorContainerWidget.cpp b/TIGLViewer/src/ModificatorContainerWidget.cpp index b7d09672e..c5f678dcd 100644 --- a/TIGLViewer/src/ModificatorContainerWidget.cpp +++ b/TIGLViewer/src/ModificatorContainerWidget.cpp @@ -137,10 +137,10 @@ void ModificatorContainerWidget::setSectionModificator(QListsectionsModificator->setCreateConnectedElementI(element); + ui->sectionsModificator->setCreateConnectedElement(element); ui->sectionsModificator->setVisible(true); currentModificator = ui->sectionModificator; } diff --git a/TIGLViewer/src/ModificatorContainerWidget.h b/TIGLViewer/src/ModificatorContainerWidget.h index 762927f17..fad1ce966 100644 --- a/TIGLViewer/src/ModificatorContainerWidget.h +++ b/TIGLViewer/src/ModificatorContainerWidget.h @@ -24,6 +24,7 @@ #include "modificators/ModificatorWingWidget.h" #include "modificators/ModificatorFuselageWidget.h" #include "modificators/ModificatorTransformationWidget.h" +#include "modificators/ModificatorSectionsWidget.h" #include "CCPACSFuselages.h" #include "CPACSWing.h" #include "CCPACSWings.h" @@ -78,7 +79,7 @@ public slots: void setFuselagesModificator(tigl::CCPACSFuselages& fuselages); void setElementModificator(tigl::CTiglSectionElement& element); void setSectionModificator(QList elements); - void setSectionsModificator(tigl::CreateConnectedElementI& conntedElementI); + void setSectionsModificator(Ui::ElementModificatorInterface& conntedElementI); // for positioning, we need two different calls for wing and for fuselage. Otherwise, we miss to invalidate the // associated wing or fuselage void setPositioningModificator(tigl::CCPACSWing& wing, tigl::CCPACSPositioning& positioning); diff --git a/TIGLViewer/src/ModificatorManager.cpp b/TIGLViewer/src/ModificatorManager.cpp index 6a3d8166a..c9da34d20 100644 --- a/TIGLViewer/src/ModificatorManager.cpp +++ b/TIGLViewer/src/ModificatorManager.cpp @@ -24,7 +24,6 @@ #include "CTiglSectionElement.h" #include "CCPACSFuselageSection.h" #include "CCPACSWingSection.h" -#include "CreateConnectedElementI.h" #include "CCPACSPositioning.h" #include "CTiglStandardizer.h" #include "TIGLViewerContext.h" @@ -150,21 +149,17 @@ void ModificatorManager::dispatch(cpcr::CPACSTreeItem* item) std::string bodyUID = item->getParent()->getUid(); // return the fuselage or wing uid tigl::CTiglUIDManager& uidManager = doc->GetConfiguration().GetUIDManager(); tigl::CTiglUIDManager::TypedPtr typePtr = uidManager.ResolveObject(bodyUID); - tigl::CreateConnectedElementI * elementI = nullptr; - if (typePtr.type == &typeid(tigl::CCPACSWing)) { - tigl::CCPACSWing &wing = *reinterpret_cast(typePtr.ptr); - elementI = dynamic_cast(&wing); - } - else if (typePtr.type == &typeid(tigl::CCPACSFuselage)) { - tigl::CCPACSFuselage &fuselage = *reinterpret_cast(typePtr.ptr); - elementI = dynamic_cast(&fuselage); + Ui::ElementModificatorInterface* element; + try { + element = reinterpret_cast(typePtr.ptr); } - else { + catch (...) { + element = nullptr; LOG(ERROR) << "ModificatorManager:: Unexpected sections type!"; } - modificatorContainerWidget->setSectionsModificator(*elementI); + modificatorContainerWidget->setSectionsModificator(*element); } else if (item->getType() == "positioning" ) { tigl::CTiglUIDManager& uidManager = doc->GetConfiguration().GetUIDManager(); diff --git a/TIGLViewer/src/modificators/ModificatorSectionsWidget.cpp b/TIGLViewer/src/modificators/ModificatorSectionsWidget.cpp index 580ffbcc7..ac4b56d24 100644 --- a/TIGLViewer/src/modificators/ModificatorSectionsWidget.cpp +++ b/TIGLViewer/src/modificators/ModificatorSectionsWidget.cpp @@ -30,7 +30,7 @@ ModificatorSectionsWidget::ModificatorSectionsWidget(QWidget* parent) , ui(new Ui::ModificatorSectionsWidget) { ui->setupUi(this); - createConnectedElementI = nullptr; + createConnectedElement = nullptr; connect(ui->addConnectedElementBtn, SIGNAL(pressed()), this, SLOT(execNewConnectedElementDialog())); connect(ui->deleteConnectedElementBtn, SIGNAL(pressed()), this, SLOT(execDeleteConnectedElementDialog())); } @@ -40,19 +40,27 @@ ModificatorSectionsWidget::~ModificatorSectionsWidget() delete ui; } -void ModificatorSectionsWidget::setCreateConnectedElementI(tigl::CreateConnectedElementI& elementI) +void ModificatorSectionsWidget::setCreateConnectedElement(Ui::ElementModificatorInterface& element) { - createConnectedElementI = &elementI; + createConnectedElement = &element; } void ModificatorSectionsWidget::execNewConnectedElementDialog() { - if (createConnectedElementI == nullptr) { + if (createConnectedElement == nullptr) { LOG(ERROR) << "ModificatorSectionsWidget:: is not correctly set!"; return; } - std::vector elementUIDs = createConnectedElementI->GetOrderedConnectedElement(); + std::vector elementUIDs; + // 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( + [&elementUIDs](auto& element){ + elementUIDs = element.GetOrderedConnectedElement(); + }, + *createConnectedElement + ); + QStringList elementUIDsQList; for (int i = 0; i < elementUIDs.size(); i++) { elementUIDsQList.push_back(elementUIDs.at(i).c_str()); @@ -64,10 +72,22 @@ void ModificatorSectionsWidget::execNewConnectedElementDialog() NewConnectedElementDialog::Where where = newElementDialog.getWhere(); try { if (where == NewConnectedElementDialog::Before) { - 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){ + element.CreateNewConnectedElementBefore(startUID); + }, + *createConnectedElement + ); } else if (where == NewConnectedElementDialog::After) { - 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){ + element.CreateNewConnectedElementAfter(startUID); + }, + *createConnectedElement + ); } } catch (const tigl::CTiglError& err) { @@ -87,12 +107,20 @@ void ModificatorSectionsWidget::execNewConnectedElementDialog() void ModificatorSectionsWidget::execDeleteConnectedElementDialog() { - if (createConnectedElementI == nullptr) { + if (createConnectedElement == nullptr) { LOG(ERROR) << "ModificatorWingsWidget::execDeleteWingDialog: wings is not set!"; return; } - std::vector elementUIDs = createConnectedElementI->GetOrderedConnectedElement(); + std::vector elementUIDs; + // 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( + [&elementUIDs](auto& element){ + elementUIDs = element.GetOrderedConnectedElement(); + }, + *createConnectedElement + ); + QStringList elementUIDsQList; for (int i = 0; i < elementUIDs.size(); i++) { elementUIDsQList.push_back(elementUIDs.at(i).c_str()); @@ -102,7 +130,13 @@ void ModificatorSectionsWidget::execDeleteConnectedElementDialog() if (deleteDialog.exec() == QDialog::Accepted) { QString uid = deleteDialog.getUIDToDelete(); try { - 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){ + element.DeleteConnectedElement(uid.toStdString()); + }, + *createConnectedElement + ); } catch (const tigl::CTiglError& err) { TIGLViewerErrorDialog errDialog(this); diff --git a/TIGLViewer/src/modificators/ModificatorSectionsWidget.h b/TIGLViewer/src/modificators/ModificatorSectionsWidget.h index e2545174a..275040078 100644 --- a/TIGLViewer/src/modificators/ModificatorSectionsWidget.h +++ b/TIGLViewer/src/modificators/ModificatorSectionsWidget.h @@ -20,10 +20,13 @@ #define MODIFICATORSECTIONSWIDGET_H #include -#include "CreateConnectedElementI.h" +#include +#include "CCPACSFuselage.h" +#include "CCPACSWing.h" namespace Ui { +using ElementModificatorInterface = std::variant; // could be extended by Duct, Pylon, Tank in the future class ModificatorSectionsWidget; } @@ -42,11 +45,13 @@ public slots: explicit ModificatorSectionsWidget(QWidget* parent = nullptr); ~ModificatorSectionsWidget(); - void setCreateConnectedElementI(tigl::CreateConnectedElementI& elementI); + void setCreateConnectedElement(Ui::ElementModificatorInterface& element); private: Ui::ModificatorSectionsWidget* ui; - tigl::CreateConnectedElementI* createConnectedElementI; + // Defined as std::variant + // Construction is used to avoid an abstract basis class from which all possible variant types had to be inherited + Ui::ElementModificatorInterface* createConnectedElement; }; #endif // MODIFICATORSECTIONSWIDGET_H diff --git a/src/fuselage/CCPACSFuselage.h b/src/fuselage/CCPACSFuselage.h index 5315c1629..8946e15b6 100644 --- a/src/fuselage/CCPACSFuselage.h +++ b/src/fuselage/CCPACSFuselage.h @@ -35,7 +35,6 @@ #include "CCPACSGuideCurve.h" #include "CTiglFuselageConnection.h" #include "Cache.h" -#include "CreateConnectedElementI.h" #include "TopoDS_Shape.hxx" #include "TopoDS_Compound.hxx" @@ -48,7 +47,7 @@ namespace tigl class CCPACSConfiguration; class CCPACSFuselageStringerFramePosition; -class CCPACSFuselage : public generated::CPACSFuselage, public CTiglRelativelyPositionedComponent, public CreateConnectedElementI +class CCPACSFuselage : public generated::CPACSFuselage, public CTiglRelativelyPositionedComponent { public: // Constructor @@ -171,7 +170,7 @@ class CCPACSFuselage : public generated::CPACSFuselage, public CTiglRelativelyPo * * @param startElementUID */ - TIGL_EXPORT void CreateNewConnectedElementAfter(std::string startElementUID) override; + TIGL_EXPORT void CreateNewConnectedElementAfter(std::string startElementUID); /** * Create a new section, a new element and connect the element to the "startElement". @@ -181,7 +180,7 @@ class CCPACSFuselage : public generated::CPACSFuselage, public CTiglRelativelyPo * * @param startElementUID */ - TIGL_EXPORT void CreateNewConnectedElementBefore(std::string startElementUID) override; + TIGL_EXPORT void CreateNewConnectedElementBefore(std::string startElementUID); /** *Create a new section, a new element and place the new element between the startElement and the endElement. @@ -189,12 +188,12 @@ class CCPACSFuselage : public generated::CPACSFuselage, public CTiglRelativelyPo * @param startElementUID * @param endElementUID */ - TIGL_EXPORT void CreateNewConnectedElementBetween(std::string startElementUID, std::string endElementUID) override; + TIGL_EXPORT void CreateNewConnectedElementBetween(std::string startElementUID, std::string endElementUID); - TIGL_EXPORT void DeleteConnectedElement(std::string elementUID) override; + TIGL_EXPORT void DeleteConnectedElement(std::string elementUID); - TIGL_EXPORT std::vector GetOrderedConnectedElement() override; + TIGL_EXPORT std::vector GetOrderedConnectedElement(); TIGL_EXPORT std::vector GetCTiglElements() ; diff --git a/src/geometry/CreateConnectedElementI.h b/src/geometry/CreateConnectedElementI.h deleted file mode 100644 index d3d7064a2..000000000 --- a/src/geometry/CreateConnectedElementI.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2019 CFS Engineering - * - * Created: 2019 Malo Drougard - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef TIGL_SECTIONCREATORINTERFACE_H -#define TIGL_SECTIONCREATORINTERFACE_H - -#include "tigl_internal.h" -#include -#include - -namespace tigl -{ - -/** -* This class defines the interface (I) of a cpacs object that is capable to create or delete a connected element. -* By connected element we mean a element that is correctly connected to another element by a segment. -* For the moment this interface is implemented by the the wing and fuselage classes. -* -*/ -class CreateConnectedElementI -{ - -public: - - /** - * Create a new section, a new element and connect the element to the "startElement". - * The new element is placed "after" the start element. - * If there is already a element after the start element, we split the existing segment and insert the new element - * between the the two elements. - * - * @param startElementUID - */ - TIGL_EXPORT virtual void CreateNewConnectedElementAfter(std::string startElementUID) = 0; - - /** - * Create a new section, a new element and connect the element to the "startElement". - * The new element is placed "Before" the start element. - * If there is already a element before the start element, we split the existing segment and insert the new element - * between the the two elements. - * - * @param startElementUID - */ - TIGL_EXPORT virtual void CreateNewConnectedElementBefore(std::string startElementUID) = 0; - - /** - *Create a new section, a new element and place the new element between the startElement and the endElement. - * @remark The startElement and endElement must be connected by a segment. - * @param startElementUID - * @param endElementUID - */ - TIGL_EXPORT virtual void CreateNewConnectedElementBetween(std::string startElementUID, std::string endElementUID) = 0; - - - /** - * Return the current connected element uids in order for this component (wing or fuselage) - * @return - */ - TIGL_EXPORT virtual std::vector GetOrderedConnectedElement() = 0; - - /** - * Delete the connected element taking care of removing the section and removing or updating the segments. - */ - TIGL_EXPORT virtual void DeleteConnectedElement(std::string ElementUID) = 0 ; - -}; -} - -#endif //TIGL_SECTIONCREATORINTERFACE_H diff --git a/src/wing/CCPACSWing.h b/src/wing/CCPACSWing.h index 806ec4478..3c61e5e6f 100644 --- a/src/wing/CCPACSWing.h +++ b/src/wing/CCPACSWing.h @@ -35,7 +35,6 @@ #include "CTiglAbstractSegment.h" #include "CCPACSGuideCurve.h" #include "Cache.h" -#include "CreateConnectedElementI.h" #include "TopoDS_Shape.hxx" #include "TopoDS_Compound.hxx" @@ -47,7 +46,7 @@ namespace tigl { class CCPACSConfiguration; -class CCPACSWing : public generated::CPACSWing, public CTiglRelativelyPositionedComponent, public CreateConnectedElementI +class CCPACSWing : public generated::CPACSWing, public CTiglRelativelyPositionedComponent { friend class CTiglWingBuilder; @@ -486,7 +485,7 @@ friend class CTiglWingBuilder; * * @param startElementUID */ - TIGL_EXPORT void CreateNewConnectedElementAfter(std::string startElementUID) override; + TIGL_EXPORT void CreateNewConnectedElementAfter(std::string startElementUID); /** * Create a new section, a new element and connect the element to the "startElement". @@ -496,7 +495,7 @@ friend class CTiglWingBuilder; * * @param startElementUID */ - TIGL_EXPORT void CreateNewConnectedElementBefore(std::string startElementUID) override; + TIGL_EXPORT void CreateNewConnectedElementBefore(std::string startElementUID); /** *Create a new section, a new element and place the new element between the startElement and the endElement. @@ -504,7 +503,7 @@ friend class CTiglWingBuilder; * @param startElementUID * @param endElementUID */ - TIGL_EXPORT void CreateNewConnectedElementBetween(std::string startElementUID, std::string endElementUID) override; + TIGL_EXPORT void CreateNewConnectedElementBetween(std::string startElementUID, std::string endElementUID); /** @@ -513,10 +512,10 @@ friend class CTiglWingBuilder; * are either deleted or updated. * @param ElementUID */ - TIGL_EXPORT void DeleteConnectedElement(std::string ElementUID) override; + TIGL_EXPORT void DeleteConnectedElement(std::string ElementUID); - TIGL_EXPORT std::vector GetOrderedConnectedElement() override; + TIGL_EXPORT std::vector GetOrderedConnectedElement(); TIGL_EXPORT std::vector GetCTiglElements() const; From e9d6cdd91305075409433e23641bbf7cdc90410a Mon Sep 17 00:00:00 2001 From: Sven Goldberg Date: Thu, 16 Jan 2025 15:08:34 +0100 Subject: [PATCH 2/2] Refactor the std::variant way by using an template constructor choosing the right type --- TIGLViewer/src/ModificatorContainerWidget.cpp | 2 +- TIGLViewer/src/ModificatorManager.cpp | 25 +++++++---- .../ModificatorSectionsWidget.cpp | 42 +++---------------- .../modificators/ModificatorSectionsWidget.h | 38 +++++++++++++++-- 4 files changed, 56 insertions(+), 51 deletions(-) diff --git a/TIGLViewer/src/ModificatorContainerWidget.cpp b/TIGLViewer/src/ModificatorContainerWidget.cpp index c5f678dcd..f6a121c86 100644 --- a/TIGLViewer/src/ModificatorContainerWidget.cpp +++ b/TIGLViewer/src/ModificatorContainerWidget.cpp @@ -138,7 +138,7 @@ void ModificatorContainerWidget::setSectionModificator(QListsectionsModificator->setCreateConnectedElement(element); ui->sectionsModificator->setVisible(true); diff --git a/TIGLViewer/src/ModificatorManager.cpp b/TIGLViewer/src/ModificatorManager.cpp index c9da34d20..84b8de58a 100644 --- a/TIGLViewer/src/ModificatorManager.cpp +++ b/TIGLViewer/src/ModificatorManager.cpp @@ -150,16 +150,23 @@ void ModificatorManager::dispatch(cpcr::CPACSTreeItem* item) tigl::CTiglUIDManager& uidManager = doc->GetConfiguration().GetUIDManager(); tigl::CTiglUIDManager::TypedPtr typePtr = uidManager.ResolveObject(bodyUID); - Ui::ElementModificatorInterface* element; - try { - element = reinterpret_cast(typePtr.ptr); - } - catch (...) { - element = nullptr; - LOG(ERROR) << "ModificatorManager:: Unexpected sections type!"; - } + auto get_element_interface = [](tigl::CTiglUIDManager::TypedPtr const& ptr) { + if (ptr.type == &typeid(tigl::CCPACSWing)) { + tigl::CCPACSWing &wing = *reinterpret_cast(ptr.ptr); + return Ui::ElementModificatorInterface(wing); + } + else if (ptr.type == &typeid(tigl::CCPACSFuselage)) { + tigl::CCPACSFuselage &fuselage = *reinterpret_cast(ptr.ptr); + return Ui::ElementModificatorInterface(fuselage); + } + else { + LOG(ERROR) << "ModificatorManager:: Unexpected sections type!"; + return Ui::ElementModificatorInterface(tigl::CCPACSFuselage(nullptr, nullptr)); + } + }; - modificatorContainerWidget->setSectionsModificator(*element); + auto element = get_element_interface(typePtr); + modificatorContainerWidget->setSectionsModificator(element); } else if (item->getType() == "positioning" ) { tigl::CTiglUIDManager& uidManager = doc->GetConfiguration().GetUIDManager(); diff --git a/TIGLViewer/src/modificators/ModificatorSectionsWidget.cpp b/TIGLViewer/src/modificators/ModificatorSectionsWidget.cpp index ac4b56d24..5bfa47ccc 100644 --- a/TIGLViewer/src/modificators/ModificatorSectionsWidget.cpp +++ b/TIGLViewer/src/modificators/ModificatorSectionsWidget.cpp @@ -52,14 +52,7 @@ void ModificatorSectionsWidget::execNewConnectedElementDialog() return; } - std::vector elementUIDs; - // 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( - [&elementUIDs](auto& element){ - elementUIDs = element.GetOrderedConnectedElement(); - }, - *createConnectedElement - ); + std::vector elementUIDs = createConnectedElement->GetOrderedConnectedElement(); QStringList elementUIDsQList; for (int i = 0; i < elementUIDs.size(); i++) { @@ -72,22 +65,10 @@ void ModificatorSectionsWidget::execNewConnectedElementDialog() NewConnectedElementDialog::Where where = newElementDialog.getWhere(); try { if (where == NewConnectedElementDialog::Before) { - // 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){ - element.CreateNewConnectedElementBefore(startUID); - }, - *createConnectedElement - ); + createConnectedElement->CreateNewConnectedElementBefore(startUID); } else if (where == NewConnectedElementDialog::After) { - // 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){ - element.CreateNewConnectedElementAfter(startUID); - }, - *createConnectedElement - ); + createConnectedElement->CreateNewConnectedElementAfter(startUID); } } catch (const tigl::CTiglError& err) { @@ -112,14 +93,7 @@ void ModificatorSectionsWidget::execDeleteConnectedElementDialog() return; } - std::vector elementUIDs; - // 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( - [&elementUIDs](auto& element){ - elementUIDs = element.GetOrderedConnectedElement(); - }, - *createConnectedElement - ); + std::vector elementUIDs = createConnectedElement->GetOrderedConnectedElement(); QStringList elementUIDsQList; for (int i = 0; i < elementUIDs.size(); i++) { @@ -130,13 +104,7 @@ void ModificatorSectionsWidget::execDeleteConnectedElementDialog() if (deleteDialog.exec() == QDialog::Accepted) { QString uid = deleteDialog.getUIDToDelete(); try { - // 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){ - element.DeleteConnectedElement(uid.toStdString()); - }, - *createConnectedElement - ); + createConnectedElement->DeleteConnectedElement(uid.toStdString()); } catch (const tigl::CTiglError& err) { TIGLViewerErrorDialog errDialog(this); diff --git a/TIGLViewer/src/modificators/ModificatorSectionsWidget.h b/TIGLViewer/src/modificators/ModificatorSectionsWidget.h index 275040078..dc3a0c189 100644 --- a/TIGLViewer/src/modificators/ModificatorSectionsWidget.h +++ b/TIGLViewer/src/modificators/ModificatorSectionsWidget.h @@ -20,13 +20,45 @@ #define MODIFICATORSECTIONSWIDGET_H #include -#include +#include #include "CCPACSFuselage.h" #include "CCPACSWing.h" namespace Ui { -using ElementModificatorInterface = std::variant; // could be extended by Duct, Pylon, Tank in the future + +// Interface-like structure to account for different possible object types whose member variables may be adapted by the CPACSCreator. +// It is currently used for CCPACSFuselage and CCPACSWing. +// Could be extended by Duct, Pylon, Tank, etc. in the future (observe: The respective classes need to define the listed functions). +struct ElementModificatorInterface +{ + // Here, functions are defined as member variables calling the 'right' (depending on present data type) function from CCPACSFuselage, CCPACSWing, etc. via lambdas + template + ElementModificatorInterface(T&& t) + : CreateNewConnectedElementAfter( + [&t](std::string str){ return t.CreateNewConnectedElementAfter(str); } + ) + , CreateNewConnectedElementBefore( + [&t](std::string str){ return t.CreateNewConnectedElementBefore(str); } + ) + , CreateNewConnectedElementBetween( + [&t](std::string str1, std::string str2){ return t.CreateNewConnectedElementBetween(str1, str2); } + ) + , DeleteConnectedElement( + [&t](std::string str){ return t.DeleteConnectedElement(str); } + ) + , GetOrderedConnectedElement( + [&t](){ return t.GetOrderedConnectedElement(); } + ) + {} + + std::function CreateNewConnectedElementAfter; + std::function CreateNewConnectedElementBefore; + std::function CreateNewConnectedElementBetween; + std::function DeleteConnectedElement; + std::function()> GetOrderedConnectedElement; +}; + class ModificatorSectionsWidget; } @@ -49,8 +81,6 @@ public slots: private: Ui::ModificatorSectionsWidget* ui; - // Defined as std::variant - // Construction is used to avoid an abstract basis class from which all possible variant types had to be inherited Ui::ElementModificatorInterface* createConnectedElement; };