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] );
477 myMesh->SetIsModified( true );
479 return anEditor.Remove( IdList, true );
482 //=============================================================================
486 //=============================================================================
488 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
489 CORBA::Double y, CORBA::Double z)
493 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
495 // Update Python script
496 TPythonDump() << "nodeID = " << this << ".AddNode( "
497 << x << ", " << y << ", " << z << " )";
499 myMesh->GetMeshDS()->Modified();
500 myMesh->SetIsModified( true ); // issue 0020693
504 //=============================================================================
508 //=============================================================================
509 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
513 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
514 SMDS_MeshElement* elem = GetMeshDS()->Add0DElement(aNode);
516 // Update Python script
517 TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
519 myMesh->GetMeshDS()->Modified();
520 myMesh->SetIsModified( true ); // issue 0020693
523 return elem->GetID();
528 //=============================================================================
532 //=============================================================================
534 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
538 int NbNodes = IDsOfNodes.length();
539 SMDS_MeshElement* elem = 0;
542 CORBA::Long index1 = IDsOfNodes[0];
543 CORBA::Long index2 = IDsOfNodes[1];
544 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
546 // Update Python script
547 TPythonDump() << "edge = " << this << ".AddEdge([ "
548 << index1 << ", " << index2 <<" ])";
551 CORBA::Long n1 = IDsOfNodes[0];
552 CORBA::Long n2 = IDsOfNodes[1];
553 CORBA::Long n12 = IDsOfNodes[2];
554 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
555 GetMeshDS()->FindNode(n2),
556 GetMeshDS()->FindNode(n12));
557 // Update Python script
558 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
559 <<n1<<", "<<n2<<", "<<n12<<" ])";
562 myMesh->GetMeshDS()->Modified();
564 return myMesh->SetIsModified( true ), elem->GetID();
569 //=============================================================================
573 //=============================================================================
575 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
579 int NbNodes = IDsOfNodes.length();
585 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
586 for (int i = 0; i < NbNodes; i++)
587 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
589 SMDS_MeshElement* elem = 0;
591 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
593 else if (NbNodes == 4) {
594 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
596 else if (NbNodes == 6) {
597 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
600 else if (NbNodes == 8) {
601 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
602 nodes[4], nodes[5], nodes[6], nodes[7]);
604 else if (NbNodes > 2) {
605 elem = GetMeshDS()->AddPolygonalFace(nodes);
608 // Update Python script
609 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
611 myMesh->GetMeshDS()->Modified();
613 return myMesh->SetIsModified( true ), elem->GetID();
618 //=============================================================================
622 //=============================================================================
623 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsOfNodes)
627 int NbNodes = IDsOfNodes.length();
628 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
629 for (int i = 0; i < NbNodes; i++)
630 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
632 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
634 // Update Python script
635 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
637 myMesh->GetMeshDS()->Modified();
638 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
641 //=============================================================================
645 //=============================================================================
647 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
651 int NbNodes = IDsOfNodes.length();
652 vector< const SMDS_MeshNode*> n(NbNodes);
653 for(int i=0;i<NbNodes;i++)
654 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
656 SMDS_MeshElement* elem = 0;
659 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
660 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
661 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
662 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
663 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
664 n[6],n[7],n[8],n[9]);
666 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
667 n[7],n[8],n[9],n[10],n[11],n[12]);
669 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
670 n[9],n[10],n[11],n[12],n[13],n[14]);
672 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
673 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
674 n[15],n[16],n[17],n[18],n[19]);
678 // Update Python script
679 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
681 myMesh->GetMeshDS()->Modified();
683 return myMesh->SetIsModified( true ), elem->GetID();
688 //=============================================================================
690 * AddPolyhedralVolume
692 //=============================================================================
693 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume (const SMESH::long_array & IDsOfNodes,
694 const SMESH::long_array & Quantities)
698 int NbNodes = IDsOfNodes.length();
699 std::vector<const SMDS_MeshNode*> n (NbNodes);
700 for (int i = 0; i < NbNodes; i++)
702 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDsOfNodes[i]);
703 if (!aNode) return 0;
707 int NbFaces = Quantities.length();
708 std::vector<int> q (NbFaces);
709 for (int j = 0; j < NbFaces; j++)
710 q[j] = Quantities[j];
712 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
714 // Update Python script
715 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
716 << IDsOfNodes << ", " << Quantities << " )";
717 myMesh->GetMeshDS()->Modified();
719 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
722 //=============================================================================
724 * AddPolyhedralVolumeByFaces
726 //=============================================================================
727 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_array & IdsOfFaces)
731 int NbFaces = IdsOfFaces.length();
732 std::vector<const SMDS_MeshNode*> poly_nodes;
733 std::vector<int> quantities (NbFaces);
735 for (int i = 0; i < NbFaces; i++) {
736 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
737 quantities[i] = aFace->NbNodes();
739 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
741 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
745 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
747 // Update Python script
748 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
749 << IdsOfFaces << " )";
750 myMesh->GetMeshDS()->Modified();
752 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
755 //=============================================================================
757 * \brief Bind a node to a vertex
758 * \param NodeID - node ID
759 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
760 * \retval boolean - false if NodeID or VertexID is invalid
762 //=============================================================================
764 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
765 throw (SALOME::SALOME_Exception)
767 Unexpect aCatch(SALOME_SalomeException);
769 SMESHDS_Mesh * mesh = GetMeshDS();
770 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
772 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
774 if ( mesh->MaxShapeIndex() < VertexID )
775 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
777 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
778 if ( shape.ShapeType() != TopAbs_VERTEX )
779 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
781 mesh->SetNodeOnVertex( node, VertexID );
783 myMesh->SetIsModified( true );
786 //=============================================================================
788 * \brief Store node position on an edge
789 * \param NodeID - node ID
790 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
791 * \param paramOnEdge - parameter on edge where the node is located
792 * \retval boolean - false if any parameter is invalid
794 //=============================================================================
796 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
797 CORBA::Double paramOnEdge)
798 throw (SALOME::SALOME_Exception)
800 Unexpect aCatch(SALOME_SalomeException);
802 SMESHDS_Mesh * mesh = GetMeshDS();
803 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
805 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
807 if ( mesh->MaxShapeIndex() < EdgeID )
808 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
810 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
811 if ( shape.ShapeType() != TopAbs_EDGE )
812 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
815 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
816 if ( paramOnEdge < f || paramOnEdge > l )
817 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
819 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
821 myMesh->SetIsModified( true );
824 //=============================================================================
826 * \brief Store node position on a face
827 * \param NodeID - node ID
828 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
829 * \param u - U parameter on face where the node is located
830 * \param v - V parameter on face where the node is located
831 * \retval boolean - false if any parameter is invalid
833 //=============================================================================
835 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
836 CORBA::Double u, CORBA::Double v)
837 throw (SALOME::SALOME_Exception)
839 Unexpect aCatch(SALOME_SalomeException);
841 SMESHDS_Mesh * mesh = GetMeshDS();
842 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
844 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
846 if ( mesh->MaxShapeIndex() < FaceID )
847 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
849 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
850 if ( shape.ShapeType() != TopAbs_FACE )
851 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
853 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
854 bool isOut = ( u < surf.FirstUParameter() ||
855 u > surf.LastUParameter() ||
856 v < surf.FirstVParameter() ||
857 v > surf.LastVParameter() );
861 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
862 << " u( " << surf.FirstUParameter()
863 << "," << surf.LastUParameter()
864 << ") v( " << surf.FirstVParameter()
865 << "," << surf.LastVParameter() << ")" );
867 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
870 mesh->SetNodeOnFace( node, FaceID, u, v );
871 myMesh->SetIsModified( true );
874 //=============================================================================
876 * \brief Bind a node to a solid
877 * \param NodeID - node ID
878 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
879 * \retval boolean - false if NodeID or SolidID is invalid
881 //=============================================================================
883 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
884 throw (SALOME::SALOME_Exception)
886 Unexpect aCatch(SALOME_SalomeException);
888 SMESHDS_Mesh * mesh = GetMeshDS();
889 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
891 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
893 if ( mesh->MaxShapeIndex() < SolidID )
894 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
896 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
897 if ( shape.ShapeType() != TopAbs_SOLID &&
898 shape.ShapeType() != TopAbs_SHELL)
899 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
901 mesh->SetNodeInVolume( node, SolidID );
903 // myMesh->SetIsModified( true ); - SetNodeInVolume() can't prevent re-compute, I believe
906 //=============================================================================
908 * \brief Bind an element to a shape
909 * \param ElementID - element ID
910 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
911 * \retval boolean - false if ElementID or ShapeID is invalid
913 //=============================================================================
915 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
917 throw (SALOME::SALOME_Exception)
919 Unexpect aCatch(SALOME_SalomeException);
921 SMESHDS_Mesh * mesh = GetMeshDS();
922 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
924 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
926 if ( mesh->MaxShapeIndex() < ShapeID )
927 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
929 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
930 if ( shape.ShapeType() != TopAbs_EDGE &&
931 shape.ShapeType() != TopAbs_FACE &&
932 shape.ShapeType() != TopAbs_SOLID &&
933 shape.ShapeType() != TopAbs_SHELL )
934 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
936 mesh->SetMeshElementOnShape( elem, ShapeID );
938 myMesh->SetIsModified( true );
941 //=============================================================================
945 //=============================================================================
947 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
952 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
953 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
957 // Update Python script
958 TPythonDump() << "isDone = " << this << ".InverseDiag( "
959 << NodeID1 << ", " << NodeID2 << " )";
962 ::SMESH_MeshEditor aMeshEditor( myMesh );
963 int ret = aMeshEditor.InverseDiag ( n1, n2 );
964 myMesh->GetMeshDS()->Modified();
965 myMesh->SetIsModified( true );
969 //=============================================================================
973 //=============================================================================
975 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
980 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
981 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
985 // Update Python script
986 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
987 << NodeID1 << ", " << NodeID2 << " )";
989 ::SMESH_MeshEditor aMeshEditor( myMesh );
991 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
993 myMesh->GetMeshDS()->Modified();
995 myMesh->SetIsModified( true ); // issue 0020693
997 storeResult(aMeshEditor);
1002 //=============================================================================
1006 //=============================================================================
1008 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
1012 ::SMESH_MeshEditor anEditor( myMesh );
1013 for (int i = 0; i < IDsOfElements.length(); i++)
1015 CORBA::Long index = IDsOfElements[i];
1016 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
1018 anEditor.Reorient( elem );
1020 // Update Python script
1021 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
1023 myMesh->GetMeshDS()->Modified();
1024 if ( IDsOfElements.length() )
1025 myMesh->SetIsModified( true ); // issue 0020693
1031 //=============================================================================
1035 //=============================================================================
1037 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
1041 TPythonDump aTPythonDump; // suppress dump in Reorient()
1043 SMESH::long_array_var anElementsId = theObject->GetIDs();
1044 CORBA::Boolean isDone = Reorient(anElementsId);
1046 // Update Python script
1047 aTPythonDump << "isDone = " << this << ".ReorientObject( " << theObject << " )";
1052 //=============================================================================
1056 //=============================================================================
1057 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
1058 SMESH::NumericalFunctor_ptr Criterion,
1059 CORBA::Double MaxAngle)
1063 SMESHDS_Mesh* aMesh = GetMeshDS();
1064 TIDSortedElemSet faces;
1065 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1067 SMESH::NumericalFunctor_i* aNumericalFunctor =
1068 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1069 SMESH::Controls::NumericalFunctorPtr aCrit;
1070 if ( !aNumericalFunctor )
1071 aCrit.reset( new SMESH::Controls::AspectRatio() );
1073 aCrit = aNumericalFunctor->GetNumericalFunctor();
1075 // Update Python script
1076 TPythonDump() << "isDone = " << this << ".TriToQuad( "
1077 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1079 ::SMESH_MeshEditor anEditor( myMesh );
1081 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
1082 myMesh->GetMeshDS()->Modified();
1084 myMesh->SetIsModified( true ); // issue 0020693
1086 storeResult(anEditor);
1092 //=============================================================================
1096 //=============================================================================
1097 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1098 SMESH::NumericalFunctor_ptr Criterion,
1099 CORBA::Double MaxAngle)
1103 TPythonDump aTPythonDump; // suppress dump in TriToQuad()
1104 SMESH::long_array_var anElementsId = theObject->GetIDs();
1105 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
1107 SMESH::NumericalFunctor_i* aNumericalFunctor =
1108 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1110 // Update Python script
1111 aTPythonDump << "isDone = " << this << ".TriToQuadObject("
1112 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1118 //=============================================================================
1122 //=============================================================================
1123 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
1124 SMESH::NumericalFunctor_ptr Criterion)
1128 SMESHDS_Mesh* aMesh = GetMeshDS();
1129 TIDSortedElemSet faces;
1130 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1132 SMESH::NumericalFunctor_i* aNumericalFunctor =
1133 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1134 SMESH::Controls::NumericalFunctorPtr aCrit;
1135 if ( !aNumericalFunctor )
1136 aCrit.reset( new SMESH::Controls::AspectRatio() );
1138 aCrit = aNumericalFunctor->GetNumericalFunctor();
1141 // Update Python script
1142 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1144 ::SMESH_MeshEditor anEditor( myMesh );
1145 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1146 myMesh->GetMeshDS()->Modified();
1148 myMesh->SetIsModified( true ); // issue 0020693
1150 storeResult(anEditor);
1156 //=============================================================================
1160 //=============================================================================
1161 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1162 SMESH::NumericalFunctor_ptr Criterion)
1166 TPythonDump aTPythonDump; // suppress dump in QuadToTri()
1168 SMESH::long_array_var anElementsId = theObject->GetIDs();
1169 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1171 SMESH::NumericalFunctor_i* aNumericalFunctor =
1172 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1174 // Update Python script
1175 aTPythonDump << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1181 //=============================================================================
1185 //=============================================================================
1186 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1187 CORBA::Boolean Diag13)
1191 SMESHDS_Mesh* aMesh = GetMeshDS();
1192 TIDSortedElemSet faces;
1193 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1195 // Update Python script
1196 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1197 << IDsOfElements << ", " << Diag13 << " )";
1199 ::SMESH_MeshEditor anEditor( myMesh );
1200 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1201 myMesh->GetMeshDS()->Modified();
1203 myMesh->SetIsModified( true ); // issue 0020693
1206 storeResult(anEditor);
1212 //=============================================================================
1216 //=============================================================================
1217 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1218 CORBA::Boolean Diag13)
1222 TPythonDump aTPythonDump; // suppress dump in SplitQuad()
1224 SMESH::long_array_var anElementsId = theObject->GetIDs();
1225 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1227 // Update Python script
1228 aTPythonDump << "isDone = " << this << ".SplitQuadObject( "
1229 << theObject << ", " << Diag13 << " )";
1235 //=============================================================================
1239 //=============================================================================
1240 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1241 SMESH::NumericalFunctor_ptr Criterion)
1245 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1246 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1248 SMESH::NumericalFunctor_i* aNumericalFunctor =
1249 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1250 SMESH::Controls::NumericalFunctorPtr aCrit;
1251 if (aNumericalFunctor)
1252 aCrit = aNumericalFunctor->GetNumericalFunctor();
1254 aCrit.reset(new SMESH::Controls::AspectRatio());
1256 ::SMESH_MeshEditor anEditor (myMesh);
1257 return anEditor.BestSplit(quad, aCrit);
1262 //================================================================================
1264 * \brief Split volumic elements into tetrahedrons
1266 //================================================================================
1268 void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems,
1269 CORBA::Short methodFlags)
1270 throw (SALOME::SALOME_Exception)
1272 Unexpect aCatch(SALOME_SalomeException);
1276 SMESH::long_array_var anElementsId = elems->GetIDs();
1277 TIDSortedElemSet elemSet;
1278 arrayToSet( anElementsId, GetMeshDS(), elemSet, SMDSAbs_Volume );
1280 ::SMESH_MeshEditor anEditor (myMesh);
1281 anEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags ));
1282 myMesh->GetMeshDS()->Modified();
1284 storeResult(anEditor);
1286 // if ( myLastCreatedElems.length() ) - it does not influence Compute()
1287 // myMesh->SetIsModified( true ); // issue 0020693
1289 TPythonDump() << this << ".SplitVolumesIntoTetra( "
1290 << elems << ", " << methodFlags << " )";
1293 //=======================================================================
1296 //=======================================================================
1299 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1300 const SMESH::long_array & IDsOfFixedNodes,
1301 CORBA::Long MaxNbOfIterations,
1302 CORBA::Double MaxAspectRatio,
1303 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1305 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1306 MaxAspectRatio, Method, false );
1310 //=======================================================================
1311 //function : SmoothParametric
1313 //=======================================================================
1316 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1317 const SMESH::long_array & IDsOfFixedNodes,
1318 CORBA::Long MaxNbOfIterations,
1319 CORBA::Double MaxAspectRatio,
1320 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1322 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1323 MaxAspectRatio, Method, true );
1327 //=======================================================================
1328 //function : SmoothObject
1330 //=======================================================================
1333 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1334 const SMESH::long_array & IDsOfFixedNodes,
1335 CORBA::Long MaxNbOfIterations,
1336 CORBA::Double MaxAspectRatio,
1337 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1339 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1340 MaxAspectRatio, Method, false);
1344 //=======================================================================
1345 //function : SmoothParametricObject
1347 //=======================================================================
1350 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1351 const SMESH::long_array & IDsOfFixedNodes,
1352 CORBA::Long MaxNbOfIterations,
1353 CORBA::Double MaxAspectRatio,
1354 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1356 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1357 MaxAspectRatio, Method, true);
1361 //=============================================================================
1365 //=============================================================================
1368 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1369 const SMESH::long_array & IDsOfFixedNodes,
1370 CORBA::Long MaxNbOfIterations,
1371 CORBA::Double MaxAspectRatio,
1372 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1377 SMESHDS_Mesh* aMesh = GetMeshDS();
1379 TIDSortedElemSet elements;
1380 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1382 set<const SMDS_MeshNode*> fixedNodes;
1383 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1384 CORBA::Long index = IDsOfFixedNodes[i];
1385 const SMDS_MeshNode * node = aMesh->FindNode(index);
1387 fixedNodes.insert( node );
1389 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1390 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1391 method = ::SMESH_MeshEditor::CENTROIDAL;
1393 ::SMESH_MeshEditor anEditor( myMesh );
1394 anEditor.Smooth(elements, fixedNodes, method,
1395 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1397 myMesh->GetMeshDS()->Modified();
1398 myMesh->SetIsModified( true ); // issue 0020693
1400 storeResult(anEditor);
1402 // Update Python script
1403 TPythonDump() << "isDone = " << this << "."
1404 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1405 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1406 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1407 << "SMESH.SMESH_MeshEditor."
1408 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1409 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1415 //=============================================================================
1419 //=============================================================================
1422 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1423 const SMESH::long_array & IDsOfFixedNodes,
1424 CORBA::Long MaxNbOfIterations,
1425 CORBA::Double MaxAspectRatio,
1426 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1431 TPythonDump aTPythonDump; // suppress dump in smooth()
1433 SMESH::long_array_var anElementsId = theObject->GetIDs();
1434 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1435 MaxAspectRatio, Method, IsParametric);
1437 // Update Python script
1438 aTPythonDump << "isDone = " << this << "."
1439 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1440 << theObject << ", " << IDsOfFixedNodes << ", "
1441 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1442 << "SMESH.SMESH_MeshEditor."
1443 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1444 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1450 //=============================================================================
1454 //=============================================================================
1456 void SMESH_MeshEditor_i::RenumberNodes()
1458 // Update Python script
1459 TPythonDump() << this << ".RenumberNodes()";
1461 GetMeshDS()->Renumber( true );
1465 //=============================================================================
1469 //=============================================================================
1471 void SMESH_MeshEditor_i::RenumberElements()
1473 // Update Python script
1474 TPythonDump() << this << ".RenumberElements()";
1476 GetMeshDS()->Renumber( false );
1479 //=======================================================================
1481 * \brief Return groups by their IDs
1483 //=======================================================================
1485 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1489 myMesh_i->CreateGroupServants();
1490 return myMesh_i->GetGroups( *groupIDs );
1493 //=======================================================================
1494 //function : rotationSweep
1496 //=======================================================================
1498 SMESH::ListOfGroups*
1499 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1500 const SMESH::AxisStruct & theAxis,
1501 CORBA::Double theAngleInRadians,
1502 CORBA::Long theNbOfSteps,
1503 CORBA::Double theTolerance,
1504 const bool theMakeGroups,
1505 const SMDSAbs_ElementType theElementType)
1509 TIDSortedElemSet inElements, copyElements;
1510 arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType);
1512 TIDSortedElemSet* workElements = & inElements;
1513 TPreviewMesh tmpMesh( SMDSAbs_Face );
1514 SMESH_Mesh* mesh = 0;
1515 bool makeWalls=true;
1516 if ( myPreviewMode )
1518 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1519 tmpMesh.Copy( inElements, copyElements, select, avoid );
1521 workElements = & copyElements;
1522 //makeWalls = false;
1529 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1530 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1532 ::SMESH_MeshEditor anEditor( mesh );
1533 ::SMESH_MeshEditor::PGroupIDs groupIds =
1534 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1535 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1536 storeResult(anEditor);
1537 myMesh->GetMeshDS()->Modified();
1539 // myMesh->SetIsModified( true ); -- it does not influence Compute()
1541 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1544 //=======================================================================
1545 //function : RotationSweep
1547 //=======================================================================
1549 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1550 const SMESH::AxisStruct & theAxis,
1551 CORBA::Double theAngleInRadians,
1552 CORBA::Long theNbOfSteps,
1553 CORBA::Double theTolerance)
1555 if ( !myPreviewMode ) {
1556 TPythonDump() << this << ".RotationSweep( "
1557 << theIDsOfElements << ", "
1559 << theAngleInRadians << ", "
1560 << theNbOfSteps << ", "
1561 << theTolerance << " )";
1563 rotationSweep(theIDsOfElements,
1571 //=======================================================================
1572 //function : RotationSweepMakeGroups
1574 //=======================================================================
1576 SMESH::ListOfGroups*
1577 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1578 const SMESH::AxisStruct& theAxis,
1579 CORBA::Double theAngleInRadians,
1580 CORBA::Long theNbOfSteps,
1581 CORBA::Double theTolerance)
1583 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1585 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1591 if (!myPreviewMode) {
1592 DumpGroupsList(aPythonDump, aGroups);
1593 aPythonDump << this << ".RotationSweepMakeGroups( "
1594 << theIDsOfElements << ", "
1596 << theAngleInRadians << ", "
1597 << theNbOfSteps << ", "
1598 << theTolerance << " )";
1603 //=======================================================================
1604 //function : RotationSweepObject
1606 //=======================================================================
1608 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1609 const SMESH::AxisStruct & theAxis,
1610 CORBA::Double theAngleInRadians,
1611 CORBA::Long theNbOfSteps,
1612 CORBA::Double theTolerance)
1614 if ( !myPreviewMode ) {
1615 TPythonDump() << this << ".RotationSweepObject( "
1616 << theObject << ", "
1618 << theAngleInRadians << ", "
1619 << theNbOfSteps << ", "
1620 << theTolerance << " )";
1622 SMESH::long_array_var anElementsId = theObject->GetIDs();
1623 rotationSweep(anElementsId,
1631 //=======================================================================
1632 //function : RotationSweepObject1D
1634 //=======================================================================
1636 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1637 const SMESH::AxisStruct & theAxis,
1638 CORBA::Double theAngleInRadians,
1639 CORBA::Long theNbOfSteps,
1640 CORBA::Double theTolerance)
1642 if ( !myPreviewMode ) {
1643 TPythonDump() << this << ".RotationSweepObject1D( "
1644 << theObject << ", "
1646 << theAngleInRadians << ", "
1647 << theNbOfSteps << ", "
1648 << theTolerance << " )";
1650 SMESH::long_array_var anElementsId = theObject->GetIDs();
1651 rotationSweep(anElementsId,
1660 //=======================================================================
1661 //function : RotationSweepObject2D
1663 //=======================================================================
1665 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1666 const SMESH::AxisStruct & theAxis,
1667 CORBA::Double theAngleInRadians,
1668 CORBA::Long theNbOfSteps,
1669 CORBA::Double theTolerance)
1671 if ( !myPreviewMode ) {
1672 TPythonDump() << this << ".RotationSweepObject2D( "
1673 << theObject << ", "
1675 << theAngleInRadians << ", "
1676 << theNbOfSteps << ", "
1677 << theTolerance << " )";
1679 SMESH::long_array_var anElementsId = theObject->GetIDs();
1680 rotationSweep(anElementsId,
1689 //=======================================================================
1690 //function : RotationSweepObjectMakeGroups
1692 //=======================================================================
1694 SMESH::ListOfGroups*
1695 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1696 const SMESH::AxisStruct& theAxis,
1697 CORBA::Double theAngleInRadians,
1698 CORBA::Long theNbOfSteps,
1699 CORBA::Double theTolerance)
1701 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1703 SMESH::long_array_var anElementsId = theObject->GetIDs();
1704 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1710 if (!myPreviewMode) {
1711 DumpGroupsList(aPythonDump, aGroups);
1712 aPythonDump << this << ".RotationSweepObjectMakeGroups( "
1713 << theObject << ", "
1715 << theAngleInRadians << ", "
1716 << theNbOfSteps << ", "
1717 << theTolerance << " )";
1722 //=======================================================================
1723 //function : RotationSweepObject1DMakeGroups
1725 //=======================================================================
1727 SMESH::ListOfGroups*
1728 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1729 const SMESH::AxisStruct& theAxis,
1730 CORBA::Double theAngleInRadians,
1731 CORBA::Long theNbOfSteps,
1732 CORBA::Double theTolerance)
1734 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1736 SMESH::long_array_var anElementsId = theObject->GetIDs();
1737 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1744 if (!myPreviewMode) {
1745 DumpGroupsList(aPythonDump, aGroups);
1746 aPythonDump << this << ".RotationSweepObject1DMakeGroups( "
1747 << theObject << ", "
1749 << theAngleInRadians << ", "
1750 << theNbOfSteps << ", "
1751 << theTolerance << " )";
1756 //=======================================================================
1757 //function : RotationSweepObject2DMakeGroups
1759 //=======================================================================
1761 SMESH::ListOfGroups*
1762 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1763 const SMESH::AxisStruct& theAxis,
1764 CORBA::Double theAngleInRadians,
1765 CORBA::Long theNbOfSteps,
1766 CORBA::Double theTolerance)
1768 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1770 SMESH::long_array_var anElementsId = theObject->GetIDs();
1771 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1778 if (!myPreviewMode) {
1779 DumpGroupsList(aPythonDump, aGroups);
1780 aPythonDump << this << ".RotationSweepObject2DMakeGroups( "
1781 << theObject << ", "
1783 << theAngleInRadians << ", "
1784 << theNbOfSteps << ", "
1785 << theTolerance << " )";
1791 //=======================================================================
1792 //function : extrusionSweep
1794 //=======================================================================
1796 SMESH::ListOfGroups*
1797 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1798 const SMESH::DirStruct & theStepVector,
1799 CORBA::Long theNbOfSteps,
1800 const bool theMakeGroups,
1801 const SMDSAbs_ElementType theElementType)
1809 TIDSortedElemSet elements;
1810 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1812 const SMESH::PointStruct * P = &theStepVector.PS;
1813 gp_Vec stepVec( P->x, P->y, P->z );
1815 TElemOfElemListMap aHystory;
1816 ::SMESH_MeshEditor anEditor( myMesh );
1817 ::SMESH_MeshEditor::PGroupIDs groupIds =
1818 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1820 myMesh->GetMeshDS()->Modified();
1821 storeResult(anEditor);
1823 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1825 } catch(Standard_Failure) {
1826 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1827 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1832 //=======================================================================
1833 //function : ExtrusionSweep
1835 //=======================================================================
1837 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1838 const SMESH::DirStruct & theStepVector,
1839 CORBA::Long theNbOfSteps)
1841 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1842 if (!myPreviewMode) {
1843 TPythonDump() << this << ".ExtrusionSweep( "
1844 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1849 //=======================================================================
1850 //function : ExtrusionSweepObject
1852 //=======================================================================
1854 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1855 const SMESH::DirStruct & theStepVector,
1856 CORBA::Long theNbOfSteps)
1858 SMESH::long_array_var anElementsId = theObject->GetIDs();
1859 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1860 if (!myPreviewMode) {
1861 TPythonDump() << this << ".ExtrusionSweepObject( "
1862 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1866 //=======================================================================
1867 //function : ExtrusionSweepObject1D
1869 //=======================================================================
1871 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1872 const SMESH::DirStruct & theStepVector,
1873 CORBA::Long theNbOfSteps)
1875 SMESH::long_array_var anElementsId = theObject->GetIDs();
1876 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1877 if ( !myPreviewMode ) {
1878 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1879 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1883 //=======================================================================
1884 //function : ExtrusionSweepObject2D
1886 //=======================================================================
1888 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1889 const SMESH::DirStruct & theStepVector,
1890 CORBA::Long theNbOfSteps)
1892 SMESH::long_array_var anElementsId = theObject->GetIDs();
1893 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1894 if ( !myPreviewMode ) {
1895 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1896 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1900 //=======================================================================
1901 //function : ExtrusionSweepMakeGroups
1903 //=======================================================================
1905 SMESH::ListOfGroups*
1906 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1907 const SMESH::DirStruct& theStepVector,
1908 CORBA::Long theNbOfSteps)
1910 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1912 SMESH::ListOfGroups* aGroups = extrusionSweep(theIDsOfElements, theStepVector, theNbOfSteps, true);
1914 if (!myPreviewMode) {
1915 DumpGroupsList(aPythonDump, aGroups);
1916 aPythonDump << this << ".ExtrusionSweepMakeGroups( " << theIDsOfElements
1917 << ", " << theStepVector <<", " << theNbOfSteps << " )";
1922 //=======================================================================
1923 //function : ExtrusionSweepObjectMakeGroups
1925 //=======================================================================
1927 SMESH::ListOfGroups*
1928 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1929 const SMESH::DirStruct& theStepVector,
1930 CORBA::Long theNbOfSteps)
1932 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1934 SMESH::long_array_var anElementsId = theObject->GetIDs();
1935 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector, theNbOfSteps, true);
1937 if (!myPreviewMode) {
1938 DumpGroupsList(aPythonDump, aGroups);
1939 aPythonDump << this << ".ExtrusionSweepObjectMakeGroups( " << theObject
1940 << ", " << theStepVector << ", " << theNbOfSteps << " )";
1945 //=======================================================================
1946 //function : ExtrusionSweepObject1DMakeGroups
1948 //=======================================================================
1950 SMESH::ListOfGroups*
1951 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1952 const SMESH::DirStruct& theStepVector,
1953 CORBA::Long theNbOfSteps)
1955 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1957 SMESH::long_array_var anElementsId = theObject->GetIDs();
1958 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector,
1959 theNbOfSteps, true, SMDSAbs_Edge);
1960 if (!myPreviewMode) {
1961 DumpGroupsList(aPythonDump, aGroups);
1962 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( " << theObject
1963 << ", " << theStepVector << ", " << theNbOfSteps << " )";
1968 //=======================================================================
1969 //function : ExtrusionSweepObject2DMakeGroups
1971 //=======================================================================
1973 SMESH::ListOfGroups*
1974 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1975 const SMESH::DirStruct& theStepVector,
1976 CORBA::Long theNbOfSteps)
1978 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
1980 SMESH::long_array_var anElementsId = theObject->GetIDs();
1981 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector,
1982 theNbOfSteps, true, SMDSAbs_Face);
1983 if (!myPreviewMode) {
1984 DumpGroupsList(aPythonDump, aGroups);
1985 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( " << theObject
1986 << ", " << theStepVector << ", " << theNbOfSteps << " )";
1992 //=======================================================================
1993 //function : advancedExtrusion
1995 //=======================================================================
1997 SMESH::ListOfGroups*
1998 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1999 const SMESH::DirStruct & theStepVector,
2000 CORBA::Long theNbOfSteps,
2001 CORBA::Long theExtrFlags,
2002 CORBA::Double theSewTolerance,
2003 const bool theMakeGroups)
2007 TIDSortedElemSet elements;
2008 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2010 const SMESH::PointStruct * P = &theStepVector.PS;
2011 gp_Vec stepVec( P->x, P->y, P->z );
2013 ::SMESH_MeshEditor anEditor( myMesh );
2014 TElemOfElemListMap aHystory;
2015 ::SMESH_MeshEditor::PGroupIDs groupIds =
2016 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
2017 theMakeGroups, theExtrFlags, theSewTolerance);
2018 storeResult(anEditor);
2020 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2023 //=======================================================================
2024 //function : AdvancedExtrusion
2026 //=======================================================================
2028 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
2029 const SMESH::DirStruct & theStepVector,
2030 CORBA::Long theNbOfSteps,
2031 CORBA::Long theExtrFlags,
2032 CORBA::Double theSewTolerance)
2034 if ( !myPreviewMode ) {
2035 TPythonDump() << "stepVector = " << theStepVector;
2036 TPythonDump() << this << ".AdvancedExtrusion("
2039 << theNbOfSteps << ","
2040 << theExtrFlags << ", "
2041 << theSewTolerance << " )";
2043 advancedExtrusion( theIDsOfElements,
2051 //=======================================================================
2052 //function : AdvancedExtrusionMakeGroups
2054 //=======================================================================
2055 SMESH::ListOfGroups*
2056 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
2057 const SMESH::DirStruct& theStepVector,
2058 CORBA::Long theNbOfSteps,
2059 CORBA::Long theExtrFlags,
2060 CORBA::Double theSewTolerance)
2062 if (!myPreviewMode) {
2063 TPythonDump() << "stepVector = " << theStepVector;
2065 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2067 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
2074 if (!myPreviewMode) {
2075 DumpGroupsList(aPythonDump, aGroups);
2076 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
2079 << theNbOfSteps << ","
2080 << theExtrFlags << ", "
2081 << theSewTolerance << " )";
2087 //================================================================================
2089 * \brief Convert extrusion error to IDL enum
2091 //================================================================================
2093 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2095 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
2099 RETCASE( EXTR_NO_ELEMENTS );
2100 RETCASE( EXTR_PATH_NOT_EDGE );
2101 RETCASE( EXTR_BAD_PATH_SHAPE );
2102 RETCASE( EXTR_BAD_STARTING_NODE );
2103 RETCASE( EXTR_BAD_ANGLES_NUMBER );
2104 RETCASE( EXTR_CANT_GET_TANGENT );
2106 return SMESH::SMESH_MeshEditor::EXTR_OK;
2110 //=======================================================================
2111 //function : extrusionAlongPath
2113 //=======================================================================
2114 SMESH::ListOfGroups*
2115 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2116 SMESH::SMESH_Mesh_ptr thePathMesh,
2117 GEOM::GEOM_Object_ptr thePathShape,
2118 CORBA::Long theNodeStart,
2119 CORBA::Boolean theHasAngles,
2120 const SMESH::double_array & theAngles,
2121 CORBA::Boolean theHasRefPoint,
2122 const SMESH::PointStruct & theRefPoint,
2123 const bool theMakeGroups,
2124 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
2125 const SMDSAbs_ElementType theElementType)
2127 MESSAGE("extrusionAlongPath");
2130 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
2131 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2134 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2136 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2137 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2139 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
2140 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2144 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
2146 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2150 TIDSortedElemSet elements;
2151 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
2153 list<double> angles;
2154 for (int i = 0; i < theAngles.length(); i++) {
2155 angles.push_back( theAngles[i] );
2158 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
2160 int nbOldGroups = myMesh->NbGroup();
2162 ::SMESH_MeshEditor anEditor( myMesh );
2163 ::SMESH_MeshEditor::Extrusion_Error error =
2164 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
2165 theHasAngles, angles, false,
2166 theHasRefPoint, refPnt, theMakeGroups );
2167 myMesh->GetMeshDS()->Modified();
2168 storeResult(anEditor);
2169 theError = convExtrError( error );
2171 if ( theMakeGroups ) {
2172 list<int> groupIDs = myMesh->GetGroupIds();
2173 list<int>::iterator newBegin = groupIDs.begin();
2174 std::advance( newBegin, nbOldGroups ); // skip old groups
2175 groupIDs.erase( groupIDs.begin(), newBegin );
2176 return getGroups( & groupIDs );
2182 //=======================================================================
2183 //function : extrusionAlongPathX
2185 //=======================================================================
2186 SMESH::ListOfGroups*
2187 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2188 SMESH::SMESH_IDSource_ptr Path,
2189 CORBA::Long NodeStart,
2190 CORBA::Boolean HasAngles,
2191 const SMESH::double_array& Angles,
2192 CORBA::Boolean LinearVariation,
2193 CORBA::Boolean HasRefPoint,
2194 const SMESH::PointStruct& RefPoint,
2195 const bool MakeGroups,
2196 const SMDSAbs_ElementType ElementType,
2197 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2199 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2203 list<double> angles;
2204 for (int i = 0; i < Angles.length(); i++) {
2205 angles.push_back( Angles[i] );
2207 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2208 int nbOldGroups = myMesh->NbGroup();
2210 if ( Path->_is_nil() ) {
2211 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2215 TIDSortedElemSet elements;
2216 arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
2218 ::SMESH_MeshEditor anEditor( myMesh );
2219 ::SMESH_MeshEditor::Extrusion_Error error;
2221 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
2224 SMDS_MeshNode* aNodeStart =
2225 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2226 if ( !aNodeStart ) {
2227 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2230 error = anEditor.ExtrusionAlongTrack( elements, &(aMeshImp->GetImpl()), aNodeStart,
2231 HasAngles, angles, LinearVariation,
2232 HasRefPoint, refPnt, MakeGroups );
2233 myMesh->GetMeshDS()->Modified();
2236 SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
2239 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
2240 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
2241 SMDS_MeshNode* aNodeStart =
2242 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2243 if ( !aNodeStart ) {
2244 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2247 SMESH_subMesh* aSubMesh =
2248 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
2249 error = anEditor.ExtrusionAlongTrack( elements, aSubMesh, aNodeStart,
2250 HasAngles, angles, LinearVariation,
2251 HasRefPoint, refPnt, MakeGroups );
2252 myMesh->GetMeshDS()->Modified();
2255 SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
2257 // path as group of 1D elements
2261 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2267 storeResult(anEditor);
2268 Error = convExtrError( error );
2271 list<int> groupIDs = myMesh->GetGroupIds();
2272 list<int>::iterator newBegin = groupIDs.begin();
2273 std::advance( newBegin, nbOldGroups ); // skip old groups
2274 groupIDs.erase( groupIDs.begin(), newBegin );
2275 return getGroups( & groupIDs );
2281 //=======================================================================
2282 //function : ExtrusionAlongPath
2284 //=======================================================================
2285 SMESH::SMESH_MeshEditor::Extrusion_Error
2286 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2287 SMESH::SMESH_Mesh_ptr thePathMesh,
2288 GEOM::GEOM_Object_ptr thePathShape,
2289 CORBA::Long theNodeStart,
2290 CORBA::Boolean theHasAngles,
2291 const SMESH::double_array & theAngles,
2292 CORBA::Boolean theHasRefPoint,
2293 const SMESH::PointStruct & theRefPoint)
2295 MESSAGE("ExtrusionAlongPath");
2296 if ( !myPreviewMode ) {
2297 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
2298 << theIDsOfElements << ", "
2299 << thePathMesh << ", "
2300 << thePathShape << ", "
2301 << theNodeStart << ", "
2302 << theHasAngles << ", "
2303 << theAngles << ", "
2304 << theHasRefPoint << ", "
2305 << "SMESH.PointStruct( "
2306 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2307 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2308 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2310 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2311 extrusionAlongPath( theIDsOfElements,
2324 //=======================================================================
2325 //function : ExtrusionAlongPathObject
2327 //=======================================================================
2328 SMESH::SMESH_MeshEditor::Extrusion_Error
2329 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
2330 SMESH::SMESH_Mesh_ptr thePathMesh,
2331 GEOM::GEOM_Object_ptr thePathShape,
2332 CORBA::Long theNodeStart,
2333 CORBA::Boolean theHasAngles,
2334 const SMESH::double_array & theAngles,
2335 CORBA::Boolean theHasRefPoint,
2336 const SMESH::PointStruct & theRefPoint)
2338 if ( !myPreviewMode ) {
2339 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
2340 << theObject << ", "
2341 << thePathMesh << ", "
2342 << thePathShape << ", "
2343 << theNodeStart << ", "
2344 << theHasAngles << ", "
2345 << theAngles << ", "
2346 << theHasRefPoint << ", "
2347 << "SMESH.PointStruct( "
2348 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2349 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2350 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2352 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2353 SMESH::long_array_var anElementsId = theObject->GetIDs();
2354 extrusionAlongPath( anElementsId,
2367 //=======================================================================
2368 //function : ExtrusionAlongPathObject1D
2370 //=======================================================================
2371 SMESH::SMESH_MeshEditor::Extrusion_Error
2372 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
2373 SMESH::SMESH_Mesh_ptr thePathMesh,
2374 GEOM::GEOM_Object_ptr thePathShape,
2375 CORBA::Long theNodeStart,
2376 CORBA::Boolean theHasAngles,
2377 const SMESH::double_array & theAngles,
2378 CORBA::Boolean theHasRefPoint,
2379 const SMESH::PointStruct & theRefPoint)
2381 if ( !myPreviewMode ) {
2382 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
2383 << theObject << ", "
2384 << thePathMesh << ", "
2385 << thePathShape << ", "
2386 << theNodeStart << ", "
2387 << theHasAngles << ", "
2388 << theAngles << ", "
2389 << theHasRefPoint << ", "
2390 << "SMESH.PointStruct( "
2391 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2392 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2393 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2395 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2396 SMESH::long_array_var anElementsId = theObject->GetIDs();
2397 extrusionAlongPath( anElementsId,
2411 //=======================================================================
2412 //function : ExtrusionAlongPathObject2D
2414 //=======================================================================
2415 SMESH::SMESH_MeshEditor::Extrusion_Error
2416 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
2417 SMESH::SMESH_Mesh_ptr thePathMesh,
2418 GEOM::GEOM_Object_ptr thePathShape,
2419 CORBA::Long theNodeStart,
2420 CORBA::Boolean theHasAngles,
2421 const SMESH::double_array & theAngles,
2422 CORBA::Boolean theHasRefPoint,
2423 const SMESH::PointStruct & theRefPoint)
2425 if ( !myPreviewMode ) {
2426 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
2427 << theObject << ", "
2428 << thePathMesh << ", "
2429 << thePathShape << ", "
2430 << theNodeStart << ", "
2431 << theHasAngles << ", "
2432 << theAngles << ", "
2433 << theHasRefPoint << ", "
2434 << "SMESH.PointStruct( "
2435 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2436 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2437 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2439 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2440 SMESH::long_array_var anElementsId = theObject->GetIDs();
2441 extrusionAlongPath( anElementsId,
2456 //=======================================================================
2457 //function : ExtrusionAlongPathMakeGroups
2459 //=======================================================================
2460 SMESH::ListOfGroups*
2461 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2462 SMESH::SMESH_Mesh_ptr thePathMesh,
2463 GEOM::GEOM_Object_ptr thePathShape,
2464 CORBA::Long theNodeStart,
2465 CORBA::Boolean theHasAngles,
2466 const SMESH::double_array& theAngles,
2467 CORBA::Boolean theHasRefPoint,
2468 const SMESH::PointStruct& theRefPoint,
2469 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2471 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2473 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2483 if (!myPreviewMode) {
2484 bool isDumpGroups = aGroups && aGroups->length() > 0;
2486 aPythonDump << "(" << aGroups << ", error)";
2488 aPythonDump <<"error";
2490 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2491 << theIDsOfElements << ", "
2492 << thePathMesh << ", "
2493 << thePathShape << ", "
2494 << theNodeStart << ", "
2495 << theHasAngles << ", "
2496 << theAngles << ", "
2497 << theHasRefPoint << ", "
2498 << "SMESH.PointStruct( "
2499 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2500 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2501 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2506 //=======================================================================
2507 //function : ExtrusionAlongPathObjectMakeGroups
2509 //=======================================================================
2510 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2511 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2512 SMESH::SMESH_Mesh_ptr thePathMesh,
2513 GEOM::GEOM_Object_ptr thePathShape,
2514 CORBA::Long theNodeStart,
2515 CORBA::Boolean theHasAngles,
2516 const SMESH::double_array& theAngles,
2517 CORBA::Boolean theHasRefPoint,
2518 const SMESH::PointStruct& theRefPoint,
2519 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2521 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2523 SMESH::long_array_var anElementsId = theObject->GetIDs();
2524 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2535 if (!myPreviewMode) {
2536 bool isDumpGroups = aGroups && aGroups->length() > 0;
2538 aPythonDump << "(" << aGroups << ", error)";
2540 aPythonDump <<"error";
2542 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2543 << theObject << ", "
2544 << thePathMesh << ", "
2545 << thePathShape << ", "
2546 << theNodeStart << ", "
2547 << theHasAngles << ", "
2548 << theAngles << ", "
2549 << theHasRefPoint << ", "
2550 << "SMESH.PointStruct( "
2551 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2552 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2553 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2558 //=======================================================================
2559 //function : ExtrusionAlongPathObject1DMakeGroups
2561 //=======================================================================
2562 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2563 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2564 SMESH::SMESH_Mesh_ptr thePathMesh,
2565 GEOM::GEOM_Object_ptr thePathShape,
2566 CORBA::Long theNodeStart,
2567 CORBA::Boolean theHasAngles,
2568 const SMESH::double_array& theAngles,
2569 CORBA::Boolean theHasRefPoint,
2570 const SMESH::PointStruct& theRefPoint,
2571 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2573 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2575 SMESH::long_array_var anElementsId = theObject->GetIDs();
2576 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2588 if (!myPreviewMode) {
2589 bool isDumpGroups = aGroups && aGroups->length() > 0;
2591 aPythonDump << "(" << aGroups << ", error)";
2593 aPythonDump << "error";
2595 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
2596 << theObject << ", "
2597 << thePathMesh << ", "
2598 << thePathShape << ", "
2599 << theNodeStart << ", "
2600 << theHasAngles << ", "
2601 << theAngles << ", "
2602 << theHasRefPoint << ", "
2603 << "SMESH.PointStruct( "
2604 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2605 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2606 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2611 //=======================================================================
2612 //function : ExtrusionAlongPathObject2DMakeGroups
2614 //=======================================================================
2615 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2616 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2617 SMESH::SMESH_Mesh_ptr thePathMesh,
2618 GEOM::GEOM_Object_ptr thePathShape,
2619 CORBA::Long theNodeStart,
2620 CORBA::Boolean theHasAngles,
2621 const SMESH::double_array& theAngles,
2622 CORBA::Boolean theHasRefPoint,
2623 const SMESH::PointStruct& theRefPoint,
2624 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2626 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2628 SMESH::long_array_var anElementsId = theObject->GetIDs();
2629 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2641 if (!myPreviewMode) {
2642 bool isDumpGroups = aGroups && aGroups->length() > 0;
2644 aPythonDump << "(" << aGroups << ", error)";
2646 aPythonDump << "error";
2648 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
2649 << theObject << ", "
2650 << thePathMesh << ", "
2651 << thePathShape << ", "
2652 << theNodeStart << ", "
2653 << theHasAngles << ", "
2654 << theAngles << ", "
2655 << theHasRefPoint << ", "
2656 << "SMESH.PointStruct( "
2657 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2658 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2659 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2665 //=======================================================================
2666 //function : ExtrusionAlongPathObjX
2668 //=======================================================================
2669 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2670 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
2671 SMESH::SMESH_IDSource_ptr Path,
2672 CORBA::Long NodeStart,
2673 CORBA::Boolean HasAngles,
2674 const SMESH::double_array& Angles,
2675 CORBA::Boolean LinearVariation,
2676 CORBA::Boolean HasRefPoint,
2677 const SMESH::PointStruct& RefPoint,
2678 CORBA::Boolean MakeGroups,
2679 SMESH::ElementType ElemType,
2680 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2682 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2684 SMESH::long_array_var anElementsId = Object->GetIDs();
2685 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2694 (SMDSAbs_ElementType)ElemType,
2697 if (!myPreviewMode) {
2698 bool isDumpGroups = aGroups && aGroups->length() > 0;
2700 aPythonDump << "(" << *aGroups << ", error)";
2702 aPythonDump << "error";
2704 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2707 << NodeStart << ", "
2708 << HasAngles << ", "
2710 << LinearVariation << ", "
2711 << HasRefPoint << ", "
2712 << "SMESH.PointStruct( "
2713 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2714 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2715 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2716 << MakeGroups << ", "
2717 << ElemType << " )";
2723 //=======================================================================
2724 //function : ExtrusionAlongPathX
2726 //=======================================================================
2727 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2728 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2729 SMESH::SMESH_IDSource_ptr Path,
2730 CORBA::Long NodeStart,
2731 CORBA::Boolean HasAngles,
2732 const SMESH::double_array& Angles,
2733 CORBA::Boolean LinearVariation,
2734 CORBA::Boolean HasRefPoint,
2735 const SMESH::PointStruct& RefPoint,
2736 CORBA::Boolean MakeGroups,
2737 SMESH::ElementType ElemType,
2738 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2740 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2742 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2751 (SMDSAbs_ElementType)ElemType,
2754 if (!myPreviewMode) {
2755 bool isDumpGroups = aGroups && aGroups->length() > 0;
2757 aPythonDump << "(" << *aGroups << ", error)";
2759 aPythonDump <<"error";
2761 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2762 << IDsOfElements << ", "
2764 << NodeStart << ", "
2765 << HasAngles << ", "
2767 << LinearVariation << ", "
2768 << HasRefPoint << ", "
2769 << "SMESH.PointStruct( "
2770 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2771 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2772 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2773 << MakeGroups << ", "
2774 << ElemType << " )";
2780 //================================================================================
2782 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2783 * of given angles along path steps
2784 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2785 * which proceeds the extrusion
2786 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2787 * is used to define the sub-mesh for the path
2789 //================================================================================
2791 SMESH::double_array*
2792 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2793 GEOM::GEOM_Object_ptr thePathShape,
2794 const SMESH::double_array & theAngles)
2796 SMESH::double_array_var aResult = new SMESH::double_array();
2797 int nbAngles = theAngles.length();
2798 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2800 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2801 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2802 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2803 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2804 return aResult._retn();
2805 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2806 if ( nbSteps == nbAngles )
2808 aResult.inout() = theAngles;
2812 aResult->length( nbSteps );
2813 double rAn2St = double( nbAngles ) / double( nbSteps );
2814 double angPrev = 0, angle;
2815 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2817 double angCur = rAn2St * ( iSt+1 );
2818 double angCurFloor = floor( angCur );
2819 double angPrevFloor = floor( angPrev );
2820 if ( angPrevFloor == angCurFloor )
2821 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2824 int iP = int( angPrevFloor );
2825 double angPrevCeil = ceil(angPrev);
2826 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2828 int iC = int( angCurFloor );
2829 if ( iC < nbAngles )
2830 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2832 iP = int( angPrevCeil );
2834 angle += theAngles[ iC ];
2836 aResult[ iSt ] = angle;
2841 // Update Python script
2842 TPythonDump() << "rotAngles = " << theAngles;
2843 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2844 << thePathMesh << ", "
2845 << thePathShape << ", "
2848 return aResult._retn();
2852 //=======================================================================
2855 //=======================================================================
2857 SMESH::ListOfGroups*
2858 SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements,
2859 const SMESH::AxisStruct & theAxis,
2860 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2861 CORBA::Boolean theCopy,
2862 const bool theMakeGroups,
2863 ::SMESH_Mesh* theTargetMesh)
2867 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2868 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2871 switch ( theMirrorType ) {
2872 case SMESH::SMESH_MeshEditor::POINT:
2873 aTrsf.SetMirror( P );
2875 case SMESH::SMESH_MeshEditor::AXIS:
2876 aTrsf.SetMirror( gp_Ax1( P, V ));
2879 aTrsf.SetMirror( gp_Ax2( P, V ));
2882 ::SMESH_MeshEditor anEditor( myMesh );
2883 ::SMESH_MeshEditor::PGroupIDs groupIds =
2884 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2887 storeResult(anEditor);
2890 myMesh->GetMeshDS()->Modified();
2891 myMesh->SetIsModified( true );
2894 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2897 //=======================================================================
2900 //=======================================================================
2902 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2903 const SMESH::AxisStruct & theAxis,
2904 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2905 CORBA::Boolean theCopy)
2907 if ( !myPreviewMode ) {
2908 TPythonDump() << this << ".Mirror( "
2909 << theIDsOfElements << ", "
2911 << mirrorTypeName(theMirrorType) << ", "
2914 if ( theIDsOfElements.length() > 0 )
2916 TIDSortedElemSet elements;
2917 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2918 mirror(elements, theAxis, theMirrorType, theCopy, false);
2923 //=======================================================================
2924 //function : MirrorObject
2926 //=======================================================================
2928 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2929 const SMESH::AxisStruct & theAxis,
2930 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2931 CORBA::Boolean theCopy)
2933 if ( !myPreviewMode ) {
2934 TPythonDump() << this << ".MirrorObject( "
2935 << theObject << ", "
2937 << mirrorTypeName(theMirrorType) << ", "
2940 TIDSortedElemSet elements;
2941 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2942 mirror(elements, theAxis, theMirrorType, theCopy, false);
2945 //=======================================================================
2946 //function : MirrorMakeGroups
2948 //=======================================================================
2950 SMESH::ListOfGroups*
2951 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2952 const SMESH::AxisStruct& theMirror,
2953 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2955 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2957 SMESH::ListOfGroups * aGroups = 0;
2958 if ( theIDsOfElements.length() > 0 )
2960 TIDSortedElemSet elements;
2961 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2962 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2964 if (!myPreviewMode) {
2965 DumpGroupsList(aPythonDump, aGroups);
2966 aPythonDump << this << ".MirrorMakeGroups( "
2967 << theIDsOfElements << ", "
2968 << theMirror << ", "
2969 << mirrorTypeName(theMirrorType) << " )";
2974 //=======================================================================
2975 //function : MirrorObjectMakeGroups
2977 //=======================================================================
2979 SMESH::ListOfGroups*
2980 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2981 const SMESH::AxisStruct& theMirror,
2982 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2984 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2986 SMESH::ListOfGroups * aGroups = 0;
2987 TIDSortedElemSet elements;
2988 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2989 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2993 DumpGroupsList(aPythonDump,aGroups);
2994 aPythonDump << this << ".MirrorObjectMakeGroups( "
2995 << theObject << ", "
2996 << theMirror << ", "
2997 << mirrorTypeName(theMirrorType) << " )";
3002 //=======================================================================
3003 //function : MirrorMakeMesh
3005 //=======================================================================
3007 SMESH::SMESH_Mesh_ptr
3008 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
3009 const SMESH::AxisStruct& theMirror,
3010 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3011 CORBA::Boolean theCopyGroups,
3012 const char* theMeshName)
3014 SMESH_Mesh_i* mesh_i;
3015 SMESH::SMESH_Mesh_var mesh;
3016 { // open new scope to dump "MakeMesh" command
3017 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3019 TPythonDump pydump; // to prevent dump at mesh creation
3021 mesh = makeMesh( theMeshName );
3022 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3023 if (mesh_i && theIDsOfElements.length() > 0 )
3025 TIDSortedElemSet elements;
3026 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3027 mirror(elements, theMirror, theMirrorType,
3028 false, theCopyGroups, & mesh_i->GetImpl());
3029 mesh_i->CreateGroupServants();
3032 if (!myPreviewMode) {
3033 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
3034 << theIDsOfElements << ", "
3035 << theMirror << ", "
3036 << mirrorTypeName(theMirrorType) << ", "
3037 << theCopyGroups << ", '"
3038 << theMeshName << "' )";
3043 if (!myPreviewMode && mesh_i)
3044 mesh_i->GetGroups();
3046 return mesh._retn();
3049 //=======================================================================
3050 //function : MirrorObjectMakeMesh
3052 //=======================================================================
3054 SMESH::SMESH_Mesh_ptr
3055 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3056 const SMESH::AxisStruct& theMirror,
3057 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3058 CORBA::Boolean theCopyGroups,
3059 const char* theMeshName)
3061 SMESH_Mesh_i* mesh_i;
3062 SMESH::SMESH_Mesh_var mesh;
3063 { // open new scope to dump "MakeMesh" command
3064 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3066 TPythonDump pydump; // to prevent dump at mesh creation
3068 mesh = makeMesh( theMeshName );
3069 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3070 TIDSortedElemSet elements;
3072 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3074 mirror(elements, theMirror, theMirrorType,
3075 false, theCopyGroups, & mesh_i->GetImpl());
3076 mesh_i->CreateGroupServants();
3078 if (!myPreviewMode) {
3079 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
3080 << theObject << ", "
3081 << theMirror << ", "
3082 << mirrorTypeName(theMirrorType) << ", "
3083 << theCopyGroups << ", '"
3084 << theMeshName << "' )";
3089 if (!myPreviewMode && mesh_i)
3090 mesh_i->GetGroups();
3092 return mesh._retn();
3095 //=======================================================================
3096 //function : translate
3098 //=======================================================================
3100 SMESH::ListOfGroups*
3101 SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements,
3102 const SMESH::DirStruct & theVector,
3103 CORBA::Boolean theCopy,
3104 const bool theMakeGroups,
3105 ::SMESH_Mesh* theTargetMesh)
3110 const SMESH::PointStruct * P = &theVector.PS;
3111 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
3113 ::SMESH_MeshEditor anEditor( myMesh );
3114 ::SMESH_MeshEditor::PGroupIDs groupIds =
3115 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3118 storeResult(anEditor);
3121 myMesh->GetMeshDS()->Modified();
3122 myMesh->SetIsModified( true );
3125 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3128 //=======================================================================
3129 //function : Translate
3131 //=======================================================================
3133 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
3134 const SMESH::DirStruct & theVector,
3135 CORBA::Boolean theCopy)
3137 if (!myPreviewMode) {
3138 TPythonDump() << this << ".Translate( "
3139 << theIDsOfElements << ", "
3140 << theVector << ", "
3143 if (theIDsOfElements.length()) {
3144 TIDSortedElemSet elements;
3145 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3146 translate(elements, theVector, theCopy, false);
3150 //=======================================================================
3151 //function : TranslateObject
3153 //=======================================================================
3155 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
3156 const SMESH::DirStruct & theVector,
3157 CORBA::Boolean theCopy)
3159 if (!myPreviewMode) {
3160 TPythonDump() << this << ".TranslateObject( "
3161 << theObject << ", "
3162 << theVector << ", "
3165 TIDSortedElemSet elements;
3166 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3167 translate(elements, theVector, theCopy, false);
3170 //=======================================================================
3171 //function : TranslateMakeGroups
3173 //=======================================================================
3175 SMESH::ListOfGroups*
3176 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
3177 const SMESH::DirStruct& theVector)
3179 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3181 SMESH::ListOfGroups * aGroups = 0;
3182 if (theIDsOfElements.length()) {
3183 TIDSortedElemSet elements;
3184 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3185 aGroups = translate(elements,theVector,true,true);
3187 if (!myPreviewMode) {
3188 DumpGroupsList(aPythonDump, aGroups);
3189 aPythonDump << this << ".TranslateMakeGroups( "
3190 << theIDsOfElements << ", "
3191 << theVector << " )";
3196 //=======================================================================
3197 //function : TranslateObjectMakeGroups
3199 //=======================================================================
3201 SMESH::ListOfGroups*
3202 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3203 const SMESH::DirStruct& theVector)
3205 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3207 SMESH::ListOfGroups * aGroups = 0;
3208 TIDSortedElemSet elements;
3209 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3210 aGroups = translate(elements, theVector, true, true);
3212 if (!myPreviewMode) {
3213 DumpGroupsList(aPythonDump, aGroups);
3214 aPythonDump << this << ".TranslateObjectMakeGroups( "
3215 << theObject << ", "
3216 << theVector << " )";
3221 //=======================================================================
3222 //function : TranslateMakeMesh
3224 //=======================================================================
3226 SMESH::SMESH_Mesh_ptr
3227 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3228 const SMESH::DirStruct& theVector,
3229 CORBA::Boolean theCopyGroups,
3230 const char* theMeshName)
3232 SMESH_Mesh_i* mesh_i;
3233 SMESH::SMESH_Mesh_var mesh;
3235 { // open new scope to dump "MakeMesh" command
3236 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3238 TPythonDump pydump; // to prevent dump at mesh creation
3240 mesh = makeMesh( theMeshName );
3241 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3243 if ( mesh_i && theIDsOfElements.length() )
3245 TIDSortedElemSet elements;
3246 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3247 translate(elements, theVector, false, theCopyGroups, & mesh_i->GetImpl());
3248 mesh_i->CreateGroupServants();
3251 if ( !myPreviewMode ) {
3252 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3253 << theIDsOfElements << ", "
3254 << theVector << ", "
3255 << theCopyGroups << ", '"
3256 << theMeshName << "' )";
3261 if (!myPreviewMode && mesh_i)
3262 mesh_i->GetGroups();
3264 return mesh._retn();
3267 //=======================================================================
3268 //function : TranslateObjectMakeMesh
3270 //=======================================================================
3272 SMESH::SMESH_Mesh_ptr
3273 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3274 const SMESH::DirStruct& theVector,
3275 CORBA::Boolean theCopyGroups,
3276 const char* theMeshName)
3278 SMESH_Mesh_i* mesh_i;
3279 SMESH::SMESH_Mesh_var mesh;
3280 { // open new scope to dump "MakeMesh" command
3281 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3283 TPythonDump pydump; // to prevent dump at mesh creation
3284 mesh = makeMesh( theMeshName );
3285 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3287 TIDSortedElemSet elements;
3289 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3291 translate(elements, theVector,false, theCopyGroups, & mesh_i->GetImpl());
3292 mesh_i->CreateGroupServants();
3294 if ( !myPreviewMode ) {
3295 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3296 << theObject << ", "
3297 << theVector << ", "
3298 << theCopyGroups << ", '"
3299 << theMeshName << "' )";
3304 if (!myPreviewMode && mesh_i)
3305 mesh_i->GetGroups();
3307 return mesh._retn();
3310 //=======================================================================
3313 //=======================================================================
3315 SMESH::ListOfGroups*
3316 SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements,
3317 const SMESH::AxisStruct & theAxis,
3318 CORBA::Double theAngle,
3319 CORBA::Boolean theCopy,
3320 const bool theMakeGroups,
3321 ::SMESH_Mesh* theTargetMesh)
3325 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3326 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3329 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3331 ::SMESH_MeshEditor anEditor( myMesh );
3332 ::SMESH_MeshEditor::PGroupIDs groupIds =
3333 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3336 storeResult(anEditor);
3339 myMesh->GetMeshDS()->Modified();
3340 myMesh->SetIsModified( true );
3343 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3346 //=======================================================================
3349 //=======================================================================
3351 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3352 const SMESH::AxisStruct & theAxis,
3353 CORBA::Double theAngle,
3354 CORBA::Boolean theCopy)
3356 if (!myPreviewMode) {
3357 TPythonDump() << this << ".Rotate( "
3358 << theIDsOfElements << ", "
3363 if (theIDsOfElements.length() > 0)
3365 TIDSortedElemSet elements;
3366 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3367 rotate(elements,theAxis,theAngle,theCopy,false);
3371 //=======================================================================
3372 //function : RotateObject
3374 //=======================================================================
3376 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3377 const SMESH::AxisStruct & theAxis,
3378 CORBA::Double theAngle,
3379 CORBA::Boolean theCopy)
3381 if ( !myPreviewMode ) {
3382 TPythonDump() << this << ".RotateObject( "
3383 << theObject << ", "
3388 TIDSortedElemSet elements;
3389 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3390 rotate(elements,theAxis,theAngle,theCopy,false);
3393 //=======================================================================
3394 //function : RotateMakeGroups
3396 //=======================================================================
3398 SMESH::ListOfGroups*
3399 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3400 const SMESH::AxisStruct& theAxis,
3401 CORBA::Double theAngle)
3403 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3405 SMESH::ListOfGroups * aGroups = 0;
3406 if (theIDsOfElements.length() > 0)
3408 TIDSortedElemSet elements;
3409 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3410 aGroups = rotate(elements,theAxis,theAngle,true,true);
3412 if (!myPreviewMode) {
3413 DumpGroupsList(aPythonDump, aGroups);
3414 aPythonDump << this << ".RotateMakeGroups( "
3415 << theIDsOfElements << ", "
3417 << theAngle << " )";
3422 //=======================================================================
3423 //function : RotateObjectMakeGroups
3425 //=======================================================================
3427 SMESH::ListOfGroups*
3428 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3429 const SMESH::AxisStruct& theAxis,
3430 CORBA::Double theAngle)
3432 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3434 SMESH::ListOfGroups * aGroups = 0;
3435 TIDSortedElemSet elements;
3436 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3437 aGroups = rotate(elements, theAxis, theAngle, true, true);
3439 if (!myPreviewMode) {
3440 DumpGroupsList(aPythonDump, aGroups);
3441 aPythonDump << this << ".RotateObjectMakeGroups( "
3442 << theObject << ", "
3444 << theAngle << " )";
3449 //=======================================================================
3450 //function : RotateMakeMesh
3452 //=======================================================================
3454 SMESH::SMESH_Mesh_ptr
3455 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3456 const SMESH::AxisStruct& theAxis,
3457 CORBA::Double theAngleInRadians,
3458 CORBA::Boolean theCopyGroups,
3459 const char* theMeshName)
3461 SMESH::SMESH_Mesh_var mesh;
3462 SMESH_Mesh_i* mesh_i;
3464 { // open new scope to dump "MakeMesh" command
3465 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3467 TPythonDump pydump; // to prevent dump at mesh creation
3469 mesh = makeMesh( theMeshName );
3470 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3472 if ( mesh_i && theIDsOfElements.length() > 0 )
3474 TIDSortedElemSet elements;
3475 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3476 rotate(elements, theAxis, theAngleInRadians,
3477 false, theCopyGroups, & mesh_i->GetImpl());
3478 mesh_i->CreateGroupServants();
3480 if ( !myPreviewMode ) {
3481 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3482 << theIDsOfElements << ", "
3484 << theAngleInRadians << ", "
3485 << theCopyGroups << ", '"
3486 << theMeshName << "' )";
3491 if (!myPreviewMode && mesh_i && theIDsOfElements.length() > 0 )
3492 mesh_i->GetGroups();
3494 return mesh._retn();
3497 //=======================================================================
3498 //function : RotateObjectMakeMesh
3500 //=======================================================================
3502 SMESH::SMESH_Mesh_ptr
3503 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3504 const SMESH::AxisStruct& theAxis,
3505 CORBA::Double theAngleInRadians,
3506 CORBA::Boolean theCopyGroups,
3507 const char* theMeshName)
3509 SMESH::SMESH_Mesh_var mesh;
3510 SMESH_Mesh_i* mesh_i;
3512 {// open new scope to dump "MakeMesh" command
3513 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3515 TPythonDump pydump; // to prevent dump at mesh creation
3516 mesh = makeMesh( theMeshName );
3517 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3519 TIDSortedElemSet elements;
3521 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3523 rotate(elements, theAxis, theAngleInRadians,
3524 false, theCopyGroups, & mesh_i->GetImpl());
3525 mesh_i->CreateGroupServants();
3527 if ( !myPreviewMode ) {
3528 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3529 << theObject << ", "
3531 << theAngleInRadians << ", "
3532 << theCopyGroups << ", '"
3533 << theMeshName << "' )";
3538 if (!myPreviewMode && mesh_i)
3539 mesh_i->GetGroups();
3541 return mesh._retn();
3544 //=======================================================================
3547 //=======================================================================
3549 SMESH::ListOfGroups*
3550 SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject,
3551 const SMESH::PointStruct& thePoint,
3552 const SMESH::double_array& theScaleFact,
3553 CORBA::Boolean theCopy,
3554 const bool theMakeGroups,
3555 ::SMESH_Mesh* theTargetMesh)
3558 if ( theScaleFact.length() < 1 )
3559 THROW_SALOME_CORBA_EXCEPTION("Scale factor not given", SALOME::BAD_PARAM);
3560 if ( theScaleFact.length() == 2 )
3561 THROW_SALOME_CORBA_EXCEPTION("Invalid nb of scale factors : 2", SALOME::BAD_PARAM);
3563 TIDSortedElemSet elements;
3564 if ( !idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/true))
3567 vector<double> S(3);
3568 S[0] = theScaleFact[0];
3569 S[1] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1];
3570 S[2] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2];
3571 double tol = std::numeric_limits<double>::max();
3573 aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]),
3574 0, S[1], 0, thePoint.y * (1-S[1]),
3575 0, 0, S[2], thePoint.z * (1-S[2]), tol, tol);
3577 ::SMESH_MeshEditor anEditor( myMesh );
3578 ::SMESH_MeshEditor::PGroupIDs groupIds =
3579 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3582 storeResult(anEditor);
3585 myMesh->GetMeshDS()->Modified();
3586 myMesh->SetIsModified( true );
3588 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3591 //=======================================================================
3594 //=======================================================================
3596 void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr theObject,
3597 const SMESH::PointStruct& thePoint,
3598 const SMESH::double_array& theScaleFact,
3599 CORBA::Boolean theCopy)
3601 if ( !myPreviewMode ) {
3602 TPythonDump() << this << ".Scale( "
3603 << theObject << ", "
3604 << "SMESH.PointStruct( " << thePoint.x << ", "
3605 << thePoint.y << ", " << thePoint.z << " ) ,"
3606 << theScaleFact << ", "
3609 scale(theObject, thePoint, theScaleFact, theCopy, false);
3613 //=======================================================================
3614 //function : ScaleMakeGroups
3616 //=======================================================================
3618 SMESH::ListOfGroups*
3619 SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3620 const SMESH::PointStruct& thePoint,
3621 const SMESH::double_array& theScaleFact)
3623 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3625 SMESH::ListOfGroups * aGroups = scale(theObject, thePoint, theScaleFact, true, true);
3626 if (!myPreviewMode) {
3627 DumpGroupsList(aPythonDump, aGroups);
3628 aPythonDump << this << ".Scale("
3630 << "SMESH.PointStruct(" <<thePoint.x << ","
3631 << thePoint.y << "," << thePoint.z << "),"
3632 << theScaleFact << ",True,True)";
3638 //=======================================================================
3639 //function : ScaleMakeMesh
3641 //=======================================================================
3643 SMESH::SMESH_Mesh_ptr
3644 SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3645 const SMESH::PointStruct& thePoint,
3646 const SMESH::double_array& theScaleFact,
3647 CORBA::Boolean theCopyGroups,
3648 const char* theMeshName)
3650 SMESH_Mesh_i* mesh_i;
3651 SMESH::SMESH_Mesh_var mesh;
3652 { // open new scope to dump "MakeMesh" command
3653 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3655 TPythonDump pydump; // to prevent dump at mesh creation
3656 mesh = makeMesh( theMeshName );
3657 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3661 scale(theObject, thePoint, theScaleFact,false, theCopyGroups, & mesh_i->GetImpl());
3662 mesh_i->CreateGroupServants();
3664 if ( !myPreviewMode )
3665 pydump << mesh << " = " << this << ".ScaleMakeMesh( "
3666 << theObject << ", "
3667 << "SMESH.PointStruct( " << thePoint.x << ", "
3668 << thePoint.y << ", " << thePoint.z << " ) ,"
3669 << theScaleFact << ", "
3670 << theCopyGroups << ", '"
3671 << theMeshName << "' )";
3675 if (!myPreviewMode && mesh_i)
3676 mesh_i->GetGroups();
3678 return mesh._retn();
3682 //=======================================================================
3683 //function : FindCoincidentNodes
3685 //=======================================================================
3687 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3688 SMESH::array_of_long_array_out GroupsOfNodes)
3692 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3693 ::SMESH_MeshEditor anEditor( myMesh );
3694 TIDSortedNodeSet nodes; // no input nodes
3695 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3697 GroupsOfNodes = new SMESH::array_of_long_array;
3698 GroupsOfNodes->length( aListOfListOfNodes.size() );
3699 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3700 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3701 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3702 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3703 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3704 aGroup.length( aListOfNodes.size() );
3705 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3706 aGroup[ j ] = (*lIt)->GetID();
3708 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3709 << Tolerance << " )";
3712 //=======================================================================
3713 //function : FindCoincidentNodesOnPart
3715 //=======================================================================
3716 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3717 CORBA::Double Tolerance,
3718 SMESH::array_of_long_array_out GroupsOfNodes)
3722 TIDSortedNodeSet nodes;
3723 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3725 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3726 ::SMESH_MeshEditor anEditor( myMesh );
3728 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3730 GroupsOfNodes = new SMESH::array_of_long_array;
3731 GroupsOfNodes->length( aListOfListOfNodes.size() );
3732 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3733 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3735 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3736 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3737 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3738 aGroup.length( aListOfNodes.size() );
3739 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3740 aGroup[ j ] = (*lIt)->GetID();
3742 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3744 << Tolerance << " )";
3747 //================================================================================
3749 * \brief Finds nodes coinsident with Tolerance within Object excluding nodes within
3750 * ExceptSubMeshOrGroups
3752 //================================================================================
3754 void SMESH_MeshEditor_i::
3755 FindCoincidentNodesOnPartBut(SMESH::SMESH_IDSource_ptr theObject,
3756 CORBA::Double theTolerance,
3757 SMESH::array_of_long_array_out theGroupsOfNodes,
3758 const SMESH::ListOfIDSources& theExceptSubMeshOrGroups)
3762 TIDSortedNodeSet nodes;
3763 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3765 for ( int i = 0; i < theExceptSubMeshOrGroups.length(); ++i )
3767 TIDSortedNodeSet exceptNodes;
3768 idSourceToNodeSet( theExceptSubMeshOrGroups[i], GetMeshDS(), exceptNodes );
3769 TIDSortedNodeSet::iterator avoidNode = exceptNodes.begin();
3770 for ( ; avoidNode != exceptNodes.end(); ++avoidNode)
3771 nodes.erase( *avoidNode );
3773 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3774 ::SMESH_MeshEditor anEditor( myMesh );
3776 anEditor.FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes );
3778 theGroupsOfNodes = new SMESH::array_of_long_array;
3779 theGroupsOfNodes->length( aListOfListOfNodes.size() );
3780 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3781 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3783 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3784 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3785 SMESH::long_array& aGroup = (*theGroupsOfNodes)[ i ];
3786 aGroup.length( aListOfNodes.size() );
3787 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3788 aGroup[ j ] = (*lIt)->GetID();
3790 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPartBut( "
3792 << theTolerance << ", "
3793 << theExceptSubMeshOrGroups << " )";
3796 //=======================================================================
3797 //function : MergeNodes
3799 //=======================================================================
3801 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3805 SMESHDS_Mesh* aMesh = GetMeshDS();
3807 TPythonDump aTPythonDump;
3808 aTPythonDump << this << ".MergeNodes([";
3809 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3810 for (int i = 0; i < GroupsOfNodes.length(); i++)
3812 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3813 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3814 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3815 for ( int j = 0; j < aNodeGroup.length(); j++ )
3817 CORBA::Long index = aNodeGroup[ j ];
3818 const SMDS_MeshNode * node = aMesh->FindNode(index);
3820 aListOfNodes.push_back( node );
3822 if ( aListOfNodes.size() < 2 )
3823 aListOfListOfNodes.pop_back();
3825 if ( i > 0 ) aTPythonDump << ", ";
3826 aTPythonDump << aNodeGroup;
3828 ::SMESH_MeshEditor anEditor( myMesh );
3829 anEditor.MergeNodes( aListOfListOfNodes );
3831 aTPythonDump << "])";
3832 myMesh->GetMeshDS()->Modified();
3833 myMesh->SetIsModified( true );
3836 //=======================================================================
3837 //function : FindEqualElements
3839 //=======================================================================
3840 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3841 SMESH::array_of_long_array_out GroupsOfElementsID)
3845 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theObject);
3846 if ( !(!group->_is_nil() && group->GetType() == SMESH::NODE) )
3848 typedef list<int> TListOfIDs;
3849 set<const SMDS_MeshElement*> elems;
3850 SMESH::long_array_var aElementsId = theObject->GetIDs();
3851 SMESHDS_Mesh* aMesh = GetMeshDS();
3853 for(int i = 0; i < aElementsId->length(); i++) {
3854 CORBA::Long anID = aElementsId[i];
3855 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3861 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3862 ::SMESH_MeshEditor anEditor( myMesh );
3863 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3865 GroupsOfElementsID = new SMESH::array_of_long_array;
3866 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3868 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3869 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3870 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3871 TListOfIDs& listOfIDs = *arraysIt;
3872 aGroup.length( listOfIDs.size() );
3873 TListOfIDs::iterator idIt = listOfIDs.begin();
3874 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3875 aGroup[ k ] = *idIt;
3879 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3884 //=======================================================================
3885 //function : MergeElements
3887 //=======================================================================
3889 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3893 TPythonDump aTPythonDump;
3894 aTPythonDump << this << ".MergeElements( [";
3896 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3898 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3899 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3900 aListOfListOfElementsID.push_back( list< int >() );
3901 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3902 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3903 CORBA::Long id = anElemsIDGroup[ j ];
3904 aListOfElemsID.push_back( id );
3906 if ( aListOfElemsID.size() < 2 )
3907 aListOfListOfElementsID.pop_back();
3908 if ( i > 0 ) aTPythonDump << ", ";
3909 aTPythonDump << anElemsIDGroup;
3912 ::SMESH_MeshEditor anEditor( myMesh );
3913 anEditor.MergeElements(aListOfListOfElementsID);
3914 myMesh->GetMeshDS()->Modified();
3915 myMesh->SetIsModified( true );
3917 aTPythonDump << "] )";
3920 //=======================================================================
3921 //function : MergeEqualElements
3923 //=======================================================================
3925 void SMESH_MeshEditor_i::MergeEqualElements()
3929 ::SMESH_MeshEditor anEditor( myMesh );
3930 anEditor.MergeEqualElements();
3932 TPythonDump() << this << ".MergeEqualElements()";
3935 //=============================================================================
3937 * Move the node to a given point
3939 //=============================================================================
3941 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
3946 initData(/*deleteSearchers=*/false);
3948 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
3952 if ( theNodeSearcher )
3953 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3955 if ( myPreviewMode ) // make preview data
3957 // in a preview mesh, make edges linked to a node
3958 TPreviewMesh tmpMesh;
3959 TIDSortedElemSet linkedNodes;
3960 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3961 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3962 SMDS_MeshNode *nodeCpy1 = tmpMesh.Copy(node);
3963 for ( ; nIt != linkedNodes.end(); ++nIt )
3965 SMDS_MeshNode *nodeCpy2 = tmpMesh.Copy ( cast2Node( *nIt ));
3966 tmpMesh.GetMeshDS()->AddEdge(nodeCpy1, nodeCpy2);
3970 tmpMesh.GetMeshDS()->MoveNode(nodeCpy1, x, y, z);
3971 // fill preview data
3972 ::SMESH_MeshEditor anEditor( & tmpMesh );
3973 storeResult( anEditor );
3975 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3976 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3978 GetMeshDS()->MoveNode(node, x, y, z);
3980 if ( !myPreviewMode )
3982 // Update Python script
3983 TPythonDump() << "isDone = " << this << ".MoveNode( "
3984 << NodeID << ", " << x << ", " << y << ", " << z << " )";
3985 myMesh->GetMeshDS()->Modified();
3986 myMesh->SetIsModified( true );
3992 //================================================================================
3994 * \brief Return ID of node closest to a given point
3996 //================================================================================
3998 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
4002 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4004 if ( !theNodeSearcher ) {
4005 ::SMESH_MeshEditor anEditor( myMesh );
4006 theNodeSearcher = anEditor.GetNodeSearcher();
4009 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
4010 return node->GetID();
4015 //================================================================================
4017 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
4018 * move the node closest to the point to point's location and return ID of the node
4020 //================================================================================
4022 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
4025 CORBA::Long theNodeID)
4027 // We keep theNodeSearcher until any mesh modification:
4028 // 1) initData() deletes theNodeSearcher at any edition,
4029 // 2) TSearchersDeleter - at any mesh compute event and mesh change
4031 initData(/*deleteSearchers=*/false);
4033 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4035 int nodeID = theNodeID;
4036 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
4037 if ( !node ) // preview moving node
4039 if ( !theNodeSearcher ) {
4040 ::SMESH_MeshEditor anEditor( myMesh );
4041 theNodeSearcher = anEditor.GetNodeSearcher();
4044 node = theNodeSearcher->FindClosestTo( p );
4047 nodeID = node->GetID();
4048 if ( myPreviewMode ) // make preview data
4050 // in a preview mesh, make edges linked to a node
4051 TPreviewMesh tmpMesh;
4052 TIDSortedElemSet linkedNodes;
4053 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
4054 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
4055 for ( ; nIt != linkedNodes.end(); ++nIt )
4057 SMDS_LinearEdge edge( node, cast2Node( *nIt ));
4058 tmpMesh.Copy( &edge );
4061 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
4063 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
4064 // fill preview data
4065 ::SMESH_MeshEditor anEditor( & tmpMesh );
4066 storeResult( anEditor );
4068 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
4070 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
4074 GetMeshDS()->MoveNode(node, x, y, z);
4078 if ( !myPreviewMode )
4080 TPythonDump() << "nodeID = " << this
4081 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
4082 << ", " << nodeID << " )";
4084 myMesh->GetMeshDS()->Modified();
4085 myMesh->SetIsModified( true );
4091 //=======================================================================
4093 * Return elements of given type where the given point is IN or ON.
4095 * 'ALL' type means elements of any type excluding nodes
4097 //=======================================================================
4099 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
4102 SMESH::ElementType type)
4104 SMESH::long_array_var res = new SMESH::long_array;
4105 vector< const SMDS_MeshElement* > foundElems;
4107 theSearchersDeleter.Set( myMesh );
4108 if ( !theElementSearcher ) {
4109 ::SMESH_MeshEditor anEditor( myMesh );
4110 theElementSearcher = anEditor.GetElementSearcher();
4112 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
4113 SMDSAbs_ElementType( type ),
4115 res->length( foundElems.size() );
4116 for ( int i = 0; i < foundElems.size(); ++i )
4117 res[i] = foundElems[i]->GetID();
4119 if ( !myPreviewMode ) // call from tui
4120 TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
4129 //=======================================================================
4130 //function : GetPointState
4131 //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
4132 // TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
4133 //=======================================================================
4135 CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
4139 theSearchersDeleter.Set( myMesh );
4140 if ( !theElementSearcher ) {
4141 ::SMESH_MeshEditor anEditor( myMesh );
4142 theElementSearcher = anEditor.GetElementSearcher();
4144 return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
4147 //=======================================================================
4148 //function : convError
4150 //=======================================================================
4152 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
4154 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
4158 RETCASE( SEW_BORDER1_NOT_FOUND );
4159 RETCASE( SEW_BORDER2_NOT_FOUND );
4160 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
4161 RETCASE( SEW_BAD_SIDE_NODES );
4162 RETCASE( SEW_VOLUMES_TO_SPLIT );
4163 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
4164 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
4165 RETCASE( SEW_BAD_SIDE1_NODES );
4166 RETCASE( SEW_BAD_SIDE2_NODES );
4168 return SMESH::SMESH_MeshEditor::SEW_OK;
4171 //=======================================================================
4172 //function : SewFreeBorders
4174 //=======================================================================
4176 SMESH::SMESH_MeshEditor::Sew_Error
4177 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
4178 CORBA::Long SecondNodeID1,
4179 CORBA::Long LastNodeID1,
4180 CORBA::Long FirstNodeID2,
4181 CORBA::Long SecondNodeID2,
4182 CORBA::Long LastNodeID2,
4183 CORBA::Boolean CreatePolygons,
4184 CORBA::Boolean CreatePolyedrs)
4188 SMESHDS_Mesh* aMesh = GetMeshDS();
4190 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4191 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4192 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4193 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4194 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4195 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
4197 if (!aBorderFirstNode ||
4198 !aBorderSecondNode||
4200 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4201 if (!aSide2FirstNode ||
4202 !aSide2SecondNode ||
4204 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4206 TPythonDump() << "error = " << this << ".SewFreeBorders( "
4207 << FirstNodeID1 << ", "
4208 << SecondNodeID1 << ", "
4209 << LastNodeID1 << ", "
4210 << FirstNodeID2 << ", "
4211 << SecondNodeID2 << ", "
4212 << LastNodeID2 << ", "
4213 << CreatePolygons<< ", "
4214 << CreatePolyedrs<< " )";
4216 ::SMESH_MeshEditor anEditor( myMesh );
4217 SMESH::SMESH_MeshEditor::Sew_Error error =
4218 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4228 storeResult(anEditor);
4230 myMesh->GetMeshDS()->Modified();
4231 myMesh->SetIsModified( true );
4237 //=======================================================================
4238 //function : SewConformFreeBorders
4240 //=======================================================================
4242 SMESH::SMESH_MeshEditor::Sew_Error
4243 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
4244 CORBA::Long SecondNodeID1,
4245 CORBA::Long LastNodeID1,
4246 CORBA::Long FirstNodeID2,
4247 CORBA::Long SecondNodeID2)
4251 SMESHDS_Mesh* aMesh = GetMeshDS();
4253 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4254 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4255 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4256 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4257 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4258 const SMDS_MeshNode* aSide2ThirdNode = 0;
4260 if (!aBorderFirstNode ||
4261 !aBorderSecondNode||
4263 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4264 if (!aSide2FirstNode ||
4266 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4268 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
4269 << FirstNodeID1 << ", "
4270 << SecondNodeID1 << ", "
4271 << LastNodeID1 << ", "
4272 << FirstNodeID2 << ", "
4273 << SecondNodeID2 << " )";
4275 ::SMESH_MeshEditor anEditor( myMesh );
4276 SMESH::SMESH_MeshEditor::Sew_Error error =
4277 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4286 storeResult(anEditor);
4288 myMesh->GetMeshDS()->Modified();
4289 myMesh->SetIsModified( true );
4295 //=======================================================================
4296 //function : SewBorderToSide
4298 //=======================================================================
4300 SMESH::SMESH_MeshEditor::Sew_Error
4301 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
4302 CORBA::Long SecondNodeIDOnFreeBorder,
4303 CORBA::Long LastNodeIDOnFreeBorder,
4304 CORBA::Long FirstNodeIDOnSide,
4305 CORBA::Long LastNodeIDOnSide,
4306 CORBA::Boolean CreatePolygons,
4307 CORBA::Boolean CreatePolyedrs)
4311 SMESHDS_Mesh* aMesh = GetMeshDS();
4313 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
4314 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
4315 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
4316 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
4317 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
4318 const SMDS_MeshNode* aSide2ThirdNode = 0;
4320 if (!aBorderFirstNode ||
4321 !aBorderSecondNode||
4323 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4324 if (!aSide2FirstNode ||
4326 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
4328 TPythonDump() << "error = " << this << ".SewBorderToSide( "
4329 << FirstNodeIDOnFreeBorder << ", "
4330 << SecondNodeIDOnFreeBorder << ", "
4331 << LastNodeIDOnFreeBorder << ", "
4332 << FirstNodeIDOnSide << ", "
4333 << LastNodeIDOnSide << ", "
4334 << CreatePolygons << ", "
4335 << CreatePolyedrs << ") ";
4337 ::SMESH_MeshEditor anEditor( myMesh );
4338 SMESH::SMESH_MeshEditor::Sew_Error error =
4339 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4349 storeResult(anEditor);
4351 myMesh->GetMeshDS()->Modified();
4352 myMesh->SetIsModified( true );
4358 //=======================================================================
4359 //function : SewSideElements
4361 //=======================================================================
4363 SMESH::SMESH_MeshEditor::Sew_Error
4364 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
4365 const SMESH::long_array& IDsOfSide2Elements,
4366 CORBA::Long NodeID1OfSide1ToMerge,
4367 CORBA::Long NodeID1OfSide2ToMerge,
4368 CORBA::Long NodeID2OfSide1ToMerge,
4369 CORBA::Long NodeID2OfSide2ToMerge)
4373 SMESHDS_Mesh* aMesh = GetMeshDS();
4375 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
4376 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
4377 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
4378 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
4380 if (!aFirstNode1ToMerge ||
4381 !aFirstNode2ToMerge )
4382 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
4383 if (!aSecondNode1ToMerge||
4384 !aSecondNode2ToMerge)
4385 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
4387 TIDSortedElemSet aSide1Elems, aSide2Elems;
4388 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
4389 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
4391 TPythonDump() << "error = " << this << ".SewSideElements( "
4392 << IDsOfSide1Elements << ", "
4393 << IDsOfSide2Elements << ", "
4394 << NodeID1OfSide1ToMerge << ", "
4395 << NodeID1OfSide2ToMerge << ", "
4396 << NodeID2OfSide1ToMerge << ", "
4397 << NodeID2OfSide2ToMerge << ")";
4399 ::SMESH_MeshEditor anEditor( myMesh );
4400 SMESH::SMESH_MeshEditor::Sew_Error error =
4401 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
4404 aSecondNode1ToMerge,
4405 aSecondNode2ToMerge));
4407 storeResult(anEditor);
4409 myMesh->GetMeshDS()->Modified();
4410 myMesh->SetIsModified( true );
4415 //================================================================================
4417 * \brief Set new nodes for given element
4418 * \param ide - element id
4419 * \param newIDs - new node ids
4420 * \retval CORBA::Boolean - true if result is OK
4422 //================================================================================
4424 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
4425 const SMESH::long_array& newIDs)
4429 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
4430 if(!elem) return false;
4432 int nbn = newIDs.length();
4434 vector<const SMDS_MeshNode*> aNodes(nbn);
4437 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
4440 aNodes[nbn1] = aNode;
4443 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
4444 << ide << ", " << newIDs << " )";
4446 MESSAGE("ChangeElementNodes");
4447 bool res = GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
4449 myMesh->GetMeshDS()->Modified();
4451 myMesh->SetIsModified( true );
4456 //================================================================================
4458 * \brief Update myLastCreated* or myPreviewData
4459 * \param anEditor - it contains last modification results
4461 //================================================================================
4463 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
4465 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
4467 list<int> aNodesConnectivity;
4468 typedef map<int, int> TNodesMap;
4471 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
4472 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
4474 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
4475 int nbEdges = aMeshDS->NbEdges();
4476 int nbFaces = aMeshDS->NbFaces();
4477 int nbVolum = aMeshDS->NbVolumes();
4478 switch ( previewType ) {
4479 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
4480 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
4481 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
4484 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
4485 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
4487 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
4489 while ( itMeshElems->more() ) {
4490 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
4491 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
4494 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
4495 while ( itElemNodes->more() ) {
4496 const SMDS_MeshNode* aMeshNode =
4497 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
4498 int aNodeID = aMeshNode->GetID();
4499 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
4500 if ( anIter == nodesMap.end() ) {
4501 // filling the nodes coordinates
4502 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
4503 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
4504 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
4505 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4508 aNodesConnectivity.push_back(anIter->second);
4511 // filling the elements types
4512 SMDSAbs_ElementType aType;
4514 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4515 aType = SMDSAbs_Node;
4519 aType = aMeshElem->GetType();
4520 isPoly = aMeshElem->IsPoly();
4523 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4524 myPreviewData->elementTypes[i].isPoly = isPoly;
4525 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4529 myPreviewData->nodesXYZ.length( j );
4531 // filling the elements connectivities
4532 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4533 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4534 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4535 myPreviewData->elementConnectivities[i] = *aConnIter;
4541 // add new nodes into myLastCreatedNodes
4542 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4543 myLastCreatedNodes->length(aSeq.Length());
4544 for(int i=0; i<aSeq.Length(); i++)
4545 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4548 // add new elements into myLastCreatedElems
4549 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4550 myLastCreatedElems->length(aSeq.Length());
4551 for(int i=0; i<aSeq.Length(); i++)
4552 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4556 //================================================================================
4558 * Return data of mesh edition preview
4560 //================================================================================
4562 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4564 return myPreviewData._retn();
4567 //================================================================================
4569 * \brief Returns list of it's IDs of created nodes
4570 * \retval SMESH::long_array* - list of node ID
4572 //================================================================================
4574 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4576 return myLastCreatedNodes._retn();
4579 //================================================================================
4581 * \brief Returns list of it's IDs of created elements
4582 * \retval SMESH::long_array* - list of elements' ID
4584 //================================================================================
4586 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4588 return myLastCreatedElems._retn();
4591 //=======================================================================
4592 //function : ConvertToQuadratic
4594 //=======================================================================
4596 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4598 ::SMESH_MeshEditor anEditor( myMesh );
4599 anEditor.ConvertToQuadratic(theForce3d);
4600 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4601 myMesh->GetMeshDS()->Modified();
4602 myMesh->SetIsModified( true );
4605 //=======================================================================
4606 //function : ConvertFromQuadratic
4608 //=======================================================================
4610 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4612 ::SMESH_MeshEditor anEditor( myMesh );
4613 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4614 TPythonDump() << this << ".ConvertFromQuadratic()";
4615 myMesh->GetMeshDS()->Modified();
4617 myMesh->SetIsModified( true );
4621 //=======================================================================
4622 //function : makeMesh
4623 //purpose : create a named imported mesh
4624 //=======================================================================
4626 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4628 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4629 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4630 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4631 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4632 gen->SetName( meshSO, theMeshName, "Mesh" );
4633 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4635 return mesh._retn();
4638 //=======================================================================
4639 //function : DumpGroupsList
4641 //=======================================================================
4642 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4643 const SMESH::ListOfGroups * theGroupList)
4645 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4646 if(isDumpGroupList) {
4647 theDumpPython << theGroupList << " = ";
4651 //================================================================================
4653 \brief Generates the unique group name.
4654 \param thePrefix name prefix
4657 //================================================================================
4658 string SMESH_MeshEditor_i::generateGroupName(const string& thePrefix)
4660 SMESH::ListOfGroups_var groups = myMesh_i->GetGroups();
4661 set<string> groupNames;
4663 // Get existing group names
4664 for (int i = 0, nbGroups = groups->length(); i < nbGroups; i++ ) {
4665 SMESH::SMESH_GroupBase_var aGroup = groups[i];
4666 if (CORBA::is_nil(aGroup))
4669 groupNames.insert(aGroup->GetName());
4673 string name = thePrefix;
4676 while (!groupNames.insert(name).second) {
4681 TCollection_AsciiString nbStr(index+1);
4682 name.resize( name.rfind('_')+1 );
4683 name += nbStr.ToCString();
4691 //================================================================================
4693 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4694 \param theNodes - identifiers of nodes to be doubled
4695 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4696 nodes. If list of element identifiers is empty then nodes are doubled but
4697 they not assigned to elements
4698 \return TRUE if operation has been completed successfully, FALSE otherwise
4699 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4701 //================================================================================
4703 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4704 const SMESH::long_array& theModifiedElems )
4708 ::SMESH_MeshEditor aMeshEditor( myMesh );
4709 list< int > aListOfNodes;
4711 for ( i = 0, n = theNodes.length(); i < n; i++ )
4712 aListOfNodes.push_back( theNodes[ i ] );
4714 list< int > aListOfElems;
4715 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4716 aListOfElems.push_back( theModifiedElems[ i ] );
4718 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4720 myMesh->GetMeshDS()->Modified();
4721 storeResult( aMeshEditor) ;
4723 myMesh->SetIsModified( true );
4725 // Update Python script
4726 TPythonDump() << this << ".DoubleNodes( " << theNodes << ", "<< theModifiedElems << " )";
4731 //================================================================================
4733 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4734 This method provided for convenience works as DoubleNodes() described above.
4735 \param theNodeId - identifier of node to be doubled.
4736 \param theModifiedElems - identifiers of elements to be updated.
4737 \return TRUE if operation has been completed successfully, FALSE otherwise
4738 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4740 //================================================================================
4742 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4743 const SMESH::long_array& theModifiedElems )
4745 SMESH::long_array_var aNodes = new SMESH::long_array;
4746 aNodes->length( 1 );
4747 aNodes[ 0 ] = theNodeId;
4749 TPythonDump pyDump; // suppress dump by the next line
4751 CORBA::Boolean done = DoubleNodes( aNodes, theModifiedElems );
4753 pyDump << this << ".DoubleNode( " << theNodeId << ", " << theModifiedElems << " )";
4758 //================================================================================
4760 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4761 This method provided for convenience works as DoubleNodes() described above.
4762 \param theNodes - group of nodes to be doubled.
4763 \param theModifiedElems - group of elements to be updated.
4764 \return TRUE if operation has been completed successfully, FALSE otherwise
4765 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
4767 //================================================================================
4769 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(SMESH::SMESH_GroupBase_ptr theNodes,
4770 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4772 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4775 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4776 SMESH::long_array_var aModifiedElems;
4777 if ( !CORBA::is_nil( theModifiedElems ) )
4778 aModifiedElems = theModifiedElems->GetListOfID();
4781 aModifiedElems = new SMESH::long_array;
4782 aModifiedElems->length( 0 );
4785 TPythonDump pyDump; // suppress dump by the next line
4787 bool done = DoubleNodes( aNodes, aModifiedElems );
4789 pyDump << this << ".DoubleNodeGroup( " << theNodes << ", " << theModifiedElems << " )";
4795 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements.
4796 * Works as DoubleNodeGroup(), but returns a new group with newly created nodes.
4797 * \param theNodes - group of nodes to be doubled.
4798 * \param theModifiedElems - group of elements to be updated.
4799 * \return a new group with newly created nodes
4800 * \sa DoubleNodeGroup()
4802 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes,
4803 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4805 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4808 SMESH::SMESH_Group_var aNewGroup;
4811 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4812 SMESH::long_array_var aModifiedElems;
4813 if ( !CORBA::is_nil( theModifiedElems ) )
4814 aModifiedElems = theModifiedElems->GetListOfID();
4816 aModifiedElems = new SMESH::long_array;
4817 aModifiedElems->length( 0 );
4820 TPythonDump pyDump; // suppress dump by the next line
4822 bool aResult = DoubleNodes( aNodes, aModifiedElems );
4826 // Create group with newly created nodes
4827 SMESH::long_array_var anIds = GetLastCreatedNodes();
4828 if (anIds->length() > 0) {
4829 string anUnindexedName (theNodes->GetName());
4830 string aNewName = generateGroupName(anUnindexedName + "_double");
4831 aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
4832 aNewGroup->Add(anIds);
4836 pyDump << "createdNodes = " << this << ".DoubleNodeGroupNew( " << theNodes << ", "
4837 << theModifiedElems << " )";
4839 return aNewGroup._retn();
4842 //================================================================================
4844 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4845 This method provided for convenience works as DoubleNodes() described above.
4846 \param theNodes - list of groups of nodes to be doubled
4847 \param theModifiedElems - list of groups of elements to be updated.
4848 \return TRUE if operation has been completed successfully, FALSE otherwise
4849 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
4851 //================================================================================
4853 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& theNodes,
4854 const SMESH::ListOfGroups& theModifiedElems )
4858 ::SMESH_MeshEditor aMeshEditor( myMesh );
4860 std::list< int > aNodes;
4862 for ( i = 0, n = theNodes.length(); i < n; i++ )
4864 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
4865 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
4867 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4868 for ( j = 0, m = aCurr->length(); j < m; j++ )
4869 aNodes.push_back( aCurr[ j ] );
4873 std::list< int > anElems;
4874 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4876 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
4877 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
4879 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4880 for ( j = 0, m = aCurr->length(); j < m; j++ )
4881 anElems.push_back( aCurr[ j ] );
4885 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
4887 storeResult( aMeshEditor) ;
4889 myMesh->GetMeshDS()->Modified();
4891 myMesh->SetIsModified( true );
4894 TPythonDump() << this << ".DoubleNodeGroups( " << theNodes << ", " << theModifiedElems << " )";
4899 //================================================================================
4901 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4902 \param theElems - the list of elements (edges or faces) to be replicated
4903 The nodes for duplication could be found from these elements
4904 \param theNodesNot - list of nodes to NOT replicate
4905 \param theAffectedElems - the list of elements (cells and edges) to which the
4906 replicated nodes should be associated to.
4907 \return TRUE if operation has been completed successfully, FALSE otherwise
4908 \sa DoubleNodeGroup(), DoubleNodeGroups()
4910 //================================================================================
4912 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
4913 const SMESH::long_array& theNodesNot,
4914 const SMESH::long_array& theAffectedElems )
4919 ::SMESH_MeshEditor aMeshEditor( myMesh );
4921 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4922 TIDSortedElemSet anElems, aNodes, anAffected;
4923 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4924 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4925 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
4927 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4929 storeResult( aMeshEditor) ;
4931 myMesh->GetMeshDS()->Modified();
4933 myMesh->SetIsModified( true );
4935 // Update Python script
4936 TPythonDump() << this << ".DoubleNodeElem( " << theElems << ", "
4937 << theNodesNot << ", " << theAffectedElems << " )";
4941 //================================================================================
4943 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4944 \param theElems - the list of elements (edges or faces) to be replicated
4945 The nodes for duplication could be found from these elements
4946 \param theNodesNot - list of nodes to NOT replicate
4947 \param theShape - shape to detect affected elements (element which geometric center
4948 located on or inside shape).
4949 The replicated nodes should be associated to affected elements.
4950 \return TRUE if operation has been completed successfully, FALSE otherwise
4951 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
4953 //================================================================================
4955 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_array& theElems,
4956 const SMESH::long_array& theNodesNot,
4957 GEOM::GEOM_Object_ptr theShape )
4962 ::SMESH_MeshEditor aMeshEditor( myMesh );
4964 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4965 TIDSortedElemSet anElems, aNodes;
4966 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4967 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4969 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4970 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4972 storeResult( aMeshEditor) ;
4974 myMesh->GetMeshDS()->Modified();
4976 myMesh->SetIsModified( true );
4978 // Update Python script
4979 TPythonDump() << "isDone = " << this << ".DoubleNodeElemInRegion( " << theElems << ", "
4980 << theNodesNot << ", " << theShape << " )";
4984 //================================================================================
4986 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4987 \param theElems - group of of elements (edges or faces) to be replicated
4988 \param theNodesNot - group of nodes not to replicated
4989 \param theAffectedElems - group of elements to which the replicated nodes
4990 should be associated to.
4991 \return TRUE if operation has been completed successfully, FALSE otherwise
4992 \sa DoubleNodes(), DoubleNodeGroups()
4994 //================================================================================
4996 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_ptr theElems,
4997 SMESH::SMESH_GroupBase_ptr theNodesNot,
4998 SMESH::SMESH_GroupBase_ptr theAffectedElems)
5000 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5005 ::SMESH_MeshEditor aMeshEditor( myMesh );
5007 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5008 TIDSortedElemSet anElems, aNodes, anAffected;
5009 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5010 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5011 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
5013 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5015 storeResult( aMeshEditor) ;
5017 myMesh->GetMeshDS()->Modified();
5019 myMesh->SetIsModified( true );
5021 // Update Python script
5022 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroup( " << theElems << ", "
5023 << theNodesNot << ", " << theAffectedElems << " )";
5028 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5029 * Works as DoubleNodeElemGroup(), but returns a new group with newly created elements.
5030 * \param theElems - group of of elements (edges or faces) to be replicated
5031 * \param theNodesNot - group of nodes not to replicated
5032 * \param theAffectedElems - group of elements to which the replicated nodes
5033 * should be associated to.
5034 * \return a new group with newly created elements
5035 * \sa DoubleNodeElemGroup()
5037 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems,
5038 SMESH::SMESH_GroupBase_ptr theNodesNot,
5039 SMESH::SMESH_GroupBase_ptr theAffectedElems)
5041 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5044 SMESH::SMESH_Group_var aNewGroup;
5048 ::SMESH_MeshEditor aMeshEditor( myMesh );
5050 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5051 TIDSortedElemSet anElems, aNodes, anAffected;
5052 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5053 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5054 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
5057 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5059 storeResult( aMeshEditor) ;
5062 myMesh->SetIsModified( true );
5064 // Create group with newly created elements
5065 SMESH::long_array_var anIds = GetLastCreatedElems();
5066 if (anIds->length() > 0) {
5067 SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
5068 string anUnindexedName (theElems->GetName());
5069 string aNewName = generateGroupName(anUnindexedName + "_double");
5070 aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
5071 aNewGroup->Add(anIds);
5075 // Update Python script
5076 TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupNew( " << theElems << ", "
5077 << theNodesNot << ", " << theAffectedElems << " )";
5078 return aNewGroup._retn();
5081 //================================================================================
5083 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5084 \param theElems - group of of elements (edges or faces) to be replicated
5085 \param theNodesNot - group of nodes not to replicated
5086 \param theShape - shape to detect affected elements (element which geometric center
5087 located on or inside shape).
5088 The replicated nodes should be associated to affected elements.
5089 \return TRUE if operation has been completed successfully, FALSE otherwise
5090 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
5092 //================================================================================
5094 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_GroupBase_ptr theElems,
5095 SMESH::SMESH_GroupBase_ptr theNodesNot,
5096 GEOM::GEOM_Object_ptr theShape )
5099 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5104 ::SMESH_MeshEditor aMeshEditor( myMesh );
5106 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5107 TIDSortedElemSet anElems, aNodes, anAffected;
5108 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5109 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5111 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5112 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5114 storeResult( aMeshEditor) ;
5116 myMesh->GetMeshDS()->Modified();
5118 myMesh->SetIsModified( true );
5120 // Update Python script
5121 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupInRegion( " << theElems << ", "
5122 << theNodesNot << ", " << theShape << " )";
5126 //================================================================================
5128 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5129 This method provided for convenience works as DoubleNodes() described above.
5130 \param theElems - list of groups of elements (edges or faces) to be replicated
5131 \param theNodesNot - list of groups of nodes not to replicated
5132 \param theAffectedElems - group of elements to which the replicated nodes
5133 should be associated to.
5134 \return TRUE if operation has been completed successfully, FALSE otherwise
5135 \sa DoubleNodeGroup(), DoubleNodes()
5137 //================================================================================
5139 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
5140 SMESHDS_Mesh* theMeshDS,
5141 TIDSortedElemSet& theElemSet,
5142 const bool theIsNodeGrp)
5144 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
5146 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
5147 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
5148 : aGrp->GetType() != SMESH::NODE ) )
5150 SMESH::long_array_var anIDs = aGrp->GetIDs();
5151 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
5156 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroups& theElems,
5157 const SMESH::ListOfGroups& theNodesNot,
5158 const SMESH::ListOfGroups& theAffectedElems)
5162 ::SMESH_MeshEditor aMeshEditor( myMesh );
5164 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5165 TIDSortedElemSet anElems, aNodes, anAffected;
5166 listOfGroupToSet(theElems, aMeshDS, anElems, false );
5167 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5168 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
5170 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5172 storeResult( aMeshEditor) ;
5174 myMesh->GetMeshDS()->Modified();
5176 myMesh->SetIsModified( true );
5178 // Update Python script
5179 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroups( " << &theElems << ", "
5180 << &theNodesNot << ", " << &theAffectedElems << " )";
5184 //================================================================================
5186 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5187 This method provided for convenience works as DoubleNodes() described above.
5188 \param theElems - list of groups of elements (edges or faces) to be replicated
5189 \param theNodesNot - list of groups of nodes not to replicated
5190 \param theShape - shape to detect affected elements (element which geometric center
5191 located on or inside shape).
5192 The replicated nodes should be associated to affected elements.
5193 \return TRUE if operation has been completed successfully, FALSE otherwise
5194 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
5196 //================================================================================
5199 SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theElems,
5200 const SMESH::ListOfGroups& theNodesNot,
5201 GEOM::GEOM_Object_ptr theShape )
5205 ::SMESH_MeshEditor aMeshEditor( myMesh );
5207 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5208 TIDSortedElemSet anElems, aNodes;
5209 listOfGroupToSet(theElems, aMeshDS, anElems,false );
5210 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5212 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5213 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5215 storeResult( aMeshEditor) ;
5217 myMesh->GetMeshDS()->Modified();
5219 myMesh->SetIsModified( true );
5221 // Update Python script
5222 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupsInRegion( " << &theElems << ", "
5223 << &theNodesNot << ", " << theShape << " )";
5227 //================================================================================
5229 \brief Generated skin mesh (containing 2D cells) from 3D mesh
5230 The created 2D mesh elements based on nodes of free faces of boundary volumes
5231 \return TRUE if operation has been completed successfully, FALSE otherwise
5233 //================================================================================
5235 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
5239 ::SMESH_MeshEditor aMeshEditor( myMesh );
5240 bool aResult = aMeshEditor.Make2DMeshFrom3D();
5241 storeResult( aMeshEditor) ;
5242 myMesh->GetMeshDS()->Modified();
5243 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";
5247 //================================================================================
5249 * \brief Double nodes on shared faces between groups of volumes and create flat elements on demand.
5250 * The list of groups must describe a partition of the mesh volumes.
5251 * The nodes of the internal faces at the boundaries of the groups are doubled.
5252 * In option, the internal faces are replaced by flat elements.
5253 * Triangles are transformed in prisms, and quadrangles in hexahedrons.
5254 * @param theDomains - list of groups of volumes
5255 * @param createJointElems - if TRUE, create the elements
5256 * @return TRUE if operation has been completed successfully, FALSE otherwise
5258 //================================================================================
5260 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::ListOfGroups& theDomains,
5261 CORBA::Boolean createJointElems )
5265 ::SMESH_MeshEditor aMeshEditor( myMesh );
5267 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5269 vector<TIDSortedElemSet> domains;
5272 for ( int i = 0, n = theDomains.length(); i < n; i++ )
5274 SMESH::SMESH_GroupBase_var aGrp = theDomains[ i ];
5275 if ( !CORBA::is_nil( aGrp ) && ( aGrp->GetType() != SMESH::NODE ) )
5277 TIDSortedElemSet domain;
5279 domains.push_back(domain);
5280 SMESH::long_array_var anIDs = aGrp->GetIDs();
5281 arrayToSet( anIDs, aMeshDS, domains[ i ], SMDSAbs_All );
5285 bool aResult = aMeshEditor.DoubleNodesOnGroupBoundaries( domains, createJointElems );
5287 storeResult( aMeshEditor) ;
5288 myMesh->GetMeshDS()->Modified();
5290 // Update Python script
5291 TPythonDump() << "isDone = " << this << ".DoubleNodesOnGroupBoundaries( " << &theDomains
5292 << ", " << createJointElems << " )";
5296 // issue 20749 ===================================================================
5298 * \brief Creates missing boundary elements
5299 * \param elements - elements whose boundary is to be checked
5300 * \param dimension - defines type of boundary elements to create
5301 * \param groupName - a name of group to store created boundary elements in,
5302 * "" means not to create the group
5303 * \param meshName - a name of new mesh to store created boundary elements in,
5304 * "" means not to create the new mesh
5305 * \param toCopyElements - if true, the checked elements will be copied into the new mesh
5306 * \param toCopyExistingBondary - if true, not only new but also pre-existing
5307 * boundary elements will be copied into the new mesh
5308 * \param group - returns the create group, if any
5309 * \retval SMESH::SMESH_Mesh - the mesh where elements were added to
5311 // ================================================================================
5313 SMESH::SMESH_Mesh_ptr
5314 SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource,
5315 SMESH::Bnd_Dimension dim,
5316 const char* groupName,
5317 const char* meshName,
5318 CORBA::Boolean toCopyElements,
5319 CORBA::Boolean toCopyExistingBondary,
5320 SMESH::SMESH_Group_out group)
5324 if ( dim > SMESH::BND_1DFROM2D )
5325 THROW_SALOME_CORBA_EXCEPTION("Invalid boundary dimension", SALOME::BAD_PARAM);
5328 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5330 SMESH::SMESH_Mesh_var mesh_var;
5331 SMESH::SMESH_Group_var group_var;
5335 TIDSortedElemSet elements;
5336 SMDSAbs_ElementType elemType = (dim == SMESH::BND_1DFROM2D) ? SMDSAbs_Face : SMDSAbs_Volume;
5337 if ( idSourceToSet( idSource, aMeshDS, elements, elemType,/*emptyIfIsMesh=*/true ))
5341 strlen(meshName) ? makeMesh(meshName) : SMESH::SMESH_Mesh::_duplicate(myMesh_i->_this());
5342 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh_var );
5344 SMESH_Mesh* smesh_mesh = (mesh_i==myMesh_i) ? (SMESH_Mesh*)0 : &mesh_i->GetImpl();
5346 // group of new boundary elements
5347 SMESH_Group* smesh_group = 0;
5348 if ( strlen(groupName) )
5350 group_var = mesh_i->CreateGroup( SMESH::ElementType(int(elemType)-1),groupName);
5351 if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( group_var ))
5352 smesh_group = group_i->GetSmeshGroup();
5356 ::SMESH_MeshEditor aMeshEditor( myMesh );
5357 aMeshEditor.MakeBoundaryMesh( elements,
5358 ::SMESH_MeshEditor::Bnd_Dimension(dim),
5362 toCopyExistingBondary);
5363 storeResult( aMeshEditor );
5366 const char* dimName[] = { "BND_2DFROM3D", "BND_1DFROM3D", "BND_1DFROM2D" };
5368 // result of MakeBoundaryMesh() is a tuple (mesh, group)
5369 if ( mesh_var->_is_nil() )
5370 pyDump << myMesh_i->_this() << ", ";
5372 pyDump << mesh_var << ", ";
5373 if ( group_var->_is_nil() )
5374 pyDump << "_NoneGroup = "; // assignment to None is forbiden
5376 pyDump << group_var << " = ";
5377 pyDump << this << ".MakeBoundaryMesh( "
5379 << "SMESH." << dimName[int(dim)] << ", "
5380 << "'" << groupName << "', "
5381 << "'" << meshName<< "', "
5382 << toCopyElements << ", "
5383 << toCopyExistingBondary << ")";
5385 group = group_var._retn();
5386 return mesh_var._retn();