1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 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
24 // File : SMESH_MeshEditor_i.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESH_MeshEditor_i.hxx"
31 #include "SMDS_MeshEdge.hxx"
32 #include "SMDS_MeshFace.hxx"
33 #include "SMDS_MeshVolume.hxx"
34 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
35 #include "SMESH_MeshEditor.hxx"
36 #include "SMESH_subMeshEventListener.hxx"
37 #include "SMESH_Gen_i.hxx"
38 #include "SMESH_Filter_i.hxx"
39 #include "SMESH_PythonDump.hxx"
41 #include "CASCatch.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>
65 #include "CASCatch.hxx"
70 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
73 using SMESH::TPythonDump;
77 //=============================================================================
79 * \brief Mesh to apply modifications for preview purposes
81 //=============================================================================
83 struct TPreviewMesh: public SMESH_Mesh
85 SMDSAbs_ElementType myPreviewType; // type to show
87 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
88 _isShapeToMesh = _id =_studyId =_idDoc = 0;
89 _myMeshDS = new SMESHDS_Mesh( _id, true );
90 myPreviewType = previewElements;
93 virtual ~TPreviewMesh() { delete _myMeshDS; }
94 //!< Copy a set of elements
95 void Copy(const TIDSortedElemSet & theElements,
96 TIDSortedElemSet& theCopyElements,
97 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
98 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
100 // loop on theIDsOfElements
101 TIDSortedElemSet::const_iterator eIt = theElements.begin();
102 for ( ; eIt != theElements.end(); ++eIt )
104 const SMDS_MeshElement* anElem = *eIt;
105 if ( !anElem ) continue;
106 SMDSAbs_ElementType type = anElem->GetType();
107 if ( type == theAvoidType ||
108 ( theSelectType != SMDSAbs_All && type != theSelectType ))
111 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
112 theCopyElements.insert( theCopyElements.end(), anElemCopy );
116 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
118 // copy element nodes
119 int anElemNbNodes = anElem->NbNodes();
120 vector< int > anElemNodesID( anElemNbNodes ) ;
121 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
122 for ( int i = 0; itElemNodes->more(); i++)
124 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
126 anElemNodesID[i] = anElemNode->GetID();
129 // creates a corresponding element on copied nodes
130 SMDS_MeshElement* anElemCopy = 0;
131 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
133 const SMDS_PolyhedralVolumeOfNodes* ph =
134 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
136 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
137 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
140 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
147 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
149 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
150 anElemNode->GetID());
152 };// struct TPreviewMesh
154 static SMESH_NodeSearcher * myNodeSearcher = 0;
156 //=============================================================================
158 * \brief Deleter of myNodeSearcher at any compute event occured
160 //=============================================================================
162 struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
166 TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
168 //!< Delete myNodeSearcher
171 if ( myNodeSearcher ) { delete myNodeSearcher; myNodeSearcher = 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 myNodeSearcher if other mesh is set
184 void Set(SMESH_Mesh* mesh)
186 if ( myMesh && myMesh != mesh ) {
191 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
192 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
193 TDependsOnMap::const_iterator sm;
194 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
195 sm->second->SetEventListener( this, 0, sm->second );
198 //!< delete self from all submeshes
199 void Unset(SMESH_Mesh* mesh)
201 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
202 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
203 TDependsOnMap::const_iterator sm;
204 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
205 sm->second->DeleteEventListener( this );
210 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
212 TCollection_AsciiString typeStr;
213 switch ( theMirrorType ) {
214 case SMESH::SMESH_MeshEditor::POINT:
215 typeStr = "SMESH.SMESH_MeshEditor.POINT";
217 case SMESH::SMESH_MeshEditor::AXIS:
218 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
221 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
227 //=============================================================================
231 //=============================================================================
233 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
236 myMesh = & theMesh->GetImpl();
237 myPreviewMode = isPreview;
240 //================================================================================
244 //================================================================================
246 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
250 //================================================================================
252 * \brief Clear members
254 //================================================================================
256 void SMESH_MeshEditor_i::initData()
258 if ( myPreviewMode ) {
259 myPreviewData = new SMESH::MeshPreviewStruct();
262 myLastCreatedElems = new SMESH::long_array();
263 myLastCreatedNodes = new SMESH::long_array();
264 TNodeSearcherDeleter::Delete();
268 //=============================================================================
272 //=============================================================================
275 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
279 ::SMESH_MeshEditor anEditor( myMesh );
282 for (int i = 0; i < IDsOfElements.length(); i++)
283 IdList.push_back( IDsOfElements[i] );
285 // Update Python script
286 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
288 TPythonDump() << "print 'RemoveElements: ', isDone";
291 return anEditor.Remove( IdList, false );
294 //=============================================================================
298 //=============================================================================
300 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
304 ::SMESH_MeshEditor anEditor( myMesh );
306 for (int i = 0; i < IDsOfNodes.length(); i++)
307 IdList.push_back( IDsOfNodes[i] );
309 // Update Python script
310 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
312 TPythonDump() << "print 'RemoveNodes: ', isDone";
315 return anEditor.Remove( IdList, true );
318 //=============================================================================
322 //=============================================================================
324 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
328 int NbNodes = IDsOfNodes.length();
329 SMDS_MeshElement* elem = 0;
332 CORBA::Long index1 = IDsOfNodes[0];
333 CORBA::Long index2 = IDsOfNodes[1];
334 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
336 // Update Python script
337 TPythonDump() << "edge = " << this << ".AddEdge([ "
338 << index1 << ", " << index2 <<" ])";
341 CORBA::Long n1 = IDsOfNodes[0];
342 CORBA::Long n2 = IDsOfNodes[1];
343 CORBA::Long n12 = IDsOfNodes[2];
344 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
345 GetMeshDS()->FindNode(n2),
346 GetMeshDS()->FindNode(n12));
347 // Update Python script
348 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
349 <<n1<<", "<<n2<<", "<<n12<<" ])";
353 return elem->GetID();
358 //=============================================================================
362 //=============================================================================
364 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
365 CORBA::Double y, CORBA::Double z)
369 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
371 // Update Python script
372 TPythonDump() << "nodeID = " << this << ".AddNode( "
373 << x << ", " << y << ", " << z << " )";
378 //=============================================================================
382 //=============================================================================
384 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
388 int NbNodes = IDsOfNodes.length();
394 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
395 for (int i = 0; i < NbNodes; i++)
396 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
398 SMDS_MeshElement* elem = 0;
400 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
402 else if (NbNodes == 4) {
403 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
405 else if (NbNodes == 6) {
406 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
409 else if (NbNodes == 8) {
410 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
411 nodes[4], nodes[5], nodes[6], nodes[7]);
414 // Update Python script
415 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
418 return elem->GetID();
423 //=============================================================================
427 //=============================================================================
428 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
429 (const SMESH::long_array & IDsOfNodes)
433 int NbNodes = IDsOfNodes.length();
434 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
435 for (int i = 0; i < NbNodes; i++)
436 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
438 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
440 // Update Python script
441 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
443 TPythonDump() << "print 'AddPolygonalFace: ', faceID";
447 return elem->GetID();
452 //=============================================================================
456 //=============================================================================
458 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
462 int NbNodes = IDsOfNodes.length();
463 vector< const SMDS_MeshNode*> n(NbNodes);
464 for(int i=0;i<NbNodes;i++)
465 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
467 SMDS_MeshElement* elem = 0;
470 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
471 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
472 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
473 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
474 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
475 n[6],n[7],n[8],n[9]);
477 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
478 n[7],n[8],n[9],n[10],n[11],n[12]);
480 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
481 n[9],n[10],n[11],n[12],n[13],n[14]);
483 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
484 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
485 n[15],n[16],n[17],n[18],n[19]);
489 // Update Python script
490 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
492 TPythonDump() << "print 'AddVolume: ', volID";
496 return elem->GetID();
501 //=============================================================================
503 * AddPolyhedralVolume
505 //=============================================================================
506 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume
507 (const SMESH::long_array & IDsOfNodes,
508 const SMESH::long_array & Quantities)
512 int NbNodes = IDsOfNodes.length();
513 std::vector<const SMDS_MeshNode*> n (NbNodes);
514 for (int i = 0; i < NbNodes; i++)
515 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
517 int NbFaces = Quantities.length();
518 std::vector<int> q (NbFaces);
519 for (int j = 0; j < NbFaces; j++)
520 q[j] = Quantities[j];
522 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
524 // Update Python script
525 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
526 << IDsOfNodes << ", " << Quantities << " )";
528 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
532 return elem->GetID();
537 //=============================================================================
539 * AddPolyhedralVolumeByFaces
541 //=============================================================================
542 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
543 (const SMESH::long_array & IdsOfFaces)
547 int NbFaces = IdsOfFaces.length();
548 std::vector<const SMDS_MeshNode*> poly_nodes;
549 std::vector<int> quantities (NbFaces);
551 for (int i = 0; i < NbFaces; i++) {
552 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
553 quantities[i] = aFace->NbNodes();
555 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
557 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
561 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
563 // Update Python script
564 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
565 << IdsOfFaces << " )";
567 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
571 return elem->GetID();
576 //=============================================================================
578 * \brief Bind a node to a vertex
579 * \param NodeID - node ID
580 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
581 * \retval boolean - false if NodeID or VertexID is invalid
583 //=============================================================================
585 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
586 throw (SALOME::SALOME_Exception)
588 Unexpect aCatch(SALOME_SalomeException);
590 SMESHDS_Mesh * mesh = GetMeshDS();
591 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
593 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
595 if ( mesh->MaxShapeIndex() < VertexID )
596 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
598 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
599 if ( shape.ShapeType() != TopAbs_VERTEX )
600 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
602 mesh->SetNodeOnVertex( node, VertexID );
605 //=============================================================================
607 * \brief Store node position on an edge
608 * \param NodeID - node ID
609 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
610 * \param paramOnEdge - parameter on edge where the node is located
611 * \retval boolean - false if any parameter is invalid
613 //=============================================================================
615 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
616 CORBA::Double paramOnEdge)
617 throw (SALOME::SALOME_Exception)
619 Unexpect aCatch(SALOME_SalomeException);
621 SMESHDS_Mesh * mesh = GetMeshDS();
622 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
624 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
626 if ( mesh->MaxShapeIndex() < EdgeID )
627 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
629 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
630 if ( shape.ShapeType() != TopAbs_EDGE )
631 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
634 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
635 if ( paramOnEdge < f || paramOnEdge > l )
636 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
638 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
641 //=============================================================================
643 * \brief Store node position on a face
644 * \param NodeID - node ID
645 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
646 * \param u - U parameter on face where the node is located
647 * \param v - V parameter on face where the node is located
648 * \retval boolean - false if any parameter is invalid
650 //=============================================================================
652 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
653 CORBA::Double u, CORBA::Double v)
654 throw (SALOME::SALOME_Exception)
656 Unexpect aCatch(SALOME_SalomeException);
658 SMESHDS_Mesh * mesh = GetMeshDS();
659 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
661 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
663 if ( mesh->MaxShapeIndex() < FaceID )
664 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
666 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
667 if ( shape.ShapeType() != TopAbs_FACE )
668 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
670 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
671 bool isOut = ( u < surf.FirstUParameter() ||
672 u > surf.LastUParameter() ||
673 v < surf.FirstVParameter() ||
674 v > surf.LastVParameter() );
678 cout << "FACE " << FaceID << " (" << u << "," << v << ") out of "
679 << " u( " << surf.FirstUParameter()
680 << "," << surf.LastUParameter()
681 << ") v( " << surf.FirstVParameter()
682 << "," << surf.LastVParameter()
685 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
688 mesh->SetNodeOnFace( node, FaceID, u, v );
691 //=============================================================================
693 * \brief Bind a node to a solid
694 * \param NodeID - node ID
695 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
696 * \retval boolean - false if NodeID or SolidID is invalid
698 //=============================================================================
700 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
701 throw (SALOME::SALOME_Exception)
703 Unexpect aCatch(SALOME_SalomeException);
705 SMESHDS_Mesh * mesh = GetMeshDS();
706 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
708 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
710 if ( mesh->MaxShapeIndex() < SolidID )
711 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
713 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
714 if ( shape.ShapeType() != TopAbs_SOLID &&
715 shape.ShapeType() != TopAbs_SHELL)
716 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
718 mesh->SetNodeInVolume( node, SolidID );
721 //=============================================================================
723 * \brief Bind an element to a shape
724 * \param ElementID - element ID
725 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
726 * \retval boolean - false if ElementID or ShapeID is invalid
728 //=============================================================================
730 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
732 throw (SALOME::SALOME_Exception)
734 Unexpect aCatch(SALOME_SalomeException);
736 SMESHDS_Mesh * mesh = GetMeshDS();
737 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
739 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
741 if ( mesh->MaxShapeIndex() < ShapeID )
742 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
744 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
745 if ( shape.ShapeType() != TopAbs_EDGE &&
746 shape.ShapeType() != TopAbs_FACE &&
747 shape.ShapeType() != TopAbs_SOLID &&
748 shape.ShapeType() != TopAbs_SHELL )
749 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
751 mesh->SetMeshElementOnShape( elem, ShapeID );
755 //=============================================================================
759 //=============================================================================
761 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
768 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
772 GetMeshDS()->MoveNode(node, x, y, z);
774 // Update Python script
775 TPythonDump() << "isDone = " << this << ".MoveNode( "
776 << NodeID << ", " << x << ", " << y << ", " << z << " )";
781 //=============================================================================
785 //=============================================================================
787 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
792 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
793 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
797 // Update Python script
798 TPythonDump() << "isDone = " << this << ".InverseDiag( "
799 << NodeID1 << ", " << NodeID2 << " )";
801 ::SMESH_MeshEditor aMeshEditor( myMesh );
802 return aMeshEditor.InverseDiag ( n1, n2 );
805 //=============================================================================
809 //=============================================================================
811 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
816 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
817 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
821 // Update Python script
822 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
823 << NodeID1 << ", " << NodeID2 << " )";
825 ::SMESH_MeshEditor aMeshEditor( myMesh );
827 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
829 storeResult(aMeshEditor);
834 //=============================================================================
838 //=============================================================================
840 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
844 ::SMESH_MeshEditor anEditor( myMesh );
845 for (int i = 0; i < IDsOfElements.length(); i++)
847 CORBA::Long index = IDsOfElements[i];
848 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
850 anEditor.Reorient( elem );
852 // Update Python script
853 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
859 //=============================================================================
863 //=============================================================================
865 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
869 SMESH::long_array_var anElementsId = theObject->GetIDs();
870 CORBA::Boolean isDone = Reorient(anElementsId);
872 // Clear python line, created by Reorient()
873 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
874 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
876 // Update Python script
877 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
884 //================================================================================
886 * \brief function for conversion long_array to TIDSortedElemSet
887 * \param IDs - array of IDs
888 * \param aMesh - mesh
889 * \param aMap - collection to fill
890 * \param aType - element type
892 //================================================================================
894 void arrayToSet(const SMESH::long_array & IDs,
895 const SMESHDS_Mesh* aMesh,
896 TIDSortedElemSet& aMap,
897 const SMDSAbs_ElementType aType = SMDSAbs_All )
899 for (int i=0; i<IDs.length(); i++) {
900 CORBA::Long ind = IDs[i];
901 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
902 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
908 //=============================================================================
912 //=============================================================================
913 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
914 SMESH::NumericalFunctor_ptr Criterion,
915 CORBA::Double MaxAngle)
919 SMESHDS_Mesh* aMesh = GetMeshDS();
920 TIDSortedElemSet faces;
921 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
923 SMESH::NumericalFunctor_i* aNumericalFunctor =
924 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
925 SMESH::Controls::NumericalFunctorPtr aCrit;
926 if ( !aNumericalFunctor )
927 aCrit.reset( new SMESH::Controls::AspectRatio() );
929 aCrit = aNumericalFunctor->GetNumericalFunctor();
931 // Update Python script
932 TPythonDump() << "isDone = " << this << ".TriToQuad( "
933 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
935 TPythonDump() << "print 'TriToQuad: ', isDone";
938 ::SMESH_MeshEditor anEditor( myMesh );
940 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
942 storeResult(anEditor);
948 //=============================================================================
952 //=============================================================================
953 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
954 SMESH::NumericalFunctor_ptr Criterion,
955 CORBA::Double MaxAngle)
959 SMESH::long_array_var anElementsId = theObject->GetIDs();
960 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
962 // Clear python line(s), created by TriToQuad()
963 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
964 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
966 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
969 SMESH::NumericalFunctor_i* aNumericalFunctor =
970 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
972 // Update Python script
973 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
974 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
976 TPythonDump() << "print 'TriToQuadObject: ', isDone";
983 //=============================================================================
987 //=============================================================================
988 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
989 SMESH::NumericalFunctor_ptr Criterion)
993 SMESHDS_Mesh* aMesh = GetMeshDS();
994 TIDSortedElemSet faces;
995 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
997 SMESH::NumericalFunctor_i* aNumericalFunctor =
998 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
999 SMESH::Controls::NumericalFunctorPtr aCrit;
1000 if ( !aNumericalFunctor )
1001 aCrit.reset( new SMESH::Controls::AspectRatio() );
1003 aCrit = aNumericalFunctor->GetNumericalFunctor();
1006 // Update Python script
1007 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1009 TPythonDump() << "print 'QuadToTri: ', isDone";
1012 ::SMESH_MeshEditor anEditor( myMesh );
1013 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1015 storeResult(anEditor);
1021 //=============================================================================
1025 //=============================================================================
1026 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1027 SMESH::NumericalFunctor_ptr Criterion)
1031 SMESH::long_array_var anElementsId = theObject->GetIDs();
1032 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1034 // Clear python line(s), created by QuadToTri()
1035 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1036 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1038 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1041 SMESH::NumericalFunctor_i* aNumericalFunctor =
1042 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1044 // Update Python script
1045 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1047 TPythonDump() << "print 'QuadToTriObject: ', isDone";
1054 //=============================================================================
1058 //=============================================================================
1059 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1060 CORBA::Boolean Diag13)
1064 SMESHDS_Mesh* aMesh = GetMeshDS();
1065 TIDSortedElemSet faces;
1066 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1068 // Update Python script
1069 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1070 << IDsOfElements << ", " << Diag13 << " )";
1072 TPythonDump() << "print 'SplitQuad: ', isDone";
1075 ::SMESH_MeshEditor anEditor( myMesh );
1076 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1078 storeResult(anEditor);
1084 //=============================================================================
1088 //=============================================================================
1089 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1090 CORBA::Boolean Diag13)
1094 SMESH::long_array_var anElementsId = theObject->GetIDs();
1095 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1097 // Clear python line(s), created by SplitQuad()
1098 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1099 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1101 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1104 // Update Python script
1105 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1106 << theObject << ", " << Diag13 << " )";
1108 TPythonDump() << "print 'SplitQuadObject: ', isDone";
1115 //=============================================================================
1119 //=============================================================================
1120 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1121 SMESH::NumericalFunctor_ptr Criterion)
1123 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1124 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1126 SMESH::NumericalFunctor_i* aNumericalFunctor =
1127 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1128 SMESH::Controls::NumericalFunctorPtr aCrit;
1129 if (aNumericalFunctor)
1130 aCrit = aNumericalFunctor->GetNumericalFunctor();
1132 aCrit.reset(new SMESH::Controls::AspectRatio());
1134 ::SMESH_MeshEditor anEditor (myMesh);
1135 return anEditor.BestSplit(quad, aCrit);
1141 //=======================================================================
1144 //=======================================================================
1147 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1148 const SMESH::long_array & IDsOfFixedNodes,
1149 CORBA::Long MaxNbOfIterations,
1150 CORBA::Double MaxAspectRatio,
1151 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1153 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1154 MaxAspectRatio, Method, false );
1158 //=======================================================================
1159 //function : SmoothParametric
1161 //=======================================================================
1164 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1165 const SMESH::long_array & IDsOfFixedNodes,
1166 CORBA::Long MaxNbOfIterations,
1167 CORBA::Double MaxAspectRatio,
1168 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1170 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1171 MaxAspectRatio, Method, true );
1175 //=======================================================================
1176 //function : SmoothObject
1178 //=======================================================================
1181 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1182 const SMESH::long_array & IDsOfFixedNodes,
1183 CORBA::Long MaxNbOfIterations,
1184 CORBA::Double MaxAspectRatio,
1185 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1187 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1188 MaxAspectRatio, Method, false);
1192 //=======================================================================
1193 //function : SmoothParametricObject
1195 //=======================================================================
1198 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1199 const SMESH::long_array & IDsOfFixedNodes,
1200 CORBA::Long MaxNbOfIterations,
1201 CORBA::Double MaxAspectRatio,
1202 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1204 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1205 MaxAspectRatio, Method, true);
1209 //=============================================================================
1213 //=============================================================================
1216 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1217 const SMESH::long_array & IDsOfFixedNodes,
1218 CORBA::Long MaxNbOfIterations,
1219 CORBA::Double MaxAspectRatio,
1220 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1225 SMESHDS_Mesh* aMesh = GetMeshDS();
1227 TIDSortedElemSet elements;
1228 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1230 set<const SMDS_MeshNode*> fixedNodes;
1231 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1232 CORBA::Long index = IDsOfFixedNodes[i];
1233 const SMDS_MeshNode * node = aMesh->FindNode(index);
1235 fixedNodes.insert( node );
1237 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1238 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1239 method = ::SMESH_MeshEditor::CENTROIDAL;
1241 ::SMESH_MeshEditor anEditor( myMesh );
1242 anEditor.Smooth(elements, fixedNodes, method,
1243 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1245 storeResult(anEditor);
1247 // Update Python script
1248 TPythonDump() << "isDone = " << this << "."
1249 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1250 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1251 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1252 << "SMESH.SMESH_MeshEditor."
1253 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1254 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1256 TPythonDump() << "print 'Smooth: ', isDone";
1263 //=============================================================================
1267 //=============================================================================
1270 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1271 const SMESH::long_array & IDsOfFixedNodes,
1272 CORBA::Long MaxNbOfIterations,
1273 CORBA::Double MaxAspectRatio,
1274 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1279 SMESH::long_array_var anElementsId = theObject->GetIDs();
1280 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1281 MaxAspectRatio, Method, IsParametric);
1283 // Clear python line(s), created by Smooth()
1284 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1285 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1287 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1290 // Update Python script
1291 TPythonDump() << "isDone = " << this << "."
1292 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1293 << theObject << ", " << IDsOfFixedNodes << ", "
1294 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1295 << "SMESH.SMESH_MeshEditor."
1296 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1297 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1299 TPythonDump() << "print 'SmoothObject: ', isDone";
1306 //=============================================================================
1310 //=============================================================================
1312 void SMESH_MeshEditor_i::RenumberNodes()
1314 // Update Python script
1315 TPythonDump() << this << ".RenumberNodes()";
1317 GetMeshDS()->Renumber( true );
1321 //=============================================================================
1325 //=============================================================================
1327 void SMESH_MeshEditor_i::RenumberElements()
1329 // Update Python script
1330 TPythonDump() << this << ".RenumberElements()";
1332 GetMeshDS()->Renumber( false );
1335 //=======================================================================
1337 * \brief Return groups by their IDs
1339 //=======================================================================
1341 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1345 myMesh_i->CreateGroupServants();
1346 return myMesh_i->GetGroups( *groupIDs );
1349 //=======================================================================
1350 //function : rotationSweep
1352 //=======================================================================
1354 SMESH::ListOfGroups*
1355 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1356 const SMESH::AxisStruct & theAxis,
1357 CORBA::Double theAngleInRadians,
1358 CORBA::Long theNbOfSteps,
1359 CORBA::Double theTolerance,
1360 const bool theMakeGroups)
1364 TIDSortedElemSet inElements, copyElements;
1365 arrayToSet(theIDsOfElements, GetMeshDS(), inElements);
1367 TIDSortedElemSet* workElements = & inElements;
1368 TPreviewMesh tmpMesh( SMDSAbs_Face );
1369 SMESH_Mesh* mesh = 0;
1370 bool makeWalls=true;
1371 if ( myPreviewMode )
1373 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1374 tmpMesh.Copy( inElements, copyElements, select, avoid );
1376 workElements = & copyElements;
1377 //makeWalls = false;
1384 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1385 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1387 ::SMESH_MeshEditor anEditor( mesh );
1388 ::SMESH_MeshEditor::PGroupIDs groupIds =
1389 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1390 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1391 storeResult(anEditor);
1393 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1396 //=======================================================================
1397 //function : RotationSweep
1399 //=======================================================================
1401 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1402 const SMESH::AxisStruct & theAxis,
1403 CORBA::Double theAngleInRadians,
1404 CORBA::Long theNbOfSteps,
1405 CORBA::Double theTolerance)
1407 if ( !myPreviewMode ) {
1408 TPythonDump() << "axis = " << theAxis;
1409 TPythonDump() << this << ".RotationSweep( "
1412 << theAngleInRadians << ", "
1413 << theNbOfSteps << ", "
1414 << theTolerance << " )";
1416 rotationSweep(theIDsOfElements,
1424 //=======================================================================
1425 //function : RotationSweepMakeGroups
1427 //=======================================================================
1429 SMESH::ListOfGroups*
1430 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1431 const SMESH::AxisStruct& theAxis,
1432 CORBA::Double theAngleInRadians,
1433 CORBA::Long theNbOfSteps,
1434 CORBA::Double theTolerance)
1436 if ( !myPreviewMode ) {
1437 TPythonDump() << "axis = " << theAxis;
1438 TPythonDump() << this << ".RotationSweepMakeGroups( "
1441 << theAngleInRadians << ", "
1442 << theNbOfSteps << ", "
1443 << theTolerance << " )";
1445 return rotationSweep(theIDsOfElements,
1453 //=======================================================================
1454 //function : RotationSweepObject
1456 //=======================================================================
1458 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1459 const SMESH::AxisStruct & theAxis,
1460 CORBA::Double theAngleInRadians,
1461 CORBA::Long theNbOfSteps,
1462 CORBA::Double theTolerance)
1464 if ( !myPreviewMode ) {
1465 TPythonDump() << "axis = " << theAxis;
1466 TPythonDump() << this << ".RotationSweepObject( "
1469 << theAngleInRadians << ", "
1470 << theNbOfSteps << ", "
1471 << theTolerance << " )";
1473 SMESH::long_array_var anElementsId = theObject->GetIDs();
1474 rotationSweep(anElementsId,
1482 //=======================================================================
1483 //function : RotationSweepObjectMakeGroups
1485 //=======================================================================
1487 SMESH::ListOfGroups*
1488 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1489 const SMESH::AxisStruct& theAxis,
1490 CORBA::Double theAngleInRadians,
1491 CORBA::Long theNbOfSteps,
1492 CORBA::Double theTolerance)
1494 if ( !myPreviewMode ) {
1495 TPythonDump() << "axis = " << theAxis;
1496 TPythonDump() << this << ".RotationSweepObjectMakeGroups( "
1499 << theAngleInRadians << ", "
1500 << theNbOfSteps << ", "
1501 << theTolerance << " )";
1503 SMESH::long_array_var anElementsId = theObject->GetIDs();
1504 return rotationSweep(anElementsId,
1513 //=======================================================================
1514 //function : extrusionSweep
1516 //=======================================================================
1518 SMESH::ListOfGroups*
1519 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1520 const SMESH::DirStruct & theStepVector,
1521 CORBA::Long theNbOfSteps,
1522 const bool theMakeGroups,
1523 const SMDSAbs_ElementType theElementType)
1533 TIDSortedElemSet elements;
1534 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1536 const SMESH::PointStruct * P = &theStepVector.PS;
1537 gp_Vec stepVec( P->x, P->y, P->z );
1539 TElemOfElemListMap aHystory;
1540 ::SMESH_MeshEditor anEditor( myMesh );
1541 ::SMESH_MeshEditor::PGroupIDs groupIds =
1542 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1544 storeResult(anEditor);
1546 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1549 } catch(Standard_Failure) {
1551 } CASCatch_CATCH(Standard_Failure) {
1553 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1554 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1559 //=======================================================================
1560 //function : ExtrusionSweep
1562 //=======================================================================
1564 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1565 const SMESH::DirStruct & theStepVector,
1566 CORBA::Long theNbOfSteps)
1568 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1569 if ( !myPreviewMode ) {
1570 TPythonDump() << "stepVector = " << theStepVector;
1571 TPythonDump() << this << ".ExtrusionSweep( "
1572 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1577 //=======================================================================
1578 //function : ExtrusionSweepObject
1580 //=======================================================================
1582 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1583 const SMESH::DirStruct & theStepVector,
1584 CORBA::Long theNbOfSteps)
1586 SMESH::long_array_var anElementsId = theObject->GetIDs();
1587 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1588 if ( !myPreviewMode ) {
1589 TPythonDump() << "stepVector = " << theStepVector;
1590 TPythonDump() << this << ".ExtrusionSweepObject( "
1591 << theObject << ", stepVector, " << theNbOfSteps << " )";
1595 //=======================================================================
1596 //function : ExtrusionSweepObject1D
1598 //=======================================================================
1600 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1601 const SMESH::DirStruct & theStepVector,
1602 CORBA::Long theNbOfSteps)
1604 SMESH::long_array_var anElementsId = theObject->GetIDs();
1605 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1606 if ( !myPreviewMode ) {
1607 TPythonDump() << "stepVector = " << theStepVector;
1608 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1609 << theObject << ", stepVector, " << theNbOfSteps << " )";
1613 //=======================================================================
1614 //function : ExtrusionSweepObject2D
1616 //=======================================================================
1618 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1619 const SMESH::DirStruct & theStepVector,
1620 CORBA::Long theNbOfSteps)
1622 SMESH::long_array_var anElementsId = theObject->GetIDs();
1623 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1624 if ( !myPreviewMode ) {
1625 TPythonDump() << "stepVector = " << theStepVector;
1626 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1627 << theObject << ", stepVector, " << theNbOfSteps << " )";
1631 //=======================================================================
1632 //function : ExtrusionSweepMakeGroups
1634 //=======================================================================
1636 SMESH::ListOfGroups*
1637 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1638 const SMESH::DirStruct& theStepVector,
1639 CORBA::Long theNbOfSteps)
1641 if ( !myPreviewMode ) {
1642 TPythonDump() << "stepVector = " << theStepVector;
1643 TPythonDump() << this << ".ExtrusionSweepMakeGroups( "
1644 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1646 return extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1648 //=======================================================================
1649 //function : ExtrusionSweepObjectMakeGroups
1651 //=======================================================================
1653 SMESH::ListOfGroups*
1654 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1655 const SMESH::DirStruct& theStepVector,
1656 CORBA::Long theNbOfSteps)
1658 if ( !myPreviewMode ) {
1659 TPythonDump() << "stepVector = " << theStepVector;
1660 TPythonDump() << this << ".ExtrusionSweepObjectMakeGroups( "
1661 << theObject << ", stepVector, " << theNbOfSteps << " )";
1663 SMESH::long_array_var anElementsId = theObject->GetIDs();
1664 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1667 //=======================================================================
1668 //function : ExtrusionSweepObject1DMakeGroups
1670 //=======================================================================
1672 SMESH::ListOfGroups*
1673 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1674 const SMESH::DirStruct& theStepVector,
1675 CORBA::Long theNbOfSteps)
1677 if ( !myPreviewMode ) {
1678 TPythonDump() << "stepVector = " << theStepVector;
1679 TPythonDump() << this << ".ExtrusionSweepObject1DMakeGroups( "
1680 << theObject << ", stepVector, " << theNbOfSteps << " )";
1682 SMESH::long_array_var anElementsId = theObject->GetIDs();
1683 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1686 //=======================================================================
1687 //function : ExtrusionSweepObject2DMakeGroups
1689 //=======================================================================
1691 SMESH::ListOfGroups*
1692 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1693 const SMESH::DirStruct& theStepVector,
1694 CORBA::Long theNbOfSteps)
1696 if ( !myPreviewMode ) {
1697 TPythonDump() << "stepVector = " << theStepVector;
1698 TPythonDump() << this << ".ExtrusionSweepObject2DMakeGroups( "
1699 << theObject << ", stepVector, " << theNbOfSteps << " )";
1701 SMESH::long_array_var anElementsId = theObject->GetIDs();
1702 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1706 //=======================================================================
1707 //function : advancedExtrusion
1709 //=======================================================================
1711 SMESH::ListOfGroups*
1712 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1713 const SMESH::DirStruct & theStepVector,
1714 CORBA::Long theNbOfSteps,
1715 CORBA::Long theExtrFlags,
1716 CORBA::Double theSewTolerance,
1717 const bool theMakeGroups)
1721 TIDSortedElemSet elements;
1722 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1724 const SMESH::PointStruct * P = &theStepVector.PS;
1725 gp_Vec stepVec( P->x, P->y, P->z );
1727 ::SMESH_MeshEditor anEditor( myMesh );
1728 TElemOfElemListMap aHystory;
1729 ::SMESH_MeshEditor::PGroupIDs groupIds =
1730 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1731 theMakeGroups, theExtrFlags, theSewTolerance);
1732 storeResult(anEditor);
1734 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1737 //=======================================================================
1738 //function : AdvancedExtrusion
1740 //=======================================================================
1742 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1743 const SMESH::DirStruct & theStepVector,
1744 CORBA::Long theNbOfSteps,
1745 CORBA::Long theExtrFlags,
1746 CORBA::Double theSewTolerance)
1748 if ( !myPreviewMode ) {
1749 TPythonDump() << "stepVector = " << theStepVector;
1750 TPythonDump() << this << ".AdvancedExtrusion("
1753 << theNbOfSteps << ","
1754 << theExtrFlags << ", "
1755 << theSewTolerance << " )";
1757 advancedExtrusion( theIDsOfElements,
1765 //=======================================================================
1766 //function : AdvancedExtrusionMakeGroups
1768 //=======================================================================
1770 SMESH::ListOfGroups*
1771 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1772 const SMESH::DirStruct& theStepVector,
1773 CORBA::Long theNbOfSteps,
1774 CORBA::Long theExtrFlags,
1775 CORBA::Double theSewTolerance)
1777 if ( !myPreviewMode ) {
1778 TPythonDump() << "stepVector = " << theStepVector;
1779 TPythonDump() << this << ".AdvancedExtrusionMakeGroups("
1782 << theNbOfSteps << ","
1783 << theExtrFlags << ", "
1784 << theSewTolerance << " )";
1786 return advancedExtrusion( theIDsOfElements,
1795 //================================================================================
1797 * \brief Convert extrusion error to IDL enum
1799 //================================================================================
1801 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1803 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1807 RETCASE( EXTR_NO_ELEMENTS );
1808 RETCASE( EXTR_PATH_NOT_EDGE );
1809 RETCASE( EXTR_BAD_PATH_SHAPE );
1810 RETCASE( EXTR_BAD_STARTING_NODE );
1811 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1812 RETCASE( EXTR_CANT_GET_TANGENT );
1814 return SMESH::SMESH_MeshEditor::EXTR_OK;
1818 //=======================================================================
1819 //function : extrusionAlongPath
1821 //=======================================================================
1823 SMESH::ListOfGroups*
1824 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1825 SMESH::SMESH_Mesh_ptr thePathMesh,
1826 GEOM::GEOM_Object_ptr thePathShape,
1827 CORBA::Long theNodeStart,
1828 CORBA::Boolean theHasAngles,
1829 const SMESH::double_array & theAngles,
1830 CORBA::Boolean theHasRefPoint,
1831 const SMESH::PointStruct & theRefPoint,
1832 const bool theMakeGroups,
1833 SMESH::SMESH_MeshEditor::Extrusion_Error & theError)
1837 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1838 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1841 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1843 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1844 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1846 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
1847 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1851 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1853 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1857 TIDSortedElemSet elements;
1858 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1860 list<double> angles;
1861 for (int i = 0; i < theAngles.length(); i++) {
1862 angles.push_back( theAngles[i] );
1865 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1867 int nbOldGroups = myMesh->NbGroup();
1869 ::SMESH_MeshEditor anEditor( myMesh );
1870 ::SMESH_MeshEditor::Extrusion_Error error =
1871 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1872 theHasAngles, angles,
1873 theHasRefPoint, refPnt, theMakeGroups );
1874 storeResult(anEditor);
1875 theError = convExtrError( error );
1877 if ( theMakeGroups ) {
1878 list<int> groupIDs = myMesh->GetGroupIds();
1879 list<int>::iterator newBegin = groupIDs.begin();
1880 std::advance( newBegin, nbOldGroups ); // skip old groups
1881 groupIDs.erase( groupIDs.begin(), newBegin );
1882 return getGroups( & groupIDs );
1887 //=======================================================================
1888 //function : ExtrusionAlongPath
1890 //=======================================================================
1892 SMESH::SMESH_MeshEditor::Extrusion_Error
1893 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1894 SMESH::SMESH_Mesh_ptr thePathMesh,
1895 GEOM::GEOM_Object_ptr thePathShape,
1896 CORBA::Long theNodeStart,
1897 CORBA::Boolean theHasAngles,
1898 const SMESH::double_array & theAngles,
1899 CORBA::Boolean theHasRefPoint,
1900 const SMESH::PointStruct & theRefPoint)
1902 if ( !myPreviewMode ) {
1903 TPythonDump() << "rotAngles = " << theAngles;
1905 if ( theHasRefPoint )
1906 TPythonDump() << "refPoint = SMESH.PointStruct( "
1907 << theRefPoint.x << ", "
1908 << theRefPoint.y << ", "
1909 << theRefPoint.z << " )";
1911 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1913 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
1914 << theIDsOfElements << ", "
1915 << thePathMesh << ", "
1916 << thePathShape << ", "
1917 << theNodeStart << ", "
1918 << theHasAngles << ", "
1919 << "rotAngles" << ", "
1920 << theHasRefPoint << ", refPoint )";
1922 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1923 extrusionAlongPath( theIDsOfElements,
1936 //=======================================================================
1937 //function : ExtrusionAlongPathObject
1939 //=======================================================================
1941 SMESH::SMESH_MeshEditor::Extrusion_Error
1942 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
1943 SMESH::SMESH_Mesh_ptr thePathMesh,
1944 GEOM::GEOM_Object_ptr thePathShape,
1945 CORBA::Long theNodeStart,
1946 CORBA::Boolean theHasAngles,
1947 const SMESH::double_array & theAngles,
1948 CORBA::Boolean theHasRefPoint,
1949 const SMESH::PointStruct & theRefPoint)
1951 if ( !myPreviewMode ) {
1952 TPythonDump() << "rotAngles = " << theAngles;
1954 if ( theHasRefPoint )
1955 TPythonDump() << "refPoint = SMESH.PointStruct( "
1956 << theRefPoint.x << ", "
1957 << theRefPoint.y << ", "
1958 << theRefPoint.z << " )";
1960 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1962 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
1963 << theObject << ", "
1964 << thePathMesh << ", "
1965 << thePathShape << ", "
1966 << theNodeStart << ", "
1967 << theHasAngles << ", "
1968 << "rotAngles" << ", "
1969 << theHasRefPoint << ", refPoint )";
1971 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1972 SMESH::long_array_var anElementsId = theObject->GetIDs();
1973 extrusionAlongPath( anElementsId,
1987 //=======================================================================
1988 //function : ExtrusionAlongPathMakeGroups
1990 //=======================================================================
1992 SMESH::ListOfGroups*
1993 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
1994 SMESH::SMESH_Mesh_ptr thePathMesh,
1995 GEOM::GEOM_Object_ptr thePathShape,
1996 CORBA::Long theNodeStart,
1997 CORBA::Boolean theHasAngles,
1998 const SMESH::double_array& theAngles,
1999 CORBA::Boolean theHasRefPoint,
2000 const SMESH::PointStruct& theRefPoint,
2001 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2003 if ( !myPreviewMode ) {
2004 TPythonDump() << "rotAngles = " << theAngles;
2006 if ( theHasRefPoint )
2007 TPythonDump() << "refPoint = SMESH.PointStruct( "
2008 << theRefPoint.x << ", "
2009 << theRefPoint.y << ", "
2010 << theRefPoint.z << " )";
2012 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2014 TPythonDump() << "groups = " << this << ".ExtrusionAlongPathMakeGroups( "
2015 << theIDsOfElements << ", "
2016 << thePathMesh << ", "
2017 << thePathShape << ", "
2018 << theNodeStart << ", "
2019 << theHasAngles << ", "
2020 << "rotAngles" << ", "
2021 << theHasRefPoint << ", refPoint )";
2023 return extrusionAlongPath( theIDsOfElements,
2035 //=======================================================================
2036 //function : ExtrusionAlongPathObjectMakeGroups
2038 //=======================================================================
2040 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2041 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2042 SMESH::SMESH_Mesh_ptr thePathMesh,
2043 GEOM::GEOM_Object_ptr thePathShape,
2044 CORBA::Long theNodeStart,
2045 CORBA::Boolean theHasAngles,
2046 const SMESH::double_array& theAngles,
2047 CORBA::Boolean theHasRefPoint,
2048 const SMESH::PointStruct& theRefPoint,
2049 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2051 if ( !myPreviewMode ) {
2052 TPythonDump() << "rotAngles = " << theAngles;
2054 if ( theHasRefPoint )
2055 TPythonDump() << "refPoint = SMESH.PointStruct( "
2056 << theRefPoint.x << ", "
2057 << theRefPoint.y << ", "
2058 << theRefPoint.z << " )";
2060 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2062 TPythonDump() << "groups = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2063 << theObject << ", "
2064 << thePathMesh << ", "
2065 << thePathShape << ", "
2066 << theNodeStart << ", "
2067 << theHasAngles << ", "
2068 << "rotAngles" << ", "
2069 << theHasRefPoint << ", refPoint )";
2071 SMESH::long_array_var anElementsId = theObject->GetIDs();
2072 return extrusionAlongPath( anElementsId,
2084 //================================================================================
2086 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2087 * of given angles along path steps
2088 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2089 * which proceeds the extrusion
2090 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2091 * is used to define the sub-mesh for the path
2093 //================================================================================
2095 SMESH::double_array*
2096 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2097 GEOM::GEOM_Object_ptr thePathShape,
2098 const SMESH::double_array & theAngles)
2100 SMESH::double_array_var aResult = new SMESH::double_array();
2101 return aResult._retn();
2105 //=======================================================================
2108 //=======================================================================
2110 SMESH::ListOfGroups*
2111 SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
2112 const SMESH::AxisStruct & theAxis,
2113 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2114 CORBA::Boolean theCopy,
2115 const bool theMakeGroups,
2116 ::SMESH_Mesh* theTargetMesh)
2120 TIDSortedElemSet elements;
2121 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2123 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2124 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2127 switch ( theMirrorType ) {
2128 case SMESH::SMESH_MeshEditor::POINT:
2129 aTrsf.SetMirror( P );
2131 case SMESH::SMESH_MeshEditor::AXIS:
2132 aTrsf.SetMirror( gp_Ax1( P, V ));
2135 aTrsf.SetMirror( gp_Ax2( P, V ));
2138 ::SMESH_MeshEditor anEditor( myMesh );
2139 ::SMESH_MeshEditor::PGroupIDs groupIds =
2140 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2143 storeResult(anEditor);
2145 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2148 //=======================================================================
2151 //=======================================================================
2153 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2154 const SMESH::AxisStruct & theAxis,
2155 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2156 CORBA::Boolean theCopy)
2158 if ( !myPreviewMode ) {
2159 TPythonDump() << this << ".Mirror( "
2160 << theIDsOfElements << ", "
2162 << mirrorTypeName(theMirrorType) << ", "
2165 mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2169 //=======================================================================
2170 //function : MirrorObject
2172 //=======================================================================
2174 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2175 const SMESH::AxisStruct & theAxis,
2176 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2177 CORBA::Boolean theCopy)
2179 if ( !myPreviewMode ) {
2180 TPythonDump() << this << ".MirrorObject( "
2181 << theObject << ", "
2183 << mirrorTypeName(theMirrorType) << ", "
2186 SMESH::long_array_var anElementsId = theObject->GetIDs();
2187 mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2190 //=======================================================================
2191 //function : MirrorMakeGroups
2193 //=======================================================================
2195 SMESH::ListOfGroups*
2196 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2197 const SMESH::AxisStruct& theMirror,
2198 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2200 if ( !myPreviewMode ) {
2201 TPythonDump() << this << ".MirrorMakeGroups( "
2202 << theIDsOfElements << ", "
2203 << theMirror << ", "
2204 << mirrorTypeName(theMirrorType) << " )";
2206 return mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2209 //=======================================================================
2210 //function : MirrorObjectMakeGroups
2212 //=======================================================================
2214 SMESH::ListOfGroups*
2215 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2216 const SMESH::AxisStruct& theMirror,
2217 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2219 if ( !myPreviewMode ) {
2220 TPythonDump() << this << ".MirrorObjectMakeGroups( "
2221 << theObject << ", "
2222 << theMirror << ", "
2223 << mirrorTypeName(theMirrorType) << " )";
2225 SMESH::long_array_var anElementsId = theObject->GetIDs();
2226 return mirror(anElementsId, theMirror, theMirrorType, true, true);
2229 //=======================================================================
2230 //function : MirrorMakeMesh
2232 //=======================================================================
2234 SMESH::SMESH_Mesh_ptr
2235 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2236 const SMESH::AxisStruct& theMirror,
2237 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2238 CORBA::Boolean theCopyGroups,
2239 const char* theMeshName)
2241 TPythonDump pydump; // to prevent dump at mesh creation
2243 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2244 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh ))
2246 mirror(theIDsOfElements, theMirror, theMirrorType,
2247 false, theCopyGroups, & mesh_i->GetImpl());
2248 mesh_i->CreateGroupServants();
2251 if ( !myPreviewMode ) {
2252 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2253 << theIDsOfElements << ", "
2254 << theMirror << ", "
2255 << mirrorTypeName(theMirrorType) << ", "
2256 << theCopyGroups << ", '"
2257 << theMeshName << "' )";
2259 return mesh._retn();
2262 //=======================================================================
2263 //function : MirrorObjectMakeMesh
2265 //=======================================================================
2267 SMESH::SMESH_Mesh_ptr
2268 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2269 const SMESH::AxisStruct& theMirror,
2270 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2271 CORBA::Boolean theCopyGroups,
2272 const char* theMeshName)
2274 TPythonDump pydump; // to prevent dump at mesh creation
2276 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2277 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh ))
2279 SMESH::long_array_var anElementsId = theObject->GetIDs();
2280 mirror(anElementsId, theMirror, theMirrorType,
2281 false, theCopyGroups, & mesh_i->GetImpl());
2282 mesh_i->CreateGroupServants();
2284 if ( !myPreviewMode ) {
2285 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
2286 << theObject << ", "
2287 << theMirror << ", "
2288 << mirrorTypeName(theMirrorType) << ", "
2289 << theCopyGroups << ", '"
2290 << theMeshName << "' )";
2292 return mesh._retn();
2295 //=======================================================================
2296 //function : translate
2298 //=======================================================================
2300 SMESH::ListOfGroups*
2301 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2302 const SMESH::DirStruct & theVector,
2303 CORBA::Boolean theCopy,
2304 const bool theMakeGroups,
2305 ::SMESH_Mesh* theTargetMesh)
2309 TIDSortedElemSet elements;
2310 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2313 const SMESH::PointStruct * P = &theVector.PS;
2314 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2316 ::SMESH_MeshEditor anEditor( myMesh );
2317 ::SMESH_MeshEditor::PGroupIDs groupIds =
2318 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2321 storeResult(anEditor);
2323 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2326 //=======================================================================
2327 //function : Translate
2329 //=======================================================================
2331 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2332 const SMESH::DirStruct & theVector,
2333 CORBA::Boolean theCopy)
2335 if ( !myPreviewMode ) {
2336 TPythonDump() << "vector = " << theVector;
2337 TPythonDump() << this << ".Translate( "
2342 translate(theIDsOfElements,
2348 //=======================================================================
2349 //function : TranslateObject
2351 //=======================================================================
2353 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
2354 const SMESH::DirStruct & theVector,
2355 CORBA::Boolean theCopy)
2357 if ( !myPreviewMode ) {
2358 TPythonDump() << this << ".TranslateObject( "
2363 SMESH::long_array_var anElementsId = theObject->GetIDs();
2364 translate(anElementsId,
2370 //=======================================================================
2371 //function : TranslateMakeGroups
2373 //=======================================================================
2375 SMESH::ListOfGroups*
2376 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
2377 const SMESH::DirStruct& theVector)
2379 if ( !myPreviewMode ) {
2380 TPythonDump() << "vector = " << theVector;
2381 TPythonDump() << this << ".TranslateMakeGroups( "
2385 return translate(theIDsOfElements,theVector,true,true);
2388 //=======================================================================
2389 //function : TranslateObjectMakeGroups
2391 //=======================================================================
2393 SMESH::ListOfGroups*
2394 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2395 const SMESH::DirStruct& theVector)
2397 if ( !myPreviewMode ) {
2398 TPythonDump() << "vector = " << theVector;
2399 TPythonDump() << this << ".TranslateObjectMakeGroups( "
2403 SMESH::long_array_var anElementsId = theObject->GetIDs();
2404 return translate(anElementsId, theVector, true, true);
2407 //=======================================================================
2408 //function : TranslateMakeMesh
2410 //=======================================================================
2412 SMESH::SMESH_Mesh_ptr
2413 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
2414 const SMESH::DirStruct& theVector,
2415 CORBA::Boolean theCopyGroups,
2416 const char* theMeshName)
2418 TPythonDump pydump; // to prevent dump at mesh creation
2419 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2421 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2422 translate(theIDsOfElements, theVector,
2423 false, theCopyGroups, & mesh_i->GetImpl());
2424 mesh_i->CreateGroupServants();
2426 if ( !myPreviewMode ) {
2427 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
2428 << theIDsOfElements << ", "
2429 << theVector << ", "
2430 << theCopyGroups << ", '"
2431 << theMeshName << "' )";
2433 return mesh._retn();
2436 //=======================================================================
2437 //function : TranslateObjectMakeMesh
2439 //=======================================================================
2441 SMESH::SMESH_Mesh_ptr
2442 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2443 const SMESH::DirStruct& theVector,
2444 CORBA::Boolean theCopyGroups,
2445 const char* theMeshName)
2447 TPythonDump pydump; // to prevent dump at mesh creation
2448 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2450 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2451 SMESH::long_array_var anElementsId = theObject->GetIDs();
2452 translate(anElementsId, theVector,
2453 false, theCopyGroups, & mesh_i->GetImpl());
2454 mesh_i->CreateGroupServants();
2456 if ( !myPreviewMode ) {
2457 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
2458 << theObject << ", "
2459 << theVector << ", "
2460 << theCopyGroups << ", '"
2461 << theMeshName << "' )";
2463 return mesh._retn();
2466 //=======================================================================
2469 //=======================================================================
2471 SMESH::ListOfGroups*
2472 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
2473 const SMESH::AxisStruct & theAxis,
2474 CORBA::Double theAngle,
2475 CORBA::Boolean theCopy,
2476 const bool theMakeGroups,
2477 ::SMESH_Mesh* theTargetMesh)
2481 TIDSortedElemSet elements;
2482 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2484 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2485 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2488 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
2490 ::SMESH_MeshEditor anEditor( myMesh );
2491 ::SMESH_MeshEditor::PGroupIDs groupIds =
2492 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2495 storeResult(anEditor);
2497 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2500 //=======================================================================
2503 //=======================================================================
2505 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
2506 const SMESH::AxisStruct & theAxis,
2507 CORBA::Double theAngle,
2508 CORBA::Boolean theCopy)
2510 if ( !myPreviewMode ) {
2511 TPythonDump() << "axis = " << theAxis;
2512 TPythonDump() << this << ".Rotate( "
2518 rotate(theIDsOfElements,
2525 //=======================================================================
2526 //function : RotateObject
2528 //=======================================================================
2530 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
2531 const SMESH::AxisStruct & theAxis,
2532 CORBA::Double theAngle,
2533 CORBA::Boolean theCopy)
2535 if ( !myPreviewMode ) {
2536 TPythonDump() << "axis = " << theAxis;
2537 TPythonDump() << this << ".RotateObject( "
2543 SMESH::long_array_var anElementsId = theObject->GetIDs();
2544 rotate(anElementsId,
2551 //=======================================================================
2552 //function : RotateMakeGroups
2554 //=======================================================================
2556 SMESH::ListOfGroups*
2557 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
2558 const SMESH::AxisStruct& theAxis,
2559 CORBA::Double theAngle)
2561 if ( !myPreviewMode ) {
2562 TPythonDump() << "axis = " << theAxis;
2563 TPythonDump() << this << ".RotateMakeGroups( "
2566 << theAngle << " )";
2568 return rotate(theIDsOfElements,theAxis,theAngle,true,true);
2571 //=======================================================================
2572 //function : RotateObjectMakeGroups
2574 //=======================================================================
2576 SMESH::ListOfGroups*
2577 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2578 const SMESH::AxisStruct& theAxis,
2579 CORBA::Double theAngle)
2581 if ( !myPreviewMode ) {
2582 TPythonDump() << "axis = " << theAxis;
2583 TPythonDump() << this << ".RotateObjectMakeGroups( "
2586 << theAngle << " )";
2588 SMESH::long_array_var anElementsId = theObject->GetIDs();
2589 return rotate(anElementsId,theAxis,theAngle,true,true);
2592 //=======================================================================
2593 //function : RotateMakeMesh
2595 //=======================================================================
2597 SMESH::SMESH_Mesh_ptr
2598 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
2599 const SMESH::AxisStruct& theAxis,
2600 CORBA::Double theAngleInRadians,
2601 CORBA::Boolean theCopyGroups,
2602 const char* theMeshName)
2604 TPythonDump pydump; // to prevent dump at mesh creation
2605 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2607 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2608 rotate(theIDsOfElements, theAxis, theAngleInRadians,
2609 false, theCopyGroups, & mesh_i->GetImpl());
2610 mesh_i->CreateGroupServants();
2612 if ( !myPreviewMode ) {
2613 pydump << mesh << " = " << this << ".RotateMakeMesh( "
2614 << theIDsOfElements << ", "
2616 << theAngleInRadians << ", "
2617 << theCopyGroups << ", '"
2618 << theMeshName << "' )";
2620 return mesh._retn();
2623 //=======================================================================
2624 //function : RotateObjectMakeMesh
2626 //=======================================================================
2628 SMESH::SMESH_Mesh_ptr
2629 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2630 const SMESH::AxisStruct& theAxis,
2631 CORBA::Double theAngleInRadians,
2632 CORBA::Boolean theCopyGroups,
2633 const char* theMeshName)
2635 TPythonDump pydump; // to prevent dump at mesh creation
2636 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2638 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2639 SMESH::long_array_var anElementsId = theObject->GetIDs();
2640 rotate(anElementsId, theAxis, theAngleInRadians,
2641 false, theCopyGroups, & mesh_i->GetImpl());
2642 mesh_i->CreateGroupServants();
2644 if ( !myPreviewMode ) {
2645 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
2646 << theObject << ", "
2648 << theAngleInRadians << ", "
2649 << theCopyGroups << ", '"
2650 << theMeshName << "' )";
2652 return mesh._retn();
2655 //=======================================================================
2656 //function : FindCoincidentNodes
2658 //=======================================================================
2660 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
2661 SMESH::array_of_long_array_out GroupsOfNodes)
2665 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2666 ::SMESH_MeshEditor anEditor( myMesh );
2667 set<const SMDS_MeshNode*> nodes; // no input nodes
2668 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2670 GroupsOfNodes = new SMESH::array_of_long_array;
2671 GroupsOfNodes->length( aListOfListOfNodes.size() );
2672 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2673 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2674 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2675 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2676 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2677 aGroup.length( aListOfNodes.size() );
2678 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2679 aGroup[ j ] = (*lIt)->GetID();
2681 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
2682 << Tolerance << " )";
2685 //=======================================================================
2686 //function : FindCoincidentNodesOnPart
2688 //=======================================================================
2689 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
2690 CORBA::Double Tolerance,
2691 SMESH::array_of_long_array_out GroupsOfNodes)
2694 SMESH::long_array_var aElementsId = theObject->GetIDs();
2696 SMESHDS_Mesh* aMesh = GetMeshDS();
2697 set<const SMDS_MeshNode*> nodes;
2699 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2700 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
2701 for(int i = 0; i < aElementsId->length(); i++) {
2702 CORBA::Long ind = aElementsId[i];
2703 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
2709 for(int i = 0; i < aElementsId->length(); i++) {
2710 CORBA::Long ind = aElementsId[i];
2711 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
2713 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
2714 while ( nIt->more() )
2715 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
2721 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2722 ::SMESH_MeshEditor anEditor( myMesh );
2724 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2726 GroupsOfNodes = new SMESH::array_of_long_array;
2727 GroupsOfNodes->length( aListOfListOfNodes.size() );
2728 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2729 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2730 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2731 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2732 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2733 aGroup.length( aListOfNodes.size() );
2734 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2735 aGroup[ j ] = (*lIt)->GetID();
2737 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
2739 << Tolerance << " )";
2742 //=======================================================================
2743 //function : MergeNodes
2745 //=======================================================================
2747 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
2751 SMESHDS_Mesh* aMesh = GetMeshDS();
2753 TPythonDump aTPythonDump;
2754 aTPythonDump << this << ".MergeNodes([";
2755 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2756 for (int i = 0; i < GroupsOfNodes.length(); i++)
2758 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
2759 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
2760 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
2761 for ( int j = 0; j < aNodeGroup.length(); j++ )
2763 CORBA::Long index = aNodeGroup[ j ];
2764 const SMDS_MeshNode * node = aMesh->FindNode(index);
2766 aListOfNodes.push_back( node );
2768 if ( aListOfNodes.size() < 2 )
2769 aListOfListOfNodes.pop_back();
2771 if ( i > 0 ) aTPythonDump << ", ";
2772 aTPythonDump << aNodeGroup;
2774 ::SMESH_MeshEditor anEditor( myMesh );
2775 anEditor.MergeNodes( aListOfListOfNodes );
2777 aTPythonDump << "])";
2780 //=======================================================================
2781 //function : FindEqualElements
2783 //=======================================================================
2784 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
2785 SMESH::array_of_long_array_out GroupsOfElementsID)
2788 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2789 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
2790 typedef list<int> TListOfIDs;
2791 set<const SMDS_MeshElement*> elems;
2792 SMESH::long_array_var aElementsId = theObject->GetIDs();
2793 SMESHDS_Mesh* aMesh = GetMeshDS();
2795 for(int i = 0; i < aElementsId->length(); i++) {
2796 CORBA::Long anID = aElementsId[i];
2797 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
2803 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2804 ::SMESH_MeshEditor anEditor( myMesh );
2805 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
2807 GroupsOfElementsID = new SMESH::array_of_long_array;
2808 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
2810 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
2811 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
2812 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
2813 TListOfIDs& listOfIDs = *arraysIt;
2814 aGroup.length( listOfIDs.size() );
2815 TListOfIDs::iterator idIt = listOfIDs.begin();
2816 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
2817 aGroup[ k ] = *idIt;
2821 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
2826 //=======================================================================
2827 //function : MergeElements
2829 //=======================================================================
2831 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
2835 TPythonDump aTPythonDump;
2836 aTPythonDump << this << ".MergeElements( [";
2838 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2840 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
2841 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
2842 aListOfListOfElementsID.push_back( list< int >() );
2843 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
2844 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
2845 CORBA::Long id = anElemsIDGroup[ j ];
2846 aListOfElemsID.push_back( id );
2848 if ( aListOfElemsID.size() < 2 )
2849 aListOfListOfElementsID.pop_back();
2850 if ( i > 0 ) aTPythonDump << ", ";
2851 aTPythonDump << anElemsIDGroup;
2854 ::SMESH_MeshEditor anEditor( myMesh );
2855 anEditor.MergeElements(aListOfListOfElementsID);
2857 aTPythonDump << "] )";
2860 //=======================================================================
2861 //function : MergeEqualElements
2863 //=======================================================================
2865 void SMESH_MeshEditor_i::MergeEqualElements()
2869 ::SMESH_MeshEditor anEditor( myMesh );
2870 anEditor.MergeEqualElements();
2872 TPythonDump() << this << ".MergeEqualElements()";
2875 //================================================================================
2877 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
2878 * move the node closest to the point to point's location and return ID of the node
2880 //================================================================================
2882 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
2885 CORBA::Long theNodeID)
2887 // We keep myNodeSearcher until any mesh modification:
2888 // 1) initData() deletes myNodeSearcher at any edition,
2889 // 2) TNodeSearcherDeleter - at any mesh compute event and mesh change
2893 int nodeID = theNodeID;
2894 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
2897 static TNodeSearcherDeleter deleter;
2898 deleter.Set( myMesh );
2899 if ( !myNodeSearcher ) {
2900 ::SMESH_MeshEditor anEditor( myMesh );
2901 myNodeSearcher = anEditor.GetNodeSearcher();
2904 node = myNodeSearcher->FindClosestTo( p );
2907 nodeID = node->GetID();
2908 if ( myPreviewMode ) // make preview data
2910 // in a preview mesh, make edges linked to a node
2911 TPreviewMesh tmpMesh;
2912 TIDSortedElemSet linkedNodes;
2913 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
2914 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
2915 for ( ; nIt != linkedNodes.end(); ++nIt )
2917 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
2918 tmpMesh.Copy( &edge );
2921 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
2923 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
2924 // fill preview data
2925 ::SMESH_MeshEditor anEditor( & tmpMesh );
2926 storeResult( anEditor );
2930 GetMeshDS()->MoveNode(node, x, y, z);
2934 if ( !myPreviewMode ) {
2935 TPythonDump() << "nodeID = " << this
2936 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z << " )";
2942 //=======================================================================
2943 //function : convError
2945 //=======================================================================
2947 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2949 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
2953 RETCASE( SEW_BORDER1_NOT_FOUND );
2954 RETCASE( SEW_BORDER2_NOT_FOUND );
2955 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
2956 RETCASE( SEW_BAD_SIDE_NODES );
2957 RETCASE( SEW_VOLUMES_TO_SPLIT );
2958 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
2959 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
2960 RETCASE( SEW_BAD_SIDE1_NODES );
2961 RETCASE( SEW_BAD_SIDE2_NODES );
2963 return SMESH::SMESH_MeshEditor::SEW_OK;
2966 //=======================================================================
2967 //function : SewFreeBorders
2969 //=======================================================================
2971 SMESH::SMESH_MeshEditor::Sew_Error
2972 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
2973 CORBA::Long SecondNodeID1,
2974 CORBA::Long LastNodeID1,
2975 CORBA::Long FirstNodeID2,
2976 CORBA::Long SecondNodeID2,
2977 CORBA::Long LastNodeID2,
2978 CORBA::Boolean CreatePolygons,
2979 CORBA::Boolean CreatePolyedrs)
2983 SMESHDS_Mesh* aMesh = GetMeshDS();
2985 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
2986 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
2987 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
2988 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
2989 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
2990 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
2992 if (!aBorderFirstNode ||
2993 !aBorderSecondNode||
2995 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
2996 if (!aSide2FirstNode ||
2997 !aSide2SecondNode ||
2999 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3001 TPythonDump() << "error = " << this << ".SewFreeBorders( "
3002 << FirstNodeID1 << ", "
3003 << SecondNodeID1 << ", "
3004 << LastNodeID1 << ", "
3005 << FirstNodeID2 << ", "
3006 << SecondNodeID2 << ", "
3007 << LastNodeID2 << ", "
3008 << CreatePolygons<< ", "
3009 << CreatePolyedrs<< " )";
3011 ::SMESH_MeshEditor anEditor( myMesh );
3012 SMESH::SMESH_MeshEditor::Sew_Error error =
3013 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3023 storeResult(anEditor);
3029 //=======================================================================
3030 //function : SewConformFreeBorders
3032 //=======================================================================
3034 SMESH::SMESH_MeshEditor::Sew_Error
3035 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3036 CORBA::Long SecondNodeID1,
3037 CORBA::Long LastNodeID1,
3038 CORBA::Long FirstNodeID2,
3039 CORBA::Long SecondNodeID2)
3043 SMESHDS_Mesh* aMesh = GetMeshDS();
3045 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3046 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3047 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3048 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3049 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3050 const SMDS_MeshNode* aSide2ThirdNode = 0;
3052 if (!aBorderFirstNode ||
3053 !aBorderSecondNode||
3055 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3056 if (!aSide2FirstNode ||
3058 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3060 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
3061 << FirstNodeID1 << ", "
3062 << SecondNodeID1 << ", "
3063 << LastNodeID1 << ", "
3064 << FirstNodeID2 << ", "
3065 << SecondNodeID2 << " )";
3067 ::SMESH_MeshEditor anEditor( myMesh );
3068 SMESH::SMESH_MeshEditor::Sew_Error error =
3069 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3078 storeResult(anEditor);
3084 //=======================================================================
3085 //function : SewBorderToSide
3087 //=======================================================================
3089 SMESH::SMESH_MeshEditor::Sew_Error
3090 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
3091 CORBA::Long SecondNodeIDOnFreeBorder,
3092 CORBA::Long LastNodeIDOnFreeBorder,
3093 CORBA::Long FirstNodeIDOnSide,
3094 CORBA::Long LastNodeIDOnSide,
3095 CORBA::Boolean CreatePolygons,
3096 CORBA::Boolean CreatePolyedrs)
3100 SMESHDS_Mesh* aMesh = GetMeshDS();
3102 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
3103 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
3104 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
3105 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
3106 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
3107 const SMDS_MeshNode* aSide2ThirdNode = 0;
3109 if (!aBorderFirstNode ||
3110 !aBorderSecondNode||
3112 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3113 if (!aSide2FirstNode ||
3115 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
3117 TPythonDump() << "error = " << this << ".SewBorderToSide( "
3118 << FirstNodeIDOnFreeBorder << ", "
3119 << SecondNodeIDOnFreeBorder << ", "
3120 << LastNodeIDOnFreeBorder << ", "
3121 << FirstNodeIDOnSide << ", "
3122 << LastNodeIDOnSide << ", "
3123 << CreatePolygons << ", "
3124 << CreatePolyedrs << ") ";
3126 ::SMESH_MeshEditor anEditor( myMesh );
3127 SMESH::SMESH_MeshEditor::Sew_Error error =
3128 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3138 storeResult(anEditor);
3144 //=======================================================================
3145 //function : SewSideElements
3147 //=======================================================================
3149 SMESH::SMESH_MeshEditor::Sew_Error
3150 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
3151 const SMESH::long_array& IDsOfSide2Elements,
3152 CORBA::Long NodeID1OfSide1ToMerge,
3153 CORBA::Long NodeID1OfSide2ToMerge,
3154 CORBA::Long NodeID2OfSide1ToMerge,
3155 CORBA::Long NodeID2OfSide2ToMerge)
3159 SMESHDS_Mesh* aMesh = GetMeshDS();
3161 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
3162 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
3163 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
3164 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
3166 if (!aFirstNode1ToMerge ||
3167 !aFirstNode2ToMerge )
3168 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
3169 if (!aSecondNode1ToMerge||
3170 !aSecondNode2ToMerge)
3171 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
3173 TIDSortedElemSet aSide1Elems, aSide2Elems;
3174 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
3175 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
3177 TPythonDump() << "error = " << this << ".SewSideElements( "
3178 << IDsOfSide1Elements << ", "
3179 << IDsOfSide2Elements << ", "
3180 << NodeID1OfSide1ToMerge << ", "
3181 << NodeID1OfSide2ToMerge << ", "
3182 << NodeID2OfSide1ToMerge << ", "
3183 << NodeID2OfSide2ToMerge << ")";
3185 ::SMESH_MeshEditor anEditor( myMesh );
3186 SMESH::SMESH_MeshEditor::Sew_Error error =
3187 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
3190 aSecondNode1ToMerge,
3191 aSecondNode2ToMerge));
3193 storeResult(anEditor);
3198 //================================================================================
3200 * \brief Set new nodes for given element
3201 * \param ide - element id
3202 * \param newIDs - new node ids
3203 * \retval CORBA::Boolean - true if result is OK
3205 //================================================================================
3207 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
3208 const SMESH::long_array& newIDs)
3212 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
3213 if(!elem) return false;
3215 int nbn = newIDs.length();
3217 vector<const SMDS_MeshNode*> aNodes(nbn);
3220 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
3223 aNodes[nbn1] = aNode;
3226 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
3227 << ide << ", " << newIDs << " )";
3229 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
3232 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
3235 //================================================================================
3237 * \brief Update myLastCreated* or myPreviewData
3238 * \param anEditor - it contains last modification results
3240 //================================================================================
3242 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
3244 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
3246 list<int> aNodesConnectivity;
3247 typedef map<int, int> TNodesMap;
3250 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
3251 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
3253 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
3254 int nbEdges = aMeshDS->NbEdges();
3255 int nbFaces = aMeshDS->NbFaces();
3256 int nbVolum = aMeshDS->NbVolumes();
3257 switch ( previewType ) {
3258 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
3259 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
3260 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
3263 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
3264 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
3266 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
3268 while ( itMeshElems->more() ) {
3269 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
3270 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
3273 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
3274 while ( itElemNodes->more() ) {
3275 const SMDS_MeshNode* aMeshNode =
3276 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
3277 int aNodeID = aMeshNode->GetID();
3278 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
3279 if ( anIter == nodesMap.end() ) {
3280 // filling the nodes coordinates
3281 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
3282 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
3283 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
3284 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
3287 aNodesConnectivity.push_back(anIter->second);
3290 // filling the elements types
3291 SMDSAbs_ElementType aType;
3293 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
3294 aType = SMDSAbs_Node;
3298 aType = aMeshElem->GetType();
3299 isPoly = aMeshElem->IsPoly();
3302 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
3303 myPreviewData->elementTypes[i].isPoly = isPoly;
3304 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
3308 myPreviewData->nodesXYZ.length( j );
3310 // filling the elements connectivities
3311 list<int>::iterator aConnIter = aNodesConnectivity.begin();
3312 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
3313 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
3314 myPreviewData->elementConnectivities[i] = *aConnIter;
3320 // add new nodes into myLastCreatedNodes
3321 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
3322 myLastCreatedNodes->length(aSeq.Length());
3323 for(int i=0; i<aSeq.Length(); i++)
3324 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
3327 // add new elements into myLastCreatedElems
3328 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
3329 myLastCreatedElems->length(aSeq.Length());
3330 for(int i=0; i<aSeq.Length(); i++)
3331 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
3335 //================================================================================
3337 * Return data of mesh edition preview
3339 //================================================================================
3341 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
3343 return myPreviewData._retn();
3346 //================================================================================
3348 * \brief Returns list of it's IDs of created nodes
3349 * \retval SMESH::long_array* - list of node ID
3351 //================================================================================
3353 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
3355 return myLastCreatedNodes._retn();
3358 //================================================================================
3360 * \brief Returns list of it's IDs of created elements
3361 * \retval SMESH::long_array* - list of elements' ID
3363 //================================================================================
3365 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
3367 return myLastCreatedElems._retn();
3370 //=======================================================================
3371 //function : ConvertToQuadratic
3373 //=======================================================================
3375 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
3377 ::SMESH_MeshEditor anEditor( myMesh );
3378 anEditor.ConvertToQuadratic(theForce3d);
3379 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
3382 //=======================================================================
3383 //function : ConvertFromQuadratic
3385 //=======================================================================
3387 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
3389 ::SMESH_MeshEditor anEditor( myMesh );
3390 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
3391 TPythonDump() << this << ".ConvertFromQuadratic()";
3395 //=======================================================================
3396 //function : makeMesh
3397 //purpose : create a named imported mesh
3398 //=======================================================================
3400 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
3402 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
3403 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
3404 SALOMEDS::Study_var study = gen->GetCurrentStudy();
3405 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
3406 gen->SetName( meshSO, theMeshName, "Mesh" );
3408 SALOMEDS::StudyBuilder_var builder = study->NewBuilder();
3409 SALOMEDS::GenericAttribute_var anAttr
3410 = builder->FindOrCreateAttribute( meshSO, "AttributePixMap" );
3411 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
3413 return mesh._retn();