+//================================================================================
+/*!
+ * \brief SLOT: Activate selection of faces in the Viewer
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onHyPatchFaceSelection(bool on)
+{
+ if ( on && myHyPatchFaceSelector->GetMainShape().IsNull() )
+ {
+ QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
+ QString aSubEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
+ myHyPatchFaceSelector->SetGeomShapeEntry( aSubEntry, aMainEntry );
+ }
+ myHyPatchFaceSelector->setVisible( on ); // show its buttons
+ myHyPatchFaceSelector->ShowPreview( on ); // show faces in the Viewer
+ // treat selection or not
+ myHyPatchFaceSelector->ActivateSelection( on || myHyPatchGroupSelBtn->isChecked() );
+
+ if ( on )
+ myHyPatchGroupSelBtn->setChecked( false );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT: Deactivate selection of faces in the Viewer
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onHyPatchGroupSelection(bool on)
+{
+ if ( on && myHyPatchFaceSelector->GetMainShape().IsNull() )
+ {
+ QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
+ QString aSubEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
+ myHyPatchFaceSelector->SetGeomShapeEntry( aSubEntry, aMainEntry );
+ }
+ if ( !myHyPatchFaceSelBtn->isChecked() )
+ {
+ myHyPatchFaceSelector->setVisible( false ); // show its buttons
+ myHyPatchFaceSelector->ShowPreview( false ); // show faces in the Viewer
+ }
+ // treat selection or not
+ myHyPatchFaceSelector->ActivateSelection( on || myHyPatchFaceSelBtn->isChecked() );
+
+ if ( on )
+ myHyPatchFaceSelBtn->setChecked( false );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT: show IDs of selected faces in Tags LineEdit
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onHyPatchSelectionChanged()
+{
+ QString tagString;
+ const QList<int>& tags = myHyPatchFaceSelector->GetSelectedIDs();
+ for ( int i = 0; i < tags.size(); ++i )
+ tagString += QString::number( tags[i] ) + " ";
+
+ myHyPatchTagsLE->setText( tagString );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT: Add the Tags to the HyperPatch table
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onHyPatchAdd()
+{
+ QStringList tagList = myHyPatchTagsLE->text().split(" ", QString::SkipEmptyParts);
+ if ( tagList.size() > 1 )
+ {
+ LightApp_SelectionMgr* selMrg = SMESHGUI::GetSMESHGUI()->selectionMgr();
+ SALOME_ListIO aList;
+ selMrg->selectedObjects( aList );
+ QString entries;
+ for ( SALOME_ListIteratorOfListIO anIt( aList ); anIt.More(); anIt.Next() )
+ {
+ Handle(SALOME_InteractiveObject) io = anIt.Value();
+ GEOM::GEOM_Object_var go = myHyPatchFaceSelector->GetGeomObjectByEntry( io->getEntry() );
+ if ( !CORBA::is_nil( go ))
+ entries += io->getEntry() + QString(" ");
+ else
+ {
+ entries.clear();
+ break;
+ }
+ }
+ addHyPatchToTable( myHyPatchTagsLE->text(), entries );
+ myHyPatchTagsLE->setText("");
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Add a row to myHyPatchTable
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::addHyPatchToTable(const QString& tags,
+ const QString& entries)
+{
+ if ( tags.isEmpty() ) return;
+
+ QTableWidgetItem* cell = new QTableWidgetItem( tags );
+ cell->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
+ if ( entries.isEmpty() )
+ cell->setData( Qt::UserRole, QVariant() );
+ else
+ cell->setData( Qt::UserRole, entries );
+
+ int row = myHyPatchTable->rowCount();
+ myHyPatchTable->insertRow( row );
+ myHyPatchTable->setItem( row, 0, cell );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT: remove selected rows from the HyperPatch table
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onHyPatchRemove()
+{
+ QList<QTableWidgetItem *> items = myHyPatchTable->selectedItems();
+ while ( !items.isEmpty() )
+ {
+ myHyPatchTable->removeRow( items[0]->row() );
+ items = myHyPatchTable->selectedItems();
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Add a new row in Enforced mesh table
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::addEnforcedMesh( SMESH::SMESH_IDSource_ptr mesh,
+ const QString& groupName )
+{
+ _PTR(SObject) sobj = SMESH::FindSObject( mesh );
+ if ( !sobj )
+ return;
+
+ QString meshEntry = sobj->GetID().c_str();
+ QString meshName = sobj->GetName().c_str();
+
+ QTableWidgetItem* meshCell = new QTableWidgetItem( meshName );
+ meshCell->setData( Qt::UserRole, meshEntry );
+ meshCell->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
+
+ QTableWidgetItem* groupCell = new QTableWidgetItem( groupName );
+ groupCell->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable );
+
+ int row = myEnfMeshTableWdg->rowCount();
+ myEnfMeshTableWdg->insertRow( row );
+ myEnfMeshTableWdg->setItem( row, 0, meshCell );
+ myEnfMeshTableWdg->setItem( row, 1, groupCell );
+
+ myEnfMeshTableWdg->resizeColumnToContents( 0 );
+ myEnfMeshTableWdg->resizeColumnToContents( 1 );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT called when [Add] is clicked in Enforced mesh tab.
+ * Add an item to the enforced meshes table
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedMesh()
+{
+ if ( myEnfMeshWdg->NbObjects() != 1 )
+ return;
+
+ SMESH::SMESH_IDSource_var mesh = myEnfMeshWdg->GetObject< SMESH::SMESH_IDSource >();
+ QString groupName = myEnforcedGroupName->text().simplified();
+
+ addEnforcedMesh( mesh, groupName );
+
+ selectionMgr()->clearSelected();
+ myEnfMeshWdg->SetObject( SMESH::SMESH_IDSource::_nil() );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT called when [Remove] is clicked in Enforced mesh tab.
+ * Remove a selected mesh from the enforced meshes table
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedMesh()
+{
+ QList<int> selectedRows;
+ QList<QTableWidgetItem *> selectedItems = myEnfMeshTableWdg->selectedItems();
+ QTableWidgetItem* item;
+ int row;
+ foreach( item, selectedItems )
+ {
+ row = item->row();
+ if (!selectedRows.contains( row ) )
+ selectedRows.append(row);
+ }
+
+ qSort( selectedRows );
+ QListIterator<int> it( selectedRows );
+ it.toBack();
+ while ( it.hasPrevious() ) {
+ row = it.previous();
+ myEnfMeshTableWdg->removeRow(row );
+ }
+
+ myEnfMeshTableWdg->selectionModel()->clearSelection();
+
+ onEnforcedMeshSelected(); // to activate [Add] if possible
+}
+
+//================================================================================
+/*!
+ * \brief SLOT called when mesh selection changes. Enable/disable [Add] button
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onEnforcedMeshSelected()
+{
+ bool enable = ( myEnfMeshWdg->NbObjects() == 1 );
+ if ( enable )
+ {
+ // check if a selected mesh contains segments
+ SMESH::SMESH_IDSource_var mesh = myEnfMeshWdg->GetObject< SMESH::SMESH_IDSource >();
+ if (( enable = !mesh->_is_nil() ))
+ {
+ SMESH::array_of_ElementType_var types = mesh->GetTypes();
+ if (( enable = ( types->length() > 0 )))
+ {
+ enable = false;
+ for ( CORBA::ULong i = 0; i < types->length() && !enable; ++i )
+ enable = ( types[ i ] = SMESH::EDGE );
+ }
+ }
+
+ // check if this mesh is already in the table
+ if ( enable )
+ {
+ _PTR(SObject) sobj = SMESH::FindSObject( mesh );
+ if (( enable = bool( sobj )))
+ {
+ QString meshEntry = sobj->GetID().c_str();
+ for ( int row = 0, nbRow = myEnfMeshTableWdg->rowCount(); row < nbRow && enable; ++row )
+ {
+ QTableWidgetItem * cell = myEnfMeshTableWdg->item( row, 0 );
+ enable = ( meshEntry != cell->data( Qt::UserRole ).toString() );
+ }
+ }
+ }
+ }
+ myAddEnfMeshButton->setEnabled( enable );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT called when selection changes in the table. Enable/disable [Remove] button
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onEnfMeshTableSelected()
+{
+ bool enable = !myEnfMeshTableWdg->selectedItems().empty();
+
+ myRemoveEnfMeshButton->setEnabled( enable );
+}
+
+//================================================================================
+/*!
+ * \brief Return false if algorithm is a re-mesher
+ */
+//================================================================================
+
+bool BLSURFPluginGUI_HypothesisCreator::hasGeom() const
+{
+ return hypType() == BLSURFPlugin_Hypothesis::GetHypType(true);
+}
+