+
+ if (!TextLabel5->isEnabled()) {
+ TextLabel5->setEnabled(true);
+ SelectButton5->setEnabled(true);
+ LineEdit5->setEnabled(true);
+ } else if (!TextLabel6->isEnabled()) {
+ TextLabel6->setEnabled(true);
+ SelectButton6->setEnabled(true);
+ LineEdit6->setEnabled(true);
+ }
+
+ if (constructorId == 1 || constructorId == 3) {
+ if (CheckBoxPolygons->isVisible())
+ CheckBoxPolygons->hide();
+ if (CheckBoxPolyedrs->isVisible())
+ CheckBoxPolyedrs->hide();
+ }
+
+ CheckBoxMerge->setVisible ( constructorId == 3 );
+
+ if (( !SubGroup1->isVisible() ) &&
+ ( constructorId != 0 || ModeButGrp->checkedId() == MODE_MANUAL ))
+ {
+ SubGroup1->show();
+ SubGroup2->show();
+ }
+
+ if ( constructorId != 0 )
+ {
+ ModeGroup->hide();
+ SewFreeBordersWidget->hide();
+ restoreDisplayMode();
+ }
+
+ bool isNodeSelection = true;
+
+ switch (constructorId) {
+ case 0:
+ {
+ GroupArguments->setTitle(tr("SEW_FREE_BORDERS"));
+ SubGroup1->setTitle(tr("BORDER_1"));
+ SubGroup2->setTitle(tr("BORDER_2"));
+
+ if (!CheckBoxPolygons->isVisible())
+ CheckBoxPolygons->show();
+ if (!CheckBoxPolyedrs->isVisible())
+ CheckBoxPolyedrs->show();
+
+ if ( !ModeGroup->isVisible() )
+ {
+ ModeGroup->show();
+ }
+ onModeChange( ModeButGrp->checkedId() );
+
+ isNodeSelection = ( ModeButGrp->checkedId() == MODE_MANUAL );
+
+ break;
+ }
+ case 1:
+ {
+ GroupArguments->setTitle(tr("SEW_CONFORM_FREE_BORDERS"));
+ SubGroup1->setTitle(tr("BORDER_1"));
+ SubGroup2->setTitle(tr("BORDER_2"));
+
+ TextLabel6->setEnabled(false);
+ SelectButton6->setEnabled(false);
+ LineEdit6->setEnabled(false);
+
+ myOk6 = true;
+
+ break;
+ }
+ case 2:
+ {
+ GroupArguments->setTitle(tr("SEW_BORDER_TO_SIDE"));
+ SubGroup1->setTitle(tr("BORDER"));
+ SubGroup2->setTitle(tr("SIDE"));
+
+ TextLabel5->setEnabled(false);
+ SelectButton5->setEnabled(false);
+ LineEdit5->setEnabled(false);
+
+ if (!CheckBoxPolygons->isVisible())
+ CheckBoxPolygons->show();
+ if (!CheckBoxPolyedrs->isVisible())
+ CheckBoxPolyedrs->show();
+
+ myOk5 = true;
+
+ break;
+ }
+ case 3:
+ {
+ GroupArguments->setTitle(tr("SEW_SIDE_ELEMENTS"));
+ SubGroup1->setTitle(tr("SIDE_1"));
+ SubGroup2->setTitle(tr("SIDE_2"));
+
+ TextLabel1->setText(tr("SMESH_ID_ELEMENTS"));
+ TextLabel2->setText(tr("NODE1_TO_MERGE"));
+ TextLabel3->setText(tr("NODE2_TO_MERGE"));
+ TextLabel4->setText(tr("SMESH_ID_ELEMENTS"));
+ TextLabel5->setText(tr("NODE1_TO_MERGE"));
+ TextLabel6->setText(tr("NODE2_TO_MERGE"));
+
+ LineEdit1->setValidator(new SMESHGUI_IdValidator(this));
+ LineEdit4->setValidator(new SMESHGUI_IdValidator(this));
+
+ isNodeSelection = false;
+ if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+ aViewWindow->SetSelectionMode(CellSelection);
+ break;
+ }
+ }
+
+ if (constructorId != 3) {
+ TextLabel1->setText(tr("FIRST_NODE_ID"));
+ TextLabel2->setText(tr("SECOND_NODE_ID"));
+ TextLabel3->setText(tr("LAST_NODE_ID"));
+ TextLabel4->setText(tr("FIRST_NODE_ID"));
+ TextLabel5->setText(tr("SECOND_NODE_ID"));
+ TextLabel6->setText(tr("LAST_NODE_ID"));
+
+ LineEdit1->setValidator(new SMESHGUI_IdValidator(this, 1));
+ LineEdit4->setValidator(new SMESHGUI_IdValidator(this, 1));
+ }
+
+ if ( myActor )
+ myActor->SetPointRepresentation( isNodeSelection );
+
+ if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+ aViewWindow->SetSelectionMode( isNodeSelection ? NodeSelection : ActorSelection );
+
+ UpdateButtons();
+
+ connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
+ mySelectionMgr->setSelectedObjects( io );
+
+ QApplication::instance()->processEvents();
+ updateGeometry();
+
+ resize(100,100);
+}
+
+//=======================================================================
+//function : storeDisplayMode
+//purpose : save representation of a mesh and switch it to wireframe mode
+//=======================================================================
+
+void SMESHGUI_SewingDlg::setDisplayMode()
+{
+ if ( myStoredEntityMode )
+ return;
+ myStoredEntityMode = 0;
+ myStoredRepresentation = -1;
+
+ if ( myActor && AutoSewCheck->isVisible() && !AutoSewCheck->isChecked() )
+ {
+ myStoredEntityMode = myActor->GetEntityMode();
+ myStoredRepresentation = myActor->GetRepresentation();
+
+ myActor->SetEntityMode( myStoredEntityMode & ~SMESH_Actor::eVolumes );
+ myActor->SetRepresentation( SMESH_Actor::eEdge );
+ }
+}
+
+//=======================================================================
+//function : restoreDisplayMode
+//purpose : restore representation of a mesh
+//=======================================================================
+
+void SMESHGUI_SewingDlg::restoreDisplayMode()
+{
+ if ( myActor && myStoredEntityMode )
+ {
+ if ( myActor->GetEntityMode() == ( myStoredEntityMode & ~SMESH_Actor::eVolumes ))
+ myActor->SetEntityMode( myStoredEntityMode );
+
+ if ( myActor->GetRepresentation() == SMESH_Actor::eEdge )
+ myActor->SetRepresentation( myStoredRepresentation );
+
+ myStoredEntityMode = 0;
+ myStoredRepresentation = -1;
+ }
+ for ( size_t i = 0; i < myBorderDisplayers.size(); ++i )
+ if ( myBorderDisplayers[ i ])
+ myBorderDisplayers[ i ]->Hide();
+}
+
+//=======================================================================
+//function : onModeChange
+//purpose : SLOT called when mode (auto or manual) of Sew free borders change
+//=======================================================================
+
+void SMESHGUI_SewingDlg::onModeChange( int mode )
+{
+ if ( mode == MODE_MANUAL )
+ {
+ myEditCurrentArgument = LineEdit1;
+ if ( !SubGroup1->isVisible() )
+ SubGroup1->show(), SubGroup2->show();
+ SewFreeBordersWidget->hide();
+ }
+ else
+ {
+ myEditCurrentArgument = LineEditMesh;
+ SubGroup1->hide(), SubGroup2->hide();
+ if ( !SewFreeBordersWidget->isVisible() )
+ SewFreeBordersWidget->show();
+ }
+ if ( myActor )
+ myActor->SetPointRepresentation( mode == MODE_MANUAL );
+
+ if ( SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView() )
+ aViewWindow->SetSelectionMode( mode == MODE_MANUAL ? NodeSelection : ActorSelection );
+
+ onAutoSew( AutoSewCheck->isChecked() );
+
+ QApplication::instance()->processEvents();
+ updateGeometry();
+
+ resize(100,100);
+}
+
+//=======================================================================
+//function : onAutoSew
+//purpose : SLOT called when Auto Sewing check box is checked
+//=======================================================================
+
+void SMESHGUI_SewingDlg::onAutoSew( int isAuto )
+{
+ GroupCoincidentWidget->setVisible( !isAuto );
+
+ QApplication::instance()->processEvents();
+
+ SewFreeBordersWidget->hide();
+ if ( ModeButGrp->checkedId() == MODE_AUTO )
+ SewFreeBordersWidget->show();
+
+ if ( isAuto )
+ restoreDisplayMode();
+ else
+ setDisplayMode();
+ SMESH::RepaintCurrentView();
+
+ UpdateButtons();
+
+ updateGeometry();
+ resize(minimumSizeHint());
+}
+
+//=======================================================================
+//function : haveBorders
+//purpose : Returns true if myBorders have been initialized
+//=======================================================================
+
+bool SMESHGUI_SewingDlg::haveBorders()
+{
+ return ( & myBorders.in() &&
+ myBorders->borders.length() &&
+ myBorders->coincidentGroups.length() );
+}
+
+//=======================================================================
+//function : getGroupText
+//purpose : Returns a text of a given group of coincident free borders
+//=======================================================================
+
+QString SMESHGUI_SewingDlg::getPartText(const SMESH::FreeBorderPart& aPART)
+{
+ typedef CORBA::Long TInt;
+ QString text;
+ if ( 0 <= aPART.border && aPART.border < (TInt)myBorders->borders.length() )
+ {
+ const SMESH::FreeBorder& aBRD = myBorders->borders[ aPART.border ];
+ if ( 0 <= aPART.node1 && aPART.node1 < (TInt)aBRD.nodeIDs.length() &&
+ 0 <= aPART.nodeLast && aPART.nodeLast < (TInt)aBRD.nodeIDs.length() )
+ {
+ text += QString("( %1 %2 %3 ) ")
+ .arg( aBRD.nodeIDs[ aPART.node1 ] )
+ .arg( aBRD.nodeIDs[ aPART.node2 ] )
+ .arg( aBRD.nodeIDs[ aPART.nodeLast ] );
+ }
+ }
+ return text;
+}
+
+//=======================================================================
+//function : getGroupText
+//purpose : Returns a text of a given group of coincident free borders
+//=======================================================================
+
+QString SMESHGUI_SewingDlg::getGroupText(int groupIndex)
+{
+ QString text;
+
+ if ( haveBorders() &&
+ groupIndex >= 0 &&
+ groupIndex < (int)myBorders->coincidentGroups.length() )
+ {
+ const SMESH::FreeBordersGroup& aGRP = myBorders->coincidentGroups[ groupIndex ];
+
+ for ( CORBA::ULong iP = 0; iP < aGRP.length(); ++iP )
+ {
+ QString partText = getPartText( aGRP[ iP ]);
+ if ( partText.isEmpty() )
+ return "";
+ text += partText;
+ }
+ }
+ return text;
+}
+
+//=======================================================================
+//function : onDetectClicked
+//purpose : SLOT called when [Detect] is clicked
+//=======================================================================
+
+void SMESHGUI_SewingDlg::onDetectClicked()
+{
+ myBusy = true;
+ ListCoincident->clear();
+
+ if ( myMesh->_is_nil() )
+ return;
+
+ SUIT_OverrideCursor wc;
+
+ SMESH::SMESH_MeshEditor_var editor = myMesh->GetMeshEditor();
+ myBorders = editor->FindCoincidentFreeBorders( SpinBoxTolerance->GetValue() );
+ if ( haveBorders() )
+ {
+ for ( size_t i = 0; i < myBorderDisplayers.size(); ++i )
+ {
+ delete myBorderDisplayers[ i ];
+ myBorderDisplayers[ i ] = 0;
+ }
+ myBorderDisplayers.resize( myBorders->coincidentGroups.length(), 0 );
+
+ for ( uint i = 0; i < myBorders->coincidentGroups.length(); ++i )
+ {
+ QString groupText = getGroupText( i );
+ if ( groupText.isEmpty() )
+ continue;
+
+ QColor groupColor;
+ groupColor.setHsvF( float(i) / myBorders->coincidentGroups.length(), 1., 1. );
+ QPixmap icon( QSize( 20, 20 ));
+ icon.fill( groupColor );
+
+ QListWidgetItem * item = new QListWidgetItem( icon, groupText, ListCoincident );
+ item->setData( GROUP_COLOR, groupColor );
+ item->setData( GROUP_INDEX, i );
+ }
+ }
+ myBusy = false;
+
+ onSelectGroup();
+
+ UpdateButtons();
+}
+
+//=======================================================================
+//function : onRemoveGroupClicked
+//purpose :
+//=======================================================================
+
+void SMESHGUI_SewingDlg::onRemoveGroupClicked()
+{
+ myBusy = true;
+ QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
+ for ( int i = 0; i < selItems.count(); ++i )
+ {
+ QListWidgetItem* item = selItems[ i ];
+ item->setSelected( false );
+ int groupIndex = item->data( GROUP_INDEX ).toInt();
+ delete item;
+ if ( myBorderDisplayers[ groupIndex ])
+ myBorderDisplayers[ groupIndex ]->Hide();
+ SMESH::FreeBordersGroup& aGRP = myBorders->coincidentGroups[ groupIndex ];
+ aGRP.length( 0 );
+ }
+ myBusy = false;
+
+ onSelectGroup();
+ UpdateButtons();
+}
+
+//=======================================================================
+//function : showGroup
+//purpose : display a group of coincident free borders in the Viewer
+//=======================================================================
+
+void SMESHGUI_SewingDlg::showGroup( QListWidgetItem* item )
+{
+ if ( !item ||
+ item->listWidget() != ListCoincident ||
+ !haveBorders())
+ return;
+
+ int groupIndex = item->data( GROUP_INDEX ).toInt();
+ QColor groupColor = item->data( GROUP_COLOR ).value<QColor>();
+ if ( groupIndex >= 0 &&
+ groupIndex < (int)myBorders->coincidentGroups.length() )
+ {
+ if ( !myBorderDisplayers[ groupIndex ] && SMESH::GetCurrentVtkView())
+ myBorderDisplayers[ groupIndex ] = new BorderGroupDisplayer( myBorders, groupIndex, groupColor, myMesh );
+ bool wholeBorders = setCurrentGroup();
+ if ( myBorderDisplayers[ groupIndex ])
+ myBorderDisplayers[ groupIndex ]->ShowGroup( wholeBorders );
+ }
+}
+
+//=======================================================================
+//function : setCurrentGroup
+//purpose : set index of a current free border group to myCurGroupIndex
+//=======================================================================
+
+bool SMESHGUI_SewingDlg::setCurrentGroup()
+{
+ if ( !haveBorders() )
+ return false;
+
+ QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
+ if ( selItems.count() != 1 )
+ return false;