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_subMeshEventListener.hxx"
36 #include "SMESH_Gen_i.hxx"
37 #include "SMESH_Filter_i.hxx"
38 #include "SMESH_subMesh_i.hxx"
39 #include "SMESH_Group_i.hxx"
40 #include "SMESH_PythonDump.hxx"
41 #include "SMESH_ControlsDef.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>
70 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
73 using SMESH::TPythonDump;
77 //=============================================================================
79 * \brief Mesh to apply modifications for preview purposes
81 //=============================================================================
83 struct TPreviewMesh: public SMESH_Mesh
85 SMDSAbs_ElementType myPreviewType; // type to show
87 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
88 _isShapeToMesh = (_id =_studyId =_idDoc = 0);
89 _myMeshDS = new SMESHDS_Mesh( _id, true );
90 myPreviewType = previewElements;
93 virtual ~TPreviewMesh() { delete _myMeshDS; }
94 //!< Copy a set of elements
95 void Copy(const TIDSortedElemSet & theElements,
96 TIDSortedElemSet& theCopyElements,
97 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
98 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
100 // loop on theIDsOfElements
101 TIDSortedElemSet::const_iterator eIt = theElements.begin();
102 for ( ; eIt != theElements.end(); ++eIt )
104 const SMDS_MeshElement* anElem = *eIt;
105 if ( !anElem ) continue;
106 SMDSAbs_ElementType type = anElem->GetType();
107 if ( type == theAvoidType ||
108 ( theSelectType != SMDSAbs_All && type != theSelectType ))
111 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
112 theCopyElements.insert( theCopyElements.end(), anElemCopy );
116 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
118 // copy element nodes
119 int anElemNbNodes = anElem->NbNodes();
120 vector< int > anElemNodesID( anElemNbNodes ) ;
121 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
122 for ( int i = 0; itElemNodes->more(); i++)
124 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
126 anElemNodesID[i] = anElemNode->GetID();
129 // creates a corresponding element on copied nodes
130 SMDS_MeshElement* anElemCopy = 0;
131 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
133 const SMDS_PolyhedralVolumeOfNodes* ph =
134 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
136 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
137 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
140 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
147 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
149 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
150 anElemNode->GetID());
152 };// struct TPreviewMesh
154 static SMESH_NodeSearcher * theNodeSearcher = 0;
155 static SMESH_ElementSearcher * theElementSearcher = 0;
157 //=============================================================================
159 * \brief Deleter of theNodeSearcher at any compute event occured
161 //=============================================================================
163 struct TSearchersDeleter : public SMESH_subMeshEventListener
167 TSearchersDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
169 //!< Delete theNodeSearcher
172 if ( theNodeSearcher ) delete theNodeSearcher; theNodeSearcher = 0;
173 if ( theElementSearcher ) delete theElementSearcher; theElementSearcher = 0;
175 typedef map < int, SMESH_subMesh * > TDependsOnMap;
176 //!< The meshod called by submesh: do my main job
177 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
178 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
180 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
182 Unset( sm->GetFather() );
185 //!< set self on all submeshes and delete theNodeSearcher if other mesh is set
186 void Set(SMESH_Mesh* mesh)
188 if ( myMesh != mesh )
195 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
196 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
197 TDependsOnMap::const_iterator sm;
198 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
199 sm->second->SetEventListener( this, 0, sm->second );
203 //!< delete self from all submeshes
204 void Unset(SMESH_Mesh* mesh)
206 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
207 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
208 TDependsOnMap::const_iterator sm;
209 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
210 sm->second->DeleteEventListener( this );
215 } theSearchersDeleter;
217 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
219 TCollection_AsciiString typeStr;
220 switch ( theMirrorType ) {
221 case SMESH::SMESH_MeshEditor::POINT:
222 typeStr = "SMESH.SMESH_MeshEditor.POINT";
224 case SMESH::SMESH_MeshEditor::AXIS:
225 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
228 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
232 //================================================================================
234 * \brief function for conversion long_array to TIDSortedElemSet
235 * \param IDs - array of IDs
236 * \param aMesh - mesh
237 * \param aMap - collection to fill
238 * \param aType - element type
240 //================================================================================
242 void arrayToSet(const SMESH::long_array & IDs,
243 const SMESHDS_Mesh* aMesh,
244 TIDSortedElemSet& aMap,
245 const SMDSAbs_ElementType aType = SMDSAbs_All )
247 for (int i=0; i<IDs.length(); i++) {
248 CORBA::Long ind = IDs[i];
249 const SMDS_MeshElement * elem =
250 (aType == SMDSAbs_Node ? aMesh->FindNode(ind) : aMesh->FindElement(ind));
251 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
255 //================================================================================
257 * \brief Retrieve elements of given type from SMESH_IDSource
259 //================================================================================
261 bool idSourceToSet(SMESH::SMESH_IDSource_ptr theIDSource,
262 const SMESHDS_Mesh* theMeshDS,
263 TIDSortedElemSet& theElemSet,
264 const SMDSAbs_ElementType theType,
265 const bool emptyIfIsMesh=false)
268 if ( CORBA::is_nil( theIDSource ) )
270 if ( emptyIfIsMesh && SMESH::DownCast<SMESH_Mesh_i*>( theIDSource ))
273 SMESH::long_array_var anIDs = theIDSource->GetIDs();
274 if ( anIDs->length() == 0 )
276 SMESH::array_of_ElementType_var types = theIDSource->GetTypes();
277 if ( types->length() == 1 && types[0] == SMESH::NODE ) // group of nodes
279 if ( theType == SMDSAbs_All || theType == SMDSAbs_Node )
280 arrayToSet( anIDs, theMeshDS, theElemSet, SMDSAbs_Node );
286 arrayToSet( anIDs, theMeshDS, theElemSet, theType);
290 //================================================================================
292 * \brief Retrieve nodes from SMESH_IDSource
294 //================================================================================
296 void idSourceToNodeSet(SMESH::SMESH_IDSource_ptr theObject,
297 const SMESHDS_Mesh* theMeshDS,
298 TIDSortedNodeSet& theNodeSet)
301 if ( CORBA::is_nil( theObject ) )
303 SMESH::array_of_ElementType_var types = theObject->GetTypes();
304 SMESH::long_array_var aElementsId = theObject->GetIDs();
305 if ( types->length() == 1 && types[0] == SMESH::NODE)
307 for(int i = 0; i < aElementsId->length(); i++)
308 if ( const SMDS_MeshNode * n = theMeshDS->FindNode( aElementsId[i] ))
309 theNodeSet.insert( theNodeSet.end(), n);
312 for(int i = 0; i < aElementsId->length(); i++)
313 if( const SMDS_MeshElement * elem = theMeshDS->FindElement( aElementsId[i] ))
314 theNodeSet.insert( elem->begin_nodes(), elem->end_nodes());
319 //=============================================================================
323 //=============================================================================
325 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
328 myMesh = & theMesh->GetImpl();
329 myPreviewMode = isPreview;
332 //================================================================================
336 //================================================================================
338 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
342 //================================================================================
344 * \brief Clear members
346 //================================================================================
348 void SMESH_MeshEditor_i::initData(bool deleteSearchers)
350 if ( myPreviewMode ) {
351 myPreviewData = new SMESH::MeshPreviewStruct();
354 myLastCreatedElems = new SMESH::long_array();
355 myLastCreatedNodes = new SMESH::long_array();
356 if ( deleteSearchers )
357 TSearchersDeleter::Delete();
361 //=======================================================================
362 //function : MakeIDSource
363 //purpose : Wrap a sequence of ids in a SMESH_IDSource
364 //=======================================================================
366 struct _IDSource : public POA_SMESH::SMESH_IDSource
368 SMESH::long_array _ids;
369 SMESH::ElementType _type;
370 SMESH::long_array* GetIDs() { return new SMESH::long_array( _ids ); }
371 SMESH::long_array* GetMeshInfo() { return 0; }
372 SMESH::array_of_ElementType* GetTypes()
374 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
377 return types._retn();
381 SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_array& ids,
382 SMESH::ElementType type)
384 _IDSource* anIDSource = new _IDSource;
385 anIDSource->_ids = ids;
386 anIDSource->_type = type;
387 SMESH::SMESH_IDSource_var anIDSourceVar = anIDSource->_this();
389 return anIDSourceVar._retn();
392 //=============================================================================
396 //=============================================================================
399 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
403 ::SMESH_MeshEditor anEditor( myMesh );
406 for (int i = 0; i < IDsOfElements.length(); i++)
407 IdList.push_back( IDsOfElements[i] );
409 // Update Python script
410 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
412 if ( IDsOfElements.length() )
413 myMesh->SetIsModified( true ); // issue 0020693
416 return anEditor.Remove( IdList, false );
419 //=============================================================================
423 //=============================================================================
425 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
429 ::SMESH_MeshEditor anEditor( myMesh );
431 for (int i = 0; i < IDsOfNodes.length(); i++)
432 IdList.push_back( IDsOfNodes[i] );
434 // Update Python script
435 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
437 if ( IDsOfNodes.length() )
438 myMesh->SetIsModified( true ); // issue 0020693
440 return anEditor.Remove( IdList, true );
443 //=============================================================================
447 //=============================================================================
449 CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes()
453 ::SMESH_MeshEditor anEditor( myMesh );
455 // Update Python script
456 TPythonDump() << "nbRemoved = " << this << ".RemoveOrphanNodes()";
458 // Create filter to find all orphan nodes
459 SMESH::Controls::Filter::TIdSequence seq;
460 SMESH::Controls::PredicatePtr predicate( new SMESH::Controls::FreeNodes() );
461 SMESH::Controls::Filter::GetElementsId( GetMeshDS(), predicate, seq );
463 // remove orphan nodes (if there are any)
465 for ( int i = 0; i < seq.size(); i++ )
466 IdList.push_back( seq[i] );
469 myMesh->SetIsModified( true );
471 return anEditor.Remove( IdList, true );
474 //=============================================================================
478 //=============================================================================
480 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
481 CORBA::Double y, CORBA::Double z)
485 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
487 // Update Python script
488 TPythonDump() << "nodeID = " << this << ".AddNode( "
489 << x << ", " << y << ", " << z << " )";
491 myMesh->SetIsModified( true ); // issue 0020693
496 //=============================================================================
500 //=============================================================================
501 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
505 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
506 SMDS_MeshElement* elem = GetMeshDS()->Add0DElement(aNode);
508 // Update Python script
509 TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
511 myMesh->SetIsModified( true ); // issue 0020693
514 return elem->GetID();
519 //=============================================================================
523 //=============================================================================
525 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
529 int NbNodes = IDsOfNodes.length();
530 SMDS_MeshElement* elem = 0;
533 CORBA::Long index1 = IDsOfNodes[0];
534 CORBA::Long index2 = IDsOfNodes[1];
535 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
537 // Update Python script
538 TPythonDump() << "edge = " << this << ".AddEdge([ "
539 << index1 << ", " << index2 <<" ])";
542 CORBA::Long n1 = IDsOfNodes[0];
543 CORBA::Long n2 = IDsOfNodes[1];
544 CORBA::Long n12 = IDsOfNodes[2];
545 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
546 GetMeshDS()->FindNode(n2),
547 GetMeshDS()->FindNode(n12));
548 // Update Python script
549 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
550 <<n1<<", "<<n2<<", "<<n12<<" ])";
554 return myMesh->SetIsModified( true ), elem->GetID();
559 //=============================================================================
563 //=============================================================================
565 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
569 int NbNodes = IDsOfNodes.length();
575 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
576 for (int i = 0; i < NbNodes; i++)
577 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
579 SMDS_MeshElement* elem = 0;
581 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
583 else if (NbNodes == 4) {
584 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
586 else if (NbNodes == 6) {
587 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
590 else if (NbNodes == 8) {
591 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
592 nodes[4], nodes[5], nodes[6], nodes[7]);
594 else if (NbNodes > 2) {
595 elem = GetMeshDS()->AddPolygonalFace(nodes);
598 // Update Python script
599 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
602 return myMesh->SetIsModified( true ), elem->GetID();
607 //=============================================================================
611 //=============================================================================
612 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsOfNodes)
616 int NbNodes = IDsOfNodes.length();
617 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
618 for (int i = 0; i < NbNodes; i++)
619 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
621 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
623 // Update Python script
624 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
626 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
629 //=============================================================================
633 //=============================================================================
635 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
639 int NbNodes = IDsOfNodes.length();
640 vector< const SMDS_MeshNode*> n(NbNodes);
641 for(int i=0;i<NbNodes;i++)
642 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
644 SMDS_MeshElement* elem = 0;
647 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
648 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
649 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
650 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
651 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
652 n[6],n[7],n[8],n[9]);
654 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
655 n[7],n[8],n[9],n[10],n[11],n[12]);
657 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
658 n[9],n[10],n[11],n[12],n[13],n[14]);
660 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
661 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
662 n[15],n[16],n[17],n[18],n[19]);
666 // Update Python script
667 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
670 return myMesh->SetIsModified( true ), elem->GetID();
675 //=============================================================================
677 * AddPolyhedralVolume
679 //=============================================================================
680 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume (const SMESH::long_array & IDsOfNodes,
681 const SMESH::long_array & Quantities)
685 int NbNodes = IDsOfNodes.length();
686 std::vector<const SMDS_MeshNode*> n (NbNodes);
687 for (int i = 0; i < NbNodes; i++)
688 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
690 int NbFaces = Quantities.length();
691 std::vector<int> q (NbFaces);
692 for (int j = 0; j < NbFaces; j++)
693 q[j] = Quantities[j];
695 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
697 // Update Python script
698 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
699 << IDsOfNodes << ", " << Quantities << " )";
701 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
704 //=============================================================================
706 * AddPolyhedralVolumeByFaces
708 //=============================================================================
709 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_array & IdsOfFaces)
713 int NbFaces = IdsOfFaces.length();
714 std::vector<const SMDS_MeshNode*> poly_nodes;
715 std::vector<int> quantities (NbFaces);
717 for (int i = 0; i < NbFaces; i++) {
718 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
719 quantities[i] = aFace->NbNodes();
721 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
723 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
727 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
729 // Update Python script
730 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
731 << IdsOfFaces << " )";
733 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
736 //=============================================================================
738 * \brief Bind a node to a vertex
739 * \param NodeID - node ID
740 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
741 * \retval boolean - false if NodeID or VertexID is invalid
743 //=============================================================================
745 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
746 throw (SALOME::SALOME_Exception)
748 Unexpect aCatch(SALOME_SalomeException);
750 SMESHDS_Mesh * mesh = GetMeshDS();
751 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
753 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
755 if ( mesh->MaxShapeIndex() < VertexID )
756 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
758 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
759 if ( shape.ShapeType() != TopAbs_VERTEX )
760 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
762 mesh->SetNodeOnVertex( node, VertexID );
764 myMesh->SetIsModified( true );
767 //=============================================================================
769 * \brief Store node position on an edge
770 * \param NodeID - node ID
771 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
772 * \param paramOnEdge - parameter on edge where the node is located
773 * \retval boolean - false if any parameter is invalid
775 //=============================================================================
777 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
778 CORBA::Double paramOnEdge)
779 throw (SALOME::SALOME_Exception)
781 Unexpect aCatch(SALOME_SalomeException);
783 SMESHDS_Mesh * mesh = GetMeshDS();
784 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
786 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
788 if ( mesh->MaxShapeIndex() < EdgeID )
789 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
791 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
792 if ( shape.ShapeType() != TopAbs_EDGE )
793 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
796 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
797 if ( paramOnEdge < f || paramOnEdge > l )
798 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
800 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
802 myMesh->SetIsModified( true );
805 //=============================================================================
807 * \brief Store node position on a face
808 * \param NodeID - node ID
809 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
810 * \param u - U parameter on face where the node is located
811 * \param v - V parameter on face where the node is located
812 * \retval boolean - false if any parameter is invalid
814 //=============================================================================
816 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
817 CORBA::Double u, CORBA::Double v)
818 throw (SALOME::SALOME_Exception)
820 Unexpect aCatch(SALOME_SalomeException);
822 SMESHDS_Mesh * mesh = GetMeshDS();
823 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
825 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
827 if ( mesh->MaxShapeIndex() < FaceID )
828 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
830 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
831 if ( shape.ShapeType() != TopAbs_FACE )
832 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
834 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
835 bool isOut = ( u < surf.FirstUParameter() ||
836 u > surf.LastUParameter() ||
837 v < surf.FirstVParameter() ||
838 v > surf.LastVParameter() );
842 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
843 << " u( " << surf.FirstUParameter()
844 << "," << surf.LastUParameter()
845 << ") v( " << surf.FirstVParameter()
846 << "," << surf.LastVParameter() << ")" );
848 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
851 mesh->SetNodeOnFace( node, FaceID, u, v );
853 myMesh->SetIsModified( true );
856 //=============================================================================
858 * \brief Bind a node to a solid
859 * \param NodeID - node ID
860 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
861 * \retval boolean - false if NodeID or SolidID is invalid
863 //=============================================================================
865 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
866 throw (SALOME::SALOME_Exception)
868 Unexpect aCatch(SALOME_SalomeException);
870 SMESHDS_Mesh * mesh = GetMeshDS();
871 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
873 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
875 if ( mesh->MaxShapeIndex() < SolidID )
876 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
878 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
879 if ( shape.ShapeType() != TopAbs_SOLID &&
880 shape.ShapeType() != TopAbs_SHELL)
881 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
883 mesh->SetNodeInVolume( node, SolidID );
885 // myMesh->SetIsModified( true ); - SetNodeInVolume() can't prevent re-compute, I believe
888 //=============================================================================
890 * \brief Bind an element to a shape
891 * \param ElementID - element ID
892 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
893 * \retval boolean - false if ElementID or ShapeID is invalid
895 //=============================================================================
897 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
899 throw (SALOME::SALOME_Exception)
901 Unexpect aCatch(SALOME_SalomeException);
903 SMESHDS_Mesh * mesh = GetMeshDS();
904 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
906 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
908 if ( mesh->MaxShapeIndex() < ShapeID )
909 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
911 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
912 if ( shape.ShapeType() != TopAbs_EDGE &&
913 shape.ShapeType() != TopAbs_FACE &&
914 shape.ShapeType() != TopAbs_SOLID &&
915 shape.ShapeType() != TopAbs_SHELL )
916 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
918 mesh->SetMeshElementOnShape( elem, ShapeID );
920 myMesh->SetIsModified( true );
923 //=============================================================================
927 //=============================================================================
929 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
934 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
935 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
939 // Update Python script
940 TPythonDump() << "isDone = " << this << ".InverseDiag( "
941 << NodeID1 << ", " << NodeID2 << " )";
943 myMesh->SetIsModified( true );
945 ::SMESH_MeshEditor aMeshEditor( myMesh );
946 return aMeshEditor.InverseDiag ( n1, n2 );
949 //=============================================================================
953 //=============================================================================
955 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
960 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
961 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
965 // Update Python script
966 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
967 << NodeID1 << ", " << NodeID2 << " )";
969 ::SMESH_MeshEditor aMeshEditor( myMesh );
971 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
974 myMesh->SetIsModified( true ); // issue 0020693
976 storeResult(aMeshEditor);
981 //=============================================================================
985 //=============================================================================
987 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
991 ::SMESH_MeshEditor anEditor( myMesh );
992 for (int i = 0; i < IDsOfElements.length(); i++)
994 CORBA::Long index = IDsOfElements[i];
995 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
997 anEditor.Reorient( elem );
999 // Update Python script
1000 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
1002 if ( IDsOfElements.length() )
1003 myMesh->SetIsModified( true ); // issue 0020693
1009 //=============================================================================
1013 //=============================================================================
1015 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
1019 TPythonDump aTPythonDump; // suppress dump in Reorient()
1021 SMESH::long_array_var anElementsId = theObject->GetIDs();
1022 CORBA::Boolean isDone = Reorient(anElementsId);
1024 // Update Python script
1025 aTPythonDump << "isDone = " << this << ".ReorientObject( " << theObject << " )";
1030 //=============================================================================
1034 //=============================================================================
1035 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
1036 SMESH::NumericalFunctor_ptr Criterion,
1037 CORBA::Double MaxAngle)
1041 SMESHDS_Mesh* aMesh = GetMeshDS();
1042 TIDSortedElemSet faces;
1043 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1045 SMESH::NumericalFunctor_i* aNumericalFunctor =
1046 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1047 SMESH::Controls::NumericalFunctorPtr aCrit;
1048 if ( !aNumericalFunctor )
1049 aCrit.reset( new SMESH::Controls::AspectRatio() );
1051 aCrit = aNumericalFunctor->GetNumericalFunctor();
1053 // Update Python script
1054 TPythonDump() << "isDone = " << this << ".TriToQuad( "
1055 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1057 ::SMESH_MeshEditor anEditor( myMesh );
1059 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
1061 myMesh->SetIsModified( true ); // issue 0020693
1063 storeResult(anEditor);
1069 //=============================================================================
1073 //=============================================================================
1074 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1075 SMESH::NumericalFunctor_ptr Criterion,
1076 CORBA::Double MaxAngle)
1080 TPythonDump aTPythonDump; // suppress dump in TriToQuad()
1081 SMESH::long_array_var anElementsId = theObject->GetIDs();
1082 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
1084 SMESH::NumericalFunctor_i* aNumericalFunctor =
1085 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1087 // Update Python script
1088 aTPythonDump << "isDone = " << this << ".TriToQuadObject("
1089 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1095 //=============================================================================
1099 //=============================================================================
1100 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
1101 SMESH::NumericalFunctor_ptr Criterion)
1105 SMESHDS_Mesh* aMesh = GetMeshDS();
1106 TIDSortedElemSet faces;
1107 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1109 SMESH::NumericalFunctor_i* aNumericalFunctor =
1110 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1111 SMESH::Controls::NumericalFunctorPtr aCrit;
1112 if ( !aNumericalFunctor )
1113 aCrit.reset( new SMESH::Controls::AspectRatio() );
1115 aCrit = aNumericalFunctor->GetNumericalFunctor();
1118 // Update Python script
1119 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1121 ::SMESH_MeshEditor anEditor( myMesh );
1122 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1124 myMesh->SetIsModified( true ); // issue 0020693
1126 storeResult(anEditor);
1132 //=============================================================================
1136 //=============================================================================
1137 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1138 SMESH::NumericalFunctor_ptr Criterion)
1142 TPythonDump aTPythonDump; // suppress dump in QuadToTri()
1144 SMESH::long_array_var anElementsId = theObject->GetIDs();
1145 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1147 SMESH::NumericalFunctor_i* aNumericalFunctor =
1148 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1150 // Update Python script
1151 aTPythonDump << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1157 //=============================================================================
1161 //=============================================================================
1162 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1163 CORBA::Boolean Diag13)
1167 SMESHDS_Mesh* aMesh = GetMeshDS();
1168 TIDSortedElemSet faces;
1169 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1171 // Update Python script
1172 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1173 << IDsOfElements << ", " << Diag13 << " )";
1175 ::SMESH_MeshEditor anEditor( myMesh );
1176 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1178 myMesh->SetIsModified( true ); // issue 0020693
1181 storeResult(anEditor);
1187 //=============================================================================
1191 //=============================================================================
1192 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1193 CORBA::Boolean Diag13)
1197 TPythonDump aTPythonDump; // suppress dump in SplitQuad()
1199 SMESH::long_array_var anElementsId = theObject->GetIDs();
1200 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1202 // Update Python script
1203 aTPythonDump << "isDone = " << this << ".SplitQuadObject( "
1204 << theObject << ", " << Diag13 << " )";
1210 //=============================================================================
1214 //=============================================================================
1215 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1216 SMESH::NumericalFunctor_ptr Criterion)
1218 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1219 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1221 SMESH::NumericalFunctor_i* aNumericalFunctor =
1222 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1223 SMESH::Controls::NumericalFunctorPtr aCrit;
1224 if (aNumericalFunctor)
1225 aCrit = aNumericalFunctor->GetNumericalFunctor();
1227 aCrit.reset(new SMESH::Controls::AspectRatio());
1229 ::SMESH_MeshEditor anEditor (myMesh);
1230 return anEditor.BestSplit(quad, aCrit);
1235 //================================================================================
1237 * \brief Split volumic elements into tetrahedrons
1239 //================================================================================
1241 void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems,
1242 CORBA::Short methodFlags)
1243 throw (SALOME::SALOME_Exception)
1245 Unexpect aCatch(SALOME_SalomeException);
1247 SMESH::long_array_var anElementsId = elems->GetIDs();
1248 TIDSortedElemSet elemSet;
1249 arrayToSet( anElementsId, GetMeshDS(), elemSet, SMDSAbs_Volume );
1251 ::SMESH_MeshEditor anEditor (myMesh);
1252 anEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags ));
1254 storeResult(anEditor);
1256 // if ( myLastCreatedElems.length() ) - it does not influence Compute()
1257 // myMesh->SetIsModified( true ); // issue 0020693
1259 TPythonDump() << this << ".SplitVolumesIntoTetra( "
1260 << elems << ", " << methodFlags << " )";
1263 //=======================================================================
1266 //=======================================================================
1269 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1270 const SMESH::long_array & IDsOfFixedNodes,
1271 CORBA::Long MaxNbOfIterations,
1272 CORBA::Double MaxAspectRatio,
1273 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1275 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1276 MaxAspectRatio, Method, false );
1280 //=======================================================================
1281 //function : SmoothParametric
1283 //=======================================================================
1286 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1287 const SMESH::long_array & IDsOfFixedNodes,
1288 CORBA::Long MaxNbOfIterations,
1289 CORBA::Double MaxAspectRatio,
1290 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1292 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1293 MaxAspectRatio, Method, true );
1297 //=======================================================================
1298 //function : SmoothObject
1300 //=======================================================================
1303 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1304 const SMESH::long_array & IDsOfFixedNodes,
1305 CORBA::Long MaxNbOfIterations,
1306 CORBA::Double MaxAspectRatio,
1307 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1309 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1310 MaxAspectRatio, Method, false);
1314 //=======================================================================
1315 //function : SmoothParametricObject
1317 //=======================================================================
1320 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1321 const SMESH::long_array & IDsOfFixedNodes,
1322 CORBA::Long MaxNbOfIterations,
1323 CORBA::Double MaxAspectRatio,
1324 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1326 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1327 MaxAspectRatio, Method, true);
1331 //=============================================================================
1335 //=============================================================================
1338 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1339 const SMESH::long_array & IDsOfFixedNodes,
1340 CORBA::Long MaxNbOfIterations,
1341 CORBA::Double MaxAspectRatio,
1342 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1347 SMESHDS_Mesh* aMesh = GetMeshDS();
1349 TIDSortedElemSet elements;
1350 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1352 set<const SMDS_MeshNode*> fixedNodes;
1353 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1354 CORBA::Long index = IDsOfFixedNodes[i];
1355 const SMDS_MeshNode * node = aMesh->FindNode(index);
1357 fixedNodes.insert( node );
1359 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1360 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1361 method = ::SMESH_MeshEditor::CENTROIDAL;
1363 ::SMESH_MeshEditor anEditor( myMesh );
1364 anEditor.Smooth(elements, fixedNodes, method,
1365 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1367 myMesh->SetIsModified( true ); // issue 0020693
1369 storeResult(anEditor);
1371 // Update Python script
1372 TPythonDump() << "isDone = " << this << "."
1373 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1374 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1375 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1376 << "SMESH.SMESH_MeshEditor."
1377 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1378 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1384 //=============================================================================
1388 //=============================================================================
1391 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1392 const SMESH::long_array & IDsOfFixedNodes,
1393 CORBA::Long MaxNbOfIterations,
1394 CORBA::Double MaxAspectRatio,
1395 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1400 TPythonDump aTPythonDump; // suppress dump in smooth()
1402 SMESH::long_array_var anElementsId = theObject->GetIDs();
1403 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1404 MaxAspectRatio, Method, IsParametric);
1406 // Update Python script
1407 aTPythonDump << "isDone = " << this << "."
1408 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1409 << theObject << ", " << IDsOfFixedNodes << ", "
1410 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1411 << "SMESH.SMESH_MeshEditor."
1412 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1413 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1419 //=============================================================================
1423 //=============================================================================
1425 void SMESH_MeshEditor_i::RenumberNodes()
1427 // Update Python script
1428 TPythonDump() << this << ".RenumberNodes()";
1430 GetMeshDS()->Renumber( true );
1434 //=============================================================================
1438 //=============================================================================
1440 void SMESH_MeshEditor_i::RenumberElements()
1442 // Update Python script
1443 TPythonDump() << this << ".RenumberElements()";
1445 GetMeshDS()->Renumber( false );
1448 //=======================================================================
1450 * \brief Return groups by their IDs
1452 //=======================================================================
1454 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1458 myMesh_i->CreateGroupServants();
1459 return myMesh_i->GetGroups( *groupIDs );
1462 //=======================================================================
1463 //function : rotationSweep
1465 //=======================================================================
1467 SMESH::ListOfGroups*
1468 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1469 const SMESH::AxisStruct & theAxis,
1470 CORBA::Double theAngleInRadians,
1471 CORBA::Long theNbOfSteps,
1472 CORBA::Double theTolerance,
1473 const bool theMakeGroups,
1474 const SMDSAbs_ElementType theElementType)
1478 TIDSortedElemSet inElements, copyElements;
1479 arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType);
1481 TIDSortedElemSet* workElements = & inElements;
1482 TPreviewMesh tmpMesh( SMDSAbs_Face );
1483 SMESH_Mesh* mesh = 0;
1484 bool makeWalls=true;
1485 if ( myPreviewMode )
1487 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1488 tmpMesh.Copy( inElements, copyElements, select, avoid );
1490 workElements = & copyElements;
1491 //makeWalls = false;
1498 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1499 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1501 ::SMESH_MeshEditor anEditor( mesh );
1502 ::SMESH_MeshEditor::PGroupIDs groupIds =
1503 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1504 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1505 storeResult(anEditor);
1507 // myMesh->SetIsModified( true ); -- it does not influence Compute()
1509 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1512 //=======================================================================
1513 //function : RotationSweep
1515 //=======================================================================
1517 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1518 const SMESH::AxisStruct & theAxis,
1519 CORBA::Double theAngleInRadians,
1520 CORBA::Long theNbOfSteps,
1521 CORBA::Double theTolerance)
1523 if ( !myPreviewMode ) {
1524 TPythonDump() << this << ".RotationSweep( "
1525 << theIDsOfElements << ", "
1527 << theAngleInRadians << ", "
1528 << theNbOfSteps << ", "
1529 << theTolerance << " )";
1531 rotationSweep(theIDsOfElements,
1539 //=======================================================================
1540 //function : RotationSweepMakeGroups
1542 //=======================================================================
1544 SMESH::ListOfGroups*
1545 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1546 const SMESH::AxisStruct& theAxis,
1547 CORBA::Double theAngleInRadians,
1548 CORBA::Long theNbOfSteps,
1549 CORBA::Double theTolerance)
1551 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1557 if ( !myPreviewMode ) {
1558 TPythonDump aPythonDump;
1559 DumpGroupsList(aPythonDump,aGroups);
1560 aPythonDump<< this << ".RotationSweepMakeGroups( "
1561 << theIDsOfElements << ", "
1563 << theAngleInRadians << ", "
1564 << theNbOfSteps << ", "
1565 << theTolerance << " )";
1570 //=======================================================================
1571 //function : RotationSweepObject
1573 //=======================================================================
1575 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1576 const SMESH::AxisStruct & theAxis,
1577 CORBA::Double theAngleInRadians,
1578 CORBA::Long theNbOfSteps,
1579 CORBA::Double theTolerance)
1581 if ( !myPreviewMode ) {
1582 TPythonDump() << this << ".RotationSweepObject( "
1583 << theObject << ", "
1585 << theAngleInRadians << ", "
1586 << theNbOfSteps << ", "
1587 << theTolerance << " )";
1589 SMESH::long_array_var anElementsId = theObject->GetIDs();
1590 rotationSweep(anElementsId,
1598 //=======================================================================
1599 //function : RotationSweepObject1D
1601 //=======================================================================
1603 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1604 const SMESH::AxisStruct & theAxis,
1605 CORBA::Double theAngleInRadians,
1606 CORBA::Long theNbOfSteps,
1607 CORBA::Double theTolerance)
1609 if ( !myPreviewMode ) {
1610 TPythonDump() << this << ".RotationSweepObject1D( "
1611 << theObject << ", "
1613 << theAngleInRadians << ", "
1614 << theNbOfSteps << ", "
1615 << theTolerance << " )";
1617 SMESH::long_array_var anElementsId = theObject->GetIDs();
1618 rotationSweep(anElementsId,
1627 //=======================================================================
1628 //function : RotationSweepObject2D
1630 //=======================================================================
1632 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1633 const SMESH::AxisStruct & theAxis,
1634 CORBA::Double theAngleInRadians,
1635 CORBA::Long theNbOfSteps,
1636 CORBA::Double theTolerance)
1638 if ( !myPreviewMode ) {
1639 TPythonDump() << this << ".RotationSweepObject2D( "
1640 << theObject << ", "
1642 << theAngleInRadians << ", "
1643 << theNbOfSteps << ", "
1644 << theTolerance << " )";
1646 SMESH::long_array_var anElementsId = theObject->GetIDs();
1647 rotationSweep(anElementsId,
1656 //=======================================================================
1657 //function : RotationSweepObjectMakeGroups
1659 //=======================================================================
1661 SMESH::ListOfGroups*
1662 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1663 const SMESH::AxisStruct& theAxis,
1664 CORBA::Double theAngleInRadians,
1665 CORBA::Long theNbOfSteps,
1666 CORBA::Double theTolerance)
1668 SMESH::long_array_var anElementsId = theObject->GetIDs();
1669 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1675 if ( !myPreviewMode ) {
1676 TPythonDump aPythonDump;
1677 DumpGroupsList(aPythonDump,aGroups);
1678 aPythonDump<< this << ".RotationSweepObjectMakeGroups( "
1679 << theObject << ", "
1681 << theAngleInRadians << ", "
1682 << theNbOfSteps << ", "
1683 << theTolerance << " )";
1688 //=======================================================================
1689 //function : RotationSweepObject1DMakeGroups
1691 //=======================================================================
1693 SMESH::ListOfGroups*
1694 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1695 const SMESH::AxisStruct& theAxis,
1696 CORBA::Double theAngleInRadians,
1697 CORBA::Long theNbOfSteps,
1698 CORBA::Double theTolerance)
1700 SMESH::long_array_var anElementsId = theObject->GetIDs();
1701 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1708 if ( !myPreviewMode ) {
1709 TPythonDump aPythonDump;
1710 DumpGroupsList(aPythonDump,aGroups);
1711 aPythonDump<< this << ".RotationSweepObject1DMakeGroups( "
1712 << theObject << ", "
1714 << theAngleInRadians << ", "
1715 << theNbOfSteps << ", "
1716 << theTolerance << " )";
1721 //=======================================================================
1722 //function : RotationSweepObject2DMakeGroups
1724 //=======================================================================
1726 SMESH::ListOfGroups*
1727 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1728 const SMESH::AxisStruct& theAxis,
1729 CORBA::Double theAngleInRadians,
1730 CORBA::Long theNbOfSteps,
1731 CORBA::Double theTolerance)
1733 SMESH::long_array_var anElementsId = theObject->GetIDs();
1734 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1741 if ( !myPreviewMode ) {
1742 TPythonDump aPythonDump;
1743 DumpGroupsList(aPythonDump,aGroups);
1744 aPythonDump<< this << ".RotationSweepObject2DMakeGroups( "
1745 << theObject << ", "
1747 << theAngleInRadians << ", "
1748 << theNbOfSteps << ", "
1749 << theTolerance << " )";
1755 //=======================================================================
1756 //function : extrusionSweep
1758 //=======================================================================
1760 SMESH::ListOfGroups*
1761 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1762 const SMESH::DirStruct & theStepVector,
1763 CORBA::Long theNbOfSteps,
1764 const bool theMakeGroups,
1765 const SMDSAbs_ElementType theElementType)
1773 TIDSortedElemSet elements;
1774 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1776 const SMESH::PointStruct * P = &theStepVector.PS;
1777 gp_Vec stepVec( P->x, P->y, P->z );
1779 TElemOfElemListMap aHystory;
1780 ::SMESH_MeshEditor anEditor( myMesh );
1781 ::SMESH_MeshEditor::PGroupIDs groupIds =
1782 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1784 storeResult(anEditor);
1786 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1788 } catch(Standard_Failure) {
1789 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1790 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1795 //=======================================================================
1796 //function : ExtrusionSweep
1798 //=======================================================================
1800 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1801 const SMESH::DirStruct & theStepVector,
1802 CORBA::Long theNbOfSteps)
1804 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1805 if ( !myPreviewMode ) {
1806 TPythonDump() << this << ".ExtrusionSweep( "
1807 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1812 //=======================================================================
1813 //function : ExtrusionSweepObject
1815 //=======================================================================
1817 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1818 const SMESH::DirStruct & theStepVector,
1819 CORBA::Long theNbOfSteps)
1821 SMESH::long_array_var anElementsId = theObject->GetIDs();
1822 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1823 if ( !myPreviewMode ) {
1824 TPythonDump() << this << ".ExtrusionSweepObject( "
1825 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1829 //=======================================================================
1830 //function : ExtrusionSweepObject1D
1832 //=======================================================================
1834 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1835 const SMESH::DirStruct & theStepVector,
1836 CORBA::Long theNbOfSteps)
1838 SMESH::long_array_var anElementsId = theObject->GetIDs();
1839 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1840 if ( !myPreviewMode ) {
1841 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1842 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1846 //=======================================================================
1847 //function : ExtrusionSweepObject2D
1849 //=======================================================================
1851 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1852 const SMESH::DirStruct & theStepVector,
1853 CORBA::Long theNbOfSteps)
1855 SMESH::long_array_var anElementsId = theObject->GetIDs();
1856 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1857 if ( !myPreviewMode ) {
1858 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1859 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1863 //=======================================================================
1864 //function : ExtrusionSweepMakeGroups
1866 //=======================================================================
1868 SMESH::ListOfGroups*
1869 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1870 const SMESH::DirStruct& theStepVector,
1871 CORBA::Long theNbOfSteps)
1873 SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1875 if ( !myPreviewMode ) {
1876 TPythonDump aPythonDump;
1877 DumpGroupsList(aPythonDump,aGroups);
1878 aPythonDump << this << ".ExtrusionSweepMakeGroups( "
1879 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1883 //=======================================================================
1884 //function : ExtrusionSweepObjectMakeGroups
1886 //=======================================================================
1888 SMESH::ListOfGroups*
1889 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1890 const SMESH::DirStruct& theStepVector,
1891 CORBA::Long theNbOfSteps)
1893 SMESH::long_array_var anElementsId = theObject->GetIDs();
1894 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1896 if ( !myPreviewMode ) {
1897 TPythonDump aPythonDump;
1898 DumpGroupsList(aPythonDump,aGroups);
1899 aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( "
1900 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1905 //=======================================================================
1906 //function : ExtrusionSweepObject1DMakeGroups
1908 //=======================================================================
1910 SMESH::ListOfGroups*
1911 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1912 const SMESH::DirStruct& theStepVector,
1913 CORBA::Long theNbOfSteps)
1915 SMESH::long_array_var anElementsId = theObject->GetIDs();
1916 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1917 if ( !myPreviewMode ) {
1918 TPythonDump aPythonDump;
1919 DumpGroupsList(aPythonDump,aGroups);
1920 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( "
1921 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1926 //=======================================================================
1927 //function : ExtrusionSweepObject2DMakeGroups
1929 //=======================================================================
1931 SMESH::ListOfGroups*
1932 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1933 const SMESH::DirStruct& theStepVector,
1934 CORBA::Long theNbOfSteps)
1936 SMESH::long_array_var anElementsId = theObject->GetIDs();
1937 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1938 if ( !myPreviewMode ) {
1939 TPythonDump aPythonDump;
1940 DumpGroupsList(aPythonDump,aGroups);
1941 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( "
1942 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1948 //=======================================================================
1949 //function : advancedExtrusion
1951 //=======================================================================
1953 SMESH::ListOfGroups*
1954 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1955 const SMESH::DirStruct & theStepVector,
1956 CORBA::Long theNbOfSteps,
1957 CORBA::Long theExtrFlags,
1958 CORBA::Double theSewTolerance,
1959 const bool theMakeGroups)
1963 TIDSortedElemSet elements;
1964 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1966 const SMESH::PointStruct * P = &theStepVector.PS;
1967 gp_Vec stepVec( P->x, P->y, P->z );
1969 ::SMESH_MeshEditor anEditor( myMesh );
1970 TElemOfElemListMap aHystory;
1971 ::SMESH_MeshEditor::PGroupIDs groupIds =
1972 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1973 theMakeGroups, theExtrFlags, theSewTolerance);
1974 storeResult(anEditor);
1976 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1979 //=======================================================================
1980 //function : AdvancedExtrusion
1982 //=======================================================================
1984 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1985 const SMESH::DirStruct & theStepVector,
1986 CORBA::Long theNbOfSteps,
1987 CORBA::Long theExtrFlags,
1988 CORBA::Double theSewTolerance)
1990 if ( !myPreviewMode ) {
1991 TPythonDump() << "stepVector = " << theStepVector;
1992 TPythonDump() << this << ".AdvancedExtrusion("
1995 << theNbOfSteps << ","
1996 << theExtrFlags << ", "
1997 << theSewTolerance << " )";
1999 advancedExtrusion( theIDsOfElements,
2007 //=======================================================================
2008 //function : AdvancedExtrusionMakeGroups
2010 //=======================================================================
2012 SMESH::ListOfGroups*
2013 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
2014 const SMESH::DirStruct& theStepVector,
2015 CORBA::Long theNbOfSteps,
2016 CORBA::Long theExtrFlags,
2017 CORBA::Double theSewTolerance)
2019 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
2026 if ( !myPreviewMode ) {
2027 TPythonDump() << "stepVector = " << theStepVector;
2028 TPythonDump aPythonDump;
2029 DumpGroupsList(aPythonDump,aGroups);
2030 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
2033 << theNbOfSteps << ","
2034 << theExtrFlags << ", "
2035 << theSewTolerance << " )";
2041 //================================================================================
2043 * \brief Convert extrusion error to IDL enum
2045 //================================================================================
2047 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2049 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
2053 RETCASE( EXTR_NO_ELEMENTS );
2054 RETCASE( EXTR_PATH_NOT_EDGE );
2055 RETCASE( EXTR_BAD_PATH_SHAPE );
2056 RETCASE( EXTR_BAD_STARTING_NODE );
2057 RETCASE( EXTR_BAD_ANGLES_NUMBER );
2058 RETCASE( EXTR_CANT_GET_TANGENT );
2060 return SMESH::SMESH_MeshEditor::EXTR_OK;
2064 //=======================================================================
2065 //function : extrusionAlongPath
2067 //=======================================================================
2069 SMESH::ListOfGroups*
2070 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2071 SMESH::SMESH_Mesh_ptr thePathMesh,
2072 GEOM::GEOM_Object_ptr thePathShape,
2073 CORBA::Long theNodeStart,
2074 CORBA::Boolean theHasAngles,
2075 const SMESH::double_array & theAngles,
2076 CORBA::Boolean theHasRefPoint,
2077 const SMESH::PointStruct & theRefPoint,
2078 const bool theMakeGroups,
2079 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
2080 const SMDSAbs_ElementType theElementType)
2084 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
2085 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2088 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2090 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2091 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2093 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
2094 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2098 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
2100 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2104 TIDSortedElemSet elements;
2105 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
2107 list<double> angles;
2108 for (int i = 0; i < theAngles.length(); i++) {
2109 angles.push_back( theAngles[i] );
2112 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
2114 int nbOldGroups = myMesh->NbGroup();
2116 ::SMESH_MeshEditor anEditor( myMesh );
2117 ::SMESH_MeshEditor::Extrusion_Error error =
2118 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
2119 theHasAngles, angles, false,
2120 theHasRefPoint, refPnt, theMakeGroups );
2121 storeResult(anEditor);
2122 theError = convExtrError( error );
2124 if ( theMakeGroups ) {
2125 list<int> groupIDs = myMesh->GetGroupIds();
2126 list<int>::iterator newBegin = groupIDs.begin();
2127 std::advance( newBegin, nbOldGroups ); // skip old groups
2128 groupIDs.erase( groupIDs.begin(), newBegin );
2129 return getGroups( & groupIDs );
2135 //=======================================================================
2136 //function : extrusionAlongPathX
2138 //=======================================================================
2140 SMESH::ListOfGroups*
2141 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2142 SMESH::SMESH_IDSource_ptr Path,
2143 CORBA::Long NodeStart,
2144 CORBA::Boolean HasAngles,
2145 const SMESH::double_array& Angles,
2146 CORBA::Boolean LinearVariation,
2147 CORBA::Boolean HasRefPoint,
2148 const SMESH::PointStruct& RefPoint,
2149 const bool MakeGroups,
2150 const SMDSAbs_ElementType ElementType,
2151 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2153 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2157 list<double> angles;
2158 for (int i = 0; i < Angles.length(); i++) {
2159 angles.push_back( Angles[i] );
2161 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2162 int nbOldGroups = myMesh->NbGroup();
2164 if ( Path->_is_nil() ) {
2165 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2169 TIDSortedElemSet elements;
2170 arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
2172 ::SMESH_MeshEditor anEditor( myMesh );
2173 ::SMESH_MeshEditor::Extrusion_Error error;
2175 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
2178 SMDS_MeshNode* aNodeStart =
2179 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2180 if ( !aNodeStart ) {
2181 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2184 error = anEditor.ExtrusionAlongTrack( elements, &(aMeshImp->GetImpl()), aNodeStart,
2185 HasAngles, angles, LinearVariation,
2186 HasRefPoint, refPnt, MakeGroups );
2189 SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
2192 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
2193 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
2194 SMDS_MeshNode* aNodeStart =
2195 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2196 if ( !aNodeStart ) {
2197 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2200 SMESH_subMesh* aSubMesh =
2201 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
2202 error = anEditor.ExtrusionAlongTrack( elements, aSubMesh, aNodeStart,
2203 HasAngles, angles, LinearVariation,
2204 HasRefPoint, refPnt, MakeGroups );
2207 SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
2209 // path as group of 1D elements
2213 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2219 storeResult(anEditor);
2220 Error = convExtrError( error );
2223 list<int> groupIDs = myMesh->GetGroupIds();
2224 list<int>::iterator newBegin = groupIDs.begin();
2225 std::advance( newBegin, nbOldGroups ); // skip old groups
2226 groupIDs.erase( groupIDs.begin(), newBegin );
2227 return getGroups( & groupIDs );
2233 //=======================================================================
2234 //function : ExtrusionAlongPath
2236 //=======================================================================
2238 SMESH::SMESH_MeshEditor::Extrusion_Error
2239 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2240 SMESH::SMESH_Mesh_ptr thePathMesh,
2241 GEOM::GEOM_Object_ptr thePathShape,
2242 CORBA::Long theNodeStart,
2243 CORBA::Boolean theHasAngles,
2244 const SMESH::double_array & theAngles,
2245 CORBA::Boolean theHasRefPoint,
2246 const SMESH::PointStruct & theRefPoint)
2248 if ( !myPreviewMode ) {
2249 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
2250 << theIDsOfElements << ", "
2251 << thePathMesh << ", "
2252 << thePathShape << ", "
2253 << theNodeStart << ", "
2254 << theHasAngles << ", "
2255 << theAngles << ", "
2256 << theHasRefPoint << ", "
2257 << "SMESH.PointStruct( "
2258 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2259 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2260 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2262 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2263 extrusionAlongPath( theIDsOfElements,
2276 //=======================================================================
2277 //function : ExtrusionAlongPathObject
2279 //=======================================================================
2281 SMESH::SMESH_MeshEditor::Extrusion_Error
2282 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
2283 SMESH::SMESH_Mesh_ptr thePathMesh,
2284 GEOM::GEOM_Object_ptr thePathShape,
2285 CORBA::Long theNodeStart,
2286 CORBA::Boolean theHasAngles,
2287 const SMESH::double_array & theAngles,
2288 CORBA::Boolean theHasRefPoint,
2289 const SMESH::PointStruct & theRefPoint)
2291 if ( !myPreviewMode ) {
2292 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
2293 << theObject << ", "
2294 << thePathMesh << ", "
2295 << thePathShape << ", "
2296 << theNodeStart << ", "
2297 << theHasAngles << ", "
2298 << theAngles << ", "
2299 << theHasRefPoint << ", "
2300 << "SMESH.PointStruct( "
2301 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2302 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2303 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2305 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2306 SMESH::long_array_var anElementsId = theObject->GetIDs();
2307 extrusionAlongPath( anElementsId,
2320 //=======================================================================
2321 //function : ExtrusionAlongPathObject1D
2323 //=======================================================================
2325 SMESH::SMESH_MeshEditor::Extrusion_Error
2326 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
2327 SMESH::SMESH_Mesh_ptr thePathMesh,
2328 GEOM::GEOM_Object_ptr thePathShape,
2329 CORBA::Long theNodeStart,
2330 CORBA::Boolean theHasAngles,
2331 const SMESH::double_array & theAngles,
2332 CORBA::Boolean theHasRefPoint,
2333 const SMESH::PointStruct & theRefPoint)
2335 if ( !myPreviewMode ) {
2336 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
2337 << theObject << ", "
2338 << thePathMesh << ", "
2339 << thePathShape << ", "
2340 << theNodeStart << ", "
2341 << theHasAngles << ", "
2342 << theAngles << ", "
2343 << theHasRefPoint << ", "
2344 << "SMESH.PointStruct( "
2345 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2346 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2347 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2349 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2350 SMESH::long_array_var anElementsId = theObject->GetIDs();
2351 extrusionAlongPath( anElementsId,
2365 //=======================================================================
2366 //function : ExtrusionAlongPathObject2D
2368 //=======================================================================
2370 SMESH::SMESH_MeshEditor::Extrusion_Error
2371 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
2372 SMESH::SMESH_Mesh_ptr thePathMesh,
2373 GEOM::GEOM_Object_ptr thePathShape,
2374 CORBA::Long theNodeStart,
2375 CORBA::Boolean theHasAngles,
2376 const SMESH::double_array & theAngles,
2377 CORBA::Boolean theHasRefPoint,
2378 const SMESH::PointStruct & theRefPoint)
2380 if ( !myPreviewMode ) {
2381 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
2382 << theObject << ", "
2383 << thePathMesh << ", "
2384 << thePathShape << ", "
2385 << theNodeStart << ", "
2386 << theHasAngles << ", "
2387 << theAngles << ", "
2388 << theHasRefPoint << ", "
2389 << "SMESH.PointStruct( "
2390 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2391 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2392 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2394 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2395 SMESH::long_array_var anElementsId = theObject->GetIDs();
2396 extrusionAlongPath( anElementsId,
2411 //=======================================================================
2412 //function : ExtrusionAlongPathMakeGroups
2414 //=======================================================================
2416 SMESH::ListOfGroups*
2417 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2418 SMESH::SMESH_Mesh_ptr thePathMesh,
2419 GEOM::GEOM_Object_ptr thePathShape,
2420 CORBA::Long theNodeStart,
2421 CORBA::Boolean theHasAngles,
2422 const SMESH::double_array& theAngles,
2423 CORBA::Boolean theHasRefPoint,
2424 const SMESH::PointStruct& theRefPoint,
2425 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2427 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2437 if ( !myPreviewMode ) {
2438 bool isDumpGroups = aGroups && aGroups->length() > 0;
2439 TPythonDump aPythonDump;
2441 aPythonDump << "("<<aGroups;
2444 aPythonDump << ", error)";
2446 aPythonDump <<"error";
2448 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2449 << theIDsOfElements << ", "
2450 << thePathMesh << ", "
2451 << thePathShape << ", "
2452 << theNodeStart << ", "
2453 << theHasAngles << ", "
2454 << theAngles << ", "
2455 << theHasRefPoint << ", "
2456 << "SMESH.PointStruct( "
2457 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2458 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2459 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2464 //=======================================================================
2465 //function : ExtrusionAlongPathObjectMakeGroups
2467 //=======================================================================
2469 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2470 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2471 SMESH::SMESH_Mesh_ptr thePathMesh,
2472 GEOM::GEOM_Object_ptr thePathShape,
2473 CORBA::Long theNodeStart,
2474 CORBA::Boolean theHasAngles,
2475 const SMESH::double_array& theAngles,
2476 CORBA::Boolean theHasRefPoint,
2477 const SMESH::PointStruct& theRefPoint,
2478 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2480 SMESH::long_array_var anElementsId = theObject->GetIDs();
2481 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2492 if ( !myPreviewMode ) {
2493 bool isDumpGroups = aGroups && aGroups->length() > 0;
2494 TPythonDump aPythonDump;
2496 aPythonDump << "("<<aGroups;
2499 aPythonDump << ", error)";
2501 aPythonDump <<"error";
2503 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2504 << theObject << ", "
2505 << thePathMesh << ", "
2506 << thePathShape << ", "
2507 << theNodeStart << ", "
2508 << theHasAngles << ", "
2509 << theAngles << ", "
2510 << theHasRefPoint << ", "
2511 << "SMESH.PointStruct( "
2512 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2513 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2514 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2519 //=======================================================================
2520 //function : ExtrusionAlongPathObject1DMakeGroups
2522 //=======================================================================
2524 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2525 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2526 SMESH::SMESH_Mesh_ptr thePathMesh,
2527 GEOM::GEOM_Object_ptr thePathShape,
2528 CORBA::Long theNodeStart,
2529 CORBA::Boolean theHasAngles,
2530 const SMESH::double_array& theAngles,
2531 CORBA::Boolean theHasRefPoint,
2532 const SMESH::PointStruct& theRefPoint,
2533 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2535 SMESH::long_array_var anElementsId = theObject->GetIDs();
2536 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2548 if ( !myPreviewMode ) {
2549 bool isDumpGroups = aGroups && aGroups->length() > 0;
2550 TPythonDump aPythonDump;
2552 aPythonDump << "("<<aGroups;
2555 aPythonDump << ", error)";
2557 aPythonDump <<"error";
2559 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
2560 << theObject << ", "
2561 << thePathMesh << ", "
2562 << thePathShape << ", "
2563 << theNodeStart << ", "
2564 << theHasAngles << ", "
2565 << theAngles << ", "
2566 << theHasRefPoint << ", "
2567 << "SMESH.PointStruct( "
2568 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2569 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2570 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2575 //=======================================================================
2576 //function : ExtrusionAlongPathObject2DMakeGroups
2578 //=======================================================================
2580 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2581 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2582 SMESH::SMESH_Mesh_ptr thePathMesh,
2583 GEOM::GEOM_Object_ptr thePathShape,
2584 CORBA::Long theNodeStart,
2585 CORBA::Boolean theHasAngles,
2586 const SMESH::double_array& theAngles,
2587 CORBA::Boolean theHasRefPoint,
2588 const SMESH::PointStruct& theRefPoint,
2589 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2591 SMESH::long_array_var anElementsId = theObject->GetIDs();
2592 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2604 if ( !myPreviewMode ) {
2605 bool isDumpGroups = aGroups && aGroups->length() > 0;
2606 TPythonDump aPythonDump;
2608 aPythonDump << "("<<aGroups;
2611 aPythonDump << ", error)";
2613 aPythonDump <<"error";
2615 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
2616 << theObject << ", "
2617 << thePathMesh << ", "
2618 << thePathShape << ", "
2619 << theNodeStart << ", "
2620 << theHasAngles << ", "
2621 << theAngles << ", "
2622 << theHasRefPoint << ", "
2623 << "SMESH.PointStruct( "
2624 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2625 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2626 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2632 //=======================================================================
2633 //function : ExtrusionAlongPathObjX
2635 //=======================================================================
2636 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2637 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
2638 SMESH::SMESH_IDSource_ptr Path,
2639 CORBA::Long NodeStart,
2640 CORBA::Boolean HasAngles,
2641 const SMESH::double_array& Angles,
2642 CORBA::Boolean LinearVariation,
2643 CORBA::Boolean HasRefPoint,
2644 const SMESH::PointStruct& RefPoint,
2645 CORBA::Boolean MakeGroups,
2646 SMESH::ElementType ElemType,
2647 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2649 SMESH::long_array_var anElementsId = Object->GetIDs();
2650 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2659 (SMDSAbs_ElementType)ElemType,
2662 if ( !myPreviewMode ) {
2663 bool isDumpGroups = aGroups && aGroups->length() > 0;
2664 TPythonDump aPythonDump;
2666 aPythonDump << "("<<aGroups;
2669 aPythonDump << ", error)";
2671 aPythonDump <<"error";
2673 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2676 << NodeStart << ", "
2677 << HasAngles << ", "
2679 << LinearVariation << ", "
2680 << HasRefPoint << ", "
2681 << "SMESH.PointStruct( "
2682 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2683 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2684 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2685 << MakeGroups << ", "
2686 << ElemType << " )";
2692 //=======================================================================
2693 //function : ExtrusionAlongPathX
2695 //=======================================================================
2696 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2697 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2698 SMESH::SMESH_IDSource_ptr Path,
2699 CORBA::Long NodeStart,
2700 CORBA::Boolean HasAngles,
2701 const SMESH::double_array& Angles,
2702 CORBA::Boolean LinearVariation,
2703 CORBA::Boolean HasRefPoint,
2704 const SMESH::PointStruct& RefPoint,
2705 CORBA::Boolean MakeGroups,
2706 SMESH::ElementType ElemType,
2707 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2709 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2718 (SMDSAbs_ElementType)ElemType,
2721 if ( !myPreviewMode ) {
2722 bool isDumpGroups = aGroups && aGroups->length() > 0;
2723 TPythonDump aPythonDump;
2725 aPythonDump << "("<<aGroups;
2728 aPythonDump << ", error)";
2730 aPythonDump <<"error";
2732 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2733 << IDsOfElements << ", "
2735 << NodeStart << ", "
2736 << HasAngles << ", "
2738 << LinearVariation << ", "
2739 << HasRefPoint << ", "
2740 << "SMESH.PointStruct( "
2741 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2742 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2743 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2744 << ElemType << " )";
2750 //================================================================================
2752 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2753 * of given angles along path steps
2754 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2755 * which proceeds the extrusion
2756 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2757 * is used to define the sub-mesh for the path
2759 //================================================================================
2761 SMESH::double_array*
2762 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2763 GEOM::GEOM_Object_ptr thePathShape,
2764 const SMESH::double_array & theAngles)
2766 SMESH::double_array_var aResult = new SMESH::double_array();
2767 int nbAngles = theAngles.length();
2768 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2770 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2771 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2772 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2773 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2774 return aResult._retn();
2775 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2776 if ( nbSteps == nbAngles )
2778 aResult.inout() = theAngles;
2782 aResult->length( nbSteps );
2783 double rAn2St = double( nbAngles ) / double( nbSteps );
2784 double angPrev = 0, angle;
2785 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2787 double angCur = rAn2St * ( iSt+1 );
2788 double angCurFloor = floor( angCur );
2789 double angPrevFloor = floor( angPrev );
2790 if ( angPrevFloor == angCurFloor )
2791 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2794 int iP = int( angPrevFloor );
2795 double angPrevCeil = ceil(angPrev);
2796 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2798 int iC = int( angCurFloor );
2799 if ( iC < nbAngles )
2800 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2802 iP = int( angPrevCeil );
2804 angle += theAngles[ iC ];
2806 aResult[ iSt ] = angle;
2811 // Update Python script
2812 TPythonDump() << "rotAngles = " << theAngles;
2813 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2814 << thePathMesh << ", "
2815 << thePathShape << ", "
2818 return aResult._retn();
2822 //=======================================================================
2825 //=======================================================================
2827 SMESH::ListOfGroups*
2828 SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements,
2829 const SMESH::AxisStruct & theAxis,
2830 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2831 CORBA::Boolean theCopy,
2832 const bool theMakeGroups,
2833 ::SMESH_Mesh* theTargetMesh)
2837 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2838 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2841 switch ( theMirrorType ) {
2842 case SMESH::SMESH_MeshEditor::POINT:
2843 aTrsf.SetMirror( P );
2845 case SMESH::SMESH_MeshEditor::AXIS:
2846 aTrsf.SetMirror( gp_Ax1( P, V ));
2849 aTrsf.SetMirror( gp_Ax2( P, V ));
2852 ::SMESH_MeshEditor anEditor( myMesh );
2853 ::SMESH_MeshEditor::PGroupIDs groupIds =
2854 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2857 storeResult(anEditor);
2859 myMesh->SetIsModified( true );
2861 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2864 //=======================================================================
2867 //=======================================================================
2869 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2870 const SMESH::AxisStruct & theAxis,
2871 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2872 CORBA::Boolean theCopy)
2874 if ( !myPreviewMode ) {
2875 TPythonDump() << this << ".Mirror( "
2876 << theIDsOfElements << ", "
2878 << mirrorTypeName(theMirrorType) << ", "
2881 if ( theIDsOfElements.length() > 0 )
2883 TIDSortedElemSet elements;
2884 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2885 mirror(elements, theAxis, theMirrorType, theCopy, false);
2890 //=======================================================================
2891 //function : MirrorObject
2893 //=======================================================================
2895 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2896 const SMESH::AxisStruct & theAxis,
2897 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2898 CORBA::Boolean theCopy)
2900 if ( !myPreviewMode ) {
2901 TPythonDump() << this << ".MirrorObject( "
2902 << theObject << ", "
2904 << mirrorTypeName(theMirrorType) << ", "
2907 TIDSortedElemSet elements;
2908 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2909 mirror(elements, theAxis, theMirrorType, theCopy, false);
2912 //=======================================================================
2913 //function : MirrorMakeGroups
2915 //=======================================================================
2917 SMESH::ListOfGroups*
2918 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2919 const SMESH::AxisStruct& theMirror,
2920 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2922 SMESH::ListOfGroups * aGroups = 0;
2923 if ( theIDsOfElements.length() > 0 )
2925 TIDSortedElemSet elements;
2926 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2927 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2929 if ( !myPreviewMode ) {
2930 TPythonDump aPythonDump;
2931 DumpGroupsList(aPythonDump,aGroups);
2932 aPythonDump << this << ".MirrorMakeGroups( "
2933 << theIDsOfElements << ", "
2934 << theMirror << ", "
2935 << mirrorTypeName(theMirrorType) << " )";
2940 //=======================================================================
2941 //function : MirrorObjectMakeGroups
2943 //=======================================================================
2945 SMESH::ListOfGroups*
2946 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2947 const SMESH::AxisStruct& theMirror,
2948 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2950 SMESH::ListOfGroups * aGroups = 0;
2951 TIDSortedElemSet elements;
2952 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2953 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2955 if ( !myPreviewMode )
2957 TPythonDump aPythonDump;
2958 DumpGroupsList(aPythonDump,aGroups);
2959 aPythonDump << this << ".MirrorObjectMakeGroups( "
2960 << theObject << ", "
2961 << theMirror << ", "
2962 << mirrorTypeName(theMirrorType) << " )";
2967 //=======================================================================
2968 //function : MirrorMakeMesh
2970 //=======================================================================
2972 SMESH::SMESH_Mesh_ptr
2973 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2974 const SMESH::AxisStruct& theMirror,
2975 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2976 CORBA::Boolean theCopyGroups,
2977 const char* theMeshName)
2979 SMESH_Mesh_i* mesh_i;
2980 SMESH::SMESH_Mesh_var mesh;
2981 { // open new scope to dump "MakeMesh" command
2982 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2984 TPythonDump pydump; // to prevent dump at mesh creation
2986 mesh = makeMesh( theMeshName );
2987 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2988 if (mesh_i && theIDsOfElements.length() > 0 )
2990 TIDSortedElemSet elements;
2991 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2992 mirror(elements, theMirror, theMirrorType,
2993 false, theCopyGroups, & mesh_i->GetImpl());
2994 mesh_i->CreateGroupServants();
2997 if ( !myPreviewMode ) {
2998 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2999 << theIDsOfElements << ", "
3000 << theMirror << ", "
3001 << mirrorTypeName(theMirrorType) << ", "
3002 << theCopyGroups << ", '"
3003 << theMeshName << "' )";
3008 if(!myPreviewMode && mesh_i)
3009 mesh_i->GetGroups();
3011 return mesh._retn();
3014 //=======================================================================
3015 //function : MirrorObjectMakeMesh
3017 //=======================================================================
3019 SMESH::SMESH_Mesh_ptr
3020 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3021 const SMESH::AxisStruct& theMirror,
3022 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3023 CORBA::Boolean theCopyGroups,
3024 const char* theMeshName)
3026 SMESH_Mesh_i* mesh_i;
3027 SMESH::SMESH_Mesh_var mesh;
3028 { // open new scope to dump "MakeMesh" command
3029 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3031 TPythonDump pydump; // to prevent dump at mesh creation
3033 mesh = makeMesh( theMeshName );
3034 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3035 TIDSortedElemSet elements;
3037 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3039 mirror(elements, theMirror, theMirrorType,
3040 false, theCopyGroups, & mesh_i->GetImpl());
3041 mesh_i->CreateGroupServants();
3043 if ( !myPreviewMode ) {
3044 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
3045 << theObject << ", "
3046 << theMirror << ", "
3047 << mirrorTypeName(theMirrorType) << ", "
3048 << theCopyGroups << ", '"
3049 << theMeshName << "' )";
3054 if(!myPreviewMode && mesh_i)
3055 mesh_i->GetGroups();
3057 return mesh._retn();
3060 //=======================================================================
3061 //function : translate
3063 //=======================================================================
3065 SMESH::ListOfGroups*
3066 SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements,
3067 const SMESH::DirStruct & theVector,
3068 CORBA::Boolean theCopy,
3069 const bool theMakeGroups,
3070 ::SMESH_Mesh* theTargetMesh)
3075 const SMESH::PointStruct * P = &theVector.PS;
3076 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
3078 ::SMESH_MeshEditor anEditor( myMesh );
3079 ::SMESH_MeshEditor::PGroupIDs groupIds =
3080 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3083 storeResult(anEditor);
3085 myMesh->SetIsModified( true );
3087 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3090 //=======================================================================
3091 //function : Translate
3093 //=======================================================================
3095 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
3096 const SMESH::DirStruct & theVector,
3097 CORBA::Boolean theCopy)
3099 if ( !myPreviewMode ) {
3100 TPythonDump() << this << ".Translate( "
3101 << theIDsOfElements << ", "
3102 << theVector << ", "
3105 if ( theIDsOfElements.length() )
3107 TIDSortedElemSet elements;
3108 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3109 translate(elements,theVector,theCopy,false);
3113 //=======================================================================
3114 //function : TranslateObject
3116 //=======================================================================
3118 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
3119 const SMESH::DirStruct & theVector,
3120 CORBA::Boolean theCopy)
3122 if ( !myPreviewMode ) {
3123 TPythonDump() << this << ".TranslateObject( "
3124 << theObject << ", "
3125 << theVector << ", "
3128 TIDSortedElemSet elements;
3129 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3130 translate( elements, theVector, theCopy, false);
3133 //=======================================================================
3134 //function : TranslateMakeGroups
3136 //=======================================================================
3138 SMESH::ListOfGroups*
3139 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
3140 const SMESH::DirStruct& theVector)
3142 SMESH::ListOfGroups * aGroups = 0;
3143 if ( theIDsOfElements.length() )
3145 TIDSortedElemSet elements;
3146 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3147 aGroups = translate(elements,theVector,true,true);
3149 if ( !myPreviewMode ) {
3150 TPythonDump aPythonDump;
3151 DumpGroupsList(aPythonDump,aGroups);
3152 aPythonDump << this << ".TranslateMakeGroups( "
3153 << theIDsOfElements << ", "
3154 << theVector << " )";
3159 //=======================================================================
3160 //function : TranslateObjectMakeGroups
3162 //=======================================================================
3164 SMESH::ListOfGroups*
3165 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3166 const SMESH::DirStruct& theVector)
3168 SMESH::ListOfGroups * aGroups = 0;
3169 TIDSortedElemSet elements;
3170 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3171 aGroups = translate(elements, theVector, true, true);
3173 if ( !myPreviewMode ) {
3175 TPythonDump aPythonDump;
3176 DumpGroupsList(aPythonDump,aGroups);
3177 aPythonDump << this << ".TranslateObjectMakeGroups( "
3178 << theObject << ", "
3179 << theVector << " )";
3184 //=======================================================================
3185 //function : TranslateMakeMesh
3187 //=======================================================================
3189 SMESH::SMESH_Mesh_ptr
3190 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3191 const SMESH::DirStruct& theVector,
3192 CORBA::Boolean theCopyGroups,
3193 const char* theMeshName)
3195 SMESH_Mesh_i* mesh_i;
3196 SMESH::SMESH_Mesh_var mesh;
3198 { // open new scope to dump "MakeMesh" command
3199 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3201 TPythonDump pydump; // to prevent dump at mesh creation
3203 mesh = makeMesh( theMeshName );
3204 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3206 if ( mesh_i && theIDsOfElements.length() )
3208 TIDSortedElemSet elements;
3209 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3210 translate(elements, theVector, false, theCopyGroups, & mesh_i->GetImpl());
3211 mesh_i->CreateGroupServants();
3214 if ( !myPreviewMode ) {
3215 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3216 << theIDsOfElements << ", "
3217 << theVector << ", "
3218 << theCopyGroups << ", '"
3219 << theMeshName << "' )";
3224 if(!myPreviewMode && mesh_i)
3225 mesh_i->GetGroups();
3227 return mesh._retn();
3230 //=======================================================================
3231 //function : TranslateObjectMakeMesh
3233 //=======================================================================
3235 SMESH::SMESH_Mesh_ptr
3236 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3237 const SMESH::DirStruct& theVector,
3238 CORBA::Boolean theCopyGroups,
3239 const char* theMeshName)
3241 SMESH_Mesh_i* mesh_i;
3242 SMESH::SMESH_Mesh_var mesh;
3243 { // open new scope to dump "MakeMesh" command
3244 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3246 TPythonDump pydump; // to prevent dump at mesh creation
3247 mesh = makeMesh( theMeshName );
3248 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3250 TIDSortedElemSet elements;
3252 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3254 translate(elements, theVector,false, theCopyGroups, & mesh_i->GetImpl());
3255 mesh_i->CreateGroupServants();
3257 if ( !myPreviewMode ) {
3258 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3259 << theObject << ", "
3260 << theVector << ", "
3261 << theCopyGroups << ", '"
3262 << theMeshName << "' )";
3267 if(!myPreviewMode && mesh_i)
3268 mesh_i->GetGroups();
3270 return mesh._retn();
3273 //=======================================================================
3276 //=======================================================================
3278 SMESH::ListOfGroups*
3279 SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements,
3280 const SMESH::AxisStruct & theAxis,
3281 CORBA::Double theAngle,
3282 CORBA::Boolean theCopy,
3283 const bool theMakeGroups,
3284 ::SMESH_Mesh* theTargetMesh)
3288 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3289 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3292 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3294 ::SMESH_MeshEditor anEditor( myMesh );
3295 ::SMESH_MeshEditor::PGroupIDs groupIds =
3296 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3299 storeResult(anEditor);
3301 myMesh->SetIsModified( true );
3303 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3306 //=======================================================================
3309 //=======================================================================
3311 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3312 const SMESH::AxisStruct & theAxis,
3313 CORBA::Double theAngle,
3314 CORBA::Boolean theCopy)
3316 if ( !myPreviewMode ) {
3317 TPythonDump() << this << ".Rotate( "
3318 << theIDsOfElements << ", "
3323 if ( theIDsOfElements.length() > 0 )
3325 TIDSortedElemSet elements;
3326 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3327 rotate(elements,theAxis,theAngle,theCopy,false);
3331 //=======================================================================
3332 //function : RotateObject
3334 //=======================================================================
3336 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3337 const SMESH::AxisStruct & theAxis,
3338 CORBA::Double theAngle,
3339 CORBA::Boolean theCopy)
3341 if ( !myPreviewMode ) {
3342 TPythonDump() << this << ".RotateObject( "
3343 << theObject << ", "
3348 TIDSortedElemSet elements;
3349 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3350 rotate(elements,theAxis,theAngle,theCopy,false);
3353 //=======================================================================
3354 //function : RotateMakeGroups
3356 //=======================================================================
3358 SMESH::ListOfGroups*
3359 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3360 const SMESH::AxisStruct& theAxis,
3361 CORBA::Double theAngle)
3363 SMESH::ListOfGroups * aGroups = 0;
3364 if ( theIDsOfElements.length() > 0 )
3366 TIDSortedElemSet elements;
3367 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3368 aGroups = rotate(elements,theAxis,theAngle,true,true);
3370 if ( !myPreviewMode ) {
3371 TPythonDump aPythonDump;
3372 DumpGroupsList(aPythonDump,aGroups);
3373 aPythonDump << this << ".RotateMakeGroups( "
3374 << theIDsOfElements << ", "
3376 << theAngle << " )";
3381 //=======================================================================
3382 //function : RotateObjectMakeGroups
3384 //=======================================================================
3386 SMESH::ListOfGroups*
3387 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3388 const SMESH::AxisStruct& theAxis,
3389 CORBA::Double theAngle)
3391 SMESH::ListOfGroups * aGroups = 0;
3392 TIDSortedElemSet elements;
3393 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3394 aGroups = rotate(elements,theAxis,theAngle,true,true);
3396 if ( !myPreviewMode ) {
3397 TPythonDump aPythonDump;
3398 DumpGroupsList(aPythonDump,aGroups);
3399 aPythonDump << this << ".RotateObjectMakeGroups( "
3400 << theObject << ", "
3402 << theAngle << " )";
3407 //=======================================================================
3408 //function : RotateMakeMesh
3410 //=======================================================================
3412 SMESH::SMESH_Mesh_ptr
3413 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3414 const SMESH::AxisStruct& theAxis,
3415 CORBA::Double theAngleInRadians,
3416 CORBA::Boolean theCopyGroups,
3417 const char* theMeshName)
3419 SMESH::SMESH_Mesh_var mesh;
3420 SMESH_Mesh_i* mesh_i;
3422 { // open new scope to dump "MakeMesh" command
3423 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3425 TPythonDump pydump; // to prevent dump at mesh creation
3427 mesh = makeMesh( theMeshName );
3428 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3430 if ( mesh_i && theIDsOfElements.length() > 0 )
3432 TIDSortedElemSet elements;
3433 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3434 rotate(elements, theAxis, theAngleInRadians,
3435 false, theCopyGroups, & mesh_i->GetImpl());
3436 mesh_i->CreateGroupServants();
3438 if ( !myPreviewMode ) {
3439 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3440 << theIDsOfElements << ", "
3442 << theAngleInRadians << ", "
3443 << theCopyGroups << ", '"
3444 << theMeshName << "' )";
3449 if(!myPreviewMode && mesh_i && theIDsOfElements.length() > 0 )
3450 mesh_i->GetGroups();
3452 return mesh._retn();
3455 //=======================================================================
3456 //function : RotateObjectMakeMesh
3458 //=======================================================================
3460 SMESH::SMESH_Mesh_ptr
3461 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3462 const SMESH::AxisStruct& theAxis,
3463 CORBA::Double theAngleInRadians,
3464 CORBA::Boolean theCopyGroups,
3465 const char* theMeshName)
3467 SMESH::SMESH_Mesh_var mesh;
3468 SMESH_Mesh_i* mesh_i;
3470 {// open new scope to dump "MakeMesh" command
3471 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3473 TPythonDump pydump; // to prevent dump at mesh creation
3474 mesh = makeMesh( theMeshName );
3475 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3477 TIDSortedElemSet elements;
3479 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3481 rotate(elements, theAxis, theAngleInRadians,
3482 false, theCopyGroups, & mesh_i->GetImpl());
3483 mesh_i->CreateGroupServants();
3485 if ( !myPreviewMode ) {
3486 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3487 << theObject << ", "
3489 << theAngleInRadians << ", "
3490 << theCopyGroups << ", '"
3491 << theMeshName << "' )";
3496 if(!myPreviewMode && mesh_i)
3497 mesh_i->GetGroups();
3499 return mesh._retn();
3502 //=======================================================================
3505 //=======================================================================
3507 SMESH::ListOfGroups*
3508 SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject,
3509 const SMESH::PointStruct& thePoint,
3510 const SMESH::double_array& theScaleFact,
3511 CORBA::Boolean theCopy,
3512 const bool theMakeGroups,
3513 ::SMESH_Mesh* theTargetMesh)
3516 if ( theScaleFact.length() < 1 )
3517 THROW_SALOME_CORBA_EXCEPTION("Scale factor not given", SALOME::BAD_PARAM);
3518 if ( theScaleFact.length() == 2 )
3519 THROW_SALOME_CORBA_EXCEPTION("Invalid nb of scale factors : 2", SALOME::BAD_PARAM);
3521 TIDSortedElemSet elements;
3522 if ( !idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/true))
3525 vector<double> S(3);
3526 S[0] = theScaleFact[0];
3527 S[1] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1];
3528 S[2] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2];
3529 double tol = std::numeric_limits<double>::max();
3531 aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]),
3532 0, S[1], 0, thePoint.y * (1-S[1]),
3533 0, 0, S[2], thePoint.z * (1-S[2]), tol, tol);
3535 ::SMESH_MeshEditor anEditor( myMesh );
3536 ::SMESH_MeshEditor::PGroupIDs groupIds =
3537 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3540 storeResult(anEditor);
3542 myMesh->SetIsModified( true );
3544 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3547 //=======================================================================
3550 //=======================================================================
3552 void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr theObject,
3553 const SMESH::PointStruct& thePoint,
3554 const SMESH::double_array& theScaleFact,
3555 CORBA::Boolean theCopy)
3557 if ( !myPreviewMode ) {
3558 TPythonDump() << this << ".Scale( "
3559 << theObject << ", "
3560 << "SMESH.PointStruct( " << thePoint.x << ", "
3561 << thePoint.y << ", " << thePoint.z << " ) ,"
3562 << theScaleFact << ", "
3565 scale(theObject, thePoint, theScaleFact, theCopy, false);
3569 //=======================================================================
3570 //function : ScaleMakeGroups
3572 //=======================================================================
3574 SMESH::ListOfGroups*
3575 SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3576 const SMESH::PointStruct& thePoint,
3577 const SMESH::double_array& theScaleFact)
3579 SMESH::ListOfGroups * aGroups = scale(theObject, thePoint, theScaleFact, true, true);
3580 if ( !myPreviewMode ) {
3582 TPythonDump aPythonDump;
3583 DumpGroupsList(aPythonDump,aGroups);
3584 aPythonDump << this << ".Scale("
3586 << "SMESH.PointStruct(" <<thePoint.x << ","
3587 << thePoint.y << "," << thePoint.z << "),"
3588 << theScaleFact << ",True,True)";
3594 //=======================================================================
3595 //function : ScaleMakeMesh
3597 //=======================================================================
3599 SMESH::SMESH_Mesh_ptr
3600 SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3601 const SMESH::PointStruct& thePoint,
3602 const SMESH::double_array& theScaleFact,
3603 CORBA::Boolean theCopyGroups,
3604 const char* theMeshName)
3606 SMESH_Mesh_i* mesh_i;
3607 SMESH::SMESH_Mesh_var mesh;
3608 { // open new scope to dump "MakeMesh" command
3609 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3611 TPythonDump pydump; // to prevent dump at mesh creation
3612 mesh = makeMesh( theMeshName );
3613 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3617 scale(theObject, thePoint, theScaleFact,false, theCopyGroups, & mesh_i->GetImpl());
3618 mesh_i->CreateGroupServants();
3620 if ( !myPreviewMode )
3621 pydump << mesh << " = " << this << ".ScaleMakeMesh( "
3622 << theObject << ", "
3623 << "SMESH.PointStruct( " << thePoint.x << ", "
3624 << thePoint.y << ", " << thePoint.z << " ) ,"
3625 << theScaleFact << ", "
3626 << theCopyGroups << ", '"
3627 << theMeshName << "' )";
3631 if(!myPreviewMode && mesh_i)
3632 mesh_i->GetGroups();
3634 return mesh._retn();
3638 //=======================================================================
3639 //function : FindCoincidentNodes
3641 //=======================================================================
3643 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3644 SMESH::array_of_long_array_out GroupsOfNodes)
3648 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3649 ::SMESH_MeshEditor anEditor( myMesh );
3650 TIDSortedNodeSet nodes; // no input nodes
3651 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3653 GroupsOfNodes = new SMESH::array_of_long_array;
3654 GroupsOfNodes->length( aListOfListOfNodes.size() );
3655 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3656 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3657 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3658 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3659 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3660 aGroup.length( aListOfNodes.size() );
3661 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3662 aGroup[ j ] = (*lIt)->GetID();
3664 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3665 << Tolerance << " )";
3668 //=======================================================================
3669 //function : FindCoincidentNodesOnPart
3671 //=======================================================================
3672 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3673 CORBA::Double Tolerance,
3674 SMESH::array_of_long_array_out GroupsOfNodes)
3678 TIDSortedNodeSet nodes;
3679 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3681 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3682 ::SMESH_MeshEditor anEditor( myMesh );
3684 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3686 GroupsOfNodes = new SMESH::array_of_long_array;
3687 GroupsOfNodes->length( aListOfListOfNodes.size() );
3688 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3689 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3691 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3692 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3693 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3694 aGroup.length( aListOfNodes.size() );
3695 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3696 aGroup[ j ] = (*lIt)->GetID();
3698 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3700 << Tolerance << " )";
3703 //================================================================================
3705 * \brief Finds nodes coinsident with Tolerance within Object excluding nodes within
3706 * ExceptSubMeshOrGroups
3708 //================================================================================
3710 void SMESH_MeshEditor_i::
3711 FindCoincidentNodesOnPartBut(SMESH::SMESH_IDSource_ptr theObject,
3712 CORBA::Double theTolerance,
3713 SMESH::array_of_long_array_out theGroupsOfNodes,
3714 const SMESH::ListOfIDSources& theExceptSubMeshOrGroups)
3718 TIDSortedNodeSet nodes;
3719 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3721 for ( int i = 0; i < theExceptSubMeshOrGroups.length(); ++i )
3723 TIDSortedNodeSet exceptNodes;
3724 idSourceToNodeSet( theExceptSubMeshOrGroups[i], GetMeshDS(), exceptNodes );
3725 TIDSortedNodeSet::iterator avoidNode = exceptNodes.begin();
3726 for ( ; avoidNode != exceptNodes.end(); ++avoidNode)
3727 nodes.erase( *avoidNode );
3729 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3730 ::SMESH_MeshEditor anEditor( myMesh );
3732 anEditor.FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes );
3734 theGroupsOfNodes = new SMESH::array_of_long_array;
3735 theGroupsOfNodes->length( aListOfListOfNodes.size() );
3736 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3737 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3739 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3740 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3741 SMESH::long_array& aGroup = (*theGroupsOfNodes)[ i ];
3742 aGroup.length( aListOfNodes.size() );
3743 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3744 aGroup[ j ] = (*lIt)->GetID();
3746 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPartBut( "
3748 << theTolerance << ", "
3749 << theExceptSubMeshOrGroups << " )";
3752 //=======================================================================
3753 //function : MergeNodes
3755 //=======================================================================
3757 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3761 SMESHDS_Mesh* aMesh = GetMeshDS();
3763 TPythonDump aTPythonDump;
3764 aTPythonDump << this << ".MergeNodes([";
3765 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3766 for (int i = 0; i < GroupsOfNodes.length(); i++)
3768 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3769 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3770 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3771 for ( int j = 0; j < aNodeGroup.length(); j++ )
3773 CORBA::Long index = aNodeGroup[ j ];
3774 const SMDS_MeshNode * node = aMesh->FindNode(index);
3776 aListOfNodes.push_back( node );
3778 if ( aListOfNodes.size() < 2 )
3779 aListOfListOfNodes.pop_back();
3781 if ( i > 0 ) aTPythonDump << ", ";
3782 aTPythonDump << aNodeGroup;
3784 ::SMESH_MeshEditor anEditor( myMesh );
3785 anEditor.MergeNodes( aListOfListOfNodes );
3787 aTPythonDump << "])";
3789 myMesh->SetIsModified( true );
3792 //=======================================================================
3793 //function : FindEqualElements
3795 //=======================================================================
3796 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3797 SMESH::array_of_long_array_out GroupsOfElementsID)
3801 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theObject);
3802 if ( !(!group->_is_nil() && group->GetType() == SMESH::NODE) )
3804 typedef list<int> TListOfIDs;
3805 set<const SMDS_MeshElement*> elems;
3806 SMESH::long_array_var aElementsId = theObject->GetIDs();
3807 SMESHDS_Mesh* aMesh = GetMeshDS();
3809 for(int i = 0; i < aElementsId->length(); i++) {
3810 CORBA::Long anID = aElementsId[i];
3811 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3817 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3818 ::SMESH_MeshEditor anEditor( myMesh );
3819 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3821 GroupsOfElementsID = new SMESH::array_of_long_array;
3822 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3824 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3825 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3826 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3827 TListOfIDs& listOfIDs = *arraysIt;
3828 aGroup.length( listOfIDs.size() );
3829 TListOfIDs::iterator idIt = listOfIDs.begin();
3830 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3831 aGroup[ k ] = *idIt;
3835 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3840 //=======================================================================
3841 //function : MergeElements
3843 //=======================================================================
3845 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3849 TPythonDump aTPythonDump;
3850 aTPythonDump << this << ".MergeElements( [";
3852 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3854 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3855 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3856 aListOfListOfElementsID.push_back( list< int >() );
3857 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3858 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3859 CORBA::Long id = anElemsIDGroup[ j ];
3860 aListOfElemsID.push_back( id );
3862 if ( aListOfElemsID.size() < 2 )
3863 aListOfListOfElementsID.pop_back();
3864 if ( i > 0 ) aTPythonDump << ", ";
3865 aTPythonDump << anElemsIDGroup;
3868 ::SMESH_MeshEditor anEditor( myMesh );
3869 anEditor.MergeElements(aListOfListOfElementsID);
3871 myMesh->SetIsModified( true );
3873 aTPythonDump << "] )";
3876 //=======================================================================
3877 //function : MergeEqualElements
3879 //=======================================================================
3881 void SMESH_MeshEditor_i::MergeEqualElements()
3885 ::SMESH_MeshEditor anEditor( myMesh );
3886 anEditor.MergeEqualElements();
3888 TPythonDump() << this << ".MergeEqualElements()";
3891 //=============================================================================
3893 * Move the node to a given point
3895 //=============================================================================
3897 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
3902 initData(/*deleteSearchers=*/false);
3904 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
3908 if ( theNodeSearcher )
3909 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3911 if ( myPreviewMode ) // make preview data
3913 // in a preview mesh, make edges linked to a node
3914 TPreviewMesh tmpMesh;
3915 TIDSortedElemSet linkedNodes;
3916 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3917 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3918 for ( ; nIt != linkedNodes.end(); ++nIt )
3920 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
3921 tmpMesh.Copy( &edge );
3924 node = tmpMesh.GetMeshDS()->FindNode( NodeID );
3926 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
3927 // fill preview data
3928 ::SMESH_MeshEditor anEditor( & tmpMesh );
3929 storeResult( anEditor );
3931 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3932 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3934 GetMeshDS()->MoveNode(node, x, y, z);
3936 if ( !myPreviewMode )
3938 // Update Python script
3939 TPythonDump() << "isDone = " << this << ".MoveNode( "
3940 << NodeID << ", " << x << ", " << y << ", " << z << " )";
3942 myMesh->SetIsModified( true );
3948 //================================================================================
3950 * \brief Return ID of node closest to a given point
3952 //================================================================================
3954 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
3958 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3960 if ( !theNodeSearcher ) {
3961 ::SMESH_MeshEditor anEditor( myMesh );
3962 theNodeSearcher = anEditor.GetNodeSearcher();
3965 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
3966 return node->GetID();
3971 //================================================================================
3973 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
3974 * move the node closest to the point to point's location and return ID of the node
3976 //================================================================================
3978 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
3981 CORBA::Long theNodeID)
3983 // We keep theNodeSearcher until any mesh modification:
3984 // 1) initData() deletes theNodeSearcher at any edition,
3985 // 2) TSearchersDeleter - at any mesh compute event and mesh change
3987 initData(/*deleteSearchers=*/false);
3989 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3991 int nodeID = theNodeID;
3992 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
3993 if ( !node ) // preview moving node
3995 if ( !theNodeSearcher ) {
3996 ::SMESH_MeshEditor anEditor( myMesh );
3997 theNodeSearcher = anEditor.GetNodeSearcher();
4000 node = theNodeSearcher->FindClosestTo( p );
4003 nodeID = node->GetID();
4004 if ( myPreviewMode ) // make preview data
4006 // in a preview mesh, make edges linked to a node
4007 TPreviewMesh tmpMesh;
4008 TIDSortedElemSet linkedNodes;
4009 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
4010 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
4011 for ( ; nIt != linkedNodes.end(); ++nIt )
4013 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
4014 tmpMesh.Copy( &edge );
4017 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
4019 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
4020 // fill preview data
4021 ::SMESH_MeshEditor anEditor( & tmpMesh );
4022 storeResult( anEditor );
4024 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
4026 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
4030 GetMeshDS()->MoveNode(node, x, y, z);
4034 if ( !myPreviewMode )
4036 TPythonDump() << "nodeID = " << this
4037 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
4038 << ", " << nodeID << " )";
4040 myMesh->SetIsModified( true );
4046 //=======================================================================
4048 * Return elements of given type where the given point is IN or ON.
4050 * 'ALL' type means elements of any type excluding nodes
4052 //=======================================================================
4054 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
4057 SMESH::ElementType type)
4059 SMESH::long_array_var res = new SMESH::long_array;
4060 vector< const SMDS_MeshElement* > foundElems;
4062 theSearchersDeleter.Set( myMesh );
4063 if ( !theElementSearcher ) {
4064 ::SMESH_MeshEditor anEditor( myMesh );
4065 theElementSearcher = anEditor.GetElementSearcher();
4067 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
4068 SMDSAbs_ElementType( type ),
4070 res->length( foundElems.size() );
4071 for ( int i = 0; i < foundElems.size(); ++i )
4072 res[i] = foundElems[i]->GetID();
4074 if ( !myPreviewMode ) // call from tui
4075 TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
4084 //=======================================================================
4085 //function : GetPointState
4086 //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
4087 // TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
4088 //=======================================================================
4090 CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
4094 theSearchersDeleter.Set( myMesh );
4095 if ( !theElementSearcher ) {
4096 ::SMESH_MeshEditor anEditor( myMesh );
4097 theElementSearcher = anEditor.GetElementSearcher();
4099 return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
4102 //=======================================================================
4103 //function : convError
4105 //=======================================================================
4107 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
4109 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
4113 RETCASE( SEW_BORDER1_NOT_FOUND );
4114 RETCASE( SEW_BORDER2_NOT_FOUND );
4115 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
4116 RETCASE( SEW_BAD_SIDE_NODES );
4117 RETCASE( SEW_VOLUMES_TO_SPLIT );
4118 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
4119 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
4120 RETCASE( SEW_BAD_SIDE1_NODES );
4121 RETCASE( SEW_BAD_SIDE2_NODES );
4123 return SMESH::SMESH_MeshEditor::SEW_OK;
4126 //=======================================================================
4127 //function : SewFreeBorders
4129 //=======================================================================
4131 SMESH::SMESH_MeshEditor::Sew_Error
4132 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
4133 CORBA::Long SecondNodeID1,
4134 CORBA::Long LastNodeID1,
4135 CORBA::Long FirstNodeID2,
4136 CORBA::Long SecondNodeID2,
4137 CORBA::Long LastNodeID2,
4138 CORBA::Boolean CreatePolygons,
4139 CORBA::Boolean CreatePolyedrs)
4143 SMESHDS_Mesh* aMesh = GetMeshDS();
4145 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4146 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4147 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4148 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4149 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4150 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
4152 if (!aBorderFirstNode ||
4153 !aBorderSecondNode||
4155 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4156 if (!aSide2FirstNode ||
4157 !aSide2SecondNode ||
4159 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4161 TPythonDump() << "error = " << this << ".SewFreeBorders( "
4162 << FirstNodeID1 << ", "
4163 << SecondNodeID1 << ", "
4164 << LastNodeID1 << ", "
4165 << FirstNodeID2 << ", "
4166 << SecondNodeID2 << ", "
4167 << LastNodeID2 << ", "
4168 << CreatePolygons<< ", "
4169 << CreatePolyedrs<< " )";
4171 ::SMESH_MeshEditor anEditor( myMesh );
4172 SMESH::SMESH_MeshEditor::Sew_Error error =
4173 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4183 storeResult(anEditor);
4185 myMesh->SetIsModified( true );
4191 //=======================================================================
4192 //function : SewConformFreeBorders
4194 //=======================================================================
4196 SMESH::SMESH_MeshEditor::Sew_Error
4197 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
4198 CORBA::Long SecondNodeID1,
4199 CORBA::Long LastNodeID1,
4200 CORBA::Long FirstNodeID2,
4201 CORBA::Long SecondNodeID2)
4205 SMESHDS_Mesh* aMesh = GetMeshDS();
4207 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4208 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4209 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4210 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4211 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4212 const SMDS_MeshNode* aSide2ThirdNode = 0;
4214 if (!aBorderFirstNode ||
4215 !aBorderSecondNode||
4217 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4218 if (!aSide2FirstNode ||
4220 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4222 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
4223 << FirstNodeID1 << ", "
4224 << SecondNodeID1 << ", "
4225 << LastNodeID1 << ", "
4226 << FirstNodeID2 << ", "
4227 << SecondNodeID2 << " )";
4229 ::SMESH_MeshEditor anEditor( myMesh );
4230 SMESH::SMESH_MeshEditor::Sew_Error error =
4231 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4240 storeResult(anEditor);
4242 myMesh->SetIsModified( true );
4248 //=======================================================================
4249 //function : SewBorderToSide
4251 //=======================================================================
4253 SMESH::SMESH_MeshEditor::Sew_Error
4254 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
4255 CORBA::Long SecondNodeIDOnFreeBorder,
4256 CORBA::Long LastNodeIDOnFreeBorder,
4257 CORBA::Long FirstNodeIDOnSide,
4258 CORBA::Long LastNodeIDOnSide,
4259 CORBA::Boolean CreatePolygons,
4260 CORBA::Boolean CreatePolyedrs)
4264 SMESHDS_Mesh* aMesh = GetMeshDS();
4266 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
4267 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
4268 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
4269 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
4270 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
4271 const SMDS_MeshNode* aSide2ThirdNode = 0;
4273 if (!aBorderFirstNode ||
4274 !aBorderSecondNode||
4276 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4277 if (!aSide2FirstNode ||
4279 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
4281 TPythonDump() << "error = " << this << ".SewBorderToSide( "
4282 << FirstNodeIDOnFreeBorder << ", "
4283 << SecondNodeIDOnFreeBorder << ", "
4284 << LastNodeIDOnFreeBorder << ", "
4285 << FirstNodeIDOnSide << ", "
4286 << LastNodeIDOnSide << ", "
4287 << CreatePolygons << ", "
4288 << CreatePolyedrs << ") ";
4290 ::SMESH_MeshEditor anEditor( myMesh );
4291 SMESH::SMESH_MeshEditor::Sew_Error error =
4292 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4302 storeResult(anEditor);
4304 myMesh->SetIsModified( true );
4310 //=======================================================================
4311 //function : SewSideElements
4313 //=======================================================================
4315 SMESH::SMESH_MeshEditor::Sew_Error
4316 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
4317 const SMESH::long_array& IDsOfSide2Elements,
4318 CORBA::Long NodeID1OfSide1ToMerge,
4319 CORBA::Long NodeID1OfSide2ToMerge,
4320 CORBA::Long NodeID2OfSide1ToMerge,
4321 CORBA::Long NodeID2OfSide2ToMerge)
4325 SMESHDS_Mesh* aMesh = GetMeshDS();
4327 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
4328 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
4329 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
4330 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
4332 if (!aFirstNode1ToMerge ||
4333 !aFirstNode2ToMerge )
4334 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
4335 if (!aSecondNode1ToMerge||
4336 !aSecondNode2ToMerge)
4337 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
4339 TIDSortedElemSet aSide1Elems, aSide2Elems;
4340 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
4341 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
4343 TPythonDump() << "error = " << this << ".SewSideElements( "
4344 << IDsOfSide1Elements << ", "
4345 << IDsOfSide2Elements << ", "
4346 << NodeID1OfSide1ToMerge << ", "
4347 << NodeID1OfSide2ToMerge << ", "
4348 << NodeID2OfSide1ToMerge << ", "
4349 << NodeID2OfSide2ToMerge << ")";
4351 ::SMESH_MeshEditor anEditor( myMesh );
4352 SMESH::SMESH_MeshEditor::Sew_Error error =
4353 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
4356 aSecondNode1ToMerge,
4357 aSecondNode2ToMerge));
4359 storeResult(anEditor);
4361 myMesh->SetIsModified( true );
4366 //================================================================================
4368 * \brief Set new nodes for given element
4369 * \param ide - element id
4370 * \param newIDs - new node ids
4371 * \retval CORBA::Boolean - true if result is OK
4373 //================================================================================
4375 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
4376 const SMESH::long_array& newIDs)
4380 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
4381 if(!elem) return false;
4383 int nbn = newIDs.length();
4385 vector<const SMDS_MeshNode*> aNodes(nbn);
4388 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
4391 aNodes[nbn1] = aNode;
4394 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
4395 << ide << ", " << newIDs << " )";
4397 bool res = GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
4400 myMesh->SetIsModified( true );
4405 //================================================================================
4407 * \brief Update myLastCreated* or myPreviewData
4408 * \param anEditor - it contains last modification results
4410 //================================================================================
4412 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
4414 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
4416 list<int> aNodesConnectivity;
4417 typedef map<int, int> TNodesMap;
4420 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
4421 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
4423 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
4424 int nbEdges = aMeshDS->NbEdges();
4425 int nbFaces = aMeshDS->NbFaces();
4426 int nbVolum = aMeshDS->NbVolumes();
4427 switch ( previewType ) {
4428 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
4429 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
4430 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
4433 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
4434 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
4436 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
4438 while ( itMeshElems->more() ) {
4439 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
4440 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
4443 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
4444 while ( itElemNodes->more() ) {
4445 const SMDS_MeshNode* aMeshNode =
4446 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
4447 int aNodeID = aMeshNode->GetID();
4448 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
4449 if ( anIter == nodesMap.end() ) {
4450 // filling the nodes coordinates
4451 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
4452 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
4453 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
4454 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4457 aNodesConnectivity.push_back(anIter->second);
4460 // filling the elements types
4461 SMDSAbs_ElementType aType;
4463 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4464 aType = SMDSAbs_Node;
4468 aType = aMeshElem->GetType();
4469 isPoly = aMeshElem->IsPoly();
4472 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4473 myPreviewData->elementTypes[i].isPoly = isPoly;
4474 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4478 myPreviewData->nodesXYZ.length( j );
4480 // filling the elements connectivities
4481 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4482 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4483 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4484 myPreviewData->elementConnectivities[i] = *aConnIter;
4490 // add new nodes into myLastCreatedNodes
4491 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4492 myLastCreatedNodes->length(aSeq.Length());
4493 for(int i=0; i<aSeq.Length(); i++)
4494 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4497 // add new elements into myLastCreatedElems
4498 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4499 myLastCreatedElems->length(aSeq.Length());
4500 for(int i=0; i<aSeq.Length(); i++)
4501 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4505 //================================================================================
4507 * Return data of mesh edition preview
4509 //================================================================================
4511 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4513 return myPreviewData._retn();
4516 //================================================================================
4518 * \brief Returns list of it's IDs of created nodes
4519 * \retval SMESH::long_array* - list of node ID
4521 //================================================================================
4523 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4525 return myLastCreatedNodes._retn();
4528 //================================================================================
4530 * \brief Returns list of it's IDs of created elements
4531 * \retval SMESH::long_array* - list of elements' ID
4533 //================================================================================
4535 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4537 return myLastCreatedElems._retn();
4540 //=======================================================================
4541 //function : ConvertToQuadratic
4543 //=======================================================================
4545 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4547 ::SMESH_MeshEditor anEditor( myMesh );
4548 anEditor.ConvertToQuadratic(theForce3d);
4549 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4550 myMesh->SetIsModified( true );
4553 //=======================================================================
4554 //function : ConvertFromQuadratic
4556 //=======================================================================
4558 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4560 ::SMESH_MeshEditor anEditor( myMesh );
4561 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4562 TPythonDump() << this << ".ConvertFromQuadratic()";
4564 myMesh->SetIsModified( true );
4568 //=======================================================================
4569 //function : makeMesh
4570 //purpose : create a named imported mesh
4571 //=======================================================================
4573 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4575 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4576 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4577 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4578 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4579 gen->SetName( meshSO, theMeshName, "Mesh" );
4580 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4582 return mesh._retn();
4585 //=======================================================================
4586 //function : DumpGroupsList
4588 //=======================================================================
4589 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4590 const SMESH::ListOfGroups * theGroupList)
4592 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4593 if(isDumpGroupList) {
4594 theDumpPython << theGroupList << " = ";
4598 //================================================================================
4600 \brief Generates the unique group name.
4601 \param thePrefix name prefix
4604 //================================================================================
4605 string SMESH_MeshEditor_i::generateGroupName(const string& thePrefix)
4607 SMESH::ListOfGroups_var groups = myMesh_i->GetGroups();
4608 set<string> groupNames;
4610 // Get existing group names
4611 for (int i = 0, nbGroups = groups->length(); i < nbGroups; i++ ) {
4612 SMESH::SMESH_GroupBase_var aGroup = groups[i];
4613 if (CORBA::is_nil(aGroup))
4616 groupNames.insert(aGroup->GetName());
4620 string name = thePrefix;
4623 while (!groupNames.insert(name).second) {
4628 TCollection_AsciiString nbStr(index+1);
4629 name.resize( name.rfind('_')+1 );
4630 name += nbStr.ToCString();
4638 //================================================================================
4640 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4641 \param theNodes - identifiers of nodes to be doubled
4642 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4643 nodes. If list of element identifiers is empty then nodes are doubled but
4644 they not assigned to elements
4645 \return TRUE if operation has been completed successfully, FALSE otherwise
4646 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4648 //================================================================================
4650 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4651 const SMESH::long_array& theModifiedElems )
4655 ::SMESH_MeshEditor aMeshEditor( myMesh );
4656 list< int > aListOfNodes;
4658 for ( i = 0, n = theNodes.length(); i < n; i++ )
4659 aListOfNodes.push_back( theNodes[ i ] );
4661 list< int > aListOfElems;
4662 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4663 aListOfElems.push_back( theModifiedElems[ i ] );
4665 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4667 storeResult( aMeshEditor) ;
4669 myMesh->SetIsModified( true );
4671 // Update Python script
4672 TPythonDump() << this << ".DoubleNodes( " << theNodes << ", "<< theModifiedElems << " )";
4677 //================================================================================
4679 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4680 This method provided for convenience works as DoubleNodes() described above.
4681 \param theNodeId - identifier of node to be doubled.
4682 \param theModifiedElems - identifiers of elements to be updated.
4683 \return TRUE if operation has been completed successfully, FALSE otherwise
4684 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4686 //================================================================================
4688 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4689 const SMESH::long_array& theModifiedElems )
4691 SMESH::long_array_var aNodes = new SMESH::long_array;
4692 aNodes->length( 1 );
4693 aNodes[ 0 ] = theNodeId;
4695 TPythonDump pyDump; // suppress dump by the next line
4697 CORBA::Boolean done = DoubleNodes( aNodes, theModifiedElems );
4699 pyDump << this << ".DoubleNode( " << theNodeId << ", " << theModifiedElems << " )";
4704 //================================================================================
4706 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4707 This method provided for convenience works as DoubleNodes() described above.
4708 \param theNodes - group of nodes to be doubled.
4709 \param theModifiedElems - group of elements to be updated.
4710 \return TRUE if operation has been completed successfully, FALSE otherwise
4711 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
4713 //================================================================================
4715 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(SMESH::SMESH_GroupBase_ptr theNodes,
4716 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4718 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4721 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4722 SMESH::long_array_var aModifiedElems;
4723 if ( !CORBA::is_nil( theModifiedElems ) )
4724 aModifiedElems = theModifiedElems->GetListOfID();
4727 aModifiedElems = new SMESH::long_array;
4728 aModifiedElems->length( 0 );
4731 TPythonDump pyDump; // suppress dump by the next line
4733 bool done = DoubleNodes( aNodes, aModifiedElems );
4735 pyDump << this << ".DoubleNodeGroup( " << theNodes << ", " << theModifiedElems << " )";
4741 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements.
4742 * Works as DoubleNodeGroup(), but returns a new group with newly created nodes.
4743 * \param theNodes - group of nodes to be doubled.
4744 * \param theModifiedElems - group of elements to be updated.
4745 * \return a new group with newly created nodes
4746 * \sa DoubleNodeGroup()
4748 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes,
4749 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4751 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4754 SMESH::SMESH_Group_var aNewGroup;
4757 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4758 SMESH::long_array_var aModifiedElems;
4759 if ( !CORBA::is_nil( theModifiedElems ) )
4760 aModifiedElems = theModifiedElems->GetListOfID();
4762 aModifiedElems = new SMESH::long_array;
4763 aModifiedElems->length( 0 );
4766 TPythonDump pyDump; // suppress dump by the next line
4768 bool aResult = DoubleNodes( aNodes, aModifiedElems );
4772 // Create group with newly created nodes
4773 SMESH::long_array_var anIds = GetLastCreatedNodes();
4774 if (anIds->length() > 0) {
4775 string anUnindexedName (theNodes->GetName());
4776 string aNewName = generateGroupName(anUnindexedName + "_double");
4777 aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
4778 aNewGroup->Add(anIds);
4782 pyDump << "createdNodes = " << this << ".DoubleNodeGroupNew( " << theNodes << ", "
4783 << theModifiedElems << " )";
4785 return aNewGroup._retn();
4788 //================================================================================
4790 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4791 This method provided for convenience works as DoubleNodes() described above.
4792 \param theNodes - list of groups of nodes to be doubled
4793 \param theModifiedElems - list of groups of elements to be updated.
4794 \return TRUE if operation has been completed successfully, FALSE otherwise
4795 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
4797 //================================================================================
4799 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& theNodes,
4800 const SMESH::ListOfGroups& theModifiedElems )
4804 ::SMESH_MeshEditor aMeshEditor( myMesh );
4806 std::list< int > aNodes;
4808 for ( i = 0, n = theNodes.length(); i < n; i++ )
4810 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
4811 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
4813 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4814 for ( j = 0, m = aCurr->length(); j < m; j++ )
4815 aNodes.push_back( aCurr[ j ] );
4819 std::list< int > anElems;
4820 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4822 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
4823 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
4825 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4826 for ( j = 0, m = aCurr->length(); j < m; j++ )
4827 anElems.push_back( aCurr[ j ] );
4831 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
4833 storeResult( aMeshEditor) ;
4836 myMesh->SetIsModified( true );
4839 TPythonDump() << this << ".DoubleNodeGroups( " << theNodes << ", " << theModifiedElems << " )";
4844 //================================================================================
4846 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4847 \param theElems - the list of elements (edges or faces) to be replicated
4848 The nodes for duplication could be found from these elements
4849 \param theNodesNot - list of nodes to NOT replicate
4850 \param theAffectedElems - the list of elements (cells and edges) to which the
4851 replicated nodes should be associated to.
4852 \return TRUE if operation has been completed successfully, FALSE otherwise
4853 \sa DoubleNodeGroup(), DoubleNodeGroups()
4855 //================================================================================
4857 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
4858 const SMESH::long_array& theNodesNot,
4859 const SMESH::long_array& theAffectedElems )
4864 ::SMESH_MeshEditor aMeshEditor( myMesh );
4866 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4867 TIDSortedElemSet anElems, aNodes, anAffected;
4868 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4869 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4870 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
4872 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4874 storeResult( aMeshEditor) ;
4877 myMesh->SetIsModified( true );
4879 // Update Python script
4880 TPythonDump() << this << ".DoubleNodeElem( " << theElems << ", "
4881 << theNodesNot << ", " << theAffectedElems << " )";
4885 //================================================================================
4887 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4888 \param theElems - the list of elements (edges or faces) to be replicated
4889 The nodes for duplication could be found from these elements
4890 \param theNodesNot - list of nodes to NOT replicate
4891 \param theShape - shape to detect affected elements (element which geometric center
4892 located on or inside shape).
4893 The replicated nodes should be associated to affected elements.
4894 \return TRUE if operation has been completed successfully, FALSE otherwise
4895 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
4897 //================================================================================
4899 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_array& theElems,
4900 const SMESH::long_array& theNodesNot,
4901 GEOM::GEOM_Object_ptr theShape )
4906 ::SMESH_MeshEditor aMeshEditor( myMesh );
4908 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4909 TIDSortedElemSet anElems, aNodes;
4910 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4911 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4913 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4914 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4916 storeResult( aMeshEditor) ;
4919 myMesh->SetIsModified( true );
4921 // Update Python script
4922 TPythonDump() << "isDone = " << this << ".DoubleNodeElemInRegion( " << theElems << ", "
4923 << theNodesNot << ", " << theShape << " )";
4927 //================================================================================
4929 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4930 \param theElems - group of of elements (edges or faces) to be replicated
4931 \param theNodesNot - group of nodes not to replicated
4932 \param theAffectedElems - group of elements to which the replicated nodes
4933 should be associated to.
4934 \return TRUE if operation has been completed successfully, FALSE otherwise
4935 \sa DoubleNodes(), DoubleNodeGroups()
4937 //================================================================================
4939 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_ptr theElems,
4940 SMESH::SMESH_GroupBase_ptr theNodesNot,
4941 SMESH::SMESH_GroupBase_ptr theAffectedElems)
4943 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4948 ::SMESH_MeshEditor aMeshEditor( myMesh );
4950 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4951 TIDSortedElemSet anElems, aNodes, anAffected;
4952 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4953 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4954 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
4956 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4958 storeResult( aMeshEditor) ;
4961 myMesh->SetIsModified( true );
4963 // Update Python script
4964 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroup( " << theElems << ", "
4965 << theNodesNot << ", " << theAffectedElems << " )";
4970 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4971 * Works as DoubleNodeElemGroup(), but returns a new group with newly created elements.
4972 * \param theElems - group of of elements (edges or faces) to be replicated
4973 * \param theNodesNot - group of nodes not to replicated
4974 * \param theAffectedElems - group of elements to which the replicated nodes
4975 * should be associated to.
4976 * \return a new group with newly created elements
4977 * \sa DoubleNodeElemGroup()
4979 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems,
4980 SMESH::SMESH_GroupBase_ptr theNodesNot,
4981 SMESH::SMESH_GroupBase_ptr theAffectedElems)
4983 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4986 SMESH::SMESH_Group_var aNewGroup;
4990 ::SMESH_MeshEditor aMeshEditor( myMesh );
4992 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4993 TIDSortedElemSet anElems, aNodes, anAffected;
4994 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4995 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4996 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
4999 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5001 storeResult( aMeshEditor) ;
5004 myMesh->SetIsModified( true );
5006 // Create group with newly created elements
5007 SMESH::long_array_var anIds = GetLastCreatedElems();
5008 if (anIds->length() > 0) {
5009 SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
5010 string anUnindexedName (theElems->GetName());
5011 string aNewName = generateGroupName(anUnindexedName + "_double");
5012 aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
5013 aNewGroup->Add(anIds);
5017 // Update Python script
5018 TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupNew( " << theElems << ", "
5019 << theNodesNot << ", " << theAffectedElems << " )";
5020 return aNewGroup._retn();
5023 //================================================================================
5025 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5026 \param theElems - group of of elements (edges or faces) to be replicated
5027 \param theNodesNot - group of nodes not to replicated
5028 \param theShape - shape to detect affected elements (element which geometric center
5029 located on or inside shape).
5030 The replicated nodes should be associated to affected elements.
5031 \return TRUE if operation has been completed successfully, FALSE otherwise
5032 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
5034 //================================================================================
5036 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_GroupBase_ptr theElems,
5037 SMESH::SMESH_GroupBase_ptr theNodesNot,
5038 GEOM::GEOM_Object_ptr theShape )
5041 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5046 ::SMESH_MeshEditor aMeshEditor( myMesh );
5048 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5049 TIDSortedElemSet anElems, aNodes, anAffected;
5050 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5051 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5053 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5054 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5056 storeResult( aMeshEditor) ;
5059 myMesh->SetIsModified( true );
5061 // Update Python script
5062 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupInRegion( " << theElems << ", "
5063 << theNodesNot << ", " << theShape << " )";
5067 //================================================================================
5069 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5070 This method provided for convenience works as DoubleNodes() described above.
5071 \param theElems - list of groups of elements (edges or faces) to be replicated
5072 \param theNodesNot - list of groups of nodes not to replicated
5073 \param theAffectedElems - group of elements to which the replicated nodes
5074 should be associated to.
5075 \return TRUE if operation has been completed successfully, FALSE otherwise
5076 \sa DoubleNodeGroup(), DoubleNodes()
5078 //================================================================================
5080 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
5081 SMESHDS_Mesh* theMeshDS,
5082 TIDSortedElemSet& theElemSet,
5083 const bool theIsNodeGrp)
5085 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
5087 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
5088 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
5089 : aGrp->GetType() != SMESH::NODE ) )
5091 SMESH::long_array_var anIDs = aGrp->GetIDs();
5092 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
5097 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroups& theElems,
5098 const SMESH::ListOfGroups& theNodesNot,
5099 const SMESH::ListOfGroups& theAffectedElems)
5103 ::SMESH_MeshEditor aMeshEditor( myMesh );
5105 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5106 TIDSortedElemSet anElems, aNodes, anAffected;
5107 listOfGroupToSet(theElems, aMeshDS, anElems, false );
5108 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5109 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
5111 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5113 storeResult( aMeshEditor) ;
5116 myMesh->SetIsModified( true );
5118 // Update Python script
5119 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroups( " << &theElems << ", "
5120 << &theNodesNot << ", " << &theAffectedElems << " )";
5124 //================================================================================
5126 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5127 This method provided for convenience works as DoubleNodes() described above.
5128 \param theElems - list of groups of elements (edges or faces) to be replicated
5129 \param theNodesNot - list of groups of nodes not to replicated
5130 \param theShape - shape to detect affected elements (element which geometric center
5131 located on or inside shape).
5132 The replicated nodes should be associated to affected elements.
5133 \return TRUE if operation has been completed successfully, FALSE otherwise
5134 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
5136 //================================================================================
5139 SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theElems,
5140 const SMESH::ListOfGroups& theNodesNot,
5141 GEOM::GEOM_Object_ptr theShape )
5145 ::SMESH_MeshEditor aMeshEditor( myMesh );
5147 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5148 TIDSortedElemSet anElems, aNodes;
5149 listOfGroupToSet(theElems, aMeshDS, anElems,false );
5150 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5152 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5153 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5155 storeResult( aMeshEditor) ;
5158 myMesh->SetIsModified( true );
5160 // Update Python script
5161 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupsInRegion( " << &theElems << ", "
5162 << &theNodesNot << ", " << theShape << " )";
5166 //================================================================================
5168 \brief Generated skin mesh (containing 2D cells) from 3D mesh
5169 The created 2D mesh elements based on nodes of free faces of boundary volumes
5170 \return TRUE if operation has been completed successfully, FALSE otherwise
5172 //================================================================================
5174 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
5178 ::SMESH_MeshEditor aMeshEditor( myMesh );
5179 bool aResult = aMeshEditor.Make2DMeshFrom3D();
5180 storeResult( aMeshEditor) ;
5182 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";