diff --git a/TIGLViewer/src/ModificatorContainerWidget.cpp b/TIGLViewer/src/ModificatorContainerWidget.cpp index b7d09672e..41a0c0d77 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..2ca17302b 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 const& 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..5e98f9263 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,24 @@ 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); - } - else { - 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(*elementI); + auto element = get_element_interface(typePtr); + modificatorContainerWidget->setSectionsModificator(std::move(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..412ceee18 100644 --- a/TIGLViewer/src/modificators/ModificatorSectionsWidget.cpp +++ b/TIGLViewer/src/modificators/ModificatorSectionsWidget.cpp @@ -30,7 +30,6 @@ ModificatorSectionsWidget::ModificatorSectionsWidget(QWidget* parent) , ui(new Ui::ModificatorSectionsWidget) { ui->setupUi(this); - createConnectedElementI = nullptr; connect(ui->addConnectedElementBtn, SIGNAL(pressed()), this, SLOT(execNewConnectedElementDialog())); connect(ui->deleteConnectedElementBtn, SIGNAL(pressed()), this, SLOT(execDeleteConnectedElementDialog())); } @@ -40,19 +39,20 @@ ModificatorSectionsWidget::~ModificatorSectionsWidget() delete ui; } -void ModificatorSectionsWidget::setCreateConnectedElementI(tigl::CreateConnectedElementI& elementI) +void ModificatorSectionsWidget::setCreateConnectedElement(Ui::ElementModificatorInterface const& element) { - createConnectedElementI = &elementI; + createConnectedElement = element; } void ModificatorSectionsWidget::execNewConnectedElementDialog() { - if (createConnectedElementI == nullptr) { + if (createConnectedElement == std::nullopt) { LOG(ERROR) << "ModificatorSectionsWidget:: is not correctly set!"; return; } - std::vector elementUIDs = createConnectedElementI->GetOrderedConnectedElement(); + std::vector elementUIDs = createConnectedElement->GetOrderedConnectedElement(); + QStringList elementUIDsQList; for (int i = 0; i < elementUIDs.size(); i++) { elementUIDsQList.push_back(elementUIDs.at(i).c_str()); @@ -64,10 +64,10 @@ void ModificatorSectionsWidget::execNewConnectedElementDialog() NewConnectedElementDialog::Where where = newElementDialog.getWhere(); try { if (where == NewConnectedElementDialog::Before) { - createConnectedElementI->CreateNewConnectedElementBefore(startUID); + createConnectedElement->CreateNewConnectedElementBefore(startUID); } else if (where == NewConnectedElementDialog::After) { - createConnectedElementI->CreateNewConnectedElementAfter(startUID); + createConnectedElement->CreateNewConnectedElementAfter(startUID); } } catch (const tigl::CTiglError& err) { @@ -87,12 +87,13 @@ void ModificatorSectionsWidget::execNewConnectedElementDialog() void ModificatorSectionsWidget::execDeleteConnectedElementDialog() { - if (createConnectedElementI == nullptr) { + if (createConnectedElement == std::nullopt) { LOG(ERROR) << "ModificatorWingsWidget::execDeleteWingDialog: wings is not set!"; return; } - std::vector elementUIDs = createConnectedElementI->GetOrderedConnectedElement(); + std::vector elementUIDs = createConnectedElement->GetOrderedConnectedElement(); + QStringList elementUIDsQList; for (int i = 0; i < elementUIDs.size(); i++) { elementUIDsQList.push_back(elementUIDs.at(i).c_str()); @@ -102,7 +103,7 @@ void ModificatorSectionsWidget::execDeleteConnectedElementDialog() if (deleteDialog.exec() == QDialog::Accepted) { QString uid = deleteDialog.getUIDToDelete(); try { - createConnectedElementI->DeleteConnectedElement(uid.toStdString()); + 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 e2545174a..7ad970954 100644 --- a/TIGLViewer/src/modificators/ModificatorSectionsWidget.h +++ b/TIGLViewer/src/modificators/ModificatorSectionsWidget.h @@ -20,10 +20,46 @@ #define MODIFICATORSECTIONSWIDGET_H #include -#include "CreateConnectedElementI.h" +#include +#include +#include "CCPACSFuselage.h" +#include "CCPACSWing.h" namespace Ui { + +// 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; } @@ -42,11 +78,12 @@ public slots: explicit ModificatorSectionsWidget(QWidget* parent = nullptr); ~ModificatorSectionsWidget(); - void setCreateConnectedElementI(tigl::CreateConnectedElementI& elementI); + void setCreateConnectedElement(Ui::ElementModificatorInterface const& element); private: Ui::ModificatorSectionsWidget* ui; - tigl::CreateConnectedElementI* createConnectedElementI; + // std::optional used here to account for empty initializiation of member variable in construtor (ptr and nullptr used before) + std::optional 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;