1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_MeshEditor_i.cxx
24 // Author : Nicolas REJNERI
27 #include "SMESH_MeshEditor_i.hxx"
29 #include "SMDS_Mesh0DElement.hxx"
30 #include "SMDS_MeshEdge.hxx"
31 #include "SMDS_MeshFace.hxx"
32 #include "SMDS_MeshVolume.hxx"
33 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
34 #include "SMESH_MeshEditor.hxx"
35 #include "SMESH_subMeshEventListener.hxx"
36 #include "SMESH_Gen_i.hxx"
37 #include "SMESH_Filter_i.hxx"
38 #include "SMESH_subMesh_i.hxx"
39 #include "SMESH_Group_i.hxx"
40 #include "SMESH_PythonDump.hxx"
42 #include "utilities.h"
43 #include "Utils_ExceptHandlers.hxx"
44 #include "Utils_CorbaException.hxx"
46 #include <BRepAdaptor_Surface.hxx>
47 #include <BRep_Tool.hxx>
48 #include <TopExp_Explorer.hxx>
50 #include <TopoDS_Edge.hxx>
51 #include <TopoDS_Face.hxx>
56 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
60 #include <Standard_Failure.hxx>
63 #include <Standard_ErrorHandler.hxx>
68 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
71 using SMESH::TPythonDump;
75 //=============================================================================
77 * \brief Mesh to apply modifications for preview purposes
79 //=============================================================================
81 struct TPreviewMesh: public SMESH_Mesh
83 SMDSAbs_ElementType myPreviewType; // type to show
85 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
86 _isShapeToMesh = (_id =_studyId =_idDoc = 0);
87 _myMeshDS = new SMESHDS_Mesh( _id, true );
88 myPreviewType = previewElements;
91 virtual ~TPreviewMesh() { delete _myMeshDS; }
92 //!< Copy a set of elements
93 void Copy(const TIDSortedElemSet & theElements,
94 TIDSortedElemSet& theCopyElements,
95 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
96 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
98 // loop on theIDsOfElements
99 TIDSortedElemSet::const_iterator eIt = theElements.begin();
100 for ( ; eIt != theElements.end(); ++eIt )
102 const SMDS_MeshElement* anElem = *eIt;
103 if ( !anElem ) continue;
104 SMDSAbs_ElementType type = anElem->GetType();
105 if ( type == theAvoidType ||
106 ( theSelectType != SMDSAbs_All && type != theSelectType ))
109 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
110 theCopyElements.insert( theCopyElements.end(), anElemCopy );
114 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
116 // copy element nodes
117 int anElemNbNodes = anElem->NbNodes();
118 vector< int > anElemNodesID( anElemNbNodes ) ;
119 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
120 for ( int i = 0; itElemNodes->more(); i++)
122 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
124 anElemNodesID[i] = anElemNode->GetID();
127 // creates a corresponding element on copied nodes
128 SMDS_MeshElement* anElemCopy = 0;
129 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
131 const SMDS_PolyhedralVolumeOfNodes* ph =
132 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
134 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
135 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
138 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
145 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
147 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
148 anElemNode->GetID());
150 };// struct TPreviewMesh
152 static SMESH_NodeSearcher * theNodeSearcher = 0;
153 static SMESH_ElementSearcher * theElementSearcher = 0;
155 //=============================================================================
157 * \brief Deleter of theNodeSearcher at any compute event occured
159 //=============================================================================
161 struct TSearchersDeleter : public SMESH_subMeshEventListener
165 TSearchersDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
167 //!< Delete theNodeSearcher
170 if ( theNodeSearcher ) delete theNodeSearcher; theNodeSearcher = 0;
171 if ( theElementSearcher ) delete theElementSearcher; theElementSearcher = 0;
173 typedef map < int, SMESH_subMesh * > TDependsOnMap;
174 //!< The meshod called by submesh: do my main job
175 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
176 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
178 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
180 Unset( sm->GetFather() );
183 //!< set self on all submeshes and delete theNodeSearcher if other mesh is set
184 void Set(SMESH_Mesh* mesh)
186 if ( myMesh != mesh )
193 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
194 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
195 TDependsOnMap::const_iterator sm;
196 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
197 sm->second->SetEventListener( this, 0, sm->second );
201 //!< delete self from all submeshes
202 void Unset(SMESH_Mesh* mesh)
204 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
205 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
206 TDependsOnMap::const_iterator sm;
207 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
208 sm->second->DeleteEventListener( this );
213 } theSearchersDeleter;
215 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
217 TCollection_AsciiString typeStr;
218 switch ( theMirrorType ) {
219 case SMESH::SMESH_MeshEditor::POINT:
220 typeStr = "SMESH.SMESH_MeshEditor.POINT";
222 case SMESH::SMESH_MeshEditor::AXIS:
223 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
226 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
232 //=============================================================================
236 //=============================================================================
238 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
241 myMesh = & theMesh->GetImpl();
242 myPreviewMode = isPreview;
245 //================================================================================
249 //================================================================================
251 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
255 //================================================================================
257 * \brief Clear members
259 //================================================================================
261 void SMESH_MeshEditor_i::initData(bool deleteSearchers)
263 if ( myPreviewMode ) {
264 myPreviewData = new SMESH::MeshPreviewStruct();
267 myLastCreatedElems = new SMESH::long_array();
268 myLastCreatedNodes = new SMESH::long_array();
269 if ( deleteSearchers )
270 TSearchersDeleter::Delete();
274 //=======================================================================
275 //function : MakeIDSource
276 //purpose : Wrap a sequence of ids in a SMESH_IDSource
277 //=======================================================================
279 struct _IDSource : public POA_SMESH::SMESH_IDSource
281 SMESH::long_array _ids;
282 SMESH::long_array* GetIDs() { return & _ids; }
283 SMESH::long_array* GetMeshInfo() { return 0; }
286 SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_array& ids)
288 _IDSource* anIDSource = new _IDSource;
289 anIDSource->_ids = ids;
290 SMESH::SMESH_IDSource_var anIDSourceVar = anIDSource->_this();
292 return anIDSourceVar._retn();
295 //=============================================================================
299 //=============================================================================
302 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
306 ::SMESH_MeshEditor anEditor( myMesh );
309 for (int i = 0; i < IDsOfElements.length(); i++)
310 IdList.push_back( IDsOfElements[i] );
312 // Update Python script
313 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
315 TPythonDump() << "print 'RemoveElements: ', isDone";
318 return anEditor.Remove( IdList, false );
321 //=============================================================================
325 //=============================================================================
327 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
331 ::SMESH_MeshEditor anEditor( myMesh );
333 for (int i = 0; i < IDsOfNodes.length(); i++)
334 IdList.push_back( IDsOfNodes[i] );
336 // Update Python script
337 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
339 TPythonDump() << "print 'RemoveNodes: ', isDone";
342 return anEditor.Remove( IdList, true );
345 //=============================================================================
349 //=============================================================================
351 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
352 CORBA::Double y, CORBA::Double z)
356 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
358 // Update Python script
359 TPythonDump() << "nodeID = " << this << ".AddNode( "
360 << x << ", " << y << ", " << z << " )";
365 //=============================================================================
369 //=============================================================================
370 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
374 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
375 SMDS_MeshElement* elem = GetMeshDS()->Add0DElement(aNode);
377 // Update Python script
378 TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
381 return elem->GetID();
386 //=============================================================================
390 //=============================================================================
392 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
396 int NbNodes = IDsOfNodes.length();
397 SMDS_MeshElement* elem = 0;
400 CORBA::Long index1 = IDsOfNodes[0];
401 CORBA::Long index2 = IDsOfNodes[1];
402 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
404 // Update Python script
405 TPythonDump() << "edge = " << this << ".AddEdge([ "
406 << index1 << ", " << index2 <<" ])";
409 CORBA::Long n1 = IDsOfNodes[0];
410 CORBA::Long n2 = IDsOfNodes[1];
411 CORBA::Long n12 = IDsOfNodes[2];
412 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
413 GetMeshDS()->FindNode(n2),
414 GetMeshDS()->FindNode(n12));
415 // Update Python script
416 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
417 <<n1<<", "<<n2<<", "<<n12<<" ])";
421 return elem->GetID();
426 //=============================================================================
430 //=============================================================================
432 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
436 int NbNodes = IDsOfNodes.length();
442 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
443 for (int i = 0; i < NbNodes; i++)
444 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
446 SMDS_MeshElement* elem = 0;
448 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
450 else if (NbNodes == 4) {
451 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
453 else if (NbNodes == 6) {
454 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
457 else if (NbNodes == 8) {
458 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
459 nodes[4], nodes[5], nodes[6], nodes[7]);
461 else if (NbNodes > 2) {
462 elem = GetMeshDS()->AddPolygonalFace(nodes);
465 // Update Python script
466 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
469 return elem->GetID();
474 //=============================================================================
478 //=============================================================================
479 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsOfNodes)
483 int NbNodes = IDsOfNodes.length();
484 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
485 for (int i = 0; i < NbNodes; i++)
486 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
488 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
490 // Update Python script
491 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
493 TPythonDump() << "print 'AddPolygonalFace: ', faceID";
497 return elem->GetID();
502 //=============================================================================
506 //=============================================================================
508 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
512 int NbNodes = IDsOfNodes.length();
513 vector< const SMDS_MeshNode*> n(NbNodes);
514 for(int i=0;i<NbNodes;i++)
515 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
517 SMDS_MeshElement* elem = 0;
520 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
521 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
522 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
523 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
524 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
525 n[6],n[7],n[8],n[9]);
527 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
528 n[7],n[8],n[9],n[10],n[11],n[12]);
530 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
531 n[9],n[10],n[11],n[12],n[13],n[14]);
533 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
534 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
535 n[15],n[16],n[17],n[18],n[19]);
539 // Update Python script
540 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
542 TPythonDump() << "print 'AddVolume: ', volID";
546 return elem->GetID();
551 //=============================================================================
553 * AddPolyhedralVolume
555 //=============================================================================
556 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume (const SMESH::long_array & IDsOfNodes,
557 const SMESH::long_array & Quantities)
561 int NbNodes = IDsOfNodes.length();
562 std::vector<const SMDS_MeshNode*> n (NbNodes);
563 for (int i = 0; i < NbNodes; i++)
564 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
566 int NbFaces = Quantities.length();
567 std::vector<int> q (NbFaces);
568 for (int j = 0; j < NbFaces; j++)
569 q[j] = Quantities[j];
571 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
573 // Update Python script
574 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
575 << IDsOfNodes << ", " << Quantities << " )";
577 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
581 return elem->GetID();
586 //=============================================================================
588 * AddPolyhedralVolumeByFaces
590 //=============================================================================
591 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_array & IdsOfFaces)
595 int NbFaces = IdsOfFaces.length();
596 std::vector<const SMDS_MeshNode*> poly_nodes;
597 std::vector<int> quantities (NbFaces);
599 for (int i = 0; i < NbFaces; i++) {
600 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
601 quantities[i] = aFace->NbNodes();
603 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
605 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
609 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
611 // Update Python script
612 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
613 << IdsOfFaces << " )";
615 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
619 return elem->GetID();
624 //=============================================================================
626 * \brief Bind a node to a vertex
627 * \param NodeID - node ID
628 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
629 * \retval boolean - false if NodeID or VertexID is invalid
631 //=============================================================================
633 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
634 throw (SALOME::SALOME_Exception)
636 Unexpect aCatch(SALOME_SalomeException);
638 SMESHDS_Mesh * mesh = GetMeshDS();
639 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
641 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
643 if ( mesh->MaxShapeIndex() < VertexID )
644 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
646 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
647 if ( shape.ShapeType() != TopAbs_VERTEX )
648 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
650 mesh->SetNodeOnVertex( node, VertexID );
653 //=============================================================================
655 * \brief Store node position on an edge
656 * \param NodeID - node ID
657 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
658 * \param paramOnEdge - parameter on edge where the node is located
659 * \retval boolean - false if any parameter is invalid
661 //=============================================================================
663 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
664 CORBA::Double paramOnEdge)
665 throw (SALOME::SALOME_Exception)
667 Unexpect aCatch(SALOME_SalomeException);
669 SMESHDS_Mesh * mesh = GetMeshDS();
670 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
672 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
674 if ( mesh->MaxShapeIndex() < EdgeID )
675 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
677 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
678 if ( shape.ShapeType() != TopAbs_EDGE )
679 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
682 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
683 if ( paramOnEdge < f || paramOnEdge > l )
684 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
686 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
689 //=============================================================================
691 * \brief Store node position on a face
692 * \param NodeID - node ID
693 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
694 * \param u - U parameter on face where the node is located
695 * \param v - V parameter on face where the node is located
696 * \retval boolean - false if any parameter is invalid
698 //=============================================================================
700 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
701 CORBA::Double u, CORBA::Double v)
702 throw (SALOME::SALOME_Exception)
704 Unexpect aCatch(SALOME_SalomeException);
706 SMESHDS_Mesh * mesh = GetMeshDS();
707 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
709 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
711 if ( mesh->MaxShapeIndex() < FaceID )
712 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
714 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
715 if ( shape.ShapeType() != TopAbs_FACE )
716 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
718 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
719 bool isOut = ( u < surf.FirstUParameter() ||
720 u > surf.LastUParameter() ||
721 v < surf.FirstVParameter() ||
722 v > surf.LastVParameter() );
726 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
727 << " u( " << surf.FirstUParameter()
728 << "," << surf.LastUParameter()
729 << ") v( " << surf.FirstVParameter()
730 << "," << surf.LastVParameter() << ")" );
732 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
735 mesh->SetNodeOnFace( node, FaceID, u, v );
738 //=============================================================================
740 * \brief Bind a node to a solid
741 * \param NodeID - node ID
742 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
743 * \retval boolean - false if NodeID or SolidID is invalid
745 //=============================================================================
747 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
748 throw (SALOME::SALOME_Exception)
750 Unexpect aCatch(SALOME_SalomeException);
752 SMESHDS_Mesh * mesh = GetMeshDS();
753 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
755 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
757 if ( mesh->MaxShapeIndex() < SolidID )
758 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
760 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
761 if ( shape.ShapeType() != TopAbs_SOLID &&
762 shape.ShapeType() != TopAbs_SHELL)
763 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
765 mesh->SetNodeInVolume( node, SolidID );
768 //=============================================================================
770 * \brief Bind an element to a shape
771 * \param ElementID - element ID
772 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
773 * \retval boolean - false if ElementID or ShapeID is invalid
775 //=============================================================================
777 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
779 throw (SALOME::SALOME_Exception)
781 Unexpect aCatch(SALOME_SalomeException);
783 SMESHDS_Mesh * mesh = GetMeshDS();
784 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
786 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
788 if ( mesh->MaxShapeIndex() < ShapeID )
789 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
791 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
792 if ( shape.ShapeType() != TopAbs_EDGE &&
793 shape.ShapeType() != TopAbs_FACE &&
794 shape.ShapeType() != TopAbs_SOLID &&
795 shape.ShapeType() != TopAbs_SHELL )
796 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
798 mesh->SetMeshElementOnShape( elem, ShapeID );
801 //=============================================================================
805 //=============================================================================
807 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
812 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
813 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
817 // Update Python script
818 TPythonDump() << "isDone = " << this << ".InverseDiag( "
819 << NodeID1 << ", " << NodeID2 << " )";
821 ::SMESH_MeshEditor aMeshEditor( myMesh );
822 return aMeshEditor.InverseDiag ( n1, n2 );
825 //=============================================================================
829 //=============================================================================
831 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
836 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
837 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
841 // Update Python script
842 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
843 << NodeID1 << ", " << NodeID2 << " )";
845 ::SMESH_MeshEditor aMeshEditor( myMesh );
847 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
849 storeResult(aMeshEditor);
854 //=============================================================================
858 //=============================================================================
860 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
864 ::SMESH_MeshEditor anEditor( myMesh );
865 for (int i = 0; i < IDsOfElements.length(); i++)
867 CORBA::Long index = IDsOfElements[i];
868 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
870 anEditor.Reorient( elem );
872 // Update Python script
873 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
879 //=============================================================================
883 //=============================================================================
885 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
889 SMESH::long_array_var anElementsId = theObject->GetIDs();
890 CORBA::Boolean isDone = Reorient(anElementsId);
892 // Clear python line, created by Reorient()
893 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
894 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
896 // Update Python script
897 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
904 //================================================================================
906 * \brief function for conversion long_array to TIDSortedElemSet
907 * \param IDs - array of IDs
908 * \param aMesh - mesh
909 * \param aMap - collection to fill
910 * \param aType - element type
912 //================================================================================
914 void arrayToSet(const SMESH::long_array & IDs,
915 const SMESHDS_Mesh* aMesh,
916 TIDSortedElemSet& aMap,
917 const SMDSAbs_ElementType aType = SMDSAbs_All )
919 for (int i=0; i<IDs.length(); i++) {
920 CORBA::Long ind = IDs[i];
921 const SMDS_MeshElement * elem =
922 (aType == SMDSAbs_Node ? aMesh->FindNode(ind)
923 : aMesh->FindElement(ind));
924 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
930 //=============================================================================
934 //=============================================================================
935 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
936 SMESH::NumericalFunctor_ptr Criterion,
937 CORBA::Double MaxAngle)
941 SMESHDS_Mesh* aMesh = GetMeshDS();
942 TIDSortedElemSet faces;
943 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
945 SMESH::NumericalFunctor_i* aNumericalFunctor =
946 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
947 SMESH::Controls::NumericalFunctorPtr aCrit;
948 if ( !aNumericalFunctor )
949 aCrit.reset( new SMESH::Controls::AspectRatio() );
951 aCrit = aNumericalFunctor->GetNumericalFunctor();
953 // Update Python script
954 TPythonDump() << "isDone = " << this << ".TriToQuad( "
955 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
957 TPythonDump() << "print 'TriToQuad: ', isDone";
960 ::SMESH_MeshEditor anEditor( myMesh );
962 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
964 storeResult(anEditor);
970 //=============================================================================
974 //=============================================================================
975 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
976 SMESH::NumericalFunctor_ptr Criterion,
977 CORBA::Double MaxAngle)
981 SMESH::long_array_var anElementsId = theObject->GetIDs();
982 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
984 // Clear python line(s), created by TriToQuad()
985 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
986 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
988 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
991 SMESH::NumericalFunctor_i* aNumericalFunctor =
992 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
994 // Update Python script
995 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
996 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
998 TPythonDump() << "print 'TriToQuadObject: ', isDone";
1005 //=============================================================================
1009 //=============================================================================
1010 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
1011 SMESH::NumericalFunctor_ptr Criterion)
1015 SMESHDS_Mesh* aMesh = GetMeshDS();
1016 TIDSortedElemSet faces;
1017 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1019 SMESH::NumericalFunctor_i* aNumericalFunctor =
1020 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1021 SMESH::Controls::NumericalFunctorPtr aCrit;
1022 if ( !aNumericalFunctor )
1023 aCrit.reset( new SMESH::Controls::AspectRatio() );
1025 aCrit = aNumericalFunctor->GetNumericalFunctor();
1028 // Update Python script
1029 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1031 TPythonDump() << "print 'QuadToTri: ', isDone";
1034 ::SMESH_MeshEditor anEditor( myMesh );
1035 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1037 storeResult(anEditor);
1043 //=============================================================================
1047 //=============================================================================
1048 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1049 SMESH::NumericalFunctor_ptr Criterion)
1053 SMESH::long_array_var anElementsId = theObject->GetIDs();
1054 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1056 // Clear python line(s), created by QuadToTri()
1057 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1058 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1060 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1063 SMESH::NumericalFunctor_i* aNumericalFunctor =
1064 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1066 // Update Python script
1067 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1069 TPythonDump() << "print 'QuadToTriObject: ', isDone";
1076 //=============================================================================
1080 //=============================================================================
1081 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1082 CORBA::Boolean Diag13)
1086 SMESHDS_Mesh* aMesh = GetMeshDS();
1087 TIDSortedElemSet faces;
1088 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1090 // Update Python script
1091 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1092 << IDsOfElements << ", " << Diag13 << " )";
1094 TPythonDump() << "print 'SplitQuad: ', isDone";
1097 ::SMESH_MeshEditor anEditor( myMesh );
1098 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1100 storeResult(anEditor);
1106 //=============================================================================
1110 //=============================================================================
1111 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1112 CORBA::Boolean Diag13)
1116 SMESH::long_array_var anElementsId = theObject->GetIDs();
1117 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1119 // Clear python line(s), created by SplitQuad()
1120 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1121 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1123 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1126 // Update Python script
1127 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1128 << theObject << ", " << Diag13 << " )";
1130 TPythonDump() << "print 'SplitQuadObject: ', isDone";
1137 //=============================================================================
1141 //=============================================================================
1142 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1143 SMESH::NumericalFunctor_ptr Criterion)
1145 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1146 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1148 SMESH::NumericalFunctor_i* aNumericalFunctor =
1149 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1150 SMESH::Controls::NumericalFunctorPtr aCrit;
1151 if (aNumericalFunctor)
1152 aCrit = aNumericalFunctor->GetNumericalFunctor();
1154 aCrit.reset(new SMESH::Controls::AspectRatio());
1156 ::SMESH_MeshEditor anEditor (myMesh);
1157 return anEditor.BestSplit(quad, aCrit);
1163 //=======================================================================
1166 //=======================================================================
1169 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1170 const SMESH::long_array & IDsOfFixedNodes,
1171 CORBA::Long MaxNbOfIterations,
1172 CORBA::Double MaxAspectRatio,
1173 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1175 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1176 MaxAspectRatio, Method, false );
1180 //=======================================================================
1181 //function : SmoothParametric
1183 //=======================================================================
1186 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1187 const SMESH::long_array & IDsOfFixedNodes,
1188 CORBA::Long MaxNbOfIterations,
1189 CORBA::Double MaxAspectRatio,
1190 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1192 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1193 MaxAspectRatio, Method, true );
1197 //=======================================================================
1198 //function : SmoothObject
1200 //=======================================================================
1203 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1204 const SMESH::long_array & IDsOfFixedNodes,
1205 CORBA::Long MaxNbOfIterations,
1206 CORBA::Double MaxAspectRatio,
1207 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1209 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1210 MaxAspectRatio, Method, false);
1214 //=======================================================================
1215 //function : SmoothParametricObject
1217 //=======================================================================
1220 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1221 const SMESH::long_array & IDsOfFixedNodes,
1222 CORBA::Long MaxNbOfIterations,
1223 CORBA::Double MaxAspectRatio,
1224 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1226 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1227 MaxAspectRatio, Method, true);
1231 //=============================================================================
1235 //=============================================================================
1238 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1239 const SMESH::long_array & IDsOfFixedNodes,
1240 CORBA::Long MaxNbOfIterations,
1241 CORBA::Double MaxAspectRatio,
1242 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1247 SMESHDS_Mesh* aMesh = GetMeshDS();
1249 TIDSortedElemSet elements;
1250 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1252 set<const SMDS_MeshNode*> fixedNodes;
1253 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1254 CORBA::Long index = IDsOfFixedNodes[i];
1255 const SMDS_MeshNode * node = aMesh->FindNode(index);
1257 fixedNodes.insert( node );
1259 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1260 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1261 method = ::SMESH_MeshEditor::CENTROIDAL;
1263 ::SMESH_MeshEditor anEditor( myMesh );
1264 anEditor.Smooth(elements, fixedNodes, method,
1265 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1267 storeResult(anEditor);
1269 // Update Python script
1270 TPythonDump() << "isDone = " << this << "."
1271 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1272 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1273 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1274 << "SMESH.SMESH_MeshEditor."
1275 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1276 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1278 TPythonDump() << "print 'Smooth: ', isDone";
1285 //=============================================================================
1289 //=============================================================================
1292 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1293 const SMESH::long_array & IDsOfFixedNodes,
1294 CORBA::Long MaxNbOfIterations,
1295 CORBA::Double MaxAspectRatio,
1296 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1301 SMESH::long_array_var anElementsId = theObject->GetIDs();
1302 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1303 MaxAspectRatio, Method, IsParametric);
1305 // Clear python line(s), created by Smooth()
1306 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1307 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1309 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1312 // Update Python script
1313 TPythonDump() << "isDone = " << this << "."
1314 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1315 << theObject << ", " << IDsOfFixedNodes << ", "
1316 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1317 << "SMESH.SMESH_MeshEditor."
1318 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1319 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1321 TPythonDump() << "print 'SmoothObject: ', isDone";
1328 //=============================================================================
1332 //=============================================================================
1334 void SMESH_MeshEditor_i::RenumberNodes()
1336 // Update Python script
1337 TPythonDump() << this << ".RenumberNodes()";
1339 GetMeshDS()->Renumber( true );
1343 //=============================================================================
1347 //=============================================================================
1349 void SMESH_MeshEditor_i::RenumberElements()
1351 // Update Python script
1352 TPythonDump() << this << ".RenumberElements()";
1354 GetMeshDS()->Renumber( false );
1357 //=======================================================================
1359 * \brief Return groups by their IDs
1361 //=======================================================================
1363 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1367 myMesh_i->CreateGroupServants();
1368 return myMesh_i->GetGroups( *groupIDs );
1371 //=======================================================================
1372 //function : rotationSweep
1374 //=======================================================================
1376 SMESH::ListOfGroups*
1377 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1378 const SMESH::AxisStruct & theAxis,
1379 CORBA::Double theAngleInRadians,
1380 CORBA::Long theNbOfSteps,
1381 CORBA::Double theTolerance,
1382 const bool theMakeGroups,
1383 const SMDSAbs_ElementType theElementType)
1387 TIDSortedElemSet inElements, copyElements;
1388 arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType);
1390 TIDSortedElemSet* workElements = & inElements;
1391 TPreviewMesh tmpMesh( SMDSAbs_Face );
1392 SMESH_Mesh* mesh = 0;
1393 bool makeWalls=true;
1394 if ( myPreviewMode )
1396 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1397 tmpMesh.Copy( inElements, copyElements, select, avoid );
1399 workElements = & copyElements;
1400 //makeWalls = false;
1407 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1408 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1410 ::SMESH_MeshEditor anEditor( mesh );
1411 ::SMESH_MeshEditor::PGroupIDs groupIds =
1412 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1413 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1414 storeResult(anEditor);
1416 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1419 //=======================================================================
1420 //function : RotationSweep
1422 //=======================================================================
1424 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1425 const SMESH::AxisStruct & theAxis,
1426 CORBA::Double theAngleInRadians,
1427 CORBA::Long theNbOfSteps,
1428 CORBA::Double theTolerance)
1430 if ( !myPreviewMode ) {
1431 TPythonDump() << this << ".RotationSweep( "
1432 << theIDsOfElements << ", "
1434 << theAngleInRadians << ", "
1435 << theNbOfSteps << ", "
1436 << theTolerance << " )";
1438 rotationSweep(theIDsOfElements,
1446 //=======================================================================
1447 //function : RotationSweepMakeGroups
1449 //=======================================================================
1451 SMESH::ListOfGroups*
1452 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1453 const SMESH::AxisStruct& theAxis,
1454 CORBA::Double theAngleInRadians,
1455 CORBA::Long theNbOfSteps,
1456 CORBA::Double theTolerance)
1458 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1464 if ( !myPreviewMode ) {
1465 TPythonDump aPythonDump;
1466 DumpGroupsList(aPythonDump,aGroups);
1467 aPythonDump<< this << ".RotationSweepMakeGroups( "
1468 << theIDsOfElements << ", "
1470 << theAngleInRadians << ", "
1471 << theNbOfSteps << ", "
1472 << theTolerance << " )";
1477 //=======================================================================
1478 //function : RotationSweepObject
1480 //=======================================================================
1482 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1483 const SMESH::AxisStruct & theAxis,
1484 CORBA::Double theAngleInRadians,
1485 CORBA::Long theNbOfSteps,
1486 CORBA::Double theTolerance)
1488 if ( !myPreviewMode ) {
1489 TPythonDump() << this << ".RotationSweepObject( "
1490 << theObject << ", "
1492 << theAngleInRadians << ", "
1493 << theNbOfSteps << ", "
1494 << theTolerance << " )";
1496 SMESH::long_array_var anElementsId = theObject->GetIDs();
1497 rotationSweep(anElementsId,
1505 //=======================================================================
1506 //function : RotationSweepObject1D
1508 //=======================================================================
1510 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1511 const SMESH::AxisStruct & theAxis,
1512 CORBA::Double theAngleInRadians,
1513 CORBA::Long theNbOfSteps,
1514 CORBA::Double theTolerance)
1516 if ( !myPreviewMode ) {
1517 TPythonDump() << this << ".RotationSweepObject1D( "
1518 << theObject << ", "
1520 << theAngleInRadians << ", "
1521 << theNbOfSteps << ", "
1522 << theTolerance << " )";
1524 SMESH::long_array_var anElementsId = theObject->GetIDs();
1525 rotationSweep(anElementsId,
1534 //=======================================================================
1535 //function : RotationSweepObject2D
1537 //=======================================================================
1539 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1540 const SMESH::AxisStruct & theAxis,
1541 CORBA::Double theAngleInRadians,
1542 CORBA::Long theNbOfSteps,
1543 CORBA::Double theTolerance)
1545 if ( !myPreviewMode ) {
1546 TPythonDump() << this << ".RotationSweepObject2D( "
1547 << theObject << ", "
1549 << theAngleInRadians << ", "
1550 << theNbOfSteps << ", "
1551 << theTolerance << " )";
1553 SMESH::long_array_var anElementsId = theObject->GetIDs();
1554 rotationSweep(anElementsId,
1563 //=======================================================================
1564 //function : RotationSweepObjectMakeGroups
1566 //=======================================================================
1568 SMESH::ListOfGroups*
1569 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1570 const SMESH::AxisStruct& theAxis,
1571 CORBA::Double theAngleInRadians,
1572 CORBA::Long theNbOfSteps,
1573 CORBA::Double theTolerance)
1575 SMESH::long_array_var anElementsId = theObject->GetIDs();
1576 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1582 if ( !myPreviewMode ) {
1583 TPythonDump aPythonDump;
1584 DumpGroupsList(aPythonDump,aGroups);
1585 aPythonDump<< this << ".RotationSweepObjectMakeGroups( "
1586 << theObject << ", "
1588 << theAngleInRadians << ", "
1589 << theNbOfSteps << ", "
1590 << theTolerance << " )";
1595 //=======================================================================
1596 //function : RotationSweepObject1DMakeGroups
1598 //=======================================================================
1600 SMESH::ListOfGroups*
1601 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1602 const SMESH::AxisStruct& theAxis,
1603 CORBA::Double theAngleInRadians,
1604 CORBA::Long theNbOfSteps,
1605 CORBA::Double theTolerance)
1607 SMESH::long_array_var anElementsId = theObject->GetIDs();
1608 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1615 if ( !myPreviewMode ) {
1616 TPythonDump aPythonDump;
1617 DumpGroupsList(aPythonDump,aGroups);
1618 aPythonDump<< this << ".RotationSweepObject1DMakeGroups( "
1619 << theObject << ", "
1621 << theAngleInRadians << ", "
1622 << theNbOfSteps << ", "
1623 << theTolerance << " )";
1628 //=======================================================================
1629 //function : RotationSweepObject2DMakeGroups
1631 //=======================================================================
1633 SMESH::ListOfGroups*
1634 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1635 const SMESH::AxisStruct& theAxis,
1636 CORBA::Double theAngleInRadians,
1637 CORBA::Long theNbOfSteps,
1638 CORBA::Double theTolerance)
1640 SMESH::long_array_var anElementsId = theObject->GetIDs();
1641 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1648 if ( !myPreviewMode ) {
1649 TPythonDump aPythonDump;
1650 DumpGroupsList(aPythonDump,aGroups);
1651 aPythonDump<< this << ".RotationSweepObject2DMakeGroups( "
1652 << theObject << ", "
1654 << theAngleInRadians << ", "
1655 << theNbOfSteps << ", "
1656 << theTolerance << " )";
1662 //=======================================================================
1663 //function : extrusionSweep
1665 //=======================================================================
1667 SMESH::ListOfGroups*
1668 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1669 const SMESH::DirStruct & theStepVector,
1670 CORBA::Long theNbOfSteps,
1671 const bool theMakeGroups,
1672 const SMDSAbs_ElementType theElementType)
1680 TIDSortedElemSet elements;
1681 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1683 const SMESH::PointStruct * P = &theStepVector.PS;
1684 gp_Vec stepVec( P->x, P->y, P->z );
1686 TElemOfElemListMap aHystory;
1687 ::SMESH_MeshEditor anEditor( myMesh );
1688 ::SMESH_MeshEditor::PGroupIDs groupIds =
1689 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1691 storeResult(anEditor);
1693 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1695 } catch(Standard_Failure) {
1696 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1697 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1702 //=======================================================================
1703 //function : ExtrusionSweep
1705 //=======================================================================
1707 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1708 const SMESH::DirStruct & theStepVector,
1709 CORBA::Long theNbOfSteps)
1711 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1712 if ( !myPreviewMode ) {
1713 TPythonDump() << this << ".ExtrusionSweep( "
1714 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1719 //=======================================================================
1720 //function : ExtrusionSweepObject
1722 //=======================================================================
1724 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1725 const SMESH::DirStruct & theStepVector,
1726 CORBA::Long theNbOfSteps)
1728 SMESH::long_array_var anElementsId = theObject->GetIDs();
1729 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1730 if ( !myPreviewMode ) {
1731 TPythonDump() << this << ".ExtrusionSweepObject( "
1732 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1736 //=======================================================================
1737 //function : ExtrusionSweepObject1D
1739 //=======================================================================
1741 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1742 const SMESH::DirStruct & theStepVector,
1743 CORBA::Long theNbOfSteps)
1745 SMESH::long_array_var anElementsId = theObject->GetIDs();
1746 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1747 if ( !myPreviewMode ) {
1748 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1749 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1753 //=======================================================================
1754 //function : ExtrusionSweepObject2D
1756 //=======================================================================
1758 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1759 const SMESH::DirStruct & theStepVector,
1760 CORBA::Long theNbOfSteps)
1762 SMESH::long_array_var anElementsId = theObject->GetIDs();
1763 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1764 if ( !myPreviewMode ) {
1765 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1766 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1770 //=======================================================================
1771 //function : ExtrusionSweepMakeGroups
1773 //=======================================================================
1775 SMESH::ListOfGroups*
1776 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1777 const SMESH::DirStruct& theStepVector,
1778 CORBA::Long theNbOfSteps)
1780 SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1782 if ( !myPreviewMode ) {
1783 TPythonDump aPythonDump;
1784 DumpGroupsList(aPythonDump,aGroups);
1785 aPythonDump << this << ".ExtrusionSweepMakeGroups( "
1786 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1790 //=======================================================================
1791 //function : ExtrusionSweepObjectMakeGroups
1793 //=======================================================================
1795 SMESH::ListOfGroups*
1796 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1797 const SMESH::DirStruct& theStepVector,
1798 CORBA::Long theNbOfSteps)
1800 SMESH::long_array_var anElementsId = theObject->GetIDs();
1801 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1803 if ( !myPreviewMode ) {
1804 TPythonDump aPythonDump;
1805 DumpGroupsList(aPythonDump,aGroups);
1806 aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( "
1807 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1812 //=======================================================================
1813 //function : ExtrusionSweepObject1DMakeGroups
1815 //=======================================================================
1817 SMESH::ListOfGroups*
1818 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1819 const SMESH::DirStruct& theStepVector,
1820 CORBA::Long theNbOfSteps)
1822 SMESH::long_array_var anElementsId = theObject->GetIDs();
1823 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1824 if ( !myPreviewMode ) {
1825 TPythonDump aPythonDump;
1826 DumpGroupsList(aPythonDump,aGroups);
1827 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( "
1828 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1833 //=======================================================================
1834 //function : ExtrusionSweepObject2DMakeGroups
1836 //=======================================================================
1838 SMESH::ListOfGroups*
1839 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1840 const SMESH::DirStruct& theStepVector,
1841 CORBA::Long theNbOfSteps)
1843 SMESH::long_array_var anElementsId = theObject->GetIDs();
1844 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1845 if ( !myPreviewMode ) {
1846 TPythonDump aPythonDump;
1847 DumpGroupsList(aPythonDump,aGroups);
1848 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( "
1849 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1855 //=======================================================================
1856 //function : advancedExtrusion
1858 //=======================================================================
1860 SMESH::ListOfGroups*
1861 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1862 const SMESH::DirStruct & theStepVector,
1863 CORBA::Long theNbOfSteps,
1864 CORBA::Long theExtrFlags,
1865 CORBA::Double theSewTolerance,
1866 const bool theMakeGroups)
1870 TIDSortedElemSet elements;
1871 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1873 const SMESH::PointStruct * P = &theStepVector.PS;
1874 gp_Vec stepVec( P->x, P->y, P->z );
1876 ::SMESH_MeshEditor anEditor( myMesh );
1877 TElemOfElemListMap aHystory;
1878 ::SMESH_MeshEditor::PGroupIDs groupIds =
1879 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1880 theMakeGroups, theExtrFlags, theSewTolerance);
1881 storeResult(anEditor);
1883 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1886 //=======================================================================
1887 //function : AdvancedExtrusion
1889 //=======================================================================
1891 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1892 const SMESH::DirStruct & theStepVector,
1893 CORBA::Long theNbOfSteps,
1894 CORBA::Long theExtrFlags,
1895 CORBA::Double theSewTolerance)
1897 if ( !myPreviewMode ) {
1898 TPythonDump() << "stepVector = " << theStepVector;
1899 TPythonDump() << this << ".AdvancedExtrusion("
1902 << theNbOfSteps << ","
1903 << theExtrFlags << ", "
1904 << theSewTolerance << " )";
1906 advancedExtrusion( theIDsOfElements,
1914 //=======================================================================
1915 //function : AdvancedExtrusionMakeGroups
1917 //=======================================================================
1919 SMESH::ListOfGroups*
1920 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1921 const SMESH::DirStruct& theStepVector,
1922 CORBA::Long theNbOfSteps,
1923 CORBA::Long theExtrFlags,
1924 CORBA::Double theSewTolerance)
1926 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
1933 if ( !myPreviewMode ) {
1934 TPythonDump() << "stepVector = " << theStepVector;
1935 TPythonDump aPythonDump;
1936 DumpGroupsList(aPythonDump,aGroups);
1937 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
1940 << theNbOfSteps << ","
1941 << theExtrFlags << ", "
1942 << theSewTolerance << " )";
1948 //================================================================================
1950 * \brief Convert extrusion error to IDL enum
1952 //================================================================================
1954 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1956 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1960 RETCASE( EXTR_NO_ELEMENTS );
1961 RETCASE( EXTR_PATH_NOT_EDGE );
1962 RETCASE( EXTR_BAD_PATH_SHAPE );
1963 RETCASE( EXTR_BAD_STARTING_NODE );
1964 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1965 RETCASE( EXTR_CANT_GET_TANGENT );
1967 return SMESH::SMESH_MeshEditor::EXTR_OK;
1971 //=======================================================================
1972 //function : extrusionAlongPath
1974 //=======================================================================
1976 SMESH::ListOfGroups*
1977 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1978 SMESH::SMESH_Mesh_ptr thePathMesh,
1979 GEOM::GEOM_Object_ptr thePathShape,
1980 CORBA::Long theNodeStart,
1981 CORBA::Boolean theHasAngles,
1982 const SMESH::double_array & theAngles,
1983 CORBA::Boolean theHasRefPoint,
1984 const SMESH::PointStruct & theRefPoint,
1985 const bool theMakeGroups,
1986 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
1987 const SMDSAbs_ElementType theElementType)
1991 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1992 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1995 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1997 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1998 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2000 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
2001 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2005 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
2007 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2011 TIDSortedElemSet elements;
2012 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
2014 list<double> angles;
2015 for (int i = 0; i < theAngles.length(); i++) {
2016 angles.push_back( theAngles[i] );
2019 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
2021 int nbOldGroups = myMesh->NbGroup();
2023 ::SMESH_MeshEditor anEditor( myMesh );
2024 ::SMESH_MeshEditor::Extrusion_Error error =
2025 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
2026 theHasAngles, angles, false,
2027 theHasRefPoint, refPnt, theMakeGroups );
2028 storeResult(anEditor);
2029 theError = convExtrError( error );
2031 if ( theMakeGroups ) {
2032 list<int> groupIDs = myMesh->GetGroupIds();
2033 list<int>::iterator newBegin = groupIDs.begin();
2034 std::advance( newBegin, nbOldGroups ); // skip old groups
2035 groupIDs.erase( groupIDs.begin(), newBegin );
2036 return getGroups( & groupIDs );
2042 //=======================================================================
2043 //function : extrusionAlongPathX
2045 //=======================================================================
2047 SMESH::ListOfGroups*
2048 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2049 SMESH::SMESH_IDSource_ptr Path,
2050 CORBA::Long NodeStart,
2051 CORBA::Boolean HasAngles,
2052 const SMESH::double_array& Angles,
2053 CORBA::Boolean LinearVariation,
2054 CORBA::Boolean HasRefPoint,
2055 const SMESH::PointStruct& RefPoint,
2056 const bool MakeGroups,
2057 const SMDSAbs_ElementType ElementType,
2058 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2060 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2064 list<double> angles;
2065 for (int i = 0; i < Angles.length(); i++) {
2066 angles.push_back( Angles[i] );
2068 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2069 int nbOldGroups = myMesh->NbGroup();
2071 if ( Path->_is_nil() ) {
2072 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2076 TIDSortedElemSet elements;
2077 arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
2079 ::SMESH_MeshEditor anEditor( myMesh );
2080 ::SMESH_MeshEditor::Extrusion_Error error;
2082 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
2085 SMDS_MeshNode* aNodeStart =
2086 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2087 if ( !aNodeStart ) {
2088 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2091 error = anEditor.ExtrusionAlongTrack( elements, &(aMeshImp->GetImpl()), aNodeStart,
2092 HasAngles, angles, LinearVariation,
2093 HasRefPoint, refPnt, MakeGroups );
2096 SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
2099 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
2100 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
2101 SMDS_MeshNode* aNodeStart =
2102 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2103 if ( !aNodeStart ) {
2104 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2107 SMESH_subMesh* aSubMesh =
2108 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
2109 error = anEditor.ExtrusionAlongTrack( elements, aSubMesh, aNodeStart,
2110 HasAngles, angles, LinearVariation,
2111 HasRefPoint, refPnt, MakeGroups );
2114 SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
2116 // path as group of 1D elements
2120 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2126 storeResult(anEditor);
2127 Error = convExtrError( error );
2130 list<int> groupIDs = myMesh->GetGroupIds();
2131 list<int>::iterator newBegin = groupIDs.begin();
2132 std::advance( newBegin, nbOldGroups ); // skip old groups
2133 groupIDs.erase( groupIDs.begin(), newBegin );
2134 return getGroups( & groupIDs );
2140 //=======================================================================
2141 //function : ExtrusionAlongPath
2143 //=======================================================================
2145 SMESH::SMESH_MeshEditor::Extrusion_Error
2146 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2147 SMESH::SMESH_Mesh_ptr thePathMesh,
2148 GEOM::GEOM_Object_ptr thePathShape,
2149 CORBA::Long theNodeStart,
2150 CORBA::Boolean theHasAngles,
2151 const SMESH::double_array & theAngles,
2152 CORBA::Boolean theHasRefPoint,
2153 const SMESH::PointStruct & theRefPoint)
2155 if ( !myPreviewMode ) {
2156 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
2157 << theIDsOfElements << ", "
2158 << thePathMesh << ", "
2159 << thePathShape << ", "
2160 << theNodeStart << ", "
2161 << theHasAngles << ", "
2162 << theAngles << ", "
2163 << theHasRefPoint << ", "
2164 << "SMESH.PointStruct( "
2165 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2166 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2167 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2169 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2170 extrusionAlongPath( theIDsOfElements,
2183 //=======================================================================
2184 //function : ExtrusionAlongPathObject
2186 //=======================================================================
2188 SMESH::SMESH_MeshEditor::Extrusion_Error
2189 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
2190 SMESH::SMESH_Mesh_ptr thePathMesh,
2191 GEOM::GEOM_Object_ptr thePathShape,
2192 CORBA::Long theNodeStart,
2193 CORBA::Boolean theHasAngles,
2194 const SMESH::double_array & theAngles,
2195 CORBA::Boolean theHasRefPoint,
2196 const SMESH::PointStruct & theRefPoint)
2198 if ( !myPreviewMode ) {
2199 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
2200 << theObject << ", "
2201 << thePathMesh << ", "
2202 << thePathShape << ", "
2203 << theNodeStart << ", "
2204 << theHasAngles << ", "
2205 << theAngles << ", "
2206 << theHasRefPoint << ", "
2207 << "SMESH.PointStruct( "
2208 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2209 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2210 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2212 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2213 SMESH::long_array_var anElementsId = theObject->GetIDs();
2214 extrusionAlongPath( anElementsId,
2227 //=======================================================================
2228 //function : ExtrusionAlongPathObject1D
2230 //=======================================================================
2232 SMESH::SMESH_MeshEditor::Extrusion_Error
2233 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
2234 SMESH::SMESH_Mesh_ptr thePathMesh,
2235 GEOM::GEOM_Object_ptr thePathShape,
2236 CORBA::Long theNodeStart,
2237 CORBA::Boolean theHasAngles,
2238 const SMESH::double_array & theAngles,
2239 CORBA::Boolean theHasRefPoint,
2240 const SMESH::PointStruct & theRefPoint)
2242 if ( !myPreviewMode ) {
2243 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
2244 << theObject << ", "
2245 << thePathMesh << ", "
2246 << thePathShape << ", "
2247 << theNodeStart << ", "
2248 << theHasAngles << ", "
2249 << theAngles << ", "
2250 << theHasRefPoint << ", "
2251 << "SMESH.PointStruct( "
2252 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2253 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2254 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2256 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2257 SMESH::long_array_var anElementsId = theObject->GetIDs();
2258 extrusionAlongPath( anElementsId,
2272 //=======================================================================
2273 //function : ExtrusionAlongPathObject2D
2275 //=======================================================================
2277 SMESH::SMESH_MeshEditor::Extrusion_Error
2278 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
2279 SMESH::SMESH_Mesh_ptr thePathMesh,
2280 GEOM::GEOM_Object_ptr thePathShape,
2281 CORBA::Long theNodeStart,
2282 CORBA::Boolean theHasAngles,
2283 const SMESH::double_array & theAngles,
2284 CORBA::Boolean theHasRefPoint,
2285 const SMESH::PointStruct & theRefPoint)
2287 if ( !myPreviewMode ) {
2288 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
2289 << theObject << ", "
2290 << thePathMesh << ", "
2291 << thePathShape << ", "
2292 << theNodeStart << ", "
2293 << theHasAngles << ", "
2294 << theAngles << ", "
2295 << theHasRefPoint << ", "
2296 << "SMESH.PointStruct( "
2297 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2298 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2299 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2301 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2302 SMESH::long_array_var anElementsId = theObject->GetIDs();
2303 extrusionAlongPath( anElementsId,
2318 //=======================================================================
2319 //function : ExtrusionAlongPathMakeGroups
2321 //=======================================================================
2323 SMESH::ListOfGroups*
2324 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2325 SMESH::SMESH_Mesh_ptr thePathMesh,
2326 GEOM::GEOM_Object_ptr thePathShape,
2327 CORBA::Long theNodeStart,
2328 CORBA::Boolean theHasAngles,
2329 const SMESH::double_array& theAngles,
2330 CORBA::Boolean theHasRefPoint,
2331 const SMESH::PointStruct& theRefPoint,
2332 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2334 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2344 if ( !myPreviewMode ) {
2345 bool isDumpGroups = aGroups && aGroups->length() > 0;
2346 TPythonDump aPythonDump;
2348 aPythonDump << "("<<aGroups;
2351 aPythonDump << ", error)";
2353 aPythonDump <<"error";
2355 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2356 << theIDsOfElements << ", "
2357 << thePathMesh << ", "
2358 << thePathShape << ", "
2359 << theNodeStart << ", "
2360 << theHasAngles << ", "
2361 << theAngles << ", "
2362 << theHasRefPoint << ", "
2363 << "SMESH.PointStruct( "
2364 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2365 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2366 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2371 //=======================================================================
2372 //function : ExtrusionAlongPathObjectMakeGroups
2374 //=======================================================================
2376 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2377 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2378 SMESH::SMESH_Mesh_ptr thePathMesh,
2379 GEOM::GEOM_Object_ptr thePathShape,
2380 CORBA::Long theNodeStart,
2381 CORBA::Boolean theHasAngles,
2382 const SMESH::double_array& theAngles,
2383 CORBA::Boolean theHasRefPoint,
2384 const SMESH::PointStruct& theRefPoint,
2385 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2387 SMESH::long_array_var anElementsId = theObject->GetIDs();
2388 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2399 if ( !myPreviewMode ) {
2400 bool isDumpGroups = aGroups && aGroups->length() > 0;
2401 TPythonDump aPythonDump;
2403 aPythonDump << "("<<aGroups;
2406 aPythonDump << ", error)";
2408 aPythonDump <<"error";
2410 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2411 << theObject << ", "
2412 << thePathMesh << ", "
2413 << thePathShape << ", "
2414 << theNodeStart << ", "
2415 << theHasAngles << ", "
2416 << theAngles << ", "
2417 << theHasRefPoint << ", "
2418 << "SMESH.PointStruct( "
2419 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2420 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2421 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2426 //=======================================================================
2427 //function : ExtrusionAlongPathObject1DMakeGroups
2429 //=======================================================================
2431 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2432 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2433 SMESH::SMESH_Mesh_ptr thePathMesh,
2434 GEOM::GEOM_Object_ptr thePathShape,
2435 CORBA::Long theNodeStart,
2436 CORBA::Boolean theHasAngles,
2437 const SMESH::double_array& theAngles,
2438 CORBA::Boolean theHasRefPoint,
2439 const SMESH::PointStruct& theRefPoint,
2440 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2442 SMESH::long_array_var anElementsId = theObject->GetIDs();
2443 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2455 if ( !myPreviewMode ) {
2456 bool isDumpGroups = aGroups && aGroups->length() > 0;
2457 TPythonDump aPythonDump;
2459 aPythonDump << "("<<aGroups;
2462 aPythonDump << ", error)";
2464 aPythonDump <<"error";
2466 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
2467 << theObject << ", "
2468 << thePathMesh << ", "
2469 << thePathShape << ", "
2470 << theNodeStart << ", "
2471 << theHasAngles << ", "
2472 << theAngles << ", "
2473 << theHasRefPoint << ", "
2474 << "SMESH.PointStruct( "
2475 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2476 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2477 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2482 //=======================================================================
2483 //function : ExtrusionAlongPathObject2DMakeGroups
2485 //=======================================================================
2487 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2488 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2489 SMESH::SMESH_Mesh_ptr thePathMesh,
2490 GEOM::GEOM_Object_ptr thePathShape,
2491 CORBA::Long theNodeStart,
2492 CORBA::Boolean theHasAngles,
2493 const SMESH::double_array& theAngles,
2494 CORBA::Boolean theHasRefPoint,
2495 const SMESH::PointStruct& theRefPoint,
2496 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2498 SMESH::long_array_var anElementsId = theObject->GetIDs();
2499 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2511 if ( !myPreviewMode ) {
2512 bool isDumpGroups = aGroups && aGroups->length() > 0;
2513 TPythonDump aPythonDump;
2515 aPythonDump << "("<<aGroups;
2518 aPythonDump << ", error)";
2520 aPythonDump <<"error";
2522 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
2523 << theObject << ", "
2524 << thePathMesh << ", "
2525 << thePathShape << ", "
2526 << theNodeStart << ", "
2527 << theHasAngles << ", "
2528 << theAngles << ", "
2529 << theHasRefPoint << ", "
2530 << "SMESH.PointStruct( "
2531 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2532 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2533 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2539 //=======================================================================
2540 //function : ExtrusionAlongPathObjX
2542 //=======================================================================
2543 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2544 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
2545 SMESH::SMESH_IDSource_ptr Path,
2546 CORBA::Long NodeStart,
2547 CORBA::Boolean HasAngles,
2548 const SMESH::double_array& Angles,
2549 CORBA::Boolean LinearVariation,
2550 CORBA::Boolean HasRefPoint,
2551 const SMESH::PointStruct& RefPoint,
2552 CORBA::Boolean MakeGroups,
2553 SMESH::ElementType ElemType,
2554 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2556 SMESH::long_array_var anElementsId = Object->GetIDs();
2557 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2566 (SMDSAbs_ElementType)ElemType,
2569 if ( !myPreviewMode ) {
2570 bool isDumpGroups = aGroups && aGroups->length() > 0;
2571 TPythonDump aPythonDump;
2573 aPythonDump << "("<<aGroups;
2576 aPythonDump << ", error)";
2578 aPythonDump <<"error";
2580 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2583 << NodeStart << ", "
2584 << HasAngles << ", "
2586 << LinearVariation << ", "
2587 << HasRefPoint << ", "
2588 << "SMESH.PointStruct( "
2589 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2590 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2591 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2592 << MakeGroups << ", "
2593 << ElemType << " )";
2599 //=======================================================================
2600 //function : ExtrusionAlongPathX
2602 //=======================================================================
2603 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2604 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2605 SMESH::SMESH_IDSource_ptr Path,
2606 CORBA::Long NodeStart,
2607 CORBA::Boolean HasAngles,
2608 const SMESH::double_array& Angles,
2609 CORBA::Boolean LinearVariation,
2610 CORBA::Boolean HasRefPoint,
2611 const SMESH::PointStruct& RefPoint,
2612 CORBA::Boolean MakeGroups,
2613 SMESH::ElementType ElemType,
2614 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2616 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2625 (SMDSAbs_ElementType)ElemType,
2628 if ( !myPreviewMode ) {
2629 bool isDumpGroups = aGroups && aGroups->length() > 0;
2630 TPythonDump aPythonDump;
2632 aPythonDump << "("<<aGroups;
2635 aPythonDump << ", error)";
2637 aPythonDump <<"error";
2639 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2640 << IDsOfElements << ", "
2642 << NodeStart << ", "
2643 << HasAngles << ", "
2645 << LinearVariation << ", "
2646 << HasRefPoint << ", "
2647 << "SMESH.PointStruct( "
2648 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2649 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2650 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2651 << ElemType << " )";
2657 //================================================================================
2659 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2660 * of given angles along path steps
2661 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2662 * which proceeds the extrusion
2663 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2664 * is used to define the sub-mesh for the path
2666 //================================================================================
2668 SMESH::double_array*
2669 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2670 GEOM::GEOM_Object_ptr thePathShape,
2671 const SMESH::double_array & theAngles)
2673 SMESH::double_array_var aResult = new SMESH::double_array();
2674 int nbAngles = theAngles.length();
2675 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2677 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2678 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2679 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2680 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2681 return aResult._retn();
2682 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2683 if ( nbSteps == nbAngles )
2685 aResult.inout() = theAngles;
2689 aResult->length( nbSteps );
2690 double rAn2St = double( nbAngles ) / double( nbSteps );
2691 double angPrev = 0, angle;
2692 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2694 double angCur = rAn2St * ( iSt+1 );
2695 double angCurFloor = floor( angCur );
2696 double angPrevFloor = floor( angPrev );
2697 if ( angPrevFloor == angCurFloor )
2698 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2701 int iP = int( angPrevFloor );
2702 double angPrevCeil = ceil(angPrev);
2703 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2705 int iC = int( angCurFloor );
2706 if ( iC < nbAngles )
2707 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2709 iP = int( angPrevCeil );
2711 angle += theAngles[ iC ];
2713 aResult[ iSt ] = angle;
2718 // Update Python script
2719 TPythonDump() << "rotAngles = " << theAngles;
2720 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2721 << thePathMesh << ", "
2722 << thePathShape << ", "
2725 return aResult._retn();
2729 //=======================================================================
2732 //=======================================================================
2734 SMESH::ListOfGroups*
2735 SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
2736 const SMESH::AxisStruct & theAxis,
2737 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2738 CORBA::Boolean theCopy,
2739 const bool theMakeGroups,
2740 ::SMESH_Mesh* theTargetMesh)
2744 TIDSortedElemSet elements;
2745 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2747 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2748 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2751 switch ( theMirrorType ) {
2752 case SMESH::SMESH_MeshEditor::POINT:
2753 aTrsf.SetMirror( P );
2755 case SMESH::SMESH_MeshEditor::AXIS:
2756 aTrsf.SetMirror( gp_Ax1( P, V ));
2759 aTrsf.SetMirror( gp_Ax2( P, V ));
2762 ::SMESH_MeshEditor anEditor( myMesh );
2763 ::SMESH_MeshEditor::PGroupIDs groupIds =
2764 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2767 storeResult(anEditor);
2769 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2772 //=======================================================================
2775 //=======================================================================
2777 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2778 const SMESH::AxisStruct & theAxis,
2779 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2780 CORBA::Boolean theCopy)
2782 if ( !myPreviewMode ) {
2783 TPythonDump() << this << ".Mirror( "
2784 << theIDsOfElements << ", "
2786 << mirrorTypeName(theMirrorType) << ", "
2789 mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2793 //=======================================================================
2794 //function : MirrorObject
2796 //=======================================================================
2798 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2799 const SMESH::AxisStruct & theAxis,
2800 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2801 CORBA::Boolean theCopy)
2803 if ( !myPreviewMode ) {
2804 TPythonDump() << this << ".MirrorObject( "
2805 << theObject << ", "
2807 << mirrorTypeName(theMirrorType) << ", "
2810 SMESH::long_array_var anElementsId = theObject->GetIDs();
2811 mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2814 //=======================================================================
2815 //function : MirrorMakeGroups
2817 //=======================================================================
2819 SMESH::ListOfGroups*
2820 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2821 const SMESH::AxisStruct& theMirror,
2822 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2824 SMESH::ListOfGroups * aGroups = mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2825 if ( !myPreviewMode ) {
2826 TPythonDump aPythonDump;
2827 DumpGroupsList(aPythonDump,aGroups);
2828 aPythonDump << this << ".MirrorMakeGroups( "
2829 << theIDsOfElements << ", "
2830 << theMirror << ", "
2831 << mirrorTypeName(theMirrorType) << " )";
2836 //=======================================================================
2837 //function : MirrorObjectMakeGroups
2839 //=======================================================================
2841 SMESH::ListOfGroups*
2842 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2843 const SMESH::AxisStruct& theMirror,
2844 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2846 SMESH::long_array_var anElementsId = theObject->GetIDs();
2847 SMESH::ListOfGroups * aGroups = mirror(anElementsId, theMirror, theMirrorType, true, true);
2848 if ( !myPreviewMode ) {
2849 TPythonDump aPythonDump;
2850 DumpGroupsList(aPythonDump,aGroups);
2851 aPythonDump << this << ".MirrorObjectMakeGroups( "
2852 << theObject << ", "
2853 << theMirror << ", "
2854 << mirrorTypeName(theMirrorType) << " )";
2859 //=======================================================================
2860 //function : MirrorMakeMesh
2862 //=======================================================================
2864 SMESH::SMESH_Mesh_ptr
2865 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2866 const SMESH::AxisStruct& theMirror,
2867 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2868 CORBA::Boolean theCopyGroups,
2869 const char* theMeshName)
2871 SMESH_Mesh_i* mesh_i;
2872 SMESH::SMESH_Mesh_var mesh;
2873 { // open new scope to dump "MakeMesh" command
2874 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2876 TPythonDump pydump; // to prevent dump at mesh creation
2878 mesh = makeMesh( theMeshName );
2879 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2881 mirror(theIDsOfElements, theMirror, theMirrorType,
2882 false, theCopyGroups, & mesh_i->GetImpl());
2883 mesh_i->CreateGroupServants();
2886 if ( !myPreviewMode ) {
2887 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2888 << theIDsOfElements << ", "
2889 << theMirror << ", "
2890 << mirrorTypeName(theMirrorType) << ", "
2891 << theCopyGroups << ", '"
2892 << theMeshName << "' )";
2897 if(!myPreviewMode && mesh_i)
2898 mesh_i->GetGroups();
2900 return mesh._retn();
2903 //=======================================================================
2904 //function : MirrorObjectMakeMesh
2906 //=======================================================================
2908 SMESH::SMESH_Mesh_ptr
2909 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2910 const SMESH::AxisStruct& theMirror,
2911 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2912 CORBA::Boolean theCopyGroups,
2913 const char* theMeshName)
2915 SMESH_Mesh_i* mesh_i;
2916 SMESH::SMESH_Mesh_var mesh;
2917 { // open new scope to dump "MakeMesh" command
2918 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2920 TPythonDump pydump; // to prevent dump at mesh creation
2922 mesh = makeMesh( theMeshName );
2923 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2925 SMESH::long_array_var anElementsId = theObject->GetIDs();
2926 mirror(anElementsId, theMirror, theMirrorType,
2927 false, theCopyGroups, & mesh_i->GetImpl());
2928 mesh_i->CreateGroupServants();
2931 if ( !myPreviewMode ) {
2932 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
2933 << theObject << ", "
2934 << theMirror << ", "
2935 << mirrorTypeName(theMirrorType) << ", "
2936 << theCopyGroups << ", '"
2937 << theMeshName << "' )";
2942 if(!myPreviewMode && mesh_i)
2943 mesh_i->GetGroups();
2945 return mesh._retn();
2948 //=======================================================================
2949 //function : translate
2951 //=======================================================================
2953 SMESH::ListOfGroups*
2954 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2955 const SMESH::DirStruct & theVector,
2956 CORBA::Boolean theCopy,
2957 const bool theMakeGroups,
2958 ::SMESH_Mesh* theTargetMesh)
2962 TIDSortedElemSet elements;
2963 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2966 const SMESH::PointStruct * P = &theVector.PS;
2967 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2969 ::SMESH_MeshEditor anEditor( myMesh );
2970 ::SMESH_MeshEditor::PGroupIDs groupIds =
2971 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2974 storeResult(anEditor);
2976 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2979 //=======================================================================
2980 //function : Translate
2982 //=======================================================================
2984 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2985 const SMESH::DirStruct & theVector,
2986 CORBA::Boolean theCopy)
2988 if ( !myPreviewMode ) {
2989 TPythonDump() << this << ".Translate( "
2990 << theIDsOfElements << ", "
2991 << theVector << ", "
2994 translate(theIDsOfElements,
3000 //=======================================================================
3001 //function : TranslateObject
3003 //=======================================================================
3005 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
3006 const SMESH::DirStruct & theVector,
3007 CORBA::Boolean theCopy)
3009 if ( !myPreviewMode ) {
3010 TPythonDump() << this << ".TranslateObject( "
3011 << theObject << ", "
3012 << theVector << ", "
3015 SMESH::long_array_var anElementsId = theObject->GetIDs();
3016 translate(anElementsId,
3022 //=======================================================================
3023 //function : TranslateMakeGroups
3025 //=======================================================================
3027 SMESH::ListOfGroups*
3028 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
3029 const SMESH::DirStruct& theVector)
3031 SMESH::ListOfGroups * aGroups = translate(theIDsOfElements,theVector,true,true);
3032 if ( !myPreviewMode ) {
3033 TPythonDump aPythonDump;
3034 DumpGroupsList(aPythonDump,aGroups);
3035 aPythonDump << this << ".TranslateMakeGroups( "
3036 << theIDsOfElements << ", "
3037 << theVector << " )";
3042 //=======================================================================
3043 //function : TranslateObjectMakeGroups
3045 //=======================================================================
3047 SMESH::ListOfGroups*
3048 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3049 const SMESH::DirStruct& theVector)
3051 SMESH::long_array_var anElementsId = theObject->GetIDs();
3052 SMESH::ListOfGroups * aGroups = translate(anElementsId, theVector, true, true);
3054 if ( !myPreviewMode ) {
3056 TPythonDump aPythonDump;
3057 DumpGroupsList(aPythonDump,aGroups);
3058 aPythonDump << this << ".TranslateObjectMakeGroups( "
3059 << theObject << ", "
3060 << theVector << " )";
3065 //=======================================================================
3066 //function : TranslateMakeMesh
3068 //=======================================================================
3070 SMESH::SMESH_Mesh_ptr
3071 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3072 const SMESH::DirStruct& theVector,
3073 CORBA::Boolean theCopyGroups,
3074 const char* theMeshName)
3076 SMESH_Mesh_i* mesh_i;
3077 SMESH::SMESH_Mesh_var mesh;
3079 { // open new scope to dump "MakeMesh" command
3080 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3082 TPythonDump pydump; // to prevent dump at mesh creation
3084 mesh = makeMesh( theMeshName );
3085 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3088 translate(theIDsOfElements, theVector,
3089 false, theCopyGroups, & mesh_i->GetImpl());
3090 mesh_i->CreateGroupServants();
3093 if ( !myPreviewMode ) {
3094 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3095 << theIDsOfElements << ", "
3096 << theVector << ", "
3097 << theCopyGroups << ", '"
3098 << theMeshName << "' )";
3103 if(!myPreviewMode && mesh_i)
3104 mesh_i->GetGroups();
3106 return mesh._retn();
3109 //=======================================================================
3110 //function : TranslateObjectMakeMesh
3112 //=======================================================================
3114 SMESH::SMESH_Mesh_ptr
3115 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3116 const SMESH::DirStruct& theVector,
3117 CORBA::Boolean theCopyGroups,
3118 const char* theMeshName)
3120 SMESH_Mesh_i* mesh_i;
3121 SMESH::SMESH_Mesh_var mesh;
3122 { // open new scope to dump "MakeMesh" command
3123 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3125 TPythonDump pydump; // to prevent dump at mesh creation
3126 mesh = makeMesh( theMeshName );
3127 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3130 SMESH::long_array_var anElementsId = theObject->GetIDs();
3131 translate(anElementsId, theVector,
3132 false, theCopyGroups, & mesh_i->GetImpl());
3133 mesh_i->CreateGroupServants();
3135 if ( !myPreviewMode ) {
3136 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3137 << theObject << ", "
3138 << theVector << ", "
3139 << theCopyGroups << ", '"
3140 << theMeshName << "' )";
3145 if(!myPreviewMode && mesh_i)
3146 mesh_i->GetGroups();
3148 return mesh._retn();
3151 //=======================================================================
3154 //=======================================================================
3156 SMESH::ListOfGroups*
3157 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
3158 const SMESH::AxisStruct & theAxis,
3159 CORBA::Double theAngle,
3160 CORBA::Boolean theCopy,
3161 const bool theMakeGroups,
3162 ::SMESH_Mesh* theTargetMesh)
3166 TIDSortedElemSet elements;
3167 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3169 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3170 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3173 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3175 ::SMESH_MeshEditor anEditor( myMesh );
3176 ::SMESH_MeshEditor::PGroupIDs groupIds =
3177 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3180 storeResult(anEditor);
3182 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3185 //=======================================================================
3188 //=======================================================================
3190 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3191 const SMESH::AxisStruct & theAxis,
3192 CORBA::Double theAngle,
3193 CORBA::Boolean theCopy)
3195 if ( !myPreviewMode ) {
3196 TPythonDump() << this << ".Rotate( "
3197 << theIDsOfElements << ", "
3202 rotate(theIDsOfElements,
3209 //=======================================================================
3210 //function : RotateObject
3212 //=======================================================================
3214 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3215 const SMESH::AxisStruct & theAxis,
3216 CORBA::Double theAngle,
3217 CORBA::Boolean theCopy)
3219 if ( !myPreviewMode ) {
3220 TPythonDump() << this << ".RotateObject( "
3221 << theObject << ", "
3226 SMESH::long_array_var anElementsId = theObject->GetIDs();
3227 rotate(anElementsId,
3234 //=======================================================================
3235 //function : RotateMakeGroups
3237 //=======================================================================
3239 SMESH::ListOfGroups*
3240 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3241 const SMESH::AxisStruct& theAxis,
3242 CORBA::Double theAngle)
3244 SMESH::ListOfGroups * aGroups = rotate(theIDsOfElements,theAxis,theAngle,true,true);
3245 if ( !myPreviewMode ) {
3246 TPythonDump aPythonDump;
3247 DumpGroupsList(aPythonDump,aGroups);
3248 aPythonDump << this << ".RotateMakeGroups( "
3249 << theIDsOfElements << ", "
3251 << theAngle << " )";
3256 //=======================================================================
3257 //function : RotateObjectMakeGroups
3259 //=======================================================================
3261 SMESH::ListOfGroups*
3262 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3263 const SMESH::AxisStruct& theAxis,
3264 CORBA::Double theAngle)
3266 SMESH::long_array_var anElementsId = theObject->GetIDs();
3267 SMESH::ListOfGroups * aGroups = rotate(anElementsId,theAxis,theAngle,true,true);
3269 if ( !myPreviewMode ) {
3270 TPythonDump aPythonDump;
3271 DumpGroupsList(aPythonDump,aGroups);
3272 aPythonDump << this << ".RotateObjectMakeGroups( "
3273 << theObject << ", "
3275 << theAngle << " )";
3280 //=======================================================================
3281 //function : RotateMakeMesh
3283 //=======================================================================
3285 SMESH::SMESH_Mesh_ptr
3286 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3287 const SMESH::AxisStruct& theAxis,
3288 CORBA::Double theAngleInRadians,
3289 CORBA::Boolean theCopyGroups,
3290 const char* theMeshName)
3292 SMESH::SMESH_Mesh_var mesh;
3293 SMESH_Mesh_i* mesh_i;
3295 { // open new scope to dump "MakeMesh" command
3296 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3298 TPythonDump pydump; // to prevent dump at mesh creation
3300 mesh = makeMesh( theMeshName );
3301 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3304 rotate(theIDsOfElements, theAxis, theAngleInRadians,
3305 false, theCopyGroups, & mesh_i->GetImpl());
3306 mesh_i->CreateGroupServants();
3308 if ( !myPreviewMode ) {
3309 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3310 << theIDsOfElements << ", "
3312 << theAngleInRadians << ", "
3313 << theCopyGroups << ", '"
3314 << theMeshName << "' )";
3319 if(!myPreviewMode && mesh_i)
3320 mesh_i->GetGroups();
3322 return mesh._retn();
3325 //=======================================================================
3326 //function : RotateObjectMakeMesh
3328 //=======================================================================
3330 SMESH::SMESH_Mesh_ptr
3331 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3332 const SMESH::AxisStruct& theAxis,
3333 CORBA::Double theAngleInRadians,
3334 CORBA::Boolean theCopyGroups,
3335 const char* theMeshName)
3337 SMESH::SMESH_Mesh_var mesh;
3338 SMESH_Mesh_i* mesh_i;
3340 {// open new scope to dump "MakeMesh" command
3341 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3343 TPythonDump pydump; // to prevent dump at mesh creation
3344 mesh = makeMesh( theMeshName );
3345 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3348 SMESH::long_array_var anElementsId = theObject->GetIDs();
3349 rotate(anElementsId, theAxis, theAngleInRadians,
3350 false, theCopyGroups, & mesh_i->GetImpl());
3351 mesh_i->CreateGroupServants();
3353 if ( !myPreviewMode ) {
3354 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3355 << theObject << ", "
3357 << theAngleInRadians << ", "
3358 << theCopyGroups << ", '"
3359 << theMeshName << "' )";
3364 if(!myPreviewMode && mesh_i)
3365 mesh_i->GetGroups();
3367 return mesh._retn();
3370 //=======================================================================
3371 //function : FindCoincidentNodes
3373 //=======================================================================
3375 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3376 SMESH::array_of_long_array_out GroupsOfNodes)
3380 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3381 ::SMESH_MeshEditor anEditor( myMesh );
3382 set<const SMDS_MeshNode*> nodes; // no input nodes
3383 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3385 GroupsOfNodes = new SMESH::array_of_long_array;
3386 GroupsOfNodes->length( aListOfListOfNodes.size() );
3387 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3388 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3389 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3390 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3391 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3392 aGroup.length( aListOfNodes.size() );
3393 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3394 aGroup[ j ] = (*lIt)->GetID();
3396 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3397 << Tolerance << " )";
3400 //=======================================================================
3401 //function : FindCoincidentNodesOnPart
3403 //=======================================================================
3404 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3405 CORBA::Double Tolerance,
3406 SMESH::array_of_long_array_out GroupsOfNodes)
3409 SMESH::long_array_var aElementsId = theObject->GetIDs();
3411 SMESHDS_Mesh* aMesh = GetMeshDS();
3412 set<const SMDS_MeshNode*> nodes;
3414 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
3415 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
3416 for(int i = 0; i < aElementsId->length(); i++) {
3417 CORBA::Long ind = aElementsId[i];
3418 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
3424 for(int i = 0; i < aElementsId->length(); i++) {
3425 CORBA::Long ind = aElementsId[i];
3426 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
3428 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
3429 while ( nIt->more() )
3430 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
3436 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3437 ::SMESH_MeshEditor anEditor( myMesh );
3439 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3441 GroupsOfNodes = new SMESH::array_of_long_array;
3442 GroupsOfNodes->length( aListOfListOfNodes.size() );
3443 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3444 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3445 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3446 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3447 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3448 aGroup.length( aListOfNodes.size() );
3449 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3450 aGroup[ j ] = (*lIt)->GetID();
3452 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3454 << Tolerance << " )";
3457 //=======================================================================
3458 //function : MergeNodes
3460 //=======================================================================
3462 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3466 SMESHDS_Mesh* aMesh = GetMeshDS();
3468 TPythonDump aTPythonDump;
3469 aTPythonDump << this << ".MergeNodes([";
3470 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3471 for (int i = 0; i < GroupsOfNodes.length(); i++)
3473 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3474 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3475 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3476 for ( int j = 0; j < aNodeGroup.length(); j++ )
3478 CORBA::Long index = aNodeGroup[ j ];
3479 const SMDS_MeshNode * node = aMesh->FindNode(index);
3481 aListOfNodes.push_back( node );
3483 if ( aListOfNodes.size() < 2 )
3484 aListOfListOfNodes.pop_back();
3486 if ( i > 0 ) aTPythonDump << ", ";
3487 aTPythonDump << aNodeGroup;
3489 ::SMESH_MeshEditor anEditor( myMesh );
3490 anEditor.MergeNodes( aListOfListOfNodes );
3492 aTPythonDump << "])";
3495 //=======================================================================
3496 //function : FindEqualElements
3498 //=======================================================================
3499 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3500 SMESH::array_of_long_array_out GroupsOfElementsID)
3503 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
3504 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
3505 typedef list<int> TListOfIDs;
3506 set<const SMDS_MeshElement*> elems;
3507 SMESH::long_array_var aElementsId = theObject->GetIDs();
3508 SMESHDS_Mesh* aMesh = GetMeshDS();
3510 for(int i = 0; i < aElementsId->length(); i++) {
3511 CORBA::Long anID = aElementsId[i];
3512 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3518 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3519 ::SMESH_MeshEditor anEditor( myMesh );
3520 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3522 GroupsOfElementsID = new SMESH::array_of_long_array;
3523 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3525 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3526 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3527 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3528 TListOfIDs& listOfIDs = *arraysIt;
3529 aGroup.length( listOfIDs.size() );
3530 TListOfIDs::iterator idIt = listOfIDs.begin();
3531 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3532 aGroup[ k ] = *idIt;
3536 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3541 //=======================================================================
3542 //function : MergeElements
3544 //=======================================================================
3546 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3550 TPythonDump aTPythonDump;
3551 aTPythonDump << this << ".MergeElements( [";
3553 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3555 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3556 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3557 aListOfListOfElementsID.push_back( list< int >() );
3558 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3559 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3560 CORBA::Long id = anElemsIDGroup[ j ];
3561 aListOfElemsID.push_back( id );
3563 if ( aListOfElemsID.size() < 2 )
3564 aListOfListOfElementsID.pop_back();
3565 if ( i > 0 ) aTPythonDump << ", ";
3566 aTPythonDump << anElemsIDGroup;
3569 ::SMESH_MeshEditor anEditor( myMesh );
3570 anEditor.MergeElements(aListOfListOfElementsID);
3572 aTPythonDump << "] )";
3575 //=======================================================================
3576 //function : MergeEqualElements
3578 //=======================================================================
3580 void SMESH_MeshEditor_i::MergeEqualElements()
3584 ::SMESH_MeshEditor anEditor( myMesh );
3585 anEditor.MergeEqualElements();
3587 TPythonDump() << this << ".MergeEqualElements()";
3590 //=============================================================================
3592 * Move the node to a given point
3594 //=============================================================================
3596 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
3601 initData(/*deleteSearchers=*/false);
3603 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
3607 if ( theNodeSearcher )
3608 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3610 if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3611 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3613 GetMeshDS()->MoveNode(node, x, y, z);
3615 // Update Python script
3616 TPythonDump() << "isDone = " << this << ".MoveNode( "
3617 << NodeID << ", " << x << ", " << y << ", " << z << " )";
3622 //================================================================================
3624 * \brief Return ID of node closest to a given point
3626 //================================================================================
3628 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
3632 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3634 if ( !theNodeSearcher ) {
3635 ::SMESH_MeshEditor anEditor( myMesh );
3636 theNodeSearcher = anEditor.GetNodeSearcher();
3639 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
3640 return node->GetID();
3645 //================================================================================
3647 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
3648 * move the node closest to the point to point's location and return ID of the node
3650 //================================================================================
3652 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
3655 CORBA::Long theNodeID)
3657 // We keep theNodeSearcher until any mesh modification:
3658 // 1) initData() deletes theNodeSearcher at any edition,
3659 // 2) TSearchersDeleter - at any mesh compute event and mesh change
3661 initData(/*deleteSearchers=*/false);
3663 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3665 int nodeID = theNodeID;
3666 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
3667 if ( !node ) // preview moving node
3669 if ( !theNodeSearcher ) {
3670 ::SMESH_MeshEditor anEditor( myMesh );
3671 theNodeSearcher = anEditor.GetNodeSearcher();
3674 node = theNodeSearcher->FindClosestTo( p );
3677 nodeID = node->GetID();
3678 if ( myPreviewMode ) // make preview data
3680 // in a preview mesh, make edges linked to a node
3681 TPreviewMesh tmpMesh;
3682 TIDSortedElemSet linkedNodes;
3683 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3684 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3685 for ( ; nIt != linkedNodes.end(); ++nIt )
3687 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
3688 tmpMesh.Copy( &edge );
3691 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
3693 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
3694 // fill preview data
3695 ::SMESH_MeshEditor anEditor( & tmpMesh );
3696 storeResult( anEditor );
3698 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3700 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3704 GetMeshDS()->MoveNode(node, x, y, z);
3708 if ( !myPreviewMode ) {
3709 TPythonDump() << "nodeID = " << this
3710 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
3711 << ", " << nodeID << " )";
3717 //=======================================================================
3719 * Return elements of given type where the given point is IN or ON.
3721 * 'ALL' type means elements of any type excluding nodes
3723 //=======================================================================
3725 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
3728 SMESH::ElementType type)
3730 SMESH::long_array_var res = new SMESH::long_array;
3731 vector< const SMDS_MeshElement* > foundElems;
3733 theSearchersDeleter.Set( myMesh );
3734 if ( !theElementSearcher ) {
3735 ::SMESH_MeshEditor anEditor( myMesh );
3736 theElementSearcher = anEditor.GetElementSearcher();
3738 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
3739 SMDSAbs_ElementType( type ),
3741 res->length( foundElems.size() );
3742 for ( int i = 0; i < foundElems.size(); ++i )
3743 res[i] = foundElems[i]->GetID();
3745 if ( !myPreviewMode ) // call from tui
3746 TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
3755 //=======================================================================
3756 //function : convError
3758 //=======================================================================
3760 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
3762 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
3766 RETCASE( SEW_BORDER1_NOT_FOUND );
3767 RETCASE( SEW_BORDER2_NOT_FOUND );
3768 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
3769 RETCASE( SEW_BAD_SIDE_NODES );
3770 RETCASE( SEW_VOLUMES_TO_SPLIT );
3771 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
3772 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
3773 RETCASE( SEW_BAD_SIDE1_NODES );
3774 RETCASE( SEW_BAD_SIDE2_NODES );
3776 return SMESH::SMESH_MeshEditor::SEW_OK;
3779 //=======================================================================
3780 //function : SewFreeBorders
3782 //=======================================================================
3784 SMESH::SMESH_MeshEditor::Sew_Error
3785 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
3786 CORBA::Long SecondNodeID1,
3787 CORBA::Long LastNodeID1,
3788 CORBA::Long FirstNodeID2,
3789 CORBA::Long SecondNodeID2,
3790 CORBA::Long LastNodeID2,
3791 CORBA::Boolean CreatePolygons,
3792 CORBA::Boolean CreatePolyedrs)
3796 SMESHDS_Mesh* aMesh = GetMeshDS();
3798 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3799 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3800 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3801 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3802 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3803 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
3805 if (!aBorderFirstNode ||
3806 !aBorderSecondNode||
3808 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3809 if (!aSide2FirstNode ||
3810 !aSide2SecondNode ||
3812 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3814 TPythonDump() << "error = " << this << ".SewFreeBorders( "
3815 << FirstNodeID1 << ", "
3816 << SecondNodeID1 << ", "
3817 << LastNodeID1 << ", "
3818 << FirstNodeID2 << ", "
3819 << SecondNodeID2 << ", "
3820 << LastNodeID2 << ", "
3821 << CreatePolygons<< ", "
3822 << CreatePolyedrs<< " )";
3824 ::SMESH_MeshEditor anEditor( myMesh );
3825 SMESH::SMESH_MeshEditor::Sew_Error error =
3826 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3836 storeResult(anEditor);
3842 //=======================================================================
3843 //function : SewConformFreeBorders
3845 //=======================================================================
3847 SMESH::SMESH_MeshEditor::Sew_Error
3848 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3849 CORBA::Long SecondNodeID1,
3850 CORBA::Long LastNodeID1,
3851 CORBA::Long FirstNodeID2,
3852 CORBA::Long SecondNodeID2)
3856 SMESHDS_Mesh* aMesh = GetMeshDS();
3858 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3859 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3860 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3861 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3862 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3863 const SMDS_MeshNode* aSide2ThirdNode = 0;
3865 if (!aBorderFirstNode ||
3866 !aBorderSecondNode||
3868 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3869 if (!aSide2FirstNode ||
3871 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3873 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
3874 << FirstNodeID1 << ", "
3875 << SecondNodeID1 << ", "
3876 << LastNodeID1 << ", "
3877 << FirstNodeID2 << ", "
3878 << SecondNodeID2 << " )";
3880 ::SMESH_MeshEditor anEditor( myMesh );
3881 SMESH::SMESH_MeshEditor::Sew_Error error =
3882 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3891 storeResult(anEditor);
3897 //=======================================================================
3898 //function : SewBorderToSide
3900 //=======================================================================
3902 SMESH::SMESH_MeshEditor::Sew_Error
3903 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
3904 CORBA::Long SecondNodeIDOnFreeBorder,
3905 CORBA::Long LastNodeIDOnFreeBorder,
3906 CORBA::Long FirstNodeIDOnSide,
3907 CORBA::Long LastNodeIDOnSide,
3908 CORBA::Boolean CreatePolygons,
3909 CORBA::Boolean CreatePolyedrs)
3913 SMESHDS_Mesh* aMesh = GetMeshDS();
3915 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
3916 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
3917 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
3918 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
3919 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
3920 const SMDS_MeshNode* aSide2ThirdNode = 0;
3922 if (!aBorderFirstNode ||
3923 !aBorderSecondNode||
3925 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3926 if (!aSide2FirstNode ||
3928 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
3930 TPythonDump() << "error = " << this << ".SewBorderToSide( "
3931 << FirstNodeIDOnFreeBorder << ", "
3932 << SecondNodeIDOnFreeBorder << ", "
3933 << LastNodeIDOnFreeBorder << ", "
3934 << FirstNodeIDOnSide << ", "
3935 << LastNodeIDOnSide << ", "
3936 << CreatePolygons << ", "
3937 << CreatePolyedrs << ") ";
3939 ::SMESH_MeshEditor anEditor( myMesh );
3940 SMESH::SMESH_MeshEditor::Sew_Error error =
3941 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3951 storeResult(anEditor);
3957 //=======================================================================
3958 //function : SewSideElements
3960 //=======================================================================
3962 SMESH::SMESH_MeshEditor::Sew_Error
3963 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
3964 const SMESH::long_array& IDsOfSide2Elements,
3965 CORBA::Long NodeID1OfSide1ToMerge,
3966 CORBA::Long NodeID1OfSide2ToMerge,
3967 CORBA::Long NodeID2OfSide1ToMerge,
3968 CORBA::Long NodeID2OfSide2ToMerge)
3972 SMESHDS_Mesh* aMesh = GetMeshDS();
3974 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
3975 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
3976 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
3977 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
3979 if (!aFirstNode1ToMerge ||
3980 !aFirstNode2ToMerge )
3981 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
3982 if (!aSecondNode1ToMerge||
3983 !aSecondNode2ToMerge)
3984 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
3986 TIDSortedElemSet aSide1Elems, aSide2Elems;
3987 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
3988 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
3990 TPythonDump() << "error = " << this << ".SewSideElements( "
3991 << IDsOfSide1Elements << ", "
3992 << IDsOfSide2Elements << ", "
3993 << NodeID1OfSide1ToMerge << ", "
3994 << NodeID1OfSide2ToMerge << ", "
3995 << NodeID2OfSide1ToMerge << ", "
3996 << NodeID2OfSide2ToMerge << ")";
3998 ::SMESH_MeshEditor anEditor( myMesh );
3999 SMESH::SMESH_MeshEditor::Sew_Error error =
4000 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
4003 aSecondNode1ToMerge,
4004 aSecondNode2ToMerge));
4006 storeResult(anEditor);
4011 //================================================================================
4013 * \brief Set new nodes for given element
4014 * \param ide - element id
4015 * \param newIDs - new node ids
4016 * \retval CORBA::Boolean - true if result is OK
4018 //================================================================================
4020 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
4021 const SMESH::long_array& newIDs)
4025 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
4026 if(!elem) return false;
4028 int nbn = newIDs.length();
4030 vector<const SMDS_MeshNode*> aNodes(nbn);
4033 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
4036 aNodes[nbn1] = aNode;
4039 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
4040 << ide << ", " << newIDs << " )";
4042 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
4045 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
4048 //================================================================================
4050 * \brief Update myLastCreated* or myPreviewData
4051 * \param anEditor - it contains last modification results
4053 //================================================================================
4055 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
4057 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
4059 list<int> aNodesConnectivity;
4060 typedef map<int, int> TNodesMap;
4063 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
4064 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
4066 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
4067 int nbEdges = aMeshDS->NbEdges();
4068 int nbFaces = aMeshDS->NbFaces();
4069 int nbVolum = aMeshDS->NbVolumes();
4070 switch ( previewType ) {
4071 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
4072 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
4073 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
4076 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
4077 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
4079 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
4081 while ( itMeshElems->more() ) {
4082 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
4083 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
4086 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
4087 while ( itElemNodes->more() ) {
4088 const SMDS_MeshNode* aMeshNode =
4089 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
4090 int aNodeID = aMeshNode->GetID();
4091 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
4092 if ( anIter == nodesMap.end() ) {
4093 // filling the nodes coordinates
4094 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
4095 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
4096 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
4097 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4100 aNodesConnectivity.push_back(anIter->second);
4103 // filling the elements types
4104 SMDSAbs_ElementType aType;
4106 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4107 aType = SMDSAbs_Node;
4111 aType = aMeshElem->GetType();
4112 isPoly = aMeshElem->IsPoly();
4115 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4116 myPreviewData->elementTypes[i].isPoly = isPoly;
4117 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4121 myPreviewData->nodesXYZ.length( j );
4123 // filling the elements connectivities
4124 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4125 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4126 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4127 myPreviewData->elementConnectivities[i] = *aConnIter;
4133 // add new nodes into myLastCreatedNodes
4134 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4135 myLastCreatedNodes->length(aSeq.Length());
4136 for(int i=0; i<aSeq.Length(); i++)
4137 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4140 // add new elements into myLastCreatedElems
4141 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4142 myLastCreatedElems->length(aSeq.Length());
4143 for(int i=0; i<aSeq.Length(); i++)
4144 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4148 //================================================================================
4150 * Return data of mesh edition preview
4152 //================================================================================
4154 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4156 return myPreviewData._retn();
4159 //================================================================================
4161 * \brief Returns list of it's IDs of created nodes
4162 * \retval SMESH::long_array* - list of node ID
4164 //================================================================================
4166 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4168 return myLastCreatedNodes._retn();
4171 //================================================================================
4173 * \brief Returns list of it's IDs of created elements
4174 * \retval SMESH::long_array* - list of elements' ID
4176 //================================================================================
4178 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4180 return myLastCreatedElems._retn();
4183 //=======================================================================
4184 //function : ConvertToQuadratic
4186 //=======================================================================
4188 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4190 ::SMESH_MeshEditor anEditor( myMesh );
4191 anEditor.ConvertToQuadratic(theForce3d);
4192 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4195 //=======================================================================
4196 //function : ConvertFromQuadratic
4198 //=======================================================================
4200 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4202 ::SMESH_MeshEditor anEditor( myMesh );
4203 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4204 TPythonDump() << this << ".ConvertFromQuadratic()";
4208 //=======================================================================
4209 //function : makeMesh
4210 //purpose : create a named imported mesh
4211 //=======================================================================
4213 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4215 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4216 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4217 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4218 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4219 gen->SetName( meshSO, theMeshName, "Mesh" );
4220 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4222 return mesh._retn();
4225 //=======================================================================
4226 //function : DumpGroupsList
4228 //=======================================================================
4229 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4230 const SMESH::ListOfGroups * theGroupList)
4232 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4233 if(isDumpGroupList) {
4234 theDumpPython << theGroupList << " = ";
4238 //================================================================================
4240 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4241 \param theNodes - identifiers of nodes to be doubled
4242 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4243 nodes. If list of element identifiers is empty then nodes are doubled but
4244 they not assigned to elements
4245 \return TRUE if operation has been completed successfully, FALSE otherwise
4246 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4248 //================================================================================
4250 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4251 const SMESH::long_array& theModifiedElems )
4255 ::SMESH_MeshEditor aMeshEditor( myMesh );
4256 list< int > aListOfNodes;
4258 for ( i = 0, n = theNodes.length(); i < n; i++ )
4259 aListOfNodes.push_back( theNodes[ i ] );
4261 list< int > aListOfElems;
4262 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4263 aListOfElems.push_back( theModifiedElems[ i ] );
4265 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4267 storeResult( aMeshEditor) ;
4272 //================================================================================
4274 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4275 This method provided for convenience works as DoubleNodes() described above.
4276 \param theNodeId - identifier of node to be doubled.
4277 \param theModifiedElems - identifiers of elements to be updated.
4278 \return TRUE if operation has been completed successfully, FALSE otherwise
4279 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4281 //================================================================================
4283 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4284 const SMESH::long_array& theModifiedElems )
4286 SMESH::long_array_var aNodes = new SMESH::long_array;
4287 aNodes->length( 1 );
4288 aNodes[ 0 ] = theNodeId;
4289 return DoubleNodes( aNodes, theModifiedElems );
4292 //================================================================================
4294 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4295 This method provided for convenience works as DoubleNodes() described above.
4296 \param theNodes - group of nodes to be doubled.
4297 \param theModifiedElems - group of elements to be updated.
4298 \return TRUE if operation has been completed successfully, FALSE otherwise
4299 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
4301 //================================================================================
4303 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(
4304 SMESH::SMESH_GroupBase_ptr theNodes,
4305 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4307 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4310 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4311 SMESH::long_array_var aModifiedElems;
4312 if ( !CORBA::is_nil( theModifiedElems ) )
4313 aModifiedElems = theModifiedElems->GetListOfID();
4316 aModifiedElems = new SMESH::long_array;
4317 aModifiedElems->length( 0 );
4320 return DoubleNodes( aNodes, aModifiedElems );
4323 //================================================================================
4325 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4326 This method provided for convenience works as DoubleNodes() described above.
4327 \param theNodes - list of groups of nodes to be doubled
4328 \param theModifiedElems - list of groups of elements to be updated.
4329 \return TRUE if operation has been completed successfully, FALSE otherwise
4330 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
4332 //================================================================================
4334 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(
4335 const SMESH::ListOfGroups& theNodes,
4336 const SMESH::ListOfGroups& theModifiedElems )
4340 ::SMESH_MeshEditor aMeshEditor( myMesh );
4342 std::list< int > aNodes;
4344 for ( i = 0, n = theNodes.length(); i < n; i++ )
4346 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
4347 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
4349 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4350 for ( j = 0, m = aCurr->length(); j < m; j++ )
4351 aNodes.push_back( aCurr[ j ] );
4355 std::list< int > anElems;
4356 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4358 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
4359 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
4361 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4362 for ( j = 0, m = aCurr->length(); j < m; j++ )
4363 anElems.push_back( aCurr[ j ] );
4367 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
4369 storeResult( aMeshEditor) ;
4374 //================================================================================
4376 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4377 \param theElems - the list of elements (edges or faces) to be replicated
4378 The nodes for duplication could be found from these elements
4379 \param theNodesNot - list of nodes to NOT replicate
4380 \param theAffectedElems - the list of elements (cells and edges) to which the
4381 replicated nodes should be associated to.
4382 \return TRUE if operation has been completed successfully, FALSE otherwise
4383 \sa DoubleNodeGroup(), DoubleNodeGroups()
4385 //================================================================================
4387 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
4388 const SMESH::long_array& theNodesNot,
4389 const SMESH::long_array& theAffectedElems )
4394 ::SMESH_MeshEditor aMeshEditor( myMesh );
4396 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4397 TIDSortedElemSet anElems, aNodes, anAffected;
4398 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4399 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4400 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
4402 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4404 storeResult( aMeshEditor) ;
4406 // Update Python script
4407 TPythonDump() << "isDone = " << this << ".DoubleNodes( " << theElems << ", "
4408 << theNodesNot << ", " << theAffectedElems << " )";
4412 //================================================================================
4414 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4415 \param theElems - the list of elements (edges or faces) to be replicated
4416 The nodes for duplication could be found from these elements
4417 \param theNodesNot - list of nodes to NOT replicate
4418 \param theShape - shape to detect affected elements (element which geometric center
4419 located on or inside shape).
4420 The replicated nodes should be associated to affected elements.
4421 \return TRUE if operation has been completed successfully, FALSE otherwise
4422 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
4424 //================================================================================
4426 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion
4427 ( const SMESH::long_array& theElems,
4428 const SMESH::long_array& theNodesNot,
4429 GEOM::GEOM_Object_ptr theShape )
4434 ::SMESH_MeshEditor aMeshEditor( myMesh );
4436 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4437 TIDSortedElemSet anElems, aNodes;
4438 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4439 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4441 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4442 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4444 storeResult( aMeshEditor) ;
4446 // Update Python script
4447 TPythonDump() << "isDone = " << this << ".DoubleNodesInRegion( " << theElems << ", "
4448 << theNodesNot << ", " << theShape << " )";
4452 //================================================================================
4454 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4455 \param theElems - group of of elements (edges or faces) to be replicated
4456 \param theNodesNot - group of nodes not to replicated
4457 \param theAffectedElems - group of elements to which the replicated nodes
4458 should be associated to.
4459 \return TRUE if operation has been completed successfully, FALSE otherwise
4460 \sa DoubleNodes(), DoubleNodeGroups()
4462 //================================================================================
4464 static void groupToSet(SMESH::SMESH_GroupBase_ptr theGrp,
4465 SMESHDS_Mesh* theMeshDS,
4466 TIDSortedElemSet& theElemSet,
4467 const SMDSAbs_ElementType theType)
4470 if ( CORBA::is_nil( theGrp ) )
4472 SMESH::long_array_var anIDs = theGrp->GetIDs();
4473 arrayToSet( anIDs, theMeshDS, theElemSet, theType);
4476 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(
4477 SMESH::SMESH_GroupBase_ptr theElems,
4478 SMESH::SMESH_GroupBase_ptr theNodesNot,
4479 SMESH::SMESH_GroupBase_ptr theAffectedElems )
4482 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4487 ::SMESH_MeshEditor aMeshEditor( myMesh );
4489 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4490 TIDSortedElemSet anElems, aNodes, anAffected;
4491 groupToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4492 groupToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4493 groupToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
4495 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4497 storeResult( aMeshEditor) ;
4499 // Update Python script
4500 TPythonDump() << "isDone = " << this << ".DoubleNodeGroup( " << theElems << ", "
4501 << theNodesNot << ", " << theAffectedElems << " )";
4505 //================================================================================
4507 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4508 \param theElems - group of of elements (edges or faces) to be replicated
4509 \param theNodesNot - group of nodes not to replicated
4510 \param theShape - shape to detect affected elements (element which geometric center
4511 located on or inside shape).
4512 The replicated nodes should be associated to affected elements.
4513 \return TRUE if operation has been completed successfully, FALSE otherwise
4514 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
4516 //================================================================================
4518 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(
4519 SMESH::SMESH_GroupBase_ptr theElems,
4520 SMESH::SMESH_GroupBase_ptr theNodesNot,
4521 GEOM::GEOM_Object_ptr theShape )
4524 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4529 ::SMESH_MeshEditor aMeshEditor( myMesh );
4531 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4532 TIDSortedElemSet anElems, aNodes, anAffected;
4533 groupToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4534 groupToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4536 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4537 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4539 storeResult( aMeshEditor) ;
4541 // Update Python script
4542 TPythonDump() << "isDone = " << this << ".DoubleNodeGroupInRegion( " << theElems << ", "
4543 << theNodesNot << ", " << theShape << " )";
4547 //================================================================================
4549 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4550 This method provided for convenience works as DoubleNodes() described above.
4551 \param theElems - list of groups of elements (edges or faces) to be replicated
4552 \param theNodesNot - list of groups of nodes not to replicated
4553 \param theAffectedElems - group of elements to which the replicated nodes
4554 should be associated to.
4555 \return TRUE if operation has been completed successfully, FALSE otherwise
4556 \sa DoubleNodeGroup(), DoubleNodes()
4558 //================================================================================
4560 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
4561 SMESHDS_Mesh* theMeshDS,
4562 TIDSortedElemSet& theElemSet,
4563 const bool theIsNodeGrp)
4565 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
4567 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
4568 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
4569 : aGrp->GetType() != SMESH::NODE ) )
4571 SMESH::long_array_var anIDs = aGrp->GetIDs();
4572 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
4577 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(
4578 const SMESH::ListOfGroups& theElems,
4579 const SMESH::ListOfGroups& theNodesNot,
4580 const SMESH::ListOfGroups& theAffectedElems )
4584 ::SMESH_MeshEditor aMeshEditor( myMesh );
4586 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4587 TIDSortedElemSet anElems, aNodes, anAffected;
4588 listOfGroupToSet(theElems, aMeshDS, anElems, false );
4589 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
4590 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
4592 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4594 storeResult( aMeshEditor) ;
4596 // Update Python script
4597 TPythonDump() << "isDone = " << this << ".DoubleNodeGroups( " << &theElems << ", "
4598 << &theNodesNot << ", " << &theAffectedElems << " )";
4602 //================================================================================
4604 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4605 This method provided for convenience works as DoubleNodes() described above.
4606 \param theElems - list of groups of elements (edges or faces) to be replicated
4607 \param theNodesNot - list of groups of nodes not to replicated
4608 \param theShape - shape to detect affected elements (element which geometric center
4609 located on or inside shape).
4610 The replicated nodes should be associated to affected elements.
4611 \return TRUE if operation has been completed successfully, FALSE otherwise
4612 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
4614 //================================================================================
4616 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(
4617 const SMESH::ListOfGroups& theElems,
4618 const SMESH::ListOfGroups& theNodesNot,
4619 GEOM::GEOM_Object_ptr theShape )
4623 ::SMESH_MeshEditor aMeshEditor( myMesh );
4625 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4626 TIDSortedElemSet anElems, aNodes;
4627 listOfGroupToSet(theElems, aMeshDS, anElems,false );
4628 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
4630 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4631 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4633 storeResult( aMeshEditor) ;
4635 // Update Python script
4636 TPythonDump() << "isDone = " << this << ".DoubleNodeGroupsInRegion( " << &theElems << ", "
4637 << &theNodesNot << ", " << theShape << " )";
4641 //================================================================================
4643 \brief Generated skin mesh (containing 2D cells) from 3D mesh
4644 The created 2D mesh elements based on nodes of free faces of boundary volumes
4645 \return TRUE if operation has been completed successfully, FALSE otherwise
4647 //================================================================================
4649 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
4653 ::SMESH_MeshEditor aMeshEditor( myMesh );
4654 bool aResult = aMeshEditor.Make2DMeshFrom3D();
4655 storeResult( aMeshEditor) ;
4657 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";