+
+//=================================================================================
+// function : keyPressEvent()
+// purpose :
+//=================================================================================
+void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
+{
+ QDialog::keyPressEvent( e );
+ if ( e->isAccepted() )
+ return;
+
+ if ( e->key() == Qt::Key_F1 )
+ {
+ e->accept();
+ onHelp();
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Enable showing of the popup when Geometry selection btn is clicked
+ * \param enable - true to enable
+ */
+//================================================================================
+
+enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
+
+void SMESHGUI_GroupDlg::updateGeomPopup()
+{
+ bool enable = false;
+
+ if ( !myMesh->_is_nil() )
+ enable = myMesh->NbEdges() > 0;
+
+ if ( myGeomGroupBtn )
+ {
+ disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
+ if ( enable ) {
+ if ( !myGeomPopup ) {
+ myGeomPopup = new QMenu(this);
+ myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
+ myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
+ connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
+ }
+ connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
+ }
+ }
+}
+
+
+//=================================================================================
+// function : onGeomSelectionButton()
+// purpose :
+//=================================================================================
+void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
+{
+ if ( myGeomPopup && isBtnOn )
+ {
+ myCurrentLineEdit = myGeomGroupLine;
+ QAction* a = myGeomPopup->exec( QCursor::pos() );
+ if (!a || myActions[a] == DIRECT_GEOM_INDEX)
+ setSelectionMode(7);
+ }
+ else if (!isBtnOn)
+ {
+ myCurrentLineEdit = 0;
+ setSelectionMode(8);
+ }
+}
+
+//=================================================================================
+// function : onGeomPopup()
+// purpose :
+//=================================================================================
+void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
+{
+ int index = myActions[a];
+ if ( index == GEOM_BY_MESH_INDEX )
+ {
+ mySelectionMode = -1;
+ if ( !myShapeByMeshOp ) {
+ myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
+ connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
+ SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
+ connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
+ SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
+ }
+ // set mesh object to SMESHGUI_ShapeByMeshOp and start it
+ if ( !myMesh->_is_nil() ) {
+ myIsBusy = true;
+ hide(); // stop processing selection
+ myIsBusy = false;
+ myShapeByMeshOp->setModule( mySMESHGUI );
+ myShapeByMeshOp->setStudy( 0 ); // it's really necessary
+ myShapeByMeshOp->SetMesh( myMesh );
+ myShapeByMeshOp->start();
+ }
+ }
+}
+
+//================================================================================
+/*!
+ * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
+ */
+//================================================================================
+
+void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
+{
+ if ( myShapeByMeshOp == op ) {
+ mySMESHGUI->getApp()->updateObjectBrowser();
+ show();
+ // Select a found geometry object
+ GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
+ if ( !aGeomVar->_is_nil() )
+ {
+ QString ID = aGeomVar->GetStudyEntry();
+ _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+ if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
+ SALOME_ListIO anIOList;
+ Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
+ ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
+ anIOList.Append( anIO );
+ mySelectionMgr->setSelectedObjects( anIOList, false );
+ onObjectSelectionChanged();
+ }
+ }
+ }
+}
+
+//================================================================================
+/*!
+ * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
+ */
+//================================================================================
+
+void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
+{
+ if ( myShapeByMeshOp == op )
+ {
+ show();
+ setSelectionMode(7);
+ }
+}
+
+//=================================================================================
+// function : setGroupColor()
+// purpose :
+//=================================================================================
+void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
+{
+ QColor aQColor( (int)( theColor.R * 255.0 ),
+ (int)( theColor.G * 255.0 ),
+ (int)( theColor.B * 255.0 ) );
+ setGroupQColor( aQColor );
+}
+
+//=================================================================================
+// function : getGroupColor()
+// purpose :
+//=================================================================================
+SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
+{
+ QColor aQColor = getGroupQColor();
+
+ SALOMEDS::Color aColor;
+ aColor.R = (float)aQColor.red() / 255.0;
+ aColor.G = (float)aQColor.green() / 255.0;
+ aColor.B = (float)aQColor.blue() / 255.0;
+
+ return aColor;
+}
+
+//=================================================================================
+// function : setGroupQColor()
+// purpose :
+//=================================================================================
+void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
+{
+ if( theColor.isValid() )
+ myColorBtn->setColor( theColor );
+}
+
+//=================================================================================
+// function : getGroupQColor()
+// purpose :
+//=================================================================================
+QColor SMESHGUI_GroupDlg::getGroupQColor() const
+{
+ return myColorBtn->color();
+}
+
+//=================================================================================
+// function : setDefaultGroupColor()
+// purpose :
+//=================================================================================
+void SMESHGUI_GroupDlg::setDefaultGroupColor()
+{
+ if( myMesh->_is_nil() )
+ return;
+
+ bool isAutoColor = myMesh->GetAutoColor();
+
+ QColor aQColor;
+ if( !isAutoColor )
+ {
+ int r = 0, g = 0, b = 0;
+ SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
+ aQColor.setRgb( r, g, b );
+ }
+ else
+ {
+ SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
+
+ QList<SALOMEDS::Color> aReservedColors;
+ for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
+ {
+ SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
+ SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
+ aReservedColors.append( aReservedColor );
+ }
+
+ SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
+ aQColor.setRgb( (int)( aColor.R * 255.0 ),
+ (int)( aColor.G * 255.0 ),
+ (int)( aColor.B * 255.0 ) );
+
+ }
+
+ setGroupQColor( aQColor );
+}
+
+//=================================================================================
+// function : SetAppropriateActor()
+// purpose : Find more appropriate of visible actors, set it to myActor, allow picking
+// NPAL19389: create a group with a selection in another group.
+// if mesh actor is not visible - find any first visible group or submesh
+//=================================================================================
+bool SMESHGUI_GroupDlg::SetAppropriateActor()
+{
+ bool isActor = false;
+
+ if (myMesh->_is_nil()) return false;
+
+ SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
+
+ // try mesh actor
+ myActor = SMESH::FindActorByObject(myMesh);
+ if (myActor && myActor->hasIO())
+ {
+ isActor = true;
+ if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
+ isActor = false;
+ }
+
+ // try current group actor
+ if (!isActor) {
+ if (!myGroup->_is_nil()) {
+ myActor = SMESH::FindActorByObject(myGroup);
+ if (myActor && myActor->hasIO())
+ {
+ isActor = true;
+ if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
+ isActor = false;
+ }
+ }
+ }
+
+ // try current group on geometry actor
+ if (!isActor) {
+ if (!myGroupOnGeom->_is_nil()) {
+ myActor = SMESH::FindActorByObject(myGroupOnGeom);
+ if (myActor && myActor->hasIO())
+ {
+ isActor = true;
+ if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
+ isActor = false;
+ }
+ }
+ }
+
+ // try any visible actor of group or submesh of current mesh
+ if (!isActor && aViewWindow) {
+ // mesh entry
+ _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
+ if (aSObject) {
+ CORBA::String_var meshEntry = aSObject->GetID().c_str();
+ int len = strlen(meshEntry);
+
+ // iterate on all actors in current view window, search for
+ // any visible actor, that belongs to group or submesh of current mesh
+ vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
+ aCollection->InitTraversal();
+ for (vtkActor *anAct = aCollection->GetNextActor();
+ anAct && !isActor;
+ anAct = aCollection->GetNextActor())
+ {
+ SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct);
+ if (anActor && anActor->hasIO()) {
+ Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
+ if (aViewWindow->isVisible(anIO)) {
+ if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0) {
+ myActor = anActor;
+ isActor = true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (isActor)
+ SMESH::SetPickable(myActor);
+
+ return isActor;
+}
+
+//=======================================================================
+//function : setShowEntityMode
+//purpose : make shown only entity corresponding to my type
+//=======================================================================
+void SMESHGUI_GroupDlg::setShowEntityMode()
+{
+ if ( !myMesh->_is_nil() ) {
+ if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
+ if (!myStoredShownEntity)
+ myStoredShownEntity = actor->GetEntityMode();
+ switch ( myTypeId ) {
+ case 0: restoreShowEntityMode(); break;
+ case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
+ case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
+ case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
+ }
+ }
+ }
+}
+
+//=======================================================================
+//function : restoreShowEntityMode
+//purpose : restore ShowEntity mode of myActor
+//=======================================================================
+void SMESHGUI_GroupDlg::restoreShowEntityMode()
+{
+ if ( myStoredShownEntity && !myMesh->_is_nil() ) {
+ if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
+ actor->SetEntityMode(myStoredShownEntity);
+ }
+ }
+ myStoredShownEntity = 0;
+}