Skip to content

Commit

Permalink
Throw error when sections are added in segments containing gc
Browse files Browse the repository at this point in the history
The CPACS creator currently allows adding sections in segments (or at their boundaries) when they contain guide curves. However this leads to crashes or undefined behaviour. As it might be hard to discuss reasonable behaviour or predict what the user wants in complex examples, we do not allow this right now.
(At least partly) fixes issue #626
  • Loading branch information
svengoldberg committed Nov 26, 2024
1 parent 91d6101 commit 8f1c05a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/fuselage/CCPACSFuselage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ 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 not supported", TIGL_UID_ERROR);
}

std::string segmentToSplit = GetSegments().GetSegmentFromTo(startElementUID, endElementUID).GetUID();
CTiglFuselageSectionElement* startElement = fuselageHelper->GetCTiglElementOfFuselage(startElementUID);
Expand Down Expand Up @@ -797,6 +801,20 @@ 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).GetEndSectionElementUID() == startElementUID)
{
if(GetSegment(i).GetGuideCurves())
{
throw tigl::CTiglError("Adding sections after fuselage segments containing guide curves is not supported", TIGL_UID_ERROR);
}
}
}

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

CTiglFuselageSectionElement* previousElement = fuselageHelper->GetCTiglElementOfFuselage(previousElementUID);
Expand Down Expand Up @@ -848,6 +866,20 @@ 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).GetStartSectionElementUID() == startElementUID)
{
if(GetSegment(i).GetGuideCurves())
{
throw tigl::CTiglError("Adding sections before fuselage segments containing guide curves is not supported", TIGL_UID_ERROR);
}
}
}

std::string previousElementUID = elementsAfter[0];

CTiglFuselageSectionElement* previousElement = fuselageHelper->GetCTiglElementOfFuselage(previousElementUID);
Expand Down
32 changes: 32 additions & 0 deletions src/wing/CCPACSWing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,10 @@ 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 not supported", TIGL_UID_ERROR);
}

std::string segmentToSplit = GetSegments().GetSegmentFromTo(startElementUID, endElementUID).GetUID();
CTiglWingSectionElement *startElement = wingHelper->GetCTiglElementOfWing(startElementUID);
Expand Down Expand Up @@ -1454,6 +1458,20 @@ 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).GetOuterSectionElementUID() == startElementUID)
{
if(GetSegment(i).GetGuideCurves())
{
throw tigl::CTiglError("Adding sections after wing segments containing guide curves is not supported", TIGL_UID_ERROR);
}
}
}

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

CTiglWingSectionElement* previousElement = wingHelper->GetCTiglElementOfWing(previousElementUID);
Expand Down Expand Up @@ -1506,6 +1524,20 @@ 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).GetInnerSectionElementUID() == startElementUID)
{
if(GetSegment(i).GetGuideCurves())
{
throw tigl::CTiglError("Adding sections before wing segments containing guide curves is not supported", TIGL_UID_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 8f1c05a

Please sign in to comment.