1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_MeshEditor_i.cxx
24 // Author : Nicolas REJNERI
27 #include "SMESH_MeshEditor_i.hxx"
29 #include "SMDS_MeshEdge.hxx"
30 #include "SMDS_MeshFace.hxx"
31 #include "SMDS_MeshVolume.hxx"
32 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
33 #include "SMESH_MeshEditor.hxx"
34 #include "SMESH_subMeshEventListener.hxx"
35 #include "SMESH_Gen_i.hxx"
36 #include "SMESH_Filter_i.hxx"
37 #include "SMESH_PythonDump.hxx"
39 #include "utilities.h"
40 #include "Utils_ExceptHandlers.hxx"
41 #include "Utils_CorbaException.hxx"
43 #include <BRepAdaptor_Surface.hxx>
44 #include <BRep_Tool.hxx>
45 #include <TopExp_Explorer.hxx>
47 #include <TopoDS_Edge.hxx>
48 #include <TopoDS_Face.hxx>
53 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
57 #include <Standard_Failure.hxx>
60 #include <Standard_ErrorHandler.hxx>
65 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
68 using SMESH::TPythonDump;
72 //=============================================================================
74 * \brief Mesh to apply modifications for preview purposes
76 //=============================================================================
78 struct TPreviewMesh: public SMESH_Mesh
80 SMDSAbs_ElementType myPreviewType; // type to show
82 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
83 _isShapeToMesh = _id =_studyId =_idDoc = 0;
84 _myMeshDS = new SMESHDS_Mesh( _id, true );
85 myPreviewType = previewElements;
88 virtual ~TPreviewMesh() { delete _myMeshDS; }
89 //!< Copy a set of elements
90 void Copy(const TIDSortedElemSet & theElements,
91 TIDSortedElemSet& theCopyElements,
92 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
93 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
95 // loop on theIDsOfElements
96 TIDSortedElemSet::const_iterator eIt = theElements.begin();
97 for ( ; eIt != theElements.end(); ++eIt )
99 const SMDS_MeshElement* anElem = *eIt;
100 if ( !anElem ) continue;
101 SMDSAbs_ElementType type = anElem->GetType();
102 if ( type == theAvoidType ||
103 ( theSelectType != SMDSAbs_All && type != theSelectType ))
106 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
107 theCopyElements.insert( theCopyElements.end(), anElemCopy );
111 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
113 // copy element nodes
114 int anElemNbNodes = anElem->NbNodes();
115 vector< int > anElemNodesID( anElemNbNodes ) ;
116 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
117 for ( int i = 0; itElemNodes->more(); i++)
119 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
121 anElemNodesID[i] = anElemNode->GetID();
124 // creates a corresponding element on copied nodes
125 SMDS_MeshElement* anElemCopy = 0;
126 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
128 const SMDS_PolyhedralVolumeOfNodes* ph =
129 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
131 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
132 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
135 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
142 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
144 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
145 anElemNode->GetID());
147 };// struct TPreviewMesh
149 static SMESH_NodeSearcher * myNodeSearcher = 0;
151 //=============================================================================
153 * \brief Deleter of myNodeSearcher at any compute event occured
155 //=============================================================================
157 struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
161 TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
163 //!< Delete myNodeSearcher
166 if ( myNodeSearcher ) { delete myNodeSearcher; myNodeSearcher = 0; }
168 typedef map < int, SMESH_subMesh * > TDependsOnMap;
169 //!< The meshod called by submesh: do my main job
170 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
171 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
173 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
175 Unset( sm->GetFather() );
178 //!< set self on all submeshes and delete myNodeSearcher if other mesh is set
179 void Set(SMESH_Mesh* mesh)
181 if ( myMesh && myMesh != mesh ) {
186 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
187 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
188 TDependsOnMap::const_iterator sm;
189 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
190 sm->second->SetEventListener( this, 0, sm->second );
193 //!< delete self from all submeshes
194 void Unset(SMESH_Mesh* mesh)
196 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
197 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
198 TDependsOnMap::const_iterator sm;
199 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
200 sm->second->DeleteEventListener( this );
205 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
207 TCollection_AsciiString typeStr;
208 switch ( theMirrorType ) {
209 case SMESH::SMESH_MeshEditor::POINT:
210 typeStr = "SMESH.SMESH_MeshEditor.POINT";
212 case SMESH::SMESH_MeshEditor::AXIS:
213 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
216 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
222 //=============================================================================
226 //=============================================================================
228 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
231 myMesh = & theMesh->GetImpl();
232 myPreviewMode = isPreview;
235 //================================================================================
239 //================================================================================
241 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
245 //================================================================================
247 * \brief Clear members
249 //================================================================================
251 void SMESH_MeshEditor_i::initData()
253 if ( myPreviewMode ) {
254 myPreviewData = new SMESH::MeshPreviewStruct();
257 myLastCreatedElems = new SMESH::long_array();
258 myLastCreatedNodes = new SMESH::long_array();
259 TNodeSearcherDeleter::Delete();
263 //=============================================================================
267 //=============================================================================
270 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
274 ::SMESH_MeshEditor anEditor( myMesh );
277 for (int i = 0; i < IDsOfElements.length(); i++)
278 IdList.push_back( IDsOfElements[i] );
280 // Update Python script
281 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
283 TPythonDump() << "print 'RemoveElements: ', isDone";
286 return anEditor.Remove( IdList, false );
289 //=============================================================================
293 //=============================================================================
295 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
299 ::SMESH_MeshEditor anEditor( myMesh );
301 for (int i = 0; i < IDsOfNodes.length(); i++)
302 IdList.push_back( IDsOfNodes[i] );
304 // Update Python script
305 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
307 TPythonDump() << "print 'RemoveNodes: ', isDone";
310 return anEditor.Remove( IdList, true );
313 //=============================================================================
317 //=============================================================================
319 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
323 int NbNodes = IDsOfNodes.length();
324 SMDS_MeshElement* elem = 0;
327 CORBA::Long index1 = IDsOfNodes[0];
328 CORBA::Long index2 = IDsOfNodes[1];
329 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
331 // Update Python script
332 TPythonDump() << "edge = " << this << ".AddEdge([ "
333 << index1 << ", " << index2 <<" ])";
336 CORBA::Long n1 = IDsOfNodes[0];
337 CORBA::Long n2 = IDsOfNodes[1];
338 CORBA::Long n12 = IDsOfNodes[2];
339 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
340 GetMeshDS()->FindNode(n2),
341 GetMeshDS()->FindNode(n12));
342 // Update Python script
343 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
344 <<n1<<", "<<n2<<", "<<n12<<" ])";
348 return elem->GetID();
353 //=============================================================================
357 //=============================================================================
359 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
360 CORBA::Double y, CORBA::Double z)
364 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
366 // Update Python script
367 TPythonDump() << "nodeID = " << this << ".AddNode( "
368 << x << ", " << y << ", " << z << " )";
373 //=============================================================================
377 //=============================================================================
379 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
383 int NbNodes = IDsOfNodes.length();
389 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
390 for (int i = 0; i < NbNodes; i++)
391 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
393 SMDS_MeshElement* elem = 0;
395 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
397 else if (NbNodes == 4) {
398 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
400 else if (NbNodes == 6) {
401 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
404 else if (NbNodes == 8) {
405 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
406 nodes[4], nodes[5], nodes[6], nodes[7]);
409 // Update Python script
410 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
413 return elem->GetID();
418 //=============================================================================
422 //=============================================================================
423 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
424 (const SMESH::long_array & IDsOfNodes)
428 int NbNodes = IDsOfNodes.length();
429 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
430 for (int i = 0; i < NbNodes; i++)
431 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
433 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
435 // Update Python script
436 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
438 TPythonDump() << "print 'AddPolygonalFace: ', faceID";
442 return elem->GetID();
447 //=============================================================================
451 //=============================================================================
453 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
457 int NbNodes = IDsOfNodes.length();
458 vector< const SMDS_MeshNode*> n(NbNodes);
459 for(int i=0;i<NbNodes;i++)
460 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
462 SMDS_MeshElement* elem = 0;
465 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
466 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
467 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
468 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
469 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
470 n[6],n[7],n[8],n[9]);
472 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
473 n[7],n[8],n[9],n[10],n[11],n[12]);
475 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
476 n[9],n[10],n[11],n[12],n[13],n[14]);
478 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
479 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
480 n[15],n[16],n[17],n[18],n[19]);
484 // Update Python script
485 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
487 TPythonDump() << "print 'AddVolume: ', volID";
491 return elem->GetID();
496 //=============================================================================
498 * AddPolyhedralVolume
500 //=============================================================================
501 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume
502 (const SMESH::long_array & IDsOfNodes,
503 const SMESH::long_array & Quantities)
507 int NbNodes = IDsOfNodes.length();
508 std::vector<const SMDS_MeshNode*> n (NbNodes);
509 for (int i = 0; i < NbNodes; i++)
510 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
512 int NbFaces = Quantities.length();
513 std::vector<int> q (NbFaces);
514 for (int j = 0; j < NbFaces; j++)
515 q[j] = Quantities[j];
517 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
519 // Update Python script
520 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
521 << IDsOfNodes << ", " << Quantities << " )";
523 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
527 return elem->GetID();
532 //=============================================================================
534 * AddPolyhedralVolumeByFaces
536 //=============================================================================
537 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
538 (const SMESH::long_array & IdsOfFaces)
542 int NbFaces = IdsOfFaces.length();
543 std::vector<const SMDS_MeshNode*> poly_nodes;
544 std::vector<int> quantities (NbFaces);
546 for (int i = 0; i < NbFaces; i++) {
547 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
548 quantities[i] = aFace->NbNodes();
550 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
552 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
556 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
558 // Update Python script
559 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
560 << IdsOfFaces << " )";
562 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
566 return elem->GetID();
571 //=============================================================================
573 * \brief Bind a node to a vertex
574 * \param NodeID - node ID
575 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
576 * \retval boolean - false if NodeID or VertexID is invalid
578 //=============================================================================
580 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
581 throw (SALOME::SALOME_Exception)
583 Unexpect aCatch(SALOME_SalomeException);
585 SMESHDS_Mesh * mesh = GetMeshDS();
586 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
588 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
590 if ( mesh->MaxShapeIndex() < VertexID )
591 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
593 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
594 if ( shape.ShapeType() != TopAbs_VERTEX )
595 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
597 mesh->SetNodeOnVertex( node, VertexID );
600 //=============================================================================
602 * \brief Store node position on an edge
603 * \param NodeID - node ID
604 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
605 * \param paramOnEdge - parameter on edge where the node is located
606 * \retval boolean - false if any parameter is invalid
608 //=============================================================================
610 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
611 CORBA::Double paramOnEdge)
612 throw (SALOME::SALOME_Exception)
614 Unexpect aCatch(SALOME_SalomeException);
616 SMESHDS_Mesh * mesh = GetMeshDS();
617 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
619 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
621 if ( mesh->MaxShapeIndex() < EdgeID )
622 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
624 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
625 if ( shape.ShapeType() != TopAbs_EDGE )
626 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
629 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
630 if ( paramOnEdge < f || paramOnEdge > l )
631 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
633 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
636 //=============================================================================
638 * \brief Store node position on a face
639 * \param NodeID - node ID
640 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
641 * \param u - U parameter on face where the node is located
642 * \param v - V parameter on face where the node is located
643 * \retval boolean - false if any parameter is invalid
645 //=============================================================================
647 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
648 CORBA::Double u, CORBA::Double v)
649 throw (SALOME::SALOME_Exception)
651 Unexpect aCatch(SALOME_SalomeException);
653 SMESHDS_Mesh * mesh = GetMeshDS();
654 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
656 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
658 if ( mesh->MaxShapeIndex() < FaceID )
659 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
661 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
662 if ( shape.ShapeType() != TopAbs_FACE )
663 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
665 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
666 bool isOut = ( u < surf.FirstUParameter() ||
667 u > surf.LastUParameter() ||
668 v < surf.FirstVParameter() ||
669 v > surf.LastVParameter() );
673 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
674 << " u( " << surf.FirstUParameter()
675 << "," << surf.LastUParameter()
676 << ") v( " << surf.FirstVParameter()
677 << "," << surf.LastVParameter() << ")" );
679 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
682 mesh->SetNodeOnFace( node, FaceID, u, v );
685 //=============================================================================
687 * \brief Bind a node to a solid
688 * \param NodeID - node ID
689 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
690 * \retval boolean - false if NodeID or SolidID is invalid
692 //=============================================================================
694 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
695 throw (SALOME::SALOME_Exception)
697 Unexpect aCatch(SALOME_SalomeException);
699 SMESHDS_Mesh * mesh = GetMeshDS();
700 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
702 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
704 if ( mesh->MaxShapeIndex() < SolidID )
705 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
707 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
708 if ( shape.ShapeType() != TopAbs_SOLID &&
709 shape.ShapeType() != TopAbs_SHELL)
710 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
712 mesh->SetNodeInVolume( node, SolidID );
715 //=============================================================================
717 * \brief Bind an element to a shape
718 * \param ElementID - element ID
719 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
720 * \retval boolean - false if ElementID or ShapeID is invalid
722 //=============================================================================
724 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
726 throw (SALOME::SALOME_Exception)
728 Unexpect aCatch(SALOME_SalomeException);
730 SMESHDS_Mesh * mesh = GetMeshDS();
731 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
733 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
735 if ( mesh->MaxShapeIndex() < ShapeID )
736 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
738 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
739 if ( shape.ShapeType() != TopAbs_EDGE &&
740 shape.ShapeType() != TopAbs_FACE &&
741 shape.ShapeType() != TopAbs_SOLID &&
742 shape.ShapeType() != TopAbs_SHELL )
743 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
745 mesh->SetMeshElementOnShape( elem, ShapeID );
749 //=============================================================================
753 //=============================================================================
755 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
762 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
766 GetMeshDS()->MoveNode(node, x, y, z);
768 // Update Python script
769 TPythonDump() << "isDone = " << this << ".MoveNode( "
770 << NodeID << ", " << x << ", " << y << ", " << z << " )";
775 //=============================================================================
779 //=============================================================================
781 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
786 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
787 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
791 // Update Python script
792 TPythonDump() << "isDone = " << this << ".InverseDiag( "
793 << NodeID1 << ", " << NodeID2 << " )";
795 ::SMESH_MeshEditor aMeshEditor( myMesh );
796 return aMeshEditor.InverseDiag ( n1, n2 );
799 //=============================================================================
803 //=============================================================================
805 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
810 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
811 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
815 // Update Python script
816 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
817 << NodeID1 << ", " << NodeID2 << " )";
819 ::SMESH_MeshEditor aMeshEditor( myMesh );
821 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
823 storeResult(aMeshEditor);
828 //=============================================================================
832 //=============================================================================
834 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
838 ::SMESH_MeshEditor anEditor( myMesh );
839 for (int i = 0; i < IDsOfElements.length(); i++)
841 CORBA::Long index = IDsOfElements[i];
842 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
844 anEditor.Reorient( elem );
846 // Update Python script
847 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
853 //=============================================================================
857 //=============================================================================
859 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
863 SMESH::long_array_var anElementsId = theObject->GetIDs();
864 CORBA::Boolean isDone = Reorient(anElementsId);
866 // Clear python line, created by Reorient()
867 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
868 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
870 // Update Python script
871 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
878 //================================================================================
880 * \brief function for conversion long_array to TIDSortedElemSet
881 * \param IDs - array of IDs
882 * \param aMesh - mesh
883 * \param aMap - collection to fill
884 * \param aType - element type
886 //================================================================================
888 void arrayToSet(const SMESH::long_array & IDs,
889 const SMESHDS_Mesh* aMesh,
890 TIDSortedElemSet& aMap,
891 const SMDSAbs_ElementType aType = SMDSAbs_All )
893 for (int i=0; i<IDs.length(); i++) {
894 CORBA::Long ind = IDs[i];
895 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
896 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
902 //=============================================================================
906 //=============================================================================
907 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
908 SMESH::NumericalFunctor_ptr Criterion,
909 CORBA::Double MaxAngle)
913 SMESHDS_Mesh* aMesh = GetMeshDS();
914 TIDSortedElemSet faces;
915 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
917 SMESH::NumericalFunctor_i* aNumericalFunctor =
918 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
919 SMESH::Controls::NumericalFunctorPtr aCrit;
920 if ( !aNumericalFunctor )
921 aCrit.reset( new SMESH::Controls::AspectRatio() );
923 aCrit = aNumericalFunctor->GetNumericalFunctor();
925 // Update Python script
926 TPythonDump() << "isDone = " << this << ".TriToQuad( "
927 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
929 TPythonDump() << "print 'TriToQuad: ', isDone";
932 ::SMESH_MeshEditor anEditor( myMesh );
934 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
936 storeResult(anEditor);
942 //=============================================================================
946 //=============================================================================
947 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
948 SMESH::NumericalFunctor_ptr Criterion,
949 CORBA::Double MaxAngle)
953 SMESH::long_array_var anElementsId = theObject->GetIDs();
954 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
956 // Clear python line(s), created by TriToQuad()
957 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
958 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
960 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
963 SMESH::NumericalFunctor_i* aNumericalFunctor =
964 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
966 // Update Python script
967 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
968 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
970 TPythonDump() << "print 'TriToQuadObject: ', isDone";
977 //=============================================================================
981 //=============================================================================
982 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
983 SMESH::NumericalFunctor_ptr Criterion)
987 SMESHDS_Mesh* aMesh = GetMeshDS();
988 TIDSortedElemSet faces;
989 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
991 SMESH::NumericalFunctor_i* aNumericalFunctor =
992 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
993 SMESH::Controls::NumericalFunctorPtr aCrit;
994 if ( !aNumericalFunctor )
995 aCrit.reset( new SMESH::Controls::AspectRatio() );
997 aCrit = aNumericalFunctor->GetNumericalFunctor();
1000 // Update Python script
1001 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1003 TPythonDump() << "print 'QuadToTri: ', isDone";
1006 ::SMESH_MeshEditor anEditor( myMesh );
1007 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1009 storeResult(anEditor);
1015 //=============================================================================
1019 //=============================================================================
1020 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1021 SMESH::NumericalFunctor_ptr Criterion)
1025 SMESH::long_array_var anElementsId = theObject->GetIDs();
1026 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1028 // Clear python line(s), created by QuadToTri()
1029 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1030 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1032 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1035 SMESH::NumericalFunctor_i* aNumericalFunctor =
1036 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1038 // Update Python script
1039 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1041 TPythonDump() << "print 'QuadToTriObject: ', isDone";
1048 //=============================================================================
1052 //=============================================================================
1053 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1054 CORBA::Boolean Diag13)
1058 SMESHDS_Mesh* aMesh = GetMeshDS();
1059 TIDSortedElemSet faces;
1060 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1062 // Update Python script
1063 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1064 << IDsOfElements << ", " << Diag13 << " )";
1066 TPythonDump() << "print 'SplitQuad: ', isDone";
1069 ::SMESH_MeshEditor anEditor( myMesh );
1070 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1072 storeResult(anEditor);
1078 //=============================================================================
1082 //=============================================================================
1083 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1084 CORBA::Boolean Diag13)
1088 SMESH::long_array_var anElementsId = theObject->GetIDs();
1089 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1091 // Clear python line(s), created by SplitQuad()
1092 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1093 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1095 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1098 // Update Python script
1099 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1100 << theObject << ", " << Diag13 << " )";
1102 TPythonDump() << "print 'SplitQuadObject: ', isDone";
1109 //=============================================================================
1113 //=============================================================================
1114 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1115 SMESH::NumericalFunctor_ptr Criterion)
1117 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1118 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1120 SMESH::NumericalFunctor_i* aNumericalFunctor =
1121 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1122 SMESH::Controls::NumericalFunctorPtr aCrit;
1123 if (aNumericalFunctor)
1124 aCrit = aNumericalFunctor->GetNumericalFunctor();
1126 aCrit.reset(new SMESH::Controls::AspectRatio());
1128 ::SMESH_MeshEditor anEditor (myMesh);
1129 return anEditor.BestSplit(quad, aCrit);
1135 //=======================================================================
1138 //=======================================================================
1141 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1142 const SMESH::long_array & IDsOfFixedNodes,
1143 CORBA::Long MaxNbOfIterations,
1144 CORBA::Double MaxAspectRatio,
1145 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1147 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1148 MaxAspectRatio, Method, false );
1152 //=======================================================================
1153 //function : SmoothParametric
1155 //=======================================================================
1158 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1159 const SMESH::long_array & IDsOfFixedNodes,
1160 CORBA::Long MaxNbOfIterations,
1161 CORBA::Double MaxAspectRatio,
1162 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1164 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1165 MaxAspectRatio, Method, true );
1169 //=======================================================================
1170 //function : SmoothObject
1172 //=======================================================================
1175 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1176 const SMESH::long_array & IDsOfFixedNodes,
1177 CORBA::Long MaxNbOfIterations,
1178 CORBA::Double MaxAspectRatio,
1179 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1181 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1182 MaxAspectRatio, Method, false);
1186 //=======================================================================
1187 //function : SmoothParametricObject
1189 //=======================================================================
1192 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1193 const SMESH::long_array & IDsOfFixedNodes,
1194 CORBA::Long MaxNbOfIterations,
1195 CORBA::Double MaxAspectRatio,
1196 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1198 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1199 MaxAspectRatio, Method, true);
1203 //=============================================================================
1207 //=============================================================================
1210 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1211 const SMESH::long_array & IDsOfFixedNodes,
1212 CORBA::Long MaxNbOfIterations,
1213 CORBA::Double MaxAspectRatio,
1214 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1219 SMESHDS_Mesh* aMesh = GetMeshDS();
1221 TIDSortedElemSet elements;
1222 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1224 set<const SMDS_MeshNode*> fixedNodes;
1225 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1226 CORBA::Long index = IDsOfFixedNodes[i];
1227 const SMDS_MeshNode * node = aMesh->FindNode(index);
1229 fixedNodes.insert( node );
1231 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1232 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1233 method = ::SMESH_MeshEditor::CENTROIDAL;
1235 ::SMESH_MeshEditor anEditor( myMesh );
1236 anEditor.Smooth(elements, fixedNodes, method,
1237 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1239 storeResult(anEditor);
1241 // Update Python script
1242 TPythonDump() << "isDone = " << this << "."
1243 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1244 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1245 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1246 << "SMESH.SMESH_MeshEditor."
1247 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1248 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1250 TPythonDump() << "print 'Smooth: ', isDone";
1257 //=============================================================================
1261 //=============================================================================
1264 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1265 const SMESH::long_array & IDsOfFixedNodes,
1266 CORBA::Long MaxNbOfIterations,
1267 CORBA::Double MaxAspectRatio,
1268 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1273 SMESH::long_array_var anElementsId = theObject->GetIDs();
1274 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1275 MaxAspectRatio, Method, IsParametric);
1277 // Clear python line(s), created by Smooth()
1278 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1279 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1281 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1284 // Update Python script
1285 TPythonDump() << "isDone = " << this << "."
1286 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1287 << theObject << ", " << IDsOfFixedNodes << ", "
1288 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1289 << "SMESH.SMESH_MeshEditor."
1290 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1291 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1293 TPythonDump() << "print 'SmoothObject: ', isDone";
1300 //=============================================================================
1304 //=============================================================================
1306 void SMESH_MeshEditor_i::RenumberNodes()
1308 // Update Python script
1309 TPythonDump() << this << ".RenumberNodes()";
1311 GetMeshDS()->Renumber( true );
1315 //=============================================================================
1319 //=============================================================================
1321 void SMESH_MeshEditor_i::RenumberElements()
1323 // Update Python script
1324 TPythonDump() << this << ".RenumberElements()";
1326 GetMeshDS()->Renumber( false );
1329 //=======================================================================
1331 * \brief Return groups by their IDs
1333 //=======================================================================
1335 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1339 myMesh_i->CreateGroupServants();
1340 return myMesh_i->GetGroups( *groupIDs );
1343 //=======================================================================
1344 //function : rotationSweep
1346 //=======================================================================
1348 SMESH::ListOfGroups*
1349 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1350 const SMESH::AxisStruct & theAxis,
1351 CORBA::Double theAngleInRadians,
1352 CORBA::Long theNbOfSteps,
1353 CORBA::Double theTolerance,
1354 const bool theMakeGroups)
1358 TIDSortedElemSet inElements, copyElements;
1359 arrayToSet(theIDsOfElements, GetMeshDS(), inElements);
1361 TIDSortedElemSet* workElements = & inElements;
1362 TPreviewMesh tmpMesh( SMDSAbs_Face );
1363 SMESH_Mesh* mesh = 0;
1364 bool makeWalls=true;
1365 if ( myPreviewMode )
1367 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1368 tmpMesh.Copy( inElements, copyElements, select, avoid );
1370 workElements = & copyElements;
1371 //makeWalls = false;
1378 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1379 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1381 ::SMESH_MeshEditor anEditor( mesh );
1382 ::SMESH_MeshEditor::PGroupIDs groupIds =
1383 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1384 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1385 storeResult(anEditor);
1387 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1390 //=======================================================================
1391 //function : RotationSweep
1393 //=======================================================================
1395 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1396 const SMESH::AxisStruct & theAxis,
1397 CORBA::Double theAngleInRadians,
1398 CORBA::Long theNbOfSteps,
1399 CORBA::Double theTolerance)
1401 if ( !myPreviewMode ) {
1402 TPythonDump() << "axis = " << theAxis;
1403 TPythonDump() << this << ".RotationSweep( "
1406 << theAngleInRadians << ", "
1407 << theNbOfSteps << ", "
1408 << theTolerance << " )";
1410 rotationSweep(theIDsOfElements,
1418 //=======================================================================
1419 //function : RotationSweepMakeGroups
1421 //=======================================================================
1423 SMESH::ListOfGroups*
1424 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1425 const SMESH::AxisStruct& theAxis,
1426 CORBA::Double theAngleInRadians,
1427 CORBA::Long theNbOfSteps,
1428 CORBA::Double theTolerance)
1430 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1436 if ( !myPreviewMode ) {
1437 TPythonDump()<< "axis = " << theAxis;
1438 TPythonDump aPythonDump;
1439 DumpGroupsList(aPythonDump,aGroups);
1440 aPythonDump<< this << ".RotationSweepMakeGroups( "
1443 << theAngleInRadians << ", "
1444 << theNbOfSteps << ", "
1445 << theTolerance << " )";
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 SMESH::long_array_var anElementsId = theObject->GetIDs();
1492 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1498 if ( !myPreviewMode ) {
1499 TPythonDump() << "axis = " << theAxis;
1500 TPythonDump aPythonDump;
1501 DumpGroupsList(aPythonDump,aGroups);
1502 aPythonDump<< this << ".RotationSweepObjectMakeGroups( "
1505 << theAngleInRadians << ", "
1506 << theNbOfSteps << ", "
1507 << theTolerance << " )";
1513 //=======================================================================
1514 //function : extrusionSweep
1516 //=======================================================================
1518 SMESH::ListOfGroups*
1519 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1520 const SMESH::DirStruct & theStepVector,
1521 CORBA::Long theNbOfSteps,
1522 const bool theMakeGroups,
1523 const SMDSAbs_ElementType theElementType)
1531 TIDSortedElemSet elements;
1532 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1534 const SMESH::PointStruct * P = &theStepVector.PS;
1535 gp_Vec stepVec( P->x, P->y, P->z );
1537 TElemOfElemListMap aHystory;
1538 ::SMESH_MeshEditor anEditor( myMesh );
1539 ::SMESH_MeshEditor::PGroupIDs groupIds =
1540 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1542 storeResult(anEditor);
1544 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1546 } catch(Standard_Failure) {
1547 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1548 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1553 //=======================================================================
1554 //function : ExtrusionSweep
1556 //=======================================================================
1558 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1559 const SMESH::DirStruct & theStepVector,
1560 CORBA::Long theNbOfSteps)
1562 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1563 if ( !myPreviewMode ) {
1564 TPythonDump() << "stepVector = " << theStepVector;
1565 TPythonDump() << this << ".ExtrusionSweep( "
1566 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1571 //=======================================================================
1572 //function : ExtrusionSweepObject
1574 //=======================================================================
1576 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1577 const SMESH::DirStruct & theStepVector,
1578 CORBA::Long theNbOfSteps)
1580 SMESH::long_array_var anElementsId = theObject->GetIDs();
1581 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1582 if ( !myPreviewMode ) {
1583 TPythonDump() << "stepVector = " << theStepVector;
1584 TPythonDump() << this << ".ExtrusionSweepObject( "
1585 << theObject << ", stepVector, " << theNbOfSteps << " )";
1589 //=======================================================================
1590 //function : ExtrusionSweepObject1D
1592 //=======================================================================
1594 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1595 const SMESH::DirStruct & theStepVector,
1596 CORBA::Long theNbOfSteps)
1598 SMESH::long_array_var anElementsId = theObject->GetIDs();
1599 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1600 if ( !myPreviewMode ) {
1601 TPythonDump() << "stepVector = " << theStepVector;
1602 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1603 << theObject << ", stepVector, " << theNbOfSteps << " )";
1607 //=======================================================================
1608 //function : ExtrusionSweepObject2D
1610 //=======================================================================
1612 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1613 const SMESH::DirStruct & theStepVector,
1614 CORBA::Long theNbOfSteps)
1616 SMESH::long_array_var anElementsId = theObject->GetIDs();
1617 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1618 if ( !myPreviewMode ) {
1619 TPythonDump() << "stepVector = " << theStepVector;
1620 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1621 << theObject << ", stepVector, " << theNbOfSteps << " )";
1625 //=======================================================================
1626 //function : ExtrusionSweepMakeGroups
1628 //=======================================================================
1630 SMESH::ListOfGroups*
1631 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1632 const SMESH::DirStruct& theStepVector,
1633 CORBA::Long theNbOfSteps)
1635 SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1637 if ( !myPreviewMode ) {
1638 TPythonDump() << "stepVector = " << theStepVector;
1639 TPythonDump aPythonDump;
1640 DumpGroupsList(aPythonDump,aGroups);
1641 aPythonDump << this << ".ExtrusionSweepMakeGroups( "
1642 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1646 //=======================================================================
1647 //function : ExtrusionSweepObjectMakeGroups
1649 //=======================================================================
1651 SMESH::ListOfGroups*
1652 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1653 const SMESH::DirStruct& theStepVector,
1654 CORBA::Long theNbOfSteps)
1656 SMESH::long_array_var anElementsId = theObject->GetIDs();
1657 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1659 if ( !myPreviewMode ) {
1660 TPythonDump() << "stepVector = " << theStepVector;
1661 TPythonDump aPythonDump;
1662 DumpGroupsList(aPythonDump,aGroups);
1663 aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( "
1664 << theObject << ", stepVector, " << theNbOfSteps << " )";
1669 //=======================================================================
1670 //function : ExtrusionSweepObject1DMakeGroups
1672 //=======================================================================
1674 SMESH::ListOfGroups*
1675 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1676 const SMESH::DirStruct& theStepVector,
1677 CORBA::Long theNbOfSteps)
1679 SMESH::long_array_var anElementsId = theObject->GetIDs();
1680 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1681 if ( !myPreviewMode ) {
1682 TPythonDump() << "stepVector = " << theStepVector;
1683 TPythonDump aPythonDump;
1684 DumpGroupsList(aPythonDump,aGroups);
1685 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( "
1686 << theObject << ", stepVector, " << theNbOfSteps << " )";
1691 //=======================================================================
1692 //function : ExtrusionSweepObject2DMakeGroups
1694 //=======================================================================
1696 SMESH::ListOfGroups*
1697 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1698 const SMESH::DirStruct& theStepVector,
1699 CORBA::Long theNbOfSteps)
1701 SMESH::long_array_var anElementsId = theObject->GetIDs();
1702 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1703 if ( !myPreviewMode ) {
1704 TPythonDump() << "stepVector = " << theStepVector;
1705 TPythonDump aPythonDump;
1706 DumpGroupsList(aPythonDump,aGroups);
1707 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( "
1708 << theObject << ", stepVector, " << theNbOfSteps << " )";
1714 //=======================================================================
1715 //function : advancedExtrusion
1717 //=======================================================================
1719 SMESH::ListOfGroups*
1720 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1721 const SMESH::DirStruct & theStepVector,
1722 CORBA::Long theNbOfSteps,
1723 CORBA::Long theExtrFlags,
1724 CORBA::Double theSewTolerance,
1725 const bool theMakeGroups)
1729 TIDSortedElemSet elements;
1730 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1732 const SMESH::PointStruct * P = &theStepVector.PS;
1733 gp_Vec stepVec( P->x, P->y, P->z );
1735 ::SMESH_MeshEditor anEditor( myMesh );
1736 TElemOfElemListMap aHystory;
1737 ::SMESH_MeshEditor::PGroupIDs groupIds =
1738 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1739 theMakeGroups, theExtrFlags, theSewTolerance);
1740 storeResult(anEditor);
1742 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1745 //=======================================================================
1746 //function : AdvancedExtrusion
1748 //=======================================================================
1750 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1751 const SMESH::DirStruct & theStepVector,
1752 CORBA::Long theNbOfSteps,
1753 CORBA::Long theExtrFlags,
1754 CORBA::Double theSewTolerance)
1756 if ( !myPreviewMode ) {
1757 TPythonDump() << "stepVector = " << theStepVector;
1758 TPythonDump() << this << ".AdvancedExtrusion("
1761 << theNbOfSteps << ","
1762 << theExtrFlags << ", "
1763 << theSewTolerance << " )";
1765 advancedExtrusion( theIDsOfElements,
1773 //=======================================================================
1774 //function : AdvancedExtrusionMakeGroups
1776 //=======================================================================
1778 SMESH::ListOfGroups*
1779 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1780 const SMESH::DirStruct& theStepVector,
1781 CORBA::Long theNbOfSteps,
1782 CORBA::Long theExtrFlags,
1783 CORBA::Double theSewTolerance)
1785 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
1792 if ( !myPreviewMode ) {
1793 TPythonDump() << "stepVector = " << theStepVector;
1794 TPythonDump aPythonDump;
1795 DumpGroupsList(aPythonDump,aGroups);
1796 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
1799 << theNbOfSteps << ","
1800 << theExtrFlags << ", "
1801 << theSewTolerance << " )";
1807 //================================================================================
1809 * \brief Convert extrusion error to IDL enum
1811 //================================================================================
1813 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1815 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1819 RETCASE( EXTR_NO_ELEMENTS );
1820 RETCASE( EXTR_PATH_NOT_EDGE );
1821 RETCASE( EXTR_BAD_PATH_SHAPE );
1822 RETCASE( EXTR_BAD_STARTING_NODE );
1823 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1824 RETCASE( EXTR_CANT_GET_TANGENT );
1826 return SMESH::SMESH_MeshEditor::EXTR_OK;
1830 //=======================================================================
1831 //function : extrusionAlongPath
1833 //=======================================================================
1835 SMESH::ListOfGroups*
1836 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1837 SMESH::SMESH_Mesh_ptr thePathMesh,
1838 GEOM::GEOM_Object_ptr thePathShape,
1839 CORBA::Long theNodeStart,
1840 CORBA::Boolean theHasAngles,
1841 const SMESH::double_array & theAngles,
1842 CORBA::Boolean theHasRefPoint,
1843 const SMESH::PointStruct & theRefPoint,
1844 const bool theMakeGroups,
1845 SMESH::SMESH_MeshEditor::Extrusion_Error & theError)
1849 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1850 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1853 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1855 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1856 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1858 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
1859 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1863 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1865 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1869 TIDSortedElemSet elements;
1870 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1872 list<double> angles;
1873 for (int i = 0; i < theAngles.length(); i++) {
1874 angles.push_back( theAngles[i] );
1877 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1879 int nbOldGroups = myMesh->NbGroup();
1881 ::SMESH_MeshEditor anEditor( myMesh );
1882 ::SMESH_MeshEditor::Extrusion_Error error =
1883 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1884 theHasAngles, angles,
1885 theHasRefPoint, refPnt, theMakeGroups );
1886 storeResult(anEditor);
1887 theError = convExtrError( error );
1889 if ( theMakeGroups ) {
1890 list<int> groupIDs = myMesh->GetGroupIds();
1891 list<int>::iterator newBegin = groupIDs.begin();
1892 std::advance( newBegin, nbOldGroups ); // skip old groups
1893 groupIDs.erase( groupIDs.begin(), newBegin );
1894 return getGroups( & groupIDs );
1899 //=======================================================================
1900 //function : ExtrusionAlongPath
1902 //=======================================================================
1904 SMESH::SMESH_MeshEditor::Extrusion_Error
1905 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1906 SMESH::SMESH_Mesh_ptr thePathMesh,
1907 GEOM::GEOM_Object_ptr thePathShape,
1908 CORBA::Long theNodeStart,
1909 CORBA::Boolean theHasAngles,
1910 const SMESH::double_array & theAngles,
1911 CORBA::Boolean theHasRefPoint,
1912 const SMESH::PointStruct & theRefPoint)
1914 if ( !myPreviewMode ) {
1915 TPythonDump() << "rotAngles = " << theAngles;
1917 if ( theHasRefPoint )
1918 TPythonDump() << "refPoint = SMESH.PointStruct( "
1919 << theRefPoint.x << ", "
1920 << theRefPoint.y << ", "
1921 << theRefPoint.z << " )";
1923 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1925 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
1926 << theIDsOfElements << ", "
1927 << thePathMesh << ", "
1928 << thePathShape << ", "
1929 << theNodeStart << ", "
1930 << theHasAngles << ", "
1931 << "rotAngles" << ", "
1932 << theHasRefPoint << ", refPoint )";
1934 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1935 extrusionAlongPath( theIDsOfElements,
1948 //=======================================================================
1949 //function : ExtrusionAlongPathObject
1951 //=======================================================================
1953 SMESH::SMESH_MeshEditor::Extrusion_Error
1954 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
1955 SMESH::SMESH_Mesh_ptr thePathMesh,
1956 GEOM::GEOM_Object_ptr thePathShape,
1957 CORBA::Long theNodeStart,
1958 CORBA::Boolean theHasAngles,
1959 const SMESH::double_array & theAngles,
1960 CORBA::Boolean theHasRefPoint,
1961 const SMESH::PointStruct & theRefPoint)
1963 if ( !myPreviewMode ) {
1964 TPythonDump() << "rotAngles = " << theAngles;
1966 if ( theHasRefPoint )
1967 TPythonDump() << "refPoint = SMESH.PointStruct( "
1968 << theRefPoint.x << ", "
1969 << theRefPoint.y << ", "
1970 << theRefPoint.z << " )";
1972 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1974 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
1975 << theObject << ", "
1976 << thePathMesh << ", "
1977 << thePathShape << ", "
1978 << theNodeStart << ", "
1979 << theHasAngles << ", "
1980 << "rotAngles" << ", "
1981 << theHasRefPoint << ", refPoint )";
1983 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1984 SMESH::long_array_var anElementsId = theObject->GetIDs();
1985 extrusionAlongPath( anElementsId,
1999 //=======================================================================
2000 //function : ExtrusionAlongPathMakeGroups
2002 //=======================================================================
2004 SMESH::ListOfGroups*
2005 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2006 SMESH::SMESH_Mesh_ptr thePathMesh,
2007 GEOM::GEOM_Object_ptr thePathShape,
2008 CORBA::Long theNodeStart,
2009 CORBA::Boolean theHasAngles,
2010 const SMESH::double_array& theAngles,
2011 CORBA::Boolean theHasRefPoint,
2012 const SMESH::PointStruct& theRefPoint,
2013 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2015 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2025 if ( !myPreviewMode ) {
2026 TPythonDump() << "rotAngles = " << theAngles;
2028 if ( theHasRefPoint )
2029 TPythonDump() << "refPoint = SMESH.PointStruct( "
2030 << theRefPoint.x << ", "
2031 << theRefPoint.y << ", "
2032 << theRefPoint.z << " )";
2034 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2036 bool isDumpGroups = aGroups && aGroups->length() > 0;
2037 TPythonDump aPythonDump;
2039 aPythonDump << "("<<aGroups;
2042 aPythonDump << ", error)";
2044 aPythonDump <<"error";
2046 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2047 << theIDsOfElements << ", "
2048 << thePathMesh << ", "
2049 << thePathShape << ", "
2050 << theNodeStart << ", "
2051 << theHasAngles << ", "
2052 << "rotAngles" << ", "
2053 << theHasRefPoint << ", refPoint )";
2058 //=======================================================================
2059 //function : ExtrusionAlongPathObjectMakeGroups
2061 //=======================================================================
2063 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2064 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2065 SMESH::SMESH_Mesh_ptr thePathMesh,
2066 GEOM::GEOM_Object_ptr thePathShape,
2067 CORBA::Long theNodeStart,
2068 CORBA::Boolean theHasAngles,
2069 const SMESH::double_array& theAngles,
2070 CORBA::Boolean theHasRefPoint,
2071 const SMESH::PointStruct& theRefPoint,
2072 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2074 SMESH::long_array_var anElementsId = theObject->GetIDs();
2075 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2086 if ( !myPreviewMode ) {
2087 TPythonDump() << "rotAngles = " << theAngles;
2089 if ( theHasRefPoint )
2090 TPythonDump() << "refPoint = SMESH.PointStruct( "
2091 << theRefPoint.x << ", "
2092 << theRefPoint.y << ", "
2093 << theRefPoint.z << " )";
2095 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2097 bool isDumpGroups = aGroups && aGroups->length() > 0;
2098 TPythonDump aPythonDump;
2100 aPythonDump << "("<<aGroups;
2103 aPythonDump << ", error)";
2105 aPythonDump <<"error";
2107 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2108 << theObject << ", "
2109 << thePathMesh << ", "
2110 << thePathShape << ", "
2111 << theNodeStart << ", "
2112 << theHasAngles << ", "
2113 << "rotAngles" << ", "
2114 << theHasRefPoint << ", refPoint )";
2119 //================================================================================
2121 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2122 * of given angles along path steps
2123 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2124 * which proceeds the extrusion
2125 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2126 * is used to define the sub-mesh for the path
2128 //================================================================================
2130 SMESH::double_array*
2131 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2132 GEOM::GEOM_Object_ptr thePathShape,
2133 const SMESH::double_array & theAngles)
2135 SMESH::double_array_var aResult = new SMESH::double_array();
2136 int nbAngles = theAngles.length();
2137 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2139 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2140 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2141 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2142 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2143 return aResult._retn();
2144 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2145 if ( nbSteps == nbAngles )
2147 aResult.inout() = theAngles;
2151 aResult->length( nbSteps );
2152 double rAn2St = double( nbAngles ) / double( nbSteps );
2153 double angPrev = 0, angle;
2154 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2156 double angCur = rAn2St * ( iSt+1 );
2157 double angCurFloor = floor( angCur );
2158 double angPrevFloor = floor( angPrev );
2159 if ( angPrevFloor == angCurFloor )
2160 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2163 int iP = int( angPrevFloor );
2164 double angPrevCeil = ceil(angPrev);
2165 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2167 int iC = int( angCurFloor );
2168 if ( iC < nbAngles )
2169 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2171 iP = int( angPrevCeil );
2173 angle += theAngles[ iC ];
2175 aResult[ iSt ] = angle;
2180 // Update Python script
2181 TPythonDump() << "rotAngles = " << theAngles;
2182 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2183 << thePathMesh << ", "
2184 << thePathShape << ", "
2187 return aResult._retn();
2191 //=======================================================================
2194 //=======================================================================
2196 SMESH::ListOfGroups*
2197 SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
2198 const SMESH::AxisStruct & theAxis,
2199 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2200 CORBA::Boolean theCopy,
2201 const bool theMakeGroups,
2202 ::SMESH_Mesh* theTargetMesh)
2206 TIDSortedElemSet elements;
2207 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2209 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2210 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2213 switch ( theMirrorType ) {
2214 case SMESH::SMESH_MeshEditor::POINT:
2215 aTrsf.SetMirror( P );
2217 case SMESH::SMESH_MeshEditor::AXIS:
2218 aTrsf.SetMirror( gp_Ax1( P, V ));
2221 aTrsf.SetMirror( gp_Ax2( P, V ));
2224 ::SMESH_MeshEditor anEditor( myMesh );
2225 ::SMESH_MeshEditor::PGroupIDs groupIds =
2226 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2229 storeResult(anEditor);
2231 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2234 //=======================================================================
2237 //=======================================================================
2239 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2240 const SMESH::AxisStruct & theAxis,
2241 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2242 CORBA::Boolean theCopy)
2244 if ( !myPreviewMode ) {
2245 TPythonDump() << this << ".Mirror( "
2246 << theIDsOfElements << ", "
2248 << mirrorTypeName(theMirrorType) << ", "
2251 mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2255 //=======================================================================
2256 //function : MirrorObject
2258 //=======================================================================
2260 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2261 const SMESH::AxisStruct & theAxis,
2262 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2263 CORBA::Boolean theCopy)
2265 if ( !myPreviewMode ) {
2266 TPythonDump() << this << ".MirrorObject( "
2267 << theObject << ", "
2269 << mirrorTypeName(theMirrorType) << ", "
2272 SMESH::long_array_var anElementsId = theObject->GetIDs();
2273 mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2276 //=======================================================================
2277 //function : MirrorMakeGroups
2279 //=======================================================================
2281 SMESH::ListOfGroups*
2282 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2283 const SMESH::AxisStruct& theMirror,
2284 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2286 SMESH::ListOfGroups * aGroups = mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2287 if ( !myPreviewMode ) {
2288 TPythonDump()<<"axis = "<<theMirror;
2289 TPythonDump aPythonDump;
2290 DumpGroupsList(aPythonDump,aGroups);
2291 aPythonDump << this << ".MirrorMakeGroups( "
2292 << theIDsOfElements << ", "
2294 << mirrorTypeName(theMirrorType) << " )";
2299 //=======================================================================
2300 //function : MirrorObjectMakeGroups
2302 //=======================================================================
2304 SMESH::ListOfGroups*
2305 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2306 const SMESH::AxisStruct& theMirror,
2307 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2309 SMESH::long_array_var anElementsId = theObject->GetIDs();
2310 SMESH::ListOfGroups * aGroups = mirror(anElementsId, theMirror, theMirrorType, true, true);
2311 if ( !myPreviewMode ) {
2312 TPythonDump()<<"axis = "<<theMirror;
2313 TPythonDump aPythonDump;
2314 DumpGroupsList(aPythonDump,aGroups);
2315 aPythonDump << this << ".MirrorObjectMakeGroups( "
2316 << theObject << ", "
2318 << mirrorTypeName(theMirrorType) << " )";
2323 //=======================================================================
2324 //function : MirrorMakeMesh
2326 //=======================================================================
2328 SMESH::SMESH_Mesh_ptr
2329 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2330 const SMESH::AxisStruct& theMirror,
2331 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2332 CORBA::Boolean theCopyGroups,
2333 const char* theMeshName)
2335 SMESH_Mesh_i* mesh_i;
2336 SMESH::SMESH_Mesh_var mesh;
2337 { // open new scope to dump "MakeMesh" command
2338 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2340 TPythonDump pydump; // to prevent dump at mesh creation
2342 mesh = makeMesh( theMeshName );
2343 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2345 mirror(theIDsOfElements, theMirror, theMirrorType,
2346 false, theCopyGroups, & mesh_i->GetImpl());
2347 mesh_i->CreateGroupServants();
2350 if ( !myPreviewMode ) {
2351 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2352 << theIDsOfElements << ", "
2353 << theMirror << ", "
2354 << mirrorTypeName(theMirrorType) << ", "
2355 << theCopyGroups << ", '"
2356 << theMeshName << "' )";
2361 if(!myPreviewMode && mesh_i)
2362 mesh_i->GetGroups();
2364 return mesh._retn();
2367 //=======================================================================
2368 //function : MirrorObjectMakeMesh
2370 //=======================================================================
2372 SMESH::SMESH_Mesh_ptr
2373 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2374 const SMESH::AxisStruct& theMirror,
2375 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2376 CORBA::Boolean theCopyGroups,
2377 const char* theMeshName)
2379 SMESH_Mesh_i* mesh_i;
2380 SMESH::SMESH_Mesh_var mesh;
2381 { // open new scope to dump "MakeMesh" command
2382 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2384 TPythonDump pydump; // to prevent dump at mesh creation
2386 mesh = makeMesh( theMeshName );
2387 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2389 SMESH::long_array_var anElementsId = theObject->GetIDs();
2390 mirror(anElementsId, theMirror, theMirrorType,
2391 false, theCopyGroups, & mesh_i->GetImpl());
2392 mesh_i->CreateGroupServants();
2395 if ( !myPreviewMode ) {
2396 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
2397 << theObject << ", "
2398 << theMirror << ", "
2399 << mirrorTypeName(theMirrorType) << ", "
2400 << theCopyGroups << ", '"
2401 << theMeshName << "' )";
2406 if(!myPreviewMode && mesh_i)
2407 mesh_i->GetGroups();
2409 return mesh._retn();
2412 //=======================================================================
2413 //function : translate
2415 //=======================================================================
2417 SMESH::ListOfGroups*
2418 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2419 const SMESH::DirStruct & theVector,
2420 CORBA::Boolean theCopy,
2421 const bool theMakeGroups,
2422 ::SMESH_Mesh* theTargetMesh)
2426 TIDSortedElemSet elements;
2427 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2430 const SMESH::PointStruct * P = &theVector.PS;
2431 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2433 ::SMESH_MeshEditor anEditor( myMesh );
2434 ::SMESH_MeshEditor::PGroupIDs groupIds =
2435 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2438 storeResult(anEditor);
2440 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2443 //=======================================================================
2444 //function : Translate
2446 //=======================================================================
2448 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2449 const SMESH::DirStruct & theVector,
2450 CORBA::Boolean theCopy)
2452 if ( !myPreviewMode ) {
2453 TPythonDump() << "vector = " << theVector;
2454 TPythonDump() << this << ".Translate( "
2459 translate(theIDsOfElements,
2465 //=======================================================================
2466 //function : TranslateObject
2468 //=======================================================================
2470 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
2471 const SMESH::DirStruct & theVector,
2472 CORBA::Boolean theCopy)
2474 if ( !myPreviewMode ) {
2475 TPythonDump() << this << ".TranslateObject( "
2480 SMESH::long_array_var anElementsId = theObject->GetIDs();
2481 translate(anElementsId,
2487 //=======================================================================
2488 //function : TranslateMakeGroups
2490 //=======================================================================
2492 SMESH::ListOfGroups*
2493 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
2494 const SMESH::DirStruct& theVector)
2496 SMESH::ListOfGroups * aGroups = translate(theIDsOfElements,theVector,true,true);
2497 if ( !myPreviewMode ) {
2498 TPythonDump() << "vector = " << theVector;
2499 TPythonDump aPythonDump;
2500 DumpGroupsList(aPythonDump,aGroups);
2501 aPythonDump << this << ".TranslateMakeGroups( "
2508 //=======================================================================
2509 //function : TranslateObjectMakeGroups
2511 //=======================================================================
2513 SMESH::ListOfGroups*
2514 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2515 const SMESH::DirStruct& theVector)
2517 SMESH::long_array_var anElementsId = theObject->GetIDs();
2518 SMESH::ListOfGroups * aGroups = translate(anElementsId, theVector, true, true);
2520 if ( !myPreviewMode ) {
2522 TPythonDump() << "vector = " << theVector;
2523 TPythonDump aPythonDump;
2524 DumpGroupsList(aPythonDump,aGroups);
2525 aPythonDump << this << ".TranslateObjectMakeGroups( "
2532 //=======================================================================
2533 //function : TranslateMakeMesh
2535 //=======================================================================
2537 SMESH::SMESH_Mesh_ptr
2538 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
2539 const SMESH::DirStruct& theVector,
2540 CORBA::Boolean theCopyGroups,
2541 const char* theMeshName)
2543 SMESH_Mesh_i* mesh_i;
2544 SMESH::SMESH_Mesh_var mesh;
2546 { // open new scope to dump "MakeMesh" command
2547 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2549 TPythonDump pydump; // to prevent dump at mesh creation
2551 mesh = makeMesh( theMeshName );
2552 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2555 translate(theIDsOfElements, theVector,
2556 false, theCopyGroups, & mesh_i->GetImpl());
2557 mesh_i->CreateGroupServants();
2560 if ( !myPreviewMode ) {
2561 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
2562 << theIDsOfElements << ", "
2563 << theVector << ", "
2564 << theCopyGroups << ", '"
2565 << theMeshName << "' )";
2570 if(!myPreviewMode && mesh_i)
2571 mesh_i->GetGroups();
2573 return mesh._retn();
2576 //=======================================================================
2577 //function : TranslateObjectMakeMesh
2579 //=======================================================================
2581 SMESH::SMESH_Mesh_ptr
2582 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2583 const SMESH::DirStruct& theVector,
2584 CORBA::Boolean theCopyGroups,
2585 const char* theMeshName)
2587 SMESH_Mesh_i* mesh_i;
2588 SMESH::SMESH_Mesh_var mesh;
2589 { // open new scope to dump "MakeMesh" command
2590 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2592 TPythonDump pydump; // to prevent dump at mesh creation
2593 mesh = makeMesh( theMeshName );
2594 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2597 SMESH::long_array_var anElementsId = theObject->GetIDs();
2598 translate(anElementsId, theVector,
2599 false, theCopyGroups, & mesh_i->GetImpl());
2600 mesh_i->CreateGroupServants();
2602 if ( !myPreviewMode ) {
2603 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
2604 << theObject << ", "
2605 << theVector << ", "
2606 << theCopyGroups << ", '"
2607 << theMeshName << "' )";
2612 if(!myPreviewMode && mesh_i)
2613 mesh_i->GetGroups();
2615 return mesh._retn();
2618 //=======================================================================
2621 //=======================================================================
2623 SMESH::ListOfGroups*
2624 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
2625 const SMESH::AxisStruct & theAxis,
2626 CORBA::Double theAngle,
2627 CORBA::Boolean theCopy,
2628 const bool theMakeGroups,
2629 ::SMESH_Mesh* theTargetMesh)
2633 TIDSortedElemSet elements;
2634 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2636 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2637 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2640 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
2642 ::SMESH_MeshEditor anEditor( myMesh );
2643 ::SMESH_MeshEditor::PGroupIDs groupIds =
2644 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2647 storeResult(anEditor);
2649 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2652 //=======================================================================
2655 //=======================================================================
2657 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
2658 const SMESH::AxisStruct & theAxis,
2659 CORBA::Double theAngle,
2660 CORBA::Boolean theCopy)
2662 if ( !myPreviewMode ) {
2663 TPythonDump() << "axis = " << theAxis;
2664 TPythonDump() << this << ".Rotate( "
2670 rotate(theIDsOfElements,
2677 //=======================================================================
2678 //function : RotateObject
2680 //=======================================================================
2682 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
2683 const SMESH::AxisStruct & theAxis,
2684 CORBA::Double theAngle,
2685 CORBA::Boolean theCopy)
2687 if ( !myPreviewMode ) {
2688 TPythonDump() << "axis = " << theAxis;
2689 TPythonDump() << this << ".RotateObject( "
2695 SMESH::long_array_var anElementsId = theObject->GetIDs();
2696 rotate(anElementsId,
2703 //=======================================================================
2704 //function : RotateMakeGroups
2706 //=======================================================================
2708 SMESH::ListOfGroups*
2709 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
2710 const SMESH::AxisStruct& theAxis,
2711 CORBA::Double theAngle)
2713 SMESH::ListOfGroups * aGroups = rotate(theIDsOfElements,theAxis,theAngle,true,true);
2714 if ( !myPreviewMode ) {
2715 TPythonDump() << "axis = " << theAxis;
2716 TPythonDump aPythonDump;
2717 DumpGroupsList(aPythonDump,aGroups);
2718 aPythonDump << this << ".RotateMakeGroups( "
2721 << theAngle << " )";
2726 //=======================================================================
2727 //function : RotateObjectMakeGroups
2729 //=======================================================================
2731 SMESH::ListOfGroups*
2732 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2733 const SMESH::AxisStruct& theAxis,
2734 CORBA::Double theAngle)
2736 SMESH::long_array_var anElementsId = theObject->GetIDs();
2737 SMESH::ListOfGroups * aGroups = rotate(anElementsId,theAxis,theAngle,true,true);
2739 if ( !myPreviewMode ) {
2740 TPythonDump() << "axis = " << theAxis;
2741 TPythonDump aPythonDump;
2742 DumpGroupsList(aPythonDump,aGroups);
2743 aPythonDump << this << ".RotateObjectMakeGroups( "
2746 << theAngle << " )";
2751 //=======================================================================
2752 //function : RotateMakeMesh
2754 //=======================================================================
2756 SMESH::SMESH_Mesh_ptr
2757 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
2758 const SMESH::AxisStruct& theAxis,
2759 CORBA::Double theAngleInRadians,
2760 CORBA::Boolean theCopyGroups,
2761 const char* theMeshName)
2763 SMESH::SMESH_Mesh_var mesh;
2764 SMESH_Mesh_i* mesh_i;
2766 { // open new scope to dump "MakeMesh" command
2767 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2769 TPythonDump pydump; // to prevent dump at mesh creation
2771 mesh = makeMesh( theMeshName );
2772 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2775 rotate(theIDsOfElements, theAxis, theAngleInRadians,
2776 false, theCopyGroups, & mesh_i->GetImpl());
2777 mesh_i->CreateGroupServants();
2779 if ( !myPreviewMode ) {
2780 pydump << mesh << " = " << this << ".RotateMakeMesh( "
2781 << theIDsOfElements << ", "
2783 << theAngleInRadians << ", "
2784 << theCopyGroups << ", '"
2785 << theMeshName << "' )";
2790 if(!myPreviewMode && mesh_i)
2791 mesh_i->GetGroups();
2793 return mesh._retn();
2796 //=======================================================================
2797 //function : RotateObjectMakeMesh
2799 //=======================================================================
2801 SMESH::SMESH_Mesh_ptr
2802 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2803 const SMESH::AxisStruct& theAxis,
2804 CORBA::Double theAngleInRadians,
2805 CORBA::Boolean theCopyGroups,
2806 const char* theMeshName)
2808 SMESH::SMESH_Mesh_var mesh;
2809 SMESH_Mesh_i* mesh_i;
2811 {// open new scope to dump "MakeMesh" command
2812 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2814 TPythonDump pydump; // to prevent dump at mesh creation
2815 mesh = makeMesh( theMeshName );
2816 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2819 SMESH::long_array_var anElementsId = theObject->GetIDs();
2820 rotate(anElementsId, theAxis, theAngleInRadians,
2821 false, theCopyGroups, & mesh_i->GetImpl());
2822 mesh_i->CreateGroupServants();
2824 if ( !myPreviewMode ) {
2825 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
2826 << theObject << ", "
2828 << theAngleInRadians << ", "
2829 << theCopyGroups << ", '"
2830 << theMeshName << "' )";
2835 if(!myPreviewMode && mesh_i)
2836 mesh_i->GetGroups();
2838 return mesh._retn();
2841 //=======================================================================
2842 //function : FindCoincidentNodes
2844 //=======================================================================
2846 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
2847 SMESH::array_of_long_array_out GroupsOfNodes)
2851 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2852 ::SMESH_MeshEditor anEditor( myMesh );
2853 set<const SMDS_MeshNode*> nodes; // no input nodes
2854 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2856 GroupsOfNodes = new SMESH::array_of_long_array;
2857 GroupsOfNodes->length( aListOfListOfNodes.size() );
2858 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2859 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2860 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2861 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2862 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2863 aGroup.length( aListOfNodes.size() );
2864 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2865 aGroup[ j ] = (*lIt)->GetID();
2867 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
2868 << Tolerance << " )";
2871 //=======================================================================
2872 //function : FindCoincidentNodesOnPart
2874 //=======================================================================
2875 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
2876 CORBA::Double Tolerance,
2877 SMESH::array_of_long_array_out GroupsOfNodes)
2880 SMESH::long_array_var aElementsId = theObject->GetIDs();
2882 SMESHDS_Mesh* aMesh = GetMeshDS();
2883 set<const SMDS_MeshNode*> nodes;
2885 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2886 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
2887 for(int i = 0; i < aElementsId->length(); i++) {
2888 CORBA::Long ind = aElementsId[i];
2889 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
2895 for(int i = 0; i < aElementsId->length(); i++) {
2896 CORBA::Long ind = aElementsId[i];
2897 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
2899 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
2900 while ( nIt->more() )
2901 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
2907 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2908 ::SMESH_MeshEditor anEditor( myMesh );
2910 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2912 GroupsOfNodes = new SMESH::array_of_long_array;
2913 GroupsOfNodes->length( aListOfListOfNodes.size() );
2914 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2915 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2916 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2917 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2918 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2919 aGroup.length( aListOfNodes.size() );
2920 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2921 aGroup[ j ] = (*lIt)->GetID();
2923 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
2925 << Tolerance << " )";
2928 //=======================================================================
2929 //function : MergeNodes
2931 //=======================================================================
2933 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
2937 SMESHDS_Mesh* aMesh = GetMeshDS();
2939 TPythonDump aTPythonDump;
2940 aTPythonDump << this << ".MergeNodes([";
2941 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2942 for (int i = 0; i < GroupsOfNodes.length(); i++)
2944 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
2945 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
2946 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
2947 for ( int j = 0; j < aNodeGroup.length(); j++ )
2949 CORBA::Long index = aNodeGroup[ j ];
2950 const SMDS_MeshNode * node = aMesh->FindNode(index);
2952 aListOfNodes.push_back( node );
2954 if ( aListOfNodes.size() < 2 )
2955 aListOfListOfNodes.pop_back();
2957 if ( i > 0 ) aTPythonDump << ", ";
2958 aTPythonDump << aNodeGroup;
2960 ::SMESH_MeshEditor anEditor( myMesh );
2961 anEditor.MergeNodes( aListOfListOfNodes );
2963 aTPythonDump << "])";
2966 //=======================================================================
2967 //function : FindEqualElements
2969 //=======================================================================
2970 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
2971 SMESH::array_of_long_array_out GroupsOfElementsID)
2974 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2975 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
2976 typedef list<int> TListOfIDs;
2977 set<const SMDS_MeshElement*> elems;
2978 SMESH::long_array_var aElementsId = theObject->GetIDs();
2979 SMESHDS_Mesh* aMesh = GetMeshDS();
2981 for(int i = 0; i < aElementsId->length(); i++) {
2982 CORBA::Long anID = aElementsId[i];
2983 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
2989 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2990 ::SMESH_MeshEditor anEditor( myMesh );
2991 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
2993 GroupsOfElementsID = new SMESH::array_of_long_array;
2994 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
2996 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
2997 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
2998 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
2999 TListOfIDs& listOfIDs = *arraysIt;
3000 aGroup.length( listOfIDs.size() );
3001 TListOfIDs::iterator idIt = listOfIDs.begin();
3002 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3003 aGroup[ k ] = *idIt;
3007 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3012 //=======================================================================
3013 //function : MergeElements
3015 //=======================================================================
3017 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3021 TPythonDump aTPythonDump;
3022 aTPythonDump << this << ".MergeElements( [";
3024 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3026 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3027 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3028 aListOfListOfElementsID.push_back( list< int >() );
3029 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3030 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3031 CORBA::Long id = anElemsIDGroup[ j ];
3032 aListOfElemsID.push_back( id );
3034 if ( aListOfElemsID.size() < 2 )
3035 aListOfListOfElementsID.pop_back();
3036 if ( i > 0 ) aTPythonDump << ", ";
3037 aTPythonDump << anElemsIDGroup;
3040 ::SMESH_MeshEditor anEditor( myMesh );
3041 anEditor.MergeElements(aListOfListOfElementsID);
3043 aTPythonDump << "] )";
3046 //=======================================================================
3047 //function : MergeEqualElements
3049 //=======================================================================
3051 void SMESH_MeshEditor_i::MergeEqualElements()
3055 ::SMESH_MeshEditor anEditor( myMesh );
3056 anEditor.MergeEqualElements();
3058 TPythonDump() << this << ".MergeEqualElements()";
3061 //================================================================================
3063 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
3064 * move the node closest to the point to point's location and return ID of the node
3066 //================================================================================
3068 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
3071 CORBA::Long theNodeID)
3073 // We keep myNodeSearcher until any mesh modification:
3074 // 1) initData() deletes myNodeSearcher at any edition,
3075 // 2) TNodeSearcherDeleter - at any mesh compute event and mesh change
3079 int nodeID = theNodeID;
3080 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
3083 static TNodeSearcherDeleter deleter;
3084 deleter.Set( myMesh );
3085 if ( !myNodeSearcher ) {
3086 ::SMESH_MeshEditor anEditor( myMesh );
3087 myNodeSearcher = anEditor.GetNodeSearcher();
3090 node = myNodeSearcher->FindClosestTo( p );
3093 nodeID = node->GetID();
3094 if ( myPreviewMode ) // make preview data
3096 // in a preview mesh, make edges linked to a node
3097 TPreviewMesh tmpMesh;
3098 TIDSortedElemSet linkedNodes;
3099 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3100 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3101 for ( ; nIt != linkedNodes.end(); ++nIt )
3103 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
3104 tmpMesh.Copy( &edge );
3107 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
3109 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
3110 // fill preview data
3111 ::SMESH_MeshEditor anEditor( & tmpMesh );
3112 storeResult( anEditor );
3116 GetMeshDS()->MoveNode(node, x, y, z);
3120 if ( !myPreviewMode ) {
3121 TPythonDump() << "nodeID = " << this
3122 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
3123 << ", " << nodeID << " )";
3129 //=======================================================================
3130 //function : convError
3132 //=======================================================================
3134 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
3136 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
3140 RETCASE( SEW_BORDER1_NOT_FOUND );
3141 RETCASE( SEW_BORDER2_NOT_FOUND );
3142 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
3143 RETCASE( SEW_BAD_SIDE_NODES );
3144 RETCASE( SEW_VOLUMES_TO_SPLIT );
3145 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
3146 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
3147 RETCASE( SEW_BAD_SIDE1_NODES );
3148 RETCASE( SEW_BAD_SIDE2_NODES );
3150 return SMESH::SMESH_MeshEditor::SEW_OK;
3153 //=======================================================================
3154 //function : SewFreeBorders
3156 //=======================================================================
3158 SMESH::SMESH_MeshEditor::Sew_Error
3159 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
3160 CORBA::Long SecondNodeID1,
3161 CORBA::Long LastNodeID1,
3162 CORBA::Long FirstNodeID2,
3163 CORBA::Long SecondNodeID2,
3164 CORBA::Long LastNodeID2,
3165 CORBA::Boolean CreatePolygons,
3166 CORBA::Boolean CreatePolyedrs)
3170 SMESHDS_Mesh* aMesh = GetMeshDS();
3172 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3173 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3174 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3175 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3176 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3177 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
3179 if (!aBorderFirstNode ||
3180 !aBorderSecondNode||
3182 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3183 if (!aSide2FirstNode ||
3184 !aSide2SecondNode ||
3186 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3188 TPythonDump() << "error = " << this << ".SewFreeBorders( "
3189 << FirstNodeID1 << ", "
3190 << SecondNodeID1 << ", "
3191 << LastNodeID1 << ", "
3192 << FirstNodeID2 << ", "
3193 << SecondNodeID2 << ", "
3194 << LastNodeID2 << ", "
3195 << CreatePolygons<< ", "
3196 << CreatePolyedrs<< " )";
3198 ::SMESH_MeshEditor anEditor( myMesh );
3199 SMESH::SMESH_MeshEditor::Sew_Error error =
3200 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3210 storeResult(anEditor);
3216 //=======================================================================
3217 //function : SewConformFreeBorders
3219 //=======================================================================
3221 SMESH::SMESH_MeshEditor::Sew_Error
3222 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3223 CORBA::Long SecondNodeID1,
3224 CORBA::Long LastNodeID1,
3225 CORBA::Long FirstNodeID2,
3226 CORBA::Long SecondNodeID2)
3230 SMESHDS_Mesh* aMesh = GetMeshDS();
3232 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3233 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3234 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3235 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3236 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3237 const SMDS_MeshNode* aSide2ThirdNode = 0;
3239 if (!aBorderFirstNode ||
3240 !aBorderSecondNode||
3242 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3243 if (!aSide2FirstNode ||
3245 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3247 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
3248 << FirstNodeID1 << ", "
3249 << SecondNodeID1 << ", "
3250 << LastNodeID1 << ", "
3251 << FirstNodeID2 << ", "
3252 << SecondNodeID2 << " )";
3254 ::SMESH_MeshEditor anEditor( myMesh );
3255 SMESH::SMESH_MeshEditor::Sew_Error error =
3256 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3265 storeResult(anEditor);
3271 //=======================================================================
3272 //function : SewBorderToSide
3274 //=======================================================================
3276 SMESH::SMESH_MeshEditor::Sew_Error
3277 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
3278 CORBA::Long SecondNodeIDOnFreeBorder,
3279 CORBA::Long LastNodeIDOnFreeBorder,
3280 CORBA::Long FirstNodeIDOnSide,
3281 CORBA::Long LastNodeIDOnSide,
3282 CORBA::Boolean CreatePolygons,
3283 CORBA::Boolean CreatePolyedrs)
3287 SMESHDS_Mesh* aMesh = GetMeshDS();
3289 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
3290 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
3291 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
3292 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
3293 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
3294 const SMDS_MeshNode* aSide2ThirdNode = 0;
3296 if (!aBorderFirstNode ||
3297 !aBorderSecondNode||
3299 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3300 if (!aSide2FirstNode ||
3302 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
3304 TPythonDump() << "error = " << this << ".SewBorderToSide( "
3305 << FirstNodeIDOnFreeBorder << ", "
3306 << SecondNodeIDOnFreeBorder << ", "
3307 << LastNodeIDOnFreeBorder << ", "
3308 << FirstNodeIDOnSide << ", "
3309 << LastNodeIDOnSide << ", "
3310 << CreatePolygons << ", "
3311 << CreatePolyedrs << ") ";
3313 ::SMESH_MeshEditor anEditor( myMesh );
3314 SMESH::SMESH_MeshEditor::Sew_Error error =
3315 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3325 storeResult(anEditor);
3331 //=======================================================================
3332 //function : SewSideElements
3334 //=======================================================================
3336 SMESH::SMESH_MeshEditor::Sew_Error
3337 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
3338 const SMESH::long_array& IDsOfSide2Elements,
3339 CORBA::Long NodeID1OfSide1ToMerge,
3340 CORBA::Long NodeID1OfSide2ToMerge,
3341 CORBA::Long NodeID2OfSide1ToMerge,
3342 CORBA::Long NodeID2OfSide2ToMerge)
3346 SMESHDS_Mesh* aMesh = GetMeshDS();
3348 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
3349 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
3350 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
3351 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
3353 if (!aFirstNode1ToMerge ||
3354 !aFirstNode2ToMerge )
3355 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
3356 if (!aSecondNode1ToMerge||
3357 !aSecondNode2ToMerge)
3358 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
3360 TIDSortedElemSet aSide1Elems, aSide2Elems;
3361 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
3362 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
3364 TPythonDump() << "error = " << this << ".SewSideElements( "
3365 << IDsOfSide1Elements << ", "
3366 << IDsOfSide2Elements << ", "
3367 << NodeID1OfSide1ToMerge << ", "
3368 << NodeID1OfSide2ToMerge << ", "
3369 << NodeID2OfSide1ToMerge << ", "
3370 << NodeID2OfSide2ToMerge << ")";
3372 ::SMESH_MeshEditor anEditor( myMesh );
3373 SMESH::SMESH_MeshEditor::Sew_Error error =
3374 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
3377 aSecondNode1ToMerge,
3378 aSecondNode2ToMerge));
3380 storeResult(anEditor);
3385 //================================================================================
3387 * \brief Set new nodes for given element
3388 * \param ide - element id
3389 * \param newIDs - new node ids
3390 * \retval CORBA::Boolean - true if result is OK
3392 //================================================================================
3394 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
3395 const SMESH::long_array& newIDs)
3399 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
3400 if(!elem) return false;
3402 int nbn = newIDs.length();
3404 vector<const SMDS_MeshNode*> aNodes(nbn);
3407 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
3410 aNodes[nbn1] = aNode;
3413 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
3414 << ide << ", " << newIDs << " )";
3416 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
3419 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
3422 //================================================================================
3424 * \brief Update myLastCreated* or myPreviewData
3425 * \param anEditor - it contains last modification results
3427 //================================================================================
3429 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
3431 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
3433 list<int> aNodesConnectivity;
3434 typedef map<int, int> TNodesMap;
3437 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
3438 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
3440 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
3441 int nbEdges = aMeshDS->NbEdges();
3442 int nbFaces = aMeshDS->NbFaces();
3443 int nbVolum = aMeshDS->NbVolumes();
3444 switch ( previewType ) {
3445 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
3446 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
3447 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
3450 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
3451 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
3453 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
3455 while ( itMeshElems->more() ) {
3456 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
3457 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
3460 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
3461 while ( itElemNodes->more() ) {
3462 const SMDS_MeshNode* aMeshNode =
3463 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
3464 int aNodeID = aMeshNode->GetID();
3465 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
3466 if ( anIter == nodesMap.end() ) {
3467 // filling the nodes coordinates
3468 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
3469 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
3470 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
3471 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
3474 aNodesConnectivity.push_back(anIter->second);
3477 // filling the elements types
3478 SMDSAbs_ElementType aType;
3480 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
3481 aType = SMDSAbs_Node;
3485 aType = aMeshElem->GetType();
3486 isPoly = aMeshElem->IsPoly();
3489 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
3490 myPreviewData->elementTypes[i].isPoly = isPoly;
3491 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
3495 myPreviewData->nodesXYZ.length( j );
3497 // filling the elements connectivities
3498 list<int>::iterator aConnIter = aNodesConnectivity.begin();
3499 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
3500 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
3501 myPreviewData->elementConnectivities[i] = *aConnIter;
3507 // add new nodes into myLastCreatedNodes
3508 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
3509 myLastCreatedNodes->length(aSeq.Length());
3510 for(int i=0; i<aSeq.Length(); i++)
3511 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
3514 // add new elements into myLastCreatedElems
3515 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
3516 myLastCreatedElems->length(aSeq.Length());
3517 for(int i=0; i<aSeq.Length(); i++)
3518 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
3522 //================================================================================
3524 * Return data of mesh edition preview
3526 //================================================================================
3528 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
3530 return myPreviewData._retn();
3533 //================================================================================
3535 * \brief Returns list of it's IDs of created nodes
3536 * \retval SMESH::long_array* - list of node ID
3538 //================================================================================
3540 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
3542 return myLastCreatedNodes._retn();
3545 //================================================================================
3547 * \brief Returns list of it's IDs of created elements
3548 * \retval SMESH::long_array* - list of elements' ID
3550 //================================================================================
3552 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
3554 return myLastCreatedElems._retn();
3557 //=======================================================================
3558 //function : ConvertToQuadratic
3560 //=======================================================================
3562 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
3564 ::SMESH_MeshEditor anEditor( myMesh );
3565 anEditor.ConvertToQuadratic(theForce3d);
3566 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
3569 //=======================================================================
3570 //function : ConvertFromQuadratic
3572 //=======================================================================
3574 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
3576 ::SMESH_MeshEditor anEditor( myMesh );
3577 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
3578 TPythonDump() << this << ".ConvertFromQuadratic()";
3582 //=======================================================================
3583 //function : makeMesh
3584 //purpose : create a named imported mesh
3585 //=======================================================================
3587 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
3589 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
3590 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
3591 SALOMEDS::Study_var study = gen->GetCurrentStudy();
3592 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
3593 gen->SetName( meshSO, theMeshName, "Mesh" );
3595 SALOMEDS::StudyBuilder_var builder = study->NewBuilder();
3596 SALOMEDS::GenericAttribute_var anAttr
3597 = builder->FindOrCreateAttribute( meshSO, "AttributePixMap" );
3598 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
3600 return mesh._retn();
3603 //=======================================================================
3604 //function : DumpGroupsList
3606 //=======================================================================
3607 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
3608 const SMESH::ListOfGroups * theGroupList)
3610 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
3611 if(isDumpGroupList) {
3612 theDumpPython << theGroupList << " = ";
3616 //================================================================================
3618 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
3619 \param theNodes - identifiers of nodes to be doubled
3620 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
3621 nodes. If list of element identifiers is empty then nodes are doubled but
3622 they not assigned to elements
3623 \return TRUE if operation has been completed successfully, FALSE otherwise
3624 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
3626 //================================================================================
3628 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
3629 const SMESH::long_array& theModifiedElems )
3633 ::SMESH_MeshEditor aMeshEditor( myMesh );
3634 list< int > aListOfNodes;
3636 for ( i = 0, n = theNodes.length(); i < n; i++ )
3637 aListOfNodes.push_back( theNodes[ i ] );
3639 list< int > aListOfElems;
3640 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
3641 aListOfElems.push_back( theModifiedElems[ i ] );
3643 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
3645 storeResult( aMeshEditor) ;
3650 //================================================================================
3652 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
3653 This method provided for convenience works as DoubleNodes() described above.
3654 \param theNodeId - identifier of node to be doubled.
3655 \param theModifiedElems - identifiers of elements to be updated.
3656 \return TRUE if operation has been completed successfully, FALSE otherwise
3657 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
3659 //================================================================================
3661 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
3662 const SMESH::long_array& theModifiedElems )
3664 SMESH::long_array_var aNodes = new SMESH::long_array;
3665 aNodes->length( 1 );
3666 aNodes[ 0 ] = theNodeId;
3667 return DoubleNodes( aNodes, theModifiedElems );
3670 //================================================================================
3672 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
3673 This method provided for convenience works as DoubleNodes() described above.
3674 \param theNodes - group of nodes to be doubled.
3675 \param theModifiedElems - group of elements to be updated.
3676 \return TRUE if operation has been completed successfully, FALSE otherwise
3677 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
3679 //================================================================================
3681 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(
3682 SMESH::SMESH_GroupBase_ptr theNodes,
3683 SMESH::SMESH_GroupBase_ptr theModifiedElems )
3685 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
3688 SMESH::long_array_var aNodes = theNodes->GetListOfID();
3689 SMESH::long_array_var aModifiedElems;
3690 if ( !CORBA::is_nil( theModifiedElems ) )
3691 aModifiedElems = theModifiedElems->GetListOfID();
3694 aModifiedElems = new SMESH::long_array;
3695 aModifiedElems->length( 0 );
3698 return DoubleNodes( aNodes, aModifiedElems );
3701 //================================================================================
3703 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
3704 This method provided for convenience works as DoubleNodes() described above.
3705 \param theNodes - list of groups of nodes to be doubled
3706 \param theModifiedElems - list of groups of elements to be updated.
3707 \return TRUE if operation has been completed successfully, FALSE otherwise
3708 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
3710 //================================================================================
3712 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(
3713 const SMESH::ListOfGroups& theNodes,
3714 const SMESH::ListOfGroups& theModifiedElems )
3718 ::SMESH_MeshEditor aMeshEditor( myMesh );
3720 std::list< int > aNodes;
3722 for ( i = 0, n = theNodes.length(); i < n; i++ )
3724 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
3725 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
3727 SMESH::long_array_var aCurr = aGrp->GetListOfID();
3728 for ( j = 0, m = aCurr->length(); j < m; j++ )
3729 aNodes.push_back( aCurr[ j ] );
3733 std::list< int > anElems;
3734 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
3736 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
3737 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
3739 SMESH::long_array_var aCurr = aGrp->GetListOfID();
3740 for ( j = 0, m = aCurr->length(); j < m; j++ )
3741 anElems.push_back( aCurr[ j ] );
3745 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
3747 storeResult( aMeshEditor) ;