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
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_MeshEditor_i.cxx
24 // Author : Nicolas REJNERI
31 #include "SMESH_MeshEditor_i.hxx"
33 #include "SMDS_Mesh0DElement.hxx"
34 #include "SMDS_LinearEdge.hxx"
35 #include "SMDS_MeshFace.hxx"
36 #include "SMDS_MeshVolume.hxx"
37 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
38 #include "SMESH_subMeshEventListener.hxx"
39 #include "SMESH_Gen_i.hxx"
40 #include "SMESH_Filter_i.hxx"
41 #include "SMESH_subMesh_i.hxx"
42 #include "SMESH_Group_i.hxx"
43 #include "SMESH_PythonDump.hxx"
44 #include "SMESH_ControlsDef.hxx"
46 #include "utilities.h"
47 #include "Utils_ExceptHandlers.hxx"
48 #include "Utils_CorbaException.hxx"
50 #include <BRepAdaptor_Surface.hxx>
51 #include <BRep_Tool.hxx>
52 #include <TopExp_Explorer.hxx>
54 #include <TopoDS_Edge.hxx>
55 #include <TopoDS_Face.hxx>
60 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
64 #include <Standard_Failure.hxx>
67 #include <Standard_ErrorHandler.hxx>
73 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
76 using SMESH::TPythonDump;
80 //=============================================================================
82 * \brief Mesh to apply modifications for preview purposes
84 //=============================================================================
86 struct TPreviewMesh: public SMESH_Mesh
88 SMDSAbs_ElementType myPreviewType; // type to show
90 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
91 _isShapeToMesh = (_id =_studyId =_idDoc = 0);
92 _myMeshDS = new SMESHDS_Mesh( _id, true );
93 myPreviewType = previewElements;
96 virtual ~TPreviewMesh() { delete _myMeshDS; }
97 //!< Copy a set of elements
98 void Copy(const TIDSortedElemSet & theElements,
99 TIDSortedElemSet& theCopyElements,
100 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
101 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
103 // loop on theIDsOfElements
104 TIDSortedElemSet::const_iterator eIt = theElements.begin();
105 for ( ; eIt != theElements.end(); ++eIt )
107 const SMDS_MeshElement* anElem = *eIt;
108 if ( !anElem ) continue;
109 SMDSAbs_ElementType type = anElem->GetType();
110 if ( type == theAvoidType ||
111 ( theSelectType != SMDSAbs_All && type != theSelectType ))
114 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
115 theCopyElements.insert( theCopyElements.end(), anElemCopy );
119 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
121 // copy element nodes
122 int anElemNbNodes = anElem->NbNodes();
123 vector< int > anElemNodesID( anElemNbNodes ) ;
124 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
125 for ( int i = 0; itElemNodes->more(); i++)
127 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
129 anElemNodesID[i] = anElemNode->GetID();
132 // creates a corresponding element on copied nodes
133 SMDS_MeshElement* anElemCopy = 0;
134 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
136 const SMDS_VtkVolume* ph =
137 dynamic_cast<const SMDS_VtkVolume*> (anElem);
139 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
140 (anElemNodesID, ph->GetQuantities(),anElem->GetID());
143 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
150 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
152 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
153 anElemNode->GetID());
155 };// struct TPreviewMesh
157 static SMESH_NodeSearcher * theNodeSearcher = 0;
158 static SMESH_ElementSearcher * theElementSearcher = 0;
160 //=============================================================================
162 * \brief Deleter of theNodeSearcher at any compute event occured
164 //=============================================================================
166 struct TSearchersDeleter : public SMESH_subMeshEventListener
170 TSearchersDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
172 //!< Delete theNodeSearcher
175 if ( theNodeSearcher ) delete theNodeSearcher; theNodeSearcher = 0;
176 if ( theElementSearcher ) delete theElementSearcher; theElementSearcher = 0;
178 typedef map < int, SMESH_subMesh * > TDependsOnMap;
179 //!< The meshod called by submesh: do my main job
180 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
181 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
183 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
185 Unset( sm->GetFather() );
188 //!< set self on all submeshes and delete theNodeSearcher if other mesh is set
189 void Set(SMESH_Mesh* mesh)
191 if ( myMesh != mesh )
198 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
199 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
200 TDependsOnMap::const_iterator sm;
201 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
202 sm->second->SetEventListener( this, 0, sm->second );
206 //!< delete self from all submeshes
207 void Unset(SMESH_Mesh* mesh)
209 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
210 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
211 TDependsOnMap::const_iterator sm;
212 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
213 sm->second->DeleteEventListener( this );
218 } theSearchersDeleter;
220 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
222 TCollection_AsciiString typeStr;
223 switch ( theMirrorType ) {
224 case SMESH::SMESH_MeshEditor::POINT:
225 typeStr = "SMESH.SMESH_MeshEditor.POINT";
227 case SMESH::SMESH_MeshEditor::AXIS:
228 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
231 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
235 //================================================================================
237 * \brief function for conversion of long_array to TIDSortedElemSet
238 * \param IDs - array of IDs
239 * \param aMesh - mesh
240 * \param aMap - collection to fill
241 * \param aType - element type
243 //================================================================================
245 void arrayToSet(const SMESH::long_array & IDs,
246 const SMESHDS_Mesh* aMesh,
247 TIDSortedElemSet& aMap,
248 const SMDSAbs_ElementType aType = SMDSAbs_All )
250 for (int i=0; i<IDs.length(); i++) {
251 CORBA::Long ind = IDs[i];
252 const SMDS_MeshElement * elem =
253 (aType == SMDSAbs_Node ? aMesh->FindNode(ind) : aMesh->FindElement(ind));
254 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
258 //================================================================================
260 * \brief Retrieve elements of given type from SMESH_IDSource
262 //================================================================================
264 bool idSourceToSet(SMESH::SMESH_IDSource_ptr theIDSource,
265 const SMESHDS_Mesh* theMeshDS,
266 TIDSortedElemSet& theElemSet,
267 const SMDSAbs_ElementType theType,
268 const bool emptyIfIsMesh=false)
271 if ( CORBA::is_nil( theIDSource ) )
273 if ( emptyIfIsMesh && SMESH::DownCast<SMESH_Mesh_i*>( theIDSource ))
276 SMESH::long_array_var anIDs = theIDSource->GetIDs();
277 if ( anIDs->length() == 0 )
279 SMESH::array_of_ElementType_var types = theIDSource->GetTypes();
280 if ( types->length() == 1 && types[0] == SMESH::NODE ) // group of nodes
282 if ( theType == SMDSAbs_All || theType == SMDSAbs_Node )
283 arrayToSet( anIDs, theMeshDS, theElemSet, SMDSAbs_Node );
289 arrayToSet( anIDs, theMeshDS, theElemSet, theType);
293 //================================================================================
295 * \brief Retrieve nodes from SMESH_IDSource
297 //================================================================================
299 void idSourceToNodeSet(SMESH::SMESH_IDSource_ptr theObject,
300 const SMESHDS_Mesh* theMeshDS,
301 TIDSortedNodeSet& theNodeSet)
304 if ( CORBA::is_nil( theObject ) )
306 SMESH::array_of_ElementType_var types = theObject->GetTypes();
307 SMESH::long_array_var aElementsId = theObject->GetIDs();
308 if ( types->length() == 1 && types[0] == SMESH::NODE)
310 for(int i = 0; i < aElementsId->length(); i++)
311 if ( const SMDS_MeshNode * n = theMeshDS->FindNode( aElementsId[i] ))
312 theNodeSet.insert( theNodeSet.end(), n);
315 for(int i = 0; i < aElementsId->length(); i++)
316 if( const SMDS_MeshElement * elem = theMeshDS->FindElement( aElementsId[i] ))
317 theNodeSet.insert( elem->begin_nodes(), elem->end_nodes());
321 //================================================================================
323 * \brief Returns elements connected to the given elements
325 //================================================================================
327 void getElementsAround(const TIDSortedElemSet& theElements,
328 const SMESHDS_Mesh* theMeshDS,
329 TIDSortedElemSet& theElementsAround)
331 if ( theElements.empty() ) return;
333 SMDSAbs_ElementType elemType = (*theElements.begin())->GetType();
334 bool sameElemType = ( elemType == (*theElements.rbegin())->GetType() );
336 theMeshDS->GetMeshInfo().NbElements( elemType ) == theElements.size() )
337 return; // all the elements are in theElements
340 elemType = SMDSAbs_All;
342 TIDSortedElemSet visitedNodes;
343 TIDSortedElemSet::const_iterator elemIt = theElements.begin();
344 for ( ; elemIt != theElements.end(); ++elemIt )
346 const SMDS_MeshElement* e = *elemIt;
347 int i = e->NbCornerNodes();
350 const SMDS_MeshNode* n = e->GetNode( i );
351 if ( visitedNodes.insert( n ).second )
353 SMDS_ElemIteratorPtr invIt = n->GetInverseElementIterator(elemType);
354 while ( invIt->more() )
356 const SMDS_MeshElement* elemAround = invIt->next();
357 if ( !theElements.count( elemAround ))
358 theElementsAround.insert( elemAround );
366 //=============================================================================
370 //=============================================================================
372 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
375 myMesh = & theMesh->GetImpl();
376 myPreviewMode = isPreview;
379 //================================================================================
383 //================================================================================
385 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
389 //================================================================================
391 * \brief Clear members
393 //================================================================================
395 void SMESH_MeshEditor_i::initData(bool deleteSearchers)
397 if ( myPreviewMode ) {
398 myPreviewData = new SMESH::MeshPreviewStruct();
401 myLastCreatedElems = new SMESH::long_array();
402 myLastCreatedNodes = new SMESH::long_array();
403 if ( deleteSearchers )
404 TSearchersDeleter::Delete();
408 //=======================================================================
409 //function : MakeIDSource
410 //purpose : Wrap a sequence of ids in a SMESH_IDSource
411 //=======================================================================
413 struct _IDSource : public POA_SMESH::SMESH_IDSource
415 SMESH::long_array _ids;
416 SMESH::ElementType _type;
417 SMESH::SMESH_Mesh_ptr _mesh;
418 SMESH::long_array* GetIDs() { return new SMESH::long_array( _ids ); }
419 SMESH::long_array* GetMeshInfo() { return 0; }
420 SMESH::SMESH_Mesh_ptr GetMesh() { return SMESH::SMESH_Mesh::_duplicate( _mesh ); }
421 SMESH::array_of_ElementType* GetTypes()
423 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
426 return types._retn();
430 SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_array& ids,
431 SMESH::ElementType type)
433 _IDSource* anIDSource = new _IDSource;
434 anIDSource->_ids = ids;
435 anIDSource->_type = type;
436 anIDSource->_mesh = myMesh_i->_this();
437 SMESH::SMESH_IDSource_var anIDSourceVar = anIDSource->_this();
439 return anIDSourceVar._retn();
442 //=============================================================================
446 //=============================================================================
449 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
453 ::SMESH_MeshEditor anEditor( myMesh );
456 for (int i = 0; i < IDsOfElements.length(); i++)
457 IdList.push_back( IDsOfElements[i] );
459 // Update Python script
460 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
463 bool ret = anEditor.Remove( IdList, false );
464 myMesh->GetMeshDS()->Modified();
465 if ( IDsOfElements.length() )
466 myMesh->SetIsModified( true ); // issue 0020693
470 //=============================================================================
474 //=============================================================================
476 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
480 ::SMESH_MeshEditor anEditor( myMesh );
482 for (int i = 0; i < IDsOfNodes.length(); i++)
483 IdList.push_back( IDsOfNodes[i] );
485 // Update Python script
486 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
488 bool ret = anEditor.Remove( IdList, true );
489 myMesh->GetMeshDS()->Modified();
490 if ( IDsOfNodes.length() )
491 myMesh->SetIsModified( true ); // issue 0020693
495 //=============================================================================
499 //=============================================================================
501 CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes()
505 ::SMESH_MeshEditor anEditor( myMesh );
507 // Update Python script
508 TPythonDump() << "nbRemoved = " << this << ".RemoveOrphanNodes()";
510 // Create filter to find all orphan nodes
511 SMESH::Controls::Filter::TIdSequence seq;
512 SMESH::Controls::PredicatePtr predicate( new SMESH::Controls::FreeNodes() );
513 SMESH::Controls::Filter::GetElementsId( GetMeshDS(), predicate, seq );
515 // remove orphan nodes (if there are any)
517 for ( int i = 0; i < seq.size(); i++ )
518 IdList.push_back( seq[i] );
520 bool ret = anEditor.Remove( IdList, true );
521 myMesh->GetMeshDS()->Modified();
523 myMesh->SetIsModified( true );
528 //=============================================================================
532 //=============================================================================
534 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
535 CORBA::Double y, CORBA::Double z)
539 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
541 // Update Python script
542 TPythonDump() << "nodeID = " << this << ".AddNode( "
543 << x << ", " << y << ", " << z << " )";
545 myMesh->GetMeshDS()->Modified();
546 myMesh->SetIsModified( true ); // issue 0020693
550 //=============================================================================
554 //=============================================================================
555 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
559 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
560 SMDS_MeshElement* elem = GetMeshDS()->Add0DElement(aNode);
562 // Update Python script
563 TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
565 myMesh->GetMeshDS()->Modified();
566 myMesh->SetIsModified( true ); // issue 0020693
569 return elem->GetID();
574 //=============================================================================
578 //=============================================================================
580 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
584 int NbNodes = IDsOfNodes.length();
585 SMDS_MeshElement* elem = 0;
588 CORBA::Long index1 = IDsOfNodes[0];
589 CORBA::Long index2 = IDsOfNodes[1];
590 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
592 // Update Python script
593 TPythonDump() << "edge = " << this << ".AddEdge([ "
594 << index1 << ", " << index2 <<" ])";
597 CORBA::Long n1 = IDsOfNodes[0];
598 CORBA::Long n2 = IDsOfNodes[1];
599 CORBA::Long n12 = IDsOfNodes[2];
600 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
601 GetMeshDS()->FindNode(n2),
602 GetMeshDS()->FindNode(n12));
603 // Update Python script
604 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
605 <<n1<<", "<<n2<<", "<<n12<<" ])";
608 myMesh->GetMeshDS()->Modified();
610 return myMesh->SetIsModified( true ), elem->GetID();
615 //=============================================================================
619 //=============================================================================
621 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
625 int NbNodes = IDsOfNodes.length();
631 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
632 for (int i = 0; i < NbNodes; i++)
633 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
635 SMDS_MeshElement* elem = 0;
637 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
639 else if (NbNodes == 4) {
640 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
642 else if (NbNodes == 6) {
643 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
646 else if (NbNodes == 8) {
647 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
648 nodes[4], nodes[5], nodes[6], nodes[7]);
650 else if (NbNodes > 2) {
651 elem = GetMeshDS()->AddPolygonalFace(nodes);
654 // Update Python script
655 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
657 myMesh->GetMeshDS()->Modified();
659 return myMesh->SetIsModified( true ), elem->GetID();
664 //=============================================================================
668 //=============================================================================
669 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsOfNodes)
673 int NbNodes = IDsOfNodes.length();
674 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
675 for (int i = 0; i < NbNodes; i++)
676 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
678 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
680 // Update Python script
681 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
683 myMesh->GetMeshDS()->Modified();
684 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
687 //=============================================================================
691 //=============================================================================
693 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
697 int NbNodes = IDsOfNodes.length();
698 vector< const SMDS_MeshNode*> n(NbNodes);
699 for(int i=0;i<NbNodes;i++)
700 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
702 SMDS_MeshElement* elem = 0;
705 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
706 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
707 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
708 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
709 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
710 n[6],n[7],n[8],n[9]);
712 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
713 n[7],n[8],n[9],n[10],n[11],n[12]);
715 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
716 n[9],n[10],n[11],n[12],n[13],n[14]);
718 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
719 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
720 n[15],n[16],n[17],n[18],n[19]);
724 // Update Python script
725 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
727 myMesh->GetMeshDS()->Modified();
729 return myMesh->SetIsModified( true ), elem->GetID();
734 //=============================================================================
736 * AddPolyhedralVolume
738 //=============================================================================
739 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume (const SMESH::long_array & IDsOfNodes,
740 const SMESH::long_array & Quantities)
744 int NbNodes = IDsOfNodes.length();
745 std::vector<const SMDS_MeshNode*> n (NbNodes);
746 for (int i = 0; i < NbNodes; i++)
748 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDsOfNodes[i]);
749 if (!aNode) return 0;
753 int NbFaces = Quantities.length();
754 std::vector<int> q (NbFaces);
755 for (int j = 0; j < NbFaces; j++)
756 q[j] = Quantities[j];
758 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
760 // Update Python script
761 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
762 << IDsOfNodes << ", " << Quantities << " )";
763 myMesh->GetMeshDS()->Modified();
765 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
768 //=============================================================================
770 * AddPolyhedralVolumeByFaces
772 //=============================================================================
773 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_array & IdsOfFaces)
777 int NbFaces = IdsOfFaces.length();
778 std::vector<const SMDS_MeshNode*> poly_nodes;
779 std::vector<int> quantities (NbFaces);
781 for (int i = 0; i < NbFaces; i++) {
782 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
783 quantities[i] = aFace->NbNodes();
785 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
787 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
791 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
793 // Update Python script
794 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
795 << IdsOfFaces << " )";
796 myMesh->GetMeshDS()->Modified();
798 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
801 //=============================================================================
803 * \brief Bind a node to a vertex
804 * \param NodeID - node ID
805 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
806 * \retval boolean - false if NodeID or VertexID is invalid
808 //=============================================================================
810 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
811 throw (SALOME::SALOME_Exception)
813 Unexpect aCatch(SALOME_SalomeException);
815 SMESHDS_Mesh * mesh = GetMeshDS();
816 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
818 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
820 if ( mesh->MaxShapeIndex() < VertexID )
821 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
823 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
824 if ( shape.ShapeType() != TopAbs_VERTEX )
825 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
827 mesh->SetNodeOnVertex( node, VertexID );
829 myMesh->SetIsModified( true );
832 //=============================================================================
834 * \brief Store node position on an edge
835 * \param NodeID - node ID
836 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
837 * \param paramOnEdge - parameter on edge where the node is located
838 * \retval boolean - false if any parameter is invalid
840 //=============================================================================
842 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
843 CORBA::Double paramOnEdge)
844 throw (SALOME::SALOME_Exception)
846 Unexpect aCatch(SALOME_SalomeException);
848 SMESHDS_Mesh * mesh = GetMeshDS();
849 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
851 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
853 if ( mesh->MaxShapeIndex() < EdgeID )
854 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
856 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
857 if ( shape.ShapeType() != TopAbs_EDGE )
858 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
861 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
862 if ( paramOnEdge < f || paramOnEdge > l )
863 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
865 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
867 myMesh->SetIsModified( true );
870 //=============================================================================
872 * \brief Store node position on a face
873 * \param NodeID - node ID
874 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
875 * \param u - U parameter on face where the node is located
876 * \param v - V parameter on face where the node is located
877 * \retval boolean - false if any parameter is invalid
879 //=============================================================================
881 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
882 CORBA::Double u, CORBA::Double v)
883 throw (SALOME::SALOME_Exception)
885 Unexpect aCatch(SALOME_SalomeException);
887 SMESHDS_Mesh * mesh = GetMeshDS();
888 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
890 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
892 if ( mesh->MaxShapeIndex() < FaceID )
893 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
895 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
896 if ( shape.ShapeType() != TopAbs_FACE )
897 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
899 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
900 bool isOut = ( u < surf.FirstUParameter() ||
901 u > surf.LastUParameter() ||
902 v < surf.FirstVParameter() ||
903 v > surf.LastVParameter() );
907 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
908 << " u( " << surf.FirstUParameter()
909 << "," << surf.LastUParameter()
910 << ") v( " << surf.FirstVParameter()
911 << "," << surf.LastVParameter() << ")" );
913 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
916 mesh->SetNodeOnFace( node, FaceID, u, v );
917 myMesh->SetIsModified( true );
920 //=============================================================================
922 * \brief Bind a node to a solid
923 * \param NodeID - node ID
924 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
925 * \retval boolean - false if NodeID or SolidID is invalid
927 //=============================================================================
929 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
930 throw (SALOME::SALOME_Exception)
932 Unexpect aCatch(SALOME_SalomeException);
934 SMESHDS_Mesh * mesh = GetMeshDS();
935 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
937 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
939 if ( mesh->MaxShapeIndex() < SolidID )
940 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
942 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
943 if ( shape.ShapeType() != TopAbs_SOLID &&
944 shape.ShapeType() != TopAbs_SHELL)
945 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
947 mesh->SetNodeInVolume( node, SolidID );
949 // myMesh->SetIsModified( true ); - SetNodeInVolume() can't prevent re-compute, I believe
952 //=============================================================================
954 * \brief Bind an element to a shape
955 * \param ElementID - element ID
956 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
957 * \retval boolean - false if ElementID or ShapeID is invalid
959 //=============================================================================
961 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
963 throw (SALOME::SALOME_Exception)
965 Unexpect aCatch(SALOME_SalomeException);
967 SMESHDS_Mesh * mesh = GetMeshDS();
968 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
970 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
972 if ( mesh->MaxShapeIndex() < ShapeID )
973 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
975 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
976 if ( shape.ShapeType() != TopAbs_EDGE &&
977 shape.ShapeType() != TopAbs_FACE &&
978 shape.ShapeType() != TopAbs_SOLID &&
979 shape.ShapeType() != TopAbs_SHELL )
980 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
982 mesh->SetMeshElementOnShape( elem, ShapeID );
984 myMesh->SetIsModified( true );
987 //=============================================================================
991 //=============================================================================
993 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
998 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
999 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
1003 // Update Python script
1004 TPythonDump() << "isDone = " << this << ".InverseDiag( "
1005 << NodeID1 << ", " << NodeID2 << " )";
1008 ::SMESH_MeshEditor aMeshEditor( myMesh );
1009 int ret = aMeshEditor.InverseDiag ( n1, n2 );
1010 myMesh->GetMeshDS()->Modified();
1011 myMesh->SetIsModified( true );
1015 //=============================================================================
1019 //=============================================================================
1021 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
1022 CORBA::Long NodeID2)
1026 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
1027 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
1031 // Update Python script
1032 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
1033 << NodeID1 << ", " << NodeID2 << " )";
1035 ::SMESH_MeshEditor aMeshEditor( myMesh );
1037 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
1039 myMesh->GetMeshDS()->Modified();
1041 myMesh->SetIsModified( true ); // issue 0020693
1043 storeResult(aMeshEditor);
1048 //=============================================================================
1052 //=============================================================================
1054 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
1058 ::SMESH_MeshEditor anEditor( myMesh );
1059 for (int i = 0; i < IDsOfElements.length(); i++)
1061 CORBA::Long index = IDsOfElements[i];
1062 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
1064 anEditor.Reorient( elem );
1066 // Update Python script
1067 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
1069 myMesh->GetMeshDS()->Modified();
1070 if ( IDsOfElements.length() )
1071 myMesh->SetIsModified( true ); // issue 0020693
1077 //=============================================================================
1081 //=============================================================================
1083 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
1087 TPythonDump aTPythonDump; // suppress dump in Reorient()
1089 SMESH::long_array_var anElementsId = theObject->GetIDs();
1090 CORBA::Boolean isDone = Reorient(anElementsId);
1092 // Update Python script
1093 aTPythonDump << "isDone = " << this << ".ReorientObject( " << theObject << " )";
1098 //=============================================================================
1102 //=============================================================================
1103 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
1104 SMESH::NumericalFunctor_ptr Criterion,
1105 CORBA::Double MaxAngle)
1109 SMESHDS_Mesh* aMesh = GetMeshDS();
1110 TIDSortedElemSet faces;
1111 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1113 SMESH::NumericalFunctor_i* aNumericalFunctor =
1114 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1115 SMESH::Controls::NumericalFunctorPtr aCrit;
1116 if ( !aNumericalFunctor )
1117 aCrit.reset( new SMESH::Controls::AspectRatio() );
1119 aCrit = aNumericalFunctor->GetNumericalFunctor();
1121 // Update Python script
1122 TPythonDump() << "isDone = " << this << ".TriToQuad( "
1123 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1125 ::SMESH_MeshEditor anEditor( myMesh );
1127 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
1128 myMesh->GetMeshDS()->Modified();
1130 myMesh->SetIsModified( true ); // issue 0020693
1132 storeResult(anEditor);
1138 //=============================================================================
1142 //=============================================================================
1143 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1144 SMESH::NumericalFunctor_ptr Criterion,
1145 CORBA::Double MaxAngle)
1149 TPythonDump aTPythonDump; // suppress dump in TriToQuad()
1150 SMESH::long_array_var anElementsId = theObject->GetIDs();
1151 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
1153 SMESH::NumericalFunctor_i* aNumericalFunctor =
1154 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1156 // Update Python script
1157 aTPythonDump << "isDone = " << this << ".TriToQuadObject("
1158 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1164 //=============================================================================
1168 //=============================================================================
1169 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
1170 SMESH::NumericalFunctor_ptr Criterion)
1174 SMESHDS_Mesh* aMesh = GetMeshDS();
1175 TIDSortedElemSet faces;
1176 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1178 SMESH::NumericalFunctor_i* aNumericalFunctor =
1179 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1180 SMESH::Controls::NumericalFunctorPtr aCrit;
1181 if ( !aNumericalFunctor )
1182 aCrit.reset( new SMESH::Controls::AspectRatio() );
1184 aCrit = aNumericalFunctor->GetNumericalFunctor();
1187 // Update Python script
1188 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1190 ::SMESH_MeshEditor anEditor( myMesh );
1191 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1192 myMesh->GetMeshDS()->Modified();
1194 myMesh->SetIsModified( true ); // issue 0020693
1196 storeResult(anEditor);
1202 //=============================================================================
1206 //=============================================================================
1207 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1208 SMESH::NumericalFunctor_ptr Criterion)
1212 TPythonDump aTPythonDump; // suppress dump in QuadToTri()
1214 SMESH::long_array_var anElementsId = theObject->GetIDs();
1215 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1217 SMESH::NumericalFunctor_i* aNumericalFunctor =
1218 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1220 // Update Python script
1221 aTPythonDump << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1227 //=============================================================================
1231 //=============================================================================
1232 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1233 CORBA::Boolean Diag13)
1237 SMESHDS_Mesh* aMesh = GetMeshDS();
1238 TIDSortedElemSet faces;
1239 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1241 // Update Python script
1242 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1243 << IDsOfElements << ", " << Diag13 << " )";
1245 ::SMESH_MeshEditor anEditor( myMesh );
1246 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1247 myMesh->GetMeshDS()->Modified();
1249 myMesh->SetIsModified( true ); // issue 0020693
1252 storeResult(anEditor);
1258 //=============================================================================
1262 //=============================================================================
1263 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1264 CORBA::Boolean Diag13)
1268 TPythonDump aTPythonDump; // suppress dump in SplitQuad()
1270 SMESH::long_array_var anElementsId = theObject->GetIDs();
1271 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1273 // Update Python script
1274 aTPythonDump << "isDone = " << this << ".SplitQuadObject( "
1275 << theObject << ", " << Diag13 << " )";
1281 //=============================================================================
1285 //=============================================================================
1286 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1287 SMESH::NumericalFunctor_ptr Criterion)
1291 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1292 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1294 SMESH::NumericalFunctor_i* aNumericalFunctor =
1295 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1296 SMESH::Controls::NumericalFunctorPtr aCrit;
1297 if (aNumericalFunctor)
1298 aCrit = aNumericalFunctor->GetNumericalFunctor();
1300 aCrit.reset(new SMESH::Controls::AspectRatio());
1302 ::SMESH_MeshEditor anEditor (myMesh);
1303 return anEditor.BestSplit(quad, aCrit);
1308 //================================================================================
1310 * \brief Split volumic elements into tetrahedrons
1312 //================================================================================
1314 void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems,
1315 CORBA::Short methodFlags)
1316 throw (SALOME::SALOME_Exception)
1318 Unexpect aCatch(SALOME_SalomeException);
1322 SMESH::long_array_var anElementsId = elems->GetIDs();
1323 TIDSortedElemSet elemSet;
1324 arrayToSet( anElementsId, GetMeshDS(), elemSet, SMDSAbs_Volume );
1326 ::SMESH_MeshEditor anEditor (myMesh);
1327 anEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags ));
1328 myMesh->GetMeshDS()->Modified();
1330 storeResult(anEditor);
1332 // if ( myLastCreatedElems.length() ) - it does not influence Compute()
1333 // myMesh->SetIsModified( true ); // issue 0020693
1335 TPythonDump() << this << ".SplitVolumesIntoTetra( "
1336 << elems << ", " << methodFlags << " )";
1339 //=======================================================================
1342 //=======================================================================
1345 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1346 const SMESH::long_array & IDsOfFixedNodes,
1347 CORBA::Long MaxNbOfIterations,
1348 CORBA::Double MaxAspectRatio,
1349 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1351 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1352 MaxAspectRatio, Method, false );
1356 //=======================================================================
1357 //function : SmoothParametric
1359 //=======================================================================
1362 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1363 const SMESH::long_array & IDsOfFixedNodes,
1364 CORBA::Long MaxNbOfIterations,
1365 CORBA::Double MaxAspectRatio,
1366 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1368 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1369 MaxAspectRatio, Method, true );
1373 //=======================================================================
1374 //function : SmoothObject
1376 //=======================================================================
1379 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1380 const SMESH::long_array & IDsOfFixedNodes,
1381 CORBA::Long MaxNbOfIterations,
1382 CORBA::Double MaxAspectRatio,
1383 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1385 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1386 MaxAspectRatio, Method, false);
1390 //=======================================================================
1391 //function : SmoothParametricObject
1393 //=======================================================================
1396 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1397 const SMESH::long_array & IDsOfFixedNodes,
1398 CORBA::Long MaxNbOfIterations,
1399 CORBA::Double MaxAspectRatio,
1400 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1402 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1403 MaxAspectRatio, Method, true);
1407 //=============================================================================
1411 //=============================================================================
1414 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1415 const SMESH::long_array & IDsOfFixedNodes,
1416 CORBA::Long MaxNbOfIterations,
1417 CORBA::Double MaxAspectRatio,
1418 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1423 SMESHDS_Mesh* aMesh = GetMeshDS();
1425 TIDSortedElemSet elements;
1426 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1428 set<const SMDS_MeshNode*> fixedNodes;
1429 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1430 CORBA::Long index = IDsOfFixedNodes[i];
1431 const SMDS_MeshNode * node = aMesh->FindNode(index);
1433 fixedNodes.insert( node );
1435 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1436 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1437 method = ::SMESH_MeshEditor::CENTROIDAL;
1439 ::SMESH_MeshEditor anEditor( myMesh );
1440 anEditor.Smooth(elements, fixedNodes, method,
1441 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1443 myMesh->GetMeshDS()->Modified();
1444 myMesh->SetIsModified( true ); // issue 0020693
1446 storeResult(anEditor);
1448 // Update Python script
1449 TPythonDump() << "isDone = " << this << "."
1450 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1451 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1452 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1453 << "SMESH.SMESH_MeshEditor."
1454 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1455 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1461 //=============================================================================
1465 //=============================================================================
1468 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1469 const SMESH::long_array & IDsOfFixedNodes,
1470 CORBA::Long MaxNbOfIterations,
1471 CORBA::Double MaxAspectRatio,
1472 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1477 TPythonDump aTPythonDump; // suppress dump in smooth()
1479 SMESH::long_array_var anElementsId = theObject->GetIDs();
1480 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1481 MaxAspectRatio, Method, IsParametric);
1483 // Update Python script
1484 aTPythonDump << "isDone = " << this << "."
1485 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1486 << theObject << ", " << IDsOfFixedNodes << ", "
1487 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1488 << "SMESH.SMESH_MeshEditor."
1489 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1490 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1496 //=============================================================================
1500 //=============================================================================
1502 void SMESH_MeshEditor_i::RenumberNodes()
1504 // Update Python script
1505 TPythonDump() << this << ".RenumberNodes()";
1507 GetMeshDS()->Renumber( true );
1511 //=============================================================================
1515 //=============================================================================
1517 void SMESH_MeshEditor_i::RenumberElements()
1519 // Update Python script
1520 TPythonDump() << this << ".RenumberElements()";
1522 GetMeshDS()->Renumber( false );
1525 //=======================================================================
1527 * \brief Return groups by their IDs
1529 //=======================================================================
1531 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1535 myMesh_i->CreateGroupServants();
1536 return myMesh_i->GetGroups( *groupIDs );
1539 //=======================================================================
1540 //function : rotationSweep
1542 //=======================================================================
1544 SMESH::ListOfGroups*
1545 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1546 const SMESH::AxisStruct & theAxis,
1547 CORBA::Double theAngleInRadians,
1548 CORBA::Long theNbOfSteps,
1549 CORBA::Double theTolerance,
1550 const bool theMakeGroups,
1551 const SMDSAbs_ElementType theElementType)
1555 TIDSortedElemSet inElements, copyElements;
1556 arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType);
1558 TIDSortedElemSet* workElements = & inElements;
1559 TPreviewMesh tmpMesh( SMDSAbs_Face );
1560 SMESH_Mesh* mesh = 0;
1561 bool makeWalls=true;
1562 if ( myPreviewMode )
1564 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1565 tmpMesh.Copy( inElements, copyElements, select, avoid );
1567 workElements = & copyElements;
1568 //makeWalls = false;
1575 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1576 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1578 ::SMESH_MeshEditor anEditor( mesh );
1579 ::SMESH_MeshEditor::PGroupIDs groupIds =
1580 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1581 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1582 storeResult(anEditor);
1583 myMesh->GetMeshDS()->Modified();
1585 // myMesh->SetIsModified( true ); -- it does not influence Compute()
1587 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1590 //=======================================================================
1591 //function : RotationSweep
1593 //=======================================================================
1595 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1596 const SMESH::AxisStruct & theAxis,
1597 CORBA::Double theAngleInRadians,
1598 CORBA::Long theNbOfSteps,
1599 CORBA::Double theTolerance)
1601 if ( !myPreviewMode ) {
1602 TPythonDump() << this << ".RotationSweep( "
1603 << theIDsOfElements << ", "
1605 << theAngleInRadians << ", "
1606 << theNbOfSteps << ", "
1607 << theTolerance << " )";
1609 rotationSweep(theIDsOfElements,
1617 //=======================================================================
1618 //function : RotationSweepMakeGroups
1620 //=======================================================================
1622 SMESH::ListOfGroups*
1623 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1624 const SMESH::AxisStruct& theAxis,
1625 CORBA::Double theAngleInRadians,
1626 CORBA::Long theNbOfSteps,
1627 CORBA::Double theTolerance)
1629 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1631 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1637 if (!myPreviewMode) {
1638 DumpGroupsList(aPythonDump, aGroups);
1639 aPythonDump << this << ".RotationSweepMakeGroups( "
1640 << theIDsOfElements << ", "
1642 << theAngleInRadians << ", "
1643 << theNbOfSteps << ", "
1644 << theTolerance << " )";
1649 //=======================================================================
1650 //function : RotationSweepObject
1652 //=======================================================================
1654 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1655 const SMESH::AxisStruct & theAxis,
1656 CORBA::Double theAngleInRadians,
1657 CORBA::Long theNbOfSteps,
1658 CORBA::Double theTolerance)
1660 if ( !myPreviewMode ) {
1661 TPythonDump() << this << ".RotationSweepObject( "
1662 << theObject << ", "
1664 << theAngleInRadians << ", "
1665 << theNbOfSteps << ", "
1666 << theTolerance << " )";
1668 SMESH::long_array_var anElementsId = theObject->GetIDs();
1669 rotationSweep(anElementsId,
1677 //=======================================================================
1678 //function : RotationSweepObject1D
1680 //=======================================================================
1682 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1683 const SMESH::AxisStruct & theAxis,
1684 CORBA::Double theAngleInRadians,
1685 CORBA::Long theNbOfSteps,
1686 CORBA::Double theTolerance)
1688 if ( !myPreviewMode ) {
1689 TPythonDump() << this << ".RotationSweepObject1D( "
1690 << theObject << ", "
1692 << theAngleInRadians << ", "
1693 << theNbOfSteps << ", "
1694 << theTolerance << " )";
1696 SMESH::long_array_var anElementsId = theObject->GetIDs();
1697 rotationSweep(anElementsId,
1706 //=======================================================================
1707 //function : RotationSweepObject2D
1709 //=======================================================================
1711 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1712 const SMESH::AxisStruct & theAxis,
1713 CORBA::Double theAngleInRadians,
1714 CORBA::Long theNbOfSteps,
1715 CORBA::Double theTolerance)
1717 if ( !myPreviewMode ) {
1718 TPythonDump() << this << ".RotationSweepObject2D( "
1719 << theObject << ", "
1721 << theAngleInRadians << ", "
1722 << theNbOfSteps << ", "
1723 << theTolerance << " )";
1725 SMESH::long_array_var anElementsId = theObject->GetIDs();
1726 rotationSweep(anElementsId,
1735 //=======================================================================
1736 //function : RotationSweepObjectMakeGroups
1738 //=======================================================================
1740 SMESH::ListOfGroups*
1741 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1742 const SMESH::AxisStruct& theAxis,
1743 CORBA::Double theAngleInRadians,
1744 CORBA::Long theNbOfSteps,
1745 CORBA::Double theTolerance)
1747 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1749 SMESH::long_array_var anElementsId = theObject->GetIDs();
1750 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1756 if (!myPreviewMode) {
1757 DumpGroupsList(aPythonDump, aGroups);
1758 aPythonDump << this << ".RotationSweepObjectMakeGroups( "
1759 << theObject << ", "
1761 << theAngleInRadians << ", "
1762 << theNbOfSteps << ", "
1763 << theTolerance << " )";
1768 //=======================================================================
1769 //function : RotationSweepObject1DMakeGroups
1771 //=======================================================================
1773 SMESH::ListOfGroups*
1774 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1775 const SMESH::AxisStruct& theAxis,
1776 CORBA::Double theAngleInRadians,
1777 CORBA::Long theNbOfSteps,
1778 CORBA::Double theTolerance)
1780 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1782 SMESH::long_array_var anElementsId = theObject->GetIDs();
1783 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1790 if (!myPreviewMode) {
1791 DumpGroupsList(aPythonDump, aGroups);
1792 aPythonDump << this << ".RotationSweepObject1DMakeGroups( "
1793 << theObject << ", "
1795 << theAngleInRadians << ", "
1796 << theNbOfSteps << ", "
1797 << theTolerance << " )";
1802 //=======================================================================
1803 //function : RotationSweepObject2DMakeGroups
1805 //=======================================================================
1807 SMESH::ListOfGroups*
1808 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1809 const SMESH::AxisStruct& theAxis,
1810 CORBA::Double theAngleInRadians,
1811 CORBA::Long theNbOfSteps,
1812 CORBA::Double theTolerance)
1814 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1816 SMESH::long_array_var anElementsId = theObject->GetIDs();
1817 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1824 if (!myPreviewMode) {
1825 DumpGroupsList(aPythonDump, aGroups);
1826 aPythonDump << this << ".RotationSweepObject2DMakeGroups( "
1827 << theObject << ", "
1829 << theAngleInRadians << ", "
1830 << theNbOfSteps << ", "
1831 << theTolerance << " )";
1837 //=======================================================================
1838 //function : extrusionSweep
1840 //=======================================================================
1842 SMESH::ListOfGroups*
1843 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1844 const SMESH::DirStruct & theStepVector,
1845 CORBA::Long theNbOfSteps,
1847 const SMDSAbs_ElementType theElementType)
1855 TIDSortedElemSet elements, copyElements;
1856 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1858 const SMESH::PointStruct * P = &theStepVector.PS;
1859 gp_Vec stepVec( P->x, P->y, P->z );
1861 TIDSortedElemSet* workElements = & elements;
1862 TPreviewMesh tmpMesh( SMDSAbs_Face );
1863 SMESH_Mesh* mesh = myMesh;
1865 if ( myPreviewMode ) {
1866 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1867 tmpMesh.Copy( elements, copyElements, select, avoid );
1869 workElements = & copyElements;
1870 theMakeGroups = false;
1873 TElemOfElemListMap aHystory;
1874 ::SMESH_MeshEditor anEditor( mesh );
1875 ::SMESH_MeshEditor::PGroupIDs groupIds =
1876 anEditor.ExtrusionSweep (*workElements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1878 myMesh->GetMeshDS()->Modified();
1879 storeResult(anEditor);
1881 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1883 } catch(Standard_Failure) {
1884 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1885 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1890 //=======================================================================
1891 //function : ExtrusionSweep
1893 //=======================================================================
1895 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1896 const SMESH::DirStruct & theStepVector,
1897 CORBA::Long theNbOfSteps)
1899 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1900 if (!myPreviewMode) {
1901 TPythonDump() << this << ".ExtrusionSweep( "
1902 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1907 //=======================================================================
1908 //function : ExtrusionSweepObject
1910 //=======================================================================
1912 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1913 const SMESH::DirStruct & theStepVector,
1914 CORBA::Long theNbOfSteps)
1916 SMESH::long_array_var anElementsId = theObject->GetIDs();
1917 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1918 if (!myPreviewMode) {
1919 TPythonDump() << this << ".ExtrusionSweepObject( "
1920 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1924 //=======================================================================
1925 //function : ExtrusionSweepObject1D
1927 //=======================================================================
1929 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1930 const SMESH::DirStruct & theStepVector,
1931 CORBA::Long theNbOfSteps)
1933 SMESH::long_array_var anElementsId = theObject->GetIDs();
1934 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1935 if ( !myPreviewMode ) {
1936 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1937 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1941 //=======================================================================
1942 //function : ExtrusionSweepObject2D
1944 //=======================================================================
1946 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1947 const SMESH::DirStruct & theStepVector,
1948 CORBA::Long theNbOfSteps)
1950 SMESH::long_array_var anElementsId = theObject->GetIDs();
1951 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1952 if ( !myPreviewMode ) {
1953 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1954 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1958 //=======================================================================
1959 //function : ExtrusionSweepMakeGroups
1961 //=======================================================================
1963 SMESH::ListOfGroups*
1964 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1965 const SMESH::DirStruct& theStepVector,
1966 CORBA::Long theNbOfSteps)
1968 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1970 SMESH::ListOfGroups* aGroups = extrusionSweep(theIDsOfElements, theStepVector, theNbOfSteps, true);
1972 if (!myPreviewMode) {
1973 DumpGroupsList(aPythonDump, aGroups);
1974 aPythonDump << this << ".ExtrusionSweepMakeGroups( " << theIDsOfElements
1975 << ", " << theStepVector <<", " << theNbOfSteps << " )";
1980 //=======================================================================
1981 //function : ExtrusionSweepObjectMakeGroups
1983 //=======================================================================
1985 SMESH::ListOfGroups*
1986 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1987 const SMESH::DirStruct& theStepVector,
1988 CORBA::Long theNbOfSteps)
1990 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1992 SMESH::long_array_var anElementsId = theObject->GetIDs();
1993 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector, theNbOfSteps, true);
1995 if (!myPreviewMode) {
1996 DumpGroupsList(aPythonDump, aGroups);
1997 aPythonDump << this << ".ExtrusionSweepObjectMakeGroups( " << theObject
1998 << ", " << theStepVector << ", " << theNbOfSteps << " )";
2003 //=======================================================================
2004 //function : ExtrusionSweepObject1DMakeGroups
2006 //=======================================================================
2008 SMESH::ListOfGroups*
2009 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2010 const SMESH::DirStruct& theStepVector,
2011 CORBA::Long theNbOfSteps)
2013 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2015 SMESH::long_array_var anElementsId = theObject->GetIDs();
2016 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector,
2017 theNbOfSteps, true, SMDSAbs_Edge);
2018 if (!myPreviewMode) {
2019 DumpGroupsList(aPythonDump, aGroups);
2020 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( " << theObject
2021 << ", " << theStepVector << ", " << theNbOfSteps << " )";
2026 //=======================================================================
2027 //function : ExtrusionSweepObject2DMakeGroups
2029 //=======================================================================
2031 SMESH::ListOfGroups*
2032 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2033 const SMESH::DirStruct& theStepVector,
2034 CORBA::Long theNbOfSteps)
2036 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2038 SMESH::long_array_var anElementsId = theObject->GetIDs();
2039 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector,
2040 theNbOfSteps, true, SMDSAbs_Face);
2041 if (!myPreviewMode) {
2042 DumpGroupsList(aPythonDump, aGroups);
2043 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( " << theObject
2044 << ", " << theStepVector << ", " << theNbOfSteps << " )";
2050 //=======================================================================
2051 //function : advancedExtrusion
2053 //=======================================================================
2055 SMESH::ListOfGroups*
2056 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
2057 const SMESH::DirStruct & theStepVector,
2058 CORBA::Long theNbOfSteps,
2059 CORBA::Long theExtrFlags,
2060 CORBA::Double theSewTolerance,
2061 const bool theMakeGroups)
2065 TIDSortedElemSet elements;
2066 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2068 const SMESH::PointStruct * P = &theStepVector.PS;
2069 gp_Vec stepVec( P->x, P->y, P->z );
2071 ::SMESH_MeshEditor anEditor( myMesh );
2072 TElemOfElemListMap aHystory;
2073 ::SMESH_MeshEditor::PGroupIDs groupIds =
2074 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
2075 theMakeGroups, theExtrFlags, theSewTolerance);
2076 storeResult(anEditor);
2078 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2081 //=======================================================================
2082 //function : AdvancedExtrusion
2084 //=======================================================================
2086 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
2087 const SMESH::DirStruct & theStepVector,
2088 CORBA::Long theNbOfSteps,
2089 CORBA::Long theExtrFlags,
2090 CORBA::Double theSewTolerance)
2092 if ( !myPreviewMode ) {
2093 TPythonDump() << "stepVector = " << theStepVector;
2094 TPythonDump() << this << ".AdvancedExtrusion("
2097 << theNbOfSteps << ","
2098 << theExtrFlags << ", "
2099 << theSewTolerance << " )";
2101 advancedExtrusion( theIDsOfElements,
2109 //=======================================================================
2110 //function : AdvancedExtrusionMakeGroups
2112 //=======================================================================
2113 SMESH::ListOfGroups*
2114 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
2115 const SMESH::DirStruct& theStepVector,
2116 CORBA::Long theNbOfSteps,
2117 CORBA::Long theExtrFlags,
2118 CORBA::Double theSewTolerance)
2120 if (!myPreviewMode) {
2121 TPythonDump() << "stepVector = " << theStepVector;
2123 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2125 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
2132 if (!myPreviewMode) {
2133 DumpGroupsList(aPythonDump, aGroups);
2134 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
2137 << theNbOfSteps << ","
2138 << theExtrFlags << ", "
2139 << theSewTolerance << " )";
2145 //================================================================================
2147 * \brief Convert extrusion error to IDL enum
2149 //================================================================================
2151 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2153 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
2157 RETCASE( EXTR_NO_ELEMENTS );
2158 RETCASE( EXTR_PATH_NOT_EDGE );
2159 RETCASE( EXTR_BAD_PATH_SHAPE );
2160 RETCASE( EXTR_BAD_STARTING_NODE );
2161 RETCASE( EXTR_BAD_ANGLES_NUMBER );
2162 RETCASE( EXTR_CANT_GET_TANGENT );
2164 return SMESH::SMESH_MeshEditor::EXTR_OK;
2168 //=======================================================================
2169 //function : extrusionAlongPath
2171 //=======================================================================
2172 SMESH::ListOfGroups*
2173 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2174 SMESH::SMESH_Mesh_ptr thePathMesh,
2175 GEOM::GEOM_Object_ptr thePathShape,
2176 CORBA::Long theNodeStart,
2177 CORBA::Boolean theHasAngles,
2178 const SMESH::double_array & theAngles,
2179 CORBA::Boolean theHasRefPoint,
2180 const SMESH::PointStruct & theRefPoint,
2181 const bool theMakeGroups,
2182 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
2183 const SMDSAbs_ElementType theElementType)
2185 MESSAGE("extrusionAlongPath");
2188 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
2189 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2192 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2194 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2195 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2197 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
2198 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2202 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
2204 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2208 TIDSortedElemSet elements;
2209 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
2211 list<double> angles;
2212 for (int i = 0; i < theAngles.length(); i++) {
2213 angles.push_back( theAngles[i] );
2216 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
2218 int nbOldGroups = myMesh->NbGroup();
2220 ::SMESH_MeshEditor anEditor( myMesh );
2221 ::SMESH_MeshEditor::Extrusion_Error error =
2222 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
2223 theHasAngles, angles, false,
2224 theHasRefPoint, refPnt, theMakeGroups );
2225 myMesh->GetMeshDS()->Modified();
2226 storeResult(anEditor);
2227 theError = convExtrError( error );
2229 if ( theMakeGroups ) {
2230 list<int> groupIDs = myMesh->GetGroupIds();
2231 list<int>::iterator newBegin = groupIDs.begin();
2232 std::advance( newBegin, nbOldGroups ); // skip old groups
2233 groupIDs.erase( groupIDs.begin(), newBegin );
2234 return getGroups( & groupIDs );
2240 //=======================================================================
2241 //function : extrusionAlongPathX
2243 //=======================================================================
2244 SMESH::ListOfGroups*
2245 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2246 SMESH::SMESH_IDSource_ptr Path,
2247 CORBA::Long NodeStart,
2248 CORBA::Boolean HasAngles,
2249 const SMESH::double_array& Angles,
2250 CORBA::Boolean LinearVariation,
2251 CORBA::Boolean HasRefPoint,
2252 const SMESH::PointStruct& RefPoint,
2254 const SMDSAbs_ElementType ElementType,
2255 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2257 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2261 list<double> angles;
2262 for (int i = 0; i < Angles.length(); i++) {
2263 angles.push_back( Angles[i] );
2265 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2266 int nbOldGroups = myMesh->NbGroup();
2268 if ( Path->_is_nil() ) {
2269 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2273 TIDSortedElemSet elements, copyElements;
2274 arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
2276 TIDSortedElemSet* workElements = &elements;
2277 TPreviewMesh tmpMesh( SMDSAbs_Face );
2278 SMESH_Mesh* mesh = myMesh;
2280 if ( myPreviewMode )
2282 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
2283 tmpMesh.Copy( elements, copyElements, select, avoid );
2285 workElements = & copyElements;
2289 ::SMESH_MeshEditor anEditor( mesh );
2290 ::SMESH_MeshEditor::Extrusion_Error error;
2292 if ( SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path ))
2295 SMDS_MeshNode* aNodeStart =
2296 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2297 if ( !aNodeStart ) {
2298 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2301 error = anEditor.ExtrusionAlongTrack( *workElements, &(aMeshImp->GetImpl()), aNodeStart,
2302 HasAngles, angles, LinearVariation,
2303 HasRefPoint, refPnt, MakeGroups );
2304 myMesh->GetMeshDS()->Modified();
2306 else if ( SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path ))
2309 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
2310 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
2311 SMDS_MeshNode* aNodeStart =
2312 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2313 if ( !aNodeStart ) {
2314 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2317 SMESH_subMesh* aSubMesh =
2318 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
2319 error = anEditor.ExtrusionAlongTrack( *workElements, aSubMesh, aNodeStart,
2320 HasAngles, angles, LinearVariation,
2321 HasRefPoint, refPnt, MakeGroups );
2322 myMesh->GetMeshDS()->Modified();
2324 else if ( SMESH::DownCast<SMESH_Group_i*>( Path ))
2326 // path as group of 1D elements
2332 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2336 storeResult(anEditor);
2337 Error = convExtrError( error );
2340 list<int> groupIDs = myMesh->GetGroupIds();
2341 list<int>::iterator newBegin = groupIDs.begin();
2342 std::advance( newBegin, nbOldGroups ); // skip old groups
2343 groupIDs.erase( groupIDs.begin(), newBegin );
2344 return getGroups( & groupIDs );
2350 //=======================================================================
2351 //function : ExtrusionAlongPath
2353 //=======================================================================
2354 SMESH::SMESH_MeshEditor::Extrusion_Error
2355 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2356 SMESH::SMESH_Mesh_ptr thePathMesh,
2357 GEOM::GEOM_Object_ptr thePathShape,
2358 CORBA::Long theNodeStart,
2359 CORBA::Boolean theHasAngles,
2360 const SMESH::double_array & theAngles,
2361 CORBA::Boolean theHasRefPoint,
2362 const SMESH::PointStruct & theRefPoint)
2364 MESSAGE("ExtrusionAlongPath");
2365 if ( !myPreviewMode ) {
2366 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
2367 << theIDsOfElements << ", "
2368 << thePathMesh << ", "
2369 << thePathShape << ", "
2370 << theNodeStart << ", "
2371 << theHasAngles << ", "
2372 << theAngles << ", "
2373 << theHasRefPoint << ", "
2374 << "SMESH.PointStruct( "
2375 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2376 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2377 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2379 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2380 extrusionAlongPath( theIDsOfElements,
2393 //=======================================================================
2394 //function : ExtrusionAlongPathObject
2396 //=======================================================================
2397 SMESH::SMESH_MeshEditor::Extrusion_Error
2398 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
2399 SMESH::SMESH_Mesh_ptr thePathMesh,
2400 GEOM::GEOM_Object_ptr thePathShape,
2401 CORBA::Long theNodeStart,
2402 CORBA::Boolean theHasAngles,
2403 const SMESH::double_array & theAngles,
2404 CORBA::Boolean theHasRefPoint,
2405 const SMESH::PointStruct & theRefPoint)
2407 if ( !myPreviewMode ) {
2408 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
2409 << theObject << ", "
2410 << thePathMesh << ", "
2411 << thePathShape << ", "
2412 << theNodeStart << ", "
2413 << theHasAngles << ", "
2414 << theAngles << ", "
2415 << theHasRefPoint << ", "
2416 << "SMESH.PointStruct( "
2417 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2418 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2419 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2421 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2422 SMESH::long_array_var anElementsId = theObject->GetIDs();
2423 extrusionAlongPath( anElementsId,
2436 //=======================================================================
2437 //function : ExtrusionAlongPathObject1D
2439 //=======================================================================
2440 SMESH::SMESH_MeshEditor::Extrusion_Error
2441 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
2442 SMESH::SMESH_Mesh_ptr thePathMesh,
2443 GEOM::GEOM_Object_ptr thePathShape,
2444 CORBA::Long theNodeStart,
2445 CORBA::Boolean theHasAngles,
2446 const SMESH::double_array & theAngles,
2447 CORBA::Boolean theHasRefPoint,
2448 const SMESH::PointStruct & theRefPoint)
2450 if ( !myPreviewMode ) {
2451 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
2452 << theObject << ", "
2453 << thePathMesh << ", "
2454 << thePathShape << ", "
2455 << theNodeStart << ", "
2456 << theHasAngles << ", "
2457 << theAngles << ", "
2458 << theHasRefPoint << ", "
2459 << "SMESH.PointStruct( "
2460 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2461 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2462 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2464 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2465 SMESH::long_array_var anElementsId = theObject->GetIDs();
2466 extrusionAlongPath( anElementsId,
2480 //=======================================================================
2481 //function : ExtrusionAlongPathObject2D
2483 //=======================================================================
2484 SMESH::SMESH_MeshEditor::Extrusion_Error
2485 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
2486 SMESH::SMESH_Mesh_ptr thePathMesh,
2487 GEOM::GEOM_Object_ptr thePathShape,
2488 CORBA::Long theNodeStart,
2489 CORBA::Boolean theHasAngles,
2490 const SMESH::double_array & theAngles,
2491 CORBA::Boolean theHasRefPoint,
2492 const SMESH::PointStruct & theRefPoint)
2494 if ( !myPreviewMode ) {
2495 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
2496 << theObject << ", "
2497 << thePathMesh << ", "
2498 << thePathShape << ", "
2499 << theNodeStart << ", "
2500 << theHasAngles << ", "
2501 << theAngles << ", "
2502 << theHasRefPoint << ", "
2503 << "SMESH.PointStruct( "
2504 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2505 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2506 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2508 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2509 SMESH::long_array_var anElementsId = theObject->GetIDs();
2510 extrusionAlongPath( anElementsId,
2525 //=======================================================================
2526 //function : ExtrusionAlongPathMakeGroups
2528 //=======================================================================
2529 SMESH::ListOfGroups*
2530 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2531 SMESH::SMESH_Mesh_ptr thePathMesh,
2532 GEOM::GEOM_Object_ptr thePathShape,
2533 CORBA::Long theNodeStart,
2534 CORBA::Boolean theHasAngles,
2535 const SMESH::double_array& theAngles,
2536 CORBA::Boolean theHasRefPoint,
2537 const SMESH::PointStruct& theRefPoint,
2538 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2540 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2542 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2552 if (!myPreviewMode) {
2553 bool isDumpGroups = aGroups && aGroups->length() > 0;
2555 aPythonDump << "(" << aGroups << ", error)";
2557 aPythonDump <<"error";
2559 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2560 << theIDsOfElements << ", "
2561 << thePathMesh << ", "
2562 << thePathShape << ", "
2563 << theNodeStart << ", "
2564 << theHasAngles << ", "
2565 << theAngles << ", "
2566 << theHasRefPoint << ", "
2567 << "SMESH.PointStruct( "
2568 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2569 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2570 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2575 //=======================================================================
2576 //function : ExtrusionAlongPathObjectMakeGroups
2578 //=======================================================================
2579 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2580 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2581 SMESH::SMESH_Mesh_ptr thePathMesh,
2582 GEOM::GEOM_Object_ptr thePathShape,
2583 CORBA::Long theNodeStart,
2584 CORBA::Boolean theHasAngles,
2585 const SMESH::double_array& theAngles,
2586 CORBA::Boolean theHasRefPoint,
2587 const SMESH::PointStruct& theRefPoint,
2588 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2590 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2592 SMESH::long_array_var anElementsId = theObject->GetIDs();
2593 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2604 if (!myPreviewMode) {
2605 bool isDumpGroups = aGroups && aGroups->length() > 0;
2607 aPythonDump << "(" << aGroups << ", error)";
2609 aPythonDump <<"error";
2611 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2612 << theObject << ", "
2613 << thePathMesh << ", "
2614 << thePathShape << ", "
2615 << theNodeStart << ", "
2616 << theHasAngles << ", "
2617 << theAngles << ", "
2618 << theHasRefPoint << ", "
2619 << "SMESH.PointStruct( "
2620 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2621 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2622 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2627 //=======================================================================
2628 //function : ExtrusionAlongPathObject1DMakeGroups
2630 //=======================================================================
2631 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2632 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2633 SMESH::SMESH_Mesh_ptr thePathMesh,
2634 GEOM::GEOM_Object_ptr thePathShape,
2635 CORBA::Long theNodeStart,
2636 CORBA::Boolean theHasAngles,
2637 const SMESH::double_array& theAngles,
2638 CORBA::Boolean theHasRefPoint,
2639 const SMESH::PointStruct& theRefPoint,
2640 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2642 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2644 SMESH::long_array_var anElementsId = theObject->GetIDs();
2645 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2657 if (!myPreviewMode) {
2658 bool isDumpGroups = aGroups && aGroups->length() > 0;
2660 aPythonDump << "(" << aGroups << ", error)";
2662 aPythonDump << "error";
2664 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
2665 << theObject << ", "
2666 << thePathMesh << ", "
2667 << thePathShape << ", "
2668 << theNodeStart << ", "
2669 << theHasAngles << ", "
2670 << theAngles << ", "
2671 << theHasRefPoint << ", "
2672 << "SMESH.PointStruct( "
2673 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2674 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2675 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2680 //=======================================================================
2681 //function : ExtrusionAlongPathObject2DMakeGroups
2683 //=======================================================================
2684 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2685 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2686 SMESH::SMESH_Mesh_ptr thePathMesh,
2687 GEOM::GEOM_Object_ptr thePathShape,
2688 CORBA::Long theNodeStart,
2689 CORBA::Boolean theHasAngles,
2690 const SMESH::double_array& theAngles,
2691 CORBA::Boolean theHasRefPoint,
2692 const SMESH::PointStruct& theRefPoint,
2693 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2695 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2697 SMESH::long_array_var anElementsId = theObject->GetIDs();
2698 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2710 if (!myPreviewMode) {
2711 bool isDumpGroups = aGroups && aGroups->length() > 0;
2713 aPythonDump << "(" << aGroups << ", error)";
2715 aPythonDump << "error";
2717 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
2718 << theObject << ", "
2719 << thePathMesh << ", "
2720 << thePathShape << ", "
2721 << theNodeStart << ", "
2722 << theHasAngles << ", "
2723 << theAngles << ", "
2724 << theHasRefPoint << ", "
2725 << "SMESH.PointStruct( "
2726 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2727 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2728 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2734 //=======================================================================
2735 //function : ExtrusionAlongPathObjX
2737 //=======================================================================
2738 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2739 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
2740 SMESH::SMESH_IDSource_ptr Path,
2741 CORBA::Long NodeStart,
2742 CORBA::Boolean HasAngles,
2743 const SMESH::double_array& Angles,
2744 CORBA::Boolean LinearVariation,
2745 CORBA::Boolean HasRefPoint,
2746 const SMESH::PointStruct& RefPoint,
2747 CORBA::Boolean MakeGroups,
2748 SMESH::ElementType ElemType,
2749 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2751 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2753 SMESH::long_array_var anElementsId = Object->GetIDs();
2754 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2763 (SMDSAbs_ElementType)ElemType,
2766 if (!myPreviewMode) {
2767 bool isDumpGroups = aGroups && aGroups->length() > 0;
2769 aPythonDump << "(" << *aGroups << ", error)";
2771 aPythonDump << "error";
2773 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2776 << NodeStart << ", "
2777 << HasAngles << ", "
2779 << LinearVariation << ", "
2780 << HasRefPoint << ", "
2781 << "SMESH.PointStruct( "
2782 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2783 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2784 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2785 << MakeGroups << ", "
2786 << ElemType << " )";
2792 //=======================================================================
2793 //function : ExtrusionAlongPathX
2795 //=======================================================================
2796 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2797 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2798 SMESH::SMESH_IDSource_ptr Path,
2799 CORBA::Long NodeStart,
2800 CORBA::Boolean HasAngles,
2801 const SMESH::double_array& Angles,
2802 CORBA::Boolean LinearVariation,
2803 CORBA::Boolean HasRefPoint,
2804 const SMESH::PointStruct& RefPoint,
2805 CORBA::Boolean MakeGroups,
2806 SMESH::ElementType ElemType,
2807 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2809 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2811 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2820 (SMDSAbs_ElementType)ElemType,
2823 if (!myPreviewMode) {
2824 bool isDumpGroups = aGroups && aGroups->length() > 0;
2826 aPythonDump << "(" << *aGroups << ", error)";
2828 aPythonDump <<"error";
2830 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2831 << IDsOfElements << ", "
2833 << NodeStart << ", "
2834 << HasAngles << ", "
2836 << LinearVariation << ", "
2837 << HasRefPoint << ", "
2838 << "SMESH.PointStruct( "
2839 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2840 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2841 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2842 << MakeGroups << ", "
2843 << ElemType << " )";
2849 //================================================================================
2851 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2852 * of given angles along path steps
2853 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2854 * which proceeds the extrusion
2855 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2856 * is used to define the sub-mesh for the path
2858 //================================================================================
2860 SMESH::double_array*
2861 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2862 GEOM::GEOM_Object_ptr thePathShape,
2863 const SMESH::double_array & theAngles)
2865 SMESH::double_array_var aResult = new SMESH::double_array();
2866 int nbAngles = theAngles.length();
2867 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2869 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2870 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2871 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2872 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2873 return aResult._retn();
2874 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2875 if ( nbSteps == nbAngles )
2877 aResult.inout() = theAngles;
2881 aResult->length( nbSteps );
2882 double rAn2St = double( nbAngles ) / double( nbSteps );
2883 double angPrev = 0, angle;
2884 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2886 double angCur = rAn2St * ( iSt+1 );
2887 double angCurFloor = floor( angCur );
2888 double angPrevFloor = floor( angPrev );
2889 if ( angPrevFloor == angCurFloor )
2890 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2893 int iP = int( angPrevFloor );
2894 double angPrevCeil = ceil(angPrev);
2895 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2897 int iC = int( angCurFloor );
2898 if ( iC < nbAngles )
2899 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2901 iP = int( angPrevCeil );
2903 angle += theAngles[ iC ];
2905 aResult[ iSt ] = angle;
2910 // Update Python script
2911 TPythonDump() << "rotAngles = " << theAngles;
2912 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2913 << thePathMesh << ", "
2914 << thePathShape << ", "
2917 return aResult._retn();
2921 //=======================================================================
2924 //=======================================================================
2926 SMESH::ListOfGroups*
2927 SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements,
2928 const SMESH::AxisStruct & theAxis,
2929 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2930 CORBA::Boolean theCopy,
2932 ::SMESH_Mesh* theTargetMesh)
2936 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2937 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2939 if ( theTargetMesh )
2943 switch ( theMirrorType ) {
2944 case SMESH::SMESH_MeshEditor::POINT:
2945 aTrsf.SetMirror( P );
2947 case SMESH::SMESH_MeshEditor::AXIS:
2948 aTrsf.SetMirror( gp_Ax1( P, V ));
2951 aTrsf.SetMirror( gp_Ax2( P, V ));
2954 TIDSortedElemSet copyElements;
2955 TPreviewMesh tmpMesh;
2956 TIDSortedElemSet* workElements = & theElements;
2957 SMESH_Mesh* mesh = myMesh;
2959 if ( myPreviewMode )
2961 tmpMesh.Copy( theElements, copyElements);
2962 if ( !theCopy && !theTargetMesh )
2964 TIDSortedElemSet elemsAround, elemsAroundCopy;
2965 getElementsAround( theElements, GetMeshDS(), elemsAround );
2966 tmpMesh.Copy( elemsAround, elemsAroundCopy);
2969 workElements = & copyElements;
2970 theMakeGroups = false;
2973 ::SMESH_MeshEditor anEditor( mesh );
2974 ::SMESH_MeshEditor::PGroupIDs groupIds =
2975 anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2977 if(theCopy || myPreviewMode)
2978 storeResult(anEditor);
2981 myMesh->SetIsModified( true );
2982 myMesh->GetMeshDS()->Modified();
2984 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2987 //=======================================================================
2990 //=======================================================================
2992 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2993 const SMESH::AxisStruct & theAxis,
2994 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2995 CORBA::Boolean theCopy)
2997 if ( !myPreviewMode ) {
2998 TPythonDump() << this << ".Mirror( "
2999 << theIDsOfElements << ", "
3001 << mirrorTypeName(theMirrorType) << ", "
3004 if ( theIDsOfElements.length() > 0 )
3006 TIDSortedElemSet elements;
3007 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3008 mirror(elements, theAxis, theMirrorType, theCopy, false);
3013 //=======================================================================
3014 //function : MirrorObject
3016 //=======================================================================
3018 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
3019 const SMESH::AxisStruct & theAxis,
3020 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3021 CORBA::Boolean theCopy)
3023 if ( !myPreviewMode ) {
3024 TPythonDump() << this << ".MirrorObject( "
3025 << theObject << ", "
3027 << mirrorTypeName(theMirrorType) << ", "
3030 TIDSortedElemSet elements;
3032 bool emptyIfIsMesh = myPreviewMode ? false : true;
3034 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, emptyIfIsMesh))
3035 mirror(elements, theAxis, theMirrorType, theCopy, false);
3038 //=======================================================================
3039 //function : MirrorMakeGroups
3041 //=======================================================================
3043 SMESH::ListOfGroups*
3044 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
3045 const SMESH::AxisStruct& theMirror,
3046 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
3048 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3050 SMESH::ListOfGroups * aGroups = 0;
3051 if ( theIDsOfElements.length() > 0 )
3053 TIDSortedElemSet elements;
3054 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3055 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
3057 if (!myPreviewMode) {
3058 DumpGroupsList(aPythonDump, aGroups);
3059 aPythonDump << this << ".MirrorMakeGroups( "
3060 << theIDsOfElements << ", "
3061 << theMirror << ", "
3062 << mirrorTypeName(theMirrorType) << " )";
3067 //=======================================================================
3068 //function : MirrorObjectMakeGroups
3070 //=======================================================================
3072 SMESH::ListOfGroups*
3073 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3074 const SMESH::AxisStruct& theMirror,
3075 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
3077 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3079 SMESH::ListOfGroups * aGroups = 0;
3080 TIDSortedElemSet elements;
3081 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3082 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
3086 DumpGroupsList(aPythonDump,aGroups);
3087 aPythonDump << this << ".MirrorObjectMakeGroups( "
3088 << theObject << ", "
3089 << theMirror << ", "
3090 << mirrorTypeName(theMirrorType) << " )";
3095 //=======================================================================
3096 //function : MirrorMakeMesh
3098 //=======================================================================
3100 SMESH::SMESH_Mesh_ptr
3101 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
3102 const SMESH::AxisStruct& theMirror,
3103 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3104 CORBA::Boolean theCopyGroups,
3105 const char* theMeshName)
3107 SMESH_Mesh_i* mesh_i;
3108 SMESH::SMESH_Mesh_var mesh;
3109 { // open new scope to dump "MakeMesh" command
3110 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3112 TPythonDump pydump; // to prevent dump at mesh creation
3114 mesh = makeMesh( theMeshName );
3115 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3116 if (mesh_i && theIDsOfElements.length() > 0 )
3118 TIDSortedElemSet elements;
3119 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3120 mirror(elements, theMirror, theMirrorType,
3121 false, theCopyGroups, & mesh_i->GetImpl());
3122 mesh_i->CreateGroupServants();
3125 if (!myPreviewMode) {
3126 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
3127 << theIDsOfElements << ", "
3128 << theMirror << ", "
3129 << mirrorTypeName(theMirrorType) << ", "
3130 << theCopyGroups << ", '"
3131 << theMeshName << "' )";
3136 if (!myPreviewMode && mesh_i)
3137 mesh_i->GetGroups();
3139 return mesh._retn();
3142 //=======================================================================
3143 //function : MirrorObjectMakeMesh
3145 //=======================================================================
3147 SMESH::SMESH_Mesh_ptr
3148 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3149 const SMESH::AxisStruct& theMirror,
3150 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3151 CORBA::Boolean theCopyGroups,
3152 const char* theMeshName)
3154 SMESH_Mesh_i* mesh_i;
3155 SMESH::SMESH_Mesh_var mesh;
3156 { // open new scope to dump "MakeMesh" command
3157 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3159 TPythonDump pydump; // to prevent dump at mesh creation
3161 mesh = makeMesh( theMeshName );
3162 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3163 TIDSortedElemSet elements;
3165 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3167 mirror(elements, theMirror, theMirrorType,
3168 false, theCopyGroups, & mesh_i->GetImpl());
3169 mesh_i->CreateGroupServants();
3171 if (!myPreviewMode) {
3172 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
3173 << theObject << ", "
3174 << theMirror << ", "
3175 << mirrorTypeName(theMirrorType) << ", "
3176 << theCopyGroups << ", '"
3177 << theMeshName << "' )";
3182 if (!myPreviewMode && mesh_i)
3183 mesh_i->GetGroups();
3185 return mesh._retn();
3188 //=======================================================================
3189 //function : translate
3191 //=======================================================================
3193 SMESH::ListOfGroups*
3194 SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements,
3195 const SMESH::DirStruct & theVector,
3196 CORBA::Boolean theCopy,
3198 ::SMESH_Mesh* theTargetMesh)
3202 if ( theTargetMesh )
3206 const SMESH::PointStruct * P = &theVector.PS;
3207 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
3209 TIDSortedElemSet copyElements;
3210 TIDSortedElemSet* workElements = &theElements;
3211 TPreviewMesh tmpMesh;
3212 SMESH_Mesh* mesh = myMesh;
3214 if ( myPreviewMode )
3216 tmpMesh.Copy( theElements, copyElements);
3217 if ( !theCopy && !theTargetMesh )
3219 TIDSortedElemSet elemsAround, elemsAroundCopy;
3220 getElementsAround( theElements, GetMeshDS(), elemsAround );
3221 tmpMesh.Copy( elemsAround, elemsAroundCopy);
3224 workElements = & copyElements;
3225 theMakeGroups = false;
3228 ::SMESH_MeshEditor anEditor( mesh );
3229 ::SMESH_MeshEditor::PGroupIDs groupIds =
3230 anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3232 if(theCopy || myPreviewMode)
3233 storeResult(anEditor);
3236 myMesh->GetMeshDS()->Modified();
3237 myMesh->SetIsModified( true );
3240 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3243 //=======================================================================
3244 //function : Translate
3246 //=======================================================================
3248 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
3249 const SMESH::DirStruct & theVector,
3250 CORBA::Boolean theCopy)
3252 if (!myPreviewMode) {
3253 TPythonDump() << this << ".Translate( "
3254 << theIDsOfElements << ", "
3255 << theVector << ", "
3258 if (theIDsOfElements.length()) {
3259 TIDSortedElemSet elements;
3260 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3261 translate(elements, theVector, theCopy, false);
3265 //=======================================================================
3266 //function : TranslateObject
3268 //=======================================================================
3270 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
3271 const SMESH::DirStruct & theVector,
3272 CORBA::Boolean theCopy)
3274 if (!myPreviewMode) {
3275 TPythonDump() << this << ".TranslateObject( "
3276 << theObject << ", "
3277 << theVector << ", "
3280 TIDSortedElemSet elements;
3282 bool emptyIfIsMesh = myPreviewMode ? false : true;
3284 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, emptyIfIsMesh))
3285 translate(elements, theVector, theCopy, false);
3288 //=======================================================================
3289 //function : TranslateMakeGroups
3291 //=======================================================================
3293 SMESH::ListOfGroups*
3294 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
3295 const SMESH::DirStruct& theVector)
3297 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3299 SMESH::ListOfGroups * aGroups = 0;
3300 if (theIDsOfElements.length()) {
3301 TIDSortedElemSet elements;
3302 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3303 aGroups = translate(elements,theVector,true,true);
3305 if (!myPreviewMode) {
3306 DumpGroupsList(aPythonDump, aGroups);
3307 aPythonDump << this << ".TranslateMakeGroups( "
3308 << theIDsOfElements << ", "
3309 << theVector << " )";
3314 //=======================================================================
3315 //function : TranslateObjectMakeGroups
3317 //=======================================================================
3319 SMESH::ListOfGroups*
3320 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3321 const SMESH::DirStruct& theVector)
3323 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3325 SMESH::ListOfGroups * aGroups = 0;
3326 TIDSortedElemSet elements;
3327 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3328 aGroups = translate(elements, theVector, true, true);
3330 if (!myPreviewMode) {
3331 DumpGroupsList(aPythonDump, aGroups);
3332 aPythonDump << this << ".TranslateObjectMakeGroups( "
3333 << theObject << ", "
3334 << theVector << " )";
3339 //=======================================================================
3340 //function : TranslateMakeMesh
3342 //=======================================================================
3344 SMESH::SMESH_Mesh_ptr
3345 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3346 const SMESH::DirStruct& theVector,
3347 CORBA::Boolean theCopyGroups,
3348 const char* theMeshName)
3350 SMESH_Mesh_i* mesh_i;
3351 SMESH::SMESH_Mesh_var mesh;
3353 { // open new scope to dump "MakeMesh" command
3354 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3356 TPythonDump pydump; // to prevent dump at mesh creation
3358 mesh = makeMesh( theMeshName );
3359 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3361 if ( mesh_i && theIDsOfElements.length() )
3363 TIDSortedElemSet elements;
3364 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3365 translate(elements, theVector, false, theCopyGroups, & mesh_i->GetImpl());
3366 mesh_i->CreateGroupServants();
3369 if ( !myPreviewMode ) {
3370 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3371 << theIDsOfElements << ", "
3372 << theVector << ", "
3373 << theCopyGroups << ", '"
3374 << theMeshName << "' )";
3379 if (!myPreviewMode && mesh_i)
3380 mesh_i->GetGroups();
3382 return mesh._retn();
3385 //=======================================================================
3386 //function : TranslateObjectMakeMesh
3388 //=======================================================================
3390 SMESH::SMESH_Mesh_ptr
3391 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3392 const SMESH::DirStruct& theVector,
3393 CORBA::Boolean theCopyGroups,
3394 const char* theMeshName)
3396 SMESH_Mesh_i* mesh_i;
3397 SMESH::SMESH_Mesh_var mesh;
3398 { // open new scope to dump "MakeMesh" command
3399 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3401 TPythonDump pydump; // to prevent dump at mesh creation
3402 mesh = makeMesh( theMeshName );
3403 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3405 TIDSortedElemSet elements;
3407 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3409 translate(elements, theVector,false, theCopyGroups, & mesh_i->GetImpl());
3410 mesh_i->CreateGroupServants();
3412 if ( !myPreviewMode ) {
3413 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3414 << theObject << ", "
3415 << theVector << ", "
3416 << theCopyGroups << ", '"
3417 << theMeshName << "' )";
3422 if (!myPreviewMode && mesh_i)
3423 mesh_i->GetGroups();
3425 return mesh._retn();
3428 //=======================================================================
3431 //=======================================================================
3433 SMESH::ListOfGroups*
3434 SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements,
3435 const SMESH::AxisStruct & theAxis,
3436 CORBA::Double theAngle,
3437 CORBA::Boolean theCopy,
3439 ::SMESH_Mesh* theTargetMesh)
3443 if ( theTargetMesh )
3446 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3447 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3450 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3452 TIDSortedElemSet copyElements;
3453 TIDSortedElemSet* workElements = &theElements;
3454 TPreviewMesh tmpMesh;
3455 SMESH_Mesh* mesh = myMesh;
3457 if ( myPreviewMode ) {
3458 tmpMesh.Copy( theElements, copyElements );
3459 if ( !theCopy && !theTargetMesh )
3461 TIDSortedElemSet elemsAround, elemsAroundCopy;
3462 getElementsAround( theElements, GetMeshDS(), elemsAround );
3463 tmpMesh.Copy( elemsAround, elemsAroundCopy);
3466 workElements = ©Elements;
3467 theMakeGroups = false;
3470 ::SMESH_MeshEditor anEditor( mesh );
3471 ::SMESH_MeshEditor::PGroupIDs groupIds =
3472 anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3474 if(theCopy || myPreviewMode)
3475 storeResult(anEditor);
3478 myMesh->GetMeshDS()->Modified();
3479 myMesh->SetIsModified( true );
3482 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3485 //=======================================================================
3488 //=======================================================================
3490 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3491 const SMESH::AxisStruct & theAxis,
3492 CORBA::Double theAngle,
3493 CORBA::Boolean theCopy)
3495 if (!myPreviewMode) {
3496 TPythonDump() << this << ".Rotate( "
3497 << theIDsOfElements << ", "
3502 if (theIDsOfElements.length() > 0)
3504 TIDSortedElemSet elements;
3505 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3506 rotate(elements,theAxis,theAngle,theCopy,false);
3510 //=======================================================================
3511 //function : RotateObject
3513 //=======================================================================
3515 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3516 const SMESH::AxisStruct & theAxis,
3517 CORBA::Double theAngle,
3518 CORBA::Boolean theCopy)
3520 if ( !myPreviewMode ) {
3521 TPythonDump() << this << ".RotateObject( "
3522 << theObject << ", "
3527 TIDSortedElemSet elements;
3528 bool emptyIfIsMesh = myPreviewMode ? false : true;
3529 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, emptyIfIsMesh))
3530 rotate(elements,theAxis,theAngle,theCopy,false);
3533 //=======================================================================
3534 //function : RotateMakeGroups
3536 //=======================================================================
3538 SMESH::ListOfGroups*
3539 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3540 const SMESH::AxisStruct& theAxis,
3541 CORBA::Double theAngle)
3543 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3545 SMESH::ListOfGroups * aGroups = 0;
3546 if (theIDsOfElements.length() > 0)
3548 TIDSortedElemSet elements;
3549 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3550 aGroups = rotate(elements,theAxis,theAngle,true,true);
3552 if (!myPreviewMode) {
3553 DumpGroupsList(aPythonDump, aGroups);
3554 aPythonDump << this << ".RotateMakeGroups( "
3555 << theIDsOfElements << ", "
3557 << theAngle << " )";
3562 //=======================================================================
3563 //function : RotateObjectMakeGroups
3565 //=======================================================================
3567 SMESH::ListOfGroups*
3568 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3569 const SMESH::AxisStruct& theAxis,
3570 CORBA::Double theAngle)
3572 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3574 SMESH::ListOfGroups * aGroups = 0;
3575 TIDSortedElemSet elements;
3576 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3577 aGroups = rotate(elements, theAxis, theAngle, true, true);
3579 if (!myPreviewMode) {
3580 DumpGroupsList(aPythonDump, aGroups);
3581 aPythonDump << this << ".RotateObjectMakeGroups( "
3582 << theObject << ", "
3584 << theAngle << " )";
3589 //=======================================================================
3590 //function : RotateMakeMesh
3592 //=======================================================================
3594 SMESH::SMESH_Mesh_ptr
3595 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3596 const SMESH::AxisStruct& theAxis,
3597 CORBA::Double theAngleInRadians,
3598 CORBA::Boolean theCopyGroups,
3599 const char* theMeshName)
3601 SMESH::SMESH_Mesh_var mesh;
3602 SMESH_Mesh_i* mesh_i;
3604 { // open new scope to dump "MakeMesh" command
3605 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3607 TPythonDump pydump; // to prevent dump at mesh creation
3609 mesh = makeMesh( theMeshName );
3610 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3612 if ( mesh_i && theIDsOfElements.length() > 0 )
3614 TIDSortedElemSet elements;
3615 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3616 rotate(elements, theAxis, theAngleInRadians,
3617 false, theCopyGroups, & mesh_i->GetImpl());
3618 mesh_i->CreateGroupServants();
3620 if ( !myPreviewMode ) {
3621 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3622 << theIDsOfElements << ", "
3624 << theAngleInRadians << ", "
3625 << theCopyGroups << ", '"
3626 << theMeshName << "' )";
3631 if (!myPreviewMode && mesh_i && theIDsOfElements.length() > 0 )
3632 mesh_i->GetGroups();
3634 return mesh._retn();
3637 //=======================================================================
3638 //function : RotateObjectMakeMesh
3640 //=======================================================================
3642 SMESH::SMESH_Mesh_ptr
3643 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3644 const SMESH::AxisStruct& theAxis,
3645 CORBA::Double theAngleInRadians,
3646 CORBA::Boolean theCopyGroups,
3647 const char* theMeshName)
3649 SMESH::SMESH_Mesh_var mesh;
3650 SMESH_Mesh_i* mesh_i;
3652 {// open new scope to dump "MakeMesh" command
3653 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3655 TPythonDump pydump; // to prevent dump at mesh creation
3656 mesh = makeMesh( theMeshName );
3657 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3659 TIDSortedElemSet elements;
3661 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3663 rotate(elements, theAxis, theAngleInRadians,
3664 false, theCopyGroups, & mesh_i->GetImpl());
3665 mesh_i->CreateGroupServants();
3667 if ( !myPreviewMode ) {
3668 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3669 << theObject << ", "
3671 << theAngleInRadians << ", "
3672 << theCopyGroups << ", '"
3673 << theMeshName << "' )";
3678 if (!myPreviewMode && mesh_i)
3679 mesh_i->GetGroups();
3681 return mesh._retn();
3684 //=======================================================================
3687 //=======================================================================
3689 SMESH::ListOfGroups*
3690 SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject,
3691 const SMESH::PointStruct& thePoint,
3692 const SMESH::double_array& theScaleFact,
3693 CORBA::Boolean theCopy,
3695 ::SMESH_Mesh* theTargetMesh)
3698 if ( theScaleFact.length() < 1 )
3699 THROW_SALOME_CORBA_EXCEPTION("Scale factor not given", SALOME::BAD_PARAM);
3700 if ( theScaleFact.length() == 2 )
3701 THROW_SALOME_CORBA_EXCEPTION("Invalid nb of scale factors : 2", SALOME::BAD_PARAM);
3703 if ( theTargetMesh )
3706 TIDSortedElemSet elements;
3707 bool emptyIfIsMesh = myPreviewMode ? false : true;
3708 if ( !idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, emptyIfIsMesh))
3713 (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1],
3714 (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2],
3716 double tol = std::numeric_limits<double>::max();
3718 aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]),
3719 0, S[1], 0, thePoint.y * (1-S[1]),
3720 0, 0, S[2], thePoint.z * (1-S[2]), tol, tol);
3722 TIDSortedElemSet copyElements;
3723 TPreviewMesh tmpMesh;
3724 TIDSortedElemSet* workElements = &elements;
3725 SMESH_Mesh* mesh = myMesh;
3727 if ( myPreviewMode )
3729 tmpMesh.Copy( elements, copyElements);
3730 if ( !theCopy && !theTargetMesh )
3732 TIDSortedElemSet elemsAround, elemsAroundCopy;
3733 getElementsAround( elements, GetMeshDS(), elemsAround );
3734 tmpMesh.Copy( elemsAround, elemsAroundCopy);
3737 workElements = & copyElements;
3738 theMakeGroups = false;
3741 ::SMESH_MeshEditor anEditor( mesh );
3742 ::SMESH_MeshEditor::PGroupIDs groupIds =
3743 anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3745 if(theCopy || myPreviewMode )
3746 storeResult(anEditor);
3749 myMesh->GetMeshDS()->Modified();
3750 myMesh->SetIsModified( true );
3752 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3755 //=======================================================================
3758 //=======================================================================
3760 void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr theObject,
3761 const SMESH::PointStruct& thePoint,
3762 const SMESH::double_array& theScaleFact,
3763 CORBA::Boolean theCopy)
3765 if ( !myPreviewMode ) {
3766 TPythonDump() << this << ".Scale( "
3767 << theObject << ", "
3768 << "SMESH.PointStruct( " << thePoint.x << ", "
3769 << thePoint.y << ", " << thePoint.z << " ) ,"
3770 << theScaleFact << ", "
3773 scale(theObject, thePoint, theScaleFact, theCopy, false);
3777 //=======================================================================
3778 //function : ScaleMakeGroups
3780 //=======================================================================
3782 SMESH::ListOfGroups*
3783 SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3784 const SMESH::PointStruct& thePoint,
3785 const SMESH::double_array& theScaleFact)
3787 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3789 SMESH::ListOfGroups * aGroups = scale(theObject, thePoint, theScaleFact, true, true);
3790 if (!myPreviewMode) {
3791 DumpGroupsList(aPythonDump, aGroups);
3792 aPythonDump << this << ".Scale("
3794 << "SMESH.PointStruct(" <<thePoint.x << ","
3795 << thePoint.y << "," << thePoint.z << "),"
3796 << theScaleFact << ",True,True)";
3802 //=======================================================================
3803 //function : ScaleMakeMesh
3805 //=======================================================================
3807 SMESH::SMESH_Mesh_ptr
3808 SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3809 const SMESH::PointStruct& thePoint,
3810 const SMESH::double_array& theScaleFact,
3811 CORBA::Boolean theCopyGroups,
3812 const char* theMeshName)
3814 SMESH_Mesh_i* mesh_i;
3815 SMESH::SMESH_Mesh_var mesh;
3816 { // open new scope to dump "MakeMesh" command
3817 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3819 TPythonDump pydump; // to prevent dump at mesh creation
3820 mesh = makeMesh( theMeshName );
3821 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3825 scale(theObject, thePoint, theScaleFact,false, theCopyGroups, & mesh_i->GetImpl());
3826 mesh_i->CreateGroupServants();
3828 if ( !myPreviewMode )
3829 pydump << mesh << " = " << this << ".ScaleMakeMesh( "
3830 << theObject << ", "
3831 << "SMESH.PointStruct( " << thePoint.x << ", "
3832 << thePoint.y << ", " << thePoint.z << " ) ,"
3833 << theScaleFact << ", "
3834 << theCopyGroups << ", '"
3835 << theMeshName << "' )";
3839 if (!myPreviewMode && mesh_i)
3840 mesh_i->GetGroups();
3842 return mesh._retn();
3846 //=======================================================================
3847 //function : FindCoincidentNodes
3849 //=======================================================================
3851 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3852 SMESH::array_of_long_array_out GroupsOfNodes)
3856 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3857 ::SMESH_MeshEditor anEditor( myMesh );
3858 TIDSortedNodeSet nodes; // no input nodes
3859 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3861 GroupsOfNodes = new SMESH::array_of_long_array;
3862 GroupsOfNodes->length( aListOfListOfNodes.size() );
3863 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3864 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3865 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3866 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3867 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3868 aGroup.length( aListOfNodes.size() );
3869 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3870 aGroup[ j ] = (*lIt)->GetID();
3872 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3873 << Tolerance << " )";
3876 //=======================================================================
3877 //function : FindCoincidentNodesOnPart
3879 //=======================================================================
3880 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3881 CORBA::Double Tolerance,
3882 SMESH::array_of_long_array_out GroupsOfNodes)
3886 TIDSortedNodeSet nodes;
3887 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3889 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3890 ::SMESH_MeshEditor anEditor( myMesh );
3892 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3894 GroupsOfNodes = new SMESH::array_of_long_array;
3895 GroupsOfNodes->length( aListOfListOfNodes.size() );
3896 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3897 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3899 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3900 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3901 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3902 aGroup.length( aListOfNodes.size() );
3903 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3904 aGroup[ j ] = (*lIt)->GetID();
3906 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3908 << Tolerance << " )";
3911 //================================================================================
3913 * \brief Finds nodes coinsident with Tolerance within Object excluding nodes within
3914 * ExceptSubMeshOrGroups
3916 //================================================================================
3918 void SMESH_MeshEditor_i::
3919 FindCoincidentNodesOnPartBut(SMESH::SMESH_IDSource_ptr theObject,
3920 CORBA::Double theTolerance,
3921 SMESH::array_of_long_array_out theGroupsOfNodes,
3922 const SMESH::ListOfIDSources& theExceptSubMeshOrGroups)
3926 TIDSortedNodeSet nodes;
3927 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3929 for ( int i = 0; i < theExceptSubMeshOrGroups.length(); ++i )
3931 TIDSortedNodeSet exceptNodes;
3932 idSourceToNodeSet( theExceptSubMeshOrGroups[i], GetMeshDS(), exceptNodes );
3933 TIDSortedNodeSet::iterator avoidNode = exceptNodes.begin();
3934 for ( ; avoidNode != exceptNodes.end(); ++avoidNode)
3935 nodes.erase( *avoidNode );
3937 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3938 ::SMESH_MeshEditor anEditor( myMesh );
3940 anEditor.FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes );
3942 theGroupsOfNodes = new SMESH::array_of_long_array;
3943 theGroupsOfNodes->length( aListOfListOfNodes.size() );
3944 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3945 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3947 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3948 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3949 SMESH::long_array& aGroup = (*theGroupsOfNodes)[ i ];
3950 aGroup.length( aListOfNodes.size() );
3951 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3952 aGroup[ j ] = (*lIt)->GetID();
3954 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPartBut( "
3956 << theTolerance << ", "
3957 << theExceptSubMeshOrGroups << " )";
3960 //=======================================================================
3961 //function : MergeNodes
3963 //=======================================================================
3965 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3969 SMESHDS_Mesh* aMesh = GetMeshDS();
3971 TPythonDump aTPythonDump;
3972 aTPythonDump << this << ".MergeNodes([";
3973 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3974 for (int i = 0; i < GroupsOfNodes.length(); i++)
3976 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3977 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3978 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3979 for ( int j = 0; j < aNodeGroup.length(); j++ )
3981 CORBA::Long index = aNodeGroup[ j ];
3982 const SMDS_MeshNode * node = aMesh->FindNode(index);
3984 aListOfNodes.push_back( node );
3986 if ( aListOfNodes.size() < 2 )
3987 aListOfListOfNodes.pop_back();
3989 if ( i > 0 ) aTPythonDump << ", ";
3990 aTPythonDump << aNodeGroup;
3992 ::SMESH_MeshEditor anEditor( myMesh );
3993 anEditor.MergeNodes( aListOfListOfNodes );
3995 aTPythonDump << "])";
3996 myMesh->GetMeshDS()->Modified();
3997 myMesh->SetIsModified( true );
4000 //=======================================================================
4001 //function : FindEqualElements
4003 //=======================================================================
4004 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
4005 SMESH::array_of_long_array_out GroupsOfElementsID)
4009 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theObject);
4010 if ( !(!group->_is_nil() && group->GetType() == SMESH::NODE) )
4012 typedef list<int> TListOfIDs;
4013 set<const SMDS_MeshElement*> elems;
4014 SMESH::long_array_var aElementsId = theObject->GetIDs();
4015 SMESHDS_Mesh* aMesh = GetMeshDS();
4017 for(int i = 0; i < aElementsId->length(); i++) {
4018 CORBA::Long anID = aElementsId[i];
4019 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
4025 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
4026 ::SMESH_MeshEditor anEditor( myMesh );
4027 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
4029 GroupsOfElementsID = new SMESH::array_of_long_array;
4030 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
4032 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
4033 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
4034 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
4035 TListOfIDs& listOfIDs = *arraysIt;
4036 aGroup.length( listOfIDs.size() );
4037 TListOfIDs::iterator idIt = listOfIDs.begin();
4038 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
4039 aGroup[ k ] = *idIt;
4043 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
4048 //=======================================================================
4049 //function : MergeElements
4051 //=======================================================================
4053 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
4057 TPythonDump aTPythonDump;
4058 aTPythonDump << this << ".MergeElements( [";
4060 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
4062 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
4063 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
4064 aListOfListOfElementsID.push_back( list< int >() );
4065 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
4066 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
4067 CORBA::Long id = anElemsIDGroup[ j ];
4068 aListOfElemsID.push_back( id );
4070 if ( aListOfElemsID.size() < 2 )
4071 aListOfListOfElementsID.pop_back();
4072 if ( i > 0 ) aTPythonDump << ", ";
4073 aTPythonDump << anElemsIDGroup;
4076 ::SMESH_MeshEditor anEditor( myMesh );
4077 anEditor.MergeElements(aListOfListOfElementsID);
4078 myMesh->GetMeshDS()->Modified();
4079 myMesh->SetIsModified( true );
4081 aTPythonDump << "] )";
4084 //=======================================================================
4085 //function : MergeEqualElements
4087 //=======================================================================
4089 void SMESH_MeshEditor_i::MergeEqualElements()
4093 ::SMESH_MeshEditor anEditor( myMesh );
4094 anEditor.MergeEqualElements();
4096 TPythonDump() << this << ".MergeEqualElements()";
4099 //=============================================================================
4101 * Move the node to a given point
4103 //=============================================================================
4105 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
4110 initData(/*deleteSearchers=*/false);
4112 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
4116 if ( theNodeSearcher )
4117 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4119 if ( myPreviewMode ) // make preview data
4121 // in a preview mesh, make edges linked to a node
4122 TPreviewMesh tmpMesh;
4123 TIDSortedElemSet linkedNodes;
4124 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
4125 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
4126 SMDS_MeshNode *nodeCpy1 = tmpMesh.Copy(node);
4127 for ( ; nIt != linkedNodes.end(); ++nIt )
4129 SMDS_MeshNode *nodeCpy2 = tmpMesh.Copy ( cast2Node( *nIt ));
4130 tmpMesh.GetMeshDS()->AddEdge(nodeCpy1, nodeCpy2);
4134 tmpMesh.GetMeshDS()->MoveNode(nodeCpy1, x, y, z);
4135 // fill preview data
4136 ::SMESH_MeshEditor anEditor( & tmpMesh );
4137 storeResult( anEditor );
4139 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
4140 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
4142 GetMeshDS()->MoveNode(node, x, y, z);
4144 if ( !myPreviewMode )
4146 // Update Python script
4147 TPythonDump() << "isDone = " << this << ".MoveNode( "
4148 << NodeID << ", " << x << ", " << y << ", " << z << " )";
4149 myMesh->GetMeshDS()->Modified();
4150 myMesh->SetIsModified( true );
4156 //================================================================================
4158 * \brief Return ID of node closest to a given point
4160 //================================================================================
4162 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
4166 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4168 if ( !theNodeSearcher ) {
4169 ::SMESH_MeshEditor anEditor( myMesh );
4170 theNodeSearcher = anEditor.GetNodeSearcher();
4173 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
4174 return node->GetID();
4179 //================================================================================
4181 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
4182 * move the node closest to the point to point's location and return ID of the node
4184 //================================================================================
4186 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
4189 CORBA::Long theNodeID)
4191 // We keep theNodeSearcher until any mesh modification:
4192 // 1) initData() deletes theNodeSearcher at any edition,
4193 // 2) TSearchersDeleter - at any mesh compute event and mesh change
4195 initData(/*deleteSearchers=*/false);
4197 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4199 int nodeID = theNodeID;
4200 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
4201 if ( !node ) // preview moving node
4203 if ( !theNodeSearcher ) {
4204 ::SMESH_MeshEditor anEditor( myMesh );
4205 theNodeSearcher = anEditor.GetNodeSearcher();
4208 node = theNodeSearcher->FindClosestTo( p );
4211 nodeID = node->GetID();
4212 if ( myPreviewMode ) // make preview data
4214 // in a preview mesh, make edges linked to a node
4215 TPreviewMesh tmpMesh;
4216 TIDSortedElemSet linkedNodes;
4217 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
4218 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
4219 for ( ; nIt != linkedNodes.end(); ++nIt )
4221 SMDS_LinearEdge edge( node, cast2Node( *nIt ));
4222 tmpMesh.Copy( &edge );
4225 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
4227 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
4228 // fill preview data
4229 ::SMESH_MeshEditor anEditor( & tmpMesh );
4230 storeResult( anEditor );
4232 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
4234 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
4238 GetMeshDS()->MoveNode(node, x, y, z);
4242 if ( !myPreviewMode )
4244 TPythonDump() << "nodeID = " << this
4245 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
4246 << ", " << nodeID << " )";
4248 myMesh->GetMeshDS()->Modified();
4249 myMesh->SetIsModified( true );
4255 //=======================================================================
4257 * Return elements of given type where the given point is IN or ON.
4259 * 'ALL' type means elements of any type excluding nodes
4261 //=======================================================================
4263 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
4266 SMESH::ElementType type)
4268 SMESH::long_array_var res = new SMESH::long_array;
4269 vector< const SMDS_MeshElement* > foundElems;
4271 theSearchersDeleter.Set( myMesh );
4272 if ( !theElementSearcher ) {
4273 ::SMESH_MeshEditor anEditor( myMesh );
4274 theElementSearcher = anEditor.GetElementSearcher();
4276 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
4277 SMDSAbs_ElementType( type ),
4279 res->length( foundElems.size() );
4280 for ( int i = 0; i < foundElems.size(); ++i )
4281 res[i] = foundElems[i]->GetID();
4283 if ( !myPreviewMode ) // call from tui
4284 TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
4293 //=======================================================================
4294 //function : GetPointState
4295 //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
4296 // TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
4297 //=======================================================================
4299 CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
4303 theSearchersDeleter.Set( myMesh );
4304 if ( !theElementSearcher ) {
4305 ::SMESH_MeshEditor anEditor( myMesh );
4306 theElementSearcher = anEditor.GetElementSearcher();
4308 return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
4311 //=======================================================================
4312 //function : convError
4314 //=======================================================================
4316 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
4318 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
4322 RETCASE( SEW_BORDER1_NOT_FOUND );
4323 RETCASE( SEW_BORDER2_NOT_FOUND );
4324 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
4325 RETCASE( SEW_BAD_SIDE_NODES );
4326 RETCASE( SEW_VOLUMES_TO_SPLIT );
4327 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
4328 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
4329 RETCASE( SEW_BAD_SIDE1_NODES );
4330 RETCASE( SEW_BAD_SIDE2_NODES );
4332 return SMESH::SMESH_MeshEditor::SEW_OK;
4335 //=======================================================================
4336 //function : SewFreeBorders
4338 //=======================================================================
4340 SMESH::SMESH_MeshEditor::Sew_Error
4341 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
4342 CORBA::Long SecondNodeID1,
4343 CORBA::Long LastNodeID1,
4344 CORBA::Long FirstNodeID2,
4345 CORBA::Long SecondNodeID2,
4346 CORBA::Long LastNodeID2,
4347 CORBA::Boolean CreatePolygons,
4348 CORBA::Boolean CreatePolyedrs)
4352 SMESHDS_Mesh* aMesh = GetMeshDS();
4354 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4355 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4356 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4357 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4358 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4359 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
4361 if (!aBorderFirstNode ||
4362 !aBorderSecondNode||
4364 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4365 if (!aSide2FirstNode ||
4366 !aSide2SecondNode ||
4368 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4370 TPythonDump() << "error = " << this << ".SewFreeBorders( "
4371 << FirstNodeID1 << ", "
4372 << SecondNodeID1 << ", "
4373 << LastNodeID1 << ", "
4374 << FirstNodeID2 << ", "
4375 << SecondNodeID2 << ", "
4376 << LastNodeID2 << ", "
4377 << CreatePolygons<< ", "
4378 << CreatePolyedrs<< " )";
4380 ::SMESH_MeshEditor anEditor( myMesh );
4381 SMESH::SMESH_MeshEditor::Sew_Error error =
4382 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4392 storeResult(anEditor);
4394 myMesh->GetMeshDS()->Modified();
4395 myMesh->SetIsModified( true );
4401 //=======================================================================
4402 //function : SewConformFreeBorders
4404 //=======================================================================
4406 SMESH::SMESH_MeshEditor::Sew_Error
4407 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
4408 CORBA::Long SecondNodeID1,
4409 CORBA::Long LastNodeID1,
4410 CORBA::Long FirstNodeID2,
4411 CORBA::Long SecondNodeID2)
4415 SMESHDS_Mesh* aMesh = GetMeshDS();
4417 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4418 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4419 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4420 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4421 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4422 const SMDS_MeshNode* aSide2ThirdNode = 0;
4424 if (!aBorderFirstNode ||
4425 !aBorderSecondNode||
4427 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4428 if (!aSide2FirstNode ||
4430 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4432 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
4433 << FirstNodeID1 << ", "
4434 << SecondNodeID1 << ", "
4435 << LastNodeID1 << ", "
4436 << FirstNodeID2 << ", "
4437 << SecondNodeID2 << " )";
4439 ::SMESH_MeshEditor anEditor( myMesh );
4440 SMESH::SMESH_MeshEditor::Sew_Error error =
4441 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4450 storeResult(anEditor);
4452 myMesh->GetMeshDS()->Modified();
4453 myMesh->SetIsModified( true );
4459 //=======================================================================
4460 //function : SewBorderToSide
4462 //=======================================================================
4464 SMESH::SMESH_MeshEditor::Sew_Error
4465 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
4466 CORBA::Long SecondNodeIDOnFreeBorder,
4467 CORBA::Long LastNodeIDOnFreeBorder,
4468 CORBA::Long FirstNodeIDOnSide,
4469 CORBA::Long LastNodeIDOnSide,
4470 CORBA::Boolean CreatePolygons,
4471 CORBA::Boolean CreatePolyedrs)
4475 SMESHDS_Mesh* aMesh = GetMeshDS();
4477 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
4478 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
4479 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
4480 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
4481 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
4482 const SMDS_MeshNode* aSide2ThirdNode = 0;
4484 if (!aBorderFirstNode ||
4485 !aBorderSecondNode||
4487 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4488 if (!aSide2FirstNode ||
4490 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
4492 TPythonDump() << "error = " << this << ".SewBorderToSide( "
4493 << FirstNodeIDOnFreeBorder << ", "
4494 << SecondNodeIDOnFreeBorder << ", "
4495 << LastNodeIDOnFreeBorder << ", "
4496 << FirstNodeIDOnSide << ", "
4497 << LastNodeIDOnSide << ", "
4498 << CreatePolygons << ", "
4499 << CreatePolyedrs << ") ";
4501 ::SMESH_MeshEditor anEditor( myMesh );
4502 SMESH::SMESH_MeshEditor::Sew_Error error =
4503 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4513 storeResult(anEditor);
4515 myMesh->GetMeshDS()->Modified();
4516 myMesh->SetIsModified( true );
4522 //=======================================================================
4523 //function : SewSideElements
4525 //=======================================================================
4527 SMESH::SMESH_MeshEditor::Sew_Error
4528 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
4529 const SMESH::long_array& IDsOfSide2Elements,
4530 CORBA::Long NodeID1OfSide1ToMerge,
4531 CORBA::Long NodeID1OfSide2ToMerge,
4532 CORBA::Long NodeID2OfSide1ToMerge,
4533 CORBA::Long NodeID2OfSide2ToMerge)
4537 SMESHDS_Mesh* aMesh = GetMeshDS();
4539 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
4540 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
4541 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
4542 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
4544 if (!aFirstNode1ToMerge ||
4545 !aFirstNode2ToMerge )
4546 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
4547 if (!aSecondNode1ToMerge||
4548 !aSecondNode2ToMerge)
4549 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
4551 TIDSortedElemSet aSide1Elems, aSide2Elems;
4552 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
4553 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
4555 TPythonDump() << "error = " << this << ".SewSideElements( "
4556 << IDsOfSide1Elements << ", "
4557 << IDsOfSide2Elements << ", "
4558 << NodeID1OfSide1ToMerge << ", "
4559 << NodeID1OfSide2ToMerge << ", "
4560 << NodeID2OfSide1ToMerge << ", "
4561 << NodeID2OfSide2ToMerge << ")";
4563 ::SMESH_MeshEditor anEditor( myMesh );
4564 SMESH::SMESH_MeshEditor::Sew_Error error =
4565 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
4568 aSecondNode1ToMerge,
4569 aSecondNode2ToMerge));
4571 storeResult(anEditor);
4573 myMesh->GetMeshDS()->Modified();
4574 myMesh->SetIsModified( true );
4579 //================================================================================
4581 * \brief Set new nodes for given element
4582 * \param ide - element id
4583 * \param newIDs - new node ids
4584 * \retval CORBA::Boolean - true if result is OK
4586 //================================================================================
4588 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
4589 const SMESH::long_array& newIDs)
4593 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
4594 if(!elem) return false;
4596 int nbn = newIDs.length();
4598 vector<const SMDS_MeshNode*> aNodes(nbn);
4601 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
4604 aNodes[nbn1] = aNode;
4607 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
4608 << ide << ", " << newIDs << " )";
4610 MESSAGE("ChangeElementNodes");
4611 bool res = GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
4613 myMesh->GetMeshDS()->Modified();
4615 myMesh->SetIsModified( true );
4620 //================================================================================
4622 * \brief Update myLastCreated* or myPreviewData
4623 * \param anEditor - it contains last modification results
4625 //================================================================================
4627 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
4629 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
4631 list<int> aNodesConnectivity;
4632 typedef map<int, int> TNodesMap;
4635 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
4636 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
4638 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
4639 int nbEdges = aMeshDS->NbEdges();
4640 int nbFaces = aMeshDS->NbFaces();
4641 int nbVolum = aMeshDS->NbVolumes();
4642 switch ( previewType ) {
4643 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
4644 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
4645 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
4648 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
4649 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
4651 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
4653 while ( itMeshElems->more() ) {
4654 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
4655 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
4658 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
4659 while ( itElemNodes->more() ) {
4660 const SMDS_MeshNode* aMeshNode =
4661 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
4662 int aNodeID = aMeshNode->GetID();
4663 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
4664 if ( anIter == nodesMap.end() ) {
4665 // filling the nodes coordinates
4666 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
4667 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
4668 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
4669 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4672 aNodesConnectivity.push_back(anIter->second);
4675 // filling the elements types
4676 SMDSAbs_ElementType aType;
4678 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4679 aType = SMDSAbs_Node;
4683 aType = aMeshElem->GetType();
4684 isPoly = aMeshElem->IsPoly();
4687 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4688 myPreviewData->elementTypes[i].isPoly = isPoly;
4689 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4693 myPreviewData->nodesXYZ.length( j );
4695 // filling the elements connectivities
4696 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4697 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4698 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4699 myPreviewData->elementConnectivities[i] = *aConnIter;
4705 // append new nodes into myLastCreatedNodes
4706 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4707 int j = myLastCreatedNodes->length();
4708 int newLen = j + aSeq.Length();
4709 myLastCreatedNodes->length( newLen );
4710 for(int i=0; j<newLen; i++,j++)
4711 myLastCreatedNodes[j] = aSeq.Value(i+1)->GetID();
4714 // append new elements into myLastCreatedElems
4715 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4716 int j = myLastCreatedElems->length();
4717 int newLen = j + aSeq.Length();
4718 myLastCreatedElems->length( newLen );
4719 for(int i=0; j<newLen; i++,j++)
4720 myLastCreatedElems[j] = aSeq.Value(i+1)->GetID();
4724 //================================================================================
4726 * Return data of mesh edition preview
4728 //================================================================================
4730 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4732 return myPreviewData._retn();
4735 //================================================================================
4737 * \brief Returns list of it's IDs of created nodes
4738 * \retval SMESH::long_array* - list of node ID
4740 //================================================================================
4742 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4744 return myLastCreatedNodes._retn();
4747 //================================================================================
4749 * \brief Returns list of it's IDs of created elements
4750 * \retval SMESH::long_array* - list of elements' ID
4752 //================================================================================
4754 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4756 return myLastCreatedElems._retn();
4759 //=======================================================================
4760 //function : ConvertToQuadratic
4762 //=======================================================================
4764 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4766 ::SMESH_MeshEditor anEditor( myMesh );
4767 anEditor.ConvertToQuadratic(theForce3d);
4768 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4769 myMesh->GetMeshDS()->Modified();
4770 myMesh->SetIsModified( true );
4773 //=======================================================================
4774 //function : ConvertFromQuadratic
4776 //=======================================================================
4778 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4780 ::SMESH_MeshEditor anEditor( myMesh );
4781 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4782 TPythonDump() << this << ".ConvertFromQuadratic()";
4783 myMesh->GetMeshDS()->Modified();
4785 myMesh->SetIsModified( true );
4788 //================================================================================
4790 * \brief Makes a part of the mesh quadratic
4792 //================================================================================
4794 void SMESH_MeshEditor_i::ConvertToQuadraticObject(CORBA::Boolean theForce3d,
4795 SMESH::SMESH_IDSource_ptr theObject)
4796 throw (SALOME::SALOME_Exception)
4798 Unexpect aCatch(SALOME_SalomeException);
4800 TIDSortedElemSet elems;
4801 if ( idSourceToSet( theObject, GetMeshDS(), elems, SMDSAbs_All, /*emptyIfIsMesh=*/true ))
4803 if ( elems.empty() )
4805 ConvertToQuadratic( theForce3d );
4807 else if ( (*elems.begin())->GetType() == SMDSAbs_Node )
4809 THROW_SALOME_CORBA_EXCEPTION("Group of nodes is not allowed", SALOME::BAD_PARAM);
4813 ::SMESH_MeshEditor anEditor( myMesh );
4814 anEditor.ConvertToQuadratic(theForce3d, elems);
4817 myMesh->GetMeshDS()->Modified();
4818 myMesh->SetIsModified( true );
4820 pyDump << this << ".ConvertToQuadraticObject( "<<theForce3d<<", "<<theObject<<" )";
4823 //================================================================================
4825 * \brief Makes a part of the mesh linear
4827 //================================================================================
4829 void SMESH_MeshEditor_i::ConvertFromQuadraticObject(SMESH::SMESH_IDSource_ptr theObject)
4830 throw (SALOME::SALOME_Exception)
4832 Unexpect aCatch(SALOME_SalomeException);
4834 TIDSortedElemSet elems;
4835 if ( idSourceToSet( theObject, GetMeshDS(), elems, SMDSAbs_All, /*emptyIfIsMesh=*/true ))
4837 if ( elems.empty() )
4839 ConvertFromQuadratic();
4841 else if ( (*elems.begin())->GetType() == SMDSAbs_Node )
4843 THROW_SALOME_CORBA_EXCEPTION("Group of nodes is not allowed", SALOME::BAD_PARAM);
4847 ::SMESH_MeshEditor anEditor( myMesh );
4848 anEditor.ConvertFromQuadratic(elems);
4851 myMesh->GetMeshDS()->Modified();
4852 myMesh->SetIsModified( true );
4854 pyDump << this << ".ConvertFromQuadraticObject( "<<theObject<<" )";
4857 //=======================================================================
4858 //function : makeMesh
4859 //purpose : create a named imported mesh
4860 //=======================================================================
4862 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4864 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4865 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4866 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4867 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4868 gen->SetName( meshSO, theMeshName, "Mesh" );
4869 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4871 return mesh._retn();
4874 //=======================================================================
4875 //function : DumpGroupsList
4877 //=======================================================================
4878 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4879 const SMESH::ListOfGroups * theGroupList)
4881 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4882 if(isDumpGroupList) {
4883 theDumpPython << theGroupList << " = ";
4887 //================================================================================
4889 \brief Generates the unique group name.
4890 \param thePrefix name prefix
4893 //================================================================================
4894 string SMESH_MeshEditor_i::generateGroupName(const string& thePrefix)
4896 SMESH::ListOfGroups_var groups = myMesh_i->GetGroups();
4897 set<string> groupNames;
4899 // Get existing group names
4900 for (int i = 0, nbGroups = groups->length(); i < nbGroups; i++ ) {
4901 SMESH::SMESH_GroupBase_var aGroup = groups[i];
4902 if (CORBA::is_nil(aGroup))
4905 groupNames.insert(aGroup->GetName());
4909 string name = thePrefix;
4912 while (!groupNames.insert(name).second) {
4917 TCollection_AsciiString nbStr(index+1);
4918 name.resize( name.rfind('_')+1 );
4919 name += nbStr.ToCString();
4927 //================================================================================
4929 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4930 \param theNodes - identifiers of nodes to be doubled
4931 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4932 nodes. If list of element identifiers is empty then nodes are doubled but
4933 they not assigned to elements
4934 \return TRUE if operation has been completed successfully, FALSE otherwise
4935 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4937 //================================================================================
4939 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4940 const SMESH::long_array& theModifiedElems )
4944 ::SMESH_MeshEditor aMeshEditor( myMesh );
4945 list< int > aListOfNodes;
4947 for ( i = 0, n = theNodes.length(); i < n; i++ )
4948 aListOfNodes.push_back( theNodes[ i ] );
4950 list< int > aListOfElems;
4951 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4952 aListOfElems.push_back( theModifiedElems[ i ] );
4954 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4956 myMesh->GetMeshDS()->Modified();
4957 storeResult( aMeshEditor) ;
4959 myMesh->SetIsModified( true );
4961 // Update Python script
4962 TPythonDump() << this << ".DoubleNodes( " << theNodes << ", "<< theModifiedElems << " )";
4967 //================================================================================
4969 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4970 This method provided for convenience works as DoubleNodes() described above.
4971 \param theNodeId - identifier of node to be doubled.
4972 \param theModifiedElems - identifiers of elements to be updated.
4973 \return TRUE if operation has been completed successfully, FALSE otherwise
4974 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4976 //================================================================================
4978 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4979 const SMESH::long_array& theModifiedElems )
4981 SMESH::long_array_var aNodes = new SMESH::long_array;
4982 aNodes->length( 1 );
4983 aNodes[ 0 ] = theNodeId;
4985 TPythonDump pyDump; // suppress dump by the next line
4987 CORBA::Boolean done = DoubleNodes( aNodes, theModifiedElems );
4989 pyDump << this << ".DoubleNode( " << theNodeId << ", " << theModifiedElems << " )";
4994 //================================================================================
4996 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4997 This method provided for convenience works as DoubleNodes() described above.
4998 \param theNodes - group of nodes to be doubled.
4999 \param theModifiedElems - group of elements to be updated.
5000 \return TRUE if operation has been completed successfully, FALSE otherwise
5001 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
5003 //================================================================================
5005 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(SMESH::SMESH_GroupBase_ptr theNodes,
5006 SMESH::SMESH_GroupBase_ptr theModifiedElems )
5008 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
5011 SMESH::long_array_var aNodes = theNodes->GetListOfID();
5012 SMESH::long_array_var aModifiedElems;
5013 if ( !CORBA::is_nil( theModifiedElems ) )
5014 aModifiedElems = theModifiedElems->GetListOfID();
5017 aModifiedElems = new SMESH::long_array;
5018 aModifiedElems->length( 0 );
5021 TPythonDump pyDump; // suppress dump by the next line
5023 bool done = DoubleNodes( aNodes, aModifiedElems );
5025 pyDump << this << ".DoubleNodeGroup( " << theNodes << ", " << theModifiedElems << " )";
5031 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements.
5032 * Works as DoubleNodeGroup(), but returns a new group with newly created nodes.
5033 * \param theNodes - group of nodes to be doubled.
5034 * \param theModifiedElems - group of elements to be updated.
5035 * \return a new group with newly created nodes
5036 * \sa DoubleNodeGroup()
5038 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes,
5039 SMESH::SMESH_GroupBase_ptr theModifiedElems )
5041 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
5044 SMESH::SMESH_Group_var aNewGroup;
5047 SMESH::long_array_var aNodes = theNodes->GetListOfID();
5048 SMESH::long_array_var aModifiedElems;
5049 if ( !CORBA::is_nil( theModifiedElems ) )
5050 aModifiedElems = theModifiedElems->GetListOfID();
5052 aModifiedElems = new SMESH::long_array;
5053 aModifiedElems->length( 0 );
5056 TPythonDump pyDump; // suppress dump by the next line
5058 bool aResult = DoubleNodes( aNodes, aModifiedElems );
5062 // Create group with newly created nodes
5063 SMESH::long_array_var anIds = GetLastCreatedNodes();
5064 if (anIds->length() > 0) {
5065 string anUnindexedName (theNodes->GetName());
5066 string aNewName = generateGroupName(anUnindexedName + "_double");
5067 aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
5068 aNewGroup->Add(anIds);
5072 pyDump << "createdNodes = " << this << ".DoubleNodeGroupNew( " << theNodes << ", "
5073 << theModifiedElems << " )";
5075 return aNewGroup._retn();
5078 //================================================================================
5080 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5081 This method provided for convenience works as DoubleNodes() described above.
5082 \param theNodes - list of groups of nodes to be doubled
5083 \param theModifiedElems - list of groups of elements to be updated.
5084 \return TRUE if operation has been completed successfully, FALSE otherwise
5085 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
5087 //================================================================================
5089 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& theNodes,
5090 const SMESH::ListOfGroups& theModifiedElems )
5094 ::SMESH_MeshEditor aMeshEditor( myMesh );
5096 std::list< int > aNodes;
5098 for ( i = 0, n = theNodes.length(); i < n; i++ )
5100 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
5101 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
5103 SMESH::long_array_var aCurr = aGrp->GetListOfID();
5104 for ( j = 0, m = aCurr->length(); j < m; j++ )
5105 aNodes.push_back( aCurr[ j ] );
5109 std::list< int > anElems;
5110 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
5112 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
5113 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
5115 SMESH::long_array_var aCurr = aGrp->GetListOfID();
5116 for ( j = 0, m = aCurr->length(); j < m; j++ )
5117 anElems.push_back( aCurr[ j ] );
5121 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
5123 storeResult( aMeshEditor) ;
5125 myMesh->GetMeshDS()->Modified();
5127 myMesh->SetIsModified( true );
5130 TPythonDump() << this << ".DoubleNodeGroups( " << theNodes << ", " << theModifiedElems << " )";
5135 //================================================================================
5137 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements.
5138 * Works as DoubleNodeGroups(), but returns a new group with newly created nodes.
5139 * \param theNodes - group of nodes to be doubled.
5140 * \param theModifiedElems - group of elements to be updated.
5141 * \return a new group with newly created nodes
5142 * \sa DoubleNodeGroups()
5144 //================================================================================
5146 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupsNew( const SMESH::ListOfGroups& theNodes,
5147 const SMESH::ListOfGroups& theModifiedElems )
5149 SMESH::SMESH_Group_var aNewGroup;
5151 TPythonDump pyDump; // suppress dump by the next line
5153 bool aResult = DoubleNodeGroups( theNodes, theModifiedElems );
5157 // Create group with newly created nodes
5158 SMESH::long_array_var anIds = GetLastCreatedNodes();
5159 if (anIds->length() > 0) {
5160 string anUnindexedName (theNodes[0]->GetName());
5161 string aNewName = generateGroupName(anUnindexedName + "_double");
5162 aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
5163 aNewGroup->Add(anIds);
5167 pyDump << "createdNodes = " << this << ".DoubleNodeGroupsNew( " << theNodes << ", "
5168 << theModifiedElems << " )";
5170 return aNewGroup._retn();
5174 //================================================================================
5176 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5177 \param theElems - the list of elements (edges or faces) to be replicated
5178 The nodes for duplication could be found from these elements
5179 \param theNodesNot - list of nodes to NOT replicate
5180 \param theAffectedElems - the list of elements (cells and edges) to which the
5181 replicated nodes should be associated to.
5182 \return TRUE if operation has been completed successfully, FALSE otherwise
5183 \sa DoubleNodeGroup(), DoubleNodeGroups()
5185 //================================================================================
5187 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
5188 const SMESH::long_array& theNodesNot,
5189 const SMESH::long_array& theAffectedElems )
5194 ::SMESH_MeshEditor aMeshEditor( myMesh );
5196 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5197 TIDSortedElemSet anElems, aNodes, anAffected;
5198 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
5199 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
5200 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
5202 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5204 storeResult( aMeshEditor) ;
5206 myMesh->GetMeshDS()->Modified();
5208 myMesh->SetIsModified( true );
5210 // Update Python script
5211 TPythonDump() << this << ".DoubleNodeElem( " << theElems << ", "
5212 << theNodesNot << ", " << theAffectedElems << " )";
5216 //================================================================================
5218 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5219 \param theElems - the list of elements (edges or faces) to be replicated
5220 The nodes for duplication could be found from these elements
5221 \param theNodesNot - list of nodes to NOT replicate
5222 \param theShape - shape to detect affected elements (element which geometric center
5223 located on or inside shape).
5224 The replicated nodes should be associated to affected elements.
5225 \return TRUE if operation has been completed successfully, FALSE otherwise
5226 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
5228 //================================================================================
5230 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_array& theElems,
5231 const SMESH::long_array& theNodesNot,
5232 GEOM::GEOM_Object_ptr theShape )
5237 ::SMESH_MeshEditor aMeshEditor( myMesh );
5239 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5240 TIDSortedElemSet anElems, aNodes;
5241 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
5242 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
5244 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5245 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5247 storeResult( aMeshEditor) ;
5249 myMesh->GetMeshDS()->Modified();
5251 myMesh->SetIsModified( true );
5253 // Update Python script
5254 TPythonDump() << "isDone = " << this << ".DoubleNodeElemInRegion( " << theElems << ", "
5255 << theNodesNot << ", " << theShape << " )";
5259 //================================================================================
5261 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5262 \param theElems - group of of elements (edges or faces) to be replicated
5263 \param theNodesNot - group of nodes not to replicated
5264 \param theAffectedElems - group of elements to which the replicated nodes
5265 should be associated to.
5266 \return TRUE if operation has been completed successfully, FALSE otherwise
5267 \sa DoubleNodes(), DoubleNodeGroups()
5269 //================================================================================
5271 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_ptr theElems,
5272 SMESH::SMESH_GroupBase_ptr theNodesNot,
5273 SMESH::SMESH_GroupBase_ptr theAffectedElems)
5275 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5280 ::SMESH_MeshEditor aMeshEditor( myMesh );
5282 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5283 TIDSortedElemSet anElems, aNodes, anAffected;
5284 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5285 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5286 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
5288 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5290 storeResult( aMeshEditor) ;
5292 myMesh->GetMeshDS()->Modified();
5294 myMesh->SetIsModified( true );
5296 // Update Python script
5297 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroup( " << theElems << ", "
5298 << theNodesNot << ", " << theAffectedElems << " )";
5303 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5304 * Works as DoubleNodeElemGroup(), but returns a new group with newly created elements.
5305 * \param theElems - group of of elements (edges or faces) to be replicated
5306 * \param theNodesNot - group of nodes not to replicated
5307 * \param theAffectedElems - group of elements to which the replicated nodes
5308 * should be associated to.
5309 * \return a new group with newly created elements
5310 * \sa DoubleNodeElemGroup()
5312 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems,
5313 SMESH::SMESH_GroupBase_ptr theNodesNot,
5314 SMESH::SMESH_GroupBase_ptr theAffectedElems)
5316 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5319 SMESH::SMESH_Group_var aNewGroup;
5323 ::SMESH_MeshEditor aMeshEditor( myMesh );
5325 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5326 TIDSortedElemSet anElems, aNodes, anAffected;
5327 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5328 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5329 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
5332 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5334 storeResult( aMeshEditor) ;
5337 myMesh->SetIsModified( true );
5339 // Create group with newly created elements
5340 SMESH::long_array_var anIds = GetLastCreatedElems();
5341 if (anIds->length() > 0) {
5342 SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
5343 string anUnindexedName (theElems->GetName());
5344 string aNewName = generateGroupName(anUnindexedName + "_double");
5345 aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
5346 aNewGroup->Add(anIds);
5350 // Update Python script
5351 TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupNew( " << theElems << ", "
5352 << theNodesNot << ", " << theAffectedElems << " )";
5353 return aNewGroup._retn();
5356 //================================================================================
5358 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5359 \param theElems - group of of elements (edges or faces) to be replicated
5360 \param theNodesNot - group of nodes not to replicated
5361 \param theShape - shape to detect affected elements (element which geometric center
5362 located on or inside shape).
5363 The replicated nodes should be associated to affected elements.
5364 \return TRUE if operation has been completed successfully, FALSE otherwise
5365 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
5367 //================================================================================
5369 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_GroupBase_ptr theElems,
5370 SMESH::SMESH_GroupBase_ptr theNodesNot,
5371 GEOM::GEOM_Object_ptr theShape )
5374 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5379 ::SMESH_MeshEditor aMeshEditor( myMesh );
5381 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5382 TIDSortedElemSet anElems, aNodes, anAffected;
5383 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5384 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5386 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5387 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5389 storeResult( aMeshEditor) ;
5391 myMesh->GetMeshDS()->Modified();
5393 myMesh->SetIsModified( true );
5395 // Update Python script
5396 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupInRegion( " << theElems << ", "
5397 << theNodesNot << ", " << theShape << " )";
5401 //================================================================================
5403 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5404 This method provided for convenience works as DoubleNodes() described above.
5405 \param theElems - list of groups of elements (edges or faces) to be replicated
5406 \param theNodesNot - list of groups of nodes not to replicated
5407 \param theAffectedElems - group of elements to which the replicated nodes
5408 should be associated to.
5409 \return TRUE if operation has been completed successfully, FALSE otherwise
5410 \sa DoubleNodeGroup(), DoubleNodes(), DoubleNodeElemGroupsNew()
5412 //================================================================================
5414 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
5415 SMESHDS_Mesh* theMeshDS,
5416 TIDSortedElemSet& theElemSet,
5417 const bool theIsNodeGrp)
5419 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
5421 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
5422 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
5423 : aGrp->GetType() != SMESH::NODE ) )
5425 SMESH::long_array_var anIDs = aGrp->GetIDs();
5426 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
5431 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroups& theElems,
5432 const SMESH::ListOfGroups& theNodesNot,
5433 const SMESH::ListOfGroups& theAffectedElems)
5437 ::SMESH_MeshEditor aMeshEditor( myMesh );
5439 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5440 TIDSortedElemSet anElems, aNodes, anAffected;
5441 listOfGroupToSet(theElems, aMeshDS, anElems, false );
5442 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5443 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
5445 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5447 storeResult( aMeshEditor) ;
5449 myMesh->GetMeshDS()->Modified();
5451 myMesh->SetIsModified( true );
5453 // Update Python script
5454 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroups( " << &theElems << ", "
5455 << &theNodesNot << ", " << &theAffectedElems << " )";
5459 //================================================================================
5461 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5462 * Works as DoubleNodeElemGroups(), but returns a new group with newly created elements.
5463 \param theElems - list of groups of elements (edges or faces) to be replicated
5464 \param theNodesNot - list of groups of nodes not to replicated
5465 \param theAffectedElems - group of elements to which the replicated nodes
5466 should be associated to.
5467 * \return a new group with newly created elements
5468 * \sa DoubleNodeElemGroups()
5470 //================================================================================
5472 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupsNew(const SMESH::ListOfGroups& theElems,
5473 const SMESH::ListOfGroups& theNodesNot,
5474 const SMESH::ListOfGroups& theAffectedElems)
5476 SMESH::SMESH_Group_var aNewGroup;
5480 ::SMESH_MeshEditor aMeshEditor( myMesh );
5482 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5483 TIDSortedElemSet anElems, aNodes, anAffected;
5484 listOfGroupToSet(theElems, aMeshDS, anElems, false );
5485 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5486 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
5488 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5490 storeResult( aMeshEditor) ;
5492 myMesh->GetMeshDS()->Modified();
5494 myMesh->SetIsModified( true );
5496 // Create group with newly created elements
5497 SMESH::long_array_var anIds = GetLastCreatedElems();
5498 if (anIds->length() > 0) {
5499 SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
5500 string anUnindexedName (theElems[0]->GetName());
5501 string aNewName = generateGroupName(anUnindexedName + "_double");
5502 aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
5503 aNewGroup->Add(anIds);
5507 // Update Python script
5508 TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupsNew( " << &theElems << ", "
5509 << &theNodesNot << ", " << &theAffectedElems << " )";
5510 return aNewGroup._retn();
5513 //================================================================================
5515 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5516 This method provided for convenience works as DoubleNodes() described above.
5517 \param theElems - list of groups of elements (edges or faces) to be replicated
5518 \param theNodesNot - list of groups of nodes not to replicated
5519 \param theShape - shape to detect affected elements (element which geometric center
5520 located on or inside shape).
5521 The replicated nodes should be associated to affected elements.
5522 \return TRUE if operation has been completed successfully, FALSE otherwise
5523 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
5525 //================================================================================
5528 SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theElems,
5529 const SMESH::ListOfGroups& theNodesNot,
5530 GEOM::GEOM_Object_ptr theShape )
5534 ::SMESH_MeshEditor aMeshEditor( myMesh );
5536 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5537 TIDSortedElemSet anElems, aNodes;
5538 listOfGroupToSet(theElems, aMeshDS, anElems,false );
5539 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5541 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5542 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5544 storeResult( aMeshEditor) ;
5546 myMesh->GetMeshDS()->Modified();
5548 myMesh->SetIsModified( true );
5550 // Update Python script
5551 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupsInRegion( " << &theElems << ", "
5552 << &theNodesNot << ", " << theShape << " )";
5556 //================================================================================
5558 \brief Generated skin mesh (containing 2D cells) from 3D mesh
5559 The created 2D mesh elements based on nodes of free faces of boundary volumes
5560 \return TRUE if operation has been completed successfully, FALSE otherwise
5562 //================================================================================
5564 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
5568 ::SMESH_MeshEditor aMeshEditor( myMesh );
5569 bool aResult = aMeshEditor.Make2DMeshFrom3D();
5570 storeResult( aMeshEditor) ;
5571 myMesh->GetMeshDS()->Modified();
5572 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";
5576 //================================================================================
5578 * \brief Double nodes on shared faces between groups of volumes and create flat elements on demand.
5579 * The list of groups must describe a partition of the mesh volumes.
5580 * The nodes of the internal faces at the boundaries of the groups are doubled.
5581 * In option, the internal faces are replaced by flat elements.
5582 * Triangles are transformed in prisms, and quadrangles in hexahedrons.
5583 * @param theDomains - list of groups of volumes
5584 * @param createJointElems - if TRUE, create the elements
5585 * @return TRUE if operation has been completed successfully, FALSE otherwise
5587 //================================================================================
5589 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::ListOfGroups& theDomains,
5590 CORBA::Boolean createJointElems )
5594 ::SMESH_MeshEditor aMeshEditor( myMesh );
5596 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5598 vector<TIDSortedElemSet> domains;
5601 for ( int i = 0, n = theDomains.length(); i < n; i++ )
5603 SMESH::SMESH_GroupBase_var aGrp = theDomains[ i ];
5604 if ( !CORBA::is_nil( aGrp ) && ( aGrp->GetType() != SMESH::NODE ) )
5606 TIDSortedElemSet domain;
5608 domains.push_back(domain);
5609 SMESH::long_array_var anIDs = aGrp->GetIDs();
5610 arrayToSet( anIDs, aMeshDS, domains[ i ], SMDSAbs_All );
5614 bool aResult = aMeshEditor.DoubleNodesOnGroupBoundaries( domains, createJointElems );
5616 storeResult( aMeshEditor) ;
5617 myMesh->GetMeshDS()->Modified();
5619 // Update Python script
5620 TPythonDump() << "isDone = " << this << ".DoubleNodesOnGroupBoundaries( " << &theDomains
5621 << ", " << createJointElems << " )";
5625 // issue 20749 ===================================================================
5627 * \brief Creates missing boundary elements
5628 * \param elements - elements whose boundary is to be checked
5629 * \param dimension - defines type of boundary elements to create
5630 * \param groupName - a name of group to store created boundary elements in,
5631 * "" means not to create the group
5632 * \param meshName - a name of new mesh to store created boundary elements in,
5633 * "" means not to create the new mesh
5634 * \param toCopyElements - if true, the checked elements will be copied into the new mesh
5635 * \param toCopyExistingBondary - if true, not only new but also pre-existing
5636 * boundary elements will be copied into the new mesh
5637 * \param group - returns the create group, if any
5638 * \retval SMESH::SMESH_Mesh - the mesh where elements were added to
5640 // ================================================================================
5642 SMESH::SMESH_Mesh_ptr
5643 SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource,
5644 SMESH::Bnd_Dimension dim,
5645 const char* groupName,
5646 const char* meshName,
5647 CORBA::Boolean toCopyElements,
5648 CORBA::Boolean toCopyExistingBondary,
5649 SMESH::SMESH_Group_out group)
5653 if ( dim > SMESH::BND_1DFROM2D )
5654 THROW_SALOME_CORBA_EXCEPTION("Invalid boundary dimension", SALOME::BAD_PARAM);
5656 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5658 SMESH::SMESH_Mesh_var mesh_var;
5659 SMESH::SMESH_Group_var group_var;
5663 TIDSortedElemSet elements;
5664 SMDSAbs_ElementType elemType = (dim == SMESH::BND_1DFROM2D) ? SMDSAbs_Face : SMDSAbs_Volume;
5665 if ( idSourceToSet( idSource, aMeshDS, elements, elemType,/*emptyIfIsMesh=*/true ))
5669 strlen(meshName) ? makeMesh(meshName) : SMESH::SMESH_Mesh::_duplicate(myMesh_i->_this());
5670 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh_var );
5672 SMESH_Mesh* smesh_mesh = (mesh_i==myMesh_i) ? (SMESH_Mesh*)0 : &mesh_i->GetImpl();
5674 // group of new boundary elements
5675 SMESH_Group* smesh_group = 0;
5676 if ( strlen(groupName) )
5678 group_var = mesh_i->CreateGroup( SMESH::ElementType(int(elemType)-1),groupName);
5679 if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( group_var ))
5680 smesh_group = group_i->GetSmeshGroup();
5684 ::SMESH_MeshEditor aMeshEditor( myMesh );
5685 aMeshEditor.MakeBoundaryMesh( elements,
5686 ::SMESH_MeshEditor::Bnd_Dimension(dim),
5690 toCopyExistingBondary);
5691 storeResult( aMeshEditor );
5694 smesh_mesh->GetMeshDS()->Modified();
5697 const char* dimName[] = { "BND_2DFROM3D", "BND_1DFROM3D", "BND_1DFROM2D" };
5699 // result of MakeBoundaryMesh() is a tuple (mesh, group)
5700 if ( mesh_var->_is_nil() )
5701 pyDump << myMesh_i->_this() << ", ";
5703 pyDump << mesh_var << ", ";
5704 if ( group_var->_is_nil() )
5705 pyDump << "_NoneGroup = "; // assignment to None is forbiden
5707 pyDump << group_var << " = ";
5708 pyDump << this << ".MakeBoundaryMesh( "
5710 << "SMESH." << dimName[int(dim)] << ", "
5711 << "'" << groupName << "', "
5712 << "'" << meshName<< "', "
5713 << toCopyElements << ", "
5714 << toCopyExistingBondary << ")";
5716 group = group_var._retn();
5717 return mesh_var._retn();
5720 //================================================================================
5722 * \brief Creates missing boundary elements
5723 * \param dimension - defines type of boundary elements to create
5724 * \param groupName - a name of group to store all boundary elements in,
5725 * "" means not to create the group
5726 * \param meshName - a name of a new mesh, which is a copy of the initial
5727 * mesh + created boundary elements; "" means not to create the new mesh
5728 * \param toCopyAll - if true, the whole initial mesh will be copied into
5729 * the new mesh else only boundary elements will be copied into the new mesh
5730 * \param groups - optional groups of elements to make boundary around
5731 * \param mesh - returns the mesh where elements were added to
5732 * \param group - returns the created group, if any
5733 * \retval long - number of added boundary elements
5735 //================================================================================
5737 CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim,
5738 const char* groupName,
5739 const char* meshName,
5740 CORBA::Boolean toCopyAll,
5741 const SMESH::ListOfIDSources& groups,
5742 SMESH::SMESH_Mesh_out mesh,
5743 SMESH::SMESH_Group_out group)
5744 throw (SALOME::SALOME_Exception)
5746 Unexpect aCatch(SALOME_SalomeException);
5750 if ( dim > SMESH::BND_1DFROM2D )
5751 THROW_SALOME_CORBA_EXCEPTION("Invalid boundary dimension", SALOME::BAD_PARAM);
5753 // check that groups belongs to to this mesh and is not this mesh
5754 const int nbGroups = groups.length();
5755 for ( int i = 0; i < nbGroups; ++i )
5757 SMESH::SMESH_Mesh_var m = groups[i]->GetMesh();
5758 if ( myMesh_i != SMESH::DownCast<SMESH_Mesh_i*>( m ))
5759 THROW_SALOME_CORBA_EXCEPTION("group does not belong to this mesh", SALOME::BAD_PARAM);
5760 if ( SMESH::DownCast<SMESH_Mesh_i*>( groups[i] ))
5761 THROW_SALOME_CORBA_EXCEPTION("expect a group but recieve a mesh", SALOME::BAD_PARAM);
5767 SMESH::SMESH_Mesh_var mesh_var;
5768 SMESH::SMESH_Group_var group_var;
5771 mesh_var = SMESH::SMESH_Mesh::_duplicate( myMesh_i->_this() );
5772 const bool toCopyMesh = ( strlen( meshName ) > 0 );
5776 mesh_var = SMESH_Gen_i::GetSMESHGen()->CopyMesh(mesh_var,
5778 /*toCopyGroups=*/false,
5779 /*toKeepIDs=*/true);
5781 mesh_var = makeMesh(meshName);
5783 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh_var );
5784 SMESH_Mesh* tgtMesh = &mesh_i->GetImpl();
5787 SMESH_Mesh* srcMesh = ( toCopyMesh && !toCopyAll ) ? myMesh : tgtMesh;
5788 SMESHDS_Mesh* srcMeshDS = srcMesh->GetMeshDS();
5790 // group of boundary elements
5791 SMESH_Group* smesh_group = 0;
5792 SMDSAbs_ElementType elemType = (dim == SMESH::BND_2DFROM3D) ? SMDSAbs_Volume : SMDSAbs_Face;
5793 if ( strlen(groupName) )
5795 SMESH::ElementType groupType = SMESH::ElementType( int(elemType)-1 );
5796 group_var = mesh_i->CreateGroup( groupType, groupName );
5797 if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( group_var ))
5798 smesh_group = group_i->GetSmeshGroup();
5801 TIDSortedElemSet elements;
5805 for ( int i = 0; i < nbGroups; ++i )
5808 if ( idSourceToSet( groups[i], srcMeshDS, elements, elemType,/*emptyIfIsMesh=*/false ))
5810 SMESH::Bnd_Dimension bdim =
5811 ( elemType == SMDSAbs_Volume ) ? SMESH::BND_2DFROM3D : SMESH::BND_1DFROM2D;
5812 ::SMESH_MeshEditor aMeshEditor( srcMesh );
5813 nbAdded += aMeshEditor.MakeBoundaryMesh( elements,
5814 ::SMESH_MeshEditor::Bnd_Dimension(bdim),
5817 /*toCopyElements=*/false,
5818 /*toCopyExistingBondary=*/srcMesh != tgtMesh,
5819 /*toAddExistingBondary=*/true,
5820 /*aroundElements=*/true);
5821 storeResult( aMeshEditor );
5827 ::SMESH_MeshEditor aMeshEditor( srcMesh );
5828 nbAdded += aMeshEditor.MakeBoundaryMesh( elements,
5829 ::SMESH_MeshEditor::Bnd_Dimension(dim),
5832 /*toCopyElements=*/false,
5833 /*toCopyExistingBondary=*/srcMesh != tgtMesh,
5834 /*toAddExistingBondary=*/true);
5835 storeResult( aMeshEditor );
5837 tgtMesh->GetMeshDS()->Modified();
5839 const char* dimName[] = { "BND_2DFROM3D", "BND_1DFROM3D", "BND_1DFROM2D" };
5841 // result of MakeBoundaryElements() is a tuple (nb, mesh, group)
5842 pyDump << "nbAdded, ";
5843 if ( mesh_var->_is_nil() )
5844 pyDump << myMesh_i->_this() << ", ";
5846 pyDump << mesh_var << ", ";
5847 if ( group_var->_is_nil() )
5848 pyDump << "_NoneGroup = "; // assignment to None is forbiden
5850 pyDump << group_var << " = ";
5851 pyDump << this << ".MakeBoundaryElements( "
5852 << "SMESH." << dimName[int(dim)] << ", "
5853 << "'" << groupName << "', "
5854 << "'" << meshName<< "', "
5855 << toCopyAll << ", "
5858 mesh = mesh_var._retn();
5859 group = group_var._retn();