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 new SMESH::long_array( _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();
3371 //=======================================================================
3374 //=======================================================================
3376 SMESH::ListOfGroups*
3377 SMESH_MeshEditor_i::scale(const SMESH::long_array & theIDsOfElements,
3378 const SMESH::PointStruct& thePoint,
3379 const SMESH::double_array& theScaleFact,
3380 CORBA::Boolean theCopy,
3381 const bool theMakeGroups,
3382 ::SMESH_Mesh* theTargetMesh)
3386 TIDSortedElemSet elements;
3387 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3389 gp_Pnt aPnt( thePoint.x, thePoint.y, thePoint.z );
3390 list<double> aScaleFact;
3391 for (int i = 0; i < theScaleFact.length(); i++) {
3392 aScaleFact.push_back( theScaleFact[i] );
3395 ::SMESH_MeshEditor anEditor( myMesh );
3396 ::SMESH_MeshEditor::PGroupIDs groupIds =
3397 anEditor.Scale (elements, aPnt, aScaleFact, theCopy,
3398 theMakeGroups, theTargetMesh);
3401 storeResult(anEditor);
3403 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3407 //=======================================================================
3410 //=======================================================================
3412 void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr theObject,
3413 const SMESH::PointStruct& thePoint,
3414 const SMESH::double_array& theScaleFact,
3415 CORBA::Boolean theCopy)
3417 if ( !myPreviewMode ) {
3418 TPythonDump() << this << ".Scale( "
3419 << theObject << ", "
3420 << "SMESH.PointStruct( " << thePoint.x << ", "
3421 << thePoint.y << ", " << thePoint.z << " ) ,"
3422 << theScaleFact << ", "
3425 SMESH::long_array_var anElementsId = theObject->GetIDs();
3426 scale(anElementsId, thePoint, theScaleFact, theCopy, false);
3430 //=======================================================================
3431 //function : ScaleMakeGroups
3433 //=======================================================================
3435 SMESH::ListOfGroups*
3436 SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3437 const SMESH::PointStruct& thePoint,
3438 const SMESH::double_array& theScaleFact)
3440 SMESH::long_array_var anElementsId = theObject->GetIDs();
3441 SMESH::ListOfGroups * aGroups =
3442 scale(anElementsId, thePoint, theScaleFact, true, true);
3444 if ( !myPreviewMode ) {
3446 TPythonDump aPythonDump;
3447 DumpGroupsList(aPythonDump,aGroups);
3448 aPythonDump << this << ".Scale("
3450 << "SMESH.PointStruct(" <<thePoint.x << ","
3451 << thePoint.y << "," << thePoint.z << "),"
3452 << theScaleFact << ",True,True)";
3458 //=======================================================================
3459 //function : ScaleMakeMesh
3461 //=======================================================================
3463 SMESH::SMESH_Mesh_ptr
3464 SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3465 const SMESH::PointStruct& thePoint,
3466 const SMESH::double_array& theScaleFact,
3467 CORBA::Boolean theCopyGroups,
3468 const char* theMeshName)
3470 SMESH_Mesh_i* mesh_i;
3471 SMESH::SMESH_Mesh_var mesh;
3472 { // open new scope to dump "MakeMesh" command
3473 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3475 TPythonDump pydump; // to prevent dump at mesh creation
3476 mesh = makeMesh( theMeshName );
3477 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3480 SMESH::long_array_var anElementsId = theObject->GetIDs();
3481 scale(anElementsId, thePoint, theScaleFact,
3482 false, theCopyGroups, & mesh_i->GetImpl());
3483 mesh_i->CreateGroupServants();
3485 if ( !myPreviewMode ) {
3486 pydump << mesh << " = " << this << ".ScaleMakeMesh( "
3487 << theObject << ", "
3488 << "SMESH.PointStruct( " << thePoint.x << ", "
3489 << thePoint.y << ", " << thePoint.z << " ) ,"
3490 << theScaleFact << ", "
3491 << theCopyGroups << ", '"
3492 << theMeshName << "' )";
3497 if(!myPreviewMode && mesh_i)
3498 mesh_i->GetGroups();
3500 return mesh._retn();
3504 //=======================================================================
3505 //function : FindCoincidentNodes
3507 //=======================================================================
3509 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3510 SMESH::array_of_long_array_out GroupsOfNodes)
3514 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3515 ::SMESH_MeshEditor anEditor( myMesh );
3516 set<const SMDS_MeshNode*> nodes; // no input nodes
3517 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3519 GroupsOfNodes = new SMESH::array_of_long_array;
3520 GroupsOfNodes->length( aListOfListOfNodes.size() );
3521 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3522 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3523 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3524 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3525 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3526 aGroup.length( aListOfNodes.size() );
3527 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3528 aGroup[ j ] = (*lIt)->GetID();
3530 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3531 << Tolerance << " )";
3534 //=======================================================================
3535 //function : FindCoincidentNodesOnPart
3537 //=======================================================================
3538 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3539 CORBA::Double Tolerance,
3540 SMESH::array_of_long_array_out GroupsOfNodes)
3543 SMESH::long_array_var aElementsId = theObject->GetIDs();
3545 SMESHDS_Mesh* aMesh = GetMeshDS();
3546 set<const SMDS_MeshNode*> nodes;
3548 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
3549 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
3550 for(int i = 0; i < aElementsId->length(); i++) {
3551 CORBA::Long ind = aElementsId[i];
3552 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
3558 for(int i = 0; i < aElementsId->length(); i++) {
3559 CORBA::Long ind = aElementsId[i];
3560 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
3562 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
3563 while ( nIt->more() )
3564 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
3570 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3571 ::SMESH_MeshEditor anEditor( myMesh );
3573 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3575 GroupsOfNodes = new SMESH::array_of_long_array;
3576 GroupsOfNodes->length( aListOfListOfNodes.size() );
3577 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3578 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3579 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3580 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3581 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3582 aGroup.length( aListOfNodes.size() );
3583 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3584 aGroup[ j ] = (*lIt)->GetID();
3586 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3588 << Tolerance << " )";
3591 //=======================================================================
3592 //function : MergeNodes
3594 //=======================================================================
3596 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3600 SMESHDS_Mesh* aMesh = GetMeshDS();
3602 TPythonDump aTPythonDump;
3603 aTPythonDump << this << ".MergeNodes([";
3604 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3605 for (int i = 0; i < GroupsOfNodes.length(); i++)
3607 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3608 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3609 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3610 for ( int j = 0; j < aNodeGroup.length(); j++ )
3612 CORBA::Long index = aNodeGroup[ j ];
3613 const SMDS_MeshNode * node = aMesh->FindNode(index);
3615 aListOfNodes.push_back( node );
3617 if ( aListOfNodes.size() < 2 )
3618 aListOfListOfNodes.pop_back();
3620 if ( i > 0 ) aTPythonDump << ", ";
3621 aTPythonDump << aNodeGroup;
3623 ::SMESH_MeshEditor anEditor( myMesh );
3624 anEditor.MergeNodes( aListOfListOfNodes );
3626 aTPythonDump << "])";
3629 //=======================================================================
3630 //function : FindEqualElements
3632 //=======================================================================
3633 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3634 SMESH::array_of_long_array_out GroupsOfElementsID)
3637 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
3638 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
3639 typedef list<int> TListOfIDs;
3640 set<const SMDS_MeshElement*> elems;
3641 SMESH::long_array_var aElementsId = theObject->GetIDs();
3642 SMESHDS_Mesh* aMesh = GetMeshDS();
3644 for(int i = 0; i < aElementsId->length(); i++) {
3645 CORBA::Long anID = aElementsId[i];
3646 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3652 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3653 ::SMESH_MeshEditor anEditor( myMesh );
3654 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3656 GroupsOfElementsID = new SMESH::array_of_long_array;
3657 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3659 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3660 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3661 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3662 TListOfIDs& listOfIDs = *arraysIt;
3663 aGroup.length( listOfIDs.size() );
3664 TListOfIDs::iterator idIt = listOfIDs.begin();
3665 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3666 aGroup[ k ] = *idIt;
3670 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3675 //=======================================================================
3676 //function : MergeElements
3678 //=======================================================================
3680 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3684 TPythonDump aTPythonDump;
3685 aTPythonDump << this << ".MergeElements( [";
3687 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3689 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3690 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3691 aListOfListOfElementsID.push_back( list< int >() );
3692 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3693 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3694 CORBA::Long id = anElemsIDGroup[ j ];
3695 aListOfElemsID.push_back( id );
3697 if ( aListOfElemsID.size() < 2 )
3698 aListOfListOfElementsID.pop_back();
3699 if ( i > 0 ) aTPythonDump << ", ";
3700 aTPythonDump << anElemsIDGroup;
3703 ::SMESH_MeshEditor anEditor( myMesh );
3704 anEditor.MergeElements(aListOfListOfElementsID);
3706 aTPythonDump << "] )";
3709 //=======================================================================
3710 //function : MergeEqualElements
3712 //=======================================================================
3714 void SMESH_MeshEditor_i::MergeEqualElements()
3718 ::SMESH_MeshEditor anEditor( myMesh );
3719 anEditor.MergeEqualElements();
3721 TPythonDump() << this << ".MergeEqualElements()";
3724 //=============================================================================
3726 * Move the node to a given point
3728 //=============================================================================
3730 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
3735 initData(/*deleteSearchers=*/false);
3737 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
3741 if ( theNodeSearcher )
3742 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3744 if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3745 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3747 GetMeshDS()->MoveNode(node, x, y, z);
3749 // Update Python script
3750 TPythonDump() << "isDone = " << this << ".MoveNode( "
3751 << NodeID << ", " << x << ", " << y << ", " << z << " )";
3756 //================================================================================
3758 * \brief Return ID of node closest to a given point
3760 //================================================================================
3762 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
3766 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3768 if ( !theNodeSearcher ) {
3769 ::SMESH_MeshEditor anEditor( myMesh );
3770 theNodeSearcher = anEditor.GetNodeSearcher();
3773 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
3774 return node->GetID();
3779 //================================================================================
3781 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
3782 * move the node closest to the point to point's location and return ID of the node
3784 //================================================================================
3786 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
3789 CORBA::Long theNodeID)
3791 // We keep theNodeSearcher until any mesh modification:
3792 // 1) initData() deletes theNodeSearcher at any edition,
3793 // 2) TSearchersDeleter - at any mesh compute event and mesh change
3795 initData(/*deleteSearchers=*/false);
3797 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3799 int nodeID = theNodeID;
3800 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
3801 if ( !node ) // preview moving node
3803 if ( !theNodeSearcher ) {
3804 ::SMESH_MeshEditor anEditor( myMesh );
3805 theNodeSearcher = anEditor.GetNodeSearcher();
3808 node = theNodeSearcher->FindClosestTo( p );
3811 nodeID = node->GetID();
3812 if ( myPreviewMode ) // make preview data
3814 // in a preview mesh, make edges linked to a node
3815 TPreviewMesh tmpMesh;
3816 TIDSortedElemSet linkedNodes;
3817 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3818 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3819 for ( ; nIt != linkedNodes.end(); ++nIt )
3821 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
3822 tmpMesh.Copy( &edge );
3825 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
3827 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
3828 // fill preview data
3829 ::SMESH_MeshEditor anEditor( & tmpMesh );
3830 storeResult( anEditor );
3832 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3834 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3838 GetMeshDS()->MoveNode(node, x, y, z);
3842 if ( !myPreviewMode ) {
3843 TPythonDump() << "nodeID = " << this
3844 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
3845 << ", " << nodeID << " )";
3851 //=======================================================================
3853 * Return elements of given type where the given point is IN or ON.
3855 * 'ALL' type means elements of any type excluding nodes
3857 //=======================================================================
3859 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
3862 SMESH::ElementType type)
3864 SMESH::long_array_var res = new SMESH::long_array;
3865 vector< const SMDS_MeshElement* > foundElems;
3867 theSearchersDeleter.Set( myMesh );
3868 if ( !theElementSearcher ) {
3869 ::SMESH_MeshEditor anEditor( myMesh );
3870 theElementSearcher = anEditor.GetElementSearcher();
3872 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
3873 SMDSAbs_ElementType( type ),
3875 res->length( foundElems.size() );
3876 for ( int i = 0; i < foundElems.size(); ++i )
3877 res[i] = foundElems[i]->GetID();
3879 if ( !myPreviewMode ) // call from tui
3880 TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
3889 //=======================================================================
3890 //function : convError
3892 //=======================================================================
3894 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
3896 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
3900 RETCASE( SEW_BORDER1_NOT_FOUND );
3901 RETCASE( SEW_BORDER2_NOT_FOUND );
3902 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
3903 RETCASE( SEW_BAD_SIDE_NODES );
3904 RETCASE( SEW_VOLUMES_TO_SPLIT );
3905 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
3906 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
3907 RETCASE( SEW_BAD_SIDE1_NODES );
3908 RETCASE( SEW_BAD_SIDE2_NODES );
3910 return SMESH::SMESH_MeshEditor::SEW_OK;
3913 //=======================================================================
3914 //function : SewFreeBorders
3916 //=======================================================================
3918 SMESH::SMESH_MeshEditor::Sew_Error
3919 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
3920 CORBA::Long SecondNodeID1,
3921 CORBA::Long LastNodeID1,
3922 CORBA::Long FirstNodeID2,
3923 CORBA::Long SecondNodeID2,
3924 CORBA::Long LastNodeID2,
3925 CORBA::Boolean CreatePolygons,
3926 CORBA::Boolean CreatePolyedrs)
3930 SMESHDS_Mesh* aMesh = GetMeshDS();
3932 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3933 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3934 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3935 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3936 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3937 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
3939 if (!aBorderFirstNode ||
3940 !aBorderSecondNode||
3942 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3943 if (!aSide2FirstNode ||
3944 !aSide2SecondNode ||
3946 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3948 TPythonDump() << "error = " << this << ".SewFreeBorders( "
3949 << FirstNodeID1 << ", "
3950 << SecondNodeID1 << ", "
3951 << LastNodeID1 << ", "
3952 << FirstNodeID2 << ", "
3953 << SecondNodeID2 << ", "
3954 << LastNodeID2 << ", "
3955 << CreatePolygons<< ", "
3956 << CreatePolyedrs<< " )";
3958 ::SMESH_MeshEditor anEditor( myMesh );
3959 SMESH::SMESH_MeshEditor::Sew_Error error =
3960 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3970 storeResult(anEditor);
3976 //=======================================================================
3977 //function : SewConformFreeBorders
3979 //=======================================================================
3981 SMESH::SMESH_MeshEditor::Sew_Error
3982 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3983 CORBA::Long SecondNodeID1,
3984 CORBA::Long LastNodeID1,
3985 CORBA::Long FirstNodeID2,
3986 CORBA::Long SecondNodeID2)
3990 SMESHDS_Mesh* aMesh = GetMeshDS();
3992 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3993 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3994 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3995 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3996 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3997 const SMDS_MeshNode* aSide2ThirdNode = 0;
3999 if (!aBorderFirstNode ||
4000 !aBorderSecondNode||
4002 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4003 if (!aSide2FirstNode ||
4005 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4007 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
4008 << FirstNodeID1 << ", "
4009 << SecondNodeID1 << ", "
4010 << LastNodeID1 << ", "
4011 << FirstNodeID2 << ", "
4012 << SecondNodeID2 << " )";
4014 ::SMESH_MeshEditor anEditor( myMesh );
4015 SMESH::SMESH_MeshEditor::Sew_Error error =
4016 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4025 storeResult(anEditor);
4031 //=======================================================================
4032 //function : SewBorderToSide
4034 //=======================================================================
4036 SMESH::SMESH_MeshEditor::Sew_Error
4037 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
4038 CORBA::Long SecondNodeIDOnFreeBorder,
4039 CORBA::Long LastNodeIDOnFreeBorder,
4040 CORBA::Long FirstNodeIDOnSide,
4041 CORBA::Long LastNodeIDOnSide,
4042 CORBA::Boolean CreatePolygons,
4043 CORBA::Boolean CreatePolyedrs)
4047 SMESHDS_Mesh* aMesh = GetMeshDS();
4049 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
4050 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
4051 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
4052 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
4053 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
4054 const SMDS_MeshNode* aSide2ThirdNode = 0;
4056 if (!aBorderFirstNode ||
4057 !aBorderSecondNode||
4059 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4060 if (!aSide2FirstNode ||
4062 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
4064 TPythonDump() << "error = " << this << ".SewBorderToSide( "
4065 << FirstNodeIDOnFreeBorder << ", "
4066 << SecondNodeIDOnFreeBorder << ", "
4067 << LastNodeIDOnFreeBorder << ", "
4068 << FirstNodeIDOnSide << ", "
4069 << LastNodeIDOnSide << ", "
4070 << CreatePolygons << ", "
4071 << CreatePolyedrs << ") ";
4073 ::SMESH_MeshEditor anEditor( myMesh );
4074 SMESH::SMESH_MeshEditor::Sew_Error error =
4075 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4085 storeResult(anEditor);
4091 //=======================================================================
4092 //function : SewSideElements
4094 //=======================================================================
4096 SMESH::SMESH_MeshEditor::Sew_Error
4097 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
4098 const SMESH::long_array& IDsOfSide2Elements,
4099 CORBA::Long NodeID1OfSide1ToMerge,
4100 CORBA::Long NodeID1OfSide2ToMerge,
4101 CORBA::Long NodeID2OfSide1ToMerge,
4102 CORBA::Long NodeID2OfSide2ToMerge)
4106 SMESHDS_Mesh* aMesh = GetMeshDS();
4108 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
4109 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
4110 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
4111 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
4113 if (!aFirstNode1ToMerge ||
4114 !aFirstNode2ToMerge )
4115 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
4116 if (!aSecondNode1ToMerge||
4117 !aSecondNode2ToMerge)
4118 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
4120 TIDSortedElemSet aSide1Elems, aSide2Elems;
4121 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
4122 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
4124 TPythonDump() << "error = " << this << ".SewSideElements( "
4125 << IDsOfSide1Elements << ", "
4126 << IDsOfSide2Elements << ", "
4127 << NodeID1OfSide1ToMerge << ", "
4128 << NodeID1OfSide2ToMerge << ", "
4129 << NodeID2OfSide1ToMerge << ", "
4130 << NodeID2OfSide2ToMerge << ")";
4132 ::SMESH_MeshEditor anEditor( myMesh );
4133 SMESH::SMESH_MeshEditor::Sew_Error error =
4134 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
4137 aSecondNode1ToMerge,
4138 aSecondNode2ToMerge));
4140 storeResult(anEditor);
4145 //================================================================================
4147 * \brief Set new nodes for given element
4148 * \param ide - element id
4149 * \param newIDs - new node ids
4150 * \retval CORBA::Boolean - true if result is OK
4152 //================================================================================
4154 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
4155 const SMESH::long_array& newIDs)
4159 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
4160 if(!elem) return false;
4162 int nbn = newIDs.length();
4164 vector<const SMDS_MeshNode*> aNodes(nbn);
4167 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
4170 aNodes[nbn1] = aNode;
4173 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
4174 << ide << ", " << newIDs << " )";
4176 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
4179 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
4182 //================================================================================
4184 * \brief Update myLastCreated* or myPreviewData
4185 * \param anEditor - it contains last modification results
4187 //================================================================================
4189 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
4191 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
4193 list<int> aNodesConnectivity;
4194 typedef map<int, int> TNodesMap;
4197 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
4198 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
4200 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
4201 int nbEdges = aMeshDS->NbEdges();
4202 int nbFaces = aMeshDS->NbFaces();
4203 int nbVolum = aMeshDS->NbVolumes();
4204 switch ( previewType ) {
4205 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
4206 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
4207 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
4210 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
4211 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
4213 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
4215 while ( itMeshElems->more() ) {
4216 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
4217 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
4220 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
4221 while ( itElemNodes->more() ) {
4222 const SMDS_MeshNode* aMeshNode =
4223 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
4224 int aNodeID = aMeshNode->GetID();
4225 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
4226 if ( anIter == nodesMap.end() ) {
4227 // filling the nodes coordinates
4228 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
4229 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
4230 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
4231 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4234 aNodesConnectivity.push_back(anIter->second);
4237 // filling the elements types
4238 SMDSAbs_ElementType aType;
4240 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4241 aType = SMDSAbs_Node;
4245 aType = aMeshElem->GetType();
4246 isPoly = aMeshElem->IsPoly();
4249 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4250 myPreviewData->elementTypes[i].isPoly = isPoly;
4251 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4255 myPreviewData->nodesXYZ.length( j );
4257 // filling the elements connectivities
4258 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4259 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4260 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4261 myPreviewData->elementConnectivities[i] = *aConnIter;
4267 // add new nodes into myLastCreatedNodes
4268 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4269 myLastCreatedNodes->length(aSeq.Length());
4270 for(int i=0; i<aSeq.Length(); i++)
4271 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4274 // add new elements into myLastCreatedElems
4275 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4276 myLastCreatedElems->length(aSeq.Length());
4277 for(int i=0; i<aSeq.Length(); i++)
4278 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4282 //================================================================================
4284 * Return data of mesh edition preview
4286 //================================================================================
4288 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4290 return myPreviewData._retn();
4293 //================================================================================
4295 * \brief Returns list of it's IDs of created nodes
4296 * \retval SMESH::long_array* - list of node ID
4298 //================================================================================
4300 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4302 return myLastCreatedNodes._retn();
4305 //================================================================================
4307 * \brief Returns list of it's IDs of created elements
4308 * \retval SMESH::long_array* - list of elements' ID
4310 //================================================================================
4312 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4314 return myLastCreatedElems._retn();
4317 //=======================================================================
4318 //function : ConvertToQuadratic
4320 //=======================================================================
4322 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4324 ::SMESH_MeshEditor anEditor( myMesh );
4325 anEditor.ConvertToQuadratic(theForce3d);
4326 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4329 //=======================================================================
4330 //function : ConvertFromQuadratic
4332 //=======================================================================
4334 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4336 ::SMESH_MeshEditor anEditor( myMesh );
4337 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4338 TPythonDump() << this << ".ConvertFromQuadratic()";
4342 //=======================================================================
4343 //function : makeMesh
4344 //purpose : create a named imported mesh
4345 //=======================================================================
4347 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4349 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4350 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4351 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4352 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4353 gen->SetName( meshSO, theMeshName, "Mesh" );
4354 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4356 return mesh._retn();
4359 //=======================================================================
4360 //function : DumpGroupsList
4362 //=======================================================================
4363 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4364 const SMESH::ListOfGroups * theGroupList)
4366 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4367 if(isDumpGroupList) {
4368 theDumpPython << theGroupList << " = ";
4372 //================================================================================
4374 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4375 \param theNodes - identifiers of nodes to be doubled
4376 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4377 nodes. If list of element identifiers is empty then nodes are doubled but
4378 they not assigned to elements
4379 \return TRUE if operation has been completed successfully, FALSE otherwise
4380 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4382 //================================================================================
4384 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4385 const SMESH::long_array& theModifiedElems )
4389 ::SMESH_MeshEditor aMeshEditor( myMesh );
4390 list< int > aListOfNodes;
4392 for ( i = 0, n = theNodes.length(); i < n; i++ )
4393 aListOfNodes.push_back( theNodes[ i ] );
4395 list< int > aListOfElems;
4396 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4397 aListOfElems.push_back( theModifiedElems[ i ] );
4399 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4401 storeResult( aMeshEditor) ;
4406 //================================================================================
4408 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4409 This method provided for convenience works as DoubleNodes() described above.
4410 \param theNodeId - identifier of node to be doubled.
4411 \param theModifiedElems - identifiers of elements to be updated.
4412 \return TRUE if operation has been completed successfully, FALSE otherwise
4413 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4415 //================================================================================
4417 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4418 const SMESH::long_array& theModifiedElems )
4420 SMESH::long_array_var aNodes = new SMESH::long_array;
4421 aNodes->length( 1 );
4422 aNodes[ 0 ] = theNodeId;
4423 return DoubleNodes( aNodes, theModifiedElems );
4426 //================================================================================
4428 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4429 This method provided for convenience works as DoubleNodes() described above.
4430 \param theNodes - group of nodes to be doubled.
4431 \param theModifiedElems - group of elements to be updated.
4432 \return TRUE if operation has been completed successfully, FALSE otherwise
4433 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
4435 //================================================================================
4437 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(
4438 SMESH::SMESH_GroupBase_ptr theNodes,
4439 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4441 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4444 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4445 SMESH::long_array_var aModifiedElems;
4446 if ( !CORBA::is_nil( theModifiedElems ) )
4447 aModifiedElems = theModifiedElems->GetListOfID();
4450 aModifiedElems = new SMESH::long_array;
4451 aModifiedElems->length( 0 );
4454 return DoubleNodes( aNodes, aModifiedElems );
4457 //================================================================================
4459 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4460 This method provided for convenience works as DoubleNodes() described above.
4461 \param theNodes - list of groups of nodes to be doubled
4462 \param theModifiedElems - list of groups of elements to be updated.
4463 \return TRUE if operation has been completed successfully, FALSE otherwise
4464 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
4466 //================================================================================
4468 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(
4469 const SMESH::ListOfGroups& theNodes,
4470 const SMESH::ListOfGroups& theModifiedElems )
4474 ::SMESH_MeshEditor aMeshEditor( myMesh );
4476 std::list< int > aNodes;
4478 for ( i = 0, n = theNodes.length(); i < n; i++ )
4480 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
4481 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
4483 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4484 for ( j = 0, m = aCurr->length(); j < m; j++ )
4485 aNodes.push_back( aCurr[ j ] );
4489 std::list< int > anElems;
4490 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4492 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
4493 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
4495 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4496 for ( j = 0, m = aCurr->length(); j < m; j++ )
4497 anElems.push_back( aCurr[ j ] );
4501 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
4503 storeResult( aMeshEditor) ;
4508 //================================================================================
4510 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4511 \param theElems - the list of elements (edges or faces) to be replicated
4512 The nodes for duplication could be found from these elements
4513 \param theNodesNot - list of nodes to NOT replicate
4514 \param theAffectedElems - the list of elements (cells and edges) to which the
4515 replicated nodes should be associated to.
4516 \return TRUE if operation has been completed successfully, FALSE otherwise
4517 \sa DoubleNodeGroup(), DoubleNodeGroups()
4519 //================================================================================
4521 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
4522 const SMESH::long_array& theNodesNot,
4523 const SMESH::long_array& theAffectedElems )
4528 ::SMESH_MeshEditor aMeshEditor( myMesh );
4530 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4531 TIDSortedElemSet anElems, aNodes, anAffected;
4532 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4533 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4534 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
4536 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4538 storeResult( aMeshEditor) ;
4540 // Update Python script
4541 TPythonDump() << "isDone = " << this << ".DoubleNodes( " << theElems << ", "
4542 << theNodesNot << ", " << theAffectedElems << " )";
4546 //================================================================================
4548 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4549 \param theElems - the list of elements (edges or faces) to be replicated
4550 The nodes for duplication could be found from these elements
4551 \param theNodesNot - list of nodes to NOT replicate
4552 \param theShape - shape to detect affected elements (element which geometric center
4553 located on or inside shape).
4554 The replicated nodes should be associated to affected elements.
4555 \return TRUE if operation has been completed successfully, FALSE otherwise
4556 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
4558 //================================================================================
4560 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion
4561 ( const SMESH::long_array& theElems,
4562 const SMESH::long_array& theNodesNot,
4563 GEOM::GEOM_Object_ptr theShape )
4568 ::SMESH_MeshEditor aMeshEditor( myMesh );
4570 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4571 TIDSortedElemSet anElems, aNodes;
4572 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4573 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4575 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4576 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4578 storeResult( aMeshEditor) ;
4580 // Update Python script
4581 TPythonDump() << "isDone = " << this << ".DoubleNodesInRegion( " << theElems << ", "
4582 << theNodesNot << ", " << theShape << " )";
4586 //================================================================================
4588 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4589 \param theElems - group of of elements (edges or faces) to be replicated
4590 \param theNodesNot - group of nodes not to replicated
4591 \param theAffectedElems - group of elements to which the replicated nodes
4592 should be associated to.
4593 \return TRUE if operation has been completed successfully, FALSE otherwise
4594 \sa DoubleNodes(), DoubleNodeGroups()
4596 //================================================================================
4598 static void groupToSet(SMESH::SMESH_GroupBase_ptr theGrp,
4599 SMESHDS_Mesh* theMeshDS,
4600 TIDSortedElemSet& theElemSet,
4601 const SMDSAbs_ElementType theType)
4604 if ( CORBA::is_nil( theGrp ) )
4606 SMESH::long_array_var anIDs = theGrp->GetIDs();
4607 arrayToSet( anIDs, theMeshDS, theElemSet, theType);
4610 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(
4611 SMESH::SMESH_GroupBase_ptr theElems,
4612 SMESH::SMESH_GroupBase_ptr theNodesNot,
4613 SMESH::SMESH_GroupBase_ptr theAffectedElems )
4616 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4621 ::SMESH_MeshEditor aMeshEditor( myMesh );
4623 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4624 TIDSortedElemSet anElems, aNodes, anAffected;
4625 groupToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4626 groupToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4627 groupToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
4629 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4631 storeResult( aMeshEditor) ;
4633 // Update Python script
4634 TPythonDump() << "isDone = " << this << ".DoubleNodeGroup( " << theElems << ", "
4635 << theNodesNot << ", " << theAffectedElems << " )";
4639 //================================================================================
4641 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4642 \param theElems - group of of elements (edges or faces) to be replicated
4643 \param theNodesNot - group of nodes not to replicated
4644 \param theShape - shape to detect affected elements (element which geometric center
4645 located on or inside shape).
4646 The replicated nodes should be associated to affected elements.
4647 \return TRUE if operation has been completed successfully, FALSE otherwise
4648 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
4650 //================================================================================
4652 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(
4653 SMESH::SMESH_GroupBase_ptr theElems,
4654 SMESH::SMESH_GroupBase_ptr theNodesNot,
4655 GEOM::GEOM_Object_ptr theShape )
4658 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4663 ::SMESH_MeshEditor aMeshEditor( myMesh );
4665 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4666 TIDSortedElemSet anElems, aNodes, anAffected;
4667 groupToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4668 groupToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4670 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4671 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4673 storeResult( aMeshEditor) ;
4675 // Update Python script
4676 TPythonDump() << "isDone = " << this << ".DoubleNodeGroupInRegion( " << theElems << ", "
4677 << theNodesNot << ", " << theShape << " )";
4681 //================================================================================
4683 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4684 This method provided for convenience works as DoubleNodes() described above.
4685 \param theElems - list of groups of elements (edges or faces) to be replicated
4686 \param theNodesNot - list of groups of nodes not to replicated
4687 \param theAffectedElems - group of elements to which the replicated nodes
4688 should be associated to.
4689 \return TRUE if operation has been completed successfully, FALSE otherwise
4690 \sa DoubleNodeGroup(), DoubleNodes()
4692 //================================================================================
4694 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
4695 SMESHDS_Mesh* theMeshDS,
4696 TIDSortedElemSet& theElemSet,
4697 const bool theIsNodeGrp)
4699 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
4701 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
4702 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
4703 : aGrp->GetType() != SMESH::NODE ) )
4705 SMESH::long_array_var anIDs = aGrp->GetIDs();
4706 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
4711 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(
4712 const SMESH::ListOfGroups& theElems,
4713 const SMESH::ListOfGroups& theNodesNot,
4714 const SMESH::ListOfGroups& theAffectedElems )
4718 ::SMESH_MeshEditor aMeshEditor( myMesh );
4720 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4721 TIDSortedElemSet anElems, aNodes, anAffected;
4722 listOfGroupToSet(theElems, aMeshDS, anElems, false );
4723 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
4724 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
4726 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4728 storeResult( aMeshEditor) ;
4730 // Update Python script
4731 TPythonDump() << "isDone = " << this << ".DoubleNodeGroups( " << &theElems << ", "
4732 << &theNodesNot << ", " << &theAffectedElems << " )";
4736 //================================================================================
4738 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4739 This method provided for convenience works as DoubleNodes() described above.
4740 \param theElems - list of groups of elements (edges or faces) to be replicated
4741 \param theNodesNot - list of groups of nodes not to replicated
4742 \param theShape - shape to detect affected elements (element which geometric center
4743 located on or inside shape).
4744 The replicated nodes should be associated to affected elements.
4745 \return TRUE if operation has been completed successfully, FALSE otherwise
4746 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
4748 //================================================================================
4750 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(
4751 const SMESH::ListOfGroups& theElems,
4752 const SMESH::ListOfGroups& theNodesNot,
4753 GEOM::GEOM_Object_ptr theShape )
4757 ::SMESH_MeshEditor aMeshEditor( myMesh );
4759 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4760 TIDSortedElemSet anElems, aNodes;
4761 listOfGroupToSet(theElems, aMeshDS, anElems,false );
4762 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
4764 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4765 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4767 storeResult( aMeshEditor) ;
4769 // Update Python script
4770 TPythonDump() << "isDone = " << this << ".DoubleNodeGroupsInRegion( " << &theElems << ", "
4771 << &theNodesNot << ", " << theShape << " )";
4775 //================================================================================
4777 \brief Generated skin mesh (containing 2D cells) from 3D mesh
4778 The created 2D mesh elements based on nodes of free faces of boundary volumes
4779 \return TRUE if operation has been completed successfully, FALSE otherwise
4781 //================================================================================
4783 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
4787 ::SMESH_MeshEditor aMeshEditor( myMesh );
4788 bool aResult = aMeshEditor.Make2DMeshFrom3D();
4789 storeResult( aMeshEditor) ;
4791 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";