1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_MeshEditor_i.cxx
24 // Author : Nicolas REJNERI
27 #include "SMESH_MeshEditor_i.hxx"
29 #include "SMDS_Mesh0DElement.hxx"
30 #include "SMDS_MeshEdge.hxx"
31 #include "SMDS_MeshFace.hxx"
32 #include "SMDS_MeshVolume.hxx"
33 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
34 #include "SMESH_MeshEditor.hxx"
35 #include "SMESH_subMeshEventListener.hxx"
36 #include "SMESH_Gen_i.hxx"
37 #include "SMESH_Filter_i.hxx"
38 #include "SMESH_subMesh_i.hxx"
39 #include "SMESH_Group_i.hxx"
40 #include "SMESH_PythonDump.hxx"
42 #include "utilities.h"
43 #include "Utils_ExceptHandlers.hxx"
44 #include "Utils_CorbaException.hxx"
46 #include <BRepAdaptor_Surface.hxx>
47 #include <BRep_Tool.hxx>
48 #include <TopExp_Explorer.hxx>
50 #include <TopoDS_Edge.hxx>
51 #include <TopoDS_Face.hxx>
56 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
60 #include <Standard_Failure.hxx>
63 #include <Standard_ErrorHandler.hxx>
68 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
71 using SMESH::TPythonDump;
75 //=============================================================================
77 * \brief Mesh to apply modifications for preview purposes
79 //=============================================================================
81 struct TPreviewMesh: public SMESH_Mesh
83 SMDSAbs_ElementType myPreviewType; // type to show
85 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
86 _isShapeToMesh = (_id =_studyId =_idDoc = 0);
87 _myMeshDS = new SMESHDS_Mesh( _id, true );
88 myPreviewType = previewElements;
91 virtual ~TPreviewMesh() { delete _myMeshDS; }
92 //!< Copy a set of elements
93 void Copy(const TIDSortedElemSet & theElements,
94 TIDSortedElemSet& theCopyElements,
95 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
96 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
98 // loop on theIDsOfElements
99 TIDSortedElemSet::const_iterator eIt = theElements.begin();
100 for ( ; eIt != theElements.end(); ++eIt )
102 const SMDS_MeshElement* anElem = *eIt;
103 if ( !anElem ) continue;
104 SMDSAbs_ElementType type = anElem->GetType();
105 if ( type == theAvoidType ||
106 ( theSelectType != SMDSAbs_All && type != theSelectType ))
109 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
110 theCopyElements.insert( theCopyElements.end(), anElemCopy );
114 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
116 // copy element nodes
117 int anElemNbNodes = anElem->NbNodes();
118 vector< int > anElemNodesID( anElemNbNodes ) ;
119 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
120 for ( int i = 0; itElemNodes->more(); i++)
122 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
124 anElemNodesID[i] = anElemNode->GetID();
127 // creates a corresponding element on copied nodes
128 SMDS_MeshElement* anElemCopy = 0;
129 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
131 const SMDS_PolyhedralVolumeOfNodes* ph =
132 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
134 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
135 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
138 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
145 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
147 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
148 anElemNode->GetID());
150 };// struct TPreviewMesh
152 static SMESH_NodeSearcher * myNodeSearcher = 0;
154 //=============================================================================
156 * \brief Deleter of myNodeSearcher at any compute event occured
158 //=============================================================================
160 struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
164 TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
166 //!< Delete myNodeSearcher
169 if ( myNodeSearcher ) { delete myNodeSearcher; myNodeSearcher = 0; }
171 typedef map < int, SMESH_subMesh * > TDependsOnMap;
172 //!< The meshod called by submesh: do my main job
173 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
174 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
176 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
178 Unset( sm->GetFather() );
181 //!< set self on all submeshes and delete myNodeSearcher if other mesh is set
182 void Set(SMESH_Mesh* mesh)
184 if ( myMesh && myMesh != mesh ) {
189 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
190 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
191 TDependsOnMap::const_iterator sm;
192 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
193 sm->second->SetEventListener( this, 0, sm->second );
196 //!< delete self from all submeshes
197 void Unset(SMESH_Mesh* mesh)
199 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
200 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
201 TDependsOnMap::const_iterator sm;
202 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
203 sm->second->DeleteEventListener( this );
209 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
211 TCollection_AsciiString typeStr;
212 switch ( theMirrorType ) {
213 case SMESH::SMESH_MeshEditor::POINT:
214 typeStr = "SMESH.SMESH_MeshEditor.POINT";
216 case SMESH::SMESH_MeshEditor::AXIS:
217 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
220 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
226 //=============================================================================
230 //=============================================================================
232 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
235 myMesh = & theMesh->GetImpl();
236 myPreviewMode = isPreview;
239 //================================================================================
243 //================================================================================
245 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
249 //================================================================================
251 * \brief Clear members
253 //================================================================================
255 void SMESH_MeshEditor_i::initData()
257 if ( myPreviewMode ) {
258 myPreviewData = new SMESH::MeshPreviewStruct();
261 myLastCreatedElems = new SMESH::long_array();
262 myLastCreatedNodes = new SMESH::long_array();
263 TNodeSearcherDeleter::Delete();
267 //=============================================================================
271 //=============================================================================
274 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
278 ::SMESH_MeshEditor anEditor( myMesh );
281 for (int i = 0; i < IDsOfElements.length(); i++)
282 IdList.push_back( IDsOfElements[i] );
284 // Update Python script
285 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
287 TPythonDump() << "print 'RemoveElements: ', isDone";
290 return anEditor.Remove( IdList, false );
293 //=============================================================================
297 //=============================================================================
299 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
303 ::SMESH_MeshEditor anEditor( myMesh );
305 for (int i = 0; i < IDsOfNodes.length(); i++)
306 IdList.push_back( IDsOfNodes[i] );
308 // Update Python script
309 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
311 TPythonDump() << "print 'RemoveNodes: ', isDone";
314 return anEditor.Remove( IdList, true );
317 //=============================================================================
321 //=============================================================================
323 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
324 CORBA::Double y, CORBA::Double z)
328 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
330 // Update Python script
331 TPythonDump() << "nodeID = " << this << ".AddNode( "
332 << x << ", " << y << ", " << z << " )";
337 //=============================================================================
341 //=============================================================================
342 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
346 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
347 SMDS_MeshElement* elem = GetMeshDS()->Add0DElement(aNode);
349 // Update Python script
350 TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
353 return elem->GetID();
358 //=============================================================================
362 //=============================================================================
364 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
368 int NbNodes = IDsOfNodes.length();
369 SMDS_MeshElement* elem = 0;
372 CORBA::Long index1 = IDsOfNodes[0];
373 CORBA::Long index2 = IDsOfNodes[1];
374 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
376 // Update Python script
377 TPythonDump() << "edge = " << this << ".AddEdge([ "
378 << index1 << ", " << index2 <<" ])";
381 CORBA::Long n1 = IDsOfNodes[0];
382 CORBA::Long n2 = IDsOfNodes[1];
383 CORBA::Long n12 = IDsOfNodes[2];
384 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
385 GetMeshDS()->FindNode(n2),
386 GetMeshDS()->FindNode(n12));
387 // Update Python script
388 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
389 <<n1<<", "<<n2<<", "<<n12<<" ])";
393 return elem->GetID();
398 //=============================================================================
402 //=============================================================================
404 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
408 int NbNodes = IDsOfNodes.length();
414 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
415 for (int i = 0; i < NbNodes; i++)
416 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
418 SMDS_MeshElement* elem = 0;
420 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
422 else if (NbNodes == 4) {
423 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
425 else if (NbNodes == 6) {
426 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
429 else if (NbNodes == 8) {
430 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
431 nodes[4], nodes[5], nodes[6], nodes[7]);
434 // Update Python script
435 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
438 return elem->GetID();
443 //=============================================================================
447 //=============================================================================
448 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
449 (const SMESH::long_array & IDsOfNodes)
453 int NbNodes = IDsOfNodes.length();
454 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
455 for (int i = 0; i < NbNodes; i++)
456 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
458 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
460 // Update Python script
461 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
463 TPythonDump() << "print 'AddPolygonalFace: ', faceID";
467 return elem->GetID();
472 //=============================================================================
476 //=============================================================================
478 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
482 int NbNodes = IDsOfNodes.length();
483 vector< const SMDS_MeshNode*> n(NbNodes);
484 for(int i=0;i<NbNodes;i++)
485 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
487 SMDS_MeshElement* elem = 0;
490 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
491 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
492 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
493 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
494 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
495 n[6],n[7],n[8],n[9]);
497 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
498 n[7],n[8],n[9],n[10],n[11],n[12]);
500 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
501 n[9],n[10],n[11],n[12],n[13],n[14]);
503 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
504 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
505 n[15],n[16],n[17],n[18],n[19]);
509 // Update Python script
510 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
512 TPythonDump() << "print 'AddVolume: ', volID";
516 return elem->GetID();
521 //=============================================================================
523 * AddPolyhedralVolume
525 //=============================================================================
526 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume
527 (const SMESH::long_array & IDsOfNodes,
528 const SMESH::long_array & Quantities)
532 int NbNodes = IDsOfNodes.length();
533 std::vector<const SMDS_MeshNode*> n (NbNodes);
534 for (int i = 0; i < NbNodes; i++)
535 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
537 int NbFaces = Quantities.length();
538 std::vector<int> q (NbFaces);
539 for (int j = 0; j < NbFaces; j++)
540 q[j] = Quantities[j];
542 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
544 // Update Python script
545 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
546 << IDsOfNodes << ", " << Quantities << " )";
548 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
552 return elem->GetID();
557 //=============================================================================
559 * AddPolyhedralVolumeByFaces
561 //=============================================================================
562 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
563 (const SMESH::long_array & IdsOfFaces)
567 int NbFaces = IdsOfFaces.length();
568 std::vector<const SMDS_MeshNode*> poly_nodes;
569 std::vector<int> quantities (NbFaces);
571 for (int i = 0; i < NbFaces; i++) {
572 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
573 quantities[i] = aFace->NbNodes();
575 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
577 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
581 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
583 // Update Python script
584 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
585 << IdsOfFaces << " )";
587 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
591 return elem->GetID();
596 //=============================================================================
598 * \brief Bind a node to a vertex
599 * \param NodeID - node ID
600 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
601 * \retval boolean - false if NodeID or VertexID is invalid
603 //=============================================================================
605 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
606 throw (SALOME::SALOME_Exception)
608 Unexpect aCatch(SALOME_SalomeException);
610 SMESHDS_Mesh * mesh = GetMeshDS();
611 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
613 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
615 if ( mesh->MaxShapeIndex() < VertexID )
616 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
618 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
619 if ( shape.ShapeType() != TopAbs_VERTEX )
620 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
622 mesh->SetNodeOnVertex( node, VertexID );
625 //=============================================================================
627 * \brief Store node position on an edge
628 * \param NodeID - node ID
629 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
630 * \param paramOnEdge - parameter on edge where the node is located
631 * \retval boolean - false if any parameter is invalid
633 //=============================================================================
635 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
636 CORBA::Double paramOnEdge)
637 throw (SALOME::SALOME_Exception)
639 Unexpect aCatch(SALOME_SalomeException);
641 SMESHDS_Mesh * mesh = GetMeshDS();
642 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
644 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
646 if ( mesh->MaxShapeIndex() < EdgeID )
647 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
649 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
650 if ( shape.ShapeType() != TopAbs_EDGE )
651 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
654 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
655 if ( paramOnEdge < f || paramOnEdge > l )
656 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
658 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
661 //=============================================================================
663 * \brief Store node position on a face
664 * \param NodeID - node ID
665 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
666 * \param u - U parameter on face where the node is located
667 * \param v - V parameter on face where the node is located
668 * \retval boolean - false if any parameter is invalid
670 //=============================================================================
672 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
673 CORBA::Double u, CORBA::Double v)
674 throw (SALOME::SALOME_Exception)
676 Unexpect aCatch(SALOME_SalomeException);
678 SMESHDS_Mesh * mesh = GetMeshDS();
679 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
681 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
683 if ( mesh->MaxShapeIndex() < FaceID )
684 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
686 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
687 if ( shape.ShapeType() != TopAbs_FACE )
688 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
690 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
691 bool isOut = ( u < surf.FirstUParameter() ||
692 u > surf.LastUParameter() ||
693 v < surf.FirstVParameter() ||
694 v > surf.LastVParameter() );
698 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
699 << " u( " << surf.FirstUParameter()
700 << "," << surf.LastUParameter()
701 << ") v( " << surf.FirstVParameter()
702 << "," << surf.LastVParameter() << ")" );
704 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
707 mesh->SetNodeOnFace( node, FaceID, u, v );
710 //=============================================================================
712 * \brief Bind a node to a solid
713 * \param NodeID - node ID
714 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
715 * \retval boolean - false if NodeID or SolidID is invalid
717 //=============================================================================
719 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
720 throw (SALOME::SALOME_Exception)
722 Unexpect aCatch(SALOME_SalomeException);
724 SMESHDS_Mesh * mesh = GetMeshDS();
725 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
727 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
729 if ( mesh->MaxShapeIndex() < SolidID )
730 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
732 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
733 if ( shape.ShapeType() != TopAbs_SOLID &&
734 shape.ShapeType() != TopAbs_SHELL)
735 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
737 mesh->SetNodeInVolume( node, SolidID );
740 //=============================================================================
742 * \brief Bind an element to a shape
743 * \param ElementID - element ID
744 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
745 * \retval boolean - false if ElementID or ShapeID is invalid
747 //=============================================================================
749 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
751 throw (SALOME::SALOME_Exception)
753 Unexpect aCatch(SALOME_SalomeException);
755 SMESHDS_Mesh * mesh = GetMeshDS();
756 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
758 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
760 if ( mesh->MaxShapeIndex() < ShapeID )
761 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
763 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
764 if ( shape.ShapeType() != TopAbs_EDGE &&
765 shape.ShapeType() != TopAbs_FACE &&
766 shape.ShapeType() != TopAbs_SOLID &&
767 shape.ShapeType() != TopAbs_SHELL )
768 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
770 mesh->SetMeshElementOnShape( elem, ShapeID );
774 //=============================================================================
778 //=============================================================================
780 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
787 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
791 GetMeshDS()->MoveNode(node, x, y, z);
793 // Update Python script
794 TPythonDump() << "isDone = " << this << ".MoveNode( "
795 << NodeID << ", " << x << ", " << y << ", " << z << " )";
800 //=============================================================================
804 //=============================================================================
806 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
811 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
812 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
816 // Update Python script
817 TPythonDump() << "isDone = " << this << ".InverseDiag( "
818 << NodeID1 << ", " << NodeID2 << " )";
820 ::SMESH_MeshEditor aMeshEditor( myMesh );
821 return aMeshEditor.InverseDiag ( n1, n2 );
824 //=============================================================================
828 //=============================================================================
830 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
835 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
836 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
840 // Update Python script
841 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
842 << NodeID1 << ", " << NodeID2 << " )";
844 ::SMESH_MeshEditor aMeshEditor( myMesh );
846 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
848 storeResult(aMeshEditor);
853 //=============================================================================
857 //=============================================================================
859 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
863 ::SMESH_MeshEditor anEditor( myMesh );
864 for (int i = 0; i < IDsOfElements.length(); i++)
866 CORBA::Long index = IDsOfElements[i];
867 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
869 anEditor.Reorient( elem );
871 // Update Python script
872 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
878 //=============================================================================
882 //=============================================================================
884 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
888 SMESH::long_array_var anElementsId = theObject->GetIDs();
889 CORBA::Boolean isDone = Reorient(anElementsId);
891 // Clear python line, created by Reorient()
892 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
893 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
895 // Update Python script
896 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
903 //================================================================================
905 * \brief function for conversion long_array to TIDSortedElemSet
906 * \param IDs - array of IDs
907 * \param aMesh - mesh
908 * \param aMap - collection to fill
909 * \param aType - element type
911 //================================================================================
913 void arrayToSet(const SMESH::long_array & IDs,
914 const SMESHDS_Mesh* aMesh,
915 TIDSortedElemSet& aMap,
916 const SMDSAbs_ElementType aType = SMDSAbs_All )
918 for (int i=0; i<IDs.length(); i++) {
919 CORBA::Long ind = IDs[i];
920 const SMDS_MeshElement * elem =
921 (aType == SMDSAbs_Node ? aMesh->FindNode(ind)
922 : aMesh->FindElement(ind));
923 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
929 //=============================================================================
933 //=============================================================================
934 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
935 SMESH::NumericalFunctor_ptr Criterion,
936 CORBA::Double MaxAngle)
940 SMESHDS_Mesh* aMesh = GetMeshDS();
941 TIDSortedElemSet faces;
942 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
944 SMESH::NumericalFunctor_i* aNumericalFunctor =
945 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
946 SMESH::Controls::NumericalFunctorPtr aCrit;
947 if ( !aNumericalFunctor )
948 aCrit.reset( new SMESH::Controls::AspectRatio() );
950 aCrit = aNumericalFunctor->GetNumericalFunctor();
952 // Update Python script
953 TPythonDump() << "isDone = " << this << ".TriToQuad( "
954 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
956 TPythonDump() << "print 'TriToQuad: ', isDone";
959 ::SMESH_MeshEditor anEditor( myMesh );
961 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
963 storeResult(anEditor);
969 //=============================================================================
973 //=============================================================================
974 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
975 SMESH::NumericalFunctor_ptr Criterion,
976 CORBA::Double MaxAngle)
980 SMESH::long_array_var anElementsId = theObject->GetIDs();
981 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
983 // Clear python line(s), created by TriToQuad()
984 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
985 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
987 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
990 SMESH::NumericalFunctor_i* aNumericalFunctor =
991 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
993 // Update Python script
994 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
995 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
997 TPythonDump() << "print 'TriToQuadObject: ', isDone";
1004 //=============================================================================
1008 //=============================================================================
1009 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
1010 SMESH::NumericalFunctor_ptr Criterion)
1014 SMESHDS_Mesh* aMesh = GetMeshDS();
1015 TIDSortedElemSet faces;
1016 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1018 SMESH::NumericalFunctor_i* aNumericalFunctor =
1019 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1020 SMESH::Controls::NumericalFunctorPtr aCrit;
1021 if ( !aNumericalFunctor )
1022 aCrit.reset( new SMESH::Controls::AspectRatio() );
1024 aCrit = aNumericalFunctor->GetNumericalFunctor();
1027 // Update Python script
1028 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1030 TPythonDump() << "print 'QuadToTri: ', isDone";
1033 ::SMESH_MeshEditor anEditor( myMesh );
1034 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1036 storeResult(anEditor);
1042 //=============================================================================
1046 //=============================================================================
1047 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1048 SMESH::NumericalFunctor_ptr Criterion)
1052 SMESH::long_array_var anElementsId = theObject->GetIDs();
1053 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1055 // Clear python line(s), created by QuadToTri()
1056 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1057 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1059 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1062 SMESH::NumericalFunctor_i* aNumericalFunctor =
1063 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1065 // Update Python script
1066 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1068 TPythonDump() << "print 'QuadToTriObject: ', isDone";
1075 //=============================================================================
1079 //=============================================================================
1080 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1081 CORBA::Boolean Diag13)
1085 SMESHDS_Mesh* aMesh = GetMeshDS();
1086 TIDSortedElemSet faces;
1087 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1089 // Update Python script
1090 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1091 << IDsOfElements << ", " << Diag13 << " )";
1093 TPythonDump() << "print 'SplitQuad: ', isDone";
1096 ::SMESH_MeshEditor anEditor( myMesh );
1097 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1099 storeResult(anEditor);
1105 //=============================================================================
1109 //=============================================================================
1110 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1111 CORBA::Boolean Diag13)
1115 SMESH::long_array_var anElementsId = theObject->GetIDs();
1116 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1118 // Clear python line(s), created by SplitQuad()
1119 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1120 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1122 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1125 // Update Python script
1126 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1127 << theObject << ", " << Diag13 << " )";
1129 TPythonDump() << "print 'SplitQuadObject: ', isDone";
1136 //=============================================================================
1140 //=============================================================================
1141 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1142 SMESH::NumericalFunctor_ptr Criterion)
1144 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1145 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1147 SMESH::NumericalFunctor_i* aNumericalFunctor =
1148 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1149 SMESH::Controls::NumericalFunctorPtr aCrit;
1150 if (aNumericalFunctor)
1151 aCrit = aNumericalFunctor->GetNumericalFunctor();
1153 aCrit.reset(new SMESH::Controls::AspectRatio());
1155 ::SMESH_MeshEditor anEditor (myMesh);
1156 return anEditor.BestSplit(quad, aCrit);
1162 //=======================================================================
1165 //=======================================================================
1168 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1169 const SMESH::long_array & IDsOfFixedNodes,
1170 CORBA::Long MaxNbOfIterations,
1171 CORBA::Double MaxAspectRatio,
1172 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1174 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1175 MaxAspectRatio, Method, false );
1179 //=======================================================================
1180 //function : SmoothParametric
1182 //=======================================================================
1185 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1186 const SMESH::long_array & IDsOfFixedNodes,
1187 CORBA::Long MaxNbOfIterations,
1188 CORBA::Double MaxAspectRatio,
1189 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1191 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1192 MaxAspectRatio, Method, true );
1196 //=======================================================================
1197 //function : SmoothObject
1199 //=======================================================================
1202 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1203 const SMESH::long_array & IDsOfFixedNodes,
1204 CORBA::Long MaxNbOfIterations,
1205 CORBA::Double MaxAspectRatio,
1206 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1208 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1209 MaxAspectRatio, Method, false);
1213 //=======================================================================
1214 //function : SmoothParametricObject
1216 //=======================================================================
1219 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1220 const SMESH::long_array & IDsOfFixedNodes,
1221 CORBA::Long MaxNbOfIterations,
1222 CORBA::Double MaxAspectRatio,
1223 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1225 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1226 MaxAspectRatio, Method, true);
1230 //=============================================================================
1234 //=============================================================================
1237 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1238 const SMESH::long_array & IDsOfFixedNodes,
1239 CORBA::Long MaxNbOfIterations,
1240 CORBA::Double MaxAspectRatio,
1241 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1246 SMESHDS_Mesh* aMesh = GetMeshDS();
1248 TIDSortedElemSet elements;
1249 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1251 set<const SMDS_MeshNode*> fixedNodes;
1252 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1253 CORBA::Long index = IDsOfFixedNodes[i];
1254 const SMDS_MeshNode * node = aMesh->FindNode(index);
1256 fixedNodes.insert( node );
1258 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1259 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1260 method = ::SMESH_MeshEditor::CENTROIDAL;
1262 ::SMESH_MeshEditor anEditor( myMesh );
1263 anEditor.Smooth(elements, fixedNodes, method,
1264 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1266 storeResult(anEditor);
1268 // Update Python script
1269 TPythonDump() << "isDone = " << this << "."
1270 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1271 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1272 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1273 << "SMESH.SMESH_MeshEditor."
1274 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1275 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1277 TPythonDump() << "print 'Smooth: ', isDone";
1284 //=============================================================================
1288 //=============================================================================
1291 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1292 const SMESH::long_array & IDsOfFixedNodes,
1293 CORBA::Long MaxNbOfIterations,
1294 CORBA::Double MaxAspectRatio,
1295 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1300 SMESH::long_array_var anElementsId = theObject->GetIDs();
1301 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1302 MaxAspectRatio, Method, IsParametric);
1304 // Clear python line(s), created by Smooth()
1305 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1306 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1308 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1311 // Update Python script
1312 TPythonDump() << "isDone = " << this << "."
1313 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1314 << theObject << ", " << IDsOfFixedNodes << ", "
1315 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1316 << "SMESH.SMESH_MeshEditor."
1317 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1318 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1320 TPythonDump() << "print 'SmoothObject: ', isDone";
1327 //=============================================================================
1331 //=============================================================================
1333 void SMESH_MeshEditor_i::RenumberNodes()
1335 // Update Python script
1336 TPythonDump() << this << ".RenumberNodes()";
1338 GetMeshDS()->Renumber( true );
1342 //=============================================================================
1346 //=============================================================================
1348 void SMESH_MeshEditor_i::RenumberElements()
1350 // Update Python script
1351 TPythonDump() << this << ".RenumberElements()";
1353 GetMeshDS()->Renumber( false );
1356 //=======================================================================
1358 * \brief Return groups by their IDs
1360 //=======================================================================
1362 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1366 myMesh_i->CreateGroupServants();
1367 return myMesh_i->GetGroups( *groupIDs );
1370 //=======================================================================
1371 //function : rotationSweep
1373 //=======================================================================
1375 SMESH::ListOfGroups*
1376 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1377 const SMESH::AxisStruct & theAxis,
1378 CORBA::Double theAngleInRadians,
1379 CORBA::Long theNbOfSteps,
1380 CORBA::Double theTolerance,
1381 const bool theMakeGroups,
1382 const SMDSAbs_ElementType theElementType)
1386 TIDSortedElemSet inElements, copyElements;
1387 arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType);
1389 TIDSortedElemSet* workElements = & inElements;
1390 TPreviewMesh tmpMesh( SMDSAbs_Face );
1391 SMESH_Mesh* mesh = 0;
1392 bool makeWalls=true;
1393 if ( myPreviewMode )
1395 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1396 tmpMesh.Copy( inElements, copyElements, select, avoid );
1398 workElements = & copyElements;
1399 //makeWalls = false;
1406 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1407 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1409 ::SMESH_MeshEditor anEditor( mesh );
1410 ::SMESH_MeshEditor::PGroupIDs groupIds =
1411 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1412 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1413 storeResult(anEditor);
1415 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1418 //=======================================================================
1419 //function : RotationSweep
1421 //=======================================================================
1423 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1424 const SMESH::AxisStruct & theAxis,
1425 CORBA::Double theAngleInRadians,
1426 CORBA::Long theNbOfSteps,
1427 CORBA::Double theTolerance)
1429 if ( !myPreviewMode ) {
1430 TPythonDump() << this << ".RotationSweep( "
1431 << theIDsOfElements << ", "
1433 << theAngleInRadians << ", "
1434 << theNbOfSteps << ", "
1435 << theTolerance << " )";
1437 rotationSweep(theIDsOfElements,
1445 //=======================================================================
1446 //function : RotationSweepMakeGroups
1448 //=======================================================================
1450 SMESH::ListOfGroups*
1451 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1452 const SMESH::AxisStruct& theAxis,
1453 CORBA::Double theAngleInRadians,
1454 CORBA::Long theNbOfSteps,
1455 CORBA::Double theTolerance)
1457 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1463 if ( !myPreviewMode ) {
1464 TPythonDump aPythonDump;
1465 DumpGroupsList(aPythonDump,aGroups);
1466 aPythonDump<< this << ".RotationSweepMakeGroups( "
1467 << theIDsOfElements << ", "
1469 << theAngleInRadians << ", "
1470 << theNbOfSteps << ", "
1471 << theTolerance << " )";
1476 //=======================================================================
1477 //function : RotationSweepObject
1479 //=======================================================================
1481 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1482 const SMESH::AxisStruct & theAxis,
1483 CORBA::Double theAngleInRadians,
1484 CORBA::Long theNbOfSteps,
1485 CORBA::Double theTolerance)
1487 if ( !myPreviewMode ) {
1488 TPythonDump() << this << ".RotationSweepObject( "
1489 << theObject << ", "
1491 << theAngleInRadians << ", "
1492 << theNbOfSteps << ", "
1493 << theTolerance << " )";
1495 SMESH::long_array_var anElementsId = theObject->GetIDs();
1496 rotationSweep(anElementsId,
1504 //=======================================================================
1505 //function : RotationSweepObject1D
1507 //=======================================================================
1509 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1510 const SMESH::AxisStruct & theAxis,
1511 CORBA::Double theAngleInRadians,
1512 CORBA::Long theNbOfSteps,
1513 CORBA::Double theTolerance)
1515 if ( !myPreviewMode ) {
1516 TPythonDump() << this << ".RotationSweepObject1D( "
1517 << theObject << ", "
1519 << theAngleInRadians << ", "
1520 << theNbOfSteps << ", "
1521 << theTolerance << " )";
1523 SMESH::long_array_var anElementsId = theObject->GetIDs();
1524 rotationSweep(anElementsId,
1533 //=======================================================================
1534 //function : RotationSweepObject2D
1536 //=======================================================================
1538 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1539 const SMESH::AxisStruct & theAxis,
1540 CORBA::Double theAngleInRadians,
1541 CORBA::Long theNbOfSteps,
1542 CORBA::Double theTolerance)
1544 if ( !myPreviewMode ) {
1545 TPythonDump() << this << ".RotationSweepObject2D( "
1546 << theObject << ", "
1548 << theAngleInRadians << ", "
1549 << theNbOfSteps << ", "
1550 << theTolerance << " )";
1552 SMESH::long_array_var anElementsId = theObject->GetIDs();
1553 rotationSweep(anElementsId,
1562 //=======================================================================
1563 //function : RotationSweepObjectMakeGroups
1565 //=======================================================================
1567 SMESH::ListOfGroups*
1568 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1569 const SMESH::AxisStruct& theAxis,
1570 CORBA::Double theAngleInRadians,
1571 CORBA::Long theNbOfSteps,
1572 CORBA::Double theTolerance)
1574 SMESH::long_array_var anElementsId = theObject->GetIDs();
1575 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1581 if ( !myPreviewMode ) {
1582 TPythonDump aPythonDump;
1583 DumpGroupsList(aPythonDump,aGroups);
1584 aPythonDump<< this << ".RotationSweepObjectMakeGroups( "
1585 << theObject << ", "
1587 << theAngleInRadians << ", "
1588 << theNbOfSteps << ", "
1589 << theTolerance << " )";
1594 //=======================================================================
1595 //function : RotationSweepObject1DMakeGroups
1597 //=======================================================================
1599 SMESH::ListOfGroups*
1600 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1601 const SMESH::AxisStruct& theAxis,
1602 CORBA::Double theAngleInRadians,
1603 CORBA::Long theNbOfSteps,
1604 CORBA::Double theTolerance)
1606 SMESH::long_array_var anElementsId = theObject->GetIDs();
1607 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1614 if ( !myPreviewMode ) {
1615 TPythonDump aPythonDump;
1616 DumpGroupsList(aPythonDump,aGroups);
1617 aPythonDump<< this << ".RotationSweepObject1DMakeGroups( "
1618 << theObject << ", "
1620 << theAngleInRadians << ", "
1621 << theNbOfSteps << ", "
1622 << theTolerance << " )";
1627 //=======================================================================
1628 //function : RotationSweepObject2DMakeGroups
1630 //=======================================================================
1632 SMESH::ListOfGroups*
1633 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1634 const SMESH::AxisStruct& theAxis,
1635 CORBA::Double theAngleInRadians,
1636 CORBA::Long theNbOfSteps,
1637 CORBA::Double theTolerance)
1639 SMESH::long_array_var anElementsId = theObject->GetIDs();
1640 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1647 if ( !myPreviewMode ) {
1648 TPythonDump aPythonDump;
1649 DumpGroupsList(aPythonDump,aGroups);
1650 aPythonDump<< this << ".RotationSweepObject2DMakeGroups( "
1651 << theObject << ", "
1653 << theAngleInRadians << ", "
1654 << theNbOfSteps << ", "
1655 << theTolerance << " )";
1661 //=======================================================================
1662 //function : extrusionSweep
1664 //=======================================================================
1666 SMESH::ListOfGroups*
1667 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1668 const SMESH::DirStruct & theStepVector,
1669 CORBA::Long theNbOfSteps,
1670 const bool theMakeGroups,
1671 const SMDSAbs_ElementType theElementType)
1679 TIDSortedElemSet elements;
1680 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1682 const SMESH::PointStruct * P = &theStepVector.PS;
1683 gp_Vec stepVec( P->x, P->y, P->z );
1685 TElemOfElemListMap aHystory;
1686 ::SMESH_MeshEditor anEditor( myMesh );
1687 ::SMESH_MeshEditor::PGroupIDs groupIds =
1688 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1690 storeResult(anEditor);
1692 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1694 } catch(Standard_Failure) {
1695 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1696 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1701 //=======================================================================
1702 //function : ExtrusionSweep
1704 //=======================================================================
1706 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1707 const SMESH::DirStruct & theStepVector,
1708 CORBA::Long theNbOfSteps)
1710 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1711 if ( !myPreviewMode ) {
1712 TPythonDump() << this << ".ExtrusionSweep( "
1713 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1718 //=======================================================================
1719 //function : ExtrusionSweepObject
1721 //=======================================================================
1723 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1724 const SMESH::DirStruct & theStepVector,
1725 CORBA::Long theNbOfSteps)
1727 SMESH::long_array_var anElementsId = theObject->GetIDs();
1728 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1729 if ( !myPreviewMode ) {
1730 TPythonDump() << this << ".ExtrusionSweepObject( "
1731 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1735 //=======================================================================
1736 //function : ExtrusionSweepObject1D
1738 //=======================================================================
1740 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1741 const SMESH::DirStruct & theStepVector,
1742 CORBA::Long theNbOfSteps)
1744 SMESH::long_array_var anElementsId = theObject->GetIDs();
1745 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1746 if ( !myPreviewMode ) {
1747 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1748 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1752 //=======================================================================
1753 //function : ExtrusionSweepObject2D
1755 //=======================================================================
1757 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1758 const SMESH::DirStruct & theStepVector,
1759 CORBA::Long theNbOfSteps)
1761 SMESH::long_array_var anElementsId = theObject->GetIDs();
1762 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1763 if ( !myPreviewMode ) {
1764 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1765 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1769 //=======================================================================
1770 //function : ExtrusionSweepMakeGroups
1772 //=======================================================================
1774 SMESH::ListOfGroups*
1775 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1776 const SMESH::DirStruct& theStepVector,
1777 CORBA::Long theNbOfSteps)
1779 SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1781 if ( !myPreviewMode ) {
1782 TPythonDump aPythonDump;
1783 DumpGroupsList(aPythonDump,aGroups);
1784 aPythonDump << this << ".ExtrusionSweepMakeGroups( "
1785 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1789 //=======================================================================
1790 //function : ExtrusionSweepObjectMakeGroups
1792 //=======================================================================
1794 SMESH::ListOfGroups*
1795 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1796 const SMESH::DirStruct& theStepVector,
1797 CORBA::Long theNbOfSteps)
1799 SMESH::long_array_var anElementsId = theObject->GetIDs();
1800 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1802 if ( !myPreviewMode ) {
1803 TPythonDump aPythonDump;
1804 DumpGroupsList(aPythonDump,aGroups);
1805 aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( "
1806 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1811 //=======================================================================
1812 //function : ExtrusionSweepObject1DMakeGroups
1814 //=======================================================================
1816 SMESH::ListOfGroups*
1817 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1818 const SMESH::DirStruct& theStepVector,
1819 CORBA::Long theNbOfSteps)
1821 SMESH::long_array_var anElementsId = theObject->GetIDs();
1822 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1823 if ( !myPreviewMode ) {
1824 TPythonDump aPythonDump;
1825 DumpGroupsList(aPythonDump,aGroups);
1826 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( "
1827 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1832 //=======================================================================
1833 //function : ExtrusionSweepObject2DMakeGroups
1835 //=======================================================================
1837 SMESH::ListOfGroups*
1838 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1839 const SMESH::DirStruct& theStepVector,
1840 CORBA::Long theNbOfSteps)
1842 SMESH::long_array_var anElementsId = theObject->GetIDs();
1843 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1844 if ( !myPreviewMode ) {
1845 TPythonDump aPythonDump;
1846 DumpGroupsList(aPythonDump,aGroups);
1847 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( "
1848 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1854 //=======================================================================
1855 //function : advancedExtrusion
1857 //=======================================================================
1859 SMESH::ListOfGroups*
1860 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1861 const SMESH::DirStruct & theStepVector,
1862 CORBA::Long theNbOfSteps,
1863 CORBA::Long theExtrFlags,
1864 CORBA::Double theSewTolerance,
1865 const bool theMakeGroups)
1869 TIDSortedElemSet elements;
1870 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1872 const SMESH::PointStruct * P = &theStepVector.PS;
1873 gp_Vec stepVec( P->x, P->y, P->z );
1875 ::SMESH_MeshEditor anEditor( myMesh );
1876 TElemOfElemListMap aHystory;
1877 ::SMESH_MeshEditor::PGroupIDs groupIds =
1878 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1879 theMakeGroups, theExtrFlags, theSewTolerance);
1880 storeResult(anEditor);
1882 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1885 //=======================================================================
1886 //function : AdvancedExtrusion
1888 //=======================================================================
1890 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1891 const SMESH::DirStruct & theStepVector,
1892 CORBA::Long theNbOfSteps,
1893 CORBA::Long theExtrFlags,
1894 CORBA::Double theSewTolerance)
1896 if ( !myPreviewMode ) {
1897 TPythonDump() << "stepVector = " << theStepVector;
1898 TPythonDump() << this << ".AdvancedExtrusion("
1901 << theNbOfSteps << ","
1902 << theExtrFlags << ", "
1903 << theSewTolerance << " )";
1905 advancedExtrusion( theIDsOfElements,
1913 //=======================================================================
1914 //function : AdvancedExtrusionMakeGroups
1916 //=======================================================================
1918 SMESH::ListOfGroups*
1919 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1920 const SMESH::DirStruct& theStepVector,
1921 CORBA::Long theNbOfSteps,
1922 CORBA::Long theExtrFlags,
1923 CORBA::Double theSewTolerance)
1925 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
1932 if ( !myPreviewMode ) {
1933 TPythonDump() << "stepVector = " << theStepVector;
1934 TPythonDump aPythonDump;
1935 DumpGroupsList(aPythonDump,aGroups);
1936 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
1939 << theNbOfSteps << ","
1940 << theExtrFlags << ", "
1941 << theSewTolerance << " )";
1947 //================================================================================
1949 * \brief Convert extrusion error to IDL enum
1951 //================================================================================
1953 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1955 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1959 RETCASE( EXTR_NO_ELEMENTS );
1960 RETCASE( EXTR_PATH_NOT_EDGE );
1961 RETCASE( EXTR_BAD_PATH_SHAPE );
1962 RETCASE( EXTR_BAD_STARTING_NODE );
1963 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1964 RETCASE( EXTR_CANT_GET_TANGENT );
1966 return SMESH::SMESH_MeshEditor::EXTR_OK;
1970 //=======================================================================
1971 //function : extrusionAlongPath
1973 //=======================================================================
1975 SMESH::ListOfGroups*
1976 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1977 SMESH::SMESH_Mesh_ptr thePathMesh,
1978 GEOM::GEOM_Object_ptr thePathShape,
1979 CORBA::Long theNodeStart,
1980 CORBA::Boolean theHasAngles,
1981 const SMESH::double_array & theAngles,
1982 CORBA::Boolean theHasRefPoint,
1983 const SMESH::PointStruct & theRefPoint,
1984 const bool theMakeGroups,
1985 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
1986 const SMDSAbs_ElementType theElementType)
1990 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1991 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1994 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1996 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1997 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1999 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
2000 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2004 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
2006 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2010 TIDSortedElemSet elements;
2011 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
2013 list<double> angles;
2014 for (int i = 0; i < theAngles.length(); i++) {
2015 angles.push_back( theAngles[i] );
2018 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
2020 int nbOldGroups = myMesh->NbGroup();
2022 ::SMESH_MeshEditor anEditor( myMesh );
2023 ::SMESH_MeshEditor::Extrusion_Error error =
2024 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
2025 theHasAngles, angles, false,
2026 theHasRefPoint, refPnt, theMakeGroups );
2027 storeResult(anEditor);
2028 theError = convExtrError( error );
2030 if ( theMakeGroups ) {
2031 list<int> groupIDs = myMesh->GetGroupIds();
2032 list<int>::iterator newBegin = groupIDs.begin();
2033 std::advance( newBegin, nbOldGroups ); // skip old groups
2034 groupIDs.erase( groupIDs.begin(), newBegin );
2035 return getGroups( & groupIDs );
2041 //=======================================================================
2042 //function : extrusionAlongPathX
2044 //=======================================================================
2046 SMESH::ListOfGroups*
2047 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2048 SMESH::SMESH_IDSource_ptr Path,
2049 CORBA::Long NodeStart,
2050 CORBA::Boolean HasAngles,
2051 const SMESH::double_array& Angles,
2052 CORBA::Boolean LinearVariation,
2053 CORBA::Boolean HasRefPoint,
2054 const SMESH::PointStruct& RefPoint,
2055 const bool MakeGroups,
2056 const SMDSAbs_ElementType ElementType,
2057 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2059 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2063 list<double> angles;
2064 for (int i = 0; i < Angles.length(); i++) {
2065 angles.push_back( Angles[i] );
2067 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2068 int nbOldGroups = myMesh->NbGroup();
2070 if ( Path->_is_nil() ) {
2071 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2075 TIDSortedElemSet elements;
2076 arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
2078 ::SMESH_MeshEditor anEditor( myMesh );
2079 ::SMESH_MeshEditor::Extrusion_Error error;
2081 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
2084 SMDS_MeshNode* aNodeStart =
2085 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2086 if ( !aNodeStart ) {
2087 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2090 error = anEditor.ExtrusionAlongTrack( elements, &(aMeshImp->GetImpl()), aNodeStart,
2091 HasAngles, angles, LinearVariation,
2092 HasRefPoint, refPnt, MakeGroups );
2095 SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
2098 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
2099 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
2100 SMDS_MeshNode* aNodeStart =
2101 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2102 if ( !aNodeStart ) {
2103 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2106 SMESH_subMesh* aSubMesh =
2107 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
2108 error = anEditor.ExtrusionAlongTrack( elements, aSubMesh, aNodeStart,
2109 HasAngles, angles, LinearVariation,
2110 HasRefPoint, refPnt, MakeGroups );
2113 SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
2115 // path as group of 1D elements
2119 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2125 storeResult(anEditor);
2126 Error = convExtrError( error );
2129 list<int> groupIDs = myMesh->GetGroupIds();
2130 list<int>::iterator newBegin = groupIDs.begin();
2131 std::advance( newBegin, nbOldGroups ); // skip old groups
2132 groupIDs.erase( groupIDs.begin(), newBegin );
2133 return getGroups( & groupIDs );
2139 //=======================================================================
2140 //function : ExtrusionAlongPath
2142 //=======================================================================
2144 SMESH::SMESH_MeshEditor::Extrusion_Error
2145 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2146 SMESH::SMESH_Mesh_ptr thePathMesh,
2147 GEOM::GEOM_Object_ptr thePathShape,
2148 CORBA::Long theNodeStart,
2149 CORBA::Boolean theHasAngles,
2150 const SMESH::double_array & theAngles,
2151 CORBA::Boolean theHasRefPoint,
2152 const SMESH::PointStruct & theRefPoint)
2154 if ( !myPreviewMode ) {
2155 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
2156 << theIDsOfElements << ", "
2157 << thePathMesh << ", "
2158 << thePathShape << ", "
2159 << theNodeStart << ", "
2160 << theHasAngles << ", "
2161 << theAngles << ", "
2162 << theHasRefPoint << ", "
2163 << "SMESH.PointStruct( "
2164 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2165 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2166 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2168 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2169 extrusionAlongPath( theIDsOfElements,
2182 //=======================================================================
2183 //function : ExtrusionAlongPathObject
2185 //=======================================================================
2187 SMESH::SMESH_MeshEditor::Extrusion_Error
2188 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
2189 SMESH::SMESH_Mesh_ptr thePathMesh,
2190 GEOM::GEOM_Object_ptr thePathShape,
2191 CORBA::Long theNodeStart,
2192 CORBA::Boolean theHasAngles,
2193 const SMESH::double_array & theAngles,
2194 CORBA::Boolean theHasRefPoint,
2195 const SMESH::PointStruct & theRefPoint)
2197 if ( !myPreviewMode ) {
2198 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
2199 << theObject << ", "
2200 << thePathMesh << ", "
2201 << thePathShape << ", "
2202 << theNodeStart << ", "
2203 << theHasAngles << ", "
2204 << theAngles << ", "
2205 << theHasRefPoint << ", "
2206 << "SMESH.PointStruct( "
2207 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2208 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2209 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2211 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2212 SMESH::long_array_var anElementsId = theObject->GetIDs();
2213 extrusionAlongPath( anElementsId,
2226 //=======================================================================
2227 //function : ExtrusionAlongPathObject1D
2229 //=======================================================================
2231 SMESH::SMESH_MeshEditor::Extrusion_Error
2232 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
2233 SMESH::SMESH_Mesh_ptr thePathMesh,
2234 GEOM::GEOM_Object_ptr thePathShape,
2235 CORBA::Long theNodeStart,
2236 CORBA::Boolean theHasAngles,
2237 const SMESH::double_array & theAngles,
2238 CORBA::Boolean theHasRefPoint,
2239 const SMESH::PointStruct & theRefPoint)
2241 if ( !myPreviewMode ) {
2242 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
2243 << theObject << ", "
2244 << thePathMesh << ", "
2245 << thePathShape << ", "
2246 << theNodeStart << ", "
2247 << theHasAngles << ", "
2248 << theAngles << ", "
2249 << theHasRefPoint << ", "
2250 << "SMESH.PointStruct( "
2251 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2252 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2253 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2255 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2256 SMESH::long_array_var anElementsId = theObject->GetIDs();
2257 extrusionAlongPath( anElementsId,
2271 //=======================================================================
2272 //function : ExtrusionAlongPathObject2D
2274 //=======================================================================
2276 SMESH::SMESH_MeshEditor::Extrusion_Error
2277 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
2278 SMESH::SMESH_Mesh_ptr thePathMesh,
2279 GEOM::GEOM_Object_ptr thePathShape,
2280 CORBA::Long theNodeStart,
2281 CORBA::Boolean theHasAngles,
2282 const SMESH::double_array & theAngles,
2283 CORBA::Boolean theHasRefPoint,
2284 const SMESH::PointStruct & theRefPoint)
2286 if ( !myPreviewMode ) {
2287 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
2288 << theObject << ", "
2289 << thePathMesh << ", "
2290 << thePathShape << ", "
2291 << theNodeStart << ", "
2292 << theHasAngles << ", "
2293 << theAngles << ", "
2294 << theHasRefPoint << ", "
2295 << "SMESH.PointStruct( "
2296 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2297 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2298 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2300 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2301 SMESH::long_array_var anElementsId = theObject->GetIDs();
2302 extrusionAlongPath( anElementsId,
2317 //=======================================================================
2318 //function : ExtrusionAlongPathMakeGroups
2320 //=======================================================================
2322 SMESH::ListOfGroups*
2323 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2324 SMESH::SMESH_Mesh_ptr thePathMesh,
2325 GEOM::GEOM_Object_ptr thePathShape,
2326 CORBA::Long theNodeStart,
2327 CORBA::Boolean theHasAngles,
2328 const SMESH::double_array& theAngles,
2329 CORBA::Boolean theHasRefPoint,
2330 const SMESH::PointStruct& theRefPoint,
2331 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2333 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2343 if ( !myPreviewMode ) {
2344 bool isDumpGroups = aGroups && aGroups->length() > 0;
2345 TPythonDump aPythonDump;
2347 aPythonDump << "("<<aGroups;
2350 aPythonDump << ", error)";
2352 aPythonDump <<"error";
2354 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2355 << theIDsOfElements << ", "
2356 << thePathMesh << ", "
2357 << thePathShape << ", "
2358 << theNodeStart << ", "
2359 << theHasAngles << ", "
2360 << theAngles << ", "
2361 << theHasRefPoint << ", "
2362 << "SMESH.PointStruct( "
2363 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2364 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2365 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2370 //=======================================================================
2371 //function : ExtrusionAlongPathObjectMakeGroups
2373 //=======================================================================
2375 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2376 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2377 SMESH::SMESH_Mesh_ptr thePathMesh,
2378 GEOM::GEOM_Object_ptr thePathShape,
2379 CORBA::Long theNodeStart,
2380 CORBA::Boolean theHasAngles,
2381 const SMESH::double_array& theAngles,
2382 CORBA::Boolean theHasRefPoint,
2383 const SMESH::PointStruct& theRefPoint,
2384 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2386 SMESH::long_array_var anElementsId = theObject->GetIDs();
2387 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2398 if ( !myPreviewMode ) {
2399 bool isDumpGroups = aGroups && aGroups->length() > 0;
2400 TPythonDump aPythonDump;
2402 aPythonDump << "("<<aGroups;
2405 aPythonDump << ", error)";
2407 aPythonDump <<"error";
2409 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2410 << theObject << ", "
2411 << thePathMesh << ", "
2412 << thePathShape << ", "
2413 << theNodeStart << ", "
2414 << theHasAngles << ", "
2415 << theAngles << ", "
2416 << theHasRefPoint << ", "
2417 << "SMESH.PointStruct( "
2418 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2419 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2420 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2425 //=======================================================================
2426 //function : ExtrusionAlongPathObject1DMakeGroups
2428 //=======================================================================
2430 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2431 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2432 SMESH::SMESH_Mesh_ptr thePathMesh,
2433 GEOM::GEOM_Object_ptr thePathShape,
2434 CORBA::Long theNodeStart,
2435 CORBA::Boolean theHasAngles,
2436 const SMESH::double_array& theAngles,
2437 CORBA::Boolean theHasRefPoint,
2438 const SMESH::PointStruct& theRefPoint,
2439 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2441 SMESH::long_array_var anElementsId = theObject->GetIDs();
2442 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2454 if ( !myPreviewMode ) {
2455 bool isDumpGroups = aGroups && aGroups->length() > 0;
2456 TPythonDump aPythonDump;
2458 aPythonDump << "("<<aGroups;
2461 aPythonDump << ", error)";
2463 aPythonDump <<"error";
2465 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
2466 << theObject << ", "
2467 << thePathMesh << ", "
2468 << thePathShape << ", "
2469 << theNodeStart << ", "
2470 << theHasAngles << ", "
2471 << theAngles << ", "
2472 << theHasRefPoint << ", "
2473 << "SMESH.PointStruct( "
2474 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2475 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2476 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2481 //=======================================================================
2482 //function : ExtrusionAlongPathObject2DMakeGroups
2484 //=======================================================================
2486 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2487 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2488 SMESH::SMESH_Mesh_ptr thePathMesh,
2489 GEOM::GEOM_Object_ptr thePathShape,
2490 CORBA::Long theNodeStart,
2491 CORBA::Boolean theHasAngles,
2492 const SMESH::double_array& theAngles,
2493 CORBA::Boolean theHasRefPoint,
2494 const SMESH::PointStruct& theRefPoint,
2495 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2497 SMESH::long_array_var anElementsId = theObject->GetIDs();
2498 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2510 if ( !myPreviewMode ) {
2511 bool isDumpGroups = aGroups && aGroups->length() > 0;
2512 TPythonDump aPythonDump;
2514 aPythonDump << "("<<aGroups;
2517 aPythonDump << ", error)";
2519 aPythonDump <<"error";
2521 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
2522 << theObject << ", "
2523 << thePathMesh << ", "
2524 << thePathShape << ", "
2525 << theNodeStart << ", "
2526 << theHasAngles << ", "
2527 << theAngles << ", "
2528 << theHasRefPoint << ", "
2529 << "SMESH.PointStruct( "
2530 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2531 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2532 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2538 //=======================================================================
2539 //function : ExtrusionAlongPathObjX
2541 //=======================================================================
2542 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2543 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
2544 SMESH::SMESH_IDSource_ptr Path,
2545 CORBA::Long NodeStart,
2546 CORBA::Boolean HasAngles,
2547 const SMESH::double_array& Angles,
2548 CORBA::Boolean LinearVariation,
2549 CORBA::Boolean HasRefPoint,
2550 const SMESH::PointStruct& RefPoint,
2551 CORBA::Boolean MakeGroups,
2552 SMESH::ElementType ElemType,
2553 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2555 SMESH::long_array_var anElementsId = Object->GetIDs();
2556 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2565 (SMDSAbs_ElementType)ElemType,
2568 if ( !myPreviewMode ) {
2569 bool isDumpGroups = aGroups && aGroups->length() > 0;
2570 TPythonDump aPythonDump;
2572 aPythonDump << "("<<aGroups;
2575 aPythonDump << ", error)";
2577 aPythonDump <<"error";
2579 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2582 << NodeStart << ", "
2583 << HasAngles << ", "
2585 << LinearVariation << ", "
2586 << HasRefPoint << ", "
2587 << "SMESH.PointStruct( "
2588 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2589 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2590 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2591 << ElemType << " )";
2597 //=======================================================================
2598 //function : ExtrusionAlongPathX
2600 //=======================================================================
2601 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2602 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2603 SMESH::SMESH_IDSource_ptr Path,
2604 CORBA::Long NodeStart,
2605 CORBA::Boolean HasAngles,
2606 const SMESH::double_array& Angles,
2607 CORBA::Boolean LinearVariation,
2608 CORBA::Boolean HasRefPoint,
2609 const SMESH::PointStruct& RefPoint,
2610 CORBA::Boolean MakeGroups,
2611 SMESH::ElementType ElemType,
2612 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2614 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2623 (SMDSAbs_ElementType)ElemType,
2626 if ( !myPreviewMode ) {
2627 bool isDumpGroups = aGroups && aGroups->length() > 0;
2628 TPythonDump aPythonDump;
2630 aPythonDump << "("<<aGroups;
2633 aPythonDump << ", error)";
2635 aPythonDump <<"error";
2637 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2638 << IDsOfElements << ", "
2640 << NodeStart << ", "
2641 << HasAngles << ", "
2643 << LinearVariation << ", "
2644 << HasRefPoint << ", "
2645 << "SMESH.PointStruct( "
2646 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2647 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2648 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2649 << ElemType << " )";
2655 //================================================================================
2657 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2658 * of given angles along path steps
2659 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2660 * which proceeds the extrusion
2661 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2662 * is used to define the sub-mesh for the path
2664 //================================================================================
2666 SMESH::double_array*
2667 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2668 GEOM::GEOM_Object_ptr thePathShape,
2669 const SMESH::double_array & theAngles)
2671 SMESH::double_array_var aResult = new SMESH::double_array();
2672 int nbAngles = theAngles.length();
2673 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2675 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2676 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2677 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2678 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2679 return aResult._retn();
2680 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2681 if ( nbSteps == nbAngles )
2683 aResult.inout() = theAngles;
2687 aResult->length( nbSteps );
2688 double rAn2St = double( nbAngles ) / double( nbSteps );
2689 double angPrev = 0, angle;
2690 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2692 double angCur = rAn2St * ( iSt+1 );
2693 double angCurFloor = floor( angCur );
2694 double angPrevFloor = floor( angPrev );
2695 if ( angPrevFloor == angCurFloor )
2696 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2699 int iP = int( angPrevFloor );
2700 double angPrevCeil = ceil(angPrev);
2701 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2703 int iC = int( angCurFloor );
2704 if ( iC < nbAngles )
2705 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2707 iP = int( angPrevCeil );
2709 angle += theAngles[ iC ];
2711 aResult[ iSt ] = angle;
2716 // Update Python script
2717 TPythonDump() << "rotAngles = " << theAngles;
2718 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2719 << thePathMesh << ", "
2720 << thePathShape << ", "
2723 return aResult._retn();
2727 //=======================================================================
2730 //=======================================================================
2732 SMESH::ListOfGroups*
2733 SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
2734 const SMESH::AxisStruct & theAxis,
2735 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2736 CORBA::Boolean theCopy,
2737 const bool theMakeGroups,
2738 ::SMESH_Mesh* theTargetMesh)
2742 TIDSortedElemSet elements;
2743 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2745 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2746 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2749 switch ( theMirrorType ) {
2750 case SMESH::SMESH_MeshEditor::POINT:
2751 aTrsf.SetMirror( P );
2753 case SMESH::SMESH_MeshEditor::AXIS:
2754 aTrsf.SetMirror( gp_Ax1( P, V ));
2757 aTrsf.SetMirror( gp_Ax2( P, V ));
2760 ::SMESH_MeshEditor anEditor( myMesh );
2761 ::SMESH_MeshEditor::PGroupIDs groupIds =
2762 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2765 storeResult(anEditor);
2767 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2770 //=======================================================================
2773 //=======================================================================
2775 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2776 const SMESH::AxisStruct & theAxis,
2777 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2778 CORBA::Boolean theCopy)
2780 if ( !myPreviewMode ) {
2781 TPythonDump() << this << ".Mirror( "
2782 << theIDsOfElements << ", "
2784 << mirrorTypeName(theMirrorType) << ", "
2787 mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2791 //=======================================================================
2792 //function : MirrorObject
2794 //=======================================================================
2796 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2797 const SMESH::AxisStruct & theAxis,
2798 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2799 CORBA::Boolean theCopy)
2801 if ( !myPreviewMode ) {
2802 TPythonDump() << this << ".MirrorObject( "
2803 << theObject << ", "
2805 << mirrorTypeName(theMirrorType) << ", "
2808 SMESH::long_array_var anElementsId = theObject->GetIDs();
2809 mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2812 //=======================================================================
2813 //function : MirrorMakeGroups
2815 //=======================================================================
2817 SMESH::ListOfGroups*
2818 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2819 const SMESH::AxisStruct& theMirror,
2820 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2822 SMESH::ListOfGroups * aGroups = mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2823 if ( !myPreviewMode ) {
2824 TPythonDump aPythonDump;
2825 DumpGroupsList(aPythonDump,aGroups);
2826 aPythonDump << this << ".MirrorMakeGroups( "
2827 << theIDsOfElements << ", "
2828 << theMirror << ", "
2829 << mirrorTypeName(theMirrorType) << " )";
2834 //=======================================================================
2835 //function : MirrorObjectMakeGroups
2837 //=======================================================================
2839 SMESH::ListOfGroups*
2840 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2841 const SMESH::AxisStruct& theMirror,
2842 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2844 SMESH::long_array_var anElementsId = theObject->GetIDs();
2845 SMESH::ListOfGroups * aGroups = mirror(anElementsId, theMirror, theMirrorType, true, true);
2846 if ( !myPreviewMode ) {
2847 TPythonDump aPythonDump;
2848 DumpGroupsList(aPythonDump,aGroups);
2849 aPythonDump << this << ".MirrorObjectMakeGroups( "
2850 << theObject << ", "
2851 << theMirror << ", "
2852 << mirrorTypeName(theMirrorType) << " )";
2857 //=======================================================================
2858 //function : MirrorMakeMesh
2860 //=======================================================================
2862 SMESH::SMESH_Mesh_ptr
2863 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2864 const SMESH::AxisStruct& theMirror,
2865 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2866 CORBA::Boolean theCopyGroups,
2867 const char* theMeshName)
2869 SMESH_Mesh_i* mesh_i;
2870 SMESH::SMESH_Mesh_var mesh;
2871 { // open new scope to dump "MakeMesh" command
2872 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2874 TPythonDump pydump; // to prevent dump at mesh creation
2876 mesh = makeMesh( theMeshName );
2877 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2879 mirror(theIDsOfElements, theMirror, theMirrorType,
2880 false, theCopyGroups, & mesh_i->GetImpl());
2881 mesh_i->CreateGroupServants();
2884 if ( !myPreviewMode ) {
2885 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2886 << theIDsOfElements << ", "
2887 << theMirror << ", "
2888 << mirrorTypeName(theMirrorType) << ", "
2889 << theCopyGroups << ", '"
2890 << theMeshName << "' )";
2895 if(!myPreviewMode && mesh_i)
2896 mesh_i->GetGroups();
2898 return mesh._retn();
2901 //=======================================================================
2902 //function : MirrorObjectMakeMesh
2904 //=======================================================================
2906 SMESH::SMESH_Mesh_ptr
2907 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2908 const SMESH::AxisStruct& theMirror,
2909 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2910 CORBA::Boolean theCopyGroups,
2911 const char* theMeshName)
2913 SMESH_Mesh_i* mesh_i;
2914 SMESH::SMESH_Mesh_var mesh;
2915 { // open new scope to dump "MakeMesh" command
2916 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2918 TPythonDump pydump; // to prevent dump at mesh creation
2920 mesh = makeMesh( theMeshName );
2921 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2923 SMESH::long_array_var anElementsId = theObject->GetIDs();
2924 mirror(anElementsId, theMirror, theMirrorType,
2925 false, theCopyGroups, & mesh_i->GetImpl());
2926 mesh_i->CreateGroupServants();
2929 if ( !myPreviewMode ) {
2930 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
2931 << theObject << ", "
2932 << theMirror << ", "
2933 << mirrorTypeName(theMirrorType) << ", "
2934 << theCopyGroups << ", '"
2935 << theMeshName << "' )";
2940 if(!myPreviewMode && mesh_i)
2941 mesh_i->GetGroups();
2943 return mesh._retn();
2946 //=======================================================================
2947 //function : translate
2949 //=======================================================================
2951 SMESH::ListOfGroups*
2952 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2953 const SMESH::DirStruct & theVector,
2954 CORBA::Boolean theCopy,
2955 const bool theMakeGroups,
2956 ::SMESH_Mesh* theTargetMesh)
2960 TIDSortedElemSet elements;
2961 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2964 const SMESH::PointStruct * P = &theVector.PS;
2965 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2967 ::SMESH_MeshEditor anEditor( myMesh );
2968 ::SMESH_MeshEditor::PGroupIDs groupIds =
2969 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2972 storeResult(anEditor);
2974 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2977 //=======================================================================
2978 //function : Translate
2980 //=======================================================================
2982 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2983 const SMESH::DirStruct & theVector,
2984 CORBA::Boolean theCopy)
2986 if ( !myPreviewMode ) {
2987 TPythonDump() << this << ".Translate( "
2988 << theIDsOfElements << ", "
2989 << theVector << ", "
2992 translate(theIDsOfElements,
2998 //=======================================================================
2999 //function : TranslateObject
3001 //=======================================================================
3003 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
3004 const SMESH::DirStruct & theVector,
3005 CORBA::Boolean theCopy)
3007 if ( !myPreviewMode ) {
3008 TPythonDump() << this << ".TranslateObject( "
3009 << theObject << ", "
3010 << theVector << ", "
3013 SMESH::long_array_var anElementsId = theObject->GetIDs();
3014 translate(anElementsId,
3020 //=======================================================================
3021 //function : TranslateMakeGroups
3023 //=======================================================================
3025 SMESH::ListOfGroups*
3026 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
3027 const SMESH::DirStruct& theVector)
3029 SMESH::ListOfGroups * aGroups = translate(theIDsOfElements,theVector,true,true);
3030 if ( !myPreviewMode ) {
3031 TPythonDump aPythonDump;
3032 DumpGroupsList(aPythonDump,aGroups);
3033 aPythonDump << this << ".TranslateMakeGroups( "
3034 << theIDsOfElements << ", "
3035 << theVector << " )";
3040 //=======================================================================
3041 //function : TranslateObjectMakeGroups
3043 //=======================================================================
3045 SMESH::ListOfGroups*
3046 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3047 const SMESH::DirStruct& theVector)
3049 SMESH::long_array_var anElementsId = theObject->GetIDs();
3050 SMESH::ListOfGroups * aGroups = translate(anElementsId, theVector, true, true);
3052 if ( !myPreviewMode ) {
3054 TPythonDump aPythonDump;
3055 DumpGroupsList(aPythonDump,aGroups);
3056 aPythonDump << this << ".TranslateObjectMakeGroups( "
3057 << theObject << ", "
3058 << theVector << " )";
3063 //=======================================================================
3064 //function : TranslateMakeMesh
3066 //=======================================================================
3068 SMESH::SMESH_Mesh_ptr
3069 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3070 const SMESH::DirStruct& theVector,
3071 CORBA::Boolean theCopyGroups,
3072 const char* theMeshName)
3074 SMESH_Mesh_i* mesh_i;
3075 SMESH::SMESH_Mesh_var mesh;
3077 { // open new scope to dump "MakeMesh" command
3078 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3080 TPythonDump pydump; // to prevent dump at mesh creation
3082 mesh = makeMesh( theMeshName );
3083 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3086 translate(theIDsOfElements, theVector,
3087 false, theCopyGroups, & mesh_i->GetImpl());
3088 mesh_i->CreateGroupServants();
3091 if ( !myPreviewMode ) {
3092 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3093 << theIDsOfElements << ", "
3094 << theVector << ", "
3095 << theCopyGroups << ", '"
3096 << theMeshName << "' )";
3101 if(!myPreviewMode && mesh_i)
3102 mesh_i->GetGroups();
3104 return mesh._retn();
3107 //=======================================================================
3108 //function : TranslateObjectMakeMesh
3110 //=======================================================================
3112 SMESH::SMESH_Mesh_ptr
3113 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3114 const SMESH::DirStruct& theVector,
3115 CORBA::Boolean theCopyGroups,
3116 const char* theMeshName)
3118 SMESH_Mesh_i* mesh_i;
3119 SMESH::SMESH_Mesh_var mesh;
3120 { // open new scope to dump "MakeMesh" command
3121 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3123 TPythonDump pydump; // to prevent dump at mesh creation
3124 mesh = makeMesh( theMeshName );
3125 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3128 SMESH::long_array_var anElementsId = theObject->GetIDs();
3129 translate(anElementsId, theVector,
3130 false, theCopyGroups, & mesh_i->GetImpl());
3131 mesh_i->CreateGroupServants();
3133 if ( !myPreviewMode ) {
3134 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3135 << theObject << ", "
3136 << theVector << ", "
3137 << theCopyGroups << ", '"
3138 << theMeshName << "' )";
3143 if(!myPreviewMode && mesh_i)
3144 mesh_i->GetGroups();
3146 return mesh._retn();
3149 //=======================================================================
3152 //=======================================================================
3154 SMESH::ListOfGroups*
3155 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
3156 const SMESH::AxisStruct & theAxis,
3157 CORBA::Double theAngle,
3158 CORBA::Boolean theCopy,
3159 const bool theMakeGroups,
3160 ::SMESH_Mesh* theTargetMesh)
3164 TIDSortedElemSet elements;
3165 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3167 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3168 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3171 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3173 ::SMESH_MeshEditor anEditor( myMesh );
3174 ::SMESH_MeshEditor::PGroupIDs groupIds =
3175 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3178 storeResult(anEditor);
3180 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3183 //=======================================================================
3186 //=======================================================================
3188 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3189 const SMESH::AxisStruct & theAxis,
3190 CORBA::Double theAngle,
3191 CORBA::Boolean theCopy)
3193 if ( !myPreviewMode ) {
3194 TPythonDump() << this << ".Rotate( "
3195 << theIDsOfElements << ", "
3200 rotate(theIDsOfElements,
3207 //=======================================================================
3208 //function : RotateObject
3210 //=======================================================================
3212 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3213 const SMESH::AxisStruct & theAxis,
3214 CORBA::Double theAngle,
3215 CORBA::Boolean theCopy)
3217 if ( !myPreviewMode ) {
3218 TPythonDump() << this << ".RotateObject( "
3219 << theObject << ", "
3224 SMESH::long_array_var anElementsId = theObject->GetIDs();
3225 rotate(anElementsId,
3232 //=======================================================================
3233 //function : RotateMakeGroups
3235 //=======================================================================
3237 SMESH::ListOfGroups*
3238 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3239 const SMESH::AxisStruct& theAxis,
3240 CORBA::Double theAngle)
3242 SMESH::ListOfGroups * aGroups = rotate(theIDsOfElements,theAxis,theAngle,true,true);
3243 if ( !myPreviewMode ) {
3244 TPythonDump aPythonDump;
3245 DumpGroupsList(aPythonDump,aGroups);
3246 aPythonDump << this << ".RotateMakeGroups( "
3247 << theIDsOfElements << ", "
3249 << theAngle << " )";
3254 //=======================================================================
3255 //function : RotateObjectMakeGroups
3257 //=======================================================================
3259 SMESH::ListOfGroups*
3260 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3261 const SMESH::AxisStruct& theAxis,
3262 CORBA::Double theAngle)
3264 SMESH::long_array_var anElementsId = theObject->GetIDs();
3265 SMESH::ListOfGroups * aGroups = rotate(anElementsId,theAxis,theAngle,true,true);
3267 if ( !myPreviewMode ) {
3268 TPythonDump aPythonDump;
3269 DumpGroupsList(aPythonDump,aGroups);
3270 aPythonDump << this << ".RotateObjectMakeGroups( "
3271 << theObject << ", "
3273 << theAngle << " )";
3278 //=======================================================================
3279 //function : RotateMakeMesh
3281 //=======================================================================
3283 SMESH::SMESH_Mesh_ptr
3284 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3285 const SMESH::AxisStruct& theAxis,
3286 CORBA::Double theAngleInRadians,
3287 CORBA::Boolean theCopyGroups,
3288 const char* theMeshName)
3290 SMESH::SMESH_Mesh_var mesh;
3291 SMESH_Mesh_i* mesh_i;
3293 { // open new scope to dump "MakeMesh" command
3294 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3296 TPythonDump pydump; // to prevent dump at mesh creation
3298 mesh = makeMesh( theMeshName );
3299 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3302 rotate(theIDsOfElements, theAxis, theAngleInRadians,
3303 false, theCopyGroups, & mesh_i->GetImpl());
3304 mesh_i->CreateGroupServants();
3306 if ( !myPreviewMode ) {
3307 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3308 << theIDsOfElements << ", "
3310 << theAngleInRadians << ", "
3311 << theCopyGroups << ", '"
3312 << theMeshName << "' )";
3317 if(!myPreviewMode && mesh_i)
3318 mesh_i->GetGroups();
3320 return mesh._retn();
3323 //=======================================================================
3324 //function : RotateObjectMakeMesh
3326 //=======================================================================
3328 SMESH::SMESH_Mesh_ptr
3329 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3330 const SMESH::AxisStruct& theAxis,
3331 CORBA::Double theAngleInRadians,
3332 CORBA::Boolean theCopyGroups,
3333 const char* theMeshName)
3335 SMESH::SMESH_Mesh_var mesh;
3336 SMESH_Mesh_i* mesh_i;
3338 {// open new scope to dump "MakeMesh" command
3339 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3341 TPythonDump pydump; // to prevent dump at mesh creation
3342 mesh = makeMesh( theMeshName );
3343 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3346 SMESH::long_array_var anElementsId = theObject->GetIDs();
3347 rotate(anElementsId, theAxis, theAngleInRadians,
3348 false, theCopyGroups, & mesh_i->GetImpl());
3349 mesh_i->CreateGroupServants();
3351 if ( !myPreviewMode ) {
3352 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3353 << theObject << ", "
3355 << theAngleInRadians << ", "
3356 << theCopyGroups << ", '"
3357 << theMeshName << "' )";
3362 if(!myPreviewMode && mesh_i)
3363 mesh_i->GetGroups();
3365 return mesh._retn();
3368 //=======================================================================
3369 //function : FindCoincidentNodes
3371 //=======================================================================
3373 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3374 SMESH::array_of_long_array_out GroupsOfNodes)
3378 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3379 ::SMESH_MeshEditor anEditor( myMesh );
3380 set<const SMDS_MeshNode*> nodes; // no input nodes
3381 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3383 GroupsOfNodes = new SMESH::array_of_long_array;
3384 GroupsOfNodes->length( aListOfListOfNodes.size() );
3385 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3386 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3387 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3388 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3389 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3390 aGroup.length( aListOfNodes.size() );
3391 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3392 aGroup[ j ] = (*lIt)->GetID();
3394 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3395 << Tolerance << " )";
3398 //=======================================================================
3399 //function : FindCoincidentNodesOnPart
3401 //=======================================================================
3402 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3403 CORBA::Double Tolerance,
3404 SMESH::array_of_long_array_out GroupsOfNodes)
3407 SMESH::long_array_var aElementsId = theObject->GetIDs();
3409 SMESHDS_Mesh* aMesh = GetMeshDS();
3410 set<const SMDS_MeshNode*> nodes;
3412 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
3413 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
3414 for(int i = 0; i < aElementsId->length(); i++) {
3415 CORBA::Long ind = aElementsId[i];
3416 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
3422 for(int i = 0; i < aElementsId->length(); i++) {
3423 CORBA::Long ind = aElementsId[i];
3424 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
3426 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
3427 while ( nIt->more() )
3428 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
3434 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3435 ::SMESH_MeshEditor anEditor( myMesh );
3437 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3439 GroupsOfNodes = new SMESH::array_of_long_array;
3440 GroupsOfNodes->length( aListOfListOfNodes.size() );
3441 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3442 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3443 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3444 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3445 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3446 aGroup.length( aListOfNodes.size() );
3447 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3448 aGroup[ j ] = (*lIt)->GetID();
3450 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3452 << Tolerance << " )";
3455 //=======================================================================
3456 //function : MergeNodes
3458 //=======================================================================
3460 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3464 SMESHDS_Mesh* aMesh = GetMeshDS();
3466 TPythonDump aTPythonDump;
3467 aTPythonDump << this << ".MergeNodes([";
3468 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3469 for (int i = 0; i < GroupsOfNodes.length(); i++)
3471 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3472 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3473 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3474 for ( int j = 0; j < aNodeGroup.length(); j++ )
3476 CORBA::Long index = aNodeGroup[ j ];
3477 const SMDS_MeshNode * node = aMesh->FindNode(index);
3479 aListOfNodes.push_back( node );
3481 if ( aListOfNodes.size() < 2 )
3482 aListOfListOfNodes.pop_back();
3484 if ( i > 0 ) aTPythonDump << ", ";
3485 aTPythonDump << aNodeGroup;
3487 ::SMESH_MeshEditor anEditor( myMesh );
3488 anEditor.MergeNodes( aListOfListOfNodes );
3490 aTPythonDump << "])";
3493 //=======================================================================
3494 //function : FindEqualElements
3496 //=======================================================================
3497 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3498 SMESH::array_of_long_array_out GroupsOfElementsID)
3501 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
3502 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
3503 typedef list<int> TListOfIDs;
3504 set<const SMDS_MeshElement*> elems;
3505 SMESH::long_array_var aElementsId = theObject->GetIDs();
3506 SMESHDS_Mesh* aMesh = GetMeshDS();
3508 for(int i = 0; i < aElementsId->length(); i++) {
3509 CORBA::Long anID = aElementsId[i];
3510 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3516 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3517 ::SMESH_MeshEditor anEditor( myMesh );
3518 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3520 GroupsOfElementsID = new SMESH::array_of_long_array;
3521 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3523 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3524 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3525 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3526 TListOfIDs& listOfIDs = *arraysIt;
3527 aGroup.length( listOfIDs.size() );
3528 TListOfIDs::iterator idIt = listOfIDs.begin();
3529 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3530 aGroup[ k ] = *idIt;
3534 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3539 //=======================================================================
3540 //function : MergeElements
3542 //=======================================================================
3544 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3548 TPythonDump aTPythonDump;
3549 aTPythonDump << this << ".MergeElements( [";
3551 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3553 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3554 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3555 aListOfListOfElementsID.push_back( list< int >() );
3556 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3557 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3558 CORBA::Long id = anElemsIDGroup[ j ];
3559 aListOfElemsID.push_back( id );
3561 if ( aListOfElemsID.size() < 2 )
3562 aListOfListOfElementsID.pop_back();
3563 if ( i > 0 ) aTPythonDump << ", ";
3564 aTPythonDump << anElemsIDGroup;
3567 ::SMESH_MeshEditor anEditor( myMesh );
3568 anEditor.MergeElements(aListOfListOfElementsID);
3570 aTPythonDump << "] )";
3573 //=======================================================================
3574 //function : MergeEqualElements
3576 //=======================================================================
3578 void SMESH_MeshEditor_i::MergeEqualElements()
3582 ::SMESH_MeshEditor anEditor( myMesh );
3583 anEditor.MergeEqualElements();
3585 TPythonDump() << this << ".MergeEqualElements()";
3588 //================================================================================
3590 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
3591 * move the node closest to the point to point's location and return ID of the node
3593 //================================================================================
3595 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
3598 CORBA::Long theNodeID)
3600 // We keep myNodeSearcher until any mesh modification:
3601 // 1) initData() deletes myNodeSearcher at any edition,
3602 // 2) TNodeSearcherDeleter - at any mesh compute event and mesh change
3606 int nodeID = theNodeID;
3607 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
3610 static TNodeSearcherDeleter deleter;
3611 deleter.Set( myMesh );
3612 if ( !myNodeSearcher ) {
3613 ::SMESH_MeshEditor anEditor( myMesh );
3614 myNodeSearcher = anEditor.GetNodeSearcher();
3617 node = myNodeSearcher->FindClosestTo( p );
3620 nodeID = node->GetID();
3621 if ( myPreviewMode ) // make preview data
3623 // in a preview mesh, make edges linked to a node
3624 TPreviewMesh tmpMesh;
3625 TIDSortedElemSet linkedNodes;
3626 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3627 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3628 for ( ; nIt != linkedNodes.end(); ++nIt )
3630 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
3631 tmpMesh.Copy( &edge );
3634 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
3636 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
3637 // fill preview data
3638 ::SMESH_MeshEditor anEditor( & tmpMesh );
3639 storeResult( anEditor );
3643 GetMeshDS()->MoveNode(node, x, y, z);
3647 if ( !myPreviewMode ) {
3648 TPythonDump() << "nodeID = " << this
3649 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
3650 << ", " << nodeID << " )";
3656 //=======================================================================
3657 //function : convError
3659 //=======================================================================
3661 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
3663 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
3667 RETCASE( SEW_BORDER1_NOT_FOUND );
3668 RETCASE( SEW_BORDER2_NOT_FOUND );
3669 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
3670 RETCASE( SEW_BAD_SIDE_NODES );
3671 RETCASE( SEW_VOLUMES_TO_SPLIT );
3672 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
3673 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
3674 RETCASE( SEW_BAD_SIDE1_NODES );
3675 RETCASE( SEW_BAD_SIDE2_NODES );
3677 return SMESH::SMESH_MeshEditor::SEW_OK;
3680 //=======================================================================
3681 //function : SewFreeBorders
3683 //=======================================================================
3685 SMESH::SMESH_MeshEditor::Sew_Error
3686 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
3687 CORBA::Long SecondNodeID1,
3688 CORBA::Long LastNodeID1,
3689 CORBA::Long FirstNodeID2,
3690 CORBA::Long SecondNodeID2,
3691 CORBA::Long LastNodeID2,
3692 CORBA::Boolean CreatePolygons,
3693 CORBA::Boolean CreatePolyedrs)
3697 SMESHDS_Mesh* aMesh = GetMeshDS();
3699 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3700 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3701 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3702 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3703 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3704 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
3706 if (!aBorderFirstNode ||
3707 !aBorderSecondNode||
3709 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3710 if (!aSide2FirstNode ||
3711 !aSide2SecondNode ||
3713 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3715 TPythonDump() << "error = " << this << ".SewFreeBorders( "
3716 << FirstNodeID1 << ", "
3717 << SecondNodeID1 << ", "
3718 << LastNodeID1 << ", "
3719 << FirstNodeID2 << ", "
3720 << SecondNodeID2 << ", "
3721 << LastNodeID2 << ", "
3722 << CreatePolygons<< ", "
3723 << CreatePolyedrs<< " )";
3725 ::SMESH_MeshEditor anEditor( myMesh );
3726 SMESH::SMESH_MeshEditor::Sew_Error error =
3727 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3737 storeResult(anEditor);
3743 //=======================================================================
3744 //function : SewConformFreeBorders
3746 //=======================================================================
3748 SMESH::SMESH_MeshEditor::Sew_Error
3749 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3750 CORBA::Long SecondNodeID1,
3751 CORBA::Long LastNodeID1,
3752 CORBA::Long FirstNodeID2,
3753 CORBA::Long SecondNodeID2)
3757 SMESHDS_Mesh* aMesh = GetMeshDS();
3759 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3760 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3761 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3762 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3763 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3764 const SMDS_MeshNode* aSide2ThirdNode = 0;
3766 if (!aBorderFirstNode ||
3767 !aBorderSecondNode||
3769 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3770 if (!aSide2FirstNode ||
3772 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3774 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
3775 << FirstNodeID1 << ", "
3776 << SecondNodeID1 << ", "
3777 << LastNodeID1 << ", "
3778 << FirstNodeID2 << ", "
3779 << SecondNodeID2 << " )";
3781 ::SMESH_MeshEditor anEditor( myMesh );
3782 SMESH::SMESH_MeshEditor::Sew_Error error =
3783 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3792 storeResult(anEditor);
3798 //=======================================================================
3799 //function : SewBorderToSide
3801 //=======================================================================
3803 SMESH::SMESH_MeshEditor::Sew_Error
3804 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
3805 CORBA::Long SecondNodeIDOnFreeBorder,
3806 CORBA::Long LastNodeIDOnFreeBorder,
3807 CORBA::Long FirstNodeIDOnSide,
3808 CORBA::Long LastNodeIDOnSide,
3809 CORBA::Boolean CreatePolygons,
3810 CORBA::Boolean CreatePolyedrs)
3814 SMESHDS_Mesh* aMesh = GetMeshDS();
3816 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
3817 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
3818 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
3819 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
3820 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
3821 const SMDS_MeshNode* aSide2ThirdNode = 0;
3823 if (!aBorderFirstNode ||
3824 !aBorderSecondNode||
3826 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3827 if (!aSide2FirstNode ||
3829 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
3831 TPythonDump() << "error = " << this << ".SewBorderToSide( "
3832 << FirstNodeIDOnFreeBorder << ", "
3833 << SecondNodeIDOnFreeBorder << ", "
3834 << LastNodeIDOnFreeBorder << ", "
3835 << FirstNodeIDOnSide << ", "
3836 << LastNodeIDOnSide << ", "
3837 << CreatePolygons << ", "
3838 << CreatePolyedrs << ") ";
3840 ::SMESH_MeshEditor anEditor( myMesh );
3841 SMESH::SMESH_MeshEditor::Sew_Error error =
3842 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3852 storeResult(anEditor);
3858 //=======================================================================
3859 //function : SewSideElements
3861 //=======================================================================
3863 SMESH::SMESH_MeshEditor::Sew_Error
3864 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
3865 const SMESH::long_array& IDsOfSide2Elements,
3866 CORBA::Long NodeID1OfSide1ToMerge,
3867 CORBA::Long NodeID1OfSide2ToMerge,
3868 CORBA::Long NodeID2OfSide1ToMerge,
3869 CORBA::Long NodeID2OfSide2ToMerge)
3873 SMESHDS_Mesh* aMesh = GetMeshDS();
3875 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
3876 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
3877 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
3878 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
3880 if (!aFirstNode1ToMerge ||
3881 !aFirstNode2ToMerge )
3882 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
3883 if (!aSecondNode1ToMerge||
3884 !aSecondNode2ToMerge)
3885 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
3887 TIDSortedElemSet aSide1Elems, aSide2Elems;
3888 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
3889 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
3891 TPythonDump() << "error = " << this << ".SewSideElements( "
3892 << IDsOfSide1Elements << ", "
3893 << IDsOfSide2Elements << ", "
3894 << NodeID1OfSide1ToMerge << ", "
3895 << NodeID1OfSide2ToMerge << ", "
3896 << NodeID2OfSide1ToMerge << ", "
3897 << NodeID2OfSide2ToMerge << ")";
3899 ::SMESH_MeshEditor anEditor( myMesh );
3900 SMESH::SMESH_MeshEditor::Sew_Error error =
3901 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
3904 aSecondNode1ToMerge,
3905 aSecondNode2ToMerge));
3907 storeResult(anEditor);
3912 //================================================================================
3914 * \brief Set new nodes for given element
3915 * \param ide - element id
3916 * \param newIDs - new node ids
3917 * \retval CORBA::Boolean - true if result is OK
3919 //================================================================================
3921 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
3922 const SMESH::long_array& newIDs)
3926 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
3927 if(!elem) return false;
3929 int nbn = newIDs.length();
3931 vector<const SMDS_MeshNode*> aNodes(nbn);
3934 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
3937 aNodes[nbn1] = aNode;
3940 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
3941 << ide << ", " << newIDs << " )";
3943 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
3946 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
3949 //================================================================================
3951 * \brief Update myLastCreated* or myPreviewData
3952 * \param anEditor - it contains last modification results
3954 //================================================================================
3956 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
3958 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
3960 list<int> aNodesConnectivity;
3961 typedef map<int, int> TNodesMap;
3964 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
3965 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
3967 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
3968 int nbEdges = aMeshDS->NbEdges();
3969 int nbFaces = aMeshDS->NbFaces();
3970 int nbVolum = aMeshDS->NbVolumes();
3971 switch ( previewType ) {
3972 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
3973 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
3974 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
3977 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
3978 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
3980 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
3982 while ( itMeshElems->more() ) {
3983 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
3984 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
3987 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
3988 while ( itElemNodes->more() ) {
3989 const SMDS_MeshNode* aMeshNode =
3990 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
3991 int aNodeID = aMeshNode->GetID();
3992 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
3993 if ( anIter == nodesMap.end() ) {
3994 // filling the nodes coordinates
3995 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
3996 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
3997 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
3998 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4001 aNodesConnectivity.push_back(anIter->second);
4004 // filling the elements types
4005 SMDSAbs_ElementType aType;
4007 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4008 aType = SMDSAbs_Node;
4012 aType = aMeshElem->GetType();
4013 isPoly = aMeshElem->IsPoly();
4016 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4017 myPreviewData->elementTypes[i].isPoly = isPoly;
4018 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4022 myPreviewData->nodesXYZ.length( j );
4024 // filling the elements connectivities
4025 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4026 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4027 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4028 myPreviewData->elementConnectivities[i] = *aConnIter;
4034 // add new nodes into myLastCreatedNodes
4035 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4036 myLastCreatedNodes->length(aSeq.Length());
4037 for(int i=0; i<aSeq.Length(); i++)
4038 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4041 // add new elements into myLastCreatedElems
4042 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4043 myLastCreatedElems->length(aSeq.Length());
4044 for(int i=0; i<aSeq.Length(); i++)
4045 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4049 //================================================================================
4051 * Return data of mesh edition preview
4053 //================================================================================
4055 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4057 return myPreviewData._retn();
4060 //================================================================================
4062 * \brief Returns list of it's IDs of created nodes
4063 * \retval SMESH::long_array* - list of node ID
4065 //================================================================================
4067 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4069 return myLastCreatedNodes._retn();
4072 //================================================================================
4074 * \brief Returns list of it's IDs of created elements
4075 * \retval SMESH::long_array* - list of elements' ID
4077 //================================================================================
4079 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4081 return myLastCreatedElems._retn();
4084 //=======================================================================
4085 //function : ConvertToQuadratic
4087 //=======================================================================
4089 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4091 ::SMESH_MeshEditor anEditor( myMesh );
4092 anEditor.ConvertToQuadratic(theForce3d);
4093 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4096 //=======================================================================
4097 //function : ConvertFromQuadratic
4099 //=======================================================================
4101 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4103 ::SMESH_MeshEditor anEditor( myMesh );
4104 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4105 TPythonDump() << this << ".ConvertFromQuadratic()";
4109 //=======================================================================
4110 //function : makeMesh
4111 //purpose : create a named imported mesh
4112 //=======================================================================
4114 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4116 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4117 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4118 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4119 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4120 gen->SetName( meshSO, theMeshName, "Mesh" );
4121 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4123 return mesh._retn();
4126 //=======================================================================
4127 //function : DumpGroupsList
4129 //=======================================================================
4130 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4131 const SMESH::ListOfGroups * theGroupList)
4133 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4134 if(isDumpGroupList) {
4135 theDumpPython << theGroupList << " = ";
4139 //================================================================================
4141 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4142 \param theElems - the list of elements (edges or faces) to be replicated
4143 The nodes for duplication could be found from these elements
4144 \param theNodesNot - list of nodes to NOT replicate
4145 \param theAffectedElems - the list of elements (cells and edges) to which the
4146 replicated nodes should be associated to.
4147 \return TRUE if operation has been completed successfully, FALSE otherwise
4148 \sa DoubleNodeGroup(), DoubleNodeGroups()
4150 //================================================================================
4152 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theElems,
4153 const SMESH::long_array& theNodesNot,
4154 const SMESH::long_array& theAffectedElems )
4159 ::SMESH_MeshEditor aMeshEditor( myMesh );
4161 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4162 TIDSortedElemSet anElems, aNodes, anAffected;
4163 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4164 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4165 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
4167 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4169 storeResult( aMeshEditor) ;
4174 //================================================================================
4176 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4177 \param theElems - the list of elements (edges or faces) to be replicated
4178 The nodes for duplication could be found from these elements
4179 \param theNodesNot - list of nodes to NOT replicate
4180 \param theShape - shape to detect affected elements (element which geometric center
4181 located on or inside shape).
4182 The replicated nodes should be associated to affected elements.
4183 \return TRUE if operation has been completed successfully, FALSE otherwise
4184 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
4186 //================================================================================
4188 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesInRegion
4189 ( const SMESH::long_array& theElems,
4190 const SMESH::long_array& theNodesNot,
4191 GEOM::GEOM_Object_ptr theShape )
4196 ::SMESH_MeshEditor aMeshEditor( myMesh );
4198 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4199 TIDSortedElemSet anElems, aNodes;
4200 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4201 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4203 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4204 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4206 storeResult( aMeshEditor) ;
4211 //================================================================================
4213 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4214 \param theElems - group of of elements (edges or faces) to be replicated
4215 \param theNodesNot - group of nodes not to replicated
4216 \param theAffectedElems - group of elements to which the replicated nodes
4217 should be associated to.
4218 \return TRUE if operation has been completed successfully, FALSE otherwise
4219 \sa DoubleNodes(), DoubleNodeGroups()
4221 //================================================================================
4223 static void groupToSet(SMESH::SMESH_GroupBase_ptr theGrp,
4224 SMESHDS_Mesh* theMeshDS,
4225 TIDSortedElemSet& theElemSet,
4226 const SMDSAbs_ElementType theType)
4229 if ( CORBA::is_nil( theGrp ) )
4231 SMESH::long_array_var anIDs = theGrp->GetIDs();
4232 arrayToSet( anIDs, theMeshDS, theElemSet, theType);
4235 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(
4236 SMESH::SMESH_GroupBase_ptr theElems,
4237 SMESH::SMESH_GroupBase_ptr theNodesNot,
4238 SMESH::SMESH_GroupBase_ptr theAffectedElems )
4241 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4246 ::SMESH_MeshEditor aMeshEditor( myMesh );
4248 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4249 TIDSortedElemSet anElems, aNodes, anAffected;
4250 groupToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4251 groupToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4252 groupToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
4254 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4256 storeResult( aMeshEditor) ;
4261 //================================================================================
4263 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4264 \param theElems - group of of elements (edges or faces) to be replicated
4265 \param theNodesNot - group of nodes not to replicated
4266 \param theShape - shape to detect affected elements (element which geometric center
4267 located on or inside shape).
4268 The replicated nodes should be associated to affected elements.
4269 \return TRUE if operation has been completed successfully, FALSE otherwise
4270 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
4272 //================================================================================
4274 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroupInRegion(
4275 SMESH::SMESH_GroupBase_ptr theElems,
4276 SMESH::SMESH_GroupBase_ptr theNodesNot,
4277 GEOM::GEOM_Object_ptr theShape )
4280 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4285 ::SMESH_MeshEditor aMeshEditor( myMesh );
4287 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4288 TIDSortedElemSet anElems, aNodes, anAffected;
4289 groupToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4290 groupToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4292 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4293 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4295 storeResult( aMeshEditor) ;
4300 //================================================================================
4302 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4303 This method provided for convenience works as DoubleNodes() described above.
4304 \param theElems - list of groups of elements (edges or faces) to be replicated
4305 \param theNodesNot - list of groups of nodes not to replicated
4306 \param theAffectedElems - group of elements to which the replicated nodes
4307 should be associated to.
4308 \return TRUE if operation has been completed successfully, FALSE otherwise
4309 \sa DoubleNodeGroup(), DoubleNodes()
4311 //================================================================================
4313 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
4314 SMESHDS_Mesh* theMeshDS,
4315 TIDSortedElemSet& theElemSet,
4316 const bool theIsNodeGrp)
4318 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
4320 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
4321 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
4322 : aGrp->GetType() != SMESH::NODE ) )
4324 SMESH::long_array_var anIDs = aGrp->GetIDs();
4325 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
4330 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(
4331 const SMESH::ListOfGroups& theElems,
4332 const SMESH::ListOfGroups& theNodesNot,
4333 const SMESH::ListOfGroups& theAffectedElems )
4337 ::SMESH_MeshEditor aMeshEditor( myMesh );
4339 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4340 TIDSortedElemSet anElems, aNodes, anAffected;
4341 listOfGroupToSet(theElems, aMeshDS, anElems, false );
4342 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
4343 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
4345 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4347 storeResult( aMeshEditor) ;
4352 //================================================================================
4354 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4355 This method provided for convenience works as DoubleNodes() described above.
4356 \param theElems - list of groups of elements (edges or faces) to be replicated
4357 \param theNodesNot - list of groups of nodes not to replicated
4358 \param theShape - shape to detect affected elements (element which geometric center
4359 located on or inside shape).
4360 The replicated nodes should be associated to affected elements.
4361 \return TRUE if operation has been completed successfully, FALSE otherwise
4362 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
4364 //================================================================================
4366 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroupsInRegion(
4367 const SMESH::ListOfGroups& theElems,
4368 const SMESH::ListOfGroups& theNodesNot,
4369 GEOM::GEOM_Object_ptr theShape )
4373 ::SMESH_MeshEditor aMeshEditor( myMesh );
4375 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4376 TIDSortedElemSet anElems, aNodes;
4377 listOfGroupToSet(theElems, aMeshDS, anElems,false );
4378 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
4380 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4381 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4383 storeResult( aMeshEditor) ;