1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 // File : SMESH_MeshEditor_i.cxx
25 // Author : Nicolas REJNERI
32 #include "SMESH_MeshEditor_i.hxx"
34 #include "SMDS_Mesh0DElement.hxx"
35 #include "SMDS_LinearEdge.hxx"
36 #include "SMDS_MeshFace.hxx"
37 #include "SMDS_MeshVolume.hxx"
38 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
39 #include "SMESH_subMeshEventListener.hxx"
40 #include "SMESH_Gen_i.hxx"
41 #include "SMESH_Filter_i.hxx"
42 #include "SMESH_subMesh_i.hxx"
43 #include "SMESH_Group_i.hxx"
44 #include "SMESH_PythonDump.hxx"
45 #include "SMESH_ControlsDef.hxx"
47 #include "utilities.h"
48 #include "Utils_ExceptHandlers.hxx"
49 #include "Utils_CorbaException.hxx"
51 #include <BRepAdaptor_Surface.hxx>
52 #include <BRep_Tool.hxx>
53 #include <TopExp_Explorer.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Face.hxx>
61 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
65 #include <Standard_Failure.hxx>
68 #include <Standard_ErrorHandler.hxx>
74 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
77 using SMESH::TPythonDump;
81 //=============================================================================
83 * \brief Mesh to apply modifications for preview purposes
85 //=============================================================================
87 struct TPreviewMesh: public SMESH_Mesh
89 SMDSAbs_ElementType myPreviewType; // type to show
91 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
92 _isShapeToMesh = (_id =_studyId =_idDoc = 0);
93 _myMeshDS = new SMESHDS_Mesh( _id, true );
94 myPreviewType = previewElements;
97 virtual ~TPreviewMesh() { delete _myMeshDS; }
98 //!< Copy a set of elements
99 void Copy(const TIDSortedElemSet & theElements,
100 TIDSortedElemSet& theCopyElements,
101 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
102 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
104 // loop on theIDsOfElements
105 TIDSortedElemSet::const_iterator eIt = theElements.begin();
106 for ( ; eIt != theElements.end(); ++eIt )
108 const SMDS_MeshElement* anElem = *eIt;
109 if ( !anElem ) continue;
110 SMDSAbs_ElementType type = anElem->GetType();
111 if ( type == theAvoidType ||
112 ( theSelectType != SMDSAbs_All && type != theSelectType ))
115 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
116 theCopyElements.insert( theCopyElements.end(), anElemCopy );
120 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
122 // copy element nodes
123 int anElemNbNodes = anElem->NbNodes();
124 vector< int > anElemNodesID( anElemNbNodes ) ;
125 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
126 for ( int i = 0; itElemNodes->more(); i++)
128 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
130 anElemNodesID[i] = anElemNode->GetID();
133 // creates a corresponding element on copied nodes
134 SMDS_MeshElement* anElemCopy = 0;
135 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
137 const SMDS_VtkVolume* ph =
138 dynamic_cast<const SMDS_VtkVolume*> (anElem);
140 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
141 (anElemNodesID, ph->GetQuantities(),anElem->GetID());
144 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
151 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
153 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
154 anElemNode->GetID());
156 };// struct TPreviewMesh
158 static SMESH_NodeSearcher * theNodeSearcher = 0;
159 static SMESH_ElementSearcher * theElementSearcher = 0;
161 //=============================================================================
163 * \brief Deleter of theNodeSearcher at any compute event occured
165 //=============================================================================
167 struct TSearchersDeleter : public SMESH_subMeshEventListener
171 TSearchersDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
173 //!< Delete theNodeSearcher
176 if ( theNodeSearcher ) delete theNodeSearcher; theNodeSearcher = 0;
177 if ( theElementSearcher ) delete theElementSearcher; theElementSearcher = 0;
179 typedef map < int, SMESH_subMesh * > TDependsOnMap;
180 //!< The meshod called by submesh: do my main job
181 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
182 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
184 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
186 Unset( sm->GetFather() );
189 //!< set self on all submeshes and delete theNodeSearcher if other mesh is set
190 void Set(SMESH_Mesh* mesh)
192 if ( myMesh != mesh )
199 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
200 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
201 TDependsOnMap::const_iterator sm;
202 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
203 sm->second->SetEventListener( this, 0, sm->second );
207 //!< delete self from all submeshes
208 void Unset(SMESH_Mesh* mesh)
210 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
211 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
212 TDependsOnMap::const_iterator sm;
213 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
214 sm->second->DeleteEventListener( this );
219 } theSearchersDeleter;
221 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
223 TCollection_AsciiString typeStr;
224 switch ( theMirrorType ) {
225 case SMESH::SMESH_MeshEditor::POINT:
226 typeStr = "SMESH.SMESH_MeshEditor.POINT";
228 case SMESH::SMESH_MeshEditor::AXIS:
229 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
232 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
236 //================================================================================
238 * \brief function for conversion long_array to TIDSortedElemSet
239 * \param IDs - array of IDs
240 * \param aMesh - mesh
241 * \param aMap - collection to fill
242 * \param aType - element type
244 //================================================================================
246 void arrayToSet(const SMESH::long_array & IDs,
247 const SMESHDS_Mesh* aMesh,
248 TIDSortedElemSet& aMap,
249 const SMDSAbs_ElementType aType = SMDSAbs_All )
251 for (int i=0; i<IDs.length(); i++) {
252 CORBA::Long ind = IDs[i];
253 const SMDS_MeshElement * elem =
254 (aType == SMDSAbs_Node ? aMesh->FindNode(ind) : aMesh->FindElement(ind));
255 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
259 //================================================================================
261 * \brief Retrieve elements of given type from SMESH_IDSource
263 //================================================================================
265 bool idSourceToSet(SMESH::SMESH_IDSource_ptr theIDSource,
266 const SMESHDS_Mesh* theMeshDS,
267 TIDSortedElemSet& theElemSet,
268 const SMDSAbs_ElementType theType,
269 const bool emptyIfIsMesh=false)
272 if ( CORBA::is_nil( theIDSource ) )
274 if ( emptyIfIsMesh && SMESH::DownCast<SMESH_Mesh_i*>( theIDSource ))
277 SMESH::long_array_var anIDs = theIDSource->GetIDs();
278 if ( anIDs->length() == 0 )
280 SMESH::array_of_ElementType_var types = theIDSource->GetTypes();
281 if ( types->length() == 1 && types[0] == SMESH::NODE ) // group of nodes
283 if ( theType == SMDSAbs_All || theType == SMDSAbs_Node )
284 arrayToSet( anIDs, theMeshDS, theElemSet, SMDSAbs_Node );
290 arrayToSet( anIDs, theMeshDS, theElemSet, theType);
294 //================================================================================
296 * \brief Retrieve nodes from SMESH_IDSource
298 //================================================================================
300 void idSourceToNodeSet(SMESH::SMESH_IDSource_ptr theObject,
301 const SMESHDS_Mesh* theMeshDS,
302 TIDSortedNodeSet& theNodeSet)
305 if ( CORBA::is_nil( theObject ) )
307 SMESH::array_of_ElementType_var types = theObject->GetTypes();
308 SMESH::long_array_var aElementsId = theObject->GetIDs();
309 if ( types->length() == 1 && types[0] == SMESH::NODE)
311 for(int i = 0; i < aElementsId->length(); i++)
312 if ( const SMDS_MeshNode * n = theMeshDS->FindNode( aElementsId[i] ))
313 theNodeSet.insert( theNodeSet.end(), n);
316 for(int i = 0; i < aElementsId->length(); i++)
317 if( const SMDS_MeshElement * elem = theMeshDS->FindElement( aElementsId[i] ))
318 theNodeSet.insert( elem->begin_nodes(), elem->end_nodes());
323 //=============================================================================
327 //=============================================================================
329 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
332 myMesh = & theMesh->GetImpl();
333 myPreviewMode = isPreview;
336 //================================================================================
340 //================================================================================
342 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
346 //================================================================================
348 * \brief Clear members
350 //================================================================================
352 void SMESH_MeshEditor_i::initData(bool deleteSearchers)
354 if ( myPreviewMode ) {
355 myPreviewData = new SMESH::MeshPreviewStruct();
358 myLastCreatedElems = new SMESH::long_array();
359 myLastCreatedNodes = new SMESH::long_array();
360 if ( deleteSearchers )
361 TSearchersDeleter::Delete();
365 //=======================================================================
366 //function : MakeIDSource
367 //purpose : Wrap a sequence of ids in a SMESH_IDSource
368 //=======================================================================
370 struct _IDSource : public POA_SMESH::SMESH_IDSource
372 SMESH::long_array _ids;
373 SMESH::ElementType _type;
374 SMESH::SMESH_Mesh_ptr _mesh;
375 SMESH::long_array* GetIDs() { return new SMESH::long_array( _ids ); }
376 SMESH::long_array* GetMeshInfo() { return 0; }
377 SMESH::SMESH_Mesh_ptr GetMesh() { return SMESH::SMESH_Mesh::_duplicate( _mesh ); }
378 SMESH::array_of_ElementType* GetTypes()
380 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
383 return types._retn();
387 SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_array& ids,
388 SMESH::ElementType type)
390 _IDSource* anIDSource = new _IDSource;
391 anIDSource->_ids = ids;
392 anIDSource->_type = type;
393 anIDSource->_mesh = myMesh_i->_this();
394 SMESH::SMESH_IDSource_var anIDSourceVar = anIDSource->_this();
396 return anIDSourceVar._retn();
399 //=============================================================================
403 //=============================================================================
406 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
410 ::SMESH_MeshEditor anEditor( myMesh );
413 for (int i = 0; i < IDsOfElements.length(); i++)
414 IdList.push_back( IDsOfElements[i] );
416 // Update Python script
417 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
420 bool ret = anEditor.Remove( IdList, false );
421 myMesh->GetMeshDS()->Modified();
422 if ( IDsOfElements.length() )
423 myMesh->SetIsModified( true ); // issue 0020693
427 //=============================================================================
431 //=============================================================================
433 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
437 ::SMESH_MeshEditor anEditor( myMesh );
439 for (int i = 0; i < IDsOfNodes.length(); i++)
440 IdList.push_back( IDsOfNodes[i] );
442 // Update Python script
443 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
445 bool ret = anEditor.Remove( IdList, true );
446 myMesh->GetMeshDS()->Modified();
447 if ( IDsOfNodes.length() )
448 myMesh->SetIsModified( true ); // issue 0020693
452 //=============================================================================
456 //=============================================================================
458 CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes()
462 ::SMESH_MeshEditor anEditor( myMesh );
464 // Update Python script
465 TPythonDump() << "nbRemoved = " << this << ".RemoveOrphanNodes()";
467 // Create filter to find all orphan nodes
468 SMESH::Controls::Filter::TIdSequence seq;
469 SMESH::Controls::PredicatePtr predicate( new SMESH::Controls::FreeNodes() );
470 SMESH::Controls::Filter::GetElementsId( GetMeshDS(), predicate, seq );
472 // remove orphan nodes (if there are any)
474 for ( int i = 0; i < seq.size(); i++ )
475 IdList.push_back( seq[i] );
478 myMesh->SetIsModified( true );
480 return anEditor.Remove( IdList, true );
483 //=============================================================================
487 //=============================================================================
489 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
490 CORBA::Double y, CORBA::Double z)
494 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
496 // Update Python script
497 TPythonDump() << "nodeID = " << this << ".AddNode( "
498 << x << ", " << y << ", " << z << " )";
500 myMesh->GetMeshDS()->Modified();
501 myMesh->SetIsModified( true ); // issue 0020693
505 //=============================================================================
509 //=============================================================================
510 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
514 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
515 SMDS_MeshElement* elem = GetMeshDS()->Add0DElement(aNode);
517 // Update Python script
518 TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
520 myMesh->GetMeshDS()->Modified();
521 myMesh->SetIsModified( true ); // issue 0020693
524 return elem->GetID();
529 //=============================================================================
533 //=============================================================================
535 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
539 int NbNodes = IDsOfNodes.length();
540 SMDS_MeshElement* elem = 0;
543 CORBA::Long index1 = IDsOfNodes[0];
544 CORBA::Long index2 = IDsOfNodes[1];
545 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
547 // Update Python script
548 TPythonDump() << "edge = " << this << ".AddEdge([ "
549 << index1 << ", " << index2 <<" ])";
552 CORBA::Long n1 = IDsOfNodes[0];
553 CORBA::Long n2 = IDsOfNodes[1];
554 CORBA::Long n12 = IDsOfNodes[2];
555 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
556 GetMeshDS()->FindNode(n2),
557 GetMeshDS()->FindNode(n12));
558 // Update Python script
559 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
560 <<n1<<", "<<n2<<", "<<n12<<" ])";
563 myMesh->GetMeshDS()->Modified();
565 return myMesh->SetIsModified( true ), elem->GetID();
570 //=============================================================================
574 //=============================================================================
576 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
580 int NbNodes = IDsOfNodes.length();
586 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
587 for (int i = 0; i < NbNodes; i++)
588 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
590 SMDS_MeshElement* elem = 0;
592 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
594 else if (NbNodes == 4) {
595 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
597 else if (NbNodes == 6) {
598 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
601 else if (NbNodes == 8) {
602 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
603 nodes[4], nodes[5], nodes[6], nodes[7]);
605 else if (NbNodes > 2) {
606 elem = GetMeshDS()->AddPolygonalFace(nodes);
609 // Update Python script
610 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
612 myMesh->GetMeshDS()->Modified();
614 return myMesh->SetIsModified( true ), elem->GetID();
619 //=============================================================================
623 //=============================================================================
624 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsOfNodes)
628 int NbNodes = IDsOfNodes.length();
629 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
630 for (int i = 0; i < NbNodes; i++)
631 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
633 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
635 // Update Python script
636 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
638 myMesh->GetMeshDS()->Modified();
639 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
642 //=============================================================================
646 //=============================================================================
648 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
652 int NbNodes = IDsOfNodes.length();
653 vector< const SMDS_MeshNode*> n(NbNodes);
654 for(int i=0;i<NbNodes;i++)
655 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
657 SMDS_MeshElement* elem = 0;
660 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
661 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
662 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
663 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
664 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
665 n[6],n[7],n[8],n[9]);
667 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
668 n[7],n[8],n[9],n[10],n[11],n[12]);
670 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
671 n[9],n[10],n[11],n[12],n[13],n[14]);
673 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
674 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
675 n[15],n[16],n[17],n[18],n[19]);
679 // Update Python script
680 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
682 myMesh->GetMeshDS()->Modified();
684 return myMesh->SetIsModified( true ), elem->GetID();
689 //=============================================================================
691 * AddPolyhedralVolume
693 //=============================================================================
694 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume (const SMESH::long_array & IDsOfNodes,
695 const SMESH::long_array & Quantities)
699 int NbNodes = IDsOfNodes.length();
700 std::vector<const SMDS_MeshNode*> n (NbNodes);
701 for (int i = 0; i < NbNodes; i++)
703 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDsOfNodes[i]);
704 if (!aNode) return 0;
708 int NbFaces = Quantities.length();
709 std::vector<int> q (NbFaces);
710 for (int j = 0; j < NbFaces; j++)
711 q[j] = Quantities[j];
713 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
715 // Update Python script
716 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
717 << IDsOfNodes << ", " << Quantities << " )";
718 myMesh->GetMeshDS()->Modified();
720 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
723 //=============================================================================
725 * AddPolyhedralVolumeByFaces
727 //=============================================================================
728 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_array & IdsOfFaces)
732 int NbFaces = IdsOfFaces.length();
733 std::vector<const SMDS_MeshNode*> poly_nodes;
734 std::vector<int> quantities (NbFaces);
736 for (int i = 0; i < NbFaces; i++) {
737 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
738 quantities[i] = aFace->NbNodes();
740 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
742 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
746 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
748 // Update Python script
749 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
750 << IdsOfFaces << " )";
751 myMesh->GetMeshDS()->Modified();
753 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
756 //=============================================================================
758 * \brief Bind a node to a vertex
759 * \param NodeID - node ID
760 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
761 * \retval boolean - false if NodeID or VertexID is invalid
763 //=============================================================================
765 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
766 throw (SALOME::SALOME_Exception)
768 Unexpect aCatch(SALOME_SalomeException);
770 SMESHDS_Mesh * mesh = GetMeshDS();
771 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
773 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
775 if ( mesh->MaxShapeIndex() < VertexID )
776 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
778 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
779 if ( shape.ShapeType() != TopAbs_VERTEX )
780 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
782 mesh->SetNodeOnVertex( node, VertexID );
784 myMesh->SetIsModified( true );
787 //=============================================================================
789 * \brief Store node position on an edge
790 * \param NodeID - node ID
791 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
792 * \param paramOnEdge - parameter on edge where the node is located
793 * \retval boolean - false if any parameter is invalid
795 //=============================================================================
797 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
798 CORBA::Double paramOnEdge)
799 throw (SALOME::SALOME_Exception)
801 Unexpect aCatch(SALOME_SalomeException);
803 SMESHDS_Mesh * mesh = GetMeshDS();
804 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
806 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
808 if ( mesh->MaxShapeIndex() < EdgeID )
809 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
811 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
812 if ( shape.ShapeType() != TopAbs_EDGE )
813 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
816 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
817 if ( paramOnEdge < f || paramOnEdge > l )
818 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
820 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
822 myMesh->SetIsModified( true );
825 //=============================================================================
827 * \brief Store node position on a face
828 * \param NodeID - node ID
829 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
830 * \param u - U parameter on face where the node is located
831 * \param v - V parameter on face where the node is located
832 * \retval boolean - false if any parameter is invalid
834 //=============================================================================
836 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
837 CORBA::Double u, CORBA::Double v)
838 throw (SALOME::SALOME_Exception)
840 Unexpect aCatch(SALOME_SalomeException);
842 SMESHDS_Mesh * mesh = GetMeshDS();
843 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
845 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
847 if ( mesh->MaxShapeIndex() < FaceID )
848 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
850 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
851 if ( shape.ShapeType() != TopAbs_FACE )
852 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
854 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
855 bool isOut = ( u < surf.FirstUParameter() ||
856 u > surf.LastUParameter() ||
857 v < surf.FirstVParameter() ||
858 v > surf.LastVParameter() );
862 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
863 << " u( " << surf.FirstUParameter()
864 << "," << surf.LastUParameter()
865 << ") v( " << surf.FirstVParameter()
866 << "," << surf.LastVParameter() << ")" );
868 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
871 mesh->SetNodeOnFace( node, FaceID, u, v );
872 myMesh->SetIsModified( true );
875 //=============================================================================
877 * \brief Bind a node to a solid
878 * \param NodeID - node ID
879 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
880 * \retval boolean - false if NodeID or SolidID is invalid
882 //=============================================================================
884 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
885 throw (SALOME::SALOME_Exception)
887 Unexpect aCatch(SALOME_SalomeException);
889 SMESHDS_Mesh * mesh = GetMeshDS();
890 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
892 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
894 if ( mesh->MaxShapeIndex() < SolidID )
895 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
897 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
898 if ( shape.ShapeType() != TopAbs_SOLID &&
899 shape.ShapeType() != TopAbs_SHELL)
900 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
902 mesh->SetNodeInVolume( node, SolidID );
904 // myMesh->SetIsModified( true ); - SetNodeInVolume() can't prevent re-compute, I believe
907 //=============================================================================
909 * \brief Bind an element to a shape
910 * \param ElementID - element ID
911 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
912 * \retval boolean - false if ElementID or ShapeID is invalid
914 //=============================================================================
916 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
918 throw (SALOME::SALOME_Exception)
920 Unexpect aCatch(SALOME_SalomeException);
922 SMESHDS_Mesh * mesh = GetMeshDS();
923 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
925 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
927 if ( mesh->MaxShapeIndex() < ShapeID )
928 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
930 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
931 if ( shape.ShapeType() != TopAbs_EDGE &&
932 shape.ShapeType() != TopAbs_FACE &&
933 shape.ShapeType() != TopAbs_SOLID &&
934 shape.ShapeType() != TopAbs_SHELL )
935 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
937 mesh->SetMeshElementOnShape( elem, ShapeID );
939 myMesh->SetIsModified( true );
942 //=============================================================================
946 //=============================================================================
948 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
953 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
954 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
958 // Update Python script
959 TPythonDump() << "isDone = " << this << ".InverseDiag( "
960 << NodeID1 << ", " << NodeID2 << " )";
963 ::SMESH_MeshEditor aMeshEditor( myMesh );
964 int ret = aMeshEditor.InverseDiag ( n1, n2 );
965 myMesh->GetMeshDS()->Modified();
966 myMesh->SetIsModified( true );
970 //=============================================================================
974 //=============================================================================
976 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
981 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
982 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
986 // Update Python script
987 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
988 << NodeID1 << ", " << NodeID2 << " )";
990 ::SMESH_MeshEditor aMeshEditor( myMesh );
992 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
994 myMesh->GetMeshDS()->Modified();
996 myMesh->SetIsModified( true ); // issue 0020693
998 storeResult(aMeshEditor);
1003 //=============================================================================
1007 //=============================================================================
1009 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
1013 ::SMESH_MeshEditor anEditor( myMesh );
1014 for (int i = 0; i < IDsOfElements.length(); i++)
1016 CORBA::Long index = IDsOfElements[i];
1017 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
1019 anEditor.Reorient( elem );
1021 // Update Python script
1022 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
1024 myMesh->GetMeshDS()->Modified();
1025 if ( IDsOfElements.length() )
1026 myMesh->SetIsModified( true ); // issue 0020693
1032 //=============================================================================
1036 //=============================================================================
1038 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
1042 TPythonDump aTPythonDump; // suppress dump in Reorient()
1044 SMESH::long_array_var anElementsId = theObject->GetIDs();
1045 CORBA::Boolean isDone = Reorient(anElementsId);
1047 // Update Python script
1048 aTPythonDump << "isDone = " << this << ".ReorientObject( " << theObject << " )";
1053 //=============================================================================
1057 //=============================================================================
1058 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
1059 SMESH::NumericalFunctor_ptr Criterion,
1060 CORBA::Double MaxAngle)
1064 SMESHDS_Mesh* aMesh = GetMeshDS();
1065 TIDSortedElemSet faces;
1066 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1068 SMESH::NumericalFunctor_i* aNumericalFunctor =
1069 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1070 SMESH::Controls::NumericalFunctorPtr aCrit;
1071 if ( !aNumericalFunctor )
1072 aCrit.reset( new SMESH::Controls::AspectRatio() );
1074 aCrit = aNumericalFunctor->GetNumericalFunctor();
1076 // Update Python script
1077 TPythonDump() << "isDone = " << this << ".TriToQuad( "
1078 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1080 ::SMESH_MeshEditor anEditor( myMesh );
1082 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
1083 myMesh->GetMeshDS()->Modified();
1085 myMesh->SetIsModified( true ); // issue 0020693
1087 storeResult(anEditor);
1093 //=============================================================================
1097 //=============================================================================
1098 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1099 SMESH::NumericalFunctor_ptr Criterion,
1100 CORBA::Double MaxAngle)
1104 TPythonDump aTPythonDump; // suppress dump in TriToQuad()
1105 SMESH::long_array_var anElementsId = theObject->GetIDs();
1106 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
1108 SMESH::NumericalFunctor_i* aNumericalFunctor =
1109 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1111 // Update Python script
1112 aTPythonDump << "isDone = " << this << ".TriToQuadObject("
1113 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1119 //=============================================================================
1123 //=============================================================================
1124 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
1125 SMESH::NumericalFunctor_ptr Criterion)
1129 SMESHDS_Mesh* aMesh = GetMeshDS();
1130 TIDSortedElemSet faces;
1131 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1133 SMESH::NumericalFunctor_i* aNumericalFunctor =
1134 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1135 SMESH::Controls::NumericalFunctorPtr aCrit;
1136 if ( !aNumericalFunctor )
1137 aCrit.reset( new SMESH::Controls::AspectRatio() );
1139 aCrit = aNumericalFunctor->GetNumericalFunctor();
1142 // Update Python script
1143 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1145 ::SMESH_MeshEditor anEditor( myMesh );
1146 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1147 myMesh->GetMeshDS()->Modified();
1149 myMesh->SetIsModified( true ); // issue 0020693
1151 storeResult(anEditor);
1157 //=============================================================================
1161 //=============================================================================
1162 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1163 SMESH::NumericalFunctor_ptr Criterion)
1167 TPythonDump aTPythonDump; // suppress dump in QuadToTri()
1169 SMESH::long_array_var anElementsId = theObject->GetIDs();
1170 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1172 SMESH::NumericalFunctor_i* aNumericalFunctor =
1173 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1175 // Update Python script
1176 aTPythonDump << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1182 //=============================================================================
1186 //=============================================================================
1187 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1188 CORBA::Boolean Diag13)
1192 SMESHDS_Mesh* aMesh = GetMeshDS();
1193 TIDSortedElemSet faces;
1194 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1196 // Update Python script
1197 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1198 << IDsOfElements << ", " << Diag13 << " )";
1200 ::SMESH_MeshEditor anEditor( myMesh );
1201 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1202 myMesh->GetMeshDS()->Modified();
1204 myMesh->SetIsModified( true ); // issue 0020693
1207 storeResult(anEditor);
1213 //=============================================================================
1217 //=============================================================================
1218 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1219 CORBA::Boolean Diag13)
1223 TPythonDump aTPythonDump; // suppress dump in SplitQuad()
1225 SMESH::long_array_var anElementsId = theObject->GetIDs();
1226 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1228 // Update Python script
1229 aTPythonDump << "isDone = " << this << ".SplitQuadObject( "
1230 << theObject << ", " << Diag13 << " )";
1236 //=============================================================================
1240 //=============================================================================
1241 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1242 SMESH::NumericalFunctor_ptr Criterion)
1246 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1247 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1249 SMESH::NumericalFunctor_i* aNumericalFunctor =
1250 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1251 SMESH::Controls::NumericalFunctorPtr aCrit;
1252 if (aNumericalFunctor)
1253 aCrit = aNumericalFunctor->GetNumericalFunctor();
1255 aCrit.reset(new SMESH::Controls::AspectRatio());
1257 ::SMESH_MeshEditor anEditor (myMesh);
1258 return anEditor.BestSplit(quad, aCrit);
1263 //================================================================================
1265 * \brief Split volumic elements into tetrahedrons
1267 //================================================================================
1269 void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems,
1270 CORBA::Short methodFlags)
1271 throw (SALOME::SALOME_Exception)
1273 Unexpect aCatch(SALOME_SalomeException);
1277 SMESH::long_array_var anElementsId = elems->GetIDs();
1278 TIDSortedElemSet elemSet;
1279 arrayToSet( anElementsId, GetMeshDS(), elemSet, SMDSAbs_Volume );
1281 ::SMESH_MeshEditor anEditor (myMesh);
1282 anEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags ));
1283 myMesh->GetMeshDS()->Modified();
1285 storeResult(anEditor);
1287 // if ( myLastCreatedElems.length() ) - it does not influence Compute()
1288 // myMesh->SetIsModified( true ); // issue 0020693
1290 TPythonDump() << this << ".SplitVolumesIntoTetra( "
1291 << elems << ", " << methodFlags << " )";
1294 //=======================================================================
1297 //=======================================================================
1300 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1301 const SMESH::long_array & IDsOfFixedNodes,
1302 CORBA::Long MaxNbOfIterations,
1303 CORBA::Double MaxAspectRatio,
1304 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1306 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1307 MaxAspectRatio, Method, false );
1311 //=======================================================================
1312 //function : SmoothParametric
1314 //=======================================================================
1317 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1318 const SMESH::long_array & IDsOfFixedNodes,
1319 CORBA::Long MaxNbOfIterations,
1320 CORBA::Double MaxAspectRatio,
1321 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1323 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1324 MaxAspectRatio, Method, true );
1328 //=======================================================================
1329 //function : SmoothObject
1331 //=======================================================================
1334 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1335 const SMESH::long_array & IDsOfFixedNodes,
1336 CORBA::Long MaxNbOfIterations,
1337 CORBA::Double MaxAspectRatio,
1338 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1340 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1341 MaxAspectRatio, Method, false);
1345 //=======================================================================
1346 //function : SmoothParametricObject
1348 //=======================================================================
1351 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1352 const SMESH::long_array & IDsOfFixedNodes,
1353 CORBA::Long MaxNbOfIterations,
1354 CORBA::Double MaxAspectRatio,
1355 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1357 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1358 MaxAspectRatio, Method, true);
1362 //=============================================================================
1366 //=============================================================================
1369 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1370 const SMESH::long_array & IDsOfFixedNodes,
1371 CORBA::Long MaxNbOfIterations,
1372 CORBA::Double MaxAspectRatio,
1373 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1378 SMESHDS_Mesh* aMesh = GetMeshDS();
1380 TIDSortedElemSet elements;
1381 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1383 set<const SMDS_MeshNode*> fixedNodes;
1384 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1385 CORBA::Long index = IDsOfFixedNodes[i];
1386 const SMDS_MeshNode * node = aMesh->FindNode(index);
1388 fixedNodes.insert( node );
1390 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1391 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1392 method = ::SMESH_MeshEditor::CENTROIDAL;
1394 ::SMESH_MeshEditor anEditor( myMesh );
1395 anEditor.Smooth(elements, fixedNodes, method,
1396 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1398 myMesh->GetMeshDS()->Modified();
1399 myMesh->SetIsModified( true ); // issue 0020693
1401 storeResult(anEditor);
1403 // Update Python script
1404 TPythonDump() << "isDone = " << this << "."
1405 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1406 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1407 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1408 << "SMESH.SMESH_MeshEditor."
1409 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1410 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1416 //=============================================================================
1420 //=============================================================================
1423 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1424 const SMESH::long_array & IDsOfFixedNodes,
1425 CORBA::Long MaxNbOfIterations,
1426 CORBA::Double MaxAspectRatio,
1427 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1432 TPythonDump aTPythonDump; // suppress dump in smooth()
1434 SMESH::long_array_var anElementsId = theObject->GetIDs();
1435 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1436 MaxAspectRatio, Method, IsParametric);
1438 // Update Python script
1439 aTPythonDump << "isDone = " << this << "."
1440 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1441 << theObject << ", " << IDsOfFixedNodes << ", "
1442 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1443 << "SMESH.SMESH_MeshEditor."
1444 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1445 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1451 //=============================================================================
1455 //=============================================================================
1457 void SMESH_MeshEditor_i::RenumberNodes()
1459 // Update Python script
1460 TPythonDump() << this << ".RenumberNodes()";
1462 GetMeshDS()->Renumber( true );
1466 //=============================================================================
1470 //=============================================================================
1472 void SMESH_MeshEditor_i::RenumberElements()
1474 // Update Python script
1475 TPythonDump() << this << ".RenumberElements()";
1477 GetMeshDS()->Renumber( false );
1480 //=======================================================================
1482 * \brief Return groups by their IDs
1484 //=======================================================================
1486 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1490 myMesh_i->CreateGroupServants();
1491 return myMesh_i->GetGroups( *groupIDs );
1494 //=======================================================================
1495 //function : rotationSweep
1497 //=======================================================================
1499 SMESH::ListOfGroups*
1500 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1501 const SMESH::AxisStruct & theAxis,
1502 CORBA::Double theAngleInRadians,
1503 CORBA::Long theNbOfSteps,
1504 CORBA::Double theTolerance,
1505 const bool theMakeGroups,
1506 const SMDSAbs_ElementType theElementType)
1510 TIDSortedElemSet inElements, copyElements;
1511 arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType);
1513 TIDSortedElemSet* workElements = & inElements;
1514 TPreviewMesh tmpMesh( SMDSAbs_Face );
1515 SMESH_Mesh* mesh = 0;
1516 bool makeWalls=true;
1517 if ( myPreviewMode )
1519 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1520 tmpMesh.Copy( inElements, copyElements, select, avoid );
1522 workElements = & copyElements;
1523 //makeWalls = false;
1530 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1531 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1533 ::SMESH_MeshEditor anEditor( mesh );
1534 ::SMESH_MeshEditor::PGroupIDs groupIds =
1535 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1536 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1537 storeResult(anEditor);
1538 myMesh->GetMeshDS()->Modified();
1540 // myMesh->SetIsModified( true ); -- it does not influence Compute()
1542 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1545 //=======================================================================
1546 //function : RotationSweep
1548 //=======================================================================
1550 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1551 const SMESH::AxisStruct & theAxis,
1552 CORBA::Double theAngleInRadians,
1553 CORBA::Long theNbOfSteps,
1554 CORBA::Double theTolerance)
1556 if ( !myPreviewMode ) {
1557 TPythonDump() << this << ".RotationSweep( "
1558 << theIDsOfElements << ", "
1560 << theAngleInRadians << ", "
1561 << theNbOfSteps << ", "
1562 << theTolerance << " )";
1564 rotationSweep(theIDsOfElements,
1572 //=======================================================================
1573 //function : RotationSweepMakeGroups
1575 //=======================================================================
1577 SMESH::ListOfGroups*
1578 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1579 const SMESH::AxisStruct& theAxis,
1580 CORBA::Double theAngleInRadians,
1581 CORBA::Long theNbOfSteps,
1582 CORBA::Double theTolerance)
1584 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1590 if ( !myPreviewMode ) {
1591 TPythonDump aPythonDump;
1592 DumpGroupsList(aPythonDump,aGroups);
1593 aPythonDump<< this << ".RotationSweepMakeGroups( "
1594 << theIDsOfElements << ", "
1596 << theAngleInRadians << ", "
1597 << theNbOfSteps << ", "
1598 << theTolerance << " )";
1603 //=======================================================================
1604 //function : RotationSweepObject
1606 //=======================================================================
1608 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1609 const SMESH::AxisStruct & theAxis,
1610 CORBA::Double theAngleInRadians,
1611 CORBA::Long theNbOfSteps,
1612 CORBA::Double theTolerance)
1614 if ( !myPreviewMode ) {
1615 TPythonDump() << this << ".RotationSweepObject( "
1616 << theObject << ", "
1618 << theAngleInRadians << ", "
1619 << theNbOfSteps << ", "
1620 << theTolerance << " )";
1622 SMESH::long_array_var anElementsId = theObject->GetIDs();
1623 rotationSweep(anElementsId,
1631 //=======================================================================
1632 //function : RotationSweepObject1D
1634 //=======================================================================
1636 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1637 const SMESH::AxisStruct & theAxis,
1638 CORBA::Double theAngleInRadians,
1639 CORBA::Long theNbOfSteps,
1640 CORBA::Double theTolerance)
1642 if ( !myPreviewMode ) {
1643 TPythonDump() << this << ".RotationSweepObject1D( "
1644 << theObject << ", "
1646 << theAngleInRadians << ", "
1647 << theNbOfSteps << ", "
1648 << theTolerance << " )";
1650 SMESH::long_array_var anElementsId = theObject->GetIDs();
1651 rotationSweep(anElementsId,
1660 //=======================================================================
1661 //function : RotationSweepObject2D
1663 //=======================================================================
1665 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1666 const SMESH::AxisStruct & theAxis,
1667 CORBA::Double theAngleInRadians,
1668 CORBA::Long theNbOfSteps,
1669 CORBA::Double theTolerance)
1671 if ( !myPreviewMode ) {
1672 TPythonDump() << this << ".RotationSweepObject2D( "
1673 << theObject << ", "
1675 << theAngleInRadians << ", "
1676 << theNbOfSteps << ", "
1677 << theTolerance << " )";
1679 SMESH::long_array_var anElementsId = theObject->GetIDs();
1680 rotationSweep(anElementsId,
1689 //=======================================================================
1690 //function : RotationSweepObjectMakeGroups
1692 //=======================================================================
1694 SMESH::ListOfGroups*
1695 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1696 const SMESH::AxisStruct& theAxis,
1697 CORBA::Double theAngleInRadians,
1698 CORBA::Long theNbOfSteps,
1699 CORBA::Double theTolerance)
1701 SMESH::long_array_var anElementsId = theObject->GetIDs();
1702 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1708 if ( !myPreviewMode ) {
1709 TPythonDump aPythonDump;
1710 DumpGroupsList(aPythonDump,aGroups);
1711 aPythonDump<< this << ".RotationSweepObjectMakeGroups( "
1712 << theObject << ", "
1714 << theAngleInRadians << ", "
1715 << theNbOfSteps << ", "
1716 << theTolerance << " )";
1721 //=======================================================================
1722 //function : RotationSweepObject1DMakeGroups
1724 //=======================================================================
1726 SMESH::ListOfGroups*
1727 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1728 const SMESH::AxisStruct& theAxis,
1729 CORBA::Double theAngleInRadians,
1730 CORBA::Long theNbOfSteps,
1731 CORBA::Double theTolerance)
1733 SMESH::long_array_var anElementsId = theObject->GetIDs();
1734 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1741 if ( !myPreviewMode ) {
1742 TPythonDump aPythonDump;
1743 DumpGroupsList(aPythonDump,aGroups);
1744 aPythonDump<< this << ".RotationSweepObject1DMakeGroups( "
1745 << theObject << ", "
1747 << theAngleInRadians << ", "
1748 << theNbOfSteps << ", "
1749 << theTolerance << " )";
1754 //=======================================================================
1755 //function : RotationSweepObject2DMakeGroups
1757 //=======================================================================
1759 SMESH::ListOfGroups*
1760 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1761 const SMESH::AxisStruct& theAxis,
1762 CORBA::Double theAngleInRadians,
1763 CORBA::Long theNbOfSteps,
1764 CORBA::Double theTolerance)
1766 SMESH::long_array_var anElementsId = theObject->GetIDs();
1767 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1774 if ( !myPreviewMode ) {
1775 TPythonDump aPythonDump;
1776 DumpGroupsList(aPythonDump,aGroups);
1777 aPythonDump<< this << ".RotationSweepObject2DMakeGroups( "
1778 << theObject << ", "
1780 << theAngleInRadians << ", "
1781 << theNbOfSteps << ", "
1782 << theTolerance << " )";
1788 //=======================================================================
1789 //function : extrusionSweep
1791 //=======================================================================
1793 SMESH::ListOfGroups*
1794 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1795 const SMESH::DirStruct & theStepVector,
1796 CORBA::Long theNbOfSteps,
1797 const bool theMakeGroups,
1798 const SMDSAbs_ElementType theElementType)
1806 TIDSortedElemSet elements;
1807 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1809 const SMESH::PointStruct * P = &theStepVector.PS;
1810 gp_Vec stepVec( P->x, P->y, P->z );
1812 TElemOfElemListMap aHystory;
1813 ::SMESH_MeshEditor anEditor( myMesh );
1814 ::SMESH_MeshEditor::PGroupIDs groupIds =
1815 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1817 myMesh->GetMeshDS()->Modified();
1818 storeResult(anEditor);
1820 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1822 } catch(Standard_Failure) {
1823 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1824 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1829 //=======================================================================
1830 //function : ExtrusionSweep
1832 //=======================================================================
1834 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1835 const SMESH::DirStruct & theStepVector,
1836 CORBA::Long theNbOfSteps)
1838 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1839 if ( !myPreviewMode ) {
1840 TPythonDump() << this << ".ExtrusionSweep( "
1841 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1846 //=======================================================================
1847 //function : ExtrusionSweepObject
1849 //=======================================================================
1851 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1852 const SMESH::DirStruct & theStepVector,
1853 CORBA::Long theNbOfSteps)
1855 SMESH::long_array_var anElementsId = theObject->GetIDs();
1856 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1857 if ( !myPreviewMode ) {
1858 TPythonDump() << this << ".ExtrusionSweepObject( "
1859 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1863 //=======================================================================
1864 //function : ExtrusionSweepObject1D
1866 //=======================================================================
1868 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1869 const SMESH::DirStruct & theStepVector,
1870 CORBA::Long theNbOfSteps)
1872 SMESH::long_array_var anElementsId = theObject->GetIDs();
1873 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1874 if ( !myPreviewMode ) {
1875 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1876 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1880 //=======================================================================
1881 //function : ExtrusionSweepObject2D
1883 //=======================================================================
1885 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1886 const SMESH::DirStruct & theStepVector,
1887 CORBA::Long theNbOfSteps)
1889 SMESH::long_array_var anElementsId = theObject->GetIDs();
1890 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1891 if ( !myPreviewMode ) {
1892 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1893 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1897 //=======================================================================
1898 //function : ExtrusionSweepMakeGroups
1900 //=======================================================================
1902 SMESH::ListOfGroups*
1903 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1904 const SMESH::DirStruct& theStepVector,
1905 CORBA::Long theNbOfSteps)
1907 SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1909 if ( !myPreviewMode ) {
1910 TPythonDump aPythonDump;
1911 DumpGroupsList(aPythonDump,aGroups);
1912 aPythonDump << this << ".ExtrusionSweepMakeGroups( "
1913 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1917 //=======================================================================
1918 //function : ExtrusionSweepObjectMakeGroups
1920 //=======================================================================
1922 SMESH::ListOfGroups*
1923 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1924 const SMESH::DirStruct& theStepVector,
1925 CORBA::Long theNbOfSteps)
1927 SMESH::long_array_var anElementsId = theObject->GetIDs();
1928 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1930 if ( !myPreviewMode ) {
1931 TPythonDump aPythonDump;
1932 DumpGroupsList(aPythonDump,aGroups);
1933 aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( "
1934 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1939 //=======================================================================
1940 //function : ExtrusionSweepObject1DMakeGroups
1942 //=======================================================================
1944 SMESH::ListOfGroups*
1945 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1946 const SMESH::DirStruct& theStepVector,
1947 CORBA::Long theNbOfSteps)
1949 SMESH::long_array_var anElementsId = theObject->GetIDs();
1950 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1951 if ( !myPreviewMode ) {
1952 TPythonDump aPythonDump;
1953 DumpGroupsList(aPythonDump,aGroups);
1954 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( "
1955 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1960 //=======================================================================
1961 //function : ExtrusionSweepObject2DMakeGroups
1963 //=======================================================================
1965 SMESH::ListOfGroups*
1966 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1967 const SMESH::DirStruct& theStepVector,
1968 CORBA::Long theNbOfSteps)
1970 SMESH::long_array_var anElementsId = theObject->GetIDs();
1971 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1972 if ( !myPreviewMode ) {
1973 TPythonDump aPythonDump;
1974 DumpGroupsList(aPythonDump,aGroups);
1975 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( "
1976 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1982 //=======================================================================
1983 //function : advancedExtrusion
1985 //=======================================================================
1987 SMESH::ListOfGroups*
1988 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1989 const SMESH::DirStruct & theStepVector,
1990 CORBA::Long theNbOfSteps,
1991 CORBA::Long theExtrFlags,
1992 CORBA::Double theSewTolerance,
1993 const bool theMakeGroups)
1997 TIDSortedElemSet elements;
1998 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2000 const SMESH::PointStruct * P = &theStepVector.PS;
2001 gp_Vec stepVec( P->x, P->y, P->z );
2003 ::SMESH_MeshEditor anEditor( myMesh );
2004 TElemOfElemListMap aHystory;
2005 ::SMESH_MeshEditor::PGroupIDs groupIds =
2006 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
2007 theMakeGroups, theExtrFlags, theSewTolerance);
2008 storeResult(anEditor);
2010 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2013 //=======================================================================
2014 //function : AdvancedExtrusion
2016 //=======================================================================
2018 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
2019 const SMESH::DirStruct & theStepVector,
2020 CORBA::Long theNbOfSteps,
2021 CORBA::Long theExtrFlags,
2022 CORBA::Double theSewTolerance)
2024 if ( !myPreviewMode ) {
2025 TPythonDump() << "stepVector = " << theStepVector;
2026 TPythonDump() << this << ".AdvancedExtrusion("
2029 << theNbOfSteps << ","
2030 << theExtrFlags << ", "
2031 << theSewTolerance << " )";
2033 advancedExtrusion( theIDsOfElements,
2041 //=======================================================================
2042 //function : AdvancedExtrusionMakeGroups
2044 //=======================================================================
2046 SMESH::ListOfGroups*
2047 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
2048 const SMESH::DirStruct& theStepVector,
2049 CORBA::Long theNbOfSteps,
2050 CORBA::Long theExtrFlags,
2051 CORBA::Double theSewTolerance)
2053 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
2060 if ( !myPreviewMode ) {
2061 TPythonDump() << "stepVector = " << theStepVector;
2062 TPythonDump aPythonDump;
2063 DumpGroupsList(aPythonDump,aGroups);
2064 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
2067 << theNbOfSteps << ","
2068 << theExtrFlags << ", "
2069 << theSewTolerance << " )";
2075 //================================================================================
2077 * \brief Convert extrusion error to IDL enum
2079 //================================================================================
2081 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2083 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
2087 RETCASE( EXTR_NO_ELEMENTS );
2088 RETCASE( EXTR_PATH_NOT_EDGE );
2089 RETCASE( EXTR_BAD_PATH_SHAPE );
2090 RETCASE( EXTR_BAD_STARTING_NODE );
2091 RETCASE( EXTR_BAD_ANGLES_NUMBER );
2092 RETCASE( EXTR_CANT_GET_TANGENT );
2094 return SMESH::SMESH_MeshEditor::EXTR_OK;
2098 //=======================================================================
2099 //function : extrusionAlongPath
2101 //=======================================================================
2103 SMESH::ListOfGroups*
2104 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2105 SMESH::SMESH_Mesh_ptr thePathMesh,
2106 GEOM::GEOM_Object_ptr thePathShape,
2107 CORBA::Long theNodeStart,
2108 CORBA::Boolean theHasAngles,
2109 const SMESH::double_array & theAngles,
2110 CORBA::Boolean theHasRefPoint,
2111 const SMESH::PointStruct & theRefPoint,
2112 const bool theMakeGroups,
2113 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
2114 const SMDSAbs_ElementType theElementType)
2116 MESSAGE("extrusionAlongPath");
2119 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
2120 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2123 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2125 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2126 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2128 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
2129 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2133 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
2135 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2139 TIDSortedElemSet elements;
2140 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
2142 list<double> angles;
2143 for (int i = 0; i < theAngles.length(); i++) {
2144 angles.push_back( theAngles[i] );
2147 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
2149 int nbOldGroups = myMesh->NbGroup();
2151 ::SMESH_MeshEditor anEditor( myMesh );
2152 ::SMESH_MeshEditor::Extrusion_Error error =
2153 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
2154 theHasAngles, angles, false,
2155 theHasRefPoint, refPnt, theMakeGroups );
2156 myMesh->GetMeshDS()->Modified();
2157 storeResult(anEditor);
2158 theError = convExtrError( error );
2160 if ( theMakeGroups ) {
2161 list<int> groupIDs = myMesh->GetGroupIds();
2162 list<int>::iterator newBegin = groupIDs.begin();
2163 std::advance( newBegin, nbOldGroups ); // skip old groups
2164 groupIDs.erase( groupIDs.begin(), newBegin );
2165 return getGroups( & groupIDs );
2171 //=======================================================================
2172 //function : extrusionAlongPathX
2174 //=======================================================================
2176 SMESH::ListOfGroups*
2177 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2178 SMESH::SMESH_IDSource_ptr Path,
2179 CORBA::Long NodeStart,
2180 CORBA::Boolean HasAngles,
2181 const SMESH::double_array& Angles,
2182 CORBA::Boolean LinearVariation,
2183 CORBA::Boolean HasRefPoint,
2184 const SMESH::PointStruct& RefPoint,
2185 const bool MakeGroups,
2186 const SMDSAbs_ElementType ElementType,
2187 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2189 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2193 list<double> angles;
2194 for (int i = 0; i < Angles.length(); i++) {
2195 angles.push_back( Angles[i] );
2197 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2198 int nbOldGroups = myMesh->NbGroup();
2200 if ( Path->_is_nil() ) {
2201 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2205 TIDSortedElemSet elements;
2206 arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
2208 ::SMESH_MeshEditor anEditor( myMesh );
2209 ::SMESH_MeshEditor::Extrusion_Error error;
2211 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
2214 SMDS_MeshNode* aNodeStart =
2215 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2216 if ( !aNodeStart ) {
2217 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2220 error = anEditor.ExtrusionAlongTrack( elements, &(aMeshImp->GetImpl()), aNodeStart,
2221 HasAngles, angles, LinearVariation,
2222 HasRefPoint, refPnt, MakeGroups );
2223 myMesh->GetMeshDS()->Modified();
2226 SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
2229 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
2230 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
2231 SMDS_MeshNode* aNodeStart =
2232 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2233 if ( !aNodeStart ) {
2234 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2237 SMESH_subMesh* aSubMesh =
2238 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
2239 error = anEditor.ExtrusionAlongTrack( elements, aSubMesh, aNodeStart,
2240 HasAngles, angles, LinearVariation,
2241 HasRefPoint, refPnt, MakeGroups );
2242 myMesh->GetMeshDS()->Modified();
2245 SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
2247 // path as group of 1D elements
2251 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2257 storeResult(anEditor);
2258 Error = convExtrError( error );
2261 list<int> groupIDs = myMesh->GetGroupIds();
2262 list<int>::iterator newBegin = groupIDs.begin();
2263 std::advance( newBegin, nbOldGroups ); // skip old groups
2264 groupIDs.erase( groupIDs.begin(), newBegin );
2265 return getGroups( & groupIDs );
2271 //=======================================================================
2272 //function : ExtrusionAlongPath
2274 //=======================================================================
2276 SMESH::SMESH_MeshEditor::Extrusion_Error
2277 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2278 SMESH::SMESH_Mesh_ptr thePathMesh,
2279 GEOM::GEOM_Object_ptr thePathShape,
2280 CORBA::Long theNodeStart,
2281 CORBA::Boolean theHasAngles,
2282 const SMESH::double_array & theAngles,
2283 CORBA::Boolean theHasRefPoint,
2284 const SMESH::PointStruct & theRefPoint)
2286 MESSAGE("ExtrusionAlongPath");
2287 if ( !myPreviewMode ) {
2288 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
2289 << theIDsOfElements << ", "
2290 << thePathMesh << ", "
2291 << thePathShape << ", "
2292 << theNodeStart << ", "
2293 << theHasAngles << ", "
2294 << theAngles << ", "
2295 << theHasRefPoint << ", "
2296 << "SMESH.PointStruct( "
2297 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2298 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2299 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2301 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2302 extrusionAlongPath( theIDsOfElements,
2315 //=======================================================================
2316 //function : ExtrusionAlongPathObject
2318 //=======================================================================
2320 SMESH::SMESH_MeshEditor::Extrusion_Error
2321 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
2322 SMESH::SMESH_Mesh_ptr thePathMesh,
2323 GEOM::GEOM_Object_ptr thePathShape,
2324 CORBA::Long theNodeStart,
2325 CORBA::Boolean theHasAngles,
2326 const SMESH::double_array & theAngles,
2327 CORBA::Boolean theHasRefPoint,
2328 const SMESH::PointStruct & theRefPoint)
2330 if ( !myPreviewMode ) {
2331 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
2332 << theObject << ", "
2333 << thePathMesh << ", "
2334 << thePathShape << ", "
2335 << theNodeStart << ", "
2336 << theHasAngles << ", "
2337 << theAngles << ", "
2338 << theHasRefPoint << ", "
2339 << "SMESH.PointStruct( "
2340 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2341 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2342 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2344 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2345 SMESH::long_array_var anElementsId = theObject->GetIDs();
2346 extrusionAlongPath( anElementsId,
2359 //=======================================================================
2360 //function : ExtrusionAlongPathObject1D
2362 //=======================================================================
2364 SMESH::SMESH_MeshEditor::Extrusion_Error
2365 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
2366 SMESH::SMESH_Mesh_ptr thePathMesh,
2367 GEOM::GEOM_Object_ptr thePathShape,
2368 CORBA::Long theNodeStart,
2369 CORBA::Boolean theHasAngles,
2370 const SMESH::double_array & theAngles,
2371 CORBA::Boolean theHasRefPoint,
2372 const SMESH::PointStruct & theRefPoint)
2374 if ( !myPreviewMode ) {
2375 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
2376 << theObject << ", "
2377 << thePathMesh << ", "
2378 << thePathShape << ", "
2379 << theNodeStart << ", "
2380 << theHasAngles << ", "
2381 << theAngles << ", "
2382 << theHasRefPoint << ", "
2383 << "SMESH.PointStruct( "
2384 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2385 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2386 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2388 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2389 SMESH::long_array_var anElementsId = theObject->GetIDs();
2390 extrusionAlongPath( anElementsId,
2404 //=======================================================================
2405 //function : ExtrusionAlongPathObject2D
2407 //=======================================================================
2409 SMESH::SMESH_MeshEditor::Extrusion_Error
2410 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
2411 SMESH::SMESH_Mesh_ptr thePathMesh,
2412 GEOM::GEOM_Object_ptr thePathShape,
2413 CORBA::Long theNodeStart,
2414 CORBA::Boolean theHasAngles,
2415 const SMESH::double_array & theAngles,
2416 CORBA::Boolean theHasRefPoint,
2417 const SMESH::PointStruct & theRefPoint)
2419 if ( !myPreviewMode ) {
2420 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
2421 << theObject << ", "
2422 << thePathMesh << ", "
2423 << thePathShape << ", "
2424 << theNodeStart << ", "
2425 << theHasAngles << ", "
2426 << theAngles << ", "
2427 << theHasRefPoint << ", "
2428 << "SMESH.PointStruct( "
2429 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2430 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2431 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2433 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2434 SMESH::long_array_var anElementsId = theObject->GetIDs();
2435 extrusionAlongPath( anElementsId,
2450 //=======================================================================
2451 //function : ExtrusionAlongPathMakeGroups
2453 //=======================================================================
2455 SMESH::ListOfGroups*
2456 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2457 SMESH::SMESH_Mesh_ptr thePathMesh,
2458 GEOM::GEOM_Object_ptr thePathShape,
2459 CORBA::Long theNodeStart,
2460 CORBA::Boolean theHasAngles,
2461 const SMESH::double_array& theAngles,
2462 CORBA::Boolean theHasRefPoint,
2463 const SMESH::PointStruct& theRefPoint,
2464 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2466 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2476 if ( !myPreviewMode ) {
2477 bool isDumpGroups = aGroups && aGroups->length() > 0;
2478 TPythonDump aPythonDump;
2480 aPythonDump << "("<<aGroups;
2483 aPythonDump << ", error)";
2485 aPythonDump <<"error";
2487 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2488 << theIDsOfElements << ", "
2489 << thePathMesh << ", "
2490 << thePathShape << ", "
2491 << theNodeStart << ", "
2492 << theHasAngles << ", "
2493 << theAngles << ", "
2494 << theHasRefPoint << ", "
2495 << "SMESH.PointStruct( "
2496 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2497 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2498 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2503 //=======================================================================
2504 //function : ExtrusionAlongPathObjectMakeGroups
2506 //=======================================================================
2508 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2509 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2510 SMESH::SMESH_Mesh_ptr thePathMesh,
2511 GEOM::GEOM_Object_ptr thePathShape,
2512 CORBA::Long theNodeStart,
2513 CORBA::Boolean theHasAngles,
2514 const SMESH::double_array& theAngles,
2515 CORBA::Boolean theHasRefPoint,
2516 const SMESH::PointStruct& theRefPoint,
2517 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2519 SMESH::long_array_var anElementsId = theObject->GetIDs();
2520 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2531 if ( !myPreviewMode ) {
2532 bool isDumpGroups = aGroups && aGroups->length() > 0;
2533 TPythonDump aPythonDump;
2535 aPythonDump << "("<<aGroups;
2538 aPythonDump << ", error)";
2540 aPythonDump <<"error";
2542 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2543 << theObject << ", "
2544 << thePathMesh << ", "
2545 << thePathShape << ", "
2546 << theNodeStart << ", "
2547 << theHasAngles << ", "
2548 << theAngles << ", "
2549 << theHasRefPoint << ", "
2550 << "SMESH.PointStruct( "
2551 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2552 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2553 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2558 //=======================================================================
2559 //function : ExtrusionAlongPathObject1DMakeGroups
2561 //=======================================================================
2563 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2564 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2565 SMESH::SMESH_Mesh_ptr thePathMesh,
2566 GEOM::GEOM_Object_ptr thePathShape,
2567 CORBA::Long theNodeStart,
2568 CORBA::Boolean theHasAngles,
2569 const SMESH::double_array& theAngles,
2570 CORBA::Boolean theHasRefPoint,
2571 const SMESH::PointStruct& theRefPoint,
2572 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2574 SMESH::long_array_var anElementsId = theObject->GetIDs();
2575 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2587 if ( !myPreviewMode ) {
2588 bool isDumpGroups = aGroups && aGroups->length() > 0;
2589 TPythonDump aPythonDump;
2591 aPythonDump << "("<<aGroups;
2594 aPythonDump << ", error)";
2596 aPythonDump <<"error";
2598 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
2599 << theObject << ", "
2600 << thePathMesh << ", "
2601 << thePathShape << ", "
2602 << theNodeStart << ", "
2603 << theHasAngles << ", "
2604 << theAngles << ", "
2605 << theHasRefPoint << ", "
2606 << "SMESH.PointStruct( "
2607 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2608 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2609 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2614 //=======================================================================
2615 //function : ExtrusionAlongPathObject2DMakeGroups
2617 //=======================================================================
2619 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2620 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2621 SMESH::SMESH_Mesh_ptr thePathMesh,
2622 GEOM::GEOM_Object_ptr thePathShape,
2623 CORBA::Long theNodeStart,
2624 CORBA::Boolean theHasAngles,
2625 const SMESH::double_array& theAngles,
2626 CORBA::Boolean theHasRefPoint,
2627 const SMESH::PointStruct& theRefPoint,
2628 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2630 SMESH::long_array_var anElementsId = theObject->GetIDs();
2631 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2643 if ( !myPreviewMode ) {
2644 bool isDumpGroups = aGroups && aGroups->length() > 0;
2645 TPythonDump aPythonDump;
2647 aPythonDump << "("<<aGroups;
2650 aPythonDump << ", error)";
2652 aPythonDump <<"error";
2654 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
2655 << theObject << ", "
2656 << thePathMesh << ", "
2657 << thePathShape << ", "
2658 << theNodeStart << ", "
2659 << theHasAngles << ", "
2660 << theAngles << ", "
2661 << theHasRefPoint << ", "
2662 << "SMESH.PointStruct( "
2663 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2664 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2665 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2671 //=======================================================================
2672 //function : ExtrusionAlongPathObjX
2674 //=======================================================================
2675 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2676 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
2677 SMESH::SMESH_IDSource_ptr Path,
2678 CORBA::Long NodeStart,
2679 CORBA::Boolean HasAngles,
2680 const SMESH::double_array& Angles,
2681 CORBA::Boolean LinearVariation,
2682 CORBA::Boolean HasRefPoint,
2683 const SMESH::PointStruct& RefPoint,
2684 CORBA::Boolean MakeGroups,
2685 SMESH::ElementType ElemType,
2686 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2688 SMESH::long_array_var anElementsId = Object->GetIDs();
2689 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2698 (SMDSAbs_ElementType)ElemType,
2701 if ( !myPreviewMode ) {
2702 bool isDumpGroups = aGroups && aGroups->length() > 0;
2703 TPythonDump aPythonDump;
2705 aPythonDump << "("<<aGroups;
2708 aPythonDump << ", error)";
2710 aPythonDump <<"error";
2712 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2715 << NodeStart << ", "
2716 << HasAngles << ", "
2718 << LinearVariation << ", "
2719 << HasRefPoint << ", "
2720 << "SMESH.PointStruct( "
2721 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2722 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2723 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2724 << MakeGroups << ", "
2725 << ElemType << " )";
2731 //=======================================================================
2732 //function : ExtrusionAlongPathX
2734 //=======================================================================
2735 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2736 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2737 SMESH::SMESH_IDSource_ptr Path,
2738 CORBA::Long NodeStart,
2739 CORBA::Boolean HasAngles,
2740 const SMESH::double_array& Angles,
2741 CORBA::Boolean LinearVariation,
2742 CORBA::Boolean HasRefPoint,
2743 const SMESH::PointStruct& RefPoint,
2744 CORBA::Boolean MakeGroups,
2745 SMESH::ElementType ElemType,
2746 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2748 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2757 (SMDSAbs_ElementType)ElemType,
2760 if ( !myPreviewMode ) {
2761 bool isDumpGroups = aGroups && aGroups->length() > 0;
2762 TPythonDump aPythonDump;
2764 aPythonDump << "("<<aGroups;
2767 aPythonDump << ", error)";
2769 aPythonDump <<"error";
2771 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2772 << IDsOfElements << ", "
2774 << NodeStart << ", "
2775 << HasAngles << ", "
2777 << LinearVariation << ", "
2778 << HasRefPoint << ", "
2779 << "SMESH.PointStruct( "
2780 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2781 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2782 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2783 << ElemType << " )";
2789 //================================================================================
2791 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2792 * of given angles along path steps
2793 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2794 * which proceeds the extrusion
2795 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2796 * is used to define the sub-mesh for the path
2798 //================================================================================
2800 SMESH::double_array*
2801 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2802 GEOM::GEOM_Object_ptr thePathShape,
2803 const SMESH::double_array & theAngles)
2805 SMESH::double_array_var aResult = new SMESH::double_array();
2806 int nbAngles = theAngles.length();
2807 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2809 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2810 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2811 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2812 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2813 return aResult._retn();
2814 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2815 if ( nbSteps == nbAngles )
2817 aResult.inout() = theAngles;
2821 aResult->length( nbSteps );
2822 double rAn2St = double( nbAngles ) / double( nbSteps );
2823 double angPrev = 0, angle;
2824 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2826 double angCur = rAn2St * ( iSt+1 );
2827 double angCurFloor = floor( angCur );
2828 double angPrevFloor = floor( angPrev );
2829 if ( angPrevFloor == angCurFloor )
2830 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2833 int iP = int( angPrevFloor );
2834 double angPrevCeil = ceil(angPrev);
2835 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2837 int iC = int( angCurFloor );
2838 if ( iC < nbAngles )
2839 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2841 iP = int( angPrevCeil );
2843 angle += theAngles[ iC ];
2845 aResult[ iSt ] = angle;
2850 // Update Python script
2851 TPythonDump() << "rotAngles = " << theAngles;
2852 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2853 << thePathMesh << ", "
2854 << thePathShape << ", "
2857 return aResult._retn();
2861 //=======================================================================
2864 //=======================================================================
2866 SMESH::ListOfGroups*
2867 SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements,
2868 const SMESH::AxisStruct & theAxis,
2869 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2870 CORBA::Boolean theCopy,
2871 const bool theMakeGroups,
2872 ::SMESH_Mesh* theTargetMesh)
2876 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2877 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2880 switch ( theMirrorType ) {
2881 case SMESH::SMESH_MeshEditor::POINT:
2882 aTrsf.SetMirror( P );
2884 case SMESH::SMESH_MeshEditor::AXIS:
2885 aTrsf.SetMirror( gp_Ax1( P, V ));
2888 aTrsf.SetMirror( gp_Ax2( P, V ));
2891 ::SMESH_MeshEditor anEditor( myMesh );
2892 ::SMESH_MeshEditor::PGroupIDs groupIds =
2893 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2896 storeResult(anEditor);
2899 myMesh->GetMeshDS()->Modified();
2900 myMesh->SetIsModified( true );
2903 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2906 //=======================================================================
2909 //=======================================================================
2911 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2912 const SMESH::AxisStruct & theAxis,
2913 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2914 CORBA::Boolean theCopy)
2916 if ( !myPreviewMode ) {
2917 TPythonDump() << this << ".Mirror( "
2918 << theIDsOfElements << ", "
2920 << mirrorTypeName(theMirrorType) << ", "
2923 if ( theIDsOfElements.length() > 0 )
2925 TIDSortedElemSet elements;
2926 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2927 mirror(elements, theAxis, theMirrorType, theCopy, false);
2932 //=======================================================================
2933 //function : MirrorObject
2935 //=======================================================================
2937 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2938 const SMESH::AxisStruct & theAxis,
2939 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2940 CORBA::Boolean theCopy)
2942 if ( !myPreviewMode ) {
2943 TPythonDump() << this << ".MirrorObject( "
2944 << theObject << ", "
2946 << mirrorTypeName(theMirrorType) << ", "
2949 TIDSortedElemSet elements;
2950 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2951 mirror(elements, theAxis, theMirrorType, theCopy, false);
2954 //=======================================================================
2955 //function : MirrorMakeGroups
2957 //=======================================================================
2959 SMESH::ListOfGroups*
2960 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2961 const SMESH::AxisStruct& theMirror,
2962 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2964 SMESH::ListOfGroups * aGroups = 0;
2965 if ( theIDsOfElements.length() > 0 )
2967 TIDSortedElemSet elements;
2968 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2969 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2971 if ( !myPreviewMode ) {
2972 TPythonDump aPythonDump;
2973 DumpGroupsList(aPythonDump,aGroups);
2974 aPythonDump << this << ".MirrorMakeGroups( "
2975 << theIDsOfElements << ", "
2976 << theMirror << ", "
2977 << mirrorTypeName(theMirrorType) << " )";
2982 //=======================================================================
2983 //function : MirrorObjectMakeGroups
2985 //=======================================================================
2987 SMESH::ListOfGroups*
2988 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2989 const SMESH::AxisStruct& theMirror,
2990 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2992 SMESH::ListOfGroups * aGroups = 0;
2993 TIDSortedElemSet elements;
2994 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2995 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2997 if ( !myPreviewMode )
2999 TPythonDump aPythonDump;
3000 DumpGroupsList(aPythonDump,aGroups);
3001 aPythonDump << this << ".MirrorObjectMakeGroups( "
3002 << theObject << ", "
3003 << theMirror << ", "
3004 << mirrorTypeName(theMirrorType) << " )";
3009 //=======================================================================
3010 //function : MirrorMakeMesh
3012 //=======================================================================
3014 SMESH::SMESH_Mesh_ptr
3015 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
3016 const SMESH::AxisStruct& theMirror,
3017 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3018 CORBA::Boolean theCopyGroups,
3019 const char* theMeshName)
3021 SMESH_Mesh_i* mesh_i;
3022 SMESH::SMESH_Mesh_var mesh;
3023 { // open new scope to dump "MakeMesh" command
3024 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3026 TPythonDump pydump; // to prevent dump at mesh creation
3028 mesh = makeMesh( theMeshName );
3029 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3030 if (mesh_i && theIDsOfElements.length() > 0 )
3032 TIDSortedElemSet elements;
3033 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3034 mirror(elements, theMirror, theMirrorType,
3035 false, theCopyGroups, & mesh_i->GetImpl());
3036 mesh_i->CreateGroupServants();
3039 if ( !myPreviewMode ) {
3040 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
3041 << theIDsOfElements << ", "
3042 << theMirror << ", "
3043 << mirrorTypeName(theMirrorType) << ", "
3044 << theCopyGroups << ", '"
3045 << theMeshName << "' )";
3050 if(!myPreviewMode && mesh_i)
3051 mesh_i->GetGroups();
3053 return mesh._retn();
3056 //=======================================================================
3057 //function : MirrorObjectMakeMesh
3059 //=======================================================================
3061 SMESH::SMESH_Mesh_ptr
3062 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3063 const SMESH::AxisStruct& theMirror,
3064 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3065 CORBA::Boolean theCopyGroups,
3066 const char* theMeshName)
3068 SMESH_Mesh_i* mesh_i;
3069 SMESH::SMESH_Mesh_var mesh;
3070 { // open new scope to dump "MakeMesh" command
3071 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3073 TPythonDump pydump; // to prevent dump at mesh creation
3075 mesh = makeMesh( theMeshName );
3076 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3077 TIDSortedElemSet elements;
3079 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3081 mirror(elements, theMirror, theMirrorType,
3082 false, theCopyGroups, & mesh_i->GetImpl());
3083 mesh_i->CreateGroupServants();
3085 if ( !myPreviewMode ) {
3086 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
3087 << theObject << ", "
3088 << theMirror << ", "
3089 << mirrorTypeName(theMirrorType) << ", "
3090 << theCopyGroups << ", '"
3091 << theMeshName << "' )";
3096 if(!myPreviewMode && mesh_i)
3097 mesh_i->GetGroups();
3099 return mesh._retn();
3102 //=======================================================================
3103 //function : translate
3105 //=======================================================================
3107 SMESH::ListOfGroups*
3108 SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements,
3109 const SMESH::DirStruct & theVector,
3110 CORBA::Boolean theCopy,
3111 const bool theMakeGroups,
3112 ::SMESH_Mesh* theTargetMesh)
3117 const SMESH::PointStruct * P = &theVector.PS;
3118 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
3120 ::SMESH_MeshEditor anEditor( myMesh );
3121 ::SMESH_MeshEditor::PGroupIDs groupIds =
3122 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3125 storeResult(anEditor);
3128 myMesh->GetMeshDS()->Modified();
3129 myMesh->SetIsModified( true );
3132 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3135 //=======================================================================
3136 //function : Translate
3138 //=======================================================================
3140 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
3141 const SMESH::DirStruct & theVector,
3142 CORBA::Boolean theCopy)
3144 if ( !myPreviewMode ) {
3145 TPythonDump() << this << ".Translate( "
3146 << theIDsOfElements << ", "
3147 << theVector << ", "
3150 if ( theIDsOfElements.length() )
3152 TIDSortedElemSet elements;
3153 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3154 translate(elements,theVector,theCopy,false);
3158 //=======================================================================
3159 //function : TranslateObject
3161 //=======================================================================
3163 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
3164 const SMESH::DirStruct & theVector,
3165 CORBA::Boolean theCopy)
3167 if ( !myPreviewMode ) {
3168 TPythonDump() << this << ".TranslateObject( "
3169 << theObject << ", "
3170 << theVector << ", "
3173 TIDSortedElemSet elements;
3174 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3175 translate( elements, theVector, theCopy, false);
3178 //=======================================================================
3179 //function : TranslateMakeGroups
3181 //=======================================================================
3183 SMESH::ListOfGroups*
3184 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
3185 const SMESH::DirStruct& theVector)
3187 SMESH::ListOfGroups * aGroups = 0;
3188 if ( theIDsOfElements.length() )
3190 TIDSortedElemSet elements;
3191 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3192 aGroups = translate(elements,theVector,true,true);
3194 if ( !myPreviewMode ) {
3195 TPythonDump aPythonDump;
3196 DumpGroupsList(aPythonDump,aGroups);
3197 aPythonDump << this << ".TranslateMakeGroups( "
3198 << theIDsOfElements << ", "
3199 << theVector << " )";
3204 //=======================================================================
3205 //function : TranslateObjectMakeGroups
3207 //=======================================================================
3209 SMESH::ListOfGroups*
3210 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3211 const SMESH::DirStruct& theVector)
3213 SMESH::ListOfGroups * aGroups = 0;
3214 TIDSortedElemSet elements;
3215 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3216 aGroups = translate(elements, theVector, true, true);
3218 if ( !myPreviewMode ) {
3220 TPythonDump aPythonDump;
3221 DumpGroupsList(aPythonDump,aGroups);
3222 aPythonDump << this << ".TranslateObjectMakeGroups( "
3223 << theObject << ", "
3224 << theVector << " )";
3229 //=======================================================================
3230 //function : TranslateMakeMesh
3232 //=======================================================================
3234 SMESH::SMESH_Mesh_ptr
3235 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3236 const SMESH::DirStruct& theVector,
3237 CORBA::Boolean theCopyGroups,
3238 const char* theMeshName)
3240 SMESH_Mesh_i* mesh_i;
3241 SMESH::SMESH_Mesh_var mesh;
3243 { // open new scope to dump "MakeMesh" command
3244 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3246 TPythonDump pydump; // to prevent dump at mesh creation
3248 mesh = makeMesh( theMeshName );
3249 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3251 if ( mesh_i && theIDsOfElements.length() )
3253 TIDSortedElemSet elements;
3254 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3255 translate(elements, theVector, false, theCopyGroups, & mesh_i->GetImpl());
3256 mesh_i->CreateGroupServants();
3259 if ( !myPreviewMode ) {
3260 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3261 << theIDsOfElements << ", "
3262 << theVector << ", "
3263 << theCopyGroups << ", '"
3264 << theMeshName << "' )";
3269 if(!myPreviewMode && mesh_i)
3270 mesh_i->GetGroups();
3272 return mesh._retn();
3275 //=======================================================================
3276 //function : TranslateObjectMakeMesh
3278 //=======================================================================
3280 SMESH::SMESH_Mesh_ptr
3281 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3282 const SMESH::DirStruct& theVector,
3283 CORBA::Boolean theCopyGroups,
3284 const char* theMeshName)
3286 SMESH_Mesh_i* mesh_i;
3287 SMESH::SMESH_Mesh_var mesh;
3288 { // open new scope to dump "MakeMesh" command
3289 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3291 TPythonDump pydump; // to prevent dump at mesh creation
3292 mesh = makeMesh( theMeshName );
3293 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3295 TIDSortedElemSet elements;
3297 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3299 translate(elements, theVector,false, theCopyGroups, & mesh_i->GetImpl());
3300 mesh_i->CreateGroupServants();
3302 if ( !myPreviewMode ) {
3303 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3304 << theObject << ", "
3305 << theVector << ", "
3306 << theCopyGroups << ", '"
3307 << theMeshName << "' )";
3312 if(!myPreviewMode && mesh_i)
3313 mesh_i->GetGroups();
3315 return mesh._retn();
3318 //=======================================================================
3321 //=======================================================================
3323 SMESH::ListOfGroups*
3324 SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements,
3325 const SMESH::AxisStruct & theAxis,
3326 CORBA::Double theAngle,
3327 CORBA::Boolean theCopy,
3328 const bool theMakeGroups,
3329 ::SMESH_Mesh* theTargetMesh)
3333 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3334 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3337 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3339 ::SMESH_MeshEditor anEditor( myMesh );
3340 ::SMESH_MeshEditor::PGroupIDs groupIds =
3341 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3344 storeResult(anEditor);
3347 myMesh->GetMeshDS()->Modified();
3348 myMesh->SetIsModified( true );
3351 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3354 //=======================================================================
3357 //=======================================================================
3359 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3360 const SMESH::AxisStruct & theAxis,
3361 CORBA::Double theAngle,
3362 CORBA::Boolean theCopy)
3364 if ( !myPreviewMode ) {
3365 TPythonDump() << this << ".Rotate( "
3366 << theIDsOfElements << ", "
3371 if ( theIDsOfElements.length() > 0 )
3373 TIDSortedElemSet elements;
3374 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3375 rotate(elements,theAxis,theAngle,theCopy,false);
3379 //=======================================================================
3380 //function : RotateObject
3382 //=======================================================================
3384 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3385 const SMESH::AxisStruct & theAxis,
3386 CORBA::Double theAngle,
3387 CORBA::Boolean theCopy)
3389 if ( !myPreviewMode ) {
3390 TPythonDump() << this << ".RotateObject( "
3391 << theObject << ", "
3396 TIDSortedElemSet elements;
3397 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3398 rotate(elements,theAxis,theAngle,theCopy,false);
3401 //=======================================================================
3402 //function : RotateMakeGroups
3404 //=======================================================================
3406 SMESH::ListOfGroups*
3407 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3408 const SMESH::AxisStruct& theAxis,
3409 CORBA::Double theAngle)
3411 SMESH::ListOfGroups * aGroups = 0;
3412 if ( theIDsOfElements.length() > 0 )
3414 TIDSortedElemSet elements;
3415 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3416 aGroups = rotate(elements,theAxis,theAngle,true,true);
3418 if ( !myPreviewMode ) {
3419 TPythonDump aPythonDump;
3420 DumpGroupsList(aPythonDump,aGroups);
3421 aPythonDump << this << ".RotateMakeGroups( "
3422 << theIDsOfElements << ", "
3424 << theAngle << " )";
3429 //=======================================================================
3430 //function : RotateObjectMakeGroups
3432 //=======================================================================
3434 SMESH::ListOfGroups*
3435 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3436 const SMESH::AxisStruct& theAxis,
3437 CORBA::Double theAngle)
3439 SMESH::ListOfGroups * aGroups = 0;
3440 TIDSortedElemSet elements;
3441 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3442 aGroups = rotate(elements,theAxis,theAngle,true,true);
3444 if ( !myPreviewMode ) {
3445 TPythonDump aPythonDump;
3446 DumpGroupsList(aPythonDump,aGroups);
3447 aPythonDump << this << ".RotateObjectMakeGroups( "
3448 << theObject << ", "
3450 << theAngle << " )";
3455 //=======================================================================
3456 //function : RotateMakeMesh
3458 //=======================================================================
3460 SMESH::SMESH_Mesh_ptr
3461 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3462 const SMESH::AxisStruct& theAxis,
3463 CORBA::Double theAngleInRadians,
3464 CORBA::Boolean theCopyGroups,
3465 const char* theMeshName)
3467 SMESH::SMESH_Mesh_var mesh;
3468 SMESH_Mesh_i* mesh_i;
3470 { // open new scope to dump "MakeMesh" command
3471 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3473 TPythonDump pydump; // to prevent dump at mesh creation
3475 mesh = makeMesh( theMeshName );
3476 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3478 if ( mesh_i && theIDsOfElements.length() > 0 )
3480 TIDSortedElemSet elements;
3481 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3482 rotate(elements, theAxis, theAngleInRadians,
3483 false, theCopyGroups, & mesh_i->GetImpl());
3484 mesh_i->CreateGroupServants();
3486 if ( !myPreviewMode ) {
3487 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3488 << theIDsOfElements << ", "
3490 << theAngleInRadians << ", "
3491 << theCopyGroups << ", '"
3492 << theMeshName << "' )";
3497 if(!myPreviewMode && mesh_i && theIDsOfElements.length() > 0 )
3498 mesh_i->GetGroups();
3500 return mesh._retn();
3503 //=======================================================================
3504 //function : RotateObjectMakeMesh
3506 //=======================================================================
3508 SMESH::SMESH_Mesh_ptr
3509 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3510 const SMESH::AxisStruct& theAxis,
3511 CORBA::Double theAngleInRadians,
3512 CORBA::Boolean theCopyGroups,
3513 const char* theMeshName)
3515 SMESH::SMESH_Mesh_var mesh;
3516 SMESH_Mesh_i* mesh_i;
3518 {// open new scope to dump "MakeMesh" command
3519 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3521 TPythonDump pydump; // to prevent dump at mesh creation
3522 mesh = makeMesh( theMeshName );
3523 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3525 TIDSortedElemSet elements;
3527 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3529 rotate(elements, theAxis, theAngleInRadians,
3530 false, theCopyGroups, & mesh_i->GetImpl());
3531 mesh_i->CreateGroupServants();
3533 if ( !myPreviewMode ) {
3534 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3535 << theObject << ", "
3537 << theAngleInRadians << ", "
3538 << theCopyGroups << ", '"
3539 << theMeshName << "' )";
3544 if(!myPreviewMode && mesh_i)
3545 mesh_i->GetGroups();
3547 return mesh._retn();
3550 //=======================================================================
3553 //=======================================================================
3555 SMESH::ListOfGroups*
3556 SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject,
3557 const SMESH::PointStruct& thePoint,
3558 const SMESH::double_array& theScaleFact,
3559 CORBA::Boolean theCopy,
3560 const bool theMakeGroups,
3561 ::SMESH_Mesh* theTargetMesh)
3564 if ( theScaleFact.length() < 1 )
3565 THROW_SALOME_CORBA_EXCEPTION("Scale factor not given", SALOME::BAD_PARAM);
3566 if ( theScaleFact.length() == 2 )
3567 THROW_SALOME_CORBA_EXCEPTION("Invalid nb of scale factors : 2", SALOME::BAD_PARAM);
3569 TIDSortedElemSet elements;
3570 if ( !idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/true))
3573 vector<double> S(3);
3574 S[0] = theScaleFact[0];
3575 S[1] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1];
3576 S[2] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2];
3577 double tol = std::numeric_limits<double>::max();
3579 aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]),
3580 0, S[1], 0, thePoint.y * (1-S[1]),
3581 0, 0, S[2], thePoint.z * (1-S[2]), tol, tol);
3583 ::SMESH_MeshEditor anEditor( myMesh );
3584 ::SMESH_MeshEditor::PGroupIDs groupIds =
3585 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3588 storeResult(anEditor);
3591 myMesh->GetMeshDS()->Modified();
3592 myMesh->SetIsModified( true );
3594 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3597 //=======================================================================
3600 //=======================================================================
3602 void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr theObject,
3603 const SMESH::PointStruct& thePoint,
3604 const SMESH::double_array& theScaleFact,
3605 CORBA::Boolean theCopy)
3607 if ( !myPreviewMode ) {
3608 TPythonDump() << this << ".Scale( "
3609 << theObject << ", "
3610 << "SMESH.PointStruct( " << thePoint.x << ", "
3611 << thePoint.y << ", " << thePoint.z << " ) ,"
3612 << theScaleFact << ", "
3615 scale(theObject, thePoint, theScaleFact, theCopy, false);
3619 //=======================================================================
3620 //function : ScaleMakeGroups
3622 //=======================================================================
3624 SMESH::ListOfGroups*
3625 SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3626 const SMESH::PointStruct& thePoint,
3627 const SMESH::double_array& theScaleFact)
3629 SMESH::ListOfGroups * aGroups = scale(theObject, thePoint, theScaleFact, true, true);
3630 if ( !myPreviewMode ) {
3632 TPythonDump aPythonDump;
3633 DumpGroupsList(aPythonDump,aGroups);
3634 aPythonDump << this << ".Scale("
3636 << "SMESH.PointStruct(" <<thePoint.x << ","
3637 << thePoint.y << "," << thePoint.z << "),"
3638 << theScaleFact << ",True,True)";
3644 //=======================================================================
3645 //function : ScaleMakeMesh
3647 //=======================================================================
3649 SMESH::SMESH_Mesh_ptr
3650 SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3651 const SMESH::PointStruct& thePoint,
3652 const SMESH::double_array& theScaleFact,
3653 CORBA::Boolean theCopyGroups,
3654 const char* theMeshName)
3656 SMESH_Mesh_i* mesh_i;
3657 SMESH::SMESH_Mesh_var mesh;
3658 { // open new scope to dump "MakeMesh" command
3659 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3661 TPythonDump pydump; // to prevent dump at mesh creation
3662 mesh = makeMesh( theMeshName );
3663 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3667 scale(theObject, thePoint, theScaleFact,false, theCopyGroups, & mesh_i->GetImpl());
3668 mesh_i->CreateGroupServants();
3670 if ( !myPreviewMode )
3671 pydump << mesh << " = " << this << ".ScaleMakeMesh( "
3672 << theObject << ", "
3673 << "SMESH.PointStruct( " << thePoint.x << ", "
3674 << thePoint.y << ", " << thePoint.z << " ) ,"
3675 << theScaleFact << ", "
3676 << theCopyGroups << ", '"
3677 << theMeshName << "' )";
3681 if(!myPreviewMode && mesh_i)
3682 mesh_i->GetGroups();
3684 return mesh._retn();
3688 //=======================================================================
3689 //function : FindCoincidentNodes
3691 //=======================================================================
3693 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3694 SMESH::array_of_long_array_out GroupsOfNodes)
3698 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3699 ::SMESH_MeshEditor anEditor( myMesh );
3700 TIDSortedNodeSet nodes; // no input nodes
3701 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3703 GroupsOfNodes = new SMESH::array_of_long_array;
3704 GroupsOfNodes->length( aListOfListOfNodes.size() );
3705 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3706 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3707 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3708 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3709 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3710 aGroup.length( aListOfNodes.size() );
3711 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3712 aGroup[ j ] = (*lIt)->GetID();
3714 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3715 << Tolerance << " )";
3718 //=======================================================================
3719 //function : FindCoincidentNodesOnPart
3721 //=======================================================================
3722 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3723 CORBA::Double Tolerance,
3724 SMESH::array_of_long_array_out GroupsOfNodes)
3728 TIDSortedNodeSet nodes;
3729 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3731 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3732 ::SMESH_MeshEditor anEditor( myMesh );
3734 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3736 GroupsOfNodes = new SMESH::array_of_long_array;
3737 GroupsOfNodes->length( aListOfListOfNodes.size() );
3738 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3739 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3741 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3742 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3743 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3744 aGroup.length( aListOfNodes.size() );
3745 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3746 aGroup[ j ] = (*lIt)->GetID();
3748 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3750 << Tolerance << " )";
3753 //================================================================================
3755 * \brief Finds nodes coinsident with Tolerance within Object excluding nodes within
3756 * ExceptSubMeshOrGroups
3758 //================================================================================
3760 void SMESH_MeshEditor_i::
3761 FindCoincidentNodesOnPartBut(SMESH::SMESH_IDSource_ptr theObject,
3762 CORBA::Double theTolerance,
3763 SMESH::array_of_long_array_out theGroupsOfNodes,
3764 const SMESH::ListOfIDSources& theExceptSubMeshOrGroups)
3768 TIDSortedNodeSet nodes;
3769 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3771 for ( int i = 0; i < theExceptSubMeshOrGroups.length(); ++i )
3773 TIDSortedNodeSet exceptNodes;
3774 idSourceToNodeSet( theExceptSubMeshOrGroups[i], GetMeshDS(), exceptNodes );
3775 TIDSortedNodeSet::iterator avoidNode = exceptNodes.begin();
3776 for ( ; avoidNode != exceptNodes.end(); ++avoidNode)
3777 nodes.erase( *avoidNode );
3779 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3780 ::SMESH_MeshEditor anEditor( myMesh );
3782 anEditor.FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes );
3784 theGroupsOfNodes = new SMESH::array_of_long_array;
3785 theGroupsOfNodes->length( aListOfListOfNodes.size() );
3786 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3787 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3789 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3790 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3791 SMESH::long_array& aGroup = (*theGroupsOfNodes)[ i ];
3792 aGroup.length( aListOfNodes.size() );
3793 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3794 aGroup[ j ] = (*lIt)->GetID();
3796 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPartBut( "
3798 << theTolerance << ", "
3799 << theExceptSubMeshOrGroups << " )";
3802 //=======================================================================
3803 //function : MergeNodes
3805 //=======================================================================
3807 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3811 SMESHDS_Mesh* aMesh = GetMeshDS();
3813 TPythonDump aTPythonDump;
3814 aTPythonDump << this << ".MergeNodes([";
3815 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3816 for (int i = 0; i < GroupsOfNodes.length(); i++)
3818 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3819 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3820 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3821 for ( int j = 0; j < aNodeGroup.length(); j++ )
3823 CORBA::Long index = aNodeGroup[ j ];
3824 const SMDS_MeshNode * node = aMesh->FindNode(index);
3826 aListOfNodes.push_back( node );
3828 if ( aListOfNodes.size() < 2 )
3829 aListOfListOfNodes.pop_back();
3831 if ( i > 0 ) aTPythonDump << ", ";
3832 aTPythonDump << aNodeGroup;
3834 ::SMESH_MeshEditor anEditor( myMesh );
3835 anEditor.MergeNodes( aListOfListOfNodes );
3837 aTPythonDump << "])";
3838 myMesh->GetMeshDS()->Modified();
3839 myMesh->SetIsModified( true );
3842 //=======================================================================
3843 //function : FindEqualElements
3845 //=======================================================================
3846 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3847 SMESH::array_of_long_array_out GroupsOfElementsID)
3851 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theObject);
3852 if ( !(!group->_is_nil() && group->GetType() == SMESH::NODE) )
3854 typedef list<int> TListOfIDs;
3855 set<const SMDS_MeshElement*> elems;
3856 SMESH::long_array_var aElementsId = theObject->GetIDs();
3857 SMESHDS_Mesh* aMesh = GetMeshDS();
3859 for(int i = 0; i < aElementsId->length(); i++) {
3860 CORBA::Long anID = aElementsId[i];
3861 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3867 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3868 ::SMESH_MeshEditor anEditor( myMesh );
3869 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3871 GroupsOfElementsID = new SMESH::array_of_long_array;
3872 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3874 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3875 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3876 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3877 TListOfIDs& listOfIDs = *arraysIt;
3878 aGroup.length( listOfIDs.size() );
3879 TListOfIDs::iterator idIt = listOfIDs.begin();
3880 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3881 aGroup[ k ] = *idIt;
3885 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3890 //=======================================================================
3891 //function : MergeElements
3893 //=======================================================================
3895 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3899 TPythonDump aTPythonDump;
3900 aTPythonDump << this << ".MergeElements( [";
3902 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3904 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3905 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3906 aListOfListOfElementsID.push_back( list< int >() );
3907 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3908 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3909 CORBA::Long id = anElemsIDGroup[ j ];
3910 aListOfElemsID.push_back( id );
3912 if ( aListOfElemsID.size() < 2 )
3913 aListOfListOfElementsID.pop_back();
3914 if ( i > 0 ) aTPythonDump << ", ";
3915 aTPythonDump << anElemsIDGroup;
3918 ::SMESH_MeshEditor anEditor( myMesh );
3919 anEditor.MergeElements(aListOfListOfElementsID);
3920 myMesh->GetMeshDS()->Modified();
3921 myMesh->SetIsModified( true );
3923 aTPythonDump << "] )";
3926 //=======================================================================
3927 //function : MergeEqualElements
3929 //=======================================================================
3931 void SMESH_MeshEditor_i::MergeEqualElements()
3935 ::SMESH_MeshEditor anEditor( myMesh );
3936 anEditor.MergeEqualElements();
3938 TPythonDump() << this << ".MergeEqualElements()";
3941 //=============================================================================
3943 * Move the node to a given point
3945 //=============================================================================
3947 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
3952 initData(/*deleteSearchers=*/false);
3954 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
3958 if ( theNodeSearcher )
3959 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3961 if ( myPreviewMode ) // make preview data
3963 // in a preview mesh, make edges linked to a node
3964 TPreviewMesh tmpMesh;
3965 TIDSortedElemSet linkedNodes;
3966 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3967 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3968 SMDS_MeshNode *nodeCpy1 = tmpMesh.Copy(node);
3969 for ( ; nIt != linkedNodes.end(); ++nIt )
3971 SMDS_MeshNode *nodeCpy2 = tmpMesh.Copy ( cast2Node( *nIt ));
3972 tmpMesh.GetMeshDS()->AddEdge(nodeCpy1, nodeCpy2);
3976 tmpMesh.GetMeshDS()->MoveNode(nodeCpy1, x, y, z);
3977 // fill preview data
3978 ::SMESH_MeshEditor anEditor( & tmpMesh );
3979 storeResult( anEditor );
3981 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3982 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3984 GetMeshDS()->MoveNode(node, x, y, z);
3986 if ( !myPreviewMode )
3988 // Update Python script
3989 TPythonDump() << "isDone = " << this << ".MoveNode( "
3990 << NodeID << ", " << x << ", " << y << ", " << z << " )";
3991 myMesh->GetMeshDS()->Modified();
3992 myMesh->SetIsModified( true );
3998 //================================================================================
4000 * \brief Return ID of node closest to a given point
4002 //================================================================================
4004 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
4008 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4010 if ( !theNodeSearcher ) {
4011 ::SMESH_MeshEditor anEditor( myMesh );
4012 theNodeSearcher = anEditor.GetNodeSearcher();
4015 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
4016 return node->GetID();
4021 //================================================================================
4023 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
4024 * move the node closest to the point to point's location and return ID of the node
4026 //================================================================================
4028 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
4031 CORBA::Long theNodeID)
4033 // We keep theNodeSearcher until any mesh modification:
4034 // 1) initData() deletes theNodeSearcher at any edition,
4035 // 2) TSearchersDeleter - at any mesh compute event and mesh change
4037 initData(/*deleteSearchers=*/false);
4039 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4041 int nodeID = theNodeID;
4042 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
4043 if ( !node ) // preview moving node
4045 if ( !theNodeSearcher ) {
4046 ::SMESH_MeshEditor anEditor( myMesh );
4047 theNodeSearcher = anEditor.GetNodeSearcher();
4050 node = theNodeSearcher->FindClosestTo( p );
4053 nodeID = node->GetID();
4054 if ( myPreviewMode ) // make preview data
4056 // in a preview mesh, make edges linked to a node
4057 TPreviewMesh tmpMesh;
4058 TIDSortedElemSet linkedNodes;
4059 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
4060 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
4061 for ( ; nIt != linkedNodes.end(); ++nIt )
4063 SMDS_LinearEdge edge( node, cast2Node( *nIt ));
4064 tmpMesh.Copy( &edge );
4067 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
4069 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
4070 // fill preview data
4071 ::SMESH_MeshEditor anEditor( & tmpMesh );
4072 storeResult( anEditor );
4074 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
4076 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
4080 GetMeshDS()->MoveNode(node, x, y, z);
4084 if ( !myPreviewMode )
4086 TPythonDump() << "nodeID = " << this
4087 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
4088 << ", " << nodeID << " )";
4090 myMesh->GetMeshDS()->Modified();
4091 myMesh->SetIsModified( true );
4097 //=======================================================================
4099 * Return elements of given type where the given point is IN or ON.
4101 * 'ALL' type means elements of any type excluding nodes
4103 //=======================================================================
4105 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
4108 SMESH::ElementType type)
4110 SMESH::long_array_var res = new SMESH::long_array;
4111 vector< const SMDS_MeshElement* > foundElems;
4113 theSearchersDeleter.Set( myMesh );
4114 if ( !theElementSearcher ) {
4115 ::SMESH_MeshEditor anEditor( myMesh );
4116 theElementSearcher = anEditor.GetElementSearcher();
4118 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
4119 SMDSAbs_ElementType( type ),
4121 res->length( foundElems.size() );
4122 for ( int i = 0; i < foundElems.size(); ++i )
4123 res[i] = foundElems[i]->GetID();
4125 if ( !myPreviewMode ) // call from tui
4126 TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
4135 //=======================================================================
4136 //function : GetPointState
4137 //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
4138 // TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
4139 //=======================================================================
4141 CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
4145 theSearchersDeleter.Set( myMesh );
4146 if ( !theElementSearcher ) {
4147 ::SMESH_MeshEditor anEditor( myMesh );
4148 theElementSearcher = anEditor.GetElementSearcher();
4150 return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
4153 //=======================================================================
4154 //function : convError
4156 //=======================================================================
4158 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
4160 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
4164 RETCASE( SEW_BORDER1_NOT_FOUND );
4165 RETCASE( SEW_BORDER2_NOT_FOUND );
4166 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
4167 RETCASE( SEW_BAD_SIDE_NODES );
4168 RETCASE( SEW_VOLUMES_TO_SPLIT );
4169 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
4170 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
4171 RETCASE( SEW_BAD_SIDE1_NODES );
4172 RETCASE( SEW_BAD_SIDE2_NODES );
4174 return SMESH::SMESH_MeshEditor::SEW_OK;
4177 //=======================================================================
4178 //function : SewFreeBorders
4180 //=======================================================================
4182 SMESH::SMESH_MeshEditor::Sew_Error
4183 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
4184 CORBA::Long SecondNodeID1,
4185 CORBA::Long LastNodeID1,
4186 CORBA::Long FirstNodeID2,
4187 CORBA::Long SecondNodeID2,
4188 CORBA::Long LastNodeID2,
4189 CORBA::Boolean CreatePolygons,
4190 CORBA::Boolean CreatePolyedrs)
4194 SMESHDS_Mesh* aMesh = GetMeshDS();
4196 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4197 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4198 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4199 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4200 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4201 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
4203 if (!aBorderFirstNode ||
4204 !aBorderSecondNode||
4206 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4207 if (!aSide2FirstNode ||
4208 !aSide2SecondNode ||
4210 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4212 TPythonDump() << "error = " << this << ".SewFreeBorders( "
4213 << FirstNodeID1 << ", "
4214 << SecondNodeID1 << ", "
4215 << LastNodeID1 << ", "
4216 << FirstNodeID2 << ", "
4217 << SecondNodeID2 << ", "
4218 << LastNodeID2 << ", "
4219 << CreatePolygons<< ", "
4220 << CreatePolyedrs<< " )";
4222 ::SMESH_MeshEditor anEditor( myMesh );
4223 SMESH::SMESH_MeshEditor::Sew_Error error =
4224 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4234 storeResult(anEditor);
4236 myMesh->GetMeshDS()->Modified();
4237 myMesh->SetIsModified( true );
4243 //=======================================================================
4244 //function : SewConformFreeBorders
4246 //=======================================================================
4248 SMESH::SMESH_MeshEditor::Sew_Error
4249 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
4250 CORBA::Long SecondNodeID1,
4251 CORBA::Long LastNodeID1,
4252 CORBA::Long FirstNodeID2,
4253 CORBA::Long SecondNodeID2)
4257 SMESHDS_Mesh* aMesh = GetMeshDS();
4259 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4260 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4261 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4262 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4263 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4264 const SMDS_MeshNode* aSide2ThirdNode = 0;
4266 if (!aBorderFirstNode ||
4267 !aBorderSecondNode||
4269 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4270 if (!aSide2FirstNode ||
4272 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4274 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
4275 << FirstNodeID1 << ", "
4276 << SecondNodeID1 << ", "
4277 << LastNodeID1 << ", "
4278 << FirstNodeID2 << ", "
4279 << SecondNodeID2 << " )";
4281 ::SMESH_MeshEditor anEditor( myMesh );
4282 SMESH::SMESH_MeshEditor::Sew_Error error =
4283 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4292 storeResult(anEditor);
4294 myMesh->GetMeshDS()->Modified();
4295 myMesh->SetIsModified( true );
4301 //=======================================================================
4302 //function : SewBorderToSide
4304 //=======================================================================
4306 SMESH::SMESH_MeshEditor::Sew_Error
4307 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
4308 CORBA::Long SecondNodeIDOnFreeBorder,
4309 CORBA::Long LastNodeIDOnFreeBorder,
4310 CORBA::Long FirstNodeIDOnSide,
4311 CORBA::Long LastNodeIDOnSide,
4312 CORBA::Boolean CreatePolygons,
4313 CORBA::Boolean CreatePolyedrs)
4317 SMESHDS_Mesh* aMesh = GetMeshDS();
4319 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
4320 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
4321 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
4322 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
4323 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
4324 const SMDS_MeshNode* aSide2ThirdNode = 0;
4326 if (!aBorderFirstNode ||
4327 !aBorderSecondNode||
4329 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4330 if (!aSide2FirstNode ||
4332 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
4334 TPythonDump() << "error = " << this << ".SewBorderToSide( "
4335 << FirstNodeIDOnFreeBorder << ", "
4336 << SecondNodeIDOnFreeBorder << ", "
4337 << LastNodeIDOnFreeBorder << ", "
4338 << FirstNodeIDOnSide << ", "
4339 << LastNodeIDOnSide << ", "
4340 << CreatePolygons << ", "
4341 << CreatePolyedrs << ") ";
4343 ::SMESH_MeshEditor anEditor( myMesh );
4344 SMESH::SMESH_MeshEditor::Sew_Error error =
4345 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4355 storeResult(anEditor);
4357 myMesh->GetMeshDS()->Modified();
4358 myMesh->SetIsModified( true );
4364 //=======================================================================
4365 //function : SewSideElements
4367 //=======================================================================
4369 SMESH::SMESH_MeshEditor::Sew_Error
4370 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
4371 const SMESH::long_array& IDsOfSide2Elements,
4372 CORBA::Long NodeID1OfSide1ToMerge,
4373 CORBA::Long NodeID1OfSide2ToMerge,
4374 CORBA::Long NodeID2OfSide1ToMerge,
4375 CORBA::Long NodeID2OfSide2ToMerge)
4379 SMESHDS_Mesh* aMesh = GetMeshDS();
4381 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
4382 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
4383 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
4384 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
4386 if (!aFirstNode1ToMerge ||
4387 !aFirstNode2ToMerge )
4388 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
4389 if (!aSecondNode1ToMerge||
4390 !aSecondNode2ToMerge)
4391 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
4393 TIDSortedElemSet aSide1Elems, aSide2Elems;
4394 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
4395 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
4397 TPythonDump() << "error = " << this << ".SewSideElements( "
4398 << IDsOfSide1Elements << ", "
4399 << IDsOfSide2Elements << ", "
4400 << NodeID1OfSide1ToMerge << ", "
4401 << NodeID1OfSide2ToMerge << ", "
4402 << NodeID2OfSide1ToMerge << ", "
4403 << NodeID2OfSide2ToMerge << ")";
4405 ::SMESH_MeshEditor anEditor( myMesh );
4406 SMESH::SMESH_MeshEditor::Sew_Error error =
4407 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
4410 aSecondNode1ToMerge,
4411 aSecondNode2ToMerge));
4413 storeResult(anEditor);
4415 myMesh->GetMeshDS()->Modified();
4416 myMesh->SetIsModified( true );
4421 //================================================================================
4423 * \brief Set new nodes for given element
4424 * \param ide - element id
4425 * \param newIDs - new node ids
4426 * \retval CORBA::Boolean - true if result is OK
4428 //================================================================================
4430 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
4431 const SMESH::long_array& newIDs)
4435 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
4436 if(!elem) return false;
4438 int nbn = newIDs.length();
4440 vector<const SMDS_MeshNode*> aNodes(nbn);
4443 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
4446 aNodes[nbn1] = aNode;
4449 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
4450 << ide << ", " << newIDs << " )";
4452 MESSAGE("ChangeElementNodes");
4453 bool res = GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
4455 myMesh->GetMeshDS()->Modified();
4457 myMesh->SetIsModified( true );
4462 //================================================================================
4464 * \brief Update myLastCreated* or myPreviewData
4465 * \param anEditor - it contains last modification results
4467 //================================================================================
4469 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
4471 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
4473 list<int> aNodesConnectivity;
4474 typedef map<int, int> TNodesMap;
4477 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
4478 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
4480 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
4481 int nbEdges = aMeshDS->NbEdges();
4482 int nbFaces = aMeshDS->NbFaces();
4483 int nbVolum = aMeshDS->NbVolumes();
4484 switch ( previewType ) {
4485 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
4486 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
4487 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
4490 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
4491 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
4493 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
4495 while ( itMeshElems->more() ) {
4496 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
4497 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
4500 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
4501 while ( itElemNodes->more() ) {
4502 const SMDS_MeshNode* aMeshNode =
4503 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
4504 int aNodeID = aMeshNode->GetID();
4505 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
4506 if ( anIter == nodesMap.end() ) {
4507 // filling the nodes coordinates
4508 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
4509 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
4510 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
4511 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4514 aNodesConnectivity.push_back(anIter->second);
4517 // filling the elements types
4518 SMDSAbs_ElementType aType;
4520 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4521 aType = SMDSAbs_Node;
4525 aType = aMeshElem->GetType();
4526 isPoly = aMeshElem->IsPoly();
4529 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4530 myPreviewData->elementTypes[i].isPoly = isPoly;
4531 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4535 myPreviewData->nodesXYZ.length( j );
4537 // filling the elements connectivities
4538 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4539 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4540 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4541 myPreviewData->elementConnectivities[i] = *aConnIter;
4547 // add new nodes into myLastCreatedNodes
4548 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4549 myLastCreatedNodes->length(aSeq.Length());
4550 for(int i=0; i<aSeq.Length(); i++)
4551 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4554 // add new elements into myLastCreatedElems
4555 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4556 myLastCreatedElems->length(aSeq.Length());
4557 for(int i=0; i<aSeq.Length(); i++)
4558 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4562 //================================================================================
4564 * Return data of mesh edition preview
4566 //================================================================================
4568 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4570 return myPreviewData._retn();
4573 //================================================================================
4575 * \brief Returns list of it's IDs of created nodes
4576 * \retval SMESH::long_array* - list of node ID
4578 //================================================================================
4580 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4582 return myLastCreatedNodes._retn();
4585 //================================================================================
4587 * \brief Returns list of it's IDs of created elements
4588 * \retval SMESH::long_array* - list of elements' ID
4590 //================================================================================
4592 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4594 return myLastCreatedElems._retn();
4597 //=======================================================================
4598 //function : ConvertToQuadratic
4600 //=======================================================================
4602 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4604 ::SMESH_MeshEditor anEditor( myMesh );
4605 anEditor.ConvertToQuadratic(theForce3d);
4606 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4607 myMesh->GetMeshDS()->Modified();
4608 myMesh->SetIsModified( true );
4611 //=======================================================================
4612 //function : ConvertFromQuadratic
4614 //=======================================================================
4616 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4618 ::SMESH_MeshEditor anEditor( myMesh );
4619 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4620 TPythonDump() << this << ".ConvertFromQuadratic()";
4621 myMesh->GetMeshDS()->Modified();
4623 myMesh->SetIsModified( true );
4627 //=======================================================================
4628 //function : makeMesh
4629 //purpose : create a named imported mesh
4630 //=======================================================================
4632 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4634 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4635 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4636 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4637 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4638 gen->SetName( meshSO, theMeshName, "Mesh" );
4639 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4641 return mesh._retn();
4644 //=======================================================================
4645 //function : DumpGroupsList
4647 //=======================================================================
4648 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4649 const SMESH::ListOfGroups * theGroupList)
4651 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4652 if(isDumpGroupList) {
4653 theDumpPython << theGroupList << " = ";
4657 //================================================================================
4659 \brief Generates the unique group name.
4660 \param thePrefix name prefix
4663 //================================================================================
4664 string SMESH_MeshEditor_i::generateGroupName(const string& thePrefix)
4666 SMESH::ListOfGroups_var groups = myMesh_i->GetGroups();
4667 set<string> groupNames;
4669 // Get existing group names
4670 for (int i = 0, nbGroups = groups->length(); i < nbGroups; i++ ) {
4671 SMESH::SMESH_GroupBase_var aGroup = groups[i];
4672 if (CORBA::is_nil(aGroup))
4675 groupNames.insert(aGroup->GetName());
4679 string name = thePrefix;
4682 while (!groupNames.insert(name).second) {
4687 TCollection_AsciiString nbStr(index+1);
4688 name.resize( name.rfind('_')+1 );
4689 name += nbStr.ToCString();
4697 //================================================================================
4699 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4700 \param theNodes - identifiers of nodes to be doubled
4701 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4702 nodes. If list of element identifiers is empty then nodes are doubled but
4703 they not assigned to elements
4704 \return TRUE if operation has been completed successfully, FALSE otherwise
4705 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4707 //================================================================================
4709 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4710 const SMESH::long_array& theModifiedElems )
4714 ::SMESH_MeshEditor aMeshEditor( myMesh );
4715 list< int > aListOfNodes;
4717 for ( i = 0, n = theNodes.length(); i < n; i++ )
4718 aListOfNodes.push_back( theNodes[ i ] );
4720 list< int > aListOfElems;
4721 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4722 aListOfElems.push_back( theModifiedElems[ i ] );
4724 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4726 myMesh->GetMeshDS()->Modified();
4727 storeResult( aMeshEditor) ;
4729 myMesh->SetIsModified( true );
4731 // Update Python script
4732 TPythonDump() << this << ".DoubleNodes( " << theNodes << ", "<< theModifiedElems << " )";
4737 //================================================================================
4739 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4740 This method provided for convenience works as DoubleNodes() described above.
4741 \param theNodeId - identifier of node to be doubled.
4742 \param theModifiedElems - identifiers of elements to be updated.
4743 \return TRUE if operation has been completed successfully, FALSE otherwise
4744 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4746 //================================================================================
4748 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4749 const SMESH::long_array& theModifiedElems )
4751 SMESH::long_array_var aNodes = new SMESH::long_array;
4752 aNodes->length( 1 );
4753 aNodes[ 0 ] = theNodeId;
4755 TPythonDump pyDump; // suppress dump by the next line
4757 CORBA::Boolean done = DoubleNodes( aNodes, theModifiedElems );
4759 pyDump << this << ".DoubleNode( " << theNodeId << ", " << theModifiedElems << " )";
4764 //================================================================================
4766 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4767 This method provided for convenience works as DoubleNodes() described above.
4768 \param theNodes - group of nodes to be doubled.
4769 \param theModifiedElems - group of elements to be updated.
4770 \return TRUE if operation has been completed successfully, FALSE otherwise
4771 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
4773 //================================================================================
4775 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(SMESH::SMESH_GroupBase_ptr theNodes,
4776 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4778 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4781 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4782 SMESH::long_array_var aModifiedElems;
4783 if ( !CORBA::is_nil( theModifiedElems ) )
4784 aModifiedElems = theModifiedElems->GetListOfID();
4787 aModifiedElems = new SMESH::long_array;
4788 aModifiedElems->length( 0 );
4791 TPythonDump pyDump; // suppress dump by the next line
4793 bool done = DoubleNodes( aNodes, aModifiedElems );
4795 pyDump << this << ".DoubleNodeGroup( " << theNodes << ", " << theModifiedElems << " )";
4801 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements.
4802 * Works as DoubleNodeGroup(), but returns a new group with newly created nodes.
4803 * \param theNodes - group of nodes to be doubled.
4804 * \param theModifiedElems - group of elements to be updated.
4805 * \return a new group with newly created nodes
4806 * \sa DoubleNodeGroup()
4808 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes,
4809 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4811 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4814 SMESH::SMESH_Group_var aNewGroup;
4817 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4818 SMESH::long_array_var aModifiedElems;
4819 if ( !CORBA::is_nil( theModifiedElems ) )
4820 aModifiedElems = theModifiedElems->GetListOfID();
4822 aModifiedElems = new SMESH::long_array;
4823 aModifiedElems->length( 0 );
4826 TPythonDump pyDump; // suppress dump by the next line
4828 bool aResult = DoubleNodes( aNodes, aModifiedElems );
4832 // Create group with newly created nodes
4833 SMESH::long_array_var anIds = GetLastCreatedNodes();
4834 if (anIds->length() > 0) {
4835 string anUnindexedName (theNodes->GetName());
4836 string aNewName = generateGroupName(anUnindexedName + "_double");
4837 aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
4838 aNewGroup->Add(anIds);
4842 pyDump << "createdNodes = " << this << ".DoubleNodeGroupNew( " << theNodes << ", "
4843 << theModifiedElems << " )";
4845 return aNewGroup._retn();
4848 //================================================================================
4850 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4851 This method provided for convenience works as DoubleNodes() described above.
4852 \param theNodes - list of groups of nodes to be doubled
4853 \param theModifiedElems - list of groups of elements to be updated.
4854 \return TRUE if operation has been completed successfully, FALSE otherwise
4855 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
4857 //================================================================================
4859 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& theNodes,
4860 const SMESH::ListOfGroups& theModifiedElems )
4864 ::SMESH_MeshEditor aMeshEditor( myMesh );
4866 std::list< int > aNodes;
4868 for ( i = 0, n = theNodes.length(); i < n; i++ )
4870 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
4871 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
4873 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4874 for ( j = 0, m = aCurr->length(); j < m; j++ )
4875 aNodes.push_back( aCurr[ j ] );
4879 std::list< int > anElems;
4880 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4882 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
4883 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
4885 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4886 for ( j = 0, m = aCurr->length(); j < m; j++ )
4887 anElems.push_back( aCurr[ j ] );
4891 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
4893 storeResult( aMeshEditor) ;
4895 myMesh->GetMeshDS()->Modified();
4897 myMesh->SetIsModified( true );
4900 TPythonDump() << this << ".DoubleNodeGroups( " << theNodes << ", " << theModifiedElems << " )";
4905 //================================================================================
4907 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4908 \param theElems - the list of elements (edges or faces) to be replicated
4909 The nodes for duplication could be found from these elements
4910 \param theNodesNot - list of nodes to NOT replicate
4911 \param theAffectedElems - the list of elements (cells and edges) to which the
4912 replicated nodes should be associated to.
4913 \return TRUE if operation has been completed successfully, FALSE otherwise
4914 \sa DoubleNodeGroup(), DoubleNodeGroups()
4916 //================================================================================
4918 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
4919 const SMESH::long_array& theNodesNot,
4920 const SMESH::long_array& theAffectedElems )
4925 ::SMESH_MeshEditor aMeshEditor( myMesh );
4927 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4928 TIDSortedElemSet anElems, aNodes, anAffected;
4929 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4930 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4931 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
4933 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4935 storeResult( aMeshEditor) ;
4937 myMesh->GetMeshDS()->Modified();
4939 myMesh->SetIsModified( true );
4941 // Update Python script
4942 TPythonDump() << this << ".DoubleNodeElem( " << theElems << ", "
4943 << theNodesNot << ", " << theAffectedElems << " )";
4947 //================================================================================
4949 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4950 \param theElems - the list of elements (edges or faces) to be replicated
4951 The nodes for duplication could be found from these elements
4952 \param theNodesNot - list of nodes to NOT replicate
4953 \param theShape - shape to detect affected elements (element which geometric center
4954 located on or inside shape).
4955 The replicated nodes should be associated to affected elements.
4956 \return TRUE if operation has been completed successfully, FALSE otherwise
4957 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
4959 //================================================================================
4961 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_array& theElems,
4962 const SMESH::long_array& theNodesNot,
4963 GEOM::GEOM_Object_ptr theShape )
4968 ::SMESH_MeshEditor aMeshEditor( myMesh );
4970 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4971 TIDSortedElemSet anElems, aNodes;
4972 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4973 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4975 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4976 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4978 storeResult( aMeshEditor) ;
4980 myMesh->GetMeshDS()->Modified();
4982 myMesh->SetIsModified( true );
4984 // Update Python script
4985 TPythonDump() << "isDone = " << this << ".DoubleNodeElemInRegion( " << theElems << ", "
4986 << theNodesNot << ", " << theShape << " )";
4990 //================================================================================
4992 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4993 \param theElems - group of of elements (edges or faces) to be replicated
4994 \param theNodesNot - group of nodes not to replicated
4995 \param theAffectedElems - group of elements to which the replicated nodes
4996 should be associated to.
4997 \return TRUE if operation has been completed successfully, FALSE otherwise
4998 \sa DoubleNodes(), DoubleNodeGroups()
5000 //================================================================================
5002 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_ptr theElems,
5003 SMESH::SMESH_GroupBase_ptr theNodesNot,
5004 SMESH::SMESH_GroupBase_ptr theAffectedElems)
5006 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5011 ::SMESH_MeshEditor aMeshEditor( myMesh );
5013 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5014 TIDSortedElemSet anElems, aNodes, anAffected;
5015 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5016 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5017 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
5019 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5021 storeResult( aMeshEditor) ;
5023 myMesh->GetMeshDS()->Modified();
5025 myMesh->SetIsModified( true );
5027 // Update Python script
5028 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroup( " << theElems << ", "
5029 << theNodesNot << ", " << theAffectedElems << " )";
5034 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5035 * Works as DoubleNodeElemGroup(), but returns a new group with newly created elements.
5036 * \param theElems - group of of elements (edges or faces) to be replicated
5037 * \param theNodesNot - group of nodes not to replicated
5038 * \param theAffectedElems - group of elements to which the replicated nodes
5039 * should be associated to.
5040 * \return a new group with newly created elements
5041 * \sa DoubleNodeElemGroup()
5043 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems,
5044 SMESH::SMESH_GroupBase_ptr theNodesNot,
5045 SMESH::SMESH_GroupBase_ptr theAffectedElems)
5047 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5050 SMESH::SMESH_Group_var aNewGroup;
5054 ::SMESH_MeshEditor aMeshEditor( myMesh );
5056 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5057 TIDSortedElemSet anElems, aNodes, anAffected;
5058 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5059 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5060 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
5063 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5065 storeResult( aMeshEditor) ;
5068 myMesh->SetIsModified( true );
5070 // Create group with newly created elements
5071 SMESH::long_array_var anIds = GetLastCreatedElems();
5072 if (anIds->length() > 0) {
5073 SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
5074 string anUnindexedName (theElems->GetName());
5075 string aNewName = generateGroupName(anUnindexedName + "_double");
5076 aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
5077 aNewGroup->Add(anIds);
5081 // Update Python script
5082 TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupNew( " << theElems << ", "
5083 << theNodesNot << ", " << theAffectedElems << " )";
5084 return aNewGroup._retn();
5087 //================================================================================
5089 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5090 \param theElems - group of of elements (edges or faces) to be replicated
5091 \param theNodesNot - group of nodes not to replicated
5092 \param theShape - shape to detect affected elements (element which geometric center
5093 located on or inside shape).
5094 The replicated nodes should be associated to affected elements.
5095 \return TRUE if operation has been completed successfully, FALSE otherwise
5096 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
5098 //================================================================================
5100 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_GroupBase_ptr theElems,
5101 SMESH::SMESH_GroupBase_ptr theNodesNot,
5102 GEOM::GEOM_Object_ptr theShape )
5105 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5110 ::SMESH_MeshEditor aMeshEditor( myMesh );
5112 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5113 TIDSortedElemSet anElems, aNodes, anAffected;
5114 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5115 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5117 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5118 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5120 storeResult( aMeshEditor) ;
5122 myMesh->GetMeshDS()->Modified();
5124 myMesh->SetIsModified( true );
5126 // Update Python script
5127 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupInRegion( " << theElems << ", "
5128 << theNodesNot << ", " << theShape << " )";
5132 //================================================================================
5134 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5135 This method provided for convenience works as DoubleNodes() described above.
5136 \param theElems - list of groups of elements (edges or faces) to be replicated
5137 \param theNodesNot - list of groups of nodes not to replicated
5138 \param theAffectedElems - group of elements to which the replicated nodes
5139 should be associated to.
5140 \return TRUE if operation has been completed successfully, FALSE otherwise
5141 \sa DoubleNodeGroup(), DoubleNodes()
5143 //================================================================================
5145 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
5146 SMESHDS_Mesh* theMeshDS,
5147 TIDSortedElemSet& theElemSet,
5148 const bool theIsNodeGrp)
5150 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
5152 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
5153 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
5154 : aGrp->GetType() != SMESH::NODE ) )
5156 SMESH::long_array_var anIDs = aGrp->GetIDs();
5157 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
5162 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroups& theElems,
5163 const SMESH::ListOfGroups& theNodesNot,
5164 const SMESH::ListOfGroups& theAffectedElems)
5168 ::SMESH_MeshEditor aMeshEditor( myMesh );
5170 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5171 TIDSortedElemSet anElems, aNodes, anAffected;
5172 listOfGroupToSet(theElems, aMeshDS, anElems, false );
5173 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5174 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
5176 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5178 storeResult( aMeshEditor) ;
5180 myMesh->GetMeshDS()->Modified();
5182 myMesh->SetIsModified( true );
5184 // Update Python script
5185 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroups( " << &theElems << ", "
5186 << &theNodesNot << ", " << &theAffectedElems << " )";
5190 //================================================================================
5192 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5193 This method provided for convenience works as DoubleNodes() described above.
5194 \param theElems - list of groups of elements (edges or faces) to be replicated
5195 \param theNodesNot - list of groups of nodes not to replicated
5196 \param theShape - shape to detect affected elements (element which geometric center
5197 located on or inside shape).
5198 The replicated nodes should be associated to affected elements.
5199 \return TRUE if operation has been completed successfully, FALSE otherwise
5200 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
5202 //================================================================================
5205 SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theElems,
5206 const SMESH::ListOfGroups& theNodesNot,
5207 GEOM::GEOM_Object_ptr theShape )
5211 ::SMESH_MeshEditor aMeshEditor( myMesh );
5213 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5214 TIDSortedElemSet anElems, aNodes;
5215 listOfGroupToSet(theElems, aMeshDS, anElems,false );
5216 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5218 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5219 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5221 storeResult( aMeshEditor) ;
5223 myMesh->GetMeshDS()->Modified();
5225 myMesh->SetIsModified( true );
5227 // Update Python script
5228 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupsInRegion( " << &theElems << ", "
5229 << &theNodesNot << ", " << theShape << " )";
5233 //================================================================================
5235 \brief Generated skin mesh (containing 2D cells) from 3D mesh
5236 The created 2D mesh elements based on nodes of free faces of boundary volumes
5237 \return TRUE if operation has been completed successfully, FALSE otherwise
5239 //================================================================================
5241 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
5245 ::SMESH_MeshEditor aMeshEditor( myMesh );
5246 bool aResult = aMeshEditor.Make2DMeshFrom3D();
5247 storeResult( aMeshEditor) ;
5248 myMesh->GetMeshDS()->Modified();
5249 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";
5253 //================================================================================
5255 * \brief Double nodes on shared faces between groups of volumes and create flat elements on demand.
5256 * The list of groups must describe a partition of the mesh volumes.
5257 * The nodes of the internal faces at the boundaries of the groups are doubled.
5258 * In option, the internal faces are replaced by flat elements.
5259 * Triangles are transformed in prisms, and quadrangles in hexahedrons.
5260 * @param theDomains - list of groups of volumes
5261 * @param createJointElems - if TRUE, create the elements
5262 * @return TRUE if operation has been completed successfully, FALSE otherwise
5264 //================================================================================
5266 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::ListOfGroups& theDomains,
5267 CORBA::Boolean createJointElems )
5271 ::SMESH_MeshEditor aMeshEditor( myMesh );
5273 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5275 vector<TIDSortedElemSet> domains;
5278 for ( int i = 0, n = theDomains.length(); i < n; i++ )
5280 SMESH::SMESH_GroupBase_var aGrp = theDomains[ i ];
5281 if ( !CORBA::is_nil( aGrp ) && ( aGrp->GetType() != SMESH::NODE ) )
5283 TIDSortedElemSet domain;
5285 domains.push_back(domain);
5286 SMESH::long_array_var anIDs = aGrp->GetIDs();
5287 arrayToSet( anIDs, aMeshDS, domains[ i ], SMDSAbs_All );
5291 bool aResult = aMeshEditor.DoubleNodesOnGroupBoundaries( domains, createJointElems );
5293 storeResult( aMeshEditor) ;
5294 myMesh->GetMeshDS()->Modified();
5296 // Update Python script
5297 TPythonDump() << "isDone = " << this << ".DoubleNodesOnGroupBoundaries( " << &theDomains
5298 << ", " << createJointElems << " )";
5302 // issue 20749 ===================================================================
5304 * \brief Creates missing boundary elements
5305 * \param elements - elements whose boundary is to be checked
5306 * \param dimension - defines type of boundary elements to create
5307 * \param groupName - a name of group to store created boundary elements in,
5308 * "" means not to create the group
5309 * \param meshName - a name of new mesh to store created boundary elements in,
5310 * "" means not to create the new mesh
5311 * \param toCopyElements - if true, the checked elements will be copied into the new mesh
5312 * \param toCopyExistingBondary - if true, not only new but also pre-existing
5313 * boundary elements will be copied into the new mesh
5314 * \param group - returns the create group, if any
5315 * \retval SMESH::SMESH_Mesh - the mesh where elements were added to
5317 // ================================================================================
5319 SMESH::SMESH_Mesh_ptr
5320 SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource,
5321 SMESH::Bnd_Dimension dim,
5322 const char* groupName,
5323 const char* meshName,
5324 CORBA::Boolean toCopyElements,
5325 CORBA::Boolean toCopyExistingBondary,
5326 SMESH::SMESH_Group_out group)
5330 if ( dim > SMESH::BND_1DFROM2D )
5331 THROW_SALOME_CORBA_EXCEPTION("Invalid boundary dimension", SALOME::BAD_PARAM);
5334 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5336 SMESH::SMESH_Mesh_var mesh_var;
5337 SMESH::SMESH_Group_var group_var;
5341 TIDSortedElemSet elements;
5342 SMDSAbs_ElementType elemType = (dim == SMESH::BND_1DFROM2D) ? SMDSAbs_Face : SMDSAbs_Volume;
5343 if ( idSourceToSet( idSource, aMeshDS, elements, elemType,/*emptyIfIsMesh=*/true ))
5347 strlen(meshName) ? makeMesh(meshName) : SMESH::SMESH_Mesh::_duplicate(myMesh_i->_this());
5348 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh_var );
5350 SMESH_Mesh* smesh_mesh = (mesh_i==myMesh_i) ? (SMESH_Mesh*)0 : &mesh_i->GetImpl();
5352 // group of new boundary elements
5353 SMESH_Group* smesh_group = 0;
5354 if ( strlen(groupName) )
5356 group_var = mesh_i->CreateGroup( SMESH::ElementType(elemType),groupName);
5357 if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( group_var ))
5358 smesh_group = group_i->GetSmeshGroup();
5362 ::SMESH_MeshEditor aMeshEditor( myMesh );
5363 aMeshEditor.MakeBoundaryMesh( elements,
5364 ::SMESH_MeshEditor::Bnd_Dimension(dim),
5368 toCopyExistingBondary);
5369 storeResult( aMeshEditor );
5372 // result of MakeBoundaryMesh() is a tuple (mesh, group)
5373 if ( mesh_var->_is_nil() )
5374 pyDump << myMesh_i->_this() << ", ";
5376 pyDump << mesh_var << ", ";
5377 if ( group_var->_is_nil() )
5378 pyDump << "_NoneGroup = "; // assignment to None is forbiden
5380 pyDump << group_var << " = ";
5381 pyDump << this << ".MakeBoundaryMesh( "
5384 << groupName << ", "
5386 << toCopyElements << ", "
5387 << toCopyExistingBondary << ")";
5389 group = group_var._retn();
5390 return mesh_var._retn();