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
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_MeshEditor_i.cxx
24 // Author : Nicolas REJNERI
31 #include "SMESH_MeshEditor_i.hxx"
33 #include "SMDS_Mesh0DElement.hxx"
34 #include "SMDS_LinearEdge.hxx"
35 #include "SMDS_MeshFace.hxx"
36 #include "SMDS_MeshVolume.hxx"
37 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
38 #include "SMESH_subMeshEventListener.hxx"
39 #include "SMESH_Gen_i.hxx"
40 #include "SMESH_Filter_i.hxx"
41 #include "SMESH_subMesh_i.hxx"
42 #include "SMESH_Group_i.hxx"
43 #include "SMESH_PythonDump.hxx"
44 #include "SMESH_ControlsDef.hxx"
46 #include "utilities.h"
47 #include "Utils_ExceptHandlers.hxx"
48 #include "Utils_CorbaException.hxx"
50 #include <BRepAdaptor_Surface.hxx>
51 #include <BRep_Tool.hxx>
52 #include <TopExp_Explorer.hxx>
54 #include <TopoDS_Edge.hxx>
55 #include <TopoDS_Face.hxx>
60 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
64 #include <Standard_Failure.hxx>
67 #include <Standard_ErrorHandler.hxx>
73 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
76 using SMESH::TPythonDump;
80 //=============================================================================
82 * \brief Mesh to apply modifications for preview purposes
84 //=============================================================================
86 struct TPreviewMesh: public SMESH_Mesh
88 SMDSAbs_ElementType myPreviewType; // type to show
90 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
91 _isShapeToMesh = (_id =_studyId =_idDoc = 0);
92 _myMeshDS = new SMESHDS_Mesh( _id, true );
93 myPreviewType = previewElements;
96 virtual ~TPreviewMesh() { delete _myMeshDS; }
97 //!< Copy a set of elements
98 void Copy(const TIDSortedElemSet & theElements,
99 TIDSortedElemSet& theCopyElements,
100 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
101 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
103 // loop on theIDsOfElements
104 TIDSortedElemSet::const_iterator eIt = theElements.begin();
105 for ( ; eIt != theElements.end(); ++eIt )
107 const SMDS_MeshElement* anElem = *eIt;
108 if ( !anElem ) continue;
109 SMDSAbs_ElementType type = anElem->GetType();
110 if ( type == theAvoidType ||
111 ( theSelectType != SMDSAbs_All && type != theSelectType ))
114 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
115 theCopyElements.insert( theCopyElements.end(), anElemCopy );
119 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
121 // copy element nodes
122 int anElemNbNodes = anElem->NbNodes();
123 vector< int > anElemNodesID( anElemNbNodes ) ;
124 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
125 for ( int i = 0; itElemNodes->more(); i++)
127 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
129 anElemNodesID[i] = anElemNode->GetID();
132 // creates a corresponding element on copied nodes
133 SMDS_MeshElement* anElemCopy = 0;
134 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
136 const SMDS_VtkVolume* ph =
137 dynamic_cast<const SMDS_VtkVolume*> (anElem);
139 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
140 (anElemNodesID, ph->GetQuantities(),anElem->GetID());
143 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
150 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
152 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
153 anElemNode->GetID());
155 };// struct TPreviewMesh
157 static SMESH_NodeSearcher * theNodeSearcher = 0;
158 static SMESH_ElementSearcher * theElementSearcher = 0;
160 //=============================================================================
162 * \brief Deleter of theNodeSearcher at any compute event occured
164 //=============================================================================
166 struct TSearchersDeleter : public SMESH_subMeshEventListener
170 TSearchersDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
172 //!< Delete theNodeSearcher
175 if ( theNodeSearcher ) delete theNodeSearcher; theNodeSearcher = 0;
176 if ( theElementSearcher ) delete theElementSearcher; theElementSearcher = 0;
178 typedef map < int, SMESH_subMesh * > TDependsOnMap;
179 //!< The meshod called by submesh: do my main job
180 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
181 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
183 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
185 Unset( sm->GetFather() );
188 //!< set self on all submeshes and delete theNodeSearcher if other mesh is set
189 void Set(SMESH_Mesh* mesh)
191 if ( myMesh != mesh )
198 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
199 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
200 TDependsOnMap::const_iterator sm;
201 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
202 sm->second->SetEventListener( this, 0, sm->second );
206 //!< delete self from all submeshes
207 void Unset(SMESH_Mesh* mesh)
209 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
210 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
211 TDependsOnMap::const_iterator sm;
212 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
213 sm->second->DeleteEventListener( this );
218 } theSearchersDeleter;
220 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
222 TCollection_AsciiString typeStr;
223 switch ( theMirrorType ) {
224 case SMESH::SMESH_MeshEditor::POINT:
225 typeStr = "SMESH.SMESH_MeshEditor.POINT";
227 case SMESH::SMESH_MeshEditor::AXIS:
228 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
231 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
235 //================================================================================
237 * \brief function for conversion long_array to TIDSortedElemSet
238 * \param IDs - array of IDs
239 * \param aMesh - mesh
240 * \param aMap - collection to fill
241 * \param aType - element type
243 //================================================================================
245 void arrayToSet(const SMESH::long_array & IDs,
246 const SMESHDS_Mesh* aMesh,
247 TIDSortedElemSet& aMap,
248 const SMDSAbs_ElementType aType = SMDSAbs_All )
250 for (int i=0; i<IDs.length(); i++) {
251 CORBA::Long ind = IDs[i];
252 const SMDS_MeshElement * elem =
253 (aType == SMDSAbs_Node ? aMesh->FindNode(ind) : aMesh->FindElement(ind));
254 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
258 //================================================================================
260 * \brief Retrieve elements of given type from SMESH_IDSource
262 //================================================================================
264 bool idSourceToSet(SMESH::SMESH_IDSource_ptr theIDSource,
265 const SMESHDS_Mesh* theMeshDS,
266 TIDSortedElemSet& theElemSet,
267 const SMDSAbs_ElementType theType,
268 const bool emptyIfIsMesh=false)
271 if ( CORBA::is_nil( theIDSource ) )
273 if ( emptyIfIsMesh && SMESH::DownCast<SMESH_Mesh_i*>( theIDSource ))
276 SMESH::long_array_var anIDs = theIDSource->GetIDs();
277 if ( anIDs->length() == 0 )
279 SMESH::array_of_ElementType_var types = theIDSource->GetTypes();
280 if ( types->length() == 1 && types[0] == SMESH::NODE ) // group of nodes
282 if ( theType == SMDSAbs_All || theType == SMDSAbs_Node )
283 arrayToSet( anIDs, theMeshDS, theElemSet, SMDSAbs_Node );
289 arrayToSet( anIDs, theMeshDS, theElemSet, theType);
293 //================================================================================
295 * \brief Retrieve nodes from SMESH_IDSource
297 //================================================================================
299 void idSourceToNodeSet(SMESH::SMESH_IDSource_ptr theObject,
300 const SMESHDS_Mesh* theMeshDS,
301 TIDSortedNodeSet& theNodeSet)
304 if ( CORBA::is_nil( theObject ) )
306 SMESH::array_of_ElementType_var types = theObject->GetTypes();
307 SMESH::long_array_var aElementsId = theObject->GetIDs();
308 if ( types->length() == 1 && types[0] == SMESH::NODE)
310 for(int i = 0; i < aElementsId->length(); i++)
311 if ( const SMDS_MeshNode * n = theMeshDS->FindNode( aElementsId[i] ))
312 theNodeSet.insert( theNodeSet.end(), n);
315 for(int i = 0; i < aElementsId->length(); i++)
316 if( const SMDS_MeshElement * elem = theMeshDS->FindElement( aElementsId[i] ))
317 theNodeSet.insert( elem->begin_nodes(), elem->end_nodes());
322 //=============================================================================
326 //=============================================================================
328 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
331 myMesh = & theMesh->GetImpl();
332 myPreviewMode = isPreview;
335 //================================================================================
339 //================================================================================
341 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
345 //================================================================================
347 * \brief Clear members
349 //================================================================================
351 void SMESH_MeshEditor_i::initData(bool deleteSearchers)
353 if ( myPreviewMode ) {
354 myPreviewData = new SMESH::MeshPreviewStruct();
357 myLastCreatedElems = new SMESH::long_array();
358 myLastCreatedNodes = new SMESH::long_array();
359 if ( deleteSearchers )
360 TSearchersDeleter::Delete();
364 //=======================================================================
365 //function : MakeIDSource
366 //purpose : Wrap a sequence of ids in a SMESH_IDSource
367 //=======================================================================
369 struct _IDSource : public POA_SMESH::SMESH_IDSource
371 SMESH::long_array _ids;
372 SMESH::ElementType _type;
373 SMESH::SMESH_Mesh_ptr _mesh;
374 SMESH::long_array* GetIDs() { return new SMESH::long_array( _ids ); }
375 SMESH::long_array* GetMeshInfo() { return 0; }
376 SMESH::SMESH_Mesh_ptr GetMesh() { return SMESH::SMESH_Mesh::_duplicate( _mesh ); }
377 SMESH::array_of_ElementType* GetTypes()
379 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
382 return types._retn();
386 SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_array& ids,
387 SMESH::ElementType type)
389 _IDSource* anIDSource = new _IDSource;
390 anIDSource->_ids = ids;
391 anIDSource->_type = type;
392 anIDSource->_mesh = myMesh_i->_this();
393 SMESH::SMESH_IDSource_var anIDSourceVar = anIDSource->_this();
395 return anIDSourceVar._retn();
398 //=============================================================================
402 //=============================================================================
405 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
409 ::SMESH_MeshEditor anEditor( myMesh );
412 for (int i = 0; i < IDsOfElements.length(); i++)
413 IdList.push_back( IDsOfElements[i] );
415 // Update Python script
416 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
419 bool ret = anEditor.Remove( IdList, false );
420 myMesh->GetMeshDS()->Modified();
421 if ( IDsOfElements.length() )
422 myMesh->SetIsModified( true ); // issue 0020693
426 //=============================================================================
430 //=============================================================================
432 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
436 ::SMESH_MeshEditor anEditor( myMesh );
438 for (int i = 0; i < IDsOfNodes.length(); i++)
439 IdList.push_back( IDsOfNodes[i] );
441 // Update Python script
442 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
444 bool ret = anEditor.Remove( IdList, true );
445 myMesh->GetMeshDS()->Modified();
446 if ( IDsOfNodes.length() )
447 myMesh->SetIsModified( true ); // issue 0020693
451 //=============================================================================
455 //=============================================================================
457 CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes()
461 ::SMESH_MeshEditor anEditor( myMesh );
463 // Update Python script
464 TPythonDump() << "nbRemoved = " << this << ".RemoveOrphanNodes()";
466 // Create filter to find all orphan nodes
467 SMESH::Controls::Filter::TIdSequence seq;
468 SMESH::Controls::PredicatePtr predicate( new SMESH::Controls::FreeNodes() );
469 SMESH::Controls::Filter::GetElementsId( GetMeshDS(), predicate, seq );
471 // remove orphan nodes (if there are any)
473 for ( int i = 0; i < seq.size(); i++ )
474 IdList.push_back( seq[i] );
476 bool ret = anEditor.Remove( IdList, true );
477 myMesh->GetMeshDS()->Modified();
479 myMesh->SetIsModified( true );
484 //=============================================================================
488 //=============================================================================
490 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
491 CORBA::Double y, CORBA::Double z)
495 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
497 // Update Python script
498 TPythonDump() << "nodeID = " << this << ".AddNode( "
499 << x << ", " << y << ", " << z << " )";
501 myMesh->GetMeshDS()->Modified();
502 myMesh->SetIsModified( true ); // issue 0020693
506 //=============================================================================
510 //=============================================================================
511 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
515 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
516 SMDS_MeshElement* elem = GetMeshDS()->Add0DElement(aNode);
518 // Update Python script
519 TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
521 myMesh->GetMeshDS()->Modified();
522 myMesh->SetIsModified( true ); // issue 0020693
525 return elem->GetID();
530 //=============================================================================
534 //=============================================================================
536 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
540 int NbNodes = IDsOfNodes.length();
541 SMDS_MeshElement* elem = 0;
544 CORBA::Long index1 = IDsOfNodes[0];
545 CORBA::Long index2 = IDsOfNodes[1];
546 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
548 // Update Python script
549 TPythonDump() << "edge = " << this << ".AddEdge([ "
550 << index1 << ", " << index2 <<" ])";
553 CORBA::Long n1 = IDsOfNodes[0];
554 CORBA::Long n2 = IDsOfNodes[1];
555 CORBA::Long n12 = IDsOfNodes[2];
556 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
557 GetMeshDS()->FindNode(n2),
558 GetMeshDS()->FindNode(n12));
559 // Update Python script
560 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
561 <<n1<<", "<<n2<<", "<<n12<<" ])";
564 myMesh->GetMeshDS()->Modified();
566 return myMesh->SetIsModified( true ), elem->GetID();
571 //=============================================================================
575 //=============================================================================
577 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
581 int NbNodes = IDsOfNodes.length();
587 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
588 for (int i = 0; i < NbNodes; i++)
589 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
591 SMDS_MeshElement* elem = 0;
593 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
595 else if (NbNodes == 4) {
596 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
598 else if (NbNodes == 6) {
599 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
602 else if (NbNodes == 8) {
603 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
604 nodes[4], nodes[5], nodes[6], nodes[7]);
606 else if (NbNodes > 2) {
607 elem = GetMeshDS()->AddPolygonalFace(nodes);
610 // Update Python script
611 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
613 myMesh->GetMeshDS()->Modified();
615 return myMesh->SetIsModified( true ), elem->GetID();
620 //=============================================================================
624 //=============================================================================
625 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsOfNodes)
629 int NbNodes = IDsOfNodes.length();
630 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
631 for (int i = 0; i < NbNodes; i++)
632 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
634 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
636 // Update Python script
637 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
639 myMesh->GetMeshDS()->Modified();
640 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
643 //=============================================================================
647 //=============================================================================
649 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
653 int NbNodes = IDsOfNodes.length();
654 vector< const SMDS_MeshNode*> n(NbNodes);
655 for(int i=0;i<NbNodes;i++)
656 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
658 SMDS_MeshElement* elem = 0;
661 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
662 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
663 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
664 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
665 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
666 n[6],n[7],n[8],n[9]);
668 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
669 n[7],n[8],n[9],n[10],n[11],n[12]);
671 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
672 n[9],n[10],n[11],n[12],n[13],n[14]);
674 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
675 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
676 n[15],n[16],n[17],n[18],n[19]);
680 // Update Python script
681 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
683 myMesh->GetMeshDS()->Modified();
685 return myMesh->SetIsModified( true ), elem->GetID();
690 //=============================================================================
692 * AddPolyhedralVolume
694 //=============================================================================
695 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume (const SMESH::long_array & IDsOfNodes,
696 const SMESH::long_array & Quantities)
700 int NbNodes = IDsOfNodes.length();
701 std::vector<const SMDS_MeshNode*> n (NbNodes);
702 for (int i = 0; i < NbNodes; i++)
704 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDsOfNodes[i]);
705 if (!aNode) return 0;
709 int NbFaces = Quantities.length();
710 std::vector<int> q (NbFaces);
711 for (int j = 0; j < NbFaces; j++)
712 q[j] = Quantities[j];
714 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
716 // Update Python script
717 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
718 << IDsOfNodes << ", " << Quantities << " )";
719 myMesh->GetMeshDS()->Modified();
721 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
724 //=============================================================================
726 * AddPolyhedralVolumeByFaces
728 //=============================================================================
729 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_array & IdsOfFaces)
733 int NbFaces = IdsOfFaces.length();
734 std::vector<const SMDS_MeshNode*> poly_nodes;
735 std::vector<int> quantities (NbFaces);
737 for (int i = 0; i < NbFaces; i++) {
738 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
739 quantities[i] = aFace->NbNodes();
741 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
743 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
747 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
749 // Update Python script
750 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
751 << IdsOfFaces << " )";
752 myMesh->GetMeshDS()->Modified();
754 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
757 //=============================================================================
759 * \brief Bind a node to a vertex
760 * \param NodeID - node ID
761 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
762 * \retval boolean - false if NodeID or VertexID is invalid
764 //=============================================================================
766 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
767 throw (SALOME::SALOME_Exception)
769 Unexpect aCatch(SALOME_SalomeException);
771 SMESHDS_Mesh * mesh = GetMeshDS();
772 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
774 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
776 if ( mesh->MaxShapeIndex() < VertexID )
777 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
779 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
780 if ( shape.ShapeType() != TopAbs_VERTEX )
781 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
783 mesh->SetNodeOnVertex( node, VertexID );
785 myMesh->SetIsModified( true );
788 //=============================================================================
790 * \brief Store node position on an edge
791 * \param NodeID - node ID
792 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
793 * \param paramOnEdge - parameter on edge where the node is located
794 * \retval boolean - false if any parameter is invalid
796 //=============================================================================
798 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
799 CORBA::Double paramOnEdge)
800 throw (SALOME::SALOME_Exception)
802 Unexpect aCatch(SALOME_SalomeException);
804 SMESHDS_Mesh * mesh = GetMeshDS();
805 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
807 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
809 if ( mesh->MaxShapeIndex() < EdgeID )
810 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
812 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
813 if ( shape.ShapeType() != TopAbs_EDGE )
814 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
817 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
818 if ( paramOnEdge < f || paramOnEdge > l )
819 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
821 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
823 myMesh->SetIsModified( true );
826 //=============================================================================
828 * \brief Store node position on a face
829 * \param NodeID - node ID
830 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
831 * \param u - U parameter on face where the node is located
832 * \param v - V parameter on face where the node is located
833 * \retval boolean - false if any parameter is invalid
835 //=============================================================================
837 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
838 CORBA::Double u, CORBA::Double v)
839 throw (SALOME::SALOME_Exception)
841 Unexpect aCatch(SALOME_SalomeException);
843 SMESHDS_Mesh * mesh = GetMeshDS();
844 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
846 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
848 if ( mesh->MaxShapeIndex() < FaceID )
849 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
851 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
852 if ( shape.ShapeType() != TopAbs_FACE )
853 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
855 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
856 bool isOut = ( u < surf.FirstUParameter() ||
857 u > surf.LastUParameter() ||
858 v < surf.FirstVParameter() ||
859 v > surf.LastVParameter() );
863 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
864 << " u( " << surf.FirstUParameter()
865 << "," << surf.LastUParameter()
866 << ") v( " << surf.FirstVParameter()
867 << "," << surf.LastVParameter() << ")" );
869 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
872 mesh->SetNodeOnFace( node, FaceID, u, v );
873 myMesh->SetIsModified( true );
876 //=============================================================================
878 * \brief Bind a node to a solid
879 * \param NodeID - node ID
880 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
881 * \retval boolean - false if NodeID or SolidID is invalid
883 //=============================================================================
885 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
886 throw (SALOME::SALOME_Exception)
888 Unexpect aCatch(SALOME_SalomeException);
890 SMESHDS_Mesh * mesh = GetMeshDS();
891 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
893 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
895 if ( mesh->MaxShapeIndex() < SolidID )
896 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
898 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
899 if ( shape.ShapeType() != TopAbs_SOLID &&
900 shape.ShapeType() != TopAbs_SHELL)
901 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
903 mesh->SetNodeInVolume( node, SolidID );
905 // myMesh->SetIsModified( true ); - SetNodeInVolume() can't prevent re-compute, I believe
908 //=============================================================================
910 * \brief Bind an element to a shape
911 * \param ElementID - element ID
912 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
913 * \retval boolean - false if ElementID or ShapeID is invalid
915 //=============================================================================
917 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
919 throw (SALOME::SALOME_Exception)
921 Unexpect aCatch(SALOME_SalomeException);
923 SMESHDS_Mesh * mesh = GetMeshDS();
924 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
926 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
928 if ( mesh->MaxShapeIndex() < ShapeID )
929 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
931 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
932 if ( shape.ShapeType() != TopAbs_EDGE &&
933 shape.ShapeType() != TopAbs_FACE &&
934 shape.ShapeType() != TopAbs_SOLID &&
935 shape.ShapeType() != TopAbs_SHELL )
936 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
938 mesh->SetMeshElementOnShape( elem, ShapeID );
940 myMesh->SetIsModified( true );
943 //=============================================================================
947 //=============================================================================
949 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
954 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
955 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
959 // Update Python script
960 TPythonDump() << "isDone = " << this << ".InverseDiag( "
961 << NodeID1 << ", " << NodeID2 << " )";
964 ::SMESH_MeshEditor aMeshEditor( myMesh );
965 int ret = aMeshEditor.InverseDiag ( n1, n2 );
966 myMesh->GetMeshDS()->Modified();
967 myMesh->SetIsModified( true );
971 //=============================================================================
975 //=============================================================================
977 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
982 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
983 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
987 // Update Python script
988 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
989 << NodeID1 << ", " << NodeID2 << " )";
991 ::SMESH_MeshEditor aMeshEditor( myMesh );
993 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
995 myMesh->GetMeshDS()->Modified();
997 myMesh->SetIsModified( true ); // issue 0020693
999 storeResult(aMeshEditor);
1004 //=============================================================================
1008 //=============================================================================
1010 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
1014 ::SMESH_MeshEditor anEditor( myMesh );
1015 for (int i = 0; i < IDsOfElements.length(); i++)
1017 CORBA::Long index = IDsOfElements[i];
1018 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
1020 anEditor.Reorient( elem );
1022 // Update Python script
1023 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
1025 myMesh->GetMeshDS()->Modified();
1026 if ( IDsOfElements.length() )
1027 myMesh->SetIsModified( true ); // issue 0020693
1033 //=============================================================================
1037 //=============================================================================
1039 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
1043 TPythonDump aTPythonDump; // suppress dump in Reorient()
1045 SMESH::long_array_var anElementsId = theObject->GetIDs();
1046 CORBA::Boolean isDone = Reorient(anElementsId);
1048 // Update Python script
1049 aTPythonDump << "isDone = " << this << ".ReorientObject( " << theObject << " )";
1054 //=============================================================================
1058 //=============================================================================
1059 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
1060 SMESH::NumericalFunctor_ptr Criterion,
1061 CORBA::Double MaxAngle)
1065 SMESHDS_Mesh* aMesh = GetMeshDS();
1066 TIDSortedElemSet faces;
1067 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1069 SMESH::NumericalFunctor_i* aNumericalFunctor =
1070 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1071 SMESH::Controls::NumericalFunctorPtr aCrit;
1072 if ( !aNumericalFunctor )
1073 aCrit.reset( new SMESH::Controls::AspectRatio() );
1075 aCrit = aNumericalFunctor->GetNumericalFunctor();
1077 // Update Python script
1078 TPythonDump() << "isDone = " << this << ".TriToQuad( "
1079 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1081 ::SMESH_MeshEditor anEditor( myMesh );
1083 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
1084 myMesh->GetMeshDS()->Modified();
1086 myMesh->SetIsModified( true ); // issue 0020693
1088 storeResult(anEditor);
1094 //=============================================================================
1098 //=============================================================================
1099 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1100 SMESH::NumericalFunctor_ptr Criterion,
1101 CORBA::Double MaxAngle)
1105 TPythonDump aTPythonDump; // suppress dump in TriToQuad()
1106 SMESH::long_array_var anElementsId = theObject->GetIDs();
1107 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
1109 SMESH::NumericalFunctor_i* aNumericalFunctor =
1110 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1112 // Update Python script
1113 aTPythonDump << "isDone = " << this << ".TriToQuadObject("
1114 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1120 //=============================================================================
1124 //=============================================================================
1125 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
1126 SMESH::NumericalFunctor_ptr Criterion)
1130 SMESHDS_Mesh* aMesh = GetMeshDS();
1131 TIDSortedElemSet faces;
1132 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1134 SMESH::NumericalFunctor_i* aNumericalFunctor =
1135 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1136 SMESH::Controls::NumericalFunctorPtr aCrit;
1137 if ( !aNumericalFunctor )
1138 aCrit.reset( new SMESH::Controls::AspectRatio() );
1140 aCrit = aNumericalFunctor->GetNumericalFunctor();
1143 // Update Python script
1144 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1146 ::SMESH_MeshEditor anEditor( myMesh );
1147 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1148 myMesh->GetMeshDS()->Modified();
1150 myMesh->SetIsModified( true ); // issue 0020693
1152 storeResult(anEditor);
1158 //=============================================================================
1162 //=============================================================================
1163 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1164 SMESH::NumericalFunctor_ptr Criterion)
1168 TPythonDump aTPythonDump; // suppress dump in QuadToTri()
1170 SMESH::long_array_var anElementsId = theObject->GetIDs();
1171 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1173 SMESH::NumericalFunctor_i* aNumericalFunctor =
1174 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1176 // Update Python script
1177 aTPythonDump << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1183 //=============================================================================
1187 //=============================================================================
1188 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1189 CORBA::Boolean Diag13)
1193 SMESHDS_Mesh* aMesh = GetMeshDS();
1194 TIDSortedElemSet faces;
1195 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1197 // Update Python script
1198 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1199 << IDsOfElements << ", " << Diag13 << " )";
1201 ::SMESH_MeshEditor anEditor( myMesh );
1202 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1203 myMesh->GetMeshDS()->Modified();
1205 myMesh->SetIsModified( true ); // issue 0020693
1208 storeResult(anEditor);
1214 //=============================================================================
1218 //=============================================================================
1219 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1220 CORBA::Boolean Diag13)
1224 TPythonDump aTPythonDump; // suppress dump in SplitQuad()
1226 SMESH::long_array_var anElementsId = theObject->GetIDs();
1227 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1229 // Update Python script
1230 aTPythonDump << "isDone = " << this << ".SplitQuadObject( "
1231 << theObject << ", " << Diag13 << " )";
1237 //=============================================================================
1241 //=============================================================================
1242 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1243 SMESH::NumericalFunctor_ptr Criterion)
1247 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1248 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1250 SMESH::NumericalFunctor_i* aNumericalFunctor =
1251 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1252 SMESH::Controls::NumericalFunctorPtr aCrit;
1253 if (aNumericalFunctor)
1254 aCrit = aNumericalFunctor->GetNumericalFunctor();
1256 aCrit.reset(new SMESH::Controls::AspectRatio());
1258 ::SMESH_MeshEditor anEditor (myMesh);
1259 return anEditor.BestSplit(quad, aCrit);
1264 //================================================================================
1266 * \brief Split volumic elements into tetrahedrons
1268 //================================================================================
1270 void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems,
1271 CORBA::Short methodFlags)
1272 throw (SALOME::SALOME_Exception)
1274 Unexpect aCatch(SALOME_SalomeException);
1278 SMESH::long_array_var anElementsId = elems->GetIDs();
1279 TIDSortedElemSet elemSet;
1280 arrayToSet( anElementsId, GetMeshDS(), elemSet, SMDSAbs_Volume );
1282 ::SMESH_MeshEditor anEditor (myMesh);
1283 anEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags ));
1284 myMesh->GetMeshDS()->Modified();
1286 storeResult(anEditor);
1288 // if ( myLastCreatedElems.length() ) - it does not influence Compute()
1289 // myMesh->SetIsModified( true ); // issue 0020693
1291 TPythonDump() << this << ".SplitVolumesIntoTetra( "
1292 << elems << ", " << methodFlags << " )";
1295 //=======================================================================
1298 //=======================================================================
1301 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1302 const SMESH::long_array & IDsOfFixedNodes,
1303 CORBA::Long MaxNbOfIterations,
1304 CORBA::Double MaxAspectRatio,
1305 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1307 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1308 MaxAspectRatio, Method, false );
1312 //=======================================================================
1313 //function : SmoothParametric
1315 //=======================================================================
1318 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1319 const SMESH::long_array & IDsOfFixedNodes,
1320 CORBA::Long MaxNbOfIterations,
1321 CORBA::Double MaxAspectRatio,
1322 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1324 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1325 MaxAspectRatio, Method, true );
1329 //=======================================================================
1330 //function : SmoothObject
1332 //=======================================================================
1335 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1336 const SMESH::long_array & IDsOfFixedNodes,
1337 CORBA::Long MaxNbOfIterations,
1338 CORBA::Double MaxAspectRatio,
1339 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1341 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1342 MaxAspectRatio, Method, false);
1346 //=======================================================================
1347 //function : SmoothParametricObject
1349 //=======================================================================
1352 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1353 const SMESH::long_array & IDsOfFixedNodes,
1354 CORBA::Long MaxNbOfIterations,
1355 CORBA::Double MaxAspectRatio,
1356 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1358 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1359 MaxAspectRatio, Method, true);
1363 //=============================================================================
1367 //=============================================================================
1370 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1371 const SMESH::long_array & IDsOfFixedNodes,
1372 CORBA::Long MaxNbOfIterations,
1373 CORBA::Double MaxAspectRatio,
1374 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1379 SMESHDS_Mesh* aMesh = GetMeshDS();
1381 TIDSortedElemSet elements;
1382 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1384 set<const SMDS_MeshNode*> fixedNodes;
1385 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1386 CORBA::Long index = IDsOfFixedNodes[i];
1387 const SMDS_MeshNode * node = aMesh->FindNode(index);
1389 fixedNodes.insert( node );
1391 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1392 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1393 method = ::SMESH_MeshEditor::CENTROIDAL;
1395 ::SMESH_MeshEditor anEditor( myMesh );
1396 anEditor.Smooth(elements, fixedNodes, method,
1397 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1399 myMesh->GetMeshDS()->Modified();
1400 myMesh->SetIsModified( true ); // issue 0020693
1402 storeResult(anEditor);
1404 // Update Python script
1405 TPythonDump() << "isDone = " << this << "."
1406 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1407 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1408 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1409 << "SMESH.SMESH_MeshEditor."
1410 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1411 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1417 //=============================================================================
1421 //=============================================================================
1424 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1425 const SMESH::long_array & IDsOfFixedNodes,
1426 CORBA::Long MaxNbOfIterations,
1427 CORBA::Double MaxAspectRatio,
1428 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1433 TPythonDump aTPythonDump; // suppress dump in smooth()
1435 SMESH::long_array_var anElementsId = theObject->GetIDs();
1436 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1437 MaxAspectRatio, Method, IsParametric);
1439 // Update Python script
1440 aTPythonDump << "isDone = " << this << "."
1441 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1442 << theObject << ", " << IDsOfFixedNodes << ", "
1443 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1444 << "SMESH.SMESH_MeshEditor."
1445 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1446 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1452 //=============================================================================
1456 //=============================================================================
1458 void SMESH_MeshEditor_i::RenumberNodes()
1460 // Update Python script
1461 TPythonDump() << this << ".RenumberNodes()";
1463 GetMeshDS()->Renumber( true );
1467 //=============================================================================
1471 //=============================================================================
1473 void SMESH_MeshEditor_i::RenumberElements()
1475 // Update Python script
1476 TPythonDump() << this << ".RenumberElements()";
1478 GetMeshDS()->Renumber( false );
1481 //=======================================================================
1483 * \brief Return groups by their IDs
1485 //=======================================================================
1487 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1491 myMesh_i->CreateGroupServants();
1492 return myMesh_i->GetGroups( *groupIDs );
1495 //=======================================================================
1496 //function : rotationSweep
1498 //=======================================================================
1500 SMESH::ListOfGroups*
1501 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1502 const SMESH::AxisStruct & theAxis,
1503 CORBA::Double theAngleInRadians,
1504 CORBA::Long theNbOfSteps,
1505 CORBA::Double theTolerance,
1506 const bool theMakeGroups,
1507 const SMDSAbs_ElementType theElementType)
1511 TIDSortedElemSet inElements, copyElements;
1512 arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType);
1514 TIDSortedElemSet* workElements = & inElements;
1515 TPreviewMesh tmpMesh( SMDSAbs_Face );
1516 SMESH_Mesh* mesh = 0;
1517 bool makeWalls=true;
1518 if ( myPreviewMode )
1520 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1521 tmpMesh.Copy( inElements, copyElements, select, avoid );
1523 workElements = & copyElements;
1524 //makeWalls = false;
1531 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1532 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1534 ::SMESH_MeshEditor anEditor( mesh );
1535 ::SMESH_MeshEditor::PGroupIDs groupIds =
1536 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1537 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1538 storeResult(anEditor);
1539 myMesh->GetMeshDS()->Modified();
1541 // myMesh->SetIsModified( true ); -- it does not influence Compute()
1543 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1546 //=======================================================================
1547 //function : RotationSweep
1549 //=======================================================================
1551 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1552 const SMESH::AxisStruct & theAxis,
1553 CORBA::Double theAngleInRadians,
1554 CORBA::Long theNbOfSteps,
1555 CORBA::Double theTolerance)
1557 if ( !myPreviewMode ) {
1558 TPythonDump() << this << ".RotationSweep( "
1559 << theIDsOfElements << ", "
1561 << theAngleInRadians << ", "
1562 << theNbOfSteps << ", "
1563 << theTolerance << " )";
1565 rotationSweep(theIDsOfElements,
1573 //=======================================================================
1574 //function : RotationSweepMakeGroups
1576 //=======================================================================
1578 SMESH::ListOfGroups*
1579 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1580 const SMESH::AxisStruct& theAxis,
1581 CORBA::Double theAngleInRadians,
1582 CORBA::Long theNbOfSteps,
1583 CORBA::Double theTolerance)
1585 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1587 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1593 if (!myPreviewMode) {
1594 DumpGroupsList(aPythonDump, aGroups);
1595 aPythonDump << this << ".RotationSweepMakeGroups( "
1596 << theIDsOfElements << ", "
1598 << theAngleInRadians << ", "
1599 << theNbOfSteps << ", "
1600 << theTolerance << " )";
1605 //=======================================================================
1606 //function : RotationSweepObject
1608 //=======================================================================
1610 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1611 const SMESH::AxisStruct & theAxis,
1612 CORBA::Double theAngleInRadians,
1613 CORBA::Long theNbOfSteps,
1614 CORBA::Double theTolerance)
1616 if ( !myPreviewMode ) {
1617 TPythonDump() << this << ".RotationSweepObject( "
1618 << theObject << ", "
1620 << theAngleInRadians << ", "
1621 << theNbOfSteps << ", "
1622 << theTolerance << " )";
1624 SMESH::long_array_var anElementsId = theObject->GetIDs();
1625 rotationSweep(anElementsId,
1633 //=======================================================================
1634 //function : RotationSweepObject1D
1636 //=======================================================================
1638 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1639 const SMESH::AxisStruct & theAxis,
1640 CORBA::Double theAngleInRadians,
1641 CORBA::Long theNbOfSteps,
1642 CORBA::Double theTolerance)
1644 if ( !myPreviewMode ) {
1645 TPythonDump() << this << ".RotationSweepObject1D( "
1646 << theObject << ", "
1648 << theAngleInRadians << ", "
1649 << theNbOfSteps << ", "
1650 << theTolerance << " )";
1652 SMESH::long_array_var anElementsId = theObject->GetIDs();
1653 rotationSweep(anElementsId,
1662 //=======================================================================
1663 //function : RotationSweepObject2D
1665 //=======================================================================
1667 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1668 const SMESH::AxisStruct & theAxis,
1669 CORBA::Double theAngleInRadians,
1670 CORBA::Long theNbOfSteps,
1671 CORBA::Double theTolerance)
1673 if ( !myPreviewMode ) {
1674 TPythonDump() << this << ".RotationSweepObject2D( "
1675 << theObject << ", "
1677 << theAngleInRadians << ", "
1678 << theNbOfSteps << ", "
1679 << theTolerance << " )";
1681 SMESH::long_array_var anElementsId = theObject->GetIDs();
1682 rotationSweep(anElementsId,
1691 //=======================================================================
1692 //function : RotationSweepObjectMakeGroups
1694 //=======================================================================
1696 SMESH::ListOfGroups*
1697 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1698 const SMESH::AxisStruct& theAxis,
1699 CORBA::Double theAngleInRadians,
1700 CORBA::Long theNbOfSteps,
1701 CORBA::Double theTolerance)
1703 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1705 SMESH::long_array_var anElementsId = theObject->GetIDs();
1706 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1712 if (!myPreviewMode) {
1713 DumpGroupsList(aPythonDump, aGroups);
1714 aPythonDump << this << ".RotationSweepObjectMakeGroups( "
1715 << theObject << ", "
1717 << theAngleInRadians << ", "
1718 << theNbOfSteps << ", "
1719 << theTolerance << " )";
1724 //=======================================================================
1725 //function : RotationSweepObject1DMakeGroups
1727 //=======================================================================
1729 SMESH::ListOfGroups*
1730 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1731 const SMESH::AxisStruct& theAxis,
1732 CORBA::Double theAngleInRadians,
1733 CORBA::Long theNbOfSteps,
1734 CORBA::Double theTolerance)
1736 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1738 SMESH::long_array_var anElementsId = theObject->GetIDs();
1739 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1746 if (!myPreviewMode) {
1747 DumpGroupsList(aPythonDump, aGroups);
1748 aPythonDump << this << ".RotationSweepObject1DMakeGroups( "
1749 << theObject << ", "
1751 << theAngleInRadians << ", "
1752 << theNbOfSteps << ", "
1753 << theTolerance << " )";
1758 //=======================================================================
1759 //function : RotationSweepObject2DMakeGroups
1761 //=======================================================================
1763 SMESH::ListOfGroups*
1764 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1765 const SMESH::AxisStruct& theAxis,
1766 CORBA::Double theAngleInRadians,
1767 CORBA::Long theNbOfSteps,
1768 CORBA::Double theTolerance)
1770 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1772 SMESH::long_array_var anElementsId = theObject->GetIDs();
1773 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1780 if (!myPreviewMode) {
1781 DumpGroupsList(aPythonDump, aGroups);
1782 aPythonDump << this << ".RotationSweepObject2DMakeGroups( "
1783 << theObject << ", "
1785 << theAngleInRadians << ", "
1786 << theNbOfSteps << ", "
1787 << theTolerance << " )";
1793 //=======================================================================
1794 //function : extrusionSweep
1796 //=======================================================================
1798 SMESH::ListOfGroups*
1799 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1800 const SMESH::DirStruct & theStepVector,
1801 CORBA::Long theNbOfSteps,
1802 const bool theMakeGroups,
1803 const SMDSAbs_ElementType theElementType)
1811 TIDSortedElemSet elements;
1812 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1814 const SMESH::PointStruct * P = &theStepVector.PS;
1815 gp_Vec stepVec( P->x, P->y, P->z );
1817 TElemOfElemListMap aHystory;
1818 ::SMESH_MeshEditor anEditor( myMesh );
1819 ::SMESH_MeshEditor::PGroupIDs groupIds =
1820 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1822 myMesh->GetMeshDS()->Modified();
1823 storeResult(anEditor);
1825 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1827 } catch(Standard_Failure) {
1828 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1829 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1834 //=======================================================================
1835 //function : ExtrusionSweep
1837 //=======================================================================
1839 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1840 const SMESH::DirStruct & theStepVector,
1841 CORBA::Long theNbOfSteps)
1843 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1844 if (!myPreviewMode) {
1845 TPythonDump() << this << ".ExtrusionSweep( "
1846 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1851 //=======================================================================
1852 //function : ExtrusionSweepObject
1854 //=======================================================================
1856 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1857 const SMESH::DirStruct & theStepVector,
1858 CORBA::Long theNbOfSteps)
1860 SMESH::long_array_var anElementsId = theObject->GetIDs();
1861 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1862 if (!myPreviewMode) {
1863 TPythonDump() << this << ".ExtrusionSweepObject( "
1864 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1868 //=======================================================================
1869 //function : ExtrusionSweepObject1D
1871 //=======================================================================
1873 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1874 const SMESH::DirStruct & theStepVector,
1875 CORBA::Long theNbOfSteps)
1877 SMESH::long_array_var anElementsId = theObject->GetIDs();
1878 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1879 if ( !myPreviewMode ) {
1880 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1881 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1885 //=======================================================================
1886 //function : ExtrusionSweepObject2D
1888 //=======================================================================
1890 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1891 const SMESH::DirStruct & theStepVector,
1892 CORBA::Long theNbOfSteps)
1894 SMESH::long_array_var anElementsId = theObject->GetIDs();
1895 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1896 if ( !myPreviewMode ) {
1897 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1898 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1902 //=======================================================================
1903 //function : ExtrusionSweepMakeGroups
1905 //=======================================================================
1907 SMESH::ListOfGroups*
1908 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1909 const SMESH::DirStruct& theStepVector,
1910 CORBA::Long theNbOfSteps)
1912 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1914 SMESH::ListOfGroups* aGroups = extrusionSweep(theIDsOfElements, theStepVector, theNbOfSteps, true);
1916 if (!myPreviewMode) {
1917 DumpGroupsList(aPythonDump, aGroups);
1918 aPythonDump << this << ".ExtrusionSweepMakeGroups( " << theIDsOfElements
1919 << ", " << theStepVector <<", " << theNbOfSteps << " )";
1924 //=======================================================================
1925 //function : ExtrusionSweepObjectMakeGroups
1927 //=======================================================================
1929 SMESH::ListOfGroups*
1930 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1931 const SMESH::DirStruct& theStepVector,
1932 CORBA::Long theNbOfSteps)
1934 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1936 SMESH::long_array_var anElementsId = theObject->GetIDs();
1937 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector, theNbOfSteps, true);
1939 if (!myPreviewMode) {
1940 DumpGroupsList(aPythonDump, aGroups);
1941 aPythonDump << this << ".ExtrusionSweepObjectMakeGroups( " << theObject
1942 << ", " << theStepVector << ", " << theNbOfSteps << " )";
1947 //=======================================================================
1948 //function : ExtrusionSweepObject1DMakeGroups
1950 //=======================================================================
1952 SMESH::ListOfGroups*
1953 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1954 const SMESH::DirStruct& theStepVector,
1955 CORBA::Long theNbOfSteps)
1957 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1959 SMESH::long_array_var anElementsId = theObject->GetIDs();
1960 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector,
1961 theNbOfSteps, true, SMDSAbs_Edge);
1962 if (!myPreviewMode) {
1963 DumpGroupsList(aPythonDump, aGroups);
1964 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( " << theObject
1965 << ", " << theStepVector << ", " << theNbOfSteps << " )";
1970 //=======================================================================
1971 //function : ExtrusionSweepObject2DMakeGroups
1973 //=======================================================================
1975 SMESH::ListOfGroups*
1976 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1977 const SMESH::DirStruct& theStepVector,
1978 CORBA::Long theNbOfSteps)
1980 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1982 SMESH::long_array_var anElementsId = theObject->GetIDs();
1983 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector,
1984 theNbOfSteps, true, SMDSAbs_Face);
1985 if (!myPreviewMode) {
1986 DumpGroupsList(aPythonDump, aGroups);
1987 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( " << theObject
1988 << ", " << theStepVector << ", " << theNbOfSteps << " )";
1994 //=======================================================================
1995 //function : advancedExtrusion
1997 //=======================================================================
1999 SMESH::ListOfGroups*
2000 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
2001 const SMESH::DirStruct & theStepVector,
2002 CORBA::Long theNbOfSteps,
2003 CORBA::Long theExtrFlags,
2004 CORBA::Double theSewTolerance,
2005 const bool theMakeGroups)
2009 TIDSortedElemSet elements;
2010 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2012 const SMESH::PointStruct * P = &theStepVector.PS;
2013 gp_Vec stepVec( P->x, P->y, P->z );
2015 ::SMESH_MeshEditor anEditor( myMesh );
2016 TElemOfElemListMap aHystory;
2017 ::SMESH_MeshEditor::PGroupIDs groupIds =
2018 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
2019 theMakeGroups, theExtrFlags, theSewTolerance);
2020 storeResult(anEditor);
2022 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2025 //=======================================================================
2026 //function : AdvancedExtrusion
2028 //=======================================================================
2030 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
2031 const SMESH::DirStruct & theStepVector,
2032 CORBA::Long theNbOfSteps,
2033 CORBA::Long theExtrFlags,
2034 CORBA::Double theSewTolerance)
2036 if ( !myPreviewMode ) {
2037 TPythonDump() << "stepVector = " << theStepVector;
2038 TPythonDump() << this << ".AdvancedExtrusion("
2041 << theNbOfSteps << ","
2042 << theExtrFlags << ", "
2043 << theSewTolerance << " )";
2045 advancedExtrusion( theIDsOfElements,
2053 //=======================================================================
2054 //function : AdvancedExtrusionMakeGroups
2056 //=======================================================================
2057 SMESH::ListOfGroups*
2058 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
2059 const SMESH::DirStruct& theStepVector,
2060 CORBA::Long theNbOfSteps,
2061 CORBA::Long theExtrFlags,
2062 CORBA::Double theSewTolerance)
2064 if (!myPreviewMode) {
2065 TPythonDump() << "stepVector = " << theStepVector;
2067 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2069 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
2076 if (!myPreviewMode) {
2077 DumpGroupsList(aPythonDump, aGroups);
2078 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
2081 << theNbOfSteps << ","
2082 << theExtrFlags << ", "
2083 << theSewTolerance << " )";
2089 //================================================================================
2091 * \brief Convert extrusion error to IDL enum
2093 //================================================================================
2095 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2097 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
2101 RETCASE( EXTR_NO_ELEMENTS );
2102 RETCASE( EXTR_PATH_NOT_EDGE );
2103 RETCASE( EXTR_BAD_PATH_SHAPE );
2104 RETCASE( EXTR_BAD_STARTING_NODE );
2105 RETCASE( EXTR_BAD_ANGLES_NUMBER );
2106 RETCASE( EXTR_CANT_GET_TANGENT );
2108 return SMESH::SMESH_MeshEditor::EXTR_OK;
2112 //=======================================================================
2113 //function : extrusionAlongPath
2115 //=======================================================================
2116 SMESH::ListOfGroups*
2117 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2118 SMESH::SMESH_Mesh_ptr thePathMesh,
2119 GEOM::GEOM_Object_ptr thePathShape,
2120 CORBA::Long theNodeStart,
2121 CORBA::Boolean theHasAngles,
2122 const SMESH::double_array & theAngles,
2123 CORBA::Boolean theHasRefPoint,
2124 const SMESH::PointStruct & theRefPoint,
2125 const bool theMakeGroups,
2126 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
2127 const SMDSAbs_ElementType theElementType)
2129 MESSAGE("extrusionAlongPath");
2132 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
2133 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2136 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2138 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2139 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2141 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
2142 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2146 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
2148 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2152 TIDSortedElemSet elements;
2153 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
2155 list<double> angles;
2156 for (int i = 0; i < theAngles.length(); i++) {
2157 angles.push_back( theAngles[i] );
2160 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
2162 int nbOldGroups = myMesh->NbGroup();
2164 ::SMESH_MeshEditor anEditor( myMesh );
2165 ::SMESH_MeshEditor::Extrusion_Error error =
2166 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
2167 theHasAngles, angles, false,
2168 theHasRefPoint, refPnt, theMakeGroups );
2169 myMesh->GetMeshDS()->Modified();
2170 storeResult(anEditor);
2171 theError = convExtrError( error );
2173 if ( theMakeGroups ) {
2174 list<int> groupIDs = myMesh->GetGroupIds();
2175 list<int>::iterator newBegin = groupIDs.begin();
2176 std::advance( newBegin, nbOldGroups ); // skip old groups
2177 groupIDs.erase( groupIDs.begin(), newBegin );
2178 return getGroups( & groupIDs );
2184 //=======================================================================
2185 //function : extrusionAlongPathX
2187 //=======================================================================
2188 SMESH::ListOfGroups*
2189 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2190 SMESH::SMESH_IDSource_ptr Path,
2191 CORBA::Long NodeStart,
2192 CORBA::Boolean HasAngles,
2193 const SMESH::double_array& Angles,
2194 CORBA::Boolean LinearVariation,
2195 CORBA::Boolean HasRefPoint,
2196 const SMESH::PointStruct& RefPoint,
2197 const bool MakeGroups,
2198 const SMDSAbs_ElementType ElementType,
2199 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2201 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2205 list<double> angles;
2206 for (int i = 0; i < Angles.length(); i++) {
2207 angles.push_back( Angles[i] );
2209 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2210 int nbOldGroups = myMesh->NbGroup();
2212 if ( Path->_is_nil() ) {
2213 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2217 TIDSortedElemSet elements;
2218 arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
2220 ::SMESH_MeshEditor anEditor( myMesh );
2221 ::SMESH_MeshEditor::Extrusion_Error error;
2223 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
2226 SMDS_MeshNode* aNodeStart =
2227 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2228 if ( !aNodeStart ) {
2229 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2232 error = anEditor.ExtrusionAlongTrack( elements, &(aMeshImp->GetImpl()), aNodeStart,
2233 HasAngles, angles, LinearVariation,
2234 HasRefPoint, refPnt, MakeGroups );
2235 myMesh->GetMeshDS()->Modified();
2238 SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
2241 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
2242 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
2243 SMDS_MeshNode* aNodeStart =
2244 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2245 if ( !aNodeStart ) {
2246 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2249 SMESH_subMesh* aSubMesh =
2250 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
2251 error = anEditor.ExtrusionAlongTrack( elements, aSubMesh, aNodeStart,
2252 HasAngles, angles, LinearVariation,
2253 HasRefPoint, refPnt, MakeGroups );
2254 myMesh->GetMeshDS()->Modified();
2257 SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
2259 // path as group of 1D elements
2263 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2269 storeResult(anEditor);
2270 Error = convExtrError( error );
2273 list<int> groupIDs = myMesh->GetGroupIds();
2274 list<int>::iterator newBegin = groupIDs.begin();
2275 std::advance( newBegin, nbOldGroups ); // skip old groups
2276 groupIDs.erase( groupIDs.begin(), newBegin );
2277 return getGroups( & groupIDs );
2283 //=======================================================================
2284 //function : ExtrusionAlongPath
2286 //=======================================================================
2287 SMESH::SMESH_MeshEditor::Extrusion_Error
2288 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2289 SMESH::SMESH_Mesh_ptr thePathMesh,
2290 GEOM::GEOM_Object_ptr thePathShape,
2291 CORBA::Long theNodeStart,
2292 CORBA::Boolean theHasAngles,
2293 const SMESH::double_array & theAngles,
2294 CORBA::Boolean theHasRefPoint,
2295 const SMESH::PointStruct & theRefPoint)
2297 MESSAGE("ExtrusionAlongPath");
2298 if ( !myPreviewMode ) {
2299 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
2300 << theIDsOfElements << ", "
2301 << thePathMesh << ", "
2302 << thePathShape << ", "
2303 << theNodeStart << ", "
2304 << theHasAngles << ", "
2305 << theAngles << ", "
2306 << theHasRefPoint << ", "
2307 << "SMESH.PointStruct( "
2308 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2309 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2310 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2312 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2313 extrusionAlongPath( theIDsOfElements,
2326 //=======================================================================
2327 //function : ExtrusionAlongPathObject
2329 //=======================================================================
2330 SMESH::SMESH_MeshEditor::Extrusion_Error
2331 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
2332 SMESH::SMESH_Mesh_ptr thePathMesh,
2333 GEOM::GEOM_Object_ptr thePathShape,
2334 CORBA::Long theNodeStart,
2335 CORBA::Boolean theHasAngles,
2336 const SMESH::double_array & theAngles,
2337 CORBA::Boolean theHasRefPoint,
2338 const SMESH::PointStruct & theRefPoint)
2340 if ( !myPreviewMode ) {
2341 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
2342 << theObject << ", "
2343 << thePathMesh << ", "
2344 << thePathShape << ", "
2345 << theNodeStart << ", "
2346 << theHasAngles << ", "
2347 << theAngles << ", "
2348 << theHasRefPoint << ", "
2349 << "SMESH.PointStruct( "
2350 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2351 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2352 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2354 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2355 SMESH::long_array_var anElementsId = theObject->GetIDs();
2356 extrusionAlongPath( anElementsId,
2369 //=======================================================================
2370 //function : ExtrusionAlongPathObject1D
2372 //=======================================================================
2373 SMESH::SMESH_MeshEditor::Extrusion_Error
2374 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
2375 SMESH::SMESH_Mesh_ptr thePathMesh,
2376 GEOM::GEOM_Object_ptr thePathShape,
2377 CORBA::Long theNodeStart,
2378 CORBA::Boolean theHasAngles,
2379 const SMESH::double_array & theAngles,
2380 CORBA::Boolean theHasRefPoint,
2381 const SMESH::PointStruct & theRefPoint)
2383 if ( !myPreviewMode ) {
2384 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
2385 << theObject << ", "
2386 << thePathMesh << ", "
2387 << thePathShape << ", "
2388 << theNodeStart << ", "
2389 << theHasAngles << ", "
2390 << theAngles << ", "
2391 << theHasRefPoint << ", "
2392 << "SMESH.PointStruct( "
2393 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2394 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2395 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2397 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2398 SMESH::long_array_var anElementsId = theObject->GetIDs();
2399 extrusionAlongPath( anElementsId,
2413 //=======================================================================
2414 //function : ExtrusionAlongPathObject2D
2416 //=======================================================================
2417 SMESH::SMESH_MeshEditor::Extrusion_Error
2418 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
2419 SMESH::SMESH_Mesh_ptr thePathMesh,
2420 GEOM::GEOM_Object_ptr thePathShape,
2421 CORBA::Long theNodeStart,
2422 CORBA::Boolean theHasAngles,
2423 const SMESH::double_array & theAngles,
2424 CORBA::Boolean theHasRefPoint,
2425 const SMESH::PointStruct & theRefPoint)
2427 if ( !myPreviewMode ) {
2428 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
2429 << theObject << ", "
2430 << thePathMesh << ", "
2431 << thePathShape << ", "
2432 << theNodeStart << ", "
2433 << theHasAngles << ", "
2434 << theAngles << ", "
2435 << theHasRefPoint << ", "
2436 << "SMESH.PointStruct( "
2437 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2438 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2439 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2441 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2442 SMESH::long_array_var anElementsId = theObject->GetIDs();
2443 extrusionAlongPath( anElementsId,
2458 //=======================================================================
2459 //function : ExtrusionAlongPathMakeGroups
2461 //=======================================================================
2462 SMESH::ListOfGroups*
2463 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2464 SMESH::SMESH_Mesh_ptr thePathMesh,
2465 GEOM::GEOM_Object_ptr thePathShape,
2466 CORBA::Long theNodeStart,
2467 CORBA::Boolean theHasAngles,
2468 const SMESH::double_array& theAngles,
2469 CORBA::Boolean theHasRefPoint,
2470 const SMESH::PointStruct& theRefPoint,
2471 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2473 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2475 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2485 if (!myPreviewMode) {
2486 bool isDumpGroups = aGroups && aGroups->length() > 0;
2488 aPythonDump << "(" << aGroups << ", error)";
2490 aPythonDump <<"error";
2492 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2493 << theIDsOfElements << ", "
2494 << thePathMesh << ", "
2495 << thePathShape << ", "
2496 << theNodeStart << ", "
2497 << theHasAngles << ", "
2498 << theAngles << ", "
2499 << theHasRefPoint << ", "
2500 << "SMESH.PointStruct( "
2501 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2502 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2503 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2508 //=======================================================================
2509 //function : ExtrusionAlongPathObjectMakeGroups
2511 //=======================================================================
2512 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2513 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2514 SMESH::SMESH_Mesh_ptr thePathMesh,
2515 GEOM::GEOM_Object_ptr thePathShape,
2516 CORBA::Long theNodeStart,
2517 CORBA::Boolean theHasAngles,
2518 const SMESH::double_array& theAngles,
2519 CORBA::Boolean theHasRefPoint,
2520 const SMESH::PointStruct& theRefPoint,
2521 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2523 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2525 SMESH::long_array_var anElementsId = theObject->GetIDs();
2526 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2537 if (!myPreviewMode) {
2538 bool isDumpGroups = aGroups && aGroups->length() > 0;
2540 aPythonDump << "(" << aGroups << ", error)";
2542 aPythonDump <<"error";
2544 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2545 << theObject << ", "
2546 << thePathMesh << ", "
2547 << thePathShape << ", "
2548 << theNodeStart << ", "
2549 << theHasAngles << ", "
2550 << theAngles << ", "
2551 << theHasRefPoint << ", "
2552 << "SMESH.PointStruct( "
2553 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2554 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2555 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2560 //=======================================================================
2561 //function : ExtrusionAlongPathObject1DMakeGroups
2563 //=======================================================================
2564 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2565 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2566 SMESH::SMESH_Mesh_ptr thePathMesh,
2567 GEOM::GEOM_Object_ptr thePathShape,
2568 CORBA::Long theNodeStart,
2569 CORBA::Boolean theHasAngles,
2570 const SMESH::double_array& theAngles,
2571 CORBA::Boolean theHasRefPoint,
2572 const SMESH::PointStruct& theRefPoint,
2573 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2575 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2577 SMESH::long_array_var anElementsId = theObject->GetIDs();
2578 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2590 if (!myPreviewMode) {
2591 bool isDumpGroups = aGroups && aGroups->length() > 0;
2593 aPythonDump << "(" << aGroups << ", error)";
2595 aPythonDump << "error";
2597 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
2598 << theObject << ", "
2599 << thePathMesh << ", "
2600 << thePathShape << ", "
2601 << theNodeStart << ", "
2602 << theHasAngles << ", "
2603 << theAngles << ", "
2604 << theHasRefPoint << ", "
2605 << "SMESH.PointStruct( "
2606 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2607 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2608 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2613 //=======================================================================
2614 //function : ExtrusionAlongPathObject2DMakeGroups
2616 //=======================================================================
2617 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2618 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2619 SMESH::SMESH_Mesh_ptr thePathMesh,
2620 GEOM::GEOM_Object_ptr thePathShape,
2621 CORBA::Long theNodeStart,
2622 CORBA::Boolean theHasAngles,
2623 const SMESH::double_array& theAngles,
2624 CORBA::Boolean theHasRefPoint,
2625 const SMESH::PointStruct& theRefPoint,
2626 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2628 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2630 SMESH::long_array_var anElementsId = theObject->GetIDs();
2631 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2643 if (!myPreviewMode) {
2644 bool isDumpGroups = aGroups && aGroups->length() > 0;
2646 aPythonDump << "(" << aGroups << ", error)";
2648 aPythonDump << "error";
2650 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
2651 << theObject << ", "
2652 << thePathMesh << ", "
2653 << thePathShape << ", "
2654 << theNodeStart << ", "
2655 << theHasAngles << ", "
2656 << theAngles << ", "
2657 << theHasRefPoint << ", "
2658 << "SMESH.PointStruct( "
2659 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2660 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2661 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2667 //=======================================================================
2668 //function : ExtrusionAlongPathObjX
2670 //=======================================================================
2671 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2672 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
2673 SMESH::SMESH_IDSource_ptr Path,
2674 CORBA::Long NodeStart,
2675 CORBA::Boolean HasAngles,
2676 const SMESH::double_array& Angles,
2677 CORBA::Boolean LinearVariation,
2678 CORBA::Boolean HasRefPoint,
2679 const SMESH::PointStruct& RefPoint,
2680 CORBA::Boolean MakeGroups,
2681 SMESH::ElementType ElemType,
2682 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2684 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2686 SMESH::long_array_var anElementsId = Object->GetIDs();
2687 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2696 (SMDSAbs_ElementType)ElemType,
2699 if (!myPreviewMode) {
2700 bool isDumpGroups = aGroups && aGroups->length() > 0;
2702 aPythonDump << "(" << *aGroups << ", error)";
2704 aPythonDump << "error";
2706 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2709 << NodeStart << ", "
2710 << HasAngles << ", "
2712 << LinearVariation << ", "
2713 << HasRefPoint << ", "
2714 << "SMESH.PointStruct( "
2715 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2716 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2717 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2718 << MakeGroups << ", "
2719 << ElemType << " )";
2725 //=======================================================================
2726 //function : ExtrusionAlongPathX
2728 //=======================================================================
2729 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2730 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2731 SMESH::SMESH_IDSource_ptr Path,
2732 CORBA::Long NodeStart,
2733 CORBA::Boolean HasAngles,
2734 const SMESH::double_array& Angles,
2735 CORBA::Boolean LinearVariation,
2736 CORBA::Boolean HasRefPoint,
2737 const SMESH::PointStruct& RefPoint,
2738 CORBA::Boolean MakeGroups,
2739 SMESH::ElementType ElemType,
2740 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2742 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2744 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2753 (SMDSAbs_ElementType)ElemType,
2756 if (!myPreviewMode) {
2757 bool isDumpGroups = aGroups && aGroups->length() > 0;
2759 aPythonDump << "(" << *aGroups << ", error)";
2761 aPythonDump <<"error";
2763 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2764 << IDsOfElements << ", "
2766 << NodeStart << ", "
2767 << HasAngles << ", "
2769 << LinearVariation << ", "
2770 << HasRefPoint << ", "
2771 << "SMESH.PointStruct( "
2772 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2773 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2774 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2775 << MakeGroups << ", "
2776 << ElemType << " )";
2782 //================================================================================
2784 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2785 * of given angles along path steps
2786 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2787 * which proceeds the extrusion
2788 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2789 * is used to define the sub-mesh for the path
2791 //================================================================================
2793 SMESH::double_array*
2794 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2795 GEOM::GEOM_Object_ptr thePathShape,
2796 const SMESH::double_array & theAngles)
2798 SMESH::double_array_var aResult = new SMESH::double_array();
2799 int nbAngles = theAngles.length();
2800 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2802 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2803 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2804 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2805 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2806 return aResult._retn();
2807 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2808 if ( nbSteps == nbAngles )
2810 aResult.inout() = theAngles;
2814 aResult->length( nbSteps );
2815 double rAn2St = double( nbAngles ) / double( nbSteps );
2816 double angPrev = 0, angle;
2817 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2819 double angCur = rAn2St * ( iSt+1 );
2820 double angCurFloor = floor( angCur );
2821 double angPrevFloor = floor( angPrev );
2822 if ( angPrevFloor == angCurFloor )
2823 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2826 int iP = int( angPrevFloor );
2827 double angPrevCeil = ceil(angPrev);
2828 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2830 int iC = int( angCurFloor );
2831 if ( iC < nbAngles )
2832 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2834 iP = int( angPrevCeil );
2836 angle += theAngles[ iC ];
2838 aResult[ iSt ] = angle;
2843 // Update Python script
2844 TPythonDump() << "rotAngles = " << theAngles;
2845 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2846 << thePathMesh << ", "
2847 << thePathShape << ", "
2850 return aResult._retn();
2854 //=======================================================================
2857 //=======================================================================
2859 SMESH::ListOfGroups*
2860 SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements,
2861 const SMESH::AxisStruct & theAxis,
2862 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2863 CORBA::Boolean theCopy,
2864 const bool theMakeGroups,
2865 ::SMESH_Mesh* theTargetMesh)
2869 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2870 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2873 switch ( theMirrorType ) {
2874 case SMESH::SMESH_MeshEditor::POINT:
2875 aTrsf.SetMirror( P );
2877 case SMESH::SMESH_MeshEditor::AXIS:
2878 aTrsf.SetMirror( gp_Ax1( P, V ));
2881 aTrsf.SetMirror( gp_Ax2( P, V ));
2884 ::SMESH_MeshEditor anEditor( myMesh );
2885 ::SMESH_MeshEditor::PGroupIDs groupIds =
2886 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2889 storeResult(anEditor);
2892 myMesh->GetMeshDS()->Modified();
2893 myMesh->SetIsModified( true );
2896 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2899 //=======================================================================
2902 //=======================================================================
2904 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2905 const SMESH::AxisStruct & theAxis,
2906 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2907 CORBA::Boolean theCopy)
2909 if ( !myPreviewMode ) {
2910 TPythonDump() << this << ".Mirror( "
2911 << theIDsOfElements << ", "
2913 << mirrorTypeName(theMirrorType) << ", "
2916 if ( theIDsOfElements.length() > 0 )
2918 TIDSortedElemSet elements;
2919 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2920 mirror(elements, theAxis, theMirrorType, theCopy, false);
2925 //=======================================================================
2926 //function : MirrorObject
2928 //=======================================================================
2930 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2931 const SMESH::AxisStruct & theAxis,
2932 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2933 CORBA::Boolean theCopy)
2935 if ( !myPreviewMode ) {
2936 TPythonDump() << this << ".MirrorObject( "
2937 << theObject << ", "
2939 << mirrorTypeName(theMirrorType) << ", "
2942 TIDSortedElemSet elements;
2943 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2944 mirror(elements, theAxis, theMirrorType, theCopy, false);
2947 //=======================================================================
2948 //function : MirrorMakeGroups
2950 //=======================================================================
2952 SMESH::ListOfGroups*
2953 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2954 const SMESH::AxisStruct& theMirror,
2955 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2957 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2959 SMESH::ListOfGroups * aGroups = 0;
2960 if ( theIDsOfElements.length() > 0 )
2962 TIDSortedElemSet elements;
2963 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2964 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2966 if (!myPreviewMode) {
2967 DumpGroupsList(aPythonDump, aGroups);
2968 aPythonDump << this << ".MirrorMakeGroups( "
2969 << theIDsOfElements << ", "
2970 << theMirror << ", "
2971 << mirrorTypeName(theMirrorType) << " )";
2976 //=======================================================================
2977 //function : MirrorObjectMakeGroups
2979 //=======================================================================
2981 SMESH::ListOfGroups*
2982 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2983 const SMESH::AxisStruct& theMirror,
2984 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2986 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2988 SMESH::ListOfGroups * aGroups = 0;
2989 TIDSortedElemSet elements;
2990 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2991 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2995 DumpGroupsList(aPythonDump,aGroups);
2996 aPythonDump << this << ".MirrorObjectMakeGroups( "
2997 << theObject << ", "
2998 << theMirror << ", "
2999 << mirrorTypeName(theMirrorType) << " )";
3004 //=======================================================================
3005 //function : MirrorMakeMesh
3007 //=======================================================================
3009 SMESH::SMESH_Mesh_ptr
3010 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
3011 const SMESH::AxisStruct& theMirror,
3012 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3013 CORBA::Boolean theCopyGroups,
3014 const char* theMeshName)
3016 SMESH_Mesh_i* mesh_i;
3017 SMESH::SMESH_Mesh_var mesh;
3018 { // open new scope to dump "MakeMesh" command
3019 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3021 TPythonDump pydump; // to prevent dump at mesh creation
3023 mesh = makeMesh( theMeshName );
3024 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3025 if (mesh_i && theIDsOfElements.length() > 0 )
3027 TIDSortedElemSet elements;
3028 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3029 mirror(elements, theMirror, theMirrorType,
3030 false, theCopyGroups, & mesh_i->GetImpl());
3031 mesh_i->CreateGroupServants();
3034 if (!myPreviewMode) {
3035 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
3036 << theIDsOfElements << ", "
3037 << theMirror << ", "
3038 << mirrorTypeName(theMirrorType) << ", "
3039 << theCopyGroups << ", '"
3040 << theMeshName << "' )";
3045 if (!myPreviewMode && mesh_i)
3046 mesh_i->GetGroups();
3048 return mesh._retn();
3051 //=======================================================================
3052 //function : MirrorObjectMakeMesh
3054 //=======================================================================
3056 SMESH::SMESH_Mesh_ptr
3057 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3058 const SMESH::AxisStruct& theMirror,
3059 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3060 CORBA::Boolean theCopyGroups,
3061 const char* theMeshName)
3063 SMESH_Mesh_i* mesh_i;
3064 SMESH::SMESH_Mesh_var mesh;
3065 { // open new scope to dump "MakeMesh" command
3066 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3068 TPythonDump pydump; // to prevent dump at mesh creation
3070 mesh = makeMesh( theMeshName );
3071 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3072 TIDSortedElemSet elements;
3074 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3076 mirror(elements, theMirror, theMirrorType,
3077 false, theCopyGroups, & mesh_i->GetImpl());
3078 mesh_i->CreateGroupServants();
3080 if (!myPreviewMode) {
3081 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
3082 << theObject << ", "
3083 << theMirror << ", "
3084 << mirrorTypeName(theMirrorType) << ", "
3085 << theCopyGroups << ", '"
3086 << theMeshName << "' )";
3091 if (!myPreviewMode && mesh_i)
3092 mesh_i->GetGroups();
3094 return mesh._retn();
3097 //=======================================================================
3098 //function : translate
3100 //=======================================================================
3102 SMESH::ListOfGroups*
3103 SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements,
3104 const SMESH::DirStruct & theVector,
3105 CORBA::Boolean theCopy,
3106 const bool theMakeGroups,
3107 ::SMESH_Mesh* theTargetMesh)
3112 const SMESH::PointStruct * P = &theVector.PS;
3113 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
3115 ::SMESH_MeshEditor anEditor( myMesh );
3116 ::SMESH_MeshEditor::PGroupIDs groupIds =
3117 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3120 storeResult(anEditor);
3123 myMesh->GetMeshDS()->Modified();
3124 myMesh->SetIsModified( true );
3127 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3130 //=======================================================================
3131 //function : Translate
3133 //=======================================================================
3135 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
3136 const SMESH::DirStruct & theVector,
3137 CORBA::Boolean theCopy)
3139 if (!myPreviewMode) {
3140 TPythonDump() << this << ".Translate( "
3141 << theIDsOfElements << ", "
3142 << theVector << ", "
3145 if (theIDsOfElements.length()) {
3146 TIDSortedElemSet elements;
3147 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3148 translate(elements, theVector, theCopy, false);
3152 //=======================================================================
3153 //function : TranslateObject
3155 //=======================================================================
3157 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
3158 const SMESH::DirStruct & theVector,
3159 CORBA::Boolean theCopy)
3161 if (!myPreviewMode) {
3162 TPythonDump() << this << ".TranslateObject( "
3163 << theObject << ", "
3164 << theVector << ", "
3167 TIDSortedElemSet elements;
3168 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3169 translate(elements, theVector, theCopy, false);
3172 //=======================================================================
3173 //function : TranslateMakeGroups
3175 //=======================================================================
3177 SMESH::ListOfGroups*
3178 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
3179 const SMESH::DirStruct& theVector)
3181 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3183 SMESH::ListOfGroups * aGroups = 0;
3184 if (theIDsOfElements.length()) {
3185 TIDSortedElemSet elements;
3186 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3187 aGroups = translate(elements,theVector,true,true);
3189 if (!myPreviewMode) {
3190 DumpGroupsList(aPythonDump, aGroups);
3191 aPythonDump << this << ".TranslateMakeGroups( "
3192 << theIDsOfElements << ", "
3193 << theVector << " )";
3198 //=======================================================================
3199 //function : TranslateObjectMakeGroups
3201 //=======================================================================
3203 SMESH::ListOfGroups*
3204 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3205 const SMESH::DirStruct& theVector)
3207 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3209 SMESH::ListOfGroups * aGroups = 0;
3210 TIDSortedElemSet elements;
3211 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3212 aGroups = translate(elements, theVector, true, true);
3214 if (!myPreviewMode) {
3215 DumpGroupsList(aPythonDump, aGroups);
3216 aPythonDump << this << ".TranslateObjectMakeGroups( "
3217 << theObject << ", "
3218 << theVector << " )";
3223 //=======================================================================
3224 //function : TranslateMakeMesh
3226 //=======================================================================
3228 SMESH::SMESH_Mesh_ptr
3229 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3230 const SMESH::DirStruct& theVector,
3231 CORBA::Boolean theCopyGroups,
3232 const char* theMeshName)
3234 SMESH_Mesh_i* mesh_i;
3235 SMESH::SMESH_Mesh_var mesh;
3237 { // open new scope to dump "MakeMesh" command
3238 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3240 TPythonDump pydump; // to prevent dump at mesh creation
3242 mesh = makeMesh( theMeshName );
3243 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3245 if ( mesh_i && theIDsOfElements.length() )
3247 TIDSortedElemSet elements;
3248 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3249 translate(elements, theVector, false, theCopyGroups, & mesh_i->GetImpl());
3250 mesh_i->CreateGroupServants();
3253 if ( !myPreviewMode ) {
3254 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3255 << theIDsOfElements << ", "
3256 << theVector << ", "
3257 << theCopyGroups << ", '"
3258 << theMeshName << "' )";
3263 if (!myPreviewMode && mesh_i)
3264 mesh_i->GetGroups();
3266 return mesh._retn();
3269 //=======================================================================
3270 //function : TranslateObjectMakeMesh
3272 //=======================================================================
3274 SMESH::SMESH_Mesh_ptr
3275 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3276 const SMESH::DirStruct& theVector,
3277 CORBA::Boolean theCopyGroups,
3278 const char* theMeshName)
3280 SMESH_Mesh_i* mesh_i;
3281 SMESH::SMESH_Mesh_var mesh;
3282 { // open new scope to dump "MakeMesh" command
3283 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3285 TPythonDump pydump; // to prevent dump at mesh creation
3286 mesh = makeMesh( theMeshName );
3287 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3289 TIDSortedElemSet elements;
3291 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3293 translate(elements, theVector,false, theCopyGroups, & mesh_i->GetImpl());
3294 mesh_i->CreateGroupServants();
3296 if ( !myPreviewMode ) {
3297 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3298 << theObject << ", "
3299 << theVector << ", "
3300 << theCopyGroups << ", '"
3301 << theMeshName << "' )";
3306 if (!myPreviewMode && mesh_i)
3307 mesh_i->GetGroups();
3309 return mesh._retn();
3312 //=======================================================================
3315 //=======================================================================
3317 SMESH::ListOfGroups*
3318 SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements,
3319 const SMESH::AxisStruct & theAxis,
3320 CORBA::Double theAngle,
3321 CORBA::Boolean theCopy,
3322 const bool theMakeGroups,
3323 ::SMESH_Mesh* theTargetMesh)
3327 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3328 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3331 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3333 ::SMESH_MeshEditor anEditor( myMesh );
3334 ::SMESH_MeshEditor::PGroupIDs groupIds =
3335 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3338 storeResult(anEditor);
3341 myMesh->GetMeshDS()->Modified();
3342 myMesh->SetIsModified( true );
3345 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3348 //=======================================================================
3351 //=======================================================================
3353 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3354 const SMESH::AxisStruct & theAxis,
3355 CORBA::Double theAngle,
3356 CORBA::Boolean theCopy)
3358 if (!myPreviewMode) {
3359 TPythonDump() << this << ".Rotate( "
3360 << theIDsOfElements << ", "
3365 if (theIDsOfElements.length() > 0)
3367 TIDSortedElemSet elements;
3368 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3369 rotate(elements,theAxis,theAngle,theCopy,false);
3373 //=======================================================================
3374 //function : RotateObject
3376 //=======================================================================
3378 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3379 const SMESH::AxisStruct & theAxis,
3380 CORBA::Double theAngle,
3381 CORBA::Boolean theCopy)
3383 if ( !myPreviewMode ) {
3384 TPythonDump() << this << ".RotateObject( "
3385 << theObject << ", "
3390 TIDSortedElemSet elements;
3391 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3392 rotate(elements,theAxis,theAngle,theCopy,false);
3395 //=======================================================================
3396 //function : RotateMakeGroups
3398 //=======================================================================
3400 SMESH::ListOfGroups*
3401 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3402 const SMESH::AxisStruct& theAxis,
3403 CORBA::Double theAngle)
3405 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3407 SMESH::ListOfGroups * aGroups = 0;
3408 if (theIDsOfElements.length() > 0)
3410 TIDSortedElemSet elements;
3411 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3412 aGroups = rotate(elements,theAxis,theAngle,true,true);
3414 if (!myPreviewMode) {
3415 DumpGroupsList(aPythonDump, aGroups);
3416 aPythonDump << this << ".RotateMakeGroups( "
3417 << theIDsOfElements << ", "
3419 << theAngle << " )";
3424 //=======================================================================
3425 //function : RotateObjectMakeGroups
3427 //=======================================================================
3429 SMESH::ListOfGroups*
3430 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3431 const SMESH::AxisStruct& theAxis,
3432 CORBA::Double theAngle)
3434 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3436 SMESH::ListOfGroups * aGroups = 0;
3437 TIDSortedElemSet elements;
3438 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3439 aGroups = rotate(elements, theAxis, theAngle, true, true);
3441 if (!myPreviewMode) {
3442 DumpGroupsList(aPythonDump, aGroups);
3443 aPythonDump << this << ".RotateObjectMakeGroups( "
3444 << theObject << ", "
3446 << theAngle << " )";
3451 //=======================================================================
3452 //function : RotateMakeMesh
3454 //=======================================================================
3456 SMESH::SMESH_Mesh_ptr
3457 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3458 const SMESH::AxisStruct& theAxis,
3459 CORBA::Double theAngleInRadians,
3460 CORBA::Boolean theCopyGroups,
3461 const char* theMeshName)
3463 SMESH::SMESH_Mesh_var mesh;
3464 SMESH_Mesh_i* mesh_i;
3466 { // open new scope to dump "MakeMesh" command
3467 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3469 TPythonDump pydump; // to prevent dump at mesh creation
3471 mesh = makeMesh( theMeshName );
3472 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3474 if ( mesh_i && theIDsOfElements.length() > 0 )
3476 TIDSortedElemSet elements;
3477 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3478 rotate(elements, theAxis, theAngleInRadians,
3479 false, theCopyGroups, & mesh_i->GetImpl());
3480 mesh_i->CreateGroupServants();
3482 if ( !myPreviewMode ) {
3483 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3484 << theIDsOfElements << ", "
3486 << theAngleInRadians << ", "
3487 << theCopyGroups << ", '"
3488 << theMeshName << "' )";
3493 if (!myPreviewMode && mesh_i && theIDsOfElements.length() > 0 )
3494 mesh_i->GetGroups();
3496 return mesh._retn();
3499 //=======================================================================
3500 //function : RotateObjectMakeMesh
3502 //=======================================================================
3504 SMESH::SMESH_Mesh_ptr
3505 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3506 const SMESH::AxisStruct& theAxis,
3507 CORBA::Double theAngleInRadians,
3508 CORBA::Boolean theCopyGroups,
3509 const char* theMeshName)
3511 SMESH::SMESH_Mesh_var mesh;
3512 SMESH_Mesh_i* mesh_i;
3514 {// open new scope to dump "MakeMesh" command
3515 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3517 TPythonDump pydump; // to prevent dump at mesh creation
3518 mesh = makeMesh( theMeshName );
3519 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3521 TIDSortedElemSet elements;
3523 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3525 rotate(elements, theAxis, theAngleInRadians,
3526 false, theCopyGroups, & mesh_i->GetImpl());
3527 mesh_i->CreateGroupServants();
3529 if ( !myPreviewMode ) {
3530 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3531 << theObject << ", "
3533 << theAngleInRadians << ", "
3534 << theCopyGroups << ", '"
3535 << theMeshName << "' )";
3540 if (!myPreviewMode && mesh_i)
3541 mesh_i->GetGroups();
3543 return mesh._retn();
3546 //=======================================================================
3549 //=======================================================================
3551 SMESH::ListOfGroups*
3552 SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject,
3553 const SMESH::PointStruct& thePoint,
3554 const SMESH::double_array& theScaleFact,
3555 CORBA::Boolean theCopy,
3556 const bool theMakeGroups,
3557 ::SMESH_Mesh* theTargetMesh)
3560 if ( theScaleFact.length() < 1 )
3561 THROW_SALOME_CORBA_EXCEPTION("Scale factor not given", SALOME::BAD_PARAM);
3562 if ( theScaleFact.length() == 2 )
3563 THROW_SALOME_CORBA_EXCEPTION("Invalid nb of scale factors : 2", SALOME::BAD_PARAM);
3565 TIDSortedElemSet elements;
3566 if ( !idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/true))
3569 vector<double> S(3);
3570 S[0] = theScaleFact[0];
3571 S[1] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1];
3572 S[2] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2];
3573 double tol = std::numeric_limits<double>::max();
3575 aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]),
3576 0, S[1], 0, thePoint.y * (1-S[1]),
3577 0, 0, S[2], thePoint.z * (1-S[2]), tol, tol);
3579 ::SMESH_MeshEditor anEditor( myMesh );
3580 ::SMESH_MeshEditor::PGroupIDs groupIds =
3581 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3584 storeResult(anEditor);
3587 myMesh->GetMeshDS()->Modified();
3588 myMesh->SetIsModified( true );
3590 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3593 //=======================================================================
3596 //=======================================================================
3598 void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr theObject,
3599 const SMESH::PointStruct& thePoint,
3600 const SMESH::double_array& theScaleFact,
3601 CORBA::Boolean theCopy)
3603 if ( !myPreviewMode ) {
3604 TPythonDump() << this << ".Scale( "
3605 << theObject << ", "
3606 << "SMESH.PointStruct( " << thePoint.x << ", "
3607 << thePoint.y << ", " << thePoint.z << " ) ,"
3608 << theScaleFact << ", "
3611 scale(theObject, thePoint, theScaleFact, theCopy, false);
3615 //=======================================================================
3616 //function : ScaleMakeGroups
3618 //=======================================================================
3620 SMESH::ListOfGroups*
3621 SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3622 const SMESH::PointStruct& thePoint,
3623 const SMESH::double_array& theScaleFact)
3625 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3627 SMESH::ListOfGroups * aGroups = scale(theObject, thePoint, theScaleFact, true, true);
3628 if (!myPreviewMode) {
3629 DumpGroupsList(aPythonDump, aGroups);
3630 aPythonDump << this << ".Scale("
3632 << "SMESH.PointStruct(" <<thePoint.x << ","
3633 << thePoint.y << "," << thePoint.z << "),"
3634 << theScaleFact << ",True,True)";
3640 //=======================================================================
3641 //function : ScaleMakeMesh
3643 //=======================================================================
3645 SMESH::SMESH_Mesh_ptr
3646 SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3647 const SMESH::PointStruct& thePoint,
3648 const SMESH::double_array& theScaleFact,
3649 CORBA::Boolean theCopyGroups,
3650 const char* theMeshName)
3652 SMESH_Mesh_i* mesh_i;
3653 SMESH::SMESH_Mesh_var mesh;
3654 { // open new scope to dump "MakeMesh" command
3655 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3657 TPythonDump pydump; // to prevent dump at mesh creation
3658 mesh = makeMesh( theMeshName );
3659 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3663 scale(theObject, thePoint, theScaleFact,false, theCopyGroups, & mesh_i->GetImpl());
3664 mesh_i->CreateGroupServants();
3666 if ( !myPreviewMode )
3667 pydump << mesh << " = " << this << ".ScaleMakeMesh( "
3668 << theObject << ", "
3669 << "SMESH.PointStruct( " << thePoint.x << ", "
3670 << thePoint.y << ", " << thePoint.z << " ) ,"
3671 << theScaleFact << ", "
3672 << theCopyGroups << ", '"
3673 << theMeshName << "' )";
3677 if (!myPreviewMode && mesh_i)
3678 mesh_i->GetGroups();
3680 return mesh._retn();
3684 //=======================================================================
3685 //function : FindCoincidentNodes
3687 //=======================================================================
3689 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3690 SMESH::array_of_long_array_out GroupsOfNodes)
3694 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3695 ::SMESH_MeshEditor anEditor( myMesh );
3696 TIDSortedNodeSet nodes; // no input nodes
3697 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3699 GroupsOfNodes = new SMESH::array_of_long_array;
3700 GroupsOfNodes->length( aListOfListOfNodes.size() );
3701 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3702 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3703 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3704 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3705 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3706 aGroup.length( aListOfNodes.size() );
3707 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3708 aGroup[ j ] = (*lIt)->GetID();
3710 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3711 << Tolerance << " )";
3714 //=======================================================================
3715 //function : FindCoincidentNodesOnPart
3717 //=======================================================================
3718 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3719 CORBA::Double Tolerance,
3720 SMESH::array_of_long_array_out GroupsOfNodes)
3724 TIDSortedNodeSet nodes;
3725 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3727 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3728 ::SMESH_MeshEditor anEditor( myMesh );
3730 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3732 GroupsOfNodes = new SMESH::array_of_long_array;
3733 GroupsOfNodes->length( aListOfListOfNodes.size() );
3734 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3735 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3737 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3738 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3739 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3740 aGroup.length( aListOfNodes.size() );
3741 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3742 aGroup[ j ] = (*lIt)->GetID();
3744 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3746 << Tolerance << " )";
3749 //================================================================================
3751 * \brief Finds nodes coinsident with Tolerance within Object excluding nodes within
3752 * ExceptSubMeshOrGroups
3754 //================================================================================
3756 void SMESH_MeshEditor_i::
3757 FindCoincidentNodesOnPartBut(SMESH::SMESH_IDSource_ptr theObject,
3758 CORBA::Double theTolerance,
3759 SMESH::array_of_long_array_out theGroupsOfNodes,
3760 const SMESH::ListOfIDSources& theExceptSubMeshOrGroups)
3764 TIDSortedNodeSet nodes;
3765 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3767 for ( int i = 0; i < theExceptSubMeshOrGroups.length(); ++i )
3769 TIDSortedNodeSet exceptNodes;
3770 idSourceToNodeSet( theExceptSubMeshOrGroups[i], GetMeshDS(), exceptNodes );
3771 TIDSortedNodeSet::iterator avoidNode = exceptNodes.begin();
3772 for ( ; avoidNode != exceptNodes.end(); ++avoidNode)
3773 nodes.erase( *avoidNode );
3775 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3776 ::SMESH_MeshEditor anEditor( myMesh );
3778 anEditor.FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes );
3780 theGroupsOfNodes = new SMESH::array_of_long_array;
3781 theGroupsOfNodes->length( aListOfListOfNodes.size() );
3782 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3783 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3785 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3786 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3787 SMESH::long_array& aGroup = (*theGroupsOfNodes)[ i ];
3788 aGroup.length( aListOfNodes.size() );
3789 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3790 aGroup[ j ] = (*lIt)->GetID();
3792 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPartBut( "
3794 << theTolerance << ", "
3795 << theExceptSubMeshOrGroups << " )";
3798 //=======================================================================
3799 //function : MergeNodes
3801 //=======================================================================
3803 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3807 SMESHDS_Mesh* aMesh = GetMeshDS();
3809 TPythonDump aTPythonDump;
3810 aTPythonDump << this << ".MergeNodes([";
3811 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3812 for (int i = 0; i < GroupsOfNodes.length(); i++)
3814 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3815 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3816 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3817 for ( int j = 0; j < aNodeGroup.length(); j++ )
3819 CORBA::Long index = aNodeGroup[ j ];
3820 const SMDS_MeshNode * node = aMesh->FindNode(index);
3822 aListOfNodes.push_back( node );
3824 if ( aListOfNodes.size() < 2 )
3825 aListOfListOfNodes.pop_back();
3827 if ( i > 0 ) aTPythonDump << ", ";
3828 aTPythonDump << aNodeGroup;
3830 ::SMESH_MeshEditor anEditor( myMesh );
3831 anEditor.MergeNodes( aListOfListOfNodes );
3833 aTPythonDump << "])";
3834 myMesh->GetMeshDS()->Modified();
3835 myMesh->SetIsModified( true );
3838 //=======================================================================
3839 //function : FindEqualElements
3841 //=======================================================================
3842 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3843 SMESH::array_of_long_array_out GroupsOfElementsID)
3847 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theObject);
3848 if ( !(!group->_is_nil() && group->GetType() == SMESH::NODE) )
3850 typedef list<int> TListOfIDs;
3851 set<const SMDS_MeshElement*> elems;
3852 SMESH::long_array_var aElementsId = theObject->GetIDs();
3853 SMESHDS_Mesh* aMesh = GetMeshDS();
3855 for(int i = 0; i < aElementsId->length(); i++) {
3856 CORBA::Long anID = aElementsId[i];
3857 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3863 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3864 ::SMESH_MeshEditor anEditor( myMesh );
3865 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3867 GroupsOfElementsID = new SMESH::array_of_long_array;
3868 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3870 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3871 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3872 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3873 TListOfIDs& listOfIDs = *arraysIt;
3874 aGroup.length( listOfIDs.size() );
3875 TListOfIDs::iterator idIt = listOfIDs.begin();
3876 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3877 aGroup[ k ] = *idIt;
3881 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3886 //=======================================================================
3887 //function : MergeElements
3889 //=======================================================================
3891 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3895 TPythonDump aTPythonDump;
3896 aTPythonDump << this << ".MergeElements( [";
3898 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3900 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3901 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3902 aListOfListOfElementsID.push_back( list< int >() );
3903 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3904 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3905 CORBA::Long id = anElemsIDGroup[ j ];
3906 aListOfElemsID.push_back( id );
3908 if ( aListOfElemsID.size() < 2 )
3909 aListOfListOfElementsID.pop_back();
3910 if ( i > 0 ) aTPythonDump << ", ";
3911 aTPythonDump << anElemsIDGroup;
3914 ::SMESH_MeshEditor anEditor( myMesh );
3915 anEditor.MergeElements(aListOfListOfElementsID);
3916 myMesh->GetMeshDS()->Modified();
3917 myMesh->SetIsModified( true );
3919 aTPythonDump << "] )";
3922 //=======================================================================
3923 //function : MergeEqualElements
3925 //=======================================================================
3927 void SMESH_MeshEditor_i::MergeEqualElements()
3931 ::SMESH_MeshEditor anEditor( myMesh );
3932 anEditor.MergeEqualElements();
3934 TPythonDump() << this << ".MergeEqualElements()";
3937 //=============================================================================
3939 * Move the node to a given point
3941 //=============================================================================
3943 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
3948 initData(/*deleteSearchers=*/false);
3950 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
3954 if ( theNodeSearcher )
3955 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3957 if ( myPreviewMode ) // make preview data
3959 // in a preview mesh, make edges linked to a node
3960 TPreviewMesh tmpMesh;
3961 TIDSortedElemSet linkedNodes;
3962 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3963 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3964 SMDS_MeshNode *nodeCpy1 = tmpMesh.Copy(node);
3965 for ( ; nIt != linkedNodes.end(); ++nIt )
3967 SMDS_MeshNode *nodeCpy2 = tmpMesh.Copy ( cast2Node( *nIt ));
3968 tmpMesh.GetMeshDS()->AddEdge(nodeCpy1, nodeCpy2);
3972 tmpMesh.GetMeshDS()->MoveNode(nodeCpy1, x, y, z);
3973 // fill preview data
3974 ::SMESH_MeshEditor anEditor( & tmpMesh );
3975 storeResult( anEditor );
3977 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3978 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3980 GetMeshDS()->MoveNode(node, x, y, z);
3982 if ( !myPreviewMode )
3984 // Update Python script
3985 TPythonDump() << "isDone = " << this << ".MoveNode( "
3986 << NodeID << ", " << x << ", " << y << ", " << z << " )";
3987 myMesh->GetMeshDS()->Modified();
3988 myMesh->SetIsModified( true );
3994 //================================================================================
3996 * \brief Return ID of node closest to a given point
3998 //================================================================================
4000 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
4004 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4006 if ( !theNodeSearcher ) {
4007 ::SMESH_MeshEditor anEditor( myMesh );
4008 theNodeSearcher = anEditor.GetNodeSearcher();
4011 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
4012 return node->GetID();
4017 //================================================================================
4019 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
4020 * move the node closest to the point to point's location and return ID of the node
4022 //================================================================================
4024 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
4027 CORBA::Long theNodeID)
4029 // We keep theNodeSearcher until any mesh modification:
4030 // 1) initData() deletes theNodeSearcher at any edition,
4031 // 2) TSearchersDeleter - at any mesh compute event and mesh change
4033 initData(/*deleteSearchers=*/false);
4035 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4037 int nodeID = theNodeID;
4038 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
4039 if ( !node ) // preview moving node
4041 if ( !theNodeSearcher ) {
4042 ::SMESH_MeshEditor anEditor( myMesh );
4043 theNodeSearcher = anEditor.GetNodeSearcher();
4046 node = theNodeSearcher->FindClosestTo( p );
4049 nodeID = node->GetID();
4050 if ( myPreviewMode ) // make preview data
4052 // in a preview mesh, make edges linked to a node
4053 TPreviewMesh tmpMesh;
4054 TIDSortedElemSet linkedNodes;
4055 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
4056 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
4057 for ( ; nIt != linkedNodes.end(); ++nIt )
4059 SMDS_LinearEdge edge( node, cast2Node( *nIt ));
4060 tmpMesh.Copy( &edge );
4063 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
4065 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
4066 // fill preview data
4067 ::SMESH_MeshEditor anEditor( & tmpMesh );
4068 storeResult( anEditor );
4070 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
4072 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
4076 GetMeshDS()->MoveNode(node, x, y, z);
4080 if ( !myPreviewMode )
4082 TPythonDump() << "nodeID = " << this
4083 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
4084 << ", " << nodeID << " )";
4086 myMesh->GetMeshDS()->Modified();
4087 myMesh->SetIsModified( true );
4093 //=======================================================================
4095 * Return elements of given type where the given point is IN or ON.
4097 * 'ALL' type means elements of any type excluding nodes
4099 //=======================================================================
4101 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
4104 SMESH::ElementType type)
4106 SMESH::long_array_var res = new SMESH::long_array;
4107 vector< const SMDS_MeshElement* > foundElems;
4109 theSearchersDeleter.Set( myMesh );
4110 if ( !theElementSearcher ) {
4111 ::SMESH_MeshEditor anEditor( myMesh );
4112 theElementSearcher = anEditor.GetElementSearcher();
4114 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
4115 SMDSAbs_ElementType( type ),
4117 res->length( foundElems.size() );
4118 for ( int i = 0; i < foundElems.size(); ++i )
4119 res[i] = foundElems[i]->GetID();
4121 if ( !myPreviewMode ) // call from tui
4122 TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
4131 //=======================================================================
4132 //function : GetPointState
4133 //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
4134 // TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
4135 //=======================================================================
4137 CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
4141 theSearchersDeleter.Set( myMesh );
4142 if ( !theElementSearcher ) {
4143 ::SMESH_MeshEditor anEditor( myMesh );
4144 theElementSearcher = anEditor.GetElementSearcher();
4146 return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
4149 //=======================================================================
4150 //function : convError
4152 //=======================================================================
4154 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
4156 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
4160 RETCASE( SEW_BORDER1_NOT_FOUND );
4161 RETCASE( SEW_BORDER2_NOT_FOUND );
4162 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
4163 RETCASE( SEW_BAD_SIDE_NODES );
4164 RETCASE( SEW_VOLUMES_TO_SPLIT );
4165 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
4166 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
4167 RETCASE( SEW_BAD_SIDE1_NODES );
4168 RETCASE( SEW_BAD_SIDE2_NODES );
4170 return SMESH::SMESH_MeshEditor::SEW_OK;
4173 //=======================================================================
4174 //function : SewFreeBorders
4176 //=======================================================================
4178 SMESH::SMESH_MeshEditor::Sew_Error
4179 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
4180 CORBA::Long SecondNodeID1,
4181 CORBA::Long LastNodeID1,
4182 CORBA::Long FirstNodeID2,
4183 CORBA::Long SecondNodeID2,
4184 CORBA::Long LastNodeID2,
4185 CORBA::Boolean CreatePolygons,
4186 CORBA::Boolean CreatePolyedrs)
4190 SMESHDS_Mesh* aMesh = GetMeshDS();
4192 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4193 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4194 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4195 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4196 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4197 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
4199 if (!aBorderFirstNode ||
4200 !aBorderSecondNode||
4202 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4203 if (!aSide2FirstNode ||
4204 !aSide2SecondNode ||
4206 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4208 TPythonDump() << "error = " << this << ".SewFreeBorders( "
4209 << FirstNodeID1 << ", "
4210 << SecondNodeID1 << ", "
4211 << LastNodeID1 << ", "
4212 << FirstNodeID2 << ", "
4213 << SecondNodeID2 << ", "
4214 << LastNodeID2 << ", "
4215 << CreatePolygons<< ", "
4216 << CreatePolyedrs<< " )";
4218 ::SMESH_MeshEditor anEditor( myMesh );
4219 SMESH::SMESH_MeshEditor::Sew_Error error =
4220 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4230 storeResult(anEditor);
4232 myMesh->GetMeshDS()->Modified();
4233 myMesh->SetIsModified( true );
4239 //=======================================================================
4240 //function : SewConformFreeBorders
4242 //=======================================================================
4244 SMESH::SMESH_MeshEditor::Sew_Error
4245 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
4246 CORBA::Long SecondNodeID1,
4247 CORBA::Long LastNodeID1,
4248 CORBA::Long FirstNodeID2,
4249 CORBA::Long SecondNodeID2)
4253 SMESHDS_Mesh* aMesh = GetMeshDS();
4255 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4256 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4257 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4258 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4259 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4260 const SMDS_MeshNode* aSide2ThirdNode = 0;
4262 if (!aBorderFirstNode ||
4263 !aBorderSecondNode||
4265 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4266 if (!aSide2FirstNode ||
4268 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4270 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
4271 << FirstNodeID1 << ", "
4272 << SecondNodeID1 << ", "
4273 << LastNodeID1 << ", "
4274 << FirstNodeID2 << ", "
4275 << SecondNodeID2 << " )";
4277 ::SMESH_MeshEditor anEditor( myMesh );
4278 SMESH::SMESH_MeshEditor::Sew_Error error =
4279 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4288 storeResult(anEditor);
4290 myMesh->GetMeshDS()->Modified();
4291 myMesh->SetIsModified( true );
4297 //=======================================================================
4298 //function : SewBorderToSide
4300 //=======================================================================
4302 SMESH::SMESH_MeshEditor::Sew_Error
4303 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
4304 CORBA::Long SecondNodeIDOnFreeBorder,
4305 CORBA::Long LastNodeIDOnFreeBorder,
4306 CORBA::Long FirstNodeIDOnSide,
4307 CORBA::Long LastNodeIDOnSide,
4308 CORBA::Boolean CreatePolygons,
4309 CORBA::Boolean CreatePolyedrs)
4313 SMESHDS_Mesh* aMesh = GetMeshDS();
4315 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
4316 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
4317 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
4318 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
4319 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
4320 const SMDS_MeshNode* aSide2ThirdNode = 0;
4322 if (!aBorderFirstNode ||
4323 !aBorderSecondNode||
4325 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4326 if (!aSide2FirstNode ||
4328 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
4330 TPythonDump() << "error = " << this << ".SewBorderToSide( "
4331 << FirstNodeIDOnFreeBorder << ", "
4332 << SecondNodeIDOnFreeBorder << ", "
4333 << LastNodeIDOnFreeBorder << ", "
4334 << FirstNodeIDOnSide << ", "
4335 << LastNodeIDOnSide << ", "
4336 << CreatePolygons << ", "
4337 << CreatePolyedrs << ") ";
4339 ::SMESH_MeshEditor anEditor( myMesh );
4340 SMESH::SMESH_MeshEditor::Sew_Error error =
4341 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4351 storeResult(anEditor);
4353 myMesh->GetMeshDS()->Modified();
4354 myMesh->SetIsModified( true );
4360 //=======================================================================
4361 //function : SewSideElements
4363 //=======================================================================
4365 SMESH::SMESH_MeshEditor::Sew_Error
4366 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
4367 const SMESH::long_array& IDsOfSide2Elements,
4368 CORBA::Long NodeID1OfSide1ToMerge,
4369 CORBA::Long NodeID1OfSide2ToMerge,
4370 CORBA::Long NodeID2OfSide1ToMerge,
4371 CORBA::Long NodeID2OfSide2ToMerge)
4375 SMESHDS_Mesh* aMesh = GetMeshDS();
4377 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
4378 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
4379 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
4380 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
4382 if (!aFirstNode1ToMerge ||
4383 !aFirstNode2ToMerge )
4384 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
4385 if (!aSecondNode1ToMerge||
4386 !aSecondNode2ToMerge)
4387 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
4389 TIDSortedElemSet aSide1Elems, aSide2Elems;
4390 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
4391 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
4393 TPythonDump() << "error = " << this << ".SewSideElements( "
4394 << IDsOfSide1Elements << ", "
4395 << IDsOfSide2Elements << ", "
4396 << NodeID1OfSide1ToMerge << ", "
4397 << NodeID1OfSide2ToMerge << ", "
4398 << NodeID2OfSide1ToMerge << ", "
4399 << NodeID2OfSide2ToMerge << ")";
4401 ::SMESH_MeshEditor anEditor( myMesh );
4402 SMESH::SMESH_MeshEditor::Sew_Error error =
4403 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
4406 aSecondNode1ToMerge,
4407 aSecondNode2ToMerge));
4409 storeResult(anEditor);
4411 myMesh->GetMeshDS()->Modified();
4412 myMesh->SetIsModified( true );
4417 //================================================================================
4419 * \brief Set new nodes for given element
4420 * \param ide - element id
4421 * \param newIDs - new node ids
4422 * \retval CORBA::Boolean - true if result is OK
4424 //================================================================================
4426 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
4427 const SMESH::long_array& newIDs)
4431 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
4432 if(!elem) return false;
4434 int nbn = newIDs.length();
4436 vector<const SMDS_MeshNode*> aNodes(nbn);
4439 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
4442 aNodes[nbn1] = aNode;
4445 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
4446 << ide << ", " << newIDs << " )";
4448 MESSAGE("ChangeElementNodes");
4449 bool res = GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
4451 myMesh->GetMeshDS()->Modified();
4453 myMesh->SetIsModified( true );
4458 //================================================================================
4460 * \brief Update myLastCreated* or myPreviewData
4461 * \param anEditor - it contains last modification results
4463 //================================================================================
4465 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
4467 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
4469 list<int> aNodesConnectivity;
4470 typedef map<int, int> TNodesMap;
4473 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
4474 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
4476 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
4477 int nbEdges = aMeshDS->NbEdges();
4478 int nbFaces = aMeshDS->NbFaces();
4479 int nbVolum = aMeshDS->NbVolumes();
4480 switch ( previewType ) {
4481 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
4482 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
4483 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
4486 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
4487 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
4489 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
4491 while ( itMeshElems->more() ) {
4492 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
4493 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
4496 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
4497 while ( itElemNodes->more() ) {
4498 const SMDS_MeshNode* aMeshNode =
4499 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
4500 int aNodeID = aMeshNode->GetID();
4501 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
4502 if ( anIter == nodesMap.end() ) {
4503 // filling the nodes coordinates
4504 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
4505 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
4506 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
4507 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4510 aNodesConnectivity.push_back(anIter->second);
4513 // filling the elements types
4514 SMDSAbs_ElementType aType;
4516 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4517 aType = SMDSAbs_Node;
4521 aType = aMeshElem->GetType();
4522 isPoly = aMeshElem->IsPoly();
4525 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4526 myPreviewData->elementTypes[i].isPoly = isPoly;
4527 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4531 myPreviewData->nodesXYZ.length( j );
4533 // filling the elements connectivities
4534 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4535 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4536 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4537 myPreviewData->elementConnectivities[i] = *aConnIter;
4543 // add new nodes into myLastCreatedNodes
4544 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4545 myLastCreatedNodes->length(aSeq.Length());
4546 for(int i=0; i<aSeq.Length(); i++)
4547 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4550 // add new elements into myLastCreatedElems
4551 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4552 myLastCreatedElems->length(aSeq.Length());
4553 for(int i=0; i<aSeq.Length(); i++)
4554 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4558 //================================================================================
4560 * Return data of mesh edition preview
4562 //================================================================================
4564 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4566 return myPreviewData._retn();
4569 //================================================================================
4571 * \brief Returns list of it's IDs of created nodes
4572 * \retval SMESH::long_array* - list of node ID
4574 //================================================================================
4576 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4578 return myLastCreatedNodes._retn();
4581 //================================================================================
4583 * \brief Returns list of it's IDs of created elements
4584 * \retval SMESH::long_array* - list of elements' ID
4586 //================================================================================
4588 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4590 return myLastCreatedElems._retn();
4593 //=======================================================================
4594 //function : ConvertToQuadratic
4596 //=======================================================================
4598 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4600 ::SMESH_MeshEditor anEditor( myMesh );
4601 anEditor.ConvertToQuadratic(theForce3d);
4602 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4603 myMesh->GetMeshDS()->Modified();
4604 myMesh->SetIsModified( true );
4607 //=======================================================================
4608 //function : ConvertFromQuadratic
4610 //=======================================================================
4612 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4614 ::SMESH_MeshEditor anEditor( myMesh );
4615 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4616 TPythonDump() << this << ".ConvertFromQuadratic()";
4617 myMesh->GetMeshDS()->Modified();
4619 myMesh->SetIsModified( true );
4623 //=======================================================================
4624 //function : makeMesh
4625 //purpose : create a named imported mesh
4626 //=======================================================================
4628 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4630 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4631 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4632 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4633 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4634 gen->SetName( meshSO, theMeshName, "Mesh" );
4635 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4637 return mesh._retn();
4640 //=======================================================================
4641 //function : DumpGroupsList
4643 //=======================================================================
4644 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4645 const SMESH::ListOfGroups * theGroupList)
4647 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4648 if(isDumpGroupList) {
4649 theDumpPython << theGroupList << " = ";
4653 //================================================================================
4655 \brief Generates the unique group name.
4656 \param thePrefix name prefix
4659 //================================================================================
4660 string SMESH_MeshEditor_i::generateGroupName(const string& thePrefix)
4662 SMESH::ListOfGroups_var groups = myMesh_i->GetGroups();
4663 set<string> groupNames;
4665 // Get existing group names
4666 for (int i = 0, nbGroups = groups->length(); i < nbGroups; i++ ) {
4667 SMESH::SMESH_GroupBase_var aGroup = groups[i];
4668 if (CORBA::is_nil(aGroup))
4671 groupNames.insert(aGroup->GetName());
4675 string name = thePrefix;
4678 while (!groupNames.insert(name).second) {
4683 TCollection_AsciiString nbStr(index+1);
4684 name.resize( name.rfind('_')+1 );
4685 name += nbStr.ToCString();
4693 //================================================================================
4695 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4696 \param theNodes - identifiers of nodes to be doubled
4697 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4698 nodes. If list of element identifiers is empty then nodes are doubled but
4699 they not assigned to elements
4700 \return TRUE if operation has been completed successfully, FALSE otherwise
4701 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4703 //================================================================================
4705 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4706 const SMESH::long_array& theModifiedElems )
4710 ::SMESH_MeshEditor aMeshEditor( myMesh );
4711 list< int > aListOfNodes;
4713 for ( i = 0, n = theNodes.length(); i < n; i++ )
4714 aListOfNodes.push_back( theNodes[ i ] );
4716 list< int > aListOfElems;
4717 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4718 aListOfElems.push_back( theModifiedElems[ i ] );
4720 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4722 myMesh->GetMeshDS()->Modified();
4723 storeResult( aMeshEditor) ;
4725 myMesh->SetIsModified( true );
4727 // Update Python script
4728 TPythonDump() << this << ".DoubleNodes( " << theNodes << ", "<< theModifiedElems << " )";
4733 //================================================================================
4735 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4736 This method provided for convenience works as DoubleNodes() described above.
4737 \param theNodeId - identifier of node to be doubled.
4738 \param theModifiedElems - identifiers of elements to be updated.
4739 \return TRUE if operation has been completed successfully, FALSE otherwise
4740 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4742 //================================================================================
4744 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4745 const SMESH::long_array& theModifiedElems )
4747 SMESH::long_array_var aNodes = new SMESH::long_array;
4748 aNodes->length( 1 );
4749 aNodes[ 0 ] = theNodeId;
4751 TPythonDump pyDump; // suppress dump by the next line
4753 CORBA::Boolean done = DoubleNodes( aNodes, theModifiedElems );
4755 pyDump << this << ".DoubleNode( " << theNodeId << ", " << theModifiedElems << " )";
4760 //================================================================================
4762 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4763 This method provided for convenience works as DoubleNodes() described above.
4764 \param theNodes - group of nodes to be doubled.
4765 \param theModifiedElems - group of elements to be updated.
4766 \return TRUE if operation has been completed successfully, FALSE otherwise
4767 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
4769 //================================================================================
4771 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(SMESH::SMESH_GroupBase_ptr theNodes,
4772 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4774 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4777 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4778 SMESH::long_array_var aModifiedElems;
4779 if ( !CORBA::is_nil( theModifiedElems ) )
4780 aModifiedElems = theModifiedElems->GetListOfID();
4783 aModifiedElems = new SMESH::long_array;
4784 aModifiedElems->length( 0 );
4787 TPythonDump pyDump; // suppress dump by the next line
4789 bool done = DoubleNodes( aNodes, aModifiedElems );
4791 pyDump << this << ".DoubleNodeGroup( " << theNodes << ", " << theModifiedElems << " )";
4797 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements.
4798 * Works as DoubleNodeGroup(), but returns a new group with newly created nodes.
4799 * \param theNodes - group of nodes to be doubled.
4800 * \param theModifiedElems - group of elements to be updated.
4801 * \return a new group with newly created nodes
4802 * \sa DoubleNodeGroup()
4804 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes,
4805 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4807 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4810 SMESH::SMESH_Group_var aNewGroup;
4813 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4814 SMESH::long_array_var aModifiedElems;
4815 if ( !CORBA::is_nil( theModifiedElems ) )
4816 aModifiedElems = theModifiedElems->GetListOfID();
4818 aModifiedElems = new SMESH::long_array;
4819 aModifiedElems->length( 0 );
4822 TPythonDump pyDump; // suppress dump by the next line
4824 bool aResult = DoubleNodes( aNodes, aModifiedElems );
4828 // Create group with newly created nodes
4829 SMESH::long_array_var anIds = GetLastCreatedNodes();
4830 if (anIds->length() > 0) {
4831 string anUnindexedName (theNodes->GetName());
4832 string aNewName = generateGroupName(anUnindexedName + "_double");
4833 aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
4834 aNewGroup->Add(anIds);
4838 pyDump << "createdNodes = " << this << ".DoubleNodeGroupNew( " << theNodes << ", "
4839 << theModifiedElems << " )";
4841 return aNewGroup._retn();
4844 //================================================================================
4846 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4847 This method provided for convenience works as DoubleNodes() described above.
4848 \param theNodes - list of groups of nodes to be doubled
4849 \param theModifiedElems - list of groups of elements to be updated.
4850 \return TRUE if operation has been completed successfully, FALSE otherwise
4851 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
4853 //================================================================================
4855 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& theNodes,
4856 const SMESH::ListOfGroups& theModifiedElems )
4860 ::SMESH_MeshEditor aMeshEditor( myMesh );
4862 std::list< int > aNodes;
4864 for ( i = 0, n = theNodes.length(); i < n; i++ )
4866 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
4867 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
4869 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4870 for ( j = 0, m = aCurr->length(); j < m; j++ )
4871 aNodes.push_back( aCurr[ j ] );
4875 std::list< int > anElems;
4876 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4878 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
4879 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
4881 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4882 for ( j = 0, m = aCurr->length(); j < m; j++ )
4883 anElems.push_back( aCurr[ j ] );
4887 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
4889 storeResult( aMeshEditor) ;
4891 myMesh->GetMeshDS()->Modified();
4893 myMesh->SetIsModified( true );
4896 TPythonDump() << this << ".DoubleNodeGroups( " << theNodes << ", " << theModifiedElems << " )";
4901 //================================================================================
4903 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4904 \param theElems - the list of elements (edges or faces) to be replicated
4905 The nodes for duplication could be found from these elements
4906 \param theNodesNot - list of nodes to NOT replicate
4907 \param theAffectedElems - the list of elements (cells and edges) to which the
4908 replicated nodes should be associated to.
4909 \return TRUE if operation has been completed successfully, FALSE otherwise
4910 \sa DoubleNodeGroup(), DoubleNodeGroups()
4912 //================================================================================
4914 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
4915 const SMESH::long_array& theNodesNot,
4916 const SMESH::long_array& theAffectedElems )
4921 ::SMESH_MeshEditor aMeshEditor( myMesh );
4923 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4924 TIDSortedElemSet anElems, aNodes, anAffected;
4925 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4926 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4927 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
4929 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4931 storeResult( aMeshEditor) ;
4933 myMesh->GetMeshDS()->Modified();
4935 myMesh->SetIsModified( true );
4937 // Update Python script
4938 TPythonDump() << this << ".DoubleNodeElem( " << theElems << ", "
4939 << theNodesNot << ", " << theAffectedElems << " )";
4943 //================================================================================
4945 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4946 \param theElems - the list of elements (edges or faces) to be replicated
4947 The nodes for duplication could be found from these elements
4948 \param theNodesNot - list of nodes to NOT replicate
4949 \param theShape - shape to detect affected elements (element which geometric center
4950 located on or inside shape).
4951 The replicated nodes should be associated to affected elements.
4952 \return TRUE if operation has been completed successfully, FALSE otherwise
4953 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
4955 //================================================================================
4957 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_array& theElems,
4958 const SMESH::long_array& theNodesNot,
4959 GEOM::GEOM_Object_ptr theShape )
4964 ::SMESH_MeshEditor aMeshEditor( myMesh );
4966 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4967 TIDSortedElemSet anElems, aNodes;
4968 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4969 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4971 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4972 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4974 storeResult( aMeshEditor) ;
4976 myMesh->GetMeshDS()->Modified();
4978 myMesh->SetIsModified( true );
4980 // Update Python script
4981 TPythonDump() << "isDone = " << this << ".DoubleNodeElemInRegion( " << theElems << ", "
4982 << theNodesNot << ", " << theShape << " )";
4986 //================================================================================
4988 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4989 \param theElems - group of of elements (edges or faces) to be replicated
4990 \param theNodesNot - group of nodes not to replicated
4991 \param theAffectedElems - group of elements to which the replicated nodes
4992 should be associated to.
4993 \return TRUE if operation has been completed successfully, FALSE otherwise
4994 \sa DoubleNodes(), DoubleNodeGroups()
4996 //================================================================================
4998 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_ptr theElems,
4999 SMESH::SMESH_GroupBase_ptr theNodesNot,
5000 SMESH::SMESH_GroupBase_ptr theAffectedElems)
5002 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5007 ::SMESH_MeshEditor aMeshEditor( myMesh );
5009 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5010 TIDSortedElemSet anElems, aNodes, anAffected;
5011 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5012 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5013 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
5015 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5017 storeResult( aMeshEditor) ;
5019 myMesh->GetMeshDS()->Modified();
5021 myMesh->SetIsModified( true );
5023 // Update Python script
5024 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroup( " << theElems << ", "
5025 << theNodesNot << ", " << theAffectedElems << " )";
5030 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5031 * Works as DoubleNodeElemGroup(), but returns a new group with newly created elements.
5032 * \param theElems - group of of elements (edges or faces) to be replicated
5033 * \param theNodesNot - group of nodes not to replicated
5034 * \param theAffectedElems - group of elements to which the replicated nodes
5035 * should be associated to.
5036 * \return a new group with newly created elements
5037 * \sa DoubleNodeElemGroup()
5039 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems,
5040 SMESH::SMESH_GroupBase_ptr theNodesNot,
5041 SMESH::SMESH_GroupBase_ptr theAffectedElems)
5043 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5046 SMESH::SMESH_Group_var aNewGroup;
5050 ::SMESH_MeshEditor aMeshEditor( myMesh );
5052 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5053 TIDSortedElemSet anElems, aNodes, anAffected;
5054 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5055 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5056 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
5059 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5061 storeResult( aMeshEditor) ;
5064 myMesh->SetIsModified( true );
5066 // Create group with newly created elements
5067 SMESH::long_array_var anIds = GetLastCreatedElems();
5068 if (anIds->length() > 0) {
5069 SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
5070 string anUnindexedName (theElems->GetName());
5071 string aNewName = generateGroupName(anUnindexedName + "_double");
5072 aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
5073 aNewGroup->Add(anIds);
5077 // Update Python script
5078 TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupNew( " << theElems << ", "
5079 << theNodesNot << ", " << theAffectedElems << " )";
5080 return aNewGroup._retn();
5083 //================================================================================
5085 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5086 \param theElems - group of of elements (edges or faces) to be replicated
5087 \param theNodesNot - group of nodes not to replicated
5088 \param theShape - shape to detect affected elements (element which geometric center
5089 located on or inside shape).
5090 The replicated nodes should be associated to affected elements.
5091 \return TRUE if operation has been completed successfully, FALSE otherwise
5092 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
5094 //================================================================================
5096 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_GroupBase_ptr theElems,
5097 SMESH::SMESH_GroupBase_ptr theNodesNot,
5098 GEOM::GEOM_Object_ptr theShape )
5101 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5106 ::SMESH_MeshEditor aMeshEditor( myMesh );
5108 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5109 TIDSortedElemSet anElems, aNodes, anAffected;
5110 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5111 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5113 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5114 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5116 storeResult( aMeshEditor) ;
5118 myMesh->GetMeshDS()->Modified();
5120 myMesh->SetIsModified( true );
5122 // Update Python script
5123 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupInRegion( " << theElems << ", "
5124 << theNodesNot << ", " << theShape << " )";
5128 //================================================================================
5130 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5131 This method provided for convenience works as DoubleNodes() described above.
5132 \param theElems - list of groups of elements (edges or faces) to be replicated
5133 \param theNodesNot - list of groups of nodes not to replicated
5134 \param theAffectedElems - group of elements to which the replicated nodes
5135 should be associated to.
5136 \return TRUE if operation has been completed successfully, FALSE otherwise
5137 \sa DoubleNodeGroup(), DoubleNodes(), DoubleNodeElemGroupsNew()
5139 //================================================================================
5141 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
5142 SMESHDS_Mesh* theMeshDS,
5143 TIDSortedElemSet& theElemSet,
5144 const bool theIsNodeGrp)
5146 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
5148 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
5149 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
5150 : aGrp->GetType() != SMESH::NODE ) )
5152 SMESH::long_array_var anIDs = aGrp->GetIDs();
5153 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
5158 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroups& theElems,
5159 const SMESH::ListOfGroups& theNodesNot,
5160 const SMESH::ListOfGroups& theAffectedElems)
5164 ::SMESH_MeshEditor aMeshEditor( myMesh );
5166 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5167 TIDSortedElemSet anElems, aNodes, anAffected;
5168 listOfGroupToSet(theElems, aMeshDS, anElems, false );
5169 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5170 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
5172 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5174 storeResult( aMeshEditor) ;
5176 myMesh->GetMeshDS()->Modified();
5178 myMesh->SetIsModified( true );
5180 // Update Python script
5181 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroups( " << &theElems << ", "
5182 << &theNodesNot << ", " << &theAffectedElems << " )";
5186 //================================================================================
5188 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5189 * Works as DoubleNodeElemGroups(), but returns a new group with newly created elements.
5190 \param theElems - list of groups of elements (edges or faces) to be replicated
5191 \param theNodesNot - list of groups of nodes not to replicated
5192 \param theAffectedElems - group of elements to which the replicated nodes
5193 should be associated to.
5194 * \return a new group with newly created elements
5195 * \sa DoubleNodeElemGroups()
5197 //================================================================================
5199 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupsNew(const SMESH::ListOfGroups& theElems,
5200 const SMESH::ListOfGroups& theNodesNot,
5201 const SMESH::ListOfGroups& theAffectedElems)
5203 SMESH::SMESH_Group_var aNewGroup;
5207 ::SMESH_MeshEditor aMeshEditor( myMesh );
5209 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5210 TIDSortedElemSet anElems, aNodes, anAffected;
5211 listOfGroupToSet(theElems, aMeshDS, anElems, false );
5212 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5213 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
5215 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5217 storeResult( aMeshEditor) ;
5219 myMesh->GetMeshDS()->Modified();
5221 myMesh->SetIsModified( true );
5223 // Create group with newly created elements
5224 SMESH::long_array_var anIds = GetLastCreatedElems();
5225 if (anIds->length() > 0) {
5226 SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
5227 string anUnindexedName (theElems[0]->GetName());
5228 string aNewName = generateGroupName(anUnindexedName + "_double");
5229 aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
5230 aNewGroup->Add(anIds);
5234 // Update Python script
5235 TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupsNew( " << &theElems << ", "
5236 << &theNodesNot << ", " << &theAffectedElems << " )";
5237 return aNewGroup._retn();
5240 //================================================================================
5242 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5243 This method provided for convenience works as DoubleNodes() described above.
5244 \param theElems - list of groups of elements (edges or faces) to be replicated
5245 \param theNodesNot - list of groups of nodes not to replicated
5246 \param theShape - shape to detect affected elements (element which geometric center
5247 located on or inside shape).
5248 The replicated nodes should be associated to affected elements.
5249 \return TRUE if operation has been completed successfully, FALSE otherwise
5250 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
5252 //================================================================================
5255 SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theElems,
5256 const SMESH::ListOfGroups& theNodesNot,
5257 GEOM::GEOM_Object_ptr theShape )
5261 ::SMESH_MeshEditor aMeshEditor( myMesh );
5263 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5264 TIDSortedElemSet anElems, aNodes;
5265 listOfGroupToSet(theElems, aMeshDS, anElems,false );
5266 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5268 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5269 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5271 storeResult( aMeshEditor) ;
5273 myMesh->GetMeshDS()->Modified();
5275 myMesh->SetIsModified( true );
5277 // Update Python script
5278 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupsInRegion( " << &theElems << ", "
5279 << &theNodesNot << ", " << theShape << " )";
5283 //================================================================================
5285 \brief Generated skin mesh (containing 2D cells) from 3D mesh
5286 The created 2D mesh elements based on nodes of free faces of boundary volumes
5287 \return TRUE if operation has been completed successfully, FALSE otherwise
5289 //================================================================================
5291 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
5295 ::SMESH_MeshEditor aMeshEditor( myMesh );
5296 bool aResult = aMeshEditor.Make2DMeshFrom3D();
5297 storeResult( aMeshEditor) ;
5298 myMesh->GetMeshDS()->Modified();
5299 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";
5303 //================================================================================
5305 * \brief Double nodes on shared faces between groups of volumes and create flat elements on demand.
5306 * The list of groups must describe a partition of the mesh volumes.
5307 * The nodes of the internal faces at the boundaries of the groups are doubled.
5308 * In option, the internal faces are replaced by flat elements.
5309 * Triangles are transformed in prisms, and quadrangles in hexahedrons.
5310 * @param theDomains - list of groups of volumes
5311 * @param createJointElems - if TRUE, create the elements
5312 * @return TRUE if operation has been completed successfully, FALSE otherwise
5314 //================================================================================
5316 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::ListOfGroups& theDomains,
5317 CORBA::Boolean createJointElems )
5321 ::SMESH_MeshEditor aMeshEditor( myMesh );
5323 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5325 vector<TIDSortedElemSet> domains;
5328 for ( int i = 0, n = theDomains.length(); i < n; i++ )
5330 SMESH::SMESH_GroupBase_var aGrp = theDomains[ i ];
5331 if ( !CORBA::is_nil( aGrp ) && ( aGrp->GetType() != SMESH::NODE ) )
5333 TIDSortedElemSet domain;
5335 domains.push_back(domain);
5336 SMESH::long_array_var anIDs = aGrp->GetIDs();
5337 arrayToSet( anIDs, aMeshDS, domains[ i ], SMDSAbs_All );
5341 bool aResult = aMeshEditor.DoubleNodesOnGroupBoundaries( domains, createJointElems );
5343 storeResult( aMeshEditor) ;
5344 myMesh->GetMeshDS()->Modified();
5346 // Update Python script
5347 TPythonDump() << "isDone = " << this << ".DoubleNodesOnGroupBoundaries( " << &theDomains
5348 << ", " << createJointElems << " )";
5352 // issue 20749 ===================================================================
5354 * \brief Creates missing boundary elements
5355 * \param elements - elements whose boundary is to be checked
5356 * \param dimension - defines type of boundary elements to create
5357 * \param groupName - a name of group to store created boundary elements in,
5358 * "" means not to create the group
5359 * \param meshName - a name of new mesh to store created boundary elements in,
5360 * "" means not to create the new mesh
5361 * \param toCopyElements - if true, the checked elements will be copied into the new mesh
5362 * \param toCopyExistingBondary - if true, not only new but also pre-existing
5363 * boundary elements will be copied into the new mesh
5364 * \param group - returns the create group, if any
5365 * \retval SMESH::SMESH_Mesh - the mesh where elements were added to
5367 // ================================================================================
5369 SMESH::SMESH_Mesh_ptr
5370 SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource,
5371 SMESH::Bnd_Dimension dim,
5372 const char* groupName,
5373 const char* meshName,
5374 CORBA::Boolean toCopyElements,
5375 CORBA::Boolean toCopyExistingBondary,
5376 SMESH::SMESH_Group_out group)
5380 if ( dim > SMESH::BND_1DFROM2D )
5381 THROW_SALOME_CORBA_EXCEPTION("Invalid boundary dimension", SALOME::BAD_PARAM);
5384 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5386 SMESH::SMESH_Mesh_var mesh_var;
5387 SMESH::SMESH_Group_var group_var;
5391 TIDSortedElemSet elements;
5392 SMDSAbs_ElementType elemType = (dim == SMESH::BND_1DFROM2D) ? SMDSAbs_Face : SMDSAbs_Volume;
5393 if ( idSourceToSet( idSource, aMeshDS, elements, elemType,/*emptyIfIsMesh=*/true ))
5397 strlen(meshName) ? makeMesh(meshName) : SMESH::SMESH_Mesh::_duplicate(myMesh_i->_this());
5398 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh_var );
5400 SMESH_Mesh* smesh_mesh = (mesh_i==myMesh_i) ? (SMESH_Mesh*)0 : &mesh_i->GetImpl();
5402 // group of new boundary elements
5403 SMESH_Group* smesh_group = 0;
5404 if ( strlen(groupName) )
5406 group_var = mesh_i->CreateGroup( SMESH::ElementType(int(elemType)-1),groupName);
5407 if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( group_var ))
5408 smesh_group = group_i->GetSmeshGroup();
5412 ::SMESH_MeshEditor aMeshEditor( myMesh );
5413 aMeshEditor.MakeBoundaryMesh( elements,
5414 ::SMESH_MeshEditor::Bnd_Dimension(dim),
5418 toCopyExistingBondary);
5419 storeResult( aMeshEditor );
5422 const char* dimName[] = { "BND_2DFROM3D", "BND_1DFROM3D", "BND_1DFROM2D" };
5424 // result of MakeBoundaryMesh() is a tuple (mesh, group)
5425 if ( mesh_var->_is_nil() )
5426 pyDump << myMesh_i->_this() << ", ";
5428 pyDump << mesh_var << ", ";
5429 if ( group_var->_is_nil() )
5430 pyDump << "_NoneGroup = "; // assignment to None is forbiden
5432 pyDump << group_var << " = ";
5433 pyDump << this << ".MakeBoundaryMesh( "
5435 << "SMESH." << dimName[int(dim)] << ", "
5436 << "'" << groupName << "', "
5437 << "'" << meshName<< "', "
5438 << toCopyElements << ", "
5439 << toCopyExistingBondary << ")";
5441 group = group_var._retn();
5442 return mesh_var._retn();