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 "utilities.h"
42 #include "Utils_ExceptHandlers.hxx"
43 #include "Utils_CorbaException.hxx"
45 #include <BRepAdaptor_Surface.hxx>
46 #include <BRep_Tool.hxx>
47 #include <TopExp_Explorer.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Face.hxx>
55 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
59 #include <Standard_Failure.hxx>
62 #include <Standard_ErrorHandler.hxx>
67 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
70 using SMESH::TPythonDump;
74 //=============================================================================
76 * \brief Mesh to apply modifications for preview purposes
78 //=============================================================================
80 struct TPreviewMesh: public SMESH_Mesh
82 SMDSAbs_ElementType myPreviewType; // type to show
84 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
85 _isShapeToMesh = _id =_studyId =_idDoc = 0;
86 _myMeshDS = new SMESHDS_Mesh( _id, true );
87 myPreviewType = previewElements;
90 virtual ~TPreviewMesh() { delete _myMeshDS; }
91 //!< Copy a set of elements
92 void Copy(const TIDSortedElemSet & theElements,
93 TIDSortedElemSet& theCopyElements,
94 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
95 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
97 // loop on theIDsOfElements
98 TIDSortedElemSet::const_iterator eIt = theElements.begin();
99 for ( ; eIt != theElements.end(); ++eIt )
101 const SMDS_MeshElement* anElem = *eIt;
102 if ( !anElem ) continue;
103 SMDSAbs_ElementType type = anElem->GetType();
104 if ( type == theAvoidType ||
105 ( theSelectType != SMDSAbs_All && type != theSelectType ))
108 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
109 theCopyElements.insert( theCopyElements.end(), anElemCopy );
113 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
115 // copy element nodes
116 int anElemNbNodes = anElem->NbNodes();
117 vector< int > anElemNodesID( anElemNbNodes ) ;
118 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
119 for ( int i = 0; itElemNodes->more(); i++)
121 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
123 anElemNodesID[i] = anElemNode->GetID();
126 // creates a corresponding element on copied nodes
127 SMDS_MeshElement* anElemCopy = 0;
128 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
130 const SMDS_PolyhedralVolumeOfNodes* ph =
131 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
133 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
134 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
137 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
144 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
146 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
147 anElemNode->GetID());
149 };// struct TPreviewMesh
151 static SMESH_NodeSearcher * myNodeSearcher = 0;
153 //=============================================================================
155 * \brief Deleter of myNodeSearcher at any compute event occured
157 //=============================================================================
159 struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
163 TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
165 //!< Delete myNodeSearcher
168 if ( myNodeSearcher ) { delete myNodeSearcher; myNodeSearcher = 0; }
170 typedef map < int, SMESH_subMesh * > TDependsOnMap;
171 //!< The meshod called by submesh: do my main job
172 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
173 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
175 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
177 Unset( sm->GetFather() );
180 //!< set self on all submeshes and delete myNodeSearcher if other mesh is set
181 void Set(SMESH_Mesh* mesh)
183 if ( myMesh && myMesh != mesh ) {
188 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
189 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
190 TDependsOnMap::const_iterator sm;
191 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
192 sm->second->SetEventListener( this, 0, sm->second );
195 //!< delete self from all submeshes
196 void Unset(SMESH_Mesh* mesh)
198 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
199 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
200 TDependsOnMap::const_iterator sm;
201 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
202 sm->second->DeleteEventListener( this );
207 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
209 TCollection_AsciiString typeStr;
210 switch ( theMirrorType ) {
211 case SMESH::SMESH_MeshEditor::POINT:
212 typeStr = "SMESH.SMESH_MeshEditor.POINT";
214 case SMESH::SMESH_MeshEditor::AXIS:
215 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
218 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
224 //=============================================================================
228 //=============================================================================
230 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
233 myMesh = & theMesh->GetImpl();
234 myPreviewMode = isPreview;
237 //================================================================================
241 //================================================================================
243 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
247 //================================================================================
249 * \brief Clear members
251 //================================================================================
253 void SMESH_MeshEditor_i::initData()
255 if ( myPreviewMode ) {
256 myPreviewData = new SMESH::MeshPreviewStruct();
259 myLastCreatedElems = new SMESH::long_array();
260 myLastCreatedNodes = new SMESH::long_array();
261 TNodeSearcherDeleter::Delete();
265 //=============================================================================
269 //=============================================================================
272 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
276 ::SMESH_MeshEditor anEditor( myMesh );
279 for (int i = 0; i < IDsOfElements.length(); i++)
280 IdList.push_back( IDsOfElements[i] );
282 // Update Python script
283 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
285 TPythonDump() << "print 'RemoveElements: ', isDone";
288 return anEditor.Remove( IdList, false );
291 //=============================================================================
295 //=============================================================================
297 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
301 ::SMESH_MeshEditor anEditor( myMesh );
303 for (int i = 0; i < IDsOfNodes.length(); i++)
304 IdList.push_back( IDsOfNodes[i] );
306 // Update Python script
307 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
309 TPythonDump() << "print 'RemoveNodes: ', isDone";
312 return anEditor.Remove( IdList, true );
315 //=============================================================================
319 //=============================================================================
321 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
325 int NbNodes = IDsOfNodes.length();
326 SMDS_MeshElement* elem = 0;
329 CORBA::Long index1 = IDsOfNodes[0];
330 CORBA::Long index2 = IDsOfNodes[1];
331 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
333 // Update Python script
334 TPythonDump() << "edge = " << this << ".AddEdge([ "
335 << index1 << ", " << index2 <<" ])";
338 CORBA::Long n1 = IDsOfNodes[0];
339 CORBA::Long n2 = IDsOfNodes[1];
340 CORBA::Long n12 = IDsOfNodes[2];
341 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
342 GetMeshDS()->FindNode(n2),
343 GetMeshDS()->FindNode(n12));
344 // Update Python script
345 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
346 <<n1<<", "<<n2<<", "<<n12<<" ])";
350 return elem->GetID();
355 //=============================================================================
359 //=============================================================================
361 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
362 CORBA::Double y, CORBA::Double z)
366 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
368 // Update Python script
369 TPythonDump() << "nodeID = " << this << ".AddNode( "
370 << x << ", " << y << ", " << z << " )";
375 //=============================================================================
379 //=============================================================================
381 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
385 int NbNodes = IDsOfNodes.length();
391 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
392 for (int i = 0; i < NbNodes; i++)
393 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
395 SMDS_MeshElement* elem = 0;
397 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
399 else if (NbNodes == 4) {
400 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
402 else if (NbNodes == 6) {
403 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
406 else if (NbNodes == 8) {
407 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
408 nodes[4], nodes[5], nodes[6], nodes[7]);
411 // Update Python script
412 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
415 return elem->GetID();
420 //=============================================================================
424 //=============================================================================
425 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
426 (const SMESH::long_array & IDsOfNodes)
430 int NbNodes = IDsOfNodes.length();
431 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
432 for (int i = 0; i < NbNodes; i++)
433 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
435 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
437 // Update Python script
438 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
440 TPythonDump() << "print 'AddPolygonalFace: ', faceID";
444 return elem->GetID();
449 //=============================================================================
453 //=============================================================================
455 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
459 int NbNodes = IDsOfNodes.length();
460 vector< const SMDS_MeshNode*> n(NbNodes);
461 for(int i=0;i<NbNodes;i++)
462 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
464 SMDS_MeshElement* elem = 0;
467 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
468 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
469 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
470 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
471 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
472 n[6],n[7],n[8],n[9]);
474 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
475 n[7],n[8],n[9],n[10],n[11],n[12]);
477 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
478 n[9],n[10],n[11],n[12],n[13],n[14]);
480 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
481 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
482 n[15],n[16],n[17],n[18],n[19]);
486 // Update Python script
487 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
489 TPythonDump() << "print 'AddVolume: ', volID";
493 return elem->GetID();
498 //=============================================================================
500 * AddPolyhedralVolume
502 //=============================================================================
503 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume
504 (const SMESH::long_array & IDsOfNodes,
505 const SMESH::long_array & Quantities)
509 int NbNodes = IDsOfNodes.length();
510 std::vector<const SMDS_MeshNode*> n (NbNodes);
511 for (int i = 0; i < NbNodes; i++)
512 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
514 int NbFaces = Quantities.length();
515 std::vector<int> q (NbFaces);
516 for (int j = 0; j < NbFaces; j++)
517 q[j] = Quantities[j];
519 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
521 // Update Python script
522 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
523 << IDsOfNodes << ", " << Quantities << " )";
525 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
529 return elem->GetID();
534 //=============================================================================
536 * AddPolyhedralVolumeByFaces
538 //=============================================================================
539 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
540 (const SMESH::long_array & IdsOfFaces)
544 int NbFaces = IdsOfFaces.length();
545 std::vector<const SMDS_MeshNode*> poly_nodes;
546 std::vector<int> quantities (NbFaces);
548 for (int i = 0; i < NbFaces; i++) {
549 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
550 quantities[i] = aFace->NbNodes();
552 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
554 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
558 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
560 // Update Python script
561 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
562 << IdsOfFaces << " )";
564 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
568 return elem->GetID();
573 //=============================================================================
575 * \brief Bind a node to a vertex
576 * \param NodeID - node ID
577 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
578 * \retval boolean - false if NodeID or VertexID is invalid
580 //=============================================================================
582 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
583 throw (SALOME::SALOME_Exception)
585 Unexpect aCatch(SALOME_SalomeException);
587 SMESHDS_Mesh * mesh = GetMeshDS();
588 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
590 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
592 if ( mesh->MaxShapeIndex() < VertexID )
593 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
595 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
596 if ( shape.ShapeType() != TopAbs_VERTEX )
597 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
599 mesh->SetNodeOnVertex( node, VertexID );
602 //=============================================================================
604 * \brief Store node position on an edge
605 * \param NodeID - node ID
606 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
607 * \param paramOnEdge - parameter on edge where the node is located
608 * \retval boolean - false if any parameter is invalid
610 //=============================================================================
612 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
613 CORBA::Double paramOnEdge)
614 throw (SALOME::SALOME_Exception)
616 Unexpect aCatch(SALOME_SalomeException);
618 SMESHDS_Mesh * mesh = GetMeshDS();
619 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
621 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
623 if ( mesh->MaxShapeIndex() < EdgeID )
624 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
626 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
627 if ( shape.ShapeType() != TopAbs_EDGE )
628 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
631 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
632 if ( paramOnEdge < f || paramOnEdge > l )
633 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
635 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
638 //=============================================================================
640 * \brief Store node position on a face
641 * \param NodeID - node ID
642 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
643 * \param u - U parameter on face where the node is located
644 * \param v - V parameter on face where the node is located
645 * \retval boolean - false if any parameter is invalid
647 //=============================================================================
649 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
650 CORBA::Double u, CORBA::Double v)
651 throw (SALOME::SALOME_Exception)
653 Unexpect aCatch(SALOME_SalomeException);
655 SMESHDS_Mesh * mesh = GetMeshDS();
656 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
658 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
660 if ( mesh->MaxShapeIndex() < FaceID )
661 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
663 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
664 if ( shape.ShapeType() != TopAbs_FACE )
665 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
667 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
668 bool isOut = ( u < surf.FirstUParameter() ||
669 u > surf.LastUParameter() ||
670 v < surf.FirstVParameter() ||
671 v > surf.LastVParameter() );
675 cout << "FACE " << FaceID << " (" << u << "," << v << ") out of "
676 << " u( " << surf.FirstUParameter()
677 << "," << surf.LastUParameter()
678 << ") v( " << surf.FirstVParameter()
679 << "," << surf.LastVParameter()
682 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
685 mesh->SetNodeOnFace( node, FaceID, u, v );
688 //=============================================================================
690 * \brief Bind a node to a solid
691 * \param NodeID - node ID
692 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
693 * \retval boolean - false if NodeID or SolidID is invalid
695 //=============================================================================
697 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
698 throw (SALOME::SALOME_Exception)
700 Unexpect aCatch(SALOME_SalomeException);
702 SMESHDS_Mesh * mesh = GetMeshDS();
703 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
705 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
707 if ( mesh->MaxShapeIndex() < SolidID )
708 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
710 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
711 if ( shape.ShapeType() != TopAbs_SOLID &&
712 shape.ShapeType() != TopAbs_SHELL)
713 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
715 mesh->SetNodeInVolume( node, SolidID );
718 //=============================================================================
720 * \brief Bind an element to a shape
721 * \param ElementID - element ID
722 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
723 * \retval boolean - false if ElementID or ShapeID is invalid
725 //=============================================================================
727 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
729 throw (SALOME::SALOME_Exception)
731 Unexpect aCatch(SALOME_SalomeException);
733 SMESHDS_Mesh * mesh = GetMeshDS();
734 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
736 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
738 if ( mesh->MaxShapeIndex() < ShapeID )
739 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
741 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
742 if ( shape.ShapeType() != TopAbs_EDGE &&
743 shape.ShapeType() != TopAbs_FACE &&
744 shape.ShapeType() != TopAbs_SOLID &&
745 shape.ShapeType() != TopAbs_SHELL )
746 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
748 mesh->SetMeshElementOnShape( elem, ShapeID );
752 //=============================================================================
756 //=============================================================================
758 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
765 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
769 GetMeshDS()->MoveNode(node, x, y, z);
771 // Update Python script
772 TPythonDump() << "isDone = " << this << ".MoveNode( "
773 << NodeID << ", " << x << ", " << y << ", " << z << " )";
778 //=============================================================================
782 //=============================================================================
784 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
789 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
790 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
794 // Update Python script
795 TPythonDump() << "isDone = " << this << ".InverseDiag( "
796 << NodeID1 << ", " << NodeID2 << " )";
798 ::SMESH_MeshEditor aMeshEditor( myMesh );
799 return aMeshEditor.InverseDiag ( n1, n2 );
802 //=============================================================================
806 //=============================================================================
808 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
813 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
814 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
818 // Update Python script
819 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
820 << NodeID1 << ", " << NodeID2 << " )";
822 ::SMESH_MeshEditor aMeshEditor( myMesh );
824 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
826 storeResult(aMeshEditor);
831 //=============================================================================
835 //=============================================================================
837 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
841 ::SMESH_MeshEditor anEditor( myMesh );
842 for (int i = 0; i < IDsOfElements.length(); i++)
844 CORBA::Long index = IDsOfElements[i];
845 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
847 anEditor.Reorient( elem );
849 // Update Python script
850 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
856 //=============================================================================
860 //=============================================================================
862 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
866 SMESH::long_array_var anElementsId = theObject->GetIDs();
867 CORBA::Boolean isDone = Reorient(anElementsId);
869 // Clear python line, created by Reorient()
870 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
871 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
873 // Update Python script
874 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
881 //================================================================================
883 * \brief function for conversion long_array to TIDSortedElemSet
884 * \param IDs - array of IDs
885 * \param aMesh - mesh
886 * \param aMap - collection to fill
887 * \param aType - element type
889 //================================================================================
891 void arrayToSet(const SMESH::long_array & IDs,
892 const SMESHDS_Mesh* aMesh,
893 TIDSortedElemSet& aMap,
894 const SMDSAbs_ElementType aType = SMDSAbs_All )
896 for (int i=0; i<IDs.length(); i++) {
897 CORBA::Long ind = IDs[i];
898 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
899 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
905 //=============================================================================
909 //=============================================================================
910 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
911 SMESH::NumericalFunctor_ptr Criterion,
912 CORBA::Double MaxAngle)
916 SMESHDS_Mesh* aMesh = GetMeshDS();
917 TIDSortedElemSet faces;
918 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
920 SMESH::NumericalFunctor_i* aNumericalFunctor =
921 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
922 SMESH::Controls::NumericalFunctorPtr aCrit;
923 if ( !aNumericalFunctor )
924 aCrit.reset( new SMESH::Controls::AspectRatio() );
926 aCrit = aNumericalFunctor->GetNumericalFunctor();
928 // Update Python script
929 TPythonDump() << "isDone = " << this << ".TriToQuad( "
930 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
932 TPythonDump() << "print 'TriToQuad: ', isDone";
935 ::SMESH_MeshEditor anEditor( myMesh );
937 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
939 storeResult(anEditor);
945 //=============================================================================
949 //=============================================================================
950 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
951 SMESH::NumericalFunctor_ptr Criterion,
952 CORBA::Double MaxAngle)
956 SMESH::long_array_var anElementsId = theObject->GetIDs();
957 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
959 // Clear python line(s), created by TriToQuad()
960 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
961 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
963 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
966 SMESH::NumericalFunctor_i* aNumericalFunctor =
967 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
969 // Update Python script
970 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
971 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
973 TPythonDump() << "print 'TriToQuadObject: ', isDone";
980 //=============================================================================
984 //=============================================================================
985 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
986 SMESH::NumericalFunctor_ptr Criterion)
990 SMESHDS_Mesh* aMesh = GetMeshDS();
991 TIDSortedElemSet faces;
992 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
994 SMESH::NumericalFunctor_i* aNumericalFunctor =
995 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
996 SMESH::Controls::NumericalFunctorPtr aCrit;
997 if ( !aNumericalFunctor )
998 aCrit.reset( new SMESH::Controls::AspectRatio() );
1000 aCrit = aNumericalFunctor->GetNumericalFunctor();
1003 // Update Python script
1004 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1006 TPythonDump() << "print 'QuadToTri: ', isDone";
1009 ::SMESH_MeshEditor anEditor( myMesh );
1010 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1012 storeResult(anEditor);
1018 //=============================================================================
1022 //=============================================================================
1023 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1024 SMESH::NumericalFunctor_ptr Criterion)
1028 SMESH::long_array_var anElementsId = theObject->GetIDs();
1029 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1031 // Clear python line(s), created by QuadToTri()
1032 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1033 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1035 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1038 SMESH::NumericalFunctor_i* aNumericalFunctor =
1039 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1041 // Update Python script
1042 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1044 TPythonDump() << "print 'QuadToTriObject: ', isDone";
1051 //=============================================================================
1055 //=============================================================================
1056 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1057 CORBA::Boolean Diag13)
1061 SMESHDS_Mesh* aMesh = GetMeshDS();
1062 TIDSortedElemSet faces;
1063 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1065 // Update Python script
1066 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1067 << IDsOfElements << ", " << Diag13 << " )";
1069 TPythonDump() << "print 'SplitQuad: ', isDone";
1072 ::SMESH_MeshEditor anEditor( myMesh );
1073 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1075 storeResult(anEditor);
1081 //=============================================================================
1085 //=============================================================================
1086 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1087 CORBA::Boolean Diag13)
1091 SMESH::long_array_var anElementsId = theObject->GetIDs();
1092 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1094 // Clear python line(s), created by SplitQuad()
1095 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1096 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1098 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1101 // Update Python script
1102 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1103 << theObject << ", " << Diag13 << " )";
1105 TPythonDump() << "print 'SplitQuadObject: ', isDone";
1112 //=============================================================================
1116 //=============================================================================
1117 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1118 SMESH::NumericalFunctor_ptr Criterion)
1120 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1121 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1123 SMESH::NumericalFunctor_i* aNumericalFunctor =
1124 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1125 SMESH::Controls::NumericalFunctorPtr aCrit;
1126 if (aNumericalFunctor)
1127 aCrit = aNumericalFunctor->GetNumericalFunctor();
1129 aCrit.reset(new SMESH::Controls::AspectRatio());
1131 ::SMESH_MeshEditor anEditor (myMesh);
1132 return anEditor.BestSplit(quad, aCrit);
1138 //=======================================================================
1141 //=======================================================================
1144 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1145 const SMESH::long_array & IDsOfFixedNodes,
1146 CORBA::Long MaxNbOfIterations,
1147 CORBA::Double MaxAspectRatio,
1148 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1150 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1151 MaxAspectRatio, Method, false );
1155 //=======================================================================
1156 //function : SmoothParametric
1158 //=======================================================================
1161 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1162 const SMESH::long_array & IDsOfFixedNodes,
1163 CORBA::Long MaxNbOfIterations,
1164 CORBA::Double MaxAspectRatio,
1165 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1167 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1168 MaxAspectRatio, Method, true );
1172 //=======================================================================
1173 //function : SmoothObject
1175 //=======================================================================
1178 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1179 const SMESH::long_array & IDsOfFixedNodes,
1180 CORBA::Long MaxNbOfIterations,
1181 CORBA::Double MaxAspectRatio,
1182 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1184 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1185 MaxAspectRatio, Method, false);
1189 //=======================================================================
1190 //function : SmoothParametricObject
1192 //=======================================================================
1195 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1196 const SMESH::long_array & IDsOfFixedNodes,
1197 CORBA::Long MaxNbOfIterations,
1198 CORBA::Double MaxAspectRatio,
1199 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1201 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1202 MaxAspectRatio, Method, true);
1206 //=============================================================================
1210 //=============================================================================
1213 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1214 const SMESH::long_array & IDsOfFixedNodes,
1215 CORBA::Long MaxNbOfIterations,
1216 CORBA::Double MaxAspectRatio,
1217 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1222 SMESHDS_Mesh* aMesh = GetMeshDS();
1224 TIDSortedElemSet elements;
1225 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1227 set<const SMDS_MeshNode*> fixedNodes;
1228 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1229 CORBA::Long index = IDsOfFixedNodes[i];
1230 const SMDS_MeshNode * node = aMesh->FindNode(index);
1232 fixedNodes.insert( node );
1234 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1235 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1236 method = ::SMESH_MeshEditor::CENTROIDAL;
1238 ::SMESH_MeshEditor anEditor( myMesh );
1239 anEditor.Smooth(elements, fixedNodes, method,
1240 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1242 storeResult(anEditor);
1244 // Update Python script
1245 TPythonDump() << "isDone = " << this << "."
1246 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1247 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1248 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1249 << "SMESH.SMESH_MeshEditor."
1250 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1251 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1253 TPythonDump() << "print 'Smooth: ', isDone";
1260 //=============================================================================
1264 //=============================================================================
1267 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1268 const SMESH::long_array & IDsOfFixedNodes,
1269 CORBA::Long MaxNbOfIterations,
1270 CORBA::Double MaxAspectRatio,
1271 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1276 SMESH::long_array_var anElementsId = theObject->GetIDs();
1277 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1278 MaxAspectRatio, Method, IsParametric);
1280 // Clear python line(s), created by Smooth()
1281 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1282 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1284 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1287 // Update Python script
1288 TPythonDump() << "isDone = " << this << "."
1289 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1290 << theObject << ", " << IDsOfFixedNodes << ", "
1291 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1292 << "SMESH.SMESH_MeshEditor."
1293 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1294 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1296 TPythonDump() << "print 'SmoothObject: ', isDone";
1303 //=============================================================================
1307 //=============================================================================
1309 void SMESH_MeshEditor_i::RenumberNodes()
1311 // Update Python script
1312 TPythonDump() << this << ".RenumberNodes()";
1314 GetMeshDS()->Renumber( true );
1318 //=============================================================================
1322 //=============================================================================
1324 void SMESH_MeshEditor_i::RenumberElements()
1326 // Update Python script
1327 TPythonDump() << this << ".RenumberElements()";
1329 GetMeshDS()->Renumber( false );
1332 //=======================================================================
1334 * \brief Return groups by their IDs
1336 //=======================================================================
1338 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1342 myMesh_i->CreateGroupServants();
1343 return myMesh_i->GetGroups( *groupIDs );
1346 //=======================================================================
1347 //function : rotationSweep
1349 //=======================================================================
1351 SMESH::ListOfGroups*
1352 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1353 const SMESH::AxisStruct & theAxis,
1354 CORBA::Double theAngleInRadians,
1355 CORBA::Long theNbOfSteps,
1356 CORBA::Double theTolerance,
1357 const bool theMakeGroups)
1361 TIDSortedElemSet inElements, copyElements;
1362 arrayToSet(theIDsOfElements, GetMeshDS(), inElements);
1364 TIDSortedElemSet* workElements = & inElements;
1365 TPreviewMesh tmpMesh( SMDSAbs_Face );
1366 SMESH_Mesh* mesh = 0;
1367 bool makeWalls=true;
1368 if ( myPreviewMode )
1370 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1371 tmpMesh.Copy( inElements, copyElements, select, avoid );
1373 workElements = & copyElements;
1374 //makeWalls = false;
1381 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1382 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1384 ::SMESH_MeshEditor anEditor( mesh );
1385 ::SMESH_MeshEditor::PGroupIDs groupIds =
1386 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1387 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1388 storeResult(anEditor);
1390 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1393 //=======================================================================
1394 //function : RotationSweep
1396 //=======================================================================
1398 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1399 const SMESH::AxisStruct & theAxis,
1400 CORBA::Double theAngleInRadians,
1401 CORBA::Long theNbOfSteps,
1402 CORBA::Double theTolerance)
1404 if ( !myPreviewMode ) {
1405 TPythonDump() << "axis = " << theAxis;
1406 TPythonDump() << this << ".RotationSweep( "
1409 << theAngleInRadians << ", "
1410 << theNbOfSteps << ", "
1411 << theTolerance << " )";
1413 rotationSweep(theIDsOfElements,
1421 //=======================================================================
1422 //function : RotationSweepMakeGroups
1424 //=======================================================================
1426 SMESH::ListOfGroups*
1427 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1428 const SMESH::AxisStruct& theAxis,
1429 CORBA::Double theAngleInRadians,
1430 CORBA::Long theNbOfSteps,
1431 CORBA::Double theTolerance)
1433 if ( !myPreviewMode ) {
1434 TPythonDump() << "axis = " << theAxis;
1435 TPythonDump() << this << ".RotationSweepMakeGroups( "
1438 << theAngleInRadians << ", "
1439 << theNbOfSteps << ", "
1440 << theTolerance << " )";
1442 return rotationSweep(theIDsOfElements,
1450 //=======================================================================
1451 //function : RotationSweepObject
1453 //=======================================================================
1455 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1456 const SMESH::AxisStruct & theAxis,
1457 CORBA::Double theAngleInRadians,
1458 CORBA::Long theNbOfSteps,
1459 CORBA::Double theTolerance)
1461 if ( !myPreviewMode ) {
1462 TPythonDump() << "axis = " << theAxis;
1463 TPythonDump() << this << ".RotationSweepObject( "
1466 << theAngleInRadians << ", "
1467 << theNbOfSteps << ", "
1468 << theTolerance << " )";
1470 SMESH::long_array_var anElementsId = theObject->GetIDs();
1471 rotationSweep(anElementsId,
1479 //=======================================================================
1480 //function : RotationSweepObjectMakeGroups
1482 //=======================================================================
1484 SMESH::ListOfGroups*
1485 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1486 const SMESH::AxisStruct& theAxis,
1487 CORBA::Double theAngleInRadians,
1488 CORBA::Long theNbOfSteps,
1489 CORBA::Double theTolerance)
1491 if ( !myPreviewMode ) {
1492 TPythonDump() << "axis = " << theAxis;
1493 TPythonDump() << this << ".RotationSweepObjectMakeGroups( "
1496 << theAngleInRadians << ", "
1497 << theNbOfSteps << ", "
1498 << theTolerance << " )";
1500 SMESH::long_array_var anElementsId = theObject->GetIDs();
1501 return rotationSweep(anElementsId,
1510 //=======================================================================
1511 //function : extrusionSweep
1513 //=======================================================================
1515 SMESH::ListOfGroups*
1516 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1517 const SMESH::DirStruct & theStepVector,
1518 CORBA::Long theNbOfSteps,
1519 const bool theMakeGroups,
1520 const SMDSAbs_ElementType theElementType)
1528 TIDSortedElemSet elements;
1529 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1531 const SMESH::PointStruct * P = &theStepVector.PS;
1532 gp_Vec stepVec( P->x, P->y, P->z );
1534 TElemOfElemListMap aHystory;
1535 ::SMESH_MeshEditor anEditor( myMesh );
1536 ::SMESH_MeshEditor::PGroupIDs groupIds =
1537 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1539 storeResult(anEditor);
1541 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1543 } catch(Standard_Failure) {
1544 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1545 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1550 //=======================================================================
1551 //function : ExtrusionSweep
1553 //=======================================================================
1555 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1556 const SMESH::DirStruct & theStepVector,
1557 CORBA::Long theNbOfSteps)
1559 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1560 if ( !myPreviewMode ) {
1561 TPythonDump() << "stepVector = " << theStepVector;
1562 TPythonDump() << this << ".ExtrusionSweep( "
1563 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1568 //=======================================================================
1569 //function : ExtrusionSweepObject
1571 //=======================================================================
1573 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1574 const SMESH::DirStruct & theStepVector,
1575 CORBA::Long theNbOfSteps)
1577 SMESH::long_array_var anElementsId = theObject->GetIDs();
1578 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1579 if ( !myPreviewMode ) {
1580 TPythonDump() << "stepVector = " << theStepVector;
1581 TPythonDump() << this << ".ExtrusionSweepObject( "
1582 << theObject << ", stepVector, " << theNbOfSteps << " )";
1586 //=======================================================================
1587 //function : ExtrusionSweepObject1D
1589 //=======================================================================
1591 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1592 const SMESH::DirStruct & theStepVector,
1593 CORBA::Long theNbOfSteps)
1595 SMESH::long_array_var anElementsId = theObject->GetIDs();
1596 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1597 if ( !myPreviewMode ) {
1598 TPythonDump() << "stepVector = " << theStepVector;
1599 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1600 << theObject << ", stepVector, " << theNbOfSteps << " )";
1604 //=======================================================================
1605 //function : ExtrusionSweepObject2D
1607 //=======================================================================
1609 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1610 const SMESH::DirStruct & theStepVector,
1611 CORBA::Long theNbOfSteps)
1613 SMESH::long_array_var anElementsId = theObject->GetIDs();
1614 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1615 if ( !myPreviewMode ) {
1616 TPythonDump() << "stepVector = " << theStepVector;
1617 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1618 << theObject << ", stepVector, " << theNbOfSteps << " )";
1622 //=======================================================================
1623 //function : ExtrusionSweepMakeGroups
1625 //=======================================================================
1627 SMESH::ListOfGroups*
1628 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1629 const SMESH::DirStruct& theStepVector,
1630 CORBA::Long theNbOfSteps)
1632 if ( !myPreviewMode ) {
1633 TPythonDump() << "stepVector = " << theStepVector;
1634 TPythonDump() << this << ".ExtrusionSweepMakeGroups( "
1635 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1637 return extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1639 //=======================================================================
1640 //function : ExtrusionSweepObjectMakeGroups
1642 //=======================================================================
1644 SMESH::ListOfGroups*
1645 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1646 const SMESH::DirStruct& theStepVector,
1647 CORBA::Long theNbOfSteps)
1649 if ( !myPreviewMode ) {
1650 TPythonDump() << "stepVector = " << theStepVector;
1651 TPythonDump() << this << ".ExtrusionSweepObjectMakeGroups( "
1652 << theObject << ", stepVector, " << theNbOfSteps << " )";
1654 SMESH::long_array_var anElementsId = theObject->GetIDs();
1655 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1658 //=======================================================================
1659 //function : ExtrusionSweepObject1DMakeGroups
1661 //=======================================================================
1663 SMESH::ListOfGroups*
1664 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1665 const SMESH::DirStruct& theStepVector,
1666 CORBA::Long theNbOfSteps)
1668 if ( !myPreviewMode ) {
1669 TPythonDump() << "stepVector = " << theStepVector;
1670 TPythonDump() << this << ".ExtrusionSweepObject1DMakeGroups( "
1671 << theObject << ", stepVector, " << theNbOfSteps << " )";
1673 SMESH::long_array_var anElementsId = theObject->GetIDs();
1674 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1677 //=======================================================================
1678 //function : ExtrusionSweepObject2DMakeGroups
1680 //=======================================================================
1682 SMESH::ListOfGroups*
1683 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1684 const SMESH::DirStruct& theStepVector,
1685 CORBA::Long theNbOfSteps)
1687 if ( !myPreviewMode ) {
1688 TPythonDump() << "stepVector = " << theStepVector;
1689 TPythonDump() << this << ".ExtrusionSweepObject2DMakeGroups( "
1690 << theObject << ", stepVector, " << theNbOfSteps << " )";
1692 SMESH::long_array_var anElementsId = theObject->GetIDs();
1693 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1697 //=======================================================================
1698 //function : advancedExtrusion
1700 //=======================================================================
1702 SMESH::ListOfGroups*
1703 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1704 const SMESH::DirStruct & theStepVector,
1705 CORBA::Long theNbOfSteps,
1706 CORBA::Long theExtrFlags,
1707 CORBA::Double theSewTolerance,
1708 const bool theMakeGroups)
1712 TIDSortedElemSet elements;
1713 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1715 const SMESH::PointStruct * P = &theStepVector.PS;
1716 gp_Vec stepVec( P->x, P->y, P->z );
1718 ::SMESH_MeshEditor anEditor( myMesh );
1719 TElemOfElemListMap aHystory;
1720 ::SMESH_MeshEditor::PGroupIDs groupIds =
1721 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1722 theMakeGroups, theExtrFlags, theSewTolerance);
1723 storeResult(anEditor);
1725 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1728 //=======================================================================
1729 //function : AdvancedExtrusion
1731 //=======================================================================
1733 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1734 const SMESH::DirStruct & theStepVector,
1735 CORBA::Long theNbOfSteps,
1736 CORBA::Long theExtrFlags,
1737 CORBA::Double theSewTolerance)
1739 if ( !myPreviewMode ) {
1740 TPythonDump() << "stepVector = " << theStepVector;
1741 TPythonDump() << this << ".AdvancedExtrusion("
1744 << theNbOfSteps << ","
1745 << theExtrFlags << ", "
1746 << theSewTolerance << " )";
1748 advancedExtrusion( theIDsOfElements,
1756 //=======================================================================
1757 //function : AdvancedExtrusionMakeGroups
1759 //=======================================================================
1761 SMESH::ListOfGroups*
1762 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1763 const SMESH::DirStruct& theStepVector,
1764 CORBA::Long theNbOfSteps,
1765 CORBA::Long theExtrFlags,
1766 CORBA::Double theSewTolerance)
1768 if ( !myPreviewMode ) {
1769 TPythonDump() << "stepVector = " << theStepVector;
1770 TPythonDump() << this << ".AdvancedExtrusionMakeGroups("
1773 << theNbOfSteps << ","
1774 << theExtrFlags << ", "
1775 << theSewTolerance << " )";
1777 return advancedExtrusion( theIDsOfElements,
1786 //================================================================================
1788 * \brief Convert extrusion error to IDL enum
1790 //================================================================================
1792 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1794 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1798 RETCASE( EXTR_NO_ELEMENTS );
1799 RETCASE( EXTR_PATH_NOT_EDGE );
1800 RETCASE( EXTR_BAD_PATH_SHAPE );
1801 RETCASE( EXTR_BAD_STARTING_NODE );
1802 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1803 RETCASE( EXTR_CANT_GET_TANGENT );
1805 return SMESH::SMESH_MeshEditor::EXTR_OK;
1809 //=======================================================================
1810 //function : extrusionAlongPath
1812 //=======================================================================
1814 SMESH::ListOfGroups*
1815 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1816 SMESH::SMESH_Mesh_ptr thePathMesh,
1817 GEOM::GEOM_Object_ptr thePathShape,
1818 CORBA::Long theNodeStart,
1819 CORBA::Boolean theHasAngles,
1820 const SMESH::double_array & theAngles,
1821 CORBA::Boolean theHasRefPoint,
1822 const SMESH::PointStruct & theRefPoint,
1823 const bool theMakeGroups,
1824 SMESH::SMESH_MeshEditor::Extrusion_Error & theError)
1828 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1829 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1832 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1834 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1835 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1837 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
1838 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1842 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1844 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1848 TIDSortedElemSet elements;
1849 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1851 list<double> angles;
1852 for (int i = 0; i < theAngles.length(); i++) {
1853 angles.push_back( theAngles[i] );
1856 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1858 int nbOldGroups = myMesh->NbGroup();
1860 ::SMESH_MeshEditor anEditor( myMesh );
1861 ::SMESH_MeshEditor::Extrusion_Error error =
1862 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1863 theHasAngles, angles,
1864 theHasRefPoint, refPnt, theMakeGroups );
1865 storeResult(anEditor);
1866 theError = convExtrError( error );
1868 if ( theMakeGroups ) {
1869 list<int> groupIDs = myMesh->GetGroupIds();
1870 list<int>::iterator newBegin = groupIDs.begin();
1871 std::advance( newBegin, nbOldGroups ); // skip old groups
1872 groupIDs.erase( groupIDs.begin(), newBegin );
1873 return getGroups( & groupIDs );
1878 //=======================================================================
1879 //function : ExtrusionAlongPath
1881 //=======================================================================
1883 SMESH::SMESH_MeshEditor::Extrusion_Error
1884 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1885 SMESH::SMESH_Mesh_ptr thePathMesh,
1886 GEOM::GEOM_Object_ptr thePathShape,
1887 CORBA::Long theNodeStart,
1888 CORBA::Boolean theHasAngles,
1889 const SMESH::double_array & theAngles,
1890 CORBA::Boolean theHasRefPoint,
1891 const SMESH::PointStruct & theRefPoint)
1893 if ( !myPreviewMode ) {
1894 TPythonDump() << "rotAngles = " << theAngles;
1896 if ( theHasRefPoint )
1897 TPythonDump() << "refPoint = SMESH.PointStruct( "
1898 << theRefPoint.x << ", "
1899 << theRefPoint.y << ", "
1900 << theRefPoint.z << " )";
1902 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1904 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
1905 << theIDsOfElements << ", "
1906 << thePathMesh << ", "
1907 << thePathShape << ", "
1908 << theNodeStart << ", "
1909 << theHasAngles << ", "
1910 << "rotAngles" << ", "
1911 << theHasRefPoint << ", refPoint )";
1913 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1914 extrusionAlongPath( theIDsOfElements,
1927 //=======================================================================
1928 //function : ExtrusionAlongPathObject
1930 //=======================================================================
1932 SMESH::SMESH_MeshEditor::Extrusion_Error
1933 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
1934 SMESH::SMESH_Mesh_ptr thePathMesh,
1935 GEOM::GEOM_Object_ptr thePathShape,
1936 CORBA::Long theNodeStart,
1937 CORBA::Boolean theHasAngles,
1938 const SMESH::double_array & theAngles,
1939 CORBA::Boolean theHasRefPoint,
1940 const SMESH::PointStruct & theRefPoint)
1942 if ( !myPreviewMode ) {
1943 TPythonDump() << "rotAngles = " << theAngles;
1945 if ( theHasRefPoint )
1946 TPythonDump() << "refPoint = SMESH.PointStruct( "
1947 << theRefPoint.x << ", "
1948 << theRefPoint.y << ", "
1949 << theRefPoint.z << " )";
1951 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1953 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
1954 << theObject << ", "
1955 << thePathMesh << ", "
1956 << thePathShape << ", "
1957 << theNodeStart << ", "
1958 << theHasAngles << ", "
1959 << "rotAngles" << ", "
1960 << theHasRefPoint << ", refPoint )";
1962 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1963 SMESH::long_array_var anElementsId = theObject->GetIDs();
1964 extrusionAlongPath( anElementsId,
1978 //=======================================================================
1979 //function : ExtrusionAlongPathMakeGroups
1981 //=======================================================================
1983 SMESH::ListOfGroups*
1984 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
1985 SMESH::SMESH_Mesh_ptr thePathMesh,
1986 GEOM::GEOM_Object_ptr thePathShape,
1987 CORBA::Long theNodeStart,
1988 CORBA::Boolean theHasAngles,
1989 const SMESH::double_array& theAngles,
1990 CORBA::Boolean theHasRefPoint,
1991 const SMESH::PointStruct& theRefPoint,
1992 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
1994 if ( !myPreviewMode ) {
1995 TPythonDump() << "rotAngles = " << theAngles;
1997 if ( theHasRefPoint )
1998 TPythonDump() << "refPoint = SMESH.PointStruct( "
1999 << theRefPoint.x << ", "
2000 << theRefPoint.y << ", "
2001 << theRefPoint.z << " )";
2003 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2005 TPythonDump() << "groups = " << this << ".ExtrusionAlongPathMakeGroups( "
2006 << theIDsOfElements << ", "
2007 << thePathMesh << ", "
2008 << thePathShape << ", "
2009 << theNodeStart << ", "
2010 << theHasAngles << ", "
2011 << "rotAngles" << ", "
2012 << theHasRefPoint << ", refPoint )";
2014 return extrusionAlongPath( theIDsOfElements,
2026 //=======================================================================
2027 //function : ExtrusionAlongPathObjectMakeGroups
2029 //=======================================================================
2031 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2032 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2033 SMESH::SMESH_Mesh_ptr thePathMesh,
2034 GEOM::GEOM_Object_ptr thePathShape,
2035 CORBA::Long theNodeStart,
2036 CORBA::Boolean theHasAngles,
2037 const SMESH::double_array& theAngles,
2038 CORBA::Boolean theHasRefPoint,
2039 const SMESH::PointStruct& theRefPoint,
2040 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2042 if ( !myPreviewMode ) {
2043 TPythonDump() << "rotAngles = " << theAngles;
2045 if ( theHasRefPoint )
2046 TPythonDump() << "refPoint = SMESH.PointStruct( "
2047 << theRefPoint.x << ", "
2048 << theRefPoint.y << ", "
2049 << theRefPoint.z << " )";
2051 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2053 TPythonDump() << "groups = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2054 << theObject << ", "
2055 << thePathMesh << ", "
2056 << thePathShape << ", "
2057 << theNodeStart << ", "
2058 << theHasAngles << ", "
2059 << "rotAngles" << ", "
2060 << theHasRefPoint << ", refPoint )";
2062 SMESH::long_array_var anElementsId = theObject->GetIDs();
2063 return extrusionAlongPath( anElementsId,
2075 //================================================================================
2077 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2078 * of given angles along path steps
2079 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2080 * which proceeds the extrusion
2081 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2082 * is used to define the sub-mesh for the path
2084 //================================================================================
2086 SMESH::double_array*
2087 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2088 GEOM::GEOM_Object_ptr thePathShape,
2089 const SMESH::double_array & theAngles)
2091 SMESH::double_array_var aResult = new SMESH::double_array();
2092 return aResult._retn();
2096 //=======================================================================
2099 //=======================================================================
2101 SMESH::ListOfGroups*
2102 SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
2103 const SMESH::AxisStruct & theAxis,
2104 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2105 CORBA::Boolean theCopy,
2106 const bool theMakeGroups,
2107 ::SMESH_Mesh* theTargetMesh)
2111 TIDSortedElemSet elements;
2112 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2114 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2115 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2118 switch ( theMirrorType ) {
2119 case SMESH::SMESH_MeshEditor::POINT:
2120 aTrsf.SetMirror( P );
2122 case SMESH::SMESH_MeshEditor::AXIS:
2123 aTrsf.SetMirror( gp_Ax1( P, V ));
2126 aTrsf.SetMirror( gp_Ax2( P, V ));
2129 ::SMESH_MeshEditor anEditor( myMesh );
2130 ::SMESH_MeshEditor::PGroupIDs groupIds =
2131 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2134 storeResult(anEditor);
2136 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2139 //=======================================================================
2142 //=======================================================================
2144 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2145 const SMESH::AxisStruct & theAxis,
2146 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2147 CORBA::Boolean theCopy)
2149 if ( !myPreviewMode ) {
2150 TPythonDump() << this << ".Mirror( "
2151 << theIDsOfElements << ", "
2153 << mirrorTypeName(theMirrorType) << ", "
2156 mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2160 //=======================================================================
2161 //function : MirrorObject
2163 //=======================================================================
2165 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2166 const SMESH::AxisStruct & theAxis,
2167 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2168 CORBA::Boolean theCopy)
2170 if ( !myPreviewMode ) {
2171 TPythonDump() << this << ".MirrorObject( "
2172 << theObject << ", "
2174 << mirrorTypeName(theMirrorType) << ", "
2177 SMESH::long_array_var anElementsId = theObject->GetIDs();
2178 mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2181 //=======================================================================
2182 //function : MirrorMakeGroups
2184 //=======================================================================
2186 SMESH::ListOfGroups*
2187 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2188 const SMESH::AxisStruct& theMirror,
2189 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2191 if ( !myPreviewMode ) {
2192 TPythonDump() << this << ".MirrorMakeGroups( "
2193 << theIDsOfElements << ", "
2194 << theMirror << ", "
2195 << mirrorTypeName(theMirrorType) << " )";
2197 return mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2200 //=======================================================================
2201 //function : MirrorObjectMakeGroups
2203 //=======================================================================
2205 SMESH::ListOfGroups*
2206 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2207 const SMESH::AxisStruct& theMirror,
2208 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2210 if ( !myPreviewMode ) {
2211 TPythonDump() << this << ".MirrorObjectMakeGroups( "
2212 << theObject << ", "
2213 << theMirror << ", "
2214 << mirrorTypeName(theMirrorType) << " )";
2216 SMESH::long_array_var anElementsId = theObject->GetIDs();
2217 return mirror(anElementsId, theMirror, theMirrorType, true, true);
2220 //=======================================================================
2221 //function : MirrorMakeMesh
2223 //=======================================================================
2225 SMESH::SMESH_Mesh_ptr
2226 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2227 const SMESH::AxisStruct& theMirror,
2228 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2229 CORBA::Boolean theCopyGroups,
2230 const char* theMeshName)
2232 TPythonDump pydump; // to prevent dump at mesh creation
2234 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2235 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh ))
2237 mirror(theIDsOfElements, theMirror, theMirrorType,
2238 false, theCopyGroups, & mesh_i->GetImpl());
2239 mesh_i->CreateGroupServants();
2242 if ( !myPreviewMode ) {
2243 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2244 << theIDsOfElements << ", "
2245 << theMirror << ", "
2246 << mirrorTypeName(theMirrorType) << ", "
2247 << theCopyGroups << ", '"
2248 << theMeshName << "' )";
2250 return mesh._retn();
2253 //=======================================================================
2254 //function : MirrorObjectMakeMesh
2256 //=======================================================================
2258 SMESH::SMESH_Mesh_ptr
2259 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2260 const SMESH::AxisStruct& theMirror,
2261 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2262 CORBA::Boolean theCopyGroups,
2263 const char* theMeshName)
2265 TPythonDump pydump; // to prevent dump at mesh creation
2267 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2268 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh ))
2270 SMESH::long_array_var anElementsId = theObject->GetIDs();
2271 mirror(anElementsId, theMirror, theMirrorType,
2272 false, theCopyGroups, & mesh_i->GetImpl());
2273 mesh_i->CreateGroupServants();
2275 if ( !myPreviewMode ) {
2276 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
2277 << theObject << ", "
2278 << theMirror << ", "
2279 << mirrorTypeName(theMirrorType) << ", "
2280 << theCopyGroups << ", '"
2281 << theMeshName << "' )";
2283 return mesh._retn();
2286 //=======================================================================
2287 //function : translate
2289 //=======================================================================
2291 SMESH::ListOfGroups*
2292 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2293 const SMESH::DirStruct & theVector,
2294 CORBA::Boolean theCopy,
2295 const bool theMakeGroups,
2296 ::SMESH_Mesh* theTargetMesh)
2300 TIDSortedElemSet elements;
2301 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2304 const SMESH::PointStruct * P = &theVector.PS;
2305 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2307 ::SMESH_MeshEditor anEditor( myMesh );
2308 ::SMESH_MeshEditor::PGroupIDs groupIds =
2309 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2312 storeResult(anEditor);
2314 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2317 //=======================================================================
2318 //function : Translate
2320 //=======================================================================
2322 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2323 const SMESH::DirStruct & theVector,
2324 CORBA::Boolean theCopy)
2326 if ( !myPreviewMode ) {
2327 TPythonDump() << "vector = " << theVector;
2328 TPythonDump() << this << ".Translate( "
2333 translate(theIDsOfElements,
2339 //=======================================================================
2340 //function : TranslateObject
2342 //=======================================================================
2344 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
2345 const SMESH::DirStruct & theVector,
2346 CORBA::Boolean theCopy)
2348 if ( !myPreviewMode ) {
2349 TPythonDump() << this << ".TranslateObject( "
2354 SMESH::long_array_var anElementsId = theObject->GetIDs();
2355 translate(anElementsId,
2361 //=======================================================================
2362 //function : TranslateMakeGroups
2364 //=======================================================================
2366 SMESH::ListOfGroups*
2367 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
2368 const SMESH::DirStruct& theVector)
2370 if ( !myPreviewMode ) {
2371 TPythonDump() << "vector = " << theVector;
2372 TPythonDump() << this << ".TranslateMakeGroups( "
2376 return translate(theIDsOfElements,theVector,true,true);
2379 //=======================================================================
2380 //function : TranslateObjectMakeGroups
2382 //=======================================================================
2384 SMESH::ListOfGroups*
2385 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2386 const SMESH::DirStruct& theVector)
2388 if ( !myPreviewMode ) {
2389 TPythonDump() << "vector = " << theVector;
2390 TPythonDump() << this << ".TranslateObjectMakeGroups( "
2394 SMESH::long_array_var anElementsId = theObject->GetIDs();
2395 return translate(anElementsId, theVector, true, true);
2398 //=======================================================================
2399 //function : TranslateMakeMesh
2401 //=======================================================================
2403 SMESH::SMESH_Mesh_ptr
2404 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
2405 const SMESH::DirStruct& theVector,
2406 CORBA::Boolean theCopyGroups,
2407 const char* theMeshName)
2409 TPythonDump pydump; // to prevent dump at mesh creation
2410 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2412 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2413 translate(theIDsOfElements, theVector,
2414 false, theCopyGroups, & mesh_i->GetImpl());
2415 mesh_i->CreateGroupServants();
2417 if ( !myPreviewMode ) {
2418 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
2419 << theIDsOfElements << ", "
2420 << theVector << ", "
2421 << theCopyGroups << ", '"
2422 << theMeshName << "' )";
2424 return mesh._retn();
2427 //=======================================================================
2428 //function : TranslateObjectMakeMesh
2430 //=======================================================================
2432 SMESH::SMESH_Mesh_ptr
2433 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2434 const SMESH::DirStruct& theVector,
2435 CORBA::Boolean theCopyGroups,
2436 const char* theMeshName)
2438 TPythonDump pydump; // to prevent dump at mesh creation
2439 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2441 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2442 SMESH::long_array_var anElementsId = theObject->GetIDs();
2443 translate(anElementsId, theVector,
2444 false, theCopyGroups, & mesh_i->GetImpl());
2445 mesh_i->CreateGroupServants();
2447 if ( !myPreviewMode ) {
2448 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
2449 << theObject << ", "
2450 << theVector << ", "
2451 << theCopyGroups << ", '"
2452 << theMeshName << "' )";
2454 return mesh._retn();
2457 //=======================================================================
2460 //=======================================================================
2462 SMESH::ListOfGroups*
2463 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
2464 const SMESH::AxisStruct & theAxis,
2465 CORBA::Double theAngle,
2466 CORBA::Boolean theCopy,
2467 const bool theMakeGroups,
2468 ::SMESH_Mesh* theTargetMesh)
2472 TIDSortedElemSet elements;
2473 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2475 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2476 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2479 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
2481 ::SMESH_MeshEditor anEditor( myMesh );
2482 ::SMESH_MeshEditor::PGroupIDs groupIds =
2483 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2486 storeResult(anEditor);
2488 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2491 //=======================================================================
2494 //=======================================================================
2496 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
2497 const SMESH::AxisStruct & theAxis,
2498 CORBA::Double theAngle,
2499 CORBA::Boolean theCopy)
2501 if ( !myPreviewMode ) {
2502 TPythonDump() << "axis = " << theAxis;
2503 TPythonDump() << this << ".Rotate( "
2509 rotate(theIDsOfElements,
2516 //=======================================================================
2517 //function : RotateObject
2519 //=======================================================================
2521 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
2522 const SMESH::AxisStruct & theAxis,
2523 CORBA::Double theAngle,
2524 CORBA::Boolean theCopy)
2526 if ( !myPreviewMode ) {
2527 TPythonDump() << "axis = " << theAxis;
2528 TPythonDump() << this << ".RotateObject( "
2534 SMESH::long_array_var anElementsId = theObject->GetIDs();
2535 rotate(anElementsId,
2542 //=======================================================================
2543 //function : RotateMakeGroups
2545 //=======================================================================
2547 SMESH::ListOfGroups*
2548 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
2549 const SMESH::AxisStruct& theAxis,
2550 CORBA::Double theAngle)
2552 if ( !myPreviewMode ) {
2553 TPythonDump() << "axis = " << theAxis;
2554 TPythonDump() << this << ".RotateMakeGroups( "
2557 << theAngle << " )";
2559 return rotate(theIDsOfElements,theAxis,theAngle,true,true);
2562 //=======================================================================
2563 //function : RotateObjectMakeGroups
2565 //=======================================================================
2567 SMESH::ListOfGroups*
2568 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2569 const SMESH::AxisStruct& theAxis,
2570 CORBA::Double theAngle)
2572 if ( !myPreviewMode ) {
2573 TPythonDump() << "axis = " << theAxis;
2574 TPythonDump() << this << ".RotateObjectMakeGroups( "
2577 << theAngle << " )";
2579 SMESH::long_array_var anElementsId = theObject->GetIDs();
2580 return rotate(anElementsId,theAxis,theAngle,true,true);
2583 //=======================================================================
2584 //function : RotateMakeMesh
2586 //=======================================================================
2588 SMESH::SMESH_Mesh_ptr
2589 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
2590 const SMESH::AxisStruct& theAxis,
2591 CORBA::Double theAngleInRadians,
2592 CORBA::Boolean theCopyGroups,
2593 const char* theMeshName)
2595 TPythonDump pydump; // to prevent dump at mesh creation
2596 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2598 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2599 rotate(theIDsOfElements, theAxis, theAngleInRadians,
2600 false, theCopyGroups, & mesh_i->GetImpl());
2601 mesh_i->CreateGroupServants();
2603 if ( !myPreviewMode ) {
2604 pydump << mesh << " = " << this << ".RotateMakeMesh( "
2605 << theIDsOfElements << ", "
2607 << theAngleInRadians << ", "
2608 << theCopyGroups << ", '"
2609 << theMeshName << "' )";
2611 return mesh._retn();
2614 //=======================================================================
2615 //function : RotateObjectMakeMesh
2617 //=======================================================================
2619 SMESH::SMESH_Mesh_ptr
2620 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2621 const SMESH::AxisStruct& theAxis,
2622 CORBA::Double theAngleInRadians,
2623 CORBA::Boolean theCopyGroups,
2624 const char* theMeshName)
2626 TPythonDump pydump; // to prevent dump at mesh creation
2627 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2629 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2630 SMESH::long_array_var anElementsId = theObject->GetIDs();
2631 rotate(anElementsId, theAxis, theAngleInRadians,
2632 false, theCopyGroups, & mesh_i->GetImpl());
2633 mesh_i->CreateGroupServants();
2635 if ( !myPreviewMode ) {
2636 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
2637 << theObject << ", "
2639 << theAngleInRadians << ", "
2640 << theCopyGroups << ", '"
2641 << theMeshName << "' )";
2643 return mesh._retn();
2646 //=======================================================================
2647 //function : FindCoincidentNodes
2649 //=======================================================================
2651 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
2652 SMESH::array_of_long_array_out GroupsOfNodes)
2656 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2657 ::SMESH_MeshEditor anEditor( myMesh );
2658 set<const SMDS_MeshNode*> nodes; // no input nodes
2659 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2661 GroupsOfNodes = new SMESH::array_of_long_array;
2662 GroupsOfNodes->length( aListOfListOfNodes.size() );
2663 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2664 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2665 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2666 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2667 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2668 aGroup.length( aListOfNodes.size() );
2669 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2670 aGroup[ j ] = (*lIt)->GetID();
2672 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
2673 << Tolerance << " )";
2676 //=======================================================================
2677 //function : FindCoincidentNodesOnPart
2679 //=======================================================================
2680 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
2681 CORBA::Double Tolerance,
2682 SMESH::array_of_long_array_out GroupsOfNodes)
2685 SMESH::long_array_var aElementsId = theObject->GetIDs();
2687 SMESHDS_Mesh* aMesh = GetMeshDS();
2688 set<const SMDS_MeshNode*> nodes;
2690 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2691 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
2692 for(int i = 0; i < aElementsId->length(); i++) {
2693 CORBA::Long ind = aElementsId[i];
2694 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
2700 for(int i = 0; i < aElementsId->length(); i++) {
2701 CORBA::Long ind = aElementsId[i];
2702 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
2704 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
2705 while ( nIt->more() )
2706 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
2712 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2713 ::SMESH_MeshEditor anEditor( myMesh );
2715 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2717 GroupsOfNodes = new SMESH::array_of_long_array;
2718 GroupsOfNodes->length( aListOfListOfNodes.size() );
2719 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2720 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2721 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2722 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2723 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2724 aGroup.length( aListOfNodes.size() );
2725 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2726 aGroup[ j ] = (*lIt)->GetID();
2728 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
2730 << Tolerance << " )";
2733 //=======================================================================
2734 //function : MergeNodes
2736 //=======================================================================
2738 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
2742 SMESHDS_Mesh* aMesh = GetMeshDS();
2744 TPythonDump aTPythonDump;
2745 aTPythonDump << this << ".MergeNodes([";
2746 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2747 for (int i = 0; i < GroupsOfNodes.length(); i++)
2749 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
2750 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
2751 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
2752 for ( int j = 0; j < aNodeGroup.length(); j++ )
2754 CORBA::Long index = aNodeGroup[ j ];
2755 const SMDS_MeshNode * node = aMesh->FindNode(index);
2757 aListOfNodes.push_back( node );
2759 if ( aListOfNodes.size() < 2 )
2760 aListOfListOfNodes.pop_back();
2762 if ( i > 0 ) aTPythonDump << ", ";
2763 aTPythonDump << aNodeGroup;
2765 ::SMESH_MeshEditor anEditor( myMesh );
2766 anEditor.MergeNodes( aListOfListOfNodes );
2768 aTPythonDump << "])";
2771 //=======================================================================
2772 //function : FindEqualElements
2774 //=======================================================================
2775 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
2776 SMESH::array_of_long_array_out GroupsOfElementsID)
2779 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2780 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
2781 typedef list<int> TListOfIDs;
2782 set<const SMDS_MeshElement*> elems;
2783 SMESH::long_array_var aElementsId = theObject->GetIDs();
2784 SMESHDS_Mesh* aMesh = GetMeshDS();
2786 for(int i = 0; i < aElementsId->length(); i++) {
2787 CORBA::Long anID = aElementsId[i];
2788 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
2794 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2795 ::SMESH_MeshEditor anEditor( myMesh );
2796 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
2798 GroupsOfElementsID = new SMESH::array_of_long_array;
2799 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
2801 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
2802 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
2803 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
2804 TListOfIDs& listOfIDs = *arraysIt;
2805 aGroup.length( listOfIDs.size() );
2806 TListOfIDs::iterator idIt = listOfIDs.begin();
2807 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
2808 aGroup[ k ] = *idIt;
2812 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
2817 //=======================================================================
2818 //function : MergeElements
2820 //=======================================================================
2822 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
2826 TPythonDump aTPythonDump;
2827 aTPythonDump << this << ".MergeElements( [";
2829 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2831 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
2832 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
2833 aListOfListOfElementsID.push_back( list< int >() );
2834 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
2835 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
2836 CORBA::Long id = anElemsIDGroup[ j ];
2837 aListOfElemsID.push_back( id );
2839 if ( aListOfElemsID.size() < 2 )
2840 aListOfListOfElementsID.pop_back();
2841 if ( i > 0 ) aTPythonDump << ", ";
2842 aTPythonDump << anElemsIDGroup;
2845 ::SMESH_MeshEditor anEditor( myMesh );
2846 anEditor.MergeElements(aListOfListOfElementsID);
2848 aTPythonDump << "] )";
2851 //=======================================================================
2852 //function : MergeEqualElements
2854 //=======================================================================
2856 void SMESH_MeshEditor_i::MergeEqualElements()
2860 ::SMESH_MeshEditor anEditor( myMesh );
2861 anEditor.MergeEqualElements();
2863 TPythonDump() << this << ".MergeEqualElements()";
2866 //================================================================================
2868 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
2869 * move the node closest to the point to point's location and return ID of the node
2871 //================================================================================
2873 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
2876 CORBA::Long theNodeID)
2878 // We keep myNodeSearcher until any mesh modification:
2879 // 1) initData() deletes myNodeSearcher at any edition,
2880 // 2) TNodeSearcherDeleter - at any mesh compute event and mesh change
2884 int nodeID = theNodeID;
2885 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
2888 static TNodeSearcherDeleter deleter;
2889 deleter.Set( myMesh );
2890 if ( !myNodeSearcher ) {
2891 ::SMESH_MeshEditor anEditor( myMesh );
2892 myNodeSearcher = anEditor.GetNodeSearcher();
2895 node = myNodeSearcher->FindClosestTo( p );
2898 nodeID = node->GetID();
2899 if ( myPreviewMode ) // make preview data
2901 // in a preview mesh, make edges linked to a node
2902 TPreviewMesh tmpMesh;
2903 TIDSortedElemSet linkedNodes;
2904 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
2905 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
2906 for ( ; nIt != linkedNodes.end(); ++nIt )
2908 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
2909 tmpMesh.Copy( &edge );
2912 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
2914 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
2915 // fill preview data
2916 ::SMESH_MeshEditor anEditor( & tmpMesh );
2917 storeResult( anEditor );
2921 GetMeshDS()->MoveNode(node, x, y, z);
2925 if ( !myPreviewMode ) {
2926 TPythonDump() << "nodeID = " << this
2927 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z << " )";
2933 //=======================================================================
2934 //function : convError
2936 //=======================================================================
2938 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2940 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
2944 RETCASE( SEW_BORDER1_NOT_FOUND );
2945 RETCASE( SEW_BORDER2_NOT_FOUND );
2946 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
2947 RETCASE( SEW_BAD_SIDE_NODES );
2948 RETCASE( SEW_VOLUMES_TO_SPLIT );
2949 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
2950 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
2951 RETCASE( SEW_BAD_SIDE1_NODES );
2952 RETCASE( SEW_BAD_SIDE2_NODES );
2954 return SMESH::SMESH_MeshEditor::SEW_OK;
2957 //=======================================================================
2958 //function : SewFreeBorders
2960 //=======================================================================
2962 SMESH::SMESH_MeshEditor::Sew_Error
2963 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
2964 CORBA::Long SecondNodeID1,
2965 CORBA::Long LastNodeID1,
2966 CORBA::Long FirstNodeID2,
2967 CORBA::Long SecondNodeID2,
2968 CORBA::Long LastNodeID2,
2969 CORBA::Boolean CreatePolygons,
2970 CORBA::Boolean CreatePolyedrs)
2974 SMESHDS_Mesh* aMesh = GetMeshDS();
2976 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
2977 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
2978 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
2979 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
2980 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
2981 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
2983 if (!aBorderFirstNode ||
2984 !aBorderSecondNode||
2986 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
2987 if (!aSide2FirstNode ||
2988 !aSide2SecondNode ||
2990 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
2992 TPythonDump() << "error = " << this << ".SewFreeBorders( "
2993 << FirstNodeID1 << ", "
2994 << SecondNodeID1 << ", "
2995 << LastNodeID1 << ", "
2996 << FirstNodeID2 << ", "
2997 << SecondNodeID2 << ", "
2998 << LastNodeID2 << ", "
2999 << CreatePolygons<< ", "
3000 << CreatePolyedrs<< " )";
3002 ::SMESH_MeshEditor anEditor( myMesh );
3003 SMESH::SMESH_MeshEditor::Sew_Error error =
3004 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3014 storeResult(anEditor);
3020 //=======================================================================
3021 //function : SewConformFreeBorders
3023 //=======================================================================
3025 SMESH::SMESH_MeshEditor::Sew_Error
3026 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3027 CORBA::Long SecondNodeID1,
3028 CORBA::Long LastNodeID1,
3029 CORBA::Long FirstNodeID2,
3030 CORBA::Long SecondNodeID2)
3034 SMESHDS_Mesh* aMesh = GetMeshDS();
3036 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3037 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3038 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3039 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3040 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3041 const SMDS_MeshNode* aSide2ThirdNode = 0;
3043 if (!aBorderFirstNode ||
3044 !aBorderSecondNode||
3046 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3047 if (!aSide2FirstNode ||
3049 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3051 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
3052 << FirstNodeID1 << ", "
3053 << SecondNodeID1 << ", "
3054 << LastNodeID1 << ", "
3055 << FirstNodeID2 << ", "
3056 << SecondNodeID2 << " )";
3058 ::SMESH_MeshEditor anEditor( myMesh );
3059 SMESH::SMESH_MeshEditor::Sew_Error error =
3060 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3069 storeResult(anEditor);
3075 //=======================================================================
3076 //function : SewBorderToSide
3078 //=======================================================================
3080 SMESH::SMESH_MeshEditor::Sew_Error
3081 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
3082 CORBA::Long SecondNodeIDOnFreeBorder,
3083 CORBA::Long LastNodeIDOnFreeBorder,
3084 CORBA::Long FirstNodeIDOnSide,
3085 CORBA::Long LastNodeIDOnSide,
3086 CORBA::Boolean CreatePolygons,
3087 CORBA::Boolean CreatePolyedrs)
3091 SMESHDS_Mesh* aMesh = GetMeshDS();
3093 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
3094 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
3095 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
3096 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
3097 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
3098 const SMDS_MeshNode* aSide2ThirdNode = 0;
3100 if (!aBorderFirstNode ||
3101 !aBorderSecondNode||
3103 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3104 if (!aSide2FirstNode ||
3106 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
3108 TPythonDump() << "error = " << this << ".SewBorderToSide( "
3109 << FirstNodeIDOnFreeBorder << ", "
3110 << SecondNodeIDOnFreeBorder << ", "
3111 << LastNodeIDOnFreeBorder << ", "
3112 << FirstNodeIDOnSide << ", "
3113 << LastNodeIDOnSide << ", "
3114 << CreatePolygons << ", "
3115 << CreatePolyedrs << ") ";
3117 ::SMESH_MeshEditor anEditor( myMesh );
3118 SMESH::SMESH_MeshEditor::Sew_Error error =
3119 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3129 storeResult(anEditor);
3135 //=======================================================================
3136 //function : SewSideElements
3138 //=======================================================================
3140 SMESH::SMESH_MeshEditor::Sew_Error
3141 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
3142 const SMESH::long_array& IDsOfSide2Elements,
3143 CORBA::Long NodeID1OfSide1ToMerge,
3144 CORBA::Long NodeID1OfSide2ToMerge,
3145 CORBA::Long NodeID2OfSide1ToMerge,
3146 CORBA::Long NodeID2OfSide2ToMerge)
3150 SMESHDS_Mesh* aMesh = GetMeshDS();
3152 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
3153 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
3154 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
3155 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
3157 if (!aFirstNode1ToMerge ||
3158 !aFirstNode2ToMerge )
3159 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
3160 if (!aSecondNode1ToMerge||
3161 !aSecondNode2ToMerge)
3162 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
3164 TIDSortedElemSet aSide1Elems, aSide2Elems;
3165 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
3166 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
3168 TPythonDump() << "error = " << this << ".SewSideElements( "
3169 << IDsOfSide1Elements << ", "
3170 << IDsOfSide2Elements << ", "
3171 << NodeID1OfSide1ToMerge << ", "
3172 << NodeID1OfSide2ToMerge << ", "
3173 << NodeID2OfSide1ToMerge << ", "
3174 << NodeID2OfSide2ToMerge << ")";
3176 ::SMESH_MeshEditor anEditor( myMesh );
3177 SMESH::SMESH_MeshEditor::Sew_Error error =
3178 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
3181 aSecondNode1ToMerge,
3182 aSecondNode2ToMerge));
3184 storeResult(anEditor);
3189 //================================================================================
3191 * \brief Set new nodes for given element
3192 * \param ide - element id
3193 * \param newIDs - new node ids
3194 * \retval CORBA::Boolean - true if result is OK
3196 //================================================================================
3198 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
3199 const SMESH::long_array& newIDs)
3203 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
3204 if(!elem) return false;
3206 int nbn = newIDs.length();
3208 vector<const SMDS_MeshNode*> aNodes(nbn);
3211 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
3214 aNodes[nbn1] = aNode;
3217 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
3218 << ide << ", " << newIDs << " )";
3220 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
3223 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
3226 //================================================================================
3228 * \brief Update myLastCreated* or myPreviewData
3229 * \param anEditor - it contains last modification results
3231 //================================================================================
3233 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
3235 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
3237 list<int> aNodesConnectivity;
3238 typedef map<int, int> TNodesMap;
3241 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
3242 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
3244 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
3245 int nbEdges = aMeshDS->NbEdges();
3246 int nbFaces = aMeshDS->NbFaces();
3247 int nbVolum = aMeshDS->NbVolumes();
3248 switch ( previewType ) {
3249 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
3250 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
3251 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
3254 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
3255 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
3257 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
3259 while ( itMeshElems->more() ) {
3260 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
3261 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
3264 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
3265 while ( itElemNodes->more() ) {
3266 const SMDS_MeshNode* aMeshNode =
3267 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
3268 int aNodeID = aMeshNode->GetID();
3269 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
3270 if ( anIter == nodesMap.end() ) {
3271 // filling the nodes coordinates
3272 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
3273 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
3274 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
3275 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
3278 aNodesConnectivity.push_back(anIter->second);
3281 // filling the elements types
3282 SMDSAbs_ElementType aType;
3284 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
3285 aType = SMDSAbs_Node;
3289 aType = aMeshElem->GetType();
3290 isPoly = aMeshElem->IsPoly();
3293 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
3294 myPreviewData->elementTypes[i].isPoly = isPoly;
3295 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
3299 myPreviewData->nodesXYZ.length( j );
3301 // filling the elements connectivities
3302 list<int>::iterator aConnIter = aNodesConnectivity.begin();
3303 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
3304 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
3305 myPreviewData->elementConnectivities[i] = *aConnIter;
3311 // add new nodes into myLastCreatedNodes
3312 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
3313 myLastCreatedNodes->length(aSeq.Length());
3314 for(int i=0; i<aSeq.Length(); i++)
3315 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
3318 // add new elements into myLastCreatedElems
3319 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
3320 myLastCreatedElems->length(aSeq.Length());
3321 for(int i=0; i<aSeq.Length(); i++)
3322 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
3326 //================================================================================
3328 * Return data of mesh edition preview
3330 //================================================================================
3332 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
3334 return myPreviewData._retn();
3337 //================================================================================
3339 * \brief Returns list of it's IDs of created nodes
3340 * \retval SMESH::long_array* - list of node ID
3342 //================================================================================
3344 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
3346 return myLastCreatedNodes._retn();
3349 //================================================================================
3351 * \brief Returns list of it's IDs of created elements
3352 * \retval SMESH::long_array* - list of elements' ID
3354 //================================================================================
3356 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
3358 return myLastCreatedElems._retn();
3361 //=======================================================================
3362 //function : ConvertToQuadratic
3364 //=======================================================================
3366 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
3368 ::SMESH_MeshEditor anEditor( myMesh );
3369 anEditor.ConvertToQuadratic(theForce3d);
3370 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
3373 //=======================================================================
3374 //function : ConvertFromQuadratic
3376 //=======================================================================
3378 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
3380 ::SMESH_MeshEditor anEditor( myMesh );
3381 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
3382 TPythonDump() << this << ".ConvertFromQuadratic()";
3386 //=======================================================================
3387 //function : makeMesh
3388 //purpose : create a named imported mesh
3389 //=======================================================================
3391 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
3393 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
3394 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
3395 SALOMEDS::Study_var study = gen->GetCurrentStudy();
3396 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
3397 gen->SetName( meshSO, theMeshName, "Mesh" );
3399 SALOMEDS::StudyBuilder_var builder = study->NewBuilder();
3400 SALOMEDS::GenericAttribute_var anAttr
3401 = builder->FindOrCreateAttribute( meshSO, "AttributePixMap" );
3402 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
3404 return mesh._retn();