+//================================================================================
+/*!
+ * \brief Create a sub-mesh on internal edges in the case where the global algorithm
+ * is of type 1D-2D[-3D] so that the internal edges would remain not meshed.
+ */
+//================================================================================
+
+void SMESHGUI_MeshOp::createSubMeshOnInternalEdges( SMESH::SMESH_Mesh_ptr theMesh,
+ GEOM::GEOM_Object_ptr theMainShape )
+{
+ if ( theMesh->_is_nil() || theMainShape->_is_nil() )
+ return;
+
+ if ( isAccessibleDim( 1 ))
+ return; // global 1D algorithm is/can be assigned
+
+ const HypothesesSet::SetType internSet = HypothesesSet::INTERN;
+ bool toCreate = true;
+ bool toCreateMandatory = ( myHypoSet &&
+ myAverageSize > 0 &&
+ ( myHypoSet->init( /*algo=*/ true, internSet ), myHypoSet->more()) &&
+ ( myHypoSet->init( /*algo=*/false, internSet ), myHypoSet->more()));
+ if ( !toCreateMandatory ) // ask the user
+ toCreate = false; // can't pass both mesh and geometry to Create Submesh operation (so far?)
+ // toCreate = SUIT_MessageBox::warning( SMESHGUI::desktop(),
+ // QObject::tr("SMESH_WRN_WARNING"),
+ // QObject::tr("SMESH_CREATE_SUBMESH_ON_INTERNAL_EDGES"),
+ // QObject::tr("SMESH_BUT_YES"),
+ // QObject::tr("SMESH_BUT_NO"), 1, 0);
+ if ( !toCreate )
+ return;
+
+ TopoDS_Shape shape;
+ if ( !GEOMBase::GetShape( theMainShape, shape ))
+ return;
+
+ std::vector< TopoDS_Shape > internalEdges;
+ for ( TopExp_Explorer edge( shape, TopAbs_EDGE, TopAbs_WIRE ); edge.More(); edge.Next() )
+ internalEdges.push_back( edge.Current() );
+
+ if ( internalEdges.empty() )
+ return;
+
+ TopTools_IndexedMapOfShape shapeIDs;
+ TopExp::MapShapes( shape, shapeIDs );
+
+ std::set< int > intIDSet;
+ for ( size_t i = 0; i < internalEdges.size(); ++i )
+ intIDSet.insert( shapeIDs.FindIndex( internalEdges[ i ]));
+
+ GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
+ if (geomGen->_is_nil()) return;
+
+ GEOM::GEOM_Object_var edgeGroup;
+ GEOM::GEOM_IShapesOperations_wrap sOp = geomGen->GetIShapesOperations();
+ GEOM::GEOM_IGroupOperations_wrap gOp = geomGen->GetIGroupOperations();
+ GEOM::ListOfGO_var geomGroups = sOp->GetExistingSubObjects( theMainShape,
+ /*groupsOnly=*/true );
+ for ( CORBA::ULong i = 0; i < geomGroups->length(); ++i )
+ {
+ GEOM::ListOfLong_var ids = gOp->GetObjects( geomGroups[ i ]);
+ std::set< int > idSet( & ids[0], & ids[0] + ids->length() );
+ if ( idSet == intIDSet )
+ {
+ edgeGroup = geomGroups[ i ];
+ break;
+ }
+ }
+
+ if ( edgeGroup->_is_nil() )
+ {
+ GEOM::GEOM_Object_var edgeGroup = gOp->CreateGroup( theMainShape, TopAbs_EDGE );
+
+ GEOM::ListOfLong_var edgeIDs = new GEOM::ListOfLong;
+ edgeIDs->length( internalEdges.size() );
+ std::set< int >::iterator id = intIDSet.begin();
+ for ( size_t i = 0; i < intIDSet.size(); ++i, ++id )
+ edgeIDs[ i ] = *id;
+ gOp->UnionIDs( edgeGroup, edgeIDs );
+
+ SALOMEDS::SObject_wrap so = geomGen->AddInStudy( edgeGroup, "Internal edges", theMainShape );
+ }
+
+ if ( !toCreateMandatory )
+ {
+ // show Create Sub-mesh dislog
+ // _PTR(SObject) aMeshSO = SMESH::FindSObject( theMesh );
+ // selectionMgr()->clearFilters();
+ // selectObject( pSubmesh );
+ // SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
+ return;
+ }
+
+ // create a sub-mesh using myAverageSize w/o GUI
+
+ SMESH::SMESH_subMesh_var subMesh = theMesh->GetSubMesh( edgeGroup, "" );
+
+ for ( int isAlgo = 1; isAlgo >= 0; --isAlgo )
+ for ( myHypoSet->init( isAlgo, internSet ); myHypoSet->more(); myHypoSet->next() )
+ {
+ QString aHypoTypeName = myHypoSet->current();
+ HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
+ if ( !aHypData )
+ continue;
+
+ myDim = aHypData->Dim[0];
+ if ( myDim != 1 )
+ continue;
+
+ // create or/and set
+ SMESH::SMESH_Hypothesis_var newHypo;
+ if ( isAlgo )
+ {
+ myAvailableHypData[ myDim ][ Algo ].clear();
+ myAvailableHypData[ myDim ][ Algo ] << aHypData;
+ QStringList hypList; hypList << aHypoTypeName;
+ myDlg->tab( myDim )->setAvailableHyps( Algo, hypList );
+ setCurrentHyp( myDim, Algo, 0 );
+ newHypo = getAlgo( myDim );
+ }
+ else
+ {
+ SMESH::HypInitParams params = { 2, myAverageSize, false };
+ newHypo = getInitParamsHypothesis( aHypData->TypeName, aHypData->ServerLibName, & params );
+ QString hypName = GetUniqueName( getHypoNames(), aHypData->Label );
+ SALOMEDS::SObject_wrap so =
+ SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(), newHypo,
+ hypName.toUtf8().data() );
+ }
+ SMESH::AddHypothesisOnSubMesh( subMesh, newHypo );
+ }
+
+ return;
+}
+
+//================================================================================
+/*!
+ * \brief Ask the user to enter an average size which will be used to create
+ * hypotheses of a hypo-set basing on this size
+ * \param [out] averageSize - average element size
+ * \return bool - false if the user canceled the dialog
+ */
+//================================================================================
+
+bool SMESHGUI_MeshOp::getAverageSize( double & averageSize )
+{
+ HypothesisData* hypData = SMESH::GetHypothesisData( "MaxLength" );
+ if ( !hypData )
+ return false;
+
+ SMESH::SMESH_Hypothesis_var hyp = getInitParamsHypothesis( hypData->TypeName,
+ hypData->ServerLibName );
+ if ( hyp->_is_nil() )
+ return false;
+
+ SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( hypData->TypeName );
+ if ( !aCreator )
+ return false;
+
+ initHypCreator( aCreator );
+ myDlg->setEnabled( false );
+
+ aCreator->edit( hyp.in(), HypothesesSet::getCommonHypoSetHypoType(),
+ dlg(), this, SLOT( onHypoEdited( int )));
+
+ StdMeshers::StdMeshers_MaxLength_var lenHyp = StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
+ if ( lenHyp->_is_nil() )
+ return false;
+
+ averageSize = lenHyp->GetLength();
+ return true;
+}
+