1 // Copyright (C) 2007-2010 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
23 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 // File : SMESH_MeshEditor_i.cxx
25 // Author : Nicolas REJNERI
28 #include "SMESH_MeshEditor_i.hxx"
30 #include "SMDS_Mesh0DElement.hxx"
31 #include "SMDS_MeshEdge.hxx"
32 #include "SMDS_MeshFace.hxx"
33 #include "SMDS_MeshVolume.hxx"
34 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
35 #include "SMESH_MeshEditor.hxx"
36 #include "SMESH_subMeshEventListener.hxx"
37 #include "SMESH_Gen_i.hxx"
38 #include "SMESH_Filter_i.hxx"
39 #include "SMESH_subMesh_i.hxx"
40 #include "SMESH_Group_i.hxx"
41 #include "SMESH_PythonDump.hxx"
43 #include "utilities.h"
44 #include "Utils_ExceptHandlers.hxx"
45 #include "Utils_CorbaException.hxx"
47 #include <BRepAdaptor_Surface.hxx>
48 #include <BRep_Tool.hxx>
49 #include <TopExp_Explorer.hxx>
51 #include <TopoDS_Edge.hxx>
52 #include <TopoDS_Face.hxx>
57 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
61 #include <Standard_Failure.hxx>
64 #include <Standard_ErrorHandler.hxx>
69 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
72 using SMESH::TPythonDump;
76 //=============================================================================
78 * \brief Mesh to apply modifications for preview purposes
80 //=============================================================================
82 struct TPreviewMesh: public SMESH_Mesh
84 SMDSAbs_ElementType myPreviewType; // type to show
86 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
87 _isShapeToMesh = (_id =_studyId =_idDoc = 0);
88 _myMeshDS = new SMESHDS_Mesh( _id, true );
89 myPreviewType = previewElements;
92 virtual ~TPreviewMesh() { delete _myMeshDS; }
93 //!< Copy a set of elements
94 void Copy(const TIDSortedElemSet & theElements,
95 TIDSortedElemSet& theCopyElements,
96 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
97 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
99 // loop on theIDsOfElements
100 TIDSortedElemSet::const_iterator eIt = theElements.begin();
101 for ( ; eIt != theElements.end(); ++eIt )
103 const SMDS_MeshElement* anElem = *eIt;
104 if ( !anElem ) continue;
105 SMDSAbs_ElementType type = anElem->GetType();
106 if ( type == theAvoidType ||
107 ( theSelectType != SMDSAbs_All && type != theSelectType ))
110 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
111 theCopyElements.insert( theCopyElements.end(), anElemCopy );
115 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
117 // copy element nodes
118 int anElemNbNodes = anElem->NbNodes();
119 vector< int > anElemNodesID( anElemNbNodes ) ;
120 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
121 for ( int i = 0; itElemNodes->more(); i++)
123 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
125 anElemNodesID[i] = anElemNode->GetID();
128 // creates a corresponding element on copied nodes
129 SMDS_MeshElement* anElemCopy = 0;
130 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
132 const SMDS_PolyhedralVolumeOfNodes* ph =
133 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
135 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
136 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
139 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
146 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
148 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
149 anElemNode->GetID());
151 };// struct TPreviewMesh
153 static SMESH_NodeSearcher * theNodeSearcher = 0;
154 static SMESH_ElementSearcher * theElementSearcher = 0;
156 //=============================================================================
158 * \brief Deleter of theNodeSearcher at any compute event occured
160 //=============================================================================
162 struct TSearchersDeleter : public SMESH_subMeshEventListener
166 TSearchersDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
168 //!< Delete theNodeSearcher
171 if ( theNodeSearcher ) delete theNodeSearcher; theNodeSearcher = 0;
172 if ( theElementSearcher ) delete theElementSearcher; theElementSearcher = 0;
174 typedef map < int, SMESH_subMesh * > TDependsOnMap;
175 //!< The meshod called by submesh: do my main job
176 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
177 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
179 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
181 Unset( sm->GetFather() );
184 //!< set self on all submeshes and delete theNodeSearcher if other mesh is set
185 void Set(SMESH_Mesh* mesh)
187 if ( myMesh != mesh )
194 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
195 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
196 TDependsOnMap::const_iterator sm;
197 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
198 sm->second->SetEventListener( this, 0, sm->second );
202 //!< delete self from all submeshes
203 void Unset(SMESH_Mesh* mesh)
205 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
206 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
207 TDependsOnMap::const_iterator sm;
208 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
209 sm->second->DeleteEventListener( this );
214 } theSearchersDeleter;
216 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
218 TCollection_AsciiString typeStr;
219 switch ( theMirrorType ) {
220 case SMESH::SMESH_MeshEditor::POINT:
221 typeStr = "SMESH.SMESH_MeshEditor.POINT";
223 case SMESH::SMESH_MeshEditor::AXIS:
224 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
227 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
233 //=============================================================================
237 //=============================================================================
239 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
242 myMesh = & theMesh->GetImpl();
243 myPreviewMode = isPreview;
246 //================================================================================
250 //================================================================================
252 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
256 //================================================================================
258 * \brief Clear members
260 //================================================================================
262 void SMESH_MeshEditor_i::initData(bool deleteSearchers)
264 if ( myPreviewMode ) {
265 myPreviewData = new SMESH::MeshPreviewStruct();
268 myLastCreatedElems = new SMESH::long_array();
269 myLastCreatedNodes = new SMESH::long_array();
270 if ( deleteSearchers )
271 TSearchersDeleter::Delete();
275 //=======================================================================
276 //function : MakeIDSource
277 //purpose : Wrap a sequence of ids in a SMESH_IDSource
278 //=======================================================================
280 struct _IDSource : public POA_SMESH::SMESH_IDSource
282 SMESH::long_array _ids;
283 SMESH::long_array* GetIDs() { return new SMESH::long_array( _ids ); }
284 SMESH::long_array* GetMeshInfo() { return 0; }
287 SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_array& ids)
289 _IDSource* anIDSource = new _IDSource;
290 anIDSource->_ids = ids;
291 SMESH::SMESH_IDSource_var anIDSourceVar = anIDSource->_this();
293 return anIDSourceVar._retn();
296 //=============================================================================
300 //=============================================================================
303 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
307 ::SMESH_MeshEditor anEditor( myMesh );
310 for (int i = 0; i < IDsOfElements.length(); i++)
311 IdList.push_back( IDsOfElements[i] );
313 // Update Python script
314 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
316 return anEditor.Remove( IdList, false );
319 //=============================================================================
323 //=============================================================================
325 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
329 ::SMESH_MeshEditor anEditor( myMesh );
331 for (int i = 0; i < IDsOfNodes.length(); i++)
332 IdList.push_back( IDsOfNodes[i] );
334 // Update Python script
335 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
337 return anEditor.Remove( IdList, true );
340 //=============================================================================
344 //=============================================================================
346 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
347 CORBA::Double y, CORBA::Double z)
351 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
353 // Update Python script
354 TPythonDump() << "nodeID = " << this << ".AddNode( "
355 << x << ", " << y << ", " << z << " )";
360 //=============================================================================
364 //=============================================================================
365 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
369 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
370 SMDS_MeshElement* elem = GetMeshDS()->Add0DElement(aNode);
372 // Update Python script
373 TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
376 return elem->GetID();
381 //=============================================================================
385 //=============================================================================
387 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
391 int NbNodes = IDsOfNodes.length();
392 SMDS_MeshElement* elem = 0;
395 CORBA::Long index1 = IDsOfNodes[0];
396 CORBA::Long index2 = IDsOfNodes[1];
397 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
399 // Update Python script
400 TPythonDump() << "edge = " << this << ".AddEdge([ "
401 << index1 << ", " << index2 <<" ])";
404 CORBA::Long n1 = IDsOfNodes[0];
405 CORBA::Long n2 = IDsOfNodes[1];
406 CORBA::Long n12 = IDsOfNodes[2];
407 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
408 GetMeshDS()->FindNode(n2),
409 GetMeshDS()->FindNode(n12));
410 // Update Python script
411 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
412 <<n1<<", "<<n2<<", "<<n12<<" ])";
416 return elem->GetID();
421 //=============================================================================
425 //=============================================================================
427 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
431 int NbNodes = IDsOfNodes.length();
437 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
438 for (int i = 0; i < NbNodes; i++)
439 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
441 SMDS_MeshElement* elem = 0;
443 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
445 else if (NbNodes == 4) {
446 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
448 else if (NbNodes == 6) {
449 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
452 else if (NbNodes == 8) {
453 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
454 nodes[4], nodes[5], nodes[6], nodes[7]);
456 else if (NbNodes > 2) {
457 elem = GetMeshDS()->AddPolygonalFace(nodes);
460 // Update Python script
461 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
464 return elem->GetID();
469 //=============================================================================
473 //=============================================================================
474 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsOfNodes)
478 int NbNodes = IDsOfNodes.length();
479 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
480 for (int i = 0; i < NbNodes; i++)
481 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
483 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
485 // Update Python script
486 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
488 return elem ? elem->GetID() : 0;
491 //=============================================================================
495 //=============================================================================
497 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
501 int NbNodes = IDsOfNodes.length();
502 vector< const SMDS_MeshNode*> n(NbNodes);
503 for(int i=0;i<NbNodes;i++)
504 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
506 SMDS_MeshElement* elem = 0;
509 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
510 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
511 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
512 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
513 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
514 n[6],n[7],n[8],n[9]);
516 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
517 n[7],n[8],n[9],n[10],n[11],n[12]);
519 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
520 n[9],n[10],n[11],n[12],n[13],n[14]);
522 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
523 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
524 n[15],n[16],n[17],n[18],n[19]);
528 // Update Python script
529 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
532 return elem->GetID();
537 //=============================================================================
539 * AddPolyhedralVolume
541 //=============================================================================
542 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume (const SMESH::long_array & IDsOfNodes,
543 const SMESH::long_array & Quantities)
547 int NbNodes = IDsOfNodes.length();
548 std::vector<const SMDS_MeshNode*> n (NbNodes);
549 for (int i = 0; i < NbNodes; i++)
550 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
552 int NbFaces = Quantities.length();
553 std::vector<int> q (NbFaces);
554 for (int j = 0; j < NbFaces; j++)
555 q[j] = Quantities[j];
557 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
559 // Update Python script
560 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
561 << IDsOfNodes << ", " << Quantities << " )";
563 return elem ? elem->GetID() : 0;
566 //=============================================================================
568 * AddPolyhedralVolumeByFaces
570 //=============================================================================
571 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_array & IdsOfFaces)
575 int NbFaces = IdsOfFaces.length();
576 std::vector<const SMDS_MeshNode*> poly_nodes;
577 std::vector<int> quantities (NbFaces);
579 for (int i = 0; i < NbFaces; i++) {
580 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
581 quantities[i] = aFace->NbNodes();
583 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
585 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
589 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
591 // Update Python script
592 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
593 << IdsOfFaces << " )";
595 return elem ? elem->GetID() : 0;
598 //=============================================================================
600 * \brief Bind a node to a vertex
601 * \param NodeID - node ID
602 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
603 * \retval boolean - false if NodeID or VertexID is invalid
605 //=============================================================================
607 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
608 throw (SALOME::SALOME_Exception)
610 Unexpect aCatch(SALOME_SalomeException);
612 SMESHDS_Mesh * mesh = GetMeshDS();
613 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
615 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
617 if ( mesh->MaxShapeIndex() < VertexID )
618 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
620 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
621 if ( shape.ShapeType() != TopAbs_VERTEX )
622 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
624 mesh->SetNodeOnVertex( node, VertexID );
627 //=============================================================================
629 * \brief Store node position on an edge
630 * \param NodeID - node ID
631 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
632 * \param paramOnEdge - parameter on edge where the node is located
633 * \retval boolean - false if any parameter is invalid
635 //=============================================================================
637 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
638 CORBA::Double paramOnEdge)
639 throw (SALOME::SALOME_Exception)
641 Unexpect aCatch(SALOME_SalomeException);
643 SMESHDS_Mesh * mesh = GetMeshDS();
644 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
646 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
648 if ( mesh->MaxShapeIndex() < EdgeID )
649 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
651 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
652 if ( shape.ShapeType() != TopAbs_EDGE )
653 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
656 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
657 if ( paramOnEdge < f || paramOnEdge > l )
658 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
660 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
663 //=============================================================================
665 * \brief Store node position on a face
666 * \param NodeID - node ID
667 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
668 * \param u - U parameter on face where the node is located
669 * \param v - V parameter on face where the node is located
670 * \retval boolean - false if any parameter is invalid
672 //=============================================================================
674 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
675 CORBA::Double u, CORBA::Double v)
676 throw (SALOME::SALOME_Exception)
678 Unexpect aCatch(SALOME_SalomeException);
680 SMESHDS_Mesh * mesh = GetMeshDS();
681 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
683 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
685 if ( mesh->MaxShapeIndex() < FaceID )
686 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
688 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
689 if ( shape.ShapeType() != TopAbs_FACE )
690 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
692 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
693 bool isOut = ( u < surf.FirstUParameter() ||
694 u > surf.LastUParameter() ||
695 v < surf.FirstVParameter() ||
696 v > surf.LastVParameter() );
700 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
701 << " u( " << surf.FirstUParameter()
702 << "," << surf.LastUParameter()
703 << ") v( " << surf.FirstVParameter()
704 << "," << surf.LastVParameter() << ")" );
706 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
709 mesh->SetNodeOnFace( node, FaceID, u, v );
712 //=============================================================================
714 * \brief Bind a node to a solid
715 * \param NodeID - node ID
716 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
717 * \retval boolean - false if NodeID or SolidID is invalid
719 //=============================================================================
721 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
722 throw (SALOME::SALOME_Exception)
724 Unexpect aCatch(SALOME_SalomeException);
726 SMESHDS_Mesh * mesh = GetMeshDS();
727 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
729 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
731 if ( mesh->MaxShapeIndex() < SolidID )
732 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
734 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
735 if ( shape.ShapeType() != TopAbs_SOLID &&
736 shape.ShapeType() != TopAbs_SHELL)
737 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
739 mesh->SetNodeInVolume( node, SolidID );
742 //=============================================================================
744 * \brief Bind an element to a shape
745 * \param ElementID - element ID
746 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
747 * \retval boolean - false if ElementID or ShapeID is invalid
749 //=============================================================================
751 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
753 throw (SALOME::SALOME_Exception)
755 Unexpect aCatch(SALOME_SalomeException);
757 SMESHDS_Mesh * mesh = GetMeshDS();
758 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
760 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
762 if ( mesh->MaxShapeIndex() < ShapeID )
763 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
765 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
766 if ( shape.ShapeType() != TopAbs_EDGE &&
767 shape.ShapeType() != TopAbs_FACE &&
768 shape.ShapeType() != TopAbs_SOLID &&
769 shape.ShapeType() != TopAbs_SHELL )
770 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
772 mesh->SetMeshElementOnShape( elem, ShapeID );
775 //=============================================================================
779 //=============================================================================
781 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
786 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
787 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
791 // Update Python script
792 TPythonDump() << "isDone = " << this << ".InverseDiag( "
793 << NodeID1 << ", " << NodeID2 << " )";
795 ::SMESH_MeshEditor aMeshEditor( myMesh );
796 return aMeshEditor.InverseDiag ( n1, n2 );
799 //=============================================================================
803 //=============================================================================
805 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
810 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
811 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
815 // Update Python script
816 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
817 << NodeID1 << ", " << NodeID2 << " )";
819 ::SMESH_MeshEditor aMeshEditor( myMesh );
821 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
823 storeResult(aMeshEditor);
828 //=============================================================================
832 //=============================================================================
834 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
838 ::SMESH_MeshEditor anEditor( myMesh );
839 for (int i = 0; i < IDsOfElements.length(); i++)
841 CORBA::Long index = IDsOfElements[i];
842 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
844 anEditor.Reorient( elem );
846 // Update Python script
847 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
853 //=============================================================================
857 //=============================================================================
859 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
863 SMESH::long_array_var anElementsId = theObject->GetIDs();
864 CORBA::Boolean isDone = Reorient(anElementsId);
866 // Clear python line, created by Reorient()
867 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
868 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
870 // Update Python script
871 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
878 //================================================================================
880 * \brief function for conversion long_array to TIDSortedElemSet
881 * \param IDs - array of IDs
882 * \param aMesh - mesh
883 * \param aMap - collection to fill
884 * \param aType - element type
886 //================================================================================
888 void arrayToSet(const SMESH::long_array & IDs,
889 const SMESHDS_Mesh* aMesh,
890 TIDSortedElemSet& aMap,
891 const SMDSAbs_ElementType aType = SMDSAbs_All )
893 for (int i=0; i<IDs.length(); i++) {
894 CORBA::Long ind = IDs[i];
895 const SMDS_MeshElement * elem =
896 (aType == SMDSAbs_Node ? aMesh->FindNode(ind)
897 : aMesh->FindElement(ind));
898 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
904 //=============================================================================
908 //=============================================================================
909 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
910 SMESH::NumericalFunctor_ptr Criterion,
911 CORBA::Double MaxAngle)
915 SMESHDS_Mesh* aMesh = GetMeshDS();
916 TIDSortedElemSet faces;
917 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
919 SMESH::NumericalFunctor_i* aNumericalFunctor =
920 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
921 SMESH::Controls::NumericalFunctorPtr aCrit;
922 if ( !aNumericalFunctor )
923 aCrit.reset( new SMESH::Controls::AspectRatio() );
925 aCrit = aNumericalFunctor->GetNumericalFunctor();
927 // Update Python script
928 TPythonDump() << "isDone = " << this << ".TriToQuad( "
929 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
931 ::SMESH_MeshEditor anEditor( myMesh );
933 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
935 storeResult(anEditor);
941 //=============================================================================
945 //=============================================================================
946 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
947 SMESH::NumericalFunctor_ptr Criterion,
948 CORBA::Double MaxAngle)
952 SMESH::long_array_var anElementsId = theObject->GetIDs();
953 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
955 // Clear python line(s), created by TriToQuad()
956 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
957 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
959 SMESH::NumericalFunctor_i* aNumericalFunctor =
960 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
962 // Update Python script
963 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
964 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
970 //=============================================================================
974 //=============================================================================
975 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
976 SMESH::NumericalFunctor_ptr Criterion)
980 SMESHDS_Mesh* aMesh = GetMeshDS();
981 TIDSortedElemSet faces;
982 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
984 SMESH::NumericalFunctor_i* aNumericalFunctor =
985 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
986 SMESH::Controls::NumericalFunctorPtr aCrit;
987 if ( !aNumericalFunctor )
988 aCrit.reset( new SMESH::Controls::AspectRatio() );
990 aCrit = aNumericalFunctor->GetNumericalFunctor();
993 // Update Python script
994 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
996 ::SMESH_MeshEditor anEditor( myMesh );
997 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
999 storeResult(anEditor);
1005 //=============================================================================
1009 //=============================================================================
1010 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1011 SMESH::NumericalFunctor_ptr Criterion)
1015 SMESH::long_array_var anElementsId = theObject->GetIDs();
1016 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1018 // Clear python line(s), created by QuadToTri()
1019 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1020 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1022 SMESH::NumericalFunctor_i* aNumericalFunctor =
1023 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1025 // Update Python script
1026 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1032 //=============================================================================
1036 //=============================================================================
1037 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1038 CORBA::Boolean Diag13)
1042 SMESHDS_Mesh* aMesh = GetMeshDS();
1043 TIDSortedElemSet faces;
1044 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1046 // Update Python script
1047 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1048 << IDsOfElements << ", " << Diag13 << " )";
1050 ::SMESH_MeshEditor anEditor( myMesh );
1051 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1053 storeResult(anEditor);
1059 //=============================================================================
1063 //=============================================================================
1064 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1065 CORBA::Boolean Diag13)
1069 SMESH::long_array_var anElementsId = theObject->GetIDs();
1070 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1072 // Clear python line(s), created by SplitQuad()
1073 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1074 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1076 // Update Python script
1077 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1078 << theObject << ", " << Diag13 << " )";
1084 //=============================================================================
1088 //=============================================================================
1089 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1090 SMESH::NumericalFunctor_ptr Criterion)
1092 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1093 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1095 SMESH::NumericalFunctor_i* aNumericalFunctor =
1096 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1097 SMESH::Controls::NumericalFunctorPtr aCrit;
1098 if (aNumericalFunctor)
1099 aCrit = aNumericalFunctor->GetNumericalFunctor();
1101 aCrit.reset(new SMESH::Controls::AspectRatio());
1103 ::SMESH_MeshEditor anEditor (myMesh);
1104 return anEditor.BestSplit(quad, aCrit);
1109 //================================================================================
1111 * \brief Split volumic elements into tetrahedrons
1113 //================================================================================
1115 void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems,
1116 CORBA::Short methodFlags)
1117 throw (SALOME::SALOME_Exception)
1119 Unexpect aCatch(SALOME_SalomeException);
1121 SMESH::long_array_var anElementsId = elems->GetIDs();
1122 TIDSortedElemSet elemSet;
1123 arrayToSet( anElementsId, GetMeshDS(), elemSet, SMDSAbs_Volume );
1125 ::SMESH_MeshEditor anEditor (myMesh);
1126 anEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags ));
1128 TPythonDump() << this << ".SplitVolumesIntoTetra( "
1129 << elems << ", " << methodFlags << " )";
1132 //=======================================================================
1135 //=======================================================================
1138 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1139 const SMESH::long_array & IDsOfFixedNodes,
1140 CORBA::Long MaxNbOfIterations,
1141 CORBA::Double MaxAspectRatio,
1142 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1144 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1145 MaxAspectRatio, Method, false );
1149 //=======================================================================
1150 //function : SmoothParametric
1152 //=======================================================================
1155 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1156 const SMESH::long_array & IDsOfFixedNodes,
1157 CORBA::Long MaxNbOfIterations,
1158 CORBA::Double MaxAspectRatio,
1159 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1161 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1162 MaxAspectRatio, Method, true );
1166 //=======================================================================
1167 //function : SmoothObject
1169 //=======================================================================
1172 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1173 const SMESH::long_array & IDsOfFixedNodes,
1174 CORBA::Long MaxNbOfIterations,
1175 CORBA::Double MaxAspectRatio,
1176 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1178 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1179 MaxAspectRatio, Method, false);
1183 //=======================================================================
1184 //function : SmoothParametricObject
1186 //=======================================================================
1189 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1190 const SMESH::long_array & IDsOfFixedNodes,
1191 CORBA::Long MaxNbOfIterations,
1192 CORBA::Double MaxAspectRatio,
1193 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1195 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1196 MaxAspectRatio, Method, true);
1200 //=============================================================================
1204 //=============================================================================
1207 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1208 const SMESH::long_array & IDsOfFixedNodes,
1209 CORBA::Long MaxNbOfIterations,
1210 CORBA::Double MaxAspectRatio,
1211 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1216 SMESHDS_Mesh* aMesh = GetMeshDS();
1218 TIDSortedElemSet elements;
1219 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1221 set<const SMDS_MeshNode*> fixedNodes;
1222 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1223 CORBA::Long index = IDsOfFixedNodes[i];
1224 const SMDS_MeshNode * node = aMesh->FindNode(index);
1226 fixedNodes.insert( node );
1228 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1229 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1230 method = ::SMESH_MeshEditor::CENTROIDAL;
1232 ::SMESH_MeshEditor anEditor( myMesh );
1233 anEditor.Smooth(elements, fixedNodes, method,
1234 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1236 storeResult(anEditor);
1238 // Update Python script
1239 TPythonDump() << "isDone = " << this << "."
1240 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1241 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1242 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1243 << "SMESH.SMESH_MeshEditor."
1244 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1245 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1251 //=============================================================================
1255 //=============================================================================
1258 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1259 const SMESH::long_array & IDsOfFixedNodes,
1260 CORBA::Long MaxNbOfIterations,
1261 CORBA::Double MaxAspectRatio,
1262 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1267 SMESH::long_array_var anElementsId = theObject->GetIDs();
1268 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1269 MaxAspectRatio, Method, IsParametric);
1271 // Clear python line(s), created by Smooth()
1272 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1273 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1275 // Update Python script
1276 TPythonDump() << "isDone = " << this << "."
1277 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1278 << theObject << ", " << IDsOfFixedNodes << ", "
1279 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1280 << "SMESH.SMESH_MeshEditor."
1281 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1282 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1288 //=============================================================================
1292 //=============================================================================
1294 void SMESH_MeshEditor_i::RenumberNodes()
1296 // Update Python script
1297 TPythonDump() << this << ".RenumberNodes()";
1299 GetMeshDS()->Renumber( true );
1303 //=============================================================================
1307 //=============================================================================
1309 void SMESH_MeshEditor_i::RenumberElements()
1311 // Update Python script
1312 TPythonDump() << this << ".RenumberElements()";
1314 GetMeshDS()->Renumber( false );
1317 //=======================================================================
1319 * \brief Return groups by their IDs
1321 //=======================================================================
1323 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1327 myMesh_i->CreateGroupServants();
1328 return myMesh_i->GetGroups( *groupIDs );
1331 //=======================================================================
1332 //function : rotationSweep
1334 //=======================================================================
1336 SMESH::ListOfGroups*
1337 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1338 const SMESH::AxisStruct & theAxis,
1339 CORBA::Double theAngleInRadians,
1340 CORBA::Long theNbOfSteps,
1341 CORBA::Double theTolerance,
1342 const bool theMakeGroups,
1343 const SMDSAbs_ElementType theElementType)
1347 TIDSortedElemSet inElements, copyElements;
1348 arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType);
1350 TIDSortedElemSet* workElements = & inElements;
1351 TPreviewMesh tmpMesh( SMDSAbs_Face );
1352 SMESH_Mesh* mesh = 0;
1353 bool makeWalls=true;
1354 if ( myPreviewMode )
1356 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1357 tmpMesh.Copy( inElements, copyElements, select, avoid );
1359 workElements = & copyElements;
1360 //makeWalls = false;
1367 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1368 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1370 ::SMESH_MeshEditor anEditor( mesh );
1371 ::SMESH_MeshEditor::PGroupIDs groupIds =
1372 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1373 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1374 storeResult(anEditor);
1376 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1379 //=======================================================================
1380 //function : RotationSweep
1382 //=======================================================================
1384 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1385 const SMESH::AxisStruct & theAxis,
1386 CORBA::Double theAngleInRadians,
1387 CORBA::Long theNbOfSteps,
1388 CORBA::Double theTolerance)
1390 if ( !myPreviewMode ) {
1391 TPythonDump() << this << ".RotationSweep( "
1392 << theIDsOfElements << ", "
1394 << theAngleInRadians << ", "
1395 << theNbOfSteps << ", "
1396 << theTolerance << " )";
1398 rotationSweep(theIDsOfElements,
1406 //=======================================================================
1407 //function : RotationSweepMakeGroups
1409 //=======================================================================
1411 SMESH::ListOfGroups*
1412 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1413 const SMESH::AxisStruct& theAxis,
1414 CORBA::Double theAngleInRadians,
1415 CORBA::Long theNbOfSteps,
1416 CORBA::Double theTolerance)
1418 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1424 if ( !myPreviewMode ) {
1425 TPythonDump aPythonDump;
1426 DumpGroupsList(aPythonDump,aGroups);
1427 aPythonDump<< this << ".RotationSweepMakeGroups( "
1428 << theIDsOfElements << ", "
1430 << theAngleInRadians << ", "
1431 << theNbOfSteps << ", "
1432 << theTolerance << " )";
1437 //=======================================================================
1438 //function : RotationSweepObject
1440 //=======================================================================
1442 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1443 const SMESH::AxisStruct & theAxis,
1444 CORBA::Double theAngleInRadians,
1445 CORBA::Long theNbOfSteps,
1446 CORBA::Double theTolerance)
1448 if ( !myPreviewMode ) {
1449 TPythonDump() << this << ".RotationSweepObject( "
1450 << theObject << ", "
1452 << theAngleInRadians << ", "
1453 << theNbOfSteps << ", "
1454 << theTolerance << " )";
1456 SMESH::long_array_var anElementsId = theObject->GetIDs();
1457 rotationSweep(anElementsId,
1465 //=======================================================================
1466 //function : RotationSweepObject1D
1468 //=======================================================================
1470 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1471 const SMESH::AxisStruct & theAxis,
1472 CORBA::Double theAngleInRadians,
1473 CORBA::Long theNbOfSteps,
1474 CORBA::Double theTolerance)
1476 if ( !myPreviewMode ) {
1477 TPythonDump() << this << ".RotationSweepObject1D( "
1478 << theObject << ", "
1480 << theAngleInRadians << ", "
1481 << theNbOfSteps << ", "
1482 << theTolerance << " )";
1484 SMESH::long_array_var anElementsId = theObject->GetIDs();
1485 rotationSweep(anElementsId,
1494 //=======================================================================
1495 //function : RotationSweepObject2D
1497 //=======================================================================
1499 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1500 const SMESH::AxisStruct & theAxis,
1501 CORBA::Double theAngleInRadians,
1502 CORBA::Long theNbOfSteps,
1503 CORBA::Double theTolerance)
1505 if ( !myPreviewMode ) {
1506 TPythonDump() << this << ".RotationSweepObject2D( "
1507 << theObject << ", "
1509 << theAngleInRadians << ", "
1510 << theNbOfSteps << ", "
1511 << theTolerance << " )";
1513 SMESH::long_array_var anElementsId = theObject->GetIDs();
1514 rotationSweep(anElementsId,
1523 //=======================================================================
1524 //function : RotationSweepObjectMakeGroups
1526 //=======================================================================
1528 SMESH::ListOfGroups*
1529 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1530 const SMESH::AxisStruct& theAxis,
1531 CORBA::Double theAngleInRadians,
1532 CORBA::Long theNbOfSteps,
1533 CORBA::Double theTolerance)
1535 SMESH::long_array_var anElementsId = theObject->GetIDs();
1536 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1542 if ( !myPreviewMode ) {
1543 TPythonDump aPythonDump;
1544 DumpGroupsList(aPythonDump,aGroups);
1545 aPythonDump<< this << ".RotationSweepObjectMakeGroups( "
1546 << theObject << ", "
1548 << theAngleInRadians << ", "
1549 << theNbOfSteps << ", "
1550 << theTolerance << " )";
1555 //=======================================================================
1556 //function : RotationSweepObject1DMakeGroups
1558 //=======================================================================
1560 SMESH::ListOfGroups*
1561 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1562 const SMESH::AxisStruct& theAxis,
1563 CORBA::Double theAngleInRadians,
1564 CORBA::Long theNbOfSteps,
1565 CORBA::Double theTolerance)
1567 SMESH::long_array_var anElementsId = theObject->GetIDs();
1568 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1575 if ( !myPreviewMode ) {
1576 TPythonDump aPythonDump;
1577 DumpGroupsList(aPythonDump,aGroups);
1578 aPythonDump<< this << ".RotationSweepObject1DMakeGroups( "
1579 << theObject << ", "
1581 << theAngleInRadians << ", "
1582 << theNbOfSteps << ", "
1583 << theTolerance << " )";
1588 //=======================================================================
1589 //function : RotationSweepObject2DMakeGroups
1591 //=======================================================================
1593 SMESH::ListOfGroups*
1594 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1595 const SMESH::AxisStruct& theAxis,
1596 CORBA::Double theAngleInRadians,
1597 CORBA::Long theNbOfSteps,
1598 CORBA::Double theTolerance)
1600 SMESH::long_array_var anElementsId = theObject->GetIDs();
1601 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1608 if ( !myPreviewMode ) {
1609 TPythonDump aPythonDump;
1610 DumpGroupsList(aPythonDump,aGroups);
1611 aPythonDump<< this << ".RotationSweepObject2DMakeGroups( "
1612 << theObject << ", "
1614 << theAngleInRadians << ", "
1615 << theNbOfSteps << ", "
1616 << theTolerance << " )";
1622 //=======================================================================
1623 //function : extrusionSweep
1625 //=======================================================================
1627 SMESH::ListOfGroups*
1628 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1629 const SMESH::DirStruct & theStepVector,
1630 CORBA::Long theNbOfSteps,
1631 const bool theMakeGroups,
1632 const SMDSAbs_ElementType theElementType)
1640 TIDSortedElemSet elements;
1641 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1643 const SMESH::PointStruct * P = &theStepVector.PS;
1644 gp_Vec stepVec( P->x, P->y, P->z );
1646 TElemOfElemListMap aHystory;
1647 ::SMESH_MeshEditor anEditor( myMesh );
1648 ::SMESH_MeshEditor::PGroupIDs groupIds =
1649 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1651 storeResult(anEditor);
1653 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1655 } catch(Standard_Failure) {
1656 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1657 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1662 //=======================================================================
1663 //function : ExtrusionSweep
1665 //=======================================================================
1667 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1668 const SMESH::DirStruct & theStepVector,
1669 CORBA::Long theNbOfSteps)
1671 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1672 if ( !myPreviewMode ) {
1673 TPythonDump() << this << ".ExtrusionSweep( "
1674 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1679 //=======================================================================
1680 //function : ExtrusionSweepObject
1682 //=======================================================================
1684 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1685 const SMESH::DirStruct & theStepVector,
1686 CORBA::Long theNbOfSteps)
1688 SMESH::long_array_var anElementsId = theObject->GetIDs();
1689 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1690 if ( !myPreviewMode ) {
1691 TPythonDump() << this << ".ExtrusionSweepObject( "
1692 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1696 //=======================================================================
1697 //function : ExtrusionSweepObject1D
1699 //=======================================================================
1701 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1702 const SMESH::DirStruct & theStepVector,
1703 CORBA::Long theNbOfSteps)
1705 SMESH::long_array_var anElementsId = theObject->GetIDs();
1706 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1707 if ( !myPreviewMode ) {
1708 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1709 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1713 //=======================================================================
1714 //function : ExtrusionSweepObject2D
1716 //=======================================================================
1718 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1719 const SMESH::DirStruct & theStepVector,
1720 CORBA::Long theNbOfSteps)
1722 SMESH::long_array_var anElementsId = theObject->GetIDs();
1723 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1724 if ( !myPreviewMode ) {
1725 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1726 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1730 //=======================================================================
1731 //function : ExtrusionSweepMakeGroups
1733 //=======================================================================
1735 SMESH::ListOfGroups*
1736 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1737 const SMESH::DirStruct& theStepVector,
1738 CORBA::Long theNbOfSteps)
1740 SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1742 if ( !myPreviewMode ) {
1743 TPythonDump aPythonDump;
1744 DumpGroupsList(aPythonDump,aGroups);
1745 aPythonDump << this << ".ExtrusionSweepMakeGroups( "
1746 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1750 //=======================================================================
1751 //function : ExtrusionSweepObjectMakeGroups
1753 //=======================================================================
1755 SMESH::ListOfGroups*
1756 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1757 const SMESH::DirStruct& theStepVector,
1758 CORBA::Long theNbOfSteps)
1760 SMESH::long_array_var anElementsId = theObject->GetIDs();
1761 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1763 if ( !myPreviewMode ) {
1764 TPythonDump aPythonDump;
1765 DumpGroupsList(aPythonDump,aGroups);
1766 aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( "
1767 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1772 //=======================================================================
1773 //function : ExtrusionSweepObject1DMakeGroups
1775 //=======================================================================
1777 SMESH::ListOfGroups*
1778 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1779 const SMESH::DirStruct& theStepVector,
1780 CORBA::Long theNbOfSteps)
1782 SMESH::long_array_var anElementsId = theObject->GetIDs();
1783 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1784 if ( !myPreviewMode ) {
1785 TPythonDump aPythonDump;
1786 DumpGroupsList(aPythonDump,aGroups);
1787 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( "
1788 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1793 //=======================================================================
1794 //function : ExtrusionSweepObject2DMakeGroups
1796 //=======================================================================
1798 SMESH::ListOfGroups*
1799 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1800 const SMESH::DirStruct& theStepVector,
1801 CORBA::Long theNbOfSteps)
1803 SMESH::long_array_var anElementsId = theObject->GetIDs();
1804 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1805 if ( !myPreviewMode ) {
1806 TPythonDump aPythonDump;
1807 DumpGroupsList(aPythonDump,aGroups);
1808 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( "
1809 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1815 //=======================================================================
1816 //function : advancedExtrusion
1818 //=======================================================================
1820 SMESH::ListOfGroups*
1821 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1822 const SMESH::DirStruct & theStepVector,
1823 CORBA::Long theNbOfSteps,
1824 CORBA::Long theExtrFlags,
1825 CORBA::Double theSewTolerance,
1826 const bool theMakeGroups)
1830 TIDSortedElemSet elements;
1831 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1833 const SMESH::PointStruct * P = &theStepVector.PS;
1834 gp_Vec stepVec( P->x, P->y, P->z );
1836 ::SMESH_MeshEditor anEditor( myMesh );
1837 TElemOfElemListMap aHystory;
1838 ::SMESH_MeshEditor::PGroupIDs groupIds =
1839 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1840 theMakeGroups, theExtrFlags, theSewTolerance);
1841 storeResult(anEditor);
1843 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1846 //=======================================================================
1847 //function : AdvancedExtrusion
1849 //=======================================================================
1851 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1852 const SMESH::DirStruct & theStepVector,
1853 CORBA::Long theNbOfSteps,
1854 CORBA::Long theExtrFlags,
1855 CORBA::Double theSewTolerance)
1857 if ( !myPreviewMode ) {
1858 TPythonDump() << "stepVector = " << theStepVector;
1859 TPythonDump() << this << ".AdvancedExtrusion("
1862 << theNbOfSteps << ","
1863 << theExtrFlags << ", "
1864 << theSewTolerance << " )";
1866 advancedExtrusion( theIDsOfElements,
1874 //=======================================================================
1875 //function : AdvancedExtrusionMakeGroups
1877 //=======================================================================
1879 SMESH::ListOfGroups*
1880 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1881 const SMESH::DirStruct& theStepVector,
1882 CORBA::Long theNbOfSteps,
1883 CORBA::Long theExtrFlags,
1884 CORBA::Double theSewTolerance)
1886 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
1893 if ( !myPreviewMode ) {
1894 TPythonDump() << "stepVector = " << theStepVector;
1895 TPythonDump aPythonDump;
1896 DumpGroupsList(aPythonDump,aGroups);
1897 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
1900 << theNbOfSteps << ","
1901 << theExtrFlags << ", "
1902 << theSewTolerance << " )";
1908 //================================================================================
1910 * \brief Convert extrusion error to IDL enum
1912 //================================================================================
1914 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1916 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1920 RETCASE( EXTR_NO_ELEMENTS );
1921 RETCASE( EXTR_PATH_NOT_EDGE );
1922 RETCASE( EXTR_BAD_PATH_SHAPE );
1923 RETCASE( EXTR_BAD_STARTING_NODE );
1924 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1925 RETCASE( EXTR_CANT_GET_TANGENT );
1927 return SMESH::SMESH_MeshEditor::EXTR_OK;
1931 //=======================================================================
1932 //function : extrusionAlongPath
1934 //=======================================================================
1936 SMESH::ListOfGroups*
1937 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1938 SMESH::SMESH_Mesh_ptr thePathMesh,
1939 GEOM::GEOM_Object_ptr thePathShape,
1940 CORBA::Long theNodeStart,
1941 CORBA::Boolean theHasAngles,
1942 const SMESH::double_array & theAngles,
1943 CORBA::Boolean theHasRefPoint,
1944 const SMESH::PointStruct & theRefPoint,
1945 const bool theMakeGroups,
1946 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
1947 const SMDSAbs_ElementType theElementType)
1951 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1952 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1955 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1957 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1958 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1960 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
1961 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1965 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1967 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1971 TIDSortedElemSet elements;
1972 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1974 list<double> angles;
1975 for (int i = 0; i < theAngles.length(); i++) {
1976 angles.push_back( theAngles[i] );
1979 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1981 int nbOldGroups = myMesh->NbGroup();
1983 ::SMESH_MeshEditor anEditor( myMesh );
1984 ::SMESH_MeshEditor::Extrusion_Error error =
1985 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1986 theHasAngles, angles, false,
1987 theHasRefPoint, refPnt, theMakeGroups );
1988 storeResult(anEditor);
1989 theError = convExtrError( error );
1991 if ( theMakeGroups ) {
1992 list<int> groupIDs = myMesh->GetGroupIds();
1993 list<int>::iterator newBegin = groupIDs.begin();
1994 std::advance( newBegin, nbOldGroups ); // skip old groups
1995 groupIDs.erase( groupIDs.begin(), newBegin );
1996 return getGroups( & groupIDs );
2002 //=======================================================================
2003 //function : extrusionAlongPathX
2005 //=======================================================================
2007 SMESH::ListOfGroups*
2008 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2009 SMESH::SMESH_IDSource_ptr Path,
2010 CORBA::Long NodeStart,
2011 CORBA::Boolean HasAngles,
2012 const SMESH::double_array& Angles,
2013 CORBA::Boolean LinearVariation,
2014 CORBA::Boolean HasRefPoint,
2015 const SMESH::PointStruct& RefPoint,
2016 const bool MakeGroups,
2017 const SMDSAbs_ElementType ElementType,
2018 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2020 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2024 list<double> angles;
2025 for (int i = 0; i < Angles.length(); i++) {
2026 angles.push_back( Angles[i] );
2028 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2029 int nbOldGroups = myMesh->NbGroup();
2031 if ( Path->_is_nil() ) {
2032 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2036 TIDSortedElemSet elements;
2037 arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
2039 ::SMESH_MeshEditor anEditor( myMesh );
2040 ::SMESH_MeshEditor::Extrusion_Error error;
2042 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
2045 SMDS_MeshNode* aNodeStart =
2046 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2047 if ( !aNodeStart ) {
2048 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2051 error = anEditor.ExtrusionAlongTrack( elements, &(aMeshImp->GetImpl()), aNodeStart,
2052 HasAngles, angles, LinearVariation,
2053 HasRefPoint, refPnt, MakeGroups );
2056 SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
2059 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
2060 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
2061 SMDS_MeshNode* aNodeStart =
2062 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2063 if ( !aNodeStart ) {
2064 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2067 SMESH_subMesh* aSubMesh =
2068 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
2069 error = anEditor.ExtrusionAlongTrack( elements, aSubMesh, aNodeStart,
2070 HasAngles, angles, LinearVariation,
2071 HasRefPoint, refPnt, MakeGroups );
2074 SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
2076 // path as group of 1D elements
2080 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2086 storeResult(anEditor);
2087 Error = convExtrError( error );
2090 list<int> groupIDs = myMesh->GetGroupIds();
2091 list<int>::iterator newBegin = groupIDs.begin();
2092 std::advance( newBegin, nbOldGroups ); // skip old groups
2093 groupIDs.erase( groupIDs.begin(), newBegin );
2094 return getGroups( & groupIDs );
2100 //=======================================================================
2101 //function : ExtrusionAlongPath
2103 //=======================================================================
2105 SMESH::SMESH_MeshEditor::Extrusion_Error
2106 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2107 SMESH::SMESH_Mesh_ptr thePathMesh,
2108 GEOM::GEOM_Object_ptr thePathShape,
2109 CORBA::Long theNodeStart,
2110 CORBA::Boolean theHasAngles,
2111 const SMESH::double_array & theAngles,
2112 CORBA::Boolean theHasRefPoint,
2113 const SMESH::PointStruct & theRefPoint)
2115 if ( !myPreviewMode ) {
2116 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
2117 << theIDsOfElements << ", "
2118 << thePathMesh << ", "
2119 << thePathShape << ", "
2120 << theNodeStart << ", "
2121 << theHasAngles << ", "
2122 << theAngles << ", "
2123 << theHasRefPoint << ", "
2124 << "SMESH.PointStruct( "
2125 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2126 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2127 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2129 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2130 extrusionAlongPath( theIDsOfElements,
2143 //=======================================================================
2144 //function : ExtrusionAlongPathObject
2146 //=======================================================================
2148 SMESH::SMESH_MeshEditor::Extrusion_Error
2149 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
2150 SMESH::SMESH_Mesh_ptr thePathMesh,
2151 GEOM::GEOM_Object_ptr thePathShape,
2152 CORBA::Long theNodeStart,
2153 CORBA::Boolean theHasAngles,
2154 const SMESH::double_array & theAngles,
2155 CORBA::Boolean theHasRefPoint,
2156 const SMESH::PointStruct & theRefPoint)
2158 if ( !myPreviewMode ) {
2159 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
2160 << theObject << ", "
2161 << thePathMesh << ", "
2162 << thePathShape << ", "
2163 << theNodeStart << ", "
2164 << theHasAngles << ", "
2165 << theAngles << ", "
2166 << theHasRefPoint << ", "
2167 << "SMESH.PointStruct( "
2168 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2169 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2170 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2172 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2173 SMESH::long_array_var anElementsId = theObject->GetIDs();
2174 extrusionAlongPath( anElementsId,
2187 //=======================================================================
2188 //function : ExtrusionAlongPathObject1D
2190 //=======================================================================
2192 SMESH::SMESH_MeshEditor::Extrusion_Error
2193 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
2194 SMESH::SMESH_Mesh_ptr thePathMesh,
2195 GEOM::GEOM_Object_ptr thePathShape,
2196 CORBA::Long theNodeStart,
2197 CORBA::Boolean theHasAngles,
2198 const SMESH::double_array & theAngles,
2199 CORBA::Boolean theHasRefPoint,
2200 const SMESH::PointStruct & theRefPoint)
2202 if ( !myPreviewMode ) {
2203 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
2204 << theObject << ", "
2205 << thePathMesh << ", "
2206 << thePathShape << ", "
2207 << theNodeStart << ", "
2208 << theHasAngles << ", "
2209 << theAngles << ", "
2210 << theHasRefPoint << ", "
2211 << "SMESH.PointStruct( "
2212 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2213 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2214 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2216 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2217 SMESH::long_array_var anElementsId = theObject->GetIDs();
2218 extrusionAlongPath( anElementsId,
2232 //=======================================================================
2233 //function : ExtrusionAlongPathObject2D
2235 //=======================================================================
2237 SMESH::SMESH_MeshEditor::Extrusion_Error
2238 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
2239 SMESH::SMESH_Mesh_ptr thePathMesh,
2240 GEOM::GEOM_Object_ptr thePathShape,
2241 CORBA::Long theNodeStart,
2242 CORBA::Boolean theHasAngles,
2243 const SMESH::double_array & theAngles,
2244 CORBA::Boolean theHasRefPoint,
2245 const SMESH::PointStruct & theRefPoint)
2247 if ( !myPreviewMode ) {
2248 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
2249 << theObject << ", "
2250 << thePathMesh << ", "
2251 << thePathShape << ", "
2252 << theNodeStart << ", "
2253 << theHasAngles << ", "
2254 << theAngles << ", "
2255 << theHasRefPoint << ", "
2256 << "SMESH.PointStruct( "
2257 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2258 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2259 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2261 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2262 SMESH::long_array_var anElementsId = theObject->GetIDs();
2263 extrusionAlongPath( anElementsId,
2278 //=======================================================================
2279 //function : ExtrusionAlongPathMakeGroups
2281 //=======================================================================
2283 SMESH::ListOfGroups*
2284 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2285 SMESH::SMESH_Mesh_ptr thePathMesh,
2286 GEOM::GEOM_Object_ptr thePathShape,
2287 CORBA::Long theNodeStart,
2288 CORBA::Boolean theHasAngles,
2289 const SMESH::double_array& theAngles,
2290 CORBA::Boolean theHasRefPoint,
2291 const SMESH::PointStruct& theRefPoint,
2292 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2294 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2304 if ( !myPreviewMode ) {
2305 bool isDumpGroups = aGroups && aGroups->length() > 0;
2306 TPythonDump aPythonDump;
2308 aPythonDump << "("<<aGroups;
2311 aPythonDump << ", error)";
2313 aPythonDump <<"error";
2315 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2316 << theIDsOfElements << ", "
2317 << thePathMesh << ", "
2318 << thePathShape << ", "
2319 << theNodeStart << ", "
2320 << theHasAngles << ", "
2321 << theAngles << ", "
2322 << theHasRefPoint << ", "
2323 << "SMESH.PointStruct( "
2324 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2325 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2326 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2331 //=======================================================================
2332 //function : ExtrusionAlongPathObjectMakeGroups
2334 //=======================================================================
2336 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2337 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2338 SMESH::SMESH_Mesh_ptr thePathMesh,
2339 GEOM::GEOM_Object_ptr thePathShape,
2340 CORBA::Long theNodeStart,
2341 CORBA::Boolean theHasAngles,
2342 const SMESH::double_array& theAngles,
2343 CORBA::Boolean theHasRefPoint,
2344 const SMESH::PointStruct& theRefPoint,
2345 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2347 SMESH::long_array_var anElementsId = theObject->GetIDs();
2348 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2359 if ( !myPreviewMode ) {
2360 bool isDumpGroups = aGroups && aGroups->length() > 0;
2361 TPythonDump aPythonDump;
2363 aPythonDump << "("<<aGroups;
2366 aPythonDump << ", error)";
2368 aPythonDump <<"error";
2370 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2371 << theObject << ", "
2372 << thePathMesh << ", "
2373 << thePathShape << ", "
2374 << theNodeStart << ", "
2375 << theHasAngles << ", "
2376 << theAngles << ", "
2377 << theHasRefPoint << ", "
2378 << "SMESH.PointStruct( "
2379 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2380 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2381 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2386 //=======================================================================
2387 //function : ExtrusionAlongPathObject1DMakeGroups
2389 //=======================================================================
2391 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2392 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2393 SMESH::SMESH_Mesh_ptr thePathMesh,
2394 GEOM::GEOM_Object_ptr thePathShape,
2395 CORBA::Long theNodeStart,
2396 CORBA::Boolean theHasAngles,
2397 const SMESH::double_array& theAngles,
2398 CORBA::Boolean theHasRefPoint,
2399 const SMESH::PointStruct& theRefPoint,
2400 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2402 SMESH::long_array_var anElementsId = theObject->GetIDs();
2403 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2415 if ( !myPreviewMode ) {
2416 bool isDumpGroups = aGroups && aGroups->length() > 0;
2417 TPythonDump aPythonDump;
2419 aPythonDump << "("<<aGroups;
2422 aPythonDump << ", error)";
2424 aPythonDump <<"error";
2426 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
2427 << theObject << ", "
2428 << thePathMesh << ", "
2429 << thePathShape << ", "
2430 << theNodeStart << ", "
2431 << theHasAngles << ", "
2432 << theAngles << ", "
2433 << theHasRefPoint << ", "
2434 << "SMESH.PointStruct( "
2435 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2436 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2437 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2442 //=======================================================================
2443 //function : ExtrusionAlongPathObject2DMakeGroups
2445 //=======================================================================
2447 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2448 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2449 SMESH::SMESH_Mesh_ptr thePathMesh,
2450 GEOM::GEOM_Object_ptr thePathShape,
2451 CORBA::Long theNodeStart,
2452 CORBA::Boolean theHasAngles,
2453 const SMESH::double_array& theAngles,
2454 CORBA::Boolean theHasRefPoint,
2455 const SMESH::PointStruct& theRefPoint,
2456 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2458 SMESH::long_array_var anElementsId = theObject->GetIDs();
2459 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2471 if ( !myPreviewMode ) {
2472 bool isDumpGroups = aGroups && aGroups->length() > 0;
2473 TPythonDump aPythonDump;
2475 aPythonDump << "("<<aGroups;
2478 aPythonDump << ", error)";
2480 aPythonDump <<"error";
2482 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
2483 << theObject << ", "
2484 << thePathMesh << ", "
2485 << thePathShape << ", "
2486 << theNodeStart << ", "
2487 << theHasAngles << ", "
2488 << theAngles << ", "
2489 << theHasRefPoint << ", "
2490 << "SMESH.PointStruct( "
2491 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2492 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2493 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2499 //=======================================================================
2500 //function : ExtrusionAlongPathObjX
2502 //=======================================================================
2503 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2504 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
2505 SMESH::SMESH_IDSource_ptr Path,
2506 CORBA::Long NodeStart,
2507 CORBA::Boolean HasAngles,
2508 const SMESH::double_array& Angles,
2509 CORBA::Boolean LinearVariation,
2510 CORBA::Boolean HasRefPoint,
2511 const SMESH::PointStruct& RefPoint,
2512 CORBA::Boolean MakeGroups,
2513 SMESH::ElementType ElemType,
2514 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2516 SMESH::long_array_var anElementsId = Object->GetIDs();
2517 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2526 (SMDSAbs_ElementType)ElemType,
2529 if ( !myPreviewMode ) {
2530 bool isDumpGroups = aGroups && aGroups->length() > 0;
2531 TPythonDump aPythonDump;
2533 aPythonDump << "("<<aGroups;
2536 aPythonDump << ", error)";
2538 aPythonDump <<"error";
2540 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2543 << NodeStart << ", "
2544 << HasAngles << ", "
2546 << LinearVariation << ", "
2547 << HasRefPoint << ", "
2548 << "SMESH.PointStruct( "
2549 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2550 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2551 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2552 << MakeGroups << ", "
2553 << ElemType << " )";
2559 //=======================================================================
2560 //function : ExtrusionAlongPathX
2562 //=======================================================================
2563 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2564 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2565 SMESH::SMESH_IDSource_ptr Path,
2566 CORBA::Long NodeStart,
2567 CORBA::Boolean HasAngles,
2568 const SMESH::double_array& Angles,
2569 CORBA::Boolean LinearVariation,
2570 CORBA::Boolean HasRefPoint,
2571 const SMESH::PointStruct& RefPoint,
2572 CORBA::Boolean MakeGroups,
2573 SMESH::ElementType ElemType,
2574 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2576 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2585 (SMDSAbs_ElementType)ElemType,
2588 if ( !myPreviewMode ) {
2589 bool isDumpGroups = aGroups && aGroups->length() > 0;
2590 TPythonDump aPythonDump;
2592 aPythonDump << "("<<aGroups;
2595 aPythonDump << ", error)";
2597 aPythonDump <<"error";
2599 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2600 << IDsOfElements << ", "
2602 << NodeStart << ", "
2603 << HasAngles << ", "
2605 << LinearVariation << ", "
2606 << HasRefPoint << ", "
2607 << "SMESH.PointStruct( "
2608 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2609 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2610 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2611 << ElemType << " )";
2617 //================================================================================
2619 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2620 * of given angles along path steps
2621 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2622 * which proceeds the extrusion
2623 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2624 * is used to define the sub-mesh for the path
2626 //================================================================================
2628 SMESH::double_array*
2629 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2630 GEOM::GEOM_Object_ptr thePathShape,
2631 const SMESH::double_array & theAngles)
2633 SMESH::double_array_var aResult = new SMESH::double_array();
2634 int nbAngles = theAngles.length();
2635 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2637 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2638 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2639 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2640 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2641 return aResult._retn();
2642 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2643 if ( nbSteps == nbAngles )
2645 aResult.inout() = theAngles;
2649 aResult->length( nbSteps );
2650 double rAn2St = double( nbAngles ) / double( nbSteps );
2651 double angPrev = 0, angle;
2652 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2654 double angCur = rAn2St * ( iSt+1 );
2655 double angCurFloor = floor( angCur );
2656 double angPrevFloor = floor( angPrev );
2657 if ( angPrevFloor == angCurFloor )
2658 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2661 int iP = int( angPrevFloor );
2662 double angPrevCeil = ceil(angPrev);
2663 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2665 int iC = int( angCurFloor );
2666 if ( iC < nbAngles )
2667 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2669 iP = int( angPrevCeil );
2671 angle += theAngles[ iC ];
2673 aResult[ iSt ] = angle;
2678 // Update Python script
2679 TPythonDump() << "rotAngles = " << theAngles;
2680 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2681 << thePathMesh << ", "
2682 << thePathShape << ", "
2685 return aResult._retn();
2689 //=======================================================================
2692 //=======================================================================
2694 SMESH::ListOfGroups*
2695 SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
2696 const SMESH::AxisStruct & theAxis,
2697 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2698 CORBA::Boolean theCopy,
2699 const bool theMakeGroups,
2700 ::SMESH_Mesh* theTargetMesh)
2704 TIDSortedElemSet elements;
2705 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2707 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2708 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2711 switch ( theMirrorType ) {
2712 case SMESH::SMESH_MeshEditor::POINT:
2713 aTrsf.SetMirror( P );
2715 case SMESH::SMESH_MeshEditor::AXIS:
2716 aTrsf.SetMirror( gp_Ax1( P, V ));
2719 aTrsf.SetMirror( gp_Ax2( P, V ));
2722 ::SMESH_MeshEditor anEditor( myMesh );
2723 ::SMESH_MeshEditor::PGroupIDs groupIds =
2724 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2727 storeResult(anEditor);
2729 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2732 //=======================================================================
2735 //=======================================================================
2737 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2738 const SMESH::AxisStruct & theAxis,
2739 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2740 CORBA::Boolean theCopy)
2742 if ( !myPreviewMode ) {
2743 TPythonDump() << this << ".Mirror( "
2744 << theIDsOfElements << ", "
2746 << mirrorTypeName(theMirrorType) << ", "
2749 mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2753 //=======================================================================
2754 //function : MirrorObject
2756 //=======================================================================
2758 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2759 const SMESH::AxisStruct & theAxis,
2760 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2761 CORBA::Boolean theCopy)
2763 if ( !myPreviewMode ) {
2764 TPythonDump() << this << ".MirrorObject( "
2765 << theObject << ", "
2767 << mirrorTypeName(theMirrorType) << ", "
2770 SMESH::long_array_var anElementsId = theObject->GetIDs();
2771 mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2774 //=======================================================================
2775 //function : MirrorMakeGroups
2777 //=======================================================================
2779 SMESH::ListOfGroups*
2780 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2781 const SMESH::AxisStruct& theMirror,
2782 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2784 SMESH::ListOfGroups * aGroups = mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2785 if ( !myPreviewMode ) {
2786 TPythonDump aPythonDump;
2787 DumpGroupsList(aPythonDump,aGroups);
2788 aPythonDump << this << ".MirrorMakeGroups( "
2789 << theIDsOfElements << ", "
2790 << theMirror << ", "
2791 << mirrorTypeName(theMirrorType) << " )";
2796 //=======================================================================
2797 //function : MirrorObjectMakeGroups
2799 //=======================================================================
2801 SMESH::ListOfGroups*
2802 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2803 const SMESH::AxisStruct& theMirror,
2804 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2806 SMESH::long_array_var anElementsId = theObject->GetIDs();
2807 SMESH::ListOfGroups * aGroups = mirror(anElementsId, theMirror, theMirrorType, true, true);
2808 if ( !myPreviewMode ) {
2809 TPythonDump aPythonDump;
2810 DumpGroupsList(aPythonDump,aGroups);
2811 aPythonDump << this << ".MirrorObjectMakeGroups( "
2812 << theObject << ", "
2813 << theMirror << ", "
2814 << mirrorTypeName(theMirrorType) << " )";
2819 //=======================================================================
2820 //function : MirrorMakeMesh
2822 //=======================================================================
2824 SMESH::SMESH_Mesh_ptr
2825 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2826 const SMESH::AxisStruct& theMirror,
2827 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2828 CORBA::Boolean theCopyGroups,
2829 const char* theMeshName)
2831 SMESH_Mesh_i* mesh_i;
2832 SMESH::SMESH_Mesh_var mesh;
2833 { // open new scope to dump "MakeMesh" command
2834 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2836 TPythonDump pydump; // to prevent dump at mesh creation
2838 mesh = makeMesh( theMeshName );
2839 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2841 mirror(theIDsOfElements, theMirror, theMirrorType,
2842 false, theCopyGroups, & mesh_i->GetImpl());
2843 mesh_i->CreateGroupServants();
2846 if ( !myPreviewMode ) {
2847 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2848 << theIDsOfElements << ", "
2849 << theMirror << ", "
2850 << mirrorTypeName(theMirrorType) << ", "
2851 << theCopyGroups << ", '"
2852 << theMeshName << "' )";
2857 if(!myPreviewMode && mesh_i)
2858 mesh_i->GetGroups();
2860 return mesh._retn();
2863 //=======================================================================
2864 //function : MirrorObjectMakeMesh
2866 //=======================================================================
2868 SMESH::SMESH_Mesh_ptr
2869 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2870 const SMESH::AxisStruct& theMirror,
2871 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2872 CORBA::Boolean theCopyGroups,
2873 const char* theMeshName)
2875 SMESH_Mesh_i* mesh_i;
2876 SMESH::SMESH_Mesh_var mesh;
2877 { // open new scope to dump "MakeMesh" command
2878 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2880 TPythonDump pydump; // to prevent dump at mesh creation
2882 mesh = makeMesh( theMeshName );
2883 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2885 SMESH::long_array_var anElementsId = theObject->GetIDs();
2886 mirror(anElementsId, theMirror, theMirrorType,
2887 false, theCopyGroups, & mesh_i->GetImpl());
2888 mesh_i->CreateGroupServants();
2891 if ( !myPreviewMode ) {
2892 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
2893 << theObject << ", "
2894 << theMirror << ", "
2895 << mirrorTypeName(theMirrorType) << ", "
2896 << theCopyGroups << ", '"
2897 << theMeshName << "' )";
2902 if(!myPreviewMode && mesh_i)
2903 mesh_i->GetGroups();
2905 return mesh._retn();
2908 //=======================================================================
2909 //function : translate
2911 //=======================================================================
2913 SMESH::ListOfGroups*
2914 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2915 const SMESH::DirStruct & theVector,
2916 CORBA::Boolean theCopy,
2917 const bool theMakeGroups,
2918 ::SMESH_Mesh* theTargetMesh)
2922 TIDSortedElemSet elements;
2923 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2926 const SMESH::PointStruct * P = &theVector.PS;
2927 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2929 ::SMESH_MeshEditor anEditor( myMesh );
2930 ::SMESH_MeshEditor::PGroupIDs groupIds =
2931 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2934 storeResult(anEditor);
2936 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2939 //=======================================================================
2940 //function : Translate
2942 //=======================================================================
2944 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2945 const SMESH::DirStruct & theVector,
2946 CORBA::Boolean theCopy)
2948 if ( !myPreviewMode ) {
2949 TPythonDump() << this << ".Translate( "
2950 << theIDsOfElements << ", "
2951 << theVector << ", "
2954 translate(theIDsOfElements,
2960 //=======================================================================
2961 //function : TranslateObject
2963 //=======================================================================
2965 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
2966 const SMESH::DirStruct & theVector,
2967 CORBA::Boolean theCopy)
2969 if ( !myPreviewMode ) {
2970 TPythonDump() << this << ".TranslateObject( "
2971 << theObject << ", "
2972 << theVector << ", "
2975 SMESH::long_array_var anElementsId = theObject->GetIDs();
2976 translate(anElementsId,
2982 //=======================================================================
2983 //function : TranslateMakeGroups
2985 //=======================================================================
2987 SMESH::ListOfGroups*
2988 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
2989 const SMESH::DirStruct& theVector)
2991 SMESH::ListOfGroups * aGroups = translate(theIDsOfElements,theVector,true,true);
2992 if ( !myPreviewMode ) {
2993 TPythonDump aPythonDump;
2994 DumpGroupsList(aPythonDump,aGroups);
2995 aPythonDump << this << ".TranslateMakeGroups( "
2996 << theIDsOfElements << ", "
2997 << theVector << " )";
3002 //=======================================================================
3003 //function : TranslateObjectMakeGroups
3005 //=======================================================================
3007 SMESH::ListOfGroups*
3008 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3009 const SMESH::DirStruct& theVector)
3011 SMESH::long_array_var anElementsId = theObject->GetIDs();
3012 SMESH::ListOfGroups * aGroups = translate(anElementsId, theVector, true, true);
3014 if ( !myPreviewMode ) {
3016 TPythonDump aPythonDump;
3017 DumpGroupsList(aPythonDump,aGroups);
3018 aPythonDump << this << ".TranslateObjectMakeGroups( "
3019 << theObject << ", "
3020 << theVector << " )";
3025 //=======================================================================
3026 //function : TranslateMakeMesh
3028 //=======================================================================
3030 SMESH::SMESH_Mesh_ptr
3031 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3032 const SMESH::DirStruct& theVector,
3033 CORBA::Boolean theCopyGroups,
3034 const char* theMeshName)
3036 SMESH_Mesh_i* mesh_i;
3037 SMESH::SMESH_Mesh_var mesh;
3039 { // open new scope to dump "MakeMesh" command
3040 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3042 TPythonDump pydump; // to prevent dump at mesh creation
3044 mesh = makeMesh( theMeshName );
3045 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3048 translate(theIDsOfElements, theVector,
3049 false, theCopyGroups, & mesh_i->GetImpl());
3050 mesh_i->CreateGroupServants();
3053 if ( !myPreviewMode ) {
3054 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3055 << theIDsOfElements << ", "
3056 << theVector << ", "
3057 << theCopyGroups << ", '"
3058 << theMeshName << "' )";
3063 if(!myPreviewMode && mesh_i)
3064 mesh_i->GetGroups();
3066 return mesh._retn();
3069 //=======================================================================
3070 //function : TranslateObjectMakeMesh
3072 //=======================================================================
3074 SMESH::SMESH_Mesh_ptr
3075 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3076 const SMESH::DirStruct& theVector,
3077 CORBA::Boolean theCopyGroups,
3078 const char* theMeshName)
3080 SMESH_Mesh_i* mesh_i;
3081 SMESH::SMESH_Mesh_var mesh;
3082 { // open new scope to dump "MakeMesh" command
3083 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3085 TPythonDump pydump; // to prevent dump at mesh creation
3086 mesh = makeMesh( theMeshName );
3087 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3090 SMESH::long_array_var anElementsId = theObject->GetIDs();
3091 translate(anElementsId, theVector,
3092 false, theCopyGroups, & mesh_i->GetImpl());
3093 mesh_i->CreateGroupServants();
3095 if ( !myPreviewMode ) {
3096 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3097 << theObject << ", "
3098 << theVector << ", "
3099 << theCopyGroups << ", '"
3100 << theMeshName << "' )";
3105 if(!myPreviewMode && mesh_i)
3106 mesh_i->GetGroups();
3108 return mesh._retn();
3111 //=======================================================================
3114 //=======================================================================
3116 SMESH::ListOfGroups*
3117 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
3118 const SMESH::AxisStruct & theAxis,
3119 CORBA::Double theAngle,
3120 CORBA::Boolean theCopy,
3121 const bool theMakeGroups,
3122 ::SMESH_Mesh* theTargetMesh)
3126 TIDSortedElemSet elements;
3127 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3129 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3130 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3133 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3135 ::SMESH_MeshEditor anEditor( myMesh );
3136 ::SMESH_MeshEditor::PGroupIDs groupIds =
3137 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3140 storeResult(anEditor);
3142 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3145 //=======================================================================
3148 //=======================================================================
3150 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3151 const SMESH::AxisStruct & theAxis,
3152 CORBA::Double theAngle,
3153 CORBA::Boolean theCopy)
3155 if ( !myPreviewMode ) {
3156 TPythonDump() << this << ".Rotate( "
3157 << theIDsOfElements << ", "
3162 rotate(theIDsOfElements,
3169 //=======================================================================
3170 //function : RotateObject
3172 //=======================================================================
3174 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3175 const SMESH::AxisStruct & theAxis,
3176 CORBA::Double theAngle,
3177 CORBA::Boolean theCopy)
3179 if ( !myPreviewMode ) {
3180 TPythonDump() << this << ".RotateObject( "
3181 << theObject << ", "
3186 SMESH::long_array_var anElementsId = theObject->GetIDs();
3187 rotate(anElementsId,
3194 //=======================================================================
3195 //function : RotateMakeGroups
3197 //=======================================================================
3199 SMESH::ListOfGroups*
3200 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3201 const SMESH::AxisStruct& theAxis,
3202 CORBA::Double theAngle)
3204 SMESH::ListOfGroups * aGroups = rotate(theIDsOfElements,theAxis,theAngle,true,true);
3205 if ( !myPreviewMode ) {
3206 TPythonDump aPythonDump;
3207 DumpGroupsList(aPythonDump,aGroups);
3208 aPythonDump << this << ".RotateMakeGroups( "
3209 << theIDsOfElements << ", "
3211 << theAngle << " )";
3216 //=======================================================================
3217 //function : RotateObjectMakeGroups
3219 //=======================================================================
3221 SMESH::ListOfGroups*
3222 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3223 const SMESH::AxisStruct& theAxis,
3224 CORBA::Double theAngle)
3226 SMESH::long_array_var anElementsId = theObject->GetIDs();
3227 SMESH::ListOfGroups * aGroups = rotate(anElementsId,theAxis,theAngle,true,true);
3229 if ( !myPreviewMode ) {
3230 TPythonDump aPythonDump;
3231 DumpGroupsList(aPythonDump,aGroups);
3232 aPythonDump << this << ".RotateObjectMakeGroups( "
3233 << theObject << ", "
3235 << theAngle << " )";
3240 //=======================================================================
3241 //function : RotateMakeMesh
3243 //=======================================================================
3245 SMESH::SMESH_Mesh_ptr
3246 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3247 const SMESH::AxisStruct& theAxis,
3248 CORBA::Double theAngleInRadians,
3249 CORBA::Boolean theCopyGroups,
3250 const char* theMeshName)
3252 SMESH::SMESH_Mesh_var mesh;
3253 SMESH_Mesh_i* mesh_i;
3255 { // open new scope to dump "MakeMesh" command
3256 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3258 TPythonDump pydump; // to prevent dump at mesh creation
3260 mesh = makeMesh( theMeshName );
3261 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3264 rotate(theIDsOfElements, theAxis, theAngleInRadians,
3265 false, theCopyGroups, & mesh_i->GetImpl());
3266 mesh_i->CreateGroupServants();
3268 if ( !myPreviewMode ) {
3269 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3270 << theIDsOfElements << ", "
3272 << theAngleInRadians << ", "
3273 << theCopyGroups << ", '"
3274 << theMeshName << "' )";
3279 if(!myPreviewMode && mesh_i)
3280 mesh_i->GetGroups();
3282 return mesh._retn();
3285 //=======================================================================
3286 //function : RotateObjectMakeMesh
3288 //=======================================================================
3290 SMESH::SMESH_Mesh_ptr
3291 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3292 const SMESH::AxisStruct& theAxis,
3293 CORBA::Double theAngleInRadians,
3294 CORBA::Boolean theCopyGroups,
3295 const char* theMeshName)
3297 SMESH::SMESH_Mesh_var mesh;
3298 SMESH_Mesh_i* mesh_i;
3300 {// open new scope to dump "MakeMesh" command
3301 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3303 TPythonDump pydump; // to prevent dump at mesh creation
3304 mesh = makeMesh( theMeshName );
3305 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3308 SMESH::long_array_var anElementsId = theObject->GetIDs();
3309 rotate(anElementsId, theAxis, theAngleInRadians,
3310 false, theCopyGroups, & mesh_i->GetImpl());
3311 mesh_i->CreateGroupServants();
3313 if ( !myPreviewMode ) {
3314 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3315 << theObject << ", "
3317 << theAngleInRadians << ", "
3318 << theCopyGroups << ", '"
3319 << theMeshName << "' )";
3324 if(!myPreviewMode && mesh_i)
3325 mesh_i->GetGroups();
3327 return mesh._retn();
3331 //=======================================================================
3334 //=======================================================================
3336 SMESH::ListOfGroups*
3337 SMESH_MeshEditor_i::scale(const SMESH::long_array & theIDsOfElements,
3338 const SMESH::PointStruct& thePoint,
3339 const SMESH::double_array& theScaleFact,
3340 CORBA::Boolean theCopy,
3341 const bool theMakeGroups,
3342 ::SMESH_Mesh* theTargetMesh)
3346 TIDSortedElemSet elements;
3347 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3349 gp_Pnt aPnt( thePoint.x, thePoint.y, thePoint.z );
3350 list<double> aScaleFact;
3351 for (int i = 0; i < theScaleFact.length(); i++) {
3352 aScaleFact.push_back( theScaleFact[i] );
3355 ::SMESH_MeshEditor anEditor( myMesh );
3356 ::SMESH_MeshEditor::PGroupIDs groupIds =
3357 anEditor.Scale (elements, aPnt, aScaleFact, theCopy,
3358 theMakeGroups, theTargetMesh);
3361 storeResult(anEditor);
3363 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3367 //=======================================================================
3370 //=======================================================================
3372 void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr theObject,
3373 const SMESH::PointStruct& thePoint,
3374 const SMESH::double_array& theScaleFact,
3375 CORBA::Boolean theCopy)
3377 if ( !myPreviewMode ) {
3378 TPythonDump() << this << ".Scale( "
3379 << theObject << ", "
3380 << "SMESH.PointStruct( " << thePoint.x << ", "
3381 << thePoint.y << ", " << thePoint.z << " ) ,"
3382 << theScaleFact << ", "
3385 SMESH::long_array_var anElementsId = theObject->GetIDs();
3386 scale(anElementsId, thePoint, theScaleFact, theCopy, false);
3390 //=======================================================================
3391 //function : ScaleMakeGroups
3393 //=======================================================================
3395 SMESH::ListOfGroups*
3396 SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3397 const SMESH::PointStruct& thePoint,
3398 const SMESH::double_array& theScaleFact)
3400 SMESH::long_array_var anElementsId = theObject->GetIDs();
3401 SMESH::ListOfGroups * aGroups =
3402 scale(anElementsId, thePoint, theScaleFact, true, true);
3404 if ( !myPreviewMode ) {
3406 TPythonDump aPythonDump;
3407 DumpGroupsList(aPythonDump,aGroups);
3408 aPythonDump << this << ".Scale("
3410 << "SMESH.PointStruct(" <<thePoint.x << ","
3411 << thePoint.y << "," << thePoint.z << "),"
3412 << theScaleFact << ",True,True)";
3418 //=======================================================================
3419 //function : ScaleMakeMesh
3421 //=======================================================================
3423 SMESH::SMESH_Mesh_ptr
3424 SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3425 const SMESH::PointStruct& thePoint,
3426 const SMESH::double_array& theScaleFact,
3427 CORBA::Boolean theCopyGroups,
3428 const char* theMeshName)
3430 SMESH_Mesh_i* mesh_i;
3431 SMESH::SMESH_Mesh_var mesh;
3432 { // open new scope to dump "MakeMesh" command
3433 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3435 TPythonDump pydump; // to prevent dump at mesh creation
3436 mesh = makeMesh( theMeshName );
3437 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3440 SMESH::long_array_var anElementsId = theObject->GetIDs();
3441 scale(anElementsId, thePoint, theScaleFact,
3442 false, theCopyGroups, & mesh_i->GetImpl());
3443 mesh_i->CreateGroupServants();
3445 if ( !myPreviewMode ) {
3446 pydump << mesh << " = " << this << ".ScaleMakeMesh( "
3447 << theObject << ", "
3448 << "SMESH.PointStruct( " << thePoint.x << ", "
3449 << thePoint.y << ", " << thePoint.z << " ) ,"
3450 << theScaleFact << ", "
3451 << theCopyGroups << ", '"
3452 << theMeshName << "' )";
3457 if(!myPreviewMode && mesh_i)
3458 mesh_i->GetGroups();
3460 return mesh._retn();
3464 //=======================================================================
3465 //function : FindCoincidentNodes
3467 //=======================================================================
3469 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3470 SMESH::array_of_long_array_out GroupsOfNodes)
3474 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3475 ::SMESH_MeshEditor anEditor( myMesh );
3476 set<const SMDS_MeshNode*> nodes; // no input nodes
3477 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3479 GroupsOfNodes = new SMESH::array_of_long_array;
3480 GroupsOfNodes->length( aListOfListOfNodes.size() );
3481 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3482 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3483 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3484 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3485 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3486 aGroup.length( aListOfNodes.size() );
3487 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3488 aGroup[ j ] = (*lIt)->GetID();
3490 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3491 << Tolerance << " )";
3494 //=======================================================================
3495 //function : FindCoincidentNodesOnPart
3497 //=======================================================================
3498 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3499 CORBA::Double Tolerance,
3500 SMESH::array_of_long_array_out GroupsOfNodes)
3503 SMESH::long_array_var aElementsId = theObject->GetIDs();
3505 SMESHDS_Mesh* aMesh = GetMeshDS();
3506 set<const SMDS_MeshNode*> nodes;
3508 if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
3509 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
3510 for(int i = 0; i < aElementsId->length(); i++) {
3511 CORBA::Long ind = aElementsId[i];
3512 const SMDS_MeshNode * elem = aMesh->FindNode(ind);
3518 for(int i = 0; i < aElementsId->length(); i++) {
3519 CORBA::Long ind = aElementsId[i];
3520 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
3522 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
3523 while ( nIt->more() )
3524 nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
3530 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3531 ::SMESH_MeshEditor anEditor( myMesh );
3533 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3535 GroupsOfNodes = new SMESH::array_of_long_array;
3536 GroupsOfNodes->length( aListOfListOfNodes.size() );
3537 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3538 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3539 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3540 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3541 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3542 aGroup.length( aListOfNodes.size() );
3543 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3544 aGroup[ j ] = (*lIt)->GetID();
3546 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3548 << Tolerance << " )";
3551 //=======================================================================
3552 //function : MergeNodes
3554 //=======================================================================
3556 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3560 SMESHDS_Mesh* aMesh = GetMeshDS();
3562 TPythonDump aTPythonDump;
3563 aTPythonDump << this << ".MergeNodes([";
3564 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3565 for (int i = 0; i < GroupsOfNodes.length(); i++)
3567 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3568 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3569 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3570 for ( int j = 0; j < aNodeGroup.length(); j++ )
3572 CORBA::Long index = aNodeGroup[ j ];
3573 const SMDS_MeshNode * node = aMesh->FindNode(index);
3575 aListOfNodes.push_back( node );
3577 if ( aListOfNodes.size() < 2 )
3578 aListOfListOfNodes.pop_back();
3580 if ( i > 0 ) aTPythonDump << ", ";
3581 aTPythonDump << aNodeGroup;
3583 ::SMESH_MeshEditor anEditor( myMesh );
3584 anEditor.MergeNodes( aListOfListOfNodes );
3586 aTPythonDump << "])";
3589 //=======================================================================
3590 //function : FindEqualElements
3592 //=======================================================================
3593 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3594 SMESH::array_of_long_array_out GroupsOfElementsID)
3597 if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
3598 SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
3599 typedef list<int> TListOfIDs;
3600 set<const SMDS_MeshElement*> elems;
3601 SMESH::long_array_var aElementsId = theObject->GetIDs();
3602 SMESHDS_Mesh* aMesh = GetMeshDS();
3604 for(int i = 0; i < aElementsId->length(); i++) {
3605 CORBA::Long anID = aElementsId[i];
3606 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3612 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3613 ::SMESH_MeshEditor anEditor( myMesh );
3614 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3616 GroupsOfElementsID = new SMESH::array_of_long_array;
3617 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3619 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3620 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3621 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3622 TListOfIDs& listOfIDs = *arraysIt;
3623 aGroup.length( listOfIDs.size() );
3624 TListOfIDs::iterator idIt = listOfIDs.begin();
3625 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3626 aGroup[ k ] = *idIt;
3630 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3635 //=======================================================================
3636 //function : MergeElements
3638 //=======================================================================
3640 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3644 TPythonDump aTPythonDump;
3645 aTPythonDump << this << ".MergeElements( [";
3647 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3649 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3650 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3651 aListOfListOfElementsID.push_back( list< int >() );
3652 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3653 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3654 CORBA::Long id = anElemsIDGroup[ j ];
3655 aListOfElemsID.push_back( id );
3657 if ( aListOfElemsID.size() < 2 )
3658 aListOfListOfElementsID.pop_back();
3659 if ( i > 0 ) aTPythonDump << ", ";
3660 aTPythonDump << anElemsIDGroup;
3663 ::SMESH_MeshEditor anEditor( myMesh );
3664 anEditor.MergeElements(aListOfListOfElementsID);
3666 aTPythonDump << "] )";
3669 //=======================================================================
3670 //function : MergeEqualElements
3672 //=======================================================================
3674 void SMESH_MeshEditor_i::MergeEqualElements()
3678 ::SMESH_MeshEditor anEditor( myMesh );
3679 anEditor.MergeEqualElements();
3681 TPythonDump() << this << ".MergeEqualElements()";
3684 //=============================================================================
3686 * Move the node to a given point
3688 //=============================================================================
3690 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
3695 initData(/*deleteSearchers=*/false);
3697 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
3701 if ( theNodeSearcher )
3702 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3704 if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3705 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3707 GetMeshDS()->MoveNode(node, x, y, z);
3709 // Update Python script
3710 TPythonDump() << "isDone = " << this << ".MoveNode( "
3711 << NodeID << ", " << x << ", " << y << ", " << z << " )";
3716 //================================================================================
3718 * \brief Return ID of node closest to a given point
3720 //================================================================================
3722 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
3726 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3728 if ( !theNodeSearcher ) {
3729 ::SMESH_MeshEditor anEditor( myMesh );
3730 theNodeSearcher = anEditor.GetNodeSearcher();
3733 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
3734 return node->GetID();
3739 //================================================================================
3741 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
3742 * move the node closest to the point to point's location and return ID of the node
3744 //================================================================================
3746 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
3749 CORBA::Long theNodeID)
3751 // We keep theNodeSearcher until any mesh modification:
3752 // 1) initData() deletes theNodeSearcher at any edition,
3753 // 2) TSearchersDeleter - at any mesh compute event and mesh change
3755 initData(/*deleteSearchers=*/false);
3757 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3759 int nodeID = theNodeID;
3760 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
3761 if ( !node ) // preview moving node
3763 if ( !theNodeSearcher ) {
3764 ::SMESH_MeshEditor anEditor( myMesh );
3765 theNodeSearcher = anEditor.GetNodeSearcher();
3768 node = theNodeSearcher->FindClosestTo( p );
3771 nodeID = node->GetID();
3772 if ( myPreviewMode ) // make preview data
3774 // in a preview mesh, make edges linked to a node
3775 TPreviewMesh tmpMesh;
3776 TIDSortedElemSet linkedNodes;
3777 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3778 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3779 for ( ; nIt != linkedNodes.end(); ++nIt )
3781 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
3782 tmpMesh.Copy( &edge );
3785 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
3787 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
3788 // fill preview data
3789 ::SMESH_MeshEditor anEditor( & tmpMesh );
3790 storeResult( anEditor );
3792 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3794 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3798 GetMeshDS()->MoveNode(node, x, y, z);
3802 if ( !myPreviewMode ) {
3803 TPythonDump() << "nodeID = " << this
3804 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
3805 << ", " << nodeID << " )";
3811 //=======================================================================
3813 * Return elements of given type where the given point is IN or ON.
3815 * 'ALL' type means elements of any type excluding nodes
3817 //=======================================================================
3819 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
3822 SMESH::ElementType type)
3824 SMESH::long_array_var res = new SMESH::long_array;
3825 vector< const SMDS_MeshElement* > foundElems;
3827 theSearchersDeleter.Set( myMesh );
3828 if ( !theElementSearcher ) {
3829 ::SMESH_MeshEditor anEditor( myMesh );
3830 theElementSearcher = anEditor.GetElementSearcher();
3832 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
3833 SMDSAbs_ElementType( type ),
3835 res->length( foundElems.size() );
3836 for ( int i = 0; i < foundElems.size(); ++i )
3837 res[i] = foundElems[i]->GetID();
3839 if ( !myPreviewMode ) // call from tui
3840 TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
3849 //=======================================================================
3850 //function : GetPointState
3851 //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
3852 // TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
3853 //=======================================================================
3855 CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
3859 theSearchersDeleter.Set( myMesh );
3860 if ( !theElementSearcher ) {
3861 ::SMESH_MeshEditor anEditor( myMesh );
3862 theElementSearcher = anEditor.GetElementSearcher();
3864 return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
3867 //=======================================================================
3868 //function : convError
3870 //=======================================================================
3872 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
3874 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
3878 RETCASE( SEW_BORDER1_NOT_FOUND );
3879 RETCASE( SEW_BORDER2_NOT_FOUND );
3880 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
3881 RETCASE( SEW_BAD_SIDE_NODES );
3882 RETCASE( SEW_VOLUMES_TO_SPLIT );
3883 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
3884 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
3885 RETCASE( SEW_BAD_SIDE1_NODES );
3886 RETCASE( SEW_BAD_SIDE2_NODES );
3888 return SMESH::SMESH_MeshEditor::SEW_OK;
3891 //=======================================================================
3892 //function : SewFreeBorders
3894 //=======================================================================
3896 SMESH::SMESH_MeshEditor::Sew_Error
3897 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
3898 CORBA::Long SecondNodeID1,
3899 CORBA::Long LastNodeID1,
3900 CORBA::Long FirstNodeID2,
3901 CORBA::Long SecondNodeID2,
3902 CORBA::Long LastNodeID2,
3903 CORBA::Boolean CreatePolygons,
3904 CORBA::Boolean CreatePolyedrs)
3908 SMESHDS_Mesh* aMesh = GetMeshDS();
3910 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3911 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3912 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3913 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3914 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3915 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
3917 if (!aBorderFirstNode ||
3918 !aBorderSecondNode||
3920 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3921 if (!aSide2FirstNode ||
3922 !aSide2SecondNode ||
3924 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3926 TPythonDump() << "error = " << this << ".SewFreeBorders( "
3927 << FirstNodeID1 << ", "
3928 << SecondNodeID1 << ", "
3929 << LastNodeID1 << ", "
3930 << FirstNodeID2 << ", "
3931 << SecondNodeID2 << ", "
3932 << LastNodeID2 << ", "
3933 << CreatePolygons<< ", "
3934 << CreatePolyedrs<< " )";
3936 ::SMESH_MeshEditor anEditor( myMesh );
3937 SMESH::SMESH_MeshEditor::Sew_Error error =
3938 convError( anEditor.SewFreeBorder (aBorderFirstNode,
3948 storeResult(anEditor);
3954 //=======================================================================
3955 //function : SewConformFreeBorders
3957 //=======================================================================
3959 SMESH::SMESH_MeshEditor::Sew_Error
3960 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3961 CORBA::Long SecondNodeID1,
3962 CORBA::Long LastNodeID1,
3963 CORBA::Long FirstNodeID2,
3964 CORBA::Long SecondNodeID2)
3968 SMESHDS_Mesh* aMesh = GetMeshDS();
3970 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
3971 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3972 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
3973 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
3974 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
3975 const SMDS_MeshNode* aSide2ThirdNode = 0;
3977 if (!aBorderFirstNode ||
3978 !aBorderSecondNode||
3980 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3981 if (!aSide2FirstNode ||
3983 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3985 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
3986 << FirstNodeID1 << ", "
3987 << SecondNodeID1 << ", "
3988 << LastNodeID1 << ", "
3989 << FirstNodeID2 << ", "
3990 << SecondNodeID2 << " )";
3992 ::SMESH_MeshEditor anEditor( myMesh );
3993 SMESH::SMESH_MeshEditor::Sew_Error error =
3994 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4003 storeResult(anEditor);
4009 //=======================================================================
4010 //function : SewBorderToSide
4012 //=======================================================================
4014 SMESH::SMESH_MeshEditor::Sew_Error
4015 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
4016 CORBA::Long SecondNodeIDOnFreeBorder,
4017 CORBA::Long LastNodeIDOnFreeBorder,
4018 CORBA::Long FirstNodeIDOnSide,
4019 CORBA::Long LastNodeIDOnSide,
4020 CORBA::Boolean CreatePolygons,
4021 CORBA::Boolean CreatePolyedrs)
4025 SMESHDS_Mesh* aMesh = GetMeshDS();
4027 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
4028 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
4029 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
4030 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
4031 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
4032 const SMDS_MeshNode* aSide2ThirdNode = 0;
4034 if (!aBorderFirstNode ||
4035 !aBorderSecondNode||
4037 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4038 if (!aSide2FirstNode ||
4040 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
4042 TPythonDump() << "error = " << this << ".SewBorderToSide( "
4043 << FirstNodeIDOnFreeBorder << ", "
4044 << SecondNodeIDOnFreeBorder << ", "
4045 << LastNodeIDOnFreeBorder << ", "
4046 << FirstNodeIDOnSide << ", "
4047 << LastNodeIDOnSide << ", "
4048 << CreatePolygons << ", "
4049 << CreatePolyedrs << ") ";
4051 ::SMESH_MeshEditor anEditor( myMesh );
4052 SMESH::SMESH_MeshEditor::Sew_Error error =
4053 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4063 storeResult(anEditor);
4069 //=======================================================================
4070 //function : SewSideElements
4072 //=======================================================================
4074 SMESH::SMESH_MeshEditor::Sew_Error
4075 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
4076 const SMESH::long_array& IDsOfSide2Elements,
4077 CORBA::Long NodeID1OfSide1ToMerge,
4078 CORBA::Long NodeID1OfSide2ToMerge,
4079 CORBA::Long NodeID2OfSide1ToMerge,
4080 CORBA::Long NodeID2OfSide2ToMerge)
4084 SMESHDS_Mesh* aMesh = GetMeshDS();
4086 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
4087 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
4088 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
4089 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
4091 if (!aFirstNode1ToMerge ||
4092 !aFirstNode2ToMerge )
4093 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
4094 if (!aSecondNode1ToMerge||
4095 !aSecondNode2ToMerge)
4096 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
4098 TIDSortedElemSet aSide1Elems, aSide2Elems;
4099 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
4100 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
4102 TPythonDump() << "error = " << this << ".SewSideElements( "
4103 << IDsOfSide1Elements << ", "
4104 << IDsOfSide2Elements << ", "
4105 << NodeID1OfSide1ToMerge << ", "
4106 << NodeID1OfSide2ToMerge << ", "
4107 << NodeID2OfSide1ToMerge << ", "
4108 << NodeID2OfSide2ToMerge << ")";
4110 ::SMESH_MeshEditor anEditor( myMesh );
4111 SMESH::SMESH_MeshEditor::Sew_Error error =
4112 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
4115 aSecondNode1ToMerge,
4116 aSecondNode2ToMerge));
4118 storeResult(anEditor);
4123 //================================================================================
4125 * \brief Set new nodes for given element
4126 * \param ide - element id
4127 * \param newIDs - new node ids
4128 * \retval CORBA::Boolean - true if result is OK
4130 //================================================================================
4132 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
4133 const SMESH::long_array& newIDs)
4137 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
4138 if(!elem) return false;
4140 int nbn = newIDs.length();
4142 vector<const SMDS_MeshNode*> aNodes(nbn);
4145 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
4148 aNodes[nbn1] = aNode;
4151 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
4152 << ide << ", " << newIDs << " )";
4154 return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
4157 //================================================================================
4159 * \brief Update myLastCreated* or myPreviewData
4160 * \param anEditor - it contains last modification results
4162 //================================================================================
4164 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
4166 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
4168 list<int> aNodesConnectivity;
4169 typedef map<int, int> TNodesMap;
4172 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
4173 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
4175 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
4176 int nbEdges = aMeshDS->NbEdges();
4177 int nbFaces = aMeshDS->NbFaces();
4178 int nbVolum = aMeshDS->NbVolumes();
4179 switch ( previewType ) {
4180 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
4181 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
4182 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
4185 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
4186 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
4188 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
4190 while ( itMeshElems->more() ) {
4191 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
4192 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
4195 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
4196 while ( itElemNodes->more() ) {
4197 const SMDS_MeshNode* aMeshNode =
4198 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
4199 int aNodeID = aMeshNode->GetID();
4200 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
4201 if ( anIter == nodesMap.end() ) {
4202 // filling the nodes coordinates
4203 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
4204 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
4205 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
4206 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4209 aNodesConnectivity.push_back(anIter->second);
4212 // filling the elements types
4213 SMDSAbs_ElementType aType;
4215 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4216 aType = SMDSAbs_Node;
4220 aType = aMeshElem->GetType();
4221 isPoly = aMeshElem->IsPoly();
4224 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4225 myPreviewData->elementTypes[i].isPoly = isPoly;
4226 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4230 myPreviewData->nodesXYZ.length( j );
4232 // filling the elements connectivities
4233 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4234 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4235 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4236 myPreviewData->elementConnectivities[i] = *aConnIter;
4242 // add new nodes into myLastCreatedNodes
4243 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4244 myLastCreatedNodes->length(aSeq.Length());
4245 for(int i=0; i<aSeq.Length(); i++)
4246 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4249 // add new elements into myLastCreatedElems
4250 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4251 myLastCreatedElems->length(aSeq.Length());
4252 for(int i=0; i<aSeq.Length(); i++)
4253 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4257 //================================================================================
4259 * Return data of mesh edition preview
4261 //================================================================================
4263 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4265 return myPreviewData._retn();
4268 //================================================================================
4270 * \brief Returns list of it's IDs of created nodes
4271 * \retval SMESH::long_array* - list of node ID
4273 //================================================================================
4275 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4277 return myLastCreatedNodes._retn();
4280 //================================================================================
4282 * \brief Returns list of it's IDs of created elements
4283 * \retval SMESH::long_array* - list of elements' ID
4285 //================================================================================
4287 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4289 return myLastCreatedElems._retn();
4292 //=======================================================================
4293 //function : ConvertToQuadratic
4295 //=======================================================================
4297 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4299 ::SMESH_MeshEditor anEditor( myMesh );
4300 anEditor.ConvertToQuadratic(theForce3d);
4301 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4304 //=======================================================================
4305 //function : ConvertFromQuadratic
4307 //=======================================================================
4309 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4311 ::SMESH_MeshEditor anEditor( myMesh );
4312 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4313 TPythonDump() << this << ".ConvertFromQuadratic()";
4317 //=======================================================================
4318 //function : makeMesh
4319 //purpose : create a named imported mesh
4320 //=======================================================================
4322 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4324 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4325 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4326 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4327 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4328 gen->SetName( meshSO, theMeshName, "Mesh" );
4329 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4331 return mesh._retn();
4334 //=======================================================================
4335 //function : DumpGroupsList
4337 //=======================================================================
4338 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4339 const SMESH::ListOfGroups * theGroupList)
4341 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4342 if(isDumpGroupList) {
4343 theDumpPython << theGroupList << " = ";
4347 //================================================================================
4349 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4350 \param theNodes - identifiers of nodes to be doubled
4351 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4352 nodes. If list of element identifiers is empty then nodes are doubled but
4353 they not assigned to elements
4354 \return TRUE if operation has been completed successfully, FALSE otherwise
4355 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4357 //================================================================================
4359 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4360 const SMESH::long_array& theModifiedElems )
4364 ::SMESH_MeshEditor aMeshEditor( myMesh );
4365 list< int > aListOfNodes;
4367 for ( i = 0, n = theNodes.length(); i < n; i++ )
4368 aListOfNodes.push_back( theNodes[ i ] );
4370 list< int > aListOfElems;
4371 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4372 aListOfElems.push_back( theModifiedElems[ i ] );
4374 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4376 storeResult( aMeshEditor) ;
4381 //================================================================================
4383 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4384 This method provided for convenience works as DoubleNodes() described above.
4385 \param theNodeId - identifier of node to be doubled.
4386 \param theModifiedElems - identifiers of elements to be updated.
4387 \return TRUE if operation has been completed successfully, FALSE otherwise
4388 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4390 //================================================================================
4392 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4393 const SMESH::long_array& theModifiedElems )
4395 SMESH::long_array_var aNodes = new SMESH::long_array;
4396 aNodes->length( 1 );
4397 aNodes[ 0 ] = theNodeId;
4398 return DoubleNodes( aNodes, theModifiedElems );
4401 //================================================================================
4403 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4404 This method provided for convenience works as DoubleNodes() described above.
4405 \param theNodes - group of nodes to be doubled.
4406 \param theModifiedElems - group of elements to be updated.
4407 \return TRUE if operation has been completed successfully, FALSE otherwise
4408 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
4410 //================================================================================
4412 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(
4413 SMESH::SMESH_GroupBase_ptr theNodes,
4414 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4416 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4419 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4420 SMESH::long_array_var aModifiedElems;
4421 if ( !CORBA::is_nil( theModifiedElems ) )
4422 aModifiedElems = theModifiedElems->GetListOfID();
4425 aModifiedElems = new SMESH::long_array;
4426 aModifiedElems->length( 0 );
4429 return DoubleNodes( aNodes, aModifiedElems );
4432 //================================================================================
4434 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4435 This method provided for convenience works as DoubleNodes() described above.
4436 \param theNodes - list of groups of nodes to be doubled
4437 \param theModifiedElems - list of groups of elements to be updated.
4438 \return TRUE if operation has been completed successfully, FALSE otherwise
4439 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
4441 //================================================================================
4443 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(
4444 const SMESH::ListOfGroups& theNodes,
4445 const SMESH::ListOfGroups& theModifiedElems )
4449 ::SMESH_MeshEditor aMeshEditor( myMesh );
4451 std::list< int > aNodes;
4453 for ( i = 0, n = theNodes.length(); i < n; i++ )
4455 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
4456 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
4458 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4459 for ( j = 0, m = aCurr->length(); j < m; j++ )
4460 aNodes.push_back( aCurr[ j ] );
4464 std::list< int > anElems;
4465 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4467 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
4468 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
4470 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4471 for ( j = 0, m = aCurr->length(); j < m; j++ )
4472 anElems.push_back( aCurr[ j ] );
4476 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
4478 storeResult( aMeshEditor) ;
4483 //================================================================================
4485 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4486 \param theElems - the list of elements (edges or faces) to be replicated
4487 The nodes for duplication could be found from these elements
4488 \param theNodesNot - list of nodes to NOT replicate
4489 \param theAffectedElems - the list of elements (cells and edges) to which the
4490 replicated nodes should be associated to.
4491 \return TRUE if operation has been completed successfully, FALSE otherwise
4492 \sa DoubleNodeGroup(), DoubleNodeGroups()
4494 //================================================================================
4496 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
4497 const SMESH::long_array& theNodesNot,
4498 const SMESH::long_array& theAffectedElems )
4503 ::SMESH_MeshEditor aMeshEditor( myMesh );
4505 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4506 TIDSortedElemSet anElems, aNodes, anAffected;
4507 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4508 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4509 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
4511 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4513 storeResult( aMeshEditor) ;
4515 // Update Python script
4516 TPythonDump() << "isDone = " << this << ".DoubleNodes( " << theElems << ", "
4517 << theNodesNot << ", " << theAffectedElems << " )";
4521 //================================================================================
4523 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4524 \param theElems - the list of elements (edges or faces) to be replicated
4525 The nodes for duplication could be found from these elements
4526 \param theNodesNot - list of nodes to NOT replicate
4527 \param theShape - shape to detect affected elements (element which geometric center
4528 located on or inside shape).
4529 The replicated nodes should be associated to affected elements.
4530 \return TRUE if operation has been completed successfully, FALSE otherwise
4531 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
4533 //================================================================================
4535 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion
4536 ( const SMESH::long_array& theElems,
4537 const SMESH::long_array& theNodesNot,
4538 GEOM::GEOM_Object_ptr theShape )
4543 ::SMESH_MeshEditor aMeshEditor( myMesh );
4545 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4546 TIDSortedElemSet anElems, aNodes;
4547 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4548 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4550 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4551 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4553 storeResult( aMeshEditor) ;
4555 // Update Python script
4556 TPythonDump() << "isDone = " << this << ".DoubleNodesInRegion( " << theElems << ", "
4557 << theNodesNot << ", " << theShape << " )";
4561 //================================================================================
4563 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4564 \param theElems - group of of elements (edges or faces) to be replicated
4565 \param theNodesNot - group of nodes not to replicated
4566 \param theAffectedElems - group of elements to which the replicated nodes
4567 should be associated to.
4568 \return TRUE if operation has been completed successfully, FALSE otherwise
4569 \sa DoubleNodes(), DoubleNodeGroups()
4571 //================================================================================
4573 static void groupToSet(SMESH::SMESH_GroupBase_ptr theGrp,
4574 SMESHDS_Mesh* theMeshDS,
4575 TIDSortedElemSet& theElemSet,
4576 const SMDSAbs_ElementType theType)
4579 if ( CORBA::is_nil( theGrp ) )
4581 SMESH::long_array_var anIDs = theGrp->GetIDs();
4582 arrayToSet( anIDs, theMeshDS, theElemSet, theType);
4585 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(
4586 SMESH::SMESH_GroupBase_ptr theElems,
4587 SMESH::SMESH_GroupBase_ptr theNodesNot,
4588 SMESH::SMESH_GroupBase_ptr theAffectedElems )
4591 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4596 ::SMESH_MeshEditor aMeshEditor( myMesh );
4598 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4599 TIDSortedElemSet anElems, aNodes, anAffected;
4600 groupToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4601 groupToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4602 groupToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
4604 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4606 storeResult( aMeshEditor) ;
4608 // Update Python script
4609 TPythonDump() << "isDone = " << this << ".DoubleNodeGroup( " << theElems << ", "
4610 << theNodesNot << ", " << theAffectedElems << " )";
4614 //================================================================================
4616 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4617 \param theElems - group of of elements (edges or faces) to be replicated
4618 \param theNodesNot - group of nodes not to replicated
4619 \param theShape - shape to detect affected elements (element which geometric center
4620 located on or inside shape).
4621 The replicated nodes should be associated to affected elements.
4622 \return TRUE if operation has been completed successfully, FALSE otherwise
4623 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
4625 //================================================================================
4627 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(
4628 SMESH::SMESH_GroupBase_ptr theElems,
4629 SMESH::SMESH_GroupBase_ptr theNodesNot,
4630 GEOM::GEOM_Object_ptr theShape )
4633 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4638 ::SMESH_MeshEditor aMeshEditor( myMesh );
4640 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4641 TIDSortedElemSet anElems, aNodes, anAffected;
4642 groupToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4643 groupToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4645 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4646 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4648 storeResult( aMeshEditor) ;
4650 // Update Python script
4651 TPythonDump() << "isDone = " << this << ".DoubleNodeGroupInRegion( " << theElems << ", "
4652 << theNodesNot << ", " << theShape << " )";
4656 //================================================================================
4658 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4659 This method provided for convenience works as DoubleNodes() described above.
4660 \param theElems - list of groups of elements (edges or faces) to be replicated
4661 \param theNodesNot - list of groups of nodes not to replicated
4662 \param theAffectedElems - group of elements to which the replicated nodes
4663 should be associated to.
4664 \return TRUE if operation has been completed successfully, FALSE otherwise
4665 \sa DoubleNodeGroup(), DoubleNodes()
4667 //================================================================================
4669 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
4670 SMESHDS_Mesh* theMeshDS,
4671 TIDSortedElemSet& theElemSet,
4672 const bool theIsNodeGrp)
4674 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
4676 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
4677 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
4678 : aGrp->GetType() != SMESH::NODE ) )
4680 SMESH::long_array_var anIDs = aGrp->GetIDs();
4681 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
4686 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(
4687 const SMESH::ListOfGroups& theElems,
4688 const SMESH::ListOfGroups& theNodesNot,
4689 const SMESH::ListOfGroups& theAffectedElems )
4693 ::SMESH_MeshEditor aMeshEditor( myMesh );
4695 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4696 TIDSortedElemSet anElems, aNodes, anAffected;
4697 listOfGroupToSet(theElems, aMeshDS, anElems, false );
4698 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
4699 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
4701 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4703 storeResult( aMeshEditor) ;
4705 // Update Python script
4706 TPythonDump() << "isDone = " << this << ".DoubleNodeGroups( " << &theElems << ", "
4707 << &theNodesNot << ", " << &theAffectedElems << " )";
4711 //================================================================================
4713 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4714 This method provided for convenience works as DoubleNodes() described above.
4715 \param theElems - list of groups of elements (edges or faces) to be replicated
4716 \param theNodesNot - list of groups of nodes not to replicated
4717 \param theShape - shape to detect affected elements (element which geometric center
4718 located on or inside shape).
4719 The replicated nodes should be associated to affected elements.
4720 \return TRUE if operation has been completed successfully, FALSE otherwise
4721 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
4723 //================================================================================
4725 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(
4726 const SMESH::ListOfGroups& theElems,
4727 const SMESH::ListOfGroups& theNodesNot,
4728 GEOM::GEOM_Object_ptr theShape )
4732 ::SMESH_MeshEditor aMeshEditor( myMesh );
4734 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4735 TIDSortedElemSet anElems, aNodes;
4736 listOfGroupToSet(theElems, aMeshDS, anElems,false );
4737 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
4739 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4740 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4742 storeResult( aMeshEditor) ;
4744 // Update Python script
4745 TPythonDump() << "isDone = " << this << ".DoubleNodeGroupsInRegion( " << &theElems << ", "
4746 << &theNodesNot << ", " << theShape << " )";
4750 //================================================================================
4752 \brief Generated skin mesh (containing 2D cells) from 3D mesh
4753 The created 2D mesh elements based on nodes of free faces of boundary volumes
4754 \return TRUE if operation has been completed successfully, FALSE otherwise
4756 //================================================================================
4758 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
4762 ::SMESH_MeshEditor aMeshEditor( myMesh );
4763 bool aResult = aMeshEditor.Make2DMeshFrom3D();
4764 storeResult( aMeshEditor) ;
4766 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";