1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_MeshEditor_i.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESH_MeshEditor_i.hxx"
31 #include "SMDS_MeshEdge.hxx"
32 #include "SMDS_MeshFace.hxx"
33 #include "SMDS_MeshVolume.hxx"
34 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
35 #include "SMESH_MeshEditor.hxx"
36 #include "SMESH_subMeshEventListener.hxx"
37 #include "SMESH_Gen_i.hxx"
38 #include "SMESH_Filter_i.hxx"
39 #include "SMESH_PythonDump.hxx"
41 #include "utilities.h"
42 #include "Utils_ExceptHandlers.hxx"
43 #include "Utils_CorbaException.hxx"
45 #include <BRepAdaptor_Surface.hxx>
46 #include <BRep_Tool.hxx>
47 #include <TopExp_Explorer.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Face.hxx>
55 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
59 #include <Standard_Failure.hxx>
62 #include <Standard_ErrorHandler.hxx>
67 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
70 using SMESH::TPythonDump;
74 //=============================================================================
76 * \brief Mesh to apply modifications for preview purposes
78 //=============================================================================
80 struct TPreviewMesh: public SMESH_Mesh
82 SMDSAbs_ElementType myPreviewType; // type to show
84 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
85 _isShapeToMesh = _id =_studyId =_idDoc = 0;
86 _myMeshDS = new SMESHDS_Mesh( _id, true );
87 myPreviewType = previewElements;
90 virtual ~TPreviewMesh() { delete _myMeshDS; }
91 //!< Copy a set of elements
92 void Copy(const TIDSortedElemSet & theElements,
93 TIDSortedElemSet& theCopyElements,
94 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
95 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
97 // loop on theIDsOfElements
98 TIDSortedElemSet::const_iterator eIt = theElements.begin();
99 for ( ; eIt != theElements.end(); ++eIt )
101 const SMDS_MeshElement* anElem = *eIt;
102 if ( !anElem ) continue;
103 SMDSAbs_ElementType type = anElem->GetType();
104 if ( type == theAvoidType ||
105 ( theSelectType != SMDSAbs_All && type != theSelectType ))
108 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
109 theCopyElements.insert( theCopyElements.end(), anElemCopy );
113 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
115 // copy element nodes
116 int anElemNbNodes = anElem->NbNodes();
117 vector< int > anElemNodesID( anElemNbNodes ) ;
118 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
119 for ( int i = 0; itElemNodes->more(); i++)
121 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
123 anElemNodesID[i] = anElemNode->GetID();
126 // creates a corresponding element on copied nodes
127 SMDS_MeshElement* anElemCopy = 0;
128 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
130 const SMDS_PolyhedralVolumeOfNodes* ph =
131 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
133 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
134 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
137 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
144 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
146 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
147 anElemNode->GetID());
149 };// struct TPreviewMesh
151 static SMESH_NodeSearcher * myNodeSearcher = 0;
153 //=============================================================================
155 * \brief Deleter of myNodeSearcher at any compute event occured
157 //=============================================================================
159 struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
163 TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
165 //!< Delete myNodeSearcher
168 if ( myNodeSearcher ) { delete myNodeSearcher; myNodeSearcher = 0; }
170 typedef map < int, SMESH_subMesh * > TDependsOnMap;
171 //!< The meshod called by submesh: do my main job
172 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
173 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
175 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
177 Unset( sm->GetFather() );
180 //!< set self on all submeshes and delete myNodeSearcher if other mesh is set
181 void Set(SMESH_Mesh* mesh)
183 if ( myMesh && myMesh != mesh ) {
188 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
189 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
190 TDependsOnMap::const_iterator sm;
191 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
192 sm->second->SetEventListener( this, 0, sm->second );
195 //!< delete self from all submeshes
196 void Unset(SMESH_Mesh* mesh)
198 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
199 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
200 TDependsOnMap::const_iterator sm;
201 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
202 sm->second->DeleteEventListener( this );
207 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
209 TCollection_AsciiString typeStr;
210 switch ( theMirrorType ) {
211 case SMESH::SMESH_MeshEditor::POINT:
212 typeStr = "SMESH.SMESH_MeshEditor.POINT";
214 case SMESH::SMESH_MeshEditor::AXIS:
215 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
218 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
224 //=============================================================================
228 //=============================================================================
230 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
233 myMesh = & theMesh->GetImpl();
234 myPreviewMode = isPreview;
237 //================================================================================
241 //================================================================================
243 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
247 //================================================================================
249 * \brief Clear members
251 //================================================================================
253 void SMESH_MeshEditor_i::initData()
255 if ( myPreviewMode ) {
256 myPreviewData = new SMESH::MeshPreviewStruct();
259 myLastCreatedElems = new SMESH::long_array();
260 myLastCreatedNodes = new SMESH::long_array();
261 TNodeSearcherDeleter::Delete();
265 //=============================================================================
269 //=============================================================================
272 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
276 ::SMESH_MeshEditor anEditor( myMesh );
279 for (int i = 0; i < IDsOfElements.length(); i++)
280 IdList.push_back( IDsOfElements[i] );
282 // Update Python script
283 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
285 TPythonDump() << "print 'RemoveElements: ', isDone";
288 return anEditor.Remove( IdList, false );
291 //=============================================================================
295 //=============================================================================
297 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
301 ::SMESH_MeshEditor anEditor( myMesh );
303 for (int i = 0; i < IDsOfNodes.length(); i++)
304 IdList.push_back( IDsOfNodes[i] );
306 // Update Python script
307 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
309 TPythonDump() << "print 'RemoveNodes: ', isDone";
312 return anEditor.Remove( IdList, true );
315 //=============================================================================
319 //=============================================================================
321 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
325 int NbNodes = IDsOfNodes.length();
326 SMDS_MeshElement* elem = 0;
329 CORBA::Long index1 = IDsOfNodes[0];
330 CORBA::Long index2 = IDsOfNodes[1];
331 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
333 // Update Python script
334 TPythonDump() << "edge = " << this << ".AddEdge([ "
335 << index1 << ", " << index2 <<" ])";
338 CORBA::Long n1 = IDsOfNodes[0];
339 CORBA::Long n2 = IDsOfNodes[1];
340 CORBA::Long n12 = IDsOfNodes[2];
341 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
342 GetMeshDS()->FindNode(n2),
343 GetMeshDS()->FindNode(n12));
344 // Update Python script
345 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
346 <<n1<<", "<<n2<<", "<<n12<<" ])";
350 return elem->GetID();
355 //=============================================================================
359 //=============================================================================
361 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
362 CORBA::Double y, CORBA::Double z)
366 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
368 // Update Python script
369 TPythonDump() << "nodeID = " << this << ".AddNode( "
370 << x << ", " << y << ", " << z << " )";
375 //=============================================================================
379 //=============================================================================
381 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
385 int NbNodes = IDsOfNodes.length();
391 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
392 for (int i = 0; i < NbNodes; i++)
393 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
395 SMDS_MeshElement* elem = 0;
397 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
399 else if (NbNodes == 4) {
400 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
402 else if (NbNodes == 6) {
403 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
406 else if (NbNodes == 8) {
407 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
408 nodes[4], nodes[5], nodes[6], nodes[7]);
411 // Update Python script
412 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
415 return elem->GetID();
420 //=============================================================================
424 //=============================================================================
425 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
426 (const SMESH::long_array & IDsOfNodes)
430 int NbNodes = IDsOfNodes.length();
431 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
432 for (int i = 0; i < NbNodes; i++)
433 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
435 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
437 // Update Python script
438 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
440 TPythonDump() << "print 'AddPolygonalFace: ', faceID";
444 return elem->GetID();
449 //=============================================================================
453 //=============================================================================
455 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
459 int NbNodes = IDsOfNodes.length();
460 vector< const SMDS_MeshNode*> n(NbNodes);
461 for(int i=0;i<NbNodes;i++)
462 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
464 SMDS_MeshElement* elem = 0;
467 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
468 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
469 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
470 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
471 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
472 n[6],n[7],n[8],n[9]);
474 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
475 n[7],n[8],n[9],n[10],n[11],n[12]);
477 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
478 n[9],n[10],n[11],n[12],n[13],n[14]);
480 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
481 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
482 n[15],n[16],n[17],n[18],n[19]);
486 // Update Python script
487 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
489 TPythonDump() << "print 'AddVolume: ', volID";
493 return elem->GetID();
498 //=============================================================================
500 * AddPolyhedralVolume
502 //=============================================================================
503 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume
504 (const SMESH::long_array & IDsOfNodes,
505 const SMESH::long_array & Quantities)
509 int NbNodes = IDsOfNodes.length();
510 std::vector<const SMDS_MeshNode*> n (NbNodes);
511 for (int i = 0; i < NbNodes; i++)
512 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
514 int NbFaces = Quantities.length();
515 std::vector<int> q (NbFaces);
516 for (int j = 0; j < NbFaces; j++)
517 q[j] = Quantities[j];
519 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
521 // Update Python script
522 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
523 << IDsOfNodes << ", " << Quantities << " )";
525 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
529 return elem->GetID();
534 //=============================================================================
536 * AddPolyhedralVolumeByFaces
538 //=============================================================================
539 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
540 (const SMESH::long_array & IdsOfFaces)
544 int NbFaces = IdsOfFaces.length();
545 std::vector<const SMDS_MeshNode*> poly_nodes;
546 std::vector<int> quantities (NbFaces);
548 for (int i = 0; i < NbFaces; i++) {
549 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
550 quantities[i] = aFace->NbNodes();
552 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
554 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
558 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
560 // Update Python script
561 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
562 << IdsOfFaces << " )";
564 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
568 return elem->GetID();
573 //=============================================================================
575 * \brief Bind a node to a vertex
576 * \param NodeID - node ID
577 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
578 * \retval boolean - false if NodeID or VertexID is invalid
580 //=============================================================================
582 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
583 throw (SALOME::SALOME_Exception)
585 Unexpect aCatch(SALOME_SalomeException);
587 SMESHDS_Mesh * mesh = GetMeshDS();
588 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
590 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
592 if ( mesh->MaxShapeIndex() < VertexID )
593 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
595 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
596 if ( shape.ShapeType() != TopAbs_VERTEX )
597 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
599 mesh->SetNodeOnVertex( node, VertexID );
602 //=============================================================================
604 * \brief Store node position on an edge
605 * \param NodeID - node ID
606 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
607 * \param paramOnEdge - parameter on edge where the node is located
608 * \retval boolean - false if any parameter is invalid
610 //=============================================================================
612 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
613 CORBA::Double paramOnEdge)
614 throw (SALOME::SALOME_Exception)
616 Unexpect aCatch(SALOME_SalomeException);
618 SMESHDS_Mesh * mesh = GetMeshDS();
619 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
621 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
623 if ( mesh->MaxShapeIndex() < EdgeID )
624 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
626 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
627 if ( shape.ShapeType() != TopAbs_EDGE )
628 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
631 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
632 if ( paramOnEdge < f || paramOnEdge > l )
633 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
635 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
638 //=============================================================================
640 * \brief Store node position on a face
641 * \param NodeID - node ID
642 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
643 * \param u - U parameter on face where the node is located
644 * \param v - V parameter on face where the node is located
645 * \retval boolean - false if any parameter is invalid
647 //=============================================================================
649 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
650 CORBA::Double u, CORBA::Double v)
651 throw (SALOME::SALOME_Exception)
653 Unexpect aCatch(SALOME_SalomeException);
655 SMESHDS_Mesh * mesh = GetMeshDS();
656 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
658 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
660 if ( mesh->MaxShapeIndex() < FaceID )
661 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
663 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
664 if ( shape.ShapeType() != TopAbs_FACE )
665 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
667 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
668 bool isOut = ( u < surf.FirstUParameter() ||
669 u > surf.LastUParameter() ||
670 v < surf.FirstVParameter() ||
671 v > surf.LastVParameter() );
675 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
676 << " u( " << surf.FirstUParameter()
677 << "," << surf.LastUParameter()
678 << ") v( " << surf.FirstVParameter()
679 << "," << surf.LastVParameter() << ")" );
681 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
684 mesh->SetNodeOnFace( node, FaceID, u, v );
687 //=============================================================================
689 * \brief Bind a node to a solid
690 * \param NodeID - node ID
691 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
692 * \retval boolean - false if NodeID or SolidID is invalid
694 //=============================================================================
696 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
697 throw (SALOME::SALOME_Exception)
699 Unexpect aCatch(SALOME_SalomeException);
701 SMESHDS_Mesh * mesh = GetMeshDS();
702 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
704 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
706 if ( mesh->MaxShapeIndex() < SolidID )
707 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
709 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
710 if ( shape.ShapeType() != TopAbs_SOLID &&
711 shape.ShapeType() != TopAbs_SHELL)
712 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
714 mesh->SetNodeInVolume( node, SolidID );
717 //=============================================================================
719 * \brief Bind an element to a shape
720 * \param ElementID - element ID
721 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
722 * \retval boolean - false if ElementID or ShapeID is invalid
724 //=============================================================================
726 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
728 throw (SALOME::SALOME_Exception)
730 Unexpect aCatch(SALOME_SalomeException);
732 SMESHDS_Mesh * mesh = GetMeshDS();
733 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
735 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
737 if ( mesh->MaxShapeIndex() < ShapeID )
738 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
740 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
741 if ( shape.ShapeType() != TopAbs_EDGE &&
742 shape.ShapeType() != TopAbs_FACE &&
743 shape.ShapeType() != TopAbs_SOLID &&
744 shape.ShapeType() != TopAbs_SHELL )
745 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
747 mesh->SetMeshElementOnShape( elem, ShapeID );
751 //=============================================================================
755 //=============================================================================
757 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
764 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
768 GetMeshDS()->MoveNode(node, x, y, z);
770 // Update Python script
771 TPythonDump() << "isDone = " << this << ".MoveNode( "
772 << NodeID << ", " << x << ", " << y << ", " << z << " )";
777 //=============================================================================
781 //=============================================================================
783 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
788 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
789 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
793 // Update Python script
794 TPythonDump() << "isDone = " << this << ".InverseDiag( "
795 << NodeID1 << ", " << NodeID2 << " )";
797 ::SMESH_MeshEditor aMeshEditor( myMesh );
798 return aMeshEditor.InverseDiag ( n1, n2 );
801 //=============================================================================
805 //=============================================================================
807 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
812 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
813 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
817 // Update Python script
818 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
819 << NodeID1 << ", " << NodeID2 << " )";
821 ::SMESH_MeshEditor aMeshEditor( myMesh );
823 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
825 storeResult(aMeshEditor);
830 //=============================================================================
834 //=============================================================================
836 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
840 ::SMESH_MeshEditor anEditor( myMesh );
841 for (int i = 0; i < IDsOfElements.length(); i++)
843 CORBA::Long index = IDsOfElements[i];
844 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
846 anEditor.Reorient( elem );
848 // Update Python script
849 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
855 //=============================================================================
859 //=============================================================================
861 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
865 SMESH::long_array_var anElementsId = theObject->GetIDs();
866 CORBA::Boolean isDone = Reorient(anElementsId);
868 // Clear python line, created by Reorient()
869 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
870 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
872 // Update Python script
873 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
880 //================================================================================
882 * \brief function for conversion long_array to TIDSortedElemSet
883 * \param IDs - array of IDs
884 * \param aMesh - mesh
885 * \param aMap - collection to fill
886 * \param aType - element type
888 //================================================================================
890 void arrayToSet(const SMESH::long_array & IDs,
891 const SMESHDS_Mesh* aMesh,
892 TIDSortedElemSet& aMap,
893 const SMDSAbs_ElementType aType = SMDSAbs_All )
895 for (int i=0; i<IDs.length(); i++) {
896 CORBA::Long ind = IDs[i];
897 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
898 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
904 //=============================================================================
908 //=============================================================================
909 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
910 SMESH::NumericalFunctor_ptr Criterion,
911 CORBA::Double MaxAngle)
915 SMESHDS_Mesh* aMesh = GetMeshDS();
916 TIDSortedElemSet faces;
917 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
919 SMESH::NumericalFunctor_i* aNumericalFunctor =
920 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
921 SMESH::Controls::NumericalFunctorPtr aCrit;
922 if ( !aNumericalFunctor )
923 aCrit.reset( new SMESH::Controls::AspectRatio() );
925 aCrit = aNumericalFunctor->GetNumericalFunctor();
927 // Update Python script
928 TPythonDump() << "isDone = " << this << ".TriToQuad( "
929 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
931 TPythonDump() << "print 'TriToQuad: ', isDone";
934 ::SMESH_MeshEditor anEditor( myMesh );
936 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
938 storeResult(anEditor);
944 //=============================================================================
948 //=============================================================================
949 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
950 SMESH::NumericalFunctor_ptr Criterion,
951 CORBA::Double MaxAngle)
955 SMESH::long_array_var anElementsId = theObject->GetIDs();
956 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
958 // Clear python line(s), created by TriToQuad()
959 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
960 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
962 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
965 SMESH::NumericalFunctor_i* aNumericalFunctor =
966 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
968 // Update Python script
969 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
970 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
972 TPythonDump() << "print 'TriToQuadObject: ', isDone";
979 //=============================================================================
983 //=============================================================================
984 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
985 SMESH::NumericalFunctor_ptr Criterion)
989 SMESHDS_Mesh* aMesh = GetMeshDS();
990 TIDSortedElemSet faces;
991 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
993 SMESH::NumericalFunctor_i* aNumericalFunctor =
994 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
995 SMESH::Controls::NumericalFunctorPtr aCrit;
996 if ( !aNumericalFunctor )
997 aCrit.reset( new SMESH::Controls::AspectRatio() );
999 aCrit = aNumericalFunctor->GetNumericalFunctor();
1002 // Update Python script
1003 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1005 TPythonDump() << "print 'QuadToTri: ', isDone";
1008 ::SMESH_MeshEditor anEditor( myMesh );
1009 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1011 storeResult(anEditor);
1017 //=============================================================================
1021 //=============================================================================
1022 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1023 SMESH::NumericalFunctor_ptr Criterion)
1027 SMESH::long_array_var anElementsId = theObject->GetIDs();
1028 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1030 // Clear python line(s), created by QuadToTri()
1031 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1032 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1034 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1037 SMESH::NumericalFunctor_i* aNumericalFunctor =
1038 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1040 // Update Python script
1041 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1043 TPythonDump() << "print 'QuadToTriObject: ', isDone";
1050 //=============================================================================
1054 //=============================================================================
1055 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1056 CORBA::Boolean Diag13)
1060 SMESHDS_Mesh* aMesh = GetMeshDS();
1061 TIDSortedElemSet faces;
1062 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1064 // Update Python script
1065 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1066 << IDsOfElements << ", " << Diag13 << " )";
1068 TPythonDump() << "print 'SplitQuad: ', isDone";
1071 ::SMESH_MeshEditor anEditor( myMesh );
1072 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1074 storeResult(anEditor);
1080 //=============================================================================
1084 //=============================================================================
1085 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1086 CORBA::Boolean Diag13)
1090 SMESH::long_array_var anElementsId = theObject->GetIDs();
1091 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1093 // Clear python line(s), created by SplitQuad()
1094 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1095 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1097 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1100 // Update Python script
1101 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1102 << theObject << ", " << Diag13 << " )";
1104 TPythonDump() << "print 'SplitQuadObject: ', isDone";
1111 //=============================================================================
1115 //=============================================================================
1116 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1117 SMESH::NumericalFunctor_ptr Criterion)
1119 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1120 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1122 SMESH::NumericalFunctor_i* aNumericalFunctor =
1123 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1124 SMESH::Controls::NumericalFunctorPtr aCrit;
1125 if (aNumericalFunctor)
1126 aCrit = aNumericalFunctor->GetNumericalFunctor();
1128 aCrit.reset(new SMESH::Controls::AspectRatio());
1130 ::SMESH_MeshEditor anEditor (myMesh);
1131 return anEditor.BestSplit(quad, aCrit);
1137 //=======================================================================
1140 //=======================================================================
1143 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1144 const SMESH::long_array & IDsOfFixedNodes,
1145 CORBA::Long MaxNbOfIterations,
1146 CORBA::Double MaxAspectRatio,
1147 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1149 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1150 MaxAspectRatio, Method, false );
1154 //=======================================================================
1155 //function : SmoothParametric
1157 //=======================================================================
1160 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1161 const SMESH::long_array & IDsOfFixedNodes,
1162 CORBA::Long MaxNbOfIterations,
1163 CORBA::Double MaxAspectRatio,
1164 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1166 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1167 MaxAspectRatio, Method, true );
1171 //=======================================================================
1172 //function : SmoothObject
1174 //=======================================================================
1177 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1178 const SMESH::long_array & IDsOfFixedNodes,
1179 CORBA::Long MaxNbOfIterations,
1180 CORBA::Double MaxAspectRatio,
1181 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1183 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1184 MaxAspectRatio, Method, false);
1188 //=======================================================================
1189 //function : SmoothParametricObject
1191 //=======================================================================
1194 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1195 const SMESH::long_array & IDsOfFixedNodes,
1196 CORBA::Long MaxNbOfIterations,
1197 CORBA::Double MaxAspectRatio,
1198 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1200 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1201 MaxAspectRatio, Method, true);
1205 //=============================================================================
1209 //=============================================================================
1212 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1213 const SMESH::long_array & IDsOfFixedNodes,
1214 CORBA::Long MaxNbOfIterations,
1215 CORBA::Double MaxAspectRatio,
1216 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1221 SMESHDS_Mesh* aMesh = GetMeshDS();
1223 TIDSortedElemSet elements;
1224 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1226 set<const SMDS_MeshNode*> fixedNodes;
1227 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1228 CORBA::Long index = IDsOfFixedNodes[i];
1229 const SMDS_MeshNode * node = aMesh->FindNode(index);
1231 fixedNodes.insert( node );
1233 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1234 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1235 method = ::SMESH_MeshEditor::CENTROIDAL;
1237 ::SMESH_MeshEditor anEditor( myMesh );
1238 anEditor.Smooth(elements, fixedNodes, method,
1239 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1241 storeResult(anEditor);
1243 // Update Python script
1244 TPythonDump() << "isDone = " << this << "."
1245 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1246 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1247 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1248 << "SMESH.SMESH_MeshEditor."
1249 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1250 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1252 TPythonDump() << "print 'Smooth: ', isDone";
1259 //=============================================================================
1263 //=============================================================================
1266 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1267 const SMESH::long_array & IDsOfFixedNodes,
1268 CORBA::Long MaxNbOfIterations,
1269 CORBA::Double MaxAspectRatio,
1270 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1275 SMESH::long_array_var anElementsId = theObject->GetIDs();
1276 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1277 MaxAspectRatio, Method, IsParametric);
1279 // Clear python line(s), created by Smooth()
1280 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1281 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1283 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1286 // Update Python script
1287 TPythonDump() << "isDone = " << this << "."
1288 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1289 << theObject << ", " << IDsOfFixedNodes << ", "
1290 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1291 << "SMESH.SMESH_MeshEditor."
1292 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1293 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1295 TPythonDump() << "print 'SmoothObject: ', isDone";
1302 //=============================================================================
1306 //=============================================================================
1308 void SMESH_MeshEditor_i::RenumberNodes()
1310 // Update Python script
1311 TPythonDump() << this << ".RenumberNodes()";
1313 GetMeshDS()->Renumber( true );
1317 //=============================================================================
1321 //=============================================================================
1323 void SMESH_MeshEditor_i::RenumberElements()
1325 // Update Python script
1326 TPythonDump() << this << ".RenumberElements()";
1328 GetMeshDS()->Renumber( false );
1331 //=======================================================================
1333 * \brief Return groups by their IDs
1335 //=======================================================================
1337 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1341 myMesh_i->CreateGroupServants();
1342 return myMesh_i->GetGroups( *groupIDs );
1345 //=======================================================================
1346 //function : rotationSweep
1348 //=======================================================================
1350 SMESH::ListOfGroups*
1351 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1352 const SMESH::AxisStruct & theAxis,
1353 CORBA::Double theAngleInRadians,
1354 CORBA::Long theNbOfSteps,
1355 CORBA::Double theTolerance,
1356 const bool theMakeGroups)
1360 TIDSortedElemSet inElements, copyElements;
1361 arrayToSet(theIDsOfElements, GetMeshDS(), inElements);
1363 TIDSortedElemSet* workElements = & inElements;
1364 TPreviewMesh tmpMesh( SMDSAbs_Face );
1365 SMESH_Mesh* mesh = 0;
1366 bool makeWalls=true;
1367 if ( myPreviewMode )
1369 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1370 tmpMesh.Copy( inElements, copyElements, select, avoid );
1372 workElements = & copyElements;
1373 //makeWalls = false;
1380 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1381 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1383 ::SMESH_MeshEditor anEditor( mesh );
1384 ::SMESH_MeshEditor::PGroupIDs groupIds =
1385 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1386 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1387 storeResult(anEditor);
1389 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1392 //=======================================================================
1393 //function : RotationSweep
1395 //=======================================================================
1397 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1398 const SMESH::AxisStruct & theAxis,
1399 CORBA::Double theAngleInRadians,
1400 CORBA::Long theNbOfSteps,
1401 CORBA::Double theTolerance)
1403 if ( !myPreviewMode ) {
1404 TPythonDump() << "axis = " << theAxis;
1405 TPythonDump() << this << ".RotationSweep( "
1408 << theAngleInRadians << ", "
1409 << theNbOfSteps << ", "
1410 << theTolerance << " )";
1412 rotationSweep(theIDsOfElements,
1420 //=======================================================================
1421 //function : RotationSweepMakeGroups
1423 //=======================================================================
1425 SMESH::ListOfGroups*
1426 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1427 const SMESH::AxisStruct& theAxis,
1428 CORBA::Double theAngleInRadians,
1429 CORBA::Long theNbOfSteps,
1430 CORBA::Double theTolerance)
1432 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1438 if ( !myPreviewMode ) {
1439 TPythonDump()<< "axis = " << theAxis;
1440 TPythonDump aPythonDump;
1441 DumpGroupsList(aPythonDump,aGroups);
1442 aPythonDump<< this << ".RotationSweepMakeGroups( "
1445 << theAngleInRadians << ", "
1446 << theNbOfSteps << ", "
1447 << theTolerance << " )";
1452 //=======================================================================
1453 //function : RotationSweepObject
1455 //=======================================================================
1457 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1458 const SMESH::AxisStruct & theAxis,
1459 CORBA::Double theAngleInRadians,
1460 CORBA::Long theNbOfSteps,
1461 CORBA::Double theTolerance)
1463 if ( !myPreviewMode ) {
1464 TPythonDump() << "axis = " << theAxis;
1465 TPythonDump() << this << ".RotationSweepObject( "
1468 << theAngleInRadians << ", "
1469 << theNbOfSteps << ", "
1470 << theTolerance << " )";
1472 SMESH::long_array_var anElementsId = theObject->GetIDs();
1473 rotationSweep(anElementsId,
1481 //=======================================================================
1482 //function : RotationSweepObjectMakeGroups
1484 //=======================================================================
1486 SMESH::ListOfGroups*
1487 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1488 const SMESH::AxisStruct& theAxis,
1489 CORBA::Double theAngleInRadians,
1490 CORBA::Long theNbOfSteps,
1491 CORBA::Double theTolerance)
1493 SMESH::long_array_var anElementsId = theObject->GetIDs();
1494 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1500 if ( !myPreviewMode ) {
1501 TPythonDump() << "axis = " << theAxis;
1502 TPythonDump aPythonDump;
1503 DumpGroupsList(aPythonDump,aGroups);
1504 aPythonDump<< this << ".RotationSweepObjectMakeGroups( "
1507 << theAngleInRadians << ", "
1508 << theNbOfSteps << ", "
1509 << theTolerance << " )";
1515 //=======================================================================
1516 //function : extrusionSweep
1518 //=======================================================================
1520 SMESH::ListOfGroups*
1521 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1522 const SMESH::DirStruct & theStepVector,
1523 CORBA::Long theNbOfSteps,
1524 const bool theMakeGroups,
1525 const SMDSAbs_ElementType theElementType)
1533 TIDSortedElemSet elements;
1534 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1536 const SMESH::PointStruct * P = &theStepVector.PS;
1537 gp_Vec stepVec( P->x, P->y, P->z );
1539 TElemOfElemListMap aHystory;
1540 ::SMESH_MeshEditor anEditor( myMesh );
1541 ::SMESH_MeshEditor::PGroupIDs groupIds =
1542 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1544 storeResult(anEditor);
1546 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1548 } catch(Standard_Failure) {
1549 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1550 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1555 //=======================================================================
1556 //function : ExtrusionSweep
1558 //=======================================================================
1560 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1561 const SMESH::DirStruct & theStepVector,
1562 CORBA::Long theNbOfSteps)
1564 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1565 if ( !myPreviewMode ) {
1566 TPythonDump() << "stepVector = " << theStepVector;
1567 TPythonDump() << this << ".ExtrusionSweep( "
1568 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1573 //=======================================================================
1574 //function : ExtrusionSweepObject
1576 //=======================================================================
1578 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1579 const SMESH::DirStruct & theStepVector,
1580 CORBA::Long theNbOfSteps)
1582 SMESH::long_array_var anElementsId = theObject->GetIDs();
1583 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1584 if ( !myPreviewMode ) {
1585 TPythonDump() << "stepVector = " << theStepVector;
1586 TPythonDump() << this << ".ExtrusionSweepObject( "
1587 << theObject << ", stepVector, " << theNbOfSteps << " )";
1591 //=======================================================================
1592 //function : ExtrusionSweepObject1D
1594 //=======================================================================
1596 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1597 const SMESH::DirStruct & theStepVector,
1598 CORBA::Long theNbOfSteps)
1600 SMESH::long_array_var anElementsId = theObject->GetIDs();
1601 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1602 if ( !myPreviewMode ) {
1603 TPythonDump() << "stepVector = " << theStepVector;
1604 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1605 << theObject << ", stepVector, " << theNbOfSteps << " )";
1609 //=======================================================================
1610 //function : ExtrusionSweepObject2D
1612 //=======================================================================
1614 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1615 const SMESH::DirStruct & theStepVector,
1616 CORBA::Long theNbOfSteps)
1618 SMESH::long_array_var anElementsId = theObject->GetIDs();
1619 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1620 if ( !myPreviewMode ) {
1621 TPythonDump() << "stepVector = " << theStepVector;
1622 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1623 << theObject << ", stepVector, " << theNbOfSteps << " )";
1627 //=======================================================================
1628 //function : ExtrusionSweepMakeGroups
1630 //=======================================================================
1632 SMESH::ListOfGroups*
1633 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1634 const SMESH::DirStruct& theStepVector,
1635 CORBA::Long theNbOfSteps)
1637 SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1639 if ( !myPreviewMode ) {
1640 TPythonDump() << "stepVector = " << theStepVector;
1641 TPythonDump aPythonDump;
1642 DumpGroupsList(aPythonDump,aGroups);
1643 aPythonDump << this << ".ExtrusionSweepMakeGroups( "
1644 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1648 //=======================================================================
1649 //function : ExtrusionSweepObjectMakeGroups
1651 //=======================================================================
1653 SMESH::ListOfGroups*
1654 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1655 const SMESH::DirStruct& theStepVector,
1656 CORBA::Long theNbOfSteps)
1658 SMESH::long_array_var anElementsId = theObject->GetIDs();
1659 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1661 if ( !myPreviewMode ) {
1662 TPythonDump() << "stepVector = " << theStepVector;
1663 TPythonDump aPythonDump;
1664 DumpGroupsList(aPythonDump,aGroups);
1665 aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( "
1666 << theObject << ", stepVector, " << theNbOfSteps << " )";
1671 //=======================================================================
1672 //function : ExtrusionSweepObject1DMakeGroups
1674 //=======================================================================
1676 SMESH::ListOfGroups*
1677 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1678 const SMESH::DirStruct& theStepVector,
1679 CORBA::Long theNbOfSteps)
1681 SMESH::long_array_var anElementsId = theObject->GetIDs();
1682 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1683 if ( !myPreviewMode ) {
1684 TPythonDump() << "stepVector = " << theStepVector;
1685 TPythonDump aPythonDump;
1686 DumpGroupsList(aPythonDump,aGroups);
1687 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( "
1688 << theObject << ", stepVector, " << theNbOfSteps << " )";
1693 //=======================================================================
1694 //function : ExtrusionSweepObject2DMakeGroups
1696 //=======================================================================
1698 SMESH::ListOfGroups*
1699 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1700 const SMESH::DirStruct& theStepVector,
1701 CORBA::Long theNbOfSteps)
1703 SMESH::long_array_var anElementsId = theObject->GetIDs();
1704 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1705 if ( !myPreviewMode ) {
1706 TPythonDump() << "stepVector = " << theStepVector;
1707 TPythonDump aPythonDump;
1708 DumpGroupsList(aPythonDump,aGroups);
1709 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( "
1710 << theObject << ", stepVector, " << theNbOfSteps << " )";
1716 //=======================================================================
1717 //function : advancedExtrusion
1719 //=======================================================================
1721 SMESH::ListOfGroups*
1722 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1723 const SMESH::DirStruct & theStepVector,
1724 CORBA::Long theNbOfSteps,
1725 CORBA::Long theExtrFlags,
1726 CORBA::Double theSewTolerance,
1727 const bool theMakeGroups)
1731 TIDSortedElemSet elements;
1732 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1734 const SMESH::PointStruct * P = &theStepVector.PS;
1735 gp_Vec stepVec( P->x, P->y, P->z );
1737 ::SMESH_MeshEditor anEditor( myMesh );
1738 TElemOfElemListMap aHystory;
1739 ::SMESH_MeshEditor::PGroupIDs groupIds =
1740 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1741 theMakeGroups, theExtrFlags, theSewTolerance);
1742 storeResult(anEditor);
1744 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1747 //=======================================================================
1748 //function : AdvancedExtrusion
1750 //=======================================================================
1752 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1753 const SMESH::DirStruct & theStepVector,
1754 CORBA::Long theNbOfSteps,
1755 CORBA::Long theExtrFlags,
1756 CORBA::Double theSewTolerance)
1758 if ( !myPreviewMode ) {
1759 TPythonDump() << "stepVector = " << theStepVector;
1760 TPythonDump() << this << ".AdvancedExtrusion("
1763 << theNbOfSteps << ","
1764 << theExtrFlags << ", "
1765 << theSewTolerance << " )";
1767 advancedExtrusion( theIDsOfElements,
1775 //=======================================================================
1776 //function : AdvancedExtrusionMakeGroups
1778 //=======================================================================
1780 SMESH::ListOfGroups*
1781 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1782 const SMESH::DirStruct& theStepVector,
1783 CORBA::Long theNbOfSteps,
1784 CORBA::Long theExtrFlags,
1785 CORBA::Double theSewTolerance)
1787 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
1794 if ( !myPreviewMode ) {
1795 TPythonDump() << "stepVector = " << theStepVector;
1796 TPythonDump aPythonDump;
1797 DumpGroupsList(aPythonDump,aGroups);
1798 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
1801 << theNbOfSteps << ","
1802 << theExtrFlags << ", "
1803 << theSewTolerance << " )";
1809 //================================================================================
1811 * \brief Convert extrusion error to IDL enum
1813 //================================================================================
1815 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1817 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1821 RETCASE( EXTR_NO_ELEMENTS );
1822 RETCASE( EXTR_PATH_NOT_EDGE );
1823 RETCASE( EXTR_BAD_PATH_SHAPE );
1824 RETCASE( EXTR_BAD_STARTING_NODE );
1825 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1826 RETCASE( EXTR_CANT_GET_TANGENT );
1828 return SMESH::SMESH_MeshEditor::EXTR_OK;
1832 //=======================================================================
1833 //function : extrusionAlongPath
1835 //=======================================================================
1837 SMESH::ListOfGroups*
1838 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1839 SMESH::SMESH_Mesh_ptr thePathMesh,
1840 GEOM::GEOM_Object_ptr thePathShape,
1841 CORBA::Long theNodeStart,
1842 CORBA::Boolean theHasAngles,
1843 const SMESH::double_array & theAngles,
1844 CORBA::Boolean theHasRefPoint,
1845 const SMESH::PointStruct & theRefPoint,
1846 const bool theMakeGroups,
1847 SMESH::SMESH_MeshEditor::Extrusion_Error & theError)
1851 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1852 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1855 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1857 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1858 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1860 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
1861 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1865 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1867 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1871 TIDSortedElemSet elements;
1872 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1874 list<double> angles;
1875 for (int i = 0; i < theAngles.length(); i++) {
1876 angles.push_back( theAngles[i] );
1879 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1881 int nbOldGroups = myMesh->NbGroup();
1883 ::SMESH_MeshEditor anEditor( myMesh );
1884 ::SMESH_MeshEditor::Extrusion_Error error =
1885 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1886 theHasAngles, angles,
1887 theHasRefPoint, refPnt, theMakeGroups );
1888 storeResult(anEditor);
1889 theError = convExtrError( error );
1891 if ( theMakeGroups ) {
1892 list<int> groupIDs = myMesh->GetGroupIds();
1893 list<int>::iterator newBegin = groupIDs.begin();
1894 std::advance( newBegin, nbOldGroups ); // skip old groups
1895 groupIDs.erase( groupIDs.begin(), newBegin );
1896 return getGroups( & groupIDs );
1901 //=======================================================================
1902 //function : ExtrusionAlongPath
1904 //=======================================================================
1906 SMESH::SMESH_MeshEditor::Extrusion_Error
1907 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1908 SMESH::SMESH_Mesh_ptr thePathMesh,
1909 GEOM::GEOM_Object_ptr thePathShape,
1910 CORBA::Long theNodeStart,
1911 CORBA::Boolean theHasAngles,
1912 const SMESH::double_array & theAngles,
1913 CORBA::Boolean theHasRefPoint,
1914 const SMESH::PointStruct & theRefPoint)
1916 if ( !myPreviewMode ) {
1917 TPythonDump() << "rotAngles = " << theAngles;
1919 if ( theHasRefPoint )
1920 TPythonDump() << "refPoint = SMESH.PointStruct( "
1921 << theRefPoint.x << ", "
1922 << theRefPoint.y << ", "
1923 << theRefPoint.z << " )";
1925 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1927 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
1928 << theIDsOfElements << ", "
1929 << thePathMesh << ", "
1930 << thePathShape << ", "
1931 << theNodeStart << ", "
1932 << theHasAngles << ", "
1933 << "rotAngles" << ", "
1934 << theHasRefPoint << ", refPoint )";
1936 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1937 extrusionAlongPath( theIDsOfElements,
1950 //=======================================================================
1951 //function : ExtrusionAlongPathObject
1953 //=======================================================================
1955 SMESH::SMESH_MeshEditor::Extrusion_Error
1956 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
1957 SMESH::SMESH_Mesh_ptr thePathMesh,
1958 GEOM::GEOM_Object_ptr thePathShape,
1959 CORBA::Long theNodeStart,
1960 CORBA::Boolean theHasAngles,
1961 const SMESH::double_array & theAngles,
1962 CORBA::Boolean theHasRefPoint,
1963 const SMESH::PointStruct & theRefPoint)
1965 if ( !myPreviewMode ) {
1966 TPythonDump() << "rotAngles = " << theAngles;
1968 if ( theHasRefPoint )
1969 TPythonDump() << "refPoint = SMESH.PointStruct( "
1970 << theRefPoint.x << ", "
1971 << theRefPoint.y << ", "
1972 << theRefPoint.z << " )";
1974 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1976 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
1977 << theObject << ", "
1978 << thePathMesh << ", "
1979 << thePathShape << ", "
1980 << theNodeStart << ", "
1981 << theHasAngles << ", "
1982 << "rotAngles" << ", "
1983 << theHasRefPoint << ", refPoint )";
1985 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1986 SMESH::long_array_var anElementsId = theObject->GetIDs();
1987 extrusionAlongPath( anElementsId,
2001 //=======================================================================
2002 //function : ExtrusionAlongPathMakeGroups
2004 //=======================================================================
2006 SMESH::ListOfGroups*
2007 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2008 SMESH::SMESH_Mesh_ptr thePathMesh,
2009 GEOM::GEOM_Object_ptr thePathShape,
2010 CORBA::Long theNodeStart,
2011 CORBA::Boolean theHasAngles,
2012 const SMESH::double_array& theAngles,
2013 CORBA::Boolean theHasRefPoint,
2014 const SMESH::PointStruct& theRefPoint,
2015 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2017 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2027 if ( !myPreviewMode ) {
2028 TPythonDump() << "rotAngles = " << theAngles;
2030 if ( theHasRefPoint )
2031 TPythonDump() << "refPoint = SMESH.PointStruct( "
2032 << theRefPoint.x << ", "
2033 << theRefPoint.y << ", "
2034 << theRefPoint.z << " )";
2036 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2038 bool isDumpGroups = aGroups && aGroups->length() > 0;
2039 TPythonDump aPythonDump;
2041 aPythonDump << "("<<aGroups;
2044 aPythonDump << ", error)";
2046 aPythonDump <<"error";
2048 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2049 << theIDsOfElements << ", "
2050 << thePathMesh << ", "
2051 << thePathShape << ", "
2052 << theNodeStart << ", "
2053 << theHasAngles << ", "
2054 << "rotAngles" << ", "
2055 << theHasRefPoint << ", refPoint )";
2060 //=======================================================================
2061 //function : ExtrusionAlongPathObjectMakeGroups
2063 //=======================================================================
2065 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2066 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2067 SMESH::SMESH_Mesh_ptr thePathMesh,
2068 GEOM::GEOM_Object_ptr thePathShape,
2069 CORBA::Long theNodeStart,
2070 CORBA::Boolean theHasAngles,
2071 const SMESH::double_array& theAngles,
2072 CORBA::Boolean theHasRefPoint,
2073 const SMESH::PointStruct& theRefPoint,
2074 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2076 SMESH::long_array_var anElementsId = theObject->GetIDs();
2077 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2088 if ( !myPreviewMode ) {
2089 TPythonDump() << "rotAngles = " << theAngles;
2091 if ( theHasRefPoint )
2092 TPythonDump() << "refPoint = SMESH.PointStruct( "
2093 << theRefPoint.x << ", "
2094 << theRefPoint.y << ", "
2095 << theRefPoint.z << " )";
2097 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2099 bool isDumpGroups = aGroups && aGroups->length() > 0;
2100 TPythonDump aPythonDump;
2102 aPythonDump << "("<<aGroups;
2105 aPythonDump << ", error)";
2107 aPythonDump <<"error";
2109 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2110 << theObject << ", "
2111 << thePathMesh << ", "
2112 << thePathShape << ", "
2113 << theNodeStart << ", "
2114 << theHasAngles << ", "
2115 << "rotAngles" << ", "
2116 << theHasRefPoint << ", refPoint )";
2121 //================================================================================
2123 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2124 * of given angles along path steps
2125 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2126 * which proceeds the extrusion
2127 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2128 * is used to define the sub-mesh for the path
2130 //================================================================================
2132 SMESH::double_array*
2133 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2134 GEOM::GEOM_Object_ptr thePathShape,
2135 const SMESH::double_array & theAngles)
2137 SMESH::double_array_var aResult = new SMESH::double_array();
2138 int nbAngles = theAngles.length();
2139 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2141 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2142 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2143 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2144 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2145 return aResult._retn();
2146 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2147 if ( nbSteps == nbAngles )
2149 aResult.inout() = theAngles;
2153 aResult->length( nbSteps );
2154 double rAn2St = double( nbAngles ) / double( nbSteps );
2155 double angPrev = 0, angle;
2156 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2158 double angCur = rAn2St * ( iSt+1 );
2159 double angCurFloor = floor( angCur );
2160 double angPrevFloor = floor( angPrev );
2161 if ( angPrevFloor == angCurFloor )
2162 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2165 int iP = int( angPrevFloor );
2166 double angPrevCeil = ceil(angPrev);
2167 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2169 int iC = int( angCurFloor );
2170 if ( iC < nbAngles )
2171 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2173 iP = int( angPrevCeil );
2175 angle += theAngles[ iC ];
2177 aResult[ iSt ] = angle;
2182 // Update Python script
2183 TPythonDump() << "rotAngles = " << theAngles;
2184 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2185 << thePathMesh << ", "
2186 << thePathShape << ", "
2189 return aResult._retn();
2193 //=======================================================================
2196 //=======================================================================
2198 SMESH::ListOfGroups*
2199 SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
2200 const SMESH::AxisStruct & theAxis,
2201 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2202 CORBA::Boolean theCopy,
2203 const bool theMakeGroups,
2204 ::SMESH_Mesh* theTargetMesh)
2208 TIDSortedElemSet elements;
2209 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2211 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2212 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2215 switch ( theMirrorType ) {
2216 case SMESH::SMESH_MeshEditor::POINT:
2217 aTrsf.SetMirror( P );
2219 case SMESH::SMESH_MeshEditor::AXIS:
2220 aTrsf.SetMirror( gp_Ax1( P, V ));
2223 aTrsf.SetMirror( gp_Ax2( P, V ));
2226 ::SMESH_MeshEditor anEditor( myMesh );
2227 ::SMESH_MeshEditor::PGroupIDs groupIds =
2228 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2231 storeResult(anEditor);
2233 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2236 //=======================================================================
2239 //=======================================================================
2241 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2242 const SMESH::AxisStruct & theAxis,
2243 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2244 CORBA::Boolean theCopy)
2246 if ( !myPreviewMode ) {
2247 TPythonDump() << this << ".Mirror( "
2248 << theIDsOfElements << ", "
2250 << mirrorTypeName(theMirrorType) << ", "
2253 mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2257 //=======================================================================
2258 //function : MirrorObject
2260 //=======================================================================
2262 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2263 const SMESH::AxisStruct & theAxis,
2264 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2265 CORBA::Boolean theCopy)
2267 if ( !myPreviewMode ) {
2268 TPythonDump() << this << ".MirrorObject( "
2269 << theObject << ", "
2271 << mirrorTypeName(theMirrorType) << ", "
2274 SMESH::long_array_var anElementsId = theObject->GetIDs();
2275 mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2278 //=======================================================================
2279 //function : MirrorMakeGroups
2281 //=======================================================================
2283 SMESH::ListOfGroups*
2284 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2285 const SMESH::AxisStruct& theMirror,
2286 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2288 SMESH::ListOfGroups * aGroups = mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2289 if ( !myPreviewMode ) {
2290 TPythonDump()<<"axis = "<<theMirror;
2291 TPythonDump aPythonDump;
2292 DumpGroupsList(aPythonDump,aGroups);
2293 aPythonDump << this << ".MirrorMakeGroups( "
2294 << theIDsOfElements << ", "
2296 << mirrorTypeName(theMirrorType) << " )";
2301 //=======================================================================
2302 //function : MirrorObjectMakeGroups
2304 //=======================================================================
2306 SMESH::ListOfGroups*
2307 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2308 const SMESH::AxisStruct& theMirror,
2309 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2311 SMESH::long_array_var anElementsId = theObject->GetIDs();
2312 SMESH::ListOfGroups * aGroups = mirror(anElementsId, theMirror, theMirrorType, true, true);
2313 if ( !myPreviewMode ) {
2314 TPythonDump()<<"axis = "<<theMirror;
2315 TPythonDump aPythonDump;
2316 DumpGroupsList(aPythonDump,aGroups);
2317 aPythonDump << this << ".MirrorObjectMakeGroups( "
2318 << theObject << ", "
2320 << mirrorTypeName(theMirrorType) << " )";
2325 //=======================================================================
2326 //function : MirrorMakeMesh
2328 //=======================================================================
2330 SMESH::SMESH_Mesh_ptr
2331 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2332 const SMESH::AxisStruct& theMirror,
2333 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2334 CORBA::Boolean theCopyGroups,
2335 const char* theMeshName)
2337 SMESH_Mesh_i* mesh_i;
2338 SMESH::SMESH_Mesh_var mesh;
2339 { // open new scope to dump "MakeMesh" command
2340 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2342 TPythonDump pydump; // to prevent dump at mesh creation
2344 mesh = makeMesh( theMeshName );
2345 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2347 mirror(theIDsOfElements, theMirror, theMirrorType,
2348 false, theCopyGroups, & mesh_i->GetImpl());
2349 mesh_i->CreateGroupServants();
2352 if ( !myPreviewMode ) {
2353 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2354 << theIDsOfElements << ", "
2355 << theMirror << ", "
2356 << mirrorTypeName(theMirrorType) << ", "
2357 << theCopyGroups << ", '"
2358 << theMeshName << "' )";
2363 if(!myPreviewMode && mesh_i)
2364 mesh_i->GetGroups();
2366 return mesh._retn();
2369 //=======================================================================
2370 //function : MirrorObjectMakeMesh
2372 //=======================================================================
2374 SMESH::SMESH_Mesh_ptr
2375 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2376 const SMESH::AxisStruct& theMirror,
2377 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2378 CORBA::Boolean theCopyGroups,
2379 const char* theMeshName)
2381 SMESH_Mesh_i* mesh_i;
2382 SMESH::SMESH_Mesh_var mesh;
2383 { // open new scope to dump "MakeMesh" command
2384 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2386 TPythonDump pydump; // to prevent dump at mesh creation
2388 mesh = makeMesh( theMeshName );
2389 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2391 SMESH::long_array_var anElementsId = theObject->GetIDs();
2392 mirror(anElementsId, theMirror, theMirrorType,
2393 false, theCopyGroups, & mesh_i->GetImpl());
2394 mesh_i->CreateGroupServants();
2397 if ( !myPreviewMode ) {
2398 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
2399 << theObject << ", "
2400 << theMirror << ", "
2401 << mirrorTypeName(theMirrorType) << ", "
2402 << theCopyGroups << ", '"
2403 << theMeshName << "' )";
2408 if(!myPreviewMode && mesh_i)
2409 mesh_i->GetGroups();
2411 return mesh._retn();
2414 //=======================================================================
2415 //function : translate
2417 //=======================================================================
2419 SMESH::ListOfGroups*
2420 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2421 const SMESH::DirStruct & theVector,
2422 CORBA::Boolean theCopy,
2423 const bool theMakeGroups,
2424 ::SMESH_Mesh* theTargetMesh)
2428 TIDSortedElemSet elements;
2429 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2432 const SMESH::PointStruct * P = &theVector.PS;
2433 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2435 ::SMESH_MeshEditor anEditor( myMesh );
2436 ::SMESH_MeshEditor::PGroupIDs groupIds =
2437 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2440 storeResult(anEditor);
2442 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2445 //=======================================================================
2446 //function : Translate
2448 //=======================================================================
2450 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2451 const SMESH::DirStruct & theVector,
2452 CORBA::Boolean theCopy)
2454 if ( !myPreviewMode ) {
2455 TPythonDump() << "vector = " << theVector;
2456 TPythonDump() << this << ".Translate( "
2461 translate(theIDsOfElements,
2467 //=======================================================================
2468 //function : TranslateObject
2470 //=======================================================================
2472 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
2473 const SMESH::DirStruct & theVector,
2474 CORBA::Boolean theCopy)
2476 if ( !myPreviewMode ) {
2477 TPythonDump() << this << ".TranslateObject( "
2482 SMESH::long_array_var anElementsId = theObject->GetIDs();
2483 translate(anElementsId,
2489 //=======================================================================
2490 //function : TranslateMakeGroups
2492 //=======================================================================
2494 SMESH::ListOfGroups*
2495 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
2496 const SMESH::DirStruct& theVector)
2498 SMESH::ListOfGroups * aGroups = translate(theIDsOfElements,theVector,true,true);
2499 if ( !myPreviewMode ) {
2500 TPythonDump() << "vector = " << theVector;
2501 TPythonDump aPythonDump;
2502 DumpGroupsList(aPythonDump,aGroups);
2503 aPythonDump << this << ".TranslateMakeGroups( "
2510 //=======================================================================
2511 //function : TranslateObjectMakeGroups
2513 //=======================================================================
2515 SMESH::ListOfGroups*
2516 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2517 const SMESH::DirStruct& theVector)
2519 SMESH::long_array_var anElementsId = theObject->GetIDs();
2520 SMESH::ListOfGroups * aGroups = translate(anElementsId, theVector, true, true);
2522 if ( !myPreviewMode ) {
2524 TPythonDump() << "vector = " << theVector;
2525 TPythonDump aPythonDump;
2526 DumpGroupsList(aPythonDump,aGroups);
2527 aPythonDump << this << ".TranslateObjectMakeGroups( "
2534 //=======================================================================
2535 //function : TranslateMakeMesh
2537 //=======================================================================
2539 SMESH::SMESH_Mesh_ptr
2540 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
2541 const SMESH::DirStruct& theVector,
2542 CORBA::Boolean theCopyGroups,
2543 const char* theMeshName)
2545 SMESH_Mesh_i* mesh_i;
2546 SMESH::SMESH_Mesh_var mesh;
2548 { // open new scope to dump "MakeMesh" command
2549 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2551 TPythonDump pydump; // to prevent dump at mesh creation
2553 mesh = makeMesh( theMeshName );
2554 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2557 translate(theIDsOfElements, theVector,
2558 false, theCopyGroups, & mesh_i->GetImpl());
2559 mesh_i->CreateGroupServants();
2562 if ( !myPreviewMode ) {
2563 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
2564 << theIDsOfElements << ", "
2565 << theVector << ", "
2566 << theCopyGroups << ", '"
2567 << theMeshName << "' )";
2572 if(!myPreviewMode && mesh_i)
2573 mesh_i->GetGroups();
2575 return mesh._retn();
2578 //=======================================================================
2579 //function : TranslateObjectMakeMesh
2581 //=======================================================================
2583 SMESH::SMESH_Mesh_ptr
2584 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2585 const SMESH::DirStruct& theVector,
2586 CORBA::Boolean theCopyGroups,
2587 const char* theMeshName)
2589 SMESH_Mesh_i* mesh_i;
2590 SMESH::SMESH_Mesh_var mesh;
2591 { // open new scope to dump "MakeMesh" command
2592 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2594 TPythonDump pydump; // to prevent dump at mesh creation
2595 mesh = makeMesh( theMeshName );
2596 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2599 SMESH::long_array_var anElementsId = theObject->GetIDs();
2600 translate(anElementsId, theVector,
2601 false, theCopyGroups, & mesh_i->GetImpl());
2602 mesh_i->CreateGroupServants();
2604 if ( !myPreviewMode ) {
2605 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
2606 << theObject << ", "
2607 << theVector << ", "
2608 << theCopyGroups << ", '"
2609 << theMeshName << "' )";
2614 if(!myPreviewMode && mesh_i)
2615 mesh_i->GetGroups();
2617 return mesh._retn();
2620 //=======================================================================
2623 //=======================================================================
2625 SMESH::ListOfGroups*
2626 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
2627 const SMESH::AxisStruct & theAxis,
2628 CORBA::Double theAngle,
2629 CORBA::Boolean theCopy,
2630 const bool theMakeGroups,
2631 ::SMESH_Mesh* theTargetMesh)
2635 TIDSortedElemSet elements;
2636 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2638 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2639 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2642 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
2644 ::SMESH_MeshEditor anEditor( myMesh );
2645 ::SMESH_MeshEditor::PGroupIDs groupIds =
2646 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2649 storeResult(anEditor);
2651 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2654 //=======================================================================
2657 //=======================================================================
2659 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
2660 const SMESH::AxisStruct & theAxis,
2661 CORBA::Double theAngle,
2662 CORBA::Boolean theCopy)
2664 if ( !myPreviewMode ) {
2665 TPythonDump() << "axis = " << theAxis;
2666 TPythonDump() << this << ".Rotate( "
2672 rotate(theIDsOfElements,
2679 //=======================================================================
2680 //function : RotateObject
2682 //=======================================================================
2684 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
2685 const SMESH::AxisStruct & theAxis,
2686 CORBA::Double theAngle,
2687 CORBA::Boolean theCopy)
2689 if ( !myPreviewMode ) {
2690 TPythonDump() << "axis = " << theAxis;
2691 TPythonDump() << this << ".RotateObject( "
2697 SMESH::long_array_var anElementsId = theObject->GetIDs();
2698 rotate(anElementsId,
2705 //=======================================================================
2706 //function : RotateMakeGroups
2708 //=======================================================================
2710 SMESH::ListOfGroups*
2711 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
2712 const SMESH::AxisStruct& theAxis,
2713 CORBA::Double theAngle)
2715 SMESH::ListOfGroups * aGroups = rotate(theIDsOfElements,theAxis,theAngle,true,true);
2716 if ( !myPreviewMode ) {
2717 TPythonDump() << "axis = " << theAxis;
2718 TPythonDump aPythonDump;
2719 DumpGroupsList(aPythonDump,aGroups);
2720 aPythonDump << this << ".RotateMakeGroups( "
2723 << theAngle << " )";
2728 //=======================================================================
2729 //function : RotateObjectMakeGroups
2731 //=======================================================================
2733 SMESH::ListOfGroups*
2734 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2735 const SMESH::AxisStruct& theAxis,
2736 CORBA::Double theAngle)
2738 SMESH::long_array_var anElementsId = theObject->GetIDs();
2739 SMESH::ListOfGroups * aGroups = rotate(anElementsId,theAxis,theAngle,true,true);
2741 if ( !myPreviewMode ) {
2742 TPythonDump() << "axis = " << theAxis;
2743 TPythonDump aPythonDump;
2744 DumpGroupsList(aPythonDump,aGroups);
2745 aPythonDump << this << ".RotateObjectMakeGroups( "
2748 << theAngle << " )";
2753 //=======================================================================
2754 //function : RotateMakeMesh
2756 //=======================================================================
2758 SMESH::SMESH_Mesh_ptr
2759 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
2760 const SMESH::AxisStruct& theAxis,
2761 CORBA::Double theAngleInRadians,
2762 CORBA::Boolean theCopyGroups,
2763 const char* theMeshName)
2765 SMESH::SMESH_Mesh_var mesh;
2766 SMESH_Mesh_i* mesh_i;
2768 { // open new scope to dump "MakeMesh" command
2769 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2771 TPythonDump pydump; // to prevent dump at mesh creation
2773 mesh = makeMesh( theMeshName );
2774 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2777 rotate(theIDsOfElements, theAxis, theAngleInRadians,
2778 false, theCopyGroups, & mesh_i->GetImpl());
2779 mesh_i->CreateGroupServants();
2781 if ( !myPreviewMode ) {
2782 pydump << mesh << " = " << this << ".RotateMakeMesh( "
2783 << theIDsOfElements << ", "
2785 << theAngleInRadians << ", "
2786 << theCopyGroups << ", '"
2787 << theMeshName << "' )";
2792 if(!myPreviewMode && mesh_i)
2793 mesh_i->GetGroups();
2795 return mesh._retn();
2798 //=======================================================================
2799 //function : RotateObjectMakeMesh
2801 //=======================================================================
2803 SMESH::SMESH_Mesh_ptr
2804 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2805 const SMESH::AxisStruct& theAxis,
2806 CORBA::Double theAngleInRadians,
2807 CORBA::Boolean theCopyGroups,
2808 const char* theMeshName)
2810 SMESH::SMESH_Mesh_var mesh;
2811 SMESH_Mesh_i* mesh_i;
2813 {// open new scope to dump "MakeMesh" command
2814 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2816 TPythonDump pydump; // to prevent dump at mesh creation
2817 mesh = makeMesh( theMeshName );
2818 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2821 SMESH::long_array_var anElementsId = theObject->GetIDs();
2822 rotate(anElementsId, theAxis, theAngleInRadians,
2823 false, theCopyGroups, & mesh_i->GetImpl());
2824 mesh_i->CreateGroupServants();
2826 if ( !myPreviewMode ) {
2827 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
2828 << theObject << ", "
2830 << theAngleInRadians << ", "
2831 << theCopyGroups << ", '"
2832 << theMeshName << "' )";
2837 if(!myPreviewMode && mesh_i)
2838 mesh_i->GetGroups();
2840 return mesh._retn();
2843 //=======================================================================
2844 //function : FindCoincidentNodes
2846 //=======================================================================
2848 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
2849 SMESH::array_of_long_array_out GroupsOfNodes)
2853 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2854 ::SMESH_MeshEditor anEditor( myMesh );
2855 set<const SMDS_MeshNode*> nodes; // no input nodes
2856 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2858 GroupsOfNodes = new SMESH::array_of_long_array;
2859 GroupsOfNodes->length( aListOfListOfNodes.size() );
2860 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2861 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2862 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2863 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2864 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2865 aGroup.length( aListOfNodes.size() );
2866 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2867 aGroup[ j ] = (*lIt)->GetID();
2869 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
2870 << Tolerance << " )";
2873 //=======================================================================
2874 //function : FindCoincidentNodesOnPart
2876 //=======================================================================
2877 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
2878 CORBA::Double Tolerance,
2879 SMESH::array_of_long_array_out GroupsOfNodes)
2882 SMESH::long_array_var aElementsId = theObject->GetIDs();
2884 SMESHDS_Mesh* aMesh = GetMeshDS();
2885 set<const SMDS_MeshNode*> nodes;
2887 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2888 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
2889 for(int i = 0; i < aElementsId->length(); i++) {
2890 CORBA::Long ind = aElementsId[i];
2891 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
2897 for(int i = 0; i < aElementsId->length(); i++) {
2898 CORBA::Long ind = aElementsId[i];
2899 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
2901 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
2902 while ( nIt->more() )
2903 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
2909 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2910 ::SMESH_MeshEditor anEditor( myMesh );
2912 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2914 GroupsOfNodes = new SMESH::array_of_long_array;
2915 GroupsOfNodes->length( aListOfListOfNodes.size() );
2916 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2917 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2918 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2919 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2920 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2921 aGroup.length( aListOfNodes.size() );
2922 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2923 aGroup[ j ] = (*lIt)->GetID();
2925 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
2927 << Tolerance << " )";
2930 //=======================================================================
2931 //function : MergeNodes
2933 //=======================================================================
2935 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
2939 SMESHDS_Mesh* aMesh = GetMeshDS();
2941 TPythonDump aTPythonDump;
2942 aTPythonDump << this << ".MergeNodes([";
2943 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2944 for (int i = 0; i < GroupsOfNodes.length(); i++)
2946 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
2947 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
2948 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
2949 for ( int j = 0; j < aNodeGroup.length(); j++ )
2951 CORBA::Long index = aNodeGroup[ j ];
2952 const SMDS_MeshNode * node = aMesh->FindNode(index);
2954 aListOfNodes.push_back( node );
2956 if ( aListOfNodes.size() < 2 )
2957 aListOfListOfNodes.pop_back();
2959 if ( i > 0 ) aTPythonDump << ", ";
2960 aTPythonDump << aNodeGroup;
2962 ::SMESH_MeshEditor anEditor( myMesh );
2963 anEditor.MergeNodes( aListOfListOfNodes );
2965 aTPythonDump << "])";
2968 //=======================================================================
2969 //function : FindEqualElements
2971 //=======================================================================
2972 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
2973 SMESH::array_of_long_array_out GroupsOfElementsID)
2976 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2977 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
2978 typedef list<int> TListOfIDs;
2979 set<const SMDS_MeshElement*> elems;
2980 SMESH::long_array_var aElementsId = theObject->GetIDs();
2981 SMESHDS_Mesh* aMesh = GetMeshDS();
2983 for(int i = 0; i < aElementsId->length(); i++) {
2984 CORBA::Long anID = aElementsId[i];
2985 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
2991 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2992 ::SMESH_MeshEditor anEditor( myMesh );
2993 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
2995 GroupsOfElementsID = new SMESH::array_of_long_array;
2996 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
2998 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
2999 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3000 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3001 TListOfIDs& listOfIDs = *arraysIt;
3002 aGroup.length( listOfIDs.size() );
3003 TListOfIDs::iterator idIt = listOfIDs.begin();
3004 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3005 aGroup[ k ] = *idIt;
3009 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3014 //=======================================================================
3015 //function : MergeElements
3017 //=======================================================================
3019 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3023 TPythonDump aTPythonDump;
3024 aTPythonDump << this << ".MergeElements( [";
3026 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3028 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3029 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3030 aListOfListOfElementsID.push_back( list< int >() );
3031 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3032 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3033 CORBA::Long id = anElemsIDGroup[ j ];
3034 aListOfElemsID.push_back( id );
3036 if ( aListOfElemsID.size() < 2 )
3037 aListOfListOfElementsID.pop_back();
3038 if ( i > 0 ) aTPythonDump << ", ";
3039 aTPythonDump << anElemsIDGroup;
3042 ::SMESH_MeshEditor anEditor( myMesh );
3043 anEditor.MergeElements(aListOfListOfElementsID);
3045 aTPythonDump << "] )";
3048 //=======================================================================
3049 //function : MergeEqualElements
3051 //=======================================================================
3053 void SMESH_MeshEditor_i::MergeEqualElements()
3057 ::SMESH_MeshEditor anEditor( myMesh );
3058 anEditor.MergeEqualElements();
3060 TPythonDump() << this << ".MergeEqualElements()";
3063 //================================================================================
3065 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
3066 * move the node closest to the point to point's location and return ID of the node
3068 //================================================================================
3070 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
3073 CORBA::Long theNodeID)
3075 // We keep myNodeSearcher until any mesh modification:
3076 // 1) initData() deletes myNodeSearcher at any edition,
3077 // 2) TNodeSearcherDeleter - at any mesh compute event and mesh change
3081 int nodeID = theNodeID;
3082 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
3085 static TNodeSearcherDeleter deleter;
3086 deleter.Set( myMesh );
3087 if ( !myNodeSearcher ) {
3088 ::SMESH_MeshEditor anEditor( myMesh );
3089 myNodeSearcher = anEditor.GetNodeSearcher();
3092 node = myNodeSearcher->FindClosestTo( p );
3095 nodeID = node->GetID();
3096 if ( myPreviewMode ) // make preview data
3098 // in a preview mesh, make edges linked to a node
3099 TPreviewMesh tmpMesh;
3100 TIDSortedElemSet linkedNodes;
3101 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3102 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3103 for ( ; nIt != linkedNodes.end(); ++nIt )
3105 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
3106 tmpMesh.Copy( &edge );
3109 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
3111 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
3112 // fill preview data
3113 ::SMESH_MeshEditor anEditor( & tmpMesh );
3114 storeResult( anEditor );
3118 GetMeshDS()->MoveNode(node, x, y, z);
3122 if ( !myPreviewMode ) {
3123 TPythonDump() << "nodeID = " << this
3124 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
3125 << ", " << nodeID << " )";
3131 //=======================================================================
3132 //function : convError
3134 //=======================================================================
3136 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
3138 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
3142 RETCASE( SEW_BORDER1_NOT_FOUND );
3143 RETCASE( SEW_BORDER2_NOT_FOUND );
3144 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
3145 RETCASE( SEW_BAD_SIDE_NODES );
3146 RETCASE( SEW_VOLUMES_TO_SPLIT );
3147 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
3148 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
3149 RETCASE( SEW_BAD_SIDE1_NODES );
3150 RETCASE( SEW_BAD_SIDE2_NODES );
3152 return SMESH::SMESH_MeshEditor::SEW_OK;
3155 //=======================================================================
3156 //function : SewFreeBorders
3158 //=======================================================================
3160 SMESH::SMESH_MeshEditor::Sew_Error
3161 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
3162 CORBA::Long SecondNodeID1,
3163 CORBA::Long LastNodeID1,
3164 CORBA::Long FirstNodeID2,
3165 CORBA::Long SecondNodeID2,
3166 CORBA::Long LastNodeID2,
3167 CORBA::Boolean CreatePolygons,
3168 CORBA::Boolean CreatePolyedrs)
3172 SMESHDS_Mesh* aMesh = GetMeshDS();
3174 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3175 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3176 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3177 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3178 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3179 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
3181 if (!aBorderFirstNode ||
3182 !aBorderSecondNode||
3184 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3185 if (!aSide2FirstNode ||
3186 !aSide2SecondNode ||
3188 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3190 TPythonDump() << "error = " << this << ".SewFreeBorders( "
3191 << FirstNodeID1 << ", "
3192 << SecondNodeID1 << ", "
3193 << LastNodeID1 << ", "
3194 << FirstNodeID2 << ", "
3195 << SecondNodeID2 << ", "
3196 << LastNodeID2 << ", "
3197 << CreatePolygons<< ", "
3198 << CreatePolyedrs<< " )";
3200 ::SMESH_MeshEditor anEditor( myMesh );
3201 SMESH::SMESH_MeshEditor::Sew_Error error =
3202 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3212 storeResult(anEditor);
3218 //=======================================================================
3219 //function : SewConformFreeBorders
3221 //=======================================================================
3223 SMESH::SMESH_MeshEditor::Sew_Error
3224 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3225 CORBA::Long SecondNodeID1,
3226 CORBA::Long LastNodeID1,
3227 CORBA::Long FirstNodeID2,
3228 CORBA::Long SecondNodeID2)
3232 SMESHDS_Mesh* aMesh = GetMeshDS();
3234 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3235 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3236 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3237 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3238 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3239 const SMDS_MeshNode* aSide2ThirdNode = 0;
3241 if (!aBorderFirstNode ||
3242 !aBorderSecondNode||
3244 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3245 if (!aSide2FirstNode ||
3247 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3249 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
3250 << FirstNodeID1 << ", "
3251 << SecondNodeID1 << ", "
3252 << LastNodeID1 << ", "
3253 << FirstNodeID2 << ", "
3254 << SecondNodeID2 << " )";
3256 ::SMESH_MeshEditor anEditor( myMesh );
3257 SMESH::SMESH_MeshEditor::Sew_Error error =
3258 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3267 storeResult(anEditor);
3273 //=======================================================================
3274 //function : SewBorderToSide
3276 //=======================================================================
3278 SMESH::SMESH_MeshEditor::Sew_Error
3279 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
3280 CORBA::Long SecondNodeIDOnFreeBorder,
3281 CORBA::Long LastNodeIDOnFreeBorder,
3282 CORBA::Long FirstNodeIDOnSide,
3283 CORBA::Long LastNodeIDOnSide,
3284 CORBA::Boolean CreatePolygons,
3285 CORBA::Boolean CreatePolyedrs)
3289 SMESHDS_Mesh* aMesh = GetMeshDS();
3291 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
3292 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
3293 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
3294 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
3295 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
3296 const SMDS_MeshNode* aSide2ThirdNode = 0;
3298 if (!aBorderFirstNode ||
3299 !aBorderSecondNode||
3301 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3302 if (!aSide2FirstNode ||
3304 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
3306 TPythonDump() << "error = " << this << ".SewBorderToSide( "
3307 << FirstNodeIDOnFreeBorder << ", "
3308 << SecondNodeIDOnFreeBorder << ", "
3309 << LastNodeIDOnFreeBorder << ", "
3310 << FirstNodeIDOnSide << ", "
3311 << LastNodeIDOnSide << ", "
3312 << CreatePolygons << ", "
3313 << CreatePolyedrs << ") ";
3315 ::SMESH_MeshEditor anEditor( myMesh );
3316 SMESH::SMESH_MeshEditor::Sew_Error error =
3317 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3327 storeResult(anEditor);
3333 //=======================================================================
3334 //function : SewSideElements
3336 //=======================================================================
3338 SMESH::SMESH_MeshEditor::Sew_Error
3339 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
3340 const SMESH::long_array& IDsOfSide2Elements,
3341 CORBA::Long NodeID1OfSide1ToMerge,
3342 CORBA::Long NodeID1OfSide2ToMerge,
3343 CORBA::Long NodeID2OfSide1ToMerge,
3344 CORBA::Long NodeID2OfSide2ToMerge)
3348 SMESHDS_Mesh* aMesh = GetMeshDS();
3350 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
3351 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
3352 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
3353 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
3355 if (!aFirstNode1ToMerge ||
3356 !aFirstNode2ToMerge )
3357 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
3358 if (!aSecondNode1ToMerge||
3359 !aSecondNode2ToMerge)
3360 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
3362 TIDSortedElemSet aSide1Elems, aSide2Elems;
3363 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
3364 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
3366 TPythonDump() << "error = " << this << ".SewSideElements( "
3367 << IDsOfSide1Elements << ", "
3368 << IDsOfSide2Elements << ", "
3369 << NodeID1OfSide1ToMerge << ", "
3370 << NodeID1OfSide2ToMerge << ", "
3371 << NodeID2OfSide1ToMerge << ", "
3372 << NodeID2OfSide2ToMerge << ")";
3374 ::SMESH_MeshEditor anEditor( myMesh );
3375 SMESH::SMESH_MeshEditor::Sew_Error error =
3376 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
3379 aSecondNode1ToMerge,
3380 aSecondNode2ToMerge));
3382 storeResult(anEditor);
3387 //================================================================================
3389 * \brief Set new nodes for given element
3390 * \param ide - element id
3391 * \param newIDs - new node ids
3392 * \retval CORBA::Boolean - true if result is OK
3394 //================================================================================
3396 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
3397 const SMESH::long_array& newIDs)
3401 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
3402 if(!elem) return false;
3404 int nbn = newIDs.length();
3406 vector<const SMDS_MeshNode*> aNodes(nbn);
3409 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
3412 aNodes[nbn1] = aNode;
3415 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
3416 << ide << ", " << newIDs << " )";
3418 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
3421 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
3424 //================================================================================
3426 * \brief Update myLastCreated* or myPreviewData
3427 * \param anEditor - it contains last modification results
3429 //================================================================================
3431 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
3433 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
3435 list<int> aNodesConnectivity;
3436 typedef map<int, int> TNodesMap;
3439 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
3440 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
3442 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
3443 int nbEdges = aMeshDS->NbEdges();
3444 int nbFaces = aMeshDS->NbFaces();
3445 int nbVolum = aMeshDS->NbVolumes();
3446 switch ( previewType ) {
3447 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
3448 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
3449 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
3452 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
3453 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
3455 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
3457 while ( itMeshElems->more() ) {
3458 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
3459 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
3462 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
3463 while ( itElemNodes->more() ) {
3464 const SMDS_MeshNode* aMeshNode =
3465 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
3466 int aNodeID = aMeshNode->GetID();
3467 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
3468 if ( anIter == nodesMap.end() ) {
3469 // filling the nodes coordinates
3470 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
3471 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
3472 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
3473 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
3476 aNodesConnectivity.push_back(anIter->second);
3479 // filling the elements types
3480 SMDSAbs_ElementType aType;
3482 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
3483 aType = SMDSAbs_Node;
3487 aType = aMeshElem->GetType();
3488 isPoly = aMeshElem->IsPoly();
3491 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
3492 myPreviewData->elementTypes[i].isPoly = isPoly;
3493 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
3497 myPreviewData->nodesXYZ.length( j );
3499 // filling the elements connectivities
3500 list<int>::iterator aConnIter = aNodesConnectivity.begin();
3501 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
3502 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
3503 myPreviewData->elementConnectivities[i] = *aConnIter;
3509 // add new nodes into myLastCreatedNodes
3510 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
3511 myLastCreatedNodes->length(aSeq.Length());
3512 for(int i=0; i<aSeq.Length(); i++)
3513 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
3516 // add new elements into myLastCreatedElems
3517 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
3518 myLastCreatedElems->length(aSeq.Length());
3519 for(int i=0; i<aSeq.Length(); i++)
3520 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
3524 //================================================================================
3526 * Return data of mesh edition preview
3528 //================================================================================
3530 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
3532 return myPreviewData._retn();
3535 //================================================================================
3537 * \brief Returns list of it's IDs of created nodes
3538 * \retval SMESH::long_array* - list of node ID
3540 //================================================================================
3542 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
3544 return myLastCreatedNodes._retn();
3547 //================================================================================
3549 * \brief Returns list of it's IDs of created elements
3550 * \retval SMESH::long_array* - list of elements' ID
3552 //================================================================================
3554 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
3556 return myLastCreatedElems._retn();
3559 //=======================================================================
3560 //function : ConvertToQuadratic
3562 //=======================================================================
3564 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
3566 ::SMESH_MeshEditor anEditor( myMesh );
3567 anEditor.ConvertToQuadratic(theForce3d);
3568 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
3571 //=======================================================================
3572 //function : ConvertFromQuadratic
3574 //=======================================================================
3576 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
3578 ::SMESH_MeshEditor anEditor( myMesh );
3579 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
3580 TPythonDump() << this << ".ConvertFromQuadratic()";
3584 //=======================================================================
3585 //function : makeMesh
3586 //purpose : create a named imported mesh
3587 //=======================================================================
3589 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
3591 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
3592 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
3593 SALOMEDS::Study_var study = gen->GetCurrentStudy();
3594 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
3595 gen->SetName( meshSO, theMeshName, "Mesh" );
3597 SALOMEDS::StudyBuilder_var builder = study->NewBuilder();
3598 SALOMEDS::GenericAttribute_var anAttr
3599 = builder->FindOrCreateAttribute( meshSO, "AttributePixMap" );
3600 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
3602 return mesh._retn();
3605 //=======================================================================
3606 //function : DumpGroupsList
3608 //=======================================================================
3609 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
3610 const SMESH::ListOfGroups * theGroupList)
3612 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
3613 if(isDumpGroupList) {
3614 theDumpPython << theGroupList << " = ";
3618 //================================================================================
3620 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
3621 \param theNodes - identifiers of nodes to be doubled
3622 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
3623 nodes. If list of element identifiers is empty then nodes are doubled but
3624 they not assigned to elements
3625 \return TRUE if operation has been completed successfully, FALSE otherwise
3626 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
3628 //================================================================================
3630 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
3631 const SMESH::long_array& theModifiedElems )
3635 ::SMESH_MeshEditor aMeshEditor( myMesh );
3636 list< int > aListOfNodes;
3638 for ( i = 0, n = theNodes.length(); i < n; i++ )
3639 aListOfNodes.push_back( theNodes[ i ] );
3641 list< int > aListOfElems;
3642 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
3643 aListOfElems.push_back( theModifiedElems[ i ] );
3645 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
3647 storeResult( aMeshEditor) ;
3652 //================================================================================
3654 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
3655 This method provided for convenience works as DoubleNodes() described above.
3656 \param theNodeId - identifier of node to be doubled.
3657 \param theModifiedElems - identifiers of elements to be updated.
3658 \return TRUE if operation has been completed successfully, FALSE otherwise
3659 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
3661 //================================================================================
3663 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
3664 const SMESH::long_array& theModifiedElems )
3666 SMESH::long_array_var aNodes = new SMESH::long_array;
3667 aNodes->length( 1 );
3668 aNodes[ 0 ] = theNodeId;
3669 return DoubleNodes( aNodes, theModifiedElems );
3672 //================================================================================
3674 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
3675 This method provided for convenience works as DoubleNodes() described above.
3676 \param theNodes - group of nodes to be doubled.
3677 \param theModifiedElems - group of elements to be updated.
3678 \return TRUE if operation has been completed successfully, FALSE otherwise
3679 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
3681 //================================================================================
3683 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(
3684 SMESH::SMESH_GroupBase_ptr theNodes,
3685 SMESH::SMESH_GroupBase_ptr theModifiedElems )
3687 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
3690 SMESH::long_array_var aNodes = theNodes->GetListOfID();
3691 SMESH::long_array_var aModifiedElems;
3692 if ( !CORBA::is_nil( theModifiedElems ) )
3693 aModifiedElems = theModifiedElems->GetListOfID();
3696 aModifiedElems = new SMESH::long_array;
3697 aModifiedElems->length( 0 );
3700 return DoubleNodes( aNodes, aModifiedElems );
3703 //================================================================================
3705 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
3706 This method provided for convenience works as DoubleNodes() described above.
3707 \param theNodes - list of groups of nodes to be doubled
3708 \param theModifiedElems - list of groups of elements to be updated.
3709 \return TRUE if operation has been completed successfully, FALSE otherwise
3710 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
3712 //================================================================================
3714 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(
3715 const SMESH::ListOfGroups& theNodes,
3716 const SMESH::ListOfGroups& theModifiedElems )
3720 ::SMESH_MeshEditor aMeshEditor( myMesh );
3722 std::list< int > aNodes;
3724 for ( i = 0, n = theNodes.length(); i < n; i++ )
3726 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
3727 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
3729 SMESH::long_array_var aCurr = aGrp->GetListOfID();
3730 for ( j = 0, m = aCurr->length(); j < m; j++ )
3731 aNodes.push_back( aCurr[ j ] );
3735 std::list< int > anElems;
3736 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
3738 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
3739 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
3741 SMESH::long_array_var aCurr = aGrp->GetListOfID();
3742 for ( j = 0, m = aCurr->length(); j < m; j++ )
3743 anElems.push_back( aCurr[ j ] );
3747 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
3749 storeResult( aMeshEditor) ;