1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_MeshEditor_i.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESH_MeshEditor_i.hxx"
31 #include "SMDS_MeshEdge.hxx"
32 #include "SMDS_MeshFace.hxx"
33 #include "SMDS_MeshVolume.hxx"
34 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
35 #include "SMESH_MeshEditor.hxx"
36 #include "SMESH_subMeshEventListener.hxx"
37 #include "SMESH_Gen_i.hxx"
38 #include "SMESH_Filter_i.hxx"
39 #include "SMESH_PythonDump.hxx"
41 #include "utilities.h"
42 #include "Utils_ExceptHandlers.hxx"
43 #include "Utils_CorbaException.hxx"
45 #include <BRepAdaptor_Surface.hxx>
46 #include <BRep_Tool.hxx>
47 #include <TopExp_Explorer.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Face.hxx>
55 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
59 #include <Standard_Failure.hxx>
62 #include <Standard_ErrorHandler.hxx>
67 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
70 using SMESH::TPythonDump;
74 //=============================================================================
76 * \brief Mesh to apply modifications for preview purposes
78 //=============================================================================
80 struct TPreviewMesh: public SMESH_Mesh
82 SMDSAbs_ElementType myPreviewType; // type to show
84 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
85 _isShapeToMesh = _id =_studyId =_idDoc = 0;
86 _myMeshDS = new SMESHDS_Mesh( _id, true );
87 myPreviewType = previewElements;
90 virtual ~TPreviewMesh() { delete _myMeshDS; }
91 //!< Copy a set of elements
92 void Copy(const TIDSortedElemSet & theElements,
93 TIDSortedElemSet& theCopyElements,
94 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
95 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
97 // loop on theIDsOfElements
98 TIDSortedElemSet::const_iterator eIt = theElements.begin();
99 for ( ; eIt != theElements.end(); ++eIt )
101 const SMDS_MeshElement* anElem = *eIt;
102 if ( !anElem ) continue;
103 SMDSAbs_ElementType type = anElem->GetType();
104 if ( type == theAvoidType ||
105 ( theSelectType != SMDSAbs_All && type != theSelectType ))
108 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
109 theCopyElements.insert( theCopyElements.end(), anElemCopy );
113 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
115 // copy element nodes
116 int anElemNbNodes = anElem->NbNodes();
117 vector< int > anElemNodesID( anElemNbNodes ) ;
118 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
119 for ( int i = 0; itElemNodes->more(); i++)
121 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
123 anElemNodesID[i] = anElemNode->GetID();
126 // creates a corresponding element on copied nodes
127 SMDS_MeshElement* anElemCopy = 0;
128 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
130 const SMDS_PolyhedralVolumeOfNodes* ph =
131 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
133 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
134 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
137 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
144 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
146 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
147 anElemNode->GetID());
149 };// struct TPreviewMesh
151 static SMESH_NodeSearcher * myNodeSearcher = 0;
153 //=============================================================================
155 * \brief Deleter of myNodeSearcher at any compute event occured
157 //=============================================================================
159 struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
163 TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
165 //!< Delete myNodeSearcher
168 if ( myNodeSearcher ) { delete myNodeSearcher; myNodeSearcher = 0; }
170 typedef map < int, SMESH_subMesh * > TDependsOnMap;
171 //!< The meshod called by submesh: do my main job
172 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
173 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
175 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
177 Unset( sm->GetFather() );
180 //!< set self on all submeshes and delete myNodeSearcher if other mesh is set
181 void Set(SMESH_Mesh* mesh)
183 if ( myMesh && myMesh != mesh ) {
188 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
189 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
190 TDependsOnMap::const_iterator sm;
191 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
192 sm->second->SetEventListener( this, 0, sm->second );
195 //!< delete self from all submeshes
196 void Unset(SMESH_Mesh* mesh)
198 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
199 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
200 TDependsOnMap::const_iterator sm;
201 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
202 sm->second->DeleteEventListener( this );
207 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
209 TCollection_AsciiString typeStr;
210 switch ( theMirrorType ) {
211 case SMESH::SMESH_MeshEditor::POINT:
212 typeStr = "SMESH.SMESH_MeshEditor.POINT";
214 case SMESH::SMESH_MeshEditor::AXIS:
215 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
218 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
224 //=============================================================================
228 //=============================================================================
230 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
233 myMesh = & theMesh->GetImpl();
234 myPreviewMode = isPreview;
237 //================================================================================
241 //================================================================================
243 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
247 //================================================================================
249 * \brief Clear members
251 //================================================================================
253 void SMESH_MeshEditor_i::initData()
255 if ( myPreviewMode ) {
256 myPreviewData = new SMESH::MeshPreviewStruct();
259 myLastCreatedElems = new SMESH::long_array();
260 myLastCreatedNodes = new SMESH::long_array();
261 TNodeSearcherDeleter::Delete();
265 //=============================================================================
269 //=============================================================================
272 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
276 ::SMESH_MeshEditor anEditor( myMesh );
279 for (int i = 0; i < IDsOfElements.length(); i++)
280 IdList.push_back( IDsOfElements[i] );
282 // Update Python script
283 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
285 TPythonDump() << "print 'RemoveElements: ', isDone";
288 return anEditor.Remove( IdList, false );
291 //=============================================================================
295 //=============================================================================
297 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
301 ::SMESH_MeshEditor anEditor( myMesh );
303 for (int i = 0; i < IDsOfNodes.length(); i++)
304 IdList.push_back( IDsOfNodes[i] );
306 // Update Python script
307 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
309 TPythonDump() << "print 'RemoveNodes: ', isDone";
312 return anEditor.Remove( IdList, true );
315 //=============================================================================
319 //=============================================================================
321 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
325 int NbNodes = IDsOfNodes.length();
326 SMDS_MeshElement* elem = 0;
329 CORBA::Long index1 = IDsOfNodes[0];
330 CORBA::Long index2 = IDsOfNodes[1];
331 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
333 // Update Python script
334 TPythonDump() << "edge = " << this << ".AddEdge([ "
335 << index1 << ", " << index2 <<" ])";
338 CORBA::Long n1 = IDsOfNodes[0];
339 CORBA::Long n2 = IDsOfNodes[1];
340 CORBA::Long n12 = IDsOfNodes[2];
341 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
342 GetMeshDS()->FindNode(n2),
343 GetMeshDS()->FindNode(n12));
344 // Update Python script
345 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
346 <<n1<<", "<<n2<<", "<<n12<<" ])";
350 return elem->GetID();
355 //=============================================================================
359 //=============================================================================
361 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
362 CORBA::Double y, CORBA::Double z)
366 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
368 // Update Python script
369 TPythonDump() << "nodeID = " << this << ".AddNode( "
370 << x << ", " << y << ", " << z << " )";
375 //=============================================================================
379 //=============================================================================
381 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
385 int NbNodes = IDsOfNodes.length();
391 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
392 for (int i = 0; i < NbNodes; i++)
393 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
395 SMDS_MeshElement* elem = 0;
397 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
399 else if (NbNodes == 4) {
400 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
402 else if (NbNodes == 6) {
403 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
406 else if (NbNodes == 8) {
407 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
408 nodes[4], nodes[5], nodes[6], nodes[7]);
411 // Update Python script
412 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
415 return elem->GetID();
420 //=============================================================================
424 //=============================================================================
425 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
426 (const SMESH::long_array & IDsOfNodes)
430 int NbNodes = IDsOfNodes.length();
431 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
432 for (int i = 0; i < NbNodes; i++)
433 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
435 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
437 // Update Python script
438 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
440 TPythonDump() << "print 'AddPolygonalFace: ', faceID";
444 return elem->GetID();
449 //=============================================================================
453 //=============================================================================
455 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
459 int NbNodes = IDsOfNodes.length();
460 vector< const SMDS_MeshNode*> n(NbNodes);
461 for(int i=0;i<NbNodes;i++)
462 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
464 SMDS_MeshElement* elem = 0;
467 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
468 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
469 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
470 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
471 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
472 n[6],n[7],n[8],n[9]);
474 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
475 n[7],n[8],n[9],n[10],n[11],n[12]);
477 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
478 n[9],n[10],n[11],n[12],n[13],n[14]);
480 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
481 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
482 n[15],n[16],n[17],n[18],n[19]);
486 // Update Python script
487 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
489 TPythonDump() << "print 'AddVolume: ', volID";
493 return elem->GetID();
498 //=============================================================================
500 * AddPolyhedralVolume
502 //=============================================================================
503 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume
504 (const SMESH::long_array & IDsOfNodes,
505 const SMESH::long_array & Quantities)
509 int NbNodes = IDsOfNodes.length();
510 std::vector<const SMDS_MeshNode*> n (NbNodes);
511 for (int i = 0; i < NbNodes; i++)
512 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
514 int NbFaces = Quantities.length();
515 std::vector<int> q (NbFaces);
516 for (int j = 0; j < NbFaces; j++)
517 q[j] = Quantities[j];
519 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
521 // Update Python script
522 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
523 << IDsOfNodes << ", " << Quantities << " )";
525 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
529 return elem->GetID();
534 //=============================================================================
536 * AddPolyhedralVolumeByFaces
538 //=============================================================================
539 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
540 (const SMESH::long_array & IdsOfFaces)
544 int NbFaces = IdsOfFaces.length();
545 std::vector<const SMDS_MeshNode*> poly_nodes;
546 std::vector<int> quantities (NbFaces);
548 for (int i = 0; i < NbFaces; i++) {
549 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
550 quantities[i] = aFace->NbNodes();
552 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
554 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
558 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
560 // Update Python script
561 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
562 << IdsOfFaces << " )";
564 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
568 return elem->GetID();
573 //=============================================================================
575 * \brief Bind a node to a vertex
576 * \param NodeID - node ID
577 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
578 * \retval boolean - false if NodeID or VertexID is invalid
580 //=============================================================================
582 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
583 throw (SALOME::SALOME_Exception)
585 Unexpect aCatch(SALOME_SalomeException);
587 SMESHDS_Mesh * mesh = GetMeshDS();
588 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
590 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
592 if ( mesh->MaxShapeIndex() < VertexID )
593 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
595 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
596 if ( shape.ShapeType() != TopAbs_VERTEX )
597 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
599 mesh->SetNodeOnVertex( node, VertexID );
602 //=============================================================================
604 * \brief Store node position on an edge
605 * \param NodeID - node ID
606 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
607 * \param paramOnEdge - parameter on edge where the node is located
608 * \retval boolean - false if any parameter is invalid
610 //=============================================================================
612 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
613 CORBA::Double paramOnEdge)
614 throw (SALOME::SALOME_Exception)
616 Unexpect aCatch(SALOME_SalomeException);
618 SMESHDS_Mesh * mesh = GetMeshDS();
619 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
621 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
623 if ( mesh->MaxShapeIndex() < EdgeID )
624 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
626 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
627 if ( shape.ShapeType() != TopAbs_EDGE )
628 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
631 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
632 if ( paramOnEdge < f || paramOnEdge > l )
633 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
635 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
638 //=============================================================================
640 * \brief Store node position on a face
641 * \param NodeID - node ID
642 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
643 * \param u - U parameter on face where the node is located
644 * \param v - V parameter on face where the node is located
645 * \retval boolean - false if any parameter is invalid
647 //=============================================================================
649 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
650 CORBA::Double u, CORBA::Double v)
651 throw (SALOME::SALOME_Exception)
653 Unexpect aCatch(SALOME_SalomeException);
655 SMESHDS_Mesh * mesh = GetMeshDS();
656 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
658 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
660 if ( mesh->MaxShapeIndex() < FaceID )
661 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
663 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
664 if ( shape.ShapeType() != TopAbs_FACE )
665 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
667 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
668 bool isOut = ( u < surf.FirstUParameter() ||
669 u > surf.LastUParameter() ||
670 v < surf.FirstVParameter() ||
671 v > surf.LastVParameter() );
675 cout << "FACE " << FaceID << " (" << u << "," << v << ") out of "
676 << " u( " << surf.FirstUParameter()
677 << "," << surf.LastUParameter()
678 << ") v( " << surf.FirstVParameter()
679 << "," << surf.LastVParameter()
682 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
685 mesh->SetNodeOnFace( node, FaceID, u, v );
688 //=============================================================================
690 * \brief Bind a node to a solid
691 * \param NodeID - node ID
692 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
693 * \retval boolean - false if NodeID or SolidID is invalid
695 //=============================================================================
697 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
698 throw (SALOME::SALOME_Exception)
700 Unexpect aCatch(SALOME_SalomeException);
702 SMESHDS_Mesh * mesh = GetMeshDS();
703 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
705 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
707 if ( mesh->MaxShapeIndex() < SolidID )
708 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
710 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
711 if ( shape.ShapeType() != TopAbs_SOLID &&
712 shape.ShapeType() != TopAbs_SHELL)
713 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
715 mesh->SetNodeInVolume( node, SolidID );
718 //=============================================================================
720 * \brief Bind an element to a shape
721 * \param ElementID - element ID
722 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
723 * \retval boolean - false if ElementID or ShapeID is invalid
725 //=============================================================================
727 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
729 throw (SALOME::SALOME_Exception)
731 Unexpect aCatch(SALOME_SalomeException);
733 SMESHDS_Mesh * mesh = GetMeshDS();
734 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
736 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
738 if ( mesh->MaxShapeIndex() < ShapeID )
739 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
741 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
742 if ( shape.ShapeType() != TopAbs_EDGE &&
743 shape.ShapeType() != TopAbs_FACE &&
744 shape.ShapeType() != TopAbs_SOLID &&
745 shape.ShapeType() != TopAbs_SHELL )
746 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
748 mesh->SetMeshElementOnShape( elem, ShapeID );
752 //=============================================================================
756 //=============================================================================
758 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
765 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
769 GetMeshDS()->MoveNode(node, x, y, z);
771 // Update Python script
772 TPythonDump() << "isDone = " << this << ".MoveNode( "
773 << NodeID << ", " << x << ", " << y << ", " << z << " )";
778 //=============================================================================
782 //=============================================================================
784 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
789 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
790 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
794 // Update Python script
795 TPythonDump() << "isDone = " << this << ".InverseDiag( "
796 << NodeID1 << ", " << NodeID2 << " )";
798 ::SMESH_MeshEditor aMeshEditor( myMesh );
799 return aMeshEditor.InverseDiag ( n1, n2 );
802 //=============================================================================
806 //=============================================================================
808 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
813 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
814 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
818 // Update Python script
819 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
820 << NodeID1 << ", " << NodeID2 << " )";
822 ::SMESH_MeshEditor aMeshEditor( myMesh );
824 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
826 storeResult(aMeshEditor);
831 //=============================================================================
835 //=============================================================================
837 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
841 ::SMESH_MeshEditor anEditor( myMesh );
842 for (int i = 0; i < IDsOfElements.length(); i++)
844 CORBA::Long index = IDsOfElements[i];
845 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
847 anEditor.Reorient( elem );
849 // Update Python script
850 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
856 //=============================================================================
860 //=============================================================================
862 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
866 SMESH::long_array_var anElementsId = theObject->GetIDs();
867 CORBA::Boolean isDone = Reorient(anElementsId);
869 // Clear python line, created by Reorient()
870 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
871 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
873 // Update Python script
874 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
881 //================================================================================
883 * \brief function for conversion long_array to TIDSortedElemSet
884 * \param IDs - array of IDs
885 * \param aMesh - mesh
886 * \param aMap - collection to fill
887 * \param aType - element type
889 //================================================================================
891 void arrayToSet(const SMESH::long_array & IDs,
892 const SMESHDS_Mesh* aMesh,
893 TIDSortedElemSet& aMap,
894 const SMDSAbs_ElementType aType = SMDSAbs_All )
896 for (int i=0; i<IDs.length(); i++) {
897 CORBA::Long ind = IDs[i];
898 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
899 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
905 //=============================================================================
909 //=============================================================================
910 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
911 SMESH::NumericalFunctor_ptr Criterion,
912 CORBA::Double MaxAngle)
916 SMESHDS_Mesh* aMesh = GetMeshDS();
917 TIDSortedElemSet faces;
918 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
920 SMESH::NumericalFunctor_i* aNumericalFunctor =
921 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
922 SMESH::Controls::NumericalFunctorPtr aCrit;
923 if ( !aNumericalFunctor )
924 aCrit.reset( new SMESH::Controls::AspectRatio() );
926 aCrit = aNumericalFunctor->GetNumericalFunctor();
928 // Update Python script
929 TPythonDump() << "isDone = " << this << ".TriToQuad( "
930 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
932 TPythonDump() << "print 'TriToQuad: ', isDone";
935 ::SMESH_MeshEditor anEditor( myMesh );
937 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
939 storeResult(anEditor);
945 //=============================================================================
949 //=============================================================================
950 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
951 SMESH::NumericalFunctor_ptr Criterion,
952 CORBA::Double MaxAngle)
956 SMESH::long_array_var anElementsId = theObject->GetIDs();
957 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
959 // Clear python line(s), created by TriToQuad()
960 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
961 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
963 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
966 SMESH::NumericalFunctor_i* aNumericalFunctor =
967 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
969 // Update Python script
970 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
971 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
973 TPythonDump() << "print 'TriToQuadObject: ', isDone";
980 //=============================================================================
984 //=============================================================================
985 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
986 SMESH::NumericalFunctor_ptr Criterion)
990 SMESHDS_Mesh* aMesh = GetMeshDS();
991 TIDSortedElemSet faces;
992 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
994 SMESH::NumericalFunctor_i* aNumericalFunctor =
995 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
996 SMESH::Controls::NumericalFunctorPtr aCrit;
997 if ( !aNumericalFunctor )
998 aCrit.reset( new SMESH::Controls::AspectRatio() );
1000 aCrit = aNumericalFunctor->GetNumericalFunctor();
1003 // Update Python script
1004 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1006 TPythonDump() << "print 'QuadToTri: ', isDone";
1009 ::SMESH_MeshEditor anEditor( myMesh );
1010 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1012 storeResult(anEditor);
1018 //=============================================================================
1022 //=============================================================================
1023 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1024 SMESH::NumericalFunctor_ptr Criterion)
1028 SMESH::long_array_var anElementsId = theObject->GetIDs();
1029 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1031 // Clear python line(s), created by QuadToTri()
1032 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1033 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1035 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1038 SMESH::NumericalFunctor_i* aNumericalFunctor =
1039 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1041 // Update Python script
1042 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1044 TPythonDump() << "print 'QuadToTriObject: ', isDone";
1051 //=============================================================================
1055 //=============================================================================
1056 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1057 CORBA::Boolean Diag13)
1061 SMESHDS_Mesh* aMesh = GetMeshDS();
1062 TIDSortedElemSet faces;
1063 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1065 // Update Python script
1066 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1067 << IDsOfElements << ", " << Diag13 << " )";
1069 TPythonDump() << "print 'SplitQuad: ', isDone";
1072 ::SMESH_MeshEditor anEditor( myMesh );
1073 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1075 storeResult(anEditor);
1081 //=============================================================================
1085 //=============================================================================
1086 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1087 CORBA::Boolean Diag13)
1091 SMESH::long_array_var anElementsId = theObject->GetIDs();
1092 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1094 // Clear python line(s), created by SplitQuad()
1095 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1096 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1098 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1101 // Update Python script
1102 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1103 << theObject << ", " << Diag13 << " )";
1105 TPythonDump() << "print 'SplitQuadObject: ', isDone";
1112 //=============================================================================
1116 //=============================================================================
1117 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1118 SMESH::NumericalFunctor_ptr Criterion)
1120 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1121 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1123 SMESH::NumericalFunctor_i* aNumericalFunctor =
1124 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1125 SMESH::Controls::NumericalFunctorPtr aCrit;
1126 if (aNumericalFunctor)
1127 aCrit = aNumericalFunctor->GetNumericalFunctor();
1129 aCrit.reset(new SMESH::Controls::AspectRatio());
1131 ::SMESH_MeshEditor anEditor (myMesh);
1132 return anEditor.BestSplit(quad, aCrit);
1138 //=======================================================================
1141 //=======================================================================
1144 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1145 const SMESH::long_array & IDsOfFixedNodes,
1146 CORBA::Long MaxNbOfIterations,
1147 CORBA::Double MaxAspectRatio,
1148 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1150 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1151 MaxAspectRatio, Method, false );
1155 //=======================================================================
1156 //function : SmoothParametric
1158 //=======================================================================
1161 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1162 const SMESH::long_array & IDsOfFixedNodes,
1163 CORBA::Long MaxNbOfIterations,
1164 CORBA::Double MaxAspectRatio,
1165 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1167 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1168 MaxAspectRatio, Method, true );
1172 //=======================================================================
1173 //function : SmoothObject
1175 //=======================================================================
1178 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1179 const SMESH::long_array & IDsOfFixedNodes,
1180 CORBA::Long MaxNbOfIterations,
1181 CORBA::Double MaxAspectRatio,
1182 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1184 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1185 MaxAspectRatio, Method, false);
1189 //=======================================================================
1190 //function : SmoothParametricObject
1192 //=======================================================================
1195 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1196 const SMESH::long_array & IDsOfFixedNodes,
1197 CORBA::Long MaxNbOfIterations,
1198 CORBA::Double MaxAspectRatio,
1199 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1201 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1202 MaxAspectRatio, Method, true);
1206 //=============================================================================
1210 //=============================================================================
1213 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1214 const SMESH::long_array & IDsOfFixedNodes,
1215 CORBA::Long MaxNbOfIterations,
1216 CORBA::Double MaxAspectRatio,
1217 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1222 SMESHDS_Mesh* aMesh = GetMeshDS();
1224 TIDSortedElemSet elements;
1225 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1227 set<const SMDS_MeshNode*> fixedNodes;
1228 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1229 CORBA::Long index = IDsOfFixedNodes[i];
1230 const SMDS_MeshNode * node = aMesh->FindNode(index);
1232 fixedNodes.insert( node );
1234 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1235 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1236 method = ::SMESH_MeshEditor::CENTROIDAL;
1238 ::SMESH_MeshEditor anEditor( myMesh );
1239 anEditor.Smooth(elements, fixedNodes, method,
1240 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1242 storeResult(anEditor);
1244 // Update Python script
1245 TPythonDump() << "isDone = " << this << "."
1246 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1247 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1248 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1249 << "SMESH.SMESH_MeshEditor."
1250 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1251 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1253 TPythonDump() << "print 'Smooth: ', isDone";
1260 //=============================================================================
1264 //=============================================================================
1267 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1268 const SMESH::long_array & IDsOfFixedNodes,
1269 CORBA::Long MaxNbOfIterations,
1270 CORBA::Double MaxAspectRatio,
1271 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1276 SMESH::long_array_var anElementsId = theObject->GetIDs();
1277 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1278 MaxAspectRatio, Method, IsParametric);
1280 // Clear python line(s), created by Smooth()
1281 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1282 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1284 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1287 // Update Python script
1288 TPythonDump() << "isDone = " << this << "."
1289 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1290 << theObject << ", " << IDsOfFixedNodes << ", "
1291 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1292 << "SMESH.SMESH_MeshEditor."
1293 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1294 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1296 TPythonDump() << "print 'SmoothObject: ', isDone";
1303 //=============================================================================
1307 //=============================================================================
1309 void SMESH_MeshEditor_i::RenumberNodes()
1311 // Update Python script
1312 TPythonDump() << this << ".RenumberNodes()";
1314 GetMeshDS()->Renumber( true );
1318 //=============================================================================
1322 //=============================================================================
1324 void SMESH_MeshEditor_i::RenumberElements()
1326 // Update Python script
1327 TPythonDump() << this << ".RenumberElements()";
1329 GetMeshDS()->Renumber( false );
1332 //=======================================================================
1334 * \brief Return groups by their IDs
1336 //=======================================================================
1338 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1342 myMesh_i->CreateGroupServants();
1343 return myMesh_i->GetGroups( *groupIDs );
1346 //=======================================================================
1347 //function : rotationSweep
1349 //=======================================================================
1351 SMESH::ListOfGroups*
1352 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1353 const SMESH::AxisStruct & theAxis,
1354 CORBA::Double theAngleInRadians,
1355 CORBA::Long theNbOfSteps,
1356 CORBA::Double theTolerance,
1357 const bool theMakeGroups)
1361 TIDSortedElemSet inElements, copyElements;
1362 arrayToSet(theIDsOfElements, GetMeshDS(), inElements);
1364 TIDSortedElemSet* workElements = & inElements;
1365 TPreviewMesh tmpMesh( SMDSAbs_Face );
1366 SMESH_Mesh* mesh = 0;
1367 bool makeWalls=true;
1368 if ( myPreviewMode )
1370 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1371 tmpMesh.Copy( inElements, copyElements, select, avoid );
1373 workElements = & copyElements;
1374 //makeWalls = false;
1381 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1382 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1384 ::SMESH_MeshEditor anEditor( mesh );
1385 ::SMESH_MeshEditor::PGroupIDs groupIds =
1386 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1387 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1388 storeResult(anEditor);
1390 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1393 //=======================================================================
1394 //function : RotationSweep
1396 //=======================================================================
1398 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1399 const SMESH::AxisStruct & theAxis,
1400 CORBA::Double theAngleInRadians,
1401 CORBA::Long theNbOfSteps,
1402 CORBA::Double theTolerance)
1404 if ( !myPreviewMode ) {
1405 TPythonDump() << "axis = " << theAxis;
1406 TPythonDump() << this << ".RotationSweep( "
1409 << theAngleInRadians << ", "
1410 << theNbOfSteps << ", "
1411 << theTolerance << " )";
1413 rotationSweep(theIDsOfElements,
1421 //=======================================================================
1422 //function : RotationSweepMakeGroups
1424 //=======================================================================
1426 SMESH::ListOfGroups*
1427 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1428 const SMESH::AxisStruct& theAxis,
1429 CORBA::Double theAngleInRadians,
1430 CORBA::Long theNbOfSteps,
1431 CORBA::Double theTolerance)
1433 if ( !myPreviewMode ) {
1434 TPythonDump() << "axis = " << theAxis;
1435 TPythonDump() << this << ".RotationSweepMakeGroups( "
1438 << theAngleInRadians << ", "
1439 << theNbOfSteps << ", "
1440 << theTolerance << " )";
1442 return rotationSweep(theIDsOfElements,
1450 //=======================================================================
1451 //function : RotationSweepObject
1453 //=======================================================================
1455 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1456 const SMESH::AxisStruct & theAxis,
1457 CORBA::Double theAngleInRadians,
1458 CORBA::Long theNbOfSteps,
1459 CORBA::Double theTolerance)
1461 if ( !myPreviewMode ) {
1462 TPythonDump() << "axis = " << theAxis;
1463 TPythonDump() << this << ".RotationSweepObject( "
1466 << theAngleInRadians << ", "
1467 << theNbOfSteps << ", "
1468 << theTolerance << " )";
1470 SMESH::long_array_var anElementsId = theObject->GetIDs();
1471 rotationSweep(anElementsId,
1479 //=======================================================================
1480 //function : RotationSweepObjectMakeGroups
1482 //=======================================================================
1484 SMESH::ListOfGroups*
1485 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1486 const SMESH::AxisStruct& theAxis,
1487 CORBA::Double theAngleInRadians,
1488 CORBA::Long theNbOfSteps,
1489 CORBA::Double theTolerance)
1491 if ( !myPreviewMode ) {
1492 TPythonDump() << "axis = " << theAxis;
1493 TPythonDump() << this << ".RotationSweepObjectMakeGroups( "
1496 << theAngleInRadians << ", "
1497 << theNbOfSteps << ", "
1498 << theTolerance << " )";
1500 SMESH::long_array_var anElementsId = theObject->GetIDs();
1501 return rotationSweep(anElementsId,
1510 //=======================================================================
1511 //function : extrusionSweep
1513 //=======================================================================
1515 SMESH::ListOfGroups*
1516 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1517 const SMESH::DirStruct & theStepVector,
1518 CORBA::Long theNbOfSteps,
1519 const bool theMakeGroups,
1520 const SMDSAbs_ElementType theElementType)
1528 TIDSortedElemSet elements;
1529 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1531 const SMESH::PointStruct * P = &theStepVector.PS;
1532 gp_Vec stepVec( P->x, P->y, P->z );
1534 TElemOfElemListMap aHystory;
1535 ::SMESH_MeshEditor anEditor( myMesh );
1536 ::SMESH_MeshEditor::PGroupIDs groupIds =
1537 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1539 storeResult(anEditor);
1541 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1543 } catch(Standard_Failure) {
1544 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1545 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1550 //=======================================================================
1551 //function : ExtrusionSweep
1553 //=======================================================================
1555 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1556 const SMESH::DirStruct & theStepVector,
1557 CORBA::Long theNbOfSteps)
1559 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1560 if ( !myPreviewMode ) {
1561 TPythonDump() << "stepVector = " << theStepVector;
1562 TPythonDump() << this << ".ExtrusionSweep( "
1563 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1568 //=======================================================================
1569 //function : ExtrusionSweepObject
1571 //=======================================================================
1573 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1574 const SMESH::DirStruct & theStepVector,
1575 CORBA::Long theNbOfSteps)
1577 SMESH::long_array_var anElementsId = theObject->GetIDs();
1578 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1579 if ( !myPreviewMode ) {
1580 TPythonDump() << "stepVector = " << theStepVector;
1581 TPythonDump() << this << ".ExtrusionSweepObject( "
1582 << theObject << ", stepVector, " << theNbOfSteps << " )";
1586 //=======================================================================
1587 //function : ExtrusionSweepObject1D
1589 //=======================================================================
1591 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1592 const SMESH::DirStruct & theStepVector,
1593 CORBA::Long theNbOfSteps)
1595 SMESH::long_array_var anElementsId = theObject->GetIDs();
1596 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1597 if ( !myPreviewMode ) {
1598 TPythonDump() << "stepVector = " << theStepVector;
1599 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1600 << theObject << ", stepVector, " << theNbOfSteps << " )";
1604 //=======================================================================
1605 //function : ExtrusionSweepObject2D
1607 //=======================================================================
1609 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1610 const SMESH::DirStruct & theStepVector,
1611 CORBA::Long theNbOfSteps)
1613 SMESH::long_array_var anElementsId = theObject->GetIDs();
1614 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1615 if ( !myPreviewMode ) {
1616 TPythonDump() << "stepVector = " << theStepVector;
1617 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1618 << theObject << ", stepVector, " << theNbOfSteps << " )";
1622 //=======================================================================
1623 //function : ExtrusionSweepMakeGroups
1625 //=======================================================================
1627 SMESH::ListOfGroups*
1628 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1629 const SMESH::DirStruct& theStepVector,
1630 CORBA::Long theNbOfSteps)
1632 if ( !myPreviewMode ) {
1633 TPythonDump() << "stepVector = " << theStepVector;
1634 TPythonDump() << this << ".ExtrusionSweepMakeGroups( "
1635 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1637 return extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1639 //=======================================================================
1640 //function : ExtrusionSweepObjectMakeGroups
1642 //=======================================================================
1644 SMESH::ListOfGroups*
1645 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1646 const SMESH::DirStruct& theStepVector,
1647 CORBA::Long theNbOfSteps)
1649 if ( !myPreviewMode ) {
1650 TPythonDump() << "stepVector = " << theStepVector;
1651 TPythonDump() << this << ".ExtrusionSweepObjectMakeGroups( "
1652 << theObject << ", stepVector, " << theNbOfSteps << " )";
1654 SMESH::long_array_var anElementsId = theObject->GetIDs();
1655 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1658 //=======================================================================
1659 //function : ExtrusionSweepObject1DMakeGroups
1661 //=======================================================================
1663 SMESH::ListOfGroups*
1664 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1665 const SMESH::DirStruct& theStepVector,
1666 CORBA::Long theNbOfSteps)
1668 if ( !myPreviewMode ) {
1669 TPythonDump() << "stepVector = " << theStepVector;
1670 TPythonDump() << this << ".ExtrusionSweepObject1DMakeGroups( "
1671 << theObject << ", stepVector, " << theNbOfSteps << " )";
1673 SMESH::long_array_var anElementsId = theObject->GetIDs();
1674 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1677 //=======================================================================
1678 //function : ExtrusionSweepObject2DMakeGroups
1680 //=======================================================================
1682 SMESH::ListOfGroups*
1683 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1684 const SMESH::DirStruct& theStepVector,
1685 CORBA::Long theNbOfSteps)
1687 if ( !myPreviewMode ) {
1688 TPythonDump() << "stepVector = " << theStepVector;
1689 TPythonDump() << this << ".ExtrusionSweepObject2DMakeGroups( "
1690 << theObject << ", stepVector, " << theNbOfSteps << " )";
1692 SMESH::long_array_var anElementsId = theObject->GetIDs();
1693 return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1697 //=======================================================================
1698 //function : advancedExtrusion
1700 //=======================================================================
1702 SMESH::ListOfGroups*
1703 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1704 const SMESH::DirStruct & theStepVector,
1705 CORBA::Long theNbOfSteps,
1706 CORBA::Long theExtrFlags,
1707 CORBA::Double theSewTolerance,
1708 const bool theMakeGroups)
1712 TIDSortedElemSet elements;
1713 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1715 const SMESH::PointStruct * P = &theStepVector.PS;
1716 gp_Vec stepVec( P->x, P->y, P->z );
1718 ::SMESH_MeshEditor anEditor( myMesh );
1719 TElemOfElemListMap aHystory;
1720 ::SMESH_MeshEditor::PGroupIDs groupIds =
1721 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1722 theMakeGroups, theExtrFlags, theSewTolerance);
1723 storeResult(anEditor);
1725 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1728 //=======================================================================
1729 //function : AdvancedExtrusion
1731 //=======================================================================
1733 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1734 const SMESH::DirStruct & theStepVector,
1735 CORBA::Long theNbOfSteps,
1736 CORBA::Long theExtrFlags,
1737 CORBA::Double theSewTolerance)
1739 if ( !myPreviewMode ) {
1740 TPythonDump() << "stepVector = " << theStepVector;
1741 TPythonDump() << this << ".AdvancedExtrusion("
1744 << theNbOfSteps << ","
1745 << theExtrFlags << ", "
1746 << theSewTolerance << " )";
1748 advancedExtrusion( theIDsOfElements,
1756 //=======================================================================
1757 //function : AdvancedExtrusionMakeGroups
1759 //=======================================================================
1761 SMESH::ListOfGroups*
1762 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1763 const SMESH::DirStruct& theStepVector,
1764 CORBA::Long theNbOfSteps,
1765 CORBA::Long theExtrFlags,
1766 CORBA::Double theSewTolerance)
1768 if ( !myPreviewMode ) {
1769 TPythonDump() << "stepVector = " << theStepVector;
1770 TPythonDump() << this << ".AdvancedExtrusionMakeGroups("
1773 << theNbOfSteps << ","
1774 << theExtrFlags << ", "
1775 << theSewTolerance << " )";
1777 return advancedExtrusion( theIDsOfElements,
1786 //================================================================================
1788 * \brief Convert extrusion error to IDL enum
1790 //================================================================================
1792 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1794 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1798 RETCASE( EXTR_NO_ELEMENTS );
1799 RETCASE( EXTR_PATH_NOT_EDGE );
1800 RETCASE( EXTR_BAD_PATH_SHAPE );
1801 RETCASE( EXTR_BAD_STARTING_NODE );
1802 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1803 RETCASE( EXTR_CANT_GET_TANGENT );
1805 return SMESH::SMESH_MeshEditor::EXTR_OK;
1809 //=======================================================================
1810 //function : extrusionAlongPath
1812 //=======================================================================
1814 SMESH::ListOfGroups*
1815 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1816 SMESH::SMESH_Mesh_ptr thePathMesh,
1817 GEOM::GEOM_Object_ptr thePathShape,
1818 CORBA::Long theNodeStart,
1819 CORBA::Boolean theHasAngles,
1820 const SMESH::double_array & theAngles,
1821 CORBA::Boolean theHasRefPoint,
1822 const SMESH::PointStruct & theRefPoint,
1823 const bool theMakeGroups,
1824 SMESH::SMESH_MeshEditor::Extrusion_Error & theError)
1828 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1829 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1832 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1834 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1835 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1837 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
1838 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1842 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1844 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1848 TIDSortedElemSet elements;
1849 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1851 list<double> angles;
1852 for (int i = 0; i < theAngles.length(); i++) {
1853 angles.push_back( theAngles[i] );
1856 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1858 int nbOldGroups = myMesh->NbGroup();
1860 ::SMESH_MeshEditor anEditor( myMesh );
1861 ::SMESH_MeshEditor::Extrusion_Error error =
1862 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1863 theHasAngles, angles,
1864 theHasRefPoint, refPnt, theMakeGroups );
1865 storeResult(anEditor);
1866 theError = convExtrError( error );
1868 if ( theMakeGroups ) {
1869 list<int> groupIDs = myMesh->GetGroupIds();
1870 list<int>::iterator newBegin = groupIDs.begin();
1871 std::advance( newBegin, nbOldGroups ); // skip old groups
1872 groupIDs.erase( groupIDs.begin(), newBegin );
1873 return getGroups( & groupIDs );
1878 //=======================================================================
1879 //function : ExtrusionAlongPath
1881 //=======================================================================
1883 SMESH::SMESH_MeshEditor::Extrusion_Error
1884 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1885 SMESH::SMESH_Mesh_ptr thePathMesh,
1886 GEOM::GEOM_Object_ptr thePathShape,
1887 CORBA::Long theNodeStart,
1888 CORBA::Boolean theHasAngles,
1889 const SMESH::double_array & theAngles,
1890 CORBA::Boolean theHasRefPoint,
1891 const SMESH::PointStruct & theRefPoint)
1893 if ( !myPreviewMode ) {
1894 TPythonDump() << "rotAngles = " << theAngles;
1896 if ( theHasRefPoint )
1897 TPythonDump() << "refPoint = SMESH.PointStruct( "
1898 << theRefPoint.x << ", "
1899 << theRefPoint.y << ", "
1900 << theRefPoint.z << " )";
1902 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1904 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
1905 << theIDsOfElements << ", "
1906 << thePathMesh << ", "
1907 << thePathShape << ", "
1908 << theNodeStart << ", "
1909 << theHasAngles << ", "
1910 << "rotAngles" << ", "
1911 << theHasRefPoint << ", refPoint )";
1913 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1914 extrusionAlongPath( theIDsOfElements,
1927 //=======================================================================
1928 //function : ExtrusionAlongPathObject
1930 //=======================================================================
1932 SMESH::SMESH_MeshEditor::Extrusion_Error
1933 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
1934 SMESH::SMESH_Mesh_ptr thePathMesh,
1935 GEOM::GEOM_Object_ptr thePathShape,
1936 CORBA::Long theNodeStart,
1937 CORBA::Boolean theHasAngles,
1938 const SMESH::double_array & theAngles,
1939 CORBA::Boolean theHasRefPoint,
1940 const SMESH::PointStruct & theRefPoint)
1942 if ( !myPreviewMode ) {
1943 TPythonDump() << "rotAngles = " << theAngles;
1945 if ( theHasRefPoint )
1946 TPythonDump() << "refPoint = SMESH.PointStruct( "
1947 << theRefPoint.x << ", "
1948 << theRefPoint.y << ", "
1949 << theRefPoint.z << " )";
1951 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1953 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
1954 << theObject << ", "
1955 << thePathMesh << ", "
1956 << thePathShape << ", "
1957 << theNodeStart << ", "
1958 << theHasAngles << ", "
1959 << "rotAngles" << ", "
1960 << theHasRefPoint << ", refPoint )";
1962 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1963 SMESH::long_array_var anElementsId = theObject->GetIDs();
1964 extrusionAlongPath( anElementsId,
1978 //=======================================================================
1979 //function : ExtrusionAlongPathMakeGroups
1981 //=======================================================================
1983 SMESH::ListOfGroups*
1984 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
1985 SMESH::SMESH_Mesh_ptr thePathMesh,
1986 GEOM::GEOM_Object_ptr thePathShape,
1987 CORBA::Long theNodeStart,
1988 CORBA::Boolean theHasAngles,
1989 const SMESH::double_array& theAngles,
1990 CORBA::Boolean theHasRefPoint,
1991 const SMESH::PointStruct& theRefPoint,
1992 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
1994 if ( !myPreviewMode ) {
1995 TPythonDump() << "rotAngles = " << theAngles;
1997 if ( theHasRefPoint )
1998 TPythonDump() << "refPoint = SMESH.PointStruct( "
1999 << theRefPoint.x << ", "
2000 << theRefPoint.y << ", "
2001 << theRefPoint.z << " )";
2003 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2005 TPythonDump() << "groups = " << this << ".ExtrusionAlongPathMakeGroups( "
2006 << theIDsOfElements << ", "
2007 << thePathMesh << ", "
2008 << thePathShape << ", "
2009 << theNodeStart << ", "
2010 << theHasAngles << ", "
2011 << "rotAngles" << ", "
2012 << theHasRefPoint << ", refPoint )";
2014 return extrusionAlongPath( theIDsOfElements,
2026 //=======================================================================
2027 //function : ExtrusionAlongPathObjectMakeGroups
2029 //=======================================================================
2031 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2032 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2033 SMESH::SMESH_Mesh_ptr thePathMesh,
2034 GEOM::GEOM_Object_ptr thePathShape,
2035 CORBA::Long theNodeStart,
2036 CORBA::Boolean theHasAngles,
2037 const SMESH::double_array& theAngles,
2038 CORBA::Boolean theHasRefPoint,
2039 const SMESH::PointStruct& theRefPoint,
2040 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2042 if ( !myPreviewMode ) {
2043 TPythonDump() << "rotAngles = " << theAngles;
2045 if ( theHasRefPoint )
2046 TPythonDump() << "refPoint = SMESH.PointStruct( "
2047 << theRefPoint.x << ", "
2048 << theRefPoint.y << ", "
2049 << theRefPoint.z << " )";
2051 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2053 TPythonDump() << "groups = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2054 << theObject << ", "
2055 << thePathMesh << ", "
2056 << thePathShape << ", "
2057 << theNodeStart << ", "
2058 << theHasAngles << ", "
2059 << "rotAngles" << ", "
2060 << theHasRefPoint << ", refPoint )";
2062 SMESH::long_array_var anElementsId = theObject->GetIDs();
2063 return extrusionAlongPath( anElementsId,
2075 //================================================================================
2077 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2078 * of given angles along path steps
2079 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2080 * which proceeds the extrusion
2081 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2082 * is used to define the sub-mesh for the path
2084 //================================================================================
2086 SMESH::double_array*
2087 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2088 GEOM::GEOM_Object_ptr thePathShape,
2089 const SMESH::double_array & theAngles)
2091 SMESH::double_array_var aResult = new SMESH::double_array();
2092 int nbAngles = theAngles.length();
2093 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2095 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2096 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2097 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2098 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2099 return aResult._retn();
2100 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2101 if ( nbSteps == nbAngles )
2103 aResult.inout() = theAngles;
2107 aResult->length( nbSteps );
2108 double rAn2St = double( nbAngles ) / double( nbSteps );
2109 double angPrev = 0, angle;
2110 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2112 double angCur = rAn2St * ( iSt+1 );
2113 double angCurFloor = floor( angCur );
2114 double angPrevFloor = floor( angPrev );
2115 if ( angPrevFloor == angCurFloor )
2116 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2119 int iP = int( angPrevFloor );
2120 double angPrevCeil = ceil(angPrev);
2121 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2123 int iC = int( angCurFloor );
2124 if ( iC < nbAngles )
2125 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2127 iP = int( angPrevCeil );
2129 angle += theAngles[ iC ];
2131 aResult[ iSt ] = angle;
2136 // Update Python script
2137 TPythonDump() << "rotAngles = " << theAngles;
2138 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2139 << thePathMesh << ", "
2140 << thePathShape << ", "
2143 return aResult._retn();
2147 //=======================================================================
2150 //=======================================================================
2152 SMESH::ListOfGroups*
2153 SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
2154 const SMESH::AxisStruct & theAxis,
2155 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2156 CORBA::Boolean theCopy,
2157 const bool theMakeGroups,
2158 ::SMESH_Mesh* theTargetMesh)
2162 TIDSortedElemSet elements;
2163 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2165 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2166 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2169 switch ( theMirrorType ) {
2170 case SMESH::SMESH_MeshEditor::POINT:
2171 aTrsf.SetMirror( P );
2173 case SMESH::SMESH_MeshEditor::AXIS:
2174 aTrsf.SetMirror( gp_Ax1( P, V ));
2177 aTrsf.SetMirror( gp_Ax2( P, V ));
2180 ::SMESH_MeshEditor anEditor( myMesh );
2181 ::SMESH_MeshEditor::PGroupIDs groupIds =
2182 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2185 storeResult(anEditor);
2187 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2190 //=======================================================================
2193 //=======================================================================
2195 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2196 const SMESH::AxisStruct & theAxis,
2197 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2198 CORBA::Boolean theCopy)
2200 if ( !myPreviewMode ) {
2201 TPythonDump() << this << ".Mirror( "
2202 << theIDsOfElements << ", "
2204 << mirrorTypeName(theMirrorType) << ", "
2207 mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2211 //=======================================================================
2212 //function : MirrorObject
2214 //=======================================================================
2216 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2217 const SMESH::AxisStruct & theAxis,
2218 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2219 CORBA::Boolean theCopy)
2221 if ( !myPreviewMode ) {
2222 TPythonDump() << this << ".MirrorObject( "
2223 << theObject << ", "
2225 << mirrorTypeName(theMirrorType) << ", "
2228 SMESH::long_array_var anElementsId = theObject->GetIDs();
2229 mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2232 //=======================================================================
2233 //function : MirrorMakeGroups
2235 //=======================================================================
2237 SMESH::ListOfGroups*
2238 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2239 const SMESH::AxisStruct& theMirror,
2240 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2242 if ( !myPreviewMode ) {
2243 TPythonDump() << this << ".MirrorMakeGroups( "
2244 << theIDsOfElements << ", "
2245 << theMirror << ", "
2246 << mirrorTypeName(theMirrorType) << " )";
2248 return mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2251 //=======================================================================
2252 //function : MirrorObjectMakeGroups
2254 //=======================================================================
2256 SMESH::ListOfGroups*
2257 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2258 const SMESH::AxisStruct& theMirror,
2259 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2261 if ( !myPreviewMode ) {
2262 TPythonDump() << this << ".MirrorObjectMakeGroups( "
2263 << theObject << ", "
2264 << theMirror << ", "
2265 << mirrorTypeName(theMirrorType) << " )";
2267 SMESH::long_array_var anElementsId = theObject->GetIDs();
2268 return mirror(anElementsId, theMirror, theMirrorType, true, true);
2271 //=======================================================================
2272 //function : MirrorMakeMesh
2274 //=======================================================================
2276 SMESH::SMESH_Mesh_ptr
2277 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2278 const SMESH::AxisStruct& theMirror,
2279 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2280 CORBA::Boolean theCopyGroups,
2281 const char* theMeshName)
2283 TPythonDump pydump; // to prevent dump at mesh creation
2285 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2286 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh ))
2288 mirror(theIDsOfElements, theMirror, theMirrorType,
2289 false, theCopyGroups, & mesh_i->GetImpl());
2290 mesh_i->CreateGroupServants();
2293 if ( !myPreviewMode ) {
2294 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2295 << theIDsOfElements << ", "
2296 << theMirror << ", "
2297 << mirrorTypeName(theMirrorType) << ", "
2298 << theCopyGroups << ", '"
2299 << theMeshName << "' )";
2301 return mesh._retn();
2304 //=======================================================================
2305 //function : MirrorObjectMakeMesh
2307 //=======================================================================
2309 SMESH::SMESH_Mesh_ptr
2310 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2311 const SMESH::AxisStruct& theMirror,
2312 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2313 CORBA::Boolean theCopyGroups,
2314 const char* theMeshName)
2316 TPythonDump pydump; // to prevent dump at mesh creation
2318 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2319 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh ))
2321 SMESH::long_array_var anElementsId = theObject->GetIDs();
2322 mirror(anElementsId, theMirror, theMirrorType,
2323 false, theCopyGroups, & mesh_i->GetImpl());
2324 mesh_i->CreateGroupServants();
2326 if ( !myPreviewMode ) {
2327 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
2328 << theObject << ", "
2329 << theMirror << ", "
2330 << mirrorTypeName(theMirrorType) << ", "
2331 << theCopyGroups << ", '"
2332 << theMeshName << "' )";
2334 return mesh._retn();
2337 //=======================================================================
2338 //function : translate
2340 //=======================================================================
2342 SMESH::ListOfGroups*
2343 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2344 const SMESH::DirStruct & theVector,
2345 CORBA::Boolean theCopy,
2346 const bool theMakeGroups,
2347 ::SMESH_Mesh* theTargetMesh)
2351 TIDSortedElemSet elements;
2352 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2355 const SMESH::PointStruct * P = &theVector.PS;
2356 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2358 ::SMESH_MeshEditor anEditor( myMesh );
2359 ::SMESH_MeshEditor::PGroupIDs groupIds =
2360 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2363 storeResult(anEditor);
2365 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2368 //=======================================================================
2369 //function : Translate
2371 //=======================================================================
2373 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2374 const SMESH::DirStruct & theVector,
2375 CORBA::Boolean theCopy)
2377 if ( !myPreviewMode ) {
2378 TPythonDump() << "vector = " << theVector;
2379 TPythonDump() << this << ".Translate( "
2384 translate(theIDsOfElements,
2390 //=======================================================================
2391 //function : TranslateObject
2393 //=======================================================================
2395 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
2396 const SMESH::DirStruct & theVector,
2397 CORBA::Boolean theCopy)
2399 if ( !myPreviewMode ) {
2400 TPythonDump() << this << ".TranslateObject( "
2405 SMESH::long_array_var anElementsId = theObject->GetIDs();
2406 translate(anElementsId,
2412 //=======================================================================
2413 //function : TranslateMakeGroups
2415 //=======================================================================
2417 SMESH::ListOfGroups*
2418 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
2419 const SMESH::DirStruct& theVector)
2421 if ( !myPreviewMode ) {
2422 TPythonDump() << "vector = " << theVector;
2423 TPythonDump() << this << ".TranslateMakeGroups( "
2427 return translate(theIDsOfElements,theVector,true,true);
2430 //=======================================================================
2431 //function : TranslateObjectMakeGroups
2433 //=======================================================================
2435 SMESH::ListOfGroups*
2436 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2437 const SMESH::DirStruct& theVector)
2439 if ( !myPreviewMode ) {
2440 TPythonDump() << "vector = " << theVector;
2441 TPythonDump() << this << ".TranslateObjectMakeGroups( "
2445 SMESH::long_array_var anElementsId = theObject->GetIDs();
2446 return translate(anElementsId, theVector, true, true);
2449 //=======================================================================
2450 //function : TranslateMakeMesh
2452 //=======================================================================
2454 SMESH::SMESH_Mesh_ptr
2455 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
2456 const SMESH::DirStruct& theVector,
2457 CORBA::Boolean theCopyGroups,
2458 const char* theMeshName)
2460 TPythonDump pydump; // to prevent dump at mesh creation
2461 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2463 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2464 translate(theIDsOfElements, theVector,
2465 false, theCopyGroups, & mesh_i->GetImpl());
2466 mesh_i->CreateGroupServants();
2468 if ( !myPreviewMode ) {
2469 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
2470 << theIDsOfElements << ", "
2471 << theVector << ", "
2472 << theCopyGroups << ", '"
2473 << theMeshName << "' )";
2475 return mesh._retn();
2478 //=======================================================================
2479 //function : TranslateObjectMakeMesh
2481 //=======================================================================
2483 SMESH::SMESH_Mesh_ptr
2484 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2485 const SMESH::DirStruct& theVector,
2486 CORBA::Boolean theCopyGroups,
2487 const char* theMeshName)
2489 TPythonDump pydump; // to prevent dump at mesh creation
2490 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2492 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2493 SMESH::long_array_var anElementsId = theObject->GetIDs();
2494 translate(anElementsId, theVector,
2495 false, theCopyGroups, & mesh_i->GetImpl());
2496 mesh_i->CreateGroupServants();
2498 if ( !myPreviewMode ) {
2499 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
2500 << theObject << ", "
2501 << theVector << ", "
2502 << theCopyGroups << ", '"
2503 << theMeshName << "' )";
2505 return mesh._retn();
2508 //=======================================================================
2511 //=======================================================================
2513 SMESH::ListOfGroups*
2514 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
2515 const SMESH::AxisStruct & theAxis,
2516 CORBA::Double theAngle,
2517 CORBA::Boolean theCopy,
2518 const bool theMakeGroups,
2519 ::SMESH_Mesh* theTargetMesh)
2523 TIDSortedElemSet elements;
2524 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2526 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2527 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2530 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
2532 ::SMESH_MeshEditor anEditor( myMesh );
2533 ::SMESH_MeshEditor::PGroupIDs groupIds =
2534 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2537 storeResult(anEditor);
2539 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2542 //=======================================================================
2545 //=======================================================================
2547 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
2548 const SMESH::AxisStruct & theAxis,
2549 CORBA::Double theAngle,
2550 CORBA::Boolean theCopy)
2552 if ( !myPreviewMode ) {
2553 TPythonDump() << "axis = " << theAxis;
2554 TPythonDump() << this << ".Rotate( "
2560 rotate(theIDsOfElements,
2567 //=======================================================================
2568 //function : RotateObject
2570 //=======================================================================
2572 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
2573 const SMESH::AxisStruct & theAxis,
2574 CORBA::Double theAngle,
2575 CORBA::Boolean theCopy)
2577 if ( !myPreviewMode ) {
2578 TPythonDump() << "axis = " << theAxis;
2579 TPythonDump() << this << ".RotateObject( "
2585 SMESH::long_array_var anElementsId = theObject->GetIDs();
2586 rotate(anElementsId,
2593 //=======================================================================
2594 //function : RotateMakeGroups
2596 //=======================================================================
2598 SMESH::ListOfGroups*
2599 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
2600 const SMESH::AxisStruct& theAxis,
2601 CORBA::Double theAngle)
2603 if ( !myPreviewMode ) {
2604 TPythonDump() << "axis = " << theAxis;
2605 TPythonDump() << this << ".RotateMakeGroups( "
2608 << theAngle << " )";
2610 return rotate(theIDsOfElements,theAxis,theAngle,true,true);
2613 //=======================================================================
2614 //function : RotateObjectMakeGroups
2616 //=======================================================================
2618 SMESH::ListOfGroups*
2619 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2620 const SMESH::AxisStruct& theAxis,
2621 CORBA::Double theAngle)
2623 if ( !myPreviewMode ) {
2624 TPythonDump() << "axis = " << theAxis;
2625 TPythonDump() << this << ".RotateObjectMakeGroups( "
2628 << theAngle << " )";
2630 SMESH::long_array_var anElementsId = theObject->GetIDs();
2631 return rotate(anElementsId,theAxis,theAngle,true,true);
2634 //=======================================================================
2635 //function : RotateMakeMesh
2637 //=======================================================================
2639 SMESH::SMESH_Mesh_ptr
2640 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
2641 const SMESH::AxisStruct& theAxis,
2642 CORBA::Double theAngleInRadians,
2643 CORBA::Boolean theCopyGroups,
2644 const char* theMeshName)
2646 TPythonDump pydump; // to prevent dump at mesh creation
2647 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2649 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2650 rotate(theIDsOfElements, theAxis, theAngleInRadians,
2651 false, theCopyGroups, & mesh_i->GetImpl());
2652 mesh_i->CreateGroupServants();
2654 if ( !myPreviewMode ) {
2655 pydump << mesh << " = " << this << ".RotateMakeMesh( "
2656 << theIDsOfElements << ", "
2658 << theAngleInRadians << ", "
2659 << theCopyGroups << ", '"
2660 << theMeshName << "' )";
2662 return mesh._retn();
2665 //=======================================================================
2666 //function : RotateObjectMakeMesh
2668 //=======================================================================
2670 SMESH::SMESH_Mesh_ptr
2671 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2672 const SMESH::AxisStruct& theAxis,
2673 CORBA::Double theAngleInRadians,
2674 CORBA::Boolean theCopyGroups,
2675 const char* theMeshName)
2677 TPythonDump pydump; // to prevent dump at mesh creation
2678 SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
2680 if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
2681 SMESH::long_array_var anElementsId = theObject->GetIDs();
2682 rotate(anElementsId, theAxis, theAngleInRadians,
2683 false, theCopyGroups, & mesh_i->GetImpl());
2684 mesh_i->CreateGroupServants();
2686 if ( !myPreviewMode ) {
2687 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
2688 << theObject << ", "
2690 << theAngleInRadians << ", "
2691 << theCopyGroups << ", '"
2692 << theMeshName << "' )";
2694 return mesh._retn();
2697 //=======================================================================
2698 //function : FindCoincidentNodes
2700 //=======================================================================
2702 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
2703 SMESH::array_of_long_array_out GroupsOfNodes)
2707 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2708 ::SMESH_MeshEditor anEditor( myMesh );
2709 set<const SMDS_MeshNode*> nodes; // no input nodes
2710 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2712 GroupsOfNodes = new SMESH::array_of_long_array;
2713 GroupsOfNodes->length( aListOfListOfNodes.size() );
2714 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2715 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2716 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2717 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2718 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2719 aGroup.length( aListOfNodes.size() );
2720 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2721 aGroup[ j ] = (*lIt)->GetID();
2723 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
2724 << Tolerance << " )";
2727 //=======================================================================
2728 //function : FindCoincidentNodesOnPart
2730 //=======================================================================
2731 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
2732 CORBA::Double Tolerance,
2733 SMESH::array_of_long_array_out GroupsOfNodes)
2736 SMESH::long_array_var aElementsId = theObject->GetIDs();
2738 SMESHDS_Mesh* aMesh = GetMeshDS();
2739 set<const SMDS_MeshNode*> nodes;
2741 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2742 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
2743 for(int i = 0; i < aElementsId->length(); i++) {
2744 CORBA::Long ind = aElementsId[i];
2745 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
2751 for(int i = 0; i < aElementsId->length(); i++) {
2752 CORBA::Long ind = aElementsId[i];
2753 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
2755 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
2756 while ( nIt->more() )
2757 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
2763 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2764 ::SMESH_MeshEditor anEditor( myMesh );
2766 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2768 GroupsOfNodes = new SMESH::array_of_long_array;
2769 GroupsOfNodes->length( aListOfListOfNodes.size() );
2770 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2771 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2772 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2773 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2774 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2775 aGroup.length( aListOfNodes.size() );
2776 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2777 aGroup[ j ] = (*lIt)->GetID();
2779 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
2781 << Tolerance << " )";
2784 //=======================================================================
2785 //function : MergeNodes
2787 //=======================================================================
2789 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
2793 SMESHDS_Mesh* aMesh = GetMeshDS();
2795 TPythonDump aTPythonDump;
2796 aTPythonDump << this << ".MergeNodes([";
2797 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2798 for (int i = 0; i < GroupsOfNodes.length(); i++)
2800 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
2801 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
2802 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
2803 for ( int j = 0; j < aNodeGroup.length(); j++ )
2805 CORBA::Long index = aNodeGroup[ j ];
2806 const SMDS_MeshNode * node = aMesh->FindNode(index);
2808 aListOfNodes.push_back( node );
2810 if ( aListOfNodes.size() < 2 )
2811 aListOfListOfNodes.pop_back();
2813 if ( i > 0 ) aTPythonDump << ", ";
2814 aTPythonDump << aNodeGroup;
2816 ::SMESH_MeshEditor anEditor( myMesh );
2817 anEditor.MergeNodes( aListOfListOfNodes );
2819 aTPythonDump << "])";
2822 //=======================================================================
2823 //function : FindEqualElements
2825 //=======================================================================
2826 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
2827 SMESH::array_of_long_array_out GroupsOfElementsID)
2830 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2831 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
2832 typedef list<int> TListOfIDs;
2833 set<const SMDS_MeshElement*> elems;
2834 SMESH::long_array_var aElementsId = theObject->GetIDs();
2835 SMESHDS_Mesh* aMesh = GetMeshDS();
2837 for(int i = 0; i < aElementsId->length(); i++) {
2838 CORBA::Long anID = aElementsId[i];
2839 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
2845 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2846 ::SMESH_MeshEditor anEditor( myMesh );
2847 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
2849 GroupsOfElementsID = new SMESH::array_of_long_array;
2850 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
2852 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
2853 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
2854 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
2855 TListOfIDs& listOfIDs = *arraysIt;
2856 aGroup.length( listOfIDs.size() );
2857 TListOfIDs::iterator idIt = listOfIDs.begin();
2858 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
2859 aGroup[ k ] = *idIt;
2863 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
2868 //=======================================================================
2869 //function : MergeElements
2871 //=======================================================================
2873 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
2877 TPythonDump aTPythonDump;
2878 aTPythonDump << this << ".MergeElements( [";
2880 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2882 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
2883 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
2884 aListOfListOfElementsID.push_back( list< int >() );
2885 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
2886 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
2887 CORBA::Long id = anElemsIDGroup[ j ];
2888 aListOfElemsID.push_back( id );
2890 if ( aListOfElemsID.size() < 2 )
2891 aListOfListOfElementsID.pop_back();
2892 if ( i > 0 ) aTPythonDump << ", ";
2893 aTPythonDump << anElemsIDGroup;
2896 ::SMESH_MeshEditor anEditor( myMesh );
2897 anEditor.MergeElements(aListOfListOfElementsID);
2899 aTPythonDump << "] )";
2902 //=======================================================================
2903 //function : MergeEqualElements
2905 //=======================================================================
2907 void SMESH_MeshEditor_i::MergeEqualElements()
2911 ::SMESH_MeshEditor anEditor( myMesh );
2912 anEditor.MergeEqualElements();
2914 TPythonDump() << this << ".MergeEqualElements()";
2917 //================================================================================
2919 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
2920 * move the node closest to the point to point's location and return ID of the node
2922 //================================================================================
2924 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
2927 CORBA::Long theNodeID)
2929 // We keep myNodeSearcher until any mesh modification:
2930 // 1) initData() deletes myNodeSearcher at any edition,
2931 // 2) TNodeSearcherDeleter - at any mesh compute event and mesh change
2935 int nodeID = theNodeID;
2936 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
2939 static TNodeSearcherDeleter deleter;
2940 deleter.Set( myMesh );
2941 if ( !myNodeSearcher ) {
2942 ::SMESH_MeshEditor anEditor( myMesh );
2943 myNodeSearcher = anEditor.GetNodeSearcher();
2946 node = myNodeSearcher->FindClosestTo( p );
2949 nodeID = node->GetID();
2950 if ( myPreviewMode ) // make preview data
2952 // in a preview mesh, make edges linked to a node
2953 TPreviewMesh tmpMesh;
2954 TIDSortedElemSet linkedNodes;
2955 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
2956 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
2957 for ( ; nIt != linkedNodes.end(); ++nIt )
2959 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
2960 tmpMesh.Copy( &edge );
2963 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
2965 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
2966 // fill preview data
2967 ::SMESH_MeshEditor anEditor( & tmpMesh );
2968 storeResult( anEditor );
2972 GetMeshDS()->MoveNode(node, x, y, z);
2976 if ( !myPreviewMode ) {
2977 TPythonDump() << "nodeID = " << this
2978 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
2979 << ", " << nodeID << " )";
2985 //=======================================================================
2986 //function : convError
2988 //=======================================================================
2990 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2992 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
2996 RETCASE( SEW_BORDER1_NOT_FOUND );
2997 RETCASE( SEW_BORDER2_NOT_FOUND );
2998 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
2999 RETCASE( SEW_BAD_SIDE_NODES );
3000 RETCASE( SEW_VOLUMES_TO_SPLIT );
3001 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
3002 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
3003 RETCASE( SEW_BAD_SIDE1_NODES );
3004 RETCASE( SEW_BAD_SIDE2_NODES );
3006 return SMESH::SMESH_MeshEditor::SEW_OK;
3009 //=======================================================================
3010 //function : SewFreeBorders
3012 //=======================================================================
3014 SMESH::SMESH_MeshEditor::Sew_Error
3015 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
3016 CORBA::Long SecondNodeID1,
3017 CORBA::Long LastNodeID1,
3018 CORBA::Long FirstNodeID2,
3019 CORBA::Long SecondNodeID2,
3020 CORBA::Long LastNodeID2,
3021 CORBA::Boolean CreatePolygons,
3022 CORBA::Boolean CreatePolyedrs)
3026 SMESHDS_Mesh* aMesh = GetMeshDS();
3028 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3029 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3030 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3031 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3032 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3033 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
3035 if (!aBorderFirstNode ||
3036 !aBorderSecondNode||
3038 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3039 if (!aSide2FirstNode ||
3040 !aSide2SecondNode ||
3042 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3044 TPythonDump() << "error = " << this << ".SewFreeBorders( "
3045 << FirstNodeID1 << ", "
3046 << SecondNodeID1 << ", "
3047 << LastNodeID1 << ", "
3048 << FirstNodeID2 << ", "
3049 << SecondNodeID2 << ", "
3050 << LastNodeID2 << ", "
3051 << CreatePolygons<< ", "
3052 << CreatePolyedrs<< " )";
3054 ::SMESH_MeshEditor anEditor( myMesh );
3055 SMESH::SMESH_MeshEditor::Sew_Error error =
3056 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3066 storeResult(anEditor);
3072 //=======================================================================
3073 //function : SewConformFreeBorders
3075 //=======================================================================
3077 SMESH::SMESH_MeshEditor::Sew_Error
3078 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3079 CORBA::Long SecondNodeID1,
3080 CORBA::Long LastNodeID1,
3081 CORBA::Long FirstNodeID2,
3082 CORBA::Long SecondNodeID2)
3086 SMESHDS_Mesh* aMesh = GetMeshDS();
3088 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3089 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3090 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3091 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3092 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3093 const SMDS_MeshNode* aSide2ThirdNode = 0;
3095 if (!aBorderFirstNode ||
3096 !aBorderSecondNode||
3098 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3099 if (!aSide2FirstNode ||
3101 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3103 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
3104 << FirstNodeID1 << ", "
3105 << SecondNodeID1 << ", "
3106 << LastNodeID1 << ", "
3107 << FirstNodeID2 << ", "
3108 << SecondNodeID2 << " )";
3110 ::SMESH_MeshEditor anEditor( myMesh );
3111 SMESH::SMESH_MeshEditor::Sew_Error error =
3112 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3121 storeResult(anEditor);
3127 //=======================================================================
3128 //function : SewBorderToSide
3130 //=======================================================================
3132 SMESH::SMESH_MeshEditor::Sew_Error
3133 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
3134 CORBA::Long SecondNodeIDOnFreeBorder,
3135 CORBA::Long LastNodeIDOnFreeBorder,
3136 CORBA::Long FirstNodeIDOnSide,
3137 CORBA::Long LastNodeIDOnSide,
3138 CORBA::Boolean CreatePolygons,
3139 CORBA::Boolean CreatePolyedrs)
3143 SMESHDS_Mesh* aMesh = GetMeshDS();
3145 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
3146 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
3147 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
3148 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
3149 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
3150 const SMDS_MeshNode* aSide2ThirdNode = 0;
3152 if (!aBorderFirstNode ||
3153 !aBorderSecondNode||
3155 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3156 if (!aSide2FirstNode ||
3158 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
3160 TPythonDump() << "error = " << this << ".SewBorderToSide( "
3161 << FirstNodeIDOnFreeBorder << ", "
3162 << SecondNodeIDOnFreeBorder << ", "
3163 << LastNodeIDOnFreeBorder << ", "
3164 << FirstNodeIDOnSide << ", "
3165 << LastNodeIDOnSide << ", "
3166 << CreatePolygons << ", "
3167 << CreatePolyedrs << ") ";
3169 ::SMESH_MeshEditor anEditor( myMesh );
3170 SMESH::SMESH_MeshEditor::Sew_Error error =
3171 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3181 storeResult(anEditor);
3187 //=======================================================================
3188 //function : SewSideElements
3190 //=======================================================================
3192 SMESH::SMESH_MeshEditor::Sew_Error
3193 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
3194 const SMESH::long_array& IDsOfSide2Elements,
3195 CORBA::Long NodeID1OfSide1ToMerge,
3196 CORBA::Long NodeID1OfSide2ToMerge,
3197 CORBA::Long NodeID2OfSide1ToMerge,
3198 CORBA::Long NodeID2OfSide2ToMerge)
3202 SMESHDS_Mesh* aMesh = GetMeshDS();
3204 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
3205 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
3206 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
3207 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
3209 if (!aFirstNode1ToMerge ||
3210 !aFirstNode2ToMerge )
3211 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
3212 if (!aSecondNode1ToMerge||
3213 !aSecondNode2ToMerge)
3214 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
3216 TIDSortedElemSet aSide1Elems, aSide2Elems;
3217 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
3218 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
3220 TPythonDump() << "error = " << this << ".SewSideElements( "
3221 << IDsOfSide1Elements << ", "
3222 << IDsOfSide2Elements << ", "
3223 << NodeID1OfSide1ToMerge << ", "
3224 << NodeID1OfSide2ToMerge << ", "
3225 << NodeID2OfSide1ToMerge << ", "
3226 << NodeID2OfSide2ToMerge << ")";
3228 ::SMESH_MeshEditor anEditor( myMesh );
3229 SMESH::SMESH_MeshEditor::Sew_Error error =
3230 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
3233 aSecondNode1ToMerge,
3234 aSecondNode2ToMerge));
3236 storeResult(anEditor);
3241 //================================================================================
3243 * \brief Set new nodes for given element
3244 * \param ide - element id
3245 * \param newIDs - new node ids
3246 * \retval CORBA::Boolean - true if result is OK
3248 //================================================================================
3250 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
3251 const SMESH::long_array& newIDs)
3255 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
3256 if(!elem) return false;
3258 int nbn = newIDs.length();
3260 vector<const SMDS_MeshNode*> aNodes(nbn);
3263 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
3266 aNodes[nbn1] = aNode;
3269 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
3270 << ide << ", " << newIDs << " )";
3272 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
3275 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
3278 //================================================================================
3280 * \brief Update myLastCreated* or myPreviewData
3281 * \param anEditor - it contains last modification results
3283 //================================================================================
3285 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
3287 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
3289 list<int> aNodesConnectivity;
3290 typedef map<int, int> TNodesMap;
3293 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
3294 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
3296 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
3297 int nbEdges = aMeshDS->NbEdges();
3298 int nbFaces = aMeshDS->NbFaces();
3299 int nbVolum = aMeshDS->NbVolumes();
3300 switch ( previewType ) {
3301 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
3302 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
3303 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
3306 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
3307 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
3309 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
3311 while ( itMeshElems->more() ) {
3312 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
3313 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
3316 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
3317 while ( itElemNodes->more() ) {
3318 const SMDS_MeshNode* aMeshNode =
3319 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
3320 int aNodeID = aMeshNode->GetID();
3321 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
3322 if ( anIter == nodesMap.end() ) {
3323 // filling the nodes coordinates
3324 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
3325 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
3326 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
3327 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
3330 aNodesConnectivity.push_back(anIter->second);
3333 // filling the elements types
3334 SMDSAbs_ElementType aType;
3336 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
3337 aType = SMDSAbs_Node;
3341 aType = aMeshElem->GetType();
3342 isPoly = aMeshElem->IsPoly();
3345 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
3346 myPreviewData->elementTypes[i].isPoly = isPoly;
3347 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
3351 myPreviewData->nodesXYZ.length( j );
3353 // filling the elements connectivities
3354 list<int>::iterator aConnIter = aNodesConnectivity.begin();
3355 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
3356 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
3357 myPreviewData->elementConnectivities[i] = *aConnIter;
3363 // add new nodes into myLastCreatedNodes
3364 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
3365 myLastCreatedNodes->length(aSeq.Length());
3366 for(int i=0; i<aSeq.Length(); i++)
3367 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
3370 // add new elements into myLastCreatedElems
3371 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
3372 myLastCreatedElems->length(aSeq.Length());
3373 for(int i=0; i<aSeq.Length(); i++)
3374 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
3378 //================================================================================
3380 * Return data of mesh edition preview
3382 //================================================================================
3384 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
3386 return myPreviewData._retn();
3389 //================================================================================
3391 * \brief Returns list of it's IDs of created nodes
3392 * \retval SMESH::long_array* - list of node ID
3394 //================================================================================
3396 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
3398 return myLastCreatedNodes._retn();
3401 //================================================================================
3403 * \brief Returns list of it's IDs of created elements
3404 * \retval SMESH::long_array* - list of elements' ID
3406 //================================================================================
3408 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
3410 return myLastCreatedElems._retn();
3413 //=======================================================================
3414 //function : ConvertToQuadratic
3416 //=======================================================================
3418 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
3420 ::SMESH_MeshEditor anEditor( myMesh );
3421 anEditor.ConvertToQuadratic(theForce3d);
3422 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
3425 //=======================================================================
3426 //function : ConvertFromQuadratic
3428 //=======================================================================
3430 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
3432 ::SMESH_MeshEditor anEditor( myMesh );
3433 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
3434 TPythonDump() << this << ".ConvertFromQuadratic()";
3438 //=======================================================================
3439 //function : makeMesh
3440 //purpose : create a named imported mesh
3441 //=======================================================================
3443 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
3445 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
3446 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
3447 SALOMEDS::Study_var study = gen->GetCurrentStudy();
3448 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
3449 gen->SetName( meshSO, theMeshName, "Mesh" );
3451 SALOMEDS::StudyBuilder_var builder = study->NewBuilder();
3452 SALOMEDS::GenericAttribute_var anAttr
3453 = builder->FindOrCreateAttribute( meshSO, "AttributePixMap" );
3454 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
3456 return mesh._retn();