1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_MeshEditor_i.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESH_MeshEditor_i.hxx"
31 #include "SMDS_MeshEdge.hxx"
32 #include "SMDS_MeshFace.hxx"
33 #include "SMDS_MeshVolume.hxx"
34 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
35 #include "SMESH_MeshEditor.hxx"
36 #include "SMESH_subMeshEventListener.hxx"
37 #include "SMESH_Gen_i.hxx"
38 #include "SMESH_Filter_i.hxx"
39 #include "SMESH_PythonDump.hxx"
41 #include "utilities.h"
42 #include "Utils_ExceptHandlers.hxx"
43 #include "Utils_CorbaException.hxx"
45 #include <BRepAdaptor_Surface.hxx>
46 #include <BRep_Tool.hxx>
47 #include <TopExp_Explorer.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Face.hxx>
55 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
59 #include <Standard_Failure.hxx>
62 #include <Standard_ErrorHandler.hxx>
67 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
70 using SMESH::TPythonDump;
74 //=============================================================================
76 * \brief Mesh to apply modifications for preview purposes
78 //=============================================================================
80 struct TPreviewMesh: public SMESH_Mesh
82 SMDSAbs_ElementType myPreviewType; // type to show
84 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
85 _isShapeToMesh = _id =_studyId =_idDoc = 0;
86 _myMeshDS = new SMESHDS_Mesh( _id, true );
87 myPreviewType = previewElements;
90 virtual ~TPreviewMesh() { delete _myMeshDS; }
91 //!< Copy a set of elements
92 void Copy(const TIDSortedElemSet & theElements,
93 TIDSortedElemSet& theCopyElements,
94 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
95 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
97 // loop on theIDsOfElements
98 TIDSortedElemSet::const_iterator eIt = theElements.begin();
99 for ( ; eIt != theElements.end(); ++eIt )
101 const SMDS_MeshElement* anElem = *eIt;
102 if ( !anElem ) continue;
103 SMDSAbs_ElementType type = anElem->GetType();
104 if ( type == theAvoidType ||
105 ( theSelectType != SMDSAbs_All && type != theSelectType ))
108 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
109 theCopyElements.insert( theCopyElements.end(), anElemCopy );
113 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
115 // copy element nodes
116 int anElemNbNodes = anElem->NbNodes();
117 vector< int > anElemNodesID( anElemNbNodes ) ;
118 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
119 for ( int i = 0; itElemNodes->more(); i++)
121 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
123 anElemNodesID[i] = anElemNode->GetID();
126 // creates a corresponding element on copied nodes
127 SMDS_MeshElement* anElemCopy = 0;
128 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
130 const SMDS_PolyhedralVolumeOfNodes* ph =
131 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
133 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
134 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
137 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
144 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
146 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
147 anElemNode->GetID());
149 };// struct TPreviewMesh
151 static SMESH_NodeSearcher * myNodeSearcher = 0;
153 //=============================================================================
155 * \brief Deleter of myNodeSearcher at any compute event occured
157 //=============================================================================
159 struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
163 TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
165 //!< Delete myNodeSearcher
168 if ( myNodeSearcher ) { delete myNodeSearcher; myNodeSearcher = 0; }
170 typedef map < int, SMESH_subMesh * > TDependsOnMap;
171 //!< The meshod called by submesh: do my main job
172 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
173 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
175 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
177 Unset( sm->GetFather() );
180 //!< set self on all submeshes and delete myNodeSearcher if other mesh is set
181 void Set(SMESH_Mesh* mesh)
183 if ( myMesh && myMesh != mesh ) {
188 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
189 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
190 TDependsOnMap::const_iterator sm;
191 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
192 sm->second->SetEventListener( this, 0, sm->second );
195 //!< delete self from all submeshes
196 void Unset(SMESH_Mesh* mesh)
198 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
199 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
200 TDependsOnMap::const_iterator sm;
201 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
202 sm->second->DeleteEventListener( this );
207 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
209 TCollection_AsciiString typeStr;
210 switch ( theMirrorType ) {
211 case SMESH::SMESH_MeshEditor::POINT:
212 typeStr = "SMESH.SMESH_MeshEditor.POINT";
214 case SMESH::SMESH_MeshEditor::AXIS:
215 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
218 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
224 //=============================================================================
228 //=============================================================================
230 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
233 myMesh = & theMesh->GetImpl();
234 myPreviewMode = isPreview;
237 //================================================================================
241 //================================================================================
243 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
247 //================================================================================
249 * \brief Clear members
251 //================================================================================
253 void SMESH_MeshEditor_i::initData()
255 if ( myPreviewMode ) {
256 myPreviewData = new SMESH::MeshPreviewStruct();
259 myLastCreatedElems = new SMESH::long_array();
260 myLastCreatedNodes = new SMESH::long_array();
261 TNodeSearcherDeleter::Delete();
265 //=============================================================================
269 //=============================================================================
272 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
276 ::SMESH_MeshEditor anEditor( myMesh );
279 for (int i = 0; i < IDsOfElements.length(); i++)
280 IdList.push_back( IDsOfElements[i] );
282 // Update Python script
283 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
285 TPythonDump() << "print 'RemoveElements: ', isDone";
288 return anEditor.Remove( IdList, false );
291 //=============================================================================
295 //=============================================================================
297 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
301 ::SMESH_MeshEditor anEditor( myMesh );
303 for (int i = 0; i < IDsOfNodes.length(); i++)
304 IdList.push_back( IDsOfNodes[i] );
306 // Update Python script
307 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
309 TPythonDump() << "print 'RemoveNodes: ', isDone";
312 return anEditor.Remove( IdList, true );
315 //=============================================================================
319 //=============================================================================
321 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
325 int NbNodes = IDsOfNodes.length();
326 SMDS_MeshElement* elem = 0;
329 CORBA::Long index1 = IDsOfNodes[0];
330 CORBA::Long index2 = IDsOfNodes[1];
331 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
333 // Update Python script
334 TPythonDump() << "edge = " << this << ".AddEdge([ "
335 << index1 << ", " << index2 <<" ])";
338 CORBA::Long n1 = IDsOfNodes[0];
339 CORBA::Long n2 = IDsOfNodes[1];
340 CORBA::Long n12 = IDsOfNodes[2];
341 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
342 GetMeshDS()->FindNode(n2),
343 GetMeshDS()->FindNode(n12));
344 // Update Python script
345 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
346 <<n1<<", "<<n2<<", "<<n12<<" ])";
350 return elem->GetID();
355 //=============================================================================
359 //=============================================================================
361 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
362 CORBA::Double y, CORBA::Double z)
366 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
368 // Update Python script
369 TPythonDump() << "nodeID = " << this << ".AddNode( "
370 << x << ", " << y << ", " << z << " )";
375 //=============================================================================
379 //=============================================================================
381 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
385 int NbNodes = IDsOfNodes.length();
391 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
392 for (int i = 0; i < NbNodes; i++)
393 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
395 SMDS_MeshElement* elem = 0;
397 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
399 else if (NbNodes == 4) {
400 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
402 else if (NbNodes == 6) {
403 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
406 else if (NbNodes == 8) {
407 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
408 nodes[4], nodes[5], nodes[6], nodes[7]);
411 // Update Python script
412 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
415 return elem->GetID();
420 //=============================================================================
424 //=============================================================================
425 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
426 (const SMESH::long_array & IDsOfNodes)
430 int NbNodes = IDsOfNodes.length();
431 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
432 for (int i = 0; i < NbNodes; i++)
433 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
435 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
437 // Update Python script
438 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
440 TPythonDump() << "print 'AddPolygonalFace: ', faceID";
444 return elem->GetID();
449 //=============================================================================
453 //=============================================================================
455 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
459 int NbNodes = IDsOfNodes.length();
460 vector< const SMDS_MeshNode*> n(NbNodes);
461 for(int i=0;i<NbNodes;i++)
462 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
464 SMDS_MeshElement* elem = 0;
467 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
468 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
469 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
470 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
471 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
472 n[6],n[7],n[8],n[9]);
474 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
475 n[7],n[8],n[9],n[10],n[11],n[12]);
477 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
478 n[9],n[10],n[11],n[12],n[13],n[14]);
480 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
481 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
482 n[15],n[16],n[17],n[18],n[19]);
486 // Update Python script
487 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
489 TPythonDump() << "print 'AddVolume: ', volID";
493 return elem->GetID();
498 //=============================================================================
500 * AddPolyhedralVolume
502 //=============================================================================
503 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume
504 (const SMESH::long_array & IDsOfNodes,
505 const SMESH::long_array & Quantities)
509 int NbNodes = IDsOfNodes.length();
510 std::vector<const SMDS_MeshNode*> n (NbNodes);
511 for (int i = 0; i < NbNodes; i++)
512 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
514 int NbFaces = Quantities.length();
515 std::vector<int> q (NbFaces);
516 for (int j = 0; j < NbFaces; j++)
517 q[j] = Quantities[j];
519 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
521 // Update Python script
522 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
523 << IDsOfNodes << ", " << Quantities << " )";
525 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
529 return elem->GetID();
534 //=============================================================================
536 * AddPolyhedralVolumeByFaces
538 //=============================================================================
539 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
540 (const SMESH::long_array & IdsOfFaces)
544 int NbFaces = IdsOfFaces.length();
545 std::vector<const SMDS_MeshNode*> poly_nodes;
546 std::vector<int> quantities (NbFaces);
548 for (int i = 0; i < NbFaces; i++) {
549 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
550 quantities[i] = aFace->NbNodes();
552 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
554 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
558 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
560 // Update Python script
561 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
562 << IdsOfFaces << " )";
564 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
568 return elem->GetID();
573 //=============================================================================
575 * \brief Bind a node to a vertex
576 * \param NodeID - node ID
577 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
578 * \retval boolean - false if NodeID or VertexID is invalid
580 //=============================================================================
582 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
583 throw (SALOME::SALOME_Exception)
585 Unexpect aCatch(SALOME_SalomeException);
587 SMESHDS_Mesh * mesh = GetMeshDS();
588 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
590 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
592 if ( mesh->MaxShapeIndex() < VertexID )
593 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
595 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
596 if ( shape.ShapeType() != TopAbs_VERTEX )
597 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
599 mesh->SetNodeOnVertex( node, VertexID );
602 //=============================================================================
604 * \brief Store node position on an edge
605 * \param NodeID - node ID
606 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
607 * \param paramOnEdge - parameter on edge where the node is located
608 * \retval boolean - false if any parameter is invalid
610 //=============================================================================
612 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
613 CORBA::Double paramOnEdge)
614 throw (SALOME::SALOME_Exception)
616 Unexpect aCatch(SALOME_SalomeException);
618 SMESHDS_Mesh * mesh = GetMeshDS();
619 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
621 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
623 if ( mesh->MaxShapeIndex() < EdgeID )
624 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
626 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
627 if ( shape.ShapeType() != TopAbs_EDGE )
628 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
631 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
632 if ( paramOnEdge < f || paramOnEdge > l )
633 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
635 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
638 //=============================================================================
640 * \brief Store node position on a face
641 * \param NodeID - node ID
642 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
643 * \param u - U parameter on face where the node is located
644 * \param v - V parameter on face where the node is located
645 * \retval boolean - false if any parameter is invalid
647 //=============================================================================
649 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
650 CORBA::Double u, CORBA::Double v)
651 throw (SALOME::SALOME_Exception)
653 Unexpect aCatch(SALOME_SalomeException);
655 SMESHDS_Mesh * mesh = GetMeshDS();
656 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
658 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
660 if ( mesh->MaxShapeIndex() < FaceID )
661 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
663 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
664 if ( shape.ShapeType() != TopAbs_FACE )
665 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
667 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
668 bool isOut = ( u < surf.FirstUParameter() ||
669 u > surf.LastUParameter() ||
670 v < surf.FirstVParameter() ||
671 v > surf.LastVParameter() );
675 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
676 << " u( " << surf.FirstUParameter()
677 << "," << surf.LastUParameter()
678 << ") v( " << surf.FirstVParameter()
679 << "," << surf.LastVParameter() << ")" );
681 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
684 mesh->SetNodeOnFace( node, FaceID, u, v );
687 //=============================================================================
689 * \brief Bind a node to a solid
690 * \param NodeID - node ID
691 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
692 * \retval boolean - false if NodeID or SolidID is invalid
694 //=============================================================================
696 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
697 throw (SALOME::SALOME_Exception)
699 Unexpect aCatch(SALOME_SalomeException);
701 SMESHDS_Mesh * mesh = GetMeshDS();
702 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
704 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
706 if ( mesh->MaxShapeIndex() < SolidID )
707 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
709 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
710 if ( shape.ShapeType() != TopAbs_SOLID &&
711 shape.ShapeType() != TopAbs_SHELL)
712 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
714 mesh->SetNodeInVolume( node, SolidID );
717 //=============================================================================
719 * \brief Bind an element to a shape
720 * \param ElementID - element ID
721 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
722 * \retval boolean - false if ElementID or ShapeID is invalid
724 //=============================================================================
726 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
728 throw (SALOME::SALOME_Exception)
730 Unexpect aCatch(SALOME_SalomeException);
732 SMESHDS_Mesh * mesh = GetMeshDS();
733 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
735 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
737 if ( mesh->MaxShapeIndex() < ShapeID )
738 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
740 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
741 if ( shape.ShapeType() != TopAbs_EDGE &&
742 shape.ShapeType() != TopAbs_FACE &&
743 shape.ShapeType() != TopAbs_SOLID &&
744 shape.ShapeType() != TopAbs_SHELL )
745 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
747 mesh->SetMeshElementOnShape( elem, ShapeID );
751 //=============================================================================
755 //=============================================================================
757 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
764 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
768 GetMeshDS()->MoveNode(node, x, y, z);
770 // Update Python script
771 TPythonDump() << "isDone = " << this << ".MoveNode( "
772 << NodeID << ", " << x << ", " << y << ", " << z << " )";
777 //=============================================================================
781 //=============================================================================
783 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
788 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
789 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
793 // Update Python script
794 TPythonDump() << "isDone = " << this << ".InverseDiag( "
795 << NodeID1 << ", " << NodeID2 << " )";
797 ::SMESH_MeshEditor aMeshEditor( myMesh );
798 return aMeshEditor.InverseDiag ( n1, n2 );
801 //=============================================================================
805 //=============================================================================
807 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
812 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
813 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
817 // Update Python script
818 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
819 << NodeID1 << ", " << NodeID2 << " )";
821 ::SMESH_MeshEditor aMeshEditor( myMesh );
823 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
825 storeResult(aMeshEditor);
830 //=============================================================================
834 //=============================================================================
836 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
840 ::SMESH_MeshEditor anEditor( myMesh );
841 for (int i = 0; i < IDsOfElements.length(); i++)
843 CORBA::Long index = IDsOfElements[i];
844 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
846 anEditor.Reorient( elem );
848 // Update Python script
849 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
855 //=============================================================================
859 //=============================================================================
861 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
865 SMESH::long_array_var anElementsId = theObject->GetIDs();
866 CORBA::Boolean isDone = Reorient(anElementsId);
868 // Clear python line, created by Reorient()
869 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
870 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
872 // Update Python script
873 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
880 //================================================================================
882 * \brief function for conversion long_array to TIDSortedElemSet
883 * \param IDs - array of IDs
884 * \param aMesh - mesh
885 * \param aMap - collection to fill
886 * \param aType - element type
888 //================================================================================
890 void arrayToSet(const SMESH::long_array & IDs,
891 const SMESHDS_Mesh* aMesh,
892 TIDSortedElemSet& aMap,
893 const SMDSAbs_ElementType aType = SMDSAbs_All )
895 for (int i=0; i<IDs.length(); i++) {
896 CORBA::Long ind = IDs[i];
897 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
898 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
904 //=============================================================================
908 //=============================================================================
909 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
910 SMESH::NumericalFunctor_ptr Criterion,
911 CORBA::Double MaxAngle)
915 SMESHDS_Mesh* aMesh = GetMeshDS();
916 TIDSortedElemSet faces;
917 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
919 SMESH::NumericalFunctor_i* aNumericalFunctor =
920 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
921 SMESH::Controls::NumericalFunctorPtr aCrit;
922 if ( !aNumericalFunctor )
923 aCrit.reset( new SMESH::Controls::AspectRatio() );
925 aCrit = aNumericalFunctor->GetNumericalFunctor();
927 // Update Python script
928 TPythonDump() << "isDone = " << this << ".TriToQuad( "
929 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
931 TPythonDump() << "print 'TriToQuad: ', isDone";
934 ::SMESH_MeshEditor anEditor( myMesh );
936 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
938 storeResult(anEditor);
944 //=============================================================================
948 //=============================================================================
949 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
950 SMESH::NumericalFunctor_ptr Criterion,
951 CORBA::Double MaxAngle)
955 SMESH::long_array_var anElementsId = theObject->GetIDs();
956 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
958 // Clear python line(s), created by TriToQuad()
959 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
960 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
962 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
965 SMESH::NumericalFunctor_i* aNumericalFunctor =
966 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
968 // Update Python script
969 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
970 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
972 TPythonDump() << "print 'TriToQuadObject: ', isDone";
979 //=============================================================================
983 //=============================================================================
984 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
985 SMESH::NumericalFunctor_ptr Criterion)
989 SMESHDS_Mesh* aMesh = GetMeshDS();
990 TIDSortedElemSet faces;
991 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
993 SMESH::NumericalFunctor_i* aNumericalFunctor =
994 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
995 SMESH::Controls::NumericalFunctorPtr aCrit;
996 if ( !aNumericalFunctor )
997 aCrit.reset( new SMESH::Controls::AspectRatio() );
999 aCrit = aNumericalFunctor->GetNumericalFunctor();
1002 // Update Python script
1003 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1005 TPythonDump() << "print 'QuadToTri: ', isDone";
1008 ::SMESH_MeshEditor anEditor( myMesh );
1009 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1011 storeResult(anEditor);
1017 //=============================================================================
1021 //=============================================================================
1022 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1023 SMESH::NumericalFunctor_ptr Criterion)
1027 SMESH::long_array_var anElementsId = theObject->GetIDs();
1028 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1030 // Clear python line(s), created by QuadToTri()
1031 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1032 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1034 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1037 SMESH::NumericalFunctor_i* aNumericalFunctor =
1038 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1040 // Update Python script
1041 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1043 TPythonDump() << "print 'QuadToTriObject: ', isDone";
1050 //=============================================================================
1054 //=============================================================================
1055 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1056 CORBA::Boolean Diag13)
1060 SMESHDS_Mesh* aMesh = GetMeshDS();
1061 TIDSortedElemSet faces;
1062 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1064 // Update Python script
1065 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1066 << IDsOfElements << ", " << Diag13 << " )";
1068 TPythonDump() << "print 'SplitQuad: ', isDone";
1071 ::SMESH_MeshEditor anEditor( myMesh );
1072 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1074 storeResult(anEditor);
1080 //=============================================================================
1084 //=============================================================================
1085 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1086 CORBA::Boolean Diag13)
1090 SMESH::long_array_var anElementsId = theObject->GetIDs();
1091 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1093 // Clear python line(s), created by SplitQuad()
1094 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1095 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1097 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1100 // Update Python script
1101 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1102 << theObject << ", " << Diag13 << " )";
1104 TPythonDump() << "print 'SplitQuadObject: ', isDone";
1111 //=============================================================================
1115 //=============================================================================
1116 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1117 SMESH::NumericalFunctor_ptr Criterion)
1119 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1120 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1122 SMESH::NumericalFunctor_i* aNumericalFunctor =
1123 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1124 SMESH::Controls::NumericalFunctorPtr aCrit;
1125 if (aNumericalFunctor)
1126 aCrit = aNumericalFunctor->GetNumericalFunctor();
1128 aCrit.reset(new SMESH::Controls::AspectRatio());
1130 ::SMESH_MeshEditor anEditor (myMesh);
1131 return anEditor.BestSplit(quad, aCrit);
1137 //=======================================================================
1140 //=======================================================================
1143 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1144 const SMESH::long_array & IDsOfFixedNodes,
1145 CORBA::Long MaxNbOfIterations,
1146 CORBA::Double MaxAspectRatio,
1147 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1149 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1150 MaxAspectRatio, Method, false );
1154 //=======================================================================
1155 //function : SmoothParametric
1157 //=======================================================================
1160 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1161 const SMESH::long_array & IDsOfFixedNodes,
1162 CORBA::Long MaxNbOfIterations,
1163 CORBA::Double MaxAspectRatio,
1164 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1166 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1167 MaxAspectRatio, Method, true );
1171 //=======================================================================
1172 //function : SmoothObject
1174 //=======================================================================
1177 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1178 const SMESH::long_array & IDsOfFixedNodes,
1179 CORBA::Long MaxNbOfIterations,
1180 CORBA::Double MaxAspectRatio,
1181 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1183 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1184 MaxAspectRatio, Method, false);
1188 //=======================================================================
1189 //function : SmoothParametricObject
1191 //=======================================================================
1194 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1195 const SMESH::long_array & IDsOfFixedNodes,
1196 CORBA::Long MaxNbOfIterations,
1197 CORBA::Double MaxAspectRatio,
1198 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1200 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1201 MaxAspectRatio, Method, true);
1205 //=============================================================================
1209 //=============================================================================
1212 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1213 const SMESH::long_array & IDsOfFixedNodes,
1214 CORBA::Long MaxNbOfIterations,
1215 CORBA::Double MaxAspectRatio,
1216 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1221 SMESHDS_Mesh* aMesh = GetMeshDS();
1223 TIDSortedElemSet elements;
1224 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1226 set<const SMDS_MeshNode*> fixedNodes;
1227 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1228 CORBA::Long index = IDsOfFixedNodes[i];
1229 const SMDS_MeshNode * node = aMesh->FindNode(index);
1231 fixedNodes.insert( node );
1233 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1234 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1235 method = ::SMESH_MeshEditor::CENTROIDAL;
1237 ::SMESH_MeshEditor anEditor( myMesh );
1238 anEditor.Smooth(elements, fixedNodes, method,
1239 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1241 storeResult(anEditor);
1243 // Update Python script
1244 TPythonDump() << "isDone = " << this << "."
1245 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1246 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1247 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1248 << "SMESH.SMESH_MeshEditor."
1249 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1250 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1252 TPythonDump() << "print 'Smooth: ', isDone";
1259 //=============================================================================
1263 //=============================================================================
1266 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1267 const SMESH::long_array & IDsOfFixedNodes,
1268 CORBA::Long MaxNbOfIterations,
1269 CORBA::Double MaxAspectRatio,
1270 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1275 SMESH::long_array_var anElementsId = theObject->GetIDs();
1276 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1277 MaxAspectRatio, Method, IsParametric);
1279 // Clear python line(s), created by Smooth()
1280 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1281 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1283 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1286 // Update Python script
1287 TPythonDump() << "isDone = " << this << "."
1288 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1289 << theObject << ", " << IDsOfFixedNodes << ", "
1290 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1291 << "SMESH.SMESH_MeshEditor."
1292 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1293 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1295 TPythonDump() << "print 'SmoothObject: ', isDone";
1302 //=============================================================================
1306 //=============================================================================
1308 void SMESH_MeshEditor_i::RenumberNodes()
1310 // Update Python script
1311 TPythonDump() << this << ".RenumberNodes()";
1313 GetMeshDS()->Renumber( true );
1317 //=============================================================================
1321 //=============================================================================
1323 void SMESH_MeshEditor_i::RenumberElements()
1325 // Update Python script
1326 TPythonDump() << this << ".RenumberElements()";
1328 GetMeshDS()->Renumber( false );
1331 //=======================================================================
1333 * \brief Return groups by their IDs
1335 //=======================================================================
1337 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1341 myMesh_i->CreateGroupServants();
1342 return myMesh_i->GetGroups( *groupIDs );
1345 //=======================================================================
1346 //function : rotationSweep
1348 //=======================================================================
1350 SMESH::ListOfGroups*
1351 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1352 const SMESH::AxisStruct & theAxis,
1353 CORBA::Double theAngleInRadians,
1354 CORBA::Long theNbOfSteps,
1355 CORBA::Double theTolerance,
1356 const bool theMakeGroups)
1360 TIDSortedElemSet inElements, copyElements;
1361 arrayToSet(theIDsOfElements, GetMeshDS(), inElements);
1363 TIDSortedElemSet* workElements = & inElements;
1364 TPreviewMesh tmpMesh( SMDSAbs_Face );
1365 SMESH_Mesh* mesh = 0;
1366 bool makeWalls=true;
1367 if ( myPreviewMode )
1369 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1370 tmpMesh.Copy( inElements, copyElements, select, avoid );
1372 workElements = & copyElements;
1373 //makeWalls = false;
1380 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1381 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1383 ::SMESH_MeshEditor anEditor( mesh );
1384 ::SMESH_MeshEditor::PGroupIDs groupIds =
1385 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1386 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1387 storeResult(anEditor);
1389 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1392 //=======================================================================
1393 //function : RotationSweep
1395 //=======================================================================
1397 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1398 const SMESH::AxisStruct & theAxis,
1399 CORBA::Double theAngleInRadians,
1400 CORBA::Long theNbOfSteps,
1401 CORBA::Double theTolerance)
1403 if ( !myPreviewMode ) {
1404 TPythonDump() << "axis = " << theAxis;
1405 TPythonDump() << this << ".RotationSweep( "
1408 << theAngleInRadians << ", "
1409 << theNbOfSteps << ", "
1410 << theTolerance << " )";
1412 rotationSweep(theIDsOfElements,
1420 //=======================================================================
1421 //function : RotationSweepMakeGroups
1423 //=======================================================================
1425 SMESH::ListOfGroups*
1426 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1427 const SMESH::AxisStruct& theAxis,
1428 CORBA::Double theAngleInRadians,
1429 CORBA::Long theNbOfSteps,
1430 CORBA::Double theTolerance)
1432 if ( !myPreviewMode ) {
1433 TPythonDump() << "axis = " << theAxis;
1434 TPythonDump() << this << ".RotationSweepMakeGroups( "
1437 << theAngleInRadians << ", "
1438 << theNbOfSteps << ", "
1439 << theTolerance << " )";
1441 return rotationSweep(theIDsOfElements,
1449 //=======================================================================
1450 //function : RotationSweepObject
1452 //=======================================================================
1454 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1455 const SMESH::AxisStruct & theAxis,
1456 CORBA::Double theAngleInRadians,
1457 CORBA::Long theNbOfSteps,
1458 CORBA::Double theTolerance)
1460 if ( !myPreviewMode ) {
1461 TPythonDump() << "axis = " << theAxis;
1462 TPythonDump() << this << ".RotationSweepObject( "
1465 << theAngleInRadians << ", "
1466 << theNbOfSteps << ", "
1467 << theTolerance << " )";
1469 SMESH::long_array_var anElementsId = theObject->GetIDs();
1470 rotationSweep(anElementsId,
1478 //=======================================================================
1479 //function : RotationSweepObjectMakeGroups
1481 //=======================================================================
1483 SMESH::ListOfGroups*
1484 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1485 const SMESH::AxisStruct& theAxis,
1486 CORBA::Double theAngleInRadians,
1487 CORBA::Long theNbOfSteps,
1488 CORBA::Double theTolerance)
1490 if ( !myPreviewMode ) {
1491 TPythonDump() << "axis = " << theAxis;
1492 TPythonDump() << this << ".RotationSweepObjectMakeGroups( "
1495 << theAngleInRadians << ", "
1496 << theNbOfSteps << ", "
1497 << theTolerance << " )";
1499 SMESH::long_array_var anElementsId = theObject->GetIDs();
1500 return rotationSweep(anElementsId,
1509 //=======================================================================
1510 //function : extrusionSweep
1512 //=======================================================================
1514 SMESH::ListOfGroups*
1515 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1516 const SMESH::DirStruct & theStepVector,
1517 CORBA::Long theNbOfSteps,
1518 const bool theMakeGroups,
1519 const SMDSAbs_ElementType theElementType)
1527 TIDSortedElemSet elements;
1528 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1530 const SMESH::PointStruct * P = &theStepVector.PS;
1531 gp_Vec stepVec( P->x, P->y, P->z );
1533 TElemOfElemListMap aHystory;
1534 ::SMESH_MeshEditor anEditor( myMesh );
1535 ::SMESH_MeshEditor::PGroupIDs groupIds =
1536 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1538 storeResult(anEditor);
1540 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1542 } catch(Standard_Failure) {
1543 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1544 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1549 //=======================================================================
1550 //function : ExtrusionSweep
1552 //=======================================================================
1554 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1555 const SMESH::DirStruct & theStepVector,
1556 CORBA::Long theNbOfSteps)
1558 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1559 if ( !myPreviewMode ) {
1560 TPythonDump() << "stepVector = " << theStepVector;
1561 TPythonDump() << this << ".ExtrusionSweep( "
1562 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1567 //=======================================================================
1568 //function : ExtrusionSweepObject
1570 //=======================================================================
1572 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1573 const SMESH::DirStruct & theStepVector,
1574 CORBA::Long theNbOfSteps)
1576 SMESH::long_array_var anElementsId = theObject->GetIDs();
1577 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1578 if ( !myPreviewMode ) {
1579 TPythonDump() << "stepVector = " << theStepVector;
1580 TPythonDump() << this << ".ExtrusionSweepObject( "
1581 << theObject << ", stepVector, " << theNbOfSteps << " )";
1585 //=======================================================================
1586 //function : ExtrusionSweepObject1D
1588 //=======================================================================
1590 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1591 const SMESH::DirStruct & theStepVector,
1592 CORBA::Long theNbOfSteps)
1594 SMESH::long_array_var anElementsId = theObject->GetIDs();
1595 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1596 if ( !myPreviewMode ) {
1597 TPythonDump() << "stepVector = " << theStepVector;
1598 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1599 << theObject << ", stepVector, " << theNbOfSteps << " )";
1603 //=======================================================================
1604 //function : ExtrusionSweepObject2D
1606 //=======================================================================
1608 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1609 const SMESH::DirStruct & theStepVector,
1610 CORBA::Long theNbOfSteps)
1612 SMESH::long_array_var anElementsId = theObject->GetIDs();
1613 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1614 if ( !myPreviewMode ) {
1615 TPythonDump() << "stepVector = " << theStepVector;
1616 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1617 << theObject << ", stepVector, " << theNbOfSteps << " )";
1621 //=======================================================================
1622 //function : ExtrusionSweepMakeGroups
1624 //=======================================================================
1626 SMESH::ListOfGroups*
1627 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1628 const SMESH::DirStruct& theStepVector,
1629 CORBA::Long theNbOfSteps)
1631 if ( !myPreviewMode ) {
1632 TPythonDump() << "stepVector = " << theStepVector;
1633 TPythonDump() << this << ".ExtrusionSweepMakeGroups( "
1634 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1636 return extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1638 //=======================================================================
1639 //function : ExtrusionSweepObjectMakeGroups
1641 //=======================================================================
1643 SMESH::ListOfGroups*
1644 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1645 const SMESH::DirStruct& theStepVector,
1646 CORBA::Long theNbOfSteps)
1648 if ( !myPreviewMode ) {
1649 TPythonDump() << "stepVector = " << theStepVector;
1650 TPythonDump() << this << ".ExtrusionSweepObjectMakeGroups( "
1651 << theObject << ", stepVector, " << theNbOfSteps << " )";
1653 SMESH::long_array_var anElementsId = theObject->GetIDs();
1654 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1657 //=======================================================================
1658 //function : ExtrusionSweepObject1DMakeGroups
1660 //=======================================================================
1662 SMESH::ListOfGroups*
1663 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1664 const SMESH::DirStruct& theStepVector,
1665 CORBA::Long theNbOfSteps)
1667 if ( !myPreviewMode ) {
1668 TPythonDump() << "stepVector = " << theStepVector;
1669 TPythonDump() << this << ".ExtrusionSweepObject1DMakeGroups( "
1670 << theObject << ", stepVector, " << theNbOfSteps << " )";
1672 SMESH::long_array_var anElementsId = theObject->GetIDs();
1673 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1676 //=======================================================================
1677 //function : ExtrusionSweepObject2DMakeGroups
1679 //=======================================================================
1681 SMESH::ListOfGroups*
1682 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1683 const SMESH::DirStruct& theStepVector,
1684 CORBA::Long theNbOfSteps)
1686 if ( !myPreviewMode ) {
1687 TPythonDump() << "stepVector = " << theStepVector;
1688 TPythonDump() << this << ".ExtrusionSweepObject2DMakeGroups( "
1689 << theObject << ", stepVector, " << theNbOfSteps << " )";
1691 SMESH::long_array_var anElementsId = theObject->GetIDs();
1692 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1696 //=======================================================================
1697 //function : advancedExtrusion
1699 //=======================================================================
1701 SMESH::ListOfGroups*
1702 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1703 const SMESH::DirStruct & theStepVector,
1704 CORBA::Long theNbOfSteps,
1705 CORBA::Long theExtrFlags,
1706 CORBA::Double theSewTolerance,
1707 const bool theMakeGroups)
1711 TIDSortedElemSet elements;
1712 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1714 const SMESH::PointStruct * P = &theStepVector.PS;
1715 gp_Vec stepVec( P->x, P->y, P->z );
1717 ::SMESH_MeshEditor anEditor( myMesh );
1718 TElemOfElemListMap aHystory;
1719 ::SMESH_MeshEditor::PGroupIDs groupIds =
1720 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1721 theMakeGroups, theExtrFlags, theSewTolerance);
1722 storeResult(anEditor);
1724 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1727 //=======================================================================
1728 //function : AdvancedExtrusion
1730 //=======================================================================
1732 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1733 const SMESH::DirStruct & theStepVector,
1734 CORBA::Long theNbOfSteps,
1735 CORBA::Long theExtrFlags,
1736 CORBA::Double theSewTolerance)
1738 if ( !myPreviewMode ) {
1739 TPythonDump() << "stepVector = " << theStepVector;
1740 TPythonDump() << this << ".AdvancedExtrusion("
1743 << theNbOfSteps << ","
1744 << theExtrFlags << ", "
1745 << theSewTolerance << " )";
1747 advancedExtrusion( theIDsOfElements,
1755 //=======================================================================
1756 //function : AdvancedExtrusionMakeGroups
1758 //=======================================================================
1760 SMESH::ListOfGroups*
1761 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1762 const SMESH::DirStruct& theStepVector,
1763 CORBA::Long theNbOfSteps,
1764 CORBA::Long theExtrFlags,
1765 CORBA::Double theSewTolerance)
1767 if ( !myPreviewMode ) {
1768 TPythonDump() << "stepVector = " << theStepVector;
1769 TPythonDump() << this << ".AdvancedExtrusionMakeGroups("
1772 << theNbOfSteps << ","
1773 << theExtrFlags << ", "
1774 << theSewTolerance << " )";
1776 return advancedExtrusion( theIDsOfElements,
1785 //================================================================================
1787 * \brief Convert extrusion error to IDL enum
1789 //================================================================================
1791 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1793 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1797 RETCASE( EXTR_NO_ELEMENTS );
1798 RETCASE( EXTR_PATH_NOT_EDGE );
1799 RETCASE( EXTR_BAD_PATH_SHAPE );
1800 RETCASE( EXTR_BAD_STARTING_NODE );
1801 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1802 RETCASE( EXTR_CANT_GET_TANGENT );
1804 return SMESH::SMESH_MeshEditor::EXTR_OK;
1808 //=======================================================================
1809 //function : extrusionAlongPath
1811 //=======================================================================
1813 SMESH::ListOfGroups*
1814 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1815 SMESH::SMESH_Mesh_ptr thePathMesh,
1816 GEOM::GEOM_Object_ptr thePathShape,
1817 CORBA::Long theNodeStart,
1818 CORBA::Boolean theHasAngles,
1819 const SMESH::double_array & theAngles,
1820 CORBA::Boolean theHasRefPoint,
1821 const SMESH::PointStruct & theRefPoint,
1822 const bool theMakeGroups,
1823 SMESH::SMESH_MeshEditor::Extrusion_Error & theError)
1827 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1828 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1831 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1833 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1834 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1836 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
1837 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1841 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1843 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1847 TIDSortedElemSet elements;
1848 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1850 list<double> angles;
1851 for (int i = 0; i < theAngles.length(); i++) {
1852 angles.push_back( theAngles[i] );
1855 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1857 int nbOldGroups = myMesh->NbGroup();
1859 ::SMESH_MeshEditor anEditor( myMesh );
1860 ::SMESH_MeshEditor::Extrusion_Error error =
1861 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1862 theHasAngles, angles,
1863 theHasRefPoint, refPnt, theMakeGroups );
1864 storeResult(anEditor);
1865 theError = convExtrError( error );
1867 if ( theMakeGroups ) {
1868 list<int> groupIDs = myMesh->GetGroupIds();
1869 list<int>::iterator newBegin = groupIDs.begin();
1870 std::advance( newBegin, nbOldGroups ); // skip old groups
1871 groupIDs.erase( groupIDs.begin(), newBegin );
1872 return getGroups( & groupIDs );
1877 //=======================================================================
1878 //function : ExtrusionAlongPath
1880 //=======================================================================
1882 SMESH::SMESH_MeshEditor::Extrusion_Error
1883 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1884 SMESH::SMESH_Mesh_ptr thePathMesh,
1885 GEOM::GEOM_Object_ptr thePathShape,
1886 CORBA::Long theNodeStart,
1887 CORBA::Boolean theHasAngles,
1888 const SMESH::double_array & theAngles,
1889 CORBA::Boolean theHasRefPoint,
1890 const SMESH::PointStruct & theRefPoint)
1892 if ( !myPreviewMode ) {
1893 TPythonDump() << "rotAngles = " << theAngles;
1895 if ( theHasRefPoint )
1896 TPythonDump() << "refPoint = SMESH.PointStruct( "
1897 << theRefPoint.x << ", "
1898 << theRefPoint.y << ", "
1899 << theRefPoint.z << " )";
1901 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1903 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
1904 << theIDsOfElements << ", "
1905 << thePathMesh << ", "
1906 << thePathShape << ", "
1907 << theNodeStart << ", "
1908 << theHasAngles << ", "
1909 << "rotAngles" << ", "
1910 << theHasRefPoint << ", refPoint )";
1912 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1913 extrusionAlongPath( theIDsOfElements,
1926 //=======================================================================
1927 //function : ExtrusionAlongPathObject
1929 //=======================================================================
1931 SMESH::SMESH_MeshEditor::Extrusion_Error
1932 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
1933 SMESH::SMESH_Mesh_ptr thePathMesh,
1934 GEOM::GEOM_Object_ptr thePathShape,
1935 CORBA::Long theNodeStart,
1936 CORBA::Boolean theHasAngles,
1937 const SMESH::double_array & theAngles,
1938 CORBA::Boolean theHasRefPoint,
1939 const SMESH::PointStruct & theRefPoint)
1941 if ( !myPreviewMode ) {
1942 TPythonDump() << "rotAngles = " << theAngles;
1944 if ( theHasRefPoint )
1945 TPythonDump() << "refPoint = SMESH.PointStruct( "
1946 << theRefPoint.x << ", "
1947 << theRefPoint.y << ", "
1948 << theRefPoint.z << " )";
1950 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1952 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
1953 << theObject << ", "
1954 << thePathMesh << ", "
1955 << thePathShape << ", "
1956 << theNodeStart << ", "
1957 << theHasAngles << ", "
1958 << "rotAngles" << ", "
1959 << theHasRefPoint << ", refPoint )";
1961 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1962 SMESH::long_array_var anElementsId = theObject->GetIDs();
1963 extrusionAlongPath( anElementsId,
1977 //=======================================================================
1978 //function : ExtrusionAlongPathMakeGroups
1980 //=======================================================================
1982 SMESH::ListOfGroups*
1983 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
1984 SMESH::SMESH_Mesh_ptr thePathMesh,
1985 GEOM::GEOM_Object_ptr thePathShape,
1986 CORBA::Long theNodeStart,
1987 CORBA::Boolean theHasAngles,
1988 const SMESH::double_array& theAngles,
1989 CORBA::Boolean theHasRefPoint,
1990 const SMESH::PointStruct& theRefPoint,
1991 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
1993 if ( !myPreviewMode ) {
1994 TPythonDump() << "rotAngles = " << theAngles;
1996 if ( theHasRefPoint )
1997 TPythonDump() << "refPoint = SMESH.PointStruct( "
1998 << theRefPoint.x << ", "
1999 << theRefPoint.y << ", "
2000 << theRefPoint.z << " )";
2002 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2004 TPythonDump() << "groups = " << this << ".ExtrusionAlongPathMakeGroups( "
2005 << theIDsOfElements << ", "
2006 << thePathMesh << ", "
2007 << thePathShape << ", "
2008 << theNodeStart << ", "
2009 << theHasAngles << ", "
2010 << "rotAngles" << ", "
2011 << theHasRefPoint << ", refPoint )";
2013 return extrusionAlongPath( theIDsOfElements,
2025 //=======================================================================
2026 //function : ExtrusionAlongPathObjectMakeGroups
2028 //=======================================================================
2030 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2031 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2032 SMESH::SMESH_Mesh_ptr thePathMesh,
2033 GEOM::GEOM_Object_ptr thePathShape,
2034 CORBA::Long theNodeStart,
2035 CORBA::Boolean theHasAngles,
2036 const SMESH::double_array& theAngles,
2037 CORBA::Boolean theHasRefPoint,
2038 const SMESH::PointStruct& theRefPoint,
2039 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2041 if ( !myPreviewMode ) {
2042 TPythonDump() << "rotAngles = " << theAngles;
2044 if ( theHasRefPoint )
2045 TPythonDump() << "refPoint = SMESH.PointStruct( "
2046 << theRefPoint.x << ", "
2047 << theRefPoint.y << ", "
2048 << theRefPoint.z << " )";
2050 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2052 TPythonDump() << "groups = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2053 << theObject << ", "
2054 << thePathMesh << ", "
2055 << thePathShape << ", "
2056 << theNodeStart << ", "
2057 << theHasAngles << ", "
2058 << "rotAngles" << ", "
2059 << theHasRefPoint << ", refPoint )";
2061 SMESH::long_array_var anElementsId = theObject->GetIDs();
2062 return extrusionAlongPath( anElementsId,
2074 //================================================================================
2076 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2077 * of given angles along path steps
2078 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2079 * which proceeds the extrusion
2080 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2081 * is used to define the sub-mesh for the path
2083 //================================================================================
2085 SMESH::double_array*
2086 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2087 GEOM::GEOM_Object_ptr thePathShape,
2088 const SMESH::double_array & theAngles)
2090 SMESH::double_array_var aResult = new SMESH::double_array();
2091 int nbAngles = theAngles.length();
2092 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2094 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2095 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2096 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2097 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2098 return aResult._retn();
2099 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2100 if ( nbSteps == nbAngles )
2102 aResult.inout() = theAngles;
2106 aResult->length( nbSteps );
2107 double rAn2St = double( nbAngles ) / double( nbSteps );
2108 double angPrev = 0, angle;
2109 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2111 double angCur = rAn2St * ( iSt+1 );
2112 double angCurFloor = floor( angCur );
2113 double angPrevFloor = floor( angPrev );
2114 if ( angPrevFloor == angCurFloor )
2115 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2118 int iP = int( angPrevFloor );
2119 double angPrevCeil = ceil(angPrev);
2120 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2122 int iC = int( angCurFloor );
2123 if ( iC < nbAngles )
2124 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2126 iP = int( angPrevCeil );
2128 angle += theAngles[ iC ];
2130 aResult[ iSt ] = angle;
2135 // Update Python script
2136 TPythonDump() << "rotAngles = " << theAngles;
2137 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2138 << thePathMesh << ", "
2139 << thePathShape << ", "
2142 return aResult._retn();
2146 //=======================================================================
2149 //=======================================================================
2151 SMESH::ListOfGroups*
2152 SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
2153 const SMESH::AxisStruct & theAxis,
2154 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2155 CORBA::Boolean theCopy,
2156 const bool theMakeGroups,
2157 ::SMESH_Mesh* theTargetMesh)
2161 TIDSortedElemSet elements;
2162 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2164 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2165 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2168 switch ( theMirrorType ) {
2169 case SMESH::SMESH_MeshEditor::POINT:
2170 aTrsf.SetMirror( P );
2172 case SMESH::SMESH_MeshEditor::AXIS:
2173 aTrsf.SetMirror( gp_Ax1( P, V ));
2176 aTrsf.SetMirror( gp_Ax2( P, V ));
2179 ::SMESH_MeshEditor anEditor( myMesh );
2180 ::SMESH_MeshEditor::PGroupIDs groupIds =
2181 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2184 storeResult(anEditor);
2186 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2189 //=======================================================================
2192 //=======================================================================
2194 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2195 const SMESH::AxisStruct & theAxis,
2196 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2197 CORBA::Boolean theCopy)
2199 if ( !myPreviewMode ) {
2200 TPythonDump() << this << ".Mirror( "
2201 << theIDsOfElements << ", "
2203 << mirrorTypeName(theMirrorType) << ", "
2206 mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2210 //=======================================================================
2211 //function : MirrorObject
2213 //=======================================================================
2215 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2216 const SMESH::AxisStruct & theAxis,
2217 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2218 CORBA::Boolean theCopy)
2220 if ( !myPreviewMode ) {
2221 TPythonDump() << this << ".MirrorObject( "
2222 << theObject << ", "
2224 << mirrorTypeName(theMirrorType) << ", "
2227 SMESH::long_array_var anElementsId = theObject->GetIDs();
2228 mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2231 //=======================================================================
2232 //function : MirrorMakeGroups
2234 //=======================================================================
2236 SMESH::ListOfGroups*
2237 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2238 const SMESH::AxisStruct& theMirror,
2239 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2241 if ( !myPreviewMode ) {
2242 TPythonDump() << this << ".MirrorMakeGroups( "
2243 << theIDsOfElements << ", "
2244 << theMirror << ", "
2245 << mirrorTypeName(theMirrorType) << " )";
2247 return mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2250 //=======================================================================
2251 //function : MirrorObjectMakeGroups
2253 //=======================================================================
2255 SMESH::ListOfGroups*
2256 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2257 const SMESH::AxisStruct& theMirror,
2258 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2260 if ( !myPreviewMode ) {
2261 TPythonDump() << this << ".MirrorObjectMakeGroups( "
2262 << theObject << ", "
2263 << theMirror << ", "
2264 << mirrorTypeName(theMirrorType) << " )";
2266 SMESH::long_array_var anElementsId = theObject->GetIDs();
2267 return mirror(anElementsId, theMirror, theMirrorType, true, true);
2270 //=======================================================================
2271 //function : MirrorMakeMesh
2273 //=======================================================================
2275 SMESH::SMESH_Mesh_ptr
2276 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2277 const SMESH::AxisStruct& theMirror,
2278 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2279 CORBA::Boolean theCopyGroups,
2280 const char* theMeshName)
2282 TPythonDump pydump; // to prevent dump at mesh creation
2284 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2285 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh ))
2287 mirror(theIDsOfElements, theMirror, theMirrorType,
2288 false, theCopyGroups, & mesh_i->GetImpl());
2289 mesh_i->CreateGroupServants();
2292 if ( !myPreviewMode ) {
2293 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2294 << theIDsOfElements << ", "
2295 << theMirror << ", "
2296 << mirrorTypeName(theMirrorType) << ", "
2297 << theCopyGroups << ", '"
2298 << theMeshName << "' )";
2300 return mesh._retn();
2303 //=======================================================================
2304 //function : MirrorObjectMakeMesh
2306 //=======================================================================
2308 SMESH::SMESH_Mesh_ptr
2309 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2310 const SMESH::AxisStruct& theMirror,
2311 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2312 CORBA::Boolean theCopyGroups,
2313 const char* theMeshName)
2315 TPythonDump pydump; // to prevent dump at mesh creation
2317 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2318 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh ))
2320 SMESH::long_array_var anElementsId = theObject->GetIDs();
2321 mirror(anElementsId, theMirror, theMirrorType,
2322 false, theCopyGroups, & mesh_i->GetImpl());
2323 mesh_i->CreateGroupServants();
2325 if ( !myPreviewMode ) {
2326 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
2327 << theObject << ", "
2328 << theMirror << ", "
2329 << mirrorTypeName(theMirrorType) << ", "
2330 << theCopyGroups << ", '"
2331 << theMeshName << "' )";
2333 return mesh._retn();
2336 //=======================================================================
2337 //function : translate
2339 //=======================================================================
2341 SMESH::ListOfGroups*
2342 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2343 const SMESH::DirStruct & theVector,
2344 CORBA::Boolean theCopy,
2345 const bool theMakeGroups,
2346 ::SMESH_Mesh* theTargetMesh)
2350 TIDSortedElemSet elements;
2351 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2354 const SMESH::PointStruct * P = &theVector.PS;
2355 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2357 ::SMESH_MeshEditor anEditor( myMesh );
2358 ::SMESH_MeshEditor::PGroupIDs groupIds =
2359 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2362 storeResult(anEditor);
2364 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2367 //=======================================================================
2368 //function : Translate
2370 //=======================================================================
2372 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2373 const SMESH::DirStruct & theVector,
2374 CORBA::Boolean theCopy)
2376 if ( !myPreviewMode ) {
2377 TPythonDump() << "vector = " << theVector;
2378 TPythonDump() << this << ".Translate( "
2383 translate(theIDsOfElements,
2389 //=======================================================================
2390 //function : TranslateObject
2392 //=======================================================================
2394 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
2395 const SMESH::DirStruct & theVector,
2396 CORBA::Boolean theCopy)
2398 if ( !myPreviewMode ) {
2399 TPythonDump() << this << ".TranslateObject( "
2404 SMESH::long_array_var anElementsId = theObject->GetIDs();
2405 translate(anElementsId,
2411 //=======================================================================
2412 //function : TranslateMakeGroups
2414 //=======================================================================
2416 SMESH::ListOfGroups*
2417 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
2418 const SMESH::DirStruct& theVector)
2420 if ( !myPreviewMode ) {
2421 TPythonDump() << "vector = " << theVector;
2422 TPythonDump() << this << ".TranslateMakeGroups( "
2426 return translate(theIDsOfElements,theVector,true,true);
2429 //=======================================================================
2430 //function : TranslateObjectMakeGroups
2432 //=======================================================================
2434 SMESH::ListOfGroups*
2435 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2436 const SMESH::DirStruct& theVector)
2438 if ( !myPreviewMode ) {
2439 TPythonDump() << "vector = " << theVector;
2440 TPythonDump() << this << ".TranslateObjectMakeGroups( "
2444 SMESH::long_array_var anElementsId = theObject->GetIDs();
2445 return translate(anElementsId, theVector, true, true);
2448 //=======================================================================
2449 //function : TranslateMakeMesh
2451 //=======================================================================
2453 SMESH::SMESH_Mesh_ptr
2454 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
2455 const SMESH::DirStruct& theVector,
2456 CORBA::Boolean theCopyGroups,
2457 const char* theMeshName)
2459 TPythonDump pydump; // to prevent dump at mesh creation
2460 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2462 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2463 translate(theIDsOfElements, theVector,
2464 false, theCopyGroups, & mesh_i->GetImpl());
2465 mesh_i->CreateGroupServants();
2467 if ( !myPreviewMode ) {
2468 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
2469 << theIDsOfElements << ", "
2470 << theVector << ", "
2471 << theCopyGroups << ", '"
2472 << theMeshName << "' )";
2474 return mesh._retn();
2477 //=======================================================================
2478 //function : TranslateObjectMakeMesh
2480 //=======================================================================
2482 SMESH::SMESH_Mesh_ptr
2483 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2484 const SMESH::DirStruct& theVector,
2485 CORBA::Boolean theCopyGroups,
2486 const char* theMeshName)
2488 TPythonDump pydump; // to prevent dump at mesh creation
2489 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2491 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2492 SMESH::long_array_var anElementsId = theObject->GetIDs();
2493 translate(anElementsId, theVector,
2494 false, theCopyGroups, & mesh_i->GetImpl());
2495 mesh_i->CreateGroupServants();
2497 if ( !myPreviewMode ) {
2498 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
2499 << theObject << ", "
2500 << theVector << ", "
2501 << theCopyGroups << ", '"
2502 << theMeshName << "' )";
2504 return mesh._retn();
2507 //=======================================================================
2510 //=======================================================================
2512 SMESH::ListOfGroups*
2513 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
2514 const SMESH::AxisStruct & theAxis,
2515 CORBA::Double theAngle,
2516 CORBA::Boolean theCopy,
2517 const bool theMakeGroups,
2518 ::SMESH_Mesh* theTargetMesh)
2522 TIDSortedElemSet elements;
2523 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2525 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2526 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2529 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
2531 ::SMESH_MeshEditor anEditor( myMesh );
2532 ::SMESH_MeshEditor::PGroupIDs groupIds =
2533 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2536 storeResult(anEditor);
2538 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2541 //=======================================================================
2544 //=======================================================================
2546 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
2547 const SMESH::AxisStruct & theAxis,
2548 CORBA::Double theAngle,
2549 CORBA::Boolean theCopy)
2551 if ( !myPreviewMode ) {
2552 TPythonDump() << "axis = " << theAxis;
2553 TPythonDump() << this << ".Rotate( "
2559 rotate(theIDsOfElements,
2566 //=======================================================================
2567 //function : RotateObject
2569 //=======================================================================
2571 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
2572 const SMESH::AxisStruct & theAxis,
2573 CORBA::Double theAngle,
2574 CORBA::Boolean theCopy)
2576 if ( !myPreviewMode ) {
2577 TPythonDump() << "axis = " << theAxis;
2578 TPythonDump() << this << ".RotateObject( "
2584 SMESH::long_array_var anElementsId = theObject->GetIDs();
2585 rotate(anElementsId,
2592 //=======================================================================
2593 //function : RotateMakeGroups
2595 //=======================================================================
2597 SMESH::ListOfGroups*
2598 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
2599 const SMESH::AxisStruct& theAxis,
2600 CORBA::Double theAngle)
2602 if ( !myPreviewMode ) {
2603 TPythonDump() << "axis = " << theAxis;
2604 TPythonDump() << this << ".RotateMakeGroups( "
2607 << theAngle << " )";
2609 return rotate(theIDsOfElements,theAxis,theAngle,true,true);
2612 //=======================================================================
2613 //function : RotateObjectMakeGroups
2615 //=======================================================================
2617 SMESH::ListOfGroups*
2618 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2619 const SMESH::AxisStruct& theAxis,
2620 CORBA::Double theAngle)
2622 if ( !myPreviewMode ) {
2623 TPythonDump() << "axis = " << theAxis;
2624 TPythonDump() << this << ".RotateObjectMakeGroups( "
2627 << theAngle << " )";
2629 SMESH::long_array_var anElementsId = theObject->GetIDs();
2630 return rotate(anElementsId,theAxis,theAngle,true,true);
2633 //=======================================================================
2634 //function : RotateMakeMesh
2636 //=======================================================================
2638 SMESH::SMESH_Mesh_ptr
2639 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
2640 const SMESH::AxisStruct& theAxis,
2641 CORBA::Double theAngleInRadians,
2642 CORBA::Boolean theCopyGroups,
2643 const char* theMeshName)
2645 TPythonDump pydump; // to prevent dump at mesh creation
2646 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2648 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2649 rotate(theIDsOfElements, theAxis, theAngleInRadians,
2650 false, theCopyGroups, & mesh_i->GetImpl());
2651 mesh_i->CreateGroupServants();
2653 if ( !myPreviewMode ) {
2654 pydump << mesh << " = " << this << ".RotateMakeMesh( "
2655 << theIDsOfElements << ", "
2657 << theAngleInRadians << ", "
2658 << theCopyGroups << ", '"
2659 << theMeshName << "' )";
2661 return mesh._retn();
2664 //=======================================================================
2665 //function : RotateObjectMakeMesh
2667 //=======================================================================
2669 SMESH::SMESH_Mesh_ptr
2670 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2671 const SMESH::AxisStruct& theAxis,
2672 CORBA::Double theAngleInRadians,
2673 CORBA::Boolean theCopyGroups,
2674 const char* theMeshName)
2676 TPythonDump pydump; // to prevent dump at mesh creation
2677 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2679 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2680 SMESH::long_array_var anElementsId = theObject->GetIDs();
2681 rotate(anElementsId, theAxis, theAngleInRadians,
2682 false, theCopyGroups, & mesh_i->GetImpl());
2683 mesh_i->CreateGroupServants();
2685 if ( !myPreviewMode ) {
2686 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
2687 << theObject << ", "
2689 << theAngleInRadians << ", "
2690 << theCopyGroups << ", '"
2691 << theMeshName << "' )";
2693 return mesh._retn();
2696 //=======================================================================
2697 //function : FindCoincidentNodes
2699 //=======================================================================
2701 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
2702 SMESH::array_of_long_array_out GroupsOfNodes)
2706 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2707 ::SMESH_MeshEditor anEditor( myMesh );
2708 set<const SMDS_MeshNode*> nodes; // no input nodes
2709 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2711 GroupsOfNodes = new SMESH::array_of_long_array;
2712 GroupsOfNodes->length( aListOfListOfNodes.size() );
2713 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2714 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2715 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2716 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2717 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2718 aGroup.length( aListOfNodes.size() );
2719 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2720 aGroup[ j ] = (*lIt)->GetID();
2722 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
2723 << Tolerance << " )";
2726 //=======================================================================
2727 //function : FindCoincidentNodesOnPart
2729 //=======================================================================
2730 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
2731 CORBA::Double Tolerance,
2732 SMESH::array_of_long_array_out GroupsOfNodes)
2735 SMESH::long_array_var aElementsId = theObject->GetIDs();
2737 SMESHDS_Mesh* aMesh = GetMeshDS();
2738 set<const SMDS_MeshNode*> nodes;
2740 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2741 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
2742 for(int i = 0; i < aElementsId->length(); i++) {
2743 CORBA::Long ind = aElementsId[i];
2744 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
2750 for(int i = 0; i < aElementsId->length(); i++) {
2751 CORBA::Long ind = aElementsId[i];
2752 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
2754 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
2755 while ( nIt->more() )
2756 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
2762 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2763 ::SMESH_MeshEditor anEditor( myMesh );
2765 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2767 GroupsOfNodes = new SMESH::array_of_long_array;
2768 GroupsOfNodes->length( aListOfListOfNodes.size() );
2769 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2770 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2771 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2772 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2773 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2774 aGroup.length( aListOfNodes.size() );
2775 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2776 aGroup[ j ] = (*lIt)->GetID();
2778 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
2780 << Tolerance << " )";
2783 //=======================================================================
2784 //function : MergeNodes
2786 //=======================================================================
2788 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
2792 SMESHDS_Mesh* aMesh = GetMeshDS();
2794 TPythonDump aTPythonDump;
2795 aTPythonDump << this << ".MergeNodes([";
2796 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2797 for (int i = 0; i < GroupsOfNodes.length(); i++)
2799 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
2800 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
2801 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
2802 for ( int j = 0; j < aNodeGroup.length(); j++ )
2804 CORBA::Long index = aNodeGroup[ j ];
2805 const SMDS_MeshNode * node = aMesh->FindNode(index);
2807 aListOfNodes.push_back( node );
2809 if ( aListOfNodes.size() < 2 )
2810 aListOfListOfNodes.pop_back();
2812 if ( i > 0 ) aTPythonDump << ", ";
2813 aTPythonDump << aNodeGroup;
2815 ::SMESH_MeshEditor anEditor( myMesh );
2816 anEditor.MergeNodes( aListOfListOfNodes );
2818 aTPythonDump << "])";
2821 //=======================================================================
2822 //function : FindEqualElements
2824 //=======================================================================
2825 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
2826 SMESH::array_of_long_array_out GroupsOfElementsID)
2829 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2830 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
2831 typedef list<int> TListOfIDs;
2832 set<const SMDS_MeshElement*> elems;
2833 SMESH::long_array_var aElementsId = theObject->GetIDs();
2834 SMESHDS_Mesh* aMesh = GetMeshDS();
2836 for(int i = 0; i < aElementsId->length(); i++) {
2837 CORBA::Long anID = aElementsId[i];
2838 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
2844 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2845 ::SMESH_MeshEditor anEditor( myMesh );
2846 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
2848 GroupsOfElementsID = new SMESH::array_of_long_array;
2849 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
2851 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
2852 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
2853 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
2854 TListOfIDs& listOfIDs = *arraysIt;
2855 aGroup.length( listOfIDs.size() );
2856 TListOfIDs::iterator idIt = listOfIDs.begin();
2857 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
2858 aGroup[ k ] = *idIt;
2862 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
2867 //=======================================================================
2868 //function : MergeElements
2870 //=======================================================================
2872 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
2876 TPythonDump aTPythonDump;
2877 aTPythonDump << this << ".MergeElements( [";
2879 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2881 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
2882 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
2883 aListOfListOfElementsID.push_back( list< int >() );
2884 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
2885 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
2886 CORBA::Long id = anElemsIDGroup[ j ];
2887 aListOfElemsID.push_back( id );
2889 if ( aListOfElemsID.size() < 2 )
2890 aListOfListOfElementsID.pop_back();
2891 if ( i > 0 ) aTPythonDump << ", ";
2892 aTPythonDump << anElemsIDGroup;
2895 ::SMESH_MeshEditor anEditor( myMesh );
2896 anEditor.MergeElements(aListOfListOfElementsID);
2898 aTPythonDump << "] )";
2901 //=======================================================================
2902 //function : MergeEqualElements
2904 //=======================================================================
2906 void SMESH_MeshEditor_i::MergeEqualElements()
2910 ::SMESH_MeshEditor anEditor( myMesh );
2911 anEditor.MergeEqualElements();
2913 TPythonDump() << this << ".MergeEqualElements()";
2916 //================================================================================
2918 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
2919 * move the node closest to the point to point's location and return ID of the node
2921 //================================================================================
2923 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
2926 CORBA::Long theNodeID)
2928 // We keep myNodeSearcher until any mesh modification:
2929 // 1) initData() deletes myNodeSearcher at any edition,
2930 // 2) TNodeSearcherDeleter - at any mesh compute event and mesh change
2934 int nodeID = theNodeID;
2935 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
2938 static TNodeSearcherDeleter deleter;
2939 deleter.Set( myMesh );
2940 if ( !myNodeSearcher ) {
2941 ::SMESH_MeshEditor anEditor( myMesh );
2942 myNodeSearcher = anEditor.GetNodeSearcher();
2945 node = myNodeSearcher->FindClosestTo( p );
2948 nodeID = node->GetID();
2949 if ( myPreviewMode ) // make preview data
2951 // in a preview mesh, make edges linked to a node
2952 TPreviewMesh tmpMesh;
2953 TIDSortedElemSet linkedNodes;
2954 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
2955 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
2956 for ( ; nIt != linkedNodes.end(); ++nIt )
2958 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
2959 tmpMesh.Copy( &edge );
2962 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
2964 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
2965 // fill preview data
2966 ::SMESH_MeshEditor anEditor( & tmpMesh );
2967 storeResult( anEditor );
2971 GetMeshDS()->MoveNode(node, x, y, z);
2975 if ( !myPreviewMode ) {
2976 TPythonDump() << "nodeID = " << this
2977 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
2978 << ", " << nodeID << " )";
2984 //=======================================================================
2985 //function : convError
2987 //=======================================================================
2989 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2991 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
2995 RETCASE( SEW_BORDER1_NOT_FOUND );
2996 RETCASE( SEW_BORDER2_NOT_FOUND );
2997 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
2998 RETCASE( SEW_BAD_SIDE_NODES );
2999 RETCASE( SEW_VOLUMES_TO_SPLIT );
3000 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
3001 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
3002 RETCASE( SEW_BAD_SIDE1_NODES );
3003 RETCASE( SEW_BAD_SIDE2_NODES );
3005 return SMESH::SMESH_MeshEditor::SEW_OK;
3008 //=======================================================================
3009 //function : SewFreeBorders
3011 //=======================================================================
3013 SMESH::SMESH_MeshEditor::Sew_Error
3014 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
3015 CORBA::Long SecondNodeID1,
3016 CORBA::Long LastNodeID1,
3017 CORBA::Long FirstNodeID2,
3018 CORBA::Long SecondNodeID2,
3019 CORBA::Long LastNodeID2,
3020 CORBA::Boolean CreatePolygons,
3021 CORBA::Boolean CreatePolyedrs)
3025 SMESHDS_Mesh* aMesh = GetMeshDS();
3027 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3028 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3029 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3030 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3031 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3032 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
3034 if (!aBorderFirstNode ||
3035 !aBorderSecondNode||
3037 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3038 if (!aSide2FirstNode ||
3039 !aSide2SecondNode ||
3041 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3043 TPythonDump() << "error = " << this << ".SewFreeBorders( "
3044 << FirstNodeID1 << ", "
3045 << SecondNodeID1 << ", "
3046 << LastNodeID1 << ", "
3047 << FirstNodeID2 << ", "
3048 << SecondNodeID2 << ", "
3049 << LastNodeID2 << ", "
3050 << CreatePolygons<< ", "
3051 << CreatePolyedrs<< " )";
3053 ::SMESH_MeshEditor anEditor( myMesh );
3054 SMESH::SMESH_MeshEditor::Sew_Error error =
3055 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3065 storeResult(anEditor);
3071 //=======================================================================
3072 //function : SewConformFreeBorders
3074 //=======================================================================
3076 SMESH::SMESH_MeshEditor::Sew_Error
3077 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3078 CORBA::Long SecondNodeID1,
3079 CORBA::Long LastNodeID1,
3080 CORBA::Long FirstNodeID2,
3081 CORBA::Long SecondNodeID2)
3085 SMESHDS_Mesh* aMesh = GetMeshDS();
3087 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3088 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3089 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3090 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3091 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3092 const SMDS_MeshNode* aSide2ThirdNode = 0;
3094 if (!aBorderFirstNode ||
3095 !aBorderSecondNode||
3097 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3098 if (!aSide2FirstNode ||
3100 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3102 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
3103 << FirstNodeID1 << ", "
3104 << SecondNodeID1 << ", "
3105 << LastNodeID1 << ", "
3106 << FirstNodeID2 << ", "
3107 << SecondNodeID2 << " )";
3109 ::SMESH_MeshEditor anEditor( myMesh );
3110 SMESH::SMESH_MeshEditor::Sew_Error error =
3111 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3120 storeResult(anEditor);
3126 //=======================================================================
3127 //function : SewBorderToSide
3129 //=======================================================================
3131 SMESH::SMESH_MeshEditor::Sew_Error
3132 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
3133 CORBA::Long SecondNodeIDOnFreeBorder,
3134 CORBA::Long LastNodeIDOnFreeBorder,
3135 CORBA::Long FirstNodeIDOnSide,
3136 CORBA::Long LastNodeIDOnSide,
3137 CORBA::Boolean CreatePolygons,
3138 CORBA::Boolean CreatePolyedrs)
3142 SMESHDS_Mesh* aMesh = GetMeshDS();
3144 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
3145 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
3146 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
3147 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
3148 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
3149 const SMDS_MeshNode* aSide2ThirdNode = 0;
3151 if (!aBorderFirstNode ||
3152 !aBorderSecondNode||
3154 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3155 if (!aSide2FirstNode ||
3157 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
3159 TPythonDump() << "error = " << this << ".SewBorderToSide( "
3160 << FirstNodeIDOnFreeBorder << ", "
3161 << SecondNodeIDOnFreeBorder << ", "
3162 << LastNodeIDOnFreeBorder << ", "
3163 << FirstNodeIDOnSide << ", "
3164 << LastNodeIDOnSide << ", "
3165 << CreatePolygons << ", "
3166 << CreatePolyedrs << ") ";
3168 ::SMESH_MeshEditor anEditor( myMesh );
3169 SMESH::SMESH_MeshEditor::Sew_Error error =
3170 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3180 storeResult(anEditor);
3186 //=======================================================================
3187 //function : SewSideElements
3189 //=======================================================================
3191 SMESH::SMESH_MeshEditor::Sew_Error
3192 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
3193 const SMESH::long_array& IDsOfSide2Elements,
3194 CORBA::Long NodeID1OfSide1ToMerge,
3195 CORBA::Long NodeID1OfSide2ToMerge,
3196 CORBA::Long NodeID2OfSide1ToMerge,
3197 CORBA::Long NodeID2OfSide2ToMerge)
3201 SMESHDS_Mesh* aMesh = GetMeshDS();
3203 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
3204 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
3205 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
3206 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
3208 if (!aFirstNode1ToMerge ||
3209 !aFirstNode2ToMerge )
3210 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
3211 if (!aSecondNode1ToMerge||
3212 !aSecondNode2ToMerge)
3213 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
3215 TIDSortedElemSet aSide1Elems, aSide2Elems;
3216 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
3217 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
3219 TPythonDump() << "error = " << this << ".SewSideElements( "
3220 << IDsOfSide1Elements << ", "
3221 << IDsOfSide2Elements << ", "
3222 << NodeID1OfSide1ToMerge << ", "
3223 << NodeID1OfSide2ToMerge << ", "
3224 << NodeID2OfSide1ToMerge << ", "
3225 << NodeID2OfSide2ToMerge << ")";
3227 ::SMESH_MeshEditor anEditor( myMesh );
3228 SMESH::SMESH_MeshEditor::Sew_Error error =
3229 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
3232 aSecondNode1ToMerge,
3233 aSecondNode2ToMerge));
3235 storeResult(anEditor);
3240 //================================================================================
3242 * \brief Set new nodes for given element
3243 * \param ide - element id
3244 * \param newIDs - new node ids
3245 * \retval CORBA::Boolean - true if result is OK
3247 //================================================================================
3249 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
3250 const SMESH::long_array& newIDs)
3254 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
3255 if(!elem) return false;
3257 int nbn = newIDs.length();
3259 vector<const SMDS_MeshNode*> aNodes(nbn);
3262 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
3265 aNodes[nbn1] = aNode;
3268 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
3269 << ide << ", " << newIDs << " )";
3271 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
3274 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
3277 //================================================================================
3279 * \brief Update myLastCreated* or myPreviewData
3280 * \param anEditor - it contains last modification results
3282 //================================================================================
3284 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
3286 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
3288 list<int> aNodesConnectivity;
3289 typedef map<int, int> TNodesMap;
3292 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
3293 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
3295 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
3296 int nbEdges = aMeshDS->NbEdges();
3297 int nbFaces = aMeshDS->NbFaces();
3298 int nbVolum = aMeshDS->NbVolumes();
3299 switch ( previewType ) {
3300 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
3301 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
3302 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
3305 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
3306 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
3308 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
3310 while ( itMeshElems->more() ) {
3311 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
3312 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
3315 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
3316 while ( itElemNodes->more() ) {
3317 const SMDS_MeshNode* aMeshNode =
3318 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
3319 int aNodeID = aMeshNode->GetID();
3320 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
3321 if ( anIter == nodesMap.end() ) {
3322 // filling the nodes coordinates
3323 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
3324 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
3325 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
3326 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
3329 aNodesConnectivity.push_back(anIter->second);
3332 // filling the elements types
3333 SMDSAbs_ElementType aType;
3335 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
3336 aType = SMDSAbs_Node;
3340 aType = aMeshElem->GetType();
3341 isPoly = aMeshElem->IsPoly();
3344 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
3345 myPreviewData->elementTypes[i].isPoly = isPoly;
3346 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
3350 myPreviewData->nodesXYZ.length( j );
3352 // filling the elements connectivities
3353 list<int>::iterator aConnIter = aNodesConnectivity.begin();
3354 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
3355 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
3356 myPreviewData->elementConnectivities[i] = *aConnIter;
3362 // add new nodes into myLastCreatedNodes
3363 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
3364 myLastCreatedNodes->length(aSeq.Length());
3365 for(int i=0; i<aSeq.Length(); i++)
3366 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
3369 // add new elements into myLastCreatedElems
3370 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
3371 myLastCreatedElems->length(aSeq.Length());
3372 for(int i=0; i<aSeq.Length(); i++)
3373 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
3377 //================================================================================
3379 * Return data of mesh edition preview
3381 //================================================================================
3383 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
3385 return myPreviewData._retn();
3388 //================================================================================
3390 * \brief Returns list of it's IDs of created nodes
3391 * \retval SMESH::long_array* - list of node ID
3393 //================================================================================
3395 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
3397 return myLastCreatedNodes._retn();
3400 //================================================================================
3402 * \brief Returns list of it's IDs of created elements
3403 * \retval SMESH::long_array* - list of elements' ID
3405 //================================================================================
3407 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
3409 return myLastCreatedElems._retn();
3412 //=======================================================================
3413 //function : ConvertToQuadratic
3415 //=======================================================================
3417 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
3419 ::SMESH_MeshEditor anEditor( myMesh );
3420 anEditor.ConvertToQuadratic(theForce3d);
3421 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
3424 //=======================================================================
3425 //function : ConvertFromQuadratic
3427 //=======================================================================
3429 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
3431 ::SMESH_MeshEditor anEditor( myMesh );
3432 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
3433 TPythonDump() << this << ".ConvertFromQuadratic()";
3437 //=======================================================================
3438 //function : makeMesh
3439 //purpose : create a named imported mesh
3440 //=======================================================================
3442 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
3444 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
3445 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
3446 SALOMEDS::Study_var study = gen->GetCurrentStudy();
3447 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
3448 gen->SetName( meshSO, theMeshName, "Mesh" );
3450 SALOMEDS::StudyBuilder_var builder = study->NewBuilder();
3451 SALOMEDS::GenericAttribute_var anAttr
3452 = builder->FindOrCreateAttribute( meshSO, "AttributePixMap" );
3453 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
3455 return mesh._retn();