+
+//================================================================================
+/*!
+ * \brief Create a polyline consisting of 1D mesh elements each lying on a 2D element of
+ * the initial mesh. Positions of new nodes are found by cutting the mesh by the
+ * plane passing through pairs of points specified by each PolySegment structure.
+ * If there are several paths connecting a pair of points, the shortest path is
+ * selected by the module. Position of the cutting plane is defined by the two
+ * points and an optional vector lying on the plane specified by a PolySegment.
+ * By default the vector is defined by Mesh module as following. A middle point
+ * of the two given points is computed. The middle point is projected to the mesh.
+ * The vector goes from the middle point to the projection point. In case of planar
+ * mesh, the vector is normal to the mesh.
+ * \param [inout] segments - PolySegment's defining positions of cutting planes.
+ * Return the used vector and position of the middle point.
+ * \param [in] groupName - optional name of a group where created mesh segments will
+ * be added.
+ */
+//================================================================================
+
+void SMESH_MeshEditor_i::MakePolyLine(SMESH::ListOfPolySegments& theSegments,
+ const char* theGroupName)
+{
+ if ( theSegments.length() == 0 )
+ THROW_SALOME_CORBA_EXCEPTION("No segments given", SALOME::BAD_PARAM );
+ if ( myMesh->NbFaces() == 0 )
+ THROW_SALOME_CORBA_EXCEPTION("No faces in the mesh", SALOME::BAD_PARAM );
+
+ SMESH_TRY;
+ initData(/*deleteSearchers=*/false);
+
+ SMESHDS_Group* groupDS = 0;
+ SMESHDS_Mesh* meshDS = getMeshDS();
+ if ( myIsPreviewMode ) // copy faces to the tmp mesh
+ {
+ TPreviewMesh * tmpMesh = getPreviewMesh( SMDSAbs_Edge );
+ SMDS_ElemIteratorPtr faceIt = getMeshDS()->elementsIterator( SMDSAbs_Face );
+ while ( faceIt->more() )
+ tmpMesh->Copy( faceIt->next() );
+ meshDS = tmpMesh->GetMeshDS();
+ }
+ else if ( theGroupName[0] ) // find/create a group of segments
+ {
+ // SMESH_Mesh::GroupIteratorPtr grpIt = myMesh->GetGroups();
+ // while ( !groupDS && grpIt->more() )
+ // {
+ // SMESH_Group* group = grpIt->next();
+ // if ( group->GetGroupDS()->GetType() == SMDSAbs_Edge &&
+ // strcmp( group->GetName(), theGroupName ) == 0 )
+ // {
+ // groupDS = dynamic_cast< SMESHDS_Group* >( group->GetGroupDS() );
+ // }
+ // }
+ if ( !groupDS )
+ {
+ SMESH::SMESH_Group_var groupVar = myMesh_i->CreateGroup( SMESH::EDGE, theGroupName );
+
+ if ( SMESH_Group_i* groupImpl = SMESH::DownCast<SMESH_Group_i*>( groupVar ))
+ groupDS = dynamic_cast< SMESHDS_Group* >( groupImpl->GetGroupDS() );
+ }
+ }
+
+ // convert input polySegments
+ SMESH_MeshAlgos::TListOfPolySegments segments( theSegments.length() );
+ for ( CORBA::ULong i = 0; i < theSegments.length(); ++i )
+ {
+ SMESH::PolySegment& segIn = theSegments[ i ];
+ SMESH_MeshAlgos::PolySegment& segOut = segments[ i ];
+ segOut.myNode1[0] = meshDS->FindNode( segIn.node1ID1 );
+ segOut.myNode2[0] = meshDS->FindNode( segIn.node1ID2 );
+ segOut.myNode1[1] = meshDS->FindNode( segIn.node2ID1 );
+ segOut.myNode2[1] = meshDS->FindNode( segIn.node2ID2 );
+ segOut.myXYZ[0].SetCoord( segIn.xyz1.x,
+ segIn.xyz1.y,
+ segIn.xyz1.z);
+ segOut.myXYZ[1].SetCoord( segIn.xyz2.x,
+ segIn.xyz2.y,
+ segIn.xyz2.z);
+ segOut.myVector.SetCoord( segIn.vector.PS.x,
+ segIn.vector.PS.y,
+ segIn.vector.PS.z );
+ }
+
+ // get a static ElementSearcher
+ SMESH::SMESH_IDSource_var idSource = SMESH::SMESH_IDSource::_narrow( myMesh_i->_this() );
+ theSearchersDeleter.Set( myMesh, getPartIOR( idSource, SMESH::FACE ));
+ if ( !theElementSearcher )
+ theElementSearcher = SMESH_MeshAlgos::GetElementSearcher( *getMeshDS() );
+
+ // compute
+ std::vector<const SMDS_MeshElement*> newEdges;
+ std::vector<const SMDS_MeshNode*> newNodes;
+ SMESH_MeshAlgos::MakePolyLine( meshDS, segments, newEdges, newNodes,
+ groupDS ? &groupDS->SMDSGroup() : 0,
+ theElementSearcher );
+
+ const_cast< SMESH_SequenceOfElemPtr& >( getEditor().GetLastCreatedElems() ).
+ swap( newEdges );
+ const_cast< SMESH_SequenceOfElemPtr& >( getEditor().GetLastCreatedNodes() ).
+ assign( newNodes.begin(), newNodes.end() );
+
+ // return vectors
+ if ( myIsPreviewMode )
+ {
+ for ( CORBA::ULong i = 0; i < theSegments.length(); ++i )
+ {
+ SMESH::PolySegment& segOut = theSegments[ i ];
+ SMESH_MeshAlgos::PolySegment& segIn = segments[ i ];
+ segOut.vector.PS.x = segIn.myVector.X();
+ segOut.vector.PS.y = segIn.myVector.Y();
+ segOut.vector.PS.z = segIn.myVector.Z();
+ }
+ }
+ else
+ {
+ TPythonDump() << "_segments = []";
+ for ( CORBA::ULong i = 0; i < theSegments.length(); ++i )
+ {
+ SMESH::PolySegment& segIn = theSegments[ i ];
+ TPythonDump() << "_segments.append( SMESH.PolySegment( "
+ << segIn.node1ID1 << ", "
+ << segIn.node1ID2 << ", "
+ << segIn.node2ID1 << ", "
+ << segIn.node2ID2 << ", "
+ << "smeshBuilder.MakeDirStruct( "
+ << segIn.vector.PS.x << ", "
+ << segIn.vector.PS.y << ", "
+ << segIn.vector.PS.z << ")))";
+ }
+ TPythonDump() << this << ".MakePolyLine( _segments, '" << theGroupName << "')";
+ }
+ meshDS->Modified();
+ SMESH_CATCH( SMESH::throwCorbaException );
+ return;
+}
+
+//================================================================================
+/*!
+ * \brief Create a slot of given width around given 1D elements lying on a triangle mesh.
+ * The slot is constructed by cutting faces by cylindrical surfaces made
+ * around each segment. Segments are expected to be created by MakePolyLine().
+ * \return Edges located at the slot boundary
+ */
+//================================================================================
+
+SMESH::ListOfEdges* SMESH_MeshEditor_i::MakeSlot(SMESH::SMESH_GroupBase_ptr theSegments,
+ CORBA::Double theWidth)
+{
+ if ( CORBA::is_nil( theSegments ) ||
+ theSegments->GetType() != SMESH::EDGE )
+ THROW_SALOME_CORBA_EXCEPTION("No segments given", SALOME::BAD_PARAM );
+ if ( myMesh->NbFaces() == 0 )
+ THROW_SALOME_CORBA_EXCEPTION("No faces in the mesh", SALOME::BAD_PARAM );
+
+ SMESH::ListOfEdges_var resultEdges = new SMESH::ListOfEdges;
+
+ SMESH_TRY;
+ initData(/*deleteSearchers=*/false);
+
+ SMESHDS_Mesh* meshDS = getMeshDS();
+
+ // get standalone face groups to be updated
+ std::vector< SMDS_MeshGroup* > faceGroups;
+ const std::set<SMESHDS_GroupBase*>& allGroups = meshDS->GetGroups();
+ std::set<SMESHDS_GroupBase*>::const_iterator grIt = allGroups.begin();
+ for ( ; grIt != allGroups.end(); ++grIt )
+ if ( const SMESHDS_Group* gr = dynamic_cast< const SMESHDS_Group* >( *grIt ))
+ if ( gr->GetType() == SMDSAbs_Face )
+ faceGroups.push_back( & const_cast< SMESHDS_Group* >( gr )->SMDSGroup() );
+
+ std::vector< SMESH_MeshAlgos::Edge > edges =
+ SMESH_MeshAlgos::MakeSlot( SMESH_Mesh_i::GetElements( theSegments, SMESH::EDGE ),
+ theWidth, meshDS, faceGroups );
+
+ resultEdges->length( edges.size() );
+ for ( size_t i = 0; i < edges.size(); ++i )
+ {
+ resultEdges[ i ].node1 = edges[i]._node1->GetID();
+ resultEdges[ i ].node2 = edges[i]._node2->GetID();
+ resultEdges[ i ].medium = edges[i]._medium ? edges[i]._medium->GetID() : 0;
+ }
+
+ meshDS->Modified();
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ TSearchersDeleter::Delete(); // face searcher becomes invalid as some faces were removed
+
+ return resultEdges._retn();
+}