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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions TIGLViewer/src/ModificatorContainerWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ void ModificatorContainerWidget::setSectionModificator(QList<tigl::CTiglSectionE
}


void ModificatorContainerWidget::setSectionsModificator(tigl::CreateConnectedElementI& element)
{
void ModificatorContainerWidget::setSectionsModificator(Ui::ElementModificatorInterface& element)
{
hideAllSpecializedWidgets();
ui->sectionsModificator->setCreateConnectedElementI(element);
ui->sectionsModificator->setCreateConnectedElement(element);
ui->sectionsModificator->setVisible(true);
currentModificator = ui->sectionModificator;
}
Expand Down
3 changes: 2 additions & 1 deletion TIGLViewer/src/ModificatorContainerWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -78,7 +79,7 @@ public slots:
void setFuselagesModificator(tigl::CCPACSFuselages& fuselages);
void setElementModificator(tigl::CTiglSectionElement& element);
void setSectionModificator(QList<tigl::CTiglSectionElement*> 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);
Expand Down
17 changes: 6 additions & 11 deletions TIGLViewer/src/ModificatorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<tigl::CCPACSWing *>(typePtr.ptr);
elementI = dynamic_cast<tigl::CreateConnectedElementI* >(&wing);
}
else if (typePtr.type == &typeid(tigl::CCPACSFuselage)) {
tigl::CCPACSFuselage &fuselage = *reinterpret_cast<tigl::CCPACSFuselage *>(typePtr.ptr);
elementI = dynamic_cast<tigl::CreateConnectedElementI* >(&fuselage);
Ui::ElementModificatorInterface* element;
try {
element = reinterpret_cast<Ui::ElementModificatorInterface* >(typePtr.ptr);
svengoldberg marked this conversation as resolved.
Show resolved Hide resolved
}
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();
Expand Down
54 changes: 44 additions & 10 deletions TIGLViewer/src/modificators/ModificatorSectionsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand All @@ -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<std::string> elementUIDs = createConnectedElementI->GetOrderedConnectedElement();
std::vector<std::string> 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());
Expand All @@ -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){
svengoldberg marked this conversation as resolved.
Show resolved Hide resolved
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){
svengoldberg marked this conversation as resolved.
Show resolved Hide resolved
element.CreateNewConnectedElementAfter(startUID);
},
*createConnectedElement
);
}
}
catch (const tigl::CTiglError& err) {
Expand All @@ -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<std::string> elementUIDs = createConnectedElementI->GetOrderedConnectedElement();
std::vector<std::string> 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());
Expand All @@ -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){
svengoldberg marked this conversation as resolved.
Show resolved Hide resolved
element.DeleteConnectedElement(uid.toStdString());
},
*createConnectedElement
);
}
catch (const tigl::CTiglError& err) {
TIGLViewerErrorDialog errDialog(this);
Expand Down
11 changes: 8 additions & 3 deletions TIGLViewer/src/modificators/ModificatorSectionsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
#define MODIFICATORSECTIONSWIDGET_H

#include <QWidget>
#include "CreateConnectedElementI.h"
#include <variant>
#include "CCPACSFuselage.h"
#include "CCPACSWing.h"

namespace Ui
{
using ElementModificatorInterface = std::variant<tigl::CCPACSFuselage, tigl::CCPACSWing>; // could be extended by Duct, Pylon, Tank in the future
class ModificatorSectionsWidget;
}

Expand All @@ -42,11 +45,13 @@ public slots:
explicit ModificatorSectionsWidget(QWidget* parent = nullptr);
~ModificatorSectionsWidget();

void setCreateConnectedElementI(tigl::CreateConnectedElementI& elementI);
void setCreateConnectedElement(Ui::ElementModificatorInterface& element);
svengoldberg marked this conversation as resolved.
Show resolved Hide resolved

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;
svengoldberg marked this conversation as resolved.
Show resolved Hide resolved
};

#endif // MODIFICATORSECTIONSWIDGET_H
13 changes: 6 additions & 7 deletions src/fuselage/CCPACSFuselage.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "CCPACSGuideCurve.h"
#include "CTiglFuselageConnection.h"
#include "Cache.h"
#include "CreateConnectedElementI.h"

#include "TopoDS_Shape.hxx"
#include "TopoDS_Compound.hxx"
Expand All @@ -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
Expand Down Expand Up @@ -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".
Expand All @@ -181,20 +180,20 @@ 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.
* @remark The startElement and endElement must be connected by a segment.
* @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<std::string> GetOrderedConnectedElement() override;
TIGL_EXPORT std::vector<std::string> GetOrderedConnectedElement();

TIGL_EXPORT std::vector<tigl::CTiglSectionElement*> GetCTiglElements() ;

Expand Down
84 changes: 0 additions & 84 deletions src/geometry/CreateConnectedElementI.h

This file was deleted.

13 changes: 6 additions & 7 deletions src/wing/CCPACSWing.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "CTiglAbstractSegment.h"
#include "CCPACSGuideCurve.h"
#include "Cache.h"
#include "CreateConnectedElementI.h"

#include "TopoDS_Shape.hxx"
#include "TopoDS_Compound.hxx"
Expand All @@ -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;

Expand Down Expand Up @@ -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".
Expand All @@ -496,15 +495,15 @@ 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.
* @remark The startElement and endElement must be connected by a segment.
* @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);


/**
Expand All @@ -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<std::string> GetOrderedConnectedElement() override;
TIGL_EXPORT std::vector<std::string> GetOrderedConnectedElement();

TIGL_EXPORT std::vector<CTiglSectionElement* > GetCTiglElements() const;

Expand Down
Loading