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 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2690 SMESH::long_array_var anElementsId = Object->GetIDs();
2691 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2700 (SMDSAbs_ElementType)ElemType,
2703 if (!myPreviewMode) {
2704 bool isDumpGroups = aGroups && aGroups->length() > 0;
2706 aPythonDump << "(" << *aGroups << ", error)";
2708 aPythonDump << "error";
2710 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2713 << NodeStart << ", "
2714 << HasAngles << ", "
2716 << LinearVariation << ", "
2717 << HasRefPoint << ", "
2718 << "SMESH.PointStruct( "
2719 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2720 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2721 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2722 << MakeGroups << ", "
2723 << ElemType << " )";
2729 //=======================================================================
2730 //function : ExtrusionAlongPathX
2732 //=======================================================================
2733 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2734 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2735 SMESH::SMESH_IDSource_ptr Path,
2736 CORBA::Long NodeStart,
2737 CORBA::Boolean HasAngles,
2738 const SMESH::double_array& Angles,
2739 CORBA::Boolean LinearVariation,
2740 CORBA::Boolean HasRefPoint,
2741 const SMESH::PointStruct& RefPoint,
2742 CORBA::Boolean MakeGroups,
2743 SMESH::ElementType ElemType,
2744 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2746 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2748 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2757 (SMDSAbs_ElementType)ElemType,
2760 if (!myPreviewMode) {
2761 bool isDumpGroups = aGroups && aGroups->length() > 0;
2763 aPythonDump << "(" << *aGroups << ", error)";
2765 aPythonDump <<"error";
2767 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2768 << IDsOfElements << ", "
2770 << NodeStart << ", "
2771 << HasAngles << ", "
2773 << LinearVariation << ", "
2774 << HasRefPoint << ", "
2775 << "SMESH.PointStruct( "
2776 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2777 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2778 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2779 << MakeGroups << ", "
2780 << ElemType << " )";
2786 //================================================================================
2788 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2789 * of given angles along path steps
2790 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2791 * which proceeds the extrusion
2792 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2793 * is used to define the sub-mesh for the path
2795 //================================================================================
2797 SMESH::double_array*
2798 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2799 GEOM::GEOM_Object_ptr thePathShape,
2800 const SMESH::double_array & theAngles)
2802 SMESH::double_array_var aResult = new SMESH::double_array();
2803 int nbAngles = theAngles.length();
2804 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2806 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2807 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2808 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2809 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2810 return aResult._retn();
2811 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2812 if ( nbSteps == nbAngles )
2814 aResult.inout() = theAngles;
2818 aResult->length( nbSteps );
2819 double rAn2St = double( nbAngles ) / double( nbSteps );
2820 double angPrev = 0, angle;
2821 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2823 double angCur = rAn2St * ( iSt+1 );
2824 double angCurFloor = floor( angCur );
2825 double angPrevFloor = floor( angPrev );
2826 if ( angPrevFloor == angCurFloor )
2827 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2830 int iP = int( angPrevFloor );
2831 double angPrevCeil = ceil(angPrev);
2832 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2834 int iC = int( angCurFloor );
2835 if ( iC < nbAngles )
2836 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2838 iP = int( angPrevCeil );
2840 angle += theAngles[ iC ];
2842 aResult[ iSt ] = angle;
2847 // Update Python script
2848 TPythonDump() << "rotAngles = " << theAngles;
2849 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2850 << thePathMesh << ", "
2851 << thePathShape << ", "
2854 return aResult._retn();
2858 //=======================================================================
2861 //=======================================================================
2863 SMESH::ListOfGroups*
2864 SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements,
2865 const SMESH::AxisStruct & theAxis,
2866 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2867 CORBA::Boolean theCopy,
2868 const bool theMakeGroups,
2869 ::SMESH_Mesh* theTargetMesh)
2873 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2874 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2877 switch ( theMirrorType ) {
2878 case SMESH::SMESH_MeshEditor::POINT:
2879 aTrsf.SetMirror( P );
2881 case SMESH::SMESH_MeshEditor::AXIS:
2882 aTrsf.SetMirror( gp_Ax1( P, V ));
2885 aTrsf.SetMirror( gp_Ax2( P, V ));
2888 ::SMESH_MeshEditor anEditor( myMesh );
2889 ::SMESH_MeshEditor::PGroupIDs groupIds =
2890 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2893 storeResult(anEditor);
2896 myMesh->GetMeshDS()->Modified();
2897 myMesh->SetIsModified( true );
2900 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2903 //=======================================================================
2906 //=======================================================================
2908 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2909 const SMESH::AxisStruct & theAxis,
2910 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2911 CORBA::Boolean theCopy)
2913 if ( !myPreviewMode ) {
2914 TPythonDump() << this << ".Mirror( "
2915 << theIDsOfElements << ", "
2917 << mirrorTypeName(theMirrorType) << ", "
2920 if ( theIDsOfElements.length() > 0 )
2922 TIDSortedElemSet elements;
2923 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2924 mirror(elements, theAxis, theMirrorType, theCopy, false);
2929 //=======================================================================
2930 //function : MirrorObject
2932 //=======================================================================
2934 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2935 const SMESH::AxisStruct & theAxis,
2936 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2937 CORBA::Boolean theCopy)
2939 if ( !myPreviewMode ) {
2940 TPythonDump() << this << ".MirrorObject( "
2941 << theObject << ", "
2943 << mirrorTypeName(theMirrorType) << ", "
2946 TIDSortedElemSet elements;
2947 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2948 mirror(elements, theAxis, theMirrorType, theCopy, false);
2951 //=======================================================================
2952 //function : MirrorMakeGroups
2954 //=======================================================================
2956 SMESH::ListOfGroups*
2957 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2958 const SMESH::AxisStruct& theMirror,
2959 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2961 SMESH::ListOfGroups * aGroups = 0;
2962 if ( theIDsOfElements.length() > 0 )
2964 TIDSortedElemSet elements;
2965 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2966 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2968 if ( !myPreviewMode ) {
2969 TPythonDump aPythonDump;
2970 DumpGroupsList(aPythonDump,aGroups);
2971 aPythonDump << this << ".MirrorMakeGroups( "
2972 << theIDsOfElements << ", "
2973 << theMirror << ", "
2974 << mirrorTypeName(theMirrorType) << " )";
2979 //=======================================================================
2980 //function : MirrorObjectMakeGroups
2982 //=======================================================================
2984 SMESH::ListOfGroups*
2985 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2986 const SMESH::AxisStruct& theMirror,
2987 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2989 SMESH::ListOfGroups * aGroups = 0;
2990 TIDSortedElemSet elements;
2991 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2992 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2994 if ( !myPreviewMode )
2996 TPythonDump aPythonDump;
2997 DumpGroupsList(aPythonDump,aGroups);
2998 aPythonDump << this << ".MirrorObjectMakeGroups( "
2999 << theObject << ", "
3000 << theMirror << ", "
3001 << mirrorTypeName(theMirrorType) << " )";
3006 //=======================================================================
3007 //function : MirrorMakeMesh
3009 //=======================================================================
3011 SMESH::SMESH_Mesh_ptr
3012 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
3013 const SMESH::AxisStruct& theMirror,
3014 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3015 CORBA::Boolean theCopyGroups,
3016 const char* theMeshName)
3018 SMESH_Mesh_i* mesh_i;
3019 SMESH::SMESH_Mesh_var mesh;
3020 { // open new scope to dump "MakeMesh" command
3021 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3023 TPythonDump pydump; // to prevent dump at mesh creation
3025 mesh = makeMesh( theMeshName );
3026 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3027 if (mesh_i && theIDsOfElements.length() > 0 )
3029 TIDSortedElemSet elements;
3030 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3031 mirror(elements, theMirror, theMirrorType,
3032 false, theCopyGroups, & mesh_i->GetImpl());
3033 mesh_i->CreateGroupServants();
3036 if ( !myPreviewMode ) {
3037 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
3038 << theIDsOfElements << ", "
3039 << theMirror << ", "
3040 << mirrorTypeName(theMirrorType) << ", "
3041 << theCopyGroups << ", '"
3042 << theMeshName << "' )";
3047 if(!myPreviewMode && mesh_i)
3048 mesh_i->GetGroups();
3050 return mesh._retn();
3053 //=======================================================================
3054 //function : MirrorObjectMakeMesh
3056 //=======================================================================
3058 SMESH::SMESH_Mesh_ptr
3059 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3060 const SMESH::AxisStruct& theMirror,
3061 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3062 CORBA::Boolean theCopyGroups,
3063 const char* theMeshName)
3065 SMESH_Mesh_i* mesh_i;
3066 SMESH::SMESH_Mesh_var mesh;
3067 { // open new scope to dump "MakeMesh" command
3068 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3070 TPythonDump pydump; // to prevent dump at mesh creation
3072 mesh = makeMesh( theMeshName );
3073 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3074 TIDSortedElemSet elements;
3076 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3078 mirror(elements, theMirror, theMirrorType,
3079 false, theCopyGroups, & mesh_i->GetImpl());
3080 mesh_i->CreateGroupServants();
3082 if ( !myPreviewMode ) {
3083 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
3084 << theObject << ", "
3085 << theMirror << ", "
3086 << mirrorTypeName(theMirrorType) << ", "
3087 << theCopyGroups << ", '"
3088 << theMeshName << "' )";
3093 if(!myPreviewMode && mesh_i)
3094 mesh_i->GetGroups();
3096 return mesh._retn();
3099 //=======================================================================
3100 //function : translate
3102 //=======================================================================
3104 SMESH::ListOfGroups*
3105 SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements,
3106 const SMESH::DirStruct & theVector,
3107 CORBA::Boolean theCopy,
3108 const bool theMakeGroups,
3109 ::SMESH_Mesh* theTargetMesh)
3114 const SMESH::PointStruct * P = &theVector.PS;
3115 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
3117 ::SMESH_MeshEditor anEditor( myMesh );
3118 ::SMESH_MeshEditor::PGroupIDs groupIds =
3119 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3122 storeResult(anEditor);
3125 myMesh->GetMeshDS()->Modified();
3126 myMesh->SetIsModified( true );
3129 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3132 //=======================================================================
3133 //function : Translate
3135 //=======================================================================
3137 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
3138 const SMESH::DirStruct & theVector,
3139 CORBA::Boolean theCopy)
3141 if ( !myPreviewMode ) {
3142 TPythonDump() << this << ".Translate( "
3143 << theIDsOfElements << ", "
3144 << theVector << ", "
3147 if ( theIDsOfElements.length() )
3149 TIDSortedElemSet elements;
3150 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3151 translate(elements,theVector,theCopy,false);
3155 //=======================================================================
3156 //function : TranslateObject
3158 //=======================================================================
3160 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
3161 const SMESH::DirStruct & theVector,
3162 CORBA::Boolean theCopy)
3164 if ( !myPreviewMode ) {
3165 TPythonDump() << this << ".TranslateObject( "
3166 << theObject << ", "
3167 << theVector << ", "
3170 TIDSortedElemSet elements;
3171 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3172 translate( elements, theVector, theCopy, false);
3175 //=======================================================================
3176 //function : TranslateMakeGroups
3178 //=======================================================================
3180 SMESH::ListOfGroups*
3181 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
3182 const SMESH::DirStruct& theVector)
3184 SMESH::ListOfGroups * aGroups = 0;
3185 if ( theIDsOfElements.length() )
3187 TIDSortedElemSet elements;
3188 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3189 aGroups = translate(elements,theVector,true,true);
3191 if ( !myPreviewMode ) {
3192 TPythonDump aPythonDump;
3193 DumpGroupsList(aPythonDump,aGroups);
3194 aPythonDump << this << ".TranslateMakeGroups( "
3195 << theIDsOfElements << ", "
3196 << theVector << " )";
3201 //=======================================================================
3202 //function : TranslateObjectMakeGroups
3204 //=======================================================================
3206 SMESH::ListOfGroups*
3207 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3208 const SMESH::DirStruct& theVector)
3210 SMESH::ListOfGroups * aGroups = 0;
3211 TIDSortedElemSet elements;
3212 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3213 aGroups = translate(elements, theVector, true, true);
3215 if ( !myPreviewMode ) {
3217 TPythonDump aPythonDump;
3218 DumpGroupsList(aPythonDump,aGroups);
3219 aPythonDump << this << ".TranslateObjectMakeGroups( "
3220 << theObject << ", "
3221 << theVector << " )";
3226 //=======================================================================
3227 //function : TranslateMakeMesh
3229 //=======================================================================
3231 SMESH::SMESH_Mesh_ptr
3232 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3233 const SMESH::DirStruct& theVector,
3234 CORBA::Boolean theCopyGroups,
3235 const char* theMeshName)
3237 SMESH_Mesh_i* mesh_i;
3238 SMESH::SMESH_Mesh_var mesh;
3240 { // open new scope to dump "MakeMesh" command
3241 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3243 TPythonDump pydump; // to prevent dump at mesh creation
3245 mesh = makeMesh( theMeshName );
3246 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3248 if ( mesh_i && theIDsOfElements.length() )
3250 TIDSortedElemSet elements;
3251 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3252 translate(elements, theVector, false, theCopyGroups, & mesh_i->GetImpl());
3253 mesh_i->CreateGroupServants();
3256 if ( !myPreviewMode ) {
3257 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3258 << theIDsOfElements << ", "
3259 << theVector << ", "
3260 << theCopyGroups << ", '"
3261 << theMeshName << "' )";
3266 if(!myPreviewMode && mesh_i)
3267 mesh_i->GetGroups();
3269 return mesh._retn();
3272 //=======================================================================
3273 //function : TranslateObjectMakeMesh
3275 //=======================================================================
3277 SMESH::SMESH_Mesh_ptr
3278 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3279 const SMESH::DirStruct& theVector,
3280 CORBA::Boolean theCopyGroups,
3281 const char* theMeshName)
3283 SMESH_Mesh_i* mesh_i;
3284 SMESH::SMESH_Mesh_var mesh;
3285 { // open new scope to dump "MakeMesh" command
3286 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3288 TPythonDump pydump; // to prevent dump at mesh creation
3289 mesh = makeMesh( theMeshName );
3290 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3292 TIDSortedElemSet elements;
3294 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3296 translate(elements, theVector,false, theCopyGroups, & mesh_i->GetImpl());
3297 mesh_i->CreateGroupServants();
3299 if ( !myPreviewMode ) {
3300 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3301 << theObject << ", "
3302 << theVector << ", "
3303 << theCopyGroups << ", '"
3304 << theMeshName << "' )";
3309 if(!myPreviewMode && mesh_i)
3310 mesh_i->GetGroups();
3312 return mesh._retn();
3315 //=======================================================================
3318 //=======================================================================
3320 SMESH::ListOfGroups*
3321 SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements,
3322 const SMESH::AxisStruct & theAxis,
3323 CORBA::Double theAngle,
3324 CORBA::Boolean theCopy,
3325 const bool theMakeGroups,
3326 ::SMESH_Mesh* theTargetMesh)
3330 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3331 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3334 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3336 ::SMESH_MeshEditor anEditor( myMesh );
3337 ::SMESH_MeshEditor::PGroupIDs groupIds =
3338 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3341 storeResult(anEditor);
3344 myMesh->GetMeshDS()->Modified();
3345 myMesh->SetIsModified( true );
3348 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3351 //=======================================================================
3354 //=======================================================================
3356 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3357 const SMESH::AxisStruct & theAxis,
3358 CORBA::Double theAngle,
3359 CORBA::Boolean theCopy)
3361 if ( !myPreviewMode ) {
3362 TPythonDump() << this << ".Rotate( "
3363 << theIDsOfElements << ", "
3368 if ( theIDsOfElements.length() > 0 )
3370 TIDSortedElemSet elements;
3371 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3372 rotate(elements,theAxis,theAngle,theCopy,false);
3376 //=======================================================================
3377 //function : RotateObject
3379 //=======================================================================
3381 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3382 const SMESH::AxisStruct & theAxis,
3383 CORBA::Double theAngle,
3384 CORBA::Boolean theCopy)
3386 if ( !myPreviewMode ) {
3387 TPythonDump() << this << ".RotateObject( "
3388 << theObject << ", "
3393 TIDSortedElemSet elements;
3394 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3395 rotate(elements,theAxis,theAngle,theCopy,false);
3398 //=======================================================================
3399 //function : RotateMakeGroups
3401 //=======================================================================
3403 SMESH::ListOfGroups*
3404 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3405 const SMESH::AxisStruct& theAxis,
3406 CORBA::Double theAngle)
3408 SMESH::ListOfGroups * aGroups = 0;
3409 if ( theIDsOfElements.length() > 0 )
3411 TIDSortedElemSet elements;
3412 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3413 aGroups = rotate(elements,theAxis,theAngle,true,true);
3415 if ( !myPreviewMode ) {
3416 TPythonDump aPythonDump;
3417 DumpGroupsList(aPythonDump,aGroups);
3418 aPythonDump << this << ".RotateMakeGroups( "
3419 << theIDsOfElements << ", "
3421 << theAngle << " )";
3426 //=======================================================================
3427 //function : RotateObjectMakeGroups
3429 //=======================================================================
3431 SMESH::ListOfGroups*
3432 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3433 const SMESH::AxisStruct& theAxis,
3434 CORBA::Double theAngle)
3436 SMESH::ListOfGroups * aGroups = 0;
3437 TIDSortedElemSet elements;
3438 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3439 aGroups = rotate(elements,theAxis,theAngle,true,true);
3441 if ( !myPreviewMode ) {
3442 TPythonDump aPythonDump;
3443 DumpGroupsList(aPythonDump,aGroups);
3444 aPythonDump << this << ".RotateObjectMakeGroups( "
3445 << theObject << ", "
3447 << theAngle << " )";
3452 //=======================================================================
3453 //function : RotateMakeMesh
3455 //=======================================================================
3457 SMESH::SMESH_Mesh_ptr
3458 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3459 const SMESH::AxisStruct& theAxis,
3460 CORBA::Double theAngleInRadians,
3461 CORBA::Boolean theCopyGroups,
3462 const char* theMeshName)
3464 SMESH::SMESH_Mesh_var mesh;
3465 SMESH_Mesh_i* mesh_i;
3467 { // open new scope to dump "MakeMesh" command
3468 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3470 TPythonDump pydump; // to prevent dump at mesh creation
3472 mesh = makeMesh( theMeshName );
3473 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3475 if ( mesh_i && theIDsOfElements.length() > 0 )
3477 TIDSortedElemSet elements;
3478 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3479 rotate(elements, theAxis, theAngleInRadians,
3480 false, theCopyGroups, & mesh_i->GetImpl());
3481 mesh_i->CreateGroupServants();
3483 if ( !myPreviewMode ) {
3484 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3485 << theIDsOfElements << ", "
3487 << theAngleInRadians << ", "
3488 << theCopyGroups << ", '"
3489 << theMeshName << "' )";
3494 if(!myPreviewMode && mesh_i && theIDsOfElements.length() > 0 )
3495 mesh_i->GetGroups();
3497 return mesh._retn();
3500 //=======================================================================
3501 //function : RotateObjectMakeMesh
3503 //=======================================================================
3505 SMESH::SMESH_Mesh_ptr
3506 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3507 const SMESH::AxisStruct& theAxis,
3508 CORBA::Double theAngleInRadians,
3509 CORBA::Boolean theCopyGroups,
3510 const char* theMeshName)
3512 SMESH::SMESH_Mesh_var mesh;
3513 SMESH_Mesh_i* mesh_i;
3515 {// open new scope to dump "MakeMesh" command
3516 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3518 TPythonDump pydump; // to prevent dump at mesh creation
3519 mesh = makeMesh( theMeshName );
3520 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3522 TIDSortedElemSet elements;
3524 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3526 rotate(elements, theAxis, theAngleInRadians,
3527 false, theCopyGroups, & mesh_i->GetImpl());
3528 mesh_i->CreateGroupServants();
3530 if ( !myPreviewMode ) {
3531 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3532 << theObject << ", "
3534 << theAngleInRadians << ", "
3535 << theCopyGroups << ", '"
3536 << theMeshName << "' )";
3541 if(!myPreviewMode && mesh_i)
3542 mesh_i->GetGroups();
3544 return mesh._retn();
3547 //=======================================================================
3550 //=======================================================================
3552 SMESH::ListOfGroups*
3553 SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject,
3554 const SMESH::PointStruct& thePoint,
3555 const SMESH::double_array& theScaleFact,
3556 CORBA::Boolean theCopy,
3557 const bool theMakeGroups,
3558 ::SMESH_Mesh* theTargetMesh)
3561 if ( theScaleFact.length() < 1 )
3562 THROW_SALOME_CORBA_EXCEPTION("Scale factor not given", SALOME::BAD_PARAM);
3563 if ( theScaleFact.length() == 2 )
3564 THROW_SALOME_CORBA_EXCEPTION("Invalid nb of scale factors : 2", SALOME::BAD_PARAM);
3566 TIDSortedElemSet elements;
3567 if ( !idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/true))
3570 vector<double> S(3);
3571 S[0] = theScaleFact[0];
3572 S[1] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1];
3573 S[2] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2];
3574 double tol = std::numeric_limits<double>::max();
3576 aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]),
3577 0, S[1], 0, thePoint.y * (1-S[1]),
3578 0, 0, S[2], thePoint.z * (1-S[2]), tol, tol);
3580 ::SMESH_MeshEditor anEditor( myMesh );
3581 ::SMESH_MeshEditor::PGroupIDs groupIds =
3582 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3585 storeResult(anEditor);
3588 myMesh->GetMeshDS()->Modified();
3589 myMesh->SetIsModified( true );
3591 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3594 //=======================================================================
3597 //=======================================================================
3599 void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr theObject,
3600 const SMESH::PointStruct& thePoint,
3601 const SMESH::double_array& theScaleFact,
3602 CORBA::Boolean theCopy)
3604 if ( !myPreviewMode ) {
3605 TPythonDump() << this << ".Scale( "
3606 << theObject << ", "
3607 << "SMESH.PointStruct( " << thePoint.x << ", "
3608 << thePoint.y << ", " << thePoint.z << " ) ,"
3609 << theScaleFact << ", "
3612 scale(theObject, thePoint, theScaleFact, theCopy, false);
3616 //=======================================================================
3617 //function : ScaleMakeGroups
3619 //=======================================================================
3621 SMESH::ListOfGroups*
3622 SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3623 const SMESH::PointStruct& thePoint,
3624 const SMESH::double_array& theScaleFact)
3626 SMESH::ListOfGroups * aGroups = scale(theObject, thePoint, theScaleFact, true, true);
3627 if ( !myPreviewMode ) {
3629 TPythonDump aPythonDump;
3630 DumpGroupsList(aPythonDump,aGroups);
3631 aPythonDump << this << ".Scale("
3633 << "SMESH.PointStruct(" <<thePoint.x << ","
3634 << thePoint.y << "," << thePoint.z << "),"
3635 << theScaleFact << ",True,True)";
3641 //=======================================================================
3642 //function : ScaleMakeMesh
3644 //=======================================================================
3646 SMESH::SMESH_Mesh_ptr
3647 SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3648 const SMESH::PointStruct& thePoint,
3649 const SMESH::double_array& theScaleFact,
3650 CORBA::Boolean theCopyGroups,
3651 const char* theMeshName)
3653 SMESH_Mesh_i* mesh_i;
3654 SMESH::SMESH_Mesh_var mesh;
3655 { // open new scope to dump "MakeMesh" command
3656 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3658 TPythonDump pydump; // to prevent dump at mesh creation
3659 mesh = makeMesh( theMeshName );
3660 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3664 scale(theObject, thePoint, theScaleFact,false, theCopyGroups, & mesh_i->GetImpl());
3665 mesh_i->CreateGroupServants();
3667 if ( !myPreviewMode )
3668 pydump << mesh << " = " << this << ".ScaleMakeMesh( "
3669 << theObject << ", "
3670 << "SMESH.PointStruct( " << thePoint.x << ", "
3671 << thePoint.y << ", " << thePoint.z << " ) ,"
3672 << theScaleFact << ", "
3673 << theCopyGroups << ", '"
3674 << theMeshName << "' )";
3678 if(!myPreviewMode && mesh_i)
3679 mesh_i->GetGroups();
3681 return mesh._retn();
3685 //=======================================================================
3686 //function : FindCoincidentNodes
3688 //=======================================================================
3690 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3691 SMESH::array_of_long_array_out GroupsOfNodes)
3695 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3696 ::SMESH_MeshEditor anEditor( myMesh );
3697 TIDSortedNodeSet nodes; // no input nodes
3698 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3700 GroupsOfNodes = new SMESH::array_of_long_array;
3701 GroupsOfNodes->length( aListOfListOfNodes.size() );
3702 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3703 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3704 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3705 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3706 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3707 aGroup.length( aListOfNodes.size() );
3708 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3709 aGroup[ j ] = (*lIt)->GetID();
3711 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3712 << Tolerance << " )";
3715 //=======================================================================
3716 //function : FindCoincidentNodesOnPart
3718 //=======================================================================
3719 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3720 CORBA::Double Tolerance,
3721 SMESH::array_of_long_array_out GroupsOfNodes)
3725 TIDSortedNodeSet nodes;
3726 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3728 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3729 ::SMESH_MeshEditor anEditor( myMesh );
3731 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3733 GroupsOfNodes = new SMESH::array_of_long_array;
3734 GroupsOfNodes->length( aListOfListOfNodes.size() );
3735 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3736 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3738 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3739 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3740 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3741 aGroup.length( aListOfNodes.size() );
3742 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3743 aGroup[ j ] = (*lIt)->GetID();
3745 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3747 << Tolerance << " )";
3750 //================================================================================
3752 * \brief Finds nodes coinsident with Tolerance within Object excluding nodes within
3753 * ExceptSubMeshOrGroups
3755 //================================================================================
3757 void SMESH_MeshEditor_i::
3758 FindCoincidentNodesOnPartBut(SMESH::SMESH_IDSource_ptr theObject,
3759 CORBA::Double theTolerance,
3760 SMESH::array_of_long_array_out theGroupsOfNodes,
3761 const SMESH::ListOfIDSources& theExceptSubMeshOrGroups)
3765 TIDSortedNodeSet nodes;
3766 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3768 for ( int i = 0; i < theExceptSubMeshOrGroups.length(); ++i )
3770 TIDSortedNodeSet exceptNodes;
3771 idSourceToNodeSet( theExceptSubMeshOrGroups[i], GetMeshDS(), exceptNodes );
3772 TIDSortedNodeSet::iterator avoidNode = exceptNodes.begin();
3773 for ( ; avoidNode != exceptNodes.end(); ++avoidNode)
3774 nodes.erase( *avoidNode );
3776 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3777 ::SMESH_MeshEditor anEditor( myMesh );
3779 anEditor.FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes );
3781 theGroupsOfNodes = new SMESH::array_of_long_array;
3782 theGroupsOfNodes->length( aListOfListOfNodes.size() );
3783 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3784 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3786 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3787 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3788 SMESH::long_array& aGroup = (*theGroupsOfNodes)[ i ];
3789 aGroup.length( aListOfNodes.size() );
3790 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3791 aGroup[ j ] = (*lIt)->GetID();
3793 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPartBut( "
3795 << theTolerance << ", "
3796 << theExceptSubMeshOrGroups << " )";
3799 //=======================================================================
3800 //function : MergeNodes
3802 //=======================================================================
3804 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3808 SMESHDS_Mesh* aMesh = GetMeshDS();
3810 TPythonDump aTPythonDump;
3811 aTPythonDump << this << ".MergeNodes([";
3812 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3813 for (int i = 0; i < GroupsOfNodes.length(); i++)
3815 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3816 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3817 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3818 for ( int j = 0; j < aNodeGroup.length(); j++ )
3820 CORBA::Long index = aNodeGroup[ j ];
3821 const SMDS_MeshNode * node = aMesh->FindNode(index);
3823 aListOfNodes.push_back( node );
3825 if ( aListOfNodes.size() < 2 )
3826 aListOfListOfNodes.pop_back();
3828 if ( i > 0 ) aTPythonDump << ", ";
3829 aTPythonDump << aNodeGroup;
3831 ::SMESH_MeshEditor anEditor( myMesh );
3832 anEditor.MergeNodes( aListOfListOfNodes );
3834 aTPythonDump << "])";
3835 myMesh->GetMeshDS()->Modified();
3836 myMesh->SetIsModified( true );
3839 //=======================================================================
3840 //function : FindEqualElements
3842 //=======================================================================
3843 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3844 SMESH::array_of_long_array_out GroupsOfElementsID)
3848 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theObject);
3849 if ( !(!group->_is_nil() && group->GetType() == SMESH::NODE) )
3851 typedef list<int> TListOfIDs;
3852 set<const SMDS_MeshElement*> elems;
3853 SMESH::long_array_var aElementsId = theObject->GetIDs();
3854 SMESHDS_Mesh* aMesh = GetMeshDS();
3856 for(int i = 0; i < aElementsId->length(); i++) {
3857 CORBA::Long anID = aElementsId[i];
3858 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3864 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3865 ::SMESH_MeshEditor anEditor( myMesh );
3866 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3868 GroupsOfElementsID = new SMESH::array_of_long_array;
3869 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3871 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3872 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3873 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3874 TListOfIDs& listOfIDs = *arraysIt;
3875 aGroup.length( listOfIDs.size() );
3876 TListOfIDs::iterator idIt = listOfIDs.begin();
3877 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3878 aGroup[ k ] = *idIt;
3882 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3887 //=======================================================================
3888 //function : MergeElements
3890 //=======================================================================
3892 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3896 TPythonDump aTPythonDump;
3897 aTPythonDump << this << ".MergeElements( [";
3899 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3901 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3902 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3903 aListOfListOfElementsID.push_back( list< int >() );
3904 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3905 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3906 CORBA::Long id = anElemsIDGroup[ j ];
3907 aListOfElemsID.push_back( id );
3909 if ( aListOfElemsID.size() < 2 )
3910 aListOfListOfElementsID.pop_back();
3911 if ( i > 0 ) aTPythonDump << ", ";
3912 aTPythonDump << anElemsIDGroup;
3915 ::SMESH_MeshEditor anEditor( myMesh );
3916 anEditor.MergeElements(aListOfListOfElementsID);
3917 myMesh->GetMeshDS()->Modified();
3918 myMesh->SetIsModified( true );
3920 aTPythonDump << "] )";
3923 //=======================================================================
3924 //function : MergeEqualElements
3926 //=======================================================================
3928 void SMESH_MeshEditor_i::MergeEqualElements()
3932 ::SMESH_MeshEditor anEditor( myMesh );
3933 anEditor.MergeEqualElements();
3935 TPythonDump() << this << ".MergeEqualElements()";
3938 //=============================================================================
3940 * Move the node to a given point
3942 //=============================================================================
3944 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
3949 initData(/*deleteSearchers=*/false);
3951 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
3955 if ( theNodeSearcher )
3956 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3958 if ( myPreviewMode ) // make preview data
3960 // in a preview mesh, make edges linked to a node
3961 TPreviewMesh tmpMesh;
3962 TIDSortedElemSet linkedNodes;
3963 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3964 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3965 SMDS_MeshNode *nodeCpy1 = tmpMesh.Copy(node);
3966 for ( ; nIt != linkedNodes.end(); ++nIt )
3968 SMDS_MeshNode *nodeCpy2 = tmpMesh.Copy ( cast2Node( *nIt ));
3969 tmpMesh.GetMeshDS()->AddEdge(nodeCpy1, nodeCpy2);
3973 tmpMesh.GetMeshDS()->MoveNode(nodeCpy1, x, y, z);
3974 // fill preview data
3975 ::SMESH_MeshEditor anEditor( & tmpMesh );
3976 storeResult( anEditor );
3978 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3979 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3981 GetMeshDS()->MoveNode(node, x, y, z);
3983 if ( !myPreviewMode )
3985 // Update Python script
3986 TPythonDump() << "isDone = " << this << ".MoveNode( "
3987 << NodeID << ", " << x << ", " << y << ", " << z << " )";
3988 myMesh->GetMeshDS()->Modified();
3989 myMesh->SetIsModified( true );
3995 //================================================================================
3997 * \brief Return ID of node closest to a given point
3999 //================================================================================
4001 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
4005 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4007 if ( !theNodeSearcher ) {
4008 ::SMESH_MeshEditor anEditor( myMesh );
4009 theNodeSearcher = anEditor.GetNodeSearcher();
4012 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
4013 return node->GetID();
4018 //================================================================================
4020 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
4021 * move the node closest to the point to point's location and return ID of the node
4023 //================================================================================
4025 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
4028 CORBA::Long theNodeID)
4030 // We keep theNodeSearcher until any mesh modification:
4031 // 1) initData() deletes theNodeSearcher at any edition,
4032 // 2) TSearchersDeleter - at any mesh compute event and mesh change
4034 initData(/*deleteSearchers=*/false);
4036 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4038 int nodeID = theNodeID;
4039 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
4040 if ( !node ) // preview moving node
4042 if ( !theNodeSearcher ) {
4043 ::SMESH_MeshEditor anEditor( myMesh );
4044 theNodeSearcher = anEditor.GetNodeSearcher();
4047 node = theNodeSearcher->FindClosestTo( p );
4050 nodeID = node->GetID();
4051 if ( myPreviewMode ) // make preview data
4053 // in a preview mesh, make edges linked to a node
4054 TPreviewMesh tmpMesh;
4055 TIDSortedElemSet linkedNodes;
4056 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
4057 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
4058 for ( ; nIt != linkedNodes.end(); ++nIt )
4060 SMDS_LinearEdge edge( node, cast2Node( *nIt ));
4061 tmpMesh.Copy( &edge );
4064 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
4066 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
4067 // fill preview data
4068 ::SMESH_MeshEditor anEditor( & tmpMesh );
4069 storeResult( anEditor );
4071 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
4073 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
4077 GetMeshDS()->MoveNode(node, x, y, z);
4081 if ( !myPreviewMode )
4083 TPythonDump() << "nodeID = " << this
4084 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
4085 << ", " << nodeID << " )";
4087 myMesh->GetMeshDS()->Modified();
4088 myMesh->SetIsModified( true );
4094 //=======================================================================
4096 * Return elements of given type where the given point is IN or ON.
4098 * 'ALL' type means elements of any type excluding nodes
4100 //=======================================================================
4102 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
4105 SMESH::ElementType type)
4107 SMESH::long_array_var res = new SMESH::long_array;
4108 vector< const SMDS_MeshElement* > foundElems;
4110 theSearchersDeleter.Set( myMesh );
4111 if ( !theElementSearcher ) {
4112 ::SMESH_MeshEditor anEditor( myMesh );
4113 theElementSearcher = anEditor.GetElementSearcher();
4115 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
4116 SMDSAbs_ElementType( type ),
4118 res->length( foundElems.size() );
4119 for ( int i = 0; i < foundElems.size(); ++i )
4120 res[i] = foundElems[i]->GetID();
4122 if ( !myPreviewMode ) // call from tui
4123 TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
4132 //=======================================================================
4133 //function : GetPointState
4134 //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
4135 // TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
4136 //=======================================================================
4138 CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
4142 theSearchersDeleter.Set( myMesh );
4143 if ( !theElementSearcher ) {
4144 ::SMESH_MeshEditor anEditor( myMesh );
4145 theElementSearcher = anEditor.GetElementSearcher();
4147 return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
4150 //=======================================================================
4151 //function : convError
4153 //=======================================================================
4155 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
4157 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
4161 RETCASE( SEW_BORDER1_NOT_FOUND );
4162 RETCASE( SEW_BORDER2_NOT_FOUND );
4163 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
4164 RETCASE( SEW_BAD_SIDE_NODES );
4165 RETCASE( SEW_VOLUMES_TO_SPLIT );
4166 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
4167 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
4168 RETCASE( SEW_BAD_SIDE1_NODES );
4169 RETCASE( SEW_BAD_SIDE2_NODES );
4171 return SMESH::SMESH_MeshEditor::SEW_OK;
4174 //=======================================================================
4175 //function : SewFreeBorders
4177 //=======================================================================
4179 SMESH::SMESH_MeshEditor::Sew_Error
4180 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
4181 CORBA::Long SecondNodeID1,
4182 CORBA::Long LastNodeID1,
4183 CORBA::Long FirstNodeID2,
4184 CORBA::Long SecondNodeID2,
4185 CORBA::Long LastNodeID2,
4186 CORBA::Boolean CreatePolygons,
4187 CORBA::Boolean CreatePolyedrs)
4191 SMESHDS_Mesh* aMesh = GetMeshDS();
4193 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4194 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4195 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4196 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4197 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4198 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
4200 if (!aBorderFirstNode ||
4201 !aBorderSecondNode||
4203 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4204 if (!aSide2FirstNode ||
4205 !aSide2SecondNode ||
4207 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4209 TPythonDump() << "error = " << this << ".SewFreeBorders( "
4210 << FirstNodeID1 << ", "
4211 << SecondNodeID1 << ", "
4212 << LastNodeID1 << ", "
4213 << FirstNodeID2 << ", "
4214 << SecondNodeID2 << ", "
4215 << LastNodeID2 << ", "
4216 << CreatePolygons<< ", "
4217 << CreatePolyedrs<< " )";
4219 ::SMESH_MeshEditor anEditor( myMesh );
4220 SMESH::SMESH_MeshEditor::Sew_Error error =
4221 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4231 storeResult(anEditor);
4233 myMesh->GetMeshDS()->Modified();
4234 myMesh->SetIsModified( true );
4240 //=======================================================================
4241 //function : SewConformFreeBorders
4243 //=======================================================================
4245 SMESH::SMESH_MeshEditor::Sew_Error
4246 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
4247 CORBA::Long SecondNodeID1,
4248 CORBA::Long LastNodeID1,
4249 CORBA::Long FirstNodeID2,
4250 CORBA::Long SecondNodeID2)
4254 SMESHDS_Mesh* aMesh = GetMeshDS();
4256 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4257 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4258 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4259 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4260 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4261 const SMDS_MeshNode* aSide2ThirdNode = 0;
4263 if (!aBorderFirstNode ||
4264 !aBorderSecondNode||
4266 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4267 if (!aSide2FirstNode ||
4269 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4271 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
4272 << FirstNodeID1 << ", "
4273 << SecondNodeID1 << ", "
4274 << LastNodeID1 << ", "
4275 << FirstNodeID2 << ", "
4276 << SecondNodeID2 << " )";
4278 ::SMESH_MeshEditor anEditor( myMesh );
4279 SMESH::SMESH_MeshEditor::Sew_Error error =
4280 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4289 storeResult(anEditor);
4291 myMesh->GetMeshDS()->Modified();
4292 myMesh->SetIsModified( true );
4298 //=======================================================================
4299 //function : SewBorderToSide
4301 //=======================================================================
4303 SMESH::SMESH_MeshEditor::Sew_Error
4304 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
4305 CORBA::Long SecondNodeIDOnFreeBorder,
4306 CORBA::Long LastNodeIDOnFreeBorder,
4307 CORBA::Long FirstNodeIDOnSide,
4308 CORBA::Long LastNodeIDOnSide,
4309 CORBA::Boolean CreatePolygons,
4310 CORBA::Boolean CreatePolyedrs)
4314 SMESHDS_Mesh* aMesh = GetMeshDS();
4316 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
4317 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
4318 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
4319 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
4320 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
4321 const SMDS_MeshNode* aSide2ThirdNode = 0;
4323 if (!aBorderFirstNode ||
4324 !aBorderSecondNode||
4326 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4327 if (!aSide2FirstNode ||
4329 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
4331 TPythonDump() << "error = " << this << ".SewBorderToSide( "
4332 << FirstNodeIDOnFreeBorder << ", "
4333 << SecondNodeIDOnFreeBorder << ", "
4334 << LastNodeIDOnFreeBorder << ", "
4335 << FirstNodeIDOnSide << ", "
4336 << LastNodeIDOnSide << ", "
4337 << CreatePolygons << ", "
4338 << CreatePolyedrs << ") ";
4340 ::SMESH_MeshEditor anEditor( myMesh );
4341 SMESH::SMESH_MeshEditor::Sew_Error error =
4342 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4352 storeResult(anEditor);
4354 myMesh->GetMeshDS()->Modified();
4355 myMesh->SetIsModified( true );
4361 //=======================================================================
4362 //function : SewSideElements
4364 //=======================================================================
4366 SMESH::SMESH_MeshEditor::Sew_Error
4367 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
4368 const SMESH::long_array& IDsOfSide2Elements,
4369 CORBA::Long NodeID1OfSide1ToMerge,
4370 CORBA::Long NodeID1OfSide2ToMerge,
4371 CORBA::Long NodeID2OfSide1ToMerge,
4372 CORBA::Long NodeID2OfSide2ToMerge)
4376 SMESHDS_Mesh* aMesh = GetMeshDS();
4378 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
4379 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
4380 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
4381 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
4383 if (!aFirstNode1ToMerge ||
4384 !aFirstNode2ToMerge )
4385 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
4386 if (!aSecondNode1ToMerge||
4387 !aSecondNode2ToMerge)
4388 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
4390 TIDSortedElemSet aSide1Elems, aSide2Elems;
4391 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
4392 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
4394 TPythonDump() << "error = " << this << ".SewSideElements( "
4395 << IDsOfSide1Elements << ", "
4396 << IDsOfSide2Elements << ", "
4397 << NodeID1OfSide1ToMerge << ", "
4398 << NodeID1OfSide2ToMerge << ", "
4399 << NodeID2OfSide1ToMerge << ", "
4400 << NodeID2OfSide2ToMerge << ")";
4402 ::SMESH_MeshEditor anEditor( myMesh );
4403 SMESH::SMESH_MeshEditor::Sew_Error error =
4404 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
4407 aSecondNode1ToMerge,
4408 aSecondNode2ToMerge));
4410 storeResult(anEditor);
4412 myMesh->GetMeshDS()->Modified();
4413 myMesh->SetIsModified( true );
4418 //================================================================================
4420 * \brief Set new nodes for given element
4421 * \param ide - element id
4422 * \param newIDs - new node ids
4423 * \retval CORBA::Boolean - true if result is OK
4425 //================================================================================
4427 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
4428 const SMESH::long_array& newIDs)
4432 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
4433 if(!elem) return false;
4435 int nbn = newIDs.length();
4437 vector<const SMDS_MeshNode*> aNodes(nbn);
4440 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
4443 aNodes[nbn1] = aNode;
4446 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
4447 << ide << ", " << newIDs << " )";
4449 MESSAGE("ChangeElementNodes");
4450 bool res = GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
4452 myMesh->GetMeshDS()->Modified();
4454 myMesh->SetIsModified( true );
4459 //================================================================================
4461 * \brief Update myLastCreated* or myPreviewData
4462 * \param anEditor - it contains last modification results
4464 //================================================================================
4466 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
4468 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
4470 list<int> aNodesConnectivity;
4471 typedef map<int, int> TNodesMap;
4474 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
4475 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
4477 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
4478 int nbEdges = aMeshDS->NbEdges();
4479 int nbFaces = aMeshDS->NbFaces();
4480 int nbVolum = aMeshDS->NbVolumes();
4481 switch ( previewType ) {
4482 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
4483 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
4484 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
4487 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
4488 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
4490 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
4492 while ( itMeshElems->more() ) {
4493 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
4494 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
4497 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
4498 while ( itElemNodes->more() ) {
4499 const SMDS_MeshNode* aMeshNode =
4500 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
4501 int aNodeID = aMeshNode->GetID();
4502 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
4503 if ( anIter == nodesMap.end() ) {
4504 // filling the nodes coordinates
4505 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
4506 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
4507 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
4508 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4511 aNodesConnectivity.push_back(anIter->second);
4514 // filling the elements types
4515 SMDSAbs_ElementType aType;
4517 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4518 aType = SMDSAbs_Node;
4522 aType = aMeshElem->GetType();
4523 isPoly = aMeshElem->IsPoly();
4526 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4527 myPreviewData->elementTypes[i].isPoly = isPoly;
4528 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4532 myPreviewData->nodesXYZ.length( j );
4534 // filling the elements connectivities
4535 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4536 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4537 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4538 myPreviewData->elementConnectivities[i] = *aConnIter;
4544 // add new nodes into myLastCreatedNodes
4545 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4546 myLastCreatedNodes->length(aSeq.Length());
4547 for(int i=0; i<aSeq.Length(); i++)
4548 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4551 // add new elements into myLastCreatedElems
4552 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4553 myLastCreatedElems->length(aSeq.Length());
4554 for(int i=0; i<aSeq.Length(); i++)
4555 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4559 //================================================================================
4561 * Return data of mesh edition preview
4563 //================================================================================
4565 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4567 return myPreviewData._retn();
4570 //================================================================================
4572 * \brief Returns list of it's IDs of created nodes
4573 * \retval SMESH::long_array* - list of node ID
4575 //================================================================================
4577 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4579 return myLastCreatedNodes._retn();
4582 //================================================================================
4584 * \brief Returns list of it's IDs of created elements
4585 * \retval SMESH::long_array* - list of elements' ID
4587 //================================================================================
4589 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4591 return myLastCreatedElems._retn();
4594 //=======================================================================
4595 //function : ConvertToQuadratic
4597 //=======================================================================
4599 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4601 ::SMESH_MeshEditor anEditor( myMesh );
4602 anEditor.ConvertToQuadratic(theForce3d);
4603 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4604 myMesh->GetMeshDS()->Modified();
4605 myMesh->SetIsModified( true );
4608 //=======================================================================
4609 //function : ConvertFromQuadratic
4611 //=======================================================================
4613 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4615 ::SMESH_MeshEditor anEditor( myMesh );
4616 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4617 TPythonDump() << this << ".ConvertFromQuadratic()";
4618 myMesh->GetMeshDS()->Modified();
4620 myMesh->SetIsModified( true );
4624 //=======================================================================
4625 //function : makeMesh
4626 //purpose : create a named imported mesh
4627 //=======================================================================
4629 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4631 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4632 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4633 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4634 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4635 gen->SetName( meshSO, theMeshName, "Mesh" );
4636 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4638 return mesh._retn();
4641 //=======================================================================
4642 //function : DumpGroupsList
4644 //=======================================================================
4645 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4646 const SMESH::ListOfGroups * theGroupList)
4648 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4649 if(isDumpGroupList) {
4650 theDumpPython << theGroupList << " = ";
4654 //================================================================================
4656 \brief Generates the unique group name.
4657 \param thePrefix name prefix
4660 //================================================================================
4661 string SMESH_MeshEditor_i::generateGroupName(const string& thePrefix)
4663 SMESH::ListOfGroups_var groups = myMesh_i->GetGroups();
4664 set<string> groupNames;
4666 // Get existing group names
4667 for (int i = 0, nbGroups = groups->length(); i < nbGroups; i++ ) {
4668 SMESH::SMESH_GroupBase_var aGroup = groups[i];
4669 if (CORBA::is_nil(aGroup))
4672 groupNames.insert(aGroup->GetName());
4676 string name = thePrefix;
4679 while (!groupNames.insert(name).second) {
4684 TCollection_AsciiString nbStr(index+1);
4685 name.resize( name.rfind('_')+1 );
4686 name += nbStr.ToCString();
4694 //================================================================================
4696 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4697 \param theNodes - identifiers of nodes to be doubled
4698 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4699 nodes. If list of element identifiers is empty then nodes are doubled but
4700 they not assigned to elements
4701 \return TRUE if operation has been completed successfully, FALSE otherwise
4702 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4704 //================================================================================
4706 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4707 const SMESH::long_array& theModifiedElems )
4711 ::SMESH_MeshEditor aMeshEditor( myMesh );
4712 list< int > aListOfNodes;
4714 for ( i = 0, n = theNodes.length(); i < n; i++ )
4715 aListOfNodes.push_back( theNodes[ i ] );
4717 list< int > aListOfElems;
4718 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4719 aListOfElems.push_back( theModifiedElems[ i ] );
4721 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4723 myMesh->GetMeshDS()->Modified();
4724 storeResult( aMeshEditor) ;
4726 myMesh->SetIsModified( true );
4728 // Update Python script
4729 TPythonDump() << this << ".DoubleNodes( " << theNodes << ", "<< theModifiedElems << " )";
4734 //================================================================================
4736 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4737 This method provided for convenience works as DoubleNodes() described above.
4738 \param theNodeId - identifier of node to be doubled.
4739 \param theModifiedElems - identifiers of elements to be updated.
4740 \return TRUE if operation has been completed successfully, FALSE otherwise
4741 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4743 //================================================================================
4745 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4746 const SMESH::long_array& theModifiedElems )
4748 SMESH::long_array_var aNodes = new SMESH::long_array;
4749 aNodes->length( 1 );
4750 aNodes[ 0 ] = theNodeId;
4752 TPythonDump pyDump; // suppress dump by the next line
4754 CORBA::Boolean done = DoubleNodes( aNodes, theModifiedElems );
4756 pyDump << this << ".DoubleNode( " << theNodeId << ", " << theModifiedElems << " )";
4761 //================================================================================
4763 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4764 This method provided for convenience works as DoubleNodes() described above.
4765 \param theNodes - group of nodes to be doubled.
4766 \param theModifiedElems - group of elements to be updated.
4767 \return TRUE if operation has been completed successfully, FALSE otherwise
4768 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
4770 //================================================================================
4772 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(SMESH::SMESH_GroupBase_ptr theNodes,
4773 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4775 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4778 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4779 SMESH::long_array_var aModifiedElems;
4780 if ( !CORBA::is_nil( theModifiedElems ) )
4781 aModifiedElems = theModifiedElems->GetListOfID();
4784 aModifiedElems = new SMESH::long_array;
4785 aModifiedElems->length( 0 );
4788 TPythonDump pyDump; // suppress dump by the next line
4790 bool done = DoubleNodes( aNodes, aModifiedElems );
4792 pyDump << this << ".DoubleNodeGroup( " << theNodes << ", " << theModifiedElems << " )";
4798 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements.
4799 * Works as DoubleNodeGroup(), but returns a new group with newly created nodes.
4800 * \param theNodes - group of nodes to be doubled.
4801 * \param theModifiedElems - group of elements to be updated.
4802 * \return a new group with newly created nodes
4803 * \sa DoubleNodeGroup()
4805 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes,
4806 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4808 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4811 SMESH::SMESH_Group_var aNewGroup;
4814 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4815 SMESH::long_array_var aModifiedElems;
4816 if ( !CORBA::is_nil( theModifiedElems ) )
4817 aModifiedElems = theModifiedElems->GetListOfID();
4819 aModifiedElems = new SMESH::long_array;
4820 aModifiedElems->length( 0 );
4823 TPythonDump pyDump; // suppress dump by the next line
4825 bool aResult = DoubleNodes( aNodes, aModifiedElems );
4829 // Create group with newly created nodes
4830 SMESH::long_array_var anIds = GetLastCreatedNodes();
4831 if (anIds->length() > 0) {
4832 string anUnindexedName (theNodes->GetName());
4833 string aNewName = generateGroupName(anUnindexedName + "_double");
4834 aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
4835 aNewGroup->Add(anIds);
4839 pyDump << "createdNodes = " << this << ".DoubleNodeGroupNew( " << theNodes << ", "
4840 << theModifiedElems << " )";
4842 return aNewGroup._retn();
4845 //================================================================================
4847 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4848 This method provided for convenience works as DoubleNodes() described above.
4849 \param theNodes - list of groups of nodes to be doubled
4850 \param theModifiedElems - list of groups of elements to be updated.
4851 \return TRUE if operation has been completed successfully, FALSE otherwise
4852 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
4854 //================================================================================
4856 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& theNodes,
4857 const SMESH::ListOfGroups& theModifiedElems )
4861 ::SMESH_MeshEditor aMeshEditor( myMesh );
4863 std::list< int > aNodes;
4865 for ( i = 0, n = theNodes.length(); i < n; i++ )
4867 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
4868 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
4870 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4871 for ( j = 0, m = aCurr->length(); j < m; j++ )
4872 aNodes.push_back( aCurr[ j ] );
4876 std::list< int > anElems;
4877 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4879 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
4880 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
4882 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4883 for ( j = 0, m = aCurr->length(); j < m; j++ )
4884 anElems.push_back( aCurr[ j ] );
4888 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
4890 storeResult( aMeshEditor) ;
4892 myMesh->GetMeshDS()->Modified();
4894 myMesh->SetIsModified( true );
4897 TPythonDump() << this << ".DoubleNodeGroups( " << theNodes << ", " << theModifiedElems << " )";
4902 //================================================================================
4904 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4905 \param theElems - the list of elements (edges or faces) to be replicated
4906 The nodes for duplication could be found from these elements
4907 \param theNodesNot - list of nodes to NOT replicate
4908 \param theAffectedElems - the list of elements (cells and edges) to which the
4909 replicated nodes should be associated to.
4910 \return TRUE if operation has been completed successfully, FALSE otherwise
4911 \sa DoubleNodeGroup(), DoubleNodeGroups()
4913 //================================================================================
4915 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
4916 const SMESH::long_array& theNodesNot,
4917 const SMESH::long_array& theAffectedElems )
4922 ::SMESH_MeshEditor aMeshEditor( myMesh );
4924 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4925 TIDSortedElemSet anElems, aNodes, anAffected;
4926 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4927 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4928 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
4930 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4932 storeResult( aMeshEditor) ;
4934 myMesh->GetMeshDS()->Modified();
4936 myMesh->SetIsModified( true );
4938 // Update Python script
4939 TPythonDump() << this << ".DoubleNodeElem( " << theElems << ", "
4940 << theNodesNot << ", " << theAffectedElems << " )";
4944 //================================================================================
4946 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4947 \param theElems - the list of elements (edges or faces) to be replicated
4948 The nodes for duplication could be found from these elements
4949 \param theNodesNot - list of nodes to NOT replicate
4950 \param theShape - shape to detect affected elements (element which geometric center
4951 located on or inside shape).
4952 The replicated nodes should be associated to affected elements.
4953 \return TRUE if operation has been completed successfully, FALSE otherwise
4954 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
4956 //================================================================================
4958 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_array& theElems,
4959 const SMESH::long_array& theNodesNot,
4960 GEOM::GEOM_Object_ptr theShape )
4965 ::SMESH_MeshEditor aMeshEditor( myMesh );
4967 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4968 TIDSortedElemSet anElems, aNodes;
4969 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4970 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4972 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4973 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4975 storeResult( aMeshEditor) ;
4977 myMesh->GetMeshDS()->Modified();
4979 myMesh->SetIsModified( true );
4981 // Update Python script
4982 TPythonDump() << "isDone = " << this << ".DoubleNodeElemInRegion( " << theElems << ", "
4983 << theNodesNot << ", " << theShape << " )";
4987 //================================================================================
4989 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4990 \param theElems - group of of elements (edges or faces) to be replicated
4991 \param theNodesNot - group of nodes not to replicated
4992 \param theAffectedElems - group of elements to which the replicated nodes
4993 should be associated to.
4994 \return TRUE if operation has been completed successfully, FALSE otherwise
4995 \sa DoubleNodes(), DoubleNodeGroups()
4997 //================================================================================
4999 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_ptr theElems,
5000 SMESH::SMESH_GroupBase_ptr theNodesNot,
5001 SMESH::SMESH_GroupBase_ptr theAffectedElems)
5003 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5008 ::SMESH_MeshEditor aMeshEditor( myMesh );
5010 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5011 TIDSortedElemSet anElems, aNodes, anAffected;
5012 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5013 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5014 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
5016 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5018 storeResult( aMeshEditor) ;
5020 myMesh->GetMeshDS()->Modified();
5022 myMesh->SetIsModified( true );
5024 // Update Python script
5025 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroup( " << theElems << ", "
5026 << theNodesNot << ", " << theAffectedElems << " )";
5031 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5032 * Works as DoubleNodeElemGroup(), but returns a new group with newly created elements.
5033 * \param theElems - group of of elements (edges or faces) to be replicated
5034 * \param theNodesNot - group of nodes not to replicated
5035 * \param theAffectedElems - group of elements to which the replicated nodes
5036 * should be associated to.
5037 * \return a new group with newly created elements
5038 * \sa DoubleNodeElemGroup()
5040 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems,
5041 SMESH::SMESH_GroupBase_ptr theNodesNot,
5042 SMESH::SMESH_GroupBase_ptr theAffectedElems)
5044 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5047 SMESH::SMESH_Group_var aNewGroup;
5051 ::SMESH_MeshEditor aMeshEditor( myMesh );
5053 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5054 TIDSortedElemSet anElems, aNodes, anAffected;
5055 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5056 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5057 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
5060 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5062 storeResult( aMeshEditor) ;
5065 myMesh->SetIsModified( true );
5067 // Create group with newly created elements
5068 SMESH::long_array_var anIds = GetLastCreatedElems();
5069 if (anIds->length() > 0) {
5070 SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
5071 string anUnindexedName (theElems->GetName());
5072 string aNewName = generateGroupName(anUnindexedName + "_double");
5073 aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
5074 aNewGroup->Add(anIds);
5078 // Update Python script
5079 TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupNew( " << theElems << ", "
5080 << theNodesNot << ", " << theAffectedElems << " )";
5081 return aNewGroup._retn();
5084 //================================================================================
5086 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5087 \param theElems - group of of elements (edges or faces) to be replicated
5088 \param theNodesNot - group of nodes not to replicated
5089 \param theShape - shape to detect affected elements (element which geometric center
5090 located on or inside shape).
5091 The replicated nodes should be associated to affected elements.
5092 \return TRUE if operation has been completed successfully, FALSE otherwise
5093 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
5095 //================================================================================
5097 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_GroupBase_ptr theElems,
5098 SMESH::SMESH_GroupBase_ptr theNodesNot,
5099 GEOM::GEOM_Object_ptr theShape )
5102 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5107 ::SMESH_MeshEditor aMeshEditor( myMesh );
5109 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5110 TIDSortedElemSet anElems, aNodes, anAffected;
5111 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5112 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5114 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5115 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5117 storeResult( aMeshEditor) ;
5119 myMesh->GetMeshDS()->Modified();
5121 myMesh->SetIsModified( true );
5123 // Update Python script
5124 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupInRegion( " << theElems << ", "
5125 << theNodesNot << ", " << theShape << " )";
5129 //================================================================================
5131 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5132 This method provided for convenience works as DoubleNodes() described above.
5133 \param theElems - list of groups of elements (edges or faces) to be replicated
5134 \param theNodesNot - list of groups of nodes not to replicated
5135 \param theAffectedElems - group of elements to which the replicated nodes
5136 should be associated to.
5137 \return TRUE if operation has been completed successfully, FALSE otherwise
5138 \sa DoubleNodeGroup(), DoubleNodes()
5140 //================================================================================
5142 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
5143 SMESHDS_Mesh* theMeshDS,
5144 TIDSortedElemSet& theElemSet,
5145 const bool theIsNodeGrp)
5147 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
5149 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
5150 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
5151 : aGrp->GetType() != SMESH::NODE ) )
5153 SMESH::long_array_var anIDs = aGrp->GetIDs();
5154 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
5159 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroups& theElems,
5160 const SMESH::ListOfGroups& theNodesNot,
5161 const SMESH::ListOfGroups& theAffectedElems)
5165 ::SMESH_MeshEditor aMeshEditor( myMesh );
5167 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5168 TIDSortedElemSet anElems, aNodes, anAffected;
5169 listOfGroupToSet(theElems, aMeshDS, anElems, false );
5170 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5171 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
5173 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5175 storeResult( aMeshEditor) ;
5177 myMesh->GetMeshDS()->Modified();
5179 myMesh->SetIsModified( true );
5181 // Update Python script
5182 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroups( " << &theElems << ", "
5183 << &theNodesNot << ", " << &theAffectedElems << " )";
5187 //================================================================================
5189 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5190 This method provided for convenience works as DoubleNodes() described above.
5191 \param theElems - list of groups of elements (edges or faces) to be replicated
5192 \param theNodesNot - list of groups of nodes not to replicated
5193 \param theShape - shape to detect affected elements (element which geometric center
5194 located on or inside shape).
5195 The replicated nodes should be associated to affected elements.
5196 \return TRUE if operation has been completed successfully, FALSE otherwise
5197 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
5199 //================================================================================
5202 SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theElems,
5203 const SMESH::ListOfGroups& theNodesNot,
5204 GEOM::GEOM_Object_ptr theShape )
5208 ::SMESH_MeshEditor aMeshEditor( myMesh );
5210 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5211 TIDSortedElemSet anElems, aNodes;
5212 listOfGroupToSet(theElems, aMeshDS, anElems,false );
5213 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5215 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5216 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5218 storeResult( aMeshEditor) ;
5220 myMesh->GetMeshDS()->Modified();
5222 myMesh->SetIsModified( true );
5224 // Update Python script
5225 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupsInRegion( " << &theElems << ", "
5226 << &theNodesNot << ", " << theShape << " )";
5230 //================================================================================
5232 \brief Generated skin mesh (containing 2D cells) from 3D mesh
5233 The created 2D mesh elements based on nodes of free faces of boundary volumes
5234 \return TRUE if operation has been completed successfully, FALSE otherwise
5236 //================================================================================
5238 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
5242 ::SMESH_MeshEditor aMeshEditor( myMesh );
5243 bool aResult = aMeshEditor.Make2DMeshFrom3D();
5244 storeResult( aMeshEditor) ;
5245 myMesh->GetMeshDS()->Modified();
5246 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";
5250 //================================================================================
5252 * \brief Double nodes on shared faces between groups of volumes and create flat elements on demand.
5253 * The list of groups must describe a partition of the mesh volumes.
5254 * The nodes of the internal faces at the boundaries of the groups are doubled.
5255 * In option, the internal faces are replaced by flat elements.
5256 * Triangles are transformed in prisms, and quadrangles in hexahedrons.
5257 * @param theDomains - list of groups of volumes
5258 * @param createJointElems - if TRUE, create the elements
5259 * @return TRUE if operation has been completed successfully, FALSE otherwise
5261 //================================================================================
5263 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::ListOfGroups& theDomains,
5264 CORBA::Boolean createJointElems )
5268 ::SMESH_MeshEditor aMeshEditor( myMesh );
5270 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5272 vector<TIDSortedElemSet> domains;
5275 for ( int i = 0, n = theDomains.length(); i < n; i++ )
5277 SMESH::SMESH_GroupBase_var aGrp = theDomains[ i ];
5278 if ( !CORBA::is_nil( aGrp ) && ( aGrp->GetType() != SMESH::NODE ) )
5280 TIDSortedElemSet domain;
5282 domains.push_back(domain);
5283 SMESH::long_array_var anIDs = aGrp->GetIDs();
5284 arrayToSet( anIDs, aMeshDS, domains[ i ], SMDSAbs_All );
5288 bool aResult = aMeshEditor.DoubleNodesOnGroupBoundaries( domains, createJointElems );
5290 storeResult( aMeshEditor) ;
5291 myMesh->GetMeshDS()->Modified();
5293 // Update Python script
5294 TPythonDump() << "isDone = " << this << ".DoubleNodesOnGroupBoundaries( " << &theDomains
5295 << ", " << createJointElems << " )";
5299 // issue 20749 ===================================================================
5301 * \brief Creates missing boundary elements
5302 * \param elements - elements whose boundary is to be checked
5303 * \param dimension - defines type of boundary elements to create
5304 * \param groupName - a name of group to store created boundary elements in,
5305 * "" means not to create the group
5306 * \param meshName - a name of new mesh to store created boundary elements in,
5307 * "" means not to create the new mesh
5308 * \param toCopyElements - if true, the checked elements will be copied into the new mesh
5309 * \param toCopyExistingBondary - if true, not only new but also pre-existing
5310 * boundary elements will be copied into the new mesh
5311 * \param group - returns the create group, if any
5312 * \retval SMESH::SMESH_Mesh - the mesh where elements were added to
5314 // ================================================================================
5316 SMESH::SMESH_Mesh_ptr
5317 SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource,
5318 SMESH::Bnd_Dimension dim,
5319 const char* groupName,
5320 const char* meshName,
5321 CORBA::Boolean toCopyElements,
5322 CORBA::Boolean toCopyExistingBondary,
5323 SMESH::SMESH_Group_out group)
5327 if ( dim > SMESH::BND_1DFROM2D )
5328 THROW_SALOME_CORBA_EXCEPTION("Invalid boundary dimension", SALOME::BAD_PARAM);
5331 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5333 SMESH::SMESH_Mesh_var mesh_var;
5334 SMESH::SMESH_Group_var group_var;
5338 TIDSortedElemSet elements;
5339 SMDSAbs_ElementType elemType = (dim == SMESH::BND_1DFROM2D) ? SMDSAbs_Face : SMDSAbs_Volume;
5340 if ( idSourceToSet( idSource, aMeshDS, elements, elemType,/*emptyIfIsMesh=*/true ))
5344 strlen(meshName) ? makeMesh(meshName) : SMESH::SMESH_Mesh::_duplicate(myMesh_i->_this());
5345 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh_var );
5347 SMESH_Mesh* smesh_mesh = (mesh_i==myMesh_i) ? (SMESH_Mesh*)0 : &mesh_i->GetImpl();
5349 // group of new boundary elements
5350 SMESH_Group* smesh_group = 0;
5351 if ( strlen(groupName) )
5353 group_var = mesh_i->CreateGroup( SMESH::ElementType(int(elemType)-1),groupName);
5354 if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( group_var ))
5355 smesh_group = group_i->GetSmeshGroup();
5359 ::SMESH_MeshEditor aMeshEditor( myMesh );
5360 aMeshEditor.MakeBoundaryMesh( elements,
5361 ::SMESH_MeshEditor::Bnd_Dimension(dim),
5365 toCopyExistingBondary);
5366 storeResult( aMeshEditor );
5369 const char* dimName[] = { "BND_2DFROM3D", "BND_1DFROM3D", "BND_1DFROM2D" };
5371 // result of MakeBoundaryMesh() is a tuple (mesh, group)
5372 if ( mesh_var->_is_nil() )
5373 pyDump << myMesh_i->_this() << ", ";
5375 pyDump << mesh_var << ", ";
5376 if ( group_var->_is_nil() )
5377 pyDump << "_NoneGroup = "; // assignment to None is forbiden
5379 pyDump << group_var << " = ";
5380 pyDump << this << ".MakeBoundaryMesh( "
5382 << "SMESH." << dimName[int(dim)] << ", "
5383 << "'" << groupName << "', "
5384 << "'" << meshName<< "', "
5385 << toCopyElements << ", "
5386 << toCopyExistingBondary << ")";
5388 group = group_var._retn();
5389 return mesh_var._retn();