1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 // File : SMESH_MeshEditor_i.cxx
25 // Author : Nicolas REJNERI
32 #include "SMESH_MeshEditor_i.hxx"
34 #include "SMDS_Mesh0DElement.hxx"
35 #include "SMDS_MeshEdge.hxx"
36 #include "SMDS_MeshFace.hxx"
37 #include "SMDS_MeshVolume.hxx"
38 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
39 #include "SMESH_subMeshEventListener.hxx"
40 #include "SMESH_Gen_i.hxx"
41 #include "SMESH_Filter_i.hxx"
42 #include "SMESH_subMesh_i.hxx"
43 #include "SMESH_Group_i.hxx"
44 #include "SMESH_PythonDump.hxx"
45 #include "SMESH_ControlsDef.hxx"
47 #include "utilities.h"
48 #include "Utils_ExceptHandlers.hxx"
49 #include "Utils_CorbaException.hxx"
51 #include <BRepAdaptor_Surface.hxx>
52 #include <BRep_Tool.hxx>
53 #include <TopExp_Explorer.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Face.hxx>
61 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
65 #include <Standard_Failure.hxx>
68 #include <Standard_ErrorHandler.hxx>
74 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
77 using SMESH::TPythonDump;
81 //=============================================================================
83 * \brief Mesh to apply modifications for preview purposes
85 //=============================================================================
87 struct TPreviewMesh: public SMESH_Mesh
89 SMDSAbs_ElementType myPreviewType; // type to show
91 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
92 _isShapeToMesh = (_id =_studyId =_idDoc = 0);
93 _myMeshDS = new SMESHDS_Mesh( _id, true );
94 myPreviewType = previewElements;
97 virtual ~TPreviewMesh() { delete _myMeshDS; }
98 //!< Copy a set of elements
99 void Copy(const TIDSortedElemSet & theElements,
100 TIDSortedElemSet& theCopyElements,
101 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
102 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
104 // loop on theIDsOfElements
105 TIDSortedElemSet::const_iterator eIt = theElements.begin();
106 for ( ; eIt != theElements.end(); ++eIt )
108 const SMDS_MeshElement* anElem = *eIt;
109 if ( !anElem ) continue;
110 SMDSAbs_ElementType type = anElem->GetType();
111 if ( type == theAvoidType ||
112 ( theSelectType != SMDSAbs_All && type != theSelectType ))
115 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
116 theCopyElements.insert( theCopyElements.end(), anElemCopy );
120 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
122 // copy element nodes
123 int anElemNbNodes = anElem->NbNodes();
124 vector< int > anElemNodesID( anElemNbNodes ) ;
125 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
126 for ( int i = 0; itElemNodes->more(); i++)
128 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
130 anElemNodesID[i] = anElemNode->GetID();
133 // creates a corresponding element on copied nodes
134 SMDS_MeshElement* anElemCopy = 0;
135 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
137 const SMDS_PolyhedralVolumeOfNodes* ph =
138 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
140 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
141 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
144 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
151 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
153 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
154 anElemNode->GetID());
156 };// struct TPreviewMesh
158 static SMESH_NodeSearcher * theNodeSearcher = 0;
159 static SMESH_ElementSearcher * theElementSearcher = 0;
161 //=============================================================================
163 * \brief Deleter of theNodeSearcher at any compute event occured
165 //=============================================================================
167 struct TSearchersDeleter : public SMESH_subMeshEventListener
171 TSearchersDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
173 //!< Delete theNodeSearcher
176 if ( theNodeSearcher ) delete theNodeSearcher; theNodeSearcher = 0;
177 if ( theElementSearcher ) delete theElementSearcher; theElementSearcher = 0;
179 typedef map < int, SMESH_subMesh * > TDependsOnMap;
180 //!< The meshod called by submesh: do my main job
181 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
182 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
184 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
186 Unset( sm->GetFather() );
189 //!< set self on all submeshes and delete theNodeSearcher if other mesh is set
190 void Set(SMESH_Mesh* mesh)
192 if ( myMesh != mesh )
199 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
200 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
201 TDependsOnMap::const_iterator sm;
202 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
203 sm->second->SetEventListener( this, 0, sm->second );
207 //!< delete self from all submeshes
208 void Unset(SMESH_Mesh* mesh)
210 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
211 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
212 TDependsOnMap::const_iterator sm;
213 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
214 sm->second->DeleteEventListener( this );
219 } theSearchersDeleter;
221 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
223 TCollection_AsciiString typeStr;
224 switch ( theMirrorType ) {
225 case SMESH::SMESH_MeshEditor::POINT:
226 typeStr = "SMESH.SMESH_MeshEditor.POINT";
228 case SMESH::SMESH_MeshEditor::AXIS:
229 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
232 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
236 //================================================================================
238 * \brief function for conversion long_array to TIDSortedElemSet
239 * \param IDs - array of IDs
240 * \param aMesh - mesh
241 * \param aMap - collection to fill
242 * \param aType - element type
244 //================================================================================
246 void arrayToSet(const SMESH::long_array & IDs,
247 const SMESHDS_Mesh* aMesh,
248 TIDSortedElemSet& aMap,
249 const SMDSAbs_ElementType aType = SMDSAbs_All )
251 for (int i=0; i<IDs.length(); i++) {
252 CORBA::Long ind = IDs[i];
253 const SMDS_MeshElement * elem =
254 (aType == SMDSAbs_Node ? aMesh->FindNode(ind) : aMesh->FindElement(ind));
255 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
259 //================================================================================
261 * \brief Retrieve elements of given type from SMESH_IDSource
263 //================================================================================
265 bool idSourceToSet(SMESH::SMESH_IDSource_ptr theIDSource,
266 const SMESHDS_Mesh* theMeshDS,
267 TIDSortedElemSet& theElemSet,
268 const SMDSAbs_ElementType theType,
269 const bool emptyIfIsMesh=false)
272 if ( CORBA::is_nil( theIDSource ) )
274 if ( emptyIfIsMesh && SMESH::DownCast<SMESH_Mesh_i*>( theIDSource ))
277 SMESH::long_array_var anIDs = theIDSource->GetIDs();
278 if ( anIDs->length() == 0 )
280 SMESH::array_of_ElementType_var types = theIDSource->GetTypes();
281 if ( types->length() == 1 && types[0] == SMESH::NODE ) // group of nodes
283 if ( theType == SMDSAbs_All || theType == SMDSAbs_Node )
284 arrayToSet( anIDs, theMeshDS, theElemSet, SMDSAbs_Node );
290 arrayToSet( anIDs, theMeshDS, theElemSet, theType);
294 //================================================================================
296 * \brief Retrieve nodes from SMESH_IDSource
298 //================================================================================
300 void idSourceToNodeSet(SMESH::SMESH_IDSource_ptr theObject,
301 const SMESHDS_Mesh* theMeshDS,
302 TIDSortedNodeSet& theNodeSet)
305 if ( CORBA::is_nil( theObject ) )
307 SMESH::array_of_ElementType_var types = theObject->GetTypes();
308 SMESH::long_array_var aElementsId = theObject->GetIDs();
309 if ( types->length() == 1 && types[0] == SMESH::NODE)
311 for(int i = 0; i < aElementsId->length(); i++)
312 if ( const SMDS_MeshNode * n = theMeshDS->FindNode( aElementsId[i] ))
313 theNodeSet.insert( theNodeSet.end(), n);
316 for(int i = 0; i < aElementsId->length(); i++)
317 if( const SMDS_MeshElement * elem = theMeshDS->FindElement( aElementsId[i] ))
318 theNodeSet.insert( elem->begin_nodes(), elem->end_nodes());
323 //=============================================================================
327 //=============================================================================
329 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
332 myMesh = & theMesh->GetImpl();
333 myPreviewMode = isPreview;
336 //================================================================================
340 //================================================================================
342 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
346 //================================================================================
348 * \brief Clear members
350 //================================================================================
352 void SMESH_MeshEditor_i::initData(bool deleteSearchers)
354 if ( myPreviewMode ) {
355 myPreviewData = new SMESH::MeshPreviewStruct();
358 myLastCreatedElems = new SMESH::long_array();
359 myLastCreatedNodes = new SMESH::long_array();
360 if ( deleteSearchers )
361 TSearchersDeleter::Delete();
365 //=======================================================================
366 //function : MakeIDSource
367 //purpose : Wrap a sequence of ids in a SMESH_IDSource
368 //=======================================================================
370 struct _IDSource : public POA_SMESH::SMESH_IDSource
372 SMESH::long_array _ids;
373 SMESH::ElementType _type;
374 SMESH::SMESH_Mesh_ptr _mesh;
375 SMESH::long_array* GetIDs() { return new SMESH::long_array( _ids ); }
376 SMESH::long_array* GetMeshInfo() { return 0; }
377 SMESH::SMESH_Mesh_ptr GetMesh() { return SMESH::SMESH_Mesh::_duplicate( _mesh ); }
378 SMESH::array_of_ElementType* GetTypes()
380 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
383 return types._retn();
387 SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_array& ids,
388 SMESH::ElementType type)
390 _IDSource* anIDSource = new _IDSource;
391 anIDSource->_ids = ids;
392 anIDSource->_type = type;
393 anIDSource->_mesh = myMesh_i->_this();
394 SMESH::SMESH_IDSource_var anIDSourceVar = anIDSource->_this();
396 return anIDSourceVar._retn();
399 //=============================================================================
403 //=============================================================================
406 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
410 ::SMESH_MeshEditor anEditor( myMesh );
413 for (int i = 0; i < IDsOfElements.length(); i++)
414 IdList.push_back( IDsOfElements[i] );
416 // Update Python script
417 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
419 if ( IDsOfElements.length() )
420 myMesh->SetIsModified( true ); // issue 0020693
423 return anEditor.Remove( IdList, false );
426 //=============================================================================
430 //=============================================================================
432 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
436 ::SMESH_MeshEditor anEditor( myMesh );
438 for (int i = 0; i < IDsOfNodes.length(); i++)
439 IdList.push_back( IDsOfNodes[i] );
441 // Update Python script
442 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
444 if ( IDsOfNodes.length() )
445 myMesh->SetIsModified( true ); // issue 0020693
447 return anEditor.Remove( IdList, true );
450 //=============================================================================
454 //=============================================================================
456 CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes()
460 ::SMESH_MeshEditor anEditor( myMesh );
462 // Update Python script
463 TPythonDump() << "nbRemoved = " << this << ".RemoveOrphanNodes()";
465 // Create filter to find all orphan nodes
466 SMESH::Controls::Filter::TIdSequence seq;
467 SMESH::Controls::PredicatePtr predicate( new SMESH::Controls::FreeNodes() );
468 SMESH::Controls::Filter::GetElementsId( GetMeshDS(), predicate, seq );
470 // remove orphan nodes (if there are any)
472 for ( int i = 0; i < seq.size(); i++ )
473 IdList.push_back( seq[i] );
476 myMesh->SetIsModified( true );
478 return anEditor.Remove( IdList, true );
481 //=============================================================================
485 //=============================================================================
487 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
488 CORBA::Double y, CORBA::Double z)
492 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
494 // Update Python script
495 TPythonDump() << "nodeID = " << this << ".AddNode( "
496 << x << ", " << y << ", " << z << " )";
498 myMesh->SetIsModified( true ); // issue 0020693
503 //=============================================================================
507 //=============================================================================
508 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
512 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
513 SMDS_MeshElement* elem = GetMeshDS()->Add0DElement(aNode);
515 // Update Python script
516 TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
518 myMesh->SetIsModified( true ); // issue 0020693
521 return elem->GetID();
526 //=============================================================================
530 //=============================================================================
532 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
536 int NbNodes = IDsOfNodes.length();
537 SMDS_MeshElement* elem = 0;
540 CORBA::Long index1 = IDsOfNodes[0];
541 CORBA::Long index2 = IDsOfNodes[1];
542 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
544 // Update Python script
545 TPythonDump() << "edge = " << this << ".AddEdge([ "
546 << index1 << ", " << index2 <<" ])";
549 CORBA::Long n1 = IDsOfNodes[0];
550 CORBA::Long n2 = IDsOfNodes[1];
551 CORBA::Long n12 = IDsOfNodes[2];
552 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
553 GetMeshDS()->FindNode(n2),
554 GetMeshDS()->FindNode(n12));
555 // Update Python script
556 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
557 <<n1<<", "<<n2<<", "<<n12<<" ])";
561 return myMesh->SetIsModified( true ), elem->GetID();
566 //=============================================================================
570 //=============================================================================
572 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
576 int NbNodes = IDsOfNodes.length();
582 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
583 for (int i = 0; i < NbNodes; i++)
584 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
586 SMDS_MeshElement* elem = 0;
588 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
590 else if (NbNodes == 4) {
591 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
593 else if (NbNodes == 6) {
594 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
597 else if (NbNodes == 8) {
598 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
599 nodes[4], nodes[5], nodes[6], nodes[7]);
601 else if (NbNodes > 2) {
602 elem = GetMeshDS()->AddPolygonalFace(nodes);
605 // Update Python script
606 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
609 return myMesh->SetIsModified( true ), elem->GetID();
614 //=============================================================================
618 //=============================================================================
619 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsOfNodes)
623 int NbNodes = IDsOfNodes.length();
624 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
625 for (int i = 0; i < NbNodes; i++)
626 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
628 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
630 // Update Python script
631 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
633 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
636 //=============================================================================
640 //=============================================================================
642 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
646 int NbNodes = IDsOfNodes.length();
647 vector< const SMDS_MeshNode*> n(NbNodes);
648 for(int i=0;i<NbNodes;i++)
649 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
651 SMDS_MeshElement* elem = 0;
654 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
655 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
656 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
657 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
658 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
659 n[6],n[7],n[8],n[9]);
661 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
662 n[7],n[8],n[9],n[10],n[11],n[12]);
664 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
665 n[9],n[10],n[11],n[12],n[13],n[14]);
667 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
668 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
669 n[15],n[16],n[17],n[18],n[19]);
673 // Update Python script
674 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
677 return myMesh->SetIsModified( true ), elem->GetID();
682 //=============================================================================
684 * AddPolyhedralVolume
686 //=============================================================================
687 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume (const SMESH::long_array & IDsOfNodes,
688 const SMESH::long_array & Quantities)
692 int NbNodes = IDsOfNodes.length();
693 std::vector<const SMDS_MeshNode*> n (NbNodes);
694 for (int i = 0; i < NbNodes; i++)
695 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
697 int NbFaces = Quantities.length();
698 std::vector<int> q (NbFaces);
699 for (int j = 0; j < NbFaces; j++)
700 q[j] = Quantities[j];
702 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
704 // Update Python script
705 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
706 << IDsOfNodes << ", " << Quantities << " )";
708 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
711 //=============================================================================
713 * AddPolyhedralVolumeByFaces
715 //=============================================================================
716 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_array & IdsOfFaces)
720 int NbFaces = IdsOfFaces.length();
721 std::vector<const SMDS_MeshNode*> poly_nodes;
722 std::vector<int> quantities (NbFaces);
724 for (int i = 0; i < NbFaces; i++) {
725 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
726 quantities[i] = aFace->NbNodes();
728 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
730 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
734 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
736 // Update Python script
737 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
738 << IdsOfFaces << " )";
740 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
743 //=============================================================================
745 * \brief Bind a node to a vertex
746 * \param NodeID - node ID
747 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
748 * \retval boolean - false if NodeID or VertexID is invalid
750 //=============================================================================
752 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
753 throw (SALOME::SALOME_Exception)
755 Unexpect aCatch(SALOME_SalomeException);
757 SMESHDS_Mesh * mesh = GetMeshDS();
758 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
760 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
762 if ( mesh->MaxShapeIndex() < VertexID )
763 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
765 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
766 if ( shape.ShapeType() != TopAbs_VERTEX )
767 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
769 mesh->SetNodeOnVertex( node, VertexID );
771 myMesh->SetIsModified( true );
774 //=============================================================================
776 * \brief Store node position on an edge
777 * \param NodeID - node ID
778 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
779 * \param paramOnEdge - parameter on edge where the node is located
780 * \retval boolean - false if any parameter is invalid
782 //=============================================================================
784 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
785 CORBA::Double paramOnEdge)
786 throw (SALOME::SALOME_Exception)
788 Unexpect aCatch(SALOME_SalomeException);
790 SMESHDS_Mesh * mesh = GetMeshDS();
791 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
793 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
795 if ( mesh->MaxShapeIndex() < EdgeID )
796 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
798 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
799 if ( shape.ShapeType() != TopAbs_EDGE )
800 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
803 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
804 if ( paramOnEdge < f || paramOnEdge > l )
805 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
807 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
809 myMesh->SetIsModified( true );
812 //=============================================================================
814 * \brief Store node position on a face
815 * \param NodeID - node ID
816 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
817 * \param u - U parameter on face where the node is located
818 * \param v - V parameter on face where the node is located
819 * \retval boolean - false if any parameter is invalid
821 //=============================================================================
823 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
824 CORBA::Double u, CORBA::Double v)
825 throw (SALOME::SALOME_Exception)
827 Unexpect aCatch(SALOME_SalomeException);
829 SMESHDS_Mesh * mesh = GetMeshDS();
830 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
832 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
834 if ( mesh->MaxShapeIndex() < FaceID )
835 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
837 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
838 if ( shape.ShapeType() != TopAbs_FACE )
839 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
841 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
842 bool isOut = ( u < surf.FirstUParameter() ||
843 u > surf.LastUParameter() ||
844 v < surf.FirstVParameter() ||
845 v > surf.LastVParameter() );
849 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
850 << " u( " << surf.FirstUParameter()
851 << "," << surf.LastUParameter()
852 << ") v( " << surf.FirstVParameter()
853 << "," << surf.LastVParameter() << ")" );
855 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
858 mesh->SetNodeOnFace( node, FaceID, u, v );
860 myMesh->SetIsModified( true );
863 //=============================================================================
865 * \brief Bind a node to a solid
866 * \param NodeID - node ID
867 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
868 * \retval boolean - false if NodeID or SolidID is invalid
870 //=============================================================================
872 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
873 throw (SALOME::SALOME_Exception)
875 Unexpect aCatch(SALOME_SalomeException);
877 SMESHDS_Mesh * mesh = GetMeshDS();
878 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
880 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
882 if ( mesh->MaxShapeIndex() < SolidID )
883 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
885 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
886 if ( shape.ShapeType() != TopAbs_SOLID &&
887 shape.ShapeType() != TopAbs_SHELL)
888 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
890 mesh->SetNodeInVolume( node, SolidID );
892 // myMesh->SetIsModified( true ); - SetNodeInVolume() can't prevent re-compute, I believe
895 //=============================================================================
897 * \brief Bind an element to a shape
898 * \param ElementID - element ID
899 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
900 * \retval boolean - false if ElementID or ShapeID is invalid
902 //=============================================================================
904 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
906 throw (SALOME::SALOME_Exception)
908 Unexpect aCatch(SALOME_SalomeException);
910 SMESHDS_Mesh * mesh = GetMeshDS();
911 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
913 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
915 if ( mesh->MaxShapeIndex() < ShapeID )
916 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
918 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
919 if ( shape.ShapeType() != TopAbs_EDGE &&
920 shape.ShapeType() != TopAbs_FACE &&
921 shape.ShapeType() != TopAbs_SOLID &&
922 shape.ShapeType() != TopAbs_SHELL )
923 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
925 mesh->SetMeshElementOnShape( elem, ShapeID );
927 myMesh->SetIsModified( true );
930 //=============================================================================
934 //=============================================================================
936 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
941 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
942 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
946 // Update Python script
947 TPythonDump() << "isDone = " << this << ".InverseDiag( "
948 << NodeID1 << ", " << NodeID2 << " )";
950 myMesh->SetIsModified( true );
952 ::SMESH_MeshEditor aMeshEditor( myMesh );
953 return aMeshEditor.InverseDiag ( n1, n2 );
956 //=============================================================================
960 //=============================================================================
962 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
967 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
968 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
972 // Update Python script
973 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
974 << NodeID1 << ", " << NodeID2 << " )";
976 ::SMESH_MeshEditor aMeshEditor( myMesh );
978 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
981 myMesh->SetIsModified( true ); // issue 0020693
983 storeResult(aMeshEditor);
988 //=============================================================================
992 //=============================================================================
994 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
998 ::SMESH_MeshEditor anEditor( myMesh );
999 for (int i = 0; i < IDsOfElements.length(); i++)
1001 CORBA::Long index = IDsOfElements[i];
1002 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
1004 anEditor.Reorient( elem );
1006 // Update Python script
1007 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
1009 if ( IDsOfElements.length() )
1010 myMesh->SetIsModified( true ); // issue 0020693
1016 //=============================================================================
1020 //=============================================================================
1022 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
1026 TPythonDump aTPythonDump; // suppress dump in Reorient()
1028 SMESH::long_array_var anElementsId = theObject->GetIDs();
1029 CORBA::Boolean isDone = Reorient(anElementsId);
1031 // Update Python script
1032 aTPythonDump << "isDone = " << this << ".ReorientObject( " << theObject << " )";
1037 //=============================================================================
1041 //=============================================================================
1042 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
1043 SMESH::NumericalFunctor_ptr Criterion,
1044 CORBA::Double MaxAngle)
1048 SMESHDS_Mesh* aMesh = GetMeshDS();
1049 TIDSortedElemSet faces;
1050 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1052 SMESH::NumericalFunctor_i* aNumericalFunctor =
1053 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1054 SMESH::Controls::NumericalFunctorPtr aCrit;
1055 if ( !aNumericalFunctor )
1056 aCrit.reset( new SMESH::Controls::AspectRatio() );
1058 aCrit = aNumericalFunctor->GetNumericalFunctor();
1060 // Update Python script
1061 TPythonDump() << "isDone = " << this << ".TriToQuad( "
1062 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1064 ::SMESH_MeshEditor anEditor( myMesh );
1066 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
1068 myMesh->SetIsModified( true ); // issue 0020693
1070 storeResult(anEditor);
1076 //=============================================================================
1080 //=============================================================================
1081 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1082 SMESH::NumericalFunctor_ptr Criterion,
1083 CORBA::Double MaxAngle)
1087 TPythonDump aTPythonDump; // suppress dump in TriToQuad()
1088 SMESH::long_array_var anElementsId = theObject->GetIDs();
1089 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
1091 SMESH::NumericalFunctor_i* aNumericalFunctor =
1092 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1094 // Update Python script
1095 aTPythonDump << "isDone = " << this << ".TriToQuadObject("
1096 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1102 //=============================================================================
1106 //=============================================================================
1107 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
1108 SMESH::NumericalFunctor_ptr Criterion)
1112 SMESHDS_Mesh* aMesh = GetMeshDS();
1113 TIDSortedElemSet faces;
1114 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1116 SMESH::NumericalFunctor_i* aNumericalFunctor =
1117 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1118 SMESH::Controls::NumericalFunctorPtr aCrit;
1119 if ( !aNumericalFunctor )
1120 aCrit.reset( new SMESH::Controls::AspectRatio() );
1122 aCrit = aNumericalFunctor->GetNumericalFunctor();
1125 // Update Python script
1126 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1128 ::SMESH_MeshEditor anEditor( myMesh );
1129 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1131 myMesh->SetIsModified( true ); // issue 0020693
1133 storeResult(anEditor);
1139 //=============================================================================
1143 //=============================================================================
1144 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1145 SMESH::NumericalFunctor_ptr Criterion)
1149 TPythonDump aTPythonDump; // suppress dump in QuadToTri()
1151 SMESH::long_array_var anElementsId = theObject->GetIDs();
1152 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1154 SMESH::NumericalFunctor_i* aNumericalFunctor =
1155 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1157 // Update Python script
1158 aTPythonDump << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1164 //=============================================================================
1168 //=============================================================================
1169 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1170 CORBA::Boolean Diag13)
1174 SMESHDS_Mesh* aMesh = GetMeshDS();
1175 TIDSortedElemSet faces;
1176 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1178 // Update Python script
1179 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1180 << IDsOfElements << ", " << Diag13 << " )";
1182 ::SMESH_MeshEditor anEditor( myMesh );
1183 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1185 myMesh->SetIsModified( true ); // issue 0020693
1188 storeResult(anEditor);
1194 //=============================================================================
1198 //=============================================================================
1199 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1200 CORBA::Boolean Diag13)
1204 TPythonDump aTPythonDump; // suppress dump in SplitQuad()
1206 SMESH::long_array_var anElementsId = theObject->GetIDs();
1207 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1209 // Update Python script
1210 aTPythonDump << "isDone = " << this << ".SplitQuadObject( "
1211 << theObject << ", " << Diag13 << " )";
1217 //=============================================================================
1221 //=============================================================================
1222 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1223 SMESH::NumericalFunctor_ptr Criterion)
1227 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1228 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1230 SMESH::NumericalFunctor_i* aNumericalFunctor =
1231 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1232 SMESH::Controls::NumericalFunctorPtr aCrit;
1233 if (aNumericalFunctor)
1234 aCrit = aNumericalFunctor->GetNumericalFunctor();
1236 aCrit.reset(new SMESH::Controls::AspectRatio());
1238 ::SMESH_MeshEditor anEditor (myMesh);
1239 return anEditor.BestSplit(quad, aCrit);
1244 //================================================================================
1246 * \brief Split volumic elements into tetrahedrons
1248 //================================================================================
1250 void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems,
1251 CORBA::Short methodFlags)
1252 throw (SALOME::SALOME_Exception)
1254 Unexpect aCatch(SALOME_SalomeException);
1258 SMESH::long_array_var anElementsId = elems->GetIDs();
1259 TIDSortedElemSet elemSet;
1260 arrayToSet( anElementsId, GetMeshDS(), elemSet, SMDSAbs_Volume );
1262 ::SMESH_MeshEditor anEditor (myMesh);
1263 anEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags ));
1265 storeResult(anEditor);
1267 // if ( myLastCreatedElems.length() ) - it does not influence Compute()
1268 // myMesh->SetIsModified( true ); // issue 0020693
1270 TPythonDump() << this << ".SplitVolumesIntoTetra( "
1271 << elems << ", " << methodFlags << " )";
1274 //=======================================================================
1277 //=======================================================================
1280 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1281 const SMESH::long_array & IDsOfFixedNodes,
1282 CORBA::Long MaxNbOfIterations,
1283 CORBA::Double MaxAspectRatio,
1284 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1286 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1287 MaxAspectRatio, Method, false );
1291 //=======================================================================
1292 //function : SmoothParametric
1294 //=======================================================================
1297 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1298 const SMESH::long_array & IDsOfFixedNodes,
1299 CORBA::Long MaxNbOfIterations,
1300 CORBA::Double MaxAspectRatio,
1301 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1303 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1304 MaxAspectRatio, Method, true );
1308 //=======================================================================
1309 //function : SmoothObject
1311 //=======================================================================
1314 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1315 const SMESH::long_array & IDsOfFixedNodes,
1316 CORBA::Long MaxNbOfIterations,
1317 CORBA::Double MaxAspectRatio,
1318 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1320 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1321 MaxAspectRatio, Method, false);
1325 //=======================================================================
1326 //function : SmoothParametricObject
1328 //=======================================================================
1331 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1332 const SMESH::long_array & IDsOfFixedNodes,
1333 CORBA::Long MaxNbOfIterations,
1334 CORBA::Double MaxAspectRatio,
1335 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1337 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1338 MaxAspectRatio, Method, true);
1342 //=============================================================================
1346 //=============================================================================
1349 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1350 const SMESH::long_array & IDsOfFixedNodes,
1351 CORBA::Long MaxNbOfIterations,
1352 CORBA::Double MaxAspectRatio,
1353 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1358 SMESHDS_Mesh* aMesh = GetMeshDS();
1360 TIDSortedElemSet elements;
1361 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1363 set<const SMDS_MeshNode*> fixedNodes;
1364 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1365 CORBA::Long index = IDsOfFixedNodes[i];
1366 const SMDS_MeshNode * node = aMesh->FindNode(index);
1368 fixedNodes.insert( node );
1370 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1371 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1372 method = ::SMESH_MeshEditor::CENTROIDAL;
1374 ::SMESH_MeshEditor anEditor( myMesh );
1375 anEditor.Smooth(elements, fixedNodes, method,
1376 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1378 myMesh->SetIsModified( true ); // issue 0020693
1380 storeResult(anEditor);
1382 // Update Python script
1383 TPythonDump() << "isDone = " << this << "."
1384 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1385 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1386 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1387 << "SMESH.SMESH_MeshEditor."
1388 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1389 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1395 //=============================================================================
1399 //=============================================================================
1402 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1403 const SMESH::long_array & IDsOfFixedNodes,
1404 CORBA::Long MaxNbOfIterations,
1405 CORBA::Double MaxAspectRatio,
1406 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1411 TPythonDump aTPythonDump; // suppress dump in smooth()
1413 SMESH::long_array_var anElementsId = theObject->GetIDs();
1414 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1415 MaxAspectRatio, Method, IsParametric);
1417 // Update Python script
1418 aTPythonDump << "isDone = " << this << "."
1419 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1420 << theObject << ", " << IDsOfFixedNodes << ", "
1421 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1422 << "SMESH.SMESH_MeshEditor."
1423 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1424 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1430 //=============================================================================
1434 //=============================================================================
1436 void SMESH_MeshEditor_i::RenumberNodes()
1438 // Update Python script
1439 TPythonDump() << this << ".RenumberNodes()";
1441 GetMeshDS()->Renumber( true );
1445 //=============================================================================
1449 //=============================================================================
1451 void SMESH_MeshEditor_i::RenumberElements()
1453 // Update Python script
1454 TPythonDump() << this << ".RenumberElements()";
1456 GetMeshDS()->Renumber( false );
1459 //=======================================================================
1461 * \brief Return groups by their IDs
1463 //=======================================================================
1465 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1469 myMesh_i->CreateGroupServants();
1470 return myMesh_i->GetGroups( *groupIDs );
1473 //=======================================================================
1474 //function : rotationSweep
1476 //=======================================================================
1478 SMESH::ListOfGroups*
1479 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1480 const SMESH::AxisStruct & theAxis,
1481 CORBA::Double theAngleInRadians,
1482 CORBA::Long theNbOfSteps,
1483 CORBA::Double theTolerance,
1484 const bool theMakeGroups,
1485 const SMDSAbs_ElementType theElementType)
1489 TIDSortedElemSet inElements, copyElements;
1490 arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType);
1492 TIDSortedElemSet* workElements = & inElements;
1493 TPreviewMesh tmpMesh( SMDSAbs_Face );
1494 SMESH_Mesh* mesh = 0;
1495 bool makeWalls=true;
1496 if ( myPreviewMode )
1498 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1499 tmpMesh.Copy( inElements, copyElements, select, avoid );
1501 workElements = & copyElements;
1502 //makeWalls = false;
1509 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1510 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1512 ::SMESH_MeshEditor anEditor( mesh );
1513 ::SMESH_MeshEditor::PGroupIDs groupIds =
1514 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1515 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1516 storeResult(anEditor);
1518 // myMesh->SetIsModified( true ); -- it does not influence Compute()
1520 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1523 //=======================================================================
1524 //function : RotationSweep
1526 //=======================================================================
1528 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1529 const SMESH::AxisStruct & theAxis,
1530 CORBA::Double theAngleInRadians,
1531 CORBA::Long theNbOfSteps,
1532 CORBA::Double theTolerance)
1534 if ( !myPreviewMode ) {
1535 TPythonDump() << this << ".RotationSweep( "
1536 << theIDsOfElements << ", "
1538 << theAngleInRadians << ", "
1539 << theNbOfSteps << ", "
1540 << theTolerance << " )";
1542 rotationSweep(theIDsOfElements,
1550 //=======================================================================
1551 //function : RotationSweepMakeGroups
1553 //=======================================================================
1555 SMESH::ListOfGroups*
1556 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1557 const SMESH::AxisStruct& theAxis,
1558 CORBA::Double theAngleInRadians,
1559 CORBA::Long theNbOfSteps,
1560 CORBA::Double theTolerance)
1562 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1568 if ( !myPreviewMode ) {
1569 TPythonDump aPythonDump;
1570 DumpGroupsList(aPythonDump,aGroups);
1571 aPythonDump<< this << ".RotationSweepMakeGroups( "
1572 << theIDsOfElements << ", "
1574 << theAngleInRadians << ", "
1575 << theNbOfSteps << ", "
1576 << theTolerance << " )";
1581 //=======================================================================
1582 //function : RotationSweepObject
1584 //=======================================================================
1586 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1587 const SMESH::AxisStruct & theAxis,
1588 CORBA::Double theAngleInRadians,
1589 CORBA::Long theNbOfSteps,
1590 CORBA::Double theTolerance)
1592 if ( !myPreviewMode ) {
1593 TPythonDump() << this << ".RotationSweepObject( "
1594 << theObject << ", "
1596 << theAngleInRadians << ", "
1597 << theNbOfSteps << ", "
1598 << theTolerance << " )";
1600 SMESH::long_array_var anElementsId = theObject->GetIDs();
1601 rotationSweep(anElementsId,
1609 //=======================================================================
1610 //function : RotationSweepObject1D
1612 //=======================================================================
1614 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1615 const SMESH::AxisStruct & theAxis,
1616 CORBA::Double theAngleInRadians,
1617 CORBA::Long theNbOfSteps,
1618 CORBA::Double theTolerance)
1620 if ( !myPreviewMode ) {
1621 TPythonDump() << this << ".RotationSweepObject1D( "
1622 << theObject << ", "
1624 << theAngleInRadians << ", "
1625 << theNbOfSteps << ", "
1626 << theTolerance << " )";
1628 SMESH::long_array_var anElementsId = theObject->GetIDs();
1629 rotationSweep(anElementsId,
1638 //=======================================================================
1639 //function : RotationSweepObject2D
1641 //=======================================================================
1643 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1644 const SMESH::AxisStruct & theAxis,
1645 CORBA::Double theAngleInRadians,
1646 CORBA::Long theNbOfSteps,
1647 CORBA::Double theTolerance)
1649 if ( !myPreviewMode ) {
1650 TPythonDump() << this << ".RotationSweepObject2D( "
1651 << theObject << ", "
1653 << theAngleInRadians << ", "
1654 << theNbOfSteps << ", "
1655 << theTolerance << " )";
1657 SMESH::long_array_var anElementsId = theObject->GetIDs();
1658 rotationSweep(anElementsId,
1667 //=======================================================================
1668 //function : RotationSweepObjectMakeGroups
1670 //=======================================================================
1672 SMESH::ListOfGroups*
1673 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1674 const SMESH::AxisStruct& theAxis,
1675 CORBA::Double theAngleInRadians,
1676 CORBA::Long theNbOfSteps,
1677 CORBA::Double theTolerance)
1679 SMESH::long_array_var anElementsId = theObject->GetIDs();
1680 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1686 if ( !myPreviewMode ) {
1687 TPythonDump aPythonDump;
1688 DumpGroupsList(aPythonDump,aGroups);
1689 aPythonDump<< this << ".RotationSweepObjectMakeGroups( "
1690 << theObject << ", "
1692 << theAngleInRadians << ", "
1693 << theNbOfSteps << ", "
1694 << theTolerance << " )";
1699 //=======================================================================
1700 //function : RotationSweepObject1DMakeGroups
1702 //=======================================================================
1704 SMESH::ListOfGroups*
1705 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1706 const SMESH::AxisStruct& theAxis,
1707 CORBA::Double theAngleInRadians,
1708 CORBA::Long theNbOfSteps,
1709 CORBA::Double theTolerance)
1711 SMESH::long_array_var anElementsId = theObject->GetIDs();
1712 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1719 if ( !myPreviewMode ) {
1720 TPythonDump aPythonDump;
1721 DumpGroupsList(aPythonDump,aGroups);
1722 aPythonDump<< this << ".RotationSweepObject1DMakeGroups( "
1723 << theObject << ", "
1725 << theAngleInRadians << ", "
1726 << theNbOfSteps << ", "
1727 << theTolerance << " )";
1732 //=======================================================================
1733 //function : RotationSweepObject2DMakeGroups
1735 //=======================================================================
1737 SMESH::ListOfGroups*
1738 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1739 const SMESH::AxisStruct& theAxis,
1740 CORBA::Double theAngleInRadians,
1741 CORBA::Long theNbOfSteps,
1742 CORBA::Double theTolerance)
1744 SMESH::long_array_var anElementsId = theObject->GetIDs();
1745 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1752 if ( !myPreviewMode ) {
1753 TPythonDump aPythonDump;
1754 DumpGroupsList(aPythonDump,aGroups);
1755 aPythonDump<< this << ".RotationSweepObject2DMakeGroups( "
1756 << theObject << ", "
1758 << theAngleInRadians << ", "
1759 << theNbOfSteps << ", "
1760 << theTolerance << " )";
1766 //=======================================================================
1767 //function : extrusionSweep
1769 //=======================================================================
1771 SMESH::ListOfGroups*
1772 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1773 const SMESH::DirStruct & theStepVector,
1774 CORBA::Long theNbOfSteps,
1775 const bool theMakeGroups,
1776 const SMDSAbs_ElementType theElementType)
1784 TIDSortedElemSet elements;
1785 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1787 const SMESH::PointStruct * P = &theStepVector.PS;
1788 gp_Vec stepVec( P->x, P->y, P->z );
1790 TElemOfElemListMap aHystory;
1791 ::SMESH_MeshEditor anEditor( myMesh );
1792 ::SMESH_MeshEditor::PGroupIDs groupIds =
1793 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1795 storeResult(anEditor);
1797 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1799 } catch(Standard_Failure) {
1800 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1801 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1806 //=======================================================================
1807 //function : ExtrusionSweep
1809 //=======================================================================
1811 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1812 const SMESH::DirStruct & theStepVector,
1813 CORBA::Long theNbOfSteps)
1815 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1816 if ( !myPreviewMode ) {
1817 TPythonDump() << this << ".ExtrusionSweep( "
1818 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1823 //=======================================================================
1824 //function : ExtrusionSweepObject
1826 //=======================================================================
1828 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1829 const SMESH::DirStruct & theStepVector,
1830 CORBA::Long theNbOfSteps)
1832 SMESH::long_array_var anElementsId = theObject->GetIDs();
1833 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1834 if ( !myPreviewMode ) {
1835 TPythonDump() << this << ".ExtrusionSweepObject( "
1836 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1840 //=======================================================================
1841 //function : ExtrusionSweepObject1D
1843 //=======================================================================
1845 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1846 const SMESH::DirStruct & theStepVector,
1847 CORBA::Long theNbOfSteps)
1849 SMESH::long_array_var anElementsId = theObject->GetIDs();
1850 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1851 if ( !myPreviewMode ) {
1852 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1853 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1857 //=======================================================================
1858 //function : ExtrusionSweepObject2D
1860 //=======================================================================
1862 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1863 const SMESH::DirStruct & theStepVector,
1864 CORBA::Long theNbOfSteps)
1866 SMESH::long_array_var anElementsId = theObject->GetIDs();
1867 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1868 if ( !myPreviewMode ) {
1869 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1870 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1874 //=======================================================================
1875 //function : ExtrusionSweepMakeGroups
1877 //=======================================================================
1879 SMESH::ListOfGroups*
1880 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1881 const SMESH::DirStruct& theStepVector,
1882 CORBA::Long theNbOfSteps)
1884 SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1886 if ( !myPreviewMode ) {
1887 TPythonDump aPythonDump;
1888 DumpGroupsList(aPythonDump,aGroups);
1889 aPythonDump << this << ".ExtrusionSweepMakeGroups( "
1890 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1894 //=======================================================================
1895 //function : ExtrusionSweepObjectMakeGroups
1897 //=======================================================================
1899 SMESH::ListOfGroups*
1900 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1901 const SMESH::DirStruct& theStepVector,
1902 CORBA::Long theNbOfSteps)
1904 SMESH::long_array_var anElementsId = theObject->GetIDs();
1905 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1907 if ( !myPreviewMode ) {
1908 TPythonDump aPythonDump;
1909 DumpGroupsList(aPythonDump,aGroups);
1910 aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( "
1911 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1916 //=======================================================================
1917 //function : ExtrusionSweepObject1DMakeGroups
1919 //=======================================================================
1921 SMESH::ListOfGroups*
1922 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1923 const SMESH::DirStruct& theStepVector,
1924 CORBA::Long theNbOfSteps)
1926 SMESH::long_array_var anElementsId = theObject->GetIDs();
1927 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1928 if ( !myPreviewMode ) {
1929 TPythonDump aPythonDump;
1930 DumpGroupsList(aPythonDump,aGroups);
1931 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( "
1932 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1937 //=======================================================================
1938 //function : ExtrusionSweepObject2DMakeGroups
1940 //=======================================================================
1942 SMESH::ListOfGroups*
1943 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1944 const SMESH::DirStruct& theStepVector,
1945 CORBA::Long theNbOfSteps)
1947 SMESH::long_array_var anElementsId = theObject->GetIDs();
1948 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1949 if ( !myPreviewMode ) {
1950 TPythonDump aPythonDump;
1951 DumpGroupsList(aPythonDump,aGroups);
1952 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( "
1953 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1959 //=======================================================================
1960 //function : advancedExtrusion
1962 //=======================================================================
1964 SMESH::ListOfGroups*
1965 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1966 const SMESH::DirStruct & theStepVector,
1967 CORBA::Long theNbOfSteps,
1968 CORBA::Long theExtrFlags,
1969 CORBA::Double theSewTolerance,
1970 const bool theMakeGroups)
1974 TIDSortedElemSet elements;
1975 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1977 const SMESH::PointStruct * P = &theStepVector.PS;
1978 gp_Vec stepVec( P->x, P->y, P->z );
1980 ::SMESH_MeshEditor anEditor( myMesh );
1981 TElemOfElemListMap aHystory;
1982 ::SMESH_MeshEditor::PGroupIDs groupIds =
1983 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1984 theMakeGroups, theExtrFlags, theSewTolerance);
1985 storeResult(anEditor);
1987 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1990 //=======================================================================
1991 //function : AdvancedExtrusion
1993 //=======================================================================
1995 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1996 const SMESH::DirStruct & theStepVector,
1997 CORBA::Long theNbOfSteps,
1998 CORBA::Long theExtrFlags,
1999 CORBA::Double theSewTolerance)
2001 if ( !myPreviewMode ) {
2002 TPythonDump() << "stepVector = " << theStepVector;
2003 TPythonDump() << this << ".AdvancedExtrusion("
2006 << theNbOfSteps << ","
2007 << theExtrFlags << ", "
2008 << theSewTolerance << " )";
2010 advancedExtrusion( theIDsOfElements,
2018 //=======================================================================
2019 //function : AdvancedExtrusionMakeGroups
2021 //=======================================================================
2023 SMESH::ListOfGroups*
2024 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
2025 const SMESH::DirStruct& theStepVector,
2026 CORBA::Long theNbOfSteps,
2027 CORBA::Long theExtrFlags,
2028 CORBA::Double theSewTolerance)
2030 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
2037 if ( !myPreviewMode ) {
2038 TPythonDump() << "stepVector = " << theStepVector;
2039 TPythonDump aPythonDump;
2040 DumpGroupsList(aPythonDump,aGroups);
2041 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
2044 << theNbOfSteps << ","
2045 << theExtrFlags << ", "
2046 << theSewTolerance << " )";
2052 //================================================================================
2054 * \brief Convert extrusion error to IDL enum
2056 //================================================================================
2058 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2060 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
2064 RETCASE( EXTR_NO_ELEMENTS );
2065 RETCASE( EXTR_PATH_NOT_EDGE );
2066 RETCASE( EXTR_BAD_PATH_SHAPE );
2067 RETCASE( EXTR_BAD_STARTING_NODE );
2068 RETCASE( EXTR_BAD_ANGLES_NUMBER );
2069 RETCASE( EXTR_CANT_GET_TANGENT );
2071 return SMESH::SMESH_MeshEditor::EXTR_OK;
2075 //=======================================================================
2076 //function : extrusionAlongPath
2078 //=======================================================================
2080 SMESH::ListOfGroups*
2081 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2082 SMESH::SMESH_Mesh_ptr thePathMesh,
2083 GEOM::GEOM_Object_ptr thePathShape,
2084 CORBA::Long theNodeStart,
2085 CORBA::Boolean theHasAngles,
2086 const SMESH::double_array & theAngles,
2087 CORBA::Boolean theHasRefPoint,
2088 const SMESH::PointStruct & theRefPoint,
2089 const bool theMakeGroups,
2090 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
2091 const SMDSAbs_ElementType theElementType)
2095 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
2096 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2099 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2101 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2102 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2104 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
2105 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2109 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
2111 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2115 TIDSortedElemSet elements;
2116 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
2118 list<double> angles;
2119 for (int i = 0; i < theAngles.length(); i++) {
2120 angles.push_back( theAngles[i] );
2123 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
2125 int nbOldGroups = myMesh->NbGroup();
2127 ::SMESH_MeshEditor anEditor( myMesh );
2128 ::SMESH_MeshEditor::Extrusion_Error error =
2129 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
2130 theHasAngles, angles, false,
2131 theHasRefPoint, refPnt, theMakeGroups );
2132 storeResult(anEditor);
2133 theError = convExtrError( error );
2135 if ( theMakeGroups ) {
2136 list<int> groupIDs = myMesh->GetGroupIds();
2137 list<int>::iterator newBegin = groupIDs.begin();
2138 std::advance( newBegin, nbOldGroups ); // skip old groups
2139 groupIDs.erase( groupIDs.begin(), newBegin );
2140 return getGroups( & groupIDs );
2146 //=======================================================================
2147 //function : extrusionAlongPathX
2149 //=======================================================================
2151 SMESH::ListOfGroups*
2152 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2153 SMESH::SMESH_IDSource_ptr Path,
2154 CORBA::Long NodeStart,
2155 CORBA::Boolean HasAngles,
2156 const SMESH::double_array& Angles,
2157 CORBA::Boolean LinearVariation,
2158 CORBA::Boolean HasRefPoint,
2159 const SMESH::PointStruct& RefPoint,
2160 const bool MakeGroups,
2161 const SMDSAbs_ElementType ElementType,
2162 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2164 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2168 list<double> angles;
2169 for (int i = 0; i < Angles.length(); i++) {
2170 angles.push_back( Angles[i] );
2172 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2173 int nbOldGroups = myMesh->NbGroup();
2175 if ( Path->_is_nil() ) {
2176 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2180 TIDSortedElemSet elements;
2181 arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
2183 ::SMESH_MeshEditor anEditor( myMesh );
2184 ::SMESH_MeshEditor::Extrusion_Error error;
2186 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
2189 SMDS_MeshNode* aNodeStart =
2190 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2191 if ( !aNodeStart ) {
2192 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2195 error = anEditor.ExtrusionAlongTrack( elements, &(aMeshImp->GetImpl()), aNodeStart,
2196 HasAngles, angles, LinearVariation,
2197 HasRefPoint, refPnt, MakeGroups );
2200 SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
2203 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
2204 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
2205 SMDS_MeshNode* aNodeStart =
2206 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2207 if ( !aNodeStart ) {
2208 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2211 SMESH_subMesh* aSubMesh =
2212 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
2213 error = anEditor.ExtrusionAlongTrack( elements, aSubMesh, aNodeStart,
2214 HasAngles, angles, LinearVariation,
2215 HasRefPoint, refPnt, MakeGroups );
2218 SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
2220 // path as group of 1D elements
2224 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2230 storeResult(anEditor);
2231 Error = convExtrError( error );
2234 list<int> groupIDs = myMesh->GetGroupIds();
2235 list<int>::iterator newBegin = groupIDs.begin();
2236 std::advance( newBegin, nbOldGroups ); // skip old groups
2237 groupIDs.erase( groupIDs.begin(), newBegin );
2238 return getGroups( & groupIDs );
2244 //=======================================================================
2245 //function : ExtrusionAlongPath
2247 //=======================================================================
2249 SMESH::SMESH_MeshEditor::Extrusion_Error
2250 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2251 SMESH::SMESH_Mesh_ptr thePathMesh,
2252 GEOM::GEOM_Object_ptr thePathShape,
2253 CORBA::Long theNodeStart,
2254 CORBA::Boolean theHasAngles,
2255 const SMESH::double_array & theAngles,
2256 CORBA::Boolean theHasRefPoint,
2257 const SMESH::PointStruct & theRefPoint)
2259 if ( !myPreviewMode ) {
2260 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
2261 << theIDsOfElements << ", "
2262 << thePathMesh << ", "
2263 << thePathShape << ", "
2264 << theNodeStart << ", "
2265 << theHasAngles << ", "
2266 << theAngles << ", "
2267 << theHasRefPoint << ", "
2268 << "SMESH.PointStruct( "
2269 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2270 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2271 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2273 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2274 extrusionAlongPath( theIDsOfElements,
2287 //=======================================================================
2288 //function : ExtrusionAlongPathObject
2290 //=======================================================================
2292 SMESH::SMESH_MeshEditor::Extrusion_Error
2293 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
2294 SMESH::SMESH_Mesh_ptr thePathMesh,
2295 GEOM::GEOM_Object_ptr thePathShape,
2296 CORBA::Long theNodeStart,
2297 CORBA::Boolean theHasAngles,
2298 const SMESH::double_array & theAngles,
2299 CORBA::Boolean theHasRefPoint,
2300 const SMESH::PointStruct & theRefPoint)
2302 if ( !myPreviewMode ) {
2303 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
2304 << theObject << ", "
2305 << thePathMesh << ", "
2306 << thePathShape << ", "
2307 << theNodeStart << ", "
2308 << theHasAngles << ", "
2309 << theAngles << ", "
2310 << theHasRefPoint << ", "
2311 << "SMESH.PointStruct( "
2312 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2313 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2314 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2316 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2317 SMESH::long_array_var anElementsId = theObject->GetIDs();
2318 extrusionAlongPath( anElementsId,
2331 //=======================================================================
2332 //function : ExtrusionAlongPathObject1D
2334 //=======================================================================
2336 SMESH::SMESH_MeshEditor::Extrusion_Error
2337 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
2338 SMESH::SMESH_Mesh_ptr thePathMesh,
2339 GEOM::GEOM_Object_ptr thePathShape,
2340 CORBA::Long theNodeStart,
2341 CORBA::Boolean theHasAngles,
2342 const SMESH::double_array & theAngles,
2343 CORBA::Boolean theHasRefPoint,
2344 const SMESH::PointStruct & theRefPoint)
2346 if ( !myPreviewMode ) {
2347 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
2348 << theObject << ", "
2349 << thePathMesh << ", "
2350 << thePathShape << ", "
2351 << theNodeStart << ", "
2352 << theHasAngles << ", "
2353 << theAngles << ", "
2354 << theHasRefPoint << ", "
2355 << "SMESH.PointStruct( "
2356 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2357 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2358 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2360 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2361 SMESH::long_array_var anElementsId = theObject->GetIDs();
2362 extrusionAlongPath( anElementsId,
2376 //=======================================================================
2377 //function : ExtrusionAlongPathObject2D
2379 //=======================================================================
2381 SMESH::SMESH_MeshEditor::Extrusion_Error
2382 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
2383 SMESH::SMESH_Mesh_ptr thePathMesh,
2384 GEOM::GEOM_Object_ptr thePathShape,
2385 CORBA::Long theNodeStart,
2386 CORBA::Boolean theHasAngles,
2387 const SMESH::double_array & theAngles,
2388 CORBA::Boolean theHasRefPoint,
2389 const SMESH::PointStruct & theRefPoint)
2391 if ( !myPreviewMode ) {
2392 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
2393 << theObject << ", "
2394 << thePathMesh << ", "
2395 << thePathShape << ", "
2396 << theNodeStart << ", "
2397 << theHasAngles << ", "
2398 << theAngles << ", "
2399 << theHasRefPoint << ", "
2400 << "SMESH.PointStruct( "
2401 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2402 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2403 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2405 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2406 SMESH::long_array_var anElementsId = theObject->GetIDs();
2407 extrusionAlongPath( anElementsId,
2422 //=======================================================================
2423 //function : ExtrusionAlongPathMakeGroups
2425 //=======================================================================
2427 SMESH::ListOfGroups*
2428 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2429 SMESH::SMESH_Mesh_ptr thePathMesh,
2430 GEOM::GEOM_Object_ptr thePathShape,
2431 CORBA::Long theNodeStart,
2432 CORBA::Boolean theHasAngles,
2433 const SMESH::double_array& theAngles,
2434 CORBA::Boolean theHasRefPoint,
2435 const SMESH::PointStruct& theRefPoint,
2436 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2438 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2448 if ( !myPreviewMode ) {
2449 bool isDumpGroups = aGroups && aGroups->length() > 0;
2450 TPythonDump aPythonDump;
2452 aPythonDump << "("<<aGroups;
2455 aPythonDump << ", error)";
2457 aPythonDump <<"error";
2459 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2460 << theIDsOfElements << ", "
2461 << thePathMesh << ", "
2462 << thePathShape << ", "
2463 << theNodeStart << ", "
2464 << theHasAngles << ", "
2465 << theAngles << ", "
2466 << theHasRefPoint << ", "
2467 << "SMESH.PointStruct( "
2468 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2469 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2470 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2475 //=======================================================================
2476 //function : ExtrusionAlongPathObjectMakeGroups
2478 //=======================================================================
2480 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2481 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2482 SMESH::SMESH_Mesh_ptr thePathMesh,
2483 GEOM::GEOM_Object_ptr thePathShape,
2484 CORBA::Long theNodeStart,
2485 CORBA::Boolean theHasAngles,
2486 const SMESH::double_array& theAngles,
2487 CORBA::Boolean theHasRefPoint,
2488 const SMESH::PointStruct& theRefPoint,
2489 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2491 SMESH::long_array_var anElementsId = theObject->GetIDs();
2492 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2503 if ( !myPreviewMode ) {
2504 bool isDumpGroups = aGroups && aGroups->length() > 0;
2505 TPythonDump aPythonDump;
2507 aPythonDump << "("<<aGroups;
2510 aPythonDump << ", error)";
2512 aPythonDump <<"error";
2514 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2515 << theObject << ", "
2516 << thePathMesh << ", "
2517 << thePathShape << ", "
2518 << theNodeStart << ", "
2519 << theHasAngles << ", "
2520 << theAngles << ", "
2521 << theHasRefPoint << ", "
2522 << "SMESH.PointStruct( "
2523 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2524 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2525 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2530 //=======================================================================
2531 //function : ExtrusionAlongPathObject1DMakeGroups
2533 //=======================================================================
2535 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2536 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2537 SMESH::SMESH_Mesh_ptr thePathMesh,
2538 GEOM::GEOM_Object_ptr thePathShape,
2539 CORBA::Long theNodeStart,
2540 CORBA::Boolean theHasAngles,
2541 const SMESH::double_array& theAngles,
2542 CORBA::Boolean theHasRefPoint,
2543 const SMESH::PointStruct& theRefPoint,
2544 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2546 SMESH::long_array_var anElementsId = theObject->GetIDs();
2547 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2559 if ( !myPreviewMode ) {
2560 bool isDumpGroups = aGroups && aGroups->length() > 0;
2561 TPythonDump aPythonDump;
2563 aPythonDump << "("<<aGroups;
2566 aPythonDump << ", error)";
2568 aPythonDump <<"error";
2570 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
2571 << theObject << ", "
2572 << thePathMesh << ", "
2573 << thePathShape << ", "
2574 << theNodeStart << ", "
2575 << theHasAngles << ", "
2576 << theAngles << ", "
2577 << theHasRefPoint << ", "
2578 << "SMESH.PointStruct( "
2579 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2580 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2581 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2586 //=======================================================================
2587 //function : ExtrusionAlongPathObject2DMakeGroups
2589 //=======================================================================
2591 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2592 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2593 SMESH::SMESH_Mesh_ptr thePathMesh,
2594 GEOM::GEOM_Object_ptr thePathShape,
2595 CORBA::Long theNodeStart,
2596 CORBA::Boolean theHasAngles,
2597 const SMESH::double_array& theAngles,
2598 CORBA::Boolean theHasRefPoint,
2599 const SMESH::PointStruct& theRefPoint,
2600 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2602 SMESH::long_array_var anElementsId = theObject->GetIDs();
2603 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2615 if ( !myPreviewMode ) {
2616 bool isDumpGroups = aGroups && aGroups->length() > 0;
2617 TPythonDump aPythonDump;
2619 aPythonDump << "("<<aGroups;
2622 aPythonDump << ", error)";
2624 aPythonDump <<"error";
2626 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
2627 << theObject << ", "
2628 << thePathMesh << ", "
2629 << thePathShape << ", "
2630 << theNodeStart << ", "
2631 << theHasAngles << ", "
2632 << theAngles << ", "
2633 << theHasRefPoint << ", "
2634 << "SMESH.PointStruct( "
2635 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2636 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2637 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2643 //=======================================================================
2644 //function : ExtrusionAlongPathObjX
2646 //=======================================================================
2647 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2648 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
2649 SMESH::SMESH_IDSource_ptr Path,
2650 CORBA::Long NodeStart,
2651 CORBA::Boolean HasAngles,
2652 const SMESH::double_array& Angles,
2653 CORBA::Boolean LinearVariation,
2654 CORBA::Boolean HasRefPoint,
2655 const SMESH::PointStruct& RefPoint,
2656 CORBA::Boolean MakeGroups,
2657 SMESH::ElementType ElemType,
2658 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2660 SMESH::long_array_var anElementsId = Object->GetIDs();
2661 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2670 (SMDSAbs_ElementType)ElemType,
2673 if ( !myPreviewMode ) {
2674 bool isDumpGroups = aGroups && aGroups->length() > 0;
2675 TPythonDump aPythonDump;
2677 aPythonDump << "("<<aGroups;
2680 aPythonDump << ", error)";
2682 aPythonDump <<"error";
2684 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2687 << NodeStart << ", "
2688 << HasAngles << ", "
2690 << LinearVariation << ", "
2691 << HasRefPoint << ", "
2692 << "SMESH.PointStruct( "
2693 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2694 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2695 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2696 << MakeGroups << ", "
2697 << ElemType << " )";
2703 //=======================================================================
2704 //function : ExtrusionAlongPathX
2706 //=======================================================================
2707 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2708 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2709 SMESH::SMESH_IDSource_ptr Path,
2710 CORBA::Long NodeStart,
2711 CORBA::Boolean HasAngles,
2712 const SMESH::double_array& Angles,
2713 CORBA::Boolean LinearVariation,
2714 CORBA::Boolean HasRefPoint,
2715 const SMESH::PointStruct& RefPoint,
2716 CORBA::Boolean MakeGroups,
2717 SMESH::ElementType ElemType,
2718 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2720 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2729 (SMDSAbs_ElementType)ElemType,
2732 if ( !myPreviewMode ) {
2733 bool isDumpGroups = aGroups && aGroups->length() > 0;
2734 TPythonDump aPythonDump;
2736 aPythonDump << "("<<aGroups;
2739 aPythonDump << ", error)";
2741 aPythonDump <<"error";
2743 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2744 << IDsOfElements << ", "
2746 << NodeStart << ", "
2747 << HasAngles << ", "
2749 << LinearVariation << ", "
2750 << HasRefPoint << ", "
2751 << "SMESH.PointStruct( "
2752 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2753 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2754 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2755 << ElemType << " )";
2761 //================================================================================
2763 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2764 * of given angles along path steps
2765 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2766 * which proceeds the extrusion
2767 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2768 * is used to define the sub-mesh for the path
2770 //================================================================================
2772 SMESH::double_array*
2773 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2774 GEOM::GEOM_Object_ptr thePathShape,
2775 const SMESH::double_array & theAngles)
2777 SMESH::double_array_var aResult = new SMESH::double_array();
2778 int nbAngles = theAngles.length();
2779 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2781 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2782 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2783 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2784 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2785 return aResult._retn();
2786 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2787 if ( nbSteps == nbAngles )
2789 aResult.inout() = theAngles;
2793 aResult->length( nbSteps );
2794 double rAn2St = double( nbAngles ) / double( nbSteps );
2795 double angPrev = 0, angle;
2796 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2798 double angCur = rAn2St * ( iSt+1 );
2799 double angCurFloor = floor( angCur );
2800 double angPrevFloor = floor( angPrev );
2801 if ( angPrevFloor == angCurFloor )
2802 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2805 int iP = int( angPrevFloor );
2806 double angPrevCeil = ceil(angPrev);
2807 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2809 int iC = int( angCurFloor );
2810 if ( iC < nbAngles )
2811 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2813 iP = int( angPrevCeil );
2815 angle += theAngles[ iC ];
2817 aResult[ iSt ] = angle;
2822 // Update Python script
2823 TPythonDump() << "rotAngles = " << theAngles;
2824 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2825 << thePathMesh << ", "
2826 << thePathShape << ", "
2829 return aResult._retn();
2833 //=======================================================================
2836 //=======================================================================
2838 SMESH::ListOfGroups*
2839 SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements,
2840 const SMESH::AxisStruct & theAxis,
2841 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2842 CORBA::Boolean theCopy,
2843 const bool theMakeGroups,
2844 ::SMESH_Mesh* theTargetMesh)
2848 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2849 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2852 switch ( theMirrorType ) {
2853 case SMESH::SMESH_MeshEditor::POINT:
2854 aTrsf.SetMirror( P );
2856 case SMESH::SMESH_MeshEditor::AXIS:
2857 aTrsf.SetMirror( gp_Ax1( P, V ));
2860 aTrsf.SetMirror( gp_Ax2( P, V ));
2863 ::SMESH_MeshEditor anEditor( myMesh );
2864 ::SMESH_MeshEditor::PGroupIDs groupIds =
2865 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2868 storeResult(anEditor);
2870 myMesh->SetIsModified( true );
2872 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2875 //=======================================================================
2878 //=======================================================================
2880 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2881 const SMESH::AxisStruct & theAxis,
2882 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2883 CORBA::Boolean theCopy)
2885 if ( !myPreviewMode ) {
2886 TPythonDump() << this << ".Mirror( "
2887 << theIDsOfElements << ", "
2889 << mirrorTypeName(theMirrorType) << ", "
2892 if ( theIDsOfElements.length() > 0 )
2894 TIDSortedElemSet elements;
2895 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2896 mirror(elements, theAxis, theMirrorType, theCopy, false);
2901 //=======================================================================
2902 //function : MirrorObject
2904 //=======================================================================
2906 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2907 const SMESH::AxisStruct & theAxis,
2908 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2909 CORBA::Boolean theCopy)
2911 if ( !myPreviewMode ) {
2912 TPythonDump() << this << ".MirrorObject( "
2913 << theObject << ", "
2915 << mirrorTypeName(theMirrorType) << ", "
2918 TIDSortedElemSet elements;
2919 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2920 mirror(elements, theAxis, theMirrorType, theCopy, false);
2923 //=======================================================================
2924 //function : MirrorMakeGroups
2926 //=======================================================================
2928 SMESH::ListOfGroups*
2929 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2930 const SMESH::AxisStruct& theMirror,
2931 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2933 SMESH::ListOfGroups * aGroups = 0;
2934 if ( theIDsOfElements.length() > 0 )
2936 TIDSortedElemSet elements;
2937 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2938 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2940 if ( !myPreviewMode ) {
2941 TPythonDump aPythonDump;
2942 DumpGroupsList(aPythonDump,aGroups);
2943 aPythonDump << this << ".MirrorMakeGroups( "
2944 << theIDsOfElements << ", "
2945 << theMirror << ", "
2946 << mirrorTypeName(theMirrorType) << " )";
2951 //=======================================================================
2952 //function : MirrorObjectMakeGroups
2954 //=======================================================================
2956 SMESH::ListOfGroups*
2957 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2958 const SMESH::AxisStruct& theMirror,
2959 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2961 SMESH::ListOfGroups * aGroups = 0;
2962 TIDSortedElemSet elements;
2963 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2964 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2966 if ( !myPreviewMode )
2968 TPythonDump aPythonDump;
2969 DumpGroupsList(aPythonDump,aGroups);
2970 aPythonDump << this << ".MirrorObjectMakeGroups( "
2971 << theObject << ", "
2972 << theMirror << ", "
2973 << mirrorTypeName(theMirrorType) << " )";
2978 //=======================================================================
2979 //function : MirrorMakeMesh
2981 //=======================================================================
2983 SMESH::SMESH_Mesh_ptr
2984 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2985 const SMESH::AxisStruct& theMirror,
2986 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2987 CORBA::Boolean theCopyGroups,
2988 const char* theMeshName)
2990 SMESH_Mesh_i* mesh_i;
2991 SMESH::SMESH_Mesh_var mesh;
2992 { // open new scope to dump "MakeMesh" command
2993 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2995 TPythonDump pydump; // to prevent dump at mesh creation
2997 mesh = makeMesh( theMeshName );
2998 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2999 if (mesh_i && theIDsOfElements.length() > 0 )
3001 TIDSortedElemSet elements;
3002 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3003 mirror(elements, theMirror, theMirrorType,
3004 false, theCopyGroups, & mesh_i->GetImpl());
3005 mesh_i->CreateGroupServants();
3008 if ( !myPreviewMode ) {
3009 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
3010 << theIDsOfElements << ", "
3011 << theMirror << ", "
3012 << mirrorTypeName(theMirrorType) << ", "
3013 << theCopyGroups << ", '"
3014 << theMeshName << "' )";
3019 if(!myPreviewMode && mesh_i)
3020 mesh_i->GetGroups();
3022 return mesh._retn();
3025 //=======================================================================
3026 //function : MirrorObjectMakeMesh
3028 //=======================================================================
3030 SMESH::SMESH_Mesh_ptr
3031 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3032 const SMESH::AxisStruct& theMirror,
3033 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3034 CORBA::Boolean theCopyGroups,
3035 const char* theMeshName)
3037 SMESH_Mesh_i* mesh_i;
3038 SMESH::SMESH_Mesh_var mesh;
3039 { // open new scope to dump "MakeMesh" command
3040 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3042 TPythonDump pydump; // to prevent dump at mesh creation
3044 mesh = makeMesh( theMeshName );
3045 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3046 TIDSortedElemSet elements;
3048 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3050 mirror(elements, theMirror, theMirrorType,
3051 false, theCopyGroups, & mesh_i->GetImpl());
3052 mesh_i->CreateGroupServants();
3054 if ( !myPreviewMode ) {
3055 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
3056 << theObject << ", "
3057 << theMirror << ", "
3058 << mirrorTypeName(theMirrorType) << ", "
3059 << theCopyGroups << ", '"
3060 << theMeshName << "' )";
3065 if(!myPreviewMode && mesh_i)
3066 mesh_i->GetGroups();
3068 return mesh._retn();
3071 //=======================================================================
3072 //function : translate
3074 //=======================================================================
3076 SMESH::ListOfGroups*
3077 SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements,
3078 const SMESH::DirStruct & theVector,
3079 CORBA::Boolean theCopy,
3080 const bool theMakeGroups,
3081 ::SMESH_Mesh* theTargetMesh)
3086 const SMESH::PointStruct * P = &theVector.PS;
3087 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
3089 ::SMESH_MeshEditor anEditor( myMesh );
3090 ::SMESH_MeshEditor::PGroupIDs groupIds =
3091 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3094 storeResult(anEditor);
3096 myMesh->SetIsModified( true );
3098 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3101 //=======================================================================
3102 //function : Translate
3104 //=======================================================================
3106 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
3107 const SMESH::DirStruct & theVector,
3108 CORBA::Boolean theCopy)
3110 if ( !myPreviewMode ) {
3111 TPythonDump() << this << ".Translate( "
3112 << theIDsOfElements << ", "
3113 << theVector << ", "
3116 if ( theIDsOfElements.length() )
3118 TIDSortedElemSet elements;
3119 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3120 translate(elements,theVector,theCopy,false);
3124 //=======================================================================
3125 //function : TranslateObject
3127 //=======================================================================
3129 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
3130 const SMESH::DirStruct & theVector,
3131 CORBA::Boolean theCopy)
3133 if ( !myPreviewMode ) {
3134 TPythonDump() << this << ".TranslateObject( "
3135 << theObject << ", "
3136 << theVector << ", "
3139 TIDSortedElemSet elements;
3140 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3141 translate( elements, theVector, theCopy, false);
3144 //=======================================================================
3145 //function : TranslateMakeGroups
3147 //=======================================================================
3149 SMESH::ListOfGroups*
3150 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
3151 const SMESH::DirStruct& theVector)
3153 SMESH::ListOfGroups * aGroups = 0;
3154 if ( theIDsOfElements.length() )
3156 TIDSortedElemSet elements;
3157 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3158 aGroups = translate(elements,theVector,true,true);
3160 if ( !myPreviewMode ) {
3161 TPythonDump aPythonDump;
3162 DumpGroupsList(aPythonDump,aGroups);
3163 aPythonDump << this << ".TranslateMakeGroups( "
3164 << theIDsOfElements << ", "
3165 << theVector << " )";
3170 //=======================================================================
3171 //function : TranslateObjectMakeGroups
3173 //=======================================================================
3175 SMESH::ListOfGroups*
3176 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3177 const SMESH::DirStruct& theVector)
3179 SMESH::ListOfGroups * aGroups = 0;
3180 TIDSortedElemSet elements;
3181 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3182 aGroups = translate(elements, theVector, true, true);
3184 if ( !myPreviewMode ) {
3186 TPythonDump aPythonDump;
3187 DumpGroupsList(aPythonDump,aGroups);
3188 aPythonDump << this << ".TranslateObjectMakeGroups( "
3189 << theObject << ", "
3190 << theVector << " )";
3195 //=======================================================================
3196 //function : TranslateMakeMesh
3198 //=======================================================================
3200 SMESH::SMESH_Mesh_ptr
3201 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3202 const SMESH::DirStruct& theVector,
3203 CORBA::Boolean theCopyGroups,
3204 const char* theMeshName)
3206 SMESH_Mesh_i* mesh_i;
3207 SMESH::SMESH_Mesh_var mesh;
3209 { // open new scope to dump "MakeMesh" command
3210 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3212 TPythonDump pydump; // to prevent dump at mesh creation
3214 mesh = makeMesh( theMeshName );
3215 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3217 if ( mesh_i && theIDsOfElements.length() )
3219 TIDSortedElemSet elements;
3220 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3221 translate(elements, theVector, false, theCopyGroups, & mesh_i->GetImpl());
3222 mesh_i->CreateGroupServants();
3225 if ( !myPreviewMode ) {
3226 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3227 << theIDsOfElements << ", "
3228 << theVector << ", "
3229 << theCopyGroups << ", '"
3230 << theMeshName << "' )";
3235 if(!myPreviewMode && mesh_i)
3236 mesh_i->GetGroups();
3238 return mesh._retn();
3241 //=======================================================================
3242 //function : TranslateObjectMakeMesh
3244 //=======================================================================
3246 SMESH::SMESH_Mesh_ptr
3247 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3248 const SMESH::DirStruct& theVector,
3249 CORBA::Boolean theCopyGroups,
3250 const char* theMeshName)
3252 SMESH_Mesh_i* mesh_i;
3253 SMESH::SMESH_Mesh_var mesh;
3254 { // open new scope to dump "MakeMesh" command
3255 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3257 TPythonDump pydump; // to prevent dump at mesh creation
3258 mesh = makeMesh( theMeshName );
3259 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3261 TIDSortedElemSet elements;
3263 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3265 translate(elements, theVector,false, theCopyGroups, & mesh_i->GetImpl());
3266 mesh_i->CreateGroupServants();
3268 if ( !myPreviewMode ) {
3269 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3270 << theObject << ", "
3271 << theVector << ", "
3272 << theCopyGroups << ", '"
3273 << theMeshName << "' )";
3278 if(!myPreviewMode && mesh_i)
3279 mesh_i->GetGroups();
3281 return mesh._retn();
3284 //=======================================================================
3287 //=======================================================================
3289 SMESH::ListOfGroups*
3290 SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements,
3291 const SMESH::AxisStruct & theAxis,
3292 CORBA::Double theAngle,
3293 CORBA::Boolean theCopy,
3294 const bool theMakeGroups,
3295 ::SMESH_Mesh* theTargetMesh)
3299 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3300 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3303 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3305 ::SMESH_MeshEditor anEditor( myMesh );
3306 ::SMESH_MeshEditor::PGroupIDs groupIds =
3307 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3310 storeResult(anEditor);
3312 myMesh->SetIsModified( true );
3314 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3317 //=======================================================================
3320 //=======================================================================
3322 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3323 const SMESH::AxisStruct & theAxis,
3324 CORBA::Double theAngle,
3325 CORBA::Boolean theCopy)
3327 if ( !myPreviewMode ) {
3328 TPythonDump() << this << ".Rotate( "
3329 << theIDsOfElements << ", "
3334 if ( theIDsOfElements.length() > 0 )
3336 TIDSortedElemSet elements;
3337 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3338 rotate(elements,theAxis,theAngle,theCopy,false);
3342 //=======================================================================
3343 //function : RotateObject
3345 //=======================================================================
3347 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3348 const SMESH::AxisStruct & theAxis,
3349 CORBA::Double theAngle,
3350 CORBA::Boolean theCopy)
3352 if ( !myPreviewMode ) {
3353 TPythonDump() << this << ".RotateObject( "
3354 << theObject << ", "
3359 TIDSortedElemSet elements;
3360 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3361 rotate(elements,theAxis,theAngle,theCopy,false);
3364 //=======================================================================
3365 //function : RotateMakeGroups
3367 //=======================================================================
3369 SMESH::ListOfGroups*
3370 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3371 const SMESH::AxisStruct& theAxis,
3372 CORBA::Double theAngle)
3374 SMESH::ListOfGroups * aGroups = 0;
3375 if ( theIDsOfElements.length() > 0 )
3377 TIDSortedElemSet elements;
3378 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3379 aGroups = rotate(elements,theAxis,theAngle,true,true);
3381 if ( !myPreviewMode ) {
3382 TPythonDump aPythonDump;
3383 DumpGroupsList(aPythonDump,aGroups);
3384 aPythonDump << this << ".RotateMakeGroups( "
3385 << theIDsOfElements << ", "
3387 << theAngle << " )";
3392 //=======================================================================
3393 //function : RotateObjectMakeGroups
3395 //=======================================================================
3397 SMESH::ListOfGroups*
3398 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3399 const SMESH::AxisStruct& theAxis,
3400 CORBA::Double theAngle)
3402 SMESH::ListOfGroups * aGroups = 0;
3403 TIDSortedElemSet elements;
3404 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3405 aGroups = rotate(elements,theAxis,theAngle,true,true);
3407 if ( !myPreviewMode ) {
3408 TPythonDump aPythonDump;
3409 DumpGroupsList(aPythonDump,aGroups);
3410 aPythonDump << this << ".RotateObjectMakeGroups( "
3411 << theObject << ", "
3413 << theAngle << " )";
3418 //=======================================================================
3419 //function : RotateMakeMesh
3421 //=======================================================================
3423 SMESH::SMESH_Mesh_ptr
3424 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3425 const SMESH::AxisStruct& theAxis,
3426 CORBA::Double theAngleInRadians,
3427 CORBA::Boolean theCopyGroups,
3428 const char* theMeshName)
3430 SMESH::SMESH_Mesh_var mesh;
3431 SMESH_Mesh_i* mesh_i;
3433 { // open new scope to dump "MakeMesh" command
3434 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3436 TPythonDump pydump; // to prevent dump at mesh creation
3438 mesh = makeMesh( theMeshName );
3439 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3441 if ( mesh_i && theIDsOfElements.length() > 0 )
3443 TIDSortedElemSet elements;
3444 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3445 rotate(elements, theAxis, theAngleInRadians,
3446 false, theCopyGroups, & mesh_i->GetImpl());
3447 mesh_i->CreateGroupServants();
3449 if ( !myPreviewMode ) {
3450 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3451 << theIDsOfElements << ", "
3453 << theAngleInRadians << ", "
3454 << theCopyGroups << ", '"
3455 << theMeshName << "' )";
3460 if(!myPreviewMode && mesh_i && theIDsOfElements.length() > 0 )
3461 mesh_i->GetGroups();
3463 return mesh._retn();
3466 //=======================================================================
3467 //function : RotateObjectMakeMesh
3469 //=======================================================================
3471 SMESH::SMESH_Mesh_ptr
3472 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3473 const SMESH::AxisStruct& theAxis,
3474 CORBA::Double theAngleInRadians,
3475 CORBA::Boolean theCopyGroups,
3476 const char* theMeshName)
3478 SMESH::SMESH_Mesh_var mesh;
3479 SMESH_Mesh_i* mesh_i;
3481 {// open new scope to dump "MakeMesh" command
3482 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3484 TPythonDump pydump; // to prevent dump at mesh creation
3485 mesh = makeMesh( theMeshName );
3486 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3488 TIDSortedElemSet elements;
3490 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3492 rotate(elements, theAxis, theAngleInRadians,
3493 false, theCopyGroups, & mesh_i->GetImpl());
3494 mesh_i->CreateGroupServants();
3496 if ( !myPreviewMode ) {
3497 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3498 << theObject << ", "
3500 << theAngleInRadians << ", "
3501 << theCopyGroups << ", '"
3502 << theMeshName << "' )";
3507 if(!myPreviewMode && mesh_i)
3508 mesh_i->GetGroups();
3510 return mesh._retn();
3513 //=======================================================================
3516 //=======================================================================
3518 SMESH::ListOfGroups*
3519 SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject,
3520 const SMESH::PointStruct& thePoint,
3521 const SMESH::double_array& theScaleFact,
3522 CORBA::Boolean theCopy,
3523 const bool theMakeGroups,
3524 ::SMESH_Mesh* theTargetMesh)
3527 if ( theScaleFact.length() < 1 )
3528 THROW_SALOME_CORBA_EXCEPTION("Scale factor not given", SALOME::BAD_PARAM);
3529 if ( theScaleFact.length() == 2 )
3530 THROW_SALOME_CORBA_EXCEPTION("Invalid nb of scale factors : 2", SALOME::BAD_PARAM);
3532 TIDSortedElemSet elements;
3533 if ( !idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/true))
3536 vector<double> S(3);
3537 S[0] = theScaleFact[0];
3538 S[1] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1];
3539 S[2] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2];
3540 double tol = std::numeric_limits<double>::max();
3542 aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]),
3543 0, S[1], 0, thePoint.y * (1-S[1]),
3544 0, 0, S[2], thePoint.z * (1-S[2]), tol, tol);
3546 ::SMESH_MeshEditor anEditor( myMesh );
3547 ::SMESH_MeshEditor::PGroupIDs groupIds =
3548 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3551 storeResult(anEditor);
3553 myMesh->SetIsModified( true );
3555 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3558 //=======================================================================
3561 //=======================================================================
3563 void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr theObject,
3564 const SMESH::PointStruct& thePoint,
3565 const SMESH::double_array& theScaleFact,
3566 CORBA::Boolean theCopy)
3568 if ( !myPreviewMode ) {
3569 TPythonDump() << this << ".Scale( "
3570 << theObject << ", "
3571 << "SMESH.PointStruct( " << thePoint.x << ", "
3572 << thePoint.y << ", " << thePoint.z << " ) ,"
3573 << theScaleFact << ", "
3576 scale(theObject, thePoint, theScaleFact, theCopy, false);
3580 //=======================================================================
3581 //function : ScaleMakeGroups
3583 //=======================================================================
3585 SMESH::ListOfGroups*
3586 SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3587 const SMESH::PointStruct& thePoint,
3588 const SMESH::double_array& theScaleFact)
3590 SMESH::ListOfGroups * aGroups = scale(theObject, thePoint, theScaleFact, true, true);
3591 if ( !myPreviewMode ) {
3593 TPythonDump aPythonDump;
3594 DumpGroupsList(aPythonDump,aGroups);
3595 aPythonDump << this << ".Scale("
3597 << "SMESH.PointStruct(" <<thePoint.x << ","
3598 << thePoint.y << "," << thePoint.z << "),"
3599 << theScaleFact << ",True,True)";
3605 //=======================================================================
3606 //function : ScaleMakeMesh
3608 //=======================================================================
3610 SMESH::SMESH_Mesh_ptr
3611 SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3612 const SMESH::PointStruct& thePoint,
3613 const SMESH::double_array& theScaleFact,
3614 CORBA::Boolean theCopyGroups,
3615 const char* theMeshName)
3617 SMESH_Mesh_i* mesh_i;
3618 SMESH::SMESH_Mesh_var mesh;
3619 { // open new scope to dump "MakeMesh" command
3620 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3622 TPythonDump pydump; // to prevent dump at mesh creation
3623 mesh = makeMesh( theMeshName );
3624 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3628 scale(theObject, thePoint, theScaleFact,false, theCopyGroups, & mesh_i->GetImpl());
3629 mesh_i->CreateGroupServants();
3631 if ( !myPreviewMode )
3632 pydump << mesh << " = " << this << ".ScaleMakeMesh( "
3633 << theObject << ", "
3634 << "SMESH.PointStruct( " << thePoint.x << ", "
3635 << thePoint.y << ", " << thePoint.z << " ) ,"
3636 << theScaleFact << ", "
3637 << theCopyGroups << ", '"
3638 << theMeshName << "' )";
3642 if(!myPreviewMode && mesh_i)
3643 mesh_i->GetGroups();
3645 return mesh._retn();
3649 //=======================================================================
3650 //function : FindCoincidentNodes
3652 //=======================================================================
3654 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3655 SMESH::array_of_long_array_out GroupsOfNodes)
3659 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3660 ::SMESH_MeshEditor anEditor( myMesh );
3661 TIDSortedNodeSet nodes; // no input nodes
3662 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3664 GroupsOfNodes = new SMESH::array_of_long_array;
3665 GroupsOfNodes->length( aListOfListOfNodes.size() );
3666 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3667 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3668 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3669 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3670 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3671 aGroup.length( aListOfNodes.size() );
3672 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3673 aGroup[ j ] = (*lIt)->GetID();
3675 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3676 << Tolerance << " )";
3679 //=======================================================================
3680 //function : FindCoincidentNodesOnPart
3682 //=======================================================================
3683 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3684 CORBA::Double Tolerance,
3685 SMESH::array_of_long_array_out GroupsOfNodes)
3689 TIDSortedNodeSet nodes;
3690 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3692 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3693 ::SMESH_MeshEditor anEditor( myMesh );
3695 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3697 GroupsOfNodes = new SMESH::array_of_long_array;
3698 GroupsOfNodes->length( aListOfListOfNodes.size() );
3699 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3700 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3702 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3703 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3704 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3705 aGroup.length( aListOfNodes.size() );
3706 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3707 aGroup[ j ] = (*lIt)->GetID();
3709 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3711 << Tolerance << " )";
3714 //================================================================================
3716 * \brief Finds nodes coinsident with Tolerance within Object excluding nodes within
3717 * ExceptSubMeshOrGroups
3719 //================================================================================
3721 void SMESH_MeshEditor_i::
3722 FindCoincidentNodesOnPartBut(SMESH::SMESH_IDSource_ptr theObject,
3723 CORBA::Double theTolerance,
3724 SMESH::array_of_long_array_out theGroupsOfNodes,
3725 const SMESH::ListOfIDSources& theExceptSubMeshOrGroups)
3729 TIDSortedNodeSet nodes;
3730 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3732 for ( int i = 0; i < theExceptSubMeshOrGroups.length(); ++i )
3734 TIDSortedNodeSet exceptNodes;
3735 idSourceToNodeSet( theExceptSubMeshOrGroups[i], GetMeshDS(), exceptNodes );
3736 TIDSortedNodeSet::iterator avoidNode = exceptNodes.begin();
3737 for ( ; avoidNode != exceptNodes.end(); ++avoidNode)
3738 nodes.erase( *avoidNode );
3740 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3741 ::SMESH_MeshEditor anEditor( myMesh );
3743 anEditor.FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes );
3745 theGroupsOfNodes = new SMESH::array_of_long_array;
3746 theGroupsOfNodes->length( aListOfListOfNodes.size() );
3747 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3748 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3750 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3751 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3752 SMESH::long_array& aGroup = (*theGroupsOfNodes)[ i ];
3753 aGroup.length( aListOfNodes.size() );
3754 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3755 aGroup[ j ] = (*lIt)->GetID();
3757 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPartBut( "
3759 << theTolerance << ", "
3760 << theExceptSubMeshOrGroups << " )";
3763 //=======================================================================
3764 //function : MergeNodes
3766 //=======================================================================
3768 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3772 SMESHDS_Mesh* aMesh = GetMeshDS();
3774 TPythonDump aTPythonDump;
3775 aTPythonDump << this << ".MergeNodes([";
3776 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3777 for (int i = 0; i < GroupsOfNodes.length(); i++)
3779 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3780 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3781 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3782 for ( int j = 0; j < aNodeGroup.length(); j++ )
3784 CORBA::Long index = aNodeGroup[ j ];
3785 const SMDS_MeshNode * node = aMesh->FindNode(index);
3787 aListOfNodes.push_back( node );
3789 if ( aListOfNodes.size() < 2 )
3790 aListOfListOfNodes.pop_back();
3792 if ( i > 0 ) aTPythonDump << ", ";
3793 aTPythonDump << aNodeGroup;
3795 ::SMESH_MeshEditor anEditor( myMesh );
3796 anEditor.MergeNodes( aListOfListOfNodes );
3798 aTPythonDump << "])";
3800 myMesh->SetIsModified( true );
3803 //=======================================================================
3804 //function : FindEqualElements
3806 //=======================================================================
3807 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3808 SMESH::array_of_long_array_out GroupsOfElementsID)
3812 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theObject);
3813 if ( !(!group->_is_nil() && group->GetType() == SMESH::NODE) )
3815 typedef list<int> TListOfIDs;
3816 set<const SMDS_MeshElement*> elems;
3817 SMESH::long_array_var aElementsId = theObject->GetIDs();
3818 SMESHDS_Mesh* aMesh = GetMeshDS();
3820 for(int i = 0; i < aElementsId->length(); i++) {
3821 CORBA::Long anID = aElementsId[i];
3822 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3828 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3829 ::SMESH_MeshEditor anEditor( myMesh );
3830 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3832 GroupsOfElementsID = new SMESH::array_of_long_array;
3833 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3835 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3836 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3837 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3838 TListOfIDs& listOfIDs = *arraysIt;
3839 aGroup.length( listOfIDs.size() );
3840 TListOfIDs::iterator idIt = listOfIDs.begin();
3841 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3842 aGroup[ k ] = *idIt;
3846 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3851 //=======================================================================
3852 //function : MergeElements
3854 //=======================================================================
3856 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3860 TPythonDump aTPythonDump;
3861 aTPythonDump << this << ".MergeElements( [";
3863 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3865 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3866 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3867 aListOfListOfElementsID.push_back( list< int >() );
3868 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3869 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3870 CORBA::Long id = anElemsIDGroup[ j ];
3871 aListOfElemsID.push_back( id );
3873 if ( aListOfElemsID.size() < 2 )
3874 aListOfListOfElementsID.pop_back();
3875 if ( i > 0 ) aTPythonDump << ", ";
3876 aTPythonDump << anElemsIDGroup;
3879 ::SMESH_MeshEditor anEditor( myMesh );
3880 anEditor.MergeElements(aListOfListOfElementsID);
3882 myMesh->SetIsModified( true );
3884 aTPythonDump << "] )";
3887 //=======================================================================
3888 //function : MergeEqualElements
3890 //=======================================================================
3892 void SMESH_MeshEditor_i::MergeEqualElements()
3896 ::SMESH_MeshEditor anEditor( myMesh );
3897 anEditor.MergeEqualElements();
3899 TPythonDump() << this << ".MergeEqualElements()";
3902 //=============================================================================
3904 * Move the node to a given point
3906 //=============================================================================
3908 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
3913 initData(/*deleteSearchers=*/false);
3915 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
3919 if ( theNodeSearcher )
3920 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3922 if ( myPreviewMode ) // make preview data
3924 // in a preview mesh, make edges linked to a node
3925 TPreviewMesh tmpMesh;
3926 TIDSortedElemSet linkedNodes;
3927 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3928 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3929 for ( ; nIt != linkedNodes.end(); ++nIt )
3931 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
3932 tmpMesh.Copy( &edge );
3935 node = tmpMesh.GetMeshDS()->FindNode( NodeID );
3937 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
3938 // fill preview data
3939 ::SMESH_MeshEditor anEditor( & tmpMesh );
3940 storeResult( anEditor );
3942 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3943 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3945 GetMeshDS()->MoveNode(node, x, y, z);
3947 if ( !myPreviewMode )
3949 // Update Python script
3950 TPythonDump() << "isDone = " << this << ".MoveNode( "
3951 << NodeID << ", " << x << ", " << y << ", " << z << " )";
3953 myMesh->SetIsModified( true );
3959 //================================================================================
3961 * \brief Return ID of node closest to a given point
3963 //================================================================================
3965 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
3969 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3971 if ( !theNodeSearcher ) {
3972 ::SMESH_MeshEditor anEditor( myMesh );
3973 theNodeSearcher = anEditor.GetNodeSearcher();
3976 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
3977 return node->GetID();
3982 //================================================================================
3984 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
3985 * move the node closest to the point to point's location and return ID of the node
3987 //================================================================================
3989 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
3992 CORBA::Long theNodeID)
3994 // We keep theNodeSearcher until any mesh modification:
3995 // 1) initData() deletes theNodeSearcher at any edition,
3996 // 2) TSearchersDeleter - at any mesh compute event and mesh change
3998 initData(/*deleteSearchers=*/false);
4000 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4002 int nodeID = theNodeID;
4003 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
4004 if ( !node ) // preview moving node
4006 if ( !theNodeSearcher ) {
4007 ::SMESH_MeshEditor anEditor( myMesh );
4008 theNodeSearcher = anEditor.GetNodeSearcher();
4011 node = theNodeSearcher->FindClosestTo( p );
4014 nodeID = node->GetID();
4015 if ( myPreviewMode ) // make preview data
4017 // in a preview mesh, make edges linked to a node
4018 TPreviewMesh tmpMesh;
4019 TIDSortedElemSet linkedNodes;
4020 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
4021 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
4022 for ( ; nIt != linkedNodes.end(); ++nIt )
4024 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
4025 tmpMesh.Copy( &edge );
4028 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
4030 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
4031 // fill preview data
4032 ::SMESH_MeshEditor anEditor( & tmpMesh );
4033 storeResult( anEditor );
4035 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
4037 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
4041 GetMeshDS()->MoveNode(node, x, y, z);
4045 if ( !myPreviewMode )
4047 TPythonDump() << "nodeID = " << this
4048 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
4049 << ", " << nodeID << " )";
4051 myMesh->SetIsModified( true );
4057 //=======================================================================
4059 * Return elements of given type where the given point is IN or ON.
4061 * 'ALL' type means elements of any type excluding nodes
4063 //=======================================================================
4065 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
4068 SMESH::ElementType type)
4070 SMESH::long_array_var res = new SMESH::long_array;
4071 vector< const SMDS_MeshElement* > foundElems;
4073 theSearchersDeleter.Set( myMesh );
4074 if ( !theElementSearcher ) {
4075 ::SMESH_MeshEditor anEditor( myMesh );
4076 theElementSearcher = anEditor.GetElementSearcher();
4078 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
4079 SMDSAbs_ElementType( type ),
4081 res->length( foundElems.size() );
4082 for ( int i = 0; i < foundElems.size(); ++i )
4083 res[i] = foundElems[i]->GetID();
4085 if ( !myPreviewMode ) // call from tui
4086 TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
4095 //=======================================================================
4096 //function : GetPointState
4097 //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
4098 // TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
4099 //=======================================================================
4101 CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
4105 theSearchersDeleter.Set( myMesh );
4106 if ( !theElementSearcher ) {
4107 ::SMESH_MeshEditor anEditor( myMesh );
4108 theElementSearcher = anEditor.GetElementSearcher();
4110 return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
4113 //=======================================================================
4114 //function : convError
4116 //=======================================================================
4118 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
4120 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
4124 RETCASE( SEW_BORDER1_NOT_FOUND );
4125 RETCASE( SEW_BORDER2_NOT_FOUND );
4126 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
4127 RETCASE( SEW_BAD_SIDE_NODES );
4128 RETCASE( SEW_VOLUMES_TO_SPLIT );
4129 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
4130 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
4131 RETCASE( SEW_BAD_SIDE1_NODES );
4132 RETCASE( SEW_BAD_SIDE2_NODES );
4134 return SMESH::SMESH_MeshEditor::SEW_OK;
4137 //=======================================================================
4138 //function : SewFreeBorders
4140 //=======================================================================
4142 SMESH::SMESH_MeshEditor::Sew_Error
4143 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
4144 CORBA::Long SecondNodeID1,
4145 CORBA::Long LastNodeID1,
4146 CORBA::Long FirstNodeID2,
4147 CORBA::Long SecondNodeID2,
4148 CORBA::Long LastNodeID2,
4149 CORBA::Boolean CreatePolygons,
4150 CORBA::Boolean CreatePolyedrs)
4154 SMESHDS_Mesh* aMesh = GetMeshDS();
4156 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4157 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4158 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4159 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4160 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4161 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
4163 if (!aBorderFirstNode ||
4164 !aBorderSecondNode||
4166 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4167 if (!aSide2FirstNode ||
4168 !aSide2SecondNode ||
4170 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4172 TPythonDump() << "error = " << this << ".SewFreeBorders( "
4173 << FirstNodeID1 << ", "
4174 << SecondNodeID1 << ", "
4175 << LastNodeID1 << ", "
4176 << FirstNodeID2 << ", "
4177 << SecondNodeID2 << ", "
4178 << LastNodeID2 << ", "
4179 << CreatePolygons<< ", "
4180 << CreatePolyedrs<< " )";
4182 ::SMESH_MeshEditor anEditor( myMesh );
4183 SMESH::SMESH_MeshEditor::Sew_Error error =
4184 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4194 storeResult(anEditor);
4196 myMesh->SetIsModified( true );
4202 //=======================================================================
4203 //function : SewConformFreeBorders
4205 //=======================================================================
4207 SMESH::SMESH_MeshEditor::Sew_Error
4208 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
4209 CORBA::Long SecondNodeID1,
4210 CORBA::Long LastNodeID1,
4211 CORBA::Long FirstNodeID2,
4212 CORBA::Long SecondNodeID2)
4216 SMESHDS_Mesh* aMesh = GetMeshDS();
4218 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4219 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4220 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4221 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4222 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4223 const SMDS_MeshNode* aSide2ThirdNode = 0;
4225 if (!aBorderFirstNode ||
4226 !aBorderSecondNode||
4228 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4229 if (!aSide2FirstNode ||
4231 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4233 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
4234 << FirstNodeID1 << ", "
4235 << SecondNodeID1 << ", "
4236 << LastNodeID1 << ", "
4237 << FirstNodeID2 << ", "
4238 << SecondNodeID2 << " )";
4240 ::SMESH_MeshEditor anEditor( myMesh );
4241 SMESH::SMESH_MeshEditor::Sew_Error error =
4242 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4251 storeResult(anEditor);
4253 myMesh->SetIsModified( true );
4259 //=======================================================================
4260 //function : SewBorderToSide
4262 //=======================================================================
4264 SMESH::SMESH_MeshEditor::Sew_Error
4265 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
4266 CORBA::Long SecondNodeIDOnFreeBorder,
4267 CORBA::Long LastNodeIDOnFreeBorder,
4268 CORBA::Long FirstNodeIDOnSide,
4269 CORBA::Long LastNodeIDOnSide,
4270 CORBA::Boolean CreatePolygons,
4271 CORBA::Boolean CreatePolyedrs)
4275 SMESHDS_Mesh* aMesh = GetMeshDS();
4277 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
4278 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
4279 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
4280 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
4281 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
4282 const SMDS_MeshNode* aSide2ThirdNode = 0;
4284 if (!aBorderFirstNode ||
4285 !aBorderSecondNode||
4287 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4288 if (!aSide2FirstNode ||
4290 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
4292 TPythonDump() << "error = " << this << ".SewBorderToSide( "
4293 << FirstNodeIDOnFreeBorder << ", "
4294 << SecondNodeIDOnFreeBorder << ", "
4295 << LastNodeIDOnFreeBorder << ", "
4296 << FirstNodeIDOnSide << ", "
4297 << LastNodeIDOnSide << ", "
4298 << CreatePolygons << ", "
4299 << CreatePolyedrs << ") ";
4301 ::SMESH_MeshEditor anEditor( myMesh );
4302 SMESH::SMESH_MeshEditor::Sew_Error error =
4303 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4313 storeResult(anEditor);
4315 myMesh->SetIsModified( true );
4321 //=======================================================================
4322 //function : SewSideElements
4324 //=======================================================================
4326 SMESH::SMESH_MeshEditor::Sew_Error
4327 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
4328 const SMESH::long_array& IDsOfSide2Elements,
4329 CORBA::Long NodeID1OfSide1ToMerge,
4330 CORBA::Long NodeID1OfSide2ToMerge,
4331 CORBA::Long NodeID2OfSide1ToMerge,
4332 CORBA::Long NodeID2OfSide2ToMerge)
4336 SMESHDS_Mesh* aMesh = GetMeshDS();
4338 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
4339 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
4340 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
4341 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
4343 if (!aFirstNode1ToMerge ||
4344 !aFirstNode2ToMerge )
4345 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
4346 if (!aSecondNode1ToMerge||
4347 !aSecondNode2ToMerge)
4348 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
4350 TIDSortedElemSet aSide1Elems, aSide2Elems;
4351 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
4352 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
4354 TPythonDump() << "error = " << this << ".SewSideElements( "
4355 << IDsOfSide1Elements << ", "
4356 << IDsOfSide2Elements << ", "
4357 << NodeID1OfSide1ToMerge << ", "
4358 << NodeID1OfSide2ToMerge << ", "
4359 << NodeID2OfSide1ToMerge << ", "
4360 << NodeID2OfSide2ToMerge << ")";
4362 ::SMESH_MeshEditor anEditor( myMesh );
4363 SMESH::SMESH_MeshEditor::Sew_Error error =
4364 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
4367 aSecondNode1ToMerge,
4368 aSecondNode2ToMerge));
4370 storeResult(anEditor);
4372 myMesh->SetIsModified( true );
4377 //================================================================================
4379 * \brief Set new nodes for given element
4380 * \param ide - element id
4381 * \param newIDs - new node ids
4382 * \retval CORBA::Boolean - true if result is OK
4384 //================================================================================
4386 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
4387 const SMESH::long_array& newIDs)
4391 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
4392 if(!elem) return false;
4394 int nbn = newIDs.length();
4396 vector<const SMDS_MeshNode*> aNodes(nbn);
4399 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
4402 aNodes[nbn1] = aNode;
4405 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
4406 << ide << ", " << newIDs << " )";
4408 bool res = GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
4411 myMesh->SetIsModified( true );
4416 //================================================================================
4418 * \brief Update myLastCreated* or myPreviewData
4419 * \param anEditor - it contains last modification results
4421 //================================================================================
4423 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
4425 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
4427 list<int> aNodesConnectivity;
4428 typedef map<int, int> TNodesMap;
4431 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
4432 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
4434 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
4435 int nbEdges = aMeshDS->NbEdges();
4436 int nbFaces = aMeshDS->NbFaces();
4437 int nbVolum = aMeshDS->NbVolumes();
4438 switch ( previewType ) {
4439 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
4440 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
4441 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
4444 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
4445 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
4447 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
4449 while ( itMeshElems->more() ) {
4450 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
4451 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
4454 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
4455 while ( itElemNodes->more() ) {
4456 const SMDS_MeshNode* aMeshNode =
4457 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
4458 int aNodeID = aMeshNode->GetID();
4459 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
4460 if ( anIter == nodesMap.end() ) {
4461 // filling the nodes coordinates
4462 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
4463 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
4464 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
4465 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4468 aNodesConnectivity.push_back(anIter->second);
4471 // filling the elements types
4472 SMDSAbs_ElementType aType;
4474 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4475 aType = SMDSAbs_Node;
4479 aType = aMeshElem->GetType();
4480 isPoly = aMeshElem->IsPoly();
4483 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4484 myPreviewData->elementTypes[i].isPoly = isPoly;
4485 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4489 myPreviewData->nodesXYZ.length( j );
4491 // filling the elements connectivities
4492 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4493 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4494 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4495 myPreviewData->elementConnectivities[i] = *aConnIter;
4501 // add new nodes into myLastCreatedNodes
4502 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4503 myLastCreatedNodes->length(aSeq.Length());
4504 for(int i=0; i<aSeq.Length(); i++)
4505 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4508 // add new elements into myLastCreatedElems
4509 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4510 myLastCreatedElems->length(aSeq.Length());
4511 for(int i=0; i<aSeq.Length(); i++)
4512 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4516 //================================================================================
4518 * Return data of mesh edition preview
4520 //================================================================================
4522 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4524 return myPreviewData._retn();
4527 //================================================================================
4529 * \brief Returns list of it's IDs of created nodes
4530 * \retval SMESH::long_array* - list of node ID
4532 //================================================================================
4534 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4536 return myLastCreatedNodes._retn();
4539 //================================================================================
4541 * \brief Returns list of it's IDs of created elements
4542 * \retval SMESH::long_array* - list of elements' ID
4544 //================================================================================
4546 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4548 return myLastCreatedElems._retn();
4551 //=======================================================================
4552 //function : ConvertToQuadratic
4554 //=======================================================================
4556 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4558 ::SMESH_MeshEditor anEditor( myMesh );
4559 anEditor.ConvertToQuadratic(theForce3d);
4560 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4561 myMesh->SetIsModified( true );
4564 //=======================================================================
4565 //function : ConvertFromQuadratic
4567 //=======================================================================
4569 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4571 ::SMESH_MeshEditor anEditor( myMesh );
4572 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4573 TPythonDump() << this << ".ConvertFromQuadratic()";
4575 myMesh->SetIsModified( true );
4579 //=======================================================================
4580 //function : makeMesh
4581 //purpose : create a named imported mesh
4582 //=======================================================================
4584 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4586 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4587 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4588 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4589 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4590 gen->SetName( meshSO, theMeshName, "Mesh" );
4591 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4593 return mesh._retn();
4596 //=======================================================================
4597 //function : DumpGroupsList
4599 //=======================================================================
4600 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4601 const SMESH::ListOfGroups * theGroupList)
4603 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4604 if(isDumpGroupList) {
4605 theDumpPython << theGroupList << " = ";
4609 //================================================================================
4611 \brief Generates the unique group name.
4612 \param thePrefix name prefix
4615 //================================================================================
4616 string SMESH_MeshEditor_i::generateGroupName(const string& thePrefix)
4618 SMESH::ListOfGroups_var groups = myMesh_i->GetGroups();
4619 set<string> groupNames;
4621 // Get existing group names
4622 for (int i = 0, nbGroups = groups->length(); i < nbGroups; i++ ) {
4623 SMESH::SMESH_GroupBase_var aGroup = groups[i];
4624 if (CORBA::is_nil(aGroup))
4627 groupNames.insert(aGroup->GetName());
4631 string name = thePrefix;
4634 while (!groupNames.insert(name).second) {
4639 TCollection_AsciiString nbStr(index+1);
4640 name.resize( name.rfind('_')+1 );
4641 name += nbStr.ToCString();
4649 //================================================================================
4651 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4652 \param theNodes - identifiers of nodes to be doubled
4653 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4654 nodes. If list of element identifiers is empty then nodes are doubled but
4655 they not assigned to elements
4656 \return TRUE if operation has been completed successfully, FALSE otherwise
4657 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4659 //================================================================================
4661 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4662 const SMESH::long_array& theModifiedElems )
4666 ::SMESH_MeshEditor aMeshEditor( myMesh );
4667 list< int > aListOfNodes;
4669 for ( i = 0, n = theNodes.length(); i < n; i++ )
4670 aListOfNodes.push_back( theNodes[ i ] );
4672 list< int > aListOfElems;
4673 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4674 aListOfElems.push_back( theModifiedElems[ i ] );
4676 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4678 storeResult( aMeshEditor) ;
4680 myMesh->SetIsModified( true );
4682 // Update Python script
4683 TPythonDump() << this << ".DoubleNodes( " << theNodes << ", "<< theModifiedElems << " )";
4688 //================================================================================
4690 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4691 This method provided for convenience works as DoubleNodes() described above.
4692 \param theNodeId - identifier of node to be doubled.
4693 \param theModifiedElems - identifiers of elements to be updated.
4694 \return TRUE if operation has been completed successfully, FALSE otherwise
4695 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4697 //================================================================================
4699 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4700 const SMESH::long_array& theModifiedElems )
4702 SMESH::long_array_var aNodes = new SMESH::long_array;
4703 aNodes->length( 1 );
4704 aNodes[ 0 ] = theNodeId;
4706 TPythonDump pyDump; // suppress dump by the next line
4708 CORBA::Boolean done = DoubleNodes( aNodes, theModifiedElems );
4710 pyDump << this << ".DoubleNode( " << theNodeId << ", " << theModifiedElems << " )";
4715 //================================================================================
4717 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4718 This method provided for convenience works as DoubleNodes() described above.
4719 \param theNodes - group of nodes to be doubled.
4720 \param theModifiedElems - group of elements to be updated.
4721 \return TRUE if operation has been completed successfully, FALSE otherwise
4722 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
4724 //================================================================================
4726 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(SMESH::SMESH_GroupBase_ptr theNodes,
4727 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4729 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4732 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4733 SMESH::long_array_var aModifiedElems;
4734 if ( !CORBA::is_nil( theModifiedElems ) )
4735 aModifiedElems = theModifiedElems->GetListOfID();
4738 aModifiedElems = new SMESH::long_array;
4739 aModifiedElems->length( 0 );
4742 TPythonDump pyDump; // suppress dump by the next line
4744 bool done = DoubleNodes( aNodes, aModifiedElems );
4746 pyDump << this << ".DoubleNodeGroup( " << theNodes << ", " << theModifiedElems << " )";
4752 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements.
4753 * Works as DoubleNodeGroup(), but returns a new group with newly created nodes.
4754 * \param theNodes - group of nodes to be doubled.
4755 * \param theModifiedElems - group of elements to be updated.
4756 * \return a new group with newly created nodes
4757 * \sa DoubleNodeGroup()
4759 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes,
4760 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4762 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4765 SMESH::SMESH_Group_var aNewGroup;
4768 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4769 SMESH::long_array_var aModifiedElems;
4770 if ( !CORBA::is_nil( theModifiedElems ) )
4771 aModifiedElems = theModifiedElems->GetListOfID();
4773 aModifiedElems = new SMESH::long_array;
4774 aModifiedElems->length( 0 );
4777 TPythonDump pyDump; // suppress dump by the next line
4779 bool aResult = DoubleNodes( aNodes, aModifiedElems );
4783 // Create group with newly created nodes
4784 SMESH::long_array_var anIds = GetLastCreatedNodes();
4785 if (anIds->length() > 0) {
4786 string anUnindexedName (theNodes->GetName());
4787 string aNewName = generateGroupName(anUnindexedName + "_double");
4788 aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
4789 aNewGroup->Add(anIds);
4793 pyDump << "createdNodes = " << this << ".DoubleNodeGroupNew( " << theNodes << ", "
4794 << theModifiedElems << " )";
4796 return aNewGroup._retn();
4799 //================================================================================
4801 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4802 This method provided for convenience works as DoubleNodes() described above.
4803 \param theNodes - list of groups of nodes to be doubled
4804 \param theModifiedElems - list of groups of elements to be updated.
4805 \return TRUE if operation has been completed successfully, FALSE otherwise
4806 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
4808 //================================================================================
4810 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& theNodes,
4811 const SMESH::ListOfGroups& theModifiedElems )
4815 ::SMESH_MeshEditor aMeshEditor( myMesh );
4817 std::list< int > aNodes;
4819 for ( i = 0, n = theNodes.length(); i < n; i++ )
4821 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
4822 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
4824 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4825 for ( j = 0, m = aCurr->length(); j < m; j++ )
4826 aNodes.push_back( aCurr[ j ] );
4830 std::list< int > anElems;
4831 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4833 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
4834 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
4836 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4837 for ( j = 0, m = aCurr->length(); j < m; j++ )
4838 anElems.push_back( aCurr[ j ] );
4842 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
4844 storeResult( aMeshEditor) ;
4847 myMesh->SetIsModified( true );
4850 TPythonDump() << this << ".DoubleNodeGroups( " << theNodes << ", " << theModifiedElems << " )";
4855 //================================================================================
4857 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4858 \param theElems - the list of elements (edges or faces) to be replicated
4859 The nodes for duplication could be found from these elements
4860 \param theNodesNot - list of nodes to NOT replicate
4861 \param theAffectedElems - the list of elements (cells and edges) to which the
4862 replicated nodes should be associated to.
4863 \return TRUE if operation has been completed successfully, FALSE otherwise
4864 \sa DoubleNodeGroup(), DoubleNodeGroups()
4866 //================================================================================
4868 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
4869 const SMESH::long_array& theNodesNot,
4870 const SMESH::long_array& theAffectedElems )
4875 ::SMESH_MeshEditor aMeshEditor( myMesh );
4877 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4878 TIDSortedElemSet anElems, aNodes, anAffected;
4879 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4880 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4881 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
4883 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4885 storeResult( aMeshEditor) ;
4888 myMesh->SetIsModified( true );
4890 // Update Python script
4891 TPythonDump() << this << ".DoubleNodeElem( " << theElems << ", "
4892 << theNodesNot << ", " << theAffectedElems << " )";
4896 //================================================================================
4898 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4899 \param theElems - the list of elements (edges or faces) to be replicated
4900 The nodes for duplication could be found from these elements
4901 \param theNodesNot - list of nodes to NOT replicate
4902 \param theShape - shape to detect affected elements (element which geometric center
4903 located on or inside shape).
4904 The replicated nodes should be associated to affected elements.
4905 \return TRUE if operation has been completed successfully, FALSE otherwise
4906 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
4908 //================================================================================
4910 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_array& theElems,
4911 const SMESH::long_array& theNodesNot,
4912 GEOM::GEOM_Object_ptr theShape )
4917 ::SMESH_MeshEditor aMeshEditor( myMesh );
4919 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4920 TIDSortedElemSet anElems, aNodes;
4921 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4922 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4924 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4925 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4927 storeResult( aMeshEditor) ;
4930 myMesh->SetIsModified( true );
4932 // Update Python script
4933 TPythonDump() << "isDone = " << this << ".DoubleNodeElemInRegion( " << theElems << ", "
4934 << theNodesNot << ", " << theShape << " )";
4938 //================================================================================
4940 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4941 \param theElems - group of of elements (edges or faces) to be replicated
4942 \param theNodesNot - group of nodes not to replicated
4943 \param theAffectedElems - group of elements to which the replicated nodes
4944 should be associated to.
4945 \return TRUE if operation has been completed successfully, FALSE otherwise
4946 \sa DoubleNodes(), DoubleNodeGroups()
4948 //================================================================================
4950 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_ptr theElems,
4951 SMESH::SMESH_GroupBase_ptr theNodesNot,
4952 SMESH::SMESH_GroupBase_ptr theAffectedElems)
4954 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4959 ::SMESH_MeshEditor aMeshEditor( myMesh );
4961 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4962 TIDSortedElemSet anElems, aNodes, anAffected;
4963 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4964 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4965 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
4967 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4969 storeResult( aMeshEditor) ;
4972 myMesh->SetIsModified( true );
4974 // Update Python script
4975 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroup( " << theElems << ", "
4976 << theNodesNot << ", " << theAffectedElems << " )";
4981 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4982 * Works as DoubleNodeElemGroup(), but returns a new group with newly created elements.
4983 * \param theElems - group of of elements (edges or faces) to be replicated
4984 * \param theNodesNot - group of nodes not to replicated
4985 * \param theAffectedElems - group of elements to which the replicated nodes
4986 * should be associated to.
4987 * \return a new group with newly created elements
4988 * \sa DoubleNodeElemGroup()
4990 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems,
4991 SMESH::SMESH_GroupBase_ptr theNodesNot,
4992 SMESH::SMESH_GroupBase_ptr theAffectedElems)
4994 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4997 SMESH::SMESH_Group_var aNewGroup;
5001 ::SMESH_MeshEditor aMeshEditor( myMesh );
5003 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5004 TIDSortedElemSet anElems, aNodes, anAffected;
5005 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5006 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5007 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
5010 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5012 storeResult( aMeshEditor) ;
5015 myMesh->SetIsModified( true );
5017 // Create group with newly created elements
5018 SMESH::long_array_var anIds = GetLastCreatedElems();
5019 if (anIds->length() > 0) {
5020 SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
5021 string anUnindexedName (theElems->GetName());
5022 string aNewName = generateGroupName(anUnindexedName + "_double");
5023 aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
5024 aNewGroup->Add(anIds);
5028 // Update Python script
5029 TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupNew( " << theElems << ", "
5030 << theNodesNot << ", " << theAffectedElems << " )";
5031 return aNewGroup._retn();
5034 //================================================================================
5036 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5037 \param theElems - group of of elements (edges or faces) to be replicated
5038 \param theNodesNot - group of nodes not to replicated
5039 \param theShape - shape to detect affected elements (element which geometric center
5040 located on or inside shape).
5041 The replicated nodes should be associated to affected elements.
5042 \return TRUE if operation has been completed successfully, FALSE otherwise
5043 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
5045 //================================================================================
5047 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_GroupBase_ptr theElems,
5048 SMESH::SMESH_GroupBase_ptr theNodesNot,
5049 GEOM::GEOM_Object_ptr theShape )
5052 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5057 ::SMESH_MeshEditor aMeshEditor( myMesh );
5059 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5060 TIDSortedElemSet anElems, aNodes, anAffected;
5061 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5062 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5064 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5065 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5067 storeResult( aMeshEditor) ;
5070 myMesh->SetIsModified( true );
5072 // Update Python script
5073 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupInRegion( " << theElems << ", "
5074 << theNodesNot << ", " << theShape << " )";
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 theElems - list of groups of elements (edges or faces) to be replicated
5083 \param theNodesNot - list of groups of nodes not to replicated
5084 \param theAffectedElems - group of elements to which the replicated nodes
5085 should be associated to.
5086 \return TRUE if operation has been completed successfully, FALSE otherwise
5087 \sa DoubleNodeGroup(), DoubleNodes()
5089 //================================================================================
5091 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
5092 SMESHDS_Mesh* theMeshDS,
5093 TIDSortedElemSet& theElemSet,
5094 const bool theIsNodeGrp)
5096 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
5098 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
5099 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
5100 : aGrp->GetType() != SMESH::NODE ) )
5102 SMESH::long_array_var anIDs = aGrp->GetIDs();
5103 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
5108 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroups& theElems,
5109 const SMESH::ListOfGroups& theNodesNot,
5110 const SMESH::ListOfGroups& theAffectedElems)
5114 ::SMESH_MeshEditor aMeshEditor( myMesh );
5116 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5117 TIDSortedElemSet anElems, aNodes, anAffected;
5118 listOfGroupToSet(theElems, aMeshDS, anElems, false );
5119 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5120 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
5122 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5124 storeResult( aMeshEditor) ;
5127 myMesh->SetIsModified( true );
5129 // Update Python script
5130 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroups( " << &theElems << ", "
5131 << &theNodesNot << ", " << &theAffectedElems << " )";
5135 //================================================================================
5137 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5138 This method provided for convenience works as DoubleNodes() described above.
5139 \param theElems - list of groups of elements (edges or faces) to be replicated
5140 \param theNodesNot - list of groups of nodes not to replicated
5141 \param theShape - shape to detect affected elements (element which geometric center
5142 located on or inside shape).
5143 The replicated nodes should be associated to affected elements.
5144 \return TRUE if operation has been completed successfully, FALSE otherwise
5145 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
5147 //================================================================================
5150 SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theElems,
5151 const SMESH::ListOfGroups& theNodesNot,
5152 GEOM::GEOM_Object_ptr theShape )
5156 ::SMESH_MeshEditor aMeshEditor( myMesh );
5158 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5159 TIDSortedElemSet anElems, aNodes;
5160 listOfGroupToSet(theElems, aMeshDS, anElems,false );
5161 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5163 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5164 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5166 storeResult( aMeshEditor) ;
5169 myMesh->SetIsModified( true );
5171 // Update Python script
5172 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupsInRegion( " << &theElems << ", "
5173 << &theNodesNot << ", " << theShape << " )";
5177 //================================================================================
5179 \brief Generated skin mesh (containing 2D cells) from 3D mesh
5180 The created 2D mesh elements based on nodes of free faces of boundary volumes
5181 \return TRUE if operation has been completed successfully, FALSE otherwise
5183 //================================================================================
5185 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
5189 ::SMESH_MeshEditor aMeshEditor( myMesh );
5190 bool aResult = aMeshEditor.Make2DMeshFrom3D();
5191 storeResult( aMeshEditor) ;
5193 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";
5197 // issue 20749 ===================================================================
5199 * \brief Creates missing boundary elements
5200 * \param elements - elements whose boundary is to be checked
5201 * \param dimension - defines type of boundary elements to create
5202 * \param groupName - a name of group to store created boundary elements in,
5203 * "" means not to create the group
5204 * \param meshName - a name of new mesh to store created boundary elements in,
5205 * "" means not to create the new mesh
5206 * \param toCopyElements - if true, the checked elements will be copied into the new mesh
5207 * \param toCopyExistingBondary - if true, not only new but also pre-existing
5208 * boundary elements will be copied into the new mesh
5209 * \param group - returns the create group, if any
5210 * \retval SMESH::SMESH_Mesh - the mesh where elements were added to
5212 // ================================================================================
5214 SMESH::SMESH_Mesh_ptr
5215 SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource,
5216 SMESH::Bnd_Dimension dim,
5217 const char* groupName,
5218 const char* meshName,
5219 CORBA::Boolean toCopyElements,
5220 CORBA::Boolean toCopyExistingBondary,
5221 SMESH::SMESH_Group_out group)
5225 if ( dim > SMESH::BND_1DFROM2D )
5226 THROW_SALOME_CORBA_EXCEPTION("Invalid boundary dimension", SALOME::BAD_PARAM);
5229 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5231 SMESH::SMESH_Mesh_var mesh_var;
5232 SMESH::SMESH_Group_var group_var;
5236 TIDSortedElemSet elements;
5237 SMDSAbs_ElementType elemType = (dim == SMESH::BND_1DFROM2D) ? SMDSAbs_Face : SMDSAbs_Volume;
5238 if ( idSourceToSet( idSource, aMeshDS, elements, elemType,/*emptyIfIsMesh=*/true ))
5242 strlen(meshName) ? makeMesh(meshName) : SMESH::SMESH_Mesh::_duplicate(myMesh_i->_this());
5243 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh_var );
5245 SMESH_Mesh* smesh_mesh = (mesh_i==myMesh_i) ? (SMESH_Mesh*)0 : &mesh_i->GetImpl();
5247 // group of new boundary elements
5248 SMESH_Group* smesh_group = 0;
5249 if ( strlen(groupName) )
5251 group_var = mesh_i->CreateGroup( SMESH::ElementType(elemType),groupName);
5252 if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( group_var ))
5253 smesh_group = group_i->GetSmeshGroup();
5257 ::SMESH_MeshEditor aMeshEditor( myMesh );
5258 aMeshEditor.MakeBoundaryMesh( elements,
5259 ::SMESH_MeshEditor::Bnd_Dimension(dim),
5263 toCopyExistingBondary);
5264 storeResult( aMeshEditor );
5267 // result of MakeBoundaryMesh() is a tuple (mesh, group)
5268 if ( mesh_var->_is_nil() )
5269 pyDump << myMesh_i->_this() << ", ";
5271 pyDump << mesh_var << ", ";
5272 if ( group_var->_is_nil() )
5273 pyDump << "_NoneGroup = "; // assignment to None is forbiden
5275 pyDump << group_var << " = ";
5276 pyDump << this << ".MakeBoundaryMesh( "
5279 << groupName << ", "
5281 << toCopyElements << ", "
5282 << toCopyExistingBondary << ")";
5284 group = group_var._retn();
5285 return mesh_var._retn();