Skip to content

Commit

Permalink
Merge pull request #1039 from DLR-SC/626_cpacs_creator_add_section_gc
Browse files Browse the repository at this point in the history
CPACS-Creator: Add error handling when a section should be added in (or next to) a segment containing guide curves
  • Loading branch information
svengoldberg authored Nov 29, 2024
2 parents 91d6101 + 2466e1d commit b3a3d1a
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 9 deletions.
11 changes: 10 additions & 1 deletion bindings/python_internal/configuration.i
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
#include "CCPACSExternalObject.h"
#include "CTiglShapeCache.h"
#include "CTiglError.h"
#include "CCPACSWalls.h"
#include "CCPACSWallPosition.h"
#include "CCPACSFuselageWallSegment.h"
#include "CCPACSWingSegment.h"
#include "CCPACSFuselageSegment.h"
#include "CTiglWingConnection.h"
Expand Down Expand Up @@ -87,6 +89,7 @@
#include "generated/CPACSBoundingElementUIDs.h"
#include "generated/CPACSStructuralWallElement.h"
#include "generated/CPACSStructuralWallElements.h"
#include "generated/CPACSWalls.h"
#include "generated/CPACSWallPositionUIDs.h"
#include "generated/CPACSWallPosition.h"
#include "generated/CPACSWallPositions.h"
Expand Down Expand Up @@ -180,7 +183,6 @@
%include "generated/CPACSLateralCap_placement.h"
%boost_optional(tigl::generated::CPACSLateralCap)
%include "generated/CPACSLateralCap.h"

%boost_optional(tigl::generated::CPACSBoundingElementUIDs)
%include "generated/CPACSBoundingElementUIDs.h"
%include "generated/CPACSStructuralWallElement.h"
Expand All @@ -190,8 +192,14 @@
%include "generated/CPACSWallPositions.h"
%include "generated/CPACSWallSegment.h"
%include "generated/CPACSWallSegments.h"
%boost_optional(tigl::CCPACSWalls)
%boost_optional(tigl::generated::CPACSWalls)
%boost_optional(tigl::CCPACSWallPosition)
%boost_optional(tigl::CCPACSFuselageWallSegment)
%include "generated/CPACSWalls.h"
%include "CCPACSWalls.h"
%include "CCPACSWallPosition.h"
%include "CCPACSFuselageWallSegment.h"

// ----------------- Engines ---------------------------//
%boost_optional(tigl::CCPACSEngines)
Expand Down Expand Up @@ -538,6 +546,7 @@ class CCPACSWingRibsPositioning;
%factory(tigl::ITiglGeometricComponent& tigl::CTiglUIDManager::GetGeometricComponent,
tigl::CCPACSFuselage,
tigl::CCPACSFuselageSegment,
tigl::CCPACSFuselageWallSegment,
tigl::CCPACSWing,
tigl::CCPACSWingSegment,
tigl::CCPACSWingComponentSegment,
Expand Down
29 changes: 29 additions & 0 deletions src/fuselage/CCPACSFuselage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,11 @@ void CCPACSFuselage::SetFuselageHelper(CTiglFuselageHelper& cache) const

void CCPACSFuselage::CreateNewConnectedElementBetween(std::string startElementUID, std::string endElementUID)
{
if(GetSegments().GetSegmentFromTo(startElementUID, endElementUID).GetGuideCurves())
{
throw tigl::CTiglError("Adding sections in fuselage segments containing guide curves is currently not supported.\n"
"In general, guide curves should only be added when all sections are already defined, since the guide curves depend on them.", TIGL_ERROR);
}

std::string segmentToSplit = GetSegments().GetSegmentFromTo(startElementUID, endElementUID).GetUID();
CTiglFuselageSectionElement* startElement = fuselageHelper->GetCTiglElementOfFuselage(startElementUID);
Expand Down Expand Up @@ -797,6 +802,18 @@ void CCPACSFuselage::CreateNewConnectedElementAfter(std::string startElementUID)
if ( elementsBefore.size() < 2) {
throw CTiglError("Impossible to add a element after if there is no previous element");
}

// Iterate over segments to find the one ending in startElementUID
// If the corresponding segment contains guide curves -> Throw error, since adding elements after gc-segments is not supported
for (int i=1; i <= GetSegmentCount(); i++)
{
if(GetSegment(i).GetGuideCurves())
{
throw tigl::CTiglError("Adding sections after fuselage segments containing guide curves is currently not supported.\n"
"In general, guide curves should only be added when all sections are already defined, since the guide curves depend on them.", TIGL_ERROR);
}
}

std::string previousElementUID = elementsBefore[elementsBefore.size()-2];

CTiglFuselageSectionElement* previousElement = fuselageHelper->GetCTiglElementOfFuselage(previousElementUID);
Expand Down Expand Up @@ -848,6 +865,18 @@ void CCPACSFuselage::CreateNewConnectedElementBefore(std::string startElementUID
if (elementsAfter.size() < 1 ) {
throw CTiglError("Impossible to add a element before if there is no previous element");
}

// Iterate over segments to find the one starting in startElementUID
// If the corresponding segment contains guide curves -> Throw error, since adding elements after gc-segments is not supported
for (int i=1; i <= GetSegmentCount(); i++)
{
if(GetSegment(i).GetGuideCurves())
{
throw tigl::CTiglError("Adding sections before fuselage segments containing guide curves is currently not supported.\n"
"In general, guide curves should only be added when all sections are already defined, since the guide curves depend on them.", TIGL_ERROR);
}
}

std::string previousElementUID = elementsAfter[0];

CTiglFuselageSectionElement* previousElement = fuselageHelper->GetCTiglElementOfFuselage(previousElementUID);
Expand Down
8 changes: 4 additions & 4 deletions src/structural_elements/CCPACSFuselageWallSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ class CCPACSFuselageWallSegment : public generated::CPACSWallSegment, public CTi
public:
TIGL_EXPORT CCPACSFuselageWallSegment(CCPACSWallSegments* parent, CTiglUIDManager* uidMgr);

std::string GetDefaultedUID() const override
TIGL_EXPORT std::string GetDefaultedUID() const override
{
return GetUID().value_or("UnknownWallSegment");
}

TiglGeometricComponentIntent GetComponentIntent() const override
TIGL_EXPORT TiglGeometricComponentIntent GetComponentIntent() const override
{
return TIGL_INTENT_INNER_STRUCTURE | TIGL_INTENT_PHYSICAL;
}

TiglGeometricComponentType GetComponentType() const override
TIGL_EXPORT TiglGeometricComponentType GetComponentType() const override
{
return TIGL_COMPONENT_FUSELAGE_WALL;
}

TopoDS_Compound GetCutPlanes() const;
TIGL_EXPORT TopoDS_Compound GetCutPlanes() const;

TIGL_EXPORT void SetPhi(const double& value) override;
TIGL_EXPORT void SetDoubleSidedExtrusion(const boost::optional<bool>& value) override;
Expand Down
8 changes: 4 additions & 4 deletions src/structural_elements/CCPACSWalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ namespace tigl
class CCPACSWalls : public generated::CPACSWalls
{
public:
CCPACSWalls(CCPACSFuselageStructure* parent, CTiglUIDManager* uidMgr);
TIGL_EXPORT CCPACSWalls(CCPACSFuselageStructure* parent, CTiglUIDManager* uidMgr);

const CCPACSFuselageWallSegment& GetWallSegment(const std::string& uid) const;
const CCPACSWallPosition& GetWallPosition(const std::string& uid) const;
TIGL_EXPORT const CCPACSFuselageWallSegment& GetWallSegment(const std::string& uid) const;
TIGL_EXPORT const CCPACSWallPosition& GetWallPosition(const std::string& uid) const;

void Invalidate(const boost::optional<std::string>& source = boost::none) const;
TIGL_EXPORT void Invalidate(const boost::optional<std::string>& source = boost::none) const;
};

} // namespace tigl
Expand Down
29 changes: 29 additions & 0 deletions src/wing/CCPACSWing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,11 @@ void CCPACSWing::SetARKeepArea(double newAR)

void CCPACSWing::CreateNewConnectedElementBetween(std::string startElementUID, std::string endElementUID)
{
if(GetSegments().GetSegmentFromTo(startElementUID, endElementUID).GetGuideCurves())
{
throw tigl::CTiglError("Adding sections in wing segments containing guide curves is currently not supported.\n"
"In general, guide curves should only be added when all sections are already defined, since the guide curves depend on them.", TIGL_ERROR);
}

std::string segmentToSplit = GetSegments().GetSegmentFromTo(startElementUID, endElementUID).GetUID();
CTiglWingSectionElement *startElement = wingHelper->GetCTiglElementOfWing(startElementUID);
Expand Down Expand Up @@ -1454,6 +1459,18 @@ void CCPACSWing::CreateNewConnectedElementAfter(std::string startElementUID)
if ( elementsBefore.size() < 2) {
throw CTiglError("Impossible to add a element after if there is no previous element");
}

// Iterate over segments to find the one ending in startElementUID
// If the corresponding segment contains guide curves -> Throw error, since adding elements after gc-segments is not supported
for (int i=1; i <= GetSegmentCount(); i++)
{
if(GetSegment(i).GetGuideCurves())
{
throw tigl::CTiglError("Adding sections after wing segments containing guide curves is currently not supported.\n"
"In general, guide curves should only be added when all sections are already defined, since the guide curves depend on them.", TIGL_ERROR);
}
}

std::string previousElementUID = elementsBefore[elementsBefore.size()-2];

CTiglWingSectionElement* previousElement = wingHelper->GetCTiglElementOfWing(previousElementUID);
Expand Down Expand Up @@ -1506,6 +1523,18 @@ void CCPACSWing::CreateNewConnectedElementBefore(std::string startElementUID)
if (elementsAfter.size() < 1 ) {
throw CTiglError("Impossible to add a element before if there is no previous element");
}

// Iterate over segments to find the one starting in startElementUID
// If the corresponding segment contains guide curves -> Throw error, since adding elements after gc-segments is not supported
for (int i=1; i <= GetSegmentCount(); i++)
{
if(GetSegment(i).GetGuideCurves())
{
throw tigl::CTiglError("Adding sections before wing segments containing guide curves is currently not supported.\n"
"In general, guide curves should only be added when all sections are already defined, since the guide curves depend on them.", TIGL_ERROR);
}
}

std::string previousElementUID = elementsAfter[0];

CTiglWingSectionElement* previousElement = wingHelper->GetCTiglElementOfWing(previousElementUID);
Expand Down
10 changes: 10 additions & 0 deletions tests/unittests/creatorFuselage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,16 @@ TEST_F(creatorFuselage, setRotation_MultipleFuselagesModel)
}


TEST_F(creatorFuselage, createSection_FuselageSegmentGuideCurves)
{

setVariables("TestData/simple_test_guide_curves.xml", "Fuselage");

EXPECT_THROW(fuselage->CreateNewConnectedElementBefore("GuideCurveModel_Fuselage_Sec1_El1"), tigl::CTiglError);
EXPECT_THROW(fuselage->CreateNewConnectedElementBetween("GuideCurveModel_Fuselage_Sec1_El1", "GuideCurveModel_Fuselage_Sec2_El1"), tigl::CTiglError);
EXPECT_THROW(fuselage->CreateNewConnectedElementAfter("GuideCurveModel_Fuselage_Sec3_El1"), tigl::CTiglError);
}


TEST_F(creatorFuselage, createSection_MultipleFuselageModel)
{
Expand Down
11 changes: 11 additions & 0 deletions tests/unittests/creatorWing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,17 @@ TEST_F(creatorWing, MultipleWings_SetARKeepArea) {
}


TEST_F(creatorWing, createSection_WingSegmentGuideCurves)
{

setVariables("TestData/simple_test_guide_curves.xml", "Wing");

EXPECT_THROW(wing->CreateNewConnectedElementBefore("GuideCurveModel_Wing_Sec1_El1"), tigl::CTiglError);
EXPECT_THROW(wing->CreateNewConnectedElementBetween("GuideCurveModel_Wing_Sec1_El1", "GuideCurveModel_Wing_Sec2_El1"), tigl::CTiglError);
EXPECT_THROW(wing->CreateNewConnectedElementAfter("GuideCurveModel_Wing_Sec4_El1"), tigl::CTiglError);
}


TEST_F(creatorWing, MultipleWings_CreateSections)
{
setVariables("TestData/multiple_wings.xml", "Wing");
Expand Down

0 comments on commit b3a3d1a

Please sign in to comment.