1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_MeshEditor_i.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESH_MeshEditor_i.hxx"
31 #include "SMDS_MeshEdge.hxx"
32 #include "SMDS_MeshFace.hxx"
33 #include "SMDS_MeshVolume.hxx"
34 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
35 #include "SMESH_MeshEditor.hxx"
36 #include "SMESH_subMeshEventListener.hxx"
37 #include "SMESH_Gen_i.hxx"
38 #include "SMESH_Filter_i.hxx"
39 #include "SMESH_PythonDump.hxx"
41 #include "CASCatch.hxx"
42 #include "utilities.h"
43 #include "Utils_ExceptHandlers.hxx"
44 #include "Utils_CorbaException.hxx"
46 #include <BRepAdaptor_Surface.hxx>
47 #include <BRep_Tool.hxx>
48 #include <TopExp_Explorer.hxx>
50 #include <TopoDS_Edge.hxx>
51 #include <TopoDS_Face.hxx>
56 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
60 #include <Standard_Failure.hxx>
63 #include <Standard_ErrorHandler.hxx>
65 #include "CASCatch.hxx"
70 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
73 using SMESH::TPythonDump;
77 //=============================================================================
79 * \brief Mesh to apply modifications for preview purposes
81 //=============================================================================
83 struct TPreviewMesh: public SMESH_Mesh
85 SMDSAbs_ElementType myPreviewType; // type to show
87 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
88 _isShapeToMesh = _id =_studyId =_idDoc = 0;
89 _myMeshDS = new SMESHDS_Mesh( _id, true );
90 myPreviewType = previewElements;
93 virtual ~TPreviewMesh() { delete _myMeshDS; }
94 //!< Copy a set of elements
95 void Copy(const TIDSortedElemSet & theElements,
96 TIDSortedElemSet& theCopyElements,
97 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
98 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
100 // loop on theIDsOfElements
101 TIDSortedElemSet::const_iterator eIt = theElements.begin();
102 for ( ; eIt != theElements.end(); ++eIt )
104 const SMDS_MeshElement* anElem = *eIt;
105 if ( !anElem ) continue;
106 SMDSAbs_ElementType type = anElem->GetType();
107 if ( type == theAvoidType ||
108 ( theSelectType != SMDSAbs_All && type != theSelectType ))
111 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
112 theCopyElements.insert( theCopyElements.end(), anElemCopy );
116 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
118 // copy element nodes
119 int anElemNbNodes = anElem->NbNodes();
120 vector< int > anElemNodesID( anElemNbNodes ) ;
121 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
122 for ( int i = 0; itElemNodes->more(); i++)
124 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
126 anElemNodesID[i] = anElemNode->GetID();
129 // creates a corresponding element on copied nodes
130 SMDS_MeshElement* anElemCopy = 0;
131 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
133 const SMDS_PolyhedralVolumeOfNodes* ph =
134 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
136 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
137 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
140 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
147 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
149 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
150 anElemNode->GetID());
152 };// struct TPreviewMesh
154 static SMESH_NodeSearcher * myNodeSearcher = 0;
156 //=============================================================================
158 * \brief Deleter of myNodeSearcher at any compute event occured
160 //=============================================================================
162 struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
166 TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
168 //!< Delete myNodeSearcher
171 if ( myNodeSearcher ) { delete myNodeSearcher; myNodeSearcher = 0; }
173 typedef map < int, SMESH_subMesh * > TDependsOnMap;
174 //!< The meshod called by submesh: do my main job
175 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
176 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
178 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
180 Unset( sm->GetFather() );
183 //!< set self on all submeshes and delete myNodeSearcher if other mesh is set
184 void Set(SMESH_Mesh* mesh)
186 if ( myMesh && myMesh != mesh ) {
191 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
192 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
193 TDependsOnMap::const_iterator sm;
194 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
195 sm->second->SetEventListener( this, 0, sm->second );
198 //!< delete self from all submeshes
199 void Unset(SMESH_Mesh* mesh)
201 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
202 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
203 TDependsOnMap::const_iterator sm;
204 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
205 sm->second->DeleteEventListener( this );
210 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
212 TCollection_AsciiString typeStr;
213 switch ( theMirrorType ) {
214 case SMESH::SMESH_MeshEditor::POINT:
215 typeStr = "SMESH.SMESH_MeshEditor.POINT";
217 case SMESH::SMESH_MeshEditor::AXIS:
218 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
221 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
227 //=============================================================================
231 //=============================================================================
233 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
236 myMesh = & theMesh->GetImpl();
237 myPreviewMode = isPreview;
240 //================================================================================
244 //================================================================================
246 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
250 //================================================================================
252 * \brief Clear members
254 //================================================================================
256 void SMESH_MeshEditor_i::initData()
258 if ( myPreviewMode ) {
259 myPreviewData = new SMESH::MeshPreviewStruct();
262 myLastCreatedElems = new SMESH::long_array();
263 myLastCreatedNodes = new SMESH::long_array();
264 TNodeSearcherDeleter::Delete();
268 //=============================================================================
272 //=============================================================================
275 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
279 ::SMESH_MeshEditor anEditor( myMesh );
282 for (int i = 0; i < IDsOfElements.length(); i++)
283 IdList.push_back( IDsOfElements[i] );
285 // Update Python script
286 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
288 TPythonDump() << "print 'RemoveElements: ', isDone";
291 return anEditor.Remove( IdList, false );
294 //=============================================================================
298 //=============================================================================
300 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
304 ::SMESH_MeshEditor anEditor( myMesh );
306 for (int i = 0; i < IDsOfNodes.length(); i++)
307 IdList.push_back( IDsOfNodes[i] );
309 // Update Python script
310 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
312 TPythonDump() << "print 'RemoveNodes: ', isDone";
315 return anEditor.Remove( IdList, true );
318 //=============================================================================
322 //=============================================================================
324 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
328 int NbNodes = IDsOfNodes.length();
329 SMDS_MeshElement* elem = 0;
332 CORBA::Long index1 = IDsOfNodes[0];
333 CORBA::Long index2 = IDsOfNodes[1];
334 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
336 // Update Python script
337 TPythonDump() << "edge = " << this << ".AddEdge([ "
338 << index1 << ", " << index2 <<" ])";
341 CORBA::Long n1 = IDsOfNodes[0];
342 CORBA::Long n2 = IDsOfNodes[1];
343 CORBA::Long n12 = IDsOfNodes[2];
344 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
345 GetMeshDS()->FindNode(n2),
346 GetMeshDS()->FindNode(n12));
347 // Update Python script
348 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
349 <<n1<<", "<<n2<<", "<<n12<<" ])";
353 return elem->GetID();
358 //=============================================================================
362 //=============================================================================
364 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
365 CORBA::Double y, CORBA::Double z)
369 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
371 // Update Python script
372 TPythonDump() << "nodeID = " << this << ".AddNode( "
373 << x << ", " << y << ", " << z << " )";
378 //=============================================================================
382 //=============================================================================
384 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
388 int NbNodes = IDsOfNodes.length();
394 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
395 for (int i = 0; i < NbNodes; i++)
396 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
398 SMDS_MeshElement* elem = 0;
400 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
402 else if (NbNodes == 4) {
403 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
405 else if (NbNodes == 6) {
406 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
409 else if (NbNodes == 8) {
410 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
411 nodes[4], nodes[5], nodes[6], nodes[7]);
414 // Update Python script
415 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
418 return elem->GetID();
423 //=============================================================================
427 //=============================================================================
428 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
429 (const SMESH::long_array & IDsOfNodes)
433 int NbNodes = IDsOfNodes.length();
434 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
435 for (int i = 0; i < NbNodes; i++)
436 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
438 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
440 // Update Python script
441 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
443 TPythonDump() << "print 'AddPolygonalFace: ', faceID";
447 return elem->GetID();
452 //=============================================================================
456 //=============================================================================
458 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
462 int NbNodes = IDsOfNodes.length();
463 vector< const SMDS_MeshNode*> n(NbNodes);
464 for(int i=0;i<NbNodes;i++)
465 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
467 SMDS_MeshElement* elem = 0;
470 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
471 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
472 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
473 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
474 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
475 n[6],n[7],n[8],n[9]);
477 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
478 n[7],n[8],n[9],n[10],n[11],n[12]);
480 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
481 n[9],n[10],n[11],n[12],n[13],n[14]);
483 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
484 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
485 n[15],n[16],n[17],n[18],n[19]);
489 // Update Python script
490 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
492 TPythonDump() << "print 'AddVolume: ', volID";
496 return elem->GetID();
501 //=============================================================================
503 * AddPolyhedralVolume
505 //=============================================================================
506 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume
507 (const SMESH::long_array & IDsOfNodes,
508 const SMESH::long_array & Quantities)
512 int NbNodes = IDsOfNodes.length();
513 std::vector<const SMDS_MeshNode*> n (NbNodes);
514 for (int i = 0; i < NbNodes; i++)
515 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
517 int NbFaces = Quantities.length();
518 std::vector<int> q (NbFaces);
519 for (int j = 0; j < NbFaces; j++)
520 q[j] = Quantities[j];
522 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
524 // Update Python script
525 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
526 << IDsOfNodes << ", " << Quantities << " )";
528 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
532 return elem->GetID();
537 //=============================================================================
539 * AddPolyhedralVolumeByFaces
541 //=============================================================================
542 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
543 (const SMESH::long_array & IdsOfFaces)
547 int NbFaces = IdsOfFaces.length();
548 std::vector<const SMDS_MeshNode*> poly_nodes;
549 std::vector<int> quantities (NbFaces);
551 for (int i = 0; i < NbFaces; i++) {
552 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
553 quantities[i] = aFace->NbNodes();
555 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
557 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
561 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
563 // Update Python script
564 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
565 << IdsOfFaces << " )";
567 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
571 return elem->GetID();
576 //=============================================================================
578 * \brief Bind a node to a vertex
579 * \param NodeID - node ID
580 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
581 * \retval boolean - false if NodeID or VertexID is invalid
583 //=============================================================================
585 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
586 throw (SALOME::SALOME_Exception)
588 Unexpect aCatch(SALOME_SalomeException);
590 SMESHDS_Mesh * mesh = GetMeshDS();
591 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
593 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
595 if ( mesh->MaxShapeIndex() < VertexID )
596 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
598 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
599 if ( shape.ShapeType() != TopAbs_VERTEX )
600 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
602 mesh->SetNodeOnVertex( node, VertexID );
605 //=============================================================================
607 * \brief Store node position on an edge
608 * \param NodeID - node ID
609 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
610 * \param paramOnEdge - parameter on edge where the node is located
611 * \retval boolean - false if any parameter is invalid
613 //=============================================================================
615 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
616 CORBA::Double paramOnEdge)
617 throw (SALOME::SALOME_Exception)
619 Unexpect aCatch(SALOME_SalomeException);
621 SMESHDS_Mesh * mesh = GetMeshDS();
622 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
624 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
626 if ( mesh->MaxShapeIndex() < EdgeID )
627 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
629 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
630 if ( shape.ShapeType() != TopAbs_EDGE )
631 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
634 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
635 if ( paramOnEdge < f || paramOnEdge > l )
636 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
638 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
641 //=============================================================================
643 * \brief Store node position on a face
644 * \param NodeID - node ID
645 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
646 * \param u - U parameter on face where the node is located
647 * \param v - V parameter on face where the node is located
648 * \retval boolean - false if any parameter is invalid
650 //=============================================================================
652 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
653 CORBA::Double u, CORBA::Double v)
654 throw (SALOME::SALOME_Exception)
656 Unexpect aCatch(SALOME_SalomeException);
658 SMESHDS_Mesh * mesh = GetMeshDS();
659 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
661 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
663 if ( mesh->MaxShapeIndex() < FaceID )
664 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
666 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
667 if ( shape.ShapeType() != TopAbs_FACE )
668 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
670 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
671 bool isOut = ( u < surf.FirstUParameter() ||
672 u > surf.LastUParameter() ||
673 v < surf.FirstVParameter() ||
674 v > surf.LastVParameter() );
678 cout << "FACE " << FaceID << " (" << u << "," << v << ") out of "
679 << " u( " << surf.FirstUParameter()
680 << "," << surf.LastUParameter()
681 << ") v( " << surf.FirstVParameter()
682 << "," << surf.LastVParameter()
685 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
688 mesh->SetNodeOnFace( node, FaceID, u, v );
691 //=============================================================================
693 * \brief Bind a node to a solid
694 * \param NodeID - node ID
695 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
696 * \retval boolean - false if NodeID or SolidID is invalid
698 //=============================================================================
700 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
701 throw (SALOME::SALOME_Exception)
703 Unexpect aCatch(SALOME_SalomeException);
705 SMESHDS_Mesh * mesh = GetMeshDS();
706 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
708 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
710 if ( mesh->MaxShapeIndex() < SolidID )
711 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
713 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
714 if ( shape.ShapeType() != TopAbs_SOLID &&
715 shape.ShapeType() != TopAbs_SHELL)
716 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
718 mesh->SetNodeInVolume( node, SolidID );
721 //=============================================================================
723 * \brief Bind an element to a shape
724 * \param ElementID - element ID
725 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
726 * \retval boolean - false if ElementID or ShapeID is invalid
728 //=============================================================================
730 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
732 throw (SALOME::SALOME_Exception)
734 Unexpect aCatch(SALOME_SalomeException);
736 SMESHDS_Mesh * mesh = GetMeshDS();
737 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
739 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
741 if ( mesh->MaxShapeIndex() < ShapeID )
742 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
744 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
745 if ( shape.ShapeType() != TopAbs_EDGE &&
746 shape.ShapeType() != TopAbs_FACE &&
747 shape.ShapeType() != TopAbs_SOLID &&
748 shape.ShapeType() != TopAbs_SHELL )
749 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
751 mesh->SetMeshElementOnShape( elem, ShapeID );
755 //=============================================================================
759 //=============================================================================
761 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
768 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
772 GetMeshDS()->MoveNode(node, x, y, z);
774 // Update Python script
775 TPythonDump() << "isDone = " << this << ".MoveNode( "
776 << NodeID << ", " << x << ", " << y << ", " << z << " )";
781 //=============================================================================
785 //=============================================================================
787 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
792 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
793 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
797 // Update Python script
798 TPythonDump() << "isDone = " << this << ".InverseDiag( "
799 << NodeID1 << ", " << NodeID2 << " )";
801 ::SMESH_MeshEditor aMeshEditor( myMesh );
802 return aMeshEditor.InverseDiag ( n1, n2 );
805 //=============================================================================
809 //=============================================================================
811 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
816 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
817 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
821 // Update Python script
822 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
823 << NodeID1 << ", " << NodeID2 << " )";
825 ::SMESH_MeshEditor aMeshEditor( myMesh );
827 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
829 storeResult(aMeshEditor);
834 //=============================================================================
838 //=============================================================================
840 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
844 ::SMESH_MeshEditor anEditor( myMesh );
845 for (int i = 0; i < IDsOfElements.length(); i++)
847 CORBA::Long index = IDsOfElements[i];
848 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
850 anEditor.Reorient( elem );
852 // Update Python script
853 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
859 //=============================================================================
863 //=============================================================================
865 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
869 SMESH::long_array_var anElementsId = theObject->GetIDs();
870 CORBA::Boolean isDone = Reorient(anElementsId);
872 // Clear python line, created by Reorient()
873 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
874 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
876 // Update Python script
877 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
884 //================================================================================
886 * \brief function for conversion long_array to TIDSortedElemSet
887 * \param IDs - array of IDs
888 * \param aMesh - mesh
889 * \param aMap - collection to fill
890 * \param aType - element type
892 //================================================================================
894 void arrayToSet(const SMESH::long_array & IDs,
895 const SMESHDS_Mesh* aMesh,
896 TIDSortedElemSet& aMap,
897 const SMDSAbs_ElementType aType = SMDSAbs_All )
899 for (int i=0; i<IDs.length(); i++) {
900 CORBA::Long ind = IDs[i];
901 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
902 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
908 //=============================================================================
912 //=============================================================================
913 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
914 SMESH::NumericalFunctor_ptr Criterion,
915 CORBA::Double MaxAngle)
919 SMESHDS_Mesh* aMesh = GetMeshDS();
920 TIDSortedElemSet faces;
921 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
923 SMESH::NumericalFunctor_i* aNumericalFunctor =
924 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
925 SMESH::Controls::NumericalFunctorPtr aCrit;
926 if ( !aNumericalFunctor )
927 aCrit.reset( new SMESH::Controls::AspectRatio() );
929 aCrit = aNumericalFunctor->GetNumericalFunctor();
931 // Update Python script
932 TPythonDump() << "isDone = " << this << ".TriToQuad( "
933 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
935 TPythonDump() << "print 'TriToQuad: ', isDone";
938 ::SMESH_MeshEditor anEditor( myMesh );
940 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
942 storeResult(anEditor);
948 //=============================================================================
952 //=============================================================================
953 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
954 SMESH::NumericalFunctor_ptr Criterion,
955 CORBA::Double MaxAngle)
959 SMESH::long_array_var anElementsId = theObject->GetIDs();
960 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
962 // Clear python line(s), created by TriToQuad()
963 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
964 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
966 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
969 SMESH::NumericalFunctor_i* aNumericalFunctor =
970 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
972 // Update Python script
973 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
974 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
976 TPythonDump() << "print 'TriToQuadObject: ', isDone";
983 //=============================================================================
987 //=============================================================================
988 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
989 SMESH::NumericalFunctor_ptr Criterion)
993 SMESHDS_Mesh* aMesh = GetMeshDS();
994 TIDSortedElemSet faces;
995 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
997 SMESH::NumericalFunctor_i* aNumericalFunctor =
998 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
999 SMESH::Controls::NumericalFunctorPtr aCrit;
1000 if ( !aNumericalFunctor )
1001 aCrit.reset( new SMESH::Controls::AspectRatio() );
1003 aCrit = aNumericalFunctor->GetNumericalFunctor();
1006 // Update Python script
1007 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1009 TPythonDump() << "print 'QuadToTri: ', isDone";
1012 ::SMESH_MeshEditor anEditor( myMesh );
1013 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1015 storeResult(anEditor);
1021 //=============================================================================
1025 //=============================================================================
1026 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1027 SMESH::NumericalFunctor_ptr Criterion)
1031 SMESH::long_array_var anElementsId = theObject->GetIDs();
1032 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1034 // Clear python line(s), created by QuadToTri()
1035 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1036 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1038 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1041 SMESH::NumericalFunctor_i* aNumericalFunctor =
1042 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1044 // Update Python script
1045 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1047 TPythonDump() << "print 'QuadToTriObject: ', isDone";
1054 //=============================================================================
1058 //=============================================================================
1059 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1060 CORBA::Boolean Diag13)
1064 SMESHDS_Mesh* aMesh = GetMeshDS();
1065 TIDSortedElemSet faces;
1066 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1068 // Update Python script
1069 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1070 << IDsOfElements << ", " << Diag13 << " )";
1072 TPythonDump() << "print 'SplitQuad: ', isDone";
1075 ::SMESH_MeshEditor anEditor( myMesh );
1076 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1078 storeResult(anEditor);
1084 //=============================================================================
1088 //=============================================================================
1089 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1090 CORBA::Boolean Diag13)
1094 SMESH::long_array_var anElementsId = theObject->GetIDs();
1095 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1097 // Clear python line(s), created by SplitQuad()
1098 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1099 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1101 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1104 // Update Python script
1105 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1106 << theObject << ", " << Diag13 << " )";
1108 TPythonDump() << "print 'SplitQuadObject: ', isDone";
1115 //=============================================================================
1119 //=============================================================================
1120 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1121 SMESH::NumericalFunctor_ptr Criterion)
1123 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1124 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1126 SMESH::NumericalFunctor_i* aNumericalFunctor =
1127 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1128 SMESH::Controls::NumericalFunctorPtr aCrit;
1129 if (aNumericalFunctor)
1130 aCrit = aNumericalFunctor->GetNumericalFunctor();
1132 aCrit.reset(new SMESH::Controls::AspectRatio());
1134 ::SMESH_MeshEditor anEditor (myMesh);
1135 return anEditor.BestSplit(quad, aCrit);
1141 //=======================================================================
1144 //=======================================================================
1147 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1148 const SMESH::long_array & IDsOfFixedNodes,
1149 CORBA::Long MaxNbOfIterations,
1150 CORBA::Double MaxAspectRatio,
1151 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1153 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1154 MaxAspectRatio, Method, false );
1158 //=======================================================================
1159 //function : SmoothParametric
1161 //=======================================================================
1164 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1165 const SMESH::long_array & IDsOfFixedNodes,
1166 CORBA::Long MaxNbOfIterations,
1167 CORBA::Double MaxAspectRatio,
1168 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1170 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1171 MaxAspectRatio, Method, true );
1175 //=======================================================================
1176 //function : SmoothObject
1178 //=======================================================================
1181 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1182 const SMESH::long_array & IDsOfFixedNodes,
1183 CORBA::Long MaxNbOfIterations,
1184 CORBA::Double MaxAspectRatio,
1185 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1187 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1188 MaxAspectRatio, Method, false);
1192 //=======================================================================
1193 //function : SmoothParametricObject
1195 //=======================================================================
1198 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1199 const SMESH::long_array & IDsOfFixedNodes,
1200 CORBA::Long MaxNbOfIterations,
1201 CORBA::Double MaxAspectRatio,
1202 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1204 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1205 MaxAspectRatio, Method, true);
1209 //=============================================================================
1213 //=============================================================================
1216 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1217 const SMESH::long_array & IDsOfFixedNodes,
1218 CORBA::Long MaxNbOfIterations,
1219 CORBA::Double MaxAspectRatio,
1220 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1225 SMESHDS_Mesh* aMesh = GetMeshDS();
1227 TIDSortedElemSet elements;
1228 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1230 set<const SMDS_MeshNode*> fixedNodes;
1231 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1232 CORBA::Long index = IDsOfFixedNodes[i];
1233 const SMDS_MeshNode * node = aMesh->FindNode(index);
1235 fixedNodes.insert( node );
1237 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1238 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1239 method = ::SMESH_MeshEditor::CENTROIDAL;
1241 ::SMESH_MeshEditor anEditor( myMesh );
1242 anEditor.Smooth(elements, fixedNodes, method,
1243 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1245 storeResult(anEditor);
1247 // Update Python script
1248 TPythonDump() << "isDone = " << this << "."
1249 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1250 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1251 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1252 << "SMESH.SMESH_MeshEditor."
1253 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1254 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1256 TPythonDump() << "print 'Smooth: ', isDone";
1263 //=============================================================================
1267 //=============================================================================
1270 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1271 const SMESH::long_array & IDsOfFixedNodes,
1272 CORBA::Long MaxNbOfIterations,
1273 CORBA::Double MaxAspectRatio,
1274 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1279 SMESH::long_array_var anElementsId = theObject->GetIDs();
1280 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1281 MaxAspectRatio, Method, IsParametric);
1283 // Clear python line(s), created by Smooth()
1284 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1285 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1287 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1290 // Update Python script
1291 TPythonDump() << "isDone = " << this << "."
1292 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1293 << theObject << ", " << IDsOfFixedNodes << ", "
1294 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1295 << "SMESH.SMESH_MeshEditor."
1296 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1297 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1299 TPythonDump() << "print 'SmoothObject: ', isDone";
1306 //=============================================================================
1310 //=============================================================================
1312 void SMESH_MeshEditor_i::RenumberNodes()
1314 // Update Python script
1315 TPythonDump() << this << ".RenumberNodes()";
1317 GetMeshDS()->Renumber( true );
1321 //=============================================================================
1325 //=============================================================================
1327 void SMESH_MeshEditor_i::RenumberElements()
1329 // Update Python script
1330 TPythonDump() << this << ".RenumberElements()";
1332 GetMeshDS()->Renumber( false );
1335 //=======================================================================
1337 * \brief Return groups by their IDs
1339 //=======================================================================
1341 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1345 myMesh_i->CreateGroupServants();
1346 return myMesh_i->GetGroups( *groupIDs );
1349 //=======================================================================
1350 //function : rotationSweep
1352 //=======================================================================
1354 SMESH::ListOfGroups*
1355 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1356 const SMESH::AxisStruct & theAxis,
1357 CORBA::Double theAngleInRadians,
1358 CORBA::Long theNbOfSteps,
1359 CORBA::Double theTolerance,
1360 const bool theMakeGroups)
1364 TIDSortedElemSet inElements, copyElements;
1365 arrayToSet(theIDsOfElements, GetMeshDS(), inElements);
1367 TIDSortedElemSet* workElements = & inElements;
1368 TPreviewMesh tmpMesh( SMDSAbs_Face );
1369 SMESH_Mesh* mesh = 0;
1370 bool makeWalls=true;
1371 if ( myPreviewMode )
1373 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1374 tmpMesh.Copy( inElements, copyElements, select, avoid );
1376 workElements = & copyElements;
1377 //makeWalls = false;
1384 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1385 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1387 ::SMESH_MeshEditor anEditor( mesh );
1388 ::SMESH_MeshEditor::PGroupIDs groupIds =
1389 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1390 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1391 storeResult(anEditor);
1393 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1396 //=======================================================================
1397 //function : RotationSweep
1399 //=======================================================================
1401 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1402 const SMESH::AxisStruct & theAxis,
1403 CORBA::Double theAngleInRadians,
1404 CORBA::Long theNbOfSteps,
1405 CORBA::Double theTolerance)
1407 if ( !myPreviewMode ) {
1408 TPythonDump() << "axis = " << theAxis;
1409 TPythonDump() << this << ".RotationSweep( "
1412 << theAngleInRadians << ", "
1413 << theNbOfSteps << ", "
1414 << theTolerance << " )";
1416 rotationSweep(theIDsOfElements,
1424 //=======================================================================
1425 //function : RotationSweepMakeGroups
1427 //=======================================================================
1429 SMESH::ListOfGroups*
1430 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1431 const SMESH::AxisStruct& theAxis,
1432 CORBA::Double theAngleInRadians,
1433 CORBA::Long theNbOfSteps,
1434 CORBA::Double theTolerance)
1436 if ( !myPreviewMode ) {
1437 TPythonDump() << "axis = " << theAxis;
1438 TPythonDump() << this << ".RotationSweepMakeGroups( "
1441 << theAngleInRadians << ", "
1442 << theNbOfSteps << ", "
1443 << theTolerance << " )";
1445 return rotationSweep(theIDsOfElements,
1453 //=======================================================================
1454 //function : RotationSweepObject
1456 //=======================================================================
1458 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1459 const SMESH::AxisStruct & theAxis,
1460 CORBA::Double theAngleInRadians,
1461 CORBA::Long theNbOfSteps,
1462 CORBA::Double theTolerance)
1464 if ( !myPreviewMode ) {
1465 TPythonDump() << "axis = " << theAxis;
1466 TPythonDump() << this << ".RotationSweepObject( "
1469 << theAngleInRadians << ", "
1470 << theNbOfSteps << ", "
1471 << theTolerance << " )";
1473 SMESH::long_array_var anElementsId = theObject->GetIDs();
1474 rotationSweep(anElementsId,
1482 //=======================================================================
1483 //function : RotationSweepObjectMakeGroups
1485 //=======================================================================
1487 SMESH::ListOfGroups*
1488 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1489 const SMESH::AxisStruct& theAxis,
1490 CORBA::Double theAngleInRadians,
1491 CORBA::Long theNbOfSteps,
1492 CORBA::Double theTolerance)
1494 if ( !myPreviewMode ) {
1495 TPythonDump() << "axis = " << theAxis;
1496 TPythonDump() << this << ".RotationSweepObjectMakeGroups( "
1499 << theAngleInRadians << ", "
1500 << theNbOfSteps << ", "
1501 << theTolerance << " )";
1503 SMESH::long_array_var anElementsId = theObject->GetIDs();
1504 return rotationSweep(anElementsId,
1513 //=======================================================================
1514 //function : extrusionSweep
1516 //=======================================================================
1518 SMESH::ListOfGroups*
1519 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1520 const SMESH::DirStruct & theStepVector,
1521 CORBA::Long theNbOfSteps,
1522 const bool theMakeGroups,
1523 const SMDSAbs_ElementType theElementType)
1533 TIDSortedElemSet elements;
1534 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1536 const SMESH::PointStruct * P = &theStepVector.PS;
1537 gp_Vec stepVec( P->x, P->y, P->z );
1539 TElemOfElemListMap aHystory;
1540 ::SMESH_MeshEditor anEditor( myMesh );
1541 ::SMESH_MeshEditor::PGroupIDs groupIds =
1542 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1544 storeResult(anEditor);
1546 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1549 } catch(Standard_Failure) {
1551 } CASCatch_CATCH(Standard_Failure) {
1553 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1554 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1559 //=======================================================================
1560 //function : ExtrusionSweep
1562 //=======================================================================
1564 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1565 const SMESH::DirStruct & theStepVector,
1566 CORBA::Long theNbOfSteps)
1568 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1569 if ( !myPreviewMode ) {
1570 TPythonDump() << "stepVector = " << theStepVector;
1571 TPythonDump() << this << ".ExtrusionSweep( "
1572 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1577 //=======================================================================
1578 //function : ExtrusionSweepObject
1580 //=======================================================================
1582 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1583 const SMESH::DirStruct & theStepVector,
1584 CORBA::Long theNbOfSteps)
1586 SMESH::long_array_var anElementsId = theObject->GetIDs();
1587 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1588 if ( !myPreviewMode ) {
1589 TPythonDump() << "stepVector = " << theStepVector;
1590 TPythonDump() << this << ".ExtrusionSweepObject( "
1591 << theObject << ", stepVector, " << theNbOfSteps << " )";
1595 //=======================================================================
1596 //function : ExtrusionSweepObject1D
1598 //=======================================================================
1600 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1601 const SMESH::DirStruct & theStepVector,
1602 CORBA::Long theNbOfSteps)
1604 SMESH::long_array_var anElementsId = theObject->GetIDs();
1605 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1606 if ( !myPreviewMode ) {
1607 TPythonDump() << "stepVector = " << theStepVector;
1608 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1609 << theObject << ", stepVector, " << theNbOfSteps << " )";
1613 //=======================================================================
1614 //function : ExtrusionSweepObject2D
1616 //=======================================================================
1618 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1619 const SMESH::DirStruct & theStepVector,
1620 CORBA::Long theNbOfSteps)
1622 SMESH::long_array_var anElementsId = theObject->GetIDs();
1623 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1624 if ( !myPreviewMode ) {
1625 TPythonDump() << "stepVector = " << theStepVector;
1626 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1627 << theObject << ", stepVector, " << theNbOfSteps << " )";
1631 //=======================================================================
1632 //function : ExtrusionSweepMakeGroups
1634 //=======================================================================
1636 SMESH::ListOfGroups*
1637 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1638 const SMESH::DirStruct& theStepVector,
1639 CORBA::Long theNbOfSteps)
1641 if ( !myPreviewMode ) {
1642 TPythonDump() << "stepVector = " << theStepVector;
1643 TPythonDump() << this << ".ExtrusionSweepMakeGroups( "
1644 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1646 return extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1648 //=======================================================================
1649 //function : ExtrusionSweepObjectMakeGroups
1651 //=======================================================================
1653 SMESH::ListOfGroups*
1654 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1655 const SMESH::DirStruct& theStepVector,
1656 CORBA::Long theNbOfSteps)
1658 if ( !myPreviewMode ) {
1659 TPythonDump() << "stepVector = " << theStepVector;
1660 TPythonDump() << this << ".ExtrusionSweepObjectMakeGroups( "
1661 << theObject << ", stepVector, " << theNbOfSteps << " )";
1663 SMESH::long_array_var anElementsId = theObject->GetIDs();
1664 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1667 //=======================================================================
1668 //function : ExtrusionSweepObject1DMakeGroups
1670 //=======================================================================
1672 SMESH::ListOfGroups*
1673 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1674 const SMESH::DirStruct& theStepVector,
1675 CORBA::Long theNbOfSteps)
1677 if ( !myPreviewMode ) {
1678 TPythonDump() << "stepVector = " << theStepVector;
1679 TPythonDump() << this << ".ExtrusionSweepObject1DMakeGroups( "
1680 << theObject << ", stepVector, " << theNbOfSteps << " )";
1682 SMESH::long_array_var anElementsId = theObject->GetIDs();
1683 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1686 //=======================================================================
1687 //function : ExtrusionSweepObject2DMakeGroups
1689 //=======================================================================
1691 SMESH::ListOfGroups*
1692 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1693 const SMESH::DirStruct& theStepVector,
1694 CORBA::Long theNbOfSteps)
1696 if ( !myPreviewMode ) {
1697 TPythonDump() << "stepVector = " << theStepVector;
1698 TPythonDump() << this << ".ExtrusionSweepObject2DMakeGroups( "
1699 << theObject << ", stepVector, " << theNbOfSteps << " )";
1701 SMESH::long_array_var anElementsId = theObject->GetIDs();
1702 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1706 //=======================================================================
1707 //function : advancedExtrusion
1709 //=======================================================================
1711 SMESH::ListOfGroups*
1712 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1713 const SMESH::DirStruct & theStepVector,
1714 CORBA::Long theNbOfSteps,
1715 CORBA::Long theExtrFlags,
1716 CORBA::Double theSewTolerance,
1717 const bool theMakeGroups)
1721 TIDSortedElemSet elements;
1722 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1724 const SMESH::PointStruct * P = &theStepVector.PS;
1725 gp_Vec stepVec( P->x, P->y, P->z );
1727 ::SMESH_MeshEditor anEditor( myMesh );
1728 TElemOfElemListMap aHystory;
1729 ::SMESH_MeshEditor::PGroupIDs groupIds =
1730 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1731 theMakeGroups, theExtrFlags, theSewTolerance);
1732 storeResult(anEditor);
1734 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1737 //=======================================================================
1738 //function : AdvancedExtrusion
1740 //=======================================================================
1742 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1743 const SMESH::DirStruct & theStepVector,
1744 CORBA::Long theNbOfSteps,
1745 CORBA::Long theExtrFlags,
1746 CORBA::Double theSewTolerance)
1748 if ( !myPreviewMode ) {
1749 TPythonDump() << "stepVector = " << theStepVector;
1750 TPythonDump() << this << ".AdvancedExtrusion("
1753 << theNbOfSteps << ","
1754 << theExtrFlags << ", "
1755 << theSewTolerance << " )";
1757 advancedExtrusion( theIDsOfElements,
1765 //=======================================================================
1766 //function : AdvancedExtrusionMakeGroups
1768 //=======================================================================
1770 SMESH::ListOfGroups*
1771 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1772 const SMESH::DirStruct& theStepVector,
1773 CORBA::Long theNbOfSteps,
1774 CORBA::Long theExtrFlags,
1775 CORBA::Double theSewTolerance)
1777 if ( !myPreviewMode ) {
1778 TPythonDump() << "stepVector = " << theStepVector;
1779 TPythonDump() << this << ".AdvancedExtrusionMakeGroups("
1782 << theNbOfSteps << ","
1783 << theExtrFlags << ", "
1784 << theSewTolerance << " )";
1786 return advancedExtrusion( theIDsOfElements,
1795 //================================================================================
1797 * \brief Convert extrusion error to IDL enum
1799 //================================================================================
1801 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1803 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1807 RETCASE( EXTR_NO_ELEMENTS );
1808 RETCASE( EXTR_PATH_NOT_EDGE );
1809 RETCASE( EXTR_BAD_PATH_SHAPE );
1810 RETCASE( EXTR_BAD_STARTING_NODE );
1811 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1812 RETCASE( EXTR_CANT_GET_TANGENT );
1814 return SMESH::SMESH_MeshEditor::EXTR_OK;
1818 //=======================================================================
1819 //function : extrusionAlongPath
1821 //=======================================================================
1823 SMESH::ListOfGroups*
1824 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1825 SMESH::SMESH_Mesh_ptr thePathMesh,
1826 GEOM::GEOM_Object_ptr thePathShape,
1827 CORBA::Long theNodeStart,
1828 CORBA::Boolean theHasAngles,
1829 const SMESH::double_array & theAngles,
1830 CORBA::Boolean theHasRefPoint,
1831 const SMESH::PointStruct & theRefPoint,
1832 const bool theMakeGroups,
1833 SMESH::SMESH_MeshEditor::Extrusion_Error & theError)
1837 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1838 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1841 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1843 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1844 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1846 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
1847 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1851 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1853 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1857 TIDSortedElemSet elements;
1858 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1860 list<double> angles;
1861 for (int i = 0; i < theAngles.length(); i++) {
1862 angles.push_back( theAngles[i] );
1865 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1867 int nbOldGroups = myMesh->NbGroup();
1869 ::SMESH_MeshEditor anEditor( myMesh );
1870 ::SMESH_MeshEditor::Extrusion_Error error =
1871 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1872 theHasAngles, angles,
1873 theHasRefPoint, refPnt, theMakeGroups );
1874 storeResult(anEditor);
1875 theError = convExtrError( error );
1877 if ( theMakeGroups ) {
1878 list<int> groupIDs = myMesh->GetGroupIds();
1879 list<int>::iterator newBegin = groupIDs.begin();
1880 std::advance( newBegin, nbOldGroups ); // skip old groups
1881 groupIDs.erase( groupIDs.begin(), newBegin );
1882 return getGroups( & groupIDs );
1887 //=======================================================================
1888 //function : ExtrusionAlongPath
1890 //=======================================================================
1892 SMESH::SMESH_MeshEditor::Extrusion_Error
1893 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1894 SMESH::SMESH_Mesh_ptr thePathMesh,
1895 GEOM::GEOM_Object_ptr thePathShape,
1896 CORBA::Long theNodeStart,
1897 CORBA::Boolean theHasAngles,
1898 const SMESH::double_array & theAngles,
1899 CORBA::Boolean theHasRefPoint,
1900 const SMESH::PointStruct & theRefPoint)
1902 if ( !myPreviewMode ) {
1903 TPythonDump() << "rotAngles = " << theAngles;
1905 if ( theHasRefPoint )
1906 TPythonDump() << "refPoint = SMESH.PointStruct( "
1907 << theRefPoint.x << ", "
1908 << theRefPoint.y << ", "
1909 << theRefPoint.z << " )";
1911 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1913 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
1914 << theIDsOfElements << ", "
1915 << thePathMesh << ", "
1916 << thePathShape << ", "
1917 << theNodeStart << ", "
1918 << theHasAngles << ", "
1919 << "rotAngles" << ", "
1920 << theHasRefPoint << ", refPoint )";
1922 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1923 extrusionAlongPath( theIDsOfElements,
1936 //=======================================================================
1937 //function : ExtrusionAlongPathObject
1939 //=======================================================================
1941 SMESH::SMESH_MeshEditor::Extrusion_Error
1942 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
1943 SMESH::SMESH_Mesh_ptr thePathMesh,
1944 GEOM::GEOM_Object_ptr thePathShape,
1945 CORBA::Long theNodeStart,
1946 CORBA::Boolean theHasAngles,
1947 const SMESH::double_array & theAngles,
1948 CORBA::Boolean theHasRefPoint,
1949 const SMESH::PointStruct & theRefPoint)
1951 if ( !myPreviewMode ) {
1952 TPythonDump() << "rotAngles = " << theAngles;
1954 if ( theHasRefPoint )
1955 TPythonDump() << "refPoint = SMESH.PointStruct( "
1956 << theRefPoint.x << ", "
1957 << theRefPoint.y << ", "
1958 << theRefPoint.z << " )";
1960 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1962 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
1963 << theObject << ", "
1964 << thePathMesh << ", "
1965 << thePathShape << ", "
1966 << theNodeStart << ", "
1967 << theHasAngles << ", "
1968 << "rotAngles" << ", "
1969 << theHasRefPoint << ", refPoint )";
1971 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1972 SMESH::long_array_var anElementsId = theObject->GetIDs();
1973 extrusionAlongPath( anElementsId,
1987 //=======================================================================
1988 //function : ExtrusionAlongPathMakeGroups
1990 //=======================================================================
1992 SMESH::ListOfGroups*
1993 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
1994 SMESH::SMESH_Mesh_ptr thePathMesh,
1995 GEOM::GEOM_Object_ptr thePathShape,
1996 CORBA::Long theNodeStart,
1997 CORBA::Boolean theHasAngles,
1998 const SMESH::double_array& theAngles,
1999 CORBA::Boolean theHasRefPoint,
2000 const SMESH::PointStruct& theRefPoint,
2001 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2003 if ( !myPreviewMode ) {
2004 TPythonDump() << "rotAngles = " << theAngles;
2006 if ( theHasRefPoint )
2007 TPythonDump() << "refPoint = SMESH.PointStruct( "
2008 << theRefPoint.x << ", "
2009 << theRefPoint.y << ", "
2010 << theRefPoint.z << " )";
2012 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2014 TPythonDump() << "groups = " << this << ".ExtrusionAlongPathMakeGroups( "
2015 << theIDsOfElements << ", "
2016 << thePathMesh << ", "
2017 << thePathShape << ", "
2018 << theNodeStart << ", "
2019 << theHasAngles << ", "
2020 << "rotAngles" << ", "
2021 << theHasRefPoint << ", refPoint )";
2023 return extrusionAlongPath( theIDsOfElements,
2035 //=======================================================================
2036 //function : ExtrusionAlongPathObjectMakeGroups
2038 //=======================================================================
2040 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2041 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2042 SMESH::SMESH_Mesh_ptr thePathMesh,
2043 GEOM::GEOM_Object_ptr thePathShape,
2044 CORBA::Long theNodeStart,
2045 CORBA::Boolean theHasAngles,
2046 const SMESH::double_array& theAngles,
2047 CORBA::Boolean theHasRefPoint,
2048 const SMESH::PointStruct& theRefPoint,
2049 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2051 if ( !myPreviewMode ) {
2052 TPythonDump() << "rotAngles = " << theAngles;
2054 if ( theHasRefPoint )
2055 TPythonDump() << "refPoint = SMESH.PointStruct( "
2056 << theRefPoint.x << ", "
2057 << theRefPoint.y << ", "
2058 << theRefPoint.z << " )";
2060 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2062 TPythonDump() << "groups = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2063 << theObject << ", "
2064 << thePathMesh << ", "
2065 << thePathShape << ", "
2066 << theNodeStart << ", "
2067 << theHasAngles << ", "
2068 << "rotAngles" << ", "
2069 << theHasRefPoint << ", refPoint )";
2071 SMESH::long_array_var anElementsId = theObject->GetIDs();
2072 return extrusionAlongPath( anElementsId,
2084 //================================================================================
2086 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2087 * of given angles along path steps
2088 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2089 * which proceeds the extrusion
2090 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2091 * is used to define the sub-mesh for the path
2093 //================================================================================
2095 SMESH::double_array*
2096 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2097 GEOM::GEOM_Object_ptr thePathShape,
2098 const SMESH::double_array & theAngles)
2100 SMESH::double_array_var aResult = new SMESH::double_array();
2101 return aResult._retn();
2105 //=======================================================================
2108 //=======================================================================
2110 SMESH::ListOfGroups*
2111 SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
2112 const SMESH::AxisStruct & theAxis,
2113 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2114 CORBA::Boolean theCopy,
2115 const bool theMakeGroups)
2119 TIDSortedElemSet elements;
2120 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2122 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2123 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2126 switch ( theMirrorType ) {
2127 case SMESH::SMESH_MeshEditor::POINT:
2128 aTrsf.SetMirror( P );
2130 case SMESH::SMESH_MeshEditor::AXIS:
2131 aTrsf.SetMirror( gp_Ax1( P, V ));
2134 aTrsf.SetMirror( gp_Ax2( P, V ));
2137 ::SMESH_MeshEditor anEditor( myMesh );
2138 ::SMESH_MeshEditor::PGroupIDs groupIds =
2139 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups);
2142 storeResult(anEditor);
2144 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2147 //=======================================================================
2150 //=======================================================================
2152 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2153 const SMESH::AxisStruct & theAxis,
2154 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2155 CORBA::Boolean theCopy)
2157 if ( !myPreviewMode ) {
2158 TPythonDump() << this << ".Mirror( "
2159 << theIDsOfElements << ", "
2161 << mirrorTypeName(theMirrorType) << ", "
2164 mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2168 //=======================================================================
2169 //function : MirrorObject
2171 //=======================================================================
2173 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2174 const SMESH::AxisStruct & theAxis,
2175 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2176 CORBA::Boolean theCopy)
2178 if ( !myPreviewMode ) {
2179 TPythonDump() << this << ".MirrorObject( "
2180 << theObject << ", "
2182 << mirrorTypeName(theMirrorType) << ", "
2185 SMESH::long_array_var anElementsId = theObject->GetIDs();
2186 mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2189 //=======================================================================
2190 //function : MirrorMakeGroups
2192 //=======================================================================
2194 SMESH::ListOfGroups*
2195 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2196 const SMESH::AxisStruct& theMirror,
2197 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2199 if ( !myPreviewMode ) {
2200 TPythonDump() << this << ".MirrorMakeGroups( "
2201 << theIDsOfElements << ", "
2202 << theMirror << ", "
2203 << mirrorTypeName(theMirrorType) << " )";
2205 return mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2208 //=======================================================================
2209 //function : MirrorObjectMakeGroups
2211 //=======================================================================
2213 SMESH::ListOfGroups*
2214 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2215 const SMESH::AxisStruct& theMirror,
2216 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2218 if ( !myPreviewMode ) {
2219 TPythonDump() << this << ".MirrorObjectMakeGroups( "
2220 << theObject << ", "
2221 << theMirror << ", "
2222 << mirrorTypeName(theMirrorType) << " )";
2224 SMESH::long_array_var anElementsId = theObject->GetIDs();
2225 return mirror(anElementsId, theMirror, theMirrorType, true, true);
2229 //=======================================================================
2230 //function : translate
2232 //=======================================================================
2234 SMESH::ListOfGroups*
2235 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2236 const SMESH::DirStruct & theVector,
2237 CORBA::Boolean theCopy,
2238 const bool theMakeGroups)
2242 TIDSortedElemSet elements;
2243 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2246 const SMESH::PointStruct * P = &theVector.PS;
2247 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2249 ::SMESH_MeshEditor anEditor( myMesh );
2250 ::SMESH_MeshEditor::PGroupIDs groupIds =
2251 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups);
2254 storeResult(anEditor);
2256 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2259 //=======================================================================
2260 //function : Translate
2262 //=======================================================================
2264 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2265 const SMESH::DirStruct & theVector,
2266 CORBA::Boolean theCopy)
2268 if ( !myPreviewMode ) {
2269 TPythonDump() << "vector = " << theVector;
2270 TPythonDump() << this << ".Translate( "
2275 translate(theIDsOfElements,
2281 //=======================================================================
2282 //function : TranslateObject
2284 //=======================================================================
2286 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
2287 const SMESH::DirStruct & theVector,
2288 CORBA::Boolean theCopy)
2290 if ( !myPreviewMode ) {
2291 TPythonDump() << this << ".TranslateObject( "
2296 SMESH::long_array_var anElementsId = theObject->GetIDs();
2297 translate(anElementsId,
2303 //=======================================================================
2304 //function : TranslateMakeGroups
2306 //=======================================================================
2308 SMESH::ListOfGroups*
2309 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
2310 const SMESH::DirStruct& theVector)
2312 if ( !myPreviewMode ) {
2313 TPythonDump() << "vector = " << theVector;
2314 TPythonDump() << this << ".TranslateMakeGroups( "
2318 return translate(theIDsOfElements,theVector,true,true);
2321 //=======================================================================
2322 //function : TranslateObjectMakeGroups
2324 //=======================================================================
2326 SMESH::ListOfGroups*
2327 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2328 const SMESH::DirStruct& theVector)
2330 if ( !myPreviewMode ) {
2331 TPythonDump() << this << ".TranslateObjectMakeGroups( "
2335 SMESH::long_array_var anElementsId = theObject->GetIDs();
2336 return translate(anElementsId, theVector, true, true);
2339 //=======================================================================
2342 //=======================================================================
2344 SMESH::ListOfGroups*
2345 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
2346 const SMESH::AxisStruct & theAxis,
2347 CORBA::Double theAngle,
2348 CORBA::Boolean theCopy,
2349 const bool theMakeGroups)
2353 TIDSortedElemSet elements;
2354 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2356 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2357 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2360 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
2362 ::SMESH_MeshEditor anEditor( myMesh );
2363 ::SMESH_MeshEditor::PGroupIDs groupIds =
2364 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups);
2367 storeResult(anEditor);
2369 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2372 //=======================================================================
2375 //=======================================================================
2377 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
2378 const SMESH::AxisStruct & theAxis,
2379 CORBA::Double theAngle,
2380 CORBA::Boolean theCopy)
2382 if ( !myPreviewMode ) {
2383 TPythonDump() << "axis = " << theAxis;
2384 TPythonDump() << this << ".Rotate( "
2390 rotate(theIDsOfElements,
2397 //=======================================================================
2398 //function : RotateObject
2400 //=======================================================================
2402 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
2403 const SMESH::AxisStruct & theAxis,
2404 CORBA::Double theAngle,
2405 CORBA::Boolean theCopy)
2407 if ( !myPreviewMode ) {
2408 TPythonDump() << "axis = " << theAxis;
2409 TPythonDump() << this << ".RotateObject( "
2415 SMESH::long_array_var anElementsId = theObject->GetIDs();
2416 rotate(anElementsId,
2423 //=======================================================================
2424 //function : RotateMakeGroups
2426 //=======================================================================
2428 SMESH::ListOfGroups*
2429 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
2430 const SMESH::AxisStruct& theAxis,
2431 CORBA::Double theAngle)
2433 if ( !myPreviewMode ) {
2434 TPythonDump() << "axis = " << theAxis;
2435 TPythonDump() << this << ".RotateMakeGroups( "
2438 << theAngle << " )";
2440 return rotate(theIDsOfElements,theAxis,theAngle,true,true);
2443 //=======================================================================
2444 //function : RotateObjectMakeGroups
2446 //=======================================================================
2448 SMESH::ListOfGroups*
2449 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2450 const SMESH::AxisStruct& theAxis,
2451 CORBA::Double theAngle)
2453 if ( !myPreviewMode ) {
2454 TPythonDump() << "axis = " << theAxis;
2455 TPythonDump() << this << ".RotateObjectMakeGroups( "
2458 << theAngle << " )";
2460 SMESH::long_array_var anElementsId = theObject->GetIDs();
2461 return rotate(anElementsId,theAxis,theAngle,true,true);
2464 //=======================================================================
2465 //function : FindCoincidentNodes
2467 //=======================================================================
2469 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
2470 SMESH::array_of_long_array_out GroupsOfNodes)
2474 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2475 ::SMESH_MeshEditor anEditor( myMesh );
2476 set<const SMDS_MeshNode*> nodes; // no input nodes
2477 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2479 GroupsOfNodes = new SMESH::array_of_long_array;
2480 GroupsOfNodes->length( aListOfListOfNodes.size() );
2481 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2482 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2483 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2484 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2485 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2486 aGroup.length( aListOfNodes.size() );
2487 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2488 aGroup[ j ] = (*lIt)->GetID();
2490 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
2491 << Tolerance << " )";
2494 //=======================================================================
2495 //function : FindCoincidentNodesOnPart
2497 //=======================================================================
2498 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
2499 CORBA::Double Tolerance,
2500 SMESH::array_of_long_array_out GroupsOfNodes)
2503 SMESH::long_array_var aElementsId = theObject->GetIDs();
2505 SMESHDS_Mesh* aMesh = GetMeshDS();
2506 set<const SMDS_MeshNode*> nodes;
2508 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2509 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
2510 for(int i = 0; i < aElementsId->length(); i++) {
2511 CORBA::Long ind = aElementsId[i];
2512 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
2518 for(int i = 0; i < aElementsId->length(); i++) {
2519 CORBA::Long ind = aElementsId[i];
2520 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
2522 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
2523 while ( nIt->more() )
2524 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
2530 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2531 ::SMESH_MeshEditor anEditor( myMesh );
2533 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2535 GroupsOfNodes = new SMESH::array_of_long_array;
2536 GroupsOfNodes->length( aListOfListOfNodes.size() );
2537 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2538 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2539 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2540 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2541 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2542 aGroup.length( aListOfNodes.size() );
2543 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2544 aGroup[ j ] = (*lIt)->GetID();
2546 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
2548 << Tolerance << " )";
2551 //=======================================================================
2552 //function : MergeNodes
2554 //=======================================================================
2556 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
2560 SMESHDS_Mesh* aMesh = GetMeshDS();
2562 TPythonDump aTPythonDump;
2563 aTPythonDump << this << ".MergeNodes([";
2564 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2565 for (int i = 0; i < GroupsOfNodes.length(); i++)
2567 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
2568 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
2569 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
2570 for ( int j = 0; j < aNodeGroup.length(); j++ )
2572 CORBA::Long index = aNodeGroup[ j ];
2573 const SMDS_MeshNode * node = aMesh->FindNode(index);
2575 aListOfNodes.push_back( node );
2577 if ( aListOfNodes.size() < 2 )
2578 aListOfListOfNodes.pop_back();
2580 if ( i > 0 ) aTPythonDump << ", ";
2581 aTPythonDump << aNodeGroup;
2583 ::SMESH_MeshEditor anEditor( myMesh );
2584 anEditor.MergeNodes( aListOfListOfNodes );
2586 aTPythonDump << "])";
2589 //=======================================================================
2590 //function : FindEqualElements
2592 //=======================================================================
2593 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
2594 SMESH::array_of_long_array_out GroupsOfElementsID)
2597 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2598 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
2599 typedef list<int> TListOfIDs;
2600 set<const SMDS_MeshElement*> elems;
2601 SMESH::long_array_var aElementsId = theObject->GetIDs();
2602 SMESHDS_Mesh* aMesh = GetMeshDS();
2604 for(int i = 0; i < aElementsId->length(); i++) {
2605 CORBA::Long anID = aElementsId[i];
2606 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
2612 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2613 ::SMESH_MeshEditor anEditor( myMesh );
2614 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
2616 GroupsOfElementsID = new SMESH::array_of_long_array;
2617 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
2619 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
2620 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
2621 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
2622 TListOfIDs& listOfIDs = *arraysIt;
2623 aGroup.length( listOfIDs.size() );
2624 TListOfIDs::iterator idIt = listOfIDs.begin();
2625 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
2626 aGroup[ k ] = *idIt;
2630 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
2635 //=======================================================================
2636 //function : MergeElements
2638 //=======================================================================
2640 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
2644 TPythonDump aTPythonDump;
2645 aTPythonDump << this << ".MergeElements( [";
2647 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2649 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
2650 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
2651 aListOfListOfElementsID.push_back( list< int >() );
2652 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
2653 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
2654 CORBA::Long id = anElemsIDGroup[ j ];
2655 aListOfElemsID.push_back( id );
2657 if ( aListOfElemsID.size() < 2 )
2658 aListOfListOfElementsID.pop_back();
2659 if ( i > 0 ) aTPythonDump << ", ";
2660 aTPythonDump << anElemsIDGroup;
2663 ::SMESH_MeshEditor anEditor( myMesh );
2664 anEditor.MergeElements(aListOfListOfElementsID);
2666 aTPythonDump << "] )";
2669 //=======================================================================
2670 //function : MergeEqualElements
2672 //=======================================================================
2674 void SMESH_MeshEditor_i::MergeEqualElements()
2678 ::SMESH_MeshEditor anEditor( myMesh );
2679 anEditor.MergeEqualElements();
2681 TPythonDump() << this << ".MergeEqualElements()";
2684 //================================================================================
2686 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
2687 * move the node closest to the point to point's location and return ID of the node
2689 //================================================================================
2691 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
2694 CORBA::Long theNodeID)
2696 // We keep myNodeSearcher until any mesh modification:
2697 // 1) initData() deletes myNodeSearcher at any edition,
2698 // 2) TNodeSearcherDeleter - at any mesh compute event and mesh change
2702 int nodeID = theNodeID;
2703 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
2706 static TNodeSearcherDeleter deleter;
2707 deleter.Set( myMesh );
2708 if ( !myNodeSearcher ) {
2709 ::SMESH_MeshEditor anEditor( myMesh );
2710 myNodeSearcher = anEditor.GetNodeSearcher();
2713 node = myNodeSearcher->FindClosestTo( p );
2716 nodeID = node->GetID();
2717 if ( myPreviewMode ) // make preview data
2719 // in a preview mesh, make edges linked to a node
2720 TPreviewMesh tmpMesh;
2721 TIDSortedElemSet linkedNodes;
2722 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
2723 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
2724 for ( ; nIt != linkedNodes.end(); ++nIt )
2726 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
2727 tmpMesh.Copy( &edge );
2730 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
2732 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
2733 // fill preview data
2734 ::SMESH_MeshEditor anEditor( & tmpMesh );
2735 storeResult( anEditor );
2739 GetMeshDS()->MoveNode(node, x, y, z);
2743 if ( !myPreviewMode ) {
2744 TPythonDump() << "nodeID = " << this
2745 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z << " )";
2751 //=======================================================================
2752 //function : convError
2754 //=======================================================================
2756 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2758 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
2762 RETCASE( SEW_BORDER1_NOT_FOUND );
2763 RETCASE( SEW_BORDER2_NOT_FOUND );
2764 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
2765 RETCASE( SEW_BAD_SIDE_NODES );
2766 RETCASE( SEW_VOLUMES_TO_SPLIT );
2767 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
2768 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
2769 RETCASE( SEW_BAD_SIDE1_NODES );
2770 RETCASE( SEW_BAD_SIDE2_NODES );
2772 return SMESH::SMESH_MeshEditor::SEW_OK;
2775 //=======================================================================
2776 //function : SewFreeBorders
2778 //=======================================================================
2780 SMESH::SMESH_MeshEditor::Sew_Error
2781 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
2782 CORBA::Long SecondNodeID1,
2783 CORBA::Long LastNodeID1,
2784 CORBA::Long FirstNodeID2,
2785 CORBA::Long SecondNodeID2,
2786 CORBA::Long LastNodeID2,
2787 CORBA::Boolean CreatePolygons,
2788 CORBA::Boolean CreatePolyedrs)
2792 SMESHDS_Mesh* aMesh = GetMeshDS();
2794 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
2795 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
2796 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
2797 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
2798 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
2799 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
2801 if (!aBorderFirstNode ||
2802 !aBorderSecondNode||
2804 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
2805 if (!aSide2FirstNode ||
2806 !aSide2SecondNode ||
2808 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
2810 TPythonDump() << "error = " << this << ".SewFreeBorders( "
2811 << FirstNodeID1 << ", "
2812 << SecondNodeID1 << ", "
2813 << LastNodeID1 << ", "
2814 << FirstNodeID2 << ", "
2815 << SecondNodeID2 << ", "
2816 << LastNodeID2 << ", "
2817 << CreatePolygons<< ", "
2818 << CreatePolyedrs<< " )";
2820 ::SMESH_MeshEditor anEditor( myMesh );
2821 SMESH::SMESH_MeshEditor::Sew_Error error =
2822 convError( anEditor.SewFreeBorder (aBorderFirstNode,
2832 storeResult(anEditor);
2838 //=======================================================================
2839 //function : SewConformFreeBorders
2841 //=======================================================================
2843 SMESH::SMESH_MeshEditor::Sew_Error
2844 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
2845 CORBA::Long SecondNodeID1,
2846 CORBA::Long LastNodeID1,
2847 CORBA::Long FirstNodeID2,
2848 CORBA::Long SecondNodeID2)
2852 SMESHDS_Mesh* aMesh = GetMeshDS();
2854 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
2855 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
2856 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
2857 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
2858 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
2859 const SMDS_MeshNode* aSide2ThirdNode = 0;
2861 if (!aBorderFirstNode ||
2862 !aBorderSecondNode||
2864 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
2865 if (!aSide2FirstNode ||
2867 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
2869 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
2870 << FirstNodeID1 << ", "
2871 << SecondNodeID1 << ", "
2872 << LastNodeID1 << ", "
2873 << FirstNodeID2 << ", "
2874 << SecondNodeID2 << " )";
2876 ::SMESH_MeshEditor anEditor( myMesh );
2877 SMESH::SMESH_MeshEditor::Sew_Error error =
2878 convError( anEditor.SewFreeBorder (aBorderFirstNode,
2887 storeResult(anEditor);
2893 //=======================================================================
2894 //function : SewBorderToSide
2896 //=======================================================================
2898 SMESH::SMESH_MeshEditor::Sew_Error
2899 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
2900 CORBA::Long SecondNodeIDOnFreeBorder,
2901 CORBA::Long LastNodeIDOnFreeBorder,
2902 CORBA::Long FirstNodeIDOnSide,
2903 CORBA::Long LastNodeIDOnSide,
2904 CORBA::Boolean CreatePolygons,
2905 CORBA::Boolean CreatePolyedrs)
2909 SMESHDS_Mesh* aMesh = GetMeshDS();
2911 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
2912 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
2913 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
2914 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
2915 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
2916 const SMDS_MeshNode* aSide2ThirdNode = 0;
2918 if (!aBorderFirstNode ||
2919 !aBorderSecondNode||
2921 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
2922 if (!aSide2FirstNode ||
2924 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
2926 TPythonDump() << "error = " << this << ".SewBorderToSide( "
2927 << FirstNodeIDOnFreeBorder << ", "
2928 << SecondNodeIDOnFreeBorder << ", "
2929 << LastNodeIDOnFreeBorder << ", "
2930 << FirstNodeIDOnSide << ", "
2931 << LastNodeIDOnSide << ", "
2932 << CreatePolygons << ", "
2933 << CreatePolyedrs << ") ";
2935 ::SMESH_MeshEditor anEditor( myMesh );
2936 SMESH::SMESH_MeshEditor::Sew_Error error =
2937 convError( anEditor.SewFreeBorder (aBorderFirstNode,
2947 storeResult(anEditor);
2953 //=======================================================================
2954 //function : SewSideElements
2956 //=======================================================================
2958 SMESH::SMESH_MeshEditor::Sew_Error
2959 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
2960 const SMESH::long_array& IDsOfSide2Elements,
2961 CORBA::Long NodeID1OfSide1ToMerge,
2962 CORBA::Long NodeID1OfSide2ToMerge,
2963 CORBA::Long NodeID2OfSide1ToMerge,
2964 CORBA::Long NodeID2OfSide2ToMerge)
2968 SMESHDS_Mesh* aMesh = GetMeshDS();
2970 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
2971 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
2972 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
2973 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
2975 if (!aFirstNode1ToMerge ||
2976 !aFirstNode2ToMerge )
2977 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
2978 if (!aSecondNode1ToMerge||
2979 !aSecondNode2ToMerge)
2980 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
2982 TIDSortedElemSet aSide1Elems, aSide2Elems;
2983 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
2984 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
2986 TPythonDump() << "error = " << this << ".SewSideElements( "
2987 << IDsOfSide1Elements << ", "
2988 << IDsOfSide2Elements << ", "
2989 << NodeID1OfSide1ToMerge << ", "
2990 << NodeID1OfSide2ToMerge << ", "
2991 << NodeID2OfSide1ToMerge << ", "
2992 << NodeID2OfSide2ToMerge << ")";
2994 ::SMESH_MeshEditor anEditor( myMesh );
2995 SMESH::SMESH_MeshEditor::Sew_Error error =
2996 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
2999 aSecondNode1ToMerge,
3000 aSecondNode2ToMerge));
3002 storeResult(anEditor);
3007 //================================================================================
3009 * \brief Set new nodes for given element
3010 * \param ide - element id
3011 * \param newIDs - new node ids
3012 * \retval CORBA::Boolean - true if result is OK
3014 //================================================================================
3016 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
3017 const SMESH::long_array& newIDs)
3021 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
3022 if(!elem) return false;
3024 int nbn = newIDs.length();
3026 vector<const SMDS_MeshNode*> aNodes(nbn);
3029 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
3032 aNodes[nbn1] = aNode;
3035 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
3036 << ide << ", " << newIDs << " )";
3038 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
3041 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
3044 //================================================================================
3046 * \brief Update myLastCreated* or myPreviewData
3047 * \param anEditor - it contains last modification results
3049 //================================================================================
3051 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
3053 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
3055 list<int> aNodesConnectivity;
3056 typedef map<int, int> TNodesMap;
3059 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
3060 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
3062 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
3063 int nbEdges = aMeshDS->NbEdges();
3064 int nbFaces = aMeshDS->NbFaces();
3065 int nbVolum = aMeshDS->NbVolumes();
3066 switch ( previewType ) {
3067 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
3068 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
3069 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
3072 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
3073 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
3075 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
3077 while ( itMeshElems->more() ) {
3078 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
3079 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
3082 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
3083 while ( itElemNodes->more() ) {
3084 const SMDS_MeshNode* aMeshNode =
3085 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
3086 int aNodeID = aMeshNode->GetID();
3087 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
3088 if ( anIter == nodesMap.end() ) {
3089 // filling the nodes coordinates
3090 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
3091 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
3092 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
3093 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
3096 aNodesConnectivity.push_back(anIter->second);
3099 // filling the elements types
3100 SMDSAbs_ElementType aType;
3102 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
3103 aType = SMDSAbs_Node;
3107 aType = aMeshElem->GetType();
3108 isPoly = aMeshElem->IsPoly();
3111 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
3112 myPreviewData->elementTypes[i].isPoly = isPoly;
3113 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
3117 myPreviewData->nodesXYZ.length( j );
3119 // filling the elements connectivities
3120 list<int>::iterator aConnIter = aNodesConnectivity.begin();
3121 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
3122 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
3123 myPreviewData->elementConnectivities[i] = *aConnIter;
3129 // add new nodes into myLastCreatedNodes
3130 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
3131 myLastCreatedNodes->length(aSeq.Length());
3132 for(int i=0; i<aSeq.Length(); i++)
3133 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
3136 // add new elements into myLastCreatedElems
3137 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
3138 myLastCreatedElems->length(aSeq.Length());
3139 for(int i=0; i<aSeq.Length(); i++)
3140 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
3144 //================================================================================
3146 * Return data of mesh edition preview
3148 //================================================================================
3150 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
3152 return myPreviewData._retn();
3155 //================================================================================
3157 * \brief Returns list of it's IDs of created nodes
3158 * \retval SMESH::long_array* - list of node ID
3160 //================================================================================
3162 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
3164 return myLastCreatedNodes._retn();
3167 //================================================================================
3169 * \brief Returns list of it's IDs of created elements
3170 * \retval SMESH::long_array* - list of elements' ID
3172 //================================================================================
3174 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
3176 return myLastCreatedElems._retn();
3179 //=======================================================================
3180 //function : ConvertToQuadratic
3182 //=======================================================================
3184 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
3186 ::SMESH_MeshEditor anEditor( myMesh );
3187 anEditor.ConvertToQuadratic(theForce3d);
3188 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
3191 //=======================================================================
3192 //function : ConvertFromQuadratic
3194 //=======================================================================
3196 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
3198 ::SMESH_MeshEditor anEditor( myMesh );
3199 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
3200 TPythonDump() << this << ".ConvertFromQuadratic()";