1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_MeshEditor_i.cxx
24 // Author : Nicolas REJNERI
27 #include "SMESH_MeshEditor_i.hxx"
29 #include "SMDS_Mesh0DElement.hxx"
30 #include "SMDS_MeshEdge.hxx"
31 #include "SMDS_MeshFace.hxx"
32 #include "SMDS_MeshVolume.hxx"
33 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
34 #include "SMESH_MeshEditor.hxx"
35 #include "SMESH_subMeshEventListener.hxx"
36 #include "SMESH_Gen_i.hxx"
37 #include "SMESH_Filter_i.hxx"
38 #include "SMESH_subMesh_i.hxx"
39 #include "SMESH_Group_i.hxx"
40 #include "SMESH_PythonDump.hxx"
42 #include "utilities.h"
43 #include "Utils_ExceptHandlers.hxx"
44 #include "Utils_CorbaException.hxx"
46 #include <BRepAdaptor_Surface.hxx>
47 #include <BRep_Tool.hxx>
48 #include <TopExp_Explorer.hxx>
50 #include <TopoDS_Edge.hxx>
51 #include <TopoDS_Face.hxx>
56 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
60 #include <Standard_Failure.hxx>
63 #include <Standard_ErrorHandler.hxx>
68 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
71 using SMESH::TPythonDump;
75 //=============================================================================
77 * \brief Mesh to apply modifications for preview purposes
79 //=============================================================================
81 struct TPreviewMesh: public SMESH_Mesh
83 SMDSAbs_ElementType myPreviewType; // type to show
85 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
86 _isShapeToMesh = (_id =_studyId =_idDoc = 0);
87 _myMeshDS = new SMESHDS_Mesh( _id, true );
88 myPreviewType = previewElements;
91 virtual ~TPreviewMesh() { delete _myMeshDS; }
92 //!< Copy a set of elements
93 void Copy(const TIDSortedElemSet & theElements,
94 TIDSortedElemSet& theCopyElements,
95 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
96 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
98 // loop on theIDsOfElements
99 TIDSortedElemSet::const_iterator eIt = theElements.begin();
100 for ( ; eIt != theElements.end(); ++eIt )
102 const SMDS_MeshElement* anElem = *eIt;
103 if ( !anElem ) continue;
104 SMDSAbs_ElementType type = anElem->GetType();
105 if ( type == theAvoidType ||
106 ( theSelectType != SMDSAbs_All && type != theSelectType ))
109 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
110 theCopyElements.insert( theCopyElements.end(), anElemCopy );
114 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
116 // copy element nodes
117 int anElemNbNodes = anElem->NbNodes();
118 vector< int > anElemNodesID( anElemNbNodes ) ;
119 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
120 for ( int i = 0; itElemNodes->more(); i++)
122 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
124 anElemNodesID[i] = anElemNode->GetID();
127 // creates a corresponding element on copied nodes
128 SMDS_MeshElement* anElemCopy = 0;
129 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
131 const SMDS_PolyhedralVolumeOfNodes* ph =
132 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
134 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
135 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
138 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
145 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
147 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
148 anElemNode->GetID());
150 };// struct TPreviewMesh
152 static SMESH_NodeSearcher * theNodeSearcher = 0;
153 static SMESH_ElementSearcher * theElementSearcher = 0;
155 //=============================================================================
157 * \brief Deleter of theNodeSearcher at any compute event occured
159 //=============================================================================
161 struct TSearchersDeleter : public SMESH_subMeshEventListener
165 TSearchersDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
167 //!< Delete theNodeSearcher
170 if ( theNodeSearcher ) delete theNodeSearcher; theNodeSearcher = 0;
171 if ( theElementSearcher ) delete theElementSearcher; theElementSearcher = 0;
173 typedef map < int, SMESH_subMesh * > TDependsOnMap;
174 //!< The meshod called by submesh: do my main job
175 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
176 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
178 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
180 Unset( sm->GetFather() );
183 //!< set self on all submeshes and delete theNodeSearcher if other mesh is set
184 void Set(SMESH_Mesh* mesh)
186 if ( myMesh != mesh )
193 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
194 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
195 TDependsOnMap::const_iterator sm;
196 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
197 sm->second->SetEventListener( this, 0, sm->second );
201 //!< delete self from all submeshes
202 void Unset(SMESH_Mesh* mesh)
204 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
205 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
206 TDependsOnMap::const_iterator sm;
207 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
208 sm->second->DeleteEventListener( this );
213 } theSearchersDeleter;
215 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
217 TCollection_AsciiString typeStr;
218 switch ( theMirrorType ) {
219 case SMESH::SMESH_MeshEditor::POINT:
220 typeStr = "SMESH.SMESH_MeshEditor.POINT";
222 case SMESH::SMESH_MeshEditor::AXIS:
223 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
226 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
232 //=============================================================================
236 //=============================================================================
238 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
241 myMesh = & theMesh->GetImpl();
242 myPreviewMode = isPreview;
245 //================================================================================
249 //================================================================================
251 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
255 //================================================================================
257 * \brief Clear members
259 //================================================================================
261 void SMESH_MeshEditor_i::initData(bool deleteSearchers)
263 if ( myPreviewMode ) {
264 myPreviewData = new SMESH::MeshPreviewStruct();
267 myLastCreatedElems = new SMESH::long_array();
268 myLastCreatedNodes = new SMESH::long_array();
269 if ( deleteSearchers )
270 TSearchersDeleter::Delete();
274 //=======================================================================
275 //function : MakeIDSource
276 //purpose : Wrap a sequence of ids in a SMESH_IDSource
277 //=======================================================================
279 struct _IDSource : public POA_SMESH::SMESH_IDSource
281 SMESH::long_array _ids;
282 SMESH::long_array* GetIDs() { return new SMESH::long_array( _ids ); }
283 SMESH::long_array* GetMeshInfo() { return 0; }
286 SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_array& ids)
288 _IDSource* anIDSource = new _IDSource;
289 anIDSource->_ids = ids;
290 SMESH::SMESH_IDSource_var anIDSourceVar = anIDSource->_this();
292 return anIDSourceVar._retn();
295 //=============================================================================
299 //=============================================================================
302 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
306 ::SMESH_MeshEditor anEditor( myMesh );
309 for (int i = 0; i < IDsOfElements.length(); i++)
310 IdList.push_back( IDsOfElements[i] );
312 // Update Python script
313 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
315 return anEditor.Remove( IdList, false );
318 //=============================================================================
322 //=============================================================================
324 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
328 ::SMESH_MeshEditor anEditor( myMesh );
330 for (int i = 0; i < IDsOfNodes.length(); i++)
331 IdList.push_back( IDsOfNodes[i] );
333 // Update Python script
334 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
336 return anEditor.Remove( IdList, true );
339 //=============================================================================
343 //=============================================================================
345 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
346 CORBA::Double y, CORBA::Double z)
350 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
352 // Update Python script
353 TPythonDump() << "nodeID = " << this << ".AddNode( "
354 << x << ", " << y << ", " << z << " )";
359 //=============================================================================
363 //=============================================================================
364 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
368 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
369 SMDS_MeshElement* elem = GetMeshDS()->Add0DElement(aNode);
371 // Update Python script
372 TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
375 return elem->GetID();
380 //=============================================================================
384 //=============================================================================
386 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
390 int NbNodes = IDsOfNodes.length();
391 SMDS_MeshElement* elem = 0;
394 CORBA::Long index1 = IDsOfNodes[0];
395 CORBA::Long index2 = IDsOfNodes[1];
396 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
398 // Update Python script
399 TPythonDump() << "edge = " << this << ".AddEdge([ "
400 << index1 << ", " << index2 <<" ])";
403 CORBA::Long n1 = IDsOfNodes[0];
404 CORBA::Long n2 = IDsOfNodes[1];
405 CORBA::Long n12 = IDsOfNodes[2];
406 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
407 GetMeshDS()->FindNode(n2),
408 GetMeshDS()->FindNode(n12));
409 // Update Python script
410 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
411 <<n1<<", "<<n2<<", "<<n12<<" ])";
415 return elem->GetID();
420 //=============================================================================
424 //=============================================================================
426 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
430 int NbNodes = IDsOfNodes.length();
436 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
437 for (int i = 0; i < NbNodes; i++)
438 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
440 SMDS_MeshElement* elem = 0;
442 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
444 else if (NbNodes == 4) {
445 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
447 else if (NbNodes == 6) {
448 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
451 else if (NbNodes == 8) {
452 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
453 nodes[4], nodes[5], nodes[6], nodes[7]);
455 else if (NbNodes > 2) {
456 elem = GetMeshDS()->AddPolygonalFace(nodes);
459 // Update Python script
460 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
463 return elem->GetID();
468 //=============================================================================
472 //=============================================================================
473 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsOfNodes)
477 int NbNodes = IDsOfNodes.length();
478 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
479 for (int i = 0; i < NbNodes; i++)
480 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
482 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
484 // Update Python script
485 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
487 return elem ? elem->GetID() : 0;
490 //=============================================================================
494 //=============================================================================
496 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
500 int NbNodes = IDsOfNodes.length();
501 vector< const SMDS_MeshNode*> n(NbNodes);
502 for(int i=0;i<NbNodes;i++)
503 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
505 SMDS_MeshElement* elem = 0;
508 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
509 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
510 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
511 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
512 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
513 n[6],n[7],n[8],n[9]);
515 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
516 n[7],n[8],n[9],n[10],n[11],n[12]);
518 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
519 n[9],n[10],n[11],n[12],n[13],n[14]);
521 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
522 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
523 n[15],n[16],n[17],n[18],n[19]);
527 // Update Python script
528 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
531 return elem->GetID();
536 //=============================================================================
538 * AddPolyhedralVolume
540 //=============================================================================
541 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume (const SMESH::long_array & IDsOfNodes,
542 const SMESH::long_array & Quantities)
546 int NbNodes = IDsOfNodes.length();
547 std::vector<const SMDS_MeshNode*> n (NbNodes);
548 for (int i = 0; i < NbNodes; i++)
549 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
551 int NbFaces = Quantities.length();
552 std::vector<int> q (NbFaces);
553 for (int j = 0; j < NbFaces; j++)
554 q[j] = Quantities[j];
556 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
558 // Update Python script
559 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
560 << IDsOfNodes << ", " << Quantities << " )";
562 return elem ? elem->GetID() : 0;
565 //=============================================================================
567 * AddPolyhedralVolumeByFaces
569 //=============================================================================
570 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_array & IdsOfFaces)
574 int NbFaces = IdsOfFaces.length();
575 std::vector<const SMDS_MeshNode*> poly_nodes;
576 std::vector<int> quantities (NbFaces);
578 for (int i = 0; i < NbFaces; i++) {
579 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
580 quantities[i] = aFace->NbNodes();
582 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
584 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
588 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
590 // Update Python script
591 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
592 << IdsOfFaces << " )";
594 return elem ? elem->GetID() : 0;
597 //=============================================================================
599 * \brief Bind a node to a vertex
600 * \param NodeID - node ID
601 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
602 * \retval boolean - false if NodeID or VertexID is invalid
604 //=============================================================================
606 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
607 throw (SALOME::SALOME_Exception)
609 Unexpect aCatch(SALOME_SalomeException);
611 SMESHDS_Mesh * mesh = GetMeshDS();
612 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
614 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
616 if ( mesh->MaxShapeIndex() < VertexID )
617 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
619 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
620 if ( shape.ShapeType() != TopAbs_VERTEX )
621 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
623 mesh->SetNodeOnVertex( node, VertexID );
626 //=============================================================================
628 * \brief Store node position on an edge
629 * \param NodeID - node ID
630 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
631 * \param paramOnEdge - parameter on edge where the node is located
632 * \retval boolean - false if any parameter is invalid
634 //=============================================================================
636 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
637 CORBA::Double paramOnEdge)
638 throw (SALOME::SALOME_Exception)
640 Unexpect aCatch(SALOME_SalomeException);
642 SMESHDS_Mesh * mesh = GetMeshDS();
643 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
645 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
647 if ( mesh->MaxShapeIndex() < EdgeID )
648 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
650 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
651 if ( shape.ShapeType() != TopAbs_EDGE )
652 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
655 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
656 if ( paramOnEdge < f || paramOnEdge > l )
657 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
659 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
662 //=============================================================================
664 * \brief Store node position on a face
665 * \param NodeID - node ID
666 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
667 * \param u - U parameter on face where the node is located
668 * \param v - V parameter on face where the node is located
669 * \retval boolean - false if any parameter is invalid
671 //=============================================================================
673 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
674 CORBA::Double u, CORBA::Double v)
675 throw (SALOME::SALOME_Exception)
677 Unexpect aCatch(SALOME_SalomeException);
679 SMESHDS_Mesh * mesh = GetMeshDS();
680 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
682 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
684 if ( mesh->MaxShapeIndex() < FaceID )
685 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
687 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
688 if ( shape.ShapeType() != TopAbs_FACE )
689 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
691 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
692 bool isOut = ( u < surf.FirstUParameter() ||
693 u > surf.LastUParameter() ||
694 v < surf.FirstVParameter() ||
695 v > surf.LastVParameter() );
699 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
700 << " u( " << surf.FirstUParameter()
701 << "," << surf.LastUParameter()
702 << ") v( " << surf.FirstVParameter()
703 << "," << surf.LastVParameter() << ")" );
705 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
708 mesh->SetNodeOnFace( node, FaceID, u, v );
711 //=============================================================================
713 * \brief Bind a node to a solid
714 * \param NodeID - node ID
715 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
716 * \retval boolean - false if NodeID or SolidID is invalid
718 //=============================================================================
720 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
721 throw (SALOME::SALOME_Exception)
723 Unexpect aCatch(SALOME_SalomeException);
725 SMESHDS_Mesh * mesh = GetMeshDS();
726 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
728 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
730 if ( mesh->MaxShapeIndex() < SolidID )
731 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
733 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
734 if ( shape.ShapeType() != TopAbs_SOLID &&
735 shape.ShapeType() != TopAbs_SHELL)
736 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
738 mesh->SetNodeInVolume( node, SolidID );
741 //=============================================================================
743 * \brief Bind an element to a shape
744 * \param ElementID - element ID
745 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
746 * \retval boolean - false if ElementID or ShapeID is invalid
748 //=============================================================================
750 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
752 throw (SALOME::SALOME_Exception)
754 Unexpect aCatch(SALOME_SalomeException);
756 SMESHDS_Mesh * mesh = GetMeshDS();
757 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
759 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
761 if ( mesh->MaxShapeIndex() < ShapeID )
762 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
764 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
765 if ( shape.ShapeType() != TopAbs_EDGE &&
766 shape.ShapeType() != TopAbs_FACE &&
767 shape.ShapeType() != TopAbs_SOLID &&
768 shape.ShapeType() != TopAbs_SHELL )
769 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
771 mesh->SetMeshElementOnShape( elem, ShapeID );
774 //=============================================================================
778 //=============================================================================
780 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
785 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
786 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
790 // Update Python script
791 TPythonDump() << "isDone = " << this << ".InverseDiag( "
792 << NodeID1 << ", " << NodeID2 << " )";
794 ::SMESH_MeshEditor aMeshEditor( myMesh );
795 return aMeshEditor.InverseDiag ( n1, n2 );
798 //=============================================================================
802 //=============================================================================
804 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
809 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
810 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
814 // Update Python script
815 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
816 << NodeID1 << ", " << NodeID2 << " )";
818 ::SMESH_MeshEditor aMeshEditor( myMesh );
820 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
822 storeResult(aMeshEditor);
827 //=============================================================================
831 //=============================================================================
833 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
837 ::SMESH_MeshEditor anEditor( myMesh );
838 for (int i = 0; i < IDsOfElements.length(); i++)
840 CORBA::Long index = IDsOfElements[i];
841 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
843 anEditor.Reorient( elem );
845 // Update Python script
846 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
852 //=============================================================================
856 //=============================================================================
858 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
862 SMESH::long_array_var anElementsId = theObject->GetIDs();
863 CORBA::Boolean isDone = Reorient(anElementsId);
865 // Clear python line, created by Reorient()
866 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
867 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
869 // Update Python script
870 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
877 //================================================================================
879 * \brief function for conversion long_array to TIDSortedElemSet
880 * \param IDs - array of IDs
881 * \param aMesh - mesh
882 * \param aMap - collection to fill
883 * \param aType - element type
885 //================================================================================
887 void arrayToSet(const SMESH::long_array & IDs,
888 const SMESHDS_Mesh* aMesh,
889 TIDSortedElemSet& aMap,
890 const SMDSAbs_ElementType aType = SMDSAbs_All )
892 for (int i=0; i<IDs.length(); i++) {
893 CORBA::Long ind = IDs[i];
894 const SMDS_MeshElement * elem =
895 (aType == SMDSAbs_Node ? aMesh->FindNode(ind)
896 : aMesh->FindElement(ind));
897 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
903 //=============================================================================
907 //=============================================================================
908 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
909 SMESH::NumericalFunctor_ptr Criterion,
910 CORBA::Double MaxAngle)
914 SMESHDS_Mesh* aMesh = GetMeshDS();
915 TIDSortedElemSet faces;
916 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
918 SMESH::NumericalFunctor_i* aNumericalFunctor =
919 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
920 SMESH::Controls::NumericalFunctorPtr aCrit;
921 if ( !aNumericalFunctor )
922 aCrit.reset( new SMESH::Controls::AspectRatio() );
924 aCrit = aNumericalFunctor->GetNumericalFunctor();
926 // Update Python script
927 TPythonDump() << "isDone = " << this << ".TriToQuad( "
928 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
930 ::SMESH_MeshEditor anEditor( myMesh );
932 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
934 storeResult(anEditor);
940 //=============================================================================
944 //=============================================================================
945 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
946 SMESH::NumericalFunctor_ptr Criterion,
947 CORBA::Double MaxAngle)
951 SMESH::long_array_var anElementsId = theObject->GetIDs();
952 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
954 // Clear python line(s), created by TriToQuad()
955 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
956 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
958 SMESH::NumericalFunctor_i* aNumericalFunctor =
959 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
961 // Update Python script
962 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
963 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
969 //=============================================================================
973 //=============================================================================
974 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
975 SMESH::NumericalFunctor_ptr Criterion)
979 SMESHDS_Mesh* aMesh = GetMeshDS();
980 TIDSortedElemSet faces;
981 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
983 SMESH::NumericalFunctor_i* aNumericalFunctor =
984 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
985 SMESH::Controls::NumericalFunctorPtr aCrit;
986 if ( !aNumericalFunctor )
987 aCrit.reset( new SMESH::Controls::AspectRatio() );
989 aCrit = aNumericalFunctor->GetNumericalFunctor();
992 // Update Python script
993 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
995 ::SMESH_MeshEditor anEditor( myMesh );
996 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
998 storeResult(anEditor);
1004 //=============================================================================
1008 //=============================================================================
1009 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1010 SMESH::NumericalFunctor_ptr Criterion)
1014 SMESH::long_array_var anElementsId = theObject->GetIDs();
1015 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1017 // Clear python line(s), created by QuadToTri()
1018 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1019 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1021 SMESH::NumericalFunctor_i* aNumericalFunctor =
1022 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1024 // Update Python script
1025 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1031 //=============================================================================
1035 //=============================================================================
1036 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1037 CORBA::Boolean Diag13)
1041 SMESHDS_Mesh* aMesh = GetMeshDS();
1042 TIDSortedElemSet faces;
1043 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1045 // Update Python script
1046 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1047 << IDsOfElements << ", " << Diag13 << " )";
1049 ::SMESH_MeshEditor anEditor( myMesh );
1050 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1052 storeResult(anEditor);
1058 //=============================================================================
1062 //=============================================================================
1063 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1064 CORBA::Boolean Diag13)
1068 SMESH::long_array_var anElementsId = theObject->GetIDs();
1069 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1071 // Clear python line(s), created by SplitQuad()
1072 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1073 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1075 // Update Python script
1076 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1077 << theObject << ", " << Diag13 << " )";
1083 //=============================================================================
1087 //=============================================================================
1088 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1089 SMESH::NumericalFunctor_ptr Criterion)
1091 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1092 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1094 SMESH::NumericalFunctor_i* aNumericalFunctor =
1095 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1096 SMESH::Controls::NumericalFunctorPtr aCrit;
1097 if (aNumericalFunctor)
1098 aCrit = aNumericalFunctor->GetNumericalFunctor();
1100 aCrit.reset(new SMESH::Controls::AspectRatio());
1102 ::SMESH_MeshEditor anEditor (myMesh);
1103 return anEditor.BestSplit(quad, aCrit);
1108 //================================================================================
1110 * \brief Split volumic elements into tetrahedrons
1112 //================================================================================
1114 void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems,
1115 CORBA::Short methodFlags)
1116 throw (SALOME::SALOME_Exception)
1118 Unexpect aCatch(SALOME_SalomeException);
1120 SMESH::long_array_var anElementsId = elems->GetIDs();
1121 TIDSortedElemSet elemSet;
1122 arrayToSet( anElementsId, GetMeshDS(), elemSet, SMDSAbs_Volume );
1124 ::SMESH_MeshEditor anEditor (myMesh);
1125 anEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags ));
1127 TPythonDump() << this << ".SplitVolumesIntoTetra( "
1128 << elems << ", " << methodFlags << " )";
1131 //=======================================================================
1134 //=======================================================================
1137 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1138 const SMESH::long_array & IDsOfFixedNodes,
1139 CORBA::Long MaxNbOfIterations,
1140 CORBA::Double MaxAspectRatio,
1141 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1143 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1144 MaxAspectRatio, Method, false );
1148 //=======================================================================
1149 //function : SmoothParametric
1151 //=======================================================================
1154 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1155 const SMESH::long_array & IDsOfFixedNodes,
1156 CORBA::Long MaxNbOfIterations,
1157 CORBA::Double MaxAspectRatio,
1158 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1160 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1161 MaxAspectRatio, Method, true );
1165 //=======================================================================
1166 //function : SmoothObject
1168 //=======================================================================
1171 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1172 const SMESH::long_array & IDsOfFixedNodes,
1173 CORBA::Long MaxNbOfIterations,
1174 CORBA::Double MaxAspectRatio,
1175 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1177 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1178 MaxAspectRatio, Method, false);
1182 //=======================================================================
1183 //function : SmoothParametricObject
1185 //=======================================================================
1188 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1189 const SMESH::long_array & IDsOfFixedNodes,
1190 CORBA::Long MaxNbOfIterations,
1191 CORBA::Double MaxAspectRatio,
1192 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1194 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1195 MaxAspectRatio, Method, true);
1199 //=============================================================================
1203 //=============================================================================
1206 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1207 const SMESH::long_array & IDsOfFixedNodes,
1208 CORBA::Long MaxNbOfIterations,
1209 CORBA::Double MaxAspectRatio,
1210 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1215 SMESHDS_Mesh* aMesh = GetMeshDS();
1217 TIDSortedElemSet elements;
1218 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1220 set<const SMDS_MeshNode*> fixedNodes;
1221 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1222 CORBA::Long index = IDsOfFixedNodes[i];
1223 const SMDS_MeshNode * node = aMesh->FindNode(index);
1225 fixedNodes.insert( node );
1227 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1228 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1229 method = ::SMESH_MeshEditor::CENTROIDAL;
1231 ::SMESH_MeshEditor anEditor( myMesh );
1232 anEditor.Smooth(elements, fixedNodes, method,
1233 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1235 storeResult(anEditor);
1237 // Update Python script
1238 TPythonDump() << "isDone = " << this << "."
1239 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1240 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1241 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1242 << "SMESH.SMESH_MeshEditor."
1243 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1244 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1250 //=============================================================================
1254 //=============================================================================
1257 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1258 const SMESH::long_array & IDsOfFixedNodes,
1259 CORBA::Long MaxNbOfIterations,
1260 CORBA::Double MaxAspectRatio,
1261 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1266 SMESH::long_array_var anElementsId = theObject->GetIDs();
1267 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1268 MaxAspectRatio, Method, IsParametric);
1270 // Clear python line(s), created by Smooth()
1271 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1272 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1274 // Update Python script
1275 TPythonDump() << "isDone = " << this << "."
1276 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1277 << theObject << ", " << IDsOfFixedNodes << ", "
1278 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1279 << "SMESH.SMESH_MeshEditor."
1280 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1281 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1287 //=============================================================================
1291 //=============================================================================
1293 void SMESH_MeshEditor_i::RenumberNodes()
1295 // Update Python script
1296 TPythonDump() << this << ".RenumberNodes()";
1298 GetMeshDS()->Renumber( true );
1302 //=============================================================================
1306 //=============================================================================
1308 void SMESH_MeshEditor_i::RenumberElements()
1310 // Update Python script
1311 TPythonDump() << this << ".RenumberElements()";
1313 GetMeshDS()->Renumber( false );
1316 //=======================================================================
1318 * \brief Return groups by their IDs
1320 //=======================================================================
1322 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1326 myMesh_i->CreateGroupServants();
1327 return myMesh_i->GetGroups( *groupIDs );
1330 //=======================================================================
1331 //function : rotationSweep
1333 //=======================================================================
1335 SMESH::ListOfGroups*
1336 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1337 const SMESH::AxisStruct & theAxis,
1338 CORBA::Double theAngleInRadians,
1339 CORBA::Long theNbOfSteps,
1340 CORBA::Double theTolerance,
1341 const bool theMakeGroups,
1342 const SMDSAbs_ElementType theElementType)
1346 TIDSortedElemSet inElements, copyElements;
1347 arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType);
1349 TIDSortedElemSet* workElements = & inElements;
1350 TPreviewMesh tmpMesh( SMDSAbs_Face );
1351 SMESH_Mesh* mesh = 0;
1352 bool makeWalls=true;
1353 if ( myPreviewMode )
1355 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1356 tmpMesh.Copy( inElements, copyElements, select, avoid );
1358 workElements = & copyElements;
1359 //makeWalls = false;
1366 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1367 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1369 ::SMESH_MeshEditor anEditor( mesh );
1370 ::SMESH_MeshEditor::PGroupIDs groupIds =
1371 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1372 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1373 storeResult(anEditor);
1375 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1378 //=======================================================================
1379 //function : RotationSweep
1381 //=======================================================================
1383 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1384 const SMESH::AxisStruct & theAxis,
1385 CORBA::Double theAngleInRadians,
1386 CORBA::Long theNbOfSteps,
1387 CORBA::Double theTolerance)
1389 if ( !myPreviewMode ) {
1390 TPythonDump() << this << ".RotationSweep( "
1391 << theIDsOfElements << ", "
1393 << theAngleInRadians << ", "
1394 << theNbOfSteps << ", "
1395 << theTolerance << " )";
1397 rotationSweep(theIDsOfElements,
1405 //=======================================================================
1406 //function : RotationSweepMakeGroups
1408 //=======================================================================
1410 SMESH::ListOfGroups*
1411 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1412 const SMESH::AxisStruct& theAxis,
1413 CORBA::Double theAngleInRadians,
1414 CORBA::Long theNbOfSteps,
1415 CORBA::Double theTolerance)
1417 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1423 if ( !myPreviewMode ) {
1424 TPythonDump aPythonDump;
1425 DumpGroupsList(aPythonDump,aGroups);
1426 aPythonDump<< this << ".RotationSweepMakeGroups( "
1427 << theIDsOfElements << ", "
1429 << theAngleInRadians << ", "
1430 << theNbOfSteps << ", "
1431 << theTolerance << " )";
1436 //=======================================================================
1437 //function : RotationSweepObject
1439 //=======================================================================
1441 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1442 const SMESH::AxisStruct & theAxis,
1443 CORBA::Double theAngleInRadians,
1444 CORBA::Long theNbOfSteps,
1445 CORBA::Double theTolerance)
1447 if ( !myPreviewMode ) {
1448 TPythonDump() << this << ".RotationSweepObject( "
1449 << theObject << ", "
1451 << theAngleInRadians << ", "
1452 << theNbOfSteps << ", "
1453 << theTolerance << " )";
1455 SMESH::long_array_var anElementsId = theObject->GetIDs();
1456 rotationSweep(anElementsId,
1464 //=======================================================================
1465 //function : RotationSweepObject1D
1467 //=======================================================================
1469 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1470 const SMESH::AxisStruct & theAxis,
1471 CORBA::Double theAngleInRadians,
1472 CORBA::Long theNbOfSteps,
1473 CORBA::Double theTolerance)
1475 if ( !myPreviewMode ) {
1476 TPythonDump() << this << ".RotationSweepObject1D( "
1477 << theObject << ", "
1479 << theAngleInRadians << ", "
1480 << theNbOfSteps << ", "
1481 << theTolerance << " )";
1483 SMESH::long_array_var anElementsId = theObject->GetIDs();
1484 rotationSweep(anElementsId,
1493 //=======================================================================
1494 //function : RotationSweepObject2D
1496 //=======================================================================
1498 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1499 const SMESH::AxisStruct & theAxis,
1500 CORBA::Double theAngleInRadians,
1501 CORBA::Long theNbOfSteps,
1502 CORBA::Double theTolerance)
1504 if ( !myPreviewMode ) {
1505 TPythonDump() << this << ".RotationSweepObject2D( "
1506 << theObject << ", "
1508 << theAngleInRadians << ", "
1509 << theNbOfSteps << ", "
1510 << theTolerance << " )";
1512 SMESH::long_array_var anElementsId = theObject->GetIDs();
1513 rotationSweep(anElementsId,
1522 //=======================================================================
1523 //function : RotationSweepObjectMakeGroups
1525 //=======================================================================
1527 SMESH::ListOfGroups*
1528 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1529 const SMESH::AxisStruct& theAxis,
1530 CORBA::Double theAngleInRadians,
1531 CORBA::Long theNbOfSteps,
1532 CORBA::Double theTolerance)
1534 SMESH::long_array_var anElementsId = theObject->GetIDs();
1535 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1541 if ( !myPreviewMode ) {
1542 TPythonDump aPythonDump;
1543 DumpGroupsList(aPythonDump,aGroups);
1544 aPythonDump<< this << ".RotationSweepObjectMakeGroups( "
1545 << theObject << ", "
1547 << theAngleInRadians << ", "
1548 << theNbOfSteps << ", "
1549 << theTolerance << " )";
1554 //=======================================================================
1555 //function : RotationSweepObject1DMakeGroups
1557 //=======================================================================
1559 SMESH::ListOfGroups*
1560 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1561 const SMESH::AxisStruct& theAxis,
1562 CORBA::Double theAngleInRadians,
1563 CORBA::Long theNbOfSteps,
1564 CORBA::Double theTolerance)
1566 SMESH::long_array_var anElementsId = theObject->GetIDs();
1567 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1574 if ( !myPreviewMode ) {
1575 TPythonDump aPythonDump;
1576 DumpGroupsList(aPythonDump,aGroups);
1577 aPythonDump<< this << ".RotationSweepObject1DMakeGroups( "
1578 << theObject << ", "
1580 << theAngleInRadians << ", "
1581 << theNbOfSteps << ", "
1582 << theTolerance << " )";
1587 //=======================================================================
1588 //function : RotationSweepObject2DMakeGroups
1590 //=======================================================================
1592 SMESH::ListOfGroups*
1593 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1594 const SMESH::AxisStruct& theAxis,
1595 CORBA::Double theAngleInRadians,
1596 CORBA::Long theNbOfSteps,
1597 CORBA::Double theTolerance)
1599 SMESH::long_array_var anElementsId = theObject->GetIDs();
1600 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1607 if ( !myPreviewMode ) {
1608 TPythonDump aPythonDump;
1609 DumpGroupsList(aPythonDump,aGroups);
1610 aPythonDump<< this << ".RotationSweepObject2DMakeGroups( "
1611 << theObject << ", "
1613 << theAngleInRadians << ", "
1614 << theNbOfSteps << ", "
1615 << theTolerance << " )";
1621 //=======================================================================
1622 //function : extrusionSweep
1624 //=======================================================================
1626 SMESH::ListOfGroups*
1627 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1628 const SMESH::DirStruct & theStepVector,
1629 CORBA::Long theNbOfSteps,
1630 const bool theMakeGroups,
1631 const SMDSAbs_ElementType theElementType)
1639 TIDSortedElemSet elements;
1640 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1642 const SMESH::PointStruct * P = &theStepVector.PS;
1643 gp_Vec stepVec( P->x, P->y, P->z );
1645 TElemOfElemListMap aHystory;
1646 ::SMESH_MeshEditor anEditor( myMesh );
1647 ::SMESH_MeshEditor::PGroupIDs groupIds =
1648 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1650 storeResult(anEditor);
1652 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1654 } catch(Standard_Failure) {
1655 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1656 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1661 //=======================================================================
1662 //function : ExtrusionSweep
1664 //=======================================================================
1666 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1667 const SMESH::DirStruct & theStepVector,
1668 CORBA::Long theNbOfSteps)
1670 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1671 if ( !myPreviewMode ) {
1672 TPythonDump() << this << ".ExtrusionSweep( "
1673 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1678 //=======================================================================
1679 //function : ExtrusionSweepObject
1681 //=======================================================================
1683 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1684 const SMESH::DirStruct & theStepVector,
1685 CORBA::Long theNbOfSteps)
1687 SMESH::long_array_var anElementsId = theObject->GetIDs();
1688 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1689 if ( !myPreviewMode ) {
1690 TPythonDump() << this << ".ExtrusionSweepObject( "
1691 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1695 //=======================================================================
1696 //function : ExtrusionSweepObject1D
1698 //=======================================================================
1700 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1701 const SMESH::DirStruct & theStepVector,
1702 CORBA::Long theNbOfSteps)
1704 SMESH::long_array_var anElementsId = theObject->GetIDs();
1705 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1706 if ( !myPreviewMode ) {
1707 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1708 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1712 //=======================================================================
1713 //function : ExtrusionSweepObject2D
1715 //=======================================================================
1717 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1718 const SMESH::DirStruct & theStepVector,
1719 CORBA::Long theNbOfSteps)
1721 SMESH::long_array_var anElementsId = theObject->GetIDs();
1722 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1723 if ( !myPreviewMode ) {
1724 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1725 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1729 //=======================================================================
1730 //function : ExtrusionSweepMakeGroups
1732 //=======================================================================
1734 SMESH::ListOfGroups*
1735 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1736 const SMESH::DirStruct& theStepVector,
1737 CORBA::Long theNbOfSteps)
1739 SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1741 if ( !myPreviewMode ) {
1742 TPythonDump aPythonDump;
1743 DumpGroupsList(aPythonDump,aGroups);
1744 aPythonDump << this << ".ExtrusionSweepMakeGroups( "
1745 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1749 //=======================================================================
1750 //function : ExtrusionSweepObjectMakeGroups
1752 //=======================================================================
1754 SMESH::ListOfGroups*
1755 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1756 const SMESH::DirStruct& theStepVector,
1757 CORBA::Long theNbOfSteps)
1759 SMESH::long_array_var anElementsId = theObject->GetIDs();
1760 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1762 if ( !myPreviewMode ) {
1763 TPythonDump aPythonDump;
1764 DumpGroupsList(aPythonDump,aGroups);
1765 aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( "
1766 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1771 //=======================================================================
1772 //function : ExtrusionSweepObject1DMakeGroups
1774 //=======================================================================
1776 SMESH::ListOfGroups*
1777 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1778 const SMESH::DirStruct& theStepVector,
1779 CORBA::Long theNbOfSteps)
1781 SMESH::long_array_var anElementsId = theObject->GetIDs();
1782 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1783 if ( !myPreviewMode ) {
1784 TPythonDump aPythonDump;
1785 DumpGroupsList(aPythonDump,aGroups);
1786 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( "
1787 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1792 //=======================================================================
1793 //function : ExtrusionSweepObject2DMakeGroups
1795 //=======================================================================
1797 SMESH::ListOfGroups*
1798 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1799 const SMESH::DirStruct& theStepVector,
1800 CORBA::Long theNbOfSteps)
1802 SMESH::long_array_var anElementsId = theObject->GetIDs();
1803 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1804 if ( !myPreviewMode ) {
1805 TPythonDump aPythonDump;
1806 DumpGroupsList(aPythonDump,aGroups);
1807 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( "
1808 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1814 //=======================================================================
1815 //function : advancedExtrusion
1817 //=======================================================================
1819 SMESH::ListOfGroups*
1820 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1821 const SMESH::DirStruct & theStepVector,
1822 CORBA::Long theNbOfSteps,
1823 CORBA::Long theExtrFlags,
1824 CORBA::Double theSewTolerance,
1825 const bool theMakeGroups)
1829 TIDSortedElemSet elements;
1830 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1832 const SMESH::PointStruct * P = &theStepVector.PS;
1833 gp_Vec stepVec( P->x, P->y, P->z );
1835 ::SMESH_MeshEditor anEditor( myMesh );
1836 TElemOfElemListMap aHystory;
1837 ::SMESH_MeshEditor::PGroupIDs groupIds =
1838 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1839 theMakeGroups, theExtrFlags, theSewTolerance);
1840 storeResult(anEditor);
1842 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1845 //=======================================================================
1846 //function : AdvancedExtrusion
1848 //=======================================================================
1850 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1851 const SMESH::DirStruct & theStepVector,
1852 CORBA::Long theNbOfSteps,
1853 CORBA::Long theExtrFlags,
1854 CORBA::Double theSewTolerance)
1856 if ( !myPreviewMode ) {
1857 TPythonDump() << "stepVector = " << theStepVector;
1858 TPythonDump() << this << ".AdvancedExtrusion("
1861 << theNbOfSteps << ","
1862 << theExtrFlags << ", "
1863 << theSewTolerance << " )";
1865 advancedExtrusion( theIDsOfElements,
1873 //=======================================================================
1874 //function : AdvancedExtrusionMakeGroups
1876 //=======================================================================
1878 SMESH::ListOfGroups*
1879 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1880 const SMESH::DirStruct& theStepVector,
1881 CORBA::Long theNbOfSteps,
1882 CORBA::Long theExtrFlags,
1883 CORBA::Double theSewTolerance)
1885 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
1892 if ( !myPreviewMode ) {
1893 TPythonDump() << "stepVector = " << theStepVector;
1894 TPythonDump aPythonDump;
1895 DumpGroupsList(aPythonDump,aGroups);
1896 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
1899 << theNbOfSteps << ","
1900 << theExtrFlags << ", "
1901 << theSewTolerance << " )";
1907 //================================================================================
1909 * \brief Convert extrusion error to IDL enum
1911 //================================================================================
1913 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1915 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1919 RETCASE( EXTR_NO_ELEMENTS );
1920 RETCASE( EXTR_PATH_NOT_EDGE );
1921 RETCASE( EXTR_BAD_PATH_SHAPE );
1922 RETCASE( EXTR_BAD_STARTING_NODE );
1923 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1924 RETCASE( EXTR_CANT_GET_TANGENT );
1926 return SMESH::SMESH_MeshEditor::EXTR_OK;
1930 //=======================================================================
1931 //function : extrusionAlongPath
1933 //=======================================================================
1935 SMESH::ListOfGroups*
1936 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1937 SMESH::SMESH_Mesh_ptr thePathMesh,
1938 GEOM::GEOM_Object_ptr thePathShape,
1939 CORBA::Long theNodeStart,
1940 CORBA::Boolean theHasAngles,
1941 const SMESH::double_array & theAngles,
1942 CORBA::Boolean theHasRefPoint,
1943 const SMESH::PointStruct & theRefPoint,
1944 const bool theMakeGroups,
1945 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
1946 const SMDSAbs_ElementType theElementType)
1950 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1951 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1954 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1956 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1957 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1959 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
1960 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1964 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1966 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1970 TIDSortedElemSet elements;
1971 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1973 list<double> angles;
1974 for (int i = 0; i < theAngles.length(); i++) {
1975 angles.push_back( theAngles[i] );
1978 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1980 int nbOldGroups = myMesh->NbGroup();
1982 ::SMESH_MeshEditor anEditor( myMesh );
1983 ::SMESH_MeshEditor::Extrusion_Error error =
1984 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1985 theHasAngles, angles, false,
1986 theHasRefPoint, refPnt, theMakeGroups );
1987 storeResult(anEditor);
1988 theError = convExtrError( error );
1990 if ( theMakeGroups ) {
1991 list<int> groupIDs = myMesh->GetGroupIds();
1992 list<int>::iterator newBegin = groupIDs.begin();
1993 std::advance( newBegin, nbOldGroups ); // skip old groups
1994 groupIDs.erase( groupIDs.begin(), newBegin );
1995 return getGroups( & groupIDs );
2001 //=======================================================================
2002 //function : extrusionAlongPathX
2004 //=======================================================================
2006 SMESH::ListOfGroups*
2007 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2008 SMESH::SMESH_IDSource_ptr Path,
2009 CORBA::Long NodeStart,
2010 CORBA::Boolean HasAngles,
2011 const SMESH::double_array& Angles,
2012 CORBA::Boolean LinearVariation,
2013 CORBA::Boolean HasRefPoint,
2014 const SMESH::PointStruct& RefPoint,
2015 const bool MakeGroups,
2016 const SMDSAbs_ElementType ElementType,
2017 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2019 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2023 list<double> angles;
2024 for (int i = 0; i < Angles.length(); i++) {
2025 angles.push_back( Angles[i] );
2027 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2028 int nbOldGroups = myMesh->NbGroup();
2030 if ( Path->_is_nil() ) {
2031 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2035 TIDSortedElemSet elements;
2036 arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
2038 ::SMESH_MeshEditor anEditor( myMesh );
2039 ::SMESH_MeshEditor::Extrusion_Error error;
2041 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
2044 SMDS_MeshNode* aNodeStart =
2045 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2046 if ( !aNodeStart ) {
2047 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2050 error = anEditor.ExtrusionAlongTrack( elements, &(aMeshImp->GetImpl()), aNodeStart,
2051 HasAngles, angles, LinearVariation,
2052 HasRefPoint, refPnt, MakeGroups );
2055 SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
2058 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
2059 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
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 SMESH_subMesh* aSubMesh =
2067 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
2068 error = anEditor.ExtrusionAlongTrack( elements, aSubMesh, aNodeStart,
2069 HasAngles, angles, LinearVariation,
2070 HasRefPoint, refPnt, MakeGroups );
2073 SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
2075 // path as group of 1D elements
2079 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2085 storeResult(anEditor);
2086 Error = convExtrError( error );
2089 list<int> groupIDs = myMesh->GetGroupIds();
2090 list<int>::iterator newBegin = groupIDs.begin();
2091 std::advance( newBegin, nbOldGroups ); // skip old groups
2092 groupIDs.erase( groupIDs.begin(), newBegin );
2093 return getGroups( & groupIDs );
2099 //=======================================================================
2100 //function : ExtrusionAlongPath
2102 //=======================================================================
2104 SMESH::SMESH_MeshEditor::Extrusion_Error
2105 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2106 SMESH::SMESH_Mesh_ptr thePathMesh,
2107 GEOM::GEOM_Object_ptr thePathShape,
2108 CORBA::Long theNodeStart,
2109 CORBA::Boolean theHasAngles,
2110 const SMESH::double_array & theAngles,
2111 CORBA::Boolean theHasRefPoint,
2112 const SMESH::PointStruct & theRefPoint)
2114 if ( !myPreviewMode ) {
2115 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
2116 << theIDsOfElements << ", "
2117 << thePathMesh << ", "
2118 << thePathShape << ", "
2119 << theNodeStart << ", "
2120 << theHasAngles << ", "
2121 << theAngles << ", "
2122 << theHasRefPoint << ", "
2123 << "SMESH.PointStruct( "
2124 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2125 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2126 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2128 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2129 extrusionAlongPath( theIDsOfElements,
2142 //=======================================================================
2143 //function : ExtrusionAlongPathObject
2145 //=======================================================================
2147 SMESH::SMESH_MeshEditor::Extrusion_Error
2148 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
2149 SMESH::SMESH_Mesh_ptr thePathMesh,
2150 GEOM::GEOM_Object_ptr thePathShape,
2151 CORBA::Long theNodeStart,
2152 CORBA::Boolean theHasAngles,
2153 const SMESH::double_array & theAngles,
2154 CORBA::Boolean theHasRefPoint,
2155 const SMESH::PointStruct & theRefPoint)
2157 if ( !myPreviewMode ) {
2158 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
2159 << theObject << ", "
2160 << thePathMesh << ", "
2161 << thePathShape << ", "
2162 << theNodeStart << ", "
2163 << theHasAngles << ", "
2164 << theAngles << ", "
2165 << theHasRefPoint << ", "
2166 << "SMESH.PointStruct( "
2167 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2168 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2169 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2171 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2172 SMESH::long_array_var anElementsId = theObject->GetIDs();
2173 extrusionAlongPath( anElementsId,
2186 //=======================================================================
2187 //function : ExtrusionAlongPathObject1D
2189 //=======================================================================
2191 SMESH::SMESH_MeshEditor::Extrusion_Error
2192 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
2193 SMESH::SMESH_Mesh_ptr thePathMesh,
2194 GEOM::GEOM_Object_ptr thePathShape,
2195 CORBA::Long theNodeStart,
2196 CORBA::Boolean theHasAngles,
2197 const SMESH::double_array & theAngles,
2198 CORBA::Boolean theHasRefPoint,
2199 const SMESH::PointStruct & theRefPoint)
2201 if ( !myPreviewMode ) {
2202 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
2203 << theObject << ", "
2204 << thePathMesh << ", "
2205 << thePathShape << ", "
2206 << theNodeStart << ", "
2207 << theHasAngles << ", "
2208 << theAngles << ", "
2209 << theHasRefPoint << ", "
2210 << "SMESH.PointStruct( "
2211 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2212 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2213 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2215 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2216 SMESH::long_array_var anElementsId = theObject->GetIDs();
2217 extrusionAlongPath( anElementsId,
2231 //=======================================================================
2232 //function : ExtrusionAlongPathObject2D
2234 //=======================================================================
2236 SMESH::SMESH_MeshEditor::Extrusion_Error
2237 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
2238 SMESH::SMESH_Mesh_ptr thePathMesh,
2239 GEOM::GEOM_Object_ptr thePathShape,
2240 CORBA::Long theNodeStart,
2241 CORBA::Boolean theHasAngles,
2242 const SMESH::double_array & theAngles,
2243 CORBA::Boolean theHasRefPoint,
2244 const SMESH::PointStruct & theRefPoint)
2246 if ( !myPreviewMode ) {
2247 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
2248 << theObject << ", "
2249 << thePathMesh << ", "
2250 << thePathShape << ", "
2251 << theNodeStart << ", "
2252 << theHasAngles << ", "
2253 << theAngles << ", "
2254 << theHasRefPoint << ", "
2255 << "SMESH.PointStruct( "
2256 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2257 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2258 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2260 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2261 SMESH::long_array_var anElementsId = theObject->GetIDs();
2262 extrusionAlongPath( anElementsId,
2277 //=======================================================================
2278 //function : ExtrusionAlongPathMakeGroups
2280 //=======================================================================
2282 SMESH::ListOfGroups*
2283 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2284 SMESH::SMESH_Mesh_ptr thePathMesh,
2285 GEOM::GEOM_Object_ptr thePathShape,
2286 CORBA::Long theNodeStart,
2287 CORBA::Boolean theHasAngles,
2288 const SMESH::double_array& theAngles,
2289 CORBA::Boolean theHasRefPoint,
2290 const SMESH::PointStruct& theRefPoint,
2291 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2293 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2303 if ( !myPreviewMode ) {
2304 bool isDumpGroups = aGroups && aGroups->length() > 0;
2305 TPythonDump aPythonDump;
2307 aPythonDump << "("<<aGroups;
2310 aPythonDump << ", error)";
2312 aPythonDump <<"error";
2314 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2315 << theIDsOfElements << ", "
2316 << thePathMesh << ", "
2317 << thePathShape << ", "
2318 << theNodeStart << ", "
2319 << theHasAngles << ", "
2320 << theAngles << ", "
2321 << theHasRefPoint << ", "
2322 << "SMESH.PointStruct( "
2323 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2324 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2325 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2330 //=======================================================================
2331 //function : ExtrusionAlongPathObjectMakeGroups
2333 //=======================================================================
2335 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2336 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2337 SMESH::SMESH_Mesh_ptr thePathMesh,
2338 GEOM::GEOM_Object_ptr thePathShape,
2339 CORBA::Long theNodeStart,
2340 CORBA::Boolean theHasAngles,
2341 const SMESH::double_array& theAngles,
2342 CORBA::Boolean theHasRefPoint,
2343 const SMESH::PointStruct& theRefPoint,
2344 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2346 SMESH::long_array_var anElementsId = theObject->GetIDs();
2347 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2358 if ( !myPreviewMode ) {
2359 bool isDumpGroups = aGroups && aGroups->length() > 0;
2360 TPythonDump aPythonDump;
2362 aPythonDump << "("<<aGroups;
2365 aPythonDump << ", error)";
2367 aPythonDump <<"error";
2369 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2370 << theObject << ", "
2371 << thePathMesh << ", "
2372 << thePathShape << ", "
2373 << theNodeStart << ", "
2374 << theHasAngles << ", "
2375 << theAngles << ", "
2376 << theHasRefPoint << ", "
2377 << "SMESH.PointStruct( "
2378 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2379 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2380 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2385 //=======================================================================
2386 //function : ExtrusionAlongPathObject1DMakeGroups
2388 //=======================================================================
2390 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2391 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2392 SMESH::SMESH_Mesh_ptr thePathMesh,
2393 GEOM::GEOM_Object_ptr thePathShape,
2394 CORBA::Long theNodeStart,
2395 CORBA::Boolean theHasAngles,
2396 const SMESH::double_array& theAngles,
2397 CORBA::Boolean theHasRefPoint,
2398 const SMESH::PointStruct& theRefPoint,
2399 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2401 SMESH::long_array_var anElementsId = theObject->GetIDs();
2402 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2414 if ( !myPreviewMode ) {
2415 bool isDumpGroups = aGroups && aGroups->length() > 0;
2416 TPythonDump aPythonDump;
2418 aPythonDump << "("<<aGroups;
2421 aPythonDump << ", error)";
2423 aPythonDump <<"error";
2425 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
2426 << theObject << ", "
2427 << thePathMesh << ", "
2428 << thePathShape << ", "
2429 << theNodeStart << ", "
2430 << theHasAngles << ", "
2431 << theAngles << ", "
2432 << theHasRefPoint << ", "
2433 << "SMESH.PointStruct( "
2434 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2435 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2436 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2441 //=======================================================================
2442 //function : ExtrusionAlongPathObject2DMakeGroups
2444 //=======================================================================
2446 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2447 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2448 SMESH::SMESH_Mesh_ptr thePathMesh,
2449 GEOM::GEOM_Object_ptr thePathShape,
2450 CORBA::Long theNodeStart,
2451 CORBA::Boolean theHasAngles,
2452 const SMESH::double_array& theAngles,
2453 CORBA::Boolean theHasRefPoint,
2454 const SMESH::PointStruct& theRefPoint,
2455 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2457 SMESH::long_array_var anElementsId = theObject->GetIDs();
2458 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2470 if ( !myPreviewMode ) {
2471 bool isDumpGroups = aGroups && aGroups->length() > 0;
2472 TPythonDump aPythonDump;
2474 aPythonDump << "("<<aGroups;
2477 aPythonDump << ", error)";
2479 aPythonDump <<"error";
2481 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
2482 << theObject << ", "
2483 << thePathMesh << ", "
2484 << thePathShape << ", "
2485 << theNodeStart << ", "
2486 << theHasAngles << ", "
2487 << theAngles << ", "
2488 << theHasRefPoint << ", "
2489 << "SMESH.PointStruct( "
2490 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2491 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2492 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2498 //=======================================================================
2499 //function : ExtrusionAlongPathObjX
2501 //=======================================================================
2502 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2503 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
2504 SMESH::SMESH_IDSource_ptr Path,
2505 CORBA::Long NodeStart,
2506 CORBA::Boolean HasAngles,
2507 const SMESH::double_array& Angles,
2508 CORBA::Boolean LinearVariation,
2509 CORBA::Boolean HasRefPoint,
2510 const SMESH::PointStruct& RefPoint,
2511 CORBA::Boolean MakeGroups,
2512 SMESH::ElementType ElemType,
2513 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2515 SMESH::long_array_var anElementsId = Object->GetIDs();
2516 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2525 (SMDSAbs_ElementType)ElemType,
2528 if ( !myPreviewMode ) {
2529 bool isDumpGroups = aGroups && aGroups->length() > 0;
2530 TPythonDump aPythonDump;
2532 aPythonDump << "("<<aGroups;
2535 aPythonDump << ", error)";
2537 aPythonDump <<"error";
2539 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2542 << NodeStart << ", "
2543 << HasAngles << ", "
2545 << LinearVariation << ", "
2546 << HasRefPoint << ", "
2547 << "SMESH.PointStruct( "
2548 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2549 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2550 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2551 << MakeGroups << ", "
2552 << ElemType << " )";
2558 //=======================================================================
2559 //function : ExtrusionAlongPathX
2561 //=======================================================================
2562 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2563 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2564 SMESH::SMESH_IDSource_ptr Path,
2565 CORBA::Long NodeStart,
2566 CORBA::Boolean HasAngles,
2567 const SMESH::double_array& Angles,
2568 CORBA::Boolean LinearVariation,
2569 CORBA::Boolean HasRefPoint,
2570 const SMESH::PointStruct& RefPoint,
2571 CORBA::Boolean MakeGroups,
2572 SMESH::ElementType ElemType,
2573 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2575 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2584 (SMDSAbs_ElementType)ElemType,
2587 if ( !myPreviewMode ) {
2588 bool isDumpGroups = aGroups && aGroups->length() > 0;
2589 TPythonDump aPythonDump;
2591 aPythonDump << "("<<aGroups;
2594 aPythonDump << ", error)";
2596 aPythonDump <<"error";
2598 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2599 << IDsOfElements << ", "
2601 << NodeStart << ", "
2602 << HasAngles << ", "
2604 << LinearVariation << ", "
2605 << HasRefPoint << ", "
2606 << "SMESH.PointStruct( "
2607 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2608 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2609 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2610 << ElemType << " )";
2616 //================================================================================
2618 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2619 * of given angles along path steps
2620 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2621 * which proceeds the extrusion
2622 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2623 * is used to define the sub-mesh for the path
2625 //================================================================================
2627 SMESH::double_array*
2628 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2629 GEOM::GEOM_Object_ptr thePathShape,
2630 const SMESH::double_array & theAngles)
2632 SMESH::double_array_var aResult = new SMESH::double_array();
2633 int nbAngles = theAngles.length();
2634 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2636 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2637 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2638 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2639 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2640 return aResult._retn();
2641 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2642 if ( nbSteps == nbAngles )
2644 aResult.inout() = theAngles;
2648 aResult->length( nbSteps );
2649 double rAn2St = double( nbAngles ) / double( nbSteps );
2650 double angPrev = 0, angle;
2651 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2653 double angCur = rAn2St * ( iSt+1 );
2654 double angCurFloor = floor( angCur );
2655 double angPrevFloor = floor( angPrev );
2656 if ( angPrevFloor == angCurFloor )
2657 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2660 int iP = int( angPrevFloor );
2661 double angPrevCeil = ceil(angPrev);
2662 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2664 int iC = int( angCurFloor );
2665 if ( iC < nbAngles )
2666 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2668 iP = int( angPrevCeil );
2670 angle += theAngles[ iC ];
2672 aResult[ iSt ] = angle;
2677 // Update Python script
2678 TPythonDump() << "rotAngles = " << theAngles;
2679 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2680 << thePathMesh << ", "
2681 << thePathShape << ", "
2684 return aResult._retn();
2688 //=======================================================================
2691 //=======================================================================
2693 SMESH::ListOfGroups*
2694 SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
2695 const SMESH::AxisStruct & theAxis,
2696 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2697 CORBA::Boolean theCopy,
2698 const bool theMakeGroups,
2699 ::SMESH_Mesh* theTargetMesh)
2703 TIDSortedElemSet elements;
2704 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2706 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2707 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2710 switch ( theMirrorType ) {
2711 case SMESH::SMESH_MeshEditor::POINT:
2712 aTrsf.SetMirror( P );
2714 case SMESH::SMESH_MeshEditor::AXIS:
2715 aTrsf.SetMirror( gp_Ax1( P, V ));
2718 aTrsf.SetMirror( gp_Ax2( P, V ));
2721 ::SMESH_MeshEditor anEditor( myMesh );
2722 ::SMESH_MeshEditor::PGroupIDs groupIds =
2723 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2726 storeResult(anEditor);
2728 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2731 //=======================================================================
2734 //=======================================================================
2736 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2737 const SMESH::AxisStruct & theAxis,
2738 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2739 CORBA::Boolean theCopy)
2741 if ( !myPreviewMode ) {
2742 TPythonDump() << this << ".Mirror( "
2743 << theIDsOfElements << ", "
2745 << mirrorTypeName(theMirrorType) << ", "
2748 mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2752 //=======================================================================
2753 //function : MirrorObject
2755 //=======================================================================
2757 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2758 const SMESH::AxisStruct & theAxis,
2759 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2760 CORBA::Boolean theCopy)
2762 if ( !myPreviewMode ) {
2763 TPythonDump() << this << ".MirrorObject( "
2764 << theObject << ", "
2766 << mirrorTypeName(theMirrorType) << ", "
2769 SMESH::long_array_var anElementsId = theObject->GetIDs();
2770 mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2773 //=======================================================================
2774 //function : MirrorMakeGroups
2776 //=======================================================================
2778 SMESH::ListOfGroups*
2779 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2780 const SMESH::AxisStruct& theMirror,
2781 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2783 SMESH::ListOfGroups * aGroups = mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2784 if ( !myPreviewMode ) {
2785 TPythonDump aPythonDump;
2786 DumpGroupsList(aPythonDump,aGroups);
2787 aPythonDump << this << ".MirrorMakeGroups( "
2788 << theIDsOfElements << ", "
2789 << theMirror << ", "
2790 << mirrorTypeName(theMirrorType) << " )";
2795 //=======================================================================
2796 //function : MirrorObjectMakeGroups
2798 //=======================================================================
2800 SMESH::ListOfGroups*
2801 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2802 const SMESH::AxisStruct& theMirror,
2803 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2805 SMESH::long_array_var anElementsId = theObject->GetIDs();
2806 SMESH::ListOfGroups * aGroups = mirror(anElementsId, theMirror, theMirrorType, true, true);
2807 if ( !myPreviewMode ) {
2808 TPythonDump aPythonDump;
2809 DumpGroupsList(aPythonDump,aGroups);
2810 aPythonDump << this << ".MirrorObjectMakeGroups( "
2811 << theObject << ", "
2812 << theMirror << ", "
2813 << mirrorTypeName(theMirrorType) << " )";
2818 //=======================================================================
2819 //function : MirrorMakeMesh
2821 //=======================================================================
2823 SMESH::SMESH_Mesh_ptr
2824 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2825 const SMESH::AxisStruct& theMirror,
2826 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2827 CORBA::Boolean theCopyGroups,
2828 const char* theMeshName)
2830 SMESH_Mesh_i* mesh_i;
2831 SMESH::SMESH_Mesh_var mesh;
2832 { // open new scope to dump "MakeMesh" command
2833 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2835 TPythonDump pydump; // to prevent dump at mesh creation
2837 mesh = makeMesh( theMeshName );
2838 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2840 mirror(theIDsOfElements, theMirror, theMirrorType,
2841 false, theCopyGroups, & mesh_i->GetImpl());
2842 mesh_i->CreateGroupServants();
2845 if ( !myPreviewMode ) {
2846 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2847 << theIDsOfElements << ", "
2848 << theMirror << ", "
2849 << mirrorTypeName(theMirrorType) << ", "
2850 << theCopyGroups << ", '"
2851 << theMeshName << "' )";
2856 if(!myPreviewMode && mesh_i)
2857 mesh_i->GetGroups();
2859 return mesh._retn();
2862 //=======================================================================
2863 //function : MirrorObjectMakeMesh
2865 //=======================================================================
2867 SMESH::SMESH_Mesh_ptr
2868 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2869 const SMESH::AxisStruct& theMirror,
2870 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2871 CORBA::Boolean theCopyGroups,
2872 const char* theMeshName)
2874 SMESH_Mesh_i* mesh_i;
2875 SMESH::SMESH_Mesh_var mesh;
2876 { // open new scope to dump "MakeMesh" command
2877 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2879 TPythonDump pydump; // to prevent dump at mesh creation
2881 mesh = makeMesh( theMeshName );
2882 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2884 SMESH::long_array_var anElementsId = theObject->GetIDs();
2885 mirror(anElementsId, theMirror, theMirrorType,
2886 false, theCopyGroups, & mesh_i->GetImpl());
2887 mesh_i->CreateGroupServants();
2890 if ( !myPreviewMode ) {
2891 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
2892 << theObject << ", "
2893 << theMirror << ", "
2894 << mirrorTypeName(theMirrorType) << ", "
2895 << theCopyGroups << ", '"
2896 << theMeshName << "' )";
2901 if(!myPreviewMode && mesh_i)
2902 mesh_i->GetGroups();
2904 return mesh._retn();
2907 //=======================================================================
2908 //function : translate
2910 //=======================================================================
2912 SMESH::ListOfGroups*
2913 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2914 const SMESH::DirStruct & theVector,
2915 CORBA::Boolean theCopy,
2916 const bool theMakeGroups,
2917 ::SMESH_Mesh* theTargetMesh)
2921 TIDSortedElemSet elements;
2922 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2925 const SMESH::PointStruct * P = &theVector.PS;
2926 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2928 ::SMESH_MeshEditor anEditor( myMesh );
2929 ::SMESH_MeshEditor::PGroupIDs groupIds =
2930 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2933 storeResult(anEditor);
2935 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2938 //=======================================================================
2939 //function : Translate
2941 //=======================================================================
2943 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2944 const SMESH::DirStruct & theVector,
2945 CORBA::Boolean theCopy)
2947 if ( !myPreviewMode ) {
2948 TPythonDump() << this << ".Translate( "
2949 << theIDsOfElements << ", "
2950 << theVector << ", "
2953 translate(theIDsOfElements,
2959 //=======================================================================
2960 //function : TranslateObject
2962 //=======================================================================
2964 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
2965 const SMESH::DirStruct & theVector,
2966 CORBA::Boolean theCopy)
2968 if ( !myPreviewMode ) {
2969 TPythonDump() << this << ".TranslateObject( "
2970 << theObject << ", "
2971 << theVector << ", "
2974 SMESH::long_array_var anElementsId = theObject->GetIDs();
2975 translate(anElementsId,
2981 //=======================================================================
2982 //function : TranslateMakeGroups
2984 //=======================================================================
2986 SMESH::ListOfGroups*
2987 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
2988 const SMESH::DirStruct& theVector)
2990 SMESH::ListOfGroups * aGroups = translate(theIDsOfElements,theVector,true,true);
2991 if ( !myPreviewMode ) {
2992 TPythonDump aPythonDump;
2993 DumpGroupsList(aPythonDump,aGroups);
2994 aPythonDump << this << ".TranslateMakeGroups( "
2995 << theIDsOfElements << ", "
2996 << theVector << " )";
3001 //=======================================================================
3002 //function : TranslateObjectMakeGroups
3004 //=======================================================================
3006 SMESH::ListOfGroups*
3007 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3008 const SMESH::DirStruct& theVector)
3010 SMESH::long_array_var anElementsId = theObject->GetIDs();
3011 SMESH::ListOfGroups * aGroups = translate(anElementsId, theVector, true, true);
3013 if ( !myPreviewMode ) {
3015 TPythonDump aPythonDump;
3016 DumpGroupsList(aPythonDump,aGroups);
3017 aPythonDump << this << ".TranslateObjectMakeGroups( "
3018 << theObject << ", "
3019 << theVector << " )";
3024 //=======================================================================
3025 //function : TranslateMakeMesh
3027 //=======================================================================
3029 SMESH::SMESH_Mesh_ptr
3030 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3031 const SMESH::DirStruct& theVector,
3032 CORBA::Boolean theCopyGroups,
3033 const char* theMeshName)
3035 SMESH_Mesh_i* mesh_i;
3036 SMESH::SMESH_Mesh_var mesh;
3038 { // open new scope to dump "MakeMesh" command
3039 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3041 TPythonDump pydump; // to prevent dump at mesh creation
3043 mesh = makeMesh( theMeshName );
3044 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3047 translate(theIDsOfElements, theVector,
3048 false, theCopyGroups, & mesh_i->GetImpl());
3049 mesh_i->CreateGroupServants();
3052 if ( !myPreviewMode ) {
3053 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3054 << theIDsOfElements << ", "
3055 << theVector << ", "
3056 << theCopyGroups << ", '"
3057 << theMeshName << "' )";
3062 if(!myPreviewMode && mesh_i)
3063 mesh_i->GetGroups();
3065 return mesh._retn();
3068 //=======================================================================
3069 //function : TranslateObjectMakeMesh
3071 //=======================================================================
3073 SMESH::SMESH_Mesh_ptr
3074 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3075 const SMESH::DirStruct& theVector,
3076 CORBA::Boolean theCopyGroups,
3077 const char* theMeshName)
3079 SMESH_Mesh_i* mesh_i;
3080 SMESH::SMESH_Mesh_var mesh;
3081 { // open new scope to dump "MakeMesh" command
3082 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3084 TPythonDump pydump; // to prevent dump at mesh creation
3085 mesh = makeMesh( theMeshName );
3086 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3089 SMESH::long_array_var anElementsId = theObject->GetIDs();
3090 translate(anElementsId, theVector,
3091 false, theCopyGroups, & mesh_i->GetImpl());
3092 mesh_i->CreateGroupServants();
3094 if ( !myPreviewMode ) {
3095 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3096 << theObject << ", "
3097 << theVector << ", "
3098 << theCopyGroups << ", '"
3099 << theMeshName << "' )";
3104 if(!myPreviewMode && mesh_i)
3105 mesh_i->GetGroups();
3107 return mesh._retn();
3110 //=======================================================================
3113 //=======================================================================
3115 SMESH::ListOfGroups*
3116 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
3117 const SMESH::AxisStruct & theAxis,
3118 CORBA::Double theAngle,
3119 CORBA::Boolean theCopy,
3120 const bool theMakeGroups,
3121 ::SMESH_Mesh* theTargetMesh)
3125 TIDSortedElemSet elements;
3126 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3128 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3129 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3132 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3134 ::SMESH_MeshEditor anEditor( myMesh );
3135 ::SMESH_MeshEditor::PGroupIDs groupIds =
3136 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3139 storeResult(anEditor);
3141 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3144 //=======================================================================
3147 //=======================================================================
3149 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3150 const SMESH::AxisStruct & theAxis,
3151 CORBA::Double theAngle,
3152 CORBA::Boolean theCopy)
3154 if ( !myPreviewMode ) {
3155 TPythonDump() << this << ".Rotate( "
3156 << theIDsOfElements << ", "
3161 rotate(theIDsOfElements,
3168 //=======================================================================
3169 //function : RotateObject
3171 //=======================================================================
3173 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3174 const SMESH::AxisStruct & theAxis,
3175 CORBA::Double theAngle,
3176 CORBA::Boolean theCopy)
3178 if ( !myPreviewMode ) {
3179 TPythonDump() << this << ".RotateObject( "
3180 << theObject << ", "
3185 SMESH::long_array_var anElementsId = theObject->GetIDs();
3186 rotate(anElementsId,
3193 //=======================================================================
3194 //function : RotateMakeGroups
3196 //=======================================================================
3198 SMESH::ListOfGroups*
3199 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3200 const SMESH::AxisStruct& theAxis,
3201 CORBA::Double theAngle)
3203 SMESH::ListOfGroups * aGroups = rotate(theIDsOfElements,theAxis,theAngle,true,true);
3204 if ( !myPreviewMode ) {
3205 TPythonDump aPythonDump;
3206 DumpGroupsList(aPythonDump,aGroups);
3207 aPythonDump << this << ".RotateMakeGroups( "
3208 << theIDsOfElements << ", "
3210 << theAngle << " )";
3215 //=======================================================================
3216 //function : RotateObjectMakeGroups
3218 //=======================================================================
3220 SMESH::ListOfGroups*
3221 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3222 const SMESH::AxisStruct& theAxis,
3223 CORBA::Double theAngle)
3225 SMESH::long_array_var anElementsId = theObject->GetIDs();
3226 SMESH::ListOfGroups * aGroups = rotate(anElementsId,theAxis,theAngle,true,true);
3228 if ( !myPreviewMode ) {
3229 TPythonDump aPythonDump;
3230 DumpGroupsList(aPythonDump,aGroups);
3231 aPythonDump << this << ".RotateObjectMakeGroups( "
3232 << theObject << ", "
3234 << theAngle << " )";
3239 //=======================================================================
3240 //function : RotateMakeMesh
3242 //=======================================================================
3244 SMESH::SMESH_Mesh_ptr
3245 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3246 const SMESH::AxisStruct& theAxis,
3247 CORBA::Double theAngleInRadians,
3248 CORBA::Boolean theCopyGroups,
3249 const char* theMeshName)
3251 SMESH::SMESH_Mesh_var mesh;
3252 SMESH_Mesh_i* mesh_i;
3254 { // open new scope to dump "MakeMesh" command
3255 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3257 TPythonDump pydump; // to prevent dump at mesh creation
3259 mesh = makeMesh( theMeshName );
3260 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3263 rotate(theIDsOfElements, theAxis, theAngleInRadians,
3264 false, theCopyGroups, & mesh_i->GetImpl());
3265 mesh_i->CreateGroupServants();
3267 if ( !myPreviewMode ) {
3268 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3269 << theIDsOfElements << ", "
3271 << theAngleInRadians << ", "
3272 << theCopyGroups << ", '"
3273 << theMeshName << "' )";
3278 if(!myPreviewMode && mesh_i)
3279 mesh_i->GetGroups();
3281 return mesh._retn();
3284 //=======================================================================
3285 //function : RotateObjectMakeMesh
3287 //=======================================================================
3289 SMESH::SMESH_Mesh_ptr
3290 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3291 const SMESH::AxisStruct& theAxis,
3292 CORBA::Double theAngleInRadians,
3293 CORBA::Boolean theCopyGroups,
3294 const char* theMeshName)
3296 SMESH::SMESH_Mesh_var mesh;
3297 SMESH_Mesh_i* mesh_i;
3299 {// open new scope to dump "MakeMesh" command
3300 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3302 TPythonDump pydump; // to prevent dump at mesh creation
3303 mesh = makeMesh( theMeshName );
3304 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3307 SMESH::long_array_var anElementsId = theObject->GetIDs();
3308 rotate(anElementsId, theAxis, theAngleInRadians,
3309 false, theCopyGroups, & mesh_i->GetImpl());
3310 mesh_i->CreateGroupServants();
3312 if ( !myPreviewMode ) {
3313 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3314 << theObject << ", "
3316 << theAngleInRadians << ", "
3317 << theCopyGroups << ", '"
3318 << theMeshName << "' )";
3323 if(!myPreviewMode && mesh_i)
3324 mesh_i->GetGroups();
3326 return mesh._retn();
3330 //=======================================================================
3333 //=======================================================================
3335 SMESH::ListOfGroups*
3336 SMESH_MeshEditor_i::scale(const SMESH::long_array & theIDsOfElements,
3337 const SMESH::PointStruct& thePoint,
3338 const SMESH::double_array& theScaleFact,
3339 CORBA::Boolean theCopy,
3340 const bool theMakeGroups,
3341 ::SMESH_Mesh* theTargetMesh)
3345 TIDSortedElemSet elements;
3346 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3348 gp_Pnt aPnt( thePoint.x, thePoint.y, thePoint.z );
3349 list<double> aScaleFact;
3350 for (int i = 0; i < theScaleFact.length(); i++) {
3351 aScaleFact.push_back( theScaleFact[i] );
3354 ::SMESH_MeshEditor anEditor( myMesh );
3355 ::SMESH_MeshEditor::PGroupIDs groupIds =
3356 anEditor.Scale (elements, aPnt, aScaleFact, theCopy,
3357 theMakeGroups, theTargetMesh);
3360 storeResult(anEditor);
3362 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3366 //=======================================================================
3369 //=======================================================================
3371 void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr theObject,
3372 const SMESH::PointStruct& thePoint,
3373 const SMESH::double_array& theScaleFact,
3374 CORBA::Boolean theCopy)
3376 if ( !myPreviewMode ) {
3377 TPythonDump() << this << ".Scale( "
3378 << theObject << ", "
3379 << "SMESH.PointStruct( " << thePoint.x << ", "
3380 << thePoint.y << ", " << thePoint.z << " ) ,"
3381 << theScaleFact << ", "
3384 SMESH::long_array_var anElementsId = theObject->GetIDs();
3385 scale(anElementsId, thePoint, theScaleFact, theCopy, false);
3389 //=======================================================================
3390 //function : ScaleMakeGroups
3392 //=======================================================================
3394 SMESH::ListOfGroups*
3395 SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3396 const SMESH::PointStruct& thePoint,
3397 const SMESH::double_array& theScaleFact)
3399 SMESH::long_array_var anElementsId = theObject->GetIDs();
3400 SMESH::ListOfGroups * aGroups =
3401 scale(anElementsId, thePoint, theScaleFact, true, true);
3403 if ( !myPreviewMode ) {
3405 TPythonDump aPythonDump;
3406 DumpGroupsList(aPythonDump,aGroups);
3407 aPythonDump << this << ".Scale("
3409 << "SMESH.PointStruct(" <<thePoint.x << ","
3410 << thePoint.y << "," << thePoint.z << "),"
3411 << theScaleFact << ",True,True)";
3417 //=======================================================================
3418 //function : ScaleMakeMesh
3420 //=======================================================================
3422 SMESH::SMESH_Mesh_ptr
3423 SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3424 const SMESH::PointStruct& thePoint,
3425 const SMESH::double_array& theScaleFact,
3426 CORBA::Boolean theCopyGroups,
3427 const char* theMeshName)
3429 SMESH_Mesh_i* mesh_i;
3430 SMESH::SMESH_Mesh_var mesh;
3431 { // open new scope to dump "MakeMesh" command
3432 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3434 TPythonDump pydump; // to prevent dump at mesh creation
3435 mesh = makeMesh( theMeshName );
3436 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3439 SMESH::long_array_var anElementsId = theObject->GetIDs();
3440 scale(anElementsId, thePoint, theScaleFact,
3441 false, theCopyGroups, & mesh_i->GetImpl());
3442 mesh_i->CreateGroupServants();
3444 if ( !myPreviewMode ) {
3445 pydump << mesh << " = " << this << ".ScaleMakeMesh( "
3446 << theObject << ", "
3447 << "SMESH.PointStruct( " << thePoint.x << ", "
3448 << thePoint.y << ", " << thePoint.z << " ) ,"
3449 << theScaleFact << ", "
3450 << theCopyGroups << ", '"
3451 << theMeshName << "' )";
3456 if(!myPreviewMode && mesh_i)
3457 mesh_i->GetGroups();
3459 return mesh._retn();
3463 //=======================================================================
3464 //function : FindCoincidentNodes
3466 //=======================================================================
3468 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3469 SMESH::array_of_long_array_out GroupsOfNodes)
3473 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3474 ::SMESH_MeshEditor anEditor( myMesh );
3475 set<const SMDS_MeshNode*> nodes; // no input nodes
3476 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3478 GroupsOfNodes = new SMESH::array_of_long_array;
3479 GroupsOfNodes->length( aListOfListOfNodes.size() );
3480 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3481 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3482 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3483 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3484 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3485 aGroup.length( aListOfNodes.size() );
3486 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3487 aGroup[ j ] = (*lIt)->GetID();
3489 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3490 << Tolerance << " )";
3493 //=======================================================================
3494 //function : FindCoincidentNodesOnPart
3496 //=======================================================================
3497 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3498 CORBA::Double Tolerance,
3499 SMESH::array_of_long_array_out GroupsOfNodes)
3502 SMESH::long_array_var aElementsId = theObject->GetIDs();
3504 SMESHDS_Mesh* aMesh = GetMeshDS();
3505 set<const SMDS_MeshNode*> nodes;
3507 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
3508 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
3509 for(int i = 0; i < aElementsId->length(); i++) {
3510 CORBA::Long ind = aElementsId[i];
3511 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
3517 for(int i = 0; i < aElementsId->length(); i++) {
3518 CORBA::Long ind = aElementsId[i];
3519 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
3521 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
3522 while ( nIt->more() )
3523 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
3529 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3530 ::SMESH_MeshEditor anEditor( myMesh );
3532 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3534 GroupsOfNodes = new SMESH::array_of_long_array;
3535 GroupsOfNodes->length( aListOfListOfNodes.size() );
3536 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3537 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3538 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3539 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3540 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3541 aGroup.length( aListOfNodes.size() );
3542 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3543 aGroup[ j ] = (*lIt)->GetID();
3545 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3547 << Tolerance << " )";
3550 //=======================================================================
3551 //function : MergeNodes
3553 //=======================================================================
3555 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3559 SMESHDS_Mesh* aMesh = GetMeshDS();
3561 TPythonDump aTPythonDump;
3562 aTPythonDump << this << ".MergeNodes([";
3563 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3564 for (int i = 0; i < GroupsOfNodes.length(); i++)
3566 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3567 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3568 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3569 for ( int j = 0; j < aNodeGroup.length(); j++ )
3571 CORBA::Long index = aNodeGroup[ j ];
3572 const SMDS_MeshNode * node = aMesh->FindNode(index);
3574 aListOfNodes.push_back( node );
3576 if ( aListOfNodes.size() < 2 )
3577 aListOfListOfNodes.pop_back();
3579 if ( i > 0 ) aTPythonDump << ", ";
3580 aTPythonDump << aNodeGroup;
3582 ::SMESH_MeshEditor anEditor( myMesh );
3583 anEditor.MergeNodes( aListOfListOfNodes );
3585 aTPythonDump << "])";
3588 //=======================================================================
3589 //function : FindEqualElements
3591 //=======================================================================
3592 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3593 SMESH::array_of_long_array_out GroupsOfElementsID)
3596 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
3597 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
3598 typedef list<int> TListOfIDs;
3599 set<const SMDS_MeshElement*> elems;
3600 SMESH::long_array_var aElementsId = theObject->GetIDs();
3601 SMESHDS_Mesh* aMesh = GetMeshDS();
3603 for(int i = 0; i < aElementsId->length(); i++) {
3604 CORBA::Long anID = aElementsId[i];
3605 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3611 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3612 ::SMESH_MeshEditor anEditor( myMesh );
3613 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3615 GroupsOfElementsID = new SMESH::array_of_long_array;
3616 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3618 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3619 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3620 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3621 TListOfIDs& listOfIDs = *arraysIt;
3622 aGroup.length( listOfIDs.size() );
3623 TListOfIDs::iterator idIt = listOfIDs.begin();
3624 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3625 aGroup[ k ] = *idIt;
3629 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3634 //=======================================================================
3635 //function : MergeElements
3637 //=======================================================================
3639 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3643 TPythonDump aTPythonDump;
3644 aTPythonDump << this << ".MergeElements( [";
3646 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3648 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3649 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3650 aListOfListOfElementsID.push_back( list< int >() );
3651 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3652 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3653 CORBA::Long id = anElemsIDGroup[ j ];
3654 aListOfElemsID.push_back( id );
3656 if ( aListOfElemsID.size() < 2 )
3657 aListOfListOfElementsID.pop_back();
3658 if ( i > 0 ) aTPythonDump << ", ";
3659 aTPythonDump << anElemsIDGroup;
3662 ::SMESH_MeshEditor anEditor( myMesh );
3663 anEditor.MergeElements(aListOfListOfElementsID);
3665 aTPythonDump << "] )";
3668 //=======================================================================
3669 //function : MergeEqualElements
3671 //=======================================================================
3673 void SMESH_MeshEditor_i::MergeEqualElements()
3677 ::SMESH_MeshEditor anEditor( myMesh );
3678 anEditor.MergeEqualElements();
3680 TPythonDump() << this << ".MergeEqualElements()";
3683 //=============================================================================
3685 * Move the node to a given point
3687 //=============================================================================
3689 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
3694 initData(/*deleteSearchers=*/false);
3696 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
3700 if ( theNodeSearcher )
3701 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3703 if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3704 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3706 GetMeshDS()->MoveNode(node, x, y, z);
3708 // Update Python script
3709 TPythonDump() << "isDone = " << this << ".MoveNode( "
3710 << NodeID << ", " << x << ", " << y << ", " << z << " )";
3715 //================================================================================
3717 * \brief Return ID of node closest to a given point
3719 //================================================================================
3721 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
3725 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3727 if ( !theNodeSearcher ) {
3728 ::SMESH_MeshEditor anEditor( myMesh );
3729 theNodeSearcher = anEditor.GetNodeSearcher();
3732 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
3733 return node->GetID();
3738 //================================================================================
3740 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
3741 * move the node closest to the point to point's location and return ID of the node
3743 //================================================================================
3745 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
3748 CORBA::Long theNodeID)
3750 // We keep theNodeSearcher until any mesh modification:
3751 // 1) initData() deletes theNodeSearcher at any edition,
3752 // 2) TSearchersDeleter - at any mesh compute event and mesh change
3754 initData(/*deleteSearchers=*/false);
3756 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3758 int nodeID = theNodeID;
3759 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
3760 if ( !node ) // preview moving node
3762 if ( !theNodeSearcher ) {
3763 ::SMESH_MeshEditor anEditor( myMesh );
3764 theNodeSearcher = anEditor.GetNodeSearcher();
3767 node = theNodeSearcher->FindClosestTo( p );
3770 nodeID = node->GetID();
3771 if ( myPreviewMode ) // make preview data
3773 // in a preview mesh, make edges linked to a node
3774 TPreviewMesh tmpMesh;
3775 TIDSortedElemSet linkedNodes;
3776 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3777 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3778 for ( ; nIt != linkedNodes.end(); ++nIt )
3780 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
3781 tmpMesh.Copy( &edge );
3784 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
3786 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
3787 // fill preview data
3788 ::SMESH_MeshEditor anEditor( & tmpMesh );
3789 storeResult( anEditor );
3791 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3793 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3797 GetMeshDS()->MoveNode(node, x, y, z);
3801 if ( !myPreviewMode ) {
3802 TPythonDump() << "nodeID = " << this
3803 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
3804 << ", " << nodeID << " )";
3810 //=======================================================================
3812 * Return elements of given type where the given point is IN or ON.
3814 * 'ALL' type means elements of any type excluding nodes
3816 //=======================================================================
3818 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
3821 SMESH::ElementType type)
3823 SMESH::long_array_var res = new SMESH::long_array;
3824 vector< const SMDS_MeshElement* > foundElems;
3826 theSearchersDeleter.Set( myMesh );
3827 if ( !theElementSearcher ) {
3828 ::SMESH_MeshEditor anEditor( myMesh );
3829 theElementSearcher = anEditor.GetElementSearcher();
3831 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
3832 SMDSAbs_ElementType( type ),
3834 res->length( foundElems.size() );
3835 for ( int i = 0; i < foundElems.size(); ++i )
3836 res[i] = foundElems[i]->GetID();
3838 if ( !myPreviewMode ) // call from tui
3839 TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
3848 //=======================================================================
3849 //function : GetPointState
3850 //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
3851 // TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
3852 //=======================================================================
3854 CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
3858 theSearchersDeleter.Set( myMesh );
3859 if ( !theElementSearcher ) {
3860 ::SMESH_MeshEditor anEditor( myMesh );
3861 theElementSearcher = anEditor.GetElementSearcher();
3863 return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
3866 //=======================================================================
3867 //function : convError
3869 //=======================================================================
3871 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
3873 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
3877 RETCASE( SEW_BORDER1_NOT_FOUND );
3878 RETCASE( SEW_BORDER2_NOT_FOUND );
3879 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
3880 RETCASE( SEW_BAD_SIDE_NODES );
3881 RETCASE( SEW_VOLUMES_TO_SPLIT );
3882 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
3883 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
3884 RETCASE( SEW_BAD_SIDE1_NODES );
3885 RETCASE( SEW_BAD_SIDE2_NODES );
3887 return SMESH::SMESH_MeshEditor::SEW_OK;
3890 //=======================================================================
3891 //function : SewFreeBorders
3893 //=======================================================================
3895 SMESH::SMESH_MeshEditor::Sew_Error
3896 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
3897 CORBA::Long SecondNodeID1,
3898 CORBA::Long LastNodeID1,
3899 CORBA::Long FirstNodeID2,
3900 CORBA::Long SecondNodeID2,
3901 CORBA::Long LastNodeID2,
3902 CORBA::Boolean CreatePolygons,
3903 CORBA::Boolean CreatePolyedrs)
3907 SMESHDS_Mesh* aMesh = GetMeshDS();
3909 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3910 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3911 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3912 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3913 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3914 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
3916 if (!aBorderFirstNode ||
3917 !aBorderSecondNode||
3919 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3920 if (!aSide2FirstNode ||
3921 !aSide2SecondNode ||
3923 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3925 TPythonDump() << "error = " << this << ".SewFreeBorders( "
3926 << FirstNodeID1 << ", "
3927 << SecondNodeID1 << ", "
3928 << LastNodeID1 << ", "
3929 << FirstNodeID2 << ", "
3930 << SecondNodeID2 << ", "
3931 << LastNodeID2 << ", "
3932 << CreatePolygons<< ", "
3933 << CreatePolyedrs<< " )";
3935 ::SMESH_MeshEditor anEditor( myMesh );
3936 SMESH::SMESH_MeshEditor::Sew_Error error =
3937 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3947 storeResult(anEditor);
3953 //=======================================================================
3954 //function : SewConformFreeBorders
3956 //=======================================================================
3958 SMESH::SMESH_MeshEditor::Sew_Error
3959 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3960 CORBA::Long SecondNodeID1,
3961 CORBA::Long LastNodeID1,
3962 CORBA::Long FirstNodeID2,
3963 CORBA::Long SecondNodeID2)
3967 SMESHDS_Mesh* aMesh = GetMeshDS();
3969 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3970 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3971 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3972 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3973 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3974 const SMDS_MeshNode* aSide2ThirdNode = 0;
3976 if (!aBorderFirstNode ||
3977 !aBorderSecondNode||
3979 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3980 if (!aSide2FirstNode ||
3982 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3984 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
3985 << FirstNodeID1 << ", "
3986 << SecondNodeID1 << ", "
3987 << LastNodeID1 << ", "
3988 << FirstNodeID2 << ", "
3989 << SecondNodeID2 << " )";
3991 ::SMESH_MeshEditor anEditor( myMesh );
3992 SMESH::SMESH_MeshEditor::Sew_Error error =
3993 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4002 storeResult(anEditor);
4008 //=======================================================================
4009 //function : SewBorderToSide
4011 //=======================================================================
4013 SMESH::SMESH_MeshEditor::Sew_Error
4014 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
4015 CORBA::Long SecondNodeIDOnFreeBorder,
4016 CORBA::Long LastNodeIDOnFreeBorder,
4017 CORBA::Long FirstNodeIDOnSide,
4018 CORBA::Long LastNodeIDOnSide,
4019 CORBA::Boolean CreatePolygons,
4020 CORBA::Boolean CreatePolyedrs)
4024 SMESHDS_Mesh* aMesh = GetMeshDS();
4026 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
4027 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
4028 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
4029 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
4030 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
4031 const SMDS_MeshNode* aSide2ThirdNode = 0;
4033 if (!aBorderFirstNode ||
4034 !aBorderSecondNode||
4036 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4037 if (!aSide2FirstNode ||
4039 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
4041 TPythonDump() << "error = " << this << ".SewBorderToSide( "
4042 << FirstNodeIDOnFreeBorder << ", "
4043 << SecondNodeIDOnFreeBorder << ", "
4044 << LastNodeIDOnFreeBorder << ", "
4045 << FirstNodeIDOnSide << ", "
4046 << LastNodeIDOnSide << ", "
4047 << CreatePolygons << ", "
4048 << CreatePolyedrs << ") ";
4050 ::SMESH_MeshEditor anEditor( myMesh );
4051 SMESH::SMESH_MeshEditor::Sew_Error error =
4052 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4062 storeResult(anEditor);
4068 //=======================================================================
4069 //function : SewSideElements
4071 //=======================================================================
4073 SMESH::SMESH_MeshEditor::Sew_Error
4074 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
4075 const SMESH::long_array& IDsOfSide2Elements,
4076 CORBA::Long NodeID1OfSide1ToMerge,
4077 CORBA::Long NodeID1OfSide2ToMerge,
4078 CORBA::Long NodeID2OfSide1ToMerge,
4079 CORBA::Long NodeID2OfSide2ToMerge)
4083 SMESHDS_Mesh* aMesh = GetMeshDS();
4085 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
4086 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
4087 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
4088 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
4090 if (!aFirstNode1ToMerge ||
4091 !aFirstNode2ToMerge )
4092 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
4093 if (!aSecondNode1ToMerge||
4094 !aSecondNode2ToMerge)
4095 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
4097 TIDSortedElemSet aSide1Elems, aSide2Elems;
4098 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
4099 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
4101 TPythonDump() << "error = " << this << ".SewSideElements( "
4102 << IDsOfSide1Elements << ", "
4103 << IDsOfSide2Elements << ", "
4104 << NodeID1OfSide1ToMerge << ", "
4105 << NodeID1OfSide2ToMerge << ", "
4106 << NodeID2OfSide1ToMerge << ", "
4107 << NodeID2OfSide2ToMerge << ")";
4109 ::SMESH_MeshEditor anEditor( myMesh );
4110 SMESH::SMESH_MeshEditor::Sew_Error error =
4111 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
4114 aSecondNode1ToMerge,
4115 aSecondNode2ToMerge));
4117 storeResult(anEditor);
4122 //================================================================================
4124 * \brief Set new nodes for given element
4125 * \param ide - element id
4126 * \param newIDs - new node ids
4127 * \retval CORBA::Boolean - true if result is OK
4129 //================================================================================
4131 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
4132 const SMESH::long_array& newIDs)
4136 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
4137 if(!elem) return false;
4139 int nbn = newIDs.length();
4141 vector<const SMDS_MeshNode*> aNodes(nbn);
4144 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
4147 aNodes[nbn1] = aNode;
4150 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
4151 << ide << ", " << newIDs << " )";
4153 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
4156 //================================================================================
4158 * \brief Update myLastCreated* or myPreviewData
4159 * \param anEditor - it contains last modification results
4161 //================================================================================
4163 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
4165 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
4167 list<int> aNodesConnectivity;
4168 typedef map<int, int> TNodesMap;
4171 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
4172 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
4174 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
4175 int nbEdges = aMeshDS->NbEdges();
4176 int nbFaces = aMeshDS->NbFaces();
4177 int nbVolum = aMeshDS->NbVolumes();
4178 switch ( previewType ) {
4179 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
4180 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
4181 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
4184 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
4185 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
4187 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
4189 while ( itMeshElems->more() ) {
4190 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
4191 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
4194 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
4195 while ( itElemNodes->more() ) {
4196 const SMDS_MeshNode* aMeshNode =
4197 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
4198 int aNodeID = aMeshNode->GetID();
4199 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
4200 if ( anIter == nodesMap.end() ) {
4201 // filling the nodes coordinates
4202 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
4203 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
4204 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
4205 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4208 aNodesConnectivity.push_back(anIter->second);
4211 // filling the elements types
4212 SMDSAbs_ElementType aType;
4214 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4215 aType = SMDSAbs_Node;
4219 aType = aMeshElem->GetType();
4220 isPoly = aMeshElem->IsPoly();
4223 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4224 myPreviewData->elementTypes[i].isPoly = isPoly;
4225 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4229 myPreviewData->nodesXYZ.length( j );
4231 // filling the elements connectivities
4232 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4233 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4234 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4235 myPreviewData->elementConnectivities[i] = *aConnIter;
4241 // add new nodes into myLastCreatedNodes
4242 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4243 myLastCreatedNodes->length(aSeq.Length());
4244 for(int i=0; i<aSeq.Length(); i++)
4245 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4248 // add new elements into myLastCreatedElems
4249 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4250 myLastCreatedElems->length(aSeq.Length());
4251 for(int i=0; i<aSeq.Length(); i++)
4252 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4256 //================================================================================
4258 * Return data of mesh edition preview
4260 //================================================================================
4262 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4264 return myPreviewData._retn();
4267 //================================================================================
4269 * \brief Returns list of it's IDs of created nodes
4270 * \retval SMESH::long_array* - list of node ID
4272 //================================================================================
4274 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4276 return myLastCreatedNodes._retn();
4279 //================================================================================
4281 * \brief Returns list of it's IDs of created elements
4282 * \retval SMESH::long_array* - list of elements' ID
4284 //================================================================================
4286 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4288 return myLastCreatedElems._retn();
4291 //=======================================================================
4292 //function : ConvertToQuadratic
4294 //=======================================================================
4296 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4298 ::SMESH_MeshEditor anEditor( myMesh );
4299 anEditor.ConvertToQuadratic(theForce3d);
4300 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4303 //=======================================================================
4304 //function : ConvertFromQuadratic
4306 //=======================================================================
4308 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4310 ::SMESH_MeshEditor anEditor( myMesh );
4311 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4312 TPythonDump() << this << ".ConvertFromQuadratic()";
4316 //=======================================================================
4317 //function : makeMesh
4318 //purpose : create a named imported mesh
4319 //=======================================================================
4321 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4323 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4324 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4325 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4326 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4327 gen->SetName( meshSO, theMeshName, "Mesh" );
4328 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4330 return mesh._retn();
4333 //=======================================================================
4334 //function : DumpGroupsList
4336 //=======================================================================
4337 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4338 const SMESH::ListOfGroups * theGroupList)
4340 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4341 if(isDumpGroupList) {
4342 theDumpPython << theGroupList << " = ";
4346 //================================================================================
4348 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4349 \param theNodes - identifiers of nodes to be doubled
4350 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4351 nodes. If list of element identifiers is empty then nodes are doubled but
4352 they not assigned to elements
4353 \return TRUE if operation has been completed successfully, FALSE otherwise
4354 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4356 //================================================================================
4358 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4359 const SMESH::long_array& theModifiedElems )
4363 ::SMESH_MeshEditor aMeshEditor( myMesh );
4364 list< int > aListOfNodes;
4366 for ( i = 0, n = theNodes.length(); i < n; i++ )
4367 aListOfNodes.push_back( theNodes[ i ] );
4369 list< int > aListOfElems;
4370 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4371 aListOfElems.push_back( theModifiedElems[ i ] );
4373 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4375 storeResult( aMeshEditor) ;
4380 //================================================================================
4382 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4383 This method provided for convenience works as DoubleNodes() described above.
4384 \param theNodeId - identifier of node to be doubled.
4385 \param theModifiedElems - identifiers of elements to be updated.
4386 \return TRUE if operation has been completed successfully, FALSE otherwise
4387 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4389 //================================================================================
4391 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4392 const SMESH::long_array& theModifiedElems )
4394 SMESH::long_array_var aNodes = new SMESH::long_array;
4395 aNodes->length( 1 );
4396 aNodes[ 0 ] = theNodeId;
4397 return DoubleNodes( aNodes, theModifiedElems );
4400 //================================================================================
4402 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4403 This method provided for convenience works as DoubleNodes() described above.
4404 \param theNodes - group of nodes to be doubled.
4405 \param theModifiedElems - group of elements to be updated.
4406 \return TRUE if operation has been completed successfully, FALSE otherwise
4407 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
4409 //================================================================================
4411 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(
4412 SMESH::SMESH_GroupBase_ptr theNodes,
4413 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4415 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4418 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4419 SMESH::long_array_var aModifiedElems;
4420 if ( !CORBA::is_nil( theModifiedElems ) )
4421 aModifiedElems = theModifiedElems->GetListOfID();
4424 aModifiedElems = new SMESH::long_array;
4425 aModifiedElems->length( 0 );
4428 return DoubleNodes( aNodes, aModifiedElems );
4431 //================================================================================
4433 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4434 This method provided for convenience works as DoubleNodes() described above.
4435 \param theNodes - list of groups of nodes to be doubled
4436 \param theModifiedElems - list of groups of elements to be updated.
4437 \return TRUE if operation has been completed successfully, FALSE otherwise
4438 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
4440 //================================================================================
4442 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(
4443 const SMESH::ListOfGroups& theNodes,
4444 const SMESH::ListOfGroups& theModifiedElems )
4448 ::SMESH_MeshEditor aMeshEditor( myMesh );
4450 std::list< int > aNodes;
4452 for ( i = 0, n = theNodes.length(); i < n; i++ )
4454 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
4455 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
4457 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4458 for ( j = 0, m = aCurr->length(); j < m; j++ )
4459 aNodes.push_back( aCurr[ j ] );
4463 std::list< int > anElems;
4464 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4466 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
4467 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
4469 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4470 for ( j = 0, m = aCurr->length(); j < m; j++ )
4471 anElems.push_back( aCurr[ j ] );
4475 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
4477 storeResult( aMeshEditor) ;
4482 //================================================================================
4484 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4485 \param theElems - the list of elements (edges or faces) to be replicated
4486 The nodes for duplication could be found from these elements
4487 \param theNodesNot - list of nodes to NOT replicate
4488 \param theAffectedElems - the list of elements (cells and edges) to which the
4489 replicated nodes should be associated to.
4490 \return TRUE if operation has been completed successfully, FALSE otherwise
4491 \sa DoubleNodeGroup(), DoubleNodeGroups()
4493 //================================================================================
4495 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
4496 const SMESH::long_array& theNodesNot,
4497 const SMESH::long_array& theAffectedElems )
4502 ::SMESH_MeshEditor aMeshEditor( myMesh );
4504 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4505 TIDSortedElemSet anElems, aNodes, anAffected;
4506 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4507 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4508 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
4510 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4512 storeResult( aMeshEditor) ;
4514 // Update Python script
4515 TPythonDump() << "isDone = " << this << ".DoubleNodes( " << theElems << ", "
4516 << theNodesNot << ", " << theAffectedElems << " )";
4520 //================================================================================
4522 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4523 \param theElems - the list of elements (edges or faces) to be replicated
4524 The nodes for duplication could be found from these elements
4525 \param theNodesNot - list of nodes to NOT replicate
4526 \param theShape - shape to detect affected elements (element which geometric center
4527 located on or inside shape).
4528 The replicated nodes should be associated to affected elements.
4529 \return TRUE if operation has been completed successfully, FALSE otherwise
4530 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
4532 //================================================================================
4534 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion
4535 ( const SMESH::long_array& theElems,
4536 const SMESH::long_array& theNodesNot,
4537 GEOM::GEOM_Object_ptr theShape )
4542 ::SMESH_MeshEditor aMeshEditor( myMesh );
4544 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4545 TIDSortedElemSet anElems, aNodes;
4546 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4547 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4549 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4550 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4552 storeResult( aMeshEditor) ;
4554 // Update Python script
4555 TPythonDump() << "isDone = " << this << ".DoubleNodesInRegion( " << theElems << ", "
4556 << theNodesNot << ", " << theShape << " )";
4560 //================================================================================
4562 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4563 \param theElems - group of of elements (edges or faces) to be replicated
4564 \param theNodesNot - group of nodes not to replicated
4565 \param theAffectedElems - group of elements to which the replicated nodes
4566 should be associated to.
4567 \return TRUE if operation has been completed successfully, FALSE otherwise
4568 \sa DoubleNodes(), DoubleNodeGroups()
4570 //================================================================================
4572 static void groupToSet(SMESH::SMESH_GroupBase_ptr theGrp,
4573 SMESHDS_Mesh* theMeshDS,
4574 TIDSortedElemSet& theElemSet,
4575 const SMDSAbs_ElementType theType)
4578 if ( CORBA::is_nil( theGrp ) )
4580 SMESH::long_array_var anIDs = theGrp->GetIDs();
4581 arrayToSet( anIDs, theMeshDS, theElemSet, theType);
4584 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(
4585 SMESH::SMESH_GroupBase_ptr theElems,
4586 SMESH::SMESH_GroupBase_ptr theNodesNot,
4587 SMESH::SMESH_GroupBase_ptr theAffectedElems )
4590 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4595 ::SMESH_MeshEditor aMeshEditor( myMesh );
4597 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4598 TIDSortedElemSet anElems, aNodes, anAffected;
4599 groupToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4600 groupToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4601 groupToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
4603 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4605 storeResult( aMeshEditor) ;
4607 // Update Python script
4608 TPythonDump() << "isDone = " << this << ".DoubleNodeGroup( " << theElems << ", "
4609 << theNodesNot << ", " << theAffectedElems << " )";
4613 //================================================================================
4615 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4616 \param theElems - group of of elements (edges or faces) to be replicated
4617 \param theNodesNot - group of nodes not to replicated
4618 \param theShape - shape to detect affected elements (element which geometric center
4619 located on or inside shape).
4620 The replicated nodes should be associated to affected elements.
4621 \return TRUE if operation has been completed successfully, FALSE otherwise
4622 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
4624 //================================================================================
4626 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(
4627 SMESH::SMESH_GroupBase_ptr theElems,
4628 SMESH::SMESH_GroupBase_ptr theNodesNot,
4629 GEOM::GEOM_Object_ptr theShape )
4632 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4637 ::SMESH_MeshEditor aMeshEditor( myMesh );
4639 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4640 TIDSortedElemSet anElems, aNodes, anAffected;
4641 groupToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4642 groupToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4644 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4645 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4647 storeResult( aMeshEditor) ;
4649 // Update Python script
4650 TPythonDump() << "isDone = " << this << ".DoubleNodeGroupInRegion( " << theElems << ", "
4651 << theNodesNot << ", " << theShape << " )";
4655 //================================================================================
4657 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4658 This method provided for convenience works as DoubleNodes() described above.
4659 \param theElems - list of groups of elements (edges or faces) to be replicated
4660 \param theNodesNot - list of groups of nodes not to replicated
4661 \param theAffectedElems - group of elements to which the replicated nodes
4662 should be associated to.
4663 \return TRUE if operation has been completed successfully, FALSE otherwise
4664 \sa DoubleNodeGroup(), DoubleNodes()
4666 //================================================================================
4668 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
4669 SMESHDS_Mesh* theMeshDS,
4670 TIDSortedElemSet& theElemSet,
4671 const bool theIsNodeGrp)
4673 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
4675 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
4676 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
4677 : aGrp->GetType() != SMESH::NODE ) )
4679 SMESH::long_array_var anIDs = aGrp->GetIDs();
4680 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
4685 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(
4686 const SMESH::ListOfGroups& theElems,
4687 const SMESH::ListOfGroups& theNodesNot,
4688 const SMESH::ListOfGroups& theAffectedElems )
4692 ::SMESH_MeshEditor aMeshEditor( myMesh );
4694 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4695 TIDSortedElemSet anElems, aNodes, anAffected;
4696 listOfGroupToSet(theElems, aMeshDS, anElems, false );
4697 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
4698 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
4700 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4702 storeResult( aMeshEditor) ;
4704 // Update Python script
4705 TPythonDump() << "isDone = " << this << ".DoubleNodeGroups( " << &theElems << ", "
4706 << &theNodesNot << ", " << &theAffectedElems << " )";
4710 //================================================================================
4712 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4713 This method provided for convenience works as DoubleNodes() described above.
4714 \param theElems - list of groups of elements (edges or faces) to be replicated
4715 \param theNodesNot - list of groups of nodes not to replicated
4716 \param theShape - shape to detect affected elements (element which geometric center
4717 located on or inside shape).
4718 The replicated nodes should be associated to affected elements.
4719 \return TRUE if operation has been completed successfully, FALSE otherwise
4720 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
4722 //================================================================================
4724 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(
4725 const SMESH::ListOfGroups& theElems,
4726 const SMESH::ListOfGroups& theNodesNot,
4727 GEOM::GEOM_Object_ptr theShape )
4731 ::SMESH_MeshEditor aMeshEditor( myMesh );
4733 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4734 TIDSortedElemSet anElems, aNodes;
4735 listOfGroupToSet(theElems, aMeshDS, anElems,false );
4736 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
4738 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4739 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4741 storeResult( aMeshEditor) ;
4743 // Update Python script
4744 TPythonDump() << "isDone = " << this << ".DoubleNodeGroupsInRegion( " << &theElems << ", "
4745 << &theNodesNot << ", " << theShape << " )";
4749 //================================================================================
4751 \brief Generated skin mesh (containing 2D cells) from 3D mesh
4752 The created 2D mesh elements based on nodes of free faces of boundary volumes
4753 \return TRUE if operation has been completed successfully, FALSE otherwise
4755 //================================================================================
4757 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
4761 ::SMESH_MeshEditor aMeshEditor( myMesh );
4762 bool aResult = aMeshEditor.Make2DMeshFrom3D();
4763 storeResult( aMeshEditor) ;
4765 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";