From c5bc521a7c5a6abd04e3ea4f59e1efc9f928d4f8 Mon Sep 17 00:00:00 2001 From: skv Date: Thu, 26 Mar 2015 14:52:11 +0300 Subject: [PATCH] 0022869: Disable Generate Groups if the path is closed --- src/GenerationGUI/GenerationGUI_PipeDlg.cxx | 89 ++++++++++++++++++++- src/GenerationGUI/GenerationGUI_PipeDlg.h | 1 + 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/src/GenerationGUI/GenerationGUI_PipeDlg.cxx b/src/GenerationGUI/GenerationGUI_PipeDlg.cxx index 7bc91a8a5..5474b1e43 100644 --- a/src/GenerationGUI/GenerationGUI_PipeDlg.cxx +++ b/src/GenerationGUI/GenerationGUI_PipeDlg.cxx @@ -35,7 +35,9 @@ #include #include +#include #include +#include #include #include #include @@ -217,6 +219,7 @@ void GenerationGUI_PipeDlg::Init() GroupPoints->PushButton1->click(); SelectionIntoArgument(); + updateGenGroup(); } //================================================================================= @@ -286,6 +289,7 @@ void GenerationGUI_PipeDlg::SelectionTypeButtonClicked() if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) { myEditCurrentArgument->setText(""); myPath.nullify(); + updateGenGroup(); } processPreview(); } @@ -352,6 +356,7 @@ void GenerationGUI_PipeDlg::SelectionIntoArgument() else if ( myBaseObjects.isEmpty() ) GroupPoints->PushButton1->click(); } + updateGenGroup(); } else if (myEditCurrentArgument == GroupPoints->LineEdit3) { myVec = getSelected( TopAbs_EDGE ); @@ -391,6 +396,7 @@ void GenerationGUI_PipeDlg::SelectionIntoArgument() QString aName = GEOMBase::GetName( myPath.get() ); myEditCurrentArgument->setText( aName ); } + updateGenGroup(); } processPreview(); @@ -537,7 +543,8 @@ bool GenerationGUI_PipeDlg::execute (ObjectList& objects) case 0: case 1: if (doGroups) { - doGroups = myGenGroupCheckGP->isChecked(); + doGroups = myGenGroupCheckGP->isEnabled() && + myGenGroupCheckGP->isChecked(); } for (int i = 0; i < myBaseObjects.count(); i++) { @@ -577,7 +584,8 @@ bool GenerationGUI_PipeDlg::execute (ObjectList& objects) } if (doGroups) { - doGroups = myGenGroupCheckGMP->isChecked(); + doGroups = myGenGroupCheckGMP->isEnabled() && + myGenGroupCheckGMP->isChecked(); } aList = anOper->MakePipeWithDifferentSections @@ -632,7 +640,6 @@ void GenerationGUI_PipeDlg::restoreSubShapes QCheckBox *aGenGroupCheck = NULL; QLineEdit *aPrefixEdit = NULL; - switch (getConstructorId()) { case 0 : case 1 : @@ -712,6 +719,82 @@ void GenerationGUI_PipeDlg::GenGroupClicked(bool isChecked) resetGenGroup((QCheckBox *)sender(), isChecked, false); } +//================================================================================= +// function : updateGenGroup +// purpose : Update "Generate groups" widgets depending on the path. +//================================================================================= +void GenerationGUI_PipeDlg::updateGenGroup() +{ + bool isEnable = true; + + if (myPath) { + // Check if the path is closed. + TopoDS_Shape aShapePath; + + if (GEOMBase::GetShape(myPath.get(), aShapePath) && + aShapePath.IsNull() == Standard_False) { + if (aShapePath.Closed()) { + // No groups should be generated if the path is closed. + isEnable = false; + } else { + const TopAbs_ShapeEnum aType = aShapePath.ShapeType(); + + if (aType == TopAbs_EDGE || aType == TopAbs_WIRE) { + // Check if path ends are coinsident. + TopoDS_Vertex aV[2]; + + if (aType == TopAbs_EDGE) { + // Edge + TopExp::Vertices(TopoDS::Edge(aShapePath), aV[0], aV[1]); + } else { + // Wire + TopExp::Vertices(TopoDS::Wire(aShapePath), aV[0], aV[1]); + } + + if (aV[0].IsNull() == Standard_False && + aV[1].IsNull() == Standard_False) { + if (aV[0].IsSame(aV[1])) { + // No groups should be generated if the path is closed. + isEnable = false; + } else { + const Standard_Real aTol1 = BRep_Tool::Tolerance(aV[0]); + const Standard_Real aTol2 = BRep_Tool::Tolerance(aV[1]); + const gp_Pnt aPnt1 = BRep_Tool::Pnt(aV[0]); + const gp_Pnt aPnt2 = BRep_Tool::Pnt(aV[1]); + + if (aPnt1.Distance(aPnt2) <= aTol1 + aTol2) { + // No groups should be generated if the path is closed. + isEnable = false; + } + } + } + } + } + } + } + + QCheckBox *aGenGroupCheck = NULL; + + switch (getConstructorId()) { + case 0 : + case 1 : + aGenGroupCheck = myGenGroupCheckGP; + break; + case 2 : + aGenGroupCheck = myGenGroupCheckGMP; + break; + default: + break; + } + + if (aGenGroupCheck != NULL) { + const bool isChecked = aGenGroupCheck->isChecked(); + + aGenGroupCheck->setEnabled(isEnable); + resetGenGroup(aGenGroupCheck, isEnable && isChecked, false); + } +} + //================================================================================= // function : resetGenGroup // purpose : Resets data of "Generate groups" widgets. diff --git a/src/GenerationGUI/GenerationGUI_PipeDlg.h b/src/GenerationGUI/GenerationGUI_PipeDlg.h index 7af0402b3..3684e5210 100644 --- a/src/GenerationGUI/GenerationGUI_PipeDlg.h +++ b/src/GenerationGUI/GenerationGUI_PipeDlg.h @@ -62,6 +62,7 @@ protected: private: void Init(); void enterEvent( QEvent* ); + void updateGenGroup(); void resetGenGroup (QCheckBox *theGenGroup, const bool isChecked, -- 2.39.2