1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_MeshEditor_i.cxx
24 // Author : Nicolas REJNERI
27 #include "SMESH_MeshEditor_i.hxx"
29 #include "SMDS_MeshEdge.hxx"
30 #include "SMDS_MeshFace.hxx"
31 #include "SMDS_MeshVolume.hxx"
32 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
33 #include "SMESH_MeshEditor.hxx"
34 #include "SMESH_subMeshEventListener.hxx"
35 #include "SMESH_Gen_i.hxx"
36 #include "SMESH_Filter_i.hxx"
37 #include "SMESH_subMesh_i.hxx"
38 #include "SMESH_Group_i.hxx"
39 #include "SMESH_PythonDump.hxx"
41 #include "utilities.h"
42 #include "Utils_ExceptHandlers.hxx"
43 #include "Utils_CorbaException.hxx"
45 #include <BRepAdaptor_Surface.hxx>
46 #include <BRep_Tool.hxx>
47 #include <TopExp_Explorer.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Face.hxx>
55 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
59 #include <Standard_Failure.hxx>
62 #include <Standard_ErrorHandler.hxx>
67 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
70 using SMESH::TPythonDump;
74 //=============================================================================
76 * \brief Mesh to apply modifications for preview purposes
78 //=============================================================================
80 struct TPreviewMesh: public SMESH_Mesh
82 SMDSAbs_ElementType myPreviewType; // type to show
84 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
85 _isShapeToMesh = (_id =_studyId =_idDoc = 0);
86 _myMeshDS = new SMESHDS_Mesh( _id, true );
87 myPreviewType = previewElements;
90 virtual ~TPreviewMesh() { delete _myMeshDS; }
91 //!< Copy a set of elements
92 void Copy(const TIDSortedElemSet & theElements,
93 TIDSortedElemSet& theCopyElements,
94 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
95 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
97 // loop on theIDsOfElements
98 TIDSortedElemSet::const_iterator eIt = theElements.begin();
99 for ( ; eIt != theElements.end(); ++eIt )
101 const SMDS_MeshElement* anElem = *eIt;
102 if ( !anElem ) continue;
103 SMDSAbs_ElementType type = anElem->GetType();
104 if ( type == theAvoidType ||
105 ( theSelectType != SMDSAbs_All && type != theSelectType ))
108 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
109 theCopyElements.insert( theCopyElements.end(), anElemCopy );
113 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
115 // copy element nodes
116 int anElemNbNodes = anElem->NbNodes();
117 vector< int > anElemNodesID( anElemNbNodes ) ;
118 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
119 for ( int i = 0; itElemNodes->more(); i++)
121 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
123 anElemNodesID[i] = anElemNode->GetID();
126 // creates a corresponding element on copied nodes
127 SMDS_MeshElement* anElemCopy = 0;
128 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
130 const SMDS_PolyhedralVolumeOfNodes* ph =
131 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
133 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
134 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
137 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
144 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
146 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
147 anElemNode->GetID());
149 };// struct TPreviewMesh
151 static SMESH_NodeSearcher * myNodeSearcher = 0;
153 //=============================================================================
155 * \brief Deleter of myNodeSearcher at any compute event occured
157 //=============================================================================
159 struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
163 TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
165 //!< Delete myNodeSearcher
168 if ( myNodeSearcher ) { delete myNodeSearcher; myNodeSearcher = 0; }
170 typedef map < int, SMESH_subMesh * > TDependsOnMap;
171 //!< The meshod called by submesh: do my main job
172 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
173 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
175 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
177 Unset( sm->GetFather() );
180 //!< set self on all submeshes and delete myNodeSearcher if other mesh is set
181 void Set(SMESH_Mesh* mesh)
183 if ( myMesh && myMesh != mesh ) {
188 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
189 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
190 TDependsOnMap::const_iterator sm;
191 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
192 sm->second->SetEventListener( this, 0, sm->second );
195 //!< delete self from all submeshes
196 void Unset(SMESH_Mesh* mesh)
198 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
199 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
200 TDependsOnMap::const_iterator sm;
201 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
202 sm->second->DeleteEventListener( this );
208 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
210 TCollection_AsciiString typeStr;
211 switch ( theMirrorType ) {
212 case SMESH::SMESH_MeshEditor::POINT:
213 typeStr = "SMESH.SMESH_MeshEditor.POINT";
215 case SMESH::SMESH_MeshEditor::AXIS:
216 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
219 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
225 //=============================================================================
229 //=============================================================================
231 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
234 myMesh = & theMesh->GetImpl();
235 myPreviewMode = isPreview;
238 //================================================================================
242 //================================================================================
244 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
248 //================================================================================
250 * \brief Clear members
252 //================================================================================
254 void SMESH_MeshEditor_i::initData()
256 if ( myPreviewMode ) {
257 myPreviewData = new SMESH::MeshPreviewStruct();
260 myLastCreatedElems = new SMESH::long_array();
261 myLastCreatedNodes = new SMESH::long_array();
262 TNodeSearcherDeleter::Delete();
266 //=============================================================================
270 //=============================================================================
273 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
277 ::SMESH_MeshEditor anEditor( myMesh );
280 for (int i = 0; i < IDsOfElements.length(); i++)
281 IdList.push_back( IDsOfElements[i] );
283 // Update Python script
284 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
286 TPythonDump() << "print 'RemoveElements: ', isDone";
289 return anEditor.Remove( IdList, false );
292 //=============================================================================
296 //=============================================================================
298 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
302 ::SMESH_MeshEditor anEditor( myMesh );
304 for (int i = 0; i < IDsOfNodes.length(); i++)
305 IdList.push_back( IDsOfNodes[i] );
307 // Update Python script
308 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
310 TPythonDump() << "print 'RemoveNodes: ', isDone";
313 return anEditor.Remove( IdList, true );
316 //=============================================================================
320 //=============================================================================
322 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
326 int NbNodes = IDsOfNodes.length();
327 SMDS_MeshElement* elem = 0;
330 CORBA::Long index1 = IDsOfNodes[0];
331 CORBA::Long index2 = IDsOfNodes[1];
332 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
334 // Update Python script
335 TPythonDump() << "edge = " << this << ".AddEdge([ "
336 << index1 << ", " << index2 <<" ])";
339 CORBA::Long n1 = IDsOfNodes[0];
340 CORBA::Long n2 = IDsOfNodes[1];
341 CORBA::Long n12 = IDsOfNodes[2];
342 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
343 GetMeshDS()->FindNode(n2),
344 GetMeshDS()->FindNode(n12));
345 // Update Python script
346 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
347 <<n1<<", "<<n2<<", "<<n12<<" ])";
351 return elem->GetID();
356 //=============================================================================
360 //=============================================================================
362 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
363 CORBA::Double y, CORBA::Double z)
367 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
369 // Update Python script
370 TPythonDump() << "nodeID = " << this << ".AddNode( "
371 << x << ", " << y << ", " << z << " )";
376 //=============================================================================
380 //=============================================================================
382 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
386 int NbNodes = IDsOfNodes.length();
392 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
393 for (int i = 0; i < NbNodes; i++)
394 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
396 SMDS_MeshElement* elem = 0;
398 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
400 else if (NbNodes == 4) {
401 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
403 else if (NbNodes == 6) {
404 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
407 else if (NbNodes == 8) {
408 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
409 nodes[4], nodes[5], nodes[6], nodes[7]);
412 // Update Python script
413 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
416 return elem->GetID();
421 //=============================================================================
425 //=============================================================================
426 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
427 (const SMESH::long_array & IDsOfNodes)
431 int NbNodes = IDsOfNodes.length();
432 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
433 for (int i = 0; i < NbNodes; i++)
434 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
436 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
438 // Update Python script
439 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
441 TPythonDump() << "print 'AddPolygonalFace: ', faceID";
445 return elem->GetID();
450 //=============================================================================
454 //=============================================================================
456 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
460 int NbNodes = IDsOfNodes.length();
461 vector< const SMDS_MeshNode*> n(NbNodes);
462 for(int i=0;i<NbNodes;i++)
463 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
465 SMDS_MeshElement* elem = 0;
468 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
469 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
470 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
471 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
472 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
473 n[6],n[7],n[8],n[9]);
475 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
476 n[7],n[8],n[9],n[10],n[11],n[12]);
478 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
479 n[9],n[10],n[11],n[12],n[13],n[14]);
481 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
482 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
483 n[15],n[16],n[17],n[18],n[19]);
487 // Update Python script
488 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
490 TPythonDump() << "print 'AddVolume: ', volID";
494 return elem->GetID();
499 //=============================================================================
501 * AddPolyhedralVolume
503 //=============================================================================
504 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume
505 (const SMESH::long_array & IDsOfNodes,
506 const SMESH::long_array & Quantities)
510 int NbNodes = IDsOfNodes.length();
511 std::vector<const SMDS_MeshNode*> n (NbNodes);
512 for (int i = 0; i < NbNodes; i++)
513 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
515 int NbFaces = Quantities.length();
516 std::vector<int> q (NbFaces);
517 for (int j = 0; j < NbFaces; j++)
518 q[j] = Quantities[j];
520 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
522 // Update Python script
523 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
524 << IDsOfNodes << ", " << Quantities << " )";
526 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
530 return elem->GetID();
535 //=============================================================================
537 * AddPolyhedralVolumeByFaces
539 //=============================================================================
540 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
541 (const SMESH::long_array & IdsOfFaces)
545 int NbFaces = IdsOfFaces.length();
546 std::vector<const SMDS_MeshNode*> poly_nodes;
547 std::vector<int> quantities (NbFaces);
549 for (int i = 0; i < NbFaces; i++) {
550 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
551 quantities[i] = aFace->NbNodes();
553 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
555 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
559 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
561 // Update Python script
562 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
563 << IdsOfFaces << " )";
565 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
569 return elem->GetID();
574 //=============================================================================
576 * \brief Bind a node to a vertex
577 * \param NodeID - node ID
578 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
579 * \retval boolean - false if NodeID or VertexID is invalid
581 //=============================================================================
583 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
584 throw (SALOME::SALOME_Exception)
586 Unexpect aCatch(SALOME_SalomeException);
588 SMESHDS_Mesh * mesh = GetMeshDS();
589 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
591 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
593 if ( mesh->MaxShapeIndex() < VertexID )
594 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
596 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
597 if ( shape.ShapeType() != TopAbs_VERTEX )
598 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
600 mesh->SetNodeOnVertex( node, VertexID );
603 //=============================================================================
605 * \brief Store node position on an edge
606 * \param NodeID - node ID
607 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
608 * \param paramOnEdge - parameter on edge where the node is located
609 * \retval boolean - false if any parameter is invalid
611 //=============================================================================
613 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
614 CORBA::Double paramOnEdge)
615 throw (SALOME::SALOME_Exception)
617 Unexpect aCatch(SALOME_SalomeException);
619 SMESHDS_Mesh * mesh = GetMeshDS();
620 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
622 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
624 if ( mesh->MaxShapeIndex() < EdgeID )
625 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
627 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
628 if ( shape.ShapeType() != TopAbs_EDGE )
629 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
632 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
633 if ( paramOnEdge < f || paramOnEdge > l )
634 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
636 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
639 //=============================================================================
641 * \brief Store node position on a face
642 * \param NodeID - node ID
643 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
644 * \param u - U parameter on face where the node is located
645 * \param v - V parameter on face where the node is located
646 * \retval boolean - false if any parameter is invalid
648 //=============================================================================
650 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
651 CORBA::Double u, CORBA::Double v)
652 throw (SALOME::SALOME_Exception)
654 Unexpect aCatch(SALOME_SalomeException);
656 SMESHDS_Mesh * mesh = GetMeshDS();
657 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
659 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
661 if ( mesh->MaxShapeIndex() < FaceID )
662 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
664 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
665 if ( shape.ShapeType() != TopAbs_FACE )
666 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
668 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
669 bool isOut = ( u < surf.FirstUParameter() ||
670 u > surf.LastUParameter() ||
671 v < surf.FirstVParameter() ||
672 v > surf.LastVParameter() );
676 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
677 << " u( " << surf.FirstUParameter()
678 << "," << surf.LastUParameter()
679 << ") v( " << surf.FirstVParameter()
680 << "," << surf.LastVParameter() << ")" );
682 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
685 mesh->SetNodeOnFace( node, FaceID, u, v );
688 //=============================================================================
690 * \brief Bind a node to a solid
691 * \param NodeID - node ID
692 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
693 * \retval boolean - false if NodeID or SolidID is invalid
695 //=============================================================================
697 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
698 throw (SALOME::SALOME_Exception)
700 Unexpect aCatch(SALOME_SalomeException);
702 SMESHDS_Mesh * mesh = GetMeshDS();
703 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
705 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
707 if ( mesh->MaxShapeIndex() < SolidID )
708 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
710 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
711 if ( shape.ShapeType() != TopAbs_SOLID &&
712 shape.ShapeType() != TopAbs_SHELL)
713 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
715 mesh->SetNodeInVolume( node, SolidID );
718 //=============================================================================
720 * \brief Bind an element to a shape
721 * \param ElementID - element ID
722 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
723 * \retval boolean - false if ElementID or ShapeID is invalid
725 //=============================================================================
727 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
729 throw (SALOME::SALOME_Exception)
731 Unexpect aCatch(SALOME_SalomeException);
733 SMESHDS_Mesh * mesh = GetMeshDS();
734 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
736 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
738 if ( mesh->MaxShapeIndex() < ShapeID )
739 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
741 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
742 if ( shape.ShapeType() != TopAbs_EDGE &&
743 shape.ShapeType() != TopAbs_FACE &&
744 shape.ShapeType() != TopAbs_SOLID &&
745 shape.ShapeType() != TopAbs_SHELL )
746 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
748 mesh->SetMeshElementOnShape( elem, ShapeID );
752 //=============================================================================
756 //=============================================================================
758 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
765 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
769 GetMeshDS()->MoveNode(node, x, y, z);
771 // Update Python script
772 TPythonDump() << "isDone = " << this << ".MoveNode( "
773 << NodeID << ", " << x << ", " << y << ", " << z << " )";
778 //=============================================================================
782 //=============================================================================
784 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
789 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
790 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
794 // Update Python script
795 TPythonDump() << "isDone = " << this << ".InverseDiag( "
796 << NodeID1 << ", " << NodeID2 << " )";
798 ::SMESH_MeshEditor aMeshEditor( myMesh );
799 return aMeshEditor.InverseDiag ( n1, n2 );
802 //=============================================================================
806 //=============================================================================
808 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
813 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
814 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
818 // Update Python script
819 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
820 << NodeID1 << ", " << NodeID2 << " )";
822 ::SMESH_MeshEditor aMeshEditor( myMesh );
824 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
826 storeResult(aMeshEditor);
831 //=============================================================================
835 //=============================================================================
837 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
841 ::SMESH_MeshEditor anEditor( myMesh );
842 for (int i = 0; i < IDsOfElements.length(); i++)
844 CORBA::Long index = IDsOfElements[i];
845 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
847 anEditor.Reorient( elem );
849 // Update Python script
850 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
856 //=============================================================================
860 //=============================================================================
862 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
866 SMESH::long_array_var anElementsId = theObject->GetIDs();
867 CORBA::Boolean isDone = Reorient(anElementsId);
869 // Clear python line, created by Reorient()
870 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
871 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
873 // Update Python script
874 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
881 //================================================================================
883 * \brief function for conversion long_array to TIDSortedElemSet
884 * \param IDs - array of IDs
885 * \param aMesh - mesh
886 * \param aMap - collection to fill
887 * \param aType - element type
889 //================================================================================
891 void arrayToSet(const SMESH::long_array & IDs,
892 const SMESHDS_Mesh* aMesh,
893 TIDSortedElemSet& aMap,
894 const SMDSAbs_ElementType aType = SMDSAbs_All )
896 for (int i=0; i<IDs.length(); i++) {
897 CORBA::Long ind = IDs[i];
898 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
899 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
905 //=============================================================================
909 //=============================================================================
910 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
911 SMESH::NumericalFunctor_ptr Criterion,
912 CORBA::Double MaxAngle)
916 SMESHDS_Mesh* aMesh = GetMeshDS();
917 TIDSortedElemSet faces;
918 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
920 SMESH::NumericalFunctor_i* aNumericalFunctor =
921 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
922 SMESH::Controls::NumericalFunctorPtr aCrit;
923 if ( !aNumericalFunctor )
924 aCrit.reset( new SMESH::Controls::AspectRatio() );
926 aCrit = aNumericalFunctor->GetNumericalFunctor();
928 // Update Python script
929 TPythonDump() << "isDone = " << this << ".TriToQuad( "
930 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
932 TPythonDump() << "print 'TriToQuad: ', isDone";
935 ::SMESH_MeshEditor anEditor( myMesh );
937 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
939 storeResult(anEditor);
945 //=============================================================================
949 //=============================================================================
950 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
951 SMESH::NumericalFunctor_ptr Criterion,
952 CORBA::Double MaxAngle)
956 SMESH::long_array_var anElementsId = theObject->GetIDs();
957 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
959 // Clear python line(s), created by TriToQuad()
960 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
961 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
963 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
966 SMESH::NumericalFunctor_i* aNumericalFunctor =
967 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
969 // Update Python script
970 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
971 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
973 TPythonDump() << "print 'TriToQuadObject: ', isDone";
980 //=============================================================================
984 //=============================================================================
985 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
986 SMESH::NumericalFunctor_ptr Criterion)
990 SMESHDS_Mesh* aMesh = GetMeshDS();
991 TIDSortedElemSet faces;
992 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
994 SMESH::NumericalFunctor_i* aNumericalFunctor =
995 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
996 SMESH::Controls::NumericalFunctorPtr aCrit;
997 if ( !aNumericalFunctor )
998 aCrit.reset( new SMESH::Controls::AspectRatio() );
1000 aCrit = aNumericalFunctor->GetNumericalFunctor();
1003 // Update Python script
1004 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1006 TPythonDump() << "print 'QuadToTri: ', isDone";
1009 ::SMESH_MeshEditor anEditor( myMesh );
1010 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1012 storeResult(anEditor);
1018 //=============================================================================
1022 //=============================================================================
1023 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1024 SMESH::NumericalFunctor_ptr Criterion)
1028 SMESH::long_array_var anElementsId = theObject->GetIDs();
1029 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1031 // Clear python line(s), created by QuadToTri()
1032 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1033 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1035 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1038 SMESH::NumericalFunctor_i* aNumericalFunctor =
1039 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1041 // Update Python script
1042 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1044 TPythonDump() << "print 'QuadToTriObject: ', isDone";
1051 //=============================================================================
1055 //=============================================================================
1056 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1057 CORBA::Boolean Diag13)
1061 SMESHDS_Mesh* aMesh = GetMeshDS();
1062 TIDSortedElemSet faces;
1063 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1065 // Update Python script
1066 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1067 << IDsOfElements << ", " << Diag13 << " )";
1069 TPythonDump() << "print 'SplitQuad: ', isDone";
1072 ::SMESH_MeshEditor anEditor( myMesh );
1073 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1075 storeResult(anEditor);
1081 //=============================================================================
1085 //=============================================================================
1086 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1087 CORBA::Boolean Diag13)
1091 SMESH::long_array_var anElementsId = theObject->GetIDs();
1092 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1094 // Clear python line(s), created by SplitQuad()
1095 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1096 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1098 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1101 // Update Python script
1102 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1103 << theObject << ", " << Diag13 << " )";
1105 TPythonDump() << "print 'SplitQuadObject: ', isDone";
1112 //=============================================================================
1116 //=============================================================================
1117 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1118 SMESH::NumericalFunctor_ptr Criterion)
1120 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1121 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1123 SMESH::NumericalFunctor_i* aNumericalFunctor =
1124 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1125 SMESH::Controls::NumericalFunctorPtr aCrit;
1126 if (aNumericalFunctor)
1127 aCrit = aNumericalFunctor->GetNumericalFunctor();
1129 aCrit.reset(new SMESH::Controls::AspectRatio());
1131 ::SMESH_MeshEditor anEditor (myMesh);
1132 return anEditor.BestSplit(quad, aCrit);
1138 //=======================================================================
1141 //=======================================================================
1144 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1145 const SMESH::long_array & IDsOfFixedNodes,
1146 CORBA::Long MaxNbOfIterations,
1147 CORBA::Double MaxAspectRatio,
1148 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1150 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1151 MaxAspectRatio, Method, false );
1155 //=======================================================================
1156 //function : SmoothParametric
1158 //=======================================================================
1161 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1162 const SMESH::long_array & IDsOfFixedNodes,
1163 CORBA::Long MaxNbOfIterations,
1164 CORBA::Double MaxAspectRatio,
1165 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1167 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1168 MaxAspectRatio, Method, true );
1172 //=======================================================================
1173 //function : SmoothObject
1175 //=======================================================================
1178 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1179 const SMESH::long_array & IDsOfFixedNodes,
1180 CORBA::Long MaxNbOfIterations,
1181 CORBA::Double MaxAspectRatio,
1182 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1184 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1185 MaxAspectRatio, Method, false);
1189 //=======================================================================
1190 //function : SmoothParametricObject
1192 //=======================================================================
1195 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1196 const SMESH::long_array & IDsOfFixedNodes,
1197 CORBA::Long MaxNbOfIterations,
1198 CORBA::Double MaxAspectRatio,
1199 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1201 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1202 MaxAspectRatio, Method, true);
1206 //=============================================================================
1210 //=============================================================================
1213 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1214 const SMESH::long_array & IDsOfFixedNodes,
1215 CORBA::Long MaxNbOfIterations,
1216 CORBA::Double MaxAspectRatio,
1217 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1222 SMESHDS_Mesh* aMesh = GetMeshDS();
1224 TIDSortedElemSet elements;
1225 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1227 set<const SMDS_MeshNode*> fixedNodes;
1228 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1229 CORBA::Long index = IDsOfFixedNodes[i];
1230 const SMDS_MeshNode * node = aMesh->FindNode(index);
1232 fixedNodes.insert( node );
1234 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1235 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1236 method = ::SMESH_MeshEditor::CENTROIDAL;
1238 ::SMESH_MeshEditor anEditor( myMesh );
1239 anEditor.Smooth(elements, fixedNodes, method,
1240 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1242 storeResult(anEditor);
1244 // Update Python script
1245 TPythonDump() << "isDone = " << this << "."
1246 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1247 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1248 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1249 << "SMESH.SMESH_MeshEditor."
1250 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1251 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1253 TPythonDump() << "print 'Smooth: ', isDone";
1260 //=============================================================================
1264 //=============================================================================
1267 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1268 const SMESH::long_array & IDsOfFixedNodes,
1269 CORBA::Long MaxNbOfIterations,
1270 CORBA::Double MaxAspectRatio,
1271 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1276 SMESH::long_array_var anElementsId = theObject->GetIDs();
1277 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1278 MaxAspectRatio, Method, IsParametric);
1280 // Clear python line(s), created by Smooth()
1281 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1282 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1284 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1287 // Update Python script
1288 TPythonDump() << "isDone = " << this << "."
1289 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1290 << theObject << ", " << IDsOfFixedNodes << ", "
1291 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1292 << "SMESH.SMESH_MeshEditor."
1293 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1294 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1296 TPythonDump() << "print 'SmoothObject: ', isDone";
1303 //=============================================================================
1307 //=============================================================================
1309 void SMESH_MeshEditor_i::RenumberNodes()
1311 // Update Python script
1312 TPythonDump() << this << ".RenumberNodes()";
1314 GetMeshDS()->Renumber( true );
1318 //=============================================================================
1322 //=============================================================================
1324 void SMESH_MeshEditor_i::RenumberElements()
1326 // Update Python script
1327 TPythonDump() << this << ".RenumberElements()";
1329 GetMeshDS()->Renumber( false );
1332 //=======================================================================
1334 * \brief Return groups by their IDs
1336 //=======================================================================
1338 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1342 myMesh_i->CreateGroupServants();
1343 return myMesh_i->GetGroups( *groupIDs );
1346 //=======================================================================
1347 //function : rotationSweep
1349 //=======================================================================
1351 SMESH::ListOfGroups*
1352 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1353 const SMESH::AxisStruct & theAxis,
1354 CORBA::Double theAngleInRadians,
1355 CORBA::Long theNbOfSteps,
1356 CORBA::Double theTolerance,
1357 const bool theMakeGroups,
1358 const SMDSAbs_ElementType theElementType)
1362 TIDSortedElemSet inElements, copyElements;
1363 arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType);
1365 TIDSortedElemSet* workElements = & inElements;
1366 TPreviewMesh tmpMesh( SMDSAbs_Face );
1367 SMESH_Mesh* mesh = 0;
1368 bool makeWalls=true;
1369 if ( myPreviewMode )
1371 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1372 tmpMesh.Copy( inElements, copyElements, select, avoid );
1374 workElements = & copyElements;
1375 //makeWalls = false;
1382 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1383 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1385 ::SMESH_MeshEditor anEditor( mesh );
1386 ::SMESH_MeshEditor::PGroupIDs groupIds =
1387 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1388 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1389 storeResult(anEditor);
1391 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1394 //=======================================================================
1395 //function : RotationSweep
1397 //=======================================================================
1399 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1400 const SMESH::AxisStruct & theAxis,
1401 CORBA::Double theAngleInRadians,
1402 CORBA::Long theNbOfSteps,
1403 CORBA::Double theTolerance)
1405 if ( !myPreviewMode ) {
1406 TPythonDump() << this << ".RotationSweep( "
1407 << theIDsOfElements << ", "
1409 << theAngleInRadians << ", "
1410 << theNbOfSteps << ", "
1411 << theTolerance << " )";
1413 rotationSweep(theIDsOfElements,
1421 //=======================================================================
1422 //function : RotationSweepMakeGroups
1424 //=======================================================================
1426 SMESH::ListOfGroups*
1427 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1428 const SMESH::AxisStruct& theAxis,
1429 CORBA::Double theAngleInRadians,
1430 CORBA::Long theNbOfSteps,
1431 CORBA::Double theTolerance)
1433 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1439 if ( !myPreviewMode ) {
1440 TPythonDump aPythonDump;
1441 DumpGroupsList(aPythonDump,aGroups);
1442 aPythonDump<< this << ".RotationSweepMakeGroups( "
1443 << theIDsOfElements << ", "
1445 << theAngleInRadians << ", "
1446 << theNbOfSteps << ", "
1447 << theTolerance << " )";
1452 //=======================================================================
1453 //function : RotationSweepObject
1455 //=======================================================================
1457 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1458 const SMESH::AxisStruct & theAxis,
1459 CORBA::Double theAngleInRadians,
1460 CORBA::Long theNbOfSteps,
1461 CORBA::Double theTolerance)
1463 if ( !myPreviewMode ) {
1464 TPythonDump() << this << ".RotationSweepObject( "
1465 << theObject << ", "
1467 << theAngleInRadians << ", "
1468 << theNbOfSteps << ", "
1469 << theTolerance << " )";
1471 SMESH::long_array_var anElementsId = theObject->GetIDs();
1472 rotationSweep(anElementsId,
1480 //=======================================================================
1481 //function : RotationSweepObject1D
1483 //=======================================================================
1485 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1486 const SMESH::AxisStruct & theAxis,
1487 CORBA::Double theAngleInRadians,
1488 CORBA::Long theNbOfSteps,
1489 CORBA::Double theTolerance)
1491 if ( !myPreviewMode ) {
1492 TPythonDump() << this << ".RotationSweepObject1D( "
1493 << theObject << ", "
1495 << theAngleInRadians << ", "
1496 << theNbOfSteps << ", "
1497 << theTolerance << " )";
1499 SMESH::long_array_var anElementsId = theObject->GetIDs();
1500 rotationSweep(anElementsId,
1509 //=======================================================================
1510 //function : RotationSweepObject2D
1512 //=======================================================================
1514 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1515 const SMESH::AxisStruct & theAxis,
1516 CORBA::Double theAngleInRadians,
1517 CORBA::Long theNbOfSteps,
1518 CORBA::Double theTolerance)
1520 if ( !myPreviewMode ) {
1521 TPythonDump() << this << ".RotationSweepObject2D( "
1522 << theObject << ", "
1524 << theAngleInRadians << ", "
1525 << theNbOfSteps << ", "
1526 << theTolerance << " )";
1528 SMESH::long_array_var anElementsId = theObject->GetIDs();
1529 rotationSweep(anElementsId,
1538 //=======================================================================
1539 //function : RotationSweepObjectMakeGroups
1541 //=======================================================================
1543 SMESH::ListOfGroups*
1544 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1545 const SMESH::AxisStruct& theAxis,
1546 CORBA::Double theAngleInRadians,
1547 CORBA::Long theNbOfSteps,
1548 CORBA::Double theTolerance)
1550 SMESH::long_array_var anElementsId = theObject->GetIDs();
1551 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1557 if ( !myPreviewMode ) {
1558 TPythonDump aPythonDump;
1559 DumpGroupsList(aPythonDump,aGroups);
1560 aPythonDump<< this << ".RotationSweepObjectMakeGroups( "
1561 << theObject << ", "
1563 << theAngleInRadians << ", "
1564 << theNbOfSteps << ", "
1565 << theTolerance << " )";
1570 //=======================================================================
1571 //function : RotationSweepObject1DMakeGroups
1573 //=======================================================================
1575 SMESH::ListOfGroups*
1576 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1577 const SMESH::AxisStruct& theAxis,
1578 CORBA::Double theAngleInRadians,
1579 CORBA::Long theNbOfSteps,
1580 CORBA::Double theTolerance)
1582 SMESH::long_array_var anElementsId = theObject->GetIDs();
1583 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1590 if ( !myPreviewMode ) {
1591 TPythonDump aPythonDump;
1592 DumpGroupsList(aPythonDump,aGroups);
1593 aPythonDump<< this << ".RotationSweepObject1DMakeGroups( "
1594 << theObject << ", "
1596 << theAngleInRadians << ", "
1597 << theNbOfSteps << ", "
1598 << theTolerance << " )";
1603 //=======================================================================
1604 //function : RotationSweepObject2DMakeGroups
1606 //=======================================================================
1608 SMESH::ListOfGroups*
1609 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1610 const SMESH::AxisStruct& theAxis,
1611 CORBA::Double theAngleInRadians,
1612 CORBA::Long theNbOfSteps,
1613 CORBA::Double theTolerance)
1615 SMESH::long_array_var anElementsId = theObject->GetIDs();
1616 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1623 if ( !myPreviewMode ) {
1624 TPythonDump aPythonDump;
1625 DumpGroupsList(aPythonDump,aGroups);
1626 aPythonDump<< this << ".RotationSweepObject2DMakeGroups( "
1627 << theObject << ", "
1629 << theAngleInRadians << ", "
1630 << theNbOfSteps << ", "
1631 << theTolerance << " )";
1637 //=======================================================================
1638 //function : extrusionSweep
1640 //=======================================================================
1642 SMESH::ListOfGroups*
1643 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1644 const SMESH::DirStruct & theStepVector,
1645 CORBA::Long theNbOfSteps,
1646 const bool theMakeGroups,
1647 const SMDSAbs_ElementType theElementType)
1655 TIDSortedElemSet elements;
1656 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1658 const SMESH::PointStruct * P = &theStepVector.PS;
1659 gp_Vec stepVec( P->x, P->y, P->z );
1661 TElemOfElemListMap aHystory;
1662 ::SMESH_MeshEditor anEditor( myMesh );
1663 ::SMESH_MeshEditor::PGroupIDs groupIds =
1664 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1666 storeResult(anEditor);
1668 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1670 } catch(Standard_Failure) {
1671 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1672 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1677 //=======================================================================
1678 //function : ExtrusionSweep
1680 //=======================================================================
1682 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1683 const SMESH::DirStruct & theStepVector,
1684 CORBA::Long theNbOfSteps)
1686 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1687 if ( !myPreviewMode ) {
1688 TPythonDump() << this << ".ExtrusionSweep( "
1689 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1694 //=======================================================================
1695 //function : ExtrusionSweepObject
1697 //=======================================================================
1699 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1700 const SMESH::DirStruct & theStepVector,
1701 CORBA::Long theNbOfSteps)
1703 SMESH::long_array_var anElementsId = theObject->GetIDs();
1704 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1705 if ( !myPreviewMode ) {
1706 TPythonDump() << this << ".ExtrusionSweepObject( "
1707 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1711 //=======================================================================
1712 //function : ExtrusionSweepObject1D
1714 //=======================================================================
1716 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1717 const SMESH::DirStruct & theStepVector,
1718 CORBA::Long theNbOfSteps)
1720 SMESH::long_array_var anElementsId = theObject->GetIDs();
1721 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1722 if ( !myPreviewMode ) {
1723 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1724 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1728 //=======================================================================
1729 //function : ExtrusionSweepObject2D
1731 //=======================================================================
1733 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1734 const SMESH::DirStruct & theStepVector,
1735 CORBA::Long theNbOfSteps)
1737 SMESH::long_array_var anElementsId = theObject->GetIDs();
1738 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1739 if ( !myPreviewMode ) {
1740 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1741 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1745 //=======================================================================
1746 //function : ExtrusionSweepMakeGroups
1748 //=======================================================================
1750 SMESH::ListOfGroups*
1751 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1752 const SMESH::DirStruct& theStepVector,
1753 CORBA::Long theNbOfSteps)
1755 SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1757 if ( !myPreviewMode ) {
1758 TPythonDump aPythonDump;
1759 DumpGroupsList(aPythonDump,aGroups);
1760 aPythonDump << this << ".ExtrusionSweepMakeGroups( "
1761 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1765 //=======================================================================
1766 //function : ExtrusionSweepObjectMakeGroups
1768 //=======================================================================
1770 SMESH::ListOfGroups*
1771 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1772 const SMESH::DirStruct& theStepVector,
1773 CORBA::Long theNbOfSteps)
1775 SMESH::long_array_var anElementsId = theObject->GetIDs();
1776 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1778 if ( !myPreviewMode ) {
1779 TPythonDump aPythonDump;
1780 DumpGroupsList(aPythonDump,aGroups);
1781 aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( "
1782 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1787 //=======================================================================
1788 //function : ExtrusionSweepObject1DMakeGroups
1790 //=======================================================================
1792 SMESH::ListOfGroups*
1793 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1794 const SMESH::DirStruct& theStepVector,
1795 CORBA::Long theNbOfSteps)
1797 SMESH::long_array_var anElementsId = theObject->GetIDs();
1798 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1799 if ( !myPreviewMode ) {
1800 TPythonDump aPythonDump;
1801 DumpGroupsList(aPythonDump,aGroups);
1802 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( "
1803 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1808 //=======================================================================
1809 //function : ExtrusionSweepObject2DMakeGroups
1811 //=======================================================================
1813 SMESH::ListOfGroups*
1814 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1815 const SMESH::DirStruct& theStepVector,
1816 CORBA::Long theNbOfSteps)
1818 SMESH::long_array_var anElementsId = theObject->GetIDs();
1819 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1820 if ( !myPreviewMode ) {
1821 TPythonDump aPythonDump;
1822 DumpGroupsList(aPythonDump,aGroups);
1823 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( "
1824 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1830 //=======================================================================
1831 //function : advancedExtrusion
1833 //=======================================================================
1835 SMESH::ListOfGroups*
1836 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1837 const SMESH::DirStruct & theStepVector,
1838 CORBA::Long theNbOfSteps,
1839 CORBA::Long theExtrFlags,
1840 CORBA::Double theSewTolerance,
1841 const bool theMakeGroups)
1845 TIDSortedElemSet elements;
1846 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1848 const SMESH::PointStruct * P = &theStepVector.PS;
1849 gp_Vec stepVec( P->x, P->y, P->z );
1851 ::SMESH_MeshEditor anEditor( myMesh );
1852 TElemOfElemListMap aHystory;
1853 ::SMESH_MeshEditor::PGroupIDs groupIds =
1854 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1855 theMakeGroups, theExtrFlags, theSewTolerance);
1856 storeResult(anEditor);
1858 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1861 //=======================================================================
1862 //function : AdvancedExtrusion
1864 //=======================================================================
1866 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1867 const SMESH::DirStruct & theStepVector,
1868 CORBA::Long theNbOfSteps,
1869 CORBA::Long theExtrFlags,
1870 CORBA::Double theSewTolerance)
1872 if ( !myPreviewMode ) {
1873 TPythonDump() << "stepVector = " << theStepVector;
1874 TPythonDump() << this << ".AdvancedExtrusion("
1877 << theNbOfSteps << ","
1878 << theExtrFlags << ", "
1879 << theSewTolerance << " )";
1881 advancedExtrusion( theIDsOfElements,
1889 //=======================================================================
1890 //function : AdvancedExtrusionMakeGroups
1892 //=======================================================================
1894 SMESH::ListOfGroups*
1895 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1896 const SMESH::DirStruct& theStepVector,
1897 CORBA::Long theNbOfSteps,
1898 CORBA::Long theExtrFlags,
1899 CORBA::Double theSewTolerance)
1901 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
1908 if ( !myPreviewMode ) {
1909 TPythonDump() << "stepVector = " << theStepVector;
1910 TPythonDump aPythonDump;
1911 DumpGroupsList(aPythonDump,aGroups);
1912 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
1915 << theNbOfSteps << ","
1916 << theExtrFlags << ", "
1917 << theSewTolerance << " )";
1923 //================================================================================
1925 * \brief Convert extrusion error to IDL enum
1927 //================================================================================
1929 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1931 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1935 RETCASE( EXTR_NO_ELEMENTS );
1936 RETCASE( EXTR_PATH_NOT_EDGE );
1937 RETCASE( EXTR_BAD_PATH_SHAPE );
1938 RETCASE( EXTR_BAD_STARTING_NODE );
1939 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1940 RETCASE( EXTR_CANT_GET_TANGENT );
1942 return SMESH::SMESH_MeshEditor::EXTR_OK;
1946 //=======================================================================
1947 //function : extrusionAlongPath
1949 //=======================================================================
1951 SMESH::ListOfGroups*
1952 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1953 SMESH::SMESH_Mesh_ptr thePathMesh,
1954 GEOM::GEOM_Object_ptr thePathShape,
1955 CORBA::Long theNodeStart,
1956 CORBA::Boolean theHasAngles,
1957 const SMESH::double_array & theAngles,
1958 CORBA::Boolean theHasRefPoint,
1959 const SMESH::PointStruct & theRefPoint,
1960 const bool theMakeGroups,
1961 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
1962 const SMDSAbs_ElementType theElementType)
1966 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1967 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1970 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1972 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1973 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1975 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
1976 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1980 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1982 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1986 TIDSortedElemSet elements;
1987 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1989 list<double> angles;
1990 for (int i = 0; i < theAngles.length(); i++) {
1991 angles.push_back( theAngles[i] );
1994 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1996 int nbOldGroups = myMesh->NbGroup();
1998 ::SMESH_MeshEditor anEditor( myMesh );
1999 ::SMESH_MeshEditor::Extrusion_Error error =
2000 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
2001 theHasAngles, angles, false,
2002 theHasRefPoint, refPnt, theMakeGroups );
2003 storeResult(anEditor);
2004 theError = convExtrError( error );
2006 if ( theMakeGroups ) {
2007 list<int> groupIDs = myMesh->GetGroupIds();
2008 list<int>::iterator newBegin = groupIDs.begin();
2009 std::advance( newBegin, nbOldGroups ); // skip old groups
2010 groupIDs.erase( groupIDs.begin(), newBegin );
2011 return getGroups( & groupIDs );
2017 //=======================================================================
2018 //function : extrusionAlongPathX
2020 //=======================================================================
2022 SMESH::ListOfGroups*
2023 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2024 SMESH::SMESH_IDSource_ptr Path,
2025 CORBA::Long NodeStart,
2026 CORBA::Boolean HasAngles,
2027 const SMESH::double_array& Angles,
2028 CORBA::Boolean LinearVariation,
2029 CORBA::Boolean HasRefPoint,
2030 const SMESH::PointStruct& RefPoint,
2031 const bool MakeGroups,
2032 const SMDSAbs_ElementType ElementType,
2033 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2035 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2039 list<double> angles;
2040 for (int i = 0; i < Angles.length(); i++) {
2041 angles.push_back( Angles[i] );
2043 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2044 int nbOldGroups = myMesh->NbGroup();
2046 if ( Path->_is_nil() ) {
2047 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2051 TIDSortedElemSet elements;
2052 arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
2054 ::SMESH_MeshEditor anEditor( myMesh );
2055 ::SMESH_MeshEditor::Extrusion_Error error;
2057 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
2060 SMDS_MeshNode* aNodeStart =
2061 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2062 if ( !aNodeStart ) {
2063 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2066 error = anEditor.ExtrusionAlongTrack( elements, &(aMeshImp->GetImpl()), aNodeStart,
2067 HasAngles, angles, LinearVariation,
2068 HasRefPoint, refPnt, MakeGroups );
2071 SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
2074 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
2075 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
2076 SMDS_MeshNode* aNodeStart =
2077 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2078 if ( !aNodeStart ) {
2079 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2082 SMESH_subMesh* aSubMesh =
2083 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
2084 error = anEditor.ExtrusionAlongTrack( elements, aSubMesh, aNodeStart,
2085 HasAngles, angles, LinearVariation,
2086 HasRefPoint, refPnt, MakeGroups );
2089 SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
2091 // path as group of 1D elements
2095 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2101 storeResult(anEditor);
2102 Error = convExtrError( error );
2105 list<int> groupIDs = myMesh->GetGroupIds();
2106 list<int>::iterator newBegin = groupIDs.begin();
2107 std::advance( newBegin, nbOldGroups ); // skip old groups
2108 groupIDs.erase( groupIDs.begin(), newBegin );
2109 return getGroups( & groupIDs );
2115 //=======================================================================
2116 //function : ExtrusionAlongPath
2118 //=======================================================================
2120 SMESH::SMESH_MeshEditor::Extrusion_Error
2121 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2122 SMESH::SMESH_Mesh_ptr thePathMesh,
2123 GEOM::GEOM_Object_ptr thePathShape,
2124 CORBA::Long theNodeStart,
2125 CORBA::Boolean theHasAngles,
2126 const SMESH::double_array & theAngles,
2127 CORBA::Boolean theHasRefPoint,
2128 const SMESH::PointStruct & theRefPoint)
2130 if ( !myPreviewMode ) {
2131 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
2132 << theIDsOfElements << ", "
2133 << thePathMesh << ", "
2134 << thePathShape << ", "
2135 << theNodeStart << ", "
2136 << theHasAngles << ", "
2137 << theAngles << ", "
2138 << theHasRefPoint << ", "
2139 << "SMESH.PointStruct( "
2140 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2141 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2142 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2144 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2145 extrusionAlongPath( theIDsOfElements,
2158 //=======================================================================
2159 //function : ExtrusionAlongPathObject
2161 //=======================================================================
2163 SMESH::SMESH_MeshEditor::Extrusion_Error
2164 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
2165 SMESH::SMESH_Mesh_ptr thePathMesh,
2166 GEOM::GEOM_Object_ptr thePathShape,
2167 CORBA::Long theNodeStart,
2168 CORBA::Boolean theHasAngles,
2169 const SMESH::double_array & theAngles,
2170 CORBA::Boolean theHasRefPoint,
2171 const SMESH::PointStruct & theRefPoint)
2173 if ( !myPreviewMode ) {
2174 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
2175 << theObject << ", "
2176 << thePathMesh << ", "
2177 << thePathShape << ", "
2178 << theNodeStart << ", "
2179 << theHasAngles << ", "
2180 << theAngles << ", "
2181 << theHasRefPoint << ", "
2182 << "SMESH.PointStruct( "
2183 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2184 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2185 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2187 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2188 SMESH::long_array_var anElementsId = theObject->GetIDs();
2189 extrusionAlongPath( anElementsId,
2202 //=======================================================================
2203 //function : ExtrusionAlongPathObject1D
2205 //=======================================================================
2207 SMESH::SMESH_MeshEditor::Extrusion_Error
2208 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
2209 SMESH::SMESH_Mesh_ptr thePathMesh,
2210 GEOM::GEOM_Object_ptr thePathShape,
2211 CORBA::Long theNodeStart,
2212 CORBA::Boolean theHasAngles,
2213 const SMESH::double_array & theAngles,
2214 CORBA::Boolean theHasRefPoint,
2215 const SMESH::PointStruct & theRefPoint)
2217 if ( !myPreviewMode ) {
2218 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
2219 << theObject << ", "
2220 << thePathMesh << ", "
2221 << thePathShape << ", "
2222 << theNodeStart << ", "
2223 << theHasAngles << ", "
2224 << theAngles << ", "
2225 << theHasRefPoint << ", "
2226 << "SMESH.PointStruct( "
2227 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2228 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2229 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2231 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2232 SMESH::long_array_var anElementsId = theObject->GetIDs();
2233 extrusionAlongPath( anElementsId,
2247 //=======================================================================
2248 //function : ExtrusionAlongPathObject2D
2250 //=======================================================================
2252 SMESH::SMESH_MeshEditor::Extrusion_Error
2253 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
2254 SMESH::SMESH_Mesh_ptr thePathMesh,
2255 GEOM::GEOM_Object_ptr thePathShape,
2256 CORBA::Long theNodeStart,
2257 CORBA::Boolean theHasAngles,
2258 const SMESH::double_array & theAngles,
2259 CORBA::Boolean theHasRefPoint,
2260 const SMESH::PointStruct & theRefPoint)
2262 if ( !myPreviewMode ) {
2263 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
2264 << theObject << ", "
2265 << thePathMesh << ", "
2266 << thePathShape << ", "
2267 << theNodeStart << ", "
2268 << theHasAngles << ", "
2269 << theAngles << ", "
2270 << theHasRefPoint << ", "
2271 << "SMESH.PointStruct( "
2272 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2273 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2274 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2276 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2277 SMESH::long_array_var anElementsId = theObject->GetIDs();
2278 extrusionAlongPath( anElementsId,
2293 //=======================================================================
2294 //function : ExtrusionAlongPathMakeGroups
2296 //=======================================================================
2298 SMESH::ListOfGroups*
2299 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2300 SMESH::SMESH_Mesh_ptr thePathMesh,
2301 GEOM::GEOM_Object_ptr thePathShape,
2302 CORBA::Long theNodeStart,
2303 CORBA::Boolean theHasAngles,
2304 const SMESH::double_array& theAngles,
2305 CORBA::Boolean theHasRefPoint,
2306 const SMESH::PointStruct& theRefPoint,
2307 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2309 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2319 if ( !myPreviewMode ) {
2320 bool isDumpGroups = aGroups && aGroups->length() > 0;
2321 TPythonDump aPythonDump;
2323 aPythonDump << "("<<aGroups;
2326 aPythonDump << ", error)";
2328 aPythonDump <<"error";
2330 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2331 << theIDsOfElements << ", "
2332 << thePathMesh << ", "
2333 << thePathShape << ", "
2334 << theNodeStart << ", "
2335 << theHasAngles << ", "
2336 << theAngles << ", "
2337 << theHasRefPoint << ", "
2338 << "SMESH.PointStruct( "
2339 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2340 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2341 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2346 //=======================================================================
2347 //function : ExtrusionAlongPathObjectMakeGroups
2349 //=======================================================================
2351 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2352 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2353 SMESH::SMESH_Mesh_ptr thePathMesh,
2354 GEOM::GEOM_Object_ptr thePathShape,
2355 CORBA::Long theNodeStart,
2356 CORBA::Boolean theHasAngles,
2357 const SMESH::double_array& theAngles,
2358 CORBA::Boolean theHasRefPoint,
2359 const SMESH::PointStruct& theRefPoint,
2360 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2362 SMESH::long_array_var anElementsId = theObject->GetIDs();
2363 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2374 if ( !myPreviewMode ) {
2375 bool isDumpGroups = aGroups && aGroups->length() > 0;
2376 TPythonDump aPythonDump;
2378 aPythonDump << "("<<aGroups;
2381 aPythonDump << ", error)";
2383 aPythonDump <<"error";
2385 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2386 << theObject << ", "
2387 << thePathMesh << ", "
2388 << thePathShape << ", "
2389 << theNodeStart << ", "
2390 << theHasAngles << ", "
2391 << theAngles << ", "
2392 << theHasRefPoint << ", "
2393 << "SMESH.PointStruct( "
2394 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2395 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2396 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2401 //=======================================================================
2402 //function : ExtrusionAlongPathObject1DMakeGroups
2404 //=======================================================================
2406 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2407 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2408 SMESH::SMESH_Mesh_ptr thePathMesh,
2409 GEOM::GEOM_Object_ptr thePathShape,
2410 CORBA::Long theNodeStart,
2411 CORBA::Boolean theHasAngles,
2412 const SMESH::double_array& theAngles,
2413 CORBA::Boolean theHasRefPoint,
2414 const SMESH::PointStruct& theRefPoint,
2415 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2417 SMESH::long_array_var anElementsId = theObject->GetIDs();
2418 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2430 if ( !myPreviewMode ) {
2431 bool isDumpGroups = aGroups && aGroups->length() > 0;
2432 TPythonDump aPythonDump;
2434 aPythonDump << "("<<aGroups;
2437 aPythonDump << ", error)";
2439 aPythonDump <<"error";
2441 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
2442 << theObject << ", "
2443 << thePathMesh << ", "
2444 << thePathShape << ", "
2445 << theNodeStart << ", "
2446 << theHasAngles << ", "
2447 << theAngles << ", "
2448 << theHasRefPoint << ", "
2449 << "SMESH.PointStruct( "
2450 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2451 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2452 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2457 //=======================================================================
2458 //function : ExtrusionAlongPathObject2DMakeGroups
2460 //=======================================================================
2462 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2463 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2464 SMESH::SMESH_Mesh_ptr thePathMesh,
2465 GEOM::GEOM_Object_ptr thePathShape,
2466 CORBA::Long theNodeStart,
2467 CORBA::Boolean theHasAngles,
2468 const SMESH::double_array& theAngles,
2469 CORBA::Boolean theHasRefPoint,
2470 const SMESH::PointStruct& theRefPoint,
2471 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2473 SMESH::long_array_var anElementsId = theObject->GetIDs();
2474 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2486 if ( !myPreviewMode ) {
2487 bool isDumpGroups = aGroups && aGroups->length() > 0;
2488 TPythonDump aPythonDump;
2490 aPythonDump << "("<<aGroups;
2493 aPythonDump << ", error)";
2495 aPythonDump <<"error";
2497 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
2498 << theObject << ", "
2499 << thePathMesh << ", "
2500 << thePathShape << ", "
2501 << theNodeStart << ", "
2502 << theHasAngles << ", "
2503 << theAngles << ", "
2504 << theHasRefPoint << ", "
2505 << "SMESH.PointStruct( "
2506 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2507 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2508 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2514 //=======================================================================
2515 //function : ExtrusionAlongPathObjX
2517 //=======================================================================
2518 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2519 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
2520 SMESH::SMESH_IDSource_ptr Path,
2521 CORBA::Long NodeStart,
2522 CORBA::Boolean HasAngles,
2523 const SMESH::double_array& Angles,
2524 CORBA::Boolean LinearVariation,
2525 CORBA::Boolean HasRefPoint,
2526 const SMESH::PointStruct& RefPoint,
2527 CORBA::Boolean MakeGroups,
2528 SMESH::ElementType ElemType,
2529 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2531 SMESH::long_array_var anElementsId = Object->GetIDs();
2532 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2541 (SMDSAbs_ElementType)ElemType,
2544 if ( !myPreviewMode ) {
2545 bool isDumpGroups = aGroups && aGroups->length() > 0;
2546 TPythonDump aPythonDump;
2548 aPythonDump << "("<<aGroups;
2551 aPythonDump << ", error)";
2553 aPythonDump <<"error";
2555 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2558 << NodeStart << ", "
2559 << HasAngles << ", "
2561 << LinearVariation << ", "
2562 << HasRefPoint << ", "
2563 << "SMESH.PointStruct( "
2564 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2565 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2566 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2567 << ElemType << " )";
2573 //=======================================================================
2574 //function : ExtrusionAlongPathX
2576 //=======================================================================
2577 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2578 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2579 SMESH::SMESH_IDSource_ptr Path,
2580 CORBA::Long NodeStart,
2581 CORBA::Boolean HasAngles,
2582 const SMESH::double_array& Angles,
2583 CORBA::Boolean LinearVariation,
2584 CORBA::Boolean HasRefPoint,
2585 const SMESH::PointStruct& RefPoint,
2586 CORBA::Boolean MakeGroups,
2587 SMESH::ElementType ElemType,
2588 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2590 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2599 (SMDSAbs_ElementType)ElemType,
2602 if ( !myPreviewMode ) {
2603 bool isDumpGroups = aGroups && aGroups->length() > 0;
2604 TPythonDump aPythonDump;
2606 aPythonDump << "("<<aGroups;
2609 aPythonDump << ", error)";
2611 aPythonDump <<"error";
2613 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2614 << IDsOfElements << ", "
2616 << NodeStart << ", "
2617 << HasAngles << ", "
2619 << LinearVariation << ", "
2620 << HasRefPoint << ", "
2621 << "SMESH.PointStruct( "
2622 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2623 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2624 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2625 << ElemType << " )";
2631 //================================================================================
2633 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2634 * of given angles along path steps
2635 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2636 * which proceeds the extrusion
2637 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2638 * is used to define the sub-mesh for the path
2640 //================================================================================
2642 SMESH::double_array*
2643 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2644 GEOM::GEOM_Object_ptr thePathShape,
2645 const SMESH::double_array & theAngles)
2647 SMESH::double_array_var aResult = new SMESH::double_array();
2648 int nbAngles = theAngles.length();
2649 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2651 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2652 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2653 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2654 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2655 return aResult._retn();
2656 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2657 if ( nbSteps == nbAngles )
2659 aResult.inout() = theAngles;
2663 aResult->length( nbSteps );
2664 double rAn2St = double( nbAngles ) / double( nbSteps );
2665 double angPrev = 0, angle;
2666 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2668 double angCur = rAn2St * ( iSt+1 );
2669 double angCurFloor = floor( angCur );
2670 double angPrevFloor = floor( angPrev );
2671 if ( angPrevFloor == angCurFloor )
2672 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2675 int iP = int( angPrevFloor );
2676 double angPrevCeil = ceil(angPrev);
2677 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2679 int iC = int( angCurFloor );
2680 if ( iC < nbAngles )
2681 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2683 iP = int( angPrevCeil );
2685 angle += theAngles[ iC ];
2687 aResult[ iSt ] = angle;
2692 // Update Python script
2693 TPythonDump() << "rotAngles = " << theAngles;
2694 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2695 << thePathMesh << ", "
2696 << thePathShape << ", "
2699 return aResult._retn();
2703 //=======================================================================
2706 //=======================================================================
2708 SMESH::ListOfGroups*
2709 SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
2710 const SMESH::AxisStruct & theAxis,
2711 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2712 CORBA::Boolean theCopy,
2713 const bool theMakeGroups,
2714 ::SMESH_Mesh* theTargetMesh)
2718 TIDSortedElemSet elements;
2719 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2721 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2722 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2725 switch ( theMirrorType ) {
2726 case SMESH::SMESH_MeshEditor::POINT:
2727 aTrsf.SetMirror( P );
2729 case SMESH::SMESH_MeshEditor::AXIS:
2730 aTrsf.SetMirror( gp_Ax1( P, V ));
2733 aTrsf.SetMirror( gp_Ax2( P, V ));
2736 ::SMESH_MeshEditor anEditor( myMesh );
2737 ::SMESH_MeshEditor::PGroupIDs groupIds =
2738 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2741 storeResult(anEditor);
2743 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2746 //=======================================================================
2749 //=======================================================================
2751 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2752 const SMESH::AxisStruct & theAxis,
2753 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2754 CORBA::Boolean theCopy)
2756 if ( !myPreviewMode ) {
2757 TPythonDump() << this << ".Mirror( "
2758 << theIDsOfElements << ", "
2760 << mirrorTypeName(theMirrorType) << ", "
2763 mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2767 //=======================================================================
2768 //function : MirrorObject
2770 //=======================================================================
2772 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2773 const SMESH::AxisStruct & theAxis,
2774 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2775 CORBA::Boolean theCopy)
2777 if ( !myPreviewMode ) {
2778 TPythonDump() << this << ".MirrorObject( "
2779 << theObject << ", "
2781 << mirrorTypeName(theMirrorType) << ", "
2784 SMESH::long_array_var anElementsId = theObject->GetIDs();
2785 mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2788 //=======================================================================
2789 //function : MirrorMakeGroups
2791 //=======================================================================
2793 SMESH::ListOfGroups*
2794 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2795 const SMESH::AxisStruct& theMirror,
2796 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2798 SMESH::ListOfGroups * aGroups = mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2799 if ( !myPreviewMode ) {
2800 TPythonDump aPythonDump;
2801 DumpGroupsList(aPythonDump,aGroups);
2802 aPythonDump << this << ".MirrorMakeGroups( "
2803 << theIDsOfElements << ", "
2804 << theMirror << ", "
2805 << mirrorTypeName(theMirrorType) << " )";
2810 //=======================================================================
2811 //function : MirrorObjectMakeGroups
2813 //=======================================================================
2815 SMESH::ListOfGroups*
2816 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2817 const SMESH::AxisStruct& theMirror,
2818 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2820 SMESH::long_array_var anElementsId = theObject->GetIDs();
2821 SMESH::ListOfGroups * aGroups = mirror(anElementsId, theMirror, theMirrorType, true, true);
2822 if ( !myPreviewMode ) {
2823 TPythonDump aPythonDump;
2824 DumpGroupsList(aPythonDump,aGroups);
2825 aPythonDump << this << ".MirrorObjectMakeGroups( "
2826 << theObject << ", "
2827 << theMirror << ", "
2828 << mirrorTypeName(theMirrorType) << " )";
2833 //=======================================================================
2834 //function : MirrorMakeMesh
2836 //=======================================================================
2838 SMESH::SMESH_Mesh_ptr
2839 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2840 const SMESH::AxisStruct& theMirror,
2841 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2842 CORBA::Boolean theCopyGroups,
2843 const char* theMeshName)
2845 SMESH_Mesh_i* mesh_i;
2846 SMESH::SMESH_Mesh_var mesh;
2847 { // open new scope to dump "MakeMesh" command
2848 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2850 TPythonDump pydump; // to prevent dump at mesh creation
2852 mesh = makeMesh( theMeshName );
2853 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2855 mirror(theIDsOfElements, theMirror, theMirrorType,
2856 false, theCopyGroups, & mesh_i->GetImpl());
2857 mesh_i->CreateGroupServants();
2860 if ( !myPreviewMode ) {
2861 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2862 << theIDsOfElements << ", "
2863 << theMirror << ", "
2864 << mirrorTypeName(theMirrorType) << ", "
2865 << theCopyGroups << ", '"
2866 << theMeshName << "' )";
2871 if(!myPreviewMode && mesh_i)
2872 mesh_i->GetGroups();
2874 return mesh._retn();
2877 //=======================================================================
2878 //function : MirrorObjectMakeMesh
2880 //=======================================================================
2882 SMESH::SMESH_Mesh_ptr
2883 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2884 const SMESH::AxisStruct& theMirror,
2885 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2886 CORBA::Boolean theCopyGroups,
2887 const char* theMeshName)
2889 SMESH_Mesh_i* mesh_i;
2890 SMESH::SMESH_Mesh_var mesh;
2891 { // open new scope to dump "MakeMesh" command
2892 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2894 TPythonDump pydump; // to prevent dump at mesh creation
2896 mesh = makeMesh( theMeshName );
2897 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2899 SMESH::long_array_var anElementsId = theObject->GetIDs();
2900 mirror(anElementsId, theMirror, theMirrorType,
2901 false, theCopyGroups, & mesh_i->GetImpl());
2902 mesh_i->CreateGroupServants();
2905 if ( !myPreviewMode ) {
2906 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
2907 << theObject << ", "
2908 << theMirror << ", "
2909 << mirrorTypeName(theMirrorType) << ", "
2910 << theCopyGroups << ", '"
2911 << theMeshName << "' )";
2916 if(!myPreviewMode && mesh_i)
2917 mesh_i->GetGroups();
2919 return mesh._retn();
2922 //=======================================================================
2923 //function : translate
2925 //=======================================================================
2927 SMESH::ListOfGroups*
2928 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2929 const SMESH::DirStruct & theVector,
2930 CORBA::Boolean theCopy,
2931 const bool theMakeGroups,
2932 ::SMESH_Mesh* theTargetMesh)
2936 TIDSortedElemSet elements;
2937 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2940 const SMESH::PointStruct * P = &theVector.PS;
2941 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2943 ::SMESH_MeshEditor anEditor( myMesh );
2944 ::SMESH_MeshEditor::PGroupIDs groupIds =
2945 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2948 storeResult(anEditor);
2950 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2953 //=======================================================================
2954 //function : Translate
2956 //=======================================================================
2958 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2959 const SMESH::DirStruct & theVector,
2960 CORBA::Boolean theCopy)
2962 if ( !myPreviewMode ) {
2963 TPythonDump() << this << ".Translate( "
2964 << theIDsOfElements << ", "
2965 << theVector << ", "
2968 translate(theIDsOfElements,
2974 //=======================================================================
2975 //function : TranslateObject
2977 //=======================================================================
2979 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
2980 const SMESH::DirStruct & theVector,
2981 CORBA::Boolean theCopy)
2983 if ( !myPreviewMode ) {
2984 TPythonDump() << this << ".TranslateObject( "
2985 << theObject << ", "
2986 << theVector << ", "
2989 SMESH::long_array_var anElementsId = theObject->GetIDs();
2990 translate(anElementsId,
2996 //=======================================================================
2997 //function : TranslateMakeGroups
2999 //=======================================================================
3001 SMESH::ListOfGroups*
3002 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
3003 const SMESH::DirStruct& theVector)
3005 SMESH::ListOfGroups * aGroups = translate(theIDsOfElements,theVector,true,true);
3006 if ( !myPreviewMode ) {
3007 TPythonDump aPythonDump;
3008 DumpGroupsList(aPythonDump,aGroups);
3009 aPythonDump << this << ".TranslateMakeGroups( "
3010 << theIDsOfElements << ", "
3011 << theVector << " )";
3016 //=======================================================================
3017 //function : TranslateObjectMakeGroups
3019 //=======================================================================
3021 SMESH::ListOfGroups*
3022 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3023 const SMESH::DirStruct& theVector)
3025 SMESH::long_array_var anElementsId = theObject->GetIDs();
3026 SMESH::ListOfGroups * aGroups = translate(anElementsId, theVector, true, true);
3028 if ( !myPreviewMode ) {
3030 TPythonDump aPythonDump;
3031 DumpGroupsList(aPythonDump,aGroups);
3032 aPythonDump << this << ".TranslateObjectMakeGroups( "
3033 << theObject << ", "
3034 << theVector << " )";
3039 //=======================================================================
3040 //function : TranslateMakeMesh
3042 //=======================================================================
3044 SMESH::SMESH_Mesh_ptr
3045 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3046 const SMESH::DirStruct& theVector,
3047 CORBA::Boolean theCopyGroups,
3048 const char* theMeshName)
3050 SMESH_Mesh_i* mesh_i;
3051 SMESH::SMESH_Mesh_var mesh;
3053 { // open new scope to dump "MakeMesh" command
3054 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3056 TPythonDump pydump; // to prevent dump at mesh creation
3058 mesh = makeMesh( theMeshName );
3059 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3062 translate(theIDsOfElements, theVector,
3063 false, theCopyGroups, & mesh_i->GetImpl());
3064 mesh_i->CreateGroupServants();
3067 if ( !myPreviewMode ) {
3068 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3069 << theIDsOfElements << ", "
3070 << theVector << ", "
3071 << theCopyGroups << ", '"
3072 << theMeshName << "' )";
3077 if(!myPreviewMode && mesh_i)
3078 mesh_i->GetGroups();
3080 return mesh._retn();
3083 //=======================================================================
3084 //function : TranslateObjectMakeMesh
3086 //=======================================================================
3088 SMESH::SMESH_Mesh_ptr
3089 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3090 const SMESH::DirStruct& theVector,
3091 CORBA::Boolean theCopyGroups,
3092 const char* theMeshName)
3094 SMESH_Mesh_i* mesh_i;
3095 SMESH::SMESH_Mesh_var mesh;
3096 { // open new scope to dump "MakeMesh" command
3097 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3099 TPythonDump pydump; // to prevent dump at mesh creation
3100 mesh = makeMesh( theMeshName );
3101 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3104 SMESH::long_array_var anElementsId = theObject->GetIDs();
3105 translate(anElementsId, theVector,
3106 false, theCopyGroups, & mesh_i->GetImpl());
3107 mesh_i->CreateGroupServants();
3109 if ( !myPreviewMode ) {
3110 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3111 << theObject << ", "
3112 << theVector << ", "
3113 << theCopyGroups << ", '"
3114 << theMeshName << "' )";
3119 if(!myPreviewMode && mesh_i)
3120 mesh_i->GetGroups();
3122 return mesh._retn();
3125 //=======================================================================
3128 //=======================================================================
3130 SMESH::ListOfGroups*
3131 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
3132 const SMESH::AxisStruct & theAxis,
3133 CORBA::Double theAngle,
3134 CORBA::Boolean theCopy,
3135 const bool theMakeGroups,
3136 ::SMESH_Mesh* theTargetMesh)
3140 TIDSortedElemSet elements;
3141 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3143 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3144 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3147 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3149 ::SMESH_MeshEditor anEditor( myMesh );
3150 ::SMESH_MeshEditor::PGroupIDs groupIds =
3151 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3154 storeResult(anEditor);
3156 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3159 //=======================================================================
3162 //=======================================================================
3164 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3165 const SMESH::AxisStruct & theAxis,
3166 CORBA::Double theAngle,
3167 CORBA::Boolean theCopy)
3169 if ( !myPreviewMode ) {
3170 TPythonDump() << this << ".Rotate( "
3171 << theIDsOfElements << ", "
3176 rotate(theIDsOfElements,
3183 //=======================================================================
3184 //function : RotateObject
3186 //=======================================================================
3188 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3189 const SMESH::AxisStruct & theAxis,
3190 CORBA::Double theAngle,
3191 CORBA::Boolean theCopy)
3193 if ( !myPreviewMode ) {
3194 TPythonDump() << this << ".RotateObject( "
3195 << theObject << ", "
3200 SMESH::long_array_var anElementsId = theObject->GetIDs();
3201 rotate(anElementsId,
3208 //=======================================================================
3209 //function : RotateMakeGroups
3211 //=======================================================================
3213 SMESH::ListOfGroups*
3214 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3215 const SMESH::AxisStruct& theAxis,
3216 CORBA::Double theAngle)
3218 SMESH::ListOfGroups * aGroups = rotate(theIDsOfElements,theAxis,theAngle,true,true);
3219 if ( !myPreviewMode ) {
3220 TPythonDump aPythonDump;
3221 DumpGroupsList(aPythonDump,aGroups);
3222 aPythonDump << this << ".RotateMakeGroups( "
3223 << theIDsOfElements << ", "
3225 << theAngle << " )";
3230 //=======================================================================
3231 //function : RotateObjectMakeGroups
3233 //=======================================================================
3235 SMESH::ListOfGroups*
3236 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3237 const SMESH::AxisStruct& theAxis,
3238 CORBA::Double theAngle)
3240 SMESH::long_array_var anElementsId = theObject->GetIDs();
3241 SMESH::ListOfGroups * aGroups = rotate(anElementsId,theAxis,theAngle,true,true);
3243 if ( !myPreviewMode ) {
3244 TPythonDump aPythonDump;
3245 DumpGroupsList(aPythonDump,aGroups);
3246 aPythonDump << this << ".RotateObjectMakeGroups( "
3247 << theObject << ", "
3249 << theAngle << " )";
3254 //=======================================================================
3255 //function : RotateMakeMesh
3257 //=======================================================================
3259 SMESH::SMESH_Mesh_ptr
3260 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3261 const SMESH::AxisStruct& theAxis,
3262 CORBA::Double theAngleInRadians,
3263 CORBA::Boolean theCopyGroups,
3264 const char* theMeshName)
3266 SMESH::SMESH_Mesh_var mesh;
3267 SMESH_Mesh_i* mesh_i;
3269 { // open new scope to dump "MakeMesh" command
3270 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3272 TPythonDump pydump; // to prevent dump at mesh creation
3274 mesh = makeMesh( theMeshName );
3275 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3278 rotate(theIDsOfElements, theAxis, theAngleInRadians,
3279 false, theCopyGroups, & mesh_i->GetImpl());
3280 mesh_i->CreateGroupServants();
3282 if ( !myPreviewMode ) {
3283 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3284 << theIDsOfElements << ", "
3286 << theAngleInRadians << ", "
3287 << theCopyGroups << ", '"
3288 << theMeshName << "' )";
3293 if(!myPreviewMode && mesh_i)
3294 mesh_i->GetGroups();
3296 return mesh._retn();
3299 //=======================================================================
3300 //function : RotateObjectMakeMesh
3302 //=======================================================================
3304 SMESH::SMESH_Mesh_ptr
3305 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3306 const SMESH::AxisStruct& theAxis,
3307 CORBA::Double theAngleInRadians,
3308 CORBA::Boolean theCopyGroups,
3309 const char* theMeshName)
3311 SMESH::SMESH_Mesh_var mesh;
3312 SMESH_Mesh_i* mesh_i;
3314 {// open new scope to dump "MakeMesh" command
3315 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3317 TPythonDump pydump; // to prevent dump at mesh creation
3318 mesh = makeMesh( theMeshName );
3319 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3322 SMESH::long_array_var anElementsId = theObject->GetIDs();
3323 rotate(anElementsId, theAxis, theAngleInRadians,
3324 false, theCopyGroups, & mesh_i->GetImpl());
3325 mesh_i->CreateGroupServants();
3327 if ( !myPreviewMode ) {
3328 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3329 << theObject << ", "
3331 << theAngleInRadians << ", "
3332 << theCopyGroups << ", '"
3333 << theMeshName << "' )";
3338 if(!myPreviewMode && mesh_i)
3339 mesh_i->GetGroups();
3341 return mesh._retn();
3344 //=======================================================================
3345 //function : FindCoincidentNodes
3347 //=======================================================================
3349 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3350 SMESH::array_of_long_array_out GroupsOfNodes)
3354 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3355 ::SMESH_MeshEditor anEditor( myMesh );
3356 set<const SMDS_MeshNode*> nodes; // no input nodes
3357 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3359 GroupsOfNodes = new SMESH::array_of_long_array;
3360 GroupsOfNodes->length( aListOfListOfNodes.size() );
3361 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3362 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3363 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3364 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3365 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3366 aGroup.length( aListOfNodes.size() );
3367 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3368 aGroup[ j ] = (*lIt)->GetID();
3370 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3371 << Tolerance << " )";
3374 //=======================================================================
3375 //function : FindCoincidentNodesOnPart
3377 //=======================================================================
3378 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3379 CORBA::Double Tolerance,
3380 SMESH::array_of_long_array_out GroupsOfNodes)
3383 SMESH::long_array_var aElementsId = theObject->GetIDs();
3385 SMESHDS_Mesh* aMesh = GetMeshDS();
3386 set<const SMDS_MeshNode*> nodes;
3388 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
3389 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
3390 for(int i = 0; i < aElementsId->length(); i++) {
3391 CORBA::Long ind = aElementsId[i];
3392 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
3398 for(int i = 0; i < aElementsId->length(); i++) {
3399 CORBA::Long ind = aElementsId[i];
3400 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
3402 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
3403 while ( nIt->more() )
3404 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
3410 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3411 ::SMESH_MeshEditor anEditor( myMesh );
3413 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3415 GroupsOfNodes = new SMESH::array_of_long_array;
3416 GroupsOfNodes->length( aListOfListOfNodes.size() );
3417 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3418 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3419 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3420 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3421 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3422 aGroup.length( aListOfNodes.size() );
3423 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3424 aGroup[ j ] = (*lIt)->GetID();
3426 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3428 << Tolerance << " )";
3431 //=======================================================================
3432 //function : MergeNodes
3434 //=======================================================================
3436 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3440 SMESHDS_Mesh* aMesh = GetMeshDS();
3442 TPythonDump aTPythonDump;
3443 aTPythonDump << this << ".MergeNodes([";
3444 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3445 for (int i = 0; i < GroupsOfNodes.length(); i++)
3447 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3448 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3449 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3450 for ( int j = 0; j < aNodeGroup.length(); j++ )
3452 CORBA::Long index = aNodeGroup[ j ];
3453 const SMDS_MeshNode * node = aMesh->FindNode(index);
3455 aListOfNodes.push_back( node );
3457 if ( aListOfNodes.size() < 2 )
3458 aListOfListOfNodes.pop_back();
3460 if ( i > 0 ) aTPythonDump << ", ";
3461 aTPythonDump << aNodeGroup;
3463 ::SMESH_MeshEditor anEditor( myMesh );
3464 anEditor.MergeNodes( aListOfListOfNodes );
3466 aTPythonDump << "])";
3469 //=======================================================================
3470 //function : FindEqualElements
3472 //=======================================================================
3473 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3474 SMESH::array_of_long_array_out GroupsOfElementsID)
3477 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
3478 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
3479 typedef list<int> TListOfIDs;
3480 set<const SMDS_MeshElement*> elems;
3481 SMESH::long_array_var aElementsId = theObject->GetIDs();
3482 SMESHDS_Mesh* aMesh = GetMeshDS();
3484 for(int i = 0; i < aElementsId->length(); i++) {
3485 CORBA::Long anID = aElementsId[i];
3486 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3492 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3493 ::SMESH_MeshEditor anEditor( myMesh );
3494 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3496 GroupsOfElementsID = new SMESH::array_of_long_array;
3497 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3499 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3500 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3501 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3502 TListOfIDs& listOfIDs = *arraysIt;
3503 aGroup.length( listOfIDs.size() );
3504 TListOfIDs::iterator idIt = listOfIDs.begin();
3505 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3506 aGroup[ k ] = *idIt;
3510 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3515 //=======================================================================
3516 //function : MergeElements
3518 //=======================================================================
3520 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3524 TPythonDump aTPythonDump;
3525 aTPythonDump << this << ".MergeElements( [";
3527 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3529 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3530 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3531 aListOfListOfElementsID.push_back( list< int >() );
3532 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3533 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3534 CORBA::Long id = anElemsIDGroup[ j ];
3535 aListOfElemsID.push_back( id );
3537 if ( aListOfElemsID.size() < 2 )
3538 aListOfListOfElementsID.pop_back();
3539 if ( i > 0 ) aTPythonDump << ", ";
3540 aTPythonDump << anElemsIDGroup;
3543 ::SMESH_MeshEditor anEditor( myMesh );
3544 anEditor.MergeElements(aListOfListOfElementsID);
3546 aTPythonDump << "] )";
3549 //=======================================================================
3550 //function : MergeEqualElements
3552 //=======================================================================
3554 void SMESH_MeshEditor_i::MergeEqualElements()
3558 ::SMESH_MeshEditor anEditor( myMesh );
3559 anEditor.MergeEqualElements();
3561 TPythonDump() << this << ".MergeEqualElements()";
3564 //================================================================================
3566 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
3567 * move the node closest to the point to point's location and return ID of the node
3569 //================================================================================
3571 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
3574 CORBA::Long theNodeID)
3576 // We keep myNodeSearcher until any mesh modification:
3577 // 1) initData() deletes myNodeSearcher at any edition,
3578 // 2) TNodeSearcherDeleter - at any mesh compute event and mesh change
3582 int nodeID = theNodeID;
3583 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
3586 static TNodeSearcherDeleter deleter;
3587 deleter.Set( myMesh );
3588 if ( !myNodeSearcher ) {
3589 ::SMESH_MeshEditor anEditor( myMesh );
3590 myNodeSearcher = anEditor.GetNodeSearcher();
3593 node = myNodeSearcher->FindClosestTo( p );
3596 nodeID = node->GetID();
3597 if ( myPreviewMode ) // make preview data
3599 // in a preview mesh, make edges linked to a node
3600 TPreviewMesh tmpMesh;
3601 TIDSortedElemSet linkedNodes;
3602 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3603 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3604 for ( ; nIt != linkedNodes.end(); ++nIt )
3606 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
3607 tmpMesh.Copy( &edge );
3610 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
3612 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
3613 // fill preview data
3614 ::SMESH_MeshEditor anEditor( & tmpMesh );
3615 storeResult( anEditor );
3619 GetMeshDS()->MoveNode(node, x, y, z);
3623 if ( !myPreviewMode ) {
3624 TPythonDump() << "nodeID = " << this
3625 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
3626 << ", " << nodeID << " )";
3632 //=======================================================================
3633 //function : convError
3635 //=======================================================================
3637 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
3639 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
3643 RETCASE( SEW_BORDER1_NOT_FOUND );
3644 RETCASE( SEW_BORDER2_NOT_FOUND );
3645 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
3646 RETCASE( SEW_BAD_SIDE_NODES );
3647 RETCASE( SEW_VOLUMES_TO_SPLIT );
3648 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
3649 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
3650 RETCASE( SEW_BAD_SIDE1_NODES );
3651 RETCASE( SEW_BAD_SIDE2_NODES );
3653 return SMESH::SMESH_MeshEditor::SEW_OK;
3656 //=======================================================================
3657 //function : SewFreeBorders
3659 //=======================================================================
3661 SMESH::SMESH_MeshEditor::Sew_Error
3662 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
3663 CORBA::Long SecondNodeID1,
3664 CORBA::Long LastNodeID1,
3665 CORBA::Long FirstNodeID2,
3666 CORBA::Long SecondNodeID2,
3667 CORBA::Long LastNodeID2,
3668 CORBA::Boolean CreatePolygons,
3669 CORBA::Boolean CreatePolyedrs)
3673 SMESHDS_Mesh* aMesh = GetMeshDS();
3675 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3676 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3677 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3678 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3679 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3680 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
3682 if (!aBorderFirstNode ||
3683 !aBorderSecondNode||
3685 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3686 if (!aSide2FirstNode ||
3687 !aSide2SecondNode ||
3689 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3691 TPythonDump() << "error = " << this << ".SewFreeBorders( "
3692 << FirstNodeID1 << ", "
3693 << SecondNodeID1 << ", "
3694 << LastNodeID1 << ", "
3695 << FirstNodeID2 << ", "
3696 << SecondNodeID2 << ", "
3697 << LastNodeID2 << ", "
3698 << CreatePolygons<< ", "
3699 << CreatePolyedrs<< " )";
3701 ::SMESH_MeshEditor anEditor( myMesh );
3702 SMESH::SMESH_MeshEditor::Sew_Error error =
3703 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3713 storeResult(anEditor);
3719 //=======================================================================
3720 //function : SewConformFreeBorders
3722 //=======================================================================
3724 SMESH::SMESH_MeshEditor::Sew_Error
3725 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3726 CORBA::Long SecondNodeID1,
3727 CORBA::Long LastNodeID1,
3728 CORBA::Long FirstNodeID2,
3729 CORBA::Long SecondNodeID2)
3733 SMESHDS_Mesh* aMesh = GetMeshDS();
3735 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3736 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3737 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3738 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3739 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3740 const SMDS_MeshNode* aSide2ThirdNode = 0;
3742 if (!aBorderFirstNode ||
3743 !aBorderSecondNode||
3745 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3746 if (!aSide2FirstNode ||
3748 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3750 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
3751 << FirstNodeID1 << ", "
3752 << SecondNodeID1 << ", "
3753 << LastNodeID1 << ", "
3754 << FirstNodeID2 << ", "
3755 << SecondNodeID2 << " )";
3757 ::SMESH_MeshEditor anEditor( myMesh );
3758 SMESH::SMESH_MeshEditor::Sew_Error error =
3759 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3768 storeResult(anEditor);
3774 //=======================================================================
3775 //function : SewBorderToSide
3777 //=======================================================================
3779 SMESH::SMESH_MeshEditor::Sew_Error
3780 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
3781 CORBA::Long SecondNodeIDOnFreeBorder,
3782 CORBA::Long LastNodeIDOnFreeBorder,
3783 CORBA::Long FirstNodeIDOnSide,
3784 CORBA::Long LastNodeIDOnSide,
3785 CORBA::Boolean CreatePolygons,
3786 CORBA::Boolean CreatePolyedrs)
3790 SMESHDS_Mesh* aMesh = GetMeshDS();
3792 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
3793 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
3794 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
3795 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
3796 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
3797 const SMDS_MeshNode* aSide2ThirdNode = 0;
3799 if (!aBorderFirstNode ||
3800 !aBorderSecondNode||
3802 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3803 if (!aSide2FirstNode ||
3805 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
3807 TPythonDump() << "error = " << this << ".SewBorderToSide( "
3808 << FirstNodeIDOnFreeBorder << ", "
3809 << SecondNodeIDOnFreeBorder << ", "
3810 << LastNodeIDOnFreeBorder << ", "
3811 << FirstNodeIDOnSide << ", "
3812 << LastNodeIDOnSide << ", "
3813 << CreatePolygons << ", "
3814 << CreatePolyedrs << ") ";
3816 ::SMESH_MeshEditor anEditor( myMesh );
3817 SMESH::SMESH_MeshEditor::Sew_Error error =
3818 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3828 storeResult(anEditor);
3834 //=======================================================================
3835 //function : SewSideElements
3837 //=======================================================================
3839 SMESH::SMESH_MeshEditor::Sew_Error
3840 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
3841 const SMESH::long_array& IDsOfSide2Elements,
3842 CORBA::Long NodeID1OfSide1ToMerge,
3843 CORBA::Long NodeID1OfSide2ToMerge,
3844 CORBA::Long NodeID2OfSide1ToMerge,
3845 CORBA::Long NodeID2OfSide2ToMerge)
3849 SMESHDS_Mesh* aMesh = GetMeshDS();
3851 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
3852 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
3853 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
3854 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
3856 if (!aFirstNode1ToMerge ||
3857 !aFirstNode2ToMerge )
3858 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
3859 if (!aSecondNode1ToMerge||
3860 !aSecondNode2ToMerge)
3861 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
3863 TIDSortedElemSet aSide1Elems, aSide2Elems;
3864 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
3865 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
3867 TPythonDump() << "error = " << this << ".SewSideElements( "
3868 << IDsOfSide1Elements << ", "
3869 << IDsOfSide2Elements << ", "
3870 << NodeID1OfSide1ToMerge << ", "
3871 << NodeID1OfSide2ToMerge << ", "
3872 << NodeID2OfSide1ToMerge << ", "
3873 << NodeID2OfSide2ToMerge << ")";
3875 ::SMESH_MeshEditor anEditor( myMesh );
3876 SMESH::SMESH_MeshEditor::Sew_Error error =
3877 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
3880 aSecondNode1ToMerge,
3881 aSecondNode2ToMerge));
3883 storeResult(anEditor);
3888 //================================================================================
3890 * \brief Set new nodes for given element
3891 * \param ide - element id
3892 * \param newIDs - new node ids
3893 * \retval CORBA::Boolean - true if result is OK
3895 //================================================================================
3897 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
3898 const SMESH::long_array& newIDs)
3902 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
3903 if(!elem) return false;
3905 int nbn = newIDs.length();
3907 vector<const SMDS_MeshNode*> aNodes(nbn);
3910 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
3913 aNodes[nbn1] = aNode;
3916 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
3917 << ide << ", " << newIDs << " )";
3919 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
3922 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
3925 //================================================================================
3927 * \brief Update myLastCreated* or myPreviewData
3928 * \param anEditor - it contains last modification results
3930 //================================================================================
3932 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
3934 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
3936 list<int> aNodesConnectivity;
3937 typedef map<int, int> TNodesMap;
3940 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
3941 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
3943 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
3944 int nbEdges = aMeshDS->NbEdges();
3945 int nbFaces = aMeshDS->NbFaces();
3946 int nbVolum = aMeshDS->NbVolumes();
3947 switch ( previewType ) {
3948 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
3949 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
3950 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
3953 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
3954 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
3956 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
3958 while ( itMeshElems->more() ) {
3959 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
3960 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
3963 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
3964 while ( itElemNodes->more() ) {
3965 const SMDS_MeshNode* aMeshNode =
3966 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
3967 int aNodeID = aMeshNode->GetID();
3968 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
3969 if ( anIter == nodesMap.end() ) {
3970 // filling the nodes coordinates
3971 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
3972 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
3973 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
3974 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
3977 aNodesConnectivity.push_back(anIter->second);
3980 // filling the elements types
3981 SMDSAbs_ElementType aType;
3983 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
3984 aType = SMDSAbs_Node;
3988 aType = aMeshElem->GetType();
3989 isPoly = aMeshElem->IsPoly();
3992 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
3993 myPreviewData->elementTypes[i].isPoly = isPoly;
3994 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
3998 myPreviewData->nodesXYZ.length( j );
4000 // filling the elements connectivities
4001 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4002 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4003 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4004 myPreviewData->elementConnectivities[i] = *aConnIter;
4010 // add new nodes into myLastCreatedNodes
4011 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4012 myLastCreatedNodes->length(aSeq.Length());
4013 for(int i=0; i<aSeq.Length(); i++)
4014 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4017 // add new elements into myLastCreatedElems
4018 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4019 myLastCreatedElems->length(aSeq.Length());
4020 for(int i=0; i<aSeq.Length(); i++)
4021 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4025 //================================================================================
4027 * Return data of mesh edition preview
4029 //================================================================================
4031 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4033 return myPreviewData._retn();
4036 //================================================================================
4038 * \brief Returns list of it's IDs of created nodes
4039 * \retval SMESH::long_array* - list of node ID
4041 //================================================================================
4043 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4045 return myLastCreatedNodes._retn();
4048 //================================================================================
4050 * \brief Returns list of it's IDs of created elements
4051 * \retval SMESH::long_array* - list of elements' ID
4053 //================================================================================
4055 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4057 return myLastCreatedElems._retn();
4060 //=======================================================================
4061 //function : ConvertToQuadratic
4063 //=======================================================================
4065 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4067 ::SMESH_MeshEditor anEditor( myMesh );
4068 anEditor.ConvertToQuadratic(theForce3d);
4069 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4072 //=======================================================================
4073 //function : ConvertFromQuadratic
4075 //=======================================================================
4077 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4079 ::SMESH_MeshEditor anEditor( myMesh );
4080 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4081 TPythonDump() << this << ".ConvertFromQuadratic()";
4085 //=======================================================================
4086 //function : makeMesh
4087 //purpose : create a named imported mesh
4088 //=======================================================================
4090 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4092 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4093 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4094 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4095 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4096 gen->SetName( meshSO, theMeshName, "Mesh" );
4097 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4099 return mesh._retn();
4102 //=======================================================================
4103 //function : DumpGroupsList
4105 //=======================================================================
4106 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4107 const SMESH::ListOfGroups * theGroupList)
4109 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4110 if(isDumpGroupList) {
4111 theDumpPython << theGroupList << " = ";
4115 //================================================================================
4117 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4118 \param theNodes - identifiers of nodes to be doubled
4119 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4120 nodes. If list of element identifiers is empty then nodes are doubled but
4121 they not assigned to elements
4122 \return TRUE if operation has been completed successfully, FALSE otherwise
4123 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4125 //================================================================================
4127 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4128 const SMESH::long_array& theModifiedElems )
4132 ::SMESH_MeshEditor aMeshEditor( myMesh );
4133 list< int > aListOfNodes;
4135 for ( i = 0, n = theNodes.length(); i < n; i++ )
4136 aListOfNodes.push_back( theNodes[ i ] );
4138 list< int > aListOfElems;
4139 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4140 aListOfElems.push_back( theModifiedElems[ i ] );
4142 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4144 storeResult( aMeshEditor) ;
4149 //================================================================================
4151 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4152 This method provided for convenience works as DoubleNodes() described above.
4153 \param theNodeId - identifier of node to be doubled.
4154 \param theModifiedElems - identifiers of elements to be updated.
4155 \return TRUE if operation has been completed successfully, FALSE otherwise
4156 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4158 //================================================================================
4160 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4161 const SMESH::long_array& theModifiedElems )
4163 SMESH::long_array_var aNodes = new SMESH::long_array;
4164 aNodes->length( 1 );
4165 aNodes[ 0 ] = theNodeId;
4166 return DoubleNodes( aNodes, theModifiedElems );
4169 //================================================================================
4171 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4172 This method provided for convenience works as DoubleNodes() described above.
4173 \param theNodes - group of nodes to be doubled.
4174 \param theModifiedElems - group of elements to be updated.
4175 \return TRUE if operation has been completed successfully, FALSE otherwise
4176 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
4178 //================================================================================
4180 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(
4181 SMESH::SMESH_GroupBase_ptr theNodes,
4182 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4184 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4187 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4188 SMESH::long_array_var aModifiedElems;
4189 if ( !CORBA::is_nil( theModifiedElems ) )
4190 aModifiedElems = theModifiedElems->GetListOfID();
4193 aModifiedElems = new SMESH::long_array;
4194 aModifiedElems->length( 0 );
4197 return DoubleNodes( aNodes, aModifiedElems );
4200 //================================================================================
4202 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4203 This method provided for convenience works as DoubleNodes() described above.
4204 \param theNodes - list of groups of nodes to be doubled
4205 \param theModifiedElems - list of groups of elements to be updated.
4206 \return TRUE if operation has been completed successfully, FALSE otherwise
4207 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
4209 //================================================================================
4211 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(
4212 const SMESH::ListOfGroups& theNodes,
4213 const SMESH::ListOfGroups& theModifiedElems )
4217 ::SMESH_MeshEditor aMeshEditor( myMesh );
4219 std::list< int > aNodes;
4221 for ( i = 0, n = theNodes.length(); i < n; i++ )
4223 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
4224 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
4226 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4227 for ( j = 0, m = aCurr->length(); j < m; j++ )
4228 aNodes.push_back( aCurr[ j ] );
4232 std::list< int > anElems;
4233 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4235 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
4236 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
4238 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4239 for ( j = 0, m = aCurr->length(); j < m; j++ )
4240 anElems.push_back( aCurr[ j ] );
4244 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
4246 storeResult( aMeshEditor) ;